@thecorporation/cli 0.1.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.
package/dist/index.js ADDED
@@ -0,0 +1,2691 @@
1
+ #!/usr/bin/env node
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __esm = (fn, res) => function __init() {
5
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
6
+ };
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+
12
+ // src/config.ts
13
+ import { readFileSync, writeFileSync, mkdirSync, existsSync } from "fs";
14
+ import { join } from "path";
15
+ import { homedir } from "os";
16
+ function deepMerge(base, override) {
17
+ for (const [key, value] of Object.entries(override)) {
18
+ if (key in base && typeof base[key] === "object" && base[key] !== null && !Array.isArray(base[key]) && typeof value === "object" && value !== null && !Array.isArray(value)) {
19
+ deepMerge(base[key], value);
20
+ } else {
21
+ base[key] = value;
22
+ }
23
+ }
24
+ }
25
+ function loadConfig() {
26
+ const cfg = structuredClone(DEFAULTS);
27
+ if (existsSync(CONFIG_FILE)) {
28
+ const saved = JSON.parse(readFileSync(CONFIG_FILE, "utf-8"));
29
+ deepMerge(cfg, saved);
30
+ }
31
+ return cfg;
32
+ }
33
+ function saveConfig(cfg) {
34
+ mkdirSync(CONFIG_DIR, { recursive: true, mode: 448 });
35
+ writeFileSync(CONFIG_FILE, JSON.stringify(cfg, null, 2) + "\n", { mode: 384 });
36
+ }
37
+ function getValue(cfg, dotPath) {
38
+ const keys = dotPath.split(".");
39
+ let current = cfg;
40
+ for (const key of keys) {
41
+ if (typeof current === "object" && current !== null && key in current) {
42
+ current = current[key];
43
+ } else {
44
+ return void 0;
45
+ }
46
+ }
47
+ return current;
48
+ }
49
+ function setValue(cfg, dotPath, value) {
50
+ const keys = dotPath.split(".");
51
+ let current = cfg;
52
+ for (const key of keys.slice(0, -1)) {
53
+ if (!(key in current) || typeof current[key] !== "object" || current[key] === null) {
54
+ current[key] = {};
55
+ }
56
+ current = current[key];
57
+ }
58
+ current[keys[keys.length - 1]] = value;
59
+ }
60
+ function requireConfig(...fields) {
61
+ const cfg = loadConfig();
62
+ const missing = fields.filter((f) => !getValue(cfg, f));
63
+ if (missing.length > 0) {
64
+ console.error(`Missing config: ${missing.join(", ")}`);
65
+ console.error("Run 'corp setup' to configure.");
66
+ process.exit(1);
67
+ }
68
+ return cfg;
69
+ }
70
+ function maskKey(value) {
71
+ if (!value || value.length < 8) return "***";
72
+ return "***" + value.slice(-4);
73
+ }
74
+ function configForDisplay(cfg) {
75
+ const display = { ...cfg };
76
+ if (display.api_key) display.api_key = maskKey(display.api_key);
77
+ if (typeof display.llm === "object" && display.llm !== null) {
78
+ const llm = { ...display.llm };
79
+ if (llm.api_key) llm.api_key = maskKey(llm.api_key);
80
+ display.llm = llm;
81
+ }
82
+ return display;
83
+ }
84
+ function resolveEntityId(cfg, explicitId) {
85
+ const eid = explicitId || cfg.active_entity_id;
86
+ if (!eid) {
87
+ console.error(
88
+ "No entity specified. Use --entity-id or set active_entity_id via 'corp config set active_entity_id <id>'."
89
+ );
90
+ process.exit(1);
91
+ }
92
+ return eid;
93
+ }
94
+ var CONFIG_DIR, CONFIG_FILE, DEFAULTS;
95
+ var init_config = __esm({
96
+ "src/config.ts"() {
97
+ "use strict";
98
+ CONFIG_DIR = process.env.CORP_CONFIG_DIR || join(homedir(), ".corp");
99
+ CONFIG_FILE = join(CONFIG_DIR, "config.json");
100
+ DEFAULTS = {
101
+ api_url: process.env.CORP_API_URL || "https://api.thecorporation.ai",
102
+ api_key: "",
103
+ workspace_id: "",
104
+ hosting_mode: "",
105
+ llm: {
106
+ provider: "anthropic",
107
+ api_key: "",
108
+ model: "claude-sonnet-4-6"
109
+ },
110
+ user: { name: "", email: "" },
111
+ active_entity_id: ""
112
+ };
113
+ }
114
+ });
115
+
116
+ // src/api-client.ts
117
+ import { CorpAPIClient, SessionExpiredError, provisionWorkspace } from "@thecorporation/corp-tools";
118
+ var init_api_client = __esm({
119
+ "src/api-client.ts"() {
120
+ "use strict";
121
+ }
122
+ });
123
+
124
+ // src/output.ts
125
+ import chalk from "chalk";
126
+ import Table from "cli-table3";
127
+ function printError(msg) {
128
+ console.error(chalk.red("Error:"), msg);
129
+ }
130
+ function printSuccess(msg) {
131
+ console.log(chalk.green(msg));
132
+ }
133
+ function printJson(data) {
134
+ console.log(JSON.stringify(data, null, 2));
135
+ }
136
+ function printStatusPanel(data) {
137
+ console.log(chalk.blue("\u2500".repeat(50)));
138
+ console.log(chalk.blue.bold(" Corp Status"));
139
+ console.log(chalk.blue("\u2500".repeat(50)));
140
+ console.log(` ${chalk.bold("Workspace:")} ${data.workspace_id ?? "N/A"}`);
141
+ console.log(` ${chalk.bold("Entities:")} ${data.entity_count ?? 0}`);
142
+ const urgency = data.urgency_counts ?? {};
143
+ if (Object.keys(urgency).length > 0) {
144
+ console.log(`
145
+ ${chalk.bold("Obligations:")}`);
146
+ for (const [tier, count] of Object.entries(urgency)) {
147
+ const colorFn = URGENCY_COLORS[tier] ?? ((s2) => s2);
148
+ console.log(` ${colorFn(`${tier}:`)} ${count}`);
149
+ }
150
+ }
151
+ if (data.next_deadline) {
152
+ console.log(`
153
+ ${chalk.bold("Next deadline:")} ${data.next_deadline}`);
154
+ }
155
+ console.log(chalk.blue("\u2500".repeat(50)));
156
+ }
157
+ function makeTable(title, columns) {
158
+ console.log(`
159
+ ${chalk.bold(title)}`);
160
+ return new Table({ head: columns.map((c) => chalk.dim(c)) });
161
+ }
162
+ function s(val, maxLen) {
163
+ const str = val == null ? "" : String(val);
164
+ if (maxLen && str.length > maxLen) return str.slice(0, maxLen);
165
+ return str;
166
+ }
167
+ function money(val) {
168
+ if (typeof val === "number") return `$${val.toLocaleString()}`;
169
+ return String(val ?? "");
170
+ }
171
+ function printEntitiesTable(entities) {
172
+ const table = makeTable("Entities", ["ID", "Name", "Type", "Jurisdiction", "Status"]);
173
+ for (const e of entities) {
174
+ table.push([s(e.entity_id, 12), s(e.name), s(e.entity_type), s(e.jurisdiction), s(e.status)]);
175
+ }
176
+ console.log(table.toString());
177
+ }
178
+ function printObligationsTable(obligations) {
179
+ const table = makeTable("Obligations", ["ID", "Type", "Urgency", "Due", "Status"]);
180
+ for (const o of obligations) {
181
+ const urg = s(o.urgency) || "upcoming";
182
+ const colorFn = URGENCY_COLORS[urg] ?? ((x) => x);
183
+ table.push([s(o.obligation_id, 12), s(o.obligation_type), colorFn(urg), s(o.due_at), s(o.status)]);
184
+ }
185
+ console.log(table.toString());
186
+ }
187
+ function printContactsTable(contacts) {
188
+ const table = makeTable("Contacts", ["ID", "Name", "Email", "Category", "Entity"]);
189
+ for (const c of contacts) {
190
+ table.push([
191
+ s(c.contact_id ?? c.id, 12),
192
+ s(c.name),
193
+ s(c.email),
194
+ s(c.category),
195
+ s(c.entity_name ?? c.entity_id)
196
+ ]);
197
+ }
198
+ console.log(table.toString());
199
+ }
200
+ function printCapTable(data) {
201
+ const accessLevel = s(data.access_level) || "admin";
202
+ const shareClasses = data.share_classes ?? [];
203
+ if (shareClasses.length > 0) {
204
+ const cols = ["Class", "Authorized", "Outstanding"];
205
+ if (accessLevel !== "summary") cols.push("Holders");
206
+ const table = makeTable("Cap Table \u2014 Share Classes", cols);
207
+ for (const sc of shareClasses) {
208
+ const row = [s(sc.class_code ?? sc.name), s(sc.authorized), s(sc.outstanding)];
209
+ if (accessLevel !== "summary") {
210
+ const holders = sc.holders ?? [];
211
+ row.push(holders.map((h) => `${h.name ?? "?"}(${h.percentage ?? "?"}%)`).join(", "));
212
+ }
213
+ table.push(row);
214
+ }
215
+ console.log(table.toString());
216
+ }
217
+ const ownership = data.ownership ?? [];
218
+ if (ownership.length > 0 && accessLevel !== "summary") {
219
+ const table = makeTable("Ownership Breakdown", ["Holder", "Shares", "Percentage", "Class"]);
220
+ for (const o of ownership) {
221
+ table.push([s(o.holder_name ?? o.name), s(o.shares), `${o.percentage ?? ""}%`, s(o.share_class)]);
222
+ }
223
+ console.log(table.toString());
224
+ }
225
+ const pools = data.option_pools ?? [];
226
+ if (pools.length > 0) {
227
+ const table = makeTable("Option Pools", ["Name", "Authorized", "Granted", "Available"]);
228
+ for (const p of pools) {
229
+ table.push([s(p.name), s(p.authorized), s(p.granted), s(p.available)]);
230
+ }
231
+ console.log(table.toString());
232
+ }
233
+ if (data.fully_diluted_shares != null) {
234
+ const fd = data.fully_diluted_shares;
235
+ console.log(`
236
+ ${chalk.bold("Fully Diluted Shares:")} ${typeof fd === "number" ? fd.toLocaleString() : fd}`);
237
+ }
238
+ }
239
+ function printSafesTable(safes) {
240
+ const table = makeTable("SAFE Notes", ["ID", "Investor", "Amount", "Cap", "Discount", "Date"]);
241
+ for (const s_ of safes) {
242
+ table.push([
243
+ s(s_.safe_id ?? s_.id, 12),
244
+ s(s_.investor_name ?? s_.investor),
245
+ money(s_.investment_amount ?? s_.amount),
246
+ s(s_.valuation_cap ?? s_.cap),
247
+ s(s_.discount_rate ?? s_.discount),
248
+ s(s_.date ?? s_.created_at)
249
+ ]);
250
+ }
251
+ console.log(table.toString());
252
+ }
253
+ function printTransfersTable(transfers) {
254
+ const table = makeTable("Share Transfers", ["ID", "From", "To", "Shares", "Class", "Date"]);
255
+ for (const t of transfers) {
256
+ table.push([
257
+ s(t.transfer_id ?? t.id, 12),
258
+ s(t.from_holder ?? t.from),
259
+ s(t.to_holder ?? t.to),
260
+ s(t.shares),
261
+ s(t.share_class),
262
+ s(t.date ?? t.transfer_date)
263
+ ]);
264
+ }
265
+ console.log(table.toString());
266
+ }
267
+ function printValuationsTable(valuations) {
268
+ const table = makeTable("Valuations", ["Date", "Type", "Valuation", "PPS"]);
269
+ for (const v of valuations) {
270
+ table.push([
271
+ s(v.valuation_date ?? v.date),
272
+ s(v.valuation_type ?? v.type),
273
+ s(v.enterprise_value ?? v.valuation),
274
+ s(v.price_per_share ?? v.pps ?? v.fmv_per_share)
275
+ ]);
276
+ }
277
+ console.log(table.toString());
278
+ }
279
+ function printGovernanceTable(bodies) {
280
+ const table = makeTable("Governance Bodies", ["ID", "Body", "Type", "Seats", "Meetings"]);
281
+ for (const b of bodies) {
282
+ table.push([
283
+ s(b.body_id ?? b.id, 12),
284
+ s(b.name),
285
+ s(b.body_type ?? b.type),
286
+ s(b.seat_count ?? b.seats),
287
+ s(b.meeting_count ?? b.meetings)
288
+ ]);
289
+ }
290
+ console.log(table.toString());
291
+ }
292
+ function printSeatsTable(seats) {
293
+ const table = makeTable("Seats", ["Seat", "Holder", "Role", "Status"]);
294
+ for (const st of seats) {
295
+ table.push([s(st.seat_name ?? st.title), s(st.holder_name ?? st.holder), s(st.role), s(st.status)]);
296
+ }
297
+ console.log(table.toString());
298
+ }
299
+ function printMeetingsTable(meetings) {
300
+ const table = makeTable("Meetings", ["ID", "Title", "Date", "Status", "Resolutions"]);
301
+ for (const m of meetings) {
302
+ table.push([
303
+ s(m.meeting_id ?? m.id, 12),
304
+ s(m.title ?? m.name),
305
+ s(m.meeting_date ?? m.date),
306
+ s(m.status),
307
+ s(m.resolution_count ?? m.resolutions)
308
+ ]);
309
+ }
310
+ console.log(table.toString());
311
+ }
312
+ function printResolutionsTable(resolutions) {
313
+ const table = makeTable("Resolutions", ["ID", "Title", "Type", "Status", "For", "Against"]);
314
+ for (const r of resolutions) {
315
+ table.push([
316
+ s(r.resolution_id ?? r.id, 12),
317
+ s(r.title),
318
+ s(r.resolution_type ?? r.type),
319
+ s(r.status),
320
+ s(r.votes_for),
321
+ s(r.votes_against)
322
+ ]);
323
+ }
324
+ console.log(table.toString());
325
+ }
326
+ function printDocumentsTable(docs) {
327
+ const table = makeTable("Documents", ["ID", "Title", "Type", "Date", "Status", "Signatures"]);
328
+ for (const d of docs) {
329
+ const sigs = d.signatures;
330
+ const sigStr = Array.isArray(sigs) ? `${sigs.length} signed` : s(sigs);
331
+ table.push([
332
+ s(d.document_id ?? d.id, 12),
333
+ s(d.title ?? d.name),
334
+ s(d.document_type ?? d.type),
335
+ s(d.date ?? d.created_at),
336
+ s(d.status),
337
+ sigStr
338
+ ]);
339
+ }
340
+ console.log(table.toString());
341
+ }
342
+ function printAgentsTable(agents) {
343
+ const table = makeTable("Agents", ["ID", "Name", "Status", "Model"]);
344
+ for (const a of agents) {
345
+ const status = s(a.status);
346
+ const colored = status === "active" ? chalk.green(status) : status === "paused" ? chalk.yellow(status) : status;
347
+ table.push([s(a.agent_id ?? a.id, 12), s(a.name), colored, s(a.model)]);
348
+ }
349
+ console.log(table.toString());
350
+ }
351
+ function printApprovalsTable(approvals) {
352
+ const table = makeTable("Pending Approvals", ["ID", "Type", "Requested By", "Description", "Created"]);
353
+ for (const a of approvals) {
354
+ let desc = s(a.description ?? a.summary);
355
+ if (desc.length > 60) desc = desc.slice(0, 57) + "...";
356
+ table.push([
357
+ s(a.approval_id ?? a.id, 12),
358
+ s(a.approval_type ?? a.type),
359
+ s(a.requested_by ?? a.requester),
360
+ desc,
361
+ s(a.created_at)
362
+ ]);
363
+ }
364
+ console.log(table.toString());
365
+ }
366
+ function printBillingPanel(status, plans) {
367
+ const tier = s(status.tier ?? status.plan) || "free";
368
+ const subs = status.subscriptions ?? [];
369
+ const usageCount = status.usage_count ?? 0;
370
+ console.log(chalk.green("\u2500".repeat(50)));
371
+ console.log(chalk.green.bold(" Billing Status"));
372
+ console.log(chalk.green("\u2500".repeat(50)));
373
+ console.log(` ${chalk.bold("Current Tier:")} ${tier}`);
374
+ console.log(` ${chalk.bold("Active Subscriptions:")} ${subs.length}`);
375
+ for (const sub of subs) {
376
+ console.log(` - ${sub.tier ?? "N/A"} (${sub.status ?? "N/A"})`);
377
+ }
378
+ console.log(` ${chalk.bold("Tool Calls:")} ${usageCount}`);
379
+ console.log(chalk.dim(" Manage: corp billing portal"));
380
+ console.log(chalk.dim(" Upgrade: corp billing upgrade"));
381
+ console.log(chalk.green("\u2500".repeat(50)));
382
+ if (plans.length > 0) {
383
+ const table = makeTable("Available Plans", ["Tier", "Price", "Type", "Description"]);
384
+ for (const p of plans) {
385
+ const amount = p.amount ?? 0;
386
+ const interval = s(p.interval);
387
+ let priceStr = "Free";
388
+ if (amount > 0) {
389
+ priceStr = interval ? `$${Math.round(amount / 100)}/${interval[0]}` : `$${Math.round(amount / 100)}`;
390
+ }
391
+ let name = s(p.name ?? p.tier);
392
+ if (p.addon) name += chalk.dim(" (add-on)");
393
+ let desc = s(p.description);
394
+ if (desc.length > 60) desc = desc.slice(0, 57) + "...";
395
+ table.push([name, priceStr, s(p.type), desc]);
396
+ }
397
+ console.log(table.toString());
398
+ }
399
+ }
400
+ var URGENCY_COLORS;
401
+ var init_output = __esm({
402
+ "src/output.ts"() {
403
+ "use strict";
404
+ URGENCY_COLORS = {
405
+ overdue: chalk.red.bold,
406
+ due_today: chalk.yellow.bold,
407
+ d1: chalk.yellow,
408
+ d7: chalk.cyan,
409
+ d14: chalk.blue,
410
+ d30: chalk.dim,
411
+ upcoming: chalk.dim
412
+ };
413
+ }
414
+ });
415
+
416
+ // src/commands/setup.ts
417
+ var setup_exports = {};
418
+ __export(setup_exports, {
419
+ setupCommand: () => setupCommand
420
+ });
421
+ import { input, confirm } from "@inquirer/prompts";
422
+ async function setupCommand() {
423
+ const cfg = loadConfig();
424
+ console.log("Welcome to corp \u2014 corporate governance from the terminal.\n");
425
+ cfg.api_url = API_URL;
426
+ console.log("--- User Info ---");
427
+ const user = cfg.user ?? { name: "", email: "" };
428
+ user.name = await input({ message: "Your name", default: user.name || void 0 });
429
+ user.email = await input({ message: "Your email", default: user.email || void 0 });
430
+ cfg.user = user;
431
+ if (!cfg.api_key || !cfg.workspace_id) {
432
+ console.log("\nProvisioning workspace...");
433
+ try {
434
+ const result = await provisionWorkspace(cfg.api_url);
435
+ cfg.api_key = result.api_key;
436
+ cfg.workspace_id = result.workspace_id;
437
+ console.log(`Workspace provisioned: ${result.workspace_id}`);
438
+ } catch (err) {
439
+ printError(`Auto-provision failed: ${err}`);
440
+ console.log("You can manually set credentials with: corp config set api_key <key>");
441
+ }
442
+ } else {
443
+ console.log("\nVerifying existing credentials...");
444
+ let keyValid = false;
445
+ try {
446
+ const resp = await fetch(
447
+ `${cfg.api_url.replace(/\/+$/, "")}/v1/workspaces/${cfg.workspace_id}/status`,
448
+ { headers: { Authorization: `Bearer ${cfg.api_key}` } }
449
+ );
450
+ keyValid = resp.status !== 401;
451
+ } catch {
452
+ }
453
+ if (keyValid) {
454
+ console.log("Credentials OK.");
455
+ } else {
456
+ console.log("API key is no longer valid.");
457
+ const reprovision = await confirm({
458
+ message: "Provision a new workspace? (This will replace your current credentials)",
459
+ default: false
460
+ });
461
+ if (reprovision) {
462
+ try {
463
+ const result = await provisionWorkspace(cfg.api_url);
464
+ cfg.api_key = result.api_key;
465
+ cfg.workspace_id = result.workspace_id;
466
+ console.log(`Workspace provisioned: ${result.workspace_id}`);
467
+ } catch (err) {
468
+ printError(`Provisioning failed: ${err}`);
469
+ }
470
+ } else {
471
+ console.log("Keeping existing credentials. You can manually update with: corp config set api_key <key>");
472
+ }
473
+ }
474
+ }
475
+ saveConfig(cfg);
476
+ console.log("\nConfig saved to ~/.corp/config.json");
477
+ console.log("Run 'corp status' to verify your connection.");
478
+ }
479
+ var API_URL;
480
+ var init_setup = __esm({
481
+ "src/commands/setup.ts"() {
482
+ "use strict";
483
+ init_config();
484
+ init_api_client();
485
+ init_output();
486
+ API_URL = "https://api.thecorporation.ai";
487
+ }
488
+ });
489
+
490
+ // src/animation.ts
491
+ function renderFrame(frame) {
492
+ const cols = [];
493
+ for (let i = 0; i < BUILDINGS.length; i++) {
494
+ const building = BUILDINGS[i];
495
+ const h = building.length;
496
+ const visible = Math.max(0, Math.min(h, frame - i));
497
+ const width = building[0]?.length ?? 6;
498
+ const blank = " ".repeat(width);
499
+ const col = Array(MAX_HEIGHT - visible).fill(blank);
500
+ col.push(...building.slice(h - visible));
501
+ cols.push(col);
502
+ }
503
+ const lines = [];
504
+ for (let row = 0; row < MAX_HEIGHT; row++) {
505
+ lines.push(cols.map((col) => col[row]).join(""));
506
+ }
507
+ return lines.join("\n");
508
+ }
509
+ async function withAnimation(fn) {
510
+ if (!process.stdout.isTTY) {
511
+ return fn();
512
+ }
513
+ let frame = 0;
514
+ let animDone = false;
515
+ const spinChars = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
516
+ let spinIdx = 0;
517
+ let lastLineCount = 0;
518
+ const clearPrev = () => {
519
+ if (lastLineCount > 0) {
520
+ process.stdout.write(`\x1B[${lastLineCount}A\x1B[0J`);
521
+ }
522
+ };
523
+ const drawFrame = () => {
524
+ clearPrev();
525
+ if (!animDone) {
526
+ const art = renderFrame(frame);
527
+ const output = `${GOLD}${art}${RESET}
528
+ `;
529
+ process.stdout.write(output);
530
+ lastLineCount = MAX_HEIGHT + 1;
531
+ frame++;
532
+ if (frame >= TOTAL_FRAMES) {
533
+ animDone = true;
534
+ }
535
+ } else {
536
+ const line = `${GOLD}${spinChars[spinIdx % spinChars.length]} Loading...${RESET}
537
+ `;
538
+ process.stdout.write(line);
539
+ lastLineCount = 1;
540
+ spinIdx++;
541
+ }
542
+ };
543
+ drawFrame();
544
+ const timer = setInterval(drawFrame, 100);
545
+ try {
546
+ const result = await fn();
547
+ return result;
548
+ } finally {
549
+ clearInterval(timer);
550
+ clearPrev();
551
+ }
552
+ }
553
+ var BUILDINGS, MAX_HEIGHT, TOTAL_FRAMES, GOLD, RESET;
554
+ var init_animation = __esm({
555
+ "src/animation.ts"() {
556
+ "use strict";
557
+ BUILDINGS = [
558
+ [
559
+ " \u250C\u2510 ",
560
+ " \u2502\u2502 ",
561
+ " \u2502\u2502 ",
562
+ " \u250C\u2524\u251C\u2510 ",
563
+ " \u2502\u2502\u2502\u2502\u2502",
564
+ " \u2502\u2502\u2502\u2502\u2502"
565
+ ],
566
+ [
567
+ " \u2554\u2550\u2550\u2557 ",
568
+ " \u2551\u25AA\u25AA\u2551 ",
569
+ " \u2551\u25AA\u25AA\u2551 ",
570
+ " \u2551\u25AA\u25AA\u2551 ",
571
+ " \u2551\u25AA\u25AA\u2551 ",
572
+ " \u2551\u25AA\u25AA\u2551 ",
573
+ " \u2551\u25AA\u25AA\u2551 ",
574
+ " \u2551\u25AA\u25AA\u2551 "
575
+ ],
576
+ [
577
+ " /\\ ",
578
+ " / \\ ",
579
+ " \u2502\u25AA\u25AA\u2502 ",
580
+ " \u2502\u25AA\u25AA\u2502 ",
581
+ " \u2502\u25AA\u25AA\u2502 "
582
+ ],
583
+ [
584
+ " \u250C\u2500\u2500\u2510 ",
585
+ " \u2502\u224B\u224B\u2502 ",
586
+ " \u2502\u25AA\u25AA\u2502 ",
587
+ " \u2502\u25AA\u25AA\u2502 ",
588
+ " \u2502\u25AA\u25AA\u2502 ",
589
+ " \u2502\u25AA\u25AA\u2502 ",
590
+ " \u2502\u25AA\u25AA\u2502 ",
591
+ " \u2502\u25AA\u25AA\u2502 ",
592
+ " \u2502\u25AA\u25AA\u2502 "
593
+ ],
594
+ [
595
+ " \u257B ",
596
+ " \u2503 ",
597
+ " \u250C\u2524\u2510 ",
598
+ " \u2502\u25AA\u2502 ",
599
+ " \u2502\u25AA\u2502 ",
600
+ " \u2502\u25AA\u2502 ",
601
+ " \u2502\u25AA\u2502 ",
602
+ " \u2502\u25AA\u2502 ",
603
+ " \u2502\u25AA\u2502 ",
604
+ " \u2502\u25AA\u2502 ",
605
+ " \u2502\u25AA\u2502 "
606
+ ],
607
+ [
608
+ " \u250C\u2510 ",
609
+ " \u251C\u2524 ",
610
+ " \u2502\u25AA\u2502 ",
611
+ " \u2502\u25AA\u2502 ",
612
+ " \u2502\u25AA\u2502 ",
613
+ " \u2502\u25AA\u2502 "
614
+ ],
615
+ [
616
+ " \u2554\u2550\u2550\u2550\u2557",
617
+ " \u2551\u25AA \u25AA\u2551",
618
+ " \u2551\u25AA \u25AA\u2551",
619
+ " \u2551\u25AA \u25AA\u2551",
620
+ " \u2551\u25AA \u25AA\u2551",
621
+ " \u2551\u25AA \u25AA\u2551",
622
+ " \u2551\u25AA \u25AA\u2551",
623
+ " \u2551\u25AA \u25AA\u2551",
624
+ " \u2551\u25AA \u25AA\u2551",
625
+ " \u2551\u25AA \u25AA\u2551"
626
+ ],
627
+ [
628
+ " \u252C\u2500\u252C ",
629
+ " \u2502~\u2502 ",
630
+ " \u2502\u25AA\u2502 ",
631
+ " \u2502\u25AA\u2502 ",
632
+ " \u2502\u25AA\u2502 ",
633
+ " \u2502\u25AA\u2502 ",
634
+ " \u2502\u25AA\u2502 "
635
+ ]
636
+ ];
637
+ MAX_HEIGHT = Math.max(...BUILDINGS.map((b) => b.length));
638
+ TOTAL_FRAMES = MAX_HEIGHT + 4;
639
+ GOLD = "\x1B[38;2;212;160;23m";
640
+ RESET = "\x1B[0m";
641
+ }
642
+ });
643
+
644
+ // src/spinner.ts
645
+ async function withSpinner(_label, fn, json) {
646
+ if (json) {
647
+ return fn();
648
+ }
649
+ return withAnimation(fn);
650
+ }
651
+ var init_spinner = __esm({
652
+ "src/spinner.ts"() {
653
+ "use strict";
654
+ init_animation();
655
+ }
656
+ });
657
+
658
+ // src/commands/status.ts
659
+ var status_exports = {};
660
+ __export(status_exports, {
661
+ statusCommand: () => statusCommand
662
+ });
663
+ async function statusCommand() {
664
+ const cfg = requireConfig("api_url", "api_key", "workspace_id");
665
+ const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
666
+ try {
667
+ const data = await withSpinner("Loading", () => client.getStatus());
668
+ printStatusPanel(data);
669
+ } catch (err) {
670
+ printError(`Failed to fetch status: ${err}`);
671
+ process.exit(1);
672
+ }
673
+ }
674
+ var init_status = __esm({
675
+ "src/commands/status.ts"() {
676
+ "use strict";
677
+ init_config();
678
+ init_api_client();
679
+ init_output();
680
+ init_spinner();
681
+ }
682
+ });
683
+
684
+ // src/commands/config.ts
685
+ var config_exports = {};
686
+ __export(config_exports, {
687
+ configGetCommand: () => configGetCommand,
688
+ configListCommand: () => configListCommand,
689
+ configSetCommand: () => configSetCommand
690
+ });
691
+ function configSetCommand(key, value) {
692
+ const cfg = loadConfig();
693
+ setValue(cfg, key, value);
694
+ saveConfig(cfg);
695
+ console.log(`${key} = ${value}`);
696
+ }
697
+ function configGetCommand(key) {
698
+ const cfg = loadConfig();
699
+ const val = getValue(cfg, key);
700
+ if (val === void 0) {
701
+ printError(`Key not found: ${key}`);
702
+ process.exit(1);
703
+ }
704
+ if (typeof val === "object" && val !== null) {
705
+ printJson(val);
706
+ } else {
707
+ console.log(String(val));
708
+ }
709
+ }
710
+ function configListCommand() {
711
+ const cfg = loadConfig();
712
+ printJson(configForDisplay(cfg));
713
+ }
714
+ var init_config2 = __esm({
715
+ "src/commands/config.ts"() {
716
+ "use strict";
717
+ init_config();
718
+ init_output();
719
+ }
720
+ });
721
+
722
+ // src/commands/obligations.ts
723
+ var obligations_exports = {};
724
+ __export(obligations_exports, {
725
+ obligationsCommand: () => obligationsCommand
726
+ });
727
+ async function obligationsCommand(opts) {
728
+ const cfg = requireConfig("api_url", "api_key", "workspace_id");
729
+ const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
730
+ try {
731
+ const data = await client.getObligations(opts.tier);
732
+ const obligations = data.obligations ?? [];
733
+ if (opts.json) printJson(obligations);
734
+ else if (obligations.length === 0) console.log("No obligations found.");
735
+ else printObligationsTable(obligations);
736
+ } catch (err) {
737
+ printError(`Failed to fetch obligations: ${err}`);
738
+ process.exit(1);
739
+ }
740
+ }
741
+ var init_obligations = __esm({
742
+ "src/commands/obligations.ts"() {
743
+ "use strict";
744
+ init_config();
745
+ init_api_client();
746
+ init_output();
747
+ }
748
+ });
749
+
750
+ // src/commands/digest.ts
751
+ var digest_exports = {};
752
+ __export(digest_exports, {
753
+ digestCommand: () => digestCommand
754
+ });
755
+ async function digestCommand(opts) {
756
+ const cfg = requireConfig("api_url", "api_key", "workspace_id");
757
+ const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
758
+ try {
759
+ if (opts.trigger) {
760
+ const result = await client.triggerDigest();
761
+ printSuccess("Digest triggered.");
762
+ printJson(result);
763
+ } else if (opts.key) {
764
+ const result = await client.getDigest(opts.key);
765
+ printJson(result);
766
+ } else {
767
+ const digests = await client.listDigests();
768
+ if (digests.length === 0) console.log("No digest history found.");
769
+ else printJson(digests);
770
+ }
771
+ } catch (err) {
772
+ printError(`Failed: ${err}`);
773
+ process.exit(1);
774
+ }
775
+ }
776
+ var init_digest = __esm({
777
+ "src/commands/digest.ts"() {
778
+ "use strict";
779
+ init_config();
780
+ init_api_client();
781
+ init_output();
782
+ }
783
+ });
784
+
785
+ // src/commands/link.ts
786
+ var link_exports = {};
787
+ __export(link_exports, {
788
+ linkCommand: () => linkCommand
789
+ });
790
+ async function linkCommand() {
791
+ const cfg = requireConfig("api_url", "api_key", "workspace_id");
792
+ const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
793
+ try {
794
+ const data = await client.createLink();
795
+ const code = data.code;
796
+ const expires = data.expires_in_seconds ?? 900;
797
+ console.log();
798
+ console.log(` ${code}`);
799
+ console.log();
800
+ console.log(`Run this on the other device (expires in ${Math.floor(expires / 60)} minutes):`);
801
+ console.log(` corp claim ${code}`);
802
+ console.log();
803
+ } catch (err) {
804
+ printError(`${err}`);
805
+ process.exit(1);
806
+ }
807
+ }
808
+ var init_link = __esm({
809
+ "src/commands/link.ts"() {
810
+ "use strict";
811
+ init_config();
812
+ init_api_client();
813
+ init_output();
814
+ }
815
+ });
816
+
817
+ // src/commands/claim.ts
818
+ var claim_exports = {};
819
+ __export(claim_exports, {
820
+ claimCommand: () => claimCommand
821
+ });
822
+ async function claimCommand(code) {
823
+ const cfg = loadConfig();
824
+ const apiUrl = (cfg.api_url || "https://api.thecorporation.ai").replace(/\/+$/, "");
825
+ try {
826
+ const resp = await fetch(`${apiUrl}/v1/workspaces/claim`, {
827
+ method: "POST",
828
+ headers: { "Content-Type": "application/json" },
829
+ body: JSON.stringify({ code })
830
+ });
831
+ if (!resp.ok) {
832
+ let detail = "";
833
+ try {
834
+ const body = await resp.json();
835
+ detail = body.detail ?? "";
836
+ } catch {
837
+ }
838
+ printError(detail || `${resp.status} ${resp.statusText}`);
839
+ process.exit(1);
840
+ }
841
+ const data = await resp.json();
842
+ cfg.api_key = data.api_key;
843
+ cfg.workspace_id = data.workspace_id;
844
+ saveConfig(cfg);
845
+ console.log(`Workspace joined: ${data.workspace_id}`);
846
+ console.log("Credentials saved to ~/.corp/config.json");
847
+ } catch (err) {
848
+ printError(`${err}`);
849
+ process.exit(1);
850
+ }
851
+ }
852
+ var init_claim = __esm({
853
+ "src/commands/claim.ts"() {
854
+ "use strict";
855
+ init_config();
856
+ init_output();
857
+ }
858
+ });
859
+
860
+ // src/llm.ts
861
+ async function chat(messages, tools, provider = "anthropic", apiKey = "", model = "", baseUrl) {
862
+ if (provider === "anthropic") {
863
+ return chatAnthropic(messages, tools, apiKey, model);
864
+ } else if (provider === "openai" || provider === "openrouter") {
865
+ const effectiveUrl = baseUrl ?? PROVIDER_BASE_URLS[provider];
866
+ return chatOpenAI(messages, tools, apiKey, model, effectiveUrl);
867
+ }
868
+ throw new Error(`Unknown LLM provider: ${provider}`);
869
+ }
870
+ async function chatAnthropic(messages, tools, apiKey = "", model = "") {
871
+ const { default: Anthropic } = await import("@anthropic-ai/sdk");
872
+ const client = new Anthropic({ apiKey });
873
+ let systemText = "";
874
+ const convMessages = [];
875
+ for (const msg of messages) {
876
+ if (msg.role === "system") {
877
+ systemText = msg.content;
878
+ } else if (msg.role === "tool") {
879
+ convMessages.push({
880
+ role: "user",
881
+ content: [{
882
+ type: "tool_result",
883
+ tool_use_id: msg.tool_call_id,
884
+ content: msg.content
885
+ }]
886
+ });
887
+ } else if (msg.role === "assistant" && msg.tool_calls) {
888
+ const contentBlocks = [];
889
+ if (msg.content) contentBlocks.push({ type: "text", text: msg.content });
890
+ for (const tc of msg.tool_calls) {
891
+ const fn = tc.function;
892
+ let args = fn.arguments;
893
+ if (typeof args === "string") args = JSON.parse(args);
894
+ contentBlocks.push({ type: "tool_use", id: tc.id, name: fn.name, input: args });
895
+ }
896
+ convMessages.push({ role: "assistant", content: contentBlocks });
897
+ } else {
898
+ convMessages.push({ role: msg.role, content: msg.content ?? "" });
899
+ }
900
+ }
901
+ let anthropicTools;
902
+ if (tools?.length) {
903
+ anthropicTools = tools.map((t) => {
904
+ const fn = t.function;
905
+ return {
906
+ name: fn.name,
907
+ description: fn.description ?? "",
908
+ input_schema: fn.parameters ?? { type: "object", properties: {} }
909
+ };
910
+ });
911
+ }
912
+ const kwargs = {
913
+ model: model || "claude-sonnet-4-20250514",
914
+ max_tokens: 4096,
915
+ messages: convMessages
916
+ };
917
+ if (systemText) kwargs.system = systemText;
918
+ if (anthropicTools) kwargs.tools = anthropicTools;
919
+ const response = await client.messages.create(kwargs);
920
+ let content = null;
921
+ const toolCallsOut = [];
922
+ for (const block of response.content) {
923
+ if (block.type === "text") {
924
+ content = block.text;
925
+ } else if (block.type === "tool_use") {
926
+ toolCallsOut.push({
927
+ id: block.id,
928
+ name: block.name,
929
+ arguments: typeof block.input === "object" ? block.input : {}
930
+ });
931
+ }
932
+ }
933
+ return {
934
+ content,
935
+ tool_calls: toolCallsOut,
936
+ usage: {
937
+ prompt_tokens: response.usage.input_tokens,
938
+ completion_tokens: response.usage.output_tokens,
939
+ total_tokens: response.usage.input_tokens + response.usage.output_tokens
940
+ },
941
+ finish_reason: response.stop_reason ?? null
942
+ };
943
+ }
944
+ async function chatOpenAI(messages, tools, apiKey = "", model = "", baseUrl) {
945
+ const { default: OpenAI } = await import("openai");
946
+ const clientOpts = { apiKey };
947
+ if (baseUrl) clientOpts.baseURL = baseUrl;
948
+ const client = new OpenAI(clientOpts);
949
+ const kwargs = {
950
+ model: model || "gpt-4o",
951
+ messages,
952
+ max_tokens: 4096
953
+ };
954
+ if (tools?.length) {
955
+ kwargs.tools = tools;
956
+ kwargs.tool_choice = "auto";
957
+ }
958
+ const response = await client.chat.completions.create(kwargs);
959
+ const choice = response.choices[0];
960
+ const message = choice.message;
961
+ const toolCallsOut = [];
962
+ if (message.tool_calls) {
963
+ for (const tc of message.tool_calls) {
964
+ let args;
965
+ try {
966
+ args = JSON.parse(tc.function.arguments);
967
+ } catch {
968
+ args = { _raw: tc.function.arguments };
969
+ }
970
+ toolCallsOut.push({ id: tc.id, name: tc.function.name, arguments: args });
971
+ }
972
+ }
973
+ return {
974
+ content: message.content,
975
+ tool_calls: toolCallsOut,
976
+ usage: {
977
+ prompt_tokens: response.usage?.prompt_tokens ?? 0,
978
+ completion_tokens: response.usage?.completion_tokens ?? 0,
979
+ total_tokens: response.usage?.total_tokens ?? 0
980
+ },
981
+ finish_reason: choice.finish_reason ?? null
982
+ };
983
+ }
984
+ var PROVIDER_BASE_URLS;
985
+ var init_llm = __esm({
986
+ "src/llm.ts"() {
987
+ "use strict";
988
+ PROVIDER_BASE_URLS = {
989
+ openrouter: "https://openrouter.ai/api/v1"
990
+ };
991
+ }
992
+ });
993
+
994
+ // src/tools.ts
995
+ import {
996
+ TOOL_DEFINITIONS as _TOOL_DEFINITIONS,
997
+ isWriteTool as _isWriteTool,
998
+ executeTool as _executeTool
999
+ } from "@thecorporation/corp-tools";
1000
+ import { join as join2 } from "path";
1001
+ import { homedir as homedir2 } from "os";
1002
+ async function executeTool(name, args, client) {
1003
+ return _executeTool(name, args, client, {
1004
+ dataDir: join2(homedir2(), ".corp"),
1005
+ onEntityFormed: (entityId) => {
1006
+ try {
1007
+ const cfg = loadConfig();
1008
+ cfg.active_entity_id = entityId;
1009
+ saveConfig(cfg);
1010
+ } catch {
1011
+ }
1012
+ }
1013
+ });
1014
+ }
1015
+ var TOOL_DEFINITIONS, isWriteTool;
1016
+ var init_tools = __esm({
1017
+ "src/tools.ts"() {
1018
+ "use strict";
1019
+ init_config();
1020
+ TOOL_DEFINITIONS = _TOOL_DEFINITIONS;
1021
+ isWriteTool = _isWriteTool;
1022
+ }
1023
+ });
1024
+
1025
+ // src/chat.ts
1026
+ var chat_exports = {};
1027
+ __export(chat_exports, {
1028
+ chatCommand: () => chatCommand
1029
+ });
1030
+ import { createInterface } from "readline";
1031
+ import chalk2 from "chalk";
1032
+ async function chatCommand() {
1033
+ const cfg = requireConfig("api_url", "api_key", "workspace_id", "llm.api_key");
1034
+ const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
1035
+ const messages = [{ role: "system", content: SYSTEM_PROMPT }];
1036
+ let totalTokens = 0;
1037
+ const rl = createInterface({ input: process.stdin, output: process.stdout });
1038
+ const prompt = () => new Promise((resolve) => rl.question(chalk2.green.bold("> "), resolve));
1039
+ console.log(chalk2.blue.bold("corp chat") + " \u2014 type /help for commands, /quit to exit\n");
1040
+ const slashHandlers = {
1041
+ "/status": async () => {
1042
+ try {
1043
+ printStatusPanel(await client.getStatus());
1044
+ } catch (e) {
1045
+ printError(`Status error: ${e}`);
1046
+ }
1047
+ },
1048
+ "/obligations": async () => {
1049
+ try {
1050
+ const data = await client.getObligations();
1051
+ const obls = data.obligations ?? [];
1052
+ if (obls.length) printObligationsTable(obls);
1053
+ else console.log(chalk2.dim("No obligations found."));
1054
+ } catch (e) {
1055
+ printError(`Obligations error: ${e}`);
1056
+ }
1057
+ },
1058
+ "/digest": async () => {
1059
+ try {
1060
+ const digests = await client.listDigests();
1061
+ if (digests.length) printJson(digests);
1062
+ else console.log(chalk2.dim("No digest history."));
1063
+ } catch (e) {
1064
+ printError(`Digest error: ${e}`);
1065
+ }
1066
+ },
1067
+ "/config": () => printJson(configForDisplay(cfg)),
1068
+ "/model": (args) => {
1069
+ const model = args.trim();
1070
+ if (!model) {
1071
+ console.log(`Current model: ${getValue(cfg, "llm.model")}`);
1072
+ return;
1073
+ }
1074
+ setValue(cfg, "llm.model", model);
1075
+ saveConfig(cfg);
1076
+ console.log(`Model switched to: ${model}`);
1077
+ },
1078
+ "/cost": () => console.log(`Session tokens used: ${totalTokens.toLocaleString()}`),
1079
+ "/clear": () => {
1080
+ messages.length = 0;
1081
+ messages.push({ role: "system", content: SYSTEM_PROMPT });
1082
+ totalTokens = 0;
1083
+ console.log(chalk2.dim("Conversation cleared."));
1084
+ },
1085
+ "/help": () => {
1086
+ console.log(`
1087
+ ${chalk2.bold("Chat Slash Commands")}
1088
+ /status Show workspace status
1089
+ /obligations List obligations
1090
+ /digest Show digest history
1091
+ /config Show current config (masked keys)
1092
+ /model <name> Switch LLM model
1093
+ /cost Show token usage
1094
+ /clear Clear conversation
1095
+ /help Show this help
1096
+ /quit Exit chat`);
1097
+ }
1098
+ };
1099
+ try {
1100
+ while (true) {
1101
+ let userInput;
1102
+ try {
1103
+ userInput = (await prompt()).trim();
1104
+ } catch {
1105
+ console.log("\n" + chalk2.dim("Goodbye."));
1106
+ break;
1107
+ }
1108
+ if (!userInput) continue;
1109
+ if (userInput.startsWith("/")) {
1110
+ const [cmd, ...rest] = userInput.split(/\s+/);
1111
+ const args = rest.join(" ");
1112
+ if (cmd === "/quit" || cmd === "/exit") {
1113
+ console.log(chalk2.dim("Goodbye."));
1114
+ break;
1115
+ }
1116
+ const handler = slashHandlers[cmd.toLowerCase()];
1117
+ if (handler) {
1118
+ await handler(args);
1119
+ continue;
1120
+ }
1121
+ printError(`Unknown command: ${cmd}. Type /help for available commands.`);
1122
+ continue;
1123
+ }
1124
+ messages.push({ role: "user", content: userInput });
1125
+ const llmCfg = cfg.llm;
1126
+ while (true) {
1127
+ let response;
1128
+ try {
1129
+ response = await chat(
1130
+ messages,
1131
+ TOOL_DEFINITIONS,
1132
+ llmCfg.provider,
1133
+ llmCfg.api_key,
1134
+ llmCfg.model,
1135
+ llmCfg.base_url
1136
+ );
1137
+ } catch (err) {
1138
+ printError(`LLM error: ${err}`);
1139
+ break;
1140
+ }
1141
+ totalTokens += response.usage.total_tokens;
1142
+ const assistantMsg = { role: "assistant", content: response.content };
1143
+ if (response.tool_calls.length > 0) {
1144
+ assistantMsg.tool_calls = response.tool_calls.map((tc) => ({
1145
+ id: tc.id,
1146
+ type: "function",
1147
+ function: { name: tc.name, arguments: JSON.stringify(tc.arguments) }
1148
+ }));
1149
+ if (!response.content) assistantMsg.content = null;
1150
+ }
1151
+ messages.push(assistantMsg);
1152
+ if (response.tool_calls.length === 0) {
1153
+ if (response.content) console.log("\n" + response.content + "\n");
1154
+ break;
1155
+ }
1156
+ for (const tc of response.tool_calls) {
1157
+ console.log(chalk2.dim(` ${isWriteTool(tc.name) ? "\u2699" : "\u2139"} ${tc.name}(${JSON.stringify(tc.arguments).slice(0, 80)})`));
1158
+ const result = await executeTool(tc.name, tc.arguments, client);
1159
+ const short = result.length > 200 ? result.slice(0, 197) + "..." : result;
1160
+ console.log(chalk2.dim(` => ${short}`));
1161
+ messages.push({ role: "tool", tool_call_id: tc.id, content: result });
1162
+ }
1163
+ }
1164
+ }
1165
+ } finally {
1166
+ rl.close();
1167
+ }
1168
+ }
1169
+ var SYSTEM_PROMPT;
1170
+ var init_chat = __esm({
1171
+ "src/chat.ts"() {
1172
+ "use strict";
1173
+ init_config();
1174
+ init_api_client();
1175
+ init_llm();
1176
+ init_tools();
1177
+ init_output();
1178
+ SYSTEM_PROMPT = `You are **corp**, an AI assistant for corporate governance.
1179
+ You help users manage their companies \u2014 entities, cap tables, compliance, governance, finances, and more.
1180
+ You have tools to read and write corporate data. Use them to fulfill user requests.
1181
+ For write operations, confirm with the user before proceeding.
1182
+ Monetary values are in cents (e.g. 100000 = $1,000.00).
1183
+ Documents must be signed by the human \u2014 you cannot sign on their behalf.
1184
+ After completing actions, suggest logical next steps.`;
1185
+ }
1186
+ });
1187
+
1188
+ // src/commands/entities.ts
1189
+ var entities_exports = {};
1190
+ __export(entities_exports, {
1191
+ entitiesCommand: () => entitiesCommand,
1192
+ entitiesConvertCommand: () => entitiesConvertCommand,
1193
+ entitiesDissolveCommand: () => entitiesDissolveCommand,
1194
+ entitiesShowCommand: () => entitiesShowCommand
1195
+ });
1196
+ import chalk3 from "chalk";
1197
+ async function entitiesCommand(opts) {
1198
+ const cfg = requireConfig("api_url", "api_key", "workspace_id");
1199
+ const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
1200
+ try {
1201
+ const entities = await withSpinner("Loading", () => client.listEntities(), opts.json);
1202
+ if (opts.json) {
1203
+ printJson(entities);
1204
+ } else if (entities.length === 0) {
1205
+ console.log("No entities found.");
1206
+ } else {
1207
+ printEntitiesTable(entities);
1208
+ }
1209
+ } catch (err) {
1210
+ printError(`Failed to fetch entities: ${err}`);
1211
+ process.exit(1);
1212
+ }
1213
+ }
1214
+ async function entitiesShowCommand(entityId, opts) {
1215
+ const cfg = requireConfig("api_url", "api_key", "workspace_id");
1216
+ const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
1217
+ try {
1218
+ const entities = await client.listEntities();
1219
+ const entity = entities.find((e) => e.entity_id === entityId);
1220
+ if (!entity) {
1221
+ printError(`Entity not found: ${entityId}`);
1222
+ process.exit(1);
1223
+ }
1224
+ if (opts.json) {
1225
+ printJson(entity);
1226
+ } else {
1227
+ console.log(chalk3.blue("\u2500".repeat(40)));
1228
+ console.log(chalk3.blue.bold(" Entity Detail"));
1229
+ console.log(chalk3.blue("\u2500".repeat(40)));
1230
+ console.log(` ${chalk3.bold("Name:")} ${entity.name ?? "N/A"}`);
1231
+ console.log(` ${chalk3.bold("Type:")} ${entity.entity_type ?? "N/A"}`);
1232
+ console.log(` ${chalk3.bold("Jurisdiction:")} ${entity.jurisdiction ?? "N/A"}`);
1233
+ console.log(` ${chalk3.bold("Status:")} ${entity.status ?? "N/A"}`);
1234
+ console.log(` ${chalk3.bold("ID:")} ${entity.entity_id ?? "N/A"}`);
1235
+ if (entity.formation_date) console.log(` ${chalk3.bold("Formation Date:")} ${entity.formation_date}`);
1236
+ if (entity.ein) console.log(` ${chalk3.bold("EIN:")} ${entity.ein}`);
1237
+ console.log(chalk3.blue("\u2500".repeat(40)));
1238
+ }
1239
+ } catch (err) {
1240
+ printError(`Failed to fetch entities: ${err}`);
1241
+ process.exit(1);
1242
+ }
1243
+ }
1244
+ async function entitiesConvertCommand(entityId, opts) {
1245
+ const cfg = requireConfig("api_url", "api_key", "workspace_id");
1246
+ const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
1247
+ try {
1248
+ const data = { new_entity_type: opts.to };
1249
+ if (opts.jurisdiction) data.new_jurisdiction = opts.jurisdiction;
1250
+ const result = await client.convertEntity(entityId, data);
1251
+ printSuccess(`Entity conversion initiated: ${result.conversion_id ?? "OK"}`);
1252
+ printJson(result);
1253
+ } catch (err) {
1254
+ printError(`Failed to convert entity: ${err}`);
1255
+ process.exit(1);
1256
+ }
1257
+ }
1258
+ async function entitiesDissolveCommand(entityId, opts) {
1259
+ const cfg = requireConfig("api_url", "api_key", "workspace_id");
1260
+ const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
1261
+ try {
1262
+ const data = { reason: opts.reason };
1263
+ if (opts.effectiveDate) data.effective_date = opts.effectiveDate;
1264
+ const result = await client.dissolveEntity(entityId, data);
1265
+ printSuccess(`Dissolution initiated: ${result.dissolution_id ?? "OK"}`);
1266
+ printJson(result);
1267
+ } catch (err) {
1268
+ printError(`Failed to dissolve entity: ${err}`);
1269
+ process.exit(1);
1270
+ }
1271
+ }
1272
+ var init_entities = __esm({
1273
+ "src/commands/entities.ts"() {
1274
+ "use strict";
1275
+ init_config();
1276
+ init_api_client();
1277
+ init_output();
1278
+ init_spinner();
1279
+ }
1280
+ });
1281
+
1282
+ // src/commands/contacts.ts
1283
+ var contacts_exports = {};
1284
+ __export(contacts_exports, {
1285
+ contactsAddCommand: () => contactsAddCommand,
1286
+ contactsEditCommand: () => contactsEditCommand,
1287
+ contactsListCommand: () => contactsListCommand,
1288
+ contactsShowCommand: () => contactsShowCommand
1289
+ });
1290
+ import chalk4 from "chalk";
1291
+ async function contactsListCommand(opts) {
1292
+ const cfg = requireConfig("api_url", "api_key", "workspace_id");
1293
+ const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
1294
+ try {
1295
+ const contacts = await client.listContacts();
1296
+ if (opts.json) printJson(contacts);
1297
+ else if (contacts.length === 0) console.log("No contacts found.");
1298
+ else printContactsTable(contacts);
1299
+ } catch (err) {
1300
+ printError(`Failed to fetch contacts: ${err}`);
1301
+ process.exit(1);
1302
+ }
1303
+ }
1304
+ async function contactsShowCommand(contactId, opts) {
1305
+ const cfg = requireConfig("api_url", "api_key", "workspace_id");
1306
+ const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
1307
+ try {
1308
+ const profile = await client.getContactProfile(contactId);
1309
+ if (opts.json) {
1310
+ printJson(profile);
1311
+ } else {
1312
+ const contact = profile.contact ?? profile;
1313
+ console.log(chalk4.cyan("\u2500".repeat(40)));
1314
+ console.log(chalk4.cyan.bold(" Contact Profile"));
1315
+ console.log(chalk4.cyan("\u2500".repeat(40)));
1316
+ console.log(` ${chalk4.bold("Name:")} ${contact.name ?? "N/A"}`);
1317
+ console.log(` ${chalk4.bold("Email:")} ${contact.email ?? "N/A"}`);
1318
+ console.log(` ${chalk4.bold("Category:")} ${contact.category ?? "N/A"}`);
1319
+ if (contact.phone) console.log(` ${chalk4.bold("Phone:")} ${contact.phone}`);
1320
+ if (contact.notes) console.log(` ${chalk4.bold("Notes:")} ${contact.notes}`);
1321
+ const holdings = profile.equity_holdings;
1322
+ if (holdings?.length) {
1323
+ console.log(`
1324
+ ${chalk4.bold("Equity Holdings:")}`);
1325
+ for (const h of holdings) console.log(` ${h.share_class ?? "?"}: ${h.shares ?? "?"} shares`);
1326
+ }
1327
+ const obls = profile.obligations;
1328
+ if (obls?.length) console.log(`
1329
+ ${chalk4.bold("Obligations:")} ${obls.length}`);
1330
+ console.log(chalk4.cyan("\u2500".repeat(40)));
1331
+ }
1332
+ } catch (err) {
1333
+ printError(`Failed to fetch contact: ${err}`);
1334
+ process.exit(1);
1335
+ }
1336
+ }
1337
+ async function contactsAddCommand(opts) {
1338
+ const cfg = requireConfig("api_url", "api_key", "workspace_id");
1339
+ const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
1340
+ try {
1341
+ const data = { name: opts.name, email: opts.email };
1342
+ if (opts.category) data.category = opts.category;
1343
+ if (opts.phone) data.phone = opts.phone;
1344
+ if (opts.notes) data.notes = opts.notes;
1345
+ const result = await client.createContact(data);
1346
+ printSuccess(`Contact created: ${result.contact_id ?? result.id ?? "OK"}`);
1347
+ } catch (err) {
1348
+ printError(`Failed to create contact: ${err}`);
1349
+ process.exit(1);
1350
+ }
1351
+ }
1352
+ async function contactsEditCommand(contactId, opts) {
1353
+ const cfg = requireConfig("api_url", "api_key", "workspace_id");
1354
+ const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
1355
+ try {
1356
+ const data = {};
1357
+ if (opts.name != null) data.name = opts.name;
1358
+ if (opts.email != null) data.email = opts.email;
1359
+ if (opts.category != null) data.category = opts.category;
1360
+ if (opts.phone != null) data.phone = opts.phone;
1361
+ if (opts.notes != null) data.notes = opts.notes;
1362
+ if (Object.keys(data).length === 0) {
1363
+ console.log("No fields to update.");
1364
+ return;
1365
+ }
1366
+ await client.updateContact(contactId, data);
1367
+ printSuccess("Contact updated.");
1368
+ } catch (err) {
1369
+ printError(`Failed to update contact: ${err}`);
1370
+ process.exit(1);
1371
+ }
1372
+ }
1373
+ var init_contacts = __esm({
1374
+ "src/commands/contacts.ts"() {
1375
+ "use strict";
1376
+ init_config();
1377
+ init_api_client();
1378
+ init_output();
1379
+ }
1380
+ });
1381
+
1382
+ // src/commands/cap-table.ts
1383
+ var cap_table_exports = {};
1384
+ __export(cap_table_exports, {
1385
+ capTableCommand: () => capTableCommand,
1386
+ distributeCommand: () => distributeCommand,
1387
+ fourOhNineACommand: () => fourOhNineACommand,
1388
+ issueEquityCommand: () => issueEquityCommand,
1389
+ issueSafeCommand: () => issueSafeCommand,
1390
+ safesCommand: () => safesCommand,
1391
+ transferSharesCommand: () => transferSharesCommand,
1392
+ transfersCommand: () => transfersCommand,
1393
+ valuationsCommand: () => valuationsCommand
1394
+ });
1395
+ import chalk5 from "chalk";
1396
+ async function capTableCommand(opts) {
1397
+ const cfg = requireConfig("api_url", "api_key", "workspace_id");
1398
+ const eid = resolveEntityId(cfg, opts.entityId);
1399
+ const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
1400
+ try {
1401
+ const data = await client.getCapTable(eid);
1402
+ if (opts.json) {
1403
+ printJson(data);
1404
+ return;
1405
+ }
1406
+ if (data.access_level === "none") {
1407
+ printError("You do not have access to this entity's cap table.");
1408
+ process.exit(1);
1409
+ }
1410
+ printCapTable(data);
1411
+ try {
1412
+ const val = await client.getCurrent409a(eid);
1413
+ if (val) print409a(val);
1414
+ } catch {
1415
+ }
1416
+ } catch (err) {
1417
+ printError(`Failed to fetch cap table: ${err}`);
1418
+ process.exit(1);
1419
+ }
1420
+ }
1421
+ async function safesCommand(opts) {
1422
+ const cfg = requireConfig("api_url", "api_key", "workspace_id");
1423
+ const eid = resolveEntityId(cfg, opts.entityId);
1424
+ const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
1425
+ try {
1426
+ const safes = await client.getSafeNotes(eid);
1427
+ if (opts.json) printJson(safes);
1428
+ else if (safes.length === 0) console.log("No SAFE notes found.");
1429
+ else printSafesTable(safes);
1430
+ } catch (err) {
1431
+ printError(`Failed to fetch SAFE notes: ${err}`);
1432
+ process.exit(1);
1433
+ }
1434
+ }
1435
+ async function transfersCommand(opts) {
1436
+ const cfg = requireConfig("api_url", "api_key", "workspace_id");
1437
+ const eid = resolveEntityId(cfg, opts.entityId);
1438
+ const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
1439
+ try {
1440
+ const transfers = await client.getShareTransfers(eid);
1441
+ if (opts.json) printJson(transfers);
1442
+ else if (transfers.length === 0) console.log("No share transfers found.");
1443
+ else printTransfersTable(transfers);
1444
+ } catch (err) {
1445
+ printError(`Failed to fetch transfers: ${err}`);
1446
+ process.exit(1);
1447
+ }
1448
+ }
1449
+ async function valuationsCommand(opts) {
1450
+ const cfg = requireConfig("api_url", "api_key", "workspace_id");
1451
+ const eid = resolveEntityId(cfg, opts.entityId);
1452
+ const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
1453
+ try {
1454
+ const valuations = await client.getValuations(eid);
1455
+ if (opts.json) printJson(valuations);
1456
+ else if (valuations.length === 0) console.log("No valuations found.");
1457
+ else printValuationsTable(valuations);
1458
+ } catch (err) {
1459
+ printError(`Failed to fetch valuations: ${err}`);
1460
+ process.exit(1);
1461
+ }
1462
+ }
1463
+ async function fourOhNineACommand(opts) {
1464
+ const cfg = requireConfig("api_url", "api_key", "workspace_id");
1465
+ const eid = resolveEntityId(cfg, opts.entityId);
1466
+ const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
1467
+ try {
1468
+ const data = await client.getCurrent409a(eid);
1469
+ if (opts.json) printJson(data);
1470
+ else if (!data || Object.keys(data).length === 0) console.log("No 409A valuation found.");
1471
+ else print409a(data);
1472
+ } catch (err) {
1473
+ printError(`Failed to fetch 409A valuation: ${err}`);
1474
+ process.exit(1);
1475
+ }
1476
+ }
1477
+ async function issueEquityCommand(opts) {
1478
+ const cfg = requireConfig("api_url", "api_key", "workspace_id");
1479
+ const eid = resolveEntityId(cfg, opts.entityId);
1480
+ const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
1481
+ try {
1482
+ const result = await client.issueEquity({
1483
+ entity_id: eid,
1484
+ grant_type: opts.grantType,
1485
+ shares: opts.shares,
1486
+ recipient_name: opts.recipient
1487
+ });
1488
+ printSuccess(`Equity issued: ${result.grant_id ?? "OK"}`);
1489
+ printJson(result);
1490
+ } catch (err) {
1491
+ printError(`Failed to issue equity: ${err}`);
1492
+ process.exit(1);
1493
+ }
1494
+ }
1495
+ async function issueSafeCommand(opts) {
1496
+ const cfg = requireConfig("api_url", "api_key", "workspace_id");
1497
+ const eid = resolveEntityId(cfg, opts.entityId);
1498
+ const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
1499
+ try {
1500
+ const result = await client.issueSafe({
1501
+ entity_id: eid,
1502
+ investor_name: opts.investor,
1503
+ principal_amount_cents: opts.amount,
1504
+ safe_type: opts.safeType,
1505
+ valuation_cap_cents: opts.valuationCap
1506
+ });
1507
+ printSuccess(`SAFE issued: ${result.safe_note_id ?? result.safe_id ?? "OK"}`);
1508
+ printJson(result);
1509
+ } catch (err) {
1510
+ printError(`Failed to issue SAFE: ${err}`);
1511
+ process.exit(1);
1512
+ }
1513
+ }
1514
+ async function transferSharesCommand(opts) {
1515
+ const cfg = requireConfig("api_url", "api_key", "workspace_id");
1516
+ const eid = resolveEntityId(cfg, opts.entityId);
1517
+ const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
1518
+ try {
1519
+ const result = await client.transferShares({
1520
+ entity_id: eid,
1521
+ from_holder: opts.fromGrant,
1522
+ to_holder: opts.to,
1523
+ shares: opts.shares,
1524
+ transfer_type: opts.type
1525
+ });
1526
+ printSuccess(`Transfer complete: ${result.transfer_id ?? "OK"}`);
1527
+ printJson(result);
1528
+ } catch (err) {
1529
+ printError(`Failed to transfer shares: ${err}`);
1530
+ process.exit(1);
1531
+ }
1532
+ }
1533
+ async function distributeCommand(opts) {
1534
+ const cfg = requireConfig("api_url", "api_key", "workspace_id");
1535
+ const eid = resolveEntityId(cfg, opts.entityId);
1536
+ const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
1537
+ try {
1538
+ const result = await client.calculateDistribution({
1539
+ entity_id: eid,
1540
+ total_amount_cents: opts.amount,
1541
+ distribution_type: opts.type
1542
+ });
1543
+ printSuccess(`Distribution calculated: ${result.distribution_id ?? "OK"}`);
1544
+ printJson(result);
1545
+ } catch (err) {
1546
+ printError(`Failed to calculate distribution: ${err}`);
1547
+ process.exit(1);
1548
+ }
1549
+ }
1550
+ function print409a(data) {
1551
+ console.log(chalk5.green("\u2500".repeat(40)));
1552
+ console.log(chalk5.green.bold(" 409A Valuation"));
1553
+ console.log(chalk5.green("\u2500".repeat(40)));
1554
+ console.log(` ${chalk5.bold("FMV/Share:")} $${data.fmv_per_share ?? "N/A"}`);
1555
+ console.log(` ${chalk5.bold("Enterprise Value:")} $${data.enterprise_value ?? "N/A"}`);
1556
+ console.log(` ${chalk5.bold("Valuation Date:")} ${data.valuation_date ?? "N/A"}`);
1557
+ if (data.provider) console.log(` ${chalk5.bold("Provider:")} ${data.provider}`);
1558
+ console.log(chalk5.green("\u2500".repeat(40)));
1559
+ }
1560
+ var init_cap_table = __esm({
1561
+ "src/commands/cap-table.ts"() {
1562
+ "use strict";
1563
+ init_config();
1564
+ init_api_client();
1565
+ init_output();
1566
+ }
1567
+ });
1568
+
1569
+ // src/commands/finance.ts
1570
+ var finance_exports = {};
1571
+ __export(finance_exports, {
1572
+ financeClassifyContractorCommand: () => financeClassifyContractorCommand,
1573
+ financeInvoiceCommand: () => financeInvoiceCommand,
1574
+ financeOpenAccountCommand: () => financeOpenAccountCommand,
1575
+ financePayCommand: () => financePayCommand,
1576
+ financePayrollCommand: () => financePayrollCommand,
1577
+ financeReconcileCommand: () => financeReconcileCommand
1578
+ });
1579
+ async function financeInvoiceCommand(opts) {
1580
+ const cfg = requireConfig("api_url", "api_key", "workspace_id");
1581
+ const eid = resolveEntityId(cfg, opts.entityId);
1582
+ const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
1583
+ try {
1584
+ const result = await client.createInvoice({
1585
+ entity_id: eid,
1586
+ customer_name: opts.customer,
1587
+ amount_cents: opts.amount,
1588
+ due_date: opts.dueDate,
1589
+ description: opts.description
1590
+ });
1591
+ printSuccess(`Invoice created: ${result.invoice_id ?? "OK"}`);
1592
+ printJson(result);
1593
+ } catch (err) {
1594
+ printError(`Failed to create invoice: ${err}`);
1595
+ process.exit(1);
1596
+ }
1597
+ }
1598
+ async function financePayrollCommand(opts) {
1599
+ const cfg = requireConfig("api_url", "api_key", "workspace_id");
1600
+ const eid = resolveEntityId(cfg, opts.entityId);
1601
+ const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
1602
+ try {
1603
+ const result = await client.runPayroll({
1604
+ entity_id: eid,
1605
+ pay_period_start: opts.periodStart,
1606
+ pay_period_end: opts.periodEnd
1607
+ });
1608
+ printSuccess(`Payroll run created: ${result.payroll_run_id ?? "OK"}`);
1609
+ printJson(result);
1610
+ } catch (err) {
1611
+ printError(`Failed to run payroll: ${err}`);
1612
+ process.exit(1);
1613
+ }
1614
+ }
1615
+ async function financePayCommand(opts) {
1616
+ const cfg = requireConfig("api_url", "api_key", "workspace_id");
1617
+ const eid = resolveEntityId(cfg, opts.entityId);
1618
+ const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
1619
+ try {
1620
+ const result = await client.submitPayment({
1621
+ entity_id: eid,
1622
+ amount_cents: opts.amount,
1623
+ recipient: opts.recipient,
1624
+ description: `Payment via ${opts.method}`
1625
+ });
1626
+ printSuccess(`Payment submitted: ${result.payment_id ?? "OK"}`);
1627
+ printJson(result);
1628
+ } catch (err) {
1629
+ printError(`Failed to submit payment: ${err}`);
1630
+ process.exit(1);
1631
+ }
1632
+ }
1633
+ async function financeOpenAccountCommand(opts) {
1634
+ const cfg = requireConfig("api_url", "api_key", "workspace_id");
1635
+ const eid = resolveEntityId(cfg, opts.entityId);
1636
+ const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
1637
+ try {
1638
+ const result = await client.openBankAccount({ entity_id: eid, institution_name: opts.institution });
1639
+ printSuccess(`Bank account opened: ${result.account_id ?? "OK"}`);
1640
+ printJson(result);
1641
+ } catch (err) {
1642
+ printError(`Failed to open bank account: ${err}`);
1643
+ process.exit(1);
1644
+ }
1645
+ }
1646
+ async function financeClassifyContractorCommand(opts) {
1647
+ const cfg = requireConfig("api_url", "api_key", "workspace_id");
1648
+ const eid = resolveEntityId(cfg, opts.entityId);
1649
+ const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
1650
+ try {
1651
+ const result = await client.classifyContractor({
1652
+ entity_id: eid,
1653
+ contractor_name: opts.name,
1654
+ state: opts.state,
1655
+ hours_per_week: opts.hours,
1656
+ exclusive_client: opts.exclusive,
1657
+ duration_months: opts.duration,
1658
+ provides_tools: opts.providesTools
1659
+ });
1660
+ printSuccess(`Classification: ${result.risk_level ?? "OK"}`);
1661
+ printJson(result);
1662
+ } catch (err) {
1663
+ printError(`Failed to classify contractor: ${err}`);
1664
+ process.exit(1);
1665
+ }
1666
+ }
1667
+ async function financeReconcileCommand(opts) {
1668
+ const cfg = requireConfig("api_url", "api_key", "workspace_id");
1669
+ const eid = resolveEntityId(cfg, opts.entityId);
1670
+ const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
1671
+ try {
1672
+ const result = await client.reconcileLedger({
1673
+ entity_id: eid,
1674
+ start_date: opts.startDate,
1675
+ end_date: opts.endDate
1676
+ });
1677
+ printSuccess(`Ledger reconciled: ${result.reconciliation_id ?? "OK"}`);
1678
+ printJson(result);
1679
+ } catch (err) {
1680
+ printError(`Failed to reconcile ledger: ${err}`);
1681
+ process.exit(1);
1682
+ }
1683
+ }
1684
+ var init_finance = __esm({
1685
+ "src/commands/finance.ts"() {
1686
+ "use strict";
1687
+ init_config();
1688
+ init_api_client();
1689
+ init_output();
1690
+ }
1691
+ });
1692
+
1693
+ // src/commands/governance.ts
1694
+ var governance_exports = {};
1695
+ __export(governance_exports, {
1696
+ governanceConveneCommand: () => governanceConveneCommand,
1697
+ governanceListCommand: () => governanceListCommand,
1698
+ governanceMeetingsCommand: () => governanceMeetingsCommand,
1699
+ governanceResolutionsCommand: () => governanceResolutionsCommand,
1700
+ governanceSeatsCommand: () => governanceSeatsCommand,
1701
+ governanceVoteCommand: () => governanceVoteCommand
1702
+ });
1703
+ async function governanceListCommand(opts) {
1704
+ const cfg = requireConfig("api_url", "api_key", "workspace_id");
1705
+ const eid = resolveEntityId(cfg, opts.entityId);
1706
+ const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
1707
+ try {
1708
+ const bodies = await client.listGovernanceBodies(eid);
1709
+ if (opts.json) printJson(bodies);
1710
+ else if (bodies.length === 0) console.log("No governance bodies found.");
1711
+ else printGovernanceTable(bodies);
1712
+ } catch (err) {
1713
+ printError(`Failed to fetch governance bodies: ${err}`);
1714
+ process.exit(1);
1715
+ }
1716
+ }
1717
+ async function governanceSeatsCommand(bodyId, opts) {
1718
+ const cfg = requireConfig("api_url", "api_key", "workspace_id");
1719
+ const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
1720
+ try {
1721
+ const seats = await client.getGovernanceSeats(bodyId);
1722
+ if (opts.json) printJson(seats);
1723
+ else if (seats.length === 0) console.log("No seats found.");
1724
+ else printSeatsTable(seats);
1725
+ } catch (err) {
1726
+ printError(`Failed to fetch seats: ${err}`);
1727
+ process.exit(1);
1728
+ }
1729
+ }
1730
+ async function governanceMeetingsCommand(bodyId, opts) {
1731
+ const cfg = requireConfig("api_url", "api_key", "workspace_id");
1732
+ const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
1733
+ try {
1734
+ const meetings = await client.listMeetings(bodyId);
1735
+ if (opts.json) printJson(meetings);
1736
+ else if (meetings.length === 0) console.log("No meetings found.");
1737
+ else printMeetingsTable(meetings);
1738
+ } catch (err) {
1739
+ printError(`Failed to fetch meetings: ${err}`);
1740
+ process.exit(1);
1741
+ }
1742
+ }
1743
+ async function governanceResolutionsCommand(meetingId, opts) {
1744
+ const cfg = requireConfig("api_url", "api_key", "workspace_id");
1745
+ const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
1746
+ try {
1747
+ const resolutions = await client.getMeetingResolutions(meetingId);
1748
+ if (opts.json) printJson(resolutions);
1749
+ else if (resolutions.length === 0) console.log("No resolutions found.");
1750
+ else printResolutionsTable(resolutions);
1751
+ } catch (err) {
1752
+ printError(`Failed to fetch resolutions: ${err}`);
1753
+ process.exit(1);
1754
+ }
1755
+ }
1756
+ async function governanceConveneCommand(opts) {
1757
+ const cfg = requireConfig("api_url", "api_key", "workspace_id");
1758
+ const eid = resolveEntityId(cfg, opts.entityId);
1759
+ const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
1760
+ try {
1761
+ const result = await client.conveneMeeting({
1762
+ entity_id: eid,
1763
+ governance_body_id: opts.body,
1764
+ meeting_type: opts.meetingType,
1765
+ title: opts.title,
1766
+ scheduled_date: opts.date,
1767
+ agenda_items: opts.agenda.map((item) => ({ title: item }))
1768
+ });
1769
+ printSuccess(`Meeting convened: ${result.meeting_id ?? "OK"}`);
1770
+ printJson(result);
1771
+ } catch (err) {
1772
+ printError(`Failed to convene meeting: ${err}`);
1773
+ process.exit(1);
1774
+ }
1775
+ }
1776
+ async function governanceVoteCommand(meetingId, itemId, opts) {
1777
+ const cfg = requireConfig("api_url", "api_key", "workspace_id");
1778
+ const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
1779
+ try {
1780
+ const result = await client.castVote(meetingId, itemId, {
1781
+ voter_id: opts.voter,
1782
+ vote_value: opts.vote
1783
+ });
1784
+ printSuccess(`Vote cast: ${result.vote_id ?? "OK"}`);
1785
+ printJson(result);
1786
+ } catch (err) {
1787
+ printError(`Failed to cast vote: ${err}`);
1788
+ process.exit(1);
1789
+ }
1790
+ }
1791
+ var init_governance = __esm({
1792
+ "src/commands/governance.ts"() {
1793
+ "use strict";
1794
+ init_config();
1795
+ init_api_client();
1796
+ init_output();
1797
+ }
1798
+ });
1799
+
1800
+ // src/commands/documents.ts
1801
+ var documents_exports = {};
1802
+ __export(documents_exports, {
1803
+ documentsGenerateCommand: () => documentsGenerateCommand,
1804
+ documentsListCommand: () => documentsListCommand,
1805
+ documentsSigningLinkCommand: () => documentsSigningLinkCommand
1806
+ });
1807
+ async function documentsListCommand(opts) {
1808
+ const cfg = requireConfig("api_url", "api_key", "workspace_id");
1809
+ const eid = resolveEntityId(cfg, opts.entityId);
1810
+ const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
1811
+ try {
1812
+ const docs = await client.getEntityDocuments(eid);
1813
+ if (opts.json) printJson(docs);
1814
+ else if (docs.length === 0) console.log("No documents found.");
1815
+ else printDocumentsTable(docs);
1816
+ } catch (err) {
1817
+ printError(`Failed to fetch documents: ${err}`);
1818
+ process.exit(1);
1819
+ }
1820
+ }
1821
+ async function documentsSigningLinkCommand(docId) {
1822
+ const cfg = requireConfig("api_url", "api_key", "workspace_id");
1823
+ const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
1824
+ try {
1825
+ const result = client.getSigningLink(docId);
1826
+ printSuccess(`Signing link: ${result.signing_url}`);
1827
+ console.log("Open this link in your browser to sign the document.");
1828
+ } catch (err) {
1829
+ printError(`Failed to get signing link: ${err}`);
1830
+ process.exit(1);
1831
+ }
1832
+ }
1833
+ async function documentsGenerateCommand(opts) {
1834
+ const cfg = requireConfig("api_url", "api_key", "workspace_id");
1835
+ const eid = resolveEntityId(cfg, opts.entityId);
1836
+ const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
1837
+ try {
1838
+ const result = await client.generateContract({
1839
+ entity_id: eid,
1840
+ template_type: opts.template,
1841
+ parameters: { counterparty_name: opts.counterparty, effective_date: opts.effectiveDate ?? "" }
1842
+ });
1843
+ printSuccess(`Contract generated: ${result.contract_id ?? "OK"}`);
1844
+ printJson(result);
1845
+ } catch (err) {
1846
+ printError(`Failed to generate contract: ${err}`);
1847
+ process.exit(1);
1848
+ }
1849
+ }
1850
+ var init_documents = __esm({
1851
+ "src/commands/documents.ts"() {
1852
+ "use strict";
1853
+ init_config();
1854
+ init_api_client();
1855
+ init_output();
1856
+ }
1857
+ });
1858
+
1859
+ // src/commands/tax.ts
1860
+ var tax_exports = {};
1861
+ __export(tax_exports, {
1862
+ taxDeadlineCommand: () => taxDeadlineCommand,
1863
+ taxFileCommand: () => taxFileCommand
1864
+ });
1865
+ async function taxFileCommand(opts) {
1866
+ const cfg = requireConfig("api_url", "api_key", "workspace_id");
1867
+ const eid = resolveEntityId(cfg, opts.entityId);
1868
+ const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
1869
+ try {
1870
+ const result = await client.fileTaxDocument({ entity_id: eid, document_type: opts.type, tax_year: opts.year });
1871
+ printSuccess(`Tax document filed: ${result.filing_id ?? "OK"}`);
1872
+ printJson(result);
1873
+ } catch (err) {
1874
+ printError(`Failed to file tax document: ${err}`);
1875
+ process.exit(1);
1876
+ }
1877
+ }
1878
+ async function taxDeadlineCommand(opts) {
1879
+ const cfg = requireConfig("api_url", "api_key", "workspace_id");
1880
+ const eid = resolveEntityId(cfg, opts.entityId);
1881
+ const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
1882
+ try {
1883
+ const result = await client.trackDeadline({
1884
+ entity_id: eid,
1885
+ deadline_type: opts.type,
1886
+ due_date: opts.dueDate,
1887
+ description: opts.description,
1888
+ recurrence: opts.recurrence ?? ""
1889
+ });
1890
+ printSuccess(`Deadline tracked: ${result.deadline_id ?? "OK"}`);
1891
+ printJson(result);
1892
+ } catch (err) {
1893
+ printError(`Failed to track deadline: ${err}`);
1894
+ process.exit(1);
1895
+ }
1896
+ }
1897
+ var init_tax = __esm({
1898
+ "src/commands/tax.ts"() {
1899
+ "use strict";
1900
+ init_config();
1901
+ init_api_client();
1902
+ init_output();
1903
+ }
1904
+ });
1905
+
1906
+ // src/commands/agents.ts
1907
+ var agents_exports = {};
1908
+ __export(agents_exports, {
1909
+ agentsCreateCommand: () => agentsCreateCommand,
1910
+ agentsDeleteCommand: () => agentsDeleteCommand,
1911
+ agentsExecutionsCommand: () => agentsExecutionsCommand,
1912
+ agentsListCommand: () => agentsListCommand,
1913
+ agentsMessageCommand: () => agentsMessageCommand,
1914
+ agentsPauseCommand: () => agentsPauseCommand,
1915
+ agentsResumeCommand: () => agentsResumeCommand,
1916
+ agentsShowCommand: () => agentsShowCommand,
1917
+ agentsSkillCommand: () => agentsSkillCommand
1918
+ });
1919
+ import chalk6 from "chalk";
1920
+ import Table2 from "cli-table3";
1921
+ async function agentsListCommand(opts) {
1922
+ const cfg = requireConfig("api_url", "api_key", "workspace_id");
1923
+ const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
1924
+ try {
1925
+ const agents = await client.listAgents();
1926
+ if (opts.json) printJson(agents);
1927
+ else if (agents.length === 0) console.log("No agents found.");
1928
+ else printAgentsTable(agents);
1929
+ } catch (err) {
1930
+ printError(`Failed to fetch agents: ${err}`);
1931
+ process.exit(1);
1932
+ }
1933
+ }
1934
+ async function agentsShowCommand(agentId, opts) {
1935
+ const cfg = requireConfig("api_url", "api_key", "workspace_id");
1936
+ const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
1937
+ try {
1938
+ const agent = await client.getAgent(agentId);
1939
+ let usage = {};
1940
+ try {
1941
+ usage = await client.getAgentUsage(agentId);
1942
+ } catch {
1943
+ }
1944
+ if (opts.json) {
1945
+ printJson({ agent, usage });
1946
+ return;
1947
+ }
1948
+ console.log(chalk6.magenta("\u2500".repeat(40)));
1949
+ console.log(chalk6.magenta.bold(" Agent Detail"));
1950
+ console.log(chalk6.magenta("\u2500".repeat(40)));
1951
+ console.log(` ${chalk6.bold("Name:")} ${agent.name ?? "N/A"}`);
1952
+ console.log(` ${chalk6.bold("Status:")} ${agent.status ?? "N/A"}`);
1953
+ console.log(` ${chalk6.bold("Model:")} ${agent.model ?? "N/A"}`);
1954
+ console.log(` ${chalk6.bold("ID:")} ${agent.agent_id ?? "N/A"}`);
1955
+ if (agent.system_prompt) {
1956
+ let prompt = String(agent.system_prompt);
1957
+ if (prompt.length > 100) prompt = prompt.slice(0, 97) + "...";
1958
+ console.log(` ${chalk6.bold("Prompt:")} ${prompt}`);
1959
+ }
1960
+ if (Object.keys(usage).length > 0) {
1961
+ console.log(`
1962
+ ${chalk6.bold("Usage:")}`);
1963
+ for (const [k, v] of Object.entries(usage)) {
1964
+ if (k !== "agent_id") console.log(` ${k}: ${v}`);
1965
+ }
1966
+ }
1967
+ console.log(chalk6.magenta("\u2500".repeat(40)));
1968
+ } catch (err) {
1969
+ printError(`Failed to fetch agent: ${err}`);
1970
+ process.exit(1);
1971
+ }
1972
+ }
1973
+ async function agentsCreateCommand(opts) {
1974
+ const cfg = requireConfig("api_url", "api_key", "workspace_id");
1975
+ const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
1976
+ try {
1977
+ const data = { name: opts.name, system_prompt: opts.prompt };
1978
+ if (opts.model) data.model = opts.model;
1979
+ const result = await client.createAgent(data);
1980
+ printSuccess(`Agent created: ${result.agent_id ?? result.id ?? "OK"}`);
1981
+ } catch (err) {
1982
+ printError(`Failed to create agent: ${err}`);
1983
+ process.exit(1);
1984
+ }
1985
+ }
1986
+ async function agentsPauseCommand(agentId) {
1987
+ const cfg = requireConfig("api_url", "api_key", "workspace_id");
1988
+ const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
1989
+ try {
1990
+ await client.updateAgent(agentId, { status: "paused" });
1991
+ printSuccess(`Agent ${agentId} paused.`);
1992
+ } catch (err) {
1993
+ printError(`Failed to pause agent: ${err}`);
1994
+ process.exit(1);
1995
+ }
1996
+ }
1997
+ async function agentsResumeCommand(agentId) {
1998
+ const cfg = requireConfig("api_url", "api_key", "workspace_id");
1999
+ const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
2000
+ try {
2001
+ await client.updateAgent(agentId, { status: "active" });
2002
+ printSuccess(`Agent ${agentId} resumed.`);
2003
+ } catch (err) {
2004
+ printError(`Failed to resume agent: ${err}`);
2005
+ process.exit(1);
2006
+ }
2007
+ }
2008
+ async function agentsDeleteCommand(agentId) {
2009
+ const cfg = requireConfig("api_url", "api_key", "workspace_id");
2010
+ const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
2011
+ try {
2012
+ await client.deleteAgent(agentId);
2013
+ printSuccess(`Agent ${agentId} deleted.`);
2014
+ } catch (err) {
2015
+ printError(`Failed to delete agent: ${err}`);
2016
+ process.exit(1);
2017
+ }
2018
+ }
2019
+ async function agentsMessageCommand(agentId, opts) {
2020
+ const cfg = requireConfig("api_url", "api_key", "workspace_id");
2021
+ const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
2022
+ try {
2023
+ const result = await client.sendAgentMessage(agentId, opts.body);
2024
+ printSuccess(`Message sent. Execution: ${result.execution_id ?? "OK"}`);
2025
+ } catch (err) {
2026
+ printError(`Failed to send message: ${err}`);
2027
+ process.exit(1);
2028
+ }
2029
+ }
2030
+ async function agentsExecutionsCommand(agentId, opts) {
2031
+ const cfg = requireConfig("api_url", "api_key", "workspace_id");
2032
+ const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
2033
+ try {
2034
+ const executions = await client.listAgentExecutions(agentId);
2035
+ if (opts.json) {
2036
+ printJson(executions);
2037
+ return;
2038
+ }
2039
+ if (executions.length === 0) {
2040
+ console.log("No executions found.");
2041
+ return;
2042
+ }
2043
+ console.log(`
2044
+ ${chalk6.bold("Agent Executions")}`);
2045
+ const table = new Table2({ head: [chalk6.dim("ID"), chalk6.dim("Status"), chalk6.dim("Started"), chalk6.dim("Duration")] });
2046
+ for (const ex of executions) {
2047
+ table.push([
2048
+ String(ex.execution_id ?? "").slice(0, 12),
2049
+ String(ex.status ?? ""),
2050
+ String(ex.started_at ?? ""),
2051
+ String(ex.duration ?? "")
2052
+ ]);
2053
+ }
2054
+ console.log(table.toString());
2055
+ } catch (err) {
2056
+ printError(`Failed to fetch executions: ${err}`);
2057
+ process.exit(1);
2058
+ }
2059
+ }
2060
+ async function agentsSkillCommand(agentId, opts) {
2061
+ const cfg = requireConfig("api_url", "api_key", "workspace_id");
2062
+ const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
2063
+ try {
2064
+ const result = await client.addAgentSkill(agentId, {
2065
+ skill_name: opts.name,
2066
+ description: opts.description,
2067
+ instructions: opts.instructions ?? ""
2068
+ });
2069
+ printSuccess(`Skill '${opts.name}' added to agent ${agentId}.`);
2070
+ printJson(result);
2071
+ } catch (err) {
2072
+ printError(`Failed to add skill: ${err}`);
2073
+ process.exit(1);
2074
+ }
2075
+ }
2076
+ var init_agents = __esm({
2077
+ "src/commands/agents.ts"() {
2078
+ "use strict";
2079
+ init_config();
2080
+ init_api_client();
2081
+ init_output();
2082
+ }
2083
+ });
2084
+
2085
+ // src/commands/billing.ts
2086
+ var billing_exports = {};
2087
+ __export(billing_exports, {
2088
+ billingCommand: () => billingCommand,
2089
+ billingPortalCommand: () => billingPortalCommand,
2090
+ billingUpgradeCommand: () => billingUpgradeCommand
2091
+ });
2092
+ import { execSync } from "child_process";
2093
+ function makeClient() {
2094
+ const cfg = requireConfig("api_url", "api_key", "workspace_id");
2095
+ return new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
2096
+ }
2097
+ function openUrl(url) {
2098
+ try {
2099
+ const cmd = process.platform === "darwin" ? "open" : process.platform === "win32" ? "start" : "xdg-open";
2100
+ execSync(`${cmd} ${JSON.stringify(url)}`, { stdio: "ignore" });
2101
+ } catch {
2102
+ }
2103
+ }
2104
+ async function billingCommand(opts) {
2105
+ const client = makeClient();
2106
+ try {
2107
+ const [status, plans] = await Promise.all([client.getBillingStatus(), client.getBillingPlans()]);
2108
+ if (opts.json) printJson({ status, plans });
2109
+ else printBillingPanel(status, plans);
2110
+ } catch (err) {
2111
+ printError(`Failed to fetch billing info: ${err}`);
2112
+ process.exit(1);
2113
+ }
2114
+ }
2115
+ async function billingPortalCommand() {
2116
+ const client = makeClient();
2117
+ try {
2118
+ const result = await client.createBillingPortal();
2119
+ const url = result.portal_url;
2120
+ if (!url) {
2121
+ printError("No portal URL returned. Ensure you have an active subscription.");
2122
+ process.exit(1);
2123
+ }
2124
+ console.log(`Opening Stripe Customer Portal...
2125
+ ${url}`);
2126
+ openUrl(url);
2127
+ printSuccess("Portal opened in your browser.");
2128
+ } catch (err) {
2129
+ printError(`Failed to create portal session: ${err}`);
2130
+ process.exit(1);
2131
+ }
2132
+ }
2133
+ async function billingUpgradeCommand(opts) {
2134
+ const client = makeClient();
2135
+ try {
2136
+ const result = await client.createBillingCheckout(opts.tier);
2137
+ const url = result.checkout_url;
2138
+ if (!url) {
2139
+ printError("No checkout URL returned.");
2140
+ process.exit(1);
2141
+ }
2142
+ console.log(`Opening Stripe Checkout for ${opts.tier}...
2143
+ ${url}`);
2144
+ openUrl(url);
2145
+ printSuccess("Checkout opened in your browser.");
2146
+ } catch (err) {
2147
+ printError(`Failed to create checkout session: ${err}`);
2148
+ process.exit(1);
2149
+ }
2150
+ }
2151
+ var init_billing = __esm({
2152
+ "src/commands/billing.ts"() {
2153
+ "use strict";
2154
+ init_config();
2155
+ init_api_client();
2156
+ init_output();
2157
+ }
2158
+ });
2159
+
2160
+ // src/commands/approvals.ts
2161
+ var approvals_exports = {};
2162
+ __export(approvals_exports, {
2163
+ approvalsListCommand: () => approvalsListCommand,
2164
+ approvalsRespondCommand: () => approvalsRespondCommand
2165
+ });
2166
+ async function approvalsListCommand(opts) {
2167
+ const cfg = requireConfig("api_url", "api_key", "workspace_id");
2168
+ const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
2169
+ try {
2170
+ const approvals = await client.listPendingApprovals();
2171
+ if (opts.json) printJson(approvals);
2172
+ else if (approvals.length === 0) console.log("No pending approvals.");
2173
+ else printApprovalsTable(approvals);
2174
+ } catch (err) {
2175
+ printError(`Failed to fetch approvals: ${err}`);
2176
+ process.exit(1);
2177
+ }
2178
+ }
2179
+ async function approvalsRespondCommand(approvalId, decision, opts) {
2180
+ const cfg = requireConfig("api_url", "api_key", "workspace_id");
2181
+ const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
2182
+ try {
2183
+ await client.respondApproval(approvalId, decision, opts.message);
2184
+ printSuccess(`Approval ${approvalId} ${decision}d.`);
2185
+ } catch (err) {
2186
+ printError(`Failed to respond to approval: ${err}`);
2187
+ process.exit(1);
2188
+ }
2189
+ }
2190
+ var init_approvals = __esm({
2191
+ "src/commands/approvals.ts"() {
2192
+ "use strict";
2193
+ init_config();
2194
+ init_api_client();
2195
+ init_output();
2196
+ }
2197
+ });
2198
+
2199
+ // src/commands/form.ts
2200
+ var form_exports = {};
2201
+ __export(form_exports, {
2202
+ formCommand: () => formCommand
2203
+ });
2204
+ import { input as input2, select } from "@inquirer/prompts";
2205
+ async function formCommand(opts) {
2206
+ const cfg = requireConfig("api_url", "api_key", "workspace_id");
2207
+ const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
2208
+ try {
2209
+ let serverCfg = {};
2210
+ try {
2211
+ serverCfg = await client.getConfig();
2212
+ } catch {
2213
+ }
2214
+ let entityType = opts.type;
2215
+ if (!entityType) {
2216
+ const types = serverCfg.entity_types ?? ["llc", "c_corp", "s_corp"];
2217
+ entityType = await select({ message: "Entity type", choices: types.map((t) => ({ value: t, name: t })) });
2218
+ }
2219
+ let name = opts.name;
2220
+ if (!name) {
2221
+ name = await input2({ message: "Entity name" });
2222
+ }
2223
+ let jurisdiction = opts.jurisdiction;
2224
+ if (!jurisdiction) {
2225
+ const jurisdictions = serverCfg.jurisdictions ?? ["DE", "WY", "NV", "CA"];
2226
+ jurisdiction = await select({
2227
+ message: "Jurisdiction",
2228
+ choices: jurisdictions.map((j) => ({ value: j, name: j })),
2229
+ default: "DE"
2230
+ });
2231
+ }
2232
+ const parsedMembers = [];
2233
+ if (opts.member && opts.member.length > 0) {
2234
+ for (const m of opts.member) {
2235
+ const parts = m.split(",").map((p) => p.trim());
2236
+ if (parts.length < 3) {
2237
+ printError(`Invalid member format: ${m}. Expected: name,email,role[,ownership_pct]`);
2238
+ process.exit(1);
2239
+ }
2240
+ const member = { name: parts[0], email: parts[1], role: parts[2] };
2241
+ if (parts.length >= 4) member.ownership_pct = parseFloat(parts[3]);
2242
+ parsedMembers.push(member);
2243
+ }
2244
+ } else {
2245
+ console.log("Add members (leave name blank to finish):");
2246
+ while (true) {
2247
+ const mname = await input2({ message: " Member name (blank to finish)", default: "" });
2248
+ if (!mname) break;
2249
+ const memail = await input2({ message: " Email" });
2250
+ const mrole = await input2({ message: " Role", default: "founder" });
2251
+ const mpctStr = await input2({ message: " Ownership %", default: "0" });
2252
+ parsedMembers.push({
2253
+ name: mname,
2254
+ email: memail,
2255
+ role: mrole,
2256
+ ownership_pct: parseFloat(mpctStr)
2257
+ });
2258
+ }
2259
+ }
2260
+ for (const m of parsedMembers) {
2261
+ if (!m.investor_type) m.investor_type = "natural_person";
2262
+ }
2263
+ const result = await client.createFormation({
2264
+ entity_type: entityType,
2265
+ legal_name: name,
2266
+ jurisdiction,
2267
+ members: parsedMembers
2268
+ });
2269
+ printSuccess(`Formation created: ${result.formation_id ?? result.id ?? "OK"}`);
2270
+ if (result.entity_id) console.log(`Entity ID: ${result.entity_id}`);
2271
+ } catch (err) {
2272
+ if (err instanceof Error && err.message.includes("exit")) throw err;
2273
+ printError(`Failed to create formation: ${err}`);
2274
+ process.exit(1);
2275
+ }
2276
+ }
2277
+ var init_form = __esm({
2278
+ "src/commands/form.ts"() {
2279
+ "use strict";
2280
+ init_config();
2281
+ init_api_client();
2282
+ init_output();
2283
+ }
2284
+ });
2285
+
2286
+ // src/commands/api-keys.ts
2287
+ var api_keys_exports = {};
2288
+ __export(api_keys_exports, {
2289
+ apiKeysCommand: () => apiKeysCommand
2290
+ });
2291
+ import chalk7 from "chalk";
2292
+ import Table3 from "cli-table3";
2293
+ async function apiKeysCommand(opts) {
2294
+ const cfg = requireConfig("api_url", "api_key", "workspace_id");
2295
+ const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
2296
+ try {
2297
+ const keys = await client.listApiKeys();
2298
+ if (opts.json) {
2299
+ printJson(keys);
2300
+ return;
2301
+ }
2302
+ if (keys.length === 0) {
2303
+ console.log("No API keys found.");
2304
+ return;
2305
+ }
2306
+ console.log(`
2307
+ ${chalk7.bold("API Keys")}`);
2308
+ const table = new Table3({
2309
+ head: [chalk7.dim("ID"), chalk7.dim("Name"), chalk7.dim("Key"), chalk7.dim("Created"), chalk7.dim("Last Used")]
2310
+ });
2311
+ for (const k of keys) {
2312
+ table.push([
2313
+ String(k.id ?? k.api_key_id ?? "").slice(0, 12),
2314
+ String(k.name ?? ""),
2315
+ maskKey(String(k.key ?? k.api_key ?? "")),
2316
+ String(k.created_at ?? ""),
2317
+ String(k.last_used_at ?? "")
2318
+ ]);
2319
+ }
2320
+ console.log(table.toString());
2321
+ } catch (err) {
2322
+ printError(`Failed to fetch API keys: ${err}`);
2323
+ process.exit(1);
2324
+ }
2325
+ }
2326
+ var init_api_keys = __esm({
2327
+ "src/commands/api-keys.ts"() {
2328
+ "use strict";
2329
+ init_config();
2330
+ init_api_client();
2331
+ init_output();
2332
+ }
2333
+ });
2334
+
2335
+ // src/commands/demo.ts
2336
+ var demo_exports = {};
2337
+ __export(demo_exports, {
2338
+ demoCommand: () => demoCommand
2339
+ });
2340
+ async function demoCommand(opts) {
2341
+ const cfg = requireConfig("api_url", "api_key", "workspace_id");
2342
+ const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
2343
+ try {
2344
+ const result = await withSpinner("Loading", () => client.seedDemo(opts.name));
2345
+ printSuccess(`Demo seeded: ${result.entity_id ?? "OK"}`);
2346
+ printJson(result);
2347
+ } catch (err) {
2348
+ printError(`Failed to seed demo: ${err}`);
2349
+ process.exit(1);
2350
+ }
2351
+ }
2352
+ var init_demo = __esm({
2353
+ "src/commands/demo.ts"() {
2354
+ "use strict";
2355
+ init_config();
2356
+ init_api_client();
2357
+ init_output();
2358
+ init_spinner();
2359
+ }
2360
+ });
2361
+
2362
+ // src/commands/serve.ts
2363
+ var serve_exports = {};
2364
+ __export(serve_exports, {
2365
+ serveCommand: () => serveCommand
2366
+ });
2367
+ async function serveCommand(opts) {
2368
+ let server;
2369
+ try {
2370
+ server = await import("@thecorporation/server");
2371
+ } catch {
2372
+ console.error(
2373
+ "Error: @thecorporation/server is not installed.\n\nInstall it with:\n npm install @thecorporation/server\n\nOr run the Rust binary directly:\n cd services/api-rs && cargo run"
2374
+ );
2375
+ process.exit(1);
2376
+ }
2377
+ if (!server.isAvailable()) {
2378
+ console.error(
2379
+ "Error: No server binary available for this platform.\n\nPre-built binaries are available for:\n - linux-x64, linux-arm64\n - darwin-x64, darwin-arm64\n - win32-x64\n\nYou can build from source:\n cd services/api-rs && cargo build --release"
2380
+ );
2381
+ process.exit(1);
2382
+ }
2383
+ const port = parseInt(opts.port, 10);
2384
+ if (isNaN(port) || port < 1 || port > 65535) {
2385
+ console.error(`Error: Invalid port "${opts.port}"`);
2386
+ process.exit(1);
2387
+ }
2388
+ console.log(`Starting server on port ${port}...`);
2389
+ console.log(`Data directory: ${opts.dataDir}`);
2390
+ const child = server.startServer({
2391
+ port,
2392
+ dataDir: opts.dataDir
2393
+ });
2394
+ const shutdown = () => {
2395
+ console.log("\nShutting down server...");
2396
+ child.kill("SIGTERM");
2397
+ };
2398
+ process.on("SIGINT", shutdown);
2399
+ process.on("SIGTERM", shutdown);
2400
+ child.on("exit", (code) => {
2401
+ process.exit(code ?? 0);
2402
+ });
2403
+ }
2404
+ var init_serve = __esm({
2405
+ "src/commands/serve.ts"() {
2406
+ "use strict";
2407
+ }
2408
+ });
2409
+
2410
+ // src/index.ts
2411
+ import { Command } from "commander";
2412
+ var program = new Command();
2413
+ program.name("corp").description("corp \u2014 Corporate governance from the terminal").version("0.1.0");
2414
+ program.command("setup").description("Interactive setup wizard").action(async () => {
2415
+ const { setupCommand: setupCommand2 } = await Promise.resolve().then(() => (init_setup(), setup_exports));
2416
+ await setupCommand2();
2417
+ });
2418
+ program.command("status").description("Workspace summary").action(async () => {
2419
+ const { statusCommand: statusCommand2 } = await Promise.resolve().then(() => (init_status(), status_exports));
2420
+ await statusCommand2();
2421
+ });
2422
+ var configCmd = program.command("config").description("Manage configuration");
2423
+ configCmd.command("set <key> <value>").description("Set a config value (dot-path)").action(async (key, value) => {
2424
+ const { configSetCommand: configSetCommand2 } = await Promise.resolve().then(() => (init_config2(), config_exports));
2425
+ configSetCommand2(key, value);
2426
+ });
2427
+ configCmd.command("get <key>").description("Get a config value (dot-path)").action(async (key) => {
2428
+ const { configGetCommand: configGetCommand2 } = await Promise.resolve().then(() => (init_config2(), config_exports));
2429
+ configGetCommand2(key);
2430
+ });
2431
+ configCmd.command("list").description("List all config (API keys masked)").action(async () => {
2432
+ const { configListCommand: configListCommand2 } = await Promise.resolve().then(() => (init_config2(), config_exports));
2433
+ configListCommand2();
2434
+ });
2435
+ program.command("obligations").description("List obligations with urgency tiers").option("--tier <tier>", "Filter by urgency tier").option("--json", "Output as JSON").action(async (opts) => {
2436
+ const { obligationsCommand: obligationsCommand2 } = await Promise.resolve().then(() => (init_obligations(), obligations_exports));
2437
+ await obligationsCommand2(opts);
2438
+ });
2439
+ program.command("digest").description("View or trigger daily digests").option("--trigger", "Trigger digest now").option("--key <key>", "Get specific digest by key").action(async (opts) => {
2440
+ const { digestCommand: digestCommand2 } = await Promise.resolve().then(() => (init_digest(), digest_exports));
2441
+ await digestCommand2(opts);
2442
+ });
2443
+ program.command("link").description("Generate a claim code to pair another device").action(async () => {
2444
+ const { linkCommand: linkCommand2 } = await Promise.resolve().then(() => (init_link(), link_exports));
2445
+ await linkCommand2();
2446
+ });
2447
+ program.command("claim <code>").description("Redeem a claim code to join a workspace").action(async (code) => {
2448
+ const { claimCommand: claimCommand2 } = await Promise.resolve().then(() => (init_claim(), claim_exports));
2449
+ await claimCommand2(code);
2450
+ });
2451
+ program.command("chat").description("Interactive LLM chat session").action(async () => {
2452
+ const { chatCommand: chatCommand2 } = await Promise.resolve().then(() => (init_chat(), chat_exports));
2453
+ await chatCommand2();
2454
+ });
2455
+ var entitiesCmd = program.command("entities").description("List entities, show detail, convert, or dissolve").option("--json", "Output as JSON").action(async (opts) => {
2456
+ const { entitiesCommand: entitiesCommand2 } = await Promise.resolve().then(() => (init_entities(), entities_exports));
2457
+ await entitiesCommand2(opts);
2458
+ });
2459
+ entitiesCmd.command("show <entity-id>").option("--json", "Output as JSON").description("Show entity detail").action(async (entityId, opts) => {
2460
+ const { entitiesShowCommand: entitiesShowCommand2 } = await Promise.resolve().then(() => (init_entities(), entities_exports));
2461
+ await entitiesShowCommand2(entityId, opts);
2462
+ });
2463
+ entitiesCmd.command("convert <entity-id>").requiredOption("--to <type>", "Target entity type (llc, corporation)").option("--jurisdiction <jurisdiction>", "New jurisdiction").description("Convert entity to a different type").action(async (entityId, opts) => {
2464
+ const { entitiesConvertCommand: entitiesConvertCommand2 } = await Promise.resolve().then(() => (init_entities(), entities_exports));
2465
+ await entitiesConvertCommand2(entityId, opts);
2466
+ });
2467
+ entitiesCmd.command("dissolve <entity-id>").requiredOption("--reason <reason>", "Dissolution reason").option("--effective-date <date>", "Effective date (ISO 8601)").description("Dissolve an entity").action(async (entityId, opts) => {
2468
+ const { entitiesDissolveCommand: entitiesDissolveCommand2 } = await Promise.resolve().then(() => (init_entities(), entities_exports));
2469
+ await entitiesDissolveCommand2(entityId, opts);
2470
+ });
2471
+ var contactsCmd = program.command("contacts").description("Contact management").option("--json", "Output as JSON").action(async (opts) => {
2472
+ const { contactsListCommand: contactsListCommand2 } = await Promise.resolve().then(() => (init_contacts(), contacts_exports));
2473
+ await contactsListCommand2(opts);
2474
+ });
2475
+ contactsCmd.command("show <contact-id>").option("--json", "Output as JSON").description("Show contact detail/profile").action(async (contactId, opts) => {
2476
+ const { contactsShowCommand: contactsShowCommand2 } = await Promise.resolve().then(() => (init_contacts(), contacts_exports));
2477
+ await contactsShowCommand2(contactId, opts);
2478
+ });
2479
+ contactsCmd.command("add").requiredOption("--name <name>", "Contact name").requiredOption("--email <email>", "Contact email").option("--category <category>", "Contact category").option("--phone <phone>", "Phone number").option("--notes <notes>", "Notes").description("Add a new contact").action(async (opts) => {
2480
+ const { contactsAddCommand: contactsAddCommand2 } = await Promise.resolve().then(() => (init_contacts(), contacts_exports));
2481
+ await contactsAddCommand2(opts);
2482
+ });
2483
+ contactsCmd.command("edit <contact-id>").option("--name <name>", "Contact name").option("--email <email>", "Contact email").option("--category <category>", "Contact category").option("--phone <phone>", "Phone number").option("--notes <notes>", "Notes").description("Edit an existing contact").action(async (contactId, opts) => {
2484
+ const { contactsEditCommand: contactsEditCommand2 } = await Promise.resolve().then(() => (init_contacts(), contacts_exports));
2485
+ await contactsEditCommand2(contactId, opts);
2486
+ });
2487
+ var capTableCmd = program.command("cap-table").description("Cap table, SAFEs, transfers, valuations").option("--entity-id <id>", "Entity ID (overrides active entity)").option("--json", "Output as JSON").action(async (opts) => {
2488
+ const { capTableCommand: capTableCommand2 } = await Promise.resolve().then(() => (init_cap_table(), cap_table_exports));
2489
+ await capTableCommand2(opts);
2490
+ });
2491
+ capTableCmd.command("safes").description("SAFE notes").action(async (_opts, cmd) => {
2492
+ const parent = cmd.parent.opts();
2493
+ const { safesCommand: safesCommand2 } = await Promise.resolve().then(() => (init_cap_table(), cap_table_exports));
2494
+ await safesCommand2(parent);
2495
+ });
2496
+ capTableCmd.command("transfers").description("Share transfers").action(async (_opts, cmd) => {
2497
+ const parent = cmd.parent.opts();
2498
+ const { transfersCommand: transfersCommand2 } = await Promise.resolve().then(() => (init_cap_table(), cap_table_exports));
2499
+ await transfersCommand2(parent);
2500
+ });
2501
+ capTableCmd.command("valuations").description("Valuations history").action(async (_opts, cmd) => {
2502
+ const parent = cmd.parent.opts();
2503
+ const { valuationsCommand: valuationsCommand2 } = await Promise.resolve().then(() => (init_cap_table(), cap_table_exports));
2504
+ await valuationsCommand2(parent);
2505
+ });
2506
+ capTableCmd.command("409a").description("Current 409A valuation").action(async (_opts, cmd) => {
2507
+ const parent = cmd.parent.opts();
2508
+ const { fourOhNineACommand: fourOhNineACommand2 } = await Promise.resolve().then(() => (init_cap_table(), cap_table_exports));
2509
+ await fourOhNineACommand2(parent);
2510
+ });
2511
+ capTableCmd.command("issue-equity").requiredOption("--grant-type <type>", "Grant type").requiredOption("--shares <n>", "Number of shares", parseInt).requiredOption("--recipient <name>", "Recipient name").description("Issue an equity grant").action(async (opts, cmd) => {
2512
+ const parent = cmd.parent.opts();
2513
+ const { issueEquityCommand: issueEquityCommand2 } = await Promise.resolve().then(() => (init_cap_table(), cap_table_exports));
2514
+ await issueEquityCommand2({ ...opts, entityId: parent.entityId });
2515
+ });
2516
+ capTableCmd.command("issue-safe").requiredOption("--investor <name>", "Investor name").requiredOption("--amount <n>", "Principal amount in cents", parseInt).option("--safe-type <type>", "SAFE type", "post_money").requiredOption("--valuation-cap <n>", "Valuation cap in cents", parseInt).description("Issue a SAFE note").action(async (opts, cmd) => {
2517
+ const parent = cmd.parent.opts();
2518
+ const { issueSafeCommand: issueSafeCommand2 } = await Promise.resolve().then(() => (init_cap_table(), cap_table_exports));
2519
+ await issueSafeCommand2({ ...opts, entityId: parent.entityId });
2520
+ });
2521
+ capTableCmd.command("transfer").requiredOption("--from-grant <id>", "Source grant ID").requiredOption("--to <name>", "Recipient name").requiredOption("--shares <n>", "Number of shares", parseInt).option("--type <type>", "Transfer type", "sale").description("Transfer shares").action(async (opts, cmd) => {
2522
+ const parent = cmd.parent.opts();
2523
+ const { transferSharesCommand: transferSharesCommand2 } = await Promise.resolve().then(() => (init_cap_table(), cap_table_exports));
2524
+ await transferSharesCommand2({ ...opts, entityId: parent.entityId });
2525
+ });
2526
+ capTableCmd.command("distribute").requiredOption("--amount <n>", "Total distribution amount in cents", parseInt).option("--type <type>", "Distribution type", "pro_rata").description("Calculate a distribution").action(async (opts, cmd) => {
2527
+ const parent = cmd.parent.opts();
2528
+ const { distributeCommand: distributeCommand2 } = await Promise.resolve().then(() => (init_cap_table(), cap_table_exports));
2529
+ await distributeCommand2({ ...opts, entityId: parent.entityId });
2530
+ });
2531
+ var financeCmd = program.command("finance").description("Invoicing, payroll, payments, banking").option("--entity-id <id>", "Entity ID (overrides active entity)");
2532
+ financeCmd.command("invoice").requiredOption("--customer <name>", "Customer name").requiredOption("--amount <n>", "Amount in cents", parseInt).requiredOption("--due-date <date>", "Due date (ISO 8601)").option("--description <desc>", "Description", "Services rendered").description("Create an invoice").action(async (opts, cmd) => {
2533
+ const parent = cmd.parent.opts();
2534
+ const { financeInvoiceCommand: financeInvoiceCommand2 } = await Promise.resolve().then(() => (init_finance(), finance_exports));
2535
+ await financeInvoiceCommand2({ ...opts, entityId: parent.entityId });
2536
+ });
2537
+ financeCmd.command("payroll").requiredOption("--period-start <date>", "Pay period start").requiredOption("--period-end <date>", "Pay period end").description("Run payroll").action(async (opts, cmd) => {
2538
+ const parent = cmd.parent.opts();
2539
+ const { financePayrollCommand: financePayrollCommand2 } = await Promise.resolve().then(() => (init_finance(), finance_exports));
2540
+ await financePayrollCommand2({ ...opts, entityId: parent.entityId });
2541
+ });
2542
+ financeCmd.command("pay").requiredOption("--amount <n>", "Amount in cents", parseInt).requiredOption("--recipient <name>", "Recipient name").option("--method <method>", "Payment method", "ach").description("Submit a payment").action(async (opts, cmd) => {
2543
+ const parent = cmd.parent.opts();
2544
+ const { financePayCommand: financePayCommand2 } = await Promise.resolve().then(() => (init_finance(), finance_exports));
2545
+ await financePayCommand2({ ...opts, entityId: parent.entityId });
2546
+ });
2547
+ financeCmd.command("open-account").option("--institution <name>", "Banking institution", "Mercury").description("Open a business bank account").action(async (opts, cmd) => {
2548
+ const parent = cmd.parent.opts();
2549
+ const { financeOpenAccountCommand: financeOpenAccountCommand2 } = await Promise.resolve().then(() => (init_finance(), finance_exports));
2550
+ await financeOpenAccountCommand2({ ...opts, entityId: parent.entityId });
2551
+ });
2552
+ financeCmd.command("classify-contractor").requiredOption("--name <name>", "Contractor name").requiredOption("--state <code>", "US state code").requiredOption("--hours <n>", "Hours per week", parseInt).option("--exclusive", "Exclusive client", false).requiredOption("--duration <n>", "Duration in months", parseInt).option("--provides-tools", "Company provides tools", false).description("Analyze contractor classification risk").action(async (opts, cmd) => {
2553
+ const parent = cmd.parent.opts();
2554
+ const { financeClassifyContractorCommand: financeClassifyContractorCommand2 } = await Promise.resolve().then(() => (init_finance(), finance_exports));
2555
+ await financeClassifyContractorCommand2({ ...opts, entityId: parent.entityId });
2556
+ });
2557
+ financeCmd.command("reconcile").requiredOption("--start-date <date>", "Period start").requiredOption("--end-date <date>", "Period end").description("Reconcile ledger").action(async (opts, cmd) => {
2558
+ const parent = cmd.parent.opts();
2559
+ const { financeReconcileCommand: financeReconcileCommand2 } = await Promise.resolve().then(() => (init_finance(), finance_exports));
2560
+ await financeReconcileCommand2({ ...opts, entityId: parent.entityId });
2561
+ });
2562
+ var governanceCmd = program.command("governance").description("Governance bodies, seats, meetings, resolutions").option("--entity-id <id>", "Entity ID (overrides active entity)").option("--json", "Output as JSON").action(async (opts) => {
2563
+ const { governanceListCommand: governanceListCommand2 } = await Promise.resolve().then(() => (init_governance(), governance_exports));
2564
+ await governanceListCommand2(opts);
2565
+ });
2566
+ governanceCmd.command("seats <body-id>").description("Seats for a governance body").action(async (bodyId, _opts, cmd) => {
2567
+ const parent = cmd.parent.opts();
2568
+ const { governanceSeatsCommand: governanceSeatsCommand2 } = await Promise.resolve().then(() => (init_governance(), governance_exports));
2569
+ await governanceSeatsCommand2(bodyId, parent);
2570
+ });
2571
+ governanceCmd.command("meetings <body-id>").description("Meetings for a governance body").action(async (bodyId, _opts, cmd) => {
2572
+ const parent = cmd.parent.opts();
2573
+ const { governanceMeetingsCommand: governanceMeetingsCommand2 } = await Promise.resolve().then(() => (init_governance(), governance_exports));
2574
+ await governanceMeetingsCommand2(bodyId, parent);
2575
+ });
2576
+ governanceCmd.command("resolutions <meeting-id>").description("Resolutions for a meeting").action(async (meetingId, _opts, cmd) => {
2577
+ const parent = cmd.parent.opts();
2578
+ const { governanceResolutionsCommand: governanceResolutionsCommand2 } = await Promise.resolve().then(() => (init_governance(), governance_exports));
2579
+ await governanceResolutionsCommand2(meetingId, parent);
2580
+ });
2581
+ governanceCmd.command("convene").requiredOption("--body <id>", "Governance body ID").requiredOption("--type <type>", "Meeting type").requiredOption("--title <title>", "Meeting title").requiredOption("--date <date>", "Meeting date (ISO 8601)").option("--agenda <item>", "Agenda item (repeatable)", (v, a) => [...a, v], []).description("Convene a governance meeting").action(async (opts, cmd) => {
2582
+ const parent = cmd.parent.opts();
2583
+ const { governanceConveneCommand: governanceConveneCommand2 } = await Promise.resolve().then(() => (init_governance(), governance_exports));
2584
+ await governanceConveneCommand2({ ...opts, meetingType: opts.type, entityId: parent.entityId });
2585
+ });
2586
+ governanceCmd.command("vote <meeting-id> <item-id>").requiredOption("--voter <name>", "Voter name/ID").requiredOption("--vote <value>", "Vote (yea, nay, abstain)").description("Cast a vote on an agenda item").action(async (meetingId, itemId, opts) => {
2587
+ const { governanceVoteCommand: governanceVoteCommand2 } = await Promise.resolve().then(() => (init_governance(), governance_exports));
2588
+ await governanceVoteCommand2(meetingId, itemId, opts);
2589
+ });
2590
+ var documentsCmd = program.command("documents").description("Documents and signing").option("--entity-id <id>", "Entity ID (overrides active entity)").option("--json", "Output as JSON").action(async (opts) => {
2591
+ const { documentsListCommand: documentsListCommand2 } = await Promise.resolve().then(() => (init_documents(), documents_exports));
2592
+ await documentsListCommand2(opts);
2593
+ });
2594
+ documentsCmd.command("signing-link <doc-id>").description("Get a signing link for a document").action(async (docId) => {
2595
+ const { documentsSigningLinkCommand: documentsSigningLinkCommand2 } = await Promise.resolve().then(() => (init_documents(), documents_exports));
2596
+ await documentsSigningLinkCommand2(docId);
2597
+ });
2598
+ documentsCmd.command("generate").requiredOption("--template <type>", "Template type").requiredOption("--counterparty <name>", "Counterparty name").option("--effective-date <date>", "Effective date (ISO 8601)").description("Generate a contract from a template").action(async (opts, cmd) => {
2599
+ const parent = cmd.parent.opts();
2600
+ const { documentsGenerateCommand: documentsGenerateCommand2 } = await Promise.resolve().then(() => (init_documents(), documents_exports));
2601
+ await documentsGenerateCommand2({ ...opts, entityId: parent.entityId });
2602
+ });
2603
+ var taxCmd = program.command("tax").description("Tax filings and deadline tracking").option("--entity-id <id>", "Entity ID (overrides active entity)");
2604
+ taxCmd.command("file").requiredOption("--type <type>", "Document type").requiredOption("--year <year>", "Tax year", parseInt).description("File a tax document").action(async (opts, cmd) => {
2605
+ const parent = cmd.parent.opts();
2606
+ const { taxFileCommand: taxFileCommand2 } = await Promise.resolve().then(() => (init_tax(), tax_exports));
2607
+ await taxFileCommand2({ ...opts, entityId: parent.entityId });
2608
+ });
2609
+ taxCmd.command("deadline").requiredOption("--type <type>", "Deadline type").requiredOption("--due-date <date>", "Due date (ISO 8601)").requiredOption("--description <desc>", "Description").option("--recurrence <recurrence>", "Recurrence").description("Track a compliance deadline").action(async (opts, cmd) => {
2610
+ const parent = cmd.parent.opts();
2611
+ const { taxDeadlineCommand: taxDeadlineCommand2 } = await Promise.resolve().then(() => (init_tax(), tax_exports));
2612
+ await taxDeadlineCommand2({ ...opts, entityId: parent.entityId });
2613
+ });
2614
+ var agentsCmd = program.command("agents").description("Agent management").option("--json", "Output as JSON").action(async (opts) => {
2615
+ const { agentsListCommand: agentsListCommand2 } = await Promise.resolve().then(() => (init_agents(), agents_exports));
2616
+ await agentsListCommand2(opts);
2617
+ });
2618
+ agentsCmd.command("show <agent-id>").option("--json", "Output as JSON").description("Show agent detail").action(async (agentId, opts) => {
2619
+ const { agentsShowCommand: agentsShowCommand2 } = await Promise.resolve().then(() => (init_agents(), agents_exports));
2620
+ await agentsShowCommand2(agentId, opts);
2621
+ });
2622
+ agentsCmd.command("create").requiredOption("--name <name>", "Agent name").requiredOption("--prompt <prompt>", "System prompt").option("--model <model>", "Model").description("Create a new agent").action(async (opts) => {
2623
+ const { agentsCreateCommand: agentsCreateCommand2 } = await Promise.resolve().then(() => (init_agents(), agents_exports));
2624
+ await agentsCreateCommand2(opts);
2625
+ });
2626
+ agentsCmd.command("pause <agent-id>").description("Pause an agent").action(async (agentId) => {
2627
+ const { agentsPauseCommand: agentsPauseCommand2 } = await Promise.resolve().then(() => (init_agents(), agents_exports));
2628
+ await agentsPauseCommand2(agentId);
2629
+ });
2630
+ agentsCmd.command("resume <agent-id>").description("Resume a paused agent").action(async (agentId) => {
2631
+ const { agentsResumeCommand: agentsResumeCommand2 } = await Promise.resolve().then(() => (init_agents(), agents_exports));
2632
+ await agentsResumeCommand2(agentId);
2633
+ });
2634
+ agentsCmd.command("delete <agent-id>").description("Delete an agent").action(async (agentId) => {
2635
+ const { agentsDeleteCommand: agentsDeleteCommand2 } = await Promise.resolve().then(() => (init_agents(), agents_exports));
2636
+ await agentsDeleteCommand2(agentId);
2637
+ });
2638
+ agentsCmd.command("message <agent-id>").requiredOption("--body <text>", "Message text").description("Send a message to an agent").action(async (agentId, opts) => {
2639
+ const { agentsMessageCommand: agentsMessageCommand2 } = await Promise.resolve().then(() => (init_agents(), agents_exports));
2640
+ await agentsMessageCommand2(agentId, opts);
2641
+ });
2642
+ agentsCmd.command("executions <agent-id>").option("--json", "Output as JSON").description("List agent execution history").action(async (agentId, opts) => {
2643
+ const { agentsExecutionsCommand: agentsExecutionsCommand2 } = await Promise.resolve().then(() => (init_agents(), agents_exports));
2644
+ await agentsExecutionsCommand2(agentId, opts);
2645
+ });
2646
+ agentsCmd.command("skill <agent-id>").requiredOption("--name <name>", "Skill name").requiredOption("--description <desc>", "Skill description").option("--instructions <text>", "Instructions").description("Add a skill to an agent").action(async (agentId, opts) => {
2647
+ const { agentsSkillCommand: agentsSkillCommand2 } = await Promise.resolve().then(() => (init_agents(), agents_exports));
2648
+ await agentsSkillCommand2(agentId, opts);
2649
+ });
2650
+ var billingCmd = program.command("billing").description("Billing status, plans, and subscription management").option("--json", "Output as JSON").action(async (opts) => {
2651
+ const { billingCommand: billingCommand2 } = await Promise.resolve().then(() => (init_billing(), billing_exports));
2652
+ await billingCommand2(opts);
2653
+ });
2654
+ billingCmd.command("portal").description("Open Stripe Customer Portal").action(async () => {
2655
+ const { billingPortalCommand: billingPortalCommand2 } = await Promise.resolve().then(() => (init_billing(), billing_exports));
2656
+ await billingPortalCommand2();
2657
+ });
2658
+ billingCmd.command("upgrade").option("--tier <tier>", "Plan to upgrade to", "cloud").description("Open Stripe Checkout to upgrade your plan").action(async (opts) => {
2659
+ const { billingUpgradeCommand: billingUpgradeCommand2 } = await Promise.resolve().then(() => (init_billing(), billing_exports));
2660
+ await billingUpgradeCommand2(opts);
2661
+ });
2662
+ var approvalsCmd = program.command("approvals").description("Pending approvals and responses").option("--json", "Output as JSON").action(async (opts) => {
2663
+ const { approvalsListCommand: approvalsListCommand2 } = await Promise.resolve().then(() => (init_approvals(), approvals_exports));
2664
+ await approvalsListCommand2(opts);
2665
+ });
2666
+ approvalsCmd.command("approve <approval-id>").option("--message <msg>", "Optional message").description("Approve a pending approval").action(async (approvalId, opts) => {
2667
+ const { approvalsRespondCommand: approvalsRespondCommand2 } = await Promise.resolve().then(() => (init_approvals(), approvals_exports));
2668
+ await approvalsRespondCommand2(approvalId, "approve", opts);
2669
+ });
2670
+ approvalsCmd.command("reject <approval-id>").option("--message <msg>", "Optional message").description("Reject a pending approval").action(async (approvalId, opts) => {
2671
+ const { approvalsRespondCommand: approvalsRespondCommand2 } = await Promise.resolve().then(() => (init_approvals(), approvals_exports));
2672
+ await approvalsRespondCommand2(approvalId, "reject", opts);
2673
+ });
2674
+ program.command("form").description("Create a new entity (interactive or scripted)").option("--type <type>", "Entity type (llc, c_corp, etc.)").option("--name <name>", "Entity name").option("--jurisdiction <jurisdiction>", "Jurisdiction (e.g. DE, WY)").option("--member <member>", "Member as 'name,email,role[,pct]' (repeatable)", (v, a) => [...a, v], []).action(async (opts) => {
2675
+ const { formCommand: formCommand2 } = await Promise.resolve().then(() => (init_form(), form_exports));
2676
+ await formCommand2(opts);
2677
+ });
2678
+ program.command("api-keys").description("List API keys").option("--json", "Output as JSON").action(async (opts) => {
2679
+ const { apiKeysCommand: apiKeysCommand2 } = await Promise.resolve().then(() => (init_api_keys(), api_keys_exports));
2680
+ await apiKeysCommand2(opts);
2681
+ });
2682
+ program.command("demo").description("Seed a fully-populated demo corporation").requiredOption("--name <name>", "Corporation name").action(async (opts) => {
2683
+ const { demoCommand: demoCommand2 } = await Promise.resolve().then(() => (init_demo(), demo_exports));
2684
+ await demoCommand2(opts);
2685
+ });
2686
+ program.command("serve").description("Start the API server locally").option("--port <port>", "Port to listen on", "8000").option("--data-dir <path>", "Data directory", "./data/repos").action(async (opts) => {
2687
+ const { serveCommand: serveCommand2 } = await Promise.resolve().then(() => (init_serve(), serve_exports));
2688
+ await serveCommand2(opts);
2689
+ });
2690
+ program.parse();
2691
+ //# sourceMappingURL=index.js.map