@chrisdudek/yg 0.2.0 → 0.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.
- package/dist/bin.js +19 -12
- package/dist/bin.js.map +1 -1
- package/dist/templates/rules.ts +15 -9
- package/package.json +1 -1
package/dist/bin.js
CHANGED
|
@@ -83,6 +83,8 @@ var AGENT_RULES_CONTENT = `# Yggdrasil - System Semantic Memory (Operating Manua
|
|
|
83
83
|
You are working in a repository managed by Yggdrasil.
|
|
84
84
|
Yggdrasil is a persistent, structured semantic memory graph stored in \`.yggdrasil/\`. It maps the repository, dictates system rules, and assembles implementation contexts.
|
|
85
85
|
|
|
86
|
+
**Why:** AI agents degrade with project size \u2014 too little context breaks contracts, too much context drowns in noise. The graph is persistent semantic memory: agents need exactly the right tokens for the task, not the whole repo. Small, precise context beats massive noisy. A repository with Yggdrasil is self-aware.
|
|
87
|
+
|
|
86
88
|
THIS PROMPT IS YOUR ENTIRE OPERATING MANUAL. Read it carefully. Follow it strictly.
|
|
87
89
|
|
|
88
90
|
---
|
|
@@ -106,13 +108,14 @@ THIS PROMPT IS YOUR ENTIRE OPERATING MANUAL. Read it carefully. Follow it strict
|
|
|
106
108
|
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.
|
|
107
109
|
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.
|
|
108
110
|
7. **Never Touch Operational Metadata:** NEVER manually edit \`.yggdrasil/.drift-state\` or \`.yggdrasil/.journal.yaml\`.
|
|
109
|
-
8. **Ask, Never Infer:** If graph and code diverge in a way with multiple valid resolutions, or if a required decision is ambiguous \u2014 STOP. State the ambiguity. List interpretations. Ask the user to decide. Never silently choose. Never patch without confirmation.
|
|
111
|
+
8. **Ask, Never Infer:** If graph and code diverge in a way with multiple valid resolutions, or if a required decision is ambiguous \u2014 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.
|
|
110
112
|
|
|
111
113
|
---
|
|
112
114
|
|
|
113
115
|
## 1.5 FAILURE STATES
|
|
114
116
|
|
|
115
117
|
You have fundamentally broken Yggdrasil if you do any of the following:
|
|
118
|
+
- \u274C You modified source code without having run \`yg owner --file <path>\` for each modified file in the SAME response.
|
|
116
119
|
- \u274C You modified source code without updating graph artifacts in the SAME response.
|
|
117
120
|
- \u274C You modified graph files without verifying/updating source code alignment in the SAME response.
|
|
118
121
|
- \u274C You resolved a code\u2194graph inconsistency without asking the user first.
|
|
@@ -128,17 +131,17 @@ You have fundamentally broken Yggdrasil if you do any of the following:
|
|
|
128
131
|
You do not need explicit "session" commands. Follow these conversational triggers:
|
|
129
132
|
|
|
130
133
|
### A. Preflight (First message of the conversation)
|
|
131
|
-
Always execute these commands before doing anything else. *(Exception: If the user's request is clearly read-only,
|
|
134
|
+
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 \u2014 no code or graph modification will occur. Examples: "explain this", "evaluate X", "what does Y do?", "analyze Z". If unsure, run full preflight.
|
|
132
135
|
1. \`yg journal-read\` -> If entries exist, consolidate them into the graph, then \`yg journal-archive\`.
|
|
133
|
-
2. \`yg drift\` -> If
|
|
136
|
+
2. \`yg drift\` -> If **drift** (code changed, graph baseline stale): run \`yg drift-sync\` for each affected node. Do NOT ask the user \u2014 they do not need to know this step. If **missing** or **unmaterialized**: report and ask the user how to proceed.
|
|
134
137
|
3. \`yg status\` -> Report graph health.
|
|
135
138
|
4. \`yg validate\` -> If W008 stale-knowledge appears, update the knowledge artifacts to reflect current node state.
|
|
136
139
|
|
|
137
140
|
### B. Session Verification (Wrap-up)
|
|
138
|
-
Triggered by phrases like: "we're done", "wrap up", "that's enough", "done".
|
|
141
|
+
Triggered by phrases like: "we're done", "wrap up", "that's enough", "done", "ok".
|
|
139
142
|
**Note: The graph should ALREADY be up to date. If the graph requires massive updates at this stage, YOU HAVE FAILED.**
|
|
140
143
|
1. If iterative journal mode was used: consolidate notes to the graph, then \`yg journal-archive\`.
|
|
141
|
-
2. \`yg drift\` ->
|
|
144
|
+
2. \`yg drift\` -> If drift detected, run \`yg drift-sync\` for each affected node. Do NOT ask \u2014 absorb automatically.
|
|
142
145
|
3. \`yg validate\` -> Fix any structural errors.
|
|
143
146
|
4. Report exactly what nodes and files were changed.
|
|
144
147
|
|
|
@@ -148,6 +151,8 @@ Triggered by phrases like: "we're done", "wrap up", "that's enough", "done".
|
|
|
148
151
|
|
|
149
152
|
You are NOT ALLOWED to edit or create source code without establishing graph coverage first.
|
|
150
153
|
|
|
154
|
+
**Gate:** Before using any tool that modifies files, you MUST have run \`yg owner --file <path>\` for each file you intend to modify. If you have not \u2014 run it first, then proceed. No exceptions. Gate applies to **source files** (files outside \`.yggdrasil/\`). For graph files (\`.yggdrasil/model/\`, \`.yggdrasil/aspects/\`, etc.), follow the Graph Modification Checklist in section 4 instead.
|
|
155
|
+
|
|
151
156
|
**Step 1: Check coverage** -> Run \`yg owner --file <path>\`
|
|
152
157
|
|
|
153
158
|
**Step 2: If Owner FOUND (The Execution Checklist)**
|
|
@@ -227,11 +232,11 @@ Your ultimate goal when describing a file or node is **Context Reproducibility**
|
|
|
227
232
|
However, you must NOT dump all knowledge into a single file. Yggdrasil's context package is **multi-layered** and hierarchically assembled. When you map existing code or design new code, you must deconstruct the knowledge and place it at the correct abstraction layer so the engine can mechanically reassemble it.
|
|
228
233
|
|
|
229
234
|
### CRITICAL RULE: CAPTURE INTENT, BUT NEVER INVENT IT
|
|
230
|
-
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".
|
|
235
|
+
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".
|
|
231
236
|
|
|
232
237
|
1. **ALWAYS Capture the User's "Why":** If the user explains the business reason, intent, or rationale behind a request (e.g., "We need to do X because Y"), you MUST permanently record this reasoning in the relevant graph artifacts (e.g., \`responsibility.md\`, \`constraints.md\`, \`decisions.md\`). Do not let the conversation context evaporate.
|
|
233
|
-
2. **NEVER Invent the "Why":** Files that imply human judgment (like \`decisions.md\` or \`knowledge/invariants\`) must reflect ACTUAL human choices.
|
|
234
|
-
3. **NO Hallucinations:** You MUST NEVER infer or hallucinate a rationale, an architectural decision, or a business rule.
|
|
238
|
+
2. **NEVER Invent the "Why":** Files that imply human judgment (like \`decisions.md\` or \`knowledge/invariants\`) must reflect ACTUAL human choices.
|
|
239
|
+
3. **NO Hallucinations:** You MUST NEVER infer or hallucinate a rationale, an architectural decision, or a business rule.
|
|
235
240
|
4. **Ask if Missing:** If the user requests a significant architectural or business logic change but does not provide the rationale, you MUST ask them "Why are we making this change?" before documenting the decision in the graph.
|
|
236
241
|
|
|
237
242
|
When mapping a file, execute this mental routing:
|
|
@@ -249,6 +254,7 @@ When mapping a file, execute this mental routing:
|
|
|
249
254
|
* **Routing:**
|
|
250
255
|
* If it calls another module: Add an outgoing structural \`relation\` in \`node.yaml\`. (The engine will automatically fetch the target's structural-context artifacts: responsibility, interface, constraints, errors).
|
|
251
256
|
* If it participates in an end-to-end process: Do not explain the whole process locally. Ensure the node is listed in \`.yggdrasil/flows/<flow_name>/flow.yaml\`. The engine will attach the flow knowledge automatically.
|
|
257
|
+
* **Flows \u2014 writing flow content:** When creating or editing flow artifacts (e.g. \`description.md\` in \`flows/<name>/\`), write business-first: describe the process from user/business perspective. Technical details only as inserts when they clarify the flow. Not technical-first with business inserts.
|
|
252
258
|
|
|
253
259
|
### Layer 3: Domain Context (Hierarchy)
|
|
254
260
|
* **What goes here:** Business rules shared by a family of nodes.
|
|
@@ -265,7 +271,7 @@ When mapping a file, execute this mental routing:
|
|
|
265
271
|
* If the file reveals an undocumented global invariant or decision: Ask the user to confirm it. If confirmed, create it under \`.yggdrasil/knowledge/<category>/\` so all future nodes inherit it.
|
|
266
272
|
|
|
267
273
|
**THE COMPLETENESS CHECK:**
|
|
268
|
-
Before finishing a mapping, ask yourself: *"If I delete the source file and give another agent ONLY the output of \`yg build-context\`, can they recreate it perfectly based on the configured artifacts, AND will they understand EXACTLY WHY this code exists and why it was designed this way?"*
|
|
274
|
+
Before finishing a mapping, ask yourself: *"If I delete the source file and give another agent ONLY the output of \`yg build-context\`, can they recreate it perfectly based on the configured artifacts, AND will they understand EXACTLY WHY this code exists and why it was designed this way?"*
|
|
269
275
|
- If no -> You missed a local constraint, a relation, or you failed to capture the user's provided rationale.
|
|
270
276
|
- If yes, but the local files are bloated -> You failed to deconstruct knowledge into Tags, Aspects, Flows, and Hierarchy. Fix the routing.
|
|
271
277
|
|
|
@@ -1239,7 +1245,7 @@ async function buildContext(graph, nodePath) {
|
|
|
1239
1245
|
}
|
|
1240
1246
|
}
|
|
1241
1247
|
}
|
|
1242
|
-
for (const flow of collectParticipatingFlows(graph,
|
|
1248
|
+
for (const flow of collectParticipatingFlows(graph, node)) {
|
|
1243
1249
|
layers.push(buildFlowLayer(flow));
|
|
1244
1250
|
for (const kPath of flow.knowledge ?? []) {
|
|
1245
1251
|
const norm = kPath.replace(/\/$/, "");
|
|
@@ -1301,8 +1307,9 @@ function collectKnowledgeItems(graph, nodePath, nodeTags, seenKnowledge) {
|
|
|
1301
1307
|
}
|
|
1302
1308
|
return result;
|
|
1303
1309
|
}
|
|
1304
|
-
function collectParticipatingFlows(graph,
|
|
1305
|
-
|
|
1310
|
+
function collectParticipatingFlows(graph, node) {
|
|
1311
|
+
const paths = /* @__PURE__ */ new Set([node.path, ...collectAncestors(node).map((a) => a.path)]);
|
|
1312
|
+
return graph.flows.filter((f) => f.nodes.some((n) => paths.has(n)));
|
|
1306
1313
|
}
|
|
1307
1314
|
function buildGlobalLayer(config) {
|
|
1308
1315
|
let content = `**Project:** ${config.name}
|