ai-sdlc 0.2.0-alpha.6 → 0.2.0-alpha.61
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 +65 -1057
- package/dist/agents/implementation.d.ts +36 -1
- package/dist/agents/implementation.d.ts.map +1 -1
- package/dist/agents/implementation.js +259 -30
- package/dist/agents/implementation.js.map +1 -1
- package/dist/agents/index.d.ts +2 -0
- package/dist/agents/index.d.ts.map +1 -1
- package/dist/agents/index.js +2 -0
- package/dist/agents/index.js.map +1 -1
- package/dist/agents/orchestrator.d.ts +61 -0
- package/dist/agents/orchestrator.d.ts.map +1 -0
- package/dist/agents/orchestrator.js +443 -0
- package/dist/agents/orchestrator.js.map +1 -0
- package/dist/agents/planning.d.ts +1 -1
- package/dist/agents/planning.d.ts.map +1 -1
- package/dist/agents/planning.js +55 -4
- package/dist/agents/planning.js.map +1 -1
- package/dist/agents/refinement.d.ts.map +1 -1
- package/dist/agents/refinement.js +22 -3
- package/dist/agents/refinement.js.map +1 -1
- package/dist/agents/research.d.ts +85 -1
- package/dist/agents/research.d.ts.map +1 -1
- package/dist/agents/research.js +506 -16
- package/dist/agents/research.js.map +1 -1
- package/dist/agents/review.d.ts +116 -2
- package/dist/agents/review.d.ts.map +1 -1
- package/dist/agents/review.js +847 -93
- package/dist/agents/review.js.map +1 -1
- package/dist/agents/rework.d.ts.map +1 -1
- package/dist/agents/rework.js +25 -4
- package/dist/agents/rework.js.map +1 -1
- package/dist/agents/single-task.d.ts +41 -0
- package/dist/agents/single-task.d.ts.map +1 -0
- package/dist/agents/single-task.js +357 -0
- package/dist/agents/single-task.js.map +1 -0
- package/dist/agents/state-assessor.d.ts +3 -3
- package/dist/agents/state-assessor.d.ts.map +1 -1
- package/dist/agents/state-assessor.js +6 -6
- package/dist/agents/state-assessor.js.map +1 -1
- package/dist/agents/test-pattern-detector.d.ts +49 -0
- package/dist/agents/test-pattern-detector.d.ts.map +1 -0
- package/dist/agents/test-pattern-detector.js +273 -0
- package/dist/agents/test-pattern-detector.js.map +1 -0
- package/dist/agents/verification.d.ts +11 -0
- package/dist/agents/verification.d.ts.map +1 -1
- package/dist/agents/verification.js +99 -12
- package/dist/agents/verification.js.map +1 -1
- package/dist/cli/batch-processor.d.ts +64 -0
- package/dist/cli/batch-processor.d.ts.map +1 -0
- package/dist/cli/batch-processor.js +85 -0
- package/dist/cli/batch-processor.js.map +1 -0
- package/dist/cli/batch-validator.d.ts +80 -0
- package/dist/cli/batch-validator.d.ts.map +1 -0
- package/dist/cli/batch-validator.js +121 -0
- package/dist/cli/batch-validator.js.map +1 -0
- package/dist/cli/commands/migrate.js +1 -1
- package/dist/cli/commands/migrate.js.map +1 -1
- package/dist/cli/commands.d.ts +67 -3
- package/dist/cli/commands.d.ts.map +1 -1
- package/dist/cli/commands.js +1765 -198
- package/dist/cli/commands.js.map +1 -1
- package/dist/cli/daemon.d.ts.map +1 -1
- package/dist/cli/daemon.js +25 -3
- package/dist/cli/daemon.js.map +1 -1
- package/dist/cli/runner.d.ts.map +1 -1
- package/dist/cli/runner.js +35 -12
- package/dist/cli/runner.js.map +1 -1
- package/dist/core/auth.d.ts +43 -0
- package/dist/core/auth.d.ts.map +1 -1
- package/dist/core/auth.js +105 -1
- package/dist/core/auth.js.map +1 -1
- package/dist/core/client.d.ts +25 -1
- package/dist/core/client.d.ts.map +1 -1
- package/dist/core/client.js +247 -7
- package/dist/core/client.js.map +1 -1
- package/dist/core/config.d.ts +32 -1
- package/dist/core/config.d.ts.map +1 -1
- package/dist/core/config.js +146 -3
- package/dist/core/config.js.map +1 -1
- package/dist/core/conflict-detector.d.ts +108 -0
- package/dist/core/conflict-detector.d.ts.map +1 -0
- package/dist/core/conflict-detector.js +413 -0
- package/dist/core/conflict-detector.js.map +1 -0
- package/dist/core/git-utils.d.ts +28 -0
- package/dist/core/git-utils.d.ts.map +1 -0
- package/dist/core/git-utils.js +146 -0
- package/dist/core/git-utils.js.map +1 -0
- package/dist/core/index.d.ts +19 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +19 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/kanban.d.ts +1 -1
- package/dist/core/kanban.d.ts.map +1 -1
- package/dist/core/kanban.js +3 -3
- package/dist/core/kanban.js.map +1 -1
- package/dist/core/llm-utils.d.ts +103 -0
- package/dist/core/llm-utils.d.ts.map +1 -0
- package/dist/core/llm-utils.js +368 -0
- package/dist/core/llm-utils.js.map +1 -0
- package/dist/core/logger.d.ts +92 -0
- package/dist/core/logger.d.ts.map +1 -0
- package/dist/core/logger.js +221 -0
- package/dist/core/logger.js.map +1 -0
- package/dist/core/process-manager.d.ts +15 -0
- package/dist/core/process-manager.d.ts.map +1 -0
- package/dist/core/process-manager.js +132 -0
- package/dist/core/process-manager.js.map +1 -0
- package/dist/core/story-logger.d.ts +102 -0
- package/dist/core/story-logger.d.ts.map +1 -0
- package/dist/core/story-logger.js +265 -0
- package/dist/core/story-logger.js.map +1 -0
- package/dist/core/story.d.ts +113 -20
- package/dist/core/story.d.ts.map +1 -1
- package/dist/core/story.js +328 -40
- package/dist/core/story.js.map +1 -1
- package/dist/core/task-parser.d.ts +59 -0
- package/dist/core/task-parser.d.ts.map +1 -0
- package/dist/core/task-parser.js +235 -0
- package/dist/core/task-parser.js.map +1 -0
- package/dist/core/task-progress.d.ts +92 -0
- package/dist/core/task-progress.d.ts.map +1 -0
- package/dist/core/task-progress.js +280 -0
- package/dist/core/task-progress.js.map +1 -0
- package/dist/core/workflow-state.d.ts +45 -6
- package/dist/core/workflow-state.d.ts.map +1 -1
- package/dist/core/workflow-state.js +201 -12
- package/dist/core/workflow-state.js.map +1 -1
- package/dist/core/worktree.d.ts +186 -0
- package/dist/core/worktree.d.ts.map +1 -0
- package/dist/core/worktree.js +554 -0
- package/dist/core/worktree.js.map +1 -0
- package/dist/index.js +146 -5
- package/dist/index.js.map +1 -1
- package/dist/services/error-classifier.d.ts +119 -0
- package/dist/services/error-classifier.d.ts.map +1 -0
- package/dist/services/error-classifier.js +182 -0
- package/dist/services/error-classifier.js.map +1 -0
- package/dist/types/index.d.ts +381 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -0
- package/dist/types/index.js.map +1 -1
- package/package.json +5 -2
- package/templates/story.md +5 -0
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import yaml from 'js-yaml';
|
|
3
|
+
import { getLogger } from './logger.js';
|
|
4
|
+
/**
|
|
5
|
+
* Try to extract JSON directly from the response
|
|
6
|
+
*/
|
|
7
|
+
function tryDirectJson(response, schema) {
|
|
8
|
+
try {
|
|
9
|
+
const trimmed = response.trim();
|
|
10
|
+
// Must start with { or [ to be valid JSON
|
|
11
|
+
if (!trimmed.startsWith('{') && !trimmed.startsWith('[')) {
|
|
12
|
+
return { success: false, error: 'Response does not start with JSON' };
|
|
13
|
+
}
|
|
14
|
+
const parsed = JSON.parse(trimmed);
|
|
15
|
+
const result = schema.safeParse(parsed);
|
|
16
|
+
if (result.success) {
|
|
17
|
+
return { success: true, data: result.data, strategy: 'direct_json' };
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
success: false,
|
|
21
|
+
error: `Schema validation failed: ${result.error.message}`,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
catch (e) {
|
|
25
|
+
return {
|
|
26
|
+
success: false,
|
|
27
|
+
error: `JSON parse error: ${e instanceof Error ? e.message : String(e)}`,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Try to extract JSON from markdown code blocks
|
|
33
|
+
* Supports ```json, ```JSON, and plain ``` blocks
|
|
34
|
+
*/
|
|
35
|
+
function tryMarkdownJsonBlock(response, schema) {
|
|
36
|
+
// Match JSON in code blocks: ```json ... ``` or ``` ... ```
|
|
37
|
+
const codeBlockRegex = /```(?:json|JSON)?\s*\n?([\s\S]*?)```/g;
|
|
38
|
+
const matches = [...response.matchAll(codeBlockRegex)];
|
|
39
|
+
for (const match of matches) {
|
|
40
|
+
const content = match[1].trim();
|
|
41
|
+
if (!content)
|
|
42
|
+
continue;
|
|
43
|
+
try {
|
|
44
|
+
const parsed = JSON.parse(content);
|
|
45
|
+
const result = schema.safeParse(parsed);
|
|
46
|
+
if (result.success) {
|
|
47
|
+
return { success: true, data: result.data, strategy: 'markdown_json_block' };
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
// Try next match
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
success: false,
|
|
57
|
+
error: 'No valid JSON found in markdown code blocks',
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Try to extract JSON by stripping leading/trailing text
|
|
62
|
+
* Finds the first { and last } to extract potential JSON
|
|
63
|
+
*/
|
|
64
|
+
function tryStrippedJson(response, schema) {
|
|
65
|
+
const firstBrace = response.indexOf('{');
|
|
66
|
+
const lastBrace = response.lastIndexOf('}');
|
|
67
|
+
if (firstBrace === -1 || lastBrace === -1 || firstBrace >= lastBrace) {
|
|
68
|
+
// Try array format
|
|
69
|
+
const firstBracket = response.indexOf('[');
|
|
70
|
+
const lastBracket = response.lastIndexOf(']');
|
|
71
|
+
if (firstBracket === -1 || lastBracket === -1 || firstBracket >= lastBracket) {
|
|
72
|
+
return { success: false, error: 'No JSON object or array found in response' };
|
|
73
|
+
}
|
|
74
|
+
try {
|
|
75
|
+
const jsonStr = response.substring(firstBracket, lastBracket + 1);
|
|
76
|
+
const parsed = JSON.parse(jsonStr);
|
|
77
|
+
const result = schema.safeParse(parsed);
|
|
78
|
+
if (result.success) {
|
|
79
|
+
return { success: true, data: result.data, strategy: 'stripped_json' };
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
success: false,
|
|
83
|
+
error: `Schema validation failed: ${result.error.message}`,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
catch (e) {
|
|
87
|
+
return {
|
|
88
|
+
success: false,
|
|
89
|
+
error: `Stripped JSON parse error: ${e instanceof Error ? e.message : String(e)}`,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
try {
|
|
94
|
+
const jsonStr = response.substring(firstBrace, lastBrace + 1);
|
|
95
|
+
const parsed = JSON.parse(jsonStr);
|
|
96
|
+
const result = schema.safeParse(parsed);
|
|
97
|
+
if (result.success) {
|
|
98
|
+
return { success: true, data: result.data, strategy: 'stripped_json' };
|
|
99
|
+
}
|
|
100
|
+
return {
|
|
101
|
+
success: false,
|
|
102
|
+
error: `Schema validation failed: ${result.error.message}`,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
catch (e) {
|
|
106
|
+
return {
|
|
107
|
+
success: false,
|
|
108
|
+
error: `Stripped JSON parse error: ${e instanceof Error ? e.message : String(e)}`,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Try to parse response as YAML
|
|
114
|
+
*/
|
|
115
|
+
function tryYamlFallback(response, schema) {
|
|
116
|
+
try {
|
|
117
|
+
// First try to extract YAML from code blocks
|
|
118
|
+
const yamlBlockRegex = /```(?:yaml|YAML|yml|YML)\s*\n?([\s\S]*?)```/g;
|
|
119
|
+
const matches = [...response.matchAll(yamlBlockRegex)];
|
|
120
|
+
for (const match of matches) {
|
|
121
|
+
const content = match[1].trim();
|
|
122
|
+
if (!content)
|
|
123
|
+
continue;
|
|
124
|
+
try {
|
|
125
|
+
const parsed = yaml.load(content);
|
|
126
|
+
const result = schema.safeParse(parsed);
|
|
127
|
+
if (result.success) {
|
|
128
|
+
return { success: true, data: result.data, strategy: 'yaml_fallback' };
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
catch {
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
// Try parsing the whole response as YAML (after stripping obvious non-YAML parts)
|
|
136
|
+
// Skip lines that look like prose (sentences without colons)
|
|
137
|
+
const lines = response.split('\n');
|
|
138
|
+
const yamlLines = [];
|
|
139
|
+
let inYamlSection = false;
|
|
140
|
+
for (const line of lines) {
|
|
141
|
+
const trimmed = line.trim();
|
|
142
|
+
// Start of YAML-like content
|
|
143
|
+
if (trimmed.includes(':') || trimmed.startsWith('-') || inYamlSection) {
|
|
144
|
+
yamlLines.push(line);
|
|
145
|
+
inYamlSection = true;
|
|
146
|
+
}
|
|
147
|
+
// Empty line might end YAML section if we haven't found valid content
|
|
148
|
+
if (trimmed === '' && yamlLines.length > 0) {
|
|
149
|
+
inYamlSection = false;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
if (yamlLines.length > 0) {
|
|
153
|
+
const yamlContent = yamlLines.join('\n');
|
|
154
|
+
const parsed = yaml.load(yamlContent);
|
|
155
|
+
const result = schema.safeParse(parsed);
|
|
156
|
+
if (result.success) {
|
|
157
|
+
return { success: true, data: result.data, strategy: 'yaml_fallback' };
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return { success: false, error: 'No valid YAML found in response' };
|
|
161
|
+
}
|
|
162
|
+
catch (e) {
|
|
163
|
+
return {
|
|
164
|
+
success: false,
|
|
165
|
+
error: `YAML parse error: ${e instanceof Error ? e.message : String(e)}`,
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Generate a clarification prompt for retry attempts
|
|
171
|
+
*/
|
|
172
|
+
function generateClarificationPrompt(schema, attemptNumber, lastError) {
|
|
173
|
+
// Get schema shape for the prompt
|
|
174
|
+
let schemaDescription = 'the expected JSON structure';
|
|
175
|
+
try {
|
|
176
|
+
if (schema instanceof z.ZodObject) {
|
|
177
|
+
const shape = schema.shape;
|
|
178
|
+
const fields = Object.keys(shape).join(', ');
|
|
179
|
+
schemaDescription = `an object with fields: ${fields}`;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
catch {
|
|
183
|
+
// Fall back to generic description
|
|
184
|
+
}
|
|
185
|
+
return `Your previous response could not be parsed. Attempt ${attemptNumber} failed with: ${lastError}
|
|
186
|
+
|
|
187
|
+
Please respond with ONLY valid JSON matching ${schemaDescription}.
|
|
188
|
+
|
|
189
|
+
Rules:
|
|
190
|
+
1. Start your response directly with { or [
|
|
191
|
+
2. Do not include any text before or after the JSON
|
|
192
|
+
3. Ensure all strings are properly escaped
|
|
193
|
+
4. Ensure all required fields are present
|
|
194
|
+
|
|
195
|
+
Try again:`;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Extract structured response from LLM output using multiple strategies
|
|
199
|
+
*
|
|
200
|
+
* Tries extraction strategies in order:
|
|
201
|
+
* 1. Direct JSON parse (response is pure JSON)
|
|
202
|
+
* 2. JSON within markdown code blocks (\`\`\`json ... \`\`\`)
|
|
203
|
+
* 3. JSON with leading/trailing text stripped
|
|
204
|
+
* 4. YAML format fallback
|
|
205
|
+
*
|
|
206
|
+
* If all strategies fail and retries are configured, prompts the LLM
|
|
207
|
+
* to try again with clearer instructions.
|
|
208
|
+
*
|
|
209
|
+
* @param response - Raw LLM response string
|
|
210
|
+
* @param schema - Zod schema to validate against
|
|
211
|
+
* @param options - Extraction options including retry configuration
|
|
212
|
+
* @returns ExtractionResult with success status, data, and metadata
|
|
213
|
+
*
|
|
214
|
+
* @example
|
|
215
|
+
* ```typescript
|
|
216
|
+
* const ReviewSchema = z.object({
|
|
217
|
+
* passed: z.boolean(),
|
|
218
|
+
* issues: z.array(z.object({
|
|
219
|
+
* severity: z.enum(['blocker', 'critical', 'major', 'minor']),
|
|
220
|
+
* description: z.string(),
|
|
221
|
+
* })),
|
|
222
|
+
* });
|
|
223
|
+
*
|
|
224
|
+
* const result = await extractStructuredResponse(llmResponse, ReviewSchema, {
|
|
225
|
+
* maxRetries: 2,
|
|
226
|
+
* retryFn: async (prompt) => await callLLM(prompt),
|
|
227
|
+
* });
|
|
228
|
+
*
|
|
229
|
+
* if (result.success) {
|
|
230
|
+
* console.log('Parsed review:', result.data);
|
|
231
|
+
* } else {
|
|
232
|
+
* console.error('Failed to parse:', result.error);
|
|
233
|
+
* }
|
|
234
|
+
* ```
|
|
235
|
+
*/
|
|
236
|
+
export async function extractStructuredResponse(response, schema, options = {}) {
|
|
237
|
+
const { maxRetries = 0, retryFn, logOnFailure = true } = options;
|
|
238
|
+
const logger = getLogger();
|
|
239
|
+
// Store all errors for debugging
|
|
240
|
+
const errors = [];
|
|
241
|
+
// Strategy 1: Direct JSON
|
|
242
|
+
const directResult = tryDirectJson(response, schema);
|
|
243
|
+
if (directResult.success) {
|
|
244
|
+
return directResult;
|
|
245
|
+
}
|
|
246
|
+
errors.push(`direct_json: ${directResult.error}`);
|
|
247
|
+
// Strategy 2: Markdown JSON block
|
|
248
|
+
const markdownResult = tryMarkdownJsonBlock(response, schema);
|
|
249
|
+
if (markdownResult.success) {
|
|
250
|
+
return markdownResult;
|
|
251
|
+
}
|
|
252
|
+
errors.push(`markdown_json_block: ${markdownResult.error}`);
|
|
253
|
+
// Strategy 3: Stripped JSON
|
|
254
|
+
const strippedResult = tryStrippedJson(response, schema);
|
|
255
|
+
if (strippedResult.success) {
|
|
256
|
+
return strippedResult;
|
|
257
|
+
}
|
|
258
|
+
errors.push(`stripped_json: ${strippedResult.error}`);
|
|
259
|
+
// Strategy 4: YAML fallback
|
|
260
|
+
const yamlResult = tryYamlFallback(response, schema);
|
|
261
|
+
if (yamlResult.success) {
|
|
262
|
+
return yamlResult;
|
|
263
|
+
}
|
|
264
|
+
errors.push(`yaml_fallback: ${yamlResult.error}`);
|
|
265
|
+
// All strategies failed - try retries if configured
|
|
266
|
+
if (maxRetries > 0 && retryFn) {
|
|
267
|
+
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
|
268
|
+
logger.info('llm-utils', `Retry attempt ${attempt}/${maxRetries} for structured response extraction`);
|
|
269
|
+
const clarificationPrompt = generateClarificationPrompt(schema, attempt, errors[errors.length - 1]);
|
|
270
|
+
try {
|
|
271
|
+
const retryResponse = await retryFn(clarificationPrompt);
|
|
272
|
+
// Try all strategies again on retry response
|
|
273
|
+
const retryDirectResult = tryDirectJson(retryResponse, schema);
|
|
274
|
+
if (retryDirectResult.success) {
|
|
275
|
+
return retryDirectResult;
|
|
276
|
+
}
|
|
277
|
+
const retryMarkdownResult = tryMarkdownJsonBlock(retryResponse, schema);
|
|
278
|
+
if (retryMarkdownResult.success) {
|
|
279
|
+
return retryMarkdownResult;
|
|
280
|
+
}
|
|
281
|
+
const retryStrippedResult = tryStrippedJson(retryResponse, schema);
|
|
282
|
+
if (retryStrippedResult.success) {
|
|
283
|
+
return retryStrippedResult;
|
|
284
|
+
}
|
|
285
|
+
const retryYamlResult = tryYamlFallback(retryResponse, schema);
|
|
286
|
+
if (retryYamlResult.success) {
|
|
287
|
+
return retryYamlResult;
|
|
288
|
+
}
|
|
289
|
+
errors.push(`retry_${attempt}: All strategies failed`);
|
|
290
|
+
}
|
|
291
|
+
catch (e) {
|
|
292
|
+
errors.push(`retry_${attempt}: ${e instanceof Error ? e.message : String(e)}`);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
// All attempts failed
|
|
297
|
+
const finalError = `All extraction strategies failed:\n${errors.join('\n')}`;
|
|
298
|
+
if (logOnFailure) {
|
|
299
|
+
logger.error('llm-utils', 'Failed to extract structured response', {
|
|
300
|
+
errors,
|
|
301
|
+
responsePreview: response.substring(0, 500),
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
return {
|
|
305
|
+
success: false,
|
|
306
|
+
error: finalError,
|
|
307
|
+
rawResponse: response,
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Synchronous version of extractStructuredResponse without retry support
|
|
312
|
+
*
|
|
313
|
+
* Useful when you don't need retry functionality or are in a synchronous context.
|
|
314
|
+
*
|
|
315
|
+
* @param response - Raw LLM response string
|
|
316
|
+
* @param schema - Zod schema to validate against
|
|
317
|
+
* @param logOnFailure - Whether to log the raw response on failure (default: true)
|
|
318
|
+
* @returns ExtractionResult with success status, data, and metadata
|
|
319
|
+
*/
|
|
320
|
+
export function extractStructuredResponseSync(response, schema, logOnFailure = true) {
|
|
321
|
+
const logger = getLogger();
|
|
322
|
+
const errors = [];
|
|
323
|
+
// Strategy 1: Direct JSON
|
|
324
|
+
const directResult = tryDirectJson(response, schema);
|
|
325
|
+
if (directResult.success) {
|
|
326
|
+
return directResult;
|
|
327
|
+
}
|
|
328
|
+
errors.push(`direct_json: ${directResult.error}`);
|
|
329
|
+
// Strategy 2: Markdown JSON block
|
|
330
|
+
const markdownResult = tryMarkdownJsonBlock(response, schema);
|
|
331
|
+
if (markdownResult.success) {
|
|
332
|
+
return markdownResult;
|
|
333
|
+
}
|
|
334
|
+
errors.push(`markdown_json_block: ${markdownResult.error}`);
|
|
335
|
+
// Strategy 3: Stripped JSON
|
|
336
|
+
const strippedResult = tryStrippedJson(response, schema);
|
|
337
|
+
if (strippedResult.success) {
|
|
338
|
+
return strippedResult;
|
|
339
|
+
}
|
|
340
|
+
errors.push(`stripped_json: ${strippedResult.error}`);
|
|
341
|
+
// Strategy 4: YAML fallback
|
|
342
|
+
const yamlResult = tryYamlFallback(response, schema);
|
|
343
|
+
if (yamlResult.success) {
|
|
344
|
+
return yamlResult;
|
|
345
|
+
}
|
|
346
|
+
errors.push(`yaml_fallback: ${yamlResult.error}`);
|
|
347
|
+
// All attempts failed
|
|
348
|
+
const finalError = `All extraction strategies failed:\n${errors.join('\n')}`;
|
|
349
|
+
if (logOnFailure) {
|
|
350
|
+
logger.error('llm-utils', 'Failed to extract structured response', {
|
|
351
|
+
errors,
|
|
352
|
+
responsePreview: response.substring(0, 500),
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
return {
|
|
356
|
+
success: false,
|
|
357
|
+
error: finalError,
|
|
358
|
+
rawResponse: response,
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
// Export individual strategies for testing
|
|
362
|
+
export const extractionStrategies = {
|
|
363
|
+
tryDirectJson,
|
|
364
|
+
tryMarkdownJsonBlock,
|
|
365
|
+
tryStrippedJson,
|
|
366
|
+
tryYamlFallback,
|
|
367
|
+
};
|
|
368
|
+
//# sourceMappingURL=llm-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"llm-utils.js","sourceRoot":"","sources":["../../src/core/llm-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAa,MAAM,KAAK,CAAC;AACnC,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAkCxC;;GAEG;AACH,SAAS,aAAa,CACpB,QAAgB,EAChB,MAAoB;IAEpB,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,QAAQ,CAAC,IAAI,EAAE,CAAC;QAChC,0CAA0C;QAC1C,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;YACzD,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,mCAAmC,EAAE,CAAC;QACxE,CAAC;QAED,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACnC,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QAExC,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;YACnB,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,QAAQ,EAAE,aAAa,EAAE,CAAC;QACvE,CAAC;QAED,OAAO;YACL,OAAO,EAAE,KAAK;YACd,KAAK,EAAE,6BAA6B,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE;SAC3D,CAAC;IACJ,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,OA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AU,GAAG,eAAe,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IACrD,IAAI,UAAU,CAAC,OAAO,EAAE,CAAC;QACvB,OAAO,UAAU,CAAC;IACpB,CAAC;IACD,MAAM,CAAC,IAAI,CAAC,kBAAkB,UAAU,CAAC,KAAK,EAAE,CAAC,CAAC;IAElD,sBAAsB;IACtB,MAAM,UAAU,GAAG,sCAAsC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;IAE7E,IAAI,YAAY,EAAE,CAAC;QACjB,MAAM,CAAC,KAAK,CAAC,WAAW,EAAE,uCAAuC,EAAE;YACjE,MAAM;YACN,eAAe,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC;SAC5C,CAAC,CAAC;IACL,CAAC;IAED,OAAO;QACL,OAAO,EAAE,KAAK;QACd,KAAK,EAAE,UAAU;QACjB,WAAW,EAAE,QAAQ;KACtB,CAAC;AACJ,CAAC;AAED,2CAA2C;AAC3C,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,aAAa;IACb,oBAAoB;IACpB,eAAe;IACf,eAAe;CAChB,CAAC"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { LogConfig } from '../types/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Log entry structure for JSON Lines format
|
|
4
|
+
*/
|
|
5
|
+
export interface LogEntry {
|
|
6
|
+
timestamp: string;
|
|
7
|
+
level: 'debug' | 'info' | 'warn' | 'error';
|
|
8
|
+
category: string;
|
|
9
|
+
message: string;
|
|
10
|
+
data?: unknown;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Rolling file logger for ai-sdlc operations
|
|
14
|
+
*
|
|
15
|
+
* Features:
|
|
16
|
+
* - JSON Lines format (one JSON object per line)
|
|
17
|
+
* - Rolling by size (configurable, default 10MB)
|
|
18
|
+
* - Retains last N files (configurable, default 5)
|
|
19
|
+
* - Location: .ai-sdlc/logs/ai-sdlc-YYYY-MM-DD.log
|
|
20
|
+
*/
|
|
21
|
+
export declare class Logger {
|
|
22
|
+
private projectRoot;
|
|
23
|
+
private config;
|
|
24
|
+
private logDir;
|
|
25
|
+
private currentLogFile;
|
|
26
|
+
constructor(projectRoot: string, config: LogConfig);
|
|
27
|
+
/**
|
|
28
|
+
* Ensure the log directory exists
|
|
29
|
+
*/
|
|
30
|
+
private ensureLogDirectory;
|
|
31
|
+
/**
|
|
32
|
+
* Get the current log file path based on today's date
|
|
33
|
+
*/
|
|
34
|
+
private getCurrentLogFile;
|
|
35
|
+
/**
|
|
36
|
+
* Check if the current log file needs rotation based on size
|
|
37
|
+
*/
|
|
38
|
+
private needsRotation;
|
|
39
|
+
/**
|
|
40
|
+
* Rotate the log file by renaming it with a sequence number
|
|
41
|
+
*/
|
|
42
|
+
private rotateLogFile;
|
|
43
|
+
/**
|
|
44
|
+
* Remove old log files beyond the retention limit
|
|
45
|
+
*/
|
|
46
|
+
private cleanupOldFiles;
|
|
47
|
+
/**
|
|
48
|
+
* Check if the given level should be logged based on config
|
|
49
|
+
*/
|
|
50
|
+
private shouldLog;
|
|
51
|
+
/**
|
|
52
|
+
* Write a log entry to the current log file
|
|
53
|
+
*/
|
|
54
|
+
private write;
|
|
55
|
+
/**
|
|
56
|
+
* Create a log entry with common fields
|
|
57
|
+
*/
|
|
58
|
+
private createEntry;
|
|
59
|
+
/**
|
|
60
|
+
* Log a debug message
|
|
61
|
+
*/
|
|
62
|
+
debug(category: string, message: string, data?: unknown): void;
|
|
63
|
+
/**
|
|
64
|
+
* Log an info message
|
|
65
|
+
*/
|
|
66
|
+
info(category: string, message: string, data?: unknown): void;
|
|
67
|
+
/**
|
|
68
|
+
* Log a warning message
|
|
69
|
+
*/
|
|
70
|
+
warn(category: string, message: string, data?: unknown): void;
|
|
71
|
+
/**
|
|
72
|
+
* Log an error message
|
|
73
|
+
*/
|
|
74
|
+
error(category: string, message: string, data?: unknown): void;
|
|
75
|
+
/**
|
|
76
|
+
* Get the path to the current log file
|
|
77
|
+
*/
|
|
78
|
+
getLogFilePath(): string;
|
|
79
|
+
/**
|
|
80
|
+
* Get all log file paths
|
|
81
|
+
*/
|
|
82
|
+
getLogFiles(): string[];
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Initialize the global logger instance
|
|
86
|
+
*/
|
|
87
|
+
export declare function initLogger(projectRoot: string, config: LogConfig): Logger;
|
|
88
|
+
/**
|
|
89
|
+
* Get the global logger instance (or create a disabled one if not initialized)
|
|
90
|
+
*/
|
|
91
|
+
export declare function getLogger(): Logger;
|
|
92
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/core/logger.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAE9C;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;IAC3C,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAYD;;;;;;;;GAQG;AACH,qBAAa,MAAM;IACjB,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,MAAM,CAAY;IAC1B,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,cAAc,CAAuB;gBAEjC,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS;IAUlD;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAM1B;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAKzB;;OAEG;IACH,OAAO,CAAC,aAAa;IAUrB;;OAEG;IACH,OAAO,CAAC,aAAa;IAiBrB;;OAEG;IACH,OAAO,CAAC,eAAe;IAyBvB;;OAEG;IACH,OAAO,CAAC,SAAS;IAOjB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