@chrisdudek/yg 1.2.0 → 1.4.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.
@@ -10,6 +10,7 @@ node_types:
10
10
  - name: module
11
11
  - name: service
12
12
  - name: library
13
+ - name: infrastructure
13
14
 
14
15
  artifacts:
15
16
  responsibility.md:
@@ -19,29 +20,11 @@ artifacts:
19
20
  interface.md:
20
21
  required:
21
22
  when: has_incoming_relations
22
- description: "Public API — methods, parameters, return types, contracts"
23
+ description: "Public API — methods, parameters, return types, contracts, failure modes, exposed data structures"
23
24
  structural_context: true
24
- logic.md:
25
+ internals.md:
25
26
  required: never
26
- description: "Algorithmic flow, control flow, branching logic, decision trees the 'how' of execution"
27
- constraints.md:
28
- required: never
29
- description: "Validation rules, business rules, invariants"
30
- structural_context: true
31
- errors.md:
32
- required:
33
- when: has_incoming_relations
34
- description: "Failure modes, edge cases, error conditions, recovery behavior"
35
- structural_context: true
36
- model.md:
37
- required: never
38
- description: "Data structures, schemas, entities, type definitions — the shape of data this node owns or manages"
39
- state.md:
40
- required: never
41
- description: "State machines, lifecycle, transitions"
42
- decisions.md:
43
- required: never
44
- description: "Local design decisions and rationale — choices specific to this node, not system-wide"
27
+ description: "How the node works and why — algorithms, business rules, state machines, design decisions with rejected alternatives"
45
28
 
46
29
  quality:
47
30
  min_artifact_length: 50
