cleargate 0.1.0-alpha.1 → 0.2.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 (67) hide show
  1. package/README.md +41 -2
  2. package/dist/MANIFEST.json +160 -0
  3. package/dist/cli.cjs +4396 -16
  4. package/dist/cli.cjs.map +1 -1
  5. package/dist/cli.js +4380 -4
  6. package/dist/cli.js.map +1 -1
  7. package/dist/templates/cleargate-planning/.claude/agents/architect.md +57 -0
  8. package/dist/templates/cleargate-planning/.claude/agents/cleargate-wiki-ingest.md +145 -0
  9. package/dist/templates/cleargate-planning/.claude/agents/cleargate-wiki-lint.md +256 -0
  10. package/dist/templates/cleargate-planning/.claude/agents/cleargate-wiki-query.md +143 -0
  11. package/dist/templates/cleargate-planning/.claude/agents/developer.md +58 -0
  12. package/dist/templates/cleargate-planning/.claude/agents/qa.md +57 -0
  13. package/dist/templates/cleargate-planning/.claude/agents/reporter.md +114 -0
  14. package/dist/templates/cleargate-planning/.claude/hooks/session-start.sh +4 -0
  15. package/dist/templates/cleargate-planning/.claude/hooks/stamp-and-gate.sh +18 -0
  16. package/dist/templates/cleargate-planning/.claude/hooks/token-ledger.sh +174 -0
  17. package/dist/templates/cleargate-planning/.claude/settings.json +35 -0
  18. package/dist/templates/cleargate-planning/.claude/skills/flashcard/SKILL.md +73 -0
  19. package/dist/templates/cleargate-planning/.cleargate/FLASHCARD.md +6 -0
  20. package/dist/templates/cleargate-planning/.cleargate/delivery/archive/.gitkeep +0 -0
  21. package/dist/templates/cleargate-planning/.cleargate/delivery/pending-sync/.gitkeep +0 -0
  22. package/dist/templates/cleargate-planning/.cleargate/knowledge/cleargate-protocol.md +508 -0
  23. package/dist/templates/cleargate-planning/.cleargate/knowledge/readiness-gates.md +133 -0
  24. package/dist/templates/cleargate-planning/.cleargate/templates/Bug.md +82 -0
  25. package/dist/templates/cleargate-planning/.cleargate/templates/CR.md +77 -0
  26. package/dist/templates/cleargate-planning/.cleargate/templates/Sprint Plan Template.md +63 -0
  27. package/dist/templates/cleargate-planning/.cleargate/templates/epic.md +120 -0
  28. package/dist/templates/cleargate-planning/.cleargate/templates/initiative.md +53 -0
  29. package/dist/templates/cleargate-planning/.cleargate/templates/proposal.md +52 -0
  30. package/dist/templates/cleargate-planning/.cleargate/templates/story.md +125 -0
  31. package/dist/templates/cleargate-planning/CLAUDE.md +41 -0
  32. package/dist/templates/cleargate-planning/MANIFEST.json +160 -0
  33. package/dist/templates/synthesis/active-sprint.md +30 -0
  34. package/dist/templates/synthesis/open-gates.md +38 -0
  35. package/dist/templates/synthesis/product-state.md +32 -0
  36. package/dist/templates/synthesis/roadmap.md +63 -0
  37. package/package.json +9 -2
  38. package/templates/cleargate-planning/.claude/agents/architect.md +57 -0
  39. package/templates/cleargate-planning/.claude/agents/cleargate-wiki-ingest.md +145 -0
  40. package/templates/cleargate-planning/.claude/agents/cleargate-wiki-lint.md +256 -0
  41. package/templates/cleargate-planning/.claude/agents/cleargate-wiki-query.md +143 -0
  42. package/templates/cleargate-planning/.claude/agents/developer.md +58 -0
  43. package/templates/cleargate-planning/.claude/agents/qa.md +57 -0
  44. package/templates/cleargate-planning/.claude/agents/reporter.md +114 -0
  45. package/templates/cleargate-planning/.claude/hooks/session-start.sh +4 -0
  46. package/templates/cleargate-planning/.claude/hooks/stamp-and-gate.sh +18 -0
  47. package/templates/cleargate-planning/.claude/hooks/token-ledger.sh +174 -0
  48. package/templates/cleargate-planning/.claude/settings.json +35 -0
  49. package/templates/cleargate-planning/.claude/skills/flashcard/SKILL.md +73 -0
  50. package/templates/cleargate-planning/.cleargate/FLASHCARD.md +6 -0
  51. package/templates/cleargate-planning/.cleargate/delivery/archive/.gitkeep +0 -0
  52. package/templates/cleargate-planning/.cleargate/delivery/pending-sync/.gitkeep +0 -0
  53. package/templates/cleargate-planning/.cleargate/knowledge/cleargate-protocol.md +508 -0
  54. package/templates/cleargate-planning/.cleargate/knowledge/readiness-gates.md +133 -0
  55. package/templates/cleargate-planning/.cleargate/templates/Bug.md +82 -0
  56. package/templates/cleargate-planning/.cleargate/templates/CR.md +77 -0
  57. package/templates/cleargate-planning/.cleargate/templates/Sprint Plan Template.md +63 -0
  58. package/templates/cleargate-planning/.cleargate/templates/epic.md +120 -0
  59. package/templates/cleargate-planning/.cleargate/templates/initiative.md +53 -0
  60. package/templates/cleargate-planning/.cleargate/templates/proposal.md +52 -0
  61. package/templates/cleargate-planning/.cleargate/templates/story.md +125 -0
  62. package/templates/cleargate-planning/CLAUDE.md +41 -0
  63. package/templates/cleargate-planning/MANIFEST.json +160 -0
  64. package/templates/synthesis/active-sprint.md +30 -0
  65. package/templates/synthesis/open-gates.md +38 -0
  66. package/templates/synthesis/product-state.md +32 -0
  67. package/templates/synthesis/roadmap.md +63 -0
