@posthog/agent 1.30.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 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 */
@@ -37,31 +29,11 @@ declare const POSTHOG_NOTIFICATIONS: {
37
29
  readonly CONSOLE: "_posthog/console";
38
30
  /** SDK session ID notification (for resumption) */
39
31
  readonly SDK_SESSION: "_posthog/sdk_session";
40
- /** Sandbox execution output (stdout/stderr from Modal or Docker) */
41
- readonly SANDBOX_OUTPUT: "_posthog/sandbox_output";
42
32
  };
43
33
  type PostHogNotificationType = (typeof POSTHOG_NOTIFICATIONS)[keyof typeof POSTHOG_NOTIFICATIONS];
44
- interface ArtifactNotificationPayload {
45
- sessionId: string;
46
- kind: "research_evaluation" | "research_questions" | "plan" | "pr_body" | string;
47
- content: unknown;
48
- }
49
- interface PhaseNotificationPayload {
50
- sessionId: string;
51
- phase: "research" | "plan" | "build" | "finalize" | string;
52
- [key: string]: unknown;
53
- }
54
34
  interface BranchCreatedPayload {
55
- sessionId: string;
56
35
  branch: string;
57
36
  }
58
- /**
59
- * Payload for PR created notification
60
- */
61
- interface PrCreatedPayload {
62
- sessionId: string;
63
- prUrl: string;
64
- }
65
37
  interface RunStartedPayload {
66
38
  sessionId: string;
67
39
  runId: string;
@@ -94,16 +66,7 @@ interface SdkSessionPayload {
94
66
  sessionId: string;
95
67
  sdkSessionId: string;
96
68
  }
97
- /**
98
- * Sandbox execution output
99
- */
100
- interface SandboxOutputPayload {
101
- sessionId: string;
102
- stdout: string;
103
- stderr: string;
104
- exitCode: number;
105
- }
106
- type PostHogNotificationPayload = ArtifactNotificationPayload | PhaseNotificationPayload | BranchCreatedPayload | PrCreatedPayload | RunStartedPayload | TaskCompletePayload | ErrorNotificationPayload | ConsoleNotificationPayload | SdkSessionPayload | SandboxOutputPayload;
69
+ type PostHogNotificationPayload = BranchCreatedPayload | RunStartedPayload | TaskCompletePayload | ErrorNotificationPayload | ConsoleNotificationPayload | SdkSessionPayload;
107
70
 
108
71
  /**
109
72
  * Stored custom notification following ACP extensibility model.
@@ -201,6 +164,9 @@ interface TaskExecutionOptions {
201
164
  queryOverrides?: Record<string, unknown>;
202
165
  canUseTool?: CanUseTool;
203
166
  skipGitBranch?: boolean;
167
+ framework?: "claude";
168
+ task?: Task;
169
+ isReconnect?: boolean;
204
170
  }
205
171
  interface ExecutionResult {
206
172
  results: any[];
@@ -256,25 +222,6 @@ interface UrlMention {
256
222
  id?: string;
257
223
  label?: string;
258
224
  }
259
- interface ResearchQuestion {
260
- id: string;
261
- question: string;
262
- options: string[];
263
- }
264
- interface ResearchAnswer {
265
- questionId: string;
266
- selectedOption: string;
267
- customInput?: string;
268
- }
269
- interface ResearchEvaluation {
270
- actionabilityScore: number;
271
- context: string;
272
- keyFiles: string[];
273
- blockers?: string[];
274
- questions?: ResearchQuestion[];
275
- answered?: boolean;
276
- answers?: ResearchAnswer[];
277
- }
278
225
  interface WorktreeInfo {
279
226
  worktreePath: string;
280
227
  worktreeName: string;
@@ -427,13 +374,14 @@ type StreamPair = {
427
374
  };
428
375
 
429
376
  /**
430
- * The claude adapter has been based on the original claude-code-acp adapter,
431
- * and could use some cleanup.
377
+ * Shared ACP connection factory.
432
378
  *
433
- * https://github.com/zed-industries/claude-code-acp
379
+ * Creates ACP connections for the Claude Code agent.
434
380
  */
435
381
 
382
+ type AgentFramework = "claude";
436
383
  type AcpConnectionConfig = {
384
+ framework?: AgentFramework;
437
385
  sessionStore?: SessionStore;
438
386
  sessionId?: string;
439
387
  taskId?: string;
@@ -442,6 +390,12 @@ type InProcessAcpConnection = {
442
390
  agentConnection: AgentSideConnection;
443
391
  clientStreams: StreamPair;
444
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
+ */
445
399
  declare function createAcpConnection(config?: AcpConnectionConfig): InProcessAcpConnection;
446
400
 
447
401
  declare class Agent {
@@ -450,10 +404,8 @@ declare class Agent {
450
404
  private posthogAPI?;
451
405
  private fileManager;
452
406
  private gitManager;
453
- private templateManager;
454
407
  private logger;
455
408
  private acpConnection?;
456
- private promptBuilder;
457
409
  private mcpServers?;
458
410
  private canUseTool?;
459
411
  private currentRunId?;
@@ -468,8 +420,11 @@ declare class Agent {
468
420
  * Configure LLM gateway environment variables for Claude Code CLI.
469
421
  */
470
422
  private _configureLlmGateway;
471
- private getOrCreateConnection;
472
- runTask(taskId: string, taskRunId: string, options?: TaskExecutionOptions): Promise<void>;
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>;
473
428
  /**
474
429
  * Creates an in-process ACP connection for client communication.
475
430
  * Sets up git branch for the task, configures LLM gateway.
@@ -495,7 +450,6 @@ declare class Agent {
495
450
  private ensureOpenAIGatewayEnv;
496
451
  private ensureGeminiGatewayEnv;
497
452
  runTaskCloud(taskId: string, taskRunId: string, options?: TaskExecutionOptions): Promise<void>;
498
- private ensurePullRequest;
499
453
  }
500
454
 
501
455
  declare const TokenEventSchema: z.ZodObject<{
@@ -711,13 +665,13 @@ declare const AgentEventSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
711
665
  }, "strip", z.ZodTypeAny, {
712
666
  type: "message_start";
713
667
  ts: number;
714
- model?: string | undefined;
715
668
  messageId?: string | undefined;
669
+ model?: string | undefined;
716
670
  }, {
717
671
  type: "message_start";
718
672
  ts: number;
719
- model?: string | undefined;
720
673
  messageId?: string | undefined;
674
+ model?: string | undefined;
721
675
  }>, z.ZodObject<{
722
676
  ts: z.ZodNumber;
723
677
  } & {
@@ -735,18 +689,18 @@ declare const AgentEventSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
735
689
  type: "message_delta";
736
690
  ts: number;
737
691
  stopReason?: string | undefined;
692
+ stopSequence?: string | undefined;
738
693
  usage?: {
739
694
  outputTokens: number;
740
695
  } | undefined;
741
- stopSequence?: string | undefined;
742
696
  }, {
743
697
  type: "message_delta";
744
698
  ts: number;
745
699
  stopReason?: string | undefined;
700
+ stopSequence?: string | undefined;
746
701
  usage?: {
747
702
  outputTokens: number;
748
703
  } | undefined;
749
- stopSequence?: string | undefined;
750
704
  }>, z.ZodObject<{
751
705
  ts: z.ZodNumber;
752
706
  } & {
@@ -831,33 +785,33 @@ declare const AgentEventSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
831
785
  }, "strip", z.ZodTypeAny, {
832
786
  type: "init";
833
787
  tools: string[];
834
- cwd: string;
788
+ ts: number;
835
789
  model: string;
836
790
  permissionMode: string;
791
+ cwd: string;
837
792
  apiKeySource: string;
838
- ts: number;
793
+ agents?: string[] | undefined;
794
+ slashCommands?: string[] | undefined;
795
+ outputStyle?: string | undefined;
839
796
  mcpServers?: {
840
797
  status: string;
841
798
  name: string;
842
799
  }[] | undefined;
843
- agents?: string[] | undefined;
844
- slashCommands?: string[] | undefined;
845
- outputStyle?: string | undefined;
846
800
  }, {
847
801
  type: "init";
848
802
  tools: string[];
849
- cwd: string;
803
+ ts: number;
850
804
  model: string;
851
805
  permissionMode: string;
806
+ cwd: string;
852
807
  apiKeySource: string;
853
- ts: number;
808
+ agents?: string[] | undefined;
809
+ slashCommands?: string[] | undefined;
810
+ outputStyle?: string | undefined;
854
811
  mcpServers?: {
855
812
  status: string;
856
813
  name: string;
857
814
  }[] | undefined;
858
- agents?: string[] | undefined;
859
- slashCommands?: string[] | undefined;
860
- outputStyle?: string | undefined;
861
815
  }>, z.ZodObject<{
862
816
  ts: z.ZodNumber;
863
817
  } & {
@@ -931,18 +885,22 @@ declare const AgentEventSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
931
885
  tool_input: z.ZodRecord<z.ZodString, z.ZodUnknown>;
932
886
  }, "strip", z.ZodTypeAny, {
933
887
  tool_use_id: string;
934
- tool_name: string;
935
888
  tool_input: Record<string, unknown>;
889
+ tool_name: string;
936
890
  }, {
937
891
  tool_use_id: string;
938
- tool_name: string;
939
892
  tool_input: Record<string, unknown>;
893
+ tool_name: string;
940
894
  }>, "many">>;
941
895
  }, "strip", z.ZodTypeAny, {
942
896
  type: "done";
943
897
  ts: number;
944
898
  result?: string | undefined;
945
899
  usage?: unknown;
900
+ durationMs?: number | undefined;
901
+ durationApiMs?: number | undefined;
902
+ numTurns?: number | undefined;
903
+ totalCostUsd?: number | undefined;
946
904
  modelUsage?: Record<string, {
947
905
  outputTokens: number;
948
906
  inputTokens: number;
@@ -952,20 +910,20 @@ declare const AgentEventSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
952
910
  costUSD: number;
953
911
  contextWindow: number;
954
912
  }> | undefined;
955
- durationMs?: number | undefined;
956
- durationApiMs?: number | undefined;
957
- numTurns?: number | undefined;
958
- totalCostUsd?: number | undefined;
959
913
  permissionDenials?: {
960
914
  tool_use_id: string;
961
- tool_name: string;
962
915
  tool_input: Record<string, unknown>;
916
+ tool_name: string;
963
917
  }[] | undefined;
964
918
  }, {
965
919
  type: "done";
966
920
  ts: number;
967
921
  result?: string | undefined;
968
922
  usage?: unknown;
923
+ durationMs?: number | undefined;
924
+ durationApiMs?: number | undefined;
925
+ numTurns?: number | undefined;
926
+ totalCostUsd?: number | undefined;
969
927
  modelUsage?: Record<string, {
970
928
  outputTokens: number;
971
929
  inputTokens: number;
@@ -975,14 +933,10 @@ declare const AgentEventSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
975
933
  costUSD: number;
976
934
  contextWindow: number;
977
935
  }> | undefined;
978
- durationMs?: number | undefined;
979
- durationApiMs?: number | undefined;
980
- numTurns?: number | undefined;
981
- totalCostUsd?: number | undefined;
982
936
  permissionDenials?: {
983
937
  tool_use_id: string;
984
- tool_name: string;
985
938
  tool_input: Record<string, unknown>;
939
+ tool_name: string;
986
940
  }[] | undefined;
987
941
  }>, z.ZodObject<{
988
942
  ts: z.ZodNumber;
@@ -1105,8 +1059,6 @@ declare class PostHogFileManager {
1105
1059
  readContext(taskId: string): Promise<string | null>;
1106
1060
  writeRequirements(taskId: string, requirements: string): Promise<void>;
1107
1061
  readRequirements(taskId: string): Promise<string | null>;
1108
- writeResearch(taskId: string, data: ResearchEvaluation): Promise<void>;
1109
- readResearch(taskId: string): Promise<ResearchEvaluation | null>;
1110
1062
  writeTodos(taskId: string, data: unknown): Promise<void>;
1111
1063
  readTodos(taskId: string): Promise<unknown | null>;
1112
1064
  getTaskFiles(taskId: string): Promise<SupportingFile[]>;
@@ -1212,6 +1164,10 @@ interface ExitPlanModeTool extends Tool {
1212
1164
  name: "ExitPlanMode";
1213
1165
  category: "assistant";
1214
1166
  }
1167
+ interface AskUserQuestionTool extends Tool {
1168
+ name: "AskUserQuestion";
1169
+ category: "assistant";
1170
+ }
1215
1171
  interface SlashCommandTool extends Tool {
1216
1172
  name: "SlashCommand";
1217
1173
  category: "assistant";
@@ -1220,7 +1176,7 @@ interface SlashCommandTool extends Tool {
1220
1176
  * Union type of all known tool types.
1221
1177
  * Useful for discriminated unions and type narrowing.
1222
1178
  */
1223
- 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;
1224
1180
 
1225
1181
  /**
1226
1182
  * Tool registry for looking up tool definitions by name.
@@ -1287,4 +1243,4 @@ declare class WorktreeManager {
1287
1243
  }>;
1288
1244
  }
1289
1245
 
1290
- export { type AcpConnectionConfig, Agent, type AgentConfig, type AgentEvent, type ArtifactNotificationPayload, 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 PhaseNotificationPayload, type PostHogNotificationPayload, type PostHogNotificationType, type PrCreatedPayload, type ReadTool, type ResearchEvaluation, 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 };
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 };