@indigoai-us/hq-cli 5.345.245 → 5.345.247
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 +91 -0
- package/dist/command-catalog.generated.d.ts +96 -9
- package/dist/command-catalog.generated.js +117 -9
- package/dist/commands/bot.js +1 -1
- package/dist/commands/core-checkpoint-native.d.ts +5 -1
- package/dist/commands/core-checkpoint-native.js +13 -5
- package/dist/commands/deploy-comments.js +139 -0
- package/dist/commands/deploy-list.d.ts +5 -0
- package/dist/commands/deploy-list.js +8 -0
- package/dist/commands/dm.d.ts +4 -1
- package/dist/commands/dm.js +11 -2
- package/dist/commands/files.d.ts +11 -2
- package/dist/commands/files.js +48 -3
- package/dist/commands/install-global.d.ts +15 -0
- package/dist/commands/install-global.js +98 -4
- package/dist/commands/lanes-loop.js +4 -1
- package/dist/commands/lanes.js +16 -5
- package/dist/commands/mcp-registration.d.ts +17 -0
- package/dist/commands/mcp-registration.js +119 -0
- package/dist/commands/mesh.d.ts +2 -0
- package/dist/commands/mesh.js +26 -6
- package/dist/commands/pkg-install.js +1 -1
- package/dist/commands/reindex.js +3 -2
- package/dist/commands/rescue.d.ts +22 -1
- package/dist/commands/rescue.js +56 -9
- package/dist/commands/sources.d.ts +1 -1
- package/dist/commands/sources.js +1 -1
- package/dist/commands/storage.d.ts +15 -2
- package/dist/commands/storage.js +74 -7
- package/dist/hq-cloud-sync-runner/bin/sync-runner.js +232 -225
- package/dist/hq-cloud-sync-runner/package.json +1 -1
- package/dist/lib/agent-kit/mcp/tools.js +22 -0
- package/dist/lib/bot/jobs/hot-signal-sync.js +4 -1
- package/dist/lib/daemon/fleet-members-cache.d.ts +55 -0
- package/dist/lib/daemon/fleet-members-cache.js +266 -0
- package/dist/lib/daemon/handoff.d.ts +4 -0
- package/dist/lib/daemon/handoff.js +2 -1
- package/dist/lib/daemon/hook-requests.d.ts +2 -1
- package/dist/lib/daemon/hook-requests.js +19 -2
- package/dist/lib/daemon/install.d.ts +9 -1
- package/dist/lib/daemon/install.js +11 -2
- package/dist/lib/daemon/ops/policy.d.ts +23 -3
- package/dist/lib/daemon/ops/policy.js +62 -15
- package/dist/lib/daemon/run.js +12 -0
- package/dist/lib/daemon/server.d.ts +5 -0
- package/dist/lib/daemon/server.js +1 -1
- package/dist/lib/daemon/supervisor.d.ts +6 -0
- package/dist/lib/daemon/supervisor.js +31 -2
- package/dist/lib/doctor/checks/antigravity-wiring.d.ts +21 -0
- package/dist/lib/doctor/checks/antigravity-wiring.js +75 -0
- package/dist/lib/doctor/checks/anywhere.js +30 -0
- package/dist/lib/doctor/checks/runtime-probe.js +13 -0
- package/dist/lib/doctor/checks/sync-runtime.js +8 -1
- package/dist/lib/doctor/platform.d.ts +1 -1
- package/dist/lib/doctor/platform.js +5 -0
- package/dist/lib/doctor/registry.js +3 -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/hook-engine/coverage.d.ts +159 -0
- package/dist/lib/hook-engine/coverage.js +347 -0
- package/dist/lib/hook-engine/native-precompact-compatibility.json +1 -0
- package/dist/lib/hot-channels/signals-pass.d.ts +52 -2
- package/dist/lib/hot-channels/signals-pass.js +65 -3
- package/dist/lib/install/antigravity-targets.d.ts +39 -0
- package/dist/lib/install/antigravity-targets.js +122 -0
- package/dist/lib/install/claude-targets.d.ts +6 -0
- package/dist/lib/install/claude-targets.js +9 -1
- package/dist/lib/lanes/reconcile-result.d.ts +1 -1
- package/dist/lib/lanes/reconcile.js +19 -4
- package/dist/lib/lanes/remote-control-lane.d.ts +6 -0
- package/dist/lib/lanes/remote-control-lane.js +10 -1
- package/dist/lib/lanes/spawn.d.ts +2 -0
- package/dist/lib/lanes/spawn.js +19 -3
- package/dist/lib/lanes/worker-env-scrub.d.ts +48 -0
- package/dist/lib/lanes/worker-env-scrub.js +146 -0
- package/dist/lib/lanes/worker-process.js +4 -1
- package/dist/lib/mesh/client.js +5 -1
- package/dist/lib/mesh/live/daemon/doctor.d.ts +9 -0
- package/dist/lib/mesh/live/daemon/doctor.js +51 -6
- package/dist/lib/mesh/live/daemon/install.d.ts +39 -0
- package/dist/lib/mesh/live/daemon/install.js +70 -0
- package/dist/lib/mesh/live/daemon/outbox-company.d.ts +47 -0
- package/dist/lib/mesh/live/daemon/outbox-company.js +77 -0
- package/dist/lib/mesh/live/daemon/run.d.ts +2 -0
- package/dist/lib/mesh/live/daemon/run.js +48 -3
- package/dist/lib/mesh/live/daemon/state.d.ts +5 -0
- package/dist/lib/mesh/live/daemon/system-unit.d.ts +21 -0
- package/dist/lib/mesh/live/daemon/system-unit.js +80 -0
- package/dist/lib/mesh/live/daemon/transcript-watch.d.ts +4 -1
- package/dist/lib/mesh/live/daemon/transcript-watch.js +42 -38
- package/dist/lib/mesh/live/direct-drain.js +3 -1
- package/dist/lib/mesh/live/emit.js +4 -2
- package/dist/lib/mesh/live/flush.d.ts +61 -0
- package/dist/lib/mesh/live/flush.js +434 -114
- package/dist/lib/mesh/live/paths.d.ts +10 -0
- package/dist/lib/mesh/live/paths.js +14 -0
- package/dist/lib/mesh/live/reporting-privacy.d.ts +41 -1
- package/dist/lib/mesh/live/reporting-privacy.js +81 -7
- package/dist/lib/mesh/live/spool.d.ts +171 -17
- package/dist/lib/mesh/live/spool.js +777 -62
- package/dist/lib/signals/engine.d.ts +82 -2
- package/dist/lib/signals/engine.js +389 -53
- package/dist/lib/signals/steps/extract.js +5 -0
- package/dist/lib/work-context/organize.d.ts +22 -4
- package/dist/lib/work-context/organize.js +50 -21
- package/dist/lib/work-context/paths.d.ts +6 -0
- package/dist/lib/work-context/paths.js +9 -0
- package/dist/lib/work-context/reconcile.d.ts +1 -1
- package/dist/lib/work-context/reconcile.js +1 -1
- package/dist/startup-registration.d.ts +14 -0
- package/dist/startup-registration.js +26 -0
- package/dist/utils/cli-telemetry.d.ts +6 -0
- package/dist/utils/cli-telemetry.js +154 -9
- package/dist/utils/github-tag-fallback.d.ts +7 -2
- package/dist/utils/github-tag-fallback.js +17 -8
- package/dist/utils/hq-core-source.d.ts +31 -0
- package/dist/utils/hq-core-source.js +144 -0
- package/dist/utils/interactive-caller.d.ts +6 -0
- package/dist/utils/interactive-caller.js +8 -0
- package/dist/utils/shipped-codex-hooks.d.ts +6 -4
- package/dist/utils/shipped-codex-hooks.js +22 -10
- package/dist/utils/vault-api.js +1 -0
- package/dist/utils/version-report.d.ts +3 -1
- package/dist/utils/version-report.js +13 -5
- package/docs/anywhere-runtime.md +2 -2
- package/package.json +8 -8
- package/scripts/check-function-manifest.mjs +99 -18
|
@@ -3,8 +3,10 @@
|
|
|
3
3
|
*
|
|
4
4
|
* CLI only presents server candidates and submits structured decisions.
|
|
5
5
|
* Ranking is server-owned. Success is reported only from the server receipt.
|
|
6
|
-
* Cancel / timeout / incapable surface
|
|
7
|
-
*
|
|
6
|
+
* Cancel / timeout / incapable surface settles the ask: a session with its
|
|
7
|
+
* company stays needs_project, one without stays as it is or becomes
|
|
8
|
+
* unresolved; the CLI never invents a project or adhoc target and never
|
|
9
|
+
* repeats the ask.
|
|
8
10
|
*/
|
|
9
11
|
import * as crypto from "node:crypto";
|
|
10
12
|
import { WORK_CONTEXT_CONTRACT_VERSION } from "./contract.js";
|
|
@@ -265,8 +267,24 @@ export function formatOrganizeList(result) {
|
|
|
265
267
|
}
|
|
266
268
|
/**
|
|
267
269
|
* Mark that the ask was cancelled / timed out / surface incapable.
|
|
268
|
-
*
|
|
269
|
-
*
|
|
270
|
+
* Clears askAfter so the CLI never repeats the ask, drops any project and
|
|
271
|
+
* task, and never invents one.
|
|
272
|
+
*
|
|
273
|
+
* A session that already has its company (`needs_project`, `needs_task`)
|
|
274
|
+
* stays `needs_project`: settling the project ask does not undo the company
|
|
275
|
+
* binding. Moving it to `unresolved` dropped the session out of
|
|
276
|
+
* `hasWorkMeshCompanyBinding`, so a Work Mesh off switch set afterwards
|
|
277
|
+
* stopped its company reporting (rq_20261121230415_a0cdf53a75). A session
|
|
278
|
+
* without its company stays `needs_company` or `company_conflict`, and any
|
|
279
|
+
* other status becomes `unresolved`.
|
|
280
|
+
*
|
|
281
|
+
* The written file is the whole state less the project, the task, and what
|
|
282
|
+
* describes that project (its gate, bind authority and hint). It keeps the
|
|
283
|
+
* markers that say how far the company can be trusted
|
|
284
|
+
* (`companyConfidence: "device_default"`, `ownerMismatch`), the pending
|
|
285
|
+
* `presenceLeave`, the state `version`, `bindingEpisodeId` and the rest. Without them a guessed
|
|
286
|
+
* device-default company, or one another actor reports, would read as a
|
|
287
|
+
* verified binding once the status stays `needs_project`.
|
|
270
288
|
*/
|
|
271
289
|
export function settleOrganizeAskWithoutBind(input) {
|
|
272
290
|
const state = readSessionState(input.sessionId, input.root);
|
|
@@ -288,36 +306,47 @@ export function settleOrganizeAskWithoutBind(input) {
|
|
|
288
306
|
};
|
|
289
307
|
const next = mergeLocalSessionFields({
|
|
290
308
|
...state,
|
|
309
|
+
// The project and task are dropped below, so a session that had its
|
|
310
|
+
// company keeps it as needs_project.
|
|
291
311
|
contextStatus: state.contextStatus === "needs_company" ||
|
|
292
312
|
state.contextStatus === "company_conflict"
|
|
293
313
|
? state.contextStatus
|
|
294
|
-
: "
|
|
314
|
+
: state.contextStatus === "needs_project" || state.contextStatus === "needs_task"
|
|
315
|
+
? "needs_project"
|
|
316
|
+
: "unresolved",
|
|
295
317
|
decision,
|
|
296
318
|
// Drop any speculative project/task — never invent.
|
|
297
319
|
projectId: undefined,
|
|
298
320
|
taskId: undefined,
|
|
299
321
|
updatedAt: now,
|
|
300
322
|
}, state);
|
|
301
|
-
//
|
|
323
|
+
// Write the whole next state with the project and task removed, so every
|
|
324
|
+
// other field survives the settle: bindingEpisodeId, the migration record,
|
|
325
|
+
// the device-default and owner-mismatch markers, a pending presenceLeave,
|
|
326
|
+
// the project reason and candidates (shown by `hq mesh doctor`, never used
|
|
327
|
+
// to bind), and the local labels (rq_20261122033331_a2dcffa5d0).
|
|
328
|
+
// What describes the dropped project goes with it:
|
|
329
|
+
// - projectGate holds the session's events until a project is chosen, and
|
|
330
|
+
// the settled ask is never asked again, so it would hold them for good;
|
|
331
|
+
// - projectBindAuthority "trusted" stops PRD sync from binding the session
|
|
332
|
+
// to a project again (prd-sync.ts), so it would stay without one;
|
|
333
|
+
// - projectHint is the first source the next prompt binds from
|
|
334
|
+
// (prompt-rebind.ts), so it would bind the project the member just
|
|
335
|
+
// cancelled. Dropping it stops only that: a prompt from the project's
|
|
336
|
+
// folder, or with HQ_SPAWN_PROJECT or a session meta file naming the
|
|
337
|
+
// project, still binds it.
|
|
338
|
+
const { projectId: _projectId, taskId: _taskId, projectGate: _projectGate, projectBindAuthority: _projectBindAuthority, projectHint: _projectHint, ...kept } = next;
|
|
339
|
+
void _projectId;
|
|
340
|
+
void _taskId;
|
|
341
|
+
void _projectGate;
|
|
342
|
+
void _projectBindAuthority;
|
|
343
|
+
void _projectHint;
|
|
302
344
|
const written = {
|
|
345
|
+
...kept,
|
|
303
346
|
contractVersion: WORK_CONTEXT_CONTRACT_VERSION,
|
|
304
|
-
sessionId: next.sessionId,
|
|
305
|
-
contextStatus: next.contextStatus,
|
|
306
347
|
updatedAt: now,
|
|
307
348
|
decision,
|
|
308
349
|
};
|
|
309
|
-
if (next.companyUid)
|
|
310
|
-
written.companyUid = next.companyUid;
|
|
311
|
-
if (next.companySlug)
|
|
312
|
-
written.companySlug = next.companySlug;
|
|
313
|
-
if (typeof next.toolWrites === "number")
|
|
314
|
-
written.toolWrites = next.toolWrites;
|
|
315
|
-
if (next.startedAt)
|
|
316
|
-
written.startedAt = next.startedAt;
|
|
317
|
-
if (next.hasTurn)
|
|
318
|
-
written.hasTurn = true;
|
|
319
|
-
if (next.source)
|
|
320
|
-
written.source = next.source;
|
|
321
350
|
writeSessionState(written, input.root);
|
|
322
351
|
return written;
|
|
323
352
|
}
|
|
@@ -335,7 +364,7 @@ export async function submitOrganizeDecision(input) {
|
|
|
335
364
|
}
|
|
336
365
|
if (input.untracked) {
|
|
337
366
|
// A session with a verified company binding cannot be marked untracked.
|
|
338
|
-
if (hasWorkMeshCompanyBinding(state)) {
|
|
367
|
+
if (hasWorkMeshCompanyBinding(state, undefined, input.root)) {
|
|
339
368
|
return { ok: false, errorCode: COMPANY_BOUND, message: untrackedRefusedMessage(input.sessionId) };
|
|
340
369
|
}
|
|
341
370
|
const now = (input.now ?? (() => new Date()))().toISOString();
|
|
@@ -13,7 +13,13 @@ export declare function workContextSessionPath(sessionId: string, root?: string)
|
|
|
13
13
|
* directory for session state (doctor state-file health) must skip them.
|
|
14
14
|
*/
|
|
15
15
|
export declare const WORK_CONTEXT_PRD_SNAPSHOT_SUFFIX = ".prd-snapshot.json";
|
|
16
|
+
/**
|
|
17
|
+
* Which fleet runtime ran the session, written by the session's own hook
|
|
18
|
+
* (crates/hq-hook/src/mesh_session_policy.rs FLEET_RUNTIME_SIDECAR_SUFFIX).
|
|
19
|
+
*/
|
|
20
|
+
export declare const WORK_CONTEXT_FLEET_RUNTIME_SUFFIX = ".fleet-runtime.json";
|
|
16
21
|
export declare const WORK_CONTEXT_SESSION_SIDECAR_SUFFIXES: readonly string[];
|
|
22
|
+
export declare function workContextFleetRuntimePath(sessionId: string, root?: string): string;
|
|
17
23
|
/** True for `<sessionId>.json`, false for sidecars and non-JSON entries. */
|
|
18
24
|
export declare function isWorkContextSessionStateFileName(name: string): boolean;
|
|
19
25
|
export declare function workContextOutboxDir(root?: string): string;
|
|
@@ -26,9 +26,18 @@ export function workContextSessionPath(sessionId, root) {
|
|
|
26
26
|
* directory for session state (doctor state-file health) must skip them.
|
|
27
27
|
*/
|
|
28
28
|
export const WORK_CONTEXT_PRD_SNAPSHOT_SUFFIX = ".prd-snapshot.json";
|
|
29
|
+
/**
|
|
30
|
+
* Which fleet runtime ran the session, written by the session's own hook
|
|
31
|
+
* (crates/hq-hook/src/mesh_session_policy.rs FLEET_RUNTIME_SIDECAR_SUFFIX).
|
|
32
|
+
*/
|
|
33
|
+
export const WORK_CONTEXT_FLEET_RUNTIME_SUFFIX = ".fleet-runtime.json";
|
|
29
34
|
export const WORK_CONTEXT_SESSION_SIDECAR_SUFFIXES = [
|
|
30
35
|
WORK_CONTEXT_PRD_SNAPSHOT_SUFFIX,
|
|
36
|
+
WORK_CONTEXT_FLEET_RUNTIME_SUFFIX,
|
|
31
37
|
];
|
|
38
|
+
export function workContextFleetRuntimePath(sessionId, root) {
|
|
39
|
+
return path.join(workContextSessionsDir(root), `${sessionId}${WORK_CONTEXT_FLEET_RUNTIME_SUFFIX}`);
|
|
40
|
+
}
|
|
32
41
|
/** True for `<sessionId>.json`, false for sidecars and non-JSON entries. */
|
|
33
42
|
export function isWorkContextSessionStateFileName(name) {
|
|
34
43
|
if (!name.endsWith(".json"))
|
|
@@ -100,7 +100,7 @@ export declare function loadObservationFromFile(filePath: string): ReconcileObse
|
|
|
100
100
|
/**
|
|
101
101
|
* Mark a session untracked (user origin only). Local receipt; no server write.
|
|
102
102
|
*/
|
|
103
|
-
export declare function markUntracked(sessionId: string, deps: Pick<ReconcileDeps, "root" | "now">, clientOperationId?: string): ReconcileOutcome;
|
|
103
|
+
export declare function markUntracked(sessionId: string, deps: Pick<ReconcileDeps, "root" | "now" | "env">, clientOperationId?: string): ReconcileOutcome;
|
|
104
104
|
export declare function reconcileObservation(obs: ReconcileObservation, deps: ReconcileDeps): Promise<ReconcileOutcome>;
|
|
105
105
|
export { replayOutbox };
|
|
106
106
|
//# sourceMappingURL=reconcile.d.ts.map
|
|
@@ -90,7 +90,7 @@ export function markUntracked(sessionId, deps, clientOperationId = `untracked_${
|
|
|
90
90
|
// with a verified company binding cannot be marked untracked. Its state is
|
|
91
91
|
// left as it is and nothing is written.
|
|
92
92
|
const prior = readSessionState(sessionId, deps.root);
|
|
93
|
-
if (hasWorkMeshCompanyBinding(prior)) {
|
|
93
|
+
if (hasWorkMeshCompanyBinding(prior, deps.env, deps.root)) {
|
|
94
94
|
return {
|
|
95
95
|
result: resultOf({
|
|
96
96
|
kind: "error",
|
|
@@ -56,6 +56,20 @@ export declare const DEFAULT_INSTALL_SETTLE_LOCK_TIMEOUT_MS: number;
|
|
|
56
56
|
export declare const INSTALL_TREE_LOCK_WAIT_NOTICE = "hq: another hq updater is still installing hq-cli; waiting for it to finish\u2026";
|
|
57
57
|
/** Resolve the lock ceiling from the environment (0 = do not extend; default on invalid). */
|
|
58
58
|
export declare function resolveSettleLockTimeoutMs(env: NodeJS.ProcessEnv): number;
|
|
59
|
+
/** Operator override for the settle wait's stale-tree observation window. */
|
|
60
|
+
export declare const INSTALL_SETTLE_STALE_PROBE_ENV = "HQ_INSTALL_SETTLE_STALE_PROBE_MS";
|
|
61
|
+
/**
|
|
62
|
+
* Resolve the stale-tree observation window from the environment. Returns
|
|
63
|
+
* undefined (the wait's own default) on absent, blank, or non-numeric values.
|
|
64
|
+
*/
|
|
65
|
+
export declare function resolveSettleStaleProbeMs(env: NodeJS.ProcessEnv): number | undefined;
|
|
66
|
+
/** Operator override for how long a healed tree must stay ready before the wait settles. */
|
|
67
|
+
export declare const INSTALL_SETTLE_QUIET_ENV = "HQ_INSTALL_SETTLE_QUIET_MS";
|
|
68
|
+
/**
|
|
69
|
+
* Resolve the settle wait's quiet window from the environment. Returns
|
|
70
|
+
* undefined (the wait's own default) on absent, blank, or non-numeric values.
|
|
71
|
+
*/
|
|
72
|
+
export declare function resolveSettleQuietMs(env: NodeJS.ProcessEnv): number | undefined;
|
|
59
73
|
/** Minimal view of a `spawnSync` result the seam relies on. */
|
|
60
74
|
export interface RecoverySpawnResult {
|
|
61
75
|
status: number | null;
|
|
@@ -72,6 +72,30 @@ export function resolveSettleLockTimeoutMs(env) {
|
|
|
72
72
|
return DEFAULT_INSTALL_SETTLE_LOCK_TIMEOUT_MS;
|
|
73
73
|
return Number.parseInt(raw.trim(), 10);
|
|
74
74
|
}
|
|
75
|
+
/** Operator override for the settle wait's stale-tree observation window. */
|
|
76
|
+
export const INSTALL_SETTLE_STALE_PROBE_ENV = "HQ_INSTALL_SETTLE_STALE_PROBE_MS";
|
|
77
|
+
/**
|
|
78
|
+
* Resolve the stale-tree observation window from the environment. Returns
|
|
79
|
+
* undefined (the wait's own default) on absent, blank, or non-numeric values.
|
|
80
|
+
*/
|
|
81
|
+
export function resolveSettleStaleProbeMs(env) {
|
|
82
|
+
const raw = env[INSTALL_SETTLE_STALE_PROBE_ENV];
|
|
83
|
+
if (typeof raw !== "string" || !/^\d+$/.test(raw.trim()))
|
|
84
|
+
return undefined;
|
|
85
|
+
return Number.parseInt(raw.trim(), 10);
|
|
86
|
+
}
|
|
87
|
+
/** Operator override for how long a healed tree must stay ready before the wait settles. */
|
|
88
|
+
export const INSTALL_SETTLE_QUIET_ENV = "HQ_INSTALL_SETTLE_QUIET_MS";
|
|
89
|
+
/**
|
|
90
|
+
* Resolve the settle wait's quiet window from the environment. Returns
|
|
91
|
+
* undefined (the wait's own default) on absent, blank, or non-numeric values.
|
|
92
|
+
*/
|
|
93
|
+
export function resolveSettleQuietMs(env) {
|
|
94
|
+
const raw = env[INSTALL_SETTLE_QUIET_ENV];
|
|
95
|
+
if (typeof raw !== "string" || !/^\d+$/.test(raw.trim()))
|
|
96
|
+
return undefined;
|
|
97
|
+
return Number.parseInt(raw.trim(), 10);
|
|
98
|
+
}
|
|
75
99
|
/**
|
|
76
100
|
* Register commands, recovering once from a torn-install module-resolution
|
|
77
101
|
* failure. On a clean registration this returns `{}` and touches nothing else.
|
|
@@ -143,6 +167,8 @@ export async function registerCommandsWithRecovery(args) {
|
|
|
143
167
|
lockPath,
|
|
144
168
|
deadlineMs: resolveSettleTimeoutMs(env),
|
|
145
169
|
lockWaitMs: resolveSettleLockTimeoutMs(env),
|
|
170
|
+
staleProbeMs: resolveSettleStaleProbeMs(env),
|
|
171
|
+
quietMs: resolveSettleQuietMs(env),
|
|
146
172
|
onLockExtended: () => stderr.write(`${INSTALL_TREE_LOCK_WAIT_NOTICE}\n`),
|
|
147
173
|
});
|
|
148
174
|
if (!result.settled) {
|
|
@@ -81,6 +81,12 @@ export declare function withCliFeatureUsed<T>(kind: CliFeatureKind, action: () =
|
|
|
81
81
|
export declare function isCliTelemetryDisabled(env?: NodeJS.ProcessEnv): boolean;
|
|
82
82
|
/** Feature-use collection stays off until the HQ flag is explicitly enabled. */
|
|
83
83
|
export declare function isCliFeatureUsedTelemetryEnabled(): boolean;
|
|
84
|
+
export declare const CLI_TELEMETRY_CONSENT_TTL_MS: number;
|
|
85
|
+
/**
|
|
86
|
+
* Whether this principal may be sent consent-gated CLI telemetry. Never
|
|
87
|
+
* throws. Only `true` allows a send.
|
|
88
|
+
*/
|
|
89
|
+
export declare function hasCliTelemetryConsent(token: string, machineIdentity: boolean, signal: AbortSignal): Promise<boolean>;
|
|
84
90
|
export declare function telemetryDisclosureMarkerPath(): string;
|
|
85
91
|
/**
|
|
86
92
|
* Print the one-line disclosure at most once per machine. Returns whether
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { randomUUID } from "node:crypto";
|
|
1
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
2
2
|
import * as fs from "node:fs";
|
|
3
3
|
import * as os from "node:os";
|
|
4
4
|
import * as path from "node:path";
|
|
5
5
|
import { CLI_VERSION } from "../cli-version.js";
|
|
6
|
-
import { isExpiring, isMachineIdentity, loadCachedTokens, loadMachineCachedTokens, } from "./cognito-session.js";
|
|
6
|
+
import { cognitoCachePrincipalUid, isExpiring, isMachineIdentity, loadCachedTokens, loadMachineCachedTokens, } from "./cognito-session.js";
|
|
7
7
|
import { resolveProcessFlagCompanyContext, resolveProcessFlagGate, } from "../lib/flag-registry.js";
|
|
8
8
|
import { vaultApiFetch } from "./vault-api.js";
|
|
9
9
|
import { firstSyncStepTelemetryProperties, isHumanInteractiveCliSession, } from "../lib/first-sync-next-step.js";
|
|
@@ -106,11 +106,13 @@ export async function emitCliInviteNudgeEvent(event, timeoutMs = TELEMETRY_TIMEO
|
|
|
106
106
|
machineIdentity: isMachineIdentity(),
|
|
107
107
|
}) || process.stdin.isTTY !== true)
|
|
108
108
|
return;
|
|
109
|
-
if (!maybeDiscloseInviteNudgeTelemetry())
|
|
110
|
-
return;
|
|
111
109
|
const controller = new AbortController();
|
|
112
110
|
const timeout = setTimeout(() => controller.abort(), timeoutMs);
|
|
113
111
|
try {
|
|
112
|
+
if (!(await hasCliTelemetryConsent(cached.accessToken, false, controller.signal)))
|
|
113
|
+
return;
|
|
114
|
+
if (!maybeDiscloseInviteNudgeTelemetry())
|
|
115
|
+
return;
|
|
114
116
|
const response = await vaultApiFetch({
|
|
115
117
|
token: cached.accessToken,
|
|
116
118
|
path: "/v1/telemetry/events",
|
|
@@ -181,13 +183,15 @@ export async function emitCliFeatureUsed(usage, timeoutMs = TELEMETRY_TIMEOUT_MS
|
|
|
181
183
|
const token = machineIdentity ? cached.idToken : cached.accessToken;
|
|
182
184
|
if (!token)
|
|
183
185
|
return;
|
|
184
|
-
const consentBasis = maybeDiscloseFeatureUsedTelemetry() ? "disclosed" : "no-consent";
|
|
185
186
|
const controller = new AbortController();
|
|
186
187
|
const timeout = setTimeout(() => controller.abort(), timeoutMs);
|
|
187
188
|
const companyUid = usage.companyUid && COMPANY_UID_PATTERN.test(usage.companyUid)
|
|
188
189
|
? usage.companyUid
|
|
189
190
|
: undefined;
|
|
190
191
|
try {
|
|
192
|
+
if (!(await hasCliTelemetryConsent(token, machineIdentity, controller.signal)))
|
|
193
|
+
return;
|
|
194
|
+
const consentBasis = maybeDiscloseFeatureUsedTelemetry() ? "disclosed" : "no-consent";
|
|
191
195
|
await vaultApiFetch({
|
|
192
196
|
token,
|
|
193
197
|
path: "/v1/telemetry/events",
|
|
@@ -262,6 +266,135 @@ function hqConfigDir() {
|
|
|
262
266
|
const home = process.env.HOME?.trim() || os.homedir();
|
|
263
267
|
return path.join(home, ".hq");
|
|
264
268
|
}
|
|
269
|
+
/**
|
|
270
|
+
* Person consent for the CLI's product events (owner decision 2026-11-21,
|
|
271
|
+
* "Gate on opt-in"). `cli_session_started` in all its variants,
|
|
272
|
+
* `cli_feature_used` and the plan-limit prompt events are sent only when the
|
|
273
|
+
* person's `telemetryOptIn`, read through `GET /v1/usage/opt-in`, is true.
|
|
274
|
+
* Never answered, opted out, and unreadable (no token, network error, timeout,
|
|
275
|
+
* non-2xx, malformed body) all mean "do not send". Agents and machine
|
|
276
|
+
* identities are always collected (the server answers `agent-required`).
|
|
277
|
+
* `HQ_TELEMETRY=0` stays an extra off switch and is checked first.
|
|
278
|
+
*
|
|
279
|
+
* The answer is cached per principal in `~/.hq` for a short TTL so most
|
|
280
|
+
* commands make no consent request. The request shares the emitter's own
|
|
281
|
+
* abort signal, so it stays inside the bounded telemetry allowance and never
|
|
282
|
+
* slows or fails a command.
|
|
283
|
+
*/
|
|
284
|
+
const CLI_TELEMETRY_CONSENT_PATH = "/v1/usage/opt-in";
|
|
285
|
+
export const CLI_TELEMETRY_CONSENT_TTL_MS = 5 * 60_000;
|
|
286
|
+
const CLI_TELEMETRY_CONSENT_CACHE_FILE = "cli-telemetry-consent.json";
|
|
287
|
+
const CLI_TELEMETRY_CONSENT_CACHE_VERSION = 1;
|
|
288
|
+
const pendingConsentReads = new Map();
|
|
289
|
+
function cliTelemetryConsentCachePath() {
|
|
290
|
+
return path.join(hqConfigDir(), CLI_TELEMETRY_CONSENT_CACHE_FILE);
|
|
291
|
+
}
|
|
292
|
+
function consentSubjectKey(token) {
|
|
293
|
+
try {
|
|
294
|
+
const principal = cognitoCachePrincipalUid(token);
|
|
295
|
+
if (!principal)
|
|
296
|
+
return null;
|
|
297
|
+
return createHash("sha256").update(principal).digest("hex");
|
|
298
|
+
}
|
|
299
|
+
catch {
|
|
300
|
+
return null;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
function readCachedConsent(subject, now) {
|
|
304
|
+
try {
|
|
305
|
+
const parsed = JSON.parse(fs.readFileSync(cliTelemetryConsentCachePath(), "utf8"));
|
|
306
|
+
if (typeof parsed !== "object" || parsed === null)
|
|
307
|
+
return null;
|
|
308
|
+
const entry = parsed;
|
|
309
|
+
if (entry.version !== CLI_TELEMETRY_CONSENT_CACHE_VERSION ||
|
|
310
|
+
entry.subject !== subject ||
|
|
311
|
+
typeof entry.enabled !== "boolean" ||
|
|
312
|
+
typeof entry.checkedAt !== "number" ||
|
|
313
|
+
!Number.isFinite(entry.checkedAt) ||
|
|
314
|
+
entry.checkedAt > now ||
|
|
315
|
+
now - entry.checkedAt >= CLI_TELEMETRY_CONSENT_TTL_MS)
|
|
316
|
+
return null;
|
|
317
|
+
return entry.enabled;
|
|
318
|
+
}
|
|
319
|
+
catch {
|
|
320
|
+
return null;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
function writeCachedConsent(subject, enabled, now) {
|
|
324
|
+
try {
|
|
325
|
+
// Do not create ~/.hq. Signed-in runs already have it (cached tokens).
|
|
326
|
+
if (!fs.existsSync(hqConfigDir()))
|
|
327
|
+
return;
|
|
328
|
+
fs.writeFileSync(cliTelemetryConsentCachePath(), JSON.stringify({
|
|
329
|
+
version: CLI_TELEMETRY_CONSENT_CACHE_VERSION,
|
|
330
|
+
subject,
|
|
331
|
+
enabled,
|
|
332
|
+
checkedAt: now,
|
|
333
|
+
}), { mode: 0o600 });
|
|
334
|
+
}
|
|
335
|
+
catch {
|
|
336
|
+
// The cache is an optimization; the next command asks again.
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
/** One opt-in read. `null` means the answer could not be read. */
|
|
340
|
+
async function fetchCliTelemetryConsent(token, signal) {
|
|
341
|
+
try {
|
|
342
|
+
const response = await vaultApiFetch({
|
|
343
|
+
token,
|
|
344
|
+
path: CLI_TELEMETRY_CONSENT_PATH,
|
|
345
|
+
method: "GET",
|
|
346
|
+
signal,
|
|
347
|
+
});
|
|
348
|
+
if (!response.ok)
|
|
349
|
+
return null;
|
|
350
|
+
const body = await response.json();
|
|
351
|
+
if (typeof body !== "object" || body === null)
|
|
352
|
+
return null;
|
|
353
|
+
const enabled = body.enabled;
|
|
354
|
+
return typeof enabled === "boolean" ? enabled : null;
|
|
355
|
+
}
|
|
356
|
+
catch {
|
|
357
|
+
return null;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* Whether this principal may be sent consent-gated CLI telemetry. Never
|
|
362
|
+
* throws. Only `true` allows a send.
|
|
363
|
+
*/
|
|
364
|
+
export async function hasCliTelemetryConsent(token, machineIdentity, signal) {
|
|
365
|
+
try {
|
|
366
|
+
// Agents and machine identities are always collected; the server answers
|
|
367
|
+
// `agent-required` for them, so no request is needed.
|
|
368
|
+
if (machineIdentity)
|
|
369
|
+
return true;
|
|
370
|
+
if (signal.aborted)
|
|
371
|
+
return false;
|
|
372
|
+
const subject = consentSubjectKey(token);
|
|
373
|
+
if (subject) {
|
|
374
|
+
const cached = readCachedConsent(subject, Date.now());
|
|
375
|
+
if (cached !== null)
|
|
376
|
+
return cached;
|
|
377
|
+
}
|
|
378
|
+
// Emitters in one finalization flush share a single in-flight read. It is
|
|
379
|
+
// dropped once settled: the file cache, not process memory, holds the
|
|
380
|
+
// answer, so a long-lived process still re-reads after the TTL.
|
|
381
|
+
const key = subject ?? `unkeyed:${createHash("sha256").update(token).digest("hex")}`;
|
|
382
|
+
let pending = pendingConsentReads.get(key);
|
|
383
|
+
if (!pending) {
|
|
384
|
+
pending = fetchCliTelemetryConsent(token, signal).then((answer) => {
|
|
385
|
+
pendingConsentReads.delete(key);
|
|
386
|
+
if (answer !== null && subject)
|
|
387
|
+
writeCachedConsent(subject, answer, Date.now());
|
|
388
|
+
return answer;
|
|
389
|
+
});
|
|
390
|
+
pendingConsentReads.set(key, pending);
|
|
391
|
+
}
|
|
392
|
+
return (await pending) === true;
|
|
393
|
+
}
|
|
394
|
+
catch {
|
|
395
|
+
return false;
|
|
396
|
+
}
|
|
397
|
+
}
|
|
265
398
|
/**
|
|
266
399
|
* Limit only session-start telemetry per machine. Local state is best effort:
|
|
267
400
|
* damaged or unwritable state must never suppress the event or affect a command.
|
|
@@ -448,16 +581,22 @@ async function emitCachedCliSessionStarted(timeoutMs) {
|
|
|
448
581
|
const cached = loadCachedTokens();
|
|
449
582
|
if (!cached || isExpiring(cached, 120))
|
|
450
583
|
return;
|
|
451
|
-
const
|
|
584
|
+
const machineIdentity = isMachineIdentity();
|
|
585
|
+
const token = machineIdentity ? cached.idToken : cached.accessToken;
|
|
452
586
|
if (!token)
|
|
453
587
|
return;
|
|
588
|
+
// The machine budget is local and synchronous, so it runs before the
|
|
589
|
+
// consent read: a run over budget makes no request at all, and the
|
|
590
|
+
// budget's own diagnostics do not depend on how the network answers.
|
|
454
591
|
if (!allowCliSessionStartedBudget())
|
|
455
592
|
return;
|
|
456
|
-
const disclosed = maybeDiscloseCliTelemetry();
|
|
457
|
-
const consentBasis = disclosed ? "disclosed" : "no-consent";
|
|
458
593
|
const controller = new AbortController();
|
|
459
594
|
const timeout = setTimeout(() => controller.abort(), timeoutMs);
|
|
460
595
|
try {
|
|
596
|
+
if (!(await hasCliTelemetryConsent(token, machineIdentity, controller.signal)))
|
|
597
|
+
return;
|
|
598
|
+
const disclosed = maybeDiscloseCliTelemetry();
|
|
599
|
+
const consentBasis = disclosed ? "disclosed" : "no-consent";
|
|
461
600
|
const response = await vaultApiFetch({
|
|
462
601
|
token,
|
|
463
602
|
path: "/v1/telemetry/events",
|
|
@@ -510,10 +649,12 @@ export async function emitCliFirstSyncNextStepOutcome(outcome, timeoutMs = TELEM
|
|
|
510
649
|
const token = cached.accessToken;
|
|
511
650
|
if (!token)
|
|
512
651
|
return;
|
|
513
|
-
const consentBasis = maybeDiscloseFirstSyncTelemetry() ? "disclosed" : "no-consent";
|
|
514
652
|
const controller = new AbortController();
|
|
515
653
|
const timeout = setTimeout(() => controller.abort(), timeoutMs);
|
|
516
654
|
try {
|
|
655
|
+
if (!(await hasCliTelemetryConsent(token, machineIdentity, controller.signal)))
|
|
656
|
+
return;
|
|
657
|
+
const consentBasis = maybeDiscloseFirstSyncTelemetry() ? "disclosed" : "no-consent";
|
|
517
658
|
const response = await vaultApiFetch({
|
|
518
659
|
token,
|
|
519
660
|
path: "/v1/telemetry/events",
|
|
@@ -579,6 +720,8 @@ export async function emitPlanLimitInviteTeammateExposure(companyUid, timeoutMs
|
|
|
579
720
|
const controller = new AbortController();
|
|
580
721
|
const timeout = setTimeout(() => controller.abort(), timeoutMs);
|
|
581
722
|
try {
|
|
723
|
+
if (!(await hasCliTelemetryConsent(token, machineIdentity, controller.signal)))
|
|
724
|
+
return;
|
|
582
725
|
const response = await vaultApiFetch({
|
|
583
726
|
token,
|
|
584
727
|
path: "/v1/telemetry/events",
|
|
@@ -644,6 +787,8 @@ async function emitCliLimitNoticeEvent(exposure, eventName, action, timeoutMs =
|
|
|
644
787
|
const controller = new AbortController();
|
|
645
788
|
const timeout = setTimeout(() => controller.abort(), timeoutMs);
|
|
646
789
|
try {
|
|
790
|
+
if (!(await hasCliTelemetryConsent(token, machineIdentity, controller.signal)))
|
|
791
|
+
return;
|
|
647
792
|
await vaultApiFetch({
|
|
648
793
|
token,
|
|
649
794
|
path: "/v1/telemetry/events",
|
|
@@ -2,12 +2,17 @@ export interface GitHubLookupDeps {
|
|
|
2
2
|
fetchImpl?: typeof fetch;
|
|
3
3
|
lsRemote?: (repo: string, refsOnly: boolean) => Promise<string>;
|
|
4
4
|
warn?: (message: string) => void;
|
|
5
|
+
/** Web/clone base for the repo. Defaults to the HQ_CORE_SOURCE `webBase`. */
|
|
6
|
+
webBase?: string;
|
|
5
7
|
}
|
|
6
8
|
export declare class GitHubApiUnavailable extends Error {
|
|
7
9
|
}
|
|
8
10
|
export declare function isTransientGitHubStatus(status: number): boolean;
|
|
9
|
-
/**
|
|
10
|
-
|
|
11
|
+
/**
|
|
12
|
+
* No shell: git.exe is resolved from PATH on Windows, just as git is on Unix.
|
|
13
|
+
* The clone URL is webBase/owner/name.git; webBase defaults to HQ_CORE_SOURCE.
|
|
14
|
+
*/
|
|
15
|
+
export declare function readRemoteTags(repo: string, refsOnly: boolean, webBase?: string): Promise<string>;
|
|
11
16
|
export declare function highestReleaseTag(output: string): string;
|
|
12
17
|
/** One scope per command; latest and floor lookups must share this callback. */
|
|
13
18
|
export declare function onceWarning(warn?: (message: string) => void): (message: string) => void;
|
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
import { execFile } from 'node:child_process';
|
|
2
|
+
import { resolveHqCoreSource } from './hq-core-source.js';
|
|
2
3
|
export class GitHubApiUnavailable extends Error {
|
|
3
4
|
}
|
|
4
5
|
export function isTransientGitHubStatus(status) {
|
|
5
6
|
return status === 403 || status === 429 || (status >= 500 && status <= 599);
|
|
6
7
|
}
|
|
7
|
-
/**
|
|
8
|
-
|
|
8
|
+
/**
|
|
9
|
+
* No shell: git.exe is resolved from PATH on Windows, just as git is on Unix.
|
|
10
|
+
* The clone URL is webBase/owner/name.git; webBase defaults to HQ_CORE_SOURCE.
|
|
11
|
+
*/
|
|
12
|
+
export function readRemoteTags(repo, refsOnly, webBase = resolveHqCoreSource().webBase) {
|
|
9
13
|
if (!/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/.test(repo)) {
|
|
10
14
|
return Promise.reject(new Error('expected a GitHub owner/repository'));
|
|
11
15
|
}
|
|
12
16
|
return new Promise((resolve, reject) => {
|
|
13
17
|
execFile('git', ['ls-remote', '--tags', ...(refsOnly ? ['--refs'] : []),
|
|
14
|
-
'
|
|
18
|
+
webBase + '/' + repo + '.git'], {
|
|
15
19
|
env: { ...process.env, GIT_TERMINAL_PROMPT: '0', GCM_INTERACTIVE: 'Never' },
|
|
16
20
|
timeout: 30_000, maxBuffer: 16 * 1024 * 1024, windowsHide: true,
|
|
17
21
|
encoding: 'utf8',
|
|
@@ -63,10 +67,15 @@ export function onceWarning(warn = console.warn) {
|
|
|
63
67
|
}
|
|
64
68
|
};
|
|
65
69
|
}
|
|
70
|
+
function lsRemoteFor(deps) {
|
|
71
|
+
return deps.lsRemote ?? ((repo, refsOnly) => readRemoteTags(repo, refsOnly, deps.webBase));
|
|
72
|
+
}
|
|
66
73
|
async function publishedReleaseTag(repo, deps) {
|
|
67
74
|
if (!/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/.test(repo))
|
|
68
75
|
throw new Error('expected a GitHub owner/repository');
|
|
69
|
-
const
|
|
76
|
+
const webBase = deps.webBase ?? resolveHqCoreSource().webBase;
|
|
77
|
+
const base = `${webBase}/${repo}`;
|
|
78
|
+
const baseUrl = new URL(base);
|
|
70
79
|
const request = (url, method) => (deps.fetchImpl ?? fetch)(url, {
|
|
71
80
|
method, redirect: 'manual', signal: AbortSignal.timeout(3_000),
|
|
72
81
|
});
|
|
@@ -75,15 +84,15 @@ async function publishedReleaseTag(repo, deps) {
|
|
|
75
84
|
const location = response.headers.get('location');
|
|
76
85
|
if (response.status === 302 && location) {
|
|
77
86
|
const target = new URL(location, base);
|
|
78
|
-
const prefix =
|
|
87
|
+
const prefix = `${baseUrl.pathname}/releases/tag/`;
|
|
79
88
|
const tag = target.pathname.slice(prefix.length);
|
|
80
|
-
if (target.origin ===
|
|
89
|
+
if (target.origin === baseUrl.origin && target.pathname.startsWith(prefix)
|
|
81
90
|
&& !target.search && !target.hash && STRICT_RELEASE_TAG.test(tag))
|
|
82
91
|
return tag;
|
|
83
92
|
}
|
|
84
93
|
}
|
|
85
94
|
catch { /* Try bounded publication checks when the web pointer is unavailable. */ }
|
|
86
|
-
const tags = sortedReleaseTags(await (deps
|
|
95
|
+
const tags = sortedReleaseTags(await lsRemoteFor(deps)(repo, true));
|
|
87
96
|
// A tag alone is not evidence of publication: release validation runs after tagging.
|
|
88
97
|
for (const tag of tags.slice(0, 5)) {
|
|
89
98
|
try {
|
|
@@ -113,7 +122,7 @@ export async function withGitTagFallback(api, repo, tag, select, deps) {
|
|
|
113
122
|
try {
|
|
114
123
|
result = select(tag === undefined
|
|
115
124
|
? await publishedReleaseTag(repo, deps)
|
|
116
|
-
: await (deps
|
|
125
|
+
: await lsRemoteFor(deps)(repo, false));
|
|
117
126
|
}
|
|
118
127
|
catch (gitError) {
|
|
119
128
|
throw new Error(error.message + '; git ls-remote fallback failed: ' +
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export interface HqCoreSource {
|
|
2
|
+
/** Prod channel `owner/name`. */
|
|
3
|
+
repo: string;
|
|
4
|
+
/** Staging channel `owner/name`. */
|
|
5
|
+
stagingRepo: string;
|
|
6
|
+
/** REST API base, e.g. `https://api.github.com`. */
|
|
7
|
+
apiBase: string;
|
|
8
|
+
/** Tarball base, e.g. `https://codeload.github.com`. */
|
|
9
|
+
codeloadBase: string;
|
|
10
|
+
/** Web/clone base, e.g. `https://github.com`. */
|
|
11
|
+
webBase: string;
|
|
12
|
+
}
|
|
13
|
+
export declare const DEFAULT_HQ_CORE_SOURCE: Readonly<HqCoreSource>;
|
|
14
|
+
export declare const HQ_CORE_SOURCE_ENV = "HQ_CORE_SOURCE";
|
|
15
|
+
export interface ResolveHqCoreSourceOptions {
|
|
16
|
+
env?: NodeJS.ProcessEnv;
|
|
17
|
+
/** Home directory holding `.hq/core-source.json`. Defaults to `os.homedir()`. */
|
|
18
|
+
homeDir?: string;
|
|
19
|
+
warn?: (message: string) => void;
|
|
20
|
+
}
|
|
21
|
+
export declare function hqCoreSourceFile(homeDir?: string): string;
|
|
22
|
+
/** Resolve the hq-core source address. Never throws. */
|
|
23
|
+
export declare function resolveHqCoreSource(options?: ResolveHqCoreSourceOptions): HqCoreSource;
|
|
24
|
+
/** True when `url` targets github.com, api.github.com or codeload.github.com over https. */
|
|
25
|
+
export declare function isGitHubHost(url: string): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* The GitHub token to send to `url`, or undefined. A GitHub token is never
|
|
28
|
+
* forwarded to an overridden non-GitHub host.
|
|
29
|
+
*/
|
|
30
|
+
export declare function githubTokenFor(url: string, token: string | undefined): string | undefined;
|
|
31
|
+
//# sourceMappingURL=hq-core-source.d.ts.map
|