name: write_template
description: "CEO designs a new PAE-Lang template -- skills-guided, adjudicated, committed via AR."
debug: true
system: agent_prompt

agent_prompt:
  - "= identity.md"

skills:
  - guides/PAETemplateGuide.md

sections:
  - agent
  - project
  - rag
  - templates
  - skills
  - message
  - rejection_feedback
  - instructions

steps:
  - type: think
    hint: |
      You are {agent.name}, designing a new operational template for the company.

      CONTEXT: Read the SKILLS & GUIDES section -- it contains the PAE Template Guide
      which defines every YAML key, step type, section key, and constraint you must follow.

      THE IRON RULE: NEVER mix thinking and formatting in the same LLM step.
      A `think` step reasons freely. A `package` step serializes only.
      If the template needs both reasoning and structured output, use two steps.

      DESIGN PROCESS:
      1. Review the AVAILABLE TASK TEMPLATES to check for overlap.
         If an existing template already covers this need, explain why a new one is unnecessary.
      2. If a new template IS justified, design it following the PAE Template Guide exactly.

      TEMPLATE DESIGN REQUIREMENTS:
      - name: must match the intended filename (lowercase_with_underscores, no .yml extension)
      - description: one clear sentence explaining what this template does
      - system: usually `agent_prompt` for full identity, or a builder for custom system prompts
      - sections: ordered list of section keys -- always include `message` and usually `instructions` last
      - steps: at minimum one `think` step and a `close` step at the end
      - adjudication: configure with appropriate criteria and threshold for the task type

      CONSTRAINTS:
      - The template must serve the company charter.
      - Only use step types defined in the guide: think, package, document, spawn, reply, close, tool.
      - Do NOT use process_ledger (AR-only).
      - close must always be the last step.
      - If the template needs skills injection, declare the skills: array at the top level.
      - Variable interpolation: {agent.name}, {project.name}, {task.message}, {steps[N].text}, etc.

  - type: package
    packet_type: IntakeResponse
    hint: |
      Convert the template design into a strict JSON payload.
      Output exactly ONE write_template action.
      The template_yaml must be valid YAML that follows the PAE Template Guide.
      Do not include prose outside the JSON structure.
    schema:
      actions:
        - type: write_template
          company_slug: "string -- the company this template belongs to"
          template_name: "string -- the template name (must match name: key in YAML)"
          template_yaml: "string -- complete valid YAML content of the template file"

  - type: close
    rag_update: true

adjudication:
  enabled: true
  pass_threshold: 85
  deliverable_type: coordination
  criteria:
    pae_lang_compliance:
      weight: 30
      description: "Template follows PAE-Lang specification -- valid step types, sections, keys"
    charter_alignment:
      weight: 20
      description: "Template serves the company charter and operational needs"
    iron_rule:
      weight: 20
      description: "Think and package steps are properly separated -- no mixed reasoning/formatting"
    completeness:
      weight: 15
      description: "All required keys present, close step at end, sections properly ordered"
    non_duplication:
      weight: 15
      description: "Template does not duplicate an existing template's purpose"
