From a35fb0fe8f5b1ed4a34001efd53bb655d302277c Mon Sep 17 00:00:00 2001 From: catlog22 Date: Thu, 26 Feb 2026 11:20:06 +0800 Subject: [PATCH] fix(workflow): bridge analyze-with-file to lite-plan handoff and lower agent planning threshold - Add Post-Completion implementation in analyze-with-file Phase 4: write handoff-lite-plan.json and call Skill with --from-analysis flag - Add --from-analysis parsing in SKILL.md router (Step 0) to inject analysisHandoff into workflowPreferences - Reconstruct exploration context in lite-plan Phase 1 from upstream analysis artifacts, skipping redundant exploration and clarification - Tighten Low complexity criteria to truly trivial changes only - Expand agent trigger: analysisHandoff or multi-angle exploration forces cli-lite-planning-agent regardless of complexity --- .../commands/workflow/analyze-with-file.md | 59 +++++++++++++++++-- .claude/skills/workflow-lite-plan/SKILL.md | 10 ++++ .../workflow-lite-plan/phases/01-lite-plan.md | 42 +++++++++++-- 3 files changed, 100 insertions(+), 11 deletions(-) diff --git a/.claude/commands/workflow/analyze-with-file.md b/.claude/commands/workflow/analyze-with-file.md index 0e702213..1fbe49e3 100644 --- a/.claude/commands/workflow/analyze-with-file.md +++ b/.claude/commands/workflow/analyze-with-file.md @@ -508,11 +508,58 @@ CONSTRAINTS: ${perspective.constraints} - **Trade-offs Made**: Key trade-offs and why certain paths were chosen over others - Add session statistics: rounds, duration, sources, artifacts, **decision count** -3. **Post-Completion Options** (AskUserQuestion) - - **创建Issue**: Launch issue-discover with conclusions - - **生成任务**: Launch workflow-lite-plan for implementation - - **导出报告**: Generate standalone analysis report - - **完成**: No further action +3. **Post-Completion Options** + + ```javascript + const hasActionableRecs = conclusions.recommendations?.some(r => r.priority === 'high' || r.priority === 'medium') + + const nextStep = AskUserQuestion({ + questions: [{ + question: "Analysis complete. What's next?", + header: "Next Step", + multiSelect: false, + options: [ + { label: hasActionableRecs ? "生成任务 (Recommended)" : "生成任务", description: "Launch workflow-lite-plan with analysis context" }, + { label: "创建Issue", description: "Launch issue-discover with conclusions" }, + { label: "导出报告", description: "Generate standalone analysis report" }, + { label: "完成", description: "No further action" } + ] + }] + }) + ``` + + **Handle "生成任务"**: + ```javascript + if (nextStep.includes("生成任务")) { + // 1. Build task description from high/medium priority recommendations + const taskDescription = conclusions.recommendations + .filter(r => r.priority === 'high' || r.priority === 'medium') + .map(r => r.action) + .join('\n') || conclusions.summary + + // 2. Extract exploration digest (inline data, not path reference) + const explorationDigest = { relevant_files: [], patterns: [], key_findings: [] } + const codebasePath = `${sessionFolder}/exploration-codebase.json` + if (file_exists(codebasePath)) { + const data = JSON.parse(Read(codebasePath)) + explorationDigest.relevant_files = data.relevant_files || [] + explorationDigest.patterns = data.patterns || [] + explorationDigest.key_findings = data.key_findings || [] + } + + // 3. Write handoff file to analysis session folder + Write(`${sessionFolder}/handoff-lite-plan.json`, JSON.stringify({ + source_session: sessionId, + summary: conclusions.summary, + recommendations: conclusions.recommendations, + decision_trail: conclusions.decision_trail, + exploration_digest: explorationDigest + }, null, 2)) + + // 4. Call lite-plan with --from-analysis handoff + Skill(skill="workflow-lite-plan", args=`--from-analysis ${sessionFolder}/handoff-lite-plan.json "${taskDescription}"`) + } + ``` **conclusions.json Schema**: - `session_id`: Session identifier @@ -691,6 +738,8 @@ User agrees with current direction, wants deeper code analysis - Need simple task breakdown - Focus on quick execution planning +> **Note**: Phase 4「生成任务」auto-generates `--from-analysis` handoff. Manual invocation normally not needed after analysis. + --- **Now execute analyze-with-file for**: $ARGUMENTS diff --git a/.claude/skills/workflow-lite-plan/SKILL.md b/.claude/skills/workflow-lite-plan/SKILL.md index cb01ee72..3bb5cf0a 100644 --- a/.claude/skills/workflow-lite-plan/SKILL.md +++ b/.claude/skills/workflow-lite-plan/SKILL.md @@ -111,6 +111,16 @@ if (autoYes) { After collecting preferences, enhance context and dispatch: ```javascript +// Step 0: Parse --from-analysis handoff (from analyze-with-file) +const fromAnalysisMatch = args.match(/--from-analysis\s+(\S+)/) +if (fromAnalysisMatch) { + const handoffPath = fromAnalysisMatch[1] + workflowPreferences.analysisHandoff = JSON.parse(Read(handoffPath)) + workflowPreferences.forceExplore = false + // Strip flag from args, keep task description + args = args.replace(/--from-analysis\s+\S+\s*/, '').trim() +} + // Step 1: Check for project context files const hasProjectTech = fileExists('.workflow/project-tech.json') const hasProjectGuidelines = fileExists('.workflow/project-guidelines.json') diff --git a/.claude/skills/workflow-lite-plan/phases/01-lite-plan.md b/.claude/skills/workflow-lite-plan/phases/01-lite-plan.md index c4c10553..1469bfba 100644 --- a/.claude/skills/workflow-lite-plan/phases/01-lite-plan.md +++ b/.claude/skills/workflow-lite-plan/phases/01-lite-plan.md @@ -106,7 +106,27 @@ bash(`mkdir -p ${sessionFolder} && test -d ${sessionFolder} && echo "SUCCESS: ${ **Exploration Decision Logic**: ```javascript -needsExploration = ( +// Analysis handoff: reconstruct exploration from upstream analysis artifacts +if (workflowPreferences.analysisHandoff) { + const handoff = workflowPreferences.analysisHandoff + Write(`${sessionFolder}/exploration-from-analysis.json`, JSON.stringify({ + relevant_files: handoff.exploration_digest.relevant_files || [], + patterns: handoff.exploration_digest.patterns || [], + key_findings: handoff.exploration_digest.key_findings || [], + clarification_needs: [], // analysis already did multi-round discussion + _metadata: { exploration_angle: "from-analysis", source_session: handoff.source_session, reconstructed: true } + }, null, 2)) + Write(`${sessionFolder}/explorations-manifest.json`, JSON.stringify({ + session_id: sessionId, task_description: task_description, timestamp: getUtc8ISOString(), + complexity: complexity, exploration_count: 1, from_analysis: handoff.source_session, + explorations: [{ angle: "from-analysis", file: "exploration-from-analysis.json", + path: `${sessionFolder}/exploration-from-analysis.json`, index: 1 }] + }, null, 2)) + needsExploration = false + // clarification_needs=[] → Phase 2 naturally skipped → proceed to Phase 3 +} + +needsExploration = needsExploration ?? ( workflowPreferences.forceExplore || task.mentions_specific_files || task.requires_codebase_context || @@ -132,9 +152,13 @@ if (!needsExploration) { const complexity = analyzeTaskComplexity(task_description) // Returns: 'Low' | 'Medium' | 'High' -// Low: Single file, isolated change, minimal risk -// Medium: Multiple files, some dependencies, moderate risk -// High: Cross-module, architectural, high risk +// Low: ONLY truly trivial — single file, single function, zero cross-module impact, no new patterns +// Examples: fix typo, rename variable, add log line, adjust constant value +// Medium: Multiple files OR any integration point OR new pattern introduction OR moderate risk +// Examples: add endpoint, implement feature, refactor module, fix bug spanning files +// High: Cross-module, architectural, or systemic change +// Examples: new subsystem, migration, security overhaul, API redesign +// ⚠️ Default bias: When uncertain between Low and Medium, choose Medium // Angle assignment based on task type (orchestrator decides, not agent) const ANGLE_PRESETS = { @@ -160,8 +184,14 @@ function selectAngles(taskDescription, count) { const selectedAngles = selectAngles(task_description, complexity === 'High' ? 4 : (complexity === 'Medium' ? 3 : 1)) // Planning strategy determination -const planningStrategy = complexity === 'Low' - ? 'Direct Claude Planning' +// Agent trigger: anything beyond trivial single-file change +// - analysisHandoff → always agent (analysis validated non-trivial task) +// - multi-angle exploration → agent (complexity warranted multiple angles) +// - Medium/High complexity → agent +// Direct Claude planning ONLY for truly trivial Low + no analysis + single angle +const planningStrategy = ( + complexity === 'Low' && !workflowPreferences.analysisHandoff && selectedAngles.length <= 1 +) ? 'Direct Claude Planning' : 'cli-lite-planning-agent' console.log(`