@nodii/dev 0.6.70 → 0.6.71
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 +9 -3
- package/dist/cli.js +2 -2
- package/dist/core.js +1 -1
- package/dist/lanes.js +3 -1
- package/dist/starting.js +25 -4
- package/dist/watchdog.js +22 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -530,9 +530,15 @@ gone, and watched worktrees whose HEAD has commits absent from its configured
|
|
|
530
530
|
remote branch. Each observation is posted to the watched run by the machine
|
|
531
531
|
coordinator; `process_dead` transitions it to explicit `orphan` immediately.
|
|
532
532
|
Every watched run whose PID is alive (or whose lane supervisor is, between
|
|
533
|
-
same-session continuations) is reported as `process_alive`.
|
|
534
|
-
|
|
535
|
-
|
|
533
|
+
same-session continuations) is reported as `process_alive`. That is not a
|
|
534
|
+
heartbeat: a lane run with no heartbeat still goes Quiet at 15 minutes (MW1-36),
|
|
535
|
+
and Dev holds it at Quiet, short of Orphan, while its Mac still sees the process.
|
|
536
|
+
Only a coordinator run takes `process_alive` as its heartbeat.
|
|
537
|
+
Each sweep also reads Dev's live runs for the machine. A dead process is reported
|
|
538
|
+
again while Dev still holds its run as running, and a live lane or coordinator
|
|
539
|
+
run with no local record is listed as `unwatchedRuns`.
|
|
540
|
+
`coordinator start` installs this job under the coordinator's own config: the job
|
|
541
|
+
runs as one agent, and a sweep by any other agent is refused.
|
|
536
542
|
A sweep leaves a dead lane runtime alone while its lane supervisor still lives
|
|
537
543
|
(the supervisor reports the exit itself) and skips it once the supervisor has
|
|
538
544
|
reported.
|
package/dist/cli.js
CHANGED
|
@@ -66,7 +66,7 @@ import { docsCommand, rulebookCommand, rulesCommand } from "./upload.js";
|
|
|
66
66
|
import { changeSetCommand, guidelineCommand } from "./guidelines.js";
|
|
67
67
|
import { designCheck, designCheckChangeSet, designCheckText, designRoles, designRolesText, surfacesBehind, surfacesBehindText } from "./design.js";
|
|
68
68
|
import { assertKnownFlags } from "./flags.js";
|
|
69
|
-
import { watchdogCommand } from "./watchdog.js";
|
|
69
|
+
import { installWatchdog, watchdogCommand } from "./watchdog.js";
|
|
70
70
|
import { machineCapacityCommand } from "./accounts.js";
|
|
71
71
|
import {
|
|
72
72
|
ALIASES,
|
|
@@ -799,7 +799,7 @@ export async function main(argv = process.argv.slice(2)) {
|
|
|
799
799
|
}
|
|
800
800
|
return;
|
|
801
801
|
}
|
|
802
|
-
if (command === "coordinator") return emitCommand(await coordinatorCommand(action, f));
|
|
802
|
+
if (command === "coordinator") return emitCommand(await coordinatorCommand(action, f, { installWatchdog }));
|
|
803
803
|
if (command === "lane" && action === "launch") return emitCommand(await launchLaneCommand(rest[0], f));
|
|
804
804
|
if (command === "lane" && action === "amend") return emitCommand(await amendLaneCommand(rest[0], f));
|
|
805
805
|
if (command === "lane" && action === "gather") {
|
package/dist/core.js
CHANGED
|
@@ -4,7 +4,7 @@ import { chmod, mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
|
4
4
|
import { homedir, platform } from "node:os";
|
|
5
5
|
import { dirname, join } from "node:path";
|
|
6
6
|
|
|
7
|
-
export const VERSION = "0.6.
|
|
7
|
+
export const VERSION = "0.6.71";
|
|
8
8
|
export const configPath = () =>
|
|
9
9
|
process.env.NODII_DEV_CONFIG_PATH ??
|
|
10
10
|
join(homedir(), ".config/nodii-dev/config.json");
|
package/dist/lanes.js
CHANGED
|
@@ -55,7 +55,9 @@ export async function inferGitContext() {
|
|
|
55
55
|
return { repo, branch: need(branch, "Detached HEAD: pass --branch."), worktree };
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
|
|
58
|
+
// `building` is the lane's phase, not a process: say when nothing healthy is running (MW1-36).
|
|
59
|
+
const laneLiveness = (x) => x.liveness && x.liveness !== "active" ? `\t${x.liveness.toUpperCase()}` : "";
|
|
60
|
+
const laneLine = (x) => `${x.key}\t${x.status}\t${x.kind}/${x.side}\t${x.title}${x.stuck ? "\tSTUCK" : ""}${laneLiveness(x)}`;
|
|
59
61
|
// GATHER-NA: a step the coordinator ruled not applicable is never shown as done.
|
|
60
62
|
const stepState = (s) => s.state === "not_applicable" ? `not applicable: ${s.notApplicableReason ?? "(no reason recorded)"}` : s.state;
|
|
61
63
|
const detailText = (x) => [laneLine(x), ...(x.steps ?? []).map((s) => ` ${s.side}\t${stepState(s)}\t${s.stepKey}\t${s.label}`)].join("\n");
|
package/dist/starting.js
CHANGED
|
@@ -198,7 +198,7 @@ const coordinatorState = (machine, run, agentId) => ({
|
|
|
198
198
|
* Adopt this session's own running coordinator run again (CLI-16): rewrite the
|
|
199
199
|
* state file and restart the heartbeater. Dev's run is unchanged.
|
|
200
200
|
*/
|
|
201
|
-
async function adoptCoordinatorRun(machine, run, c, { save, heartbeater, existingHeartbeater }) {
|
|
201
|
+
async function adoptCoordinatorRun(machine, run, c, { save, heartbeater, existingHeartbeater, installWatchdog }) {
|
|
202
202
|
await save(stateFile(machine), coordinatorState(machine, run, c.agentId));
|
|
203
203
|
const expected = run.expectedHeartbeatSeconds ?? 60;
|
|
204
204
|
// A heartbeater still beating this run keeps it; a second is never started.
|
|
@@ -208,13 +208,15 @@ async function adoptCoordinatorRun(machine, run, c, { save, heartbeater, existin
|
|
|
208
208
|
try { heartbeaterPid = await heartbeater({ runId: run.id, machine, pid: run.watched.pid, processStartedAt: run.watched.processStartedAt ?? null, intervalSeconds: Math.max(5, Math.floor(expected / 2)) }); }
|
|
209
209
|
catch (error) { heartbeaterError = error?.message ?? String(error); }
|
|
210
210
|
}
|
|
211
|
+
const watchdogTakeover = await takeOverWatchdog(installWatchdog);
|
|
211
212
|
return {
|
|
212
|
-
payload: { data: { adopted: true, run, machine: { id: run.metadata.machineId, name: machine } }, heartbeaterPid },
|
|
213
|
+
payload: { data: { adopted: true, run, machine: { id: run.metadata.machineId, name: machine } }, heartbeaterPid, ...watchdogTakeover },
|
|
213
214
|
human: [
|
|
214
215
|
`Coordinator ${run.id} is this session's run on ${machine}; adopted it again (last heartbeat ${run.lastHeartbeatAt ?? "never"}).`,
|
|
215
216
|
heartbeaterPid
|
|
216
217
|
? `heartbeater ${heartbeaterPid} keeps the run alive while session ${run.watched.pid} lives`
|
|
217
218
|
: `heartbeater not started${heartbeaterError ? ` (${heartbeaterError})` : ""}: the run goes quiet without heartbeats`,
|
|
219
|
+
...watchdogLines(watchdogTakeover),
|
|
218
220
|
].join("\n"),
|
|
219
221
|
};
|
|
220
222
|
}
|
|
@@ -304,6 +306,21 @@ export async function coordinatorHeartbeatLoop({ machine, runId, pid, processSta
|
|
|
304
306
|
}
|
|
305
307
|
|
|
306
308
|
/** Register each --account, then report every account's usage (MW1-38.1). */
|
|
309
|
+
/**
|
|
310
|
+
* The launchd job runs as one agent, so a new coordinator has to take it over
|
|
311
|
+
* or every sweep is refused (WATCHDOG_COORDINATOR_REQUIRED; NODII-DEV-CLI-42).
|
|
312
|
+
*/
|
|
313
|
+
async function takeOverWatchdog(installWatchdog) {
|
|
314
|
+
if (!installWatchdog) return { watchdog: null, watchdogError: null };
|
|
315
|
+
try { return { watchdog: await installWatchdog(), watchdogError: null }; }
|
|
316
|
+
catch (error) { return { watchdog: null, watchdogError: `${error?.code ?? "WATCHDOG_INSTALL_FAILED"}: ${error?.message ?? error}` }; }
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
const watchdogLines = ({ watchdog, watchdogError }) => [
|
|
320
|
+
...(watchdog ? [`watchdog ${watchdog.label} runs under this coordinator${watchdog.changed ? " (updated)" : ""}`] : []),
|
|
321
|
+
...(watchdogError ? [`WATCHDOG NOT RUNNING under this coordinator (${watchdogError}); no sweep reports dead processes until nodii-dev watchdog install succeeds`] : []),
|
|
322
|
+
];
|
|
323
|
+
|
|
307
324
|
async function coordinatorCapacity(machineId, flags, { request, readers }) {
|
|
308
325
|
// The run is already started: a refused registration is reported, not thrown.
|
|
309
326
|
const refused = [];
|
|
@@ -325,6 +342,8 @@ export async function coordinatorCommand(action, flags, {
|
|
|
325
342
|
isAlive = async (pid, startedAt) => (await import("./watchdog.js")).isProcessAlive(pid, startedAt),
|
|
326
343
|
sessionPid = coordinatorRuntimePid,
|
|
327
344
|
existingHeartbeater = runningHeartbeater,
|
|
345
|
+
// Only the CLI passes launchd's installer, so no caller touches launchd by default.
|
|
346
|
+
installWatchdog = null,
|
|
328
347
|
} = {}) {
|
|
329
348
|
if (action === "heartbeat") {
|
|
330
349
|
const result = await heartbeatLoop({
|
|
@@ -361,7 +380,7 @@ export async function coordinatorCommand(action, flags, {
|
|
|
361
380
|
// CLI-16: the run's session is this session (its heartbeater or state file
|
|
362
381
|
// was lost): adopt the run again and restart its heartbeater.
|
|
363
382
|
if (sessionAlive && pid === (await sessionPid().catch(() => null)))
|
|
364
|
-
return adoptCoordinatorRun(machine, live, c, { save, heartbeater, existingHeartbeater });
|
|
383
|
+
return adoptCoordinatorRun(machine, live, c, { save, heartbeater, existingHeartbeater, installWatchdog });
|
|
365
384
|
const interval = live.expectedHeartbeatSeconds ?? 60;
|
|
366
385
|
if (!coordinatorRunStale(live, now()))
|
|
367
386
|
throw new CliError("COORDINATOR_ALREADY_RUNNING", `Coordinator run ${live.id} for ${machine} is live (last heartbeat ${live.lastHeartbeatAt ?? "never"}); it is taken over only after 3x its ${interval}s heartbeat interval with its session gone. Run coordinator start from that run's own session to adopt it again.`, 1);
|
|
@@ -418,8 +437,9 @@ export async function coordinatorCommand(action, flags, {
|
|
|
418
437
|
catch (error) { heartbeaterError = error?.message ?? String(error); }
|
|
419
438
|
}
|
|
420
439
|
const accounts = await coordinatorCapacity(payload.data.machine.id, flags, { request, readers });
|
|
440
|
+
const watchdogTakeover = await takeOverWatchdog(installWatchdog);
|
|
421
441
|
return {
|
|
422
|
-
payload: { ...payload, accounts, heartbeaterPid },
|
|
442
|
+
payload: { ...payload, accounts, heartbeaterPid, ...watchdogTakeover },
|
|
423
443
|
human: (p) => [
|
|
424
444
|
`Coordinator ${p.data.run.id} is watching ${p.data.machine.name}.`,
|
|
425
445
|
`running lanes: ${p.data.runningLanes.length}`,
|
|
@@ -432,6 +452,7 @@ export async function coordinatorCommand(action, flags, {
|
|
|
432
452
|
heartbeaterPid
|
|
433
453
|
? `heartbeater ${heartbeaterPid} keeps the run alive while session ${watched.pid} lives`
|
|
434
454
|
: `heartbeater not started${heartbeaterError ? ` (${heartbeaterError})` : ""}: the run goes quiet without heartbeats`,
|
|
455
|
+
...watchdogLines(watchdogTakeover),
|
|
435
456
|
...(accounts.length
|
|
436
457
|
? accounts.map((result) => `account ${usageLine(result)}`)
|
|
437
458
|
: [`accounts: none registered; add one with --account claude:/path/to/profile (lane launch needs its usage)`]),
|
package/dist/watchdog.js
CHANGED
|
@@ -221,6 +221,21 @@ export async function sweepWatchdog({
|
|
|
221
221
|
const byId = new Map(loaded.records.map((record) => [record.runId, record]));
|
|
222
222
|
const effectiveMachineId = machineId ?? (await coordinatorMachine({ request })).machineId;
|
|
223
223
|
const orphanedRuns = [];
|
|
224
|
+
// Dev's live runs are the authority, not the local flags (NODII-DEV-CLI-42):
|
|
225
|
+
// a run Dev still holds as running gets its dead process reported again, and
|
|
226
|
+
// a run with no local record is one this sweep cannot see. Without Dev's list
|
|
227
|
+
// the local records still get checked.
|
|
228
|
+
let devLiveRuns = null;
|
|
229
|
+
try {
|
|
230
|
+
const state = await request("GET", `/api/v1/run-watchdog?machine=${encode(effectiveMachineId)}`);
|
|
231
|
+
devLiveRuns = Array.isArray(state?.data?.liveRuns) ? state.data.liveRuns : null;
|
|
232
|
+
} catch (error) {
|
|
233
|
+
facts.errors.push({ kind: "live_runs", code: error?.code ?? "RUN_WATCHDOG_STATE_FAILED" });
|
|
234
|
+
}
|
|
235
|
+
const devLiveIds = new Set((devLiveRuns ?? []).map((run) => run.id));
|
|
236
|
+
const unwatchedRuns = (devLiveRuns ?? [])
|
|
237
|
+
.filter((run) => ["lane", "coordinator"].includes(run.kind) && !byId.has(run.id))
|
|
238
|
+
.map((run) => ({ runId: run.id, kind: run.kind, lastHeartbeatAt: run.lastHeartbeatAt }));
|
|
224
239
|
// Record the non-terminal observations first: process_dead transitions the
|
|
225
240
|
// run to Orphan immediately, and must not prevent its stale socket or local
|
|
226
241
|
// commits from reaching Dev in the same sweep.
|
|
@@ -252,8 +267,8 @@ export async function sweepWatchdog({
|
|
|
252
267
|
facts.errors.push({ kind: "run", runId: record.runId, observation: "worktree_unpushed", code: error?.code ?? "RUN_WATCHDOG_REPORT_FAILED" });
|
|
253
268
|
}
|
|
254
269
|
}
|
|
255
|
-
//
|
|
256
|
-
//
|
|
270
|
+
// A PID this Mac sees alive holds a lane run at Quiet, short of Orphan, and is
|
|
271
|
+
// a coordinator run's heartbeat. It is not a lane run's heartbeat (MW1-36).
|
|
257
272
|
for (const live of facts.liveRuns ?? []) {
|
|
258
273
|
const record = byId.get(live.runId);
|
|
259
274
|
if (!record || record.orphanReportedAt || record.terminalSeenAt) continue;
|
|
@@ -268,7 +283,8 @@ export async function sweepWatchdog({
|
|
|
268
283
|
}
|
|
269
284
|
for (const dead of facts.deadRuns) {
|
|
270
285
|
const record = byId.get(dead.runId);
|
|
271
|
-
if (!record
|
|
286
|
+
if (!record) continue;
|
|
287
|
+
if ((record.orphanReportedAt || record.terminalSeenAt) && !devLiveIds.has(record.runId)) continue;
|
|
272
288
|
try {
|
|
273
289
|
const observedAt = now().toISOString();
|
|
274
290
|
const response = await request("POST", `/api/v1/runs/${encode(record.runId)}/watchdog`, observationBody({
|
|
@@ -278,7 +294,7 @@ export async function sweepWatchdog({
|
|
|
278
294
|
if (response?.data?.run?.livenessState === "orphan") {
|
|
279
295
|
record.orphanReportedAt = observedAt;
|
|
280
296
|
orphanedRuns.push({ runId: record.runId, pid: record.pid, reportedAt: record.orphanReportedAt });
|
|
281
|
-
} else if (["done", "handed_off", "failed"].includes(response?.data?.run?.status)) {
|
|
297
|
+
} else if (["done", "handed_off", "failed", "blocked"].includes(response?.data?.run?.status)) {
|
|
282
298
|
record.terminalSeenAt = observedAt;
|
|
283
299
|
} else {
|
|
284
300
|
throw new CliError("RUN_WATCHDOG_RESPONSE_INVALID", "Dev recorded process_dead without returning the run as orphan or terminal.", 1);
|
|
@@ -299,7 +315,7 @@ export async function sweepWatchdog({
|
|
|
299
315
|
} catch (error) {
|
|
300
316
|
facts.errors.push({ kind: "usage", code: error?.code ?? "ACCOUNT_USAGE_REPORT_FAILED" });
|
|
301
317
|
}
|
|
302
|
-
const report = { ...facts, orphanedRuns, accounts };
|
|
318
|
+
const report = { ...facts, orphanedRuns, unwatchedRuns, accounts };
|
|
303
319
|
return report;
|
|
304
320
|
}
|
|
305
321
|
|
|
@@ -360,7 +376,7 @@ export async function watchdogCommand(action, flags, dependencies = {}) {
|
|
|
360
376
|
}
|
|
361
377
|
if (action === "sweep") {
|
|
362
378
|
const data = await sweepWatchdog(dependencies);
|
|
363
|
-
return { payload: { data }, human: `Watchdog sweep: ${data.orphanedRuns.length} orphaned run(s), ${data.staleSockets.length} stale socket(s), ${data.unpushedWorktrees.length} unpushed worktree(s), ${data.errors.length} error(s).` };
|
|
379
|
+
return { payload: { data }, human: `Watchdog sweep: ${data.orphanedRuns.length} orphaned run(s), ${data.unwatchedRuns.length} unwatched run(s), ${data.staleSockets.length} stale socket(s), ${data.unpushedWorktrees.length} unpushed worktree(s), ${data.errors.length} error(s).` };
|
|
364
380
|
}
|
|
365
381
|
throw new CliError("USAGE", "watchdog install [--interval SECONDS] | watchdog sweep", 2);
|
|
366
382
|
}
|