@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
package/src/workflow/config.ts
CHANGED
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { planStep } from
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
1
|
+
import type { WorkflowDefinition } from './types.js';
|
|
2
|
+
import { researchStep } from './steps/research.js';
|
|
3
|
+
import { planStep } from './steps/plan.js';
|
|
4
|
+
import { buildStep } from './steps/build.js';
|
|
5
|
+
import { finalizeStep } from './steps/finalize.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,130 +1,121 @@
|
|
|
1
|
-
import { query } from
|
|
2
|
-
import { EXECUTION_SYSTEM_PROMPT } from
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
1
|
+
import { query } from '@anthropic-ai/claude-agent-sdk';
|
|
2
|
+
import { EXECUTION_SYSTEM_PROMPT } from '../../agents/execution.js';
|
|
3
|
+
import { PermissionMode } from '../../types.js';
|
|
4
|
+
import type { WorkflowStepRunner } from '../types.js';
|
|
5
|
+
import { finalizeStepGitActions } from '../utils.js';
|
|
6
|
+
import { TodoManager } from '../../todo-manager.js';
|
|
6
7
|
|
|
7
8
|
export const buildStep: WorkflowStepRunner = async ({ step, context }) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
9
|
+
const {
|
|
10
|
+
task,
|
|
11
|
+
cwd,
|
|
12
|
+
options,
|
|
13
|
+
logger,
|
|
14
|
+
promptBuilder,
|
|
15
|
+
adapter,
|
|
16
|
+
mcpServers,
|
|
17
|
+
gitManager,
|
|
18
|
+
emitEvent,
|
|
19
|
+
} = context;
|
|
20
|
+
|
|
21
|
+
const stepLogger = logger.child('BuildStep');
|
|
22
|
+
|
|
23
|
+
const latestRun = task.latest_run;
|
|
24
|
+
const prExists =
|
|
25
|
+
latestRun?.output && typeof latestRun.output === 'object'
|
|
26
|
+
? (latestRun.output as any).pr_url
|
|
27
|
+
: null;
|
|
28
|
+
|
|
29
|
+
if (prExists) {
|
|
30
|
+
stepLogger.info('PR already exists, skipping build phase', { taskId: task.id });
|
|
31
|
+
return { status: 'skipped' };
|
|
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 || {}) },
|
|
31
81
|
});
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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 {
|
|
82
|
+
|
|
83
|
+
// Track commits made during Claude Code execution
|
|
84
|
+
const commitTracker = await gitManager.trackCommitsDuring();
|
|
85
|
+
|
|
86
|
+
// Track todos from TodoWrite tool calls
|
|
87
|
+
const todoManager = new TodoManager(context.fileManager, stepLogger);
|
|
88
|
+
|
|
91
89
|
for await (const message of response) {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
if (todoList) {
|
|
103
|
-
emitEvent(adapter.createArtifactEvent("todos", todoList));
|
|
104
|
-
}
|
|
90
|
+
emitEvent(adapter.createRawSDKEvent(message));
|
|
91
|
+
const transformedEvents = adapter.transform(message);
|
|
92
|
+
for (const event of transformedEvents) {
|
|
93
|
+
emitEvent(event);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const todoList = await todoManager.checkAndPersistFromMessage(message, task.id);
|
|
97
|
+
if (todoList) {
|
|
98
|
+
emitEvent(adapter.createArtifactEvent('todos', todoList));
|
|
99
|
+
}
|
|
105
100
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
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,
|
|
101
|
+
|
|
102
|
+
// Finalize: commit any remaining changes and optionally push
|
|
103
|
+
const { commitCreated, pushedBranch } = await commitTracker.finalize({
|
|
104
|
+
commitMessage: `Implementation for ${task.title}`,
|
|
105
|
+
push: step.push,
|
|
125
106
|
});
|
|
126
|
-
}
|
|
127
107
|
|
|
128
|
-
|
|
129
|
-
|
|
108
|
+
context.stepResults[step.id] = { commitCreated };
|
|
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' };
|
|
130
121
|
};
|