@indigoai-us/hq-cli 5.345.232 → 5.345.234
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 +24 -0
- package/dist/command-catalog.generated.d.ts +4 -0
- package/dist/command-catalog.generated.js +5 -0
- package/dist/commands/core-handoff.d.ts +1 -0
- package/dist/commands/core-handoff.js +2 -28
- package/dist/commands/doctor.d.ts +1 -0
- package/dist/commands/doctor.js +24 -0
- package/dist/commands/install-global.js +10 -0
- package/dist/commands/mcp-serve-gate.d.ts +22 -0
- package/dist/commands/mcp-serve-gate.js +37 -0
- package/dist/commands/mcp-serve.js +2 -8
- package/dist/hq-cloud-sync-runner/bin/sync-runner.js +257 -214
- package/dist/hq-cloud-sync-runner/package.json +1 -1
- package/dist/index.js +6 -1
- package/dist/lib/daemon/flag.d.ts +2 -0
- package/dist/lib/daemon/flag.js +6 -4
- package/dist/lib/daemon/shared-flag-reads.d.ts +70 -0
- package/dist/lib/daemon/shared-flag-reads.js +173 -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.js +50 -0
- package/dist/lib/windows/jq.d.ts +17 -0
- package/dist/lib/windows/jq.js +72 -0
- package/dist/utils/cognito-session.d.ts +2 -56
- package/dist/utils/cognito-session.js +6 -164
- package/package.json +8 -8
- package/scripts/install-hook-engine.mjs +8 -15
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,30 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## [5.345.234] — 2026-11-19
|
|
6
|
+
- Recognize the HQ Core 16.0.50 policy injector on platforms with the Rust state store.
|
|
7
|
+
- The native hook engine now claims the old dispatcher's own work on Grok Build's PermissionDenied, PostCompact and PostToolUseFailure events (session bind, duplicate-event check, timeout journal), as it does for Notification, so those three events have no unclaimed hook left in the coverage list. With `HQ_HOOK_TRACE` set, the engine prints the dispatcher's trace lines for them on stderr, which the Grok adapter used to drop. If an HQ has a hook of one of these events that the engine does not run, the native event does none of that work and prints why on stderr; run `hq reindex` to keep the event on the old dispatcher while such a hook exists. `hq reindex` still keeps these events on the old dispatcher until the engine reports `lifecycle-dispatch`.
|
|
8
|
+
- The native hook engine now claims the old dispatcher's own work on Grok Build's StopCancelled and StopFailure events (session bind, duplicate-event check, timeout journal), which the Grok adapter ran as a Stop after its turn-end step, so those two events have no unclaimed hook left in the coverage list. If an HQ has a Stop hook the engine does not run on these events (a Stop folder hook, the turn-end hook included, or another Stop command in `.claude/settings.json`), the native event does none of that work and prints why on stderr. `hq reindex` still keeps these events on the old dispatcher until the engine reports `lifecycle-dispatch`.
|
|
9
|
+
- Fixed Windows hook tests to verify the platform's Bash fallback and read parity ledger entries with either LF or CRLF line endings.
|
|
10
|
+
- Windows HQ installs now provision a checksum-verified jq for hooks. Run `hq doctor --fix-jq` to repair a missing managed copy.
|
|
11
|
+
|
|
12
|
+
## [5.345.233] — 2026-11-19
|
|
13
|
+
- Test: publish the daemon bootstrap lease test's JSON trace atomically.
|
|
14
|
+
- Updates the bundled HQ Cloud to 6.18.113. A company Outpost other than the company's first one now accepts its own sign-in: the box checks the machine token's Outpost id against `HQ_COMPANY_OUTPOST_ID` instead of always expecting the company's first Outpost. Boxes without that variable, or with the first Outpost's id, behave as before.
|
|
15
|
+
- Updates the bundled HQ Cloud to 6.18.114. On an additional company Outpost, shells, exec sessions, lanes, jobs and the company sync service now read the box's Outpost id from `/etc/company-outpost.env` when their environment lacks it, so `hq secrets exec`, `hq integrations` and other machine-authenticated commands work there. The environment still takes precedence, and tokens for any other Outpost or company are still refused.
|
|
16
|
+
- The native secret-reveal command rule now splits commands as the released hook library does (hq-core 16.0.47 and 16.0.48): an ANSI-C string such as `hq secrets $'reveal' KEY` is now refused as the released `block-agent-secrets-reveal` refuses it, and text after a `#` comment is no longer read as a command. hq-hook now claims `block-agent-secrets-reveal` for PreToolUse.
|
|
17
|
+
- hq-hook: the native `lanes-repo-merge-hold` port now refuses a Bash command over 131071 bytes that contains `merge`, on every platform, before `hq runners hold check` is looked up. Before, Linux could not pass such a command to hq as one argument (the kernel's per-argument limit), so the check never ran there. This matches the newer hold shim and the native merge-gates check.
|
|
18
|
+
- Make hq-hook's PreToolUse check read host-specific coverage claims (`PreToolUse@codex`), so a claim for one host can never take another host's PreToolUse off the old dispatcher, and a host whose claim misses a hook refuses instead of skipping it.
|
|
19
|
+
- `hq mcp serve` without a person token cache now writes its "HQ Anywhere is not enabled" denial before it loads the server module and its hqd protocol, package lease and resident preload modules (20 modules loaded instead of 26). The message, exit code 1 and the 40 ms start-up bound are unchanged.
|
|
20
|
+
- Prepare an explicit current-staging arithmetic evaluator with command-wrapper, IFS, and split-string checks; installed hooks retain their existing arithmetic behavior.
|
|
21
|
+
- The native Stop now keeps a block a Stop folder hook has already given when the evaluator chain's deadline cuts the Stop check while a later hook is still running, as master-hook blocks there; before, a fresh Stop was allowed. A hook cut at its deadline is now reaped inside the TERM wait and gets KILL only if its process group is still there, so on Linux a hook that exits on TERM no longer holds the answer for the whole half second.
|
|
22
|
+
- One HQ-root resolver and one session-id resolver: the cloud session helpers use the HQ-root resolver in hq-root-resolver.ts instead of their own copy, and `hq core handoff` uses the shared session-id resolver. Handoff now strips only ASCII whitespace from a session id, as the shell session-id helper does (US-030 c2).
|
|
23
|
+
- Internal: `hq-hook`'s native master-hook lifecycle work (`lifecycle_master`) now models Codex `SubagentStop`, as the released v16.0.47 Codex adapter ran master-hook through `dispatch_settings_hooks "SubagentStop" "ANY"`: the settings entry it read, the payload and `HQ_HARNESS=codex` it passed, the session bind, twin dedupe, timeout journal and fan-out (registry skipped). A Codex payload that names the agent, and settings the adapter read differently, are refused before any write. Not registered or claimed: `master-hook:SubagentStop` and `codex-adapter:SubagentStop` stay unclaimed.
|
|
24
|
+
- Internal: the native Codex PostToolUse port now pins the beta.124 adapter generation that current hq-core ships (adapter a3178b59, core 940bb5a0), as an exact adapter/core pair next to v16.0.47. Before, every Codex tool call on a current root failed closed as an unknown adapter. A mixed pair (one release's adapter with the other's core) still refuses.
|
|
25
|
+
- Match jq 1.8.1 diagnostic formatting when the Windows executable stores its version beside the help text.
|
|
26
|
+
- Show the SessionStart nested-install warning when HQ paths use Windows separators, with its paths spelled as master-hook prints them under Git Bash (`/c/...`).
|
|
27
|
+
- `hq-hook run` now does the Work Mesh SessionStart hook (`core/hooks/SessionStart/35-work-mesh-session-start.sh`) natively on every host: the `session_start` spool line with the harness word each host's adapter set, the live-binding marker, the observation file and the offline preflight, with the reconcile and the pending-registration retry left for the HQ daemon as request notes. On a preflight cache miss it runs `hq mesh context reconcile --offline` with a 2-second limit, binds the device-default session and refills the cache, as the shell hook did. If the daemon state has no answer for the multi-company session lock, the session is bound to its primary company only, with one stderr line.
|
|
28
|
+
|
|
5
29
|
## [5.345.232] — 2026-11-18
|
|
6
30
|
- `hq-hook` claims `codex-adapter:PostToolUse` on Codex only (`PostToolUse@codex`): the Codex adapter's own PostToolUse work is native. `master-hook:PostToolUse` and each settings command keep their own ids and stay unclaimed, so PostToolUse stays on the old dispatcher.
|
|
7
31
|
- hq-hook can now build and leave a `codex-settings` request note for the HQ daemon: one Codex PostToolUse call's `.claude/settings.json` records, with the payload as the note's body. It refuses a note the daemon would drop. No hook calls it yet, and no hook claim changes.
|
|
@@ -12963,6 +12963,10 @@ export declare const COMMAND_CATALOG: readonly [{
|
|
|
12963
12963
|
readonly flags: "--fix";
|
|
12964
12964
|
readonly description: "Apply the allowlisted safe repairs (backs up first; read-only without this flag).";
|
|
12965
12965
|
readonly hidden: false;
|
|
12966
|
+
}, {
|
|
12967
|
+
readonly flags: "--fix-jq";
|
|
12968
|
+
readonly description: "Install the verified jq required by HQ hooks on Windows.";
|
|
12969
|
+
readonly hidden: false;
|
|
12966
12970
|
}, {
|
|
12967
12971
|
readonly flags: "--client-health-report";
|
|
12968
12972
|
readonly description: "Resolve the opt-in hq-flags gate used by the client-health report hook.";
|
|
@@ -15765,6 +15765,11 @@ export const COMMAND_CATALOG = [
|
|
|
15765
15765
|
"description": "Apply the allowlisted safe repairs (backs up first; read-only without this flag).",
|
|
15766
15766
|
"hidden": false
|
|
15767
15767
|
},
|
|
15768
|
+
{
|
|
15769
|
+
"flags": "--fix-jq",
|
|
15770
|
+
"description": "Install the verified jq required by HQ hooks on Windows.",
|
|
15771
|
+
"hidden": false
|
|
15772
|
+
},
|
|
15768
15773
|
{
|
|
15769
15774
|
"flags": "--client-health-report",
|
|
15770
15775
|
"description": "Resolve the opt-in hq-flags gate used by the client-health report hook.",
|
|
@@ -16,6 +16,7 @@ type HandoffContext = {
|
|
|
16
16
|
/** Builds the HQ-Fingerprint commit trailer value. Defaults to the offline builder. */
|
|
17
17
|
buildFingerprint?: (root: string) => string | null;
|
|
18
18
|
};
|
|
19
|
+
export declare function boundSessionCompany(root: string): string;
|
|
19
20
|
export declare function runHandoffFinalize(args: string[], context: HandoffContext): RunResult;
|
|
20
21
|
export declare function runHandoffPost(args: string[], context: HandoffContext): RunResult | Promise<RunResult>;
|
|
21
22
|
export declare function runHandoffPostWorker(args: string[], context: HandoffContext): RunResult;
|
|
@@ -14,6 +14,7 @@ import { enqueueSessionEvent } from "../lib/mesh/live/enqueue.js";
|
|
|
14
14
|
import { renderIndexTarget } from "../lib/index-render/index.js";
|
|
15
15
|
import { defaultBackgroundDependencies, runBackgroundLauncher, } from "../lib/search-index/background.js";
|
|
16
16
|
import { resolveLiveRoot } from "../utils/hq-roots.js";
|
|
17
|
+
import { resolveSessionId } from "../lib/core-utils/session-id.js";
|
|
17
18
|
import { runBundledScript } from "../utils/run-bundled-script.js";
|
|
18
19
|
import { describeCoreCommand } from "./core-command-catalog.js";
|
|
19
20
|
import { subprocess } from "./core-delegate.js";
|
|
@@ -33,34 +34,7 @@ const DESCRIPTIONS = {
|
|
|
33
34
|
post: "Run best-effort post-handoff maintenance",
|
|
34
35
|
openSteps: "List and update open handoff steps",
|
|
35
36
|
};
|
|
36
|
-
|
|
37
|
-
"HQ_SESSION_ID",
|
|
38
|
-
"CLAUDE_CODE_SESSION_ID",
|
|
39
|
-
"CLAUDE_SESSION_ID",
|
|
40
|
-
"CODEX_SESSION_ID",
|
|
41
|
-
"CODEX_THREAD_ID",
|
|
42
|
-
"GROK_SESSION_ID",
|
|
43
|
-
"HQ_FLEET_SESSION_ID",
|
|
44
|
-
];
|
|
45
|
-
function validSessionId(value) {
|
|
46
|
-
return value !== "" && value !== "." && value !== ".." && /^[A-Za-z0-9._-]+$/.test(value);
|
|
47
|
-
}
|
|
48
|
-
function resolveSessionId(root) {
|
|
49
|
-
for (const key of SESSION_ID_ENV_KEYS) {
|
|
50
|
-
const value = (process.env[key] ?? "").replace(/\s/g, "");
|
|
51
|
-
if (validSessionId(value))
|
|
52
|
-
return value;
|
|
53
|
-
}
|
|
54
|
-
const current = path.join(root, "workspace/sessions/.current");
|
|
55
|
-
try {
|
|
56
|
-
const value = fs.readFileSync(current, "utf8").replace(/\s/g, "");
|
|
57
|
-
return validSessionId(value) ? value : "";
|
|
58
|
-
}
|
|
59
|
-
catch {
|
|
60
|
-
return "";
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
function boundSessionCompany(root) {
|
|
37
|
+
export function boundSessionCompany(root) {
|
|
64
38
|
const sessionId = resolveSessionId(root);
|
|
65
39
|
if (!sessionId)
|
|
66
40
|
return "";
|
|
@@ -133,6 +133,7 @@ export interface DoctorCommandDeps {
|
|
|
133
133
|
sweepTempHomes?: (options: {
|
|
134
134
|
dryRun: boolean;
|
|
135
135
|
}) => TempHomeSweepResult;
|
|
136
|
+
installWindowsJq?: () => Promise<string | undefined>;
|
|
136
137
|
}
|
|
137
138
|
/** Text report for `hq doctor --sweep-temp-homes`. */
|
|
138
139
|
export declare function renderTempHomeSweepText(result: TempHomeSweepResult): string;
|
package/dist/commands/doctor.js
CHANGED
|
@@ -32,6 +32,7 @@ import { DEEP_FAMILY_ID, DEEP_FAMILY_TITLE, runDeepGuardTests, } from "../lib/do
|
|
|
32
32
|
import { PARITY_FAMILY_ID, PARITY_FAMILY_TITLE, runParityReplay, } from "../lib/doctor/deep/parity.js";
|
|
33
33
|
import { applyFixes } from "../lib/doctor/fix/apply.js";
|
|
34
34
|
import { renderDoctorFixJson } from "../lib/doctor/fix/json-output.js";
|
|
35
|
+
import { installWindowsJq } from "../lib/windows/jq.js";
|
|
35
36
|
import { clientHealthCheckStatusEnabled as isActiveCompanyClientHealthCheckStatusEnabled, clientHealthCheckStatusEnabledForCompany, clientHealthReasonCodesEnabled as isActiveCompanyClientHealthReasonCodesEnabled, clientHealthReasonCodesEnabledForCompany, } from "../lib/doctor/client-health-reason-codes-flag.js";
|
|
36
37
|
import { clientHealthCompanyScopeFromCheckId } from "../lib/doctor/checks/sync-health.js";
|
|
37
38
|
import { readCompaniesManifestMap } from "../lib/work-context/repo-remote.js";
|
|
@@ -363,12 +364,35 @@ export function registerDoctorCommand(program, deps = {}) {
|
|
|
363
364
|
.option("--company <slug>", "Company slug for integrations checks (otherwise resolves your single active company).")
|
|
364
365
|
.option("--only <families>", "Run only these comma-separated check families (e.g. hooks). Unknown names are rejected; --json then records the scope.")
|
|
365
366
|
.option("--fix", "Apply the allowlisted safe repairs (backs up first; read-only without this flag).")
|
|
367
|
+
.option("--fix-jq", "Install the verified jq required by HQ hooks on Windows.")
|
|
366
368
|
.addOption(new Option("--client-health-report", "Resolve the opt-in hq-flags gate used by the client-health report hook.").hideHelp())
|
|
367
369
|
.option("--sweep-temp-homes", "Delete idle temp homes (90+ minutes untouched, not in use): tmp.* folders holding .rustup or .cargo, and hq-temp-home.* folders left by the wrapper. Reports GB freed.")
|
|
368
370
|
.option("--dry-run", "With --sweep-temp-homes, list what would be removed and delete nothing.")
|
|
369
371
|
.option("--yes", "Skip the interactive --fix confirmation (non-interactive use).")
|
|
370
372
|
.option("--force", "Let --fix run despite uncommitted changes under .claude/, .codex/, or .grok/.")
|
|
371
373
|
.action(async (opts, command) => {
|
|
374
|
+
if (opts.fixJq === true) {
|
|
375
|
+
if (opts.fix || opts.only !== undefined || opts.sweepTempHomes || opts.dryRun) {
|
|
376
|
+
process.stderr.write("hq doctor --fix-jq must run as a standalone repair.\n");
|
|
377
|
+
process.exitCode = 1;
|
|
378
|
+
return;
|
|
379
|
+
}
|
|
380
|
+
try {
|
|
381
|
+
const target = await (deps.installWindowsJq ?? installWindowsJq)();
|
|
382
|
+
if (!target)
|
|
383
|
+
throw new Error("The managed jq repair is only available on Windows.");
|
|
384
|
+
process.stdout.write(opts.json ? `${JSON.stringify({ target })}\n` : `Verified jq is ready at ${target}.\n`);
|
|
385
|
+
}
|
|
386
|
+
catch (error) {
|
|
387
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
388
|
+
if (opts.json)
|
|
389
|
+
process.stdout.write(`${JSON.stringify({ error: message })}\n`);
|
|
390
|
+
else
|
|
391
|
+
process.stderr.write(`hq doctor --fix-jq: ${message}\n`);
|
|
392
|
+
process.exitCode = 1;
|
|
393
|
+
}
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
372
396
|
// `--sweep-temp-homes` is a second write path with its own fixed
|
|
373
397
|
// scope (idle, unused temp homes in the temp dirs). Like `--fix`,
|
|
374
398
|
// it refuses a family scope it would otherwise ignore, and it does not
|
|
@@ -30,6 +30,7 @@ import { trustCodexUserHooks } from '../utils/hook-trust.js';
|
|
|
30
30
|
import { assertProviderWrappersInstallable, installProviderWrappers, providerWrapperInstallPaths, removeProviderWrappers } from '../lib/install/provider-wrappers.js';
|
|
31
31
|
import { checkShimOnPath, ensureShimOnUserPath, npmShimDir, shimPathWarning } from '../lib/windows/user-path.js';
|
|
32
32
|
import { removeHqCliPs1Shims } from '../lib/windows/ps1-shims.js';
|
|
33
|
+
import { installWindowsJq, WINDOWS_JQ_REPAIR } from '../lib/windows/jq.js';
|
|
33
34
|
import { addAgentsMdBlock, addCodexHooks, classifyLegacySkills, codexAdapterPath, codexCharterSource, codexHookTrustKeys, codexTargets, hasAllCodexHooks, HQ_OWNED_MARKER, LEGACY_BACKUP_NAME, LEGACY_SKILLS_NAME, removeAgentsMdBlock, removeCodexHooks, } from '../lib/install/codex-targets.js';
|
|
34
35
|
import { addClaudeMdBlock, addHqHooks, charterPath, claudeTargets, hasAllHqHooks, HQ_ANYWHERE_PACK, HQ_MCP_SERVER_NAME, hqSkillsSource, lineDiff, masterHookPath, shimPath, removeClaudeMdBlock, removeHqHooks, SKILL_LINK_PREFIX, } from '../lib/install/claude-targets.js';
|
|
35
36
|
export { hookTargetFor, isDaemonInstalled } from '../lib/install/hook-target.js';
|
|
@@ -1207,6 +1208,15 @@ export async function runInstallGlobal(opts) {
|
|
|
1207
1208
|
}
|
|
1208
1209
|
const install = runtime === 'codex' ? installGlobalCodex : installGlobalClaude;
|
|
1209
1210
|
const hqRoot = resolveInstallRoot(opts.hqRoot, { env, cwd: opts.cwd, home: opts.home });
|
|
1211
|
+
if (process.platform === 'win32' && !opts.dryRun) {
|
|
1212
|
+
try {
|
|
1213
|
+
await installWindowsJq({ home: opts.home });
|
|
1214
|
+
}
|
|
1215
|
+
catch (error) {
|
|
1216
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1217
|
+
throw Object.assign(new Error(`Could not install jq for HQ hooks: ${message} Run ${WINDOWS_JQ_REPAIR} and retry.`), { expected: true });
|
|
1218
|
+
}
|
|
1219
|
+
}
|
|
1210
1220
|
install({
|
|
1211
1221
|
hqRoot,
|
|
1212
1222
|
home: opts.home,
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The first check of `hq mcp serve`, kept in its own small module so that the
|
|
3
|
+
* fast route in src/index.ts can deny a fresh install before it loads
|
|
4
|
+
* commands/mcp-serve.js and that module's hqd protocol, package lease and
|
|
5
|
+
* resident preload imports. Builtins and the flag key only.
|
|
6
|
+
*/
|
|
7
|
+
export declare const MCP_SERVE_DISABLED_MESSAGE = "HQ Anywhere is not enabled. The hq-anywhere-runtime flag and your HQ Anywhere person setting must both be on.\n";
|
|
8
|
+
/**
|
|
9
|
+
* A person token is required to read the opt-in setting, so without the token
|
|
10
|
+
* cache the server is denied. Mirrors personTokenCacheFile() in
|
|
11
|
+
* utils/cognito-session.ts; duplicated so this path does not load that module.
|
|
12
|
+
*/
|
|
13
|
+
export declare function hasPersonTokenCache(env: NodeJS.ProcessEnv, home: string): boolean;
|
|
14
|
+
/** Write the denial and set exit code 1, as runMcpServe does. */
|
|
15
|
+
export declare function denyMcpServe(stderr?: NodeJS.WritableStream): void;
|
|
16
|
+
/**
|
|
17
|
+
* The fast route's check: true when there is no person token cache, after the
|
|
18
|
+
* denial was written. runMcpServe makes the same check first, so the result
|
|
19
|
+
* and output are the same with or without this step.
|
|
20
|
+
*/
|
|
21
|
+
export declare function denyMcpServeWithoutTokenCache(env?: NodeJS.ProcessEnv, home?: string): boolean;
|
|
22
|
+
//# sourceMappingURL=mcp-serve-gate.d.ts.map
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The first check of `hq mcp serve`, kept in its own small module so that the
|
|
3
|
+
* fast route in src/index.ts can deny a fresh install before it loads
|
|
4
|
+
* commands/mcp-serve.js and that module's hqd protocol, package lease and
|
|
5
|
+
* resident preload imports. Builtins and the flag key only.
|
|
6
|
+
*/
|
|
7
|
+
import * as fs from "node:fs";
|
|
8
|
+
import * as os from "node:os";
|
|
9
|
+
import * as path from "node:path";
|
|
10
|
+
import { HQ_ANYWHERE_RUNTIME_FLAG } from "../lib/anywhere-runtime-flag-key.js";
|
|
11
|
+
export const MCP_SERVE_DISABLED_MESSAGE = `HQ Anywhere is not enabled. The ${HQ_ANYWHERE_RUNTIME_FLAG} flag and your HQ Anywhere person setting must both be on.\n`;
|
|
12
|
+
/**
|
|
13
|
+
* A person token is required to read the opt-in setting, so without the token
|
|
14
|
+
* cache the server is denied. Mirrors personTokenCacheFile() in
|
|
15
|
+
* utils/cognito-session.ts; duplicated so this path does not load that module.
|
|
16
|
+
*/
|
|
17
|
+
export function hasPersonTokenCache(env, home) {
|
|
18
|
+
const stateDir = env.HQ_STATE_DIR?.trim() || path.join(home, ".hq");
|
|
19
|
+
return fs.existsSync(path.join(stateDir, "cognito-tokens.json"));
|
|
20
|
+
}
|
|
21
|
+
/** Write the denial and set exit code 1, as runMcpServe does. */
|
|
22
|
+
export function denyMcpServe(stderr = process.stderr) {
|
|
23
|
+
stderr.write(MCP_SERVE_DISABLED_MESSAGE);
|
|
24
|
+
process.exitCode = 1;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The fast route's check: true when there is no person token cache, after the
|
|
28
|
+
* denial was written. runMcpServe makes the same check first, so the result
|
|
29
|
+
* and output are the same with or without this step.
|
|
30
|
+
*/
|
|
31
|
+
export function denyMcpServeWithoutTokenCache(env = process.env, home = os.homedir()) {
|
|
32
|
+
if (hasPersonTokenCache(env, home))
|
|
33
|
+
return false;
|
|
34
|
+
denyMcpServe();
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=mcp-serve-gate.js.map
|
|
@@ -18,7 +18,7 @@ import * as fs from "node:fs";
|
|
|
18
18
|
import * as os from "node:os";
|
|
19
19
|
import * as path from "node:path";
|
|
20
20
|
import { CLI_VERSION } from "../cli-version.js";
|
|
21
|
-
import {
|
|
21
|
+
import { denyMcpServe, hasPersonTokenCache } from "./mcp-serve-gate.js";
|
|
22
22
|
import { createLineSplitter, HqdClientError, hqdRequest, hqdSocketPath } from "../lib/daemon/protocol.js";
|
|
23
23
|
import { releaseCurrentPackageUseLease, releasePackageUseLeaseAfterResidentPreload } from "../utils/package-use-lease.js";
|
|
24
24
|
import { preloadResidentPackageModules, reportResidentPackagePreloadFailure, RESIDENT_PACKAGE_MODULES } from "../utils/resident-package-preload.js";
|
|
@@ -27,11 +27,6 @@ const UNREACHABLE_CODES = new Set(["ENOENT", "ECONNREFUSED", "ECONNRESET", "EPIP
|
|
|
27
27
|
/** hqd is not running, so the request never reached it and a local answer cannot repeat a write. */
|
|
28
28
|
const NOT_RUNNING_CODES = new Set(["ENOENT", "ECONNREFUSED"]);
|
|
29
29
|
const LOCAL_GATE_TTL_MS = 60_000;
|
|
30
|
-
function hasPersonTokenCache(env, home) {
|
|
31
|
-
// Mirrors personTokenCacheFile() in utils/cognito-session.ts; duplicated so this path does not load that module.
|
|
32
|
-
const stateDir = env.HQ_STATE_DIR?.trim() || path.join(home, ".hq");
|
|
33
|
-
return fs.existsSync(path.join(stateDir, "cognito-tokens.json"));
|
|
34
|
-
}
|
|
35
30
|
/** HQ root for prompts: HQ_ROOT, else the ~/.hq/root pointer written by `hq install --global`. */
|
|
36
31
|
export function readHqRoot(env, home) {
|
|
37
32
|
const fromEnv = env.HQ_ROOT?.trim();
|
|
@@ -76,8 +71,7 @@ export async function runMcpServe(opts = {}) {
|
|
|
76
71
|
});
|
|
77
72
|
});
|
|
78
73
|
if (!(await runtimeAllowed())) {
|
|
79
|
-
|
|
80
|
-
process.exitCode = 1;
|
|
74
|
+
denyMcpServe();
|
|
81
75
|
return;
|
|
82
76
|
}
|
|
83
77
|
let packageHandlers;
|