let actor_kind_type = [|
  'Human,
  'AgentClaude,
  'AgentCustom,
  'CI,
|] in

let kind_type = [|
  'done,
  'plan,
  'info,
  'review,
  'audit,
  'commit,
  'unknown,
|] in

let category_type = [|
  'Inbox,
  'Insight,
  'Feature,
  'Bugfix,
  'Investigation,
  'Decision,
  'Review,
  'Resource,
|] in

let content_role_type = [|
  'ProcessMemory,
  'KnowledgeBase,
  'Resource,
|] in

# ── Author ──────────────────────────────────────────────────────────────────
# .coder/<author>/author.ncl

let author_type = {
  name    | String,
  actor   | actor_kind_type,
  model   | String | default = "",
  contact | String | default = "",
} in

# ── Category context ────────────────────────────────────────────────────────
# .coder/<author>/<category>/context.ncl

let context_type = {
  category    | category_type,
  role        | content_role_type | default = 'ProcessMemory,
  description | String            | default = "",
  graduable   | Bool              | default = false,
} in

# ── Entry (companion NCL) ──────────────────────────────────────────────────
# Generated by `coder triage` next to each .md file.
# {filename}.ncl is the companion for {filename}.md
#
# Extracted from:
#   - filename → date, kind
#   - first line of markdown → title
#   - content keywords → tags
#   - author workspace → author
#   - triage target → category

let entry_type = {
  title      | String,
  date       | String             | default = "",
  author     | String,
  kind       | kind_type          | default = 'unknown,
  category   | category_type,
  tags       | Array String       | default = [],
  relates_to | Array String       | default = [],
  supersedes | String             | default = "",
  source     | String             | default = "",
} in

# ── Domain (for insights) ────────────────────────────────────────────────

let domain_type = [|
  'Language,
  'Runtime,
  'Architecture,
  'Tooling,
  'Pattern,
  'Debugging,
  'Security,
  'Performance,
|] in

# ── Record context ───────────────────────────────────────────────────────
# Captures the session context in which a record was generated.

let record_context_type = {
  trigger       | String       | default = "",
  files_touched | Array String | default = [],
} in

# ── Record (JSON entry) ─────────────────────────────────────────────────
# Generated by `coder record` — stored in entries.jsonl per category.
# Self-contained: no companion NCL needed.
# Superset of Entry: adds content, context, and optional insight fields.

let record_type = {
  title      | String,
  date       | String             | default = "",
  author     | String,
  kind       | kind_type          | default = 'unknown,
  category   | String,
  tags       | Array String       | default = [],
  relates_to | Array String       | default = [],
  content    | String,
  context    | record_context_type | optional,
  domain     | domain_type        | optional,
  reusable   | Bool               | optional,
} in

{
  ActorKind      = actor_kind_type,
  Kind           = kind_type,
  Category       = category_type,
  ContentRole    = content_role_type,
  Domain         = domain_type,
  Author         = author_type,
  Context        = context_type,
  Entry          = entry_type,
  RecordContext  = record_context_type,
  Record         = record_type,
}
