let d = import "../defaults.ncl" in

d.make_mode String {
  id      = "update-cv",
  trigger = "Generate CV sections adapted to a specific opportunity context (job, grant, collaboration) using projects and practices from the ontology",

  preconditions = [
    ".ontology/core.ncl exports without errors — at least one Project node and one Practice node exist",
    ".ontology/state.ncl exports without errors — career dimension is defined",
    "A target context is specified: either an Opportunity node from personal.ncl or a stated purpose (e.g., 'infrastructure engineering role', 'open source grant')",
  ],

  steps = [
    {
      id     = "resolve_context",
      action = "Determine the target audience and framing. If an Opportunity node is given, read its kind, fit_signals, and note. If a stated purpose, classify it into an audience type: Technical / HiringManager / Academic / Community.",
      actor  = 'Both,
      on_error = { strategy = 'Stop },
    },
    {
      id     = "select_projects",
      action = "From core.ncl Project nodes, select those relevant to the target context. Relevance is determined by: (1) node pole alignment with context (Yang for engineering roles, Yin for research/creative), (2) artifact_paths showing real artifacts, (3) edges showing which practices they validate.",
      cmd    = "nickel export .ontology/core.ncl | from json | get nodes | where { |n| $n.level == 'Project }",
      actor  = 'Both,
      depends_on = [{ step = "resolve_context" }],
      on_error = { strategy = 'Stop },
    },
    {
      id     = "resolve_practices",
      action = "For each selected Project node, traverse outgoing 'ValidatedBy and 'ManifestsIn edges to find linked Practice nodes. These become the skills and methodologies section of the CV.",
      actor  = 'Agent,
      depends_on = [{ step = "select_projects" }],
      on_error = { strategy = 'Stop },
    },
    {
      id     = "resolve_career_state",
      action = "Export state.ncl and read the career dimension: current_state, desired_state, and active transitions. This informs the CV narrative arc — what you are moving toward, not just what you have done.",
      cmd    = "nickel export .ontology/state.ncl | from json | get dimensions | where { |d| $d.id == 'career }",
      actor  = 'Agent,
      depends_on = [{ step = "resolve_context" }],
      on_error = { strategy = 'Continue },
      note   = "career dimension may not exist in all personal ontology implementations — step continues if absent.",
    },
    {
      id     = "render_sections",
      action = "Generate CV sections: (1) Summary — 3 sentences from career dimension narrative + key axioms. (2) Projects — one paragraph per selected Project, anchored to artifact_paths. (3) Practices — bullet list from resolved practices. (4) Trajectory — from career state transitions. Adapt register to context audience.",
      actor  = 'Agent,
      depends_on = [
        { step = "resolve_practices" },
        { step = "resolve_career_state" },
      ],
      on_error = { strategy = 'Stop },
    },
    {
      id     = "review",
      action = "Human reviews for completeness (does it show the work?), accuracy (does each claim link to a real artifact or decision?), and framing (does the summary reflect the desired_state, not just current_state?).",
      actor  = 'Human,
      depends_on = [{ step = "render_sections" }],
      on_error = { strategy = 'Stop },
    },
  ],

  postconditions = [
    "CV sections generated and anchored to Project + Practice nodes",
    "Summary narrative consistent with career dimension desired_state",
    "No claims made that are not traceable to an ontology node or artifact_path",
  ],
}
