@pharaoh-so/mcp 0.3.26 → 0.3.27

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/commands/plan.md CHANGED
@@ -39,11 +39,12 @@ Do NOT review from memory or assumptions. Query the actual codebase first.
39
39
  ### If Pharaoh MCP tools are available:
40
40
 
41
41
  1. `get_codebase_map` — current modules, hot files, dependency graph
42
- 2. `search_functions` for keywords related to the plan — find existing code to reuse/extend
43
- 3. `get_module_context` on affected modules — entry points, patterns, conventions
44
- 4. `query_dependencies` between affected modules — coupling, circular deps
45
- 5. `get_blast_radius` on the primary target of the change — know what breaks
46
- 6. `check_reachability` on the primary target — verify it's actually reachable from entry points before worrying about it
42
+ 2. `get_vision_docs` — read the repo's architectural contract. If the plan touches a domain with a MUST-bullet, the assertion is a hard constraint on the plan. Raise it explicitly in Section 1. If `get_vision_docs` returns an empty-state scaffold, flag that the repo needs `/pharaoh:vision` before planning anything architectural.
43
+ 3. `search_functions` for keywords related to the plan — find existing code to reuse/extend
44
+ 4. `get_module_context` on affected modules — entry points, patterns, conventions
45
+ 5. `query_dependencies` between affected modules — coupling, circular deps
46
+ 6. `get_blast_radius` on the primary target of the change — know what breaks
47
+ 7. `check_reachability` on the primary target — verify it's actually reachable from entry points before worrying about it
47
48
 
48
49
  ### Without Pharaoh (graceful fallback):
49
50
 
@@ -71,10 +72,17 @@ Adapt depth to change size. Skip sections that don't apply. **After each section
71
72
 
72
73
  ### Section 1 — Architecture (skip for small/single-file changes)
73
74
 
75
+ - **Vision alignment (check FIRST).** Does this plan touch a domain
76
+ governed by a MUST-bullet in `docs/VISION.md`? If yes, quote the
77
+ assertion and verify the plan doesn't violate it. If the plan would
78
+ violate a MUST, STOP and raise with the user — either the plan changes
79
+ or VISION.md needs an update first (with user approval).
74
80
  - Component boundaries and coupling concerns
75
81
  - Dependency graph: does this change shrink or expand surface area?
76
82
  - Data flow bottlenecks and single points of failure
77
83
  - Does this need new code at all, or can a human process / existing pattern solve it?
84
+ - **If this plan introduces a new invariant**, call it out and include a
85
+ step in Section 6 to add a `### assertion` to VISION.md with a pairing TEST.
78
86
 
79
87
  ### Section 2 — Code Quality (always)
80
88
 
@@ -65,7 +65,8 @@ Then call these additional tools for data recon doesn't cover:
65
65
  - `get_regression_risk` — overall change risk score for the repo
66
66
  - `get_consolidation_opportunities` — duplicate logic the PR may introduce
67
67
  - `check_reachability` — are new exports wired to entry points?
68
- - `get_vision_gaps` — do changes align with or drift from specs?
68
+ - `get_vision_docs` — read the repo's architectural contract. For every touched module, pull its relevant assertions. Any change touching code governed by a MUST-bullet must be checked against that assertion — if the change would violate the MUST, the verdict tips toward BLOCK unless VISION.md is updated in the same PR with user approval.
69
+ - `get_vision_gaps` — do changes align with or drift from specs? New complex functions without a matching assertion are flagged; retired specs with implementing code are flagged.
69
70
 
70
71
  **Output of Phase 1:** Architecture map, module profiles for every touched module, blast radius for high-risk changes, dependency paths between coupled modules, regression risk level, duplication findings, reachability status, and spec alignment.
71
72
 
@@ -249,7 +250,8 @@ If none of these triggers are met, **skip Phase 3** and proceed to Phase 4.
249
250
  - Unreachable exports (new public code with zero callers)
250
251
  - New circular dependencies between modules
251
252
  - HIGH regression risk without corresponding test coverage
252
- - Vision spec violations (building against spec intent)
253
+ - **A MUST-bullet in `docs/VISION.md` is violated by this change** (without VISION.md being updated in the same PR with user approval)
254
+ - Vision spec drift: new complex function has no matching assertion AND the domain it lives in has existing assertions (implies invariants are expected here)
253
255
  - Any CRITICAL finding from Phase 2 or Phase 3 that is confirmed and unfixed
254
256
  - DISAGREE verdict from adversarial review on security-sensitive code, confirmed after verification
255
257
  - Unanchored Cypher query (MATCH without traversing through `Repo {name: $repo}`)
