@staff0rd/assist 0.716.2 → 0.717.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.716.2",
9
+ version: "0.717.0",
10
10
  type: "module",
11
11
  main: "dist/index.js",
12
12
  bin: {
@@ -43928,6 +43928,7 @@ function linkDeps(options2, callbacks) {
43928
43928
  tunnel: options2.tunnel ?? sshTunnelFor,
43929
43929
  heal: options2.heal ?? selfUpdatePeer,
43930
43930
  reconnectMs: options2.reconnectMs ?? 3e3,
43931
+ blockedRetryMs: options2.blockedRetryMs ?? 6e4,
43931
43932
  createTimeoutMs: options2.createTimeoutMs ?? 15e3
43932
43933
  };
43933
43934
  }
@@ -44145,7 +44146,7 @@ function linkHealRefusal(node, peerVersion, healAttempted) {
44145
44146
  if (peerIsNewer(peerVersion))
44146
44147
  return `This node (${ASSIST_VERSION}) is older than ${node} (${peerVersion}); update this node and restart its daemon.`;
44147
44148
  if (healAttempted)
44148
- return `${node} is still on ${peerVersion} after auto-update (this node is ${ASSIST_VERSION}); update ${node} manually, then restart this daemon.`;
44149
+ return `${node} is still on ${peerVersion} after auto-update (this node is ${ASSIST_VERSION}); update ${node} manually; this node reconnects once it reports a compatible version.`;
44149
44150
  return void 0;
44150
44151
  }
44151
44152
 
@@ -44156,7 +44157,8 @@ function armReconnect(ctx, delay3) {
44156
44157
  ctx.reconnectTimer.unref?.();
44157
44158
  }
44158
44159
  function scheduleReconnect2(ctx) {
44159
- if (ctx.disposed || ctx.blockedMessage) return;
44160
+ if (ctx.disposed) return;
44161
+ if (ctx.blockedMessage) return armReconnect(ctx, ctx.deps.blockedRetryMs);
44160
44162
  const delay3 = ctx.breaker.tripped() ? ctx.breaker.remainingMs() : ctx.deps.reconnectMs;
44161
44163
  armReconnect(ctx, delay3);
44162
44164
  }
@@ -44187,11 +44189,12 @@ function failLink(ctx, message3) {
44187
44189
  scheduleReconnect2(ctx);
44188
44190
  }
44189
44191
  function blockLink(ctx, message3) {
44192
+ const repeat = ctx.blockedMessage === message3;
44190
44193
  ctx.blockedMessage = message3;
44191
- clearTimeout(ctx.reconnectTimer);
44192
44194
  disconnectLink(ctx);
44193
44195
  setLinkState(ctx, "version-blocked");
44194
- broadcastToViewers(ctx.relay, { type: "error", message: message3 });
44196
+ if (!repeat) broadcastToViewers(ctx.relay, { type: "error", message: message3 });
44197
+ scheduleReconnect2(ctx);
44195
44198
  }
44196
44199
 
44197
44200
  // src/commands/sessions/daemon/links/runLinkHeal.ts
@@ -44233,7 +44236,8 @@ var LinkHealer = class {
44233
44236
  const refusal = linkHealRefusal(node, peerVersion, this.healAttempted);
44234
44237
  if (refusal) {
44235
44238
  this.awaitingConfirmation = false;
44236
- daemonLog(`link ${node} heal: latched, not reconnecting: ${refusal}`);
44239
+ if (this.ctx.blockedMessage !== refusal)
44240
+ daemonLog(`link ${node} heal: latched, retrying slowly: ${refusal}`);
44237
44241
  return blockLink(this.ctx, refusal);
44238
44242
  }
44239
44243
  this.healing = true;
@@ -44245,6 +44249,10 @@ var LinkHealer = class {
44245
44249
  this.healing = false;
44246
44250
  }
44247
44251
  }
