@chrisdudek/yg 0.3.4 → 1.1.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/README.md +28 -2
- package/dist/bin.js +1818 -1232
- package/dist/bin.js.map +1 -1
- package/dist/templates/default-config.ts +3 -14
- package/dist/templates/rules.ts +272 -186
- package/graph-schemas/aspect.yaml +9 -0
- package/graph-schemas/config.yaml +39 -0
- package/graph-schemas/flow.yaml +10 -0
- package/graph-schemas/node.yaml +19 -0
- package/package.json +2 -2
- package/graph-templates/aspect.yaml +0 -2
- package/graph-templates/flow.yaml +0 -8
- package/graph-templates/knowledge.yaml +0 -2
- package/graph-templates/node.yaml +0 -17
|
@@ -6,12 +6,10 @@ stack:
|
|
|
6
6
|
|
|
7
7
|
standards: ""
|
|
8
8
|
|
|
9
|
-
tags: []
|
|
10
|
-
|
|
11
9
|
node_types:
|
|
12
|
-
- module
|
|
13
|
-
- service
|
|
14
|
-
- library
|
|
10
|
+
- name: module
|
|
11
|
+
- name: service
|
|
12
|
+
- name: library
|
|
15
13
|
|
|
16
14
|
artifacts:
|
|
17
15
|
responsibility.md:
|
|
@@ -45,19 +43,10 @@ artifacts:
|
|
|
45
43
|
required: never
|
|
46
44
|
description: "Local design decisions and rationale — choices specific to this node, not system-wide"
|
|
47
45
|
|
|
48
|
-
knowledge_categories:
|
|
49
|
-
- name: decisions
|
|
50
|
-
description: "Global semantic decisions and their rationale"
|
|
51
|
-
- name: patterns
|
|
52
|
-
description: "Implementation conventions with examples"
|
|
53
|
-
- name: invariants
|
|
54
|
-
description: "System truths that must never be violated"
|
|
55
|
-
|
|
56
46
|
quality:
|
|
57
47
|
min_artifact_length: 50
|
|
58
48
|
max_direct_relations: 10
|
|
59
49
|
context_budget:
|
|
60
50
|
warning: 10000
|
|
61
51
|
error: 20000
|
|
62
|
-
knowledge_staleness_days: 90
|
|
63
52
|
`;
|
package/dist/templates/rules.ts
CHANGED
|
@@ -1,243 +1,329 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Canonical agent rules content — hand-tuned, do not generate programmatically.
|
|
3
3
|
*
|
|
4
|
-
* Operating manual for agents
|
|
4
|
+
* Operating manual for agents working in a Yggdrasil-managed repository.
|
|
5
|
+
* Split into three cognitive sections optimized for LLM attention patterns:
|
|
6
|
+
* 1. CORE PROTOCOL — internalize before doing anything (primacy effect)
|
|
7
|
+
* 2. OPERATIONS — execute while working (working memory)
|
|
8
|
+
* 3. KNOWLEDGE BASE — look up when needed (recency effect)
|
|
5
9
|
*/
|
|
6
|
-
export const AGENT_RULES_CONTENT = `# Yggdrasil - System Semantic Memory (Operating Manual)
|
|
7
10
|
|
|
8
|
-
|
|
9
|
-
|
|
11
|
+
// prettier-ignore
|
|
12
|
+
const CORE_PROTOCOL = `## CORE PROTOCOL
|
|
13
|
+
|
|
14
|
+
Yggdrasil is persistent semantic memory stored in \`.yggdrasil/\`. It maps the repository and provides deterministic implementation context for every node. This document is your complete operating manual. Follow it strictly.
|
|
15
|
+
|
|
16
|
+
### Quick Start Protocol
|
|
17
|
+
|
|
18
|
+
\`\`\`
|
|
19
|
+
BEFORE reading, researching, planning, OR modifying ANY mapped file:
|
|
20
|
+
1. yg owner --file <path>
|
|
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.
|
|
25
|
+
If the context package seems insufficient — enrich the graph.
|
|
26
|
+
Do not bypass it.
|
|
27
|
+
|
|
28
|
+
AFTER modifying:
|
|
29
|
+
3. Update graph artifacts to reflect changes
|
|
30
|
+
4. yg validate — fix all errors
|
|
31
|
+
5. yg drift-sync --node <owner>
|
|
10
32
|
|
|
11
|
-
|
|
33
|
+
EVERY conversation start:
|
|
34
|
+
yg preflight → act on findings (see Operations)
|
|
12
35
|
|
|
13
|
-
|
|
36
|
+
NEVER: modify code without graph coverage.
|
|
37
|
+
NEVER: read mapped source files to understand a component without
|
|
38
|
+
running yg build-context first — the graph captures intent,
|
|
39
|
+
constraints, and relations that source files cannot.
|
|
40
|
+
NEVER: invent rationale, business rules, or decisions.
|
|
41
|
+
NEVER: auto-resolve drift without asking the user.
|
|
42
|
+
WHEN UNSURE: ask the user. Never guess. Never assume.
|
|
43
|
+
\`\`\`
|
|
14
44
|
|
|
15
|
-
|
|
45
|
+
### Five Core Rules
|
|
16
46
|
|
|
17
|
-
|
|
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
|
+
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
|
+
3. **Never invent why.** The graph captures human intent. If you don't know why something was decided, ask. Never hallucinate rationale.
|
|
50
|
+
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
|
+
5. **Ask before resolving ambiguity.** When multiple valid interpretations exist, stop, list options, ask the user. Never silently choose.
|
|
18
52
|
|
|
19
|
-
|
|
20
|
-
- Code changed → graph artifacts MUST be updated IN THE SAME RESPONSE. No exceptions.
|
|
21
|
-
- Graph changed → source files MUST be verified/updated IN THE SAME RESPONSE. No exceptions.
|
|
22
|
-
- There is NO "code-only" response. There is NO "graph-only" response (unless explicitly a dry-run plan).
|
|
23
|
-
- If you complete a response and one side is changed but the other is not, you have VIOLATED the core contract of Yggdrasil.
|
|
53
|
+
### Failure States
|
|
24
54
|
|
|
25
|
-
|
|
55
|
+
You have broken Yggdrasil if you do any of the following:
|
|
26
56
|
|
|
27
|
-
|
|
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.
|
|
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.
|
|
67
|
+
- ❌ 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.
|
|
28
72
|
|
|
29
|
-
|
|
30
|
-
2. **Context is Sufficient:** If you feel the need to randomly explore source files to understand what a node should do, the graph is incomplete. **Fix the graph** (add decisions, interface details, constraints). Do not bypass the graph by reading raw code.
|
|
31
|
-
3. **Graph is Intended Truth:** If the code and graph diverge, the graph is the truth. If a code change is deliberate, update the graph to match.
|
|
32
|
-
4. **Exhaustive Coverage:** Every source file MUST belong to exactly one graph node. No orphaned files.
|
|
33
|
-
5. **Tools Read, You Write:** The \`yg\` CLI tools only read, validate, and manage metadata. YOU must create and edit graph directories, \`.yaml\` files, and \`.md\` artifacts manually.
|
|
34
|
-
6. **English Only for Artifacts:** All graph artifact files (filenames from \`config.artifacts\`, in the same directory as \`node.yaml\`) MUST be written in English. Conversation can be in the user's language.
|
|
35
|
-
7. **Never Touch Operational Metadata:** NEVER manually edit \`.yggdrasil/.drift-state\` or \`.yggdrasil/.journal.yaml\`.
|
|
36
|
-
8. **Ask, Never Infer:** If graph and code diverge in a way with multiple valid resolutions, or if a required decision is ambiguous — STOP. State the ambiguity. List interpretations. Ask the user to decide. Never silently choose. Never patch without confirmation. When you stop, always explain the context and available options clearly so the user can make an informed choice.
|
|
73
|
+
### Escape Hatch
|
|
37
74
|
|
|
38
|
-
|
|
75
|
+
If the user explicitly requests a code-only change, comply but:
|
|
39
76
|
|
|
40
|
-
|
|
77
|
+
- Warn: "This creates drift. Run \`yg drift\` next session to reconcile."
|
|
78
|
+
- Do NOT run \`yg drift-sync\` — leave the drift visible.
|
|
41
79
|
|
|
42
|
-
|
|
43
|
-
- ❌ You modified source code without having run \`yg owner --file <path>\` for each modified file in the SAME response.
|
|
44
|
-
- ❌ You modified source code without updating graph artifacts in the SAME response.
|
|
45
|
-
- ❌ You modified graph files without verifying/updating source code alignment in the SAME response.
|
|
46
|
-
- ❌ You resolved a code↔graph inconsistency without asking the user first.
|
|
47
|
-
- ❌ You created or edited a graph element without reading its schema in \`.yggdrasil/templates/\`.
|
|
48
|
-
- ❌ You ran \`yg drift-sync\` before updating graph artifacts.
|
|
49
|
-
- ❌ You ran \`yg drift-sync\` after a graph-only change without verifying source files.
|
|
50
|
-
- ❌ You used Blackbox coverage for greenfield/new code.
|
|
51
|
-
- ❌ You answered a question about a mapped file/area without running \`yg build-context\` when the path was known.
|
|
80
|
+
### Environment Check
|
|
52
81
|
|
|
53
|
-
|
|
82
|
+
Before preflight:
|
|
54
83
|
|
|
55
|
-
|
|
84
|
+
- Verify \`yg\` CLI is available. If not found, inform user and stop.
|
|
85
|
+
- If \`yg preflight\` shows 0 nodes → enter BOOTSTRAP MODE (see Operations).
|
|
86
|
+
- If drift report shows >10 drifted nodes → report scope to user, ask which area to prioritize. Do not resolve all at once.`;
|
|
56
87
|
|
|
57
|
-
|
|
88
|
+
// prettier-ignore
|
|
89
|
+
const OPERATIONS = `## OPERATIONS
|
|
58
90
|
|
|
59
|
-
###
|
|
60
|
-
Always execute these commands before doing anything else. *(Exception: If the user's request is clearly read-only, run ONLY step 1).* **Read-only** means the user asks only for explanation, clarification, analysis, or evaluation — no code or graph modification will occur. Examples: "explain this", "evaluate X", "what does Y do?", "analyze Z". If unsure, run full preflight.
|
|
61
|
-
1. \`yg journal-read\` -> If entries exist, consolidate them into the graph, then \`yg journal-archive\`.
|
|
62
|
-
2. \`yg drift\` -> If **drift** (code changed, graph baseline stale): run \`yg drift-sync\` for each affected node. Do NOT ask the user — they do not need to know this step. If **missing** or **unmaterialized**: report and ask the user how to proceed.
|
|
63
|
-
3. \`yg status\` -> Report graph health.
|
|
64
|
-
4. \`yg validate\` -> If W008 stale-knowledge appears, update the knowledge artifacts to reflect current node state.
|
|
91
|
+
### Conversation Lifecycle
|
|
65
92
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
1.
|
|
69
|
-
|
|
70
|
-
|
|
93
|
+
\`\`\`
|
|
94
|
+
PREFLIGHT (every conversation, before any work):
|
|
95
|
+
- [ ] 1. yg preflight → read unified report
|
|
96
|
+
- [ ] 2. If journal entries: consolidate to graph, then yg journal-archive
|
|
97
|
+
- [ ] 3. If drift: resolve per Drift Resolution, then yg drift-sync per node
|
|
98
|
+
- [ ] 4. If validation errors: fix, re-run yg validate
|
|
99
|
+
Exception: read-only requests (explain, analyze) — skip preflight.
|
|
71
100
|
|
|
72
|
-
|
|
101
|
+
UNDERSTANDING mapped code (questions, research, OR planning):
|
|
102
|
+
- [ ] 1. yg owner --file <path>
|
|
103
|
+
- [ ] 2. Owner found → yg build-context --node <path>. Use context package as primary source.
|
|
104
|
+
- [ ] 3. Owner not found → use file analysis, state it is not graph-backed.
|
|
105
|
+
Never use grep or raw file reads as primary understanding when graph coverage exists.
|
|
106
|
+
Raw reads supplement the context package — they do not replace it.
|
|
73
107
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
4. Report exactly what nodes and files were changed.
|
|
108
|
+
WRAP-UP (user signals "done", "wrap up", "that's enough"):
|
|
109
|
+
- [ ] 1. Consolidate journal if used → yg journal-archive
|
|
110
|
+
- [ ] 2. yg drift --drifted-only → resolve
|
|
111
|
+
- [ ] 3. yg validate → fix errors
|
|
112
|
+
- [ ] 4. Report: which nodes and files were changed
|
|
113
|
+
\`\`\`
|
|
81
114
|
|
|
82
|
-
|
|
115
|
+
### Modify Source Code
|
|
83
116
|
|
|
84
|
-
|
|
117
|
+
You are not allowed to edit or create source code without establishing graph coverage first.
|
|
85
118
|
|
|
86
|
-
|
|
119
|
+
**Step 1** — Check coverage: \`yg owner --file <path>\`
|
|
87
120
|
|
|
88
|
-
**
|
|
121
|
+
**Step 2a** — Owner found: execute checklist:
|
|
89
122
|
|
|
90
|
-
|
|
123
|
+
- [ ] 1. Read specification: \`yg build-context --node <node_path>\`
|
|
124
|
+
- [ ] 2. Assess blast radius: \`yg impact --node <node_path>\` — review dependents, descendants, and co-aspect nodes before changing interfaces or shared behavior
|
|
125
|
+
- [ ] 3. Modify source code
|
|
126
|
+
- [ ] 4. Sync graph artifacts — edit artifact files to reflect the changes
|
|
127
|
+
- [ ] 5. Run \`yg validate\` — fix all errors (if unfixable after 3 attempts → stop, report to user)
|
|
128
|
+
- [ ] 6. Run \`yg drift-sync --node <node_path>\` — only after graph and code are both current
|
|
91
129
|
|
|
92
|
-
**Step
|
|
93
|
-
Whenever you write or edit source code, you MUST output this exact checklist in your response to the user, and execute each step BEFORE finishing your turn:
|
|
130
|
+
**Step 2b** — Owner not found: establish coverage first. Present options to the user:
|
|
94
131
|
|
|
95
|
-
|
|
96
|
-
- [ ] 2. Modify Source Code
|
|
97
|
-
- [ ] 3. Sync Graph Artifacts (manually edit the node's artifact files IMMEDIATELY to match new code behavior)
|
|
98
|
-
- [ ] 4. Baseline Hash (ran \`yg drift-sync\` ONLY AFTER updating the graph)
|
|
132
|
+
*Partially mapped* (file unmapped but inside a mapped module): ask whether to add to existing node or create new one.
|
|
99
133
|
|
|
100
|
-
|
|
101
|
-
STOP. Do not modify the code. First determine: **Is this greenfield or existing code?**
|
|
134
|
+
*Existing code:*
|
|
102
135
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
* **Option 1: Reverse Engineering:** Create/extend standard nodes to map the area fully before modifying.
|
|
107
|
-
* **Option 2: Blackbox Coverage:** Create a \`blackbox: true\` node to establish ownership without deep semantic exploration.
|
|
108
|
-
* **Option 3: Abort/Change Plan:** Do not touch the file.
|
|
136
|
+
- Option A — Full node: create node(s), map files, write artifacts from code analysis
|
|
137
|
+
- Option B — Blackbox: create a blackbox node at agreed granularity
|
|
138
|
+
- Option C — Abort
|
|
109
139
|
|
|
110
|
-
|
|
140
|
+
*Greenfield (new code):* Only Option A. Blackbox is forbidden for new code. Follow the graph-first workflow:
|
|
111
141
|
|
|
112
|
-
|
|
142
|
+
1. Create aspects first (cross-cutting requirements the new code must satisfy)
|
|
143
|
+
2. Create flows if the code participates in a business process
|
|
144
|
+
3. Create nodes with full artifacts — responsibility, constraints, decisions, interface, logic
|
|
145
|
+
4. Review the context package (\`yg build-context\`) — it is now the behavioral specification
|
|
146
|
+
5. Implement code that satisfies the specification
|
|
147
|
+
6. The graph specifies WHAT and WHY; the code implements HOW (framework APIs, library choices)
|
|
113
148
|
|
|
114
|
-
|
|
149
|
+
After the user chooses, return to Step 1 and follow Step 2a.
|
|
115
150
|
|
|
116
|
-
|
|
151
|
+
### Modify Graph
|
|
117
152
|
|
|
118
|
-
|
|
119
|
-
2.
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
* W005/W006: Context package too large. Consider splitting the node.
|
|
125
|
-
* W008: Stale semantic memory. Update knowledge artifacts.
|
|
153
|
+
- [ ] 1. Read the relevant schema from \`schemas/\` before touching any YAML
|
|
154
|
+
- [ ] 2. Before changing an aspect or flow, check scope: \`yg impact --aspect <id>\` or \`yg impact --flow <name>\` — understand which nodes are affected before modifying shared rules or processes
|
|
155
|
+
- [ ] 3. Make changes
|
|
156
|
+
- [ ] 4. Run \`yg validate\` immediately — fix all errors
|
|
157
|
+
- [ ] 5. Verify affected source files are consistent — update if needed
|
|
158
|
+
- [ ] 6. Run \`yg drift-sync\` for affected nodes
|
|
126
159
|
|
|
127
|
-
|
|
128
|
-
Whenever you change the graph structure or semantics, you MUST output and execute this exact checklist:
|
|
160
|
+
### Reverse Engineering
|
|
129
161
|
|
|
130
|
-
-
|
|
131
|
-
- [ ] 2. Edit graph files (\`node.yaml\`, artifacts)
|
|
132
|
-
- [ ] 3. Verify corresponding source files exist and their behavior matches updated artifacts
|
|
133
|
-
- [ ] 4. Validate (ran \`yg validate\` — fix all Errors)
|
|
134
|
-
- [ ] 5. Baseline Hash (ran \`yg drift-sync\` ONLY AFTER steps 2-3 are confirmed)
|
|
162
|
+
**Order:** aspects (cross-cutting patterns) → flows (business processes) → model nodes. Never create nodes before aspects and flows are understood.
|
|
135
163
|
|
|
136
|
-
|
|
137
|
-
* **Default:** Write changes directly to graph files immediately. Do not defer.
|
|
138
|
-
* **Opt-in:** ONLY if the user says "use iterative mode" or "use journal". Once activated, it remains active for the ENTIRE conversation until wrap-up. Use \`yg journal-add --note "..."\` to buffer intent.
|
|
164
|
+
Per area checklist:
|
|
139
165
|
|
|
140
|
-
|
|
166
|
+
- [ ] 1. \`yg owner --file <path>\` — confirm no coverage
|
|
167
|
+
- [ ] 2. Determine node granularity — propose to user if unclear
|
|
168
|
+
- [ ] 3. Create node directory, read \`schemas/node.yaml\`, create \`node.yaml\`
|
|
169
|
+
- [ ] 4. Analyze source — for each artifact type in \`config.artifacts\`: extract content, do not invent
|
|
170
|
+
- [ ] 5. Identify relations — add to \`node.yaml\`
|
|
171
|
+
- [ ] 6. Identify cross-cutting requirements — add matching aspects, create if needed
|
|
172
|
+
- [ ] 7. Identify business process participation — add to flow, ask user if process unclear
|
|
173
|
+
- [ ] 8. \`yg validate\` — fix errors
|
|
174
|
+
- [ ] 9. \`yg drift-sync --node <path>\`
|
|
141
175
|
|
|
142
|
-
|
|
176
|
+
**When to ask:**
|
|
143
177
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
178
|
+
- Business process unclear: "This code appears to be part of a larger process. Can you describe what it means from a business perspective?"
|
|
179
|
+
- Constraint without rationale: "I see [constraint X]. Do you know why this exists? I want to record the reason, not just the rule."
|
|
180
|
+
- Unexplained architectural choice: "I see [approach X]. What was the reason for this choice?"
|
|
181
|
+
- Decision without alternatives: "You chose [X]. What alternatives did you consider, and why did you reject them?" Record the answer in \`decisions.md\`.
|
|
148
182
|
|
|
149
|
-
|
|
183
|
+
### Bootstrap Mode
|
|
150
184
|
|
|
151
|
-
|
|
185
|
+
Trigger: \`yg preflight\` shows 0 nodes, or no nodes cover the active work area.
|
|
152
186
|
|
|
153
|
-
|
|
187
|
+
- [ ] 1. Identify the active work area (files the user wants to modify)
|
|
188
|
+
- [ ] 2. Scan for cross-cutting patterns → create aspects
|
|
189
|
+
- [ ] 3. Ask user about business processes → create flows if applicable
|
|
190
|
+
- [ ] 4. Propose node structure for the area
|
|
191
|
+
- [ ] 5. Create node(s) with initial artifacts, map files
|
|
192
|
+
- [ ] 6. \`yg validate\`, \`yg drift-sync\`
|
|
193
|
+
- [ ] 7. Proceed with user's original request
|
|
154
194
|
|
|
155
|
-
|
|
156
|
-
* **\`.yggdrasil/templates/\`**: Schemas for each graph layer — \`node.yaml\`, \`aspect.yaml\`, \`flow.yaml\`, \`knowledge.yaml\`.
|
|
157
|
-
* **\`.yggdrasil/model/\`**: Node tree. Each node is a directory with \`node.yaml\` and artifact files.
|
|
158
|
-
* **\`.yggdrasil/aspects/\`**: Cross-cutting rules. Directory contains \`aspect.yaml\` and \`.md\` content.
|
|
159
|
-
* **\`.yggdrasil/flows/\`**: End-to-end processes. Directory contains \`flow.yaml\` and \`.md\` content.
|
|
160
|
-
* **\`.yggdrasil/knowledge/\`**: Repo-wide wisdom. Directory contains \`knowledge.yaml\` and \`.md\` content.
|
|
195
|
+
Constraint: Do NOT map the entire repository. Focus on the active area. Expand incrementally.
|
|
161
196
|
|
|
162
|
-
|
|
197
|
+
### Drift Resolution
|
|
163
198
|
|
|
164
|
-
|
|
199
|
+
Always ask the user before resolving drift. Never auto-resolve.
|
|
165
200
|
|
|
166
|
-
|
|
201
|
+
- **Source drift** (source files changed) → update graph artifacts to match source, then \`yg drift-sync\`
|
|
202
|
+
- **Graph drift** (graph artifacts changed) → review affected source, update if needed, then \`yg drift-sync\`
|
|
203
|
+
- **Full drift** (both changed) → present both sides to user, ask which direction wins
|
|
204
|
+
- **Missing** → ask: re-materialize or remove mapping?
|
|
205
|
+
- **Unmaterialized** → ask user how to proceed
|
|
167
206
|
|
|
168
|
-
|
|
207
|
+
Threshold: >10 drifted nodes → ask user which area to prioritize. Do not resolve all at once.
|
|
169
208
|
|
|
170
|
-
###
|
|
171
|
-
The graph is not just a structural map; it is the semantic meaning of the system. Code explains "what" and "how". The graph MUST explain "WHY".
|
|
209
|
+
### Error Recovery
|
|
172
210
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
211
|
+
- **\`yg\` not found** → inform user: "yg CLI is not installed or not in PATH." Stop.
|
|
212
|
+
- **Unfixable validate errors** → if not resolved after 3 attempts, stop and report to user. Do not loop.
|
|
213
|
+
- **Budget exceeded** → if \`yg build-context\` exits with error (context package exceeds budget), warn user: "This node should be split." Do not proceed with implementation.
|
|
214
|
+
- **Corrupted \`.yggdrasil/\` files** → report to user. Do not attempt repair.
|
|
215
|
+
- **Incremental sync** → run \`yg drift-sync\` every 3-5 source files during multi-file tasks. Do not defer to end.`;
|
|
177
216
|
|
|
178
|
-
|
|
217
|
+
// prettier-ignore
|
|
218
|
+
const KNOWLEDGE_BASE = `## KNOWLEDGE BASE
|
|
179
219
|
|
|
180
|
-
###
|
|
181
|
-
* **What goes here:** Things exclusively true for this specific node.
|
|
182
|
-
* **Routing:** **DO NOT ASSUME FILE NAMES.** You MUST read \`.yggdrasil/config.yaml\` (the \`artifacts\` section) to see the exact allowed filenames for the current project and their requirement conditions (e.g., \`required: always\` vs \`when: has_incoming_relations\`). Write local node knowledge ONLY into these configured files next to \`node.yaml\`.
|
|
183
|
-
* For each artifact in \`config.artifacts\`, use its \`description\` to decide what content belongs there. Create optional artifacts (those with \`required: never\`) when the node has matching content. Extract from source; do not invent.
|
|
220
|
+
### Graph Structure
|
|
184
221
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
-
|
|
221
|
-
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
222
|
+
\`\`\`
|
|
223
|
+
.yggdrasil/
|
|
224
|
+
config.yaml ← vocabulary, stack, node types, artifact rules, required aspects
|
|
225
|
+
model/ ← what exists: nodes, hierarchy, relations, file mappings
|
|
226
|
+
aspects/ ← what must: cross-cutting requirements with rationale and guidance
|
|
227
|
+
flows/ ← why and in what process: business processes with node participation
|
|
228
|
+
schemas/ ← YAML schemas — read before creating any graph element
|
|
229
|
+
.drift-state ← generated by CLI; never edit manually
|
|
230
|
+
.journal.yaml ← generated by CLI; never edit manually
|
|
231
|
+
\`\`\`
|
|
232
|
+
|
|
233
|
+
Key facts:
|
|
234
|
+
|
|
235
|
+
- **Hierarchy:** nodes nest in \`model/\`. Children inherit parent context. Do not repeat parent content in children.
|
|
236
|
+
- **Aspect id = directory path** under \`aspects/\`. Each aspect has \`aspect.yaml\` + content \`.md\` files. No automatic parent-child — use \`implies\` explicitly.
|
|
237
|
+
- **Flows = business processes.** A flow describes what happens in the world, not code sequences. Flow aspects propagate to all participants.
|
|
238
|
+
|
|
239
|
+
### Context Assembly
|
|
240
|
+
|
|
241
|
+
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.
|
|
242
|
+
|
|
243
|
+
### Information Routing
|
|
244
|
+
|
|
245
|
+
When you encounter information, route it to the correct location:
|
|
246
|
+
|
|
247
|
+
- **Specific to this node** → local node artifact (check \`config.yaml artifacts\` for available types)
|
|
248
|
+
- **Rule for many nodes** → aspect (\`aspects/<id>/\` with \`aspect.yaml\` + content \`.md\` files). If applies to ALL nodes of a type → \`node_types[*].required_aspects\` in \`config.yaml\`
|
|
249
|
+
- **Business process** → flow (\`flows/<name>/\` with \`flow.yaml\` + \`description.md\`). Ask user if process unclear.
|
|
250
|
+
- **Shared across a domain** → parent node artifact. Children receive it through hierarchy.
|
|
251
|
+
- **Technology stack or standard** → \`config.yaml\` under \`stack\` or \`standards\` (+ \`rationale\` field)
|
|
252
|
+
- **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.
|
|
253
|
+
|
|
254
|
+
### Creating Aspects
|
|
255
|
+
|
|
256
|
+
- [ ] 1. Read \`schemas/aspect.yaml\`
|
|
257
|
+
- [ ] 2. Create \`aspects/<id>/\` directory
|
|
258
|
+
- [ ] 3. Write \`aspect.yaml\` — name, optional description, optional implies
|
|
259
|
+
- [ ] 4. Write content \`.md\` files: WHAT must be satisfied + WHY (user's words, do not invent)
|
|
260
|
+
- [ ] 5. \`yg validate\`
|
|
261
|
+
|
|
262
|
+
Test: "Does this requirement apply to more than one node?" Yes → aspect. No → local artifact.
|
|
263
|
+
|
|
264
|
+
**Aspect identification heuristic:** If the same pattern, constraint, or rule appears in 3+ places, it is a candidate aspect. Aspects fall into natural categories:
|
|
265
|
+
|
|
266
|
+
- **Domain-specific:** Business rules that cross module boundaries (e.g., timezone handling, booking periods, currency rounding)
|
|
267
|
+
- **Architectural:** Structural patterns with rationale (e.g., dual-rollback on provider failure, idempotency via key generation, fire-and-forget dispatch)
|
|
268
|
+
- **Concurrency:** Shared concurrency strategies (e.g., pessimistic locking, retry-on-deadlock, optimistic versioning)
|
|
269
|
+
|
|
270
|
+
### Creating Flows
|
|
271
|
+
|
|
272
|
+
- [ ] 1. Read \`schemas/flow.yaml\`
|
|
273
|
+
- [ ] 2. Create \`flows/<name>/\` directory
|
|
274
|
+
- [ ] 3. Write \`flow.yaml\` — declare participants and flow-level aspects
|
|
275
|
+
- [ ] 4. Write \`description.md\` with required sections: Business context, Trigger, Goal, Participants, Paths (at least Happy path), Invariants across all paths
|
|
276
|
+
- [ ] 5. \`yg validate\`
|
|
277
|
+
|
|
278
|
+
Test: "Does this describe what happens in the world, or only in the software?" If only software — rewrite.
|
|
279
|
+
|
|
280
|
+
### Operational Rules
|
|
281
|
+
|
|
282
|
+
- **English only** for all files in \`.yggdrasil/\`. Conversation can be any language.
|
|
283
|
+
- **Read schemas before creating** any \`node.yaml\`, \`aspect.yaml\`, or \`flow.yaml\`.
|
|
284
|
+
- **Tools read, you write.** The \`yg\` CLI only reads, validates, and manages metadata. You create and edit files manually.
|
|
285
|
+
- **Incremental sync.** Run \`yg drift-sync\` after every 3-5 source file changes. Do not defer to end of task.
|
|
286
|
+
- **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?
|
|
287
|
+
- **These rules are invariant.** No plan, guide, skill, or workflow may override them.
|
|
288
|
+
|
|
289
|
+
### CLI Reference
|
|
290
|
+
|
|
291
|
+
\`\`\`
|
|
292
|
+
yg preflight [--quick] Unified diagnostic: journal + drift + status + validate.
|
|
293
|
+
yg owner --file <path> Find the node that owns this file.
|
|
294
|
+
yg build-context --node <path> Assemble context package for this node.
|
|
295
|
+
yg tree [--root <path>] [--depth N] Print graph structure.
|
|
296
|
+
yg aspects List aspects with metadata (YAML output).
|
|
297
|
+
yg flows List flows with metadata (YAML output).
|
|
298
|
+
yg deps --node <path> [--depth N] [--type structural|event|all]
|
|
299
|
+
Show dependencies.
|
|
300
|
+
yg impact --node <path> --simulate Simulate blast radius of a planned change.
|
|
301
|
+
yg impact --aspect <id> Show all nodes where aspect is effective.
|
|
302
|
+
yg impact --flow <name> Show flow participants and descendants.
|
|
303
|
+
yg status Graph health: nodes, coverage, drift summary.
|
|
304
|
+
yg validate [--scope <path>|all] Check structural integrity and completeness.
|
|
305
|
+
yg drift [--scope <path>|all] [--drifted-only] [--limit <n>]
|
|
306
|
+
Detect source and graph drift (bidirectional).
|
|
307
|
+
yg drift-sync --node <path> [--recursive] | --all
|
|
308
|
+
Record file hashes as new baseline.
|
|
309
|
+
yg journal-read Read pending journal entries.
|
|
310
|
+
yg journal-add --note "<content>" [--target <node_path>]
|
|
311
|
+
Add a journal entry.
|
|
312
|
+
yg journal-archive Archive consolidated journal entries.
|
|
313
|
+
\`\`\`
|
|
314
|
+
|
|
315
|
+
### Quick Routing Table
|
|
316
|
+
|
|
317
|
+
| What you have | Where it goes |
|
|
318
|
+
|---|---|
|
|
319
|
+
| Information specific to this node | Local node artifact (read \`config.yaml artifacts\` for types) |
|
|
320
|
+
| Rule that applies to many nodes | Aspect (content \`.md\` files in \`aspects/<id>/\`) |
|
|
321
|
+
| Architectural invariant for a node type | Required aspect in \`config.yaml node_types\` |
|
|
322
|
+
| Business process participation | Flow (\`flow.yaml participants\`) |
|
|
323
|
+
| Process-level requirement | Flow \`aspects\` + aspect directory |
|
|
324
|
+
| Context shared across a domain | Parent node artifact |
|
|
325
|
+
| Technology stack | \`config.yaml stack\` (+ \`rationale\` field) |
|
|
326
|
+
| Global coding standards | \`config.yaml standards\` |
|
|
243
327
|
`;
|
|
328
|
+
|
|
329
|
+
export const AGENT_RULES_CONTENT = [CORE_PROTOCOL, OPERATIONS, KNOWLEDGE_BASE].join('\n\n---\n\n');
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# aspect.yaml — Schema for cross-cutting aspects
|
|
2
|
+
# Each aspect is a directory under .yggdrasil/aspects/ containing this file
|
|
3
|
+
# plus any number of .md content files (requirements, rationale, guidance).
|
|
4
|
+
# Aspect identifier = relative path from aspects/ to the directory (e.g. observability/logging).
|
|
5
|
+
# Aspects can be organized in nested directories for hierarchy.
|
|
6
|
+
|
|
7
|
+
name: CrossCuttingRequirementName # required — display name
|
|
8
|
+
description: "Short description for discovery via yg aspects" # optional
|
|
9
|
+
# implies: [other-aspect, another-aspect] # optional — other aspect identifiers included automatically (recursive, must be acyclic)
|