@posthog/agent 2.3.658 → 2.3.670

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/types.d.ts CHANGED
@@ -91,6 +91,8 @@ interface TaskExecutionOptions {
91
91
  processCallbacks?: ProcessSpawnedCallback;
92
92
  /** Callback invoked when the agent calls the create_output tool for structured output */
93
93
  onStructuredOutput?: (output: Record<string, unknown>) => Promise<void>;
94
+ /** Additional directories the agent process can access beyond cwd. */
95
+ additionalDirectories?: string[];
94
96
  }
95
97
  type LogLevel = "debug" | "info" | "warn" | "error";
96
98
  type OnLogCallback = (level: LogLevel, scope: string, message: string, data?: unknown) => void;
package/dist/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type {\n GitHandoffCheckpoint,\n HandoffLocalGitState as GitHandoffLocalGitState,\n} from \"@posthog/git/handoff\";\n\n/**\n * Stored custom notification following ACP extensibility model.\n * Custom notifications use underscore-prefixed methods (e.g., `_posthog/phase_start`).\n * See: https://agentclientprotocol.com/docs/extensibility\n */\nexport interface StoredNotification {\n type: \"notification\";\n /** When this notification was stored */\n timestamp: string;\n /** JSON-RPC 2.0 notification (no id field = notification, not request) */\n notification: {\n jsonrpc: \"2.0\";\n method: string;\n params?: Record<string, unknown>;\n };\n}\n\n/**\n * Type alias for stored log entries.\n */\nexport type StoredEntry = StoredNotification;\n\n// PostHog Task model (matches PostHog Code's OpenAPI schema)\nexport interface Task {\n id: string;\n task_number?: number;\n slug?: string;\n title: string;\n description: string;\n origin_product:\n | \"error_tracking\"\n | \"eval_clusters\"\n | \"user_created\"\n | \"support_queue\"\n | \"session_summaries\"\n | \"signal_report\";\n github_integration?: number | null;\n repository: string; // Format: \"organization/repository\" (e.g., \"posthog/posthog-js\")\n json_schema?: Record<string, unknown> | null; // JSON schema for task output validation\n internal?: boolean;\n created_at: string;\n updated_at: string;\n created_by?: {\n id: number;\n uuid: string;\n distinct_id: string;\n first_name: string;\n email: string;\n };\n latest_run?: TaskRun;\n}\n\n// Log entry structure for TaskRun.log\n\nexport type ArtifactType =\n | \"plan\"\n | \"context\"\n | \"reference\"\n | \"output\"\n | \"artifact\"\n | \"user_attachment\";\n\nexport interface TaskRunArtifact {\n id?: string;\n name: string;\n type: ArtifactType;\n source?: string;\n size?: number;\n content_type?: string;\n storage_path?: string;\n uploaded_at?: string;\n}\n\nexport type TaskRunStatus =\n | \"not_started\"\n | \"queued\"\n | \"in_progress\"\n | \"completed\"\n | \"failed\"\n | \"cancelled\";\n\nexport type TaskRunEnvironment = \"local\" | \"cloud\";\n\n// TaskRun model - represents individual execution runs of tasks\nexport interface TaskRun {\n id: string;\n task: string; // Task ID\n team: number;\n branch: string | null;\n stage: string | null; // Current stage (e.g., 'research', 'plan', 'build')\n environment: TaskRunEnvironment;\n status: TaskRunStatus;\n log_url: string;\n error_message: string | null;\n output: Record<string, unknown> | null; // Structured output (PR URL, commit SHA, etc.)\n state: Record<string, unknown>; // Intermediate run state (defaults to {}, never null)\n artifacts?: TaskRunArtifact[];\n created_at: string;\n updated_at: string;\n completed_at: string | null;\n}\n\nexport interface ProcessSpawnedCallback {\n onProcessSpawned?: (info: {\n pid: number;\n command: string;\n sessionId?: string;\n }) => void;\n onProcessExited?: (pid: number) => void;\n onMcpServersReady?: (serverNames: string[]) => void;\n}\n\nexport interface TaskExecutionOptions {\n repositoryPath?: string;\n adapter?: \"claude\" | \"codex\";\n model?: string;\n gatewayUrl?: string;\n codexBinaryPath?: string;\n instructions?: string;\n processCallbacks?: ProcessSpawnedCallback;\n /** Callback invoked when the agent calls the create_output tool for structured output */\n onStructuredOutput?: (output: Record<string, unknown>) => Promise<void>;\n}\n\nexport type LogLevel = \"debug\" | \"info\" | \"warn\" | \"error\";\n\nexport type OnLogCallback = (\n level: LogLevel,\n scope: string,\n message: string,\n data?: unknown,\n) => void;\n\nexport interface PostHogAPIConfig {\n apiUrl: string;\n getApiKey: () => string | Promise<string>;\n refreshApiKey?: () => string | Promise<string>;\n projectId: number;\n userAgent?: string;\n}\n\nexport interface OtelTransportConfig {\n /** PostHog ingest host, e.g., \"https://us.i.posthog.com\" */\n host: string;\n /** Project API key */\n apiKey: string;\n /** Override the logs endpoint path (default: /i/v1/logs) */\n logsPath?: string;\n}\n\nexport interface AgentConfig {\n posthog?: PostHogAPIConfig;\n /** OTEL transport config for shipping logs to PostHog Logs */\n otelTransport?: OtelTransportConfig;\n /** Skip session log persistence (e.g. for preview sessions with no real task) */\n skipLogPersistence?: boolean;\n /** Local cache path for instant log loading (e.g., ~/.posthog-code) */\n localCachePath?: string;\n /**\n * Annotate files the agent reads with PostHog enrichment (event volume,\n * flag rollout/staleness, experiment links). Defaults to enabled when\n * `posthog` config is present; set `{ enabled: false }` to opt out.\n */\n enricher?: { enabled?: boolean };\n debug?: boolean;\n onLog?: OnLogCallback;\n}\n\n// Device info for tracking where work happens\nexport interface DeviceInfo {\n type: \"local\" | \"cloud\";\n name?: string;\n}\n\n// Agent execution mode - for tracking interactive vs background runs, when backgrounded an agent will continue working without asking questions\nexport type AgentMode = \"interactive\" | \"background\";\n\n// Git file status codes\nexport type FileStatus = \"A\" | \"M\" | \"D\";\n\nexport interface FileChange {\n path: string;\n status: FileStatus;\n}\n\nexport type HandoffLocalGitState = GitHandoffLocalGitState;\n\nexport interface GitCheckpoint extends GitHandoffCheckpoint {\n artifactPath?: string;\n indexArtifactPath?: string;\n}\n\nexport interface GitCheckpointEvent extends GitCheckpoint {\n device?: DeviceInfo;\n}\n\n/**\n * Keeps the emitted `@posthog/agent/types` entrypoint as a runtime ESM module.\n *\n * `export {}` is stripped by tsup in this package, which leaves `dist/types.js`\n * empty and breaks downstream type resolution for the exported subpath.\n */\nexport const AGENT_TYPES_MODULE = true;\n"],"mappings":";AA+MO,IAAM,qBAAqB;","names":[]}
1
+ {"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type {\n GitHandoffCheckpoint,\n HandoffLocalGitState as GitHandoffLocalGitState,\n} from \"@posthog/git/handoff\";\n\n/**\n * Stored custom notification following ACP extensibility model.\n * Custom notifications use underscore-prefixed methods (e.g., `_posthog/phase_start`).\n * See: https://agentclientprotocol.com/docs/extensibility\n */\nexport interface StoredNotification {\n type: \"notification\";\n /** When this notification was stored */\n timestamp: string;\n /** JSON-RPC 2.0 notification (no id field = notification, not request) */\n notification: {\n jsonrpc: \"2.0\";\n method: string;\n params?: Record<string, unknown>;\n };\n}\n\n/**\n * Type alias for stored log entries.\n */\nexport type StoredEntry = StoredNotification;\n\n// PostHog Task model (matches PostHog Code's OpenAPI schema)\nexport interface Task {\n id: string;\n task_number?: number;\n slug?: string;\n title: string;\n description: string;\n origin_product:\n | \"error_tracking\"\n | \"eval_clusters\"\n | \"user_created\"\n | \"support_queue\"\n | \"session_summaries\"\n | \"signal_report\";\n github_integration?: number | null;\n repository: string; // Format: \"organization/repository\" (e.g., \"posthog/posthog-js\")\n json_schema?: Record<string, unknown> | null; // JSON schema for task output validation\n internal?: boolean;\n created_at: string;\n updated_at: string;\n created_by?: {\n id: number;\n uuid: string;\n distinct_id: string;\n first_name: string;\n email: string;\n };\n latest_run?: TaskRun;\n}\n\n// Log entry structure for TaskRun.log\n\nexport type ArtifactType =\n | \"plan\"\n | \"context\"\n | \"reference\"\n | \"output\"\n | \"artifact\"\n | \"user_attachment\";\n\nexport interface TaskRunArtifact {\n id?: string;\n name: string;\n type: ArtifactType;\n source?: string;\n size?: number;\n content_type?: string;\n storage_path?: string;\n uploaded_at?: string;\n}\n\nexport type TaskRunStatus =\n | \"not_started\"\n | \"queued\"\n | \"in_progress\"\n | \"completed\"\n | \"failed\"\n | \"cancelled\";\n\nexport type TaskRunEnvironment = \"local\" | \"cloud\";\n\n// TaskRun model - represents individual execution runs of tasks\nexport interface TaskRun {\n id: string;\n task: string; // Task ID\n team: number;\n branch: string | null;\n stage: string | null; // Current stage (e.g., 'research', 'plan', 'build')\n environment: TaskRunEnvironment;\n status: TaskRunStatus;\n log_url: string;\n error_message: string | null;\n output: Record<string, unknown> | null; // Structured output (PR URL, commit SHA, etc.)\n state: Record<string, unknown>; // Intermediate run state (defaults to {}, never null)\n artifacts?: TaskRunArtifact[];\n created_at: string;\n updated_at: string;\n completed_at: string | null;\n}\n\nexport interface ProcessSpawnedCallback {\n onProcessSpawned?: (info: {\n pid: number;\n command: string;\n sessionId?: string;\n }) => void;\n onProcessExited?: (pid: number) => void;\n onMcpServersReady?: (serverNames: string[]) => void;\n}\n\nexport interface TaskExecutionOptions {\n repositoryPath?: string;\n adapter?: \"claude\" | \"codex\";\n model?: string;\n gatewayUrl?: string;\n codexBinaryPath?: string;\n instructions?: string;\n processCallbacks?: ProcessSpawnedCallback;\n /** Callback invoked when the agent calls the create_output tool for structured output */\n onStructuredOutput?: (output: Record<string, unknown>) => Promise<void>;\n /** Additional directories the agent process can access beyond cwd. */\n additionalDirectories?: string[];\n}\n\nexport type LogLevel = \"debug\" | \"info\" | \"warn\" | \"error\";\n\nexport type OnLogCallback = (\n level: LogLevel,\n scope: string,\n message: string,\n data?: unknown,\n) => void;\n\nexport interface PostHogAPIConfig {\n apiUrl: string;\n getApiKey: () => string | Promise<string>;\n refreshApiKey?: () => string | Promise<string>;\n projectId: number;\n userAgent?: string;\n}\n\nexport interface OtelTransportConfig {\n /** PostHog ingest host, e.g., \"https://us.i.posthog.com\" */\n host: string;\n /** Project API key */\n apiKey: string;\n /** Override the logs endpoint path (default: /i/v1/logs) */\n logsPath?: string;\n}\n\nexport interface AgentConfig {\n posthog?: PostHogAPIConfig;\n /** OTEL transport config for shipping logs to PostHog Logs */\n otelTransport?: OtelTransportConfig;\n /** Skip session log persistence (e.g. for preview sessions with no real task) */\n skipLogPersistence?: boolean;\n /** Local cache path for instant log loading (e.g., ~/.posthog-code) */\n localCachePath?: string;\n /**\n * Annotate files the agent reads with PostHog enrichment (event volume,\n * flag rollout/staleness, experiment links). Defaults to enabled when\n * `posthog` config is present; set `{ enabled: false }` to opt out.\n */\n enricher?: { enabled?: boolean };\n debug?: boolean;\n onLog?: OnLogCallback;\n}\n\n// Device info for tracking where work happens\nexport interface DeviceInfo {\n type: \"local\" | \"cloud\";\n name?: string;\n}\n\n// Agent execution mode - for tracking interactive vs background runs, when backgrounded an agent will continue working without asking questions\nexport type AgentMode = \"interactive\" | \"background\";\n\n// Git file status codes\nexport type FileStatus = \"A\" | \"M\" | \"D\";\n\nexport interface FileChange {\n path: string;\n status: FileStatus;\n}\n\nexport type HandoffLocalGitState = GitHandoffLocalGitState;\n\nexport interface GitCheckpoint extends GitHandoffCheckpoint {\n artifactPath?: string;\n indexArtifactPath?: string;\n}\n\nexport interface GitCheckpointEvent extends GitCheckpoint {\n device?: DeviceInfo;\n}\n\n/**\n * Keeps the emitted `@posthog/agent/types` entrypoint as a runtime ESM module.\n *\n * `export {}` is stripped by tsup in this package, which leaves `dist/types.js`\n * empty and breaks downstream type resolution for the exported subpath.\n */\nexport const AGENT_TYPES_MODULE = true;\n"],"mappings":";AAiNO,IAAM,qBAAqB;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@posthog/agent",
3
- "version": "2.3.658",
3
+ "version": "2.3.670",
4
4
  "repository": "https://github.com/PostHog/code",
