@indigoai-us/hq-cli 5.60.0 → 5.62.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 (98) hide show
  1. package/dist/commands/agents.d.ts +109 -0
  2. package/dist/commands/agents.js +385 -0
  3. package/dist/commands/db-migrate.d.ts +6 -0
  4. package/dist/commands/db-migrate.js +42 -0
  5. package/dist/commands/db-provision.d.ts +15 -0
  6. package/dist/commands/db-provision.js +78 -0
  7. package/dist/commands/db-sql.d.ts +9 -0
  8. package/dist/commands/db-sql.js +81 -0
  9. package/dist/commands/db-status.d.ts +7 -0
  10. package/dist/commands/db-status.js +70 -0
  11. package/dist/commands/db.d.ts +9 -0
  12. package/dist/commands/db.js +23 -0
  13. package/dist/commands/integrations.d.ts +78 -0
  14. package/dist/commands/integrations.js +309 -0
  15. package/dist/commands/members.js +4 -4
  16. package/dist/commands/outposts.d.ts +60 -0
  17. package/dist/commands/outposts.js +255 -0
  18. package/dist/commands/pack-install.d.ts +7 -1
  19. package/dist/commands/pack-install.js +86 -15
  20. package/dist/commands/packs.d.ts +2 -1
  21. package/dist/commands/packs.js +13 -8
  22. package/dist/commands/secrets.d.ts +13 -0
  23. package/dist/commands/secrets.js +149 -10
  24. package/dist/commands/skill.d.ts +153 -0
  25. package/dist/commands/skill.js +593 -0
  26. package/dist/commands/workers.d.ts +48 -0
  27. package/dist/commands/workers.js +229 -0
  28. package/dist/index.d.ts +5 -3
  29. package/dist/index.js +14 -240
  30. package/dist/lib/db/control-plane.d.ts +45 -0
  31. package/dist/lib/db/control-plane.js +81 -0
  32. package/dist/lib/db/local.d.ts +49 -0
  33. package/dist/lib/db/local.js +106 -0
  34. package/dist/lib/db/migrate.d.ts +41 -0
  35. package/dist/lib/db/migrate.js +104 -0
  36. package/dist/lib/db/paths.d.ts +56 -0
  37. package/dist/lib/db/paths.js +103 -0
  38. package/dist/lib/db/remote-engine.d.ts +58 -0
  39. package/dist/lib/db/remote-engine.js +90 -0
  40. package/dist/lib/db/remote-sql.d.ts +22 -0
  41. package/dist/lib/db/remote-sql.js +39 -0
  42. package/dist/lib/db/sql.d.ts +49 -0
  43. package/dist/lib/db/sql.js +132 -0
  44. package/dist/main.d.ts +7 -0
  45. package/dist/main.js +272 -0
  46. package/dist/utils/cognito-session.js +3 -3
  47. package/dist/utils/sandbox-runner-client.d.ts +13 -0
  48. package/dist/utils/sandbox-runner-client.js +83 -6
  49. package/dist/utils/version-check.d.ts +6 -0
  50. package/dist/utils/version-check.js +78 -2
  51. package/package.json +9 -1
  52. package/pnpm-workspace.yaml +2 -0
  53. package/src/commands/agents.test.ts +297 -0
  54. package/src/commands/agents.ts +561 -0
  55. package/src/commands/db-migrate.ts +55 -0
  56. package/src/commands/db-provision.ts +102 -0
  57. package/src/commands/db-sql.ts +124 -0
  58. package/src/commands/db-status.ts +100 -0
  59. package/src/commands/db.ts +26 -0
  60. package/src/commands/integrations.test.ts +284 -0
  61. package/src/commands/integrations.ts +438 -0
  62. package/src/commands/members.ts +2 -2
  63. package/src/commands/outposts.test.ts +177 -0
  64. package/src/commands/outposts.ts +338 -0
  65. package/src/commands/pack-install.ts +115 -18
  66. package/src/commands/pack-update-cache.test.ts +149 -0
  67. package/src/commands/packs.ts +28 -7
  68. package/src/commands/secrets.parse-destination.test.ts +38 -0
  69. package/src/commands/secrets.test.ts +342 -0
  70. package/src/commands/secrets.ts +227 -13
  71. package/src/commands/skill.test.ts +770 -0
  72. package/src/commands/skill.ts +796 -0
  73. package/src/commands/workers.test.ts +158 -0
  74. package/src/commands/workers.ts +298 -0
  75. package/src/index.test.ts +32 -0
  76. package/src/index.ts +11 -274
  77. package/src/lib/db/control-plane.test.ts +59 -0
  78. package/src/lib/db/control-plane.ts +113 -0
  79. package/src/lib/db/local.test.ts +81 -0
  80. package/src/lib/db/local.ts +148 -0
  81. package/src/lib/db/migrate.test.ts +133 -0
  82. package/src/lib/db/migrate.ts +137 -0
  83. package/src/lib/db/paths.test.ts +112 -0
  84. package/src/lib/db/paths.ts +128 -0
  85. package/src/lib/db/remote-engine.test.ts +44 -0
  86. package/src/lib/db/remote-engine.ts +148 -0
  87. package/src/lib/db/remote-sql.test.ts +32 -0
  88. package/src/lib/db/remote-sql.ts +62 -0
  89. package/src/lib/db/sql.test.ts +106 -0
  90. package/src/lib/db/sql.ts +192 -0
  91. package/src/main.ts +314 -0
  92. package/src/utils/cognito-session.ts +1 -1
  93. package/src/utils/sandbox-runner-client.test.ts +128 -0
  94. package/src/utils/sandbox-runner-client.ts +100 -4
  95. package/src/utils/version-check.test.ts +30 -0
  96. package/src/utils/version-check.ts +72 -0
  97. package/test/commands/db-tenant-isolation.test.ts +94 -0
  98. package/test/commands/db.test.ts +85 -0
