refactor: integrate simple query service into auto mode

- Replaced dynamic import of the query function with a call to the new Simple Query Service for improved clarity and maintainability.
- Streamlined the response handling by directly utilizing the result from the simple query, enhancing code readability.
- Updated the prompt and options structure to align with the new service's requirements, ensuring consistent behavior in learning extraction.
This commit is contained in:
webdevcody
2026-01-12 21:39:39 -05:00
parent c796adbae8
commit 2b33a0d322

View File

@@ -10,6 +10,7 @@
*/ */
import { ProviderFactory } from '../providers/provider-factory.js'; import { ProviderFactory } from '../providers/provider-factory.js';
import { simpleQuery } from '../providers/simple-query-service.js';
import type { import type {
ExecuteOptions, ExecuteOptions,
Feature, Feature,
@@ -3193,40 +3194,23 @@ IMPORTANT: Only include NON-OBVIOUS learnings with real reasoning. Skip trivial
If nothing notable: {"learnings": []}`; If nothing notable: {"learnings": []}`;
try { try {
// Import query dynamically to avoid circular dependencies
const { query } = await import('@anthropic-ai/claude-agent-sdk');
// Get model from phase settings // Get model from phase settings
const settings = await this.settingsService?.getGlobalSettings(); const settings = await this.settingsService?.getGlobalSettings();
const phaseModelEntry = const phaseModelEntry =
settings?.phaseModels?.memoryExtractionModel || DEFAULT_PHASE_MODELS.memoryExtractionModel; settings?.phaseModels?.memoryExtractionModel || DEFAULT_PHASE_MODELS.memoryExtractionModel;
const { model } = resolvePhaseModel(phaseModelEntry); const { model } = resolvePhaseModel(phaseModelEntry);
const stream = query({ const result = await simpleQuery({
prompt: userPrompt, prompt: userPrompt,
options: { model,
model, cwd: projectPath,
maxTurns: 1, maxTurns: 1,
allowedTools: [], allowedTools: [],
permissionMode: 'acceptEdits', systemPrompt:
systemPrompt: 'You are a JSON extraction assistant. You MUST respond with ONLY valid JSON, no explanations, no markdown, no other text. Extract learnings from the provided implementation context and return them as JSON.',
'You are a JSON extraction assistant. You MUST respond with ONLY valid JSON, no explanations, no markdown, no other text. Extract learnings from the provided implementation context and return them as JSON.',
},
}); });
// Extract text from stream const responseText = result.text;
let responseText = '';
for await (const msg of stream) {
if (msg.type === 'assistant' && msg.message?.content) {
for (const block of msg.message.content) {
if (block.type === 'text' && block.text) {
responseText += block.text;
}
}
} else if (msg.type === 'result' && msg.subtype === 'success') {
responseText = msg.result || responseText;
}
}
console.log(`[AutoMode] Learning extraction response: ${responseText.length} chars`); console.log(`[AutoMode] Learning extraction response: ${responseText.length} chars`);
console.log(`[AutoMode] Response preview: ${responseText.substring(0, 300)}`); console.log(`[AutoMode] Response preview: ${responseText.substring(0, 300)}`);