pi-control-bridge 0.3.10 → 0.3.11

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.
@@ -3859,8 +3859,18 @@ var SessionRegistry = class {
3859
3859
  enqueueCommand(localId, command) {
3860
3860
  const queue = this.commandQueues.get(localId);
3861
3861
  if (!queue) return false;
3862
+ const waiters = this.commandWaiters.get(localId);
3863
+ if (waiters?.length) {
3864
+ const resolve2 = waiters.shift();
3865
+ if (waiters.length === 0) {
3866
+ this.commandWaiters.delete(localId);
3867
+ } else {
3868
+ this.commandWaiters.set(localId, waiters);
3869
+ }
3870
+ resolve2(command);
3871
+ return true;
3872
+ }
3862
3873
  queue.push(command);
3863
- this.resolveWaiters(localId, command);
3864
3874
  return true;
3865
3875
  }
3866
3876
  async waitForCommand(localId, timeoutMs) {
@@ -15,7 +15,7 @@ import {
15
15
  import { executeCommand } from "./command_handler.ts";
16
16
  import { ensureBridge, setBridgeConfigCwd } from "./ensure_bridge.ts";
17
17
  import { formatConnectTelegramMessage, formatControlStatusMessage } from "./messages.ts";
18
- import { buildSessionMetadata } from "./session_metadata.ts";
18
+ import { buildSessionMetadata, extractLatestAssistantResponseFromMessages } from "./session_metadata.ts";
19
19
  import { sessionStatusAfterAgentEnd, sessionStatusFromContext } from "./session_status.ts";
20
20
 
21
21
  interface SessionBinding {
@@ -236,7 +236,8 @@ export function registerHooks(pi: ExtensionAPI): void {
236
236
  pi.on("agent_end", (event, ctx) => {
237
237
  const localId = ctx.sessionManager.getSessionId();
238
238
  const status = sessionStatusAfterAgentEnd(ctx);
239
- void postEvent(localId, "agent_end", status);
239
+ const lastResult = extractLatestAssistantResponseFromMessages(event.messages);
240
+ void postEvent(localId, "agent_end", status, lastResult ? { lastResult } : undefined);
240
241
  void postSessionMetadata(pi, ctx, localId, { messages: event.messages });
241
242
  });
242
243
 
@@ -2,6 +2,8 @@ import { basename } from "node:path";
2
2
 
3
3
  import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
4
4
 
5
+ import { stripAnsi } from "../shared/ansi.ts";
6
+
5
7
  const DESCRIPTION_MAX_LEN = 240;
6
8
 
7
9
  function truncate(text: string, maxLen: number): string {
@@ -43,6 +45,13 @@ function extractUserMessageText(message: unknown): string | undefined {
43
45
  return extractTextContent(candidate.content);
44
46
  }
45
47
 
48
+ function extractAssistantMessageText(message: unknown): string | undefined {
49
+ if (!message || typeof message !== "object") return undefined;
50
+ const candidate = message as { role?: string; content?: unknown };
51
+ if (candidate.role !== "assistant") return undefined;
52
+ return extractTextContent(candidate.content);
53
+ }
54
+
46
55
  export function extractFirstUserPrompt(ctx: ExtensionContext): string | undefined {
47
56
  for (const entry of ctx.sessionManager.getEntries()) {
48
57
  if (entry.type !== "message") continue;
@@ -60,6 +69,16 @@ export function extractLatestUserPromptFromMessages(messages: unknown[]): string
60
69
  return undefined;
61
70
  }
62
71
 
72
+ export function extractLatestAssistantResponseFromMessages(messages: unknown[]): string | undefined {
73
+ for (let index = messages.length - 1; index >= 0; index -= 1) {
74
+ const text = extractAssistantMessageText(messages[index]);
75
+ if (!text) continue;
76
+ const cleaned = stripAnsi(text).trim();
77
+ if (cleaned) return cleaned;
78
+ }
79
+ return undefined;
80
+ }
81
+
63
82
  export function buildSessionMetadata(
64
83
  pi: ExtensionAPI,
65
84
  ctx: ExtensionContext,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-control-bridge",
3
- "version": "0.3.10",
3
+ "version": "0.3.11",
4
4
  "description": "Pi agent bridge extension and singleton runtime for pi-control-hub integration.",
5
5
  "keywords": [
6
6
  "pi-package",
package/shared/ansi.ts CHANGED
@@ -1,5 +1,9 @@
1
1
  const RESET = "\x1b[0m";
2
2
 
3
+ export function stripAnsi(text: string): string {
4
+ return text.replace(/\x1b\[[0-9;]*m/g, "");
5
+ }
6
+
3
7
  export const ansi = {
4
8
  reset: RESET,
5
9
  title: (text: string) => `\x1b[1;96m${text}${RESET}`,