@@ -0,0 +1,229 @@
1
+
2
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="a4a2bf8b-0a33-57ba-a565-412a14132c99")}catch(e){}}();
3
+ import chalk from "chalk";
4
+ import * as fs from "fs";
5
+ import * as path from "path";
6
+ import * as yaml from "js-yaml";
7
+ import { ensureCognitoToken } from "../utils/cognito-session.js";
8
+ import { vaultApiFetch, getCompanyUid } from "./secrets.js";
9
+ import { GROUP_ID_PATTERN, EMAIL_PATTERN, normalizeFilePrefix } from "./_patterns.js";
10
+ import { findHqRoot } from "../utils/manifest.js";
11
+ /** Read + parse the worker registry. Empty array if it does not exist. */
12
+ export function readWorkerRegistry(hqRoot) {
13
+ const p = path.join(hqRoot, "core/workers/registry.yaml");
14
+ if (!fs.existsSync(p))
15
+ return [];
16
+ const doc = yaml.load(fs.readFileSync(p, "utf8"));
17
+ return doc?.workers ?? [];
18
+ }
19
+ /**
20
+ * Best-effort active company: workspace/sessions/.current -> meta.yaml
21
+ * company_slug. Undefined when no session context is set. Pure/read-only.
22
+ */
23
+ export function resolveActiveCompany(hqRoot) {
24
+ try {
25
+ const currentFile = path.join(hqRoot, "workspace/sessions/.current");
26
+ const current = fs.readFileSync(currentFile, "utf8").trim();
27
+ if (!current)
28
+ return undefined;
29
+ const metaPath = path.join(hqRoot, "workspace/sessions", current, "meta.yaml");
30
+ if (!fs.existsSync(metaPath))
31
+ return undefined;
32
+ const meta = yaml.load(fs.readFileSync(metaPath, "utf8"));
33
+ const co = meta?.company_slug;
34
+ return typeof co === "string" && co ? co : undefined;
35
+ }
36
+ catch {
37
+ return undefined;
38
+ }
39
+ }
40
+ /**
41
+ * Membership-aware access filter for worker discovery: public workers always;
42
+ * company workers only for the active company. Mirrors the /run skill and the
43
+ * inject-worker-suggestion hook so all three surfaces agree.
44
+ */
45
+ export function filterAccessibleWorkers(workers, activeCompany) {
46
+ return workers.filter((w) => {
47
+ if (w.visibility === "public")
48
+ return true;
49
+ if (!w.company)
50
+ return false;
51
+ return activeCompany !== undefined && w.company === activeCompany;
52
+ });
53
+ }
54
+ /**
55
+ * The company-relative vault prefix for a worker, e.g.
56
+ * companies/indigo/workers/deal-brain/ -> workers/deal-brain/. Returns null for
57
+ * a worker with no company (public/shared — not shareable via ACL).
58
+ */
59
+ export function workerVaultPrefix(w) {
60
+ if (!w.company)
61
+ return null;
62
+ const companyRoot = `companies/${w.company}/`;
63
+ const rel = w.path.startsWith(companyRoot)
64
+ ? w.path.slice(companyRoot.length)
65
+ : w.path;
66
+ return normalizeFilePrefix(rel);
67
+ }
68
+ /** Classify a share principal (@all | email | grp_*) — null when invalid. */
69
+ export function classifyPrincipal(principal) {
70
+ if (principal === "@all") {
71
+ return { granteeType: "company-wide", granteeId: "", label: "everyone in the company" };
72
+ }
73
+ if (EMAIL_PATTERN.test(principal)) {
74
+ const id = principal.trim().toLowerCase();
75
+ return { granteeType: "email", granteeId: id, label: id };
76
+ }
77
+ if (GROUP_ID_PATTERN.test(principal)) {
78
+ return { granteeType: "group", granteeId: principal, label: principal };
79
+ }
80
+ return null;
81
+ }
82
+ /**
83
+ * Record a grant locally in the worker's tool-owned .grants.yaml sidecar. Kept
84
+ * out of worker.yaml so we never rewrite a hand-authored file; the registry
85
+ * generator unions this sidecar into the registry `grants:` field. Idempotent.
86
+ */
87
+ export function writeGrantSidecar(hqRoot, workerPath, principalLabel) {
88
+ const dir = path.join(hqRoot, workerPath);
89
+ const sidecar = path.join(dir, ".grants.yaml");
90
+ let grants = [];
91
+ if (fs.existsSync(sidecar)) {
92
+ const doc = yaml.load(fs.readFileSync(sidecar, "utf8"));
93
+ if (Array.isArray(doc?.grants))
94
+ grants = doc.grants.filter((g) => typeof g === "string");
95
+ }
96
+ if (!grants.includes(principalLabel))
97
+ grants.push(principalLabel);
98
+ const header = "# Worker access grants — tool-owned, written by `hq workers share`.\n" +
99
+ "# Unioned into core/workers/registry.yaml `grants:` by the registry generator.\n";
100
+ fs.writeFileSync(sidecar, header + yaml.dump({ grants }), "utf8");
101
+ }
102
+ async function runWorkersShare(workerId, opts) {
103
+ const hqRoot = findHqRoot();
104
+ const worker = readWorkerRegistry(hqRoot).find((w) => w.id === workerId);
105
+ if (!worker) {
106
+ console.error(chalk.red(`Worker '${workerId}' not found in registry.`), "\nRun 'hq workers list' to see accessible workers.");
107
+ process.exit(1);
108
+ }
109
+ const prefix = workerVaultPrefix(worker);
110
+ if (!prefix) {
111
+ console.error(chalk.red(`'${workerId}' is a shared/public worker (visibility ${worker.visibility}).`), "\nPublic workers already ship to every HQ install — only company-scoped workers are shared with `hq workers share`.");
112
+ process.exit(1);
113
+ }
114
+ const permission = opts.permission ?? "read";
115
+ if (!["read", "write"].includes(permission)) {
116
+ console.error(chalk.red(`Invalid permission '${permission}': must be read or write`));
117
+ process.exit(1);
118
+ }
119
+ const classified = classifyPrincipal(opts.with);
120
+ if (!classified) {
121
+ console.error(chalk.red(`Invalid principal '${opts.with}': must be '@all', an email address, or a group id matching grp_<alphanumeric>`));
122
+ process.exit(1);
123
+ }
124
+ const companySlug = opts.company ?? worker.company;
125
+ const token = await ensureCognitoToken();
126
+ const companyUid = await getCompanyUid(token, companySlug);
127
+ const body = {
128
+ prefix,
129
+ granteeType: classified.granteeType,
130
+ granteeId: classified.granteeId,
131
+ permission,
132
+ };
133
+ let res = await vaultApiFetch({
134
+ token,
135
+ path: `/files/${encodeURIComponent(companyUid)}/acl/grant`,
136
+ method: "POST",
137
+ body,
138
+ });
139
+ // No ACL row for this prefix yet — auto-create one with this grant.
140
+ if (res.status === 404) {
141
+ res = await vaultApiFetch({
142
+ token,
143
+ path: `/files/${encodeURIComponent(companyUid)}/acl`,
144
+ method: "POST",
145
+ body: {
146
+ prefix,
147
+ entries: [
148
+ {
149
+ granteeType: classified.granteeType,
150
+ granteeId: classified.granteeId,
151
+ permission,
152
+ },
153
+ ],
154
+ },
155
+ });
156
+ }
157
+ if (!res.ok) {
158
+ const text = await res.text().catch(() => "");
159
+ console.error(chalk.red(`Failed to share worker (HTTP ${res.status}). ${text}`));
160
+ process.exit(1);
161
+ }
162
+ writeGrantSidecar(hqRoot, worker.path, classified.label);
163
+ console.log(chalk.green("✓"), `Shared worker '${workerId}' with ${classified.label} (${permission}).`);
164
+ console.log(chalk.dim(` Vault prefix ${prefix} granted in company '${companySlug}'. It will sync to granted members and appear in their /run list.`));
165
+ }
166
+ function runWorkersList(opts) {
167
+ const hqRoot = findHqRoot();
168
+ const activeCompany = opts.company ?? resolveActiveCompany(hqRoot);
169
+ let workers = filterAccessibleWorkers(readWorkerRegistry(hqRoot), activeCompany);
170
+ if (opts.shared)
171
+ workers = workers.filter((w) => Boolean(w.grants && w.grants.trim()));
172
+ if (opts.mine)
173
+ workers = workers.filter((w) => Boolean(w.company) && w.company === activeCompany);
174
+ if (workers.length === 0) {
175
+ console.log("No accessible workers.");
176
+ return;
177
+ }
178
+ const publicWorkers = workers.filter((w) => w.visibility === "public");
179
+ const companyWorkers = workers.filter((w) => w.visibility !== "public");
180
+ console.log(chalk.bold("Available Workers:"));
181
+ const printGroup = (title, list) => {
182
+ if (list.length === 0)
183
+ return;
184
+ console.log(`\n ${chalk.cyan(title)}:`);
185
+ for (const w of list.sort((a, b) => a.id.localeCompare(b.id))) {
186
+ const desc = (w.description ?? "").slice(0, 72);
187
+ const shared = w.grants && w.grants.trim() ? chalk.dim(` [shared: ${w.grants}]`) : "";
188
+ console.log(` ${w.id.padEnd(24)} ${desc}${shared}`);
189
+ }
190
+ };
191
+ printGroup("Public", publicWorkers);
192
+ if (activeCompany)
193
+ printGroup(activeCompany, companyWorkers);
194
+ console.log(chalk.dim("\nUsage: hq run {worker-id} [skill] [args]"));
195
+ console.log(chalk.dim("Share a company worker: hq workers share {worker-id} --with {grp_<name>|@all} --permission read"));
196
+ }
197
+ export function registerWorkersCommand(program) {
198
+ const workers = program
199
+ .command("workers")
200
+ .description("Discover and share HQ workers")
201
+ .option("--company <slug>", "Company slug (resolves to companyUid)");
202
+ workers
203
+ .command("list")
204
+ .description("List workers you can access (public + your active company's)")
205
+ .option("--mine", "Only this company's workers")
206
+ .option("--shared", "Only workers that have been shared with someone")
207
+ .action((opts) => {
208
+ runWorkersList({ ...opts, company: workers.opts().company });
209
+ });
210
+ workers
211
+ .command("share <workerId>")
212
+ .description("Grant a teammate, group, or @all access to a company worker")
213
+ .requiredOption("--with <principal>", "Email address, group id (grp_<name>), or '@all' to share with every active company member")
214
+ .option("--permission <level>", "Permission level: read | write (default: read)")
215
+ .action(async (workerId, opts) => {
216
+ try {
217
+ await runWorkersShare(workerId, {
218
+ ...opts,
219
+ company: workers.opts().company,
220
+ });
221
+ }
222
+ catch (err) {
223
+ console.error(chalk.red("Error:"), err instanceof Error ? err.message : String(err));
224
+ process.exit(1);
225
+ }
226
+ });
227
+ }
228
+ //# sourceMappingURL=workers.js.map
229
+ //# debugId=a4a2bf8b-0a33-57ba-a565-412a14132c99
package/dist/index.d.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  #!/usr/bin/env node
2
- /**
3
- * HQ CLI - Module management, package management, and cloud sync for HQ
4
- */
5
2
  import "./node-preflight.js";
