@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,162 +1,142 @@
|
|
|
1
|
-
import { query } from
|
|
2
|
-
import { PLANNING_SYSTEM_PROMPT } from
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
1
|
+
import { query } from '@anthropic-ai/claude-agent-sdk';
|
|
2
|
+
import { PLANNING_SYSTEM_PROMPT } from '../../agents/planning.js';
|
|
3
|
+
import type { WorkflowStepRunner } from '../types.js';
|
|
4
|
+
import { finalizeStepGitActions } from '../utils.js';
|
|
5
|
+
import { TodoManager } from '../../todo-manager.js';
|
|
6
6
|
|
|
7
7
|
export const planStep: 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
|
-
const researchData = await fileManager.readResearch(task.id);
|
|
31
|
-
if (researchData?.questions && !researchData.answered) {
|
|
32
|
-
stepLogger.info("Waiting for answered research questions", {
|
|
33
|
-
taskId: task.id,
|
|
34
|
-
});
|
|
35
|
-
emitEvent(
|
|
36
|
-
adapter.createStatusEvent("phase_complete", {
|
|
37
|
-
phase: "research_questions",
|
|
38
|
-
}),
|
|
39
|
-
);
|
|
40
|
-
return { status: "skipped", halt: true };
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
stepLogger.info("Starting planning phase", { taskId: task.id });
|
|
44
|
-
emitEvent(adapter.createStatusEvent("phase_start", { phase: "planning" }));
|
|
45
|
-
let researchContext = "";
|
|
46
|
-
if (researchData) {
|
|
47
|
-
researchContext += `## Research Context\n\n${researchData.context}\n\n`;
|
|
48
|
-
if (researchData.keyFiles.length > 0) {
|
|
49
|
-
researchContext += `**Key Files:**\n${researchData.keyFiles.map((f) => `- ${f}`).join("\n")}\n\n`;
|
|
8
|
+
const {
|
|
9
|
+
task,
|
|
10
|
+
cwd,
|
|
11
|
+
isCloudMode,
|
|
12
|
+
options,
|
|
13
|
+
logger,
|
|
14
|
+
fileManager,
|
|
15
|
+
gitManager,
|
|
16
|
+
promptBuilder,
|
|
17
|
+
adapter,
|
|
18
|
+
mcpServers,
|
|
19
|
+
emitEvent,
|
|
20
|
+
} = context;
|
|
21
|
+
|
|
22
|
+
const stepLogger = logger.child('PlanStep');
|
|
23
|
+
|
|
24
|
+
const existingPlan = await fileManager.readPlan(task.id);
|
|
25
|
+
if (existingPlan) {
|
|
26
|
+
stepLogger.info('Plan already exists, skipping step', { taskId: task.id });
|
|
27
|
+
return { status: 'skipped' };
|
|
50
28
|
}
|
|
51
|
-
|
|
52
|
-
|
|
29
|
+
|
|
30
|
+
const researchData = await fileManager.readResearch(task.id);
|
|
31
|
+
if (researchData?.questions && !researchData.answered) {
|
|
32
|
+
stepLogger.info('Waiting for answered research questions', { taskId: task.id });
|
|
33
|
+
emitEvent(adapter.createStatusEvent('phase_complete', { phase: 'research_questions' }));
|
|
34
|
+
return { status: 'skipped', halt: true };
|
|
53
35
|
}
|
|
54
36
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
if (
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
37
|
+
stepLogger.info('Starting planning phase', { taskId: task.id });
|
|
38
|
+
emitEvent(adapter.createStatusEvent('phase_start', { phase: 'planning' }));
|
|
39
|
+
let researchContext = '';
|
|
40
|
+
if (researchData) {
|
|
41
|
+
researchContext += `## Research Context\n\n${researchData.context}\n\n`;
|
|
42
|
+
if (researchData.keyFiles.length > 0) {
|
|
43
|
+
researchContext += `**Key Files:**\n${researchData.keyFiles.map(f => `- ${f}`).join('\n')}\n\n`;
|
|
44
|
+
}
|
|
45
|
+
if (researchData.blockers && researchData.blockers.length > 0) {
|
|
46
|
+
researchContext += `**Considerations:**\n${researchData.blockers.map(b => `- ${b}`).join('\n')}\n\n`;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Add answered questions if they exist
|
|
50
|
+
if (researchData.questions && researchData.answers && researchData.answered) {
|
|
51
|
+
researchContext += `## Implementation Decisions\n\n`;
|
|
52
|
+
for (const question of researchData.questions) {
|
|
53
|
+
const answer = researchData.answers.find(
|
|
54
|
+
(a) => a.questionId === question.id
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
researchContext += `### ${question.question}\n\n`;
|
|
58
|
+
if (answer) {
|
|
59
|
+
researchContext += `**Selected:** ${answer.selectedOption}\n`;
|
|
60
|
+
if (answer.customInput) {
|
|
61
|
+
researchContext += `**Details:** ${answer.customInput}\n`;
|
|
62
|
+
}
|
|
63
|
+
} else {
|
|
64
|
+
researchContext += `**Selected:** Not answered\n`;
|
|
65
|
+
}
|
|
66
|
+
researchContext += `\n`;
|
|
67
|
+
}
|
|
75
68
|
}
|
|
76
|
-
researchContext += `\n`;
|
|
77
|
-
}
|
|
78
69
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
let planContent = "";
|
|
113
|
-
try {
|
|
70
|
+
|
|
71
|
+
const planningPrompt = await promptBuilder.buildPlanningPrompt(task, cwd);
|
|
72
|
+
const fullPrompt = `${PLANNING_SYSTEM_PROMPT}\n\n${planningPrompt}\n\n${researchContext}`;
|
|
73
|
+
|
|
74
|
+
const baseOptions: Record<string, any> = {
|
|
75
|
+
model: step.model,
|
|
76
|
+
cwd,
|
|
77
|
+
permissionMode: 'plan',
|
|
78
|
+
settingSources: ['local'],
|
|
79
|
+
mcpServers,
|
|
80
|
+
// Allow research tools: read-only operations, web search, MCP resources, and ExitPlanMode
|
|
81
|
+
allowedTools: [
|
|
82
|
+
'Read',
|
|
83
|
+
'Glob',
|
|
84
|
+
'Grep',
|
|
85
|
+
'WebFetch',
|
|
86
|
+
'WebSearch',
|
|
87
|
+
'ListMcpResources',
|
|
88
|
+
'ReadMcpResource',
|
|
89
|
+
'ExitPlanMode',
|
|
90
|
+
'TodoWrite',
|
|
91
|
+
'BashOutput',
|
|
92
|
+
],
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const response = query({
|
|
96
|
+
prompt: fullPrompt,
|
|
97
|
+
options: { ...baseOptions, ...(options.queryOverrides || {}) },
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
const todoManager = new TodoManager(fileManager, stepLogger);
|
|
101
|
+
|
|
102
|
+
let planContent = '';
|
|
114
103
|
for await (const message of response) {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
planContent += `${block.text}\n`;
|
|
134
|
-
}
|
|
104
|
+
emitEvent(adapter.createRawSDKEvent(message));
|
|
105
|
+
const transformedEvents = adapter.transform(message);
|
|
106
|
+
for (const event of transformedEvents) {
|
|
107
|
+
emitEvent(event);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const todoList = await todoManager.checkAndPersistFromMessage(message, task.id);
|
|
111
|
+
if (todoList) {
|
|
112
|
+
emitEvent(adapter.createArtifactEvent('todos', todoList));
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Extract text content for plan
|
|
116
|
+
if (message.type === 'assistant' && message.message?.content) {
|
|
117
|
+
for (const block of message.message.content) {
|
|
118
|
+
if (block.type === 'text' && block.text) {
|
|
119
|
+
planContent += `${block.text}\n`;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
135
122
|
}
|
|
136
|
-
}
|
|
137
123
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
await
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
emitEvent(
|
|
155
|
-
|
|
156
|
-
);
|
|
157
|
-
return { status: "completed", halt: true };
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
emitEvent(adapter.createStatusEvent("phase_complete", { phase: "planning" }));
|
|
161
|
-
return { status: "completed" };
|
|
124
|
+
|
|
125
|
+
if (planContent.trim()) {
|
|
126
|
+
await fileManager.writePlan(task.id, planContent.trim());
|
|
127
|
+
stepLogger.info('Plan completed', { taskId: task.id });
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
await gitManager.addAllPostHogFiles();
|
|
131
|
+
await finalizeStepGitActions(context, step, {
|
|
132
|
+
commitMessage: `Planning phase for ${task.title}`,
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
if (!isCloudMode) {
|
|
136
|
+
emitEvent(adapter.createStatusEvent('phase_complete', { phase: 'planning' }));
|
|
137
|
+
return { status: 'completed', halt: true };
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
emitEvent(adapter.createStatusEvent('phase_complete', { phase: 'planning' }));
|
|
141
|
+
return { status: 'completed' };
|
|
162
142
|
};
|