@indigoai-us/hq-cli 5.345.221 → 5.345.223
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 +70 -1
- package/dist/command-catalog.generated.d.ts +31 -0
- package/dist/command-catalog.generated.js +38 -0
- package/dist/commands/auth.js +2 -1
- package/dist/commands/bot.d.ts +1 -1
- package/dist/commands/bot.js +34 -33
- package/dist/commands/core-delegate-w1b.js +216 -190
- package/dist/commands/daemon.d.ts +1 -0
- package/dist/commands/daemon.js +15 -1
- package/dist/commands/link.d.ts +2 -0
- package/dist/commands/link.js +14 -2
- package/dist/commands/mesh.js +23 -3
- package/dist/commands/packs.js +13 -2
- package/dist/commands/sync-core.d.ts +6 -0
- package/dist/commands/sync-core.js +75 -1
- package/dist/data/command-states.json +3 -0
- package/dist/lib/bot/fleet-cron.d.ts +26 -3
- package/dist/lib/bot/fleet-cron.js +44 -4
- package/dist/lib/bot/run.d.ts +4 -4
- package/dist/lib/bot/run.js +5 -3
- package/dist/lib/bot/signals-engine-flag.d.ts +53 -13
- package/dist/lib/bot/signals-engine-flag.js +202 -9
- package/dist/lib/daemon/catalog.js +2 -0
- package/dist/lib/daemon/install.d.ts +2 -1
- package/dist/lib/daemon/install.js +9 -0
- package/dist/lib/daemon/legacy.d.ts +1 -0
- package/dist/lib/daemon/legacy.js +5 -2
- package/dist/lib/daemon/machine-check-owner.d.ts +2 -0
- package/dist/lib/daemon/machine-check-owner.js +6 -1
- package/dist/lib/daemon/machine-checks.d.ts +52 -1
- package/dist/lib/daemon/machine-checks.js +104 -11
- package/dist/lib/daemon/mesh-owner.d.ts +45 -0
- package/dist/lib/daemon/mesh-owner.js +166 -0
- package/dist/lib/daemon/native-notice-ledger.d.ts +36 -0
- package/dist/lib/daemon/native-notice-ledger.js +156 -0
- package/dist/lib/daemon/run.d.ts +15 -0
- package/dist/lib/daemon/run.js +72 -3
- package/dist/lib/daemon/selfcheck.d.ts +35 -2
- package/dist/lib/daemon/selfcheck.js +118 -9
- package/dist/lib/daemon/supervisor.d.ts +10 -0
- package/dist/lib/daemon/supervisor.js +86 -0
- package/dist/lib/flag-registry-worker-source.generated.d.ts +1 -1
- package/dist/lib/flag-registry-worker-source.generated.js +1 -1
- package/dist/lib/flag-registry-worker.js +33 -3
- package/dist/lib/flag-registry.js +13 -0
- package/dist/lib/hook-engine/coverage.d.ts +9 -0
- package/dist/lib/hook-engine/coverage.js +56 -0
- package/dist/lib/hook-engine/native-stop-compatibility.json +56 -5
- package/dist/lib/mesh/live/daemon/config.d.ts +8 -1
- package/dist/lib/mesh/live/daemon/config.js +16 -0
- package/dist/lib/mesh/live/daemon/install.d.ts +31 -2
- package/dist/lib/mesh/live/daemon/install.js +142 -1
- package/dist/lib/mesh/live/daemon/login-home.d.ts +5 -0
- package/dist/lib/mesh/live/daemon/login-home.js +27 -0
- package/dist/lib/mesh/live/daemon/unit-home.d.ts +49 -0
- package/dist/lib/mesh/live/daemon/unit-home.js +134 -0
- package/dist/lib/registry/registry.d.ts +35 -7
- package/dist/lib/registry/registry.js +88 -13
- package/dist/lib/scan-packages/index.js +23 -2
- package/dist/lib/search-index/max-doc-bytes.js +2 -1
- package/dist/lib/service-manager/startup-migration.d.ts +1 -0
- package/dist/lib/service-manager/startup-migration.js +3 -0
- package/dist/lib/signals/engine.d.ts +8 -0
- package/dist/lib/signals/engine.js +15 -5
- package/dist/lib/sync-core/engine-holds.d.ts +14 -0
- package/dist/lib/sync-core/engine-holds.js +60 -0
- package/dist/lib/sync-core/engine-home.d.ts +2 -0
- package/dist/lib/sync-core/flag.d.ts +18 -0
- package/dist/lib/sync-core/flag.js +66 -0
- package/dist/lib/sync-core/reconcile.d.ts +6 -0
- package/dist/lib/sync-core/reconcile.js +23 -0
- package/dist/lib/sync-core/rollout-state.d.ts +2 -0
- package/dist/lib/sync-core/rollout-state.js +7 -0
- package/dist/lib/sync-core/vault-settings.d.ts +32 -0
- package/dist/lib/sync-core/vault-settings.js +147 -0
- package/dist/lib/windows/install-followup.d.ts +2 -0
- package/dist/lib/windows/install-followup.js +4 -1
- package/dist/utils/host-registration.js +3 -1
- package/dist/utils/pack-contributions.d.ts +16 -1
- package/dist/utils/pack-contributions.js +139 -26
- package/dist/utils/self-update.d.ts +3 -1
- package/dist/utils/self-update.js +56 -11
- package/dist/utils/update-lock.d.ts +151 -14
- package/dist/utils/update-lock.js +782 -46
- package/dist/utils/version-gate.js +12 -2
- package/package.json +7 -7
- package/scripts/bench-core.mjs +34 -3
|
@@ -68,11 +68,13 @@ import { CLI_NAME, CLI_VERSION } from "../cli-version.js";
|
|
|
68
68
|
import { buildBunInstallArgv, buildPnpmInstallArgv, buildPrefixedInstallArgv, buildSpawnPlan, canWriteNpmInstall, captureNonWritableNpmPrefixNotice, claimNonWritableNpmPrefixNotice, checkUpdateConvergence, derivePnpmHome, detachUpdateSupervisor, isBunManagedPackageDir, isLocalDependencyInstall, isPnpmManagedPackageDir, normalizeRunningInstall, nonWritablePrefixNote, openInstallOutput, resolvePnpmPathInstall, pnpmUpdateEnv, pnpmInstalledVersion, performPnpmUpdate, resolveRunningInstall, runUpdateCommand, runSupervisedUpdateCommand, UPDATE_RECURSION_GUARD_ENV, } from "./version-gate.js";
|
|
69
69
|
import { canStageInstall, stagedNpmInstall } from "./staged-install.js";
|
|
70
70
|
import { npmGlobalInstallArgv } from "./npm-install-flags.js";
|
|
71
|
-
import { acquireUpdateLock as acquireSharedUpdateLock } from "./update-lock.js";
|
|
71
|
+
import { acquireUpdateLock as acquireSharedUpdateLock, STARTUP_TAKEOVER_WAIT_MS, } from "./update-lock.js";
|
|
72
72
|
import { markLatestIneffective } from "./version-check.js";
|
|
73
73
|
import { fileSelfUpdateBackoff } from "./self-update-backoff.js";
|
|
74
74
|
import { removeHqCliPs1Shims } from "../lib/windows/ps1-shims.js";
|
|
75
75
|
import { restartDaemonServiceIfInstalled } from "../lib/mesh/live/daemon/install.js";
|
|
76
|
+
import { meshOwnerHere, repairHqDaemonUnitFromOtherHome } from "../lib/daemon/mesh-owner.js";
|
|
77
|
+
import { homedir } from "node:os";
|
|
76
78
|
import { createCurrentPackageUseLeaseHandoff, PACKAGE_USE_LEASE_HANDOFF_ENV, releaseCurrentPackageUseLease, } from "./package-use-lease.js";
|
|
77
79
|
/**
|
|
78
80
|
* Set on the re-exec'd child so it can never self-update (and re-exec) again.
|
|
@@ -732,8 +734,13 @@ export function runUpdateQuiet(cmd, args, env, cwd) {
|
|
|
732
734
|
* instead of each tool keeping its own.
|
|
733
735
|
*/
|
|
734
736
|
export function acquireUpdateLock(now = Date.now()) {
|
|
735
|
-
|
|
736
|
-
|
|
737
|
+
// Runs before the user's command, so it waits only briefly for the mutex.
|
|
738
|
+
const handle = acquireSharedUpdateLock({
|
|
739
|
+
now,
|
|
740
|
+
tool: "hq-cli-self-update",
|
|
741
|
+
takeoverWaitMs: STARTUP_TAKEOVER_WAIT_MS,
|
|
742
|
+
});
|
|
743
|
+
return handle ? Object.assign(() => handle.release(), { stillHeld: handle.stillHeld }) : null;
|
|
737
744
|
}
|
|
738
745
|
/**
|
|
739
746
|
* Re-run `hq <argv…>` from PATH so the freshly-installed version handles the
|
|
@@ -866,10 +873,15 @@ async function updateAndReexec(argv, flavor, known, deps) {
|
|
|
866
873
|
return { action: "skipped" };
|
|
867
874
|
}
|
|
868
875
|
let outcome;
|
|
876
|
+
const heldLock = {};
|
|
869
877
|
try {
|
|
870
|
-
outcome = await attemptUpdateAndReexec(argv, flavor, known, deps, env);
|
|
878
|
+
outcome = await attemptUpdateAndReexec(argv, flavor, known, deps, env, heldLock);
|
|
871
879
|
}
|
|
872
880
|
catch (error) {
|
|
881
|
+
// A throw between taking the lock and the install's own finally must not
|
|
882
|
+
// leave the lock held: its heartbeat would keep it fresh for as long as
|
|
883
|
+
// this process lives (the daemon runs for days).
|
|
884
|
+
heldLock.release?.();
|
|
873
885
|
if (known)
|
|
874
886
|
backoff.record(known);
|
|
875
887
|
else
|
|
@@ -887,7 +899,17 @@ async function updateAndReexec(argv, flavor, known, deps) {
|
|
|
887
899
|
}
|
|
888
900
|
return outcome;
|
|
889
901
|
}
|
|
890
|
-
|
|
902
|
+
/** Release at most once, keeping `stillHeld`. */
|
|
903
|
+
function releaseOnce(release) {
|
|
904
|
+
let done = false;
|
|
905
|
+
return Object.assign(() => {
|
|
906
|
+
if (done)
|
|
907
|
+
return;
|
|
908
|
+
done = true;
|
|
909
|
+
release();
|
|
910
|
+
}, release.stillHeld ? { stillHeld: release.stillHeld } : {});
|
|
911
|
+
}
|
|
912
|
+
async function attemptUpdateAndReexec(argv, flavor, known, deps, env, heldLock = {}) {
|
|
891
913
|
const latest = known ?? (await (deps.fetchLatest ?? fetchLatestVersion)());
|
|
892
914
|
if (!latest)
|
|
893
915
|
return { action: "skipped" };
|
|
@@ -941,9 +963,11 @@ async function attemptUpdateAndReexec(argv, flavor, known, deps, env) {
|
|
|
941
963
|
}
|
|
942
964
|
install = pathTarget.install;
|
|
943
965
|
}
|
|
944
|
-
const
|
|
945
|
-
if (!
|
|
966
|
+
const acquired = flavor.lock ? (deps.acquireLock ?? acquireUpdateLock)() : () => { };
|
|
967
|
+
if (!acquired)
|
|
946
968
|
return { action: "skipped", latest };
|
|
969
|
+
const releaseLock = releaseOnce(acquired);
|
|
970
|
+
heldLock.release = releaseLock;
|
|
947
971
|
if (install.manager === "npm" &&
|
|
948
972
|
install.prefix &&
|
|
949
973
|
install.packageRoot &&
|
|
@@ -965,6 +989,13 @@ async function attemptUpdateAndReexec(argv, flavor, known, deps, env) {
|
|
|
965
989
|
return { action: "update-failed", latest };
|
|
966
990
|
}
|
|
967
991
|
const staged = canStageInstall(install) && (await readStagedSelfUpdateFlag(deps, env));
|
|
992
|
+
// A racing taker may have moved our lock since acquisition: another
|
|
993
|
+
// installer may be running, so skip before touching the install.
|
|
994
|
+
const lockCheck = releaseLock;
|
|
995
|
+
if (typeof lockCheck.stillHeld === "function" && !lockCheck.stillHeld()) {
|
|
996
|
+
releaseLock();
|
|
997
|
+
return { action: "skipped", latest };
|
|
998
|
+
}
|
|
968
999
|
const renamePath = deps.renamePath ?? fs.renameSync;
|
|
969
1000
|
// The staged install keeps the running package in place until the swap and
|
|
970
1001
|
// restores it itself, so it takes no snapshot.
|
|
@@ -1162,10 +1193,24 @@ async function attemptUpdateAndReexec(argv, flavor, known, deps, env) {
|
|
|
1162
1193
|
// A resident mesh daemon keeps the old JS loaded after a global install.
|
|
1163
1194
|
// Service restart is best-effort and cannot turn a successful update red.
|
|
1164
1195
|
try {
|
|
1165
|
-
const restart = (deps.restartDaemon ?? (() =>
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1196
|
+
const restart = (deps.restartDaemon ?? (() => {
|
|
1197
|
+
const uid = process.getuid?.();
|
|
1198
|
+
if (process.platform === "darwin" && typeof uid === "number") {
|
|
1199
|
+
try {
|
|
1200
|
+
const daemon = repairHqDaemonUnitFromOtherHome({ home: homedir(), uid, env });
|
|
1201
|
+
if (daemon.message)
|
|
1202
|
+
console.error(chalk.yellow(` ${daemon.message}`));
|
|
1203
|
+
}
|
|
1204
|
+
catch (error) {
|
|
1205
|
+
console.error(chalk.yellow(` Could not check the hq daemon service: ${error instanceof Error ? error.message : String(error)}`));
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
return restartDaemonServiceIfInstalled({
|
|
1209
|
+
env,
|
|
1210
|
+
hqRoot: env.HQ_ROOT,
|
|
1211
|
+
meshOwner: () => meshOwnerHere(homedir(), env),
|
|
1212
|
+
});
|
|
1213
|
+
}))();
|
|
1169
1214
|
if (restart?.message)
|
|
1170
1215
|
console.error(chalk.yellow(` ${restart.message}`));
|
|
1171
1216
|
}
|
|
@@ -18,21 +18,59 @@
|
|
|
18
18
|
* CLI updates. Do not change either without a coordinated hq-sync release.
|
|
19
19
|
*
|
|
20
20
|
* Path: $HOME/.hq/locks/cli-update.lock
|
|
21
|
-
* Content: JSON object with
|
|
21
|
+
* Content: JSON object with these fields:
|
|
22
22
|
* {
|
|
23
23
|
* "pid": <number> — owning process id,
|
|
24
|
-
* "startedAt": <string> — ISO-8601 acquisition
|
|
24
|
+
* "startedAt": <string> — ISO-8601 time of acquisition or of the
|
|
25
|
+
* holder's latest heartbeat,
|
|
25
26
|
* "tool": <string> — which actor holds it (e.g. "hq-cli-version-gate"),
|
|
26
|
-
* "version": <string> — the holder's own version
|
|
27
|
+
* "version": <string> — the holder's own version,
|
|
28
|
+
* "nonce": <string> — OPTIONAL, identifies one acquisition (the
|
|
29
|
+
* desktop app writes one too; readers that do
|
|
30
|
+
* not know it ignore it)
|
|
27
31
|
* }
|
|
28
|
-
* Staleness
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
+
* Staleness (same rules as hq-desktop-app's `stored_lock_is_stale`): a
|
|
33
|
+
* holder is stale when `startedAt` is at least 10 minutes old, or at least
|
|
34
|
+
* 10 minutes in the future (a skewed clock cannot pin the lock), OR its `pid`
|
|
35
|
+
* is no longer alive (`kill(pid, 0)` → ESRCH; Node maps the Windows
|
|
36
|
+
* `OpenProcess` probe the same way, and access denied counts as alive). A
|
|
37
|
+
* legacy lock with `startedAt` but no `pid` retires by age only. A stale
|
|
38
|
+
* lock may be removed and re-acquired; a fresh one means "someone else is
|
|
39
|
+
* installing the very version you want — skip".
|
|
40
|
+
* Heartbeat: while held, the holder rewrites `startedAt` every 60 seconds
|
|
41
|
+
* inside the takeover mutex (both sides), so an install that legitimately
|
|
42
|
+
* runs past 10 minutes is never judged stale. The 10-minute TTL is kept
|
|
43
|
+
* because it bounds how long a crashed holder blocks updates; the heartbeat
|
|
44
|
+
* is what keeps a long hold safe.
|
|
32
45
|
* ────────────────────────────────────────────────────────────────────────────
|
|
33
46
|
*
|
|
34
|
-
* Mechanics:
|
|
35
|
-
*
|
|
47
|
+
* Mechanics: the body is written to a temp file and hard-linked to the lock
|
|
48
|
+
* name (an atomic create-new), so the lock is never visible empty; 'wx' is
|
|
49
|
+
* the fallback where hard links are unavailable. A stale lock is renamed
|
|
50
|
+
* aside and deleted only if it still matches what was judged stale; release
|
|
51
|
+
* deletes only a file still holding this process's exact body. An
|
|
52
|
+
* unparseable lock younger than 30 seconds is left alone (mid-write).
|
|
53
|
+
* Publish, takeover and release run inside the `cli-update.lock.takeover` mkdir
|
|
54
|
+
* mutex shared with hq-desktop-app. Release leaves the lock in place when the
|
|
55
|
+
* mutex stays busy; the lock is reclaimed once its holder exits or the TTL
|
|
56
|
+
* passes, and rechecks the lock's content after taking the mutex, because a
|
|
57
|
+
* takeover can finish between the first check and the mutex. The directory is
|
|
58
|
+
* never moved. Each holder keeps a uniquely named file inside it, with the time
|
|
59
|
+
* it was taken in the name, and a crashed holder's mutex is taken by renaming
|
|
60
|
+
* that file to a new name: a rename either moves the file it judged stale or
|
|
61
|
+
* fails, so a judgment made earlier cannot touch a newer holder's mutex, and of
|
|
62
|
+
* several stealers exactly one wins. An acquirer holds the mutex only if its
|
|
63
|
+
* file is alone in the directory after it was written, so two processes that
|
|
64
|
+
* land in one directory cannot both proceed. A holder confirms its file is still
|
|
65
|
+
* there right before it moves the lock. Gaps that remain: a holder paused past
|
|
66
|
+
* the mutex TTL, or whose clock jumped forward past that TTL or back more than a
|
|
67
|
+
* day, can lose the mutex, and a theft in the moment between that check and the
|
|
68
|
+
* move goes unseen; mixed versions (an older CLI or desktop app without the
|
|
69
|
+
* mutex) can still race until both update. `stillHeld()` and the no-replace
|
|
70
|
+
* publish are the defenses there. A
|
|
71
|
+
* restore that cannot use a hard link leaves the moved file under its aside name
|
|
72
|
+
* (swept after the TTL), and the holder re-checks `stillHeld()` before
|
|
73
|
+
* installing. Unparseable lock content is
|
|
36
74
|
* treated as stale (a torn write from a crashed holder must not wedge updates
|
|
37
75
|
* forever). Everything is best-effort: any unexpected filesystem error reads
|
|
38
76
|
* as "lock held", because the callers' shared philosophy is that updating is
|
|
@@ -42,17 +80,42 @@
|
|
|
42
80
|
export declare const UPDATE_LOCK_STALE_MS: number;
|
|
43
81
|
/** `tool` recorded when this CLI takes the lock. */
|
|
44
82
|
export declare const UPDATE_LOCK_TOOL = "hq-cli-version-gate";
|
|
83
|
+
/**
|
|
84
|
+
* How often a holder rewrites `startedAt` while it holds the lock. Matches
|
|
85
|
+
* hq-desktop-app's `CLI_UPDATE_LOCK_HEARTBEAT` (60 s). An install may run up to
|
|
86
|
+
* the 30-minute update deadline, far past {@link UPDATE_LOCK_STALE_MS}. Without
|
|
87
|
+
* a refresh the desktop app (or another CLI) takes a live install's lock at
|
|
88
|
+
* 10 minutes and can start a second install on the same prefix.
|
|
89
|
+
*/
|
|
90
|
+
export declare const UPDATE_LOCK_HEARTBEAT_MS: number;
|
|
91
|
+
/**
|
|
92
|
+
* Wait for the takeover mutex on the start-up update paths (the required-update
|
|
93
|
+
* gate and the attended self-updater). The mutex only guards a few file
|
|
94
|
+
* operations, so a longer wait adds start-up latency without making a
|
|
95
|
+
* takeover more likely to succeed when the mutex is wedged.
|
|
96
|
+
*/
|
|
97
|
+
export declare const STARTUP_TAKEOVER_WAIT_MS = 1000;
|
|
98
|
+
/** How long release waits for the takeover mutex before deferring to exit. */
|
|
99
|
+
export declare const RELEASE_MUTEX_WAIT_MS = 2000;
|
|
45
100
|
export interface UpdateLockInfo {
|
|
46
101
|
pid: number;
|
|
47
102
|
startedAt: string;
|
|
48
103
|
tool: string;
|
|
49
104
|
version: string;
|
|
105
|
+
/** Identifies this acquisition; optional in the contract. */
|
|
106
|
+
nonce?: string;
|
|
50
107
|
}
|
|
51
108
|
export interface UpdateLockHandle {
|
|
52
109
|
/** Absolute path of the held lock file. */
|
|
53
110
|
path: string;
|
|
54
111
|
/** Delete the lock file. Idempotent, never throws. */
|
|
55
112
|
release: () => void;
|
|
113
|
+
/**
|
|
114
|
+
* Whether the lock file still holds exactly this process's body. Call it
|
|
115
|
+
* right before installing; false means a racing taker moved the lock and
|
|
116
|
+
* another installer may be running.
|
|
117
|
+
*/
|
|
118
|
+
stillHeld: () => boolean;
|
|
56
119
|
}
|
|
57
120
|
/** Injectable knobs so contention/staleness are unit-testable hermetically. */
|
|
58
121
|
export interface UpdateLockOptions {
|
|
@@ -62,23 +125,97 @@ export interface UpdateLockOptions {
|
|
|
62
125
|
isPidAlive?: (pid: number) => boolean;
|
|
63
126
|
tool?: string;
|
|
64
127
|
version?: string;
|
|
128
|
+
/** Wait for the shared takeover mutex (default 10 s). */
|
|
129
|
+
takeoverWaitMs?: number;
|
|
130
|
+
/** Stop waiting for the takeover mutex (the lock then reads as held). */
|
|
131
|
+
isCancelled?: () => boolean;
|
|
132
|
+
/** Test seam: runs between renaming a stale lock aside and checking it. */
|
|
133
|
+
afterTakeoverRename?: () => void;
|
|
134
|
+
/** Test seam: runs just before this process moves the lock file aside. */
|
|
135
|
+
beforeLockMove?: () => void;
|
|
136
|
+
/**
|
|
137
|
+
* Heartbeat interval while held (default {@link UPDATE_LOCK_HEARTBEAT_MS}).
|
|
138
|
+
* 0 disables the heartbeat.
|
|
139
|
+
*/
|
|
140
|
+
heartbeatMs?: number;
|
|
141
|
+
/** Wait for the takeover mutex on release (default {@link RELEASE_MUTEX_WAIT_MS}). */
|
|
142
|
+
releaseMutexWaitMs?: number;
|
|
143
|
+
/**
|
|
144
|
+
* Called with a retry when release could not take the takeover mutex. The
|
|
145
|
+
* default runs the retry once when the process exits.
|
|
146
|
+
*/
|
|
147
|
+
deferRelease?: (retry: () => void) => void;
|
|
65
148
|
}
|
|
149
|
+
/**
|
|
150
|
+
* Env var overriding the lock DIRECTORY (not the file name). Contract — matches
|
|
151
|
+
* hq-desktop-app's `LOCK_DIR_ENV`, so both sides use one lock when it is set.
|
|
152
|
+
*/
|
|
153
|
+
export declare const LOCK_DIR_ENV = "HQ_LOCK_DIR";
|
|
66
154
|
export declare function updateLockPath(): string;
|
|
67
155
|
/**
|
|
68
156
|
* Whether an existing lock's recorded holder is safe to displace: its
|
|
69
|
-
* `startedAt` is
|
|
157
|
+
* `startedAt` is at least {@link UPDATE_LOCK_STALE_MS} old or ahead, or its pid
|
|
158
|
+
* is dead.
|
|
70
159
|
* Unreadable / malformed content is stale by definition — only a crashed or
|
|
71
160
|
* interrupted holder leaves one behind, and treating it as fresh would block
|
|
72
161
|
* every future update on this machine.
|
|
73
162
|
*/
|
|
74
163
|
export declare function isLockStale(raw: string | null, now: number, isPidAlive: (pid: number) => boolean): boolean;
|
|
164
|
+
/**
|
|
165
|
+
* An unparseable lock younger than this may be a writer between create and
|
|
166
|
+
* write (older writers create the file before filling it), so it is not
|
|
167
|
+
* taken over yet. Matches the hq-desktop-app side.
|
|
168
|
+
*/
|
|
169
|
+
export declare const UNPARSEABLE_LOCK_GRACE_MS: number;
|
|
170
|
+
/**
|
|
171
|
+
* Takeover mutex shared with hq-desktop-app: a DIRECTORY named
|
|
172
|
+
* `cli-update.lock.takeover` next to the lock, created with an atomic mkdir
|
|
173
|
+
* (the same on macOS, Linux and Windows, and the same as the Rust side).
|
|
174
|
+
* Publish, takeover and release run inside it. A holder file inside it older
|
|
175
|
+
* than {@link TAKEOVER_MUTEX_STALE_MS} was left by a crashed process and is
|
|
176
|
+
* stolen by renaming it. Contract — matches hq-desktop-app's
|
|
177
|
+
* `CLI_UPDATE_TAKEOVER_FILE`.
|
|
178
|
+
*/
|
|
179
|
+
export declare const TAKEOVER_MUTEX_SUFFIX = ".takeover";
|
|
180
|
+
export declare const TAKEOVER_MUTEX_STALE_MS: number;
|
|
181
|
+
/** A holder file dated further ahead than this cannot be a clock correction. */
|
|
182
|
+
export declare const TAKEOVER_MUTEX_FUTURE_STALE_MS: number;
|
|
183
|
+
/** Default wait for the takeover mutex before reporting the lock as held. */
|
|
184
|
+
export declare const TAKEOVER_MUTEX_WAIT_MS: number;
|
|
185
|
+
/** Test seam points inside {@link acquireTakeoverMutex}. */
|
|
186
|
+
export type TakeoverMutexStage = "stale-judged" | "created" | "token-written";
|
|
187
|
+
/** Releases the takeover mutex when called. */
|
|
188
|
+
export type TakeoverMutexRelease = (() => void) & {
|
|
189
|
+
/** False once the holder file is gone, meaning another process stole the mutex. */
|
|
190
|
+
stillOwned: () => boolean;
|
|
191
|
+
};
|
|
192
|
+
/**
|
|
193
|
+
* Take the takeover mutex. Returns a release function, or null when the wait
|
|
194
|
+
* timed out or `isCancelled` returned true. Release removes the holder file and
|
|
195
|
+
* removes the directory only if that file was still there, so a holder whose
|
|
196
|
+
* mutex was stolen cannot remove the next holder's.
|
|
197
|
+
*/
|
|
198
|
+
export declare function acquireTakeoverMutex(lockPath: string, options?: {
|
|
199
|
+
waitMs?: number;
|
|
200
|
+
staleMs?: number;
|
|
201
|
+
isCancelled?: () => boolean;
|
|
202
|
+
/** Test seam: runs at each stage so a test can interleave another process. */
|
|
203
|
+
onStage?: (stage: TakeoverMutexStage) => void;
|
|
204
|
+
}): TakeoverMutexRelease | null;
|
|
205
|
+
/**
|
|
206
|
+
* Remove a lock judged stale: rename it aside, confirm it is exactly the
|
|
207
|
+
* content that was judged, and only then delete it. A mismatch means another
|
|
208
|
+
* process replaced it; put it back (or leave it aside) and report it held.
|
|
209
|
+
* `afterRename` is a test seam for interleaving another process.
|
|
210
|
+
*/
|
|
211
|
+
export declare function takeOverStale(lockPath: string, judged: string | null, afterRename?: () => void): boolean;
|
|
75
212
|
/**
|
|
76
213
|
* Take the machine-wide CLI-update lock, or return `null` when a fresh holder
|
|
77
|
-
* has it
|
|
78
|
-
*
|
|
79
|
-
* serialize correctly because the retry goes back through O_EXCL.
|
|
214
|
+
* has it or the takeover mutex could not be taken (this process should skip
|
|
215
|
+
* its install). Takeover and publish both run inside the shared mutex.
|
|
80
216
|
*
|
|
81
|
-
* Callers MUST
|
|
217
|
+
* Callers MUST call `stillHeld()` right before installing and release in a
|
|
218
|
+
* `finally` around the install.
|
|
82
219
|
*/
|
|
83
220
|
export declare function acquireUpdateLock(options?: UpdateLockOptions): UpdateLockHandle | null;
|
|
84
221
|
//# sourceMappingURL=update-lock.d.ts.map
|