@indigoai-us/hq-cli 5.345.212 → 5.345.215-beta.0
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 +49 -0
- package/dist/bin/hq-auth-refresh.js +2 -1
- package/dist/command-catalog.generated.d.ts +442 -50
- package/dist/command-catalog.generated.js +541 -50
- package/dist/commands/agent-inbox.d.ts +11 -1
- package/dist/commands/agent-inbox.js +128 -38
- package/dist/commands/agent-kit.js +2 -2
- package/dist/commands/agents.d.ts +51 -1
- package/dist/commands/agents.js +154 -2
- package/dist/commands/bot-jobs.d.ts +2 -15
- package/dist/commands/bot-jobs.js +2 -94
- package/dist/commands/bot-runtime.d.ts +46 -5
- package/dist/commands/bot-runtime.js +228 -18
- package/dist/commands/bot.d.ts +16 -9
- package/dist/commands/bot.js +169 -51
- package/dist/commands/cloud.d.ts +66 -13
- package/dist/commands/cloud.js +120 -39
- package/dist/commands/company-restore.d.ts +23 -0
- package/dist/commands/company-restore.js +128 -0
- package/dist/commands/company.js +2 -0
- package/dist/commands/core-handoff.js +1 -0
- package/dist/commands/core-hq-session-native.js +2 -2
- package/dist/commands/core-pin-native.js +1 -1
- package/dist/commands/core-policy.js +1 -1
- package/dist/commands/core-resolve-company-native.js +1 -1
- package/dist/commands/core-sentry-report-fast.d.ts +2 -0
- package/dist/commands/core-sentry-report-fast.js +3 -1
- package/dist/commands/daemon.js +11 -1
- package/dist/commands/integrations-connect.d.ts +17 -4
- package/dist/commands/integrations-connect.js +224 -26
- package/dist/commands/lanes-link.js +10 -5
- package/dist/commands/lanes.js +26 -9
- package/dist/commands/rescue.js +13 -0
- package/dist/commands/secrets.d.ts +11 -0
- package/dist/commands/secrets.js +41 -7
- package/dist/commands/sources.js +6 -0
- package/dist/commands/storage-offload.d.ts +12 -0
- package/dist/commands/storage-offload.js +41 -3
- package/dist/commands/sync-mode.js +5 -0
- package/dist/commands/whoami.js +4 -0
- package/dist/index.js +2 -0
- package/dist/lazy-commands.js +2 -0
- package/dist/lib/agent-kit/inbox-fetch.d.ts +122 -1
- package/dist/lib/agent-kit/inbox-fetch.js +215 -3
- package/dist/lib/agent-kit/inbox-redact.js +1 -1
- package/dist/lib/agent-kit/inbox-state.d.ts +98 -1
- package/dist/lib/agent-kit/inbox-state.js +261 -4
- package/dist/lib/agent-kit/mcp/tools.d.ts +3 -3
- package/dist/lib/agent-kit/mcp/tools.js +68 -25
- package/dist/lib/agent-kit/run/inbox.js +4 -2
- package/dist/lib/agent-kit/skills.js +4 -1
- package/dist/lib/agent-kit/wake.d.ts +9 -1
- package/dist/lib/agent-kit/wake.js +10 -3
- package/dist/lib/bot/config.d.ts +1 -0
- package/dist/lib/bot/config.js +10 -0
- package/dist/lib/bot/eventbridge-cron.d.ts +22 -0
- package/dist/lib/bot/eventbridge-cron.js +104 -0
- package/dist/lib/bot/fleet-cron.js +193 -14
- package/dist/lib/bot/fleet-download.d.ts +2 -0
- package/dist/lib/bot/fleet-download.js +23 -0
- package/dist/lib/bot/fleet-local.d.ts +34 -1
- package/dist/lib/bot/fleet-local.js +254 -37
- package/dist/lib/bot/fleet-python.d.ts +3 -0
- package/dist/lib/bot/fleet-python.js +34 -4
- package/dist/lib/bot/fleet-runtime-sources.d.ts +15 -0
- package/dist/lib/bot/fleet-runtime-sources.js +30 -0
- package/dist/lib/bot/legacy-provider-login.d.ts +8 -0
- package/dist/lib/bot/legacy-provider-login.js +19 -2
- package/dist/lib/bot/prompt.js +1 -1
- package/dist/lib/bot/readiness.d.ts +8 -0
- package/dist/lib/bot/readiness.js +17 -3
- package/dist/lib/bot/runtime-auth.d.ts +30 -0
- package/dist/lib/bot/runtime-auth.js +94 -3
- package/dist/lib/bot/status.d.ts +2 -0
- package/dist/lib/capacity/collectors/grok-refresh.d.ts +80 -0
- package/dist/lib/capacity/collectors/grok-refresh.js +189 -0
- package/dist/lib/capacity/collectors/grok.d.ts +5 -0
- package/dist/lib/capacity/collectors/grok.js +56 -5
- package/dist/lib/core-utils/session-id.d.ts +1 -1
- package/dist/lib/core-utils/session-id.js +4 -0
- package/dist/lib/daemon/catalog.js +11 -1
- package/dist/lib/daemon/run.js +9 -1
- package/dist/lib/daemon/updater.d.ts +34 -2
- package/dist/lib/daemon/updater.js +51 -2
- package/dist/lib/db/sqlite-binding.d.ts +1 -0
- package/dist/lib/db/sqlite-binding.js +1 -1
- package/dist/lib/delivery/artifacts.d.ts +99 -0
- package/dist/lib/delivery/artifacts.js +548 -0
- package/dist/lib/delivery/backup.d.ts +78 -0
- package/dist/lib/delivery/backup.js +343 -0
- package/dist/lib/delivery/cache.d.ts +29 -0
- package/dist/lib/delivery/cache.js +33 -0
- package/dist/lib/delivery/contracts.d.ts +142 -0
- package/dist/lib/delivery/contracts.js +289 -0
- package/dist/lib/delivery/credentials.d.ts +54 -0
- package/dist/lib/delivery/credentials.js +119 -0
- package/dist/lib/delivery/enrollment.d.ts +142 -0
- package/dist/lib/delivery/enrollment.js +382 -0
- package/dist/lib/delivery/identity.d.ts +25 -0
- package/dist/lib/delivery/identity.js +82 -0
- package/dist/lib/delivery/inbox.d.ts +116 -0
- package/dist/lib/delivery/inbox.js +260 -0
- package/dist/lib/delivery/migrations.d.ts +139 -0
- package/dist/lib/delivery/migrations.js +623 -0
- package/dist/lib/delivery/mqtt-adapter.d.ts +50 -0
- package/dist/lib/delivery/mqtt-adapter.js +242 -0
- package/dist/lib/delivery/mqtt.d.ts +61 -0
- package/dist/lib/delivery/mqtt.js +112 -0
- package/dist/lib/delivery/outbox.d.ts +95 -0
- package/dist/lib/delivery/outbox.js +187 -0
- package/dist/lib/delivery/provenance.d.ts +129 -0
- package/dist/lib/delivery/provenance.js +93 -0
- package/dist/lib/delivery/reconciler.d.ts +151 -0
- package/dist/lib/delivery/reconciler.js +492 -0
- package/dist/lib/delivery/restore.d.ts +35 -0
- package/dist/lib/delivery/restore.js +134 -0
- package/dist/lib/delivery/store.d.ts +161 -0
- package/dist/lib/delivery/store.js +940 -0
- package/dist/lib/delivery/workers/macos-job-helper.d.ts +103 -0
- package/dist/lib/delivery/workers/macos-job-helper.js +927 -0
- package/dist/lib/delivery/workers/macos.d.ts +176 -0
- package/dist/lib/delivery/workers/macos.js +901 -0
- package/dist/lib/delivery/workers/windows-boundary.d.ts +453 -0
- package/dist/lib/delivery/workers/windows-boundary.js +693 -0
- package/dist/lib/delivery/workers/windows-job-helper.d.ts +35 -0
- package/dist/lib/delivery/workers/windows-job-helper.js +264 -0
- package/dist/lib/delivery/workers/windows.d.ts +241 -0
- package/dist/lib/delivery/workers/windows.js +608 -0
- package/dist/lib/doctor/checks/release-links.d.ts +50 -8
- package/dist/lib/doctor/checks/release-links.js +260 -24
- package/dist/lib/doctor/fix/apply.js +24 -8
- package/dist/lib/doctor/fix/remediation.js +15 -5
- package/dist/lib/install/provider-wrappers.d.ts +2 -0
- package/dist/lib/install/provider-wrappers.js +68 -3
- package/dist/lib/lanes/autopilot-registry.d.ts +14 -0
- package/dist/lib/lanes/autopilot-registry.js +59 -7
- package/dist/lib/lanes/links.d.ts +14 -0
- package/dist/lib/lanes/links.js +320 -25
- package/dist/lib/lanes/outpost-pruner-install.d.ts +10 -0
- package/dist/lib/lanes/outpost-pruner-install.js +4 -3
- package/dist/main.js +3 -1
- package/dist/sentry-init.d.ts +2 -0
- package/dist/sentry-init.js +13 -2
- package/dist/sentry.d.ts +2 -0
- package/dist/sentry.js +5 -1
- package/dist/utils/cli-network-lifecycle.d.ts +9 -0
- package/dist/utils/cli-network-lifecycle.js +52 -0
- package/dist/utils/cognito-callback-port.d.ts +14 -0
- package/dist/utils/cognito-callback-port.js +24 -0
- package/dist/utils/cognito-session.js +3 -3
- package/dist/utils/deleted-company-notice.d.ts +59 -0
- package/dist/utils/deleted-company-notice.js +156 -0
- package/dist/utils/login-browser.d.ts +1 -1
- package/dist/utils/login-browser.js +7 -5
- package/dist/utils/resident-package-preload.js +30 -15
- package/dist/utils/safe-link.d.ts +63 -0
- package/dist/utils/safe-link.js +246 -0
- package/dist/utils/sentry-keepalive-transport.d.ts +28 -0
- package/dist/utils/sentry-keepalive-transport.js +70 -0
- package/dist/utils/vault-api.js +7 -0
- package/package.json +7 -7
|
@@ -235,18 +235,87 @@ export function assertAuthMode(value) {
|
|
|
235
235
|
throw new IntegrationsCliError("--auth must be none, key, or oauth.", { expected: true });
|
|
236
236
|
}
|
|
237
237
|
}
|
|
238
|
-
/**
|
|
238
|
+
/**
|
|
239
|
+
* feedback_950d8abe: hq-pro's save-time rule for a custom key header
|
|
240
|
+
* (src/integration-factory/api-key-characters.ts). Kept identical so the CLI
|
|
241
|
+
* never sends a header name hq-pro refuses with DIRECT_MCP_INVALID_AUTH_SCHEME,
|
|
242
|
+
* and never refuses one hq-pro accepts. Authorization is allowed: a header
|
|
243
|
+
* placement named Authorization is the one way to send a raw key with no
|
|
244
|
+
* prefix.
|
|
245
|
+
*/
|
|
246
|
+
const MAX_AUTH_HEADER_LENGTH = 64;
|
|
247
|
+
const DENIED_AUTH_HEADER_NAMES = new Set([
|
|
248
|
+
// hop-by-hop, framing and request target
|
|
249
|
+
"connection",
|
|
250
|
+
"keep-alive",
|
|
251
|
+
"proxy-connection",
|
|
252
|
+
"te",
|
|
253
|
+
"trailer",
|
|
254
|
+
"transfer-encoding",
|
|
255
|
+
"upgrade",
|
|
256
|
+
"http2-settings",
|
|
257
|
+
"content-length",
|
|
258
|
+
"expect",
|
|
259
|
+
"host",
|
|
260
|
+
"content-encoding",
|
|
261
|
+
// cookies, auth challenges, forwarding and client-IP headers
|
|
262
|
+
"cookie",
|
|
263
|
+
"set-cookie",
|
|
264
|
+
"www-authenticate",
|
|
265
|
+
"proxy-authorization",
|
|
266
|
+
"proxy-authenticate",
|
|
267
|
+
"forwarded",
|
|
268
|
+
"via",
|
|
269
|
+
"x-real-ip",
|
|
270
|
+
"true-client-ip",
|
|
271
|
+
"cf-connecting-ip",
|
|
272
|
+
"x-original-url",
|
|
273
|
+
// set by HQ's MCP client itself
|
|
274
|
+
"accept",
|
|
275
|
+
"accept-encoding",
|
|
276
|
+
"content-type",
|
|
277
|
+
"user-agent",
|
|
278
|
+
"mcp-protocol-version",
|
|
279
|
+
"mcp-session-id",
|
|
280
|
+
"last-event-id",
|
|
281
|
+
]);
|
|
282
|
+
/** Case-insensitive prefixes: any Proxy-* (also listed by name above) and every X-Forwarded-*. */
|
|
283
|
+
const DENIED_AUTH_HEADER_PREFIXES = ["proxy-", "x-forwarded-"];
|
|
284
|
+
/** True when hq-pro refuses to send a key in this (token-valid) header name. */
|
|
285
|
+
export function isDeniedAuthHeader(name) {
|
|
286
|
+
const lower = name.toLowerCase();
|
|
287
|
+
return (DENIED_AUTH_HEADER_NAMES.has(lower) ||
|
|
288
|
+
DENIED_AUTH_HEADER_PREFIXES.some((prefix) => lower.startsWith(prefix)));
|
|
289
|
+
}
|
|
290
|
+
/** RFC 7230 token, at most 64 characters, and not on hq-pro's denylist. */
|
|
239
291
|
export function assertAuthHeader(value) {
|
|
240
|
-
if (value
|
|
292
|
+
if (value === undefined)
|
|
293
|
+
return;
|
|
294
|
+
if (!/^[A-Za-z0-9!#$%&'*+.^_`|~-]+$/.test(value)) {
|
|
241
295
|
throw new IntegrationsCliError("--auth-header must be a non-empty HTTP header name using RFC 7230 token characters.", { expected: true });
|
|
242
296
|
}
|
|
297
|
+
if (isDeniedAuthHeader(value)) {
|
|
298
|
+
throw new IntegrationsCliError(`HQ can't send a key in the ${value} header. Use the header name from the app's docs, such as X-API-Key.`, { expected: true });
|
|
299
|
+
}
|
|
300
|
+
if (value.length > MAX_AUTH_HEADER_LENGTH) {
|
|
301
|
+
throw new IntegrationsCliError(`--auth-header can be up to ${MAX_AUTH_HEADER_LENGTH} characters.`, { expected: true });
|
|
302
|
+
}
|
|
243
303
|
}
|
|
244
304
|
/** Single-quote a value for a copy-pasteable shell command. */
|
|
245
305
|
export function shellQuote(value) {
|
|
246
306
|
return `'${value.replace(/'/g, `'\\''`)}'`;
|
|
247
307
|
}
|
|
248
|
-
/**
|
|
249
|
-
|
|
308
|
+
/**
|
|
309
|
+
* Read a secret from stdin, without echoing or trailing-newline noise.
|
|
310
|
+
*
|
|
311
|
+
* When stdin is a terminal, a bare read waits in silence and looks frozen
|
|
312
|
+
* (feedback_86a49a5c). In that case print a one-line prompt to stderr and read
|
|
313
|
+
* with echo off. Piped stdin keeps the silent read.
|
|
314
|
+
*/
|
|
315
|
+
function readStdin(promptLabel) {
|
|
316
|
+
if (process.stdin.isTTY) {
|
|
317
|
+
return promptForKey(`${promptLabel}, then press Enter (input is hidden)`, process.stderr);
|
|
318
|
+
}
|
|
250
319
|
return new Promise((resolve, reject) => {
|
|
251
320
|
let data = "";
|
|
252
321
|
process.stdin.setEncoding("utf8");
|
|
@@ -263,9 +332,9 @@ function readStdin() {
|
|
|
263
332
|
* reach argv (shell history, `ps` output) unless the caller insists via
|
|
264
333
|
* `--token`.
|
|
265
334
|
*/
|
|
266
|
-
function promptForKey(label) {
|
|
335
|
+
function promptForKey(label, out = process.stdout) {
|
|
267
336
|
return new Promise((resolve, reject) => {
|
|
268
|
-
|
|
337
|
+
out.write(`${label}: `);
|
|
269
338
|
if (process.stdin.isTTY)
|
|
270
339
|
process.stdin.setRawMode(true);
|
|
271
340
|
process.stdin.setEncoding("utf8");
|
|
@@ -281,13 +350,13 @@ function promptForKey(label) {
|
|
|
281
350
|
const codePoint = ch.codePointAt(0);
|
|
282
351
|
if (ch === "\n" || ch === "\r" || codePoint === 4) {
|
|
283
352
|
cleanup();
|
|
284
|
-
|
|
353
|
+
out.write("\n");
|
|
285
354
|
resolve(value);
|
|
286
355
|
return;
|
|
287
356
|
}
|
|
288
357
|
if (codePoint === 3) {
|
|
289
358
|
cleanup();
|
|
290
|
-
|
|
359
|
+
out.write("\n");
|
|
291
360
|
reject(new IntegrationsCliError("Cancelled.", { expected: true }));
|
|
292
361
|
return;
|
|
293
362
|
}
|
|
@@ -312,21 +381,26 @@ function promptForKey(label) {
|
|
|
312
381
|
* HQ-PRO-5QF: a key pasted from a doc or chat often arrives wrapped across
|
|
313
382
|
* lines or with a tab, and sometimes with smart quotes. hq-pro sends the key
|
|
314
383
|
* in an HTTP header, which can't carry those characters. Trim the ends, drop
|
|
315
|
-
* inner line breaks and tabs, and refuse anything else outside visible ASCII
|
|
316
|
-
* (an inner space is left for hq-pro to judge, since HTTP Basic allows it).
|
|
384
|
+
* inner line breaks and tabs, and refuse anything else outside visible ASCII.
|
|
317
385
|
* The message never echoes the key.
|
|
386
|
+
*
|
|
387
|
+
* feedback_950d8abe: this is hq-pro's rule for every key the CLI sends. The
|
|
388
|
+
* CLI sends a key as Bearer or in a custom header (--auth-header), never as an
|
|
389
|
+
* HTTP Basic password, and hq-pro accepts only visible ASCII (0x21-0x7E) for
|
|
390
|
+
* those. An inner space used to pass here and come back from hq-pro as a 400
|
|
391
|
+
* DIRECT_MCP_INVALID_API_KEY_CHARACTERS.
|
|
318
392
|
*/
|
|
319
393
|
export const API_KEY_UNSENDABLE_MESSAGE = "The key contains a character that can't be sent. Copy it again and paste only the key.";
|
|
320
394
|
export function normalizePastedApiKey(raw) {
|
|
321
395
|
const cleaned = raw.trim().replace(/[\r\n\t]+/g, "");
|
|
322
|
-
if (!/^[\
|
|
396
|
+
if (!/^[\x21-\x7e]*$/.test(cleaned)) {
|
|
323
397
|
throw new IntegrationsCliError(API_KEY_UNSENDABLE_MESSAGE, { expected: true });
|
|
324
398
|
}
|
|
325
399
|
return cleaned;
|
|
326
400
|
}
|
|
327
401
|
async function resolveKey(opts, appLabel) {
|
|
328
402
|
if (opts.tokenStdin) {
|
|
329
|
-
const piped = normalizePastedApiKey(await readStdin());
|
|
403
|
+
const piped = normalizePastedApiKey(await readStdin("Paste the API key"));
|
|
330
404
|
if (!piped) {
|
|
331
405
|
throw new IntegrationsCliError("--token-stdin was set but stdin was empty.", {
|
|
332
406
|
expected: true,
|
|
@@ -674,7 +748,7 @@ async function connectViaOAuth(token, companyUid, target, opts) {
|
|
|
674
748
|
throw err;
|
|
675
749
|
if (BRING_YOUR_OWN_CLIENT_CODES.has(err.code)) {
|
|
676
750
|
listener.close();
|
|
677
|
-
return await bringYourOwnClientHandoff(target, opts, err.message, err.redirectUri);
|
|
751
|
+
return await bringYourOwnClientHandoff(target, opts, err.message, err.redirectUri, () => blueprintEndpoint(token, companyUid, target));
|
|
678
752
|
}
|
|
679
753
|
if (!CONSOLE_HANDOFF_CODES.has(err.code))
|
|
680
754
|
throw err;
|
|
@@ -738,12 +812,17 @@ companySlug, origin) {
|
|
|
738
812
|
* A `--mcp-url` or `--docs-url` target has no catalog row to search for over
|
|
739
813
|
* there — `resolveTarget` reduces a docs page to an opaque discovery receipt
|
|
740
814
|
* the console cannot take — so unless the handoff carries the address back,
|
|
741
|
-
* the only copy of it is in the caller's scrollback. A catalog target
|
|
742
|
-
* hint
|
|
815
|
+
* the only copy of it is in the caller's scrollback. A catalog target usually
|
|
816
|
+
* needs no hint, since its label is what they search for over there. A domain
|
|
817
|
+
* the catalog does not list (shopify.com, feedback_3013b98e) finds nothing in
|
|
818
|
+
* that search, so when the endpoint was resolved it is printed too.
|
|
743
819
|
*/
|
|
744
|
-
function targetSelectionHint(opts) {
|
|
820
|
+
function targetSelectionHint(opts, target) {
|
|
745
821
|
if (opts.mcpUrl)
|
|
746
822
|
return `Server address to enter there: ${redactSensitiveUrl(opts.mcpUrl)}`;
|
|
823
|
+
if (target?.ref.mcpUrl) {
|
|
824
|
+
return `Server address to enter there: ${redactSensitiveUrl(target.ref.mcpUrl)}`;
|
|
825
|
+
}
|
|
747
826
|
if (opts.docsUrl)
|
|
748
827
|
return `Found from these docs: ${redactSensitiveUrl(opts.docsUrl)}`;
|
|
749
828
|
if (opts.entryId)
|
|
@@ -810,10 +889,30 @@ function printConsoleDestination(target, opts, url) {
|
|
|
810
889
|
"(This session points at a control plane whose console address is not " +
|
|
811
890
|
"derivable — set HQ_CONSOLE_URL to name it.)");
|
|
812
891
|
}
|
|
813
|
-
const hint = targetSelectionHint(opts);
|
|
892
|
+
const hint = targetSelectionHint(opts, target);
|
|
814
893
|
if (hint)
|
|
815
894
|
console.error(` ${hint}`);
|
|
816
895
|
}
|
|
896
|
+
/**
|
|
897
|
+
* The `--json` stdout line for an outcome that ends on the console page.
|
|
898
|
+
*
|
|
899
|
+
* Every `connect --json` sign-in handoff prints exactly one line on stdout,
|
|
900
|
+
* told apart by `setup` (see CONNECT_JSON_HELP): this is the `"console"` one.
|
|
901
|
+
* It used to print nothing, so a bot reading stdout got an empty answer and
|
|
902
|
+
* exit 0. `url` is left out when the console address cannot be derived;
|
|
903
|
+
* `serverAddress` is the MCP endpoint to enter there, when one is known.
|
|
904
|
+
*/
|
|
905
|
+
function printConsoleJson(target, opts, url) {
|
|
906
|
+
if (!opts.json)
|
|
907
|
+
return;
|
|
908
|
+
const serverAddress = opts.mcpUrl ?? target.ref.mcpUrl;
|
|
909
|
+
console.log(JSON.stringify({
|
|
910
|
+
app: target.label,
|
|
911
|
+
setup: "console",
|
|
912
|
+
...(url ? { url: redactSensitiveUrl(url) } : {}),
|
|
913
|
+
...(serverAddress ? { serverAddress: redactSensitiveUrl(serverAddress) } : {}),
|
|
914
|
+
}));
|
|
915
|
+
}
|
|
817
916
|
/**
|
|
818
917
|
* Fallback for a backend that will not accept a loopback callback: send the
|
|
819
918
|
* caller to the console and let it run the whole sign-in.
|
|
@@ -836,6 +935,7 @@ async function consoleHandoff(target, opts) {
|
|
|
836
935
|
const url = consoleIntegrationsUrl(opts.company, consoleOrigin());
|
|
837
936
|
console.error(chalk.yellow(`${target.label} signs in through the console, not the terminal — this HQ backend finishes these sign-ins there.`));
|
|
838
937
|
printConsoleDestination(target, opts, url);
|
|
938
|
+
printConsoleJson(target, opts, url);
|
|
839
939
|
// A console sign-in is started by the console, so there is nowhere to put a
|
|
840
940
|
// --scopes list. Saying nothing would let the connect finish with default
|
|
841
941
|
// permissions while the caller believes theirs were requested -- the exact
|
|
@@ -858,15 +958,23 @@ async function consoleHandoff(target, opts) {
|
|
|
858
958
|
* credentials — but only the console can collect them, so say what is needed
|
|
859
959
|
* and hand the page over rather than restating the refusal and stopping.
|
|
860
960
|
*/
|
|
861
|
-
export async function bringYourOwnClientHandoff(target, opts, reason, redirectUri) {
|
|
961
|
+
export async function bringYourOwnClientHandoff(target, opts, reason, redirectUri, resolveEndpoint) {
|
|
862
962
|
console.error(chalk.yellow(redactUrlsInText(reason)));
|
|
863
963
|
console.error(`${redactUrlsInText(target.label)} needs an OAuth app you register with the provider yourself.`);
|
|
964
|
+
// A domain, catalog or name connect (`connect shopify.com`) carries no MCP
|
|
965
|
+
// endpoint, and the recovery command must pin one: hq-pro reads a caller's
|
|
966
|
+
// own client credentials on the direct `mcpUrl` path only. Without this the
|
|
967
|
+
// handoff fell through to the generic Integrations page, where an app the
|
|
968
|
+
// catalog does not list has no control, no callback URL and no credential
|
|
969
|
+
// form (feedback_3013b98e). The endpoint is the one hq-pro's blueprint for
|
|
970
|
+
// the target names, the same lookup the access-key path uses.
|
|
971
|
+
const endpointTarget = await withResolvedEndpoint(target, resolveEndpoint);
|
|
864
972
|
// Prefer finishing here. The recovery needs two things the terminal can
|
|
865
973
|
// supply — the callback URL to register, and a client id + secret — and
|
|
866
974
|
// hq-pro sends the first one back on exactly these errors. Falling through
|
|
867
975
|
// to the console when either half is missing keeps the old behaviour rather
|
|
868
976
|
// than printing a half-command that cannot work.
|
|
869
|
-
const command = byoClientCommand(
|
|
977
|
+
const command = byoClientCommand(endpointTarget, opts);
|
|
870
978
|
if (redirectUri && command) {
|
|
871
979
|
console.error("");
|
|
872
980
|
console.error(`In the provider's developer portal, register this callback URL:`);
|
|
@@ -875,15 +983,72 @@ export async function bringYourOwnClientHandoff(target, opts, reason, redirectUr
|
|
|
875
983
|
console.error(` ${command}`);
|
|
876
984
|
console.error(chalk.dim("The secret is read from stdin, so it stays out of your shell history. " +
|
|
877
985
|
"Omit --client-secret-stdin for a public app that has no secret."));
|
|
986
|
+
if (opts.json) {
|
|
987
|
+
// `--json` callers (bots driving `--link-only`) read stdout only, so the
|
|
988
|
+
// setup path has to be there too, not just in the stderr prose.
|
|
989
|
+
console.log(JSON.stringify({
|
|
990
|
+
app: target.label,
|
|
991
|
+
setup: "own-oauth-app",
|
|
992
|
+
callbackUrl: redactSensitiveUrl(redirectUri),
|
|
993
|
+
command,
|
|
994
|
+
}));
|
|
995
|
+
}
|
|
878
996
|
return null;
|
|
879
997
|
}
|
|
880
998
|
const url = consoleIntegrationsUrl(opts.company, consoleOrigin());
|
|
881
999
|
console.error("The console shows the callback URL to register and takes the credentials.");
|
|
882
|
-
printConsoleDestination(
|
|
1000
|
+
printConsoleDestination(endpointTarget, opts, url);
|
|
1001
|
+
printConsoleJson(endpointTarget, opts, url);
|
|
883
1002
|
if (url && opts.browser !== false)
|
|
884
1003
|
await open(url).catch((error) => warnBrowserOpenFailure(error));
|
|
885
1004
|
return null;
|
|
886
1005
|
}
|
|
1006
|
+
/**
|
|
1007
|
+
* `target` with the MCP endpoint `resolveEndpoint` names, when it had none.
|
|
1008
|
+
*
|
|
1009
|
+
* Best effort: a failed or empty lookup keeps `target` unchanged, which keeps
|
|
1010
|
+
* the console handoff. A failure is logged, never thrown, because the caller
|
|
1011
|
+
* is already reporting a refusal and a second error would bury it.
|
|
1012
|
+
*/
|
|
1013
|
+
async function withResolvedEndpoint(target, resolveEndpoint) {
|
|
1014
|
+
if (target.ref.mcpUrl || !resolveEndpoint)
|
|
1015
|
+
return target;
|
|
1016
|
+
let mcpUrl;
|
|
1017
|
+
try {
|
|
1018
|
+
mcpUrl = await resolveEndpoint();
|
|
1019
|
+
}
|
|
1020
|
+
catch (error) {
|
|
1021
|
+
console.warn("[hq-cli:integrations-connect] endpoint lookup failed", safeCaughtError(error));
|
|
1022
|
+
return target;
|
|
1023
|
+
}
|
|
1024
|
+
if (!mcpUrl)
|
|
1025
|
+
return target;
|
|
1026
|
+
return {
|
|
1027
|
+
...target,
|
|
1028
|
+
ref: {
|
|
1029
|
+
mcpUrl,
|
|
1030
|
+
...(target.ref.provider ? { provider: target.ref.provider } : {}),
|
|
1031
|
+
...(target.ref.displayName ? { displayName: target.ref.displayName } : {}),
|
|
1032
|
+
...(target.ref.scope ? { scope: target.ref.scope } : {}),
|
|
1033
|
+
},
|
|
1034
|
+
};
|
|
1035
|
+
}
|
|
1036
|
+
/**
|
|
1037
|
+
* The MCP endpoint hq-pro's blueprint names for a domain, catalog or name
|
|
1038
|
+
* target, or undefined when the target has no such handle or the blueprint
|
|
1039
|
+
* names no https `kind: "mcp"` surface.
|
|
1040
|
+
*/
|
|
1041
|
+
async function blueprintEndpoint(token, companyUid, target) {
|
|
1042
|
+
const { domain, query, catalogEntryId } = target.ref;
|
|
1043
|
+
if (!domain && !query && !catalogEntryId)
|
|
1044
|
+
return undefined;
|
|
1045
|
+
const blueprint = await pullBlueprint(token, companyUid, {
|
|
1046
|
+
...(domain ? { domain } : {}),
|
|
1047
|
+
...(query ? { query } : {}),
|
|
1048
|
+
...(catalogEntryId ? { catalogEntryId } : {}),
|
|
1049
|
+
});
|
|
1050
|
+
return mcpUrlFromBlueprint(blueprint, { mcpOnly: true });
|
|
1051
|
+
}
|
|
887
1052
|
/**
|
|
888
1053
|
* The copy-pasteable command that finishes a bring-your-own-app connect.
|
|
889
1054
|
*
|
|
@@ -960,7 +1125,7 @@ async function resolveUserOAuthClient(opts, appLabel) {
|
|
|
960
1125
|
if (!clientId)
|
|
961
1126
|
return null;
|
|
962
1127
|
if (opts.clientSecretStdin) {
|
|
963
|
-
const piped = (await readStdin()).trim();
|
|
1128
|
+
const piped = (await readStdin("Paste the client secret")).trim();
|
|
964
1129
|
if (!piped) {
|
|
965
1130
|
throw new IntegrationsCliError("--client-secret-stdin was set but stdin was empty.", { expected: true });
|
|
966
1131
|
}
|
|
@@ -980,7 +1145,8 @@ async function resolveUserOAuthClient(opts, appLabel) {
|
|
|
980
1145
|
* console finishes the flow it did not start (hq-pro#2823, hq-console#783), so
|
|
981
1146
|
* the caller confirms with `hq integrations list` once the person says done.
|
|
982
1147
|
* The link goes to stdout (the whole line, unredacted: it is useless redacted)
|
|
983
|
-
* so a bot can read it; with --json it is `
|
|
1148
|
+
* so a bot can read it; with --json it is the `"sign-in-link"` line of
|
|
1149
|
+
* CONNECT_JSON_HELP.
|
|
984
1150
|
*/
|
|
985
1151
|
async function linkOnlySignIn(token, companyUid, target, opts, startInput) {
|
|
986
1152
|
let started;
|
|
@@ -990,15 +1156,16 @@ async function linkOnlySignIn(token, companyUid, target, opts, startInput) {
|
|
|
990
1156
|
catch (err) {
|
|
991
1157
|
if (!(err instanceof IntegrationsCliError) || !err.code)
|
|
992
1158
|
throw err;
|
|
993
|
-
if (BRING_YOUR_OWN_CLIENT_CODES.has(err.code))
|
|
994
|
-
return await bringYourOwnClientHandoff(target, opts, err.message, err.redirectUri);
|
|
1159
|
+
if (BRING_YOUR_OWN_CLIENT_CODES.has(err.code)) {
|
|
1160
|
+
return await bringYourOwnClientHandoff(target, opts, err.message, err.redirectUri, () => blueprintEndpoint(token, companyUid, target));
|
|
1161
|
+
}
|
|
995
1162
|
if (!CONSOLE_HANDOFF_CODES.has(err.code))
|
|
996
1163
|
throw err;
|
|
997
1164
|
return await consoleHandoff(target, { ...opts, browser: false });
|
|
998
1165
|
}
|
|
999
1166
|
const app = started.displayName || target.label;
|
|
1000
1167
|
if (opts.json) {
|
|
1001
|
-
console.log(JSON.stringify({ app, authorizationUrl: started.authorizationUrl }));
|
|
1168
|
+
console.log(JSON.stringify({ app, setup: "sign-in-link", authorizationUrl: started.authorizationUrl }));
|
|
1002
1169
|
}
|
|
1003
1170
|
else {
|
|
1004
1171
|
console.error(`Sign-in link for ${redactUrlsInText(app)} (it finishes on the HQ console):`);
|
|
@@ -1095,12 +1262,23 @@ async function completeCredentialIfNeeded(token, companyUid, target, opts, resul
|
|
|
1095
1262
|
bearerToken,
|
|
1096
1263
|
});
|
|
1097
1264
|
}
|
|
1098
|
-
|
|
1265
|
+
/**
|
|
1266
|
+
* The first https endpoint the blueprint names, recommended surface first.
|
|
1267
|
+
*
|
|
1268
|
+
* `mcpOnly` keeps only `kind: "mcp"` surfaces. The own-OAuth-app handoff
|
|
1269
|
+
* prints the result as `--mcp-url`, and a blueprint with no usable
|
|
1270
|
+
* recommended surface can still list a REST or GraphQL API first (Shopify's
|
|
1271
|
+
* Admin GraphQL URL), which is not an MCP server and would make the printed
|
|
1272
|
+
* command fail.
|
|
1273
|
+
*/
|
|
1274
|
+
function mcpUrlFromBlueprint(blueprint, { mcpOnly = false } = {}) {
|
|
1099
1275
|
const surfaces = [
|
|
1100
1276
|
...(blueprint.recommendedSurface ? [blueprint.recommendedSurface] : []),
|
|
1101
1277
|
...blueprint.surfaces,
|
|
1102
1278
|
];
|
|
1103
1279
|
for (const surface of surfaces) {
|
|
1280
|
+
if (mcpOnly && surface.kind !== "mcp")
|
|
1281
|
+
continue;
|
|
1104
1282
|
const url = surface.url?.trim();
|
|
1105
1283
|
if (url && /^https:\/\//i.test(url))
|
|
1106
1284
|
return url;
|
|
@@ -1423,6 +1601,25 @@ async function refuseIfAlreadyConnected(token, companyUid, app, opts) {
|
|
|
1423
1601
|
` Add a second: hq integrations connect ${shellQuote(app)}${requestedScope ? ` ${scopeFlag(requestedScope)}` : ""} --force`));
|
|
1424
1602
|
return true;
|
|
1425
1603
|
}
|
|
1604
|
+
/**
|
|
1605
|
+
* `connect --help` text for the `--json` stdout shapes. A sign-in that does
|
|
1606
|
+
* not finish in this command prints exactly one JSON line on stdout, and
|
|
1607
|
+
* `setup` says which of these it is.
|
|
1608
|
+
*/
|
|
1609
|
+
export const CONNECT_JSON_HELP = `
|
|
1610
|
+
--json output when the sign-in does not finish in this command (for example
|
|
1611
|
+
with --link-only) is one JSON line on stdout. "setup" says which it is:
|
|
1612
|
+
{"app","setup":"sign-in-link","authorizationUrl"}
|
|
1613
|
+
Open authorizationUrl; the sign-in finishes on the HQ console.
|
|
1614
|
+
{"app","setup":"own-oauth-app","callbackUrl","command"}
|
|
1615
|
+
Register callbackUrl with the provider, then run command with your
|
|
1616
|
+
app's client id (and its secret on stdin).
|
|
1617
|
+
{"app","setup":"console","url"?,"serverAddress"?}
|
|
1618
|
+
Finish on the console page at url (left out when the console address
|
|
1619
|
+
is unknown). serverAddress is the MCP endpoint to enter there.
|
|
1620
|
+
A finished connect prints the install result instead. Confirm any of the
|
|
1621
|
+
three with \`hq integrations list\`.
|
|
1622
|
+
`;
|
|
1426
1623
|
export function registerConnectCommands(integrations) {
|
|
1427
1624
|
integrations
|
|
1428
1625
|
.command("catalog [query]")
|
|
@@ -1557,6 +1754,7 @@ export function registerConnectCommands(integrations) {
|
|
|
1557
1754
|
.option("--personal", "Connect it as your own personal connection (not --company <slug>, which picks the company)")
|
|
1558
1755
|
.option("--company-owned", "Connect it as a connection the whole company owns (needs permission to add company apps)")
|
|
1559
1756
|
.option("--json", "Machine-readable output")
|
|
1757
|
+
.addHelpText("after", CONNECT_JSON_HELP)
|
|
1560
1758
|
.action(async (app, opts) => {
|
|
1561
1759
|
connectScopeFromOptions(opts);
|
|
1562
1760
|
assertAuthMode(opts.auth);
|
|
@@ -7,14 +7,16 @@ function writeJson(value) {
|
|
|
7
7
|
function addLinkOptions(command) {
|
|
8
8
|
return command
|
|
9
9
|
.option("--json", "Print JSON output (the default)")
|
|
10
|
-
.option("--session-id <id>", "Act as this session")
|
|
10
|
+
.option("--session-id <id>", "Act as this session (self-asserted; not an authentication)")
|
|
11
11
|
.option("--link <id>", "Conduct link id")
|
|
12
12
|
.option("--child <name|all>", "Child name or all children")
|
|
13
13
|
.option("--name <name>", "Child name")
|
|
14
|
-
.option("--engine <engine>", "Session engine")
|
|
14
|
+
.option("--engine <engine>", "Session engine (adopt: keeps the link's recorded engine when omitted)")
|
|
15
15
|
.option("--title <title>", "Session title")
|
|
16
|
-
.option("--host-session <id>", "Host session id")
|
|
16
|
+
.option("--host-session <id>", "Host session id (adopt: clears the previous conductor's host session when omitted)")
|
|
17
17
|
.option("--claims <ids>", "Exact comma-separated recipient receipt IDs")
|
|
18
|
+
.option("--token <token>", "Handover token for adopt. Use --token - to read it from stdin, or --token-file: a token on the command line is visible to other processes")
|
|
19
|
+
.option("--token-file <path>", "Read the adopt handover token from a file")
|
|
18
20
|
.option("--text <message>", "Message text")
|
|
19
21
|
.option("--text-file <path>", "Read message text from a file")
|
|
20
22
|
.option("--state <state>", "Child state")
|
|
@@ -35,8 +37,10 @@ function commandError(error) {
|
|
|
35
37
|
process.exitCode = 1;
|
|
36
38
|
}
|
|
37
39
|
export function registerLanesLinkCommand(lanes) {
|
|
38
|
-
const link = lanes.command("link")
|
|
39
|
-
|
|
40
|
+
const link = lanes.command("link")
|
|
41
|
+
.summary("Link live sessions to a conductor through session inboxes")
|
|
42
|
+
.description("Link live sessions to a conductor through session inboxes. Session ids are self-asserted (--session-id or the session environment), so the conductor and handover checks guard against stale or mistaken agents, not a hostile process running as the same user");
|
|
43
|
+
const commands = ["open", "join", "send", "ack", "capabilities", "report", "status", "inbox", "read", "wait", "list", "leave", "handover", "adopt", "close"];
|
|
40
44
|
for (const subcommand of commands) {
|
|
41
45
|
addLinkOptions(link.command(subcommand)).action(async (options) => {
|
|
42
46
|
try {
|
|
@@ -45,6 +49,7 @@ export function registerLanesLinkCommand(lanes) {
|
|
|
45
49
|
env: process.env,
|
|
46
50
|
defaultValue: true,
|
|
47
51
|
});
|
|
52
|
+
// `--token -` is read from stdin inside runLaneLink, keeping the token off argv.
|
|
48
53
|
const result = await runLaneLinkWithFlag(subcommand, { ...options, hqRoot: root, env: process.env }, enabled);
|
|
49
54
|
writeJson(result.output ?? {});
|
|
50
55
|
if (result.exitCode !== undefined)
|
package/dist/commands/lanes.js
CHANGED
|
@@ -1507,17 +1507,17 @@ function laneHostFromCtx(ctx, expectedId) {
|
|
|
1507
1507
|
return { kind: "outpost", id: identity.id };
|
|
1508
1508
|
return recordedLocalHost(ctx);
|
|
1509
1509
|
}
|
|
1510
|
-
async function readOutpostCapacity(ctx, outpostId) {
|
|
1511
|
-
return readOutpostCapacityUncached(ctx, outpostId);
|
|
1510
|
+
async function readOutpostCapacity(ctx, outpostId, waitMs = CAPACITY_PROBE_TIMEOUT_MS) {
|
|
1511
|
+
return readOutpostCapacityUncached(ctx, outpostId, waitMs);
|
|
1512
1512
|
}
|
|
1513
|
-
async function readOutpostCapacityUncached(ctx, outpostId) {
|
|
1513
|
+
async function readOutpostCapacityUncached(ctx, outpostId, waitMs = CAPACITY_PROBE_TIMEOUT_MS) {
|
|
1514
1514
|
let result;
|
|
1515
1515
|
try {
|
|
1516
1516
|
result = await ctx.dispatchOutpostExec({
|
|
1517
1517
|
outpostId,
|
|
1518
1518
|
command: buildOutpostCapacityCommand(),
|
|
1519
|
-
timeoutSeconds:
|
|
1520
|
-
waitMs
|
|
1519
|
+
timeoutSeconds: Math.ceil(waitMs / 1000),
|
|
1520
|
+
waitMs,
|
|
1521
1521
|
});
|
|
1522
1522
|
}
|
|
1523
1523
|
catch (err) {
|
|
@@ -2268,12 +2268,27 @@ async function loadClaudeBalanceHostSnapshots(ctx, hqRoot, config, options = {})
|
|
|
2268
2268
|
}
|
|
2269
2269
|
const remoteIds = outpostIds.map((id) => id.trim())
|
|
2270
2270
|
.filter((id) => !isControllerAliasOutpostId(id, localHost))
|
|
2271
|
-
.filter((id) => localHost.kind !== "outpost" || id !== localHost.id)
|
|
2272
|
-
|
|
2271
|
+
.filter((id) => localHost.kind !== "outpost" || id !== localHost.id);
|
|
2272
|
+
const known = new Set(outpostIds.map((id) => id.trim()));
|
|
2273
|
+
const explicitIds = new Set();
|
|
2274
|
+
for (const id of options.includeOutpostIds ?? []) {
|
|
2275
|
+
const trimmed = id.trim();
|
|
2276
|
+
// An explicit target such as --outpost primary is measured even when
|
|
2277
|
+
// `primary` is the controller alias. The generic loop above stays closed.
|
|
2278
|
+
if (trimmed && known.has(trimmed) && !remoteIds.includes(trimmed) &&
|
|
2279
|
+
(localHost.kind !== "outpost" || trimmed !== localHost.id)) {
|
|
2280
|
+
remoteIds.push(trimmed);
|
|
2281
|
+
explicitIds.add(trimmed);
|
|
2282
|
+
}
|
|
2283
|
+
}
|
|
2284
|
+
remoteIds.sort();
|
|
2285
|
+
// An explicit target waits the single-lane pickup interval (120s by
|
|
2286
|
+
// default). The generic capacity loop above keeps the 15s probe.
|
|
2287
|
+
const explicitWaitMs = explicitIds.size > 0 ? outpostSingleLaneWaitMs(ctx.env) : CAPACITY_PROBE_TIMEOUT_MS;
|
|
2273
2288
|
const remoteResults = await mapWithConcurrency(remoteIds, OUTPOST_HIRE_SUMMARY_CONCURRENCY, async (id) => {
|
|
2274
2289
|
let capacity;
|
|
2275
2290
|
try {
|
|
2276
|
-
capacity = await readOutpostCapacity(ctx, id);
|
|
2291
|
+
capacity = await readOutpostCapacity(ctx, id, explicitIds.has(id) ? explicitWaitMs : CAPACITY_PROBE_TIMEOUT_MS);
|
|
2277
2292
|
}
|
|
2278
2293
|
catch (err) {
|
|
2279
2294
|
if (isLanesError(err) && err.error !== "outpost_capacity_unavailable") {
|
|
@@ -4243,7 +4258,9 @@ async function runCreate(ctx, opts) {
|
|
|
4243
4258
|
? { kind: "outpost", id: outpostId }
|
|
4244
4259
|
: persistedLocalHost);
|
|
4245
4260
|
balanceTargetHost = targetHost;
|
|
4246
|
-
balanceHostLoad = await loadClaudeBalanceHostSnapshots(ctx, hqRoot, config
|
|
4261
|
+
balanceHostLoad = await loadClaudeBalanceHostSnapshots(ctx, hqRoot, config, {
|
|
4262
|
+
...(outpostId !== undefined ? { includeOutpostIds: [outpostId] } : {}),
|
|
4263
|
+
});
|
|
4247
4264
|
const selected = selectClaudeAccount({
|
|
4248
4265
|
company: accountCompany,
|
|
4249
4266
|
hosts: balanceHostLoad.snapshots,
|
package/dist/commands/rescue.js
CHANGED
|
@@ -60,9 +60,22 @@ export async function retrustHooksAfterRescue(hqRoot, retrust = retrustCodexHook
|
|
|
60
60
|
export function repairReleaseLinksAfterRescue(hqRoot, repair = repairDanglingReleaseLinks) {
|
|
61
61
|
try {
|
|
62
62
|
for (const entry of repair(hqRoot)) {
|
|
63
|
+
const outside = entry.skippedOutside && entry.skippedOutside.length > 0
|
|
64
|
+
? ` (left out ${entry.skippedOutside.length} link(s) that point outside the HQ root: ${entry.skippedOutside.join(', ')})`
|
|
65
|
+
: '';
|
|
63
66
|
if (entry.action === 'repointed') {
|
|
64
67
|
console.log(`rescue: repointed dangling link ${entry.rel} -> ${entry.linkText ?? entry.target}`);
|
|
65
68
|
}
|
|
69
|
+
else if (entry.action === 'copied') {
|
|
70
|
+
console.warn(chalk.yellow(`rescue: copied ${entry.target ?? 'its target'} to ${entry.rel}: Windows created the junction but would not list through it${outside}. ` +
|
|
71
|
+
'Copies do not follow updates; `hq rescue -y` or `hq doctor --fix` refreshes it. Make changes in the target folder, not in the copy.'));
|
|
72
|
+
}
|
|
73
|
+
else if (entry.action === 'refreshed') {
|
|
74
|
+
console.log(`rescue: refreshed the copy at ${entry.rel} from ${entry.target ?? 'its target'}${outside}`);
|
|
75
|
+
}
|
|
76
|
+
else if (entry.action === 'kept') {
|
|
77
|
+
console.warn(chalk.yellow(`rescue: left the copy at ${entry.rel} as it is: ${entry.reason ?? 'it has local changes'}.`));
|
|
78
|
+
}
|
|
66
79
|
else if (entry.action === 'removed') {
|
|
67
80
|
console.log(`rescue: removed dangling link ${entry.rel} (its target is missing)`);
|
|
68
81
|
}
|
|
@@ -10,6 +10,17 @@ export type { SecretScriptUsage, SecretMetadata, SecretLoadSuccessRow } from "..
|
|
|
10
10
|
*/
|
|
11
11
|
export declare const SECRETS_EXEC_UNATTENDED_NO_COMPANY_EXIT = 78;
|
|
12
12
|
export declare const SECRETS_EXEC_UNATTENDED_NO_COMPANY_MESSAGE: string;
|
|
13
|
+
/** True when the caller's only session id is HQ_FLEET_SESSION_ID (an HQ Fleet scheduled job). */
|
|
14
|
+
export declare function fleetOnlySession(env?: NodeJS.ProcessEnv): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* True when the caller's only session id is HQ_FLEET_SESSION_ID (an HQ Fleet
|
|
17
|
+
* scheduled job) and that session has no bound company lock (feedback_998e641c
|
|
18
|
+
* review). Such a job counts as having no session: before the fleet key was
|
|
19
|
+
* read, it was refused with exit 78, and with an unbound session it would now
|
|
20
|
+
* fall through to the server's default company instead. A bound fleet session
|
|
21
|
+
* reads its own lock, never .current.
|
|
22
|
+
*/
|
|
23
|
+
export declare function unboundFleetOnlySession(env?: NodeJS.ProcessEnv): boolean;
|
|
13
24
|
import { vaultApiFetch, getCompanyUid, getEntityUid } from "../utils/vault-api.js";
|
|
14
25
|
export type { VaultApiOptions } from "../utils/vault-api.js";
|
|
15
26
|
export { vaultApiFetch, getCompanyUid, getEntityUid };
|
package/dist/commands/secrets.js
CHANGED
|
@@ -4,7 +4,7 @@ import * as path from "node:path";
|
|
|
4
4
|
import * as yaml from "js-yaml";
|
|
5
5
|
import { assertApiKeyCompany, assertDelegatedMachineSessionUsable, buildSecretUsage, callerIsCompanyOutpost, companyOutpostIdentityFromToken, companyOutpostReadDenialMessage, extractApiMessage, highSecuritySandboxOnlyMessage, loadRevealedSecrets, normalizeScriptLockMode, normalizeSecretTier, parseSecretNameList, requestedApiKeyCompany, resolveSecretsReadCompanyUid, runSecretsEnvCommand, scopeOpts, secretsCredentialOptions, } from "../secrets-env-action.js";
|
|
6
6
|
import { readSessionCompanyLock } from "../lib/session-company-lock.js";
|
|
7
|
-
import { sessionIdFromEnv } from "../lib/core-utils/session-id.js";
|
|
7
|
+
import { SESSION_ID_ENV_KEYS, sessionIdFromEnv } from "../lib/core-utils/session-id.js";
|
|
8
8
|
import { appendPersonalSecretsAudit, isEntityScopeRef, PERSONAL_SCOPE_READ_ONLY_MESSAGE, } from "../lib/personal-secrets-audit.js";
|
|
9
9
|
export { readSessionCompanyLock } from "../lib/session-company-lock.js";
|
|
10
10
|
export { buildSecretUsage, emitEnvExportsAndExit, loadRevealedSecrets, parseSecretNameList, runSecretsEnvCommand, } from "../secrets-env-action.js";
|
|
@@ -62,10 +62,35 @@ import { cognitoSubjectFromToken, ensureCognitoToken } from "../utils/cognito-se
|
|
|
62
62
|
* required configuration, so retrying the same command will not help.
|
|
63
63
|
*/
|
|
64
64
|
export const SECRETS_EXEC_UNATTENDED_NO_COMPANY_EXIT = 78;
|
|
65
|
-
export const SECRETS_EXEC_UNATTENDED_NO_COMPANY_MESSAGE =
|
|
66
|
-
|
|
67
|
-
"
|
|
68
|
-
"
|
|
65
|
+
export const SECRETS_EXEC_UNATTENDED_NO_COMPANY_MESSAGE = `hq secrets exec has no usable session id (${SESSION_ID_ENV_KEYS.slice(0, -1).join(", ")} and ` +
|
|
66
|
+
`${SESSION_ID_ENV_KEYS[SESSION_ID_ENV_KEYS.length - 1]} are all unset, or only HQ_FLEET_SESSION_ID is set ` +
|
|
67
|
+
"and that fleet session has no company lock this call can use: none is bound, or " +
|
|
68
|
+
"hooks.multi-company-session-lock is off), so it will not borrow a company " +
|
|
69
|
+
"from whichever interactive session last wrote workspace/sessions/.current or from the server's default company. " +
|
|
70
|
+
"Pass --company <slug> (or --personal), bind the fleet session with `hq-session.sh set company <slug>`, " +
|
|
71
|
+
"or set HQ_SESSION_ID to the session this job runs under.";
|
|
72
|
+
/** True when the caller's only session id is HQ_FLEET_SESSION_ID (an HQ Fleet scheduled job). */
|
|
73
|
+
export function fleetOnlySession(env = process.env) {
|
|
74
|
+
return Boolean(sessionIdFromEnv(env)) && !sessionIdFromEnv({ ...env, HQ_FLEET_SESSION_ID: undefined });
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* True when the caller's only session id is HQ_FLEET_SESSION_ID (an HQ Fleet
|
|
78
|
+
* scheduled job) and that session has no bound company lock (feedback_998e641c
|
|
79
|
+
* review). Such a job counts as having no session: before the fleet key was
|
|
80
|
+
* read, it was refused with exit 78, and with an unbound session it would now
|
|
81
|
+
* fall through to the server's default company instead. A bound fleet session
|
|
82
|
+
* reads its own lock, never .current.
|
|
83
|
+
*/
|
|
84
|
+
export function unboundFleetOnlySession(env = process.env) {
|
|
85
|
+
if (!fleetOnlySession(env))
|
|
86
|
+
return false;
|
|
87
|
+
try {
|
|
88
|
+
return (readSessionCompanyLock(env)?.companies.length ?? 0) === 0;
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
69
94
|
import { removeCacheEntry, clearAllCache } from "../utils/secrets-cache.js";
|
|
70
95
|
import { isHqCliChild, releaseChildWrapperPackageUseLeaseAfterStart } from "../utils/child-wrapper-lease.js";
|
|
71
96
|
import { withPackageUseLeaseReleasedDuring } from "../utils/package-use-lease.js";
|
|
@@ -1410,7 +1435,17 @@ export function registerSecretsCommand(program) {
|
|
|
1410
1435
|
// An unusable HQ_MACHINE_SESSION_FILE fails here, naming the file,
|
|
1411
1436
|
// before the scope check below can report a generic error.
|
|
1412
1437
|
assertDelegatedMachineSessionUsable();
|
|
1413
|
-
const
|
|
1438
|
+
const multiCompanyLockEnabled = await fastFlagEnabledDefaultOn(MULTI_COMPANY_SESSION_LOCK_FLAG);
|
|
1439
|
+
// A fleet-only caller (only HQ_FLEET_SESSION_ID) counts as a session
|
|
1440
|
+
// only when the lock that scopes this call is read and bound. With the
|
|
1441
|
+
// multi-company lock flag off the lock is never read, so a bound fleet
|
|
1442
|
+
// job would fall through to the caller's default membership company;
|
|
1443
|
+
// a fleet job whose bind failed or was skipped has no lock at all.
|
|
1444
|
+
// Both keep the exit 78 refusal they always had (review of hq-cli
|
|
1445
|
+
// #2546). An HQ_SESSION_ID caller keeps the flag-off behaviour as is.
|
|
1446
|
+
const fleetWithoutUsableLock = fleetOnlySession(process.env)
|
|
1447
|
+
&& (!multiCompanyLockEnabled || unboundFleetOnlySession(process.env));
|
|
1448
|
+
const hasCallerSession = Boolean(sessionIdFromEnv(process.env)) && !fleetWithoutUsableLock;
|
|
1414
1449
|
if (!hasCallerSession &&
|
|
1415
1450
|
!requestedCompany &&
|
|
1416
1451
|
!parentScope.personal &&
|
|
@@ -1419,7 +1454,6 @@ export function registerSecretsCommand(program) {
|
|
|
1419
1454
|
console.error(chalk.red("Error:"), SECRETS_EXEC_UNATTENDED_NO_COMPANY_MESSAGE);
|
|
1420
1455
|
process.exit(SECRETS_EXEC_UNATTENDED_NO_COMPANY_EXIT);
|
|
1421
1456
|
}
|
|
1422
|
-
const multiCompanyLockEnabled = await fastFlagEnabledDefaultOn(MULTI_COMPANY_SESSION_LOCK_FLAG);
|
|
1423
1457
|
// Only the caller's own session id may supply a lock; never .current.
|
|
1424
1458
|
const sessionLock = multiCompanyLockEnabled && hasCallerSession ? readSessionCompanyLock(process.env) : undefined;
|
|
1425
1459
|
const hasLockedCompanies = (sessionLock?.companies.length ?? 0) > 0;
|