@posthog/agent 1.29.0 → 2.0.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/dist/index.d.ts +57 -87
- package/dist/index.js +916 -2203
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/acp-extensions.ts +0 -37
- package/src/adapters/claude/claude.ts +515 -107
- package/src/adapters/claude/tools.ts +178 -101
- package/src/adapters/connection.ts +95 -0
- package/src/agent.ts +50 -184
- package/src/file-manager.ts +1 -34
- package/src/git-manager.ts +2 -20
- package/src/posthog-api.ts +4 -4
- package/src/tools/registry.ts +5 -0
- package/src/tools/types.ts +6 -0
- package/src/types.ts +5 -25
- package/src/utils/gateway.ts +15 -0
- package/src/worktree-manager.ts +92 -46
- package/dist/templates/plan-template.md +0 -41
- package/src/agents/execution.ts +0 -37
- package/src/agents/planning.ts +0 -60
- package/src/agents/research.ts +0 -160
- package/src/prompt-builder.ts +0 -497
- package/src/template-manager.ts +0 -240
- package/src/templates/plan-template.md +0 -41
- package/src/workflow/config.ts +0 -53
- package/src/workflow/steps/build.ts +0 -135
- package/src/workflow/steps/finalize.ts +0 -241
- package/src/workflow/steps/plan.ts +0 -167
- package/src/workflow/steps/research.ts +0 -223
- package/src/workflow/types.ts +0 -62
- package/src/workflow/utils.ts +0 -53
package/dist/index.d.ts
CHANGED
|
@@ -17,16 +17,8 @@ import { z } from 'zod';
|
|
|
17
17
|
* Used with AgentSideConnection.extNotification() or Client.extNotification()
|
|
18
18
|
*/
|
|
19
19
|
declare const POSTHOG_NOTIFICATIONS: {
|
|
20
|
-
/** Artifact produced during task execution (research, plan, etc.) */
|
|
21
|
-
readonly ARTIFACT: "_posthog/artifact";
|
|
22
|
-
/** Phase has started (research, plan, build, etc.) */
|
|
23
|
-
readonly PHASE_START: "_posthog/phase_start";
|
|
24
|
-
/** Phase has completed */
|
|
25
|
-
readonly PHASE_COMPLETE: "_posthog/phase_complete";
|
|
26
20
|
/** Git branch was created */
|
|
27
21
|
readonly BRANCH_CREATED: "_posthog/branch_created";
|
|
28
|
-
/** Pull request was created */
|
|
29
|
-
readonly PR_CREATED: "_posthog/pr_created";
|
|
30
22
|
/** Task run has started */
|
|
31
23
|
readonly RUN_STARTED: "_posthog/run_started";
|
|
32
24
|
/** Task has completed */
|
|
@@ -39,27 +31,9 @@ declare const POSTHOG_NOTIFICATIONS: {
|
|
|
39
31
|
readonly SDK_SESSION: "_posthog/sdk_session";
|
|
40
32
|
};
|
|
41
33
|
type PostHogNotificationType = (typeof POSTHOG_NOTIFICATIONS)[keyof typeof POSTHOG_NOTIFICATIONS];
|
|
42
|
-
interface ArtifactNotificationPayload {
|
|
43
|
-
sessionId: string;
|
|
44
|
-
kind: "research_evaluation" | "research_questions" | "plan" | "pr_body" | string;
|
|
45
|
-
content: unknown;
|
|
46
|
-
}
|
|
47
|
-
interface PhaseNotificationPayload {
|
|
48
|
-
sessionId: string;
|
|
49
|
-
phase: "research" | "plan" | "build" | "finalize" | string;
|
|
50
|
-
[key: string]: unknown;
|
|
51
|
-
}
|
|
52
34
|
interface BranchCreatedPayload {
|
|
53
|
-
sessionId: string;
|
|
54
35
|
branch: string;
|
|
55
36
|
}
|
|
56
|
-
/**
|
|
57
|
-
* Payload for PR created notification
|
|
58
|
-
*/
|
|
59
|
-
interface PrCreatedPayload {
|
|
60
|
-
sessionId: string;
|
|
61
|
-
prUrl: string;
|
|
62
|
-
}
|
|
63
37
|
interface RunStartedPayload {
|
|
64
38
|
sessionId: string;
|
|
65
39
|
runId: string;
|
|
@@ -92,7 +66,7 @@ interface SdkSessionPayload {
|
|
|
92
66
|
sessionId: string;
|
|
93
67
|
sdkSessionId: string;
|
|
94
68
|
}
|
|
95
|
-
type PostHogNotificationPayload =
|
|
69
|
+
type PostHogNotificationPayload = BranchCreatedPayload | RunStartedPayload | TaskCompletePayload | ErrorNotificationPayload | ConsoleNotificationPayload | SdkSessionPayload;
|
|
96
70
|
|
|
97
71
|
/**
|
|
98
72
|
* Stored custom notification following ACP extensibility model.
|
|
@@ -190,6 +164,9 @@ interface TaskExecutionOptions {
|
|
|
190
164
|
queryOverrides?: Record<string, unknown>;
|
|
191
165
|
canUseTool?: CanUseTool;
|
|
192
166
|
skipGitBranch?: boolean;
|
|
167
|
+
framework?: "claude";
|
|
168
|
+
task?: Task;
|
|
169
|
+
isReconnect?: boolean;
|
|
193
170
|
}
|
|
194
171
|
interface ExecutionResult {
|
|
195
172
|
results: any[];
|
|
@@ -217,7 +194,7 @@ type OnLogCallback = (level: LogLevel$1, scope: string, message: string, data?:
|
|
|
217
194
|
interface AgentConfig {
|
|
218
195
|
workingDirectory?: string;
|
|
219
196
|
posthogApiUrl?: string;
|
|
220
|
-
|
|
197
|
+
getPosthogApiKey?: () => string;
|
|
221
198
|
posthogProjectId?: number;
|
|
222
199
|
posthogMcpUrl?: string;
|
|
223
200
|
mcpServers?: Record<string, McpServerConfig>;
|
|
@@ -227,7 +204,7 @@ interface AgentConfig {
|
|
|
227
204
|
}
|
|
228
205
|
interface PostHogAPIConfig {
|
|
229
206
|
apiUrl: string;
|
|
230
|
-
|
|
207
|
+
getApiKey: () => string;
|
|
231
208
|
projectId: number;
|
|
232
209
|
}
|
|
233
210
|
type ResourceType = "error" | "experiment" | "insight" | "feature_flag" | "generic";
|
|
@@ -245,25 +222,6 @@ interface UrlMention {
|
|
|
245
222
|
id?: string;
|
|
246
223
|
label?: string;
|
|
247
224
|
}
|
|
248
|
-
interface ResearchQuestion {
|
|
249
|
-
id: string;
|
|
250
|
-
question: string;
|
|
251
|
-
options: string[];
|
|
252
|
-
}
|
|
253
|
-
interface ResearchAnswer {
|
|
254
|
-
questionId: string;
|
|
255
|
-
selectedOption: string;
|
|
256
|
-
customInput?: string;
|
|
257
|
-
}
|
|
258
|
-
interface ResearchEvaluation {
|
|
259
|
-
actionabilityScore: number;
|
|
260
|
-
context: string;
|
|
261
|
-
keyFiles: string[];
|
|
262
|
-
blockers?: string[];
|
|
263
|
-
questions?: ResearchQuestion[];
|
|
264
|
-
answered?: boolean;
|
|
265
|
-
answers?: ResearchAnswer[];
|
|
266
|
-
}
|
|
267
225
|
interface WorktreeInfo {
|
|
268
226
|
worktreePath: string;
|
|
269
227
|
worktreeName: string;
|
|
@@ -416,13 +374,14 @@ type StreamPair = {
|
|
|
416
374
|
};
|
|
417
375
|
|
|
418
376
|
/**
|
|
419
|
-
*
|
|
420
|
-
* and could use some cleanup.
|
|
377
|
+
* Shared ACP connection factory.
|
|
421
378
|
*
|
|
422
|
-
*
|
|
379
|
+
* Creates ACP connections for the Claude Code agent.
|
|
423
380
|
*/
|
|
424
381
|
|
|
382
|
+
type AgentFramework = "claude";
|
|
425
383
|
type AcpConnectionConfig = {
|
|
384
|
+
framework?: AgentFramework;
|
|
426
385
|
sessionStore?: SessionStore;
|
|
427
386
|
sessionId?: string;
|
|
428
387
|
taskId?: string;
|
|
@@ -431,6 +390,12 @@ type InProcessAcpConnection = {
|
|
|
431
390
|
agentConnection: AgentSideConnection;
|
|
432
391
|
clientStreams: StreamPair;
|
|
433
392
|
};
|
|
393
|
+
/**
|
|
394
|
+
* Creates an ACP connection with the specified agent framework.
|
|
395
|
+
*
|
|
396
|
+
* @param config - Configuration including framework selection
|
|
397
|
+
* @returns Connection with agent and client streams
|
|
398
|
+
*/
|
|
434
399
|
declare function createAcpConnection(config?: AcpConnectionConfig): InProcessAcpConnection;
|
|
435
400
|
|
|
436
401
|
declare class Agent {
|
|
@@ -439,10 +404,8 @@ declare class Agent {
|
|
|
439
404
|
private posthogAPI?;
|
|
440
405
|
private fileManager;
|
|
441
406
|
private gitManager;
|
|
442
|
-
private templateManager;
|
|
443
407
|
private logger;
|
|
444
408
|
private acpConnection?;
|
|
445
|
-
private promptBuilder;
|
|
446
409
|
private mcpServers?;
|
|
447
410
|
private canUseTool?;
|
|
448
411
|
private currentRunId?;
|
|
@@ -454,11 +417,14 @@ declare class Agent {
|
|
|
454
417
|
*/
|
|
455
418
|
setDebug(enabled: boolean): void;
|
|
456
419
|
/**
|
|
457
|
-
* Configure LLM gateway environment variables for Claude Code CLI
|
|
420
|
+
* Configure LLM gateway environment variables for Claude Code CLI.
|
|
458
421
|
*/
|
|
459
422
|
private _configureLlmGateway;
|
|
460
|
-
|
|
461
|
-
|
|
423
|
+
/**
|
|
424
|
+
* @deprecated Use runTaskV2() for local execution or runTaskCloud() for cloud execution.
|
|
425
|
+
* This method used the old workflow system which has been removed.
|
|
426
|
+
*/
|
|
427
|
+
runTask(_taskId: string, _taskRunId: string, _options?: TaskExecutionOptions): Promise<void>;
|
|
462
428
|
/**
|
|
463
429
|
* Creates an in-process ACP connection for client communication.
|
|
464
430
|
* Sets up git branch for the task, configures LLM gateway.
|
|
@@ -482,8 +448,8 @@ declare class Agent {
|
|
|
482
448
|
getTaskExecutionStatus(taskId: string): string | null;
|
|
483
449
|
private prepareTaskBranch;
|
|
484
450
|
private ensureOpenAIGatewayEnv;
|
|
451
|
+
private ensureGeminiGatewayEnv;
|
|
485
452
|
runTaskCloud(taskId: string, taskRunId: string, options?: TaskExecutionOptions): Promise<void>;
|
|
486
|
-
private ensurePullRequest;
|
|
487
453
|
}
|
|
488
454
|
|
|
489
455
|
declare const TokenEventSchema: z.ZodObject<{
|
|
@@ -699,13 +665,13 @@ declare const AgentEventSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
|
|
|
699
665
|
}, "strip", z.ZodTypeAny, {
|
|
700
666
|
type: "message_start";
|
|
701
667
|
ts: number;
|
|
702
|
-
model?: string | undefined;
|
|
703
668
|
messageId?: string | undefined;
|
|
669
|
+
model?: string | undefined;
|
|
704
670
|
}, {
|
|
705
671
|
type: "message_start";
|
|
706
672
|
ts: number;
|
|
707
|
-
model?: string | undefined;
|
|
708
673
|
messageId?: string | undefined;
|
|
674
|
+
model?: string | undefined;
|
|
709
675
|
}>, z.ZodObject<{
|
|
710
676
|
ts: z.ZodNumber;
|
|
711
677
|
} & {
|
|
@@ -723,18 +689,18 @@ declare const AgentEventSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
|
|
|
723
689
|
type: "message_delta";
|
|
724
690
|
ts: number;
|
|
725
691
|
stopReason?: string | undefined;
|
|
692
|
+
stopSequence?: string | undefined;
|
|
726
693
|
usage?: {
|
|
727
694
|
outputTokens: number;
|
|
728
695
|
} | undefined;
|
|
729
|
-
stopSequence?: string | undefined;
|
|
730
696
|
}, {
|
|
731
697
|
type: "message_delta";
|
|
732
698
|
ts: number;
|
|
733
699
|
stopReason?: string | undefined;
|
|
700
|
+
stopSequence?: string | undefined;
|
|
734
701
|
usage?: {
|
|
735
702
|
outputTokens: number;
|
|
736
703
|
} | undefined;
|
|
737
|
-
stopSequence?: string | undefined;
|
|
738
704
|
}>, z.ZodObject<{
|
|
739
705
|
ts: z.ZodNumber;
|
|
740
706
|
} & {
|
|
@@ -819,33 +785,33 @@ declare const AgentEventSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
|
|
|
819
785
|
}, "strip", z.ZodTypeAny, {
|
|
820
786
|
type: "init";
|
|
821
787
|
tools: string[];
|
|
822
|
-
|
|
788
|
+
ts: number;
|
|
823
789
|
model: string;
|
|
824
790
|
permissionMode: string;
|
|
791
|
+
cwd: string;
|
|
825
792
|
apiKeySource: string;
|
|
826
|
-
|
|
793
|
+
agents?: string[] | undefined;
|
|
794
|
+
slashCommands?: string[] | undefined;
|
|
795
|
+
outputStyle?: string | undefined;
|
|
827
796
|
mcpServers?: {
|
|
828
797
|
status: string;
|
|
829
798
|
name: string;
|
|
830
799
|
}[] | undefined;
|
|
831
|
-
agents?: string[] | undefined;
|
|
832
|
-
slashCommands?: string[] | undefined;
|
|
833
|
-
outputStyle?: string | undefined;
|
|
834
800
|
}, {
|
|
835
801
|
type: "init";
|
|
836
802
|
tools: string[];
|
|
837
|
-
|
|
803
|
+
ts: number;
|
|
838
804
|
model: string;
|
|
839
805
|
permissionMode: string;
|
|
806
|
+
cwd: string;
|
|
840
807
|
apiKeySource: string;
|
|
841
|
-
|
|
808
|
+
agents?: string[] | undefined;
|
|
809
|
+
slashCommands?: string[] | undefined;
|
|
810
|
+
outputStyle?: string | undefined;
|
|
842
811
|
mcpServers?: {
|
|
843
812
|
status: string;
|
|
844
813
|
name: string;
|
|
845
814
|
}[] | undefined;
|
|
846
|
-
agents?: string[] | undefined;
|
|
847
|
-
slashCommands?: string[] | undefined;
|
|
848
|
-
outputStyle?: string | undefined;
|
|
849
815
|
}>, z.ZodObject<{
|
|
850
816
|
ts: z.ZodNumber;
|
|
851
817
|
} & {
|
|
@@ -919,18 +885,22 @@ declare const AgentEventSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
|
|
|
919
885
|
tool_input: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
920
886
|
}, "strip", z.ZodTypeAny, {
|
|
921
887
|
tool_use_id: string;
|
|
922
|
-
tool_name: string;
|
|
923
888
|
tool_input: Record<string, unknown>;
|
|
889
|
+
tool_name: string;
|
|
924
890
|
}, {
|
|
925
891
|
tool_use_id: string;
|
|
926
|
-
tool_name: string;
|
|
927
892
|
tool_input: Record<string, unknown>;
|
|
893
|
+
tool_name: string;
|
|
928
894
|
}>, "many">>;
|
|
929
895
|
}, "strip", z.ZodTypeAny, {
|
|
930
896
|
type: "done";
|
|
931
897
|
ts: number;
|
|
932
898
|
result?: string | undefined;
|
|
933
899
|
usage?: unknown;
|
|
900
|
+
durationMs?: number | undefined;
|
|
901
|
+
durationApiMs?: number | undefined;
|
|
902
|
+
numTurns?: number | undefined;
|
|
903
|
+
totalCostUsd?: number | undefined;
|
|
934
904
|
modelUsage?: Record<string, {
|
|
935
905
|
outputTokens: number;
|
|
936
906
|
inputTokens: number;
|
|
@@ -940,20 +910,20 @@ declare const AgentEventSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
|
|
|
940
910
|
costUSD: number;
|
|
941
911
|
contextWindow: number;
|
|
942
912
|
}> | undefined;
|
|
943
|
-
durationMs?: number | undefined;
|
|
944
|
-
durationApiMs?: number | undefined;
|
|
945
|
-
numTurns?: number | undefined;
|
|
946
|
-
totalCostUsd?: number | undefined;
|
|
947
913
|
permissionDenials?: {
|
|
948
914
|
tool_use_id: string;
|
|
949
|
-
tool_name: string;
|
|
950
915
|
tool_input: Record<string, unknown>;
|
|
916
|
+
tool_name: string;
|
|
951
917
|
}[] | undefined;
|
|
952
918
|
}, {
|
|
953
919
|
type: "done";
|
|
954
920
|
ts: number;
|
|
955
921
|
result?: string | undefined;
|
|
956
922
|
usage?: unknown;
|
|
923
|
+
durationMs?: number | undefined;
|
|
924
|
+
durationApiMs?: number | undefined;
|
|
925
|
+
numTurns?: number | undefined;
|
|
926
|
+
totalCostUsd?: number | undefined;
|
|
957
927
|
modelUsage?: Record<string, {
|
|
958
928
|
outputTokens: number;
|
|
959
929
|
inputTokens: number;
|
|
@@ -963,14 +933,10 @@ declare const AgentEventSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
|
|
|
963
933
|
costUSD: number;
|
|
964
934
|
contextWindow: number;
|
|
965
935
|
}> | undefined;
|
|
966
|
-
durationMs?: number | undefined;
|
|
967
|
-
durationApiMs?: number | undefined;
|
|
968
|
-
numTurns?: number | undefined;
|
|
969
|
-
totalCostUsd?: number | undefined;
|
|
970
936
|
permissionDenials?: {
|
|
971
937
|
tool_use_id: string;
|
|
972
|
-
tool_name: string;
|
|
973
938
|
tool_input: Record<string, unknown>;
|
|
939
|
+
tool_name: string;
|
|
974
940
|
}[] | undefined;
|
|
975
941
|
}>, z.ZodObject<{
|
|
976
942
|
ts: z.ZodNumber;
|
|
@@ -1093,8 +1059,6 @@ declare class PostHogFileManager {
|
|
|
1093
1059
|
readContext(taskId: string): Promise<string | null>;
|
|
1094
1060
|
writeRequirements(taskId: string, requirements: string): Promise<void>;
|
|
1095
1061
|
readRequirements(taskId: string): Promise<string | null>;
|
|
1096
|
-
writeResearch(taskId: string, data: ResearchEvaluation): Promise<void>;
|
|
1097
|
-
readResearch(taskId: string): Promise<ResearchEvaluation | null>;
|
|
1098
1062
|
writeTodos(taskId: string, data: unknown): Promise<void>;
|
|
1099
1063
|
readTodos(taskId: string): Promise<unknown | null>;
|
|
1100
1064
|
getTaskFiles(taskId: string): Promise<SupportingFile[]>;
|
|
@@ -1200,6 +1164,10 @@ interface ExitPlanModeTool extends Tool {
|
|
|
1200
1164
|
name: "ExitPlanMode";
|
|
1201
1165
|
category: "assistant";
|
|
1202
1166
|
}
|
|
1167
|
+
interface AskUserQuestionTool extends Tool {
|
|
1168
|
+
name: "AskUserQuestion";
|
|
1169
|
+
category: "assistant";
|
|
1170
|
+
}
|
|
1203
1171
|
interface SlashCommandTool extends Tool {
|
|
1204
1172
|
name: "SlashCommand";
|
|
1205
1173
|
category: "assistant";
|
|
@@ -1208,7 +1176,7 @@ interface SlashCommandTool extends Tool {
|
|
|
1208
1176
|
* Union type of all known tool types.
|
|
1209
1177
|
* Useful for discriminated unions and type narrowing.
|
|
1210
1178
|
*/
|
|
1211
|
-
type KnownTool = ReadTool | WriteTool | EditTool | GlobTool | NotebookEditTool | BashTool | BashOutputTool | KillShellTool | WebFetchTool | WebSearchTool | GrepTool | TaskTool | TodoWriteTool | ExitPlanModeTool | SlashCommandTool;
|
|
1179
|
+
type KnownTool = ReadTool | WriteTool | EditTool | GlobTool | NotebookEditTool | BashTool | BashOutputTool | KillShellTool | WebFetchTool | WebSearchTool | GrepTool | TaskTool | TodoWriteTool | ExitPlanModeTool | AskUserQuestionTool | SlashCommandTool;
|
|
1212
1180
|
|
|
1213
1181
|
/**
|
|
1214
1182
|
* Tool registry for looking up tool definitions by name.
|
|
@@ -1234,6 +1202,8 @@ declare class ToolRegistry {
|
|
|
1234
1202
|
getByCategory(category: string): Tool[];
|
|
1235
1203
|
}
|
|
1236
1204
|
|
|
1205
|
+
declare function getLlmGatewayUrl(posthogHost: string): string;
|
|
1206
|
+
|
|
1237
1207
|
interface WorktreeConfig {
|
|
1238
1208
|
mainRepoPath: string;
|
|
1239
1209
|
worktreeBasePath?: string;
|
|
@@ -1273,4 +1243,4 @@ declare class WorktreeManager {
|
|
|
1273
1243
|
}>;
|
|
1274
1244
|
}
|
|
1275
1245
|
|
|
1276
|
-
export { type AcpConnectionConfig, Agent, type AgentConfig, type AgentEvent, type
|
|
1246
|
+
export { type AcpConnectionConfig, Agent, type AgentConfig, type AgentEvent, type AgentFramework, type AskUserQuestionTool, type BashOutputTool, type BashTool, type BranchCreatedPayload, type ConsoleEvent, type ConsoleNotificationPayload, type EditTool, type ErrorEvent, type ErrorNotificationPayload, type ExecutionResult, type ExitPlanModeTool, type GlobTool, type GrepTool, type InProcessAcpConnection, type KillShellTool, type KnownTool, LogLevel, type LogLevel$1 as LogLevelType, Logger, type LoggerConfig, type McpServerConfig, type NotebookEditTool, type OnLogCallback, POSTHOG_NOTIFICATIONS, PermissionMode, type PostHogNotificationPayload, type PostHogNotificationType, type ReadTool, type RunStartedPayload, type SdkSessionPayload, type SessionPersistenceConfig, SessionStore, type SlashCommandTool, type StatusEvent, type StoredEntry, type StoredNotification, type SupportingFile, type Task, type TaskCompletePayload, type TaskRun, type TaskTool, type TodoItem, type TodoList, TodoManager, type TodoWriteTool, type TokenEvent, type Tool, type ToolCategory, ToolRegistry, type WebFetchTool, type WebSearchTool, type WorktreeConfig, type WorktreeInfo, WorktreeManager, type WriteTool, createAcpConnection, getLlmGatewayUrl, parseAgentEvent, parseAgentEvents };
|