@@ -19,11 +19,12 @@ Yggdrasil is persistent semantic memory stored in \`.yggdrasil/\`. It maps the r
19
19
  BEFORE reading, researching, planning, OR modifying ANY mapped file:
20
20
  1. yg owner --file <path>
21
21
  2. yg build-context --node <owner>
22
- The context package is your primary source of understanding.
23
- Raw file reads are for implementation details WITHIN a node you
24
- already understand from its context package.
22
+ The context package is your primary source of ARCHITECTURAL understanding:
23
+ intent, constraints, relations, rationale. For IMPLEMENTATION precision
24
+ (exact behavior, error handling, await patterns, edge cases) — verify
25
+ against source code. Aspects describe intended patterns; individual
26
+ implementations may deviate.
25
27
  If the context package seems insufficient — enrich the graph.
26
- Do not bypass it.
27
28
 
28
29
  AFTER modifying:
29
30
  3. Update graph artifacts to reflect changes
@@ -44,31 +45,42 @@ WHEN UNSURE: ask the user. Never guess. Never assume.
44
45
 
45
46
  ### Five Core Rules
46
47
 
47
- 1. **Graph first.** Before reading, researching, planning, or modifying mapped files, run \`yg owner\` and \`yg build-context\`. Always. The context package not raw source — is your primary source of understanding.
48
+ 1. **Graph first.** Before reading, researching, planning, or modifying mapped files, run \`yg owner\` and \`yg build-context\`. Always. The context package 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.
48
49
  2. **Code and graph are one.** Code changed → graph updated in the same response. Graph changed → source verified in the same response. No exceptions.
49
50
  3. **Never invent why.** The graph captures human intent. If you don't know why something was decided, ask. Never hallucinate rationale.
50
51
  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.
51
52
  5. **Ask before resolving ambiguity.** When multiple valid interpretations exist, stop, list options, ask the user. Never silently choose.
52
53
 
54
+ ### Recognizing Graph-Required Actions
55
+
56
+ What matters is the ACTION you are performing, not what instructed it. If the action involves understanding mapped code, the graph protocol applies — whether the instruction came from a skill, a plan, a user message, a workflow step, or your own initiative.
57
+
58
+ **Actions that require \`yg owner\` + \`yg build-context\` first:**
59
+
60
+ - Reading or exploring source files to understand a component
61
+ - Proposing approaches, designs, or plans for changing code
62
+ - Reviewing or debugging code
63
+ - Any form of reasoning about how mapped code works or should change
64
+
65
+ **Actions that do NOT require yg:**
66
+
67
+ - Git operations (log, diff, status, blame)
68
+ - Reading documentation, READMEs, or config files outside \`.yggdrasil/\`
69
+ - Running tests, builds, or linters
70
+ - Working with files that \`yg owner\` reports as unmapped
71
+
53
72
  ### Failure States
54
73
 
55
74
  You have broken Yggdrasil if you do any of the following:
56
75
 
57
- - ❌ Modified source code without running \`yg owner --file <path>\` first.
58
- - ❌ Modified source code without updating graph artifacts in the same response.
59
- - ❌ Modified graph files without verifying source code alignment in the same response.
60
- - ❌ Resolved a code-graph inconsistency without asking the user first.
76
+ - ❌ Worked on a mapped file without running \`yg owner\` + \`yg build-context\` first — regardless of what instructed the action (skill, plan, user request, workflow step).
77
+ - ❌ Modified source code without updating graph artifacts in the same response, or vice versa.
78
+ - ❌ Resolved a code-graph inconsistency or ambiguity without asking the user first.
61
79
  - ❌ Created or edited a graph element without reading its schema in \`schemas/\` first.
62
- - ❌ Ran \`yg drift-sync\` before updating graph artifacts.
63
- - ❌ Wrote a flow description that describes code sequences instead of a business process.
64
- - ❌ Used an aspect identifier that has no corresponding \`aspects/\` directory.
65
- - ❌ Placed a cross-cutting requirement in a local node artifact instead of an aspect.
66
- - ❌ Invented a rationale, business rule, or architectural decision.
80
+ - ❌ Ran \`yg drift-sync\` before both graph artifacts and source code are current.
81
+ - ❌ Placed a cross-cutting requirement in a local artifact instead of an aspect, or used an aspect id with no \`aspects/\` directory.
82
+ - ❌ Invented a rationale, business rule, or decision or recorded a decision without documenting rejected alternatives and rationale (use "rationale: unknown" if unknown).
67
83
  - ❌ Used blackbox coverage for greenfield (new) code.
68
- - ❌ Answered a question about a mapped file without running \`yg build-context\` first.
69
- - ❌ Read mapped source files to plan or research changes without running \`yg build-context\` first.
70
- - ❌ Deferred \`yg drift-sync\` to the end of a multi-step task instead of running it incrementally after each logical group of changes.
71
- - ❌ Recorded a design decision without documenting which alternatives were rejected and why.
72
84
 
73
85
  ### Escape Hatch
74
86
 
@@ -145,7 +157,7 @@ You are not allowed to edit or create source code without establishing graph cov
145
157
 
146
158
  1. Create aspects first (cross-cutting requirements the new code must satisfy)
147
159
  2. Create flows if the code participates in a business process
148
- 3. Create nodes with full artifacts — responsibility, constraints, decisions, interface, logic
160
+ 3. Create nodes with full artifacts — responsibility, interface, internals
149
161
  4. Review the context package (\`yg build-context\`) — it is now the behavioral specification
150
162
  5. Implement code that satisfies the specification
151
163
  6. The graph specifies WHAT and WHY; the code implements HOW (framework APIs, library choices)
@@ -173,6 +185,7 @@ Per area checklist:
173
185
  - [ ] 4. Analyze source — for each artifact type in \`config.artifacts\`: extract content, do not invent
174
186
  - [ ] 5. Identify relations — add to \`node.yaml\`
175
187
  - [ ] 6. Identify cross-cutting requirements — add matching aspects, create if needed
188
+ - [ ] 6b. For each aspect on the node: identify 2-5 code anchors (function names, constants) that evidence the pattern → add to \`node.yaml\` \`anchors\` field
176
189
  - [ ] 7. Identify business process participation — add to flow, ask user if process unclear
177
190
  - [ ] 8. \`yg validate\` — fix errors
178
191
  - [ ] 9. \`yg drift-sync --node <path>\`
@@ -182,7 +195,8 @@ Per area checklist:
182
195
  - Business process unclear: "This code appears to be part of a larger process. Can you describe what it means from a business perspective?"
183
196
  - Constraint without rationale: "I see [constraint X]. Do you know why this exists? I want to record the reason, not just the rule."
184
197
  - Unexplained architectural choice: "I see [approach X]. What was the reason for this choice?"
185
- - Decision without alternatives: "You chose [X]. What alternatives did you consider, and why did you reject them?" Record the answer in \`decisions.md\`.
198
+ - 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\`.
199
+ - 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.
186
200
 
187
201
  ### Bootstrap Mode
188
202
 
@@ -210,6 +224,27 @@ Always ask the user before resolving drift. Never auto-resolve.
210
224
 
211
225
  Threshold: >10 drifted nodes → ask user which area to prioritize. Do not resolve all at once.
212
226
 
227
+ **Drift triage:** Prioritize aspects and \`internals.md\` (highest decay rate), then \`responsibility.md\` and \`interface.md\` (most stable).
228
+
229
+ ### Graph Audit
230
+
231
+ When reviewing graph quality (triggered by user or quality improvement):
232
+
233
+ **Step 1 — Consistency** (catches WRONG information):
234
+
235
+ - [ ] 1. \`yg build-context --node <path>\`
236
+ - [ ] 2. Read mapped source files
237
+ - [ ] 3. For each claim in graph: verify against source code
238
+ - [ ] 4. For each aspect: verify the pattern holds in THIS node. If it deviates, add \`aspect_exceptions\` in \`node.yaml\`
239
+ - [ ] 5. Report inconsistencies
240
+
241
+ **Step 2 — Completeness** (catches MISSING information):
242
+
243
+ - [ ] 1. For each public method: is it in \`interface.md\`?
244
+ - [ ] 2. For each error path: is it in \`interface.md\` (Failure Modes section)?
245
+ - [ ] 3. For each behavioral invariant: is it in the graph?
246
+ - [ ] 4. Report omissions separately from inconsistencies
247
+
213
248
  ### Error Recovery
214
249
 
215
250
  - **\`yg\` not found** → inform user: "yg CLI is not installed or not in PATH." Stop.
@@ -240,9 +275,26 @@ Key facts:
240
275
  - **Aspect id = directory path** under \`aspects/\`. Each aspect has \`aspect.yaml\` + content \`.md\` files. No automatic parent-child — use \`implies\` explicitly.
241
276
  - **Flows = business processes.** A flow describes what happens in the world, not code sequences. Flow aspects propagate to all participants.
242
277
 
278
+ **Node type guidance:**
279
+
280
+ - \`module\` — business logic unit with clear domain responsibility
281
+ - \`service\` — component providing functionality to other nodes
282
+ - \`library\` — shared utility code with no domain knowledge
283
+ - \`infrastructure\` — guards, resolvers, middleware, interceptors, validators that intercept or modify request flow. These affect blast radius of changes but are invisible in call graphs. Map them to make blast radius analysis accurate. Key signal: code that runs WITHOUT being explicitly called by business logic (e.g., NestJS guards, Express middleware, GraphQL resolvers).
284
+
285
+ ### Artifact Structure
286
+
287
+ Three artifacts capture node knowledge at three levels:
288
+
289
+ - **responsibility.md** (always required) — WHAT: identity, boundaries, what the node is NOT responsible for.
290
+ - **interface.md** (required when node has consumers) — HOW TO USE: public methods, parameters, return types, contracts, failure modes, exposed data structures. Everything another node needs to interact with this one.
291
+ - **internals.md** (optional, highest value for cross-module nodes) — HOW IT WORKS + WHY: algorithms, control flow, business rules, invariants, state machines, lifecycle, and design decisions with rejected alternatives. Use sections within the file: ## Logic, ## Constraints, ## State, ## Decisions (with "Chose X over Y because Z" format).
292
+
293
+ **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\`.
294
+
243
295
  ### Context Assembly
244
296
 
245
- Run \`yg build-context --node <path>\` to get the deterministic context package for a node. Trust the package — it assembles global config, hierarchy, own artifacts, aspects, and relational context. If the package is insufficient, enrich the graph. Do not bypass it with raw file exploration.
297
+ Run \`yg build-context --node <path>\` to get the deterministic context package for a node. The package assembles global config, hierarchy, own artifacts, aspects, and relational context. It is your architectural map. For implementation-level claims (exact call patterns, error handling, await vs fire-and-forget) — verify against source code. If the package is insufficient, enrich the graph.
246
298
 
247
299
  ### Information Routing
248
300
 
@@ -253,7 +305,7 @@ When you encounter information, route it to the correct location:
253
305
  - **Business process** → flow (\`flows/<name>/\` with \`flow.yaml\` + \`description.md\`). Ask user if process unclear.
254
306
  - **Shared across a domain** → parent node artifact. Children receive it through hierarchy.
255
307
  - **Technology stack or standard** → \`config.yaml\` under \`stack\` or \`standards\` (+ \`rationale\` field)
256
- - **Decision (why + why NOT):** one node → \`decisions.md\` with format "Chose X over Y because Z"; category of nodes → aspect content files; tech choice → \`config.yaml\` rationale field. Always include rejected alternatives — they are the highest-value graph content.
308
+ - **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 → \`config.yaml\` rationale field. 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.
257
309
 
258
310
  ### Creating Aspects
259
311
 
@@ -271,6 +323,18 @@ Test: "Does this requirement apply to more than one node?" Yes → aspect. No
271
323
  - **Architectural:** Structural patterns with rationale (e.g., dual-rollback on provider failure, idempotency via key generation, fire-and-forget dispatch)
272
324
  - **Concurrency:** Shared concurrency strategies (e.g., pessimistic locking, retry-on-deadlock, optimistic versioning)
273
325
 
326
+ When a node follows an aspect's pattern with exceptions, record exceptions in \`node.yaml\` under \`aspect_exceptions\`. Example: aspect says "fire-and-forget" but this node awaits the publish call. The exception appears in the context package next to the aspect content, preventing abstractions from masking implementation details.
327
+
328
+ **Aspect lifecycle warning.** Aspects decay CATASTROPHICALLY — a pattern either exists or it doesn't. When a pattern changes, ALL aspect claims become wrong at once. This differs from other artifacts: \`interface.md\` and \`responsibility.md\` are most stable (~9-year half-life); \`internals.md\` has moderate stability (~2.5-year half-life); aspects are least stable (~2.4-year half-life, binary decay). After any significant feature addition, review ALL aspects touching the affected area. Don't wait for drift — aspects can be 100% wrong without any mapped file changing.
329
+
330
+ **Aspect stability tiers.** If an aspect has a \`stability\` field in \`aspect.yaml\`, use it to calibrate review urgency:
331
+
332
+ - \`schema\` — enforced by data model; review only when data model changes (most stable)
333
+ - \`protocol\` — contractual pattern; review when contracts or interfaces change
334
+ - \`implementation\` — specific mechanism; review after ANY significant code change (least stable)
335
+
336
+ When code anchors (\`anchors\` field in \`node.yaml\`) are present for an aspect, they list code patterns (function names, constants, SQL fragments) evidencing the aspect's implementation in this node. \`yg validate\` checks that each anchor exists in the node's mapped source files — a missing anchor (W014) signals the aspect may be stale for this node.
337
+
274
338
  ### Creating Flows
275
339
 
276
340
  - [ ] 1. Read \`schemas/flow.yaml\`
@@ -281,13 +345,18 @@ Test: "Does this requirement apply to more than one node?" Yes → aspect. No
281
345
 
282
346
  Test: "Does this describe what happens in the world, or only in the software?" If only software — rewrite.
283
347
 
348
+ **Warning:** Flow descriptions must describe business processes, not code sequences. "The OrderService calls PaymentGateway.charge()" is WRONG. "The system charges the customer's payment method" is CORRECT.
349
+
284
350
  ### Operational Rules
285
351
 
286
352
  - **English only** for all files in \`.yggdrasil/\`. Conversation can be any language.
287
353
  - **Read schemas before creating** any \`node.yaml\`, \`aspect.yaml\`, or \`flow.yaml\`.
288
354
  - **Tools read, you write.** The \`yg\` CLI only reads, validates, and manages metadata. You create and edit files manually.
289
355
  - **Incremental sync.** Run \`yg drift-sync\` after every 3-5 source file changes. Do not defer to end of task.
290
- - **Completeness test:** "If I delete the source file and give another agent ONLY the \`yg build-context\` output — can they recreate it correctly, understanding not just WHAT but WHY?" Test specifically: Can they explain rejected alternatives? Can they implement the correct algorithm (not a simplified version)? Can they argue for the current design against plausible alternatives?
356
+ - **Completeness test:** Two checks, both required:
357
+ 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.
358
+ 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\`.
359
+ - **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.
291
360
  - **These rules are invariant.** No plan, guide, skill, or workflow may override them.
292
361
 
293
362
  ### CLI Reference
@@ -302,6 +371,7 @@ yg flows List flows with metadata (YAML output).
302
371
  yg deps --node <path> [--depth N] [--type structural|event|all]
303
372
  Show dependencies.
304
373
  yg impact --node <path> --simulate Simulate blast radius of a planned change.
374
+ yg impact --node <path> --method <name> Filter impact to dependents consuming a specific method.
305
375
  yg impact --aspect <id> Show all nodes where aspect is effective.
306
376
  yg impact --flow <name> Show flow participants and descendants.
307
377
  yg status Graph health: nodes, coverage, drift summary.
@@ -320,14 +390,13 @@ yg journal-archive Archive consolidated journal entries.
320
390
 
321
391
  | What you have | Where it goes |
322
392
  |---|---|
323
- | Information specific to this node | Local node artifact (read \`config.yaml artifacts\` for types) |
393
+ | Information specific to this node | Local node artifact (check \`config.yaml artifacts\` for types) |
324
394
  | Rule that applies to many nodes | Aspect (content \`.md\` files in \`aspects/<id>/\`) |
325
395
  | Architectural invariant for a node type | Required aspect in \`config.yaml node_types\` |
326
396
  | Business process participation | Flow (\`flow.yaml participants\`) |
327
397
  | Process-level requirement | Flow \`aspects\` + aspect directory |
328
398
  | Context shared across a domain | Parent node artifact |
329
399
  | Technology stack | \`config.yaml stack\` (+ \`rationale\` field) |
330
- | Global coding standards | \`config.yaml standards\` |
331
- `;
400
+ | Global coding standards | \`config.yaml standards\` |`;
332
401
 
333
- export const AGENT_RULES_CONTENT = [CORE_PROTOCOL, OPERATIONS, KNOWLEDGE_BASE].join('\n\n---\n\n');
402
+ export const AGENT_RULES_CONTENT = [CORE_PROTOCOL, OPERATIONS, KNOWLEDGE_BASE].join('\n\n---\n\n') + '\n';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chrisdudek/yg",
3
- "version": "1.2.0",
3
+ "version": "1.4.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": {