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

d.make_mode String {
  id      = "draft-email",
  trigger = "Draft a professional email where the ontology provides context about who you are, what you are working on, and what you want — anchored rather than improvised",

  preconditions = [
    ".ontology/core.ncl and .ontology/state.ncl export without errors",
    "Recipient context is specified: who they are, what the relationship is, what the intent of the email is",
  ],

  steps = [
    {
      id     = "define_context",
      action = "Establish: (1) recipient — who they are and what they care about. (2) relationship — first contact / existing / following up. (3) intent — inform / request / invite / respond / close. These three determine which nodes are relevant and what register to use.",
      actor  = 'Human,
      on_error = { strategy = 'Stop },
    },
    {
      id     = "select_narrative",
      action = "Based on intent, select the minimum set of ontology nodes that provide grounding: for a first contact email, use 1-2 Project nodes with artifact_paths; for a follow-up, use state.ncl active transitions to show movement; for a close, use relevant Practice or Axiom node descriptions as shared language.",
      cmd    = "nickel export .ontology/core.ncl | from json",
      actor  = 'Both,
      depends_on = [{ step = "define_context" }],
      on_error = { strategy = 'Stop },
    },
    {
      id     = "check_active_state",
      action = "If the email references active work, export state.ncl and confirm which dimensions are in motion. Do not reference a transition as 'in progress' if the dimension shows it as blocked. The email should reflect actual state.",
      cmd    = "nickel export .ontology/state.ncl | from json | get dimensions",
      actor  = 'Agent,
      depends_on = [{ step = "select_narrative" }],
      on_error = { strategy = 'Continue },
    },
    {
      id     = "render_draft",
      action = "Write the email: subject line that states the intent directly; opening that establishes context without over-explaining; body that delivers the single thing the email is for; closing that makes the next step explicit. Maximum 250 words unless the intent requires more.",
      actor  = 'Agent,
      depends_on = [{ step = "check_active_state" }],
      on_error = { strategy = 'Stop },
    },
    {
      id     = "review",
      action = "Human reviews for: clarity (does the first sentence state the intent?), grounding (are any claims unsupported by actual project state?), tone (does it match the relationship type?), and ask (is the request or next step unambiguous?).",
      actor  = 'Human,
      depends_on = [{ step = "render_draft" }],
      on_error = { strategy = 'Stop },
    },
  ],

  postconditions = [
    "Email draft exists with explicit intent, grounded claims, and clear next step",
    "No project or work referenced that contradicts current state.ncl state",
  ],
}
