@primusclaw/personal-agent 0.13.0 → 0.15.0

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 CHANGED
@@ -770,6 +770,39 @@ function isCommand(name) {
770
770
  return within(COMMANDS, name);
771
771
  }
772
772
 
773
+ // packages/core/src/commands/agent-args.ts
774
+ var AGENT_SUBCOMMANDS = ["new", "attach", "detach", "mode", "sessions", "close", "off", "pair"];
775
+ function isSubcommand(word2) {
776
+ return AGENT_SUBCOMMANDS.includes(word2);
777
+ }
778
+ function parseAgentCommand(arg) {
779
+ const [head, rest] = splitOnce(pyStrip(arg));
780
+ const verb = head === void 0 ? void 0 : pyLower(head);
781
+ if (verb === void 0 || !isSubcommand(verb)) return null;
782
+ return { verb, rest: rest === void 0 ? "" : pyStrip(rest) };
783
+ }
784
+ var AGENTS_WORDS = ["agents", "agent"];
785
+ function oneEditApart(a, b3) {
786
+ if (a === b3 || Math.abs(a.length - b3.length) > 1) return a === b3;
787
+ let i = 0;
788
+ while (i < a.length && i < b3.length && a[i] === b3[i]) i += 1;
789
+ if (a.length === b3.length) {
790
+ if (a.slice(i + 1) === b3.slice(i + 1)) return true;
791
+ return a[i] === b3[i + 1] && a[i + 1] === b3[i] && a.slice(i + 2) === b3.slice(i + 2);
792
+ }
793
+ const [longer, shorter] = a.length > b3.length ? [a, b3] : [b3, a];
794
+ return longer.slice(i + 1) === shorter.slice(i);
795
+ }
796
+ function isAgentsSlip(text9) {
797
+ const said2 = pyStrip(text9);
798
+ if (/\s/u.test(said2)) return false;
799
+ const found = new RegExp("^[/\uFF0F](\\p{L}{4,8})[.?!\u3002\uFF1F\uFF01]*$", "u").exec(said2);
800
+ const word2 = found?.[1] === void 0 ? "" : pyLower(found[1]);
801
+ if (!word2) return false;
802
+ if (said2 === `/${word2}` && isKnownCommand(word2)) return false;
803
+ return AGENTS_WORDS.some((w) => oneEditApart(word2, w));
804
+ }
805
+
773
806
  // packages/core/src/commands/parse.ts
774
807
  function parseCommand(text9) {
775
808
  const word2 = pyLower(pyStrip(text9));
@@ -802,6 +835,7 @@ function looksLikeACode(word2) {
802
835
  return isUpper(word2) || new RegExp("\\p{Nd}", "u").test(word2);
803
836
  }
804
837
  function menuCommand(text9, group = false) {
838
+ if (!group && isAgentsSlip(text9)) return "/agents";
805
839
  const said2 = squashSpaces(text9);
806
840
  const lower = pyLower(said2);
807
841
  const command = Object.hasOwn(MENU_COMMANDS, lower) ? MENU_COMMANDS[lower] : void 0;
@@ -5587,6 +5621,30 @@ function parseApprovalsSetting(body) {
5587
5621
  if (!isObject(body) || typeof body.enabled !== "boolean") return fail("enabled_required");
5588
5622
  return { ok: true, value: { enabled: body.enabled } };
5589
5623
  }
5624
+ var ASK_TAIL = 300;
5625
+ var ASK_WORDS = [
5626
+ /(?:要不要|是否需要|是否要|是否继续|可以吗|行吗|好吗|同意吗|你看呢|选哪个|选哪一个|哪个方案)/u,
5627
+ /(?:请|麻烦)(?:你|您)?(?:确认|决定|拍板|选择|批准|审批|回复|告诉我)/u,
5628
+ /(?:等你|等您|需要你|需要您)(?:的)?(?:确认|决定|拍板|选择|批准|回复|答复|同意|授权)/u,
5629
+ /(?:你来|您来)(?:定|决定|选)/u,
5630
+ /\b(?:should I|shall I|do you want(?: me)? to|would you like(?: me)? to|want me to|let me know (?:if|whether|which|how)|please (?:confirm|approve|decide|choose|advise)|(?:waiting|wait) (?:for|on) your|need your (?:input|decision|approval|confirmation|go-ahead)|your call|which (?:option|one) (?:do you|would you|should))\b/iu
5631
+ ];
5632
+ function turnAsksPerson(message) {
5633
+ const text9 = message.replace(/\r\n?/gu, "\n").trim();
5634
+ if (!text9) return false;
5635
+ const blocks2 = text9.split(/\n\s*\n/u).map((b3) => b3.trim()).filter(Boolean);
5636
+ const last = (blocks2[blocks2.length - 1] ?? "").replace(/[`*_~>#]+/gu, "").trim();
5637
+ const tail = Array.from(last).slice(-ASK_TAIL).join("");
5638
+ if (/[??][\s))」』"'”’\]】]*[\p{Extended_Pictographic}\s]*$/u.test(tail)) return true;
5639
+ return ASK_WORDS.some((re2) => re2.test(tail));
5640
+ }
5641
+ var TERMINAL_SUMMARY = { defaultMinutes: 60, minMinutes: 15, maxMinutes: 24 * 60 };
5642
+ function parseTerminalSummarySetting(body) {
5643
+ if (!isObject(body) || typeof body.minutes !== "number" || !Number.isSafeInteger(body.minutes)) return fail("minutes_required");
5644
+ const m = body.minutes;
5645
+ if (m !== 0 && (m < TERMINAL_SUMMARY.minMinutes || m > TERMINAL_SUMMARY.maxMinutes)) return fail("minutes_out_of_range");
5646
+ return { ok: true, value: { minutes: m } };
5647
+ }
5590
5648
  function parseTerminalMute(body) {
5591
5649
  if (!isObject(body) || typeof body.muted !== "boolean") return fail("muted_required");
5592
5650
  if (typeof body.item !== "number" || !Number.isSafeInteger(body.item) || body.item < 1) return fail("item_required");
@@ -6214,6 +6272,8 @@ var turnText = defineCatalog({
6214
6272
  stillWorking: "Still working on it; the result will follow as a new message.",
6215
6273
  /** A turn whose stream is closed because a card now waits for the person's choice. */
6216
6274
  awaitingChoice: "Waiting for your choice in the card; I will continue once you pick.",
6275
+ /** A turn whose stream is closed because the chat went on below it: the whole answer comes below. */
6276
+ answerBelow: "The answer follows below, as new messages.",
6217
6277
  interrupted: "Interrupted.",
6218
6278
  /** What a turn the person stopped ends with. */
6219
6279
  stopped: "Stopped.",
@@ -6236,6 +6296,7 @@ var turnText = defineCatalog({
6236
6296
  thinking: "\u601D\u8003\u4E2D\u2026",
6237
6297
  stillWorking: "\u4ECD\u5728\u5904\u7406\uFF0C\u5B8C\u6210\u540E\u53E6\u53D1\u7ED3\u679C\u3002",
6238
6298
  awaitingChoice: "\u8BF7\u5728\u5361\u7247\u91CC\u9009\u62E9\uFF0C\u9009\u597D\u540E\u6211\u63A5\u7740\u505A\u3002",
6299
+ answerBelow: "\u56DE\u7B54\u4F1A\u5728\u4E0B\u9762\u53E6\u53D1\u3002",
6239
6300
  interrupted: "\u5DF2\u4E2D\u65AD\u3002",
6240
6301
  stopped: "\u5DF2\u505C\u6B62\u3002",
6241
6302
  doneShort: "\u5B8C\u6210\u3002",
@@ -7459,6 +7520,10 @@ var StatusMessage = class {
7459
7520
  hard = false;
7460
7521
  /** The answer is on its way (`finish`): the progress message is the answer's to retire. */
7461
7522
  finishing = false;
7523
+ /** The chat went on below the stream (`movedOn`): the line its bubble ends with; the answer comes whole below. */
7524
+ wentOn = "";
7525
+ /** Closing the stream because the chat went on below it, once its words show there (`movedOn`). */
7526
+ moving;
7462
7527
  constructor(surface, options) {
7463
7528
  this.surface = surface;
7464
7529
  this.clock = options.clock;
@@ -7531,16 +7596,24 @@ ${header}` : header;
7531
7596
  if (this.closed || !live.closable || this.streamOver || this.expiring) return;
7532
7597
  this.expiring = true;
7533
7598
  if (this.stream && this.flusher && !this.flusher.done) await unlessAborted(this.flusher.settled(), signal);
7599
+ await this.endStream(live, line3, why);
7600
+ this.log.info("the turn's stream was closed; the answer follows as a message of its own", {
7601
+ why,
7602
+ age: Math.round(live.age())
7603
+ });
7604
+ }
7605
+ /**
7606
+ * End the stream with `line` after the agent's words in its bubble: the answer, whenever it comes, is a message of its own. The
7607
+ * words not yet streamed go into the bubble too, unless the chat went on below it (`movedOn`): the answer then comes whole below,
7608
+ * and the bubble keeps only what it already shows (the chat will not let that shrink).
7609
+ */
7610
+ async endStream(live, line3, why) {
7534
7611
  this.streamOver = true;
7535
- const words3 = this.streamable() || live.streamed;
7612
+ const words3 = this.wentOn ? live.streamed : this.streamable() || live.streamed;
7536
7613
  const closed = await live.final(plainMessage(words3 ? `${words3}
7537
7614
 
7538
7615
  ${line3}` : line3));
7539
7616
  if (!closed.ok) this.log.warn(`the turn's stream could not be closed ${why}; the answer follows as a message`);
7540
- this.log.info("the turn's stream was closed; the answer follows as a message of its own", {
7541
- why,
7542
- age: Math.round(live.age())
7543
- });
7544
7617
  }
7545
7618
  /**
7546
7619
  * A card now waits for the person (a question of the agent): it is their turn, so the floating status must not go on
@@ -7576,6 +7649,28 @@ ${line3}` : line3));
7576
7649
  });
7577
7650
  return true;
7578
7651
  }
7652
+ /**
7653
+ * The chat went on below the stream while the turn runs (the person wrote again, or something else was said there): the stream's
7654
+ * bubble stays where it opened, above all that. An answer begun in it and continued below would be read from its middle, its first
7655
+ * part out of sight (2026-11-24: "(cont. 2/2)" under a queued message's notice, part 1 above both). So nothing of the agent's goes
7656
+ * into the bubble from now on: while it shows only a status, that floats on until the turn ends; one that shows words already is
7657
+ * closed at once. Either way it ends with `line`, and the whole answer comes as messages of its own, below what was said since.
7658
+ * When it comes while the answer is going out (its first part in the bubble already), the whole answer is sent again below.
7659
+ * Nothing when no stream is open or one is already closing. Never fails the turn.
7660
+ */
7661
+ movedOn(line3) {
7662
+ const live = this.live;
7663
+ if (!live || this.streamOver || this.expiring || this.wentOn) return;
7664
+ this.wentOn = line3;
7665
+ if (this.closed) return;
7666
+ this.moving = detach(async (signal) => {
7667
+ if (this.opening && !this.opening.done) await unlessAborted(this.opening.settled(), signal);
7668
+ if (this.flusher && !this.flusher.done) await unlessAborted(this.flusher.settled(), signal);
7669
+ if (!live.streamed) return;
7670
+ if (!this.expiring) this.expiry?.cancel();
7671
+ await this.closeEarly(live, line3, "because the chat went on below it", signal);
7672
+ });
7673
+ }
7579
7674
  /** The chat's id of the posted message; undefined when the post failed or its id never came (nothing is edited then). */
7580
7675
  async messageId(signal) {
7581
7676
  if (!this.posted) return void 0;
@@ -7639,6 +7734,10 @@ ${line3}` : line3));
7639
7734
  streamable() {
7640
7735
  return this.stream ? this.policy.streamable(this.stream.streamed) : "";
7641
7736
  }
7737
+ /** The agent's words for the bubble now: none once the chat went on below it (its status only; the words come below). */
7738
+ bubbleWords() {
7739
+ return this.wentOn ? "" : this.streamable();
7740
+ }
7642
7741
  /** Whether the turn is still shown by its stream (a refusal hands it to the progress message). */
7643
7742
  streaming() {
7644
7743
  return this.stream !== void 0;
@@ -7680,7 +7779,8 @@ ${line3}` : line3));
7680
7779
  await sleepSeconds(this.clock, wait, signal);
7681
7780
  continue;
7682
7781
  }
7683
- const streamed = this.streamable();
7782
+ if (this.wentOn && stream.streamed) return;
7783
+ const streamed = this.bubbleWords();
7684
7784
  const text9 = streamed || statusText(this.statusLines());
7685
7785
  if (text9 === this.lastText || streamed && streamed === stream.streamed) return;
7686
7786
  this.lastText = text9;
@@ -7726,7 +7826,7 @@ ${line3}` : line3));
7726
7826
  cancelled() {
7727
7827
  const first = !this.hard;
7728
7828
  this.hard = true;
7729
- for (const task of [this.again, this.expiry, this.choice]) task?.cancel();
7829
+ for (const task of [this.again, this.expiry, this.choice, this.moving]) task?.cancel();
7730
7830
  if (this.live?.closable && !this.streamOver) {
7731
7831
  this.streamOver = true;
7732
7832
  const live = this.live;
@@ -7757,40 +7857,56 @@ ${line3}` : line3));
7757
7857
  await this.quiesce();
