@indigoai-us/hq-cli 5.49.0 → 5.50.1
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/dist/commands/mcp-registration.d.ts +905 -0
- package/dist/commands/mcp-registration.js +2001 -0
- package/dist/commands/mcp-status.d.ts +130 -0
- package/dist/commands/mcp-status.js +406 -0
- package/dist/commands/pack-install.d.ts +62 -0
- package/dist/commands/pack-install.js +422 -14
- package/dist/commands/packs.js +28 -4
- package/dist/commands/pkg-install.js +5 -2
- package/dist/index.js +20 -3
- package/dist/types.d.ts +8 -1
- package/dist/utils/contribution-table.d.ts +103 -0
- package/dist/utils/contribution-table.js +65 -0
- package/dist/utils/environmental-error.d.ts +10 -0
- package/dist/utils/environmental-error.js +40 -0
- package/dist/utils/pack-contributions.d.ts +86 -10
- package/dist/utils/pack-contributions.js +130 -48
- package/dist/utils/secrets-cache.d.ts +9 -0
- package/dist/utils/secrets-cache.js +24 -2
- package/package.json +3 -2
- package/scripts/generate-scan-packages-table.mjs +113 -0
- package/src/commands/mcp-registration.test.ts +2787 -0
- package/src/commands/mcp-registration.ts +2612 -0
- package/src/commands/mcp-status.test.ts +483 -0
- package/src/commands/mcp-status.ts +575 -0
- package/src/commands/mcp-status.us011.test.ts +243 -0
- package/src/commands/pack-install.test.ts +589 -0
- package/src/commands/pack-install.ts +497 -13
- package/src/commands/packs.ts +26 -1
- package/src/commands/pkg-install.ts +4 -1
- package/src/index.ts +18 -1
- package/src/types.ts +9 -8
- package/src/utils/contribution-table.ts +83 -0
- package/src/utils/environmental-error.test.ts +45 -0
- package/src/utils/environmental-error.ts +39 -0
- package/src/utils/pack-contributions.test.ts +257 -25
- package/src/utils/pack-contributions.ts +177 -47
- package/src/utils/secrets-cache.ts +22 -0
- package/test/e2e/smoke-install-mcp.sh +113 -0
- package/test/fixtures/hq-pack-smoke-mcp/mcp/smoke-http.json +1 -0
- package/test/fixtures/hq-pack-smoke-mcp/package.yaml +11 -0
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { type SafeWriteEnv } from './mcp-registration.js';
|
|
3
|
+
/** A server's presence on ONE runtime surface. */
|
|
4
|
+
export type PresenceState =
|
|
5
|
+
/** The server def is present (and parsed) on this runtime. */
|
|
6
|
+
'present'
|
|
7
|
+
/** The runtime parsed fine but this server is not registered there. */
|
|
8
|
+
| 'absent'
|
|
9
|
+
/** The runtime's config is malformed (unparseable) — presence is unknowable. */
|
|
10
|
+
| 'unparseable'
|
|
11
|
+
/** The runtime is not installed (Codex only: `~/.codex` missing). */
|
|
12
|
+
| 'not-installed';
|
|
13
|
+
/** Per-runtime, per-server status. */
|
|
14
|
+
export interface RuntimeServerStatus {
|
|
15
|
+
/** present / absent / unparseable / not-installed. */
|
|
16
|
+
presence: PresenceState;
|
|
17
|
+
/** The transport read off this runtime's def (undefined when absent). */
|
|
18
|
+
transport?: string;
|
|
19
|
+
/** The target (url or command+args) read off this runtime's def (undefined when absent). */
|
|
20
|
+
target?: string;
|
|
21
|
+
/** Header KEYS present on this runtime's def (values are NEVER captured). */
|
|
22
|
+
headerKeys?: string[];
|
|
23
|
+
/** Env KEYS present on this runtime's def (values are NEVER captured). */
|
|
24
|
+
envKeys?: string[];
|
|
25
|
+
}
|
|
26
|
+
/** A single HQ-owned MCP server's cross-runtime status. */
|
|
27
|
+
export interface McpServerStatus {
|
|
28
|
+
/** The bare server name (the `mcpServers` / `mcp_servers` key). */
|
|
29
|
+
server: string;
|
|
30
|
+
/** The pack that owns it (`_hqPack` provenance). */
|
|
31
|
+
pack: string;
|
|
32
|
+
/** The transport (from whichever runtime has the def; '' when neither). */
|
|
33
|
+
transport: string;
|
|
34
|
+
/** The target — url (http/sse) or command+args (stdio); '' when unknown. NEVER a secret. */
|
|
35
|
+
target: string;
|
|
36
|
+
/** Claude-runtime status. */
|
|
37
|
+
claude: RuntimeServerStatus;
|
|
38
|
+
/** Codex-runtime status. */
|
|
39
|
+
codex: RuntimeServerStatus;
|
|
40
|
+
/**
|
|
41
|
+
* True iff the server is present on EXACTLY ONE of the two runtimes (a partial
|
|
42
|
+
* registration). When Codex is not installed and the server is Claude-only, this
|
|
43
|
+
* is still PARTIAL — `partialReason` names the missing runtime.
|
|
44
|
+
*/
|
|
45
|
+
partial: boolean;
|
|
46
|
+
/** Human-readable reason naming the missing runtime when `partial`. */
|
|
47
|
+
partialReason?: string;
|
|
48
|
+
/**
|
|
49
|
+
* True iff the server is present on BOTH runtimes but the transport-relevant
|
|
50
|
+
* content differs (transport, target, or header/env KEY sets). Header VALUES are
|
|
51
|
+
* never compared.
|
|
52
|
+
*/
|
|
53
|
+
drifted: boolean;
|
|
54
|
+
}
|
|
55
|
+
/** A runtime's top-level status. */
|
|
56
|
+
export interface RuntimeStatus {
|
|
57
|
+
/** Whether the runtime is installed (Claude is always; Codex iff `~/.codex` exists). */
|
|
58
|
+
installed: boolean;
|
|
59
|
+
/** Whether the runtime's config parsed (false => unparseable). */
|
|
60
|
+
parses: boolean;
|
|
61
|
+
/** The config file path inspected. */
|
|
62
|
+
configPath: string;
|
|
63
|
+
}
|
|
64
|
+
/** The structured `hq mcp status` report. */
|
|
65
|
+
export interface McpStatusReport {
|
|
66
|
+
/** Every HQ-owned server, keyed by name, with cross-runtime status. */
|
|
67
|
+
servers: McpServerStatus[];
|
|
68
|
+
/** Per-runtime top-level status. */
|
|
69
|
+
runtimes: {
|
|
70
|
+
claude: RuntimeStatus;
|
|
71
|
+
codex: RuntimeStatus;
|
|
72
|
+
};
|
|
73
|
+
/** The backup root + the most-recent backup directory names (restore targets). */
|
|
74
|
+
backups: {
|
|
75
|
+
/** `~/.hq/backups/mcp` — where US-006 writes pre-write snapshots. */
|
|
76
|
+
root: string;
|
|
77
|
+
/** The most-recent backup dir NAMES (`<iso>-<pack>`), newest first (capped). */
|
|
78
|
+
recent: string[];
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Compute the cross-runtime MCP status report. PURE (modulo filesystem reads):
|
|
83
|
+
* reads `~/.claude.json` + `~/.codex/config.toml` (Codex only when installed),
|
|
84
|
+
* enumerates HQ-owned servers (those with a non-empty `_hqPack`), and annotates
|
|
85
|
+
* each with per-runtime presence, PARTIAL (present in exactly one runtime, missing
|
|
86
|
+
* runtime named), and DRIFT (present in both but transport/target/header-keys
|
|
87
|
+
* differ). A malformed config marks that runtime `parses:false`/`unparseable`
|
|
88
|
+
* rather than throwing. Header VALUES are never read into the report.
|
|
89
|
+
*/
|
|
90
|
+
export declare function computeMcpStatus(env: SafeWriteEnv): McpStatusReport;
|
|
91
|
+
/**
|
|
92
|
+
* Render the report as human-readable text. Per server: name, pack, transport,
|
|
93
|
+
* target, and a per-runtime line. PARTIAL servers are marked loudly with the
|
|
94
|
+
* missing runtime NAMED; DRIFT is flagged. Header/env VALUES are rendered as
|
|
95
|
+
* {@link SECRET_REDACTION} — never the value. Ends with the backup restore hint.
|
|
96
|
+
*/
|
|
97
|
+
export declare function renderMcpStatus(report: McpStatusReport): string;
|
|
98
|
+
/** The structured capability advertisement for this hq-cli. */
|
|
99
|
+
export interface McpCapabilities {
|
|
100
|
+
/** This hq-cli supports MCP pack registration. */
|
|
101
|
+
supportsMcp: boolean;
|
|
102
|
+
/** The pack contribution types this CLI can register (currently just `mcp`). */
|
|
103
|
+
contributes: string[];
|
|
104
|
+
/** The agent runtimes MCP servers are registered into. */
|
|
105
|
+
runtimes: string[];
|
|
106
|
+
/** The MCP transports this CLI can emit. */
|
|
107
|
+
transports: string[];
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Compute this hq-cli's MCP capability advertisement. PURE — no IO, no env: the
|
|
111
|
+
* answer is a property of the CLI build itself (it supports `contributes.mcp`
|
|
112
|
+
* dual-runtime registration), so it returns a static structured object. Kept as a
|
|
113
|
+
* helper (not inlined into the action) so tests / CI can assert the advert shape
|
|
114
|
+
* without commander, mirroring {@link computeMcpStatus}.
|
|
115
|
+
*/
|
|
116
|
+
export declare function computeMcpCapabilities(): McpCapabilities;
|
|
117
|
+
/** Render the capability advert as human-readable text. */
|
|
118
|
+
export declare function renderMcpCapabilities(caps: McpCapabilities): string;
|
|
119
|
+
/**
|
|
120
|
+
* Wire the `hq mcp` command group with a read-only `status` subcommand and a
|
|
121
|
+
* `capabilities` advertisement subcommand (US-012). `status` resolves the
|
|
122
|
+
* production env (real home), computes the report, and prints either
|
|
123
|
+
* `JSON.stringify(report, null, 2)` (`--json`, for CI / US-013) or the
|
|
124
|
+
* human-readable {@link renderMcpStatus} text. `capabilities` advertises that this
|
|
125
|
+
* hq-cli supports `contributes.mcp` ({@link computeMcpCapabilities} /
|
|
126
|
+
* {@link renderMcpCapabilities}). Follows the commander pattern used by
|
|
127
|
+
* {@link registerReindexCommand} and the subcommand-group pattern in index.ts.
|
|
128
|
+
*/
|
|
129
|
+
export declare function registerMcpCommand(program: Command): void;
|
|
130
|
+
//# sourceMappingURL=mcp-status.d.ts.map
|
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* hq mcp status — read-only observability over installed MCP packs across BOTH
|
|
3
|
+
* runtimes (Claude + Codex). US-011.
|
|
4
|
+
*
|
|
5
|
+
* This closes the US-009 gap: the old symlink-only `linkStatus` structurally
|
|
6
|
+
* cannot see a JSON/TOML *merge* (an MCP server is MERGED into the shared agent
|
|
7
|
+
* configs, never symlinked). So status reads the PROVENANCE marker `_hqPack`
|
|
8
|
+
* directly off the server defs in `~/.claude.json` + `~/.codex/config.toml`,
|
|
9
|
+
* enumerates every HQ-owned server, and reports — PER runtime — present? parses?
|
|
10
|
+
* matches-or-drifted? It surfaces PARTIAL explicitly (registered in one runtime
|
|
11
|
+
* but not the other, naming the missing runtime) and lists the most-recent
|
|
12
|
+
* backups so a corrupted config has a discoverable restore target.
|
|
13
|
+
*
|
|
14
|
+
* SECRET SAFETY (hard rule): header/env VALUES are NEVER rendered in the clear.
|
|
15
|
+
* Status reads configs that hold RESOLVED secrets (the runtime needs real
|
|
16
|
+
* headers), and we do NOT have the raw secret-set at status time — so we redact
|
|
17
|
+
* by KEY presence: header/env KEYS are shown, every value is rendered as
|
|
18
|
+
* {@link SECRET_REDACTION}, and no value is ever compared in the clear.
|
|
19
|
+
*
|
|
20
|
+
* The pure {@link computeMcpStatus} + {@link renderMcpStatus} functions are
|
|
21
|
+
* exported so tests (and CI / US-013) can drive them WITHOUT going through
|
|
22
|
+
* commander; {@link registerMcpCommand} wires the `hq mcp status` command group.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="518fe2be-89c1-53a6-b2fd-263fccc128ba")}catch(e){}}();
|
|
26
|
+
import * as fs from 'fs';
|
|
27
|
+
import { HQ_PACK_PROVENANCE_KEY, SECRET_REDACTION, backupRoot, claudeConfigFormat, claudeConfigPath, codexConfigFormat, codexConfigPath, CODEX_MCP_SERVERS_KEY, ConfigParseError, isCodexInstalled, readConfigDoc, resolveEnv, } from './mcp-registration.js';
|
|
28
|
+
// ---------------------------------------------------------------------------
|
|
29
|
+
// Pure status computation.
|
|
30
|
+
// ---------------------------------------------------------------------------
|
|
31
|
+
/** How many recent backup dirs to surface. */
|
|
32
|
+
const MAX_RECENT_BACKUPS = 5;
|
|
33
|
+
/** Read provenance (`_hqPack`) off a def; non-empty string => HQ-owned. */
|
|
34
|
+
function provenanceOf(def) {
|
|
35
|
+
if (def === null || typeof def !== 'object' || Array.isArray(def))
|
|
36
|
+
return undefined;
|
|
37
|
+
const stamp = def[HQ_PACK_PROVENANCE_KEY];
|
|
38
|
+
return typeof stamp === 'string' && stamp.length > 0 ? stamp : undefined;
|
|
39
|
+
}
|
|
40
|
+
/** The transport string off a def (`type`), or '' when not a string. */
|
|
41
|
+
function transportOf(def) {
|
|
42
|
+
return typeof def.type === 'string' ? def.type : '';
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The target off a def — url (http/sse) or command(+args) (stdio). NEVER a
|
|
46
|
+
* header/secret. '' when neither a url nor a command is present.
|
|
47
|
+
*/
|
|
48
|
+
function targetOf(def) {
|
|
49
|
+
const type = transportOf(def);
|
|
50
|
+
if ((type === 'http' || type === 'sse') && typeof def.url === 'string')
|
|
51
|
+
return def.url;
|
|
52
|
+
if (typeof def.command === 'string') {
|
|
53
|
+
const args = Array.isArray(def.args) && def.args.length > 0 ? ` ${def.args.join(' ')}` : '';
|
|
54
|
+
return `${def.command}${args}`;
|
|
55
|
+
}
|
|
56
|
+
if (typeof def.url === 'string')
|
|
57
|
+
return def.url;
|
|
58
|
+
return '';
|
|
59
|
+
}
|
|
60
|
+
/** Header KEYS off a def (values NEVER captured). */
|
|
61
|
+
function headerKeysOf(def) {
|
|
62
|
+
const h = def.headers;
|
|
63
|
+
if (!h || typeof h !== 'object' || Array.isArray(h))
|
|
64
|
+
return [];
|
|
65
|
+
return Object.keys(h).sort();
|
|
66
|
+
}
|
|
67
|
+
/** Env KEYS off a def (values NEVER captured). */
|
|
68
|
+
function envKeysOf(def) {
|
|
69
|
+
const e = def.env;
|
|
70
|
+
if (!e || typeof e !== 'object' || Array.isArray(e))
|
|
71
|
+
return [];
|
|
72
|
+
return Object.keys(e).sort();
|
|
73
|
+
}
|
|
74
|
+
/** Summarize a def into its transport-relevant, value-FREE content (for drift). */
|
|
75
|
+
function summarizeDef(def) {
|
|
76
|
+
return {
|
|
77
|
+
transport: transportOf(def),
|
|
78
|
+
target: targetOf(def),
|
|
79
|
+
headerKeys: headerKeysOf(def),
|
|
80
|
+
envKeys: envKeysOf(def),
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/** True iff two def summaries differ in any transport-relevant field (header VALUES never compared). */
|
|
84
|
+
function summariesDiffer(a, b) {
|
|
85
|
+
return JSON.stringify(a) !== JSON.stringify(b);
|
|
86
|
+
}
|
|
87
|
+
/** Scan the Claude runtime: read `~/.claude.json`, collect HQ-owned servers. */
|
|
88
|
+
function scanClaude(env) {
|
|
89
|
+
const configPath = claudeConfigPath(env);
|
|
90
|
+
const hqServers = new Map();
|
|
91
|
+
let parses = true;
|
|
92
|
+
try {
|
|
93
|
+
const { doc } = readConfigDoc(configPath, claudeConfigFormat);
|
|
94
|
+
const servers = doc.mcpServers;
|
|
95
|
+
if (servers && typeof servers === 'object' && !Array.isArray(servers)) {
|
|
96
|
+
for (const [name, def] of Object.entries(servers)) {
|
|
97
|
+
const pack = provenanceOf(def);
|
|
98
|
+
if (pack !== undefined) {
|
|
99
|
+
hqServers.set(name, { def: def, pack });
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
catch (e) {
|
|
105
|
+
if (e instanceof ConfigParseError) {
|
|
106
|
+
parses = false; // malformed — report unparseable, do NOT crash the command.
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
throw e; // ConfigPermissionError or anything unexpected — surface it.
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return { installed: true, parses, configPath, hqServers };
|
|
113
|
+
}
|
|
114
|
+
/** Scan the Codex runtime: only when installed; read `~/.codex/config.toml`. */
|
|
115
|
+
function scanCodex(env) {
|
|
116
|
+
const configPath = codexConfigPath(env);
|
|
117
|
+
const hqServers = new Map();
|
|
118
|
+
if (!isCodexInstalled(env)) {
|
|
119
|
+
return { installed: false, parses: true, configPath, hqServers };
|
|
120
|
+
}
|
|
121
|
+
let parses = true;
|
|
122
|
+
try {
|
|
123
|
+
const { doc } = readConfigDoc(configPath, codexConfigFormat);
|
|
124
|
+
const servers = doc.value[CODEX_MCP_SERVERS_KEY];
|
|
125
|
+
if (servers && typeof servers === 'object' && !Array.isArray(servers)) {
|
|
126
|
+
for (const [name, def] of Object.entries(servers)) {
|
|
127
|
+
const pack = provenanceOf(def);
|
|
128
|
+
if (pack !== undefined) {
|
|
129
|
+
hqServers.set(name, { def: def, pack });
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
catch (e) {
|
|
135
|
+
if (e instanceof ConfigParseError) {
|
|
136
|
+
parses = false;
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
throw e;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return { installed: true, parses, configPath, hqServers };
|
|
143
|
+
}
|
|
144
|
+
/** Build the per-runtime, per-server status from a scan (or its absence). */
|
|
145
|
+
function runtimeServerStatus(scan, name) {
|
|
146
|
+
if (!scan.installed)
|
|
147
|
+
return { presence: 'not-installed' };
|
|
148
|
+
if (!scan.parses)
|
|
149
|
+
return { presence: 'unparseable' };
|
|
150
|
+
const found = scan.hqServers.get(name);
|
|
151
|
+
if (!found)
|
|
152
|
+
return { presence: 'absent' };
|
|
153
|
+
return {
|
|
154
|
+
presence: 'present',
|
|
155
|
+
transport: transportOf(found.def),
|
|
156
|
+
target: targetOf(found.def),
|
|
157
|
+
headerKeys: headerKeysOf(found.def),
|
|
158
|
+
envKeys: envKeysOf(found.def),
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
/** List the most-recent backup dir names under `backupRoot` (newest first, capped). */
|
|
162
|
+
function recentBackups(env) {
|
|
163
|
+
const root = backupRoot(env);
|
|
164
|
+
let entries;
|
|
165
|
+
try {
|
|
166
|
+
entries = fs.readdirSync(root, { withFileTypes: true });
|
|
167
|
+
}
|
|
168
|
+
catch {
|
|
169
|
+
// ENOENT (no backups yet) or unreadable — surface an empty list.
|
|
170
|
+
return [];
|
|
171
|
+
}
|
|
172
|
+
return entries
|
|
173
|
+
.filter((e) => e.isDirectory())
|
|
174
|
+
.map((e) => e.name)
|
|
175
|
+
// Names are `<iso>-<pack>` with a sortable UTC stamp prefix — desc = newest first.
|
|
176
|
+
.sort((a, b) => (a < b ? 1 : a > b ? -1 : 0))
|
|
177
|
+
.slice(0, MAX_RECENT_BACKUPS);
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Compute the cross-runtime MCP status report. PURE (modulo filesystem reads):
|
|
181
|
+
* reads `~/.claude.json` + `~/.codex/config.toml` (Codex only when installed),
|
|
182
|
+
* enumerates HQ-owned servers (those with a non-empty `_hqPack`), and annotates
|
|
183
|
+
* each with per-runtime presence, PARTIAL (present in exactly one runtime, missing
|
|
184
|
+
* runtime named), and DRIFT (present in both but transport/target/header-keys
|
|
185
|
+
* differ). A malformed config marks that runtime `parses:false`/`unparseable`
|
|
186
|
+
* rather than throwing. Header VALUES are never read into the report.
|
|
187
|
+
*/
|
|
188
|
+
export function computeMcpStatus(env) {
|
|
189
|
+
const claudeScan = scanClaude(env);
|
|
190
|
+
const codexScan = scanCodex(env);
|
|
191
|
+
// Union of every HQ-owned server name across both runtimes.
|
|
192
|
+
const names = new Set([...claudeScan.hqServers.keys(), ...codexScan.hqServers.keys()]);
|
|
193
|
+
const servers = [];
|
|
194
|
+
for (const name of [...names].sort()) {
|
|
195
|
+
const claude = runtimeServerStatus(claudeScan, name);
|
|
196
|
+
const codex = runtimeServerStatus(codexScan, name);
|
|
197
|
+
// Prefer whichever runtime has the def for the top-level transport/target.
|
|
198
|
+
const claudeFound = claudeScan.hqServers.get(name);
|
|
199
|
+
const codexFound = codexScan.hqServers.get(name);
|
|
200
|
+
const repDef = claudeFound?.def ?? codexFound?.def;
|
|
201
|
+
const pack = claudeFound?.pack ?? codexFound?.pack ?? '';
|
|
202
|
+
const transport = repDef ? transportOf(repDef) : '';
|
|
203
|
+
const target = repDef ? targetOf(repDef) : '';
|
|
204
|
+
const onClaude = claude.presence === 'present';
|
|
205
|
+
const onCodex = codex.presence === 'present';
|
|
206
|
+
// PARTIAL = present in exactly one runtime. Name the missing runtime.
|
|
207
|
+
let partial = false;
|
|
208
|
+
let partialReason;
|
|
209
|
+
if (onClaude && !onCodex) {
|
|
210
|
+
partial = true;
|
|
211
|
+
partialReason = codexScan.installed
|
|
212
|
+
? 'registered in Claude but NOT in Codex'
|
|
213
|
+
: 'registered in Claude; Codex runtime not installed (server not registered in Codex)';
|
|
214
|
+
}
|
|
215
|
+
else if (onCodex && !onClaude) {
|
|
216
|
+
partial = true;
|
|
217
|
+
partialReason = 'registered in Codex but NOT in Claude';
|
|
218
|
+
}
|
|
219
|
+
// DRIFT = present in both but transport-relevant content differs (no header VALUES).
|
|
220
|
+
let drifted = false;
|
|
221
|
+
if (onClaude && onCodex && claudeFound && codexFound) {
|
|
222
|
+
drifted = summariesDiffer(summarizeDef(claudeFound.def), summarizeDef(codexFound.def));
|
|
223
|
+
}
|
|
224
|
+
servers.push({
|
|
225
|
+
server: name,
|
|
226
|
+
pack,
|
|
227
|
+
transport,
|
|
228
|
+
target,
|
|
229
|
+
claude,
|
|
230
|
+
codex,
|
|
231
|
+
partial,
|
|
232
|
+
partialReason,
|
|
233
|
+
drifted,
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
return {
|
|
237
|
+
servers,
|
|
238
|
+
runtimes: {
|
|
239
|
+
claude: {
|
|
240
|
+
installed: claudeScan.installed,
|
|
241
|
+
parses: claudeScan.parses,
|
|
242
|
+
configPath: claudeScan.configPath,
|
|
243
|
+
},
|
|
244
|
+
codex: {
|
|
245
|
+
installed: codexScan.installed,
|
|
246
|
+
parses: codexScan.parses,
|
|
247
|
+
configPath: codexScan.configPath,
|
|
248
|
+
},
|
|
249
|
+
},
|
|
250
|
+
backups: {
|
|
251
|
+
root: backupRoot(env),
|
|
252
|
+
recent: recentBackups(env),
|
|
253
|
+
},
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
// ---------------------------------------------------------------------------
|
|
257
|
+
// Human-readable rendering.
|
|
258
|
+
// ---------------------------------------------------------------------------
|
|
259
|
+
/** Render one runtime's per-server line. Header/env VALUES are NEVER printed. */
|
|
260
|
+
function renderRuntimeLine(label, st) {
|
|
261
|
+
switch (st.presence) {
|
|
262
|
+
case 'present': {
|
|
263
|
+
const parts = [`present`];
|
|
264
|
+
if (st.headerKeys && st.headerKeys.length > 0) {
|
|
265
|
+
parts.push(`headers: ${st.headerKeys.map((k) => `${k}=${SECRET_REDACTION}`).join(', ')}`);
|
|
266
|
+
}
|
|
267
|
+
if (st.envKeys && st.envKeys.length > 0) {
|
|
268
|
+
parts.push(`env: ${st.envKeys.map((k) => `${k}=${SECRET_REDACTION}`).join(', ')}`);
|
|
269
|
+
}
|
|
270
|
+
return ` ${label}: ${parts.join(' | ')}`;
|
|
271
|
+
}
|
|
272
|
+
case 'absent':
|
|
273
|
+
return ` ${label}: absent`;
|
|
274
|
+
case 'unparseable':
|
|
275
|
+
return ` ${label}: UNPARSEABLE (config malformed)`;
|
|
276
|
+
case 'not-installed':
|
|
277
|
+
return ` ${label}: not installed`;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Render the report as human-readable text. Per server: name, pack, transport,
|
|
282
|
+
* target, and a per-runtime line. PARTIAL servers are marked loudly with the
|
|
283
|
+
* missing runtime NAMED; DRIFT is flagged. Header/env VALUES are rendered as
|
|
284
|
+
* {@link SECRET_REDACTION} — never the value. Ends with the backup restore hint.
|
|
285
|
+
*/
|
|
286
|
+
export function renderMcpStatus(report) {
|
|
287
|
+
const lines = [];
|
|
288
|
+
lines.push('HQ MCP status — installed packs across Claude + Codex');
|
|
289
|
+
lines.push('');
|
|
290
|
+
// Runtime header.
|
|
291
|
+
const c = report.runtimes.claude;
|
|
292
|
+
const x = report.runtimes.codex;
|
|
293
|
+
lines.push(`Runtimes: Claude [${c.parses ? 'ok' : 'UNPARSEABLE'}] ` +
|
|
294
|
+
`Codex [${!x.installed ? 'not installed' : x.parses ? 'ok' : 'UNPARSEABLE'}]`);
|
|
295
|
+
lines.push('');
|
|
296
|
+
if (report.servers.length === 0) {
|
|
297
|
+
lines.push('No HQ-owned MCP servers registered (no _hqPack provenance found in either runtime).');
|
|
298
|
+
}
|
|
299
|
+
else {
|
|
300
|
+
for (const s of report.servers) {
|
|
301
|
+
const flags = [];
|
|
302
|
+
if (s.partial)
|
|
303
|
+
flags.push('PARTIAL');
|
|
304
|
+
if (s.drifted)
|
|
305
|
+
flags.push('DRIFTED');
|
|
306
|
+
const flagStr = flags.length > 0 ? ` <<< ${flags.join(' + ')}` : '';
|
|
307
|
+
lines.push(`• ${s.server} (pack: ${s.pack})${flagStr}`);
|
|
308
|
+
lines.push(` transport: ${s.transport || '(unknown)'} target: ${s.target || '(none)'}`);
|
|
309
|
+
lines.push(renderRuntimeLine('Claude', s.claude));
|
|
310
|
+
lines.push(renderRuntimeLine('Codex ', s.codex));
|
|
311
|
+
if (s.partial && s.partialReason) {
|
|
312
|
+
lines.push(` PARTIAL: ${s.partialReason}`);
|
|
313
|
+
}
|
|
314
|
+
if (s.drifted) {
|
|
315
|
+
lines.push(` DRIFTED: Claude and Codex defs differ (transport/target/header-keys)`);
|
|
316
|
+
}
|
|
317
|
+
lines.push('');
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
// Backups (restore targets for a corrupted config).
|
|
321
|
+
lines.push(`Backups: ${report.backups.root}`);
|
|
322
|
+
if (report.backups.recent.length > 0) {
|
|
323
|
+
lines.push(` Most recent:`);
|
|
324
|
+
for (const b of report.backups.recent) {
|
|
325
|
+
lines.push(` - ${b}`);
|
|
326
|
+
}
|
|
327
|
+
lines.push(` To restore a corrupted config, copy the snapshot from the newest dir above back into place.`);
|
|
328
|
+
}
|
|
329
|
+
else {
|
|
330
|
+
lines.push(` (no backups yet)`);
|
|
331
|
+
}
|
|
332
|
+
return lines.join('\n');
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Compute this hq-cli's MCP capability advertisement. PURE — no IO, no env: the
|
|
336
|
+
* answer is a property of the CLI build itself (it supports `contributes.mcp`
|
|
337
|
+
* dual-runtime registration), so it returns a static structured object. Kept as a
|
|
338
|
+
* helper (not inlined into the action) so tests / CI can assert the advert shape
|
|
339
|
+
* without commander, mirroring {@link computeMcpStatus}.
|
|
340
|
+
*/
|
|
341
|
+
export function computeMcpCapabilities() {
|
|
342
|
+
return {
|
|
343
|
+
supportsMcp: true,
|
|
344
|
+
contributes: ['mcp'],
|
|
345
|
+
runtimes: ['claude', 'codex'],
|
|
346
|
+
transports: ['http', 'stdio', 'sse'],
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
/** Render the capability advert as human-readable text. */
|
|
350
|
+
export function renderMcpCapabilities(caps) {
|
|
351
|
+
const lines = [];
|
|
352
|
+
lines.push('HQ MCP capabilities — what this hq-cli supports');
|
|
353
|
+
lines.push('');
|
|
354
|
+
lines.push(` supports MCP: ${caps.supportsMcp ? 'yes' : 'no'}`);
|
|
355
|
+
lines.push(` contributes: ${caps.contributes.join(', ')}`);
|
|
356
|
+
lines.push(` runtimes: ${caps.runtimes.join(', ')}`);
|
|
357
|
+
lines.push(` transports: ${caps.transports.join(', ')}`);
|
|
358
|
+
return lines.join('\n');
|
|
359
|
+
}
|
|
360
|
+
// ---------------------------------------------------------------------------
|
|
361
|
+
// Command wiring.
|
|
362
|
+
// ---------------------------------------------------------------------------
|
|
363
|
+
/**
|
|
364
|
+
* Wire the `hq mcp` command group with a read-only `status` subcommand and a
|
|
365
|
+
* `capabilities` advertisement subcommand (US-012). `status` resolves the
|
|
366
|
+
* production env (real home), computes the report, and prints either
|
|
367
|
+
* `JSON.stringify(report, null, 2)` (`--json`, for CI / US-013) or the
|
|
368
|
+
* human-readable {@link renderMcpStatus} text. `capabilities` advertises that this
|
|
369
|
+
* hq-cli supports `contributes.mcp` ({@link computeMcpCapabilities} /
|
|
370
|
+
* {@link renderMcpCapabilities}). Follows the commander pattern used by
|
|
371
|
+
* {@link registerReindexCommand} and the subcommand-group pattern in index.ts.
|
|
372
|
+
*/
|
|
373
|
+
export function registerMcpCommand(program) {
|
|
374
|
+
const mcp = program
|
|
375
|
+
.command('mcp')
|
|
376
|
+
.description('MCP pack observability (read-only) across Claude + Codex');
|
|
377
|
+
mcp
|
|
378
|
+
.command('status')
|
|
379
|
+
.description('Show installed MCP packs/servers and their health in BOTH Claude and Codex (PARTIAL/DRIFT flagged; secrets redacted)')
|
|
380
|
+
.option('--json', 'Emit the structured report as JSON (for CI / scripting)')
|
|
381
|
+
.action((opts) => {
|
|
382
|
+
const env = resolveEnv();
|
|
383
|
+
const report = computeMcpStatus(env);
|
|
384
|
+
if (opts.json) {
|
|
385
|
+
process.stdout.write(`${JSON.stringify(report, null, 2)}\n`);
|
|
386
|
+
}
|
|
387
|
+
else {
|
|
388
|
+
process.stdout.write(`${renderMcpStatus(report)}\n`);
|
|
389
|
+
}
|
|
390
|
+
});
|
|
391
|
+
mcp
|
|
392
|
+
.command('capabilities')
|
|
393
|
+
.description('Advertise that this hq-cli supports contributes.mcp (dual-runtime Claude+Codex registration)')
|
|
394
|
+
.option('--json', 'Emit the structured capability object as JSON (for CI / scripting)')
|
|
395
|
+
.action((opts) => {
|
|
396
|
+
const caps = computeMcpCapabilities();
|
|
397
|
+
if (opts.json) {
|
|
398
|
+
process.stdout.write(`${JSON.stringify(caps, null, 2)}\n`);
|
|
399
|
+
}
|
|
400
|
+
else {
|
|
401
|
+
process.stdout.write(`${renderMcpCapabilities(caps)}\n`);
|
|
402
|
+
}
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
//# sourceMappingURL=mcp-status.js.map
|
|
406
|
+
//# debugId=518fe2be-89c1-53a6-b2fd-263fccc128ba
|
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
* from each pack's package.yaml; rationale lives in the layout-fix PR.)
|
|
35
35
|
*/
|
|
36
36
|
import { type KeyObject } from 'node:crypto';
|
|
37
|
+
import { type SecretResolver } from './mcp-registration.js';
|
|
37
38
|
import type { PackManifest } from '../types.js';
|
|
38
39
|
export type Transport = 'npm' | 'git' | 'local' | 'marketplace';
|
|
39
40
|
/** Prefix that routes a source through the HQ marketplace transport (US-006). */
|
|
@@ -237,6 +238,26 @@ export declare function computeArtifactHash(tarballBytes: Uint8Array): string;
|
|
|
237
238
|
* full strings rather than prefixes.
|
|
238
239
|
*/
|
|
239
240
|
export declare function verifyArtifact(input: VerifyArtifactInput): void;
|
|
241
|
+
/**
|
|
242
|
+
* Parse + shape-validate one pack's per-server MCP manifest (`mcp/{item}.json`),
|
|
243
|
+
* mirroring the bash `validate_mcp_manifest` arm. EXPORTED so the acceptance
|
|
244
|
+
* test (and US-006's registration engine) can call it directly.
|
|
245
|
+
*
|
|
246
|
+
* Throws an `Error` (whose message names the pack-relative payload path, e.g.
|
|
247
|
+
* `mcp/foo.json`) when the file does not parse as JSON or violates a transport
|
|
248
|
+
* rule:
|
|
249
|
+
* - `type` required, one of `http|stdio|sse`;
|
|
250
|
+
* - no unknown top-level keys (allowed: {@link MCP_ALLOWED_KEYS});
|
|
251
|
+
* - http/sse: `url` required + `^https?://`; `command`/`args`/`env` forbidden;
|
|
252
|
+
* - stdio: non-empty `command` required; `url`/`headers` forbidden;
|
|
253
|
+
* - `headers`/`env` (if present) are objects of string values;
|
|
254
|
+
* - NO inline literal `Bearer ` secret — such a value MUST carry a
|
|
255
|
+
* `${secret:NAME}` reference, never a literal token.
|
|
256
|
+
*
|
|
257
|
+
* @param payloadDir the pack payload root (holds `mcp/{item}.json`)
|
|
258
|
+
* @param item the bare server name declared under `contributes.mcp`
|
|
259
|
+
*/
|
|
260
|
+
export declare function validateMcpManifest(payloadDir: string, item: string): void;
|
|
240
261
|
export declare function validateManifest(payloadDir: string, hqVersion: string | null): PackManifest;
|
|
241
262
|
/**
|
|
242
263
|
* Derive the safe, auto-generated "get started" line for a freshly installed
|
|
@@ -252,6 +273,40 @@ export declare function validateManifest(payloadDir: string, hqVersion: string |
|
|
|
252
273
|
* the caller prints nothing extra).
|
|
253
274
|
*/
|
|
254
275
|
export declare function getStartedLine(initialization?: PackManifest['initialization']): string | null;
|
|
276
|
+
/**
|
|
277
|
+
* Render one declared MCP server's prompt line, redacting every header/env value.
|
|
278
|
+
* EXPORTED so the acceptance/redaction self-test can assert no secret/Bearer
|
|
279
|
+
* substring ever appears in the rendered output.
|
|
280
|
+
*/
|
|
281
|
+
export declare function renderMcpServerLine(payloadDir: string, item: string): string;
|
|
282
|
+
/**
|
|
283
|
+
* Install-time MCP trust prompt. EXPORTED so the acceptance test can drive the
|
|
284
|
+
* gate / bypass / non-TTY branches directly (capture stdout, assert no secret
|
|
285
|
+
* substring leaks, assert deny returns false). See {@link confirmHooks} for the
|
|
286
|
+
* voice/shape this mirrors.
|
|
287
|
+
*/
|
|
288
|
+
export declare function confirmMcp(pkg: PackManifest, payloadDir: string, allowMcp: boolean): Promise<boolean>;
|
|
289
|
+
/**
|
|
290
|
+
* Build the install-time {@link SecretResolver} bound to the HQ vault's local
|
|
291
|
+
* secrets-cache (`~/.hq/secrets-cache/<scope>/<NAME>`, AES-256-GCM, 0600, TTL'd).
|
|
292
|
+
*
|
|
293
|
+
* Active-company resolution at install time is INDIRECT by design: `hq install`
|
|
294
|
+
* has no `--company` flag and runs OFFLINE (no token), so we cannot resolve a
|
|
295
|
+
* single active company UID the way `hq run` / `hq secrets` do (via
|
|
296
|
+
* `getEntityUid` over the network). Instead we probe EVERY cached scope
|
|
297
|
+
* (`cmp_*`/`prs_*` — whichever has minted secrets locally) for the requested
|
|
298
|
+
* name and return the first hit. This naturally resolves to whichever company
|
|
299
|
+
* context just provisioned the secret (e.g. the one `/connect-shopify` minted
|
|
300
|
+
* `VYG_API_KEY` under), without guessing, and works whether the vault scoped the
|
|
301
|
+
* key under a company or person entity.
|
|
302
|
+
*
|
|
303
|
+
* On MISS across all scopes (no cache, expired TTL, or key never minted) it
|
|
304
|
+
* returns `null` — which is exactly what {@link registerMcpServers}'s
|
|
305
|
+
* unresolvable-secret path keys off to defer that server gracefully. With no
|
|
306
|
+
* cached scopes at all (`listSecretCacheScopes()` → `[]`) it simply returns
|
|
307
|
+
* `null` for every name, the desired graceful-deferral behavior.
|
|
308
|
+
*/
|
|
309
|
+
export declare function makeInstallSecretResolver(): SecretResolver;
|
|
255
310
|
/**
|
|
256
311
|
* Install the fetched payload to `<hqRoot>/core/packages/<pkg.name>/` (HQ
|
|
257
312
|
* v12+ layout). The HQ template (`hq-core` / `hq-core-staging`) ships
|
|
@@ -308,6 +363,13 @@ export declare function runScanPackages(hqRoot: string, opts?: {
|
|
|
308
363
|
}): void;
|
|
309
364
|
export interface InstallPackOptions {
|
|
310
365
|
allowHooks?: boolean;
|
|
366
|
+
/**
|
|
367
|
+
* US-010 install-time MCP trust prompt bypass (CI/ambient-trust). Mirrors
|
|
368
|
+
* `allowHooks`: when set, `confirmMcp` skips the prompt and prints a yellow
|
|
369
|
+
* notice. Absent/false → the operator is prompted (or, in a non-TTY shell,
|
|
370
|
+
* the install is refused with a "re-run with --allow-mcp" hint).
|
|
371
|
+
*/
|
|
372
|
+
allowMcp?: boolean;
|
|
311
373
|
followBranch?: boolean;
|
|
312
374
|
/**
|
|
313
375
|
* Route this function's human output to stderr (and silence scan-packages
|