@indigoai-us/hq-cli 5.345.203 → 5.345.205
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 +34 -0
- package/dist/command-catalog.generated.d.ts +51 -1
- package/dist/command-catalog.generated.js +63 -1
- package/dist/commands/bot.d.ts +67 -0
- package/dist/commands/bot.js +308 -41
- package/dist/commands/cloud-off-gate.d.ts +9 -2
- package/dist/commands/cloud-off-gate.js +49 -13
- package/dist/commands/cloud.d.ts +14 -2
- package/dist/commands/cloud.js +25 -16
- package/dist/commands/feedback.d.ts +26 -0
- package/dist/commands/feedback.js +91 -5
- package/dist/commands/install-global.d.ts +3 -1
- package/dist/commands/install-global.js +15 -4
- package/dist/commands/lanes.d.ts +2 -0
- package/dist/commands/lanes.js +9 -3
- package/dist/commands/mcp-serve.d.ts +5 -2
- package/dist/commands/mcp-serve.js +45 -3
- package/dist/commands/mcp-status.d.ts +3 -1
- package/dist/commands/mcp-status.js +24 -14
- package/dist/commands/secrets.js +11 -1
- package/dist/commands/sources.js +10 -15
- package/dist/commands/sync-core.js +2 -0
- package/dist/index.js +7 -2
- package/dist/lib/bot/claude-login.d.ts +7 -1
- package/dist/lib/bot/claude-login.js +56 -16
- package/dist/lib/bot/executive-settings.d.ts +13 -0
- package/dist/lib/bot/executive-settings.js +20 -17
- package/dist/lib/bot/executive-sync.d.ts +12 -0
- package/dist/lib/bot/executive-sync.js +36 -0
- package/dist/lib/bot/executive.d.ts +51 -0
- package/dist/lib/bot/executive.js +144 -0
- package/dist/lib/bot/fleet-cron.d.ts +7 -0
- package/dist/lib/bot/fleet-cron.js +2 -1
- package/dist/lib/bot/jobs/executive-handover.d.ts +6 -0
- package/dist/lib/bot/jobs/executive-handover.js +33 -0
- package/dist/lib/bot/jobs/hot-signal-sync.d.ts +22 -0
- package/dist/lib/bot/jobs/hot-signal-sync.js +47 -0
- package/dist/lib/bot/listed-running.d.ts +16 -0
- package/dist/lib/bot/listed-running.js +16 -0
- package/dist/lib/bot/pending-switch.d.ts +51 -0
- package/dist/lib/bot/pending-switch.js +103 -0
- package/dist/lib/bot/run.js +27 -3
- package/dist/lib/bot/runtime-failure.js +19 -3
- package/dist/lib/bot/status.d.ts +20 -0
- package/dist/lib/capacity/collectors/claude-oauth.d.ts +53 -5
- package/dist/lib/capacity/collectors/claude-oauth.js +251 -71
- package/dist/lib/company-skill-wrapper.js +29 -0
- package/dist/lib/daemon/catalog.js +2 -2
- package/dist/lib/daemon/hq-child-bootstrap.mjs +197 -2
- package/dist/lib/daemon/resolver.d.ts +14 -0
- package/dist/lib/daemon/resolver.js +96 -0
- package/dist/lib/daemon/run.d.ts +11 -0
- package/dist/lib/daemon/run.js +60 -8
- package/dist/lib/daemon/server.d.ts +2 -9
- package/dist/lib/daemon/server.js +3 -89
- package/dist/lib/doctor/checks/claude-wiring.js +41 -0
- package/dist/lib/doctor/checks/sync-health.d.ts +8 -0
- package/dist/lib/doctor/checks/sync-health.js +34 -2
- package/dist/lib/doctor/duplicate-hook-registrations.d.ts +34 -0
- package/dist/lib/doctor/duplicate-hook-registrations.js +130 -0
- package/dist/lib/doctor/fix/apply.js +79 -3
- package/dist/lib/doctor/fix/remediation.d.ts +1 -1
- package/dist/lib/doctor/fix/remediation.js +15 -0
- package/dist/lib/doctor/types.d.ts +1 -1
- package/dist/lib/doctor/types.js +1 -0
- package/dist/lib/lanes/config.js +13 -0
- package/dist/lib/lanes/throttle.d.ts +12 -1
- package/dist/lib/lanes/throttle.js +27 -8
- package/dist/lib/lanes/types.d.ts +5 -0
- package/dist/lib/mcp/local-native-tools.d.ts +40 -0
- package/dist/lib/mcp/local-native-tools.js +111 -0
- package/dist/lib/mcp/tools.d.ts +2 -0
- package/dist/lib/mcp/tools.js +2 -0
- package/dist/lib/signals/steps/extract.d.ts +111 -5
- package/dist/lib/signals/steps/extract.js +524 -55
- package/dist/lib/sync-core/engine-home.d.ts +2 -1
- package/dist/lib/sync-core/engine-home.js +25 -8
- package/dist/lib/sync-core/reconcile.d.ts +3 -1
- package/dist/lib/sync-core/reconcile.js +21 -8
- package/dist/lib/sync-core/release.d.ts +14 -5
- package/dist/lib/sync-core/release.js +58 -14
- package/dist/sentry-init.js +6 -0
- package/dist/utils/cli-network-lifecycle.d.ts +11 -1
- package/dist/utils/cli-network-lifecycle.js +36 -2
- package/dist/utils/daemon-helper-lifetime.d.ts +39 -0
- package/dist/utils/daemon-helper-lifetime.js +209 -0
- package/dist/utils/daemon-helper-markers.d.ts +24 -0
- package/dist/utils/daemon-helper-markers.js +53 -0
- package/dist/utils/mcp-launcher.d.ts +28 -0
- package/dist/utils/mcp-launcher.js +117 -0
- package/dist/utils/package-use-lease.d.ts +10 -0
- package/dist/utils/package-use-lease.js +31 -0
- package/dist/utils/resident-package-preload.js +4 -1
- package/docs/anywhere-runtime.md +7 -0
- package/package.json +7 -7
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stop a daemon helper when the process that owns it is gone.
|
|
3
|
+
*
|
|
4
|
+
* The child bootstrap has its own copy of the same rules (it is staged as one
|
|
5
|
+
* file and cannot import this module). Keep the handoff age and the pipe
|
|
6
|
+
* check in step with src/lib/daemon/hq-child-bootstrap.mts.
|
|
7
|
+
*
|
|
8
|
+
* stdin is not an owner channel unless it is a FIFO or a Node pipe socket.
|
|
9
|
+
* The daemon spawns helpers with stdin "ignore", which is /dev/null, and
|
|
10
|
+
* reading that returns EOF at once. Node implements stdio "pipe" as a socket.
|
|
11
|
+
*/
|
|
12
|
+
import * as fs from "node:fs";
|
|
13
|
+
import * as net from "node:net";
|
|
14
|
+
import { consumeOneShotOwnerMarkers } from "./daemon-helper-markers.js";
|
|
15
|
+
export { daemonDirectReplacementEnv, daemonDirectResidentSkipsSentry } from "./daemon-helper-markers.js";
|
|
16
|
+
/** Same window as HANDOFF_MAX_AGE_MS in succession.ts. */
|
|
17
|
+
export const HANDOFF_MAX_AGE_MS = 5 * 60_000;
|
|
18
|
+
export const OWNER_POLL_MS = 500;
|
|
19
|
+
export const OWNER_HANDOFF_RECHECK_MS = 1_000;
|
|
20
|
+
export const CHILD_STOP_GRACE_MS = 2_000;
|
|
21
|
+
export function descriptorIsOwnerPipe(fd, fstat = fs.fstatSync) {
|
|
22
|
+
try {
|
|
23
|
+
const stat = fstat(fd);
|
|
24
|
+
// Node's "pipe" stdio is a socketpair on macOS and Linux, not a FIFO.
|
|
25
|
+
// /dev/null is a character device, so ignored stdin still does not match.
|
|
26
|
+
return stat.isFIFO() || stat.isSocket();
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export function readProcStart(pid) {
|
|
33
|
+
try {
|
|
34
|
+
const text = fs.readFileSync(`/proc/${pid}/stat`, "utf8");
|
|
35
|
+
const close = text.lastIndexOf(")");
|
|
36
|
+
if (close < 0)
|
|
37
|
+
return null;
|
|
38
|
+
const rest = text.slice(close + 1).trim().split(/\s+/);
|
|
39
|
+
if (rest[0] === "Z" || rest[0] === "X")
|
|
40
|
+
return null;
|
|
41
|
+
const start = Number(rest[19]);
|
|
42
|
+
return Number.isInteger(start) ? start : null;
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
export function parentStillOwns(pid, start, kill = (target, signal) => process.kill(target, signal), readStart = readProcStart) {
|
|
49
|
+
if (!Number.isInteger(pid) || pid <= 1)
|
|
50
|
+
return false;
|
|
51
|
+
try {
|
|
52
|
+
kill(pid, 0);
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
if (error.code !== "EPERM")
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
if (start === null)
|
|
59
|
+
return true;
|
|
60
|
+
const current = readStart(pid);
|
|
61
|
+
if (current === null)
|
|
62
|
+
return false;
|
|
63
|
+
return current === start;
|
|
64
|
+
}
|
|
65
|
+
export function handoffKeepsPid(record, pid, now, selfStart, maxAgeMs = HANDOFF_MAX_AGE_MS) {
|
|
66
|
+
if (!record || typeof record !== "object")
|
|
67
|
+
return false;
|
|
68
|
+
const releasedAt = record.releasedAt;
|
|
69
|
+
if (typeof releasedAt !== "number" || !Number.isFinite(releasedAt))
|
|
70
|
+
return false;
|
|
71
|
+
if (now - releasedAt > maxAgeMs)
|
|
72
|
+
return false;
|
|
73
|
+
const units = record.units;
|
|
74
|
+
if (!Array.isArray(units))
|
|
75
|
+
return false;
|
|
76
|
+
return units.some((unit) => {
|
|
77
|
+
if (!unit || typeof unit !== "object")
|
|
78
|
+
return false;
|
|
79
|
+
if (unit.pid !== pid)
|
|
80
|
+
return false;
|
|
81
|
+
const start = unit.start;
|
|
82
|
+
if (typeof start === "number" && selfStart !== null && start !== selfStart)
|
|
83
|
+
return false;
|
|
84
|
+
return true;
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
export async function handleOwnerLoss(options) {
|
|
88
|
+
const keeps = () => handoffKeepsPid(options.readHandoff(), options.pid, options.now(), options.selfStart);
|
|
89
|
+
if (options.handoffPath) {
|
|
90
|
+
const deadline = options.now() + (options.recheckMs ?? OWNER_HANDOFF_RECHECK_MS);
|
|
91
|
+
while (options.now() < deadline) {
|
|
92
|
+
if (keeps())
|
|
93
|
+
return "detach";
|
|
94
|
+
await options.wait(50);
|
|
95
|
+
if (keeps())
|
|
96
|
+
return "detach";
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return keeps() ? "detach" : "stop";
|
|
100
|
+
}
|
|
101
|
+
let installed = false;
|
|
102
|
+
const ownerSockets = [];
|
|
103
|
+
let ownerPoll;
|
|
104
|
+
function watchPipeEof(fd, onEof) {
|
|
105
|
+
if (!descriptorIsOwnerPipe(fd))
|
|
106
|
+
return;
|
|
107
|
+
// fs.ReadStream has no unref. A referenced read would keep a finished
|
|
108
|
+
// command alive. /dev/null never reaches here: it is not a pipe.
|
|
109
|
+
let socket;
|
|
110
|
+
try {
|
|
111
|
+
socket = new net.Socket({ fd, readable: true, writable: false });
|
|
112
|
+
}
|
|
113
|
+
catch {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
ownerSockets.push(socket);
|
|
117
|
+
socket.on("end", onEof);
|
|
118
|
+
socket.on("error", () => { });
|
|
119
|
+
socket.resume();
|
|
120
|
+
socket.unref();
|
|
121
|
+
}
|
|
122
|
+
function stopOwnerWatch() {
|
|
123
|
+
if (ownerPoll)
|
|
124
|
+
clearInterval(ownerPoll);
|
|
125
|
+
ownerPoll = undefined;
|
|
126
|
+
for (const socket of ownerSockets.splice(0)) {
|
|
127
|
+
socket.removeAllListeners("end");
|
|
128
|
+
socket.removeAllListeners("close");
|
|
129
|
+
socket.on("error", () => { });
|
|
130
|
+
socket.destroy();
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
function stopSelf() {
|
|
134
|
+
try {
|
|
135
|
+
process.kill(process.pid, "SIGTERM");
|
|
136
|
+
}
|
|
137
|
+
catch {
|
|
138
|
+
// Already on the way out.
|
|
139
|
+
}
|
|
140
|
+
const timer = setTimeout(() => {
|
|
141
|
+
try {
|
|
142
|
+
process.kill(process.pid, "SIGKILL");
|
|
143
|
+
}
|
|
144
|
+
catch {
|
|
145
|
+
// The process is already gone.
|
|
146
|
+
}
|
|
147
|
+
}, CHILD_STOP_GRACE_MS);
|
|
148
|
+
timer.unref();
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Arm the watch only for the process the daemon started directly. A later hq
|
|
152
|
+
* command inherits `HQ_DAEMON_UNIT` and must not exit with its launcher or
|
|
153
|
+
* lose Sentry. The one-shot markers are removed from the environment first,
|
|
154
|
+
* before any command can spawn a child.
|
|
155
|
+
*/
|
|
156
|
+
export function installDaemonHelperLifetime(env = process.env) {
|
|
157
|
+
const direct = env.HQ_DAEMON_BOOTSTRAP_CHILD === "1" || env.HQ_DAEMON_RESIDENT === "1";
|
|
158
|
+
if (!direct || installed)
|
|
159
|
+
return;
|
|
160
|
+
installed = true;
|
|
161
|
+
const { handoffPath, controlFd } = consumeOneShotOwnerMarkers(env);
|
|
162
|
+
const parentPid = process.ppid;
|
|
163
|
+
const parentStart = readProcStart(parentPid);
|
|
164
|
+
let state = "bound";
|
|
165
|
+
const loseOwner = () => {
|
|
166
|
+
if (state !== "bound")
|
|
167
|
+
return;
|
|
168
|
+
state = "stopping";
|
|
169
|
+
void handleOwnerLoss({
|
|
170
|
+
handoffPath,
|
|
171
|
+
readHandoff: () => {
|
|
172
|
+
if (!handoffPath)
|
|
173
|
+
return null;
|
|
174
|
+
try {
|
|
175
|
+
return JSON.parse(fs.readFileSync(handoffPath, "utf8"));
|
|
176
|
+
}
|
|
177
|
+
catch {
|
|
178
|
+
return null;
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
pid: process.pid,
|
|
182
|
+
selfStart: readProcStart(process.pid),
|
|
183
|
+
now: () => Date.now(),
|
|
184
|
+
wait: (ms) => new Promise((resolve) => { setTimeout(resolve, ms); }),
|
|
185
|
+
}).then((decision) => {
|
|
186
|
+
if (decision === "detach") {
|
|
187
|
+
state = "detached";
|
|
188
|
+
stopOwnerWatch();
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
stopOwnerWatch();
|
|
192
|
+
stopSelf();
|
|
193
|
+
});
|
|
194
|
+
};
|
|
195
|
+
if (Number.isInteger(controlFd) && controlFd >= 0)
|
|
196
|
+
watchPipeEof(controlFd, loseOwner);
|
|
197
|
+
// A parent that passes a real stdin pipe, and does not use the control fd,
|
|
198
|
+
// is also an owner. /dev/null is not a pipe and is ignored.
|
|
199
|
+
if (!Number.isInteger(controlFd))
|
|
200
|
+
watchPipeEof(0, loseOwner);
|
|
201
|
+
if (parentPid > 1) {
|
|
202
|
+
ownerPoll = setInterval(() => {
|
|
203
|
+
if (!parentStillOwns(parentPid, parentStart))
|
|
204
|
+
loseOwner();
|
|
205
|
+
}, OWNER_POLL_MS);
|
|
206
|
+
ownerPoll.unref();
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
//# sourceMappingURL=daemon-helper-lifetime.js.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One-shot markers for the process the daemon started.
|
|
3
|
+
*
|
|
4
|
+
* This module does not import node:net. Fast native commands read the Sentry
|
|
5
|
+
* skip through it, and a network import here would fail their closure guard.
|
|
6
|
+
* The owner watch lives in daemon-helper-lifetime.ts and is loaded only by
|
|
7
|
+
* the full CLI entry.
|
|
8
|
+
*
|
|
9
|
+
* `HQ_DAEMON_UNIT` is not a marker. Bot and agent sessions inherit it on
|
|
10
|
+
* purpose. A descendant that treated it as an owner signal would exit when
|
|
11
|
+
* its own launcher exited.
|
|
12
|
+
*/
|
|
13
|
+
/** True after this process consumed `HQ_DAEMON_RESIDENT=1` and cleared it. */
|
|
14
|
+
export declare function daemonDirectResidentSkipsSentry(): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Environment for a torn-install re-exec of this same helper. Descendants must
|
|
17
|
+
* not see the one-shot markers; a replacement of this process must.
|
|
18
|
+
*/
|
|
19
|
+
export declare function daemonDirectReplacementEnv(base: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
|
|
20
|
+
export declare function consumeOneShotOwnerMarkers(env: NodeJS.ProcessEnv): {
|
|
21
|
+
handoffPath: string | undefined;
|
|
22
|
+
controlFd: number;
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=daemon-helper-markers.d.ts.map
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One-shot markers for the process the daemon started.
|
|
3
|
+
*
|
|
4
|
+
* This module does not import node:net. Fast native commands read the Sentry
|
|
5
|
+
* skip through it, and a network import here would fail their closure guard.
|
|
6
|
+
* The owner watch lives in daemon-helper-lifetime.ts and is loaded only by
|
|
7
|
+
* the full CLI entry.
|
|
8
|
+
*
|
|
9
|
+
* `HQ_DAEMON_UNIT` is not a marker. Bot and agent sessions inherit it on
|
|
10
|
+
* purpose. A descendant that treated it as an owner signal would exit when
|
|
11
|
+
* its own launcher exited.
|
|
12
|
+
*/
|
|
13
|
+
const ONE_SHOT_OWNER_KEYS = [
|
|
14
|
+
"HQ_DAEMON_BOOTSTRAP_CHILD",
|
|
15
|
+
"HQ_DAEMON_RESIDENT",
|
|
16
|
+
"HQ_DAEMON_OWNER_CONTROL_FD",
|
|
17
|
+
"HQ_DAEMON_HANDOFF_PATH",
|
|
18
|
+
];
|
|
19
|
+
let directResidentSkip = false;
|
|
20
|
+
let directMarkers;
|
|
21
|
+
/** True after this process consumed `HQ_DAEMON_RESIDENT=1` and cleared it. */
|
|
22
|
+
export function daemonDirectResidentSkipsSentry() {
|
|
23
|
+
return directResidentSkip;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Environment for a torn-install re-exec of this same helper. Descendants must
|
|
27
|
+
* not see the one-shot markers; a replacement of this process must.
|
|
28
|
+
*/
|
|
29
|
+
export function daemonDirectReplacementEnv(base) {
|
|
30
|
+
if (!directMarkers)
|
|
31
|
+
return base;
|
|
32
|
+
return { ...base, ...directMarkers };
|
|
33
|
+
}
|
|
34
|
+
export function consumeOneShotOwnerMarkers(env) {
|
|
35
|
+
const handoffPath = typeof env.HQ_DAEMON_HANDOFF_PATH === "string" && env.HQ_DAEMON_HANDOFF_PATH !== ""
|
|
36
|
+
? env.HQ_DAEMON_HANDOFF_PATH
|
|
37
|
+
: undefined;
|
|
38
|
+
const controlFd = Number(env.HQ_DAEMON_OWNER_CONTROL_FD);
|
|
39
|
+
const markers = {};
|
|
40
|
+
for (const key of ONE_SHOT_OWNER_KEYS) {
|
|
41
|
+
const value = env[key];
|
|
42
|
+
if (typeof value === "string" && value !== "")
|
|
43
|
+
markers[key] = value;
|
|
44
|
+
delete env[key];
|
|
45
|
+
}
|
|
46
|
+
if (env === process.env) {
|
|
47
|
+
directMarkers = markers;
|
|
48
|
+
if (markers.HQ_DAEMON_RESIDENT === "1")
|
|
49
|
+
directResidentSkip = true;
|
|
50
|
+
}
|
|
51
|
+
return { handoffPath, controlFd };
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=daemon-helper-markers.js.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/** True when `p` lives under a version-pinned package-manager or runtime directory. */
|
|
2
|
+
export declare function isVersionedStorePath(p: string): boolean;
|
|
3
|
+
/** True when `p` is a versioned store path that is not the running CLI entry. */
|
|
4
|
+
export declare function isStaleVersionedStorePath(p: string, runningEntry: string | undefined): boolean;
|
|
5
|
+
export interface McpLaunch {
|
|
6
|
+
/** Absolute node binary. */
|
|
7
|
+
command: string;
|
|
8
|
+
/** Absolute CLI entry script, unversioned where one can be proven to be this CLI. */
|
|
9
|
+
entry: string;
|
|
10
|
+
/** PATH for the MCP subprocess. */
|
|
11
|
+
path: string;
|
|
12
|
+
}
|
|
13
|
+
export interface McpLaunchInput {
|
|
14
|
+
execPath: string;
|
|
15
|
+
argv1: string;
|
|
16
|
+
env: NodeJS.ProcessEnv;
|
|
17
|
+
platform: NodeJS.Platform;
|
|
18
|
+
home?: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Decide what the MCP registration should run: an absolute node binary and an
|
|
22
|
+
* unversioned entry path for THIS CLI. No PATH lookup of `hq` and no shell shim
|
|
23
|
+
* is ever registered; a `hq` found on PATH is only used when it is a file or
|
|
24
|
+
* symlink whose realpath is the running entry (never on win32, where PATH hits
|
|
25
|
+
* are .cmd/.ps1 shims that hosts cannot spawn without a shell).
|
|
26
|
+
*/
|
|
27
|
+
export declare function resolveMcpLaunch(o: McpLaunchInput): McpLaunch;
|
|
28
|
+
//# sourceMappingURL=mcp-launcher.d.ts.map
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import * as fs from 'node:fs';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
import { MCP_SUBPROCESS_PATH } from '../lib/install/claude-targets.js';
|
|
4
|
+
import { findExecutableOnPath } from './resolve-executable.js';
|
|
5
|
+
const PKG_NAME = '@indigoai-us/hq-cli';
|
|
6
|
+
const SEP = '[\\\\/]';
|
|
7
|
+
/**
|
|
8
|
+
* Path layouts that embed a package or runtime version, so a path recorded
|
|
9
|
+
* inside them goes stale on the next update. Kept small and tested.
|
|
10
|
+
*/
|
|
11
|
+
const VERSIONED_PATH_RES = [
|
|
12
|
+
// pnpm content-addressable store links and virtual store
|
|
13
|
+
new RegExp(`${SEP}store${SEP}v\\d+${SEP}links${SEP}`),
|
|
14
|
+
new RegExp(`${SEP}\\.pnpm${SEP}`),
|
|
15
|
+
// Homebrew: Cellar/<formula>/<version>/...
|
|
16
|
+
new RegExp(`${SEP}Cellar${SEP}[^\\\\/]+${SEP}[^\\\\/]+${SEP}`),
|
|
17
|
+
// nvm (versions/node/vX), fnm (node-versions/vX)
|
|
18
|
+
new RegExp(`${SEP}versions${SEP}node${SEP}v?\\d`),
|
|
19
|
+
new RegExp(`${SEP}node-versions${SEP}v?\\d`),
|
|
20
|
+
// volta: tools/image/node/<version>, tools/image/packages/<name>
|
|
21
|
+
new RegExp(`${SEP}tools${SEP}image${SEP}(?:node|packages)${SEP}`),
|
|
22
|
+
// yarn berry caches (zip per version)
|
|
23
|
+
new RegExp(`${SEP}\\.yarn${SEP}(?:berry${SEP})?cache${SEP}`),
|
|
24
|
+
];
|
|
25
|
+
/** True when `p` lives under a version-pinned package-manager or runtime directory. */
|
|
26
|
+
export function isVersionedStorePath(p) {
|
|
27
|
+
return VERSIONED_PATH_RES.some((re) => re.test(p));
|
|
28
|
+
}
|
|
29
|
+
function realOrSelf(p) {
|
|
30
|
+
try {
|
|
31
|
+
return fs.realpathSync(p);
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
return p;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/** True when `p` is a versioned store path that is not the running CLI entry. */
|
|
38
|
+
export function isStaleVersionedStorePath(p, runningEntry) {
|
|
39
|
+
if (!isVersionedStorePath(p))
|
|
40
|
+
return false;
|
|
41
|
+
if (!runningEntry)
|
|
42
|
+
return true;
|
|
43
|
+
return realOrSelf(p) !== realOrSelf(runningEntry);
|
|
44
|
+
}
|
|
45
|
+
/** Walk up from `file` to the directory whose package.json is this package. */
|
|
46
|
+
function packageRootOf(file) {
|
|
47
|
+
let dir = path.dirname(file);
|
|
48
|
+
for (;;) {
|
|
49
|
+
try {
|
|
50
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(dir, 'package.json'), 'utf8'));
|
|
51
|
+
if (pkg.name === PKG_NAME)
|
|
52
|
+
return dir;
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
// keep walking
|
|
56
|
+
}
|
|
57
|
+
const parent = path.dirname(dir);
|
|
58
|
+
if (parent === dir)
|
|
59
|
+
return undefined;
|
|
60
|
+
dir = parent;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/** Stable `global/<n>/node_modules/@indigoai-us/hq-cli/<entry>` links pnpm maintains across updates. */
|
|
64
|
+
function pnpmGlobalAliases(realEntry, o) {
|
|
65
|
+
const root = packageRootOf(realEntry);
|
|
66
|
+
if (!root)
|
|
67
|
+
return [];
|
|
68
|
+
const rel = path.relative(root, realEntry);
|
|
69
|
+
const homes = [
|
|
70
|
+
o.env.PNPM_HOME,
|
|
71
|
+
o.env.LOCALAPPDATA ? path.join(o.env.LOCALAPPDATA, 'pnpm') : undefined,
|
|
72
|
+
o.home ? path.join(o.home, 'Library', 'pnpm') : undefined,
|
|
73
|
+
o.home ? path.join(o.home, '.local', 'share', 'pnpm') : undefined,
|
|
74
|
+
].filter((h) => !!h);
|
|
75
|
+
const out = [];
|
|
76
|
+
for (const h of homes) {
|
|
77
|
+
let versions;
|
|
78
|
+
try {
|
|
79
|
+
versions = fs.readdirSync(path.join(h, 'global'));
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
for (const v of versions)
|
|
85
|
+
out.push(path.join(h, 'global', v, 'node_modules', ...PKG_NAME.split('/'), rel));
|
|
86
|
+
}
|
|
87
|
+
return out;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Decide what the MCP registration should run: an absolute node binary and an
|
|
91
|
+
* unversioned entry path for THIS CLI. No PATH lookup of `hq` and no shell shim
|
|
92
|
+
* is ever registered; a `hq` found on PATH is only used when it is a file or
|
|
93
|
+
* symlink whose realpath is the running entry (never on win32, where PATH hits
|
|
94
|
+
* are .cmd/.ps1 shims that hosts cannot spawn without a shell).
|
|
95
|
+
*/
|
|
96
|
+
export function resolveMcpLaunch(o) {
|
|
97
|
+
const argv1 = path.resolve(o.argv1);
|
|
98
|
+
const realEntry = realOrSelf(argv1);
|
|
99
|
+
const pathValue = o.env.PATH ?? '';
|
|
100
|
+
const candidates = [argv1, ...pnpmGlobalAliases(realEntry, o)];
|
|
101
|
+
if (o.platform !== 'win32') {
|
|
102
|
+
const onPath = findExecutableOnPath('hq', pathValue, o.platform);
|
|
103
|
+
if (onPath)
|
|
104
|
+
candidates.push(onPath);
|
|
105
|
+
}
|
|
106
|
+
const entry = candidates.find((c) => path.isAbsolute(c) && !isVersionedStorePath(c) && fs.existsSync(c) && realOrSelf(c) === realEntry) ?? realEntry;
|
|
107
|
+
let command = o.execPath;
|
|
108
|
+
if (isVersionedStorePath(command)) {
|
|
109
|
+
const nodeOnPath = findExecutableOnPath('node', pathValue, o.platform);
|
|
110
|
+
if (nodeOnPath && !isVersionedStorePath(nodeOnPath) && realOrSelf(nodeOnPath) === realOrSelf(command))
|
|
111
|
+
command = nodeOnPath;
|
|
112
|
+
}
|
|
113
|
+
const delimiter = o.platform === 'win32' ? ';' : ':';
|
|
114
|
+
const dirs = [path.dirname(command), path.dirname(o.execPath), ...MCP_SUBPROCESS_PATH.split(':')];
|
|
115
|
+
return { command, entry, path: [...new Set(dirs)].join(delimiter) };
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=mcp-launcher.js.map
|
|
@@ -7,6 +7,16 @@ export declare const PACKAGE_USE_LEASE_HANDOFF_ENV = "HQ_CLI_PACKAGE_USE_LEASE_H
|
|
|
7
7
|
*/
|
|
8
8
|
export declare const DEFAULT_UPDATE_WAIT_MS = 240000;
|
|
9
9
|
export declare function updateWaitTimeoutMs(env?: NodeJS.ProcessEnv): number;
|
|
10
|
+
/**
|
|
11
|
+
* The longest one process may hold a package-use lease. The heartbeat keeps the
|
|
12
|
+
* lease fresh for as long as the event loop runs, so without a ceiling a
|
|
13
|
+
* process stuck at a terminal prompt held it for four days and blocked every
|
|
14
|
+
* desktop CLI update (feedback_77165502). Ordinary commands finish in minutes,
|
|
15
|
+
* and long-running commands release after their preload. Override with
|
|
16
|
+
* HQ_CLI_PACKAGE_USE_MAX_HOLD_MS.
|
|
17
|
+
*/
|
|
18
|
+
export declare const DEFAULT_PACKAGE_USE_LEASE_MAX_HOLD_MS: number;
|
|
19
|
+
export declare function packageUseLeaseMaxHoldMs(env?: NodeJS.ProcessEnv): number;
|
|
10
20
|
export declare const PACKAGE_USE_LEASE_PURPOSES: readonly ["command", "resident-preload", "mcp-serve", "hook", "daemon"];
|
|
11
21
|
export type PackageUseLeasePurpose = (typeof PACKAGE_USE_LEASE_PURPOSES)[number];
|
|
12
22
|
export declare class PackageUseUpdatePendingError extends Error {
|
|
@@ -24,6 +24,28 @@ export function updateWaitTimeoutMs(env = process.env) {
|
|
|
24
24
|
}
|
|
25
25
|
const PACKAGE_USE_LEASE_HEARTBEAT_INTERVAL_MS = 5 * 60 * 1000;
|
|
26
26
|
let packageUseLeaseHeartbeatIntervalMs = PACKAGE_USE_LEASE_HEARTBEAT_INTERVAL_MS;
|
|
27
|
+
/**
|
|
28
|
+
* The longest one process may hold a package-use lease. The heartbeat keeps the
|
|
29
|
+
* lease fresh for as long as the event loop runs, so without a ceiling a
|
|
30
|
+
* process stuck at a terminal prompt held it for four days and blocked every
|
|
31
|
+
* desktop CLI update (feedback_77165502). Ordinary commands finish in minutes,
|
|
32
|
+
* and long-running commands release after their preload. Override with
|
|
33
|
+
* HQ_CLI_PACKAGE_USE_MAX_HOLD_MS.
|
|
34
|
+
*/
|
|
35
|
+
export const DEFAULT_PACKAGE_USE_LEASE_MAX_HOLD_MS = 3 * 60 * 60 * 1000;
|
|
36
|
+
export function packageUseLeaseMaxHoldMs(env = process.env) {
|
|
37
|
+
const raw = env.HQ_CLI_PACKAGE_USE_MAX_HOLD_MS?.trim();
|
|
38
|
+
if (!raw || !/^\d+$/.test(raw) || Number(raw) <= 0)
|
|
39
|
+
return DEFAULT_PACKAGE_USE_LEASE_MAX_HOLD_MS;
|
|
40
|
+
return Number(raw);
|
|
41
|
+
}
|
|
42
|
+
function formatHoldDuration(ms) {
|
|
43
|
+
if (ms >= 60 * 60 * 1000)
|
|
44
|
+
return `${Math.round(ms / (60 * 60 * 1000))}h`;
|
|
45
|
+
if (ms >= 60 * 1000)
|
|
46
|
+
return `${Math.round(ms / (60 * 1000))}m`;
|
|
47
|
+
return `${Math.max(1, Math.round(ms / 1000))}s`;
|
|
48
|
+
}
|
|
27
49
|
export const PACKAGE_USE_LEASE_PURPOSES = [
|
|
28
50
|
"command",
|
|
29
51
|
"resident-preload",
|
|
@@ -224,10 +246,19 @@ export function acquirePackageUseLease(prefix, hqVersion, stateDirectory, purpos
|
|
|
224
246
|
let released = false;
|
|
225
247
|
let heartbeatInFlight = false;
|
|
226
248
|
let heartbeat = null;
|
|
249
|
+
const acquiredAtMs = Date.now();
|
|
250
|
+
const maxHoldMs = packageUseLeaseMaxHoldMs();
|
|
227
251
|
const startHeartbeat = () => {
|
|
228
252
|
heartbeat = setInterval(() => {
|
|
229
253
|
if (released || heartbeatInFlight)
|
|
230
254
|
return;
|
|
255
|
+
const heldMs = Date.now() - acquiredAtMs;
|
|
256
|
+
if (heldMs >= maxHoldMs) {
|
|
257
|
+
process.stderr.write(`hq-cli: released the HQ CLI package-use lease held by pid ${record.pid} (${purpose}) ` +
|
|
258
|
+
`after ${formatHoldDuration(heldMs)} so HQ CLI updates are not blocked\n`);
|
|
259
|
+
release();
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
231
262
|
heartbeatInFlight = true;
|
|
232
263
|
const now = new Date();
|
|
233
264
|
void utimes(leasePath, now, now)
|
|
@@ -47,7 +47,7 @@ export const RESIDENT_PACKAGE_MODULES = {
|
|
|
47
47
|
"@indigoai-us/hq-cloud",
|
|
48
48
|
],
|
|
49
49
|
"bot-logs-follow": [],
|
|
50
|
-
mcp: ["../lib/mcp/tools.js", "../lib/mcp/prompts.js", "../lib/anywhere-person-setting.js", "../utils/cognito-session.js", "@indigoai-us/hq-cloud", "../sentry.js", "../lib/doctor/client-health-reason-codes-flag.js", "@indigoai-us/hq-flags-client"],
|
|
50
|
+
mcp: ["../lib/mcp/tools.js", "../lib/mcp/prompts.js", "../lib/mcp/local-native-tools.js", "../lib/anywhere-person-setting.js", "../utils/cognito-session.js", "@indigoai-us/hq-cloud", "../sentry.js", "../lib/doctor/client-health-reason-codes-flag.js", "@indigoai-us/hq-flags-client"],
|
|
51
51
|
childWrapper: ["../main.js", "../lib/service-manager/startup-migration.js", "../commands/storage-gate.js", "../lib/storage-feature-flag.js"],
|
|
52
52
|
coreJobRun: [],
|
|
53
53
|
"daemon-call": ["../lib/daemon/protocol.js"],
|
|
@@ -97,6 +97,7 @@ export const RESIDENT_PACKAGE_MODULES = {
|
|
|
97
97
|
"../lib/daemon/mcp-oauth.js",
|
|
98
98
|
"../lib/mcp/tools.js",
|
|
99
99
|
"../lib/mcp/prompts.js",
|
|
100
|
+
"../lib/mcp/local-native-tools.js",
|
|
100
101
|
"../utils/sandbox-runner-client.js",
|
|
101
102
|
"../utils/cli-telemetry.js",
|
|
102
103
|
"../utils/cognito-session.js",
|
|
@@ -218,6 +219,7 @@ const LOADERS = {
|
|
|
218
219
|
mcp: [
|
|
219
220
|
() => import("../lib/mcp/tools.js"),
|
|
220
221
|
() => import("../lib/mcp/prompts.js"),
|
|
222
|
+
() => import("../lib/mcp/local-native-tools.js"),
|
|
221
223
|
() => import("../lib/anywhere-person-setting.js"),
|
|
222
224
|
() => import("../utils/cognito-session.js"),
|
|
223
225
|
() => import("@indigoai-us/hq-cloud"),
|
|
@@ -441,6 +443,7 @@ const LOADERS = {
|
|
|
441
443
|
() => import("../lib/daemon/mcp-oauth.js"),
|
|
442
444
|
() => import("../lib/mcp/tools.js"),
|
|
443
445
|
() => import("../lib/mcp/prompts.js"),
|
|
446
|
+
() => import("../lib/mcp/local-native-tools.js"),
|
|
444
447
|
() => import("../utils/sandbox-runner-client.js"),
|
|
445
448
|
() => import("../utils/cli-telemetry.js"),
|
|
446
449
|
() => import("../utils/cognito-session.js"),
|
package/docs/anywhere-runtime.md
CHANGED
|
@@ -51,6 +51,13 @@ When the flag is enabled, the global hook uses hqd for events outside the HQ
|
|
|
51
51
|
root. Inside the root, the project hook routes through hqd when it is running
|
|
52
52
|
and uses the direct master hook when it is stopped.
|
|
53
53
|
|
|
54
|
+
The `hq` MCP connector (`hq mcp serve`) works the same way for the tools that
|
|
55
|
+
only touch the HQ checkout. When no hqd is listening, it answers
|
|
56
|
+
`hq_resolve_company`, `hq_policy_check` and `hq_journal_append` in its own
|
|
57
|
+
process, with hqd's company binding, HQ Anywhere check and policy check. It
|
|
58
|
+
needs an HQ root from `HQ_ROOT` or `~/.hq/root`. `hq_run_worker` and the hosted
|
|
59
|
+
HQ tools still need hqd and return `hqd_unreachable` without it.
|
|
60
|
+
|
|
54
61
|
## Flag revocation
|
|
55
62
|
|
|
56
63
|
While hqd is running, it refreshes `hq-anywhere-runtime` every 30 seconds.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@indigoai-us/hq-cli",
|
|
3
|
-
"version": "5.345.
|
|
3
|
+
"version": "5.345.205",
|
|
4
4
|
"description": "HQ by Indigo management CLI — modules and cloud sync",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -117,11 +117,11 @@
|
|
|
117
117
|
"*.{ts,tsx,mts,cts,js,jsx,mjs,cjs}": "eslint --cache --no-error-on-unmatched-pattern"
|
|
118
118
|
},
|
|
119
119
|
"optionalDependencies": {
|
|
120
|
-
"@indigoai-us/hq-hook-win32-x64": "5.345.
|
|
121
|
-
"@indigoai-us/hq-hook-win32-arm64": "5.345.
|
|
122
|
-
"@indigoai-us/hq-hook-darwin-x64": "5.345.
|
|
123
|
-
"@indigoai-us/hq-hook-darwin-arm64": "5.345.
|
|
124
|
-
"@indigoai-us/hq-hook-linux-x64": "5.345.
|
|
125
|
-
"@indigoai-us/hq-hook-linux-arm64": "5.345.
|
|
120
|
+
"@indigoai-us/hq-hook-win32-x64": "5.345.205",
|
|
121
|
+
"@indigoai-us/hq-hook-win32-arm64": "5.345.205",
|
|
122
|
+
"@indigoai-us/hq-hook-darwin-x64": "5.345.205",
|
|
123
|
+
"@indigoai-us/hq-hook-darwin-arm64": "5.345.205",
|
|
124
|
+
"@indigoai-us/hq-hook-linux-x64": "5.345.205",
|
|
125
|
+
"@indigoai-us/hq-hook-linux-arm64": "5.345.205"
|
|
126
126
|
}
|
|
127
127
|
}
|