@chrisdudek/yg 1.2.0 → 1.3.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,7 +45,7 @@ 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.
@@ -54,21 +55,14 @@ WHEN UNSURE: ask the user. Never guess. Never assume.
54
55
 
55
56
  You have broken Yggdrasil if you do any of the following:
56
57
 
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.
58
+ - ❌ Worked on a mapped file without running \`yg owner\` + \`yg build-context\` first — whether reading to understand, planning, or modifying.
59
+ - ❌ Modified source code without updating graph artifacts in the same response, or vice versa.
60
+ - ❌ Resolved a code-graph inconsistency or ambiguity without asking the user first.
61
61
  - ❌ 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.
62
+ - ❌ Ran \`yg drift-sync\` before both graph artifacts and source code are current.
63
+ - ❌ Placed a cross-cutting requirement in a local artifact instead of an aspect, or used an aspect id with no \`aspects/\` directory.
64
+ - ❌ Invented a rationale, business rule, or decision or recorded a decision without documenting rejected alternatives and rationale (use "rationale: unknown" if unknown).
67
65
  - ❌ 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
66
 
73
67
  ### Escape Hatch
74
68
 
@@ -145,7 +139,7 @@ You are not allowed to edit or create source code without establishing graph cov
145
139
 
146
140
  1. Create aspects first (cross-cutting requirements the new code must satisfy)
147
141
  2. Create flows if the code participates in a business process
148
- 3. Create nodes with full artifacts — responsibility, constraints, decisions, interface, logic
142
+ 3. Create nodes with full artifacts — responsibility, interface, internals
149
143
  4. Review the context package (\`yg build-context\`) — it is now the behavioral specification
150
144
  5. Implement code that satisfies the specification
151
145
  6. The graph specifies WHAT and WHY; the code implements HOW (framework APIs, library choices)
@@ -182,7 +176,8 @@ Per area checklist:
182
176
  - Business process unclear: "This code appears to be part of a larger process. Can you describe what it means from a business perspective?"
183
177
  - Constraint without rationale: "I see [constraint X]. Do you know why this exists? I want to record the reason, not just the rule."
184
178
  - 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\`.
179
+ - 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\`.
180
+ - 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
181
 
187
182
  ### Bootstrap Mode
188
183
 
@@ -210,6 +205,27 @@ Always ask the user before resolving drift. Never auto-resolve.
210
205
 
211
206
  Threshold: >10 drifted nodes → ask user which area to prioritize. Do not resolve all at once.
212
207
 
208
+ **Drift triage:** Prioritize aspects and \`internals.md\` (highest decay rate), then \`responsibility.md\` and \`interface.md\` (most stable).
209
+
210
+ ### Graph Audit
211
+
212
+ When reviewing graph quality (triggered by user or quality improvement):
213
+
214
+ **Step 1 — Consistency** (catches WRONG information):
215
+
216
+ - [ ] 1. \`yg build-context --node <path>\`
217
+ - [ ] 2. Read mapped source files
218
+ - [ ] 3. For each claim in graph: verify against source code
219
+ - [ ] 4. For each aspect: verify the pattern holds in THIS node. If it deviates, add \`aspect_exceptions\` in \`node.yaml\`
220
+ - [ ] 5. Report inconsistencies
221
+
222
+ **Step 2 — Completeness** (catches MISSING information):
223
+
224
+ - [ ] 1. For each public method: is it in \`interface.md\`?
225
+ - [ ] 2. For each error path: is it in \`interface.md\` (Failure Modes section)?
226
+ - [ ] 3. For each behavioral invariant: is it in the graph?
227
+ - [ ] 4. Report omissions separately from inconsistencies
228
+
213
229
  ### Error Recovery
214
230
 
215
231
  - **\`yg\` not found** → inform user: "yg CLI is not installed or not in PATH." Stop.
@@ -240,9 +256,24 @@ Key facts:
240
256
  - **Aspect id = directory path** under \`aspects/\`. Each aspect has \`aspect.yaml\` + content \`.md\` files. No automatic parent-child — use \`implies\` explicitly.
241
257
  - **Flows = business processes.** A flow describes what happens in the world, not code sequences. Flow aspects propagate to all participants.
242
258
 
259
+ **Node type guidance:**
260
+
261
+ - \`module\` — business logic unit with clear domain responsibility
262
+ - \`service\` — component providing functionality to other nodes
263
+ - \`library\` — shared utility code with no domain knowledge
264
+ - \`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).
265
+
266
+ ### Artifact Structure
267
+
268
+ Three artifacts capture node knowledge at three levels:
269
+
270
+ - **responsibility.md** (always required) — WHAT: identity, boundaries, what the node is NOT responsible for.
271
+ - **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.
272
+ - **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).
273
+
243
274
  ### Context Assembly
244
275
 
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.
276
+ 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
277
 
247
278
  ### Information Routing
248
279
 
@@ -253,7 +284,7 @@ When you encounter information, route it to the correct location:
253
284
  - **Business process** → flow (\`flows/<name>/\` with \`flow.yaml\` + \`description.md\`). Ask user if process unclear.
254
285
  - **Shared across a domain** → parent node artifact. Children receive it through hierarchy.
255
286
  - **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.
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 → \`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
288
 
258
289
  ### Creating Aspects
259
290
 
@@ -271,6 +302,10 @@ Test: "Does this requirement apply to more than one node?" Yes → aspect. No
271
302
  - **Architectural:** Structural patterns with rationale (e.g., dual-rollback on provider failure, idempotency via key generation, fire-and-forget dispatch)
272
303
  - **Concurrency:** Shared concurrency strategies (e.g., pessimistic locking, retry-on-deadlock, optimistic versioning)
273
304
 
305
+ 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.
306
+
307
+ **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.
308
+
274
309
  ### Creating Flows
275
310
 
276
311
  - [ ] 1. Read \`schemas/flow.yaml\`
@@ -281,13 +316,18 @@ Test: "Does this requirement apply to more than one node?" Yes → aspect. No
281
316
 
282
317
  Test: "Does this describe what happens in the world, or only in the software?" If only software — rewrite.
283
318
 
319
+ **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.
320
+
284
321
  ### Operational Rules
285
322
 
286
323
  - **English only** for all files in \`.yggdrasil/\`. Conversation can be any language.
287
324
  - **Read schemas before creating** any \`node.yaml\`, \`aspect.yaml\`, or \`flow.yaml\`.
288
325
  - **Tools read, you write.** The \`yg\` CLI only reads, validates, and manages metadata. You create and edit files manually.
289
326
  - **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?
327
+ - **Completeness test:** Two checks, both required:
328
+ 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.
329
+ 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\`.
330
+ - **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
331
  - **These rules are invariant.** No plan, guide, skill, or workflow may override them.
292
332
 
293
333
  ### CLI Reference
@@ -320,14 +360,13 @@ yg journal-archive Archive consolidated journal entries.
320
360
 
321
361
  | What you have | Where it goes |
322
362
  |---|---|
323
- | Information specific to this node | Local node artifact (read \`config.yaml artifacts\` for types) |
363
+ | Information specific to this node | Local node artifact (check \`config.yaml artifacts\` for types) |
324
364
  | Rule that applies to many nodes | Aspect (content \`.md\` files in \`aspects/<id>/\`) |
325
365
  | Architectural invariant for a node type | Required aspect in \`config.yaml node_types\` |
326
366
  | Business process participation | Flow (\`flow.yaml participants\`) |
327
367
  | Process-level requirement | Flow \`aspects\` + aspect directory |
328
368
  | Context shared across a domain | Parent node artifact |
329
369
  | Technology stack | \`config.yaml stack\` (+ \`rationale\` field) |
330
- | Global coding standards | \`config.yaml standards\` |
331
- `;
370
+ | Global coding standards | \`config.yaml standards\` |`;
332
371
 
333
372
  export const AGENT_RULES_CONTENT = [CORE_PROTOCOL, OPERATIONS, KNOWLEDGE_BASE].join('\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.3.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": {