7758
7858
  const messages = answerMessages(parts2, options);
7759
7859
  if (this.stream && this.stream.open && !this.streamOver) {
7760
- await this.finishStream(this.stream, messages, parts2, options);
7860
+ if (!this.wentOn) {
7861
+ await this.finishStream(this.stream, messages, parts2, options);
7862
+ return;
7863
+ }
7864
+ await this.endStream(this.stream, this.wentOn, "because the chat went on below it");
7865
+ for (const message of messages) await this.surface.send(message);
7761
7866
  return;
7762
7867
  }
7763
7868
  const messageId = await this.messageId();
7764
- let rest = messages;
7765
- if (this.live && this.live.closable && !this.streamOver) rest = await this.closeRefusedStream(this.live, messages);
7766
- for (const message of rest) await this.surface.send(message);
7869
+ if (this.live && this.live.closable && !this.streamOver) await this.closeRefusedStream(this.live, messages);
7870
+ else for (const message of messages) await this.surface.send(message);
7767
7871
  if (messageId) await this.retire(messageId);
7768
7872
  }
7769
7873
  /** Stop the live view and wait for what is still on its way: the stream's opening, the last edit, a closing stream. */
7770
7874
  async quiesce() {
7771
7875
  this.close();
7772
7876
  if (this.expiry && !this.expiry.done && !this.expiring) this.expiry.cancel();
7773
- for (const task of [this.opening, this.flusher, this.expiring ? this.expiry : void 0, this.choice]) {
7877
+ for (const task of [
7878
+ this.opening,
7879
+ this.flusher,
7880
+ this.expiring ? this.expiry : void 0,
7881
+ this.choice,
7882
+ this.moving
7883
+ ]) {
7774
7884
  if (task) await task.settled();
7775
7885
  }
7776
7886
  }
7777
7887
  /**
7778
7888
  * The stream opened and the chat later refused an update of it, so the progress message took over: the stream is still
7779
- * closed, with the first part of the answer when the chat takes that. Returns what is left to send as messages.
7889
+ * closed, with the first part of the answer when the chat takes that, and what is left of the answer is sent as messages.
7780
7890
  */
7781
7891
  async closeRefusedStream(live, messages) {
7782
7892
  let final;
7783
7893
  let rest;
7784
7894
  const [first, ...others] = messages;
7785
- if (live.streamed) [final, rest] = [plainMessage(live.streamed), messages];
7895
+ if (this.wentOn)
7896
+ [final, rest] = [plainMessage(live.streamed ? `${live.streamed}
7897
+
7898
+ ${this.wentOn}` : this.wentOn), messages];
7899
+ else if (live.streamed) [final, rest] = [plainMessage(live.streamed), messages];
7786
7900
  else if (first) [final, rest] = [first, others];
7787
7901
  else [final, rest] = [plainMessage(turnText.in(this.lang).doneShort), []];
7788
7902
  const closed = await live.final(final);
7789
- if (closed.ok) return rest;
7790
- this.log.warn("the refused stream could not be closed either; the chat closes it at its limit", {
7791
- reason: closed.error.reason
7792
- });
7793
- return messages;
7903
+ if (!closed.ok) {
7904
+ this.log.warn("the refused stream could not be closed either; the chat closes it at its limit", {
7905
+ reason: closed.error.reason
7906
+ });
7907
+ rest = messages;
7908
+ }
7909
+ await this.sendAfterBubble(closed.ok && final === first, rest, messages);
7794
7910
  }
7795
7911
  /**
7796
7912
  * The stream's final message is the first part of the answer (the chat then draws its AI label and thumbs); the other
@@ -7810,7 +7926,20 @@ ${line3}` : line3));
7810
7926
  });
7811
7927
  rest = messages;
7812
7928
  }
7813
- for (const message of rest) await this.surface.send(message);
7929
+ await this.sendAfterBubble(closed.ok, rest, messages);
7930
+ }
7931
+ /**
7932
+ * Send `rest`, what follows the stream's final. When that final showed part of the answer above (`shown`) and the chat goes on
7933
+ * below the bubble while the rest goes out (`movedOn`: the person wrote meanwhile), the whole answer is sent again below that, so
7934
+ * it is never read from its middle. A final that is the whole answer (nothing follows it) stays as it is.
7935
+ */
7936
+ async sendAfterBubble(shown3, rest, messages) {
7937
+ const wentOn = () => shown3 && rest.length > 0 && this.wentOn !== "";
7938
+ for (const message of rest) {
7939
+ if (wentOn()) break;
7940
+ await this.surface.send(message);
7941
+ }
7942
+ if (wentOn()) for (const message of messages) await this.surface.send(message);
7814
7943
  }
7815
7944
  /** Wait until FINAL_SETTLE_SECONDS have passed since the last progress edit left. */
7816
7945
  async settle() {
@@ -10123,7 +10252,7 @@ function groupChosenLang(store, conversationId) {
10123
10252
  const lang = conversationId ? store.groupLanguage?.groupLanguage(conversationId) : null;
10124
10253
  return lang === "zh" || lang === "en" ? lang : void 0;
10125
10254
  }
10126
- var Chat = class {
10255
+ var Chat = class _Chat {
10127
10256
  constructor(store, sender, conversation, scope, locale, written3 = "") {
10128
10257
  this.store = store;
10129
10258
  this.sender = sender;
@@ -10154,7 +10283,50 @@ var Chat = class {
10154
10283
  send(message) {
10155
10284
  return this.conversation.send(message);
10156
10285
  }
10286
+ /** The same chat, said into through `conversation`. */
10287
+ through(conversation) {
10288
+ return new _Chat(this.store, this.sender, conversation, this.scope, this.locale, this.written);
10289
+ }
10157
10290
  };
10291
+ function postingAfter(conversation, first) {
10292
+ return {
10293
+ get ref() {
10294
+ return conversation.ref;
10295
+ },
10296
+ get caps() {
10297
+ return conversation.caps;
10298
+ },
10299
+ get replyTo() {
10300
+ return conversation.replyTo;
10301
+ },
10302
+ get edited() {
10303
+ return conversation.edited;
10304
+ },
10305
+ markSettled: (id) => {
10306
+ conversation.markSettled(id);
10307
+ },
10308
+ typing: () => conversation.typing(),
10309
+ send: (message) => {
10310
+ first();
10311
+ return conversation.send(message);
10312
+ },
10313
+ post: (message) => {
10314
+ first();
10315
+ return conversation.post(message);
10316
+ },
10317
+ update: (id, message, options) => conversation.update(id, message, options),
10318
+ delete: (id) => conversation.delete(id),
10319
+ outgoing: (message) => conversation.outgoing(message),
10320
+ deliver: (envelope) => {
10321
+ first();
10322
+ return conversation.deliver(envelope);
10323
+ },
10324
+ openStream: (replyTo, status) => {
10325
+ first();
10326
+ return conversation.openStream(replyTo, status);
10327
+ }
10328
+ };
10329
+ }
10158
10330
  async function settleClick(click, logger, card, options = {}) {
10159
10331
  const fallback = typeof card === "string" ? options.fallback ?? card : options.fallback;
10160
10332
  const message = typeof card === "string" ? click.note(card) : card;
@@ -12227,18 +12399,6 @@ function naturalCommand(text9, group = false, off = /* @__PURE__ */ new Set(), b
12227
12399
  return off.has(first) || off.has(parts2.slice(0, 2).join(" ")) ? text9 : command;
12228
12400
  }
12229
12401
 
12230
- // packages/core/src/commands/agent-args.ts
12231
- var AGENT_SUBCOMMANDS = ["new", "attach", "detach", "mode", "sessions", "close", "off", "pair"];
12232
- function isSubcommand(word2) {
12233
- return AGENT_SUBCOMMANDS.includes(word2);
12234
- }
12235
- function parseAgentCommand(arg) {
12236
- const [head, rest] = splitOnce(pyStrip(arg));
12237
- const verb = head === void 0 ? void 0 : pyLower(head);
12238
- if (verb === void 0 || !isSubcommand(verb)) return null;
12239
- return { verb, rest: rest === void 0 ? "" : pyStrip(rest) };
12240
- }
12241
-
12242
12402
  // packages/core/src/commands/repo.ts
12243
12403
  var REPO_HOST = "https://github.com";
12244
12404
  var OWNER = /^[A-Za-z0-9](?:[A-Za-z0-9]|-(?=[A-Za-z0-9])){0,38}$/u;
@@ -15585,11 +15745,11 @@ var Router = class _Router {
15585
15745
  }
15586
15746
  async route(event) {
15587
15747
  const scope = event.conversation.kind === "group" ? event.conversation.id : "";
15588
- const chat = this.ctx.chatOf(event, scope);
15589
15748
  if (event.type === "vote") {
15590
- await this.vote(event, chat);
15749
+ await this.vote(event, this.ctx.chatOf(event, scope));
15591
15750
  return;
15592
15751
  }
15752
+ const chat = this.goingOn(event, this.ctx.chatOf(event, scope));
15593
15753
  try {
15594
15754
  await this.dispatch(event, chat);
15595
15755
  } catch (error) {
@@ -15598,6 +15758,20 @@ var Router = class _Router {
15598
15758
  }
15599
15759
  await this.settleOpen(event, chat, routingText.in(chat.lang()).buttonInactive);
15600
15760
  }
15761
+ /**
15762
+ * What happens in the chat now happens below the stream of an attached agent's turn running there, whatever it is (a message
15763
+ * of the person's, a command answered at once, a click whose outcome is said): that turn's answer must come below it, whole,
15764
+ * never begun above it and continued below (`movedOn`). A message is in the chat already; a click, once it posts something.
15765
+ */
15766
+ goingOn(event, chat) {
15767
+ const goesOn = this.ctx.deps.remote.goesOn?.(chat.sender.id, chat.scope);
15768
+ if (goesOn === void 0) return chat;
15769
+ if (event.type === "message") {
15770
+ goesOn();
15771
+ return chat;
15772
+ }
15773
+ return chat.through(postingAfter(chat.conversation, goesOn));
15774
+ }
15601
15775
  /** The safety net under every card click: a click whose card is still the placeholder ends with a note. */
15602
15776
  async settleOpen(event, chat, text9) {
15603
15777
  if (event.type !== "action" || !event.invoke || !event.cardMessageId) return;
@@ -18657,6 +18831,45 @@ function choiceOf(event) {
18657
18831
  if (options.length < CHOICE_OPTIONS_MIN || options.length > CHOICE_OPTIONS_MAX) return void 0;
18658
18832
  return { options, multiple: choice["multiple"] === true };
18659
18833
  }
18834
+ var END_NAME_MAX = 120;
18835
+ var END_ERROR_MAX = 60;
18836
+ var END_SUMMARY_MAX = 400;
18837
+ var END_FULL_MAX = 2e3;
18838
+ var END_ATTACH = /^\/agent attach [A-Za-z0-9._:-]{6,128}$/u;
18839
+ var clipText = (value, max) => typeof value === "string" ? Array.from(value).slice(0, max).join("") : "";
18840
+ var END_EARLIER_MAX = 400;
18841
+ function terminalEarlierOf(value) {
18842
+ if (!Array.isArray(value)) return [];
18843
+ const out = [];
18844
+ for (const entry of value.slice(0, 2)) {
18845
+ const e = record2(entry);
18846
+ const kind = e?.["kind"];
18847
+ const count6 = e?.["count"];
18848
+ if (e === void 0 || kind !== "asked" && kind !== "failed" || out.some((o) => o.kind === kind)) continue;
18849
+ if (typeof count6 !== "number" || !Number.isSafeInteger(count6) || count6 <= 0) continue;
18850
+ out.push({ kind, text: clipText(e["text"], END_EARLIER_MAX), count: Math.min(count6, 1e4) });
18851
+ }
18852
+ return out;
18853
+ }
18854
+ function terminalEndOf(remote) {
18855
+ const kind = remote["kind"];
18856
+ const end = record2(remote["end"]);
18857
+ if (end === void 0 || kind !== "done" && kind !== "error") return void 0;
18858
+ const seq = end["item_seq"];
18859
+ if (typeof seq !== "number" || !Number.isSafeInteger(seq) || seq <= 0) return void 0;
18860
+ const attach = typeof end["attach"] === "string" && END_ATTACH.test(end["attach"]) ? end["attach"] : "";
18861
+ return {
18862
+ itemSeq: seq,
18863
+ name: clipText(end["name"], END_NAME_MAX),
18864
+ folder: clipText(end["folder"], END_NAME_MAX),
18865
+ error: kind === "error" ? clipText(end["error"], END_ERROR_MAX) : "",
18866
+ summary: clipText(end["summary"], END_SUMMARY_MAX),
18867
+ full: clipText(end["full"], END_FULL_MAX),
18868
+ more: end["more"] === true,
18869
+ attach,
18870
+ earlier: terminalEarlierOf(end["earlier"])
18871
+ };
18872
+ }
18660
18873
  var REMOTE_KINDS = /* @__PURE__ */ new Set(["done", "needs_you", "error", "resolved", "progress"]);
18661
18874
  var SEAT_ALIAS_MAX = 40;
18662
18875
  function seatOf(remote, ask3) {
@@ -18690,8 +18903,10 @@ function remoteNoticeOf(event) {
18690
18903
  const resolved = kind === "resolved" ? resolvedOf(remote) : void 0;
18691
18904
  if (kind === "resolved" && resolved === void 0) return void 0;
18692
18905
  const ask3 = record2(remote["ask"]);
18906
+ const end = terminalEndOf(remote);
18693
18907
  return {
18694
18908
  ...resolved ? { resolved } : {},
18909
+ ...end ? { end } : {},
18695
18910
  ...seatOf(remote, ask3),
18696
18911
  kind,
18697
18912
  sessionId,
@@ -19925,7 +20140,7 @@ ${p.quoted}`,
19925
20140
  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",
19926
20141
  shareNoteNoTmux: "Open in a terminal: a message from here cannot be typed into it now, so you can watch. To send from here, open the conversation in tmux, and in that one terminal only",
19927
20142
  shareNoteOld: "Open in a terminal: this machine's connector cannot type into a terminal yet (it needs 0.1.9 or newer), so you can watch",
19928
- terminalClosed: "The conversation was closed in the terminal, so the watch is over and your messages go to PrimusClaw again. Switch to it again to carry on with it.",
20143
+ terminalClosed: (p) => `The conversation was closed in the terminal, so the watch is over and your messages go to ${p.bot} again. Switch to it again to carry on with it.`,
19929
20144
  switched: (p) => `\u2014\u2014 Now: ${p.where} \u2014\u2014`,
19930
20145
  recoveredWhere: (p) => `${p.label} on ${p.host}`,
19931
20146
  recoveredContinuing: (p) => `\u2705 Recovered: the connector of ${p.where} restarted; it is going on from where it stopped, and what was waiting for your approval comes back as a new card.`,
@@ -20111,7 +20326,7 @@ ${p.quoted}`,
20111
20326
  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",
20112
20327
  shareNoteNoTmux: "\u7EC8\u7AEF\u91CC\u6B63\u5728\u7528\uFF1A\u8FD9\u91CC\u53D1\u7684\u6D88\u606F\u73B0\u5728\u6253\u4E0D\u8FDB\u90A3\u4E2A\u7EC8\u7AEF\uFF0C\u53EA\u80FD\u770B\u3002\u8981\u80FD\u53D1\uFF1A\u5728 tmux \u91CC\u6253\u5F00\u8FD9\u4E2A\u4F1A\u8BDD\uFF0C\u5E76\u4E14\u53EA\u5728\u8FD9\u4E00\u4E2A\u7EC8\u7AEF\u91CC\u5F00\u7740\u5B83",
20113
20328
  shareNoteOld: "\u7EC8\u7AEF\u91CC\u6B63\u5728\u7528\uFF1A\u8FD9\u53F0\u673A\u5668\u7684\u8FDE\u63A5\u5668\u8FD8\u4E0D\u80FD\u5F80\u7EC8\u7AEF\u91CC\u8F93\u5165\uFF08\u9700\u8981 0.1.9 \u6216\u66F4\u65B0\uFF09\uFF0C\u73B0\u5728\u53EA\u80FD\u770B",
20114
- terminalClosed: "\u7EC8\u7AEF\u91CC\u7684\u4F1A\u8BDD\u5DF2\u7ECF\u9000\u51FA\uFF0C\u65C1\u89C2\u7ED3\u675F\uFF0C\u4F60\u7684\u6D88\u606F\u56DE\u5230\u52A9\u7406\u3002\u8981\u63A5\u7740\u7528\u5B83\uFF0C\u518D\u5207\u8FC7\u53BB\u5C31\u884C\u3002",
20329
+ terminalClosed: (p) => `\u7EC8\u7AEF\u91CC\u7684\u4F1A\u8BDD\u5DF2\u7ECF\u9000\u51FA\uFF0C\u65C1\u89C2\u7ED3\u675F\uFF0C\u4F60\u7684\u6D88\u606F\u56DE\u5230 ${p.bot}\u3002\u8981\u63A5\u7740\u7528\u5B83\uFF0C\u518D\u5207\u8FC7\u53BB\u5C31\u884C\u3002`,
20115
20330
  switched: (p) => `\u2014\u2014 \u73B0\u5728\u662F ${p.where} \u2014\u2014`,
20116
20331
  recoveredWhere: (p) => `${p.host} \u4E0A\u7684 ${p.label}`,
20117
20332
  recoveredContinuing: (p) => `\u2705 \u5DF2\u6062\u590D\uFF1A${p.where} \u7684\u8FDE\u63A5\u5668\u91CD\u542F\u8FC7\uFF0C\u6B63\u5728\u4ECE\u65AD\u70B9\u63A5\u7740\u505A\uFF1B\u521A\u624D\u7B49\u4F60\u6279\u51C6\u7684\u64CD\u4F5C\u4F1A\u91CD\u65B0\u53D1\u4E00\u5F20\u5361\u3002`,
@@ -21218,12 +21433,27 @@ var terminalApprovalText = defineCatalog({
21218
21433
  approvalsOff: "Approvals from terminals are off: questions stay in the terminal.",
21219
21434
  approvalsTurnedOn: "Turned on: questions your terminals ask come here too. `/approvals off` stops it.",
21220
21435
  approvalsTurnedOff: "Turned off: questions stay in the terminal. `/approvals on` brings them back.",
21221
- approvalsUsage: "Use `/approvals on`, `/approvals off`, or `/approvals` to see which it is; `/approvals mute #12` (or `unmute #12`) for one terminal conversation, by the number its message names.",
21436
+ approvalsUsage: "Use `/approvals on`, `/approvals off`, or `/approvals` to see which it is; `/approvals mute #12` (or `unmute #12`) for one terminal conversation, by the number its message names; `/approvals summary 60` (minutes, 15 to 1440, or `off`) for how often a conversation that keeps working on its own is summed up.",
21222
21437
  muted: (p) => `Muted #${p.item}${p.where ? ` (${p.where})` : ""}: what that conversation asks, waits for or finishes stays in its terminal. \`/approvals unmute #${p.item}\` brings it back.`,
21223
21438
  unmuted: (p) => `Unmuted #${p.item}${p.where ? ` (${p.where})` : ""}: that conversation's questions and ends come here again.`,
21224
21439
  muteNotFound: (p) => `I have no item #${p.item} of yours.`,
21225
21440
  muteNotTerminal: (p) => `#${p.item} is not a conversation open in one of your terminals, so there is nothing to mute.`,
21226
- approvalsUnavailable: "I could not reach the setting just now. Try again in a moment."
21441
+ endDone: "finished",
21442
+ endError: (p) => `stopped with an error (${p.error})`,
21443
+ endIdle: "terminal idle",
21444
+ endFull: "Show all",
21445
+ endRest: "The rest is in the terminal.",
21446
+ endAttach: "Attach",
21447
+ endMute: "Mute this conversation",
21448
+ endEarlierAsked: (p) => p.text ? `An earlier turn asked: ${p.text}${p.count > 1 ? ` (${String(p.count)} earlier turns asked; see the terminal)` : ""}` : p.count > 1 ? `${String(p.count)} earlier turns asked you something; see the terminal.` : "An earlier turn asked you something; see the terminal.",
21449
+ endEarlierFailed: (p) => p.text ? `An earlier turn stopped with an error: ${p.text}${p.count > 1 ? ` (${String(p.count)} earlier turns did; see the terminal)` : ""}` : p.count > 1 ? `${String(p.count)} earlier turns stopped with an error; see the terminal.` : "An earlier turn stopped with an error; see the terminal.",
21450
+ endLatest: (p) => `Latest turn: ${p.text}`,
21451
+ approvalsUnavailable: "I could not reach the setting just now. Try again in a moment.",
21452
+ summaryEvery: (p) => `A terminal conversation that keeps working on its own (turns another session or a schedule started) is summed up at most once every ${p.minutes} minutes; the end of a turn you started, or one that asks you something, comes at once. \`/approvals summary <minutes>|off\` changes it.`,
21453
+ summaryNever: "Summaries are off: only the end of a turn you started, or one that asks you something, comes here. `/approvals summary 60` turns them back on.",
21454
+ summarySet: (p) => `Done: a conversation that keeps working on its own is summed up at most once every ${p.minutes} minutes.`,
21455
+ summaryOff: "Done: no more summaries; the end of a turn you started, or one that asks you something, still comes here.",
21456
+ summaryUsage: "Use `/approvals summary <minutes>` with 15 to 1440 minutes, `/approvals summary off`, or `/approvals summary` to see it."
21227
21457
  },
21228
21458
  zh: {
21229
21459
  title: "\u7EC8\u7AEF\u5728\u7B49\u4F60\u56DE\u7B54",
@@ -21258,12 +21488,27 @@ var terminalApprovalText = defineCatalog({
21258
21488
  approvalsOff: "\u7EC8\u7AEF\u5BA1\u6279\u63A8\u9001\u5DF2\u5173\u95ED\uFF1A\u8FD9\u4E9B\u95EE\u9898\u53EA\u5728\u7EC8\u7AEF\u91CC\u95EE\u3002",
21259
21489
  approvalsTurnedOn: "\u5DF2\u5F00\u542F\uFF1A\u7EC8\u7AEF\u91CC\u7684\u95EE\u9898\u4E5F\u4F1A\u63A8\u5230\u8FD9\u91CC\u3002\u53D1 `/approvals off` \u5173\u95ED\u3002",
21260
21490
  approvalsTurnedOff: "\u5DF2\u5173\u95ED\uFF1A\u95EE\u9898\u53EA\u5728\u7EC8\u7AEF\u91CC\u95EE\u3002\u53D1 `/approvals on` \u91CD\u65B0\u5F00\u542F\u3002",
21261
- approvalsUsage: "\u7528 `/approvals on` \u6216 `/approvals off`\uFF1B\u53EA\u53D1 `/approvals` \u770B\u5F53\u524D\u72B6\u6001\uFF1B\u5BF9\u5355\u4E2A\u7EC8\u7AEF\u4F1A\u8BDD\u7528 `/approvals mute #12`\uFF08\u6216 `unmute #12`\uFF09\uFF0C\u7F16\u53F7\u89C1\u63A8\u9001\u6D88\u606F\u5F00\u5934\u3002",
21491
+ approvalsUsage: "\u7528 `/approvals on` \u6216 `/approvals off`\uFF1B\u53EA\u53D1 `/approvals` \u770B\u5F53\u524D\u72B6\u6001\uFF1B\u5BF9\u5355\u4E2A\u7EC8\u7AEF\u4F1A\u8BDD\u7528 `/approvals mute #12`\uFF08\u6216 `unmute #12`\uFF09\uFF0C\u7F16\u53F7\u89C1\u63A8\u9001\u6D88\u606F\u91CC\u7684 #N\uFF1B`/approvals summary 60`\uFF08\u5206\u949F\uFF0C15 \u5230 1440\uFF0C\u6216 `off`\uFF09\u8BBE\u7F6E\u6301\u7EED\u5DE5\u4F5C\u7684\u4F1A\u8BDD\u591A\u4E45\u6C47\u603B\u4E00\u6B21\u3002",
21262
21492
  muted: (p) => `\u5DF2\u9759\u97F3 #${p.item}${p.where ? `\uFF08${p.where}\uFF09` : ""}\uFF1A\u8FD9\u4E2A\u4F1A\u8BDD\u7684\u63D0\u95EE\u3001\u7B49\u5F85\u548C\u5B8C\u6210\u90FD\u53EA\u7559\u5728\u7EC8\u7AEF\u91CC\u3002\u53D1 \`/approvals unmute #${p.item}\` \u6062\u590D\u3002`,
21263
21493
  unmuted: (p) => `\u5DF2\u6062\u590D #${p.item}${p.where ? `\uFF08${p.where}\uFF09` : ""}\uFF1A\u8FD9\u4E2A\u4F1A\u8BDD\u7684\u63D0\u95EE\u548C\u5B8C\u6210\u4F1A\u91CD\u65B0\u63A8\u5230\u8FD9\u91CC\u3002`,
21264
21494
  muteNotFound: (p) => `\u4F60\u6CA1\u6709\u7F16\u53F7\u4E3A #${p.item} \u7684\u4E8B\u9879\u3002`,
21265
21495
  muteNotTerminal: (p) => `#${p.item} \u4E0D\u662F\u4F60\u7EC8\u7AEF\u91CC\u6253\u5F00\u7684\u4F1A\u8BDD\uFF0C\u6CA1\u6709\u53EF\u9759\u97F3\u7684\u3002`,
21266
- approvalsUnavailable: "\u6682\u65F6\u8BFB\u4E0D\u5230\u8FD9\u4E2A\u8BBE\u7F6E\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5\u3002"
21496
+ endDone: "\u505A\u5B8C\u4E86",
21497
+ endError: (p) => `\u51FA\u9519\u505C\u4E0B\uFF08${p.error}\uFF09`,
21498
+ endIdle: "\u7EC8\u7AEF\u7A7A\u95F2",
21499
+ endFull: "\u5168\u6587",
21500
+ endRest: "\u5168\u6587\u89C1\u7EC8\u7AEF\u3002",
21501
+ endAttach: "\u63A5\u5165\u4F1A\u8BDD",
21502
+ endMute: "\u9759\u97F3\u6B64\u4F1A\u8BDD",
21503
+ endEarlierAsked: (p) => p.text ? `\u65E9\u5148\u4E00\u8F6E\u5728\u95EE\u4F60\uFF1A${p.text}${p.count > 1 ? `\uFF08\u65E9\u5148\u5171 ${String(p.count)} \u8F6E\u5728\u95EE\u4F60\uFF0C\u8BE6\u89C1\u7EC8\u7AEF\uFF09` : ""}` : `\u65E9\u5148\u6709 ${String(p.count)} \u8F6E\u5728\u95EE\u4F60\uFF0C\u8BE6\u89C1\u7EC8\u7AEF\u3002`,
21504
+ endEarlierFailed: (p) => p.text ? `\u65E9\u5148\u4E00\u8F6E\u51FA\u9519\u505C\u4E0B\uFF1A${p.text}${p.count > 1 ? `\uFF08\u65E9\u5148\u5171 ${String(p.count)} \u8F6E\u51FA\u9519\uFF0C\u8BE6\u89C1\u7EC8\u7AEF\uFF09` : ""}` : `\u65E9\u5148\u6709 ${String(p.count)} \u8F6E\u51FA\u9519\u505C\u4E0B\uFF0C\u8BE6\u89C1\u7EC8\u7AEF\u3002`,
21505
+ endLatest: (p) => `\u6700\u65B0\u4E00\u8F6E\uFF1A${p.text}`,
21506
+ approvalsUnavailable: "\u6682\u65F6\u8BFB\u4E0D\u5230\u8FD9\u4E2A\u8BBE\u7F6E\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5\u3002",
21507
+ summaryEvery: (p) => `\u5176\u4ED6\u4F1A\u8BDD\u6216\u5B9A\u65F6\u4EFB\u52A1\u9A71\u52A8\u3001\u6301\u7EED\u5728\u8DD1\u7684\u7EC8\u7AEF\u4F1A\u8BDD\uFF0C\u6700\u591A\u6BCF ${p.minutes} \u5206\u949F\u6C47\u603B\u4E00\u6B21\uFF1B\u4F60\u81EA\u5DF1\u53D1\u8D77\u7684\u56DE\u5408\u3001\u6216\u5728\u95EE\u4F60\u7684\u56DE\u5408\uFF0C\u7ED3\u675F\u65F6\u7ACB\u5373\u63A8\u9001\u3002\u53D1 \`/approvals summary <\u5206\u949F>|off\` \u4FEE\u6539\u3002`,
21508
+ summaryNever: "\u6C47\u603B\u5DF2\u5173\u95ED\uFF1A\u53EA\u63A8\u9001\u4F60\u81EA\u5DF1\u53D1\u8D77\u7684\u56DE\u5408\u3001\u6216\u5728\u95EE\u4F60\u7684\u56DE\u5408\u3002\u53D1 `/approvals summary 60` \u91CD\u65B0\u5F00\u542F\u3002",
21509
+ summarySet: (p) => `\u5DF2\u8BBE\u7F6E\uFF1A\u6301\u7EED\u5DE5\u4F5C\u7684\u7EC8\u7AEF\u4F1A\u8BDD\u6700\u591A\u6BCF ${p.minutes} \u5206\u949F\u6C47\u603B\u4E00\u6B21\u3002`,
21510
+ summaryOff: "\u5DF2\u5173\u95ED\u6C47\u603B\uFF1B\u4F60\u81EA\u5DF1\u53D1\u8D77\u7684\u56DE\u5408\u3001\u6216\u5728\u95EE\u4F60\u7684\u56DE\u5408\uFF0C\u7ED3\u675F\u65F6\u4ECD\u4F1A\u63A8\u9001\u3002",
21511
+ summaryUsage: "\u7528 `/approvals summary <\u5206\u949F>`\uFF0815 \u5230 1440\uFF09\uFF0C`/approvals summary off` \u5173\u95ED\uFF0C\u53EA\u53D1 `/approvals summary` \u67E5\u770B\u5F53\u524D\u8BBE\u7F6E\u3002"
21267
21512
  }
21268
21513
  });
21269
21514
 
@@ -21581,6 +21826,44 @@ function projectOf(ask3) {
21581
21826
  return str4(ask3["cwd"]).split("/").filter(Boolean).pop() ?? "";
21582
21827
  }
21583
21828
 
21829
+ // packages/core/src/remote-view/terminal-end-view.ts
21830
+ function terminalEndView(input) {
21831
+ const { end, lang } = input;
21832
+ const words3 = terminalApprovalText.in(lang);
21833
+ const failed3 = end.error !== "";
21834
+ const name = lit(end.name, 80) || lit(input.agent, 40);
21835
+ const status = failed3 ? words3.endError({ error: lit(end.error, 40) }) : words3.endDone;
21836
+ const where = [
21837
+ end.name ? lit(input.agent, 40) : "",
21838
+ lit(input.machine, 60),
21839
+ lit(end.folder, 80),
21840
+ words3.endIdle,
21841
+ `#${String(end.itemSeq)}`
21842
+ ].filter(Boolean);
21843
+ const earlier = end.earlier.map((e) => {
21844
+ const said2 = { text: lit(e.text, 400), count: e.count };
21845
+ return e.kind === "asked" ? words3.endEarlierAsked(said2) : words3.endEarlierFailed(said2);
21846
+ });
21847
+ const lines = end.summary.split("\n").map((line3) => lit(line3, 400)).filter(Boolean);
21848
+ const summary = (earlier.length && lines.length ? [words3.endLatest({ text: lines[0] ?? "" }), ...lines.slice(1)] : lines).join("\n\n");
21849
+ const full = end.more && end.full.trim() ? wordsText(end.full.trim()) : "";
21850
+ const buttons2 = [];
21851
+ if (end.attach) buttons2.push({ title: words3.endAttach, command: end.attach });
21852
+ buttons2.push({ title: words3.endMute, command: `/approvals mute #${String(end.itemSeq)}` });
21853
+ return {
21854
+ lang,
21855
+ title: `${name} ${status}`,
21856
+ failed: failed3,
21857
+ where: where.join(" \xB7 "),
21858
+ earlier,
21859
+ summary,
21860
+ full,
21861
+ fullLabel: words3.endFull,
21862
+ rest: end.more && !full ? words3.endRest : "",
21863
+ buttons: buttons2
21864
+ };
21865
+ }
21866
+
21584
21867
  // packages/core/src/proactive/deliver.ts
21585
21868
  var PROMPT_TITLE_MAX = 60;
21586
21869
  function view6(v) {
@@ -21691,8 +21974,22 @@ var Deliveries = class {
21691
21974
  }
21692
21975
  if (remote?.kind === "needs_you" && remote.ask !== void 0)
21693
21976
  return this.sendRemoteAsk(userId, conversation, event, remote);
21977
+ if (remote?.end !== void 0) return this.sendTerminalEnd(userId, conversation, event, remote, remote.end);
21694
21978
  return void 0;
21695
21979
  }
21980
+ /**
21981
+ * A turn that ended in a terminal while nobody was at it: its own card (which conversation, what it did, its whole answer on a tap,
21982
+ * and buttons that attach the chat to it or mute it); a channel that cannot show the card says Claw's words instead.
21983
+ */
21984
+ async sendTerminalEnd(userId, conversation, event, remote, end) {
21985
+ if (!conversation.caps.views) return void 0;
21986
+ const lang = answerLang(this.deps.store.prefs.getPrefs(userId).lang, this.clientLocale(), event["text"]);
21987
+ const model = terminalEndView({ end, machine: remote.machine, agent: remote.agent, lang });
21988
+ await conversation.send({
21989
+ body: { type: "view", view: { name: "terminalEnd", model }, fallbackText: str5(event["text"]) }
21990
+ });
21991
+ return true;
21992
+ }
21696
21993
  /**
21697
21994
  * What the assistant said, then, when its turn was refused something for want of a confirmed identity (`needs_identity`) and
21698
21995
  * this is the person's own chat (a group binding's key has `#`), the card that confirms it. A card that could not be sent never
@@ -28450,8 +28747,8 @@ function readOnlyRefused(lang, takeover = false) {
28450
28747
  const words3 = remoteText.in(lang);
28451
28748
  return words3.readOnly + (takeover ? words3.readOnlyTakeoverTail : "");
28452
28749
  }
28453
- function terminalClosedLine(lang) {
28454
- return remoteText.in(lang).terminalClosed;
28750
+ function terminalClosedLine(lang, bot) {
28751
+ return remoteText.in(lang).terminalClosed({ bot });
28455
28752
  }
28456
28753
  function whereLine(label, host) {
28457
28754
  return `${neutral2(host, 80)} \xB7 ${neutral2(label, 80)}`;
@@ -28713,7 +29010,9 @@ __export(remote_view_exports, {
28713
29010
  takeoverView: () => takeoverView,
28714
29011
  terminalAskView: () => terminalAskView,
28715
29012
  terminalAsksOf: () => terminalAsksOf,
28716
- windowView: () => windowView
29013
+ terminalEndView: () => terminalEndView,
29014
+ windowView: () => windowView,
29015
+ wordsText: () => wordsText
28717
29016
  });
28718
29017
 
28719
29018
  // packages/core/src/remote-view/machine-views.ts
@@ -29910,7 +30209,11 @@ var remoteAgentText = defineCatalog({
29910
30209
  keyRejected: "PrimusClaw rejected your linked key (it may have expired or been deleted). Send /unlink, then link again.",
29911
30210
  whichSession: "I could not tell which session you mean. Send `/agent sessions`, then `/agent attach N`.",
29912
30211
  whichSessionOrAgent: "I could not tell which session or agent you mean. Send `/agent sessions` to pick one.",
29913
- backToPrimusclaw: "Your messages go to PrimusClaw again.",
30212
+ backToBot: (p) => `Your messages go to ${p.bot} again.`,
30213
+ /** A new session that never started: the chat was never said to be in it, so its messages never left the bot. */
30214
+ stillToBot: (p) => `Your messages still go to ${p.bot}.`,
30215
+ /** A New session tap or `/agent new`, said at once: what starts where; where messages go is said once the agent has started. */
30216
+ starting: (p) => `Starting ${p.label} on ${p.host}${p.folder ? ` in ${p.folder}` : ""}\u2026 I will say here when it is running.`,
29914
30217
  tapInactive: "That button is not active any more.",
29915
30218
  tapInvalid: "That button is no longer valid.",
29916
30219
  cardExpired: "That card has expired. Send the command again, or use /agents.",
@@ -29951,11 +30254,11 @@ var remoteAgentText = defineCatalog({
29951
30254
  notAcceptedRef: (p) => `PrimusClaw did not accept that (ref ${p.ref}).`,
29952
30255
  couldNotTake: (p) => `PrimusClaw could not take that (error ${String(p.status)}).`,
29953
30256
  /** A session that ended while the chat was idle, when its end cannot be described (said in English, as the worker did). */
29954
- endedWhileIdle: (p) => (p.reason ? `The session ended: ${p.reason}.` : "The session ended.") + " Your messages go to PrimusClaw again. Start a new session with `/agent new AGENT PATH`.",
30257
+ endedWhileIdle: (p) => (p.reason ? `The session ended: ${p.reason}.` : "The session ended.") + ` Your messages go to ${p.bot} again. Start a new session with \`/agent new AGENT PATH\`.`,
29955
30258
  noMachineYet: "You have no machine connected yet.",
29956
30259
  changedElsewhere: "(Switched: see the status card below)",
29957
30260
  listBelow: "(Updated: see the card below)",
29958
- endedFollowTail: " Your messages go to PrimusClaw again. Start a new session with `/agent new AGENT PATH`.",
30261
+ endedFollowTail: (p) => ` Your messages go to ${p.bot} again. Start a new session with \`/agent new AGENT PATH\`.`,
29959
30262
  endedTail: " Start a new one with `/agent new AGENT PATH`.",
29960
30263
  approvalInPersonal: (p) => `${p.who} is waiting for your approval. I sent the card to our 1:1 chat, so the group does not see what it asks.`,
29961
30264
  ranOutRefused: (p) => `${p.tool}: this request ran out and was refused. Ask the agent to run it again if you still want it.`,
@@ -29989,7 +30292,7 @@ var remoteAgentText = defineCatalog({
29989
30292
  closedNumber: (p) => `Closed session ${String(p.number)}${p.where}.`,
29990
30293
  closedSession: (p) => `Closed the session${p.where}.`,
29991
30294
  closedIn: (p) => ` in ${p.folder}`,
29992
- closedBack: " Your messages go to PrimusClaw again.",
30295
+ closedBack: (p) => ` Your messages go to ${p.bot} again.`,
29993
30296
  newUsage: "Use `/agent new AGENT PATH`, for example `/agent new codex /home/me/repo`, or pick a folder here and tap New session.",
29994
30297
  modeIs: (p) => `Mode: \`${p.mode}\`. `,
29995
30298
  modesOffered: (p) => `The agent offers ${p.have}. Change it with \`/agent mode ID\`.`,
@@ -30037,7 +30340,9 @@ var remoteAgentText = defineCatalog({
30037
30340
  keyRejected: "PrimusClaw \u62D2\u7EDD\u4E86\u4F60\u5173\u8054\u7684 key\uFF08\u53EF\u80FD\u5DF2\u8FC7\u671F\u6216\u88AB\u5220\u9664\uFF09\u3002\u53D1 /unlink\uFF0C\u7136\u540E\u91CD\u65B0\u5173\u8054\u3002",
30038
30341
  whichSession: "\u6211\u5206\u4E0D\u6E05\u4F60\u8BF4\u7684\u662F\u54EA\u4E2A\u4F1A\u8BDD\u3002\u53D1 `/agent sessions`\uFF0C\u518D\u53D1 `/agent attach N`\u3002",
30039
30342
  whichSessionOrAgent: "\u6211\u5206\u4E0D\u6E05\u4F60\u8BF4\u7684\u662F\u54EA\u4E2A\u4F1A\u8BDD\u6216 agent\u3002\u53D1 `/agent sessions` \u9009\u4E00\u4E2A\u3002",
30040
- backToPrimusclaw: "\u4F60\u7684\u6D88\u606F\u4F1A\u91CD\u65B0\u53D1\u7ED9 PrimusClaw\u3002",
30343
+ backToBot: (p) => `\u4F60\u7684\u6D88\u606F\u4F1A\u91CD\u65B0\u53D1\u7ED9 ${p.bot}\u3002`,
30344
+ stillToBot: (p) => `\u4F60\u7684\u6D88\u606F\u4ECD\u7136\u53D1\u7ED9 ${p.bot}\u3002`,
30345
+ starting: (p) => `\u6B63\u5728 ${p.host} \u4E0A\u542F\u52A8 ${p.label}${p.folder ? `\uFF08${p.folder}\uFF09` : ""}\u2026\u2026\u542F\u52A8\u597D\u4E86\u6211\u5728\u8FD9\u91CC\u8BF4\u3002`,
30041
30346
  tapInactive: "\u8FD9\u4E2A\u6309\u94AE\u5DF2\u7ECF\u5931\u6548\u4E86\u3002",
30042
30347
  tapInvalid: "\u8FD9\u4E2A\u6309\u94AE\u5DF2\u7ECF\u4E0D\u80FD\u7528\u4E86\u3002",
30043
30348
  cardExpired: "\u8FD9\u5F20\u5361\u7247\u5DF2\u7ECF\u8FC7\u671F\u4E86\u3002\u91CD\u65B0\u53D1\u4E00\u6B21\u547D\u4EE4\uFF0C\u6216\u8005\u7528 /agents\u3002",
@@ -30077,11 +30382,11 @@ var remoteAgentText = defineCatalog({
30077
30382
  notAccepted: (p) => `PrimusClaw \u6CA1\u6709\u63A5\u53D7\u8FD9\u4E2A\u8BF7\u6C42\uFF08${p.code}\uFF09\u3002`,
30078
30383
  notAcceptedRef: (p) => `PrimusClaw \u6CA1\u6709\u63A5\u53D7\u8FD9\u4E2A\u8BF7\u6C42\uFF08ref ${p.ref}\uFF09\u3002`,
30079
30384
  couldNotTake: (p) => `PrimusClaw \u5904\u7406\u4E0D\u4E86\u8FD9\u4E2A\u8BF7\u6C42\uFF08\u9519\u8BEF ${String(p.status)}\uFF09\u3002`,
30080
- endedWhileIdle: (p) => (p.reason ? `\u4F1A\u8BDD\u5DF2\u7ED3\u675F\uFF1A${p.reason}\u3002` : "\u4F1A\u8BDD\u5DF2\u7ED3\u675F\u3002") + "\u4F60\u7684\u6D88\u606F\u4F1A\u91CD\u65B0\u53D1\u7ED9 PrimusClaw\u3002\u7528 `/agent new AGENT PATH` \u5F00\u65B0\u4F1A\u8BDD\u3002",
30385
+ endedWhileIdle: (p) => (p.reason ? `\u4F1A\u8BDD\u5DF2\u7ED3\u675F\uFF1A${p.reason}\u3002` : "\u4F1A\u8BDD\u5DF2\u7ED3\u675F\u3002") + `\u4F60\u7684\u6D88\u606F\u4F1A\u91CD\u65B0\u53D1\u7ED9 ${p.bot}\u3002\u7528 \`/agent new AGENT PATH\` \u5F00\u65B0\u4F1A\u8BDD\u3002`,
30081
30386
  noMachineYet: "\u4F60\u8FD8\u6CA1\u6709\u8FDE\u63A5\u4EFB\u4F55\u673A\u5668\u3002",
30082
30387
  changedElsewhere: "\uFF08\u5DF2\u5207\u6362\uFF0C\u89C1\u4E0B\u65B9\u7684\u65B0\u72B6\u6001\u5361\uFF09",
30083
30388
  listBelow: "\uFF08\u5DF2\u66F4\u65B0\uFF0C\u89C1\u4E0B\u65B9\u7684\u65B0\u5361\u7247\uFF09",
30084
- endedFollowTail: " \u4F60\u7684\u6D88\u606F\u4F1A\u91CD\u65B0\u53D1\u7ED9 PrimusClaw\u3002\u7528 `/agent new AGENT PATH` \u5F00\u65B0\u4F1A\u8BDD\u3002",
30389
+ endedFollowTail: (p) => ` \u4F60\u7684\u6D88\u606F\u4F1A\u91CD\u65B0\u53D1\u7ED9 ${p.bot}\u3002\u7528 \`/agent new AGENT PATH\` \u5F00\u65B0\u4F1A\u8BDD\u3002`,
30085
30390
  endedTail: " \u7528 `/agent new AGENT PATH` \u5F00\u65B0\u4F1A\u8BDD\u3002",
30086
30391
  approvalInPersonal: (p) => `${p.who} \u5728\u7B49\u4F60\u6279\u51C6\u3002\u5BA1\u6279\u5361\u53D1\u5230\u4E86\u4F60\u548C\u6211\u7684 1:1 \u804A\u5929\u91CC\uFF0C\u7FA4\u91CC\u770B\u4E0D\u5230\u5B83\u8981\u505A\u4EC0\u4E48\u3002`,
30087
30392
  ranOutRefused: (p) => `${p.tool}\uFF1A\u8FD9\u4E2A\u8BF7\u6C42\u5DF2\u7ECF\u8FC7\u671F\uFF0C\u5DF2\u81EA\u52A8\u62D2\u7EDD\u3002\u8FD8\u9700\u8981\u7684\u8BDD\uFF0C\u8BA9 agent \u518D\u6267\u884C\u4E00\u6B21\u3002`,
@@ -30120,7 +30425,7 @@ var remoteAgentText = defineCatalog({
30120
30425
  closedNumber: (p) => `\u5DF2\u5173\u95ED\u4F1A\u8BDD ${String(p.number)}${p.where}\u3002`,
30121
30426
  closedSession: (p) => `\u5DF2\u5173\u95ED\u4F1A\u8BDD${p.where}\u3002`,
30122
30427
  closedIn: (p) => `\uFF08${p.folder}\uFF09`,
30123
- closedBack: "\u4F60\u7684\u6D88\u606F\u4F1A\u91CD\u65B0\u53D1\u7ED9 PrimusClaw\u3002",
30428
+ closedBack: (p) => `\u4F60\u7684\u6D88\u606F\u4F1A\u91CD\u65B0\u53D1\u7ED9 ${p.bot}\u3002`,
30124
30429
  // (said in English, as the worker did)
30125
30430
  newUsage: "Use `/agent new AGENT PATH`, for example `/agent new codex /home/me/repo`, or pick a folder here and tap New session.",
30126
30431
  modeIs: (p) => `Mode: \`${p.mode}\`. `,
@@ -30492,7 +30797,8 @@ var StatusBoard = class {
30492
30797
  const state = this.state.attached(chatKey);
30493
30798
  if (state === null) return;
30494
30799
  if (this.state.direct(chatKey)) {
30495
- await this.sayEntered(chatKey, to, state, unattended, lead);
30800
+ if (phase === "starting") await this.sayStarting(chatKey, to, state);
30801
+ else await this.sayEntered(chatKey, to, state, unattended, lead);
30496
30802
  return;
30497
30803
  }
30498
30804
  const card = this.statusOf(chatKey, state, phase, lead, unattended);
@@ -30524,6 +30830,19 @@ var StatusBoard = class {
30524
30830
  const [title, value] = backReply(lang, this.ctx.settings.botName);
30525
30831
  await to.send({ ...textMessage(line3), suggestions: [{ title, value }] });
30526
30832
  }
30833
+ /**
30834
+ * A chat that is the agent's window itself has just asked for a new session: one line says what starts where. Nothing says the
30835
+ * chat's messages go there yet: that is said once the agent has started (`sayEntered`), and a session that cannot start says
30836
+ * that the messages still go to the bot (2026-11-24: "now go to" said before a start that failed, then taken back).
30837
+ */
30838
+ async sayStarting(chatKey, to, state) {
30839
+ const words3 = remoteAgentText.in(this.state.lang(chatKey));
30840
+ this.ctx.remoteState.setRemoteStatusCard(chatKey, "");
30841
+ const folder = state.cwd ? `\`${neutral(state.cwd, 120)}\`` : "";
30842
+ await to.send(
30843
+ textMessage(words3.starting({ label: neutral(state.agentLabel, 80), host: neutral(state.host, 80), folder }))
30844
+ );
30845
+ }
30527
30846
  /**
30528
30847
  * The suggested replies under what the assistant says to a chat that is the agent's window itself: back to the assistant while
30529
30848
  * attached, else back to the agent it last talked to.
@@ -30567,6 +30886,7 @@ function newTurn() {
30567
30886
  task: null,
30568
30887
  stopRequested: false,
30569
30888
  waitsForTerminal: false,
30889
+ display: null,
30570
30890
  get ended() {
30571
30891
  return this.task?.running !== true;
30572
30892
  }
@@ -30595,6 +30915,18 @@ var ChatRegistry = class {
30595
30915
  /** The session each chat was told its terminal's registry row cannot be read for (once per attach). */
30596
30916
  rowHinted = /* @__PURE__ */ new Map();
30597
30917
  tickets = /* @__PURE__ */ new Map();
30918
+ /** The chat went on below its running turn's display: that turn's answer must come below what was said since (`movedOn`). */
30919
+ movedOn(chatKey) {
30920
+ this.turns.get(chatKey)?.display?.movedOn?.();
30921
+ }
30922
+ /** The turns running now in a 1:1 chat (`userId`) or, with `scope`, in that group (every binding's there). */
30923
+ turnsIn(userId, scope) {
30924
+ if (!scope) {
30925
+ const turn = this.turns.get(userId);
30926
+ return turn ? [turn] : [];
30927
+ }
30928
+ return [...this.turns].filter(([chatKey]) => groupConversationOf(chatKey) === scope).map(([, turn]) => turn);
30929
+ }
30598
30930
  /** How many messages wait behind the chat's running turn. */
30599
30931
  queuedCount(chatKey) {
30600
30932
  return this.queuedPrompts.get(chatKey)?.length ?? 0;
@@ -31241,7 +31573,8 @@ var StartClicks = class {
31241
31573
  const state = this.p.state.attached(click.chatKey);
31242
31574
  await this.becomeStatus(
31243
31575
  click,
31244
- state ? await this.p.ops.rowCard(click.chatKey, click.key, state, "", agent, "starting") : null
31576
+ state ? await this.p.ops.rowCard(click.chatKey, click.key, state, "", agent, "starting") : null,
31577
+ true
31245
31578
  );
31246
31579
  const watch = {
31247
31580
  chatKey: click.chatKey,
@@ -31330,13 +31663,14 @@ var StartClicks = class {
31330
31663
  * and the tapped card deleted (a phone does not redraw an edit). Where no new card can be sent, the tapped card becomes the
31331
31664
  * status card in place.
31332
31665
  */
31333
- async becomeStatus(click, card) {
31666
+ async becomeStatus(click, card, starting = false) {
31334
31667
  const lang = this.c.lang(click);
31335
31668
  const state = this.p.state.attached(click.chatKey);
31336
31669
  if (card === null || state === null) return this.c.home(click, saidIn(lang, "sessionUnavailable"));
31337
31670
  const old = this.p.ctx.remoteState.getRemote(click.chatKey)?.statusCard ?? "";
31338
31671
  if (this.p.state.direct(click.chatKey)) {
31339
- await this.p.board.sayEntered(click.chatKey, click.to, state);
31672
+ if (starting) await this.p.board.sayStarting(click.chatKey, click.to, state);
31673
+ else await this.p.board.sayEntered(click.chatKey, click.to, state);
31340
31674
  if (click.tapped) await this.removeTapped(click);
31341
31675
  return;
31342
31676
  }
@@ -31759,6 +32093,8 @@ var MachineClicks = class {
31759
32093
  var remoteLeads = {
31760
32094
  sessionEnded: ["\u4F1A\u8BDD\u5DF2\u7ED3\u675F", "The session ended"],
31761
32095
  couldNotStart: ["\u4F1A\u8BDD\u6CA1\u80FD\u542F\u52A8", "The session could not start"],
32096
+ /** (`folder`: already shown inert, in backticks) */
32097
+ couldNotStartIn: (folder) => [`\u4F1A\u8BDD\u6CA1\u80FD\u5728 ${folder} \u542F\u52A8`, `The session could not start in ${folder}`],
31762
32098
  turnIncomplete: ["\u8FD9\u4E00\u8F6E\u6CA1\u6709\u5B8C\u6210", "The turn did not complete"],
31763
32099
  /** (a message the terminal may have taken: never said as a turn that did not complete) */
31764
32100
  inputUnconfirmed: ["\u8FD8\u6CA1\u786E\u8BA4\u7EC8\u7AEF\u6536\u5230", "Not confirmed by the terminal yet"],
@@ -31784,7 +32120,7 @@ var connectorReasonText = defineCatalog({
31784
32120
  adapter_error: "The agent program failed. Look at `run.log` in the connector's state directory on that machine.",
31785
32121
  agent_auth_required: "The agent is not signed in on that machine. Run the agent there once (`claude`, for example) to sign in, then try again.",
31786
32122
  cwd_outside_roots: "That directory is outside the roots the agent may work in. Pick one inside them, or add it to `roots` in agents.toml and restart the connector.",
31787
- cwd_not_found: "That directory does not exist on that machine.",
32123
+ cwd_not_found: "That folder does not exist on that machine: pick one that exists there, or create it there first.",
31788
32124
  cwd_not_directory: "That path is not a directory.",
31789
32125
  cwd_not_absolute: "The directory must be an absolute path (starting with /).",
31790
32126
  invalid_cwd: "That directory name is not valid.",
@@ -31863,7 +32199,7 @@ var connectorReasonText = defineCatalog({
31863
32199
  adapter_error: "agent \u7A0B\u5E8F\u62A5\u9519\u4E86\u3002\u5728\u90A3\u53F0\u673A\u5668\u4E0A\u770B\u8FDE\u63A5\u5668\u72B6\u6001\u76EE\u5F55\u91CC\u7684 `run.log`\u3002",
31864
32200
  agent_auth_required: "\u90A3\u53F0\u673A\u5668\u4E0A\u7684 agent \u8FD8\u6CA1\u767B\u5F55\u3002\u5728\u90A3\u53F0\u673A\u5668\u4E0A\u8FD0\u884C\u4E00\u6B21 agent\uFF08\u4F8B\u5982 `claude`\uFF09\u5B8C\u6210\u767B\u5F55\uFF0C\u518D\u8BD5\u3002",
31865
32201
  cwd_outside_roots: "\u8FD9\u4E2A\u76EE\u5F55\u4E0D\u5728\u8BE5 agent \u5141\u8BB8\u7684 roots \u91CC\u3002\u6362\u4E00\u4E2A roots \u91CC\u7684\u76EE\u5F55\uFF0C\u6216\u5728 agents.toml \u7684 `roots` \u91CC\u52A0\u4E0A\u5B83\u5E76\u91CD\u542F\u8FDE\u63A5\u5668\u3002",
31866
- cwd_not_found: "\u90A3\u53F0\u673A\u5668\u4E0A\u6CA1\u6709\u8FD9\u4E2A\u76EE\u5F55\u3002",
32202
+ cwd_not_found: "\u90A3\u53F0\u673A\u5668\u4E0A\u6CA1\u6709\u8FD9\u4E2A\u76EE\u5F55\uFF1A\u9009\u4E00\u4E2A\u90A3\u91CC\u5DF2\u6709\u7684\u76EE\u5F55\uFF0C\u6216\u8005\u5148\u5728\u90A3\u53F0\u673A\u5668\u4E0A\u5EFA\u597D\u5B83\u3002",
31867
32203
  cwd_not_directory: "\u8FD9\u4E2A\u8DEF\u5F84\u4E0D\u662F\u76EE\u5F55\u3002",
31868
32204
  cwd_not_absolute: "\u76EE\u5F55\u8981\u5199\u6210\u7EDD\u5BF9\u8DEF\u5F84\uFF08\u4EE5 / \u5F00\u5934\uFF09\u3002",
31869
32205
  invalid_cwd: "\u8FD9\u4E2A\u76EE\u5F55\u540D\u65E0\u6548\uFF0C\u6362\u4E00\u4E2A\u76EE\u5F55\u518D\u8BD5\u3002",
@@ -32083,7 +32419,7 @@ var EndedWords = class {
32083
32419
  const lang = this.state.lang(chatKey);
32084
32420
  const words3 = remoteAgentText.in(lang);
32085
32421
  const head = await this.said(chatKey, remoteLeads.sessionEnded, key, provider, connectorId, reason);
32086
- return head + (follow ? words3.endedFollowTail : words3.endedTail);
32422
+ return head + (follow ? words3.endedFollowTail({ bot: this.ctx.settings.botName }) : words3.endedTail);
32087
32423
  }
32088
32424
  };
32089
32425
 
@@ -32495,8 +32831,8 @@ var BurstSpeaker = class {
32495
32831
  if (reference === null) return;
32496
32832
  this.deps.remoteState.detachRemote(this.chatKey);
32497
32833
  const bare2 = bareReason(reason);
32498
- let text9 = remoteAgentText.in("en").endedWhileIdle({ reason: bare2 });
32499
- if (bare2 === TERMINAL_CLOSED) text9 = terminalClosedLine(this.langOr("en"));
32834
+ let text9 = remoteAgentText.in("en").endedWhileIdle({ reason: bare2, bot: this.deps.botName });
32835
+ if (bare2 === TERMINAL_CLOSED) text9 = terminalClosedLine(this.langOr("en"), this.deps.botName);
32500
32836
  else if (this.deps.describeEnd !== void 0) {
32501
32837
  try {
32502
32838
  text9 = await unlessCutOff(this.deps.describeEnd(bare2), this.cutOff);
@@ -32906,16 +33242,13 @@ var Watches = class {
32906
33242
  async couldNotStart(w, state, reason) {
32907
33243
  this.ctx.guard.giveBack(w.chatKey, "remote_agent", w.ticket);
32908
33244
  const lang = this.state.lang(w.chatKey);
32909
- const said2 = await this.ended.said(
32910
- w.chatKey,
32911
- remoteLeads.couldNotStart,
32912
- w.key,
32913
- w.provider,
32914
- state.connectorId,
32915
- reason
32916
- );
33245
+ const lead = state.cwd ? remoteLeads.couldNotStartIn(`\`${neutral(state.cwd, 120)}\``) : remoteLeads.couldNotStart;
33246
+ const said2 = await this.ended.said(w.chatKey, lead, w.key, w.provider, state.connectorId, reason);
33247
+ const direct = this.state.direct(w.chatKey);
32917
33248
  this.follow.detach(w.chatKey);
32918
- await w.to.send(textMessage(`${said2} ${saidIn(lang, "backToPrimusclaw")}`));
33249
+ const words3 = remoteAgentText.in(lang);
33250
+ const bot = this.ctx.settings.botName;
33251
+ await w.to.send(textMessage(`${said2} ${direct ? words3.stillToBot({ bot }) : words3.backToBot({ bot })}`));
32919
33252
  }
32920
33253
  /** Open in a terminal: watched, read-only; its output is told as it comes. */
32921
33254
  async watching(w) {
@@ -32923,7 +33256,8 @@ var Watches = class {
32923
33256
  this.ctx.guard.giveBack(w.chatKey, "remote_agent", w.ticket);
32924
33257
  const state = this.state.attached(w.chatKey);
32925
33258
  if (state?.sessionId !== w.sessionId) return;
32926
- if (await this.board.settleStatus(w.chatKey, w.to, state, "watching")) return;
33259
+ if (this.state.direct(w.chatKey)) await this.board.sayEntered(w.chatKey, w.to, state);
33260
+ else if (await this.board.settleStatus(w.chatKey, w.to, state, "watching")) return;
32927
33261
  const lang = this.state.lang(w.chatKey);
32928
33262
  const head = remoteAgentText.in(lang).watchingHead({ label: state.agentLabel, host: state.host });
32929
33263
  await w.to.send(textMessage(`${head} ${readOnlyRefused(lang, this.state.offersTakeover(w.chatKey))}`));
@@ -32938,6 +33272,7 @@ var Watches = class {
32938
33272
  const state = this.state.attached(w.chatKey);
32939
33273
  if (state?.sessionId !== w.sessionId) return;
32940
33274
  if (state.unattended === false) this.ctx.guard.giveBack(w.chatKey, "remote_agent", w.ticket);
33275
+ if (this.state.direct(w.chatKey)) return this.board.sayEntered(w.chatKey, w.to, state, void 0, switched.trim());
32941
33276
  if (await this.board.settleStatus(w.chatKey, w.to, state, "idle", switched.trim())) {
32942
33277
  if (switched) await w.to.send(textMessage(switched.trim()));
32943
33278
  return;
@@ -32948,6 +33283,8 @@ var Watches = class {
32948
33283
  const lang = this.state.lang(w.chatKey);
32949
33284
  const state = this.state.attached(w.chatKey);
32950
33285
  const lead = remoteAgentText.in(lang).notReportedLead;
33286
+ if (state !== null && this.state.direct(w.chatKey))
33287
+ return this.board.sayEntered(w.chatKey, w.to, state, void 0, lead);
32951
33288
  if (state === null || !await this.board.settleStatus(w.chatKey, w.to, state, "idle", lead)) {
32952
33289
  await w.to.send(textMessage(saidIn(lang, "notReported")));
32953
33290
  }
@@ -34067,6 +34404,7 @@ var Prompts = class {
34067
34404
  const text9 = remoteAgentText.in(this.state.lang(p.chatKey));
34068
34405
  const waiting = this.state.chats.queuedCount(p.chatKey);
34069
34406
  if (this.state.chats.queuedMessage(p.chatKey, p.messageId)) return;
34407
+ this.state.chats.movedOn(p.chatKey);
34070
34408
  if (waiting >= QUEUED_PROMPTS_MAX) return this.say(p.to, text9.queueFull({ n: QUEUED_PROMPTS_MAX }));
34071
34409
  const sid = state.sessionId;
34072
34410
  let cmdSeq = void 0;
@@ -34106,7 +34444,7 @@ var Prompts = class {
34106
34444
  const lang = this.state.lang(p.chatKey);
34107
34445
  if (await this.state.watchOver(p.key, state)) {
34108
34446
  this.follow.detach(p.chatKey);
34109
- return this.say(p.to, terminalClosedLine(lang));
34447
+ return this.say(p.to, terminalClosedLine(lang, this.ctx.settings.botName));
34110
34448
  }
34111
34449
  await this.say(p.to, readOnlyRefused(lang, this.state.offersTakeover(p.chatKey)));
34112
34450
  }
@@ -34135,7 +34473,10 @@ var Prompts = class {
34135
34473
  }
34136
34474
  if (error instanceof ClawError && error.status === 409 && error.code === "session_closed") {
34137
34475
  this.follow.detach(p.chatKey);
34138
- await this.say(p.to, `${this.failure(error, p.chatKey)} ${saidIn(lang, "backToPrimusclaw")}`);
34476
+ await this.say(
34477
+ p.to,
34478
+ `${this.failure(error, p.chatKey)} ${remoteAgentText.in(lang).backToBot({ bot: this.ctx.settings.botName })}`
34479
+ );
34139
34480
  return false;
34140
34481
  }
34141
34482
  if (!(error instanceof ClawError) && !isTransport2(error)) throw error;
@@ -34400,7 +34741,7 @@ var SessionOps = class {
34400
34741
  }
34401
34742
  const words3 = remoteAgentText.in(lang);
34402
34743
  const where = folder ? words3.closedIn({ folder: neutral(folder, 300) }) : "";
34403
- const text9 = (number ? words3.closedNumber({ number, where }) : words3.closedSession({ where })) + (mine ? words3.closedBack : "");
34744
+ const text9 = (number ? words3.closedNumber({ number, where }) : words3.closedSession({ where })) + (mine ? words3.closedBack({ bot: this.ctx.settings.botName }) : "");
34404
34745
  return { done: true, text: text9 };
34405
34746
  }
34406
34747
  };
@@ -34751,6 +35092,9 @@ var ChatTurn = class {
34751
35092
  close(hard = false) {
34752
35093
  this.status.close(hard);
34753
35094
  }
35095
+ movedOn() {
35096
+ this.status.movedOn(turnText.in(toLang(this.options.lang)).answerBelow);
35097
+ }
34754
35098
  finish(parts2, options) {
34755
35099
  return this.status.finish(parts2, { rich: true, feedback: false, ai: options.ai, replies: options.replies });
34756
35100
  }
@@ -34873,6 +35217,7 @@ var TurnRunner = class {
34873
35217
  async run(request, turn, signal) {
34874
35218
  const { chatKey, to, state } = request;
34875
35219
  const { display, signer } = this.display(request);
35220
+ turn.display = display;
34876
35221
  display.begin();
34877
35222
  const fold = new RemoteTurnState(this.ctx.errors, request.cmdSeq);
34878
35223
  const cursor = this.ctx.remoteState.getRemote(chatKey)?.cursor ?? "";
@@ -34991,16 +35336,19 @@ var TurnRunner = class {
34991
35336
  const sid = request.state.sessionId ?? "";
34992
35337
  noteWaiting(this.state.chats.turns.get(chatKey), step);
34993
35338
  if (step.rejected?.type === "prompt" && step.rejected.cmdSeq !== null) {
34994
- await this.queuedRefused(chatKey, to, step.rejected.cmdSeq, step.rejected.reason);
35339
+ await this.queuedRefused(chatKey, to, step.rejected.cmdSeq, step.rejected.reason, display);
34995
35340
  }
34996
35341
  if (step.queued !== null) await this.showWait(request, step, display);
34997
35342
  else display.progress(step);
34998
- if (step.rowUnreadable) await this.sayRowUnreadable(chatKey, sid, to);
35343
+ if (step.rowUnreadable) await this.sayRowUnreadable(chatKey, sid, to, display);
34999
35344
  if (saysModes(step)) this.ctx.remoteState.setRemoteModes(chatKey, sid, step);
35000
- if (step.permission !== null) await this.show(chatKey, sid, step.permission, to);
35345
+ if (step.permission !== null) {
35346
+ display.movedOn?.();
35347
+ await this.show(chatKey, sid, step.permission, to);
35348
+ }
35001
35349
  if (step.resolved !== null) this.ctx.permissions.closeRemotePermission(sid, actionIdOf(step.resolved), "decided");
35002
35350
  if (step.recovered !== null && (step.recovered.continuing || !step.recovered.interrupted)) {
35003
- await this.sayRecovered(chatKey, to, step.recovered.interrupted, step.recovered.continuing);
35351
+ await this.sayRecovered(chatKey, to, step.recovered.interrupted, step.recovered.continuing, display);
35004
35352
  }
35005
35353
  }
35006
35354
  /**
@@ -35008,7 +35356,7 @@ var TurnRunner = class {
35008
35356
  * 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
35009
35357
  * told so when it was sent (`queuedBehind`): not again here.
35010
35358
  */
35011
- async tellBusy(request, step) {
35359
+ async tellBusy(request, step, display) {
35012
35360
  const { chatKey, to } = request;
35013
35361
  const mine = request.cmdSeq?.();
35014
35362
  if (step.queuedSeq === null || mine === void 0 || step.queuedSeq !== mine) return;
@@ -35024,6 +35372,7 @@ var TurnRunner = class {
35024
35372
  this.toldBusy.set(chatKey, told);
35025
35373
  const words3 = remoteAgentText.in(this.state.lang(chatKey));
35026
35374
  const text9 = before === "waiting" ? words3.terminalBusyNowHeld : words3.terminalBusy + (step.queuedHeld ? words3.terminalBusyHeld : words3.terminalBusyWaiting);
35375
+ display.movedOn?.();
35027
35376
  try {
35028
35377
  await to.send(textMessage(text9));
35029
35378
  } catch (error) {
@@ -35034,11 +35383,12 @@ var TurnRunner = class {
35034
35383
  * A message waiting behind this turn was refused on the machine before it ran: it waits no more, and the person is told. One whose
35035
35384
  * send has not answered yet has no number to match: the refusal is kept for that send (`Prompts.queueBehind`).
35036
35385
  */
35037
- async queuedRefused(chatKey, to, cmdSeq, reason) {
35386
+ async queuedRefused(chatKey, to, cmdSeq, reason, display) {
35038
35387
  if (this.state.chats.takeQueuedSeq(chatKey, cmdSeq) === void 0) {
35039
35388
  this.state.chats.noteRefusal(chatKey, cmdSeq, reason);
35040
35389
  return;
35041
35390
  }
35391
+ display.movedOn?.();
35042
35392
  try {
35043
35393
  await to.send(textMessage(remoteAgentText.in(this.state.lang(chatKey)).queuedRefused({ reason })));
35044
35394
  } catch (error) {
@@ -35057,7 +35407,7 @@ var TurnRunner = class {
35057
35407
  const note = queuedNote(reason, step.dialog, lang);
35058
35408
  display.progress({ ...step, note, waitLine: queuedLine(reason, lang) });
35059
35409
  if (reason === "terminal_dialog" && !display.showsWaits) await this.sayQuestion(display, note, to);
35060
- if (BUSY_REASONS.has(reason)) await this.tellBusy(request, step);
35410
+ if (BUSY_REASONS.has(reason)) await this.tellBusy(request, step, display);
35061
35411
  }
35062
35412
  /**
35063
35413
  * What a question on the terminal asks, while the message waits for it: said in the chat once per question and turn (the stream's
@@ -35068,6 +35418,7 @@ var TurnRunner = class {
35068
35418
  if (told.has(line3)) return;
35069
35419
  told.add(line3);
35070
35420
  this.questionsTold.set(display, told);
35421
+ display.movedOn?.();
35071
35422
  try {
35072
35423
  await to.send(textMessage(line3));
35073
35424
  } catch (error) {
@@ -35075,8 +35426,9 @@ var TurnRunner = class {
35075
35426
  }
35076
35427
  }
35077
35428
  /** Once per attach: the terminal's registry row cannot be read, and a restart of it there makes it known again. */
35078
- async sayRowUnreadable(chatKey, sid, to) {
35429
+ async sayRowUnreadable(chatKey, sid, to, display) {
35079
35430
  if (!this.state.chats.firstRowHint(chatKey, sid)) return;
35431
+ display.movedOn?.();
35080
35432
  try {
35081
35433
  await to.send(textMessage(rowUnreadableLine(this.state.lang(chatKey))));
35082
35434
  } catch (error) {
@@ -35085,9 +35437,10 @@ var TurnRunner = class {
35085
35437
  });
35086
35438
  }
35087
35439
  }
35088
- async sayRecovered(chatKey, to, interrupted, continuing) {
35440
+ async sayRecovered(chatKey, to, interrupted, continuing, display) {
35089
35441
  const state = this.ctx.remoteState.getRemote(chatKey);
35090
35442
  if (!state?.sessionId) return;
35443
+ display.movedOn?.();
35091
35444
  try {
35092
35445
  const line3 = recoveredLine(state.agentLabel, state.host, this.state.lang(chatKey), interrupted, continuing);
35093
35446
  await to.send(textMessage(line3));
@@ -35394,6 +35747,13 @@ var RemoteAgents = class {
35394
35747
  currentTurn(chatKey) {
35395
35748
  return this.chats.turns.get(chatKey);
35396
35749
  }
35750
+ goesOn(userId, scope) {
35751
+ const turns = this.chats.turnsIn(userId, scope);
35752
+ if (turns.length === 0) return void 0;
35753
+ return () => {
35754
+ for (const turn of turns) turn.display?.movedOn?.();
35755
+ };
35756
+ }
35397
35757
  /** The chat's session card is its window (`/agent mode card`, not a direct chat): a turn is shown there, with its own Stop. */
35398
35758
  windowed(chatKey) {
35399
35759
  const state = this.enabled ? this.state.attached(chatKey) : null;
@@ -35574,6 +35934,15 @@ var RemoteAgents = class {
35574
35934
  };
35575
35935
 
35576
35936
  // packages/core/src/remote/approvals-command.ts
35937
+ var SUMMARY_MIN = 15;
35938
+ var SUMMARY_MAX3 = 24 * 60;
35939
+ function summaryMinutes(arg) {
35940
+ if (arg === "") return void 0;
35941
+ if (arg === "off" || arg === "0") return 0;
35942
+ if (!/^\d{1,4}$/.test(arg)) return null;
35943
+ const n = Number(arg);
35944
+ return n >= SUMMARY_MIN && n <= SUMMARY_MAX3 ? n : null;
35945
+ }
35577
35946
  var TerminalApprovalsCommand = class {
35578
35947
  constructor(claw) {
35579
35948
  this.claw = claw;
@@ -35586,6 +35955,8 @@ var TerminalApprovalsCommand = class {
35586
35955
  const arg = args.trim().toLowerCase();
35587
35956
  const one = /^(mute|unmute)\s+#?(\d{1,9})$/.exec(arg);
35588
35957
  if (one) return this.mute(route, one[1] === "mute", Number(one[2]));
35958
+ const [word2, ...rest] = arg.split(/\s+/u);
35959
+ if (word2 === "summary") return this.summary(route, rest.join(" "));
35589
35960
  if (arg !== "" && arg !== "on" && arg !== "off") {
35590
35961
  await say3(words3.approvalsUsage);
35591
35962
  return true;
@@ -35602,6 +35973,31 @@ var TerminalApprovalsCommand = class {
35602
35973
  }
35603
35974
  return true;
35604
35975
  }
35976
+ async summary(route, arg) {
35977
+ const words3 = terminalApprovalText.in(route.lang());
35978
+ const say3 = (text9) => route.conversation.send(textMessage(text9));
35979
+ const minutes = summaryMinutes(arg);
35980
+ if (minutes === null) {
35981
+ await say3(words3.summaryUsage);
35982
+ return true;
35983
+ }
35984
+ try {
35985
+ const every = minutes === void 0 ? await this.claw.summary(route.credential) : await this.claw.setSummary(route.credential, minutes);
35986
+ if (minutes === void 0)
35987
+ await say3(every === 0 ? words3.summaryNever : words3.summaryEvery({ minutes: String(every) }));
35988
+ else await say3(every === 0 ? words3.summaryOff : words3.summarySet({ minutes: String(every) }));
35989
+ } catch (error) {
35990
+ await say3(this.refusal(error, words3));
35991
+ }
35992
+ return true;
35993
+ }
35994
+ /** What to say when Claw refused or could not be reached; anything else is not this command's to answer. */
35995
+ refusal(error, words3) {
35996
+ if (error instanceof ClawError && error.status === 400) return words3.summaryUsage;
35997
+ if (error instanceof ClawError || error instanceof ClawAnswerInvalid || isTransport2(error))
35998
+ return words3.approvalsUnavailable;
35999
+ throw error;
36000
+ }
35605
36001
  async mute(route, muted2, item) {
35606
36002
  const words3 = terminalApprovalText.in(route.lang());
35607
36003
  const say3 = (text9) => route.conversation.send(textMessage(text9));
@@ -35905,6 +36301,7 @@ export {
35905
36301
  TERMINAL_ASKS,
35906
36302
  TERMINAL_HOOK_COMMANDS,
35907
36303
  TERMINAL_SESSION_LIMITS,
36304
+ TERMINAL_SUMMARY,
35908
36305
  THUMB_COMMENT_MAX,
35909
36306
  TITLE_ID,
35910
36307
  TOKEN,
@@ -36040,6 +36437,7 @@ export {
36040
36437
  insertLinks,
36041
36438
  integrationRegistry,
36042
36439
  intentPrompt,
36440
+ isAgentsSlip,
36043
36441
  isAlnum,
36044
36442
  isApiKey,
36045
36443
  isAsciiAlpha,
@@ -36161,6 +36559,7 @@ export {
36161
36559
  parseStartedReviews,
36162
36560
  parseTerminalMute,
36163
36561
  parseTerminalSessionOpen,
36562
+ parseTerminalSummarySetting,
36164
36563
  parseTimezone,
36165
36564
  parseWorkItem,
36166
36565
  parseWorkspacesReport,
@@ -36172,6 +36571,7 @@ export {
36172
36571
  plainLine,
36173
36572
  plainText,
36174
36573
  pointAt,
36574
+ postingAfter,
36175
36575
  prShortPattern,
36176
36576
  prUrlPattern,
36177
36577
  proactiveLines,
@@ -36284,6 +36684,7 @@ export {
36284
36684
  toolOf,
36285
36685
  turn_exports as turn,
36286
36686
  turnApprovals,
36687
+ turnAsksPerson,
36287
36688
  turnIdOf,
36288
36689
  two,
36289
36690
  typedAnswerText,