@posthog/agent 1.22.0 → 1.24.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/CLAUDE.md +3 -3
- package/README.md +3 -3
- 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 +156 -111
- 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 +143 -85
- 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 +59 -58
- 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 +93 -69
- package/dist/src/git-manager.js.map +1 -1
- package/dist/src/posthog-api.d.ts +2 -3
- 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 +123 -93
- 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 +19 -18
- package/dist/src/task-manager.js.map +1 -1
- package/dist/src/task-progress-reporter.d.ts +3 -4
- package/dist/src/task-progress-reporter.d.ts.map +1 -1
- package/dist/src/task-progress-reporter.js +59 -54
- 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 +30 -28
- 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 +29 -24
- 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 +46 -38
- 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 +54 -48
- 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 +58 -46
- 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 +68 -56
- 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 +7 -4
- package/dist/src/workflow/utils.js.map +1 -1
- package/package.json +8 -8
- package/src/adapters/claude/claude-adapter.ts +220 -168
- package/src/adapters/claude/tool-mapper.ts +2 -2
- package/src/adapters/types.ts +1 -1
- package/src/agent.ts +579 -444
- package/src/agents/execution.ts +1 -1
- package/src/agents/planning.ts +1 -1
- package/src/agents/research.ts +0 -1
- package/src/file-manager.ts +64 -63
- package/src/git-manager.ts +152 -87
- package/src/posthog-api.ts +122 -82
- package/src/prompt-builder.ts +180 -135
- package/src/task-manager.ts +38 -30
- package/src/task-progress-reporter.ts +70 -59
- package/src/template-manager.ts +98 -45
- package/src/todo-manager.ts +35 -30
- package/src/tools/registry.ts +62 -62
- package/src/tools/types.ts +36 -36
- package/src/types.ts +93 -71
- package/src/utils/logger.ts +62 -56
- package/src/workflow/config.ts +48 -48
- package/src/workflow/steps/build.ts +122 -113
- package/src/workflow/steps/finalize.ts +214 -182
- package/src/workflow/steps/plan.ts +151 -131
- package/src/workflow/steps/research.ts +205 -186
- package/src/workflow/types.ts +38 -36
- package/src/workflow/utils.ts +37 -34
- package/LICENSE +0 -33
|
@@ -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":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAErE;;;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 { ToolRegistry } from \"../../tools/registry.js\";\nimport type { ToolCallEvent, ToolResultEvent } from \"../../types.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, ArtifactEvent, StatusEvent } 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,aAAa,EAAE,WAAW,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 { PostHogAPIClient } from "./posthog-api.js";
|
|
2
|
+
import type { AgentConfig, CanUseTool, ExecutionResult, Task } from "./types.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 type { AgentConfig, ExecutionResult, SupportingFile, Task, } from "./types.js";
|
|
61
|
+
export { PermissionMode } 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 {
|
|
3
|
-
import { PostHogAPIClient } from './posthog-api.js';
|
|
2
|
+
import { ClaudeAdapter } from './adapters/claude/claude-adapter.js';
|
|
4
3
|
import { PostHogFileManager } from './file-manager.js';
|
|
5
4
|
import { GitManager } from './git-manager.js';
|
|
6
|
-
import {
|
|
7
|
-
import { ClaudeAdapter } from './adapters/claude/claude-adapter.js';
|
|
8
|
-
import { Logger } from './utils/logger.js';
|
|
5
|
+
import { PostHogAPIClient } from './posthog-api.js';
|
|
9
6
|
import { PromptBuilder } from './prompt-builder.js';
|
|
7
|
+
import { TaskManager } from './task-manager.js';
|
|
10
8
|
import { TaskProgressReporter } from './task-progress-reporter.js';
|
|
9
|
+
import { TemplateManager } from './template-manager.js';
|
|
10
|
+
import { Logger } from './utils/logger.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
|
-
|
|
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,24 +98,32 @@ 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(
|
|
115
|
+
this.logger.info("Starting adaptive task execution", {
|
|
116
|
+
taskId: task.id,
|
|
117
|
+
taskSlug,
|
|
118
|
+
isCloudMode,
|
|
119
|
+
});
|
|
116
120
|
// Initialize progress reporter for task run tracking (needed for PR attachment)
|
|
117
|
-
await this.progressReporter.start(task.id, {
|
|
118
|
-
|
|
121
|
+
await this.progressReporter.start(task.id, {
|
|
122
|
+
totalSteps: TASK_WORKFLOW.length,
|
|
123
|
+
});
|
|
124
|
+
this.emitEvent(this.adapter.createStatusEvent("run_started", {
|
|
125
|
+
runId: this.progressReporter.runId,
|
|
126
|
+
}));
|
|
119
127
|
await this.prepareTaskBranch(taskSlug, isCloudMode);
|
|
120
128
|
let taskError;
|
|
121
129
|
try {
|
|
@@ -146,16 +154,20 @@ class Agent {
|
|
|
146
154
|
if (shouldCreatePR) {
|
|
147
155
|
await this.ensurePullRequest(task, workflowContext.stepResults);
|
|
148
156
|
}
|
|
149
|
-
this.logger.info(
|
|
150
|
-
this.emitEvent(this.adapter.createStatusEvent(
|
|
157
|
+
this.logger.info("Task execution complete", { taskId: task.id });
|
|
158
|
+
this.emitEvent(this.adapter.createStatusEvent("task_complete", { taskId: task.id }));
|
|
151
159
|
}
|
|
152
160
|
catch (error) {
|
|
153
161
|
taskError = error instanceof Error ? error : new Error(String(error));
|
|
154
|
-
this.logger.error(
|
|
162
|
+
this.logger.error("Task execution failed", {
|
|
163
|
+
taskId: task.id,
|
|
164
|
+
error: taskError.message,
|
|
165
|
+
});
|
|
155
166
|
}
|
|
156
167
|
finally {
|
|
157
168
|
if (taskError) {
|
|
158
169
|
await this.progressReporter.fail(taskError);
|
|
170
|
+
// biome-ignore lint/correctness/noUnsafeFinally: we actually want to throw the error
|
|
159
171
|
throw taskError;
|
|
160
172
|
}
|
|
161
173
|
else {
|
|
@@ -183,24 +195,30 @@ class Agent {
|
|
|
183
195
|
options: { ...baseOptions, ...(options.queryOverrides || {}) },
|
|
184
196
|
});
|
|
185
197
|
const results = [];
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
198
|
+
try {
|
|
199
|
+
for await (const message of response) {
|
|
200
|
+
this.logger.debug("Received message in direct run", message);
|
|
201
|
+
// Emit raw SDK event
|
|
202
|
+
this.emitEvent(this.adapter.createRawSDKEvent(message));
|
|
203
|
+
const transformedEvents = this.adapter.transform(message);
|
|
204
|
+
for (const event of transformedEvents) {
|
|
205
|
+
this.emitEvent(event);
|
|
206
|
+
}
|
|
207
|
+
results.push(message);
|
|
193
208
|
}
|
|
194
|
-
|
|
209
|
+
}
|
|
210
|
+
catch (error) {
|
|
211
|
+
this.logger.error("Error during direct run", error);
|
|
212
|
+
throw error;
|
|
195
213
|
}
|
|
196
214
|
return { results };
|
|
197
215
|
}
|
|
198
216
|
// PostHog task operations
|
|
199
217
|
async fetchTask(taskId) {
|
|
200
|
-
this.logger.debug(
|
|
218
|
+
this.logger.debug("Fetching task from PostHog", { taskId });
|
|
201
219
|
if (!this.posthogAPI) {
|
|
202
|
-
const error = new Error(
|
|
203
|
-
this.logger.error(
|
|
220
|
+
const error = new Error("PostHog API not configured. Provide posthogApiUrl and posthogApiKey in constructor.");
|
|
221
|
+
this.logger.error("PostHog API not configured", error);
|
|
204
222
|
throw error;
|
|
205
223
|
}
|
|
206
224
|
return this.posthogAPI.fetchTask(taskId);
|
|
@@ -210,60 +228,76 @@ class Agent {
|
|
|
210
228
|
}
|
|
211
229
|
async listTasks(filters) {
|
|
212
230
|
if (!this.posthogAPI) {
|
|
213
|
-
throw new Error(
|
|
231
|
+
throw new Error("PostHog API not configured. Provide posthogApiUrl and posthogApiKey in constructor.");
|
|
214
232
|
}
|
|
215
233
|
return this.posthogAPI.listTasks(filters);
|
|
216
234
|
}
|
|
217
235
|
// File system operations for task artifacts
|
|
218
|
-
async writeTaskFile(taskId, fileName, content, type =
|
|
219
|
-
this.logger.debug(
|
|
220
|
-
|
|
236
|
+
async writeTaskFile(taskId, fileName, content, type = "reference") {
|
|
237
|
+
this.logger.debug("Writing task file", {
|
|
238
|
+
taskId,
|
|
239
|
+
fileName,
|
|
240
|
+
type,
|
|
241
|
+
contentLength: content.length,
|
|
242
|
+
});
|
|
243
|
+
await this.fileManager.writeTaskFile(taskId, {
|
|
244
|
+
name: fileName,
|
|
245
|
+
content,
|
|
246
|
+
type,
|
|
247
|
+
});
|
|
221
248
|
}
|
|
222
249
|
async readTaskFile(taskId, fileName) {
|
|
223
|
-
this.logger.debug(
|
|
250
|
+
this.logger.debug("Reading task file", { taskId, fileName });
|
|
224
251
|
return await this.fileManager.readTaskFile(taskId, fileName);
|
|
225
252
|
}
|
|
226
253
|
async getTaskFiles(taskId) {
|
|
227
|
-
this.logger.debug(
|
|
254
|
+
this.logger.debug("Getting task files", { taskId });
|
|
228
255
|
const files = await this.fileManager.getTaskFiles(taskId);
|
|
229
|
-
this.logger.debug(
|
|
256
|
+
this.logger.debug("Found task files", { taskId, fileCount: files.length });
|
|
230
257
|
return files;
|
|
231
258
|
}
|
|
232
259
|
async writePlan(taskId, plan) {
|
|
233
|
-
this.logger.info(
|
|
260
|
+
this.logger.info("Writing plan", { taskId, planLength: plan.length });
|
|
234
261
|
await this.fileManager.writePlan(taskId, plan);
|
|
235
262
|
}
|
|
236
263
|
async readPlan(taskId) {
|
|
237
|
-
this.logger.debug(
|
|
264
|
+
this.logger.debug("Reading plan", { taskId });
|
|
238
265
|
return await this.fileManager.readPlan(taskId);
|
|
239
266
|
}
|
|
240
267
|
// Git operations for task execution
|
|
241
268
|
async createPlanningBranch(taskId) {
|
|
242
|
-
this.logger.info(
|
|
269
|
+
this.logger.info("Creating planning branch", { taskId });
|
|
243
270
|
const branchName = await this.gitManager.createTaskPlanningBranch(taskId);
|
|
244
|
-
this.logger.debug(
|
|
271
|
+
this.logger.debug("Planning branch created", { taskId, branchName });
|
|
245
272
|
return branchName;
|
|
246
273
|
}
|
|
247
274
|
async commitPlan(taskId, taskTitle) {
|
|
248
|
-
this.logger.info(
|
|
275
|
+
this.logger.info("Committing plan", { taskId, taskTitle });
|
|
249
276
|
const commitHash = await this.gitManager.commitPlan(taskId, taskTitle);
|
|
250
|
-
this.logger.debug(
|
|
277
|
+
this.logger.debug("Plan committed", { taskId, commitHash });
|
|
251
278
|
return commitHash;
|
|
252
279
|
}
|
|
253
280
|
async createImplementationBranch(taskId, planningBranchName) {
|
|
254
|
-
this.logger.info(
|
|
281
|
+
this.logger.info("Creating implementation branch", {
|
|
282
|
+
taskId,
|
|
283
|
+
fromBranch: planningBranchName,
|
|
284
|
+
});
|
|
255
285
|
const branchName = await this.gitManager.createTaskImplementationBranch(taskId, planningBranchName);
|
|
256
|
-
this.logger.debug(
|
|
286
|
+
this.logger.debug("Implementation branch created", { taskId, branchName });
|
|
257
287
|
return branchName;
|
|
258
288
|
}
|
|
259
289
|
async commitImplementation(taskId, taskTitle, planSummary) {
|
|
260
|
-
this.logger.info(
|
|
290
|
+
this.logger.info("Committing implementation", { taskId, taskTitle });
|
|
261
291
|
const commitHash = await this.gitManager.commitImplementation(taskId, taskTitle, planSummary);
|
|
262
|
-
this.logger.debug(
|
|
292
|
+
this.logger.debug("Implementation committed", { taskId, commitHash });
|
|
263
293
|
return commitHash;
|
|
264
294
|
}
|
|
265
295
|
async createPullRequest(taskId, branchName, taskTitle, taskDescription, customBody) {
|
|
266
|
-
this.logger.info(
|
|
296
|
+
this.logger.info("Creating pull request", {
|
|
297
|
+
taskId,
|
|
298
|
+
branchName,
|
|
299
|
+
taskTitle,
|
|
300
|
+
});
|
|
267
301
|
const defaultBody = `## Task Details
|
|
268
302
|
**Task ID**: ${taskId}
|
|
269
303
|
**Description**: ${taskDescription}
|
|
@@ -274,40 +308,50 @@ This PR implements the changes described in the task.
|
|
|
274
308
|
Generated by PostHog Agent`;
|
|
275
309
|
const prBody = customBody || defaultBody;
|
|
276
310
|
const prUrl = await this.gitManager.createPullRequest(branchName, taskTitle, prBody);
|
|
277
|
-
this.logger.info(
|
|
311
|
+
this.logger.info("Pull request created", { taskId, prUrl });
|
|
278
312
|
return prUrl;
|
|
279
313
|
}
|
|
280
314
|
async attachPullRequestToTask(taskId, prUrl, branchName) {
|
|
281
|
-
this.logger.info(
|
|
315
|
+
this.logger.info("Attaching PR to task run", { taskId, prUrl, branchName });
|
|
282
316
|
if (!this.posthogAPI || !this.progressReporter.runId) {
|
|
283
|
-
const error = new Error(
|
|
284
|
-
this.logger.error(
|
|
317
|
+
const error = new Error("PostHog API not configured or no active run. Cannot attach PR to task.");
|
|
318
|
+
this.logger.error("PostHog API not configured", error);
|
|
285
319
|
throw error;
|
|
286
320
|
}
|
|
287
321
|
const updates = {
|
|
288
|
-
output: { pr_url: prUrl }
|
|
322
|
+
output: { pr_url: prUrl },
|
|
289
323
|
};
|
|
290
324
|
if (branchName) {
|
|
291
325
|
updates.branch = branchName;
|
|
292
326
|
}
|
|
293
327
|
await this.posthogAPI.updateTaskRun(taskId, this.progressReporter.runId, updates);
|
|
294
|
-
this.logger.debug(
|
|
328
|
+
this.logger.debug("PR attached to task run", {
|
|
329
|
+
taskId,
|
|
330
|
+
runId: this.progressReporter.runId,
|
|
331
|
+
prUrl,
|
|
332
|
+
});
|
|
295
333
|
}
|
|
296
334
|
async updateTaskBranch(taskId, branchName) {
|
|
297
|
-
this.logger.info(
|
|
335
|
+
this.logger.info("Updating task run branch", { taskId, branchName });
|
|
298
336
|
if (!this.posthogAPI || !this.progressReporter.runId) {
|
|
299
|
-
const error = new Error(
|
|
300
|
-
this.logger.error(
|
|
337
|
+
const error = new Error("PostHog API not configured or no active run. Cannot update branch.");
|
|
338
|
+
this.logger.error("PostHog API not configured", error);
|
|
301
339
|
throw error;
|
|
302
340
|
}
|
|
303
|
-
await this.posthogAPI.updateTaskRun(taskId, this.progressReporter.runId, {
|
|
304
|
-
|
|
341
|
+
await this.posthogAPI.updateTaskRun(taskId, this.progressReporter.runId, {
|
|
342
|
+
branch: branchName,
|
|
343
|
+
});
|
|
344
|
+
this.logger.debug("Task run branch updated", {
|
|
345
|
+
taskId,
|
|
346
|
+
runId: this.progressReporter.runId,
|
|
347
|
+
branchName,
|
|
348
|
+
});
|
|
305
349
|
}
|
|
306
350
|
// Execution management
|
|
307
351
|
cancelTask(taskId) {
|
|
308
352
|
// Find the execution for this task and cancel it
|
|
309
|
-
for (const [executionId, execution] of this.taskManager
|
|
310
|
-
if (execution.taskId === taskId && execution.status ===
|
|
353
|
+
for (const [executionId, execution] of this.taskManager.executionStates) {
|
|
354
|
+
if (execution.taskId === taskId && execution.status === "running") {
|
|
311
355
|
this.taskManager.cancelExecution(executionId);
|
|
312
356
|
break;
|
|
313
357
|
}
|
|
@@ -315,7 +359,7 @@ Generated by PostHog Agent`;
|
|
|
315
359
|
}
|
|
316
360
|
getTaskExecutionStatus(taskId) {
|
|
317
361
|
// Find the execution for this task
|
|
318
|
-
for (const execution of this.taskManager
|
|
362
|
+
for (const execution of this.taskManager.executionStates.values()) {
|
|
319
363
|
if (execution.taskId === taskId) {
|
|
320
364
|
return execution.status;
|
|
321
365
|
}
|
|
@@ -324,17 +368,21 @@ Generated by PostHog Agent`;
|
|
|
324
368
|
}
|
|
325
369
|
async prepareTaskBranch(taskSlug, isCloudMode) {
|
|
326
370
|
if (await this.gitManager.hasChanges()) {
|
|
327
|
-
throw new Error(
|
|
371
|
+
throw new Error("Cannot start task with uncommitted changes. Please commit or stash your changes first.");
|
|
328
372
|
}
|
|
329
373
|
await this.gitManager.resetToDefaultBranchIfNeeded();
|
|
330
374
|
const existingBranch = await this.gitManager.getTaskBranch(taskSlug);
|
|
331
375
|
if (!existingBranch) {
|
|
332
376
|
const branchName = await this.gitManager.createTaskBranch(taskSlug);
|
|
333
|
-
this.emitEvent(this.adapter.createStatusEvent(
|
|
377
|
+
this.emitEvent(this.adapter.createStatusEvent("branch_created", {
|
|
378
|
+
branch: branchName,
|
|
379
|
+
}));
|
|
334
380
|
await this.gitManager.addAllPostHogFiles();
|
|
335
381
|
// Only commit if there are changes or we're in cloud mode
|
|
336
382
|
if (isCloudMode) {
|
|
337
|
-
await this.gitManager.commitAndPush(`Initialize task ${taskSlug}`, {
|
|
383
|
+
await this.gitManager.commitAndPush(`Initialize task ${taskSlug}`, {
|
|
384
|
+
allowEmpty: true,
|
|
385
|
+
});
|
|
338
386
|
}
|
|
339
387
|
else {
|
|
340
388
|
// Check if there are any changes before committing
|
|
@@ -345,7 +393,9 @@ Generated by PostHog Agent`;
|
|
|
345
393
|
}
|
|
346
394
|
}
|
|
347
395
|
else {
|
|
348
|
-
this.logger.info(
|
|
396
|
+
this.logger.info("Switching to existing task branch", {
|
|
397
|
+
branch: existingBranch,
|
|
398
|
+
});
|
|
349
399
|
await this.gitManager.switchToBranch(existingBranch);
|
|
350
400
|
}
|
|
351
401
|
}
|
|
@@ -361,41 +411,49 @@ Generated by PostHog Agent`;
|
|
|
361
411
|
}
|
|
362
412
|
async ensurePullRequest(task, stepResults) {
|
|
363
413
|
const latestRun = task.latest_run;
|
|
364
|
-
const existingPr = latestRun?.output && typeof latestRun.output ===
|
|
414
|
+
const existingPr = latestRun?.output && typeof latestRun.output === "object"
|
|
365
415
|
? latestRun.output.pr_url
|
|
366
416
|
: null;
|
|
367
417
|
if (existingPr) {
|
|
368
|
-
this.logger.info(
|
|
418
|
+
this.logger.info("PR already exists, skipping creation", {
|
|
419
|
+
taskId: task.id,
|
|
420
|
+
prUrl: existingPr,
|
|
421
|
+
});
|
|
369
422
|
return;
|
|
370
423
|
}
|
|
371
|
-
const buildResult = stepResults
|
|
424
|
+
const buildResult = stepResults.build;
|
|
372
425
|
if (!buildResult?.commitCreated) {
|
|
373
|
-
this.logger.warn(
|
|
426
|
+
this.logger.warn("Build step did not produce a commit; skipping PR creation", { taskId: task.id });
|
|
374
427
|
return;
|
|
375
428
|
}
|
|
376
429
|
const branchName = await this.gitManager.getCurrentBranch();
|
|
377
|
-
const finalizeResult = stepResults
|
|
430
|
+
const finalizeResult = stepResults.finalize;
|
|
378
431
|
const prBody = finalizeResult?.prBody;
|
|
379
|
-
const prUrl = await this.createPullRequest(task.id, branchName, task.title, task.description ??
|
|
380
|
-
this.emitEvent(this.adapter.createStatusEvent(
|
|
432
|
+
const prUrl = await this.createPullRequest(task.id, branchName, task.title, task.description ?? "", prBody);
|
|
433
|
+
this.emitEvent(this.adapter.createStatusEvent("pr_created", { prUrl }));
|
|
381
434
|
try {
|
|
382
435
|
await this.attachPullRequestToTask(task.id, prUrl, branchName);
|
|
383
|
-
this.logger.info(
|
|
436
|
+
this.logger.info("PR attached to task successfully", {
|
|
437
|
+
taskId: task.id,
|
|
438
|
+
prUrl,
|
|
439
|
+
});
|
|
384
440
|
}
|
|
385
441
|
catch (error) {
|
|
386
|
-
this.logger.warn(
|
|
442
|
+
this.logger.warn("Could not attach PR to task", {
|
|
387
443
|
error: error instanceof Error ? error.message : String(error),
|
|
388
444
|
});
|
|
389
445
|
}
|
|
390
446
|
}
|
|
391
447
|
emitEvent(event) {
|
|
392
|
-
if (this.debug && event.type !==
|
|
448
|
+
if (this.debug && event.type !== "token") {
|
|
393
449
|
// Log all events except tokens (too verbose)
|
|
394
|
-
this.logger.debug(
|
|
450
|
+
this.logger.debug("Emitting event", { type: event.type, ts: event.ts });
|
|
395
451
|
}
|
|
396
452
|
const persistPromise = this.progressReporter.recordEvent(event);
|
|
397
|
-
if (persistPromise && typeof persistPromise.then ===
|
|
398
|
-
persistPromise.catch((error) => this.logger.debug(
|
|
453
|
+
if (persistPromise && typeof persistPromise.then === "function") {
|
|
454
|
+
persistPromise.catch((error) => this.logger.debug("Failed to persist agent event", {
|
|
455
|
+
message: error.message,
|
|
456
|
+
}));
|
|
399
457
|
}
|
|
400
458
|
this.onEvent?.(event);
|
|
401
459
|
}
|