@indigoai-us/hq-cli 5.345.222 → 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 +89 -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 +79 -5
- package/dist/command-catalog.generated.js +95 -5
- package/dist/commands/bot.d.ts +1 -1
- package/dist/commands/bot.js +34 -33
- 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 +210 -188
- 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 +14 -3
- package/dist/commands/sync-core.js +31 -12
- 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/bot/fleet-cron.d.ts +26 -3
- package/dist/lib/bot/fleet-cron.js +44 -4
- package/dist/lib/bot/run.d.ts +4 -4
- package/dist/lib/bot/run.js +5 -3
- package/dist/lib/bot/signals-engine-flag.d.ts +53 -13
- package/dist/lib/bot/signals-engine-flag.js +202 -9
- 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/machine-checks.d.ts +45 -0
- package/dist/lib/daemon/machine-checks.js +95 -11
- package/dist/lib/daemon/merge-sections.d.ts +165 -0
- package/dist/lib/daemon/merge-sections.js +556 -0
- package/dist/lib/daemon/native-notice-ledger.d.ts +9 -0
- package/dist/lib/daemon/native-notice-ledger.js +43 -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 +76 -3
- 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 +11 -1
- package/dist/lib/daemon/supervisor.js +86 -0
- 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/flag-registry-worker-source.generated.d.ts +1 -1
- package/dist/lib/flag-registry-worker-source.generated.js +1 -1
- package/dist/lib/flag-registry-worker.js +33 -3
- package/dist/lib/flag-registry.js +13 -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/scan-packages/index.js +8 -9
- package/dist/lib/signals/engine.d.ts +8 -0
- package/dist/lib/signals/engine.js +15 -5
- package/dist/lib/sync-core/flag.d.ts +18 -0
- package/dist/lib/sync-core/flag.js +66 -0
- package/dist/lib/sync-core/reconcile.d.ts +6 -0
- package/dist/lib/sync-core/reconcile.js +15 -0
- package/dist/lib/sync-core/rollout-state.d.ts +2 -0
- package/dist/lib/sync-core/rollout-state.js +7 -0
- package/dist/lib/sync-core/vault-settings.d.ts +12 -1
- package/dist/lib/sync-core/vault-settings.js +23 -7
- 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/pack-contributions.d.ts +14 -2
- package/dist/utils/pack-contributions.js +31 -5
- 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/scripts/bench-core.mjs +34 -3
- 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
|
@@ -27,11 +27,13 @@ import { effectiveSyncOwner, readDaemonConfig } from "./config.js";
|
|
|
27
27
|
import { inspectEngineHome } from "../sync-core/engine-home.js";
|
|
28
28
|
import { fullModeHold } from "../sync-core/reconcile.js";
|
|
29
29
|
import { readSyncCoreRolloutState } from "../sync-core/rollout-state.js";
|
|
30
|
-
import { readSyncCoreVaultSettings } from "../sync-core/vault-settings.js";
|
|
30
|
+
import { effectiveEngineSettings, readSyncCoreVaultSettings } from "../sync-core/vault-settings.js";
|
|
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";
|
|
@@ -86,6 +89,7 @@ export function syncCoreVaultPlans(home, hqRoot, platform) {
|
|
|
86
89
|
return [];
|
|
87
90
|
const settings = readSyncCoreVaultSettings(home);
|
|
88
91
|
return state.vaults.map((vault) => {
|
|
92
|
+
const effective = effectiveEngineSettings(settings.get(vault.uid), vault.downloadStreams);
|
|
89
93
|
const plan = inspectEngineHome(home, hqRoot, {
|
|
90
94
|
uid: vault.uid,
|
|
91
95
|
kind: vault.kind,
|
|
@@ -95,7 +99,7 @@ export function syncCoreVaultPlans(home, hqRoot, platform) {
|
|
|
95
99
|
binaryPath: state.binaryPath,
|
|
96
100
|
release: state.release,
|
|
97
101
|
...(vault.legacyOffSince ? { legacyOffSince: vault.legacyOffSince } : {}),
|
|
98
|
-
...(
|
|
102
|
+
...(effective ? { settings: effective } : {}),
|
|
99
103
|
}, platform);
|
|
100
104
|
const releaseHold = vault.phase === "full" ? fullModeHold(vault, state.release, platform) : undefined;
|
|
101
105
|
return releaseHold ? { ...plan, blockedReason: releaseHold } : plan;
|
|
@@ -987,6 +991,8 @@ export async function runDaemon(opts) {
|
|
|
987
991
|
let supervisor = null;
|
|
988
992
|
// One registry request per 30-second tick decides every timed daemon flag.
|
|
989
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();
|
|
990
996
|
const stateWriter = createDaemonStateWriter({
|
|
991
997
|
file: daemonStateFilePath(home, env),
|
|
992
998
|
defaultFile: defaultDaemonStateFilePath(home, env),
|
|
@@ -999,7 +1005,57 @@ export async function runDaemon(opts) {
|
|
|
999
1005
|
...selfCheckMachineChecks(readSelfCheckResult(path.join(paths.root, SELF_CHECK_RESULT_FILE))),
|
|
1000
1006
|
...readMachineCheckResults(path.join(paths.root, MACHINE_CHECKS_RESULT_FILE)),
|
|
1001
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(),
|
|
1002
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;
|
|
1003
1059
|
// The hqd listener checks again when a shared read's HQ Anywhere answer
|
|
1004
1060
|
// changes, or the running server's runtime gate changes; it has no timer of
|
|
1005
1061
|
// its own beyond a rare fallback (anywhere-listener.ts).
|
|
@@ -1101,7 +1157,9 @@ export async function runDaemon(opts) {
|
|
|
1101
1157
|
killSwitches.close();
|
|
1102
1158
|
machineChecks.close();
|
|
1103
1159
|
flagSnapshots.close();
|
|
1160
|
+
mergeSections.close();
|
|
1104
1161
|
stateWriter.close();
|
|
1162
|
+
whoamiCache?.close();
|
|
1105
1163
|
return stopJobsClosed;
|
|
1106
1164
|
};
|
|
1107
1165
|
const plan = () => {
|
|
@@ -1326,6 +1384,7 @@ export async function runDaemon(opts) {
|
|
|
1326
1384
|
signedIn: isSignedIn,
|
|
1327
1385
|
kitConfigured: fs.existsSync(agentKitPaths(home, env).kitConfigPath),
|
|
1328
1386
|
syncPaused: config.syncPaused === true,
|
|
1387
|
+
syncCorePause: config.syncCorePause,
|
|
1329
1388
|
vaultSync: (() => {
|
|
1330
1389
|
const switches = readVaultSyncSwitches(home);
|
|
1331
1390
|
// Log once per change, not every reconcile.
|
|
@@ -1514,6 +1573,20 @@ export async function runDaemon(opts) {
|
|
|
1514
1573
|
plan,
|
|
1515
1574
|
spawn: spawnUnit,
|
|
1516
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
|
+
}
|
|
1517
1590
|
if (task !== "rotate-logs")
|
|
1518
1591
|
throw new Error(`unknown internal task ${task}`);
|
|
1519
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
|
/**
|