@posthog/agent 2.3.370 → 2.3.385

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.3.370",
3
+ "version": "2.3.385",
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": {
@@ -316,15 +316,6 @@ export class ClaudeAcpAgent extends BaseAcpAgent {
316
316
  }
317
317
 
318
318
  async prompt(params: PromptRequest): Promise<PromptResponse> {
319
- this.session.cancelled = false;
320
- this.session.interruptReason = undefined;
321
- this.session.accumulatedUsage = {
322
- inputTokens: 0,
323
- outputTokens: 0,
324
- cachedReadTokens: 0,
325
- cachedWriteTokens: 0,
326
- };
327
-
328
319
  const userMessage = promptToClaude(params);
329
320
  const promptUuid = randomUUID();
330
321
  userMessage.uuid = promptUuid;
@@ -364,7 +355,19 @@ export class ClaudeAcpAgent extends BaseAcpAgent {
364
355
  this.session.input.push(userMessage);
365
356
  }
366
357
 
367
- // Broadcast user message to client
358
+ // Reset session state here (after the queued-wait) rather than at the
359
+ // top of prompt(). Otherwise a new prompt() call would wipe cancelled=true
360
+ // on the previous still-running loop, causing it to return end_turn
361
+ // instead of the cancelled stop reason the spec requires.
362
+ this.session.cancelled = false;
363
+ this.session.interruptReason = undefined;
364
+ this.session.accumulatedUsage = {
365
+ inputTokens: 0,
366
+ outputTokens: 0,
367
+ cachedReadTokens: 0,
368
+ cachedWriteTokens: 0,
369
+ };
370
+
368
371
  await this.broadcastUserMessage(params);
369
372
 
370
373
  this.session.promptRunning = true;
@@ -652,10 +655,6 @@ export class ClaudeAcpAgent extends BaseAcpAgent {
652
655
 
653
656
  case "user":
654
657
  case "assistant": {
655
- if (this.session.cancelled) {
656
- break;
657
- }
658
-
659
658
  // Check for prompt replay (our own message echoed back)
660
659
  if (message.type === "user" && "uuid" in message && message.uuid) {
661
660
  if (message.uuid === promptUuid) {
@@ -670,12 +669,16 @@ export class ClaudeAcpAgent extends BaseAcpAgent {
670
669
  pending.resolve(false);
671
670
  this.session.pendingMessages.delete(message.uuid as string);
672
671
  handedOff = true;
673
- // the current loop stops with end_turn,
674
- // the loop of the next prompt continues running
675
- return { stopReason: "end_turn" };
672
+ return {
673
+ stopReason: this.session.cancelled ? "cancelled" : "end_turn",
674
+ };
676
675
  }
677
676
  }
678
677
 
678
+ if (this.session.cancelled) {
679
+ break;
680
+ }
681
+
679
682
  // Skip replayed user messages that aren't pending prompts
680
683
  if (
681
684
  "isReplay" in message &&