3
+ declare function isVersionRequest(argv: readonly string[]): boolean;
4
+ export declare const __test__: {
5
+ isVersionRequest: typeof isVersionRequest;
6
+ };
7
+ export {};
6
8
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,247 +1,21 @@
1
1
  #!/usr/bin/env node
2
- /**
3
- * HQ CLI - Module management, package management, and cloud sync for HQ
4
- */
5
2
  // MUST be first: guard the Node version before any dependency that needs a
6
3
  // Node 20+ API (e.g. util.styleText) or a newer native ABI is evaluated.
7
4
 
8
- !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="8839ee7d-9f6d-54fe-8f90-99ad858e349e")}catch(e){}}();
5
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="8fdfd788-4c00-50bc-9ed0-579ed9d5f903")}catch(e){}}();
9
6
  import "./node-preflight.js";
10
- import { Command } from "commander";
11
- import { initSentry, Sentry } from "./sentry.js";
12
- import { registerAddCommand } from "./commands/add.js";
13
- import { registerSyncCommand } from "./commands/sync.js";
14
- import { registerListCommand } from "./commands/list.js";
15
- import { registerUpdateCommand } from "./commands/update.js";
16
- import { registerCloudCommands } from "./commands/cloud.js";
17
- import { registerSyncModeCommand } from "./commands/sync-mode.js";
18
- import { registerSyncNarrowCommand } from "./commands/sync-narrow.js";
19
- import { registerCloudProvisionCommands } from "./commands/cloud-provision.js";
20
- import { registerCloudDemoteCommands } from "./commands/cloud-demote.js";
21
- import { registerLoginCommand } from "./commands/login.js";
22
- import { registerLogoutCommand } from "./commands/logout.js";
23
- import { registerWhoamiCommand } from "./commands/whoami.js";
24
- import { registerOnboardCommand } from "./commands/onboard.js";
25
- import { registerPackageInstallCommand } from "./commands/pkg-install.js";
26
- import { registerPackageRemoveCommand } from "./commands/pkg-remove.js";
27
- import { registerPackageUpdateCommand } from "./commands/pkg-update.js";
28
- import { registerPackageListCommand } from "./commands/pkg-list.js";
29
- import { registerPacksCommand } from "./commands/packs.js";
30
- import { registerPublishCommand } from "./commands/publish.js";
31
- import { registerCreatorsCommand } from "./commands/creators.js";
32
- import { registerTeamSyncCommand } from "./commands/team-sync.js";
33
- import { registerAuthCommands } from "./commands/auth.js";
34
- import { registerApiKeysCommand } from "./commands/api-keys.js";
35
- import { registerSecretsCommand } from "./commands/secrets.js";
36
- import { registerRunCommand } from "./commands/run.js";
37
- import { registerGroupsCommand } from "./commands/groups.js";
38
- import { registerGroupGrantsCommand } from "./commands/group-grants.js";
39
- import { registerFilesCommand } from "./commands/files.js";
40
- import { registerFilesBrowseCommands } from "./commands/files-browse.js";
41
- import { registerMembersCommand } from "./commands/members.js";
42
- import { registerPeopleCommand } from "./commands/people.js";
43
- import { registerDmCommand } from "./commands/dm.js";
44
- import { registerChannelsCommand } from "./commands/channels.js";
45
- import { registerFeedbackCommand } from "./commands/feedback.js";
46
- import { registerMeetingsCommand } from "./commands/meetings.js";
47
- import { registerSourcesCommand } from "./commands/sources.js";
48
- import { registerSignalsCommand } from "./commands/signals.js";
49
- import { registerReindexCommand } from "./commands/reindex.js";
50
- import { registerRescueCommand } from "./commands/rescue.js";
51
- import { registerMcpCommand } from "./commands/mcp-status.js";
52
- import { registerCrmCommand } from "./commands/crm.js";
53
- import { registerCompanyCommand } from "./commands/company.js";
54
- import { sanitizeArgv } from "./utils/feedback-diagnostics.js";
55
- import { environmentalFsErrorMessage } from "./utils/environmental-error.js";
56
- import { isEpipe } from "./utils/epipe.js";
57
- import { isInterceptedProcessExit } from "./utils/intercepted-process-exit.js";
58
- import { maybeWarnNewVersion, refreshVersionCache, } from "./utils/version-check.js";
59
- import { enforceVersionGate, shouldSkipGate, } from "./utils/version-gate.js";
60
7
  import { CLI_VERSION } from "./cli-version.js";
