cairn-ai 0.1.2

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 (58) hide show
  1. package/.agents/workflows/cairn-doctor.md +22 -0
  2. package/.agents/workflows/cairn-install.md +17 -0
  3. package/.agents/workflows/cairn-memory.md +15 -0
  4. package/.agents/workflows/cairn-plan.md +21 -0
  5. package/.agents/workflows/cairn-review.md +14 -0
  6. package/.agents/workflows/cairn-toolcheck.md +17 -0
  7. package/.agents/workflows/cairn-uninstall.md +17 -0
  8. package/.agents/workflows/cairn-upgrade.md +17 -0
  9. package/.agents/workflows/cairn-work.md +20 -0
  10. package/.claude/agents/explorer.md +5 -0
  11. package/.claude/agents/worker.md +5 -0
  12. package/.claude/commands/cairn-doctor.md +13 -0
  13. package/.claude/commands/cairn-install.md +13 -0
  14. package/.claude/commands/cairn-memory.md +5 -0
  15. package/.claude/commands/cairn-plan.md +5 -0
  16. package/.claude/commands/cairn-review.md +5 -0
  17. package/.claude/commands/cairn-toolcheck.md +10 -0
  18. package/.claude/commands/cairn-uninstall.md +13 -0
  19. package/.claude/commands/cairn-upgrade.md +13 -0
  20. package/.claude/commands/cairn-work.md +5 -0
  21. package/.codex-plugin/plugin.json +30 -0
  22. package/LICENSE +21 -0
  23. package/README.de.md +130 -0
  24. package/README.es.md +130 -0
  25. package/README.fr.md +130 -0
  26. package/README.ja.md +130 -0
  27. package/README.ko.md +130 -0
  28. package/README.md +138 -0
  29. package/README.pt.md +130 -0
  30. package/README.zh.md +130 -0
  31. package/agents/explorer.md +31 -0
  32. package/agents/worker.md +32 -0
  33. package/commands/cairn-doctor.md +27 -0
  34. package/commands/cairn-install.md +24 -0
  35. package/commands/cairn-memory.md +17 -0
  36. package/commands/cairn-plan.md +23 -0
  37. package/commands/cairn-review.md +16 -0
  38. package/commands/cairn-toolcheck.md +19 -0
  39. package/commands/cairn-uninstall.md +24 -0
  40. package/commands/cairn-upgrade.md +23 -0
  41. package/commands/cairn-work.md +22 -0
  42. package/docs/model-guidance/README.md +31 -0
  43. package/docs/model-guidance/claude.md +46 -0
  44. package/docs/model-guidance/codex.md +48 -0
  45. package/hooks/hooks.json +65 -0
  46. package/package.json +49 -0
  47. package/scripts/cairn +115 -0
  48. package/scripts/cairn-lifecycle.mjs +343 -0
  49. package/scripts/cairn-state.sh +104 -0
  50. package/scripts/cairn-toolcheck.mjs +205 -0
  51. package/skills/cairn-memory/SKILL.md +40 -0
  52. package/skills/cairn-plan/SKILL.md +137 -0
  53. package/skills/cairn-review/SKILL.md +44 -0
  54. package/skills/cairn-work/SKILL.md +81 -0
  55. package/templates/MEMORY.md +14 -0
  56. package/templates/PLAN.md +17 -0
  57. package/templates/domain-memory.md +20 -0
  58. package/templates/work-plan.md +86 -0
