@chrisdudek/yg 2.11.0 → 3.0.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.
@@ -1,4 +1,4 @@
1
- export const DEFAULT_CONFIG = `version: "2.0.0"
1
+ export const DEFAULT_CONFIG = `version: "3.0.0"
2
2
 
3
3
  name: ""
4
4
 
@@ -12,20 +12,6 @@ node_types:
12
12
  infrastructure:
13
13
  description: "Guards, middleware, interceptors — invisible in call graphs but affect blast radius"
14
14
 
15
- artifacts:
16
- responsibility.md:
17
- required: always
18
- description: "What this node is responsible for, and what it is not"
19
- included_in_relations: true
20
- interface.md:
21
- required:
22
- when: has_incoming_relations
23
- description: "Public API — methods, parameters, return types, contracts, failure modes, exposed data structures"
24
- included_in_relations: true
25
- internals.md:
26
- required: never
27
- description: "How the node works and why — algorithms, business rules, state machines, design decisions with rejected alternatives"
28
-
29
15
  quality:
30
16
  min_artifact_length: 50
31
17
  max_direct_relations: 10
@@ -15,11 +15,32 @@ const PROTOCOL = `## PROTOCOL
15
15
  This is your operating manual for working in a Yggdrasil-managed repository.
16
16
 
17
17
  <critical_protocol>
18
+ BEFORE starting any task — brainstorming, design, planning, OR implementation:
19
+ \`yg select --task "<goal>"\` → \`yg build-context\` on each result → read artifact files.
20
+ This is the READING phase — collect constraints that shape your design:
21
+ - Aspects = cross-cutting requirements your work MUST satisfy. Read their content files — not just the YAML description. The rules are inside.
22
+ - Flows = business processes your work must not break. Read invariants.
23
+ - Relations = interfaces your code consumes or that consume your code. Changes without checking dependents break contracts silently.
24
+ - Parent artifacts = inherited context not repeated in child nodes.
25
+ Internalize these constraints BEFORE designing your approach. This is the moment that determines quality — everything after follows from what you learn here.
26
+
18
27
  BEFORE reading, analyzing, or modifying ANY source file:
19
28
  \`yg build-context --file <path>\`
20
- One command. No exceptions. No "I'll do it later." No "this is just analysis."
21
-
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.
29
+ Resolves owner, gives you local context (node artifacts, dependencies).
30
+ If you have NOT done the task-level READING phase above — stop and do it now. File-level work without task-level constraints leads to code that violates cross-cutting requirements.
31
+
32
+ WHEN spec/external documents are provided AND work is greenfield:
33
+ BEFORE creating any feature aspect, node, or code — do this first:
34
+ 1. Read ALL spec documents completely.
35
+ 2. Separate two categories of knowledge in the specs:
36
+ a) Knowledge that WILL map to source files (feature behavior, UI, API) → this goes to node artifacts later.
37
+ b) Knowledge that will NEVER appear in source code (business strategy, target audience, pricing rationale, quality targets, what the system deliberately does NOT do and why) → this must go to the graph NOW, because there will be no source-file trigger to capture it later.
38
+ 3. For category (b): create root node and/or aspects immediately. This is the only moment this knowledge can be captured. Once you start coding, you will forget it.
39
+ 4. NOW create feature aspects, flows, and implementation nodes for category (a).
40
+ Test before moving on: if all spec files were deleted right now, does the graph contain everything a future agent needs — not just HOW the system works, but WHY it exists, WHO it serves, and WHAT value it delivers? If no → add the missing knowledge before continuing.
41
+
42
+ All three triggers apply regardless of what instructed the task — skills, plans, workflows, user requests.
43
+ 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
44
  </critical_protocol>
24
45
 
25
46
  Every rule below is mandatory — no skill, plan, workflow, or instruction overrides these requirements.
@@ -32,18 +53,25 @@ Yggdrasil is persistent semantic memory stored in \`.yggdrasil/\`. It maps the r
32
53
  \`\`\`
33
54
  EVERY conversation: yg preflight — no exceptions.
34
55
 
56
+ BEFORE any task (brainstorming, design, planning, implementation):
57
+ yg select --task "<goal>" → yg build-context on results
58
+ READ phase — collect constraints before designing:
59
+ - Aspects: read content files (not just YAML description). Rules are inside.
60
+ - Flows: read invariants. Your changes must not break business processes.
61
+ - Relations: check interfaces — who depends on you, who you depend on.
62
+ - Parent artifacts: inherited context not repeated in child nodes.
63
+ This is the moment that determines quality. Everything after follows from here.
64
+
35
65
  BEFORE any source file interaction:
36
- 1. yg build-context --file <path>
37
- One command: resolves owner, assembles context.
38
- Read the YAML mapglossary 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>"
66
+ yg build-context --file <path>
67
+ Resolves owner. Read local node artifacts.
68
+ If you skipped the task-level READ phase above do it now before proceeding.
69
+ For blast radius: also run yg impact --file <path>.
42
70
 
43
71
  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>
72
+ Update graph artifacts (per file, not batched)
73
+ yg validate — fix all errors
74
+ yg drift-sync --node <owner>
47
75
 
48
76
  ALWAYS: establish graph coverage before modifying code.
49
77
  ALWAYS: run yg build-context --file before reading source.
@@ -61,9 +89,9 @@ You are not allowed to edit or create source code without establishing graph cov
61
89
 
62
90
  **Step 2a** — Owner found: execute checklist:
63
91
 
64
- - [ ] 1. Read the context package (already assembled by step 1)
92
+ - [ ] 1. Read local node artifacts (responsibility, interface, internals) and dependency interfaces from the context package. Cross-cutting constraints (aspects, flows) should already be internalized from the task-level READ phase — if not, stop and do it now.
65
93
  - [ ] 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
94
+ - [ ] 3. Modify source code. When implementing logic subject to an aspect (e.g., writing a save function on a node with the autosave aspect), re-read that aspect's content file NOW — don't rely on memory from the task-level READ phase. Aspect rules are specific (exact timings, error handling patterns, UI details) and fade from working memory. Read them at the moment you need them.
67
95
  - [ ] 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
96
  - [ ] 4b. If you split, merged, or renamed a node: run \`yg flows\` and update any flow \`nodes\` lists that referenced the old node path to point to the correct child/new nodes.
69
97
  - [ ] 5. Run \`yg validate\` — fix all errors (if unfixable after 3 attempts → stop, report to user)
@@ -81,12 +109,14 @@ You are not allowed to edit or create source code without establishing graph cov
81
109
 
82
110
  *Greenfield (new code):* Only Option A. Blackbox is forbidden for new code. Follow the graph-first workflow:
83
111
 
112
+ 0. **If spec/external documents exist:** route ALL knowledge from specs to the graph per the Information Routing table BEFORE any feature work. Use the appropriate location for each piece of knowledge — root node, aspects, flows, or node artifacts depending on its nature.
84
113
  1. Create aspects first (cross-cutting requirements the new code must satisfy)
85
114
  2. Create flows if the code participates in a business process
86
115
  3. Create nodes with full artifacts — description in \`yg-node.yaml\`, responsibility, interface, internals
87
116
  4. Review the context package (\`yg build-context\`) — it is now the behavioral specification
88
- 5. Implement code that satisfies the specification
89
- 6. The graph specifies WHAT and WHY; the code implements HOW (framework APIs, library choices)
117
+ 5. Implement code that satisfies the specification. Every source file must be mapped — including shared utilities, types, and helpers.
118
+ 6. After implementing each node, write \`internals.md\` with a ## Decisions section. Record every design choice: "Chose X over Y because Z." This is required in greenfield — not optional. Every node has design decisions (data model shape, algorithm, library, UI pattern). If you made a choice between alternatives, document it now — you will not remember later.
119
+ 7. The graph specifies WHAT and WHY; the code implements HOW (framework APIs, library choices)
90
120
 
91
121
  **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.
92
122
 
@@ -141,13 +171,15 @@ Result: graph is stale, next agent asks user the same questions
141
171
  User: "Here are the spec docs. Implement the admin blog editor."
142
172
 
143
173
  1. Read ALL spec docs (blog-editor.md, autosave.md, user-persona.md, version-history.md)
144
- 2. Extract cross-cutting patterns create aspects (admin-ux-rules, autosave, version-history) if they don't exist
145
- 3. Create flow if the blog participates in a business process
146
- 4. Create node admin/blog with artifacts populated from spec (responsibility, interface, internals)
147
- 5. Run yg build-context the context package is now the behavioral specification
148
- 6. Implement code that satisfies the specification
149
- 7. Update artifacts with any implementation details that emerged during coding
150
- 8. yg validate, yg drift-sync
174
+ 2. Route all knowledge from spec docs to the graph per Information Routing table — business context to root node artifacts, cross-cutting requirements to aspects, business processes to flows, feature specs to node artifacts
175
+ 3. Extract cross-cutting patterns create aspects (admin-ux-rules, autosave, version-history) if they don't exist
176
+ 4. Create flow if the blog participates in a business process
177
+ 5. Create node admin/blog with artifacts populated from spec (responsibility, interface, internals)
178
+ 6. Run yg build-context the context package is now the behavioral specification
179
+ 7. Implement code that satisfies the specification
180
+ 8. Update artifacts with any implementation details that emerged during coding
181
+ 9. yg validate, yg drift-sync
182
+ Test: if spec files disappeared today, does the graph contain everything a future agent needs to understand the system?
151
183
 
152
184
  </example_correct>
153
185
 
@@ -155,13 +187,36 @@ User: "Here are the spec docs. Implement the admin blog editor."
155
187
 
156
188
  User: "Here are the spec docs. Implement the admin blog editor."
157
189
 
158
- 1. Read blog-editor.md spec
159
- 2. Implement all the codeWRONG: spec knowledge not captured in graph
160
- 3. Create node admin-pages, map 20 admin files ← WRONG: too wide, W017
190
+ 1. Read spec docs
191
+ 2. Create aspects and flow for the blog feature INCOMPLETE: knowledge from spec docs not routed to graph per Information Routing table
192
+ 3. Create node admin/blog, implement code
161
193
  4. Write responsibility.md summarizing what the code does ← WRONG: describes code, not spec intent
162
- 5. Business context (persona, UX rules, autosave rationale) lost ← WRONG: spec was input, not persisted
194
+ 5. Knowledge from spec docs lost ← WRONG: spec treated as consumed input, not persisted to graph
195
+
196
+ Result: graph mirrors code structure but misses everything spec docs contained that has no corresponding source file. Future agent must re-read spec files or ask the user.
197
+
198
+ </example_wrong>
199
+
200
+ <example_correct>
163
201
 
164
- 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.
202
+ User: "Let's design a soft delete feature for blog posts"
203
+
204
+ 1. yg select --task "blog soft delete" → find relevant nodes
205
+ 2. yg build-context on each result → read ALL artifacts (aspects, flows, conventions)
206
+ 3. Now read source files WITH graph context
207
+ 4. Propose design informed by admin-ux-rules, existing flows, database conventions
208
+
209
+ </example_correct>
210
+
211
+ <example_wrong>
212
+
213
+ User: "Let's design a soft delete feature for blog posts"
214
+
215
+ 1. Read BlogEditor.tsx to understand current behavior ← WRONG: no graph context
216
+ 2. Read database schema ← WRONG: graph has conventions, aspects, flows
217
+ 3. Propose design based on raw code ← WRONG: missed admin-ux-rules aspect, existing flows
218
+
219
+ Result: design misses cross-cutting requirements the graph already captured.
165
220
 
166
221
  </example_wrong>
167
222
 
@@ -227,7 +282,7 @@ const REFERENCE = `## REFERENCE
227
282
 
