@staff0rd/assist 0.825.2 → 0.827.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/commands/sessions/web/bundle.js +3 -3
- package/dist/index.js +177 -56
- 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.827.0",
|
|
10
10
|
type: "module",
|
|
11
11
|
main: "dist/index.js",
|
|
12
12
|
bin: {
|
|
@@ -46333,6 +46333,7 @@ function respawnSession(session, respawn, status2, clients, onStatusChange) {
|
|
|
46333
46333
|
session.gitWatcher = void 0;
|
|
46334
46334
|
session.undurable = void 0;
|
|
46335
46335
|
session.pendingDismiss = void 0;
|
|
46336
|
+
session.pendingStart = void 0;
|
|
46336
46337
|
session.closeGrace?.cancel();
|
|
46337
46338
|
session.closing = void 0;
|
|
46338
46339
|
session.scrollback = "";
|
|
@@ -46539,6 +46540,134 @@ function releaseClient(client, clients, prPreview, verify) {
|
|
|
46539
46540
|
verify.clear(client);
|
|
46540
46541
|
}
|
|
46541
46542
|
|
|
46543
|
+
// src/commands/sessions/daemon/findPortHolderPid.ts
|
|
46544
|
+
import { execFileSync as execFileSync24 } from "child_process";
|
|
46545
|
+
var PROBE_TIMEOUT_MS = 3e3;
|
|
46546
|
+
function findPortHolderPid(port) {
|
|
46547
|
+
try {
|
|
46548
|
+
return process.platform === "win32" ? netstatListenerPid(probe("netstat", ["-ano"]), port) : firstPid(probe("lsof", ["-nP", `-iTCP:${port}`, "-sTCP:LISTEN", "-t"]));
|
|
46549
|
+
} catch {
|
|
46550
|
+
return void 0;
|
|
46551
|
+
}
|
|
46552
|
+
}
|
|
46553
|
+
function probe(command, args) {
|
|
46554
|
+
return execFileSync24(command, args, {
|
|
46555
|
+
encoding: "utf8",
|
|
46556
|
+
timeout: PROBE_TIMEOUT_MS,
|
|
46557
|
+
stdio: ["ignore", "pipe", "ignore"]
|
|
46558
|
+
});
|
|
46559
|
+
}
|
|
46560
|
+
function netstatListenerPid(output, port) {
|
|
46561
|
+
const suffix = `:${port}`;
|
|
46562
|
+
for (const line of output.split("\n")) {
|
|
46563
|
+
const [protocol, local, , state, pid] = line.trim().split(/\s+/);
|
|
46564
|
+
if (protocol?.toUpperCase() !== "TCP") continue;
|
|
46565
|
+
if (state?.toUpperCase() !== "LISTENING") continue;
|
|
46566
|
+
if (!local?.endsWith(suffix)) continue;
|
|
46567
|
+
const holder = Number.parseInt(pid ?? "", 10);
|
|
46568
|
+
if (Number.isInteger(holder)) return holder;
|
|
46569
|
+
}
|
|
46570
|
+
return void 0;
|
|
46571
|
+
}
|
|
46572
|
+
function firstPid(output) {
|
|
46573
|
+
for (const line of output.split("\n")) {
|
|
46574
|
+
const pid = Number.parseInt(line.trim(), 10);
|
|
46575
|
+
if (Number.isInteger(pid)) return pid;
|
|
46576
|
+
}
|
|
46577
|
+
return void 0;
|
|
46578
|
+
}
|
|
46579
|
+
|
|
46580
|
+
// src/commands/sessions/daemon/heldStartBlocked.ts
|
|
46581
|
+
function heldStartBlocked(session, sessions) {
|
|
46582
|
+
const where = session.worktree?.path ?? "no worktree";
|
|
46583
|
+
if (sessions.get(session.id) !== session) {
|
|
46584
|
+
daemonLog(
|
|
46585
|
+
`session ${session.id} not started after seeding: card is gone (${where})`
|
|
46586
|
+
);
|
|
46587
|
+
return true;
|
|
46588
|
+
}
|
|
46589
|
+
if (session.closing) {
|
|
46590
|
+
daemonLog(
|
|
46591
|
+
`session ${session.id} not started after seeding: card is closing (${where})`
|
|
46592
|
+
);
|
|
46593
|
+
return true;
|
|
46594
|
+
}
|
|
46595
|
+
return false;
|
|
46596
|
+
}
|
|
46597
|
+
|
|
46598
|
+
// src/commands/sessions/daemon/startHeldSession.ts
|
|
46599
|
+
function startHeldSession(session, sessions, clients, onStatusChange, notify2, trigger) {
|
|
46600
|
+
const start2 = session.pendingStart;
|
|
46601
|
+
if (!start2) return;
|
|
46602
|
+
session.pendingStart = void 0;
|
|
46603
|
+
if (heldStartBlocked(session, sessions)) return;
|
|
46604
|
+
session.startedAt = Date.now();
|
|
46605
|
+
if (session.status === "running") session.runningSince = session.startedAt;
|
|
46606
|
+
try {
|
|
46607
|
+
session.pty = start2();
|
|
46608
|
+
} catch (error) {
|
|
46609
|
+
refuseSpawn(
|
|
46610
|
+
session,
|
|
46611
|
+
error,
|
|
46612
|
+
clients,
|
|
46613
|
+
onStatusChange,
|
|
46614
|
+
"started after seeding"
|
|
46615
|
+
);
|
|
46616
|
+
notify2();
|
|
46617
|
+
return;
|
|
46618
|
+
}
|
|
46619
|
+
if (session.cols && session.rows)
|
|
46620
|
+
try {
|
|
46621
|
+
session.pty?.resize(session.cols, session.rows);
|
|
46622
|
+
} catch {
|
|
46623
|
+
}
|
|
46624
|
+
wirePtyEvents(session, clients, onStatusChange);
|
|
46625
|
+
daemonLog(
|
|
46626
|
+
`session ${session.id} started once ${trigger ?? `worktree ${session.worktree?.path ?? session.cwd} finished seeding`}`
|
|
46627
|
+
);
|
|
46628
|
+
notify2();
|
|
46629
|
+
}
|
|
46630
|
+
|
|
46631
|
+
// src/commands/sessions/daemon/awaitServerPort.ts
|
|
46632
|
+
var portWaitTiming = { pollMs: 500, timeoutMs: 3e4 };
|
|
46633
|
+
function awaitServerPort(session, port, deps2) {
|
|
46634
|
+
const { sessions, clients, onStatusChange, notify: notify2 } = deps2;
|
|
46635
|
+
const deadline = Date.now() + portWaitTiming.timeoutMs;
|
|
46636
|
+
const label2 = `session ${session.id} ("${session.name}")`;
|
|
46637
|
+
const tick = () => {
|
|
46638
|
+
if (!session.pendingStart || sessions.get(session.id) !== session) return;
|
|
46639
|
+
const holder = findPortHolderPid(port);
|
|
46640
|
+
if (holder === void 0) {
|
|
46641
|
+
daemonLog(`${label2} port ${port} freed`);
|
|
46642
|
+
startHeldSession(
|
|
46643
|
+
session,
|
|
46644
|
+
sessions,
|
|
46645
|
+
clients,
|
|
46646
|
+
onStatusChange,
|
|
46647
|
+
notify2,
|
|
46648
|
+
`port ${port} freed`
|
|
46649
|
+
);
|
|
46650
|
+
return;
|
|
46651
|
+
}
|
|
46652
|
+
if (Date.now() < deadline) {
|
|
46653
|
+
setTimeout(tick, portWaitTiming.pollMs);
|
|
46654
|
+
return;
|
|
46655
|
+
}
|
|
46656
|
+
daemonLog(
|
|
46657
|
+
`${label2} gave up waiting for port ${port} after ${portWaitTiming.timeoutMs}ms`
|
|
46658
|
+
);
|
|
46659
|
+
refuseSpawn(
|
|
46660
|
+
session,
|
|
46661
|
+
new Error(`port ${port} is still held by pid ${holder}`),
|
|
46662
|
+
clients,
|
|
46663
|
+
onStatusChange,
|
|
46664
|
+
"relaunched"
|
|
46665
|
+
);
|
|
46666
|
+
notify2();
|
|
46667
|
+
};
|
|
46668
|
+
setTimeout(tick, portWaitTiming.pollMs);
|
|
46669
|
+
}
|
|
46670
|
+
|
|
46542
46671
|
// src/commands/sessions/daemon/restoredAutoAdvance.ts
|
|
46543
46672
|
function restoredAutoAdvance(id, persisted) {
|
|
46544
46673
|
const itemId2 = persisted.activity?.itemId;
|
|
@@ -46873,6 +47002,38 @@ function restoreCodexSession(id, persisted, base, status2) {
|
|
|
46873
47002
|
return plan2.idle ? waitingSession(base, persisted, pty2) : runningSession(base, persisted, pty2);
|
|
46874
47003
|
}
|
|
46875
47004
|
|
|
47005
|
+
// src/commands/sessions/daemon/restoreServerRun.ts
|
|
47006
|
+
function restoreServerRun(id, persisted, base) {
|
|
47007
|
+
const { runName } = persisted;
|
|
47008
|
+
if (persisted.commandType !== "run" || !runName) return null;
|
|
47009
|
+
const meta = serverRunMeta(runName, persisted.cwd);
|
|
47010
|
+
if (!meta.server) return null;
|
|
47011
|
+
daemonLog(
|
|
47012
|
+
`relaunching server run session ${id} ("${persisted.name}") for ${meta.origin} (${meta.group})`
|
|
47013
|
+
);
|
|
47014
|
+
const holder = meta.port ? findPortHolderPid(meta.port) : void 0;
|
|
47015
|
+
if (holder !== void 0)
|
|
47016
|
+
daemonLog(
|
|
47017
|
+
`session ${id} ("${persisted.name}") waiting for port ${meta.port} (held by pid ${holder}) to free before relaunching`
|
|
47018
|
+
);
|
|
47019
|
+
const { pty: pty2, pendingStart } = startOrHoldPty(
|
|
47020
|
+
() => spawnRun({ name: runName, args: persisted.runArgs, cwd: persisted.cwd }),
|
|
47021
|
+
holder !== void 0
|
|
47022
|
+
);
|
|
47023
|
+
return {
|
|
47024
|
+
...runningSession(base, persisted, pty2),
|
|
47025
|
+
pendingStart,
|
|
47026
|
+
scrollback: holder === void 0 ? base.scrollback : `Waiting for port ${meta.port} (held by pid ${holder}) to free\u2026\r
|
|
47027
|
+
`,
|
|
47028
|
+
runName,
|
|
47029
|
+
runArgs: persisted.runArgs,
|
|
47030
|
+
server: true,
|
|
47031
|
+
serverPort: meta.port,
|
|
47032
|
+
serverOrigin: meta.origin,
|
|
47033
|
+
serverGroup: meta.group
|
|
47034
|
+
};
|
|
47035
|
+
}
|
|
47036
|
+
|
|
46876
47037
|
// src/commands/sessions/daemon/unresumableReason.ts
|
|
46877
47038
|
function unresumableReason(harness) {
|
|
46878
47039
|
if (resolveHarness(harness) === "claude")
|
|
@@ -46916,6 +47077,8 @@ function restoreInteractiveSession(id, persisted, base, status2) {
|
|
|
46916
47077
|
if (persisted.commandType === "claude") {
|
|
46917
47078
|
return unrecoverableClaude(id, persisted);
|
|
46918
47079
|
}
|
|
47080
|
+
const serverRun = restoreServerRun(id, persisted, base);
|
|
47081
|
+
if (serverRun) return serverRun;
|
|
46919
47082
|
return notRestoredStub(base, persisted);
|
|
46920
47083
|
}
|
|
46921
47084
|
function unrecoverableClaude(id, persisted) {
|
|
@@ -47278,10 +47441,14 @@ async function recoverOrphanedWorktrees(sessions, spawnWith, notify2) {
|
|
|
47278
47441
|
}
|
|
47279
47442
|
|
|
47280
47443
|
// src/commands/sessions/daemon/restoreAllSessions.ts
|
|
47281
|
-
function restoreAllSessions(spawner,
|
|
47444
|
+
function restoreAllSessions(spawner, deps2) {
|
|
47445
|
+
const { sessions, notify: notify2 } = deps2;
|
|
47282
47446
|
const names = restoreAll(spawner, sessions);
|
|
47283
47447
|
reconcileWorktreesOnRestore(sessions, spawner.recoveryCard, notify2);
|
|
47284
47448
|
rearmStoppedSessions(sessions, notify2);
|
|
47449
|
+
for (const session of sessions.values())
|
|
47450
|
+
if (session.server && session.serverPort && session.pendingStart)
|
|
47451
|
+
awaitServerPort(session, session.serverPort, deps2);
|
|
47285
47452
|
return names;
|
|
47286
47453
|
}
|
|
47287
47454
|
|
|
@@ -47426,57 +47593,6 @@ function recordInterruptions(sessions) {
|
|
|
47426
47593
|
}
|
|
47427
47594
|
}
|
|
47428
47595
|
|
|
47429
|
-
// src/commands/sessions/daemon/heldStartBlocked.ts
|
|
47430
|
-
function heldStartBlocked(session, sessions) {
|
|
47431
|
-
const where = session.worktree?.path ?? "no worktree";
|
|
47432
|
-
if (sessions.get(session.id) !== session) {
|
|
47433
|
-
daemonLog(
|
|
47434
|
-
`session ${session.id} not started after seeding: card is gone (${where})`
|
|
47435
|
-
);
|
|
47436
|
-
return true;
|
|
47437
|
-
}
|
|
47438
|
-
if (session.closing) {
|
|
47439
|
-
daemonLog(
|
|
47440
|
-
`session ${session.id} not started after seeding: card is closing (${where})`
|
|
47441
|
-
);
|
|
47442
|
-
return true;
|
|
47443
|
-
}
|
|
47444
|
-
return false;
|
|
47445
|
-
}
|
|
47446
|
-
|
|
47447
|
-
// src/commands/sessions/daemon/startHeldSession.ts
|
|
47448
|
-
function startHeldSession(session, sessions, clients, onStatusChange, notify2) {
|
|
47449
|
-
const start2 = session.pendingStart;
|
|
47450
|
-
if (!start2) return;
|
|
47451
|
-
session.pendingStart = void 0;
|
|
47452
|
-
if (heldStartBlocked(session, sessions)) return;
|
|
47453
|
-
session.startedAt = Date.now();
|
|
47454
|
-
if (session.status === "running") session.runningSince = session.startedAt;
|
|
47455
|
-
try {
|
|
47456
|
-
session.pty = start2();
|
|
47457
|
-
} catch (error) {
|
|
47458
|
-
refuseSpawn(
|
|
47459
|
-
session,
|
|
47460
|
-
error,
|
|
47461
|
-
clients,
|
|
47462
|
-
onStatusChange,
|
|
47463
|
-
"started after seeding"
|
|
47464
|
-
);
|
|
47465
|
-
notify2();
|
|
47466
|
-
return;
|
|
47467
|
-
}
|
|
47468
|
-
if (session.cols && session.rows)
|
|
47469
|
-
try {
|
|
47470
|
-
session.pty?.resize(session.cols, session.rows);
|
|
47471
|
-
} catch {
|
|
47472
|
-
}
|
|
47473
|
-
wirePtyEvents(session, clients, onStatusChange);
|
|
47474
|
-
daemonLog(
|
|
47475
|
-
`session ${session.id} started once worktree ${session.worktree?.path ?? session.cwd} finished seeding`
|
|
47476
|
-
);
|
|
47477
|
-
notify2();
|
|
47478
|
-
}
|
|
47479
|
-
|
|
47480
47596
|
// src/commands/sessions/daemon/startHeldInTree.ts
|
|
47481
47597
|
function startHeldInTree(seeded, sessions, clients, onStatusChange, notify2) {
|
|
47482
47598
|
const start2 = (session) => startHeldSession(session, sessions, clients, onStatusChange, notify2);
|
|
@@ -48486,7 +48602,12 @@ var SessionManager = class {
|
|
|
48486
48602
|
);
|
|
48487
48603
|
}
|
|
48488
48604
|
restore() {
|
|
48489
|
-
return restoreAllSessions(this.spawner,
|
|
48605
|
+
return restoreAllSessions(this.spawner, {
|
|
48606
|
+
sessions: this.sessions,
|
|
48607
|
+
clients: this.clients,
|
|
48608
|
+
onStatusChange: this.onStatusChange,
|
|
48609
|
+
notify: this.notify
|
|
48610
|
+
});
|
|
48490
48611
|
}
|
|
48491
48612
|
drain = () => drainSessions(this.sessions, this.notify);
|
|
48492
48613
|
spawner = makeSessionSpawner(
|
|
@@ -50058,7 +50179,7 @@ function summaryPathFor(jsonlPath2) {
|
|
|
50058
50179
|
}
|
|
50059
50180
|
|
|
50060
50181
|
// src/commands/sessions/summarise/summariseSession.ts
|
|
50061
|
-
import { execFileSync as
|
|
50182
|
+
import { execFileSync as execFileSync25 } from "child_process";
|
|
50062
50183
|
function summariseSession(jsonlPath2) {
|
|
50063
50184
|
const firstMessage = extractFirstUserMessage(jsonlPath2);
|
|
50064
50185
|
const backlogIds = scanSessionBacklogRefs(jsonlPath2);
|
|
@@ -50067,7 +50188,7 @@ function summariseSession(jsonlPath2) {
|
|
|
50067
50188
|
}
|
|
50068
50189
|
const prompt = buildPrompt6(firstMessage, backlogIds);
|
|
50069
50190
|
try {
|
|
50070
|
-
const output =
|
|
50191
|
+
const output = execFileSync25("claude", ["-p", "--model", "haiku", prompt], {
|
|
50071
50192
|
encoding: "utf8",
|
|
50072
50193
|
timeout: 3e4,
|
|
50073
50194
|
stdio: ["ignore", "pipe", "ignore"]
|