@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
package/src/workflow/config.ts
CHANGED
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import { planStep } from
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import { buildStep } from "./steps/build.js";
|
|
2
|
+
import { finalizeStep } from "./steps/finalize.js";
|
|
3
|
+
import { planStep } from "./steps/plan.js";
|
|
4
|
+
import { researchStep } from "./steps/research.js";
|
|
5
|
+
import type { WorkflowDefinition } from "./types.js";
|
|
6
6
|
|
|
7
7
|
const MODELS = {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
8
|
+
SONNET: "claude-sonnet-4-5",
|
|
9
|
+
HAIKU: "claude-haiku-4-5",
|
|
10
|
+
};
|
|
11
11
|
|
|
12
12
|
export const TASK_WORKFLOW: WorkflowDefinition = [
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
13
|
+
{
|
|
14
|
+
id: "research",
|
|
15
|
+
name: "Research",
|
|
16
|
+
agent: "research",
|
|
17
|
+
model: MODELS.HAIKU,
|
|
18
|
+
permissionMode: "plan",
|
|
19
|
+
commit: true,
|
|
20
|
+
push: true,
|
|
21
|
+
run: researchStep,
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
id: "plan",
|
|
25
|
+
name: "Plan",
|
|
26
|
+
agent: "planning",
|
|
27
|
+
model: MODELS.SONNET,
|
|
28
|
+
permissionMode: "plan",
|
|
29
|
+
commit: true,
|
|
30
|
+
push: true,
|
|
31
|
+
run: planStep,
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
id: "build",
|
|
35
|
+
name: "Build",
|
|
36
|
+
agent: "execution",
|
|
37
|
+
model: MODELS.SONNET,
|
|
38
|
+
permissionMode: "acceptEdits",
|
|
39
|
+
commit: true,
|
|
40
|
+
push: true,
|
|
41
|
+
run: buildStep,
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
id: "finalize",
|
|
45
|
+
name: "Finalize",
|
|
46
|
+
agent: "system", // not used
|
|
47
|
+
model: MODELS.HAIKU, // not used
|
|
48
|
+
permissionMode: "plan", // not used
|
|
49
|
+
commit: true,
|
|
50
|
+
push: true,
|
|
51
|
+
run: finalizeStep,
|
|
52
|
+
},
|
|
53
53
|
];
|
|
@@ -1,121 +1,130 @@
|
|
|
1
|
-
import { query } from
|
|
2
|
-
import { EXECUTION_SYSTEM_PROMPT } from
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import { TodoManager } from '../../todo-manager.js';
|
|
1
|
+
import { query } from "@anthropic-ai/claude-agent-sdk";
|
|
2
|
+
import { EXECUTION_SYSTEM_PROMPT } from "../../agents/execution.js";
|
|
3
|
+
import { TodoManager } from "../../todo-manager.js";
|
|
4
|
+
import { PermissionMode } from "../../types.js";
|
|
5
|
+
import type { WorkflowStepRunner } from "../types.js";
|
|
7
6
|
|
|
8
7
|
export const buildStep: WorkflowStepRunner = async ({ step, context }) => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
stepLogger.info('Starting build phase', { taskId: task.id });
|
|
35
|
-
emitEvent(adapter.createStatusEvent('phase_start', { phase: 'build' }));
|
|
36
|
-
|
|
37
|
-
const executionPrompt = await promptBuilder.buildExecutionPrompt(task, cwd);
|
|
38
|
-
const fullPrompt = `${EXECUTION_SYSTEM_PROMPT}\n\n${executionPrompt}`;
|
|
39
|
-
|
|
40
|
-
const configuredPermissionMode =
|
|
41
|
-
options.permissionMode ??
|
|
42
|
-
(typeof step.permissionMode === 'string'
|
|
43
|
-
? (step.permissionMode as PermissionMode)
|
|
44
|
-
: step.permissionMode) ??
|
|
45
|
-
PermissionMode.ACCEPT_EDITS;
|
|
46
|
-
|
|
47
|
-
const baseOptions: Record<string, any> = {
|
|
48
|
-
model: step.model,
|
|
49
|
-
cwd,
|
|
50
|
-
permissionMode: configuredPermissionMode,
|
|
51
|
-
settingSources: ['local'],
|
|
52
|
-
mcpServers,
|
|
53
|
-
// Allow all tools for build phase - full read/write access needed for implementation
|
|
54
|
-
allowedTools: [
|
|
55
|
-
'Task',
|
|
56
|
-
'Bash',
|
|
57
|
-
'BashOutput',
|
|
58
|
-
'KillBash',
|
|
59
|
-
'Edit',
|
|
60
|
-
'Read',
|
|
61
|
-
'Write',
|
|
62
|
-
'Glob',
|
|
63
|
-
'Grep',
|
|
64
|
-
'NotebookEdit',
|
|
65
|
-
'WebFetch',
|
|
66
|
-
'WebSearch',
|
|
67
|
-
'ListMcpResources',
|
|
68
|
-
'ReadMcpResource',
|
|
69
|
-
'TodoWrite',
|
|
70
|
-
],
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
// Add fine-grained permission hook if provided
|
|
74
|
-
if (options.canUseTool) {
|
|
75
|
-
baseOptions.canUseTool = options.canUseTool;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const response = query({
|
|
79
|
-
prompt: fullPrompt,
|
|
80
|
-
options: { ...baseOptions, ...(options.queryOverrides || {}) },
|
|
8
|
+
const {
|
|
9
|
+
task,
|
|
10
|
+
cwd,
|
|
11
|
+
options,
|
|
12
|
+
logger,
|
|
13
|
+
promptBuilder,
|
|
14
|
+
adapter,
|
|
15
|
+
mcpServers,
|
|
16
|
+
gitManager,
|
|
17
|
+
emitEvent,
|
|
18
|
+
} = context;
|
|
19
|
+
|
|
20
|
+
const stepLogger = logger.child("BuildStep");
|
|
21
|
+
|
|
22
|
+
const latestRun = task.latest_run;
|
|
23
|
+
const prExists =
|
|
24
|
+
latestRun?.output && typeof latestRun.output === "object"
|
|
25
|
+
? (latestRun.output as Record<string, unknown>).pr_url
|
|
26
|
+
: null;
|
|
27
|
+
|
|
28
|
+
if (prExists) {
|
|
29
|
+
stepLogger.info("PR already exists, skipping build phase", {
|
|
30
|
+
taskId: task.id,
|
|
81
31
|
});
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
32
|
+
return { status: "skipped" };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
stepLogger.info("Starting build phase", { taskId: task.id });
|
|
36
|
+
emitEvent(adapter.createStatusEvent("phase_start", { phase: "build" }));
|
|
37
|
+
|
|
38
|
+
const executionPrompt = await promptBuilder.buildExecutionPrompt(task, cwd);
|
|
39
|
+
const fullPrompt = `${EXECUTION_SYSTEM_PROMPT}\n\n${executionPrompt}`;
|
|
40
|
+
|
|
41
|
+
const configuredPermissionMode =
|
|
42
|
+
options.permissionMode ??
|
|
43
|
+
(typeof step.permissionMode === "string"
|
|
44
|
+
? (step.permissionMode as PermissionMode)
|
|
45
|
+
: step.permissionMode) ??
|
|
46
|
+
PermissionMode.ACCEPT_EDITS;
|
|
47
|
+
|
|
48
|
+
const baseOptions: Record<string, unknown> = {
|
|
49
|
+
model: step.model,
|
|
50
|
+
cwd,
|
|
51
|
+
permissionMode: configuredPermissionMode,
|
|
52
|
+
settingSources: ["local"],
|
|
53
|
+
mcpServers,
|
|
54
|
+
// Allow all tools for build phase - full read/write access needed for implementation
|
|
55
|
+
allowedTools: [
|
|
56
|
+
"Task",
|
|
57
|
+
"Bash",
|
|
58
|
+
"BashOutput",
|
|
59
|
+
"KillBash",
|
|
60
|
+
"Edit",
|
|
61
|
+
"Read",
|
|
62
|
+
"Write",
|
|
63
|
+
"Glob",
|
|
64
|
+
"Grep",
|
|
65
|
+
"NotebookEdit",
|
|
66
|
+
"WebFetch",
|
|
67
|
+
"WebSearch",
|
|
68
|
+
"ListMcpResources",
|
|
69
|
+
"ReadMcpResource",
|
|
70
|
+
"TodoWrite",
|
|
71
|
+
],
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
// Add fine-grained permission hook if provided
|
|
75
|
+
if (options.canUseTool) {
|
|
76
|
+
baseOptions.canUseTool = options.canUseTool;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const response = query({
|
|
80
|
+
prompt: fullPrompt,
|
|
81
|
+
options: { ...baseOptions, ...(options.queryOverrides || {}) },
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
// Track commits made during Claude Code execution
|
|
85
|
+
const commitTracker = await gitManager.trackCommitsDuring();
|
|
86
|
+
|
|
87
|
+
// Track todos from TodoWrite tool calls
|
|
88
|
+
const todoManager = new TodoManager(context.fileManager, stepLogger);
|
|
89
|
+
|
|
90
|
+
try {
|
|
89
91
|
for await (const message of response) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
92
|
+
emitEvent(adapter.createRawSDKEvent(message));
|
|
93
|
+
const transformedEvents = adapter.transform(message);
|
|
94
|
+
for (const event of transformedEvents) {
|
|
95
|
+
emitEvent(event);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const todoList = await todoManager.checkAndPersistFromMessage(
|
|
99
|
+
message,
|
|
100
|
+
task.id,
|
|
101
|
+
);
|
|
102
|
+
if (todoList) {
|
|
103
|
+
emitEvent(adapter.createArtifactEvent("todos", todoList));
|
|
104
|
+
}
|
|
100
105
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
+
} catch (error) {
|
|
107
|
+
stepLogger.error("Error during build step query", error);
|
|
108
|
+
throw error;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// Finalize: commit any remaining changes and optionally push
|
|
112
|
+
const { commitCreated, pushedBranch } = await commitTracker.finalize({
|
|
113
|
+
commitMessage: `Implementation for ${task.title}`,
|
|
114
|
+
push: step.push,
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
context.stepResults[step.id] = { commitCreated };
|
|
118
|
+
|
|
119
|
+
if (!commitCreated) {
|
|
120
|
+
stepLogger.warn("No changes to commit in build phase", { taskId: task.id });
|
|
121
|
+
} else {
|
|
122
|
+
stepLogger.info("Build commits finalized", {
|
|
123
|
+
taskId: task.id,
|
|
124
|
+
pushedBranch,
|
|
106
125
|
});
|
|
126
|
+
}
|
|
107
127
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
if (!commitCreated) {
|
|
111
|
-
stepLogger.warn('No changes to commit in build phase', { taskId: task.id });
|
|
112
|
-
} else {
|
|
113
|
-
stepLogger.info('Build commits finalized', {
|
|
114
|
-
taskId: task.id,
|
|
115
|
-
pushedBranch
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
emitEvent(adapter.createStatusEvent('phase_complete', { phase: 'build' }));
|
|
120
|
-
return { status: 'completed' };
|
|
128
|
+
emitEvent(adapter.createStatusEvent("phase_complete", { phase: "build" }));
|
|
129
|
+
return { status: "completed" };
|
|
121
130
|
};
|