@staff0rd/assist 0.1007.0 → 0.1008.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
@@ -6,7 +6,7 @@ import { Command } from "commander";
6
6
  // package.json
7
7
  var package_default = {
8
8
  name: "@staff0rd/assist",
9
- version: "0.1007.0",
9
+ version: "0.1008.0",
10
10
  type: "module",
11
11
  main: "dist/index.js",
12
12
  bin: {
@@ -25753,9 +25753,25 @@ function registerDevlog(program) {
25753
25753
  }
25754
25754
 
25755
25755
  // src/commands/docs/docsConfirm.ts
25756
- import { unlinkSync as unlinkSync10 } from "fs";
25757
25756
  import chalk165 from "chalk";
25758
25757
 
25758
+ // src/commands/notify/forwardPinConfirm.ts
25759
+ import { randomUUID as randomUUID11 } from "crypto";
25760
+ var CONFIRM_TIMEOUT_MS = 15e3;
25761
+ async function forwardPinConfirm(area, pin2) {
25762
+ const requestId = randomUUID11();
25763
+ const reply2 = await requestDaemonReply(
25764
+ { type: "confirm-pin", requestId, area, pin: pin2 },
25765
+ "confirm-pin-result",
25766
+ CONFIRM_TIMEOUT_MS
25767
+ );
25768
+ if (!reply2?.found || reply2.requestId !== requestId) return void 0;
25769
+ return { ok: reply2.ok === true, message: reply2.message ?? "" };
25770
+ }
25771
+
25772
+ // src/commands/docs/approveDocsUnlock.ts
25773
+ import { unlinkSync as unlinkSync10 } from "fs";
25774
+
25759
25775
  // src/commands/docs/getDocsUnlockPinPath.ts
25760
25776
  import { join as join69 } from "path";
25761
25777
  function getDocsUnlockPinPath(pin2) {
@@ -25795,43 +25811,75 @@ async function recordDocsUnlock(orm, itemId2, phase) {
25795
25811
  });
25796
25812
  }
25797
25813
 
25798
- // src/commands/docs/docsConfirm.ts
25799
- async function docsConfirm(pin2) {
25814
+ // src/commands/docs/approveDocsUnlock.ts
25815
+ async function approveDocsUnlock(pin2) {
25800
25816
  sweepRestrictedDir();
25801
25817
  const state = readDocsUnlockPinState(pin2);
25802
- if (!state) {
25803
- console.error(chalk165.red(`No pending docs unlock for pin: ${pin2}`));
25804
- process.exitCode = 1;
25805
- return;
25806
- }
25818
+ if (!state) return void 0;
25807
25819
  unlinkSync10(getDocsUnlockPinPath(pin2));
25808
25820
  const found = await findOneItem(String(state.itemId));
25809
- if (!found) {
25821
+ if (!found)
25822
+ return {
25823
+ ok: false,
25824
+ message: `Item ${formatItemId(state.itemId)} not found; nothing was approved.`
25825
+ };
25826
+ const label = `${formatItemId(state.itemId)} ${found.item.name}`;
25827
+ if ((found.item.currentPhase ?? 1) !== state.phase)
25828
+ return {
25829
+ ok: false,
25830
+ message: `${label} has moved on from phase ${state.phase} since the unlock was requested. Nothing was approved; request a new unlock from the current phase.`
25831
+ };
25832
+ await recordDocsUnlock(found.orm, state.itemId, state.phase);
25833
+ return {
25834
+ ok: true,
25835
+ message: `Approved docs changes for phase ${state.phase} of ${label}. Its sessions may edit and commit docs pages and screenshots until the item moves on from that phase or is done or won't-do.`
25836
+ };
25837
+ }
25838
+
25839
+ // src/commands/docs/docsConfirm.ts
25840
+ async function docsConfirm(pin2) {
25841
+ const result = await approveDocsUnlock(pin2) ?? await forwardPinConfirm("docs", pin2);
25842
+ if (!result) {
25843
+ console.error(chalk165.red(`No pending docs unlock for pin: ${pin2}`));
25810
25844
  process.exitCode = 1;
25811
25845
  return;
25812
25846
  }
25813
- const label = `${formatItemId(state.itemId)} ${found.item.name}`;
25814
- if ((found.item.currentPhase ?? 1) !== state.phase) {
25815
- console.error(
25816
- chalk165.red(
25817
- `${label} has moved on from phase ${state.phase} since the unlock was requested. Nothing was approved; request a new unlock from the current phase.`
25818
- )
25819
- );
25820
- process.exitCode = 1;
25847
+ if (result.ok) {
25848
+ console.log(chalk165.green(result.message));
25821
25849
  return;
25822
25850
  }
25823
- await recordDocsUnlock(found.orm, state.itemId, state.phase);
25824
- console.log(
25825
- chalk165.green(
25826
- `Approved docs changes for phase ${state.phase} of ${label}. Its sessions may edit and commit docs pages and screenshots until the item moves on from that phase or is done or won't-do.`
25827
- )
25828
- );
25851
+ console.error(chalk165.red(result.message));
25852
+ process.exitCode = 1;
25829
25853
  }
25830
25854
 
25831
25855
  // src/commands/docs/docsUnlock.ts
25832
25856
  import { randomInt as randomInt3 } from "crypto";
25833
25857
  import { mkdirSync as mkdirSync20, unlinkSync as unlinkSync11, writeFileSync as writeFileSync33 } from "fs";
25834
25858
  import chalk166 from "chalk";
25859
+
25860
+ // src/commands/notify/deliverPinNotification.ts
25861
+ import { randomUUID as randomUUID12 } from "crypto";
25862
+ var ROUTE_TIMEOUT_MS = 1e4;
25863
+ async function relayToViewerNode(notification) {
25864
+ const sessionId = process.env.ASSIST_SESSION_ID;
25865
+ if (!sessionId) return void 0;
25866
+ const requestId = randomUUID12();
25867
+ const reply2 = await requestDaemonReply(
25868
+ { type: "notify-pin", sessionId, requestId, ...notification },
25869
+ "notify-pin-result",
25870
+ ROUTE_TIMEOUT_MS
25871
+ );
25872
+ if (reply2?.requestId !== requestId) return void 0;
25873
+ return reply2.node;
25874
+ }
25875
+ async function deliverPinNotification(notification) {
25876
+ const node = await relayToViewerNode(notification);
25877
+ if (node) return { delivered: true, node };
25878
+ const { title, message: message3 } = notification;
25879
+ return { delivered: showNotification({ title, message: message3 }) };
25880
+ }
25881
+
25882
+ // src/commands/docs/docsUnlock.ts
25835
25883
  function fail7(message3) {
25836
25884
  console.error(chalk166.red(message3));
25837
25885
  process.exitCode = 1;
@@ -25856,7 +25904,9 @@ async function docsUnlock() {
25856
25904
  sweepRestrictedDir();
25857
25905
  const pinPath = getDocsUnlockPinPath(pin2);
25858
25906
  writeFileSync33(pinPath, JSON.stringify({ pin: pin2, itemId: itemId2, phase }));
25859
- const delivered = showNotification({
25907
+ const { delivered, node } = await deliverPinNotification({
25908
+ area: "docs",
25909
+ pin: pin2,
25860
25910
  title: `assist docs unlock: ${label}`,
25861
25911
  message: `Pin ${pin2} \u2014 run: assist docs confirm ${pin2}`
25862
25912
  });
@@ -25868,8 +25918,8 @@ async function docsUnlock() {
25868
25918
  return;
25869
25919
  }
25870
25920
  console.log(
25871
- `A confirmation pin was sent to the user's desktop notifications.
25872
- To let this phase of ${label} edit docs pages and screenshots, the user runs:
25921
+ `A confirmation pin was sent to the user's desktop notifications${node ? ` on ${node}, the node controlling this session` : ""}.
25922
+ To let this phase of ${label} edit docs pages and screenshots, the user runs${node ? ` on ${node}` : ""}:
25873
25923
  ${chalk166.cyan(" assist docs confirm <PIN>")}
25874
25924
  Wait for the user to confirm before editing docs.`
25875
25925
  );
@@ -28034,13 +28084,13 @@ function validateProposedContent(labels, title, body) {
28034
28084
  }
28035
28085
 
28036
28086
  // src/commands/github/issue/reviewProposedIssueComment.ts
28037
- import { randomUUID as randomUUID11 } from "crypto";
28087
+ import { randomUUID as randomUUID13 } from "crypto";
28038
28088
  async function reviewProposedIssueComment(title, body) {
28039
28089
  const sessionId = process.env.ASSIST_SESSION_ID;
28040
28090
  if (process.env.ASSIST_SESSION !== "1" || !sessionId) return;
28041
28091
  await awaitPreviewApproval("GitHub issue comment preview", {
28042
28092
  sessionId,
28043
- requestId: randomUUID11(),
28093
+ requestId: randomUUID13(),
28044
28094
  title,
28045
28095
  body,
28046
28096
  prNumber: null,
@@ -28558,13 +28608,13 @@ function resolveCreateIssueMetadata(options2) {
28558
28608
  }
28559
28609
 
28560
28610
  // src/commands/github/issue/reviewProposedIssue.ts
28561
- import { randomUUID as randomUUID12 } from "crypto";
28611
+ import { randomUUID as randomUUID14 } from "crypto";
28562
28612
  async function reviewProposedIssue(title, body, metadata2 = []) {
28563
28613
  const sessionId = process.env.ASSIST_SESSION_ID;
28564
28614
  if (process.env.ASSIST_SESSION !== "1" || !sessionId) return void 0;
28565
28615
  return await awaitPreviewApproval("GitHub issue preview", {
28566
28616
  sessionId,
28567
- requestId: randomUUID12(),
28617
+ requestId: randomUUID14(),
28568
28618
  title,
28569
28619
  body,
28570
28620
  prNumber: null,
@@ -28864,7 +28914,7 @@ function pushUnchangedIssue(number, repo, target, fetchedAt, bodyPath) {
28864
28914
  }
28865
28915
 
28866
28916
  // src/commands/github/issue/reviewProposedIssueEdit.ts
28867
- import { randomUUID as randomUUID13 } from "crypto";
28917
+ import { randomUUID as randomUUID15 } from "crypto";
28868
28918
  async function reviewProposedIssueEdit(title, body, working) {
28869
28919
  const sessionId = process.env.ASSIST_SESSION_ID;
28870
28920
  if (process.env.ASSIST_SESSION !== "1" || !sessionId) return body;
@@ -28872,7 +28922,7 @@ async function reviewProposedIssueEdit(title, body, working) {
28872
28922
  "GitHub issue edit preview",
28873
28923
  {
28874
28924
  sessionId,
28875
- requestId: randomUUID13(),
28925
+ requestId: randomUUID15(),
28876
28926
  title,
28877
28927
  body,
28878
28928
  prNumber: null,
@@ -29885,7 +29935,7 @@ function registerRefineLaunch(program, resumeFlag) {
29885
29935
  }
29886
29936
 
29887
29937
  // src/commands/fixConflict.ts
29888
- import { randomUUID as randomUUID14 } from "crypto";
29938
+ import { randomUUID as randomUUID16 } from "crypto";
29889
29939
 
29890
29940
  // src/commands/review/checkoutPr.ts
29891
29941
  import { execFileSync as execFileSync18 } from "child_process";
@@ -30670,7 +30720,7 @@ function buildPrompt2(rebase) {
30670
30720
  async function fixConflict(number, options2 = {}) {
30671
30721
  const { resumeSessionId } = options2;
30672
30722
  if (number && !resumeSessionId) await checkoutPr(number);
30673
- const claudeSessionId = resumeSessionId ?? randomUUID14();
30723
+ const claudeSessionId = resumeSessionId ?? randomUUID16();
30674
30724
  emitActivity({
30675
30725
  kind: "command",
30676
30726
  name: "fix-conflict",
@@ -30698,7 +30748,7 @@ function registerFixConflict(program, resumeFlag) {
30698
30748
  }
30699
30749
 
30700
30750
  // src/commands/reviewPrComments.ts
30701
- import { randomUUID as randomUUID15 } from "crypto";
30751
+ import { randomUUID as randomUUID17 } from "crypto";
30702
30752
  function buildPrompt3(number, announce, options2) {
30703
30753
  const args = [
30704
30754
  "/review-pr-comments",
@@ -30724,7 +30774,7 @@ async function reviewPrComments(number, options2 = {}) {
30724
30774
  validateAnnounce(number, announce);
30725
30775
  validateMode(options2);
30726
30776
  if (number && !resumeSessionId) await checkoutPr(number);
30727
- const claudeSessionId = resumeSessionId ?? randomUUID15();
30777
+ const claudeSessionId = resumeSessionId ?? randomUUID17();
30728
30778
  emitActivity({
30729
30779
  kind: "command",
30730
30780
  name: "review-pr-comments",
@@ -31266,7 +31316,7 @@ async function offerSaveExtract(extract2, options2, paths = {}) {
31266
31316
  }
31267
31317
 
31268
31318
  // src/commands/miro/pickAnchors.ts
31269
- import { randomUUID as randomUUID16 } from "crypto";
31319
+ import { randomUUID as randomUUID18 } from "crypto";
31270
31320
 
31271
31321
  // src/commands/miro/isBox.ts
31272
31322
  var boxTypes = /* @__PURE__ */ new Set(["shape", "sticky_note"]);
@@ -31287,7 +31337,7 @@ async function pickAnchors(sessionId, items2) {
31287
31337
  "Miro anchor selection",
31288
31338
  {
31289
31339
  sessionId,
31290
- requestId: randomUUID16(),
31340
+ requestId: randomUUID18(),
31291
31341
  title: "Pick the top-left then the bottom-right box",
31292
31342
  body: encodeMiroBoardPreview(items2),
31293
31343
  prNumber: null,
@@ -32518,13 +32568,13 @@ function postReviewComment(vars) {
32518
32568
  }
32519
32569
 
32520
32570
  // src/commands/prs/reviewProposedPrComment.ts
32521
- import { randomUUID as randomUUID17 } from "crypto";
32571
+ import { randomUUID as randomUUID19 } from "crypto";
32522
32572
  async function reviewProposedPrComment(title, body, prNumber) {
32523
32573
  const sessionId = process.env.ASSIST_SESSION_ID;
32524
32574
  if (process.env.ASSIST_SESSION !== "1" || !sessionId) return;
32525
32575
  await awaitPreviewApproval("PR comment preview", {
32526
32576
  sessionId,
32527
- requestId: randomUUID17(),
32577
+ requestId: randomUUID19(),
32528
32578
  title,
32529
32579
  body,
32530
32580
  prNumber,
@@ -33559,7 +33609,7 @@ function parseScreenshotSpecs(specs) {
33559
33609
  }
33560
33610
 
33561
33611
  // src/commands/prs/previewAndApplyEdit.ts
33562
- import { randomUUID as randomUUID18 } from "crypto";
33612
+ import { randomUUID as randomUUID20 } from "crypto";
33563
33613
 
33564
33614
  // src/commands/prs/stageScreenshots.ts
33565
33615
  import { readFile as readFile8 } from "fs/promises";
@@ -33581,7 +33631,7 @@ function stageScreenshots(screenshots = []) {
33581
33631
  async function previewAndApplyEdit(args) {
33582
33632
  const decision = await awaitPreviewApproval("PR preview", {
33583
33633
  sessionId: args.sessionId,
33584
- requestId: randomUUID18(),
33634
+ requestId: randomUUID20(),
33585
33635
  title: args.title ?? args.currentTitle,
33586
33636
  body: args.body,
33587
33637
  prNumber: args.number,
@@ -33916,7 +33966,7 @@ async function placePr(prNumber, title, body, options2, attachments = []) {
33916
33966
  }
33917
33967
 
33918
33968
  // src/commands/prs/previewAndPlace.ts
33919
- import { randomUUID as randomUUID19 } from "crypto";
33969
+ import { randomUUID as randomUUID21 } from "crypto";
33920
33970
 
33921
33971
  // src/commands/review/announcePr.ts
33922
33972
  function announcePr(prNumber) {
@@ -33992,7 +34042,7 @@ function enableAutoMerge() {
33992
34042
  async function previewAndPlace(args) {
33993
34043
  const decision = await awaitPreviewApproval("PR preview", {
33994
34044
  sessionId: args.sessionId,
33995
- requestId: randomUUID19(),
34045
+ requestId: randomUUID21(),
33996
34046
  title: args.title,
33997
34047
  body: args.body,
33998
34048
  prNumber: args.prNumber,
@@ -38519,10 +38569,10 @@ function registerRefactor(program) {
38519
38569
  }
38520
38570
 
38521
38571
  // src/commands/review/checkoutPrSession.ts
38522
- import { randomUUID as randomUUID20 } from "crypto";
38572
+ import { randomUUID as randomUUID22 } from "crypto";
38523
38573
  async function checkoutPrSession(number, prompt = "") {
38524
38574
  await checkoutPr(number);
38525
- const claudeSessionId = randomUUID20();
38575
+ const claudeSessionId = randomUUID22();
38526
38576
  emitActivity({ kind: "command", name: "review", claudeSessionId });
38527
38577
  const { done: done2 } = spawnClaude(prompt, {
38528
38578
  permissionMode: "auto",
@@ -39629,7 +39679,7 @@ function gatherHighLevelSubject(prNumber, force) {
39629
39679
  }
39630
39680
 
39631
39681
  // src/commands/review/highLevel/openHighLevelOverlay.ts
39632
- import { randomUUID as randomUUID22 } from "crypto";
39682
+ import { randomUUID as randomUUID24 } from "crypto";
39633
39683
 
39634
39684
  // src/commands/review/highLevel/highLevelProgress.ts
39635
39685
  function toItem2(check2, decision) {
@@ -39888,7 +39938,7 @@ function splitQueuedComments(record) {
39888
39938
  }
39889
39939
 
39890
39940
  // src/commands/review/highLevel/previewHighLevelReview.ts
39891
- import { randomUUID as randomUUID21 } from "crypto";
39941
+ import { randomUUID as randomUUID23 } from "crypto";
39892
39942
 
39893
39943
  // src/commands/review/highLevel/formatHighLevelReviewPreview.ts
39894
39944
  function formatHighLevelReviewPreview(lineLevel, body) {
@@ -39915,7 +39965,7 @@ async function previewHighLevelReview(sessionId, record, submission) {
39915
39965
  "Review",
39916
39966
  {
39917
39967
  sessionId,
39918
- requestId: randomUUID21(),
39968
+ requestId: randomUUID23(),
39919
39969
  title: `${LABELS[submission.event]} ${record.repo}#${record.prNumber}`,
39920
39970
  body: formatHighLevelReviewPreview(submission.comments, submission.body),
39921
39971
  prNumber: record.prNumber,
@@ -39966,7 +40016,7 @@ async function openHighLevelOverlay(sessionId, subject) {
39966
40016
  "High-level review",
39967
40017
  {
39968
40018
  sessionId,
39969
- requestId: randomUUID22(),
40019
+ requestId: randomUUID24(),
39970
40020
  title: `${subject.repo}#${subject.prNumber} \u2014 ${subject.title}`,
39971
40021
  body: JSON.stringify(highLevelPreviewPayload(subject)),
39972
40022
  prNumber: subject.prNumber,
@@ -43205,7 +43255,7 @@ function registerSeq(program) {
43205
43255
  }
43206
43256
 
43207
43257
  // src/commands/show.ts
43208
- import { randomUUID as randomUUID23 } from "crypto";
43258
+ import { randomUUID as randomUUID25 } from "crypto";
43209
43259
 
43210
43260
  // src/commands/sessions/shared/sendShowPreview.ts
43211
43261
  async function sendShowPreview(request) {
@@ -43257,7 +43307,7 @@ async function show3(options2) {
43257
43307
  try {
43258
43308
  await sendShowPreview({
43259
43309
  sessionId,
43260
- requestId: randomUUID23(),
43310
+ requestId: randomUUID25(),
43261
43311
  title: options2.title ?? "Show",
43262
43312
  body
43263
43313
  });
@@ -43341,7 +43391,7 @@ function readSlackParts(files) {
43341
43391
  }
43342
43392
 
43343
43393
  // src/commands/slack/reviewProposedSlackMessage.ts
43344
- import { randomUUID as randomUUID24 } from "crypto";
43394
+ import { randomUUID as randomUUID26 } from "crypto";
43345
43395
  async function reviewProposedSlackMessage(target, body, workingPath) {
43346
43396
  const sessionId = process.env.ASSIST_SESSION_ID;
43347
43397
  if (process.env.ASSIST_SESSION !== "1" || !sessionId) return;
@@ -43351,7 +43401,7 @@ async function reviewProposedSlackMessage(target, body, workingPath) {
43351
43401
  part ? `Slack message ${part.index} of ${part.total}` : "Slack message preview",
43352
43402
  {
43353
43403
  sessionId,
43354
- requestId: randomUUID24(),
43404
+ requestId: randomUUID26(),
43355
43405
  title: part ? `${destination} (${part.index}/${part.total})` : destination,
43356
43406
  body,
43357
43407
  prNumber: null,
@@ -48359,7 +48409,7 @@ var ClientHub = class extends Set {
48359
48409
  harnessLimits = /* @__PURE__ */ new Map();
48360
48410
  // why: log delivery is opt-in so browser tabs aren't spammed; only connections that ask via subscribe-logs receive daemonLog lines.
48361
48411
  logSubscribers = /* @__PURE__ */ new Set();
48362
- peers = /* @__PURE__ */ new Set();
48412
+ peers = /* @__PURE__ */ new Map();
48363
48413
  updateLimits(rateLimits) {
48364
48414
  this.latestLimits = rateLimits;
48365
48415
  broadcast(this, { type: "limits", rateLimits });
@@ -48386,12 +48436,20 @@ var ClientHub = class extends Set {
48386
48436
  for (const [harness, rateLimits] of this.harnessLimits)
48387
48437
  sendTo(client, { type: "limits", harness, rateLimits });
48388
48438
  }
48389
- markPeer(client) {
48390
- this.peers.add(client);
48439
+ markPeer(client, node) {
48440
+ this.peers.set(client, node);
48391
48441
  }
48392
48442
  isPeer(client) {
48393
48443
  return this.peers.has(client);
48394
48444
  }
48445
+ peerNode(client) {
48446
+ return this.peers.get(client);
48447
+ }
48448
+ peerFor(node) {
48449
+ let latest2;
48450
+ for (const [client, name] of this.peers) if (name === node) latest2 = client;
48451
+ return latest2;
48452
+ }
48395
48453
  viewers() {
48396
48454
  return new Set([...this].filter((client) => !this.peers.has(client)));
48397
48455
  }
@@ -48417,7 +48475,7 @@ var ClientHub = class extends Set {
48417
48475
  };
48418
48476
 
48419
48477
  // src/commands/sessions/daemon/createSession.ts
48420
- import { randomUUID as randomUUID25 } from "crypto";
48478
+ import { randomUUID as randomUUID27 } from "crypto";
48421
48479
 
48422
48480
  // src/commands/sessions/daemon/sessionBase.ts
48423
48481
  function sessionBase(id, status2) {
@@ -48640,7 +48698,7 @@ function spawnRun(opts) {
48640
48698
  function createSession(id, { prompt, cwd, design, auto, harness, holdPty } = {}) {
48641
48699
  if (harness && harness !== "claude")
48642
48700
  return createHarnessSession(id, harness, prompt, cwd, holdPty);
48643
- const claudeSessionId = randomUUID25();
48701
+ const claudeSessionId = randomUUID27();
48644
48702
  return {
48645
48703
  ...sessionBase(id, prompt ? "running" : "waiting"),
48646
48704
  name: `Session ${id}`,
@@ -51546,7 +51604,7 @@ function codexRespawnPlan(session) {
51546
51604
  }
51547
51605
 
51548
51606
  // src/commands/sessions/daemon/interactiveRespawnPlan.ts
51549
- import { randomUUID as randomUUID26 } from "crypto";
51607
+ import { randomUUID as randomUUID28 } from "crypto";
51550
51608
 
51551
51609
  // src/commands/sessions/daemon/hasTranscriptOnDisk.ts
51552
51610
  function hasTranscriptOnDisk(session) {
@@ -51573,7 +51631,7 @@ function interactiveRespawnPlan(session, resumes) {
51573
51631
  return null;
51574
51632
  }
51575
51633
  function freshClaudePlan(session, prompt, cwd) {
51576
- const claudeSessionId = randomUUID26();
51634
+ const claudeSessionId = randomUUID28();
51577
51635
  return {
51578
51636
  spawn: () => {
51579
51637
  session.claudeSessionId = claudeSessionId;
@@ -52977,6 +53035,66 @@ async function collectHistory(linked) {
52977
53035
  return withRepoGroups(local).concat(remote);
52978
53036
  }
52979
53037
 
53038
+ // src/commands/sessions/daemon/pins/PinRelay.ts
53039
+ var ORIGIN_TTL_MS = 30 * 60 * 1e3;
53040
+ var PinRelay = class {
53041
+ constructor(now = Date.now) {
53042
+ this.now = now;
53043
+ }
53044
+ origins = /* @__PURE__ */ new Map();
53045
+ deliveries = /* @__PURE__ */ new Map();
53046
+ confirms = /* @__PURE__ */ new Map();
53047
+ rememberOrigin(area, pin2, node) {
53048
+ this.origins.set(`${area}:${pin2}`, { node, at: this.now() });
53049
+ }
53050
+ takeOrigin(area, pin2) {
53051
+ const key = `${area}:${pin2}`;
53052
+ const origin = this.origins.get(key);
53053
+ this.origins.delete(key);
53054
+ if (!origin || this.now() - origin.at > ORIGIN_TTL_MS) return void 0;
53055
+ return origin.node;
53056
+ }
53057
+ awaitDelivery(requestId, timeoutMs, settle) {
53058
+ addWaiter(this.deliveries, requestId, timeoutMs, false, settle);
53059
+ }
53060
+ settleDelivery(requestId, delivered) {
53061
+ settleWaiter(this.deliveries, requestId, delivered);
53062
+ }
53063
+ awaitConfirm(requestId, client, timeoutMs, node) {
53064
+ addWaiter(
53065
+ this.confirms,
53066
+ requestId,
53067
+ timeoutMs,
53068
+ { ok: false, message: `${node} did not answer the confirmation.` },
53069
+ (result) => sendTo(client, {
53070
+ type: "confirm-pin-result",
53071
+ requestId,
53072
+ found: true,
53073
+ ...result
53074
+ })
53075
+ );
53076
+ }
53077
+ settleConfirm(requestId, result) {
53078
+ settleWaiter(this.confirms, requestId, result);
53079
+ }
53080
+ };
53081
+ function addWaiter(waiters, requestId, timeoutMs, onTimeout, settle) {
53082
+ const timer = setTimeout(
53083
+ () => settleWaiter(waiters, requestId, onTimeout),
53084
+ timeoutMs
53085
+ );
53086
+ timer.unref?.();
53087
+ waiters.set(requestId, { settle, timer });
53088
+ }
53089
+ function settleWaiter(waiters, requestId, value) {
53090
+ if (typeof requestId !== "string") return;
53091
+ const waiter = waiters.get(requestId);
53092
+ if (!waiter) return;
53093
+ waiters.delete(requestId);
53094
+ clearTimeout(waiter.timer);
53095
+ waiter.settle(value);
53096
+ }
53097
+
52980
53098
  // src/commands/sessions/daemon/links/guardLinkCallback.ts
52981
53099
  function guardLinkCallback(label, callback) {
52982
53100
  return (...args) => {
@@ -53006,6 +53124,7 @@ function linkDeps(options2, callbacks) {
53006
53124
  "links: history-changed handler",
53007
53125
  callbacks.onHistoryChanged
53008
53126
  ),
53127
+ pins: callbacks.pins,
53009
53128
  transport: options2.transport ?? connectLinkWebSocket,
53010
53129
  reconnectMs: options2.reconnectMs ?? 3e3,
53011
53130
  blockedRetryMs: options2.blockedRetryMs ?? 6e4,
@@ -53354,6 +53473,31 @@ function relayLinkMessage(state, msg) {
53354
53473
  );
53355
53474
  }
53356
53475
 
53476
+ // src/commands/sessions/daemon/links/showRelayedPin.ts
53477
+ function tryShow(title, message3) {
53478
+ if (typeof title !== "string" || typeof message3 !== "string") return false;
53479
+ try {
53480
+ return showNotification({ title, message: message3 });
53481
+ } catch {
53482
+ return false;
53483
+ }
53484
+ }
53485
+ function showRelayedPin(ctx, msg) {
53486
+ const node = ctx.spec.name;
53487
+ const { area, pin: pin2 } = msg;
53488
+ const valid = typeof area === "string" && typeof pin2 === "string";
53489
+ const delivered = valid && tryShow(msg.title, msg.message);
53490
+ if (delivered) ctx.deps.pins.rememberOrigin(area, pin2, node);
53491
+ daemonLog(
53492
+ `link ${node} ws: ${valid ? area : "malformed"} PIN notification for a session on ${node} ${delivered ? "shown" : "not shown"}`
53493
+ );
53494
+ sendToLink(ctx, {
53495
+ type: "notify-pin-result",
53496
+ requestId: msg.requestId,
53497
+ delivered
53498
+ });
53499
+ }
53500
+
53357
53501
  // src/commands/sessions/daemon/links/scheduleReconnect.ts
53358
53502
  function armReconnect(ctx, delay2) {
53359
53503
  clearTimeout(ctx.reconnectTimer);
@@ -53435,7 +53579,20 @@ function onLinkLine(ctx, line) {
53435
53579
  return;
53436
53580
  }
53437
53581
  if (msg.type === "hello") return onHello(ctx, msg);
53438
- if (ctx.greeted) relayLinkMessage(ctx.relay, msg);
53582
+ if (!ctx.greeted) return;
53583
+ if (msg.type === "notify-pin") return showRelayedPin(ctx, msg);
53584
+ if (msg.type === "confirm-pin-result") return settleRelayedConfirm(ctx, msg);
53585
+ relayLinkMessage(ctx.relay, msg);
53586
+ }
53587
+ function settleRelayedConfirm(ctx, msg) {
53588
+ const ok = msg.ok === true;
53589
+ daemonLog(
53590
+ `link ${ctx.spec.name} ws: PIN confirmation ${ok ? "approved" : "rejected"} by ${ctx.spec.name}`
53591
+ );
53592
+ ctx.deps.pins.settleConfirm(msg.requestId, {
53593
+ ok,
53594
+ message: typeof msg.message === "string" ? msg.message : ""
53595
+ });
53439
53596
  }
53440
53597
 
53441
53598
  // src/commands/sessions/daemon/links/openLink.ts
@@ -53574,6 +53731,7 @@ var NodeLinks = class {
53574
53731
  }
53575
53732
  links = /* @__PURE__ */ new Map();
53576
53733
  options = {};
53734
+ pins = new PinRelay();
53577
53735
  configure(options2) {
53578
53736
  this.options = options2;
53579
53737
  }
@@ -53583,7 +53741,8 @@ var NodeLinks = class {
53583
53741
  viewers: () => this.clients.viewers(),
53584
53742
  onSessionsChanged: this.onSessionsChanged,
53585
53743
  onStateChanged: () => broadcast(this.clients.viewers(), this.nodes()),
53586
- onHistoryChanged: () => void this.broadcastHistory()
53744
+ onHistoryChanged: () => void this.broadcastHistory(),
53745
+ pins: this.pins
53587
53746
  });
53588
53747
  reconcileLinks(this.links, specs, (spec) => new NodeLink(spec, deps2));
53589
53748
  this.onSessionsChanged();
@@ -54135,7 +54294,10 @@ var handleHelloRequest = (client, m, d) => {
54135
54294
  daemonLog(
54136
54295
  `peer link from ${d.nodeName ?? "unknown node"} (${d.version ?? "unknown version"}); exporting local sessions only`
54137
54296
  );
54138
- m.clients.markPeer(client);
54297
+ m.clients.markPeer(
54298
+ client,
54299
+ typeof d.nodeName === "string" ? d.nodeName : void 0
54300
+ );
54139
54301
  sendTo(client, { type: "sessions", sessions: m.localSessions(), active: {} });
54140
54302
  m.replayLocal(client);
54141
54303
  };
@@ -54708,6 +54870,121 @@ var lifecycleHandlers = {
54708
54870
  shutdown: handleShutdown
54709
54871
  };
54710
54872
 
54873
+ // src/commands/sessions/daemon/pins/pinConfirmers.ts
54874
+ var pinConfirmers = {
54875
+ docs: approveDocsUnlock
54876
+ };
54877
+
54878
+ // src/commands/sessions/daemon/pins/confirmPinLocally.ts
54879
+ async function confirmPinLocally(area, pin2) {
54880
+ const confirm = pinConfirmers[area];
54881
+ if (!confirm)
54882
+ return { ok: false, message: `Unknown confirmation area ${area}.` };
54883
+ try {
54884
+ return await confirm(pin2) ?? {
54885
+ ok: false,
54886
+ message: `No pending ${area} confirmation for that pin.`
54887
+ };
54888
+ } catch (error) {
54889
+ return {
54890
+ ok: false,
54891
+ message: error instanceof Error ? error.message : String(error)
54892
+ };
54893
+ }
54894
+ }
54895
+
54896
+ // src/commands/sessions/daemon/pins/handleConfirmPin.ts
54897
+ var CONFIRM_TIMEOUT_MS2 = 1e4;
54898
+ var handlePeerConfirm = (client, m, d) => {
54899
+ const area = String(d.area);
54900
+ const from = m.clients.peerNode(client) ?? "unknown node";
54901
+ void confirmPinLocally(area, String(d.pin)).then((result) => {
54902
+ daemonLog(
54903
+ `confirm-pin: ${area} confirmation relayed from ${from} ${result.ok ? "approved" : "rejected"}`
54904
+ );
54905
+ sendTo(client, {
54906
+ type: "confirm-pin-result",
54907
+ requestId: d.requestId,
54908
+ ...result
54909
+ });
54910
+ });
54911
+ };
54912
+ var handleConfirmPin = (client, m, d) => {
54913
+ if (m.clients.isPeer(client)) return handlePeerConfirm(client, m, d);
54914
+ const area = String(d.area);
54915
+ const requestId = String(d.requestId);
54916
+ const node = m.links.pins.takeOrigin(area, String(d.pin));
54917
+ if (!node) {
54918
+ daemonLog(`confirm-pin: no relayed ${area} PIN matches; nothing forwarded`);
54919
+ sendTo(client, { type: "confirm-pin-result", requestId, found: false });
54920
+ return;
54921
+ }
54922
+ daemonLog(`confirm-pin: forwarding ${area} confirmation to ${node}`);
54923
+ m.links.pins.awaitConfirm(requestId, client, CONFIRM_TIMEOUT_MS2, node);
54924
+ m.links.route(client, { ...d, node });
54925
+ };
54926
+
54927
+ // src/commands/sessions/daemon/pins/pinNotificationTarget.ts
54928
+ function pinNotificationTarget(viewerNode, localNode, peerFor) {
54929
+ if (!viewerNode) return { kind: "local", reason: "has no active viewer" };
54930
+ if (viewerNode === localNode)
54931
+ return { kind: "local", reason: "is controlled from this node" };
54932
+ const peer = peerFor(viewerNode);
54933
+ if (!peer)
54934
+ return {
54935
+ kind: "local",
54936
+ reason: `is controlled from ${viewerNode}, which has no peer link here`
54937
+ };
54938
+ return { kind: "peer", node: viewerNode, peer };
54939
+ }
54940
+
54941
+ // src/commands/sessions/daemon/pins/handleNotifyPin.ts
54942
+ var DELIVERY_TIMEOUT_MS = 5e3;
54943
+ var handleNotifyPin = (client, m, d) => {
54944
+ const { sessionId, requestId, area } = d;
54945
+ const reply2 = (node) => sendTo(client, { type: "notify-pin-result", requestId, node });
54946
+ const target = pinNotificationTarget(
54947
+ m.localSessions().find((s) => s.id === sessionId)?.activeViewerNode,
54948
+ m.links.localNode(),
54949
+ (node) => m.clients.peerFor(node)
54950
+ );
54951
+ if (target.kind === "local") {
54952
+ daemonLog(
54953
+ `notify-pin: session ${sessionId} ${target.reason}; ${area} PIN notifies locally`
54954
+ );
54955
+ return reply2();
54956
+ }
54957
+ daemonLog(
54958
+ `notify-pin: session ${sessionId} relaying ${area} PIN notification to ${target.node}`
54959
+ );
54960
+ m.links.pins.awaitDelivery(
54961
+ String(requestId),
54962
+ DELIVERY_TIMEOUT_MS,
54963
+ (delivered) => {
54964
+ daemonLog(
54965
+ `notify-pin: session ${sessionId} ${area} PIN ${delivered ? `shown on ${target.node}` : `not shown on ${target.node}; notifying locally`}`
54966
+ );
54967
+ reply2(delivered ? target.node : void 0);
54968
+ }
54969
+ );
54970
+ const { title, message: message3, pin: pin2 } = d;
54971
+ sendTo(target.peer, {
54972
+ type: "notify-pin",
54973
+ requestId,
54974
+ area,
54975
+ pin: pin2,
54976
+ title,
54977
+ message: message3
54978
+ });
54979
+ };
54980
+
54981
+ // src/commands/sessions/daemon/pins/pinHandlers.ts
54982
+ var pinHandlers = {
54983
+ "notify-pin": handleNotifyPin,
54984
+ "notify-pin-result": (_client, m, d) => m.links.pins.settleDelivery(d.requestId, d.delivered === true),
54985
+ "confirm-pin": handleConfirmPin
54986
+ };
54987
+
54711
54988
  // src/commands/sessions/daemon/handleSnapshotRequest.ts
54712
54989
  var handleSnapshotRequest = (client, m, d) => {
54713
54990
  const sessionId = d.sessionId;
@@ -54946,6 +55223,7 @@ var messageHandlers = {
54946
55223
  ),
54947
55224
  "codex-usage": handleCodexUsage,
54948
55225
  ...viewerHandlers,
55226
+ ...pinHandlers,
54949
55227
  "type-prompt": handleTypePrompt,
54950
55228
  "type-prompt-to-writer": handleTypePromptToWriter,
54951
55229
  retry: routed((client, m, d) => {