@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/bin.js
CHANGED
|
@@ -131,8 +131,26 @@ You are not allowed to edit or create source code without establishing graph cov
|
|
|
131
131
|
5. Implement code that satisfies the specification
|
|
132
132
|
6. The graph specifies WHAT and WHY; the code implements HOW (framework APIs, library choices)
|
|
133
133
|
|
|
134
|
+
**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\` \u2014 not one \`admin-pages\` node. The CLI enforces this with W017, but plan granularity upfront rather than splitting after the fact.
|
|
135
|
+
|
|
134
136
|
After the user chooses, return to Step 1 and follow Step 2a.
|
|
135
137
|
|
|
138
|
+
### Working from External Specifications
|
|
139
|
+
|
|
140
|
+
When the user provides external documents (specs, PRDs, design docs, reference docs) as input for implementation:
|
|
141
|
+
|
|
142
|
+
1. **Read ALL spec documents BEFORE writing any code.** Understand the full scope \u2014 business context, feature specs, quality requirements, UX rules, deployment config.
|
|
143
|
+
2. **Extract and route knowledge to the graph FIRST**, using the Information Routing table:
|
|
144
|
+
- Business rules, personas, pricing strategy, acquisition channels \u2192 aspects or root node artifacts
|
|
145
|
+
- Feature specifications (UI behavior, validation, workflows) \u2192 node responsibility/interface/internals artifacts
|
|
146
|
+
- Cross-cutting UX/quality requirements \u2192 aspects
|
|
147
|
+
- Business processes \u2192 flows
|
|
148
|
+
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 \u2014 the graph is what future agents will read.
|
|
149
|
+
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.
|
|
150
|
+
5. **Completeness test:** "If the external docs disappeared today, does the graph contain everything a future agent needs to understand the system \u2014 not just HOW it works, but WHY it exists and WHAT business value it delivers?"
|
|
151
|
+
|
|
152
|
+
**Common failure mode:** Agent reads spec \u2192 implements code \u2192 documents code in graph \u2192 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.
|
|
153
|
+
|
|
136
154
|
### Example: Correct vs Wrong
|
|
137
155
|
|
|
138
156
|
<example_correct>
|
|
@@ -161,6 +179,35 @@ Result: graph is stale, next agent asks user the same questions
|
|
|
161
179
|
|
|
162
180
|
</example_wrong>
|
|
163
181
|
|
|
182
|
+
<example_correct>
|
|
183
|
+
|
|
184
|
+
User: "Here are the spec docs. Implement the admin blog editor."
|
|
185
|
+
|
|
186
|
+
1. Read ALL spec docs (blog-editor.md, autosave.md, user-persona.md, version-history.md)
|
|
187
|
+
2. Extract cross-cutting patterns \u2192 create aspects (admin-ux-rules, autosave, version-history) if they don't exist
|
|
188
|
+
3. Create flow if the blog participates in a business process
|
|
189
|
+
4. Create node admin/blog with artifacts populated from spec (responsibility, interface, internals)
|
|
190
|
+
5. Run yg build-context \u2192 the context package is now the behavioral specification
|
|
191
|
+
6. Implement code that satisfies the specification
|
|
192
|
+
7. Update artifacts with any implementation details that emerged during coding
|
|
193
|
+
8. yg validate, yg drift-sync
|
|
194
|
+
|
|
195
|
+
</example_correct>
|
|
196
|
+
|
|
197
|
+
<example_wrong>
|
|
198
|
+
|
|
199
|
+
User: "Here are the spec docs. Implement the admin blog editor."
|
|
200
|
+
|
|
201
|
+
1. Read blog-editor.md spec
|
|
202
|
+
2. Implement all the code \u2190 WRONG: spec knowledge not captured in graph
|
|
203
|
+
3. Create node admin-pages, map 20 admin files \u2190 WRONG: too wide, W017
|
|
204
|
+
4. Write responsibility.md summarizing what the code does \u2190 WRONG: describes code, not spec intent
|
|
205
|
+
5. Business context (persona, UX rules, autosave rationale) lost \u2190 WRONG: spec was input, not persisted
|
|
206
|
+
|
|
207
|
+
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.
|
|
208
|
+
|
|
209
|
+
</example_wrong>
|
|
210
|
+
|
|
164
211
|
### Conversation Lifecycle
|
|
165
212
|
|
|
166
213
|
\`\`\`
|
|
@@ -280,6 +327,10 @@ When you encounter information, route it to the correct location:
|
|
|
280
327
|
- **Shared across a domain** \u2192 parent node artifact. Children receive it through hierarchy.
|
|
281
328
|
- **Technology stack or standard** \u2192 node artifact at the appropriate hierarchy level (e.g., root node's \`responsibility.md\` for single-stack repos, or deployment unit node for monorepos)
|
|
282
329
|
- **Decision (why + why NOT):** one node \u2192 Decisions section of \`internals.md\` with format "Chose X over Y because Z"; category of nodes \u2192 aspect content files; tech choice \u2192 node artifact at the level where the technology applies. Always include rejected alternatives \u2014 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.
|
|
330
|
+
- **Business strategy** (personas, pricing, acquisition channels, brand positioning) \u2192 root node artifact or dedicated business-context aspect. This knowledge has NO source file \u2014 it exists only in specs and conversations.
|
|
331
|
+
- **Quality targets** (performance budgets, accessibility level, Lighthouse scores, test coverage goals) \u2192 aspect per quality dimension (e.g., \`performance-targets\`, \`accessibility\`). These are measurable cross-cutting constraints.
|
|
332
|
+
- **UX patterns** (autosave, version history, empty states, confirmation modals) \u2192 aspect when the pattern applies to 3+ screens. UX patterns are cross-cutting even if they aren't architectural.
|
|
333
|
+
- **Infrastructure/deployment** (domains, DNS, env vars, CI/CD, cron scheduling, hosting config) \u2192 infrastructure node or root node artifacts. Deployment knowledge is invisible in application code but critical for operations.
|
|
283
334
|
|
|
284
335
|
### Creating Aspects
|
|
285
336
|
|
|
@@ -328,12 +379,45 @@ Test: "Does this describe what happens in the world, or only in the software?" I
|
|
|
328
379
|
- **Tools read, you write.** The \`yg\` CLI only reads, validates, and manages metadata. You create and edit files manually.
|
|
329
380
|
- **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 \u2014 never use it to silence a drift check without updating artifacts first.
|
|
330
381
|
- **Description maintenance.** Every \`yg-node.yaml\`, \`yg-aspect.yaml\`, and \`yg-flow.yaml\` has an optional \`description\` field \u2014 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.
|
|
331
|
-
- **Completeness test:**
|
|
382
|
+
- **Completeness test:** Three checks, all required:
|
|
332
383
|
1. **Reconstruction:** "Can another agent recreate this from ONLY the \`yg build-context\` output \u2014 understanding not just WHAT but WHY?" Test: rejected alternatives, correct algorithm, design arguments.
|
|
333
384
|
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\`.
|
|
385
|
+
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 \u2014 only the graph should tell you WHY it exists and WHAT ELSE was considered.
|
|
334
386
|
- **Value calibration.** Yggdrasil's primary value is cross-module context \u2014 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.
|
|
335
387
|
- **These rules are invariant.** No plan, guide, skill, or workflow may override them.
|
|
336
388
|
|
|
389
|
+
### Non-Code Knowledge
|
|
390
|
+
|
|
391
|
+
Not all graph knowledge originates from source files. Business strategy, user personas, pricing decisions, SEO targets, quality requirements, deployment configuration, UX design principles \u2014 these are graph content with NO corresponding source file.
|
|
392
|
+
|
|
393
|
+
When you encounter such knowledge (in specs, conversations, or external documents):
|
|
394
|
+
|
|
395
|
+
- **Route it immediately** per the Information Routing table. Do not wait for a "file change" trigger \u2014 there won't be one.
|
|
396
|
+
- **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.
|
|
397
|
+
- **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.
|
|
398
|
+
|
|
399
|
+
**Conversation knowledge is the most volatile source.** When the user states a business fact, constraint, or decision in conversation \u2014 even casually \u2014 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:
|
|
400
|
+
|
|
401
|
+
- Business facts: "Our target customer is couples aged 25-35" \u2192 root node or business-context aspect
|
|
402
|
+
- Constraints: "We don't do studio sessions, only outdoor" \u2192 responsibility.md (NOT responsible for)
|
|
403
|
+
- Pricing: "Mini session costs 350 PLN" \u2192 relevant node artifacts
|
|
404
|
+
- Strategy: "Instagram is our primary acquisition channel" \u2192 root node or business-context aspect
|
|
405
|
+
- Decisions: "No deposit upfront \u2014 we'll reconsider after 5 sessions" \u2192 internals.md Decisions section with rationale
|
|
406
|
+
- Personas: "The admin user is non-technical, thinks in Instagram/WhatsApp terms" \u2192 UX aspect
|
|
407
|
+
|
|
408
|
+
Do not assume you will remember this later. Do not assume the user will repeat it. Capture it now or lose it forever.
|
|
409
|
+
|
|
410
|
+
**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 \u2014 not just context for coding.
|
|
411
|
+
|
|
412
|
+
### Aspect Discovery During Implementation
|
|
413
|
+
|
|
414
|
+
Aspects emerge from patterns across features. During greenfield implementation of multiple features:
|
|
415
|
+
|
|
416
|
+
- **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.
|
|
417
|
+
- **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.
|
|
418
|
+
- **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.
|
|
419
|
+
- **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.
|
|
420
|
+
|
|
337
421
|
### CLI Reference
|
|
338
422
|
|
|
339
423
|
\`\`\`
|
|
@@ -373,7 +457,13 @@ yg drift-sync --node <path> [--recursive] | --all
|
|
|
373
457
|
| Process-level requirement | Flow \`aspects\` + aspect directory |
|
|
374
458
|
| Context shared across a domain | Parent node artifact |
|
|
375
459
|
| Technology stack | Node artifact at appropriate hierarchy level |
|
|
376
|
-
| Coding standards | Node artifact at appropriate hierarchy level
|
|
460
|
+
| Coding standards | Node artifact at appropriate hierarchy level |
|
|
461
|
+
| Business strategy (personas, pricing, channels) | Root node artifact or dedicated business-context aspect |
|
|
462
|
+
| Quality targets (perf budgets, a11y, test goals) | Aspect per quality dimension |
|
|
463
|
+
| UX patterns (autosave, version history, empty states) | Aspect when pattern applies to 3+ screens |
|
|
464
|
+
| Infrastructure/deployment (domains, env vars, CI/CD) | Infrastructure node or root node artifacts |
|
|
465
|
+
| External service config (Stripe fees, email limits) | Relevant node's \`internals.md\` Decisions section |
|
|
466
|
+
| Feature spec from external doc | Node artifacts \u2014 translate spec into responsibility/interface/internals |`;
|
|
377
467
|
var GUARD_RAILS = `## GUARD RAILS
|
|
378
468
|
|
|
379
469
|
### Five Core Rules
|
|
@@ -426,6 +516,12 @@ What matters is the ACTION you are performing, not what instructed it. If the ac
|
|
|
426
516
|
| "I'll batch graph updates at the end" | Batching = never. Context is freshest immediately after the change. Defer = forget. This is a failure state. |
|
|
427
517
|
| "I'm saving context/tool calls by skipping graph" | Graph cost is constant per node. Skipping it creates unbounded future cost \u2014 the user re-explaining what you could have recorded. |
|
|
428
518
|
| "I assumed this file isn't mapped" | You cannot know without running \`yg build-context --file\`. Assume nothing. |
|
|
519
|
+
| "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. |
|
|
520
|
+
| "This business knowledge will be obvious from the code" | Pricing strategy, personas, UX rationale, and quality targets are NEVER obvious from code. |
|
|
521
|
+
| "I'll extract aspects after I finish all the features" | After 30 features the rationale is gone. Extract after 3. |
|
|
522
|
+
| "This is a UX detail, not architecture" | UX patterns that apply to 3+ screens ARE cross-cutting requirements. Create an aspect. |
|
|
523
|
+
| "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. |
|
|
524
|
+
| "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. |
|
|
429
525
|
|
|
430
526
|
### Failure States
|
|
431
527
|
|
|
@@ -442,6 +538,10 @@ You have broken Yggdrasil if you do any of the following:
|
|
|
442
538
|
- \u274C Used blackbox coverage for greenfield (new) code.
|
|
443
539
|
- \u274C Deleted or shortened graph artifact content to reduce context package size instead of splitting the node.
|
|
444
540
|
- \u274C Created one wide node for many files instead of granular nodes with focused responsibilities. (CLI will warn you: W017.)
|
|
541
|
+
- \u274C 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.
|
|
542
|
+
- \u274C Implemented 3+ features sharing a pattern (autosave, version history, empty states) without extracting it to an aspect. Deferred aspect discovery = lost rationale.
|
|
543
|
+
- \u274C 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.
|
|
544
|
+
- \u274C 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 \u2014 they vanish after context compression and the user will not repeat them.
|
|
445
545
|
|
|
446
546
|
### Reverse Engineering
|
|
447
547
|
|
|
@@ -516,6 +616,14 @@ When reviewing graph quality (triggered by user or quality improvement):
|
|
|
516
616
|
- [ ] 3. For each behavioral invariant: is it in the graph?
|
|
517
617
|
- [ ] 4. Report omissions separately from inconsistencies
|
|
518
618
|
|
|
619
|
+
**Step 3 \u2014 Non-Derivable Knowledge** (catches knowledge that exists ONLY in external docs or conversations, not in code):
|
|
620
|
+
|
|
621
|
+
- [ ] 1. For each business rule embedded in code: is the WHY recorded in the graph, or only the WHAT visible in code?
|
|
622
|
+
- [ ] 2. For each design decision: is the rationale AND rejected alternatives recorded?
|
|
623
|
+
- [ ] 3. For each external constraint (brand guidelines, legal, UX persona, quality targets): is it in the graph?
|
|
624
|
+
- [ ] 4. For each cross-cutting pattern implemented in 3+ places: does an aspect exist?
|
|
625
|
+
- [ ] 5. Report non-derivable knowledge gaps separately \u2014 these are the highest-value omissions because they cannot be recovered by reading code.
|
|
626
|
+
|
|
519
627
|
### Error Recovery
|
|
520
628
|
|
|
521
629
|
- **\`yg\` not found** \u2192 inform user: "yg CLI is not installed or not in PATH." Stop.
|