44252
+ reset() {
44253
+ this.healAttempted = false;
44254
+ this.awaitingConfirmation = false;
44255
+ }
44248
44256
  onCompatible() {
44249
44257
  if (!this.awaitingConfirmation) return;
44250
44258
  this.awaitingConfirmation = false;
@@ -44381,6 +44389,11 @@ function onHello(ctx, msg) {
44381
44389
  return failLink(ctx, verdict.reason);
44382
44390
  }
44383
44391
  if (verdict.kind === "heal") return ctx.onMismatch(verdict.peer.version);
44392
+ if (ctx.blockedMessage)
44393
+ daemonLog(
44394
+ `link ${ctx.spec.name} heal: peer now reports ${verdict.peer.version}; latch cleared`
44395
+ );
44396
+ ctx.blockedMessage = void 0;
44384
44397
  ctx.greeted = true;
44385
44398
  ctx.breaker.clear();
44386
44399
  ctx.lastError = void 0;
@@ -44407,9 +44420,9 @@ function onLinkClose(ctx, socket, reason4) {
44407
44420
  scheduleReconnect2(ctx);
44408
44421
  }
44409
44422
  async function openLink(ctx) {
44410
- if (ctx.disposed || ctx.blockedMessage || ctx.socket) return;
44423
+ if (ctx.disposed || ctx.socket) return;
44411
44424
  if (ctx.breaker.tripped()) return scheduleReconnect2(ctx);
44412
- setLinkState(ctx, "connecting");
44425
+ if (!ctx.blockedMessage) setLinkState(ctx, "connecting");
44413
44426
  try {
44414
44427
  await ctx.tunnel?.ready();
44415
44428
  if (ctx.disposed) return;
@@ -44460,9 +44473,19 @@ var NodeLink = class {
44460
44473
  ctx.onMismatch = (version2) => void healer.onMismatch(version2);
44461
44474
  ctx.onCompatible = () => healer.onCompatible();
44462
44475
  this.ctx = ctx;
44476
+ this.healer = healer;
44463
44477
  }
44464
44478
  ctx;
44479
+ healer;
44465
44480
  start = () => this.ctx.connect();
44481
+ unlatch() {
44482
+ if (!this.ctx.blockedMessage) return;
44483
+ daemonLog(`link ${this.spec.name} heal: latch cleared by reload`);
44484
+ this.ctx.blockedMessage = void 0;
44485
+ this.healer.reset();
44486
+ setLinkState(this.ctx, "disconnected");
44487
+ reconnectNow(this.ctx);
44488
+ }
44466
44489
  sessions = () => this.ctx.relay.sessions;
44467
44490
  status = () => describeLink(this.ctx);
44468
44491
  history = () => requestLinkHistory(this.ctx);
@@ -44487,7 +44510,10 @@ function sameTarget(wanted, current) {
44487
44510
  function reconcileLinks(links2, specs, create) {
44488
44511
  const wanted = new Map(specs.map((spec) => [spec.name, spec]));
44489
44512
  for (const [name, link3] of links2) {
44490
- if (sameTarget(wanted.get(name), link3.spec)) continue;
44513
+ if (sameTarget(wanted.get(name), link3.spec)) {
44514
+ link3.unlatch();
44515
+ continue;
44516
+ }
44491
44517
  daemonLog(`link ${name}: removed`);
44492
44518
  link3.dispose();
44493
44519
  links2.delete(name);
@@ -45211,6 +45237,27 @@ function handleCreateRun(client, m, d) {
45211
45237
  });
45212
45238
  }
45213
45239
 
45240
+ // src/commands/sessions/daemon/handleOutputRequest.ts
45241
+ var handleOutputRequest = (client, m, d) => {
45242
+ const sessionId = d.sessionId;
45243
+ let scrollback;
45244
+ m.update((sessions) => {
45245
+ scrollback = sessions.get(sessionId)?.scrollback;
45246
+ return false;
45247
+ });
45248
+ daemonLog(
45249
+ `output requested: id=${sessionId} ${scrollback === void 0 ? "unknown session" : `${scrollback.length} chars`}`
45250
+ );
45251
+ sendTo(
45252
+ client,
45253
+ scrollback === void 0 ? {
45254
+ type: "session-output",
45255
+ sessionId,
45256
+ error: `No session ${sessionId} on this node`
45257
+ } : { type: "session-output", sessionId, scrollback }
45258
+ );
45259
+ };
45260
+
45214
45261
  // src/commands/sessions/daemon/handleSetStatus.ts
45215
45262
  function handleSetStatus(client, m, d) {
45216
45263
  daemonLog(
@@ -45481,10 +45528,12 @@ var messageHandlers = {
45481
45528
  ping: (client) => sendTo(client, { type: "pong", pid: process.pid }),
45482
45529
  "subscribe-logs": (client, m, d) => m.clients.subscribeLogs(client, d.replay !== false),
45483
45530
  hello: handleHelloRequest,
45531
+ output: handleOutputRequest,
45484
45532
  nodes: (client, m) => m.links.sendNodes(client),
45485
- "reload-links": (_client, m) => {
45533
+ "reload-links": (client, m) => {
45486
45534
  daemonLog("reload-links received");
45487
45535
  m.links.reload();
45536
+ sendTo(client, { type: "ack" });
45488
45537
  },
45489
45538
  create: creator(true, spawnCreate),
45490
45539
  "create-run": handleCreateRun,
@@ -46186,7 +46235,31 @@ async function doctorNodes(name, options2) {
46186
46235
  }
46187
46236
 
46188
46237
  // src/commands/sessions/nodes/linkNode.ts
46238
+ import chalk252 from "chalk";
46239
+
46240
+ // src/commands/sessions/nodes/notifyDaemonLinks.ts
46189
46241
  import chalk251 from "chalk";
46242
+ async function notifyDaemonLinks() {
46243
+ if (!await isDaemonRunning()) {
46244
+ console.log(
46245
+ chalk251.yellow(
46246
+ "The sessions daemon is not running; it loads the links when it starts."
46247
+ )
46248
+ );
46249
+ return;
46250
+ }
46251
+ try {
46252
+ await sendToDaemonAwaitAck({ type: "reload-links" });
46253
+ console.log(chalk251.dim("The sessions daemon reloaded its links."));
46254
+ } catch (error) {
46255
+ const message3 = error instanceof Error ? error.message : String(error);
46256
+ console.log(
46257
+ chalk251.yellow(
46258
+ `Could not notify the sessions daemon (${message3}); run \`assist daemon restart\` to apply the change.`
46259
+ )
46260
+ );
46261
+ }
46262
+ }
46190
46263
 
46191
46264
  // src/commands/sessions/nodes/writeLinks.ts
46192
46265
  function readLinks() {
@@ -46202,7 +46275,6 @@ async function writeLinks(links2) {
46202
46275
  const validation = validateConfig(updated2, "sessions.links");
46203
46276
  if (!validation.ok) throw new Error(validation.errors.join("\n"));
46204
46277
  saveGlobalConfig(updated2);
46205
- if (await isDaemonRunning()) await sendToDaemon({ type: "reload-links" });
46206
46278
  }
46207
46279
 
46208
46280
  // src/commands/sessions/nodes/linkNode.ts
@@ -46242,12 +46314,13 @@ async function linkNode(name, url, options2) {
46242
46314
  const link3 = buildLink(name, url, options2, others);
46243
46315
  await writeLinks([...others, link3]);
46244
46316
  console.log(
46245
- chalk251.green(`Linked ${name} (${describeTarget(toLinkSpec(link3))})`)
46317
+ chalk252.green(`Linked ${name} (${describeTarget(toLinkSpec(link3))})`)
46246
46318
  );
46319
+ await notifyDaemonLinks();
46247
46320
  }
46248
46321
 
46249
46322
  // src/commands/sessions/nodes/listNodes.ts
46250
- import chalk252 from "chalk";
46323
+ import chalk253 from "chalk";
46251
46324
  async function nodesReport() {
46252
46325
  const live = await queryNodes();
46253
46326
  if (live)
@@ -46264,10 +46337,10 @@ async function listNodes(options2) {
46264
46337
  console.log(JSON.stringify(report2, null, 2));
46265
46338
  return;
46266
46339
  }
46267
- console.log(`${report2.local} ${chalk252.dim("(this node)")}`);
46340
+ console.log(`${report2.local} ${chalk253.dim("(this node)")}`);
46268
46341
  if (!report2.daemonRunning)
46269
- console.log(chalk252.dim(" daemon not running; showing configured links"));
46270
- if (report2.links.length === 0) console.log(chalk252.dim(" no links"));
46342
+ console.log(chalk253.dim(" daemon not running; showing configured links"));
46343
+ if (report2.links.length === 0) console.log(chalk253.dim(" no links"));
46271
46344
  for (const link3 of report2.links) console.log(formatLink(link3));
46272
46345
  }
46273
46346
 
@@ -46306,16 +46379,17 @@ async function nodeLogs(name, options2) {
46306
46379
  }
46307
46380
 
46308
46381
  // src/commands/sessions/nodes/unlinkNode.ts
46309
- import chalk253 from "chalk";
46382
+ import chalk254 from "chalk";
46310
46383
  async function unlinkNode(name) {
46311
46384
  const links2 = readLinks();
46312
46385
  const remaining = links2.filter((link3) => link3.name !== name);
46313
46386
  if (remaining.length === links2.length) {
46314
- console.log(chalk253.yellow(`No link named ${name}`));
46387
+ console.log(chalk254.yellow(`No link named ${name}`));
46315
46388
  return;
46316
46389
  }
46317
46390
  await writeLinks(remaining);
46318
- console.log(chalk253.green(`Unlinked ${name}`));
46391
+ console.log(chalk254.green(`Unlinked ${name}`));
46392
+ await notifyDaemonLinks();
46319
46393
  }
46320
46394
 
46321
46395
  // src/commands/sessions/nodes/registerNodes.ts
@@ -46373,9 +46447,64 @@ async function renameSession(title) {
46373
46447
  }
46374
46448
  }
46375
46449
 
46450
+ // src/commands/sessions/daemon/requestSessionOutput.ts
46451
+ import { createInterface as createInterface12 } from "readline";
46452
+ var OUTPUT_TIMEOUT_MS = 5e3;
46453
+ async function requestSessionOutput(sessionId) {
46454
+ const socket = await connectToDaemon().catch(() => {
46455
+ throw new Error("No sessions daemon is running");
46456
+ });
46457
+ try {
46458
+ const lines2 = createInterface12({ input: socket });
46459
+ lines2.on("error", () => {
46460
+ });
46461
+ const reply2 = readDaemonMessage(
46462
+ lines2,
46463
+ OUTPUT_TIMEOUT_MS,
46464
+ { error: "Timed out waiting for the sessions daemon" },
46465
+ (data) => data.type === "session-output" && data.sessionId === sessionId ? data : void 0
46466
+ );
46467
+ socket.write(`${JSON.stringify({ type: "output", sessionId })}
46468
+ `);
46469
+ const { scrollback, error } = await reply2;
46470
+ if (scrollback === void 0) throw new Error(error);
46471
+ return scrollback;
46472
+ } finally {
46473
+ socket.destroy();
46474
+ }
46475
+ }
46476
+
46477
+ // src/commands/sessions/lastLines.ts
46478
+ function lastLines(scrollback, count8) {
46479
+ const lines2 = stripAnsi(scrollback).split(/\r?\n/);
46480
+ if (lines2.at(-1) === "") lines2.pop();
46481
+ return lines2.slice(-count8);
46482
+ }
46483
+
46484
+ // src/commands/sessions/sessionOutput.ts
46485
+ async function sessionOutput(sessionId, options2) {
46486
+ const count8 = Number.parseInt(options2.lines, 10);
46487
+ if (!Number.isInteger(count8) || count8 < 1)
46488
+ return fail7(`-n must be a positive integer, got ${options2.lines}`);
46489
+ if (sessionId.includes(":"))
46490
+ return fail7(
46491
+ `Session ${sessionId} is on a linked node; reading linked-node sessions is not supported yet`
46492
+ );
46493
+ try {
46494
+ const scrollback = await requestSessionOutput(sessionId);
46495
+ for (const line of lastLines(scrollback, count8)) console.log(line);
46496
+ } catch (error) {
46497
+ fail7(error instanceof Error ? error.message : String(error));
46498
+ }
46499
+ }
46500
+ function fail7(message3) {
46501
+ console.error(message3);
46502
+ process.exitCode = 1;
46503
+ }
46504
+
46376
46505
  // src/commands/sessions/summarise.ts
46377
46506
  import * as fs58 from "fs";
46378
- import chalk254 from "chalk";
46507
+ import chalk255 from "chalk";
46379
46508
 
46380
46509
  // src/commands/sessions/summarise/shared.ts
46381
46510
  import * as fs57 from "fs";
@@ -46434,22 +46563,22 @@ ${firstMessage}`);
46434
46563
  async function summarise2(options2) {
46435
46564
  const files = await discoverSessionFiles();
46436
46565
  if (files.length === 0) {
46437
- console.log(chalk254.yellow("No sessions found."));
46566
+ console.log(chalk255.yellow("No sessions found."));
46438
46567
  return;
46439
46568
  }
46440
46569
  const toProcess = selectCandidates(files, options2);
46441
46570
  if (toProcess.length === 0) {
46442
- console.log(chalk254.green("All sessions already summarised."));
46571
+ console.log(chalk255.green("All sessions already summarised."));
46443
46572
  return;
46444
46573
  }
46445
46574
  console.log(
46446
- chalk254.cyan(
46575
+ chalk255.cyan(
46447
46576
  `Summarising ${toProcess.length} session(s) (${files.length} total)\u2026`
46448
46577
  )
46449
46578
  );
46450
46579
  const { succeeded, failed: failed3 } = processSessions(toProcess);
46451
46580
  console.log(
46452
- chalk254.green(`Done: ${succeeded} summarised`) + (failed3 > 0 ? chalk254.yellow(`, ${failed3} skipped`) : "")
46581
+ chalk255.green(`Done: ${succeeded} summarised`) + (failed3 > 0 ? chalk255.yellow(`, ${failed3} skipped`) : "")
46453
46582
  );
46454
46583
  }
46455
46584
  function selectCandidates(files, options2) {
@@ -46469,16 +46598,16 @@ function processSessions(files) {
46469
46598
  let failed3 = 0;
46470
46599
  for (let i = 0; i < files.length; i++) {
46471
46600
  const file = files[i];
46472
- process.stdout.write(chalk254.dim(` [${i + 1}/${files.length}] `));
46601
+ process.stdout.write(chalk255.dim(` [${i + 1}/${files.length}] `));
46473
46602
  const summary = summariseSession(file);
46474
46603
  if (summary) {
46475
46604
  writeSummary(file, summary);
46476
46605
  succeeded++;
46477
- process.stdout.write(`${chalk254.green("\u2713")} ${summary}
46606
+ process.stdout.write(`${chalk255.green("\u2713")} ${summary}
46478
46607
  `);
46479
46608
  } else {
46480
46609
  failed3++;
46481
- process.stdout.write(` ${chalk254.yellow("skip")}
46610
+ process.stdout.write(` ${chalk255.yellow("skip")}
46482
46611
  `);
46483
46612
  }
46484
46613
  }
@@ -46500,16 +46629,19 @@ function registerSessions(program2) {
46500
46629
  cmd.command("rename <title>").description(
46501
46630
  "Retitle the current daemon-managed session, overriding the generated title for the rest of its life"
46502
46631
  ).action(renameSession);
46632
+ cmd.command("output <session-id>").description(
46633
+ "Print a snapshot of a session's output with ANSI codes stripped"
46634
+ ).option("-n, --lines <count>", "Number of lines", "200").action(sessionOutput);
46503
46635
  registerSetStatusCommand(cmd);
46504
46636
  registerNodes(cmd);
46505
46637
  configHelp(cmd, sessionsConfigHelp);
46506
46638
  }
46507
46639
 
46508
46640
  // src/reportCliError.ts
46509
- import chalk255 from "chalk";
46641
+ import chalk256 from "chalk";
46510
46642
  function reportCliError(error) {
46511
46643
  if (error instanceof InvalidItemIdError || error instanceof AmbiguousRepoConfigError || error instanceof UnknownRepoConfigError || error instanceof MissingRunCwdError || error instanceof MiroExtractError) {
46512
- console.error(chalk255.red(error.message));
46644
+ console.error(chalk256.red(error.message));
46513
46645
  } else {
46514
46646
  console.error(error);
46515
46647
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@staff0rd/assist",
3
- "version": "0.716.2",
3
+ "version": "0.717.0",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "bin": {