@primusclaw/personal-agent 0.15.4 → 0.15.5
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/dist/index.js +237 -26
- package/dist/types/locales/remote.d.ts +2 -0
- package/dist/types/remote/chats.d.ts +5 -0
- package/dist/types/remote/events.d.ts +7 -0
- package/dist/types/remote/follow/echoes.d.ts +31 -0
- package/dist/types/remote/follow/follower.d.ts +1 -1
- package/dist/types/remote/follow/retract.d.ts +27 -0
- package/dist/types/remote/follow/speaker.d.ts +21 -2
- package/dist/types/remote/follow/timings.d.ts +4 -0
- package/dist/types/remote/lines.d.ts +3 -0
- package/dist/types/remote/turns/runner.d.ts +11 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -20331,6 +20331,8 @@ var remoteText = defineCatalog({
|
|
|
20331
20331
|
typedInTerminal: (p) => `\u{1F5A5} **Typed in the terminal:**
|
|
20332
20332
|
|
|
20333
20333
|
${p.quoted}`,
|
|
20334
|
+
/** What a message that showed a prompt typed in the terminal is changed to when the terminal took the prompt back and the chat cannot delete it. */
|
|
20335
|
+
typedTakenBack: "\u{1F5A5} _Taken back in the terminal._",
|
|
20334
20336
|
shareConnect: "Connect (the terminal keeps working)",
|
|
20335
20337
|
shareWatch: "Watch only (the terminal keeps working)",
|
|
20336
20338
|
shareNoteTyped: "Open in a terminal: once connected, what you send here is typed into that terminal, and its replies and what is typed there show up here; the terminal keeps working, and you can leave at any time",
|
|
@@ -20517,6 +20519,7 @@ It installs the connector, pairs the machine with you and keeps it running. I wi
|
|
|
20517
20519
|
typedInTerminal: (p) => `\u{1F5A5} **\u7EC8\u7AEF\u91CC\u8F93\u5165\uFF1A**
|
|
20518
20520
|
|
|
20519
20521
|
${p.quoted}`,
|
|
20522
|
+
typedTakenBack: "\u{1F5A5} _\u7EC8\u7AEF\u91CC\u5DF2\u64A4\u56DE\u3002_",
|
|
20520
20523
|
shareConnect: "\u8FDE\u4E0A\uFF08\u7EC8\u7AEF\u7167\u5E38\u7528\uFF09",
|
|
20521
20524
|
shareWatch: "\u53EA\u770B\uFF08\u7EC8\u7AEF\u7167\u5E38\u7528\uFF09",
|
|
20522
20525
|
shareNoteTyped: "\u7EC8\u7AEF\u91CC\u6B63\u5728\u7528\uFF1A\u8FDE\u4E0A\u540E\uFF0C\u4F60\u5728\u8FD9\u91CC\u53D1\u7684\u6D88\u606F\u4F1A\u4F5C\u4E3A\u8F93\u5165\u6253\u8FDB\u90A3\u4E2A\u7EC8\u7AEF\uFF0C\u56DE\u590D\u548C\u7EC8\u7AEF\u91CC\u6572\u7684\u5185\u5BB9\u90FD\u4F1A\u51FA\u73B0\u5728\u8FD9\u91CC\uFF1B\u7EC8\u7AEF\u7167\u5E38\u7528\uFF0C\u968F\u65F6\u53EF\u4EE5\u65AD\u5F00",
|
|
@@ -28407,6 +28410,7 @@ __export(remote_exports, {
|
|
|
28407
28410
|
takesFiles: () => takesFiles,
|
|
28408
28411
|
terminalClosedLine: () => terminalClosedLine,
|
|
28409
28412
|
typedLine: () => typedLine,
|
|
28413
|
+
typedTakenBackLine: () => typedTakenBackLine,
|
|
28410
28414
|
typesInto: () => typesInto,
|
|
28411
28415
|
unattendedAllowed: () => unattendedAllowed,
|
|
28412
28416
|
unsolicitedParts: () => unsolicitedParts,
|
|
@@ -29056,6 +29060,8 @@ var NOTHING2 = Object.freeze({
|
|
|
29056
29060
|
queuedSeq: null,
|
|
29057
29061
|
queuedHeld: false,
|
|
29058
29062
|
typed: null,
|
|
29063
|
+
typedId: null,
|
|
29064
|
+
retracted: null,
|
|
29059
29065
|
terminal: null,
|
|
29060
29066
|
terminalMode: null,
|
|
29061
29067
|
acp: null
|
|
@@ -29155,9 +29161,18 @@ function unwrapPasted(text9) {
|
|
|
29155
29161
|
return `${at > 0 ? "\n" : ""}${inner}${end < all.length ? "\n" : ""}`;
|
|
29156
29162
|
});
|
|
29157
29163
|
}
|
|
29164
|
+
var MESSAGE_ID_MAX = 128;
|
|
29165
|
+
function messageIdOf2(payload) {
|
|
29166
|
+
const id = str7(update(payload)["messageId"]);
|
|
29167
|
+
return id !== "" && id.length <= MESSAGE_ID_MAX ? id : null;
|
|
29168
|
+
}
|
|
29158
29169
|
function typed(payload) {
|
|
29159
29170
|
const text9 = pyStrip(unwrapPasted(textOf7(payload)));
|
|
29160
|
-
return text9 && !NOT_TYPED.test(text9) ? remoteStep({ typed: text9 }) : NOTHING2;
|
|
29171
|
+
return text9 && !NOT_TYPED.test(text9) ? remoteStep({ typed: text9, typedId: messageIdOf2(payload) }) : NOTHING2;
|
|
29172
|
+
}
|
|
29173
|
+
function retracted(payload) {
|
|
29174
|
+
const id = messageIdOf2(payload);
|
|
29175
|
+
return id === null ? NOTHING2 : remoteStep({ retracted: id });
|
|
29161
29176
|
}
|
|
29162
29177
|
var TOOL_NAME = /^[A-Za-z][\w.-]{0,63}$/u;
|
|
29163
29178
|
function toolNameOf(u) {
|
|
@@ -29263,6 +29278,7 @@ var READERS = {
|
|
|
29263
29278
|
agent_message_chunk: chunk,
|
|
29264
29279
|
agent_thought_chunk: chunk,
|
|
29265
29280
|
user_message_chunk: typed,
|
|
29281
|
+
user_message_retracted: retracted,
|
|
29266
29282
|
tool_call: tool,
|
|
29267
29283
|
tool_call_update: tool,
|
|
29268
29284
|
plan: (payload) => remoteStep({ plan: planLine(payload) }),
|
|
@@ -29404,6 +29420,9 @@ function typedLine(text9, lang) {
|
|
|
29404
29420
|
const quoted = pySplitlines(shown3).slice(0, TYPED_LINES_MAX).map((line3) => pyStrip(line3) ? `> ${line3}` : ">").join("\n");
|
|
29405
29421
|
return remoteText.in(lang).typedInTerminal({ quoted });
|
|
29406
29422
|
}
|
|
29423
|
+
function typedTakenBackLine(lang) {
|
|
29424
|
+
return remoteText.in(lang).typedTakenBack;
|
|
29425
|
+
}
|
|
29407
29426
|
var WAIT_LINE_MAX_ZH = 6;
|
|
29408
29427
|
var WAIT_LINE_MAX_EN = 16;
|
|
29409
29428
|
var QUEUED_KEYS = /* @__PURE__ */ new Map([
|
|
@@ -31559,6 +31578,65 @@ function perPerson(guard) {
|
|
|
31559
31578
|
};
|
|
31560
31579
|
}
|
|
31561
31580
|
|
|
31581
|
+
// packages/core/src/remote/follow/echoes.ts
|
|
31582
|
+
var ECHOES_KEPT = 16;
|
|
31583
|
+
var TypedEchoes = class {
|
|
31584
|
+
posted = /* @__PURE__ */ new Map();
|
|
31585
|
+
/** Prompts the terminal took back before any message of theirs was recorded (a post that landed late may still be). */
|
|
31586
|
+
early = /* @__PURE__ */ new Set();
|
|
31587
|
+
/** `message` shows `prompt` (or one more block of it). */
|
|
31588
|
+
remember(prompt, message) {
|
|
31589
|
+
const shown3 = this.posted.get(prompt) ?? { messages: [], tries: this.early.delete(prompt) ? 0 : null };
|
|
31590
|
+
this.posted.delete(prompt);
|
|
31591
|
+
shown3.messages.push(message);
|
|
31592
|
+
this.posted.set(prompt, shown3);
|
|
31593
|
+
for (const oldest of this.posted.keys()) {
|
|
31594
|
+
if (this.posted.size <= ECHOES_KEPT) break;
|
|
31595
|
+
this.posted.delete(oldest);
|
|
31596
|
+
}
|
|
31597
|
+
}
|
|
31598
|
+
/** The messages that show `prompt`, oldest first; none when it was not shown (or was let go). */
|
|
31599
|
+
of(prompt) {
|
|
31600
|
+
return this.posted.get(prompt)?.messages ?? [];
|
|
31601
|
+
}
|
|
31602
|
+
/**
|
|
31603
|
+
* The terminal took `prompt` back: false when it was not shown (nothing to take away now). One whose post is still in flight (it
|
|
31604
|
+
* lands after the reader was cancelled) is remembered as taken back, so that its message goes as soon as it is recorded.
|
|
31605
|
+
*/
|
|
31606
|
+
takeBack(prompt) {
|
|
31607
|
+
const shown3 = this.posted.get(prompt);
|
|
31608
|
+
if (shown3 === void 0) {
|
|
31609
|
+
this.early.delete(prompt);
|
|
31610
|
+
this.early.add(prompt);
|
|
31611
|
+
for (const oldest of this.early) {
|
|
31612
|
+
if (this.early.size <= ECHOES_KEPT) break;
|
|
31613
|
+
this.early.delete(oldest);
|
|
31614
|
+
}
|
|
31615
|
+
return false;
|
|
31616
|
+
}
|
|
31617
|
+
shown3.tries ??= 0;
|
|
31618
|
+
return true;
|
|
31619
|
+
}
|
|
31620
|
+
/** The prompts the terminal took back whose messages are still to be taken away, with the tries each has had since the first. */
|
|
31621
|
+
pending() {
|
|
31622
|
+
const pending = /* @__PURE__ */ new Map();
|
|
31623
|
+
for (const [prompt, shown3] of this.posted) if (shown3.tries !== null) pending.set(prompt, shown3.tries);
|
|
31624
|
+
return pending;
|
|
31625
|
+
}
|
|
31626
|
+
/** Another try at `prompt` is made: counted. */
|
|
31627
|
+
tried(prompt) {
|
|
31628
|
+
const shown3 = this.posted.get(prompt);
|
|
31629
|
+
if (shown3?.tries != null) shown3.tries += 1;
|
|
31630
|
+
}
|
|
31631
|
+
/** `left` are the messages of `prompt` still to be taken away (a taking away that failed): none forgets the prompt. */
|
|
31632
|
+
settle(prompt, left) {
|
|
31633
|
+
const shown3 = this.posted.get(prompt);
|
|
31634
|
+
if (shown3 === void 0) return;
|
|
31635
|
+
if (left.length === 0) this.posted.delete(prompt);
|
|
31636
|
+
else shown3.messages = [...left];
|
|
31637
|
+
}
|
|
31638
|
+
};
|
|
31639
|
+
|
|
31562
31640
|
// packages/core/src/remote/chats.ts
|
|
31563
31641
|
var TYPED_PATHS_KEPT = 20;
|
|
31564
31642
|
var TYPED_PATH_SECONDS = 3600;
|
|
@@ -31593,6 +31671,8 @@ var ChatRegistry = class {
|
|
|
31593
31671
|
/** Whether the agent of the attached session can take over a conversation a terminal has open. */
|
|
31594
31672
|
agentTakeover = /* @__PURE__ */ new Map();
|
|
31595
31673
|
typed = /* @__PURE__ */ new Map();
|
|
31674
|
+
/** The messages that show what was typed at the terminal the chat shares, to take one away when the terminal takes its prompt back. */
|
|
31675
|
+
echoes = /* @__PURE__ */ new Map();
|
|
31596
31676
|
readOnly = /* @__PURE__ */ new Map();
|
|
31597
31677
|
readOnlyKnown = /* @__PURE__ */ new Map();
|
|
31598
31678
|
terminalInput = /* @__PURE__ */ new Map();
|
|
@@ -31709,6 +31789,12 @@ var ChatRegistry = class {
|
|
|
31709
31789
|
this.rowHinted.set(chatKey, sessionId);
|
|
31710
31790
|
return true;
|
|
31711
31791
|
}
|
|
31792
|
+
/** The chat's record of the messages that show prompts typed at its terminal. */
|
|
31793
|
+
echoesOf(chatKey) {
|
|
31794
|
+
const kept = this.echoes.get(chatKey) ?? new TypedEchoes();
|
|
31795
|
+
this.echoes.set(chatKey, kept);
|
|
31796
|
+
return kept;
|
|
31797
|
+
}
|
|
31712
31798
|
/** What is sent to the chat's session is typed into a terminal on the machine. */
|
|
31713
31799
|
typesIntoTerminal(chatKey, sessionId) {
|
|
31714
31800
|
return sessionId !== null && this.terminalInput.get(chatKey) === sessionId;
|
|
@@ -31745,6 +31831,7 @@ var ChatRegistry = class {
|
|
|
31745
31831
|
/** Everything known of a chat whose person unlinked (its session's reader is stopped by the caller). */
|
|
31746
31832
|
forget(chatKey) {
|
|
31747
31833
|
this.typed.delete(chatKey);
|
|
31834
|
+
this.echoes.delete(chatKey);
|
|
31748
31835
|
this.agentUnattended.delete(chatKey);
|
|
31749
31836
|
this.readOnly.delete(chatKey);
|
|
31750
31837
|
this.readOnlyKnown.delete(chatKey);
|
|
@@ -32843,12 +32930,65 @@ var WATCH_TIMINGS = {
|
|
|
32843
32930
|
};
|
|
32844
32931
|
var RECONNECT_MAX_MS = 6e4;
|
|
32845
32932
|
var RETRY_MS = 15e3;
|
|
32933
|
+
var RETRACT_RETRY_MS = 2e3;
|
|
32846
32934
|
var STOP_WAIT_MS = 15e3;
|
|
32847
32935
|
var CURSOR_EVERY = 25;
|
|
32848
32936
|
function reconnectDelayMs(timings, failures) {
|
|
32849
32937
|
return Math.min(RECONNECT_MAX_MS, timings.reconnectMs * 2 ** Math.min(failures, 8));
|
|
32850
32938
|
}
|
|
32851
32939
|
|
|
32940
|
+
// packages/core/src/remote/follow/retract.ts
|
|
32941
|
+
var RETRACT_TRIES = 3;
|
|
32942
|
+
var RETRACT_DRAINS = 5;
|
|
32943
|
+
function unlessCutOff(work, signal) {
|
|
32944
|
+
if (signal === void 0) return work;
|
|
32945
|
+
if (signal.aborted) return Promise.reject(new Error("cut off"));
|
|
32946
|
+
return new Promise((resolve, reject) => {
|
|
32947
|
+
const onAbort = () => {
|
|
32948
|
+
reject(new Error("cut off"));
|
|
32949
|
+
};
|
|
32950
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
32951
|
+
work.then(resolve, reject).finally(() => {
|
|
32952
|
+
signal.removeEventListener("abort", onAbort);
|
|
32953
|
+
});
|
|
32954
|
+
});
|
|
32955
|
+
}
|
|
32956
|
+
async function takeAway(to, message, tries, cx) {
|
|
32957
|
+
for (let attempt = 0; attempt < tries; attempt += 1) {
|
|
32958
|
+
if (attempt > 0) {
|
|
32959
|
+
try {
|
|
32960
|
+
await unlessCutOff(cx.clock.sleep((cx.retryMs ?? RETRACT_RETRY_MS) * attempt), cx.cutOff);
|
|
32961
|
+
} catch {
|
|
32962
|
+
return false;
|
|
32963
|
+
}
|
|
32964
|
+
}
|
|
32965
|
+
try {
|
|
32966
|
+
if ((await unlessCutOff(to.delete(message), cx.cutOff)).ok) return true;
|
|
32967
|
+
await unlessCutOff(to.update(message, richMessage(typedTakenBackLine(cx.lang()))), cx.cutOff);
|
|
32968
|
+
return true;
|
|
32969
|
+
} catch (error) {
|
|
32970
|
+
cx.logger.warn("a prompt the terminal took back could not be taken away", { error: errorName(error) });
|
|
32971
|
+
}
|
|
32972
|
+
}
|
|
32973
|
+
return false;
|
|
32974
|
+
}
|
|
32975
|
+
async function takeAwayAll(echoes, prompt, to, tries, cx) {
|
|
32976
|
+
const left = [];
|
|
32977
|
+
for (const message of echoes.of(prompt)) if (!await takeAway(to, message, tries, cx)) left.push(message);
|
|
32978
|
+
echoes.settle(prompt, left);
|
|
32979
|
+
}
|
|
32980
|
+
async function drainTakenBack(echoes, to, cx) {
|
|
32981
|
+
for (const [prompt, tries] of echoes.pending()) {
|
|
32982
|
+
if (tries >= RETRACT_DRAINS) {
|
|
32983
|
+
cx.logger.warn("a prompt the terminal took back could not be taken away: given up");
|
|
32984
|
+
echoes.settle(prompt, []);
|
|
32985
|
+
} else {
|
|
32986
|
+
echoes.tried(prompt);
|
|
32987
|
+
await takeAwayAll(echoes, prompt, to, 1, cx);
|
|
32988
|
+
}
|
|
32989
|
+
}
|
|
32990
|
+
}
|
|
32991
|
+
|
|
32852
32992
|
// packages/core/src/remote/follow/speaker.ts
|
|
32853
32993
|
var BurstSpeaker = class {
|
|
32854
32994
|
// the id of the last event while text waits: what a hold of it is known by
|
|
@@ -33067,18 +33207,51 @@ var BurstSpeaker = class {
|
|
|
33067
33207
|
this.deps.logger.warn("the permission card of a remote agent could not be shown", { error: errorName(error) });
|
|
33068
33208
|
}
|
|
33069
33209
|
}
|
|
33070
|
-
/**
|
|
33071
|
-
|
|
33210
|
+
/**
|
|
33211
|
+
* A prompt typed at the terminal the chat shares: one message, so the reply that follows reads as its answer. `id`: what the
|
|
33212
|
+
* terminal's conversation calls the prompt; the message is kept under it so that `retract` can take it away.
|
|
33213
|
+
*/
|
|
33214
|
+
async typed(text9, id = null) {
|
|
33072
33215
|
const to = this.reachable(true);
|
|
33073
33216
|
if (to !== null) {
|
|
33074
|
-
|
|
33075
|
-
|
|
33076
|
-
|
|
33077
|
-
|
|
33078
|
-
);
|
|
33217
|
+
const message = richMessage(typedLine(text9, this.langOr("en")));
|
|
33218
|
+
const failed3 = "a prompt typed at the terminal could not be shown";
|
|
33219
|
+
if (id !== null && to.caps.messageIds && to.caps.delete) await this.tellAs(to, message, id, failed3);
|
|
33220
|
+
else await this.tell(to, message, failed3);
|
|
33079
33221
|
}
|
|
33080
33222
|
this.typedTurn = true;
|
|
33081
33223
|
}
|
|
33224
|
+
/**
|
|
33225
|
+
* The terminal took a prompt back (Claude Code put the text into its box again and the person sent another): the messages that
|
|
33226
|
+
* showed it go, so the chat shows what the terminal shows. Each is deleted; when the chat cannot delete it, it is edited down to a
|
|
33227
|
+
* line saying so; a refusal is tried again a few times at once. A message that stays (every try failed, the chat was out of reach)
|
|
33228
|
+
* is tried again at each of the next events of the session, a few times (`drainRetractions`). Nothing when the prompt was not shown
|
|
33229
|
+
* (the person could not be woken then, or the worker restarted since), and no one is woken by a message going.
|
|
33230
|
+
*/
|
|
33231
|
+
async retract(id) {
|
|
33232
|
+
if (!this.deps.echoes.takeBack(id)) return;
|
|
33233
|
+
const state = this.deps.remoteState.attachedRemote(this.chatKey);
|
|
33234
|
+
const reference = this.deps.references.getReference(this.chatKey);
|
|
33235
|
+
if (state === null || reference === null) return;
|
|
33236
|
+
this.typedTurn = false;
|
|
33237
|
+
await takeAwayAll(this.deps.echoes, id, this.deps.conversationFor(reference), RETRACT_TRIES, this.retractContext());
|
|
33238
|
+
}
|
|
33239
|
+
/** The messages of the prompts that could not be taken away yet are tried again, once each, until a few events went by. */
|
|
33240
|
+
async drainRetractions() {
|
|
33241
|
+
if (this.deps.echoes.pending().size === 0) return;
|
|
33242
|
+
const reference = this.deps.references.getReference(this.chatKey);
|
|
33243
|
+
if (reference === null || this.deps.remoteState.attachedRemote(this.chatKey) === null) return;
|
|
33244
|
+
await drainTakenBack(this.deps.echoes, this.deps.conversationFor(reference), this.retractContext());
|
|
33245
|
+
}
|
|
33246
|
+
retractContext() {
|
|
33247
|
+
return {
|
|
33248
|
+
clock: this.deps.clock,
|
|
33249
|
+
logger: this.deps.logger,
|
|
33250
|
+
...this.deps.timings.retractRetryMs === void 0 ? {} : { retryMs: this.deps.timings.retractRetryMs },
|
|
33251
|
+
lang: () => this.langOr("en"),
|
|
33252
|
+
...this.cutOff === void 0 ? {} : { cutOff: this.cutOff }
|
|
33253
|
+
};
|
|
33254
|
+
}
|
|
33082
33255
|
/** The connector restarted and this session is back: one line, never to wake anyone. */
|
|
33083
33256
|
async recovered(interrupted, continuing) {
|
|
33084
33257
|
const to = this.reachable(false);
|
|
@@ -33127,20 +33300,26 @@ var BurstSpeaker = class {
|
|
|
33127
33300
|
this.deps.logger.warn(failed3, { error: errorName(error) });
|
|
33128
33301
|
}
|
|
33129
33302
|
}
|
|
33130
|
-
|
|
33131
|
-
|
|
33132
|
-
|
|
33133
|
-
|
|
33134
|
-
|
|
33135
|
-
|
|
33136
|
-
|
|
33303
|
+
/** `tell`, keeping the message's id under `prompt` so that it can be taken away later. */
|
|
33304
|
+
async tellAs(to, message, prompt, failed3) {
|
|
33305
|
+
const posting = to.post(message);
|
|
33306
|
+
const remember = (posted) => {
|
|
33307
|
+
if (!posted) return;
|
|
33308
|
+
this.deps.echoes.remember(prompt, posted);
|
|
33309
|
+
if (this.deps.echoes.pending().has(prompt)) {
|
|
33310
|
+
const { clock: clock2, logger, retryMs, lang } = this.retractContext();
|
|
33311
|
+
const unbound = { clock: clock2, logger, lang, ...retryMs === void 0 ? {} : { retryMs } };
|
|
33312
|
+
void takeAwayAll(this.deps.echoes, prompt, to, 1, unbound).catch(() => void 0);
|
|
33313
|
+
}
|
|
33137
33314
|
};
|
|
33138
|
-
|
|
33139
|
-
|
|
33140
|
-
|
|
33141
|
-
|
|
33142
|
-
|
|
33143
|
-
}
|
|
33315
|
+
try {
|
|
33316
|
+
remember(await unlessCutOff(posting, this.cutOff));
|
|
33317
|
+
} catch (error) {
|
|
33318
|
+
posting.then(remember, () => void 0);
|
|
33319
|
+
this.deps.logger.warn(failed3, { error: errorName(error) });
|
|
33320
|
+
}
|
|
33321
|
+
}
|
|
33322
|
+
};
|
|
33144
33323
|
|
|
33145
33324
|
// packages/core/src/remote/follow/follower.ts
|
|
33146
33325
|
var CredentialUnavailable2 = class extends Error {
|
|
@@ -33362,6 +33541,7 @@ var Follower = class {
|
|
|
33362
33541
|
const now = this.deps.clock.monotonicMs();
|
|
33363
33542
|
if (saysModes(step)) this.deps.remoteState.setRemoteModes(this.chatKey, this.sessionId, step);
|
|
33364
33543
|
if (step.closed !== null) {
|
|
33544
|
+
await this.speaker.drainRetractions();
|
|
33365
33545
|
await this.flush({ force: false, holdOnFailure: false });
|
|
33366
33546
|
await this.speaker.ended(step.closed);
|
|
33367
33547
|
return false;
|
|
@@ -33395,12 +33575,14 @@ var Follower = class {
|
|
|
33395
33575
|
this.deps.permissions.closeRemotePermission(this.sessionId, actionId, "decided");
|
|
33396
33576
|
}
|
|
33397
33577
|
}
|
|
33398
|
-
/** What is said between two stretches of the agent's text: a prompt typed at the terminal, the connector coming back. */
|
|
33578
|
+
/** What is said between two stretches of the agent's text: a prompt typed at the terminal (or taken back), the connector coming back. */
|
|
33399
33579
|
async sayBetween(step) {
|
|
33400
33580
|
if (step.typed) {
|
|
33401
33581
|
await this.flush({ force: false, holdOnFailure: false });
|
|
33402
|
-
await this.speaker.typed(step.typed);
|
|
33582
|
+
await this.speaker.typed(step.typed, step.typedId);
|
|
33403
33583
|
}
|
|
33584
|
+
await this.speaker.drainRetractions();
|
|
33585
|
+
if (step.retracted !== null) await this.speaker.retract(step.retracted);
|
|
33404
33586
|
if (step.recovered !== null) {
|
|
33405
33587
|
await this.flush({ force: false, holdOnFailure: false });
|
|
33406
33588
|
await this.speaker.recovered(step.recovered.interrupted, step.recovered.continuing);
|
|
@@ -34267,6 +34449,7 @@ var FollowControl = class {
|
|
|
34267
34449
|
reach: this.ctx.reach,
|
|
34268
34450
|
remoteState: this.ctx.remoteState,
|
|
34269
34451
|
references: this.ctx.references,
|
|
34452
|
+
echoes: chats.echoesOf(chatKey),
|
|
34270
34453
|
permissions: this.ctx.permissions,
|
|
34271
34454
|
conversationFor: (reference) => this.ctx.conversationFor(reference),
|
|
34272
34455
|
showPermission: (key, sid, request, to) => this.hooks.showPermission(key, sid, request, to),
|
|
@@ -34328,6 +34511,9 @@ var FollowControl = class {
|
|
|
34328
34511
|
},
|
|
34329
34512
|
get stopWaitMs() {
|
|
34330
34513
|
return pick2().stopWaitMs ?? STOP_WAIT_MS;
|
|
34514
|
+
},
|
|
34515
|
+
get retractRetryMs() {
|
|
34516
|
+
return pick2().retractRetryMs ?? RETRACT_RETRY_MS;
|
|
34331
34517
|
}
|
|
34332
34518
|
};
|
|
34333
34519
|
}
|
|
@@ -35590,14 +35776,14 @@ var TurnRunner = class {
|
|
|
35590
35776
|
for await (const event of this.ctx.claw.stream(credential2, sid, reading.cursor || void 0, signal)) {
|
|
35591
35777
|
reading.came = true;
|
|
35592
35778
|
if (event.id) reading.cursor = event.id;
|
|
35593
|
-
await this.apply(request, fold.feed(event), display);
|
|
35779
|
+
await this.apply(request, fold.feed(event), display, signal);
|
|
35594
35780
|
reading.handled += 1;
|
|
35595
35781
|
if (event.id && reading.handled % CURSOR_EVERY2 === 0)
|
|
35596
35782
|
this.ctx.remoteState.setRemoteCursor(request.chatKey, sid, event.id);
|
|
35597
35783
|
if (isOver(fold)) break;
|
|
35598
35784
|
}
|
|
35599
35785
|
}
|
|
35600
|
-
async apply(request, step, display) {
|
|
35786
|
+
async apply(request, step, display, signal) {
|
|
35601
35787
|
if (step.replay) return;
|
|
35602
35788
|
const { chatKey, to } = request;
|
|
35603
35789
|
const sid = request.state.sessionId ?? "";
|
|
@@ -35607,7 +35793,7 @@ var TurnRunner = class {
|
|
|
35607
35793
|
}
|
|
35608
35794
|
if (step.queued !== null) await this.showWait(request, step, display);
|
|
35609
35795
|
else display.progress(step);
|
|
35610
|
-
|
|
35796
|
+
await this.terminalNotes(chatKey, sid, to, step, display, signal);
|
|
35611
35797
|
if (saysModes(step)) this.ctx.remoteState.setRemoteModes(chatKey, sid, step);
|
|
35612
35798
|
if (step.permission !== null) {
|
|
35613
35799
|
display.movedOn?.();
|
|
@@ -35618,6 +35804,31 @@ var TurnRunner = class {
|
|
|
35618
35804
|
await this.sayRecovered(chatKey, to, step.recovered.interrupted, step.recovered.continuing, display);
|
|
35619
35805
|
}
|
|
35620
35806
|
}
|
|
35807
|
+
/** What the terminal's own doing says to the chat while this turn reads the session: a prompt it took back, a registry row it cannot read. */
|
|
35808
|
+
async terminalNotes(chatKey, sid, to, step, display, signal) {
|
|
35809
|
+
await this.takeBackAgain(chatKey, to, signal);
|
|
35810
|
+
if (step.retracted !== null) await this.takeBack(chatKey, to, step.retracted, signal);
|
|
35811
|
+
if (step.rowUnreadable) await this.sayRowUnreadable(chatKey, sid, to, display);
|
|
35812
|
+
}
|
|
35813
|
+
/**
|
|
35814
|
+
* The terminal took back a prompt the chat showed (said while this turn reads the session, so the follower does not hear it): the
|
|
35815
|
+
* message that shows it goes now, in one try; what stays is tried again by the follower, at its next events.
|
|
35816
|
+
*/
|
|
35817
|
+
async takeBack(chatKey, to, prompt, signal) {
|
|
35818
|
+
const echoes = this.state.chats.echoesOf(chatKey);
|
|
35819
|
+
if (!echoes.takeBack(prompt)) return;
|
|
35820
|
+
await takeAwayAll(echoes, prompt, to, 1, this.retractContext(chatKey, signal));
|
|
35821
|
+
}
|
|
35822
|
+
/** One more try, at an event of the turn, at the messages of prompts the terminal took back that could not be taken away yet. */
|
|
35823
|
+
async takeBackAgain(chatKey, to, signal) {
|
|
35824
|
+
const echoes = this.state.chats.echoesOf(chatKey);
|
|
35825
|
+
if (echoes.pending().size === 0) return;
|
|
35826
|
+
await drainTakenBack(echoes, to, this.retractContext(chatKey, signal));
|
|
35827
|
+
}
|
|
35828
|
+
/** What taking a message away needs here: the turn being cancelled gives up what waits (the message stays kept for the follower). */
|
|
35829
|
+
retractContext(chatKey, cutOff) {
|
|
35830
|
+
return { clock: this.ctx.clock, logger: this.ctx.logger, lang: () => this.state.lang(chatKey), cutOff };
|
|
35831
|
+
}
|
|
35621
35832
|
/**
|
|
35622
35833
|
* This turn's message waits for the turn the terminal is running: the person is told at once, in the chat, once per message, and
|
|
35623
35834
|
* how to take it back (in the terminal when its own queue holds it; else /stop). A message queued behind a turn of this chat was
|
|
@@ -214,6 +214,8 @@ export declare const remoteText: import("./catalog.js").Catalog<{
|
|
|
214
214
|
typedInTerminal: (p: {
|
|
215
215
|
quoted: string;
|
|
216
216
|
}) => string;
|
|
217
|
+
/** What a message that showed a prompt typed in the terminal is changed to when the terminal took the prompt back and the chat cannot delete it. */
|
|
218
|
+
typedTakenBack: string;
|
|
217
219
|
shareConnect: string;
|
|
218
220
|
shareWatch: string;
|
|
219
221
|
shareNoteTyped: string;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { TypedEchoes } from "./follow/echoes.js";
|
|
1
2
|
import type { Follower } from "./follow/follower.js";
|
|
2
3
|
import type { Task } from "./tasks.js";
|
|
3
4
|
import type { TurnDisplay } from "./turns/display.js";
|
|
@@ -62,6 +63,8 @@ export declare class ChatRegistry {
|
|
|
62
63
|
/** Whether the agent of the attached session can take over a conversation a terminal has open. */
|
|
63
64
|
readonly agentTakeover: Map<string, boolean>;
|
|
64
65
|
private readonly typed;
|
|
66
|
+
/** The messages that show what was typed at the terminal the chat shares, to take one away when the terminal takes its prompt back. */
|
|
67
|
+
private readonly echoes;
|
|
65
68
|
private readonly readOnly;
|
|
66
69
|
private readonly readOnlyKnown;
|
|
67
70
|
private readonly terminalInput;
|
|
@@ -103,6 +106,8 @@ export declare class ChatRegistry {
|
|
|
103
106
|
markTerminal(chatKey: string, sessionId: string, terminal: boolean): void;
|
|
104
107
|
/** True the first time for a chat's session: the chat is to be told its terminal's registry row cannot be read. */
|
|
105
108
|
firstRowHint(chatKey: string, sessionId: string): boolean;
|
|
109
|
+
/** The chat's record of the messages that show prompts typed at its terminal. */
|
|
110
|
+
echoesOf(chatKey: string): TypedEchoes;
|
|
106
111
|
/** What is sent to the chat's session is typed into a terminal on the machine. */
|
|
107
112
|
typesIntoTerminal(chatKey: string, sessionId: string | null): boolean;
|
|
108
113
|
/**
|
|
@@ -67,6 +67,13 @@ export interface RemoteStep {
|
|
|
67
67
|
readonly queuedHeld: boolean;
|
|
68
68
|
/** What the person typed at the terminal of a conversation shared with the chat. */
|
|
69
69
|
readonly typed: string | null;
|
|
70
|
+
/** The id that prompt has in the terminal's conversation (`messageId`), null when the connector does not say. */
|
|
71
|
+
readonly typedId: string | null;
|
|
72
|
+
/**
|
|
73
|
+
* The id of a prompt typed at the terminal that the terminal took back (`user_message_retracted`): Claude Code put it back into the
|
|
74
|
+
* box and the person sent another in its place, so the terminal no longer shows it.
|
|
75
|
+
*/
|
|
76
|
+
readonly retracted: string | null;
|
|
70
77
|
/** What is sent is typed into a terminal on the machine (`input: "terminal"`). */
|
|
71
78
|
readonly terminal: boolean | null;
|
|
72
79
|
/** That terminal's permission mode as its connector read it at the start. */
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The chat messages that show what was typed at the terminal the chat shares, by the id the prompt has in the terminal's
|
|
3
|
+
* conversation. A prompt typed there is shown in the chat as it is typed (one message for each block of text in it); when the
|
|
4
|
+
* terminal takes it back (the person pressed Esc before anything came of it and Claude Code put the text back into the box), the
|
|
5
|
+
* messages are taken away, so the chat shows what the terminal shows. A message that could not be taken away stays here, marked, for
|
|
6
|
+
* the next try. Kept in memory for the few prompts a person has under way: a worker that restarts has forgotten them, and what it
|
|
7
|
+
* showed before stays.
|
|
8
|
+
*/
|
|
9
|
+
import type { MessageId } from "../../ports/surface.js";
|
|
10
|
+
/** How many prompts' messages are kept per chat. */
|
|
11
|
+
export declare const ECHOES_KEPT = 16;
|
|
12
|
+
export declare class TypedEchoes {
|
|
13
|
+
private readonly posted;
|
|
14
|
+
/** Prompts the terminal took back before any message of theirs was recorded (a post that landed late may still be). */
|
|
15
|
+
private readonly early;
|
|
16
|
+
/** `message` shows `prompt` (or one more block of it). */
|
|
17
|
+
remember(prompt: string, message: MessageId): void;
|
|
18
|
+
/** The messages that show `prompt`, oldest first; none when it was not shown (or was let go). */
|
|
19
|
+
of(prompt: string): readonly MessageId[];
|
|
20
|
+
/**
|
|
21
|
+
* The terminal took `prompt` back: false when it was not shown (nothing to take away now). One whose post is still in flight (it
|
|
22
|
+
* lands after the reader was cancelled) is remembered as taken back, so that its message goes as soon as it is recorded.
|
|
23
|
+
*/
|
|
24
|
+
takeBack(prompt: string): boolean;
|
|
25
|
+
/** The prompts the terminal took back whose messages are still to be taken away, with the tries each has had since the first. */
|
|
26
|
+
pending(): ReadonlyMap<string, number>;
|
|
27
|
+
/** Another try at `prompt` is made: counted. */
|
|
28
|
+
tried(prompt: string): void;
|
|
29
|
+
/** `left` are the messages of `prompt` still to be taken away (a taking away that failed): none forgets the prompt. */
|
|
30
|
+
settle(prompt: string, left: readonly MessageId[]): void;
|
|
31
|
+
}
|
|
@@ -77,7 +77,7 @@ export declare class Follower {
|
|
|
77
77
|
/** Fold one event in. False when the reader has nothing more to do. */
|
|
78
78
|
private handle;
|
|
79
79
|
private askOrResolve;
|
|
80
|
-
/** What is said between two stretches of the agent's text: a prompt typed at the terminal, the connector coming back. */
|
|
80
|
+
/** What is said between two stretches of the agent's text: a prompt typed at the terminal (or taken back), the connector coming back. */
|
|
81
81
|
private sayBetween;
|
|
82
82
|
private advance;
|
|
83
83
|
private flush;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Lang } from "../../locales/lang.js";
|
|
2
|
+
import type { Clock } from "../../ports/clock.js";
|
|
3
|
+
import type { Logger } from "../../ports/logger.js";
|
|
4
|
+
import { type Conversation } from "../../ports/surface.js";
|
|
5
|
+
import type { TypedEchoes } from "./echoes.js";
|
|
6
|
+
/** How many times the messages of a prompt the terminal took back are tried at once, and how many later events try them once more. */
|
|
7
|
+
export declare const RETRACT_TRIES = 3;
|
|
8
|
+
export declare const RETRACT_DRAINS = 5;
|
|
9
|
+
/** What taking a message away needs. */
|
|
10
|
+
export interface RetractContext {
|
|
11
|
+
readonly clock: Clock;
|
|
12
|
+
readonly logger: Logger;
|
|
13
|
+
/** The wait before the second try (doubled for the third); `RETRACT_RETRY_MS` when not given. */
|
|
14
|
+
readonly retryMs?: number;
|
|
15
|
+
readonly lang: () => Lang;
|
|
16
|
+
/** Aborted when the reader is cancelled: what waits is given up (the message stays kept for whoever reads on). */
|
|
17
|
+
readonly cutOff?: AbortSignal;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* `work`, or a rejection as soon as `signal` aborts (the work itself is left to settle on its own). Every wait of a reader's on the
|
|
21
|
+
* chat goes through it: a cancelled reader is never held by one that does not come back (Python's task cancel ends any await).
|
|
22
|
+
*/
|
|
23
|
+
export declare function unlessCutOff<T>(work: Promise<T>, signal: AbortSignal | undefined): Promise<T>;
|
|
24
|
+
/** Take away what shows the prompt `prompt`, each message in up to `tries` tries; what stays is kept for the next try. */
|
|
25
|
+
export declare function takeAwayAll(echoes: TypedEchoes, prompt: string, to: Conversation, tries: number, cx: RetractContext): Promise<void>;
|
|
26
|
+
/** One more try at every prompt the terminal took back whose messages stay; a prompt that has had `RETRACT_DRAINS` of them is let go. */
|
|
27
|
+
export declare function drainTakenBack(echoes: TypedEchoes, to: Conversation, cx: RetractContext): Promise<void>;
|
|
@@ -8,6 +8,7 @@ import type { RemoteStateRepository } from "../../ports/store/remote.js";
|
|
|
8
8
|
import { type Conversation } from "../../ports/surface.js";
|
|
9
9
|
import { type RemoteStep } from "../events.js";
|
|
10
10
|
import { type RemoteTurnState } from "../turn-state.js";
|
|
11
|
+
import type { TypedEchoes } from "./echoes.js";
|
|
11
12
|
import { type FollowTimings } from "./timings.js";
|
|
12
13
|
/** Whether a person may be woken now, and where what they may not be told yet is held (`proactive`). */
|
|
13
14
|
export interface FollowReach {
|
|
@@ -28,6 +29,8 @@ export interface SpeakerDeps {
|
|
|
28
29
|
readonly reach: FollowReach;
|
|
29
30
|
readonly remoteState: RemoteStateRepository;
|
|
30
31
|
readonly references: ConversationRefRepository;
|
|
32
|
+
/** The messages that show what was typed at the terminal (to take one away when the terminal takes its prompt back). */
|
|
33
|
+
readonly echoes: TypedEchoes;
|
|
31
34
|
/** The conversation a stored reference posts to. */
|
|
32
35
|
conversationFor(reference: JsonObject): Conversation;
|
|
33
36
|
showPermission(chatKey: string, sessionId: string, request: Readonly<Record<string, unknown>>, to: Conversation): Promise<void>;
|
|
@@ -109,8 +112,22 @@ export declare class BurstSpeaker {
|
|
|
109
112
|
settleWindow(): Promise<void>;
|
|
110
113
|
/** A permission request gets its card at once, and none while the person may not be woken. */
|
|
111
114
|
ask(request: Readonly<Record<string, unknown>>): Promise<void>;
|
|
112
|
-
/**
|
|
113
|
-
|
|
115
|
+
/**
|
|
116
|
+
* A prompt typed at the terminal the chat shares: one message, so the reply that follows reads as its answer. `id`: what the
|
|
117
|
+
* terminal's conversation calls the prompt; the message is kept under it so that `retract` can take it away.
|
|
118
|
+
*/
|
|
119
|
+
typed(text: string, id?: string | null): Promise<void>;
|
|
120
|
+
/**
|
|
121
|
+
* The terminal took a prompt back (Claude Code put the text into its box again and the person sent another): the messages that
|
|
122
|
+
* showed it go, so the chat shows what the terminal shows. Each is deleted; when the chat cannot delete it, it is edited down to a
|
|
123
|
+
* line saying so; a refusal is tried again a few times at once. A message that stays (every try failed, the chat was out of reach)
|
|
124
|
+
* is tried again at each of the next events of the session, a few times (`drainRetractions`). Nothing when the prompt was not shown
|
|
125
|
+
* (the person could not be woken then, or the worker restarted since), and no one is woken by a message going.
|
|
126
|
+
*/
|
|
127
|
+
retract(id: string): Promise<void>;
|
|
128
|
+
/** The messages of the prompts that could not be taken away yet are tried again, once each, until a few events went by. */
|
|
129
|
+
drainRetractions(): Promise<void>;
|
|
130
|
+
private retractContext;
|
|
114
131
|
/** The connector restarted and this session is back: one line, never to wake anyone. */
|
|
115
132
|
recovered(interrupted: boolean, continuing: boolean): Promise<void>;
|
|
116
133
|
/**
|
|
@@ -121,4 +138,6 @@ export declare class BurstSpeaker {
|
|
|
121
138
|
/** The chat to tell now, or null: nobody to tell, or (`unlessPaused`: also a pause) the person may not be woken. */
|
|
122
139
|
private reachable;
|
|
123
140
|
private tell;
|
|
141
|
+
/** `tell`, keeping the message's id under `prompt` so that it can be taken away later. */
|
|
142
|
+
private tellAs;
|
|
124
143
|
}
|
|
@@ -14,6 +14,8 @@ export interface FollowTimings {
|
|
|
14
14
|
readonly retryMs?: number;
|
|
15
15
|
/** How long a stop waits for the reader to deliver what it read (`STOP_WAIT_MS` when not given). */
|
|
16
16
|
readonly stopWaitMs?: number;
|
|
17
|
+
/** The wait before the second try of taking away the message of a prompt the terminal took back, doubled for the third (`RETRACT_RETRY_MS` when not given). */
|
|
18
|
+
readonly retractRetryMs?: number;
|
|
17
19
|
}
|
|
18
20
|
export declare const DEFAULT_TIMINGS: FollowTimings;
|
|
19
21
|
/** How a watched conversation (open in a terminal, read-only) is followed: told after a few quiet seconds, not half a minute. */
|
|
@@ -21,6 +23,8 @@ export declare const WATCH_TIMINGS: FollowTimings;
|
|
|
21
23
|
export declare const RECONNECT_MAX_MS = 60000;
|
|
22
24
|
/** A message that could not be sent is tried again after this long. */
|
|
23
25
|
export declare const RETRY_MS = 15000;
|
|
26
|
+
/** A message of a prompt the terminal took back that could not be taken away is tried again after this long. */
|
|
27
|
+
export declare const RETRACT_RETRY_MS = 2000;
|
|
24
28
|
/** `stop` waits this long for the reader to finish what it was doing. */
|
|
25
29
|
export declare const STOP_WAIT_MS = 15000;
|
|
26
30
|
/** Events between two writes of the read position (a write also follows every delivery). */
|
|
@@ -35,6 +35,9 @@ export declare const TYPED_CHARS_MAX = 4000;
|
|
|
35
35
|
* link, an image or a tag, nor an address the rich text links by itself (whoever types at that terminal reaches the chat through the
|
|
36
36
|
* connector: what they typed is shown, never followed). */
|
|
37
37
|
export declare function typedLine(text: string, lang: Lang): string;
|
|
38
|
+
/** What a message that showed a prompt typed at the terminal is edited down to when the terminal took the prompt back and the chat
|
|
39
|
+
* cannot delete the message. */
|
|
40
|
+
export declare function typedTakenBackLine(lang: Lang): string;
|
|
38
41
|
/**
|
|
39
42
|
* Teams' floating status (an informative update) is cut on a phone after a few characters. Microsoft documents only an upper
|
|
40
43
|
* bound (1000 characters) and no display width; the one measurement is a phone, which showed four Chinese
|
|
@@ -69,6 +69,17 @@ export declare class TurnRunner {
|
|
|
69
69
|
/** One stream, read until it ends or the turn does. */
|
|
70
70
|
private readStream;
|
|
71
71
|
private apply;
|
|
72
|
+
/** What the terminal's own doing says to the chat while this turn reads the session: a prompt it took back, a registry row it cannot read. */
|
|
73
|
+
private terminalNotes;
|
|
74
|
+
/**
|
|
75
|
+
* The terminal took back a prompt the chat showed (said while this turn reads the session, so the follower does not hear it): the
|
|
76
|
+
* message that shows it goes now, in one try; what stays is tried again by the follower, at its next events.
|
|
77
|
+
*/
|
|
78
|
+
private takeBack;
|
|
79
|
+
/** One more try, at an event of the turn, at the messages of prompts the terminal took back that could not be taken away yet. */
|
|
80
|
+
private takeBackAgain;
|
|
81
|
+
/** What taking a message away needs here: the turn being cancelled gives up what waits (the message stays kept for the follower). */
|
|
82
|
+
private retractContext;
|
|
72
83
|
/**
|
|
73
84
|
* This turn's message waits for the turn the terminal is running: the person is told at once, in the chat, once per message, and
|
|
74
85
|
* how to take it back (in the terminal when its own queue holds it; else /stop). A message queued behind a turn of this chat was
|