@wherever-dev/client 0.4.0 → 0.5.1
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 +14 -0
- package/dist/client.d.ts +3 -1
- package/dist/client.js +259 -41
- package/dist/client.js.map +1 -1
- package/dist/types.d.ts +19 -5
- package/dist/types.js +49 -1
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
- package/src/client.ts +274 -42
- package/src/types.ts +100 -5
- package/test/message-delivery-confirmation.test.ts +126 -0
- package/test/optimistic-force-command.test.ts +127 -0
- package/test/steer-queue-cancel.test.ts +130 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @wherever-dev/client
|
|
2
2
|
|
|
3
|
+
## 0.5.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 3c035f6: Fix a `/skill:<name>` invocation showing up as TWO messages: the raw optimistic echo (which then flipped to "Not delivered / Retry" and persisted across reloads) plus the transformed skill chip. The client optimistically echoes the raw `/skill:...` invocation, but the server confirms it with a raw `message_ack` and later echoes back the expanded `<skill>` block, so exact-content delivery matching missed and appended a duplicate. Delivery confirmation now matches the raw optimistic bubble to the expanded server echo by skill-invocation identity (name + args) and rewrites it in place, so there is a single confirmed skill chip. Adds shared `parseSkillInvocation` / `skillInvocationIdentity` helpers to `@wherever-dev/client` (now used by the web instead of a local copy).
|
|
8
|
+
|
|
9
|
+
## 0.5.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- d9df862: Show web `!command` / `!!command` (force command) bash tool calls INSTANTLY again instead of only after a server round-trip. Since the `!sudo` change, `!`-commands no longer add any local user echo — the bash tool-call render (driven by the server's `tool_start`) is the only feedback — so nothing appeared until the full client → server → `tool_start` → client hop completed, making force commands feel laggy.
|
|
14
|
+
|
|
15
|
+
The client now renders an OPTIMISTIC bash tool bubble the moment a `!`/`!!` command is sent (correct `$ bash command="..."` label, `forceCommand`, live "Elapsed" timer), tagged `optimistic` so it is NOT delivery-tracked (no watchdog/retry banner) and is reconciled — not duplicated — when the server's real `tool_start` arrives (FIFO match on the oldest pending optimistic bubble, so back-to-back `!`-commands line up correctly). `!sudo ...` is intentionally excluded from the optimistic bubble because the server defers it behind a password prompt and only emits `tool_start` once the password arrives. A stuck optimistic bubble (e.g. the turn ends before any `tool_start`) is still finalized as interrupted by the existing agent_end/aborted sweep.
|
|
16
|
+
|
|
3
17
|
## 0.4.0
|
|
4
18
|
|
|
5
19
|
### Minor Changes
|
package/dist/client.d.ts
CHANGED
|
@@ -90,11 +90,13 @@ export declare class WhereverClient {
|
|
|
90
90
|
resendMessage(messageId: string): boolean;
|
|
91
91
|
discardMessage(messageId: string): void;
|
|
92
92
|
abort(): void;
|
|
93
|
+
cancelSteer(): void;
|
|
93
94
|
joinSession(sessionFile: string, cwd?: string, model?: string): void;
|
|
94
95
|
switchSession(sessionFile: string, cwd?: string, model?: string): void;
|
|
96
|
+
forkSession(sessionId: string, entryId: string): boolean;
|
|
95
97
|
createSession(cwd: string, model?: string, gitInit?: boolean, createRemote?: boolean, repoVisibility?: 'private' | 'public', cloneRemote?: boolean): void;
|
|
96
98
|
leaveSession(): void;
|
|
97
|
-
|
|
99
|
+
continueFolderConflict(): void;
|
|
98
100
|
ping(): void;
|
|
99
101
|
clearMessages(): void;
|
|
100
102
|
dismissSessionError(): void;
|
package/dist/client.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { writable, get } from "sveltore";
|
|
2
|
+
import { skillInvocationIdentity } from "./types.js";
|
|
2
3
|
const defaultState = {
|
|
3
4
|
connected: false,
|
|
4
5
|
connecting: false,
|
|
@@ -12,7 +13,7 @@ const defaultState = {
|
|
|
12
13
|
isStreaming: false,
|
|
13
14
|
messages: [],
|
|
14
15
|
clientId: null,
|
|
15
|
-
|
|
16
|
+
folderConflict: null,
|
|
16
17
|
isInterrupted: false,
|
|
17
18
|
notice: null,
|
|
18
19
|
sudoPrompt: null,
|
|
@@ -27,6 +28,8 @@ const defaultState = {
|
|
|
27
28
|
historyOffset: 0,
|
|
28
29
|
loadingMoreHistory: false,
|
|
29
30
|
contextUsage: null,
|
|
31
|
+
pendingSteering: [],
|
|
32
|
+
skills: [],
|
|
30
33
|
};
|
|
31
34
|
export class WhereverClient {
|
|
32
35
|
ws = null;
|
|
@@ -46,7 +49,7 @@ export class WhereverClient {
|
|
|
46
49
|
// Watchdog for an in-flight session_new. Symmetrical to loadWatchdog: creating
|
|
47
50
|
// a session sets creatingSession=true and shows a BLOCKING full-screen overlay,
|
|
48
51
|
// and the only things that clear it are session_created/session_error/
|
|
49
|
-
//
|
|
52
|
+
// session_interrupted (or a socket close). If none of those
|
|
50
53
|
// ever arrives (a slow git init / remote-repo creation, an error thrown before
|
|
51
54
|
// the reply is sent, or a half-open socket the liveness watchdog has not yet
|
|
52
55
|
// reaped), the overlay spins forever and the only recovery is a reload. This
|
|
@@ -519,7 +522,7 @@ export class WhereverClient {
|
|
|
519
522
|
}, WhereverClient.LOAD_WATCHDOG_MS);
|
|
520
523
|
}
|
|
521
524
|
// Clear the load watchdog. Called at every point the load resolves
|
|
522
|
-
// (message_history, session_error,
|
|
525
|
+
// (message_history, session_error, disconnect, leave).
|
|
523
526
|
clearLoadWatchdog() {
|
|
524
527
|
if (this.loadWatchdog) {
|
|
525
528
|
clearTimeout(this.loadWatchdog);
|
|
@@ -547,7 +550,7 @@ export class WhereverClient {
|
|
|
547
550
|
}, WhereverClient.CREATE_WATCHDOG_MS);
|
|
548
551
|
}
|
|
549
552
|
// Clear the create watchdog. Called at every point a create resolves
|
|
550
|
-
// (session_created, session_error,
|
|
553
|
+
// (session_created, session_error, session_interrupted,
|
|
551
554
|
// disconnect, leave).
|
|
552
555
|
clearCreateWatchdog() {
|
|
553
556
|
if (this.createWatchdog) {
|
|
@@ -606,23 +609,20 @@ export class WhereverClient {
|
|
|
606
609
|
}
|
|
607
610
|
// Any message that resolves an in-flight session_load disarms the watchdog.
|
|
608
611
|
// session_created arrives just before message_history; message_history is the
|
|
609
|
-
// real completion, but an error/
|
|
612
|
+
// real completion, but an error/destroy/interrupt also resolves it.
|
|
610
613
|
switch (msg.type) {
|
|
611
614
|
case 'message_history':
|
|
612
615
|
case 'session_error':
|
|
613
|
-
case 'session_conflict':
|
|
614
616
|
case 'session_destroyed':
|
|
615
617
|
case 'session_interrupted':
|
|
616
618
|
this.clearLoadWatchdog();
|
|
617
619
|
break;
|
|
618
620
|
}
|
|
619
621
|
// Any message that resolves an in-flight session_new disarms the create
|
|
620
|
-
// watchdog. session_created is the success path; error/
|
|
621
|
-
// it too.
|
|
622
|
+
// watchdog. session_created is the success path; error/interrupt end it too.
|
|
622
623
|
switch (msg.type) {
|
|
623
624
|
case 'session_created':
|
|
624
625
|
case 'session_error':
|
|
625
|
-
case 'session_conflict':
|
|
626
626
|
case 'session_interrupted':
|
|
627
627
|
this.clearCreateWatchdog();
|
|
628
628
|
break;
|
|
@@ -706,6 +706,29 @@ export class WhereverClient {
|
|
|
706
706
|
};
|
|
707
707
|
});
|
|
708
708
|
break;
|
|
709
|
+
case 'message_ack':
|
|
710
|
+
// The server accepted this outbound user message (a normal turn, or a
|
|
711
|
+
// mid-stream steer queued for the next step) and handed it to the agent.
|
|
712
|
+
// This is the delivery CONFIRMATION: it arrives immediately, so an
|
|
713
|
+
// accepted steer is not left waiting on the message_end (role:user)
|
|
714
|
+
// echo, which for a steer only comes at the next model call and can miss
|
|
715
|
+
// the confirmation window (flipping the message to a false "Retry").
|
|
716
|
+
// Content-matched to the oldest still-unconfirmed pending message.
|
|
717
|
+
if (typeof msg.content === 'string') {
|
|
718
|
+
this.confirmDeliveredByContent(msg.content);
|
|
719
|
+
}
|
|
720
|
+
break;
|
|
721
|
+
case 'queue_update':
|
|
722
|
+
// The server relayed pi's current steer queue. Replace our pending-steer
|
|
723
|
+
// set outright (it is the full queue): a message whose content is still
|
|
724
|
+
// in this set is a queued steer that has NOT yet been injected, so the
|
|
725
|
+
// UI can offer to cancel it. When a queued steer is delivered or
|
|
726
|
+
// cancelled, a fresh queue_update arrives with it removed.
|
|
727
|
+
this.stateStore.update((s) => ({
|
|
728
|
+
...s,
|
|
729
|
+
pendingSteering: Array.isArray(msg.steering) ? [...msg.steering] : [],
|
|
730
|
+
}));
|
|
731
|
+
break;
|
|
709
732
|
case 'message_end':
|
|
710
733
|
this.stateStore.update((s) => {
|
|
711
734
|
let newMessages = s.messages;
|
|
@@ -741,6 +764,26 @@ export class WhereverClient {
|
|
|
741
764
|
return get(this.stateStore);
|
|
742
765
|
}
|
|
743
766
|
}
|
|
767
|
+
// Skill invocations arrive TWICE from the server: first the RAW
|
|
768
|
+
// `/skill:<name> <args>` (as the immediate message_ack, which already
|
|
769
|
+
// confirmed the optimistic bubble by exact content), then the
|
|
770
|
+
// EXPANDED skill block (this message_end echo). They are the same
|
|
771
|
+
// invocation, so instead of appending the expanded form as a
|
|
772
|
+
// duplicate, REWRITE the already-present raw bubble to the expanded
|
|
773
|
+
// content so it renders as the skill chip.
|
|
774
|
+
const echoIdentity = msg.role === 'user' ? skillInvocationIdentity(msg.content) : null;
|
|
775
|
+
if (echoIdentity) {
|
|
776
|
+
const existing = [...newMessages]
|
|
777
|
+
.reverse()
|
|
778
|
+
.find((m) => m.role === 'user' &&
|
|
779
|
+
skillInvocationIdentity(m.content) === echoIdentity);
|
|
780
|
+
if (existing) {
|
|
781
|
+
if (existing.content !== msg.content) {
|
|
782
|
+
newMessages = newMessages.map((m) => m.id === existing.id ? { ...m, content: msg.content } : m);
|
|
783
|
+
}
|
|
784
|
+
return { ...s, messages: newMessages };
|
|
785
|
+
}
|
|
786
|
+
}
|
|
744
787
|
const lastUserMessage = [...newMessages]
|
|
745
788
|
.reverse()
|
|
746
789
|
.find((m) => m.role === 'user');
|
|
@@ -773,6 +816,11 @@ export class WhereverClient {
|
|
|
773
816
|
this.stateStore.update((s) => ({
|
|
774
817
|
...s,
|
|
775
818
|
isStreaming: false,
|
|
819
|
+
// The run ended: any steer that was queued has been delivered (or
|
|
820
|
+
// dropped), so nothing is cancellable anymore. The server also emits
|
|
821
|
+
// a final queue_update, but clear here defensively in case it is
|
|
822
|
+
// missed, so a stale "Cancel" affordance cannot linger.
|
|
823
|
+
pendingSteering: [],
|
|
776
824
|
messages: s.messages.map((m) => m.isStreaming
|
|
777
825
|
? {
|
|
778
826
|
...m,
|
|
@@ -812,6 +860,37 @@ export class WhereverClient {
|
|
|
812
860
|
? { ...m, isStreaming: false }
|
|
813
861
|
: m);
|
|
814
862
|
const startedAt = Date.now();
|
|
863
|
+
const isForce = !!msg.forceCommand;
|
|
864
|
+
// A `!command` / `!!command` already rendered an OPTIMISTIC bash bubble
|
|
865
|
+
// locally at send time (so it appeared instantly, without waiting for
|
|
866
|
+
// this server round-trip). Reconcile onto the OLDEST such pending bubble
|
|
867
|
+
// instead of appending a duplicate: adopt the real startedAt and drop
|
|
868
|
+
// the optimistic flag, keeping any output the user's bubble may already
|
|
869
|
+
// carry empty (tool_update/tool_end will fill it). Fall back to append
|
|
870
|
+
// when there is no pending optimistic bubble (agent tool call, or the
|
|
871
|
+
// optimistic one was already reconciled).
|
|
872
|
+
if (isForce) {
|
|
873
|
+
const pending = finalizedMessages.find((m) => m.role === 'tool' && m.optimistic && m.isStreaming);
|
|
874
|
+
if (pending) {
|
|
875
|
+
return {
|
|
876
|
+
...s,
|
|
877
|
+
messages: finalizedMessages.map((m) => m.id === pending.id
|
|
878
|
+
? {
|
|
879
|
+
...m,
|
|
880
|
+
optimistic: false,
|
|
881
|
+
toolName: msg.toolName,
|
|
882
|
+
toolArgs,
|
|
883
|
+
content: toolArgs
|
|
884
|
+
? `$ ${msg.toolName} ${toolArgs}`
|
|
885
|
+
: `$ ${msg.toolName}`,
|
|
886
|
+
startedAt,
|
|
887
|
+
timestamp: startedAt,
|
|
888
|
+
forceCommand: true,
|
|
889
|
+
}
|
|
890
|
+
: m),
|
|
891
|
+
};
|
|
892
|
+
}
|
|
893
|
+
}
|
|
815
894
|
const newMsg = {
|
|
816
895
|
id: this.generateId(),
|
|
817
896
|
role: 'tool',
|
|
@@ -824,7 +903,7 @@ export class WhereverClient {
|
|
|
824
903
|
toolArgs: toolArgs,
|
|
825
904
|
toolOutput: '',
|
|
826
905
|
startedAt,
|
|
827
|
-
...(
|
|
906
|
+
...(isForce ? { forceCommand: true } : {}),
|
|
828
907
|
};
|
|
829
908
|
return {
|
|
830
909
|
...s,
|
|
@@ -963,8 +1042,16 @@ export class WhereverClient {
|
|
|
963
1042
|
isStreaming: msg.isStreaming ?? false,
|
|
964
1043
|
creatingSession: false,
|
|
965
1044
|
// The server forces read-only for sessions in a configured
|
|
966
|
-
// sessions.readOnly folder (observe-only fleet view)
|
|
1045
|
+
// sessions.readOnly folder (observe-only fleet view) AND, transiently,
|
|
1046
|
+
// for a folder conflict until the user clicks "Continue anyway".
|
|
967
1047
|
readOnly: msg.readOnly ?? false,
|
|
1048
|
+
// Folder-conflict warning banner. Set when attaching to a session in a
|
|
1049
|
+
// folder that already has another active session. `continued` starts
|
|
1050
|
+
// false (composer stays read-only, banner offers "Continue anyway");
|
|
1051
|
+
// `active` is refreshed by live folder_conflict updates.
|
|
1052
|
+
folderConflict: msg.folderConflict
|
|
1053
|
+
? { cwd: msg.cwd, active: true, continued: false }
|
|
1054
|
+
: null,
|
|
968
1055
|
// pending -> the history is painted now but the live agent is still
|
|
969
1056
|
// building; keep the composer disabled (agentPending) until
|
|
970
1057
|
// session_ready. A non-pending create (new session, warm reload) is
|
|
@@ -973,6 +1060,9 @@ export class WhereverClient {
|
|
|
973
1060
|
// Initial context-usage snapshot for the new session (null if unknown;
|
|
974
1061
|
// live updates arrive via 'context_usage').
|
|
975
1062
|
contextUsage: msg.contextUsage ?? null,
|
|
1063
|
+
// Reset skill-command autocomplete for the newly attached session; the
|
|
1064
|
+
// authoritative list is (re-)requested on session_ready.
|
|
1065
|
+
skills: [],
|
|
976
1066
|
}));
|
|
977
1067
|
break;
|
|
978
1068
|
case 'session_ready':
|
|
@@ -991,6 +1081,23 @@ export class WhereverClient {
|
|
|
991
1081
|
contextUsage: msg.contextUsage ?? s.contextUsage,
|
|
992
1082
|
};
|
|
993
1083
|
});
|
|
1084
|
+
// The live agent (with its resource loader) now exists, so its skill
|
|
1085
|
+
// commands are resolvable. Ask for them to populate `/skill:` composer
|
|
1086
|
+
// autocomplete. Safe to re-request; the server replies with the full list.
|
|
1087
|
+
{
|
|
1088
|
+
const sid = get(this.stateStore).sessionId;
|
|
1089
|
+
if (sid)
|
|
1090
|
+
this.send({ type: 'skills_request', sessionId: sid });
|
|
1091
|
+
}
|
|
1092
|
+
break;
|
|
1093
|
+
case 'skills_list':
|
|
1094
|
+
// The set of `/skill:<name>` commands for the active session. Replace
|
|
1095
|
+
// outright; ignore a list for a session we already switched away from.
|
|
1096
|
+
this.stateStore.update((s) => {
|
|
1097
|
+
if (s.sessionId && msg.sessionId && s.sessionId !== msg.sessionId)
|
|
1098
|
+
return s;
|
|
1099
|
+
return { ...s, skills: Array.isArray(msg.skills) ? msg.skills : [] };
|
|
1100
|
+
});
|
|
994
1101
|
break;
|
|
995
1102
|
case 'context_usage':
|
|
996
1103
|
this.stateStore.update((s) => ({
|
|
@@ -1060,19 +1167,37 @@ export class WhereverClient {
|
|
|
1060
1167
|
agentPending: false,
|
|
1061
1168
|
}));
|
|
1062
1169
|
break;
|
|
1063
|
-
case '
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1170
|
+
case 'folder_conflict':
|
|
1171
|
+
// Live update of whether another active session still exists in this
|
|
1172
|
+
// client's folder. The banner appears when a second session shows up in
|
|
1173
|
+
// the folder and disappears once it is gone. Applies only to the client's
|
|
1174
|
+
// OWN folder; a stale update for a different cwd is ignored.
|
|
1175
|
+
this.stateStore.update((s) => {
|
|
1176
|
+
if (!s.sessionId)
|
|
1177
|
+
return s;
|
|
1178
|
+
if (s.activeCwd && msg.cwd !== s.activeCwd)
|
|
1179
|
+
return s;
|
|
1180
|
+
if (!msg.active) {
|
|
1181
|
+
// No other session remains: fully resolved, drop the banner.
|
|
1182
|
+
return s.folderConflict ? { ...s, folderConflict: null } : s;
|
|
1183
|
+
}
|
|
1184
|
+
if (s.folderConflict) {
|
|
1185
|
+
// Already showing: just refresh, preserving the user's `continued`
|
|
1186
|
+
// choice (so we don't re-disable a composer they already enabled).
|
|
1187
|
+
return {
|
|
1188
|
+
...s,
|
|
1189
|
+
folderConflict: { ...s.folderConflict, cwd: msg.cwd, active: true },
|
|
1190
|
+
};
|
|
1191
|
+
}
|
|
1192
|
+
// A conflict appeared AFTER we were already attached (another client
|
|
1193
|
+
// opened a second session in our folder). Raise the banner. We were
|
|
1194
|
+
// sending fine until now, so treat it as already-`continued` rather
|
|
1195
|
+
// than yanking the composer into read-only underneath the user.
|
|
1196
|
+
return {
|
|
1197
|
+
...s,
|
|
1198
|
+
folderConflict: { cwd: msg.cwd, active: true, continued: true },
|
|
1199
|
+
};
|
|
1200
|
+
});
|
|
1076
1201
|
break;
|
|
1077
1202
|
case 'session_interrupted':
|
|
1078
1203
|
this.stateStore.update((s) => ({
|
|
@@ -1332,6 +1457,9 @@ export class WhereverClient {
|
|
|
1332
1457
|
isStreaming: false,
|
|
1333
1458
|
toolName: m.toolName,
|
|
1334
1459
|
sessionId,
|
|
1460
|
+
// Carry the source entry id (set on user messages by the server) so the
|
|
1461
|
+
// UI can offer "Fork from here" on each user message.
|
|
1462
|
+
...(typeof m.entryId === 'string' && m.entryId ? { entryId: m.entryId } : {}),
|
|
1335
1463
|
});
|
|
1336
1464
|
}
|
|
1337
1465
|
}
|
|
@@ -1461,12 +1589,47 @@ export class WhereverClient {
|
|
|
1461
1589
|
// A `!command` / `!!command` is intercepted by the server and run as a bash
|
|
1462
1590
|
// tool call, NOT delivered to the agent. The server never echoes it back as a
|
|
1463
1591
|
// user message, and the bash tool_start/tool_end events are the real, durable
|
|
1464
|
-
// feedback (and are recorded in history). So do NOT add any local
|
|
1465
|
-
// for it: a bubble here would be a transient duplicate that vanishes on
|
|
1592
|
+
// feedback (and are recorded in history). So do NOT add any local USER echo
|
|
1593
|
+
// for it: a user bubble here would be a transient duplicate that vanishes on
|
|
1466
1594
|
// reload (bash runs are not part of the user-message transcript) and, if
|
|
1467
|
-
// delivery-tracked, would wrongly time out into a retry/discard banner.
|
|
1468
|
-
//
|
|
1595
|
+
// delivery-tracked, would wrongly time out into a retry/discard banner.
|
|
1596
|
+
//
|
|
1597
|
+
// We DO, however, render an optimistic bash TOOL bubble immediately so the
|
|
1598
|
+
// command shows up instantly instead of only after the server round-trip
|
|
1599
|
+
// (client -> server -> tool_start -> client). It is tagged `optimistic` so
|
|
1600
|
+
// the real `tool_start` reconciles onto it (no duplicate) and is NOT
|
|
1601
|
+
// delivery-tracked (no watchdog/banner). Skip the optimistic bubble for
|
|
1602
|
+
// `!sudo ...`: the server defers those behind a password prompt and does not
|
|
1603
|
+
// emit `tool_start` until the password arrives, so a pending bubble would sit
|
|
1604
|
+
// there streaming (and never reconcile if the prompt is cancelled).
|
|
1469
1605
|
if (text.trimStart().startsWith('!')) {
|
|
1606
|
+
const raw = text.trimStart();
|
|
1607
|
+
const isExcluded = raw.startsWith('!!');
|
|
1608
|
+
const command = (isExcluded ? raw.slice(2) : raw.slice(1)).trim();
|
|
1609
|
+
const isSudo = /^sudo(\s|$)/.test(command);
|
|
1610
|
+
if (command && !isSudo) {
|
|
1611
|
+
const toolArgs = `command=${JSON.stringify(command)}`;
|
|
1612
|
+
const startedAt = Date.now();
|
|
1613
|
+
const optimisticTool = {
|
|
1614
|
+
id: this.generateId(),
|
|
1615
|
+
role: 'tool',
|
|
1616
|
+
content: `$ bash ${toolArgs}`,
|
|
1617
|
+
timestamp: startedAt,
|
|
1618
|
+
isStreaming: true,
|
|
1619
|
+
toolName: 'bash',
|
|
1620
|
+
toolArgs,
|
|
1621
|
+
toolOutput: '',
|
|
1622
|
+
startedAt,
|
|
1623
|
+
forceCommand: true,
|
|
1624
|
+
optimistic: true,
|
|
1625
|
+
};
|
|
1626
|
+
this.stateStore.update((st) => ({
|
|
1627
|
+
...st,
|
|
1628
|
+
sessionError: null,
|
|
1629
|
+
messages: [...st.messages, optimisticTool],
|
|
1630
|
+
}));
|
|
1631
|
+
return true;
|
|
1632
|
+
}
|
|
1470
1633
|
this.stateStore.update((st) => ({ ...st, sessionError: null }));
|
|
1471
1634
|
return true;
|
|
1472
1635
|
}
|
|
@@ -1594,18 +1757,44 @@ export class WhereverClient {
|
|
|
1594
1757
|
// Mark the oldest still-unconfirmed user message with this content as
|
|
1595
1758
|
// delivered (the server echoed it back). Content-matched because the server
|
|
1596
1759
|
// echo carries no client message id. Returns true if one was confirmed.
|
|
1760
|
+
//
|
|
1761
|
+
// Skill invocations need a looser match: the client optimistically echoes the
|
|
1762
|
+
// RAW `/skill:<name> <args>`, but the server echoes the EXPANDED skill block
|
|
1763
|
+
// (pi inlines the skill body before storing/echoing). Exact-content matching
|
|
1764
|
+
// would miss, leaving the raw bubble orphaned as "failed" AND appending the
|
|
1765
|
+
// expanded echo as a duplicate. So fall back to matching a pending message
|
|
1766
|
+
// whose skill-invocation IDENTITY (name + args) equals the echo's, and REWRITE
|
|
1767
|
+
// its content to the confirmed (expanded) form so it renders as the skill chip
|
|
1768
|
+
// and the server's own echo is then deduped against it.
|
|
1597
1769
|
confirmDeliveredByContent(content) {
|
|
1598
1770
|
let confirmedId = null;
|
|
1599
1771
|
let sessionId = null;
|
|
1772
|
+
const echoIdentity = skillInvocationIdentity(content);
|
|
1600
1773
|
this.stateStore.update((st) => {
|
|
1601
|
-
|
|
1774
|
+
let target = st.messages.find((m) => m.role === 'user' && m.delivery !== undefined && m.content === content);
|
|
1775
|
+
// Skill-identity fallback: match the RAW optimistic echo to this EXPANDED
|
|
1776
|
+
// server echo when they are the same invocation.
|
|
1777
|
+
if (!target && echoIdentity) {
|
|
1778
|
+
target = st.messages.find((m) => m.role === 'user' &&
|
|
1779
|
+
m.delivery !== undefined &&
|
|
1780
|
+
skillInvocationIdentity(m.content) === echoIdentity);
|
|
1781
|
+
}
|
|
1602
1782
|
if (!target)
|
|
1603
1783
|
return st;
|
|
1604
1784
|
confirmedId = target.id;
|
|
1605
1785
|
sessionId = st.sessionId;
|
|
1606
1786
|
return {
|
|
1607
1787
|
...st,
|
|
1608
|
-
messages: st.messages.map((m) => m.id === target.id
|
|
1788
|
+
messages: st.messages.map((m) => m.id === target.id
|
|
1789
|
+
? {
|
|
1790
|
+
...m,
|
|
1791
|
+
delivery: undefined,
|
|
1792
|
+
// Adopt the expanded content so the skill chip renders (and the
|
|
1793
|
+
// server's message_end echo dedupes against it instead of
|
|
1794
|
+
// appending a second bubble).
|
|
1795
|
+
...(echoIdentity ? { content } : {}),
|
|
1796
|
+
}
|
|
1797
|
+
: m),
|
|
1609
1798
|
};
|
|
1610
1799
|
});
|
|
1611
1800
|
if (confirmedId) {
|
|
@@ -1661,10 +1850,21 @@ export class WhereverClient {
|
|
|
1661
1850
|
return;
|
|
1662
1851
|
this.send({ type: 'abort', sessionId: s.sessionId });
|
|
1663
1852
|
}
|
|
1853
|
+
// Cancel the queued mid-stream steer messages for the active session without
|
|
1854
|
+
// aborting the in-flight turn. Optimistically clears our local pending-steer
|
|
1855
|
+
// set so the "Cancel" affordance disappears immediately; the server's fresh
|
|
1856
|
+
// queue_update (after clearQueue) reconciles the authoritative state.
|
|
1857
|
+
cancelSteer() {
|
|
1858
|
+
const s = get(this.stateStore);
|
|
1859
|
+
if (!s.sessionId)
|
|
1860
|
+
return;
|
|
1861
|
+
this.send({ type: 'cancel_steer', sessionId: s.sessionId });
|
|
1862
|
+
this.stateStore.update((st) => ({ ...st, pendingSteering: [] }));
|
|
1863
|
+
}
|
|
1664
1864
|
joinSession(sessionFile, cwd, model) {
|
|
1665
1865
|
this.stateStore.update((s) => ({
|
|
1666
1866
|
...s,
|
|
1667
|
-
|
|
1867
|
+
folderConflict: null,
|
|
1668
1868
|
sessionError: null,
|
|
1669
1869
|
loadingSession: true,
|
|
1670
1870
|
agentPending: false,
|
|
@@ -1701,7 +1901,7 @@ export class WhereverClient {
|
|
|
1701
1901
|
activeCwd: null,
|
|
1702
1902
|
activeModel: null,
|
|
1703
1903
|
readOnly: false,
|
|
1704
|
-
|
|
1904
|
+
folderConflict: null,
|
|
1705
1905
|
sessionError: null,
|
|
1706
1906
|
notice: null,
|
|
1707
1907
|
sudoPrompt: null,
|
|
@@ -1709,6 +1909,7 @@ export class WhereverClient {
|
|
|
1709
1909
|
resyncing: false,
|
|
1710
1910
|
agentPending: false,
|
|
1711
1911
|
contextUsage: null,
|
|
1912
|
+
pendingSteering: [],
|
|
1712
1913
|
loadingSession: true,
|
|
1713
1914
|
}));
|
|
1714
1915
|
this.resumeSessionFile = null;
|
|
@@ -1720,10 +1921,21 @@ export class WhereverClient {
|
|
|
1720
1921
|
this.send({ type: 'session_load', sessionFile, cwd, model });
|
|
1721
1922
|
this.armLoadWatchdog();
|
|
1722
1923
|
}
|
|
1924
|
+
// Fork the given session at a specific user-message entry, mirroring pi's
|
|
1925
|
+
// `/fork` (position 'before'). The server creates a new branched session file
|
|
1926
|
+
// and replies with `session_forked` (carrying the new file path + the chosen
|
|
1927
|
+
// message's text). The app layer listens for that reply, switches to the new
|
|
1928
|
+
// session, and pre-fills the composer. This method only issues the request;
|
|
1929
|
+
// it does not itself change the active session.
|
|
1930
|
+
forkSession(sessionId, entryId) {
|
|
1931
|
+
if (!sessionId || !entryId)
|
|
1932
|
+
return false;
|
|
1933
|
+
return this.send({ type: 'session_fork', sessionId, entryId });
|
|
1934
|
+
}
|
|
1723
1935
|
createSession(cwd, model, gitInit, createRemote, repoVisibility, cloneRemote) {
|
|
1724
1936
|
this.stateStore.update((s) => ({
|
|
1725
1937
|
...s,
|
|
1726
|
-
|
|
1938
|
+
folderConflict: null,
|
|
1727
1939
|
sessionError: null,
|
|
1728
1940
|
creatingSession: true,
|
|
1729
1941
|
loadingSession: false,
|
|
@@ -1772,26 +1984,32 @@ export class WhereverClient {
|
|
|
1772
1984
|
resyncing: false,
|
|
1773
1985
|
agentPending: false,
|
|
1774
1986
|
contextUsage: null,
|
|
1987
|
+
pendingSteering: [],
|
|
1775
1988
|
}));
|
|
1776
1989
|
this.clearLoadWatchdog();
|
|
1777
1990
|
this.resumeSessionFile = null;
|
|
1778
1991
|
this.resumeCwd = undefined;
|
|
1779
1992
|
this.resumeModel = undefined;
|
|
1780
1993
|
}
|
|
1781
|
-
|
|
1994
|
+
// "Continue anyway" on the folder-conflict warning banner: ask the server to
|
|
1995
|
+
// lift read-only for this client's current session (both sessions in the
|
|
1996
|
+
// folder then run concurrently; the other is NOT aborted). Optimistically
|
|
1997
|
+
// enable the composer and mark the banner `continued` so it drops its button
|
|
1998
|
+
// but stays as a passive warning until the other session leaves the folder.
|
|
1999
|
+
continueFolderConflict() {
|
|
1782
2000
|
const s = get(this.stateStore);
|
|
1783
|
-
if (!s.
|
|
2001
|
+
if (!s.folderConflict || !s.sessionId)
|
|
1784
2002
|
return;
|
|
1785
2003
|
this.send({
|
|
1786
|
-
type: '
|
|
1787
|
-
|
|
1788
|
-
sessionId: s.conflict.targetSessionId,
|
|
1789
|
-
cwd: cwd || s.conflict.conflictingCwd,
|
|
2004
|
+
type: 'folder_conflict_continue',
|
|
2005
|
+
sessionId: s.sessionId,
|
|
1790
2006
|
});
|
|
1791
2007
|
this.stateStore.update((s) => ({
|
|
1792
2008
|
...s,
|
|
1793
|
-
|
|
1794
|
-
|
|
2009
|
+
readOnly: false,
|
|
2010
|
+
folderConflict: s.folderConflict
|
|
2011
|
+
? { ...s.folderConflict, continued: true }
|
|
2012
|
+
: null,
|
|
1795
2013
|
}));
|
|
1796
2014
|
}
|
|
1797
2015
|
ping() {
|