🔖 Checkpoint: Edit /workspaces/claude-code-flow/package.json

This commit is contained in:
rUv committed 2025-09-26 17:57:41 +00:00
1 parent edd35dc696
commit a4bae50e28
4 files changed
+204 -2

No files matched your search

+1
View File
@@ -0,0 +1 @@
{"checkpoint": "task-20250926-175544", "task": "{{user_prompt}} ", "timestamp": "2025-09-26T17:55:45Z", "commit": "edd35dc6960cf11a0a4dfe51146b2c41ce049429", "github_release": "true"}
@@ -0,0 +1,200 @@
import { existsSync } from 'fs';
import { promises as fs } from 'fs/promises';
import path from 'path';
const MEMORY_PROTOCOL = `
## 🧠 MANDATORY MEMORY COORDINATION PROTOCOL
### 🚨 CRITICAL: Every Agent MUST Write AND Read Memory
**EVERY spawned agent MUST follow this exact pattern:**
\`\`\`javascript
// 1️⃣ IMMEDIATELY when agent starts - WRITE initial status
mcp__claude-flow__memory_usage {
action: "store",
key: "swarm/[agent-name]/status",
namespace: "coordination",
value: JSON.stringify({
agent: "[agent-name]",
status: "starting",
timestamp: Date.now(),
tasks: ["list", "of", "tasks"],
progress: 0
})
}
// 2️⃣ AFTER EACH MAJOR STEP - WRITE progress
mcp__claude-flow__memory_usage {
action: "store",
key: "swarm/[agent-name]/progress",
namespace: "coordination",
value: JSON.stringify({
completed: ["task1", "task2"],
current: "working on task3",
progress: 35,
files_created: ["file1.js"],
interfaces: { "API": "definition" },
dependencies_needed: []
})
}
// 3️⃣ SHARE ARTIFACTS - WRITE for others
mcp__claude-flow__memory_usage {
action: "store",
key: "swarm/shared/[component]",
namespace: "coordination",
value: JSON.stringify({
type: "interface",
definition: "actual code here",
created_by: "[agent-name]"
})
}
// 4️⃣ CHECK DEPENDENCIES - READ then WAIT
const dep = mcp__claude-flow__memory_usage {
action: "retrieve",
key: "swarm/shared/[component]",
namespace: "coordination"
}
if (!dep.found) {
// Write waiting status
mcp__claude-flow__memory_usage {
action: "store",
key: "swarm/[agent-name]/waiting",
namespace: "coordination",
value: JSON.stringify({
waiting_for: "[component]",
from: "[other-agent]"
})
}
}
// 5️⃣ SIGNAL COMPLETION
mcp__claude-flow__memory_usage {
action: "store",
key: "swarm/[agent-name]/complete",
namespace: "coordination",
value: JSON.stringify({
status: "complete",
deliverables: ["list"],
integration_points: ["how to use"]
})
}
\`\`\`
### 📊 MEMORY KEY STRUCTURE
- Use namespace: "coordination" ALWAYS
- Keys: swarm/[agent]/status|progress|waiting|complete
- Shared: swarm/shared/[component]
### ❌ COMMON MISTAKES
1. Only reading, never writing
2. Wrong namespace
3. No progress updates
4. Missing shared artifacts
`;
const AGENT_INSTRUCTION = `
🚨 MANDATORY MEMORY COORDINATION:
1. START - IMMEDIATELY write status:
mcp__claude-flow__memory_usage { action: "store", key: "swarm/[your-name]/status", namespace: "coordination", value: {status: "starting"} }
2. PROGRESS - After EVERY major step:
mcp__claude-flow__memory_usage { action: "store", key: "swarm/[your-name]/progress", namespace: "coordination", value: {progress: X%} }
3. SHARE - Write ALL interfaces/APIs:
mcp__claude-flow__memory_usage { action: "store", key: "swarm/shared/[component]", namespace: "coordination", value: {definition: "..."} }
4. CHECK - Verify dependencies exist:
mcp__claude-flow__memory_usage { action: "retrieve", key: "swarm/shared/[component]", namespace: "coordination" }
5. COMPLETE - Signal when done:
mcp__claude-flow__memory_usage { action: "store", key: "swarm/[your-name]/complete", namespace: "coordination", value: {deliverables: [...]} }
REMEMBER: If you don't WRITE to memory, other agents can't coordinate with you!
`;
export async function injectMemoryProtocol(projectPath = process.cwd()) {
const claudeMdPath = path.join(projectPath, 'CLAUDE.md');
try {
let content = '';
let hasProtocol = false;
if (existsSync(claudeMdPath)) {
content = await fs.readFile(claudeMdPath, 'utf8');
hasProtocol = content.includes('MANDATORY MEMORY COORDINATION PROTOCOL');
}
if (!hasProtocol) {
const injectionPoint = content.indexOf('## Project Overview');
if (injectionPoint > -1) {
content = content.slice(0, injectionPoint) + MEMORY_PROTOCOL + '\n\n' + content.slice(injectionPoint);
} else {
content = MEMORY_PROTOCOL + '\n\n' + content;
}
await fs.writeFile(claudeMdPath, content, 'utf8');
console.log('✅ Injected memory coordination protocol into CLAUDE.md');
return true;
} else {
console.log('✓ Memory coordination protocol already present in CLAUDE.md');
return false;
}
} catch (error) {
console.error('⚠️ Could not inject memory protocol:', error.message);
return false;
}
}
export function enhanceSwarmPrompt(originalPrompt, agentCount = 5) {
const enhancement = `
CRITICAL: ALL AGENTS MUST COORDINATE THROUGH MEMORY
${AGENT_INSTRUCTION}
Each of the ${agentCount} agents MUST:
- Write initial status when starting
- Update progress after each step (with %)
- Share all interfaces/APIs/configs
- Check dependencies before using
- Signal completion when done
ALL memory operations use namespace: "coordination"
Memory monitoring commands:
- Check status: memory search "swarm/*/status" --namespace coordination
- View progress: memory search "swarm/*/progress" --namespace coordination
- Find blockers: memory search "swarm/*/waiting" --namespace coordination
- List shared: memory search "swarm/shared/*" --namespace coordination
---
ORIGINAL OBJECTIVE:
${originalPrompt}`;
return enhancement;
}
export function enhanceHiveMindPrompt(originalPrompt, workers = []) {
const workerInstructions = workers.map((w)=>`Agent ${w.name}: MUST write to swarm/${w.name}/status and swarm/${w.name}/progress`).join('\n');
return `
HIVE MIND COORDINATION REQUIREMENTS:
${AGENT_INSTRUCTION}
${workerInstructions}
Coordination namespace: "coordination"
Status pattern: swarm/[agent]/status
Progress pattern: swarm/[agent]/progress
Shared pattern: swarm/shared/[component]
---
ORIGINAL OBJECTIVE:
${originalPrompt}`;
}
export function shouldInjectProtocol(flags) {
return flags.claude || flags.spawn || flags['auto-spawn'];
}
export default {
injectMemoryProtocol,
enhanceSwarmPrompt,
enhanceHiveMindPrompt,
shouldInjectProtocol,
MEMORY_PROTOCOL,
AGENT_INSTRUCTION
};
//# sourceMappingURL=inject-memory-protocol.js.map
@@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/cli/simple-commands/inject-memory-protocol.js"],"sourcesContent":["// inject-memory-protocol.js - Injects memory coordination protocol for swarms\n\nimport { existsSync } from 'fs';\nimport { promises as fs } from 'fs/promises';\nimport path from 'path';\n\n/**\n * Memory coordination protocol to inject\n */\nconst MEMORY_PROTOCOL = `\n## 🧠 MANDATORY MEMORY COORDINATION PROTOCOL\n\n### 🚨 CRITICAL: Every Agent MUST Write AND Read Memory\n\n**EVERY spawned agent MUST follow this exact pattern:**\n\n\\`\\`\\`javascript\n// 1️⃣ IMMEDIATELY when agent starts - WRITE initial status\nmcp__claude-flow__memory_usage {\n action: \"store\",\n key: \"swarm/[agent-name]/status\",\n namespace: \"coordination\",\n value: JSON.stringify({\n agent: \"[agent-name]\",\n status: \"starting\",\n timestamp: Date.now(),\n tasks: [\"list\", \"of\", \"tasks\"],\n progress: 0\n })\n}\n\n// 2️⃣ AFTER EACH MAJOR STEP - WRITE progress\nmcp__claude-flow__memory_usage {\n action: \"store\",\n key: \"swarm/[agent-name]/progress\",\n namespace: \"coordination\",\n value: JSON.stringify({\n completed: [\"task1\", \"task2\"],\n current: \"working on task3\",\n progress: 35,\n files_created: [\"file1.js\"],\n interfaces: { \"API\": \"definition\" },\n dependencies_needed: []\n })\n}\n\n// 3️⃣ SHARE ARTIFACTS - WRITE for others\nmcp__claude-flow__memory_usage {\n action: \"store\",\n key: \"swarm/shared/[component]\",\n namespace: \"coordination\",\n value: JSON.stringify({\n type: \"interface\",\n definition: \"actual code here\",\n created_by: \"[agent-name]\"\n })\n}\n\n// 4️⃣ CHECK DEPENDENCIES - READ then WAIT\nconst dep = mcp__claude-flow__memory_usage {\n action: \"retrieve\",\n key: \"swarm/shared/[component]\",\n namespace: \"coordination\"\n}\nif (!dep.found) {\n // Write waiting status\n mcp__claude-flow__memory_usage {\n action: \"store\",\n key: \"swarm/[agent-name]/waiting\",\n namespace: \"coordination\",\n value: JSON.stringify({\n waiting_for: \"[component]\",\n from: \"[other-agent]\"\n })\n }\n}\n\n// 5️⃣ SIGNAL COMPLETION\nmcp__claude-flow__memory_usage {\n action: \"store\",\n key: \"swarm/[agent-name]/complete\",\n namespace: \"coordination\",\n value: JSON.stringify({\n status: \"complete\",\n deliverables: [\"list\"],\n integration_points: [\"how to use\"]\n })\n}\n\\`\\`\\`\n\n### 📊 MEMORY KEY STRUCTURE\n- Use namespace: \"coordination\" ALWAYS\n- Keys: swarm/[agent]/status|progress|waiting|complete\n- Shared: swarm/shared/[component]\n\n### ❌ COMMON MISTAKES\n1. Only reading, never writing\n2. Wrong namespace\n3. No progress updates\n4. Missing shared artifacts\n`;\n\n/**\n * Agent instruction template with memory requirements\n */\nconst AGENT_INSTRUCTION = `\n🚨 MANDATORY MEMORY COORDINATION:\n\n1. START - IMMEDIATELY write status:\n mcp__claude-flow__memory_usage { action: \"store\", key: \"swarm/[your-name]/status\", namespace: \"coordination\", value: {status: \"starting\"} }\n\n2. PROGRESS - After EVERY major step:\n mcp__claude-flow__memory_usage { action: \"store\", key: \"swarm/[your-name]/progress\", namespace: \"coordination\", value: {progress: X%} }\n\n3. SHARE - Write ALL interfaces/APIs:\n mcp__claude-flow__memory_usage { action: \"store\", key: \"swarm/shared/[component]\", namespace: \"coordination\", value: {definition: \"...\"} }\n\n4. CHECK - Verify dependencies exist:\n mcp__claude-flow__memory_usage { action: \"retrieve\", key: \"swarm/shared/[component]\", namespace: \"coordination\" }\n\n5. COMPLETE - Signal when done:\n mcp__claude-flow__memory_usage { action: \"store\", key: \"swarm/[your-name]/complete\", namespace: \"coordination\", value: {deliverables: [...]} }\n\nREMEMBER: If you don't WRITE to memory, other agents can't coordinate with you!\n`;\n\n/**\n * Inject memory protocol into CLAUDE.md\n */\nexport async function injectMemoryProtocol(projectPath = process.cwd()) {\n const claudeMdPath = path.join(projectPath, 'CLAUDE.md');\n \n try {\n let content = '';\n let hasProtocol = false;\n \n // Check if CLAUDE.md exists\n if (existsSync(claudeMdPath)) {\n content = await fs.readFile(claudeMdPath, 'utf8');\n hasProtocol = content.includes('MANDATORY MEMORY COORDINATION PROTOCOL');\n }\n \n // If protocol not present, inject it\n if (!hasProtocol) {\n // Find a good injection point (after project overview or at start)\n const injectionPoint = content.indexOf('## Project Overview');\n \n if (injectionPoint > -1) {\n // Insert before Project Overview\n content = \n content.slice(0, injectionPoint) + \n MEMORY_PROTOCOL + '\\n\\n' +\n content.slice(injectionPoint);\n } else {\n // Prepend to file\n content = MEMORY_PROTOCOL + '\\n\\n' + content;\n }\n \n await fs.writeFile(claLine truncated
+2 -2
View File
@@ -15,8 +15,8 @@
"build": "npm run clean && npm run update-version && npm run build:esm && npm run build:cjs && npm run build:binary",
"update-version": "node scripts/update-bin-version.js",
"clean": "rm -rf dist dist-cjs",
"build:esm": "swc src -d dist --config-file .swcrc --ignore 'src/ui/extension/node_modules/**/*'",
"build:cjs": "swc src -d dist-cjs --config-file .swcrc --ignore 'src/ui/extension/node_modules/**/*'",
"build:esm": "swc src -d dist --config-file .swcrc",
"build:cjs": "swc src -d dist-cjs --config-file .swcrc",
"build:ts": "npm run build:esm && npm run build:cjs",
"build:binary": "pkg dist/src/cli/main.js --targets node18-linux-x64,node18-macos-x64,node18-win-x64 --output bin/claude-flow",
"build:simple": "npm run build:ts && pkg dist/cli/simple-cli.js --output bin/claude-flow-simple",