@indigoai-us/hq-cli 5.345.225 → 5.345.228
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 +174 -0
- package/dist/command-catalog.generated.d.ts +215 -0
- package/dist/command-catalog.generated.js +261 -0
- package/dist/commands/auth.d.ts +2 -2
- package/dist/commands/auth.js +3 -3
- package/dist/commands/core-delegate-w1b.js +92 -69
- package/dist/commands/core-delegate.d.ts +19 -1
- package/dist/commands/core-delegate.js +411 -6
- package/dist/commands/core-dm-bind-native.js +2 -1
- package/dist/commands/core-handoff.d.ts +5 -0
- package/dist/commands/core-handoff.js +1008 -14
- package/dist/commands/core-pin-native.d.ts +1 -0
- package/dist/commands/core-pin-native.js +3 -15
- package/dist/commands/core-register-project-native.d.ts +6 -0
- package/dist/commands/core-register-project-native.js +182 -52
- package/dist/commands/core-work-mesh-bind-trusted-native.js +4 -9
- package/dist/commands/daemon.js +3 -3
- package/dist/commands/deploy-domains.js +38 -2
- package/dist/commands/index-cmd.d.ts +3 -1
- package/dist/commands/index-cmd.js +12 -0
- package/dist/commands/lanes-accounts.d.ts +14 -0
- package/dist/commands/lanes-accounts.js +119 -0
- package/dist/commands/lanes-checks.js +1 -1
- package/dist/commands/lanes-move.js +10 -0
- package/dist/commands/lanes-session-start.d.ts +1 -2
- package/dist/commands/lanes-session-start.js +9 -145
- package/dist/commands/lanes-shared.d.ts +3 -0
- package/dist/commands/lanes-shared.js +9 -0
- package/dist/commands/lanes.d.ts +3 -0
- package/dist/commands/lanes.js +231 -39
- package/dist/commands/link.d.ts +8 -3
- package/dist/commands/link.js +14 -17
- package/dist/commands/mcp-registration.d.ts +65 -7
- package/dist/commands/mcp-registration.js +289 -51
- package/dist/commands/mesh.d.ts +12 -0
- package/dist/commands/mesh.js +92 -10
- package/dist/commands/reindex.js +6 -0
- package/dist/commands/repo.d.ts +13 -0
- package/dist/commands/repo.js +39 -1
- package/dist/commands/sync-held.d.ts +22 -0
- package/dist/commands/sync-held.js +167 -18
- package/dist/commands/sync-mode.d.ts +3 -1
- package/dist/commands/sync-mode.js +11 -1
- package/dist/hq-cloud-sync-runner/bin/sync-runner.js +4845 -2524
- package/dist/hq-cloud-sync-runner/package.json +1 -1
- package/dist/lazy-commands.js +3 -4
- package/dist/lib/capacity/accounts.d.ts +4 -0
- package/dist/lib/capacity/accounts.js +4 -0
- package/dist/lib/capacity/route.js +14 -0
- package/dist/lib/capacity/sign-in.d.ts +18 -0
- package/dist/lib/capacity/sign-in.js +34 -1
- package/dist/lib/checkpoint-ontology/entity-file.js +4 -4
- package/dist/lib/checkpoint-ontology/merge-copies.js +7 -11
- package/dist/lib/checkpoint-ontology/plan.js +2 -1
- package/dist/lib/core-utils/archive-old-threads.js +5 -2
- package/dist/lib/core-utils/session-company.d.ts +13 -1
- package/dist/lib/core-utils/session-company.js +75 -4
- package/dist/lib/core-utils/worktree-resume.d.ts +6 -0
- package/dist/lib/core-utils/worktree-resume.js +8 -4
- package/dist/lib/daemon/background-qos.d.ts +7 -0
- package/dist/lib/daemon/background-qos.js +13 -0
- package/dist/lib/daemon/catalog.d.ts +10 -0
- package/dist/lib/daemon/catalog.js +9 -2
- package/dist/lib/daemon/hook-requests-acl-suggest.d.ts +18 -0
- package/dist/lib/daemon/hook-requests-acl-suggest.js +245 -0
- package/dist/lib/daemon/hook-requests-fleet-session-start.d.ts +32 -0
- package/dist/lib/daemon/hook-requests-fleet-session-start.js +214 -0
- package/dist/lib/daemon/hook-requests-mesh-tool-writes.d.ts +44 -0
- package/dist/lib/daemon/hook-requests-mesh-tool-writes.js +292 -0
- package/dist/lib/daemon/hook-requests-mesh.d.ts +54 -0
- package/dist/lib/daemon/hook-requests-mesh.js +559 -0
- package/dist/lib/daemon/hook-requests.d.ts +417 -0
- package/dist/lib/daemon/hook-requests.js +1747 -0
- package/dist/lib/daemon/lanes-reconcile-status.d.ts +35 -0
- package/dist/lib/daemon/lanes-reconcile-status.js +86 -0
- package/dist/lib/daemon/machine-checks.d.ts +12 -2
- package/dist/lib/daemon/machine-checks.js +27 -10
- package/dist/lib/daemon/merge-sections.d.ts +24 -2
- package/dist/lib/daemon/merge-sections.js +58 -16
- package/dist/lib/daemon/ops/policy.d.ts +1 -1
- package/dist/lib/daemon/ops/policy.js +47 -6
- package/dist/lib/daemon/resolver.js +9 -2
- package/dist/lib/daemon/run.d.ts +11 -7
- package/dist/lib/daemon/run.js +195 -18
- package/dist/lib/daemon/search-index-worker-v1.d.ts +2 -0
- package/dist/lib/daemon/search-index-worker-v1.js +25 -0
- package/dist/lib/daemon/server.js +6 -1
- package/dist/lib/daemon/session-registry.d.ts +0 -1
- package/dist/lib/daemon/session-registry.js +0 -3
- package/dist/lib/daemon/supervisor.d.ts +5 -1
- package/dist/lib/daemon/supervisor.js +1 -1
- package/dist/lib/daemon/tcc-eperm.d.ts +59 -4
- package/dist/lib/daemon/tcc-eperm.js +110 -8
- package/dist/lib/doctor/fix/process-identity.d.ts +20 -2
- package/dist/lib/doctor/fix/process-identity.js +48 -5
- package/dist/lib/flag-registry-worker-source.generated.d.ts +1 -1
- package/dist/lib/flag-registry-worker-source.generated.js +1 -1
- package/dist/lib/hook-engine/canary-gate.js +1 -0
- package/dist/lib/hook-engine/native-stop-compatibility.json +2 -1
- package/dist/lib/hot-channels/adapters/attio.js +2 -1
- package/dist/lib/hot-channels/adapters/meetings.js +2 -1
- package/dist/lib/lanes/account-company.d.ts +7 -1
- package/dist/lib/lanes/account-company.js +22 -4
- package/dist/lib/lanes/account-ownership.d.ts +65 -0
- package/dist/lib/lanes/account-ownership.js +134 -0
- package/dist/lib/lanes/accounts.js +9 -2
- package/dist/lib/lanes/claude-balance.js +9 -3
- package/dist/lib/lanes/company-outposts.d.ts +37 -0
- package/dist/lib/lanes/company-outposts.js +164 -0
- package/dist/lib/lanes/config.js +17 -0
- package/dist/lib/lanes/host-capacity.d.ts +19 -0
- package/dist/lib/lanes/host-capacity.js +37 -0
- package/dist/lib/lanes/liveness.d.ts +6 -0
- package/dist/lib/lanes/liveness.js +49 -8
- package/dist/lib/lanes/orphan-report.d.ts +15 -0
- package/dist/lib/lanes/orphan-report.js +223 -0
- package/dist/lib/lanes/orphan-sweep.d.ts +26 -0
- package/dist/lib/lanes/orphan-sweep.js +152 -0
- package/dist/lib/lanes/reaper.d.ts +2 -0
- package/dist/lib/lanes/reaper.js +11 -8
- package/dist/lib/lanes/reconcile.d.ts +8 -7
- package/dist/lib/lanes/reconcile.js +83 -3
- package/dist/lib/lanes/spawn.d.ts +0 -10
- package/dist/lib/lanes/spawn.js +51 -1
- package/dist/lib/lanes/types.d.ts +12 -0
- package/dist/lib/mesh/live/backfill-held.d.ts +13 -0
- package/dist/lib/mesh/live/backfill-held.js +23 -0
- package/dist/lib/mesh/live/daemon/mode.d.ts +8 -4
- package/dist/lib/mesh/live/daemon/mode.js +8 -4
- package/dist/lib/mesh/live/daemon/run.d.ts +14 -3
- package/dist/lib/mesh/live/daemon/run.js +116 -7
- package/dist/lib/mesh/live/direct-drain.d.ts +123 -0
- package/dist/lib/mesh/live/direct-drain.js +315 -0
- package/dist/lib/mesh/live/emit-replay.d.ts +10 -0
- package/dist/lib/mesh/live/emit-replay.js +10 -0
- package/dist/lib/mesh/live/flush.d.ts +15 -0
- package/dist/lib/mesh/live/flush.js +27 -0
- package/dist/lib/mesh/live/liveness-carry.d.ts +45 -0
- package/dist/lib/mesh/live/liveness-carry.js +141 -0
- package/dist/lib/mesh/live/spool.d.ts +19 -0
- package/dist/lib/mesh/live/spool.js +80 -0
- package/dist/lib/safe-store.d.ts +2 -0
- package/dist/lib/safe-store.js +8 -6
- package/dist/lib/search-index/index.d.ts +9 -3
- package/dist/lib/search-index/index.js +35 -10
- package/dist/lib/search-index/worker-process.d.ts +9 -0
- package/dist/lib/search-index/worker-process.js +171 -0
- package/dist/lib/session-company-lock.d.ts +3 -1
- package/dist/lib/session-company-lock.js +3 -2
- package/dist/utils/delegate-command-supervisor.d.ts +3 -0
- package/dist/utils/delegate-command-supervisor.js +44 -0
- package/dist/utils/delegate-lock.d.ts +12 -0
- package/dist/utils/delegate-lock.js +88 -0
- package/dist/utils/frontmatter.d.ts +27 -0
- package/dist/utils/frontmatter.js +33 -0
- package/dist/utils/hook-trust.d.ts +1 -0
- package/dist/utils/hook-trust.js +18 -2
- package/dist/utils/host-registration.d.ts +13 -1
- package/dist/utils/host-registration.js +98 -5
- package/dist/utils/package-use-lease.d.ts +1 -1
- package/dist/utils/package-use-lease.js +15 -7
- package/docs/anywhere-runtime.md +17 -0
- package/package.json +9 -8
- package/scripts/check-function-manifest.mjs +17 -3
|
@@ -16,6 +16,14 @@
|
|
|
16
16
|
* TCC_EPERM_EXIT_CODE. The daemon's LaunchAgent has KeepAlive=true, so launchd
|
|
17
17
|
* starts it again (after its ThrottleInterval) whatever the exit code.
|
|
18
18
|
*
|
|
19
|
+
* A daemon whose every op stops at the same file (policy.check opening the
|
|
20
|
+
* caller's session meta.yaml, for one) never shows a second path. So when the
|
|
21
|
+
* window holds enough hits on one path only, hqd lists the HQ root itself:
|
|
22
|
+
* macOS privacy refuses that with EPERM too, while one odd file (flags, an
|
|
23
|
+
* ACL) leaves the root readable. A refused root counts as the trip; a
|
|
24
|
+
* readable one does not, and is asked again at most once per
|
|
25
|
+
* TCC_EPERM_ROOT_CHECK_INTERVAL_MS.
|
|
26
|
+
*
|
|
19
27
|
* It never exits for EPERM outside the HQ root, for EACCES, off macOS, while
|
|
20
28
|
* the daemon is already stopping, or when no service manager would start it
|
|
21
29
|
* again. A permission that stays revoked would otherwise restart the daemon
|
|
@@ -34,8 +42,13 @@ export const TCC_EPERM_EXIT_CODE = 74;
|
|
|
34
42
|
export const TCC_EPERM_WINDOW_MS = 60_000;
|
|
35
43
|
/** Hits needed inside the window. */
|
|
36
44
|
export const TCC_EPERM_MIN_EVENTS = 3;
|
|
37
|
-
/**
|
|
45
|
+
/**
|
|
46
|
+
* Distinct paths needed inside the window, so one odd file cannot trip it.
|
|
47
|
+
* With fewer, the guard trips only if listing the HQ root is refused as well.
|
|
48
|
+
*/
|
|
38
49
|
export const TCC_EPERM_MIN_PATHS = 2;
|
|
50
|
+
/** While enough hits sit on too few paths, the guard lists the HQ root at most this often. */
|
|
51
|
+
export const TCC_EPERM_ROOT_CHECK_INTERVAL_MS = 10_000;
|
|
39
52
|
/** Exits allowed inside TCC_EPERM_EXIT_WINDOW_MS before the daemon stays up instead. */
|
|
40
53
|
export const TCC_EPERM_MAX_EXITS = 3;
|
|
41
54
|
export const TCC_EPERM_EXIT_WINDOW_MS = 30 * 60_000;
|
|
@@ -43,8 +56,47 @@ export const TCC_EPERM_EXIT_WINDOW_MS = 30 * 60_000;
|
|
|
43
56
|
export const TCC_EPERM_EXITS_FILE = "tcc-eperm-exits.json";
|
|
44
57
|
/** Under the daemon dir: present while hqd is up but cannot read the HQ folder. */
|
|
45
58
|
export const FILES_ACCESS_NEEDED_MARKER = "files-access-needed.json";
|
|
46
|
-
|
|
47
|
-
|
|
59
|
+
const FILES_ACCESS_LAUNCHES = new Set(["node-direct", "hq-app", "terminal"]);
|
|
60
|
+
/**
|
|
61
|
+
* How this daemon was started, from its run options and parent pid. launchd
|
|
62
|
+
* is pid 1, so a managed daemon whose parent is launchd runs node directly;
|
|
63
|
+
* under the HQ.app launcher (--hq-launchd-task) the parent is the launcher.
|
|
64
|
+
*/
|
|
65
|
+
export function filesAccessLaunch(opts) {
|
|
66
|
+
if (opts.host !== undefined)
|
|
67
|
+
return "hq-app";
|
|
68
|
+
if (opts.managed !== true)
|
|
69
|
+
return "terminal";
|
|
70
|
+
return opts.ppid === 1 ? "node-direct" : "hq-app";
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* What to tell the user. With no known launch (a marker from an older
|
|
74
|
+
* daemon) this is the HQ-app wording the daemon always used.
|
|
75
|
+
*/
|
|
76
|
+
export function filesAccessNeededMessage(launch, program) {
|
|
77
|
+
const settings = "Open System Settings > Privacy & Security > Full Disk Access";
|
|
78
|
+
if (launch === "node-direct") {
|
|
79
|
+
const who = program ? `the program that runs the HQ daemon, ${program}` : "the node program that runs the HQ daemon";
|
|
80
|
+
const add = program ? `click +, press Cmd+Shift+G, enter ${program}, add it` : "click +, add that node program";
|
|
81
|
+
return (`HQ needs Full Disk Access for ${who}. macOS is refusing that program's file reads and writes in your HQ folder, ` +
|
|
82
|
+
"and allowing the HQ app does not cover it. " +
|
|
83
|
+
`${settings}, ${add}, then run: hq daemon restart. ` +
|
|
84
|
+
"Upgrading node (for example with Homebrew) can change that path; add the new path again after an upgrade.");
|
|
85
|
+
}
|
|
86
|
+
if (launch === "terminal") {
|
|
87
|
+
return ("HQ needs Full Disk Access for the terminal app the HQ daemon was started from. macOS is refusing the daemon's file reads and writes in your HQ folder. " +
|
|
88
|
+
`${settings}, allow that terminal app, then start the daemon again`);
|
|
89
|
+
}
|
|
90
|
+
return ("HQ needs Full Disk Access (or Files and Folders access) to your HQ folder. macOS is refusing the daemon's file reads and writes there. " +
|
|
91
|
+
`${settings}, allow HQ, then run: hq daemon restart`);
|
|
92
|
+
}
|
|
93
|
+
/** A usable program path from the marker: absolute, one line, bounded. */
|
|
94
|
+
function markerProgram(value) {
|
|
95
|
+
if (typeof value !== "string" || value.length > 1024 || !path.isAbsolute(value))
|
|
96
|
+
return undefined;
|
|
97
|
+
// eslint-disable-next-line no-control-regex
|
|
98
|
+
return /[\u0000-\u001f\u007f]/.test(value) ? undefined : value;
|
|
99
|
+
}
|
|
48
100
|
export const TCC_EPERM_SENTRY_FINGERPRINT = ["hqd", "tcc-eperm-under-hq-root"];
|
|
49
101
|
/**
|
|
50
102
|
* Syscalls that read. macOS privacy refuses these with EPERM when it cuts a
|
|
@@ -167,13 +219,36 @@ export function recordEpermExit(daemonDir, now, exitWindowMs = TCC_EPERM_EXIT_WI
|
|
|
167
219
|
writePrivateJson(path.join(daemonDir, TCC_EPERM_EXITS_FILE), { exits });
|
|
168
220
|
return exits;
|
|
169
221
|
}
|
|
170
|
-
|
|
222
|
+
/**
|
|
223
|
+
* `launch`: how the daemon was started (filesAccessLaunch). `program`: the
|
|
224
|
+
* binary launchd runs (process.execPath in hqd); recorded only for
|
|
225
|
+
* "node-direct", the one case where it is the program macOS checks.
|
|
226
|
+
*/
|
|
227
|
+
export function writeFilesAccessNeeded(daemonDir, now, reason, launch, program) {
|
|
228
|
+
const usable = launch === "node-direct" ? markerProgram(program) : undefined;
|
|
171
229
|
writePrivateJson(path.join(daemonDir, FILES_ACCESS_NEEDED_MARKER), {
|
|
172
230
|
since: new Date(now).toISOString(),
|
|
173
231
|
reason,
|
|
174
|
-
|
|
232
|
+
...(launch ? { launch } : {}),
|
|
233
|
+
...(usable ? { program: usable } : {}),
|
|
234
|
+
message: filesAccessNeededMessage(launch, usable),
|
|
175
235
|
});
|
|
176
236
|
}
|
|
237
|
+
/** The message for the marker a running daemon wrote, from the launch and program it recorded. */
|
|
238
|
+
export function filesAccessNeededMessageFromMarker(daemonDir) {
|
|
239
|
+
let launch;
|
|
240
|
+
let program;
|
|
241
|
+
try {
|
|
242
|
+
const marker = JSON.parse(fs.readFileSync(path.join(daemonDir, FILES_ACCESS_NEEDED_MARKER), "utf8"));
|
|
243
|
+
launch = typeof marker.launch === "string" && FILES_ACCESS_LAUNCHES.has(marker.launch) ? marker.launch : undefined;
|
|
244
|
+
program = launch === "node-direct" ? markerProgram(marker.program) : undefined;
|
|
245
|
+
}
|
|
246
|
+
catch {
|
|
247
|
+
launch = undefined;
|
|
248
|
+
program = undefined;
|
|
249
|
+
}
|
|
250
|
+
return filesAccessNeededMessage(launch, program);
|
|
251
|
+
}
|
|
177
252
|
export function clearFilesAccessNeeded(daemonDir) {
|
|
178
253
|
fs.rmSync(path.join(daemonDir, FILES_ACCESS_NEEDED_MARKER), { force: true });
|
|
179
254
|
}
|
|
@@ -191,8 +266,13 @@ export function createTccEpermGuard(deps) {
|
|
|
191
266
|
const now = deps.now ?? Date.now;
|
|
192
267
|
const probe = deps.probe ?? ((root) => void fs.readdirSync(root));
|
|
193
268
|
const schedule = deps.schedule ?? defaultSchedule;
|
|
269
|
+
const launch = deps.launch;
|
|
270
|
+
const program = launch === "node-direct" ? markerProgram(deps.program ?? process.execPath) : undefined;
|
|
194
271
|
let window = createEpermWindow(deps.window);
|
|
195
272
|
const windowMs = deps.window?.windowMs ?? TCC_EPERM_WINDOW_MS;
|
|
273
|
+
const minEvents = deps.window?.minEvents ?? TCC_EPERM_MIN_EVENTS;
|
|
274
|
+
const rootCheckIntervalMs = deps.rootCheckIntervalMs ?? TCC_EPERM_ROOT_CHECK_INTERVAL_MS;
|
|
275
|
+
let lastRootCheck = null;
|
|
196
276
|
let state = "watching";
|
|
197
277
|
let cancelProbe = null;
|
|
198
278
|
if (deps.platform === "darwin") {
|
|
@@ -220,6 +300,7 @@ export function createTccEpermGuard(deps) {
|
|
|
220
300
|
cancelProbe?.();
|
|
221
301
|
cancelProbe = null;
|
|
222
302
|
window = createEpermWindow(deps.window);
|
|
303
|
+
lastRootCheck = null;
|
|
223
304
|
state = "watching";
|
|
224
305
|
try {
|
|
225
306
|
clearFilesAccessNeeded(deps.daemonDir);
|
|
@@ -233,13 +314,32 @@ export function createTccEpermGuard(deps) {
|
|
|
233
314
|
const stayUp = (at, reason) => {
|
|
234
315
|
state = "access-needed";
|
|
235
316
|
try {
|
|
236
|
-
writeFilesAccessNeeded(deps.daemonDir, at, reason);
|
|
317
|
+
writeFilesAccessNeeded(deps.daemonDir, at, reason, launch, program);
|
|
237
318
|
}
|
|
238
319
|
catch (writeErr) {
|
|
239
320
|
deps.log("warn", `could not write ${FILES_ACCESS_NEEDED_MARKER}: ${writeErr.message}`);
|
|
240
321
|
}
|
|
241
322
|
cancelProbe ??= schedule(() => void checkAccess(), deps.probeIntervalMs ?? TCC_EPERM_PROBE_INTERVAL_MS);
|
|
242
323
|
};
|
|
324
|
+
/**
|
|
325
|
+
* Enough hits, too few paths: is the HQ root itself refused? Only EPERM
|
|
326
|
+
* counts; a root that is missing or fails some other way is not a privacy
|
|
327
|
+
* refusal. Lists the root at most once per rootCheckIntervalMs.
|
|
328
|
+
*/
|
|
329
|
+
const rootRefused = (hqRoot, at) => {
|
|
330
|
+
if (window.summary().hits < minEvents)
|
|
331
|
+
return false;
|
|
332
|
+
if (lastRootCheck !== null && at >= lastRootCheck && at - lastRootCheck < rootCheckIntervalMs)
|
|
333
|
+
return false;
|
|
334
|
+
lastRootCheck = at;
|
|
335
|
+
try {
|
|
336
|
+
probe(hqRoot);
|
|
337
|
+
return false;
|
|
338
|
+
}
|
|
339
|
+
catch (err) {
|
|
340
|
+
return err?.code === "EPERM";
|
|
341
|
+
}
|
|
342
|
+
};
|
|
243
343
|
return {
|
|
244
344
|
state: () => state,
|
|
245
345
|
checkAccess,
|
|
@@ -257,7 +357,8 @@ export function createTccEpermGuard(deps) {
|
|
|
257
357
|
if (!hit)
|
|
258
358
|
return;
|
|
259
359
|
const at = now();
|
|
260
|
-
|
|
360
|
+
const byRoot = !window.record(hit, at);
|
|
361
|
+
if (byRoot && !rootRefused(hqRoot, at))
|
|
261
362
|
return;
|
|
262
363
|
const recentExits = readEpermExits(deps.daemonDir);
|
|
263
364
|
let decision = decideEpermExit({
|
|
@@ -289,6 +390,7 @@ export function createTccEpermGuard(deps) {
|
|
|
289
390
|
event: "hqd.tcc_eperm",
|
|
290
391
|
platform: deps.platform,
|
|
291
392
|
...window.summary(),
|
|
393
|
+
...(byRoot ? { rootRefused: true } : {}),
|
|
292
394
|
windowMs,
|
|
293
395
|
decision: decision.action,
|
|
294
396
|
...(decision.action === "stay" ? { reason: decision.reason } : { exitCode: decision.code }),
|
|
@@ -301,7 +403,7 @@ export function createTccEpermGuard(deps) {
|
|
|
301
403
|
void report(event).finally(() => deps.exit(code));
|
|
302
404
|
}
|
|
303
405
|
else {
|
|
304
|
-
deps.log("error", `hqd: staying up; ${
|
|
406
|
+
deps.log("error", `hqd: staying up; ${filesAccessNeededMessage(launch, program)}`);
|
|
305
407
|
void report(event);
|
|
306
408
|
}
|
|
307
409
|
},
|
|
@@ -3,11 +3,29 @@
|
|
|
3
3
|
* that reused it (feedback cd56a501).
|
|
4
4
|
*/
|
|
5
5
|
import type { RefreshOwnerIdentity } from "./refresh-sync-handoff.js";
|
|
6
|
+
/** Inputs for locating the system process tool; tests inject them. */
|
|
7
|
+
export interface ProcessToolProbe {
|
|
8
|
+
platform?: NodeJS.Platform;
|
|
9
|
+
env?: NodeJS.ProcessEnv;
|
|
10
|
+
isExecutable?: (file: string) => boolean;
|
|
11
|
+
}
|
|
12
|
+
/** The fixed POSIX locations of `ps`, tried in order. */
|
|
13
|
+
export declare const POSIX_PS_PATHS: readonly string[];
|
|
14
|
+
/**
|
|
15
|
+
* The absolute path of the system tool that reads a process start time, found
|
|
16
|
+
* at a fixed location and never through PATH, so the answer is the same on
|
|
17
|
+
* every machine whatever PATH holds. POSIX: the first executable of /bin/ps and
|
|
18
|
+
* /usr/bin/ps. Windows: %SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe
|
|
19
|
+
* (SystemRoot defaults to C:\Windows). Null if the tool is not there.
|
|
20
|
+
*/
|
|
21
|
+
export declare function processStartTool(probe?: ProcessToolProbe): string | null;
|
|
6
22
|
/**
|
|
7
23
|
* A process's start time, or null if it cannot be read: `ps -o lstart=` on
|
|
8
|
-
* POSIX, the process StartTime from PowerShell on Windows.
|
|
24
|
+
* POSIX, the process StartTime from PowerShell on Windows. Both tools are
|
|
25
|
+
* found by fixed path (processStartTool); if neither is there the answer is
|
|
26
|
+
* null, which lock callers treat as busy.
|
|
9
27
|
*/
|
|
10
|
-
export declare function processStartTime(pid: number): string | null;
|
|
28
|
+
export declare function processStartTime(pid: number, probe?: ProcessToolProbe): string | null;
|
|
11
29
|
/** Real process-table identity for the refresh spawn lock. */
|
|
12
30
|
export declare const DEFAULT_OWNER_IDENTITY: RefreshOwnerIdentity;
|
|
13
31
|
//# sourceMappingURL=process-identity.d.ts.map
|
|
@@ -3,22 +3,65 @@
|
|
|
3
3
|
* that reused it (feedback cd56a501).
|
|
4
4
|
*/
|
|
5
5
|
import { spawnSync } from "node:child_process";
|
|
6
|
+
import * as fs from "node:fs";
|
|
7
|
+
import * as path from "node:path";
|
|
8
|
+
/** The fixed POSIX locations of `ps`, tried in order. */
|
|
9
|
+
export const POSIX_PS_PATHS = ["/bin/ps", "/usr/bin/ps"];
|
|
10
|
+
function defaultIsExecutable(platform) {
|
|
11
|
+
return (file) => {
|
|
12
|
+
try {
|
|
13
|
+
if (!fs.statSync(file).isFile())
|
|
14
|
+
return false;
|
|
15
|
+
if (platform !== "win32")
|
|
16
|
+
fs.accessSync(file, fs.constants.X_OK);
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The absolute path of the system tool that reads a process start time, found
|
|
26
|
+
* at a fixed location and never through PATH, so the answer is the same on
|
|
27
|
+
* every machine whatever PATH holds. POSIX: the first executable of /bin/ps and
|
|
28
|
+
* /usr/bin/ps. Windows: %SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe
|
|
29
|
+
* (SystemRoot defaults to C:\Windows). Null if the tool is not there.
|
|
30
|
+
*/
|
|
31
|
+
export function processStartTool(probe = {}) {
|
|
32
|
+
const platform = probe.platform ?? process.platform;
|
|
33
|
+
const isExecutable = probe.isExecutable ?? defaultIsExecutable(platform);
|
|
34
|
+
if (platform === "win32") {
|
|
35
|
+
const env = probe.env ?? process.env;
|
|
36
|
+
const key = Object.keys(env).find((name) => name.toUpperCase() === "SYSTEMROOT");
|
|
37
|
+
const systemRoot = (key ? env[key] : undefined) || "C:\\Windows";
|
|
38
|
+
const powershell = path.win32.join(systemRoot, "System32", "WindowsPowerShell", "v1.0", "powershell.exe");
|
|
39
|
+
return isExecutable(powershell) ? powershell : null;
|
|
40
|
+
}
|
|
41
|
+
return POSIX_PS_PATHS.find((candidate) => isExecutable(candidate)) ?? null;
|
|
42
|
+
}
|
|
6
43
|
/**
|
|
7
44
|
* A process's start time, or null if it cannot be read: `ps -o lstart=` on
|
|
8
|
-
* POSIX, the process StartTime from PowerShell on Windows.
|
|
45
|
+
* POSIX, the process StartTime from PowerShell on Windows. Both tools are
|
|
46
|
+
* found by fixed path (processStartTool); if neither is there the answer is
|
|
47
|
+
* null, which lock callers treat as busy.
|
|
9
48
|
*/
|
|
10
|
-
export function processStartTime(pid) {
|
|
49
|
+
export function processStartTime(pid, probe = {}) {
|
|
11
50
|
if (!Number.isInteger(pid) || pid <= 0)
|
|
12
51
|
return null;
|
|
52
|
+
const tool = processStartTool(probe);
|
|
53
|
+
if (!tool)
|
|
54
|
+
return null;
|
|
55
|
+
const platform = probe.platform ?? process.platform;
|
|
13
56
|
try {
|
|
14
|
-
const result =
|
|
15
|
-
? spawnSync(
|
|
57
|
+
const result = platform === "win32"
|
|
58
|
+
? spawnSync(tool, [
|
|
16
59
|
"-NoProfile",
|
|
17
60
|
"-NonInteractive",
|
|
18
61
|
"-Command",
|
|
19
62
|
`(Get-Process -Id ${pid} -ErrorAction Stop).StartTime.ToUniversalTime().ToString('o')`,
|
|
20
63
|
], { encoding: "utf8", timeout: 10_000, windowsHide: true })
|
|
21
|
-
: spawnSync(
|
|
64
|
+
: spawnSync(tool, ["-o", "lstart=", "-p", String(pid)], { encoding: "utf8", timeout: 5_000 });
|
|
22
65
|
const text = (result.stdout ?? "").trim();
|
|
23
66
|
return result.status === 0 && text ? text : null;
|
|
24
67
|
}
|