61
- // Swallow EPIPE when a downstream reader (e.g. `source <(…)`, `| head`) closes
62
- // the pipe early. This covers the ASYNC path — an 'error' event emitted on the
63
- // stream. The SYNCHRONOUS path (a `write EPIPE` thrown straight out of
64
- // console.log inside a command) is handled in the top-level catch below; both
65
- // share `isEpipe` (HQ-6B).
66
- const onPipeError = (err) => {
67
- if (isEpipe(err)) {
68
- process.exit(0);
69
- }
70
- throw err;
71
- };
72
- process.stdout.on("error", onPipeError);
73
- process.stderr.on("error", onPipeError);
74
- initSentry();
75
- maybeWarnNewVersion();
76
- const program = new Command();
77
- program
78
- .name("hq")
79
- .description("HQ management CLI — modules, packages, and cloud sync")
80
- .version(CLI_VERSION);
81
- // Module management subcommand group
82
- const modulesCmd = program
83
- .command("modules")
84
- .description("Module management commands");
85
- registerAddCommand(modulesCmd);
86
- registerSyncCommand(modulesCmd);
87
- registerListCommand(modulesCmd);
88
- registerUpdateCommand(modulesCmd);
89
- // Package management subcommand group
90
- const packagesCmd = program
91
- .command("packages")
92
- .description("Package management commands");
93
- registerPackageInstallCommand(packagesCmd);
94
- registerPackageRemoveCommand(packagesCmd);
95
- registerPackageUpdateCommand(packagesCmd);
96
- registerPackageListCommand(packagesCmd);
97
- // Content-pack lifecycle (core/packages/hq-pack-*). Distinct from the registry
98
- // `packages` system above. Available as both `hq packages packs …` (grouped)
99
- // and `hq packs …` (top-level convenience).
100
- registerPacksCommand(packagesCmd);
101
- registerPacksCommand(program);
102
- // Top-level shortcuts for package commands
103
- // "hq install <slug>" = "hq packages install <slug>"
104
- // "hq remove <slug>" = "hq packages remove <slug>"
105
- registerPackageInstallCommand(program);
106
- registerPackageRemoveCommand(program);
107
- // Marketplace publish (top-level — packer + authenticated upload, US-004)
108
- // "hq publish <skill-or-worker-path>" packages and submits a pack to the
109
- // marketplace via POST /v1/listings.
110
- registerPublishCommand(program);
111
- // `hq creators apply` — request verified-creator access (required to publish).
112
- registerCreatorsCommand(program);
113
- // Cloud sync subcommand group
114
- const syncCmd = program
115
- .command("sync")
116
- .description("Cloud sync commands — sync HQ to S3 for mobile access");
117
- registerCloudCommands(syncCmd);
118
- registerSyncModeCommand(syncCmd);
119
- registerSyncNarrowCommand(syncCmd);
120
- // Cloud provisioning subcommand group (entity + bucket + initial sync)
121
- // Distinct from `hq sync` which assumes provisioning has already happened.
122
- const cloudCmd = program
123
- .command("cloud")
124
- .description("Cloud commands — provision entities and manage cloud-backed companies");
125
- registerCloudProvisionCommands(cloudCmd);
126
- registerCloudDemoteCommands(cloudCmd);
127
- // Team commands (top-level)
128
- registerTeamSyncCommand(program);
129
- // Auth commands (top-level — Cognito OAuth)
130
- registerLoginCommand(program);
131
- registerLogoutCommand(program);
132
- registerWhoamiCommand(program);
133
- registerAuthCommands(program);
134
- // Secrets management (subcommand group — hq secrets set|get|list|delete|exec|generate-link|cache)
135
- registerSecretsCommand(program);
136
- // API key management (subcommand group — hq api-keys create|list|revoke)
137
- registerApiKeysCommand(program);
138
- // Schema-driven dev runner — hq run [options] -- <cmd>
139
- registerRunCommand(program);
140
- // Groups management (subcommand group — hq groups create|delete|add|remove|list|members)
141
- registerGroupsCommand(program);
142
- // Cross-company group grants (subcommand group —
143
- // hq group-grants grant|revoke|outbound|inbound)
144
- registerGroupGrantsCommand(program);
145
- // Files ACL management (subcommand group — hq files share|unshare|acl)
146
- // `registerFilesCommand` returns the `files` group so we can attach the
147
- // browse-vs-sync subcommands (`hq files browse`/`cat`) onto the same group.
148
- const filesCmd = registerFilesCommand(program);
149
- registerFilesBrowseCommands(filesCmd);
150
- // Membership management (subcommand group — hq members invite|list|revoke)
151
- registerMembersCommand(program);
152
- // People directory (subcommand group — hq people list|search|resolve), reading
153
- // the local companies/<co>/people store scoped to one company.
154
- registerPeopleCommand(program);
155
- registerDmCommand(program);
156
- registerChannelsCommand(program);
157
- // Onboarding (top-level — Cognito + vault-service provisioning)
158
- registerOnboardCommand(program);
159
- // Feedback (subcommand group — hq feedback bug|feature)
160
- registerFeedbackCommand(program);
161
- // Meetings (subcommand group — hq meetings list|get|search|transcript|notes)
162
- registerMeetingsCommand(program);
163
- // Sources read surface (subcommand group — hq sources list|get|channels|entities)
164
- registerSourcesCommand(program);
165
- // Signals read surface (subcommand group — hq signals list|get|types|entities)
166
- registerSignalsCommand(program);
167
- // Skill/personal-overlay mirroring + workers-registry regen. Invoked by the
168
- // hq-core reindex hook shim (Stop / PostToolUse) and by sync()/rescue() after
169
- // they change on-disk sources. Keeps a `master-sync` alias for one release.
170
- // Implementation lives in @indigoai-us/hq-cloud.
171
- registerReindexCommand(program);
172
- // Drift-preserving HQ-core re-sync (top-level — `hq rescue`). CLI sibling of
173
- // the HQ Sync app's "Update / Restore" pill; drives the same replace-rescue.sh
174
- // shipped from @indigoai-us/hq-cloud.
175
- registerRescueCommand(program);
176
- // MCP pack observability (subcommand group — `hq mcp status`). Read-only
177
- // provenance-based status across BOTH Claude + Codex runtimes (reads `_hqPack`
178
- // off the configs, NOT linkStatus), with secret-redacted output + `--json`.
179
- registerMcpCommand(program);
180
- // Native CRM entity upsert (subcommand group — `hq crm entity upsert`). Wraps
181
- // POST /crm/entities (the ontology write gate) so an authenticated company
182
- // member can create/update canonical CRM entities in the company vault.
183
- registerCrmCommand(program);
184
- // Company settings (subcommand group — `hq company settings set`). Owner-only
185
- // toggles for crmEnabled / ontologyEnabled via PUT /company-settings.
186
- registerCompanyCommand(program);
187
- (async () => {
188
- try {
189
- Sentry.addBreadcrumb({
190
- category: "command",
191
- message: sanitizeArgv(process.argv.slice(2)).join(" "),
192
- level: "info",
193
- });
194
- // Hard version gate: ask hq-pro whether this CLI is below the floor and
195
- // auto-update if so (exits the process on update). Skipped for inspection
196
- // flags (`--version`, `--help`) so users debugging a broken install can
197
- // still introspect what they have. Silent on any failure — never blocks
198
- // the CLI on a flaky network or hq-pro hiccup. See `utils/version-gate.ts`.
199
- if (!shouldSkipGate(process.argv)) {
200
- await enforceVersionGate();
201
- }
202
- await program.parseAsync();
203
- }
204
- catch (err) {
205
- // A broken pipe (EPIPE) means the reader of `hq`'s output closed it early
206
- // (`hq … | head`, `source <(hq …)`, a parent that exited). That is normal
207
- // Unix behavior with no user-facing degradation — exit cleanly (0) and
208
- // skip Sentry capture instead of shipping a fatal (HQ-6B). A synchronous
209
- // `write EPIPE` thrown out of console.log lands here rather than on the
210
- // stream 'error' listener above.
211
- if (isEpipe(err)) {
212
- process.exitCode = 0;
213
- }
214
- else if (isInterceptedProcessExit(err)) {
215
- // A security/audit FUZZ harness replaced `process.exit` with a throw so it
216
- // can keep exercising the binary. Commander calling `process.exit` for
217
- // normal CLI control flow (e.g. an unknown command → exit 1) then surfaces
218
- // here as that synthetic marker. It is a test-harness artifact, NOT an
219
- // hq-cli defect — a real user's `process.exit` just exits, so nothing is
220
- // thrown or captured. Skip Sentry capture (no signal, no user-facing
221
- // degradation) and preserve the intended non-zero exit (HQ-CLI-3).
222
- process.exitCode = 1;
223
- }
224
- else {
225
- // A full disk / exhausted quota / read-only filesystem is the user's
226
- // machine, not an HQ code defect. Surface a clear, actionable message and
227
- // skip Sentry capture so one full disk doesn't flood the tracker with
228
- // identical, unfixable crash reports (HQ-CLI-2). Genuine errors still go
229
- // to Sentry and still exit 1.
230
- const envMsg = environmentalFsErrorMessage(err);
231
- if (envMsg) {
232
- process.stderr.write(`hq: ${envMsg}\n`);
233
- }
234
- else {
235
- Sentry.captureException(err);
236
- }
237
- process.exitCode = 1;
238
- }
239
- }
240
- finally {
241
- // Release health: finalize the per-run session before the flush.
242
- Sentry.endSession();
243
- await Promise.allSettled([refreshVersionCache(), Sentry.flush(2000)]);
244
- }
245
- })();
8
+ function isVersionRequest(argv) {
9
+ const args = argv.slice(2);
10
+ return args.length === 1 && (args[0] === "--version" || args[0] === "-V" || args[0] === "-v");
11
+ }
12
+ if (isVersionRequest(process.argv)) {
13
+ process.stdout.write(`${CLI_VERSION}\n`);
14
+ }
15
+ else {
16
+ const { runCli } = await import("./main.js");
17
+ await runCli();
18
+ }
19
+ export const __test__ = { isVersionRequest };
246
20
  //# sourceMappingURL=index.js.map
