@@ -238,16 +238,32 @@ Session: ${sessionFolder}
238238
239239## MANDATORY FIRST STEPS
2402401. Run: ccw tool exec get_modules_by_depth '{}'
241- 2. Execute relevant searches based on topic keywords
242- 3. Read: .workflow/project-tech.json (if exists)
241+ 2. Read: .workflow/project-tech.json (if exists)
242+
243+ ## Layered Exploration (MUST follow all 3 layers)
244+
245+ ### Layer 1 — Module Discovery (Breadth)
246+ - Search codebase by topic keywords, identify ALL relevant files
247+ - Map module boundaries and entry points
248+ - Output: relevant_files[] with file role annotations
249+
250+ ### Layer 2 — Structure Tracing (Depth)
251+ - For top 3-5 key files from Layer 1: trace call chains (2-3 levels deep)
252+ - Identify data flow paths and dependency relationships
253+ - Output: call_chains[], data_flows[]
254+
255+ ### Layer 3 — Code Anchor Extraction (Detail)
256+ - For each key finding: extract the actual code snippet (20-50 lines) with file:line reference
257+ - Annotate WHY this code matters to the analysis topic
258+ - Output: code_anchors[] — these are CRITICAL for subsequent analysis quality
243259
244260## Exploration Focus
245261${ dimensions .map (d => ` - ${ d} : Identify relevant code patterns and structures` ).join (' \n ' )}
246262
247263## Output
248264Write findings to: ${ sessionFolder} /exploration-codebase.json
249265
250- Schema: {relevant_files, patterns, key_findings, questions_for_user, _metadata}
266+ Schema: {relevant_files, patterns, key_findings, code_anchors: [{file, lines, snippet, significance}], call_chains: [{entry, chain, files}], questions_for_user, _metadata}
251267`
252268})
253269```
@@ -268,16 +284,29 @@ Session: ${sessionFolder}
268284
269285## MANDATORY FIRST STEPS
2702861. Run: ccw tool exec get_modules_by_depth '{}'
271- 2. Execute searches focused on ${ perspective .focus }
272- 3. Read: .workflow/project-tech.json (if exists)
287+ 2. Read: .workflow/project-tech.json (if exists)
288+
289+ ## Layered Exploration (${ perspective .name } angle, MUST follow all 3 layers)
290+
291+ ### Layer 1 — Module Discovery
292+ - Search codebase focused on ${ perspective .focus }
293+ - Identify ALL relevant files for this perspective
294+
295+ ### Layer 2 — Structure Tracing
296+ - For top 3-5 key files: trace call chains (2-3 levels deep)
297+ - Map data flows relevant to ${ perspective .focus }
298+
299+ ### Layer 3 — Code Anchor Extraction
300+ - For each key finding: extract actual code snippet (20-50 lines) with file:line
301+ - Annotate significance for ${ perspective .name } analysis
273302
274303## Exploration Focus (${ perspective .name } angle)
275304${ perspective .exploration_tasks .map (t => ` - ${ t} ` ).join (' \n ' )}
276305
277306## Output
278307Write findings to: ${ sessionFolder} /explorations/${ perspective .name } .json
279308
280- Schema: {relevant_files, patterns, key_findings, perspective_insights, _metadata}
309+ Schema: {relevant_files, patterns, key_findings, code_anchors: [{file, lines, snippet, significance}], call_chains: [{entry, chain, files}], perspective_insights, _metadata}
281310`
282311 })
283312})
@@ -301,11 +330,14 @@ PRIOR EXPLORATION CONTEXT:
301330- Key files: ${ explorationResults .relevant_files .slice (0 ,5 ).map (f => f .path ).join (' , ' )}
302331- Patterns found: ${ explorationResults .patterns .slice (0 ,3 ).join (' , ' )}
303332- Key findings: ${ explorationResults .key_findings .slice (0 ,3 ).join (' , ' )}
333+ - Code anchors (actual code snippets):
334+ ${ (explorationResults .code_anchors || []).slice (0 ,5 ).map (a => ` [${ a .file } :${ a .lines } ] ${ a .significance } \n \`\`\`\n ${ a .snippet } \n \`\`\` ` ).join (' \n ' )}
335+ - Call chains: ${ (explorationResults .call_chains || []).slice (0 ,3 ).map (c => ` ${ c .entry } → ${ c .chain .join (' → ' )} ` ).join (' ; ' )}
304336
305337TASK:
306- • Build on exploration findings above
307- • Analyze common patterns and anti-patterns
308- • Highlight potential issues or opportunities
338+ • Build on exploration findings above — reference specific code anchors in analysis
339+ • Analyze common patterns and anti-patterns with code evidence
340+ • Highlight potential issues or opportunities with file:line references
309341• Generate discussion points for user clarification
310342
311343MODE: analysis
@@ -324,7 +356,10 @@ const explorationContext = `
324356PRIOR EXPLORATION CONTEXT:
325357- Key files: ${ explorationResults .relevant_files .slice (0 ,5 ).map (f => f .path ).join (' , ' )}
326358- Patterns found: ${ explorationResults .patterns .slice (0 ,3 ).join (' , ' )}
327- - Key findings: ${ explorationResults .key_findings .slice (0 ,3 ).join (' , ' )} `
359+ - Key findings: ${ explorationResults .key_findings .slice (0 ,3 ).join (' , ' )}
360+ - Code anchors:
361+ ${ (explorationResults .code_anchors || []).slice (0 ,5 ).map (a => ` [${ a .file } :${ a .lines } ] ${ a .significance } ` ).join (' \n ' )}
362+ - Call chains: ${ (explorationResults .call_chains || []).slice (0 ,3 ).map (c => ` ${ c .entry } → ${ c .chain .join (' → ' )} ` ).join (' ; ' )} `
328363
329364// Launch parallel CLI calls based on selected perspectives (max 4)
330365selectedPerspectives .forEach (perspective => {
@@ -368,6 +403,8 @@ CONSTRAINTS: ${perspective.constraints}
368403- ` dimensions[] ` : Analysis dimensions
369404- ` sources[] ` : {type, file/summary}
370405- ` key_findings[] ` : Main insights
406+ - ` code_anchors[] ` : {file, lines, snippet, significance}
407+ - ` call_chains[] ` : {entry, chain, files}
371408- ` discussion_points[] ` : Questions for user
372409- ` open_questions[] ` : Unresolved questions
373410
@@ -378,7 +415,9 @@ CONSTRAINTS: ${perspective.constraints}
378415- ` dimensions[] ` : Analysis dimensions
379416- ` perspectives[] ` : [ {name, tool, findings, insights, questions}]
380417- ` synthesis ` : {convergent_themes, conflicting_views, unique_contributions}
381- - ` aggregated_findings[] ` : Main insights across perspectives
418+ - ` key_findings[] ` : Main insights across perspectives
419+ - ` code_anchors[] ` : {file, lines, snippet, significance, perspective}
420+ - ` call_chains[] ` : {entry, chain, files, perspective}
382421- ` discussion_points[] ` : Questions for user
383422- ` open_questions[] ` : Unresolved questions
384423
@@ -423,9 +462,14 @@ CONSTRAINTS: ${perspective.constraints}
423462 - If direction changed, record a full Decision Record
424463
425464 ** Agree, Deepen** :
426- - Continue analysis in current direction
427- - Use CLI for deeper exploration
428- - ** 📌 Record** : Which assumptions were confirmed, specific angles for deeper exploration
465+ - AskUserQuestion for deepen direction (single-select):
466+ - ** 代码细节** : Read specific files, trace call chains deeper → cli-explore-agent with targeted file list
467+ - ** 边界条件** : Analyze error handling, edge cases, failure paths → Gemini CLI focused on error paths
468+ - ** 替代方案** : Compare different implementation approaches → Gemini CLI comparative analysis
469+ - ** 性能/安全** : Analyze hot paths, complexity, or security vectors → cli-explore-agent + domain prompt
470+ - Launch new cli-explore-agent or CLI call with ** narrower scope + deeper depth requirement**
471+ - Merge new code_anchors and call_chains into existing exploration results
472+ - ** 📌 Record** : Which assumptions were confirmed, specific angles for deeper exploration, deepen direction chosen
429473
430474 ** Adjust Direction** :
431475 - AskUserQuestion for adjusted focus (code details / architecture / best practices)
@@ -471,7 +515,10 @@ CONSTRAINTS: ${perspective.constraints}
471515
472516| User Choice | Action | Tool | Description |
473517| -------------| --------| ------| -------------|
474- | Deepen | Continue current direction | Gemini CLI | Deeper analysis in same focus |
518+ | Deepen → 代码细节 | Read files, trace call chains | cli-explore-agent | Targeted deep-dive into specific files |
519+ | Deepen → 边界条件 | Analyze error/edge cases | Gemini CLI | Focus on failure paths and edge cases |
520+ | Deepen → 替代方案 | Compare approaches | Gemini CLI | Comparative analysis |
521+ | Deepen → 性能/安全 | Analyze hot paths/vectors | cli-explore-agent | Domain-specific deep analysis |
475522| Adjust | Change analysis angle | Selected CLI | New exploration with adjusted scope |
476523| Questions | Answer specific questions | CLI or analysis | Address user inquiries |
477524| Complete | Exit discussion loop | - | Proceed to synthesis |
@@ -629,7 +676,8 @@ DO NOT reference any analyze-with-file phase instructions beyond this point.
629676- ` completed` : Completion timestamp
630677- ` total_rounds` : Number of discussion rounds
631678- ` summary` : Executive summary
632- - ` key_conclusions[]` : {point, evidence, confidence}
679+ - ` key_conclusions[]` : {point, evidence, confidence, code_anchor_refs[]}
680+ - ` code_anchors[]` : {file, lines, snippet, significance}
633681- ` recommendations[]` : {action, rationale, priority}
634682- ` open_questions[]` : Unresolved questions
635683- ` follow_up_suggestions[]` : {type, summary}
0 commit comments