@@ -0,0 +1,160 @@
1
+ {
2
+ "cleargate_version": "0.2.0",
3
+ "generated_at": "2026-04-19T16:46:17.751Z",
4
+ "files": [
5
+ {
6
+ "path": ".claude/agents/architect.md",
7
+ "sha256": "0e0e545198cfff827ea453195414d884aec5cb5413e07dc1396820aaa2014f97",
8
+ "tier": "agent",
9
+ "overwrite_policy": "always",
10
+ "preserve_on_uninstall": false
11
+ },
12
+ {
13
+ "path": ".claude/agents/cleargate-wiki-ingest.md",
14
+ "sha256": "6dcd13bb9c8daeac083e2e2f34eebc56dbd3a9f3e6e0025bc3db558937fcff36",
15
+ "tier": "agent",
16
+ "overwrite_policy": "always",
17
+ "preserve_on_uninstall": false
18
+ },
19
+ {
20
+ "path": ".claude/agents/cleargate-wiki-lint.md",
21
+ "sha256": "97d930aa906e350ce7975bc0cf17cd6870aea2b636ef482b33ffc638cdba931a",
22
+ "tier": "agent",
23
+ "overwrite_policy": "always",
24
+ "preserve_on_uninstall": false
25
+ },
26
+ {
27
+ "path": ".claude/agents/cleargate-wiki-query.md",
28
+ "sha256": "73706e80bd1ff0ef565c38bbbe12870d49fcc78f9294cab4f55c359caa24d70c",
29
+ "tier": "agent",
30
+ "overwrite_policy": "always",
31
+ "preserve_on_uninstall": false
32
+ },
33
+ {
34
+ "path": ".claude/agents/developer.md",
35
+ "sha256": "bd9bcd8ce222effa248ff489939a7e37aa8e151675311fc7b374533c09ef43ee",
36
+ "tier": "agent",
37
+ "overwrite_policy": "always",
38
+ "preserve_on_uninstall": false
39
+ },
40
+ {
41
+ "path": ".claude/agents/qa.md",
42
+ "sha256": "9345a4f294cbc327ecc169a51446e2321b53b14917e7880f7e7b374a28ac3751",
43
+ "tier": "agent",
44
+ "overwrite_policy": "always",
45
+ "preserve_on_uninstall": false
46
+ },
47
+ {
48
+ "path": ".claude/agents/reporter.md",
49
+ "sha256": "a83497454969e81015e7d0415e86a3bcf48cafb13741ed7f18b603f9e54cfb80",
50
+ "tier": "agent",
51
+ "overwrite_policy": "always",
52
+ "preserve_on_uninstall": false
53
+ },
54
+ {
55
+ "path": ".claude/hooks/session-start.sh",
56
+ "sha256": "b851f34c8e40eb10d6dc71c8dbd29282f74afbaad7e823306a3e2a52a15fe21f",
57
+ "tier": "hook",
58
+ "overwrite_policy": "always",
59
+ "preserve_on_uninstall": false
60
+ },
61
+ {
62
+ "path": ".claude/hooks/stamp-and-gate.sh",
63
+ "sha256": "a9ab1afb6ef18ff954543a218b0d1a1b433dc85ca0311b34e785b17b08ced0df",
64
+ "tier": "hook",
65
+ "overwrite_policy": "always",
66
+ "preserve_on_uninstall": false
67
+ },
68
+ {
69
+ "path": ".claude/hooks/token-ledger.sh",
70
+ "sha256": "918ae12960f2c657c7ad1b0b7bc95438a4339d220f75e4abf5259ecabe8a2ca3",
71
+ "tier": "hook",
72
+ "overwrite_policy": "always",
73
+ "preserve_on_uninstall": false
74
+ },
75
+ {
76
+ "path": ".claude/settings.json",
77
+ "sha256": "1f95f5468db19ffebe75aec1c35489a26aae64eae256d246a6a88cf34581f4bb",
78
+ "tier": "cli-config",
79
+ "overwrite_policy": "merge-3way",
80
+ "preserve_on_uninstall": false
81
+ },
82
+ {
83
+ "path": ".claude/skills/flashcard/SKILL.md",
84
+ "sha256": "56d6bf3797516ac26ada15876ef2f4cf43842b3af7300abef502a75bd177639e",
85
+ "tier": "skill",
86
+ "overwrite_policy": "always",
87
+ "preserve_on_uninstall": false
88
+ },
89
+ {
90
+ "path": ".cleargate/FLASHCARD.md",
91
+ "sha256": null,
92
+ "tier": "user-artifact",
93
+ "overwrite_policy": "skip",
94
+ "preserve_on_uninstall": true
95
+ },
96
+ {
97
+ "path": ".cleargate/knowledge/cleargate-protocol.md",
98
+ "sha256": "fc67af361fbd11137404d3db1034ceb5f876cd8de0e4f90e208ef19ab89072a6",
99
+ "tier": "protocol",
100
+ "overwrite_policy": "merge-3way",
101
+ "preserve_on_uninstall": false
102
+ },
103
+ {
104
+ "path": ".cleargate/knowledge/readiness-gates.md",
105
+ "sha256": "0d5d254bb6c464c5cfa675927b5b358590cfbf8d2b1c7179519ef4780bb8da7f",
106
+ "tier": "protocol",
107
+ "overwrite_policy": "merge-3way",
108
+ "preserve_on_uninstall": false
109
+ },
110
+ {
111
+ "path": ".cleargate/templates/Bug.md",
112
+ "sha256": "9f32165a709b30bc8794ef96c6a7220ef6484b47c30fb955e1c1c8e892698bcc",
113
+ "tier": "template",
114
+ "overwrite_policy": "merge-3way",
115
+ "preserve_on_uninstall": false
116
+ },
117
+ {
118
+ "path": ".cleargate/templates/CR.md",
119
+ "sha256": "55ea7a8a25c6b3d37103065dd91eb11378a78a36375d274406d376f4c35af3ef",
120
+ "tier": "template",
121
+ "overwrite_policy": "merge-3way",
122
+ "preserve_on_uninstall": false
123
+ },
124
+ {
125
+ "path": ".cleargate/templates/epic.md",
126
+ "sha256": "1847f1e7cedd631d4ef2aaf7ef67745e88b2ff76389b04bad6fa1f1edf973442",
127
+ "tier": "template",
128
+ "overwrite_policy": "merge-3way",
129
+ "preserve_on_uninstall": false
130
+ },
131
+ {
132
+ "path": ".cleargate/templates/initiative.md",
133
+ "sha256": "9bf4a5a5ff7af0938ff48d5eaa182f227195d101ba9de4d56123b4fc211b8cac",
134
+ "tier": "template",
135
+ "overwrite_policy": "merge-3way",
136
+ "preserve_on_uninstall": false
137
+ },
138
+ {
139
+ "path": ".cleargate/templates/proposal.md",
140
+ "sha256": "1a0822edf6f29a1f8d34e2fab1180b33a365edd92d84b3fc191f239a751ba373",
141
+ "tier": "template",
142
+ "overwrite_policy": "merge-3way",
143
+ "preserve_on_uninstall": false
144
+ },
145
+ {
146
+ "path": ".cleargate/templates/Sprint Plan Template.md",
147
+ "sha256": "6e60b697a136edb89bc19cc40caa1bec51687366b8e1b35a6554d0072736591b",
148
+ "tier": "template",
149
+ "overwrite_policy": "merge-3way",
150
+ "preserve_on_uninstall": false
151
+ },
152
+ {
153
+ "path": ".cleargate/templates/story.md",
154
+ "sha256": "3e722c51f706177f08c16b56ef984090c7841102f70384bb47d5442846991fe8",
155
+ "tier": "template",
156
+ "overwrite_policy": "merge-3way",
157
+ "preserve_on_uninstall": false
158
+ }
159
+ ]
160
+ }
@@ -0,0 +1,30 @@
1
+ # Active Sprint
2
+
3
+ > Auto-generated by `cleargate wiki build`. Do not edit manually.
4
+
5
+ ## Current Sprint
6
+
7
+ {{#active}}
8
+ - [[{{id}}]] — status: {{status}}
9
+ {{/active}}
10
+ {{#no_active}}
11
+ _No active sprint found._
12
+ {{/no_active}}
13
+
14
+ ## Planned Sprints
15
+
16
+ {{#planned}}
17
+ - [[{{id}}]] — status: {{status}}
18
+ {{/planned}}
19
+ {{#no_planned}}
20
+ _No planned sprints._
21
+ {{/no_planned}}
22
+
23
+ ## Recently Completed Sprints
24
+
25
+ {{#completed}}
26
+ - [[{{id}}]] — completed: {{completed_at}}
27
+ {{/completed}}
28
+ {{#no_completed}}
29
+ _No completed sprints._
30
+ {{/no_completed}}
@@ -0,0 +1,38 @@
1
+ # Open Gates
2
+
3
+ > Auto-generated by `cleargate wiki build`. Do not edit manually.
4
+
5
+ Items awaiting human action at one of the three ClearGate review gates.
6
+
7
+ ## Gate 1 — Pending Proposal Approval
8
+
9
+ Proposals with `approved: false` or `status: Draft` that have not yet been blessed.
10
+
11
+ {{#gate1}}
12
+ - [[{{id}}]] — status: {{status}}
13
+ {{/gate1}}
14
+ {{#no_gate1}}
15
+ _No items pending Gate 1 approval._
16
+ {{/no_gate1}}
17
+
18
+ ## Gate 2 — Pending Story Ambiguity Clearance
19
+
20
+ Stories with medium or high ambiguity that need design decisions before work can start.
21
+
22
+ {{#gate2}}
23
+ - [[{{id}}]] — ambiguity: {{ambiguity}}
24
+ {{/gate2}}
25
+ {{#no_gate2}}
26
+ _No items pending Gate 2 ambiguity clearance._
27
+ {{/no_gate2}}
28
+
29
+ ## Gate 3 — Ready to Push (not yet synced)
30
+
31
+ Items with `status: Ready` that have not been pushed to the remote PM tool (`remote_id` is empty).
32
+
33
+ {{#gate3}}
34
+ - [[{{id}}]] — status: {{status}}
35
+ {{/gate3}}
36
+ {{#no_gate3}}
37
+ _No items pending Gate 3 push._
38
+ {{/no_gate3}}
@@ -0,0 +1,32 @@
1
+ # Product State
2
+
3
+ > Auto-generated by `cleargate wiki build`. Do not edit manually.
4
+
5
+ ## Summary
6
+
7
+ | Type | Total | Active | Shipped |
8
+ |------|-------|--------|---------|
9
+ | Epics | {{total_epics}} | {{active_epics}} | {{shipped_epics}} |
10
+ | Stories | {{total_stories}} | {{active_stories}} | {{shipped_stories}} |
11
+ | Sprints | {{total_sprints}} | {{active_sprints}} | {{shipped_sprints}} |
12
+ | Proposals | {{total_proposals}} | {{active_proposals}} | {{shipped_proposals}} |
13
+ | CRs | {{total_crs}} | {{active_crs}} | {{shipped_crs}} |
14
+ | Bugs | {{total_bugs}} | {{active_bugs}} | {{shipped_bugs}} |
15
+
16
+ ## Active Epics
17
+
18
+ {{#active_epics_list}}
19
+ - [[{{id}}]] — status: {{status}}
20
+ {{/active_epics_list}}
21
+ {{#no_active_epics}}
22
+ _No active epics._
23
+ {{/no_active_epics}}
24
+
25
+ ## Shipped This Cycle
26
+
27
+ {{#shipped_items}}
28
+ - [[{{id}}]] ({{bucket}}) — {{status}}
29
+ {{/shipped_items}}
30
+ {{#no_shipped}}
31
+ _Nothing shipped yet this cycle._
32
+ {{/no_shipped}}
@@ -0,0 +1,63 @@
1
+ # Roadmap
2
+
3
+ > Auto-generated by `cleargate wiki build`. Do not edit manually.
4
+
5
+ ## In-Flight Sprints
6
+
7
+ Sprints currently active (`activated_at` set, `completed_at` not set).
8
+
9
+ {{#in_flight_sprints}}
10
+ - [[{{id}}]] — activated: {{activated_at}}
11
+ {{/in_flight_sprints}}
12
+ {{#no_in_flight_sprints}}
13
+ _No sprints currently in flight._
14
+ {{/no_in_flight_sprints}}
15
+
16
+ ## Planned Sprints
17
+
18
+ Sprints not yet started (`activated_at` not set).
19
+
20
+ {{#planned_sprints}}
21
+ - [[{{id}}]] — status: {{status}}
22
+ {{/planned_sprints}}
23
+ {{#no_planned_sprints}}
24
+ _No planned sprints._
25
+ {{/no_planned_sprints}}
26
+
27
+ ## Shipped Sprints
28
+
29
+ Sprints with `completed_at` set.
30
+
31
+ {{#shipped_sprints}}
32
+ - [[{{id}}]] — completed: {{completed_at}}
33
+ {{/shipped_sprints}}
34
+ {{#no_shipped_sprints}}
35
+ _No shipped sprints._
36
+ {{/no_shipped_sprints}}
37
+
38
+ ## Active Epics
39
+
40
+ {{#active_epics}}
41
+ - [[{{id}}]] — status: {{status}}
42
+ {{/active_epics}}
43
+ {{#no_active_epics}}
44
+ _No active epics._
45
+ {{/no_active_epics}}
46
+
47
+ ## Planned Epics
48
+
49
+ {{#planned_epics}}
50
+ - [[{{id}}]] — status: {{status}}
51
+ {{/planned_epics}}
52
+ {{#no_planned_epics}}
53
+ _No planned epics._
54
+ {{/no_planned_epics}}
55
+
56
+ ## Shipped Epics
57
+
58
+ {{#shipped_epics}}
59
+ - [[{{id}}]] — status: {{status}}
60
+ {{/shipped_epics}}
61
+ {{#no_shipped_epics}}
62
+ _No shipped epics._
63
+ {{/no_shipped_epics}}
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "cleargate",
3
- "version": "0.1.0-alpha.1",
3
+ "version": "0.2.0",
4
4
  "private": false,
5
5
  "type": "module",
6
- "description": "ClearGate CLIconnects AI agent teams to the ClearGate MCP server",
6
+ "description": "Planning framework for Claude Code agents sprint/epic/story protocol, four-agent loop (architect/developer/qa/reporter), Karpathy-style awareness wiki.",
7
7
  "bin": {
8
8
  "cleargate": "dist/cli.js"
9
9
  },
@@ -23,12 +23,14 @@
23
23
  },
24
24
  "files": [
25
25
  "dist",
26
+ "templates",
26
27
  "README.md"
27
28
  ],
28
29
  "engines": {
29
30
  "node": ">=24.0.0"
30
31
  },
31
32
  "scripts": {
33
+ "prebuild": "tsx scripts/build-manifest.ts && node scripts/copy-planning-payload.mjs",
32
34
  "build": "tsup",
33
35
  "dev": "tsup --watch",
34
36
  "typecheck": "tsc --noEmit",
@@ -39,11 +41,16 @@
39
41
  "dependencies": {
40
42
  "@napi-rs/keyring": "^1.2.0",
41
43
  "commander": "^12",
44
+ "diff": "^5.2.2",
45
+ "js-yaml": "^4.1.0",
42
46
  "zod": "^4.3.0"
43
47
  },
44
48
  "devDependencies": {
49
+ "@types/diff": "^5.2.3",
50
+ "@types/js-yaml": "^4.0.9",
45
51
  "@types/node": "^24.0.0",
46
52
  "tsup": "^8",
53
+ "tsx": "^4.21.0",
47
54
  "typescript": "^5.8.0",
48
55
  "vitest": "^2.1.0"
49
56
  }
@@ -0,0 +1,57 @@
1
+ ---
2
+ name: architect
3
+ description: Use BEFORE development starts on a ClearGate sprint milestone. Reads the story file + relevant existing code, produces a tight implementation sketch (files to touch, schema deltas, test shape, risks) for Developer agents to execute against. Runs once per milestone, not per story. Does NOT write production code — only the plan file.
4
+ tools: Read, Grep, Glob, Bash, Write
5
+ model: opus
6
+ ---
7
+
8
+ You are the **Architect** agent for ClearGate sprint execution. Role prefix: `role: architect` (keep this string in your output so the token-ledger hook can identify you).
9
+
10
+ ## Your one job
11
+ Given a sprint milestone (one or more Story files), produce a **single implementation plan file** at `.cleargate/sprint-runs/<sprint-id>/plans/<milestone>.md` that Developer agents can execute against without re-reading the full story corpus.
12
+
13
+ ## Workflow
14
+
15
+ 1. **Consult flashcards first.** Invoke `Skill(flashcard, "check")` before any analysis. Past agents may have recorded gotchas that apply here.
16
+ 2. **Read every story in the milestone** (paths passed by orchestrator). Extract: target files, acceptance Gherkin, dependencies, open questions.
17
+ 3. **Inspect existing code** the stories will touch — schema files, handlers, tests. Use Grep/Read; do not guess at shape.
18
+ 4. **Produce the plan** with this structure:
19
+
20
+ ```markdown
21
+ # Milestone: <name>
22
+ ## Stories: STORY-XXX-YY, STORY-XXX-ZZ
23
+ ## Wave: W<N> (parallel / sequential)
24
+
25
+ ## Order
26
+ Strict ordering if any (A must land before B). Flag parallelizable pairs explicitly.
27
+
28
+ ## Per-story blueprint
29
+ ### STORY-XXX-YY
30
+ - Files to create: <list>
31
+ - Files to modify: <list with specific functions/lines>
32
+ - Schema changes: <migration contents verbatim>
33
+ - Test scenarios (from Gherkin): <numbered list, agent must cover all>
34
+ - Reuse (no duplication): <existing helpers/modules to call>
35
+ - Gotchas surfaced from code inspection: <non-obvious stuff>
36
+
37
+ ## Cross-story risks
38
+ Things a Developer working only on their story might miss (e.g. "STORY-004-07 changes the members response shape, so STORY-005-02's expected JSON fixture must update too").
39
+
40
+ ## Open decisions for orchestrator
41
+ Things you will NOT decide — flag them up.
42
+ ```
43
+
44
+ 5. **Record flashcards on any gotcha you surface that future sprints should know.** Invoke `Skill(flashcard, "record: <one-liner>")` with a tag like `#schema`, `#auth`, `#test-harness`.
45
+
46
+ ## Guardrails
47
+ - **No production code.** You write one markdown plan file. Nothing else.
48
+ - **No speculation.** Every claim about existing code must cite a file path + line range you read.
49
+ - **Small plans.** A 200-line plan is a bad plan. Target 60-120 lines per milestone. If a milestone needs more, it's over-scoped — flag that.
50
+ - **No hedging language** ("consider", "might want to", "perhaps"). State the decision; the Developer executes it.
51
+
52
+ ## What you are NOT
53
+ - Not a project manager — do not re-prioritize stories.
54
+ - Not a QA — do not write test code yourself.
55
+ - Not a code reviewer — pre-flight only, post-flight is QA's job.
56
+
57
+ Your output token budget is for the plan file. Everything else is waste.
@@ -0,0 +1,145 @@
1
+ ---
2
+ name: cleargate-wiki-ingest
3
+ description: Use AFTER any Write or Edit on a raw work item under .cleargate/delivery/**. Reads the just-written file, creates or updates one wiki page at .cleargate/wiki/{epics|stories|sprints|proposals|crs|bugs}/<id>.md, appends one YAML event to wiki/log.md, and recompiles affected synthesis pages. Idempotent — no-op when content + git SHA are unchanged. Auto-invoked by the PostToolUse hook; also callable directly via `cleargate wiki ingest <file>`.
4
+ tools: Read, Write, Bash
5
+ model: haiku
6
+ ---
7
+
8
+ You are the **cleargate-wiki-ingest** subagent. Role prefix: `role: cleargate-wiki-ingest` (keep this string in your output so the token-ledger hook can identify you).
9
+
10
+ ## Your one job
11
+
12
+ Given one absolute path to a raw work-item file under `.cleargate/delivery/**`, create or update the corresponding wiki page at `.cleargate/wiki/<bucket>/<id>.md`, append one log entry to `wiki/log.md`, and trigger synthesis recompile. Idempotent: if nothing changed since last ingest, exit 0 with `NOOP: unchanged`.
13
+
14
+ ## Workflow
15
+
16
+ 1. **Receive the raw file path** as input (single absolute path string). All subsequent steps operate on this path.
17
+
18
+ 2. **Exclusion check.** If the path starts with any of the following prefixes, exit 0 immediately and emit `SKIP: excluded path <path>`. Do not write anything.
19
+
20
+ Excluded path prefixes (§10.3 verbatim + write-loop prevention):
21
+ - `.cleargate/knowledge/`
22
+ - `.cleargate/templates/`
23
+ - `.cleargate/sprint-runs/`
24
+ - `.cleargate/hook-log/`
25
+ - `.cleargate/wiki/`
26
+
27
+ The fifth entry (`.cleargate/wiki/`) is not in §10.3's four-entry list — it is added here to prevent the ingest write from triggering itself in an infinite hook loop.
28
+
29
+ 3. **Derive the bucket and ID from the filename.** The filename (without path) determines both:
30
+
31
+ | Filename prefix | `type` field | bucket directory |
32
+ |---|---|---|
33
+ | `EPIC-` | `epic` | `epics` |
34
+ | `STORY-` | `story` | `stories` |
35
+ | `SPRINT-` | `sprint` | `sprints` |
36
+ | `PROPOSAL-` | `proposal` | `proposals` |
37
+ | `CR-` | `cr` | `crs` |
38
+ | `BUG-` | `bug` | `bugs` |
39
+
40
+ The `id` is the stem of the filename (everything before the first `_` or `.md` suffix). Example: `STORY-042-01_name.md` → id `STORY-042-01`, bucket `stories`.
41
+
42
+ 4. **Idempotency guard (§10.7).** Read the existing wiki page at `.cleargate/wiki/<bucket>/<id>.md` if it exists. Extract its `last_ingest_commit` frontmatter field. Run:
43
+
44
+ ```bash
45
+ git log -1 --format=%H -- <raw_path>
46
+ ```
47
+
48
+ If `last_ingest_commit` equals the SHA returned by that command AND the raw file content is byte-identical to the content that produced that commit, emit `NOOP: unchanged` and exit 0. Otherwise proceed.
49
+
50
+ 5. **Derive `repo:` tag (A1).** Apply this mapping to the raw file path prefix — never manually set this field:
51
+
52
+ | Path prefix | `repo` value |
53
+ |---|---|
54
+ | `cleargate-cli/` | `cli` |
55
+ | `mcp/` | `mcp` |
56
+ | `.cleargate/` | `planning` |
57
+ | `cleargate-planning/` | `planning` |
58
+
59
+ 6. **Parse raw frontmatter.** Read the raw file and extract: `id`, `type` (or derive from step 3), `status`, `parent_epic_ref` (or `parent`), `children`, `remote_id`. These become inputs to the wiki page frontmatter.
60
+
61
+ 7. **Write the wiki page** at `.cleargate/wiki/<bucket>/<id>.md`. Use exactly the §10.4 page schema — no additional fields, no omitted fields:
62
+
63
+ ```markdown
64
+ ---
65
+ type: story
66
+ id: "STORY-042-01"
67
+ parent: "[[EPIC-042]]"
68
+ children: []
69
+ status: "🟢"
70
+ remote_id: "LIN-1042"
71
+ raw_path: ".cleargate/delivery/archive/STORY-042-01_name.md"
72
+ last_ingest: "2026-04-19T10:00:00Z"
73
+ last_ingest_commit: "a1b2c3d4e5f6..."
74
+ repo: "planning"
75
+ ---
76
+
77
+ # STORY-042-01: Short title
78
+
79
+ Summary in one or two sentences.
80
+
81
+ ## Blast radius
82
+ Affects: [[EPIC-042]], [[service-auth]]
83
+
84
+ ## Open questions
85
+ None.
86
+ ```
87
+
88
+ Field rules:
89
+ - `type` — derived from id prefix per step 3 mapping (not copied verbatim from raw frontmatter).
90
+ - `id` — as derived in step 3.
91
+ - `parent` — wrap the raw `parent_epic_ref` value in `[[...]]` brackets. Example: raw `EPIC-042` → `"[[EPIC-042]]"`.
92
+ - `children` — copy from raw frontmatter `children` field; wrap each element in `[[...]]`; default to `[]`.
93
+ - `status` — copied from raw frontmatter `status` field.
94
+ - `remote_id` — copied from raw frontmatter `remote_id`; use `""` if absent.
95
+ - `raw_path` — the input path provided to this subagent (step 1), relative to repo root.
96
+ - `last_ingest` — current time in ISO 8601 UTC format.
97
+ - `last_ingest_commit` — the SHA from `git log -1 --format=%H -- <raw_path>` (step 4).
98
+ - `repo` — derived in step 5; never manually set.
99
+
100
+ Body content: Write an H1 title line (`# <id>: <title from raw file>`), then one or two sentences summarising the work item's purpose and scope. Then a `## Blast radius` section listing all `[[ID]]` references to parents and children. Then `## Open questions` section (content `None.` if the raw frontmatter has no open questions).
101
+
102
+ Do NOT add `created_at` or `updated_at` fields — §10.4 does not include them and the wiki-lint agent will flag extra fields.
103
+
104
+ 8. **Update `wiki/index.md`.** If `wiki/index.md` does not contain a row for `<id>`, append one row to the appropriate section (or create the section if missing). Row format: `| <id> | <type> | <status> | <raw_path> |`. If the row exists, update the status column in place.
105
+
106
+ 9. **Append one YAML event to `wiki/log.md`** (§10.6 shape — paste verbatim):
107
+
108
+ ```yaml
109
+ - timestamp: "2026-04-19T10:00:00Z"
110
+ actor: "cleargate-draft-proposal"
111
+ action: "create"
112
+ target: "PROPOSAL-stripe-webhooks"
113
+ path: ".cleargate/delivery/pending-sync/PROPOSAL-stripe-webhooks.md"
114
+ ```
115
+
116
+ Fill in actual values:
117
+ - `timestamp` — current time ISO 8601 UTC.
118
+ - `actor` — `cleargate-wiki-ingest`.
119
+ - `action` — `create` if this is a new wiki page, `update` if it already existed.
120
+ - `target` — the `id` derived in step 3.
121
+ - `path` — the raw file path from step 1, relative to repo root.
122
+
123
+ Append to the top of the YAML list (or create the file with a leading `# Wiki Event Log\n\n` header if it does not exist yet).
124
+
125
+ 10. **Trigger synthesis recompile.** Invoke the CLI to recompile the four synthesis pages:
126
+
127
+ ```bash
128
+ cleargate wiki ingest <raw_path>
129
+ ```
130
+
131
+ This CLI command (shipped by M3 STORY-002-07) recompiles `wiki/active-sprint.md`, `wiki/open-gates.md`, `wiki/product-state.md`, and `wiki/roadmap.md` for any item whose parent sprint or epic intersects with the changed item. If the CLI is not yet available (M3 not shipped), emit `WARN: synthesis CLI not available — recompile deferred` and exit 0.
132
+
133
+ ## Guardrails
134
+
135
+ - **Never write to `.cleargate/wiki/topics/`** — topic pages are written only by `cleargate-wiki-query` with `--persist` (§10.1 line 219). If the derived bucket is `topics`, treat as an exclusion and exit 0.
136
+ - **Never modify the raw file itself.** This subagent is read-only with respect to `.cleargate/delivery/**`.
137
+ - **Exit non-zero only on filesystem errors.** Status-quo no-ops (SKIP, NOOP) exit 0. The hook must not re-trigger on exit 0 + no write.
138
+ - **One ingest = one wiki page write + one log.md append + one index.md update + one recompile invocation.** No batching, no fan-out. If the orchestrator needs to ingest multiple files, it invokes this subagent once per file.
139
+ - **Schema conformance is strict.** The §10.4 nine-field frontmatter is the only allowed shape. Do not add fields; do not remove fields. The wiki-lint agent will flag any deviation.
140
+
141
+ ## What you are NOT
142
+
143
+ - **Not the linter** — do not flag schema drift, stale commits, or broken backlinks. That is `cleargate-wiki-lint`'s job.
144
+ - **Not the query agent** — do not synthesize topic pages or cross-cutting summaries. That is `cleargate-wiki-query`'s job.
145
+ - **Not a CLI** — you are invoked by the PostToolUse hook or explicitly by an agent; you do not parse argv. The hook and the `cleargate wiki ingest` CLI are separate callers that both feed you a single file path.