@xelth/eck-snapshot 4.2.4 → 5.4.1

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.

Files changed (51) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +106 -0
  3. package/index.js +14 -0
  4. package/package.json +64 -9
  5. package/scripts/mcp-eck-core.js +101 -0
  6. package/scripts/mcp-glm-zai-worker.mjs +243 -0
  7. package/scripts/verify_changes.js +68 -0
  8. package/setup.json +845 -0
  9. package/src/cli/cli.js +369 -0
  10. package/src/cli/commands/claudeSettings.js +93 -0
  11. package/src/cli/commands/consilium.js +86 -0
  12. package/src/cli/commands/createSnapshot.js +917 -0
  13. package/src/cli/commands/detectProfiles.js +98 -0
  14. package/src/cli/commands/detectProject.js +112 -0
  15. package/src/cli/commands/doctor.js +60 -0
  16. package/src/cli/commands/envSync.js +319 -0
  17. package/src/cli/commands/generateProfileGuide.js +144 -0
  18. package/src/cli/commands/pruneSnapshot.js +106 -0
  19. package/src/cli/commands/restoreSnapshot.js +173 -0
  20. package/src/cli/commands/setupGemini.js +149 -0
  21. package/src/cli/commands/setupGemini.test.js +115 -0
  22. package/src/cli/commands/setupMcp.js +269 -0
  23. package/src/cli/commands/showFile.js +39 -0
  24. package/src/cli/commands/trainTokens.js +38 -0
  25. package/src/cli/commands/updateSnapshot.js +247 -0
  26. package/src/config.js +115 -0
  27. package/src/core/skeletonizer.js +201 -0
  28. package/src/mcp-server/index.js +211 -0
  29. package/src/services/claudeCliService.js +626 -0
  30. package/src/services/claudeCliService.test.js +267 -0
  31. package/src/templates/agent-prompt.template.md +43 -0
  32. package/src/templates/architect-prompt.template.md +164 -0
  33. package/src/templates/claude-code/README.md +105 -0
  34. package/src/templates/claude-code/mcp-config-template.json +11 -0
  35. package/src/templates/claude-code/mcp-server-template.js +206 -0
  36. package/src/templates/claude-code/settings-claude.json +1 -0
  37. package/src/templates/envScanRequest.md +4 -0
  38. package/src/templates/gitWorkflow.md +32 -0
  39. package/src/templates/multiAgent.md +118 -0
  40. package/src/templates/opencode/coder.template.md +22 -0
  41. package/src/templates/opencode/junior-architect.template.md +85 -0
  42. package/src/templates/skeleton-instruction.md +16 -0
  43. package/src/templates/update-prompt.template.md +19 -0
  44. package/src/utils/aiHeader.js +678 -0
  45. package/src/utils/claudeMdGenerator.js +148 -0
  46. package/src/utils/eckProtocolParser.js +221 -0
  47. package/src/utils/fileUtils.js +1017 -0
  48. package/src/utils/gitUtils.js +51 -0
  49. package/src/utils/opencodeAgentsGenerator.js +271 -0
  50. package/src/utils/projectDetector.js +704 -0
  51. package/src/utils/tokenEstimator.js +201 -0
