@chrisdudek/yg 2.7.0 → 2.9.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.
- package/dist/bin.js +632 -397
- package/dist/bin.js.map +1 -1
- package/dist/templates/rules.ts +383 -244
- package/package.json +1 -1
package/dist/templates/rules.ts
CHANGED
|
@@ -3,160 +3,166 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Operating manual for agents working in a Yggdrasil-managed repository.
|
|
5
5
|
* Split into three cognitive sections optimized for LLM attention patterns:
|
|
6
|
-
* 1.
|
|
7
|
-
* 2.
|
|
8
|
-
* 3.
|
|
6
|
+
* 1. PROTOCOL — the rule and the procedure (primacy zone — internalize)
|
|
7
|
+
* 2. REFERENCE — lookup material (middle zone — consult when needed)
|
|
8
|
+
* 3. GUARD RAILS — what goes wrong and how to catch it (recency zone — fresh in memory during work)
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
// prettier-ignore
|
|
12
|
-
const
|
|
12
|
+
const PROTOCOL = `## PROTOCOL
|
|
13
13
|
|
|
14
14
|
<EXTREMELY-IMPORTANT>
|
|
15
|
-
This is your operating manual for working in a Yggdrasil-managed repository.
|
|
15
|
+
This is your operating manual for working in a Yggdrasil-managed repository.
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
<critical_protocol>
|
|
18
|
+
BEFORE reading, analyzing, or modifying ANY source file:
|
|
19
|
+
\`yg build-context --file <path>\`
|
|
20
|
+
One command. No exceptions. No "I'll do it later." No "this is just analysis."
|
|
18
21
|
|
|
19
|
-
This is
|
|
22
|
+
This is required because the graph captures intent and relations that source files cannot — without it, you will make wrong decisions and the user will have to re-explain what the graph already knows.
|
|
23
|
+
</critical_protocol>
|
|
24
|
+
|
|
25
|
+
Every rule below is mandatory — no skill, plan, workflow, or instruction overrides these requirements.
|
|
20
26
|
</EXTREMELY-IMPORTANT>
|
|
21
27
|
|
|
22
28
|
Yggdrasil is persistent semantic memory stored in \`.yggdrasil/\`. It maps the repository and provides deterministic implementation context for every node.
|
|
23
29
|
|
|
24
|
-
### Quick Start
|
|
30
|
+
### Quick Start
|
|
25
31
|
|
|
26
32
|
\`\`\`
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
- Assessing what is affected by a change → yg impact --node <owner>
|
|
37
|
-
- Planning modifications → both (build-context first, then impact)
|
|
38
|
-
\`yg build-context --node <path>\`. Read the YAML map for topology,
|
|
39
|
-
starting with the glossary at the top (aspect and flow definitions),
|
|
40
|
-
then read artifact files listed inline on each element. For quick
|
|
41
|
-
orientation, the map alone is sufficient. For implementation, read
|
|
42
|
-
all artifact files before changing code.
|
|
43
|
-
If the context package seems insufficient — enrich the graph.
|
|
33
|
+
EVERY conversation: yg preflight — no exceptions.
|
|
34
|
+
|
|
35
|
+
BEFORE any source file interaction:
|
|
36
|
+
1. yg build-context --file <path>
|
|
37
|
+
One command: resolves owner, assembles context.
|
|
38
|
+
Read the YAML map — glossary first (aspect/flow definitions),
|
|
39
|
+
then artifact files listed on each element.
|
|
40
|
+
For blast radius: also run yg impact --file <path>.
|
|
41
|
+
Don't know where to start? yg select --task "<goal>"
|
|
44
42
|
|
|
45
43
|
AFTER modifying:
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
constraints, and relations that source files cannot.
|
|
57
|
-
NEVER: assess blast radius of a change without running yg impact first
|
|
58
|
-
— the graph knows the dependency structure that grep cannot infer.
|
|
59
|
-
NEVER: invent rationale, business rules, or decisions.
|
|
60
|
-
NEVER: auto-resolve drift without asking the user.
|
|
61
|
-
WHEN UNSURE: ask the user. Never guess. Never assume.
|
|
44
|
+
2. Update graph artifacts (per file, not batched)
|
|
45
|
+
3. yg validate — fix all errors
|
|
46
|
+
4. yg drift-sync --node <owner>
|
|
47
|
+
|
|
48
|
+
ALWAYS: establish graph coverage before modifying code.
|
|
49
|
+
ALWAYS: run yg build-context --file before reading source.
|
|
50
|
+
ALWAYS: run yg impact before assessing blast radius.
|
|
51
|
+
ALWAYS: ask the user for rationale — record it, do not invent it.
|
|
52
|
+
ALWAYS: ask before resolving drift or ambiguity.
|
|
53
|
+
WHEN UNSURE: ask the user. Do not guess. Do not assume.
|
|
62
54
|
\`\`\`
|
|
63
55
|
|
|
64
|
-
###
|
|
56
|
+
### Modify Source Code
|
|
65
57
|
|
|
66
|
-
|
|
67
|
-
2. **The graph is the specification; code implements it.** The graph absorbs knowledge from every source — external docs, conversations, decisions — and must be self-sufficient. If all other sources disappeared, the graph alone must contain enough to understand the system. Do not leave knowledge in external documents and reference them — capture the knowledge in graph artifacts. Update graph artifacts immediately after each file change, while context is fresh — do not batch graph updates to the end of a task. Code and graph move together: code changed → graph updated before moving to the next file. Graph changed → source verified in the same response. When planning work — in any tool, skill, or workflow — graph updates are part of each step's definition of done, never a separate phase.
|
|
68
|
-
3. **Never invent why.** The graph captures human intent. If you don't know why something was decided, ask. Never hallucinate rationale.
|
|
69
|
-
4. **Always capture why — especially why NOT.** When the user explains a reason, record it in the graph immediately. When a design choice is made, also record rejected alternatives: "Chose X over Y because Z." Rejected alternatives are the highest-value information — invisible in code and irrecoverable once forgotten. Conversation evaporates; graph persists.
|
|
70
|
-
5. **Ask before resolving ambiguity.** When multiple valid interpretations exist, stop, list options, ask the user. Never silently choose.
|
|
58
|
+
You are not allowed to edit or create source code without establishing graph coverage first.
|
|
71
59
|
|
|
72
|
-
|
|
60
|
+
**Step 1** — Get context: \`yg build-context --file <path>\` (resolves owner automatically)
|
|
73
61
|
|
|
74
|
-
|
|
62
|
+
**Step 2a** — Owner found: execute checklist:
|
|
75
63
|
|
|
76
|
-
|
|
64
|
+
- [ ] 1. Read the context package (already assembled by step 1)
|
|
65
|
+
- [ ] 2. Assess blast radius: \`yg impact --node <node_path>\` — review dependents, descendants, and co-aspect nodes before changing interfaces or shared behavior
|
|
66
|
+
- [ ] 3. Modify source code
|
|
67
|
+
- [ ] 4. Sync graph artifacts — edit artifact files to reflect the changes (after each file, not batched — context is freshest immediately after the change). If the node's purpose changed, update \`description\` in \`yg-node.yaml\`.
|
|
68
|
+
- [ ] 5. Run \`yg validate\` — fix all errors (if unfixable after 3 attempts → stop, report to user)
|
|
69
|
+
- [ ] 6. Run \`yg drift-sync --node <node_path>\` — only after graph and code are both current
|
|
77
70
|
|
|
78
|
-
|
|
79
|
-
- Proposing approaches, designs, or plans for changing code
|
|
80
|
-
- Reviewing or debugging code
|
|
81
|
-
- Any form of reasoning about how mapped code works or should change
|
|
71
|
+
**Step 2b** — Owner not found: establish coverage first. Present options to the user:
|
|
82
72
|
|
|
83
|
-
|
|
73
|
+
*Partially mapped* (file unmapped but inside a mapped module): ask whether to add to existing node or create new one.
|
|
84
74
|
|
|
85
|
-
|
|
86
|
-
- Finding all dependents of a component
|
|
87
|
-
- Planning cross-cutting refactors or feature removals
|
|
88
|
-
- Scoping work that spans multiple nodes
|
|
75
|
+
*Existing code:*
|
|
89
76
|
|
|
90
|
-
|
|
77
|
+
- Option A — Full node: create node(s), map files, write artifacts from code analysis
|
|
78
|
+
- Option B — Blackbox: create a blackbox node at agreed granularity
|
|
79
|
+
- Option C — Abort
|
|
91
80
|
|
|
92
|
-
|
|
93
|
-
- Reading documentation, READMEs, or config files outside \`.yggdrasil/\`
|
|
94
|
-
- Running tests, builds, or linters
|
|
95
|
-
- Working with files that \`yg owner\` reports as unmapped
|
|
81
|
+
*Greenfield (new code):* Only Option A. Blackbox is forbidden for new code. Follow the graph-first workflow:
|
|
96
82
|
|
|
97
|
-
|
|
83
|
+
1. Create aspects first (cross-cutting requirements the new code must satisfy)
|
|
84
|
+
2. Create flows if the code participates in a business process
|
|
85
|
+
3. Create nodes with full artifacts — description in \`yg-node.yaml\`, responsibility, interface, internals
|
|
86
|
+
4. Review the context package (\`yg build-context\`) — it is now the behavioral specification
|
|
87
|
+
5. Implement code that satisfies the specification
|
|
88
|
+
6. The graph specifies WHAT and WHY; the code implements HOW (framework APIs, library choices)
|
|
98
89
|
|
|
99
|
-
|
|
100
|
-
|---|---|
|
|
101
|
-
| "The skill/plan says to explore the codebase" | Exploring mapped code = yg owner + graph tool first |
|
|
102
|
-
| "I'm just scoping/searching, not understanding" | Scoping IS a graph action; use yg impact |
|
|
103
|
-
| "The plan step says to read this file" | Reading a mapped file = yg owner first |
|
|
104
|
-
| "I'm brainstorming, not implementing" | Brainstorming about mapped code needs graph context |
|
|
105
|
-
| "I'm only grepping for references" | Grep finds text; yg impact finds structural dependencies. Use both. |
|
|
106
|
-
| "I'll use the graph later when I modify" | Graph-first means BEFORE reading, not before modifying |
|
|
107
|
-
| "I'll grep the codebase to find where to start" | Run \`yg select --task\` first — it matches your intent against graph artifacts. Then \`yg owner\` on results. |
|
|
108
|
-
| "Drift is blocking repo-check, let me just sync it" | Drift means artifacts are stale. Update artifacts first, then sync. \`drift-sync\` without artifact update = hiding staleness. |
|
|
90
|
+
**Node sizing rule:** One node per cohesive feature area, NOT per directory. If a node would map >10 source files or cover >3 distinct user workflows, split it into child nodes. Example: an admin panel should be \`admin/blog\`, \`admin/gallery\`, \`admin/clients\`, \`admin/orders\` — not one \`admin-pages\` node. The CLI enforces this with W017, but plan granularity upfront rather than splitting after the fact.
|
|
109
91
|
|
|
110
|
-
|
|
92
|
+
After the user chooses, return to Step 1 and follow Step 2a.
|
|
111
93
|
|
|
112
|
-
|
|
94
|
+
### Working from External Specifications
|
|
113
95
|
|
|
114
|
-
|
|
115
|
-
- ❌ Modified source code without updating graph artifacts before moving to the next file, or vice versa.
|
|
116
|
-
- ❌ Resolved a code-graph inconsistency or ambiguity without asking the user first.
|
|
117
|
-
- ❌ Created or edited a graph element without reading its schema in \`schemas/\` first.
|
|
118
|
-
- ❌ Ran \`yg drift-sync\` before both graph artifacts and source code are current.
|
|
119
|
-
- ❌ Placed a cross-cutting requirement in a local artifact instead of an aspect, or used an aspect id with no \`aspects/\` directory.
|
|
120
|
-
- ❌ Invented a rationale, business rule, or decision — or recorded a decision without documenting rejected alternatives and rationale (use "rationale: unknown" if unknown).
|
|
121
|
-
- ❌ Used blackbox coverage for greenfield (new) code.
|
|
122
|
-
- ❌ Deleted or shortened graph artifact content to reduce context package size instead of splitting the node.
|
|
96
|
+
When the user provides external documents (specs, PRDs, design docs, reference docs) as input for implementation:
|
|
123
97
|
|
|
124
|
-
|
|
98
|
+
1. **Read ALL spec documents BEFORE writing any code.** Understand the full scope — business context, feature specs, quality requirements, UX rules, deployment config.
|
|
99
|
+
2. **Extract and route knowledge to the graph FIRST**, using the Information Routing table:
|
|
100
|
+
- Business rules, personas, pricing strategy, acquisition channels → aspects or root node artifacts
|
|
101
|
+
- Feature specifications (UI behavior, validation, workflows) → node responsibility/interface/internals artifacts
|
|
102
|
+
- Cross-cutting UX/quality requirements → aspects
|
|
103
|
+
- Business processes → flows
|
|
104
|
+
3. **The graph is the specification; external docs are INPUT to the graph, not a parallel source of truth.** After the graph is populated, external docs become redundant — the graph is what future agents will read.
|
|
105
|
+
4. **Spec knowledge is not code knowledge.** Specs contain business context (WHY the system exists, WHO it serves, WHAT it should do) that will never appear in source code. If you only document what you built, you lose what motivated building it.
|
|
106
|
+
5. **Completeness test:** "If the external docs disappeared today, does the graph contain everything a future agent needs to understand the system — not just HOW it works, but WHY it exists and WHAT business value it delivers?"
|
|
125
107
|
|
|
126
|
-
|
|
108
|
+
**Common failure mode:** Agent reads spec → implements code → documents code in graph → spec knowledge (personas, pricing, UX rationale, quality targets) is lost because it was treated as "input I consumed" rather than "knowledge I must persist." The graph must absorb the spec, not just the code.
|
|
127
109
|
|
|
128
|
-
|
|
129
|
-
- Do NOT run \`yg drift-sync\` — leave the drift visible.
|
|
110
|
+
### Example: Correct vs Wrong
|
|
130
111
|
|
|
131
|
-
|
|
112
|
+
<example_correct>
|
|
132
113
|
|
|
133
|
-
|
|
114
|
+
User: "Fix the bug in payment.service.ts"
|
|
134
115
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
116
|
+
1. yg build-context --file src/payment.service.ts → payment/payment-service
|
|
117
|
+
2. Read YAML map — glossary, then artifact files
|
|
118
|
+
3. Read source file, understand bug in graph context
|
|
119
|
+
4. Fix bug
|
|
120
|
+
5. Update payment-service artifacts (responsibility.md, interface.md if API changed)
|
|
121
|
+
6. yg validate
|
|
122
|
+
7. yg drift-sync --node payment/payment-service
|
|
138
123
|
|
|
139
|
-
|
|
124
|
+
</example_correct>
|
|
140
125
|
|
|
141
|
-
|
|
126
|
+
<example_wrong>
|
|
142
127
|
|
|
143
|
-
|
|
144
|
-
2. Follow the Quick Start Protocol from that file before touching any mapped code
|
|
128
|
+
User: "Fix the bug in payment.service.ts"
|
|
145
129
|
|
|
146
|
-
|
|
130
|
+
1. Read src/payment.service.ts ← WRONG: no graph context loaded
|
|
131
|
+
2. Fix bug
|
|
132
|
+
3. "I'll update the graph later" ← WRONG: deferred = forgotten
|
|
147
133
|
|
|
148
|
-
|
|
149
|
-
BEFORE doing anything else: read .yggdrasil/agent-rules.md and follow its protocol.
|
|
150
|
-
DELIVERABLES — all required, incomplete work will be rejected:
|
|
151
|
-
1. Working source code
|
|
152
|
-
2. Graph nodes with artifacts for every new/modified source file
|
|
153
|
-
3. \`yg validate\` passing
|
|
154
|
-
\`\`\`
|
|
134
|
+
Result: graph is stale, next agent asks user the same questions
|
|
155
135
|
|
|
156
|
-
|
|
136
|
+
</example_wrong>
|
|
157
137
|
|
|
158
|
-
|
|
159
|
-
|
|
138
|
+
<example_correct>
|
|
139
|
+
|
|
140
|
+
User: "Here are the spec docs. Implement the admin blog editor."
|
|
141
|
+
|
|
142
|
+
1. Read ALL spec docs (blog-editor.md, autosave.md, user-persona.md, version-history.md)
|
|
143
|
+
2. Extract cross-cutting patterns → create aspects (admin-ux-rules, autosave, version-history) if they don't exist
|
|
144
|
+
3. Create flow if the blog participates in a business process
|
|
145
|
+
4. Create node admin/blog with artifacts populated from spec (responsibility, interface, internals)
|
|
146
|
+
5. Run yg build-context → the context package is now the behavioral specification
|
|
147
|
+
6. Implement code that satisfies the specification
|
|
148
|
+
7. Update artifacts with any implementation details that emerged during coding
|
|
149
|
+
8. yg validate, yg drift-sync
|
|
150
|
+
|
|
151
|
+
</example_correct>
|
|
152
|
+
|
|
153
|
+
<example_wrong>
|
|
154
|
+
|
|
155
|
+
User: "Here are the spec docs. Implement the admin blog editor."
|
|
156
|
+
|
|
157
|
+
1. Read blog-editor.md spec
|
|
158
|
+
2. Implement all the code ← WRONG: spec knowledge not captured in graph
|
|
159
|
+
3. Create node admin-pages, map 20 admin files ← WRONG: too wide, W017
|
|
160
|
+
4. Write responsibility.md summarizing what the code does ← WRONG: describes code, not spec intent
|
|
161
|
+
5. Business context (persona, UX rules, autosave rationale) lost ← WRONG: spec was input, not persisted
|
|
162
|
+
|
|
163
|
+
Result: graph mirrors code but misses WHY. Next agent reads graph, understands HOW but not WHO it's for or WHAT UX rules govern it.
|
|
164
|
+
|
|
165
|
+
</example_wrong>
|
|
160
166
|
|
|
161
167
|
### Conversation Lifecycle
|
|
162
168
|
|
|
@@ -165,66 +171,26 @@ PREFLIGHT (every conversation, before any work):
|
|
|
165
171
|
- [ ] 1. yg preflight → read unified report
|
|
166
172
|
- [ ] 2. If drift: resolve per Drift Resolution, then yg drift-sync per node
|
|
167
173
|
- [ ] 3. If validation errors: fix, re-run yg validate
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
UNDERSTANDING
|
|
171
|
-
- [ ] 1. yg
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
flow definitions, then read artifact files listed inline on each
|
|
175
|
-
element. For quick orientation, the map alone is sufficient. For
|
|
176
|
-
implementation, read all artifact files before changing code.
|
|
177
|
-
- [ ] 3. Owner not found → use file analysis, state it is not graph-backed.
|
|
174
|
+
No exceptions. You cannot know if a file is mapped without running yg.
|
|
175
|
+
|
|
176
|
+
UNDERSTANDING any source file (questions, research, OR planning):
|
|
177
|
+
- [ ] 1. yg build-context --file <path>
|
|
178
|
+
Mapped → read the YAML map (glossary first, then artifact files).
|
|
179
|
+
Unmapped → use file analysis, state it is not graph-backed.
|
|
178
180
|
Never use grep or raw file reads as primary understanding when graph coverage exists.
|
|
179
181
|
Raw reads supplement the context package — they do not replace it.
|
|
180
182
|
|
|
183
|
+
BEFORE reasoning about source code, state which graph context you loaded:
|
|
184
|
+
"graph: <node_path>" if mapped, "graph: unmapped" if not.
|
|
185
|
+
This is a required output step, not optional reflection.
|
|
186
|
+
|
|
181
187
|
WRAP-UP (user signals "done", "wrap up", "that's enough"):
|
|
182
188
|
- [ ] 1. yg drift --drifted-only → resolve
|
|
183
189
|
- [ ] 2. yg validate → fix errors
|
|
184
190
|
- [ ] 3. Report: which nodes and files were changed
|
|
185
191
|
|
|
186
|
-
BEFORE ENDING ANY RESPONSE (self-audit):
|
|
187
|
-
- [ ] Did I interact with mapped code (read, research, or modify)? If yes → did I use a graph tool BEFORE reading source?
|
|
188
|
-
- [ ] Did I modify source code? If yes → did I update graph artifacts before moving to the next file?
|
|
189
|
-
- [ ] If you broke either rule, you have broken the protocol. Do not finish until both are fixed.
|
|
190
192
|
\`\`\`
|
|
191
193
|
|
|
192
|
-
### Modify Source Code
|
|
193
|
-
|
|
194
|
-
You are not allowed to edit or create source code without establishing graph coverage first.
|
|
195
|
-
|
|
196
|
-
**Step 1** — Check coverage: \`yg owner --file <path>\`
|
|
197
|
-
|
|
198
|
-
**Step 2a** — Owner found: execute checklist:
|
|
199
|
-
|
|
200
|
-
- [ ] 1. Read specification: \`yg build-context --node <node_path>\`
|
|
201
|
-
- [ ] 2. Assess blast radius: \`yg impact --node <node_path>\` — review dependents, descendants, and co-aspect nodes before changing interfaces or shared behavior
|
|
202
|
-
- [ ] 3. Modify source code
|
|
203
|
-
- [ ] 4. Sync graph artifacts — edit artifact files to reflect the changes (after each file, not batched — context is freshest immediately after the change). If the node's purpose changed, update \`description\` in \`yg-node.yaml\`.
|
|
204
|
-
- [ ] 5. Run \`yg validate\` — fix all errors (if unfixable after 3 attempts → stop, report to user)
|
|
205
|
-
- [ ] 6. Run \`yg drift-sync --node <node_path>\` — only after graph and code are both current
|
|
206
|
-
|
|
207
|
-
**Step 2b** — Owner not found: establish coverage first. Present options to the user:
|
|
208
|
-
|
|
209
|
-
*Partially mapped* (file unmapped but inside a mapped module): ask whether to add to existing node or create new one.
|
|
210
|
-
|
|
211
|
-
*Existing code:*
|
|
212
|
-
|
|
213
|
-
- Option A — Full node: create node(s), map files, write artifacts from code analysis
|
|
214
|
-
- Option B — Blackbox: create a blackbox node at agreed granularity
|
|
215
|
-
- Option C — Abort
|
|
216
|
-
|
|
217
|
-
*Greenfield (new code):* Only Option A. Blackbox is forbidden for new code. Follow the graph-first workflow:
|
|
218
|
-
|
|
219
|
-
1. Create aspects first (cross-cutting requirements the new code must satisfy)
|
|
220
|
-
2. Create flows if the code participates in a business process
|
|
221
|
-
3. Create nodes with full artifacts — description in \`yg-node.yaml\`, responsibility, interface, internals
|
|
222
|
-
4. Review the context package (\`yg build-context\`) — it is now the behavioral specification
|
|
223
|
-
5. Implement code that satisfies the specification
|
|
224
|
-
6. The graph specifies WHAT and WHY; the code implements HOW (framework APIs, library choices)
|
|
225
|
-
|
|
226
|
-
After the user chooses, return to Step 1 and follow Step 2a.
|
|
227
|
-
|
|
228
194
|
### Modify Graph
|
|
229
195
|
|
|
230
196
|
- [ ] 1. Read the relevant schema from \`schemas/\` before touching any YAML
|
|
@@ -234,90 +200,27 @@ After the user chooses, return to Step 1 and follow Step 2a.
|
|
|
234
200
|
- [ ] 5. Verify affected source files are consistent — update if needed
|
|
235
201
|
- [ ] 6. Run \`yg drift-sync\` for affected nodes
|
|
236
202
|
|
|
237
|
-
###
|
|
238
|
-
|
|
239
|
-
**Order:** aspects (cross-cutting patterns) → flows (business processes) → model nodes. Never create nodes before aspects and flows are understood.
|
|
240
|
-
|
|
241
|
-
Per area checklist:
|
|
242
|
-
|
|
243
|
-
- [ ] 1. \`yg owner --file <path>\` — confirm no coverage
|
|
244
|
-
- [ ] 2. Determine node granularity — propose to user if unclear
|
|
245
|
-
- [ ] 3. Create node directory, read \`schemas/yg-node.yaml\`, create \`yg-node.yaml\`
|
|
246
|
-
- [ ] 3b. Write \`description\` in \`yg-node.yaml\` — a short summary of what the node does
|
|
247
|
-
- [ ] 4. Analyze source — for each artifact type in \`yg-config.yaml artifacts\`: extract content, do not invent
|
|
248
|
-
- [ ] 5. Identify relations — add to \`yg-node.yaml\`
|
|
249
|
-
- [ ] 6. Identify cross-cutting requirements — add matching aspects, create if needed
|
|
250
|
-
- [ ] 6b. For each aspect on the node: identify 2-5 code anchors (function names, constants) that evidence the pattern → add as \`anchors\` in the aspect entry in \`yg-node.yaml\`
|
|
251
|
-
- [ ] 7. Identify business process participation — add to flow, ask user if process unclear
|
|
252
|
-
- [ ] 8. \`yg validate\` — fix errors
|
|
253
|
-
- [ ] 9. \`yg drift-sync --node <path>\`
|
|
254
|
-
|
|
255
|
-
**When to ask:**
|
|
256
|
-
|
|
257
|
-
- Business process unclear: "This code appears to be part of a larger process. Can you describe what it means from a business perspective?"
|
|
258
|
-
- Constraint without rationale: "I see [constraint X]. Do you know why this exists? I want to record the reason, not just the rule."
|
|
259
|
-
- Unexplained architectural choice: "I see [approach X]. What was the reason for this choice?"
|
|
260
|
-
- Decision without alternatives: "You chose [X]. What alternatives did you consider, and why did you reject them?" Record the answer in the Decisions section of \`internals.md\`.
|
|
261
|
-
- Decision without known rationale: Record the decision in \`internals.md\` with "rationale: unknown — inferred from code, not confirmed by developer." A recorded decision with unknown rationale is infinitely more valuable than no record at all, and safer than an invented rationale.
|
|
262
|
-
|
|
263
|
-
### Bootstrap Mode
|
|
264
|
-
|
|
265
|
-
Trigger: \`yg preflight\` shows 0 nodes, or no nodes cover the active work area.
|
|
266
|
-
|
|
267
|
-
- [ ] 1. Identify the active work area (files the user wants to modify)
|
|
268
|
-
- [ ] 2. Scan for cross-cutting patterns → create aspects
|
|
269
|
-
- [ ] 3. Ask user about business processes → create flows if applicable
|
|
270
|
-
- [ ] 4. Propose node structure for the area
|
|
271
|
-
- [ ] 5. Create node(s) with initial artifacts, map files
|
|
272
|
-
- [ ] 6. \`yg validate\`, \`yg drift-sync\`
|
|
273
|
-
- [ ] 7. Proceed with user's original request
|
|
274
|
-
|
|
275
|
-
Constraint: Do NOT map the entire repository. Focus on the active area. Expand incrementally.
|
|
276
|
-
|
|
277
|
-
### Drift Resolution
|
|
278
|
-
|
|
279
|
-
Always ask the user before resolving drift. Never auto-resolve.
|
|
280
|
-
|
|
281
|
-
- **Source drift** (source files changed) → update graph artifacts to match source, then \`yg drift-sync\`
|
|
282
|
-
- **Graph drift** (graph artifacts changed) → review affected source, update if needed, then \`yg drift-sync\`
|
|
283
|
-
- **Full drift** (both changed) → present both sides to user, ask which direction wins
|
|
284
|
-
- **Missing** → ask: re-materialize or remove mapping?
|
|
285
|
-
- **Unmaterialized** → ask user how to proceed
|
|
286
|
-
|
|
287
|
-
Threshold: >10 drifted nodes → ask user which area to prioritize. Do not resolve all at once.
|
|
288
|
-
|
|
289
|
-
**Drift triage:** Prioritize aspects and \`internals.md\` (highest decay rate), then \`responsibility.md\` and \`interface.md\` (most stable).
|
|
290
|
-
|
|
291
|
-
### Graph Audit
|
|
292
|
-
|
|
293
|
-
When reviewing graph quality (triggered by user or quality improvement):
|
|
294
|
-
|
|
295
|
-
**Step 1 — Consistency** (catches WRONG information):
|
|
203
|
+
### Delegating to Subagents
|
|
296
204
|
|
|
297
|
-
|
|
298
|
-
- [ ] 2. Read mapped source files
|
|
299
|
-
- [ ] 3. For each claim in graph: verify against source code
|
|
300
|
-
- [ ] 4. For each aspect: verify the pattern holds in THIS node. If it deviates, add \`exceptions\` to the aspect entry in \`yg-node.yaml\`
|
|
301
|
-
- [ ] 5. Report inconsistencies
|
|
205
|
+
When you delegate work to a subagent (any subprocess, tool agent, or spawned assistant), the subagent does NOT inherit your Yggdrasil knowledge. Before any other instruction, the subagent MUST:
|
|
302
206
|
|
|
303
|
-
|
|
207
|
+
1. Read \`.yggdrasil/agent-rules.md\` — this is the complete operating manual
|
|
208
|
+
2. Follow the Quick Start Protocol from that file before touching any mapped code
|
|
304
209
|
|
|
305
|
-
|
|
306
|
-
- [ ] 2. For each error path: is it in \`interface.md\` (Failure Modes section)?
|
|
307
|
-
- [ ] 3. For each behavioral invariant: is it in the graph?
|
|
308
|
-
- [ ] 4. Report omissions separately from inconsistencies
|
|
210
|
+
Include this as the FIRST instruction in every subagent prompt:
|
|
309
211
|
|
|
310
|
-
|
|
212
|
+
\`\`\`
|
|
213
|
+
BEFORE doing anything else: read .yggdrasil/agent-rules.md and follow its protocol.
|
|
214
|
+
DELIVERABLES — all required, incomplete work will be rejected:
|
|
215
|
+
1. Working source code
|
|
216
|
+
2. Graph nodes with artifacts for every new/modified source file
|
|
217
|
+
3. \`yg validate\` passing
|
|
218
|
+
\`\`\`
|
|
311
219
|
|
|
312
|
-
|
|
313
|
-
- **Unfixable validate errors** → if not resolved after 3 attempts, stop and report to user. Do not loop.
|
|
314
|
-
- **Budget warning (W005/W006)** → informational. \`yg validate\` shows a breakdown (own/hierarchy/aspects/flows/dependencies). Large inherited context means the system is complex — this is not a problem to fix, it is reality to acknowledge. Do not delete knowledge from artifacts. Do not attempt to "reduce" inherited context.
|
|
315
|
-
- **Own budget warning (W015)** → own artifacts are large. Consider splitting this node's responsibilities into child nodes. Redistribute knowledge across children so total knowledge is preserved or increased, never reduced.
|
|
316
|
-
- **Corrupted \`.yggdrasil/\` files** → report to user. Do not attempt repair.
|
|
317
|
-
- **Incremental sync** → run \`yg drift-sync\` every 3-5 source files during multi-file tasks. Do not defer to end. But NEVER run \`yg drift-sync\` to silence a failing drift check — drift is a signal that artifacts need updating. First update artifacts, then sync.`;
|
|
220
|
+
A subagent that delivers code without corresponding graph updates has not completed its task. Before accepting subagent output, verify: are there new or modified source files without corresponding graph coverage? If yes, the work is incomplete.`;
|
|
318
221
|
|
|
319
222
|
// prettier-ignore
|
|
320
|
-
const
|
|
223
|
+
const REFERENCE = `## REFERENCE
|
|
321
224
|
|
|
322
225
|
### Graph Structure
|
|
323
226
|
|
|
@@ -382,6 +285,10 @@ When you encounter information, route it to the correct location:
|
|
|
382
285
|
- **Shared across a domain** → parent node artifact. Children receive it through hierarchy.
|
|
383
286
|
- **Technology stack or standard** → node artifact at the appropriate hierarchy level (e.g., root node's \`responsibility.md\` for single-stack repos, or deployment unit node for monorepos)
|
|
384
287
|
- **Decision (why + why NOT):** one node → Decisions section of \`internals.md\` with format "Chose X over Y because Z"; category of nodes → aspect content files; tech choice → node artifact at the level where the technology applies. Always include rejected alternatives — they are the highest-value graph content. If the rationale is unknown: record the decision with "rationale: unknown" and note what CAN be observed from the code. Never invent a plausible-sounding rationale.
|
|
288
|
+
- **Business strategy** (personas, pricing, acquisition channels, brand positioning) → root node artifact or dedicated business-context aspect. This knowledge has NO source file — it exists only in specs and conversations.
|
|
289
|
+
- **Quality targets** (performance budgets, accessibility level, Lighthouse scores, test coverage goals) → aspect per quality dimension (e.g., \`performance-targets\`, \`accessibility\`). These are measurable cross-cutting constraints.
|
|
290
|
+
- **UX patterns** (autosave, version history, empty states, confirmation modals) → aspect when the pattern applies to 3+ screens. UX patterns are cross-cutting even if they aren't architectural.
|
|
291
|
+
- **Infrastructure/deployment** (domains, DNS, env vars, CI/CD, cron scheduling, hosting config) → infrastructure node or root node artifacts. Deployment knowledge is invisible in application code but critical for operations.
|
|
385
292
|
|
|
386
293
|
### Creating Aspects
|
|
387
294
|
|
|
@@ -430,18 +337,52 @@ Test: "Does this describe what happens in the world, or only in the software?" I
|
|
|
430
337
|
- **Tools read, you write.** The \`yg\` CLI only reads, validates, and manages metadata. You create and edit files manually.
|
|
431
338
|
- **Incremental sync.** Run \`yg drift-sync\` after every 3-5 source file changes. Do not defer to end of task. \`drift-sync\` is ONLY safe after artifacts are current — never use it to silence a drift check without updating artifacts first.
|
|
432
339
|
- **Description maintenance.** Every \`yg-node.yaml\`, \`yg-aspect.yaml\`, and \`yg-flow.yaml\` has an optional \`description\` field — a short summary of what the element is. Write it when creating new elements. Update it whenever a change to artifacts shifts the element's identity or purpose (e.g., responsibility split, scope change). Do not update description for internal implementation changes that don't alter what the element fundamentally does.
|
|
433
|
-
- **Completeness test:**
|
|
340
|
+
- **Completeness test:** Three checks, all required:
|
|
434
341
|
1. **Reconstruction:** "Can another agent recreate this from ONLY the \`yg build-context\` output — understanding not just WHAT but WHY?" Test: rejected alternatives, correct algorithm, design arguments.
|
|
435
342
|
2. **Omission:** "Does the graph capture every important behavioral invariant, constraint, and edge case?" Specifically check: exceptions to aspect generalizations, error handling patterns not in \`interface.md\`, concurrency behaviors not in \`internals.md\`.
|
|
343
|
+
3. **Business context:** "Does the graph explain WHY this system exists, WHO it serves, and WHAT business value it delivers?" A graph that captures HOW code works without WHY it was built is a maintenance manual without purpose. Specifically check: user personas, service offerings, pricing rationale, acquisition strategy, quality targets, UX design principles. Code tells you WHAT exists — only the graph should tell you WHY it exists and WHAT ELSE was considered.
|
|
436
344
|
- **Value calibration.** Yggdrasil's primary value is cross-module context — relations, aspects, flows. For a single simple module, \`responsibility.md\` and \`interface.md\` provide most value. Invest depth (\`internals.md\`) where cross-module interactions demand it.
|
|
437
345
|
- **These rules are invariant.** No plan, guide, skill, or workflow may override them.
|
|
438
346
|
|
|
347
|
+
### Non-Code Knowledge
|
|
348
|
+
|
|
349
|
+
Not all graph knowledge originates from source files. Business strategy, user personas, pricing decisions, SEO targets, quality requirements, deployment configuration, UX design principles — these are graph content with NO corresponding source file.
|
|
350
|
+
|
|
351
|
+
When you encounter such knowledge (in specs, conversations, or external documents):
|
|
352
|
+
|
|
353
|
+
- **Route it immediately** per the Information Routing table. Do not wait for a "file change" trigger — there won't be one.
|
|
354
|
+
- **The Completeness Test applies equally** to code-derived and non-code knowledge. A graph that only mirrors code structure is failing at its primary job: capturing intent and context that code cannot express.
|
|
355
|
+
- **Non-code knowledge decays differently.** Business strategy changes by decision, not by commit. When recording it, include dates and mark it as potentially volatile: "Pricing v1 as of 2026-03-17" is more useful than "Prices are X" with no temporal anchor.
|
|
356
|
+
|
|
357
|
+
**Conversation knowledge is the most volatile source.** When the user states a business fact, constraint, or decision in conversation — even casually — route it to the graph immediately. Conversations vanish after context compression. If the user said it and it's not in code, it MUST be in the graph. Examples of conversational knowledge that must be captured:
|
|
358
|
+
|
|
359
|
+
- Business facts: "Our target customer is couples aged 25-35" → root node or business-context aspect
|
|
360
|
+
- Constraints: "We don't do studio sessions, only outdoor" → responsibility.md (NOT responsible for)
|
|
361
|
+
- Pricing: "Mini session costs 350 PLN" → relevant node artifacts
|
|
362
|
+
- Strategy: "Instagram is our primary acquisition channel" → root node or business-context aspect
|
|
363
|
+
- Decisions: "No deposit upfront — we'll reconsider after 5 sessions" → internals.md Decisions section with rationale
|
|
364
|
+
- Personas: "The admin user is non-technical, thinks in Instagram/WhatsApp terms" → UX aspect
|
|
365
|
+
|
|
366
|
+
Do not assume you will remember this later. Do not assume the user will repeat it. Capture it now or lose it forever.
|
|
367
|
+
|
|
368
|
+
**Common failure mode:** The entire protocol is file-centric (\`build-context --file\`, "after modifying source file", "per file not batched"). This means knowledge that doesn't map to a specific source file has no natural trigger for capture. Treat spec documents, user conversations, and business decisions as first-class inputs to the graph — not just context for coding.
|
|
369
|
+
|
|
370
|
+
### Aspect Discovery During Implementation
|
|
371
|
+
|
|
372
|
+
Aspects emerge from patterns across features. During greenfield implementation of multiple features:
|
|
373
|
+
|
|
374
|
+
- **After implementing 3+ features in the same area, pause and review:** Are there repeated patterns (autosave, version history, confirmation modals, empty states)? Are there shared UX rules from a persona doc? Are there quality requirements from specs? Extract them to aspects NOW.
|
|
375
|
+
- **Do NOT wait until all features are done.** Aspect extraction after 3 features captures the pattern while context is fresh. After 30 features, the rationale is forgotten and the aspect becomes a mechanical extraction without WHY.
|
|
376
|
+
- **Watch for "invisible" aspects:** UX patterns (autosave everywhere), quality constraints (WCAG level, Lighthouse targets), and business rules (Polish locale, price-in-grosz) are cross-cutting but don't feel "architectural." They are still aspects.
|
|
377
|
+
- **Trigger:** If you notice yourself implementing the same pattern for the third time, stop coding and create the aspect first. Then continue with the aspect applied to the current and previous nodes.
|
|
378
|
+
|
|
439
379
|
### CLI Reference
|
|
440
380
|
|
|
441
381
|
\`\`\`
|
|
442
382
|
yg preflight [--quick] Unified diagnostic: drift + status + validate.
|
|
443
|
-
yg owner --file <path> Find the node that owns this file.
|
|
444
|
-
yg build-context --
|
|
383
|
+
yg owner --file <path> Find the node that owns this file (quick check).
|
|
384
|
+
yg build-context --file <path> Resolve owner + assemble context in one step.
|
|
385
|
+
yg build-context --node <path> Assemble context map for a known node.
|
|
445
386
|
yg build-context --node <path> --full Same map + file contents appended below separator.
|
|
446
387
|
yg tree [--root <path>] [--depth N] Print graph structure.
|
|
447
388
|
yg aspects List aspects with metadata (YAML output).
|
|
@@ -450,8 +391,9 @@ yg select --task <description> [--limit <n>]
|
|
|
450
391
|
Find graph nodes relevant to a task description.
|
|
451
392
|
yg deps --node <path> [--depth N] [--type structural|event|all]
|
|
452
393
|
Show dependencies.
|
|
453
|
-
yg impact --
|
|
454
|
-
yg impact --node <path> --
|
|
394
|
+
yg impact --file <path> Resolve owner + show blast radius in one step.
|
|
395
|
+
yg impact --node <path> --simulate Simulate blast radius (works with --file too).
|
|
396
|
+
yg impact --node <path> --method <name> Filter to dependents consuming a method (works with --file too).
|
|
455
397
|
yg impact --aspect <id> Show all nodes where aspect is effective.
|
|
456
398
|
yg impact --flow <name> Show flow participants and descendants.
|
|
457
399
|
yg status Graph health: nodes, coverage, drift summary.
|
|
@@ -473,6 +415,203 @@ yg drift-sync --node <path> [--recursive] | --all
|
|
|
473
415
|
| Process-level requirement | Flow \`aspects\` + aspect directory |
|
|
474
416
|
| Context shared across a domain | Parent node artifact |
|
|
475
417
|
| Technology stack | Node artifact at appropriate hierarchy level |
|
|
476
|
-
| Coding standards | Node artifact at appropriate hierarchy level
|
|
418
|
+
| Coding standards | Node artifact at appropriate hierarchy level |
|
|
419
|
+
| Business strategy (personas, pricing, channels) | Root node artifact or dedicated business-context aspect |
|
|
420
|
+
| Quality targets (perf budgets, a11y, test goals) | Aspect per quality dimension |
|
|
421
|
+
| UX patterns (autosave, version history, empty states) | Aspect when pattern applies to 3+ screens |
|
|
422
|
+
| Infrastructure/deployment (domains, env vars, CI/CD) | Infrastructure node or root node artifacts |
|
|
423
|
+
| External service config (Stripe fees, email limits) | Relevant node's \`internals.md\` Decisions section |
|
|
424
|
+
| Feature spec from external doc | Node artifacts — translate spec into responsibility/interface/internals |`;
|
|
425
|
+
|
|
426
|
+
// prettier-ignore
|
|
427
|
+
const GUARD_RAILS = `## GUARD RAILS
|
|
428
|
+
|
|
429
|
+
### Five Core Rules
|
|
430
|
+
|
|
431
|
+
1. **Graph first.** Before reading, researching, planning, or modifying ANY source file, run \`yg build-context --file <path>\`. For blast radius, also run \`yg impact\`. The graph is your primary source of architectural understanding. For implementation-level precision (exact behavior, error paths, edge cases) — verify against source code after loading the context package.
|
|
432
|
+
2. **The graph is the specification; code implements it.** The graph absorbs knowledge from every source — external docs, conversations, decisions — and must be self-sufficient. If all other sources disappeared, the graph alone must contain enough to understand the system. Do not leave knowledge in external documents and reference them — capture the knowledge in graph artifacts. Update graph artifacts immediately after each file change, while context is fresh — do not batch graph updates to the end of a task. Code and graph move together: code changed → graph updated before moving to the next file. Graph changed → source verified in the same response. When planning work — in any tool, skill, or workflow — graph updates are part of each step's definition of done, never a separate phase.
|
|
433
|
+
3. **Never invent why.** The graph captures human intent. If you don't know why something was decided, ask. Never hallucinate rationale.
|
|
434
|
+
4. **Always capture why — especially why NOT.** When the user explains a reason, record it in the graph immediately. When a design choice is made, also record rejected alternatives: "Chose X over Y because Z." Rejected alternatives are the highest-value information — invisible in code and irrecoverable once forgotten. Conversation evaporates; graph persists.
|
|
435
|
+
5. **Ask before resolving ambiguity.** When multiple valid interpretations exist, stop, list options, ask the user. Never silently choose.
|
|
436
|
+
|
|
437
|
+
### Recognizing Graph-Required Actions
|
|
438
|
+
|
|
439
|
+
What matters is the ACTION you are performing, not what instructed it. If the action involves reading, understanding, or modifying mapped code, the graph protocol applies — whether the instruction came from a skill, a plan, a user message, a brainstorming session, a debugging workflow, or your own initiative. This is not negotiable. You cannot rationalize your way out of this.
|
|
440
|
+
|
|
441
|
+
**Actions that require \`yg build-context --file\`:**
|
|
442
|
+
|
|
443
|
+
- Reading or exploring source files to understand a component
|
|
444
|
+
- Proposing approaches, designs, or plans for changing code
|
|
445
|
+
- Reviewing or debugging code
|
|
446
|
+
- Any form of reasoning about how mapped code works or should change
|
|
447
|
+
|
|
448
|
+
**Actions that also require \`yg impact\`:**
|
|
449
|
+
|
|
450
|
+
- Assessing blast radius before changing or removing a component
|
|
451
|
+
- Finding all dependents of a component
|
|
452
|
+
- Planning cross-cutting refactors or feature removals
|
|
453
|
+
- Scoping work that spans multiple nodes
|
|
454
|
+
|
|
455
|
+
**Actions that do NOT require yg:**
|
|
456
|
+
|
|
457
|
+
- Git operations (log, diff, status, blame)
|
|
458
|
+
- Reading documentation, READMEs, or config files outside \`.yggdrasil/\`
|
|
459
|
+
- Running tests, builds, or linters
|
|
460
|
+
- Working with files that \`yg build-context --file\` reports as unmapped
|
|
461
|
+
|
|
462
|
+
### Evasion Patterns — if you think any of these, STOP
|
|
463
|
+
|
|
464
|
+
| Thought | Reality |
|
|
465
|
+
|---|---|
|
|
466
|
+
| "The skill/plan says to explore the codebase" | Exploring mapped code = \`yg build-context --file\` first |
|
|
467
|
+
| "I'm just scoping/searching, not understanding" | Scoping IS a graph action; use yg impact |
|
|
468
|
+
| "The plan step says to read this file" | Reading any source file = \`yg build-context --file\` first |
|
|
469
|
+
| "I'm brainstorming, not implementing" | Brainstorming about code needs graph context. You proved this by failing at it. |
|
|
470
|
+
| "I'm only grepping for references" | Grep finds text; yg impact finds structural dependencies. Use both. |
|
|
471
|
+
| "I'll use the graph later when I modify" | Graph-first means BEFORE reading, not before modifying |
|
|
472
|
+
| "I'll grep the codebase to find where to start" | Run \`yg select --task\` first, then \`yg build-context --file\` on results. |
|
|
473
|
+
| "Drift is blocking repo-check, let me just sync it" | Drift means artifacts are stale. Update artifacts first, then sync. \`drift-sync\` will warn you (W018). |
|
|
474
|
+
| "The user said work autonomously" | Autonomy amplifies discipline, not relaxes it. More tasks = more graph updates, not fewer. |
|
|
475
|
+
| "Same pattern as the last 5 files, no need to document" | Repetitive patterns hide deviations. Per-node coverage captures what aspects don't. The next agent won't know what you know now. |
|
|
476
|
+
| "I'll batch graph updates at the end" | Batching = never. Context is freshest immediately after the change. Defer = forget. This is a failure state. |
|
|
477
|
+
| "I'm saving context/tool calls by skipping graph" | Graph cost is constant per node. Skipping it creates unbounded future cost — the user re-explaining what you could have recorded. |
|
|
478
|
+
| "I assumed this file isn't mapped" | You cannot know without running \`yg build-context --file\`. Assume nothing. |
|
|
479
|
+
| "The spec is just input, I don't need to capture it" | Specs contain business context that code cannot express. Capture it or lose it. |
|
|
480
|
+
| "This business knowledge will be obvious from the code" | Pricing strategy, personas, UX rationale, and quality targets are NEVER obvious from code. |
|
|
481
|
+
| "I'll extract aspects after I finish all the features" | After 30 features the rationale is gone. Extract after 3. |
|
|
482
|
+
| "This is a UX detail, not architecture" | UX patterns that apply to 3+ screens ARE cross-cutting requirements. Create an aspect. |
|
|
483
|
+
| "The user just mentioned it casually, it's not a formal decision" | Casual statements ARE decisions. "We don't do studio" is a business constraint. Capture it now or lose it after context compression. |
|
|
484
|
+
| "I'll remember this from the conversation" | No you won't. Context gets compressed. The user won't repeat it. Write it to the graph now. |
|
|
485
|
+
|
|
486
|
+
### Failure States
|
|
487
|
+
|
|
488
|
+
You have broken Yggdrasil if you do any of the following:
|
|
489
|
+
|
|
490
|
+
- ❌ Worked on a source file without running \`yg build-context --file\` first — regardless of what instructed the action (skill, plan, user request, workflow step).
|
|
491
|
+
- ❌ Modified source code without updating graph artifacts before moving to the next file, or vice versa.
|
|
492
|
+
- ❌ Batched graph updates to "do later" — deferred = forgotten. Update after EACH file.
|
|
493
|
+
- ❌ Resolved a code-graph inconsistency or ambiguity without asking the user first.
|
|
494
|
+
- ❌ Created or edited a graph element without reading its schema in \`schemas/\` first.
|
|
495
|
+
- ❌ Ran \`yg drift-sync\` before both graph artifacts and source code are current. (CLI will warn you: W018.)
|
|
496
|
+
- ❌ Placed a cross-cutting requirement in a local artifact instead of an aspect, or used an aspect id with no \`aspects/\` directory.
|
|
497
|
+
- ❌ Invented a rationale, business rule, or decision — or recorded a decision without documenting rejected alternatives and rationale (use "rationale: unknown" if unknown).
|
|
498
|
+
- ❌ Used blackbox coverage for greenfield (new) code.
|
|
499
|
+
- ❌ Deleted or shortened graph artifact content to reduce context package size instead of splitting the node.
|
|
500
|
+
- ❌ Created one wide node for many files instead of granular nodes with focused responsibilities. (CLI will warn you: W017.)
|
|
501
|
+
- ❌ Implemented features from a spec without first transferring spec knowledge (business context, UX rules, quality targets) into the graph. Code without captured intent is a maintenance trap.
|
|
502
|
+
- ❌ Implemented 3+ features sharing a pattern (autosave, version history, empty states) without extracting it to an aspect. Deferred aspect discovery = lost rationale.
|
|
503
|
+
- ❌ Left business strategy, personas, or quality targets only in external documents instead of routing them to graph artifacts. External docs are input; the graph is the persistent store.
|
|
504
|
+
- ❌ Heard the user state a business fact, constraint, or decision in conversation and did not record it in the graph. Conversations are the most volatile knowledge source — they vanish after context compression and the user will not repeat them.
|
|
505
|
+
|
|
506
|
+
### Reverse Engineering
|
|
507
|
+
|
|
508
|
+
**Order:** aspects (cross-cutting patterns) → flows (business processes) → model nodes. Never create nodes before aspects and flows are understood.
|
|
509
|
+
|
|
510
|
+
Per area checklist:
|
|
511
|
+
|
|
512
|
+
- [ ] 1. \`yg build-context --file <path>\` — confirm no coverage
|
|
513
|
+
- [ ] 2. Determine node granularity — propose to user if unclear
|
|
514
|
+
- [ ] 3. Create node directory, read \`schemas/yg-node.yaml\`, create \`yg-node.yaml\`
|
|
515
|
+
- [ ] 3b. Write \`description\` in \`yg-node.yaml\` — a short summary of what the node does
|
|
516
|
+
- [ ] 4. Analyze source — for each artifact type in \`yg-config.yaml artifacts\`: extract content, do not invent
|
|
517
|
+
- [ ] 5. Identify relations — add to \`yg-node.yaml\`
|
|
518
|
+
- [ ] 6. Identify cross-cutting requirements — add matching aspects, create if needed
|
|
519
|
+
- [ ] 6b. For each aspect on the node: identify 2-5 code anchors (function names, constants) that evidence the pattern → add as \`anchors\` in the aspect entry in \`yg-node.yaml\`
|
|
520
|
+
- [ ] 7. Identify business process participation — add to flow, ask user if process unclear
|
|
521
|
+
- [ ] 8. \`yg validate\` — fix errors
|
|
522
|
+
- [ ] 9. \`yg drift-sync --node <path>\`
|
|
523
|
+
|
|
524
|
+
**When to ask:**
|
|
525
|
+
|
|
526
|
+
- Business process unclear: "This code appears to be part of a larger process. Can you describe what it means from a business perspective?"
|
|
527
|
+
- Constraint without rationale: "I see [constraint X]. Do you know why this exists? I want to record the reason, not just the rule."
|
|
528
|
+
- Unexplained architectural choice: "I see [approach X]. What was the reason for this choice?"
|
|
529
|
+
- Decision without alternatives: "You chose [X]. What alternatives did you consider, and why did you reject them?" Record the answer in the Decisions section of \`internals.md\`.
|
|
530
|
+
- Decision without known rationale: Record the decision in \`internals.md\` with "rationale: unknown — inferred from code, not confirmed by developer." A recorded decision with unknown rationale is infinitely more valuable than no record at all, and safer than an invented rationale.
|
|
531
|
+
|
|
532
|
+
### Bootstrap Mode
|
|
533
|
+
|
|
534
|
+
Trigger: \`yg preflight\` shows 0 nodes, or no nodes cover the active work area.
|
|
535
|
+
|
|
536
|
+
- [ ] 1. Identify the active work area (files the user wants to modify)
|
|
537
|
+
- [ ] 2. Scan for cross-cutting patterns → create aspects
|
|
538
|
+
- [ ] 3. Ask user about business processes → create flows if applicable
|
|
539
|
+
- [ ] 4. Propose node structure for the area
|
|
540
|
+
- [ ] 5. Create node(s) with initial artifacts, map files
|
|
541
|
+
- [ ] 6. \`yg validate\`, \`yg drift-sync\`
|
|
542
|
+
- [ ] 7. Proceed with user's original request
|
|
543
|
+
|
|
544
|
+
Constraint: Do NOT map the entire repository. Focus on the active area. Expand incrementally.
|
|
545
|
+
|
|
546
|
+
### Drift Resolution
|
|
547
|
+
|
|
548
|
+
Always ask the user before resolving drift. Never auto-resolve.
|
|
549
|
+
|
|
550
|
+
- **Source drift** (source files changed) → update graph artifacts to match source, then \`yg drift-sync\`
|
|
551
|
+
- **Graph drift** (graph artifacts changed) → review affected source, update if needed, then \`yg drift-sync\`
|
|
552
|
+
- **Full drift** (both changed) → present both sides to user, ask which direction wins
|
|
553
|
+
- **Missing** → ask: re-materialize or remove mapping?
|
|
554
|
+
- **Unmaterialized** → ask user how to proceed
|
|
555
|
+
|
|
556
|
+
Threshold: >10 drifted nodes → ask user which area to prioritize. Do not resolve all at once.
|
|
557
|
+
|
|
558
|
+
**Drift triage:** Prioritize aspects and \`internals.md\` (highest decay rate), then \`responsibility.md\` and \`interface.md\` (most stable).
|
|
559
|
+
|
|
560
|
+
### Graph Audit
|
|
561
|
+
|
|
562
|
+
When reviewing graph quality (triggered by user or quality improvement):
|
|
563
|
+
|
|
564
|
+
**Step 1 — Consistency** (catches WRONG information):
|
|
565
|
+
|
|
566
|
+
- [ ] 1. \`yg build-context --node <path>\`
|
|
567
|
+
- [ ] 2. Read mapped source files
|
|
568
|
+
- [ ] 3. For each claim in graph: verify against source code
|
|
569
|
+
- [ ] 4. For each aspect: verify the pattern holds in THIS node. If it deviates, add \`exceptions\` to the aspect entry in \`yg-node.yaml\`
|
|
570
|
+
- [ ] 5. Report inconsistencies
|
|
571
|
+
|
|
572
|
+
**Step 2 — Completeness** (catches MISSING information):
|
|
573
|
+
|
|
574
|
+
- [ ] 1. For each public method: is it in \`interface.md\`?
|
|
575
|
+
- [ ] 2. For each error path: is it in \`interface.md\` (Failure Modes section)?
|
|
576
|
+
- [ ] 3. For each behavioral invariant: is it in the graph?
|
|
577
|
+
- [ ] 4. Report omissions separately from inconsistencies
|
|
578
|
+
|
|
579
|
+
**Step 3 — Non-Derivable Knowledge** (catches knowledge that exists ONLY in external docs or conversations, not in code):
|
|
580
|
+
|
|
581
|
+
- [ ] 1. For each business rule embedded in code: is the WHY recorded in the graph, or only the WHAT visible in code?
|
|
582
|
+
- [ ] 2. For each design decision: is the rationale AND rejected alternatives recorded?
|
|
583
|
+
- [ ] 3. For each external constraint (brand guidelines, legal, UX persona, quality targets): is it in the graph?
|
|
584
|
+
- [ ] 4. For each cross-cutting pattern implemented in 3+ places: does an aspect exist?
|
|
585
|
+
- [ ] 5. Report non-derivable knowledge gaps separately — these are the highest-value omissions because they cannot be recovered by reading code.
|
|
586
|
+
|
|
587
|
+
### Error Recovery
|
|
588
|
+
|
|
589
|
+
- **\`yg\` not found** → inform user: "yg CLI is not installed or not in PATH." Stop.
|
|
590
|
+
- **Unfixable validate errors** → if not resolved after 3 attempts, stop and report to user. Do not loop.
|
|
591
|
+
- **Budget warning (W005/W006)** → informational. \`yg validate\` shows a breakdown (own/hierarchy/aspects/flows/dependencies). Large inherited context means the system is complex — this is not a problem to fix, it is reality to acknowledge. Do not delete knowledge from artifacts. Do not attempt to "reduce" inherited context.
|
|
592
|
+
- **Own budget warning (W015)** → own artifacts are large. Consider splitting this node's responsibilities into child nodes. Redistribute knowledge across children so total knowledge is preserved or increased, never reduced.
|
|
593
|
+
- **Corrupted \`.yggdrasil/\` files** → report to user. Do not attempt repair.
|
|
594
|
+
- **Incremental sync** → run \`yg drift-sync\` every 3-5 source files during multi-file tasks. Do not defer to end. But NEVER run \`yg drift-sync\` to silence a failing drift check — drift is a signal that artifacts need updating. First update artifacts, then sync.
|
|
595
|
+
|
|
596
|
+
### Escape Hatch
|
|
597
|
+
|
|
598
|
+
If the user explicitly requests a code-only change, comply but:
|
|
599
|
+
|
|
600
|
+
- Warn: "This creates drift. Run \`yg drift\` next session to reconcile."
|
|
601
|
+
- Do NOT run \`yg drift-sync\` — leave the drift visible.
|
|
602
|
+
|
|
603
|
+
### Environment Check
|
|
604
|
+
|
|
605
|
+
Before preflight:
|
|
606
|
+
|
|
607
|
+
- Verify \`yg\` CLI is available. If not found, inform user and stop.
|
|
608
|
+
- If \`yg preflight\` shows 0 nodes → enter BOOTSTRAP MODE (see above).
|
|
609
|
+
- If drift report shows >10 drifted nodes → report scope to user, ask which area to prioritize. Do not resolve all at once.
|
|
610
|
+
|
|
611
|
+
<critical_protocol>
|
|
612
|
+
BEFORE reading, analyzing, or modifying ANY source file:
|
|
613
|
+
\`yg build-context --file <path>\`
|
|
614
|
+
One command. No exceptions. No "I'll do it later." No "this is just analysis."
|
|
615
|
+
</critical_protocol>`;
|
|
477
616
|
|
|
478
|
-
export const AGENT_RULES_CONTENT = [
|
|
617
|
+
export const AGENT_RULES_CONTENT = [PROTOCOL, REFERENCE, GUARD_RAILS].join('\n\n---\n\n') + '\n';
|