@indigoai-us/hq-cli 5.345.212-beta.0 → 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 +40 -1
- 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/command-registration-plan.d.ts +15 -0
- package/dist/command-registration-plan.js +20 -1
- 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.js +6 -1
- package/dist/commands/billing.js +17 -4
- 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 +68 -6
- package/dist/commands/files.js +2 -2
- package/dist/commands/integrations-api.d.ts +11 -0
- package/dist/commands/integrations-connect.d.ts +9 -1
- package/dist/commands/integrations-connect.js +154 -18
- package/dist/commands/integrations-core.d.ts +1 -1
- package/dist/commands/integrations-core.js +18 -10
- package/dist/commands/integrations.js +1 -1
- package/dist/commands/lanes-link.js +10 -5
- package/dist/commands/lanes.js +34 -16
- 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 +6 -1
- 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/billing/usage-only.d.ts +4 -1
- package/dist/lib/billing/usage-only.js +7 -2
- 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/capacity/ledger.d.ts +7 -0
- package/dist/lib/capacity/ledger.js +31 -1
- package/dist/lib/capacity/project.d.ts +1 -1
- package/dist/lib/capacity/project.js +13 -4
- package/dist/lib/capacity/route.d.ts +10 -0
- package/dist/lib/capacity/route.js +16 -0
- 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/install.d.ts +15 -0
- package/dist/lib/daemon/install.js +31 -0
- package/dist/lib/daemon/migrate.js +29 -4
- 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/__testing__/run-doctor.js +4 -0
- package/dist/lib/doctor/checks/jq.d.ts +27 -0
- package/dist/lib/doctor/checks/jq.js +82 -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/doctor/registry.js +4 -0
- package/dist/lib/flag-snapshot-file.js +36 -8
- package/dist/lib/install/codex-targets.d.ts +52 -1
- package/dist/lib/install/codex-targets.js +77 -2
- 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/monitor.d.ts +4 -1
- package/dist/lib/lanes/monitor.js +47 -10
- package/dist/lib/lanes/outpost-pruner-install.d.ts +10 -0
- package/dist/lib/lanes/outpost-pruner-install.js +4 -3
- package/dist/lib/lanes/spawn.js +8 -1
- package/dist/lib/lanes/watch.js +31 -0
- package/dist/lib/onboarding/checkpoint.d.ts +6 -0
- package/dist/lib/onboarding/checkpoint.js +6 -0
- package/dist/lib/onboarding/orchestrator.d.ts +3 -1
- package/dist/lib/onboarding/orchestrator.js +62 -9
- package/dist/lib/onboarding/types.d.ts +8 -0
- package/dist/lib/work-context/organize.d.ts +23 -1
- package/dist/lib/work-context/organize.js +25 -3
- package/dist/lib/work-context/reconcile.js +3 -2
- package/dist/main.js +3 -1
- package/dist/secrets-env-action.js +7 -5
- 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/startup-registration.js +7 -2
- package/dist/utils/billing-gate.d.ts +12 -16
- package/dist/utils/billing-gate.js +17 -18
- package/dist/utils/cli-network-lifecycle.d.ts +9 -0
- package/dist/utils/cli-network-lifecycle.js +52 -0
- package/dist/utils/install-tree-torn.d.ts +22 -4
- package/dist/utils/install-tree-torn.js +24 -0
- package/dist/utils/registration-plan-error.d.ts +22 -0
- package/dist/utils/registration-plan-error.js +27 -0
- package/dist/utils/safe-link.d.ts +63 -0
- package/dist/utils/safe-link.js +246 -0
- package/dist/utils/sentry-fingerprint.js +3 -0
- package/dist/utils/sentry-keepalive-transport.d.ts +28 -0
- package/dist/utils/sentry-keepalive-transport.js +70 -0
- package/dist/utils/unauthorized-error.d.ts +36 -0
- package/dist/utils/unauthorized-error.js +105 -0
- package/dist/utils/vault-api.js +7 -5
- package/package.json +7 -7
- package/scripts/install-hook-engine.mjs +17 -0
|
@@ -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
|
@@ -94,8 +94,8 @@ import { writeQuestionBody } from "../lib/lanes/questions.js";
|
|
|
94
94
|
import { compactionAfterUsage, } from "../lib/lanes/compaction.js";
|
|
95
95
|
import { parseCliEffort, resolveLaneEffort, } from "../lib/lanes/effort.js";
|
|
96
96
|
import { LanesError } from "../lib/lanes/errors.js";
|
|
97
|
-
import { LedgerCorrupt, capacityOptionsFromEnv, readCollectorMark, readNow, rebuildNow, } from "../lib/capacity/ledger.js";
|
|
98
|
-
import { pickAccount, refusalHasStaleReading, staleReadingTargets, } from "../lib/capacity/route.js";
|
|
97
|
+
import { LedgerCorrupt, LedgerMissing, capacityOptionsFromEnv, readCollectorMark, readNow, rebuildNow, } from "../lib/capacity/ledger.js";
|
|
98
|
+
import { pickAccount, refusalHasNoReadings, refusalHasStaleReading, staleReadingTargets, UNKNOWN_USAGE_SCORE, } from "../lib/capacity/route.js";
|
|
99
99
|
import { capacityViewAge } from "../lib/capacity/freshness.js";
|
|
100
100
|
import { applyTerminalToLane, classifyLaneExit, readLatestEnvelopeRecord } from "../lib/lanes/watcher.js";
|
|
101
101
|
import { isSubagentLane, parseLaneEnvelope, parseLaneRunner } from "../lib/lanes/types.js";
|
|
@@ -3596,7 +3596,20 @@ async function runCreate(ctx, opts) {
|
|
|
3596
3596
|
let autoChosenAccount;
|
|
3597
3597
|
if (opts.account !== undefined && opts.account.trim() === "auto") {
|
|
3598
3598
|
const ledgerOptions = capacityOptionsFromEnv(ctx.env);
|
|
3599
|
-
|
|
3599
|
+
// feedback_9e444a9f / feedback_86552798: with no ledger yet (capacity was
|
|
3600
|
+
// never enabled), or a ledger with no reading for any lane account, there
|
|
3601
|
+
// is no evidence any account is full. Route as if the flag were omitted
|
|
3602
|
+
// (balanced admission over the enabled lane accounts) instead of refusing
|
|
3603
|
+
// with capacity_unavailable or no_account_with_room.
|
|
3604
|
+
const noReadingsFallback = () => {
|
|
3605
|
+
autoAccountPick = {
|
|
3606
|
+
why: "no capacity reading for any lane account yet, so the account is chosen as if --account were omitted",
|
|
3607
|
+
headroom: 0,
|
|
3608
|
+
score: UNKNOWN_USAGE_SCORE,
|
|
3609
|
+
};
|
|
3610
|
+
opts = { ...opts, account: undefined };
|
|
3611
|
+
};
|
|
3612
|
+
let view = null;
|
|
3600
3613
|
try {
|
|
3601
3614
|
view = readNow(ledgerOptions);
|
|
3602
3615
|
}
|
|
@@ -3604,7 +3617,7 @@ async function runCreate(ctx, opts) {
|
|
|
3604
3617
|
if (err instanceof LedgerCorrupt) {
|
|
3605
3618
|
view = rebuildNow(ledgerOptions);
|
|
3606
3619
|
}
|
|
3607
|
-
else {
|
|
3620
|
+
else if (!(err instanceof LedgerMissing)) {
|
|
3608
3621
|
throw new LanesError("capacity_unavailable", `Cannot route --account auto: ${err instanceof Error ? err.message : String(err)}`, {});
|
|
3609
3622
|
}
|
|
3610
3623
|
}
|
|
@@ -3629,11 +3642,11 @@ async function runCreate(ctx, opts) {
|
|
|
3629
3642
|
lanesError: routeLanesError,
|
|
3630
3643
|
allowExtraUsage: opts.allowExtraUsage === true,
|
|
3631
3644
|
});
|
|
3632
|
-
let result = routeOn(view);
|
|
3645
|
+
let result = view === null ? null : routeOn(view);
|
|
3633
3646
|
// feedback_94446741: a refusal that rests on a missing or day-old reading
|
|
3634
3647
|
// is not evidence that the account is full. Take one fresh reading and
|
|
3635
3648
|
// route again; refuse only if there is still no room.
|
|
3636
|
-
if (refusalHasStaleReading(result) && ctx.refreshCapacity) {
|
|
3649
|
+
if (result !== null && refusalHasStaleReading(result) && ctx.refreshCapacity) {
|
|
3637
3650
|
try {
|
|
3638
3651
|
const refreshed = await ctx.refreshCapacity({
|
|
3639
3652
|
env: ctx.env,
|
|
@@ -3649,7 +3662,10 @@ async function runCreate(ctx, opts) {
|
|
|
3649
3662
|
// A failed refresh leaves the original refusal in place.
|
|
3650
3663
|
}
|
|
3651
3664
|
}
|
|
3652
|
-
if (
|
|
3665
|
+
if (result === null || refusalHasNoReadings(result)) {
|
|
3666
|
+
noReadingsFallback();
|
|
3667
|
+
}
|
|
3668
|
+
else if (!result.ok || !result.pick) {
|
|
3653
3669
|
const resetSuffix = result.next_reset ? `; next reset ${result.next_reset}` : "";
|
|
3654
3670
|
throw new LanesError("no_account_with_room", `No account has room${resetSuffix}`, {
|
|
3655
3671
|
next_reset: result.next_reset,
|
|
@@ -3657,15 +3673,17 @@ async function runCreate(ctx, opts) {
|
|
|
3657
3673
|
skipped: result.skipped,
|
|
3658
3674
|
});
|
|
3659
3675
|
}
|
|
3660
|
-
|
|
3661
|
-
|
|
3662
|
-
|
|
3663
|
-
|
|
3664
|
-
|
|
3665
|
-
|
|
3666
|
-
|
|
3667
|
-
|
|
3668
|
-
|
|
3676
|
+
else {
|
|
3677
|
+
autoChosenProvider = parseLaneProvider(result.pick.provider);
|
|
3678
|
+
autoChosenAccount = result.pick.account;
|
|
3679
|
+
autoAccountPick = {
|
|
3680
|
+
why: result.pick.why,
|
|
3681
|
+
headroom: result.pick.headroom,
|
|
3682
|
+
score: result.pick.score,
|
|
3683
|
+
};
|
|
3684
|
+
opts = { ...opts, account: autoChosenAccount, provider: autoChosenProvider };
|
|
3685
|
+
explicitProvider = autoChosenProvider;
|
|
3686
|
+
}
|
|
3669
3687
|
}
|
|
3670
3688
|
if (opts.outpost !== undefined && opts.outpost !== "") {
|
|
3671
3689
|
const requested = opts.outpost.trim();
|
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
|
@@ -4,6 +4,7 @@ import { homedir } from "node:os";
|
|
|
4
4
|
import { dirname, join, resolve } from "node:path";
|
|
5
5
|
import { COMMAND_CATALOG } from "./command-catalog.generated.js";
|
|
6
6
|
import { installUnknownCommandSuggestions } from "./unknown-command.js";
|
|
7
|
+
import { MissingRegistrationPlanError } from "./utils/registration-plan-error.js";
|
|
7
8
|
const commandCatalog = COMMAND_CATALOG;
|
|
8
9
|
/**
|
|
9
10
|
* One entry for every root, including groups that are assembled by several
|
|
@@ -14,8 +15,10 @@ const LAZY_COMMANDS = commandCatalog.map((command) => ({
|
|
|
14
15
|
name: command.name,
|
|
15
16
|
register: async (program) => {
|
|
16
17
|
const registered = await registerCommandRoot(program, command.name);
|
|
18
|
+
// A missing plan means the catalog and the plan came from different installs
|
|
19
|
+
// (an update landed mid-start); the typed error routes it to torn-install recovery.
|
|
17
20
|
if (!registered)
|
|
18
|
-
throw new
|
|
21
|
+
throw new MissingRegistrationPlanError(command.name);
|
|
19
22
|
},
|
|
20
23
|
}));
|
|
21
24
|
/**
|
|
@@ -30,6 +33,8 @@ export async function registerCommandRoot(program, root) {
|
|
|
30
33
|
function commandDefinition(command) {
|
|
31
34
|
const stub = new Command(command.name)
|
|
32
35
|
.description(command.description);
|
|
36
|
+
if (command.summary)
|
|
37
|
+
stub.summary(command.summary);
|
|
33
38
|
if (command.helpOption === false)
|
|
34
39
|
stub.helpOption(false);
|
|
35
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 {
|