@posthog/agent 1.24.0 → 1.24.2
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/LICENSE +33 -0
- package/dist/index.d.ts +11 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/src/adapters/claude/claude-adapter.d.ts +3 -3
- package/dist/src/adapters/claude/claude-adapter.d.ts.map +1 -1
- package/dist/src/adapters/claude/claude-adapter.js +111 -156
- package/dist/src/adapters/claude/claude-adapter.js.map +1 -1
- package/dist/src/adapters/claude/tool-mapper.d.ts +1 -1
- package/dist/src/adapters/claude/tool-mapper.d.ts.map +1 -1
- package/dist/src/adapters/claude/tool-mapper.js.map +1 -1
- package/dist/src/adapters/types.d.ts +1 -1
- package/dist/src/adapters/types.d.ts.map +1 -1
- package/dist/src/agent.d.ts +7 -7
- package/dist/src/agent.d.ts.map +1 -1
- package/dist/src/agent.js +85 -143
- package/dist/src/agent.js.map +1 -1
- package/dist/src/agents/execution.js.map +1 -1
- package/dist/src/agents/planning.js.map +1 -1
- package/dist/src/agents/research.js.map +1 -1
- package/dist/src/file-manager.d.ts +4 -4
- package/dist/src/file-manager.d.ts.map +1 -1
- package/dist/src/file-manager.js +58 -59
- package/dist/src/file-manager.js.map +1 -1
- package/dist/src/git-manager.d.ts +1 -1
- package/dist/src/git-manager.d.ts.map +1 -1
- package/dist/src/git-manager.js +70 -87
- package/dist/src/git-manager.js.map +1 -1
- package/dist/src/posthog-api.d.ts +3 -2
- package/dist/src/posthog-api.d.ts.map +1 -1
- package/dist/src/posthog-api.js +22 -22
- package/dist/src/posthog-api.js.map +1 -1
- package/dist/src/prompt-builder.d.ts +3 -3
- package/dist/src/prompt-builder.d.ts.map +1 -1
- package/dist/src/prompt-builder.js +93 -123
- package/dist/src/prompt-builder.js.map +1 -1
- package/dist/src/task-manager.d.ts +4 -4
- package/dist/src/task-manager.d.ts.map +1 -1
- package/dist/src/task-manager.js +18 -19
- package/dist/src/task-manager.js.map +1 -1
- package/dist/src/task-progress-reporter.d.ts +4 -3
- package/dist/src/task-progress-reporter.d.ts.map +1 -1
- package/dist/src/task-progress-reporter.js +54 -59
- package/dist/src/task-progress-reporter.js.map +1 -1
- package/dist/src/template-manager.d.ts +1 -1
- package/dist/src/template-manager.d.ts.map +1 -1
- package/dist/src/template-manager.js +28 -30
- package/dist/src/template-manager.js.map +1 -1
- package/dist/src/todo-manager.d.ts +3 -3
- package/dist/src/todo-manager.d.ts.map +1 -1
- package/dist/src/todo-manager.js +24 -29
- package/dist/src/todo-manager.js.map +1 -1
- package/dist/src/tools/registry.d.ts +1 -1
- package/dist/src/tools/registry.js +60 -60
- package/dist/src/tools/registry.js.map +1 -1
- package/dist/src/tools/types.d.ts +31 -31
- package/dist/src/types.d.ts +33 -33
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/types.js.map +1 -1
- package/dist/src/utils/logger.d.ts +4 -4
- package/dist/src/utils/logger.d.ts.map +1 -1
- package/dist/src/utils/logger.js +8 -8
- package/dist/src/utils/logger.js.map +1 -1
- package/dist/src/workflow/config.d.ts +1 -1
- package/dist/src/workflow/config.d.ts.map +1 -1
- package/dist/src/workflow/config.js +18 -18
- package/dist/src/workflow/config.js.map +1 -1
- package/dist/src/workflow/steps/build.d.ts +1 -1
- package/dist/src/workflow/steps/build.d.ts.map +1 -1
- package/dist/src/workflow/steps/build.js +38 -46
- package/dist/src/workflow/steps/build.js.map +1 -1
- package/dist/src/workflow/steps/finalize.d.ts +1 -1
- package/dist/src/workflow/steps/finalize.d.ts.map +1 -1
- package/dist/src/workflow/steps/finalize.js +48 -54
- package/dist/src/workflow/steps/finalize.js.map +1 -1
- package/dist/src/workflow/steps/plan.d.ts +1 -1
- package/dist/src/workflow/steps/plan.d.ts.map +1 -1
- package/dist/src/workflow/steps/plan.js +46 -58
- package/dist/src/workflow/steps/plan.js.map +1 -1
- package/dist/src/workflow/steps/research.d.ts +1 -1
- package/dist/src/workflow/steps/research.d.ts.map +1 -1
- package/dist/src/workflow/steps/research.js +56 -68
- package/dist/src/workflow/steps/research.js.map +1 -1
- package/dist/src/workflow/types.d.ts +12 -12
- package/dist/src/workflow/types.d.ts.map +1 -1
- package/dist/src/workflow/utils.d.ts +1 -1
- package/dist/src/workflow/utils.d.ts.map +1 -1
- package/dist/src/workflow/utils.js +4 -7
- package/dist/src/workflow/utils.js.map +1 -1
- package/package.json +6 -6
- package/src/adapters/claude/claude-adapter.ts +168 -220
- package/src/adapters/claude/tool-mapper.ts +2 -2
- package/src/adapters/types.ts +1 -1
- package/src/agent.ts +444 -579
- package/src/agents/execution.ts +1 -1
- package/src/agents/planning.ts +1 -1
- package/src/agents/research.ts +1 -0
- package/src/file-manager.ts +63 -64
- package/src/git-manager.ts +88 -144
- package/src/posthog-api.ts +82 -122
- package/src/prompt-builder.ts +135 -180
- package/src/task-manager.ts +30 -38
- package/src/task-progress-reporter.ts +59 -70
- package/src/template-manager.ts +45 -98
- package/src/todo-manager.ts +30 -35
- package/src/tools/registry.ts +62 -62
- package/src/tools/types.ts +36 -36
- package/src/types.ts +71 -93
- package/src/utils/logger.ts +56 -62
- package/src/workflow/config.ts +48 -48
- package/src/workflow/steps/build.ts +113 -122
- package/src/workflow/steps/finalize.ts +182 -214
- package/src/workflow/steps/plan.ts +131 -151
- package/src/workflow/steps/research.ts +186 -205
- package/src/workflow/types.ts +36 -38
- package/src/workflow/utils.ts +34 -37
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-mapper.d.ts","sourceRoot":"","sources":["../../../../src/adapters/claude/tool-mapper.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"tool-mapper.d.ts","sourceRoot":"","sources":["../../../../src/adapters/claude/tool-mapper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAGrE;;;GAGG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,QAAQ,CAAsB;IAEtC;;;OAGG;IACH,cAAc,CAAC,KAAK,EAAE,aAAa,GAAG,aAAa;IAcnD;;;OAGG;IACH,gBAAgB,CAAC,KAAK,EAAE,eAAe,GAAG,eAAe;CAa1D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-mapper.js","sources":["../../../../src/adapters/claude/tool-mapper.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"tool-mapper.js","sources":["../../../../src/adapters/claude/tool-mapper.ts"],"sourcesContent":["import type { ToolCallEvent, ToolResultEvent } from '../../types.js';\nimport { ToolRegistry } from '../../tools/registry.js';\n\n/**\n * Maps Claude tool names to our tool type system.\n * Enriches tool events with metadata for better UI consumption.\n */\nexport class ClaudeToolMapper {\n private registry = new ToolRegistry();\n\n /**\n * Enrich a tool call event with tool metadata.\n * Looks up the tool definition and adds it to the event.\n */\n enrichToolCall(event: ToolCallEvent): ToolCallEvent {\n const tool = this.registry.get(event.toolName);\n if (!tool) {\n // Tool not recognized, return as-is\n return event;\n }\n\n return {\n ...event,\n tool,\n category: tool.category,\n };\n }\n\n /**\n * Enrich a tool result event with tool metadata.\n * Looks up the tool definition and adds it to the event.\n */\n enrichToolResult(event: ToolResultEvent): ToolResultEvent {\n const tool = this.registry.get(event.toolName);\n if (!tool) {\n // Tool not recognized, return as-is\n return event;\n }\n\n return {\n ...event,\n tool,\n category: tool.category,\n };\n }\n}\n"],"names":[],"mappings":";;AAGA;;;AAGG;MACU,gBAAgB,CAAA;AACnB,IAAA,QAAQ,GAAG,IAAI,YAAY,EAAE;AAErC;;;AAGG;AACH,IAAA,cAAc,CAAC,KAAoB,EAAA;AACjC,QAAA,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC;QAC9C,IAAI,CAAC,IAAI,EAAE;;AAET,YAAA,OAAO,KAAK;QACd;QAEA,OAAO;AACL,YAAA,GAAG,KAAK;YACR,IAAI;YACJ,QAAQ,EAAE,IAAI,CAAC,QAAQ;SACxB;IACH;AAEA;;;AAGG;AACH,IAAA,gBAAgB,CAAC,KAAsB,EAAA;AACrC,QAAA,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC;QAC9C,IAAI,CAAC,IAAI,EAAE;;AAET,YAAA,OAAO,KAAK;QACd;QAEA,OAAO;AACL,YAAA,GAAG,KAAK;YACR,IAAI;YACJ,QAAQ,EAAE,IAAI,CAAC,QAAQ;SACxB;IACH;AACD;;;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AgentEvent,
|
|
1
|
+
import type { AgentEvent, StatusEvent, ArtifactEvent } from '../types.js';
|
|
2
2
|
/**
|
|
3
3
|
* Provider adapter interface for transforming provider-specific messages
|
|
4
4
|
* into our standardized AgentEvent format.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/adapters/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,
|
|
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,EAAE,CAAC;IAE7C;;;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"}
|
package/dist/src/agent.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import type { Task, ExecutionResult, AgentConfig, CanUseTool } from './types.js';
|
|
2
|
+
import { PostHogAPIClient } from './posthog-api.js';
|
|
3
3
|
export declare class Agent {
|
|
4
4
|
private workingDirectory;
|
|
5
5
|
private onEvent?;
|
|
@@ -24,10 +24,10 @@ export declare class Agent {
|
|
|
24
24
|
* Configure LLM gateway environment variables for Claude Code CLI
|
|
25
25
|
*/
|
|
26
26
|
private _configureLlmGateway;
|
|
27
|
-
runTask(taskOrId: Task | string, options?: import(
|
|
27
|
+
runTask(taskOrId: Task | string, options?: import('./types.js').TaskExecutionOptions): Promise<void>;
|
|
28
28
|
run(prompt: string, options?: {
|
|
29
29
|
repositoryPath?: string;
|
|
30
|
-
permissionMode?: import(
|
|
30
|
+
permissionMode?: import('./types.js').PermissionMode;
|
|
31
31
|
queryOverrides?: Record<string, any>;
|
|
32
32
|
canUseTool?: CanUseTool;
|
|
33
33
|
}): Promise<ExecutionResult>;
|
|
@@ -38,7 +38,7 @@ export declare class Agent {
|
|
|
38
38
|
organization?: string;
|
|
39
39
|
origin_product?: string;
|
|
40
40
|
}): Promise<Task[]>;
|
|
41
|
-
writeTaskFile(taskId: string, fileName: string, content: string, type?:
|
|
41
|
+
writeTaskFile(taskId: string, fileName: string, content: string, type?: 'plan' | 'context' | 'reference' | 'output'): Promise<void>;
|
|
42
42
|
readTaskFile(taskId: string, fileName: string): Promise<string | null>;
|
|
43
43
|
getTaskFiles(taskId: string): Promise<any[]>;
|
|
44
44
|
writePlan(taskId: string, plan: string): Promise<void>;
|
|
@@ -57,6 +57,6 @@ export declare class Agent {
|
|
|
57
57
|
private ensurePullRequest;
|
|
58
58
|
private emitEvent;
|
|
59
59
|
}
|
|
60
|
-
export
|
|
61
|
-
export {
|
|
60
|
+
export { PermissionMode } from './types.js';
|
|
61
|
+
export type { Task, SupportingFile, ExecutionResult, AgentConfig } from './types.js';
|
|
62
62
|
//# sourceMappingURL=agent.d.ts.map
|
package/dist/src/agent.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../src/agent.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../src/agent.ts"],"names":[],"mappings":"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"}
|
package/dist/src/agent.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { query } from '@anthropic-ai/claude-agent-sdk';
|
|
2
|
-
import {
|
|
2
|
+
import { TaskManager } from './task-manager.js';
|
|
3
|
+
import { PostHogAPIClient } from './posthog-api.js';
|
|
3
4
|
import { PostHogFileManager } from './file-manager.js';
|
|
4
5
|
import { GitManager } from './git-manager.js';
|
|
5
|
-
import { PostHogAPIClient } from './posthog-api.js';
|
|
6
|
-
import { PromptBuilder } from './prompt-builder.js';
|
|
7
|
-
import { TaskManager } from './task-manager.js';
|
|
8
|
-
import { TaskProgressReporter } from './task-progress-reporter.js';
|
|
9
6
|
import { TemplateManager } from './template-manager.js';
|
|
7
|
+
import { ClaudeAdapter } from './adapters/claude/claude-adapter.js';
|
|
10
8
|
import { Logger } from './utils/logger.js';
|
|
9
|
+
import { PromptBuilder } from './prompt-builder.js';
|
|
10
|
+
import { TaskProgressReporter } from './task-progress-reporter.js';
|
|
11
11
|
import { TASK_WORKFLOW } from './workflow/config.js';
|
|
12
12
|
export { PermissionMode } from './types.js';
|
|
13
13
|
|
|
@@ -32,34 +32,34 @@ class Agent {
|
|
|
32
32
|
this.canUseTool = config.canUseTool;
|
|
33
33
|
this.debug = config.debug || false;
|
|
34
34
|
// Build default PostHog MCP server configuration
|
|
35
|
-
const posthogMcpUrl = config.posthogMcpUrl
|
|
36
|
-
process.env.POSTHOG_MCP_URL
|
|
37
|
-
|
|
35
|
+
const posthogMcpUrl = config.posthogMcpUrl
|
|
36
|
+
|| process.env.POSTHOG_MCP_URL
|
|
37
|
+
|| 'https://mcp.posthog.com/mcp';
|
|
38
38
|
// Add auth if API key provided
|
|
39
39
|
const headers = {};
|
|
40
40
|
if (config.posthogApiKey) {
|
|
41
|
-
headers
|
|
41
|
+
headers['Authorization'] = `Bearer ${config.posthogApiKey}`;
|
|
42
42
|
}
|
|
43
43
|
const defaultMcpServers = {
|
|
44
44
|
posthog: {
|
|
45
|
-
type:
|
|
45
|
+
type: 'http',
|
|
46
46
|
url: posthogMcpUrl,
|
|
47
47
|
...(Object.keys(headers).length > 0 ? { headers } : {}),
|
|
48
|
-
}
|
|
48
|
+
}
|
|
49
49
|
};
|
|
50
50
|
// Merge default PostHog MCP with user-provided servers (user config takes precedence)
|
|
51
51
|
this.mcpServers = {
|
|
52
52
|
...defaultMcpServers,
|
|
53
|
-
...config.mcpServers
|
|
53
|
+
...config.mcpServers
|
|
54
54
|
};
|
|
55
|
-
this.logger = new Logger({ debug: this.debug, prefix:
|
|
55
|
+
this.logger = new Logger({ debug: this.debug, prefix: '[PostHog Agent]' });
|
|
56
56
|
this.taskManager = new TaskManager();
|
|
57
57
|
// Hardcode Claude adapter for now - extensible for other providers later
|
|
58
58
|
this.adapter = new ClaudeAdapter();
|
|
59
|
-
this.fileManager = new PostHogFileManager(this.workingDirectory, this.logger.child(
|
|
59
|
+
this.fileManager = new PostHogFileManager(this.workingDirectory, this.logger.child('FileManager'));
|
|
60
60
|
this.gitManager = new GitManager({
|
|
61
61
|
repositoryPath: this.workingDirectory,
|
|
62
|
-
logger: this.logger.child(
|
|
62
|
+
logger: this.logger.child('GitManager')
|
|
63
63
|
// TODO: Add author config from environment or config
|
|
64
64
|
});
|
|
65
65
|
this.templateManager = new TemplateManager();
|
|
@@ -74,7 +74,7 @@ class Agent {
|
|
|
74
74
|
getTaskFiles: (taskId) => this.getTaskFiles(taskId),
|
|
75
75
|
generatePlanTemplate: (vars) => this.templateManager.generatePlan(vars),
|
|
76
76
|
posthogClient: this.posthogAPI,
|
|
77
|
-
logger: this.logger.child(
|
|
77
|
+
logger: this.logger.child('PromptBuilder')
|
|
78
78
|
});
|
|
79
79
|
this.progressReporter = new TaskProgressReporter(this.posthogAPI, this.logger);
|
|
80
80
|
}
|
|
@@ -98,32 +98,24 @@ class Agent {
|
|
|
98
98
|
process.env.ANTHROPIC_BASE_URL = gatewayUrl;
|
|
99
99
|
process.env.ANTHROPIC_AUTH_TOKEN = apiKey;
|
|
100
100
|
this.ensureOpenAIGatewayEnv(gatewayUrl, apiKey);
|
|
101
|
-
this.logger.debug(
|
|
101
|
+
this.logger.debug('Configured LLM gateway', { gatewayUrl });
|
|
102
102
|
}
|
|
103
103
|
catch (error) {
|
|
104
|
-
this.logger.error(
|
|
104
|
+
this.logger.error('Failed to configure LLM gateway', error);
|
|
105
105
|
throw error;
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
108
|
// Adaptive task execution orchestrated via workflow steps
|
|
109
109
|
async runTask(taskOrId, options = {}) {
|
|
110
110
|
await this._configureLlmGateway();
|
|
111
|
-
const task = typeof taskOrId ===
|
|
111
|
+
const task = typeof taskOrId === 'string' ? await this.fetchTask(taskOrId) : taskOrId;
|
|
112
112
|
const cwd = options.repositoryPath || this.workingDirectory;
|
|
113
113
|
const isCloudMode = options.isCloudMode ?? false;
|
|
114
114
|
const taskSlug = task.slug || task.id;
|
|
115
|
-
this.logger.info(
|
|
116
|
-
taskId: task.id,
|
|
117
|
-
taskSlug,
|
|
118
|
-
isCloudMode,
|
|
119
|
-
});
|
|
115
|
+
this.logger.info('Starting adaptive task execution', { taskId: task.id, taskSlug, isCloudMode });
|
|
120
116
|
// Initialize progress reporter for task run tracking (needed for PR attachment)
|
|
121
|
-
await this.progressReporter.start(task.id, {
|
|
122
|
-
|
|
123
|
-
});
|
|
124
|
-
this.emitEvent(this.adapter.createStatusEvent("run_started", {
|
|
125
|
-
runId: this.progressReporter.runId,
|
|
126
|
-
}));
|
|
117
|
+
await this.progressReporter.start(task.id, { totalSteps: TASK_WORKFLOW.length });
|
|
118
|
+
this.emitEvent(this.adapter.createStatusEvent('run_started', { runId: this.progressReporter.runId }));
|
|
127
119
|
await this.prepareTaskBranch(taskSlug, isCloudMode);
|
|
128
120
|
let taskError;
|
|
129
121
|
try {
|
|
@@ -154,20 +146,16 @@ class Agent {
|
|
|
154
146
|
if (shouldCreatePR) {
|
|
155
147
|
await this.ensurePullRequest(task, workflowContext.stepResults);
|
|
156
148
|
}
|
|
157
|
-
this.logger.info(
|
|
158
|
-
this.emitEvent(this.adapter.createStatusEvent(
|
|
149
|
+
this.logger.info('Task execution complete', { taskId: task.id });
|
|
150
|
+
this.emitEvent(this.adapter.createStatusEvent('task_complete', { taskId: task.id }));
|
|
159
151
|
}
|
|
160
152
|
catch (error) {
|
|
161
153
|
taskError = error instanceof Error ? error : new Error(String(error));
|
|
162
|
-
this.logger.error(
|
|
163
|
-
taskId: task.id,
|
|
164
|
-
error: taskError.message,
|
|
165
|
-
});
|
|
154
|
+
this.logger.error('Task execution failed', { taskId: task.id, error: taskError.message });
|
|
166
155
|
}
|
|
167
156
|
finally {
|
|
168
157
|
if (taskError) {
|
|
169
158
|
await this.progressReporter.fail(taskError);
|
|
170
|
-
// biome-ignore lint/correctness/noUnsafeFinally: we actually want to throw the error
|
|
171
159
|
throw taskError;
|
|
172
160
|
}
|
|
173
161
|
else {
|
|
@@ -195,30 +183,24 @@ class Agent {
|
|
|
195
183
|
options: { ...baseOptions, ...(options.queryOverrides || {}) },
|
|
196
184
|
});
|
|
197
185
|
const results = [];
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
this.emitEvent(event);
|
|
206
|
-
}
|
|
207
|
-
results.push(message);
|
|
186
|
+
for await (const message of response) {
|
|
187
|
+
this.logger.debug('Received message in direct run', message);
|
|
188
|
+
// Emit raw SDK event
|
|
189
|
+
this.emitEvent(this.adapter.createRawSDKEvent(message));
|
|
190
|
+
const transformedEvents = this.adapter.transform(message);
|
|
191
|
+
for (const event of transformedEvents) {
|
|
192
|
+
this.emitEvent(event);
|
|
208
193
|
}
|
|
209
|
-
|
|
210
|
-
catch (error) {
|
|
211
|
-
this.logger.error("Error during direct run", error);
|
|
212
|
-
throw error;
|
|
194
|
+
results.push(message);
|
|
213
195
|
}
|
|
214
196
|
return { results };
|
|
215
197
|
}
|
|
216
198
|
// PostHog task operations
|
|
217
199
|
async fetchTask(taskId) {
|
|
218
|
-
this.logger.debug(
|
|
200
|
+
this.logger.debug('Fetching task from PostHog', { taskId });
|
|
219
201
|
if (!this.posthogAPI) {
|
|
220
|
-
const error = new Error(
|
|
221
|
-
this.logger.error(
|
|
202
|
+
const error = new Error('PostHog API not configured. Provide posthogApiUrl and posthogApiKey in constructor.');
|
|
203
|
+
this.logger.error('PostHog API not configured', error);
|
|
222
204
|
throw error;
|
|
223
205
|
}
|
|
224
206
|
return this.posthogAPI.fetchTask(taskId);
|
|
@@ -228,76 +210,60 @@ class Agent {
|
|
|
228
210
|
}
|
|
229
211
|
async listTasks(filters) {
|
|
230
212
|
if (!this.posthogAPI) {
|
|
231
|
-
throw new Error(
|
|
213
|
+
throw new Error('PostHog API not configured. Provide posthogApiUrl and posthogApiKey in constructor.');
|
|
232
214
|
}
|
|
233
215
|
return this.posthogAPI.listTasks(filters);
|
|
234
216
|
}
|
|
235
217
|
// File system operations for task artifacts
|
|
236
|
-
async writeTaskFile(taskId, fileName, content, type =
|
|
237
|
-
this.logger.debug(
|
|
238
|
-
|
|
239
|
-
fileName,
|
|
240
|
-
type,
|
|
241
|
-
contentLength: content.length,
|
|
242
|
-
});
|
|
243
|
-
await this.fileManager.writeTaskFile(taskId, {
|
|
244
|
-
name: fileName,
|
|
245
|
-
content,
|
|
246
|
-
type,
|
|
247
|
-
});
|
|
218
|
+
async writeTaskFile(taskId, fileName, content, type = 'reference') {
|
|
219
|
+
this.logger.debug('Writing task file', { taskId, fileName, type, contentLength: content.length });
|
|
220
|
+
await this.fileManager.writeTaskFile(taskId, { name: fileName, content, type });
|
|
248
221
|
}
|
|
249
222
|
async readTaskFile(taskId, fileName) {
|
|
250
|
-
this.logger.debug(
|
|
223
|
+
this.logger.debug('Reading task file', { taskId, fileName });
|
|
251
224
|
return await this.fileManager.readTaskFile(taskId, fileName);
|
|
252
225
|
}
|
|
253
226
|
async getTaskFiles(taskId) {
|
|
254
|
-
this.logger.debug(
|
|
227
|
+
this.logger.debug('Getting task files', { taskId });
|
|
255
228
|
const files = await this.fileManager.getTaskFiles(taskId);
|
|
256
|
-
this.logger.debug(
|
|
229
|
+
this.logger.debug('Found task files', { taskId, fileCount: files.length });
|
|
257
230
|
return files;
|
|
258
231
|
}
|
|
259
232
|
async writePlan(taskId, plan) {
|
|
260
|
-
this.logger.info(
|
|
233
|
+
this.logger.info('Writing plan', { taskId, planLength: plan.length });
|
|
261
234
|
await this.fileManager.writePlan(taskId, plan);
|
|
262
235
|
}
|
|
263
236
|
async readPlan(taskId) {
|
|
264
|
-
this.logger.debug(
|
|
237
|
+
this.logger.debug('Reading plan', { taskId });
|
|
265
238
|
return await this.fileManager.readPlan(taskId);
|
|
266
239
|
}
|
|
267
240
|
// Git operations for task execution
|
|
268
241
|
async createPlanningBranch(taskId) {
|
|
269
|
-
this.logger.info(
|
|
242
|
+
this.logger.info('Creating planning branch', { taskId });
|
|
270
243
|
const branchName = await this.gitManager.createTaskPlanningBranch(taskId);
|
|
271
|
-
this.logger.debug(
|
|
244
|
+
this.logger.debug('Planning branch created', { taskId, branchName });
|
|
272
245
|
return branchName;
|
|
273
246
|
}
|
|
274
247
|
async commitPlan(taskId, taskTitle) {
|
|
275
|
-
this.logger.info(
|
|
248
|
+
this.logger.info('Committing plan', { taskId, taskTitle });
|
|
276
249
|
const commitHash = await this.gitManager.commitPlan(taskId, taskTitle);
|
|
277
|
-
this.logger.debug(
|
|
250
|
+
this.logger.debug('Plan committed', { taskId, commitHash });
|
|
278
251
|
return commitHash;
|
|
279
252
|
}
|
|
280
253
|
async createImplementationBranch(taskId, planningBranchName) {
|
|
281
|
-
this.logger.info(
|
|
282
|
-
taskId,
|
|
283
|
-
fromBranch: planningBranchName,
|
|
284
|
-
});
|
|
254
|
+
this.logger.info('Creating implementation branch', { taskId, fromBranch: planningBranchName });
|
|
285
255
|
const branchName = await this.gitManager.createTaskImplementationBranch(taskId, planningBranchName);
|
|
286
|
-
this.logger.debug(
|
|
256
|
+
this.logger.debug('Implementation branch created', { taskId, branchName });
|
|
287
257
|
return branchName;
|
|
288
258
|
}
|
|
289
259
|
async commitImplementation(taskId, taskTitle, planSummary) {
|
|
290
|
-
this.logger.info(
|
|
260
|
+
this.logger.info('Committing implementation', { taskId, taskTitle });
|
|
291
261
|
const commitHash = await this.gitManager.commitImplementation(taskId, taskTitle, planSummary);
|
|
292
|
-
this.logger.debug(
|
|
262
|
+
this.logger.debug('Implementation committed', { taskId, commitHash });
|
|
293
263
|
return commitHash;
|
|
294
264
|
}
|
|
295
265
|
async createPullRequest(taskId, branchName, taskTitle, taskDescription, customBody) {
|
|
296
|
-
this.logger.info(
|
|
297
|
-
taskId,
|
|
298
|
-
branchName,
|
|
299
|
-
taskTitle,
|
|
300
|
-
});
|
|
266
|
+
this.logger.info('Creating pull request', { taskId, branchName, taskTitle });
|
|
301
267
|
const defaultBody = `## Task Details
|
|
302
268
|
**Task ID**: ${taskId}
|
|
303
269
|
**Description**: ${taskDescription}
|
|
@@ -308,50 +274,40 @@ This PR implements the changes described in the task.
|
|
|
308
274
|
Generated by PostHog Agent`;
|
|
309
275
|
const prBody = customBody || defaultBody;
|
|
310
276
|
const prUrl = await this.gitManager.createPullRequest(branchName, taskTitle, prBody);
|
|
311
|
-
this.logger.info(
|
|
277
|
+
this.logger.info('Pull request created', { taskId, prUrl });
|
|
312
278
|
return prUrl;
|
|
313
279
|
}
|
|
314
280
|
async attachPullRequestToTask(taskId, prUrl, branchName) {
|
|
315
|
-
this.logger.info(
|
|
281
|
+
this.logger.info('Attaching PR to task run', { taskId, prUrl, branchName });
|
|
316
282
|
if (!this.posthogAPI || !this.progressReporter.runId) {
|
|
317
|
-
const error = new Error(
|
|
318
|
-
this.logger.error(
|
|
283
|
+
const error = new Error('PostHog API not configured or no active run. Cannot attach PR to task.');
|
|
284
|
+
this.logger.error('PostHog API not configured', error);
|
|
319
285
|
throw error;
|
|
320
286
|
}
|
|
321
287
|
const updates = {
|
|
322
|
-
output: { pr_url: prUrl }
|
|
288
|
+
output: { pr_url: prUrl }
|
|
323
289
|
};
|
|
324
290
|
if (branchName) {
|
|
325
291
|
updates.branch = branchName;
|
|
326
292
|
}
|
|
327
293
|
await this.posthogAPI.updateTaskRun(taskId, this.progressReporter.runId, updates);
|
|
328
|
-
this.logger.debug(
|
|
329
|
-
taskId,
|
|
330
|
-
runId: this.progressReporter.runId,
|
|
331
|
-
prUrl,
|
|
332
|
-
});
|
|
294
|
+
this.logger.debug('PR attached to task run', { taskId, runId: this.progressReporter.runId, prUrl });
|
|
333
295
|
}
|
|
334
296
|
async updateTaskBranch(taskId, branchName) {
|
|
335
|
-
this.logger.info(
|
|
297
|
+
this.logger.info('Updating task run branch', { taskId, branchName });
|
|
336
298
|
if (!this.posthogAPI || !this.progressReporter.runId) {
|
|
337
|
-
const error = new Error(
|
|
338
|
-
this.logger.error(
|
|
299
|
+
const error = new Error('PostHog API not configured or no active run. Cannot update branch.');
|
|
300
|
+
this.logger.error('PostHog API not configured', error);
|
|
339
301
|
throw error;
|
|
340
302
|
}
|
|
341
|
-
await this.posthogAPI.updateTaskRun(taskId, this.progressReporter.runId, {
|
|
342
|
-
|
|
343
|
-
});
|
|
344
|
-
this.logger.debug("Task run branch updated", {
|
|
345
|
-
taskId,
|
|
346
|
-
runId: this.progressReporter.runId,
|
|
347
|
-
branchName,
|
|
348
|
-
});
|
|
303
|
+
await this.posthogAPI.updateTaskRun(taskId, this.progressReporter.runId, { branch: branchName });
|
|
304
|
+
this.logger.debug('Task run branch updated', { taskId, runId: this.progressReporter.runId, branchName });
|
|
349
305
|
}
|
|
350
306
|
// Execution management
|
|
351
307
|
cancelTask(taskId) {
|
|
352
308
|
// Find the execution for this task and cancel it
|
|
353
|
-
for (const [executionId, execution] of this.taskManager
|
|
354
|
-
if (execution.taskId === taskId && execution.status ===
|
|
309
|
+
for (const [executionId, execution] of this.taskManager['executionStates']) {
|
|
310
|
+
if (execution.taskId === taskId && execution.status === 'running') {
|
|
355
311
|
this.taskManager.cancelExecution(executionId);
|
|
356
312
|
break;
|
|
357
313
|
}
|
|
@@ -359,7 +315,7 @@ Generated by PostHog Agent`;
|
|
|
359
315
|
}
|
|
360
316
|
getTaskExecutionStatus(taskId) {
|
|
361
317
|
// Find the execution for this task
|
|
362
|
-
for (const execution of this.taskManager
|
|
318
|
+
for (const execution of this.taskManager['executionStates'].values()) {
|
|
363
319
|
if (execution.taskId === taskId) {
|
|
364
320
|
return execution.status;
|
|
365
321
|
}
|
|
@@ -368,21 +324,17 @@ Generated by PostHog Agent`;
|
|
|
368
324
|
}
|
|
369
325
|
async prepareTaskBranch(taskSlug, isCloudMode) {
|
|
370
326
|
if (await this.gitManager.hasChanges()) {
|
|
371
|
-
throw new Error(
|
|
327
|
+
throw new Error('Cannot start task with uncommitted changes. Please commit or stash your changes first.');
|
|
372
328
|
}
|
|
373
329
|
await this.gitManager.resetToDefaultBranchIfNeeded();
|
|
374
330
|
const existingBranch = await this.gitManager.getTaskBranch(taskSlug);
|
|
375
331
|
if (!existingBranch) {
|
|
376
332
|
const branchName = await this.gitManager.createTaskBranch(taskSlug);
|
|
377
|
-
this.emitEvent(this.adapter.createStatusEvent(
|
|
378
|
-
branch: branchName,
|
|
379
|
-
}));
|
|
333
|
+
this.emitEvent(this.adapter.createStatusEvent('branch_created', { branch: branchName }));
|
|
380
334
|
await this.gitManager.addAllPostHogFiles();
|
|
381
335
|
// Only commit if there are changes or we're in cloud mode
|
|
382
336
|
if (isCloudMode) {
|
|
383
|
-
await this.gitManager.commitAndPush(`Initialize task ${taskSlug}`, {
|
|
384
|
-
allowEmpty: true,
|
|
385
|
-
});
|
|
337
|
+
await this.gitManager.commitAndPush(`Initialize task ${taskSlug}`, { allowEmpty: true });
|
|
386
338
|
}
|
|
387
339
|
else {
|
|
388
340
|
// Check if there are any changes before committing
|
|
@@ -393,9 +345,7 @@ Generated by PostHog Agent`;
|
|
|
393
345
|
}
|
|
394
346
|
}
|
|
395
347
|
else {
|
|
396
|
-
this.logger.info(
|
|
397
|
-
branch: existingBranch,
|
|
398
|
-
});
|
|
348
|
+
this.logger.info('Switching to existing task branch', { branch: existingBranch });
|
|
399
349
|
await this.gitManager.switchToBranch(existingBranch);
|
|
400
350
|
}
|
|
401
351
|
}
|
|
@@ -411,49 +361,41 @@ Generated by PostHog Agent`;
|
|
|
411
361
|
}
|
|
412
362
|
async ensurePullRequest(task, stepResults) {
|
|
413
363
|
const latestRun = task.latest_run;
|
|
414
|
-
const existingPr = latestRun?.output && typeof latestRun.output ===
|
|
364
|
+
const existingPr = latestRun?.output && typeof latestRun.output === 'object'
|
|
415
365
|
? latestRun.output.pr_url
|
|
416
366
|
: null;
|
|
417
367
|
if (existingPr) {
|
|
418
|
-
this.logger.info(
|
|
419
|
-
taskId: task.id,
|
|
420
|
-
prUrl: existingPr,
|
|
421
|
-
});
|
|
368
|
+
this.logger.info('PR already exists, skipping creation', { taskId: task.id, prUrl: existingPr });
|
|
422
369
|
return;
|
|
423
370
|
}
|
|
424
|
-
const buildResult = stepResults
|
|
371
|
+
const buildResult = stepResults['build'];
|
|
425
372
|
if (!buildResult?.commitCreated) {
|
|
426
|
-
this.logger.warn(
|
|
373
|
+
this.logger.warn('Build step did not produce a commit; skipping PR creation', { taskId: task.id });
|
|
427
374
|
return;
|
|
428
375
|
}
|
|
429
376
|
const branchName = await this.gitManager.getCurrentBranch();
|
|
430
|
-
const finalizeResult = stepResults
|
|
377
|
+
const finalizeResult = stepResults['finalize'];
|
|
431
378
|
const prBody = finalizeResult?.prBody;
|
|
432
|
-
const prUrl = await this.createPullRequest(task.id, branchName, task.title, task.description ??
|
|
433
|
-
this.emitEvent(this.adapter.createStatusEvent(
|
|
379
|
+
const prUrl = await this.createPullRequest(task.id, branchName, task.title, task.description ?? '', prBody);
|
|
380
|
+
this.emitEvent(this.adapter.createStatusEvent('pr_created', { prUrl }));
|
|
434
381
|
try {
|
|
435
382
|
await this.attachPullRequestToTask(task.id, prUrl, branchName);
|
|
436
|
-
this.logger.info(
|
|
437
|
-
taskId: task.id,
|
|
438
|
-
prUrl,
|
|
439
|
-
});
|
|
383
|
+
this.logger.info('PR attached to task successfully', { taskId: task.id, prUrl });
|
|
440
384
|
}
|
|
441
385
|
catch (error) {
|
|
442
|
-
this.logger.warn(
|
|
386
|
+
this.logger.warn('Could not attach PR to task', {
|
|
443
387
|
error: error instanceof Error ? error.message : String(error),
|
|
444
388
|
});
|
|
445
389
|
}
|
|
446
390
|
}
|
|
447
391
|
emitEvent(event) {
|
|
448
|
-
if (this.debug && event.type !==
|
|
392
|
+
if (this.debug && event.type !== 'token') {
|
|
449
393
|
// Log all events except tokens (too verbose)
|
|
450
|
-
this.logger.debug(
|
|
394
|
+
this.logger.debug('Emitting event', { type: event.type, ts: event.ts });
|
|
451
395
|
}
|
|
452
396
|
const persistPromise = this.progressReporter.recordEvent(event);
|
|
453
|
-
if (persistPromise && typeof persistPromise.then ===
|
|
454
|
-
persistPromise.catch((error) => this.logger.debug(
|
|
455
|
-
message: error.message,
|
|
456
|
-
}));
|
|
397
|
+
if (persistPromise && typeof persistPromise.then === 'function') {
|
|
398
|
+
persistPromise.catch((error) => this.logger.debug('Failed to persist agent event', { message: error.message }));
|
|
457
399
|
}
|
|
458
400
|
this.onEvent?.(event);
|
|
459
401
|
}
|