@bastani/atomic 0.5.3-1 → 0.5.4-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +110 -11
- package/dist/{chunk-mn870nrv.js → chunk-xkxndz5g.js} +213 -154
- package/dist/sdk/components/workflow-picker-panel.d.ts +120 -0
- package/dist/sdk/define-workflow.d.ts +1 -1
- package/dist/sdk/index.js +1 -1
- package/dist/sdk/runtime/discovery.d.ts +57 -3
- package/dist/sdk/runtime/executor.d.ts +15 -2
- package/dist/sdk/runtime/tmux.d.ts +9 -0
- package/dist/sdk/types.d.ts +63 -4
- package/dist/sdk/workflows/builtin/deep-research-codebase/claude/index.d.ts +61 -0
- package/dist/sdk/workflows/builtin/deep-research-codebase/copilot/index.d.ts +48 -0
- package/dist/sdk/workflows/builtin/deep-research-codebase/helpers/heuristic.d.ts +25 -0
- package/dist/sdk/workflows/builtin/deep-research-codebase/helpers/prompts.d.ts +91 -0
- package/dist/sdk/workflows/builtin/deep-research-codebase/helpers/scout.d.ts +56 -0
- package/dist/sdk/workflows/builtin/deep-research-codebase/opencode/index.d.ts +48 -0
- package/dist/sdk/workflows/builtin/ralph/claude/index.js +6 -5
- package/dist/sdk/workflows/builtin/ralph/copilot/index.js +6 -5
- package/dist/sdk/workflows/builtin/ralph/opencode/index.js +6 -5
- package/dist/sdk/workflows/index.d.ts +4 -4
- package/dist/sdk/workflows/index.js +7 -1
- package/package.json +1 -1
- package/src/cli.ts +25 -3
- package/src/commands/cli/chat/index.ts +5 -5
- package/src/commands/cli/init/index.ts +79 -77
- package/src/commands/cli/workflow-command.test.ts +757 -0
- package/src/commands/cli/workflow.test.ts +310 -0
- package/src/commands/cli/workflow.ts +445 -105
- package/src/sdk/components/workflow-picker-panel.tsx +1462 -0
- package/src/sdk/define-workflow.test.ts +101 -0
- package/src/sdk/define-workflow.ts +62 -2
- package/src/sdk/runtime/discovery.ts +111 -8
- package/src/sdk/runtime/executor.ts +89 -32
- package/src/sdk/runtime/tmux.conf +55 -0
- package/src/sdk/runtime/tmux.ts +34 -10
- package/src/sdk/types.ts +67 -4
- package/src/sdk/workflows/builtin/deep-research-codebase/claude/index.ts +294 -0
- package/src/sdk/workflows/builtin/deep-research-codebase/copilot/index.ts +276 -0
- package/src/sdk/workflows/builtin/deep-research-codebase/helpers/heuristic.ts +38 -0
- package/src/sdk/workflows/builtin/deep-research-codebase/helpers/prompts.ts +816 -0
- package/src/sdk/workflows/builtin/deep-research-codebase/helpers/scout.ts +334 -0
- package/src/sdk/workflows/builtin/deep-research-codebase/opencode/index.ts +284 -0
- package/src/sdk/workflows/builtin/ralph/claude/index.ts +8 -4
- package/src/sdk/workflows/builtin/ralph/copilot/index.ts +10 -4
- package/src/sdk/workflows/builtin/ralph/opencode/index.ts +8 -4
- package/src/sdk/workflows/index.ts +9 -1
- package/src/services/system/auto-sync.ts +1 -1
- package/src/services/system/install-ui.ts +109 -39
- package/src/theme/colors.ts +65 -1
|
@@ -0,0 +1,816 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prompt builders for the deep-research-codebase workflow.
|
|
3
|
+
*
|
|
4
|
+
* Context-engineering principles applied throughout:
|
|
5
|
+
* - Position-aware placement: the research question is repeated at the
|
|
6
|
+
* TOP and BOTTOM of every prompt (recall is 85-95% at the edges and
|
|
7
|
+
* drops to 76-82% in the middle — see context-fundamentals).
|
|
8
|
+
* - Informativity over exhaustiveness: each explorer prompt contains
|
|
9
|
+
* only that explorer's partition, never the full file list.
|
|
10
|
+
* - Explicit trailing commentary (F6): every prompt asks the agent to
|
|
11
|
+
* produce a short text summary AFTER any tool/file output, so the
|
|
12
|
+
* transcript is not empty when downstream stages read it.
|
|
13
|
+
* - File-based handoff (filesystem-context skill): explorer findings
|
|
14
|
+
* are written to disk and the aggregator reads them by path, instead
|
|
15
|
+
* of inlining N transcripts into the aggregator's prompt.
|
|
16
|
+
* - Documentarian role: every prompt explicitly forbids critique or
|
|
17
|
+
* improvement suggestions; we are recording what exists.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import path from "node:path";
|
|
21
|
+
import type { PartitionUnit } from "./scout.ts";
|
|
22
|
+
|
|
23
|
+
const DOCUMENTARIAN_DISCLAIMER =
|
|
24
|
+
"You are a documentarian, not a critic. Document what EXISTS — do not " +
|
|
25
|
+
"propose improvements, identify issues, or suggest refactors. Focus on " +
|
|
26
|
+
"concrete file paths, line numbers, and how things actually work.";
|
|
27
|
+
|
|
28
|
+
/** Slugify the user's prompt for use in the final research filename. */
|
|
29
|
+
export function slugifyPrompt(prompt: string): string {
|
|
30
|
+
const slug = prompt
|
|
31
|
+
.toLowerCase()
|
|
32
|
+
.replace(/[^a-z0-9\s-]/g, "")
|
|
33
|
+
.split(/\s+/)
|
|
34
|
+
.filter(Boolean)
|
|
35
|
+
.slice(0, 6)
|
|
36
|
+
.join("-")
|
|
37
|
+
.substring(0, 60);
|
|
38
|
+
return slug || "research";
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
42
|
+
// Stage 1 — codebase-scout
|
|
43
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
44
|
+
|
|
45
|
+
export function buildScoutPrompt(opts: {
|
|
46
|
+
question: string;
|
|
47
|
+
tree: string;
|
|
48
|
+
totalLoc: number;
|
|
49
|
+
totalFiles: number;
|
|
50
|
+
explorerCount: number;
|
|
51
|
+
partitionPreview: PartitionUnit[][];
|
|
52
|
+
}): string {
|
|
53
|
+
const partitionPreview = opts.partitionPreview
|
|
54
|
+
.map((bin, i) => {
|
|
55
|
+
const dirs = bin.map((u) => `\`${u.path}/\``).join(", ");
|
|
56
|
+
const loc = bin.reduce((s, u) => s + u.loc, 0);
|
|
57
|
+
return ` ${i + 1}. ${dirs} — ${loc.toLocaleString()} LOC`;
|
|
58
|
+
})
|
|
59
|
+
.join("\n");
|
|
60
|
+
|
|
61
|
+
return [
|
|
62
|
+
`<RESEARCH_QUESTION>`,
|
|
63
|
+
opts.question,
|
|
64
|
+
`</RESEARCH_QUESTION>`,
|
|
65
|
+
``,
|
|
66
|
+
`<CONTEXT>`,
|
|
67
|
+
`You are the codebase scout for the deep-research-codebase workflow. The`,
|
|
68
|
+
`workflow has already computed the codebase layout deterministically:`,
|
|
69
|
+
``,
|
|
70
|
+
`- Total source files: ${opts.totalFiles.toLocaleString()}`,
|
|
71
|
+
`- Total LOC: ${opts.totalLoc.toLocaleString()}`,
|
|
72
|
+
`- Explorers to spawn: ${opts.explorerCount} (chosen by LOC heuristic)`,
|
|
73
|
+
``,
|
|
74
|
+
`Pre-computed partition assignments (${opts.explorerCount} explorers):`,
|
|
75
|
+
partitionPreview,
|
|
76
|
+
``,
|
|
77
|
+
`Compact directory tree (depth 3, ≤200 entries):`,
|
|
78
|
+
"```",
|
|
79
|
+
opts.tree,
|
|
80
|
+
"```",
|
|
81
|
+
`</CONTEXT>`,
|
|
82
|
+
``,
|
|
83
|
+
`<TASK>`,
|
|
84
|
+
`Read the tree above and produce a brief architectural orientation that`,
|
|
85
|
+
`will help the ${opts.explorerCount} parallel explorer sub-agents understand the`,
|
|
86
|
+
`layout BEFORE they dive into their assigned partitions.`,
|
|
87
|
+
``,
|
|
88
|
+
`Cover, in ≤300 words:`,
|
|
89
|
+
` 1. The repo's overall shape (monorepo vs single package, polyglot or not)`,
|
|
90
|
+
` 2. The 3-5 most important top-level directories and what each contains`,
|
|
91
|
+
` 3. Architectural boundaries / layering you can see from the tree`,
|
|
92
|
+
` 4. Where entry points or main modules likely live`,
|
|
93
|
+
``,
|
|
94
|
+
`Do NOT attempt to answer the research question yet — your job is`,
|
|
95
|
+
`orientation for downstream explorers, not investigation. You may use`,
|
|
96
|
+
`Read/Glob/Grep sparingly to verify your guesses about a few key files,`,
|
|
97
|
+
`but keep the output short.`,
|
|
98
|
+
`</TASK>`,
|
|
99
|
+
``,
|
|
100
|
+
`<CONSTRAINTS>`,
|
|
101
|
+
DOCUMENTARIAN_DISCLAIMER,
|
|
102
|
+
`Stay under 300 words. No bullet lists longer than 5 items.`,
|
|
103
|
+
`End with a short prose paragraph (NOT a tool call) so this transcript`,
|
|
104
|
+
`has content for downstream stages to read.`,
|
|
105
|
+
`</CONSTRAINTS>`,
|
|
106
|
+
``,
|
|
107
|
+
`<RESEARCH_QUESTION_REMINDER>`,
|
|
108
|
+
opts.question,
|
|
109
|
+
`</RESEARCH_QUESTION_REMINDER>`,
|
|
110
|
+
].join("\n");
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
114
|
+
// Stage 2 — explorer-N
|
|
115
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
116
|
+
|
|
117
|
+
export function buildExplorerPrompt(opts: {
|
|
118
|
+
question: string;
|
|
119
|
+
index: number;
|
|
120
|
+
total: number;
|
|
121
|
+
partition: PartitionUnit[];
|
|
122
|
+
scoutOverview: string;
|
|
123
|
+
scratchPath: string;
|
|
124
|
+
root: string;
|
|
125
|
+
}): string {
|
|
126
|
+
const assignmentLines = opts.partition
|
|
127
|
+
.map((u) => {
|
|
128
|
+
const abs = path.join(opts.root, u.path);
|
|
129
|
+
return ` - \`${abs}/\` (${u.fileCount} files, ${u.loc.toLocaleString()} LOC)`;
|
|
130
|
+
})
|
|
131
|
+
.join("\n");
|
|
132
|
+
|
|
133
|
+
// Comma-separated absolute dir list — used in subagent dispatch prompts as
|
|
134
|
+
// an unambiguous scope constraint that the locator/pattern-finder can pass
|
|
135
|
+
// straight to Glob.
|
|
136
|
+
const dirListAbs = opts.partition
|
|
137
|
+
.map((u) => `\`${path.join(opts.root, u.path)}\``)
|
|
138
|
+
.join(", ");
|
|
139
|
+
|
|
140
|
+
const orientation = opts.scoutOverview.trim().length > 0
|
|
141
|
+
? opts.scoutOverview.trim()
|
|
142
|
+
: "(scout overview unavailable — proceed without)";
|
|
143
|
+
|
|
144
|
+
return [
|
|
145
|
+
`<RESEARCH_QUESTION>`,
|
|
146
|
+
opts.question,
|
|
147
|
+
`</RESEARCH_QUESTION>`,
|
|
148
|
+
``,
|
|
149
|
+
`<YOUR_IDENTITY>`,
|
|
150
|
+
`You are explorer ${opts.index} of ${opts.total}. You are a COORDINATOR — your`,
|
|
151
|
+
`job is to dispatch specialized research sub-agents and synthesize their`,
|
|
152
|
+
`findings. You do NOT use Read/Glob/Grep yourself; you orchestrate the`,
|
|
153
|
+
`specialists. The codebase has been partitioned across ${opts.total} parallel`,
|
|
154
|
+
`explorers — you are responsible for your assigned slice. Other explorers`,
|
|
155
|
+
`are simultaneously covering the rest.`,
|
|
156
|
+
`</YOUR_IDENTITY>`,
|
|
157
|
+
``,
|
|
158
|
+
`<ARCHITECTURAL_ORIENTATION>`,
|
|
159
|
+
`The codebase scout produced this overview to help you orient before dispatch:`,
|
|
160
|
+
``,
|
|
161
|
+
orientation,
|
|
162
|
+
`</ARCHITECTURAL_ORIENTATION>`,
|
|
163
|
+
``,
|
|
164
|
+
`<YOUR_ASSIGNMENT>`,
|
|
165
|
+
`Your assigned directories (DO NOT search outside these — other explorers`,
|
|
166
|
+
`cover the rest):`,
|
|
167
|
+
``,
|
|
168
|
+
assignmentLines,
|
|
169
|
+
`</YOUR_ASSIGNMENT>`,
|
|
170
|
+
``,
|
|
171
|
+
`<RESEARCH_PROTOCOL>`,
|
|
172
|
+
`Execute these steps IN ORDER. Each numbered step must complete before the`,
|
|
173
|
+
`next begins. Use the exact \`@"name (agent)"\` dispatch syntax shown below.`,
|
|
174
|
+
``,
|
|
175
|
+
`── STEP 1 — Locate relevant files (codebase-locator) ──`,
|
|
176
|
+
``,
|
|
177
|
+
`Dispatch the codebase-locator. Constrain it strictly to your assigned dirs:`,
|
|
178
|
+
``,
|
|
179
|
+
` @"codebase-locator (agent)" CRITICAL: search ONLY within these directories`,
|
|
180
|
+
` (do not search elsewhere): ${dirListAbs}.`,
|
|
181
|
+
``,
|
|
182
|
+
` Find files in those directories that relate to this research question:`,
|
|
183
|
+
` "${opts.question}"`,
|
|
184
|
+
``,
|
|
185
|
+
` Categorize results by purpose: implementation, tests, types, config,`,
|
|
186
|
+
` examples, docs. Return absolute paths grouped by category.`,
|
|
187
|
+
``,
|
|
188
|
+
`── STEP 2 — Analyze the most relevant files (codebase-analyzer) ──`,
|
|
189
|
+
``,
|
|
190
|
+
`Pick the 5-10 most relevant IMPLEMENTATION files from STEP 1's output and`,
|
|
191
|
+
`dispatch the codebase-analyzer:`,
|
|
192
|
+
``,
|
|
193
|
+
` @"codebase-analyzer (agent)" Document how the following files work as`,
|
|
194
|
+
` they relate to the research question "${opts.question}":`,
|
|
195
|
+
` <list the files you picked, one per line>`,
|
|
196
|
+
``,
|
|
197
|
+
` Cover control flow, data flow, key abstractions, and any external`,
|
|
198
|
+
` dependencies. Use file:line references throughout. Do NOT critique or`,
|
|
199
|
+
` suggest improvements — describe what exists.`,
|
|
200
|
+
``,
|
|
201
|
+
`── STEP 3 — Find existing patterns (codebase-pattern-finder) ──`,
|
|
202
|
+
``,
|
|
203
|
+
`Dispatch the pattern-finder, scoped to your dirs:`,
|
|
204
|
+
``,
|
|
205
|
+
` @"codebase-pattern-finder (agent)" CRITICAL: search ONLY within these`,
|
|
206
|
+
` directories: ${dirListAbs}.`,
|
|
207
|
+
``,
|
|
208
|
+
` Find existing code patterns related to "${opts.question}" inside those`,
|
|
209
|
+
` directories. Return concrete code snippets with file:line references.`,
|
|
210
|
+
``,
|
|
211
|
+
`── STEP 4 — External documentation research (CONDITIONAL) ──`,
|
|
212
|
+
``,
|
|
213
|
+
`ONLY run this step IF Step 2 surfaced external library or dependency`,
|
|
214
|
+
`usage that is CENTRAL to answering the research question. Otherwise SKIP.`,
|
|
215
|
+
``,
|
|
216
|
+
`If applicable, dispatch:`,
|
|
217
|
+
``,
|
|
218
|
+
` @"codebase-online-researcher (agent)" Research the documentation for`,
|
|
219
|
+
` <library/dependency name> as it relates to: "${opts.question}".`,
|
|
220
|
+
``,
|
|
221
|
+
` Return links and concrete findings. The agent should follow the`,
|
|
222
|
+
` token-efficient fetch order described in its instructions.`,
|
|
223
|
+
``,
|
|
224
|
+
`── STEP 5 — Synthesize and write findings ──`,
|
|
225
|
+
``,
|
|
226
|
+
`Combine the outputs from Steps 1-4 into a single markdown document and`,
|
|
227
|
+
`use the Write tool to write it to:`,
|
|
228
|
+
``,
|
|
229
|
+
` ${opts.scratchPath}`,
|
|
230
|
+
``,
|
|
231
|
+
`Use the OUTPUT_FORMAT below.`,
|
|
232
|
+
``,
|
|
233
|
+
`── STEP 6 — Brief summary ──`,
|
|
234
|
+
``,
|
|
235
|
+
`As your final response (after the Write tool call), output a 2-3 sentence`,
|
|
236
|
+
`prose summary of what you found. This is REQUIRED so the aggregator can`,
|
|
237
|
+
`index your report and the transcript is not empty.`,
|
|
238
|
+
`</RESEARCH_PROTOCOL>`,
|
|
239
|
+
``,
|
|
240
|
+
`<OUTPUT_FORMAT>`,
|
|
241
|
+
`The file at \`${opts.scratchPath}\` must be a markdown document with these`,
|
|
242
|
+
`sections, in this order. Each section should reflect what the corresponding`,
|
|
243
|
+
`sub-agent returned:`,
|
|
244
|
+
``,
|
|
245
|
+
`# Explorer ${opts.index} Findings`,
|
|
246
|
+
``,
|
|
247
|
+
`## Scope`,
|
|
248
|
+
`One-line description of which directories you covered.`,
|
|
249
|
+
``,
|
|
250
|
+
`## Overview`,
|
|
251
|
+
`1-2 paragraph synthesis of all sub-agent findings as they relate to the`,
|
|
252
|
+
`research question.`,
|
|
253
|
+
``,
|
|
254
|
+
`## Files in Scope`,
|
|
255
|
+
`From codebase-locator (Step 1). Categorized list with absolute paths.`,
|
|
256
|
+
``,
|
|
257
|
+
`## How It Works`,
|
|
258
|
+
`From codebase-analyzer (Step 2). Control flow, data flow, key abstractions,`,
|
|
259
|
+
`with file:line references throughout.`,
|
|
260
|
+
``,
|
|
261
|
+
`## Patterns`,
|
|
262
|
+
`From codebase-pattern-finder (Step 3). Concrete code examples with`,
|
|
263
|
+
`file:line refs.`,
|
|
264
|
+
``,
|
|
265
|
+
`## External References`,
|
|
266
|
+
`From codebase-online-researcher (Step 4) — INCLUDE ONLY if Step 4 ran.`,
|
|
267
|
+
`Otherwise omit this section. Include links the online researcher returned.`,
|
|
268
|
+
``,
|
|
269
|
+
`## Cross-References`,
|
|
270
|
+
`Files OUTSIDE your assigned directories that other explorers should check,`,
|
|
271
|
+
`with a 1-line note on why each is relevant.`,
|
|
272
|
+
``,
|
|
273
|
+
`## File Index`,
|
|
274
|
+
`Bulleted list of every file the sub-agents touched, each with a 1-line`,
|
|
275
|
+
`description of what's in it.`,
|
|
276
|
+
`</OUTPUT_FORMAT>`,
|
|
277
|
+
``,
|
|
278
|
+
`<CONSTRAINTS>`,
|
|
279
|
+
DOCUMENTARIAN_DISCLAIMER,
|
|
280
|
+
`Use file:line references throughout — concrete, not abstract.`,
|
|
281
|
+
`Do NOT investigate directories outside your assignment, even via sub-agents.`,
|
|
282
|
+
`Do NOT skip Steps 1-3 or 5-6. Step 4 is the only optional step.`,
|
|
283
|
+
`Do NOT use Read/Glob/Grep directly — coordinate via sub-agents only.`,
|
|
284
|
+
`End your turn with the required 2-3 sentence prose summary AFTER writing`,
|
|
285
|
+
`the file (do not end on a tool call).`,
|
|
286
|
+
`</CONSTRAINTS>`,
|
|
287
|
+
``,
|
|
288
|
+
`<RESEARCH_QUESTION_REMINDER>`,
|
|
289
|
+
opts.question,
|
|
290
|
+
`</RESEARCH_QUESTION_REMINDER>`,
|
|
291
|
+
].join("\n");
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
295
|
+
// Stage 1b — research-history (parallel sibling of codebase-scout)
|
|
296
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* The research-history scout dispatches specialized sub-agents to surface
|
|
300
|
+
* historical context from the project's `research/` directory:
|
|
301
|
+
* - codebase-research-locator → finds prior research docs about the topic
|
|
302
|
+
* - codebase-research-analyzer → extracts key insights from the most
|
|
303
|
+
* relevant docs
|
|
304
|
+
*
|
|
305
|
+
* Output is consumed via session transcript (not file write) — kept short
|
|
306
|
+
* (≤400 words) so the aggregator can embed it cheaply.
|
|
307
|
+
*/
|
|
308
|
+
export function buildHistoryPrompt(opts: {
|
|
309
|
+
question: string;
|
|
310
|
+
root: string;
|
|
311
|
+
}): string {
|
|
312
|
+
return [
|
|
313
|
+
`<RESEARCH_QUESTION>`,
|
|
314
|
+
opts.question,
|
|
315
|
+
`</RESEARCH_QUESTION>`,
|
|
316
|
+
``,
|
|
317
|
+
`<YOUR_IDENTITY>`,
|
|
318
|
+
`You are the research-history scout for the deep-research-codebase`,
|
|
319
|
+
`workflow. You run in parallel with the codebase-scout. Your job is to`,
|
|
320
|
+
`surface relevant historical context from the project's existing research`,
|
|
321
|
+
`directory using specialized sub-agents — NOT to investigate the live`,
|
|
322
|
+
`codebase (the explorers will do that).`,
|
|
323
|
+
`</YOUR_IDENTITY>`,
|
|
324
|
+
``,
|
|
325
|
+
`<RESEARCH_PROTOCOL>`,
|
|
326
|
+
`Execute these steps in order:`,
|
|
327
|
+
``,
|
|
328
|
+
`── STEP 1 — Locate prior research documents ──`,
|
|
329
|
+
``,
|
|
330
|
+
`Dispatch the research-locator sub-agent:`,
|
|
331
|
+
``,
|
|
332
|
+
` @"codebase-research-locator (agent)" Locate research documents related`,
|
|
333
|
+
` to: "${opts.question}". Search the \`${path.join(opts.root, "research")}\``,
|
|
334
|
+
` directory and any sibling research directories. Return categorized`,
|
|
335
|
+
` document paths (docs/, tickets/, notes/, etc.) with 1-line summaries.`,
|
|
336
|
+
``,
|
|
337
|
+
`If no research/ directory exists or no relevant docs are found, note`,
|
|
338
|
+
`that explicitly and SKIP STEP 2.`,
|
|
339
|
+
``,
|
|
340
|
+
`── STEP 2 — Extract insights from the most relevant documents ──`,
|
|
341
|
+
``,
|
|
342
|
+
`Pick the 3-5 MOST relevant documents from STEP 1 and dispatch the`,
|
|
343
|
+
`research-analyzer:`,
|
|
344
|
+
``,
|
|
345
|
+
` @"codebase-research-analyzer (agent)" Extract key insights from these`,
|
|
346
|
+
` documents as they relate to the research question "${opts.question}":`,
|
|
347
|
+
` <list the doc paths you picked>`,
|
|
348
|
+
``,
|
|
349
|
+
` Filter out noise. Focus on prior decisions, completed investigations,`,
|
|
350
|
+
` and unresolved questions that bear on the current research question.`,
|
|
351
|
+
``,
|
|
352
|
+
`── STEP 3 — Synthesize ──`,
|
|
353
|
+
``,
|
|
354
|
+
`Output a 200-400 word synthesis of historical context as your final`,
|
|
355
|
+
`prose response. Cover:`,
|
|
356
|
+
` - Key prior decisions on related topics`,
|
|
357
|
+
` - Past investigations and their conclusions`,
|
|
358
|
+
` - Open questions from prior research`,
|
|
359
|
+
` - Document paths the aggregator should reference (with brief notes)`,
|
|
360
|
+
``,
|
|
361
|
+
`If no relevant history exists, output a single sentence saying so.`,
|
|
362
|
+
``,
|
|
363
|
+
`Do NOT write any files — your output is consumed via session transcript.`,
|
|
364
|
+
`</RESEARCH_PROTOCOL>`,
|
|
365
|
+
``,
|
|
366
|
+
`<CONSTRAINTS>`,
|
|
367
|
+
DOCUMENTARIAN_DISCLAIMER,
|
|
368
|
+
`Stay under 400 words total in your final synthesis.`,
|
|
369
|
+
`Do NOT investigate live source files — that's the explorers' job.`,
|
|
370
|
+
`End with the prose synthesis (do not end on a tool call).`,
|
|
371
|
+
`</CONSTRAINTS>`,
|
|
372
|
+
``,
|
|
373
|
+
`<RESEARCH_QUESTION_REMINDER>`,
|
|
374
|
+
opts.question,
|
|
375
|
+
`</RESEARCH_QUESTION_REMINDER>`,
|
|
376
|
+
].join("\n");
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
380
|
+
// Generic variants (Copilot / OpenCode)
|
|
381
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
382
|
+
//
|
|
383
|
+
// The Claude variants above use `@"name (agent)"` sub-agent dispatch, which is
|
|
384
|
+
// a Claude-specific feature. Copilot and OpenCode sessions are bound to a
|
|
385
|
+
// single agent for the lifetime of the session, so replicating the specialist
|
|
386
|
+
// pattern would require spawning separate child sessions for each specialist —
|
|
387
|
+
// a linear blow-up in session count that is not worth the context-isolation
|
|
388
|
+
// benefit for a partition-scoped explorer.
|
|
389
|
+
//
|
|
390
|
+
// Instead, these generic variants guide a single default-agent session through
|
|
391
|
+
// the same conceptual steps (locate → analyze → patterns → synthesize) using
|
|
392
|
+
// its own built-in file tools. The graph topology remains identical to the
|
|
393
|
+
// Claude version: scout ∥ history → explorer-1..N → aggregator.
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
* Generic explorer prompt (Copilot / OpenCode). Drives a single default-agent
|
|
397
|
+
* session through the locate → analyze → patterns → synthesize sequence using
|
|
398
|
+
* built-in tools directly, instead of Claude's sub-agent dispatch.
|
|
399
|
+
*/
|
|
400
|
+
export function buildExplorerPromptGeneric(opts: {
|
|
401
|
+
question: string;
|
|
402
|
+
index: number;
|
|
403
|
+
total: number;
|
|
404
|
+
partition: PartitionUnit[];
|
|
405
|
+
scoutOverview: string;
|
|
406
|
+
historyOverview: string;
|
|
407
|
+
scratchPath: string;
|
|
408
|
+
root: string;
|
|
409
|
+
}): string {
|
|
410
|
+
const assignmentLines = opts.partition
|
|
411
|
+
.map((u) => {
|
|
412
|
+
const abs = path.join(opts.root, u.path);
|
|
413
|
+
return ` - \`${abs}/\` (${u.fileCount} files, ${u.loc.toLocaleString()} LOC)`;
|
|
414
|
+
})
|
|
415
|
+
.join("\n");
|
|
416
|
+
|
|
417
|
+
const dirListAbs = opts.partition
|
|
418
|
+
.map((u) => `\`${path.join(opts.root, u.path)}\``)
|
|
419
|
+
.join(", ");
|
|
420
|
+
|
|
421
|
+
const orientation = opts.scoutOverview.trim().length > 0
|
|
422
|
+
? opts.scoutOverview.trim()
|
|
423
|
+
: "(scout overview unavailable — proceed without)";
|
|
424
|
+
|
|
425
|
+
const history = opts.historyOverview.trim().length > 0
|
|
426
|
+
? opts.historyOverview.trim()
|
|
427
|
+
: "(no historical research surfaced)";
|
|
428
|
+
|
|
429
|
+
return [
|
|
430
|
+
`<RESEARCH_QUESTION>`,
|
|
431
|
+
opts.question,
|
|
432
|
+
`</RESEARCH_QUESTION>`,
|
|
433
|
+
``,
|
|
434
|
+
`<YOUR_IDENTITY>`,
|
|
435
|
+
`You are explorer ${opts.index} of ${opts.total} in a deep-research workflow.`,
|
|
436
|
+
`The codebase has been partitioned across ${opts.total} parallel explorers —`,
|
|
437
|
+
`you are responsible for ONE assigned slice. Other explorers are`,
|
|
438
|
+
`simultaneously investigating the rest. You are a documentarian, not a`,
|
|
439
|
+
`critic: record what EXISTS, do not propose improvements.`,
|
|
440
|
+
``,
|
|
441
|
+
`Your session is fresh — it was created specifically for this task. Every`,
|
|
442
|
+
`piece of context you need is in this prompt; nothing carries over from the`,
|
|
443
|
+
`scout or from other explorers. Treat this prompt as your complete briefing.`,
|
|
444
|
+
`</YOUR_IDENTITY>`,
|
|
445
|
+
``,
|
|
446
|
+
`<ARCHITECTURAL_ORIENTATION>`,
|
|
447
|
+
`The codebase scout produced this overview to help you orient:`,
|
|
448
|
+
``,
|
|
449
|
+
orientation,
|
|
450
|
+
`</ARCHITECTURAL_ORIENTATION>`,
|
|
451
|
+
``,
|
|
452
|
+
`<HISTORICAL_CONTEXT>`,
|
|
453
|
+
`Prior research surfaced by the research-history scout (supplementary —`,
|
|
454
|
+
`live findings you produce below take precedence):`,
|
|
455
|
+
``,
|
|
456
|
+
history,
|
|
457
|
+
`</HISTORICAL_CONTEXT>`,
|
|
458
|
+
``,
|
|
459
|
+
`<YOUR_ASSIGNMENT>`,
|
|
460
|
+
`Your assigned directories (DO NOT search outside these — other explorers`,
|
|
461
|
+
`cover the rest):`,
|
|
462
|
+
``,
|
|
463
|
+
assignmentLines,
|
|
464
|
+
`</YOUR_ASSIGNMENT>`,
|
|
465
|
+
``,
|
|
466
|
+
`<RESEARCH_PROTOCOL>`,
|
|
467
|
+
`Execute these steps IN ORDER using your built-in file tools (read, grep,`,
|
|
468
|
+
`glob, shell). Each step must complete before the next begins.`,
|
|
469
|
+
``,
|
|
470
|
+
`── STEP 1 — Locate relevant files ──`,
|
|
471
|
+
``,
|
|
472
|
+
`Use grep / glob to find files within ONLY these directories:`,
|
|
473
|
+
`${dirListAbs}`,
|
|
474
|
+
``,
|
|
475
|
+
`that relate to the research question. CRITICAL: restrict every search to`,
|
|
476
|
+
`the directories listed above — do not wander into the rest of the codebase.`,
|
|
477
|
+
``,
|
|
478
|
+
`Categorize what you find by purpose:`,
|
|
479
|
+
` - Implementation (core logic)`,
|
|
480
|
+
` - Tests (unit / integration / e2e)`,
|
|
481
|
+
` - Types / interfaces`,
|
|
482
|
+
` - Configuration`,
|
|
483
|
+
` - Examples / fixtures`,
|
|
484
|
+
` - Documentation`,
|
|
485
|
+
``,
|
|
486
|
+
`Record absolute paths grouped by category. Do NOT read file contents yet.`,
|
|
487
|
+
``,
|
|
488
|
+
`── STEP 2 — Analyze the most relevant implementation files ──`,
|
|
489
|
+
``,
|
|
490
|
+
`Pick the 5-10 MOST relevant implementation files from STEP 1 and read them`,
|
|
491
|
+
`in full. For each file, document:`,
|
|
492
|
+
` - Its role (what it does, why it exists)`,
|
|
493
|
+
` - Key abstractions, types, and functions with \`file.ts:line\` references`,
|
|
494
|
+
` - Control flow and data flow as they relate to the research question`,
|
|
495
|
+
` - External dependencies it uses (libraries, other modules)`,
|
|
496
|
+
``,
|
|
497
|
+
`Use file:line references throughout — never abstract descriptions.`,
|
|
498
|
+
``,
|
|
499
|
+
`── STEP 3 — Find existing patterns ──`,
|
|
500
|
+
``,
|
|
501
|
+
`Search (within your assigned directories only) for concrete code patterns`,
|
|
502
|
+
`related to the research question. Return snippets with \`file.ts:line\``,
|
|
503
|
+
`references so the aggregator can cite them directly.`,
|
|
504
|
+
``,
|
|
505
|
+
`── STEP 4 — External documentation (CONDITIONAL) ──`,
|
|
506
|
+
``,
|
|
507
|
+
`ONLY run this step IF Step 2 surfaced external library usage that is`,
|
|
508
|
+
`CENTRAL to answering the research question. Otherwise skip it entirely.`,
|
|
509
|
+
``,
|
|
510
|
+
`If applicable, use your web-fetch / web-search tools to pull focused`,
|
|
511
|
+
`documentation excerpts for the relevant library, tied back to how your`,
|
|
512
|
+
`assigned files use it. Return links and concrete findings only — no`,
|
|
513
|
+
`general tutorials.`,
|
|
514
|
+
``,
|
|
515
|
+
`── STEP 5 — Synthesize and write findings ──`,
|
|
516
|
+
``,
|
|
517
|
+
`Combine the outputs from Steps 1-4 into a single markdown document and`,
|
|
518
|
+
`write it to this path using your write / edit tool:`,
|
|
519
|
+
``,
|
|
520
|
+
` ${opts.scratchPath}`,
|
|
521
|
+
``,
|
|
522
|
+
`Use the OUTPUT_FORMAT below. This file is the ONLY way your findings`,
|
|
523
|
+
`reach the aggregator — be complete and precise.`,
|
|
524
|
+
``,
|
|
525
|
+
`── STEP 6 — Brief prose summary (REQUIRED) ──`,
|
|
526
|
+
``,
|
|
527
|
+
`AFTER writing the file, output a 2-3 sentence prose summary as your final`,
|
|
528
|
+
`textual response. This is required for two reasons:`,
|
|
529
|
+
` 1. The aggregator uses it as an index of your report`,
|
|
530
|
+
` 2. If your session ends on a tool call with no trailing prose, the`,
|
|
531
|
+
` downstream handoff will be empty and the aggregator will miss your`,
|
|
532
|
+
` contribution entirely.`,
|
|
533
|
+
`</RESEARCH_PROTOCOL>`,
|
|
534
|
+
``,
|
|
535
|
+
`<OUTPUT_FORMAT>`,
|
|
536
|
+
`The file at \`${opts.scratchPath}\` must be a markdown document with these`,
|
|
537
|
+
`sections, in this order:`,
|
|
538
|
+
``,
|
|
539
|
+
`# Explorer ${opts.index} Findings`,
|
|
540
|
+
``,
|
|
541
|
+
`## Scope`,
|
|
542
|
+
`One-line description of which directories you covered.`,
|
|
543
|
+
``,
|
|
544
|
+
`## Overview`,
|
|
545
|
+
`1-2 paragraph synthesis of your findings as they relate to the research`,
|
|
546
|
+
`question.`,
|
|
547
|
+
``,
|
|
548
|
+
`## Files in Scope`,
|
|
549
|
+
`From Step 1. Categorized list with absolute paths.`,
|
|
550
|
+
``,
|
|
551
|
+
`## How It Works`,
|
|
552
|
+
`From Step 2. Control flow, data flow, key abstractions, with \`file.ts:line\``,
|
|
553
|
+
`references throughout.`,
|
|
554
|
+
``,
|
|
555
|
+
`## Patterns`,
|
|
556
|
+
`From Step 3. Concrete code examples with \`file.ts:line\` references.`,
|
|
557
|
+
``,
|
|
558
|
+
`## External References`,
|
|
559
|
+
`From Step 4 — INCLUDE ONLY if Step 4 ran. Otherwise omit this section.`,
|
|
560
|
+
``,
|
|
561
|
+
`## Cross-References`,
|
|
562
|
+
`Files OUTSIDE your assigned directories that other explorers should check,`,
|
|
563
|
+
`with a 1-line note on why each is relevant.`,
|
|
564
|
+
``,
|
|
565
|
+
`## File Index`,
|
|
566
|
+
`Bulleted list of every file you touched, each with a 1-line description.`,
|
|
567
|
+
`</OUTPUT_FORMAT>`,
|
|
568
|
+
``,
|
|
569
|
+
`<CONSTRAINTS>`,
|
|
570
|
+
DOCUMENTARIAN_DISCLAIMER,
|
|
571
|
+
`Use file:line references throughout — concrete, not abstract.`,
|
|
572
|
+
`Do NOT investigate directories outside your assignment.`,
|
|
573
|
+
`Do NOT skip Steps 1-3 or 5-6. Step 4 is the only optional step.`,
|
|
574
|
+
`End your turn with the required 2-3 sentence prose summary AFTER writing`,
|
|
575
|
+
`the file — do NOT end on a tool call, or your findings will be lost to the`,
|
|
576
|
+
`aggregator.`,
|
|
577
|
+
`</CONSTRAINTS>`,
|
|
578
|
+
``,
|
|
579
|
+
`<RESEARCH_QUESTION_REMINDER>`,
|
|
580
|
+
opts.question,
|
|
581
|
+
`</RESEARCH_QUESTION_REMINDER>`,
|
|
582
|
+
].join("\n");
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
/**
|
|
586
|
+
* Generic research-history prompt (Copilot / OpenCode). A single default-agent
|
|
587
|
+
* session searches the project's research/ directory using its own file tools,
|
|
588
|
+
* instead of dispatching Claude's codebase-research-locator / analyzer
|
|
589
|
+
* sub-agents.
|
|
590
|
+
*/
|
|
591
|
+
export function buildHistoryPromptGeneric(opts: {
|
|
592
|
+
question: string;
|
|
593
|
+
root: string;
|
|
594
|
+
}): string {
|
|
595
|
+
const researchDir = path.join(opts.root, "research");
|
|
596
|
+
|
|
597
|
+
return [
|
|
598
|
+
`<RESEARCH_QUESTION>`,
|
|
599
|
+
opts.question,
|
|
600
|
+
`</RESEARCH_QUESTION>`,
|
|
601
|
+
``,
|
|
602
|
+
`<YOUR_IDENTITY>`,
|
|
603
|
+
`You are the research-history scout for the deep-research-codebase`,
|
|
604
|
+
`workflow. You run in parallel with the codebase-scout. Your job is to`,
|
|
605
|
+
`surface relevant historical context from the project's existing research`,
|
|
606
|
+
`directory (${researchDir}) — NOT to investigate the live codebase (the`,
|
|
607
|
+
`explorers will do that).`,
|
|
608
|
+
`</YOUR_IDENTITY>`,
|
|
609
|
+
``,
|
|
610
|
+
`<RESEARCH_PROTOCOL>`,
|
|
611
|
+
`Execute these steps in order using your built-in file tools (read, grep,`,
|
|
612
|
+
`glob, shell):`,
|
|
613
|
+
``,
|
|
614
|
+
`── STEP 1 — Locate prior research documents ──`,
|
|
615
|
+
``,
|
|
616
|
+
`Search \`${researchDir}\` (and any sibling research directories that exist)`,
|
|
617
|
+
`for documents related to the research question. Look for:`,
|
|
618
|
+
` - Research docs (research/docs/, research/*.md)`,
|
|
619
|
+
` - Decision records / ADRs`,
|
|
620
|
+
` - Tickets, notes, or RFCs about related topics`,
|
|
621
|
+
``,
|
|
622
|
+
`If no research/ directory exists at all, note that explicitly and SKIP`,
|
|
623
|
+
`to the final synthesis step with a single-sentence "no history" output.`,
|
|
624
|
+
``,
|
|
625
|
+
`── STEP 2 — Extract insights from the most relevant documents ──`,
|
|
626
|
+
``,
|
|
627
|
+
`Pick the 3-5 MOST relevant documents from STEP 1 and read them. For each,`,
|
|
628
|
+
`extract:`,
|
|
629
|
+
` - Prior decisions that bear on the current question`,
|
|
630
|
+
` - Completed investigations and their conclusions`,
|
|
631
|
+
` - Open questions or unresolved threads`,
|
|
632
|
+
``,
|
|
633
|
+
`Filter out noise — skip anything that isn't directly relevant.`,
|
|
634
|
+
``,
|
|
635
|
+
`── STEP 3 — Synthesize ──`,
|
|
636
|
+
``,
|
|
637
|
+
`Output a 200-400 word synthesis of historical context as your final`,
|
|
638
|
+
`prose response. Cover:`,
|
|
639
|
+
` - Key prior decisions on related topics`,
|
|
640
|
+
` - Past investigations and their conclusions`,
|
|
641
|
+
` - Open questions from prior research`,
|
|
642
|
+
` - Document paths the aggregator should reference (with brief notes)`,
|
|
643
|
+
``,
|
|
644
|
+
`If no relevant history exists, output a single sentence saying so.`,
|
|
645
|
+
``,
|
|
646
|
+
`Do NOT write any files — your output is consumed via session transcript.`,
|
|
647
|
+
`Your final assistant message must contain the synthesis as prose. If you`,
|
|
648
|
+
`end on a tool call with no trailing text, the aggregator will see nothing.`,
|
|
649
|
+
`</RESEARCH_PROTOCOL>`,
|
|
650
|
+
``,
|
|
651
|
+
`<CONSTRAINTS>`,
|
|
652
|
+
DOCUMENTARIAN_DISCLAIMER,
|
|
653
|
+
`Stay under 400 words total in your final synthesis.`,
|
|
654
|
+
`Do NOT investigate live source files — that's the explorers' job.`,
|
|
655
|
+
`End with the prose synthesis (do not end on a tool call).`,
|
|
656
|
+
`</CONSTRAINTS>`,
|
|
657
|
+
``,
|
|
658
|
+
`<RESEARCH_QUESTION_REMINDER>`,
|
|
659
|
+
opts.question,
|
|
660
|
+
`</RESEARCH_QUESTION_REMINDER>`,
|
|
661
|
+
].join("\n");
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
665
|
+
// Stage 3 — aggregator
|
|
666
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
667
|
+
|
|
668
|
+
export function buildAggregatorPrompt(opts: {
|
|
669
|
+
question: string;
|
|
670
|
+
totalLoc: number;
|
|
671
|
+
totalFiles: number;
|
|
672
|
+
explorerCount: number;
|
|
673
|
+
explorerFiles: { index: number; scratchPath: string; partition: PartitionUnit[] }[];
|
|
674
|
+
finalPath: string;
|
|
675
|
+
scoutOverview: string;
|
|
676
|
+
historyOverview: string;
|
|
677
|
+
}): string {
|
|
678
|
+
const explorerSummary = opts.explorerFiles
|
|
679
|
+
.map((e) => {
|
|
680
|
+
const dirs = e.partition.map((u) => `\`${u.path}/\``).join(", ");
|
|
681
|
+
return `- **Explorer ${e.index}** → \`${e.scratchPath}\`\n Covered: ${dirs}`;
|
|
682
|
+
})
|
|
683
|
+
.join("\n");
|
|
684
|
+
|
|
685
|
+
const orientation = opts.scoutOverview.trim().length > 0
|
|
686
|
+
? opts.scoutOverview.trim()
|
|
687
|
+
: "(scout overview unavailable)";
|
|
688
|
+
|
|
689
|
+
const history = opts.historyOverview.trim().length > 0
|
|
690
|
+
? opts.historyOverview.trim()
|
|
691
|
+
: "(no historical research surfaced)";
|
|
692
|
+
|
|
693
|
+
return [
|
|
694
|
+
`<RESEARCH_QUESTION>`,
|
|
695
|
+
opts.question,
|
|
696
|
+
`</RESEARCH_QUESTION>`,
|
|
697
|
+
``,
|
|
698
|
+
`<YOUR_IDENTITY>`,
|
|
699
|
+
`You are the aggregator. ${opts.explorerCount} parallel explorer sub-agents`,
|
|
700
|
+
`have completed their investigations of the codebase`,
|
|
701
|
+
`(${opts.totalLoc.toLocaleString()} LOC across ${opts.totalFiles.toLocaleString()} source files),`,
|
|
702
|
+
`and a parallel research-history scout has surveyed the project's prior`,
|
|
703
|
+
`research documents. Each explorer wrote a detailed findings file. Your`,
|
|
704
|
+
`job is to synthesize these findings — together with historical context —`,
|
|
705
|
+
`into a single comprehensive research document that answers the question.`,
|
|
706
|
+
`</YOUR_IDENTITY>`,
|
|
707
|
+
``,
|
|
708
|
+
`<ARCHITECTURAL_ORIENTATION>`,
|
|
709
|
+
orientation,
|
|
710
|
+
`</ARCHITECTURAL_ORIENTATION>`,
|
|
711
|
+
``,
|
|
712
|
+
`<HISTORICAL_CONTEXT>`,
|
|
713
|
+
`The research-history scout dispatched codebase-research-locator and`,
|
|
714
|
+
`codebase-research-analyzer over the project's research/ directory. Their`,
|
|
715
|
+
`synthesis (use as supplementary context — live findings take precedence):`,
|
|
716
|
+
``,
|
|
717
|
+
history,
|
|
718
|
+
`</HISTORICAL_CONTEXT>`,
|
|
719
|
+
``,
|
|
720
|
+
`<EXPLORER_REPORTS>`,
|
|
721
|
+
`Read each explorer's findings file in full. Each file has the same`,
|
|
722
|
+
`structure (Scope / Overview / Files in Scope / How It Works / Patterns /`,
|
|
723
|
+
`External References / Cross-References / File Index). The findings`,
|
|
724
|
+
`inside each file were produced by codebase-locator, codebase-analyzer,`,
|
|
725
|
+
`codebase-pattern-finder, and (sometimes) codebase-online-researcher`,
|
|
726
|
+
`sub-agents — they are LIVE evidence and take precedence over history.`,
|
|
727
|
+
``,
|
|
728
|
+
explorerSummary,
|
|
729
|
+
`</EXPLORER_REPORTS>`,
|
|
730
|
+
``,
|
|
731
|
+
`<TASK>`,
|
|
732
|
+
`1. Read EVERY explorer findings file in full, one at a time, using the`,
|
|
733
|
+
` Read tool with no offset or limit.`,
|
|
734
|
+
`2. Synthesize the findings into a unified research document.`,
|
|
735
|
+
`3. Cross-reference: identify connections between findings from different`,
|
|
736
|
+
` explorers, especially via the "Cross-References" sections.`,
|
|
737
|
+
`4. Integrate historical context where it adds value — but live findings`,
|
|
738
|
+
` from the explorers are the primary source of truth. If history and`,
|
|
739
|
+
` live findings disagree, trust the live findings.`,
|
|
740
|
+
`5. Resolve any remaining contradictions by re-reading the underlying`,
|
|
741
|
+
` source files directly.`,
|
|
742
|
+
`6. Write the final research document to: \`${opts.finalPath}\``,
|
|
743
|
+
`7. After writing the file, output a ≤200-word executive summary as your`,
|
|
744
|
+
` final prose response so this transcript has content.`,
|
|
745
|
+
`</TASK>`,
|
|
746
|
+
``,
|
|
747
|
+
`<OUTPUT_FORMAT>`,
|
|
748
|
+
`The file at \`${opts.finalPath}\` must follow this structure:`,
|
|
749
|
+
``,
|
|
750
|
+
"```markdown",
|
|
751
|
+
`---`,
|
|
752
|
+
`date: <today's date YYYY-MM-DD HH:MM:SS TZ — run \`date '+%Y-%m-%d %H:%M:%S %Z'\`>`,
|
|
753
|
+
`researcher: deep-research-codebase workflow`,
|
|
754
|
+
`git_commit: <run \`git rev-parse --verify HEAD\`>`,
|
|
755
|
+
`branch: <run \`git branch --show-current\`>`,
|
|
756
|
+
`repository: <repo name from \`basename \\$(git rev-parse --show-toplevel)\`>`,
|
|
757
|
+
`topic: "<the original research question>"`,
|
|
758
|
+
`tags: [research, codebase, deep-research]`,
|
|
759
|
+
`status: complete`,
|
|
760
|
+
`last_updated: <today's date YYYY-MM-DD>`,
|
|
761
|
+
`---`,
|
|
762
|
+
``,
|
|
763
|
+
`# Research: <short title>`,
|
|
764
|
+
``,
|
|
765
|
+
`## Research Question`,
|
|
766
|
+
`<verbatim original question>`,
|
|
767
|
+
``,
|
|
768
|
+
`## Executive Summary`,
|
|
769
|
+
`3-5 paragraph high-level answer with concrete evidence.`,
|
|
770
|
+
``,
|
|
771
|
+
`## Detailed Findings`,
|
|
772
|
+
``,
|
|
773
|
+
`### <Component / Area 1>`,
|
|
774
|
+
`Description with file:line references.`,
|
|
775
|
+
``,
|
|
776
|
+
`### <Component / Area 2>`,
|
|
777
|
+
`...`,
|
|
778
|
+
``,
|
|
779
|
+
`## Architecture & Patterns`,
|
|
780
|
+
`Cross-cutting patterns observed across multiple components.`,
|
|
781
|
+
``,
|
|
782
|
+
`## Code References`,
|
|
783
|
+
`- \`path/to/file.ts:123\` — what's there`,
|
|
784
|
+
``,
|
|
785
|
+
`## Historical Context (from research/)`,
|
|
786
|
+
`Relevant insights from prior research documents, with paths. Omit this`,
|
|
787
|
+
`section entirely if the research-history scout found nothing.`,
|
|
788
|
+
``,
|
|
789
|
+
`## Open Questions`,
|
|
790
|
+
`Areas needing further investigation.`,
|
|
791
|
+
``,
|
|
792
|
+
`## Methodology`,
|
|
793
|
+
`Generated by the deep-research-codebase workflow with ${opts.explorerCount} parallel`,
|
|
794
|
+
`explorers covering ${opts.totalFiles.toLocaleString()} source files`,
|
|
795
|
+
`(${opts.totalLoc.toLocaleString()} LOC). Each explorer dispatched the`,
|
|
796
|
+
`codebase-locator, codebase-analyzer, codebase-pattern-finder, and (when`,
|
|
797
|
+
`applicable) codebase-online-researcher sub-agents over its assigned`,
|
|
798
|
+
`partition. A parallel research-history scout dispatched`,
|
|
799
|
+
`codebase-research-locator and codebase-research-analyzer over the`,
|
|
800
|
+
`project's prior research documents.`,
|
|
801
|
+
"```",
|
|
802
|
+
`</OUTPUT_FORMAT>`,
|
|
803
|
+
``,
|
|
804
|
+
`<CONSTRAINTS>`,
|
|
805
|
+
DOCUMENTARIAN_DISCLAIMER,
|
|
806
|
+
`Prefer concrete file:line references over abstract descriptions.`,
|
|
807
|
+
`Do NOT skim explorer reports — read each one in full.`,
|
|
808
|
+
`If two explorers contradict each other, re-read the underlying source files.`,
|
|
809
|
+
`End with the required ≤200-word executive summary AFTER writing the file.`,
|
|
810
|
+
`</CONSTRAINTS>`,
|
|
811
|
+
``,
|
|
812
|
+
`<RESEARCH_QUESTION_REMINDER>`,
|
|
813
|
+
opts.question,
|
|
814
|
+
`</RESEARCH_QUESTION_REMINDER>`,
|
|
815
|
+
].join("\n");
|
|
816
|
+
}
|