@indigoai-us/hq-cli 5.345.214 → 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.
Files changed (103) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/dist/command-catalog.generated.d.ts +134 -7
  3. package/dist/command-catalog.generated.js +168 -7
  4. package/dist/commands/agents.d.ts +51 -1
  5. package/dist/commands/agents.js +154 -2
  6. package/dist/commands/bot-jobs.d.ts +2 -15
  7. package/dist/commands/bot-jobs.js +2 -94
  8. package/dist/commands/bot-runtime.d.ts +46 -5
  9. package/dist/commands/bot-runtime.js +228 -18
  10. package/dist/commands/bot.d.ts +16 -9
  11. package/dist/commands/bot.js +169 -51
  12. package/dist/commands/cloud.d.ts +66 -13
  13. package/dist/commands/cloud.js +120 -39
  14. package/dist/commands/company-restore.d.ts +23 -0
  15. package/dist/commands/company-restore.js +128 -0
  16. package/dist/commands/company.js +2 -0
  17. package/dist/commands/integrations-connect.d.ts +10 -3
  18. package/dist/commands/integrations-connect.js +87 -13
  19. package/dist/commands/lanes.js +26 -9
  20. package/dist/commands/sources.js +6 -0
  21. package/dist/commands/storage-offload.d.ts +12 -0
  22. package/dist/commands/storage-offload.js +41 -3
  23. package/dist/commands/sync-mode.js +5 -0
  24. package/dist/commands/whoami.js +4 -0
  25. package/dist/lib/bot/config.d.ts +1 -0
  26. package/dist/lib/bot/config.js +10 -0
  27. package/dist/lib/bot/eventbridge-cron.d.ts +22 -0
  28. package/dist/lib/bot/eventbridge-cron.js +104 -0
  29. package/dist/lib/bot/fleet-local.d.ts +33 -1
  30. package/dist/lib/bot/fleet-local.js +215 -31
  31. package/dist/lib/bot/fleet-python.d.ts +3 -0
  32. package/dist/lib/bot/fleet-python.js +34 -4
  33. package/dist/lib/bot/fleet-runtime-sources.d.ts +15 -0
  34. package/dist/lib/bot/fleet-runtime-sources.js +30 -0
  35. package/dist/lib/bot/legacy-provider-login.d.ts +8 -0
  36. package/dist/lib/bot/legacy-provider-login.js +19 -2
  37. package/dist/lib/bot/prompt.js +1 -1
  38. package/dist/lib/bot/readiness.d.ts +8 -0
  39. package/dist/lib/bot/readiness.js +17 -3
  40. package/dist/lib/bot/runtime-auth.d.ts +30 -0
  41. package/dist/lib/bot/runtime-auth.js +94 -3
  42. package/dist/lib/bot/status.d.ts +2 -0
  43. package/dist/lib/capacity/collectors/grok-refresh.d.ts +80 -0
  44. package/dist/lib/capacity/collectors/grok-refresh.js +189 -0
  45. package/dist/lib/capacity/collectors/grok.d.ts +5 -0
  46. package/dist/lib/capacity/collectors/grok.js +56 -5
  47. package/dist/lib/daemon/catalog.js +11 -1
  48. package/dist/lib/db/sqlite-binding.d.ts +1 -0
  49. package/dist/lib/db/sqlite-binding.js +1 -1
  50. package/dist/lib/delivery/artifacts.d.ts +99 -0
  51. package/dist/lib/delivery/artifacts.js +548 -0
  52. package/dist/lib/delivery/backup.d.ts +78 -0
  53. package/dist/lib/delivery/backup.js +343 -0
  54. package/dist/lib/delivery/cache.d.ts +29 -0
  55. package/dist/lib/delivery/cache.js +33 -0
  56. package/dist/lib/delivery/contracts.d.ts +142 -0
  57. package/dist/lib/delivery/contracts.js +289 -0
  58. package/dist/lib/delivery/credentials.d.ts +54 -0
  59. package/dist/lib/delivery/credentials.js +119 -0
  60. package/dist/lib/delivery/enrollment.d.ts +142 -0
  61. package/dist/lib/delivery/enrollment.js +382 -0
  62. package/dist/lib/delivery/identity.d.ts +25 -0
  63. package/dist/lib/delivery/identity.js +82 -0
  64. package/dist/lib/delivery/inbox.d.ts +116 -0
  65. package/dist/lib/delivery/inbox.js +260 -0
  66. package/dist/lib/delivery/migrations.d.ts +139 -0
  67. package/dist/lib/delivery/migrations.js +623 -0
  68. package/dist/lib/delivery/mqtt-adapter.d.ts +50 -0
  69. package/dist/lib/delivery/mqtt-adapter.js +242 -0
  70. package/dist/lib/delivery/mqtt.d.ts +61 -0
  71. package/dist/lib/delivery/mqtt.js +112 -0
  72. package/dist/lib/delivery/outbox.d.ts +95 -0
  73. package/dist/lib/delivery/outbox.js +187 -0
  74. package/dist/lib/delivery/provenance.d.ts +129 -0
  75. package/dist/lib/delivery/provenance.js +93 -0
  76. package/dist/lib/delivery/reconciler.d.ts +151 -0
  77. package/dist/lib/delivery/reconciler.js +492 -0
  78. package/dist/lib/delivery/restore.d.ts +35 -0
  79. package/dist/lib/delivery/restore.js +134 -0
  80. package/dist/lib/delivery/store.d.ts +161 -0
  81. package/dist/lib/delivery/store.js +940 -0
  82. package/dist/lib/delivery/workers/macos-job-helper.d.ts +103 -0
  83. package/dist/lib/delivery/workers/macos-job-helper.js +927 -0
  84. package/dist/lib/delivery/workers/macos.d.ts +176 -0
  85. package/dist/lib/delivery/workers/macos.js +901 -0
  86. package/dist/lib/delivery/workers/windows-boundary.d.ts +453 -0
  87. package/dist/lib/delivery/workers/windows-boundary.js +693 -0
  88. package/dist/lib/delivery/workers/windows-job-helper.d.ts +35 -0
  89. package/dist/lib/delivery/workers/windows-job-helper.js +264 -0
  90. package/dist/lib/delivery/workers/windows.d.ts +241 -0
  91. package/dist/lib/delivery/workers/windows.js +608 -0
  92. package/dist/lib/install/provider-wrappers.d.ts +2 -0
  93. package/dist/lib/install/provider-wrappers.js +68 -3
  94. package/dist/utils/cognito-callback-port.d.ts +14 -0
  95. package/dist/utils/cognito-callback-port.js +24 -0
  96. package/dist/utils/cognito-session.js +3 -3
  97. package/dist/utils/deleted-company-notice.d.ts +59 -0
  98. package/dist/utils/deleted-company-notice.js +156 -0
  99. package/dist/utils/login-browser.d.ts +1 -1
  100. package/dist/utils/login-browser.js +7 -5
  101. package/dist/utils/resident-package-preload.js +30 -15
  102. package/dist/utils/vault-api.js +7 -0
  103. package/package.json +7 -7
