mirror of
https://github.com/jparkerweb/plan2code.git
synced 2026-07-21 18:33:22 -07:00
feat: add plan2code-bot with --resume capability and state cleanup
Add the autonomous workflow test runner (plan2code-bot) that uses the Claude Agent SDK to run plan2code end-to-end. Includes --resume flag to continue incomplete runs from saved state, and automatic state file cleanup on successful completion.
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { buildStepPrompt } from './step-instructions.js';
|
||||
import type { BotConfig } from '../types.js';
|
||||
|
||||
const config: BotConfig = {
|
||||
workDir: '/tmp/work',
|
||||
projectDir: '/tmp/work/my-app',
|
||||
ideaDescription: 'A todo app with drag-and-drop',
|
||||
ideaName: 'drag-todo',
|
||||
mode: 'new-project',
|
||||
};
|
||||
|
||||
describe('buildStepPrompt', () => {
|
||||
it('each step includes the autonomous preamble', () => {
|
||||
const steps = ['init', 'plan', 'document', 'implement', 'finalize'] as const;
|
||||
for (const step of steps) {
|
||||
const prompt = buildStepPrompt(step, config);
|
||||
expect(prompt).toContain('running autonomously');
|
||||
}
|
||||
});
|
||||
|
||||
it('init prompt includes /plan2code-init skill invocation', () => {
|
||||
const prompt = buildStepPrompt('init', config);
|
||||
expect(prompt).toContain('/plan2code-init');
|
||||
});
|
||||
|
||||
it('plan prompt includes /plan2code-1-plan skill invocation', () => {
|
||||
const prompt = buildStepPrompt('plan', config);
|
||||
expect(prompt).toContain('/plan2code-1-plan');
|
||||
});
|
||||
|
||||
it('document prompt includes /plan2code-2-document skill invocation', () => {
|
||||
const prompt = buildStepPrompt('document', config);
|
||||
expect(prompt).toContain('/plan2code-2-document');
|
||||
});
|
||||
|
||||
it('implement prompt includes /plan2code-3-implement skill invocation', () => {
|
||||
const prompt = buildStepPrompt('implement', config);
|
||||
expect(prompt).toContain('/plan2code-3-implement');
|
||||
});
|
||||
|
||||
it('finalize prompt includes /plan2code-4-finalize skill invocation', () => {
|
||||
const prompt = buildStepPrompt('finalize', config);
|
||||
expect(prompt).toContain('/plan2code-4-finalize');
|
||||
});
|
||||
|
||||
it('plan prompt includes project name and description', () => {
|
||||
const prompt = buildStepPrompt('plan', config);
|
||||
expect(prompt).toContain('drag-todo');
|
||||
expect(prompt).toContain('A todo app with drag-and-drop');
|
||||
});
|
||||
|
||||
it('init prompt includes project name and description', () => {
|
||||
const prompt = buildStepPrompt('init', config);
|
||||
expect(prompt).toContain('drag-todo');
|
||||
expect(prompt).toContain('A todo app with drag-and-drop');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,86 @@
|
||||
import type { BotConfig, StepName } from '../types.js';
|
||||
|
||||
const AUTONOMOUS_PREAMBLE = `You are running autonomously as part of an automated test pipeline. Do NOT pause for human input. When you encounter questions or approval gates, make reasonable decisions and proceed. If asked for confirmation, approve. If asked to choose, pick the most reasonable option. Complete the entire step without stopping.`;
|
||||
|
||||
export function buildStepPrompt(step: StepName, config: BotConfig): string {
|
||||
switch (step) {
|
||||
case 'init':
|
||||
return buildInitPrompt(config);
|
||||
case 'plan':
|
||||
return buildPlanPrompt(config);
|
||||
case 'document':
|
||||
return buildDocumentPrompt(config);
|
||||
case 'implement':
|
||||
return buildImplementPrompt(config);
|
||||
case 'finalize':
|
||||
return buildFinalizePrompt(config);
|
||||
}
|
||||
}
|
||||
|
||||
function buildInitPrompt(config: BotConfig): string {
|
||||
return `${AUTONOMOUS_PREAMBLE}
|
||||
|
||||
Run the /plan2code-init skill to generate an AGENTS.md file for this project.
|
||||
|
||||
The project idea is: ${config.ideaDescription}
|
||||
The project name is: ${config.ideaName}
|
||||
|
||||
When asked questions:
|
||||
- For the project description, use the idea above
|
||||
- Accept all defaults and approve all gates
|
||||
- Complete the init process fully`;
|
||||
}
|
||||
|
||||
function buildPlanPrompt(config: BotConfig): string {
|
||||
return `${AUTONOMOUS_PREAMBLE}
|
||||
|
||||
Run the /plan2code-1-plan skill to create a plan for this project.
|
||||
|
||||
Read the IDEA.md file first to understand the project. The project is: ${config.ideaDescription}
|
||||
|
||||
When making decisions during planning:
|
||||
- Set confidence levels reasonably high (85-95%)
|
||||
- Accept the generated tech stack without revision
|
||||
- Do not request additional reference files
|
||||
- Approve the plan when asked for sign-off
|
||||
- Keep scope small and achievable (3-4 phases max)
|
||||
- Use the project name: ${config.ideaName}`;
|
||||
}
|
||||
|
||||
function buildDocumentPrompt(config: BotConfig): string {
|
||||
return `${AUTONOMOUS_PREAMBLE}
|
||||
|
||||
Run the /plan2code-2-document skill to transform the plan into implementation specs.
|
||||
|
||||
Read the existing plan output in specs/ first to understand what was planned.
|
||||
|
||||
When making decisions:
|
||||
- Accept all generated documentation
|
||||
- Approve phase breakdowns and task lists
|
||||
- Do not request changes to the generated docs`;
|
||||
}
|
||||
|
||||
function buildImplementPrompt(config: BotConfig): string {
|
||||
return `${AUTONOMOUS_PREAMBLE}
|
||||
|
||||
Run the /plan2code-3-implement skill to implement the next available phase.
|
||||
|
||||
When making decisions:
|
||||
- Pick the first available/unchecked phase
|
||||
- Write working code that fulfills the spec tasks
|
||||
- Mark tasks as complete as you finish them
|
||||
- Approve and sign off when the phase is done
|
||||
- Skip running tests if asked (or select the simplest test option)`;
|
||||
}
|
||||
|
||||
function buildFinalizePrompt(config: BotConfig): string {
|
||||
return `${AUTONOMOUS_PREAMBLE}
|
||||
|
||||
Run the /plan2code-4-finalize skill to validate and archive the completed project.
|
||||
|
||||
When making decisions:
|
||||
- Approve all documentation updates
|
||||
- Accept the completion summary
|
||||
- If asked for a rating or feedback, give 8/10 and positive feedback
|
||||
- Complete the archival process fully`;
|
||||
}
|
||||
Reference in New Issue
Block a user