@indigoai-us/hq-cli 5.345.223 → 5.345.225
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/CHANGELOG.md +66 -0
- package/assets/bot-workers/setup/context/quick-reference.md +2 -2
- package/assets/mesh-daemon/README.md +11 -12
- package/dist/command-catalog.generated.d.ts +78 -4
- package/dist/command-catalog.generated.js +94 -4
- package/dist/commands/cloud-provision.d.ts +4 -1
- package/dist/commands/cloud-provision.js +7 -3
- package/dist/commands/cloud-retire.js +1 -1
- package/dist/commands/core-delegate-w1b.js +3 -1
- package/dist/commands/core-delegate.d.ts +5 -0
- package/dist/commands/core-dm-bind-native.d.ts +5 -1
- package/dist/commands/core-dm-bind-native.js +4 -0
- package/dist/commands/core-job-notify-native.d.ts +5 -1
- package/dist/commands/core-job-notify-native.js +8 -2
- package/dist/commands/core-jobs-native.d.ts +27 -1
- package/dist/commands/core-jobs-native.js +49 -28
- package/dist/commands/core-pipeline-conductor-native.js +7 -7
- package/dist/commands/core-pipeline-driver-native.js +5 -5
- package/dist/commands/core-refresh-vault-access-native.d.ts +5 -0
- package/dist/commands/core-refresh-vault-access-native.js +3 -1
- package/dist/commands/core-work-mesh-bind-trusted-native.js +1 -1
- package/dist/commands/daemon.d.ts +2 -0
- package/dist/commands/daemon.js +67 -1
- package/dist/commands/lanes-hold.d.ts +2 -27
- package/dist/commands/lanes-hold.js +3 -75
- package/dist/commands/lanes-loop.js +1 -1
- package/dist/commands/lanes-session-start.js +2 -2
- package/dist/commands/mesh.d.ts +12 -0
- package/dist/commands/mesh.js +13 -4
- package/dist/commands/monitor.js +1 -1
- package/dist/commands/packs.js +1 -1
- package/dist/commands/whoami.d.ts +10 -17
- package/dist/commands/whoami.js +7 -79
- package/dist/data/command-states.json +13 -0
- package/dist/index.js +1 -1
- package/dist/lib/daemon/catalog.d.ts +8 -5
- package/dist/lib/daemon/catalog.js +13 -7
- package/dist/lib/daemon/config.d.ts +5 -0
- package/dist/lib/daemon/config.js +6 -0
- package/dist/lib/daemon/lanes-monitor-state.d.ts +55 -0
- package/dist/lib/daemon/lanes-monitor-state.js +129 -0
- package/dist/lib/daemon/lanes-reconcile-loader.d.ts +7 -0
- package/dist/lib/daemon/lanes-reconcile-loader.js +13 -0
- package/dist/lib/daemon/merge-sections.d.ts +165 -0
- package/dist/lib/daemon/merge-sections.js +556 -0
- package/dist/lib/daemon/ops/policy.d.ts +1 -1
- package/dist/lib/daemon/ops/policy.js +1 -1
- package/dist/lib/daemon/protocol.d.ts +1 -1
- package/dist/lib/daemon/protocol.js +0 -6
- package/dist/lib/daemon/run.js +73 -1
- package/dist/lib/daemon/selfcheck.js +2 -2
- package/dist/lib/daemon/server.d.ts +2 -4
- package/dist/lib/daemon/server.js +5 -48
- package/dist/lib/daemon/state-file.d.ts +74 -4
- package/dist/lib/daemon/state-file.js +159 -19
- package/dist/lib/daemon/supervisor.d.ts +1 -1
- package/dist/lib/daemon/updater.d.ts +2 -6
- package/dist/lib/daemon/updater.js +4 -11
- package/dist/lib/daemon/whoami-cache.d.ts +96 -0
- package/dist/lib/daemon/whoami-cache.js +244 -0
- package/dist/lib/hook-engine/coverage.d.ts +2 -0
- package/dist/lib/hook-engine/coverage.js +71 -0
- package/dist/lib/hook-engine/native-precompact-compatibility.json +449 -0
- package/dist/lib/hook-engine/reconcile.js +14 -8
- package/dist/lib/install/hook-target.d.ts +13 -3
- package/dist/lib/install/hook-target.js +14 -11
- package/dist/lib/lanes/envelope-repair-dispatch.js +1 -1
- package/dist/lib/lanes/monitor.d.ts +2 -0
- package/dist/lib/lanes/monitor.js +2 -1
- package/dist/lib/lanes/registry-flag.d.ts +6 -0
- package/dist/lib/lanes/registry-flag.js +3 -2
- package/dist/lib/lanes/repo-merge-hold.d.ts +39 -0
- package/dist/lib/lanes/repo-merge-hold.js +90 -0
- package/dist/lib/lanes/watcher-main.js +3 -3
- package/dist/lib/mesh/live/daemon/doctor.js +1 -1
- package/dist/lib/mesh/live/daemon/install.js +2 -2
- package/dist/lib/windows/install-followup.js +1 -1
- package/dist/utils/client-health-contract.d.ts +1 -0
- package/dist/utils/client-health-contract.js +5 -0
- package/dist/utils/client-health.d.ts +2 -0
- package/dist/utils/client-health.js +40 -0
- package/dist/utils/cognito-session.d.ts +2 -14
- package/dist/utils/cognito-session.js +2 -40
- package/dist/utils/daemon-cli-version.d.ts +13 -0
- package/dist/utils/daemon-cli-version.js +47 -0
- package/dist/utils/duplicate-command-usage.js +1 -1
- package/dist/utils/machine-token-cache.d.ts +21 -0
- package/dist/utils/machine-token-cache.js +49 -0
- package/dist/utils/resident-package-preload.js +4 -0
- package/dist/utils/whoami-identity.d.ts +54 -0
- package/dist/utils/whoami-identity.js +108 -0
- package/package.json +7 -7
- package/dist/lib/daemon/ops/memory.d.ts +0 -18
- package/dist/lib/daemon/ops/memory.js +0 -65
- package/dist/lib/daemon/ops/mesh.d.ts +0 -38
- package/dist/lib/daemon/ops/mesh.js +0 -70
package/dist/lib/daemon/run.js
CHANGED
|
@@ -31,7 +31,9 @@ import { effectiveEngineSettings, readSyncCoreVaultSettings } from "../sync-core
|
|
|
31
31
|
import { assertPersonalServiceSessionCapability, readRemoteControlPoolsConfig, remoteControlPoolSecretsEnv, } from "./remote-control-pools.js";
|
|
32
32
|
import { loadLanesConfig } from "../lanes/config.js";
|
|
33
33
|
import { daemonLanesReconcileHandler } from "../lanes/daemon-reconcile.js";
|
|
34
|
-
import {
|
|
34
|
+
import { computeLanesMonitorSection } from "./lanes-monitor-state.js";
|
|
35
|
+
import { ensureDaemonLanesReconcileHandler, runDaemonLanesReconcileInProcess } from "./lanes-reconcile-loader.js";
|
|
36
|
+
import { startWhoamiCacheWriter } from "./whoami-cache.js";
|
|
35
37
|
import { SUPERVISOR_HANDOFF_FLAG, createDaemonFlagSnapshotSource, readDaemonFlag } from "./flag.js";
|
|
36
38
|
import { createDaemonKillSwitchMonitors } from "./timed-flag-monitors.js";
|
|
37
39
|
import { MACHINE_CHECKS_RESULT_FILE, readMachineCheckResults, startMachineCheckSchedule } from "./machine-checks.js";
|
|
@@ -53,6 +55,7 @@ import { classifyWindowsTask, currentWindowsIdentity, daemonRootRefusal } from "
|
|
|
53
55
|
import { detectMachineType } from "./machine-type.js";
|
|
54
56
|
import { appendPrivate, daemonPaths, ensurePrivateDir, openPrivateAppend } from "./paths.js";
|
|
55
57
|
import { SELF_CHECK_RESULT_FILE, readSelfCheckResult } from "./selfcheck.js";
|
|
58
|
+
import { createRegistryMergeFlagReader, startMergeSectionRefresh } from "./merge-sections.js";
|
|
56
59
|
import { createDaemonStateWriter, daemonStateFilePath, defaultDaemonStateFilePath, readVaultAccessManifest, selfCheckMachineChecks, } from "./state-file.js";
|
|
57
60
|
import { hqdSocketPath } from "./protocol.js";
|
|
58
61
|
import { startHqdServer, syncHqdEnabledMarker } from "./server.js";
|
|
@@ -988,6 +991,8 @@ export async function runDaemon(opts) {
|
|
|
988
991
|
let supervisor = null;
|
|
989
992
|
// One registry request per 30-second tick decides every timed daemon flag.
|
|
990
993
|
// The same request also refreshes the state file hooks read (state-file.ts).
|
|
994
|
+
// Each session-and-error pair is logged once, not on every 30-second write.
|
|
995
|
+
const lanesMonitorSessionErrors = new Set();
|
|
991
996
|
const stateWriter = createDaemonStateWriter({
|
|
992
997
|
file: daemonStateFilePath(home, env),
|
|
993
998
|
defaultFile: defaultDaemonStateFilePath(home, env),
|
|
@@ -1000,7 +1005,57 @@ export async function runDaemon(opts) {
|
|
|
1000
1005
|
...selfCheckMachineChecks(readSelfCheckResult(path.join(paths.root, SELF_CHECK_RESULT_FILE))),
|
|
1001
1006
|
...readMachineCheckResults(path.join(paths.root, MACHINE_CHECKS_RESULT_FILE)),
|
|
1002
1007
|
],
|
|
1008
|
+
// What `hq lanes monitor-check` would answer, so the UserPromptSubmit hook
|
|
1009
|
+
// starts no program. No configured, existing HQ root: no section.
|
|
1010
|
+
readLanesMonitor: () => {
|
|
1011
|
+
const configured = readDaemonConfig(paths.configPath).hqRoot ?? (env.HQ_ROOT?.trim() || undefined);
|
|
1012
|
+
if (!configured || !fs.existsSync(configured))
|
|
1013
|
+
return null;
|
|
1014
|
+
return computeLanesMonitorSection({
|
|
1015
|
+
hqRoot: configured,
|
|
1016
|
+
now: new Date(),
|
|
1017
|
+
homedir: () => home,
|
|
1018
|
+
env,
|
|
1019
|
+
onSessionError: (sessionId, error) => {
|
|
1020
|
+
const key = `${sessionId}:${error instanceof Error ? error.name : "UnknownError"}`;
|
|
1021
|
+
if (lanesMonitorSessionErrors.has(key))
|
|
1022
|
+
return;
|
|
1023
|
+
if (lanesMonitorSessionErrors.size >= 256)
|
|
1024
|
+
lanesMonitorSessionErrors.clear();
|
|
1025
|
+
lanesMonitorSessionErrors.add(key);
|
|
1026
|
+
log("warn", `state file: lanes_monitor left out a session whose Monitor evidence could not be read (${key})`);
|
|
1027
|
+
},
|
|
1028
|
+
});
|
|
1029
|
+
},
|
|
1030
|
+
readMergeSections: () => mergeSections.latest(),
|
|
1031
|
+
});
|
|
1032
|
+
// The merge sections the native merge check reads are refused past 60 s, so
|
|
1033
|
+
// they are rebuilt every 15 s and the state file is rewritten each time,
|
|
1034
|
+
// between the 30-second registry requests (merge-sections.ts).
|
|
1035
|
+
const mergeSections = startMergeSectionRefresh({
|
|
1036
|
+
hqRoot: () => readDaemonConfig(paths.configPath).hqRoot ?? (env.HQ_ROOT?.trim() || undefined),
|
|
1037
|
+
readFlag: createRegistryMergeFlagReader({ env }),
|
|
1038
|
+
onRefresh: () => stateWriter.refresh(),
|
|
1003
1039
|
});
|
|
1040
|
+
// The cached `hq whoami` answer CLI commands read instead of starting
|
|
1041
|
+
// `hq whoami` (whoami-cache.ts). The token caches it describes live under
|
|
1042
|
+
// this user's own home, so a daemon run for another home writes none.
|
|
1043
|
+
const whoamiCache = path.resolve(home) === path.resolve(os.homedir())
|
|
1044
|
+
? startWhoamiCacheWriter({
|
|
1045
|
+
home,
|
|
1046
|
+
env,
|
|
1047
|
+
log,
|
|
1048
|
+
build: async (readPersonUid) => {
|
|
1049
|
+
const [{ buildWhoamiIdentity }, { resolveCognitoTokenSource }, { loadCachedTokens }] = await Promise.all([
|
|
1050
|
+
import("../../utils/whoami-identity.js"),
|
|
1051
|
+
import("../../utils/cognito-session.js"),
|
|
1052
|
+
import("@indigoai-us/hq-cloud"),
|
|
1053
|
+
]);
|
|
1054
|
+
return buildWhoamiIdentity(resolveCognitoTokenSource(env) === "machine", loadCachedTokens(), readPersonUid);
|
|
1055
|
+
},
|
|
1056
|
+
lookupPersonUid: async (token) => (await import("../../commands/whoami.js")).readPersonUid(token),
|
|
1057
|
+
})
|
|
1058
|
+
: null;
|
|
1004
1059
|
// The hqd listener checks again when a shared read's HQ Anywhere answer
|
|
1005
1060
|
// changes, or the running server's runtime gate changes; it has no timer of
|
|
1006
1061
|
// its own beyond a rare fallback (anywhere-listener.ts).
|
|
@@ -1102,7 +1157,9 @@ export async function runDaemon(opts) {
|
|
|
1102
1157
|
killSwitches.close();
|
|
1103
1158
|
machineChecks.close();
|
|
1104
1159
|
flagSnapshots.close();
|
|
1160
|
+
mergeSections.close();
|
|
1105
1161
|
stateWriter.close();
|
|
1162
|
+
whoamiCache?.close();
|
|
1106
1163
|
return stopJobsClosed;
|
|
1107
1164
|
};
|
|
1108
1165
|
const plan = () => {
|
|
@@ -1327,6 +1384,7 @@ export async function runDaemon(opts) {
|
|
|
1327
1384
|
signedIn: isSignedIn,
|
|
1328
1385
|
kitConfigured: fs.existsSync(agentKitPaths(home, env).kitConfigPath),
|
|
1329
1386
|
syncPaused: config.syncPaused === true,
|
|
1387
|
+
syncCorePause: config.syncCorePause,
|
|
1330
1388
|
vaultSync: (() => {
|
|
1331
1389
|
const switches = readVaultSyncSwitches(home);
|
|
1332
1390
|
// Log once per change, not every reconcile.
|
|
@@ -1515,6 +1573,20 @@ export async function runDaemon(opts) {
|
|
|
1515
1573
|
plan,
|
|
1516
1574
|
spawn: spawnUnit,
|
|
1517
1575
|
runInternal: async (task) => {
|
|
1576
|
+
if (task === "lanes-reconcile") {
|
|
1577
|
+
// The timed unit only exists while the lane-store watcher is not
|
|
1578
|
+
// running; it reconciles here instead of starting `hq` (US-036).
|
|
1579
|
+
const currentRoot = () => {
|
|
1580
|
+
const configured = readDaemonConfig(paths.configPath).hqRoot ?? (env.HQ_ROOT?.trim() || undefined);
|
|
1581
|
+
return configured && fs.existsSync(configured) ? configured : undefined;
|
|
1582
|
+
};
|
|
1583
|
+
const root = currentRoot();
|
|
1584
|
+
if (!root)
|
|
1585
|
+
throw new Error("lanes reconcile has no HQ folder");
|
|
1586
|
+
// The reconciler is registered once and keeps this resolver, so it follows a later HQ folder change.
|
|
1587
|
+
await runDaemonLanesReconcileInProcess({ hqRoot: () => currentRoot() ?? root, env });
|
|
1588
|
+
return true;
|
|
1589
|
+
}
|
|
1518
1590
|
if (task !== "rotate-logs")
|
|
1519
1591
|
throw new Error(`unknown internal task ${task}`);
|
|
1520
1592
|
const n = rotateLogs(paths.logsDir);
|
|
@@ -232,10 +232,10 @@ vaultName = () => undefined, wake = null) {
|
|
|
232
232
|
? `HQ sync on ${machine}: the sync engine for ${names} has not synced for over ${ATTENTION_AFTER_MS / 60_000} minutes. ` +
|
|
233
233
|
"Run `hq daemon status` on that machine."
|
|
234
234
|
: `HQ sync on ${machine}: the sync engine is running without change notifications, so it only polls and other machines' changes can arrive up to 30 minutes late. ` +
|
|
235
|
-
"Run `hq
|
|
235
|
+
"Run `hq daemon status` and `hq daemon doctor` on that machine.";
|
|
236
236
|
const lines = problems.map((p) => `- ${named(p)}: ${p.what}. Retry with: hq daemon restart ${p.unitId}`);
|
|
237
237
|
if (wake)
|
|
238
|
-
lines.push(`- change notifications: ${wake.what}. Check with: hq
|
|
238
|
+
lines.push(`- change notifications: ${wake.what}. Check with: hq daemon status and hq daemon doctor`);
|
|
239
239
|
lines.push("", "Logs: hq daemon logs <unit>. This check runs in hq daemon and sends at most one DM a day from this machine.");
|
|
240
240
|
return { body, details: lines.join("\n") };
|
|
241
241
|
}
|
|
@@ -32,13 +32,11 @@ export interface HqdServerOptions {
|
|
|
32
32
|
hqRoot?: string;
|
|
33
33
|
version?: string;
|
|
34
34
|
now?: () => Date;
|
|
35
|
-
/** Called
|
|
35
|
+
/** Called when the Windows named-pipe helper fails and hqd must stop. */
|
|
36
36
|
onShutdown?: () => void;
|
|
37
37
|
log?: (level: "info" | "warn" | "error", message: string) => void;
|
|
38
|
-
/** Environment for policy scripts
|
|
38
|
+
/** Environment for policy scripts (tests sandbox HOME here). */
|
|
39
39
|
env?: NodeJS.ProcessEnv;
|
|
40
|
-
/** Work-mesh root override for mesh.presence (tests). */
|
|
41
|
-
workMeshRoot?: string;
|
|
42
40
|
/** Test seam for the hq-anywhere-runtime fail-safe gate. */
|
|
43
41
|
mcpEnabled?: () => boolean | Promise<boolean>;
|
|
44
42
|
/** Test seam for the live hq-flags read used by the daemon's bounded runtime monitor. */
|
|
@@ -18,8 +18,6 @@ import { createLineSplitter, encodeMessage, HQD_DEFAULT_REQUEST_TIMEOUT_MS, HQD_
|
|
|
18
18
|
import { SessionRegistry } from "./session-registry.js";
|
|
19
19
|
import { sessionMetaCompanies } from "../core-utils/session-company.js";
|
|
20
20
|
import { journalAppend, JournalOpError } from "./ops/journal.js";
|
|
21
|
-
import { memoryGet, memoryPut, MemoryOpError } from "./ops/memory.js";
|
|
22
|
-
import { meshPresence, MeshOpError } from "./ops/mesh.js";
|
|
23
21
|
import { PolicyIndex, PolicyOpError, policyCheck } from "./ops/policy.js";
|
|
24
22
|
import { defaultMcpToken, HqMcpBridge, jsonResult, McpOpError, runWorker } from "./ops/mcp.js";
|
|
25
23
|
import { authenticateMachineCredentials, machineTokenExpiresAt, MachineLoginError, parseStdinMachineCredentials } from "./machine-login.js";
|
|
@@ -438,8 +436,8 @@ export async function startHqdServer(opts) {
|
|
|
438
436
|
socket: healthSocket(socketPath, isPipe),
|
|
439
437
|
};
|
|
440
438
|
};
|
|
441
|
-
const alwaysAvailableOps = new Set(["ping", "health", "auth.status"
|
|
442
|
-
const allowedWhileDisabled = new Set(["session.
|
|
439
|
+
const alwaysAvailableOps = new Set(["ping", "health", "auth.status"]);
|
|
440
|
+
const allowedWhileDisabled = new Set(["session.close"]);
|
|
443
441
|
/** Gate each external hqd request once, leaving diagnostics and cleanup available while disabled. */
|
|
444
442
|
const handle = (req) => {
|
|
445
443
|
const requestStartedAt = Date.now();
|
|
@@ -527,17 +525,6 @@ export async function startHqdServer(opts) {
|
|
|
527
525
|
assertCompanyMatchesPersisted(company ?? undefined, explicit ? "explicit" : "cwd-bound", persistedCompanies(sessionId));
|
|
528
526
|
return sessions.open({ runtime, sessionId, cwd: canonicalDir(cwd), company });
|
|
529
527
|
}
|
|
530
|
-
case "session.get": {
|
|
531
|
-
const runtime = stringArg(args, "runtime", false);
|
|
532
|
-
const sessionId = stringArg(args, "sessionId", false);
|
|
533
|
-
if (!sessionId) {
|
|
534
|
-
const all = sessions.list();
|
|
535
|
-
return { sessions: runtime ? all.filter((s) => s.runtime === runtime) : all };
|
|
536
|
-
}
|
|
537
|
-
if (!runtime)
|
|
538
|
-
throw new OpError("bad_args", "runtime is required with sessionId");
|
|
539
|
-
return { session: sessions.get(runtime, sessionId) };
|
|
540
|
-
}
|
|
541
528
|
case "session.close": {
|
|
542
529
|
const runtime = stringArg(args, "runtime");
|
|
543
530
|
const sessionId = stringArg(args, "sessionId");
|
|
@@ -562,37 +549,12 @@ export async function startHqdServer(opts) {
|
|
|
562
549
|
cwd: stringArg(args, "cwd", false),
|
|
563
550
|
}, { hqRoot, index: policyIndex, env, now: clock });
|
|
564
551
|
}
|
|
565
|
-
case "policy.index": {
|
|
566
|
-
requireRoot();
|
|
567
|
-
const company = stringArg(args, "company", false);
|
|
568
|
-
return { version: policyIndex.version, policies: policyIndex.list(company) };
|
|
569
|
-
}
|
|
570
552
|
case "journal.append": {
|
|
571
553
|
const company = companyFor(args);
|
|
572
554
|
if (!company)
|
|
573
555
|
throw new OpError("bad_args", "company is required (or a cwd linked to a company)");
|
|
574
556
|
return journalAppend({ company, project: stringArg(args, "project"), section: stringArg(args, "section"), text: stringArg(args, "text") }, requireRoot(), clock());
|
|
575
557
|
}
|
|
576
|
-
case "memory.get":
|
|
577
|
-
return memoryGet(requireRoot(), stringArg(args, "sessionId"), stringArg(args, "key", false));
|
|
578
|
-
case "memory.put":
|
|
579
|
-
return memoryPut(requireRoot(), stringArg(args, "sessionId"), stringArg(args, "key"), args.value, clock());
|
|
580
|
-
case "mesh.presence": {
|
|
581
|
-
const harness = stringArg(args, "harness", false) ?? stringArg(args, "runtime");
|
|
582
|
-
return meshPresence({
|
|
583
|
-
sessionId: stringArg(args, "sessionId"),
|
|
584
|
-
harness,
|
|
585
|
-
kind: stringArg(args, "kind"),
|
|
586
|
-
cwd: stringArg(args, "cwd", false),
|
|
587
|
-
company: companyFor(args),
|
|
588
|
-
project: stringArg(args, "project", false),
|
|
589
|
-
task: stringArg(args, "task", false),
|
|
590
|
-
taskId: stringArg(args, "taskId", false),
|
|
591
|
-
status: stringArg(args, "status", false),
|
|
592
|
-
summary: stringArg(args, "summary", false),
|
|
593
|
-
reason: stringArg(args, "reason", false),
|
|
594
|
-
}, { hqRoot: opts.hqRoot, workMeshRoot: opts.workMeshRoot, env, now: clock });
|
|
595
|
-
}
|
|
596
558
|
case "mcp.call": {
|
|
597
559
|
const name = stringArg(args, "name");
|
|
598
560
|
const raw = args.arguments ?? {};
|
|
@@ -686,9 +648,10 @@ export async function startHqdServer(opts) {
|
|
|
686
648
|
}
|
|
687
649
|
}
|
|
688
650
|
}
|
|
689
|
-
case "shutdown":
|
|
690
|
-
return { stopping: true };
|
|
691
651
|
default:
|
|
652
|
+
// Removed ops (session.get, policy.index, memory.get, memory.put,
|
|
653
|
+
// mesh.presence, shutdown: hq-core-rust US-036) land here too, so an
|
|
654
|
+
// old client gets this refusal instead of a silent no-op.
|
|
692
655
|
throw new OpError("unknown_op", `unknown op ${req.op}`);
|
|
693
656
|
}
|
|
694
657
|
};
|
|
@@ -710,18 +673,12 @@ export async function startHqdServer(opts) {
|
|
|
710
673
|
const req = parsed.request;
|
|
711
674
|
const succeed = (result) => {
|
|
712
675
|
respond(socket, { id: req.id, ok: true, result });
|
|
713
|
-
if (req.op === "shutdown") {
|
|
714
|
-
log("info", "hqd received a shutdown request");
|
|
715
|
-
setImmediate(() => opts.onShutdown?.());
|
|
716
|
-
}
|
|
717
676
|
};
|
|
718
677
|
const fail = (err) => {
|
|
719
678
|
observeError(err);
|
|
720
679
|
const error = err instanceof OpError ||
|
|
721
680
|
err instanceof PolicyOpError ||
|
|
722
681
|
err instanceof JournalOpError ||
|
|
723
|
-
err instanceof MemoryOpError ||
|
|
724
|
-
err instanceof MeshOpError ||
|
|
725
682
|
err instanceof McpOpError ||
|
|
726
683
|
err instanceof MachineLoginError
|
|
727
684
|
? { code: err.code, message: err.message }
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The daemon's state file: one JSON file, rewritten atomically after each
|
|
3
|
-
* flag registry request the daemon's timed flag monitors share,
|
|
4
|
-
*
|
|
3
|
+
* flag registry request the daemon's timed flag monitors share, and again
|
|
4
|
+
* after each refresh of the merge sections (every 15 s, merge-sections.ts),
|
|
5
|
+
* that hooks read instead of starting Node or calling the network.
|
|
5
6
|
*
|
|
6
|
-
* It holds
|
|
7
|
+
* It holds these sections and nothing else:
|
|
7
8
|
* - flags: every flag value the registry returned for the daemon's scope
|
|
8
9
|
* (person, or one company uid), with the time the registry answered;
|
|
9
10
|
* - vault_access: per company slug, the caller's role, whether the access
|
|
@@ -13,7 +14,18 @@
|
|
|
13
14
|
* today (id, status, time, optional one-line summary, and for a finding
|
|
14
15
|
* its text, cut to 4096 bytes, and a fingerprint the hook engine uses to
|
|
15
16
|
* show it once). The finding text can name local paths, so like the rest
|
|
16
|
-
* of the file it is never logged or sent
|
|
17
|
+
* of the file it is never logged or sent;
|
|
18
|
+
* - lanes_monitor (optional, written only when the daemon computed it): per
|
|
19
|
+
* Claude senior session of an active lane, the active and uncovered lane
|
|
20
|
+
* ids, the Monitor calls that would cover the uncovered ones, and the
|
|
21
|
+
* reminder text (lanes-monitor-state.ts). It is what `hq lanes
|
|
22
|
+
* monitor-check` would answer, precomputed so the UserPromptSubmit hook
|
|
23
|
+
* starts no program. A missing or stale section means no reminder.
|
|
24
|
+
* - merge_holds and merge_approvals (merge-sections.ts): the repository
|
|
25
|
+
* merge holds with each owning company's hold flag, and per session the
|
|
26
|
+
* conduct decision queue and review gate the native merge check reads.
|
|
27
|
+
* Each has its own refreshed_at and a 60-second max age; a section that
|
|
28
|
+
* cannot be built is left out, which makes that check refuse merges.
|
|
17
29
|
*
|
|
18
30
|
* No token, key or other secret is written. The vault access list tells which
|
|
19
31
|
* companies and paths a person can reach, so the file lives in the per-host
|
|
@@ -37,6 +49,7 @@
|
|
|
37
49
|
import { type StoreWriteHook } from "./paths.js";
|
|
38
50
|
import type { DaemonFlagRegistryRead } from "./flag.js";
|
|
39
51
|
import type { SelfCheckResult } from "./selfcheck.js";
|
|
52
|
+
import type { MergeApprovalsSection, MergeHoldsSection, MergeSections } from "./merge-sections.js";
|
|
40
53
|
import { type DaemonStateFileOffReason } from "./state-file-switch.js";
|
|
41
54
|
export declare const DAEMON_STATE_SCHEMA = "hq-state.v1";
|
|
42
55
|
export declare const DAEMON_STATE_FILE = "hq-state.json";
|
|
@@ -76,6 +89,33 @@ export interface DaemonStateMachineCheck {
|
|
|
76
89
|
export declare const MACHINE_CHECK_DETAIL_BYTES = 4096;
|
|
77
90
|
/** `text` cut to at most `maxBytes` of UTF-8, never inside a character. */
|
|
78
91
|
export declare function cutUtf8(text: string, maxBytes: number): string;
|
|
92
|
+
export interface DaemonStateMonitorCall {
|
|
93
|
+
command: string;
|
|
94
|
+
timeout_ms: number;
|
|
95
|
+
persistent: false;
|
|
96
|
+
}
|
|
97
|
+
export interface DaemonStateLanesMonitorSession {
|
|
98
|
+
/** Always "claude": only Claude Code has a Monitor tool. */
|
|
99
|
+
engine: "claude";
|
|
100
|
+
checked_at: string;
|
|
101
|
+
active_lane_ids: string[];
|
|
102
|
+
/** A subset of active_lane_ids, in the same order. */
|
|
103
|
+
uncovered_lane_ids: string[];
|
|
104
|
+
monitor_calls: DaemonStateMonitorCall[];
|
|
105
|
+
reminder: string;
|
|
106
|
+
}
|
|
107
|
+
export interface DaemonStateLanesMonitor {
|
|
108
|
+
checked_at: string;
|
|
109
|
+
/** Keyed by senior session id. Empty when the daemon checked and no session has an active lane. */
|
|
110
|
+
sessions: Record<string, DaemonStateLanesMonitorSession>;
|
|
111
|
+
}
|
|
112
|
+
/** At most this many sessions are written into lanes_monitor. */
|
|
113
|
+
export declare const LANES_MONITOR_MAX_SESSIONS = 64;
|
|
114
|
+
/** The hook engine refuses an extra section larger than this (crates/hq-hook). */
|
|
115
|
+
export declare const LANES_MONITOR_READER_MAX_BYTES: number;
|
|
116
|
+
/** The writer keeps lanes_monitor, serialized, at or under this many bytes. */
|
|
117
|
+
export declare const LANES_MONITOR_MAX_BYTES: number;
|
|
118
|
+
export declare const LANES_MONITOR_SESSION_ID_RE: RegExp;
|
|
79
119
|
export interface DaemonStateFile {
|
|
80
120
|
schema: typeof DAEMON_STATE_SCHEMA;
|
|
81
121
|
written_at: string;
|
|
@@ -87,6 +127,11 @@ export interface DaemonStateFile {
|
|
|
87
127
|
machine_checks: {
|
|
88
128
|
results: DaemonStateMachineCheck[];
|
|
89
129
|
};
|
|
130
|
+
/** Written only when present (not null or undefined). */
|
|
131
|
+
lanes_monitor?: DaemonStateLanesMonitor | null;
|
|
132
|
+
/** Left out of the file when absent or null (merge-sections.ts). */
|
|
133
|
+
merge_holds?: MergeHoldsSection | null;
|
|
134
|
+
merge_approvals?: MergeApprovalsSection | null;
|
|
90
135
|
}
|
|
91
136
|
/** `HQ_STATE_FILE` when set (tests and isolated daemons), else `<daemon folder>/hq-state.json`. */
|
|
92
137
|
export declare function daemonStateFilePath(home?: string, env?: NodeJS.ProcessEnv): string;
|
|
@@ -115,6 +160,15 @@ export declare function readVaultAccessManifest(hqRoot: string | undefined): Dae
|
|
|
115
160
|
* carry vault ids, so only their count reaches the state file.
|
|
116
161
|
*/
|
|
117
162
|
export declare function selfCheckMachineChecks(result: SelfCheckResult | null): DaemonStateMachineCheck[];
|
|
163
|
+
/**
|
|
164
|
+
* The lanes_monitor section with only its documented fields, in key order, or
|
|
165
|
+
* null when any part of it is malformed (a bad session id or entry, an
|
|
166
|
+
* uncovered id that is not active, more than LANES_MONITOR_MAX_SESSIONS
|
|
167
|
+
* sessions, or more than LANES_MONITOR_READER_MAX_BYTES serialized). The whole
|
|
168
|
+
* section is dropped rather than part of it, so a reader never takes a partial
|
|
169
|
+
* answer for a complete one.
|
|
170
|
+
*/
|
|
171
|
+
export declare function lanesMonitorSectionOf(value: unknown): DaemonStateLanesMonitor | null;
|
|
118
172
|
/** The exact bytes written: one line of JSON with the keys in schema order. */
|
|
119
173
|
export declare function renderDaemonStateFile(state: DaemonStateFile): string;
|
|
120
174
|
export interface WriteDaemonStateFileDeps {
|
|
@@ -174,6 +228,14 @@ export interface DaemonStateWriterOptions {
|
|
|
174
228
|
/** The vault access section; null when there is none to write. */
|
|
175
229
|
readVaultAccess?: () => DaemonStateVaultAccess | null;
|
|
176
230
|
readMachineChecks?: () => DaemonStateMachineCheck[];
|
|
231
|
+
/**
|
|
232
|
+
* The lanes_monitor section (lanes-monitor-state.ts); null when there is none
|
|
233
|
+
* to write. A throwing reader leaves the section out and the rest of the
|
|
234
|
+
* file is still written.
|
|
235
|
+
*/
|
|
236
|
+
readLanesMonitor?: () => DaemonStateLanesMonitor | null;
|
|
237
|
+
/** The latest merge sections (merge-sections.ts); a null section is left out. */
|
|
238
|
+
readMergeSections?: () => MergeSections;
|
|
177
239
|
/** Test seam for the write (Windows rename behavior). */
|
|
178
240
|
writeDeps?: WriteDaemonStateFileDeps;
|
|
179
241
|
/**
|
|
@@ -192,6 +254,14 @@ export interface DaemonStateWriter {
|
|
|
192
254
|
* writer makes no request of its own.
|
|
193
255
|
*/
|
|
194
256
|
onRegistryRead(read: DaemonFlagRegistryRead, env: NodeJS.ProcessEnv): void;
|
|
257
|
+
/**
|
|
258
|
+
* Write the file again with fresh vault access, machine checks and merge
|
|
259
|
+
* sections, and the flags of the last registry request with the time that
|
|
260
|
+
* request answered (readers age flags by that time). Nothing is written
|
|
261
|
+
* before the first registry request, or while the last one switched the
|
|
262
|
+
* file off.
|
|
263
|
+
*/
|
|
264
|
+
refresh(): void;
|
|
195
265
|
close(): void;
|
|
196
266
|
}
|
|
197
267
|
/**
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The daemon's state file: one JSON file, rewritten atomically after each
|
|
3
|
-
* flag registry request the daemon's timed flag monitors share,
|
|
4
|
-
*
|
|
3
|
+
* flag registry request the daemon's timed flag monitors share, and again
|
|
4
|
+
* after each refresh of the merge sections (every 15 s, merge-sections.ts),
|
|
5
|
+
* that hooks read instead of starting Node or calling the network.
|
|
5
6
|
*
|
|
6
|
-
* It holds
|
|
7
|
+
* It holds these sections and nothing else:
|
|
7
8
|
* - flags: every flag value the registry returned for the daemon's scope
|
|
8
9
|
* (person, or one company uid), with the time the registry answered;
|
|
9
10
|
* - vault_access: per company slug, the caller's role, whether the access
|
|
@@ -13,7 +14,18 @@
|
|
|
13
14
|
* today (id, status, time, optional one-line summary, and for a finding
|
|
14
15
|
* its text, cut to 4096 bytes, and a fingerprint the hook engine uses to
|
|
15
16
|
* show it once). The finding text can name local paths, so like the rest
|
|
16
|
-
* of the file it is never logged or sent
|
|
17
|
+
* of the file it is never logged or sent;
|
|
18
|
+
* - lanes_monitor (optional, written only when the daemon computed it): per
|
|
19
|
+
* Claude senior session of an active lane, the active and uncovered lane
|
|
20
|
+
* ids, the Monitor calls that would cover the uncovered ones, and the
|
|
21
|
+
* reminder text (lanes-monitor-state.ts). It is what `hq lanes
|
|
22
|
+
* monitor-check` would answer, precomputed so the UserPromptSubmit hook
|
|
23
|
+
* starts no program. A missing or stale section means no reminder.
|
|
24
|
+
* - merge_holds and merge_approvals (merge-sections.ts): the repository
|
|
25
|
+
* merge holds with each owning company's hold flag, and per session the
|
|
26
|
+
* conduct decision queue and review gate the native merge check reads.
|
|
27
|
+
* Each has its own refreshed_at and a 60-second max age; a section that
|
|
28
|
+
* cannot be built is left out, which makes that check refuse merges.
|
|
17
29
|
*
|
|
18
30
|
* No token, key or other secret is written. The vault access list tells which
|
|
19
31
|
* companies and paths a person can reach, so the file lives in the per-host
|
|
@@ -70,6 +82,13 @@ export function cutUtf8(text, maxBytes) {
|
|
|
70
82
|
end -= 1;
|
|
71
83
|
return bytes.subarray(0, end).toString("utf8");
|
|
72
84
|
}
|
|
85
|
+
/** At most this many sessions are written into lanes_monitor. */
|
|
86
|
+
export const LANES_MONITOR_MAX_SESSIONS = 64;
|
|
87
|
+
/** The hook engine refuses an extra section larger than this (crates/hq-hook). */
|
|
88
|
+
export const LANES_MONITOR_READER_MAX_BYTES = 256 * 1024;
|
|
89
|
+
/** The writer keeps lanes_monitor, serialized, at or under this many bytes. */
|
|
90
|
+
export const LANES_MONITOR_MAX_BYTES = 192 * 1024;
|
|
91
|
+
export const LANES_MONITOR_SESSION_ID_RE = /^[A-Za-z0-9._-]+$/;
|
|
73
92
|
/** `HQ_STATE_FILE` when set (tests and isolated daemons), else `<daemon folder>/hq-state.json`. */
|
|
74
93
|
export function daemonStateFilePath(home, env = process.env) {
|
|
75
94
|
const explicit = env.HQ_STATE_FILE?.trim();
|
|
@@ -202,6 +221,70 @@ function machineChecksOf(results) {
|
|
|
202
221
|
}
|
|
203
222
|
return out;
|
|
204
223
|
}
|
|
224
|
+
function isLaneIdList(value) {
|
|
225
|
+
return Array.isArray(value) && value.every((id) => typeof id === "string" && id.length > 0);
|
|
226
|
+
}
|
|
227
|
+
function lanesMonitorSessionOf(value) {
|
|
228
|
+
if (!isRecord(value) || value.engine !== "claude" || !isIsoTime(value.checked_at))
|
|
229
|
+
return null;
|
|
230
|
+
if (typeof value.reminder !== "string")
|
|
231
|
+
return null;
|
|
232
|
+
const active = value.active_lane_ids;
|
|
233
|
+
const uncovered = value.uncovered_lane_ids;
|
|
234
|
+
if (!isLaneIdList(active) || !isLaneIdList(uncovered))
|
|
235
|
+
return null;
|
|
236
|
+
const activeSet = new Set(active);
|
|
237
|
+
if (!uncovered.every((id) => activeSet.has(id)))
|
|
238
|
+
return null;
|
|
239
|
+
if (!Array.isArray(value.monitor_calls))
|
|
240
|
+
return null;
|
|
241
|
+
const calls = [];
|
|
242
|
+
for (const call of value.monitor_calls) {
|
|
243
|
+
if (!isRecord(call) || typeof call.command !== "string" || !call.command)
|
|
244
|
+
return null;
|
|
245
|
+
if (typeof call.timeout_ms !== "number" || !Number.isInteger(call.timeout_ms) || call.timeout_ms <= 0)
|
|
246
|
+
return null;
|
|
247
|
+
if (call.persistent !== false)
|
|
248
|
+
return null;
|
|
249
|
+
calls.push({ command: call.command, timeout_ms: call.timeout_ms, persistent: false });
|
|
250
|
+
}
|
|
251
|
+
return {
|
|
252
|
+
engine: "claude",
|
|
253
|
+
checked_at: value.checked_at,
|
|
254
|
+
active_lane_ids: [...active],
|
|
255
|
+
uncovered_lane_ids: [...uncovered],
|
|
256
|
+
monitor_calls: calls,
|
|
257
|
+
reminder: value.reminder,
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* The lanes_monitor section with only its documented fields, in key order, or
|
|
262
|
+
* null when any part of it is malformed (a bad session id or entry, an
|
|
263
|
+
* uncovered id that is not active, more than LANES_MONITOR_MAX_SESSIONS
|
|
264
|
+
* sessions, or more than LANES_MONITOR_READER_MAX_BYTES serialized). The whole
|
|
265
|
+
* section is dropped rather than part of it, so a reader never takes a partial
|
|
266
|
+
* answer for a complete one.
|
|
267
|
+
*/
|
|
268
|
+
export function lanesMonitorSectionOf(value) {
|
|
269
|
+
if (!isRecord(value) || !isIsoTime(value.checked_at) || !isRecord(value.sessions))
|
|
270
|
+
return null;
|
|
271
|
+
const ids = Object.keys(value.sessions);
|
|
272
|
+
if (ids.length > LANES_MONITOR_MAX_SESSIONS)
|
|
273
|
+
return null;
|
|
274
|
+
const sessions = {};
|
|
275
|
+
for (const id of ids) {
|
|
276
|
+
if (!LANES_MONITOR_SESSION_ID_RE.test(id))
|
|
277
|
+
return null;
|
|
278
|
+
const entry = lanesMonitorSessionOf(value.sessions[id]);
|
|
279
|
+
if (!entry)
|
|
280
|
+
return null;
|
|
281
|
+
sessions[id] = entry;
|
|
282
|
+
}
|
|
283
|
+
const section = { checked_at: value.checked_at, sessions };
|
|
284
|
+
if (Buffer.byteLength(JSON.stringify(section), "utf8") > LANES_MONITOR_READER_MAX_BYTES)
|
|
285
|
+
return null;
|
|
286
|
+
return section;
|
|
287
|
+
}
|
|
205
288
|
/** The exact bytes written: one line of JSON with the keys in schema order. */
|
|
206
289
|
export function renderDaemonStateFile(state) {
|
|
207
290
|
const scopes = {};
|
|
@@ -218,7 +301,12 @@ export function renderDaemonStateFile(state) {
|
|
|
218
301
|
? { refreshed_at: state.vault_access.refreshed_at, companies: state.vault_access.companies }
|
|
219
302
|
: null,
|
|
220
303
|
machine_checks: { results: machineChecksOf(state.machine_checks.results) },
|
|
304
|
+
...(state.merge_holds ? { merge_holds: state.merge_holds } : {}),
|
|
305
|
+
...(state.merge_approvals ? { merge_approvals: state.merge_approvals } : {}),
|
|
221
306
|
};
|
|
307
|
+
const lanesMonitor = state.lanes_monitor ? lanesMonitorSectionOf(state.lanes_monitor) : null;
|
|
308
|
+
if (lanesMonitor)
|
|
309
|
+
ordered.lanes_monitor = lanesMonitor;
|
|
222
310
|
return `${JSON.stringify(ordered)}\n`;
|
|
223
311
|
}
|
|
224
312
|
/**
|
|
@@ -297,6 +385,7 @@ export function readDaemonStateFile(file) {
|
|
|
297
385
|
const checks = isRecord(parsed.machine_checks) && Array.isArray(parsed.machine_checks.results)
|
|
298
386
|
? machineChecksOf(parsed.machine_checks.results)
|
|
299
387
|
: [];
|
|
388
|
+
const lanesMonitor = parsed.lanes_monitor === undefined ? null : lanesMonitorSectionOf(parsed.lanes_monitor);
|
|
300
389
|
return {
|
|
301
390
|
schema: DAEMON_STATE_SCHEMA,
|
|
302
391
|
written_at: parsed.written_at,
|
|
@@ -306,6 +395,9 @@ export function readDaemonStateFile(file) {
|
|
|
306
395
|
? { refreshed_at: vault.refreshed_at, companies: vault.companies }
|
|
307
396
|
: null,
|
|
308
397
|
machine_checks: { results: checks },
|
|
398
|
+
...(isRecord(parsed.merge_holds) ? { merge_holds: parsed.merge_holds } : {}),
|
|
399
|
+
...(isRecord(parsed.merge_approvals) ? { merge_approvals: parsed.merge_approvals } : {}),
|
|
400
|
+
...(lanesMonitor ? { lanes_monitor: lanesMonitor } : {}),
|
|
309
401
|
};
|
|
310
402
|
}
|
|
311
403
|
/** `person`, a company uid, or null for a slug that resolves to no uid (its flags are not written). */
|
|
@@ -360,6 +452,7 @@ export function createDaemonStateWriter(options) {
|
|
|
360
452
|
const log = options.log ?? (() => { });
|
|
361
453
|
let closed = false;
|
|
362
454
|
let lastProblem;
|
|
455
|
+
let lanesMonitorProblem;
|
|
363
456
|
// The file left from before the switch went off is removed once per off period.
|
|
364
457
|
let removedWhileOff = false;
|
|
365
458
|
const ownFile = options.defaultFile === undefined || path.resolve(options.defaultFile) === path.resolve(options.file);
|
|
@@ -373,7 +466,62 @@ export function createDaemonStateWriter(options) {
|
|
|
373
466
|
log("info", "state file: written again");
|
|
374
467
|
};
|
|
375
468
|
const errorName = (error) => (error instanceof Error ? error.name : "UnknownError");
|
|
469
|
+
// The flags of the last registry request while the file is on; null before
|
|
470
|
+
// the first one and while it is off. Kept in memory only, never read back
|
|
471
|
+
// from the file.
|
|
472
|
+
let lastScopes = null;
|
|
473
|
+
/** Write the file; the problem to report, or undefined when it was written. */
|
|
474
|
+
const write = (now, scopes) => {
|
|
475
|
+
const merge = options.readMergeSections?.() ?? { merge_holds: null, merge_approvals: null };
|
|
476
|
+
let lanesMonitor = null;
|
|
477
|
+
try {
|
|
478
|
+
lanesMonitor = options.readLanesMonitor?.() ?? null;
|
|
479
|
+
if (lanesMonitorProblem)
|
|
480
|
+
log("info", "state file: lanes_monitor section computed again");
|
|
481
|
+
lanesMonitorProblem = undefined;
|
|
482
|
+
}
|
|
483
|
+
catch (error) {
|
|
484
|
+
// The hook reads a missing section as "no reminder"; the rest of the
|
|
485
|
+
// file is still written.
|
|
486
|
+
lanesMonitor = null;
|
|
487
|
+
const problem = errorName(error);
|
|
488
|
+
if (problem !== lanesMonitorProblem)
|
|
489
|
+
log("warn", `state file: lanes_monitor section left out (${problem})`);
|
|
490
|
+
lanesMonitorProblem = problem;
|
|
491
|
+
}
|
|
492
|
+
try {
|
|
493
|
+
writeDaemonStateFile(options.file, {
|
|
494
|
+
schema: DAEMON_STATE_SCHEMA,
|
|
495
|
+
written_at: now.toISOString(),
|
|
496
|
+
max_age_seconds: maxAgeSeconds,
|
|
497
|
+
flags: { scopes },
|
|
498
|
+
vault_access: options.readVaultAccess?.() ?? null,
|
|
499
|
+
machine_checks: { results: options.readMachineChecks?.() ?? [] },
|
|
500
|
+
merge_holds: merge.merge_holds,
|
|
501
|
+
merge_approvals: merge.merge_approvals,
|
|
502
|
+
...(lanesMonitor ? { lanes_monitor: lanesMonitor } : {}),
|
|
503
|
+
}, { ...options.writeDeps, ...(options.defaultFile ? { defaultFile: options.defaultFile } : {}) });
|
|
504
|
+
}
|
|
505
|
+
catch (error) {
|
|
506
|
+
// Never the contents: the file holds the vault access list.
|
|
507
|
+
const code = error.code;
|
|
508
|
+
return `could not be written (${typeof code === "string" ? code : errorName(error)}); readers keep the previous file`;
|
|
509
|
+
}
|
|
510
|
+
return undefined;
|
|
511
|
+
};
|
|
376
512
|
return {
|
|
513
|
+
refresh() {
|
|
514
|
+
if (closed || !lastScopes)
|
|
515
|
+
return;
|
|
516
|
+
try {
|
|
517
|
+
const problem = write(wallClock(), lastScopes);
|
|
518
|
+
if (problem)
|
|
519
|
+
report(problem);
|
|
520
|
+
}
|
|
521
|
+
catch {
|
|
522
|
+
// a failing section reader or log sink cannot reach the caller
|
|
523
|
+
}
|
|
524
|
+
},
|
|
377
525
|
onRegistryRead(read, env) {
|
|
378
526
|
if (closed)
|
|
379
527
|
return;
|
|
@@ -381,6 +529,7 @@ export function createDaemonStateWriter(options) {
|
|
|
381
529
|
const snapshot = !read.signedOut && read.errors.length === 0 ? read.client?.snapshot?.() ?? null : null;
|
|
382
530
|
const off = (options.offReason ?? defaultOffReason)(read, env);
|
|
383
531
|
if (off) {
|
|
532
|
+
lastScopes = null;
|
|
384
533
|
let removed = "";
|
|
385
534
|
if (!removedWhileOff && ownFile) {
|
|
386
535
|
removedWhileOff = true;
|
|
@@ -401,25 +550,16 @@ export function createDaemonStateWriter(options) {
|
|
|
401
550
|
// request: a file planted or loosened by another process is never
|
|
402
551
|
// rewritten as the daemon's own, and when the daemon is signed out or
|
|
403
552
|
// the request failed the flags are absent, so readers use each flag's
|
|
404
|
-
// default.
|
|
553
|
+
// default. refresh() rewrites these same flags, with this request's
|
|
554
|
+
// fetched_at, until the next request.
|
|
405
555
|
const scopes = {};
|
|
406
556
|
if (snapshot && scope) {
|
|
407
557
|
scopes[scope] = { fetched_at: now.toISOString(), values: daemonStateFlagValues(snapshot.flags) };
|
|
408
558
|
}
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
max_age_seconds: maxAgeSeconds,
|
|
414
|
-
flags: { scopes },
|
|
415
|
-
vault_access: options.readVaultAccess?.() ?? null,
|
|
416
|
-
machine_checks: { results: options.readMachineChecks?.() ?? [] },
|
|
417
|
-
}, { ...options.writeDeps, ...(options.defaultFile ? { defaultFile: options.defaultFile } : {}) });
|
|
418
|
-
}
|
|
419
|
-
catch (error) {
|
|
420
|
-
// Never the contents: the file holds the vault access list.
|
|
421
|
-
const code = error.code;
|
|
422
|
-
report(`could not be written (${typeof code === "string" ? code : errorName(error)}); readers keep the previous file`);
|
|
559
|
+
lastScopes = scopes;
|
|
560
|
+
const problem = write(now, scopes);
|
|
561
|
+
if (problem) {
|
|
562
|
+
report(problem);
|
|
423
563
|
return;
|
|
424
564
|
}
|
|
425
565
|
if (read.signedOut)
|
|
@@ -91,7 +91,7 @@ export interface SupervisedChild {
|
|
|
91
91
|
on(event: "error", handler: (err: Error) => void): unknown;
|
|
92
92
|
kill(signal?: NodeJS.Signals | number): boolean;
|
|
93
93
|
}
|
|
94
|
-
type UnitStatus = "running" | "waiting" | "unavailable" | "backoff" | "exited" | "idle" | "stopped" | "held";
|
|
94
|
+
type UnitStatus = "running" | "waiting" | "unavailable" | "backoff" | "exited" | "idle" | "stopped" | "held" | "paused";
|
|
95
95
|
/**
|
|
96
96
|
* Why a long-running unit is held down. `permanent`: the last exit had a cause
|
|
97
97
|
* a restart cannot fix. `exhausted`: EPISODE_MAX_FAILURES failures without a
|