mirror of
https://github.com/catlog22/Claude-Code-Workflow.git
synced 2026-02-13 02:41:50 +08:00
fix: enforce synchronous bash execution in memory update workflows
Explicitly set run_in_background: false for all Bash commands in update-full and update-related workflows to prevent unwanted background execution. This ensures synchronous execution without requiring BashOutput polling. Changes: - Phase 1-4: Add run_in_background: false to all Bash calls - Simplify code examples and remove redundant explanations - Update both direct execution and agent batch execution patterns 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -95,14 +95,15 @@ src/ (depth 1) → SINGLE-LAYER STRATEGY
|
|||||||
|
|
||||||
### Phase 1: Discovery & Analysis
|
### Phase 1: Discovery & Analysis
|
||||||
|
|
||||||
```bash
|
```javascript
|
||||||
# Cache git changes
|
// Cache git changes
|
||||||
bash(git add -A 2>/dev/null || true)
|
Bash({command: "git add -A 2>/dev/null || true", run_in_background: false});
|
||||||
|
|
||||||
# Get module structure
|
// Get module structure
|
||||||
bash(~/.claude/scripts/get_modules_by_depth.sh list)
|
Bash({command: "~/.claude/scripts/get_modules_by_depth.sh list", run_in_background: false});
|
||||||
# OR with --path
|
|
||||||
bash(cd <target-path> && ~/.claude/scripts/get_modules_by_depth.sh list)
|
// OR with --path
|
||||||
|
Bash({command: "cd <target-path> && ~/.claude/scripts/get_modules_by_depth.sh list", run_in_background: false});
|
||||||
```
|
```
|
||||||
|
|
||||||
**Parse output** `depth:N|path:<PATH>|...` to extract module paths and count.
|
**Parse output** `depth:N|path:<PATH>|...` to extract module paths and count.
|
||||||
@@ -172,26 +173,23 @@ Update Plan:
|
|||||||
|
|
||||||
**Strategy**: Parallel execution within layer (max 4 concurrent), no agent overhead.
|
**Strategy**: Parallel execution within layer (max 4 concurrent), no agent overhead.
|
||||||
|
|
||||||
```javascript
|
**CRITICAL**: All Bash commands use `run_in_background: false` for synchronous execution.
|
||||||
// Group modules by LAYER (not depth)
|
|
||||||
let modules_by_layer = group_by_layer(module_list);
|
|
||||||
let tool_order = construct_tool_order(primary_tool);
|
|
||||||
|
|
||||||
// Process by LAYER (3 → 2 → 1), not by depth
|
```javascript
|
||||||
for (let layer of [3, 2, 1]) {
|
for (let layer of [3, 2, 1]) {
|
||||||
if (modules_by_layer[layer].length === 0) continue;
|
if (modules_by_layer[layer].length === 0) continue;
|
||||||
|
|
||||||
let batches = batch_modules(modules_by_layer[layer], 4);
|
let batches = batch_modules(modules_by_layer[layer], 4);
|
||||||
|
|
||||||
for (let batch of batches) {
|
for (let batch of batches) {
|
||||||
let parallel_tasks = batch.map(module => {
|
let parallel_tasks = batch.map(module => {
|
||||||
return async () => {
|
return async () => {
|
||||||
// Auto-determine strategy based on depth
|
|
||||||
let strategy = module.depth >= 3 ? "multi-layer" : "single-layer";
|
let strategy = module.depth >= 3 ? "multi-layer" : "single-layer";
|
||||||
|
|
||||||
for (let tool of tool_order) {
|
for (let tool of tool_order) {
|
||||||
let exit_code = bash(`cd ${module.path} && ~/.claude/scripts/update_module_claude.sh "${strategy}" "." "${tool}"`);
|
Bash({
|
||||||
if (exit_code === 0) {
|
command: `cd ${module.path} && ~/.claude/scripts/update_module_claude.sh "${strategy}" "." "${tool}"`,
|
||||||
|
run_in_background: false
|
||||||
|
});
|
||||||
|
if (bash_result.exit_code === 0) {
|
||||||
report(`✅ ${module.path} (Layer ${layer}) updated with ${tool}`);
|
report(`✅ ${module.path} (Layer ${layer}) updated with ${tool}`);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -200,7 +198,6 @@ for (let layer of [3, 2, 1]) {
|
|||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
await Promise.all(parallel_tasks.map(task => task()));
|
await Promise.all(parallel_tasks.map(task => task()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -255,7 +252,10 @@ EXECUTION SCRIPT: ~/.claude/scripts/update_module_claude.sh
|
|||||||
EXECUTION FLOW (for each module):
|
EXECUTION FLOW (for each module):
|
||||||
1. Tool fallback loop (exit on first success):
|
1. Tool fallback loop (exit on first success):
|
||||||
for tool in {{tool_1}} {{tool_2}} {{tool_3}}; do
|
for tool in {{tool_1}} {{tool_2}} {{tool_3}}; do
|
||||||
bash(cd "{{module_path}}" && ~/.claude/scripts/update_module_claude.sh "{{strategy}}" "." "${tool}")
|
Bash({
|
||||||
|
command: `cd "{{module_path}}" && ~/.claude/scripts/update_module_claude.sh "{{strategy}}" "." "${tool}"`,
|
||||||
|
run_in_background: false
|
||||||
|
})
|
||||||
exit_code=$?
|
exit_code=$?
|
||||||
|
|
||||||
if [ $exit_code -eq 0 ]; then
|
if [ $exit_code -eq 0 ]; then
|
||||||
@@ -287,12 +287,12 @@ REPORTING FORMAT:
|
|||||||
```
|
```
|
||||||
### Phase 4: Safety Verification
|
### Phase 4: Safety Verification
|
||||||
|
|
||||||
```bash
|
```javascript
|
||||||
# Check only CLAUDE.md modified
|
// Check only CLAUDE.md files modified
|
||||||
bash(git diff --cached --name-only | grep -v "CLAUDE.md" || echo "Only CLAUDE.md files modified")
|
Bash({command: 'git diff --cached --name-only | grep -v "CLAUDE.md" || echo "Only CLAUDE.md files modified"', run_in_background: false});
|
||||||
|
|
||||||
# Display status
|
// Display status
|
||||||
bash(git status --short)
|
Bash({command: "git status --short", run_in_background: false});
|
||||||
```
|
```
|
||||||
|
|
||||||
**Result Summary**:
|
**Result Summary**:
|
||||||
|
|||||||
@@ -39,12 +39,12 @@ Orchestrates context-aware CLAUDE.md updates for changed modules using batched a
|
|||||||
|
|
||||||
## Phase 1: Change Detection & Analysis
|
## Phase 1: Change Detection & Analysis
|
||||||
|
|
||||||
```bash
|
```javascript
|
||||||
# Detect changed modules (no index refresh needed)
|
// Detect changed modules
|
||||||
bash(~/.claude/scripts/detect_changed_modules.sh list)
|
Bash({command: "~/.claude/scripts/detect_changed_modules.sh list", run_in_background: false});
|
||||||
|
|
||||||
# Cache git changes
|
// Cache git changes
|
||||||
bash(git add -A 2>/dev/null || true)
|
Bash({command: "git add -A 2>/dev/null || true", run_in_background: false});
|
||||||
```
|
```
|
||||||
|
|
||||||
**Parse output** `depth:N|path:<PATH>|change:<TYPE>` to extract affected modules.
|
**Parse output** `depth:N|path:<PATH>|change:<TYPE>` to extract affected modules.
|
||||||
@@ -89,47 +89,36 @@ Related Update Plan:
|
|||||||
|
|
||||||
## Phase 3A: Direct Execution (<15 modules)
|
## Phase 3A: Direct Execution (<15 modules)
|
||||||
|
|
||||||
**Strategy**: Parallel execution within depth (max 4 concurrent), no agent overhead, tool fallback per module.
|
**Strategy**: Parallel execution within depth (max 4 concurrent), no agent overhead.
|
||||||
|
|
||||||
|
**CRITICAL**: All Bash commands use `run_in_background: false` for synchronous execution.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
let modules_by_depth = group_by_depth(changed_modules);
|
|
||||||
let tool_order = construct_tool_order(primary_tool);
|
|
||||||
|
|
||||||
for (let depth of sorted_depths.reverse()) { // N → 0
|
for (let depth of sorted_depths.reverse()) { // N → 0
|
||||||
let modules = modules_by_depth[depth];
|
let batches = batch_modules(modules_by_depth[depth], 4);
|
||||||
let batches = batch_modules(modules, 4); // Split into groups of 4
|
|
||||||
|
|
||||||
for (let batch of batches) {
|
for (let batch of batches) {
|
||||||
// Execute batch in parallel (max 4 concurrent)
|
|
||||||
let parallel_tasks = batch.map(module => {
|
let parallel_tasks = batch.map(module => {
|
||||||
return async () => {
|
return async () => {
|
||||||
let success = false;
|
|
||||||
for (let tool of tool_order) {
|
for (let tool of tool_order) {
|
||||||
let exit_code = bash(cd ${module.path} && ~/.claude/scripts/update_module_claude.sh "single-layer" "." "${tool}");
|
Bash({
|
||||||
if (exit_code === 0) {
|
command: `cd ${module.path} && ~/.claude/scripts/update_module_claude.sh "single-layer" "." "${tool}"`,
|
||||||
report("${module.path} updated with ${tool}");
|
run_in_background: false
|
||||||
success = true;
|
});
|
||||||
break;
|
if (bash_result.exit_code === 0) {
|
||||||
|
report(`✅ ${module.path} updated with ${tool}`);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!success) {
|
report(`❌ FAILED: ${module.path} failed all tools`);
|
||||||
report("FAILED: ${module.path} failed all tools");
|
return false;
|
||||||
}
|
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
await Promise.all(parallel_tasks.map(task => task()));
|
||||||
await Promise.all(parallel_tasks.map(task => task())); // Run batch in parallel
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
**Benefits**:
|
|
||||||
- No agent startup overhead
|
|
||||||
- Parallel execution within depth (max 4 concurrent)
|
|
||||||
- Tool fallback still applies per module
|
|
||||||
- Faster for small changesets (<15 modules)
|
|
||||||
- Same batching strategy as Phase 3B but without agent layer
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Phase 3B: Agent Batch Execution (≥15 modules)
|
## Phase 3B: Agent Batch Execution (≥15 modules)
|
||||||
@@ -193,19 +182,27 @@ TOOLS (try in order):
|
|||||||
|
|
||||||
EXECUTION:
|
EXECUTION:
|
||||||
For each module above:
|
For each module above:
|
||||||
1. cd "{{module_path}}"
|
1. Try tool 1:
|
||||||
2. Try tool 1:
|
Bash({
|
||||||
bash(cd "{{module_path}}" && ~/.claude/scripts/update_module_claude.sh "single-layer" "." "{{tool_1}}")
|
command: `cd "{{module_path}}" && ~/.claude/scripts/update_module_claude.sh "single-layer" "." "{{tool_1}}"`,
|
||||||
→ Success: Report "{{module_path}} updated with {{tool_1}}", proceed to next module
|
run_in_background: false
|
||||||
|
})
|
||||||
|
→ Success: Report "✅ {{module_path}} updated with {{tool_1}}", proceed to next module
|
||||||
→ Failure: Try tool 2
|
→ Failure: Try tool 2
|
||||||
3. Try tool 2:
|
2. Try tool 2:
|
||||||
bash(cd "{{module_path}}" && ~/.claude/scripts/update_module_claude.sh "single-layer" "." "{{tool_2}}")
|
Bash({
|
||||||
→ Success: Report "{{module_path}} updated with {{tool_2}}", proceed to next module
|
command: `cd "{{module_path}}" && ~/.claude/scripts/update_module_claude.sh "single-layer" "." "{{tool_2}}"`,
|
||||||
|
run_in_background: false
|
||||||
|
})
|
||||||
|
→ Success: Report "✅ {{module_path}} updated with {{tool_2}}", proceed to next module
|
||||||
→ Failure: Try tool 3
|
→ Failure: Try tool 3
|
||||||
4. Try tool 3:
|
3. Try tool 3:
|
||||||
bash(cd "{{module_path}}" && ~/.claude/scripts/update_module_claude.sh "single-layer" "." "{{tool_3}}")
|
Bash({
|
||||||
→ Success: Report "{{module_path}} updated with {{tool_3}}", proceed to next module
|
command: `cd "{{module_path}}" && ~/.claude/scripts/update_module_claude.sh "single-layer" "." "{{tool_3}}"`,
|
||||||
→ Failure: Report "FAILED: {{module_path}} failed all tools", proceed to next module
|
run_in_background: false
|
||||||
|
})
|
||||||
|
→ Success: Report "✅ {{module_path}} updated with {{tool_3}}", proceed to next module
|
||||||
|
→ Failure: Report "❌ FAILED: {{module_path}} failed all tools", proceed to next module
|
||||||
|
|
||||||
REPORTING:
|
REPORTING:
|
||||||
Report final summary with:
|
Report final summary with:
|
||||||
@@ -213,30 +210,16 @@ Report final summary with:
|
|||||||
- Successful: Y modules
|
- Successful: Y modules
|
||||||
- Failed: Z modules
|
- Failed: Z modules
|
||||||
- Tool usage: {{tool_1}}:X, {{tool_2}}:Y, {{tool_3}}:Z
|
- Tool usage: {{tool_1}}:X, {{tool_2}}:Y, {{tool_3}}:Z
|
||||||
- Detailed results for each module
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Example Execution
|
|
||||||
|
|
||||||
**Depth 3 (new module)**:
|
|
||||||
```javascript
|
|
||||||
Task(subagent_type="memory-bridge", batch=[./src/api/auth], mode="related")
|
|
||||||
```
|
|
||||||
|
|
||||||
**Benefits**:
|
|
||||||
- 4 modules → 1 agent (75% reduction)
|
|
||||||
- Parallel batches, sequential within batch
|
|
||||||
- Each module gets full fallback chain
|
|
||||||
- Context-aware updates based on git changes
|
|
||||||
|
|
||||||
## Phase 4: Safety Verification
|
## Phase 4: Safety Verification
|
||||||
|
|
||||||
```bash
|
```javascript
|
||||||
# Check only CLAUDE.md modified
|
// Check only CLAUDE.md modified
|
||||||
bash(git diff --cached --name-only | grep -v "CLAUDE.md" || echo "Only CLAUDE.md files modified")
|
Bash({command: 'git diff --cached --name-only | grep -v "CLAUDE.md" || echo "Only CLAUDE.md files modified"', run_in_background: false});
|
||||||
|
|
||||||
# Display statistics
|
// Display statistics
|
||||||
bash(git diff --stat)
|
Bash({command: "git diff --stat", run_in_background: false});
|
||||||
```
|
```
|
||||||
|
|
||||||
**Aggregate results**:
|
**Aggregate results**:
|
||||||
|
|||||||
Reference in New Issue
Block a user