228
283
  \`\`\`
229
284
  .yggdrasil/
230
- yg-config.yaml ← version, vocabulary, node types, artifact rules, required aspects
285
+ yg-config.yaml ← version, vocabulary, node types, required aspects
231
286
  model/ ← what exists: nodes, hierarchy, relations, file mappings
232
287
  aspects/ ← what must: cross-cutting requirements with rationale and guidance
233
288
  flows/ ← why and in what process: business processes with node participation
@@ -253,7 +308,7 @@ Three artifacts capture node knowledge at three levels:
253
308
 
254
309
  **Enrichment priority (when adding incrementally):** \`interface.md\` first (highest cross-module ROI — contracts enable other nodes to reason about interactions), then \`responsibility.md\` (identity and boundaries), then \`internals.md\` (depth for complex nodes). A node with only \`interface.md\` provides more cross-module value than one with only \`internals.md\`.
255
310
 
256
- Projects can define additional artifact types in \`yg-config.yaml\` under \`artifacts\`. Each custom artifact has a \`description\` (tells you what to write), a \`required\` condition (\`always\`, \`never\`, \`when: has_incoming_relations\`, \`when: has_aspect:<id>\`), and an \`included_in_relations\` flag (if true, included in dependency context packages for structural relations). The three standard artifacts are always present in config. Check \`yg-config.yaml\` to see all defined artifacts for the project.
311
+ These three artifacts are built into the CLI and are not configurable. \`responsibility.md\` is always required, \`interface.md\` is required when the node has incoming relations, and \`internals.md\` is always optional.
257
312
 
258
313
  ### Context Assembly
259
314
 
@@ -268,9 +323,14 @@ Projects can define additional artifact types in \`yg-config.yaml\` under \`arti
268
323
 
269
324
  All artifact paths are relative to \`.yggdrasil/\` — construct full path as \`.yggdrasil/<path>\`.
270
325
 
271
- **Default mode (paths-only):** Use for all graph operations. Read the YAML map first — start with the \`glossary\` to understand aspects and flows, then the \`node\` section for the target. Read artifact files inline on each element using the Read tool. For quick orientation (scoping, blast radius assessment), the map alone is sufficient. For implementation or modification, read all artifact files before changing code.
326
+ **Default mode (paths-only):** Use for all graph operations. Read the YAML map, then read artifact files with purpose:
327
+
328
+ 1. **Glossary first** — defines aspects and flows. Aspects are constraints your implementation must satisfy (not background reading). Flows are business processes whose invariants you must not break.
329
+ 2. **Node section** — your target's own artifacts. Read before modifying.
330
+ 3. **Hierarchy** — parent artifacts contain inherited requirements not repeated in child nodes.
331
+ 4. **Dependencies** — interfaces you consume or that consume you. Read before changing contracts.
272
332
 
273
- The glossary at the top defines all aspects and flowsread it first to understand IDs used throughout.
333
+ A typical context package is ~8K tokens (less than a single source file). Read ALL artifact files listed the cost is low, the risk of skipping is high (violating constraints you didn't know about).
274
334
 
275
335
  **Full mode (\`--full\`):** Use only when you cannot read files individually — e.g., when pasting context into a prompt, sharing with a user, or when you have no Read tool available.
276
336
 
@@ -280,7 +340,7 @@ Artifact paths are stable identifiers within a session. When building context fo
280
340
 
281
341
  When you encounter information, route it to the correct location:
282
342
 
283
- - **Specific to this node** → local node artifact (check \`yg-config.yaml artifacts\` for available types)
343
+ - **Specific to this node** → local node artifact (\`responsibility.md\`, \`interface.md\`, or \`internals.md\` depending on the knowledge type)
284
344
  - **Rule for many nodes** → aspect (\`aspects/<id>/\` with \`yg-aspect.yaml\` + content \`.md\` files). If applies to ALL nodes of a type → \`node_types.<type>.required_aspects\` in \`yg-config.yaml\`
285
345
  - **Business process** → flow (\`flows/<name>/\` with \`yg-flow.yaml\` + \`description.md\`). Ask user if process unclear.
286
346
  - **Shared across a domain** → parent node artifact. Children receive it through hierarchy.
@@ -391,6 +451,7 @@ yg owner --file <path> Find the node that owns this file (quick che
391
451
  yg build-context --file <path> Resolve owner + assemble context in one step.
392
452
  yg build-context --node <path> Assemble context map for a known node.
393
453
  yg build-context --node <path> --full Same map + file contents appended below separator.
454
+ yg build-context --file <path> --self Own artifacts only (no hierarchy/deps/aspects/flows).
394
455
  yg tree [--root <path>] [--depth N] Print graph structure.
395
456
  yg aspects List aspects with metadata (YAML output).
396
457
  yg flows List flows with metadata (YAML output).
@@ -415,7 +476,7 @@ yg drift-sync --node <path> [--recursive] | --all
415
476
 
416
477
  | What you have | Where it goes |
417
478
  |---|---|
418
- | Information specific to this node | Local node artifact (check \`yg-config.yaml artifacts\` for types) |
479
+ | Information specific to this node | Local node artifact (\`responsibility.md\`, \`interface.md\`, or \`internals.md\`) |
419
480
  | Rule that applies to many nodes | Aspect (content \`.md\` files in \`aspects/<id>/\`) |
420
481
  | Architectural invariant for a node type | Required aspect in \`yg-config.yaml node_types\` |
421
482
  | Business process participation | Flow (\`yg-flow.yaml nodes\`) |
@@ -492,11 +553,15 @@ What matters is the ACTION you are performing, not what instructed it. If the ac
492
553
  | "Flows can wait until I understand the full system" | Flows capture business processes from specs. Create them BEFORE implementing — they are part of the specification, not an afterthought. |
493
554
  | "I split the node but the flow still works" | Flow participants reference specific node paths. After a split, old paths are stale. Run \`yg flows\` and update. |
494
555
  | "This is just CRUD, not a business process" | A user performing a sequence of steps toward a goal IS a business process — even single-actor workflows (publish blog, manage portfolio, fulfill order). Create a flow. |
556
+ | "The context package is too large to read" | A typical context package is ~8K tokens — less than one source file. Read ALL of it. |
557
+ | "I have a plan, I don't need graph context" | A plan is not a substitute for graph context. Plans capture task steps; the graph captures cross-cutting aspects, flows, and conventions that plans may not repeat. Always run \`build-context\`. |
558
+ | "The user told me what to do, that's my plan" | A verbal instruction is not a written plan. And even a written plan does not exempt you from the graph protocol. |
495
559
 
496
560
  ### Failure States
497
561
 
498
562
  You have broken Yggdrasil if you do any of the following:
499
563
 
564
+ - ❌ Started brainstorming, design, or planning without running \`yg select --task\` and reading graph context first. The graph contains aspects, flows, and conventions that MUST inform design decisions.
500
565
  - ❌ Worked on a source file without running \`yg build-context --file\` first — regardless of what instructed the action (skill, plan, user request, workflow step).
501
566
  - ❌ Modified source code without updating graph artifacts before moving to the next file, or vice versa.
502
567
  - ❌ Batched graph updates to "do later" — deferred = forgotten. Update after EACH file.
@@ -526,7 +591,7 @@ Per area checklist:
526
591
  - [ ] 2. Determine node granularity — propose to user if unclear
527
592
  - [ ] 3. Create node directory, read \`schemas/yg-node.yaml\`, create \`yg-node.yaml\`
528
593
  - [ ] 3b. Write \`description\` in \`yg-node.yaml\` — a short summary of what the node does
529
- - [ ] 4. Analyze source — for each artifact type in \`yg-config.yaml artifacts\`: extract content, do not invent
594
+ - [ ] 4. Analyze source — write \`responsibility.md\`, \`interface.md\`, and \`internals.md\` from code analysis, do not invent
530
595
  - [ ] 5. Identify relations — add to \`yg-node.yaml\`
531
596
  - [ ] 6. Identify cross-cutting requirements — add matching aspects, create if needed
532
597
  - [ ] 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\`
@@ -2,7 +2,7 @@
2
2
  # Located at .yggdrasil/yg-config.yaml — one per project.
3
3
  # Edit this after running yg init to describe your project.
4
4
 
5
- version: "2.0.0" # managed by CLI — do not edit manually. Tracks the CLI version
5
+ version: "3.0.0" # managed by CLI — do not edit manually. Tracks the CLI version
6
6
  # that created or last migrated this config. Used by the migration
7
7
  # system to determine which migrations to run on upgrade.
8
8
 
@@ -17,17 +17,8 @@ node_types: # required — non-empty object of node type d
17
17
  library:
18
18
  description: "Shared utility code with no domain knowledge"
19
19
 
20
- artifacts: # required artifact type definitions
21
- responsibility.md: # key = filename in node directories
22
- required: always # always | never | { when: <condition> }
23
- description: "What this node is responsible for, and what it is not"
24
- included_in_relations: true # true = included in dependency context packages
25
- interface.md:
26
- required:
27
- when: has_incoming_relations # conditions: has_incoming_relations, has_outgoing_relations, has_aspect:<id>
28
- description: "Public API — methods, parameters, return types, contracts"
29
- included_in_relations: true
30
- # Additional artifact types: logic.md, constraints.md, errors.md, model.md, state.md, decisions.md
20
+ # artifacts are hardcoded in the CLI (responsibility.md, interface.md, internals.md)
21
+ # and cannot be configured. See STANDARD_ARTIFACTS in source code.
31
22
 
32
23
  quality: # optional — quality thresholds
33
24
  min_artifact_length: 50 # minimum characters for an artifact (warning if below)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chrisdudek/yg",
3
- "version": "2.11.0",
3
+ "version": "3.0.0",
4
4
  "description": "Make your repository self-aware. Persistent semantic memory and deterministic context assembly for AI agents.",
5
5
  "type": "module",
6
6
  "bin": {