|
1 | 1 | import { readdirSync } from 'node:fs' |
2 | 2 | import { join } from 'node:path' |
| 3 | +import { BUILD_PROMPT, EXTEND_PROMPT, SCAFFOLD_PROMPT } from './prompts.generated.js' |
| 4 | +import { renderTemplate } from './prompt-template.js' |
3 | 5 |
|
4 | 6 | /** |
5 | 7 | * The prompts a build session opens with, and the one check that decides between them. |
6 | 8 | * |
7 | | - * This was the driver-backed half of ai-autopilot's `Bootstrap` spine: injectable build / improve |
8 | | - * steps whose results were wrapped in a synthetic supervised agent so the narration could show a |
9 | | - * phase. The spine went with the review loop (A3/A5), and the session that used it is now one |
10 | | - * prompt honoring gates (D2), so what survives is the prompt text itself. |
| 9 | + * The prompt text lives in `prompts/*_prompt.md` like every other agent-facing prompt (#551/#1347); |
| 10 | + * these functions only fill the user's intent into the compiled templates. `tf.prompt` is the same |
| 11 | + * name the system prompt gives the user's prompt. |
11 | 12 | */ |
12 | 13 |
|
13 | | -/** Compose the build prompt for an intent. The stack is the agent's call (#545). */ |
| 14 | +/** The greenfield build prompt (`prompts/build_prompt.md`). The stack is the agent's call (#545). */ |
14 | 15 | export function buildPrompt(intent: string): string { |
15 | | - return [ |
16 | | - `Build this app end to end: ${intent}`, |
17 | | - 'The workspace may be empty — if so, scaffold the whole project from scratch:', |
18 | | - 'create package.json with scripts, all config, and every source file, install', |
19 | | - 'the dependencies, and make the app run.', |
20 | | - 'When done, summarize what you built in one short paragraph.', |
21 | | - ].join('\n') |
| 16 | + return renderTemplate(BUILD_PROMPT, { tf: { prompt: intent } }) |
22 | 17 | } |
23 | 18 |
|
24 | 19 | /** |
25 | | - * Framing for an agent against an *existing* codebase. The greenfield {@link buildPrompt} tells the |
26 | | - * agent the workspace may be empty and to scaffold from scratch, which is the wrong instruction |
27 | | - * when the user pointed the framework at a project that already exists (#185). |
28 | | - * |
29 | | - * Naming the workspace is the whole job. The rules that used to follow it (do not re-scaffold, |
30 | | - * read the existing code first, make the smallest coherent set of changes) were dropped in #1224: |
31 | | - * they told a capable agent how to do its work rather than what the work was, and the one thing it |
32 | | - * cannot infer, that this codebase already exists, is in the first line. Chosen when the workspace |
33 | | - * already holds source at build time. |
| 20 | + * The existing-codebase prompt (`prompts/extend_prompt.md`), chosen when the workspace already |
| 21 | + * holds source at build time (#185). |
34 | 22 | */ |
35 | 23 | export function extendPrompt(intent: string): string { |
36 | | - return [ |
37 | | - `Work within the existing codebase in this workspace to deliver: ${intent}`, |
38 | | - 'When done, summarize what you changed in one short paragraph.', |
39 | | - ].join('\n') |
| 24 | + return renderTemplate(EXTEND_PROMPT, { tf: { prompt: intent } }) |
40 | 25 | } |
41 | 26 |
|
42 | 27 | /** |
43 | | - * A hard "the app does not exist yet — create it from scratch" directive, for a build whose |
44 | | - * opening turn left the workspace empty: the agent stalled rather than scaffolding (#182). |
| 28 | + * The scaffold retry prompt (`prompts/scaffold_prompt.md`), for a build whose opening turn left |
| 29 | + * the workspace empty (#182). |
45 | 30 | */ |
46 | 31 | export function scaffoldPrompt(intent: string): string { |
47 | | - return [ |
48 | | - `The workspace is empty — no app exists here yet. You must create the entire app now from scratch: ${intent}`, |
49 | | - 'This is a from-scratch build, not an edit: do not wait for existing code, and do', |
50 | | - 'not refuse because the directory is empty — that is expected. Scaffold the full', |
51 | | - 'project (package.json with scripts, config, and every source file), install', |
52 | | - 'dependencies, and do not stop until the requested features exist and the app runs.', |
53 | | - ].join('\n') |
| 32 | + return renderTemplate(SCAFFOLD_PROMPT, { tf: { prompt: intent } }) |
54 | 33 | } |
55 | 34 |
|
56 | 35 | const IGNORED_DIRS = new Set(['node_modules', '.git', 'dist', 'build', '.next', '.turbo', '.cache', '.vite']) |
|
0 commit comments