@posthog/agent 2.3.256 → 2.3.261

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/src/server/bin.ts CHANGED
@@ -30,6 +30,16 @@ const envSchema = z.object({
30
30
 
31
31
  const program = new Command();
32
32
 
33
+ function parseBooleanOption(
34
+ raw: string | undefined,
35
+ flag: string,
36
+ ): boolean | undefined {
37
+ if (raw === undefined) return undefined;
38
+ if (raw === "true") return true;
39
+ if (raw === "false") return false;
40
+ program.error(`${flag} must be either "true" or "false"`);
41
+ }
42
+
33
43
  function parseJsonOption<S extends z.ZodType>(
34
44
  raw: string | undefined,
35
45
  schema: S,
@@ -70,6 +80,7 @@ program
70
80
  "--mcpServers <json>",
71
81
  "MCP servers config as JSON array (ACP McpServer[] format)",
72
82
  )
83
+ .option("--createPr <boolean>", "Whether this run may publish changes")
73
84
  .option("--baseBranch <branch>", "Base branch for PR creation")
74
85
  .option(
75
86
  "--claudeCodeConfig <json>",
@@ -93,6 +104,7 @@ program
93
104
  const env = envResult.data;
94
105
 
95
106
  const mode = options.mode === "background" ? "background" : "interactive";
107
+ const createPr = parseBooleanOption(options.createPr, "--createPr");
96
108
 
97
109
  const mcpServers = parseJsonOption(
98
110
  options.mcpServers,
@@ -122,6 +134,7 @@ program
122
134
  mode,
123
135
  taskId: options.taskId,
124
136
  runId: options.runId,
137
+ createPr,
125
138
  mcpServers,
126
139
  baseBranch: options.baseBranch,
127
140
  claudeCode,
@@ -172,13 +172,13 @@ describe("Question relay", () => {
172
172
  { kind: "allow_once", optionId: "allow", name: "Allow" },
173
173
  ];
174
174
 
175
- describe("with CODE_INTERACTION_ORIGIN=slack", () => {
175
+ describe("with POSTHOG_CODE_INTERACTION_ORIGIN=slack", () => {
176
176
  beforeEach(() => {
177
- process.env.CODE_INTERACTION_ORIGIN = "slack";
177
+ process.env.POSTHOG_CODE_INTERACTION_ORIGIN = "slack";
178
178
  });
179
179
 
180
180
  afterEach(() => {
181
- delete process.env.CODE_INTERACTION_ORIGIN;
181
+ delete process.env.POSTHOG_CODE_INTERACTION_ORIGIN;
182
182
  });
183
183
 
184
184
  it("returns cancelled with relay message for question tool", async () => {
@@ -220,9 +220,9 @@ describe("Question relay", () => {
220
220
  });
221
221
  });
222
222
 
223
- describe("without CODE_INTERACTION_ORIGIN", () => {
223
+ describe("without POSTHOG_CODE_INTERACTION_ORIGIN", () => {
224
224
  beforeEach(() => {
225
- delete process.env.CODE_INTERACTION_ORIGIN;
225
+ delete process.env.POSTHOG_CODE_INTERACTION_ORIGIN;
226
226
  });
227
227
 
228
228
  it("auto-approves question tools (no Slack relay)", async () => {
@@ -301,6 +301,35 @@ describe("Question relay", () => {
301
301
  expect(appendRawLine).toHaveBeenCalledTimes(2);
302
302
  });
303
303
  });
304
+
305
+ describe("with createPr disabled", () => {
306
+ it("cancels publish commands", async () => {
307
+ server = new AgentServer({
308
+ port,
309
+ jwtPublicKey: "unused-in-unit-tests",
310
+ repositoryPath: repo.path,
311
+ apiUrl: "http://localhost:8000",
312
+ apiKey: "test-api-key",
313
+ projectId: 1,
314
+ mode: "interactive",
315
+ taskId: "test-task-id",
316
+ runId: "test-run-id",
317
+ createPr: false,
318
+ }) as unknown as TestableAgentServer;
319
+
320
+ const client = server.createCloudClient(TEST_PAYLOAD);
321
+ const result = await client.requestPermission({
322
+ options: ALLOW_OPTIONS,
323
+ toolCall: {
324
+ rawInput: { command: "git push origin my-branch" },
325
+ _meta: { toolName: "Bash" },
326
+ },
327
+ });
328
+
329
+ expect(result.outcome.outcome).toBe("cancelled");
330
+ expect(result._meta?.message).toContain("stop before publishing");
331
+ });
332
+ });
304
333
  });
305
334
 
306
335
  describe("relayAgentResponse duplicate suppression", () => {
@@ -18,6 +18,7 @@ export interface AgentServerConfig {
18
18
  mode: AgentMode;
19
19
  taskId: string;
20
20
  runId: string;
21
+ createPr?: boolean;
21
22
  version?: string;
22
23
  mcpServers?: RemoteMcpServer[];
23
24
  baseBranch?: string;
package/src/types.ts CHANGED
@@ -114,6 +114,8 @@ export interface TaskExecutionOptions {
114
114
  codexBinaryPath?: string;
115
115
  instructions?: string;
116
116
  processCallbacks?: ProcessSpawnedCallback;
117
+ /** Callback invoked when the agent calls the create_output tool for structured output */
118
+ onStructuredOutput?: (output: Record<string, unknown>) => Promise<void>;
117
119
  }
118
120
 
119
121
  export type LogLevel = "debug" | "info" | "warn" | "error";