@indigoai-us/hq-cli 5.345.223 → 5.345.226
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 +98 -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 +156 -4
- package/dist/command-catalog.generated.js +191 -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 +68 -2
- package/dist/commands/deploy-domains.js +38 -2
- package/dist/commands/lanes-accounts.d.ts +14 -0
- package/dist/commands/lanes-accounts.js +119 -0
- 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-move.js +10 -0
- package/dist/commands/lanes-session-start.js +2 -2
- package/dist/commands/lanes-shared.js +9 -0
- package/dist/commands/lanes.js +137 -12
- 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/sync-held.d.ts +22 -0
- package/dist/commands/sync-held.js +167 -18
- 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/hq-cloud-sync-runner/bin/sync-runner.js +4845 -2524
- package/dist/hq-cloud-sync-runner/package.json +1 -1
- package/dist/index.js +1 -1
- package/dist/lib/capacity/accounts.d.ts +4 -0
- package/dist/lib/capacity/accounts.js +4 -0
- package/dist/lib/capacity/route.js +14 -0
- package/dist/lib/capacity/sign-in.d.ts +18 -0
- package/dist/lib/capacity/sign-in.js +34 -1
- package/dist/lib/daemon/catalog.d.ts +9 -5
- package/dist/lib/daemon/catalog.js +14 -8
- package/dist/lib/daemon/config.d.ts +5 -0
- package/dist/lib/daemon/config.js +6 -0
- package/dist/lib/daemon/hook-requests.d.ts +76 -0
- package/dist/lib/daemon/hook-requests.js +481 -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/lanes-reconcile-status.d.ts +35 -0
- package/dist/lib/daemon/lanes-reconcile-status.js +86 -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 +2 -2
- package/dist/lib/daemon/ops/policy.js +44 -5
- package/dist/lib/daemon/protocol.d.ts +1 -1
- package/dist/lib/daemon/protocol.js +0 -6
- package/dist/lib/daemon/run.js +110 -5
- package/dist/lib/daemon/selfcheck.js +2 -2
- package/dist/lib/daemon/server.d.ts +2 -4
- package/dist/lib/daemon/server.js +11 -49
- 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 +3 -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/flag-registry-worker-source.generated.d.ts +1 -1
- package/dist/lib/flag-registry-worker-source.generated.js +1 -1
- 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/account-company.d.ts +7 -1
- package/dist/lib/lanes/account-company.js +22 -4
- package/dist/lib/lanes/account-ownership.d.ts +65 -0
- package/dist/lib/lanes/account-ownership.js +134 -0
- package/dist/lib/lanes/accounts.js +9 -2
- package/dist/lib/lanes/claude-balance.js +9 -3
- package/dist/lib/lanes/config.js +17 -0
- package/dist/lib/lanes/envelope-repair-dispatch.js +1 -1
- package/dist/lib/lanes/host-capacity.d.ts +19 -0
- package/dist/lib/lanes/host-capacity.js +37 -0
- package/dist/lib/lanes/monitor.d.ts +2 -0
- package/dist/lib/lanes/monitor.js +2 -1
- package/dist/lib/lanes/reconcile.js +44 -3
- 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/spawn.d.ts +0 -10
- package/dist/lib/lanes/spawn.js +51 -1
- package/dist/lib/lanes/types.d.ts +12 -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 +8 -8
- 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,11 +31,14 @@ 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";
|
|
38
40
|
import { createLanesReconcileWatcher } from "./lanes-reconcile-watcher.js";
|
|
41
|
+
import { createLanesReconcileStatus, withLanesReconcileUnit } from "./lanes-reconcile-status.js";
|
|
39
42
|
import { findLegacyUnits, legacyMeshUnitsToRetire, legacyOwnerLookup, } from "./legacy.js";
|
|
40
43
|
import { readLegacySyncEnv } from "./legacy-sync-env.js";
|
|
41
44
|
import { readVaultSyncSwitches, unreadableSwitchesWarning, writeVaultSyncSwitches } from "../vault-sync-switches.js";
|
|
@@ -53,6 +56,7 @@ import { classifyWindowsTask, currentWindowsIdentity, daemonRootRefusal } from "
|
|
|
53
56
|
import { detectMachineType } from "./machine-type.js";
|
|
54
57
|
import { appendPrivate, daemonPaths, ensurePrivateDir, openPrivateAppend } from "./paths.js";
|
|
55
58
|
import { SELF_CHECK_RESULT_FILE, readSelfCheckResult } from "./selfcheck.js";
|
|
59
|
+
import { createRegistryMergeFlagReader, startMergeSectionRefresh } from "./merge-sections.js";
|
|
56
60
|
import { createDaemonStateWriter, daemonStateFilePath, defaultDaemonStateFilePath, readVaultAccessManifest, selfCheckMachineChecks, } from "./state-file.js";
|
|
57
61
|
import { hqdSocketPath } from "./protocol.js";
|
|
58
62
|
import { startHqdServer, syncHqdEnabledMarker } from "./server.js";
|
|
@@ -74,6 +78,7 @@ import { createTccEpermGuard, TCC_EPERM_SENTRY_FINGERPRINT } from "./tcc-eperm.j
|
|
|
74
78
|
import { daemonRunGuard } from "./lanes-reconcile-guard.js";
|
|
75
79
|
import { startStopJobDrainer } from "./stop-jobs.js";
|
|
76
80
|
import { executeStopJob, pruneStopJobResults, stopJobCompleted } from "./stop-job-executor.js";
|
|
81
|
+
import { executeHookRequest, startHookRequestDrainer } from "./hook-requests.js";
|
|
77
82
|
import { closeStopDiagnosticCursor, drainStopDiagnostics } from "./stop-diagnostics.js";
|
|
78
83
|
export const LOG_ROTATE_BYTES = 5 * 1024 * 1024;
|
|
79
84
|
/** Exit code for "restart me": non-zero so every service manager relaunches (Windows tasks only restart on failure). */
|
|
@@ -988,6 +993,8 @@ export async function runDaemon(opts) {
|
|
|
988
993
|
let supervisor = null;
|
|
989
994
|
// One registry request per 30-second tick decides every timed daemon flag.
|
|
990
995
|
// The same request also refreshes the state file hooks read (state-file.ts).
|
|
996
|
+
// Each session-and-error pair is logged once, not on every 30-second write.
|
|
997
|
+
const lanesMonitorSessionErrors = new Set();
|
|
991
998
|
const stateWriter = createDaemonStateWriter({
|
|
992
999
|
file: daemonStateFilePath(home, env),
|
|
993
1000
|
defaultFile: defaultDaemonStateFilePath(home, env),
|
|
@@ -1000,7 +1007,57 @@ export async function runDaemon(opts) {
|
|
|
1000
1007
|
...selfCheckMachineChecks(readSelfCheckResult(path.join(paths.root, SELF_CHECK_RESULT_FILE))),
|
|
1001
1008
|
...readMachineCheckResults(path.join(paths.root, MACHINE_CHECKS_RESULT_FILE)),
|
|
1002
1009
|
],
|
|
1010
|
+
// What `hq lanes monitor-check` would answer, so the UserPromptSubmit hook
|
|
1011
|
+
// starts no program. No configured, existing HQ root: no section.
|
|
1012
|
+
readLanesMonitor: () => {
|
|
1013
|
+
const configured = readDaemonConfig(paths.configPath).hqRoot ?? (env.HQ_ROOT?.trim() || undefined);
|
|
1014
|
+
if (!configured || !fs.existsSync(configured))
|
|
1015
|
+
return null;
|
|
1016
|
+
return computeLanesMonitorSection({
|
|
1017
|
+
hqRoot: configured,
|
|
1018
|
+
now: new Date(),
|
|
1019
|
+
homedir: () => home,
|
|
1020
|
+
env,
|
|
1021
|
+
onSessionError: (sessionId, error) => {
|
|
1022
|
+
const key = `${sessionId}:${error instanceof Error ? error.name : "UnknownError"}`;
|
|
1023
|
+
if (lanesMonitorSessionErrors.has(key))
|
|
1024
|
+
return;
|
|
1025
|
+
if (lanesMonitorSessionErrors.size >= 256)
|
|
1026
|
+
lanesMonitorSessionErrors.clear();
|
|
1027
|
+
lanesMonitorSessionErrors.add(key);
|
|
1028
|
+
log("warn", `state file: lanes_monitor left out a session whose Monitor evidence could not be read (${key})`);
|
|
1029
|
+
},
|
|
1030
|
+
});
|
|
1031
|
+
},
|
|
1032
|
+
readMergeSections: () => mergeSections.latest(),
|
|
1033
|
+
});
|
|
1034
|
+
// The merge sections the native merge check reads are refused past 60 s, so
|
|
1035
|
+
// they are rebuilt every 15 s and the state file is rewritten each time,
|
|
1036
|
+
// between the 30-second registry requests (merge-sections.ts).
|
|
1037
|
+
const mergeSections = startMergeSectionRefresh({
|
|
1038
|
+
hqRoot: () => readDaemonConfig(paths.configPath).hqRoot ?? (env.HQ_ROOT?.trim() || undefined),
|
|
1039
|
+
readFlag: createRegistryMergeFlagReader({ env }),
|
|
1040
|
+
onRefresh: () => stateWriter.refresh(),
|
|
1003
1041
|
});
|
|
1042
|
+
// The cached `hq whoami` answer CLI commands read instead of starting
|
|
1043
|
+
// `hq whoami` (whoami-cache.ts). The token caches it describes live under
|
|
1044
|
+
// this user's own home, so a daemon run for another home writes none.
|
|
1045
|
+
const whoamiCache = path.resolve(home) === path.resolve(os.homedir())
|
|
1046
|
+
? startWhoamiCacheWriter({
|
|
1047
|
+
home,
|
|
1048
|
+
env,
|
|
1049
|
+
log,
|
|
1050
|
+
build: async (readPersonUid) => {
|
|
1051
|
+
const [{ buildWhoamiIdentity }, { resolveCognitoTokenSource }, { loadCachedTokens }] = await Promise.all([
|
|
1052
|
+
import("../../utils/whoami-identity.js"),
|
|
1053
|
+
import("../../utils/cognito-session.js"),
|
|
1054
|
+
import("@indigoai-us/hq-cloud"),
|
|
1055
|
+
]);
|
|
1056
|
+
return buildWhoamiIdentity(resolveCognitoTokenSource(env) === "machine", loadCachedTokens(), readPersonUid);
|
|
1057
|
+
},
|
|
1058
|
+
lookupPersonUid: async (token) => (await import("../../commands/whoami.js")).readPersonUid(token),
|
|
1059
|
+
})
|
|
1060
|
+
: null;
|
|
1004
1061
|
// The hqd listener checks again when a shared read's HQ Anywhere answer
|
|
1005
1062
|
// changes, or the running server's runtime gate changes; it has no timer of
|
|
1006
1063
|
// its own beyond a rare fallback (anywhere-listener.ts).
|
|
@@ -1030,6 +1087,17 @@ export async function runDaemon(opts) {
|
|
|
1030
1087
|
let laneReconcileWatcher = null;
|
|
1031
1088
|
let laneReconcileWatcherRoot = null;
|
|
1032
1089
|
let laneReconcileWatchFailedRoot = null;
|
|
1090
|
+
// The watcher's reconcile has no planned unit; its last outcome is added to
|
|
1091
|
+
// the state file so `hq daemon status` has a line for it.
|
|
1092
|
+
let lastPlanSignedIn = false;
|
|
1093
|
+
let lastPlanServices = [];
|
|
1094
|
+
const writeDaemonState = (state) => writeJsonAtomic(paths.statePath, withLanesReconcileUnit(state, laneReconcileWatcher ? laneReconcileStatus.unit(lastPlanSignedIn) : null, lastPlanServices));
|
|
1095
|
+
const laneReconcileStatus = createLanesReconcileStatus({
|
|
1096
|
+
onChange: () => {
|
|
1097
|
+
if (supervisor && laneReconcileWatcher)
|
|
1098
|
+
writeDaemonState(supervisor.state());
|
|
1099
|
+
},
|
|
1100
|
+
});
|
|
1033
1101
|
let laneReconcileHandlerLoadInFlight = false;
|
|
1034
1102
|
let laneReconcileHandlerLoadFailed = false;
|
|
1035
1103
|
const loadLaneReconcileHandler = (initialRoot) => {
|
|
@@ -1089,20 +1157,39 @@ export async function runDaemon(opts) {
|
|
|
1089
1157
|
}),
|
|
1090
1158
|
log: message => log("warn", message),
|
|
1091
1159
|
});
|
|
1092
|
-
|
|
1160
|
+
// Request notes hq-hook leaves on PostToolUse (hook-requests.ts): same lease, same stop signal, this daemon's HQ root only.
|
|
1161
|
+
const hookRequestDrainer = startHookRequestDrainer({
|
|
1162
|
+
home,
|
|
1163
|
+
root: () => readDaemonConfig(paths.configPath).hqRoot ?? env.HQ_ROOT,
|
|
1164
|
+
ownsQueue: ownsStopQueue,
|
|
1165
|
+
execute: request => executeHookRequest(request, {
|
|
1166
|
+
nodeBinary: opts.nodeBinary,
|
|
1167
|
+
hqBinary: opts.hqBinary,
|
|
1168
|
+
allowedRoot: readDaemonConfig(paths.configPath).hqRoot ?? env.HQ_ROOT,
|
|
1169
|
+
env,
|
|
1170
|
+
signal: stopJobAbort.signal,
|
|
1171
|
+
}),
|
|
1172
|
+
log: message => log("warn", message),
|
|
1173
|
+
});
|
|
1174
|
+
/** Closes the watchers; the promise settles once the Stop job or hook request in progress (if any) has finished. */
|
|
1093
1175
|
const closeRuntimeWatchers = () => {
|
|
1094
1176
|
if (stopDiagnosticRoot)
|
|
1095
1177
|
closeStopDiagnosticCursor(stopDiagnosticRoot);
|
|
1096
1178
|
clearInterval(stopDiagnosticTimer);
|
|
1097
1179
|
stopJobAbort.abort();
|
|
1098
|
-
const stopJobsClosed =
|
|
1180
|
+
const stopJobsClosed = Promise.all([
|
|
1181
|
+
stopJobDrainer.close().catch((err) => log("warn", `Stop job drainer did not close cleanly: ${String(err)}`)),
|
|
1182
|
+
hookRequestDrainer.close().catch((err) => log("warn", `Hook request drainer did not close cleanly: ${String(err)}`)),
|
|
1183
|
+
]).then(() => undefined);
|
|
1099
1184
|
laneReconcileWatcher?.close();
|
|
1100
1185
|
laneReconcileWatcher = null;
|
|
1101
1186
|
laneReconcileWatcherRoot = null;
|
|
1102
1187
|
killSwitches.close();
|
|
1103
1188
|
machineChecks.close();
|
|
1104
1189
|
flagSnapshots.close();
|
|
1190
|
+
mergeSections.close();
|
|
1105
1191
|
stateWriter.close();
|
|
1192
|
+
whoamiCache?.close();
|
|
1106
1193
|
return stopJobsClosed;
|
|
1107
1194
|
};
|
|
1108
1195
|
const plan = () => {
|
|
@@ -1136,9 +1223,10 @@ export async function runDaemon(opts) {
|
|
|
1136
1223
|
try {
|
|
1137
1224
|
for (const directory of laneDirectories)
|
|
1138
1225
|
fs.mkdirSync(directory, { recursive: true, mode: 0o700 });
|
|
1226
|
+
laneReconcileStatus.reset();
|
|
1139
1227
|
laneReconcileWatcher = createLanesReconcileWatcher({
|
|
1140
1228
|
directories: laneDirectories,
|
|
1141
|
-
reconcile: laneReconcileHandler,
|
|
1229
|
+
reconcile: laneReconcileStatus.track(laneReconcileHandler),
|
|
1142
1230
|
intervalMs: 15_000,
|
|
1143
1231
|
onError: (error) => log("error", `in-process lanes reconcile failed: ${error instanceof Error ? error.message : String(error)}`),
|
|
1144
1232
|
onWatchError: (error) => {
|
|
@@ -1280,6 +1368,8 @@ export async function runDaemon(opts) {
|
|
|
1280
1368
|
const runners = { ...packageRunners, syncRunner: syncSource.runnerPath };
|
|
1281
1369
|
const services = enabledServices(machineType, config);
|
|
1282
1370
|
const isSignedIn = signedIn(env, home, log);
|
|
1371
|
+
lastPlanSignedIn = isSignedIn;
|
|
1372
|
+
lastPlanServices = services;
|
|
1283
1373
|
const syncOwner = effectiveSyncOwner(config, machineType);
|
|
1284
1374
|
let syncRunnerProcesses = [];
|
|
1285
1375
|
let syncRunnerOwnerPid = null;
|
|
@@ -1327,6 +1417,7 @@ export async function runDaemon(opts) {
|
|
|
1327
1417
|
signedIn: isSignedIn,
|
|
1328
1418
|
kitConfigured: fs.existsSync(agentKitPaths(home, env).kitConfigPath),
|
|
1329
1419
|
syncPaused: config.syncPaused === true,
|
|
1420
|
+
syncCorePause: config.syncCorePause,
|
|
1330
1421
|
vaultSync: (() => {
|
|
1331
1422
|
const switches = readVaultSyncSwitches(home);
|
|
1332
1423
|
// Log once per change, not every reconcile.
|
|
@@ -1515,6 +1606,20 @@ export async function runDaemon(opts) {
|
|
|
1515
1606
|
plan,
|
|
1516
1607
|
spawn: spawnUnit,
|
|
1517
1608
|
runInternal: async (task) => {
|
|
1609
|
+
if (task === "lanes-reconcile") {
|
|
1610
|
+
// The timed unit only exists while the lane-store watcher is not
|
|
1611
|
+
// running; it reconciles here instead of starting `hq` (US-036).
|
|
1612
|
+
const currentRoot = () => {
|
|
1613
|
+
const configured = readDaemonConfig(paths.configPath).hqRoot ?? (env.HQ_ROOT?.trim() || undefined);
|
|
1614
|
+
return configured && fs.existsSync(configured) ? configured : undefined;
|
|
1615
|
+
};
|
|
1616
|
+
const root = currentRoot();
|
|
1617
|
+
if (!root)
|
|
1618
|
+
throw new Error("lanes reconcile has no HQ folder");
|
|
1619
|
+
// The reconciler is registered once and keeps this resolver, so it follows a later HQ folder change.
|
|
1620
|
+
await runDaemonLanesReconcileInProcess({ hqRoot: () => currentRoot() ?? root, env });
|
|
1621
|
+
return true;
|
|
1622
|
+
}
|
|
1518
1623
|
if (task !== "rotate-logs")
|
|
1519
1624
|
throw new Error(`unknown internal task ${task}`);
|
|
1520
1625
|
const n = rotateLogs(paths.logsDir);
|
|
@@ -1528,7 +1633,7 @@ export async function runDaemon(opts) {
|
|
|
1528
1633
|
},
|
|
1529
1634
|
restartDaemon: () => restartDaemon(),
|
|
1530
1635
|
runGuard: daemonRunGuard,
|
|
1531
|
-
writeState:
|
|
1636
|
+
writeState: writeDaemonState,
|
|
1532
1637
|
holds: {
|
|
1533
1638
|
read: () => readUnitHolds(paths.holdsPath),
|
|
1534
1639
|
write: (holds) => writeUnitHolds(paths.holdsPath, holds),
|
|
@@ -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,23 +673,22 @@ 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 }
|
|
728
685
|
: { code: "internal", message: err instanceof Error ? err.message : String(err) };
|
|
729
|
-
if (error.code === "
|
|
686
|
+
if (error.code === "hq_root_unreadable") {
|
|
687
|
+
// Not a daemon bug (macOS privacy permission), so no error report,
|
|
688
|
+
// but it must stay visible in the daemon log.
|
|
689
|
+
log("warn", `hqd ${req.op} failed: ${error.message}`);
|
|
690
|
+
}
|
|
691
|
+
else if (error.code === "internal") {
|
|
730
692
|
log("error", `hqd ${req.op} failed: ${error.message}`);
|
|
731
693
|
try {
|
|
732
694
|
opts.reportError?.(req.op, err);
|
|
@@ -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
|
/**
|