@posthog/agent 2.3.259 → 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.
@@ -5683,7 +5683,7 @@ var import_hono = require("hono");
5683
5683
  // package.json
5684
5684
  var package_default = {
5685
5685
  name: "@posthog/agent",
5686
- version: "2.3.259",
5686
+ version: "2.3.261",
5687
5687
  repository: "https://github.com/PostHog/code",
5688
5688
  description: "TypeScript agent framework wrapping Claude Agent SDK with Git-based task execution for PostHog",
5689
5689
  exports: {
@@ -12612,12 +12612,9 @@ var AgentServer = class _AgentServer {
12612
12612
  prompt,
12613
12613
  ...this.detectedPrUrl && {
12614
12614
  _meta: {
12615
- prContext: `IMPORTANT \u2014 OVERRIDE PREVIOUS INSTRUCTIONS ABOUT CREATING BRANCHES/PRs.
12616
- You already have an open pull request: ${this.detectedPrUrl}
12617
- You MUST:
12618
- 1. Check out the existing PR branch with \`gh pr checkout ${this.detectedPrUrl}\`
12619
- 2. Make changes, commit, and push to that branch
12620
- You MUST NOT create a new branch, close the existing PR, or create a new PR.`
12615
+ // Keep the live-session PR override aligned with the startup
12616
+ // prompt policy so non-Slack runs remain review-first.
12617
+ prContext: this.buildDetectedPrContext(this.detectedPrUrl)
12621
12618
  }
12622
12619
  }
12623
12620
  });
@@ -13077,13 +13074,38 @@ ${toolSummary}`);
13077
13074
  }
13078
13075
  return { append: cloudAppend };
13079
13076
  }
13077
+ getCloudInteractionOrigin() {
13078
+ return process.env.POSTHOG_CODE_INTERACTION_ORIGIN ?? process.env.CODE_INTERACTION_ORIGIN ?? process.env.TWIG_INTERACTION_ORIGIN;
13079
+ }
13080
+ /**
13081
+ * Slack-origin cloud runs auto-publish by default. Every other origin is
13082
+ * review-first unless the user explicitly asks, and createPr=false always
13083
+ * disables publishing.
13084
+ */
13085
+ shouldAutoPublishCloudChanges() {
13086
+ return this.getCloudInteractionOrigin() === "slack" && this.config.createPr !== false;
13087
+ }
13088
+ buildDetectedPrContext(prUrl) {
13089
+ if (!this.shouldAutoPublishCloudChanges()) {
13090
+ return `An open pull request already exists: ${prUrl}
13091
+ Use that PR as context if it is helpful, but stop with local changes ready for review.
13092
+ Do NOT create commits, push to the PR branch, update the pull request, create a new branch, or create a new pull request unless the user explicitly asks.`;
13093
+ }
13094
+ return `IMPORTANT \u2014 OVERRIDE PREVIOUS INSTRUCTIONS ABOUT CREATING BRANCHES/PRs.
13095
+ You already have an open pull request: ${prUrl}
13096
+ You MUST:
13097
+ 1. Check out the existing PR branch with \`gh pr checkout ${prUrl}\`
13098
+ 2. Make changes, commit, and push to that branch
13099
+ You MUST NOT create a new branch, close the existing PR, or create a new PR.`;
13100
+ }
13080
13101
  buildCloudSystemPrompt(prUrl) {
13081
13102
  const taskId = this.config.taskId;
13103
+ const shouldAutoCreatePr = this.shouldAutoPublishCloudChanges();
13082
13104
  const attributionInstructions = `
13083
13105
  ## Attribution
13084
13106
  Do NOT use Claude Code's default attribution (no "Co-Authored-By" trailers, no "Generated with [Claude Code]" lines).
13085
13107
 
13086
- Instead, add the following trailers to EVERY commit message (after a blank line at the end):
13108
+ If you create a commit, add the following trailers to the commit message (after a blank line at the end):
13087
13109
  Generated-By: PostHog Code
13088
13110
  Task-Id: ${taskId}
13089
13111
 
@@ -13098,6 +13120,20 @@ EOF
13098
13120
  )"
13099
13121
  \`\`\``;
13100
13122
  if (prUrl) {
13123
+ if (!shouldAutoCreatePr) {
13124
+ return `
13125
+ # Cloud Task Execution
13126
+
13127
+ This task already has an open pull request: ${prUrl}
13128
+
13129
+ Do the requested work, but stop with local changes ready for review.
13130
+
13131
+ Important:
13132
+ - Do NOT create new commits, push to the branch, or update the pull request unless the user explicitly asks.
13133
+ - Do NOT create a new branch or a new pull request.
13134
+ ${attributionInstructions}
13135
+ `;
13136
+ }
13101
13137
  return `
13102
13138
  # Cloud Task Execution
13103
13139
 
@@ -13131,6 +13167,17 @@ When the user asks for code changes or software engineering tasks:
13131
13167
  Important:
13132
13168
  - Do NOT create branches, commits, or pull requests in this mode.
13133
13169
  - Prefer using MCP tools to answer questions with real data over giving generic advice.
13170
+ `;
13171
+ }
13172
+ if (!shouldAutoCreatePr) {
13173
+ return `
13174
+ # Cloud Task Execution
13175
+
13176
+ Do the requested work, but stop with local changes ready for review.
13177
+
13178
+ Important:
13179
+ - Do NOT create a branch, commit, push, or open a pull request unless the user explicitly asks.
13180
+ ${attributionInstructions}
13134
13181
  `;
13135
13182
  }
13136
13183
  return `
@@ -13239,9 +13286,30 @@ ${attributionInstructions}
13239
13286
  LLM_GATEWAY_URL: gatewayUrl
13240
13287
  });
13241
13288
  }
13289
+ buildSlackQuestionRelayResponse(payload, toolMeta2) {
13290
+ this.relaySlackQuestion(payload, toolMeta2);
13291
+ return {
13292
+ outcome: { outcome: "cancelled" },
13293
+ _meta: {
13294
+ message: "This question has been relayed to the Slack thread where this task originated. The user will reply there. Do NOT re-ask the question or pick an answer yourself. Simply let the user know you are waiting for their reply."
13295
+ }
13296
+ };
13297
+ }
13298
+ shouldBlockPublishPermission(params) {
13299
+ if (this.config.createPr !== false) {
13300
+ return false;
13301
+ }
13302
+ const meta = params.toolCall?._meta && typeof params.toolCall._meta === "object" && !Array.isArray(params.toolCall._meta) ? params.toolCall._meta : null;
13303
+ const rawInput = params.toolCall?.rawInput && typeof params.toolCall.rawInput === "object" && !Array.isArray(params.toolCall.rawInput) ? params.toolCall.rawInput : null;
13304
+ const toolName = typeof meta?.toolName === "string" ? meta.toolName : null;
13305
+ const command = typeof rawInput?.command === "string" ? rawInput.command : null;
13306
+ return Boolean(
13307
+ toolName && (toolName === "Bash" || toolName.includes("bash")) && command && /\bgit\s+push\b|\bgh\s+pr\s+(create|edit|ready|merge)\b/.test(command)
13308
+ );
13309
+ }
13242
13310
  createCloudClient(payload) {
13243
13311
  const mode = this.getEffectiveMode(payload);
13244
- const interactionOrigin = process.env.CODE_INTERACTION_ORIGIN ?? process.env.TWIG_INTERACTION_ORIGIN;
13312
+ const interactionOrigin = process.env.POSTHOG_CODE_INTERACTION_ORIGIN ?? process.env.CODE_INTERACTION_ORIGIN ?? process.env.TWIG_INTERACTION_ORIGIN;
13245
13313
  return {
13246
13314
  requestPermission: async (params) => {
13247
13315
  this.logger.debug("Permission request", {
@@ -13256,15 +13324,20 @@ ${attributionInstructions}
13256
13324
  if (interactionOrigin === "slack") {
13257
13325
  const codeToolKind = params.toolCall?._meta?.codeToolKind;
13258
13326
  if (codeToolKind === "question") {
13259
- this.relaySlackQuestion(payload, params.toolCall?._meta);
13260
- return {
13261
- outcome: { outcome: "cancelled" },
13262
- _meta: {
13263
- message: "This question has been relayed to the Slack thread where this task originated. The user will reply there. Do NOT re-ask the question or pick an answer yourself. Simply let the user know you are waiting for their reply."
13264
- }
13265
- };
13327
+ return this.buildSlackQuestionRelayResponse(
13328
+ payload,
13329
+ params.toolCall?._meta
13330
+ );
13266
13331
  }
13267
13332
  }
13333
+ if (this.shouldBlockPublishPermission(params)) {
13334
+ return {
13335
+ outcome: { outcome: "cancelled" },
13336
+ _meta: {
13337
+ message: "This run is configured to stop before publishing. Do not push commits or create/update pull requests unless the user explicitly asks."
13338
+ }
13339
+ };
13340
+ }
13268
13341
  return {
13269
13342
  outcome: {
13270
13343
  outcome: "selected",
@@ -13549,6 +13622,12 @@ var envSchema = import_v42.z.object({
13549
13622
  }).regex(/^\d+$/, "POSTHOG_PROJECT_ID must be a numeric string").transform((val) => parseInt(val, 10))
13550
13623
  });
13551
13624
  var program = new import_commander.Command();
13625
+ function parseBooleanOption(raw, flag) {
13626
+ if (raw === void 0) return void 0;
13627
+ if (raw === "true") return true;
13628
+ if (raw === "false") return false;
13629
+ program.error(`${flag} must be either "true" or "false"`);
13630
+ }
13552
13631
  function parseJsonOption(raw, schema, flag) {
13553
13632
  if (!raw) return void 0;
13554
13633
  let parsed;
@@ -13572,7 +13651,7 @@ program.name("agent-server").description("PostHog cloud agent server - runs in s
13572
13651
  ).option("--repositoryPath <path>", "Path to the repository").requiredOption("--taskId <id>", "Task ID").requiredOption("--runId <id>", "Task run ID").option(
13573
13652
  "--mcpServers <json>",
13574
13653
  "MCP servers config as JSON array (ACP McpServer[] format)"
13575
- ).option("--baseBranch <branch>", "Base branch for PR creation").option(
13654
+ ).option("--createPr <boolean>", "Whether this run may publish changes").option("--baseBranch <branch>", "Base branch for PR creation").option(
13576
13655
  "--claudeCodeConfig <json>",
13577
13656
  "Claude Code config as JSON (systemPrompt, systemPromptAppend, plugins)"
13578
13657
  ).option(
@@ -13588,6 +13667,7 @@ ${errors}`);
13588
13667
  }
13589
13668
  const env = envResult.data;
13590
13669
  const mode = options.mode === "background" ? "background" : "interactive";
13670
+ const createPr = parseBooleanOption(options.createPr, "--createPr");
13591
13671
  const mcpServers = parseJsonOption(
13592
13672
  options.mcpServers,
13593
13673
  mcpServersSchema,
@@ -13609,6 +13689,7 @@ ${errors}`);
13609
13689
  mode,
13610
13690
  taskId: options.taskId,
13611
13691
  runId: options.runId,
13692
+ createPr,
13612
13693
  mcpServers,
13613
13694
  baseBranch: options.baseBranch,
13614
13695
  claudeCode,