cairn-ai 0.2.9 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/.agents/workflows/cairn-plan.md +11 -18
  2. package/.agents/workflows/cairn-work.md +14 -20
  3. package/.claude/commands/cairn-plan.md +1 -1
  4. package/.claude/commands/cairn-work.md +1 -1
  5. package/.codex-plugin/plugin.json +1 -1
  6. package/README.ko.md +2 -2
  7. package/README.md +2 -2
  8. package/agents/worker.md +1 -1
  9. package/commands/cairn-plan.md +9 -15
  10. package/commands/cairn-work.md +13 -21
  11. package/docs/model-guidance/README.md +8 -6
  12. package/docs/model-guidance/claude.md +2 -1
  13. package/docs/model-guidance/codex.md +1 -1
  14. package/package.json +1 -1
  15. package/scripts/cairn-goal-cli.mjs +53 -12
  16. package/scripts/cairn-goal-operations-evidence.mjs +105 -22
  17. package/scripts/cairn-goal-operations-mutations.mjs +42 -8
  18. package/scripts/cairn-goal-operations.mjs +66 -19
  19. package/scripts/cairn-goal-policy.mjs +29 -3
  20. package/scripts/cairn-goal-state-validation.mjs +141 -12
  21. package/scripts/cairn-goal-state.mjs +17 -5
  22. package/scripts/cairn-goal.mjs +9 -3
  23. package/scripts/cairn-state-context.mjs +13 -4
  24. package/scripts/cairn-state-init.mjs +2 -2
  25. package/scripts/cairn-state.mjs +48 -6
  26. package/scripts/cairn.mjs +1 -1
  27. package/skills/cairn-plan/SKILL.md +34 -175
  28. package/skills/cairn-plan/delegation.md +62 -0
  29. package/skills/cairn-plan/heavy-path.md +26 -0
  30. package/skills/cairn-plan/planning-rules.md +68 -0
  31. package/skills/cairn-work/SKILL.md +38 -143
  32. package/skills/cairn-work/delegation.md +62 -0
  33. package/skills/cairn-work/heavy-path.md +16 -0
  34. package/skills/cairn-work/recovery.md +29 -0
  35. package/skills/cairn-work/verification.md +65 -0
  36. package/templates/PLAN.md +1 -1
  37. package/templates/work-plan.md +19 -7
@@ -5,200 +5,59 @@ description: Use before non-trivial implementation, refactoring, migrations, deb
5
5
 
6
6
  # Cairn Plan
7
7
 
8
- Use this before non-trivial implementation, refactoring, migrations, debugging, or repository automation. Also use it when the user asks for planning, design, "설계부터", "신중하게", "꼼꼼히", complexity triage, or coordinated agent work.
9
-
10
- ## Purpose
11
-
12
- Plans must reduce execution tokens. Do not leave long plans only in chat. Store the topic in `PLAN.md` and details in `docs/plan/<topic>.md`.
13
-
14
- When project-root `MEMORY.md` exists, read it as the repository policy and domain-knowledge index before exploring or delegating work. If it is absent, continue without repository memory; never invoke another memory service or block solely because the file is missing. Delegated agents follow the same rule.
15
-
16
- Do not treat planning as optional for implementation work that is more than a narrow single-file fix. Produce or update a plan when the request changes behavior, architecture, data, or multiple files, or when an external operation requires code edits, conflict resolution, destructive recovery, release/deploy, or design. External-state mutation alone is not a planning trigger: routine known-target Git/GitHub operations such as status, fetch, checkout, branch, merge, push, and PR management stay plan/goal-free.
17
-
18
- Plan from the whole work down. First understand the full requested outcome and affected surfaces, then classify the work into small executable tasks. If one task is still too broad to verify cleanly, split that task into sub-tasks.
8
+ Use before non-trivial implementation, refactoring, migrations, debugging, or repository automation, or when the user asks for planning, design, "설계부터", "신중하게", "꼼꼼히", or coordinated agents. Plans reduce execution tokens: store the topic in `PLAN.md` and details in `docs/plan/<topic>.md`, never only in chat.
19
9
 
20
10
  ## Re-entry and Required References
21
11
 
22
- At the start and after compaction, restart, or handoff, restore context in this order: optional root `MEMORY.md` → `cairn-plan` → the active plan → current-task references → model guidance recorded by the plan. A new implementation request with no persisted goal may create its initial plan through the procedure below. Missing `MEMORY.md` is not an inconsistency. If persisted state names a plan or task and that required reference is missing, unreadable, or inconsistent, do not explore, edit, delegate, or complete work; report or record a blocker first. Do not add a read-receipt field that claims the model read a file: filesystem/state consistency and bound tool evidence remain the fail-closed authority.
12
+ At the start and after compaction, restart, or handoff, restore context in this order: optional root `MEMORY.md` → `cairn-plan` → the active plan → current-task references → model guidance recorded by the plan. Missing `MEMORY.md` is not an inconsistency: continue without repository memory and never invoke another memory service. If persisted state names a plan or task and that required reference is missing, unreadable, or inconsistent, do not explore, edit, delegate, or complete work; report or record a blocker first. No read-receipt fields: state consistency and bound tool evidence are the authority.
23
13
 
24
14
  ## Runtime Location
25
15
 
