@posthog/agent 2.1.13 → 2.1.15

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.
@@ -1175,7 +1175,7 @@ var import_uuid = require("uuid");
1175
1175
  // package.json
1176
1176
  var package_default = {
1177
1177
  name: "@posthog/agent",
1178
- version: "2.1.13",
1178
+ version: "2.1.15",
1179
1179
  repository: "https://github.com/PostHog/twig",
1180
1180
  description: "TypeScript agent framework wrapping Claude Agent SDK with Git-based task execution for PostHog",
1181
1181
  exports: {
@@ -10302,7 +10302,11 @@ var AgentServer = class {
10302
10302
  await clientConnection.newSession({
10303
10303
  cwd: this.config.repositoryPath,
10304
10304
  mcpServers: [],
10305
- _meta: { sessionId: payload.run_id }
10305
+ _meta: {
10306
+ sessionId: payload.run_id,
10307
+ taskRunId: payload.run_id,
10308
+ systemPrompt: { append: this.buildCloudSystemPrompt() }
10309
+ }
10306
10310
  });
10307
10311
  this.session = {
10308
10312
  payload,
@@ -10314,6 +10318,11 @@ var AgentServer = class {
10314
10318
  logWriter
10315
10319
  };
10316
10320
  this.logger.info("Session initialized successfully");
10321
+ this.posthogAPI.updateTaskRun(payload.task_id, payload.run_id, {
10322
+ status: "in_progress"
10323
+ }).catch(
10324
+ (err) => this.logger.warn("Failed to set task run to in_progress", err)
10325
+ );
10317
10326
  await this.sendInitialTaskMessage(payload);
10318
10327
  }
10319
10328
  async sendInitialTaskMessage(payload) {
@@ -10350,6 +10359,19 @@ var AgentServer = class {
10350
10359
  }
10351
10360
  }
10352
10361
  }
10362
+ buildCloudSystemPrompt() {
10363
+ return `
10364
+ # Cloud Task Execution
10365
+
10366
+ After completing the requested changes:
10367
+ 1. Create a new branch with a descriptive name based on the work done
10368
+ 2. Stage and commit all changes with a clear commit message
10369
+ 3. Push the branch to origin
10370
+ 4. Create a pull request using \`gh pr create\` with a descriptive title and body
10371
+
10372
+ Important: Always create the PR. Do not ask for confirmation.
10373
+ `;
10374
+ }
10353
10375
  async signalTaskComplete(payload, stopReason) {
10354
10376
  const status = stopReason === "cancelled" ? "cancelled" : stopReason === "error" ? "failed" : "completed";
10355
10377
  try {
@@ -10410,10 +10432,70 @@ var AgentServer = class {
10410
10432
  if ((toolName === "Write" || toolName === "Edit") && toolResponse?.filePath) {
10411
10433
  await this.captureTreeState();
10412
10434
  }
10435
+ if (toolName && (toolName.includes("Bash") || toolName.includes("bash"))) {
10436
+ this.detectAndAttachPrUrl(payload, params.update);
10437
+ }
10413
10438
  }
10414
10439
  }
10415
10440
  };
10416
10441
  }
10442
+ detectAndAttachPrUrl(payload, update) {
10443
+ try {
10444
+ const meta = update?._meta?.claudeCode;
10445
+ const toolResponse = meta?.toolResponse;
10446
+ let textToSearch = "";
10447
+ if (toolResponse) {
10448
+ if (typeof toolResponse === "string") {
10449
+ textToSearch = toolResponse;
10450
+ } else if (typeof toolResponse === "object" && toolResponse !== null) {
10451
+ const respObj = toolResponse;
10452
+ textToSearch = String(respObj.stdout || "") + String(respObj.stderr || "");
10453
+ if (!textToSearch && respObj.output) {
10454
+ textToSearch = String(respObj.output);
10455
+ }
10456
+ }
10457
+ }
10458
+ const content = update?.content;
10459
+ if (Array.isArray(content)) {
10460
+ for (const item of content) {
10461
+ if (item.type === "text" && item.text) {
10462
+ textToSearch += ` ${item.text}`;
10463
+ }
10464
+ }
10465
+ }
10466
+ if (!textToSearch) return;
10467
+ const prUrlMatch = textToSearch.match(
10468
+ /https:\/\/github\.com\/[^/]+\/[^/]+\/pull\/\d+/
10469
+ );
10470
+ if (!prUrlMatch) return;
10471
+ const prUrl = prUrlMatch[0];
10472
+ this.logger.info("Detected PR URL in bash output", {
10473
+ runId: payload.run_id,
10474
+ prUrl
10475
+ });
10476
+ this.posthogAPI.updateTaskRun(payload.task_id, payload.run_id, {
10477
+ output: { pr_url: prUrl }
10478
+ }).then(() => {
10479
+ this.logger.info("PR URL attached to task run", {
10480
+ taskId: payload.task_id,
10481
+ runId: payload.run_id,
10482
+ prUrl
10483
+ });
10484
+ }).catch((err) => {
10485
+ this.logger.error("Failed to attach PR URL to task run", {
10486
+ taskId: payload.task_id,
10487
+ runId: payload.run_id,
10488
+ prUrl,
10489
+ error: err
10490
+ });
10491
+ });
10492
+ } catch (err) {
10493
+ this.logger.debug("Error in PR URL detection", {
10494
+ runId: payload.run_id,
10495
+ error: err
10496
+ });
10497
+ }
10498
+ }
10417
10499
  async cleanupSession() {
10418
10500
  if (!this.session) return;
10419
10501
  this.logger.info("Cleaning up session");