@auto-engineer/server-implementer 0.8.14 → 0.9.1
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/CHANGELOG.md +20 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -4
- package/.turbo/turbo-format.log +0 -5
- package/.turbo/turbo-lint.log +0 -5
- package/.turbo/turbo-test.log +0 -13
- package/.turbo/turbo-type-check.log +0 -4
- package/src/agent/runAllSlices.js +0 -11
- package/src/agent/runFlows.js +0 -37
- package/src/agent/runSlice.js +0 -320
- package/src/agent/runTests.js +0 -100
- package/src/commands/implement-server.js +0 -100
- package/src/commands/implement-slice.js +0 -283
- package/src/index.js +0 -5
- package/src/prompts/systemPrompt.js +0 -43
- package/src/utils/extractCodeBlock.js +0 -6
|
@@ -1,283 +0,0 @@
|
|
|
1
|
-
import { defineCommandHandler } from '@auto-engineer/message-bus';
|
|
2
|
-
import { generateTextWithAI } from '@auto-engineer/ai-gateway';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
import { existsSync } from 'fs';
|
|
5
|
-
import { readFile, writeFile } from 'fs/promises';
|
|
6
|
-
import fg from 'fast-glob';
|
|
7
|
-
import createDebug from 'debug';
|
|
8
|
-
const debug = createDebug('server-impl:slice');
|
|
9
|
-
const debugHandler = createDebug('server-impl:slice:handler');
|
|
10
|
-
const debugProcess = createDebug('server-impl:slice:process');
|
|
11
|
-
const debugResult = createDebug('server-impl:slice:result');
|
|
12
|
-
export const commandHandler = defineCommandHandler({
|
|
13
|
-
name: 'ImplementSlice',
|
|
14
|
-
alias: 'implement:slice',
|
|
15
|
-
description: 'AI implements a specific server slice',
|
|
16
|
-
category: 'implement',
|
|
17
|
-
fields: {
|
|
18
|
-
slicePath: {
|
|
19
|
-
description: 'Path to the slice directory to implement',
|
|
20
|
-
required: true,
|
|
21
|
-
},
|
|
22
|
-
context: {
|
|
23
|
-
description: 'Context for retry attempts with previous outputs',
|
|
24
|
-
required: false,
|
|
25
|
-
},
|
|
26
|
-
},
|
|
27
|
-
examples: [
|
|
28
|
-
'$ auto implement:slice --slice-path=./server/src/domain/flows/seasonal-assistant/enters-shopping-criteria-into-assistant',
|
|
29
|
-
],
|
|
30
|
-
handle: async (command) => {
|
|
31
|
-
debug('CommandHandler executing for ImplementSlice');
|
|
32
|
-
const result = await handleImplementSliceCommand(command);
|
|
33
|
-
if (result.type === 'SliceImplemented') {
|
|
34
|
-
debug('Command handler completed: success');
|
|
35
|
-
debug('✅ Slice implementation completed successfully');
|
|
36
|
-
debug(' Slice: %s', path.basename(result.data.slicePath));
|
|
37
|
-
debug(' Files implemented: %d', result.data.filesImplemented.length);
|
|
38
|
-
} else {
|
|
39
|
-
debug('Command handler completed: failure - %s', result.data.error);
|
|
40
|
-
debug('❌ Slice implementation failed: %s', result.data.error);
|
|
41
|
-
}
|
|
42
|
-
return result;
|
|
43
|
-
},
|
|
44
|
-
});
|
|
45
|
-
// Helper function to extract code block from AI response
|
|
46
|
-
function extractCodeBlock(text) {
|
|
47
|
-
return text
|
|
48
|
-
.replace(/```(?:ts|typescript)?/g, '')
|
|
49
|
-
.replace(/```/g, '')
|
|
50
|
-
.trim();
|
|
51
|
-
}
|
|
52
|
-
// Load all TypeScript files from the slice directory
|
|
53
|
-
async function loadContextFiles(sliceDir) {
|
|
54
|
-
const files = await fg(['*.ts'], { cwd: sliceDir });
|
|
55
|
-
const context = {};
|
|
56
|
-
for (const file of files) {
|
|
57
|
-
const absPath = path.join(sliceDir, file);
|
|
58
|
-
context[file] = await readFile(absPath, 'utf-8');
|
|
59
|
-
}
|
|
60
|
-
return context;
|
|
61
|
-
}
|
|
62
|
-
// Find files that need implementation
|
|
63
|
-
function findFilesToImplement(contextFiles) {
|
|
64
|
-
return Object.entries(contextFiles).filter(
|
|
65
|
-
([, content]) => content.includes('TODO:') || content.includes('IMPLEMENTATION INSTRUCTIONS'),
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
// System prompt for AI implementation
|
|
69
|
-
const SYSTEM_PROMPT = `
|
|
70
|
-
You are a software engineer implementing missing logic in a sliced event-driven TypeScript server. Each slice contains partially scaffolded code, and your task is to complete the logic following implementation instructions embedded in each file.
|
|
71
|
-
|
|
72
|
-
Project Characteristics:
|
|
73
|
-
- Architecture: sliced event-sourced CQRS (Command, Query, Reaction slices)
|
|
74
|
-
- Language: TypeScript with type-graphql and Emmett
|
|
75
|
-
- Each slice has scaffolded files with implementation instructions clearly marked with comments (e.g., '## IMPLEMENTATION INSTRUCTIONS ##') or TODOs.
|
|
76
|
-
- Tests (e.g., *.specs.ts) must pass.
|
|
77
|
-
- Type errors are not allowed.
|
|
78
|
-
|
|
79
|
-
Your Goal:
|
|
80
|
-
- Read the implementation instructions from the provided file.
|
|
81
|
-
- Generate only the code needed to fulfill the instructions, nothing extra and provide back the whole file without the instructions.
|
|
82
|
-
- Maintain immutability and adhere to functional best practices.
|
|
83
|
-
- Use only the types and domain constructs already present in the slice.
|
|
84
|
-
- Do not remove existing imports or types that are still referenced or required in the file.
|
|
85
|
-
- Return the entire updated file, not just the modified parts and remove any TODO comments or instructions after implementing the logic
|
|
86
|
-
|
|
87
|
-
Key rules:
|
|
88
|
-
- Never modify code outside the TODO or instruction areas.
|
|
89
|
-
- Ensure the code is production-ready and type-safe.
|
|
90
|
-
- Follow the slice type conventions:
|
|
91
|
-
- **Command slice**: validate command, inspect state, emit events, never mutate state. Uses graphql mutations.
|
|
92
|
-
- **Reaction slice**: respond to events with commands.
|
|
93
|
-
- **Query slice**: maintain projections based on events, do not emit or throw. Uses graphql queries.
|
|
94
|
-
- All code must be TypeScript compliant and follow functional patterns.
|
|
95
|
-
- If a test exists, make it pass.
|
|
96
|
-
- Keep implementations minimal and idiomatic.
|
|
97
|
-
|
|
98
|
-
Avoid:
|
|
99
|
-
- Adding new dependencies.
|
|
100
|
-
- Refactoring unrelated code.
|
|
101
|
-
- Changing the structure of already scaffolded files unless instructed.
|
|
102
|
-
|
|
103
|
-
You will receive:
|
|
104
|
-
- The path of the file to implement.
|
|
105
|
-
- The current contents of the file, with instruction comments.
|
|
106
|
-
- Other relevant files from the same slice (e.g., types, test, state, etc.).
|
|
107
|
-
|
|
108
|
-
You must:
|
|
109
|
-
- Return the entire updated file (no commentary and remove all implementation instructions).
|
|
110
|
-
- Ensure the output is valid TypeScript.
|
|
111
|
-
`;
|
|
112
|
-
// Build prompt for initial implementation
|
|
113
|
-
function buildInitialPrompt(targetFile, context) {
|
|
114
|
-
return `
|
|
115
|
-
${SYSTEM_PROMPT}
|
|
116
|
-
|
|
117
|
-
---
|
|
118
|
-
📄 Target file to implement: ${targetFile}
|
|
119
|
-
|
|
120
|
-
${context[targetFile]}
|
|
121
|
-
|
|
122
|
-
---
|
|
123
|
-
🧠 Other files in the same slice:
|
|
124
|
-
${Object.entries(context)
|
|
125
|
-
.filter(([name]) => name !== targetFile)
|
|
126
|
-
.map(([name, content]) => `// File: ${name}\n${content}`)
|
|
127
|
-
.join('\n\n')}
|
|
128
|
-
|
|
129
|
-
---
|
|
130
|
-
Return only the whole updated file of ${targetFile}. Do not remove existing imports or types that are still referenced or required in the file. The file returned has to be production ready.
|
|
131
|
-
`.trim();
|
|
132
|
-
}
|
|
133
|
-
// Build prompt for retry with context
|
|
134
|
-
function buildRetryPrompt(targetFile, context, previousOutputs) {
|
|
135
|
-
return `
|
|
136
|
-
${SYSTEM_PROMPT}
|
|
137
|
-
|
|
138
|
-
---
|
|
139
|
-
The previous implementation needs adjustment based on this feedback:
|
|
140
|
-
|
|
141
|
-
${previousOutputs}
|
|
142
|
-
|
|
143
|
-
📄 File to update: ${targetFile}
|
|
144
|
-
|
|
145
|
-
${context[targetFile]}
|
|
146
|
-
|
|
147
|
-
🧠 Other files in the same slice:
|
|
148
|
-
${Object.entries(context)
|
|
149
|
-
.filter(([name]) => name !== targetFile)
|
|
150
|
-
.map(([name, content]) => `// File: ${name}\n${content}`)
|
|
151
|
-
.join('\n\n')}
|
|
152
|
-
|
|
153
|
-
---
|
|
154
|
-
Return only the corrected full contents of ${targetFile}, no commentary, no markdown.
|
|
155
|
-
`.trim();
|
|
156
|
-
}
|
|
157
|
-
// Main implementation function
|
|
158
|
-
async function implementSlice(slicePath, context) {
|
|
159
|
-
const sliceName = path.basename(slicePath);
|
|
160
|
-
debugProcess(`Implementing slice: ${sliceName}`);
|
|
161
|
-
try {
|
|
162
|
-
// Load all context files
|
|
163
|
-
const contextFiles = await loadContextFiles(slicePath);
|
|
164
|
-
const filesToImplement = findFilesToImplement(contextFiles);
|
|
165
|
-
const implementedFiles = [];
|
|
166
|
-
if (filesToImplement.length === 0) {
|
|
167
|
-
debugProcess('No files with TODO or IMPLEMENTATION INSTRUCTIONS found');
|
|
168
|
-
return { success: true, filesImplemented: [] };
|
|
169
|
-
}
|
|
170
|
-
// Implement each file that needs it
|
|
171
|
-
for (const [targetFile] of filesToImplement) {
|
|
172
|
-
debugProcess(`Implementing ${targetFile}`);
|
|
173
|
-
let prompt;
|
|
174
|
-
if (context !== undefined && context.previousOutputs !== undefined && context.previousOutputs.length > 0) {
|
|
175
|
-
// Use retry prompt if we have previous context
|
|
176
|
-
prompt = buildRetryPrompt(targetFile, contextFiles, context.previousOutputs);
|
|
177
|
-
debugProcess(`Using retry prompt for attempt #${context.attemptNumber ?? 2}`);
|
|
178
|
-
} else {
|
|
179
|
-
// Use initial prompt for first attempt
|
|
180
|
-
prompt = buildInitialPrompt(targetFile, contextFiles);
|
|
181
|
-
}
|
|
182
|
-
// Generate implementation with AI
|
|
183
|
-
const aiOutput = await generateTextWithAI(prompt);
|
|
184
|
-
const cleanedCode = extractCodeBlock(aiOutput);
|
|
185
|
-
// Write the implemented file
|
|
186
|
-
const filePath = path.join(slicePath, targetFile);
|
|
187
|
-
await writeFile(filePath, cleanedCode, 'utf-8');
|
|
188
|
-
debugProcess(`Successfully implemented ${targetFile}`);
|
|
189
|
-
implementedFiles.push(targetFile);
|
|
190
|
-
// Update context for next file
|
|
191
|
-
contextFiles[targetFile] = cleanedCode;
|
|
192
|
-
}
|
|
193
|
-
return { success: true, filesImplemented: implementedFiles };
|
|
194
|
-
} catch (error) {
|
|
195
|
-
const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
|
|
196
|
-
debugProcess(`Implementation failed: ${errorMessage}`);
|
|
197
|
-
return { success: false, filesImplemented: [], error: errorMessage };
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
function logCommandDebugInfo(command, resolvedSlicePath) {
|
|
201
|
-
const rawData = command.data;
|
|
202
|
-
const slicePath = rawData.slicePath ?? rawData.path;
|
|
203
|
-
const { context } = command.data;
|
|
204
|
-
debug('Handling ImplementSliceCommand');
|
|
205
|
-
debug(' Slice path: %s', resolvedSlicePath ?? slicePath);
|
|
206
|
-
debug(' Context provided: %s', context ? 'yes' : 'no');
|
|
207
|
-
if (context) {
|
|
208
|
-
debug(' Attempt number: %d', context.attemptNumber ?? 1);
|
|
209
|
-
}
|
|
210
|
-
debug(' Request ID: %s', command.requestId);
|
|
211
|
-
debug(' Correlation ID: %s', command.correlationId ?? 'none');
|
|
212
|
-
}
|
|
213
|
-
function createFailedEvent(command, error, resolvedSlicePath) {
|
|
214
|
-
const rawData = command.data;
|
|
215
|
-
const slicePath = resolvedSlicePath ?? rawData.slicePath ?? rawData.path;
|
|
216
|
-
return {
|
|
217
|
-
type: 'SliceImplementationFailed',
|
|
218
|
-
data: {
|
|
219
|
-
slicePath,
|
|
220
|
-
error,
|
|
221
|
-
},
|
|
222
|
-
timestamp: new Date(),
|
|
223
|
-
requestId: command.requestId,
|
|
224
|
-
correlationId: command.correlationId,
|
|
225
|
-
};
|
|
226
|
-
}
|
|
227
|
-
function createSuccessEvent(command, filesImplemented, resolvedSlicePath) {
|
|
228
|
-
const rawData = command.data;
|
|
229
|
-
const slicePath = resolvedSlicePath ?? rawData.slicePath ?? rawData.path;
|
|
230
|
-
return {
|
|
231
|
-
type: 'SliceImplemented',
|
|
232
|
-
data: {
|
|
233
|
-
slicePath,
|
|
234
|
-
filesImplemented,
|
|
235
|
-
},
|
|
236
|
-
timestamp: new Date(),
|
|
237
|
-
requestId: command.requestId,
|
|
238
|
-
correlationId: command.correlationId,
|
|
239
|
-
};
|
|
240
|
-
}
|
|
241
|
-
function logRetryContext(context) {
|
|
242
|
-
if (context !== undefined && context.previousOutputs !== undefined && context.previousOutputs.length > 0) {
|
|
243
|
-
debugProcess('Retrying with context from previous attempt #%d', context.attemptNumber ?? 1);
|
|
244
|
-
debugProcess('Previous outputs: %s', context.previousOutputs.substring(0, 500));
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
export async function handleImplementSliceCommand(command) {
|
|
248
|
-
// Handle both 'slicePath' and 'path' parameters for backward compatibility
|
|
249
|
-
const rawData = command.data;
|
|
250
|
-
const slicePath = rawData.slicePath ?? rawData.path;
|
|
251
|
-
const { context } = command.data;
|
|
252
|
-
if (slicePath === undefined || slicePath === null || slicePath === '') {
|
|
253
|
-
debugHandler('ERROR: No slice path provided. Expected slicePath or path parameter');
|
|
254
|
-
return createFailedEvent(command, 'No slice path provided. Expected slicePath parameter');
|
|
255
|
-
}
|
|
256
|
-
logCommandDebugInfo(command, slicePath);
|
|
257
|
-
try {
|
|
258
|
-
const sliceRoot = path.resolve(slicePath);
|
|
259
|
-
debugHandler('Resolved paths:');
|
|
260
|
-
debugHandler(' Slice root: %s', sliceRoot);
|
|
261
|
-
if (!existsSync(sliceRoot)) {
|
|
262
|
-
debugHandler('ERROR: Slice directory not found at %s', sliceRoot);
|
|
263
|
-
return createFailedEvent(command, `Slice directory not found at: ${sliceRoot}`, sliceRoot);
|
|
264
|
-
}
|
|
265
|
-
debugProcess('Starting slice implementation for: %s', sliceRoot);
|
|
266
|
-
logRetryContext(context);
|
|
267
|
-
const result = await implementSlice(sliceRoot, context);
|
|
268
|
-
if (!result.success) {
|
|
269
|
-
return createFailedEvent(command, result.error ?? 'Implementation failed', sliceRoot);
|
|
270
|
-
}
|
|
271
|
-
debugResult('Process succeeded');
|
|
272
|
-
debugResult('Files implemented: %d', result.filesImplemented.length);
|
|
273
|
-
debugResult('Files: %s', result.filesImplemented.join(', '));
|
|
274
|
-
debugResult('Returning success event: SliceImplemented');
|
|
275
|
-
return createSuccessEvent(command, result.filesImplemented, sliceRoot);
|
|
276
|
-
} catch (error) {
|
|
277
|
-
debug('ERROR: Exception caught: %O', error);
|
|
278
|
-
const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
|
|
279
|
-
return createFailedEvent(command, errorMessage, slicePath);
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
// Default export is the command handler
|
|
283
|
-
export default commandHandler;
|
package/src/index.js
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { commandHandler as implementServerHandler } from './commands/implement-server';
|
|
2
|
-
import { commandHandler as implementSliceHandler } from './commands/implement-slice';
|
|
3
|
-
export const COMMANDS = [implementServerHandler, implementSliceHandler];
|
|
4
|
-
export { implementServerHandler, implementSliceHandler };
|
|
5
|
-
export { handleImplementSliceCommand } from './commands/implement-slice';
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
export const SYSTEM_PROMPT = `
|
|
2
|
-
You are a software engineer implementing missing logic in a sliced event-driven TypeScript server. Each slice contains partially scaffolded code, and your task is to complete the logic following implementation instructions embedded in each file.
|
|
3
|
-
|
|
4
|
-
Project Characteristics:
|
|
5
|
-
- Architecture: sliced event-sourced CQRS (Command, Query, Reaction slices)
|
|
6
|
-
- Language: TypeScript with type-graphql and Emmett
|
|
7
|
-
- Each slice has scaffolded files with implementation instructions clearly marked with comments (e.g., '## IMPLEMENTATION INSTRUCTIONS ##') or TODOs.
|
|
8
|
-
- Tests (e.g., *.specs.ts) must pass.
|
|
9
|
-
- Type errors are not allowed.
|
|
10
|
-
|
|
11
|
-
Your Goal:
|
|
12
|
-
- Read the implementation instructions from the provided file.
|
|
13
|
-
- Generate only the code needed to fulfill the instructions, nothing extra and provide back the whole file without the instructions.
|
|
14
|
-
- Maintain immutability and adhere to functional best practices.
|
|
15
|
-
- Use only the types and domain constructs already present in the slice.
|
|
16
|
-
- Do not remove existing imports or types that are still referenced or required in the file.
|
|
17
|
-
- Return the entire updated file, not just the modified parts and remove any TODO comments or instructions after implementing the logic
|
|
18
|
-
|
|
19
|
-
Key rules:
|
|
20
|
-
- Never modify code outside the TODO or instruction areas.
|
|
21
|
-
- Ensure the code is production-ready and type-safe.
|
|
22
|
-
- Follow the slice type conventions:
|
|
23
|
-
- **Command slice**: validate command, inspect state, emit events, never mutate state. Uses graphql mutations.
|
|
24
|
-
- **Reaction slice**: respond to events with commands.
|
|
25
|
-
- **Query slice**: maintain projections based on events, do not emit or throw. Uses graphql queries.
|
|
26
|
-
- All code must be TypeScript compliant and follow functional patterns.
|
|
27
|
-
- If a test exists, make it pass.
|
|
28
|
-
- Keep implementations minimal and idiomatic.
|
|
29
|
-
|
|
30
|
-
Avoid:
|
|
31
|
-
- Adding new dependencies.
|
|
32
|
-
- Refactoring unrelated code.
|
|
33
|
-
- Changing the structure of already scaffolded files unless instructed.
|
|
34
|
-
|
|
35
|
-
You will receive:
|
|
36
|
-
- The path of the file to implement.
|
|
37
|
-
- The current contents of the file, with instruction comments.
|
|
38
|
-
- Other relevant files from the same slice (e.g., types, test, state, etc.).
|
|
39
|
-
|
|
40
|
-
You must:
|
|
41
|
-
- Return the entire updated file (no commentary and remove all implementation instructions).
|
|
42
|
-
- Ensure the output is valid TypeScript.
|
|
43
|
-
`;
|