feat(cli): add support for custom execution IDs and multi-turn conversations

- Introduced `--id <id>` option in CLI for custom execution IDs.
- Enhanced CLI command handling to support multi-turn conversations.
- Updated execution and conversation detail retrieval to accommodate new structure.
- Implemented merging of multiple conversations with tracking of source IDs.
- Improved history management to save and load conversation records.
- Added styles for displaying multi-turn conversation details in the dashboard.
- Refactored existing execution detail functions for backward compatibility.
This commit is contained in:
catlog22
2025-12-13 14:03:24 +08:00
parent 23e15e479e
commit c780544792
14 changed files with 1483 additions and 640 deletions

View File

@@ -54,6 +54,14 @@ Phase 3: Planning (NO CODE EXECUTION - planning only)
└─ Decision (based on Phase 1 complexity):
├─ Low → Load schema: cat ~/.claude/workflows/cli-templates/schemas/plan-json-schema.json → Direct Claude planning (following schema) → plan.json → MUST proceed to Phase 4
└─ Medium/High → cli-lite-planning-agent → plan.json → MUST proceed to Phase 4
└─ CLI Execution ID Assignment (MANDATORY for all tasks):
├─ Generate cli_execution_id for each task (format: {sessionId}-T{N})
└─ Compute cli_execution strategy based on depends_on:
├─ No deps → strategy: "new"
├─ 1 dep + sequential → strategy: "resume", resume_from: parent.cli_execution_id
├─ 1 dep + parallel children → strategy: "fork", resume_from: parent.cli_execution_id
├─ N deps → strategy: "merge", merge_from: [parent1.cli_execution_id, ...]
└─ N deps + creates branch → strategy: "merge_fork", merge_from: [...], new ID
Phase 4: Confirmation & Selection
├─ Display plan summary (tasks, complexity, estimated time)
@@ -373,17 +381,73 @@ manifest.explorations.forEach(exp => {
const plan = {
summary: "...",
approach: "...",
tasks: [...], // Each task: { id, title, scope, ..., depends_on, execution_group, complexity }
tasks: [...], // Each task: { id, title, scope, ..., depends_on, cli_execution_id, cli_execution }
estimated_time: "...",
recommended_execution: "Agent",
complexity: "Low",
_metadata: { timestamp: getUtc8ISOString(), source: "direct-planning", planning_mode: "direct" }
}
// Step 4: Write plan to session folder
// Step 4: ⚠️ MANDATORY - Assign CLI Execution IDs and strategies
assignCliExecutionIds(plan.tasks, sessionId)
// Step 5: Write plan to session folder
Write(`${sessionFolder}/plan.json`, JSON.stringify(plan, null, 2))
// Step 5: MUST continue to Phase 4 (Confirmation) - DO NOT execute code here
// Step 6: MUST continue to Phase 4 (Confirmation) - DO NOT execute code here
```
**CLI Execution ID Assignment Function** (MANDATORY for ALL planning modes):
```javascript
function assignCliExecutionIds(tasks, sessionId) {
// Build dependency graph
const taskMap = new Map(tasks.map(t => [t.id, t]))
const childCount = new Map() // Track how many tasks depend on each task
tasks.forEach(task => {
(task.depends_on || []).forEach(depId => {
childCount.set(depId, (childCount.get(depId) || 0) + 1)
})
})
tasks.forEach(task => {
// Assign unique CLI execution ID
task.cli_execution_id = `${sessionId}-${task.id}`
const deps = task.depends_on || []
if (deps.length === 0) {
// No dependencies: new conversation
task.cli_execution = { strategy: "new" }
} else if (deps.length === 1) {
const parent = taskMap.get(deps[0])
const parentChildCount = childCount.get(deps[0]) || 0
if (parentChildCount === 1) {
// Single child: resume (continue same conversation)
task.cli_execution = {
strategy: "resume",
resume_from: parent.cli_execution_id
}
} else {
// Multiple children: fork (create new branch)
task.cli_execution = {
strategy: "fork",
resume_from: parent.cli_execution_id
}
}
} else {
// Multiple dependencies: merge
const mergeFrom = deps.map(depId => taskMap.get(depId).cli_execution_id)
task.cli_execution = {
strategy: "merge_fork", // Merge always creates new ID
merge_from: mergeFrom
}
}
})
return tasks
}
```
**Medium/High Complexity** - Invoke cli-lite-planning-agent:
@@ -398,6 +462,15 @@ Generate implementation plan and write plan.json.
## Output Schema Reference
Execute: cat ~/.claude/workflows/cli-templates/schemas/plan-json-schema.json (get schema reference before generating plan)
## CLI Execution ID Requirements (MANDATORY)
After generating tasks, you MUST assign CLI execution IDs and strategies:
1. Each task needs cli_execution_id: {sessionId}-{task.id}
2. Compute cli_execution.strategy based on depends_on:
- No deps → { strategy: "new" }
- 1 dep (single child) → { strategy: "resume", resume_from: parent.cli_execution_id }
- 1 dep (multiple children) → { strategy: "fork", resume_from: parent.cli_execution_id }
- N deps → { strategy: "merge_fork", merge_from: [parent1.cli_execution_id, ...] }
## Task Description
${task_description}