@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/tools/types.ts
CHANGED
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
* Makes it easier for UIs to filter and display tools by function.
|
|
4
4
|
*/
|
|
5
5
|
export type ToolCategory =
|
|
6
|
-
|
|
|
7
|
-
|
|
|
8
|
-
|
|
|
9
|
-
|
|
|
10
|
-
|
|
|
11
|
-
|
|
|
6
|
+
| "filesystem" // File operations: Read, Write, Edit, Glob, NotebookEdit
|
|
7
|
+
| "shell" // Shell operations: Bash, BashOutput, KillShell
|
|
8
|
+
| "web" // Web operations: WebFetch, WebSearch
|
|
9
|
+
| "assistant" // Assistant operations: Task, TodoWrite, ExitPlanMode
|
|
10
|
+
| "search" // Search operations: Grep
|
|
11
|
+
| "unknown"; // Unknown or unrecognized tools
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Base tool interface representing a tool that can be called by the agent.
|
|
@@ -23,86 +23,86 @@ export interface Tool {
|
|
|
23
23
|
// Filesystem tools
|
|
24
24
|
|
|
25
25
|
export interface ReadTool extends Tool {
|
|
26
|
-
name:
|
|
27
|
-
category:
|
|
26
|
+
name: "Read";
|
|
27
|
+
category: "filesystem";
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
export interface WriteTool extends Tool {
|
|
31
|
-
name:
|
|
32
|
-
category:
|
|
31
|
+
name: "Write";
|
|
32
|
+
category: "filesystem";
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
export interface EditTool extends Tool {
|
|
36
|
-
name:
|
|
37
|
-
category:
|
|
36
|
+
name: "Edit";
|
|
37
|
+
category: "filesystem";
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
export interface GlobTool extends Tool {
|
|
41
|
-
name:
|
|
42
|
-
category:
|
|
41
|
+
name: "Glob";
|
|
42
|
+
category: "filesystem";
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
export interface NotebookEditTool extends Tool {
|
|
46
|
-
name:
|
|
47
|
-
category:
|
|
46
|
+
name: "NotebookEdit";
|
|
47
|
+
category: "filesystem";
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
// Shell tools
|
|
51
51
|
|
|
52
52
|
export interface BashTool extends Tool {
|
|
53
|
-
name:
|
|
54
|
-
category:
|
|
53
|
+
name: "Bash";
|
|
54
|
+
category: "shell";
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
export interface BashOutputTool extends Tool {
|
|
58
|
-
name:
|
|
59
|
-
category:
|
|
58
|
+
name: "BashOutput";
|
|
59
|
+
category: "shell";
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
export interface KillShellTool extends Tool {
|
|
63
|
-
name:
|
|
64
|
-
category:
|
|
63
|
+
name: "KillShell";
|
|
64
|
+
category: "shell";
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
// Web tools
|
|
68
68
|
|
|
69
69
|
export interface WebFetchTool extends Tool {
|
|
70
|
-
name:
|
|
71
|
-
category:
|
|
70
|
+
name: "WebFetch";
|
|
71
|
+
category: "web";
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
export interface WebSearchTool extends Tool {
|
|
75
|
-
name:
|
|
76
|
-
category:
|
|
75
|
+
name: "WebSearch";
|
|
76
|
+
category: "web";
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
// Search tools
|
|
80
80
|
|
|
81
81
|
export interface GrepTool extends Tool {
|
|
82
|
-
name:
|
|
83
|
-
category:
|
|
82
|
+
name: "Grep";
|
|
83
|
+
category: "search";
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
// Assistant tools
|
|
87
87
|
|
|
88
88
|
export interface TaskTool extends Tool {
|
|
89
|
-
name:
|
|
90
|
-
category:
|
|
89
|
+
name: "Task";
|
|
90
|
+
category: "assistant";
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
export interface TodoWriteTool extends Tool {
|
|
94
|
-
name:
|
|
95
|
-
category:
|
|
94
|
+
name: "TodoWrite";
|
|
95
|
+
category: "assistant";
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
export interface ExitPlanModeTool extends Tool {
|
|
99
|
-
name:
|
|
100
|
-
category:
|
|
99
|
+
name: "ExitPlanMode";
|
|
100
|
+
category: "assistant";
|
|
101
101
|
}
|
|
102
102
|
|
|
103
103
|
export interface SlashCommandTool extends Tool {
|
|
104
|
-
name:
|
|
105
|
-
category:
|
|
104
|
+
name: "SlashCommand";
|
|
105
|
+
category: "assistant";
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
/**
|
package/src/types.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
|
|
2
1
|
// import and export to keep a single type file
|
|
3
|
-
import type {
|
|
2
|
+
import type {
|
|
3
|
+
CanUseTool,
|
|
4
|
+
PermissionResult,
|
|
5
|
+
} from "@anthropic-ai/claude-agent-sdk";
|
|
4
6
|
export type { CanUseTool, PermissionResult };
|
|
5
7
|
|
|
6
8
|
// PostHog Task model (matches Array's OpenAPI schema)
|
|
@@ -8,7 +10,12 @@ export interface Task {
|
|
|
8
10
|
id: string;
|
|
9
11
|
title: string;
|
|
10
12
|
description: string;
|
|
11
|
-
origin_product:
|
|
13
|
+
origin_product:
|
|
14
|
+
| "error_tracking"
|
|
15
|
+
| "eval_clusters"
|
|
16
|
+
| "user_created"
|
|
17
|
+
| "support_queue"
|
|
18
|
+
| "session_summaries";
|
|
12
19
|
position?: number;
|
|
13
20
|
github_integration?: number | null;
|
|
14
21
|
repository_config?: unknown; // JSONField
|
|
@@ -32,7 +39,12 @@ export interface LogEntry {
|
|
|
32
39
|
[key: string]: unknown; // Allow additional fields
|
|
33
40
|
}
|
|
34
41
|
|
|
35
|
-
export type ArtifactType =
|
|
42
|
+
export type ArtifactType =
|
|
43
|
+
| "plan"
|
|
44
|
+
| "context"
|
|
45
|
+
| "reference"
|
|
46
|
+
| "output"
|
|
47
|
+
| "artifact";
|
|
36
48
|
|
|
37
49
|
export interface TaskRunArtifact {
|
|
38
50
|
name: string;
|
|
@@ -49,7 +61,7 @@ export interface TaskRun {
|
|
|
49
61
|
task: string; // Task ID
|
|
50
62
|
team: number;
|
|
51
63
|
branch: string | null;
|
|
52
|
-
status:
|
|
64
|
+
status: "started" | "in_progress" | "completed" | "failed";
|
|
53
65
|
log_url?: string; // Presigned S3 URL for log access (valid for 1 hour)
|
|
54
66
|
error_message: string | null;
|
|
55
67
|
output: Record<string, unknown> | null; // Structured output (PR URL, commit SHA, etc.)
|
|
@@ -78,7 +90,7 @@ export enum PermissionMode {
|
|
|
78
90
|
PLAN = "plan",
|
|
79
91
|
DEFAULT = "default",
|
|
80
92
|
ACCEPT_EDITS = "acceptEdits",
|
|
81
|
-
BYPASS = "bypassPermissions"
|
|
93
|
+
BYPASS = "bypassPermissions",
|
|
82
94
|
}
|
|
83
95
|
|
|
84
96
|
export interface ExecutionOptions {
|
|
@@ -105,57 +117,57 @@ interface BaseEvent {
|
|
|
105
117
|
|
|
106
118
|
// Streaming content events
|
|
107
119
|
export interface TokenEvent extends BaseEvent {
|
|
108
|
-
type:
|
|
120
|
+
type: "token";
|
|
109
121
|
content: string;
|
|
110
|
-
contentType?:
|
|
122
|
+
contentType?: "text" | "thinking" | "tool_input";
|
|
111
123
|
}
|
|
112
124
|
|
|
113
125
|
export interface ContentBlockStartEvent extends BaseEvent {
|
|
114
|
-
type:
|
|
126
|
+
type: "content_block_start";
|
|
115
127
|
index: number;
|
|
116
|
-
contentType:
|
|
128
|
+
contentType: "text" | "tool_use" | "thinking";
|
|
117
129
|
toolName?: string;
|
|
118
130
|
toolId?: string;
|
|
119
131
|
}
|
|
120
132
|
|
|
121
133
|
export interface ContentBlockStopEvent extends BaseEvent {
|
|
122
|
-
type:
|
|
134
|
+
type: "content_block_stop";
|
|
123
135
|
index: number;
|
|
124
136
|
}
|
|
125
137
|
|
|
126
138
|
// Tool events
|
|
127
139
|
export interface ToolCallEvent extends BaseEvent {
|
|
128
|
-
type:
|
|
140
|
+
type: "tool_call";
|
|
129
141
|
toolName: string;
|
|
130
142
|
callId: string;
|
|
131
143
|
args: Record<string, any>;
|
|
132
|
-
parentToolUseId?: string | null;
|
|
144
|
+
parentToolUseId?: string | null; // For nested tool calls (subagents)
|
|
133
145
|
// Tool metadata (enriched by adapter for UI consumption)
|
|
134
|
-
tool?: import(
|
|
135
|
-
category?: import(
|
|
146
|
+
tool?: import("./tools/types.js").Tool;
|
|
147
|
+
category?: import("./tools/types.js").ToolCategory;
|
|
136
148
|
}
|
|
137
149
|
|
|
138
150
|
export interface ToolResultEvent extends BaseEvent {
|
|
139
|
-
type:
|
|
151
|
+
type: "tool_result";
|
|
140
152
|
toolName: string;
|
|
141
153
|
callId: string;
|
|
142
154
|
result: any;
|
|
143
|
-
isError?: boolean;
|
|
144
|
-
parentToolUseId?: string | null;
|
|
155
|
+
isError?: boolean; // Whether the tool execution failed
|
|
156
|
+
parentToolUseId?: string | null; // For nested tool calls (subagents)
|
|
145
157
|
// Tool metadata (enriched by adapter for UI consumption)
|
|
146
|
-
tool?: import(
|
|
147
|
-
category?: import(
|
|
158
|
+
tool?: import("./tools/types.js").Tool;
|
|
159
|
+
category?: import("./tools/types.js").ToolCategory;
|
|
148
160
|
}
|
|
149
161
|
|
|
150
162
|
// Message lifecycle events
|
|
151
163
|
export interface MessageStartEvent extends BaseEvent {
|
|
152
|
-
type:
|
|
164
|
+
type: "message_start";
|
|
153
165
|
messageId?: string;
|
|
154
166
|
model?: string;
|
|
155
167
|
}
|
|
156
168
|
|
|
157
169
|
export interface MessageDeltaEvent extends BaseEvent {
|
|
158
|
-
type:
|
|
170
|
+
type: "message_delta";
|
|
159
171
|
stopReason?: string;
|
|
160
172
|
stopSequence?: string;
|
|
161
173
|
usage?: {
|
|
@@ -164,32 +176,32 @@ export interface MessageDeltaEvent extends BaseEvent {
|
|
|
164
176
|
}
|
|
165
177
|
|
|
166
178
|
export interface MessageStopEvent extends BaseEvent {
|
|
167
|
-
type:
|
|
179
|
+
type: "message_stop";
|
|
168
180
|
}
|
|
169
181
|
|
|
170
182
|
// User message events
|
|
171
183
|
export interface UserMessageEvent extends BaseEvent {
|
|
172
|
-
type:
|
|
184
|
+
type: "user_message";
|
|
173
185
|
content: string;
|
|
174
186
|
isSynthetic?: boolean;
|
|
175
187
|
}
|
|
176
188
|
|
|
177
189
|
// System events
|
|
178
190
|
export interface StatusEvent extends BaseEvent {
|
|
179
|
-
type:
|
|
191
|
+
type: "status";
|
|
180
192
|
phase: string;
|
|
181
193
|
// Common optional fields (varies by phase):
|
|
182
|
-
kind?: string;
|
|
183
|
-
branch?: string;
|
|
184
|
-
prUrl?: string;
|
|
185
|
-
taskId?: string;
|
|
186
|
-
messageId?: string;
|
|
187
|
-
model?: string;
|
|
188
|
-
[key: string]: any;
|
|
194
|
+
kind?: string; // Kind of status (plan, implementation)
|
|
195
|
+
branch?: string; // Git branch name
|
|
196
|
+
prUrl?: string; // Pull request URL
|
|
197
|
+
taskId?: string; // Task identifier
|
|
198
|
+
messageId?: string; // Claude message ID
|
|
199
|
+
model?: string; // Model name
|
|
200
|
+
[key: string]: any; // Allow additional fields
|
|
189
201
|
}
|
|
190
202
|
|
|
191
203
|
export interface InitEvent extends BaseEvent {
|
|
192
|
-
type:
|
|
204
|
+
type: "init";
|
|
193
205
|
model: string;
|
|
194
206
|
tools: string[];
|
|
195
207
|
permissionMode: string;
|
|
@@ -202,21 +214,22 @@ export interface InitEvent extends BaseEvent {
|
|
|
202
214
|
}
|
|
203
215
|
|
|
204
216
|
export interface CompactBoundaryEvent extends BaseEvent {
|
|
205
|
-
type:
|
|
206
|
-
trigger:
|
|
217
|
+
type: "compact_boundary";
|
|
218
|
+
trigger: "manual" | "auto";
|
|
207
219
|
preTokens: number;
|
|
208
220
|
}
|
|
209
221
|
|
|
210
222
|
// Result events
|
|
211
223
|
export interface DoneEvent extends BaseEvent {
|
|
212
|
-
type:
|
|
213
|
-
result?: string;
|
|
224
|
+
type: "done";
|
|
225
|
+
result?: string; // Final summary text from Claude
|
|
214
226
|
durationMs?: number;
|
|
215
|
-
durationApiMs?: number;
|
|
227
|
+
durationApiMs?: number; // API-only duration (excluding local processing)
|
|
216
228
|
numTurns?: number;
|
|
217
229
|
totalCostUsd?: number;
|
|
218
230
|
usage?: any;
|
|
219
|
-
modelUsage?: {
|
|
231
|
+
modelUsage?: {
|
|
232
|
+
// Per-model usage breakdown
|
|
220
233
|
[modelName: string]: {
|
|
221
234
|
inputTokens: number;
|
|
222
235
|
outputTokens: number;
|
|
@@ -227,7 +240,8 @@ export interface DoneEvent extends BaseEvent {
|
|
|
227
240
|
contextWindow: number;
|
|
228
241
|
};
|
|
229
242
|
};
|
|
230
|
-
permissionDenials?: Array<{
|
|
243
|
+
permissionDenials?: Array<{
|
|
244
|
+
// Tools that were denied by permissions
|
|
231
245
|
tool_name: string;
|
|
232
246
|
tool_use_id: string;
|
|
233
247
|
tool_input: Record<string, unknown>;
|
|
@@ -235,7 +249,7 @@ export interface DoneEvent extends BaseEvent {
|
|
|
235
249
|
}
|
|
236
250
|
|
|
237
251
|
export interface ErrorEvent extends BaseEvent {
|
|
238
|
-
type:
|
|
252
|
+
type: "error";
|
|
239
253
|
message: string;
|
|
240
254
|
error?: any;
|
|
241
255
|
errorType?: string;
|
|
@@ -245,20 +259,20 @@ export interface ErrorEvent extends BaseEvent {
|
|
|
245
259
|
|
|
246
260
|
// Metric and artifact events (general purpose, not tool-specific)
|
|
247
261
|
export interface MetricEvent extends BaseEvent {
|
|
248
|
-
type:
|
|
262
|
+
type: "metric";
|
|
249
263
|
key: string;
|
|
250
264
|
value: number;
|
|
251
265
|
unit?: string;
|
|
252
266
|
}
|
|
253
267
|
|
|
254
268
|
export interface ArtifactEvent extends BaseEvent {
|
|
255
|
-
type:
|
|
269
|
+
type: "artifact";
|
|
256
270
|
kind: string;
|
|
257
271
|
content: any;
|
|
258
272
|
}
|
|
259
273
|
|
|
260
274
|
export interface RawSDKEvent extends BaseEvent {
|
|
261
|
-
type:
|
|
275
|
+
type: "raw_sdk_event";
|
|
262
276
|
sdkMessage: any; // Full SDK message for debugging
|
|
263
277
|
}
|
|
264
278
|
|
|
@@ -296,24 +310,28 @@ export interface TaskExecutionResult {
|
|
|
296
310
|
}
|
|
297
311
|
|
|
298
312
|
// MCP Server configuration types (re-exported from Claude SDK for convenience)
|
|
299
|
-
export type McpServerConfig =
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
313
|
+
export type McpServerConfig =
|
|
314
|
+
| {
|
|
315
|
+
type?: "stdio";
|
|
316
|
+
command: string;
|
|
317
|
+
args?: string[];
|
|
318
|
+
env?: Record<string, string>;
|
|
319
|
+
}
|
|
320
|
+
| {
|
|
321
|
+
type: "sse";
|
|
322
|
+
url: string;
|
|
323
|
+
headers?: Record<string, string>;
|
|
324
|
+
}
|
|
325
|
+
| {
|
|
326
|
+
type: "http";
|
|
327
|
+
url: string;
|
|
328
|
+
headers?: Record<string, string>;
|
|
329
|
+
}
|
|
330
|
+
| {
|
|
331
|
+
type: "sdk";
|
|
332
|
+
name: string;
|
|
333
|
+
instance?: any; // McpServer instance
|
|
334
|
+
};
|
|
317
335
|
|
|
318
336
|
export interface AgentConfig {
|
|
319
337
|
workingDirectory?: string;
|
|
@@ -327,7 +345,6 @@ export interface AgentConfig {
|
|
|
327
345
|
// PostHog MCP configuration
|
|
328
346
|
posthogMcpUrl?: string;
|
|
329
347
|
|
|
330
|
-
|
|
331
348
|
// MCP Server configuration
|
|
332
349
|
// Additional MCP servers (PostHog MCP is always included by default)
|
|
333
350
|
// You can override the PostHog MCP config by providing mcpServers.posthog
|
|
@@ -348,7 +365,12 @@ export interface PostHogAPIConfig {
|
|
|
348
365
|
}
|
|
349
366
|
|
|
350
367
|
// URL mention types
|
|
351
|
-
export type ResourceType =
|
|
368
|
+
export type ResourceType =
|
|
369
|
+
| "error"
|
|
370
|
+
| "experiment"
|
|
371
|
+
| "insight"
|
|
372
|
+
| "feature_flag"
|
|
373
|
+
| "generic";
|
|
352
374
|
|
|
353
375
|
export interface PostHogResource {
|
|
354
376
|
type: ResourceType;
|
|
@@ -380,11 +402,11 @@ export interface ResearchAnswer {
|
|
|
380
402
|
}
|
|
381
403
|
|
|
382
404
|
export interface ResearchEvaluation {
|
|
383
|
-
actionabilityScore: number;
|
|
384
|
-
context: string;
|
|
385
|
-
keyFiles: string[];
|
|
386
|
-
blockers?: string[];
|
|
405
|
+
actionabilityScore: number; // 0-1 confidence score
|
|
406
|
+
context: string; // brief summary for planning
|
|
407
|
+
keyFiles: string[]; // files needing modification
|
|
408
|
+
blockers?: string[]; // what's preventing full confidence
|
|
387
409
|
questions?: ResearchQuestion[]; // only if score < 0.7
|
|
388
|
-
answered?: boolean;
|
|
389
|
-
answers?: ResearchAnswer[];
|
|
390
|
-
}
|
|
410
|
+
answered?: boolean; // whether questions have been answered
|
|
411
|
+
answers?: ResearchAnswer[]; // user's answers to questions
|
|
412
|
+
}
|
package/src/utils/logger.ts
CHANGED
|
@@ -2,78 +2,84 @@
|
|
|
2
2
|
* Simple logger utility with configurable debug mode
|
|
3
3
|
*/
|
|
4
4
|
export enum LogLevel {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
ERROR = 0,
|
|
6
|
+
WARN = 1,
|
|
7
|
+
INFO = 2,
|
|
8
|
+
DEBUG = 3,
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
export interface LoggerConfig {
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
debug?: boolean;
|
|
13
|
+
prefix?: string;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export class Logger {
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
private debugEnabled: boolean;
|
|
18
|
+
private prefix: string;
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
constructor(config: LoggerConfig = {}) {
|
|
21
|
+
this.debugEnabled = config.debug ?? false;
|
|
22
|
+
this.prefix = config.prefix ?? "[PostHog Agent]";
|
|
23
|
+
}
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
setDebug(enabled: boolean) {
|
|
26
|
+
this.debugEnabled = enabled;
|
|
27
|
+
}
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return base;
|
|
38
|
-
}
|
|
29
|
+
private formatMessage(
|
|
30
|
+
level: string,
|
|
31
|
+
message: string,
|
|
32
|
+
data?: unknown,
|
|
33
|
+
): string {
|
|
34
|
+
const timestamp = new Date().toISOString();
|
|
35
|
+
const base = `${timestamp} ${this.prefix} ${level} ${message}`;
|
|
39
36
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
if (error instanceof Error) {
|
|
43
|
-
console.error(this.formatMessage('[ERROR]', message, {
|
|
44
|
-
message: error.message,
|
|
45
|
-
stack: error.stack
|
|
46
|
-
}));
|
|
47
|
-
} else {
|
|
48
|
-
console.error(this.formatMessage('[ERROR]', message, error));
|
|
49
|
-
}
|
|
37
|
+
if (data !== undefined) {
|
|
38
|
+
return `${base} ${JSON.stringify(data, null, 2)}`;
|
|
50
39
|
}
|
|
51
40
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
41
|
+
return base;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
error(message: string, error?: Error | unknown) {
|
|
45
|
+
// Always log errors
|
|
46
|
+
if (error instanceof Error) {
|
|
47
|
+
console.error(
|
|
48
|
+
this.formatMessage("[ERROR]", message, {
|
|
49
|
+
message: error.message,
|
|
50
|
+
stack: error.stack,
|
|
51
|
+
}),
|
|
52
|
+
);
|
|
53
|
+
} else {
|
|
54
|
+
console.error(this.formatMessage("[ERROR]", message, error));
|
|
56
55
|
}
|
|
56
|
+
}
|
|
57
57
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
58
|
+
warn(message: string, data?: unknown) {
|
|
59
|
+
if (this.debugEnabled) {
|
|
60
|
+
console.warn(this.formatMessage("[WARN]", message, data));
|
|
62
61
|
}
|
|
62
|
+
}
|
|
63
63
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
64
|
+
info(message: string, data?: unknown) {
|
|
65
|
+
if (this.debugEnabled) {
|
|
66
|
+
console.log(this.formatMessage("[INFO]", message, data));
|
|
68
67
|
}
|
|
68
|
+
}
|
|
69
69
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
child(childPrefix: string): Logger {
|
|
74
|
-
return new Logger({
|
|
75
|
-
debug: this.debugEnabled,
|
|
76
|
-
prefix: `${this.prefix} [${childPrefix}]`
|
|
77
|
-
});
|
|
70
|
+
debug(message: string, data?: unknown) {
|
|
71
|
+
if (this.debugEnabled) {
|
|
72
|
+
console.log(this.formatMessage("[DEBUG]", message, data));
|
|
78
73
|
}
|
|
79
|
-
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Create a child logger with additional prefix
|
|
78
|
+
*/
|
|
79
|
+
child(childPrefix: string): Logger {
|
|
80
|
+
return new Logger({
|
|
81
|
+
debug: this.debugEnabled,
|
|
82
|
+
prefix: `${this.prefix} [${childPrefix}]`,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|