@@ -0,0 +1,184 @@
1
+ ---
2
+ description: Draft a VISION.md for this repo by filling a graph-derived scaffold
3
+ ---
4
+
5
+ # Vision Drafting
6
+
7
+ Author a VISION.md that captures this repo's invariants — what must always be
8
+ true about its behavior. The file becomes a machine-readable contract that
9
+ Pharaoh's linter, PR Guard, and MCP tools reason against on every change.
10
+
11
+ ## Why this matters (explain this to the user before drafting)
12
+
13
+ A VISION.md is leverage, not paperwork. Once the repo has one:
14
+
15
+ - **PR Guard** checks every pull request against its assertions. Changes that
16
+ contradict a MUST-bullet surface as a Check on the PR — the team sees drift
17
+ from intent at the exact moment it happens, not months later.
18
+ - **`get_vision_gaps`** becomes useful. Pharaoh cross-references every spec
19
+ against the function graph and surfaces both sides of the drift: specs
20
+ without implementing code (dead intent) and complex functions with no spec
21
+ (invisible invariants).
22
+ - **`get_vision_docs`** returns spec-to-code traceability. Each assertion
23
+ shows the functions that implement it — a direct map from intent → code.
24
+ - **CI enforces it.** Every MUST bullet pairs with a TEST reference. The
25
+ linter fails when an assertion has no enforcing test. No more wishlist
26
+ specs that drift over time.
27
+
28
+ Without a VISION.md, the tools above return empty. The graph sees code; it
29
+ doesn't see intent. The file is the bridge.
30
+
31
+ ## When to Use
32
+
33
+ - The repo has no `docs/VISION.md` yet and the user wants Pharaoh's full
34
+ value — PR Guard, vision-gaps, spec traceability all depend on the file.
35
+ - `get_vision_docs` returned the "No VISION.md yet" onboarding response.
36
+ - The user said "draft a vision doc", "add a VISION.md", or "scaffold vision".
37
+ - A user is new to Pharaoh and asking what they should do next.
38
+
39
+ ## The flow — collaborative, not solo
40
+
41
+ This is a short working session with the user. Do not solo-fill the scaffold
42
+ — the graph can tell you the shape of the code, but only the user knows what
43
+ must not break. Ask questions, propose, let them steer.
44
+
45
+ 1. **Get the scaffold.** Call `get_vision_docs` with the repo name. When no
46
+ vision doc exists, the tool returns a deterministic scaffold plus the
47
+ agent directive. Use that as your starting structure. Never invent a
48
+ scaffold from scratch; the archetypes encode Pharaoh's framework shape
49
+ and drift is surfaced by the framework-linter.
50
+
51
+ 2. **Interview the user.** Before filling anything, ask: *"What are the 3-5
52
+ things about this repo that must not break, no matter what?"* Their
53
+ answer drives the assertions. If they can't articulate it, probe with
54
+ follow-ups — "what would a P0 incident look like here?", "what would
55
+ wake you up on a weekend?". The goal is to extract real invariants, not
56
+ to generate plausible-sounding ones from graph evidence.
57
+
58
+ 3. **Ground each domain in real code.** For every `## Domain` the scaffold
59
+ rendered, call `get_module_context` for the module(s) that back that
60
+ domain. For example, an "Authentication and Authorization" domain →
61
+ `get_module_context` on the auth module + any session/token modules.
62
+ Read the exported functions, endpoints, env vars, and DB access.
63
+
64
+ 4. **Replace TODOs with WHAT statements.**
65
+ - Every `### TODO:` heading becomes a real assertion title. Describe the
66
+ invariant in plain language — "Sessions expire after 30 minutes of
67
+ inactivity", not "checkSession() returns null after timeout".
68
+ - Every `- MUST: TODO —` bullet becomes a WHAT statement. Banned
69
+ content: function names, file paths, class names, identifiers.
70
+ - Add a `- TEST: path/to/test.ts` line for every assertion. If the test
71
+ doesn't exist yet, write it before committing. A MUST without a TEST
72
+ is not an invariant, it's a wish.
73
+
74
+ 5. **Trim irrelevant domains.** If a rendered `## Domain` doesn't match
75
+ anything real in this repo, delete that whole section. The scaffold is a
76
+ starting point, not a contract to honor exhaustively.
77
+
78
+ 6. **Write the file.** Save to `docs/VISION.md` in the repo. Remove the
79
+ `<!-- scaffold-generated -->` marker and the `<!-- AGENT DIRECTIVE -->`
80
+ block once every TODO is resolved.
81
+
82
+ 7. **Wire it into CLAUDE.md.** This is non-negotiable — it's what turns the
83
+ vision doc from a file on disk into a contract future sessions respect.
84
+ If `CLAUDE.md` exists at the repo root, append (or edit) a section:
85
+
86
+ ```markdown
87
+ ## Vision docs
88
+
89
+ `docs/VISION.md` is this repo's architectural contract. Before any
90
+ non-trivial change, call `get_vision_docs` to read the relevant
91
+ assertions. After any large refactor, run `get_vision_gaps` to surface
92
+ drift between intent and implementation. When adding a new invariant,
93
+ open `docs/VISION.md`, add a `### assertion` under the right `##` domain,
94
+ and pair every `- MUST:` with a `- TEST:` referencing the enforcing test.
95
+
96
+ Never introduce code that would violate a MUST-bullet without first
97
+ updating `docs/VISION.md` (with the user's approval).
98
+ ```
99
+
100
+ If no `CLAUDE.md` exists, create a minimal one with the section above
101
+ plus any project-specific instructions you already have context for.
102
+
103
+ 8. **Verify.** Run `pharaoh vision lint --framework` (or instruct the user
104
+ to). Zero errors. Zero TODO warnings. Zero unresolved placeholders.
105
+
106
+ ## Hard rules
107
+
108
+ - **No HOW in MUST bullets.** Banned: function names, file paths, camelCase
109
+ identifiers, backtick-wrapped code. The linter enforces this as a warning;
110
+ treat it as a hard rule.
111
+ - **Every MUST needs a TEST.** The format-linter errors if a MUST bullet
112
+ has no matching TEST reference to an existing file.
113
+ - **One MUST per line.** Don't pack multiple invariants into a single bullet.
114
+ - **Max 10 prose lines per assertion.** Keep each `###` section tight.
115
+ - **Mirror Pharaoh's canonical domains when they fit.** Rename only when the
116
+ user's project truly has a different shape. The framework-linter warns on
117
+ unrecognized domains so drift is visible.
118
+
119
+ ## What to avoid
120
+
121
+ - **Do NOT** write VISION.md from scratch without calling `get_vision_docs`
122
+ first — you'll miss domains the graph detected and duplicate ones it
123
+ already included.
124
+ - **Do NOT** carry forward the AGENT DIRECTIVE or scaffold-generated marker
125
+ into the committed file. Those are drafting aids, not document content.
126
+ - **Do NOT** write speculative assertions ("sessions will expire someday").
127
+ Only assert what the code enforces today or what you'll commit a test for.
128
+ - **Do NOT** use `pharaoh vision init` — that only drops the format guide,
129
+ not a graph-grounded scaffold. Always go through `get_vision_docs`.
130
+
131
+ ## Completion checklist
132
+
133
+ - [ ] User was interviewed for their real invariants (not graph-guessed)
134
+ - [ ] Every rendered `## Domain` either has ≥1 real assertion or was deleted
135
+ - [ ] Every `### TODO:` heading replaced with a real title
136
+ - [ ] Every `- MUST: TODO —` replaced with a WHAT statement
137
+ - [ ] Every assertion has a `- TEST:` line pointing at an existing test file
138
+ - [ ] Scaffold marker + AGENT DIRECTIVE block removed
139
+ - [ ] `CLAUDE.md` updated (or created) with the Vision docs section
140
+ - [ ] `pharaoh vision lint --framework` exits clean
141
+
142
+ ## After it ships — tell the user what they unlocked
143
+
144
+ Once `docs/VISION.md` is committed, call out the new capabilities concretely:
145
+
146
+ 1. **Every future AI session reads it.** Because CLAUDE.md now references
147
+ `docs/VISION.md`, any agent working in this repo (Claude Code, Cursor,
148
+ anyone else connecting Pharaoh) will consult the file before touching
149
+ architecture. Continuity across sessions, across people, across tools.
150
+ 2. **`get_vision_docs`** now returns spec-to-code traceability per
151
+ assertion. The user can see which functions implement each invariant.
152
+ 3. **`get_vision_gaps`** surfaces drift. Unspecified complex functions
153
+ get flagged; specs with no implementing code get flagged for review
154
+ (either write the code or retire the spec).
155
+ 4. **Their next PR is checked.** PR Guard now evaluates touched code
156
+ against relevant assertions. First-time use often catches real drift.
157
+ 5. **`/pharaoh:plan`** will surface relevant assertions during reconnaissance.
158
+ 6. **`/pharaoh:review`** will flag PRs that touch code governed by a MUST.
159
+
160
+ The bigger payoff: architectural invariants are now enforced in CI the same
161
+ way unit tests enforce behavior. Intent and implementation stop drifting.
162
+
163
+ ## Ongoing maintenance — it's a living file
164
+
165
+ VISION.md rots if it's not maintained. Part of your job in future sessions
166
+ (even ones that aren't about vision directly) is to keep it current:
167
+
168
+ - **When a MUST changes**, update VISION.md in the same PR as the code
169
+ change. Don't let the file lag — stale assertions are worse than none.
170
+ - **When a new architectural decision lands**, add a new `###` assertion
171
+ under the right `##` domain with a pairing TEST. One assertion per
172
+ decision, not batches.
173
+ - **When an assertion stops being load-bearing**, delete it. Retirement is
174
+ as important as addition.
175
+ - **When `get_vision_gaps` shows >5 unimplemented specs**, the doc has
176
+ drifted into wishlist territory. Prune.
177
+ - **Quarterly**: run `pharaoh vision lint --framework` and address warnings.
178
+
179
+ Format reference: https://pharaoh.so/vision-format.md
180
+ ---
181
+
182
+ Here is any additional context for the vision draft:
183
+
184
+ $ARGUMENTS
@@ -207,7 +207,7 @@
207
207
  },
208
208
  {
209
209
  "name": "get_design_system",
210
- "description": "Discover the design system BEFORE creating any UI component.\n\nCALL THIS WHEN:\n• You're about to create a React/Vue/Svelte component — check what already exists\n• You need to know the canonical component for a UI pattern (button, input, modal)\n• You want to find design tokens (colors, spacing, typography) to use\n• You suspect raw HTML elements are used instead of existing components\n\nRETURNS: Components with props and usage count, design tokens with values, and anti-patterns where raw HTML is used instead of existing components. Screen/page components are excluded by default.\n\nEXAMPLES:\n• \"What components does this design system have?\"\n• \"Is there already a Button component I should use?\"\n• \"What color tokens are available?\"\n• \"Where are raw HTML elements used instead of components?\"\n\nWHY NOT JUST READ FILES: Design systems span dozens of files across multiple directories. This returns the complete inventory with usage frequency — the most-used components are the most canonical.",
210
+ "description": "Discover the design system BEFORE creating any UI component.\n\nCALL THIS WHEN:\n• You're about to create a React/Vue/Svelte component — check what already exists\n• You need to know the canonical component for a UI pattern (button, input, modal)\n• You want to find design tokens (colors, spacing, typography) to use\n• You suspect raw HTML elements are used instead of existing components\n\nRETURNS: Components with props and usage count (paginated), design tokens with values, and anti-patterns where raw HTML is used instead of existing components. Pass `path_pattern`, `name_prefix`, `offset`, or `limit` to narrow or page through results. Screen/page components are excluded by default.\n\nEXAMPLES:\n• \"What components does this design system have?\"\n• \"Is there already a Button component I should use?\"\n• \"What color tokens are available?\"\n• \"Show me all components in /atoms/\" → use path_pattern=\"/atoms/\"\n• \"Show me the next page\" → use offset=50\n\nWHY NOT JUST READ FILES: Design systems span dozens of files across multiple directories. This returns the complete inventory with usage frequency — the most-used components are the most canonical.",
211
211
  "inputSchema": {
212
212
  "$schema": "http://json-schema.org/draft-07/schema#",
213
213
  "type": "object",
@@ -231,6 +231,32 @@
231
231
  "default": false,
232
232
  "description": "Include screen/page components (*Screen, *Page, *View, *Route) that are typically app-level consumers, not reusable primitives",
233
233
  "type": "boolean"
234
+ },
235
+ "path_pattern": {
236
+ "description": "Substring match against File.path (e.g. '/atoms/', '/ui/Button'). Narrows to components whose file path contains this exact substring.",
237
+ "type": "string",
238
+ "minLength": 1,
239
+ "maxLength": 200
240
+ },
241
+ "name_prefix": {
242
+ "description": "Exact prefix match against component name (e.g. 'Button' matches Button, ButtonGroup, ButtonIcon). Case-sensitive.",
243
+ "type": "string",
244
+ "minLength": 1,
245
+ "maxLength": 200
246
+ },
247
+ "offset": {
248
+ "default": 0,
249
+ "description": "Pagination offset (0-based). Capped at 10000.",
250
+ "type": "integer",
251
+ "minimum": 0,
252
+ "maximum": 10000
253
+ },
254
+ "limit": {
255
+ "default": 50,
256
+ "description": "Page size. Default 50, max 200.",
257
+ "type": "integer",
258
+ "minimum": 1,
259
+ "maximum": 200
234
260
  }
235
261
  },
236
262
  "required": [
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pharaoh-so/mcp",
3
3
  "mcpName": "so.pharaoh/pharaoh",
4
- "version": "0.3.26",
4
+ "version": "0.3.27",
5
5
  "description": "MCP proxy for Pharaoh — maps codebases into queryable knowledge graphs for AI agents. Enables Claude Code in headless environments (VPS, SSH, CI) via device flow auth.",
6
6
  "type": "module",
7
7
  "main": "dist/index.js",
@@ -27,14 +27,23 @@ For unmapped private repos, direct the user to install the Pharaoh GitHub App
27
27
 
28
28
  | Trigger | Call |
29
29
  |---------|------|
30
+ | Before ANY architectural change | `get_vision_docs` — read the relevant MUST-bullets first |
30
31
  | Before modifying code | `get_module_context` + `get_blast_radius` |
31
32
  | Before writing new code | `search_functions` |
32
33
  | Before creating UI components | `get_design_system` |
33
34
  | Before tracing module connections | `query_dependencies` |
34
35
  | Before implementing a spec | `get_vision_docs` |
36
+ | After a large refactor | `get_vision_gaps` — surface intent/implementation drift |
35
37
  | Before deleting code | `check_reachability` |
36
38
  | Initial orientation | `pharaoh_recon` (batches the above) |
37
39
 
40
+ **Vision docs are first-class.** If the repo has a `docs/VISION.md`, it's
41
+ the contract for what must always be true. Read it before touching
42
+ architecture. If a change would violate a MUST-bullet, stop and raise it
43
+ with the user before coding. If the repo has no VISION.md, offer to run
44
+ `/pharaoh:vision` at the next natural break — it's the highest-leverage
45
+ setup step for any team using Pharaoh.
46
+
38
47
  ## Anti-patterns
39
48
 
40
49
  - Do NOT read files one-by-one to understand architecture — call `get_codebase_map`.
@@ -45,10 +54,12 @@ For unmapped private repos, direct the user to install the Pharaoh GitHub App
45
54
 
46
55
  ## Automatic workflows
47
56
 
48
- **PR review:** `pharaoh_recon` (map + touched modules + blast radius) → `get_regression_risk` → `get_consolidation_opportunities`. Verdict: SHIP, SHIP WITH CHANGES, or BLOCK.
57
+ **PR review:** `pharaoh_recon` (map + touched modules + blast radius) → `get_vision_docs` (relevant assertions) → `get_regression_risk` → `get_consolidation_opportunities`. Verdict: SHIP, SHIP WITH CHANGES, or BLOCK. Any PR touching code governed by a MUST-bullet should reference the assertion in the review.
49
58
 
50
59
  **Health audit:** `get_unused_code` → `get_test_coverage` → `get_regression_risk` → `get_vision_gaps` → `get_cross_repo_audit`. Grade A–F.
51
60
 
61
+ **Vision maintenance:** When an architectural decision lands in a PR, update `docs/VISION.md` in the same commit — add an assertion if one is new, retire one if it no longer applies. Stale vision docs are worse than none.
62
+
52
63
  ## Using results
53
64
 
54
65
  - Lead with what the data reveals about this codebase — not a raw dump. Highlight surprises.
@@ -45,11 +45,12 @@ Do NOT review from memory or assumptions. Query the actual codebase first.
45
45
  ### If Pharaoh MCP tools are available:
46
46
 
47
47
  1. `get_codebase_map` — current modules, hot files, dependency graph
48
- 2. `search_functions` for keywords related to the plan — find existing code to reuse/extend
49
- 3. `get_module_context` on affected modules — entry points, patterns, conventions
50
- 4. `query_dependencies` between affected modules — coupling, circular deps
51
- 5. `get_blast_radius` on the primary target of the change — know what breaks
52
- 6. `check_reachability` on the primary target — verify it's actually reachable from entry points before worrying about it
48
+ 2. `get_vision_docs` — read the repo's architectural contract. If the plan touches a domain with a MUST-bullet, the assertion is a hard constraint on the plan. Raise it explicitly in Section 1. If `get_vision_docs` returns an empty-state scaffold, flag that the repo needs `/pharaoh:vision` before planning anything architectural.
49
+ 3. `search_functions` for keywords related to the plan — find existing code to reuse/extend
50
+ 4. `get_module_context` on affected modules — entry points, patterns, conventions
51
+ 5. `query_dependencies` between affected modules — coupling, circular deps
52
+ 6. `get_blast_radius` on the primary target of the change — know what breaks
53
+ 7. `check_reachability` on the primary target — verify it's actually reachable from entry points before worrying about it
53
54
 
54
55
  ### Without Pharaoh (graceful fallback):
55
56
 
@@ -77,10 +78,17 @@ Adapt depth to change size. Skip sections that don't apply. **After each section
77
78
 
78
79
  ### Section 1 — Architecture (skip for small/single-file changes)
79
80
 
81
+ - **Vision alignment (check FIRST).** Does this plan touch a domain
82
+ governed by a MUST-bullet in `docs/VISION.md`? If yes, quote the
83
+ assertion and verify the plan doesn't violate it. If the plan would
84
+ violate a MUST, STOP and raise with the user — either the plan changes
85
+ or VISION.md needs an update first (with user approval).
80
86
  - Component boundaries and coupling concerns
81
87
  - Dependency graph: does this change shrink or expand surface area?
82
88
  - Data flow bottlenecks and single points of failure
83
89
  - Does this need new code at all, or can a human process / existing pattern solve it?
90
+ - **If this plan introduces a new invariant**, call it out and include a
91
+ step in Section 6 to add a `### assertion` to VISION.md with a pairing TEST.
84
92
 
85
93
  ### Section 2 — Code Quality (always)
86
94
 
@@ -71,7 +71,8 @@ Then call these additional tools for data recon doesn't cover:
71
71
  - `get_regression_risk` — overall change risk score for the repo
72
72
  - `get_consolidation_opportunities` — duplicate logic the PR may introduce
73
73
  - `check_reachability` — are new exports wired to entry points?
74
- - `get_vision_gaps` — do changes align with or drift from specs?
74
+ - `get_vision_docs` — read the repo's architectural contract. For every touched module, pull its relevant assertions. Any change touching code governed by a MUST-bullet must be checked against that assertion — if the change would violate the MUST, the verdict tips toward BLOCK unless VISION.md is updated in the same PR with user approval.
75
+ - `get_vision_gaps` — do changes align with or drift from specs? New complex functions without a matching assertion are flagged; retired specs with implementing code are flagged.
75
76
 
76
77
  **Output of Phase 1:** Architecture map, module profiles for every touched module, blast radius for high-risk changes, dependency paths between coupled modules, regression risk level, duplication findings, reachability status, and spec alignment.
77
78
 
@@ -255,7 +256,8 @@ If none of these triggers are met, **skip Phase 3** and proceed to Phase 4.
255
256
  - Unreachable exports (new public code with zero callers)
256
257
  - New circular dependencies between modules
257
258
  - HIGH regression risk without corresponding test coverage
258
- - Vision spec violations (building against spec intent)
259
+ - **A MUST-bullet in `docs/VISION.md` is violated by this change** (without VISION.md being updated in the same PR with user approval)
260
+ - Vision spec drift: new complex function has no matching assertion AND the domain it lives in has existing assertions (implies invariants are expected here)
259
261
  - Any CRITICAL finding from Phase 2 or Phase 3 that is confirmed and unfixed
260
262
  - DISAGREE verdict from adversarial review on security-sensitive code, confirmed after verification
261
263
  - Unanchored Cypher query (MATCH without traversing through `Repo {name: $repo}`)
@@ -0,0 +1,185 @@
1
+ ---
2
+ name: vision
3
+ prompt-name: vision-with-pharaoh
4
+ description: Draft a VISION.md for this repo by filling a graph-derived scaffold. Pharaoh generates the structure and domain archetypes from the repo's knowledge graph; you fill in the assertions using ground-truth module context. Output is a committed docs/VISION.md that the format-linter and framework-linter both accept.
5
+ version: 0.1.0
6
+ homepage: https://pharaoh.so
7
+ user-invocable: true
8
+ metadata: {"emoji": "☥", "tags": ["vision", "architecture", "specs", "invariants", "pharaoh"]}
9
+ ---
10
+
11
+ # Vision Drafting
12
+
13
+ Author a VISION.md that captures this repo's invariants — what must always be
14
+ true about its behavior. The file becomes a machine-readable contract that
15
+ Pharaoh's linter, PR Guard, and MCP tools reason against on every change.
16
+
17
+ ## Why this matters (explain this to the user before drafting)
18
+
19
+ A VISION.md is leverage, not paperwork. Once the repo has one:
20
+
21
+ - **PR Guard** checks every pull request against its assertions. Changes that
22
+ contradict a MUST-bullet surface as a Check on the PR — the team sees drift
23
+ from intent at the exact moment it happens, not months later.
24
+ - **`get_vision_gaps`** becomes useful. Pharaoh cross-references every spec
25
+ against the function graph and surfaces both sides of the drift: specs
26
+ without implementing code (dead intent) and complex functions with no spec
27
+ (invisible invariants).
28
+ - **`get_vision_docs`** returns spec-to-code traceability. Each assertion
29
+ shows the functions that implement it — a direct map from intent → code.
30
+ - **CI enforces it.** Every MUST bullet pairs with a TEST reference. The
31
+ linter fails when an assertion has no enforcing test. No more wishlist
32
+ specs that drift over time.
33
+
34
+ Without a VISION.md, the tools above return empty. The graph sees code; it
35
+ doesn't see intent. The file is the bridge.
36
+
37
+ ## When to Use
38
+
39
+ - The repo has no `docs/VISION.md` yet and the user wants Pharaoh's full
40
+ value — PR Guard, vision-gaps, spec traceability all depend on the file.
41
+ - `get_vision_docs` returned the "No VISION.md yet" onboarding response.
42
+ - The user said "draft a vision doc", "add a VISION.md", or "scaffold vision".
43
+ - A user is new to Pharaoh and asking what they should do next.
44
+
45
+ ## The flow — collaborative, not solo
46
+
47
+ This is a short working session with the user. Do not solo-fill the scaffold
48
+ — the graph can tell you the shape of the code, but only the user knows what
49
+ must not break. Ask questions, propose, let them steer.
50
+
51
+ 1. **Get the scaffold.** Call `get_vision_docs` with the repo name. When no
52
+ vision doc exists, the tool returns a deterministic scaffold plus the
53
+ agent directive. Use that as your starting structure. Never invent a
54
+ scaffold from scratch; the archetypes encode Pharaoh's framework shape
55
+ and drift is surfaced by the framework-linter.
56
+
57
+ 2. **Interview the user.** Before filling anything, ask: *"What are the 3-5
58
+ things about this repo that must not break, no matter what?"* Their
59
+ answer drives the assertions. If they can't articulate it, probe with
60
+ follow-ups — "what would a P0 incident look like here?", "what would
61
+ wake you up on a weekend?". The goal is to extract real invariants, not
62
+ to generate plausible-sounding ones from graph evidence.
63
+
64
+ 3. **Ground each domain in real code.** For every `## Domain` the scaffold
65
+ rendered, call `get_module_context` for the module(s) that back that
66
+ domain. For example, an "Authentication and Authorization" domain →
67
+ `get_module_context` on the auth module + any session/token modules.
68
+ Read the exported functions, endpoints, env vars, and DB access.
69
+
70
+ 4. **Replace TODOs with WHAT statements.**
71
+ - Every `### TODO:` heading becomes a real assertion title. Describe the
72
+ invariant in plain language — "Sessions expire after 30 minutes of
73
+ inactivity", not "checkSession() returns null after timeout".
74
+ - Every `- MUST: TODO —` bullet becomes a WHAT statement. Banned
75
+ content: function names, file paths, class names, identifiers.
76
+ - Add a `- TEST: path/to/test.ts` line for every assertion. If the test
77
+ doesn't exist yet, write it before committing. A MUST without a TEST
78
+ is not an invariant, it's a wish.
79
+
80
+ 5. **Trim irrelevant domains.** If a rendered `## Domain` doesn't match
81
+ anything real in this repo, delete that whole section. The scaffold is a
82
+ starting point, not a contract to honor exhaustively.
83
+
84
+ 6. **Write the file.** Save to `docs/VISION.md` in the repo. Remove the
85
+ `<!-- scaffold-generated -->` marker and the `<!-- AGENT DIRECTIVE -->`
86
+ block once every TODO is resolved.
87
+
88
+ 7. **Wire it into CLAUDE.md.** This is non-negotiable — it's what turns the
89
+ vision doc from a file on disk into a contract future sessions respect.
90
+ If `CLAUDE.md` exists at the repo root, append (or edit) a section:
91
+
92
+ ```markdown
93
+ ## Vision docs
94
+
95
+ `docs/VISION.md` is this repo's architectural contract. Before any
96
+ non-trivial change, call `get_vision_docs` to read the relevant
97
+ assertions. After any large refactor, run `get_vision_gaps` to surface
98
+ drift between intent and implementation. When adding a new invariant,
99
+ open `docs/VISION.md`, add a `### assertion` under the right `##` domain,
100
+ and pair every `- MUST:` with a `- TEST:` referencing the enforcing test.
101
+
102
+ Never introduce code that would violate a MUST-bullet without first
103
+ updating `docs/VISION.md` (with the user's approval).
104
+ ```
105
+
106
+ If no `CLAUDE.md` exists, create a minimal one with the section above
107
+ plus any project-specific instructions you already have context for.
108
+
109
+ 8. **Verify.** Run `pharaoh vision lint --framework` (or instruct the user
110
+ to). Zero errors. Zero TODO warnings. Zero unresolved placeholders.
111
+
112
+ ## Hard rules
113
+
114
+ - **No HOW in MUST bullets.** Banned: function names, file paths, camelCase
115
+ identifiers, backtick-wrapped code. The linter enforces this as a warning;
116
+ treat it as a hard rule.
117
+ - **Every MUST needs a TEST.** The format-linter errors if a MUST bullet
118
+ has no matching TEST reference to an existing file.
119
+ - **One MUST per line.** Don't pack multiple invariants into a single bullet.
120
+ - **Max 10 prose lines per assertion.** Keep each `###` section tight.
121
+ - **Mirror Pharaoh's canonical domains when they fit.** Rename only when the
122
+ user's project truly has a different shape. The framework-linter warns on
123
+ unrecognized domains so drift is visible.
124
+
125
+ ## What to avoid
126
+
127
+ - **Do NOT** write VISION.md from scratch without calling `get_vision_docs`
128
+ first — you'll miss domains the graph detected and duplicate ones it
129
+ already included.
130
+ - **Do NOT** carry forward the AGENT DIRECTIVE or scaffold-generated marker
131
+ into the committed file. Those are drafting aids, not document content.
132
+ - **Do NOT** write speculative assertions ("sessions will expire someday").
133
+ Only assert what the code enforces today or what you'll commit a test for.
134
+ - **Do NOT** use `pharaoh vision init` — that only drops the format guide,
135
+ not a graph-grounded scaffold. Always go through `get_vision_docs`.
136
+
137
+ ## Completion checklist
138
+
139
+ - [ ] User was interviewed for their real invariants (not graph-guessed)
140
+ - [ ] Every rendered `## Domain` either has ≥1 real assertion or was deleted
141
+ - [ ] Every `### TODO:` heading replaced with a real title
142
+ - [ ] Every `- MUST: TODO —` replaced with a WHAT statement
143
+ - [ ] Every assertion has a `- TEST:` line pointing at an existing test file
144
+ - [ ] Scaffold marker + AGENT DIRECTIVE block removed
145
+ - [ ] `CLAUDE.md` updated (or created) with the Vision docs section
146
+ - [ ] `pharaoh vision lint --framework` exits clean
147
+
148
+ ## After it ships — tell the user what they unlocked
149
+
150
+ Once `docs/VISION.md` is committed, call out the new capabilities concretely:
151
+
152
+ 1. **Every future AI session reads it.** Because CLAUDE.md now references
153
+ `docs/VISION.md`, any agent working in this repo (Claude Code, Cursor,
154
+ anyone else connecting Pharaoh) will consult the file before touching
155
+ architecture. Continuity across sessions, across people, across tools.
156
+ 2. **`get_vision_docs`** now returns spec-to-code traceability per
157
+ assertion. The user can see which functions implement each invariant.
158
+ 3. **`get_vision_gaps`** surfaces drift. Unspecified complex functions
159
+ get flagged; specs with no implementing code get flagged for review
160
+ (either write the code or retire the spec).
161
+ 4. **Their next PR is checked.** PR Guard now evaluates touched code
162
+ against relevant assertions. First-time use often catches real drift.
163
+ 5. **`/pharaoh:plan`** will surface relevant assertions during reconnaissance.
164
+ 6. **`/pharaoh:review`** will flag PRs that touch code governed by a MUST.
165
+
166
+ The bigger payoff: architectural invariants are now enforced in CI the same
167
+ way unit tests enforce behavior. Intent and implementation stop drifting.
168
+
169
+ ## Ongoing maintenance — it's a living file
170
+
171
+ VISION.md rots if it's not maintained. Part of your job in future sessions
172
+ (even ones that aren't about vision directly) is to keep it current:
173
+
174
+ - **When a MUST changes**, update VISION.md in the same PR as the code
175
+ change. Don't let the file lag — stale assertions are worse than none.
176
+ - **When a new architectural decision lands**, add a new `###` assertion
177
+ under the right `##` domain with a pairing TEST. One assertion per
178
+ decision, not batches.
179
+ - **When an assertion stops being load-bearing**, delete it. Retirement is
180
+ as important as addition.
181
+ - **When `get_vision_gaps` shows >5 unimplemented specs**, the doc has
182
+ drifted into wishlist territory. Prune.
183
+ - **Quarterly**: run `pharaoh vision lint --framework` and address warnings.
184
+
185
+ Format reference: https://pharaoh.so/vision-format.md