@posthog/agent 1.18.0 → 1.20.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/dist/claude-cli/cli.js +2973 -2492
- package/dist/claude-cli/yoga.wasm +0 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/src/adapters/claude/claude-adapter.d.ts +3 -2
- package/dist/src/adapters/claude/claude-adapter.d.ts.map +1 -1
- package/dist/src/adapters/claude/claude-adapter.js +8 -0
- package/dist/src/adapters/claude/claude-adapter.js.map +1 -1
- package/dist/src/adapters/types.d.ts +6 -1
- package/dist/src/adapters/types.d.ts.map +1 -1
- package/dist/src/agents/research.d.ts +1 -1
- package/dist/src/agents/research.d.ts.map +1 -1
- package/dist/src/agents/research.js +55 -5
- package/dist/src/agents/research.js.map +1 -1
- package/dist/src/file-manager.d.ts +2 -0
- package/dist/src/file-manager.d.ts.map +1 -1
- package/dist/src/file-manager.js +27 -0
- package/dist/src/file-manager.js.map +1 -1
- package/dist/src/prompt-builder.d.ts.map +1 -1
- package/dist/src/prompt-builder.js +25 -0
- package/dist/src/prompt-builder.js.map +1 -1
- package/dist/src/todo-manager.d.ts +29 -0
- package/dist/src/todo-manager.d.ts.map +1 -0
- package/dist/src/todo-manager.js +126 -0
- package/dist/src/todo-manager.js.map +1 -0
- package/dist/src/workflow/steps/build.d.ts.map +1 -1
- package/dist/src/workflow/steps/build.js +7 -0
- package/dist/src/workflow/steps/build.js.map +1 -1
- package/dist/src/workflow/steps/plan.d.ts.map +1 -1
- package/dist/src/workflow/steps/plan.js +10 -3
- package/dist/src/workflow/steps/plan.js.map +1 -1
- package/package.json +4 -3
- package/src/adapters/claude/claude-adapter.ts +11 -2
- package/src/adapters/types.ts +7 -1
- package/src/agents/research.ts +55 -5
- package/src/file-manager.ts +30 -0
- package/src/prompt-builder.ts +24 -0
- package/src/todo-manager.ts +169 -0
- package/src/workflow/steps/build.ts +9 -0
- package/src/workflow/steps/plan.ts +13 -3
|
Binary file
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,8 @@ export { PermissionMode, } from './src/types.js';
|
|
|
3
3
|
export type { Task, TaskRun, SupportingFile, ExecutionResult, AgentConfig, McpServerConfig, AgentEvent, ResearchEvaluation } from './src/types.js';
|
|
4
4
|
export { Logger, LogLevel, } from './src/utils/logger.js';
|
|
5
5
|
export type { LoggerConfig } from './src/utils/logger.js';
|
|
6
|
+
export { TodoManager } from './src/todo-manager.js';
|
|
7
|
+
export type { TodoItem, TodoList } from './src/todo-manager.js';
|
|
6
8
|
export type { ProviderAdapter } from './src/adapters/types.js';
|
|
7
9
|
export { ClaudeAdapter } from './src/adapters/claude/claude-adapter.js';
|
|
8
10
|
export type { Tool, ToolCategory, KnownTool, ReadTool, WriteTool, EditTool, GlobTool, NotebookEditTool, BashTool, BashOutputTool, KillShellTool, WebFetchTool, WebSearchTool, GrepTool, TaskTool, TodoWriteTool, ExitPlanModeTool, SlashCommandTool, } from './src/tools/types.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AACA,OAAO,EACH,KAAK,GACR,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACH,cAAc,GACjB,MAAM,gBAAgB,CAAC;AAExB,YAAY,EACR,IAAI,EACJ,OAAO,EACP,cAAc,EACd,eAAe,EACf,WAAW,EACX,eAAe,EACf,UAAU,EACV,kBAAkB,EACrB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACH,MAAM,EACN,QAAQ,GACX,MAAM,uBAAuB,CAAC;AAE/B,YAAY,EACR,YAAY,EACf,MAAM,uBAAuB,CAAC;AAG/B,YAAY,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,yCAAyC,CAAC;AAGx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AC"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { Agent } from './src/agent.js';
|
|
2
2
|
export { PermissionMode } from './src/types.js';
|
|
3
3
|
export { LogLevel, Logger } from './src/utils/logger.js';
|
|
4
|
+
export { TodoManager } from './src/todo-manager.js';
|
|
4
5
|
export { ClaudeAdapter } from './src/adapters/claude/claude-adapter.js';
|
|
5
6
|
export { ToolRegistry } from './src/tools/registry.js';
|
|
6
7
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AgentEvent } from '../../types.js';
|
|
1
|
+
import type { AgentEvent, ArtifactEvent, StatusEvent } from '../../types.js';
|
|
2
2
|
import type { SDKMessage } from '@anthropic-ai/claude-agent-sdk';
|
|
3
3
|
import type { ProviderAdapter } from '../types.js';
|
|
4
4
|
/**
|
|
@@ -10,7 +10,8 @@ export declare class ClaudeAdapter implements ProviderAdapter {
|
|
|
10
10
|
private toolMapper;
|
|
11
11
|
createRawSDKEvent(sdkMessage: any): AgentEvent;
|
|
12
12
|
transform(sdkMessage: SDKMessage): AgentEvent | null;
|
|
13
|
-
createStatusEvent(phase: string, additionalData?: any):
|
|
13
|
+
createStatusEvent(phase: string, additionalData?: any): StatusEvent;
|
|
14
|
+
createArtifactEvent(kind: string, content: any): ArtifactEvent;
|
|
14
15
|
private extractUserContent;
|
|
15
16
|
private extractFromObject;
|
|
16
17
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"claude-adapter.d.ts","sourceRoot":"","sources":["../../../../src/adapters/claude/claude-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"claude-adapter.d.ts","sourceRoot":"","sources":["../../../../src/adapters/claude/claude-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAGnD;;;GAGG;AACH,qBAAa,aAAc,YAAW,eAAe;IACnD,QAAQ,CAAC,IAAI,YAAY;IACzB,OAAO,CAAC,UAAU,CAA0B;IAC5C,iBAAiB,CAAC,UAAU,EAAE,GAAG,GAAG,UAAU;IAQ9C,SAAS,CAAC,UAAU,EAAE,UAAU,GAAG,UAAU,GAAG,IAAI;IA2OpD,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,cAAc,CAAC,EAAE,GAAG,GAAG,WAAW;IASnE,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,GAAG,aAAa;IAS9D,OAAO,CAAC,kBAAkB;IAkC1B,OAAO,CAAC,iBAAiB;CAoB1B"}
|
|
@@ -241,6 +241,14 @@ class ClaudeAdapter {
|
|
|
241
241
|
...additionalData
|
|
242
242
|
};
|
|
243
243
|
}
|
|
244
|
+
createArtifactEvent(kind, content) {
|
|
245
|
+
return {
|
|
246
|
+
type: 'artifact',
|
|
247
|
+
ts: Date.now(),
|
|
248
|
+
kind,
|
|
249
|
+
content
|
|
250
|
+
};
|
|
251
|
+
}
|
|
244
252
|
extractUserContent(content) {
|
|
245
253
|
if (!content) {
|
|
246
254
|
return null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"claude-adapter.js","sources":["../../../../src/adapters/claude/claude-adapter.ts"],"sourcesContent":["import type { AgentEvent } from '../../types.js';\nimport type { SDKMessage } from '@anthropic-ai/claude-agent-sdk';\nimport type { ProviderAdapter } from '../types.js';\nimport { ClaudeToolMapper } from './tool-mapper.js';\n\n/**\n * Claude provider adapter.\n * Transforms Claude SDK messages into our standardized AgentEvent format.\n */\nexport class ClaudeAdapter implements ProviderAdapter {\n readonly name = 'claude';\n private toolMapper = new ClaudeToolMapper();\n createRawSDKEvent(sdkMessage: any): AgentEvent {\n return {\n type: 'raw_sdk_event',\n ts: Date.now(),\n sdkMessage\n };\n }\n\n transform(sdkMessage: SDKMessage): AgentEvent | null {\n const baseEvent = { ts: Date.now() };\n\n // Handle stream events\n if (sdkMessage.type === 'stream_event') {\n const event = sdkMessage.event;\n\n switch (event.type) {\n case 'message_start':\n return {\n ...baseEvent,\n type: 'message_start',\n messageId: event.message?.id,\n model: event.message?.model\n };\n\n case 'content_block_start':\n const contentBlock = event.content_block;\n if (!contentBlock) return null;\n\n return {\n ...baseEvent,\n type: 'content_block_start',\n index: event.index,\n contentType: contentBlock.type as 'text' | 'tool_use' | 'thinking',\n toolName: contentBlock.type === 'tool_use' ? contentBlock.name : undefined,\n toolId: contentBlock.type === 'tool_use' ? contentBlock.id : undefined\n };\n\n case 'content_block_delta':\n const delta = event.delta;\n if (!delta) return null;\n\n if (delta.type === 'text_delta') {\n return {\n ...baseEvent,\n type: 'token',\n content: delta.text,\n contentType: 'text'\n };\n } else if (delta.type === 'input_json_delta') {\n return {\n ...baseEvent,\n type: 'token',\n content: delta.partial_json,\n contentType: 'tool_input'\n };\n } else if (delta.type === 'thinking_delta') {\n return {\n ...baseEvent,\n type: 'token',\n content: delta.thinking,\n contentType: 'thinking'\n };\n }\n return null;\n\n case 'content_block_stop':\n return {\n ...baseEvent,\n type: 'content_block_stop',\n index: event.index\n };\n\n case 'message_delta':\n return {\n ...baseEvent,\n type: 'message_delta',\n stopReason: event.delta?.stop_reason,\n stopSequence: event.delta?.stop_sequence,\n usage: event.usage ? {\n outputTokens: event.usage.output_tokens\n } : undefined\n };\n\n case 'message_stop':\n return {\n ...baseEvent,\n type: 'message_stop'\n };\n\n case 'ping':\n // Ignore ping events\n return null;\n\n case 'error':\n return {\n ...baseEvent,\n type: 'error',\n message: event.error?.message || 'Unknown error',\n error: event.error,\n errorType: event.error?.type || 'stream_error',\n context: event.error ? {\n type: event.error.type,\n code: event.error.code,\n } : undefined,\n sdkError: event.error\n };\n\n default:\n return null;\n }\n }\n\n // Handle assistant messages (full message, not streaming)\n if (sdkMessage.type === 'assistant') {\n const message = sdkMessage.message;\n\n // Extract tool calls from content blocks\n if (message.content && Array.isArray(message.content)) {\n for (const block of message.content) {\n if (block.type === 'tool_use') {\n // Create tool_call event and enrich with metadata\n const toolCallEvent = {\n ...baseEvent,\n type: 'tool_call' as const,\n toolName: block.name,\n callId: block.id,\n args: block.input || {},\n parentToolUseId: sdkMessage.parent_tool_use_id\n };\n // Enrich with tool metadata\n return this.toolMapper.enrichToolCall(toolCallEvent);\n }\n }\n }\n\n // If no tool calls, emit status event\n return {\n ...baseEvent,\n type: 'status',\n phase: 'assistant_message',\n messageId: message.id,\n model: message.model\n };\n }\n\n // Handle user messages\n if (sdkMessage.type === 'user') {\n const message = sdkMessage.message;\n\n // Check for tool results in content blocks\n if (message?.content && Array.isArray(message.content)) {\n for (const block of message.content) {\n if (block.type === 'tool_result') {\n // Create tool_result event and enrich with metadata\n const toolResultEvent = {\n ...baseEvent,\n type: 'tool_result' as const,\n toolName: block.tool_name || 'unknown',\n callId: block.tool_use_id || '',\n result: block.content,\n isError: block.is_error,\n parentToolUseId: sdkMessage.parent_tool_use_id\n };\n // Enrich with tool metadata\n return this.toolMapper.enrichToolResult(toolResultEvent);\n }\n }\n }\n\n // Otherwise extract text content\n const textContent = this.extractUserContent(message?.content);\n if (!textContent) {\n return null;\n }\n return {\n ...baseEvent,\n type: 'user_message',\n content: textContent,\n isSynthetic: sdkMessage.isSynthetic\n };\n }\n\n // Handle result messages\n if (sdkMessage.type === 'result') {\n if (sdkMessage.subtype === 'success') {\n return {\n ...baseEvent,\n type: 'done',\n result: sdkMessage.result,\n durationMs: sdkMessage.duration_ms,\n durationApiMs: sdkMessage.duration_api_ms,\n numTurns: sdkMessage.num_turns,\n totalCostUsd: sdkMessage.total_cost_usd,\n usage: sdkMessage.usage,\n modelUsage: sdkMessage.modelUsage,\n permissionDenials: sdkMessage.permission_denials\n };\n } else {\n return {\n ...baseEvent,\n type: 'error',\n message: `Execution failed: ${sdkMessage.subtype}`,\n error: { subtype: sdkMessage.subtype },\n errorType: sdkMessage.subtype || 'result_error',\n context: {\n subtype: sdkMessage.subtype,\n duration_ms: sdkMessage.duration_ms,\n num_turns: sdkMessage.num_turns\n },\n sdkError: sdkMessage\n };\n }\n }\n\n // Handle system messages\n if (sdkMessage.type === 'system') {\n if (sdkMessage.subtype === 'init') {\n return {\n ...baseEvent,\n type: 'init',\n model: sdkMessage.model,\n tools: sdkMessage.tools,\n permissionMode: sdkMessage.permissionMode,\n cwd: sdkMessage.cwd,\n apiKeySource: sdkMessage.apiKeySource,\n agents: sdkMessage.agents,\n slashCommands: sdkMessage.slash_commands,\n outputStyle: sdkMessage.output_style,\n mcpServers: sdkMessage.mcp_servers\n };\n } else if (sdkMessage.subtype === 'compact_boundary') {\n return {\n ...baseEvent,\n type: 'compact_boundary',\n trigger: sdkMessage.compact_metadata.trigger,\n preTokens: sdkMessage.compact_metadata.pre_tokens\n };\n }\n }\n\n return null;\n }\n \n createStatusEvent(phase: string, additionalData?: any): import('../../types.js').StatusEvent {\n return {\n type: 'status',\n ts: Date.now(),\n phase,\n ...additionalData\n };\n }\n\n private extractUserContent(content: unknown): string | null {\n if (!content) {\n return null;\n }\n\n if (typeof content === 'string') {\n const trimmed = content.trim();\n return trimmed.length > 0 ? trimmed : null;\n }\n\n if (Array.isArray(content)) {\n const parts: string[] = [];\n for (const block of content) {\n const extracted = this.extractUserContent(block);\n if (extracted) {\n parts.push(extracted);\n } else if (block && typeof block === 'object') {\n const candidate = this.extractFromObject(block as Record<string, unknown>);\n if (candidate) {\n parts.push(candidate);\n }\n }\n }\n const text = parts.join('\\n').trim();\n return text.length > 0 ? text : null;\n }\n\n if (typeof content === 'object') {\n return this.extractFromObject(content as Record<string, unknown>);\n }\n\n return null;\n }\n\n private extractFromObject(value: Record<string, unknown>): string | null {\n const preferredKeys = ['text', 'input_text', 'input', 'markdown', 'content', 'message'];\n for (const key of preferredKeys) {\n if (typeof value[key] === 'string') {\n const trimmed = (value[key] as string).trim();\n if (trimmed.length > 0) {\n return trimmed;\n }\n }\n }\n\n for (const entry of Object.values(value)) {\n const extracted = this.extractUserContent(entry);\n if (extracted) {\n return extracted;\n }\n }\n\n return null;\n }\n}\n"],"names":[],"mappings":";;AAKA;;;AAGG;MACU,aAAa,CAAA;IACf,IAAI,GAAG,QAAQ;AAChB,IAAA,UAAU,GAAG,IAAI,gBAAgB,EAAE;AAC3C,IAAA,iBAAiB,CAAC,UAAe,EAAA;QAC/B,OAAO;AACL,YAAA,IAAI,EAAE,eAAe;AACrB,YAAA,EAAE,EAAE,IAAI,CAAC,GAAG,EAAE;YACd;SACD;IACH;AAEA,IAAA,SAAS,CAAC,UAAsB,EAAA;QAC9B,MAAM,SAAS,GAAG,EAAE,EAAE,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE;;AAGpC,QAAA,IAAI,UAAU,CAAC,IAAI,KAAK,cAAc,EAAE;AACtC,YAAA,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK;AAE9B,YAAA,QAAQ,KAAK,CAAC,IAAI;AAChB,gBAAA,KAAK,eAAe;oBAClB,OAAO;AACL,wBAAA,GAAG,SAAS;AACZ,wBAAA,IAAI,EAAE,eAAe;AACrB,wBAAA,SAAS,EAAE,KAAK,CAAC,OAAO,EAAE,EAAE;AAC5B,wBAAA,KAAK,EAAE,KAAK,CAAC,OAAO,EAAE;qBACvB;AAEH,gBAAA,KAAK,qBAAqB;AACxB,oBAAA,MAAM,YAAY,GAAG,KAAK,CAAC,aAAa;AACxC,oBAAA,IAAI,CAAC,YAAY;AAAE,wBAAA,OAAO,IAAI;oBAE9B,OAAO;A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AC,IAAI,EAAE;AAC7C,gBAAA,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE;AACtB,oBAAA,OAAO,OAAO;gBAChB;YACF;QACF;QAEA,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;YACxC,MAAM,SAAS,GAAG,IAAI,CAAC,kBAAkB,CAAC,KAAK,CAAC;YAChD,IAAI,SAAS,EAAE;AACb,gBAAA,OAAO,SAAS;YAClB;QACF;AAEA,QAAA,OAAO,IAAI;IACb;AACD;;;;"}
|
|
1
|
+
{"version":3,"file":"claude-adapter.js","sources":["../../../../src/adapters/claude/claude-adapter.ts"],"sourcesContent":["import type { AgentEvent, ArtifactEvent, StatusEvent } from '../../types.js';\nimport type { SDKMessage } from '@anthropic-ai/claude-agent-sdk';\nimport type { ProviderAdapter } from '../types.js';\nimport { ClaudeToolMapper } from './tool-mapper.js';\n\n/**\n * Claude provider adapter.\n * Transforms Claude SDK messages into our standardized AgentEvent format.\n */\nexport class ClaudeAdapter implements ProviderAdapter {\n readonly name = 'claude';\n private toolMapper = new ClaudeToolMapper();\n createRawSDKEvent(sdkMessage: any): AgentEvent {\n return {\n type: 'raw_sdk_event',\n ts: Date.now(),\n sdkMessage\n };\n }\n\n transform(sdkMessage: SDKMessage): AgentEvent | null {\n const baseEvent = { ts: Date.now() };\n\n // Handle stream events\n if (sdkMessage.type === 'stream_event') {\n const event = sdkMessage.event;\n\n switch (event.type) {\n case 'message_start':\n return {\n ...baseEvent,\n type: 'message_start',\n messageId: event.message?.id,\n model: event.message?.model\n };\n\n case 'content_block_start':\n const contentBlock = event.content_block;\n if (!contentBlock) return null;\n\n return {\n ...baseEvent,\n type: 'content_block_start',\n index: event.index,\n contentType: contentBlock.type as 'text' | 'tool_use' | 'thinking',\n toolName: contentBlock.type === 'tool_use' ? contentBlock.name : undefined,\n toolId: contentBlock.type === 'tool_use' ? contentBlock.id : undefined\n };\n\n case 'content_block_delta':\n const delta = event.delta;\n if (!delta) return null;\n\n if (delta.type === 'text_delta') {\n return {\n ...baseEvent,\n type: 'token',\n content: delta.text,\n contentType: 'text'\n };\n } else if (delta.type === 'input_json_delta') {\n return {\n ...baseEvent,\n type: 'token',\n content: delta.partial_json,\n contentType: 'tool_input'\n };\n } else if (delta.type === 'thinking_delta') {\n return {\n ...baseEvent,\n type: 'token',\n content: delta.thinking,\n contentType: 'thinking'\n };\n }\n return null;\n\n case 'content_block_stop':\n return {\n ...baseEvent,\n type: 'content_block_stop',\n index: event.index\n };\n\n case 'message_delta':\n return {\n ...baseEvent,\n type: 'message_delta',\n stopReason: event.delta?.stop_reason,\n stopSequence: event.delta?.stop_sequence,\n usage: event.usage ? {\n outputTokens: event.usage.output_tokens\n } : undefined\n };\n\n case 'message_stop':\n return {\n ...baseEvent,\n type: 'message_stop'\n };\n\n case 'ping':\n // Ignore ping events\n return null;\n\n case 'error':\n return {\n ...baseEvent,\n type: 'error',\n message: event.error?.message || 'Unknown error',\n error: event.error,\n errorType: event.error?.type || 'stream_error',\n context: event.error ? {\n type: event.error.type,\n code: event.error.code,\n } : undefined,\n sdkError: event.error\n };\n\n default:\n return null;\n }\n }\n\n // Handle assistant messages (full message, not streaming)\n if (sdkMessage.type === 'assistant') {\n const message = sdkMessage.message;\n\n // Extract tool calls from content blocks\n if (message.content && Array.isArray(message.content)) {\n for (const block of message.content) {\n if (block.type === 'tool_use') {\n // Create tool_call event and enrich with metadata\n const toolCallEvent = {\n ...baseEvent,\n type: 'tool_call' as const,\n toolName: block.name,\n callId: block.id,\n args: block.input || {},\n parentToolUseId: sdkMessage.parent_tool_use_id\n };\n // Enrich with tool metadata\n return this.toolMapper.enrichToolCall(toolCallEvent);\n }\n }\n }\n\n // If no tool calls, emit status event\n return {\n ...baseEvent,\n type: 'status',\n phase: 'assistant_message',\n messageId: message.id,\n model: message.model\n };\n }\n\n // Handle user messages\n if (sdkMessage.type === 'user') {\n const message = sdkMessage.message;\n\n // Check for tool results in content blocks\n if (message?.content && Array.isArray(message.content)) {\n for (const block of message.content) {\n if (block.type === 'tool_result') {\n // Create tool_result event and enrich with metadata\n const toolResultEvent = {\n ...baseEvent,\n type: 'tool_result' as const,\n toolName: block.tool_name || 'unknown',\n callId: block.tool_use_id || '',\n result: block.content,\n isError: block.is_error,\n parentToolUseId: sdkMessage.parent_tool_use_id\n };\n // Enrich with tool metadata\n return this.toolMapper.enrichToolResult(toolResultEvent);\n }\n }\n }\n\n // Otherwise extract text content\n const textContent = this.extractUserContent(message?.content);\n if (!textContent) {\n return null;\n }\n return {\n ...baseEvent,\n type: 'user_message',\n content: textContent,\n isSynthetic: sdkMessage.isSynthetic\n };\n }\n\n // Handle result messages\n if (sdkMessage.type === 'result') {\n if (sdkMessage.subtype === 'success') {\n return {\n ...baseEvent,\n type: 'done',\n result: sdkMessage.result,\n durationMs: sdkMessage.duration_ms,\n durationApiMs: sdkMessage.duration_api_ms,\n numTurns: sdkMessage.num_turns,\n totalCostUsd: sdkMessage.total_cost_usd,\n usage: sdkMessage.usage,\n modelUsage: sdkMessage.modelUsage,\n permissionDenials: sdkMessage.permission_denials\n };\n } else {\n return {\n ...baseEvent,\n type: 'error',\n message: `Execution failed: ${sdkMessage.subtype}`,\n error: { subtype: sdkMessage.subtype },\n errorType: sdkMessage.subtype || 'result_error',\n context: {\n subtype: sdkMessage.subtype,\n duration_ms: sdkMessage.duration_ms,\n num_turns: sdkMessage.num_turns\n },\n sdkError: sdkMessage\n };\n }\n }\n\n // Handle system messages\n if (sdkMessage.type === 'system') {\n if (sdkMessage.subtype === 'init') {\n return {\n ...baseEvent,\n type: 'init',\n model: sdkMessage.model,\n tools: sdkMessage.tools,\n permissionMode: sdkMessage.permissionMode,\n cwd: sdkMessage.cwd,\n apiKeySource: sdkMessage.apiKeySource,\n agents: sdkMessage.agents,\n slashCommands: sdkMessage.slash_commands,\n outputStyle: sdkMessage.output_style,\n mcpServers: sdkMessage.mcp_servers\n };\n } else if (sdkMessage.subtype === 'compact_boundary') {\n return {\n ...baseEvent,\n type: 'compact_boundary',\n trigger: sdkMessage.compact_metadata.trigger,\n preTokens: sdkMessage.compact_metadata.pre_tokens\n };\n }\n }\n\n return null;\n }\n \n createStatusEvent(phase: string, additionalData?: any): StatusEvent {\n return {\n type: 'status',\n ts: Date.now(),\n phase,\n ...additionalData\n };\n }\n\n createArtifactEvent(kind: string, content: any): ArtifactEvent {\n return {\n type: 'artifact',\n ts: Date.now(),\n kind,\n content\n };\n }\n\n private extractUserContent(content: unknown): string | null {\n if (!content) {\n return null;\n }\n\n if (typeof content === 'string') {\n const trimmed = content.trim();\n return trimmed.length > 0 ? trimmed : null;\n }\n\n if (Array.isArray(content)) {\n const parts: string[] = [];\n for (const block of content) {\n const extracted = this.extractUserContent(block);\n if (extracted) {\n parts.push(extracted);\n } else if (block && typeof block === 'object') {\n const candidate = this.extractFromObject(block as Record<string, unknown>);\n if (candidate) {\n parts.push(candidate);\n }\n }\n }\n const text = parts.join('\\n').trim();\n return text.length > 0 ? text : null;\n }\n\n if (typeof content === 'object') {\n return this.extractFromObject(content as Record<string, unknown>);\n }\n\n return null;\n }\n\n private extractFromObject(value: Record<string, unknown>): string | null {\n const preferredKeys = ['text', 'input_text', 'input', 'markdown', 'content', 'message'];\n for (const key of preferredKeys) {\n if (typeof value[key] === 'string') {\n const trimmed = (value[key] as string).trim();\n if (trimmed.length > 0) {\n return trimmed;\n }\n }\n }\n\n for (const entry of Object.values(value)) {\n const extracted = this.extractUserContent(entry);\n if (extracted) {\n return extracted;\n }\n }\n\n return null;\n }\n}\n"],"names":[],"mappings":";;AAKA;;;AAGG;MACU,aAAa,CAAA;IACf,IAAI,GAAG,QAAQ;AAChB,IAAA,UAAU,GAAG,IAAI,gBAAgB,EAAE;AAC3C,IAAA,iBAAiB,CAAC,UAAe,EAAA;QAC/B,OAAO;AACL,YAAA,IAAI,EAAE,eAAe;AACrB,YAAA,EAAE,EAAE,IAAI,CAAC,GAAG,EAAE;YACd;SACD;IACH;AAEA,IAA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|
|
2
2
|
/**
|
|
3
3
|
* Provider adapter interface for transforming provider-specific messages
|
|
4
4
|
* into our standardized AgentEvent format.
|
|
@@ -19,6 +19,11 @@ export interface ProviderAdapter {
|
|
|
19
19
|
* Used for task phase transitions and other status updates.
|
|
20
20
|
*/
|
|
21
21
|
createStatusEvent(phase: string, additionalData?: any): StatusEvent;
|
|
22
|
+
/**
|
|
23
|
+
* Create an artifact event for custom task artifacts (todos, etc).
|
|
24
|
+
* Used to emit structured artifacts for UI consumption.
|
|
25
|
+
*/
|
|
26
|
+
createArtifactEvent(kind: string, content: any): ArtifactEvent;
|
|
22
27
|
/**
|
|
23
28
|
* Create a raw SDK event for debugging purposes.
|
|
24
29
|
* Wraps the original SDK message in a raw_sdk_event.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/adapters/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/adapters/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE1E;;;;;;GAMG;AACH,MAAM,WAAW,eAAe;IAC9B,+CAA+C;IAC/C,IAAI,EAAE,MAAM,CAAC;IAEb;;;OAGG;IACH,SAAS,CAAC,UAAU,EAAE,OAAO,GAAG,UAAU,GAAG,IAAI,CAAC;IAElD;;;OAGG;IACH,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,cAAc,CAAC,EAAE,GAAG,GAAG,WAAW,CAAC;IAEpE;;;OAGG;IACH,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,GAAG,aAAa,CAAC;IAE/D;;;OAGG;IACH,iBAAiB,CAAC,UAAU,EAAE,GAAG,GAAG,UAAU,CAAC;CAChD"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const RESEARCH_SYSTEM_PROMPT = "<role>\nPostHog AI Research Agent \u2014 analyze codebases to evaluate task actionability and identify missing information.\n</role>\n\n<constraints>\n- Read-only: analyze files, search code, explore structure\n- No modifications or code changes\n- Output structured JSON only\n</constraints>\n\n<objective>\nYour PRIMARY goal is to evaluate whether a task is actionable and assign an actionability score.\n\nCalculate an actionabilityScore (0-1) based on:\n- **Task clarity** (0.4 weight): Is the task description specific and unambiguous?\n- **Codebase context** (0.3 weight): Can you locate the relevant code and patterns?\n- **Architectural decisions** (0.2 weight): Are the implementation approaches clear?\n- **Dependencies** (0.1 weight): Are required dependencies and constraints understood?\n\nIf actionabilityScore < 0.7, generate specific clarifying questions to increase confidence.\n\nDO NOT ask questions like \"how should I fix this\" \u2014
|
|
1
|
+
export declare const RESEARCH_SYSTEM_PROMPT = "<role>\nPostHog AI Research Agent \u2014 analyze codebases to evaluate task actionability and identify missing information.\n</role>\n\n<constraints>\n- Read-only: analyze files, search code, explore structure\n- No modifications or code changes\n- Output structured JSON only\n</constraints>\n\n<objective>\nYour PRIMARY goal is to evaluate whether a task is actionable and assign an actionability score.\n\nCalculate an actionabilityScore (0-1) based on:\n- **Task clarity** (0.4 weight): Is the task description specific and unambiguous?\n- **Codebase context** (0.3 weight): Can you locate the relevant code and patterns?\n- **Architectural decisions** (0.2 weight): Are the implementation approaches clear?\n- **Dependencies** (0.1 weight): Are required dependencies and constraints understood?\n\nIf actionabilityScore < 0.7, generate specific clarifying questions to increase confidence.\n\nQuestions must present complete implementation choices, NOT request information from the user:\noptions: array of strings\n- GOOD: options: [\"Use Redux Toolkit (matches pattern in src/store/)\", \"Zustand (lighter weight)\"]\n- BAD: \"Tell me which state management library to use\"\n- GOOD: options: [\"Place in Button.tsx (existing component)\", \"create NewButton.tsx (separate concerns)?\"]\n- BAD: \"Where should I put this code?\"\n\nDO NOT ask questions like \"how should I fix this\" or \"tell me the pattern\" \u2014 present concrete options that can be directly chosen and acted upon.\n</objective>\n\n<process>\n1. Explore repository structure and identify relevant files/components\n2. Understand existing patterns, conventions, and dependencies\n3. Calculate actionabilityScore based on clarity, context, architecture, and dependencies\n4. Identify key files that will need modification\n5. If score < 0.7: generate 2-4 specific questions to resolve blockers\n6. Output JSON matching ResearchEvaluation schema\n</process>\n\n<output_format>\nOutput ONLY valid JSON with no markdown wrappers, no preamble, no explanation:\n\n{\n \"actionabilityScore\": 0.85,\n \"context\": \"Brief 2-3 sentence summary of the task and implementation approach\",\n \"keyFiles\": [\"path/to/file1.ts\", \"path/to/file2.ts\"],\n \"blockers\": [\"Optional: what's preventing full confidence\"],\n \"questions\": [\n {\n \"id\": \"q1\",\n \"question\": \"Specific architectural decision needed?\",\n \"options\": [\n \"First approach with concrete details\",\n \"Alternative approach with concrete details\",\n \"Third option if needed\"\n ]\n }\n ]\n}\n\nRules:\n- actionabilityScore: number between 0 and 1\n- context: concise summary for planning phase\n- keyFiles: array of file paths that need modification\n- blockers: optional array explaining confidence gaps\n- questions: ONLY include if actionabilityScore < 0.7\n- Each question must have 2-3 options (maximum 3)\n- Max 3 questions total\n- Options must be complete, actionable choices that require NO additional user input\n- NEVER use options like \"Tell me the pattern\", \"Show me examples\", \"Specify the approach\"\n- Each option must be a full implementation decision that can be directly acted upon\n</output_format>\n\n<scoring_examples>\n<example score=\"0.9\">\nTask: \"Fix typo in login button text\"\nReasoning: Completely clear task, found exact component, no architectural decisions\n</example>\n\n<example score=\"0.75\">\nTask: \"Add caching to API endpoints\"\nReasoning: Clear goal, found endpoints, but multiple caching strategies possible\n</example>\n\n<example score=\"0.55\">\nTask: \"Improve performance\"\nReasoning: Vague task, unclear scope, needs questions about which areas to optimize\nQuestions needed: Which features are slow? What metrics define success?\n</example>\n\n<example score=\"0.3\">\nTask: \"Add the new feature\"\nReasoning: Extremely vague, no context, cannot locate relevant code\nQuestions needed: What feature? Which product area? What should it do?\n</example>\n</scoring_examples>\n\n<question_examples>\n<good_example>\n{\n \"id\": \"q1\",\n \"question\": \"Which caching layer should we use for API responses?\",\n \"options\": [\n \"Redis with 1-hour TTL (existing infrastructure, requires Redis client setup)\",\n \"In-memory LRU cache with 100MB limit (simpler, single-server only)\",\n \"HTTP Cache-Control headers only (minimal backend changes, relies on browser/CDN)\"\n ]\n}\nReason: Each option is a complete, actionable decision with concrete details\n</good_example>\n\n<good_example>\n{\n \"id\": \"q2\",\n \"question\": \"Where should the new analytics tracking code be placed?\",\n \"options\": [\n \"In the existing UserAnalytics.ts module alongside page view tracking\",\n \"Create a new EventTracking.ts module in src/analytics/ for all event tracking\",\n \"Add directly to each component that needs tracking (no centralized module)\"\n ]\n}\nReason: Specific file paths and architectural patterns, no user input needed\n</good_example>\n\n<bad_example>\n{\n \"id\": \"q1\", \n \"question\": \"How should I implement this?\",\n \"options\": [\"One way\", \"Another way\"]\n}\nReason: Too vague, doesn't explain the tradeoffs or provide concrete details\n</bad_example>\n\n<bad_example>\n{\n \"id\": \"q2\",\n \"question\": \"Which pattern should we follow for state management?\",\n \"options\": [\n \"Tell me which pattern the codebase currently uses\",\n \"Show me examples of state management\",\n \"Whatever you think is best\"\n ]\n}\nReason: Options request user input instead of being actionable choices. Should be concrete patterns like \"Zustand stores (matching existing patterns in src/stores/)\" or \"React Context (simpler, no new dependencies)\"\n</bad_example>\n\n<bad_example>\n{\n \"id\": \"q3\",\n \"question\": \"What color scheme should the button use?\",\n \"options\": [\n \"Use the existing theme colors\",\n \"Let me specify custom colors\",\n \"Match the design system\"\n ]\n}\nReason: \"Let me specify\" requires user input. Should be \"Primary blue (#0066FF, existing theme)\" or \"Secondary gray (#6B7280, existing theme)\"\n</bad_example>\n</question_examples>";
|
|
2
2
|
//# sourceMappingURL=research.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"research.d.ts","sourceRoot":"","sources":["../../../src/agents/research.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,sBAAsB,
|
|
1
|
+
{"version":3,"file":"research.d.ts","sourceRoot":"","sources":["../../../src/agents/research.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,sBAAsB,klMA+Jd,CAAC"}
|
|
@@ -19,7 +19,14 @@ Calculate an actionabilityScore (0-1) based on:
|
|
|
19
19
|
|
|
20
20
|
If actionabilityScore < 0.7, generate specific clarifying questions to increase confidence.
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
Questions must present complete implementation choices, NOT request information from the user:
|
|
23
|
+
options: array of strings
|
|
24
|
+
- GOOD: options: ["Use Redux Toolkit (matches pattern in src/store/)", "Zustand (lighter weight)"]
|
|
25
|
+
- BAD: "Tell me which state management library to use"
|
|
26
|
+
- GOOD: options: ["Place in Button.tsx (existing component)", "create NewButton.tsx (separate concerns)?"]
|
|
27
|
+
- BAD: "Where should I put this code?"
|
|
28
|
+
|
|
29
|
+
DO NOT ask questions like "how should I fix this" or "tell me the pattern" — present concrete options that can be directly chosen and acted upon.
|
|
23
30
|
</objective>
|
|
24
31
|
|
|
25
32
|
<process>
|
|
@@ -60,6 +67,9 @@ Rules:
|
|
|
60
67
|
- questions: ONLY include if actionabilityScore < 0.7
|
|
61
68
|
- Each question must have 2-3 options (maximum 3)
|
|
62
69
|
- Max 3 questions total
|
|
70
|
+
- Options must be complete, actionable choices that require NO additional user input
|
|
71
|
+
- NEVER use options like "Tell me the pattern", "Show me examples", "Specify the approach"
|
|
72
|
+
- Each option must be a full implementation decision that can be directly acted upon
|
|
63
73
|
</output_format>
|
|
64
74
|
|
|
65
75
|
<scoring_examples>
|
|
@@ -92,11 +102,25 @@ Questions needed: What feature? Which product area? What should it do?
|
|
|
92
102
|
"id": "q1",
|
|
93
103
|
"question": "Which caching layer should we use for API responses?",
|
|
94
104
|
"options": [
|
|
95
|
-
"Redis (existing infrastructure, requires setup)",
|
|
96
|
-
"In-memory cache (simpler,
|
|
97
|
-
"
|
|
105
|
+
"Redis with 1-hour TTL (existing infrastructure, requires Redis client setup)",
|
|
106
|
+
"In-memory LRU cache with 100MB limit (simpler, single-server only)",
|
|
107
|
+
"HTTP Cache-Control headers only (minimal backend changes, relies on browser/CDN)"
|
|
98
108
|
]
|
|
99
109
|
}
|
|
110
|
+
Reason: Each option is a complete, actionable decision with concrete details
|
|
111
|
+
</good_example>
|
|
112
|
+
|
|
113
|
+
<good_example>
|
|
114
|
+
{
|
|
115
|
+
"id": "q2",
|
|
116
|
+
"question": "Where should the new analytics tracking code be placed?",
|
|
117
|
+
"options": [
|
|
118
|
+
"In the existing UserAnalytics.ts module alongside page view tracking",
|
|
119
|
+
"Create a new EventTracking.ts module in src/analytics/ for all event tracking",
|
|
120
|
+
"Add directly to each component that needs tracking (no centralized module)"
|
|
121
|
+
]
|
|
122
|
+
}
|
|
123
|
+
Reason: Specific file paths and architectural patterns, no user input needed
|
|
100
124
|
</good_example>
|
|
101
125
|
|
|
102
126
|
<bad_example>
|
|
@@ -105,7 +129,33 @@ Questions needed: What feature? Which product area? What should it do?
|
|
|
105
129
|
"question": "How should I implement this?",
|
|
106
130
|
"options": ["One way", "Another way"]
|
|
107
131
|
}
|
|
108
|
-
Reason: Too vague, doesn't explain the tradeoffs
|
|
132
|
+
Reason: Too vague, doesn't explain the tradeoffs or provide concrete details
|
|
133
|
+
</bad_example>
|
|
134
|
+
|
|
135
|
+
<bad_example>
|
|
136
|
+
{
|
|
137
|
+
"id": "q2",
|
|
138
|
+
"question": "Which pattern should we follow for state management?",
|
|
139
|
+
"options": [
|
|
140
|
+
"Tell me which pattern the codebase currently uses",
|
|
141
|
+
"Show me examples of state management",
|
|
142
|
+
"Whatever you think is best"
|
|
143
|
+
]
|
|
144
|
+
}
|
|
145
|
+
Reason: Options request user input instead of being actionable choices. Should be concrete patterns like "Zustand stores (matching existing patterns in src/stores/)" or "React Context (simpler, no new dependencies)"
|
|
146
|
+
</bad_example>
|
|
147
|
+
|
|
148
|
+
<bad_example>
|
|
149
|
+
{
|
|
150
|
+
"id": "q3",
|
|
151
|
+
"question": "What color scheme should the button use?",
|
|
152
|
+
"options": [
|
|
153
|
+
"Use the existing theme colors",
|
|
154
|
+
"Let me specify custom colors",
|
|
155
|
+
"Match the design system"
|
|
156
|
+
]
|
|
157
|
+
}
|
|
158
|
+
Reason: "Let me specify" requires user input. Should be "Primary blue (#0066FF, existing theme)" or "Secondary gray (#6B7280, existing theme)"
|
|
109
159
|
</bad_example>
|
|
110
160
|
</question_examples>`;
|
|
111
161
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"research.js","sources":["../../../src/agents/research.ts"],"sourcesContent":["export const RESEARCH_SYSTEM_PROMPT = `<role>\nPostHog AI Research Agent — analyze codebases to evaluate task actionability and identify missing information.\n</role>\n\n<constraints>\n- Read-only: analyze files, search code, explore structure\n- No modifications or code changes\n- Output structured JSON only\n</constraints>\n\n<objective>\nYour PRIMARY goal is to evaluate whether a task is actionable and assign an actionability score.\n\nCalculate an actionabilityScore (0-1) based on:\n- **Task clarity** (0.4 weight): Is the task description specific and unambiguous?\n- **Codebase context** (0.3 weight): Can you locate the relevant code and patterns?\n- **Architectural decisions** (0.2 weight): Are the implementation approaches clear?\n- **Dependencies** (0.1 weight): Are required dependencies and constraints understood?\n\nIf actionabilityScore < 0.7, generate specific clarifying questions to increase confidence.\n\nDO NOT ask questions like \"how should I fix this\" —
|
|
1
|
+
{"version":3,"file":"research.js","sources":["../../../src/agents/research.ts"],"sourcesContent":["export const RESEARCH_SYSTEM_PROMPT = `<role>\nPostHog AI Research Agent — analyze codebases to evaluate task actionability and identify missing information.\n</role>\n\n<constraints>\n- Read-only: analyze files, search code, explore structure\n- No modifications or code changes\n- Output structured JSON only\n</constraints>\n\n<objective>\nYour PRIMARY goal is to evaluate whether a task is actionable and assign an actionability score.\n\nCalculate an actionabilityScore (0-1) based on:\n- **Task clarity** (0.4 weight): Is the task description specific and unambiguous?\n- **Codebase context** (0.3 weight): Can you locate the relevant code and patterns?\n- **Architectural decisions** (0.2 weight): Are the implementation approaches clear?\n- **Dependencies** (0.1 weight): Are required dependencies and constraints understood?\n\nIf actionabilityScore < 0.7, generate specific clarifying questions to increase confidence.\n\nQuestions must present complete implementation choices, NOT request information from the user:\noptions: array of strings\n- GOOD: options: [\"Use Redux Toolkit (matches pattern in src/store/)\", \"Zustand (lighter weight)\"]\n- BAD: \"Tell me which state management library to use\"\n- GOOD: options: [\"Place in Button.tsx (existing component)\", \"create NewButton.tsx (separate concerns)?\"]\n- BAD: \"Where should I put this code?\"\n\nDO NOT ask questions like \"how should I fix this\" or \"tell me the pattern\" — present concrete options that can be directly chosen and acted upon.\n</objective>\n\n<process>\n1. Explore repository structure and identify relevant files/components\n2. Understand existing patterns, conventions, and dependencies\n3. Calculate actionabilityScore based on clarity, context, architecture, and dependencies\n4. Identify key files that will need modification\n5. If score < 0.7: generate 2-4 specific questions to resolve blockers\n6. Output JSON matching ResearchEvaluation schema\n</process>\n\n<output_format>\nOutput ONLY valid JSON with no markdown wrappers, no preamble, no explanation:\n\n{\n \"actionabilityScore\": 0.85,\n \"context\": \"Brief 2-3 sentence summary of the task and implementation approach\",\n \"keyFiles\": [\"path/to/file1.ts\", \"path/to/file2.ts\"],\n \"blockers\": [\"Optional: what's preventing full confidence\"],\n \"questions\": [\n {\n \"id\": \"q1\",\n \"question\": \"Specific architectural decision needed?\",\n \"options\": [\n \"First approach with concrete details\",\n \"Alternative approach with concrete details\",\n \"Third option if needed\"\n ]\n }\n ]\n}\n\nRules:\n- actionabilityScore: number between 0 and 1\n- context: concise summary for planning phase\n- keyFiles: array of file paths that need modification\n- blockers: optional array explaining confidence gaps\n- questions: ONLY include if actionabilityScore < 0.7\n- Each question must have 2-3 options (maximum 3)\n- Max 3 questions total\n- Options must be complete, actionable choices that require NO additional user input\n- NEVER use options like \"Tell me the pattern\", \"Show me examples\", \"Specify the approach\"\n- Each option must be a full implementation decision that can be directly acted upon\n</output_format>\n\n<scoring_examples>\n<example score=\"0.9\">\nTask: \"Fix typo in login button text\"\nReasoning: Completely clear task, found exact component, no architectural decisions\n</example>\n\n<example score=\"0.75\">\nTask: \"Add caching to API endpoints\"\nReasoning: Clear goal, found endpoints, but multiple caching strategies possible\n</example>\n\n<example score=\"0.55\">\nTask: \"Improve performance\"\nReasoning: Vague task, unclear scope, needs questions about which areas to optimize\nQuestions needed: Which features are slow? What metrics define success?\n</example>\n\n<example score=\"0.3\">\nTask: \"Add the new feature\"\nReasoning: Extremely vague, no context, cannot locate relevant code\nQuestions needed: What feature? Which product area? What should it do?\n</example>\n</scoring_examples>\n\n<question_examples>\n<good_example>\n{\n \"id\": \"q1\",\n \"question\": \"Which caching layer should we use for API responses?\",\n \"options\": [\n \"Redis with 1-hour TTL (existing infrastructure, requires Redis client setup)\",\n \"In-memory LRU cache with 100MB limit (simpler, single-server only)\",\n \"HTTP Cache-Control headers only (minimal backend changes, relies on browser/CDN)\"\n ]\n}\nReason: Each option is a complete, actionable decision with concrete details\n</good_example>\n\n<good_example>\n{\n \"id\": \"q2\",\n \"question\": \"Where should the new analytics tracking code be placed?\",\n \"options\": [\n \"In the existing UserAnalytics.ts module alongside page view tracking\",\n \"Create a new EventTracking.ts module in src/analytics/ for all event tracking\",\n \"Add directly to each component that needs tracking (no centralized module)\"\n ]\n}\nReason: Specific file paths and architectural patterns, no user input needed\n</good_example>\n\n<bad_example>\n{\n \"id\": \"q1\", \n \"question\": \"How should I implement this?\",\n \"options\": [\"One way\", \"Another way\"]\n}\nReason: Too vague, doesn't explain the tradeoffs or provide concrete details\n</bad_example>\n\n<bad_example>\n{\n \"id\": \"q2\",\n \"question\": \"Which pattern should we follow for state management?\",\n \"options\": [\n \"Tell me which pattern the codebase currently uses\",\n \"Show me examples of state management\",\n \"Whatever you think is best\"\n ]\n}\nReason: Options request user input instead of being actionable choices. Should be concrete patterns like \"Zustand stores (matching existing patterns in src/stores/)\" or \"React Context (simpler, no new dependencies)\"\n</bad_example>\n\n<bad_example>\n{\n \"id\": \"q3\",\n \"question\": \"What color scheme should the button use?\",\n \"options\": [\n \"Use the existing theme colors\",\n \"Let me specify custom colors\",\n \"Match the design system\"\n ]\n}\nReason: \"Let me specify\" requires user input. Should be \"Primary blue (#0066FF, existing theme)\" or \"Secondary gray (#6B7280, existing theme)\"\n</bad_example>\n</question_examples>`;\n\n"],"names":[],"mappings":"AAAO,MAAM,sBAAsB,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -26,6 +26,8 @@ export declare class PostHogFileManager {
|
|
|
26
26
|
readRequirements(taskId: string): Promise<string | null>;
|
|
27
27
|
writeResearch(taskId: string, data: ResearchEvaluation): Promise<void>;
|
|
28
28
|
readResearch(taskId: string): Promise<ResearchEvaluation | null>;
|
|
29
|
+
writeTodos(taskId: string, data: any): Promise<void>;
|
|
30
|
+
readTodos(taskId: string): Promise<any | null>;
|
|
29
31
|
getTaskFiles(taskId: string): Promise<SupportingFile[]>;
|
|
30
32
|
}
|
|
31
33
|
//# sourceMappingURL=file-manager.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-manager.d.ts","sourceRoot":"","sources":["../../src/file-manager.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AACrE,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,WAAW,GAAG,QAAQ,GAAG,UAAU,CAAC;CAChE;AAED,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,cAAc,CAAS;IAC/B,OAAO,CAAC,MAAM,CAAS;gBAEX,cAAc,EAAE,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E,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAUrD,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAYnD,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAgBtD,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAIhD,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAQ5D,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAInD,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAQtE,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAIxD,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;IAuBtE,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC;IAUhE,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;IAoBpD,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,GAAG,IAAI,CAAC;IAU9C,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;CAyB9D"}
|
package/dist/src/file-manager.js
CHANGED
|
@@ -159,6 +159,33 @@ class PostHogFileManager {
|
|
|
159
159
|
return null;
|
|
160
160
|
}
|
|
161
161
|
}
|
|
162
|
+
async writeTodos(taskId, data) {
|
|
163
|
+
this.logger.debug('Writing todos', {
|
|
164
|
+
taskId,
|
|
165
|
+
total: data.metadata?.total ?? 0,
|
|
166
|
+
completed: data.metadata?.completed ?? 0,
|
|
167
|
+
});
|
|
168
|
+
await this.writeTaskFile(taskId, {
|
|
169
|
+
name: 'todos.json',
|
|
170
|
+
content: JSON.stringify(data, null, 2),
|
|
171
|
+
type: 'artifact'
|
|
172
|
+
});
|
|
173
|
+
this.logger.info('Todos file written', {
|
|
174
|
+
taskId,
|
|
175
|
+
total: data.metadata?.total ?? 0,
|
|
176
|
+
completed: data.metadata?.completed ?? 0,
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
async readTodos(taskId) {
|
|
180
|
+
try {
|
|
181
|
+
const content = await this.readTaskFile(taskId, 'todos.json');
|
|
182
|
+
return content ? JSON.parse(content) : null;
|
|
183
|
+
}
|
|
184
|
+
catch (error) {
|
|
185
|
+
this.logger.debug('Failed to parse todos.json', { error });
|
|
186
|
+
return null;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
162
189
|
async getTaskFiles(taskId) {
|
|
163
190
|
const fileNames = await this.listTaskFiles(taskId);
|
|
164
191
|
const files = [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-manager.js","sources":["../../src/file-manager.ts"],"sourcesContent":["import { promises as fs } from 'fs';\nimport { join } from 'path';\nimport type { SupportingFile, ResearchEvaluation } from './types.js';\nimport { Logger } from './utils/logger.js';\n\nexport interface TaskFile {\n name: string;\n content: string;\n type: 'plan' | 'context' | 'reference' | 'output' | 'artifact';\n}\n\nexport class PostHogFileManager {\n private repositoryPath: string;\n private logger: Logger;\n\n constructor(repositoryPath: string, logger?: Logger) {\n this.repositoryPath = repositoryPath;\n this.logger = logger || new Logger({ debug: false, prefix: '[FileManager]' });\n }\n\n private getTaskDirectory(taskId: string): string {\n return join(this.repositoryPath, '.posthog', taskId);\n }\n\n private getTaskFilePath(taskId: string, fileName: string): string {\n return join(this.getTaskDirectory(taskId), fileName);\n }\n\n async ensureTaskDirectory(taskId: string): Promise<void> {\n const taskDir = this.getTaskDirectory(taskId);\n try {\n await fs.access(taskDir);\n } catch {\n await fs.mkdir(taskDir, { recursive: true });\n }\n }\n\n async writeTaskFile(taskId: string, file: TaskFile): Promise<void> {\n await this.ensureTaskDirectory(taskId);\n const filePath = this.getTaskFilePath(taskId, file.name);\n\n this.logger.debug('Writing task file', {\n filePath,\n contentLength: file.content.length,\n contentType: typeof file.content\n });\n\n await fs.writeFile(filePath, file.content, 'utf8');\n\n this.logger.debug('File written successfully', { filePath });\n }\n\n async readTaskFile(taskId: string, fileName: string): Promise<string | null> {\n try {\n const filePath = this.getTaskFilePath(taskId, fileName);\n return await fs.readFile(filePath, 'utf8');\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') {\n return null;\n }\n throw error;\n }\n }\n\n async listTaskFiles(taskId: string): Promise<string[]> {\n try {\n const taskDir = this.getTaskDirectory(taskId);\n const files = await fs.readdir(taskDir);\n return files.filter(file => !file.startsWith('.'));\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') {\n return [];\n }\n throw error;\n }\n }\n\n async deleteTaskFile(taskId: string, fileName: string): Promise<void> {\n try {\n const filePath = this.getTaskFilePath(taskId, fileName);\n await fs.unlink(filePath);\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== 'ENOENT') {\n throw error;\n }\n }\n }\n\n async taskDirectoryExists(taskId: string): Promise<boolean> {\n try {\n const taskDir = this.getTaskDirectory(taskId);\n await fs.access(taskDir);\n return true;\n } catch {\n return false;\n }\n }\n\n async cleanupTaskDirectory(taskId: string): Promise<void> {\n try {\n const taskDir = this.getTaskDirectory(taskId);\n await fs.rm(taskDir, { recursive: true, force: true });\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== 'ENOENT') {\n throw error;\n }\n }\n }\n\n // Convenience methods for common file types\n async writePlan(taskId: string, plan: string): Promise<void> {\n this.logger.debug('Writing plan', {\n taskId,\n planLength: plan.length,\n contentPreview: plan.substring(0, 200)\n });\n\n await this.writeTaskFile(taskId, {\n name: 'plan.md',\n content: plan,\n type: 'plan'\n });\n\n this.logger.info('Plan file written', { taskId });\n }\n\n async readPlan(taskId: string): Promise<string | null> {\n return await this.readTaskFile(taskId, 'plan.md');\n }\n\n async writeContext(taskId: string, context: string): Promise<void> {\n await this.writeTaskFile(taskId, {\n name: 'context.md',\n content: context,\n type: 'context'\n });\n }\n\n async readContext(taskId: string): Promise<string | null> {\n return await this.readTaskFile(taskId, 'context.md');\n }\n\n async writeRequirements(taskId: string, requirements: string): Promise<void> {\n await this.writeTaskFile(taskId, {\n name: 'requirements.md',\n content: requirements,\n type: 'reference'\n });\n }\n\n async readRequirements(taskId: string): Promise<string | null> {\n return await this.readTaskFile(taskId, 'requirements.md');\n }\n\n async writeResearch(taskId: string, data: ResearchEvaluation): Promise<void> {\n this.logger.debug('Writing research', {\n taskId,\n score: data.actionabilityScore,\n hasQuestions: !!data.questions,\n questionCount: data.questions?.length ?? 0,\n answered: data.answered ?? false,\n });\n\n await this.writeTaskFile(taskId, {\n name: 'research.json',\n content: JSON.stringify(data, null, 2),\n type: 'artifact'\n });\n\n this.logger.info('Research file written', { \n taskId, \n score: data.actionabilityScore,\n hasQuestions: !!data.questions,\n answered: data.answered ?? false,\n });\n }\n\n async readResearch(taskId: string): Promise<ResearchEvaluation | null> {\n try {\n const content = await this.readTaskFile(taskId, 'research.json');\n return content ? JSON.parse(content) as ResearchEvaluation : null;\n } catch (error) {\n this.logger.debug('Failed to parse research.json', { error });\n return null;\n }\n }\n\n async getTaskFiles(taskId: string): Promise<SupportingFile[]> {\n const fileNames = await this.listTaskFiles(taskId);\n const files: SupportingFile[] = [];\n \n for (const fileName of fileNames) {\n const content = await this.readTaskFile(taskId, fileName);\n if (content !== null) {\n // Determine type based on file name\n let type: SupportingFile['type'] = 'reference';\n if (fileName === 'plan.md') type = 'plan';\n else if (fileName === 'context.md') type = 'context';\n else if (fileName === 'requirements.md') type = 'reference';\n else if (fileName.startsWith('output_')) type = 'output';\n \n files.push({\n name: fileName,\n content,\n type,\n created_at: new Date().toISOString() // Could be enhanced with file stats\n });\n }\n }\n \n return files;\n }\n}\n"],"names":["fs"],"mappings":";;;;MAWa,kBAAkB,CAAA;AACrB,IAAA,cAAc;AACd,IAAA,MAAM;IAEd,WAAA,CAAY,cAAsB,EAAE,MAAe,EAAA;AACjD,QAAA,IAAI,CAAC,cAAc,GAAG,cAAc;AACpC,QAAA,IAAI,CAAC,MAAM,GAAG,MAAM,IAAI,IAAI,MAAM,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,CAAC;IAC/E;AAEQ,IAAA,gBAAgB,CAAC,MAAc,EAAA;QACrC,OAAO,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,UAAU,EAAE,MAAM,CAAC;IACtD;IAEQ,eAAe,CAAC,MAAc,EAAE,QAAgB,EAAA;QACtD,OAAO,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,EAAE,QAAQ,CAAC;IACtD;IAEA,MAAM,mBAAmB,CAAC,MAAc,EAAA;QACtC,MAAM,OAAO,GAAG,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC;AAC7C,QAAA,IAAI;AACF,YAAA,MAAMA,QAAE,CAAC,MAAM,CAAC,OAAO,CAAC;QAC1B;AAAE,QAAA,MAAM;AACN,YAAA,MAAMA,QAAE,CAAC,KAAK,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;QAC9C;IACF;AAEA,IAAA,MAAM,aAAa,CAAC,MAAc,EAAE,IAAc,EAAA;AAChD,QAAA,MAAM,IAAI,CAAC,mBAAmB,CAAC,MAAM,CAAC;AACtC,QAAA,MAAM,QAAQ,GAAG,IAAI,CAAC,eAAe,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC;AAExD,QAAA,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,mBAAmB,EAAE;YACrC,QAAQ;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S;qBAC/C,IAAI,QAAQ,KAAK,iBAAiB;oBAAE,IAAI,GAAG,WAAW;AACtD,qBAAA,IAAI,QAAQ,CAAC,UAAU,CAAC,SAAS,CAAC;oBAAE,IAAI,GAAG,QAAQ;gBAExD,KAAK,CAAC,IAAI,CAAC;AACT,oBAAA,IAAI,EAAE,QAAQ;oBACd,OAAO;oBACP,IAAI;oBACJ,UAAU,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;AACrC,iBAAA,CAAC;YACJ;QACF;AAEA,QAAA,OAAO,KAAK;IACd;AACD;;;;"}
|
|
1
|
+
{"version":3,"file":"file-manager.js","sources":["../../src/file-manager.ts"],"sourcesContent":["import { promises as fs } from 'fs';\nimport { join } from 'path';\nimport type { SupportingFile, ResearchEvaluation } from './types.js';\nimport { Logger } from './utils/logger.js';\n\nexport interface TaskFile {\n name: string;\n content: string;\n type: 'plan' | 'context' | 'reference' | 'output' | 'artifact';\n}\n\nexport class PostHogFileManager {\n private repositoryPath: string;\n private logger: Logger;\n\n constructor(repositoryPath: string, logger?: Logger) {\n this.repositoryPath = repositoryPath;\n this.logger = logger || new Logger({ debug: false, prefix: '[FileManager]' });\n }\n\n private getTaskDirectory(taskId: string): string {\n return join(this.repositoryPath, '.posthog', taskId);\n }\n\n private getTaskFilePath(taskId: string, fileName: string): string {\n return join(this.getTaskDirectory(taskId), fileName);\n }\n\n async ensureTaskDirectory(taskId: string): Promise<void> {\n const taskDir = this.getTaskDirectory(taskId);\n try {\n await fs.access(taskDir);\n } catch {\n await fs.mkdir(taskDir, { recursive: true });\n }\n }\n\n async writeTaskFile(taskId: string, file: TaskFile): Promise<void> {\n await this.ensureTaskDirectory(taskId);\n const filePath = this.getTaskFilePath(taskId, file.name);\n\n this.logger.debug('Writing task file', {\n filePath,\n contentLength: file.content.length,\n contentType: typeof file.content\n });\n\n await fs.writeFile(filePath, file.content, 'utf8');\n\n this.logger.debug('File written successfully', { filePath });\n }\n\n async readTaskFile(taskId: string, fileName: string): Promise<string | null> {\n try {\n const filePath = this.getTaskFilePath(taskId, fileName);\n return await fs.readFile(filePath, 'utf8');\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') {\n return null;\n }\n throw error;\n }\n }\n\n async listTaskFiles(taskId: string): Promise<string[]> {\n try {\n const taskDir = this.getTaskDirectory(taskId);\n const files = await fs.readdir(taskDir);\n return files.filter(file => !file.startsWith('.'));\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') {\n return [];\n }\n throw error;\n }\n }\n\n async deleteTaskFile(taskId: string, fileName: string): Promise<void> {\n try {\n const filePath = this.getTaskFilePath(taskId, fileName);\n await fs.unlink(filePath);\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== 'ENOENT') {\n throw error;\n }\n }\n }\n\n async taskDirectoryExists(taskId: string): Promise<boolean> {\n try {\n const taskDir = this.getTaskDirectory(taskId);\n await fs.access(taskDir);\n return true;\n } catch {\n return false;\n }\n }\n\n async cleanupTaskDirectory(taskId: string): Promise<void> {\n try {\n const taskDir = this.getTaskDirectory(taskId);\n await fs.rm(taskDir, { recursive: true, force: true });\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== 'ENOENT') {\n throw error;\n }\n }\n }\n\n // Convenience methods for common file types\n async writePlan(taskId: string, plan: string): Promise<void> {\n this.logger.debug('Writing plan', {\n taskId,\n planLength: plan.length,\n contentPreview: plan.substring(0, 200)\n });\n\n await this.writeTaskFile(taskId, {\n name: 'plan.md',\n content: plan,\n type: 'plan'\n });\n\n this.logger.info('Plan file written', { taskId });\n }\n\n async readPlan(taskId: string): Promise<string | null> {\n return await this.readTaskFile(taskId, 'plan.md');\n }\n\n async writeContext(taskId: string, context: string): Promise<void> {\n await this.writeTaskFile(taskId, {\n name: 'context.md',\n content: context,\n type: 'context'\n });\n }\n\n async readContext(taskId: string): Promise<string | null> {\n return await this.readTaskFile(taskId, 'context.md');\n }\n\n async writeRequirements(taskId: string, requirements: string): Promise<void> {\n await this.writeTaskFile(taskId, {\n name: 'requirements.md',\n content: requirements,\n type: 'reference'\n });\n }\n\n async readRequirements(taskId: string): Promise<string | null> {\n return await this.readTaskFile(taskId, 'requirements.md');\n }\n\n async writeResearch(taskId: string, data: ResearchEvaluation): Promise<void> {\n this.logger.debug('Writing research', {\n taskId,\n score: data.actionabilityScore,\n hasQuestions: !!data.questions,\n questionCount: data.questions?.length ?? 0,\n answered: data.answered ?? false,\n });\n\n await this.writeTaskFile(taskId, {\n name: 'research.json',\n content: JSON.stringify(data, null, 2),\n type: 'artifact'\n });\n\n this.logger.info('Research file written', { \n taskId, \n score: data.actionabilityScore,\n hasQuestions: !!data.questions,\n answered: data.answered ?? false,\n });\n }\n\n async readResearch(taskId: string): Promise<ResearchEvaluation | null> {\n try {\n const content = await this.readTaskFile(taskId, 'research.json');\n return content ? JSON.parse(content) as ResearchEvaluation : null;\n } catch (error) {\n this.logger.debug('Failed to parse research.json', { error });\n return null;\n }\n }\n\n async writeTodos(taskId: string, data: any): Promise<void> {\n this.logger.debug('Writing todos', {\n taskId,\n total: data.metadata?.total ?? 0,\n completed: data.metadata?.completed ?? 0,\n });\n\n await this.writeTaskFile(taskId, {\n name: 'todos.json',\n content: JSON.stringify(data, null, 2),\n type: 'artifact'\n });\n\n this.logger.info('Todos file written', {\n taskId,\n total: data.metadata?.total ?? 0,\n completed: data.metadata?.completed ?? 0,\n });\n }\n\n async readTodos(taskId: string): Promise<any | null> {\n try {\n const content = await this.readTaskFile(taskId, 'todos.json');\n return content ? JSON.parse(content) : null;\n } catch (error) {\n this.logger.debug('Failed to parse todos.json', { error });\n return null;\n }\n }\n\n async getTaskFiles(taskId: string): Promise<SupportingFile[]> {\n const fileNames = await this.listTaskFiles(taskId);\n const files: SupportingFile[] = [];\n \n for (const fileName of fileNames) {\n const content = await this.readTaskFile(taskId, fileName);\n if (content !== null) {\n // Determine type based on file name\n let type: SupportingFile['type'] = 'reference';\n if (fileName === 'plan.md') type = 'plan';\n else if (fileName === 'context.md') type = 'context';\n else if (fileName === 'requirements.md') type = 'reference';\n else if (fileName.startsWith('output_')) type = 'output';\n \n files.push({\n name: fileName,\n content,\n type,\n created_at: new Date().toISOString() // Could be enhanced with file stats\n });\n }\n }\n \n return files;\n }\n}\n"],"names":["fs"],"mappings":";;;;MAWa,kBAAkB,CAAA;AACrB,IAAA,cAAc;AACd,IAAA,MAAM;IAEd,WAAA,CAAY,cAAsB,EAAE,MAAe,EAAA;AACjD,QAAA,IAAI,CAAC,cAAc,GAAG,cAAc;AACpC,QAAA,IAAI,CAAC,MAAM,GAAG,MAAM,IAAI,IAAI,MAAM,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,CAAC;IAC/E;AAEQ,IAAA,gBAAgB,CAAC,MAAc,EAAA;QACrC,OAAO,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,UAAU,EAAE,MAAM,CAAC;IACtD;IAEQ,eAAe,CAAC,MAAc,EAAE,QAAgB,EAAA;QACtD,OAAO,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,EAAE,QAAQ,CAAC;IACtD;IAEA,MAAM,mBAAmB,CAAC,MAAc,EAAA;QACtC,MAAM,OAAO,GAAG,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC;AAC7C,QAAA,IAAI;AACF,YAAA,MAAMA,QAAE,CAAC,MAAM,CAAC,OAAO,CAAC;QAC1B;AAAE,QAAA,MAAM;AACN,YAAA,MAAMA,QAAE,CAAC,KAAK,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;QAC9C;IACF;AAEA,IAAA,MAAM,aAAa,CAAC,MAAc,EAAE,IAAc,EAAA;AAChD,QAAA,MAAM,IAAI,CAAC,mBAAmB,CAAC,MAAM,CAAC;AACtC,QAAA,MAAM,QAAQ,GAAG,IAAI,CAAC,eAAe,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC;AAExD,QAAA,IAAI,CAAC,M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e;IAW7B;;;OAGG;IACH,OAAO,CAAC,kBAAkB;IA+B1B;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAsBxB;;OAEG;YACW,oBAAoB;IAqDlC;;;OAGG;YACW,qBAAqB;IAgC7B,mBAAmB,CAAC,IAAI,EAAE,IAAI,EAAE,cAAc,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IA2DzE,mBAAmB,CAAC,IAAI,EAAE,IAAI,EAAE,cAAc,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IA4EzE,oBAAoB,CAAC,IAAI,EAAE,IAAI,EAAE,cAAc,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAkGjF"}
|
|
@@ -307,18 +307,43 @@ class PromptBuilder {
|
|
|
307
307
|
try {
|
|
308
308
|
const taskFiles = await this.getTaskFiles(task.id);
|
|
309
309
|
const hasPlan = taskFiles.some((f) => f.type === 'plan');
|
|
310
|
+
const todosFile = taskFiles.find((f) => f.name === 'todos.json');
|
|
310
311
|
if (taskFiles.length > 0) {
|
|
311
312
|
prompt += '\n<context>\n';
|
|
312
313
|
for (const file of taskFiles) {
|
|
313
314
|
if (file.type === 'plan') {
|
|
314
315
|
prompt += `<plan>\n${file.content}\n</plan>\n`;
|
|
315
316
|
}
|
|
317
|
+
else if (file.name === 'todos.json') {
|
|
318
|
+
// skip - we do this below
|
|
319
|
+
continue;
|
|
320
|
+
}
|
|
316
321
|
else {
|
|
317
322
|
prompt += `<file name="${file.name}" type="${file.type}">\n${file.content}\n</file>\n`;
|
|
318
323
|
}
|
|
319
324
|
}
|
|
320
325
|
prompt += '</context>\n';
|
|
321
326
|
}
|
|
327
|
+
// Add todos context if resuming work
|
|
328
|
+
if (todosFile) {
|
|
329
|
+
try {
|
|
330
|
+
const todos = JSON.parse(todosFile.content);
|
|
331
|
+
if (todos.items && todos.items.length > 0) {
|
|
332
|
+
prompt += '\n<previous_todos>\n';
|
|
333
|
+
prompt += 'You previously created the following todo list for this task:\n\n';
|
|
334
|
+
for (const item of todos.items) {
|
|
335
|
+
const statusIcon = item.status === 'completed' ? '✓' : item.status === 'in_progress' ? '▶' : '○';
|
|
336
|
+
prompt += `${statusIcon} [${item.status}] ${item.content}\n`;
|
|
337
|
+
}
|
|
338
|
+
prompt += `\nProgress: ${todos.metadata.completed}/${todos.metadata.total} completed\n`;
|
|
339
|
+
prompt += '\nYou can reference this list when resuming work or create an updated list as needed.\n';
|
|
340
|
+
prompt += '</previous_todos>\n';
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
catch (error) {
|
|
344
|
+
this.logger.debug('Failed to parse todos.json for context', { error });
|
|
345
|
+
}
|
|
346
|
+
}
|
|
322
347
|
prompt += '\n<instructions>\n';
|
|
323
348
|
if (hasPlan) {
|
|
324
349
|
prompt += 'Implement the changes described in the execution plan. Follow the plan step-by-step and make the necessary file modifications.\n';
|