@wherever-dev/client 0.3.0 → 0.3.2

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/CHANGELOG.md CHANGED
@@ -1,5 +1,72 @@
1
1
  # @wherever-dev/client
2
2
 
3
+ ## 0.3.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 4836b65: Fix dangling tool calls being hoisted to the end of the transcript on the web frontend, showing as a phantom "series of aborted tool calls" after the latest reply.
8
+
9
+ When loaded history contained a tool call with no matching tool result (e.g. an interrupted long-running `bash` that was superseded by a new user turn, then more replies), the web history mapping deferred every unmatched tool call and appended them all AFTER the last mapped message. So dangling calls from the MIDDLE of the conversation piled up below the latest assistant reply, even though the CLI (and the actual transcript) has them inline where they were issued. The reproducing session was a deliberate recoverability test ("Generate a long message..."/"long running tool call using bash sleep" then interrupting it).
10
+
11
+ The mapping now renders each tool call IN PLACE at its position in the stream: a result-less tool message is emitted when the tool call is seen, and its matching tool result fills it in later (oldest-open-first per tool name, preserving the parallel-call FIFO behaviour). A call that never receives a result stays exactly where it was issued, correctly marked `interrupted` (neutral "no result" state), instead of migrating to the end. On the live streaming tail, only the newest still-open call is kept streaming ("Elapsed" ticking); earlier open calls in the window are interrupted.
12
+
13
+ Tests: two new client tests covering (1) a mid-conversation dangling call staying in place with the final message still an assistant reply, and (2) multiple dangling calls where only the newest streams on the live tail while earlier ones are interrupted in place. All existing tool abort/interrupted/duration tests still pass.
14
+
15
+ - 12083e5: Render an aborted tool call as interrupted, not a red error.
16
+
17
+ When you hit the web "abort" button while tools are running, pi kills the in-flight tools and surfaces each as an errored result with a trailing "...aborted" status ("Command aborted" for bash, "Operation aborted" for edit/write). The web then rendered that as a red error tick, as if the tool had genuinely failed. With parallel tool calls this was especially confusing: a tool that happened to finish just before the abort showed a green success tick while the killed one showed a red error, even though the user aborted the whole turn.
18
+
19
+ The client now detects an abort result (an errored result whose trailing status line is "...aborted") and renders it with the neutral "interrupted" state (muted icon, neutral border) instead of a red error, on both the live tool_end path and when reconstructing from loaded history. A tool that genuinely completed keeps its green success, and a genuine failure keeps its red error. The match is anchored to the trailing status line, so ordinary command output that merely contains the word "aborted" is not misclassified.
20
+
21
+ Also fixes a related mismatch with PARALLEL same-named tools. Live tool_end frames were matched to a tool message by name via a last-match search, so with two concurrent bash calls both tool_end frames could land on the same message, leaving the other tool stuck streaming; it was then finalized by the agent_end sweep with no result and shown as a bogus green success tick. tool_end now claims the OLDEST still-streaming tool of that name (FIFO), so each concurrent call settles a distinct message. And any tool still streaming when the turn ends (agent_end) is now marked interrupted rather than left to render green, since its outcome is unknown.
22
+
23
+ Also adds a `tool-calls` (parallel tool_use) behavior to the test fake LLM to exercise concurrent tool execution.
24
+
25
+ - db16623: Render `read`-tool image output inline in the web frontend, mirroring the CLI's inline image display.
26
+
27
+ When the agent uses the builtin `read` tool on an image path, the pi tool result carries an image content block (`{type:'image', data, mimeType}`) alongside the text note. Previously the server's `extractToolResult` kept only text blocks, so the web never saw the image. The server now also pulls image blocks out of the tool result and ships them (base64 + mimeType) on the `tool_end` frame via a new optional `images` field, and reconstructs them from history when a session is reloaded. The client stores them on the `ChatMessage` (`images`), and the web renders each image inline right under the tool header, always visible (not hidden behind the collapse toggle), while the textual arguments/output stay collapsible. Click an image to open it full size. Text-only tools are unaffected.
28
+
29
+ - 9931867: Pair reconstructed tool results to their exact tool call by id, not just by tool name.
30
+
31
+ The server now forwards the tool-call id on both `tool_call` (the id the assistant issued) and `tool_result` (the `toolCallId` it satisfies) history messages, and the web history mapping matches a result to its exact call by that id, falling back to the previous oldest-open-first per-tool-name behaviour only when no id is present (older sessions, or the synthesized `bashExecution` pair).
32
+
33
+ This fixes mis-pairing when same-named calls interleave with some left dangling: e.g. two `bash` calls issued back-to-back where only the second returns a result. Name-FIFO alone would resolve the first call and leave the second dangling; id matching resolves the correct one and leaves the genuinely-interrupted call marked interrupted, in place.
34
+
35
+ Tests: a new client test covering id-exact pairing (result resolves call #2 by id, leaving call #1 dangling/interrupted, order preserved).
36
+
37
+ - 8536f30: Warn both the web frontend and the CLI when a CLI takeover discards an in-flight turn.
38
+
39
+ When a `pi` CLI resumes/registers a session while the standalone server is mid-turn for a web viewer, the CLI seizes control and the server disposes its live agent. Disposing mid-turn discards the whole in-flight turn without persisting it (persistence only happens on turn completion), so the web viewer, who was watching a tool run or a reply stream, lost it silently with no explanation.
40
+
41
+ The server now detects that the server-side agent was mid-turn at takeover and sends the attached web clients a non-fatal `session_notice` (level: warning). The web frontend renders it as a dismissible banner. The wording is tailored to what was lost: a running tool call (tracked via a per-session in-flight tool-execution count, so its result never arrives) or a streaming reply (the partial text is discarded and not saved). A takeover of an already-settled (idle) session is not flagged. The session stays attached (informational, unlike `session_interrupted`).
42
+
43
+ The notice also states the takeover semantics accurately: once the CLI has taken over it owns the session's execution loop, so messages sent from the web frontend are relayed to the CLI rather than wresting control back. The web frontend regains control only when the CLI disconnects.
44
+
45
+ The CLI side is covered too. On register, the server sends the taking-over CLI a `cli_takeover_interrupted` message, and the Wherever extension surfaces a single matching notice. This closes a blind spot: a still-streaming turn is never persisted, so the extension's own resumed-mid-tool-call check (which reads the saved transcript) cannot see the streaming-text case. For the tool-call case, the extension's transcript check already warns with the tool names, so the server-driven notice defers to it to avoid a duplicate.
46
+
47
+ Also fixes the web frontend rendering a killed-then-orphaned tool call as a green success tick. When a CLI takeover kills an in-flight tool (the pi SDK aborts the run and SIGKILLs the tool's process tree, so it does not keep running in the background), the transcript keeps a dangling toolCall with no toolResult. The web history mapping now flags such a result-less, non-streaming tool call as `interrupted`, and the UI shows a neutral "interrupted, no result" state (a muted ⊘ icon, neutral border, and an explanatory output note) instead of the green ✅ "Succeeded": its outcome is genuinely unknown, neither success nor failure.
48
+
49
+ Also cleans up the CLI's resumed-mid-run warning (the extension's dangling-tool-call widget):
50
+ - It now counts only the TRAILING dangling tool calls (those after the last user message on the active branch), not every unsatisfied tool call in the whole session. Earlier turns' interrupted tool calls are already superseded by a later human turn and do not block auto-continue, so they were over-counted (e.g. "4 tool calls" when only 1 was actually blocking).
51
+ - It shows a single persistent widget instead of a widget plus a duplicate transient notify.
52
+ - Its guidance is corrected: the CLI has already taken over, so it says to send a message to retry or continue, rather than the stale "send a message to take over".
53
+
54
+ ## 0.3.1
55
+
56
+ ### Patch Changes
57
+
58
+ - 333f6ad: Never silently lose a message when the connection drops mid-send; confirm delivery and recover it on reload.
59
+
60
+ A frame handed to a socket that reports OPEN can still never reach the server (a half-open TCP connection: `send()` buffers locally and does not throw, but the bytes never land). The optimistic echo was treated as delivered, the input was cleared, and on reload the message was gone with no way to recover it.
61
+
62
+ Outbound user messages are now tracked as `delivery: 'sending'` until the server echoes them back (`message_end` role:user), at which point they are confirmed. If no echo arrives within a window, the message flips to `delivery: 'failed'` and the UI surfaces "Not delivered" with Retry / Discard instead of a normal-looking sent message. Unconfirmed messages are persisted per session, so a reload reconciles them against the loaded history: anything the server actually persisted is shown as delivered, and anything it did not is re-surfaced as a recoverable failed message (never silently dropped). New client APIs: `resendMessage(id)` and `discardMessage(id)`.
63
+
64
+ - 9368269: Show how long each tool call has been running, like the pi CLI.
65
+
66
+ A running tool now shows a live-ticking "Elapsed N.Ns" and, once it finishes, "Took N.Ns" (one decimal, matching the CLI's bash duration format). The client reducer stamps `startedAt` on `tool_start` and `endedAt` on `tool_end` (new `ChatMessage` fields), and freezes a still-running tool's `endedAt` if the turn ends or is aborted without a `tool_end`, so the timer stops instead of counting up forever. The web UI ticks only while a tool is actually running (no per-frame work on an idle session).
67
+
68
+ Durations also survive a reload/reconnect: history mapping pairs each `tool_call` with its `tool_result` and derives `startedAt`/`endedAt` from their timestamps (no server change needed), so a tool restored from loaded history shows the same "Took N.Ns" as a live-streamed one.
69
+
3
70
  ## 0.3.0
4
71
 
5
72
  ### Minor Changes
package/dist/client.d.ts CHANGED
@@ -34,6 +34,9 @@ export declare class WhereverClient {
34
34
  private resumeModel?;
35
35
  private listeners;
36
36
  private pendingUploads;
37
+ private confirmTimers;
38
+ private static readonly CONFIRM_MS;
39
+ private static readonly PENDING_PREFIX;
37
40
  constructor(config: WhereverClientConfig);
38
41
  connect(newConfig?: Partial<WhereverClientConfig>, preserveState?: boolean): void;
39
42
  disconnect(resetState?: boolean): void;
@@ -49,6 +52,18 @@ export declare class WhereverClient {
49
52
  private clearCreateWatchdog;
50
53
  private scheduleReconnect;
51
54
  private handleMessage;
55
+ /**
56
+ * True when an errored tool result is the product of a USER ABORT (e.g. the
57
+ * web "abort" button killed a running tool), rather than a genuine tool
58
+ * failure. The pi tools append a trailing status line on abort ("Command
59
+ * aborted" for bash, "Operation aborted" for edit/write, bare "aborted" for a
60
+ * pre-execution abort). We match that trailing status so the UI can render a
61
+ * neutral "interrupted" state instead of a red error: you cancelling a tool is
62
+ * not the tool failing. Only meaningful when isError is already true; matched
63
+ * as the LAST non-empty line to avoid false positives from command output that
64
+ * merely contains the word "aborted".
65
+ */
66
+ private isAbortedToolResult;
52
67
  /**
53
68
  * Map a server `HistoryMessage[]` window into UI `ChatMessage[]`. When
54
69
  * `applyStreamingTail` is true, the last assistant/thinking message and any
@@ -64,6 +79,14 @@ export declare class WhereverClient {
64
79
  loadMoreHistory(): void;
65
80
  send(msg: any): boolean;
66
81
  sendMessage(text: string): boolean;
82
+ private pendingKey;
83
+ private persistPending;
84
+ private loadPersistedPending;
85
+ private armConfirm;
86
+ private clearConfirm;
87
+ private confirmDeliveredByContent;
88
+ resendMessage(messageId: string): boolean;
89
+ discardMessage(messageId: string): void;
67
90
  abort(): void;
68
91
  joinSession(sessionFile: string, cwd?: string, model?: string): void;
69
92
  switchSession(sessionFile: string, cwd?: string, model?: string): void;
@@ -73,6 +96,7 @@ export declare class WhereverClient {
73
96
  ping(): void;
74
97
  clearMessages(): void;
75
98
  dismissSessionError(): void;
99
+ dismissNotice(): void;
76
100
  changeModel(model: string): void;
77
101
  setConfig(updates: Partial<WhereverClientConfig>): void;
78
102
  onMessage(cb: (msg: any) => void): () => void;