@xelth/eck-snapshot 5.8.6 β†’ 6.0.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.

Potentially problematic release.


This version of @xelth/eck-snapshot might be problematic. Click here for more details.

@@ -1,74 +1,75 @@
1
- # 🧠 ROLE: Junior Architect (Sonnet 4.5)
1
+ # 🧠 ROLE: Swarm Orchestrator & Junior Architect (GLM-4.7)
2
2
 
3
- ## 1. PROJECT CONTEXT & MEMORY
4
- You are working inside the repository.
3
+ ## 1. PROJECT MODE ACTIVE
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. SMART DELEGATION PROTOCOL (TOKEN ECONOMY)
11
+ ## 2. PROJECT CONTEXT (.eck DIRECTORY)
12
+ The `.eck/` directory is your brain externalized. **Before taking action:**
13
+ - Read the files in `.eck/` (like `CONTEXT.md`, `ROADMAP.md`, `TECH_DEBT.md`) to understand the rules and current state.
14
+ - Update these manifests if the architecture or roadmap changes.
15
+
16
+ ## 3. SWARM DELEGATION PROTOCOL (TOKEN ECONOMY)
13
17
 
14
18
  ### A. Token Efficiency: When NOT to Delegate
15
19
  **DO NOT delegate tasks where explanation costs more tokens than execution.**
16
20
  * *Examples:*
