@indigoai-us/hq-cli 5.345.236 → 5.345.238
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 +46 -0
- package/dist/command-catalog.generated.d.ts +1 -1
- package/dist/command-catalog.generated.js +1 -1
- package/dist/commands/bot.d.ts +2 -0
- package/dist/commands/bot.js +32 -0
- package/dist/commands/daemon.d.ts +1 -0
- package/dist/commands/daemon.js +70 -6
- package/dist/commands/deploy-app-db.js +4 -19
- package/dist/commands/deploy-app-upload.js +66 -40
- package/dist/commands/deploy-mutations.js +24 -16
- package/dist/commands/deploy-runtime-bindings.js +7 -26
- package/dist/commands/deploy-ssr.js +5 -24
- package/dist/commands/mesh.js +6 -2
- package/dist/commands/signals-run.d.ts +43 -2
- package/dist/commands/signals-run.js +85 -7
- package/dist/commands/sync-core.d.ts +7 -0
- package/dist/commands/sync-core.js +52 -3
- package/dist/lib/agent-kit/inbox-state.d.ts +2 -1
- package/dist/lib/agent-kit/inbox-state.js +27 -3
- package/dist/lib/bot/continuity.d.ts +21 -2
- package/dist/lib/bot/continuity.js +48 -19
- package/dist/lib/bot/fleet-cron.js +6 -0
- package/dist/lib/bot/fleet-local.d.ts +11 -1
- package/dist/lib/bot/fleet-local.js +21 -1
- package/dist/lib/bot/fleet-state.d.ts +129 -0
- package/dist/lib/bot/fleet-state.js +669 -0
- package/dist/lib/bot/promote.d.ts +32 -3
- package/dist/lib/bot/promote.js +188 -16
- package/dist/lib/bot/promotion-hold-reconcile.d.ts +56 -0
- package/dist/lib/bot/promotion-hold-reconcile.js +155 -0
- package/dist/lib/daemon/catalog.d.ts +13 -0
- package/dist/lib/daemon/catalog.js +32 -6
- package/dist/lib/daemon/lanes-reconcile-status.d.ts +0 -4
- package/dist/lib/daemon/lanes-reconcile-status.js +2 -12
- package/dist/lib/daemon/lanes-reconcile-watcher.d.ts +1 -1
- package/dist/lib/daemon/lanes-reconcile-watcher.js +2 -1
- package/dist/lib/daemon/legacy-handover.d.ts +38 -0
- package/dist/lib/daemon/legacy-handover.js +117 -0
- package/dist/lib/daemon/mesh-owner.js +2 -1
- package/dist/lib/daemon/run.d.ts +35 -2
- package/dist/lib/daemon/run.js +108 -15
- package/dist/lib/daemon/selfcheck.d.ts +28 -0
- package/dist/lib/daemon/selfcheck.js +86 -15
- package/dist/lib/deploy-api.d.ts +1 -1
- package/dist/lib/deploy-api.js +2 -1
- package/dist/lib/deploy-identity.d.ts +18 -0
- package/dist/lib/deploy-identity.js +179 -0
- package/dist/lib/hot-channels/alert.js +13 -6
- package/dist/lib/hot-channels/fleet-complete.d.ts +89 -0
- package/dist/lib/hot-channels/fleet-complete.js +157 -0
- package/dist/lib/hot-channels/run.js +2 -1
- package/dist/lib/hot-channels/signals-claude-login.d.ts +3 -2
- package/dist/lib/hot-channels/signals-claude-login.js +6 -1
- package/dist/lib/hot-channels/signals-pass-failure.d.ts +29 -0
- package/dist/lib/hot-channels/signals-pass-failure.js +36 -0
- package/dist/lib/hot-channels/signals-pass.d.ts +49 -2
- package/dist/lib/hot-channels/signals-pass.js +188 -12
- package/dist/lib/hot-channels/signals-runtime.d.ts +6 -3
- package/dist/lib/hot-channels/signals-runtime.js +11 -2
- package/dist/lib/lanes/reconcile-result.d.ts +5 -0
- package/dist/lib/lanes/reconcile-result.js +20 -2
- package/dist/lib/lanes/reconcile.js +12 -3
- package/dist/lib/mesh/live/emit.js +25 -6
- package/dist/lib/mesh/live/flush.js +119 -15
- package/dist/lib/mesh/live/reporting-privacy.d.ts +41 -0
- package/dist/lib/mesh/live/reporting-privacy.js +147 -1
- package/dist/lib/mesh/live/spool.d.ts +16 -0
- package/dist/lib/mesh/live/spool.js +45 -0
- package/dist/lib/signals/engine.d.ts +17 -3
- package/dist/lib/signals/engine.js +28 -9
- package/dist/lib/signals/failure-alert.d.ts +33 -1
- package/dist/lib/signals/failure-alert.js +72 -5
- package/dist/lib/signals/owner-notice.d.ts +94 -0
- package/dist/lib/signals/owner-notice.js +233 -0
- package/dist/lib/signals/reply.d.ts +7 -0
- package/dist/lib/signals/reply.js +23 -3
- package/dist/lib/signals/steps/adapters.d.ts +51 -2
- package/dist/lib/signals/steps/adapters.js +213 -7
- package/dist/lib/signals/steps/extract.js +18 -4
- package/dist/lib/signals/steps/types.d.ts +63 -1
- package/dist/lib/signals/steps/types.js +32 -0
- package/dist/lib/sync-core/engine-auth.d.ts +35 -0
- package/dist/lib/sync-core/engine-auth.js +96 -0
- package/dist/lib/sync-core/engine-home.d.ts +6 -0
- package/dist/lib/sync-core/engine-home.js +12 -0
- package/dist/lib/sync-core/rollout-state.d.ts +1 -0
- package/dist/lib/sync-core/rollout-state.js +3 -0
- package/dist/lib/vault-sync-switches.d.ts +7 -0
- package/dist/lib/vault-sync-switches.js +56 -0
- package/dist/lib/work-context/errors.d.ts +12 -0
- package/dist/lib/work-context/errors.js +15 -0
- package/dist/lib/work-context/organize.js +6 -1
- package/dist/lib/work-context/reconcile.js +20 -1
- package/dist/utils/resident-package-preload.js +34 -4
- package/docs/anywhere-runtime.md +6 -0
- package/package.json +7 -7
|
@@ -83,15 +83,18 @@ export const DEFAULT_SERVICES = {
|
|
|
83
83
|
};
|
|
84
84
|
/** Services another enabled service turns on; only an explicit disable keeps them off. */
|
|
85
85
|
export const IMPLIED_SERVICES = { mesh: "sync-core" };
|
|
86
|
+
/** Services that run whenever a vault is on the new sync engine here, whatever the config says. */
|
|
87
|
+
export const ENGINE_REQUIRED_SERVICES = ["mesh"];
|
|
86
88
|
/** Defaults plus this host's overrides, in catalog order. Unknown names are ignored. */
|
|
87
|
-
export function enabledServices(machineType, overrides) {
|
|
89
|
+
export function enabledServices(machineType, overrides, opts = {}) {
|
|
88
90
|
const defaults = DEFAULT_SERVICES[machineType];
|
|
89
91
|
const wanted = (s) => (defaults.includes(s) || overrides.enable.includes(s)) && !overrides.disable.includes(s);
|
|
90
92
|
const implied = (s) => {
|
|
91
93
|
const by = IMPLIED_SERVICES[s];
|
|
92
94
|
return by !== undefined && wanted(by) && !overrides.disable.includes(s);
|
|
93
95
|
};
|
|
94
|
-
|
|
96
|
+
const engines = (opts.engineVaults ?? 0) > 0 && wanted("sync-core");
|
|
97
|
+
return SERVICE_NAMES.filter((s) => wanted(s) || implied(s) || (engines && ENGINE_REQUIRED_SERVICES.includes(s)));
|
|
95
98
|
}
|
|
96
99
|
/**
|
|
97
100
|
* Why the daemon schedules no search-index pass. The timer never starts `hq`
|
|
@@ -113,6 +116,9 @@ export const SYNC_CORE_SELFCHECK_UNIT = "sync-core-selfcheck";
|
|
|
113
116
|
export const SYNC_CORE_SELFCHECK_INTERVAL_SEC = 3600;
|
|
114
117
|
export const SYNC_CORE_MANIFEST_INTERVAL_SEC = 24 * 3600;
|
|
115
118
|
export const SYNC_CORE_LEGACY_SETTLE_MS = 10 * 60 * 1000;
|
|
119
|
+
/** How long an engine may wait for the old sync to restart before status and the self-check call it stuck. */
|
|
120
|
+
export const LEGACY_HANDOVER_STUCK_AFTER_MS = 10 * 60 * 1000;
|
|
121
|
+
export const LEGACY_HANDOVER_STUCK_PREFIX = "stuck: waiting over 10 minutes for the running sync";
|
|
116
122
|
function base(service, over = {}) {
|
|
117
123
|
return {
|
|
118
124
|
id: service,
|
|
@@ -153,6 +159,26 @@ export const CLAUDE_RUNNER_SCRIPT = "/usr/local/bin/outpost-runner.sh";
|
|
|
153
159
|
const NO_HQ_ROOT = "no HQ folder configured (run `hq daemon install --hq-root <path>`)";
|
|
154
160
|
export const NOT_SIGNED_IN = "not signed in (run `hq login`)";
|
|
155
161
|
const KIT_NOT_SET_UP = "the agent kit is not set up on this machine (run `hq agent kit install`)";
|
|
162
|
+
function isoSeconds(ms) {
|
|
163
|
+
return new Date(ms).toISOString().replace(/\.\d{3}Z$/, "Z");
|
|
164
|
+
}
|
|
165
|
+
function legacySyncOffFor(vault, vaultSync) {
|
|
166
|
+
return vault.kind === "personal"
|
|
167
|
+
? vaultSync?.personalOff === true
|
|
168
|
+
: vaultSync?.offCompanies.has(vault.slug ?? "") === true;
|
|
169
|
+
}
|
|
170
|
+
function stuckHandoverReason(what, offSince, holder, stopRequestedAt) {
|
|
171
|
+
const who = `${holder.owner ? `${holder.owner} ` : ""}${holder.pid !== undefined ? `pid ${holder.pid}, ` : ""}started ${isoSeconds(holder.startedAt)}`;
|
|
172
|
+
const asked = stopRequestedAt !== undefined ? `; HQ asked it to stop at ${isoSeconds(stopRequestedAt)}` : "";
|
|
173
|
+
return `${LEGACY_HANDOVER_STUCK_PREFIX} (started before the switch was turned off for ${what} at ${isoSeconds(offSince)}; ${who}) to restart${asked}. ` +
|
|
174
|
+
"Check that the HQ desktop app is open with Auto-sync on, then run `hq daemon status`";
|
|
175
|
+
}
|
|
176
|
+
const LEGACY_RESTART_WAIT_PREFIX = "waiting for the running sync (started before the switch was turned off for ";
|
|
177
|
+
/** True only when an engine unit's one remaining block is an old runner that has to restart. */
|
|
178
|
+
export function isLegacyRestartWait(block) {
|
|
179
|
+
return block?.state === "waiting"
|
|
180
|
+
&& (block.reason.startsWith(LEGACY_RESTART_WAIT_PREFIX) || block.reason.startsWith(LEGACY_HANDOVER_STUCK_PREFIX));
|
|
181
|
+
}
|
|
156
182
|
function syncOwnerBlock(ctx) {
|
|
157
183
|
if (ctx.machineType === "desktop" && ctx.syncOwner === "desktop-app" && ctx.desktopAppManagesSync) {
|
|
158
184
|
return "the desktop app is still managing sync (run `hq daemon sync take-ownership` after it stops its runner)";
|
|
@@ -245,9 +271,7 @@ function planService(service, ctx) {
|
|
|
245
271
|
const now = ctx.now ?? Date.now();
|
|
246
272
|
const engines = (ctx.syncCoreVaults ?? []).map((vault) => {
|
|
247
273
|
const full = vault.phase === "full";
|
|
248
|
-
const legacyOff = vault.
|
|
249
|
-
? ctx.vaultSync?.personalOff === true
|
|
250
|
-
: ctx.vaultSync?.offCompanies.has(vault.slug ?? "") === true;
|
|
274
|
+
const legacyOff = legacySyncOffFor(vault, ctx.vaultSync);
|
|
251
275
|
const offSince = vault.legacyOffSince ? Date.parse(vault.legacyOffSince) : Number.NaN;
|
|
252
276
|
const settled = Number.isFinite(offSince) && now - offSince >= SYNC_CORE_LEGACY_SETTLE_MS;
|
|
253
277
|
const settleNeeded = ctx.legacySyncHolder !== undefined
|
|
@@ -262,7 +286,9 @@ function planService(service, ctx) {
|
|
|
262
286
|
: holder.status === "unreadable"
|
|
263
287
|
? "waiting to learn when the sync that holds the sync lock started (its owner status could not be read)"
|
|
264
288
|
: !Number.isFinite(offSince) || holder.startedAt < offSince
|
|
265
|
-
?
|
|
289
|
+
? Number.isFinite(offSince) && legacyOff && now - offSince >= LEGACY_HANDOVER_STUCK_AFTER_MS
|
|
290
|
+
? stuckHandoverReason(what, offSince, holder, ctx.legacyHandoverStopRequestedAt)
|
|
291
|
+
: `waiting for the running sync (started before the switch was turned off for ${what}) to restart`
|
|
266
292
|
: undefined;
|
|
267
293
|
return base(service, {
|
|
268
294
|
id: syncCoreUnitId(vault.uid),
|
|
@@ -8,10 +8,6 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import type { DaemonState } from "./supervisor.js";
|
|
10
10
|
type Unit = DaemonState["units"][number];
|
|
11
|
-
/** The longest `lastError` written to the state file, in UTF-8 bytes. */
|
|
12
|
-
export declare const LANES_RECONCILE_ERROR_BYTES = 300;
|
|
13
|
-
/** One line, no secrets, no control characters (it is printed to a terminal), at most LANES_RECONCILE_ERROR_BYTES. */
|
|
14
|
-
export declare function lanesReconcileErrorText(error: unknown): string;
|
|
15
11
|
export interface LanesReconcileStatus {
|
|
16
12
|
/** The same reconcile, with its outcome recorded. A failure is rethrown. */
|
|
17
13
|
track(reconcile: () => Promise<void>): () => Promise<void>;
|
|
@@ -6,19 +6,9 @@
|
|
|
6
6
|
* the outcome of each watcher run and adds one unit entry to the state file
|
|
7
7
|
* `hq daemon status` reads.
|
|
8
8
|
*/
|
|
9
|
-
import {
|
|
10
|
-
import { redactSecrets } from "../db/redact.js";
|
|
9
|
+
import { reconcileFailureText } from "../lanes/reconcile-result.js";
|
|
11
10
|
import { NOT_SIGNED_IN, SERVICE_DESCRIPTIONS } from "./catalog.js";
|
|
12
|
-
import { cutUtf8 } from "./state-file.js";
|
|
13
|
-
/** The longest `lastError` written to the state file, in UTF-8 bytes. */
|
|
14
|
-
export const LANES_RECONCILE_ERROR_BYTES = 300;
|
|
15
11
|
const UNIT_ID = "lanes-reconcile";
|
|
16
|
-
/** One line, no secrets, no control characters (it is printed to a terminal), at most LANES_RECONCILE_ERROR_BYTES. */
|
|
17
|
-
export function lanesReconcileErrorText(error) {
|
|
18
|
-
const raw = error instanceof Error ? error.message : String(error);
|
|
19
|
-
const oneLine = redactSecrets(redactForLog(raw)).replace(/\p{Cc}+/gu, " ").replace(/\s+/g, " ").trim();
|
|
20
|
-
return cutUtf8(oneLine, LANES_RECONCILE_ERROR_BYTES);
|
|
21
|
-
}
|
|
22
12
|
export function createLanesReconcileStatus(options = {}) {
|
|
23
13
|
const now = options.now ?? Date.now;
|
|
24
14
|
let lastRunAt;
|
|
@@ -34,7 +24,7 @@ export function createLanesReconcileStatus(options = {}) {
|
|
|
34
24
|
}
|
|
35
25
|
catch (error) {
|
|
36
26
|
lastResult = "failed";
|
|
37
|
-
lastError =
|
|
27
|
+
lastError = reconcileFailureText(error);
|
|
38
28
|
throw error;
|
|
39
29
|
}
|
|
40
30
|
finally {
|
|
@@ -10,7 +10,7 @@ export declare function createLanesReconcileWatcher(options: {
|
|
|
10
10
|
debounceMs?: number;
|
|
11
11
|
intervalMs?: number;
|
|
12
12
|
watch?: (directory: string, listener: (event: string, filename: string | Buffer | null) => void) => Watcher;
|
|
13
|
-
onError?: (error:
|
|
13
|
+
onError?: (error: Error) => void;
|
|
14
14
|
onWatchError?: (error: unknown) => void;
|
|
15
15
|
}): LanesReconcileWatcher;
|
|
16
16
|
export {};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as fs from "node:fs";
|
|
2
|
+
import { reconcileFailureText } from "../lanes/reconcile-result.js";
|
|
2
3
|
/** Reconcile at startup, on lane-store changes, and on a bounded in-process timer. */
|
|
3
4
|
export function createLanesReconcileWatcher(options) {
|
|
4
5
|
const debounceMs = options.debounceMs ?? 250;
|
|
@@ -21,7 +22,7 @@ export function createLanesReconcileWatcher(options) {
|
|
|
21
22
|
await options.reconcile();
|
|
22
23
|
}
|
|
23
24
|
catch (error) {
|
|
24
|
-
options.onError?.(error);
|
|
25
|
+
options.onError?.(new Error(reconcileFailureText(error)));
|
|
25
26
|
}
|
|
26
27
|
finally {
|
|
27
28
|
running = false;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/** Asks an old sync runner started before a vault's switch changed to stop (SIGTERM, never SIGKILL, never on Windows) so its owner relaunches it with the current skip list. */
|
|
2
|
+
import { type LegacySyncHolder } from "./catalog.js";
|
|
3
|
+
export declare const LEGACY_HANDOVER_RESIGNAL_AFTER_MS: number;
|
|
4
|
+
export declare const LEGACY_HANDOVER_STUCK_FILE = "legacy-handover.json";
|
|
5
|
+
export type LegacyHandoverOutcome = "signalled" | "already-signalled" | "own-runner" | "no-pid" | "not-running" | "not-a-sync-runner" | "unsupported-platform" | "signal-failed";
|
|
6
|
+
export interface LegacyHandoverStuck {
|
|
7
|
+
what: string;
|
|
8
|
+
since: number;
|
|
9
|
+
reason: string;
|
|
10
|
+
}
|
|
11
|
+
export interface LegacyHandoverDeps {
|
|
12
|
+
now: () => number;
|
|
13
|
+
selfPid: number;
|
|
14
|
+
isAlive: (pid: number) => boolean;
|
|
15
|
+
commandLine: (pid: number) => string | null;
|
|
16
|
+
signal: (pid: number, signal: "SIGTERM") => void;
|
|
17
|
+
/** Windows has no graceful SIGTERM: process.kill ends the runner at once, possibly mid-replace. */
|
|
18
|
+
platform?: NodeJS.Platform;
|
|
19
|
+
/** Persist the restore waits that passed the bound, for status and the self-check. */
|
|
20
|
+
writeRestoreStuck?: (stuck: LegacyHandoverStuck[]) => void;
|
|
21
|
+
log: (level: "info" | "warn", message: string) => void;
|
|
22
|
+
}
|
|
23
|
+
export interface LegacyHandover {
|
|
24
|
+
request(holder: Extract<LegacySyncHolder, {
|
|
25
|
+
status: "started";
|
|
26
|
+
}>, vaults: readonly string[]): LegacyHandoverOutcome;
|
|
27
|
+
/** When the current holder was last asked to stop, if it was. */
|
|
28
|
+
requestedAt(holder: LegacySyncHolder | undefined): number | undefined;
|
|
29
|
+
/** Record vaults switched back on that the running old sync still skips. */
|
|
30
|
+
reportRestoreWaits(holder: LegacySyncHolder | undefined, waits: readonly {
|
|
31
|
+
what: string;
|
|
32
|
+
since: number;
|
|
33
|
+
}[]): void;
|
|
34
|
+
}
|
|
35
|
+
export declare function createLegacyHandover(deps: LegacyHandoverDeps): LegacyHandover;
|
|
36
|
+
export declare function writeLegacyHandoverStuck(file: string, stuck: readonly LegacyHandoverStuck[], now?: number): void;
|
|
37
|
+
export declare function readLegacyHandoverStuck(file: string): LegacyHandoverStuck[];
|
|
38
|
+
//# sourceMappingURL=legacy-handover.d.ts.map
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/** Asks an old sync runner started before a vault's switch changed to stop (SIGTERM, never SIGKILL, never on Windows) so its owner relaunches it with the current skip list. */
|
|
2
|
+
import * as fs from "node:fs";
|
|
3
|
+
import * as path from "node:path";
|
|
4
|
+
import { LEGACY_HANDOVER_STUCK_AFTER_MS } from "./catalog.js";
|
|
5
|
+
import { SYNC_RUNNER_OWNER, isSyncRunnerCommandLine } from "./sync-runner.js";
|
|
6
|
+
export const LEGACY_HANDOVER_RESIGNAL_AFTER_MS = 5 * 60_000;
|
|
7
|
+
const FORGET_AFTER_MS = 6 * 60 * 60_000;
|
|
8
|
+
export const LEGACY_HANDOVER_STUCK_FILE = "legacy-handover.json";
|
|
9
|
+
function holderKey(holder) {
|
|
10
|
+
return `${holder.pid ?? "?"}@${holder.startedAt}`;
|
|
11
|
+
}
|
|
12
|
+
function isoSeconds(ms) {
|
|
13
|
+
return new Date(ms).toISOString().replace(/\.\d{3}Z$/, "Z");
|
|
14
|
+
}
|
|
15
|
+
export function createLegacyHandover(deps) {
|
|
16
|
+
const sent = new Map();
|
|
17
|
+
const refused = new Map();
|
|
18
|
+
let lastStuck = "[]";
|
|
19
|
+
const prune = (now) => {
|
|
20
|
+
for (const map of [sent, refused]) {
|
|
21
|
+
for (const [key, at] of map)
|
|
22
|
+
if (now - at > FORGET_AFTER_MS)
|
|
23
|
+
map.delete(key);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
const requestedAt = (holder) => holder?.status === "started" ? sent.get(holderKey(holder)) : undefined;
|
|
27
|
+
return {
|
|
28
|
+
requestedAt,
|
|
29
|
+
request(holder, vaults) {
|
|
30
|
+
const key = holderKey(holder);
|
|
31
|
+
const now = deps.now();
|
|
32
|
+
prune(now);
|
|
33
|
+
if (holder.owner === SYNC_RUNNER_OWNER)
|
|
34
|
+
return "own-runner";
|
|
35
|
+
if (holder.pid === undefined || !Number.isInteger(holder.pid) || holder.pid <= 1 || holder.pid === deps.selfPid) {
|
|
36
|
+
return "no-pid";
|
|
37
|
+
}
|
|
38
|
+
if (deps.platform === "win32")
|
|
39
|
+
return "unsupported-platform";
|
|
40
|
+
const pid = holder.pid;
|
|
41
|
+
const last = sent.get(key);
|
|
42
|
+
if (last !== undefined && now - last < LEGACY_HANDOVER_RESIGNAL_AFTER_MS)
|
|
43
|
+
return "already-signalled";
|
|
44
|
+
if (!deps.isAlive(pid))
|
|
45
|
+
return "not-running";
|
|
46
|
+
const command = deps.commandLine(pid);
|
|
47
|
+
if (command === null || !isSyncRunnerCommandLine(command)) {
|
|
48
|
+
if (!refused.has(key)) {
|
|
49
|
+
refused.set(key, now);
|
|
50
|
+
deps.log("warn", `the sync lease names pid ${pid}, which is not a sync runner; leaving it alone`);
|
|
51
|
+
}
|
|
52
|
+
return "not-a-sync-runner";
|
|
53
|
+
}
|
|
54
|
+
try {
|
|
55
|
+
deps.signal(pid, "SIGTERM");
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
deps.log("warn", `could not ask the old sync runner (pid ${pid}) to restart: ${error.message}`);
|
|
59
|
+
return "signal-failed";
|
|
60
|
+
}
|
|
61
|
+
sent.set(key, now);
|
|
62
|
+
deps.log("info", `asked the old sync runner (${holder.owner ?? "unknown owner"}, pid ${pid}) to stop so its owner restarts it with the current sync switches for ${vaults.join(", ")}`);
|
|
63
|
+
return "signalled";
|
|
64
|
+
},
|
|
65
|
+
reportRestoreWaits(holder, waits) {
|
|
66
|
+
if (!deps.writeRestoreStuck)
|
|
67
|
+
return;
|
|
68
|
+
const now = deps.now();
|
|
69
|
+
const stuck = holder?.status !== "started"
|
|
70
|
+
? []
|
|
71
|
+
: waits.filter((wait) => now - wait.since >= LEGACY_HANDOVER_STUCK_AFTER_MS).map((wait) => {
|
|
72
|
+
const asked = requestedAt(holder);
|
|
73
|
+
const who = `${holder.owner ? `${holder.owner} ` : ""}${holder.pid !== undefined ? `pid ${holder.pid}, ` : ""}started ${isoSeconds(holder.startedAt)}`;
|
|
74
|
+
return {
|
|
75
|
+
what: wait.what,
|
|
76
|
+
since: wait.since,
|
|
77
|
+
reason: `stuck: the running sync (${who}) still skips ${wait.what}, whose switch HQ turned back on at ${isoSeconds(wait.since)}, so ${wait.what} has no sync until it restarts` +
|
|
78
|
+
`${asked !== undefined ? `; HQ asked it to stop at ${isoSeconds(asked)}` : ""}. Check that the HQ desktop app is open with Auto-sync on, or restart the app`,
|
|
79
|
+
};
|
|
80
|
+
});
|
|
81
|
+
const text = JSON.stringify(stuck);
|
|
82
|
+
if (text === lastStuck)
|
|
83
|
+
return;
|
|
84
|
+
try {
|
|
85
|
+
deps.writeRestoreStuck(stuck);
|
|
86
|
+
lastStuck = text;
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
deps.log("warn", `could not record the stuck sync handover: ${error.message}`);
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
export function writeLegacyHandoverStuck(file, stuck, now = Date.now()) {
|
|
95
|
+
if (stuck.length === 0) {
|
|
96
|
+
fs.rmSync(file, { force: true });
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
fs.mkdirSync(path.dirname(file), { recursive: true, mode: 0o700 });
|
|
100
|
+
const tmp = `${file}.${process.pid}.tmp`;
|
|
101
|
+
fs.writeFileSync(tmp, `${JSON.stringify({ checkedAt: now, stuck })}\n`, { mode: 0o600 });
|
|
102
|
+
fs.renameSync(tmp, file);
|
|
103
|
+
}
|
|
104
|
+
export function readLegacyHandoverStuck(file) {
|
|
105
|
+
let parsed;
|
|
106
|
+
try {
|
|
107
|
+
parsed = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
return [];
|
|
111
|
+
}
|
|
112
|
+
const stuck = parsed?.stuck;
|
|
113
|
+
if (!Array.isArray(stuck))
|
|
114
|
+
return [];
|
|
115
|
+
return stuck.filter((entry) => !!entry && typeof entry.what === "string" && typeof entry.reason === "string" && typeof entry.since === "number");
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=legacy-handover.js.map
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as fs from "node:fs";
|
|
2
2
|
import { enabledServices } from "./catalog.js";
|
|
3
|
+
import { engineVaultCount } from "../sync-core/rollout-state.js";
|
|
3
4
|
import { readDaemonConfig } from "./config.js";
|
|
4
5
|
import { hostedDaemonRunning, recentlyHostedDaemon } from "./handoff.js";
|
|
5
6
|
import { clearHealPending, healPending, homeIsLoginSafe, isLoginHome, jobLoadedFromHome, meshUnitFromOtherHome, removeMeshUnitFromOtherHome } from "../mesh/live/daemon/unit-home.js";
|
|
@@ -27,7 +28,7 @@ export function meshOwnerHere(home, env, deps = {}) {
|
|
|
27
28
|
existsSync: fs.existsSync,
|
|
28
29
|
readFileSync: (p) => fs.readFileSync(p, "utf8"),
|
|
29
30
|
}).type;
|
|
30
|
-
return enabledServices(machineType, config).includes("mesh") ? "hq-daemon" : "hq-daemon-mesh-off";
|
|
31
|
+
return enabledServices(machineType, config, { engineVaults: engineVaultCount(home) }).includes("mesh") ? "hq-daemon" : "hq-daemon-mesh-off";
|
|
31
32
|
}
|
|
32
33
|
function daemonRunsElsewhere(home, env) {
|
|
33
34
|
const paths = daemonPaths(home, env);
|
package/dist/lib/daemon/run.d.ts
CHANGED
|
@@ -6,10 +6,13 @@
|
|
|
6
6
|
* signing in takes effect without restarting the daemon.
|
|
7
7
|
*/
|
|
8
8
|
import { acquirePackageUseLease } from "../../utils/package-use-lease.js";
|
|
9
|
-
import { type
|
|
9
|
+
import { type PlanFleetBotsDeps } from "../bot/fleet-daemon.js";
|
|
10
|
+
import { type FleetBotPlan, type LegacySyncHolder, type PlanContext, type ServiceName, type UnitPlan } from "./catalog.js";
|
|
11
|
+
import { type LegacyHandover } from "./legacy-handover.js";
|
|
10
12
|
import { type SyncCoreVaultPlan } from "../sync-core/engine-home.js";
|
|
11
13
|
import { type DaemonFlagRegistryRead, type DaemonFlagSnapshotSource } from "./flag.js";
|
|
12
14
|
import { type LegacyUnit, type WindowsTaskOwner } from "./legacy.js";
|
|
15
|
+
import { type VaultSwitchOnTimes, type VaultSyncSwitches } from "../vault-sync-switches.js";
|
|
13
16
|
import { type DaemonLockResult } from "./lock.js";
|
|
14
17
|
import { removeMeshUnitFromOtherHome, type LaunchctlRunner } from "../mesh/live/daemon/unit-home.js";
|
|
15
18
|
import { type MeshUnitRepairResult } from "../mesh/live/daemon/install.js";
|
|
@@ -21,7 +24,21 @@ export declare const LOG_ROTATE_BYTES: number;
|
|
|
21
24
|
/** Exit code for "restart me": non-zero so every service manager relaunches (Windows tasks only restart on failure). */
|
|
22
25
|
export declare const RESTART_EXIT_CODE = 75;
|
|
23
26
|
export declare function syncCoreVaultPlans(home: string, hqRoot: string | undefined, platform: NodeJS.Platform): SyncCoreVaultPlan[];
|
|
24
|
-
export declare function planUnitsWithSyncCoreInterlock(services: readonly ServiceName[], context: PlanContext, supervisor: Pick<Supervisor, "runningPlanKey" | "state"> | null | undefined, readOwnerStatus: () => WatchRunnerOwnerStatus | null): UnitPlan[];
|
|
27
|
+
export declare function planUnitsWithSyncCoreInterlock(services: readonly ServiceName[], context: PlanContext, supervisor: Pick<Supervisor, "runningPlanKey" | "state"> | null | undefined, readOwnerStatus: () => WatchRunnerOwnerStatus | null, handover?: LegacyHandover, readSwitchOnTimes?: () => VaultSwitchOnTimes): UnitPlan[];
|
|
28
|
+
export interface LegacyRestoreWait {
|
|
29
|
+
what: string;
|
|
30
|
+
/** When HQ turned the vault's old-sync switch back on. */
|
|
31
|
+
since: number;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Vaults whose old-sync switch HQ turned back on (a rollback, or a held engine)
|
|
35
|
+
* after the running old sync started: that runner still skips them until it
|
|
36
|
+
* restarts, so they have no sync at all until then.
|
|
37
|
+
*/
|
|
38
|
+
export declare function legacyRestoreWaits(vaultSync: VaultSyncSwitches | undefined, onTimes: VaultSwitchOnTimes, holder: LegacySyncHolder | undefined, engineStillRunning?: {
|
|
39
|
+
personal: boolean;
|
|
40
|
+
companies: ReadonlySet<string>;
|
|
41
|
+
}): LegacyRestoreWait[];
|
|
25
42
|
export declare function legacySyncHeldByOtherOwner(units: DaemonState["units"], readOwnerStatus: () => WatchRunnerOwnerStatus | null): LegacySyncHolder | undefined;
|
|
26
43
|
/** A bounded shutdown deadline that can account for sync push persistence. */
|
|
27
44
|
export declare function createShutdownCap(): {
|
|
@@ -63,6 +80,7 @@ export declare function hqdListenerRuntimeAllowed(env: NodeJS.ProcessEnv, readSe
|
|
|
63
80
|
/** Route an updater request through the daemon's existing graceful handoff. */
|
|
64
81
|
export declare function handoffForPackageUpdateRequest(requested: boolean, restartDaemon: () => void): void;
|
|
65
82
|
export interface RunDaemonOptions {
|
|
83
|
+
legacyHandover?: LegacyHandover;
|
|
66
84
|
removeMeshUnitFromOtherHome?: typeof removeMeshUnitFromOtherHome;
|
|
67
85
|
isLoginHome?: (home: string) => boolean;
|
|
68
86
|
foreground?: boolean;
|
|
@@ -126,6 +144,21 @@ export declare function daemonInstantSyncEnabled(env: NodeJS.ProcessEnv, configu
|
|
|
126
144
|
* background service, so it is not one of them.
|
|
127
145
|
*/
|
|
128
146
|
export declare function listLocalBots(root?: string): string[];
|
|
147
|
+
/** The plan's bots. A signed-in pass also lets held bots whose move HQ cancelled
|
|
148
|
+
* free themselves, in the background and rate-limited per bot.
|
|
149
|
+
*/
|
|
150
|
+
export declare function daemonBotPlans(input: {
|
|
151
|
+
heldBots: {
|
|
152
|
+
kick(): Promise<void>;
|
|
153
|
+
};
|
|
154
|
+
signedIn: boolean;
|
|
155
|
+
services: readonly ServiceName[];
|
|
156
|
+
fleet: PlanFleetBotsDeps;
|
|
157
|
+
root?: string;
|
|
158
|
+
}): {
|
|
159
|
+
bots: string[];
|
|
160
|
+
fleetBots: FleetBotPlan[];
|
|
161
|
+
};
|
|
129
162
|
/** Whose task `taskName` is: only the current user's own task may be taken over. */
|
|
130
163
|
export declare function windowsTaskOwner(taskName: string): WindowsTaskOwner;
|
|
131
164
|
export declare function probeLegacyUnits(platform: NodeJS.Platform, home: string): LegacyUnit[];
|
package/dist/lib/daemon/run.js
CHANGED
|
@@ -23,14 +23,16 @@ import { isLocalDependencyInstall, resolveRunningInstall } from "../../utils/ver
|
|
|
23
23
|
import { agentKitPaths } from "../agent-kit/paths.js";
|
|
24
24
|
import { HQ_FLEET_RUNTIME_ENGINE_ID, readBotConfig } from "../bot/config.js";
|
|
25
25
|
import { clearStaleReadyBeforeGatewayStart, planFleetBots } from "../bot/fleet-daemon.js";
|
|
26
|
+
import { createHeldBotReconciler, heldBotThrottleDir } from "../bot/promotion-hold-reconcile.js";
|
|
26
27
|
import { botsRoot } from "../bot/paths.js";
|
|
27
|
-
import { CLAUDE_RUNNER_SCRIPT, CODEX_RUNNER_SCRIPT, enabledServices, planUnits, SEARCH_INDEX_WORKER_UNAVAILABLE } from "./catalog.js";
|
|
28
|
+
import { CLAUDE_RUNNER_SCRIPT, CODEX_RUNNER_SCRIPT, enabledServices, planUnits, SEARCH_INDEX_WORKER_UNAVAILABLE, isLegacyRestartWait } from "./catalog.js";
|
|
29
|
+
import { createLegacyHandover, LEGACY_HANDOVER_STUCK_FILE, writeLegacyHandoverStuck } from "./legacy-handover.js";
|
|
28
30
|
import { effectiveSyncOwner, readDaemonConfig } from "./config.js";
|
|
29
31
|
import { backgroundQosCommand } from "./background-qos.js";
|
|
30
32
|
import { serveQmdWorker } from "../search-index/worker-process.js";
|
|
31
33
|
import { inspectEngineHome } from "../sync-core/engine-home.js";
|
|
32
34
|
import { fullModeHold } from "../sync-core/reconcile.js";
|
|
33
|
-
import { readSyncCoreRolloutState } from "../sync-core/rollout-state.js";
|
|
35
|
+
import { engineVaultCount, readSyncCoreRolloutState } from "../sync-core/rollout-state.js";
|
|
34
36
|
import { effectiveEngineSettings, readSyncCoreVaultSettings } from "../sync-core/vault-settings.js";
|
|
35
37
|
import { assertPersonalServiceSessionCapability, readRemoteControlPoolsConfig, remoteControlPoolSecretsEnv, } from "./remote-control-pools.js";
|
|
36
38
|
import { loadLanesConfig } from "../lanes/config.js";
|
|
@@ -46,7 +48,7 @@ import { createLanesReconcileWatcher } from "./lanes-reconcile-watcher.js";
|
|
|
46
48
|
import { createLanesReconcileStatus, withLanesReconcileUnit } from "./lanes-reconcile-status.js";
|
|
47
49
|
import { findLegacyUnits, legacyMeshUnitsToRetire, legacyOwnerLookup, } from "./legacy.js";
|
|
48
50
|
import { readLegacySyncEnv } from "./legacy-sync-env.js";
|
|
49
|
-
import { readVaultSyncSwitches, unreadableSwitchesWarning, writeVaultSyncSwitches } from "../vault-sync-switches.js";
|
|
51
|
+
import { readVaultSwitchOnTimes, readVaultSyncSwitches, unreadableSwitchesWarning, writeVaultSyncSwitches } from "../vault-sync-switches.js";
|
|
50
52
|
import { scheduleDaemonPlistRefresh } from "./plist-refresh.js";
|
|
51
53
|
import { acquireDaemonLock, isProcessAlive, processCommandLine, releaseDaemonLock } from "./lock.js";
|
|
52
54
|
import { retireLegacyMeshUnits } from "./migrate.js";
|
|
@@ -69,7 +71,7 @@ import { createHqdRuntimeEvents, observeHqdRuntimeFlag, startHqdRuntimeListener
|
|
|
69
71
|
import { heartbeatFile, startHeartbeat } from "./heartbeat.js";
|
|
70
72
|
import { daemonStartEnv } from "./hook-env.js";
|
|
71
73
|
import { createProtocolTail, ensureProtocolFifo, openProtocolWriter } from "./protocol-tail.js";
|
|
72
|
-
import { takeControlRequests } from "./requests.js";
|
|
74
|
+
import { takeControlRequests, writeControlRequest } from "./requests.js";
|
|
73
75
|
import { currentHqCloud, currentHqCloudAfterLeaseRelease, hqCloudRunners, hqCloudVersionOlder } from "./hq-cloud.js";
|
|
74
76
|
import { stageSyncRunnerBundle } from "./sync-runner-bundle.js";
|
|
75
77
|
import { stageHqChildBootstrap } from "./hq-child-bootstrap-stage.js";
|
|
@@ -113,7 +115,7 @@ export function syncCoreVaultPlans(home, hqRoot, platform) {
|
|
|
113
115
|
});
|
|
114
116
|
}
|
|
115
117
|
const rememberedSyncCoreVaults = new Map();
|
|
116
|
-
export function planUnitsWithSyncCoreInterlock(services, context, supervisor, readOwnerStatus) {
|
|
118
|
+
export function planUnitsWithSyncCoreInterlock(services, context, supervisor, readOwnerStatus, handover, readSwitchOnTimes = () => ({ companies: {} })) {
|
|
117
119
|
const companies = new Set();
|
|
118
120
|
const runningVaults = new Set();
|
|
119
121
|
let personal = false;
|
|
@@ -180,18 +182,74 @@ export function planUnitsWithSyncCoreInterlock(services, context, supervisor, re
|
|
|
180
182
|
waiting = planUnits(services, transitionContext);
|
|
181
183
|
legacy = waiting.find((unit) => unit.id === "sync");
|
|
182
184
|
}
|
|
183
|
-
|
|
185
|
+
let onTimes;
|
|
186
|
+
try {
|
|
187
|
+
onTimes = readSwitchOnTimes();
|
|
188
|
+
}
|
|
189
|
+
catch {
|
|
190
|
+
onTimes = { companies: {} };
|
|
191
|
+
}
|
|
192
|
+
const anyTurnedOn = onTimes.personal !== undefined || Object.keys(onTimes.companies).length > 0;
|
|
193
|
+
const holder = context.syncCoreVaults?.some((vault) => vault.phase === "full") || anyTurnedOn
|
|
184
194
|
? legacySyncHeldByOtherOwner(supervisor?.state().units ?? [], readOwnerStatus)
|
|
185
195
|
: undefined;
|
|
186
196
|
const legacySyncReadyForCore = legacy !== undefined
|
|
187
197
|
&& (legacy.blocked !== undefined
|
|
188
198
|
|| holder !== undefined
|
|
189
199
|
|| supervisor?.runningPlanKey("sync") === planKey(legacy, CLI_VERSION));
|
|
190
|
-
|
|
200
|
+
const planned = {
|
|
191
201
|
...transitionContext,
|
|
192
202
|
legacySyncReadyForCore,
|
|
193
203
|
...(holder !== undefined ? { legacySyncHolder: holder } : {}),
|
|
194
|
-
}
|
|
204
|
+
};
|
|
205
|
+
let plans = planUnits(services, planned);
|
|
206
|
+
if (!handover)
|
|
207
|
+
return plans;
|
|
208
|
+
const vaultName = (uid) => {
|
|
209
|
+
const vault = context.syncCoreVaults?.find((v) => v.uid === uid);
|
|
210
|
+
return vault?.kind === "personal" ? "the personal vault" : `the ${vault?.slug ?? uid} vault`;
|
|
211
|
+
};
|
|
212
|
+
const toEngine = plans
|
|
213
|
+
.filter((unit) => unit.id.startsWith("sync-core:") && isLegacyRestartWait(unit.blocked))
|
|
214
|
+
.map((unit) => vaultName(unit.id.slice("sync-core:".length)));
|
|
215
|
+
const engineStillRunning = { personal: false, companies: new Set() };
|
|
216
|
+
for (const uid of runningVaults) {
|
|
217
|
+
const vault = rememberedSyncCoreVaults.get(uid);
|
|
218
|
+
if (vault?.kind === "personal")
|
|
219
|
+
engineStillRunning.personal = true;
|
|
220
|
+
else if (vault?.slug)
|
|
221
|
+
engineStillRunning.companies.add(vault.slug);
|
|
222
|
+
}
|
|
223
|
+
const restores = legacyRestoreWaits(transitionContext.vaultSync, onTimes, holder, engineStillRunning);
|
|
224
|
+
if (holder?.status === "started" && (toEngine.length > 0 || restores.length > 0)) {
|
|
225
|
+
handover.request(holder, [...toEngine, ...restores.map((wait) => wait.what)]);
|
|
226
|
+
}
|
|
227
|
+
handover.reportRestoreWaits(holder, restores);
|
|
228
|
+
const stopRequestedAt = handover.requestedAt(holder);
|
|
229
|
+
if (stopRequestedAt !== undefined && toEngine.length > 0) {
|
|
230
|
+
plans = planUnits(services, { ...planned, legacyHandoverStopRequestedAt: stopRequestedAt });
|
|
231
|
+
}
|
|
232
|
+
return plans;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Vaults whose old-sync switch HQ turned back on (a rollback, or a held engine)
|
|
236
|
+
* after the running old sync started: that runner still skips them until it
|
|
237
|
+
* restarts, so they have no sync at all until then.
|
|
238
|
+
*/
|
|
239
|
+
export function legacyRestoreWaits(vaultSync, onTimes, holder, engineStillRunning = { personal: false, companies: new Set() }) {
|
|
240
|
+
if (holder?.status !== "started" || vaultSync?.allOff === true)
|
|
241
|
+
return [];
|
|
242
|
+
const waits = [];
|
|
243
|
+
const add = (what, at, off) => {
|
|
244
|
+
const since = at ? Date.parse(at) : Number.NaN;
|
|
245
|
+
if (!off && Number.isFinite(since) && holder.startedAt < since)
|
|
246
|
+
waits.push({ what, since });
|
|
247
|
+
};
|
|
248
|
+
add("the personal vault", onTimes.personal, vaultSync?.personalOff === true || engineStillRunning.personal);
|
|
249
|
+
for (const [slug, at] of Object.entries(onTimes.companies).sort(([a], [b]) => a.localeCompare(b))) {
|
|
250
|
+
add(`the ${slug} vault`, at, vaultSync?.offCompanies.has(slug) === true || engineStillRunning.companies.has(slug));
|
|
251
|
+
}
|
|
252
|
+
return waits;
|
|
195
253
|
}
|
|
196
254
|
export function legacySyncHeldByOtherOwner(units, readOwnerStatus) {
|
|
197
255
|
const sync = units.find((unit) => unit.id === "sync");
|
|
@@ -212,7 +270,7 @@ export function legacySyncHeldByOtherOwner(units, readOwnerStatus) {
|
|
|
212
270
|
if (retrying && sync.pid !== undefined && owner.pid === sync.pid)
|
|
213
271
|
return undefined;
|
|
214
272
|
const startedAt = Date.parse(owner.startedAt);
|
|
215
|
-
return Number.isFinite(startedAt) ? { status: "started", startedAt } : { status: "unreadable" };
|
|
273
|
+
return Number.isFinite(startedAt) ? { status: "started", startedAt, pid: owner.pid, owner: owner.owner } : { status: "unreadable" };
|
|
216
274
|
}
|
|
217
275
|
/** A bounded shutdown deadline that can account for sync push persistence. */
|
|
218
276
|
export function createShutdownCap() {
|
|
@@ -496,6 +554,14 @@ export function listLocalBots(root = botsRoot()) {
|
|
|
496
554
|
.map((d) => d.name)
|
|
497
555
|
.sort();
|
|
498
556
|
}
|
|
557
|
+
/** The plan's bots. A signed-in pass also lets held bots whose move HQ cancelled
|
|
558
|
+
* free themselves, in the background and rate-limited per bot.
|
|
559
|
+
*/
|
|
560
|
+
export function daemonBotPlans(input) {
|
|
561
|
+
if (input.signedIn && input.services.includes("bots"))
|
|
562
|
+
void input.heldBots.kick();
|
|
563
|
+
return { bots: listLocalBots(input.root), fleetBots: planFleetBots(input.fleet) };
|
|
564
|
+
}
|
|
499
565
|
/** Whose task `taskName` is: only the current user's own task may be taken over. */
|
|
500
566
|
export function windowsTaskOwner(taskName) {
|
|
501
567
|
const run = (cmd, args) => {
|
|
@@ -806,6 +872,13 @@ export async function runDaemon(opts) {
|
|
|
806
872
|
const paths = daemonPaths(home, env);
|
|
807
873
|
ensurePrivateDir(paths.syncPassRequestsDir);
|
|
808
874
|
const log = makeLogger(paths, opts.foreground === true);
|
|
875
|
+
const heldBots = createHeldBotReconciler({
|
|
876
|
+
root: botsRoot(home, env),
|
|
877
|
+
platform,
|
|
878
|
+
throttle: { dir: heldBotThrottleDir(paths.root) },
|
|
879
|
+
requestStart: (unit) => { writeControlRequest(paths.requestsDir, { action: "restart", unit }); },
|
|
880
|
+
log,
|
|
881
|
+
});
|
|
809
882
|
const syncRunnerBundleDirectory = opts.syncRunnerBundleDirectory ?? path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../../hq-cloud-sync-runner");
|
|
810
883
|
const cliPackageRoot = opts.cliPackageRoot === undefined ? resolveRunningInstall().packageRoot : opts.cliPackageRoot;
|
|
811
884
|
const cliPackagePrefix = opts.cliPackagePrefix === undefined
|
|
@@ -961,7 +1034,7 @@ export async function runDaemon(opts) {
|
|
|
961
1034
|
}
|
|
962
1035
|
return legacyCache.units;
|
|
963
1036
|
};
|
|
964
|
-
const meshEnabled = enabledServices(machineType, initial).includes("mesh");
|
|
1037
|
+
const meshEnabled = enabledServices(machineType, initial, { engineVaults: engineVaultCount(home) }).includes("mesh");
|
|
965
1038
|
const launchctl = (command, args) => {
|
|
966
1039
|
const r = spawnSync(command, args, { encoding: "utf8", windowsHide: true, timeout: 15_000 });
|
|
967
1040
|
return { status: r.status, stdout: r.stdout ?? "", stderr: r.stderr ?? "" };
|
|
@@ -998,7 +1071,7 @@ export async function runDaemon(opts) {
|
|
|
998
1071
|
platform,
|
|
999
1072
|
managed: opts.managed === true,
|
|
1000
1073
|
hosted: opts.host !== undefined,
|
|
1001
|
-
meshEnabled
|
|
1074
|
+
meshEnabled,
|
|
1002
1075
|
}, {
|
|
1003
1076
|
run: (command, args) => {
|
|
1004
1077
|
const r = spawnSync(command, args, { encoding: "utf8", windowsHide: true, timeout: 15_000 });
|
|
@@ -1018,6 +1091,22 @@ export async function runDaemon(opts) {
|
|
|
1018
1091
|
}
|
|
1019
1092
|
legacyCache = null;
|
|
1020
1093
|
}
|
|
1094
|
+
const legacyHandover = opts.legacyHandover ?? createLegacyHandover({
|
|
1095
|
+
now: Date.now,
|
|
1096
|
+
selfPid: process.pid,
|
|
1097
|
+
isAlive: (pid) => isProcessAlive(pid),
|
|
1098
|
+
commandLine: (pid) => processCommandLine(pid, {
|
|
1099
|
+
platform,
|
|
1100
|
+
run: (file, args) => {
|
|
1101
|
+
const r = spawnSync(file, args, { encoding: "utf8", windowsHide: true, timeout: 15_000 });
|
|
1102
|
+
return { status: r.status, stdout: r.stdout ?? "", stderr: r.stderr ?? "" };
|
|
1103
|
+
},
|
|
1104
|
+
}),
|
|
1105
|
+
signal: (pid, sig) => process.kill(pid, sig),
|
|
1106
|
+
platform,
|
|
1107
|
+
writeRestoreStuck: (stuck) => writeLegacyHandoverStuck(path.join(paths.root, LEGACY_HANDOVER_STUCK_FILE), stuck),
|
|
1108
|
+
log: (level, message) => log(level, message),
|
|
1109
|
+
});
|
|
1021
1110
|
const meshOwnerReason = () => {
|
|
1022
1111
|
const lockPath = meshDaemonPidPath(meshDaemonDir(undefined, home, env));
|
|
1023
1112
|
const owner = readPidLock(lockPath);
|
|
@@ -1463,7 +1552,7 @@ export async function runDaemon(opts) {
|
|
|
1463
1552
|
}
|
|
1464
1553
|
const packageRunners = hqCloud ? hqCloudRunners(hqCloud.root) : { syncRunner: null, heartbeat: null, sessionHost: null };
|
|
1465
1554
|
const runners = { ...packageRunners, syncRunner: syncSource.runnerPath };
|
|
1466
|
-
const services = enabledServices(machineType, config);
|
|
1555
|
+
const services = enabledServices(machineType, config, { engineVaults: engineVaultCount(home) });
|
|
1467
1556
|
const isSignedIn = signedIn(env, home, log);
|
|
1468
1557
|
lastPlanSignedIn = isSignedIn;
|
|
1469
1558
|
lastPlanServices = services;
|
|
@@ -1543,8 +1632,12 @@ export async function runDaemon(opts) {
|
|
|
1543
1632
|
syncOwner === "daemon" && services.includes("sync") && !config.syncPaused &&
|
|
1544
1633
|
!appManagesSync && Boolean(hqRoot && isSignedIn && runners.syncRunner),
|
|
1545
1634
|
syncHeartbeatTimeoutMs: syncHeartbeatTimeoutMs(env),
|
|
1546
|
-
|
|
1547
|
-
|
|
1635
|
+
...daemonBotPlans({
|
|
1636
|
+
heldBots,
|
|
1637
|
+
signedIn: isSignedIn,
|
|
1638
|
+
services,
|
|
1639
|
+
fleet: { platform, home, env, log: (message) => log("info", message) },
|
|
1640
|
+
}),
|
|
1548
1641
|
legacyOwner: legacyOwnerLookup(legacy),
|
|
1549
1642
|
cliSelfUpdatable: updatable,
|
|
1550
1643
|
claudePath: findUserBinary("claude", env, home),
|
|
@@ -1564,7 +1657,7 @@ export async function runDaemon(opts) {
|
|
|
1564
1657
|
};
|
|
1565
1658
|
const plans = planUnitsWithSyncCoreInterlock(services, context, supervisor, () => hqRoot
|
|
1566
1659
|
? readWatchRunnerOwnerStatus(watchRunnerOwnerStatusPath(hqRoot, home, env))
|
|
1567
|
-
: null);
|
|
1660
|
+
: null, legacyHandover, () => readVaultSwitchOnTimes(home));
|
|
1568
1661
|
if (startupPlanOpen) {
|
|
1569
1662
|
const replaceablePackageRoots = cliPackageRoot ? [cliPackageRoot] : [];
|
|
1570
1663
|
if (hqCloud?.source === "bundled")
|