5
5
  "description": "TypeScript agent framework wrapping Claude Agent SDK with Git-based task execution for PostHog",
6
6
  "exports": {
@@ -29,7 +29,7 @@ describe("createLocalToolsMcpServer", () => {
29
29
  it("exposes git_signed_commit over MCP in a cloud run with a token", async () => {
30
30
  const server = createLocalToolsMcpServer(
31
31
  { cwd: "/repo", token: "ghs_x" },
32
- { taskRunId: "run-1" },
32
+ { environment: "cloud" },
33
33
  );
34
34
  if (!server) {
35
35
  throw new Error("expected the local-tools server to be registered");
@@ -121,6 +121,7 @@ export type SDKMessageFilter = {
121
121
  export type NewSessionMeta = {
122
122
  taskRunId?: string;
123
123
  taskId?: string;
124
+ environment?: "local" | "cloud";
124
125
  disableBuiltInTools?: boolean;
125
126
  systemPrompt?: unknown;
126
127
  sessionId?: string;
@@ -97,6 +97,7 @@ export {
97
97
  interface NewSessionMeta {
98
98
  taskRunId?: string;
99
99
  taskId?: string;
100
+ environment?: "local" | "cloud";
100
101
  systemPrompt?: string;
101
102
  permissionMode?: string;
102
103
  model?: string;
@@ -17,6 +17,8 @@ export interface CodexProcessOptions {
17
17
  logger?: Logger;
18
18
  processCallbacks?: ProcessSpawnedCallback;
19
19
  settings?: CodexSettings;
20
+ /** Additional writable roots passed to Codex's workspace-write sandbox. */
21
+ additionalDirectories?: string[];
20
22
  }
21
23
 
22
24
  export interface CodexProcess {
@@ -57,6 +59,13 @@ function buildConfigArgs(options: CodexProcessOptions): string[] {
57
59
  args.push("-c", `model_reasoning_effort="${options.reasoningEffort}"`);
58
60
  }
59
61
 
62
+ if (options.additionalDirectories?.length) {
63
+ const escaped = options.additionalDirectories
64
+ .map((p) => `"${p.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"`)
65
+ .join(",");
66
+ args.push("-c", `sandbox_workspace_write.writable_roots=[${escaped}]`);
67
+ }
68
+
60
69
  if (options.instructions) {
61
70
  const escaped = options.instructions
62
71
  .replace(/\\/g, "\\\\")
@@ -10,7 +10,7 @@ describe("local-tools registry", () => {
10
10
  const savedSandbox = process.env.IS_SANDBOX;
11
11
 
12
12
  beforeEach(() => {
13
- // isCloudRun also keys off IS_SANDBOX; clear it so meta.taskRunId is the
13
+ // isCloudRun also keys off IS_SANDBOX; clear it so meta.environment is the
14
14
  // only cloud signal under test.
15
15
  delete process.env.IS_SANDBOX;
16
16
  });
@@ -35,23 +35,44 @@ describe("local-tools registry", () => {
35
35
  });
36
36
 
37
37
  it.each([
38
- { name: "cloud run with a token", taskRunId: "run-1", token: "ghs_x" },
39
- { name: "cloud run without a token", taskRunId: "run-1", token: undefined },
40
- { name: "desktop run with a token", taskRunId: undefined, token: "ghs_x" },
38
+ {
39
+ name: "cloud run with a token",
40
+ meta: { environment: "cloud" as const },
41
+ token: "ghs_x",
42
+ expected: true,
43
+ },
44
+ {
45
+ name: "cloud run without a token",
46
+ meta: { environment: "cloud" as const },
47
+ token: undefined,
48
+ expected: false,
49
+ },
50
+ {
51
+ name: "desktop run with a token",
52
+ meta: { environment: "local" as const },
53
+ token: "ghs_x",
54
+ expected: false,
55
+ },
41
56
  {
42
57
  name: "desktop run without a token",
43
- taskRunId: undefined,
58
+ meta: { environment: "local" as const },
44
59
  token: undefined,
60
+ expected: false,
45
61
  },
46
62
  ])(
47
63
  "exposes git_signed_commit only in $name when cloud+token",
48
- ({ taskRunId, token }) => {
49
- const tools = enabledLocalTools(
50
- { cwd: "/repo", token },
51
- taskRunId ? { taskRunId } : undefined,
52
- );
64
+ ({ meta, token, expected }) => {
65
+ const tools = enabledLocalTools({ cwd: "/repo", token }, meta);
53
66
  const hasSignedCommit = tools.some((t) => t.name === "git_signed_commit");
54
- expect(hasSignedCommit).toBe(Boolean(taskRunId) && Boolean(token));
67
+ expect(hasSignedCommit).toBe(expected);
55
68
  },
56
69
  );
70
+
71
+ it("does not treat legacy taskRunId-only metadata as cloud", () => {
72
+ const tools = enabledLocalTools({ cwd: "/repo", token: "ghs_x" }, {
73
+ taskRunId: "run-1",
74
+ } as unknown as { environment?: "local" | "cloud" });
75
+ const hasSignedCommit = tools.some((t) => t.name === "git_signed_commit");
76
+ expect(hasSignedCommit).toBe(false);
77
+ });
57
78
  });
@@ -19,7 +19,7 @@ export interface LocalToolCtx {
19
19
 
20
20
  /** Minimal session-meta shape needed to gate tools (e.g. cloud-only). */
21
21
  export interface LocalToolGateMeta {
22
- taskRunId?: string;
22
+ environment?: "local" | "cloud";
23
23
  }
24
24
 
25
25
  /**
package/src/agent.ts CHANGED
@@ -136,6 +136,7 @@ export class Agent {
136
136
  binaryPath: options.codexBinaryPath,
137
137
  model: sanitizedModel,
138
138
  instructions: options.instructions,
139
+ additionalDirectories: options.additionalDirectories,
139
140
  }
140
141
  : undefined,
141
142
  });
@@ -976,6 +976,7 @@ export class AgentServer {
976
976
  sessionId: payload.run_id,
977
977
  taskRunId: payload.run_id,
978
978
  taskId: payload.task_id,
979
+ environment: "cloud",
979
980
  systemPrompt: sessionSystemPrompt,
980
981
  ...(this.config.model && { model: this.config.model }),
981
982
  allowedDomains: this.config.allowedDomains,
package/src/types.ts CHANGED
@@ -125,6 +125,8 @@ export interface TaskExecutionOptions {
125
125
  processCallbacks?: ProcessSpawnedCallback;
126
126
  /** Callback invoked when the agent calls the create_output tool for structured output */
127
127
  onStructuredOutput?: (output: Record<string, unknown>) => Promise<void>;
128
+ /** Additional directories the agent process can access beyond cwd. */
129
+ additionalDirectories?: string[];
128
130
  }
129
131
 
130
132
  export type LogLevel = "debug" | "info" | "warn" | "error";
@@ -27,11 +27,16 @@ export const IS_ROOT =
27
27
  export const ALLOW_BYPASS = !IS_ROOT || !!process.env.IS_SANDBOX;
28
28
 
29
29
  /**
30
- * A cloud sandbox run, as opposed to a local desktop session. Cloud sandboxes
31
- * always set IS_SANDBOX and carry a taskRunId; desktop sessions have neither.
30
+ * A cloud sandbox run, as opposed to a local desktop session. `taskRunId` is
31
+ * used by both desktop and cloud for persistence, so it must not imply cloud.
32
32
  */
33
- export function isCloudRun(meta: { taskRunId?: string } | undefined): boolean {
34
- return !!process.env.IS_SANDBOX || !!meta?.taskRunId;
33
+ export function isCloudRun(
34
+ meta: { environment?: "local" | "cloud" } | undefined,
35
+ ): boolean {
36
+ if (meta?.environment) {
37
+ return meta.environment === "cloud";
38
+ }
39
+ return !!process.env.IS_SANDBOX;
35
40
  }
36
41
 
37
42
  /** The GitHub token available to the sandbox, if any. */