@codemcp/workflows 4.7.0 → 4.9.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/.turbo/turbo-build.log +1 -1
- package/dist/components/beads/beads-instruction-generator.d.ts +48 -0
- package/dist/components/beads/beads-instruction-generator.d.ts.map +1 -0
- package/dist/components/beads/beads-instruction-generator.js +182 -0
- package/dist/components/beads/beads-instruction-generator.js.map +1 -0
- package/dist/components/beads/beads-plan-manager.d.ts +66 -0
- package/dist/components/beads/beads-plan-manager.d.ts.map +1 -0
- package/dist/components/beads/beads-plan-manager.js +288 -0
- package/dist/components/beads/beads-plan-manager.js.map +1 -0
- package/dist/components/beads/beads-task-backend-client.d.ts +43 -0
- package/dist/components/beads/beads-task-backend-client.d.ts.map +1 -0
- package/dist/components/beads/beads-task-backend-client.js +178 -0
- package/dist/components/beads/beads-task-backend-client.js.map +1 -0
- package/dist/components/server-components-factory.d.ts +39 -0
- package/dist/components/server-components-factory.d.ts.map +1 -0
- package/dist/components/server-components-factory.js +62 -0
- package/dist/components/server-components-factory.js.map +1 -0
- package/dist/server-config.d.ts.map +1 -1
- package/dist/server-config.js +8 -4
- package/dist/server-config.js.map +1 -1
- package/dist/server-implementation.d.ts +1 -1
- package/dist/tool-handlers/get-tool-info.d.ts.map +1 -1
- package/dist/tool-handlers/get-tool-info.js +2 -1
- package/dist/tool-handlers/get-tool-info.js.map +1 -1
- package/dist/tool-handlers/proceed-to-phase.d.ts +5 -0
- package/dist/tool-handlers/proceed-to-phase.d.ts.map +1 -1
- package/dist/tool-handlers/proceed-to-phase.js +95 -0
- package/dist/tool-handlers/proceed-to-phase.js.map +1 -1
- package/dist/tool-handlers/start-development.d.ts.map +1 -1
- package/dist/tool-handlers/start-development.js +7 -3
- package/dist/tool-handlers/start-development.js.map +1 -1
- package/dist/tool-handlers/whats-next.d.ts +0 -12
- package/dist/tool-handlers/whats-next.d.ts.map +1 -1
- package/dist/tool-handlers/whats-next.js +1 -88
- package/dist/tool-handlers/whats-next.js.map +1 -1
- package/dist/types.d.ts +7 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/version-info.d.ts +30 -0
- package/dist/version-info.d.ts.map +1 -0
- package/dist/version-info.js +178 -0
- package/dist/version-info.js.map +1 -0
- package/package.json +2 -2
- package/src/components/beads/beads-instruction-generator.ts +261 -0
- package/src/components/beads/beads-plan-manager.ts +358 -0
- package/src/components/beads/beads-task-backend-client.ts +232 -0
- package/src/components/server-components-factory.ts +86 -0
- package/src/server-config.ts +9 -4
- package/src/tool-handlers/get-tool-info.ts +2 -1
- package/src/tool-handlers/proceed-to-phase.ts +140 -0
- package/src/tool-handlers/start-development.ts +14 -3
- package/src/tool-handlers/whats-next.ts +4 -117
- package/src/types.ts +7 -4
- package/src/version-info.ts +213 -0
- package/test/e2e/component-substitution.test.ts +208 -0
- package/test/unit/beads-instruction-generator.test.ts +847 -0
- package/test/unit/beads-phase-task-id-integration.test.ts +557 -0
- package/test/unit/server-components-factory.test.ts +279 -0
- package/test/unit/setup-project-docs-handler.test.ts +3 -2
- package/test/utils/e2e-test-setup.ts +0 -1
- package/test/utils/temp-files.ts +12 -0
- package/tsconfig.build.tsbuildinfo +1 -1
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Beads Instruction Generator
|
|
3
|
+
*
|
|
4
|
+
* Beads-specific implementation of IInstructionGenerator.
|
|
5
|
+
* Generates instructions optimized for beads task management workflow.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
type IInstructionGenerator,
|
|
10
|
+
type InstructionContext,
|
|
11
|
+
type GeneratedInstructions,
|
|
12
|
+
type YamlStateMachine,
|
|
13
|
+
ProjectDocsManager,
|
|
14
|
+
TaskBackendManager,
|
|
15
|
+
type TaskBackendConfig,
|
|
16
|
+
} from '@codemcp/workflows-core';
|
|
17
|
+
import { BeadsTaskBackendClient } from './beads-task-backend-client.js';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Beads-specific instruction generator
|
|
21
|
+
*/
|
|
22
|
+
export class BeadsInstructionGenerator implements IInstructionGenerator {
|
|
23
|
+
private projectDocsManager: ProjectDocsManager;
|
|
24
|
+
|
|
25
|
+
constructor(
|
|
26
|
+
_taskBackendClient?: BeadsTaskBackendClient,
|
|
27
|
+
_taskBackendDetector: () => TaskBackendConfig = TaskBackendManager.detectTaskBackend
|
|
28
|
+
) {
|
|
29
|
+
this.projectDocsManager = new ProjectDocsManager();
|
|
30
|
+
// Task backend client and detector may be used in future enhancements
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Set the state machine definition (kept for interface compatibility)
|
|
35
|
+
*/
|
|
36
|
+
setStateMachine(_stateMachine: YamlStateMachine): void {
|
|
37
|
+
// Not needed for beads implementation but kept for interface compliance
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Generate comprehensive instructions optimized for beads workflow
|
|
43
|
+
*/
|
|
44
|
+
async generateInstructions(
|
|
45
|
+
baseInstructions: string,
|
|
46
|
+
context: InstructionContext
|
|
47
|
+
): Promise<GeneratedInstructions> {
|
|
48
|
+
// Apply variable substitution to base instructions
|
|
49
|
+
const substitutedInstructions = this.applyVariableSubstitution(
|
|
50
|
+
baseInstructions,
|
|
51
|
+
context.conversationContext.projectPath,
|
|
52
|
+
context.conversationContext.gitBranch
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
// Enhance base instructions with beads-specific guidance
|
|
56
|
+
const enhancedInstructions = await this.enhanceBeadsInstructions(
|
|
57
|
+
substitutedInstructions,
|
|
58
|
+
context
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
return {
|
|
62
|
+
instructions: enhancedInstructions,
|
|
63
|
+
planFileGuidance:
|
|
64
|
+
'Using beads CLI for task management - plan file serves as context only',
|
|
65
|
+
metadata: {
|
|
66
|
+
phase: context.phase,
|
|
67
|
+
planFilePath: context.conversationContext.planFilePath,
|
|
68
|
+
transitionReason: context.transitionReason,
|
|
69
|
+
isModeled: context.isModeled,
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Apply variable substitution to instructions
|
|
76
|
+
*/
|
|
77
|
+
private applyVariableSubstitution(
|
|
78
|
+
instructions: string,
|
|
79
|
+
projectPath: string,
|
|
80
|
+
gitBranch?: string
|
|
81
|
+
): string {
|
|
82
|
+
const substitutions = this.projectDocsManager.getVariableSubstitutions(
|
|
83
|
+
projectPath,
|
|
84
|
+
gitBranch
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
let result = instructions;
|
|
88
|
+
for (const [variable, value] of Object.entries(substitutions)) {
|
|
89
|
+
result = result.replace(
|
|
90
|
+
new RegExp(this.escapeRegExp(variable), 'g'),
|
|
91
|
+
value
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return result;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Escape special regex characters in variable names
|
|
100
|
+
*/
|
|
101
|
+
private escapeRegExp(string: string): string {
|
|
102
|
+
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Enhance instructions with beads-specific guidance
|
|
107
|
+
*/
|
|
108
|
+
private async enhanceBeadsInstructions(
|
|
109
|
+
baseInstructions: string,
|
|
110
|
+
context: InstructionContext
|
|
111
|
+
): Promise<string> {
|
|
112
|
+
const {
|
|
113
|
+
phase,
|
|
114
|
+
conversationContext,
|
|
115
|
+
transitionReason,
|
|
116
|
+
isModeled,
|
|
117
|
+
planFileExists,
|
|
118
|
+
} = context;
|
|
119
|
+
|
|
120
|
+
// Generate beads-specific task management guidance
|
|
121
|
+
const beadsTaskGuidance = await this.generateBeadsTaskGuidance(context);
|
|
122
|
+
|
|
123
|
+
// Beads-optimized instruction structure
|
|
124
|
+
const enhanced = `You are in the ${phase} phase.
|
|
125
|
+
${baseInstructions}
|
|
126
|
+
|
|
127
|
+
**Plan File Guidance:**
|
|
128
|
+
Use the plan file as memory for the current objective
|
|
129
|
+
- Update the "Key Decisions" section with important choices made
|
|
130
|
+
- Add relevant notes to help maintain context
|
|
131
|
+
- Do NOT enter tasks in the plan file, use beads CLI exclusively for task management
|
|
132
|
+
|
|
133
|
+
**🔧 BD CLI Task Management:**
|
|
134
|
+
${beadsTaskGuidance}`;
|
|
135
|
+
|
|
136
|
+
// Add project context
|
|
137
|
+
const enhancedWithContext =
|
|
138
|
+
enhanced +
|
|
139
|
+
`\n\n**Project Context:**
|
|
140
|
+
- Project: ${conversationContext.projectPath}
|
|
141
|
+
- Branch: ${conversationContext.gitBranch}
|
|
142
|
+
- Current Phase: ${phase}`;
|
|
143
|
+
|
|
144
|
+
// Add transition context if this is a modeled transition
|
|
145
|
+
let final = enhancedWithContext;
|
|
146
|
+
if (isModeled && transitionReason) {
|
|
147
|
+
final += `\n\n**Phase Context:**
|
|
148
|
+
- ${transitionReason}`;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// Add plan file creation note if needed
|
|
152
|
+
if (!planFileExists) {
|
|
153
|
+
final +=
|
|
154
|
+
'\n\n**Note**: Plan file will be created when you first update it.';
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// Add beads-specific reminders
|
|
158
|
+
final += `\n\n**Important Reminders:**
|
|
159
|
+
- Use ONLY bd CLI tool for task management - do not use your own task management tools
|
|
160
|
+
- Call whats_next() after the next user message to maintain the development workflow`;
|
|
161
|
+
|
|
162
|
+
return final;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Generate beads-specific task management guidance
|
|
167
|
+
*/
|
|
168
|
+
private async generateBeadsTaskGuidance(
|
|
169
|
+
context: InstructionContext
|
|
170
|
+
): Promise<string> {
|
|
171
|
+
const { phase } = context;
|
|
172
|
+
|
|
173
|
+
// Extract phase task ID from plan file (this would need to be implemented)
|
|
174
|
+
const phaseTaskId = await this.extractPhaseTaskId(context);
|
|
175
|
+
|
|
176
|
+
if (!phaseTaskId) {
|
|
177
|
+
return `- Use bd CLI tool exclusively
|
|
178
|
+
- **Start by listing ready tasks**: \`bd list --parent <phase-task-id> --status open\`
|
|
179
|
+
- **Create new tasks**: \`bd create 'Task title' --parent <phase-task-id> -p 2\`
|
|
180
|
+
- **Update status when working**: \`bd update <task-id> --status in_progress\`
|
|
181
|
+
- **Complete tasks**: \`bd close <task-id>\`
|
|
182
|
+
- **Focus on ready tasks first** - let beads handle dependencies
|
|
183
|
+
- Add new tasks as they are identified during your work with the user`;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return `
|
|
187
|
+
You are currently in the ${this.capitalizePhase(phase)} phase. All work items should be created as children of ${phaseTaskId}.
|
|
188
|
+
|
|
189
|
+
**Focus on ${this.capitalizePhase(phase)} Phase Tasks** (subtasks of \`${phaseTaskId}\`):
|
|
190
|
+
• \`bd list --parent ${phaseTaskId} --status open\` - List ready work items
|
|
191
|
+
• \`bd update <task-id> --status in_progress\` - Start working on a specific task
|
|
192
|
+
• \`bd close <task-id>\` - Mark task complete when finished
|
|
193
|
+
|
|
194
|
+
**Create New Tasks for Current Phase**:
|
|
195
|
+
• \`bd create 'Task description' --parent ${phaseTaskId} -p 2\` - Create work item under current phase
|
|
196
|
+
|
|
197
|
+
**Essential Commands**:
|
|
198
|
+
• \`bd list --parent ${phaseTaskId} --status open\` - List ready work items
|
|
199
|
+
• \`bd create 'Task description' --parent ${phaseTaskId} -p 2\` - Create work item
|
|
200
|
+
• \`bd update <task-id> --status in_progress\` - Start working
|
|
201
|
+
• \`bd close <task-id>\` - Complete work item
|
|
202
|
+
• \`bd show ${phaseTaskId}\` - View phase and its work items
|
|
203
|
+
|
|
204
|
+
**Immediate Action**: Run \`bd list --parent ${phaseTaskId} --status open\` to see ready tasks.`;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Extract phase task ID from plan file (simplified implementation)
|
|
209
|
+
*/
|
|
210
|
+
private async extractPhaseTaskId(
|
|
211
|
+
context: InstructionContext
|
|
212
|
+
): Promise<string | null> {
|
|
213
|
+
try {
|
|
214
|
+
const { readFile } = await import('node:fs/promises');
|
|
215
|
+
const content = await readFile(
|
|
216
|
+
context.conversationContext.planFilePath,
|
|
217
|
+
'utf-8'
|
|
218
|
+
);
|
|
219
|
+
|
|
220
|
+
const phaseName = this.capitalizePhase(context.phase);
|
|
221
|
+
const phaseHeader = `## ${phaseName}`;
|
|
222
|
+
|
|
223
|
+
// Look for the phase header followed by beads-phase-id comment
|
|
224
|
+
const phaseSection = content.split('\n');
|
|
225
|
+
let foundPhaseHeader = false;
|
|
226
|
+
|
|
227
|
+
for (const line of phaseSection) {
|
|
228
|
+
if (line.trim() === phaseHeader) {
|
|
229
|
+
foundPhaseHeader = true;
|
|
230
|
+
continue;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
if (foundPhaseHeader && line.includes('beads-phase-id:')) {
|
|
234
|
+
const match = line.match(/beads-phase-id:\s*([\w\d.-]+)/);
|
|
235
|
+
if (match) {
|
|
236
|
+
return match[1] || null;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// Stop looking if we hit the next phase header
|
|
241
|
+
if (foundPhaseHeader && line.startsWith('##') && line !== phaseHeader) {
|
|
242
|
+
break;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
return null;
|
|
247
|
+
} catch (_error) {
|
|
248
|
+
return null;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Capitalize phase name for display
|
|
254
|
+
*/
|
|
255
|
+
private capitalizePhase(phase: string): string {
|
|
256
|
+
return phase
|
|
257
|
+
.split('_')
|
|
258
|
+
.map(word => word.charAt(0).toUpperCase() + word.slice(1))
|
|
259
|
+
.join(' ');
|
|
260
|
+
}
|
|
261
|
+
}
|
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Beads Plan Manager
|
|
3
|
+
*
|
|
4
|
+
* Beads-specific implementation of IPlanManager.
|
|
5
|
+
* Manages plan files optimized for beads task management workflow.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
type IPlanManager,
|
|
10
|
+
type PlanFileInfo,
|
|
11
|
+
type YamlStateMachine,
|
|
12
|
+
type TaskBackendConfig,
|
|
13
|
+
createLogger,
|
|
14
|
+
} from '@codemcp/workflows-core';
|
|
15
|
+
import { writeFile, readFile, access } from 'node:fs/promises';
|
|
16
|
+
import { dirname } from 'node:path';
|
|
17
|
+
import { mkdir } from 'node:fs/promises';
|
|
18
|
+
|
|
19
|
+
const logger = createLogger('BeadsPlanManager');
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Beads-specific plan manager implementation
|
|
23
|
+
*/
|
|
24
|
+
export class BeadsPlanManager implements IPlanManager {
|
|
25
|
+
private stateMachine: YamlStateMachine | null = null;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Set the state machine definition for dynamic plan generation
|
|
29
|
+
*/
|
|
30
|
+
setStateMachine(stateMachine: YamlStateMachine): void {
|
|
31
|
+
this.stateMachine = stateMachine;
|
|
32
|
+
logger.debug('State machine set for beads plan manager', {
|
|
33
|
+
name: stateMachine.name,
|
|
34
|
+
phases: Object.keys(stateMachine.states),
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Set the task backend configuration
|
|
40
|
+
*/
|
|
41
|
+
setTaskBackend(taskBackend: TaskBackendConfig): void {
|
|
42
|
+
// Task backend is implicit for beads plan manager (always beads)
|
|
43
|
+
logger.debug('Task backend set for beads plan manager', {
|
|
44
|
+
backend: taskBackend.backend,
|
|
45
|
+
available: taskBackend.isAvailable,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Get plan file information
|
|
51
|
+
*/
|
|
52
|
+
async getPlanFileInfo(planFilePath: string): Promise<PlanFileInfo> {
|
|
53
|
+
try {
|
|
54
|
+
await access(planFilePath);
|
|
55
|
+
const content = await readFile(planFilePath, 'utf-8');
|
|
56
|
+
return {
|
|
57
|
+
path: planFilePath,
|
|
58
|
+
exists: true,
|
|
59
|
+
content,
|
|
60
|
+
};
|
|
61
|
+
} catch (_error) {
|
|
62
|
+
return {
|
|
63
|
+
path: planFilePath,
|
|
64
|
+
exists: false,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Create initial plan file if it doesn't exist
|
|
71
|
+
*/
|
|
72
|
+
async ensurePlanFile(
|
|
73
|
+
planFilePath: string,
|
|
74
|
+
projectPath: string,
|
|
75
|
+
gitBranch: string
|
|
76
|
+
): Promise<void> {
|
|
77
|
+
logger.debug('Ensuring beads plan file exists', {
|
|
78
|
+
planFilePath,
|
|
79
|
+
projectPath,
|
|
80
|
+
gitBranch,
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
const planInfo = await this.getPlanFileInfo(planFilePath);
|
|
84
|
+
|
|
85
|
+
if (!planInfo.exists) {
|
|
86
|
+
logger.info('Plan file not found, creating beads-optimized plan', {
|
|
87
|
+
planFilePath,
|
|
88
|
+
});
|
|
89
|
+
await this.createInitialBeadsPlanFile(
|
|
90
|
+
planFilePath,
|
|
91
|
+
projectPath,
|
|
92
|
+
gitBranch
|
|
93
|
+
);
|
|
94
|
+
logger.info('Beads plan file created successfully', { planFilePath });
|
|
95
|
+
} else {
|
|
96
|
+
logger.debug('Plan file already exists', { planFilePath });
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Create initial plan file optimized for beads workflow
|
|
102
|
+
*/
|
|
103
|
+
private async createInitialBeadsPlanFile(
|
|
104
|
+
planFilePath: string,
|
|
105
|
+
projectPath: string,
|
|
106
|
+
gitBranch: string
|
|
107
|
+
): Promise<void> {
|
|
108
|
+
logger.debug('Creating beads-optimized plan file', { planFilePath });
|
|
109
|
+
|
|
110
|
+
try {
|
|
111
|
+
// Ensure directory exists
|
|
112
|
+
await mkdir(dirname(planFilePath), { recursive: true });
|
|
113
|
+
logger.debug('Plan file directory ensured', {
|
|
114
|
+
directory: dirname(planFilePath),
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
const projectName = projectPath.split('/').pop() || 'Unknown Project';
|
|
118
|
+
const branchInfo = gitBranch !== 'no-git' ? ` (${gitBranch} branch)` : '';
|
|
119
|
+
|
|
120
|
+
const initialContent = this.generateBeadsInitialPlanContent(
|
|
121
|
+
projectName,
|
|
122
|
+
branchInfo
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
await writeFile(planFilePath, initialContent, 'utf-8');
|
|
126
|
+
logger.info('Beads plan file written successfully', {
|
|
127
|
+
planFilePath,
|
|
128
|
+
contentLength: initialContent.length,
|
|
129
|
+
projectName,
|
|
130
|
+
});
|
|
131
|
+
} catch (error) {
|
|
132
|
+
logger.error('Failed to create beads plan file', error as Error, {
|
|
133
|
+
planFilePath,
|
|
134
|
+
});
|
|
135
|
+
throw error;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Generate initial plan file content optimized for beads workflow
|
|
141
|
+
*/
|
|
142
|
+
private generateBeadsInitialPlanContent(
|
|
143
|
+
projectName: string,
|
|
144
|
+
branchInfo: string
|
|
145
|
+
): string {
|
|
146
|
+
const timestamp = new Date().toISOString().split('T')[0];
|
|
147
|
+
|
|
148
|
+
if (!this.stateMachine) {
|
|
149
|
+
throw new Error(
|
|
150
|
+
'State machine not set. This should not happen as state machine is always loaded.'
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const phases = Object.keys(this.stateMachine.states);
|
|
155
|
+
const initialPhase = this.stateMachine.initial_state;
|
|
156
|
+
|
|
157
|
+
const documentationUrl = this.generateWorkflowDocumentationUrl(
|
|
158
|
+
this.stateMachine.name
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
let content = `# Development Plan: ${projectName}${branchInfo}
|
|
162
|
+
|
|
163
|
+
*Generated on ${timestamp} by Vibe Feature MCP*
|
|
164
|
+
*Workflow: ${
|
|
165
|
+
documentationUrl
|
|
166
|
+
? '[' + this.stateMachine.name + ']' + '(' + documentationUrl + ')'
|
|
167
|
+
: this.stateMachine.name
|
|
168
|
+
}*
|
|
169
|
+
*Task Management: Beads Issue Tracker*
|
|
170
|
+
|
|
171
|
+
## Goal
|
|
172
|
+
*Define what you're building or fixing - this will be updated as requirements are gathered*
|
|
173
|
+
|
|
174
|
+
## ${this.capitalizePhase(initialPhase)}
|
|
175
|
+
<!-- beads-phase-id: TBD -->
|
|
176
|
+
### Tasks
|
|
177
|
+
|
|
178
|
+
**🔧 TASK MANAGEMENT VIA CLI TOOL bd**
|
|
179
|
+
|
|
180
|
+
Tasks are managed via bd CLI tool. Use bd commands to create and manage tasks with proper hierarchy:
|
|
181
|
+
|
|
182
|
+
- \`bd list --parent <phase-task-id> --status open\`
|
|
183
|
+
- \`bd create "Task title" --parent <phase-task-id> -p 2\`
|
|
184
|
+
- \`bd close <task-id>\`
|
|
185
|
+
|
|
186
|
+
**Never use [ ] or [x] checkboxes - use bd commands only!**
|
|
187
|
+
|
|
188
|
+
### Completed
|
|
189
|
+
- [x] Created development plan file
|
|
190
|
+
|
|
191
|
+
`;
|
|
192
|
+
|
|
193
|
+
// Generate sections for each phase with beads-specific guidance
|
|
194
|
+
for (const phase of phases) {
|
|
195
|
+
if (phase !== initialPhase) {
|
|
196
|
+
content += `## ${this.capitalizePhase(phase)}
|
|
197
|
+
<!-- beads-phase-id: TBD -->
|
|
198
|
+
### Tasks
|
|
199
|
+
|
|
200
|
+
**🔧 TASK MANAGEMENT VIA CLI TOOL bd**
|
|
201
|
+
|
|
202
|
+
Tasks are managed via bd CLI tool. Use bd commands to create and manage tasks with proper hierarchy:
|
|
203
|
+
|
|
204
|
+
- \`bd list --parent <phase-task-id> --status open\`
|
|
205
|
+
- \`bd create "Task title" --parent <phase-task-id> -p 2\`
|
|
206
|
+
- \`bd close <task-id>\`
|
|
207
|
+
|
|
208
|
+
**Never use [ ] or [x] checkboxes - use bd commands only!**
|
|
209
|
+
|
|
210
|
+
### Completed
|
|
211
|
+
*None yet*
|
|
212
|
+
|
|
213
|
+
`;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
content += `## Key Decisions
|
|
218
|
+
*Important decisions will be documented here as they are made*
|
|
219
|
+
|
|
220
|
+
## Notes
|
|
221
|
+
*Additional context and observations*
|
|
222
|
+
|
|
223
|
+
---
|
|
224
|
+
*This plan is maintained by the LLM and uses beads CLI for task management. Tool responses provide guidance on which bd commands to use for task management.*
|
|
225
|
+
`;
|
|
226
|
+
|
|
227
|
+
return content;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Update plan file with new content
|
|
232
|
+
*/
|
|
233
|
+
async updatePlanFile(planFilePath: string, content: string): Promise<void> {
|
|
234
|
+
// Ensure directory exists
|
|
235
|
+
await mkdir(dirname(planFilePath), { recursive: true });
|
|
236
|
+
|
|
237
|
+
await writeFile(planFilePath, content, 'utf-8');
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Get plan file content for LLM context
|
|
242
|
+
*/
|
|
243
|
+
async getPlanFileContent(planFilePath: string): Promise<string> {
|
|
244
|
+
const planInfo = await this.getPlanFileInfo(planFilePath);
|
|
245
|
+
|
|
246
|
+
if (!planInfo.exists) {
|
|
247
|
+
return 'Plan file does not exist yet. It will be created when the LLM updates it.';
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
return planInfo.content || '';
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Generate phase-specific plan file guidance optimized for beads
|
|
255
|
+
*/
|
|
256
|
+
generatePlanFileGuidance(phase: string): string {
|
|
257
|
+
if (!this.stateMachine) {
|
|
258
|
+
throw new Error(
|
|
259
|
+
'State machine not set. This should not happen as state machine is always loaded.'
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
const phaseDefinition = this.stateMachine.states[phase];
|
|
264
|
+
if (!phaseDefinition) {
|
|
265
|
+
logger.warn('Unknown phase for beads plan file guidance', { phase });
|
|
266
|
+
return `Update the ${this.capitalizePhase(phase)} section with current progress. Use bd CLI for all task management.`;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
const capitalizedPhase = this.capitalizePhase(phase);
|
|
270
|
+
|
|
271
|
+
return `Update the ${capitalizedPhase} section with progress. Use bd CLI exclusively for task management - never use checkboxes. Document important decisions in the Key Decisions section.`;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Delete plan file
|
|
276
|
+
*/
|
|
277
|
+
async deletePlanFile(planFilePath: string): Promise<boolean> {
|
|
278
|
+
logger.debug('Deleting beads plan file', { planFilePath });
|
|
279
|
+
|
|
280
|
+
try {
|
|
281
|
+
// Check if file exists first
|
|
282
|
+
await access(planFilePath);
|
|
283
|
+
|
|
284
|
+
// Import unlink dynamically to avoid issues
|
|
285
|
+
const { unlink } = await import('node:fs/promises');
|
|
286
|
+
await unlink(planFilePath);
|
|
287
|
+
|
|
288
|
+
logger.info('Beads plan file deleted successfully', { planFilePath });
|
|
289
|
+
return true;
|
|
290
|
+
} catch (error: unknown) {
|
|
291
|
+
if ((error as NodeJS.ErrnoException).code === 'ENOENT') {
|
|
292
|
+
logger.debug('Beads plan file does not exist, nothing to delete', {
|
|
293
|
+
planFilePath,
|
|
294
|
+
});
|
|
295
|
+
return true; // Consider it successful if file doesn't exist
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
logger.error('Failed to delete beads plan file', error as Error, {
|
|
299
|
+
planFilePath,
|
|
300
|
+
});
|
|
301
|
+
throw error;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* Ensure plan file is deleted (verify deletion)
|
|
307
|
+
*/
|
|
308
|
+
async ensurePlanFileDeleted(planFilePath: string): Promise<boolean> {
|
|
309
|
+
logger.debug('Ensuring beads plan file is deleted', { planFilePath });
|
|
310
|
+
|
|
311
|
+
try {
|
|
312
|
+
await access(planFilePath);
|
|
313
|
+
// If we reach here, file still exists
|
|
314
|
+
logger.warn('Beads plan file still exists after deletion attempt', {
|
|
315
|
+
planFilePath,
|
|
316
|
+
});
|
|
317
|
+
return false;
|
|
318
|
+
} catch (error: unknown) {
|
|
319
|
+
if ((error as NodeJS.ErrnoException).code === 'ENOENT') {
|
|
320
|
+
logger.debug('Beads plan file successfully deleted (does not exist)', {
|
|
321
|
+
planFilePath,
|
|
322
|
+
});
|
|
323
|
+
return true;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
// Some other error occurred
|
|
327
|
+
logger.error('Error checking beads plan file deletion', error as Error, {
|
|
328
|
+
planFilePath,
|
|
329
|
+
});
|
|
330
|
+
throw error;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Capitalize phase name for display
|
|
336
|
+
*/
|
|
337
|
+
private capitalizePhase(phase: string): string {
|
|
338
|
+
return phase
|
|
339
|
+
.split('_')
|
|
340
|
+
.map(word => word.charAt(0).toUpperCase() + word.slice(1))
|
|
341
|
+
.join(' ');
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Generate workflow documentation URL for predefined workflows
|
|
346
|
+
*/
|
|
347
|
+
private generateWorkflowDocumentationUrl(
|
|
348
|
+
workflowName: string
|
|
349
|
+
): string | undefined {
|
|
350
|
+
// Don't generate URL for custom workflows
|
|
351
|
+
if (workflowName === 'custom') {
|
|
352
|
+
return undefined;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
// Generate URL for predefined workflows
|
|
356
|
+
return `https://mrsimpson.github.io/responsible-vibe-mcp/workflows/${workflowName}`;
|
|
357
|
+
}
|
|
358
|
+
}
|