@primusclaw/personal-agent 0.10.4 → 0.11.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
@@ -515,6 +515,7 @@ var MAX_HELD_PER_USER = 100;
515
515
  var HELD_TTL_SECONDS = 7 * DAY;
516
516
  var APPROVAL_TTL_SECONDS = 7 * DAY;
517
517
  var ACTING_SESSION_KEEP_SECONDS = 30 * DAY;
518
+ var REVIEW_ONBOARDING_KEEP_SECONDS = 7 * DAY;
518
519
  var RECENT_REPOS = 5;
519
520
  var PENDING_REPO_TTL_SECONDS = DAY;
520
521
  var SESSION_LIST = 5;
@@ -3129,9 +3130,9 @@ function mentionId(mention) {
3129
3130
  function keysOfWho(who, mentions) {
3130
3131
  const refs = markerIndexes(who).filter((i) => i < mentions.length);
3131
3132
  const named2 = refs.map((r) => mentions[r]?.name ?? "");
3132
- const names2 = named2.length ? named2 : [withoutMarkers(who)];
3133
+ const names3 = named2.length ? named2 : [withoutMarkers(who)];
3133
3134
  const keys2 = new Set(refs.map((r) => `id:${mentionId(mentions[r])}`));
3134
- for (const n of names2) {
3135
+ for (const n of names3) {
3135
3136
  if (tokens(n).length) keys2.add(`w:${sortedCp(tokens(withoutParens(n))).join("")}`);
3136
3137
  if (flat(n)) keys2.add(`f:${flat(withoutParens(n))}`);
3137
3138
  }
@@ -4079,6 +4080,7 @@ var assistantCardText = defineCatalog({
4079
4080
  confirmTitle: "Please confirm",
4080
4081
  confirm: "Confirm",
4081
4082
  deny: "Don't",
4083
+ denyMerge: "Don't merge",
4082
4084
  boardTitle: "Your tasks",
4083
4085
  boardWaiting: (p) => `${String(p.n)} waiting for you`,
4084
4086
  boardNothing: "Nothing waits for you",
@@ -4127,6 +4129,7 @@ var assistantCardText = defineCatalog({
4127
4129
  confirmTitle: "\u9700\u8981\u4F60\u786E\u8BA4",
4128
4130
  confirm: "\u786E\u8BA4",
4129
4131
  deny: "\u4E0D\u8981",
4132
+ denyMerge: "\u4E0D\u5408",
4130
4133
  boardTitle: "\u4F60\u7684\u4E8B\u9879",
4131
4134
  boardWaiting: (p) => `${String(p.n)} \u4EF6\u7B49\u4F60\u5904\u7406`,
4132
4135
  boardNothing: "\u6CA1\u6709\u7B49\u4F60\u5904\u7406\u7684\u4E8B",
@@ -5275,6 +5278,31 @@ var isCount = (v) => typeof v === "number" && Number.isSafeInteger(v) && v >= 0;
5275
5278
  function parseRemoteId(v) {
5276
5279
  return typeof v === "string" && UUID_RE.test(v) ? v.toLowerCase() : null;
5277
5280
  }
5281
+ var REMOTE_OUTBOX_REPORT_MAX_SESSIONS = 20;
5282
+ var OUTBOX_MAX_MS = 864e5;
5283
+ var OUTBOX_ERROR_RE = /^(?:http_[1-5]\d\d|network|error)$/;
5284
+ function parseOutboxReport(raw) {
5285
+ if (!isObject(raw)) return null;
5286
+ const { pending, oldest_age_ms: oldest, failures, failing_ms: failing, last_error: lastError, sessions } = raw;
5287
+ if (!isCount(pending) || !isCount(oldest) || !isCount(failures) || !isCount(failing)) return null;
5288
+ const out = [];
5289
+ if (Array.isArray(sessions)) {
5290
+ for (const s of sessions.slice(0, REMOTE_OUTBOX_REPORT_MAX_SESSIONS)) {
5291
+ if (!isObject(s)) continue;
5292
+ const sid = parseRemoteId(s.session_id);
5293
+ if (!sid || !isCount(s.pending) || !isCount(s.oldest_age_ms)) continue;
5294
+ out.push({ sessionId: sid, pending: s.pending, oldestAgeMs: Math.min(s.oldest_age_ms, OUTBOX_MAX_MS) });
5295
+ }
5296
+ }
5297
+ return {
5298
+ pending,
5299
+ oldestAgeMs: Math.min(oldest, OUTBOX_MAX_MS),
5300
+ failures,
5301
+ failingMs: Math.min(failing, OUTBOX_MAX_MS),
5302
+ lastError: typeof lastError === "string" && OUTBOX_ERROR_RE.test(lastError) ? lastError : null,
5303
+ sessions: out
5304
+ };
5305
+ }
5278
5306
  function parseVersion(v) {
5279
5307
  if (v === void 0 || v === null) return { ok: true, value: null };
5280
5308
  if (typeof v !== "string" || v.length > 64 || !NAME_RE.test(v)) return fail("invalid_version");
@@ -5316,7 +5344,7 @@ function parseHeartbeat(body) {
5316
5344
  if (!isCount(body.cmd_cursor)) return fail("invalid_cmd_cursor");
5317
5345
  cmdCursor = body.cmd_cursor;
5318
5346
  }
5319
- return { ok: true, value: { version, agents, cmdCursor } };
5347
+ return { ok: true, value: { version, agents, cmdCursor, outbox: parseOutboxReport(body.outbox) } };
5320
5348
  }
5321
5349
  function parseEventBatch(body) {
5322
5350
  if (!isObject(body)) return fail("body_required");
@@ -11244,15 +11272,15 @@ function categoryBlocks(lang, chat, values) {
11244
11272
  function oneToOneBlock(lang, chat, bot) {
11245
11273
  const zh = lang === "zh";
11246
11274
  const oneToOne = { ...chat, group: false, understanding: false };
11247
- const names2 = [];
11275
+ const names3 = [];
11248
11276
  const items = CAPABILITIES.filter((c) => c.where === "dm" && (zh ? c.dmZh : c.dmEn) !== "" && shown(c, oneToOne));
11249
11277
  for (const c of [...items.filter((c2) => c2.category === "remote"), ...items.filter((c2) => c2.category !== "remote")]) {
11250
11278
  const name = zh ? c.dmZh : c.dmEn;
11251
- if (!names2.includes(name)) names2.push(name);
11279
+ if (!names3.includes(name)) names3.push(name);
11252
11280
  }
11253
- if (names2.length === 0) return void 0;
11281
+ if (names3.length === 0) return void 0;
11254
11282
  const lines = [zh ? "**\u79C1\u804A\u6211\u8FD8\u53EF\u4EE5**" : "**More in a 1:1 chat with me**"];
11255
- for (const name of names2) lines.push(`- ${name}`);
11283
+ for (const name of names3) lines.push(`- ${name}`);
11256
11284
  lines.push(
11257
11285
  zh ? `\u8FD9\u4E9B\u5728\u548C\u6211\u7684 1:1 \u804A\u5929\u91CC\u7528\uFF1A\u70B9 ${bot} \u7684\u540D\u5B57\uFF0C\u53D1\u8D77\u79C1\u804A\u5C31\u884C\u3002` : `These are in a 1:1 chat with me: select ${bot}'s name and start a chat.`
11258
11286
  );
@@ -12757,13 +12785,13 @@ var AccountCommands = class {
12757
12785
  const { store, github } = this.ctx.deps;
12758
12786
  const prefs = store.prefs.getPrefs(chat.sender.id);
12759
12787
  const [on, off] = zh ? ["\u5F00", "\u5173"] : ["on", "off"];
12760
- const names2 = LANG_NAMES[chat.lang()];
12788
+ const names3 = LANG_NAMES[chat.lang()];
12761
12789
  const how = langHow(prefs.langSet, prefs.lang !== "", zh, chat.conversation.caps.shortName);
12762
12790
  const values = {
12763
12791
  timezone: prefs.timezone,
12764
12792
  quiet: prefs.quietEnabled ? `${prefs.quietStart}-${prefs.quietEnd}` : off,
12765
12793
  brief: prefs.briefTriggerId ? on : off,
12766
- lang: names2[zh ? 0 : 1] + how
12794
+ lang: names3[zh ? 0 : 1] + how
12767
12795
  };
12768
12796
  if (prefs.pausedUntil !== null && store.now() < prefs.pausedUntil) values["pause"] = zh ? "\u6682\u505C\u4E2D" : "paused";
12769
12797
  if (key) values["account"] = zh ? "\u5DF2\u8FDE\u63A5" : "connected";
@@ -16815,7 +16843,7 @@ var AssistantActions = class {
16815
16843
  }
16816
16844
  /** Nothing was answered: the card comes back with `note`, and pressing it again can help. */
16817
16845
  async again(click, card, note) {
16818
- const model = { text: note, cardId: card.cardId, allowLabel: card.label, lang: click.lang() };
16846
+ const model = { text: note, cardId: card.cardId, allowLabel: card.label, kind: card.kind, lang: click.lang() };
16819
16847
  await click.settle(viewMessage2({ name: "confirmWrite", model }), { fallback: note });
16820
16848
  }
16821
16849
  };
@@ -18192,7 +18220,7 @@ ${text8}`;
18192
18220
  held.kind,
18193
18221
  held.allowLabel
18194
18222
  );
18195
- const model = { text: inCard || held.allowLabel, cardId: cardId2, allowLabel: held.allowLabel, lang };
18223
+ const model = { text: inCard || held.allowLabel, cardId: cardId2, allowLabel: held.allowLabel, kind: held.kind, lang };
18196
18224
  return view3({ name: "confirmWrite", model });
18197
18225
  }
18198
18226
  const confirm = confirmActionOf(event, this.deps.exactCommand);
@@ -22539,12 +22567,12 @@ function parseReviewAsk(text8, mentions) {
22539
22567
  function personKeys(who, mentions) {
22540
22568
  const refs = markerIndexes(who).filter((i) => i < mentions.length);
22541
22569
  const ids = new Set(refs.map((r) => mentionId(mentions[r])));
22542
- const names2 = refs.length ? [normName(refs.map((r) => pyStrip(mentions[r]?.name ?? "")).join(" "))] : [normName(bareName(withoutMarkers(who)))];
22570
+ const names3 = refs.length ? [normName(refs.map((r) => pyStrip(mentions[r]?.name ?? "")).join(" "))] : [normName(bareName(withoutMarkers(who)))];
22543
22571
  const keys2 = /* @__PURE__ */ new Set();
22544
- for (const n of names2) {
22572
+ for (const n of names3) {
22545
22573
  for (const v of [n, withoutParens(n)]) if (tokens(v).length) keys2.add(sortedCp(tokens(v)).join(""));
22546
22574
  }
22547
- for (const n of names2) for (const v of [n, withoutParens(n)]) if (flat(v)) keys2.add(flat(v));
22575
+ for (const n of names3) for (const v of [n, withoutParens(n)]) if (flat(v)) keys2.add(flat(v));
22548
22576
  return { ids, names: keys2 };
22549
22577
  }
22550
22578
  function otherReviewers(ask3) {
@@ -22552,8 +22580,8 @@ function otherReviewers(ask3) {
22552
22580
  const others = [];
22553
22581
  for (const who of ask3.again) {
22554
22582
  if (!bareName(who)) continue;
22555
- const { ids, names: names2 } = personKeys(who, ask3.mentions);
22556
- const same2 = ids.size && first.ids.size ? ids.size === first.ids.size && [...ids].every((i) => first.ids.has(i)) : [...names2].some((n) => first.names.has(n));
22583
+ const { ids, names: names3 } = personKeys(who, ask3.mentions);
22584
+ const same2 = ids.size && first.ids.size ? ids.size === first.ids.size && [...ids].every((i) => first.ids.has(i)) : [...names3].some((n) => first.names.has(n));
22557
22585
  if (same2) continue;
22558
22586
  const mentioned = markerIndexes(who).filter((i) => i < ask3.mentions.length).map((i) => ask3.mentions[i]?.name ?? "").join(" ");
22559
22587
  const shown3 = mentioned || pyStrip(withoutMarkers(who));
@@ -22679,6 +22707,16 @@ var GithubAccount = class {
22679
22707
  binding = /* @__PURE__ */ new Map();
22680
22708
  /** Teams user -> the confirmation setting chosen while their binding is made. */
22681
22709
  modeChosen = /* @__PURE__ */ new Map();
22710
+ /** Told after a person connected GitHub or switched their standing authorization (errors are logged, never thrown). */
22711
+ changed;
22712
+ async tellChanged(userId, change) {
22713
+ if (this.changed === void 0) return;
22714
+ try {
22715
+ await this.changed(userId, change);
22716
+ } catch (err2) {
22717
+ this.deps.logger.warn("what waits on a person's GitHub binding could not be told", { error: errorName(err2) });
22718
+ }
22719
+ }
22682
22720
  /** Settles when every device flow started so far has ended (for tests and an orderly stop). */
22683
22721
  async idle() {
22684
22722
  await Promise.all([...this.binding.values()].map((b3) => b3.done));
@@ -22822,11 +22860,12 @@ var GithubAccount = class {
22822
22860
  const written3 = await writeMode(this.deps, sender.id, chosen);
22823
22861
  if (short) {
22824
22862
  await sayQuietly(this.deps, conversation, accountText2.connectedShort(state.login), "github bind");
22825
- return [true, state.login];
22863
+ } else {
22864
+ const [zh, en2] = REVIEW_MODES[chosen];
22865
+ const confirmation = written3 === true ? `${en2} / ${zh}` : written3 === NOT_YET ? NOT_YET_TEXT : accountText2.choiceNotSaved;
22866
+ await sayQuietly(this.deps, conversation, accountText2.connected(state.login, confirmation), "github bind");
22826
22867
  }
22827
- const [zh, en2] = REVIEW_MODES[chosen];
22828
- const confirmation = written3 === true ? `${en2} / ${zh}` : written3 === NOT_YET ? NOT_YET_TEXT : accountText2.choiceNotSaved;
22829
- await sayQuietly(this.deps, conversation, accountText2.connected(state.login, confirmation), "github bind");
22868
+ await this.tellChanged(sender.id, "bound");
22830
22869
  return [true, state.login];
22831
22870
  }
22832
22871
  /** A click on one of the two confirmation settings: the clicker's own binding is the only one changed. */
@@ -22970,6 +23009,7 @@ ${readsLine(connection, known)}` : "";
22970
23009
  return set.error;
22971
23010
  }
22972
23011
  await say2(this.deps, conversation, set.value.delegation ? accountText2.autoMergeOn : accountText2.autoMergeOff);
23012
+ await this.tellChanged(sender.id, set.value.delegation ? "delegation_on" : "delegation_off");
22973
23013
  return void 0;
22974
23014
  }
22975
23015
  };
@@ -23399,10 +23439,10 @@ function activeItemsText(data, who) {
23399
23439
  }
23400
23440
  function modelsAllowedText(data) {
23401
23441
  const models = Array.isArray(data.models) ? data.models : [];
23402
- const names2 = models.flatMap(
23442
+ const names3 = models.flatMap(
23403
23443
  (m) => typeof m === "object" && m !== null && typeof m.name === "string" ? [m.name] : []
23404
23444
  );
23405
- const listed = names2.slice(0, MAX_MODELS_LISTED).map((n) => cpHead(n.replace(/[^A-Za-z0-9._:/-]/gu, ""), 100)).join("\u3001");
23445
+ const listed = names3.slice(0, MAX_MODELS_LISTED).map((n) => cpHead(n.replace(/[^A-Za-z0-9._:/-]/gu, ""), 100)).join("\u3001");
23406
23446
  return `\u6307\u5B9A\u7684\u6A21\u578B\u4E0D\u5728 PrimusClaw \u5141\u8BB8\u7684\u6A21\u578B\u91CC\uFF0C\u6240\u4EE5\u6CA1\u6709\u5F00\u59CB review\u3002${listed ? `\u53EF\u4EE5\u7528\u7684\u6A21\u578B\uFF1A${listed}\u3002` : ""}`;
23407
23447
  }
23408
23448
  function batchRefusal(err2, who, count5, errors) {
@@ -23486,13 +23526,19 @@ function modelChosenNote(review, who, asked3) {
23486
23526
  function mergeLine(reviews, who, merge, auto) {
23487
23527
  if (!merge || !reviews.length) return "";
23488
23528
  const held = reviews.filter((r) => r.mergeHeld);
23489
- if (held.length === reviews.length) return `\u5408\u5165\u8981\u7B49 ${who} \u672C\u4EBA\u786E\u8BA4\uFF0CTA \u786E\u8BA4\u4E4B\u524D\u4E0D\u4F1A\u5408\u5165\u3002`;
23490
- const some = held.length ? `\u5176\u4E2D ${held.map((r) => shortName(r.pull)).join("\u3001")} \u7684\u5408\u5165\u8981\u7B49 ${who} \u672C\u4EBA\u786E\u8BA4\u3002` : "";
23491
- const free = reviews.filter((r) => !r.mergeHeld);
23492
- const byAsker = !auto && free.every((r) => r.item?.mergeByRequester === true);
23493
- const asker = byAsker ? `\u5408\u5165\u4E0D\u7528\u7B49 ${who} \u786E\u8BA4\uFF1A${who} \u6279\u51C6\u540E\uFF0C\u53EA\u8981 CI \u5168\u7EFF\u3001\u6CA1\u6709\u672A\u89E3\u51B3\u7684\u8BC4\u8BBA\uFF0C\u5C31\u4F1A\u81EA\u52A8\u5408\u5165\uFF08${who} \u90A3\u8FB9\u88AB\u62E6\u4E0B\u7684\u5408\u5165\uFF0C\u4F1A\u7528\u4F60\u81EA\u5DF1\u7684 GitHub \u8D26\u53F7\u5408\uFF0C\u524D\u63D0\u662F PR \u662F\u4F60\u63D0\u7684\uFF09\u3002` : "";
23494
- const automatic = auto ? `${who} \u5DF2\u8BBE\u4E3A\u5168\u81EA\u52A8\u5408\u5165\uFF08\u65E0\u9700\u4EBA\u5DE5\u786E\u8BA4\uFF0C\u53EA\u6709\u4ED3\u5E93\u81EA\u5DF1\u8981\u6C42\u786E\u8BA4\u7684\u624D\u4F1A\u95EE TA\uFF09\u3002` : "";
23495
- return automatic + asker + some;
23529
+ const all = held.length === reviews.length;
23530
+ const names3 = held.map((r) => shortName(r.pull)).join("\u3001");
23531
+ const automatic = auto && !all ? `${who} \u5DF2\u8BBE\u4E3A\u5168\u81EA\u52A8\u5408\u5165\uFF08\u65E0\u9700\u4EBA\u5DE5\u786E\u8BA4\uFF0C\u53EA\u6709\u4ED3\u5E93\u81EA\u5DF1\u8981\u6C42\u786E\u8BA4\u7684\u624D\u4F1A\u95EE TA\uFF09\u3002` : "";
23532
+ const askable = reviews.some((r) => r.item?.mergeByRequester === true);
23533
+ if (!held.length && !auto && !askable) return "";
23534
+ if (reviews.every(selfReview)) {
23535
+ if (all) return `\u5408\u5165\u8981\u7B49 ${who} \u672C\u4EBA\u786E\u8BA4\uFF0CTA \u786E\u8BA4\u4E4B\u524D\u4E0D\u4F1A\u5408\u5165\u3002`;
23536
+ return automatic + (held.length ? `\u5176\u4E2D ${names3} \u7684\u5408\u5165\u8981\u7B49 ${who} \u672C\u4EBA\u786E\u8BA4\u3002` : "");
23537
+ }
23538
+ const confirm = all ? `\uFF08${who} \u9700\u8981\u786E\u8BA4\uFF0CTA \u786E\u8BA4\u4E4B\u524D\u4E0D\u4F1A\u5408\u5165\uFF09` : held.length ? `\uFF08\u5176\u4E2D ${names3} \u7684\u5408\u5165 ${who} \u9700\u8981\u786E\u8BA4\uFF09` : "";
23539
+ const byReviewer = `${who} \u6279\u51C6\u540E\uFF0C\u7528 ${who} \u7684\u8D26\u53F7\u5408\u5165${confirm}\u3002`;
23540
+ const asker = askable ? `${who} \u6CA1\u6709\u5408\u5165\u6743\u9650\u65F6\uFF0C\u4F1A\u5148\u95EE\u4F60\u8981\u4E0D\u8981\u7528\u4F60\u81EA\u5DF1\u7684\u8D26\u53F7\u5408\u5165\u3002` : "";
23541
+ return byReviewer + automatic + asker;
23496
23542
  }
23497
23543
 
23498
23544
  // packages/core/src/review/service/confirm.ts
@@ -24656,8 +24702,6 @@ var reviewStartText = {
24656
24702
  unsureWho: (bot) => `\u6211\u4E0D\u786E\u5B9A\u4F60\u8BF7\u7684\u662F\u8C01\uFF0C\u6240\u4EE5\u6CA1\u6709\u5F00\u59CB review\u3002\u8BF7\u5199\u51FA reviewer \u7684\u540D\u5B57\uFF0C\u4F8B\u5982 ${howToAsk(bot)}`,
24657
24703
  unsureWhoFull: (bot) => `\u6211\u4E0D\u786E\u5B9A\u4F60\u8BF7\u7684\u662F\u8C01\uFF0C\u6240\u4EE5\u6CA1\u6709\u5F00\u59CB review\u3002\u8BF7\u5199\u51FA reviewer \u7684\u5168\u540D\uFF0C\u4F8B\u5982 ${howToAsk(bot)}`,
24658
24704
  githubUnknown: (who) => `\u6682\u65F6\u65E0\u6CD5\u786E\u8BA4 ${who} \u7684 GitHub \u7ED1\u5B9A\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5\u3002`,
24659
- notAuthorized: (who, merge) => `${who} \u8FD8\u6CA1\u6709\u6388\u6743\u6211\u4EE3 TA ${merge ? "review \u5408\u5165" : "review"}\uFF08\u9700\u8981 TA \u5728 1:1 \u91CC\u53D1 \`/github auto-merge on\` \u5F00\u542F\u4E00\u6B21\u957F\u671F\u6388\u6743\uFF09\uFF0C\u6211\u4E0D\u4F1A\u52A8\u7528 TA \u7684 GitHub \u8D26\u53F7\uFF0C\u6240\u4EE5\u6CA1\u6709\u5F00\u59CB review\u3002\u8BF7 ${who} \u6388\u6743\u540E\u518D @ \u6211\u4E00\u6B21\u3002`,
24660
- reviewerNotLinked: (who, bot) => `${who} \u8FD8\u6CA1\u6709\u5728 ${bot} \u91CC\u8FDE\u63A5\u81EA\u5DF1\u7684 Primus key\uFF081:1 \u91CC\u53D1 \`/link\`\uFF09\uFF0C\u4EE3 TA review \u8981\u7528 TA \u81EA\u5DF1\u7684\u8D26\u53F7\u548C\u6A21\u578B\u989D\u5EA6\uFF0C\u6240\u4EE5\u6CA1\u6709\u5F00\u59CB review\u3002\u8BF7 ${who} \u5148\u8FDE\u63A5\uFF0C\u7136\u540E\u518D @ \u6211\u4E00\u6B21\u3002`,
24661
24705
  reviewerNotConnected: (who, bot) => `${who} \u8FD8\u6CA1\u6709\u901A\u8FC7 Primus \u8EAB\u4EFD\u670D\u52A1\u8FDE\u63A5 ${bot}\uFF0C\u6211\u6CA1\u6CD5\u4EE5 TA \u7684\u8EAB\u4EFD\u5F00\u59CB\uFF0C\u6240\u4EE5\u6CA1\u6709\u5F00\u59CB review\u3002\u8BF7 ${who} \u5148\u5728 1:1 \u91CC\u5B8C\u6210\u8FDE\u63A5\uFF0C\u7136\u540E\u518D @ \u6211\u4E00\u6B21\u3002`,
24662
24706
  reviewerPlatformDown: (who) => `\u6211\u6682\u65F6\u8054\u7CFB\u4E0D\u4E0A Primus \u5E73\u53F0\uFF0C\u6CA1\u80FD\u786E\u8BA4 ${who} \u7684\u8EAB\u4EFD\uFF0C\u6240\u4EE5\u6CA1\u6709\u5F00\u59CB review\u3002\u8BF7\u7A0D\u540E\u518D @ \u6211\u4E00\u6B21\u3002`,
24663
24707
  modelsUnknown: (whose, model) => `\u6682\u65F6\u6CA1\u6CD5\u5411 PrimusClaw \u786E\u8BA4${whose} key \u80FD\u7528\u54EA\u4E9B\u6A21\u578B\uFF0C\u6240\u4EE5\u6CA1\u6709\u7528 ${model} \u5F00\u59CB review\u3002\u8BF7\u7A0D\u540E\u518D\u8BD5\uFF0C\u6216\u4E0D\u6307\u5B9A\u6A21\u578B\u3002`,
@@ -25089,15 +25133,27 @@ ${how}`;
25089
25133
  }
25090
25134
  /** Sends what `send` says into the person's own chat, at most once a day for this kind; true when they have it. */
25091
25135
  async onceADay(person, via, kind, send) {
25136
+ return await this.onceADayOutcome(person, via, kind, send) !== "failed";
25137
+ }
25138
+ /**
25139
+ * As `onceADay`, telling apart sent now ("sent"), held back because a notice of this kind already went to them today
25140
+ * ("earlier": what that one said may not be this), and not sent ("failed").
25141
+ */
25142
+ async onceADayOutcome(person, via, kind, send) {
25092
25143
  const delegation = this.deps.store.reviewDelegation;
25093
- if (!delegation.claimGithubNotice(person.userId, kind, BIND_NOTICE_SECONDS)) return true;
25094
- const chat = await personalChat(this.deps, person, via);
25144
+ if (!delegation.claimGithubNotice(person.userId, kind, BIND_NOTICE_SECONDS)) return "earlier";
25145
+ if (await this.toPerson(person, via, send)) return "sent";
25146
+ delegation.releaseGithubNotice(person.userId, kind);
25147
+ return "failed";
25148
+ }
25149
+ /** Sends what `send` says into the person's own chat, with no daily limit; true when it went. */
25150
+ async toPerson(person, via, send) {
25095
25151
  try {
25152
+ const chat = await personalChat(this.deps, person, via);
25096
25153
  if (chat === void 0) throw new Error("no 1:1 chat with this person");
25097
25154
  await send(chat);
25098
25155
  } catch (err2) {
25099
25156
  this.deps.logger.warn("the steps for a person a review needs could not be sent", { error: errorName(err2) });
25100
- delegation.releaseGithubNotice(person.userId, kind);
25101
25157
  return false;
25102
25158
  }
25103
25159
  return true;
@@ -25142,6 +25198,500 @@ ${sender.name || "\u6709\u540C\u4E8B"}${group ? "\u5728\u7FA4\u91CC" : ""}\u8BF7
25142
25198
  }
25143
25199
  };
25144
25200
 
25201
+ // packages/core/src/locales/review-onboarding.ts
25202
+ var ONBOARDING_STEPS = ["identity", "bind", "auto_merge", "link"];
25203
+ var STEP_EN = {
25204
+ identity: "Connect your Primus account: press Confirm on the identity service card I sent you",
25205
+ bind: "Connect GitHub: send me `/github bind` here, enter the code it shows on GitHub and approve (the token is kept only in the Primus identity service)",
25206
+ auto_merge: "Allow reviews as you: send me `/github auto-merge on` here, so that I may use your GitHub account when a colleague asks you for a review (`/github auto-merge off` turns it off at any time)",
25207
+ link: "Link your own PrimusClaw key: send me `/link` here (a review asked of you runs on your own model quota)"
25208
+ };
25209
+ var STEP_ZH = {
25210
+ identity: "\u8FDE\u63A5\u4F60\u7684 Primus \u8D26\u53F7\uFF1A\u70B9\u6211\u53D1\u7ED9\u4F60\u7684\u8EAB\u4EFD\u670D\u52A1\u5361\u7247\u4E0A\u7684\u786E\u8BA4",
25211
+ bind: "\u8FDE\u63A5 GitHub\uFF1A\u5728\u8FD9\u91CC\u53D1 `/github bind`\uFF0C\u6309\u63D0\u793A\u5728 GitHub \u8F93\u5165\u9A8C\u8BC1\u7801\u5E76\u6279\u51C6\uFF08\u4EE4\u724C\u53EA\u5B58\u5728 Primus \u8EAB\u4EFD\u670D\u52A1\uFF09",
25212
+ auto_merge: "\u5F00\u542F\u4EE3\u5BA1\u6388\u6743\uFF1A\u5728\u8FD9\u91CC\u53D1 `/github auto-merge on`\uFF0C\u540C\u4E8B\u8BF7\u4F60\u4EE3\u5BA1\u65F6\u6211\u624D\u80FD\u7528\u4F60\u7684 GitHub \u8D26\u53F7\uFF08\u968F\u65F6\u53EF\u4EE5 `/github auto-merge off` \u5173\u95ED\uFF09",
25213
+ link: "\u8FDE\u63A5\u4F60\u81EA\u5DF1\u7684 PrimusClaw key\uFF1A\u5728\u8FD9\u91CC\u53D1 `/link`\uFF08\u4EE3\u5BA1\u7528\u4F60\u81EA\u5DF1\u7684\u6A21\u578B\u989D\u5EA6\uFF09"
25214
+ };
25215
+ var STEP_SHORT = {
25216
+ identity: "\u8FDE\u63A5 Primus \u8D26\u53F7",
25217
+ bind: "\u53D1 `/github bind` \u8FDE\u63A5 GitHub",
25218
+ auto_merge: "\u53D1 `/github auto-merge on` \u5F00\u542F\u4EE3\u5BA1\u6388\u6743",
25219
+ link: "\u53D1 `/link` \u8FDE\u63A5\u81EA\u5DF1\u7684 PrimusClaw key"
25220
+ };
25221
+ function stepsShown(withLink) {
25222
+ return withLink ? ONBOARDING_STEPS : ONBOARDING_STEPS.slice(0, 3);
25223
+ }
25224
+ function checklist(steps, current, zh) {
25225
+ const at = steps.indexOf(current);
25226
+ return steps.map((step, i) => {
25227
+ const mark = i < at ? zh ? "\uFF08\u5DF2\u5B8C\u6210\uFF09" : " (done)" : i === at ? zh ? " \u2190 \u73B0\u5728\u8FD9\u4E00\u6B65" : " <- this step now" : "";
25228
+ return `${String(i + 1)}. ${(zh ? STEP_ZH : STEP_EN)[step]}${mark}`;
25229
+ }).join("\n");
25230
+ }
25231
+ var onboardingText2 = {
25232
+ /** The reviewer's first message: what was asked of them, and every step with the one to do now marked. */
25233
+ first: (asked3, steps, current) => {
25234
+ const n = String(steps.length);
25235
+ const verbEn = asked3.merge ? "review and merge" : "review";
25236
+ const verbZh = asked3.merge ? "review \u5408\u5165" : "review";
25237
+ return `${asked3.asker || "A colleague"} asked me${asked3.group ? " in a group chat" : ""} to ${verbEn} ${asked3.pulls} as you; I have done nothing yet. To allow it there are ${n} steps, and as each is done I tell you the next:
25238
+ ${checklist(steps, current, false)}
25239
+
25240
+ ${asked3.asker || "\u6709\u540C\u4E8B"}${asked3.group ? "\u5728\u7FA4\u91CC" : ""}\u8BF7\u6211\u4EE5\u4F60\u7684\u540D\u4E49 ${verbZh} ${asked3.pulls}\uFF0C\u6211\u8FD8\u4EC0\u4E48\u90FD\u6CA1\u6709\u505A\u3002\u5982\u8981\u5141\u8BB8\uFF0C\u9700\u8981\u5B8C\u6210\u4E0B\u9762 ${n} \u6B65\uFF0C\u6BCF\u5B8C\u6210\u4E00\u6B65\u6211\u4F1A\u544A\u8BC9\u4F60\u4E0B\u4E00\u6B65\uFF1A
25241
+ ${checklist(steps, current, true)}`;
25242
+ },
25243
+ /** A step (or more) was done: the next one, with every step marked. */
25244
+ next: (askers, steps, current) => {
25245
+ const at = String(steps.indexOf(current) + 1);
25246
+ return `Done so far, thank you. Next is step ${at} of ${String(steps.length)}, so that ${askers || "your colleague"} can have me review as you:
25247
+ ${checklist(steps, current, false)}
25248
+
25249
+ \u524D\u9762\u7684\u6B65\u9AA4\u5DF2\u5B8C\u6210\u3002\u4E0B\u4E00\u6B65\u662F\u7B2C ${at} \u6B65\uFF08\u5171 ${String(steps.length)} \u6B65\uFF09\uFF0C\u5B8C\u6210\u540E ${askers || "\u540C\u4E8B"} \u5C31\u80FD\u8BF7\u6211\u4EE5\u4F60\u7684\u540D\u4E49\u4EE3\u5BA1\uFF1A
25250
+ ` + checklist(steps, current, true);
25251
+ },
25252
+ /** Every step is done. */
25253
+ allDone: (askers) => `All steps are done. I told ${askers || "your colleague"} that a review can be asked of you now; nothing starts until they ask again.
25254
+
25255
+ \u5168\u90E8\u5B8C\u6210\u3002\u6211\u5DF2\u544A\u8BC9 ${askers || "\u540C\u4E8B"} \u73B0\u5728\u53EF\u4EE5\u8BF7\u4F60\u4EE3\u5BA1\u4E86\uFF1BTA \u91CD\u65B0\u53D1\u8D77\u4E4B\u524D\u4E0D\u4F1A\u5F00\u59CB\u4EFB\u4F55\u4E8B\u3002`,
25256
+ /** The buttons' card under a step. */
25257
+ bindPrompt: "Connect GitHub now? / \u73B0\u5728\u8FDE\u63A5 GitHub\uFF1F",
25258
+ bindButton: "Connect GitHub / \u8FDE\u63A5 GitHub",
25259
+ autoMergePrompt: "Allow reviews as you now? You can turn it off at any time with `/github auto-merge off`. / \u73B0\u5728\u5F00\u542F\u4EE3\u5BA1\u6388\u6743\uFF1F\u968F\u65F6\u53EF\u4EE5\u7528 `/github auto-merge off` \u5173\u95ED\u3002",
25260
+ autoMergeButton: "Allow / \u5F00\u542F\u4EE3\u5BA1\u6388\u6743",
25261
+ declineButton: "Not now / \u6682\u4E0D\u5F00\u542F",
25262
+ binding: "Connecting GitHub: the code follows. / \u6B63\u5728\u8FDE\u63A5 GitHub\uFF0C\u9A8C\u8BC1\u7801\u89C1\u4E0B\u4E00\u6761\u3002",
25263
+ allowed: "Done. / \u5DF2\u5904\u7406\u3002",
25264
+ declined: "Understood: reviews as you stay off, and the colleague is told. / \u597D\u7684\uFF0C\u4E0D\u5F00\u542F\u4EE3\u5BA1\u6388\u6743\uFF0C\u6211\u4F1A\u544A\u8BC9\u540C\u4E8B\u3002",
25265
+ notYours: "This button is for someone else. / \u8FD9\u4E2A\u6309\u94AE\u4E0D\u662F\u7ED9\u4F60\u7684\u3002",
25266
+ inactive: "This button is no longer active. / \u8FD9\u4E2A\u6309\u94AE\u5DF2\u5931\u6548\u3002",
25267
+ oneToOne: "Please do this in your 1:1 chat with me. / \u8BF7\u5728\u548C\u6211\u7684 1:1 \u804A\u5929\u91CC\u64CD\u4F5C\u3002",
25268
+ /** The asker, where they asked: which step the reviewer has left, and what happens next. */
25269
+ missing: (who, steps, current, sent, group) => {
25270
+ const at = steps.indexOf(current) + 1;
25271
+ const all = steps.map((s, i) => `${String(i + 1)}. ${STEP_SHORT[s]}`).join("\uFF1B");
25272
+ const lead = `${who} \u8FD8\u4E0D\u80FD\u88AB\u6211\u4EE3\u5BA1\uFF1A\u8FD8\u5DEE\u7B2C ${String(at)} \u6B65\u300C${STEP_SHORT[current]}\u300D\uFF08\u5171 ${String(steps.length)} \u6B65\uFF1A${all}\uFF09\uFF0C\u6240\u4EE5\u6CA1\u6709\u5F00\u59CB review\u3002`;
25273
+ const here = group ? "\u8FD9\u4E2A\u7FA4\u91CC" : "\u8FD9\u91CC";
25274
+ return sent ? `${lead}\u6211\u5DF2\u79C1\u4FE1 TA \u8FD9\u51E0\u6B65\uFF1BTA \u6BCF\u5B8C\u6210\u4E00\u6B65\u6211\u4F1A\u63D0\u793A\u4E0B\u4E00\u6B65\uFF0C\u5168\u90E8\u5B8C\u6210\u540E\u6211\u4F1A\u5728${here}\u544A\u8BC9\u4F60\uFF0C\u70B9\u4E00\u4E0B\u5C31\u80FD\u6309\u539F\u8BF7\u6C42\u91CD\u65B0\u53D1\u8D77\u3002` : `${lead}\u6211\u6CA1\u80FD\u79C1\u4FE1 ${who}\uFF1B\u8BF7 ${who} \u5728 1:1 \u91CC\u7ED9\u6211\u53D1\u4EFB\u610F\u4E00\u6761\u6D88\u606F\uFF0C\u6211\u4F1A\u544A\u8BC9 TA \u5269\u4E0B\u7684\u6B65\u9AA4\uFF0C\u5168\u90E8\u5B8C\u6210\u540E\u6211\u4F1A\u5728${here}\u544A\u8BC9\u4F60\u3002`;
25275
+ },
25276
+ /** The asker, where they asked, once every step is done. */
25277
+ ready: (who, pulls, merge) => `${who} \u5DF2\u5B8C\u6210\u6388\u6743\uFF0C\u53EF\u4EE5\u5F00\u59CB\u4EE3\u5BA1\u4E86\u3002\u70B9\u4E0B\u9762\u7684\u6309\u94AE\uFF0C\u6309\u539F\u6765\u7684\u8BF7\u6C42\u91CD\u65B0\u53D1\u8D77\uFF08${pulls}\uFF0C${merge ? "review \u5408\u5165" : "\u53EA review"}\uFF09\u3002`,
25278
+ readyTitle: "\u53EF\u4EE5\u5F00\u59CB\u4EE3\u5BA1\u4E86",
25279
+ retryButton: "\u91CD\u65B0\u53D1\u8D77\u4EE3\u5BA1",
25280
+ retried: (pulls) => `\u5DF2\u6309\u539F\u6765\u7684\u8BF7\u6C42\u91CD\u65B0\u53D1\u8D77\uFF1A${pulls}\u3002`,
25281
+ onlyAsker: "\u53EA\u6709\u53D1\u8D77\u8FD9\u6B21\u4EE3\u5BA1\u7684\u4EBA\u53EF\u4EE5\u91CD\u65B0\u53D1\u8D77\u3002",
25282
+ retryGone: "\u8FD9\u4E2A\u6309\u94AE\u5DF2\u5931\u6548\uFF08\u5DF2\u7528\u8FC7\u6216\u5DF2\u8FC7\u671F\uFF09\uFF0C\u9700\u8981\u7684\u8BDD\u8BF7\u518D\u53D1\u4E00\u6B21\u8BF7\u6C42\u3002",
25283
+ /** The asker, where they asked, when the reviewer said no. */
25284
+ refused: (who, pulls) => `${who} \u9009\u62E9\u6682\u4E0D\u5F00\u542F\u4EE3\u5BA1\u6388\u6743\uFF0C\u6240\u4EE5 ${pulls} \u7684\u4EE3\u5BA1\u4E0D\u4F1A\u5F00\u59CB\u3002\u9700\u8981\u7684\u8BDD\u8BF7\u53E6\u8BF7\u4E00\u4F4D reviewer\u3002`
25285
+ };
25286
+
25287
+ // packages/core/src/review/service/onboarding.ts
25288
+ var ONBOARDING_SWEEP_MS = 6e4;
25289
+ var ONBOARDING_CLICK = "review_onboarding";
25290
+ var HANDOFF_REUSE_SECONDS = 23 * 3600;
25291
+ var RANK = { identity: 1, bind: 2, auto_merge: 3, link: 4, ready: 5 };
25292
+ var str6 = (value) => typeof value === "string" ? value : "";
25293
+ function actorOf(value) {
25294
+ const o = typeof value === "object" && value !== null ? value : {};
25295
+ return { userId: str6(o.userId), name: str6(o.name), channelUserId: str6(o.channelUserId) };
25296
+ }
25297
+ function keptOf(row2) {
25298
+ const r = row2.request;
25299
+ const pulls = Array.isArray(r.pulls) ? r.pulls.flatMap((p) => {
25300
+ const o = typeof p === "object" && p !== null ? p : {};
25301
+ const number = Number(o.number);
25302
+ return str6(o.owner) && str6(o.repo) && Number.isInteger(number) && number > 0 ? [pullRef(str6(o.owner), str6(o.repo), number)] : [];
25303
+ }) : [];
25304
+ const asked3 = r.asked;
25305
+ if (!pulls.length || typeof asked3 !== "object" || asked3 === null || Array.isArray(asked3)) return void 0;
25306
+ return {
25307
+ actor: actorOf(r.actor),
25308
+ requester: actorOf(r.requester),
25309
+ pulls,
25310
+ merge: r.merge === true,
25311
+ models: Array.isArray(r.models) ? r.models.filter((m) => typeof m === "string" && m !== "") : [],
25312
+ note: str6(r.note),
25313
+ handoffId: str6(r.handoffId),
25314
+ askedAt: typeof r.askedAt === "number" ? r.askedAt : 0,
25315
+ asked: asked3,
25316
+ group: r.group === true,
25317
+ where: str6(r.where)
25318
+ };
25319
+ }
25320
+ var names2 = (rows) => [...new Set(rows.map((k) => k.requester.name).filter(Boolean))].join("\u3001");
25321
+ var ReviewerOnboarding = class {
25322
+ constructor(deps, notices, random, retry, github) {
25323
+ this.deps = deps;
25324
+ this.notices = notices;
25325
+ this.random = random;
25326
+ this.retry = retry;
25327
+ this.github = github;
25328
+ }
25329
+ deps;
25330
+ notices;
25331
+ random;
25332
+ retry;
25333
+ github;
25334
+ running = /* @__PURE__ */ new Set();
25335
+ /** Settles when the reads started by messages have ended. For tests. */
25336
+ async idle() {
25337
+ while (this.running.size) await Promise.all([...this.running]);
25338
+ }
25339
+ /** The step this person is to do now for a review asked of them, or undefined when it cannot be read just now. */
25340
+ async progress(userId) {
25341
+ let status;
25342
+ try {
25343
+ status = await this.deps.credentials.status(userId);
25344
+ } catch (err2) {
25345
+ this.deps.logger.info("a reviewer's steps could not be read", { error: errorName(err2) });
25346
+ return void 0;
25347
+ }
25348
+ if (!status.ok) return status.error.kind === "not_bound" ? "identity" : void 0;
25349
+ if (!usable(status.value)) return "bind";
25350
+ if (!status.value.delegation) return "auto_merge";
25351
+ return this.linked(userId) ? "ready" : "link";
25352
+ }
25353
+ linked(userId) {
25354
+ return (this.deps.store.links.getKey(userId) ?? "").startsWith("ak-");
25355
+ }
25356
+ /**
25357
+ * A review for someone else did not start because `step` is theirs to do: kept, the steps sent to them (once a day, the
25358
+ * identity card too while the identity service does not know them), and one line where it was asked naming the step.
25359
+ */
25360
+ async refused(ctx, ask3, actor, pulls, step) {
25361
+ const steps = stepsShown(!this.linked(actor.userId));
25362
+ const asked3 = {
25363
+ asker: ctx.sender.name,
25364
+ group: ctx.group,
25365
+ pulls: pulls.map(shortName).join(", "),
25366
+ merge: ask3.merge
25367
+ };
25368
+ const person = { id: actor.userId, channelUserId: actor.channelUserId, name: actor.name, email: "" };
25369
+ const store = this.deps.store.reviewDelegation;
25370
+ const regressed = this.behind(actor.userId, RANK[step]);
25371
+ const prior = Math.max(0, ...store.openReviewOnboardings(actor.userId).map((o) => o.toldRank));
25372
+ const send = async (chat) => {
25373
+ await say2(this.deps, chat, onboardingText2.first(asked3, steps, step));
25374
+ await this.cardAfterText(chat, person, step);
25375
+ };
25376
+ let sent = prior >= RANK[step];
25377
+ if (!sent) {
25378
+ const outcome = await this.notices.onceADayOutcome(actor, ctx.conversation.ref, "bind", send);
25379
+ sent = outcome === "sent" || outcome === "earlier" && await this.notices.toPerson(actor, ctx.conversation.ref, send);
25380
+ }
25381
+ const request = {
25382
+ actor: { ...actor },
25383
+ requester: { userId: ctx.sender.id, name: ctx.sender.name, channelUserId: ctx.sender.channelUserId },
25384
+ pulls: pulls.map((p) => ({ owner: p.owner, repo: p.repo, number: p.number })),
25385
+ merge: ask3.merge,
25386
+ // (the model the asker named runs the retry too, through the same model checks a new request gets)
25387
+ models: [...ask3.models],
25388
+ note: ctx.text,
25389
+ handoffId: ask3.handoffId,
25390
+ askedAt: epochSeconds(this.deps.clock),
25391
+ asked: ctx.conversation.ref.wire,
25392
+ group: ctx.group,
25393
+ where: ctx.group ? ctx.message.conversationName : ""
25394
+ };
25395
+ store.saveReviewOnboarding({
25396
+ onboardingId: this.random.hexId(),
25397
+ actorId: actor.userId,
25398
+ requesterId: ctx.sender.id,
25399
+ pulls: pulls.map(shortName).join(" "),
25400
+ request,
25401
+ // (not reached: their next message, or the sweep, sends the steps)
25402
+ toldRank: sent ? RANK[step] : prior
25403
+ });
25404
+ if (regressed && sent) store.claimOnboardingStep(actor.userId, RANK[step]);
25405
+ await say2(this.deps, ctx.conversation, onboardingText2.missing(actor.name || "\u5BF9\u65B9", steps, step, sent, ctx.group));
25406
+ }
25407
+ /**
25408
+ * What goes with a step, after its text went: a card that could not be sent is not worth saying the step again for
25409
+ * (the text names what to type), so it is only logged and the step counts as said.
25410
+ */
25411
+ async cardAfterText(chat, person, step) {
25412
+ try {
25413
+ await this.stepCard(chat, person, step);
25414
+ } catch (err2) {
25415
+ this.deps.logger.warn("the card under a reviewer's step could not be sent", { error: errorName(err2) });
25416
+ }
25417
+ }
25418
+ /** What goes with a step: the identity card, or a button that does the step. */
25419
+ async stepCard(chat, person, step) {
25420
+ if (step === "identity") {
25421
+ await this.deps.host.connectIdentity(person, chat, "");
25422
+ return;
25423
+ }
25424
+ const button = (title, op, style) => ({
25425
+ title,
25426
+ verb: `primusclaw.${ONBOARDING_CLICK}`,
25427
+ data: { primusclaw: ONBOARDING_CLICK, op },
25428
+ ...style ? { style } : {}
25429
+ });
25430
+ if (step === "bind")
25431
+ await chat.send(noteMessage({ text: onboardingText2.bindPrompt, buttons: [button(onboardingText2.bindButton, "bind", "positive")] }));
25432
+ else if (step === "auto_merge")
25433
+ await chat.send(
25434
+ noteMessage({
25435
+ text: onboardingText2.autoMergePrompt,
25436
+ buttons: [button(onboardingText2.autoMergeButton, "auto_merge_on", "positive"), button(onboardingText2.declineButton, "decline")]
25437
+ })
25438
+ );
25439
+ }
25440
+ /**
25441
+ * A reviewer who undid a step they had done (`/github unbind`, or an identity service that no longer knows them) is
25442
+ * behind what they were told: each open ask told further than `rank` is put just below it, so the step they are at
25443
+ * now is said again (once, by whoever raises it first). True when any was.
25444
+ */
25445
+ behind(userId, rank) {
25446
+ const store = this.deps.store.reviewDelegation;
25447
+ let any = false;
25448
+ for (const row2 of store.openReviewOnboardings(userId))
25449
+ if (row2.toldRank > rank) {
25450
+ store.releaseOnboardingStep(row2.onboardingId, row2.toldRank, rank - 1);
25451
+ any = true;
25452
+ }
25453
+ return any;
25454
+ }
25455
+ /** A message of this person's: when something waits for them, their state is read again (in the background). */
25456
+ activity(userId) {
25457
+ if (!this.deps.store.reviewDelegation.openReviewOnboardings(userId).length) return;
25458
+ const task = this.advance(userId).catch((err2) => {
25459
+ this.deps.logger.warn("a reviewer's next step could not be sent", { error: errorName(err2) });
25460
+ });
25461
+ this.running.add(task);
25462
+ void task.finally(() => this.running.delete(task));
25463
+ }
25464
+ /** Every reviewer something waits for, read again; every asker still owed a reviewer's no, told. */
25465
+ async sweep() {
25466
+ try {
25467
+ await this.tellDeclined(this.deps.store.reviewDelegation.declinedReviewOnboardings());
25468
+ } catch (err2) {
25469
+ this.deps.logger.warn("an asker could not be told that the reviewer said no", { error: errorName(err2) });
25470
+ }
25471
+ for (const userId of this.deps.store.reviewDelegation.onboardingReviewers()) {
25472
+ try {
25473
+ await this.advance(userId);
25474
+ } catch (err2) {
25475
+ this.deps.logger.warn("a reviewer's next step could not be sent", { error: errorName(err2) });
25476
+ }
25477
+ }
25478
+ }
25479
+ /**
25480
+ * This person's state, read again: a step further than they were told is answered with the next one (once, whoever
25481
+ * reads it first), and so is a step they undid; all done, each asker is told where they asked. A step that could not
25482
+ * be said is claimed back, so the next read (their next message, or the sweep) says it.
25483
+ */
25484
+ async advance(userId) {
25485
+ const store = this.deps.store.reviewDelegation;
25486
+ if (!store.openReviewOnboardings(userId).length) return;
25487
+ const now = await this.progress(userId);
25488
+ if (now === void 0) return;
25489
+ const rank = RANK[now];
25490
+ this.behind(userId, rank);
25491
+ const open = store.openReviewOnboardings(userId);
25492
+ if (!open.length) return;
25493
+ if (!store.claimOnboardingStep(userId, rank)) return;
25494
+ const unclaim = (rows) => {
25495
+ for (const row2 of rows)
25496
+ if (row2.toldRank < rank) store.releaseOnboardingStep(row2.onboardingId, rank, row2.toldRank);
25497
+ };
25498
+ if (now === "ready") {
25499
+ const before = new Map(open.map((o) => [o.onboardingId, o.toldRank]));
25500
+ await this.ready(store.openReviewOnboardings(userId), rank, (id) => before.get(id) ?? 0);
25501
+ return;
25502
+ }
25503
+ let said2 = false;
25504
+ try {
25505
+ said2 = await this.tell(userId, open, now);
25506
+ } finally {
25507
+ if (!said2) unclaim(open);
25508
+ }
25509
+ }
25510
+ /** The step `now` said in the reviewer's own chat; false when that chat could not be reached. */
25511
+ async tell(userId, open, now) {
25512
+ const kept = open.flatMap((row2) => keptOf(row2) ?? []);
25513
+ const first = kept[0];
25514
+ if (first === void 0) return false;
25515
+ const chat = await personalChat(this.deps, first.actor, this.via(first));
25516
+ if (chat === void 0) {
25517
+ this.deps.logger.info("a reviewer's next step waits for their chat to be reachable");
25518
+ return false;
25519
+ }
25520
+ const person = { id: userId, channelUserId: first.actor.channelUserId, name: first.actor.name, email: "" };
25521
+ const steps = stepsShown(!this.linked(userId));
25522
+ const text8 = open.every((o) => o.toldRank === 0) ? onboardingText2.first(
25523
+ { asker: names2(kept), group: first.group, pulls: first.pulls.map(shortName).join(", "), merge: first.merge },
25524
+ steps,
25525
+ now
25526
+ ) : onboardingText2.next(names2(kept), steps, now);
25527
+ await say2(this.deps, chat, text8);
25528
+ await this.cardAfterText(chat, person, now);
25529
+ return true;
25530
+ }
25531
+ via(kept) {
25532
+ return this.deps.restoreRef(kept.asked);
25533
+ }
25534
+ /**
25535
+ * Every step is done: each asker, where they asked, hears it with the button that asks again, and only then is the
25536
+ * request marked told; one that could not be told is claimed back (from `rank`) and told on the next read. The
25537
+ * reviewer hears it too.
25538
+ */
25539
+ async ready(open, rank, toldBefore) {
25540
+ const store = this.deps.store.reviewDelegation;
25541
+ const told = [];
25542
+ for (const row2 of open) {
25543
+ const kept = keptOf(row2);
25544
+ const where = kept === void 0 ? void 0 : stored(this.deps, kept.asked);
25545
+ if (kept === void 0 || where === void 0) {
25546
+ store.finishReviewOnboarding(row2.onboardingId);
25547
+ continue;
25548
+ }
25549
+ const pulls = kept.pulls.map(shortName).join(", ");
25550
+ const text8 = onboardingText2.ready(kept.actor.name || "\u5BF9\u65B9", pulls, kept.merge);
25551
+ const retry = {
25552
+ title: onboardingText2.retryButton,
25553
+ verb: `primusclaw.${ONBOARDING_CLICK}`,
25554
+ data: { primusclaw: ONBOARDING_CLICK, op: "retry", id: row2.onboardingId },
25555
+ style: "positive"
25556
+ };
25557
+ try {
25558
+ await where.send(
25559
+ noteMessage({ text: this.deps.mask(text8), title: onboardingText2.readyTitle, tone: "good", buttons: [retry] })
25560
+ );
25561
+ } catch (err2) {
25562
+ this.deps.logger.warn("the asker could not be told that the reviewer is ready", { error: errorName(err2) });
25563
+ store.releaseOnboardingStep(row2.onboardingId, rank, toldBefore(row2.onboardingId));
25564
+ continue;
25565
+ }
25566
+ if (store.finishReviewOnboarding(row2.onboardingId)) told.push(kept);
25567
+ }
25568
+ const first = told[0];
25569
+ if (first === void 0) return;
25570
+ try {
25571
+ const chat = await personalChat(this.deps, first.actor, this.via(first));
25572
+ if (chat !== void 0) await say2(this.deps, chat, onboardingText2.allDone(names2(told)));
25573
+ } catch (err2) {
25574
+ this.deps.logger.warn("the reviewer could not be told that every step is done", { error: errorName(err2) });
25575
+ }
25576
+ }
25577
+ /**
25578
+ * The reviewer turned their standing authorization off, or said not now: each asker waiting on them is told, once. Each
25579
+ * is marked declined first (nothing waits for the reviewer any more), and stays owed to its asker until the telling
25580
+ * went, so a send that fails is tried again by the sweep.
25581
+ */
25582
+ async declined(userId) {
25583
+ const store = this.deps.store.reviewDelegation;
25584
+ for (const row2 of store.openReviewOnboardings(userId)) store.declineReviewOnboarding(row2.onboardingId);
25585
+ await this.tellDeclined(store.declinedReviewOnboardings(userId));
25586
+ }
25587
+ /** Each asker owed a reviewer's no is told it where they asked (once, whoever takes it first); then it is dropped. */
25588
+ async tellDeclined(rows) {
25589
+ const store = this.deps.store.reviewDelegation;
25590
+ for (const row2 of rows) {
25591
+ if (!store.claimDeclinedOnboarding(row2.onboardingId)) continue;
25592
+ const kept = keptOf(row2);
25593
+ const where = kept === void 0 ? void 0 : stored(this.deps, kept.asked);
25594
+ if (kept === void 0 || where === void 0) {
25595
+ store.dropReviewOnboarding(row2.onboardingId);
25596
+ continue;
25597
+ }
25598
+ try {
25599
+ await say2(this.deps, where, onboardingText2.refused(kept.actor.name || "\u5BF9\u65B9", kept.pulls.map(shortName).join(", ")));
25600
+ } catch (err2) {
25601
+ this.deps.logger.warn("the asker could not be told that the reviewer said no", { error: errorName(err2) });
25602
+ store.releaseDeclinedOnboarding(row2.onboardingId);
25603
+ continue;
25604
+ }
25605
+ store.dropReviewOnboarding(row2.onboardingId);
25606
+ }
25607
+ }
25608
+ /** A press of one of the buttons this sent. */
25609
+ async click(click) {
25610
+ const data = click.action.data;
25611
+ const op = data.op;
25612
+ if (op === "retry") {
25613
+ await this.retryClick(click, str6(data.id));
25614
+ return;
25615
+ }
25616
+ if (op !== "bind" && op !== "auto_merge_on" && op !== "decline") {
25617
+ await click.settle(onboardingText2.inactive);
25618
+ return;
25619
+ }
25620
+ if (click.conversation.ref.kind !== "personal") {
25621
+ await click.settle(onboardingText2.oneToOne);
25622
+ return;
25623
+ }
25624
+ if (op === "decline") {
25625
+ await click.settle(onboardingText2.declined);
25626
+ await this.declined(click.sender.id);
25627
+ return;
25628
+ }
25629
+ await click.settle(op === "bind" ? onboardingText2.binding : onboardingText2.allowed);
25630
+ await this.github(click.sender, op === "bind" ? "bind" : "auto-merge on", click.conversation);
25631
+ }
25632
+ /** The asker's press of "ask again": the same request, started again through every check, once. */
25633
+ async retryClick(click, id) {
25634
+ const store = this.deps.store.reviewDelegation;
25635
+ const row2 = id ? store.getReviewOnboarding(id) : null;
25636
+ const kept = row2 === null || !row2.done || row2.declined ? void 0 : keptOf(row2);
25637
+ if (row2 === null || kept === void 0) {
25638
+ await click.settle(onboardingText2.retryGone);
25639
+ return;
25640
+ }
25641
+ if (click.sender.id !== row2.requesterId) {
25642
+ const retry = {
25643
+ title: onboardingText2.retryButton,
25644
+ verb: `primusclaw.${ONBOARDING_CLICK}`,
25645
+ data: { primusclaw: ONBOARDING_CLICK, op: "retry", id }
25646
+ };
25647
+ await click.settle(noteMessage({ text: onboardingText2.onlyAsker, title: onboardingText2.readyTitle, buttons: [retry] }), {
25648
+ fallback: onboardingText2.onlyAsker
25649
+ });
25650
+ return;
25651
+ }
25652
+ store.dropReviewOnboarding(row2.onboardingId);
25653
+ const pulls = kept.pulls.map(shortName).join(", ");
25654
+ await click.settle(onboardingText2.retried(pulls));
25655
+ const fresh = epochSeconds(this.deps.clock) - kept.askedAt < HANDOFF_REUSE_SECONDS;
25656
+ const ask3 = reviewAsk({
25657
+ who: kept.actor.name,
25658
+ pulls: kept.pulls,
25659
+ merge: kept.merge,
25660
+ models: kept.models,
25661
+ named: [kept.actor.channelUserId],
25662
+ handoffId: fresh ? kept.handoffId : ""
25663
+ });
25664
+ const message = {
25665
+ type: "message",
25666
+ id: `${click.action.id || row2.onboardingId}-retry`,
25667
+ sender: click.sender,
25668
+ conversation: click.conversation.ref,
25669
+ locale: click.action.locale,
25670
+ clientPlatform: click.action.clientPlatform,
25671
+ text: kept.note,
25672
+ mentioned: true,
25673
+ targeted: false,
25674
+ namesBotFirst: false,
25675
+ conversationName: kept.where,
25676
+ mentions: [],
25677
+ links: [],
25678
+ quotes: [],
25679
+ files: [],
25680
+ unreadableFiles: [],
25681
+ provenance: "typed"
25682
+ };
25683
+ const ctx = {
25684
+ message,
25685
+ sender: click.sender,
25686
+ conversation: click.conversation,
25687
+ scope: click.scope,
25688
+ text: kept.note,
25689
+ group: click.conversation.ref.kind !== "personal"
25690
+ };
25691
+ await this.retry(ctx, ask3, kept.actor);
25692
+ }
25693
+ };
25694
+
25145
25695
  // packages/core/src/review/intent-check.ts
25146
25696
  var BARE_NUMBER = pyFullmatch(String.raw`#?\s*\d{1,7}`);
25147
25697
  var INTENTS = ["review_merge", "review", "none"];
@@ -25547,17 +26097,19 @@ async function withTimeout(deps, promise, ms) {
25547
26097
  // packages/core/src/review/service/start.ts
25548
26098
  var asked2 = (ctx) => ctx.conversation.ref;
25549
26099
  var ReviewChecks = class {
25550
- constructor(deps, reviewers, items, notices, launch) {
26100
+ constructor(deps, reviewers, items, notices, onboarding, launch) {
25551
26101
  this.deps = deps;
25552
26102
  this.reviewers = reviewers;
25553
26103
  this.items = items;
25554
26104
  this.notices = notices;
26105
+ this.onboarding = onboarding;
25555
26106
  this.launch = launch;
25556
26107
  }
25557
26108
  deps;
25558
26109
  reviewers;
25559
26110
  items;
25560
26111
  notices;
26112
+ onboarding;
25561
26113
  launch;
25562
26114
  say(ctx, text8) {
25563
26115
  return say2(this.deps, ctx.conversation, text8);
@@ -25632,35 +26184,40 @@ var ReviewChecks = class {
25632
26184
  }
25633
26185
  return actor;
25634
26186
  }
25635
- /** The reviewer's GitHub binding, usable and authorized, or undefined when the asker was told why not. */
26187
+ /**
26188
+ * The reviewer's GitHub binding, usable and authorized, or undefined when the asker was told why not. A review asked of
26189
+ * someone else who has a step left is kept until they have done it (`ReviewerOnboarding`), and the asker is told which.
26190
+ */
25636
26191
  async reviewerState(ctx, ask3, actor, pulls) {
25637
26192
  const status = await this.deps.credentials.status(actor.userId);
25638
- if (!status.ok) {
25639
- if (status.error.kind === "not_bound") {
25640
- await this.notices.noGithub(asked2(ctx), ctx.group, ctx.sender, actor, pulls, ctx.conversation, false);
25641
- return void 0;
25642
- }
26193
+ if (!status.ok && status.error.kind !== "not_bound") {
25643
26194
  this.deps.logger.warn("github status call failed", { error: describeRefusal(status.error) });
25644
26195
  await this.say(ctx, reviewStartText.githubUnknown(actor.name || "\u5BF9\u65B9"));
25645
26196
  return void 0;
25646
26197
  }
25647
- if (!usable(status.value)) {
25648
- await this.notices.noGithub(asked2(ctx), ctx.group, ctx.sender, actor, pulls, ctx.conversation, true);
26198
+ if (actor.userId === ctx.sender.id) {
26199
+ if (status.ok && usable(status.value)) return status.value;
26200
+ await this.notices.noGithub(asked2(ctx), ctx.group, ctx.sender, actor, pulls, ctx.conversation, status.ok);
25649
26201
  return void 0;
25650
26202
  }
25651
- if (!status.value.delegation && actor.userId !== ctx.sender.id) {
25652
- await this.say(ctx, reviewStartText.notAuthorized(actor.name || "\u5BF9\u65B9", ask3.merge));
26203
+ if (!status.ok) {
26204
+ await this.onboarding.refused(ctx, ask3, actor, pulls, "identity");
26205
+ return void 0;
26206
+ }
26207
+ const step = !usable(status.value) ? "bind" : !status.value.delegation ? "auto_merge" : void 0;
26208
+ if (step !== void 0) {
26209
+ await this.onboarding.refused(ctx, ask3, actor, pulls, step);
25653
26210
  return void 0;
25654
26211
  }
25655
26212
  return status.value;
25656
26213
  }
25657
26214
  /** A review asked of someone else runs on their own token and key: both, or undefined when the asker was told. */
25658
- async actingCredentials(ctx, actor) {
26215
+ async actingCredentials(ctx, ask3, actor, pulls) {
25659
26216
  if (actor.userId === ctx.sender.id) return { token: "", key: "" };
25660
26217
  const who = actor.name || "\u5BF9\u65B9";
25661
26218
  const key = this.deps.store.links.getKey(actor.userId) ?? "";
25662
26219
  if (!key.startsWith("ak-")) {
25663
- await this.say(ctx, reviewStartText.reviewerNotLinked(who, this.deps.botName));
26220
+ await this.onboarding.refused(ctx, ask3, actor, pulls, "link");
25664
26221
  return void 0;
25665
26222
  }
25666
26223
  const token = await tokenFor(this.deps, actor.userId);
@@ -25707,7 +26264,7 @@ var ReviewChecks = class {
25707
26264
  }
25708
26265
  const state = await this.reviewerState(ctx, ask3, actor, pulls);
25709
26266
  if (state === void 0) return;
25710
- const acting = await this.actingCredentials(ctx, actor);
26267
+ const acting = await this.actingCredentials(ctx, ask3, actor, pulls);
25711
26268
  if (acting === void 0) return;
25712
26269
  const who = actor.name || "\u5BF9\u65B9";
25713
26270
  const model = await this.modelFor(ctx, ask3, token, acting.key || modelKey, Boolean(acting.key), who);
@@ -26025,11 +26582,20 @@ var GithubReview = class {
26025
26582
  this.held = new HeldWrites(deps, this.notices, this.account);
26026
26583
  this.turns.offerHeld = (review, item, asked3) => this.held.offer(review, item, asked3);
26027
26584
  this.launch = new ReviewLaunch(deps, this.items, this.notices, this.cards, this.follows, this.turns);
26585
+ this.onboarding = new ReviewerOnboarding(
26586
+ deps,
26587
+ this.notices,
26588
+ random,
26589
+ (ctx, ask3, actor) => this.checks.request(ctx, ask3, actor),
26590
+ (sender, args, conversation) => this.account.command(sender, args, conversation)
26591
+ );
26592
+ this.account.changed = (userId, change) => change === "delegation_off" ? this.onboarding.declined(userId) : this.onboarding.advance(userId);
26028
26593
  this.checks = new ReviewChecks(
26029
26594
  deps,
26030
26595
  this.reviewers,
26031
26596
  this.items,
26032
26597
  this.notices,
26598
+ this.onboarding,
26033
26599
  (s, held, handed) => this.launch.launch(s, held, handed)
26034
26600
  );
26035
26601
  this.turns.retryAsItem = (review, s) => this.launch.asItem(review, s);
@@ -26047,15 +26613,22 @@ var GithubReview = class {
26047
26613
  held;
26048
26614
  checks;
26049
26615
  launch;
26616
+ onboarding;
26050
26617
  /** Settles when the background work started so far (device flows, follows, hints) has ended. For tests. */
26051
26618
  async idle() {
26052
26619
  await Promise.all([this.account.idle(), this.follows.idle(), this.connect.idle()]);
26620
+ await this.onboarding.idle();
26053
26621
  }
26054
26622
  /** Which channel id is whose, from a message of theirs: a mention in a group can then be read without the member list. */
26055
26623
  remember(message) {
26056
26624
  const sender = message.sender;
26057
26625
  if (sender.channelUserId)
26058
26626
  this.deps.store.members.rememberMember(sender.channelUserId, sender.id, sender.name, sender.email);
26627
+ this.onboarding.activity(sender.id);
26628
+ }
26629
+ /** The reviewers a review waits for, read again: each step done is answered with the next (every ONBOARDING_SWEEP_MS). */
26630
+ sweepOnboarding() {
26631
+ return this.onboarding.sweep();
26059
26632
  }
26060
26633
  context(route) {
26061
26634
  return {
@@ -26282,10 +26855,17 @@ var GithubReview = class {
26282
26855
  clicks: [
26283
26856
  {
26284
26857
  // (the action's `verb` is its card data's `primusclaw` kind, as the adapter reads it; never the channel's verb)
26285
- verbs: ["github_mode", "github_confirm", "github_connect"],
26858
+ verbs: ["github_mode", "github_confirm", "github_connect", ONBOARDING_CLICK],
26286
26859
  beforeCredential: async (click) => {
26287
26860
  await this.click(click);
26288
26861
  return true;
26862
+ },
26863
+ // (the ready card goes where the asker asked, a group too: only its retry is answered there, and only to the
26864
+ // asker; it runs on the reviewer's own credential, never the group's or the presser's)
26865
+ inGroup: async (click) => {
26866
+ if (click.action.data.primusclaw !== ONBOARDING_CLICK) return false;
26867
+ await this.onboarding.click(click);
26868
+ return true;
26289
26869
  }
26290
26870
  }
26291
26871
  ]
@@ -26294,7 +26874,9 @@ var GithubReview = class {
26294
26874
  async click(click) {
26295
26875
  const data = click.action.data;
26296
26876
  const settle = (card, fallback) => click.settle(card, fallback === void 0 ? {} : { fallback });
26297
- if (data.primusclaw === "github_mode") await this.account.modeClick(click.sender, data, settle, click.conversation);
26877
+ if (data.primusclaw === ONBOARDING_CLICK) await this.onboarding.click(click);
26878
+ else if (data.primusclaw === "github_mode")
26879
+ await this.account.modeClick(click.sender, data, settle, click.conversation);
26298
26880
  else if (data.primusclaw === "github_confirm")
26299
26881
  await this.held.click(click.sender, data, settle, click.conversation);
26300
26882
  else await this.connect.dismiss(click.sender, data, click.lang(), settle);
@@ -26815,7 +27397,7 @@ function record5(value) {
26815
27397
  const parsed = Record_.safeParse(value);
26816
27398
  return parsed.success ? parsed.data : {};
26817
27399
  }
26818
- function str6(value) {
27400
+ function str7(value) {
26819
27401
  return typeof value === "string" ? value : "";
26820
27402
  }
26821
27403
  function seqOf(value) {
@@ -26834,7 +27416,7 @@ function textOf5(payload) {
26834
27416
  const inner = Record_.safeParse(content);
26835
27417
  if (inner.success && typeof inner.data["text"] === "string") return inner.data["text"];
26836
27418
  if (typeof content === "string") return content;
26837
- return str6(u["text"]);
27419
+ return str7(u["text"]);
26838
27420
  }
26839
27421
  var STOP_REASONS = /* @__PURE__ */ new Set(["end_turn", "max_tokens", "max_turn_requests", "refusal", "cancelled", "error"]);
26840
27422
  function availableModes(raw) {
@@ -26883,7 +27465,7 @@ function planLine(payload) {
26883
27465
  const done = items.filter((e) => e["status"] === "completed").length;
26884
27466
  const current = items.find((e) => e["status"] === "in_progress") ?? items.find((e) => e["status"] !== "completed");
26885
27467
  let line2 = `\u{1F4CB} Plan: ${String(done)} of ${String(items.length)} done`;
26886
- if (current && str6(current["content"])) line2 += `, now: ${neutral2(current["content"], PLAN_ITEM_MAX)}`;
27468
+ if (current && str7(current["content"])) line2 += `, now: ${neutral2(current["content"], PLAN_ITEM_MAX)}`;
26887
27469
  return line2;
26888
27470
  }
26889
27471
  var NOT_TYPED = new RegExp(
@@ -26909,33 +27491,33 @@ function typed(payload) {
26909
27491
  var TOOL_NAME = /^[A-Za-z][\w.-]{0,63}$/u;
26910
27492
  function toolNameOf(u) {
26911
27493
  const meta = record5(record5(u["_meta"])["claudeCode"]);
26912
- const named2 = str6(meta["toolName"]);
27494
+ const named2 = str7(meta["toolName"]);
26913
27495
  if (TOOL_NAME.test(named2)) return named2;
26914
- const head = str6(u["title"]).split(": ", 1)[0] ?? "";
26915
- return head !== str6(u["title"]) && TOOL_NAME.test(head) ? head : "";
27496
+ const head = str7(u["title"]).split(": ", 1)[0] ?? "";
27497
+ return head !== str7(u["title"]) && TOOL_NAME.test(head) ? head : "";
26916
27498
  }
26917
27499
  function tool(payload, kind) {
26918
27500
  const u = update(payload);
26919
- const id = str6(u["toolCallId"]) || str6(u["tool_call_id"]) || str6(u["id"]);
26920
- const status = str6(u["status"]) || (kind === "tool_call" ? "pending" : "");
27501
+ const id = str7(u["toolCallId"]) || str7(u["tool_call_id"]) || str7(u["id"]);
27502
+ const status = str7(u["status"]) || (kind === "tool_call" ? "pending" : "");
26921
27503
  const name = toolNameOf(u);
26922
- return remoteStep({ tool: { id, title: str6(u["title"]), status, ...name ? { name } : {} } });
27504
+ return remoteStep({ tool: { id, title: str7(u["title"]), status, ...name ? { name } : {} } });
26923
27505
  }
26924
27506
  function terminalQueued(payload) {
26925
27507
  const seq = seqOf(payload["cmd_seq"]);
26926
- const forId = neutral2(str6(payload["cmd_id"]), 80) || (seq !== null ? String(seq) : "");
27508
+ const forId = neutral2(str7(payload["cmd_id"]), 80) || (seq !== null ? String(seq) : "");
26927
27509
  return remoteStep({
26928
- queued: str6(payload["reason"]) || "terminal_working",
27510
+ queued: str7(payload["reason"]) || "terminal_working",
26929
27511
  queuedFor: forId || null,
26930
27512
  queuedSeq: seq,
26931
27513
  queuedHeld: payload["held"] === "terminal",
26932
- dialog: neutral2(str6(payload["dialog"]), DIALOG_MAX) || null,
27514
+ dialog: neutral2(str7(payload["dialog"]), DIALOG_MAX) || null,
26933
27515
  rowUnreadable: payload["registry_row_unreadable"] === true
26934
27516
  });
26935
27517
  }
26936
27518
  function turnEnd(payload, _kind, errors) {
26937
- let reason = str6(payload["stopReason"]) || "end_turn";
26938
- let error = str6(payload["error"]) || str6(payload["message"]);
27519
+ let reason = str7(payload["stopReason"]) || "end_turn";
27520
+ let error = str7(payload["error"]) || str7(payload["message"]);
26939
27521
  if (!STOP_REASONS.has(reason)) {
26940
27522
  error = error || `an internal error (ref ${errors.withhold("remote_stop_reason", reason)})`;
26941
27523
  reason = "error";
@@ -26956,8 +27538,8 @@ function sessionStarted(payload) {
26956
27538
  modeFlags: modeFlags(payload["modes"]),
26957
27539
  readOnly: flag2(payload["read_only"]) ?? false,
26958
27540
  terminal: payload["input"] === "terminal",
26959
- terminalMode: neutral2(str6(payload["terminal_mode"]), 40) || null,
26960
- acp: neutral2(str6(payload["acp_session_id"]), RESUME_REF_MAX) || null,
27541
+ terminalMode: neutral2(str7(payload["terminal_mode"]), 40) || null,
27542
+ acp: neutral2(str7(payload["acp_session_id"]), RESUME_REF_MAX) || null,
26961
27543
  rowUnreadable: payload["registry_row_unreadable"] === true
26962
27544
  });
26963
27545
  }
@@ -26982,21 +27564,21 @@ function sessionResumed(payload) {
26982
27564
  });
26983
27565
  }
26984
27566
  function sessionClosed(payload, _kind, errors) {
26985
- const reason = str6(payload["reason"]) || str6(payload["message"]) || str6(payload["error"]);
27567
+ const reason = str7(payload["reason"]) || str7(payload["message"]) || str7(payload["error"]);
26986
27568
  return remoteStep({ closed: neutral2(errors.publicReason(reason, "remote_session_closed"), 300) });
26987
27569
  }
26988
27570
  function commandRejected(payload, _kind, errors) {
26989
- const reason = str6(payload["reason"]);
27571
+ const reason = str7(payload["reason"]);
26990
27572
  return remoteStep({
26991
27573
  rejected: {
26992
- type: str6(payload["type"]),
27574
+ type: str7(payload["type"]),
26993
27575
  reason: neutral2(errors.publicReason(reason, "remote_command_rejected"), 300),
26994
27576
  cmdSeq: seqOf(payload["cmd_seq"])
26995
27577
  }
26996
27578
  });
26997
27579
  }
26998
27580
  function failed2(payload, _kind, errors) {
26999
- const text8 = str6(payload["message"]) || str6(payload["error"]) || str6(payload["reason"]);
27581
+ const text8 = str7(payload["message"]) || str7(payload["error"]) || str7(payload["reason"]);
27000
27582
  return remoteStep({
27001
27583
  finished: true,
27002
27584
  stopReason: "error",
@@ -27738,15 +28320,15 @@ function sessionRows(input, shown3) {
27738
28320
  });
27739
28321
  }
27740
28322
  function joinedOf(input, shown3) {
27741
- const names2 = input.names ?? /* @__PURE__ */ new Map();
28323
+ const names3 = input.names ?? /* @__PURE__ */ new Map();
27742
28324
  const shownIds = shown3.map((s) => s.sessionId);
27743
28325
  const mine = /* @__PURE__ */ new Set();
27744
28326
  for (const [sid, acp] of input.own ?? /* @__PURE__ */ new Map()) {
27745
- if (shownIds.includes(sid) && !names2.get(sid)?.ref) mine.add(acp);
28327
+ if (shownIds.includes(sid) && !names3.get(sid)?.ref) mine.add(acp);
27746
28328
  }
27747
28329
  const connected = /* @__PURE__ */ new Map();
27748
28330
  shownIds.forEach((sid, i) => {
27749
- const ref = names2.get(sid)?.ref;
28331
+ const ref = names3.get(sid)?.ref;
27750
28332
  if (ref) connected.set(ref, { number: i + 1, sessionId: sid });
27751
28333
  });
27752
28334
  return { connected, mine };
@@ -29535,8 +30117,8 @@ function resolveAgent(connectors, ref, now, lang = "en") {
29535
30117
  const only2 = online[0];
29536
30118
  if (online.length === 1 && only2 !== void 0) return only2;
29537
30119
  if (online.length > 1) {
29538
- const names2 = online.map((p) => `\`${agentRefOf(p.connector, p.agent)}\``).join(", ");
29539
- return refusal2(remoteAgentText.in(lang).agentOnMachines({ names: names2 }));
30120
+ const names3 = online.map((p) => `\`${agentRefOf(p.connector, p.agent)}\``).join(", ");
30121
+ return refusal2(remoteAgentText.in(lang).agentOnMachines({ names: names3 }));
29540
30122
  }
29541
30123
  return refusal2(offlineText(first.connector, now, lang));
29542
30124
  }
@@ -29803,8 +30385,8 @@ var Targets = class {
29803
30385
  if (/^\d+$/u.test(ref)) return refusal3(saidIn(lang, "whichSession"));
29804
30386
  const chosen = resolveAgent(connectors, ref, now, lang);
29805
30387
  if (chosen.kind === "machine") {
29806
- const names2 = chosen.agents.map((a) => `\`${agentRefOf(chosen.connector, a)}\``).join(", ");
29807
- return refusal3(remoteAgentText.in(lang).agentsOnHost({ host: neutral(chosen.connector.name, 80), names: names2 }));
30388
+ const names3 = chosen.agents.map((a) => `\`${agentRefOf(chosen.connector, a)}\``).join(", ");
30389
+ return refusal3(remoteAgentText.in(lang).agentsOnHost({ host: neutral(chosen.connector.name, 80), names: names3 }));
29808
30390
  }
29809
30391
  if (chosen.kind === "refusal") {
29810
30392
  if (found.length > 0 || chosen.text === noAgentCalled(ref, lang))
@@ -32009,9 +32591,9 @@ ${left}` : "";
32009
32591
  else if (state) chosen = connectors.filter((c) => c.connectorId === state.connectorId);
32010
32592
  const only2 = chosen[0];
32011
32593
  if (chosen.length !== 1 || only2 === void 0) {
32012
- const names2 = connectors.map((c) => `\`${neutral(c.name, 60)}\``).join(", ");
32594
+ const names3 = connectors.map((c) => `\`${neutral(c.name, 60)}\``).join(", ");
32013
32595
  const words3 = remoteAgentText.in("en");
32014
- return this.say(call, names2 ? words3.whichMachine({ names: names2 }) : words3.whichMachineNone);
32596
+ return this.say(call, names3 ? words3.whichMachine({ names: names3 }) : words3.whichMachineNone);
32015
32597
  }
32016
32598
  const setup = await this.p.lists.setup(call.key);
32017
32599
  await call.to.send(this.p.ctx.views.disconnect(only2.name, only2.connectorId, setup, this.lang(call), only2.paired));
@@ -34442,6 +35024,7 @@ export {
34442
35024
  ONBOARDING_DM_BUDGET_SECONDS,
34443
35025
  ONBOARDING_INTERVAL_SECONDS,
34444
35026
  ONBOARDING_REQUEST_MINUTES,
35027
+ ONBOARDING_SWEEP_MS,
34445
35028
  OPTIONS_MAX,
34446
35029
  OPTION_MAX,
34447
35030
  ObserveBoard,
@@ -34492,6 +35075,7 @@ export {
34492
35075
  REMOTE_HIDE_LIMITS,
34493
35076
  REMOTE_LINE,
34494
35077
  REMOTE_ORIGIN_TERMINAL_HOOK,
35078
+ REMOTE_OUTBOX_REPORT_MAX_SESSIONS,
34495
35079
  REMOTE_PERMISSION_KEEP_SECONDS,
34496
35080
  WATCH_TIMINGS as REMOTE_WATCH_TIMINGS,
34497
35081
  REPO,
@@ -34504,6 +35088,7 @@ export {
34504
35088
  REVIEW_HANDOFF_ACTION,
34505
35089
  REVIEW_MODES,
34506
35090
  REVIEW_MODE_NAMES,
35091
+ REVIEW_ONBOARDING_KEEP_SECONDS,
34507
35092
  RULE_MAX_BYTES,
34508
35093
  RULE_TTL_MS,
34509
35094
  Receipts,
@@ -34790,6 +35375,7 @@ export {
34790
35375
  parseLimits,
34791
35376
  parseLinkCode,
34792
35377
  parseObserve,
35378
+ parseOutboxReport,
34793
35379
  parseQuietWindow,
34794
35380
  parseRemoteId,
34795
35381
  parseRepo,