<!-- rye:signed:2026-04-01T05:31:37Z:62d60ba3d103451a68e5ab4fe4e16b1ad929eca6f1b080ef0eada810a1dc8a5f:L0GtHx3vnmgR6PuIOqdeGc1B6WbeTUz1ZL5Zh6Pm20p32ABqC9O0HLA0jzPu1XR1SlPhReNEBfmblT7wURUjBw:6ea18199041a1ea8 -->

# Create Directive

Create a new directive file with proper metadata, validate, and sign it.

```xml
<directive name="create_directive" version="3.0.0">
  <metadata>
    <description>Create a directive file with minimal required fields, check for duplicates, write to disk, and sign it.</description>
    <category>rye/core</category>
    <author>rye-os</author>
    <model tier="fast" />
    <limits turns="6" tokens="4096" />
    <permissions>
      <fetch>
        <directive>*</directive>
      </fetch>
      <execute>
        <tool>rye.file-system.*</tool>
      </execute>
      <sign>
        <directive>*</directive>
      </sign>
    </permissions>
  </metadata>

  <inputs>
    <input name="name" type="string" required="true">
      Directive name in snake_case (e.g., "deploy_app", "create_component")
    </input>
    <input name="category" type="string" required="true">
      Directory path relative to .ai/directives/ (e.g., "workflows", "testing")
    </input>
    <input name="description" type="string" required="true">
      What does this directive do? Be specific and actionable.
    </input>
    <input name="process_steps" type="string" required="false">
      Brief summary of process steps (bullet points)
    </input>
  </inputs>

  <outputs>
    <output name="directive_path">Path to the created directive file</output>
    <output name="signed">Whether the directive was successfully signed</output>
  </outputs>
</directive>
```

<process>
  <step name="check_duplicates">
    Search for existing directives with a similar name to avoid creating duplicates.
    `rye_fetch(query="{input:name}", scope="directive")`
    If a duplicate exists, stop and report it.
  </step>

  <step name="validate_inputs">
    Validate that {input:name} is snake_case alphanumeric, {input:category} is non-empty, and {input:description} is non-empty. Halt if any validation fails.
  </step>

  <step name="write_directive_file">
    Generate the directive markdown file and write it to .ai/directives/{input:category}/{input:name}.md

    The generated file must contain:
    1. A signature comment placeholder at the top
    2. A markdown title and description
    3. A single ```xml fenced block containing ONLY metadata, inputs, and outputs
    4. Pseudo-XML process steps AFTER the fence for the LLM to follow

    Use {input:process_steps} if provided to inform the step content.

    `rye_execute(item_type="tool", item_id="rye/file-system/write", parameters={"path": ".ai/directives/{input:category}/{input:name}.md", "content": "<generated directive content>", "create_dirs": true})`

  </step>

  <step name="sign_directive">
    Validate and sign the new directive file.
    `rye_sign(item_type="directive", item_id="{input:category}/{input:name}")`
  </step>
</process>

<success_criteria>
<criterion>No duplicate directive with the same name exists</criterion>
<criterion>Directive file created at .ai/directives/{input:category}/{input:name}.md</criterion>
<criterion>XML fence contains well-formed metadata, inputs, and outputs</criterion>
<criterion>Signature validation comment present at top of file</criterion>
</success_criteria>
