@chrisdudek/yg 2.7.0 → 2.8.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 +521 -394
- package/dist/bin.js.map +1 -1
- package/dist/templates/rules.ts +275 -244
- package/package.json +1 -1
package/dist/templates/rules.ts
CHANGED
|
@@ -3,201 +3,65 @@
|
|
|
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
|
|
25
|
-
|
|
26
|
-
\`\`\`
|
|
27
|
-
BEFORE reading, researching, planning, OR modifying ANY mapped file:
|
|
28
|
-
0. Don't know which file or node to start from? Run
|
|
29
|
-
yg select --task "<your goal>" to find relevant nodes via keyword
|
|
30
|
-
matching against graph artifacts. If a semantic search tool is also
|
|
31
|
-
available, use it for richer intent matching. Use the results
|
|
32
|
-
to identify relevant nodes, then proceed to step 1.
|
|
33
|
-
1. yg owner --file <path>
|
|
34
|
-
2. Choose the right graph tool for your task:
|
|
35
|
-
- Understanding how/why it works → yg build-context --node <owner>
|
|
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.
|
|
30
|
+
### Quick Start
|
|
44
31
|
|
|
45
|
-
AFTER modifying:
|
|
46
|
-
3. Update graph artifacts to reflect changes
|
|
47
|
-
4. yg validate — fix all errors
|
|
48
|
-
5. yg drift-sync --node <owner>
|
|
49
|
-
|
|
50
|
-
EVERY conversation start:
|
|
51
|
-
yg preflight → act on findings (see Operations)
|
|
52
|
-
|
|
53
|
-
NEVER: modify code without graph coverage.
|
|
54
|
-
NEVER: read mapped source files to understand a component without
|
|
55
|
-
running yg build-context first — the graph captures intent,
|
|
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.
|
|
62
32
|
\`\`\`
|
|
33
|
+
EVERY conversation: yg preflight — no exceptions.
|
|
63
34
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
### Recognizing Graph-Required Actions
|
|
73
|
-
|
|
74
|
-
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.
|
|
75
|
-
|
|
76
|
-
**Actions that require \`yg owner\` + \`yg build-context\`:**
|
|
77
|
-
|
|
78
|
-
- Reading or exploring source files to understand a component
|
|
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
|
|
82
|
-
|
|
83
|
-
**Actions that require \`yg owner\` + \`yg impact\`:**
|
|
84
|
-
|
|
85
|
-
- Assessing blast radius before changing or removing a component
|
|
86
|
-
- Finding all dependents of a component
|
|
87
|
-
- Planning cross-cutting refactors or feature removals
|
|
88
|
-
- Scoping work that spans multiple nodes
|
|
89
|
-
|
|
90
|
-
**Actions that do NOT require yg:**
|
|
91
|
-
|
|
92
|
-
- Git operations (log, diff, status, blame)
|
|
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
|
|
96
|
-
|
|
97
|
-
**Evasion patterns — if you think any of these, STOP:**
|
|
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>"
|
|
98
42
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
### Failure States
|
|
111
|
-
|
|
112
|
-
You have broken Yggdrasil if you do any of the following:
|
|
113
|
-
|
|
114
|
-
- ❌ Worked on a mapped file without running \`yg owner\` + the appropriate graph tool (\`build-context\` or \`impact\`) first — regardless of what instructed the action (skill, plan, user request, workflow step).
|
|
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.
|
|
123
|
-
|
|
124
|
-
### Escape Hatch
|
|
125
|
-
|
|
126
|
-
If the user explicitly requests a code-only change, comply but:
|
|
127
|
-
|
|
128
|
-
- Warn: "This creates drift. Run \`yg drift\` next session to reconcile."
|
|
129
|
-
- Do NOT run \`yg drift-sync\` — leave the drift visible.
|
|
130
|
-
|
|
131
|
-
### Environment Check
|
|
132
|
-
|
|
133
|
-
Before preflight:
|
|
134
|
-
|
|
135
|
-
- Verify \`yg\` CLI is available. If not found, inform user and stop.
|
|
136
|
-
- If \`yg preflight\` shows 0 nodes → enter BOOTSTRAP MODE (see Operations).
|
|
137
|
-
- If drift report shows >10 drifted nodes → report scope to user, ask which area to prioritize. Do not resolve all at once.
|
|
138
|
-
|
|
139
|
-
### Delegating to Subagents
|
|
140
|
-
|
|
141
|
-
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:
|
|
142
|
-
|
|
143
|
-
1. Read \`.yggdrasil/agent-rules.md\` — this is the complete operating manual
|
|
144
|
-
2. Follow the Quick Start Protocol from that file before touching any mapped code
|
|
145
|
-
|
|
146
|
-
Include this as the FIRST instruction in every subagent prompt:
|
|
147
|
-
|
|
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
|
-
\`\`\`
|
|
155
|
-
|
|
156
|
-
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.`;
|
|
157
|
-
|
|
158
|
-
// prettier-ignore
|
|
159
|
-
const OPERATIONS = `## OPERATIONS
|
|
160
|
-
|
|
161
|
-
### Conversation Lifecycle
|
|
162
|
-
|
|
163
|
-
\`\`\`
|
|
164
|
-
PREFLIGHT (every conversation, before any work):
|
|
165
|
-
- [ ] 1. yg preflight → read unified report
|
|
166
|
-
- [ ] 2. If drift: resolve per Drift Resolution, then yg drift-sync per node
|
|
167
|
-
- [ ] 3. If validation errors: fix, re-run yg validate
|
|
168
|
-
Exception: read-only requests (explain, analyze) — skip preflight.
|
|
169
|
-
|
|
170
|
-
UNDERSTANDING mapped code (questions, research, OR planning):
|
|
171
|
-
- [ ] 1. yg owner --file <path>
|
|
172
|
-
- [ ] 2. Owner found → yg build-context --node <path>. Read the YAML map
|
|
173
|
-
for topology, starting with the glossary at the top for aspect and
|
|
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.
|
|
178
|
-
Never use grep or raw file reads as primary understanding when graph coverage exists.
|
|
179
|
-
Raw reads supplement the context package — they do not replace it.
|
|
180
|
-
|
|
181
|
-
WRAP-UP (user signals "done", "wrap up", "that's enough"):
|
|
182
|
-
- [ ] 1. yg drift --drifted-only → resolve
|
|
183
|
-
- [ ] 2. yg validate → fix errors
|
|
184
|
-
- [ ] 3. Report: which nodes and files were changed
|
|
185
|
-
|
|
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.
|
|
43
|
+
AFTER modifying:
|
|
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.
|
|
190
54
|
\`\`\`
|
|
191
55
|
|
|
192
56
|
### Modify Source Code
|
|
193
57
|
|
|
194
58
|
You are not allowed to edit or create source code without establishing graph coverage first.
|
|
195
59
|
|
|
196
|
-
**Step 1** —
|
|
60
|
+
**Step 1** — Get context: \`yg build-context --file <path>\` (resolves owner automatically)
|
|
197
61
|
|
|
198
62
|
**Step 2a** — Owner found: execute checklist:
|
|
199
63
|
|
|
200
|
-
- [ ] 1. Read
|
|
64
|
+
- [ ] 1. Read the context package (already assembled by step 1)
|
|
201
65
|
- [ ] 2. Assess blast radius: \`yg impact --node <node_path>\` — review dependents, descendants, and co-aspect nodes before changing interfaces or shared behavior
|
|
202
66
|
- [ ] 3. Modify source code
|
|
203
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\`.
|
|
@@ -225,99 +89,91 @@ You are not allowed to edit or create source code without establishing graph cov
|
|
|
225
89
|
|
|
226
90
|
After the user chooses, return to Step 1 and follow Step 2a.
|
|
227
91
|
|
|
228
|
-
###
|
|
92
|
+
### Example: Correct vs Wrong
|
|
229
93
|
|
|
230
|
-
|
|
231
|
-
- [ ] 2. Before changing an aspect or flow, check scope: \`yg impact --aspect <id>\` or \`yg impact --flow <name>\` — understand which nodes are affected before modifying shared rules or processes
|
|
232
|
-
- [ ] 3. Make changes
|
|
233
|
-
- [ ] 4. Run \`yg validate\` immediately — fix all errors
|
|
234
|
-
- [ ] 5. Verify affected source files are consistent — update if needed
|
|
235
|
-
- [ ] 6. Run \`yg drift-sync\` for affected nodes
|
|
94
|
+
<example_correct>
|
|
236
95
|
|
|
237
|
-
|
|
96
|
+
User: "Fix the bug in payment.service.ts"
|
|
238
97
|
|
|
239
|
-
|
|
98
|
+
1. yg build-context --file src/payment.service.ts → payment/payment-service
|
|
99
|
+
2. Read YAML map — glossary, then artifact files
|
|
100
|
+
3. Read source file, understand bug in graph context
|
|
101
|
+
4. Fix bug
|
|
102
|
+
5. Update payment-service artifacts (responsibility.md, interface.md if API changed)
|
|
103
|
+
6. yg validate
|
|
104
|
+
7. yg drift-sync --node payment/payment-service
|
|
240
105
|
|
|
241
|
-
|
|
106
|
+
</example_correct>
|
|
242
107
|
|
|
243
|
-
|
|
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>\`
|
|
108
|
+
<example_wrong>
|
|
254
109
|
|
|
255
|
-
|
|
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.
|
|
110
|
+
User: "Fix the bug in payment.service.ts"
|
|
262
111
|
|
|
263
|
-
|
|
112
|
+
1. Read src/payment.service.ts ← WRONG: no graph context loaded
|
|
113
|
+
2. Fix bug
|
|
114
|
+
3. "I'll update the graph later" ← WRONG: deferred = forgotten
|
|
264
115
|
|
|
265
|
-
|
|
116
|
+
Result: graph is stale, next agent asks user the same questions
|
|
266
117
|
|
|
267
|
-
|
|
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
|
|
118
|
+
</example_wrong>
|
|
274
119
|
|
|
275
|
-
|
|
120
|
+
### Conversation Lifecycle
|
|
276
121
|
|
|
277
|
-
|
|
122
|
+
\`\`\`
|
|
123
|
+
PREFLIGHT (every conversation, before any work):
|
|
124
|
+
- [ ] 1. yg preflight → read unified report
|
|
125
|
+
- [ ] 2. If drift: resolve per Drift Resolution, then yg drift-sync per node
|
|
126
|
+
- [ ] 3. If validation errors: fix, re-run yg validate
|
|
127
|
+
No exceptions. You cannot know if a file is mapped without running yg.
|
|
278
128
|
|
|
279
|
-
|
|
129
|
+
UNDERSTANDING any source file (questions, research, OR planning):
|
|
130
|
+
- [ ] 1. yg build-context --file <path>
|
|
131
|
+
Mapped → read the YAML map (glossary first, then artifact files).
|
|
132
|
+
Unmapped → use file analysis, state it is not graph-backed.
|
|
133
|
+
Never use grep or raw file reads as primary understanding when graph coverage exists.
|
|
134
|
+
Raw reads supplement the context package — they do not replace it.
|
|
280
135
|
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
- **Missing** → ask: re-materialize or remove mapping?
|
|
285
|
-
- **Unmaterialized** → ask user how to proceed
|
|
136
|
+
BEFORE reasoning about source code, state which graph context you loaded:
|
|
137
|
+
"graph: <node_path>" if mapped, "graph: unmapped" if not.
|
|
138
|
+
This is a required output step, not optional reflection.
|
|
286
139
|
|
|
287
|
-
|
|
140
|
+
WRAP-UP (user signals "done", "wrap up", "that's enough"):
|
|
141
|
+
- [ ] 1. yg drift --drifted-only → resolve
|
|
142
|
+
- [ ] 2. yg validate → fix errors
|
|
143
|
+
- [ ] 3. Report: which nodes and files were changed
|
|
288
144
|
|
|
289
|
-
|
|
145
|
+
\`\`\`
|
|
290
146
|
|
|
291
|
-
### Graph
|
|
147
|
+
### Modify Graph
|
|
292
148
|
|
|
293
|
-
|
|
149
|
+
- [ ] 1. Read the relevant schema from \`schemas/\` before touching any YAML
|
|
150
|
+
- [ ] 2. Before changing an aspect or flow, check scope: \`yg impact --aspect <id>\` or \`yg impact --flow <name>\` — understand which nodes are affected before modifying shared rules or processes
|
|
151
|
+
- [ ] 3. Make changes
|
|
152
|
+
- [ ] 4. Run \`yg validate\` immediately — fix all errors
|
|
153
|
+
- [ ] 5. Verify affected source files are consistent — update if needed
|
|
154
|
+
- [ ] 6. Run \`yg drift-sync\` for affected nodes
|
|
294
155
|
|
|
295
|
-
|
|
156
|
+
### Delegating to Subagents
|
|
296
157
|
|
|
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
|
|
158
|
+
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
159
|
|
|
303
|
-
|
|
160
|
+
1. Read \`.yggdrasil/agent-rules.md\` — this is the complete operating manual
|
|
161
|
+
2. Follow the Quick Start Protocol from that file before touching any mapped code
|
|
304
162
|
|
|
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
|
|
163
|
+
Include this as the FIRST instruction in every subagent prompt:
|
|
309
164
|
|
|
310
|
-
|
|
165
|
+
\`\`\`
|
|
166
|
+
BEFORE doing anything else: read .yggdrasil/agent-rules.md and follow its protocol.
|
|
167
|
+
DELIVERABLES — all required, incomplete work will be rejected:
|
|
168
|
+
1. Working source code
|
|
169
|
+
2. Graph nodes with artifacts for every new/modified source file
|
|
170
|
+
3. \`yg validate\` passing
|
|
171
|
+
\`\`\`
|
|
311
172
|
|
|
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.`;
|
|
173
|
+
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
174
|
|
|
319
175
|
// prettier-ignore
|
|
320
|
-
const
|
|
176
|
+
const REFERENCE = `## REFERENCE
|
|
321
177
|
|
|
322
178
|
### Graph Structure
|
|
323
179
|
|
|
@@ -440,8 +296,9 @@ Test: "Does this describe what happens in the world, or only in the software?" I
|
|
|
440
296
|
|
|
441
297
|
\`\`\`
|
|
442
298
|
yg preflight [--quick] Unified diagnostic: drift + status + validate.
|
|
443
|
-
yg owner --file <path> Find the node that owns this file.
|
|
444
|
-
yg build-context --
|
|
299
|
+
yg owner --file <path> Find the node that owns this file (quick check).
|
|
300
|
+
yg build-context --file <path> Resolve owner + assemble context in one step.
|
|
301
|
+
yg build-context --node <path> Assemble context map for a known node.
|
|
445
302
|
yg build-context --node <path> --full Same map + file contents appended below separator.
|
|
446
303
|
yg tree [--root <path>] [--depth N] Print graph structure.
|
|
447
304
|
yg aspects List aspects with metadata (YAML output).
|
|
@@ -450,8 +307,9 @@ yg select --task <description> [--limit <n>]
|
|
|
450
307
|
Find graph nodes relevant to a task description.
|
|
451
308
|
yg deps --node <path> [--depth N] [--type structural|event|all]
|
|
452
309
|
Show dependencies.
|
|
453
|
-
yg impact --
|
|
454
|
-
yg impact --node <path> --
|
|
310
|
+
yg impact --file <path> Resolve owner + show blast radius in one step.
|
|
311
|
+
yg impact --node <path> --simulate Simulate blast radius (works with --file too).
|
|
312
|
+
yg impact --node <path> --method <name> Filter to dependents consuming a method (works with --file too).
|
|
455
313
|
yg impact --aspect <id> Show all nodes where aspect is effective.
|
|
456
314
|
yg impact --flow <name> Show flow participants and descendants.
|
|
457
315
|
yg status Graph health: nodes, coverage, drift summary.
|
|
@@ -475,4 +333,177 @@ yg drift-sync --node <path> [--recursive] | --all
|
|
|
475
333
|
| Technology stack | Node artifact at appropriate hierarchy level |
|
|
476
334
|
| Coding standards | Node artifact at appropriate hierarchy level |`;
|
|
477
335
|
|
|
478
|
-
|
|
336
|
+
// prettier-ignore
|
|
337
|
+
const GUARD_RAILS = `## GUARD RAILS
|
|
338
|
+
|
|
339
|
+
### Five Core Rules
|
|
340
|
+
|
|
341
|
+
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.
|
|
342
|
+
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.
|
|
343
|
+
3. **Never invent why.** The graph captures human intent. If you don't know why something was decided, ask. Never hallucinate rationale.
|
|
344
|
+
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.
|
|
345
|
+
5. **Ask before resolving ambiguity.** When multiple valid interpretations exist, stop, list options, ask the user. Never silently choose.
|
|
346
|
+
|
|
347
|
+
### Recognizing Graph-Required Actions
|
|
348
|
+
|
|
349
|
+
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.
|
|
350
|
+
|
|
351
|
+
**Actions that require \`yg build-context --file\`:**
|
|
352
|
+
|
|
353
|
+
- Reading or exploring source files to understand a component
|
|
354
|
+
- Proposing approaches, designs, or plans for changing code
|
|
355
|
+
- Reviewing or debugging code
|
|
356
|
+
- Any form of reasoning about how mapped code works or should change
|
|
357
|
+
|
|
358
|
+
**Actions that also require \`yg impact\`:**
|
|
359
|
+
|
|
360
|
+
- Assessing blast radius before changing or removing a component
|
|
361
|
+
- Finding all dependents of a component
|
|
362
|
+
- Planning cross-cutting refactors or feature removals
|
|
363
|
+
- Scoping work that spans multiple nodes
|
|
364
|
+
|
|
365
|
+
**Actions that do NOT require yg:**
|
|
366
|
+
|
|
367
|
+
- Git operations (log, diff, status, blame)
|
|
368
|
+
- Reading documentation, READMEs, or config files outside \`.yggdrasil/\`
|
|
369
|
+
- Running tests, builds, or linters
|
|
370
|
+
- Working with files that \`yg build-context --file\` reports as unmapped
|
|
371
|
+
|
|
372
|
+
### Evasion Patterns — if you think any of these, STOP
|
|
373
|
+
|
|
374
|
+
| Thought | Reality |
|
|
375
|
+
|---|---|
|
|
376
|
+
| "The skill/plan says to explore the codebase" | Exploring mapped code = \`yg build-context --file\` first |
|
|
377
|
+
| "I'm just scoping/searching, not understanding" | Scoping IS a graph action; use yg impact |
|
|
378
|
+
| "The plan step says to read this file" | Reading any source file = \`yg build-context --file\` first |
|
|
379
|
+
| "I'm brainstorming, not implementing" | Brainstorming about code needs graph context. You proved this by failing at it. |
|
|
380
|
+
| "I'm only grepping for references" | Grep finds text; yg impact finds structural dependencies. Use both. |
|
|
381
|
+
| "I'll use the graph later when I modify" | Graph-first means BEFORE reading, not before modifying |
|
|
382
|
+
| "I'll grep the codebase to find where to start" | Run \`yg select --task\` first, then \`yg build-context --file\` on results. |
|
|
383
|
+
| "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). |
|
|
384
|
+
| "The user said work autonomously" | Autonomy amplifies discipline, not relaxes it. More tasks = more graph updates, not fewer. |
|
|
385
|
+
| "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. |
|
|
386
|
+
| "I'll batch graph updates at the end" | Batching = never. Context is freshest immediately after the change. Defer = forget. This is a failure state. |
|
|
387
|
+
| "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. |
|
|
388
|
+
| "I assumed this file isn't mapped" | You cannot know without running \`yg build-context --file\`. Assume nothing. |
|
|
389
|
+
|
|
390
|
+
### Failure States
|
|
391
|
+
|
|
392
|
+
You have broken Yggdrasil if you do any of the following:
|
|
393
|
+
|
|
394
|
+
- ❌ Worked on a source file without running \`yg build-context --file\` first — regardless of what instructed the action (skill, plan, user request, workflow step).
|
|
395
|
+
- ❌ Modified source code without updating graph artifacts before moving to the next file, or vice versa.
|
|
396
|
+
- ❌ Batched graph updates to "do later" — deferred = forgotten. Update after EACH file.
|
|
397
|
+
- ❌ Resolved a code-graph inconsistency or ambiguity without asking the user first.
|
|
398
|
+
- ❌ Created or edited a graph element without reading its schema in \`schemas/\` first.
|
|
399
|
+
- ❌ Ran \`yg drift-sync\` before both graph artifacts and source code are current. (CLI will warn you: W018.)
|
|
400
|
+
- ❌ Placed a cross-cutting requirement in a local artifact instead of an aspect, or used an aspect id with no \`aspects/\` directory.
|
|
401
|
+
- ❌ Invented a rationale, business rule, or decision — or recorded a decision without documenting rejected alternatives and rationale (use "rationale: unknown" if unknown).
|
|
402
|
+
- ❌ Used blackbox coverage for greenfield (new) code.
|
|
403
|
+
- ❌ Deleted or shortened graph artifact content to reduce context package size instead of splitting the node.
|
|
404
|
+
- ❌ Created one wide node for many files instead of granular nodes with focused responsibilities. (CLI will warn you: W017.)
|
|
405
|
+
|
|
406
|
+
### Reverse Engineering
|
|
407
|
+
|
|
408
|
+
**Order:** aspects (cross-cutting patterns) → flows (business processes) → model nodes. Never create nodes before aspects and flows are understood.
|
|
409
|
+
|
|
410
|
+
Per area checklist:
|
|
411
|
+
|
|
412
|
+
- [ ] 1. \`yg build-context --file <path>\` — confirm no coverage
|
|
413
|
+
- [ ] 2. Determine node granularity — propose to user if unclear
|
|
414
|
+
- [ ] 3. Create node directory, read \`schemas/yg-node.yaml\`, create \`yg-node.yaml\`
|
|
415
|
+
- [ ] 3b. Write \`description\` in \`yg-node.yaml\` — a short summary of what the node does
|
|
416
|
+
- [ ] 4. Analyze source — for each artifact type in \`yg-config.yaml artifacts\`: extract content, do not invent
|
|
417
|
+
- [ ] 5. Identify relations — add to \`yg-node.yaml\`
|
|
418
|
+
- [ ] 6. Identify cross-cutting requirements — add matching aspects, create if needed
|
|
419
|
+
- [ ] 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\`
|
|
420
|
+
- [ ] 7. Identify business process participation — add to flow, ask user if process unclear
|
|
421
|
+
- [ ] 8. \`yg validate\` — fix errors
|
|
422
|
+
- [ ] 9. \`yg drift-sync --node <path>\`
|
|
423
|
+
|
|
424
|
+
**When to ask:**
|
|
425
|
+
|
|
426
|
+
- Business process unclear: "This code appears to be part of a larger process. Can you describe what it means from a business perspective?"
|
|
427
|
+
- Constraint without rationale: "I see [constraint X]. Do you know why this exists? I want to record the reason, not just the rule."
|
|
428
|
+
- Unexplained architectural choice: "I see [approach X]. What was the reason for this choice?"
|
|
429
|
+
- 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\`.
|
|
430
|
+
- 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.
|
|
431
|
+
|
|
432
|
+
### Bootstrap Mode
|
|
433
|
+
|
|
434
|
+
Trigger: \`yg preflight\` shows 0 nodes, or no nodes cover the active work area.
|
|
435
|
+
|
|
436
|
+
- [ ] 1. Identify the active work area (files the user wants to modify)
|
|
437
|
+
- [ ] 2. Scan for cross-cutting patterns → create aspects
|
|
438
|
+
- [ ] 3. Ask user about business processes → create flows if applicable
|
|
439
|
+
- [ ] 4. Propose node structure for the area
|
|
440
|
+
- [ ] 5. Create node(s) with initial artifacts, map files
|
|
441
|
+
- [ ] 6. \`yg validate\`, \`yg drift-sync\`
|
|
442
|
+
- [ ] 7. Proceed with user's original request
|
|
443
|
+
|
|
444
|
+
Constraint: Do NOT map the entire repository. Focus on the active area. Expand incrementally.
|
|
445
|
+
|
|
446
|
+
### Drift Resolution
|
|
447
|
+
|
|
448
|
+
Always ask the user before resolving drift. Never auto-resolve.
|
|
449
|
+
|
|
450
|
+
- **Source drift** (source files changed) → update graph artifacts to match source, then \`yg drift-sync\`
|
|
451
|
+
- **Graph drift** (graph artifacts changed) → review affected source, update if needed, then \`yg drift-sync\`
|
|
452
|
+
- **Full drift** (both changed) → present both sides to user, ask which direction wins
|
|
453
|
+
- **Missing** → ask: re-materialize or remove mapping?
|
|
454
|
+
- **Unmaterialized** → ask user how to proceed
|
|
455
|
+
|
|
456
|
+
Threshold: >10 drifted nodes → ask user which area to prioritize. Do not resolve all at once.
|
|
457
|
+
|
|
458
|
+
**Drift triage:** Prioritize aspects and \`internals.md\` (highest decay rate), then \`responsibility.md\` and \`interface.md\` (most stable).
|
|
459
|
+
|
|
460
|
+
### Graph Audit
|
|
461
|
+
|
|
462
|
+
When reviewing graph quality (triggered by user or quality improvement):
|
|
463
|
+
|
|
464
|
+
**Step 1 — Consistency** (catches WRONG information):
|
|
465
|
+
|
|
466
|
+
- [ ] 1. \`yg build-context --node <path>\`
|
|
467
|
+
- [ ] 2. Read mapped source files
|
|
468
|
+
- [ ] 3. For each claim in graph: verify against source code
|
|
469
|
+
- [ ] 4. For each aspect: verify the pattern holds in THIS node. If it deviates, add \`exceptions\` to the aspect entry in \`yg-node.yaml\`
|
|
470
|
+
- [ ] 5. Report inconsistencies
|
|
471
|
+
|
|
472
|
+
**Step 2 — Completeness** (catches MISSING information):
|
|
473
|
+
|
|
474
|
+
- [ ] 1. For each public method: is it in \`interface.md\`?
|
|
475
|
+
- [ ] 2. For each error path: is it in \`interface.md\` (Failure Modes section)?
|
|
476
|
+
- [ ] 3. For each behavioral invariant: is it in the graph?
|
|
477
|
+
- [ ] 4. Report omissions separately from inconsistencies
|
|
478
|
+
|
|
479
|
+
### Error Recovery
|
|
480
|
+
|
|
481
|
+
- **\`yg\` not found** → inform user: "yg CLI is not installed or not in PATH." Stop.
|
|
482
|
+
- **Unfixable validate errors** → if not resolved after 3 attempts, stop and report to user. Do not loop.
|
|
483
|
+
- **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.
|
|
484
|
+
- **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.
|
|
485
|
+
- **Corrupted \`.yggdrasil/\` files** → report to user. Do not attempt repair.
|
|
486
|
+
- **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.
|
|
487
|
+
|
|
488
|
+
### Escape Hatch
|
|
489
|
+
|
|
490
|
+
If the user explicitly requests a code-only change, comply but:
|
|
491
|
+
|
|
492
|
+
- Warn: "This creates drift. Run \`yg drift\` next session to reconcile."
|
|
493
|
+
- Do NOT run \`yg drift-sync\` — leave the drift visible.
|
|
494
|
+
|
|
495
|
+
### Environment Check
|
|
496
|
+
|
|
497
|
+
Before preflight:
|
|
498
|
+
|
|
499
|
+
- Verify \`yg\` CLI is available. If not found, inform user and stop.
|
|
500
|
+
- If \`yg preflight\` shows 0 nodes → enter BOOTSTRAP MODE (see above).
|
|
501
|
+
- If drift report shows >10 drifted nodes → report scope to user, ask which area to prioritize. Do not resolve all at once.
|
|
502
|
+
|
|
503
|
+
<critical_protocol>
|
|
504
|
+
BEFORE reading, analyzing, or modifying ANY source file:
|
|
505
|
+
\`yg build-context --file <path>\`
|
|
506
|
+
One command. No exceptions. No "I'll do it later." No "this is just analysis."
|
|
507
|
+
</critical_protocol>`;
|
|
508
|
+
|
|
509
|
+
export const AGENT_RULES_CONTENT = [PROTOCOL, REFERENCE, GUARD_RAILS].join('\n\n---\n\n') + '\n';
|