@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,158 @@
1
+ /**
2
+ * Unit tests for `hq workers` (workers.ts).
3
+ *
4
+ * Coverage:
5
+ * - readWorkerRegistry — parses registry.yaml, empty when missing
6
+ * - filterAccessibleWorkers — public always; company only for active company
7
+ * - workerVaultPrefix — companies/{co}/workers/{id}/ -> workers/{id}/; null for public
8
+ * - classifyPrincipal — @all | email | grp_ | invalid
9
+ * - resolveActiveCompany — reads .current -> meta.yaml company_slug
10
+ * - writeGrantSidecar — creates + unions .grants.yaml idempotently
11
+ */
12
+
13
+ import { afterEach, beforeEach, describe, expect, it } from "vitest";
14
+ import * as fs from "fs";
15
+ import * as os from "os";
16
+ import * as path from "path";
17
+ import * as yaml from "js-yaml";
18
+ import {
19
+ readWorkerRegistry,
20
+ filterAccessibleWorkers,
21
+ workerVaultPrefix,
22
+ classifyPrincipal,
23
+ resolveActiveCompany,
24
+ writeGrantSidecar,
25
+ type RegistryWorker,
26
+ } from "./workers.js";
27
+
28
+ let hqRoot: string;
29
+
30
+ function writeRegistry(workers: RegistryWorker[]): void {
31
+ const p = path.join(hqRoot, "core/workers/registry.yaml");
32
+ fs.mkdirSync(path.dirname(p), { recursive: true });
33
+ fs.writeFileSync(p, yaml.dump({ version: "5.1", workers }), "utf8");
34
+ }
35
+
36
+ const pub: RegistryWorker = {
37
+ id: "architect",
38
+ path: "core/workers/public/dev-team/architect/",
39
+ type: "CodeWorker",
40
+ visibility: "public",
41
+ description: "System design",
42
+ };
43
+ const indigo: RegistryWorker = {
44
+ id: "deal-brain",
45
+ path: "companies/indigo/workers/deal-brain/",
46
+ type: "OpsWorker",
47
+ visibility: "private",
48
+ company: "indigo",
49
+ description: "GTM teammate",
50
+ };
51
+ const amass: RegistryWorker = {
52
+ id: "gtm-refresh",
53
+ path: "companies/amass/workers/gtm-refresh/",
54
+ type: "OpsWorker",
55
+ visibility: "private",
56
+ company: "amass",
57
+ description: "Depletions",
58
+ };
59
+
60
+ beforeEach(() => {
61
+ hqRoot = fs.mkdtempSync(path.join(os.tmpdir(), "hq-workers-"));
62
+ });
63
+ afterEach(() => {
64
+ fs.rmSync(hqRoot, { recursive: true, force: true });
65
+ });
66
+
67
+ describe("readWorkerRegistry", () => {
68
+ it("returns [] when the registry does not exist", () => {
69
+ expect(readWorkerRegistry(hqRoot)).toEqual([]);
70
+ });
71
+ it("parses the workers list", () => {
72
+ writeRegistry([pub, indigo]);
73
+ const got = readWorkerRegistry(hqRoot);
74
+ expect(got.map((w) => w.id)).toEqual(["architect", "deal-brain"]);
75
+ });
76
+ });
77
+
78
+ describe("filterAccessibleWorkers", () => {
79
+ it("always includes public workers", () => {
80
+ expect(filterAccessibleWorkers([pub], undefined).map((w) => w.id)).toEqual(["architect"]);
81
+ });
82
+ it("includes company workers only for the active company", () => {
83
+ const got = filterAccessibleWorkers([pub, indigo, amass], "indigo").map((w) => w.id);
84
+ expect(got).toEqual(["architect", "deal-brain"]);
85
+ expect(got).not.toContain("gtm-refresh");
86
+ });
87
+ it("excludes all company workers when no active company", () => {
88
+ expect(filterAccessibleWorkers([pub, indigo, amass], undefined).map((w) => w.id)).toEqual([
89
+ "architect",
90
+ ]);
91
+ });
92
+ });
93
+
94
+ describe("workerVaultPrefix", () => {
95
+ it("maps a company worker path to a company-relative glob prefix (covers everything under the worker dir)", () => {
96
+ expect(workerVaultPrefix(indigo)).toBe("workers/deal-brain/*");
97
+ });
98
+ it("returns null for a public worker", () => {
99
+ expect(workerVaultPrefix(pub)).toBeNull();
100
+ });
101
+ });
102
+
103
+ describe("classifyPrincipal", () => {
104
+ it("classifies @all as company-wide with empty granteeId", () => {
105
+ expect(classifyPrincipal("@all")).toEqual({
106
+ granteeType: "company-wide",
107
+ granteeId: "",
108
+ label: "everyone in the company",
109
+ });
110
+ });
111
+ it("lowercases emails", () => {
112
+ expect(classifyPrincipal("Me@Co.com")).toEqual({
113
+ granteeType: "email",
114
+ granteeId: "me@co.com",
115
+ label: "me@co.com",
116
+ });
117
+ });
118
+ it("accepts group ids", () => {
119
+ expect(classifyPrincipal("grp_finance")).toEqual({
120
+ granteeType: "group",
121
+ granteeId: "grp_finance",
122
+ label: "grp_finance",
123
+ });
124
+ });
125
+ it("rejects invalid principals", () => {
126
+ expect(classifyPrincipal("not-a-principal")).toBeNull();
127
+ expect(classifyPrincipal("grp_")).toBeNull();
128
+ });
129
+ });
130
+
131
+ describe("resolveActiveCompany", () => {
132
+ it("undefined when no session pointer", () => {
133
+ expect(resolveActiveCompany(hqRoot)).toBeUndefined();
134
+ });
135
+ it("reads company_slug from the current session meta", () => {
136
+ const sess = "sess-123";
137
+ fs.mkdirSync(path.join(hqRoot, "workspace/sessions", sess), { recursive: true });
138
+ fs.writeFileSync(path.join(hqRoot, "workspace/sessions/.current"), sess);
139
+ fs.writeFileSync(
140
+ path.join(hqRoot, "workspace/sessions", sess, "meta.yaml"),
141
+ "company_slug: indigo\n",
142
+ );
143
+ expect(resolveActiveCompany(hqRoot)).toBe("indigo");
144
+ });
145
+ });
146
+
147
+ describe("writeGrantSidecar", () => {
148
+ it("creates .grants.yaml with the principal, then unions idempotently", () => {
149
+ fs.mkdirSync(path.join(hqRoot, indigo.path), { recursive: true });
150
+ writeGrantSidecar(hqRoot, indigo.path, "grp_finance");
151
+ writeGrantSidecar(hqRoot, indigo.path, "grp_finance"); // idempotent
152
+ writeGrantSidecar(hqRoot, indigo.path, "me@co.com");
153
+ const doc = yaml.load(
154
+ fs.readFileSync(path.join(hqRoot, indigo.path, ".grants.yaml"), "utf8"),
155
+ ) as { grants: string[] };
156
+ expect(doc.grants).toEqual(["grp_finance", "me@co.com"]);
157
+ });
158
+ });
@@ -0,0 +1,298 @@
1
+ import { Command } from "commander";
2
+ import chalk from "chalk";
3
+ import * as fs from "fs";
4
+ import * as path from "path";
5
+ import * as yaml from "js-yaml";
6
+ import { ensureCognitoToken } from "../utils/cognito-session.js";
7
+ import { vaultApiFetch, getCompanyUid } from "./secrets.js";
8
+ import { GROUP_ID_PATTERN, EMAIL_PATTERN, normalizeFilePrefix } from "./_patterns.js";
9
+ import { findHqRoot } from "../utils/manifest.js";
10
+
11
+ // A worker entry as it appears in the auto-generated core/workers/registry.yaml.
12
+ export interface RegistryWorker {
13
+ id: string;
14
+ path: string;
15
+ type: string;
16
+ visibility: string;
17
+ company?: string;
18
+ team?: string;
19
+ status?: string;
20
+ description?: string;
21
+ triggers?: string;
22
+ grants?: string;
23
+ }
24
+
25
+ /** Read + parse the worker registry. Empty array if it does not exist. */
26
+ export function readWorkerRegistry(hqRoot: string): RegistryWorker[] {
27
+ const p = path.join(hqRoot, "core/workers/registry.yaml");
28
+ if (!fs.existsSync(p)) return [];
29
+ const doc = yaml.load(fs.readFileSync(p, "utf8")) as
30
+ | { workers?: RegistryWorker[] }
31
+ | null;
32
+ return doc?.workers ?? [];
33
+ }
34
+
35
+ /**
36
+ * Best-effort active company: workspace/sessions/.current -> meta.yaml
37
+ * company_slug. Undefined when no session context is set. Pure/read-only.
38
+ */
39
+ export function resolveActiveCompany(hqRoot: string): string | undefined {
40
+ try {
41
+ const currentFile = path.join(hqRoot, "workspace/sessions/.current");
42
+ const current = fs.readFileSync(currentFile, "utf8").trim();
43
+ if (!current) return undefined;
44
+ const metaPath = path.join(hqRoot, "workspace/sessions", current, "meta.yaml");
45
+ if (!fs.existsSync(metaPath)) return undefined;
46
+ const meta = yaml.load(fs.readFileSync(metaPath, "utf8")) as
47
+ | Record<string, unknown>
48
+ | null;
49
+ const co = meta?.company_slug;
50
+ return typeof co === "string" && co ? co : undefined;
51
+ } catch {
52
+ return undefined;
53
+ }
54
+ }
55
+
56
+ /**
57
+ * Membership-aware access filter for worker discovery: public workers always;
58
+ * company workers only for the active company. Mirrors the /run skill and the
59
+ * inject-worker-suggestion hook so all three surfaces agree.
60
+ */
61
+ export function filterAccessibleWorkers(
62
+ workers: RegistryWorker[],
63
+ activeCompany: string | undefined,
64
+ ): RegistryWorker[] {
65
+ return workers.filter((w) => {
66
+ if (w.visibility === "public") return true;
67
+ if (!w.company) return false;
68
+ return activeCompany !== undefined && w.company === activeCompany;
69
+ });
70
+ }
71
+
72
+ /**
73
+ * The company-relative vault prefix for a worker, e.g.
74
+ * companies/indigo/workers/deal-brain/ -> workers/deal-brain/. Returns null for
75
+ * a worker with no company (public/shared — not shareable via ACL).
76
+ */
77
+ export function workerVaultPrefix(w: RegistryWorker): string | null {
78
+ if (!w.company) return null;
79
+ const companyRoot = `companies/${w.company}/`;
80
+ const rel = w.path.startsWith(companyRoot)
81
+ ? w.path.slice(companyRoot.length)
82
+ : w.path;
83
+ return normalizeFilePrefix(rel);
84
+ }
85
+
86
+ export type GranteeType = "company-wide" | "email" | "group";
87
+
88
+ export interface ClassifiedPrincipal {
89
+ granteeType: GranteeType;
90
+ granteeId: string;
91
+ label: string;
92
+ }
93
+
94
+ /** Classify a share principal (@all | email | grp_*) — null when invalid. */
95
+ export function classifyPrincipal(principal: string): ClassifiedPrincipal | null {
96
+ if (principal === "@all") {
97
+ return { granteeType: "company-wide", granteeId: "", label: "everyone in the company" };
98
+ }
99
+ if (EMAIL_PATTERN.test(principal)) {
100
+ const id = principal.trim().toLowerCase();
101
+ return { granteeType: "email", granteeId: id, label: id };
102
+ }
103
+ if (GROUP_ID_PATTERN.test(principal)) {
104
+ return { granteeType: "group", granteeId: principal, label: principal };
105
+ }
106
+ return null;
107
+ }
108
+
109
+ /**
110
+ * Record a grant locally in the worker's tool-owned .grants.yaml sidecar. Kept
111
+ * out of worker.yaml so we never rewrite a hand-authored file; the registry
112
+ * generator unions this sidecar into the registry `grants:` field. Idempotent.
113
+ */
114
+ export function writeGrantSidecar(
115
+ hqRoot: string,
116
+ workerPath: string,
117
+ principalLabel: string,
118
+ ): void {
119
+ const dir = path.join(hqRoot, workerPath);
120
+ const sidecar = path.join(dir, ".grants.yaml");
121
+ let grants: string[] = [];
122
+ if (fs.existsSync(sidecar)) {
123
+ const doc = yaml.load(fs.readFileSync(sidecar, "utf8")) as
124
+ | { grants?: string[] }
125
+ | null;
126
+ if (Array.isArray(doc?.grants)) grants = doc!.grants.filter((g) => typeof g === "string");
127
+ }
128
+ if (!grants.includes(principalLabel)) grants.push(principalLabel);
129
+ const header =
130
+ "# Worker access grants — tool-owned, written by `hq workers share`.\n" +
131
+ "# Unioned into core/workers/registry.yaml `grants:` by the registry generator.\n";
132
+ fs.writeFileSync(sidecar, header + yaml.dump({ grants }), "utf8");
133
+ }
134
+
135
+ async function runWorkersShare(
136
+ workerId: string,
137
+ opts: { with: string; permission?: string; company?: string },
138
+ ): Promise<void> {
139
+ const hqRoot = findHqRoot();
140
+ const worker = readWorkerRegistry(hqRoot).find((w) => w.id === workerId);
141
+ if (!worker) {
142
+ console.error(
143
+ chalk.red(`Worker '${workerId}' not found in registry.`),
144
+ "\nRun 'hq workers list' to see accessible workers.",
145
+ );
146
+ process.exit(1);
147
+ }
148
+
149
+ const prefix = workerVaultPrefix(worker!);
150
+ if (!prefix) {
151
+ console.error(
152
+ chalk.red(`'${workerId}' is a shared/public worker (visibility ${worker!.visibility}).`),
153
+ "\nPublic workers already ship to every HQ install — only company-scoped workers are shared with `hq workers share`.",
154
+ );
155
+ process.exit(1);
156
+ }
157
+
158
+ const permission = opts.permission ?? "read";
159
+ if (!["read", "write"].includes(permission)) {
160
+ console.error(chalk.red(`Invalid permission '${permission}': must be read or write`));
161
+ process.exit(1);
162
+ }
163
+
164
+ const classified = classifyPrincipal(opts.with);
165
+ if (!classified) {
166
+ console.error(
167
+ chalk.red(
168
+ `Invalid principal '${opts.with}': must be '@all', an email address, or a group id matching grp_<alphanumeric>`,
169
+ ),
170
+ );
171
+ process.exit(1);
172
+ }
173
+
174
+ const companySlug = opts.company ?? worker!.company;
175
+ const token = await ensureCognitoToken();
176
+ const companyUid = await getCompanyUid(token, companySlug);
177
+
178
+ const body = {
179
+ prefix,
180
+ granteeType: classified!.granteeType,
181
+ granteeId: classified!.granteeId,
182
+ permission,
183
+ };
184
+ let res = await vaultApiFetch({
185
+ token,
186
+ path: `/files/${encodeURIComponent(companyUid)}/acl/grant`,
187
+ method: "POST",
188
+ body,
189
+ });
190
+ // No ACL row for this prefix yet — auto-create one with this grant.
191
+ if (res.status === 404) {
192
+ res = await vaultApiFetch({
193
+ token,
194
+ path: `/files/${encodeURIComponent(companyUid)}/acl`,
195
+ method: "POST",
196
+ body: {
197
+ prefix,
198
+ entries: [
199
+ {
200
+ granteeType: classified!.granteeType,
201
+ granteeId: classified!.granteeId,
202
+ permission,
203
+ },
204
+ ],
205
+ },
206
+ });
207
+ }
208
+ if (!res.ok) {
209
+ const text = await res.text().catch(() => "");
210
+ console.error(chalk.red(`Failed to share worker (HTTP ${res.status}). ${text}`));
211
+ process.exit(1);
212
+ }
213
+
214
+ writeGrantSidecar(hqRoot, worker!.path, classified!.label);
215
+
216
+ console.log(
217
+ chalk.green("✓"),
218
+ `Shared worker '${workerId}' with ${classified!.label} (${permission}).`,
219
+ );
220
+ console.log(
221
+ chalk.dim(
222
+ ` Vault prefix ${prefix} granted in company '${companySlug}'. It will sync to granted members and appear in their /run list.`,
223
+ ),
224
+ );
225
+ }
226
+
227
+ function runWorkersList(opts: { company?: string; mine?: boolean; shared?: boolean }): void {
228
+ const hqRoot = findHqRoot();
229
+ const activeCompany = opts.company ?? resolveActiveCompany(hqRoot);
230
+ let workers = filterAccessibleWorkers(readWorkerRegistry(hqRoot), activeCompany);
231
+
232
+ if (opts.shared) workers = workers.filter((w) => Boolean(w.grants && w.grants.trim()));
233
+ if (opts.mine) workers = workers.filter((w) => Boolean(w.company) && w.company === activeCompany);
234
+
235
+ if (workers.length === 0) {
236
+ console.log("No accessible workers.");
237
+ return;
238
+ }
239
+
240
+ const publicWorkers = workers.filter((w) => w.visibility === "public");
241
+ const companyWorkers = workers.filter((w) => w.visibility !== "public");
242
+
243
+ console.log(chalk.bold("Available Workers:"));
244
+ const printGroup = (title: string, list: RegistryWorker[]) => {
245
+ if (list.length === 0) return;
246
+ console.log(`\n ${chalk.cyan(title)}:`);
247
+ for (const w of list.sort((a, b) => a.id.localeCompare(b.id))) {
248
+ const desc = (w.description ?? "").slice(0, 72);
249
+ const shared = w.grants && w.grants.trim() ? chalk.dim(` [shared: ${w.grants}]`) : "";
250
+ console.log(` ${w.id.padEnd(24)} ${desc}${shared}`);
251
+ }
252
+ };
253
+ printGroup("Public", publicWorkers);
254
+ if (activeCompany) printGroup(activeCompany, companyWorkers);
255
+
256
+ console.log(chalk.dim("\nUsage: hq run {worker-id} [skill] [args]"));
257
+ console.log(
258
+ chalk.dim(
259
+ "Share a company worker: hq workers share {worker-id} --with {grp_<name>|@all} --permission read",
260
+ ),
261
+ );
262
+ }
263
+
264
+ export function registerWorkersCommand(program: Command): void {
265
+ const workers = program
266
+ .command("workers")
267
+ .description("Discover and share HQ workers")
268
+ .option("--company <slug>", "Company slug (resolves to companyUid)");
269
+
270
+ workers
271
+ .command("list")
272
+ .description("List workers you can access (public + your active company's)")
273
+ .option("--mine", "Only this company's workers")
274
+ .option("--shared", "Only workers that have been shared with someone")
275
+ .action((opts: { mine?: boolean; shared?: boolean }) => {
276
+ runWorkersList({ ...opts, company: workers.opts().company as string | undefined });
277
+ });
278
+
279
+ workers
280
+ .command("share <workerId>")
281
+ .description("Grant a teammate, group, or @all access to a company worker")
282
+ .requiredOption(
283
+ "--with <principal>",
284
+ "Email address, group id (grp_<name>), or '@all' to share with every active company member",
285
+ )
286
+ .option("--permission <level>", "Permission level: read | write (default: read)")
287
+ .action(async (workerId: string, opts: { with: string; permission?: string }) => {
288
+ try {
289
+ await runWorkersShare(workerId, {
290
+ ...opts,
291
+ company: workers.opts().company as string | undefined,
292
+ });
293
+ } catch (err) {
294
+ console.error(chalk.red("Error:"), err instanceof Error ? err.message : String(err));
295
+ process.exit(1);
296
+ }
297
+ });
298
+ }
@@ -0,0 +1,32 @@
1
+ import { afterEach, describe, expect, it, vi } from "vitest";
2
+
3
+ vi.mock("./cli-version.js", () => ({
4
+ CLI_VERSION: "5.60.0",
5
+ CLI_NAME: "@indigoai-us/hq-cli",
6
+ }));
7
+
8
+ vi.mock("./node-preflight.js", () => ({}));
9
+
10
+ afterEach(() => {
11
+ vi.restoreAllMocks();
12
+ vi.resetModules();
13
+ });
14
+
15
+ describe("bin bootstrap", () => {
16
+ it("answers --version without importing the command graph", async () => {
17
+ const originalArgv = process.argv;
18
+ const write = vi.spyOn(process.stdout, "write").mockImplementation(() => true);
19
+ const runCli = vi.fn();
20
+ vi.doMock("./main.js", () => ({ runCli }));
21
+ process.argv = ["node", "hq", "--version"];
22
+
23
+ try {
24
+ await import("./index.js");
25
+ } finally {
26
+ process.argv = originalArgv;
27
+ }
28
+
29
+ expect(write).toHaveBeenCalledWith("5.60.0\n");
30
+ expect(runCli).not.toHaveBeenCalled();
31
+ });
32
+ });