@indigoai-us/hq-cli 5.345.221 → 5.345.222

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.
Files changed (64) hide show
  1. package/CHANGELOG.md +47 -1
  2. package/dist/command-catalog.generated.d.ts +31 -0
  3. package/dist/command-catalog.generated.js +38 -0
  4. package/dist/commands/auth.js +2 -1
  5. package/dist/commands/core-delegate-w1b.js +9 -3
  6. package/dist/commands/daemon.d.ts +1 -0
  7. package/dist/commands/daemon.js +15 -1
  8. package/dist/commands/link.d.ts +2 -0
  9. package/dist/commands/link.js +14 -2
  10. package/dist/commands/mesh.js +23 -3
  11. package/dist/commands/sync-core.d.ts +6 -0
  12. package/dist/commands/sync-core.js +55 -0
  13. package/dist/data/command-states.json +3 -0
  14. package/dist/lib/daemon/catalog.js +2 -0
  15. package/dist/lib/daemon/install.d.ts +2 -1
  16. package/dist/lib/daemon/install.js +9 -0
  17. package/dist/lib/daemon/legacy.d.ts +1 -0
  18. package/dist/lib/daemon/legacy.js +5 -2
  19. package/dist/lib/daemon/machine-check-owner.d.ts +2 -0
  20. package/dist/lib/daemon/machine-check-owner.js +6 -1
  21. package/dist/lib/daemon/machine-checks.d.ts +7 -1
  22. package/dist/lib/daemon/machine-checks.js +10 -1
  23. package/dist/lib/daemon/mesh-owner.d.ts +45 -0
  24. package/dist/lib/daemon/mesh-owner.js +166 -0
  25. package/dist/lib/daemon/native-notice-ledger.d.ts +27 -0
  26. package/dist/lib/daemon/native-notice-ledger.js +113 -0
  27. package/dist/lib/daemon/run.d.ts +15 -0
  28. package/dist/lib/daemon/run.js +71 -3
  29. package/dist/lib/daemon/selfcheck.d.ts +35 -2
  30. package/dist/lib/daemon/selfcheck.js +118 -9
  31. package/dist/lib/hook-engine/coverage.d.ts +9 -0
  32. package/dist/lib/hook-engine/coverage.js +56 -0
  33. package/dist/lib/hook-engine/native-stop-compatibility.json +56 -5
  34. package/dist/lib/mesh/live/daemon/config.d.ts +8 -1
  35. package/dist/lib/mesh/live/daemon/config.js +16 -0
  36. package/dist/lib/mesh/live/daemon/install.d.ts +31 -2
  37. package/dist/lib/mesh/live/daemon/install.js +142 -1
  38. package/dist/lib/mesh/live/daemon/login-home.d.ts +5 -0
  39. package/dist/lib/mesh/live/daemon/login-home.js +27 -0
  40. package/dist/lib/mesh/live/daemon/unit-home.d.ts +49 -0
  41. package/dist/lib/mesh/live/daemon/unit-home.js +134 -0
  42. package/dist/lib/registry/registry.d.ts +35 -7
  43. package/dist/lib/registry/registry.js +88 -13
  44. package/dist/lib/scan-packages/index.js +24 -2
  45. package/dist/lib/search-index/max-doc-bytes.js +2 -1
  46. package/dist/lib/service-manager/startup-migration.d.ts +1 -0
  47. package/dist/lib/service-manager/startup-migration.js +3 -0
  48. package/dist/lib/sync-core/engine-holds.d.ts +14 -0
  49. package/dist/lib/sync-core/engine-holds.js +60 -0
  50. package/dist/lib/sync-core/engine-home.d.ts +2 -0
  51. package/dist/lib/sync-core/reconcile.js +8 -0
  52. package/dist/lib/sync-core/vault-settings.d.ts +21 -0
  53. package/dist/lib/sync-core/vault-settings.js +131 -0
  54. package/dist/lib/windows/install-followup.d.ts +2 -0
  55. package/dist/lib/windows/install-followup.js +4 -1
  56. package/dist/utils/host-registration.js +3 -1
  57. package/dist/utils/pack-contributions.d.ts +3 -0
  58. package/dist/utils/pack-contributions.js +110 -23
  59. package/dist/utils/self-update.d.ts +3 -1
  60. package/dist/utils/self-update.js +56 -11
  61. package/dist/utils/update-lock.d.ts +151 -14
  62. package/dist/utils/update-lock.js +782 -46
  63. package/dist/utils/version-gate.js +12 -2
  64. package/package.json +7 -7
@@ -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 exactly these fields:
21
+ * Content: JSON object with these fields:
22
22
  * {
23
23
  * "pid": <number> — owning process id,
24
- * "startedAt": <string> — ISO-8601 acquisition timestamp,
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: a holder is stale when `startedAt` is older than 10 minutes OR
29
- * its `pid` is no longer alive (`kill(pid, 0)` → ESRCH). A stale lock may be
30
- * removed and re-acquired; a fresh one means "someone else is installing the
31
- * very version you want — skip".
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: acquisition is a single atomic `open(…, 'wx')` (O_CREAT|O_EXCL) —
35
- * no mkdir dance, no read-then-write window. Unparseable lock content is
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 older than {@link UPDATE_LOCK_STALE_MS}, or its pid is dead.
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 (this process should skip its install). A stale holder is removed and
78
- * acquisition retried exactly once — two genuinely-racing processes still
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 release in a `finally` around the install.
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