# Workflow: add-directive

Purpose: Author a human directive in the vault.

This is the ONLY codepath in GMD that creates directories under
`Knowledge/_human/Directives/`. Agent-facing code MUST NOT create
these directories (DIR-02 invariant; audit-enforced in
tests/audit-directive-authority.sh Case AGENT-NEVER-MKDIR).

## Preflight

1. Component gate: run
   `node -e "const {isEnabled}=require('./bin/lib/config.js'); process.exit(isEnabled('obsidian')?0:1)"`
   - Exit code 1 -> print "Obsidian component is disabled. Enable via
     config.components.obsidian.enabled=true and retry." then exit 0.
2. Resolve vault root via:
   `VAULT=$(node -e "const {resolveVaultRoot}=require('./bin/lib/vault-project.js'); console.log(resolveVaultRoot(process.cwd()))")`

## Wizard (AskUserQuestion-driven)

3. Ask user: scope? (options: repo | project | concept | task)
4. If scope=project: list `$VAULT/Projects/*` and ask which project
5. Ask: applies_to_agents? (free-form; parse as array; default ["all"])
6. Ask: precedence? (integer; default 1)
7. Ask: enforce_in_curation? (yes/no; default no)
8. Ask: summary? (>= 10 words)
9. Ask: body markdown? (free-form; open Claude's editor)

## Write

10. Compute target path:
    ```
    case $SCOPE in
      repo)    DIR="$VAULT/Knowledge/_human/Directives/Repo" ;;
      project) DIR="$VAULT/Knowledge/_human/Directives/Projects/$PROJECT" ;;
      concept) DIR="$VAULT/Knowledge/_human/Directives/Concepts" ;;
      task)    DIR="$VAULT/Knowledge/_human/Directives/Tasks" ;;
    esac
    mkdir -p "$DIR"                                    # <- ONLY place in codebase
    SLUG=$(echo "$SUMMARY" | head -c 40 | tr '[:upper:]' '[:lower:]' | tr -cs 'a-z0-9' '-')
    TARGET="$DIR/$SLUG.md"
    ```
11. Write frontmatter + body via Write tool with keys:
    ```yaml
    type: directive
    scope: {scope}
    applies_to_agents: {applies_to_agents}
    precedence: {precedence}
    enforce_in_curation: {enforce_in_curation}
    summary: {summary}
    ```

## Validate

12. Run:
    ```bash
    node -e "
      const {validateDirectiveSchema}=require('./bin/lib/vault-directives.js');
      const {parseFrontmatter}=require('./bin/lib/vault-frontmatter.js');
      const fs=require('fs');
      const raw=fs.readFileSync('$TARGET','utf8');
      const {frontmatter}=parseFrontmatter(raw);
      const r=validateDirectiveSchema(frontmatter);
      if(!r.valid){console.error(JSON.stringify(r));process.exit(1);}
      console.log('[OK] schema valid');
    "
    ```
    Exit 1 -> print error + the diagnostic JSON; human edits + reruns.

## Finish

13. Print:
    > Directive written to $TARGET
    > Verify visible to agents: `node bin/gmd-tools.cjs vault-orient --caller gmd-planner`
