@staff0rd/assist 0.710.1 → 0.711.1
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/README.md +32 -4
- package/claude/commands/draft.md +0 -2
- package/claude/commands/refine.md +0 -1
- package/dist/commands/sessions/web/bundle.js +1 -1
- package/dist/index.js +407 -35
- package/package.json +1 -1
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.
|
|
9
|
+
version: "0.711.1",
|
|
10
10
|
type: "module",
|
|
11
11
|
main: "dist/index.js",
|
|
12
12
|
bin: {
|
|
@@ -824,7 +824,17 @@ var assistConfigShape = {
|
|
|
824
824
|
}).default({ outputDir: "./screenshots" }),
|
|
825
825
|
sessions: z3.strictObject({
|
|
826
826
|
nodeName: z3.string().optional(),
|
|
827
|
-
links: z3.array(
|
|
827
|
+
links: z3.array(
|
|
828
|
+
z3.union([
|
|
829
|
+
z3.strictObject({ name: z3.string(), url: z3.string() }),
|
|
830
|
+
z3.strictObject({
|
|
831
|
+
name: z3.string(),
|
|
832
|
+
ssh: z3.string(),
|
|
833
|
+
port: z3.number().int(),
|
|
834
|
+
localPort: z3.number().int().optional()
|
|
835
|
+
})
|
|
836
|
+
])
|
|
837
|
+
).optional(),
|
|
828
838
|
linkVersionCheck: z3.enum(["block", "warn", "off"]).default("block"),
|
|
829
839
|
includeCommittedChanges: z3.boolean().default(true),
|
|
830
840
|
topBar: z3.boolean().default(true),
|
|
@@ -6519,7 +6529,6 @@ function buildAuthoredPhasePrompt(item, phaseNumber, phase, options2 = {
|
|
|
6519
6529
|
...buildJiraStartedLines(item, phaseNumber),
|
|
6520
6530
|
"",
|
|
6521
6531
|
"Focus ONLY on this phase. Do not work on other phases.",
|
|
6522
|
-
"Work only in this item's own repo. Do not modify, commit or push any other repo without the user's explicit permission \u2014 if a task needs changes elsewhere, stop and ask the user, and suggest filing that work as a separate item in that repo's backlog.",
|
|
6523
6532
|
"If you need to modify backlog items, run `assist backlog --help` to discover available commands.",
|
|
6524
6533
|
"When you have completed all tasks for this phase, run /verify to check your work.",
|
|
6525
6534
|
...buildManualCheckLines(manualChecks, options2.commitBeforePhaseEnd),
|
|
@@ -12765,8 +12774,8 @@ var seqConfigHelp = [
|
|
|
12765
12774
|
var nodesConfigHelp = [
|
|
12766
12775
|
{
|
|
12767
12776
|
key: "sessions.links",
|
|
12768
|
-
setter: "assist sessions nodes link <name> http://127.0.0.1:<port>",
|
|
12769
|
-
note: "linked nodes whose sessions merge into this node's web UI; each name must match the peer's sessions.nodeName"
|
|
12777
|
+
setter: "assist sessions nodes link <name> http://127.0.0.1:<port> (or --ssh <alias> --port <port>)",
|
|
12778
|
+
note: "linked nodes whose sessions merge into this node's web UI, each direct (url) or over an ssh tunnel (ssh alias, peer port, localPort); each name must match the peer's sessions.nodeName"
|
|
12770
12779
|
},
|
|
12771
12780
|
{
|
|
12772
12781
|
key: "sessions.linkVersionCheck",
|
|
@@ -14066,6 +14075,27 @@ async function prList(req, res) {
|
|
|
14066
14075
|
respondJson(res, 200, { prs: await getOpenPrs(cwd) });
|
|
14067
14076
|
}
|
|
14068
14077
|
|
|
14078
|
+
// src/commands/sessions/shared/loadLinkSpecs.ts
|
|
14079
|
+
var TUNNEL_PORT_BASE = 43e3;
|
|
14080
|
+
function defaultTunnelPort(port) {
|
|
14081
|
+
return TUNNEL_PORT_BASE + port % 1e3;
|
|
14082
|
+
}
|
|
14083
|
+
function toLinkSpec(link3) {
|
|
14084
|
+
if ("url" in link3) return { name: link3.name, url: link3.url };
|
|
14085
|
+
const localPort = link3.localPort ?? defaultTunnelPort(link3.port);
|
|
14086
|
+
return {
|
|
14087
|
+
name: link3.name,
|
|
14088
|
+
url: `http://127.0.0.1:${localPort}`,
|
|
14089
|
+
ssh: { alias: link3.ssh, port: link3.port, localPort }
|
|
14090
|
+
};
|
|
14091
|
+
}
|
|
14092
|
+
function loadLinkSpecs() {
|
|
14093
|
+
return (loadConfig().sessions?.links ?? []).map(toLinkSpec);
|
|
14094
|
+
}
|
|
14095
|
+
function findLinkSpec(name) {
|
|
14096
|
+
return loadLinkSpecs().find((spec) => spec.name === name);
|
|
14097
|
+
}
|
|
14098
|
+
|
|
14069
14099
|
// src/commands/sessions/shared/newTraceId.ts
|
|
14070
14100
|
import { randomUUID as randomUUID7 } from "crypto";
|
|
14071
14101
|
var TRACE_HEADER = "x-assist-trace-id";
|
|
@@ -14129,7 +14159,7 @@ function proxyTarget(req) {
|
|
|
14129
14159
|
if (!url.pathname.startsWith("/api/") || !node) return { kind: "local" };
|
|
14130
14160
|
if (arrivedOverLink(req) || node === resolveNodeName())
|
|
14131
14161
|
return { kind: "local" };
|
|
14132
|
-
const link3 =
|
|
14162
|
+
const link3 = findLinkSpec(node);
|
|
14133
14163
|
if (!link3) return { kind: "unknown", node };
|
|
14134
14164
|
url.searchParams.delete("node");
|
|
14135
14165
|
return {
|
|
@@ -39387,6 +39417,14 @@ function registerRun(program2) {
|
|
|
39387
39417
|
|
|
39388
39418
|
// src/commands/sessions/nodes/formatLink.ts
|
|
39389
39419
|
import chalk249 from "chalk";
|
|
39420
|
+
|
|
39421
|
+
// src/commands/sessions/daemon/links/describeTarget.ts
|
|
39422
|
+
function describeTarget({ url, ssh }) {
|
|
39423
|
+
if (!ssh) return `direct ${url}`;
|
|
39424
|
+
return `ssh ${ssh.alias}:${ssh.port} via 127.0.0.1:${ssh.localPort}`;
|
|
39425
|
+
}
|
|
39426
|
+
|
|
39427
|
+
// src/commands/sessions/nodes/formatLink.ts
|
|
39390
39428
|
var STATE_COLOURS = {
|
|
39391
39429
|
connected: chalk249.green,
|
|
39392
39430
|
connecting: chalk249.yellow,
|
|
@@ -39398,7 +39436,7 @@ function formatLink(link3) {
|
|
|
39398
39436
|
const peer = link3.peerVersion ? ` peer ${link3.peerVersion}` : "";
|
|
39399
39437
|
const error = link3.error ? `
|
|
39400
39438
|
${chalk249.dim(`last error${link3.errorAt ? ` ${link3.errorAt}` : ""}: ${link3.error}`)}` : "";
|
|
39401
|
-
return ` ${link3.name} ${colour(link3.state)}
|
|
39439
|
+
return ` ${link3.name} ${colour(link3.state)} ${describeTarget(link3)}${peer}${error}`;
|
|
39402
39440
|
}
|
|
39403
39441
|
|
|
39404
39442
|
// src/commands/sessions/daemon/listDaemonPids.ts
|
|
@@ -43167,10 +43205,10 @@ function restoreAllSessions(spawner, sessions, notify2) {
|
|
|
43167
43205
|
|
|
43168
43206
|
// src/commands/sessions/daemon/retrySession.ts
|
|
43169
43207
|
function retrySession(session, clients, onStatusChange) {
|
|
43170
|
-
const
|
|
43171
|
-
if (!
|
|
43208
|
+
const spawn13 = respawnThunk(session);
|
|
43209
|
+
if (!spawn13) return false;
|
|
43172
43210
|
const respawn = () => {
|
|
43173
|
-
respawnSession(session,
|
|
43211
|
+
respawnSession(session, spawn13, "running", clients, onStatusChange);
|
|
43174
43212
|
daemonLog(`session ${session.id} retried: ${session.name}`);
|
|
43175
43213
|
};
|
|
43176
43214
|
const pty2 = session.pty;
|
|
@@ -43701,11 +43739,140 @@ async function selfUpdatePeer(url) {
|
|
|
43701
43739
|
throw new Error(body.error ?? `self-update responded ${response.status}`);
|
|
43702
43740
|
}
|
|
43703
43741
|
|
|
43742
|
+
// src/commands/sessions/daemon/links/SshTunnel.ts
|
|
43743
|
+
import { createInterface as createInterface10 } from "readline";
|
|
43744
|
+
import { setTimeout as delay2 } from "timers/promises";
|
|
43745
|
+
|
|
43746
|
+
// src/commands/sessions/daemon/links/killOrphanOnDaemonExit.ts
|
|
43747
|
+
var liveChildren = /* @__PURE__ */ new Set();
|
|
43748
|
+
var exitHookInstalled = false;
|
|
43749
|
+
function killOrphanOnDaemonExit(child) {
|
|
43750
|
+
liveChildren.add(child);
|
|
43751
|
+
child.once("exit", () => liveChildren.delete(child));
|
|
43752
|
+
if (exitHookInstalled) return;
|
|
43753
|
+
exitHookInstalled = true;
|
|
43754
|
+
process.once("exit", () => {
|
|
43755
|
+
for (const live of liveChildren) live.kill();
|
|
43756
|
+
});
|
|
43757
|
+
}
|
|
43758
|
+
|
|
43759
|
+
// src/commands/sessions/daemon/links/sshTunnelArgs.ts
|
|
43760
|
+
function sshTunnelArgs({ alias, port, localPort }) {
|
|
43761
|
+
return [
|
|
43762
|
+
"-N",
|
|
43763
|
+
"-o",
|
|
43764
|
+
"BatchMode=yes",
|
|
43765
|
+
"-o",
|
|
43766
|
+
"ExitOnForwardFailure=yes",
|
|
43767
|
+
"-o",
|
|
43768
|
+
"ServerAliveInterval=15",
|
|
43769
|
+
"-o",
|
|
43770
|
+
"ServerAliveCountMax=3",
|
|
43771
|
+
"-L",
|
|
43772
|
+
`${localPort}:127.0.0.1:${port}`,
|
|
43773
|
+
alias
|
|
43774
|
+
];
|
|
43775
|
+
}
|
|
43776
|
+
|
|
43777
|
+
// src/commands/sessions/daemon/links/SshTunnelIo.ts
|
|
43778
|
+
import { spawn as spawn11 } from "child_process";
|
|
43779
|
+
|
|
43780
|
+
// src/commands/sessions/shared/portAccepts.ts
|
|
43781
|
+
import { connect as connect3 } from "net";
|
|
43782
|
+
function portAccepts(port, timeoutMs = 1e3) {
|
|
43783
|
+
return new Promise((resolve25) => {
|
|
43784
|
+
const socket = connect3({ host: "127.0.0.1", port });
|
|
43785
|
+
const settle = (ok) => {
|
|
43786
|
+
socket.destroy();
|
|
43787
|
+
resolve25(ok);
|
|
43788
|
+
};
|
|
43789
|
+
socket.setTimeout(timeoutMs, () => settle(false));
|
|
43790
|
+
socket.once("connect", () => settle(true));
|
|
43791
|
+
socket.once("error", () => settle(false));
|
|
43792
|
+
});
|
|
43793
|
+
}
|
|
43794
|
+
|
|
43795
|
+
// src/commands/sessions/daemon/links/SshTunnelIo.ts
|
|
43796
|
+
var defaultSshTunnelIo = {
|
|
43797
|
+
spawn: (args) => spawn11("ssh", args, {
|
|
43798
|
+
stdio: ["ignore", "ignore", "pipe"],
|
|
43799
|
+
windowsHide: true
|
|
43800
|
+
}),
|
|
43801
|
+
accepts: (port) => portAccepts(port),
|
|
43802
|
+
bindTimeoutMs: 15e3,
|
|
43803
|
+
pollMs: 200
|
|
43804
|
+
};
|
|
43805
|
+
|
|
43806
|
+
// src/commands/sessions/daemon/links/SshTunnel.ts
|
|
43807
|
+
var SshTunnel = class {
|
|
43808
|
+
constructor(name, target, io = defaultSshTunnelIo) {
|
|
43809
|
+
this.name = name;
|
|
43810
|
+
this.target = target;
|
|
43811
|
+
this.io = io;
|
|
43812
|
+
}
|
|
43813
|
+
child;
|
|
43814
|
+
exitReason = "";
|
|
43815
|
+
lastStderr = "";
|
|
43816
|
+
async ready() {
|
|
43817
|
+
if (!this.child) this.start();
|
|
43818
|
+
await this.waitBound(this.child);
|
|
43819
|
+
}
|
|
43820
|
+
dispose() {
|
|
43821
|
+
const child = this.child;
|
|
43822
|
+
this.child = void 0;
|
|
43823
|
+
if (!child) return;
|
|
43824
|
+
daemonLog(`link ${this.name} tunnel: stopping ssh`);
|
|
43825
|
+
child.kill();
|
|
43826
|
+
}
|
|
43827
|
+
start() {
|
|
43828
|
+
const args = sshTunnelArgs(this.target);
|
|
43829
|
+
daemonLog(`link ${this.name} tunnel: spawning ssh ${args.join(" ")}`);
|
|
43830
|
+
const child = this.io.spawn(args);
|
|
43831
|
+
this.child = child;
|
|
43832
|
+
this.lastStderr = "";
|
|
43833
|
+
killOrphanOnDaemonExit(child);
|
|
43834
|
+
if (child.stderr)
|
|
43835
|
+
createInterface10({ input: child.stderr }).on("line", (line) => {
|
|
43836
|
+
this.lastStderr = line;
|
|
43837
|
+
daemonLog(`link ${this.name} ssh: ${line}`);
|
|
43838
|
+
});
|
|
43839
|
+
child.once("error", (error) => this.onExit(child, error.message));
|
|
43840
|
+
child.once(
|
|
43841
|
+
"exit",
|
|
43842
|
+
(code, signal) => this.onExit(child, signal ? `signal ${signal}` : `code ${code}`)
|
|
43843
|
+
);
|
|
43844
|
+
}
|
|
43845
|
+
onExit(child, reason4) {
|
|
43846
|
+
if (this.child !== child) return;
|
|
43847
|
+
this.child = void 0;
|
|
43848
|
+
this.exitReason = this.lastStderr ? `${reason4}: ${this.lastStderr}` : reason4;
|
|
43849
|
+
daemonLog(`link ${this.name} tunnel: ssh exited (${this.exitReason})`);
|
|
43850
|
+
}
|
|
43851
|
+
async waitBound(child) {
|
|
43852
|
+
const { alias, localPort } = this.target;
|
|
43853
|
+
const deadline = Date.now() + this.io.bindTimeoutMs;
|
|
43854
|
+
while (Date.now() < deadline) {
|
|
43855
|
+
if (this.child !== child)
|
|
43856
|
+
throw new Error(`ssh tunnel to ${alias} exited (${this.exitReason})`);
|
|
43857
|
+
if (await this.io.accepts(localPort)) return;
|
|
43858
|
+
await delay2(this.io.pollMs);
|
|
43859
|
+
}
|
|
43860
|
+
this.dispose();
|
|
43861
|
+
throw new Error(
|
|
43862
|
+
`ssh tunnel to ${alias} did not bind 127.0.0.1:${localPort} within ${this.io.bindTimeoutMs / 1e3}s`
|
|
43863
|
+
);
|
|
43864
|
+
}
|
|
43865
|
+
};
|
|
43866
|
+
|
|
43867
|
+
// src/commands/sessions/daemon/links/sshTunnelFor.ts
|
|
43868
|
+
var sshTunnelFor = (spec) => spec.ssh ? new SshTunnel(spec.name, spec.ssh) : void 0;
|
|
43869
|
+
|
|
43704
43870
|
// src/commands/sessions/daemon/links/linkDeps.ts
|
|
43705
43871
|
function linkDeps(options2, callbacks) {
|
|
43706
43872
|
return {
|
|
43707
43873
|
...callbacks,
|
|
43708
43874
|
transport: options2.transport ?? connectLinkWebSocket,
|
|
43875
|
+
tunnel: options2.tunnel ?? sshTunnelFor,
|
|
43709
43876
|
heal: options2.heal ?? selfUpdatePeer,
|
|
43710
43877
|
reconnectMs: options2.reconnectMs ?? 3e3,
|
|
43711
43878
|
createTimeoutMs: options2.createTimeoutMs ?? 15e3
|
|
@@ -43810,6 +43977,7 @@ function createLinkContext(spec, deps2) {
|
|
|
43810
43977
|
deps: deps2,
|
|
43811
43978
|
relay: createRelayState(spec.name, deps2.viewers, deps2.onSessionsChanged),
|
|
43812
43979
|
breaker: new LaunchCircuitBreaker(`link ${spec.name} ws`),
|
|
43980
|
+
tunnel: deps2.tunnel(spec),
|
|
43813
43981
|
socket: null,
|
|
43814
43982
|
greeted: false,
|
|
43815
43983
|
state: "disconnected",
|
|
@@ -43828,6 +43996,7 @@ function describeLink(ctx) {
|
|
|
43828
43996
|
return {
|
|
43829
43997
|
name: ctx.spec.name,
|
|
43830
43998
|
url: ctx.spec.url,
|
|
43999
|
+
ssh: ctx.spec.ssh,
|
|
43831
44000
|
state: ctx.state,
|
|
43832
44001
|
error: ctx.blockedMessage ?? ctx.lastError?.message,
|
|
43833
44002
|
errorAt: ctx.lastError?.at,
|
|
@@ -43927,15 +44096,15 @@ function linkHealRefusal(node, peerVersion, healAttempted) {
|
|
|
43927
44096
|
}
|
|
43928
44097
|
|
|
43929
44098
|
// src/commands/sessions/daemon/links/scheduleReconnect.ts
|
|
43930
|
-
function armReconnect(ctx,
|
|
44099
|
+
function armReconnect(ctx, delay3) {
|
|
43931
44100
|
clearTimeout(ctx.reconnectTimer);
|
|
43932
|
-
ctx.reconnectTimer = setTimeout(ctx.connect,
|
|
44101
|
+
ctx.reconnectTimer = setTimeout(ctx.connect, delay3);
|
|
43933
44102
|
ctx.reconnectTimer.unref?.();
|
|
43934
44103
|
}
|
|
43935
44104
|
function scheduleReconnect2(ctx) {
|
|
43936
44105
|
if (ctx.disposed || ctx.blockedMessage) return;
|
|
43937
|
-
const
|
|
43938
|
-
armReconnect(ctx,
|
|
44106
|
+
const delay3 = ctx.breaker.tripped() ? ctx.breaker.remainingMs() : ctx.deps.reconnectMs;
|
|
44107
|
+
armReconnect(ctx, delay3);
|
|
43939
44108
|
}
|
|
43940
44109
|
function reconnectNow(ctx) {
|
|
43941
44110
|
ctx.breaker.clear();
|
|
@@ -44177,8 +44346,10 @@ async function openLink(ctx) {
|
|
|
44177
44346
|
if (ctx.disposed || ctx.blockedMessage || ctx.socket) return;
|
|
44178
44347
|
if (ctx.breaker.tripped()) return scheduleReconnect2(ctx);
|
|
44179
44348
|
setLinkState(ctx, "connecting");
|
|
44180
|
-
daemonLog(`link ${ctx.spec.name} ws: connecting to ${ctx.spec.url}`);
|
|
44181
44349
|
try {
|
|
44350
|
+
await ctx.tunnel?.ready();
|
|
44351
|
+
if (ctx.disposed) return;
|
|
44352
|
+
daemonLog(`link ${ctx.spec.name} ws: connecting to ${ctx.spec.url}`);
|
|
44182
44353
|
const socket = await ctx.deps.transport(ctx.spec.url, {
|
|
44183
44354
|
onLine: (line) => onLinkLine(ctx, line),
|
|
44184
44355
|
onClose: (reason4) => onLinkClose(ctx, socket, reason4)
|
|
@@ -44241,21 +44412,25 @@ var NodeLink = class {
|
|
|
44241
44412
|
this.ctx.disposed = true;
|
|
44242
44413
|
clearTimeout(this.ctx.reconnectTimer);
|
|
44243
44414
|
disconnectLink(this.ctx);
|
|
44415
|
+
this.ctx.tunnel?.dispose();
|
|
44244
44416
|
}
|
|
44245
44417
|
};
|
|
44246
44418
|
|
|
44247
44419
|
// src/commands/sessions/daemon/links/reconcileLinks.ts
|
|
44420
|
+
function sameTarget(wanted, current) {
|
|
44421
|
+
return wanted?.url === current.url && JSON.stringify(wanted.ssh) === JSON.stringify(current.ssh);
|
|
44422
|
+
}
|
|
44248
44423
|
function reconcileLinks(links2, specs, create) {
|
|
44249
44424
|
const wanted = new Map(specs.map((spec) => [spec.name, spec]));
|
|
44250
44425
|
for (const [name, link3] of links2) {
|
|
44251
|
-
if (wanted.get(name)
|
|
44426
|
+
if (sameTarget(wanted.get(name), link3.spec)) continue;
|
|
44252
44427
|
daemonLog(`link ${name}: removed`);
|
|
44253
44428
|
link3.dispose();
|
|
44254
44429
|
links2.delete(name);
|
|
44255
44430
|
}
|
|
44256
44431
|
for (const spec of specs) {
|
|
44257
44432
|
if (links2.has(spec.name)) continue;
|
|
44258
|
-
daemonLog(`link ${spec.name}: added (${spec
|
|
44433
|
+
daemonLog(`link ${spec.name}: added (${describeTarget(spec)})`);
|
|
44259
44434
|
const link3 = create(spec);
|
|
44260
44435
|
links2.set(spec.name, link3);
|
|
44261
44436
|
link3.start();
|
|
@@ -44288,7 +44463,7 @@ var NodeLinks = class {
|
|
|
44288
44463
|
this.options = options2;
|
|
44289
44464
|
}
|
|
44290
44465
|
reload() {
|
|
44291
|
-
const specs = this.options.specs?.() ??
|
|
44466
|
+
const specs = this.options.specs?.() ?? loadLinkSpecs();
|
|
44292
44467
|
const deps2 = linkDeps(this.options, {
|
|
44293
44468
|
viewers: () => this.clients.viewers(),
|
|
44294
44469
|
onSessionsChanged: this.onSessionsChanged,
|
|
@@ -44776,7 +44951,7 @@ function exitAfterFlush(code) {
|
|
|
44776
44951
|
}
|
|
44777
44952
|
|
|
44778
44953
|
// src/commands/sessions/daemon/handleConnection.ts
|
|
44779
|
-
import { createInterface as
|
|
44954
|
+
import { createInterface as createInterface11 } from "readline";
|
|
44780
44955
|
|
|
44781
44956
|
// src/commands/sessions/daemon/handleHelloRequest.ts
|
|
44782
44957
|
var handleHelloRequest = (client, m, d) => {
|
|
@@ -44791,10 +44966,10 @@ var handleHelloRequest = (client, m, d) => {
|
|
|
44791
44966
|
};
|
|
44792
44967
|
|
|
44793
44968
|
// src/commands/sessions/daemon/creator.ts
|
|
44794
|
-
function creator(isNew,
|
|
44969
|
+
function creator(isNew, spawn13) {
|
|
44795
44970
|
return (client, m, d) => {
|
|
44796
44971
|
if (m.links.route(client, d)) return;
|
|
44797
|
-
const result =
|
|
44972
|
+
const result = spawn13(m, d);
|
|
44798
44973
|
if (typeof result !== "string") {
|
|
44799
44974
|
sendTo(client, { type: "error", message: result.error });
|
|
44800
44975
|
return;
|
|
@@ -45320,7 +45495,7 @@ function handleConnection(socket, manager) {
|
|
|
45320
45495
|
};
|
|
45321
45496
|
manager.addClient(client);
|
|
45322
45497
|
manager.clients.greet(client);
|
|
45323
|
-
const lines2 =
|
|
45498
|
+
const lines2 = createInterface11({ input: socket });
|
|
45324
45499
|
lines2.on("error", () => {
|
|
45325
45500
|
});
|
|
45326
45501
|
lines2.on("line", (line) => {
|
|
@@ -45519,6 +45694,37 @@ function failed2(hop, error, remediation) {
|
|
|
45519
45694
|
return { hop, ok: false, error, remediation };
|
|
45520
45695
|
}
|
|
45521
45696
|
|
|
45697
|
+
// src/commands/sessions/nodes/agentHop.ts
|
|
45698
|
+
var ONEPASSWORD_AGENT = '"~/Library/Group Containers/2BUA8C4S2C.com.1password/t/agent.sock"';
|
|
45699
|
+
async function agentHop(ssh, probes) {
|
|
45700
|
+
const agent = await probes.sshAgent(ssh.alias);
|
|
45701
|
+
switch (agent.status) {
|
|
45702
|
+
case "ok":
|
|
45703
|
+
return passed(
|
|
45704
|
+
"agent",
|
|
45705
|
+
`${agent.keys} key(s)${agent.socket ? ` via ${agent.socket}` : ""}`
|
|
45706
|
+
);
|
|
45707
|
+
case "missing":
|
|
45708
|
+
return failed2(
|
|
45709
|
+
"agent",
|
|
45710
|
+
`no IdentityAgent for ${ssh.alias} and SSH_AUTH_SOCK is unset`,
|
|
45711
|
+
`IdentityAgent missing \u2014 add \`IdentityAgent ${ONEPASSWORD_AGENT}\` under \`Host ${ssh.alias}\` in ~/.ssh/config`
|
|
45712
|
+
);
|
|
45713
|
+
case "no-keys":
|
|
45714
|
+
return failed2(
|
|
45715
|
+
"agent",
|
|
45716
|
+
`the agent${agent.socket ? ` at ${agent.socket}` : ""} holds no keys`,
|
|
45717
|
+
"add or import an SSH key in 1Password, then allow it in the SSH agent"
|
|
45718
|
+
);
|
|
45719
|
+
case "unreachable":
|
|
45720
|
+
return failed2(
|
|
45721
|
+
"agent",
|
|
45722
|
+
agent.error,
|
|
45723
|
+
"1Password SSH agent not reachable \u2014 open and unlock 1Password and turn on Settings \u2192 Developer \u2192 Use the SSH agent"
|
|
45724
|
+
);
|
|
45725
|
+
}
|
|
45726
|
+
}
|
|
45727
|
+
|
|
45522
45728
|
// src/commands/sessions/nodes/fetchPeerJson.ts
|
|
45523
45729
|
var PEER_TIMEOUT_MS = 3e3;
|
|
45524
45730
|
function peerErrorCode(error) {
|
|
@@ -45605,8 +45811,61 @@ function linkStateHop(spec, probes) {
|
|
|
45605
45811
|
);
|
|
45606
45812
|
}
|
|
45607
45813
|
|
|
45814
|
+
// src/commands/sessions/nodes/sshHop.ts
|
|
45815
|
+
var REMEDIATIONS = [
|
|
45816
|
+
[
|
|
45817
|
+
/connection refused/i,
|
|
45818
|
+
(alias) => `Remote Login is off on ${alias} \u2014 on a Mac turn on System Settings \u2192 General \u2192 Sharing \u2192 Remote Login; on Windows run \`Start-Service sshd\` (OpenSSH Server)`
|
|
45819
|
+
],
|
|
45820
|
+
[
|
|
45821
|
+
/could not resolve hostname/i,
|
|
45822
|
+
(alias) => `no \`Host ${alias}\` in ~/.ssh/config and ${alias} does not resolve \u2014 add a Host entry with its HostName`
|
|
45823
|
+
],
|
|
45824
|
+
[
|
|
45825
|
+
/host key verification failed/i,
|
|
45826
|
+
(alias) => `run \`ssh ${alias}\` once to accept its host key`
|
|
45827
|
+
],
|
|
45828
|
+
[
|
|
45829
|
+
/agent refused operation|sign_and_send_pubkey/i,
|
|
45830
|
+
() => "1Password refused to sign \u2014 unlock it and approve the key request"
|
|
45831
|
+
],
|
|
45832
|
+
[
|
|
45833
|
+
/permission denied/i,
|
|
45834
|
+
(alias) => `${alias} rejected every key offered \u2014 add this node's 1Password public key to ~/.ssh/authorized_keys on ${alias} (C:\\ProgramData\\ssh\\administrators_authorized_keys for a Windows administrator)`
|
|
45835
|
+
],
|
|
45836
|
+
[
|
|
45837
|
+
/timed out/i,
|
|
45838
|
+
(alias) => `${alias} did not answer on its ssh port \u2014 is it awake and on this network?`
|
|
45839
|
+
]
|
|
45840
|
+
];
|
|
45841
|
+
async function sshHop(ssh, probes) {
|
|
45842
|
+
const { code, stderr } = await probes.ssh(ssh.alias);
|
|
45843
|
+
if (code === 0) return passed("ssh", `ssh ${ssh.alias} authenticated`);
|
|
45844
|
+
const error = stderr || `ssh exited ${code}`;
|
|
45845
|
+
const match = REMEDIATIONS.find(([pattern2]) => pattern2.test(error));
|
|
45846
|
+
return failed2(
|
|
45847
|
+
"ssh",
|
|
45848
|
+
error,
|
|
45849
|
+
match?.[1](ssh.alias) ?? `run \`ssh -v ${ssh.alias}\` to see where it fails`
|
|
45850
|
+
);
|
|
45851
|
+
}
|
|
45852
|
+
|
|
45853
|
+
// src/commands/sessions/nodes/tunnelHop.ts
|
|
45854
|
+
async function tunnelHop(spec, ssh, probes) {
|
|
45855
|
+
const bound = `127.0.0.1:${ssh.localPort}`;
|
|
45856
|
+
if (await probes.tunnel(ssh.localPort))
|
|
45857
|
+
return passed("tunnel", `${bound} \u2192 ${ssh.alias}:${ssh.port}`);
|
|
45858
|
+
return failed2(
|
|
45859
|
+
"tunnel",
|
|
45860
|
+
`nothing bound on ${bound}`,
|
|
45861
|
+
`this node's daemon keeps \`ssh -N -L ${ssh.localPort}:127.0.0.1:${ssh.port} ${ssh.alias}\` up \u2014 run \`assist daemon restart\` and check daemon.log for \`link ${spec.name} tunnel:\` and \`link ${spec.name} ssh:\` lines`
|
|
45862
|
+
);
|
|
45863
|
+
}
|
|
45864
|
+
|
|
45608
45865
|
// src/commands/sessions/nodes/webHop.ts
|
|
45609
45866
|
function webRemediation(spec, error) {
|
|
45867
|
+
if (spec.ssh && error.status === void 0)
|
|
45868
|
+
return `nothing listening on ${spec.ssh.port} on ${spec.ssh.alias} \u2014 is project-switch running ${spec.name}'s web server?`;
|
|
45610
45869
|
const { hostname: hostname2, port } = new URL(spec.url);
|
|
45611
45870
|
switch (peerErrorCode(error)) {
|
|
45612
45871
|
case "ECONNREFUSED":
|
|
@@ -45634,7 +45893,7 @@ async function webHop(spec, probes) {
|
|
|
45634
45893
|
hop: failed2(
|
|
45635
45894
|
"web",
|
|
45636
45895
|
`peer reports nodeName ${health2.nodeName}, link expects ${spec.name}`,
|
|
45637
|
-
`relink with \`assist sessions nodes unlink ${spec.name}\` then \`assist sessions nodes link ${health2.nodeName} ${spec.url}\`, or set sessions.nodeName on the peer`
|
|
45896
|
+
`relink with \`assist sessions nodes unlink ${spec.name}\` then \`assist sessions nodes link ${health2.nodeName} ${spec.ssh ? `--ssh ${spec.ssh.alias} --port ${spec.ssh.port}` : spec.url}\`, or set sessions.nodeName on the peer`
|
|
45638
45897
|
)
|
|
45639
45898
|
};
|
|
45640
45899
|
return {
|
|
@@ -45658,6 +45917,17 @@ function peerDaemonHop(spec, health2) {
|
|
|
45658
45917
|
async function diagnoseLink(spec, probes) {
|
|
45659
45918
|
const hops = [];
|
|
45660
45919
|
const done2 = () => ({ ...spec, ok: hops.every((h) => h.ok), hops });
|
|
45920
|
+
if (spec.ssh) {
|
|
45921
|
+
const { ssh } = spec;
|
|
45922
|
+
for (const probe of [
|
|
45923
|
+
() => agentHop(ssh, probes),
|
|
45924
|
+
() => sshHop(ssh, probes),
|
|
45925
|
+
() => tunnelHop(spec, ssh, probes)
|
|
45926
|
+
]) {
|
|
45927
|
+
hops.push(await probe());
|
|
45928
|
+
if (!hops.at(-1)?.ok) return done2();
|
|
45929
|
+
}
|
|
45930
|
+
}
|
|
45661
45931
|
const web3 = await webHop(spec, probes);
|
|
45662
45932
|
hops.push(web3.hop);
|
|
45663
45933
|
if (!web3.health) return done2();
|
|
@@ -45716,6 +45986,77 @@ async function probePeerHello(url) {
|
|
|
45716
45986
|
return result;
|
|
45717
45987
|
}
|
|
45718
45988
|
|
|
45989
|
+
// src/commands/sessions/nodes/probeSsh.ts
|
|
45990
|
+
import { spawn as spawn12 } from "child_process";
|
|
45991
|
+
var PROBE_TIMEOUT_MS = 15e3;
|
|
45992
|
+
function probeSsh(alias) {
|
|
45993
|
+
return new Promise((resolve25) => {
|
|
45994
|
+
const child = spawn12(
|
|
45995
|
+
"ssh",
|
|
45996
|
+
["-o", "BatchMode=yes", "-o", "ConnectTimeout=5", alias, "exit"],
|
|
45997
|
+
{ stdio: ["ignore", "ignore", "pipe"], windowsHide: true }
|
|
45998
|
+
);
|
|
45999
|
+
let stderr = "";
|
|
46000
|
+
child.stderr.on("data", (chunk) => {
|
|
46001
|
+
stderr += chunk;
|
|
46002
|
+
});
|
|
46003
|
+
const timer = setTimeout(() => child.kill(), PROBE_TIMEOUT_MS);
|
|
46004
|
+
child.once("error", (error) => {
|
|
46005
|
+
clearTimeout(timer);
|
|
46006
|
+
resolve25({ code: null, stderr: error.message });
|
|
46007
|
+
});
|
|
46008
|
+
child.once("close", (code) => {
|
|
46009
|
+
clearTimeout(timer);
|
|
46010
|
+
resolve25({ code, stderr: stderr.trim() });
|
|
46011
|
+
});
|
|
46012
|
+
});
|
|
46013
|
+
}
|
|
46014
|
+
|
|
46015
|
+
// src/commands/sessions/nodes/probeSshAgent.ts
|
|
46016
|
+
import { spawnSync as spawnSync11 } from "child_process";
|
|
46017
|
+
import { homedir as homedir26 } from "os";
|
|
46018
|
+
var PROBE_TIMEOUT_MS2 = 5e3;
|
|
46019
|
+
function parseIdentityAgent(sshConfig, env = process.env) {
|
|
46020
|
+
const line = sshConfig.split(/\r?\n/).find((l) => l.toLowerCase().startsWith("identityagent "));
|
|
46021
|
+
const value = line?.slice("identityagent ".length).trim().replace(/^"(.*)"$/, "$1");
|
|
46022
|
+
if (!value || value.toLowerCase() === "none") return void 0;
|
|
46023
|
+
if (value === "SSH_AUTH_SOCK" || value === "$SSH_AUTH_SOCK")
|
|
46024
|
+
return env.SSH_AUTH_SOCK;
|
|
46025
|
+
return value.replace(/^~(?=$|[/\\])/, homedir26());
|
|
46026
|
+
}
|
|
46027
|
+
function configuredAgent(alias) {
|
|
46028
|
+
const result = spawnSync11("ssh", ["-G", alias], {
|
|
46029
|
+
encoding: "utf8",
|
|
46030
|
+
timeout: PROBE_TIMEOUT_MS2,
|
|
46031
|
+
windowsHide: true
|
|
46032
|
+
});
|
|
46033
|
+
return parseIdentityAgent(result.stdout ?? "") ?? process.env.SSH_AUTH_SOCK;
|
|
46034
|
+
}
|
|
46035
|
+
async function probeSshAgent(alias) {
|
|
46036
|
+
const socket = configuredAgent(alias);
|
|
46037
|
+
if (!socket && process.platform !== "win32") return { status: "missing" };
|
|
46038
|
+
const result = spawnSync11("ssh-add", ["-l"], {
|
|
46039
|
+
encoding: "utf8",
|
|
46040
|
+
timeout: PROBE_TIMEOUT_MS2,
|
|
46041
|
+
windowsHide: true,
|
|
46042
|
+
env: socket ? { ...process.env, SSH_AUTH_SOCK: socket } : process.env
|
|
46043
|
+
});
|
|
46044
|
+
if (result.error)
|
|
46045
|
+
return { status: "unreachable", socket, error: result.error.message };
|
|
46046
|
+
if (result.status === 0)
|
|
46047
|
+
return {
|
|
46048
|
+
status: "ok",
|
|
46049
|
+
socket,
|
|
46050
|
+
keys: result.stdout.trim().split(/\r?\n/).length
|
|
46051
|
+
};
|
|
46052
|
+
if (result.status === 1) return { status: "no-keys", socket };
|
|
46053
|
+
return {
|
|
46054
|
+
status: "unreachable",
|
|
46055
|
+
socket,
|
|
46056
|
+
error: result.stderr.trim() || `ssh-add exited ${result.status}`
|
|
46057
|
+
};
|
|
46058
|
+
}
|
|
46059
|
+
|
|
45719
46060
|
// src/commands/sessions/nodes/printReport.ts
|
|
45720
46061
|
import chalk250 from "chalk";
|
|
45721
46062
|
function printReport(report2) {
|
|
@@ -45744,6 +46085,9 @@ function doctorProbes(live) {
|
|
|
45744
46085
|
return {
|
|
45745
46086
|
health: (url) => fetchPeerJson(url, "/api/health"),
|
|
45746
46087
|
hello: probePeerHello,
|
|
46088
|
+
sshAgent: probeSshAgent,
|
|
46089
|
+
ssh: probeSsh,
|
|
46090
|
+
tunnel: (localPort) => portAccepts(localPort),
|
|
45747
46091
|
linkState: (name) => {
|
|
45748
46092
|
if (!live) return "no-daemon";
|
|
45749
46093
|
return live.links.find((l) => l.name === name) ?? "unknown-link";
|
|
@@ -45751,9 +46095,7 @@ function doctorProbes(live) {
|
|
|
45751
46095
|
};
|
|
45752
46096
|
}
|
|
45753
46097
|
async function doctorNodes(name, options2) {
|
|
45754
|
-
const specs = (
|
|
45755
|
-
(spec) => !name || spec.name === name
|
|
45756
|
-
);
|
|
46098
|
+
const specs = loadLinkSpecs().filter((spec) => !name || spec.name === name);
|
|
45757
46099
|
if (name && specs.length === 0)
|
|
45758
46100
|
throw new Error(`No link named ${name}; see assist sessions nodes`);
|
|
45759
46101
|
const probes = doctorProbes(await queryNodes());
|
|
@@ -45793,13 +46135,38 @@ function parseLinkUrl(url) {
|
|
|
45793
46135
|
throw new Error(`link url must be http(s): ${url}`);
|
|
45794
46136
|
return parsed.origin;
|
|
45795
46137
|
}
|
|
45796
|
-
|
|
46138
|
+
function parsePort(flag, value) {
|
|
46139
|
+
const port = Number(value);
|
|
46140
|
+
if (!Number.isInteger(port) || port < 1 || port > 65535)
|
|
46141
|
+
throw new Error(`${flag} must be a port number, got ${value}`);
|
|
46142
|
+
return port;
|
|
46143
|
+
}
|
|
46144
|
+
function freeTunnelPort(port, others) {
|
|
46145
|
+
const taken = new Set(others.map((link3) => toLinkSpec(link3).ssh?.localPort));
|
|
46146
|
+
let candidate = defaultTunnelPort(port);
|
|
46147
|
+
while (taken.has(candidate)) candidate++;
|
|
46148
|
+
return candidate;
|
|
46149
|
+
}
|
|
46150
|
+
function buildLink(name, url, options2, others) {
|
|
46151
|
+
if (url && options2.ssh)
|
|
46152
|
+
throw new Error("pass either <url> or --ssh <alias>, not both");
|
|
46153
|
+
if (url) return { name, url: parseLinkUrl(url) };
|
|
46154
|
+
if (!options2.ssh)
|
|
46155
|
+
throw new Error("pass the peer's <url> or --ssh <alias> --port <port>");
|
|
46156
|
+
const port = parsePort("--port", options2.port);
|
|
46157
|
+
const localPort = options2.localPort ? parsePort("--local-port", options2.localPort) : freeTunnelPort(port, others);
|
|
46158
|
+
return { name, ssh: options2.ssh, port, localPort };
|
|
46159
|
+
}
|
|
46160
|
+
async function linkNode(name, url, options2) {
|
|
45797
46161
|
if (name.includes(":")) throw new Error("node names cannot contain ':'");
|
|
45798
46162
|
if (name === resolveNodeName())
|
|
45799
46163
|
throw new Error(`${name} is this node; link to a different node`);
|
|
45800
|
-
const others = readLinks().filter((
|
|
45801
|
-
|
|
45802
|
-
|
|
46164
|
+
const others = readLinks().filter((link4) => link4.name !== name);
|
|
46165
|
+
const link3 = buildLink(name, url, options2, others);
|
|
46166
|
+
await writeLinks([...others, link3]);
|
|
46167
|
+
console.log(
|
|
46168
|
+
chalk251.green(`Linked ${name} (${describeTarget(toLinkSpec(link3))})`)
|
|
46169
|
+
);
|
|
45803
46170
|
}
|
|
45804
46171
|
|
|
45805
46172
|
// src/commands/sessions/nodes/listNodes.ts
|
|
@@ -45808,11 +46175,10 @@ async function nodesReport() {
|
|
|
45808
46175
|
const live = await queryNodes();
|
|
45809
46176
|
if (live)
|
|
45810
46177
|
return { local: live.local, daemonRunning: true, links: live.links };
|
|
45811
|
-
const configured = loadConfig().sessions?.links ?? [];
|
|
45812
46178
|
return {
|
|
45813
46179
|
local: resolveNodeName(),
|
|
45814
46180
|
daemonRunning: false,
|
|
45815
|
-
links:
|
|
46181
|
+
links: loadLinkSpecs().map((link3) => ({ ...link3, state: "disconnected" }))
|
|
45816
46182
|
};
|
|
45817
46183
|
}
|
|
45818
46184
|
async function listNodes(options2) {
|
|
@@ -45836,7 +46202,7 @@ async function fetchLogTail(name, lines2) {
|
|
|
45836
46202
|
path: daemonPaths.log,
|
|
45837
46203
|
lines: readLogTail(daemonPaths.log, lines2)
|
|
45838
46204
|
};
|
|
45839
|
-
const link3 =
|
|
46205
|
+
const link3 = findLinkSpec(name);
|
|
45840
46206
|
if (!link3)
|
|
45841
46207
|
throw new Error(`No link named ${name}; see assist sessions nodes`);
|
|
45842
46208
|
try {
|
|
@@ -45878,8 +46244,14 @@ async function unlinkNode(name) {
|
|
|
45878
46244
|
// src/commands/sessions/nodes/registerNodes.ts
|
|
45879
46245
|
function registerNodes(sessions) {
|
|
45880
46246
|
const cmd = sessions.command("nodes").description("List this node and every linked node with its link state").option("--json", "Output as JSON").action(listNodes);
|
|
45881
|
-
cmd.command("link <name>
|
|
45882
|
-
"Link a peer node by its web server URL (name must match the peer's sessions.nodeName)"
|
|
46247
|
+
cmd.command("link <name> [url]").description(
|
|
46248
|
+
"Link a peer node by its web server URL, or over ssh with --ssh and --port (name must match the peer's sessions.nodeName)"
|
|
46249
|
+
).option(
|
|
46250
|
+
"--ssh <alias>",
|
|
46251
|
+
"Tunnel to the peer through this ~/.ssh/config alias"
|
|
46252
|
+
).option("--port <port>", "The peer's loopback web server port (with --ssh)").option(
|
|
46253
|
+
"--local-port <port>",
|
|
46254
|
+
"Local end of the ssh tunnel (default: 43000 + port % 1000, bumped past other links)"
|
|
45883
46255
|
).action(linkNode);
|
|
45884
46256
|
cmd.command("unlink <name>").description("Remove a linked node").action(unlinkNode);
|
|
45885
46257
|
cmd.command("doctor [name]").description(
|