@indigoai-us/hq-cli 5.345.212 → 5.345.214
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 +20 -0
- package/dist/bin/hq-auth-refresh.js +2 -1
- package/dist/command-catalog.generated.d.ts +308 -43
- package/dist/command-catalog.generated.js +373 -43
- 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/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 +7 -1
- package/dist/commands/integrations-connect.js +137 -13
- package/dist/commands/lanes-link.js +10 -5
- package/dist/commands/rescue.js +13 -0
- package/dist/commands/secrets.d.ts +11 -0
- package/dist/commands/secrets.js +41 -7
- 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/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 +1 -0
- package/dist/lib/bot/fleet-local.js +41 -8
- 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/run.js +9 -1
- package/dist/lib/daemon/updater.d.ts +34 -2
- package/dist/lib/daemon/updater.js +51 -2
- 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/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/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/package.json +7 -7
|
@@ -674,7 +674,7 @@ async function connectViaOAuth(token, companyUid, target, opts) {
|
|
|
674
674
|
throw err;
|
|
675
675
|
if (BRING_YOUR_OWN_CLIENT_CODES.has(err.code)) {
|
|
676
676
|
listener.close();
|
|
677
|
-
return await bringYourOwnClientHandoff(target, opts, err.message, err.redirectUri);
|
|
677
|
+
return await bringYourOwnClientHandoff(target, opts, err.message, err.redirectUri, () => blueprintEndpoint(token, companyUid, target));
|
|
678
678
|
}
|
|
679
679
|
if (!CONSOLE_HANDOFF_CODES.has(err.code))
|
|
680
680
|
throw err;
|
|
@@ -738,12 +738,17 @@ companySlug, origin) {
|
|
|
738
738
|
* A `--mcp-url` or `--docs-url` target has no catalog row to search for over
|
|
739
739
|
* there — `resolveTarget` reduces a docs page to an opaque discovery receipt
|
|
740
740
|
* 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
|
|
741
|
+
* the only copy of it is in the caller's scrollback. A catalog target usually
|
|
742
|
+
* needs no hint, since its label is what they search for over there. A domain
|
|
743
|
+
* the catalog does not list (shopify.com, feedback_3013b98e) finds nothing in
|
|
744
|
+
* that search, so when the endpoint was resolved it is printed too.
|
|
743
745
|
*/
|
|
744
|
-
function targetSelectionHint(opts) {
|
|
746
|
+
function targetSelectionHint(opts, target) {
|
|
745
747
|
if (opts.mcpUrl)
|
|
746
748
|
return `Server address to enter there: ${redactSensitiveUrl(opts.mcpUrl)}`;
|
|
749
|
+
if (target?.ref.mcpUrl) {
|
|
750
|
+
return `Server address to enter there: ${redactSensitiveUrl(target.ref.mcpUrl)}`;
|
|
751
|
+
}
|
|
747
752
|
if (opts.docsUrl)
|
|
748
753
|
return `Found from these docs: ${redactSensitiveUrl(opts.docsUrl)}`;
|
|
749
754
|
if (opts.entryId)
|
|
@@ -810,10 +815,30 @@ function printConsoleDestination(target, opts, url) {
|
|
|
810
815
|
"(This session points at a control plane whose console address is not " +
|
|
811
816
|
"derivable — set HQ_CONSOLE_URL to name it.)");
|
|
812
817
|
}
|
|
813
|
-
const hint = targetSelectionHint(opts);
|
|
818
|
+
const hint = targetSelectionHint(opts, target);
|
|
814
819
|
if (hint)
|
|
815
820
|
console.error(` ${hint}`);
|
|
816
821
|
}
|
|
822
|
+
/**
|
|
823
|
+
* The `--json` stdout line for an outcome that ends on the console page.
|
|
824
|
+
*
|
|
825
|
+
* Every `connect --json` sign-in handoff prints exactly one line on stdout,
|
|
826
|
+
* told apart by `setup` (see CONNECT_JSON_HELP): this is the `"console"` one.
|
|
827
|
+
* It used to print nothing, so a bot reading stdout got an empty answer and
|
|
828
|
+
* exit 0. `url` is left out when the console address cannot be derived;
|
|
829
|
+
* `serverAddress` is the MCP endpoint to enter there, when one is known.
|
|
830
|
+
*/
|
|
831
|
+
function printConsoleJson(target, opts, url) {
|
|
832
|
+
if (!opts.json)
|
|
833
|
+
return;
|
|
834
|
+
const serverAddress = opts.mcpUrl ?? target.ref.mcpUrl;
|
|
835
|
+
console.log(JSON.stringify({
|
|
836
|
+
app: target.label,
|
|
837
|
+
setup: "console",
|
|
838
|
+
...(url ? { url: redactSensitiveUrl(url) } : {}),
|
|
839
|
+
...(serverAddress ? { serverAddress: redactSensitiveUrl(serverAddress) } : {}),
|
|
840
|
+
}));
|
|
841
|
+
}
|
|
817
842
|
/**
|
|
818
843
|
* Fallback for a backend that will not accept a loopback callback: send the
|
|
819
844
|
* caller to the console and let it run the whole sign-in.
|
|
@@ -836,6 +861,7 @@ async function consoleHandoff(target, opts) {
|
|
|
836
861
|
const url = consoleIntegrationsUrl(opts.company, consoleOrigin());
|
|
837
862
|
console.error(chalk.yellow(`${target.label} signs in through the console, not the terminal — this HQ backend finishes these sign-ins there.`));
|
|
838
863
|
printConsoleDestination(target, opts, url);
|
|
864
|
+
printConsoleJson(target, opts, url);
|
|
839
865
|
// A console sign-in is started by the console, so there is nowhere to put a
|
|
840
866
|
// --scopes list. Saying nothing would let the connect finish with default
|
|
841
867
|
// permissions while the caller believes theirs were requested -- the exact
|
|
@@ -858,15 +884,23 @@ async function consoleHandoff(target, opts) {
|
|
|
858
884
|
* credentials — but only the console can collect them, so say what is needed
|
|
859
885
|
* and hand the page over rather than restating the refusal and stopping.
|
|
860
886
|
*/
|
|
861
|
-
export async function bringYourOwnClientHandoff(target, opts, reason, redirectUri) {
|
|
887
|
+
export async function bringYourOwnClientHandoff(target, opts, reason, redirectUri, resolveEndpoint) {
|
|
862
888
|
console.error(chalk.yellow(redactUrlsInText(reason)));
|
|
863
889
|
console.error(`${redactUrlsInText(target.label)} needs an OAuth app you register with the provider yourself.`);
|
|
890
|
+
// A domain, catalog or name connect (`connect shopify.com`) carries no MCP
|
|
891
|
+
// endpoint, and the recovery command must pin one: hq-pro reads a caller's
|
|
892
|
+
// own client credentials on the direct `mcpUrl` path only. Without this the
|
|
893
|
+
// handoff fell through to the generic Integrations page, where an app the
|
|
894
|
+
// catalog does not list has no control, no callback URL and no credential
|
|
895
|
+
// form (feedback_3013b98e). The endpoint is the one hq-pro's blueprint for
|
|
896
|
+
// the target names, the same lookup the access-key path uses.
|
|
897
|
+
const endpointTarget = await withResolvedEndpoint(target, resolveEndpoint);
|
|
864
898
|
// Prefer finishing here. The recovery needs two things the terminal can
|
|
865
899
|
// supply — the callback URL to register, and a client id + secret — and
|
|
866
900
|
// hq-pro sends the first one back on exactly these errors. Falling through
|
|
867
901
|
// to the console when either half is missing keeps the old behaviour rather
|
|
868
902
|
// than printing a half-command that cannot work.
|
|
869
|
-
const command = byoClientCommand(
|
|
903
|
+
const command = byoClientCommand(endpointTarget, opts);
|
|
870
904
|
if (redirectUri && command) {
|
|
871
905
|
console.error("");
|
|
872
906
|
console.error(`In the provider's developer portal, register this callback URL:`);
|
|
@@ -875,15 +909,72 @@ export async function bringYourOwnClientHandoff(target, opts, reason, redirectUr
|
|
|
875
909
|
console.error(` ${command}`);
|
|
876
910
|
console.error(chalk.dim("The secret is read from stdin, so it stays out of your shell history. " +
|
|
877
911
|
"Omit --client-secret-stdin for a public app that has no secret."));
|
|
912
|
+
if (opts.json) {
|
|
913
|
+
// `--json` callers (bots driving `--link-only`) read stdout only, so the
|
|
914
|
+
// setup path has to be there too, not just in the stderr prose.
|
|
915
|
+
console.log(JSON.stringify({
|
|
916
|
+
app: target.label,
|
|
917
|
+
setup: "own-oauth-app",
|
|
918
|
+
callbackUrl: redactSensitiveUrl(redirectUri),
|
|
919
|
+
command,
|
|
920
|
+
}));
|
|
921
|
+
}
|
|
878
922
|
return null;
|
|
879
923
|
}
|
|
880
924
|
const url = consoleIntegrationsUrl(opts.company, consoleOrigin());
|
|
881
925
|
console.error("The console shows the callback URL to register and takes the credentials.");
|
|
882
|
-
printConsoleDestination(
|
|
926
|
+
printConsoleDestination(endpointTarget, opts, url);
|
|
927
|
+
printConsoleJson(endpointTarget, opts, url);
|
|
883
928
|
if (url && opts.browser !== false)
|
|
884
929
|
await open(url).catch((error) => warnBrowserOpenFailure(error));
|
|
885
930
|
return null;
|
|
886
931
|
}
|
|
932
|
+
/**
|
|
933
|
+
* `target` with the MCP endpoint `resolveEndpoint` names, when it had none.
|
|
934
|
+
*
|
|
935
|
+
* Best effort: a failed or empty lookup keeps `target` unchanged, which keeps
|
|
936
|
+
* the console handoff. A failure is logged, never thrown, because the caller
|
|
937
|
+
* is already reporting a refusal and a second error would bury it.
|
|
938
|
+
*/
|
|
939
|
+
async function withResolvedEndpoint(target, resolveEndpoint) {
|
|
940
|
+
if (target.ref.mcpUrl || !resolveEndpoint)
|
|
941
|
+
return target;
|
|
942
|
+
let mcpUrl;
|
|
943
|
+
try {
|
|
944
|
+
mcpUrl = await resolveEndpoint();
|
|
945
|
+
}
|
|
946
|
+
catch (error) {
|
|
947
|
+
console.warn("[hq-cli:integrations-connect] endpoint lookup failed", safeCaughtError(error));
|
|
948
|
+
return target;
|
|
949
|
+
}
|
|
950
|
+
if (!mcpUrl)
|
|
951
|
+
return target;
|
|
952
|
+
return {
|
|
953
|
+
...target,
|
|
954
|
+
ref: {
|
|
955
|
+
mcpUrl,
|
|
956
|
+
...(target.ref.provider ? { provider: target.ref.provider } : {}),
|
|
957
|
+
...(target.ref.displayName ? { displayName: target.ref.displayName } : {}),
|
|
958
|
+
...(target.ref.scope ? { scope: target.ref.scope } : {}),
|
|
959
|
+
},
|
|
960
|
+
};
|
|
961
|
+
}
|
|
962
|
+
/**
|
|
963
|
+
* The MCP endpoint hq-pro's blueprint names for a domain, catalog or name
|
|
964
|
+
* target, or undefined when the target has no such handle or the blueprint
|
|
965
|
+
* names no https `kind: "mcp"` surface.
|
|
966
|
+
*/
|
|
967
|
+
async function blueprintEndpoint(token, companyUid, target) {
|
|
968
|
+
const { domain, query, catalogEntryId } = target.ref;
|
|
969
|
+
if (!domain && !query && !catalogEntryId)
|
|
970
|
+
return undefined;
|
|
971
|
+
const blueprint = await pullBlueprint(token, companyUid, {
|
|
972
|
+
...(domain ? { domain } : {}),
|
|
973
|
+
...(query ? { query } : {}),
|
|
974
|
+
...(catalogEntryId ? { catalogEntryId } : {}),
|
|
975
|
+
});
|
|
976
|
+
return mcpUrlFromBlueprint(blueprint, { mcpOnly: true });
|
|
977
|
+
}
|
|
887
978
|
/**
|
|
888
979
|
* The copy-pasteable command that finishes a bring-your-own-app connect.
|
|
889
980
|
*
|
|
@@ -980,7 +1071,8 @@ async function resolveUserOAuthClient(opts, appLabel) {
|
|
|
980
1071
|
* console finishes the flow it did not start (hq-pro#2823, hq-console#783), so
|
|
981
1072
|
* the caller confirms with `hq integrations list` once the person says done.
|
|
982
1073
|
* The link goes to stdout (the whole line, unredacted: it is useless redacted)
|
|
983
|
-
* so a bot can read it; with --json it is `
|
|
1074
|
+
* so a bot can read it; with --json it is the `"sign-in-link"` line of
|
|
1075
|
+
* CONNECT_JSON_HELP.
|
|
984
1076
|
*/
|
|
985
1077
|
async function linkOnlySignIn(token, companyUid, target, opts, startInput) {
|
|
986
1078
|
let started;
|
|
@@ -990,15 +1082,16 @@ async function linkOnlySignIn(token, companyUid, target, opts, startInput) {
|
|
|
990
1082
|
catch (err) {
|
|
991
1083
|
if (!(err instanceof IntegrationsCliError) || !err.code)
|
|
992
1084
|
throw err;
|
|
993
|
-
if (BRING_YOUR_OWN_CLIENT_CODES.has(err.code))
|
|
994
|
-
return await bringYourOwnClientHandoff(target, opts, err.message, err.redirectUri);
|
|
1085
|
+
if (BRING_YOUR_OWN_CLIENT_CODES.has(err.code)) {
|
|
1086
|
+
return await bringYourOwnClientHandoff(target, opts, err.message, err.redirectUri, () => blueprintEndpoint(token, companyUid, target));
|
|
1087
|
+
}
|
|
995
1088
|
if (!CONSOLE_HANDOFF_CODES.has(err.code))
|
|
996
1089
|
throw err;
|
|
997
1090
|
return await consoleHandoff(target, { ...opts, browser: false });
|
|
998
1091
|
}
|
|
999
1092
|
const app = started.displayName || target.label;
|
|
1000
1093
|
if (opts.json) {
|
|
1001
|
-
console.log(JSON.stringify({ app, authorizationUrl: started.authorizationUrl }));
|
|
1094
|
+
console.log(JSON.stringify({ app, setup: "sign-in-link", authorizationUrl: started.authorizationUrl }));
|
|
1002
1095
|
}
|
|
1003
1096
|
else {
|
|
1004
1097
|
console.error(`Sign-in link for ${redactUrlsInText(app)} (it finishes on the HQ console):`);
|
|
@@ -1095,12 +1188,23 @@ async function completeCredentialIfNeeded(token, companyUid, target, opts, resul
|
|
|
1095
1188
|
bearerToken,
|
|
1096
1189
|
});
|
|
1097
1190
|
}
|
|
1098
|
-
|
|
1191
|
+
/**
|
|
1192
|
+
* The first https endpoint the blueprint names, recommended surface first.
|
|
1193
|
+
*
|
|
1194
|
+
* `mcpOnly` keeps only `kind: "mcp"` surfaces. The own-OAuth-app handoff
|
|
1195
|
+
* prints the result as `--mcp-url`, and a blueprint with no usable
|
|
1196
|
+
* recommended surface can still list a REST or GraphQL API first (Shopify's
|
|
1197
|
+
* Admin GraphQL URL), which is not an MCP server and would make the printed
|
|
1198
|
+
* command fail.
|
|
1199
|
+
*/
|
|
1200
|
+
function mcpUrlFromBlueprint(blueprint, { mcpOnly = false } = {}) {
|
|
1099
1201
|
const surfaces = [
|
|
1100
1202
|
...(blueprint.recommendedSurface ? [blueprint.recommendedSurface] : []),
|
|
1101
1203
|
...blueprint.surfaces,
|
|
1102
1204
|
];
|
|
1103
1205
|
for (const surface of surfaces) {
|
|
1206
|
+
if (mcpOnly && surface.kind !== "mcp")
|
|
1207
|
+
continue;
|
|
1104
1208
|
const url = surface.url?.trim();
|
|
1105
1209
|
if (url && /^https:\/\//i.test(url))
|
|
1106
1210
|
return url;
|
|
@@ -1423,6 +1527,25 @@ async function refuseIfAlreadyConnected(token, companyUid, app, opts) {
|
|
|
1423
1527
|
` Add a second: hq integrations connect ${shellQuote(app)}${requestedScope ? ` ${scopeFlag(requestedScope)}` : ""} --force`));
|
|
1424
1528
|
return true;
|
|
1425
1529
|
}
|
|
1530
|
+
/**
|
|
1531
|
+
* `connect --help` text for the `--json` stdout shapes. A sign-in that does
|
|
1532
|
+
* not finish in this command prints exactly one JSON line on stdout, and
|
|
1533
|
+
* `setup` says which of these it is.
|
|
1534
|
+
*/
|
|
1535
|
+
export const CONNECT_JSON_HELP = `
|
|
1536
|
+
--json output when the sign-in does not finish in this command (for example
|
|
1537
|
+
with --link-only) is one JSON line on stdout. "setup" says which it is:
|
|
1538
|
+
{"app","setup":"sign-in-link","authorizationUrl"}
|
|
1539
|
+
Open authorizationUrl; the sign-in finishes on the HQ console.
|
|
1540
|
+
{"app","setup":"own-oauth-app","callbackUrl","command"}
|
|
1541
|
+
Register callbackUrl with the provider, then run command with your
|
|
1542
|
+
app's client id (and its secret on stdin).
|
|
1543
|
+
{"app","setup":"console","url"?,"serverAddress"?}
|
|
1544
|
+
Finish on the console page at url (left out when the console address
|
|
1545
|
+
is unknown). serverAddress is the MCP endpoint to enter there.
|
|
1546
|
+
A finished connect prints the install result instead. Confirm any of the
|
|
1547
|
+
three with \`hq integrations list\`.
|
|
1548
|
+
`;
|
|
1426
1549
|
export function registerConnectCommands(integrations) {
|
|
1427
1550
|
integrations
|
|
1428
1551
|
.command("catalog [query]")
|
|
@@ -1557,6 +1680,7 @@ export function registerConnectCommands(integrations) {
|
|
|
1557
1680
|
.option("--personal", "Connect it as your own personal connection (not --company <slug>, which picks the company)")
|
|
1558
1681
|
.option("--company-owned", "Connect it as a connection the whole company owns (needs permission to add company apps)")
|
|
1559
1682
|
.option("--json", "Machine-readable output")
|
|
1683
|
+
.addHelpText("after", CONNECT_JSON_HELP)
|
|
1560
1684
|
.action(async (app, opts) => {
|
|
1561
1685
|
connectScopeFromOptions(opts);
|
|
1562
1686
|
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/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;
|
package/dist/index.js
CHANGED
|
@@ -73,6 +73,7 @@ async function runMainWithInstallTreeRecovery() {
|
|
|
73
73
|
sentry.Sentry.captureException(error, installTree.installTreeTornCaptureContext(error));
|
|
74
74
|
sentry.finishSentrySession();
|
|
75
75
|
await sentry.Sentry.flush(2_000);
|
|
76
|
+
sentry.closeSentryTransport();
|
|
76
77
|
process.exitCode = 1;
|
|
77
78
|
return;
|
|
78
79
|
}
|
|
@@ -124,6 +125,7 @@ const recoverFastImport = async (load, options = {}) => {
|
|
|
124
125
|
sentry.Sentry.captureException(error, installTree.installTreeTornCaptureContext(error));
|
|
125
126
|
sentry.finishSentrySession();
|
|
126
127
|
await sentry.Sentry.flush(2_000);
|
|
128
|
+
sentry.closeSentryTransport();
|
|
127
129
|
return { reexecStatus: 1 };
|
|
128
130
|
}
|
|
129
131
|
}
|
package/dist/lazy-commands.js
CHANGED
|
@@ -33,6 +33,8 @@ export async function registerCommandRoot(program, root) {
|
|
|
33
33
|
function commandDefinition(command) {
|
|
34
34
|
const stub = new Command(command.name)
|
|
35
35
|
.description(command.description);
|
|
36
|
+
if (command.summary)
|
|
37
|
+
stub.summary(command.summary);
|
|
36
38
|
if (command.helpOption === false)
|
|
37
39
|
stub.helpOption(false);
|
|
38
40
|
for (const alias of command.aliases)
|
|
@@ -22,7 +22,8 @@
|
|
|
22
22
|
* Pure apart from the injected `sleep`/`random`, so tests drive it with fake
|
|
23
23
|
* timers.
|
|
24
24
|
*/
|
|
25
|
-
import type
|
|
25
|
+
import { type MergedInbox } from "./inbox-state.js";
|
|
26
|
+
import type { AgentKitPaths } from "./paths.js";
|
|
26
27
|
/** Env override for the per-attempt deadline; values under the floor are raised to it. */
|
|
27
28
|
export declare const AGENT_INBOX_TIMEOUT_ENV = "HQ_AGENT_INBOX_TIMEOUT_MS";
|
|
28
29
|
/** Delay before the one retry when the server sent no usable `Retry-After`. */
|
|
@@ -50,6 +51,11 @@ export interface FetchServerInboxDeps {
|
|
|
50
51
|
random?: () => number;
|
|
51
52
|
/** Per-attempt deadline covering mint plus GET. */
|
|
52
53
|
timeoutMs?: number;
|
|
54
|
+
/**
|
|
55
|
+
* Overall cancel signal (a batch deadline). It cuts an in-flight attempt
|
|
56
|
+
* short and suppresses the retry once aborted.
|
|
57
|
+
*/
|
|
58
|
+
signal?: AbortSignal;
|
|
53
59
|
}
|
|
54
60
|
export type FetchServerInboxOutcome = {
|
|
55
61
|
ok: true;
|
|
@@ -76,6 +82,121 @@ export declare function parseRetryAfterSeconds(header: string | null | undefined
|
|
|
76
82
|
* response or the last error, plus how many attempts were made.
|
|
77
83
|
*/
|
|
78
84
|
export declare function fetchServerInboxWithRetry(deps: FetchServerInboxDeps): Promise<FetchServerInboxOutcome>;
|
|
85
|
+
/** Env override for the total time one batch of acks may take. */
|
|
86
|
+
export declare const AGENT_INBOX_ACK_DEADLINE_ENV = "HQ_AGENT_INBOX_ACK_DEADLINE_MS";
|
|
87
|
+
/** Default total time for one batch of acks (`done` with many ids). */
|
|
88
|
+
export declare const AGENT_INBOX_ACK_DEADLINE_MS = 60000;
|
|
89
|
+
/** Budget for retrying unconfirmed acks at the start of an inbox read. */
|
|
90
|
+
export declare const AGENT_INBOX_READ_ACK_RETRY_MS = 10000;
|
|
91
|
+
/**
|
|
92
|
+
* Total time for one inbox read: the ack retry plus the bounded server read.
|
|
93
|
+
* Kept under the 60 s tool timeout MCP clients commonly apply to
|
|
94
|
+
* hq_inbox_read, with room for the local work around it.
|
|
95
|
+
*/
|
|
96
|
+
export declare const AGENT_INBOX_READ_BUDGET_MS = 45000;
|
|
97
|
+
export declare function isPermanentAckStatus(status: number): boolean;
|
|
98
|
+
/** The inbox read's total budget passed before the server answered. */
|
|
99
|
+
export declare class InboxReadBudgetError extends Error {
|
|
100
|
+
readonly budgetMs: number;
|
|
101
|
+
constructor(budgetMs: number);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* fetchServerInboxWithRetry under one total budget: the in-flight attempt is
|
|
105
|
+
* cut at the budget and the retry delay never waits past it. Never throws.
|
|
106
|
+
*/
|
|
107
|
+
export declare function fetchServerInboxWithinBudget(deps: FetchServerInboxDeps, budgetMs: number): Promise<FetchServerInboxOutcome>;
|
|
108
|
+
/** The batch deadline passed before this id's ack was confirmed. */
|
|
109
|
+
export declare class InboxAckDeadlineError extends Error {
|
|
110
|
+
readonly deadlineMs: number;
|
|
111
|
+
constructor(deadlineMs: number);
|
|
112
|
+
}
|
|
113
|
+
/** Batch deadline from the env; values under the kit floor are raised to it. */
|
|
114
|
+
export declare function resolveAgentInboxAckDeadlineMs(env?: NodeJS.ProcessEnv): number;
|
|
115
|
+
export interface AckServerInboxDeps extends Omit<FetchServerInboxDeps, "fetch"> {
|
|
116
|
+
/** POST the ack for `id` with `token`. Must not throw on a non-2xx status. */
|
|
117
|
+
post: (token: string, id: string, signal: AbortSignal) => Promise<InboxFetchResponse>;
|
|
118
|
+
/**
|
|
119
|
+
* Total time for the whole batch. Once it passes, the in-flight ack is cut
|
|
120
|
+
* short and every remaining id is reported unconfirmed with `deferred: true`
|
|
121
|
+
* (feedback 3e376c49 review: N ids x ~65 s could outlive a host's timeout).
|
|
122
|
+
*/
|
|
123
|
+
deadlineMs?: number;
|
|
124
|
+
/** Called right after each confirmed (2xx) ack, before the next id is sent. */
|
|
125
|
+
onAcked?: (id: string) => void;
|
|
126
|
+
}
|
|
127
|
+
export interface InboxAckFailure {
|
|
128
|
+
id: string;
|
|
129
|
+
/** Final HTTP status, when the server answered. */
|
|
130
|
+
status?: number;
|
|
131
|
+
/** Error message, when no answer arrived (mint failure, timeout, transport, deadline). Never response bytes. */
|
|
132
|
+
error?: string;
|
|
133
|
+
attempts: number;
|
|
134
|
+
/** True when the batch deadline passed before this ack was sent. */
|
|
135
|
+
deferred?: true;
|
|
136
|
+
/** True for a 400/403/404: not retried; the id moves to ack-failed.json. */
|
|
137
|
+
permanent?: true;
|
|
138
|
+
}
|
|
139
|
+
export interface InboxAckResult {
|
|
140
|
+
acked: string[];
|
|
141
|
+
failed: InboxAckFailure[];
|
|
142
|
+
/** True only when every id got a 2xx ack from the server. */
|
|
143
|
+
complete: boolean;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Ack each id on the server with the same bounded, once-retried attempt as the
|
|
147
|
+
* inbox read (feedback 3e376c49). Before, `hq agent inbox done` and
|
|
148
|
+
* `hq_inbox_done` sent one unbounded POST per id with no retry and reported a
|
|
149
|
+
* transient failure only as a warning line, so automation could not tell a
|
|
150
|
+
* completed ack from a lost one. The server ack is idempotent (processed
|
|
151
|
+
* marker, then delete pending), so retrying after a lost response, or the
|
|
152
|
+
* caller rerunning `done`, cannot double-complete an item. Never throws.
|
|
153
|
+
*/
|
|
154
|
+
export declare function ackServerInboxItems(ids: string[], deps: AckServerInboxDeps): Promise<InboxAckResult>;
|
|
155
|
+
/** One-line description of an ack failure for a person or a log. */
|
|
156
|
+
export declare function describeInboxAckFailure(f: InboxAckFailure): string;
|
|
157
|
+
/**
|
|
158
|
+
* The `ackFailures` string format `hq_inbox_done` has always returned, kept so
|
|
159
|
+
* existing parsers keep working: `"<id> (<status>)"` for an HTTP answer, and
|
|
160
|
+
* `"ack skipped: <id>: <message>"` when no answer arrived. Structured detail
|
|
161
|
+
* is in `ackFailureDetails`. `hq agent inbox done --json` uses the same two
|
|
162
|
+
* fields, so both surfaces have one shape.
|
|
163
|
+
*/
|
|
164
|
+
export declare function formatInboxAckFailure(f: InboxAckFailure): string;
|
|
165
|
+
export interface InboxDoneOutcome extends InboxAckResult {
|
|
166
|
+
/** Requested ids newly recorded in done-ids.json (confirmed by the server). */
|
|
167
|
+
marked: string[];
|
|
168
|
+
/** Requested ids that were already in done-ids.json before this call. */
|
|
169
|
+
alreadyDone: string[];
|
|
170
|
+
/** Ids from an earlier call whose ack was confirmed on this one. */
|
|
171
|
+
retriedAcked: string[];
|
|
172
|
+
/** Ids still awaiting a confirmed ack after this call (durable in ack-pending.json). */
|
|
173
|
+
ackPending: string[];
|
|
174
|
+
/** Ids the server refused permanently on this call; moved to ack-failed.json and no longer retried. */
|
|
175
|
+
ackFailed: string[];
|
|
176
|
+
/** True when every REQUESTED id is confirmed; earlier ids still pending show in `ackPending`. */
|
|
177
|
+
requestedComplete: boolean;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* `hq agent inbox done` / `hq_inbox_done` (feedback 3e376c49): record the ids
|
|
181
|
+
* in ack-pending.json first, ack them plus any ids an earlier call left
|
|
182
|
+
* unconfirmed, and move each id to done-ids.json only after its 2xx. A failed
|
|
183
|
+
* ack, the batch deadline or a killed process leaves the id in
|
|
184
|
+
* ack-pending.json, where it stays visible and is retried by the next read or
|
|
185
|
+
* done call. Never throws on a network failure.
|
|
186
|
+
*/
|
|
187
|
+
export declare function completeInboxItems(paths: Pick<AgentKitPaths, "inboxDir">, ids: string[], deps: Omit<AckServerInboxDeps, "onAcked">): Promise<InboxDoneOutcome>;
|
|
188
|
+
/**
|
|
189
|
+
* Retry the acks an earlier `done` left unconfirmed, at the start of an inbox
|
|
190
|
+
* read. Returns undefined when nothing was pending. Bounded by
|
|
191
|
+
* AGENT_INBOX_READ_ACK_RETRY_MS (or a smaller batch deadline) so a read stays
|
|
192
|
+
* quick when the server is down.
|
|
193
|
+
*/
|
|
194
|
+
export declare function retryPendingInboxAcks(paths: Pick<AgentKitPaths, "inboxDir">, deps: Omit<AckServerInboxDeps, "onAcked">): Promise<{
|
|
195
|
+
acked: string[];
|
|
196
|
+
failed: InboxAckFailure[];
|
|
197
|
+
ackPending: string[];
|
|
198
|
+
ackFailed: string[];
|
|
199
|
+
} | undefined>;
|
|
79
200
|
/** Suffix added to the degradation note when the retry also failed. */
|
|
80
201
|
export declare const AGENT_INBOX_AFTER_ATTEMPTS_SUFFIX = " (after 2 attempts)";
|
|
81
202
|
export interface AnnotatedInbox extends MergedInbox {
|