@posthog/agent 2.1.85 → 2.1.89

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@posthog/agent",
3
- "version": "2.1.85",
3
+ "version": "2.1.89",
4
4
  "repository": "https://github.com/PostHog/twig",
5
5
  "description": "TypeScript agent framework wrapping Claude Agent SDK with Git-based task execution for PostHog",
6
6
  "exports": {
@@ -104,7 +104,7 @@
104
104
  "access": "public"
105
105
  },
106
106
  "scripts": {
107
- "build": "tsup",
107
+ "build": "rm -rf dist && tsup",
108
108
  "dev": "tsup --watch",
109
109
  "test": "vitest run",
110
110
  "test:watch": "vitest",
@@ -130,6 +130,7 @@ interface SseController {
130
130
 
131
131
  interface ActiveSession {
132
132
  payload: JwtPayload;
133
+ acpSessionId: string;
133
134
  acpConnection: InProcessAcpConnection;
134
135
  clientConnection: ClientSideConnection;
135
136
  treeTracker: TreeTracker;
@@ -409,7 +410,7 @@ export class AgentServer {
409
410
  );
410
411
 
411
412
  const result = await this.session.clientConnection.prompt({
412
- sessionId: this.session.payload.run_id,
413
+ sessionId: this.session.acpSessionId,
413
414
  prompt: [{ type: "text", text: content }],
414
415
  });
415
416
 
@@ -418,9 +419,11 @@ export class AgentServer {
418
419
 
419
420
  case POSTHOG_NOTIFICATIONS.CANCEL:
420
421
  case "cancel": {
421
- this.logger.info("Cancel requested");
422
+ this.logger.info("Cancel requested", {
423
+ acpSessionId: this.session.acpSessionId,
424
+ });
422
425
  await this.session.clientConnection.cancel({
423
- sessionId: this.session.payload.run_id,
426
+ sessionId: this.session.acpSessionId,
424
427
  });
425
428
  return { cancelled: true };
426
429
  }
@@ -515,7 +518,7 @@ export class AgentServer {
515
518
  clientCapabilities: {},
516
519
  });
517
520
 
518
- await clientConnection.newSession({
521
+ const sessionResponse = await clientConnection.newSession({
519
522
  cwd: this.config.repositoryPath,
520
523
  mcpServers: [],
521
524
  _meta: {
@@ -525,8 +528,15 @@ export class AgentServer {
525
528
  },
526
529
  });
527
530
 
531
+ const acpSessionId = sessionResponse.sessionId;
532
+ this.logger.info("ACP session created", {
533
+ acpSessionId,
534
+ runId: payload.run_id,
535
+ });
536
+
528
537
  this.session = {
529
538
  payload,
539
+ acpSessionId,
530
540
  acpConnection,
531
541
  clientConnection,
532
542
  treeTracker,
@@ -567,33 +577,19 @@ export class AgentServer {
567
577
  });
568
578
 
569
579
  const result = await this.session.clientConnection.prompt({
570
- sessionId: payload.run_id,
580
+ sessionId: this.session.acpSessionId,
571
581
  prompt: [{ type: "text", text: task.description }],
572
582
  });
573
583
 
574
584
  this.logger.info("Initial task message completed", {
575
585
  stopReason: result.stopReason,
576
586
  });
577
-
578
- // Only auto-complete for background mode
579
- const mode = this.getEffectiveMode(payload);
580
- if (mode === "background") {
581
- // Flush all pending session logs before signaling completion,
582
- await this.session.logWriter.flushAll();
583
- await this.signalTaskComplete(payload, result.stopReason);
584
- } else {
585
- this.logger.info("Interactive mode - staying open for conversation");
586
- }
587
587
  } catch (error) {
588
588
  this.logger.error("Failed to send initial task message", error);
589
- // Signal failure for background mode
590
- const mode = this.getEffectiveMode(payload);
591
- if (mode === "background") {
592
- if (this.session) {
593
- await this.session.logWriter.flushAll();
594
- }
595
- await this.signalTaskComplete(payload, "error");
589
+ if (this.session) {
590
+ await this.session.logWriter.flushAll();
596
591
  }
592
+ await this.signalTaskComplete(payload, "error");
597
593
  }
598
594
  }
599
595
 
@@ -630,12 +626,14 @@ Important:
630
626
  }
631
627
  }
632
628
 
633
- const status =
634
- stopReason === "cancelled"
635
- ? "cancelled"
636
- : stopReason === "error"
637
- ? "failed"
638
- : "completed";
629
+ if (stopReason !== "error") {
630
+ this.logger.info("Skipping status update for non-error stop reason", {
631
+ stopReason,
632
+ });
633
+ return;
634
+ }
635
+
636
+ const status = "failed";
639
637
 
640
638
  try {
641
639
  await this.posthogAPI.updateTaskRun(payload.task_id, payload.run_id, {