@primusclaw/personal-agent 0.10.1 → 0.10.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -13831,11 +13831,7 @@ var GroupRemote = class {
13831
13831
  return true;
13832
13832
  }
13833
13833
  if (!choice && parseCommand(words3.text) !== null) return false;
13834
- let quote = words3.quote;
13835
- if (remote.windowMode(bound.id) === "card") {
13836
- if (!remote.quotesWindow(bound.id, message)) return false;
13837
- quote = "";
13838
- }
13834
+ const quote = remote.quotesWindow(bound.id, message) ? "" : words3.quote;
13839
13835
  const prompt = this.ctx.deps.messageText.withQuote(words3.sent, quote);
13840
13836
  const files = await this.text.attachments(message, chat, true);
13841
13837
  if (!prompt) return files.length > 0;
@@ -14711,7 +14707,9 @@ var GroupRouter = class {
14711
14707
  return;
14712
14708
  }
14713
14709
  const handler = this.ctx.deps.handlers.clicks.find((h) => h.verbs.includes(action.verb));
14714
- if (handler?.inGroup !== void 0) await handler.inGroup(this.ctx.clickRoute(action, chat));
14710
+ if (handler?.inGroup === void 0) return;
14711
+ const groupCredential = () => this.ctx.credentials.credential(chat, false);
14712
+ await handler.inGroup({ ...this.ctx.clickRoute(action, chat), groupCredential });
14715
14713
  }
