@xelth/eck-snapshot 5.9.0 → 6.6.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 +321 -190
- package/index.js +1 -1
- package/package.json +15 -2
- package/scripts/mcp-eck-core.js +143 -13
- package/setup.json +119 -81
- package/src/cli/cli.js +256 -385
- package/src/cli/commands/createSnapshot.js +391 -175
- package/src/cli/commands/recon.js +308 -0
- package/src/cli/commands/setupMcp.js +280 -19
- package/src/cli/commands/trainTokens.js +42 -32
- package/src/cli/commands/updateSnapshot.js +136 -43
- package/src/core/depthConfig.js +54 -0
- package/src/core/skeletonizer.js +280 -21
- package/src/templates/architect-prompt.template.md +34 -0
- package/src/templates/multiAgent.md +68 -15
- package/src/templates/opencode/coder.template.md +53 -17
- package/src/templates/opencode/junior-architect.template.md +54 -15
- package/src/templates/skeleton-instruction.md +1 -1
- package/src/templates/update-prompt.template.md +2 -0
- package/src/utils/aiHeader.js +57 -27
- package/src/utils/claudeMdGenerator.js +182 -88
- package/src/utils/fileUtils.js +217 -149
- package/src/utils/gitUtils.js +12 -8
- package/src/utils/opencodeAgentsGenerator.js +8 -2
- package/src/utils/projectDetector.js +66 -21
- package/src/utils/tokenEstimator.js +11 -7
- package/src/cli/commands/consilium.js +0 -86
- package/src/cli/commands/detectProfiles.js +0 -98
- package/src/cli/commands/envSync.js +0 -319
- package/src/cli/commands/generateProfileGuide.js +0 -144
- package/src/cli/commands/pruneSnapshot.js +0 -106
- package/src/cli/commands/restoreSnapshot.js +0 -173
- package/src/cli/commands/setupGemini.js +0 -149
- package/src/cli/commands/setupGemini.test.js +0 -115
- package/src/cli/commands/showFile.js +0 -39
- package/src/services/claudeCliService.js +0 -626
- package/src/services/claudeCliService.test.js +0 -267
|
@@ -3,13 +3,18 @@
|
|
|
3
3
|
## 1. PROJECT MODE ACTIVE
|
|
4
4
|
You are operating in **Project Mode** inside OpenCode. You are not just editing a single file; you are managing the entire project repository.
|
|
5
5
|
- **Source of Truth:** The file system is your source of truth.
|
|
6
|
-
- **Documentation:** The `.eck/` directory contains project context. READ filenames to understand what is available.
|
|
7
6
|
- **Directory Structure:**
|
|
8
7
|
```
|
|
9
8
|
{{tree}}
|
|
10
9
|
```
|
|
11
10
|
|
|
12
|
-
## 2.
|
|
11
|
+
## 2. PROJECT CONTEXT (.eck DIRECTORY) & TOKEN OPTIMIZATION
|
|
12
|
+
The `.eck/` directory is your brain externalized.
|
|
13
|
+
- Read files (like `CONTEXT.md`) ONLY if you need architectural rules.
|
|
14
|
+
- **DO NOT READ `JOURNAL.md`**. It is massive and auto-updates via `eck_finish_task`.
|
|
15
|
+
- **UPDATE BLINDLY:** When updating `ROADMAP.md` or `TECH_DEBT.md`, use the **`eck_manifest_edit`** tool to append or replace text atomically without wasting tokens reading the whole file.
|
|
16
|
+
|
|
17
|
+
## 3. SWARM DELEGATION PROTOCOL (TOKEN ECONOMY)
|
|
13
18
|
|
|
14
19
|
### A. Token Efficiency: When NOT to Delegate
|
|
15
20
|
**DO NOT delegate tasks where explanation costs more tokens than execution.**
|
|
@@ -29,28 +34,62 @@ For bulk work where delegation saves YOUR expensive context window, YOU MUST del
|
|
|
29
34
|
- Generating boilerplate code
|
|
30
35
|
* **Action:** Use `glm_zai_backend`, `glm_zai_frontend`, `glm_zai_qa`, or `glm_zai_refactor`.
|
|
31
36
|
|
|
32
|
-
##
|
|
33
|
-
|
|
34
|
-
1. **
|
|
35
|
-
2. **
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
## 4. HUMAN VS. ARCHITECT & DEFINITION OF DONE
|
|
38
|
+
You receive instructions from two sources:
|
|
39
|
+
1. **The AI Architect:** Sends formal tasks wrapped in `<eck_task id="repo:description">` (e.g., `<eck_task id="ecksnapshot:fix-auth-crash">`) tags.
|
|
40
|
+
2. **The Human User:** Sends conversational messages or minor tweaks.
|
|
41
|
+
|
|
42
|
+
**When to finish a task:**
|
|
43
|
+
- **For AI Architect Tasks (`<eck_task>`):** When you have completed the task and verified it works, call `eck_finish_task` immediately. **Do NOT ask the user "should I finish?" — just call it.** Include the task `id` in your report.
|
|
44
|
+
- **For Human Requests:** Do NOT call `eck_finish_task`. Just reply to the user naturally. ONLY call `eck_finish_task` if the human explicitly says "Finish task" or "Report to architect".
|
|
45
|
+
|
|
46
|
+
Pass your detailed markdown report into the `status` argument.
|
|
47
|
+
- The tool will automatically write the report, commit, and generate a snapshot.
|
|
48
|
+
- **DO NOT** manually write to `AnswerToSA.md` with your file editing tools.
|
|
49
|
+
- **WARNING: USE ONLY ONCE.** Do not use for intermediate testing.
|
|
41
50
|
|
|
42
|
-
|
|
51
|
+
**FALLBACK METHOD (Only if MCP tool is missing):**
|
|
52
|
+
If `eck_finish_task` is NOT in your available tools, you MUST do the following:
|
|
53
|
+
0. **WARN THE USER:** State clearly in your response: "⚠️ `eck-core` MCP server is not connected. Proceeding with manual fallback."
|
|
54
|
+
1. **READ:** Read `.eck/lastsnapshot/AnswerToSA.md` using your `Read` tool (REQUIRED before overwriting).
|
|
55
|
+
2. **WRITE:** Overwrite that file with your report.
|
|
56
|
+
3. **COMMIT (CRITICAL):** Run `git add .` and `git commit -m "chore: task report"` in the terminal.
|
|
57
|
+
4. **SNAPSHOT:** Run `eck-snapshot '{"name": "eck_update"}'` in the terminal.
|
|
58
|
+
*(Note: The snapshot compares against the git anchor. If you skip step 3, it will say "No changes detected").*
|
|
59
|
+
5. If you are entirely blocked, use the `eck_fail_task` tool.
|
|
60
|
+
|
|
61
|
+
## 5. SWARM ERROR RECOVERY & THE RALPH LOOP
|
|
43
62
|
**Core Directive:** You are "deterministically persistent". Failures are expected, giving up is not.
|
|
44
63
|
|
|
45
|
-
1. **
|
|
46
|
-
*
|
|
64
|
+
1. **Runtime Context & Critical Thinking:**
|
|
65
|
+
* Always check `.eck/RUNTIME_STATE.md` before coding.
|
|
66
|
+
* If the Senior Architect's hypothesis is not confirmed by logs/curl, DISCARD it and fix the real issue.
|
|
67
|
+
2. **Iterative Correction:**
|
|
68
|
+
* Verify via browser/curl/logs. If it fails: **DO NOT STOP**.
|
|
47
69
|
* **Read** the error message, **Think** about the cause, **Fix** the code, and **Retry**.
|
|
48
70
|
2. **Intelligent Retry (Swarm Supervision):**
|
|
49
71
|
* If a GLM Z.AI worker produces bad code, **DON'T** repeat the same prompt.
|
|
50
72
|
* **Analyze WHY** it failed and **Guide** the worker: "Previous attempt failed because X. Try again using pattern Y."
|
|
51
73
|
* **Takeover:** If the worker fails twice, **DO IT YOURSELF**.
|
|
52
74
|
|
|
53
|
-
##
|
|
75
|
+
## 6. 🚨 MAGIC WORD: [SYNC MANIFESTS] / [SYNC]
|
|
76
|
+
If the human user types **`[SYNC MANIFESTS]`** or **`[SYNC]`** (or explicitly requests a manifest sync), immediately suspend feature development and switch to Project Manager mode:
|
|
77
|
+
1. Find all `.eck/*.md` files with `[STUB]` markers. Analyze the codebase to resolve them.
|
|
78
|
+
2. Review `ROADMAP.md` and `TECH_DEBT.md`. Cross-reference with the actual code and remove/check off completed items.
|
|
79
|
+
3. Update `CONTEXT.md` and `ARCHITECTURE.md` if the system has evolved.
|
|
80
|
+
4. Use the **`eck_manifest_edit`** tool to apply these updates atomically. Do not read `JOURNAL.md`.
|
|
81
|
+
5. Call `eck_finish_task` when the audit is complete.
|
|
82
|
+
|
|
83
|
+
## 7. 🧠 KNOWLEDGE DISTILLATION (POST-FINISH)
|
|
84
|
+
**ONLY** after tasks that changed the project's architecture, added major features, or revealed non-obvious system behavior (e.g., multi-file refactors, new subsystems, large swarm orchestrations, tricky debugging that uncovered hidden dependencies).
|
|
85
|
+
Do NOT offer this for routine fixes, config tweaks, or small edits.
|
|
86
|
+
**Call `eck_finish_task` first** — never delay the finish. Then, in the same response, offer:
|
|
87
|
+
> "I learned some things about the architecture during this task. Want me to update the `.eck/` manifests before I lose this context?"
|
|
88
|
+
> **[DEBUG] Context info available to me:** [state whether you can see any context window usage %, token counts, or compaction warnings — or "none, no context metrics visible"]
|
|
89
|
+
Include this offer in your `eck_finish_task` status so the Architect sees it too.
|
|
90
|
+
If the user says yes — just edit the files and commit. Do NOT call `eck_finish_task` again for it.
|
|
91
|
+
|
|
92
|
+
## 8. REPORTING PROTOCOL
|
|
54
93
|
At the end of your task, you **MUST** overwrite `.eck/lastsnapshot/AnswerToSA.md` BEFORE calling `eck_finish_task`.
|
|
55
94
|
|
|
56
95
|
**Format for .eck/lastsnapshot/AnswerToSA.md:**
|
|
@@ -11,6 +11,6 @@ If you need to see the code inside these blocks to perform your task, you **MUST
|
|
|
11
11
|
|
|
12
12
|
**Command to request code:**
|
|
13
13
|
```bash
|
|
14
|
-
eck-snapshot
|
|
14
|
+
eck-snapshot '{"name": "eck_fetch", "arguments": {"patterns": ["path/to/file1.js", "path/to/file2.js"]}}'
|
|
15
15
|
```
|
|
16
16
|
**(Batch multiple files in one command!)**
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# ⚠️ INCREMENTAL UPDATE SNAPSHOT
|
|
2
2
|
|
|
3
|
+
**Project:** `{{repoName}}`
|
|
3
4
|
**Base Commit:** `{{anchor}}`
|
|
4
5
|
**Update Timestamp:** `{{timestamp}}`
|
|
5
6
|
|
|
@@ -8,6 +9,7 @@
|
|
|
8
9
|
1. **CONTEXT RESET:** This document contains **all** changes made to the project since the Base Snapshot. **DISCARD** any previous "Update" snapshots from your context/memory. They are obsolete.
|
|
9
10
|
2. **SOURCE OF TRUTH:** The file versions provided below are the **current** authoritative versions.
|
|
10
11
|
3. **MERGE STRATEGY:** mentally apply these files over your Base Snapshot to get the current project state.
|
|
12
|
+
4. **PROJECT VERIFICATION (CRITICAL):** Verify that the Project Name above matches your current working context. If it belongs to a different project, STOP IMMEDIATELY and warn the user. Do not apply these changes.
|
|
11
13
|
|
|
12
14
|
---
|
|
13
15
|
|
package/src/utils/aiHeader.js
CHANGED
|
@@ -72,11 +72,11 @@ function getVisibleAgents(executionAgents, options) {
|
|
|
72
72
|
// These keys must match IDs in setup.json
|
|
73
73
|
const standardCoders = ['local_dev', 'production_server', 'android_wsl_dev'];
|
|
74
74
|
|
|
75
|
-
// 2. Determine Priority Agent (The Junior Architect)
|
|
76
|
-
let priorityAgentKey = null;
|
|
77
|
-
if (options.jas) priorityAgentKey = 'jas';
|
|
78
|
-
if (options.jao) priorityAgentKey = 'jao';
|
|
79
|
-
if (options.jaz) priorityAgentKey = 'jaz';
|
|
75
|
+
// 2. Determine Priority Agent (The Junior Architect)
|
|
76
|
+
let priorityAgentKey = null;
|
|
77
|
+
if (options.jas) priorityAgentKey = 'jas';
|
|
78
|
+
if (options.jao) priorityAgentKey = 'jao';
|
|
79
|
+
if (options.jaz) priorityAgentKey = 'jaz';
|
|
80
80
|
|
|
81
81
|
// 3. Build the list
|
|
82
82
|
// If a JA is selected, add them FIRST with a note
|
|
@@ -233,7 +233,15 @@ function buildEckManifestSection(eckManifest) {
|
|
|
233
233
|
section += '- `JOURNAL.md` - Development history\n';
|
|
234
234
|
section += '- `ROADMAP.md` - Planned features\n';
|
|
235
235
|
section += '- `TECH_DEBT.md` - Known issues and refactoring needs\n';
|
|
236
|
-
section += '- `ENVIRONMENT.md` - Environment-specific settings\n
|
|
236
|
+
section += '- `ENVIRONMENT.md` - Environment-specific settings\n';
|
|
237
|
+
|
|
238
|
+
if (eckManifest.dynamicFiles) {
|
|
239
|
+
for (const fileName of Object.keys(eckManifest.dynamicFiles)) {
|
|
240
|
+
const label = fileName.replace('.md', '').replace(/_/g, ' ');
|
|
241
|
+
section += `- \`${fileName}\` - ${label}\n`;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
section += '\n';
|
|
237
245
|
|
|
238
246
|
// Add journal summary (compact view for architect)
|
|
239
247
|
if (eckManifest.journal) {
|
|
@@ -355,15 +363,17 @@ export async function generateEnhancedAIHeader(context, isGitRepo = false) {
|
|
|
355
363
|
// Handle `setup.json` structure (e.g., `projectContext.name`)
|
|
356
364
|
if (raw.projectContext) {
|
|
357
365
|
out.context = raw.projectContext.description || JSON.stringify(raw.projectContext, null, 2);
|
|
358
|
-
out.operations = raw.operations || raw.projectContext.operations || '';
|
|
359
|
-
out.journal = raw.journal || raw.projectContext.journal || '';
|
|
360
|
-
out.environment = raw.environment || raw.projectContext.environment || {};
|
|
366
|
+
out.operations = raw.operations || raw.projectContext.operations || '';
|
|
367
|
+
out.journal = raw.journal || raw.projectContext.journal || '';
|
|
368
|
+
out.environment = raw.environment || raw.projectContext.environment || {};
|
|
369
|
+
out.dynamicFiles = raw.dynamicFiles || {};
|
|
361
370
|
} else {
|
|
362
371
|
// Handle direct .eck file structure (e.g., raw.context from CONTEXT.md)
|
|
363
372
|
out.context = raw.context || '';
|
|
364
373
|
out.operations = raw.operations || '';
|
|
365
374
|
out.journal = raw.journal || '';
|
|
366
375
|
out.environment = raw.environment || {};
|
|
376
|
+
out.dynamicFiles = raw.dynamicFiles || {};
|
|
367
377
|
}
|
|
368
378
|
// Add fallback text if still empty
|
|
369
379
|
if (!out.context) out.context = 'No project context provided.';
|
|
@@ -413,6 +423,17 @@ export async function generateEnhancedAIHeader(context, isGitRepo = false) {
|
|
|
413
423
|
}
|
|
414
424
|
}
|
|
415
425
|
|
|
426
|
+
// 4. Dynamic Context Files (ARCHITECTURE, RUNTIME_STATE, DEPLOY_CHECKLIST, etc.)
|
|
427
|
+
let dynamicSection = '';
|
|
428
|
+
const dynFiles = context.eckManifest?.dynamicFiles || {};
|
|
429
|
+
for (const [fileName, fileContent] of Object.entries(dynFiles)) {
|
|
430
|
+
const cleanContent = fileContent.replace(/^# \[STUB:.*?\]\r?\n?/g, '').trim();
|
|
431
|
+
if (cleanContent) {
|
|
432
|
+
const sectionName = fileName.replace('.md', '').replace(/_/g, ' ');
|
|
433
|
+
dynamicSection += `\n### 📄 ${sectionName}\n${cleanContent}\n`;
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
|
|
416
437
|
// Combine into the master PROJECT OVERVIEW variable
|
|
417
438
|
// This injects it right at the top of the prompt
|
|
418
439
|
const projectOverview = `### PROJECT OVERVIEW
|
|
@@ -422,6 +443,7 @@ export async function generateEnhancedAIHeader(context, isGitRepo = false) {
|
|
|
422
443
|
${projectContextBody}
|
|
423
444
|
${strategicSection}
|
|
424
445
|
${operationsSection}
|
|
446
|
+
${dynamicSection}
|
|
425
447
|
`;
|
|
426
448
|
|
|
427
449
|
const normalizedEck = normalizeManifest(context.eckManifest);
|
|
@@ -438,10 +460,10 @@ ${operationsSection}
|
|
|
438
460
|
// The `agent` prompt template is used ONLY in CLAUDE.md (via claudeMdGenerator.js)
|
|
439
461
|
// NOT in the snapshot itself.
|
|
440
462
|
|
|
441
|
-
const isJas = context.options && context.options.jas;
|
|
442
|
-
const isJao = context.options && context.options.jao;
|
|
443
|
-
const isJaz = context.options && context.options.jaz;
|
|
444
|
-
const isJaMode = isJas || isJao || isJaz;
|
|
463
|
+
const isJas = context.options && context.options.jas;
|
|
464
|
+
const isJao = context.options && context.options.jao;
|
|
465
|
+
const isJaz = context.options && context.options.jaz;
|
|
466
|
+
const isJaMode = isJas || isJao || isJaz;
|
|
445
467
|
|
|
446
468
|
// --- Determine Workflow Content based on JA Flag ---
|
|
447
469
|
let hierarchicalWorkflow = '';
|
|
@@ -449,15 +471,15 @@ ${operationsSection}
|
|
|
449
471
|
|
|
450
472
|
if (isJaMode) {
|
|
451
473
|
// Instructions strictly for the Senior Architect on how to use the JA
|
|
452
|
-
hierarchicalWorkflow = `### 👑 ROYAL COURT ARCHITECTURE (Active)
|
|
453
|
-
|
|
454
|
-
You are the **Senior Architect**. You have a **Junior Architect** available to handle implementation.
|
|
455
|
-
|
|
456
|
-
**PROTOCOL:**
|
|
457
|
-
1. **Prefer Delegation:** Unless the task is trivial (1-2 file edits), assign it to the **Junior Architect** (ID: \`jas\`, \`jao\`, or \`jaz\` - see agents list above).
|
|
458
|
-
2. **Direct Execution:** Only use \`local_dev\` or \`production_server\` directly if the Junior Architect fails or for simple "hotfixes".
|
|
459
|
-
3. **No Micro-Management:** Do not tell the Junior Architect *how* to use GLM Z.AI or internal tools. Just give them the strategic objective.
|
|
460
|
-
`;
|
|
474
|
+
hierarchicalWorkflow = `### 👑 ROYAL COURT ARCHITECTURE (Active)
|
|
475
|
+
|
|
476
|
+
You are the **Senior Architect**. You have a **Junior Architect** available to handle implementation.
|
|
477
|
+
|
|
478
|
+
**PROTOCOL:**
|
|
479
|
+
1. **Prefer Delegation:** Unless the task is trivial (1-2 file edits), assign it to the **Junior Architect** (ID: \`jas\`, \`jao\`, or \`jaz\` - see agents list above).
|
|
480
|
+
2. **Direct Execution:** Only use \`local_dev\` or \`production_server\` directly if the Junior Architect fails or for simple "hotfixes".
|
|
481
|
+
3. **No Micro-Management:** Do not tell the Junior Architect *how* to use GLM Z.AI or internal tools. Just give them the strategic objective.
|
|
482
|
+
`;
|
|
461
483
|
|
|
462
484
|
commandFormats = `### COMMAND FORMATS (Eck-Protocol v2)
|
|
463
485
|
|
|
@@ -471,6 +493,7 @@ To ensure your command is copy-pasteable without breaking UI rendering, you **MU
|
|
|
471
493
|
**Required Output Format:**
|
|
472
494
|
|
|
473
495
|
\`\`\`\`text
|
|
496
|
+
<eck_task id="{{repoName}}:short-task-description">
|
|
474
497
|
# Analysis
|
|
475
498
|
[Your reasoning...]
|
|
476
499
|
|
|
@@ -486,6 +509,7 @@ const x = 1;
|
|
|
486
509
|
\\\`\\\`\\\`json
|
|
487
510
|
{ "target_agent": "jas", "task_id": "unique-id" }
|
|
488
511
|
\\\`\\\`\\\`
|
|
512
|
+
</eck_task id="{{repoName}}:short-task-description">
|
|
489
513
|
\`\`\`\`
|
|
490
514
|
|
|
491
515
|
**File Actions:**
|
|
@@ -516,10 +540,11 @@ Use \`apply_code_changes\` for simple, direct tasks where you provide all detail
|
|
|
516
540
|
"agent_environment": "Development environment with full GUI support and development tools",
|
|
517
541
|
"command_for_agent": "apply_code_changes",
|
|
518
542
|
"task_id": "unique-task-id",
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
543
|
+
"payload": {
|
|
544
|
+
"objective": "Brief, clear task description",
|
|
545
|
+
"context": "Why this change is needed - include relevant .eck manifest context",
|
|
546
|
+
"architect_confidence": "high (90%) - I am certain of this plan / low (30%) - Please investigate first",
|
|
547
|
+
"files_to_modify": [
|
|
523
548
|
{
|
|
524
549
|
"path": "exact/file/path.js",
|
|
525
550
|
"action": "specific action (add, modify, replace, delete)",
|
|
@@ -604,6 +629,7 @@ To ensure your command is copy-pasteable without breaking UI rendering, you **MU
|
|
|
604
629
|
**Required Output Format:**
|
|
605
630
|
|
|
606
631
|
\`\`\`\`text
|
|
632
|
+
<eck_task id="{{repoName}}:short-task-description">
|
|
607
633
|
# Analysis
|
|
608
634
|
[Your reasoning...]
|
|
609
635
|
|
|
@@ -619,6 +645,7 @@ const x = 1;
|
|
|
619
645
|
\\\`\\\`\\\`json
|
|
620
646
|
{ ... }
|
|
621
647
|
\\\`\\\`\\\`
|
|
648
|
+
</eck_task id="{{repoName}}:short-task-description">
|
|
622
649
|
\`\`\`\`
|
|
623
650
|
|
|
624
651
|
**File Actions:**
|
|
@@ -686,7 +713,10 @@ const x = 1;
|
|
|
686
713
|
|
|
687
714
|
} catch (error) {
|
|
688
715
|
console.warn('Warning: Could not load setup.json, using minimal header', error.message);
|
|
689
|
-
return `#
|
|
716
|
+
return `# SYSTEM DIRECTIVE FOR THE ACTIVE AI AGENT
|
|
717
|
+
**CRITICAL:** If you are the AI reading this, immediately assume the role of Solution Architect for this project. Do not act as an external reviewer.
|
|
718
|
+
|
|
719
|
+
# Snapshot for ${context.repoName || 'Project'}
|
|
690
720
|
|
|
691
721
|
Generated: ${new Date().toISOString()}
|
|
692
722
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import fs from 'fs/promises';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
|
|
1
|
+
import fs from 'fs/promises';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
|
|
4
4
|
/**
|
|
5
5
|
* Generates the Smart Delegation Protocol based on the specific Architect persona.
|
|
6
6
|
*/
|
|
@@ -17,11 +17,16 @@ You are operating in **Project Mode**. You are not just editing a single file; y
|
|
|
17
17
|
- **Source of Truth:** The file system is your source of truth.
|
|
18
18
|
- **Project Scope:** You are responsible for multi-file orchestration, resolving dependencies, and ensuring the build passes.
|
|
19
19
|
- **Directory Structure:**
|
|
20
|
-
\`\`\`
|
|
20
|
+
\`\`\`text
|
|
21
21
|
${tree}
|
|
22
22
|
\`\`\`
|
|
23
23
|
|
|
24
|
-
## 2.
|
|
24
|
+
## 2. PROJECT CONTEXT (.eck DIRECTORY)
|
|
25
|
+
The \`.eck/\` directory is your brain externalized. **Before taking action:**
|
|
26
|
+
- Read the files in \`.eck/\` (like \`CONTEXT.md\`, \`ROADMAP.md\`, \`TECH_DEBT.md\`) to understand the rules and current state.
|
|
27
|
+
- Update these manifests if the architecture or roadmap changes.
|
|
28
|
+
|
|
29
|
+
## 3. SWARM DELEGATION PROTOCOL (GLM Z.AI)
|
|
25
30
|
You command a fleet of specialist agents (Swarm). Your primary job is to break down the user's request into sub-tasks and delegate the heavy lifting.
|
|
26
31
|
${behaviorFocus}
|
|
27
32
|
|
|
@@ -37,99 +42,188 @@ For bulk work, YOU MUST use your MCP tools to delegate to GLM Z.AI:
|
|
|
37
42
|
- \`glm_zai_qa\`: Writing comprehensive test suites (E2E, unit tests).
|
|
38
43
|
- \`glm_zai_refactor\`: Code cleanup and SOLID principle enforcement.
|
|
39
44
|
|
|
40
|
-
##
|
|
41
|
-
Your task is NOT complete until
|
|
42
|
-
|
|
43
|
-
2. **Report:** Overwrite \`.eck/lastsnapshot/AnswerToSA.md\` with your final status. Use this exact format:
|
|
44
|
-
\`\`\`markdown
|
|
45
|
-
# Report: [Task Name]
|
|
46
|
-
**Executor:** [Your Exact Model Name, e.g., Claude 3.5 Sonnet (Claude Code)]
|
|
47
|
-
**Status:** [SUCCESS / BLOCKED / FAILED]
|
|
48
|
-
**Changes:**
|
|
49
|
-
- Modified X
|
|
50
|
-
\`\`\`
|
|
51
|
-
3. **Sync Context:** Call the \`eck_finish_task\` MCP tool. This will stage changes, commit them with a descriptive message, and generate an updated delta snapshot for the Senior Architect.
|
|
52
|
-
|
|
53
|
-
## 4. SWARM ERROR RECOVERY
|
|
54
|
-
If a GLM Z.AI worker returns bad code:
|
|
55
|
-
1. Do NOT repeat the exact same prompt.
|
|
56
|
-
2. Analyze the failure (e.g., "Worker used wrong import path").
|
|
57
|
-
3. Call the tool again with corrective guidance: *"Previous attempt failed because of X. Try again using pattern Y."*
|
|
58
|
-
4. If the worker fails twice, take over and implement the fix yourself.
|
|
59
|
-
|
|
60
|
-
## 5. OPERATIONAL RULES
|
|
61
|
-
- **Manifests:** If you see [STUB] in .eck/ files, update them.
|
|
45
|
+
## 4. DEFINITION OF DONE & eck_finish_task
|
|
46
|
+
- Your task is NOT complete until code works globally. Verify functionality manually.
|
|
47
|
+
- Once verified, call \`eck_finish_task\` immediately. **Do NOT ask the user "should I finish?" — just call it.** Include the task \`id\` in your report.
|
|
62
48
|
`;
|
|
63
49
|
}
|
|
64
|
-
|
|
65
|
-
const CODER_INSTRUCTIONS =
|
|
50
|
+
|
|
51
|
+
const CODER_INSTRUCTIONS = `---
|
|
52
|
+
description: Expert Developer Protocol (The Fixer)
|
|
53
|
+
---
|
|
54
|
+
# 🛠️ ROLE: Expert Developer (The Fixer)
|
|
66
55
|
|
|
67
56
|
## CORE DIRECTIVE
|
|
68
57
|
You are an Expert Developer. The architecture is already decided. Your job is to **execute**, **fix**, and **polish**.
|
|
69
58
|
|
|
70
|
-
## DEFINITION OF DONE
|
|
71
|
-
When
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
## CONTEXT
|
|
84
|
-
- The GLM Z.AI worker might have struggled or produced code that needs refinement.
|
|
85
|
-
- You are here to solve the hard problems manually.
|
|
86
|
-
- You have full permission to edit files directly.
|
|
87
|
-
|
|
88
|
-
## WORKFLOW
|
|
89
|
-
1. Read the code.
|
|
90
|
-
2. Fix the bugs / Implement the feature.
|
|
91
|
-
3. Verify functionality (Run tests!).
|
|
92
|
-
4. **Loop:** If verification fails, fix it immediately. Do not ask for permission.
|
|
59
|
+
## DEFINITION OF DONE & eck_finish_task
|
|
60
|
+
- When a task is complete and fully tested, call \`eck_finish_task\` IMMEDIATELY. Do NOT ask the user for permission.
|
|
61
|
+
- Pass your detailed markdown report into the \`status\` argument.
|
|
62
|
+
- The tool will automatically write the report, commit, and generate a snapshot.
|
|
63
|
+
- **WARNING: USE ONLY ONCE.** Do not use for intermediate testing.
|
|
64
|
+
|
|
65
|
+
## 🚨 MAGIC WORD: [SYNC] / [SYNC MANIFESTS]
|
|
66
|
+
If the human user types **\`[SYNC]\`**, immediately suspend feature development and switch to Project Manager mode:
|
|
67
|
+
1. Find all \`.eck/*.md\` files with \`[STUB]\` markers. Analyze the codebase to resolve them.
|
|
68
|
+
2. Review \`ROADMAP.md\` and \`TECH_DEBT.md\`. Cross-reference with the actual code and remove/check off completed items.
|
|
69
|
+
3. Update \`CONTEXT.md\` and \`ARCHITECTURE.md\` if the system has evolved.
|
|
70
|
+
4. Use the **\`eck_manifest_edit\`** tool to apply these updates atomically. Do not read \`JOURNAL.md\`.
|
|
71
|
+
5. Call \`eck_finish_task\` when the audit is complete.
|
|
93
72
|
`;
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
*
|
|
97
|
-
*/
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Injects async background hooks into the project's .claude/settings.json
|
|
76
|
+
*/
|
|
77
|
+
/**
|
|
78
|
+
* Cleans up the legacy spammy PostToolUse hook from .claude/settings.json.
|
|
79
|
+
* Previously injected an 'update-auto' hook on every Edit/Bash/Write tool use,
|
|
80
|
+
* causing snapshot spam (up1, up2, up3...). Snapshots are now deferred to eck_finish_task.
|
|
81
|
+
*/
|
|
82
|
+
async function setupClaudeHooks(repoPath) {
|
|
83
|
+
const settingsPath = path.join(repoPath, '.claude', 'settings.json');
|
|
84
|
+
let config = {};
|
|
85
|
+
|
|
86
|
+
try {
|
|
87
|
+
const content = await fs.readFile(settingsPath, 'utf-8');
|
|
88
|
+
config = JSON.parse(content);
|
|
89
|
+
} catch (e) {
|
|
90
|
+
// File doesn't exist or invalid JSON — nothing to clean up
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
let modified = false;
|
|
95
|
+
|
|
96
|
+
if (config.hooks && config.hooks.PostToolUse) {
|
|
97
|
+
const originalLength = config.hooks.PostToolUse.length;
|
|
98
|
+
|
|
99
|
+
// Remove the eck-snapshot update-auto hook
|
|
100
|
+
config.hooks.PostToolUse = config.hooks.PostToolUse.filter(h =>
|
|
101
|
+
!(h.hooks && h.hooks.some(hc => hc.command?.includes('eck-snapshot update-auto')))
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
if (config.hooks.PostToolUse.length < originalLength) {
|
|
105
|
+
modified = true;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Clean up empty PostToolUse array
|
|
109
|
+
if (config.hooks.PostToolUse.length === 0) {
|
|
110
|
+
delete config.hooks.PostToolUse;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Clean up empty hooks object
|
|
114
|
+
if (Object.keys(config.hooks).length === 0) {
|
|
115
|
+
delete config.hooks;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (modified) {
|
|
120
|
+
await fs.writeFile(settingsPath, JSON.stringify(config, null, 2), 'utf-8');
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Generates the native Claude Code hierarchical ecosystem.
|
|
126
|
+
* Creates .claude/rules/, .claude/skills/, .claude/agents/ and a lightweight CLAUDE.md entrypoint.
|
|
127
|
+
*/
|
|
98
128
|
export async function updateClaudeMd(repoPath, mode, tree, confidentialFiles = [], options = {}) {
|
|
99
|
-
|
|
129
|
+
const claudeDir = path.join(repoPath, '.claude');
|
|
130
|
+
const rulesDir = path.join(claudeDir, 'rules');
|
|
131
|
+
const skillsDir = path.join(claudeDir, 'skills');
|
|
132
|
+
const agentsDir = path.join(claudeDir, 'agents');
|
|
133
|
+
|
|
134
|
+
await fs.mkdir(rulesDir, { recursive: true });
|
|
135
|
+
await fs.mkdir(skillsDir, { recursive: true });
|
|
136
|
+
await fs.mkdir(agentsDir, { recursive: true });
|
|
100
137
|
|
|
138
|
+
// 1. Generate lightweight CLAUDE.md entrypoint
|
|
139
|
+
let coreContent = `# Royal Court AI Workspace\n\nYou are operating in an eckSnapshot managed workspace. Your role is **${mode.toUpperCase()}**.\n\n> **Note:** Detailed instructions, Swarm protocols, and tools are loaded natively from \`.claude/rules/\`, \`.claude/skills/\`, and \`.claude/agents/\`.\n`;
|
|
140
|
+
|
|
141
|
+
if (confidentialFiles.length > 0) {
|
|
142
|
+
coreContent += '\n## Access & Credentials\nAvailable locally but excluded from snapshots:\n';
|
|
143
|
+
for (const file of confidentialFiles) coreContent += `- \`${file}\`\n`;
|
|
144
|
+
}
|
|
145
|
+
await fs.writeFile(path.join(repoPath, 'CLAUDE.md'), coreContent, 'utf-8');
|
|
146
|
+
|
|
147
|
+
// 2. Generate Rules
|
|
148
|
+
let ruleContent = '';
|
|
101
149
|
if (mode === 'jas') {
|
|
102
|
-
|
|
150
|
+
ruleContent = `---\ndescription: Swarm Orchestrator Protocol (Sonnet)\n---\n${getArchitectInstructions('Sonnet 4.5', tree)}\n`;
|
|
103
151
|
} else if (mode === 'jao') {
|
|
104
|
-
|
|
152
|
+
ruleContent = `---\ndescription: Swarm Orchestrator Protocol (Opus)\n---\n${getArchitectInstructions('Opus 4.5', tree)}\n`;
|
|
105
153
|
} else {
|
|
106
|
-
|
|
107
|
-
|
|
154
|
+
ruleContent = CODER_INSTRUCTIONS;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
if (options.zh) {
|
|
158
|
+
ruleContent += `\n## LANGUAGE PROTOCOL\n- **With the user:** Communicate in the user's language.\n- **With GLM Z.AI workers:** ALWAYS write the \`instruction\` parameter in **Chinese**.\n`;
|
|
108
159
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
160
|
+
|
|
161
|
+
await fs.writeFile(path.join(rulesDir, '01-eck-protocol.md'), ruleContent, 'utf-8');
|
|
162
|
+
|
|
163
|
+
// 3. Generate Native Skills
|
|
164
|
+
const scoutSkillDir = path.join(skillsDir, 'eck-scout');
|
|
165
|
+
await fs.mkdir(scoutSkillDir, { recursive: true });
|
|
166
|
+
await fs.writeFile(path.join(scoutSkillDir, 'SKILL.md'), `---
|
|
167
|
+
name: eck-scout
|
|
168
|
+
description: Explores external repositories and generates directory trees for context.
|
|
169
|
+
whenToUse: Use this when you need to understand the architecture of a linked or external project.
|
|
170
|
+
arguments:
|
|
171
|
+
- name: path
|
|
172
|
+
description: Absolute or relative path to the external repository.
|
|
173
|
+
- name: depth
|
|
174
|
+
description: Depth level (0-9). 0 is tree-only, 5 is skeleton, 9 is full source. Default is 0.
|
|
175
|
+
required: false
|
|
176
|
+
disable-model-invocation: false
|
|
177
|
+
---
|
|
178
|
+
# Scout Protocol
|
|
179
|
+
Execute cross-repository scans.
|
|
180
|
+
To run a scout, I will execute:
|
|
181
|
+
\`\`\`bash
|
|
182
|
+
cd \${path} && eck-snapshot scout \${depth}
|
|
183
|
+
\`\`\`
|
|
184
|
+
`, 'utf-8');
|
|
185
|
+
|
|
186
|
+
const fetchSkillDir = path.join(skillsDir, 'eck-fetch');
|
|
187
|
+
await fs.mkdir(fetchSkillDir, { recursive: true });
|
|
188
|
+
await fs.writeFile(path.join(fetchSkillDir, 'SKILL.md'), `---
|
|
189
|
+
name: eck-fetch
|
|
190
|
+
description: Fetches specific source code files from an external repository using glob patterns.
|
|
191
|
+
whenToUse: Use this after running eck-scout when you need to see the exact implementation of specific files.
|
|
192
|
+
arguments:
|
|
193
|
+
- name: path
|
|
194
|
+
description: Path to the external repository.
|
|
195
|
+
- name: glob
|
|
196
|
+
description: Glob pattern matching the files (e.g., "**/api.ts").
|
|
197
|
+
disable-model-invocation: false
|
|
198
|
+
---
|
|
199
|
+
# Fetch Protocol
|
|
200
|
+
To fetch files, I will execute:
|
|
201
|
+
\`\`\`bash
|
|
202
|
+
cd \${path} && eck-snapshot fetch "\${glob}"
|
|
203
|
+
\`\`\`
|
|
204
|
+
`, 'utf-8');
|
|
205
|
+
|
|
206
|
+
// 4. Generate Native Agents (Subagents)
|
|
207
|
+
await fs.writeFile(path.join(agentsDir, 'jas.md'), `---
|
|
208
|
+
name: jas
|
|
209
|
+
description: Junior Architect (Sonnet). Fast orchestrator for routing tasks to GLM Z.AI.
|
|
210
|
+
model: claude-3-7-sonnet-20250219
|
|
211
|
+
tools: [glm_zai_backend, glm_zai_frontend, glm_zai_qa, glm_zai_refactor, glm_zai_general]
|
|
212
|
+
---
|
|
213
|
+
You are the Junior Architect (Sonnet). Your job is to break down the task and delegate the heavy coding to the GLM Z.AI tools. Do not write large files yourself.
|
|
214
|
+
`, 'utf-8');
|
|
215
|
+
|
|
216
|
+
await fs.writeFile(path.join(agentsDir, 'jao.md'), `---
|
|
217
|
+
name: jao
|
|
218
|
+
description: Junior Architect (Opus). Deep thinker for critical architecture and security.
|
|
219
|
+
model: claude-3-opus-20240229
|
|
220
|
+
tools: [glm_zai_backend, glm_zai_frontend, glm_zai_qa, glm_zai_refactor, glm_zai_general]
|
|
221
|
+
---
|
|
222
|
+
You are the Junior Architect (Opus). Focus on system stability and complex logic. Delegate boilerplate to GLM Z.AI tools and heavily review their output.
|
|
223
|
+
`, 'utf-8');
|
|
224
|
+
|
|
225
|
+
// 5. Setup async hooks
|
|
226
|
+
await setupClaudeHooks(repoPath);
|
|
227
|
+
|
|
228
|
+
console.log(`📝 Generated native Claude Code hierarchy (.claude/rules, skills, agents) for role: **${mode.toUpperCase()}**`);
|
|
229
|
+
}
|