@@ -0,0 +1,104 @@
1
+ #!/bin/sh
2
+ set -eu
3
+
4
+ event="${1:-manual}"
5
+ root="${HARNESS_REPO_ROOT:-$(pwd)}"
6
+ locale="${LC_ALL:-${LC_MESSAGES:-${LANG:-en}}}"
7
+
8
+ mkdir -p "$root/docs/memory" "$root/docs/plan"
9
+
10
+ memory="$root/MEMORY.md"
11
+ plan="$root/PLAN.md"
12
+
13
+ if [ ! -f "$memory" ]; then
14
+ cat > "$memory" <<'EOF'
15
+ # MEMORY
16
+
17
+ This file is a short index of persistent repository knowledge.
18
+
19
+ ## Domain Knowledge
20
+
21
+ - Link detailed notes under `docs/memory/`.
22
+
23
+ ## Policy
24
+
25
+ - Prefer precise repository exploration before implementation.
26
+ - Preserve proper nouns, file names, variable names, service names, alert names, MCP tool names, and agent names exactly as written.
27
+ - Read only the detailed memory files needed for the current task.
28
+ - Write user-visible responses and artifacts in the OS locale unless the user asks for another language.
29
+
30
+ ## Update Rules
31
+
32
+ - Keep root files short.
33
+ - Move detailed domain knowledge to `docs/memory/<domain>.md`.
34
+ - Record facts with source paths, commands, and observed behavior.
35
+ EOF
36
+ fi
37
+
38
+ if [ ! -f "$plan" ]; then
39
+ cat > "$plan" <<'EOF'
40
+ # PLAN
41
+
42
+ This file is a short index of active and completed work plans.
43
+
44
+ ## Active Plans
45
+
46
+ - Link detailed plans under `docs/plan/`.
47
+
48
+ ## Completed Plans
49
+
50
+ - Move completed topics here with evidence links.
51
+
52
+ ## Planning Rules
53
+
54
+ - Plans must be decision-complete before implementation.
55
+ - Split implementation into small module slices.
56
+ - Detect repository stack and required LSP/check tools before implementation.
57
+ - Install or bootstrap missing required tools before declaring them unavailable.
58
+ - Each slice normally passes exactly two gates.
59
+ - Module acceptance verification.
60
+ - Surface integration verification.
61
+ - Run dry-run or check mode before external-state mutation when available.
62
+ - Use at most two verification passes per slice by default.
63
+ - If a gate fails, diagnose once, shrink or split the slice, and rerun both gates.
64
+ - After two failed passes, record the blocker in `docs/plan/<topic>.md`.
65
+ EOF
66
+ fi
67
+
68
+ is_ko() {
69
+ case "$locale" in
70
+ ko*|KO*) return 0 ;;
71
+ *) return 1 ;;
72
+ esac
73
+ }
74
+
75
+ case "$event" in
76
+ session-start|user-prompt-submit)
77
+ if is_ko; then
78
+ printf '%s\n' "Cairn 컨텍스트: 먼저 MEMORY.md와 PLAN.md를 읽고, 필요한 경우 toolcheck로 LSP/check 도구 준비 상태를 확인하세요."
79
+ else
80
+ printf '%s\n' "Cairn context: read MEMORY.md and PLAN.md first, then run toolcheck when LSP/check tool readiness is needed."
81
+ fi
82
+ ;;
83
+ post-tool-use)
84
+ if is_ko; then
85
+ printf '%s\n' "Cairn 점검: 외부 상태 변경에는 dry-run/check 증거가 필요하고, 동작이 바뀌었다면 docs/plan 증거를 갱신하세요."
86
+ else
87
+ printf '%s\n' "Cairn check: external-state changes need dry-run/check evidence; if behavior changed, update docs/plan evidence."
88
+ fi
89
+ ;;
90
+ stop|subagent-stop)
91
+ if is_ko; then
92
+ printf '%s\n' "Cairn 종료 게이트: 완료에는 docs/plan의 dry-run/check, 모듈 수용, 표면 통합 증거가 필요합니다."
93
+ else
94
+ printf '%s\n' "Cairn stop gate: completion requires dry-run/check, module acceptance, and surface integration evidence in docs/plan."
95
+ fi
96
+ ;;
97
+ *)
98
+ if is_ko; then
99
+ printf '%s\n' "Cairn이 MEMORY.md, PLAN.md, docs/memory, docs/plan을 초기화했습니다."
100
+ else
101
+ printf '%s\n' "Cairn initialized MEMORY.md, PLAN.md, docs/memory, and docs/plan."
102
+ fi
103
+ ;;
104
+ esac
@@ -0,0 +1,205 @@
1
+ #!/usr/bin/env node
2
+ import { readdir, stat } from "node:fs/promises";
3
+ import { join } from "node:path";
4
+ import { spawnSync } from "node:child_process";
5
+ import { pathToFileURL } from "node:url";
6
+
7
+ if (isCliEntry()) {
8
+ const root = process.cwd();
9
+ const install = process.argv.includes("--install");
10
+ const json = process.argv.includes("--json");
11
+ const report = await createReport({ root, install });
12
+
13
+ if (json) {
14
+ console.log(JSON.stringify(report, null, 2));
15
+ } else {
16
+ console.log(`Cairn toolcheck: ${report.root}`);
17
+ console.log(`Detected stacks: ${report.detected.length > 0 ? report.detected.join(", ") : "none"}`);
18
+ for (const result of report.results) {
19
+ const prefix = result.ok ? "OK" : "MISSING";
20
+ const installedText = result.installed ? " installed" : "";
21
+ console.log(`${prefix}${installedText} ${result.name} - ${result.reason}`);
22
+ if (!result.ok && result.installCommand) console.log(` install: ${result.installCommand}`);
23
+ }
24
+ }
25
+
26
+ if (report.results.some((result) => !result.ok)) process.exitCode = 1;
27
+ }
28
+
29
+ export async function createReport({ root = process.cwd(), install = false, runner = run } = {}) {
30
+ const entries = await collectEntries(root);
31
+ const detected = detectStacks(entries);
32
+ const requirements = buildRequirements(detected, entries, (command, args) => commandOk(command, args, root, runner));
33
+ const results = [];
34
+
35
+ for (const requirement of requirements) {
36
+ let ok = commandOk(requirement.command, requirement.args, root, runner);
37
+ let installed = false;
38
+ let installResult = null;
39
+ if (!ok && install && requirement.install) {
40
+ installResult = runner(requirement.install.command, requirement.install.args);
41
+ installed = installResult.status === 0;
42
+ ok = commandOk(requirement.command, requirement.args, root, runner);
43
+ }
44
+ results.push({
45
+ name: requirement.name,
46
+ reason: requirement.reason,
47
+ ok,
48
+ installed,
49
+ installCommand: requirement.install ? [requirement.install.command, ...requirement.install.args].join(" ") : null,
50
+ installStatus: installResult?.status ?? null,
51
+ });
52
+ }
53
+
54
+ return { root, detected, results };
55
+ }
56
+
57
+ export async function collectEntries(base) {
58
+ const output = [];
59
+ async function walk(dir) {
60
+ for (const entry of await readdir(dir)) {
61
+ if ([".git", ".cairn", "node_modules", "vendor", "target", ".venv", "__pycache__"].includes(entry)) continue;
62
+ const path = join(dir, entry);
63
+ const relativePath = path.slice(base.length + 1);
64
+ if (relativePath === "test/fixtures" || relativePath.startsWith("test/fixtures/")) continue;
65
+ const info = await stat(path);
66
+ if (info.isDirectory()) await walk(path);
67
+ else output.push(relativePath);
68
+ }
69
+ }
70
+ await walk(base);
71
+ return output;
72
+ }
73
+
74
+ export function detectStacks(paths) {
75
+ const stacks = new Set();
76
+ if (paths.some((path) => path === "package.json")) stacks.add("javascript");
77
+ if (paths.some((path) => path === "tsconfig.json" || path.endsWith(".ts") || path.endsWith(".tsx"))) stacks.add("typescript");
78
+ if (paths.some((path) => path === "pyproject.toml" || path.endsWith(".py"))) stacks.add("python");
79
+ if (paths.some((path) => path === "composer.json" || path.endsWith(".php"))) stacks.add("php");
80
+ if (paths.some((path) => path === "pom.xml" || path === "build.gradle" || path.endsWith(".java"))) stacks.add("java");
81
+ if (paths.some((path) => path.endsWith(".kt") || path.endsWith(".kts"))) stacks.add("kotlin");
82
+ if (paths.some((path) => path === "Package.swift" || path.endsWith(".xcodeproj") || path.endsWith(".xcworkspace") || path.endsWith(".swift"))) stacks.add("swift");
83
+ if (paths.some((path) => path === "go.mod" || path.endsWith(".go"))) stacks.add("go");
84
+ if (paths.some((path) => path === "Cargo.toml" || path.endsWith(".rs"))) stacks.add("rust");
85
+ return [...stacks];
86
+ }
87
+
88
+ export function buildRequirements(stacks, entries = [], commandAvailable = commandOk) {
89
+ const requirements = [];
90
+ if (stacks.includes("javascript")) {
91
+ requirements.push(req("node", ["--version"], "JavaScript runtime for package scripts and CLI checks"));
92
+ }
93
+ if (stacks.includes("typescript")) {
94
+ const pm = packageManager(entries);
95
+ requirements.push(req("typescript-language-server", ["--version"], "TypeScript LSP server", installDev(pm, ["typescript", "typescript-language-server"])));
96
+ requirements.push(req("tsc", ["--version"], "TypeScript compiler verification", installDev(pm, ["typescript"])));
97
+ }
98
+ if (stacks.includes("python")) {
99
+ const uv = commandAvailable("uv", ["--version"]);
100
+ const project = entries.includes("pyproject.toml");
101
+ const basedpyrightInstall = pythonInstall(uv, project, "basedpyright");
102
+ const ruffInstall = pythonInstall(uv, project, "ruff");
103
+ requirements.push(req("basedpyright", ["--version"], "Python LSP/type checker", basedpyrightInstall));
104
+ requirements.push(req("ruff", ["--version"], "Python lint and format checker", ruffInstall));
105
+ }
106
+ if (stacks.includes("php")) {
107
+ const composerProject = entries.includes("composer.json");
108
+ const composerTools = ["phpactor/phpactor", "phpstan/phpstan", "friendsofphp/php-cs-fixer"];
109
+ requirements.push(req("php", ["--version"], "PHP runtime for Composer scripts and CLI checks"));
110
+ if (composerProject) requirements.push(req("composer", ["--version"], "PHP package manager for project-local tool installation"));
111
+ requirements.push(req("phpactor", ["--version"], "PHP LSP server", composerProject ? composerInstall(composerTools) : null));
112
+ requirements.push(req("phpstan", ["--version"], "PHP static analysis verification", composerProject ? composerInstall(composerTools) : null));
113
+ requirements.push(req("php-cs-fixer", ["--version"], "PHP formatting verification", composerProject ? composerInstall(composerTools) : null));
114
+ }
115
+ if (stacks.includes("java")) {
116
+ addJvmRequirements(requirements);
117
+ requirements.push(req("jdtls", ["--version"], "Java LSP server", { command: "bash", args: ["-lc", "mkdir -p .cairn/tools && curl -L https://download.eclipse.org/jdtls/milestones/latest/jdt-language-server-latest.tar.gz | tar -xz -C .cairn/tools"] }));
118
+ addJvmBuildToolRequirements(requirements, entries);
119
+ }
120
+ if (stacks.includes("kotlin")) {
121
+ addJvmRequirements(requirements);
122
+ requirements.push(req("kotlin-lsp.sh", ["--help"], "Kotlin LSP server"));
123
+ requirements.push(req("kotlinc", ["-version"], "Kotlin compiler verification"));
124
+ addJvmBuildToolRequirements(requirements, entries);
125
+ }
126
+ if (stacks.includes("swift")) {
127
+ requirements.push(req("swift", ["--version"], "Swift toolchain for build and test commands"));
128
+ requirements.push(req("sourcekit-lsp", ["--version"], "Swift LSP server"));
129
+ if (entries.some((path) => path.endsWith(".xcodeproj") || path.endsWith(".xcworkspace"))) {
130
+ requirements.push(req("xcodebuild", ["-version"], "Xcode build verification"));
131
+ }
132
+ }
133
+ if (stacks.includes("go")) {
134
+ requirements.push(req("gopls", ["version"], "Go LSP server", { command: "go", args: ["install", "golang.org/x/tools/gopls@latest"] }));
135
+ requirements.push(req("golangci-lint", ["--version"], "Go lint verification", { command: "go", args: ["install", "github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest"] }));
136
+ }
137
+ if (stacks.includes("rust")) {
138
+ requirements.push(req("rust-analyzer", ["--version"], "Rust LSP server", { command: "rustup", args: ["component", "add", "rust-analyzer"] }));
139
+ requirements.push(req("cargo", ["clippy", "--version"], "Rust clippy verification", { command: "rustup", args: ["component", "add", "clippy"] }));
140
+ }
141
+ return requirements;
142
+ }
143
+
144
+ export function addJvmRequirements(requirements) {
145
+ if (!requirements.some((requirement) => requirement.name === "java")) {
146
+ requirements.push(req("java", ["--version"], "JVM runtime for build and test commands"));
147
+ }
148
+ if (!requirements.some((requirement) => requirement.name === "javac")) {
149
+ requirements.push(req("javac", ["--version"], "JVM compiler verification"));
150
+ }
151
+ }
152
+
153
+ export function addJvmBuildToolRequirements(requirements, entries = []) {
154
+ if (entries.includes("gradlew")) pushUnique(requirements, req("./gradlew", ["--version"], "Gradle wrapper availability"));
155
+ else if (entries.includes("build.gradle") || entries.includes("build.gradle.kts")) pushUnique(requirements, req("gradle", ["--version"], "Gradle availability"));
156
+ if (entries.includes("mvnw")) pushUnique(requirements, req("./mvnw", ["--version"], "Maven wrapper availability"));
157
+ else if (entries.includes("pom.xml")) pushUnique(requirements, req("mvn", ["--version"], "Maven availability"));
158
+ }
159
+
160
+ export function pushUnique(requirements, requirement) {
161
+ if (!requirements.some((candidate) => candidate.name === requirement.name)) requirements.push(requirement);
162
+ }
163
+
164
+ export function composerInstall(packages) {
165
+ return { command: "composer", args: ["require", "--dev", ...packages] };
166
+ }
167
+
168
+ export function pythonInstall(uv, project, tool) {
169
+ if (uv && project) return { command: "uv", args: ["add", "--dev", tool] };
170
+ if (uv) return { command: "uv", args: ["tool", "install", tool] };
171
+ return { command: "python3", args: ["-m", "pip", "install", "--user", tool] };
172
+ }
173
+
174
+ export function req(command, args, reason, installCommand = null) {
175
+ return { name: command, command, args, reason, install: installCommand };
176
+ }
177
+
178
+ export function packageManager(entries = []) {
179
+ if (entries.includes("bun.lockb") || entries.includes("bun.lock")) return "bun";
180
+ if (entries.includes("pnpm-lock.yaml")) return "pnpm";
181
+ if (entries.includes("yarn.lock")) return "yarn";
182
+ return "npm";
183
+ }
184
+
185
+ export function installDev(pm, packages) {
186
+ if (pm === "bun") return { command: "bun", args: ["add", "-d", ...packages] };
187
+ if (pm === "pnpm") return { command: "pnpm", args: ["add", "-D", ...packages] };
188
+ if (pm === "yarn") return { command: "yarn", args: ["add", "-D", ...packages] };
189
+ return { command: "npm", args: ["install", "--save-dev", ...packages] };
190
+ }
191
+
192
+ export function commandOk(command, args, root = process.cwd(), runner = run) {
193
+ if (runner(command, args).status === 0) return true;
194
+ if (runner(join(root, "node_modules", ".bin", command), args).status === 0) return true;
195
+ if (runner(join(root, "vendor", "bin", command), args).status === 0) return true;
196
+ return runner(join(root, ".cairn", "tools", "bin", command), args).status === 0;
197
+ }
198
+
199
+ export function run(command, args) {
200
+ return spawnSync(command, args, { stdio: "ignore", encoding: "utf8" });
201
+ }
202
+
203
+ function isCliEntry() {
204
+ return process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href;
205
+ }
@@ -0,0 +1,40 @@
1
+ ---
2
+ name: cairn-memory
3
+ description: Create and maintain repository MEMORY.md and docs/memory domain notes for token-efficient Codex, Claude Code, and Antigravity agent work.
4
+ ---
5
+
6
+ # Cairn Memory
7
+
8
+ Use this when domain knowledge, repository policy, or pre-plan context compression is needed.
9
+
10
+ ## Purpose
11
+
12
+ The root `MEMORY.md` is an index, not detailed knowledge. Record details in `docs/memory/<domain>.md`.
13
+
14
+ ## Procedure
15
+
16
+ 1. Run `scripts/cairn-state.sh manual` if it exists. Otherwise ensure `MEMORY.md`, `PLAN.md`, `docs/memory`, and `docs/plan` directly.
17
+ 2. Explore the repository before asking the user.
18
+ 3. Delegate when it materially improves speed or quality instead of asking the user.
19
+ - `explorer`: read-only domain discovery, boundaries, invariants, policies, contradictions, and stale facts when available.
20
+ - `worker`: exact file paths, commands, schemas, references, and bounded evidence capture.
21
+ 4. Write detailed facts to `docs/memory/<domain>.md`.
22
+ 5. Keep only one-line links and summaries in `MEMORY.md`.
23
+ 6. Write user-visible output in the OS locale unless the user asks for another language.
24
+
25
+ ## Delegation Prompt Format
26
+
27
+ ```text
28
+ TASK: Explore persistent domain knowledge for <domain>.
29
+ EXPECTED OUTCOME: Return facts, source paths, and proof commands concisely.
30
+ REQUIRED TOOLS: Read-only file search, LSP/symbol tools, command checks.
31
+ MUST DO: Preserve proper nouns exactly. Cite local paths. Separate facts from inference. Use the OS locale for user-visible text.
32
+ MUST NOT DO: Edit files. Ask the user. Guess missing names.
33
+ CONTEXT: Current task, repository root, existing MEMORY.md entries.
34
+ ```
35
+
36
+ ## Completion Criteria
37
+
38
+ - `MEMORY.md` links to detailed notes.
39
+ - Detailed notes have clear scope and sources, and are shorter than reading the original files wholesale.
40
+ - Long explanations are not duplicated in the root index.
@@ -0,0 +1,137 @@
1
+ ---
2
+ name: cairn-plan
3
+ description: Create decision-complete PLAN.md and docs/plan plans through agent delegation instead of user questions.
4
+ ---
5
+
6
+ # Cairn Plan
7
+
8
+ Use this when planning implementation, refactoring, migrations, debugging, or repository automation.
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
+ ## Procedure
15
+
16
+ 1. Run `scripts/cairn-state.sh manual` if it exists. Otherwise ensure `MEMORY.md`, `PLAN.md`, `docs/memory`, and `docs/plan` directly.
17
+ 2. Read only `MEMORY.md` and relevant `docs/memory/*.md` files.
18
+ 3. Based on the active or assigned model, read `docs/model-guidance/README.md` and only the relevant model guidance.
19
+ 4. Run `scripts/cairn toolcheck` when available, or `scripts/cairn-toolcheck.mjs` directly, to identify repository stacks and required tools.
20
+ 5. If LSP, typecheck, lint, dry-run, or verification tools are missing, run `scripts/cairn toolcheck --install` or the closest repository-native install command before treating the tool as unavailable.
21
+ 6. Explore the repository with focused search and LSP/symbol tools after tool readiness is confirmed.
22
+ 7. Identify the closest available dry-run or check mode for every slice that can mutate external state.
23
+ 8. Run complexity triage before applying workflow guidance from agents, plugins, or delegated roles.
24
+ 9. Delegate according to the selected path and model guidance instead of asking the user.
25
+ - 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.
26
+ - Use `worker` for bounded implementation slices with clear file ownership, disjoint write scope, or verification tasks that can run while the main session continues.
27
+ - Keep urgent blocking work local when the next step depends immediately on the result.
28
+ - Tell workers they are not alone in the codebase and must not revert others' edits.
29
+ 10. Create `docs/plan/<topic>.md` from `templates/work-plan.md`.
30
+ 11. Add a short index entry to `PLAN.md`.
31
+ 12. Write user-visible output in the OS locale unless the user asks for another language.
32
+
33
+ ## Complexity Triage
34
+
35
+ Decide triage from repository evidence without asking the user.
36
+
37
+ 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.
38
+
39
+ ### Light Path
40
+
41
+ Use Light Path for narrow changes inside existing architecture layers. Skip planning/review agents and implement directly or with one `worker`, but keep the verification gate.
42
+
43
+ Light Path conditions:
44
+
45
+ - The change stays inside existing architecture layers.
46
+ - No new domain model, service class, or abstraction is introduced.
47
+ - No security, authentication, authorization, session, external API, message queue, payment, DB schema, migration, concurrency, transaction-boundary, or cache-invalidation change is involved.
48
+
49
+ Light Path examples:
50
+
51
+ - One new API endpoint within existing layers.
52
+ - Add or modify a controller or service method.
53
+ - Strengthen validation rules.
54
+ - Adjust query logic.
55
+ - Change copy text or constants.
56
+ - Fix one clearly scoped bug.
57
+
58
+ Light Path flow: direct edit or single `worker` -> 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.
59
+
60
+ ### Heavy Path
61
+
62
+ Use Heavy Path when the request clearly needs the full planning and review pipeline.
63
+
64
+ Heavy Path conditions:
65
+
66
+ - Creating a new directory, module, or architecture layer.
67
+ - Introducing a new domain model, service class, or abstraction.
68
+ - Changing security, authentication, authorization, or sessions.
69
+ - Integrating an external API, message queue, or payment flow.
70
+ - Changing DB schema or migrations.
71
+ - Changing concurrency, transaction boundaries, or cache invalidation.
72
+ - Refactoring across multiple domains.
73
+ - The user signals extra care, such as "신중하게", "검토 받고", "설계부터", or "꼼꼼히".
74
+
75
+ Heavy Path flow: plan -> pre-implementation review -> bounded `worker` implementation -> verification worker or read-only review.
76
+
77
+ ### Route Record
78
+
79
+ `docs/plan/<topic>.md` must record:
80
+
81
+ - Selected path.
82
+ - Selection rationale.
83
+ - Heavy Path conditions found, if any.
84
+ - Roles or delegation omitted in Light Path and why.
85
+ - Pre-implementation decisions that review must resolve in Heavy Path.
86
+
87
+ ## Planning Rules
88
+
89
+ - Every plan must be decision-complete.
90
+ - Every plan must include complexity triage and the selected path.
91
+ - Every plan must include applied model guidance and rationale.
92
+ - Every plan must include tool readiness results: detected stack, required LSP/check tools, installed tools, and blockers.
93
+ - Every implementation slice must be small enough to verify with two checks.
94
+ - The default checks are module acceptance verification and surface integration verification.
95
+ - Every risky or external-state-changing slice must include the closest available dry-run or check command before the write/apply command.
96
+ - Verification can expand for risk, but the reason must be recorded.
97
+ - The default loop budget is two verification passes per slice. If a gate fails, diagnose once, shrink or split the slice, and rerun both gates. After two failed passes, record the blocker in `docs/plan/<topic>.md` instead of continuing an open-ended loop.
98
+ - Ask the user only when agents, repository evidence, or local verification cannot answer the decision.
99
+ - User-visible text must follow the OS locale unless the user asks for another language.
100
+
101
+ ## Tool Readiness Policy
102
+
103
+ Do not skip LSP, typecheck, lint, dry-run, or verification because the tool is missing.
104
+
105
+ - Detect the codebase stack from repository files before choosing tools.
106
+ - Prefer repository-local installation through the existing package manager and lockfile.
107
+ - Use ephemeral tool runners only when project-local installation is not appropriate.
108
+ - Run the tool after installation and record the command result.
109
+ - If installation is impossible, record the command tried, failure output summary, and blocker in `docs/plan/<topic>.md`.
110
+ - Treat "LSP server not installed" as an unresolved blocker until installation or an equivalent symbol-aware fallback has been attempted.
111
+
112
+ ## Dry-Run Policy
113
+
114
+ Prefer repository-native dry-run and check modes before mutating external state.
115
+
116
+ - Migrations and database changes: `--pretend`, dry-run, schema diff, rollback feasibility check, or equivalent.
117
+ - Package and release work: `npm pack --dry-run`, publish dry-run, build check, or equivalent.
118
+ - Infrastructure and deployment: plan, diff, validate, check, or equivalent.
119
+ - Code generation and formatting: check mode before write mode when available.
120
+ - If no dry-run mode exists, record that fact and select the smallest reversible command or test artifact available.
121
+
122
+ ## Delegation Prompt Format
123
+
124
+ ```text
125
+ TASK: Produce <role> input needed for the <topic> plan.
126
+ EXPECTED OUTCOME: Return concrete decisions, file paths, dependencies, risks, and evidence requirements.
127
+ REQUIRED TOOLS: Read-only repository exploration, tool readiness checks, LSP/symbol tools, local command checks.
128
+ MUST DO: Preserve proper nouns exactly. Prefer repository evidence. Install or bootstrap missing required tools before declaring them unavailable. Identify assumptions. Use `explorer` for read-only discovery and `worker` for bounded implementation or verification when available and useful. Tell workers they are not alone in the codebase and must not revert others' edits. Use the OS locale for user-visible text.
129
+ MUST NOT DO: Edit production code. Ask the user. Expand scope.
130
+ CONTEXT: User request, MEMORY.md, relevant docs/memory notes, applied model guidance, repository root.
131
+ ```
132
+
133
+ ## Completion Criteria
134
+
135
+ - `PLAN.md` references the plan topic.
136
+ - `docs/plan/<topic>.md` includes goal, memory inputs, model guidance, tool readiness, complexity triage, selected path, agent assignments, module slices, and two checks per slice.
137
+ - The next implementation task can run without making planning decisions.
@@ -0,0 +1,44 @@
1
+ ---
2
+ name: cairn-review
3
+ description: Review completed Cairn slices against MEMORY.md, PLAN.md, domain policy, and two-gate evidence.
4
+ ---
5
+
6
+ # Cairn Review
7
+
8
+ Use this after meaningful implementation with Cairn.
9
+
10
+ ## Purpose
11
+
12
+ Review is not another implementation loop. Confirm that the completed slice satisfies the plan and that memory and plan artifacts are useful to the next agent.
13
+
14
+ ## Procedure
15
+
16
+ 1. Read the completed slice in `docs/plan/<topic>.md`.
17
+ 2. Read `MEMORY.md` and relevant `docs/memory/*.md`.
18
+ 3. Check changed files, tool readiness evidence, and evidence paths.
19
+ 4. Delegate independent review when it materially improves speed or quality and the current tool policy allows it.
20
+ - Use `explorer` for read-only impact analysis, pattern checks, and independent diff inspection.
21
+ - Use `worker` for scoped verification command re-runs or QA artifact capture.
22
+ - Keep blocking review work local when the next step depends immediately on the result.
23
+ 5. Report findings first, ordered by severity, with file and line references. If there are no issues, say so clearly and record remaining test gaps or residual risk.
24
+ 6. Write user-visible output in the OS locale unless the user asks for another language.
25
+
26
+ ## Reviewer Prompt Format
27
+
28
+ ```text
29
+ TASK: Review correctness, scope, and evidence for slice <slice-id>.
30
+ EXPECTED OUTCOME: Findings ordered by severity with file and line references, or an explicit no-issue result with residual risk.
31
+ REQUIRED TOOLS: Read-only diff inspection, tool readiness checks, verification command execution, plan/memory reading.
32
+ MUST DO: Check tool readiness and install-attempt evidence. Check dry-run or check evidence when external state could change. Check both module evidence and surface evidence. Preserve proper nouns exactly. Use the OS locale for user-visible text.
33
+ MUST NOT DO: Edit files. Ask the user. Approve skipped LSP/typecheck/lint without install evidence. Approve missing evidence or open-ended verification loops.
34
+ CONTEXT: docs/plan/<topic>.md, MEMORY.md, relevant docs/memory notes, changed files.
35
+ ```
36
+
37
+ ## Completion Criteria
38
+
39
+ - Findings are resolved or recorded as residual risk.
40
+ - Tool readiness evidence is present for required LSP/check/verification tools.
41
+ - Dry-run or check evidence is present when required, or the plan records why no dry-run exists.
42
+ - Failed gates followed the bounded loop policy and did not continue past two verification passes without a recorded blocker.
43
+ - Review evidence exists in `docs/plan/<topic>.md`.
44
+ - The next agent can understand verification without rereading the full conversation.
@@ -0,0 +1,81 @@
1
+ ---
2
+ name: cairn-work
3
+ description: Execute docs/plan module slices through bounded worker delegation and two verification gates.
4
+ ---
5
+
6
+ # Cairn Work
7
+
8
+ Use this to implement a plan created by `cairn-plan`.
9
+
10
+ ## Purpose
11
+
12
+ Execute only one module slice at a time. Instead of a repeated red-green loop, prove a small slice with two strong verification gates.
13
+
14
+ ## Procedure
15
+
16
+ 1. Read `PLAN.md`, the selected `docs/plan/<topic>.md`, `MEMORY.md`, and relevant memory notes.
17
+ 2. Read the `docs/model-guidance/*.md` inputs recorded in the plan.
18
+ 3. Select the first incomplete module slice.
19
+ 4. Confirm that required LSP, typecheck, lint, dry-run, and verification tools are available from the plan's tool readiness section.
20
+ 5. If a required tool is missing, run `scripts/cairn toolcheck --install` or the closest repository-native install command, then rerun the tool before continuing.
21
+ 6. Confirm the selected Light Path or Heavy Path in the plan.
22
+ 7. For Light Path, implement directly or delegate to one bounded `worker`; keep the verification gate.
23
+ 8. For Heavy Path, follow the full planning and review pipeline recorded in the plan. Run pre-implementation review before mutation and read-only review after evidence exists.
24
+ 9. Delegate implementation to `worker` with exact files, ownership, constraints, and model-specific adjustment rules. Use `explorer` for parallel read-only discovery or verification when available and useful.
25
+ 10. Before mutating external state, run the slice dry-run or check command when one is recorded. If none exists, record the absence and continue with the smallest reversible command available.
26
+ 11. `worker` must return changed files, tool readiness result, dry-run or check result when applicable, module acceptance command and result, surface integration command or QA artifact, and cleanup notes.
27
+ 12. Re-run both verification gates directly.
28
+ 13. Apply the bounded loop policy when a gate fails.
29
+ 14. Record evidence in the plan file before marking the slice complete.
30
+ 15. Write user-visible output in the OS locale unless the user asks for another language.
31
+
32
+ ## Builder Prompt Format
33
+
34
+ ```text
35
+ TASK: Implement slice <slice-id> for <topic>.
36
+ EXPECTED OUTCOME: Minimal code or documentation change satisfying the slice contract.
37
+ REQUIRED TOOLS: Scoped file editing, tool readiness checks, existing test/build commands, surface QA commands.
38
+ MUST DO: Follow MEMORY.md policy. Stay within the listed file scope and ownership. Assume you are not alone in the codebase; do not revert others' edits. Install or bootstrap missing required tools before declaring them unavailable. Run dry-run or check mode before external-state mutation when available. Provide module evidence and surface evidence. Use the OS locale for user-visible text.
39
+ MUST NOT DO: Ask the user. Skip LSP/typecheck/lint because a tool is missing without attempting installation. Refactor unrelated code. Continue an open-ended verification loop. Claim completion without evidence. Modify files outside the assigned ownership.
40
+ CONTEXT: docs/plan/<topic>.md slice, relevant docs/memory notes, applied model guidance, exact files, verification commands.
41
+ ```
42
+
43
+ ## Tool Readiness Policy
44
+
45
+ - Run the repository tool readiness command recorded in the plan before implementation.
46
+ - If no command is recorded, run `scripts/cairn toolcheck` when available.
47
+ - Missing LSP, typecheck, lint, dry-run, or verification tools must trigger a project-local or repository-native install attempt.
48
+ - After installation, rerun the exact tool command and record evidence.
49
+ - If installation fails, stop the slice and record the blocker rather than silently falling back to less precise exploration.
50
+
51
+ ## Two Verification Gates
52
+
53
+ - Module acceptance: targeted unit, typecheck, lint, parser, schema, or command that proves the module contract.
54
+ - Surface integration: HTTP, browser, CLI, tmux, desktop, or parsed artifact evidence proving behavior through the real surface.
55
+
56
+ ## Dry-Run Policy
57
+
58
+ Run the closest available dry-run or check mode before commands that mutate external state.
59
+
60
+ - Migrations and database changes: `--pretend`, dry-run, schema diff, rollback feasibility check, or equivalent.
61
+ - Package and release work: `npm pack --dry-run`, publish dry-run, build check, or equivalent.
62
+ - Infrastructure and deployment: plan, diff, validate, check, or equivalent.
63
+ - Code generation and formatting: check mode before write mode when available.
64
+ - If no dry-run mode exists, record that fact in `docs/plan/<topic>.md` before continuing.
65
+
66
+ ## Bounded Loop Policy
67
+
68
+ - Run at most two verification passes per slice by default.
69
+ - If a gate fails, diagnose the cause once, shrink or split the slice, then rerun both gates.
70
+ - After two failed passes, stop implementation for the slice and record the blocker in `docs/plan/<topic>.md`.
71
+ - Do not imitate repeated red-green loops unless the plan explicitly records a risk-based reason.
72
+
73
+ ## Completion Criteria
74
+
75
+ - Both verification gates passed in the current turn.
76
+ - Required LSP/check/verification tools were available, installed, or recorded as blockers with attempted commands.
77
+ - Dry-run or check evidence exists when the slice could mutate external state, or the plan records why no dry-run exists.
78
+ - The required Light Path or Heavy Path flow was followed.
79
+ - The model guidance recorded in the plan was applied.
80
+ - Evidence was recorded in `docs/plan/<topic>.md`.
81
+ - `PLAN.md` status was updated only after evidence existed.
@@ -0,0 +1,14 @@
1
+ # MEMORY
2
+
3
+ Short index of persistent repository knowledge. Link detailed notes under `docs/memory/`.
4
+
5
+ ## Domain Knowledge
6
+
7
+ - `docs/memory/<domain>.md`: short description.
8
+
9
+ ## Policy
10
+
11
+ - Preserve proper nouns exactly as written.
12
+ - Prefer repository evidence over assumptions.
13
+ - Read only the detailed memory needed for the current task.
14
+ - Write user-visible output in the OS locale unless the user asks for another language.
@@ -0,0 +1,17 @@
1
+ # PLAN
2
+
3
+ Short index of work plans. Link detailed plans under `docs/plan/`.
4
+
5
+ ## Planning Rules
6
+
7
+ - Detect repository stack and required LSP/check tools before implementation.
8
+ - Install or bootstrap missing required tools before declaring them unavailable.
9
+ - Record tool readiness, dry-run/check evidence, module acceptance evidence, and surface integration evidence in detailed plans.
10
+
11
+ ## Active Plans
12
+
13
+ - `docs/plan/<topic>.md`: short status.
14
+
15
+ ## Completed Plans
16
+
17
+ - `docs/plan/<topic>.md`: evidence summary.