14716
14714
  words(message) {
14717
14715
  const text8 = this.text.textOf(message, true);
@@ -28059,6 +28057,7 @@ var remoteWindowText = defineCatalog({
28059
28057
  sentFromCard: "You sent from the card: ",
28060
28058
  chatBoxCard: (p) => `What you type in the chat box goes to ${p.bot}; to write to this session use the box on this card, or reply quoting this card. To send the chat box to the session instead: /agent mode chat`,
28061
28059
  chatBoxChat: (p) => `What you type goes to this session; messages that start with @${p.bot}, ${p.bot}'s / commands and requests sent on your behalf stay with ${p.bot}. To keep the chat box for ${p.bot}: /agent mode card`,
28060
+ chatBoxGroup: (p) => `In this group, what you say to @${p.bot} goes to this session (other members still talk to ${p.bot}); the box on this card goes there too. To talk to ${p.bot} again, press Back to assistant or say "@${p.bot} back to the assistant".`,
28062
28061
  thisChatToo: " (this chat too, from now on)",
28063
28062
  modeSetCard: (p) => `Done: while a chat is attached, the chat box stays with ${p.bot} and the session card's box goes to the session${p.now}.`,
28064
28063
  modeSetChat: (p) => `Done: while a chat is attached, what you type goes to the session${p.now}. Messages that start with @${p.bot} still come to me.`
@@ -28069,6 +28068,7 @@ var remoteWindowText = defineCatalog({
28069
28068
  sentFromCard: "\u4F60\u4ECE\u5361\u7247\u53D1\u7684\uFF1A",
28070
28069
  chatBoxCard: (p) => `\u5728\u804A\u5929\u6846\u91CC\u6253\u5B57\u662F\u8DDF ${p.bot} \u8BF4\uFF1B\u53D1\u7ED9\u8FD9\u4E2A\u4F1A\u8BDD\u8BF7\u7528\u5361\u7247\u4E0A\u7684\u8F93\u5165\u6846\uFF0C\u6216\u5F15\u7528\u56DE\u590D\u8FD9\u5F20\u5361\u7247\u3002\u60F3\u8BA9\u804A\u5929\u6846\u76F4\u63A5\u53D1\u7ED9\u4F1A\u8BDD\uFF1A/agent mode chat`,
28071
28070
  chatBoxChat: (p) => `\u804A\u5929\u6846\u91CC\u6253\u7684\u5B57\u90FD\u53D1\u7ED9\u8FD9\u4E2A\u4F1A\u8BDD\uFF1B\u4EE5 @${p.bot} \u5F00\u5934\u7684\u6D88\u606F\u3001${p.bot} \u7684 / \u547D\u4EE4\u548C\u534F\u8C03\u8005\u4EE3\u53D1\u7684\u8BF7\u6C42\u4ECD\u7531 ${p.bot} \u5904\u7406\u3002\u60F3\u8BA9\u804A\u5929\u6846\u7559\u7ED9 ${p.bot}\uFF1A/agent mode card`,
28071
+ chatBoxGroup: (p) => `\u5728\u8FD9\u4E2A\u7FA4\u91CC\u4F60 @${p.bot} \u8BF4\u7684\u8BDD\u90FD\u53D1\u7ED9\u8FD9\u4E2A\u4F1A\u8BDD\uFF08\u5176\u4ED6\u4EBA @${p.bot} \u4ECD\u662F\u8DDF ${p.bot} \u8BF4\uFF09\uFF0C\u5361\u7247\u4E0A\u7684\u8F93\u5165\u6846\u4E5F\u53D1\u7ED9\u5B83\u3002\u60F3\u56DE\u5230 ${p.bot}\uFF1A\u70B9\u300C\u56DE\u5230\u52A9\u7406\u300D\uFF0C\u6216\u8BF4\u300C@${p.bot} \u56DE\u5230\u52A9\u7406\u300D\u3002`,
28072
28072
  thisChatToo: "\uFF08\u8FD9\u4E2A\u804A\u5929\u73B0\u5728\u5C31\u6309\u8FD9\u4E2A\u6765\uFF09",
28073
28073
  modeSetCard: (p) => `\u597D\u7684\uFF1A\u63A5\u5165\u4F1A\u8BDD\u540E\uFF0C\u804A\u5929\u6846\u7559\u7ED9 ${p.bot}\uFF0C\u53D1\u7ED9\u4F1A\u8BDD\u7528\u4F1A\u8BDD\u5361\u7247\u4E0A\u7684\u8F93\u5165\u6846${p.now}\u3002`,
28074
28074
  modeSetChat: (p) => `\u597D\u7684\uFF1A\u63A5\u5165\u4F1A\u8BDD\u540E\uFF0C\u804A\u5929\u6846\u91CC\u6253\u7684\u5B57\u90FD\u53D1\u7ED9\u4F1A\u8BDD${p.now}\u3002\u4EE5 @${p.bot} \u5F00\u5934\u7684\u4ECD\u7136\u7ED9\u6211\u3002`
@@ -28120,6 +28120,7 @@ function sentLabel(source, lang) {
28120
28120
  }
28121
28121
  function chatBoxLine(window, lang, bot) {
28122
28122
  const words3 = remoteWindowText.in(lang);
28123
+ if (window === "group") return words3.chatBoxGroup({ bot });
28123
28124
  return window === "card" ? words3.chatBoxCard({ bot }) : words3.chatBoxChat({ bot });
28124
28125
  }
28125
28126
  function modeSetLine(window, lang, attached, bot) {
@@ -28327,12 +28328,12 @@ function actionsOf(input) {
28327
28328
  const words3 = remoteWindowCardText.in(input.lang);
28328
28329
  const session = { session_id: input.sessionId };
28329
28330
  const back = remoteButton(words3.back, "detach", null, session);
28330
- const switchTo = remoteButton(words3.switch, "switch", null, session);
28331
+ const switchTo = input.group ? [] : [remoteButton(words3.switch, "switch", null, session)];
28331
28332
  if (input.phase === "watching") {
28332
28333
  return [
28333
28334
  back,
28334
- switchTo,
28335
- ...input.takeover ? [remoteButton(words3.takeOver, "takeover", null, input.takeover)] : []
28335
+ ...switchTo,
28336
+ ...input.takeover && !input.group ? [remoteButton(words3.takeOver, "takeover", null, input.takeover)] : []
28336
28337
  ];
28337
28338
  }
28338
28339
  const send = takesInput(input.phase) ? [remoteButton(words3.send, "send", "positive", session)] : [];
@@ -28340,7 +28341,7 @@ function actionsOf(input) {
28340
28341
  ...send,
28341
28342
  remoteButton(input.terminal ? words3.stopTerminal : words3.stop, "stop", null, session),
28342
28343
  back,
28343
- switchTo
28344
+ ...switchTo
28344
28345
  ];
28345
28346
  }
28346
28347
  function windowView(input) {
@@ -28361,7 +28362,7 @@ function windowView(input) {
28361
28362
  note: input.view.note ? lit(input.view.note, 300) : null,
28362
28363
  ...approvalsOf(input),
28363
28364
  ...boxOf(input),
28364
- chatBox: chatBoxLine("card", input.lang, input.bot),
28365
+ chatBox: chatBoxLine(input.group ? "group" : "card", input.lang, input.bot),
28365
28366
  updated: words3.updated({ stamp: utcClock(input.at) }),
28366
28367
  actions: actionsOf(input),
28367
28368
  takesInput: takesInput(input.phase)
@@ -28546,6 +28547,8 @@ var remoteAgentText = defineCatalog({
28546
28547
  whichMachineNone: "Which machine? Use `/agent off NAME`. You have no machine connected.",
28547
28548
  notAttachedCard: "You are not attached to a remote session.",
28548
28549
  otherSessionCard: "That card is for another session. This chat is attached to a different one: use its buttons.",
28550
+ groupNotYours: "Only the person who switched this group to the session can use its card.",
28551
+ groupCardOnly: (p) => `In a group, the session card acts only on its session. To switch to another one, say "@${p.bot} switch to the claude session on MACHINE"; the lists of sessions and machines are in a 1:1 chat with me.`,
28549
28552
  pairHead: "To connect a new machine:",
28550
28553
  pairAbove: " the command is in the message above; run it on that machine.",
28551
28554
  emptySend: "Write in the box first, then press Send.",
@@ -28671,6 +28674,8 @@ var remoteAgentText = defineCatalog({
28671
28674
  whichMachineNone: "Which machine? Use `/agent off NAME`. You have no machine connected.",
28672
28675
  notAttachedCard: "\u4F60\u8FD8\u6CA1\u6709\u63A5\u5165\u8FDC\u7A0B\u4F1A\u8BDD\u3002",
28673
28676
  otherSessionCard: "\u8FD9\u5F20\u5361\u7247\u5C5E\u4E8E\u53E6\u4E00\u4E2A\u4F1A\u8BDD\u3002\u8FD9\u4E2A\u804A\u5929\u63A5\u5165\u7684\u662F\u522B\u7684\u4F1A\u8BDD\uFF1A\u7528\u90A3\u4E2A\u4F1A\u8BDD\u7684\u6309\u94AE\u3002",
28677
+ groupNotYours: "\u53EA\u6709\u628A\u8FD9\u4E2A\u7FA4\u5207\u5230\u8FD9\u4E2A\u4F1A\u8BDD\u7684\u4EBA\u80FD\u7528\u8FD9\u5F20\u5361\u3002",
28678
+ groupCardOnly: (p) => `\u7FA4\u91CC\u7684\u4F1A\u8BDD\u5361\u53EA\u7BA1\u8FD9\u4E00\u4E2A\u4F1A\u8BDD\u3002\u8981\u6362\u4F1A\u8BDD\uFF0C\u5728\u7FA4\u91CC\u8BF4\u300C@${p.bot} \u5207\u5230 \u673A\u5668\u540D \u4E0A\u7684 claude \u4F1A\u8BDD\u300D\uFF1B\u4F1A\u8BDD\u548C\u673A\u5668\u7684\u5217\u8868\u5728\u548C\u6211\u7684 1:1 \u804A\u5929\u91CC\u3002`,
28674
28679
  pairHead: "\u8FDE\u63A5\u65B0\u673A\u5668\uFF1A",
28675
28680
  pairAbove: "\u547D\u4EE4\u5728\u4E0A\u9762\u7684\u6D88\u606F\u91CC\uFF0C\u5728\u90A3\u53F0\u673A\u5668\u4E0A\u8FD0\u884C\u5B83\u3002",
28676
28681
  emptySend: "\u5148\u5728\u8F93\u5165\u6846\u91CC\u5199\u597D\uFF0C\u518D\u6309\u53D1\u9001\u3002",
@@ -31889,8 +31894,16 @@ var SessionClicks = class {
31889
31894
  end(click, card, fallback, announce = true) {
31890
31895
  return click.settle(card, { ...fallback ? { fallback } : {}, announce });
31891
31896
  }
31892
- /** End a tap with the card it came from again (the sessions card, or the agents card), `lead` on top. */
31897
+ /**
31898
+ * End a tap with the card it came from again (the sessions card, or the agents card), `lead` on top. In a group the lists are
31899
+ * never shown (they are the presser's own sessions and machines): the tap ends with its line alone.
31900
+ */
31893
31901
  async home(click, lead) {
31902
+ if (isGroupKey(click.chatKey)) {
31903
+ const bot = this.p.ctx.settings.botName;
31904
+ await this.end(click, lead || remoteAgentText.in(this.lang(click)).groupCardOnly({ bot }));
31905
+ return;
31906
+ }
31894
31907
  let view7;
31895
31908
  try {
31896
31909
  if (click.data["view"] === "sessions")
@@ -31952,7 +31965,8 @@ var SessionClicks = class {
31952
31965
  async back(click, lead) {
31953
31966
  const state = this.p.state.attached(click.chatKey);
31954
31967
  const op = textOf6(click.data["op"]);
31955
- if (state !== null && ["detach", "mode", "set_mode", "row", "stop"].includes(op) && state.sessionId === click.data["session_id"]) {
31968
+ if (state !== null && (["detach", "mode", "set_mode", "row", "stop"].includes(op) || isGroupKey(click.chatKey)) && // (a group: never the list)
31969
+ state.sessionId === click.data["session_id"]) {
31956
31970
  await this.end(click, (await this.p.ops.rowCard(click.chatKey, click.key, state, lead)).message, lead);
31957
31971
  return;
31958
31972
  }
@@ -33587,6 +33601,7 @@ var WindowTurn = class {
33587
33601
  var HANDED_OVER_MAX = 3500;
33588
33602
 
33589
33603
  // packages/core/src/remote/remote-agents.ts
33604
+ var GROUP_OPS = /* @__PURE__ */ new Set(["send", "stop", "detach", "mode", "set_mode", "row", "full", "attach"]);
33590
33605
  var CHAT_CONTEXT_WATCH_SECONDS = 2;
33591
33606
  var RemoteAgents = class {
33592
33607
  chats = new ChatRegistry();
@@ -33819,9 +33834,71 @@ var RemoteAgents = class {
33819
33834
  get clickHandler() {
33820
33835
  return {
33821
33836
  verbs: ["remote", "remote_decision", "remote_off"],
33822
- withCredential: (click, credential2) => this.onClick(click, credential2)
33837
+ withCredential: (click, credential2) => this.onClick(click, credential2),
33838
+ inGroup: (click) => this.onGroupClick(click)
33823
33839
  };
33824
33840
  }
33841
+ /**
33842
+ * A tap on a group's session card (the binding of the presser in that group, keyed as its messages are). Only the binder's own
33843
+ * card answers, and only for what acts on the bound session; the lists of sessions and machines stay in a 1:1 chat. A press
33844
+ * on someone else's card leaves it as it was and says whose it is. False: not a button a group answers (the router's note).
33845
+ */
33846
+ async onGroupClick(route) {
33847
+ if (!this.enabled || route.action.data["primusclaw"] !== "remote") return false;
33848
+ const chatKey = groupChatKey(route.sender.id, route.scope);
33849
+ const data = route.action.data;
33850
+ const op = typeof data["op"] === "string" ? data["op"] : "";
33851
+ if (await this.groupRefused(route, chatKey, op)) return true;
33852
+ const credential2 = route.groupCredential === void 0 ? void 0 : await route.groupCredential();
33853
+ if (!credential2) {
33854
+ await route.settle(routingText.in(this.state.lang(chatKey)).notConnected);
33855
+ return true;
33856
+ }
33857
+ await this.tap({
33858
+ chatKey,
33859
+ key: credential2,
33860
+ provider: void 0,
33861
+ to: route.conversation,
33862
+ tapped: route.action.cardMessageId,
33863
+ data,
33864
+ id: route.action.id,
33865
+ settle: (card, options) => route.settle(card, options)
33866
+ });
33867
+ return true;
33868
+ }
33869
+ /** A group tap that is not the binder's own, or not one a group's card may make: answered here (true), before any key is read. */
33870
+ async groupRefused(route, chatKey, op) {
33871
+ const data = route.action.data;
33872
+ const tapped = route.action.cardMessageId;
33873
+ const words3 = remoteAgentText.in(this.state.lang(chatKey));
33874
+ const state = this.state.attached(chatKey);
33875
+ const own3 = op === "attach" ? tapped !== "" && this.ctx.remoteState.getRemote(chatKey)?.statusCard === tapped : state !== null && state.sessionId === data["session_id"] && data["view"] !== "agents";
33876
+ if (!own3) {
33877
+ const owner = this.ownerOf(route.scope, tapped, chatKey);
33878
+ if (owner !== null) {
33879
+ const card = this.board.statusOf(owner.chatKey, owner.state, this.state.phase(owner.chatKey));
33880
+ await route.settle(card.message, { fallback: words3.groupNotYours });
33881
+ } else await route.settle(state === null ? words3.notAttachedCard : words3.otherSessionCard);
33882
+ return true;
33883
+ }
33884
+ if (GROUP_OPS.has(op)) return false;
33885
+ const line2 = words3.groupCardOnly({ bot: this.ctx.settings.botName });
33886
+ if (state === null) await route.settle(line2);
33887
+ else await route.settle(this.board.statusOf(chatKey, state, this.state.phase(chatKey)).message, { fallback: line2 });
33888
+ return true;
33889
+ }
33890
+ /** The binding in group `scope` whose card `tapped` is, when it is not `presser`'s (null: nobody's now). */
33891
+ ownerOf(scope, tapped, presser) {
33892
+ if (!tapped) return null;
33893
+ for (const chatKey of this.ctx.remoteState.remoteAttachedUsers()) {
33894
+ if (chatKey === presser || chatKey !== groupChatKey(personOf2(chatKey), scope)) continue;
33895
+ const stored2 = this.ctx.remoteState.getRemote(chatKey);
33896
+ const state = this.state.attached(chatKey);
33897
+ if (stored2 === null || state === null) continue;
33898
+ if (stored2.statusCard === tapped || stored2.windowCards.includes(tapped)) return { chatKey, state };
33899
+ }
33900
+ return null;
33901
+ }
33825
33902
  async onClick(route, credential2) {
33826
33903
  const kind = route.action.data["primusclaw"];
33827
33904
  const click = {
@@ -198,6 +198,10 @@ export declare const remoteAgentText: import("./catalog.js").Catalog<{
198
198
  whichMachineNone: string;
199
199
  notAttachedCard: string;
200
200
  otherSessionCard: string;
201
+ groupNotYours: string;
202
+ groupCardOnly: (p: {
203
+ bot: string;
204
+ }) => string;
201
205
  pairHead: string;
202
206
  pairAbove: string;
203
207
  emptySend: string;
@@ -9,6 +9,9 @@ export declare const remoteWindowText: import("./catalog.js").Catalog<{
9
9
  chatBoxChat: (p: {
10
10
  bot: string;
11
11
  }) => string;
12
+ chatBoxGroup: (p: {
13
+ bot: string;
14
+ }) => string;
12
15
  thisChatToo: string;
13
16
  modeSetCard: (p: {
14
17
  bot: string;
@@ -46,6 +46,11 @@ export interface ClickRoute extends RouteBase {
46
46
  * edit once the outcome was said.
47
47
  */
48
48
  settle(card: OutMessage | string, options?: SettleOptions): Promise<boolean>;
49
+ /**
50
+ * In a group chat: the presser's credential, read as their @-messages in that group read it (undefined: none, or not just
51
+ * now). Read only when needed; never asks the person to connect. Absent in a 1:1 chat (`withCredential` is given it).
52
+ */
53
+ readonly groupCredential?: () => Promise<string | undefined>;
49
54
  }
50
55
  /** A message read before the router's own reading of it. */
51
56
  export interface MessageInterceptor {
@@ -26,7 +26,10 @@ export declare class SessionClicks {
26
26
  constructor(p: CommandParts, commands: AgentCommands, prompts: Prompts);
27
27
  lang(click: Click): Lang;
28
28
  end(click: Click, card: OutMessage | string, fallback?: string, announce?: boolean): Promise<boolean>;
29
- /** End a tap with the card it came from again (the sessions card, or the agents card), `lead` on top. */
29
+ /**
30
+ * End a tap with the card it came from again (the sessions card, or the agents card), `lead` on top. In a group the lists are
31
+ * never shown (they are the presser's own sessions and machines): the tap ends with its line alone.
32
+ */
30
33
  home(click: Click, lead: string): Promise<void>;
31
34
  /**
32
35
  * A tap on the agents card (or the sessions card) that leaves the chat where it is ends with that card again, sent as a NEW
@@ -75,6 +75,16 @@ export declare class RemoteAgents implements RemoteChat {
75
75
  cancelAll(): void;
76
76
  /** The click handler of the remote-agent cards: the agents and sessions cards, the status card, approvals, disconnect. */
77
77
  get clickHandler(): ClickHandler;
78
+ /**
79
+ * A tap on a group's session card (the binding of the presser in that group, keyed as its messages are). Only the binder's own
80
+ * card answers, and only for what acts on the bound session; the lists of sessions and machines stay in a 1:1 chat. A press
81
+ * on someone else's card leaves it as it was and says whose it is. False: not a button a group answers (the router's note).
82
+ */
83
+ private onGroupClick;
84
+ /** A group tap that is not the binder's own, or not one a group's card may make: answered here (true), before any key is read. */
85
+ private groupRefused;
86
+ /** The binding in group `scope` whose card `tapped` is, when it is not `presser`'s (null: nobody's now). */
87
+ private ownerOf;
78
88
  private onClick;
79
89
  /** A click on an option of a permission card (on the session card, the window stays the card). */
80
90
  private decide;
@@ -10,7 +10,8 @@ export interface GroupWords {
10
10
  /**
11
11
  * A group chat bound to one of the sender's agent sessions (one group, one session at a time; the Python
12
12
  * `Agent._group_remote`). "切到 X 上的 claude" (`/agent attach REF`) binds the group for the sender, "回到助理"
13
- * (`/agent detach`) unbinds it; while bound, the sender's @-messages go to that session and "停掉它" stops its turn. The
13
+ * (`/agent detach`) unbinds it; while bound, the sender's @-messages go to that session (whether the session card is the
14
+ * window or not) and "停掉它" stops its turn. The
14
15
  * binding is the sender's own: another member's message is never read by it. False: not a message about the binding.
15
16
  */
16
17
  export declare class GroupRemote {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primusclaw/personal-agent",
3
- "version": "0.10.1",
3
+ "version": "0.10.2",
4
4
  "description": "The personal agent's channel-neutral core: domain logic, ports and plugin interfaces.",
5
5
  "license": "MIT",
6
6
  "repository": {