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