@staff0rd/assist 0.1092.4 → 0.1093.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/dist/built-version +1 -1
- package/dist/commands/sessions/web/bundle.js +432 -432
- package/dist/index.js +78 -38
- 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.1093.1",
|
|
10
10
|
type: "module",
|
|
11
11
|
main: "dist/index.js",
|
|
12
12
|
bin: {
|
|
@@ -880,7 +880,8 @@ var assistConfigShape = {
|
|
|
880
880
|
}).optional(),
|
|
881
881
|
autoUpdate: z6.strictObject({
|
|
882
882
|
enabled: z6.boolean().default(true),
|
|
883
|
-
restart: z6.boolean().default(false)
|
|
883
|
+
restart: z6.boolean().default(false),
|
|
884
|
+
idleMinutes: z6.number().positive().default(2)
|
|
884
885
|
}).optional(),
|
|
885
886
|
worktree: z6.strictObject({
|
|
886
887
|
enabled: z6.boolean().default(false),
|
|
@@ -6473,6 +6474,11 @@ var autoUpdateConfigHelp = [
|
|
|
6473
6474
|
key: "autoUpdate.restart",
|
|
6474
6475
|
setter: "assist config set autoUpdate.restart true --node",
|
|
6475
6476
|
note: "the node's web server applies a ready update itself, restarting the daemon and/or web server once every live agent session has been awaiting the user for a minute (or there are none); skipped while the build is pending, the loop is diverged or paused, and attempted once per built version. Toggle it per node from the Updates page (default off)"
|
|
6477
|
+
},
|
|
6478
|
+
{
|
|
6479
|
+
key: "autoUpdate.idleMinutes",
|
|
6480
|
+
setter: "assist config set autoUpdate.idleMinutes 5 --node",
|
|
6481
|
+
note: "with autoUpdate.restart on, hold the auto-restart until the web UI has seen no pointer, keyboard, wheel or touch input for this many minutes (default 2)"
|
|
6476
6482
|
}
|
|
6477
6483
|
];
|
|
6478
6484
|
|
|
@@ -14850,24 +14856,6 @@ function autoRestartAttempts(port, path110 = defaultPath) {
|
|
|
14850
14856
|
};
|
|
14851
14857
|
}
|
|
14852
14858
|
|
|
14853
|
-
// src/commands/sessions/web/updates/autoRestart/attemptAutoRestart.ts
|
|
14854
|
-
async function attemptAutoRestart(deps2, target, built) {
|
|
14855
|
-
deps2.attempted.set(built);
|
|
14856
|
-
deps2.log(`auto-restart: restarting ${target} to apply v${built}`);
|
|
14857
|
-
try {
|
|
14858
|
-
await deps2.restart(target);
|
|
14859
|
-
} catch (error) {
|
|
14860
|
-
deps2.log(
|
|
14861
|
-
`auto-restart: ${target} restart for v${built} failed: ${error instanceof Error ? error.message : String(error)}`
|
|
14862
|
-
);
|
|
14863
|
-
}
|
|
14864
|
-
}
|
|
14865
|
-
|
|
14866
|
-
// src/commands/sessions/web/updates/autoRestart/autoRestartTarget.ts
|
|
14867
|
-
function autoRestartTarget(restart) {
|
|
14868
|
-
return restart.length > 1 ? "both" : restart[0];
|
|
14869
|
-
}
|
|
14870
|
-
|
|
14871
14859
|
// src/commands/sessions/shared/isBusy.ts
|
|
14872
14860
|
function isBusy(session) {
|
|
14873
14861
|
if (session.node !== void 0 || session.commandType === "run") return false;
|
|
@@ -14877,7 +14865,12 @@ function isBusy(session) {
|
|
|
14877
14865
|
}
|
|
14878
14866
|
|
|
14879
14867
|
// src/commands/sessions/web/updates/autoRestart/autoRestartBlocker.ts
|
|
14880
|
-
|
|
14868
|
+
var DEFAULT_IDLE_MINUTES = 2;
|
|
14869
|
+
function userActive(input, now) {
|
|
14870
|
+
const idleMinutes = input.idleMinutes ?? DEFAULT_IDLE_MINUTES;
|
|
14871
|
+
return input.lastUserActivityAt !== void 0 && now - input.lastUserActivityAt < idleMinutes * 6e4;
|
|
14872
|
+
}
|
|
14873
|
+
function autoRestartBlocker(input, now) {
|
|
14881
14874
|
if (input.buildPending) return "build pending";
|
|
14882
14875
|
if (!input.loop) return "daemon not reachable";
|
|
14883
14876
|
if (input.loop.paused) return "auto-update paused";
|
|
@@ -14885,13 +14878,42 @@ function autoRestartBlocker(input) {
|
|
|
14885
14878
|
const busy = input.sessions.filter(isBusy);
|
|
14886
14879
|
if (busy.length > 0)
|
|
14887
14880
|
return `waiting on ${busy.length} running session${busy.length === 1 ? "" : "s"} (${busy.map((s) => s.name).join(", ")})`;
|
|
14881
|
+
if (userActive(input, now))
|
|
14882
|
+
return `you're active \xB7 restarting ${input.idleMinutes ?? DEFAULT_IDLE_MINUTES}m after you stop`;
|
|
14888
14883
|
return void 0;
|
|
14889
14884
|
}
|
|
14890
14885
|
|
|
14886
|
+
// src/commands/sessions/web/updates/autoRestart/autoRestartIdleMinutes.ts
|
|
14887
|
+
function autoRestartIdleMinutes(installDir) {
|
|
14888
|
+
try {
|
|
14889
|
+
return loadConfigFrom(installDir).autoUpdate?.idleMinutes ?? DEFAULT_IDLE_MINUTES;
|
|
14890
|
+
} catch {
|
|
14891
|
+
return DEFAULT_IDLE_MINUTES;
|
|
14892
|
+
}
|
|
14893
|
+
}
|
|
14894
|
+
|
|
14895
|
+
// src/commands/sessions/web/updates/autoRestart/attemptAutoRestart.ts
|
|
14896
|
+
async function attemptAutoRestart(deps2, target, built) {
|
|
14897
|
+
deps2.attempted.set(built);
|
|
14898
|
+
deps2.log(`auto-restart: restarting ${target} to apply v${built}`);
|
|
14899
|
+
try {
|
|
14900
|
+
await deps2.restart(target);
|
|
14901
|
+
} catch (error) {
|
|
14902
|
+
deps2.log(
|
|
14903
|
+
`auto-restart: ${target} restart for v${built} failed: ${error instanceof Error ? error.message : String(error)}`
|
|
14904
|
+
);
|
|
14905
|
+
}
|
|
14906
|
+
}
|
|
14907
|
+
|
|
14908
|
+
// src/commands/sessions/web/updates/autoRestart/autoRestartTarget.ts
|
|
14909
|
+
function autoRestartTarget(restart) {
|
|
14910
|
+
return restart.length > 1 ? "both" : restart[0];
|
|
14911
|
+
}
|
|
14912
|
+
|
|
14891
14913
|
// src/commands/sessions/web/updates/autoRestart/blockedBy.ts
|
|
14892
|
-
function blockedBy(snap, attempted2) {
|
|
14914
|
+
function blockedBy(snap, attempted2, now) {
|
|
14893
14915
|
if (attempted2 === snap.built) return "already attempted";
|
|
14894
|
-
return autoRestartBlocker(snap);
|
|
14916
|
+
return autoRestartBlocker(snap, now);
|
|
14895
14917
|
}
|
|
14896
14918
|
|
|
14897
14919
|
// src/commands/sessions/web/updates/autoRestart/createAutoRestartNotes.ts
|
|
@@ -14924,10 +14946,17 @@ function createAutoRestartNotes(deps2) {
|
|
|
14924
14946
|
}
|
|
14925
14947
|
|
|
14926
14948
|
// src/commands/sessions/web/updates/autoRestart/autoRestartPreflight.ts
|
|
14927
|
-
async function autoRestartPreflight(deps2, snap, activity2) {
|
|
14949
|
+
async function autoRestartPreflight(deps2, snap, activity2, now) {
|
|
14928
14950
|
const fresh = await deps2.freshSessions();
|
|
14929
14951
|
if (!fresh) return "daemon not reachable";
|
|
14930
|
-
return blockedBy({ ...snap, ...fresh }, deps2.attempted.get()) ?? (fresh.restartActivity !== activity2 ? "session activity changed" : void 0);
|
|
14952
|
+
return blockedBy({ ...snap, ...fresh }, deps2.attempted.get(), now()) ?? (fresh.restartActivity !== activity2 ? "session activity changed" : void 0);
|
|
14953
|
+
}
|
|
14954
|
+
|
|
14955
|
+
// src/commands/sessions/web/updates/autoRestart/noteSkipped.ts
|
|
14956
|
+
function noteSkipped(note, target, built, blocker) {
|
|
14957
|
+
if (!blocker) return false;
|
|
14958
|
+
note(`skipped ${target} restart for v${built}: ${blocker}`, blocker);
|
|
14959
|
+
return true;
|
|
14931
14960
|
}
|
|
14932
14961
|
|
|
14933
14962
|
// src/commands/sessions/web/updates/autoRestart/createAutoRestartCheck.ts
|
|
@@ -14945,19 +14974,11 @@ function createAutoRestartCheck(deps2) {
|
|
|
14945
14974
|
}
|
|
14946
14975
|
if (snap.restart.length === 0) return note(void 0);
|
|
14947
14976
|
const target = autoRestartTarget(snap.restart);
|
|
14948
|
-
const blocker = blockedBy(snap, deps2.attempted.get());
|
|
14949
|
-
if (blocker)
|
|
14950
|
-
return note(
|
|
14951
|
-
`skipped ${target} restart for v${snap.built}: ${blocker}`,
|
|
14952
|
-
blocker
|
|
14953
|
-
);
|
|
14977
|
+
const blocker = blockedBy(snap, deps2.attempted.get(), now());
|
|
14978
|
+
if (noteSkipped(note, target, snap.built, blocker)) return;
|
|
14954
14979
|
if (!notes.settled(now(), target, snap.built)) return;
|
|
14955
|
-
const finalBlocker = await autoRestartPreflight(deps2, snap, activity2);
|
|
14956
|
-
if (finalBlocker)
|
|
14957
|
-
return note(
|
|
14958
|
-
`skipped ${target} restart for v${snap.built}: ${finalBlocker}`,
|
|
14959
|
-
finalBlocker
|
|
14960
|
-
);
|
|
14980
|
+
const finalBlocker = await autoRestartPreflight(deps2, snap, activity2, now);
|
|
14981
|
+
if (noteSkipped(note, target, snap.built, finalBlocker)) return;
|
|
14961
14982
|
note(void 0, "restarting");
|
|
14962
14983
|
await attemptAutoRestart(deps2, target, snap.built);
|
|
14963
14984
|
};
|
|
@@ -14990,7 +15011,9 @@ async function snapshot(installDir) {
|
|
|
14990
15011
|
restart: state.restart,
|
|
14991
15012
|
loop: greeting ? state.reply?.loop : void 0,
|
|
14992
15013
|
sessions: greeting?.sessions ?? [],
|
|
14993
|
-
restartActivity: greeting?.restartActivity
|
|
15014
|
+
restartActivity: greeting?.restartActivity,
|
|
15015
|
+
lastUserActivityAt: greeting?.lastUserActivityAt,
|
|
15016
|
+
idleMinutes: autoRestartIdleMinutes(installDir)
|
|
14994
15017
|
};
|
|
14995
15018
|
}
|
|
14996
15019
|
function startAutoRestart(port) {
|
|
@@ -51533,6 +51556,20 @@ function toSessionInfo(session) {
|
|
|
51533
51556
|
};
|
|
51534
51557
|
}
|
|
51535
51558
|
|
|
51559
|
+
// src/commands/sessions/daemon/userActivity.ts
|
|
51560
|
+
var LOG_AFTER_IDLE_MS = 6e4;
|
|
51561
|
+
var lastAt;
|
|
51562
|
+
var userActivity = {
|
|
51563
|
+
get: () => lastAt,
|
|
51564
|
+
record: (at2 = Date.now()) => {
|
|
51565
|
+
if (lastAt === void 0 || at2 - lastAt > LOG_AFTER_IDLE_MS)
|
|
51566
|
+
daemonLog(
|
|
51567
|
+
`user-activity: web UI in use${lastAt === void 0 ? "" : ` after ${Math.round((at2 - lastAt) / 1e3)}s idle`}`
|
|
51568
|
+
);
|
|
51569
|
+
lastAt = at2;
|
|
51570
|
+
}
|
|
51571
|
+
};
|
|
51572
|
+
|
|
51536
51573
|
// src/commands/sessions/daemon/broadcastSessions.ts
|
|
51537
51574
|
var activityCounts = /* @__PURE__ */ new WeakMap();
|
|
51538
51575
|
function broadcastSessions(sessions, clients, linkedSessions = [], active) {
|
|
@@ -51541,10 +51578,12 @@ function broadcastSessions(sessions, clients, linkedSessions = [], active) {
|
|
|
51541
51578
|
const count10 = (activityCounts.get(sessions) ?? 0) + (local.some(isBusy) ? 1 : 0);
|
|
51542
51579
|
activityCounts.set(sessions, count10);
|
|
51543
51580
|
const restartActivity = `${process.pid}:${count10}`;
|
|
51581
|
+
const lastUserActivityAt = userActivity.get();
|
|
51544
51582
|
const viewers = clients.viewers();
|
|
51545
51583
|
broadcast(viewers, {
|
|
51546
51584
|
type: "sessions",
|
|
51547
51585
|
restartActivity,
|
|
51586
|
+
lastUserActivityAt,
|
|
51548
51587
|
sessions: local.concat(linkedSessions),
|
|
51549
51588
|
active: active?.toJSON() ?? {}
|
|
51550
51589
|
});
|
|
@@ -59869,6 +59908,7 @@ var messageHandlers = {
|
|
|
59869
59908
|
},
|
|
59870
59909
|
"pr-preview": (client, m, d) => m.prPreview.set(client, d),
|
|
59871
59910
|
"pr-decision": routed((_client, m, d) => m.prPreview.decide(d)),
|
|
59911
|
+
"user-activity": () => userActivity.record(),
|
|
59872
59912
|
"ui-status": (_client, _m, d) => daemonLog(`ui rendered: id=${d.sessionId} status=${d.status}`)
|
|
59873
59913
|
};
|
|
59874
59914
|
|