@@ -0,0 +1,51 @@
1
+ import fs from 'fs/promises';
2
+ import path from 'path';
3
+ import { execa } from 'execa';
4
+
5
+ const ANCHOR_FILE = '.eck/anchor';
6
+
7
+ export async function saveGitAnchor(repoPath) {
8
+ try {
9
+ const { stdout } = await execa('git', ['rev-parse', 'HEAD'], { cwd: repoPath });
10
+ const anchorPath = path.join(repoPath, ANCHOR_FILE);
11
+ await fs.mkdir(path.dirname(anchorPath), { recursive: true });
12
+ await fs.writeFile(anchorPath, stdout.trim());
13
+ // console.log(`⚓ Git anchor saved: ${stdout.trim().substring(0, 7)}`);
14
+ } catch (e) {
15
+ // Ignore if not a git repo
16
+ }
17
+ }
18
+
19
+ export async function getGitAnchor(repoPath) {
20
+ try {
21
+ const anchorPath = path.join(repoPath, ANCHOR_FILE);
22
+ return await fs.readFile(anchorPath, 'utf-8');
23
+ } catch (e) {
24
+ return null;
25
+ }
26
+ }
27
+
28
+ export async function getChangedFiles(repoPath, anchorHash) {
29
+ try {
30
+ const { stdout } = await execa('git', ['diff', '--name-only', anchorHash, 'HEAD'], { cwd: repoPath });
31
+ return stdout.split('\n').filter(Boolean);
32
+ } catch (e) {
33
+ throw new Error(`Failed to get git diff: ${e.message}`);
34
+ }
35
+ }
36
+
37
+ export async function getGitDiffOutput(repoPath, anchorHash, excludeFiles = []) {
38
+ try {
39
+ const args = ['diff', anchorHash, 'HEAD'];
40
+ if (excludeFiles.length > 0) {
41
+ args.push('--');
42
+ for (const file of excludeFiles) {
43
+ args.push(`:(exclude)${file}`);
44
+ }
45
+ }
46
+ const { stdout } = await execa('git', args, { cwd: repoPath });
47
+ return stdout;
48
+ } catch (e) {
49
+ return '';
50
+ }
51
+ }
@@ -0,0 +1,271 @@
1
+ import fs from 'fs/promises';
2
+ import path from 'path';
3
+ import yaml from 'js-yaml';
4
+ import { updateClaudeMd } from './claudeMdGenerator.js';
5
+
6
+ /**
7
+ * Generates AGENTS.md for OpenCode integration
8
+ * @param {string} repoPath - Path to the repository
9
+ * @param {string} mode - Mode (jas, jao, jag, coder)
10
+ * @param {string} tree - Directory tree string
11
+ * @param {string[]} confidentialFiles - Array of confidential file paths
12
+ */
13
+ export async function generateOpenCodeAgents(repoPath, mode, tree, confidentialFiles = []) {
14
+ let frontmatter = {};
15
+ let body = '';
16
+
17
+ // Determine agent type based on mode
18
+ if (mode === 'jas') {
19
+ frontmatter = {
20
+ mode: 'primary',
21
+ description: 'Smart delegator with GLM ZAI swarm access (Sonnet 4.5)',
22
+ model: 'opencode/claude-3-5-sonnet',
23
+ steps: 10,
24
+ tools: {
25
+ 'glm-zai:glm_zai_backend': true,
26
+ 'glm-zai:glm_zai_frontend': true,
27
+ 'glm-zai:glm_zai_qa': true,
28
+ 'glm-zai:glm_zai_refactor': true,
29
+ 'glm-zai:glm_zai_general': true,
30
+ 'eck-core:eck_finish_task': true
31
+ },
32
+ permission: {
33
+ read: 'allow',
34
+ edit: 'allow',
35
+ bash: 'allow',
36
+ '*': 'allow'
37
+ },
38
+ color: '#38A3EE'
39
+ };
40
+
41
+ // Read and adapt junior-architect template
42
+ const templatePath = path.join(repoPath, '..', '..', 'src', 'templates', 'opencode', 'junior-architect.template.md');
43
+ try {
44
+ let templateContent = await fs.readFile(templatePath, 'utf-8');
45
+ // Replace {{tree}} placeholder with actual tree
46
+ templateContent = templateContent.replace('{{tree}}', tree);
47
+ body = templateContent;
48
+ } catch (error) {
49
+ // Fallback to architect instructions from claudeMdGenerator
50
+ body = getArchitectInstructions('Sonnet 4.5', tree);
51
+ }
52
+
53
+ } else if (mode === 'jao') {
54
+ frontmatter = {
55
+ mode: 'primary',
56
+ description: 'Deep thinker with GLM ZAI swarm access (Opus 4.5)',
57
+ model: 'opencode/claude-3-5-opus',
58
+ steps: 10,
59
+ tools: {
60
+ 'glm-zai:glm_zai_backend': true,
61
+ 'glm-zai:glm_zai_frontend': true,
62
+ 'glm-zai:glm_zai_qa': true,
63
+ 'glm-zai:glm_zai_refactor': true,
64
+ 'glm-zai:glm_zai_general': true,
65
+ 'eck-core:eck_finish_task': true
66
+ },
67
+ permission: {
68
+ read: 'allow',
69
+ edit: 'allow',
70
+ bash: 'allow',
71
+ '*': 'allow'
72
+ },
73
+ color: '#FF5733'
74
+ };
75
+
76
+ body = getArchitectInstructions('Opus 4.5', tree);
77
+
78
+ } else if (mode === 'jag') {
79
+ frontmatter = {
80
+ mode: 'primary',
81
+ description: 'Massive context handler with GLM ZAI swarm access (Gemini 3 Pro)',
82
+ model: 'opencode/claude-3-5-opus',
83
+ steps: 15,
84
+ tools: {
85
+ 'glm-zai:glm_zai_backend': true,
86
+ 'glm-zai:glm_zai_frontend': true,
87
+ 'glm-zai:glm_zai_qa': true,
88
+ 'glm-zai:glm_zai_refactor': true,
89
+ 'glm-zai:glm_zai_general': true,
90
+ 'eck-core:eck_finish_task': true
91
+ },
92
+ permission: {
93
+ read: 'allow',
94
+ edit: 'allow',
95
+ bash: 'allow',
96
+ '*': 'allow'
97
+ },
98
+ color: '#9C27B0'
99
+ };
100
+
101
+ body = getArchitectInstructions('Gemini 3 Pro', tree);
102
+
103
+ } else {
104
+ // Default coder mode
105
+ frontmatter = {
106
+ mode: 'primary',
107
+ description: 'Expert developer - executes and fixes',
108
+ model: 'opencode/claude-3-5-sonnet',
109
+ steps: 5,
110
+ tools: {
111
+ 'eck-core:eck_finish_task': true
112
+ },
113
+ permission: {
114
+ read: 'allow',
115
+ edit: 'allow',
116
+ bash: 'allow',
117
+ '*': 'allow'
118
+ },
119
+ color: '#44BA81'
120
+ };
121
+
122
+ // Read coder template
123
+ const templatePath = path.join(repoPath, '..', '..', 'src', 'templates', 'opencode', 'coder.template.md');
124
+ try {
125
+ body = await fs.readFile(templatePath, 'utf-8');
126
+ } catch (error) {
127
+ // Fallback to coder instructions from claudeMdGenerator
128
+ body = CODER_INSTRUCTIONS;
129
+ }
130
+ }
131
+
132
+ // Append confidential files reference
133
+ if (confidentialFiles.length > 0) {
134
+ body += '\n\n## 🔐 Access & Credentials\n';
135
+ body += 'The following confidential files are available locally but excluded from snapshots/tree:\n';
136
+ for (const file of confidentialFiles) {
137
+ body += `- \`${file}\`\n`;
138
+ }
139
+ body += '> **Note:** Read these files only when strictly necessary.\n';
140
+ }
141
+
142
+ // Generate final content with YAML frontmatter
143
+ const frontmatterStr = yaml.dump(frontmatter, {
144
+ lineWidth: -1,
145
+ noRefs: true,
146
+ quotingType: '"'
147
+ });
148
+
149
+ const content = `---\n${frontmatterStr}---\n\n${body}`;
150
+
151
+ // Write AGENTS.md to project root (not .eck/ directory)
152
+ const agentsPath = path.join(repoPath, 'AGENTS.md');
153
+ await fs.writeFile(agentsPath, content, 'utf-8');
154
+
155
+ console.log(`📝 Generated OpenCode agents: ${agentsPath}`);
156
+ }
157
+
158
+ /**
159
+ * Gets architect instructions (reused from claudeMdGenerator.js)
160
+ * This is a simplified version for AGENTS.md generation
161
+ */
162
+ function getArchitectInstructions(modelName, tree) {
163
+ return `# 🧠 ROLE: Junior Architect (${modelName})
164
+
165
+ ## 1. PROJECT CONTEXT & MEMORY
166
+ You are working inside the repository.
167
+ - **Source of Truth:** The file system is your source of truth.
168
+ - **Documentation:** The \`.eck/\` directory contains project context. READ filenames to understand what is available.
169
+ - **Directory Structure:**
170
+ \`\`\`
171
+ ${tree}
172
+ \`\`\`
173
+
174
+ ## 2. SMART DELEGATION PROTOCOL (TOKEN ECONOMY)
175
+
176
+ ### A. Token Efficiency: When NOT to Delegate
177
+ **DO NOT delegate tasks where explanation costs more tokens than execution.**
178
+ * *Examples:*
179
+ - Reading a config file → Just use \`Read\` tool (1 tool call vs explaining to GLM ZAI)
180
+ - Checking if file exists → Use \`Bash test -f\` or \`Read\`
181
+ - Fixing a typo → Use \`Edit\` tool directly
182
+ - Writing < 50 lines of glue code
183
+ * **Rule:** If you can solve it in 1-2 tool calls, DO IT YOURSELF.
184
+
185
+ ### B. Heavy Lifting (DELEGATE TO GLM ZAI)
186
+ For bulk work where delegation saves YOUR expensive context:
187
+ * *Examples:*
188
+ - Implementing complex business logic (> 100 lines)
189
+ - Refactoring entire modules
190
+ - Writing comprehensive test suites
191
+ - Generating boilerplate code
192
+ * **Action:** Use \`glm_zai_backend\`, \`glm_zai_frontend\`, \`glm_zai_qa\`, or \`glm_zai_refactor\`.
193
+
194
+ ## 3. DEFINITION OF DONE (CRITICAL)
195
+ When you have completed your coding task and verified it works:
196
+ 1. **DO NOT** run \`git commit\` manually.
197
+ 2. **DO NOT** just say "I'm done".
198
+ 3. **Use the \`eck_finish_task\` tool** to finalize the task.
199
+ - This tool automatically:
200
+ - Updates \`.eck/lastsnapshot/AnswerToSA.md\` with your status
201
+ - Creates a proper git commit with Co-Authored-By attribution
202
+ - Generates a delta snapshot (\`eck-snapshot update-auto\`) for context sync
203
+ - This is the standard way to complete any task.
204
+
205
+ ## 4. THE RALPH WIGGUM PROTOCOL (AUTONOMOUS LOOPS)
206
+ **Core Directive:** You are "deterministically persistent". Failures are expected, giving up is not.
207
+
208
+ 1. **Iterative Correction:**
209
+ * If a build fails or tests turn red: **DO NOT STOP**.
210
+ * **Read** the error message.
211
+ * **Think** about the cause.
212
+ * **Fix** the code.
213
+ * **Retry** the verification command.
214
+ * *Repeat this loop up to 3-4 times.*
215
+
216
+ 2. **Intelligent Retry (GLM ZAI Supervision):**
217
+ * If a GLM ZAI worker produces bad code:
218
+ * **DON'T** repeat the same prompt.
219
+ * **Analyze WHY** it failed (missing context? wrong import?).
220
+ * **Guide** the worker: "Previous attempt failed because X. Try again using pattern Y."
221
+ * **Takeover:** If GLM ZAI fails twice, **DO IT YOURSELF**.
222
+
223
+ 3. **Definition of Done:**
224
+ * A task is ONLY done when the verification command (e.g., \`npm test\`) exits with code 0.
225
+ * If you cannot achieve green tests after max retries, produce a detailed report of *why* it is blocked.
226
+
227
+ ## 5. REPORTING PROTOCOL
228
+ At the end of your task, you **MUST** create or overwrite the file \`.eck/lastsnapshot/AnswerToSA.md\` BEFORE calling \`eck_finish_task\`.
229
+ This file communicates your results back to the Senior Architect.
230
+
231
+ **Format for .eck/lastsnapshot/AnswerToSA.md:**
232
+ \`\`\`markdown
233
+ # Report: [Task Name]
234
+ **Status:** [SUCCESS / BLOCKED / FAILED]
235
+ **Changes:**
236
+ - Modified X
237
+ - Created Y
238
+ **Verification:**
239
+ - Ran test Z -> Passed
240
+ **Next Steps / Questions:**
241
+ - [What should the Architect do next?]
242
+ \`\`\`
243
+
244
+ ## 6. OPERATIONAL RULES
245
+ - **Commits:** Use the \`eck_finish_task\` tool for committing and updating context.
246
+ - **Manifests:** If you see [STUB] in .eck/ files, update them.
247
+ - **Reporting:** NEVER finish a session without writing \`.eck/lastsnapshot/AnswerToSA.md\` and calling \`eck_finish_task\`.`;
248
+ }
249
+
250
+ const CODER_INSTRUCTIONS = `# 🛠️ ROLE: Expert Developer (The Fixer)
251
+
252
+ ## CORE DIRECTIVE
253
+ You are an Expert Developer. The architecture is already decided. Your job is to **execute**, **fix**, and **polish**.
254
+
255
+ ## DEFINITION OF DONE (CRITICAL)
256
+ When the task is complete:
257
+ 1. **UPDATE** the \`.eck/lastsnapshot/AnswerToSA.md\` file with your status.
258
+ 2. **Use the \`eck_finish_task\` tool** to commit and sync context.
259
+ - This tool automatically creates a git commit and generates a delta snapshot
260
+ 3. **DO NOT** use raw git commands for the final commit.
261
+
262
+ ## CONTEXT
263
+ - The GLM ZAI swarm might have struggled or produced code that needs refinement.
264
+ - You are here to solve the hard problems manually.
265
+ - You have full permission to edit files directly.
266
+
267
+ ## WORKFLOW
268
+ 1. Read the code.
269
+ 2. Fix the bugs / Implement the feature.
270
+ 3. Verify functionality (Run tests!).
271
+ 4. **Loop:** If verification fails, fix it immediately. Do not ask for permission.`;