26
- Resolve Cairn's read-only runtime from `references/cairn-runtime.json` next to this `SKILL.md`. Its `pluginRoot` contains Cairn's `scripts/`, `templates/`, commands, agents, and model guidance. In a source checkout where the locator does not exist, resolve the plugin root from this `SKILL.md` location (`../..`). Never search the target repository for Cairn scripts, templates, or model guidance, and never derive the plugin root from the current working directory. If the shared runtime or locator is missing, unreadable, or inconsistent, stop every dependent mirror and recover from the published/global package with `cairn doctor` followed by `cairn upgrade`; do not use another mirror as a repair source.
16
+ Resolve the read-only runtime from `references/cairn-runtime.json` next to this `SKILL.md` (its `pluginRoot`; in a source checkout without it, this file's `../..`). Never search the target repository for Cairn files or derive `pluginRoot` from the cwd. If the runtime or locator is missing, unreadable, or inconsistent, stop every dependent mirror and recover with published/global `cairn doctor` followed by `cairn upgrade`; never repair from another mirror.
27
17
 
28
- Use logical resource IDs such as `cairn://templates/work-plan.md` and `cairn://docs/model-guidance/codex.md` in repository plans. Resolve those IDs through `pluginRoot` only while executing. Keep `repoRoot` separate and pass it explicitly as `--root <repoRoot>`.
18
+ Plans use logical IDs such as `cairn://templates/work-plan.md`, resolved through `pluginRoot`. The session-start hook prints a ready prefix `Cairn CLI: node "<abs>/scripts/cairn.mjs" goal <command>`: copy it literally into every command and never store it in a shell variable (shell variables do not persist between tool calls). `--root` may be omitted when the cwd is inside the repository (it resolves via `HARNESS_REPO_ROOT`, else the nearest `.git` ancestor).
29
19
 
30
- For a non-trivial implementation request or continuation of already planned work, treat the request itself as authorization to create or restore a two-phase plan and activate its roadmap, even when the user does not mention a goal. Do not create a plan or goal for a routine known-target Git/GitHub operation unless it crosses one of the escalation boundaries above. The initial plan is decision-complete for the `triage-plan` task but is not implementation-ready. After writing it and its `PLAN.md` index entry, synchronize the same ordered steps to Codex UI tools when available (`update_plan` first, then `create_goal`) and start the repository goal before exploration, toolcheck, complexity triage, or a non-blocking user question:
20
+ ## Reference Files
31
21
 
32
- ```sh
33
- node "<pluginRoot>/scripts/cairn.mjs" goal start --root "<repoRoot>" --goal "<objective>" --plan "docs/plan/<topic>.md" --tasks '[{"id":"triage-plan","title":"Run planned triage and finalize the plan","requiredEvidence":["planArtifact","triageDecision"]},{"id":"implement","title":"Implement the finalized plan"},{"id":"verify","title":"Verify and review the result"}]' --criteria "<completion criterion>" --session "<current session_id>"
34
- ```
35
-
36
- Pass `--session` only with a session ID the surface actually exposes to the model; never guess or invent one, because a mismatched owner makes every later hook treat the goal as foreign. If no stable session ID is exposed, omit `--session` and record that the goal is repository-scoped.
22
+ Read a reference only when the selected path or situation requires it (Quick and Light Path never need `heavy-path.md`):
37
23
 
38
- If an unfinished repository goal already exists when a new implementation request, steer, or drift arrives, do not cancel it to start another. Fold the new work into it with `goal replan` (completed tasks and their evidence are preserved; resume a paused or blocked goal first), synchronize the plan artifact and native UI roadmap, and keep advancing until goal final review. Start a separate goal only when the user explicitly switches work. When a hook reports that another session owns the goal and this session continues that same work, take ownership with `goal claim --session <id>` using the ID shown by the hook.
39
- If Codex UI plan/goal tools are unavailable, record that limitation and continue with the repository plan and goal; never claim UI synchronization that did not occur.
24
+ - `cairn://skills/cairn-plan/planning-rules.md`: plan rules, route record, tool readiness, dry-run policy; read when finalizing a plan.
25
+ - `cairn://skills/cairn-plan/delegation.md`: subagent lifecycle, prompt format, reasoning-effort routing; read before dispatching.
26
+ - `cairn://skills/cairn-plan/heavy-path.md`: Heavy Path flow, route changes, review gates; read only on a Heavy signal or route change.
40
27
 
41
- ## Procedure
28
+ ## Path Selection
42
29
 
43
- 1. Run `node "<pluginRoot>/scripts/cairn.mjs" init --root "<repoRoot>"` through the resolved runtime. If the runtime is unavailable, ensure `MEMORY.md`, `PLAN.md`, `docs/memory`, and `docs/plan` directly and report that `cairn doctor` or `cairn upgrade` is required.
44
- 2. Read project-root `MEMORY.md` when present; otherwise continue without repository memory.
45
- 3. Classify the request as non-trivial implementation/planned-work continuation, routine known-target Git/GitHub operation, or consultation/explanation/plan-only. For a routine operation, execute without creating a plan or goal unless it requires code edits, conflict resolution, destructive recovery, release/deploy, or design. For non-trivial implementation/planned-work continuation, immediately create an initial `docs/plan/<topic>.md` from `cairn://templates/work-plan.md` and add its `PLAN.md` index entry. Based only on the request and `MEMORY.md`, describe the observable outcome, anticipated affected surfaces, and stable top-level roadmap. Make `triage-plan` the first active task and specify its memory inputs, investigation scope, toolcheck, Heavy Path criteria, and exact condition for updating the plan. Mark the plan `initial: decision-complete for triage; not implementation-ready`.
46
- 4. Before reading detailed memory, toolcheck, repository exploration, complexity triage, delegation, or any non-blocking user question, synchronize the initial roadmap:
47
- - Call Codex `update_plan` first when available so the UI displays the ordered tasks with `triage-plan` in progress.
48
- - Call Codex `create_goal` next when available so the UI displays the active objective. The non-trivial implementation request plus this developer-level skill instruction is authorization; do not use it for routine known-target Git/GitHub operations, consultation, explanation, or plan-only requests.
49
- - Start or attach the repository Cairn goal with the same objective, plan ID, stable task IDs, and current session ID.
50
- - If a UI tool is unavailable, record the limitation in the plan and continue with repository state.
51
- 5. Execute the planned `triage-plan` task: read only the relevant `docs/memory/*.md`, read applicable installed model guidance, run toolcheck, and explore the repository with focused search and LSP/symbol tools.
52
- 6. Treat tool installation as a separate external-state change. Do not install during planning without explicit user approval. After approval, use `toolcheck --install --yes --root "<repoRoot>"` only for pinned/supported installers, or the approved repository-native command. Otherwise record the missing tool and proposed command as a blocker.
53
- 7. Summarize the whole work and affected surfaces, classify it into small executable tasks/sub-tasks, identify dry-run/check modes, and run complexity triage before applying workflow guidance from agents, plugins, or delegated roles.
54
- 8. Update the same repository plan with the selected route, all checked Heavy Path signals, concrete file scope, tool readiness, delegation, verification commands, and fail-closed evidence. Mark it `decision-complete for implementation`, then call Codex `update_plan` again so the UI matches the finalized roadmap.
55
- - Spend planning tokens on executable test design: requirements, invariants, boundaries, failure modes, expected initial failure, and authoritative tool result.
56
- - Give implementation a bounded test contract and exact file scope; require the minimum passing change rather than renewed broad discovery.
57
- - Plan focused tests first, one final full check, and a package dry-run when no change occurred after the full check. Require lifecycle inspection, normal script execution for content-producing or unknown scripts, and `--ignore-scripts` only for absent or proven content-neutral scripts. Mark evidence stale after relevant mutation.
58
- 9. Only after step 8, record bound `planArtifact` and `triageDecision` evidence records, complete the `triage-plan` task, and advance to implementation.
59
- 10. Delegate according to the selected path and model guidance instead of asking the user.
60
- - Use `explorer` for independent read-only codebase discovery, impact analysis, pattern searches, and read-only verification that can run in parallel when the current tool list supports it.
61
- - Treat the user-called/main agent as the orchestrator: it plans, assigns, verifies, and records evidence.
62
- - Use `worker` for actual implementation edits with clear file ownership whenever subagent tools are available, on both Light Path and Heavy Path.
63
- - When the subagent tool provides a progress-reporting channel, require subagents to report status to the orchestrator when starting work, when deciding or confirming direction, during periodic progress, and when finishing; the orchestrator must immediately relay received status events to the user. If no mid-run reporting channel exists, relay observable events such as assignment, waiting, and final completion.
64
- - Require delegated subagents to provide a final report before leaving; after capturing the final report and evidence, close or release the completed subagent, then review the final report and evidence before marking the work complete.
65
- - When subagent tools are available, each agent may recursively delegate bounded sub-tasks to subagents, subject to the current surface's depth and concurrency limits.
66
- - If subagent tools are unavailable, the main agent takes over implementation directly and records that takeover in evidence; do not stop before local implementation solely because subagent tools are unavailable.
67
- - Keep urgent non-implementation blocking work local when the next step depends immediately on the result.
68
- - Tell every delegated agent and child subagent to read project-root `MEMORY.md` when present and continue when absent, keep scope, and tell workers they are not alone in the codebase and must not revert others' edits.
69
- 11. Give every plan and ordered task step a stable ID and declare task-level and goal-level required evidence. The task order must be sufficient for both Codex UI and hook context to show the roadmap and restore the current task after side questions.
70
- 12. Advance a Codex UI step only after the matching repository Cairn task transition succeeds with all required bound evidence records. The repository state is the fail-closed transition authority; UI state is its synchronized projection.
71
- 13. Write user-visible responses and generated or updated documentation, plans, and memory artifacts in the OS locale unless the user asks for another language.
72
-
73
- ## Reasoning Effort Routing
74
-
75
- - Models always inherit the host/user default; never configure or override them.
76
- - Light Path planning, implementation, and verification request `medium`.
77
- - Heavy Path planning, review, and implementation request `high`; final verification and review request `xhigh`.
78
- - Every module task records `Requested reasoning effort` and `Effective reasoning effort` in `docs/plan/<topic>.md`. Requested is Cairn's desired profile; Effective is what the dispatch result confirms.
79
- - Pass requested effort only when dispatching a new task/worker and the host exposes a reasoning-effort option or host-native equivalent. Omit model overrides. Effective `inherited` means no task-level override was confirmed, not proof of missing host capability. Describe capability only from the exposed interface or dispatch response, distinguish Cairn non-integration from host non-support, and leave model/global config unchanged.
80
- - On every route change, synchronize the plan artifact, repository goal task roadmap through `goal replan`, native UI plan, and reasoning effort profile before mutation. Completed task profiles are preserved as audit history; incomplete task profiles are recalculated for the new path.
81
-
82
- ## Complexity Triage
83
-
84
- Decide triage from repository evidence without asking the user.
85
-
86
- Use three mandatory checkpoints and record each result, evidence, newly discovered Heavy Path signals, and current route in the plan artifact:
87
-
88
- 1. **Request checkpoint:** before exploration, make a provisional classification from the request and `MEMORY.md`; uncertainty stays explicit and this result is not implementation authority.
89
- 2. **Planning checkpoint:** after repository exploration, affected-surface analysis, and test design, re-evaluate the provisional route and finalize the implementation plan.
90
- 3. **Code checkpoint:** during `cairn-work`, inspect the exact files, callers, and tests, then record one final re-evaluation immediately before the first edit. A pending or missing code checkpoint blocks mutation.
91
-
92
- Before the first edit, the planning or code checkpoint may change Light Path to Heavy Path or Heavy Path to Light Path when the evidence supports it. Every route change must rebuild and synchronize the plan artifact, repository goal task roadmap through `goal replan`, and native UI plan, including assignments, reviews, and required evidence; do not mutate until all three agree. After editing starts, only promote Light Path to Heavy Path: stop further edits, mark affected evidence stale, revise and synchronize all three roadmaps, run newly required Heavy Path review, and repeat the code checkpoint before resuming.
93
-
94
- This decision takes priority over plugin, agent, or delegated workflow guidance unless higher-priority system or developer instructions say otherwise. The default is Light Path; use Heavy Path only when a Heavy Path condition clearly applies.
95
-
96
- ### Light Path
97
-
98
- Use Light Path for narrow changes inside existing architecture layers. Skip planning/review agents when appropriate, but actual implementation edits still go to `worker` whenever subagent tools are available. Keep the verification gate.
99
-
100
- Light Path conditions:
101
-
102
- - The change stays inside existing architecture layers.
103
- - No new domain model, service class, or abstraction is introduced.
104
- - No security, authentication, authorization, session, external API, message queue, payment, DB schema, migration, concurrency, transaction-boundary, or cache-invalidation change is involved.
105
-
106
- Light Path examples:
107
-
108
- - One new API endpoint within existing layers.
109
- - Add or modify a controller or service method.
110
- - Strengthen validation rules.
111
- - Adjust query logic.
112
- - Change copy text or constants.
113
- - Fix one clearly scoped bug.
114
-
115
- Light Path flow: main-agent orchestration -> bounded `worker` implementation when subagent tools are available -> main-agent takeover when subagent tools are unavailable -> focused verification by the main agent or a scoped verification `worker` -> report. If there is no plan artifact, use the original user request and the diff as the verification baseline.
116
-
117
- ### Heavy Path
118
-
119
- Use Heavy Path when the request clearly needs the full planning and review pipeline.
120
-
121
- Heavy Path conditions:
122
-
123
- - Creating a new directory, module, or architecture layer.
124
- - Introducing a new domain model, service class, or abstraction.
125
- - Changing security, authentication, authorization, or sessions.
126
- - Integrating an external API, message queue, or payment flow.
127
- - Changing DB schema or migrations.
128
- - Changing concurrency, transaction boundaries, or cache invalidation.
129
- - Refactoring across multiple domains.
130
- - The user signals extra care, such as "신중하게", "검토 받고", "설계부터", or "꼼꼼히".
131
-
132
- Heavy Path flow: plan -> pre-implementation review -> bounded `worker` implementation -> verification worker or read-only review.
133
-
134
- ### Route Record
135
-
136
- `docs/plan/<topic>.md` must record:
137
-
138
- - Selected path.
139
- - Selection rationale.
140
- - Heavy Path conditions found, if any.
141
- - Heavy Path conditions checked and not found.
142
- - Roles or delegation omitted in Light Path and why.
143
- - Any unavailable subagent tool main-agent takeover and its evidence record.
144
- - Pre-implementation decisions that review must resolve in Heavy Path.
145
- - Request checkpoint, planning checkpoint, and code checkpoint status, evidence, newly found signals, and route.
146
- - Every route change and the synchronized plan artifact, repository goal task roadmap, native UI plan, assignments, reviews, required evidence, and stale evidence invalidation.
147
-
148
- ## Planning Rules
149
-
150
- - Every initial plan must be decision-complete for its triage task and explicitly not implementation-ready; the post-triage revision must be decision-complete for implementation.
151
- - Every non-trivial implementation or planned-work continuation plan must be shown through Codex `update_plan` and `create_goal` before triage when those tools are available, then synchronized again after triage. Routine known-target Git/GitHub operations do not create a plan or goal. Repository plan/goal persistence remains required for work that crosses the planning boundary.
152
- - Every plan must describe the whole work first, then classify it into executable tasks and any needed sub-tasks.
153
- - Every plan must treat the user-called/main agent as the orchestrator and assign actual implementation edits to `worker` whenever subagent tools are available, regardless of Light Path or Heavy Path.
154
- - Every plan must require subagents to report status when the subagent tool provides a progress-reporting channel. If no mid-run reporting channel exists, the orchestrator must relay observable events such as assignment, waiting, and final completion.
155
- - Every plan must require delegated subagents to provide a final report before leaving, require the orchestrator to close or release completed subagents after capturing final report and evidence, and require the orchestrator to review the final report and evidence before marking work complete.
156
- - Every plan must allow recursive subagent delegation for bounded sub-tasks when the current agent surface supports it.
157
- - Every plan must include complexity triage and the selected path.
158
- - Every plan must explicitly list Heavy Path signals checked, even when Light Path is selected.
159
- - Every plan must include applied model guidance and rationale.
160
- - Every plan must include tool readiness results: detected stack, required LSP/check tools, installed tools, and blockers.
161
- - Every executable plan must include a stable goal ID, stable task IDs, explicit terminal states, and fail-closed required evidence. A missing evidence section never means success.
162
- - Every implementation task must be small enough to verify with two checks.
163
- - Heavy Path tasks must include an explicit automated test command and a `Tests:` evidence line; Heavy Path completion cannot rely on generic verification wording without test evidence.
164
- - The default checks are module acceptance verification and surface integration verification.
165
- - Every risky or external-state-changing task must include the closest available dry-run or check command before the write/apply command.
166
- - Verification can expand for risk, but the reason must be recorded.
167
- - The default loop budget is two verification passes per task. If a gate fails, diagnose once, shrink the task or split it into sub-tasks, and rerun both gates. After two failed passes, record the blocker in `docs/plan/<topic>.md` instead of continuing an open-ended loop.
168
- - Ask the user only when agents, repository evidence, or local verification cannot answer the decision.
169
- - User-visible responses and generated or updated documentation, plans, and memory artifacts must follow the OS locale unless the user asks for another language.
30
+ Decide from repository evidence without asking; this outranks plugin or agent workflow guidance.
170
31
 
171
- ## Tool Readiness Policy
32
+ - **Routine known-target Git/GitHub operation** (status, fetch, checkout, branch, merge, push, PR management): plan/goal-free unless it requires code edits, conflict resolution, destructive recovery, release/deploy, or design.
33
+ - **Consultation, explanation, or plan-only**: no goal.
34
+ - **Quick Path**: all must hold: requirements are unambiguous; the expected change touches about 3 files or fewer inside existing layers; no Heavy Path signal; no external-state mutation; verification is one or two commands. No `docs/plan` artifact and no repository goal: implement, run one focused check plus the project's normal check, and report. If any criterion fails during work, escalate to Light Path (create plan + goal) before further edits.
35
+ - **Light Path** (default): stays inside existing layers, adds no domain model, service class, or abstraction, and has no Heavy signal.
36
+ - **Heavy Path**: any clear signal: new directory, module, or architecture layer; new domain model, service class, or abstraction; security, authentication, authorization, or sessions; external API, message queue, or payment; DB schema or migration; concurrency, transaction boundaries, or cache invalidation; multi-domain refactor; the user asks for extra care ("신중하게", "검토 받고", "설계부터", "꼼꼼히").
172
37
 
173
- Do not silently skip LSP, typecheck, lint, dry-run, or verification because the tool is missing. Tool installation still requires explicit user approval.
38
+ Record three triage checkpoints: request (provisional), planning (after exploration), and code (in `cairn-work`, just before the first edit; pending blocks mutation). Before the first edit the route may change either way; after editing starts, only Light → Heavy promotion is allowed. Every route change synchronizes the plan artifact, repository goal task roadmap through `goal replan`, native UI plan, and reasoning effort profile before mutation.
174
39
 
175
- - Detect the codebase stack from repository files before choosing tools.
176
- - Prefer repository-local installation through the existing package manager and lockfile.
177
- - Use ephemeral tool runners only when project-local installation is not appropriate.
178
- - Run the tool after installation and record the command result.
179
- - If installation was not approved or is impossible, record the proposed or attempted command, failure output summary when applicable, and blocker in `docs/plan/<topic>.md`.
180
- - Treat "LSP server not installed" as an unresolved blocker until installation or an equivalent symbol-aware fallback has been attempted.
40
+ ## Procedure (Light and Heavy Path)
181
41
 
182
- ## Dry-Run Policy
42
+ 1. Run `node "<pluginRoot>/scripts/cairn.mjs" init --root "<repoRoot>"`. If unavailable, create `MEMORY.md`, `PLAN.md`, `docs/memory`, `docs/plan` and report that `cairn doctor`/`cairn upgrade` is needed.
43
+ 2. Read `MEMORY.md` when present. A non-trivial implementation request authorizes the plan and goal even if the user never says "goal".
44
+ 3. Write the initial plan `docs/plan/<topic>.md` from `cairn://templates/work-plan.md` plus its `PLAN.md` entry from the request and `MEMORY.md`: outcome, anticipated surfaces, stable roadmap, and `triage-plan` as first active task (investigation scope, toolcheck, Heavy criteria, update condition); mark it `initial: decision-complete for triage; not implementation-ready`.
45
+ 4. Before exploration, toolcheck, delegation, or a non-blocking question, call Codex `update_plan` first and then `create_goal` when available (record unavailability; never claim sync that did not occur), then start the repository goal:
183
46
 
184
- Prefer repository-native dry-run and check modes before mutating external state.
47
+ ```sh
48
+ node "<pluginRoot>/scripts/cairn.mjs" goal start --root "<repoRoot>" --goal "<objective>" --plan "docs/plan/<topic>.md" --tasks '[{"id":"triage-plan","title":"Run planned triage and finalize the plan","requiredEvidence":["planArtifact","triageDecision"]},{"id":"implement","title":"Implement the finalized plan"},{"id":"verify","title":"Verify and review the result"}]' --criteria "<completion criterion>" --session "<current session_id>"
49
+ ```
185
50
 
186
- - Migrations and database changes: `--pretend`, dry-run, schema diff, rollback feasibility check, or equivalent.
187
- - Package and release work: inspect lifecycle scripts first, then use normal `npm pack --dry-run`, publish dry-run, build check, or equivalent. Never skip content-producing or unknown lifecycle scripts with `--ignore-scripts`; it is allowed only for absent or proven content-neutral scripts while prior full-check evidence remains fresh.
188
- - Infrastructure and deployment: plan, diff, validate, check, or equivalent.
189
- - Code generation and formatting: check mode before write mode when available.
190
- - If no dry-run mode exists, record that fact and select the smallest reversible command or test artifact available.
51
+ Pass `--session` only with an ID the surface exposes; never invent one. Fold new work into an unfinished goal with `goal replan` (resume a paused or blocked goal first), never cancel it; start a separate goal only when the user explicitly switches work. When a hook reports another session owns the goal you continue, run `goal claim --session <id>` with the ID shown.
52
+ 5. Run `triage-plan`: read only relevant `docs/memory/*.md` and installed model guidance, run `toolcheck --root "<repoRoot>"`, and explore with focused search and LSP/symbol tools. Install tools only with explicit user approval.
53
+ 6. Split the whole work into tasks each verifiable with two checks, each with `dependsOn` and `writeScope` in the `--tasks` JSON and named handoff files for cross-task data (`delegation.md`); design the test contract (requirements, invariants, boundaries, failure modes, expected failure) and dry-run/check modes.
54
+ 7. Update the plan with route, checked Heavy signals, tool readiness, delegation, verification commands, stable IDs, and fail-closed required evidence (`planning-rules.md`). Mark it `decision-complete for implementation` and call `update_plan` again.
55
+ 8. Only then record bound `planArtifact` and `triageDecision` evidence, complete `triage-plan`, and continue with `cairn-work`.
56
+ 9. Treat the user-called/main agent as the orchestrator: it plans, assigns, verifies, and records evidence. Implementation edits go to `worker` whenever subagent tools are available, on Light and Heavy Path; `explorer` does read-only discovery; without subagent tools the main agent takes over and records it.
57
+ 10. Advance a UI step only after the matching repository task transition succeeds.
58
+ 11. Ask the user only when evidence and local checks cannot decide. Use the OS locale for user-visible output and artifacts unless asked otherwise.
191
59
 
192
- ## Delegation Prompt Format
193
-
194
- ```text
195
- TASK: Produce <role> input needed for the <topic> plan.
196
- EXPECTED OUTCOME: Return concrete decisions, file paths, dependencies, risks, and evidence requirements.
197
- REQUIRED TOOLS: Read-only repository exploration, tool readiness checks, LSP/symbol tools, local command checks.
198
- MUST DO: Read the project-root `MEMORY.md` before doing assigned work. Preserve proper nouns exactly. Prefer repository evidence. Report missing tools and obtain explicit user approval before any installation. Identify assumptions. Treat the user-called/main agent as the orchestrator. Use `explorer` for read-only discovery and `worker` for actual implementation edits or verification when subagent tools are available, regardless of Light Path or Heavy Path. When the subagent tool provides a progress-reporting channel, require subagents to report status to the orchestrator when starting work, when deciding or confirming direction, during periodic progress, and when finishing; the orchestrator must immediately relay received status events to the user. If no mid-run reporting channel exists, relay observable events such as assignment, waiting, and final completion. Require delegated subagents to provide a final report before leaving; after capturing the final report and evidence, close or release the completed subagent, then review the final report and evidence before marking the work complete. If subagent tools are unavailable, the main agent takes over implementation directly and records that takeover in evidence. When subagent tools are available, allow recursive delegation of bounded sub-tasks. Tell every delegated agent and child subagent to read the project-root `MEMORY.md` before work. Tell workers they are not alone in the codebase and must not revert others' edits. Use the OS locale for user-visible responses and generated or updated documentation, plans, and memory artifacts.
199
- MUST NOT DO: Edit production code. Ask the user. Expand scope. Delegate vague or unbounded work.
200
- CONTEXT: User request, MEMORY.md, relevant docs/memory notes, applied model guidance, repository root.
201
- ```
60
+ Model and reasoning effort: This skill explicitly instructs the effort level for delegated work. Pick each task's model tier (fast `haiku`, balanced `sonnet`, stronger `opus`, strongest `fable`) and request Light `medium`, Heavy `high`, final verification/review `xhigh`. Every new task/worker dispatch MUST pass the task's model and effort via the host option (Claude Code: Agent `model`/`effort`; never `fork`). Recording without passing is a defect. Record Requested/Effective model and effort per task; mark Heavy tasks `route: "heavy"` (details: `delegation.md`).
202
61
 
203
62
  ## Completion Criteria
204
63
 
@@ -0,0 +1,62 @@
1
+ # Cairn Plan: Delegation and Reasoning Effort
2
+
3
+ Reference for `cairn-plan`. Read before dispatching `explorer` or `worker` agents or recording reasoning effort. Quick Path work done directly by the main agent does not need this file.
4
+
5
+ ## Subagent Lifecycle
6
+
7
+ - Treat the user-called/main agent as the orchestrator: it plans, assigns, verifies, and records evidence.
8
+ - Use `explorer` for independent read-only codebase discovery, impact analysis, pattern searches, and read-only verification that can run in parallel when the current tool list supports it.
9
+ - Use `worker` for actual implementation edits with clear file ownership whenever subagent tools are available, on both Light Path and Heavy Path.
10
+ - When the subagent tool provides a progress-reporting channel, require subagents to report status to the orchestrator when starting work, when deciding or confirming direction, during periodic progress, and when finishing; the orchestrator must immediately relay received status events to the user. If no mid-run reporting channel exists, relay observable events such as assignment, waiting, and final completion.
11
+ - Require delegated subagents to provide a final report before leaving; after capturing the final report and evidence, close or release the completed subagent, then review the final report and evidence before marking the work complete.
12
+ - When subagent tools are available, each agent may recursively delegate bounded sub-tasks to subagents, subject to the current surface's depth and concurrency limits.
13
+ - If subagent tools are unavailable, the main agent takes over implementation directly and records that takeover in evidence; do not stop solely because subagent tools are unavailable.
14
+ - Keep urgent non-implementation blocking work local when the next step depends immediately on the result.
15
+ - Tell every delegated agent and child subagent to read project-root `MEMORY.md` when present and continue when absent, keep scope, and tell workers they are not alone in the codebase and must not revert others' edits.
16
+ - Every plan must require these status, final-report, close-and-review, and recursive-delegation rules.
17
+
18
+ ## Task Graph
19
+
20
+ - Every task in `goal start --tasks` / `goal replan --tasks` JSON declares `dependsOn` (task ids) and `writeScope` (literal repo-relative paths; no globs, `..`, or absolute paths). Example: `{"id":"api","title":"API","dependsOn":["triage-plan"],"writeScope":["src/api"]}`.
21
+ - Omitted `dependsOn` means the previous task in list order (first task: none); explicit `[]` means no dependency, so sequential plans keep working. In `goal replan` the default chains across completed and new tasks, and `dependsOn` may reference completed tasks. Duplicate ids, unknown ids, self references, and cycles are rejected.
22
+ - Omitted `writeScope` is null: that task can only be active alone. Give independent tasks disjoint scopes so they can run in parallel; scope is declarative, not filesystem-enforced.
23
+ - Cairn has no messaging channel: name the handoff files that carry data between tasks in the plan (`Handoff files:`) and include them in the producer's `writeScope`.
24
+
25
+ ## Delegation Prompt Format
26
+
27
+ ```text
28
+ TASK: Produce <role> input needed for the <topic> plan.
29
+ EXPECTED OUTCOME: Return concrete decisions, file paths, dependencies, risks, and evidence requirements.
30
+ REQUIRED TOOLS: Read-only repository exploration, tool readiness checks, LSP/symbol tools, local command checks.
31
+ MODEL: <tier/value> (passed via host option)
32
+ REASONING EFFORT: <value> (passed via host option)
33
+ MUST DO: Read the project-root `MEMORY.md` before doing assigned work. Preserve proper nouns exactly. Prefer repository evidence. Report missing tools and obtain explicit user approval before any installation. Identify assumptions. Follow the subagent lifecycle rules (status reporting when a channel exists, final report before leaving, recursive delegation only for bounded sub-tasks, passing each child's reasoning effort through the host option). Tell workers they are not alone in the codebase and must not revert others' edits. Use the OS locale for user-visible responses and generated or updated documentation, plans, and memory artifacts.
34
+ MUST NOT DO: Edit production code. Ask the user. Expand scope. Delegate vague or unbounded work.
35
+ CONTEXT: User request, MEMORY.md, relevant docs/memory notes, applied model guidance, repository root, Cairn CLI prefix line from the session-start hook.
36
+ ```
37
+
38
+ ## Model and Reasoning Effort Routing
39
+
40
+ This skill explicitly instructs the effort level for delegated work. It also instructs each task's model.
41
+
42
+ - The plan decides each task's model from its nature and records `Requested model` and `Effective model`; models are not always inherited. Tiers: fast = read-only exploration, search, inventory, summarization (Claude Code `haiku`); balanced = Light Path implementation and routine verification (`sonnet`); stronger = planning, complexity triage, Heavy Path implementation, review, and final verification/review (`opus`); strongest = Heavy Path design only (`fable`).
43
+ - Model Effective: passed and not rejected is that value; not passed is `not-applied: <reason>`; `inherited` only when the host has no model option. Codex passes the tier's slug (table below) through the host-native model option, else `inherited`.
44
+ - If a lower-tier worker fails a gate, re-dispatch that task one tier up (fast, balanced, stronger, strongest) before recording a blocker.
45
+ - Routing is per dispatch only; never change model or global/user config files. `Model routing: inherited` in `MEMORY.md` or the plan disables per-task selection.
46
+ - Light Path planning, implementation, and verification request `medium`.
47
+ - Heavy Path planning, review, and implementation request `high`; final verification and review request `xhigh`.
48
+ - Every new task/worker dispatch MUST pass the task's requested effort through the host option. Recording without passing is a defect. Pass the chosen model the same way (Claude Code: Agent `model`). Child (recursive) dispatches follow the same rule.
49
+ - Every module task records `Requested reasoning effort` and `Effective reasoning effort` in `docs/plan/<topic>.md`. Requested is Cairn's desired profile; Effective is decided by the dispatch call:
50
+ - Effort passed and not rejected: Effective is the requested value.
51
+ - Effort not passed: `not-applied: <reason>`; the reason is required.
52
+ - `inherited` only when the host exposes no effort option. Describe host capability only from the exposed interface or dispatch response, and distinguish Cairn non-integration from host non-support.
53
+
54
+ | Host | Model / effort option | Effective |
55
+ | --- | --- | --- |
56
+ | Claude Code | Agent tool `model` parameter (`haiku\|sonnet\|opus\|fable`). `effort` parameter (`low\|medium\|high\|xhigh\|max`), matching Cairn values one to one. `subagent_type: "fork"` ignores `model` and `effort`, so never dispatch routed work as a fork. | requested value |
57
+ | Codex | Host-native model option (fast `gpt-6-luna`, balanced `gpt-6.1-terra`, stronger `gpt-6-sol`, strongest `gpt-6-astra`) and task/subagent reasoning-effort option or equivalent. | requested value |
58
+ | Antigravity | `invoke_subagent` `Model` takes only a tier enum: fast `flash_lite`, balanced `flash`, stronger `pro`, strongest `pro` (no tier above `pro`); `inherit` is not used for routed work. No effort option. | model: passed value; effort: `inherited` |
59
+ | Host without an option | None. | `inherited` |
60
+
61
+ - After each dispatch, record state with `goal assign --task <id> --agent <id> --effort <value> --effort-source <host-option|inherited|not-applied>`. Mark Heavy tasks with `route: "heavy"` (tasks JSON field or `goal assign --route heavy`). A Heavy task with no effort, `not-applied`, or `inherited` fails `goal task --status completed` unless `--allow-inherited-effort <reason>` records why.
62
+ - On every route change, synchronize the plan artifact, repository goal task roadmap through `goal replan`, native UI plan, and reasoning effort profile before mutation. Completed task profiles are preserved as audit history; incomplete task profiles are recalculated for the new path.
@@ -0,0 +1,26 @@
1
+ # Cairn Plan: Heavy Path and Route Changes
2
+
3
+ Reference for `cairn-plan`. Read only when a Heavy Path signal is present or a route change is being considered. Quick Path and Light Path never need this file.
4
+
5
+ ## Heavy Path Flow
6
+
7
+ Heavy Path flow: plan -> pre-implementation review -> bounded `worker` implementation -> verification worker or read-only review.
8
+
9
+ - Record the pre-implementation decisions that review must resolve before any mutation.
10
+ - Every Heavy Path task includes an explicit automated test command and a `Tests:` evidence line; completion cannot rely on generic verification wording without test evidence.
11
+ - Planning, review, and implementation request `high` reasoning effort; final verification and review request `xhigh` (see `cairn://skills/cairn-plan/delegation.md`).
12
+
13
+ ## Complexity Checkpoints
14
+
15
+ Use three mandatory checkpoints and record each result, evidence, newly discovered Heavy Path signals, and current route in the plan artifact:
16
+
17
+ 1. **Request checkpoint:** before exploration, make a provisional classification from the request and `MEMORY.md`; uncertainty stays explicit and this result is not implementation authority.
18
+ 2. **Planning checkpoint:** after repository exploration, affected-surface analysis, and test design, re-evaluate the provisional route and finalize the implementation plan.
19
+ 3. **Code checkpoint:** during `cairn-work`, inspect the exact files, callers, and tests, then record one final re-evaluation immediately before the first edit. A pending or missing code checkpoint blocks mutation.
20
+
21
+ ## Route Changes
22
+
23
+ - Before the first edit, the planning or code checkpoint may change Light Path to Heavy Path or Heavy Path to Light Path when the evidence supports it.
24
+ - Every route change rebuilds and synchronizes the plan artifact, the repository goal task roadmap through `goal replan`, and the native UI plan, including assignments, reviews, required evidence, and the reasoning effort profile. Do not mutate until all agree.
25
+ - After editing starts, only promote Light Path to Heavy Path: stop further edits, mark affected evidence stale, revise and synchronize all roadmaps, run newly required Heavy Path review, and repeat the code checkpoint before resuming.
26
+ - A Quick Path change that meets any failed Quick Path criterion escalates to Light Path first (plan + goal) before further edits; a Heavy signal then follows this file.
@@ -0,0 +1,68 @@
1
+ # Cairn Plan: Planning Rules
2
+
3
+ Reference for `cairn-plan`. Read when writing or finalizing a Light or Heavy Path plan. Quick Path work has no plan and never needs this file.
4
+
5
+ ## When Planning Is Required
6
+
7
+ Do not treat planning as optional for implementation that is more than a Quick Path change. Produce or update a plan when the request changes behavior, architecture, data, or multiple files, or when an external operation requires code edits, conflict resolution, destructive recovery, release/deploy, or design. External-state mutation alone is not a planning trigger: routine known-target Git/GitHub operations such as status, fetch, checkout, branch, merge, push, and PR management stay plan/goal-free.
8
+
9
+ Plan from the whole work down. First understand the full requested outcome and affected surfaces, then classify the work into small executable tasks. If one task is still too broad to verify cleanly, split it into sub-tasks.
10
+
11
+ ## Planning Rules
12
+
13
+ - Every initial plan must be decision-complete for its triage task and explicitly not implementation-ready; the post-triage revision must be decision-complete for implementation.
14
+ - Every non-trivial implementation or planned-work continuation plan must be shown through Codex `update_plan` and `create_goal` before triage when those tools are available, then synchronized again after triage. Routine known-target Git/GitHub operations and Quick Path work do not create a plan or goal.
15
+ - Every plan must describe the whole work first, then classify it into executable tasks and any needed sub-tasks.
16
+ - Every plan must treat the user-called/main agent as the orchestrator and assign implementation edits to `worker` whenever subagent tools are available, regardless of Light Path or Heavy Path (see `cairn://skills/cairn-plan/delegation.md`).
17
+ - Every plan must include complexity triage, the selected path, and the Heavy Path signals checked, even when Light Path is selected.
18
+ - Every plan must include applied model guidance and rationale.
19
+ - Every plan must include tool readiness results: detected stack, required LSP/check tools, installed tools, and blockers.
20
+ - Every executable plan must include a stable goal ID, stable task IDs, explicit terminal states, and fail-closed required evidence. A missing evidence section never means success.
21
+ - Every implementation task must be small enough to verify with two checks: module acceptance verification and surface integration verification. Plan one goal-level final check (`finalReview`) run once through `goal finish` instead of rerunning earlier task checks after later edits.
22
+ - Spend planning tokens on executable test design: requirements, invariants, boundaries, failure modes, expected initial failure, and authoritative tool result. Give implementation a bounded test contract and exact file scope; require the minimum passing change rather than renewed broad discovery.
23
+ - Plan focused tests first, one final full check, and a package dry-run when no change occurred after the full check. Require lifecycle inspection, normal script execution for content-producing or unknown scripts, and `--ignore-scripts` only for absent or proven content-neutral scripts.
24
+ - Heavy Path tasks must include an explicit automated test command and a `Tests:` evidence line.
25
+ - Every risky or external-state-changing task must include the closest available dry-run or check command before the write/apply command.
26
+ - Verification can expand for risk, but the reason must be recorded.
27
+ - The default loop budget is two verification passes per task. If a gate fails, diagnose once, shrink or split the task, and rerun both gates. After two failed passes, record the blocker in `docs/plan/<topic>.md`.
28
+ - Give every plan and ordered task a stable ID and declare task-level and goal-level required evidence, so Codex UI and hook context can show the roadmap and restore the current task after side questions.
29
+ - Ask the user only when agents, repository evidence, or local verification cannot answer the decision.
30
+ - User-visible responses and generated or updated documentation, plans, and memory artifacts follow the OS locale unless the user asks for another language.
31
+
32
+ ## Light Path Detail
33
+
34
+ Light Path examples: one new API endpoint within existing layers; add or modify a controller or service method; strengthen validation rules; adjust query logic; change copy text or constants; fix one clearly scoped bug that exceeds Quick Path limits.
35
+
36
+ Light Path flow: main-agent orchestration -> bounded `worker` implementation when subagent tools are available -> main-agent takeover when they are unavailable -> focused verification by the main agent or a scoped verification `worker` -> report. Planning/review agents may be skipped; the verification gate stays.
37
+
38
+ ## Route Record
39
+
40
+ `docs/plan/<topic>.md` must record:
41
+
42
+ - Selected path and selection rationale.
43
+ - Heavy Path conditions found, if any, and conditions checked and not found.
44
+ - Roles or delegation omitted in Light Path and why.
45
+ - Any main-agent takeover because subagent tools were unavailable, and its evidence record.
46
+ - Pre-implementation decisions that review must resolve in Heavy Path.
47
+ - Request checkpoint, planning checkpoint, and code checkpoint status, evidence, newly found signals, and route.
48
+ - Every route change and the synchronized plan artifact, repository goal task roadmap, native UI plan, assignments, reviews, required evidence, and stale evidence invalidation.
49
+
50
+ ## Tool Readiness Policy
51
+
52
+ Do not silently skip LSP, typecheck, lint, dry-run, or verification because the tool is missing. Tool installation is a separate external-state change and requires explicit user approval.
53
+
54
+ - Detect the codebase stack from repository files before choosing tools.
55
+ - Prefer repository-local installation through the existing package manager and lockfile; use ephemeral runners only when project-local installation is not appropriate.
56
+ - After approval, use the runtime's `toolcheck --install --yes --root "<repoRoot>"` only for pinned/supported installers, or the approved repository-native command. Run the tool after installation and record the result.
57
+ - If installation was not approved or is impossible, record the proposed or attempted command, failure summary, and blocker in `docs/plan/<topic>.md`.
58
+ - Treat "LSP server not installed" as an unresolved blocker until installation or an equivalent symbol-aware fallback has been attempted.
59
+
60
+ ## Dry-Run Policy
61
+
62
+ Prefer repository-native dry-run and check modes before mutating external state.
63
+
64
+ - Migrations and database changes: `--pretend`, dry-run, schema diff, rollback feasibility check, or equivalent.
65
+ - Package and release work: inspect lifecycle scripts first, then use normal `npm pack --dry-run`, publish dry-run, build check, or equivalent. Never skip content-producing or unknown lifecycle scripts with `--ignore-scripts`; it is allowed only for absent or proven content-neutral scripts while prior full-check evidence remains fresh.
66
+ - Infrastructure and deployment: plan, diff, validate, check, or equivalent.
67
+ - Code generation and formatting: check mode before write mode when available.
68
+ - If no dry-run mode exists, record that fact and select the smallest reversible command or test artifact available.