247
- //# debugId=8839ee7d-9f6d-54fe-8f90-99ad858e349e
21
+ //# debugId=8fdfd788-4c00-50bc-9ed0-579ed9d5f903
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Control-plane client for remote vault DB (US-009).
3
+ * Injectable fetch for tests — never logs response bodies that might hold secrets.
4
+ */
5
+ export interface RemoteProvisionResponse {
6
+ ok: boolean;
7
+ companyUid: string;
8
+ companySlug: string;
9
+ engineId: string;
10
+ resourceArn: string;
11
+ region: string;
12
+ status: string;
13
+ secretRef: string;
14
+ idempotent: boolean;
15
+ }
16
+ export interface RemoteStatusResponse {
17
+ companyUid: string;
18
+ companySlug?: string;
19
+ remote: {
20
+ engineId: string;
21
+ resourceArn: string;
22
+ region: string;
23
+ status: string;
24
+ secretRef: string;
25
+ } | null;
26
+ }
27
+ export interface ControlPlaneClientOptions {
28
+ baseUrl: string;
29
+ /** Bearer access token */
30
+ getAccessToken: () => Promise<string>;
31
+ fetchImpl?: typeof fetch;
32
+ }
33
+ export declare class ControlPlaneDbClient {
34
+ private readonly baseUrl;
35
+ private readonly getAccessToken;
36
+ private readonly fetchImpl;
37
+ constructor(opts: ControlPlaneClientOptions);
38
+ provision(input: {
39
+ companyUid: string;
40
+ companySlug: string;
41
+ region?: string;
42
+ }): Promise<RemoteProvisionResponse>;
43
+ status(companyUid: string): Promise<RemoteStatusResponse>;
44
+ }
45
+ //# sourceMappingURL=control-plane.d.ts.map
@@ -0,0 +1,81 @@
1
+ /**
2
+ * Control-plane client for remote vault DB (US-009).
3
+ * Injectable fetch for tests — never logs response bodies that might hold secrets.
4
+ */
5
+
6
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="b2bf60fc-6b3a-5534-af8e-3b92b9518e29")}catch(e){}}();
7
+ function assertNoPostgresUrl(label, text) {
8
+ if (/postgres:\/\//i.test(text) || /postgresql:\/\//i.test(text)) {
9
+ throw new Error(`${label}: control plane returned a connection string (refusing to surface)`);
10
+ }
11
+ }
12
+ export class ControlPlaneDbClient {
13
+ baseUrl;
14
+ getAccessToken;
15
+ fetchImpl;
16
+ constructor(opts) {
17
+ this.baseUrl = opts.baseUrl.replace(/\/$/, "");
18
+ this.getAccessToken = opts.getAccessToken;
19
+ this.fetchImpl = opts.fetchImpl ?? fetch;
20
+ }
21
+ async provision(input) {
22
+ const token = await this.getAccessToken();
23
+ const res = await this.fetchImpl(`${this.baseUrl}/v1/db/provision`, {
24
+ method: "POST",
25
+ headers: {
26
+ Authorization: `Bearer ${token}`,
27
+ "Content-Type": "application/json",
28
+ },
29
+ body: JSON.stringify(input),
30
+ });
31
+ const text = await res.text();
32
+ assertNoPostgresUrl("provision", text);
33
+ if (!res.ok) {
34
+ let msg = `provision failed (${res.status})`;
35
+ let code;
36
+ try {
37
+ const j = JSON.parse(text);
38
+ if (j.error)
39
+ msg = j.error;
40
+ if (j.code)
41
+ code = j.code;
42
+ }
43
+ catch {
44
+ /* keep */
45
+ }
46
+ const err = new Error(msg);
47
+ err.status = res.status;
48
+ if (code)
49
+ err.code = code;
50
+ throw err;
51
+ }
52
+ return JSON.parse(text);
53
+ }
54
+ async status(companyUid) {
55
+ const token = await this.getAccessToken();
56
+ const url = `${this.baseUrl}/v1/db/status?companyUid=${encodeURIComponent(companyUid)}`;
57
+ const res = await this.fetchImpl(url, {
58
+ method: "GET",
59
+ headers: { Authorization: `Bearer ${token}` },
60
+ });
61
+ const text = await res.text();
62
+ assertNoPostgresUrl("status", text);
63
+ if (!res.ok) {
64
+ let msg = `status failed (${res.status})`;
65
+ try {
66
+ const j = JSON.parse(text);
67
+ if (j.error)
68
+ msg = j.error;
69
+ }
70
+ catch {
71
+ /* keep */
72
+ }
73
+ const err = new Error(msg);
74
+ err.status = res.status;
75
+ throw err;
76
+ }
77
+ return JSON.parse(text);
78
+ }
79
+ }
80
+ //# sourceMappingURL=control-plane.js.map
81
+ //# debugId=b2bf60fc-6b3a-5534-af8e-3b92b9518e29