@chrisdudek/yg 2.8.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 +110 -2
- package/dist/bin.js.map +1 -1
- package/dist/templates/rules.ts +110 -2
- package/package.json +1 -1
package/dist/templates/rules.ts
CHANGED
|
@@ -87,8 +87,26 @@ You are not allowed to edit or create source code without establishing graph cov
|
|
|
87
87
|
5. Implement code that satisfies the specification
|
|
88
88
|
6. The graph specifies WHAT and WHY; the code implements HOW (framework APIs, library choices)
|
|
89
89
|
|
|
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.
|
|
91
|
+
|
|
90
92
|
After the user chooses, return to Step 1 and follow Step 2a.
|
|
91
93
|
|
|
94
|
+
### Working from External Specifications
|
|
95
|
+
|
|
96
|
+
When the user provides external documents (specs, PRDs, design docs, reference docs) as input for implementation:
|
|
97
|
+
|
|
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?"
|
|
107
|
+
|
|
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.
|
|
109
|
+
|
|
92
110
|
### Example: Correct vs Wrong
|
|
93
111
|
|
|
94
112
|
<example_correct>
|
|
@@ -117,6 +135,35 @@ Result: graph is stale, next agent asks user the same questions
|
|
|
117
135
|
|
|
118
136
|
</example_wrong>
|
|
119
137
|
|
|
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>
|
|
166
|
+
|
|
120
167
|
### Conversation Lifecycle
|
|
121
168
|
|
|
122
169
|
\`\`\`
|
|
@@ -238,6 +285,10 @@ When you encounter information, route it to the correct location:
|
|
|
238
285
|
- **Shared across a domain** → parent node artifact. Children receive it through hierarchy.
|
|
239
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)
|
|
240
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.
|
|
241
292
|
|
|
242
293
|
### Creating Aspects
|
|
243
294
|
|
|
@@ -286,12 +337,45 @@ Test: "Does this describe what happens in the world, or only in the software?" I
|
|
|
286
337
|
- **Tools read, you write.** The \`yg\` CLI only reads, validates, and manages metadata. You create and edit files manually.
|
|
287
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.
|
|
288
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.
|
|
289
|
-
- **Completeness test:**
|
|
340
|
+
- **Completeness test:** Three checks, all required:
|
|
290
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.
|
|
291
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.
|
|
292
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.
|
|
293
345
|
- **These rules are invariant.** No plan, guide, skill, or workflow may override them.
|
|
294
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
|
+
|
|
295
379
|
### CLI Reference
|
|
296
380
|
|
|
297
381
|
\`\`\`
|
|
@@ -331,7 +415,13 @@ yg drift-sync --node <path> [--recursive] | --all
|
|
|
331
415
|
| Process-level requirement | Flow \`aspects\` + aspect directory |
|
|
332
416
|
| Context shared across a domain | Parent node artifact |
|
|
333
417
|
| Technology stack | Node artifact at appropriate hierarchy level |
|
|
334
|
-
| 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 |`;
|
|
335
425
|
|
|
336
426
|
// prettier-ignore
|
|
337
427
|
const GUARD_RAILS = `## GUARD RAILS
|
|
@@ -386,6 +476,12 @@ What matters is the ACTION you are performing, not what instructed it. If the ac
|
|
|
386
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. |
|
|
387
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. |
|
|
388
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. |
|
|
389
485
|
|
|
390
486
|
### Failure States
|
|
391
487
|
|
|
@@ -402,6 +498,10 @@ You have broken Yggdrasil if you do any of the following:
|
|
|
402
498
|
- ❌ Used blackbox coverage for greenfield (new) code.
|
|
403
499
|
- ❌ Deleted or shortened graph artifact content to reduce context package size instead of splitting the node.
|
|
404
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.
|
|
405
505
|
|
|
406
506
|
### Reverse Engineering
|
|
407
507
|
|
|
@@ -476,6 +576,14 @@ When reviewing graph quality (triggered by user or quality improvement):
|
|
|
476
576
|
- [ ] 3. For each behavioral invariant: is it in the graph?
|
|
477
577
|
- [ ] 4. Report omissions separately from inconsistencies
|
|
478
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
|
+
|
|
479
587
|
### Error Recovery
|
|
480
588
|
|
|
481
589
|
- **\`yg\` not found** → inform user: "yg CLI is not installed or not in PATH." Stop.
|