@staff0rd/assist 0.716.1 → 0.716.3

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.1",
9
+ version: "0.716.3",
10
10
  type: "module",
11
11
  main: "dist/index.js",
12
12
  bin: {
@@ -14108,12 +14108,30 @@ import {
14108
14108
  request as httpRequest
14109
14109
  } from "http";
14110
14110
  import { request as httpsRequest } from "https";
14111
+
14112
+ // src/commands/sessions/web/isQuietPoll.ts
14113
+ var POLLED_PATHS = /* @__PURE__ */ new Set(["/api/git-status"]);
14114
+ function isQuietPoll(pathname, status3) {
14115
+ return POLLED_PATHS.has(pathname) && status3 >= 200 && status3 < 300;
14116
+ }
14117
+
14118
+ // src/commands/sessions/web/relayPeerResponse.ts
14119
+ function relayPeerResponse(peer, res, pathname, log2, done2) {
14120
+ const status3 = peer.statusCode ?? 502;
14121
+ if (!isQuietPoll(pathname, status3)) log2(String(status3));
14122
+ res.writeHead(status3, peer.headers);
14123
+ peer.pipe(res);
14124
+ peer.on("end", done2);
14125
+ peer.on("error", done2);
14126
+ }
14127
+
14128
+ // src/commands/sessions/web/forwardToPeer.ts
14111
14129
  var LINKED_FROM_HEADER = "x-assist-linked-from";
14112
14130
  function forwardToPeer(req, res, node, url) {
14113
14131
  const started = Date.now();
14114
14132
  const traceId = newTraceId();
14115
14133
  const label2 = `link ${node} http: ${req.method} ${url.pathname} trace=${traceId}`;
14116
- const elapsed = () => `${Date.now() - started}ms`;
14134
+ const log2 = (outcome) => console.log(`${label2} -> ${outcome} (${Date.now() - started}ms)`);
14117
14135
  const send = url.protocol === "https:" ? httpsRequest : httpRequest;
14118
14136
  return new Promise((resolve25) => {
14119
14137
  const upstream = send(
@@ -14127,16 +14145,10 @@ function forwardToPeer(req, res, node, url) {
14127
14145
  [TRACE_HEADER]: traceId
14128
14146
  }
14129
14147
  },
14130
- (peer) => {
14131
- console.log(`${label2} -> ${peer.statusCode} (${elapsed()})`);
14132
- res.writeHead(peer.statusCode ?? 502, peer.headers);
14133
- peer.pipe(res);
14134
- peer.on("end", resolve25);
14135
- peer.on("error", () => resolve25());
14136
- }
14148
+ (peer) => relayPeerResponse(peer, res, url.pathname, log2, resolve25)
14137
14149
  );
14138
14150
  upstream.on("error", (error) => {
14139
- console.log(`${label2} -> failed: ${error.message} (${elapsed()})`);
14151
+ log2(`failed: ${error.message}`);
14140
14152
  if (res.headersSent) res.destroy();
14141
14153
  else
14142
14154
  respondJson(res, 502, {
@@ -14173,12 +14185,12 @@ function logLinkedRequest(req, res) {
14173
14185
  const from = req.headers[LINKED_FROM_HEADER2];
14174
14186
  const trace = req.headers[TRACE_HEADER] ?? "none";
14175
14187
  const path103 = new URL(req.url ?? "/", "http://localhost").pathname;
14176
- res.once(
14177
- "finish",
14178
- () => console.log(
14188
+ res.once("finish", () => {
14189
+ if (isQuietPoll(path103, res.statusCode)) return;
14190
+ console.log(
14179
14191
  `link-from ${from} http: ${req.method} ${path103} trace=${trace} -> ${res.statusCode} (${Date.now() - started}ms)`
14180
- )
14181
- );
14192
+ );
14193
+ });
14182
14194
  }
14183
14195
  async function proxyToNode(req, res) {
14184
14196
  if (arrivedOverLink(req)) logLinkedRequest(req, res);
@@ -43916,6 +43928,7 @@ function linkDeps(options2, callbacks) {
43916
43928
  tunnel: options2.tunnel ?? sshTunnelFor,
43917
43929
  heal: options2.heal ?? selfUpdatePeer,
43918
43930
  reconnectMs: options2.reconnectMs ?? 3e3,
43931
+ blockedRetryMs: options2.blockedRetryMs ?? 6e4,
43919
43932
  createTimeoutMs: options2.createTimeoutMs ?? 15e3
43920
43933
  };
43921
43934
  }
@@ -44133,7 +44146,7 @@ function linkHealRefusal(node, peerVersion, healAttempted) {
44133
44146
  if (peerIsNewer(peerVersion))
44134
44147
  return `This node (${ASSIST_VERSION}) is older than ${node} (${peerVersion}); update this node and restart its daemon.`;
44135
44148
  if (healAttempted)
44136
- 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.`;
44137
44150
  return void 0;
44138
44151
  }
44139
44152
 
@@ -44144,7 +44157,8 @@ function armReconnect(ctx, delay3) {
44144
44157
  ctx.reconnectTimer.unref?.();
44145
44158
  }
44146
44159
  function scheduleReconnect2(ctx) {
44147
- if (ctx.disposed || ctx.blockedMessage) return;
44160
+ if (ctx.disposed) return;
44161
+ if (ctx.blockedMessage) return armReconnect(ctx, ctx.deps.blockedRetryMs);
44148
44162
  const delay3 = ctx.breaker.tripped() ? ctx.breaker.remainingMs() : ctx.deps.reconnectMs;
44149
44163
  armReconnect(ctx, delay3);
44150
44164
  }
@@ -44175,11 +44189,12 @@ function failLink(ctx, message3) {
44175
44189
  scheduleReconnect2(ctx);
44176
44190
  }
44177
44191
  function blockLink(ctx, message3) {
44192
+ const repeat = ctx.blockedMessage === message3;
44178
44193
  ctx.blockedMessage = message3;
44179
- clearTimeout(ctx.reconnectTimer);
44180
44194
  disconnectLink(ctx);
44181
44195
  setLinkState(ctx, "version-blocked");
44182
- broadcastToViewers(ctx.relay, { type: "error", message: message3 });
44196
+ if (!repeat) broadcastToViewers(ctx.relay, { type: "error", message: message3 });
44197
+ scheduleReconnect2(ctx);
44183
44198
  }
44184
44199
 
44185
44200
  // src/commands/sessions/daemon/links/runLinkHeal.ts
@@ -44221,7 +44236,8 @@ var LinkHealer = class {
44221
44236
  const refusal = linkHealRefusal(node, peerVersion, this.healAttempted);
44222
44237
  if (refusal) {
44223
44238
  this.awaitingConfirmation = false;
44224
- daemonLog(`link ${node} heal: latched, not reconnecting: ${refusal}`);
44239
+ if (this.ctx.blockedMessage !== refusal)
44240
+ daemonLog(`link ${node} heal: latched, retrying slowly: ${refusal}`);
44225
44241
  return blockLink(this.ctx, refusal);
44226
44242
  }
44227
44243
  this.healing = true;
@@ -44233,6 +44249,10 @@ var LinkHealer = class {
44233
44249
  this.healing = false;
44234
44250
  }
44235
44251
  }
44252
+ reset() {
44253
+ this.healAttempted = false;
44254
+ this.awaitingConfirmation = false;
44255
+ }
44236
44256
  onCompatible() {
44237
44257
  if (!this.awaitingConfirmation) return;
44238
44258
  this.awaitingConfirmation = false;
@@ -44369,6 +44389,11 @@ function onHello(ctx, msg) {
44369
44389
  return failLink(ctx, verdict.reason);
44370
44390
  }
44371
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;
44372
44397
  ctx.greeted = true;
44373
44398
  ctx.breaker.clear();
44374
44399
  ctx.lastError = void 0;
@@ -44395,9 +44420,9 @@ function onLinkClose(ctx, socket, reason4) {
44395
44420
  scheduleReconnect2(ctx);
44396
44421
  }
44397
44422
  async function openLink(ctx) {
44398
- if (ctx.disposed || ctx.blockedMessage || ctx.socket) return;
44423
+ if (ctx.disposed || ctx.socket) return;
44399
44424
  if (ctx.breaker.tripped()) return scheduleReconnect2(ctx);
44400
- setLinkState(ctx, "connecting");
44425
+ if (!ctx.blockedMessage) setLinkState(ctx, "connecting");
44401
44426
  try {
44402
44427
  await ctx.tunnel?.ready();
44403
44428
  if (ctx.disposed) return;
@@ -44448,9 +44473,19 @@ var NodeLink = class {
44448
44473
  ctx.onMismatch = (version2) => void healer.onMismatch(version2);
44449
44474
  ctx.onCompatible = () => healer.onCompatible();
44450
44475
  this.ctx = ctx;
44476
+ this.healer = healer;
44451
44477
  }
44452
44478
  ctx;
44479
+ healer;
44453
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
+ }
44454
44489
  sessions = () => this.ctx.relay.sessions;
44455
44490
  status = () => describeLink(this.ctx);
44456
44491
  history = () => requestLinkHistory(this.ctx);
@@ -44475,7 +44510,10 @@ function sameTarget(wanted, current) {
44475
44510
  function reconcileLinks(links2, specs, create) {
44476
44511
  const wanted = new Map(specs.map((spec) => [spec.name, spec]));
44477
44512
  for (const [name, link3] of links2) {
44478
- if (sameTarget(wanted.get(name), link3.spec)) continue;
44513
+ if (sameTarget(wanted.get(name), link3.spec)) {
44514
+ link3.unlatch();
44515
+ continue;
44516
+ }
44479
44517
  daemonLog(`link ${name}: removed`);
44480
44518
  link3.dispose();
44481
44519
  links2.delete(name);
@@ -45470,9 +45508,10 @@ var messageHandlers = {
45470
45508
  "subscribe-logs": (client, m, d) => m.clients.subscribeLogs(client, d.replay !== false),
45471
45509
  hello: handleHelloRequest,
45472
45510
  nodes: (client, m) => m.links.sendNodes(client),
45473
- "reload-links": (_client, m) => {
45511
+ "reload-links": (client, m) => {
45474
45512
  daemonLog("reload-links received");
45475
45513
  m.links.reload();
45514
+ sendTo(client, { type: "ack" });
45476
45515
  },
45477
45516
  create: creator(true, spawnCreate),
45478
45517
  "create-run": handleCreateRun,
@@ -46174,7 +46213,31 @@ async function doctorNodes(name, options2) {
46174
46213
  }
46175
46214
 
46176
46215
  // src/commands/sessions/nodes/linkNode.ts
46216
+ import chalk252 from "chalk";
46217
+
46218
+ // src/commands/sessions/nodes/notifyDaemonLinks.ts
46177
46219
  import chalk251 from "chalk";
46220
+ async function notifyDaemonLinks() {
46221
+ if (!await isDaemonRunning()) {
46222
+ console.log(
46223
+ chalk251.yellow(
46224
+ "The sessions daemon is not running; it loads the links when it starts."
46225
+ )
46226
+ );
46227
+ return;
46228
+ }
46229
+ try {
46230
+ await sendToDaemonAwaitAck({ type: "reload-links" });
46231
+ console.log(chalk251.dim("The sessions daemon reloaded its links."));
46232
+ } catch (error) {
46233
+ const message3 = error instanceof Error ? error.message : String(error);
46234
+ console.log(
46235
+ chalk251.yellow(
46236
+ `Could not notify the sessions daemon (${message3}); run \`assist daemon restart\` to apply the change.`
46237
+ )
46238
+ );
46239
+ }
46240
+ }
46178
46241
 
46179
46242
  // src/commands/sessions/nodes/writeLinks.ts
46180
46243
  function readLinks() {
@@ -46190,7 +46253,6 @@ async function writeLinks(links2) {
46190
46253
  const validation = validateConfig(updated2, "sessions.links");
46191
46254
  if (!validation.ok) throw new Error(validation.errors.join("\n"));
46192
46255
  saveGlobalConfig(updated2);
46193
- if (await isDaemonRunning()) await sendToDaemon({ type: "reload-links" });
46194
46256
  }
46195
46257
 
46196
46258
  // src/commands/sessions/nodes/linkNode.ts
@@ -46230,12 +46292,13 @@ async function linkNode(name, url, options2) {
46230
46292
  const link3 = buildLink(name, url, options2, others);
46231
46293
  await writeLinks([...others, link3]);
46232
46294
  console.log(
46233
- chalk251.green(`Linked ${name} (${describeTarget(toLinkSpec(link3))})`)
46295
+ chalk252.green(`Linked ${name} (${describeTarget(toLinkSpec(link3))})`)
46234
46296
  );
46297
+ await notifyDaemonLinks();
46235
46298
  }
46236
46299
 
46237
46300
  // src/commands/sessions/nodes/listNodes.ts
46238
- import chalk252 from "chalk";
46301
+ import chalk253 from "chalk";
46239
46302
  async function nodesReport() {
46240
46303
  const live = await queryNodes();
46241
46304
  if (live)
@@ -46252,10 +46315,10 @@ async function listNodes(options2) {
46252
46315
  console.log(JSON.stringify(report2, null, 2));
46253
46316
  return;
46254
46317
  }
46255
- console.log(`${report2.local} ${chalk252.dim("(this node)")}`);
46318
+ console.log(`${report2.local} ${chalk253.dim("(this node)")}`);
46256
46319
  if (!report2.daemonRunning)
46257
- console.log(chalk252.dim(" daemon not running; showing configured links"));
46258
- if (report2.links.length === 0) console.log(chalk252.dim(" no links"));
46320
+ console.log(chalk253.dim(" daemon not running; showing configured links"));
46321
+ if (report2.links.length === 0) console.log(chalk253.dim(" no links"));
46259
46322
  for (const link3 of report2.links) console.log(formatLink(link3));
46260
46323
  }
46261
46324
 
@@ -46294,16 +46357,17 @@ async function nodeLogs(name, options2) {
46294
46357
  }
46295
46358
 
46296
46359
  // src/commands/sessions/nodes/unlinkNode.ts
46297
- import chalk253 from "chalk";
46360
+ import chalk254 from "chalk";
46298
46361
  async function unlinkNode(name) {
46299
46362
  const links2 = readLinks();
46300
46363
  const remaining = links2.filter((link3) => link3.name !== name);
46301
46364
  if (remaining.length === links2.length) {
46302
- console.log(chalk253.yellow(`No link named ${name}`));
46365
+ console.log(chalk254.yellow(`No link named ${name}`));
46303
46366
  return;
46304
46367
  }
46305
46368
  await writeLinks(remaining);
46306
- console.log(chalk253.green(`Unlinked ${name}`));
46369
+ console.log(chalk254.green(`Unlinked ${name}`));
46370
+ await notifyDaemonLinks();
46307
46371
  }
46308
46372
 
46309
46373
  // src/commands/sessions/nodes/registerNodes.ts
@@ -46363,7 +46427,7 @@ async function renameSession(title) {
46363
46427
 
46364
46428
  // src/commands/sessions/summarise.ts
46365
46429
  import * as fs58 from "fs";
46366
- import chalk254 from "chalk";
46430
+ import chalk255 from "chalk";
46367
46431
 
46368
46432
  // src/commands/sessions/summarise/shared.ts
46369
46433
  import * as fs57 from "fs";
@@ -46422,22 +46486,22 @@ ${firstMessage}`);
46422
46486
  async function summarise2(options2) {
46423
46487
  const files = await discoverSessionFiles();
46424
46488
  if (files.length === 0) {
46425
- console.log(chalk254.yellow("No sessions found."));
46489
+ console.log(chalk255.yellow("No sessions found."));
46426
46490
  return;
46427
46491
  }
46428
46492
  const toProcess = selectCandidates(files, options2);
46429
46493
  if (toProcess.length === 0) {
46430
- console.log(chalk254.green("All sessions already summarised."));
46494
+ console.log(chalk255.green("All sessions already summarised."));
46431
46495
  return;
46432
46496
  }
46433
46497
  console.log(
46434
- chalk254.cyan(
46498
+ chalk255.cyan(
46435
46499
  `Summarising ${toProcess.length} session(s) (${files.length} total)\u2026`
46436
46500
  )
46437
46501
  );
46438
46502
  const { succeeded, failed: failed3 } = processSessions(toProcess);
46439
46503
  console.log(
46440
- chalk254.green(`Done: ${succeeded} summarised`) + (failed3 > 0 ? chalk254.yellow(`, ${failed3} skipped`) : "")
46504
+ chalk255.green(`Done: ${succeeded} summarised`) + (failed3 > 0 ? chalk255.yellow(`, ${failed3} skipped`) : "")
46441
46505
  );
46442
46506
  }
46443
46507
  function selectCandidates(files, options2) {
@@ -46457,16 +46521,16 @@ function processSessions(files) {
46457
46521
  let failed3 = 0;
46458
46522
  for (let i = 0; i < files.length; i++) {
46459
46523
  const file = files[i];
46460
- process.stdout.write(chalk254.dim(` [${i + 1}/${files.length}] `));
46524
+ process.stdout.write(chalk255.dim(` [${i + 1}/${files.length}] `));
46461
46525
  const summary = summariseSession(file);
46462
46526
  if (summary) {
46463
46527
  writeSummary(file, summary);
46464
46528
  succeeded++;
46465
- process.stdout.write(`${chalk254.green("\u2713")} ${summary}
46529
+ process.stdout.write(`${chalk255.green("\u2713")} ${summary}
46466
46530
  `);
46467
46531
  } else {
46468
46532
  failed3++;
46469
- process.stdout.write(` ${chalk254.yellow("skip")}
46533
+ process.stdout.write(` ${chalk255.yellow("skip")}
46470
46534
  `);
46471
46535
  }
46472
46536
  }
@@ -46494,10 +46558,10 @@ function registerSessions(program2) {
46494
46558
  }
46495
46559
 
46496
46560
  // src/reportCliError.ts
46497
- import chalk255 from "chalk";
46561
+ import chalk256 from "chalk";
46498
46562
  function reportCliError(error) {
46499
46563
  if (error instanceof InvalidItemIdError || error instanceof AmbiguousRepoConfigError || error instanceof UnknownRepoConfigError || error instanceof MissingRunCwdError || error instanceof MiroExtractError) {
46500
- console.error(chalk255.red(error.message));
46564
+ console.error(chalk256.red(error.message));
46501
46565
  } else {
46502
46566
  console.error(error);
46503
46567
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@staff0rd/assist",
3
- "version": "0.716.1",
3
+ "version": "0.716.3",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "bin": {