17
- - Reading a config file β†’ Just use \`Read\` tool (1 tool call vs explaining to GLM ZAI)
18
- - Checking if file exists β†’ Use \`Bash test -f\` or \`Read\`
19
- - Fixing a typo β†’ Use \`Edit\` tool directly
21
+ - Reading a config file β†’ Just use `Read` tool (1 tool call vs explaining to GLM Z.AI)
22
+ - Checking if file exists β†’ Use `Bash test -f` or `Read`
23
+ - Fixing a typo β†’ Use `Edit` tool directly
20
24
  - Writing < 50 lines of glue code
21
25
  * **Rule:** If you can solve it in 1-2 tool calls, DO IT YOURSELF.
22
26
 
23
- ### B. Heavy Lifting (DELEGATE TO GLM ZAI)
24
- For bulk work where delegation saves YOUR expensive context:
27
+ ### B. Heavy Lifting (DELEGATE TO WORKERS)
28
+ For bulk work where delegation saves YOUR expensive context window, YOU MUST delegate to your GLM Z.AI Swarm:
25
29
  * *Examples:*
26
30
  - Implementing complex business logic (> 100 lines)
27
31
  - Refactoring entire modules
28
32
  - Writing comprehensive test suites
29
33
  - Generating boilerplate code
30
- * **Action:** Use \`glm_zai_backend\`, \`glm_zai_frontend\`, \`glm_zai_qa\`, or \`glm_zai_refactor\`.
34
+ * **Action:** Use `glm_zai_backend`, `glm_zai_frontend`, `glm_zai_qa`, or `glm_zai_refactor`.
31
35
 
32
- ## 3. DEFINITION OF DONE (CRITICAL)
33
- When you have completed your coding task and verified it works:
34
- 1. **DO NOT** run \`git commit\` manually.
35
- 2. **DO NOT** just say "I'm done".
36
- 3. **Use the \`eck_finish_task\` tool** to finalize the task.
37
- - This tool automatically:
38
- - Updates \`.eck/lastsnapshot/AnswerToSA.md\` with your status
39
- - Creates a proper git commit with Co-Authored-By attribution
40
- - Generates a delta snapshot (\`eck-snapshot update-auto\`) for context sync
41
- - This is the standard way to complete any task.
36
+ ## 4. DEFINITION OF DONE (CRITICAL)
37
+ When you have completed your coding task and verified it works, you must report back and sync context.
42
38
 
43
- ## 4. THE RALPH WIGGUM PROTOCOL (AUTONOMOUS LOOPS)
44
- **Core Directive:** You are "deterministically persistent". Failures are expected, giving up is not.
39
+ **OPTION A: Using MCP Tool (Recommended)**
40
+ Call the \`eck_finish_task\` tool. Pass your detailed markdown report into the \`status\` argument.
41
+ - The tool will automatically write the report to \`AnswerToSA.md\`, commit, and generate a snapshot.
42
+ - **DO NOT** manually write to \`AnswerToSA.md\` with your file editing tools.
43
+ - **WARNING: USE ONLY ONCE.** Do not use \`eck_finish_task\` for intermediate testing. It spams snapshot history.
45
44
 
46
- 1. **Iterative Correction:**
47
- * If a build fails or tests turn red: **DO NOT STOP**.
48
- * **Read** the error message.
49
- * **Think** about the cause.
50
- * **Fix** the code.
51
- * **Retry** the verification command.
52
- * *Repeat this loop up to 3-4 times.*
45
+ **OPTION B: Manual CLI (Fallback)**
46
+ If the MCP tool is unavailable:
47
+ 1. **READ** \`.eck/lastsnapshot/AnswerToSA.md\` using your \`Read\` tool (REQUIRED by safety rules before overwriting).
48
+ 2. **WRITE** your report to that file.
49
+ 3. Run \`eck-snapshot update\` in terminal.
50
+ 4. If you are entirely blocked, use the \`eck_fail_task\` tool.
53
51
 
54
- 2. **Intelligent Retry (GLM ZAI Supervision):**
55
- * If a GLM ZAI worker produces bad code:
56
- * **DON'T** repeat the same prompt.
57
- * **Analyze WHY** it failed (missing context? wrong import?).
58
- * **Guide** the worker: "Previous attempt failed because X. Try again using pattern Y."
59
- * **Takeover:** If GLM ZAI fails twice, **DO IT YOURSELF**.
52
+ ## 5. SWARM ERROR RECOVERY & THE RALPH LOOP
53
+ **Core Directive:** You are "deterministically persistent". Failures are expected, giving up is not.
60
54
 
61
- 3. **Definition of Done:**
62
- * A task is ONLY done when the verification command (e.g., \`npm test\`) exits with code 0.
63
- * If you cannot achieve green tests after max retries, produce a detailed report of *why* it is blocked.
55
+ 1. **Runtime Context & Critical Thinking:**
56
+ * Always check `.eck/RUNTIME_STATE.md` before coding.
57
+ * If the Senior Architect's hypothesis is not confirmed by logs/curl, DISCARD it and fix the real issue.
58
+ 2. **Iterative Correction:**
59
+ * Verify via browser/curl/logs. If it fails: **DO NOT STOP**.
60
+ * **Read** the error message, **Think** about the cause, **Fix** the code, and **Retry**.
61
+ 2. **Intelligent Retry (Swarm Supervision):**
62
+ * If a GLM Z.AI worker produces bad code, **DON'T** repeat the same prompt.
63
+ * **Analyze WHY** it failed and **Guide** the worker: "Previous attempt failed because X. Try again using pattern Y."
64
+ * **Takeover:** If the worker fails twice, **DO IT YOURSELF**.
64
65
 
65
- ## 5. REPORTING PROTOCOL
66
- At the end of your task, you **MUST** create or overwrite the file \`.eck/lastsnapshot/AnswerToSA.md\` BEFORE calling \`eck_finish_task\`.
67
- This file communicates your results back to the Senior Architect (Gemini).
66
+ ## 6. REPORTING PROTOCOL
67
+ At the end of your task, you **MUST** overwrite `.eck/lastsnapshot/AnswerToSA.md` BEFORE calling `eck_finish_task`.
68
68
 
69
69
  **Format for .eck/lastsnapshot/AnswerToSA.md:**
70
- \`\`\`markdown
70
+ ```markdown
71
71
  # Report: [Task Name]
72
+ **Executor:** [Your Exact Model Name, e.g., GLM-4.7 (OpenCode)]
72
73
  **Status:** [SUCCESS / BLOCKED / FAILED]
73
74
  **Changes:**
74
75
  - Modified X
@@ -77,9 +78,4 @@ This file communicates your results back to the Senior Architect (Gemini).
77
78
  - Ran test Z -> Passed
78
79
  **Next Steps / Questions:**
79
80
  - [What should the Architect do next?]
80
- \`\`\`
81
-
82
- ## 6. OPERATIONAL RULES
83
- - **Commits:** Use the \`eck_finish_task\` tool for committing and updating context.
84
- - **Manifests:** If you see [STUB] in .eck/ files, update them.
85
- - **Reporting:** NEVER finish a session without writing \`.eck/lastsnapshot/AnswerToSA.md\` and calling \`eck_finish_task\`.
81
+ ```
@@ -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.jag) priorityAgentKey = 'jag';
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
@@ -438,10 +438,10 @@ ${operationsSection}
438
438
  // The `agent` prompt template is used ONLY in CLAUDE.md (via claudeMdGenerator.js)
439
439
  // NOT in the snapshot itself.
440
440
 
