@cairnkeep/cli 1.0.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.
- package/AGENTS.md +45 -0
- package/CONTRIBUTING.md +49 -0
- package/LICENSE +201 -0
- package/README.md +149 -0
- package/SECURITY.md +37 -0
- package/bin/cairn +73 -0
- package/claude/agents/code-reviewer.md +174 -0
- package/claude/agents/security-investigator.md +112 -0
- package/claude/agents/security-target-selector.md +90 -0
- package/claude/agents/security-validator.md +97 -0
- package/claude/agents/wiki-ingester.md +108 -0
- package/claude/agents/wiki-lint-auditor.md +94 -0
- package/claude/agents/wiki-query-analyst.md +84 -0
- package/claude/commands/context-explore.md +40 -0
- package/claude/commands/graphify.md +150 -0
- package/claude/commands/memory-review.md +85 -0
- package/claude/commands/memory-sync.md +71 -0
- package/claude/commands/recall.md +32 -0
- package/claude/commands/remember.md +43 -0
- package/claude/commands/repo-review.md +191 -0
- package/claude/commands/security-audit.md +174 -0
- package/claude/commands/wiki-ingest.md +112 -0
- package/claude/commands/wiki-lint.md +86 -0
- package/claude/commands/wiki-query.md +92 -0
- package/claude/hooks/context-explore-pretask.sh +93 -0
- package/claude/hooks/memory-capture.sh +59 -0
- package/claude/hooks/memory-recall.sh +84 -0
- package/claude/hooks/memory-wakeup.sh +45 -0
- package/docs/building-an-overlay.md +117 -0
- package/docs/domain-knowledge.md +86 -0
- package/docs/git-providers.md +36 -0
- package/docs/operating.md +366 -0
- package/mcp-memory-server/dist/embeddings.js +122 -0
- package/mcp-memory-server/dist/explore-cache.js +97 -0
- package/mcp-memory-server/dist/index.js +1256 -0
- package/mcp-memory-server/package.json +36 -0
- package/opencode/agents/code-reviewer.md +173 -0
- package/opencode/agents/security-investigator.md +111 -0
- package/opencode/agents/security-target-selector.md +89 -0
- package/opencode/agents/security-validator.md +96 -0
- package/opencode/agents/wiki-ingester.md +107 -0
- package/opencode/agents/wiki-lint-auditor.md +93 -0
- package/opencode/agents/wiki-query-analyst.md +83 -0
- package/opencode/command/code-review.md +199 -0
- package/opencode/command/context-explore.md +42 -0
- package/opencode/command/graphify.md +153 -0
- package/opencode/command/memory-review.md +44 -0
- package/opencode/command/memory-sync.md +94 -0
- package/opencode/command/recall.md +38 -0
- package/opencode/command/remember.md +46 -0
- package/opencode/command/security-audit.md +80 -0
- package/opencode/command/wiki-ingest.md +55 -0
- package/opencode/command/wiki-lint.md +51 -0
- package/opencode/command/wiki-query.md +50 -0
- package/opencode/plugins/memory-capture.ts +188 -0
- package/opencode/plugins/memory-recall.ts +132 -0
- package/opencode/plugins/memory-wakeup.ts +102 -0
- package/opencode/templates/security-finding-register.yaml.template +51 -0
- package/opencode/templates/security-issue.md.template +43 -0
- package/opencode/templates/security-policy.md.template +29 -0
- package/opencode/templates/security-report.md.template +43 -0
- package/opencode/templates/wiki-contradictions.md.template +31 -0
- package/opencode/templates/wiki-index.md.template +40 -0
- package/opencode/templates/wiki-lint-report.md.template +38 -0
- package/opencode/templates/wiki-log.md.template +11 -0
- package/opencode/templates/wiki-policy.md.template +47 -0
- package/opencode/templates/wiki-query-answer.md.template +26 -0
- package/opencode/templates/wiki-source-summary.md.template +33 -0
- package/opencode/workflows/memory-review-workflow.md +66 -0
- package/opencode/workflows/security-audit-workflow.md +197 -0
- package/opencode/workflows/wiki-ingest-workflow.md +149 -0
- package/opencode/workflows/wiki-lint-workflow.md +128 -0
- package/opencode/workflows/wiki-query-workflow.md +122 -0
- package/package.json +56 -0
- package/scripts/bootstrap.sh +99 -0
- package/scripts/doctor.sh +91 -0
- package/scripts/install-audit-timer.sh +68 -0
- package/scripts/lib/assert-tool-event.mjs +50 -0
- package/scripts/memory-store.sh +71 -0
- package/scripts/memory-wiki-audit.sh +156 -0
- package/scripts/sync-claude-assets.sh +182 -0
- package/scripts/sync-opencode-explore-assets.sh +187 -0
- package/scripts/sync-opencode-graphify-assets.sh +152 -0
- package/scripts/sync-opencode-memory-assets.sh +160 -0
- package/scripts/sync-opencode-plugin-assets.sh +163 -0
- package/scripts/sync-opencode-security-assets.sh +195 -0
- package/scripts/sync-opencode-wiki-assets.sh +250 -0
- package/scripts/test-audit-timer.sh +29 -0
- package/scripts/test-bootstrap-untracked.sh +41 -0
- package/scripts/test-cli-dispatch.sh +21 -0
- package/scripts/test-doctor.sh +32 -0
- package/scripts/test-launcher-hooks.sh +66 -0
- package/scripts/test-memory-store.sh +44 -0
- package/scripts/test-remember-recall-assertions.sh +70 -0
- package/scripts/transcript-to-text.mjs +53 -0
- package/scripts/verify-docs-parity.sh +112 -0
- package/scripts/verify-explore-maturation.sh +288 -0
- package/scripts/verify-fastcontext-reliability.sh +624 -0
- package/scripts/verify-no-private-references.sh +145 -0
- package/scripts/verify-opencode-live-parity.sh +864 -0
- package/scripts/verify-routing-seam.sh +169 -0
- package/scripts/verify-token-savings-ab.sh +557 -0
- package/templates/PROJECT-INSTRUCTIONS.md.template +42 -0
- package/templates/alignment-gap-register.yaml.template +56 -0
- package/templates/alignment-policy.md.template +28 -0
- package/templates/alignment-pr-template.md.template +18 -0
- package/templates/alignment-report.md.template +56 -0
- package/templates/env.example.template +25 -0
- package/templates/graph-policy.md.template +37 -0
- package/templates/graphs-gitignore.template +3 -0
- package/templates/memory-wiki-audit.service.template +6 -0
- package/templates/memory-wiki-audit.timer.template +9 -0
- package/templates/memory.json.template +4 -0
- package/templates/planning-config.json.template +6 -0
- package/templates/project-brief.md.template +40 -0
- package/templates/security-finding-register.yaml.template +51 -0
- package/templates/security-issue.md.template +43 -0
- package/templates/security-policy.md.template +29 -0
- package/templates/security-report.md.template +43 -0
- package/templates/start-claude.sh.template +46 -0
- package/templates/start-opencode.sh.template +41 -0
- package/templates/structured-change-canvas.md.template +63 -0
- package/templates/wiki-contradictions.md.template +31 -0
- package/templates/wiki-index.md.template +40 -0
- package/templates/wiki-lint-report.md.template +38 -0
- package/templates/wiki-log.md.template +11 -0
- package/templates/wiki-policy.md.template +47 -0
- package/templates/wiki-query-answer.md.template +26 -0
- package/templates/wiki-source-summary.md.template +33 -0
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: wiki-lint-auditor
|
|
3
|
+
description: Runs an advisory lint pass over the derived project wiki and writes a durable report without treating the wiki as canonical.
|
|
4
|
+
mode: subagent
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
<role>
|
|
8
|
+
You are the lint auditor for the governed project wiki.
|
|
9
|
+
|
|
10
|
+
Your job is to inspect the derived wiki for citation gaps, orphan pages, stale or contradicted claims, missing obvious pages, and broken cross-references, then write an advisory report.
|
|
11
|
+
|
|
12
|
+
If the prompt contains a `<required_reading>` block, read every listed file before doing anything else.
|
|
13
|
+
</role>
|
|
14
|
+
|
|
15
|
+
<project_context>
|
|
16
|
+
Before linting:
|
|
17
|
+
|
|
18
|
+
1. Read `./AGENTS.md` if it exists.
|
|
19
|
+
2. Read the supplied policy, index, and log.
|
|
20
|
+
3. Read the relevant wiki pages in scope.
|
|
21
|
+
4. Read canonical raw sources when needed to confirm a suspected stale or contradicted claim.
|
|
22
|
+
</project_context>
|
|
23
|
+
|
|
24
|
+
<input_contract>
|
|
25
|
+
You will receive a `<wiki_assignment>` block containing:
|
|
26
|
+
- `project_root`
|
|
27
|
+
- `focus_path`
|
|
28
|
+
- `index_path`
|
|
29
|
+
- `log_path`
|
|
30
|
+
- `policy_path`
|
|
31
|
+
- `report_path`
|
|
32
|
+
- `register_path`
|
|
33
|
+
- `timestamp`
|
|
34
|
+
- `branch`
|
|
35
|
+
- `project_name`
|
|
36
|
+
|
|
37
|
+
Treat `project_root` as the working directory. If the runtime spawned you elsewhere, change into `project_root` before reading or writing any relative paths.
|
|
38
|
+
</input_contract>
|
|
39
|
+
|
|
40
|
+
<lint_rules>
|
|
41
|
+
Check conservatively for:
|
|
42
|
+
- missing citations on non-trivial claims
|
|
43
|
+
- orphan pages that are not discoverable from the index or another wiki page
|
|
44
|
+
- stale claims whose cited raw sources clearly moved on since the page was last reviewed
|
|
45
|
+
- contradicted claims where the wiki conflicts with the cited canonical sources
|
|
46
|
+
- missing obvious pages only when the absence is repeated and concrete, not speculative
|
|
47
|
+
- broken cross-references to missing wiki files or repo files
|
|
48
|
+
|
|
49
|
+
Finding-signal severity (for the per-run report):
|
|
50
|
+
- `high` for contradicted claims or broken links on heavily used pages that could mislead future work
|
|
51
|
+
- `medium` for missing citations, stale pages, or orphan pages that reduce trust or discoverability
|
|
52
|
+
- `low` for optional missing pages or minor hygiene gaps
|
|
53
|
+
|
|
54
|
+
Contradiction severity (separate axis — classify every contradiction and mirror it into the register):
|
|
55
|
+
- `hard` — genuinely conflicting claims that cannot both be correct; must be resolved before downstream work relies on either page
|
|
56
|
+
- `scope-mismatch` — the claims apply to different scopes/contexts and do not truly conflict
|
|
57
|
+
- `soft` — non-blocking, contextual difference; coexists
|
|
58
|
+
</lint_rules>
|
|
59
|
+
|
|
60
|
+
<register_rules>
|
|
61
|
+
Mirror every contradiction into the persistent register at `.planning/wiki/CONTRADICTIONS.md`. This is what stops contradictions from leaking:
|
|
62
|
+
- if an open entry for the same page-pair/claim already exists, update it (severity, evidence, last-seen date); otherwise open a new entry under the `<!-- wiki:contradictions:open:start -->` block with severity, `Status: open`, affected pages, the conflicting claims, and the detection date
|
|
63
|
+
- for contradictions whose underlying page(s) now agree with the canonical source, flip `Status: open` → `resolved`, move the entry to the `<!-- wiki:contradictions:resolved:start -->` block, and record the resolution date
|
|
64
|
+
- do not delete entries — resolved ones move to the Resolved section
|
|
65
|
+
- a contradiction is `resolved` only after the page was actually reconciled, not merely acknowledged
|
|
66
|
+
</register_rules>
|
|
67
|
+
|
|
68
|
+
<report_rules>
|
|
69
|
+
Write markdown to `report_path` with this structure:
|
|
70
|
+
- `# Wiki Lint Report`
|
|
71
|
+
- bullets for `Project`, `Generated at`, `Scope`, and `Advisory status`
|
|
72
|
+
- `## Summary` with counts for each finding class
|
|
73
|
+
- `## High Signal Findings`
|
|
74
|
+
- `## Medium Signal Findings`
|
|
75
|
+
- `## Low Signal Findings`
|
|
76
|
+
- `## Suggested Next Steps`
|
|
77
|
+
|
|
78
|
+
The report must state clearly that raw docs and code remain the source of truth.
|
|
79
|
+
|
|
80
|
+
Then update the persistent contradiction register at `register_path` following `<register_rules>`: open/refresh/resolve entries in place so contradictions do not leak.
|
|
81
|
+
|
|
82
|
+
After writing the report and updating the register, append one `wiki-lint` entry to `.planning/wiki/log.md` with the timestamp, focus scope, report path, number of register changes, and a short summary.
|
|
83
|
+
Append inside the `<!-- wiki:entries:start -->` and `<!-- wiki:entries:end -->` block when those markers exist.
|
|
84
|
+
</report_rules>
|
|
85
|
+
|
|
86
|
+
<critical_rules>
|
|
87
|
+
1. Linting is advisory; raw sources remain canonical.
|
|
88
|
+
2. Prefer a small number of grounded findings over speculative cleanup noise.
|
|
89
|
+
3. Preserve contradictions instead of resolving them implicitly.
|
|
90
|
+
4. Do not rewrite wiki pages as part of linting.
|
|
91
|
+
5. Resolve all relative paths from `project_root`, not from the process cwd.
|
|
92
|
+
6. Write the report and append the log before returning a brief summary.
|
|
93
|
+
</critical_rules>
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: wiki-query-analyst
|
|
3
|
+
description: Answers repository questions from the compiled wiki first, then canonical raw sources, and optionally writes back a reusable derived answer.
|
|
4
|
+
mode: subagent
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
<role>
|
|
8
|
+
You are the query analyst for the governed project wiki.
|
|
9
|
+
|
|
10
|
+
Your job is to answer one repository question by using the wiki as a navigation aid first and canonical raw sources second. If writeback is requested, store a reusable derived answer without presenting it as canonical truth.
|
|
11
|
+
|
|
12
|
+
If the prompt contains a `<required_reading>` block, read every listed file before doing anything else.
|
|
13
|
+
</role>
|
|
14
|
+
|
|
15
|
+
<project_context>
|
|
16
|
+
Before answering:
|
|
17
|
+
|
|
18
|
+
1. Read `./AGENTS.md` if it exists.
|
|
19
|
+
2. Read the supplied policy and index.
|
|
20
|
+
3. Use the index to shortlist relevant wiki pages before reading them.
|
|
21
|
+
4. Read canonical raw docs, tests, interfaces, config, or code whenever the wiki is missing, stale, contradictory, or insufficient.
|
|
22
|
+
</project_context>
|
|
23
|
+
|
|
24
|
+
<input_contract>
|
|
25
|
+
You will receive a `<wiki_assignment>` block containing:
|
|
26
|
+
- `project_root`
|
|
27
|
+
- `question`
|
|
28
|
+
- `writeback`
|
|
29
|
+
- `index_path`
|
|
30
|
+
- `log_path`
|
|
31
|
+
- `policy_path`
|
|
32
|
+
- `output_path`
|
|
33
|
+
- `timestamp`
|
|
34
|
+
- `branch`
|
|
35
|
+
- `project_name`
|
|
36
|
+
|
|
37
|
+
Treat `project_root` as the working directory. If the runtime spawned you elsewhere, change into `project_root` before reading or writing any relative paths.
|
|
38
|
+
</input_contract>
|
|
39
|
+
|
|
40
|
+
<retrieval_order>
|
|
41
|
+
Use this order:
|
|
42
|
+
|
|
43
|
+
1. `.planning/wiki/index.md`
|
|
44
|
+
2. relevant wiki pages under `sources/`, `topics/`, `entities/`, `queries/`, and recent lint reports when they clarify trust issues
|
|
45
|
+
3. cited canonical raw sources and any directly relevant repo files
|
|
46
|
+
|
|
47
|
+
Truth rules:
|
|
48
|
+
- raw repository docs, tests, interfaces, config, and code outrank derived wiki pages
|
|
49
|
+
- prior query writebacks are reusable hints, not proof by themselves
|
|
50
|
+
- when the wiki and raw sources disagree, preserve the contradiction and trust the raw sources
|
|
51
|
+
</retrieval_order>
|
|
52
|
+
|
|
53
|
+
<answer_rules>
|
|
54
|
+
In the final answer:
|
|
55
|
+
- lead with the best grounded conclusion
|
|
56
|
+
- preserve source references for the claims you rely on
|
|
57
|
+
- call out contradiction, ambiguity, or freshness risk explicitly
|
|
58
|
+
- avoid pretending the wiki settled something the raw sources do not support
|
|
59
|
+
</answer_rules>
|
|
60
|
+
|
|
61
|
+
<writeback_rules>
|
|
62
|
+
If `writeback` is true:
|
|
63
|
+
- write markdown to `output_path`
|
|
64
|
+
- start with `# Query: {short title}`
|
|
65
|
+
- include bullets for `Asked at`, `Question`, `Answer status`, and `Last reviewed`
|
|
66
|
+
- include sections named `Answer`, `Wiki Pages Consulted`, `Canonical Sources`, `Contradictions And Freshness Notes`, and `Suggested Follow-up`
|
|
67
|
+
- keep the artifact concise and citation-heavy
|
|
68
|
+
- update `.planning/wiki/index.md` once inside the `<!-- wiki:queries:start -->` and `<!-- wiki:queries:end -->` block when those markers exist
|
|
69
|
+
- if `- None yet.` is present inside the queries block and you are adding a real entry, replace it
|
|
70
|
+
- append one `wiki-query --writeback` entry to `.planning/wiki/log.md`, inside the `<!-- wiki:entries:start -->` and `<!-- wiki:entries:end -->` block when those markers exist
|
|
71
|
+
|
|
72
|
+
If `writeback` is false:
|
|
73
|
+
- do not modify files
|
|
74
|
+
</writeback_rules>
|
|
75
|
+
|
|
76
|
+
<critical_rules>
|
|
77
|
+
1. The wiki is derived, not canonical.
|
|
78
|
+
2. Index first, wiki pages second, raw sources third.
|
|
79
|
+
3. Preserve provenance in both the chat answer and any written artifact.
|
|
80
|
+
4. Do not smooth over contradictions.
|
|
81
|
+
5. Resolve all relative paths from `project_root`, not from the process cwd.
|
|
82
|
+
6. Return a concise grounded answer after finishing any requested writeback.
|
|
83
|
+
</critical_rules>
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Review code for bugs, security issues, and maintainability concerns
|
|
3
|
+
argument-hint: "[--full | --staged | --branch <name> | --mr <project>!iid | --since <ref> | --focus <pattern> | --post-to-mr | --block-on <severity>]"
|
|
4
|
+
tools:
|
|
5
|
+
read: true
|
|
6
|
+
write: true
|
|
7
|
+
edit: true
|
|
8
|
+
bash: true
|
|
9
|
+
grep: true
|
|
10
|
+
glob: true
|
|
11
|
+
agent: true
|
|
12
|
+
question: true
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
Git provider: these steps use the git host set by `CAIRN_GIT_PROVIDER` (`github`/`gitlab`/`codeberg`/`forgejo`/`none`); resolve the operation-to-tool mapping from `docs/git-providers.md`. If it is `none` or no provider MCP is registered, skip the provider steps and continue locally.
|
|
16
|
+
|
|
17
|
+
<objective>
|
|
18
|
+
Review code for bugs, security issues, maintainability problems, and style violations.
|
|
19
|
+
|
|
20
|
+
Output: `REVIEW.md` in the repo root (or `.planning/reviews/` if it exists).
|
|
21
|
+
|
|
22
|
+
Flag handling:
|
|
23
|
+
- `--full` — review all tracked files in the repository (entire codebase)
|
|
24
|
+
- `--staged` — review only git-staged changes
|
|
25
|
+
- `--branch <name>` — review `<name>` vs default branch
|
|
26
|
+
- `--mr <project>!iid` — review MR diff via the git-provider MCP
|
|
27
|
+
- `--since <ref>` — review changes since `<ref>` (e.g. `HEAD~1`)
|
|
28
|
+
- `--focus <pattern>` — restrict to files matching glob pattern
|
|
29
|
+
- `--post-to-mr` — post findings as MR/PR diff comments (requires `--mr`)
|
|
30
|
+
- `--block-on <severity>` — fail if findings at or above severity exist (critical/high/medium)
|
|
31
|
+
- Default (no flags) — review working tree + staged changes
|
|
32
|
+
|
|
33
|
+
This is an advisory command. Findings are structured by severity and dimension.
|
|
34
|
+
</objective>
|
|
35
|
+
|
|
36
|
+
<context>
|
|
37
|
+
Arguments: $ARGUMENTS
|
|
38
|
+
|
|
39
|
+
Default behavior:
|
|
40
|
+
1. Detect review scope from flags (or default to working tree + staged)
|
|
41
|
+
2. Collect diff and relevant context files
|
|
42
|
+
3. Spawn code-reviewer subagent with diff + project context
|
|
43
|
+
4. Write structured REVIEW.md with findings
|
|
44
|
+
5. Optionally post findings to the MR/PR
|
|
45
|
+
6. Enforce block gate if `--block-on` is set
|
|
46
|
+
|
|
47
|
+
Important rules:
|
|
48
|
+
- The reviewer is READ-ONLY on source code — only creates REVIEW.md
|
|
49
|
+
- Findings must cite exact file paths and line numbers
|
|
50
|
+
- Each finding includes: severity, dimension, description, and suggested fix
|
|
51
|
+
- Don't flag style issues that match existing project conventions
|
|
52
|
+
- Review dimensions include `simplicity` — flag over-engineering (unnecessary abstractions, speculative scaffolding/YAGNI, avoidable dependencies or boilerplate); a shortcut tagged with a `ponytail:` comment is acceptable, not a finding
|
|
53
|
+
</context>
|
|
54
|
+
|
|
55
|
+
<process>
|
|
56
|
+
|
|
57
|
+
## 1. Detect Review Scope
|
|
58
|
+
|
|
59
|
+
Parse arguments to determine review mode:
|
|
60
|
+
|
|
61
|
+
### Full codebase mode (`--full`)
|
|
62
|
+
```bash
|
|
63
|
+
REVIEW_MODE=full
|
|
64
|
+
FILE_LIST=$(git ls-files | grep -vE '\.(md|txt|yml|yaml|json|toml|lock|cfg|ini|env|gitignore)$' | grep -E "$FOCUS_PATTERN" 2>/dev/null || git ls-files)
|
|
65
|
+
```
|
|
66
|
+
The reviewer receives the full file list and reads each file directly (no diff).
|
|
67
|
+
|
|
68
|
+
### Diff-based modes
|
|
69
|
+
|
|
70
|
+
| Flag | Diff Command |
|
|
71
|
+
|---|---|
|
|
72
|
+
| `--staged` | `git diff --cached` |
|
|
73
|
+
| `--branch <name>` | `git diff "${DEFAULT_BRANCH}...<name>"` |
|
|
74
|
+
| `--mr <project>!iid` | git-provider MCP: `get_merge_request_diffs` |
|
|
75
|
+
| `--since <ref>` | `git diff <ref>..HEAD` |
|
|
76
|
+
| (none) | `git diff` + `git diff --cached` |
|
|
77
|
+
|
|
78
|
+
If `--focus <pattern>` is set, filter files to matching paths.
|
|
79
|
+
|
|
80
|
+
## 2. Collect Context
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
REPO_ROOT=$(git rev-parse --show-toplevel)
|
|
84
|
+
DEFAULT_BRANCH=$(git symbolic-ref --quiet --short refs/remotes/origin/HEAD 2>/dev/null | sed 's#^origin/##' || true)
|
|
85
|
+
if [ -z "$DEFAULT_BRANCH" ]; then
|
|
86
|
+
if git rev-parse --verify origin/main >/dev/null 2>&1 || git rev-parse --verify main >/dev/null 2>&1; then
|
|
87
|
+
DEFAULT_BRANCH=main
|
|
88
|
+
elif git rev-parse --verify origin/master >/dev/null 2>&1 || git rev-parse --verify master >/dev/null 2>&1; then
|
|
89
|
+
DEFAULT_BRANCH=master
|
|
90
|
+
else
|
|
91
|
+
DEFAULT_BRANCH=HEAD
|
|
92
|
+
fi
|
|
93
|
+
fi
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Collect project context for the reviewer:
|
|
97
|
+
- Language detection (from file extensions in diff)
|
|
98
|
+
- Existing conventions (read 1-2 analogous files not in diff)
|
|
99
|
+
- Project skills (`.claude/skills/` or `.agents/skills/` if present)
|
|
100
|
+
- Lint/test config (`.eslintrc`, `pyproject.toml`, `Cargo.toml`, etc.)
|
|
101
|
+
|
|
102
|
+
## 3. Build Review Input
|
|
103
|
+
|
|
104
|
+
### Full mode (`--full`)
|
|
105
|
+
Build a file list from tracked source files (excluding docs, config, lock files). The reviewer reads each file directly. For large repos, prioritize:
|
|
106
|
+
- Entry points and public APIs
|
|
107
|
+
- Auth, security, and data-access layers
|
|
108
|
+
- Recently changed files (last 30 days by `git log --since=30-days-ago`)
|
|
109
|
+
|
|
110
|
+
### Diff-based modes
|
|
111
|
+
Combine:
|
|
112
|
+
- Full unified diff (from step 1)
|
|
113
|
+
- Project context (from step 2)
|
|
114
|
+
- File list with paths and languages
|
|
115
|
+
|
|
116
|
+
For MR mode, also capture:
|
|
117
|
+
- MR title, description, assignees, reviewers
|
|
118
|
+
- Existing discussion notes (to avoid duplicating findings)
|
|
119
|
+
|
|
120
|
+
## 4. Spawn code-reviewer
|
|
121
|
+
|
|
122
|
+
**Full mode:** Pass `<mode>full</mode>` and `<files>{tracked file list}</files>`. The reviewer reads files directly.
|
|
123
|
+
|
|
124
|
+
**Diff mode:** Pass `<mode>diff</mode>` and `<diff>{full diff}</diff>`.
|
|
125
|
+
|
|
126
|
+
```
|
|
127
|
+
Agent(
|
|
128
|
+
prompt="Read agent instructions for code review.\n\n" +
|
|
129
|
+
"<mode>{full|diff}</mode>" +
|
|
130
|
+
"<diff>{full diff — only for diff mode}</diff>" +
|
|
131
|
+
"<files>{file list with paths}</files>" +
|
|
132
|
+
"<project_context>{language, conventions, skills, lint config}</project_context>" +
|
|
133
|
+
"<config>block_on: {BLOCK_ON_SEVERITY}, focus: {FOCUS_PATTERN}</config>" +
|
|
134
|
+
"<constraints>Read-only on source. Cite file:line for every finding. Skip style issues matching project conventions.</constraints>",
|
|
135
|
+
subagent_type="code-reviewer",
|
|
136
|
+
description="Code review: {scope description}"
|
|
137
|
+
)
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Handle return:
|
|
141
|
+
- `## CLEAN` — no findings, write brief REVIEW.md
|
|
142
|
+
- `## FINDINGS` — structured findings, write REVIEW.md with table
|
|
143
|
+
- `## ESCALATE` — critical issues, write REVIEW.md and block
|
|
144
|
+
|
|
145
|
+
## 5. Write REVIEW.md
|
|
146
|
+
|
|
147
|
+
Create/update `REVIEW.md` (or `.planning/reviews/REVIEW.md` if directory exists):
|
|
148
|
+
|
|
149
|
+
```markdown
|
|
150
|
+
# Code Review — {date}
|
|
151
|
+
|
|
152
|
+
**Scope:** {full | staged | branch | MR | since}
|
|
153
|
+
**Files:** {count}
|
|
154
|
+
**Findings:** {total} ({critical} critical, {high} high, {medium} medium, {low} low)
|
|
155
|
+
|
|
156
|
+
## Findings by Severity
|
|
157
|
+
|
|
158
|
+
### Critical
|
|
159
|
+
| # | File:Line | Dimension | Description | Suggested Fix |
|
|
160
|
+
|---|---|---|---|---|
|
|
161
|
+
|
|
162
|
+
### High
|
|
163
|
+
...
|
|
164
|
+
|
|
165
|
+
### Medium
|
|
166
|
+
...
|
|
167
|
+
|
|
168
|
+
### Low
|
|
169
|
+
...
|
|
170
|
+
|
|
171
|
+
## Summary
|
|
172
|
+
{brief assessment}
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
## 6. Optional: Post to MR
|
|
176
|
+
|
|
177
|
+
If `--post-to-mr` and `--mr` are set:
|
|
178
|
+
- For each finding with file:line, create a diff discussion note
|
|
179
|
+
- Group findings by file
|
|
180
|
+
- Reference REVIEW.md in a top-level MR note
|
|
181
|
+
|
|
182
|
+
## 7. Block Gate
|
|
183
|
+
|
|
184
|
+
If `--block-on <severity>` is set and findings at or above that severity exist:
|
|
185
|
+
|
|
186
|
+
```
|
|
187
|
+
REVIEW BLOCKED: {N} findings at or above {severity}
|
|
188
|
+
▶ Fix findings or remove --block-on to continue
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
Stop here. Otherwise:
|
|
192
|
+
|
|
193
|
+
```
|
|
194
|
+
REVIEW COMPLETE: {total} findings ({critical} critical, {high} high)
|
|
195
|
+
▶ Review REVIEW.md for details
|
|
196
|
+
▶ /code-review --post-to-mr to comment on MR
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
</process>
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: On-demand token-efficient repo exploration via context_explore, returning compact citations
|
|
3
|
+
argument-hint: "<query> [repo path]"
|
|
4
|
+
tools:
|
|
5
|
+
bash: true
|
|
6
|
+
cairn-memory_context_explore: true
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
<objective>
|
|
10
|
+
Answer a repo-exploration question with compact `path:line-range` citations from `context_explore`, without reading or summarizing the cited ranges yourself — that expansion is the caller's decision, not this command's.
|
|
11
|
+
</objective>
|
|
12
|
+
|
|
13
|
+
<context>
|
|
14
|
+
Arguments: $ARGUMENTS
|
|
15
|
+
|
|
16
|
+
The first token (or the full string if no path is given) is the query. An optional trailing path argument overrides the resolved repo root.
|
|
17
|
+
</context>
|
|
18
|
+
|
|
19
|
+
<process>
|
|
20
|
+
## 0. Resolve repo root
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
ROOT=$(git rev-parse --show-toplevel 2>/dev/null || true)
|
|
24
|
+
if [ -z "$ROOT" ]; then
|
|
25
|
+
echo "Not inside a git repository. /context-explore must run from a project repo."
|
|
26
|
+
exit 1
|
|
27
|
+
fi
|
|
28
|
+
cd "$ROOT"
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
If `$ARGUMENTS` carries an optional trailing path token that is a valid path, use it to override `$ROOT`. The winning value becomes the explicit `repo_root` argument in step 1.
|
|
32
|
+
|
|
33
|
+
## 1. Call the tool
|
|
34
|
+
|
|
35
|
+
Call `context_explore` with `query` set to the question text from `$ARGUMENTS` (path override stripped) and `repo_root` set to the resolved path from step 0. `repo_root` MUST be passed explicitly — the MCP server's own working directory is not the target repo, so cwd and any environment default cannot be relied on.
|
|
36
|
+
|
|
37
|
+
## 2. Report
|
|
38
|
+
|
|
39
|
+
On success, relay the tool's `content[0].text` citation list verbatim, including its zero-citation note if that is what was returned. Do not read or summarize the cited ranges.
|
|
40
|
+
|
|
41
|
+
On failure, relay a one-line pass-through of the tool's error message (the thrown message, or `structuredContent.error`) — never a raw JSON dump, never a re-diagnosis of the cause.
|
|
42
|
+
</process>
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: "Build, rebuild, query, and inspect the project knowledge graph in .planning/graphs/"
|
|
3
|
+
argument-hint: "[build [--force]|query <term>|status|diff]"
|
|
4
|
+
tools:
|
|
5
|
+
read: true
|
|
6
|
+
bash: true
|
|
7
|
+
task: true
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
**STOP -- DO NOT READ THIS FILE. You are already reading it. This prompt was injected into your context by Claude Code's command system. Using the Read tool on this file wastes tokens. Begin executing Step 0 immediately.**
|
|
11
|
+
|
|
12
|
+
**graphify CLI:** the `graphify` subcommand is exposed by `gsd-tools` (on PATH). Invoke as `gsd-tools graphify …` as documented in this command and in `docs/CLI-TOOLS.md`. Other GSD queries use `gsd-tools <subcmd>` where a handler exists.
|
|
13
|
+
|
|
14
|
+
## Step 0 -- Banner
|
|
15
|
+
|
|
16
|
+
**Before ANY tool calls**, display this banner:
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
GRAPHIFY
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Then proceed to Step 1.
|
|
23
|
+
|
|
24
|
+
## Step 1 -- Config Gate
|
|
25
|
+
|
|
26
|
+
Check if graphify is enabled by reading `.planning/config.json` directly using the Read tool.
|
|
27
|
+
|
|
28
|
+
**DO NOT use the gsd-tools config get-value command** -- it hard-exits on missing keys.
|
|
29
|
+
|
|
30
|
+
1. Read `.planning/config.json` using the Read tool
|
|
31
|
+
2. If the file does not exist: display the disabled message below and **STOP**
|
|
32
|
+
3. Parse the JSON content. Check if `config.graphify && config.graphify.enabled === true`
|
|
33
|
+
4. If `graphify.enabled` is NOT explicitly `true`: display the disabled message below and **STOP**
|
|
34
|
+
5. If `graphify.enabled` is `true`: proceed to Step 2
|
|
35
|
+
|
|
36
|
+
**Disabled message:**
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
GRAPHIFY
|
|
40
|
+
|
|
41
|
+
Knowledge graph is disabled. To activate:
|
|
42
|
+
|
|
43
|
+
gsd-tools config-set graphify.enabled true
|
|
44
|
+
|
|
45
|
+
Then run /graphify build to create the initial graph.
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
## Step 2 -- Parse Argument
|
|
51
|
+
|
|
52
|
+
Parse `$ARGUMENTS` to determine the operation mode:
|
|
53
|
+
|
|
54
|
+
| Argument | Action |
|
|
55
|
+
|----------|--------|
|
|
56
|
+
| `build` or `build --force` | Run inline build (Step 3) |
|
|
57
|
+
| `query <term>` | Run inline query (Step 2a) |
|
|
58
|
+
| `status` | Run inline status check (Step 2b) |
|
|
59
|
+
| `diff` | Run inline diff check (Step 2c) |
|
|
60
|
+
| No argument or unknown | Show usage message |
|
|
61
|
+
|
|
62
|
+
**Usage message** (shown when no argument or unrecognized argument):
|
|
63
|
+
|
|
64
|
+
```
|
|
65
|
+
GRAPHIFY
|
|
66
|
+
|
|
67
|
+
Usage: /graphify <mode>
|
|
68
|
+
|
|
69
|
+
Modes:
|
|
70
|
+
build [--force] Build or rebuild the knowledge graph
|
|
71
|
+
query <term> Search the graph for a term
|
|
72
|
+
status Show graph freshness and statistics
|
|
73
|
+
diff Show changes since last build
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Step 2a -- Query
|
|
77
|
+
|
|
78
|
+
Run:
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
gsd-tools graphify query <term>
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Parse the JSON output and display results:
|
|
85
|
+
- If the output contains `"disabled": true`, display the disabled message from Step 1 and **STOP**
|
|
86
|
+
- If the output contains `"error"` field, display the error message and **STOP**
|
|
87
|
+
- If no nodes found, display: `No graph matches for '<term>'. Try /graphify build to create or rebuild the graph.`
|
|
88
|
+
- Otherwise, display matched nodes grouped by type, with edge relationships and confidence tiers (EXTRACTED/INFERRED/AMBIGUOUS)
|
|
89
|
+
|
|
90
|
+
**STOP** after displaying results. Do not spawn an agent.
|
|
91
|
+
|
|
92
|
+
### Step 2b -- Status
|
|
93
|
+
|
|
94
|
+
Run:
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
gsd-tools graphify status
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Parse the JSON output and display:
|
|
101
|
+
- If `exists: false`, display the message field
|
|
102
|
+
- Otherwise show last build time, node/edge/hyperedge counts, and STALE or FRESH indicator
|
|
103
|
+
|
|
104
|
+
**STOP** after displaying status. Do not spawn an agent.
|
|
105
|
+
|
|
106
|
+
### Step 2c -- Diff
|
|
107
|
+
|
|
108
|
+
Run:
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
gsd-tools graphify diff
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Parse the JSON output and display:
|
|
115
|
+
- If `no_baseline: true`, display the message field
|
|
116
|
+
- Otherwise show node and edge change counts (added/removed/changed)
|
|
117
|
+
|
|
118
|
+
If no snapshot exists, suggest running `build` twice (first to create, second to generate a diff baseline).
|
|
119
|
+
|
|
120
|
+
**STOP** after displaying diff. Do not spawn an agent.
|
|
121
|
+
|
|
122
|
+
---
|
|
123
|
+
|
|
124
|
+
## Step 3 -- Build (Inline)
|
|
125
|
+
|
|
126
|
+
Run:
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
gsd-tools graphify build [--force]
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Parse the JSON output and display:
|
|
133
|
+
- If the output contains `"disabled": true`, display the disabled message from Step 1 and **STOP**
|
|
134
|
+
- If the output contains an `"error"` field, display the error and the `stage` field when present, then **STOP**
|
|
135
|
+
- Otherwise display the build summary using `status.last_build`, `status.node_count`, `status.edge_count`, `status.hyperedge_count`, whether the snapshot was saved, and whether a forced clean rebuild was used
|
|
136
|
+
|
|
137
|
+
This command now performs the full pipeline directly:
|
|
138
|
+
- runs `graphify update .` with legacy fallback to `graphify . --update`
|
|
139
|
+
- when `--force` is present, clears `graphify-out/`, published graph artifacts, and `.planning/graphs/.last-build-snapshot.json` first
|
|
140
|
+
- validates `graphify-out/graph.json`
|
|
141
|
+
- copies `graph.json`, `graph.html`, and `GRAPH_REPORT.md` into `.planning/graphs/`
|
|
142
|
+
- writes `.planning/graphs/.last-build-snapshot.json`
|
|
143
|
+
|
|
144
|
+
**STOP** after displaying the build result. Do not spawn an agent.
|
|
145
|
+
|
|
146
|
+
---
|
|
147
|
+
|
|
148
|
+
## Anti-Patterns
|
|
149
|
+
|
|
150
|
+
1. DO NOT spawn an agent for graphify operations -- build/query/status/diff are handled directly
|
|
151
|
+
2. DO NOT modify graph files directly outside the graphify CLI path
|
|
152
|
+
3. DO NOT skip the config gate check
|
|
153
|
+
4. DO NOT use gsd-tools config get-value for the config gate -- it exits on missing keys
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Review staged memory candidates extracted from prior sessions and accept (write to AgentFS) or discard them
|
|
3
|
+
argument-hint: "[--all]"
|
|
4
|
+
tools:
|
|
5
|
+
read: true
|
|
6
|
+
write: true
|
|
7
|
+
edit: true
|
|
8
|
+
bash: true
|
|
9
|
+
grep: true
|
|
10
|
+
glob: true
|
|
11
|
+
agent: true
|
|
12
|
+
question: true
|
|
13
|
+
---
|
|
14
|
+
<objective>
|
|
15
|
+
Review memory candidates that the SessionEnd hook (memory-capture.sh) extracted
|
|
16
|
+
automatically from prior sessions and staged under `.planning/memory-staging/`.
|
|
17
|
+
This is the accept gate between autonomous extraction and durable AgentFS writes:
|
|
18
|
+
no candidate becomes a memory fact until you accept it here.
|
|
19
|
+
|
|
20
|
+
Accepted candidates are written via the cairn-memory MCP (`memory_write`).
|
|
21
|
+
Discarded ones are deleted from staging. This keeps writes agent-gated (no
|
|
22
|
+
premature or auto writes) while making extraction fully automatic.
|
|
23
|
+
|
|
24
|
+
Argument handling:
|
|
25
|
+
- no args: review candidates from the most recent staged session
|
|
26
|
+
- `--all`: review candidates across all staged sessions
|
|
27
|
+
</objective>
|
|
28
|
+
|
|
29
|
+
<execution_context>
|
|
30
|
+
@$HOME/.config/opencode/workflows/memory-review-workflow.md
|
|
31
|
+
</execution_context>
|
|
32
|
+
|
|
33
|
+
<context>
|
|
34
|
+
Arguments: $ARGUMENTS
|
|
35
|
+
</context>
|
|
36
|
+
|
|
37
|
+
<process>
|
|
38
|
+
Execute the memory-review workflow end-to-end. In summary: load staged JSON
|
|
39
|
+
candidates from `.planning/memory-staging/`, judge each against the acceptance
|
|
40
|
+
rules (durable, branch-safe, non-duplicate — check existing memory with
|
|
41
|
+
`memory_search`), write accepted ones via `memory_write`/`memory_supersede`,
|
|
42
|
+
clear reviewed staging files, and report counts. No speculative, branch-local,
|
|
43
|
+
or trivial claims should be written to AgentFS.
|
|
44
|
+
</process>
|