@indigoai-us/hq-cli 5.345.219 → 5.345.221
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 +170 -0
- package/dist/command-catalog.generated.d.ts +169 -3
- package/dist/command-catalog.generated.js +206 -3
- package/dist/commands/auth.js +4 -1
- package/dist/commands/bot-runtime.d.ts +18 -5
- package/dist/commands/bot-runtime.js +29 -12
- package/dist/commands/bot.d.ts +85 -0
- package/dist/commands/bot.js +245 -16
- package/dist/commands/cloud.d.ts +16 -0
- package/dist/commands/cloud.js +112 -102
- package/dist/commands/core-checkpoint-native.d.ts +13 -0
- package/dist/commands/core-checkpoint-native.js +167 -52
- package/dist/commands/core-hook-registration-plan.js +5 -4
- package/dist/commands/core-stop-autosave.d.ts +21 -0
- package/dist/commands/core-stop-autosave.js +300 -0
- package/dist/commands/core.js +2 -0
- package/dist/commands/daemon.d.ts +5 -0
- package/dist/commands/daemon.js +52 -9
- package/dist/commands/doctor-usage.d.ts +5 -0
- package/dist/commands/doctor-usage.js +25 -0
- package/dist/commands/env.d.ts +49 -4
- package/dist/commands/env.js +355 -5
- package/dist/commands/integrations.js +84 -3
- package/dist/commands/lanes-shared.d.ts +3 -0
- package/dist/commands/lanes.d.ts +3 -0
- package/dist/commands/lanes.js +87 -3
- package/dist/commands/packs.js +23 -0
- package/dist/commands/pkg-update.d.ts +6 -0
- package/dist/commands/pkg-update.js +15 -7
- package/dist/commands/run.js +55 -45
- package/dist/commands/sources.js +4 -3
- package/dist/commands/sync-core.d.ts +1 -0
- package/dist/commands/sync-core.js +77 -3
- package/dist/commands/whoami.js +96 -80
- package/dist/lib/bot/config.d.ts +17 -0
- package/dist/lib/bot/config.js +13 -0
- package/dist/lib/bot/fleet-cron.js +29 -4
- package/dist/lib/bot/fleet-local.d.ts +30 -2
- package/dist/lib/bot/fleet-local.js +60 -1
- package/dist/lib/bot/grok-login-scope.d.ts +36 -0
- package/dist/lib/bot/grok-login-scope.js +93 -0
- package/dist/lib/bot/inflight.d.ts +9 -0
- package/dist/lib/bot/jobs/hot-signal-sync.d.ts +51 -0
- package/dist/lib/bot/jobs/hot-signal-sync.js +90 -9
- package/dist/lib/bot/legacy-provider-login.d.ts +32 -9
- package/dist/lib/bot/legacy-provider-login.js +28 -22
- package/dist/lib/bot/run.d.ts +29 -5
- package/dist/lib/bot/run.js +203 -1
- package/dist/lib/bot/runtime-sign-in-check.js +6 -1
- package/dist/lib/bot/runtime-sign-in.d.ts +2 -0
- package/dist/lib/bot/signals-try-now.d.ts +76 -0
- package/dist/lib/bot/signals-try-now.js +111 -0
- package/dist/lib/capacity/collectors/claude-oauth.d.ts +22 -3
- package/dist/lib/capacity/collectors/claude-oauth.js +78 -22
- package/dist/lib/capacity/scheduler.d.ts +8 -0
- package/dist/lib/capacity/scheduler.js +5 -2
- package/dist/lib/core-utils/sentry-report.js +2 -0
- package/dist/lib/daemon/machine-checks.d.ts +22 -1
- package/dist/lib/daemon/machine-checks.js +54 -12
- package/dist/lib/daemon/run.js +71 -8
- package/dist/lib/daemon/runtime-notifications.d.ts +7 -0
- package/dist/lib/daemon/runtime-notifications.js +50 -0
- package/dist/lib/daemon/stop-autosave-lock.d.ts +19 -0
- package/dist/lib/daemon/stop-autosave-lock.js +166 -0
- package/dist/lib/daemon/stop-autosave.d.ts +28 -0
- package/dist/lib/daemon/stop-autosave.js +111 -0
- package/dist/lib/daemon/stop-diagnostics.d.ts +11 -0
- package/dist/lib/daemon/stop-diagnostics.js +136 -0
- package/dist/lib/daemon/stop-job-executor.d.ts +19 -0
- package/dist/lib/daemon/stop-job-executor.js +126 -0
- package/dist/lib/daemon/stop-jobs.d.ts +93 -0
- package/dist/lib/daemon/stop-jobs.js +599 -0
- package/dist/lib/doctor/checks/fleet-hook-core.d.ts +9 -1
- package/dist/lib/doctor/checks/fleet-hook-core.js +39 -15
- package/dist/lib/doctor/checks/host-core.js +1 -1
- package/dist/lib/environment/access-probes.d.ts +234 -0
- package/dist/lib/environment/access-probes.js +918 -0
- package/dist/lib/environment/profile.d.ts +15 -2
- package/dist/lib/environment/profile.js +55 -20
- package/dist/lib/environment/rfc3339.d.ts +8 -0
- package/dist/lib/environment/rfc3339.js +26 -0
- package/dist/lib/environment/work-requirements.d.ts +169 -0
- package/dist/lib/environment/work-requirements.js +389 -0
- package/dist/lib/hook-engine/coverage.d.ts +137 -7
- package/dist/lib/hook-engine/coverage.js +1424 -4
- package/dist/lib/hook-engine/fleet-registration.d.ts +17 -5
- package/dist/lib/hook-engine/fleet-registration.js +53 -17
- package/dist/lib/hook-engine/git-stop-config.json +513 -0
- package/dist/lib/hook-engine/native-stop-compatibility.json +311 -0
- package/dist/lib/hook-engine/reconcile.js +2 -2
- package/dist/lib/hot-channels/alert.d.ts +10 -1
- package/dist/lib/hot-channels/alert.js +38 -8
- package/dist/lib/hot-channels/signals-claude-login.d.ts +53 -0
- package/dist/lib/hot-channels/signals-claude-login.js +96 -0
- package/dist/lib/hot-channels/signals-pass.d.ts +143 -17
- package/dist/lib/hot-channels/signals-pass.js +324 -17
- package/dist/lib/hot-channels/signals-runtime.d.ts +30 -0
- package/dist/lib/hot-channels/signals-runtime.js +82 -0
- package/dist/lib/install/hook-target.js +1 -1
- package/dist/lib/lanes/host-capacity.d.ts +26 -2
- package/dist/lib/lanes/host-capacity.js +17 -2
- package/dist/lib/lanes/host-compute.d.ts +90 -0
- package/dist/lib/lanes/host-compute.js +185 -0
- package/dist/lib/lanes/index.d.ts +2 -0
- package/dist/lib/lanes/index.js +1 -0
- package/dist/lib/lanes/reconcile.js +22 -1
- package/dist/lib/lanes/resource-usage.d.ts +155 -0
- package/dist/lib/lanes/resource-usage.js +589 -0
- package/dist/lib/lanes/run-size.d.ts +46 -0
- package/dist/lib/lanes/run-size.js +197 -0
- package/dist/lib/lanes/store.js +27 -0
- package/dist/lib/lanes/throttle.d.ts +36 -1
- package/dist/lib/lanes/throttle.js +47 -10
- package/dist/lib/lanes/types.d.ts +40 -0
- package/dist/lib/lanes/types.js +2 -2
- package/dist/lib/lanes/watcher.js +13 -4
- package/dist/lib/lanes/worker-process.d.ts +25 -2
- package/dist/lib/lanes/worker-process.js +71 -19
- package/dist/lib/placement/match.d.ts +192 -0
- package/dist/lib/placement/match.js +667 -0
- package/dist/lib/safe-store.d.ts +14 -0
- package/dist/lib/safe-store.js +77 -4
- package/dist/lib/search-index/index.d.ts +88 -4
- package/dist/lib/search-index/index.js +299 -25
- package/dist/lib/search-index/max-doc-bytes.d.ts +17 -6
- package/dist/lib/search-index/max-doc-bytes.js +48 -23
- package/dist/lib/signals/codex-lockdown.d.ts +79 -0
- package/dist/lib/signals/codex-lockdown.js +271 -0
- package/dist/lib/signals/codex-login.d.ts +37 -0
- package/dist/lib/signals/codex-login.js +83 -0
- package/dist/lib/signals/engine.d.ts +28 -0
- package/dist/lib/signals/engine.js +77 -0
- package/dist/lib/signals/reply.d.ts +48 -0
- package/dist/lib/signals/reply.js +94 -12
- package/dist/lib/signals/run-record.js +6 -1
- package/dist/lib/signals/settings.d.ts +5 -0
- package/dist/lib/signals/settings.js +2 -0
- package/dist/lib/signals/steps/adapters.js +6 -0
- package/dist/lib/signals/steps/extract.d.ts +135 -12
- package/dist/lib/signals/steps/extract.js +416 -84
- package/dist/lib/signals/steps/types.d.ts +21 -0
- package/dist/lib/sync-core/engine-home.d.ts +41 -2
- package/dist/lib/sync-core/engine-home.js +132 -19
- package/dist/lib/sync-core/reconcile.js +1 -1
- package/dist/lib/sync-core/release-compare.d.ts +7 -0
- package/dist/lib/sync-core/release-compare.js +16 -0
- package/dist/lib/sync-core/release.d.ts +2 -1
- package/dist/lib/sync-core/release.js +2 -10
- package/dist/lib/sync-core/rollout-state.d.ts +2 -1
- package/dist/lib/sync-core/rollout-state.js +5 -2
- package/dist/lib/sync-core/vault-uid.d.ts +2 -0
- package/dist/lib/sync-core/vault-uid.js +4 -0
- package/dist/run/schema-env-overrides.d.ts +24 -0
- package/dist/run/schema-env-overrides.js +72 -0
- package/dist/schemas/hq-work-requirements.v1.schema.json +145 -0
- package/dist/utils/auth-session-check.d.ts +16 -0
- package/dist/utils/auth-session-check.js +16 -0
- package/dist/utils/client-health-contract.d.ts +6 -0
- package/dist/utils/client-health-contract.js +13 -0
- package/dist/utils/client-health.d.ts +7 -0
- package/dist/utils/client-health.js +22 -1
- package/dist/utils/command-usage.d.ts +40 -0
- package/dist/utils/command-usage.js +61 -0
- package/dist/utils/duplicate-command-usage.d.ts +72 -0
- package/dist/utils/duplicate-command-usage.js +125 -0
- package/dist/utils/host-registration.d.ts +1 -1
- package/dist/utils/host-registration.js +6 -1
- package/dist/utils/resident-package-preload.js +4 -0
- package/dist/utils/sentry-fingerprint.js +9 -0
- package/dist/utils/windows-bash.d.ts +2 -0
- package/dist/utils/windows-bash.js +2 -1
- package/package.json +15 -10
- package/scripts/bench-core-compare.mjs +313 -0
- package/scripts/bench-core.mjs +399 -12
- package/scripts/check-function-manifest.mjs +121 -7
- package/dist/commands/__fixtures__/access-vault.d.ts +0 -95
- package/dist/commands/__fixtures__/access-vault.js +0 -166
- package/dist/commands/__fixtures__/make-tar.d.ts +0 -38
- package/dist/commands/__fixtures__/make-tar.js +0 -102
- package/dist/commands/secrets-public-types.test-d.d.ts +0 -2
- package/dist/commands/secrets-public-types.test-d.js +0 -18
- package/dist/lib/decisions/fixtures/us001.d.ts +0 -137
- package/dist/lib/decisions/fixtures/us001.js +0 -21
- package/dist/lib/doctor/__testing__/fake-hq-tree.d.ts +0 -226
- package/dist/lib/doctor/__testing__/fake-hq-tree.js +0 -408
- package/dist/lib/doctor/__testing__/run-doctor.d.ts +0 -8
- package/dist/lib/doctor/__testing__/run-doctor.js +0 -69
- package/dist/lib/fingerprint/fixtures.d.ts +0 -19
- package/dist/lib/fingerprint/fixtures.js +0 -61
- package/dist/lib/hot-channels/adapters/__fixtures__/dummy.d.ts +0 -33
- package/dist/lib/hot-channels/adapters/__fixtures__/dummy.js +0 -53
- package/dist/lib/hot-channels/adapters/__fixtures__/meeting-providers.d.ts +0 -38
- package/dist/lib/hot-channels/adapters/__fixtures__/meeting-providers.js +0 -64
- package/dist/lib/mesh/live/daemon/mqtt-events.test-d.d.ts +0 -2
- package/dist/lib/mesh/live/daemon/mqtt-events.test-d.js +0 -10
- package/dist/lib/test-utils/isolated-flag-company-context.d.ts +0 -3
- package/dist/lib/test-utils/isolated-flag-company-context.js +0 -18
- package/scripts/hook-engine-manifest.mjs +0 -22
- package/scripts/mesh-daemon-if-stale.mjs +0 -20
|
@@ -68,7 +68,11 @@ export const CLAUDE_OAUTH_REFRESH_BACKOFF_MS = 10 * 60 * 1000;
|
|
|
68
68
|
export const CLAUDE_OAUTH_REFRESH_REVOKED_BACKOFF_MS = 60 * 60 * 1000;
|
|
69
69
|
/** Try a refresh when the token is this close to expiry, so one tick does not land on a stale token. */
|
|
70
70
|
export const CLAUDE_OAUTH_REFRESH_PREFLIGHT_MS = 10 * 60 * 1000;
|
|
71
|
-
|
|
71
|
+
/**
|
|
72
|
+
* Claude refresh tokens are single use. A refresh the server completed but whose
|
|
73
|
+
* response we abandoned leaves the stored token dead, so this limit is generous.
|
|
74
|
+
*/
|
|
75
|
+
export const CLAUDE_OAUTH_REFRESH_TIMEOUT_MS = 30_000;
|
|
72
76
|
export const CLAUDE_OAUTH_REFRESH_LAST_FILE = "claude-oauth-refresh-last.json";
|
|
73
77
|
const SESSION_MINUTES = 5 * 60;
|
|
74
78
|
const WEEKLY_MINUTES = 7 * 24 * 60;
|
|
@@ -1718,6 +1722,7 @@ const defaultWriteClaudeCredentials = async (request) => {
|
|
|
1718
1722
|
// the item so the write uses the SAME selector and does not create a second entry.
|
|
1719
1723
|
let selector = null;
|
|
1720
1724
|
let preRead = spawnSync("security", ["find-generic-password", "-s", request.service, "-a", username, "-w"], spawnOpts);
|
|
1725
|
+
const firstReadStatus = preRead.status;
|
|
1721
1726
|
if (preRead.status === 0) {
|
|
1722
1727
|
selector = "sa";
|
|
1723
1728
|
}
|
|
@@ -1744,8 +1749,15 @@ const defaultWriteClaudeCredentials = async (request) => {
|
|
|
1744
1749
|
return { ok: false, raceDetected: true };
|
|
1745
1750
|
}
|
|
1746
1751
|
}
|
|
1752
|
+
else if (firstReadStatus === 44 && preRead.status === 44) {
|
|
1753
|
+
// Both selectors confirmed the item does not exist (exit 44), so there is
|
|
1754
|
+
// nothing to race with or duplicate. The endpoint has already rotated the
|
|
1755
|
+
// refresh token; writing it keeps the only valid token instead of losing it.
|
|
1756
|
+
selector = "sa";
|
|
1757
|
+
}
|
|
1747
1758
|
else if (request.previousRefreshToken) {
|
|
1748
|
-
//
|
|
1759
|
+
// Unreadable for another reason (timeout, prompt, locked Keychain). Writing
|
|
1760
|
+
// blind could duplicate the item or clobber a newer token, so fail closed.
|
|
1749
1761
|
return { ok: false, raceDetected: true };
|
|
1750
1762
|
}
|
|
1751
1763
|
const body = JSON.stringify(request.document);
|
|
@@ -1800,6 +1812,49 @@ const defaultWriteClaudeCredentials = async (request) => {
|
|
|
1800
1812
|
return { ok: false, error: message };
|
|
1801
1813
|
}
|
|
1802
1814
|
};
|
|
1815
|
+
function refreshTokenFromDocumentText(text) {
|
|
1816
|
+
let parsed;
|
|
1817
|
+
try {
|
|
1818
|
+
parsed = JSON.parse(text.replace(/\n$/, ""));
|
|
1819
|
+
}
|
|
1820
|
+
catch {
|
|
1821
|
+
// Unparseable item: report it as unreadable so the caller does not act on it.
|
|
1822
|
+
return undefined;
|
|
1823
|
+
}
|
|
1824
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
|
|
1825
|
+
return undefined;
|
|
1826
|
+
const oauth = parsed.claudeAiOauth;
|
|
1827
|
+
if (!oauth || typeof oauth !== "object" || Array.isArray(oauth))
|
|
1828
|
+
return null;
|
|
1829
|
+
const record = oauth;
|
|
1830
|
+
if (typeof record.refreshToken === "string")
|
|
1831
|
+
return record.refreshToken;
|
|
1832
|
+
if (typeof record.refresh_token === "string")
|
|
1833
|
+
return record.refresh_token;
|
|
1834
|
+
return null;
|
|
1835
|
+
}
|
|
1836
|
+
const defaultReadStoredRefreshToken = (request) => {
|
|
1837
|
+
if (request.platform === "darwin") {
|
|
1838
|
+
const username = os.userInfo().username;
|
|
1839
|
+
const spawnOpts = { encoding: "utf8", timeout: CLAUDE_OAUTH_SECURITY_TIMEOUT_MS, windowsHide: true };
|
|
1840
|
+
for (const args of [
|
|
1841
|
+
["find-generic-password", "-s", request.service, "-a", username, "-w"],
|
|
1842
|
+
["find-generic-password", "-s", request.service, "-w"],
|
|
1843
|
+
]) {
|
|
1844
|
+
const read = spawnSync("security", args, spawnOpts);
|
|
1845
|
+
if (read.status === 0 && typeof read.stdout === "string")
|
|
1846
|
+
return refreshTokenFromDocumentText(read.stdout);
|
|
1847
|
+
}
|
|
1848
|
+
return undefined;
|
|
1849
|
+
}
|
|
1850
|
+
try {
|
|
1851
|
+
return refreshTokenFromDocumentText(fs.readFileSync(path.join(request.home, ".credentials.json"), "utf8"));
|
|
1852
|
+
}
|
|
1853
|
+
catch {
|
|
1854
|
+
// Missing or unreadable file: unknown, so the caller keeps its own judgement.
|
|
1855
|
+
return undefined;
|
|
1856
|
+
}
|
|
1857
|
+
};
|
|
1803
1858
|
const HQ_CLI_PACKAGE_NAME = "@indigoai-us/hq-cli";
|
|
1804
1859
|
const LOADER_FLAGS_WITH_VALUE = new Set(["--import", "--loader", "--experimental-loader", "--require", "-r", "--conditions", "-C"]);
|
|
1805
1860
|
const LOADER_FLAGS_BARE = new Set(["--experimental-strip-types", "--experimental-transform-types"]);
|
|
@@ -2290,8 +2345,6 @@ async function attemptClaudeTokenRefresh(ctx) {
|
|
|
2290
2345
|
}
|
|
2291
2346
|
const resolvedHome = path.resolve(ctx.home);
|
|
2292
2347
|
const targetHome = canonicalHomePath(ctx.home) ?? resolvedHome;
|
|
2293
|
-
// Exact match, for the auth-failed short circuit, which records the home as revoked.
|
|
2294
|
-
const sameHome = (candidate) => typeof candidate === "string" && candidate.length > 0 && canonicalHomePath(candidate) === targetHome;
|
|
2295
2348
|
// Blocking match: a path that cannot be resolved might be this home, so it blocks.
|
|
2296
2349
|
const mayHoldHome = (candidate) => {
|
|
2297
2350
|
if (typeof candidate !== "string" || candidate.length === 0)
|
|
@@ -2299,24 +2352,11 @@ async function attemptClaudeTokenRefresh(ctx) {
|
|
|
2299
2352
|
const canonical = canonicalHomePath(candidate);
|
|
2300
2353
|
return canonical === null || canonical === targetHome;
|
|
2301
2354
|
};
|
|
2302
|
-
//
|
|
2303
|
-
//
|
|
2304
|
-
//
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
const fingerprint = tokenFingerprint(ctx.refreshToken);
|
|
2308
|
-
const now = new Date(ctx.nowMs).toISOString();
|
|
2309
|
-
recordRefresh(ctx.root, key, {
|
|
2310
|
-
attemptedAt: now,
|
|
2311
|
-
outcome: "revoked",
|
|
2312
|
-
errorClass: "revoked",
|
|
2313
|
-
revokedRefreshTokenFingerprint: fingerprint,
|
|
2314
|
-
backoffUntil: new Date(ctx.nowMs + CLAUDE_OAUTH_REFRESH_REVOKED_BACKOFF_MS).toISOString(),
|
|
2315
|
-
}, (file) => {
|
|
2316
|
-
file.revokedTokens[fingerprint] = now;
|
|
2317
|
-
});
|
|
2318
|
-
return { outcome: "revoked", errorClass: "revoked" };
|
|
2319
|
-
}
|
|
2355
|
+
// A finished lane that ended with provider_auth_failed on this home is NOT
|
|
2356
|
+
// proof that the refresh token stored now is dead: the lane may have failed
|
|
2357
|
+
// on an older token, or on an access token that a refresh would renew.
|
|
2358
|
+
// Marking the current token revoked from that signal signed fresh sign-ins
|
|
2359
|
+
// out. Only the token endpoint's own answer below decides revoked.
|
|
2320
2360
|
if (liveLanes.some((lane) => lane.isLive && mayHoldHome(lane.home))) {
|
|
2321
2361
|
recordRefresh(ctx.root, key, { attemptedAt: new Date(ctx.nowMs).toISOString(), outcome: "skipped-live" });
|
|
2322
2362
|
return { outcome: "skipped-live" };
|
|
@@ -2426,6 +2466,20 @@ async function attemptClaudeTokenRefresh(ctx) {
|
|
|
2426
2466
|
|| /\b(revoked|invalid)\b/.test(errField)
|
|
2427
2467
|
|| /\b(revoked|invalid)\b/.test(descField);
|
|
2428
2468
|
if (revokedHit) {
|
|
2469
|
+
// Another process (Claude Code, a lane) may have rotated the token between
|
|
2470
|
+
// our read and this POST. Then our copy is stale, not the account.
|
|
2471
|
+
const service = ctx.service || claudeKeychainServiceName(ctx.home);
|
|
2472
|
+
const stored = ctx.readStoredRefreshToken({ home: ctx.home, service, platform: ctx.platform });
|
|
2473
|
+
if (typeof stored === "string" && stored.length > 0 && stored !== ctx.refreshToken) {
|
|
2474
|
+
// Back off so a store that keeps disagreeing with the read path cannot make
|
|
2475
|
+
// the collector POST a dead token every tick without ever deciding.
|
|
2476
|
+
recordRefresh(ctx.root, key, {
|
|
2477
|
+
attemptedAt: new Date(ctx.nowMs).toISOString(),
|
|
2478
|
+
outcome: "skipped-race",
|
|
2479
|
+
backoffUntil: new Date(ctx.nowMs + CLAUDE_OAUTH_REFRESH_BACKOFF_MS).toISOString(),
|
|
2480
|
+
});
|
|
2481
|
+
return { outcome: "skipped-race" };
|
|
2482
|
+
}
|
|
2429
2483
|
const fingerprint = tokenFingerprint(ctx.refreshToken);
|
|
2430
2484
|
const now = new Date(ctx.nowMs).toISOString();
|
|
2431
2485
|
const errorClass = errField === "invalid_grant" ? "invalid_grant" : "revoked";
|
|
@@ -2588,7 +2642,9 @@ async function maybeRefreshAccount(params) {
|
|
|
2588
2642
|
const tokenEndpoint = options.tokenEndpoint ?? CLAUDE_OAUTH_REFRESH_URL;
|
|
2589
2643
|
const listLiveLanes = options.listLiveLanes ?? defaultListLiveLanes;
|
|
2590
2644
|
const listProcesses = options.listProcesses ?? defaultListProcesses;
|
|
2645
|
+
const readStoredRefreshToken = options.readStoredRefreshToken ?? defaultReadStoredRefreshToken;
|
|
2591
2646
|
return attemptClaudeTokenRefresh({
|
|
2647
|
+
readStoredRefreshToken,
|
|
2592
2648
|
root,
|
|
2593
2649
|
home,
|
|
2594
2650
|
service,
|
|
@@ -7,6 +7,14 @@ export declare const REBUILD_TICK_MS = 60000;
|
|
|
7
7
|
export declare const POLL_TICK_MS: number;
|
|
8
8
|
export declare const CODEX_DIR_POLL_MS = 15000;
|
|
9
9
|
export declare const SPOOL_POLL_MS = 15000;
|
|
10
|
+
export declare const RUN_TIMEOUT_MS: {
|
|
11
|
+
readonly "codex-tail": 15000;
|
|
12
|
+
readonly "codex-app-server": 30000;
|
|
13
|
+
readonly "claude-statusline": 10000;
|
|
14
|
+
readonly "claude-oauth": 180000;
|
|
15
|
+
readonly grok: 30000;
|
|
16
|
+
readonly rebuild: 10000;
|
|
17
|
+
};
|
|
10
18
|
export interface CapacityTimers {
|
|
11
19
|
setTimeout(fn: () => void, ms: number): unknown;
|
|
12
20
|
clearTimeout(handle: unknown): void;
|
|
@@ -22,11 +22,14 @@ export const REBUILD_TICK_MS = 60_000;
|
|
|
22
22
|
export const POLL_TICK_MS = 5 * 60_000;
|
|
23
23
|
export const CODEX_DIR_POLL_MS = 15_000;
|
|
24
24
|
export const SPOOL_POLL_MS = 15_000;
|
|
25
|
-
const RUN_TIMEOUT_MS = {
|
|
25
|
+
export const RUN_TIMEOUT_MS = {
|
|
26
26
|
"codex-tail": 15_000,
|
|
27
27
|
"codex-app-server": 30_000,
|
|
28
28
|
"claude-statusline": 10_000,
|
|
29
|
-
|
|
29
|
+
// Must stay well above CLAUDE_OAUTH_REFRESH_TIMEOUT_MS plus Keychain reads. A run
|
|
30
|
+
// marked timed out keeps going, so a short budget lets a second run POST the same
|
|
31
|
+
// single-use refresh token and get the account marked revoked.
|
|
32
|
+
"claude-oauth": 180_000,
|
|
30
33
|
grok: 30_000,
|
|
31
34
|
rebuild: 10_000,
|
|
32
35
|
};
|
|
@@ -20,6 +20,14 @@
|
|
|
20
20
|
* it gains no access it did not have; the check keeps a link, a hardlink, a
|
|
21
21
|
* file of another user or a writable file from being run by mistake.
|
|
22
22
|
*
|
|
23
|
+
* On Windows (only `hq doctor --only machine-checks` runs there; the daemon
|
|
24
|
+
* schedule skips Windows) each script is run with the trusted Git Bash that
|
|
25
|
+
* src/utils/windows-bash.ts resolves, never System32\bash.exe (WSL) or a
|
|
26
|
+
* WindowsApps alias. With no trusted Git Bash every check is `unknown` and
|
|
27
|
+
* nothing is run. The store read rules there are safe-store's Windows rules:
|
|
28
|
+
* a real folder (not a symlink or junction) and a regular single-link file
|
|
29
|
+
* that is not a symlink; Windows has no POSIX owner or mode bits to check.
|
|
30
|
+
*
|
|
23
31
|
* Results can name local paths, so they are written only to the daemon's
|
|
24
32
|
* private folder (machine-checks.json, mode 0600) and the state file, and are
|
|
25
33
|
* never logged or sent.
|
|
@@ -58,7 +66,20 @@ export interface RunMachineChecksOptions {
|
|
|
58
66
|
checks?: readonly MachineCheckSpec[];
|
|
59
67
|
killGraceMs?: number;
|
|
60
68
|
drainMs?: number;
|
|
69
|
+
/** Platform whose rules apply. Default process.platform. */
|
|
70
|
+
platform?: NodeJS.Platform;
|
|
71
|
+
/** Windows only: the trusted Git Bash, or undefined when none. Default resolveWindowsBash. */
|
|
72
|
+
resolveBash?: (env: NodeJS.ProcessEnv) => string | undefined;
|
|
61
73
|
}
|
|
74
|
+
/** The summary of every check on Windows when no trusted Git Bash is found. */
|
|
75
|
+
export declare const MACHINE_CHECK_NO_GIT_BASH = "not run: Git Bash was not found (set CLAUDE_CODE_GIT_BASH_PATH or install Git for Windows)";
|
|
76
|
+
/**
|
|
77
|
+
* The shell that runs every script: /bin/bash off Windows; on Windows the
|
|
78
|
+
* trusted Git Bash, or undefined when none is found. A resolver answer that
|
|
79
|
+
* windows-bash.ts excludes (System32\bash.exe, a WindowsApps alias) or that
|
|
80
|
+
* is not an absolute path counts as none.
|
|
81
|
+
*/
|
|
82
|
+
export declare function machineCheckShell(platform: NodeJS.Platform, env: NodeJS.ProcessEnv, resolveBash?: (env: NodeJS.ProcessEnv) => string | undefined): string | undefined;
|
|
62
83
|
/** The finding text a script's stdout carries: empty means nothing to report. */
|
|
63
84
|
export declare function findingText(stdout: string): string;
|
|
64
85
|
/** First non-empty line with `<tag>` and `</tag>` markers removed, at most 240 characters. */
|
|
@@ -75,7 +96,7 @@ type ScriptCheck = {
|
|
|
75
96
|
summary: string;
|
|
76
97
|
};
|
|
77
98
|
/** The script's absolute path when it may be run; else why not. */
|
|
78
|
-
export declare function checkMachineCheckScript(hqRoot: string, relative: string): ScriptCheck;
|
|
99
|
+
export declare function checkMachineCheckScript(hqRoot: string, relative: string, platform?: NodeJS.Platform): ScriptCheck;
|
|
79
100
|
/**
|
|
80
101
|
* Run every machine check once, one at a time. A call while a batch is
|
|
81
102
|
* running returns that batch. Inside a machine check
|
|
@@ -20,6 +20,14 @@
|
|
|
20
20
|
* it gains no access it did not have; the check keeps a link, a hardlink, a
|
|
21
21
|
* file of another user or a writable file from being run by mistake.
|
|
22
22
|
*
|
|
23
|
+
* On Windows (only `hq doctor --only machine-checks` runs there; the daemon
|
|
24
|
+
* schedule skips Windows) each script is run with the trusted Git Bash that
|
|
25
|
+
* src/utils/windows-bash.ts resolves, never System32\bash.exe (WSL) or a
|
|
26
|
+
* WindowsApps alias. With no trusted Git Bash every check is `unknown` and
|
|
27
|
+
* nothing is run. The store read rules there are safe-store's Windows rules:
|
|
28
|
+
* a real folder (not a symlink or junction) and a regular single-link file
|
|
29
|
+
* that is not a symlink; Windows has no POSIX owner or mode bits to check.
|
|
30
|
+
*
|
|
23
31
|
* Results can name local paths, so they are written only to the daemon's
|
|
24
32
|
* private folder (machine-checks.json, mode 0600) and the state file, and are
|
|
25
33
|
* never logged or sent.
|
|
@@ -30,6 +38,7 @@ import * as fs from "node:fs";
|
|
|
30
38
|
import * as path from "node:path";
|
|
31
39
|
import { coreNextEnabled } from "../../utils/core-next-flag.js";
|
|
32
40
|
import { coreNextKillReason } from "../../utils/core-next-kill.js";
|
|
41
|
+
import { isExcludedWindowsBash, resolveWindowsBash } from "../../utils/windows-bash.js";
|
|
33
42
|
import { anyNativeSessionStartRegistered } from "./machine-check-registration.js";
|
|
34
43
|
import { openStoreDir } from "../safe-store.js";
|
|
35
44
|
import { readStoreFile, writeStoreFile } from "./paths.js";
|
|
@@ -61,6 +70,33 @@ export const MACHINE_CHECK_DRAIN_MS = 50;
|
|
|
61
70
|
const SESSION_ID = "hq-machine-checks";
|
|
62
71
|
const FINGERPRINT = /^[0-9a-f]{64}$/;
|
|
63
72
|
const STATUSES = new Set(["ok", "warn", "fail", "unknown"]);
|
|
73
|
+
/** The summary of every check on Windows when no trusted Git Bash is found. */
|
|
74
|
+
export const MACHINE_CHECK_NO_GIT_BASH = "not run: Git Bash was not found (set CLAUDE_CODE_GIT_BASH_PATH or install Git for Windows)";
|
|
75
|
+
function defaultResolveBash(env) {
|
|
76
|
+
return resolveWindowsBash(env).executable;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* The shell that runs every script: /bin/bash off Windows; on Windows the
|
|
80
|
+
* trusted Git Bash, or undefined when none is found. A resolver answer that
|
|
81
|
+
* windows-bash.ts excludes (System32\bash.exe, a WindowsApps alias) or that
|
|
82
|
+
* is not an absolute path counts as none.
|
|
83
|
+
*/
|
|
84
|
+
export function machineCheckShell(platform, env, resolveBash = defaultResolveBash) {
|
|
85
|
+
if (platform !== "win32")
|
|
86
|
+
return "/bin/bash";
|
|
87
|
+
let bash;
|
|
88
|
+
try {
|
|
89
|
+
bash = resolveBash(env);
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
return undefined;
|
|
93
|
+
}
|
|
94
|
+
if (!bash || isExcludedWindowsBash(bash, env))
|
|
95
|
+
return undefined;
|
|
96
|
+
if (!path.win32.isAbsolute(bash) && !path.posix.isAbsolute(bash))
|
|
97
|
+
return undefined;
|
|
98
|
+
return bash;
|
|
99
|
+
}
|
|
64
100
|
/** The finding text a script's stdout carries: empty means nothing to report. */
|
|
65
101
|
export function findingText(stdout) {
|
|
66
102
|
const trimmed = stdout.trim();
|
|
@@ -116,12 +152,12 @@ function disabledIds(env) {
|
|
|
116
152
|
return new Set((env.HQ_DISABLED_HOOKS ?? "").split(",").map((id) => id.trim()).filter(Boolean));
|
|
117
153
|
}
|
|
118
154
|
/** The script's absolute path when it may be run; else why not. */
|
|
119
|
-
export function checkMachineCheckScript(hqRoot, relative) {
|
|
155
|
+
export function checkMachineCheckScript(hqRoot, relative, platform = process.platform) {
|
|
120
156
|
const root = path.resolve(hqRoot);
|
|
121
157
|
const file = path.resolve(root, ...relative.split("/"));
|
|
122
158
|
if (!file.startsWith(root + path.sep))
|
|
123
159
|
return { ok: false, summary: "refused: outside-root" };
|
|
124
|
-
const opened = openStoreDir(path.dirname(file));
|
|
160
|
+
const opened = openStoreDir(path.dirname(file), platform === process.platform ? {} : { platform });
|
|
125
161
|
if (!opened.ok) {
|
|
126
162
|
return { ok: false, summary: opened.code === "folder-missing" ? "not installed" : `refused: ${opened.code}` };
|
|
127
163
|
}
|
|
@@ -154,18 +190,21 @@ function payload(event, hqRoot) {
|
|
|
154
190
|
: JSON.stringify({ hook_event_name: "UserPromptSubmit", prompt: "", session_id: SESSION_ID, cwd: hqRoot });
|
|
155
191
|
}
|
|
156
192
|
/**
|
|
157
|
-
*
|
|
158
|
-
* exit, not for stdout to close, so
|
|
159
|
-
* does not delay the result. A
|
|
160
|
-
* direct child only, never to
|
|
193
|
+
* `<shell> <file>` with the payload on stdin (shell: /bin/bash, or Git Bash
|
|
194
|
+
* on Windows). Waits for the direct child's exit, not for stdout to close, so
|
|
195
|
+
* a detached grandchild holding stdout open does not delay the result. A
|
|
196
|
+
* timeout sends SIGTERM and then SIGKILL to the direct child only, never to
|
|
197
|
+
* its process group. On Windows Node ends the direct child with
|
|
198
|
+
* TerminateProcess for either signal (there are no POSIX process groups), so
|
|
199
|
+
* the first kill already ends it and the second is a no-op.
|
|
161
200
|
*/
|
|
162
|
-
function runScript(file, spec, hqRoot, env, killGraceMs, drainMs) {
|
|
201
|
+
function runScript(shell, file, spec, hqRoot, env, killGraceMs, drainMs) {
|
|
163
202
|
return new Promise((resolve) => {
|
|
164
203
|
const chunks = [];
|
|
165
204
|
let kept = 0;
|
|
166
205
|
let child;
|
|
167
206
|
try {
|
|
168
|
-
child = spawn(
|
|
207
|
+
child = spawn(shell, [file], {
|
|
169
208
|
cwd: hqRoot,
|
|
170
209
|
env: {
|
|
171
210
|
...env,
|
|
@@ -219,15 +258,17 @@ function runScript(file, spec, hqRoot, env, killGraceMs, drainMs) {
|
|
|
219
258
|
child.stdin?.end(payload(spec.event, hqRoot));
|
|
220
259
|
});
|
|
221
260
|
}
|
|
222
|
-
async function runOne(spec, options, env, disabled) {
|
|
261
|
+
async function runOne(spec, options, env, disabled, shell) {
|
|
223
262
|
const now = options.now ?? (() => new Date());
|
|
224
263
|
const at = () => now().toISOString();
|
|
225
264
|
if (disabled.has(spec.id))
|
|
226
265
|
return { id: spec.id, status: "ok", checked_at: at(), summary: "disabled by HQ_DISABLED_HOOKS" };
|
|
227
|
-
|
|
266
|
+
if (shell === undefined)
|
|
267
|
+
return { id: spec.id, status: "unknown", checked_at: at(), summary: MACHINE_CHECK_NO_GIT_BASH };
|
|
268
|
+
const checked = checkMachineCheckScript(options.hqRoot, spec.path, options.platform ?? process.platform);
|
|
228
269
|
if (!checked.ok)
|
|
229
270
|
return { id: spec.id, status: "unknown", checked_at: at(), summary: checked.summary };
|
|
230
|
-
const run = await runScript(checked.file, spec, path.resolve(options.hqRoot), env, options.killGraceMs ?? MACHINE_CHECK_KILL_GRACE_MS, options.drainMs ?? MACHINE_CHECK_DRAIN_MS);
|
|
271
|
+
const run = await runScript(shell, checked.file, spec, path.resolve(options.hqRoot), env, options.killGraceMs ?? MACHINE_CHECK_KILL_GRACE_MS, options.drainMs ?? MACHINE_CHECK_DRAIN_MS);
|
|
231
272
|
if (run.outcome === "timed-out") {
|
|
232
273
|
return { id: spec.id, status: "unknown", checked_at: at(), summary: `timed out after ${Math.round(spec.timeoutMs / 1000)}s` };
|
|
233
274
|
}
|
|
@@ -253,9 +294,10 @@ export function runMachineChecks(options) {
|
|
|
253
294
|
return inFlight;
|
|
254
295
|
const batch = (async () => {
|
|
255
296
|
const disabled = disabledIds(env);
|
|
297
|
+
const shell = machineCheckShell(options.platform ?? process.platform, env, options.resolveBash);
|
|
256
298
|
const results = [];
|
|
257
299
|
for (const spec of options.checks ?? MACHINE_CHECKS) {
|
|
258
|
-
results.push(await runOne(spec, options, env, disabled));
|
|
300
|
+
results.push(await runOne(spec, options, env, disabled, shell));
|
|
259
301
|
}
|
|
260
302
|
if (options.resultsFile)
|
|
261
303
|
writeMachineCheckResults(options.resultsFile, results, options.resultsWrite);
|
package/dist/lib/daemon/run.js
CHANGED
|
@@ -15,6 +15,7 @@ import { loadCachedTokens } from "@indigoai-us/hq-cloud";
|
|
|
15
15
|
import { CLI_VERSION } from "../../cli-version.js";
|
|
16
16
|
import { anywhereRuntimeEnabled } from "../../commands/anywhere-runtime-flag.js";
|
|
17
17
|
import { anywhereRuntimeAllowed, readHqAnywherePersonSetting, stickyPersonSettingReader } from "../anywhere-person-setting.js";
|
|
18
|
+
import { watchRuntimeInputs } from "./runtime-notifications.js";
|
|
18
19
|
import { currentPackageUseLeaseInstall, currentPackageUseUpdateRequested } from "../../utils/package-use-lease.js";
|
|
19
20
|
import { isLocalDependencyInstall, resolveRunningInstall } from "../../utils/version-gate.js";
|
|
20
21
|
import { agentKitPaths } from "../agent-kit/paths.js";
|
|
@@ -67,6 +68,9 @@ import { userToolDirs } from "./tools.js";
|
|
|
67
68
|
import { logOffset, readLogSince, readUnitHolds, writeUnitHolds } from "./unit-holds.js";
|
|
68
69
|
import { createTccEpermGuard, TCC_EPERM_SENTRY_FINGERPRINT } from "./tcc-eperm.js";
|
|
69
70
|
import { daemonRunGuard } from "./lanes-reconcile-guard.js";
|
|
71
|
+
import { startStopJobDrainer } from "./stop-jobs.js";
|
|
72
|
+
import { executeStopJob, pruneStopJobResults, stopJobCompleted } from "./stop-job-executor.js";
|
|
73
|
+
import { closeStopDiagnosticCursor, drainStopDiagnostics } from "./stop-diagnostics.js";
|
|
70
74
|
export const LOG_ROTATE_BYTES = 5 * 1024 * 1024;
|
|
71
75
|
/** Exit code for "restart me": non-zero so every service manager relaunches (Windows tasks only restart on failure). */
|
|
72
76
|
export const RESTART_EXIT_CODE = 75;
|
|
@@ -976,7 +980,53 @@ export async function runDaemon(opts) {
|
|
|
976
980
|
laneReconcileHandlerLoadInFlight = false;
|
|
977
981
|
});
|
|
978
982
|
};
|
|
983
|
+
const stopJobAbort = new AbortController();
|
|
984
|
+
const ownsStopQueue = () => path.resolve(paths.root) === path.resolve(home, ".hq/daemon")
|
|
985
|
+
&& readPidLock(paths.lockPath)?.pid === process.pid;
|
|
986
|
+
let stopDiagnosticsRunning = false;
|
|
987
|
+
let stopDiagnosticRoot;
|
|
988
|
+
const stopDiagnosticTimer = setInterval(() => {
|
|
989
|
+
const root = readDaemonConfig(paths.configPath).hqRoot ?? env.HQ_ROOT;
|
|
990
|
+
if (stopDiagnosticRoot && (root !== stopDiagnosticRoot || !ownsStopQueue())) {
|
|
991
|
+
closeStopDiagnosticCursor(stopDiagnosticRoot);
|
|
992
|
+
stopDiagnosticRoot = undefined;
|
|
993
|
+
}
|
|
994
|
+
if (!root || stopDiagnosticsRunning || !ownsStopQueue())
|
|
995
|
+
return;
|
|
996
|
+
stopDiagnosticRoot = root;
|
|
997
|
+
stopDiagnosticsRunning = true;
|
|
998
|
+
void drainStopDiagnostics({ root, ownsQueue: ownsStopQueue, log: message => log("warn", message) })
|
|
999
|
+
.catch(error => log("warn", `Stop diagnostic drain failed: ${String(error)}`))
|
|
1000
|
+
.finally(() => { stopDiagnosticsRunning = false; });
|
|
1001
|
+
}, 5000);
|
|
1002
|
+
stopDiagnosticTimer.unref();
|
|
1003
|
+
const stopJobDrainer = startStopJobDrainer({
|
|
1004
|
+
home,
|
|
1005
|
+
ownsQueue: ownsStopQueue,
|
|
1006
|
+
completed: job => {
|
|
1007
|
+
const root = readDaemonConfig(paths.configPath).hqRoot ?? env.HQ_ROOT;
|
|
1008
|
+
return root !== undefined && stopJobCompleted(job, root);
|
|
1009
|
+
},
|
|
1010
|
+
pruneResults: olderThan => {
|
|
1011
|
+
const root = readDaemonConfig(paths.configPath).hqRoot ?? env.HQ_ROOT;
|
|
1012
|
+
if (root)
|
|
1013
|
+
pruneStopJobResults(root, olderThan);
|
|
1014
|
+
},
|
|
1015
|
+
execute: job => executeStopJob(job, {
|
|
1016
|
+
nodeBinary: opts.nodeBinary,
|
|
1017
|
+
hqBinary: opts.hqBinary,
|
|
1018
|
+
allowedRoot: readDaemonConfig(paths.configPath).hqRoot ?? env.HQ_ROOT,
|
|
1019
|
+
signal: stopJobAbort.signal,
|
|
1020
|
+
}),
|
|
1021
|
+
log: message => log("warn", message),
|
|
1022
|
+
});
|
|
1023
|
+
/** Closes the watchers; the promise settles once the Stop job in progress (if any) has written its receipt. */
|
|
979
1024
|
const closeRuntimeWatchers = () => {
|
|
1025
|
+
if (stopDiagnosticRoot)
|
|
1026
|
+
closeStopDiagnosticCursor(stopDiagnosticRoot);
|
|
1027
|
+
clearInterval(stopDiagnosticTimer);
|
|
1028
|
+
stopJobAbort.abort();
|
|
1029
|
+
const stopJobsClosed = stopJobDrainer.close().catch((err) => log("warn", `Stop job drainer did not close cleanly: ${String(err)}`));
|
|
980
1030
|
laneReconcileWatcher?.close();
|
|
981
1031
|
laneReconcileWatcher = null;
|
|
982
1032
|
laneReconcileWatcherRoot = null;
|
|
@@ -984,6 +1034,7 @@ export async function runDaemon(opts) {
|
|
|
984
1034
|
machineChecks.close();
|
|
985
1035
|
flagSnapshots.close();
|
|
986
1036
|
stateWriter.close();
|
|
1037
|
+
return stopJobsClosed;
|
|
987
1038
|
};
|
|
988
1039
|
const plan = () => {
|
|
989
1040
|
const config = readDaemonConfig(paths.configPath);
|
|
@@ -1535,7 +1586,11 @@ export async function runDaemon(opts) {
|
|
|
1535
1586
|
subscribe: (notify) => hqdRuntimeEvents.subscribe(notify),
|
|
1536
1587
|
log: (error) => log("error", `hqd socket listener update failed: ${error.message ?? String(error)}`),
|
|
1537
1588
|
});
|
|
1589
|
+
// A sign-in or daemon config change can flip the hqd gate before the next
|
|
1590
|
+
// shared read; the watch wakes the listener so it checks now.
|
|
1591
|
+
const stopHqdInputWatch = watchRuntimeInputs([paths.configPath, path.join(home, ".hq", "cognito-tokens.json")], () => hqdRuntimeEvents.emit(), (error) => log("warn", `hqd runtime input watch failed: ${error instanceof Error ? error.name : "UnknownError"}`));
|
|
1538
1592
|
const closeHqd = () => {
|
|
1593
|
+
stopHqdInputWatch();
|
|
1539
1594
|
void hqdListener.close().catch((err) => log("warn", `hqd socket did not close cleanly: ${err.message}`));
|
|
1540
1595
|
};
|
|
1541
1596
|
return await new Promise((resolve) => {
|
|
@@ -1549,14 +1604,15 @@ export async function runDaemon(opts) {
|
|
|
1549
1604
|
tccEpermGuard.dispose();
|
|
1550
1605
|
log("info", `${why}; stopping services`);
|
|
1551
1606
|
closeHqd();
|
|
1552
|
-
|
|
1607
|
+
// The aborted Stop job's receipt is written before the lease is released.
|
|
1608
|
+
const stopJobsClosed = closeRuntimeWatchers();
|
|
1553
1609
|
// Keep shutdown bounded, but let a stopping sync runner reach its persist deadline.
|
|
1554
1610
|
const cap = createShutdownCap();
|
|
1555
1611
|
extendSyncShutdownCap = cap.extendForSyncRunnerPersist;
|
|
1556
1612
|
if (supervisor.hasStoppingSyncRunner())
|
|
1557
1613
|
cap.extendForSyncRunnerPersist();
|
|
1558
1614
|
const servicesStopped = supervisor.stop();
|
|
1559
|
-
void Promise.race([servicesStopped, cap.promise]).then((result) => {
|
|
1615
|
+
void Promise.race([Promise.all([servicesStopped, stopJobsClosed]).then(([result]) => result), cap.promise]).then((result) => {
|
|
1560
1616
|
cap.clear();
|
|
1561
1617
|
extendSyncShutdownCap = undefined;
|
|
1562
1618
|
if (result === "timeout")
|
|
@@ -1579,7 +1635,7 @@ export async function runDaemon(opts) {
|
|
|
1579
1635
|
daemonStopping = true;
|
|
1580
1636
|
tccEpermGuard.dispose();
|
|
1581
1637
|
closeHqd();
|
|
1582
|
-
closeRuntimeWatchers();
|
|
1638
|
+
const stopJobsClosed = closeRuntimeWatchers();
|
|
1583
1639
|
const released = supervisor.release();
|
|
1584
1640
|
// What these readers have not read stays in the FIFO for the next daemon.
|
|
1585
1641
|
for (const tail of protocolTails)
|
|
@@ -1611,10 +1667,17 @@ export async function runDaemon(opts) {
|
|
|
1611
1667
|
// The released processes must not keep this one alive.
|
|
1612
1668
|
for (const child of spawned)
|
|
1613
1669
|
child.unref();
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1670
|
+
// The aborted Stop job's receipt is written before the lease is released
|
|
1671
|
+
// (bounded: the job's child is already signalled).
|
|
1672
|
+
let handOverTimer;
|
|
1673
|
+
void Promise.race([stopJobsClosed, new Promise((done) => { handOverTimer = setTimeout(done, 3_000); handOverTimer.unref(); })]).then(() => {
|
|
1674
|
+
if (handOverTimer)
|
|
1675
|
+
clearTimeout(handOverTimer);
|
|
1676
|
+
releaseDaemonLock(paths.lockPath);
|
|
1677
|
+
resolve(RESTART_EXIT_CODE);
|
|
1678
|
+
// Anything else still holding the event loop open must not delay the restart.
|
|
1679
|
+
setTimeout(() => process.exit(RESTART_EXIT_CODE), 5_000).unref();
|
|
1680
|
+
});
|
|
1618
1681
|
};
|
|
1619
1682
|
restartDaemon = () => {
|
|
1620
1683
|
if (!restartsForParent(opts)) {
|
|
@@ -1649,7 +1712,7 @@ export async function runDaemon(opts) {
|
|
|
1649
1712
|
catch (err) {
|
|
1650
1713
|
log("error", `supervisor failed to start: ${err.message}`);
|
|
1651
1714
|
closeHqd();
|
|
1652
|
-
closeRuntimeWatchers();
|
|
1715
|
+
void closeRuntimeWatchers();
|
|
1653
1716
|
releaseDaemonLock(paths.lockPath);
|
|
1654
1717
|
resolve(1);
|
|
1655
1718
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Watch the directories of the given files, so atomic replacement is seen.
|
|
2
|
+
* The interval only re-arms a watch that failed or whose directory did not
|
|
3
|
+
* exist yet; a newly armed watch reports a change, since the file may have
|
|
4
|
+
* appeared unseen. Missed events are covered by the hqd listener's own rare
|
|
5
|
+
* fallback check (anywhere-listener.ts), not here. */
|
|
6
|
+
export declare function watchRuntimeInputs(files: readonly string[], changed: () => void, onError: (error: unknown) => void, intervalMs?: number): () => void;
|
|
7
|
+
//# sourceMappingURL=runtime-notifications.d.ts.map
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
/** Watch the directories of the given files, so atomic replacement is seen.
|
|
4
|
+
* The interval only re-arms a watch that failed or whose directory did not
|
|
5
|
+
* exist yet; a newly armed watch reports a change, since the file may have
|
|
6
|
+
* appeared unseen. Missed events are covered by the hqd listener's own rare
|
|
7
|
+
* fallback check (anywhere-listener.ts), not here. */
|
|
8
|
+
export function watchRuntimeInputs(files, changed, onError, intervalMs = 60_000) {
|
|
9
|
+
const watched = new Map();
|
|
10
|
+
const directories = [...new Set(files.map((file) => path.dirname(file)))];
|
|
11
|
+
let closed = false;
|
|
12
|
+
const arm = () => {
|
|
13
|
+
let armed = false;
|
|
14
|
+
for (const directory of directories) {
|
|
15
|
+
if (watched.has(directory))
|
|
16
|
+
continue;
|
|
17
|
+
try {
|
|
18
|
+
const watcher = fs.watch(directory, { persistent: false }, (_event, filename) => {
|
|
19
|
+
if (!filename || files.some((file) => path.dirname(file) === directory && path.basename(file) === filename.toString()))
|
|
20
|
+
changed();
|
|
21
|
+
});
|
|
22
|
+
watcher.on("error", (error) => {
|
|
23
|
+
watcher.close();
|
|
24
|
+
watched.delete(directory);
|
|
25
|
+
onError(error);
|
|
26
|
+
});
|
|
27
|
+
watcher.on("close", () => { watched.delete(directory); });
|
|
28
|
+
watched.set(directory, watcher);
|
|
29
|
+
armed = true;
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
if (error.code !== "ENOENT")
|
|
33
|
+
onError(error);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return armed;
|
|
37
|
+
};
|
|
38
|
+
arm();
|
|
39
|
+
const timer = setInterval(() => { if (!closed && arm())
|
|
40
|
+
changed(); }, intervalMs);
|
|
41
|
+
timer.unref();
|
|
42
|
+
return () => {
|
|
43
|
+
closed = true;
|
|
44
|
+
clearInterval(timer);
|
|
45
|
+
for (const watcher of watched.values())
|
|
46
|
+
watcher.close();
|
|
47
|
+
watched.clear();
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=runtime-notifications.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** Why the folder that holds lock `directory` cannot hold it, or undefined.
|
|
2
|
+
* The folder is resolved first (macOS /tmp is a link to /private/tmp) and must
|
|
3
|
+
* be owned by this user or root and closed to group and other writes, unless
|
|
4
|
+
* it is a root-owned sticky folder such as /tmp: there another user cannot
|
|
5
|
+
* remove or rename this user's lock, and the lock folder itself is checked as
|
|
6
|
+
* a private store before it is used. A store check of the parent itself would
|
|
7
|
+
* refuse /tmp (owned by root, world-writable), which made autosave skip every
|
|
8
|
+
* file on Linux without TMPDIR.
|
|
9
|
+
*/
|
|
10
|
+
export declare function lockParentRefusal(directory: string): string | undefined;
|
|
11
|
+
/** Recover only an old, private autosave lock whose owner is definitely gone.
|
|
12
|
+
* Live or unreadable process identity stays held. The renamed directory is
|
|
13
|
+
* checked against the original inode before anything inside it is removed.
|
|
14
|
+
*/
|
|
15
|
+
export declare function acquireAutosaveLock(directory: string, now: number, staleMinutes: number, alive?: (pid: number) => boolean | undefined, birth?: (pid: number) => string | undefined): {
|
|
16
|
+
recovered: boolean;
|
|
17
|
+
release(): void;
|
|
18
|
+
} | undefined;
|
|
19
|
+
//# sourceMappingURL=stop-autosave-lock.d.ts.map
|