441
- const isJag = context.options && context.options.jag;
442
- const isJas = context.options && context.options.jas;
443
- const isJao = context.options && context.options.jao;
444
- const isJaMode = isJag || isJas || isJao;
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;
445
445
 
446
446
  // --- Determine Workflow Content based on JA Flag ---
447
447
  let hierarchicalWorkflow = '';
@@ -449,15 +449,15 @@ ${operationsSection}
449
449
 
450
450
  if (isJaMode) {
451
451
  // 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 \`jag\` - 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
- `;
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
+ `;
461
461
 
462
462
  commandFormats = `### COMMAND FORMATS (Eck-Protocol v2)
463
463
 
@@ -516,10 +516,11 @@ Use \`apply_code_changes\` for simple, direct tasks where you provide all detail
516
516
  "agent_environment": "Development environment with full GUI support and development tools",
517
517
  "command_for_agent": "apply_code_changes",
518
518
  "task_id": "unique-task-id",
519
- "payload": {
520
- "objective": "Brief, clear task description",
521
- "context": "Why this change is needed - include relevant .eck manifest context",
522
- "files_to_modify": [
519
+ "payload": {
520
+ "objective": "Brief, clear task description",
521
+ "context": "Why this change is needed - include relevant .eck manifest context",
522
+ "architect_confidence": "high (90%) - I am certain of this plan / low (30%) - Please investigate first",
523
+ "files_to_modify": [
523
524
  {
524
525
  "path": "exact/file/path.js",
525
526
  "action": "specific action (add, modify, replace, delete)",
@@ -1,153 +1,142 @@
1
- import fs from 'fs/promises';
2
- import path from 'path';
3
-
4
- /**
5
- * Generates the Smart Delegation Protocol based on the specific Architect persona.
6
- */
7
- function getArchitectInstructions(modelName, tree) {
8
- const isOpus = modelName.includes('Opus');
9
-
10
- return `# 🧠 ROLE: Junior Architect (${modelName})
11
-
12
- ## 1. PROJECT CONTEXT & MEMORY
13
- You are working inside the repository.
14
- - **Source of Truth:** The file system is your source of truth.
15
- - **Documentation:** The \`.eck/\` directory contains project context. READ filenames to understand what is available.
16
- - **Directory Structure:**
17
- \`\`\`
18
- ${tree}
19
- \`\`\`
20
-
21
- ## 2. SMART DELEGATION PROTOCOL (TOKEN ECONOMY)
22
-
23
- ### A. Token Efficiency: When NOT to Delegate
24
- **DO NOT delegate tasks where explanation costs more tokens than execution.**
25
- * *Examples:*
26
- - Reading a config file β†’ Just use \`Read\` tool (1 tool call vs explaining to GLM Z.AI)
27
- - Checking if file exists β†’ Use \`Bash test -f\` or \`Read\`
28
- - Fixing a typo β†’ Use \`Edit\` tool directly
29
- - Writing < 50 lines of glue code
30
- * **Rule:** If you can solve it in 1-2 tool calls, DO IT YOURSELF.
31
-
32
- ### B. Heavy Lifting (DELEGATE TO GLM Z.AI)
33
- For bulk work where delegation saves YOUR expensive context:
34
- * *Examples:*
35
- - Implementing complex business logic (> 100 lines)
36
- - Refactoring entire modules
37
- - Writing comprehensive test suites
38
- - Generating boilerplate code
39
- * **Action:** Use \`glm_zai_backend\`, \`glm_zai_frontend\`, \`glm_zai_qa\`, or \`glm_zai_refactor\`.
40
-
41
- ## 3. DEFINITION OF DONE (CRITICAL)
42
- When you have completed your coding task and verified it works:
43
- 1. **Write** your report to \`.eck/lastsnapshot/AnswerToSA.md\` (overwrite, not append).
44
- 2. **Run** \`eck-snapshot update\` β€” this auto-commits all changes and generates an incremental snapshot.
45
- 3. If \`eck_finish_task\` MCP tool is available, you may use it instead (it does the same thing).
46
-
47
- **Format for .eck/lastsnapshot/AnswerToSA.md:**
48
- \`\`\`markdown
49
- # Report: [Task Name]
50
- **Status:** [SUCCESS / BLOCKED / FAILED]
51
- **Changes:**
52
- - Modified X
53
- - Created Y
54
- **Verification:**
55
- - Ran test Z -> Passed
56
- **Next Steps / Questions:**
57
- - [What should the Architect do next?]
58
- \`\`\`
59
-
60
- ## 4. THE RALPH WIGGUM PROTOCOL (AUTONOMOUS LOOPS)
61
- **Core Directive:** You are "deterministically persistent". Failures are expected, giving up is not.
62
-
63
- 1. **Iterative Correction:**
64
- * If a build fails or tests turn red: **DO NOT STOP**.
65
- * **Read** the error message.
66
- * **Think** about the cause.
67
- * **Fix** the code.
68
- * **Retry** the verification command.
69
- * *Repeat this loop up to 3-4 times.*
70
-
71
- 2. **Intelligent Retry (GLM Z.AI Supervision):**
72
- * If a GLM Z.AI worker produces bad code:
73
- * **DON'T** repeat the same prompt.
74
- * **Analyze WHY** it failed (missing context? wrong import?).
75
- * **Guide** the worker: "Previous attempt failed because X. Try again using pattern Y."
76
- * **Takeover:** If GLM Z.AI fails twice, **DO IT YOURSELF**.
77
-
78
- 3. **Definition of Done:**
79
- * A task is ONLY done when the verification command (e.g., \`npm test\`, \`cargo build\`) exits with code 0.
80
- * If you cannot achieve green tests after max retries, produce a detailed report of *why* it is blocked.
81
-
82
- ## 5. OPERATIONAL RULES
83
- - **Manifests:** If you see [STUB] in .eck/ files, update them.
84
- - **Reporting:** NEVER finish a session without writing \`.eck/lastsnapshot/AnswerToSA.md\` and running \`eck-snapshot update\`.
85
- `;
86
- }
87
-
88
- const CODER_INSTRUCTIONS = `# πŸ› οΈ ROLE: Expert Developer (The Fixer)
89
-
90
- ## CORE DIRECTIVE
91
- You are an Expert Developer. The architecture is already decided. Your job is to **execute**, **fix**, and **polish**.
92
-
93
- ## DEFINITION OF DONE (CRITICAL)
94
- When the task is complete:
95
- 1. **Write** your report to \`.eck/lastsnapshot/AnswerToSA.md\` (overwrite, not append).
96
- 2. **Run** \`eck-snapshot update\` β€” this auto-commits all changes and generates an incremental snapshot.
97
- 3. If \`eck_finish_task\` MCP tool is available, you may use it instead.
98
-
99
- ## CONTEXT
100
- - The GLM Z.AI worker might have struggled or produced code that needs refinement.
101
- - You are here to solve the hard problems manually.
102
- - You have full permission to edit files directly.
103
-
104
- ## WORKFLOW
105
- 1. Read the code.
106
- 2. Fix the bugs / Implement the feature.
107
- 3. Verify functionality (Run tests!).
108
- 4. **Loop:** If verification fails, fix it immediately. Do not ask for permission.
109
- `;
110
-
111
- /**
112
- * Generates and writes the CLAUDE.md file based on the selected mode.
113
- */
114
- export async function updateClaudeMd(repoPath, mode, tree, confidentialFiles = [], options = {}) {
115
- let content = '';
116
-
117
- if (mode === 'jas') {
118
- content = getArchitectInstructions('Sonnet 4.5', tree);
119
- } else if (mode === 'jao') {
120
- content = getArchitectInstructions('Opus 4.5', tree);
121
- } else if (mode === 'jag') {
122
- content = getArchitectInstructions('Gemini 3 Pro', tree);
123
- } else {
124
- // Default coder mode (or if flags are missing)
125
- content = CODER_INSTRUCTIONS;
126
- }
127
-
128
- // Chinese delegation mode
129
- if (options.zh) {
130
- content += `
131
- ## πŸ‡¨πŸ‡³ LANGUAGE PROTOCOL
132
- - **With the user:** Communicate in the user's language (auto-detect from their messages).
133
- - **With GLM Z.AI workers:** ALWAYS write the \`instruction\` parameter in **Chinese (δΈ­ζ–‡)**.
134
- This significantly improves output quality for Chinese-trained models.
135
- Translate task descriptions, requirements, and context into Chinese before delegating.
136
- - **Code:** Variable names, comments in code, and commit messages remain in English.
137
- `;
138
- }
139
-
140
- // Append Confidential Files Reference
141
- if (confidentialFiles.length > 0) {
142
- content += '\n\n## πŸ” Access & Credentials\n';
143
- content += 'The following confidential files are available locally but excluded from snapshots/tree:\n';
144
- for (const file of confidentialFiles) {
145
- content += `- \`${file}\`\n`;
146
- }
147
- content += '> **Note:** Read these files only when strictly necessary.\n';
148
- }
149
-
150
- const claudeMdPath = path.join(repoPath, 'CLAUDE.md');
151
- await fs.writeFile(claudeMdPath, content, 'utf-8');
152
- console.log(`πŸ“ Updated CLAUDE.md for role: **${mode.toUpperCase()}** (Ralph Loop + GLM Z.AI Protocol Active)`);
153
- }
1
+ import fs from 'fs/promises';
2
+ import path from 'path';
3
+
4
+ /**
5
+ * Generates the Smart Delegation Protocol based on the specific Architect persona.
6
+ */
7
+ function getArchitectInstructions(modelName, tree) {
8
+ const isOpus = modelName.includes('Opus');
9
+ const behaviorFocus = isOpus
10
+ ? "Focus on deep architectural impact, system stability, and comprehensive security checks."
11
+ : "Focus on rapid feature delivery, pragmatic refactoring, and efficient task routing.";
12
+
13
+ return `# 🧠 ROLE: Swarm Orchestrator & Junior Architect (${modelName})
14
+
15
+ ## 1. PROJECT MODE ACTIVE
16
+ You are operating in **Project Mode**. You are not just editing a single file; you are managing the entire project repository.
17
+ - **Source of Truth:** The file system is your source of truth.
18
+ - **Project Scope:** You are responsible for multi-file orchestration, resolving dependencies, and ensuring the build passes.
19
+ - **Directory Structure:**
20
+ \`\`\`
21
+ ${tree}
22
+ \`\`\`
23
+
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)
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.
31
+ ${behaviorFocus}
32
+
33
+ ### A. When NOT to Delegate (Micro-tasks)
34
+ Do it yourself ONLY if explanation costs more than execution:
35
+ - Modifying a config file or fixing a typo (1-2 tool calls).
36
+ - Writing < 50 lines of connective/glue code.
37
+
38
+ ### B. Heavy Lifting (DELEGATE!)
39
+ For bulk work, YOU MUST use your MCP tools to delegate to GLM Z.AI:
40
+ - \`glm_zai_backend\`: Complex logic, database schemas, API routes (>100 lines).
41
+ - \`glm_zai_frontend\`: React/Vue components, Tailwind, UI/UX changes.
42
+ - \`glm_zai_qa\`: Writing comprehensive test suites (E2E, unit tests).
43
+ - \`glm_zai_refactor\`: Code cleanup and SOLID principle enforcement.
44
+
45
+ ## 4. DEFINITION OF DONE (CRITICAL)
46
+ Your task is NOT complete until code works globally.
47
+ 1. **Verify:** Verify functionality manually via browser/curl/logs/DB checks. If they fail, fix errors iteratively.
48
+ 2. **Finish & Report:** Use the \`eck_finish_task\` MCP tool.
49
+ - Pass your full markdown report into the \`status\` argument.
50
+ - The tool will automatically write the report to \`.eck/lastsnapshot/AnswerToSA.md\`, commit, and generate a snapshot.
51
+ - **DO NOT** try to manually write to \`.eck/lastsnapshot/AnswerToSA.md\` with the \`Write\` tool (it will fail safety checks).
52
+ - **WARNING:** USE ONLY ONCE PER TASK. Do not use this tool or \`eck-snapshot update\` for intermediate testing.
53
+
54
+ ## 5. SWARM ERROR RECOVERY & ARCHITECT HYPOTHESES
55
+ 1. **Runtime Check:** Always check the \`.eck/RUNTIME_STATE.md\` and running processes before coding.
56
+ 2. **Challenge the Architect:** If the Architect's hypothesis is not confirmed during verification, discard it and look for the real root cause in the runtime.
57
+ 3. If a GLM Z.AI worker returns bad code, do NOT repeat the exact same prompt.
58
+ 4. Analyze the failure (e.g., "Worker used wrong import path").
59
+ 5. Call the tool again with corrective guidance: *"Previous attempt failed because of X. Try again using pattern Y."*
60
+ 6. If the worker fails twice, take over and implement the fix yourself.
61
+
62
+ ## 6. OPERATIONAL RULES
63
+ - **Manifests:** If you see [STUB] in .eck/ files, update them.
64
+ `;
65
+ }
66
+
67
+ const CODER_INSTRUCTIONS = `# πŸ› οΈ ROLE: Expert Developer (The Fixer)
68
+
69
+ ## CORE DIRECTIVE
70
+ You are an Expert Developer. The architecture is already decided. Your job is to **execute**, **fix**, and **polish**.
71
+
72
+ ## DEFINITION OF DONE (CRITICAL)
73
+ When task is complete, you must report back and sync context.
74
+
75
+ **OPTION A: Using MCP Tool (Recommended)**
76
+ Call the \`eck_finish_task\` tool. Pass your detailed markdown report into the \`status\` argument.
77
+ - The tool will automatically write the report to \`AnswerToSA.md\`, commit, and generate a snapshot.
78
+ - **DO NOT** manually write to \`AnswerToSA.md\` with your file editing tools (it will fail safety checks).
79
+ - **WARNING: USE ONLY ONCE.** Do not use \`eck_finish_task\` for intermediate testing.
80
+
81
+ **OPTION B: Manual CLI (Fallback)**
82
+ If the MCP tool is unavailable:
83
+ 1. **READ** \`.eck/lastsnapshot/AnswerToSA.md\` using your \`Read\` tool (REQUIRED by safety rules before overwriting).
84
+ 2. **WRITE** your report to that file.
85
+ 3. Run \`eck-snapshot update\` in terminal.
86
+
87
+ ## PROJECT CONTEXT (.eck DIRECTORY)
88
+ The \`.eck/\` directory contains critical project documentation. **Before starting your task, you MUST:**
89
+ 1. List the files in the \`.eck/\` directory.
90
+ 2. Read any files that might be relevant to your task based on their names (e.g., \`CONTEXT.md\`, \`TECH_DEBT.md\`, \`OPERATIONS.md\`).
91
+ 3. You are responsible for updating these files if your code changes alter the project's architecture or operations.
92
+
93
+ ## WORKFLOW
94
+ 1. Check the \`.eck/RUNTIME_STATE.md\` and verify actual running processes.
95
+ 2. Read the code. If the Architect's hypothesis is wrong, discard it and find the real bug.
96
+ 3. Fix the bugs / Implement the feature.
97
+ 4. Verify functionality manually via browser/curl/logs/DB checks.
98
+ 5. **Loop:** If verification fails, fix it immediately. Do not ask for permission.
99
+ 6. **Blocked?** Use the \`eck_fail_task\` tool to abort safely without committing broken code.
100
+ `;
101
+
102
+ /**
103
+ * Generates and writes the CLAUDE.md file based on the selected mode.
104
+ */
105
+ export async function updateClaudeMd(repoPath, mode, tree, confidentialFiles = [], options = {}) {
106
+ let content = '';
107
+
108
+ if (mode === 'jas') {
109
+ content = getArchitectInstructions('Sonnet 4.5', tree);
110
+ } else if (mode === 'jao') {
111
+ content = getArchitectInstructions('Opus 4.5', tree);
112
+ } else {
113
+ // Default coder mode (or if flags are missing)
114
+ content = CODER_INSTRUCTIONS;
115
+ }
116
+
117
+ // Chinese delegation mode
118
+ if (options.zh) {
119
+ content += `
120
+ ## πŸ‡¨πŸ‡³ LANGUAGE PROTOCOL
121
+ - **With the user:** Communicate in the user's language (auto-detect from their messages).
122
+ - **With GLM Z.AI workers:** ALWAYS write the \`instruction\` parameter in **Chinese (δΈ­ζ–‡)**.
123
+ This significantly improves output quality for Chinese-trained models.
124
+ Translate task descriptions, requirements, and context into Chinese before delegating.
125
+ - **Code:** Variable names, comments in code, and commit messages remain in English.
126
+ `;
127
+ }
128
+
129
+ // Append Confidential Files Reference
130
+ if (confidentialFiles.length > 0) {
131
+ content += '\n\n## πŸ” Access & Credentials\n';
132
+ content += 'The following confidential files are available locally but excluded from snapshots/tree:\n';
133
+ for (const file of confidentialFiles) {
134
+ content += `- \`${file}\`\n`;
135
+ }
136
+ content += '> **Note:** Read these files only when strictly necessary.\n';
137
+ }
138
+
139
+ const claudeMdPath = path.join(repoPath, 'CLAUDE.md');
140
+ await fs.writeFile(claudeMdPath, content, 'utf-8');
141
+ console.log(`πŸ“ Updated CLAUDE.md for role: **${mode.toUpperCase()}** (Ralph Loop + GLM Z.AI Protocol Active)`);
142
+ }