@@ -35,6 +35,10 @@ export function providerWrapperInstallPaths(home) {
35
35
  }
36
36
  return paths;
37
37
  }
38
+ /** Env var the installed wrapper sets when it hands a run to another wrapper script. */
39
+ export function providerWrapperGuardVar(provider) {
40
+ return `HQ_ANYWHERE_${provider.toUpperCase()}_WRAPPER_ACTIVE`;
41
+ }
38
42
  function wrapperSource(provider) {
39
43
  const pretty = provider === 'claude' ? 'Claude Code' : 'Codex';
40
44
  const login = provider === 'claude' ? 'claude /login' : 'codex login';
@@ -45,6 +49,12 @@ function wrapperSource(provider) {
45
49
  const runAuthFailure = provider === 'codex'
46
50
  ? 'HTTP error: *401|status 401|401 Unauthorized|websocket.*auth|not logged in|signed out|not authenticated|authentication required|unauthenticated'
47
51
  : 'HTTP error: *401|status 401|401 Unauthorized|not logged in|signed out|not authenticated|authentication required|unauthenticated';
52
+ // Install locations of the real provider executable, checked when PATH holds no
53
+ // executable that is not a shell script.
54
+ const knownInstalls = provider === 'claude'
55
+ ? ['"${HOME:-}/.local/bin/claude"', '"${HOME:-}/.claude/local/node_modules/.bin/claude"']
56
+ : [];
57
+ const guard = providerWrapperGuardVar(provider);
48
58
  return [
49
59
  '#!/bin/sh',
50
60
  `${marker}: ${provider}`,
@@ -55,18 +65,73 @@ function wrapperSource(provider) {
55
65
  `login='${login}'`,
56
66
  `provider='${provider}'`,
57
67
  '',
58
- '# Skip this managed wrapper and locate the provider executable later in PATH.',
68
+ '# Locate the provider. Other tools (cmux, for example) put their own provider',
69
+ '# wrapper on PATH, and that wrapper runs the next provider it finds on PATH. To',
70
+ '# keep those wrappers working without starting each other forever:',
71
+ '# - Without the guard, run the next provider on PATH after this wrapper (any',
72
+ `# kind except another HQ wrapper). When that is a shell script, set ${guard}`,
73
+ '# so a script that runs this wrapper again lands in the branch below.',
74
+ '# - With the guard set, never run another wrapper: run the real executable (the',
75
+ '# first provider on PATH that is not a shell script, then the known install',
76
+ '# locations) directly, or stop.',
77
+ 'hq_shell_script() {',
78
+ " hq_first=$(LC_ALL=C head -c 256 \"$1\" 2>/dev/null | LC_ALL=C tr -d '\\000' | LC_ALL=C head -n 1)",
79
+ ' case "$hq_first" in',
80
+ " '#!'*/sh|'#!'*/sh\\ *|'#!'*' sh'|'#!'*' sh '*|'#!'*bash*|'#!'*zsh*|'#!'*dash*|'#!'*ksh*) return 0 ;;",
81
+ ' esac',
82
+ ' return 1',
83
+ '}',
84
+ 'hq_managed_wrapper() {',
85
+ ` LC_ALL=C head -c 256 "$1" 2>/dev/null | LC_ALL=C tr -d '\\000' | grep -q '^${marker}'`,
86
+ '}',
87
+ 'hq_known_install() {',
88
+ ' known=',
89
+ ...(knownInstalls.length > 0
90
+ ? [
91
+ ` for candidate in ${knownInstalls.join(' ')}; do`,
92
+ ' if [ -f "$candidate" ] && [ -x "$candidate" ] && [ "$candidate" != "$self" ] && ! hq_shell_script "$candidate"; then known=$candidate; return 0; fi',
93
+ ' done',
94
+ ]
95
+ : []),
96
+ ' return 1',
97
+ '}',
59
98
  'self=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd -P)/$(basename -- "$0")',
60
- 'real=',
99
+ 'next=',
100
+ 'first=',
101
+ 'binary=',
102
+ 'seen_self=0',
61
103
  'old_ifs=$IFS',
62
104
  'IFS=:',
63
105
  'for dir in $PATH; do',
64
106
  ' [ -n "$dir" ] || dir=.',
65
107
  ' candidate=$(CDPATH= cd -- "$dir" 2>/dev/null && pwd -P)/$name',
66
- ' if [ -x "$candidate" ] && [ "$candidate" != "$self" ]; then real=$candidate; break; fi',
108
+ ' if [ "$candidate" = "$self" ]; then seen_self=1; continue; fi',
109
+ ' if [ ! -f "$candidate" ] || [ ! -x "$candidate" ] || hq_managed_wrapper "$candidate"; then continue; fi',
110
+ ' if [ -z "$binary" ] && ! hq_shell_script "$candidate"; then binary=$candidate; fi',
111
+ ' if [ "$seen_self" = 1 ]; then',
112
+ ' [ -n "$next" ] || next=$candidate',
113
+ ' if [ -n "$binary" ]; then break; fi',
114
+ ' elif [ -z "$first" ]; then',
115
+ ' first=$candidate',
116
+ ' fi',
67
117
  'done',
68
118
  'IFS=$old_ifs',
119
+ '',
120
+ `if [ -n "\${${guard}:-}" ]; then`,
121
+ ' # Another wrapper ran this one again. The real executable does not get the guard,',
122
+ ' # so a session it starts treats its own nested provider calls as new runs.',
123
+ ' if [ -z "$binary" ] && hq_known_install; then binary=$known; fi',
124
+ ` if [ -n "$binary" ]; then unset ${guard}; exec "$binary" "$@"; fi`,
125
+ ` printf '%s CLI was not found: every ${provider} on PATH is a wrapper script that runs this HQ wrapper (%s) again.\\nInstall %s, or put the directory that holds the real ${provider} executable on PATH.\\n' "$pretty" "$self" "$pretty" >&2`,
126
+ ' exit 127',
127
+ 'fi',
128
+ '# Invoked by a path that is not on PATH: the first provider on PATH is the next one.',
129
+ 'if [ "$seen_self" = 0 ]; then next=$first; first=; fi',
130
+ 'real=$next',
131
+ 'if [ -z "$real" ] && hq_known_install; then real=$known; fi',
132
+ '[ -n "$real" ] || real=$first',
69
133
  'if [ -z "$real" ]; then printf \'%s CLI was not found on PATH.\\n\' "$pretty" >&2; exit 127; fi',
134
+ `if hq_shell_script "$real"; then ${guard}=1; export ${guard}; fi`,
70
135
  '',
71
136
  '# The flag override is part of the existing hq-anywhere-runtime flag contract.',
72
137
  'case "${HQ_FLAG_HQ_ANYWHERE_RUNTIME:-}" in false|0) exec "$real" "$@" ;; esac',
@@ -14,4 +14,18 @@ export declare function resetStrayPortWarningForTests(): void;
14
14
  export declare function resolveCognitoCallbackPort(raw: string | number | undefined, warn?: PortWarn): number;
15
15
  /** Return `config` with its callback port forced into the registered set. */
16
16
  export declare function withRegisteredCallbackPort<T extends CognitoAuthConfig>(config: T, warn?: PortWarn): T;
17
+ /** Default OIDC prompt for a browser sign-in: the provider shows its account chooser. */
18
+ export declare const DEFAULT_COGNITO_LOGIN_PROMPT = "select_account";
19
+ /** HQ_COGNITO_PROMPT overrides the sign-in prompt; an empty value sends no prompt. */
20
+ export declare function resolveCognitoLoginPrompt(env?: NodeJS.ProcessEnv): string | undefined;
21
+ /**
22
+ * Config for an interactive browser sign-in: a registered callback port plus
23
+ * the account-chooser prompt. Cognito forwards `prompt` to the identity
24
+ * provider, so a person with several Google accounts picks one instead of
25
+ * being signed in silently with whichever the browser used last.
26
+ *
27
+ * Use this only for a sign-in a person completes in a browser. Token refresh
28
+ * keeps passing DEFAULT_COGNITO itself, which never carries a prompt.
29
+ */
30
+ export declare function interactiveLoginConfig<T extends CognitoAuthConfig>(config: T, warn?: PortWarn): T;
17
31
  //# sourceMappingURL=cognito-callback-port.d.ts.map
@@ -53,4 +53,28 @@ export function withRegisteredCallbackPort(config, warn = defaultWarn) {
53
53
  const port = resolveCognitoCallbackPort(config.port, warn);
54
54
  return port === config.port ? config : { ...config, port };
55
55
  }
56
+ /** Default OIDC prompt for a browser sign-in: the provider shows its account chooser. */
57
+ export const DEFAULT_COGNITO_LOGIN_PROMPT = "select_account";
58
+ /** HQ_COGNITO_PROMPT overrides the sign-in prompt; an empty value sends no prompt. */
59
+ export function resolveCognitoLoginPrompt(env = process.env) {
60
+ const raw = env.HQ_COGNITO_PROMPT;
61
+ if (raw === undefined)
62
+ return DEFAULT_COGNITO_LOGIN_PROMPT;
63
+ return raw.trim() || undefined;
64
+ }
65
+ /**
66
+ * Config for an interactive browser sign-in: a registered callback port plus
67
+ * the account-chooser prompt. Cognito forwards `prompt` to the identity
68
+ * provider, so a person with several Google accounts picks one instead of
69
+ * being signed in silently with whichever the browser used last.
70
+ *
71
+ * Use this only for a sign-in a person completes in a browser. Token refresh
72
+ * keeps passing DEFAULT_COGNITO itself, which never carries a prompt.
73
+ */
74
+ export function interactiveLoginConfig(config, warn = defaultWarn) {
75
+ const registered = withRegisteredCallbackPort(config, warn);
76
+ const { prompt: _configured, ...rest } = registered;
77
+ const prompt = resolveCognitoLoginPrompt();
78
+ return (prompt ? { ...rest, prompt } : rest);
79
+ }
56
80
  //# sourceMappingURL=cognito-callback-port.js.map
@@ -32,7 +32,7 @@ import { daemonDir } from "../lib/mesh/live/daemon/paths.js";
32
32
  import { workMeshRoot } from "../lib/mesh/live/paths.js";
33
33
  import { defaultHqRootFallback, hqDiscoveryCandidates, pathForPlatform, } from "./hq-root-resolver.js";
34
34
  import { acquireLockFileExclusively } from "./exclusive-lock.js";
35
- import { resolveCognitoCallbackPort, withRegisteredCallbackPort } from "./cognito-callback-port.js";
35
+ import { interactiveLoginConfig, resolveCognitoCallbackPort } from "./cognito-callback-port.js";
36
36
  import { HQ_NO_BROWSER_LOGIN_ENV, NON_INTERACTIVE_LOGIN_MESSAGE, isInteractiveCaller, } from "./interactive-caller.js";
37
37
  import { reportNoninteractivePersonRefreshRejection } from "./cognito-refresh-sentry.js";
38
38
  import { decodeJwtPayload, loadCachedTokens, personTokenCacheFile, readPersonTokenFile, readTokenFile, } from "./person-token-cache.js";
@@ -956,7 +956,7 @@ async function ensureCognitoTokenUnserialized(options) {
956
956
  "(or HQ_MACHINE_CREDS_FILE to its machine-creds.json). Otherwise run `hq login` on a computer with a browser.");
957
957
  }
958
958
  console.error(chalk.cyan(" No cached HQ session — launching browser sign-in..."));
959
- const tokens = await browserLogin(withRegisteredCallbackPort(DEFAULT_COGNITO));
959
+ const tokens = await browserLogin(interactiveLoginConfig(DEFAULT_COGNITO));
960
960
  return tokens.accessToken;
961
961
  }
962
962
  /**
@@ -1037,7 +1037,7 @@ async function ensureCognitoIdTokenUnserialized(options) {
1037
1037
  "(or HQ_MACHINE_CREDS_FILE to its machine-creds.json). Otherwise run `hq login` on a computer with a browser.");
1038
1038
  }
1039
1039
  console.error(chalk.cyan(" No cached HQ session — launching browser sign-in..."));
1040
- const tokens = await browserLogin(withRegisteredCallbackPort(DEFAULT_COGNITO));
1040
+ const tokens = await browserLogin(interactiveLoginConfig(DEFAULT_COGNITO));
1041
1041
  return tokens.idToken;
1042
1042
  }
1043
1043
  /**
@@ -0,0 +1,59 @@
1
+ /** One entry of `deletedCompanies` on `GET /membership/me`. */
2
+ export interface DeletedCompanyEntry {
3
+ companyUid: string;
4
+ companyName?: string;
5
+ companySlug?: string;
6
+ role?: string;
7
+ deletedAt: string | null;
8
+ deletedByYou: boolean;
9
+ restorable: boolean;
10
+ restoreUntil: string | null;
11
+ }
12
+ /** Where a person goes when they cannot restore a company themselves. */
13
+ export declare const DELETED_COMPANY_SUPPORT_POINTER = "Run `hq feedback bug` to ask HQ support about recovery.";
14
+ /** The same pointer, for the end of a sentence that starts with "..., or". */
15
+ export declare const DELETED_COMPANY_SUPPORT_POINTER_INLINE = "run `hq feedback bug` to ask HQ support about recovery.";
16
+ /** Default bound on the notice's own `/membership/me` read. */
17
+ export declare const DELETED_COMPANY_NOTICE_TIMEOUT_MS = 3000;
18
+ /** Name shown for a deleted company: its name, then its slug, then "A company". */
19
+ export declare function deletedCompanyDisplayName(entry: DeletedCompanyEntry): string;
20
+ /** Narrow an untrusted `deletedCompanies` value. Malformed entries are dropped. */
21
+ export declare function parseDeletedCompanies(raw: unknown): DeletedCompanyEntry[];
22
+ /**
23
+ * Plain lines describing one deleted company and the person's next step.
24
+ * `now` closes the restore offer once `restoreUntil` has passed, even if the
25
+ * entry still says `restorable`.
26
+ */
27
+ export declare function formatDeletedCompanyNotice(entry: DeletedCompanyEntry, now?: Date): string[];
28
+ /**
29
+ * Read `deletedCompanies` from `GET /membership/me`. Throws on a transport
30
+ * failure or a non-2xx answer; `printDeletedCompanyNotices` swallows that,
31
+ * `hq company restore` reports it.
32
+ */
33
+ export declare function fetchDeletedCompanies(opts: {
34
+ token: string;
35
+ signal?: AbortSignal;
36
+ }): Promise<DeletedCompanyEntry[]>;
37
+ /** Test hook: allow the notice to print again in this process. */
38
+ export declare function resetDeletedCompanyNoticeForTests(): void;
39
+ export interface PrintDeletedCompanyNoticesOptions {
40
+ /** Bearer token to read with. Defaults to the cached session, never a sign-in. */
41
+ token?: string;
42
+ /**
43
+ * `deletedCompanies` from a `/membership/me` response the caller already
44
+ * has. When the key is present (even as `undefined`) no request is made.
45
+ */
46
+ entries?: unknown;
47
+ /** Bound on the read. */
48
+ timeoutMs?: number;
49
+ /** Where the lines go. Defaults to stderr. */
50
+ write?: (line: string) => void;
51
+ now?: Date;
52
+ }
53
+ /**
54
+ * Tell a signed-in person about companies that were deleted, on stderr, at
55
+ * most once per process. Never throws and never touches the exit code: every
56
+ * failure is silent. Machine and agent identities are skipped.
57
+ */
58
+ export declare function printDeletedCompanyNotices(opts?: PrintDeletedCompanyNoticesOptions): Promise<void>;
59
+ //# sourceMappingURL=deleted-company-notice.d.ts.map
@@ -0,0 +1,156 @@
1
+ // src/utils/deleted-company-notice.ts
2
+ //
3
+ // A deleted company disappears from `/membership/me` memberships, so a person
4
+ // whose only company was deleted sees "no memberships" with no explanation.
5
+ // hq-pro now lists those companies under `deletedCompanies`; this module turns
6
+ // them into a plain notice on stderr and feeds `hq company restore`.
7
+ //
8
+ // The pinned hq-cloud client drops unknown keys from `/membership/me`, so the
9
+ // field is read here with a direct `vaultApiFetch` call.
10
+ //
11
+ // vault-api.ts loads this module on use (a dynamic import in its
12
+ // no-memberships branch), so the static imports below do not form a cycle.
13
+ import { ensureCognitoToken, resolveCognitoTokenSource } from "./cognito-session.js";
14
+ import { vaultApiFetch } from "./vault-api.js";
15
+ /** Where a person goes when they cannot restore a company themselves. */
16
+ export const DELETED_COMPANY_SUPPORT_POINTER = "Run `hq feedback bug` to ask HQ support about recovery.";
17
+ /** The same pointer, for the end of a sentence that starts with "..., or". */
18
+ export const DELETED_COMPANY_SUPPORT_POINTER_INLINE = "run `hq feedback bug` to ask HQ support about recovery.";
19
+ /** Default bound on the notice's own `/membership/me` read. */
20
+ export const DELETED_COMPANY_NOTICE_TIMEOUT_MS = 3_000;
21
+ const LONG_DATE = new Intl.DateTimeFormat("en-US", {
22
+ dateStyle: "long",
23
+ timeZone: "UTC",
24
+ });
25
+ function formatDate(iso) {
26
+ if (typeof iso !== "string" || !iso)
27
+ return null;
28
+ const time = Date.parse(iso);
29
+ if (!Number.isFinite(time))
30
+ return null;
31
+ return LONG_DATE.format(new Date(time));
32
+ }
33
+ /** Server-supplied text is printed to a terminal: drop control characters. */
34
+ function clean(value) {
35
+ if (typeof value !== "string")
36
+ return undefined;
37
+ // eslint-disable-next-line no-control-regex
38
+ const text = value.replace(/[\u0000-\u001f\u007f-\u009f]/g, "").trim();
39
+ return text || undefined;
40
+ }
41
+ /** Name shown for a deleted company: its name, then its slug, then "A company". */
42
+ export function deletedCompanyDisplayName(entry) {
43
+ return clean(entry.companyName) ?? clean(entry.companySlug) ?? "A company";
44
+ }
45
+ /** Narrow an untrusted `deletedCompanies` value. Malformed entries are dropped. */
46
+ export function parseDeletedCompanies(raw) {
47
+ if (!Array.isArray(raw))
48
+ return [];
49
+ const entries = [];
50
+ for (const item of raw) {
51
+ if (!item || typeof item !== "object")
52
+ continue;
53
+ const record = item;
54
+ const companyUid = clean(record.companyUid);
55
+ if (!companyUid)
56
+ continue;
57
+ entries.push({
58
+ companyUid,
59
+ companyName: clean(record.companyName),
60
+ companySlug: clean(record.companySlug),
61
+ role: clean(record.role),
62
+ deletedAt: typeof record.deletedAt === "string" ? record.deletedAt : null,
63
+ deletedByYou: record.deletedByYou === true,
64
+ restorable: record.restorable === true,
65
+ restoreUntil: typeof record.restoreUntil === "string" ? record.restoreUntil : null,
66
+ });
67
+ }
68
+ return entries;
69
+ }
70
+ /**
71
+ * Plain lines describing one deleted company and the person's next step.
72
+ * `now` closes the restore offer once `restoreUntil` has passed, even if the
73
+ * entry still says `restorable`.
74
+ */
75
+ export function formatDeletedCompanyNotice(entry, now = new Date()) {
76
+ const name = deletedCompanyDisplayName(entry);
77
+ const deletedOn = formatDate(entry.deletedAt);
78
+ const lead = `${name} was deleted${deletedOn ? ` on ${deletedOn}` : ""}.`;
79
+ const untilTime = entry.restoreUntil ? Date.parse(entry.restoreUntil) : NaN;
80
+ const windowPassed = Number.isFinite(untilTime) && untilTime <= now.getTime();
81
+ if (entry.restorable && !windowPassed) {
82
+ const until = formatDate(entry.restoreUntil);
83
+ const target = clean(entry.companySlug) ?? entry.companyUid;
84
+ return [
85
+ `${lead} You can restore it${until ? ` until ${until}` : ""}: ` +
86
+ `run \`hq company restore ${target}\` or open the HQ desktop app.`,
87
+ ];
88
+ }
89
+ if (entry.deletedByYou) {
90
+ return [
91
+ `${lead} The 30-day restore window has closed. ${DELETED_COMPANY_SUPPORT_POINTER}`,
92
+ ];
93
+ }
94
+ return [
95
+ `${lead} Ask the company owner to restore it, or ${DELETED_COMPANY_SUPPORT_POINTER_INLINE}`,
96
+ ];
97
+ }
98
+ /**
99
+ * Read `deletedCompanies` from `GET /membership/me`. Throws on a transport
100
+ * failure or a non-2xx answer; `printDeletedCompanyNotices` swallows that,
101
+ * `hq company restore` reports it.
102
+ */
103
+ export async function fetchDeletedCompanies(opts) {
104
+ const res = await vaultApiFetch({
105
+ token: opts.token,
106
+ path: "/membership/me",
107
+ signal: opts.signal,
108
+ });
109
+ if (!res.ok)
110
+ throw new Error(`membership read failed (${res.status})`);
111
+ const data = (await res.json());
112
+ return parseDeletedCompanies(data?.deletedCompanies);
113
+ }
114
+ let noticeAttempted = false;
115
+ /** Test hook: allow the notice to print again in this process. */
116
+ export function resetDeletedCompanyNoticeForTests() {
117
+ noticeAttempted = false;
118
+ }
119
+ /**
120
+ * Tell a signed-in person about companies that were deleted, on stderr, at
121
+ * most once per process. Never throws and never touches the exit code: every
122
+ * failure is silent. Machine and agent identities are skipped.
123
+ */
124
+ export async function printDeletedCompanyNotices(opts = {}) {
125
+ if (noticeAttempted)
126
+ return;
127
+ noticeAttempted = true;
128
+ try {
129
+ if (resolveCognitoTokenSource() === "machine")
130
+ return;
131
+ let entries;
132
+ if ("entries" in opts) {
133
+ entries = parseDeletedCompanies(opts.entries);
134
+ }
135
+ else {
136
+ const token = opts.token ?? (await ensureCognitoToken({ interactive: false }));
137
+ if (!token)
138
+ return;
139
+ entries = await fetchDeletedCompanies({
140
+ token,
141
+ signal: AbortSignal.timeout(opts.timeoutMs ?? DELETED_COMPANY_NOTICE_TIMEOUT_MS),
142
+ });
143
+ }
144
+ if (entries.length === 0)
145
+ return;
146
+ const write = opts.write ?? ((line) => process.stderr.write(`${line}\n`));
147
+ for (const entry of entries) {
148
+ for (const line of formatDeletedCompanyNotice(entry, opts.now))
149
+ write(line);
150
+ }
151
+ }
152
+ catch {
153
+ // A notice is decoration on another command. It must never fail it.
154
+ }
155
+ }
156
+ //# sourceMappingURL=deleted-company-notice.js.map
@@ -1,4 +1,4 @@
1
1
  import type { CognitoAuthConfig, CognitoTokens } from "@indigoai-us/hq-cloud";
2
2
  /** Keep desktop login unchanged; manual login uses the same PKCE loopback flow. */
3
- export declare function loginWithBrowserPreference(config: CognitoAuthConfig, browser?: boolean): Promise<CognitoTokens>;
3
+ export declare function loginWithBrowserPreference(requested: CognitoAuthConfig, browser?: boolean): Promise<CognitoTokens>;
4
4
  //# sourceMappingURL=login-browser.d.ts.map
@@ -2,7 +2,7 @@ import { createHash, randomBytes, timingSafeEqual } from "node:crypto";
2
2
  import { createServer } from "node:http";
3
3
  import { browserLogin, saveCachedTokens, CognitoAuthError } from "@indigoai-us/hq-cloud";
4
4
  import { isHeadless } from "./headless.js";
5
- import { withRegisteredCallbackPort } from "./cognito-callback-port.js";
5
+ import { interactiveLoginConfig } from "./cognito-callback-port.js";
6
6
  function assertHumanLoginAllowed() {
7
7
  // Preserve hq-cloud's company-machine boundary on the manual URL path.
8
8
  if (["1", "true", "yes"].includes(process.env.HQ_MACHINE_AUTH_REQUIRED?.trim().toLowerCase() ?? "")) {
@@ -10,13 +10,15 @@ function assertHumanLoginAllowed() {
10
10
  }
11
11
  }
12
12
  /** Keep desktop login unchanged; manual login uses the same PKCE loopback flow. */
13
- export async function loginWithBrowserPreference(config, browser = true) {
13
+ export async function loginWithBrowserPreference(requested, browser = true) {
14
14
  // A callback port outside the registered set opens a redirect_mismatch tab.
15
+ // The manual URL path builds the same redirect_uri and authorize URL, so
16
+ // both paths share one config: registered port plus the account chooser.
17
+ const config = interactiveLoginConfig(requested);
15
18
  if (browser && !isHeadless())
16
- return browserLogin(withRegisteredCallbackPort(config));
19
+ return browserLogin(config);
17
20
  assertHumanLoginAllowed();
18
- // The manual URL path builds the same redirect_uri, so it needs the same guard.
19
- const port = withRegisteredCallbackPort(config).port ?? 3000;
21
+ const port = config.port ?? 3000;
20
22
  const redirectUri = `http://localhost:${port}/callback`;
21
23
  const base = `https://${config.userPoolDomain}.auth.${config.region}.amazoncognito.com`;
22
24
  const verifier = randomBytes(32).toString("base64url");