@thecorporation/cli 26.3.22 → 26.3.24

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 CHANGED
@@ -1371,7 +1371,7 @@ var init_references = __esm({
1371
1371
  // src/output.ts
1372
1372
  import chalk from "chalk";
1373
1373
  import Table from "cli-table3";
1374
- function printError(msg) {
1374
+ function printError2(msg) {
1375
1375
  console.error(chalk.red("Error:"), msg);
1376
1376
  }
1377
1377
  function printSuccess(msg) {
@@ -1390,6 +1390,16 @@ function printDryRun(operation, payload) {
1390
1390
  payload
1391
1391
  });
1392
1392
  }
1393
+ function printQuietId(record, ...idFields) {
1394
+ if (typeof record !== "object" || record === null) return;
1395
+ const rec = record;
1396
+ for (const field of idFields) {
1397
+ if (typeof rec[field] === "string" && rec[field]) {
1398
+ console.log(rec[field]);
1399
+ return;
1400
+ }
1401
+ }
1402
+ }
1393
1403
  function normalizeWriteResultOptions(options) {
1394
1404
  if (typeof options === "boolean") {
1395
1405
  return { jsonOnly: options };
@@ -1419,6 +1429,41 @@ function printWriteResult(result, successMessage, options) {
1419
1429
  printJson(result);
1420
1430
  return;
1421
1431
  }
1432
+ if (normalized.quiet) {
1433
+ const defaultIdFields = [
1434
+ "entity_id",
1435
+ "agent_id",
1436
+ "meeting_id",
1437
+ "body_id",
1438
+ "seat_id",
1439
+ "work_item_id",
1440
+ "document_id",
1441
+ "invoice_id",
1442
+ "payment_id",
1443
+ "safe_note_id",
1444
+ "valuation_id",
1445
+ "round_id",
1446
+ "instrument_id",
1447
+ "transfer_workflow_id",
1448
+ "distribution_id",
1449
+ "deadline_id",
1450
+ "filing_id",
1451
+ "bank_account_id",
1452
+ "classification_id",
1453
+ "resolution_id",
1454
+ "agenda_item_id",
1455
+ "contact_id",
1456
+ "request_id",
1457
+ "service_request_id",
1458
+ "key_id",
1459
+ "formation_id",
1460
+ "execution_id",
1461
+ "incident_id",
1462
+ "id"
1463
+ ];
1464
+ printQuietId(result, ...normalized.idFields ?? defaultIdFields);
1465
+ return;
1466
+ }
1422
1467
  printSuccess(successMessage);
1423
1468
  if (normalized.referenceKind && typeof result === "object" && result !== null && !Array.isArray(result)) {
1424
1469
  printReferenceSummary(normalized.referenceKind, result, {
@@ -1426,7 +1471,6 @@ function printWriteResult(result, successMessage, options) {
1426
1471
  showReuseHint: normalized.showReuseHint
1427
1472
  });
1428
1473
  }
1429
- printJson(result);
1430
1474
  }
1431
1475
  function printStatusPanel(data) {
1432
1476
  console.log(chalk.blue("\u2500".repeat(50)));
@@ -2152,7 +2196,7 @@ async function setupCommand() {
2152
2196
  cfg.workspace_id = result.workspace_id;
2153
2197
  printSuccess(`Local workspace ready: ${result.workspace_id}`);
2154
2198
  } catch (err) {
2155
- printError(`Workspace provisioning failed: ${err}`);
2199
+ printError2(`Workspace provisioning failed: ${err}`);
2156
2200
  console.log("You can retry with 'corp setup'.");
2157
2201
  }
2158
2202
  } else {
@@ -2169,7 +2213,7 @@ async function setupCommand() {
2169
2213
  cfg.workspace_id = result.workspace_id;
2170
2214
  printSuccess(`Authenticated. Workspace: ${result.workspace_id}`);
2171
2215
  } catch (err) {
2172
- printError(`Authentication failed: ${err}`);
2216
+ printError2(`Authentication failed: ${err}`);
2173
2217
  console.log(
2174
2218
  "You can manually set credentials with: corp config set api_key <key>"
2175
2219
  );
@@ -2185,7 +2229,7 @@ async function setupCommand() {
2185
2229
  try {
2186
2230
  cfg.api_url = validateApiUrl(url);
2187
2231
  } catch (err) {
2188
- printError(`Invalid URL: ${err}`);
2232
+ printError2(`Invalid URL: ${err}`);
2189
2233
  process.exit(1);
2190
2234
  }
2191
2235
  cfg.data_dir = "";
@@ -2201,7 +2245,7 @@ async function setupCommand() {
2201
2245
  cfg.workspace_id = result.workspace_id;
2202
2246
  console.log(`Workspace provisioned: ${result.workspace_id}`);
2203
2247
  } catch (err) {
2204
- printError(`Auto-provision failed: ${err}`);
2248
+ printError2(`Auto-provision failed: ${err}`);
2205
2249
  console.log(
2206
2250
  "You can manually set credentials with: corp config set api_key <key>"
2207
2251
  );
@@ -2409,7 +2453,7 @@ async function statusCommand(opts = {}) {
2409
2453
  printStatusPanel(data);
2410
2454
  }
2411
2455
  } catch (err) {
2412
- printError(`Failed to fetch status: ${err}`);
2456
+ printError2(`Failed to fetch status: ${err}`);
2413
2457
  process.exit(1);
2414
2458
  }
2415
2459
  }
@@ -2492,7 +2536,7 @@ async function contextCommand(opts) {
2492
2536
  }
2493
2537
  console.log(chalk2.blue("\u2500".repeat(50)));
2494
2538
  } catch (err) {
2495
- printError(`Failed to fetch context: ${err}`);
2539
+ printError2(`Failed to fetch context: ${err}`);
2496
2540
  process.exit(1);
2497
2541
  }
2498
2542
  }
@@ -2506,6 +2550,36 @@ var init_context = __esm({
2506
2550
  }
2507
2551
  });
2508
2552
 
2553
+ // src/commands/use.ts
2554
+ var use_exports = {};
2555
+ __export(use_exports, {
2556
+ useCommand: () => useCommand
2557
+ });
2558
+ async function useCommand(entityRef) {
2559
+ const cfg = requireConfig("api_url", "api_key", "workspace_id");
2560
+ const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
2561
+ const resolver = new ReferenceResolver(client, cfg);
2562
+ try {
2563
+ const entityId = await resolver.resolveEntity(entityRef);
2564
+ setActiveEntityId(cfg, entityId);
2565
+ saveConfig(cfg);
2566
+ const alias = getReferenceAlias("entity", { entity_id: entityId }) ?? entityId;
2567
+ printSuccess(`Active entity set to ${alias} (${entityId})`);
2568
+ } catch (err) {
2569
+ printError2(`Failed to resolve entity: ${err}`);
2570
+ process.exit(1);
2571
+ }
2572
+ }
2573
+ var init_use = __esm({
2574
+ "src/commands/use.ts"() {
2575
+ "use strict";
2576
+ init_config();
2577
+ init_api_client();
2578
+ init_output();
2579
+ init_references();
2580
+ }
2581
+ });
2582
+
2509
2583
  // src/commands/schema.ts
2510
2584
  var schema_exports = {};
2511
2585
  __export(schema_exports, {
@@ -2592,7 +2666,7 @@ async function configSetCommand(key, value, options = {}) {
2592
2666
  });
2593
2667
  });
2594
2668
  } catch (err) {
2595
- printError(`Failed to update config: ${err}`);
2669
+ printError2(`Failed to update config: ${err}`);
2596
2670
  process.exit(1);
2597
2671
  }
2598
2672
  if (key === "api_key" || key === "llm.api_key") {
@@ -2609,7 +2683,7 @@ function configGetCommand(key) {
2609
2683
  const cfg = loadConfig();
2610
2684
  const val = getValue(cfg, key);
2611
2685
  if (val === void 0) {
2612
- printError(`Key not found: ${key}`);
2686
+ printError2(`Key not found: ${key}`);
2613
2687
  process.exit(1);
2614
2688
  }
2615
2689
  if (typeof val === "object" && val !== null) {
@@ -2640,7 +2714,7 @@ __export(resolve_exports, {
2640
2714
  async function resolveCommand(kind, ref, opts) {
2641
2715
  const normalizedKind = kind.trim().toLowerCase();
2642
2716
  if (!KINDS.has(normalizedKind)) {
2643
- printError(`Unsupported resolve kind: ${kind}`);
2717
+ printError2(`Unsupported resolve kind: ${kind}`);
2644
2718
  process.exit(1);
2645
2719
  }
2646
2720
  const cfg = requireConfig("api_url", "api_key", "workspace_id");
@@ -2742,7 +2816,7 @@ async function resolveCommand(kind, ref, opts) {
2742
2816
  ...meetingId ? { meeting_id: meetingId } : {}
2743
2817
  });
2744
2818
  } catch (err) {
2745
- printError(`Failed to resolve reference: ${err}`);
2819
+ printError2(`Failed to resolve reference: ${err}`);
2746
2820
  process.exit(1);
2747
2821
  }
2748
2822
  }
@@ -2831,7 +2905,7 @@ import Table2 from "cli-table3";
2831
2905
  async function findCommand(kind, query, opts) {
2832
2906
  const normalizedKind = kind.trim().toLowerCase();
2833
2907
  if (!KINDS2.has(normalizedKind)) {
2834
- printError(`Unsupported find kind: ${kind}`);
2908
+ printError2(`Unsupported find kind: ${kind}`);
2835
2909
  process.exit(1);
2836
2910
  }
2837
2911
  const cfg = requireConfig("api_url", "api_key", "workspace_id");
@@ -2881,7 +2955,7 @@ async function findCommand(kind, query, opts) {
2881
2955
  }
2882
2956
  console.log(table.toString());
2883
2957
  } catch (err) {
2884
- printError(`Failed to find references: ${err}`);
2958
+ printError2(`Failed to find references: ${err}`);
2885
2959
  process.exit(1);
2886
2960
  }
2887
2961
  }
@@ -2963,7 +3037,7 @@ async function obligationsCommand(opts) {
2963
3037
  else if (obligations.length === 0) console.log("No obligations found.");
2964
3038
  else printObligationsTable(obligations);
2965
3039
  } catch (err) {
2966
- printError(`Failed to fetch obligations: ${err}`);
3040
+ printError2(`Failed to fetch obligations: ${err}`);
2967
3041
  process.exit(1);
2968
3042
  }
2969
3043
  }
@@ -3003,11 +3077,18 @@ async function digestCommand(opts) {
3003
3077
  printJson(result);
3004
3078
  } else {
3005
3079
  const digests = await client.listDigests();
3006
- if (digests.length === 0) console.log("No digest history found.");
3007
- else printJson(digests);
3080
+ if (digests.length === 0) {
3081
+ if (opts.json) {
3082
+ printJson([]);
3083
+ } else {
3084
+ console.log("No digest history found.");
3085
+ }
3086
+ } else {
3087
+ printJson(digests);
3088
+ }
3008
3089
  }
3009
3090
  } catch (err) {
3010
- printError(`Failed: ${err}`);
3091
+ printError2(`Failed: ${err}`);
3011
3092
  process.exit(1);
3012
3093
  }
3013
3094
  }
@@ -3033,7 +3114,7 @@ async function linkCommand(opts) {
3033
3114
  printSuccess(`Workspace linked to ${opts.provider} (external ID: ${opts.externalId})`);
3034
3115
  if (data.workspace_id) console.log(` Workspace: ${data.workspace_id}`);
3035
3116
  } catch (err) {
3036
- printError(`${err}`);
3117
+ printError2(`${err}`);
3037
3118
  process.exit(1);
3038
3119
  }
3039
3120
  }
@@ -3054,6 +3135,12 @@ __export(claim_exports, {
3054
3135
  async function claimCommand(code) {
3055
3136
  const cfg = loadConfig();
3056
3137
  const apiUrl = (cfg.api_url || "https://api.thecorporation.ai").replace(/\/+$/, "");
3138
+ if (apiUrl.startsWith("process://")) {
3139
+ printError2(
3140
+ "Claim codes require a remote API server.\n Run: npx corp config set api_url https://api.thecorporation.ai --force\n Or use: npx corp setup"
3141
+ );
3142
+ process.exit(1);
3143
+ }
3057
3144
  try {
3058
3145
  const resp = await fetch(`${apiUrl}/v1/workspaces/claim`, {
3059
3146
  method: "POST",
@@ -3067,7 +3154,7 @@ async function claimCommand(code) {
3067
3154
  detail = body.detail ?? "";
3068
3155
  } catch {
3069
3156
  }
3070
- printError(detail || `${resp.status} ${resp.statusText}`);
3157
+ printError2(detail || `${resp.status} ${resp.statusText}`);
3071
3158
  process.exit(1);
3072
3159
  }
3073
3160
  const data = await resp.json();
@@ -3078,7 +3165,7 @@ async function claimCommand(code) {
3078
3165
  console.log("Credentials saved to ~/.corp/auth.json");
3079
3166
  console.log("Settings remain in ~/.corp/config.json");
3080
3167
  } catch (err) {
3081
- printError(`${err}`);
3168
+ printError2(`${err}`);
3082
3169
  process.exit(1);
3083
3170
  }
3084
3171
  }
@@ -3275,7 +3362,7 @@ async function chatCommand() {
3275
3362
  try {
3276
3363
  printStatusPanel(await client.getStatus());
3277
3364
  } catch (e) {
3278
- printError(`Status error: ${e}`);
3365
+ printError2(`Status error: ${e}`);
3279
3366
  }
3280
3367
  },
3281
3368
  "/obligations": async () => {
@@ -3285,7 +3372,7 @@ async function chatCommand() {
3285
3372
  if (obls.length) printObligationsTable(obls);
3286
3373
  else console.log(chalk4.dim("No obligations found."));
3287
3374
  } catch (e) {
3288
- printError(`Obligations error: ${e}`);
3375
+ printError2(`Obligations error: ${e}`);
3289
3376
  }
3290
3377
  },
3291
3378
  "/digest": async () => {
@@ -3294,7 +3381,7 @@ async function chatCommand() {
3294
3381
  if (digests.length) printJson(digests);
3295
3382
  else console.log(chalk4.dim("No digest history."));
3296
3383
  } catch (e) {
3297
- printError(`Digest error: ${e}`);
3384
+ printError2(`Digest error: ${e}`);
3298
3385
  }
3299
3386
  },
3300
3387
  "/config": () => printJson(configForDisplay(cfg)),
@@ -3351,7 +3438,7 @@ ${chalk4.bold("Chat Slash Commands")}
3351
3438
  await handler(args);
3352
3439
  continue;
3353
3440
  }
3354
- printError(`Unknown command: ${cmd}. Type /help for available commands.`);
3441
+ printError2(`Unknown command: ${cmd}. Type /help for available commands.`);
3355
3442
  continue;
3356
3443
  }
3357
3444
  messages.push({ role: "user", content: userInput });
@@ -3368,7 +3455,7 @@ ${chalk4.bold("Chat Slash Commands")}
3368
3455
  llmCfg.base_url
3369
3456
  );
3370
3457
  } catch (err) {
3371
- printError(`LLM error: ${err}`);
3458
+ printError2(`LLM error: ${err}`);
3372
3459
  break;
3373
3460
  }
3374
3461
  totalTokens += response.usage.total_tokens;
@@ -3426,6 +3513,7 @@ __export(entities_exports, {
3426
3513
  entitiesDissolveCommand: () => entitiesDissolveCommand,
3427
3514
  entitiesShowCommand: () => entitiesShowCommand
3428
3515
  });
3516
+ import { confirm as confirm2 } from "@inquirer/prompts";
3429
3517
  import chalk5 from "chalk";
3430
3518
  async function entitiesCommand(opts) {
3431
3519
  const cfg = requireConfig("api_url", "api_key", "workspace_id");
@@ -3443,7 +3531,7 @@ async function entitiesCommand(opts) {
3443
3531
  printEntitiesTable(entities);
3444
3532
  }
3445
3533
  } catch (err) {
3446
- printError(`Failed to fetch entities: ${err}`);
3534
+ printError2(`Failed to fetch entities: ${err}`);
3447
3535
  process.exit(1);
3448
3536
  }
3449
3537
  }
@@ -3457,7 +3545,7 @@ async function entitiesShowCommand(entityId, opts) {
3457
3545
  const entities = await client.listEntities();
3458
3546
  const entity = entities.find((e) => e.entity_id === resolvedEntityId);
3459
3547
  if (!entity) {
3460
- printError(`Entity not found: ${entityId}`);
3548
+ printError2(`Entity not found: ${entityId}`);
3461
3549
  process.exit(1);
3462
3550
  }
3463
3551
  await resolver.stabilizeRecord("entity", entity);
@@ -3478,7 +3566,7 @@ async function entitiesShowCommand(entityId, opts) {
3478
3566
  console.log(chalk5.blue("\u2500".repeat(40)));
3479
3567
  }
3480
3568
  } catch (err) {
3481
- printError(`Failed to fetch entities: ${err}`);
3569
+ printError2(`Failed to fetch entities: ${err}`);
3482
3570
  process.exit(1);
3483
3571
  }
3484
3572
  }
@@ -3494,7 +3582,7 @@ async function entitiesConvertCommand(entityId, opts) {
3494
3582
  printSuccess(`Entity conversion initiated: ${result.conversion_id ?? "OK"}`);
3495
3583
  printJson(result);
3496
3584
  } catch (err) {
3497
- printError(`Failed to convert entity: ${err}`);
3585
+ printError2(`Failed to convert entity: ${err}`);
3498
3586
  process.exit(1);
3499
3587
  }
3500
3588
  }
@@ -3504,6 +3592,16 @@ async function entitiesDissolveCommand(entityId, opts) {
3504
3592
  const resolver = new ReferenceResolver(client, cfg);
3505
3593
  try {
3506
3594
  const resolvedEntityId = await resolver.resolveEntity(entityId);
3595
+ if (!opts.yes) {
3596
+ const ok = await confirm2({
3597
+ message: `Dissolve entity ${entityId}? This cannot be undone.`,
3598
+ default: false
3599
+ });
3600
+ if (!ok) {
3601
+ console.log("Cancelled.");
3602
+ return;
3603
+ }
3604
+ }
3507
3605
  const data = { reason: opts.reason };
3508
3606
  if (opts.effectiveDate) data.effective_date = opts.effectiveDate;
3509
3607
  const result = await client.dissolveEntity(resolvedEntityId, data);
@@ -3512,9 +3610,9 @@ async function entitiesDissolveCommand(entityId, opts) {
3512
3610
  } catch (err) {
3513
3611
  const msg = String(err);
3514
3612
  if (msg.includes("InvalidTransition") || msg.includes("422")) {
3515
- printError(`Cannot dissolve entity: only entities with 'active' status can be dissolved. Check the entity's current status with: corp entities show ${entityId}`);
3613
+ printError2(`Cannot dissolve entity: only entities with 'active' status can be dissolved. Check the entity's current status with: corp entities show ${entityId}`);
3516
3614
  } else {
3517
- printError(`Failed to dissolve entity: ${err}`);
3615
+ printError2(`Failed to dissolve entity: ${err}`);
3518
3616
  }
3519
3617
  process.exit(1);
3520
3618
  }
@@ -3551,7 +3649,7 @@ async function contactsListCommand(opts) {
3551
3649
  else if (contacts.length === 0) console.log("No contacts found.");
3552
3650
  else printContactsTable(contacts);
3553
3651
  } catch (err) {
3554
- printError(`Failed to fetch contacts: ${err}`);
3652
+ printError2(`Failed to fetch contacts: ${err}`);
3555
3653
  process.exit(1);
3556
3654
  }
3557
3655
  }
@@ -3588,7 +3686,7 @@ async function contactsShowCommand(contactId, opts) {
3588
3686
  console.log(chalk6.cyan("\u2500".repeat(40)));
3589
3687
  }
3590
3688
  } catch (err) {
3591
- printError(`Failed to fetch contact: ${err}`);
3689
+ printError2(`Failed to fetch contact: ${err}`);
3592
3690
  process.exit(1);
3593
3691
  }
3594
3692
  }
@@ -3618,7 +3716,7 @@ async function contactsAddCommand(opts) {
3618
3716
  { jsonOnly: opts.json, referenceKind: "contact", showReuseHint: true }
3619
3717
  );
3620
3718
  } catch (err) {
3621
- printError(`Failed to create contact: ${err}`);
3719
+ printError2(`Failed to create contact: ${err}`);
3622
3720
  process.exit(1);
3623
3721
  }
3624
3722
  }
@@ -3667,7 +3765,7 @@ async function contactsEditCommand(contactId, opts) {
3667
3765
  resolver.remember("contact", resolvedContactId, eid);
3668
3766
  printWriteResult(result, "Contact updated.", opts.json);
3669
3767
  } catch (err) {
3670
- printError(`Failed to update contact: ${err}`);
3768
+ printError2(`Failed to update contact: ${err}`);
3671
3769
  process.exit(1);
3672
3770
  }
3673
3771
  }
@@ -3687,14 +3785,18 @@ __export(cap_table_exports, {
3687
3785
  addSecurityCommand: () => addSecurityCommand,
3688
3786
  approveValuationCommand: () => approveValuationCommand,
3689
3787
  capTableCommand: () => capTableCommand,
3788
+ controlMapCommand: () => controlMapCommand,
3690
3789
  createInstrumentCommand: () => createInstrumentCommand,
3691
3790
  createValuationCommand: () => createValuationCommand,
3791
+ dilutionPreviewCommand: () => dilutionPreviewCommand,
3692
3792
  distributeCommand: () => distributeCommand,
3793
+ executeConversionCommand: () => executeConversionCommand,
3693
3794
  fourOhNineACommand: () => fourOhNineACommand,
3694
3795
  instrumentsCommand: () => instrumentsCommand,
3695
3796
  issueEquityCommand: () => issueEquityCommand,
3696
3797
  issueRoundCommand: () => issueRoundCommand,
3697
3798
  issueSafeCommand: () => issueSafeCommand,
3799
+ previewConversionCommand: () => previewConversionCommand,
3698
3800
  roundsCommand: () => roundsCommand,
3699
3801
  safesCommand: () => safesCommand,
3700
3802
  shareClassesCommand: () => shareClassesCommand,
@@ -3823,7 +3925,7 @@ async function capTableCommand(opts) {
3823
3925
  return;
3824
3926
  }
3825
3927
  if (data.access_level === "none") {
3826
- printError("You do not have access to this entity's cap table.");
3928
+ printError2("You do not have access to this entity's cap table.");
3827
3929
  process.exit(1);
3828
3930
  }
3829
3931
  printCapTable(data);
@@ -3833,7 +3935,7 @@ async function capTableCommand(opts) {
3833
3935
  } catch {
3834
3936
  }
3835
3937
  } catch (err) {
3836
- printError(`Failed to fetch cap table: ${err}`);
3938
+ printError2(`Failed to fetch cap table: ${err}`);
3837
3939
  process.exit(1);
3838
3940
  }
3839
3941
  }
@@ -3849,7 +3951,7 @@ async function safesCommand(opts) {
3849
3951
  else if (safes.length === 0) console.log("No SAFE notes found.");
3850
3952
  else printSafesTable(safes);
3851
3953
  } catch (err) {
3852
- printError(`Failed to fetch SAFE notes: ${err}`);
3954
+ printError2(`Failed to fetch SAFE notes: ${err}`);
3853
3955
  process.exit(1);
3854
3956
  }
3855
3957
  }
@@ -3865,7 +3967,7 @@ async function transfersCommand(opts) {
3865
3967
  else if (transfers.length === 0) console.log("No share transfers found.");
3866
3968
  else printTransfersTable(transfers);
3867
3969
  } catch (err) {
3868
- printError(`Failed to fetch transfers: ${err}`);
3970
+ printError2(`Failed to fetch transfers: ${err}`);
3869
3971
  process.exit(1);
3870
3972
  }
3871
3973
  }
@@ -3882,7 +3984,7 @@ async function instrumentsCommand(opts) {
3882
3984
  else if (instruments.length === 0) console.log("No instruments found.");
3883
3985
  else printInstrumentsTable(instruments);
3884
3986
  } catch (err) {
3885
- printError(`Failed to fetch instruments: ${err}`);
3987
+ printError2(`Failed to fetch instruments: ${err}`);
3886
3988
  process.exit(1);
3887
3989
  }
3888
3990
  }
@@ -3899,7 +4001,7 @@ async function shareClassesCommand(opts) {
3899
4001
  else if (shareClasses.length === 0) console.log("No share classes found.");
3900
4002
  else printShareClassesTable(shareClasses);
3901
4003
  } catch (err) {
3902
- printError(`Failed to fetch share classes: ${err}`);
4004
+ printError2(`Failed to fetch share classes: ${err}`);
3903
4005
  process.exit(1);
3904
4006
  }
3905
4007
  }
@@ -3915,7 +4017,7 @@ async function roundsCommand(opts) {
3915
4017
  else if (rounds.length === 0) console.log("No rounds found.");
3916
4018
  else printRoundsTable(rounds);
3917
4019
  } catch (err) {
3918
- printError(`Failed to fetch rounds: ${err}`);
4020
+ printError2(`Failed to fetch rounds: ${err}`);
3919
4021
  process.exit(1);
3920
4022
  }
3921
4023
  }
@@ -3931,7 +4033,7 @@ async function valuationsCommand(opts) {
3931
4033
  else if (valuations.length === 0) console.log("No valuations found.");
3932
4034
  else printValuationsTable(valuations);
3933
4035
  } catch (err) {
3934
- printError(`Failed to fetch valuations: ${err}`);
4036
+ printError2(`Failed to fetch valuations: ${err}`);
3935
4037
  process.exit(1);
3936
4038
  }
3937
4039
  }
@@ -3970,7 +4072,7 @@ async function fourOhNineACommand(opts) {
3970
4072
  );
3971
4073
  }
3972
4074
  } else {
3973
- printError(`Failed to fetch 409A valuation: ${err}`);
4075
+ printError2(`Failed to fetch 409A valuation: ${err}`);
3974
4076
  }
3975
4077
  process.exit(1);
3976
4078
  }
@@ -3997,12 +4099,12 @@ async function issueEquityCommand(opts) {
3997
4099
  const capTable = await client.getCapTable(eid);
3998
4100
  const issuerLegalEntityId = capTable.issuer_legal_entity_id;
3999
4101
  if (!issuerLegalEntityId) {
4000
- printError("No issuer legal entity found. Has this entity been formed with a cap table?");
4102
+ printError2("No issuer legal entity found. Has this entity been formed with a cap table?");
4001
4103
  process.exit(1);
4002
4104
  }
4003
4105
  const instruments = capTable.instruments ?? [];
4004
4106
  if (!instruments.length) {
4005
- printError("No instruments found on cap table. Create one with: corp cap-table create-instrument --kind common_equity --symbol COMMON --authorized-units <shares>");
4107
+ printError2("No instruments found on cap table. Create one with: corp cap-table create-instrument --kind common_equity --symbol COMMON --authorized-units <shares>");
4006
4108
  process.exit(1);
4007
4109
  }
4008
4110
  const explicitInstrumentId = opts.instrumentId ? await resolver.resolveInstrument(eid, opts.instrumentId) : void 0;
@@ -4036,6 +4138,16 @@ async function issueEquityCommand(opts) {
4036
4138
  grant_type: opts.grantType
4037
4139
  };
4038
4140
  if (opts.email) securityData.email = opts.email;
4141
+ const existingHolders = capTable.holders ?? [];
4142
+ const matchingHolder = existingHolders.find((h) => {
4143
+ const nameMatch = String(h.name ?? "").toLowerCase() === opts.recipient.toLowerCase();
4144
+ const emailMatch = opts.email && String(h.email ?? "").toLowerCase() === opts.email.toLowerCase();
4145
+ return nameMatch || emailMatch;
4146
+ });
4147
+ if (matchingHolder) {
4148
+ const holderId = matchingHolder.holder_id ?? matchingHolder.contact_id ?? matchingHolder.id;
4149
+ if (holderId) securityData.holder_id = holderId;
4150
+ }
4039
4151
  await client.addRoundSecurity(roundId, securityData);
4040
4152
  const issuePayload = { entity_id: eid };
4041
4153
  if (meetingId) issuePayload.meeting_id = meetingId;
@@ -4048,9 +4160,8 @@ async function issueEquityCommand(opts) {
4048
4160
  }
4049
4161
  printSuccess(`Equity issued: ${opts.shares} shares (${opts.grantType}) to ${opts.recipient}`);
4050
4162
  printReferenceSummary("round", round, { label: "Round Ref:", showReuseHint: true });
4051
- printJson(result);
4052
4163
  } catch (err) {
4053
- printError(`Failed to issue equity: ${err}`);
4164
+ printError2(`Failed to issue equity: ${err}`);
4054
4165
  process.exit(1);
4055
4166
  }
4056
4167
  }
@@ -4064,9 +4175,9 @@ async function issueSafeCommand(opts) {
4064
4175
  printDryRun("cap_table.issue_safe", {
4065
4176
  entity_id: eid,
4066
4177
  investor: opts.investor,
4067
- amount: opts.amount,
4178
+ amount_cents: opts.amountCents,
4068
4179
  safe_type: opts.safeType,
4069
- valuation_cap: opts.valuationCap,
4180
+ valuation_cap_cents: opts.valuationCapCents,
4070
4181
  email: opts.email,
4071
4182
  meeting_id: opts.meetingId,
4072
4183
  resolution_id: opts.resolutionId
@@ -4086,8 +4197,8 @@ async function issueSafeCommand(opts) {
4086
4197
  const body = {
4087
4198
  entity_id: eid,
4088
4199
  investor_name: opts.investor,
4089
- principal_amount_cents: opts.amount,
4090
- valuation_cap_cents: opts.valuationCap,
4200
+ principal_amount_cents: opts.amountCents,
4201
+ valuation_cap_cents: opts.valuationCapCents,
4091
4202
  safe_type: opts.safeType
4092
4203
  };
4093
4204
  if (opts.email) body.email = opts.email;
@@ -4100,11 +4211,10 @@ async function issueSafeCommand(opts) {
4100
4211
  printJson(result);
4101
4212
  return;
4102
4213
  }
4103
- printSuccess(`SAFE issued: $${(opts.amount / 100).toLocaleString()} to ${opts.investor}`);
4214
+ printSuccess(`SAFE issued: $${(opts.amountCents / 100).toLocaleString()} to ${opts.investor}`);
4104
4215
  printReferenceSummary("safe_note", result, { showReuseHint: true });
4105
- printJson(result);
4106
4216
  } catch (err) {
4107
- printError(`Failed to issue SAFE: ${err}`);
4217
+ printError2(`Failed to issue SAFE: ${err}`);
4108
4218
  process.exit(1);
4109
4219
  }
4110
4220
  }
@@ -4173,7 +4283,7 @@ async function transferSharesCommand(opts) {
4173
4283
  showReuseHint: true
4174
4284
  });
4175
4285
  } catch (err) {
4176
- printError(`Failed to create transfer workflow: ${err}`);
4286
+ printError2(`Failed to create transfer workflow: ${err}`);
4177
4287
  process.exit(1);
4178
4288
  }
4179
4289
  }
@@ -4185,7 +4295,7 @@ async function distributeCommand(opts) {
4185
4295
  const eid = await resolver.resolveEntity(opts.entityId);
4186
4296
  const payload = {
4187
4297
  entity_id: eid,
4188
- total_amount_cents: opts.amount,
4298
+ total_amount_cents: opts.amountCents,
4189
4299
  distribution_type: opts.type,
4190
4300
  description: opts.description
4191
4301
  };
@@ -4202,7 +4312,7 @@ async function distributeCommand(opts) {
4202
4312
  showReuseHint: true
4203
4313
  });
4204
4314
  } catch (err) {
4205
- printError(`Failed to calculate distribution: ${err}`);
4315
+ printError2(`Failed to calculate distribution: ${err}`);
4206
4316
  process.exit(1);
4207
4317
  }
4208
4318
  }
@@ -4231,7 +4341,7 @@ async function startRoundCommand(opts) {
4231
4341
  showReuseHint: true
4232
4342
  });
4233
4343
  } catch (err) {
4234
- printError(`Failed to start round: ${err}`);
4344
+ printError2(`Failed to start round: ${err}`);
4235
4345
  process.exit(1);
4236
4346
  }
4237
4347
  }
@@ -4273,7 +4383,7 @@ async function createInstrumentCommand(opts) {
4273
4383
  showReuseHint: true
4274
4384
  });
4275
4385
  } catch (err) {
4276
- printError(`Failed to create instrument: ${err}`);
4386
+ printError2(`Failed to create instrument: ${err}`);
4277
4387
  process.exit(1);
4278
4388
  }
4279
4389
  }
@@ -4302,7 +4412,7 @@ async function addSecurityCommand(opts) {
4302
4412
  const result = await client.addRoundSecurity(roundId, body);
4303
4413
  printWriteResult(result, `Security added for ${opts.recipientName}`, opts.json);
4304
4414
  } catch (err) {
4305
- printError(`Failed to add security: ${err}`);
4415
+ printError2(`Failed to add security: ${err}`);
4306
4416
  process.exit(1);
4307
4417
  }
4308
4418
  }
@@ -4343,9 +4453,8 @@ async function issueRoundCommand(opts) {
4343
4453
  if (roundMatch) {
4344
4454
  printReferenceSummary("round", roundMatch.raw, { showReuseHint: true });
4345
4455
  }
4346
- printJson(result);
4347
4456
  } catch (err) {
4348
- printError(`Failed to issue round: ${err}`);
4457
+ printError2(`Failed to issue round: ${err}`);
4349
4458
  process.exit(1);
4350
4459
  }
4351
4460
  }
@@ -4376,7 +4485,7 @@ async function createValuationCommand(opts) {
4376
4485
  showReuseHint: true
4377
4486
  });
4378
4487
  } catch (err) {
4379
- printError(`Failed to create valuation: ${err}`);
4488
+ printError2(`Failed to create valuation: ${err}`);
4380
4489
  process.exit(1);
4381
4490
  }
4382
4491
  }
@@ -4421,13 +4530,12 @@ async function submitValuationCommand(opts) {
4421
4530
  printReferenceSummary("agenda_item", { agenda_item_id: result.agenda_item_id }, { label: "Agenda Ref:" });
4422
4531
  }
4423
4532
  }
4424
- printJson(result);
4425
4533
  } catch (err) {
4426
4534
  const msg = String(err);
4427
4535
  if (msg.includes("404")) {
4428
- printError(`Valuation not found. List valuations with: corp cap-table valuations`);
4536
+ printError2(`Valuation not found. List valuations with: corp cap-table valuations`);
4429
4537
  } else {
4430
- printError(`Failed to submit valuation: ${err}`);
4538
+ printError2(`Failed to submit valuation: ${err}`);
4431
4539
  }
4432
4540
  process.exit(1);
4433
4541
  }
@@ -4457,9 +4565,129 @@ async function approveValuationCommand(opts) {
4457
4565
  } catch (err) {
4458
4566
  const msg = String(err);
4459
4567
  if (msg.includes("400")) {
4460
- printError(`Bad request \u2014 a --resolution-id from a board vote may be required. Submit for approval first: corp cap-table submit-valuation <valuation-ref>`);
4568
+ printError2(`Bad request \u2014 a --resolution-id from a board vote may be required. Submit for approval first: corp cap-table submit-valuation <valuation-ref>`);
4569
+ } else {
4570
+ printError2(`Failed to approve valuation: ${err}`);
4571
+ }
4572
+ process.exit(1);
4573
+ }
4574
+ }
4575
+ async function previewConversionCommand(opts) {
4576
+ const cfg = requireConfig("api_url", "api_key", "workspace_id");
4577
+ const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
4578
+ const resolver = new ReferenceResolver(client, cfg);
4579
+ try {
4580
+ const eid = await resolver.resolveEntity(opts.entityId);
4581
+ const safeId = await resolver.resolveSafeNote(eid, opts.safeId);
4582
+ const result = await client.previewRoundConversion({
4583
+ entity_id: eid,
4584
+ safe_note_id: safeId,
4585
+ price_per_share_cents: opts.pricePerShareCents
4586
+ });
4587
+ if (opts.json) {
4588
+ printJson(result);
4589
+ return;
4590
+ }
4591
+ printSuccess("Conversion Preview:");
4592
+ if (result.shares_issued) console.log(` Shares to issue: ${result.shares_issued}`);
4593
+ if (result.ownership_pct) console.log(` Post-conversion ownership: ${result.ownership_pct}%`);
4594
+ printJson(result);
4595
+ } catch (err) {
4596
+ printError2(`Failed to preview conversion: ${err}`);
4597
+ process.exit(1);
4598
+ }
4599
+ }
4600
+ async function executeConversionCommand(opts) {
4601
+ const cfg = requireConfig("api_url", "api_key", "workspace_id");
4602
+ const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
4603
+ const resolver = new ReferenceResolver(client, cfg);
4604
+ try {
4605
+ const eid = await resolver.resolveEntity(opts.entityId);
4606
+ const safeId = await resolver.resolveSafeNote(eid, opts.safeId);
4607
+ const payload = {
4608
+ entity_id: eid,
4609
+ safe_note_id: safeId,
4610
+ price_per_share_cents: opts.pricePerShareCents
4611
+ };
4612
+ if (opts.dryRun) {
4613
+ printDryRun("equity.conversion.execute", payload);
4614
+ return;
4615
+ }
4616
+ const result = await client.executeRoundConversion(
4617
+ payload
4618
+ );
4619
+ printWriteResult(result, `Conversion executed for SAFE ${safeId}`, {
4620
+ jsonOnly: opts.json
4621
+ });
4622
+ } catch (err) {
4623
+ printError2(`Failed to execute conversion: ${err}`);
4624
+ process.exit(1);
4625
+ }
4626
+ }
4627
+ async function dilutionPreviewCommand(opts) {
4628
+ const cfg = requireConfig("api_url", "api_key", "workspace_id");
4629
+ const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
4630
+ const resolver = new ReferenceResolver(client, cfg);
4631
+ try {
4632
+ const eid = await resolver.resolveEntity(opts.entityId);
4633
+ const roundId = await resolver.resolveRound(eid, opts.roundId);
4634
+ const result = await client.getDilutionPreview(eid, roundId);
4635
+ if (opts.json) {
4636
+ printJson(result);
4637
+ return;
4638
+ }
4639
+ if (result.round_status === "closed" || result.round_status === "issued") {
4640
+ console.log(chalk7.yellow("Note: This round is already closed. Dilution preview reflects the finalized state, not a scenario model."));
4641
+ console.log(chalk7.dim(" For scenario modeling, create a new round with: corp cap-table start-round --name '...' --issuer-legal-entity-id '...'"));
4642
+ }
4643
+ printJson(result);
4644
+ } catch (err) {
4645
+ printError2(`Failed to preview dilution: ${err}`);
4646
+ process.exit(1);
4647
+ }
4648
+ }
4649
+ async function controlMapCommand(opts) {
4650
+ const cfg = requireConfig("api_url", "api_key", "workspace_id");
4651
+ const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
4652
+ const resolver = new ReferenceResolver(client, cfg);
4653
+ try {
4654
+ const eid = await resolver.resolveEntity(opts.entityId);
4655
+ const rootEntityId = opts.rootEntityId ? await resolver.resolveEntity(opts.rootEntityId) : eid;
4656
+ let result;
4657
+ try {
4658
+ result = await client.getControlMap(eid, rootEntityId);
4659
+ } catch (firstErr) {
4660
+ const msg = String(firstErr);
4661
+ if (msg.includes("404") && !opts.rootEntityId) {
4662
+ try {
4663
+ const capTable = await client.getCapTable(eid);
4664
+ const issuerLegalEntityId = capTable.issuer_legal_entity_id;
4665
+ if (issuerLegalEntityId && issuerLegalEntityId !== eid) {
4666
+ result = await client.getControlMap(eid, issuerLegalEntityId);
4667
+ } else {
4668
+ throw firstErr;
4669
+ }
4670
+ } catch {
4671
+ throw firstErr;
4672
+ }
4673
+ } else {
4674
+ throw firstErr;
4675
+ }
4676
+ }
4677
+ if (opts.json) {
4678
+ printJson(result);
4679
+ return;
4680
+ }
4681
+ printJson(result);
4682
+ } catch (err) {
4683
+ const msg = String(err);
4684
+ if (msg.includes("404") && (msg.includes("root_entity_id") || msg.includes("not found"))) {
4685
+ printError2(
4686
+ `Control map: entity not found. Ensure the entity is active and has a cap table.
4687
+ Try: corp cap-table control-map --root-entity-id <legal-entity-id>`
4688
+ );
4461
4689
  } else {
4462
- printError(`Failed to approve valuation: ${err}`);
4690
+ printError2(`Failed to fetch control map: ${err}`);
4463
4691
  }
4464
4692
  process.exit(1);
4465
4693
  }
@@ -4489,6 +4717,7 @@ var init_cap_table = __esm({
4489
4717
  // src/commands/finance.ts
4490
4718
  var finance_exports = {};
4491
4719
  __export(finance_exports, {
4720
+ financeActivateAccountCommand: () => financeActivateAccountCommand,
4492
4721
  financeBankAccountsCommand: () => financeBankAccountsCommand,
4493
4722
  financeClassificationsCommand: () => financeClassificationsCommand,
4494
4723
  financeClassifyContractorCommand: () => financeClassifyContractorCommand,
@@ -4502,6 +4731,7 @@ __export(finance_exports, {
4502
4731
  financePayrollRunsCommand: () => financePayrollRunsCommand,
4503
4732
  financeReconcileCommand: () => financeReconcileCommand,
4504
4733
  financeReconciliationsCommand: () => financeReconciliationsCommand,
4734
+ financeStatementsCommand: () => financeStatementsCommand,
4505
4735
  financeSummaryCommand: () => financeSummaryCommand
4506
4736
  });
4507
4737
  function sumAmounts(records, candidates) {
@@ -4603,7 +4833,7 @@ async function financeSummaryCommand(opts) {
4603
4833
  }
4604
4834
  printFinanceSummaryPanel(summary);
4605
4835
  } catch (err) {
4606
- printError(`Failed to fetch finance summary: ${err}`);
4836
+ printError2(`Failed to fetch finance summary: ${err}`);
4607
4837
  process.exit(1);
4608
4838
  }
4609
4839
  }
@@ -4619,7 +4849,7 @@ async function financeInvoicesCommand(opts) {
4619
4849
  else if (invoices.length === 0) console.log("No invoices found.");
4620
4850
  else printInvoicesTable(invoices);
4621
4851
  } catch (err) {
4622
- printError(`Failed to fetch invoices: ${err}`);
4852
+ printError2(`Failed to fetch invoices: ${err}`);
4623
4853
  process.exit(1);
4624
4854
  }
4625
4855
  }
@@ -4635,7 +4865,7 @@ async function financeBankAccountsCommand(opts) {
4635
4865
  else if (accounts.length === 0) console.log("No bank accounts found.");
4636
4866
  else printBankAccountsTable(accounts);
4637
4867
  } catch (err) {
4638
- printError(`Failed to fetch bank accounts: ${err}`);
4868
+ printError2(`Failed to fetch bank accounts: ${err}`);
4639
4869
  process.exit(1);
4640
4870
  }
4641
4871
  }
@@ -4651,7 +4881,7 @@ async function financePaymentsCommand(opts) {
4651
4881
  else if (payments.length === 0) console.log("No payments found.");
4652
4882
  else printPaymentsTable(payments);
4653
4883
  } catch (err) {
4654
- printError(`Failed to fetch payments: ${err}`);
4884
+ printError2(`Failed to fetch payments: ${err}`);
4655
4885
  process.exit(1);
4656
4886
  }
4657
4887
  }
@@ -4667,7 +4897,7 @@ async function financePayrollRunsCommand(opts) {
4667
4897
  else if (runs.length === 0) console.log("No payroll runs found.");
4668
4898
  else printPayrollRunsTable(runs);
4669
4899
  } catch (err) {
4670
- printError(`Failed to fetch payroll runs: ${err}`);
4900
+ printError2(`Failed to fetch payroll runs: ${err}`);
4671
4901
  process.exit(1);
4672
4902
  }
4673
4903
  }
@@ -4683,7 +4913,7 @@ async function financeDistributionsCommand(opts) {
4683
4913
  else if (distributions.length === 0) console.log("No distributions found.");
4684
4914
  else printDistributionsTable(distributions);
4685
4915
  } catch (err) {
4686
- printError(`Failed to fetch distributions: ${err}`);
4916
+ printError2(`Failed to fetch distributions: ${err}`);
4687
4917
  process.exit(1);
4688
4918
  }
4689
4919
  }
@@ -4699,7 +4929,7 @@ async function financeReconciliationsCommand(opts) {
4699
4929
  else if (reconciliations.length === 0) console.log("No reconciliations found.");
4700
4930
  else printReconciliationsTable(reconciliations);
4701
4931
  } catch (err) {
4702
- printError(`Failed to fetch reconciliations: ${err}`);
4932
+ printError2(`Failed to fetch reconciliations: ${err}`);
4703
4933
  process.exit(1);
4704
4934
  }
4705
4935
  }
@@ -4715,7 +4945,7 @@ async function financeClassificationsCommand(opts) {
4715
4945
  else if (classifications.length === 0) console.log("No contractor classifications found.");
4716
4946
  else printClassificationsTable(classifications);
4717
4947
  } catch (err) {
4718
- printError(`Failed to fetch contractor classifications: ${err}`);
4948
+ printError2(`Failed to fetch contractor classifications: ${err}`);
4719
4949
  process.exit(1);
4720
4950
  }
4721
4951
  }
@@ -4728,7 +4958,7 @@ async function financeInvoiceCommand(opts) {
4728
4958
  const result = await client.createInvoice({
4729
4959
  entity_id: eid,
4730
4960
  customer_name: opts.customer,
4731
- amount_cents: opts.amount,
4961
+ amount_cents: opts.amountCents,
4732
4962
  due_date: opts.dueDate,
4733
4963
  description: opts.description
4734
4964
  });
@@ -4740,7 +4970,7 @@ async function financeInvoiceCommand(opts) {
4740
4970
  showReuseHint: true
4741
4971
  });
4742
4972
  } catch (err) {
4743
- printError(`Failed to create invoice: ${err}`);
4973
+ printError2(`Failed to create invoice: ${err}`);
4744
4974
  process.exit(1);
4745
4975
  }
4746
4976
  }
@@ -4763,7 +4993,7 @@ async function financePayrollCommand(opts) {
4763
4993
  showReuseHint: true
4764
4994
  });
4765
4995
  } catch (err) {
4766
- printError(`Failed to run payroll: ${err}`);
4996
+ printError2(`Failed to run payroll: ${err}`);
4767
4997
  process.exit(1);
4768
4998
  }
4769
4999
  }
@@ -4775,7 +5005,7 @@ async function financePayCommand(opts) {
4775
5005
  const eid = await resolver.resolveEntity(opts.entityId);
4776
5006
  const result = await client.submitPayment({
4777
5007
  entity_id: eid,
4778
- amount_cents: opts.amount,
5008
+ amount_cents: opts.amountCents,
4779
5009
  recipient: opts.recipient,
4780
5010
  payment_method: opts.method,
4781
5011
  description: `Payment via ${opts.method}`
@@ -4788,7 +5018,7 @@ async function financePayCommand(opts) {
4788
5018
  showReuseHint: true
4789
5019
  });
4790
5020
  } catch (err) {
4791
- printError(`Failed to submit payment: ${err}`);
5021
+ printError2(`Failed to submit payment: ${err}`);
4792
5022
  process.exit(1);
4793
5023
  }
4794
5024
  }
@@ -4807,7 +5037,27 @@ async function financeOpenAccountCommand(opts) {
4807
5037
  showReuseHint: true
4808
5038
  });
4809
5039
  } catch (err) {
4810
- printError(`Failed to open bank account: ${err}`);
5040
+ printError2(`Failed to open bank account: ${err}`);
5041
+ process.exit(1);
5042
+ }
5043
+ }
5044
+ async function financeActivateAccountCommand(accountRef, opts) {
5045
+ const cfg = requireConfig("api_url", "api_key", "workspace_id");
5046
+ const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
5047
+ const resolver = new ReferenceResolver(client, cfg);
5048
+ try {
5049
+ const eid = await resolver.resolveEntity(opts.entityId);
5050
+ const resolvedId = await resolver.resolveBankAccount(eid, accountRef);
5051
+ const result = await client.activateBankAccount(resolvedId, eid);
5052
+ await resolver.stabilizeRecord("bank_account", result, eid);
5053
+ resolver.rememberFromRecord("bank_account", result, eid);
5054
+ printWriteResult(result, `Bank account activated: ${resolvedId}`, {
5055
+ jsonOnly: opts.json,
5056
+ referenceKind: "bank_account",
5057
+ showReuseHint: true
5058
+ });
5059
+ } catch (err) {
5060
+ printError2(`Failed to activate bank account: ${err}`);
4811
5061
  process.exit(1);
4812
5062
  }
4813
5063
  }
@@ -4834,7 +5084,26 @@ async function financeClassifyContractorCommand(opts) {
4834
5084
  showReuseHint: true
4835
5085
  });
4836
5086
  } catch (err) {
4837
- printError(`Failed to classify contractor: ${err}`);
5087
+ printError2(`Failed to classify contractor: ${err}`);
5088
+ process.exit(1);
5089
+ }
5090
+ }
5091
+ async function financeStatementsCommand(opts) {
5092
+ const cfg = requireConfig("api_url", "api_key", "workspace_id");
5093
+ const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
5094
+ const resolver = new ReferenceResolver(client, cfg);
5095
+ try {
5096
+ const eid = await resolver.resolveEntity(opts.entityId);
5097
+ const params = {};
5098
+ if (opts.period) params.period = opts.period;
5099
+ const result = await client.getFinancialStatements(eid, params);
5100
+ if (opts.json) {
5101
+ printJson(result);
5102
+ return;
5103
+ }
5104
+ printJson(result);
5105
+ } catch (err) {
5106
+ printError2(`Failed to fetch financial statements: ${err}`);
4838
5107
  process.exit(1);
4839
5108
  }
4840
5109
  }
@@ -4857,7 +5126,7 @@ async function financeReconcileCommand(opts) {
4857
5126
  showReuseHint: true
4858
5127
  });
4859
5128
  } catch (err) {
4860
- printError(`Failed to reconcile ledger: ${err}`);
5129
+ printError2(`Failed to reconcile ledger: ${err}`);
4861
5130
  process.exit(1);
4862
5131
  }
4863
5132
  }
@@ -4881,9 +5150,13 @@ __export(governance_exports, {
4881
5150
  governanceAddSeatCommand: () => governanceAddSeatCommand,
4882
5151
  governanceConveneCommand: () => governanceConveneCommand,
4883
5152
  governanceCreateBodyCommand: () => governanceCreateBodyCommand,
5153
+ governanceIncidentsCommand: () => governanceIncidentsCommand,
4884
5154
  governanceListCommand: () => governanceListCommand,
4885
5155
  governanceMeetingsCommand: () => governanceMeetingsCommand,
5156
+ governanceModeCommand: () => governanceModeCommand,
4886
5157
  governanceOpenMeetingCommand: () => governanceOpenMeetingCommand,
5158
+ governanceProfileCommand: () => governanceProfileCommand,
5159
+ governanceResignCommand: () => governanceResignCommand,
4887
5160
  governanceResolutionsCommand: () => governanceResolutionsCommand,
4888
5161
  governanceSeatsCommand: () => governanceSeatsCommand,
4889
5162
  governanceVoteCommand: () => governanceVoteCommand,
@@ -4892,6 +5165,7 @@ __export(governance_exports, {
4892
5165
  sendNoticeCommand: () => sendNoticeCommand,
4893
5166
  writtenConsentCommand: () => writtenConsentCommand
4894
5167
  });
5168
+ import { confirm as confirm3 } from "@inquirer/prompts";
4895
5169
  import chalk8 from "chalk";
4896
5170
  async function governanceCreateBodyCommand(opts) {
4897
5171
  const cfg = requireConfig("api_url", "api_key", "workspace_id");
@@ -4920,12 +5194,11 @@ async function governanceCreateBodyCommand(opts) {
4920
5194
  }
4921
5195
  printSuccess(`Governance body created: ${bodyId}`);
4922
5196
  printReferenceSummary("body", result, { showReuseHint: true });
4923
- printJson(result);
4924
5197
  console.log(chalk8.dim("\n Next steps:"));
4925
5198
  console.log(chalk8.dim(` corp governance add-seat @last:body --holder <contact-ref>`));
4926
5199
  console.log(chalk8.dim(` corp governance seats @last:body`));
4927
5200
  } catch (err) {
4928
- printError(`Failed to create governance body: ${err}`);
5201
+ printError2(`Failed to create governance body: ${err}`);
4929
5202
  process.exit(1);
4930
5203
  }
4931
5204
  }
@@ -4951,9 +5224,8 @@ async function governanceAddSeatCommand(bodyId, opts) {
4951
5224
  }
4952
5225
  printSuccess(`Seat added: ${result.seat_id ?? "OK"}`);
4953
5226
  printReferenceSummary("seat", result, { showReuseHint: true });
4954
- printJson(result);
4955
5227
  } catch (err) {
4956
- printError(`Failed to add seat: ${err}`);
5228
+ printError2(`Failed to add seat: ${err}`);
4957
5229
  process.exit(1);
4958
5230
  }
4959
5231
  }
@@ -4969,7 +5241,7 @@ async function governanceListCommand(opts) {
4969
5241
  else if (bodies.length === 0) console.log("No governance bodies found.");
4970
5242
  else printGovernanceTable(bodies);
4971
5243
  } catch (err) {
4972
- printError(`Failed to fetch governance bodies: ${err}`);
5244
+ printError2(`Failed to fetch governance bodies: ${err}`);
4973
5245
  process.exit(1);
4974
5246
  }
4975
5247
  }
@@ -4986,7 +5258,7 @@ async function governanceSeatsCommand(bodyId, opts) {
4986
5258
  else if (seats.length === 0) console.log("No seats found.");
4987
5259
  else printSeatsTable(seats);
4988
5260
  } catch (err) {
4989
- printError(`Failed to fetch seats: ${err}`);
5261
+ printError2(`Failed to fetch seats: ${err}`);
4990
5262
  process.exit(1);
4991
5263
  }
4992
5264
  }
@@ -5003,7 +5275,7 @@ async function governanceMeetingsCommand(bodyId, opts) {
5003
5275
  else if (meetings.length === 0) console.log("No meetings found.");
5004
5276
  else printMeetingsTable(meetings);
5005
5277
  } catch (err) {
5006
- printError(`Failed to fetch meetings: ${err}`);
5278
+ printError2(`Failed to fetch meetings: ${err}`);
5007
5279
  process.exit(1);
5008
5280
  }
5009
5281
  }
@@ -5020,7 +5292,7 @@ async function governanceResolutionsCommand(meetingId, opts) {
5020
5292
  else if (resolutions.length === 0) console.log("No resolutions found.");
5021
5293
  else printResolutionsTable(resolutions);
5022
5294
  } catch (err) {
5023
- printError(`Failed to fetch resolutions: ${err}`);
5295
+ printError2(`Failed to fetch resolutions: ${err}`);
5024
5296
  process.exit(1);
5025
5297
  }
5026
5298
  }
@@ -5053,13 +5325,12 @@ async function governanceConveneCommand(opts) {
5053
5325
  }
5054
5326
  printSuccess(`Meeting scheduled: ${meetingId}`);
5055
5327
  printReferenceSummary("meeting", result, { showReuseHint: true });
5056
- printJson(result);
5057
5328
  console.log(chalk8.dim("\n Next steps:"));
5058
5329
  console.log(chalk8.dim(` corp governance notice @last:meeting`));
5059
5330
  console.log(chalk8.dim(` corp governance open @last:meeting --present-seat <seat-ref>`));
5060
5331
  console.log(chalk8.dim(` corp governance agenda-items @last:meeting`));
5061
5332
  } catch (err) {
5062
- printError(`Failed to schedule meeting: ${err}`);
5333
+ printError2(`Failed to schedule meeting: ${err}`);
5063
5334
  process.exit(1);
5064
5335
  }
5065
5336
  }
@@ -5084,9 +5355,8 @@ async function governanceOpenMeetingCommand(meetingId, opts) {
5084
5355
  return;
5085
5356
  }
5086
5357
  printSuccess(`Meeting opened: ${resolvedMeetingId}`);
5087
- printJson(result);
5088
5358
  } catch (err) {
5089
- printError(`Failed to open meeting: ${err}`);
5359
+ printError2(`Failed to open meeting: ${err}`);
5090
5360
  process.exit(1);
5091
5361
  }
5092
5362
  }
@@ -5114,16 +5384,15 @@ async function governanceVoteCommand(meetingId, itemId, opts) {
5114
5384
  return;
5115
5385
  }
5116
5386
  printSuccess(`Vote cast: ${result.vote_id ?? "OK"}`);
5117
- printJson(result);
5118
5387
  } catch (err) {
5119
5388
  const message = String(err);
5120
5389
  if (message.includes("voting session is not open")) {
5121
- printError(
5390
+ printError2(
5122
5391
  `Failed to cast vote: ${err}
5123
5392
  Open the meeting first: corp governance open ${meetingId} --present-seat <seat-ref>`
5124
5393
  );
5125
5394
  } else {
5126
- printError(`Failed to cast vote: ${err}`);
5395
+ printError2(`Failed to cast vote: ${err}`);
5127
5396
  }
5128
5397
  process.exit(1);
5129
5398
  }
@@ -5145,9 +5414,8 @@ async function sendNoticeCommand(meetingId, opts) {
5145
5414
  return;
5146
5415
  }
5147
5416
  printSuccess(`Notice sent for meeting ${resolvedMeetingId}`);
5148
- printJson(result);
5149
5417
  } catch (err) {
5150
- printError(`Failed to send notice: ${err}`);
5418
+ printError2(`Failed to send notice: ${err}`);
5151
5419
  process.exit(1);
5152
5420
  }
5153
5421
  }
@@ -5168,9 +5436,8 @@ async function adjournMeetingCommand(meetingId, opts) {
5168
5436
  return;
5169
5437
  }
5170
5438
  printSuccess(`Meeting ${resolvedMeetingId} adjourned`);
5171
- printJson(result);
5172
5439
  } catch (err) {
5173
- printError(`Failed to adjourn meeting: ${err}`);
5440
+ printError2(`Failed to adjourn meeting: ${err}`);
5174
5441
  process.exit(1);
5175
5442
  }
5176
5443
  }
@@ -5185,15 +5452,24 @@ async function cancelMeetingCommand(meetingId, opts) {
5185
5452
  printDryRun("governance.cancel_meeting", { entity_id: eid, meeting_id: resolvedMeetingId });
5186
5453
  return;
5187
5454
  }
5455
+ if (!opts.yes) {
5456
+ const ok = await confirm3({
5457
+ message: `Cancel meeting ${resolvedMeetingId}?`,
5458
+ default: false
5459
+ });
5460
+ if (!ok) {
5461
+ console.log("Cancelled.");
5462
+ return;
5463
+ }
5464
+ }
5188
5465
  const result = await client.cancelMeeting(resolvedMeetingId, eid);
5189
5466
  if (opts.json) {
5190
5467
  printJson(result);
5191
5468
  return;
5192
5469
  }
5193
5470
  printSuccess(`Meeting ${resolvedMeetingId} cancelled`);
5194
- printJson(result);
5195
5471
  } catch (err) {
5196
- printError(`Failed to cancel meeting: ${err}`);
5472
+ printError2(`Failed to cancel meeting: ${err}`);
5197
5473
  process.exit(1);
5198
5474
  }
5199
5475
  }
@@ -5214,9 +5490,8 @@ async function reopenMeetingCommand(meetingId, opts) {
5214
5490
  return;
5215
5491
  }
5216
5492
  printSuccess(`Meeting ${resolvedMeetingId} re-opened`);
5217
- printJson(result);
5218
5493
  } catch (err) {
5219
- printError(`Failed to re-open meeting: ${err}`);
5494
+ printError2(`Failed to re-open meeting: ${err}`);
5220
5495
  process.exit(1);
5221
5496
  }
5222
5497
  }
@@ -5242,9 +5517,8 @@ async function finalizeAgendaItemCommand(meetingId, itemId, opts) {
5242
5517
  return;
5243
5518
  }
5244
5519
  printSuccess(`Agenda item ${resolvedItemId} finalized as ${opts.status}`);
5245
- printJson(result);
5246
5520
  } catch (err) {
5247
- printError(`Failed to finalize agenda item: ${err}`);
5521
+ printError2(`Failed to finalize agenda item: ${err}`);
5248
5522
  process.exit(1);
5249
5523
  }
5250
5524
  }
@@ -5277,9 +5551,8 @@ async function computeResolutionCommand(meetingId, itemId, opts) {
5277
5551
  }
5278
5552
  printSuccess(`Resolution computed for agenda item ${itemId}`);
5279
5553
  printReferenceSummary("resolution", result, { showReuseHint: true });
5280
- printJson(result);
5281
5554
  } catch (err) {
5282
- printError(`Failed to compute resolution: ${err}`);
5555
+ printError2(`Failed to compute resolution: ${err}`);
5283
5556
  process.exit(1);
5284
5557
  }
5285
5558
  }
@@ -5303,19 +5576,123 @@ async function writtenConsentCommand(opts) {
5303
5576
  const result = await client.writtenConsent(payload);
5304
5577
  await resolver.stabilizeRecord("meeting", result, eid);
5305
5578
  resolver.rememberFromRecord("meeting", result, eid);
5306
- const meetingId = result.meeting_id ?? "OK";
5579
+ const meetingId = String(result.meeting_id ?? "");
5580
+ if (meetingId) {
5581
+ try {
5582
+ const seats = await client.getGovernanceSeats(resolvedBodyId, eid);
5583
+ const seatIds = seats.map((s2) => String(s2.seat_id ?? s2.id ?? "")).filter((id) => id.length > 0);
5584
+ if (seatIds.length > 0) {
5585
+ await client.conveneMeeting(meetingId, eid, { present_seat_ids: seatIds });
5586
+ }
5587
+ } catch {
5588
+ }
5589
+ }
5307
5590
  if (opts.json) {
5308
5591
  printJson(result);
5309
5592
  return;
5310
5593
  }
5311
- printSuccess(`Written consent created: ${meetingId}`);
5594
+ printSuccess(`Written consent created: ${meetingId || "OK"}`);
5312
5595
  printReferenceSummary("meeting", result, { showReuseHint: true });
5313
- printJson(result);
5314
5596
  console.log(chalk8.dim("\n Next steps:"));
5315
5597
  console.log(chalk8.dim(` corp governance agenda-items @last:meeting`));
5316
5598
  console.log(chalk8.dim(` corp governance vote @last:meeting <item-ref> --voter <contact-ref> --vote for`));
5317
5599
  } catch (err) {
5318
- printError(`Failed to create written consent: ${err}`);
5600
+ printError2(`Failed to create written consent: ${err}`);
5601
+ process.exit(1);
5602
+ }
5603
+ }
5604
+ async function governanceModeCommand(opts) {
5605
+ const cfg = requireConfig("api_url", "api_key", "workspace_id");
5606
+ const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
5607
+ const resolver = new ReferenceResolver(client, cfg);
5608
+ try {
5609
+ const eid = await resolver.resolveEntity(opts.entityId);
5610
+ if (opts.set) {
5611
+ const result = await client.setGovernanceMode({ entity_id: eid, mode: opts.set });
5612
+ if (opts.json) {
5613
+ printJson(result);
5614
+ return;
5615
+ }
5616
+ printSuccess(`Governance mode set to: ${opts.set}`);
5617
+ } else {
5618
+ const result = await client.getGovernanceMode(eid);
5619
+ if (opts.json) {
5620
+ printJson(result);
5621
+ return;
5622
+ }
5623
+ console.log(` ${chalk8.bold("Governance Mode:")} ${result.mode ?? "N/A"}`);
5624
+ if (result.reason) console.log(` ${chalk8.bold("Reason:")} ${result.reason}`);
5625
+ }
5626
+ } catch (err) {
5627
+ printError2(`Failed: ${err}`);
5628
+ process.exit(1);
5629
+ }
5630
+ }
5631
+ async function governanceResignCommand(seatRef, opts) {
5632
+ const cfg = requireConfig("api_url", "api_key", "workspace_id");
5633
+ const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
5634
+ const resolver = new ReferenceResolver(client, cfg);
5635
+ try {
5636
+ const eid = await resolver.resolveEntity(opts.entityId);
5637
+ const seatId = await resolver.resolveSeat(eid, seatRef, opts.bodyId);
5638
+ const result = await client.resignSeat(seatId, eid);
5639
+ if (opts.json) {
5640
+ printJson(result);
5641
+ return;
5642
+ }
5643
+ printSuccess(`Seat ${seatId} resigned.`);
5644
+ } catch (err) {
5645
+ printError2(`Failed to resign seat: ${err}`);
5646
+ process.exit(1);
5647
+ }
5648
+ }
5649
+ async function governanceIncidentsCommand(opts) {
5650
+ const cfg = requireConfig("api_url", "api_key", "workspace_id");
5651
+ const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
5652
+ const resolver = new ReferenceResolver(client, cfg);
5653
+ try {
5654
+ const eid = await resolver.resolveEntity(opts.entityId);
5655
+ const incidents = await client.listGovernanceIncidents(eid);
5656
+ if (opts.json) {
5657
+ printJson(incidents);
5658
+ return;
5659
+ }
5660
+ if (incidents.length === 0) {
5661
+ console.log("No governance incidents found.");
5662
+ return;
5663
+ }
5664
+ for (const inc of incidents) {
5665
+ const status = String(inc.status ?? "open");
5666
+ const colored = status === "resolved" ? chalk8.green(status) : chalk8.red(status);
5667
+ console.log(` [${colored}] ${inc.incident_type ?? "unknown"}: ${inc.description ?? inc.id}`);
5668
+ }
5669
+ } catch (err) {
5670
+ printError2(`Failed to list incidents: ${err}`);
5671
+ process.exit(1);
5672
+ }
5673
+ }
5674
+ async function governanceProfileCommand(opts) {
5675
+ const cfg = requireConfig("api_url", "api_key", "workspace_id");
5676
+ const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
5677
+ const resolver = new ReferenceResolver(client, cfg);
5678
+ try {
5679
+ const eid = await resolver.resolveEntity(opts.entityId);
5680
+ const profile = await client.getGovernanceProfile(eid);
5681
+ if (opts.json) {
5682
+ printJson(profile);
5683
+ return;
5684
+ }
5685
+ console.log(chalk8.blue("\u2500".repeat(40)));
5686
+ console.log(chalk8.blue.bold(" Governance Profile"));
5687
+ console.log(chalk8.blue("\u2500".repeat(40)));
5688
+ for (const [key, value] of Object.entries(profile)) {
5689
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
5690
+ console.log(` ${chalk8.bold(key.replaceAll("_", " ") + ":")} ${value}`);
5691
+ }
5692
+ }
5693
+ console.log(chalk8.blue("\u2500".repeat(40)));
5694
+ } catch (err) {
5695
+ printError2(`Failed to get governance profile: ${err}`);
5319
5696
  process.exit(1);
5320
5697
  }
5321
5698
  }
@@ -5332,7 +5709,7 @@ async function listAgendaItemsCommand(meetingId, opts) {
5332
5709
  else if (items.length === 0) console.log("No agenda items found.");
5333
5710
  else printAgendaItemsTable(items);
5334
5711
  } catch (err) {
5335
- printError(`Failed to list agenda items: ${err}`);
5712
+ printError2(`Failed to list agenda items: ${err}`);
5336
5713
  process.exit(1);
5337
5714
  }
5338
5715
  }
@@ -5573,7 +5950,7 @@ async function documentsListCommand(opts) {
5573
5950
  else if (docs.length === 0) console.log("No documents found.");
5574
5951
  else printDocumentsTable(docs);
5575
5952
  } catch (err) {
5576
- printError(`Failed to fetch documents: ${err}`);
5953
+ printError2(`Failed to fetch documents: ${err}`);
5577
5954
  process.exit(1);
5578
5955
  }
5579
5956
  }
@@ -5583,7 +5960,17 @@ async function documentsSigningLinkCommand(docId, opts) {
5583
5960
  const resolver = new ReferenceResolver(client, cfg);
5584
5961
  try {
5585
5962
  const eid = await resolver.resolveEntity(opts.entityId);
5586
- const resolvedDocumentId = await resolver.resolveDocument(eid, docId);
5963
+ let resolvedDocumentId;
5964
+ try {
5965
+ resolvedDocumentId = await resolver.resolveDocument(eid, docId);
5966
+ } catch {
5967
+ printError2(
5968
+ `Could not resolve '${docId}' as a document. If you just generated a contract, use the document_id from the generate output, not @last (which may reference the contract_id).
5969
+ List documents with: corp documents`
5970
+ );
5971
+ process.exit(1);
5972
+ return;
5973
+ }
5587
5974
  const result = await client.getSigningLink(resolvedDocumentId, eid);
5588
5975
  const shareUrl = formatSigningLink(resolvedDocumentId, result);
5589
5976
  if (process.stdout.isTTY) {
@@ -5593,7 +5980,7 @@ async function documentsSigningLinkCommand(docId, opts) {
5593
5980
  }
5594
5981
  console.log(shareUrl);
5595
5982
  } catch (err) {
5596
- printError(`Failed to get signing link: ${err}`);
5983
+ printError2(`Failed to get signing link: ${err}`);
5597
5984
  process.exit(1);
5598
5985
  }
5599
5986
  }
@@ -5628,13 +6015,33 @@ async function documentsGenerateCommand(opts) {
5628
6015
  });
5629
6016
  await resolver.stabilizeRecord("document", result, eid);
5630
6017
  resolver.rememberFromRecord("document", result, eid);
6018
+ if (result.document_id) {
6019
+ resolver.remember("document", String(result.document_id), eid);
6020
+ }
5631
6021
  printWriteResult(result, `Contract generated: ${result.contract_id ?? "OK"}`, {
5632
6022
  jsonOnly: opts.json,
5633
6023
  referenceKind: "document",
5634
6024
  showReuseHint: true
5635
6025
  });
5636
6026
  } catch (err) {
5637
- printError(`Failed to generate contract: ${err}`);
6027
+ const msg = String(err);
6028
+ if (opts.template === "employment_offer" && (msg.includes("department") || msg.includes("required"))) {
6029
+ printError2(
6030
+ `Failed to generate employment_offer: ${msg}
6031
+ Hint: employment_offer requires additional parameters. Use --param for each:
6032
+ --param department=Engineering --param dispute_resolution_terms=arbitration
6033
+ --param equity_grant_type=stock_option --param equity_shares=10000
6034
+ Or pass --base-salary 150000`
6035
+ );
6036
+ } else if (opts.template === "safe_agreement" && (msg.includes("purchase_amount") || msg.includes("required"))) {
6037
+ printError2(
6038
+ `Failed to generate safe_agreement: ${msg}
6039
+ Hint: safe_agreement requires purchase_amount. Use:
6040
+ --param purchase_amount=50000000`
6041
+ );
6042
+ } else {
6043
+ printError2(`Failed to generate contract: ${err}`);
6044
+ }
5638
6045
  process.exit(1);
5639
6046
  }
5640
6047
  }
@@ -5689,7 +6096,7 @@ async function documentsSignCommand(docId, opts) {
5689
6096
  printReferenceSummary("document", result.document, { showReuseHint: true });
5690
6097
  printJson(result.document);
5691
6098
  } catch (err) {
5692
- printError(`Failed to sign document: ${err}`);
6099
+ printError2(`Failed to sign document: ${err}`);
5693
6100
  process.exit(1);
5694
6101
  }
5695
6102
  }
@@ -5714,13 +6121,13 @@ async function documentsSignAllCommand(opts) {
5714
6121
  signatures: Array.isArray(document.signatures) ? document.signatures.length : document.signatures
5715
6122
  })));
5716
6123
  } catch (err) {
5717
- printError(`Failed to sign formation documents: ${err}`);
6124
+ printError2(`Failed to sign formation documents: ${err}`);
5718
6125
  process.exit(1);
5719
6126
  }
5720
6127
  }
5721
6128
  async function documentsPreviewPdfCommand(opts) {
5722
6129
  if (!opts.documentId || opts.documentId.trim().length === 0) {
5723
- printError("preview-pdf requires --definition-id (or deprecated alias --document-id)");
6130
+ printError2("preview-pdf requires --definition-id (or deprecated alias --document-id)");
5724
6131
  process.exit(1);
5725
6132
  }
5726
6133
  const cfg = requireConfig("api_url", "api_key", "workspace_id");
@@ -5733,7 +6140,7 @@ async function documentsPreviewPdfCommand(opts) {
5733
6140
  printSuccess(`Preview PDF URL: ${url}`);
5734
6141
  console.log("The document definition was validated successfully. Use your API key to download the PDF.");
5735
6142
  } catch (err) {
5736
- printError(`Failed to validate preview PDF: ${err}`);
6143
+ printError2(`Failed to validate preview PDF: ${err}`);
5737
6144
  process.exit(1);
5738
6145
  }
5739
6146
  }
@@ -5756,8 +6163,34 @@ __export(tax_exports, {
5756
6163
  taxDeadlineCommand: () => taxDeadlineCommand,
5757
6164
  taxDeadlinesCommand: () => taxDeadlinesCommand,
5758
6165
  taxFileCommand: () => taxFileCommand,
5759
- taxFilingsCommand: () => taxFilingsCommand
6166
+ taxFilingsCommand: () => taxFilingsCommand,
6167
+ taxSummaryCommand: () => taxSummaryCommand
5760
6168
  });
6169
+ async function taxSummaryCommand(opts) {
6170
+ const cfg = requireConfig("api_url", "api_key", "workspace_id");
6171
+ const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
6172
+ const resolver = new ReferenceResolver(client, cfg);
6173
+ try {
6174
+ const eid = await resolver.resolveEntity(opts.entityId);
6175
+ const [filings, deadlines] = await Promise.all([
6176
+ client.listTaxFilings(eid),
6177
+ client.listDeadlines(eid)
6178
+ ]);
6179
+ if (opts.json) {
6180
+ printJson({ filings, deadlines });
6181
+ return;
6182
+ }
6183
+ if (filings.length === 0 && deadlines.length === 0) {
6184
+ console.log("No tax filings or deadlines found.");
6185
+ return;
6186
+ }
6187
+ if (filings.length > 0) printTaxFilingsTable(filings);
6188
+ if (deadlines.length > 0) printDeadlinesTable(deadlines);
6189
+ } catch (err) {
6190
+ printError2(`Failed to fetch tax summary: ${err}`);
6191
+ process.exit(1);
6192
+ }
6193
+ }
5761
6194
  function normalizeRecurrence(recurrence) {
5762
6195
  if (!recurrence) return void 0;
5763
6196
  if (recurrence === "yearly") return "annual";
@@ -5775,7 +6208,7 @@ async function taxFilingsCommand(opts) {
5775
6208
  else if (filings.length === 0) console.log("No tax filings found.");
5776
6209
  else printTaxFilingsTable(filings);
5777
6210
  } catch (err) {
5778
- printError(`Failed to fetch tax filings: ${err}`);
6211
+ printError2(`Failed to fetch tax filings: ${err}`);
5779
6212
  process.exit(1);
5780
6213
  }
5781
6214
  }
@@ -5791,7 +6224,7 @@ async function taxDeadlinesCommand(opts) {
5791
6224
  else if (deadlines.length === 0) console.log("No deadlines found.");
5792
6225
  else printDeadlinesTable(deadlines);
5793
6226
  } catch (err) {
5794
- printError(`Failed to fetch deadlines: ${err}`);
6227
+ printError2(`Failed to fetch deadlines: ${err}`);
5795
6228
  process.exit(1);
5796
6229
  }
5797
6230
  }
@@ -5800,8 +6233,9 @@ async function taxFileCommand(opts) {
5800
6233
  const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
5801
6234
  const resolver = new ReferenceResolver(client, cfg);
5802
6235
  try {
6236
+ const docType = TAX_TYPE_ALIASES[opts.type] ?? opts.type;
5803
6237
  const eid = await resolver.resolveEntity(opts.entityId);
5804
- const result = await client.fileTaxDocument({ entity_id: eid, document_type: opts.type, tax_year: opts.year });
6238
+ const result = await client.fileTaxDocument({ entity_id: eid, document_type: docType, tax_year: opts.year });
5805
6239
  await resolver.stabilizeRecord("tax_filing", result, eid);
5806
6240
  resolver.rememberFromRecord("tax_filing", result, eid);
5807
6241
  printWriteResult(result, `Tax document filed: ${result.filing_id ?? "OK"}`, {
@@ -5810,7 +6244,7 @@ async function taxFileCommand(opts) {
5810
6244
  showReuseHint: true
5811
6245
  });
5812
6246
  } catch (err) {
5813
- printError(`Failed to file tax document: ${err}`);
6247
+ printError2(`Failed to file tax document: ${err}`);
5814
6248
  process.exit(1);
5815
6249
  }
5816
6250
  }
@@ -5837,10 +6271,11 @@ async function taxDeadlineCommand(opts) {
5837
6271
  showReuseHint: true
5838
6272
  });
5839
6273
  } catch (err) {
5840
- printError(`Failed to track deadline: ${err}`);
6274
+ printError2(`Failed to track deadline: ${err}`);
5841
6275
  process.exit(1);
5842
6276
  }
5843
6277
  }
6278
+ var TAX_TYPE_ALIASES;
5844
6279
  var init_tax = __esm({
5845
6280
  "src/commands/tax.ts"() {
5846
6281
  "use strict";
@@ -5848,6 +6283,15 @@ var init_tax = __esm({
5848
6283
  init_api_client();
5849
6284
  init_output();
5850
6285
  init_references();
6286
+ TAX_TYPE_ALIASES = {
6287
+ form_1120: "1120",
6288
+ form_1120s: "1120s",
6289
+ form_1065: "1065",
6290
+ form_1099_nec: "1099_nec",
6291
+ form_k1: "k1",
6292
+ form_941: "941",
6293
+ form_w2: "w2"
6294
+ };
5851
6295
  }
5852
6296
  });
5853
6297
 
@@ -5856,7 +6300,9 @@ var agents_exports = {};
5856
6300
  __export(agents_exports, {
5857
6301
  agentsCreateCommand: () => agentsCreateCommand,
5858
6302
  agentsDeleteCommand: () => agentsDeleteCommand,
5859
- agentsExecutionsCommand: () => agentsExecutionsCommand,
6303
+ agentsExecutionCommand: () => agentsExecutionCommand,
6304
+ agentsExecutionResultCommand: () => agentsExecutionResultCommand,
6305
+ agentsKillCommand: () => agentsKillCommand,
5860
6306
  agentsListCommand: () => agentsListCommand,
5861
6307
  agentsMessageCommand: () => agentsMessageCommand,
5862
6308
  agentsPauseCommand: () => agentsPauseCommand,
@@ -5864,6 +6310,7 @@ __export(agents_exports, {
5864
6310
  agentsShowCommand: () => agentsShowCommand,
5865
6311
  agentsSkillCommand: () => agentsSkillCommand
5866
6312
  });
6313
+ import { confirm as confirm4 } from "@inquirer/prompts";
5867
6314
  import chalk9 from "chalk";
5868
6315
  import { readFileSync as readFileSync2, realpathSync } from "fs";
5869
6316
  import { relative, resolve } from "path";
@@ -5878,7 +6325,7 @@ async function agentsListCommand(opts) {
5878
6325
  else if (agents.length === 0) console.log("No agents found.");
5879
6326
  else printAgentsTable(agents);
5880
6327
  } catch (err) {
5881
- printError(`Failed to fetch agents: ${err}`);
6328
+ printError2(`Failed to fetch agents: ${err}`);
5882
6329
  process.exit(1);
5883
6330
  }
5884
6331
  }
@@ -5911,7 +6358,7 @@ async function agentsShowCommand(agentId, opts) {
5911
6358
  }
5912
6359
  console.log(chalk9.magenta("\u2500".repeat(40)));
5913
6360
  } catch (err) {
5914
- printError(`Failed to fetch agent: ${err}`);
6361
+ printError2(`Failed to fetch agent: ${err}`);
5915
6362
  process.exit(1);
5916
6363
  }
5917
6364
  }
@@ -5931,7 +6378,15 @@ async function agentsCreateCommand(opts) {
5931
6378
  showReuseHint: true
5932
6379
  });
5933
6380
  } catch (err) {
5934
- printError(`Failed to create agent: ${err}`);
6381
+ const msg = String(err);
6382
+ if (msg.includes("409") || msg.includes("conflict") || msg.includes("already exists")) {
6383
+ printError2(
6384
+ `Agent name '${opts.name}' is already in use (deleted agents still reserve their name).
6385
+ Choose a different name, e.g.: corp agents create --name '...-v2' --prompt '...'`
6386
+ );
6387
+ } else {
6388
+ printError2(`Failed to create agent: ${err}`);
6389
+ }
5935
6390
  process.exit(1);
5936
6391
  }
5937
6392
  }
@@ -5944,7 +6399,7 @@ async function agentsPauseCommand(agentId, opts) {
5944
6399
  const result = await client.updateAgent(resolvedAgentId, { status: "paused" });
5945
6400
  printWriteResult(result, `Agent ${resolvedAgentId} paused.`, opts.json);
5946
6401
  } catch (err) {
5947
- printError(`Failed to pause agent: ${err}`);
6402
+ printError2(`Failed to pause agent: ${err}`);
5948
6403
  process.exit(1);
5949
6404
  }
5950
6405
  }
@@ -5957,7 +6412,16 @@ async function agentsResumeCommand(agentId, opts) {
5957
6412
  const result = await client.updateAgent(resolvedAgentId, { status: "active" });
5958
6413
  printWriteResult(result, `Agent ${resolvedAgentId} resumed.`, opts.json);
5959
6414
  } catch (err) {
5960
- printError(`Failed to resume agent: ${err}`);
6415
+ const msg = String(err);
6416
+ if (msg.includes("409") || msg.includes("disabled") || msg.includes("deleted")) {
6417
+ printError2(
6418
+ `Cannot resume agent ${agentId}: the agent may be disabled or deleted.
6419
+ Disabled/deleted agents cannot be resumed. Create a new agent instead:
6420
+ corp agents create --name '...' --prompt '...'`
6421
+ );
6422
+ } else {
6423
+ printError2(`Failed to resume agent: ${err}`);
6424
+ }
5961
6425
  process.exit(1);
5962
6426
  }
5963
6427
  }
@@ -5967,10 +6431,20 @@ async function agentsDeleteCommand(agentId, opts) {
5967
6431
  const resolver = new ReferenceResolver(client, cfg);
5968
6432
  try {
5969
6433
  const resolvedAgentId = await resolver.resolveAgent(agentId);
6434
+ if (!opts.yes) {
6435
+ const ok = await confirm4({
6436
+ message: `Delete agent ${resolvedAgentId}? This cannot be undone.`,
6437
+ default: false
6438
+ });
6439
+ if (!ok) {
6440
+ console.log("Cancelled.");
6441
+ return;
6442
+ }
6443
+ }
5970
6444
  const result = await client.deleteAgent(resolvedAgentId);
5971
6445
  printWriteResult(result, `Agent ${resolvedAgentId} deleted.`, opts.json);
5972
6446
  } catch (err) {
5973
- printError(`Failed to delete agent: ${err}`);
6447
+ printError2(`Failed to delete agent: ${err}`);
5974
6448
  process.exit(1);
5975
6449
  }
5976
6450
  }
@@ -6010,21 +6484,80 @@ async function agentsMessageCommand(agentId, opts) {
6010
6484
  const result = await client.sendAgentMessage(resolvedAgentId, body);
6011
6485
  printWriteResult(result, `Message sent. Execution: ${result.execution_id ?? "OK"}`, opts.json);
6012
6486
  } catch (err) {
6013
- printError(`Failed to send message: ${err}`);
6487
+ const msg = String(err);
6488
+ if (msg.includes("409")) {
6489
+ printError2(
6490
+ `Cannot message agent: the agent must be active or paused (not disabled/deleted).
6491
+ Check agent status: corp agents show ` + agentId + "\n Resume a paused agent: corp agents resume " + agentId
6492
+ );
6493
+ } else {
6494
+ printError2(`Failed to send message: ${err}`);
6495
+ }
6014
6496
  process.exit(1);
6015
6497
  }
6016
6498
  }
6017
- async function agentsExecutionsCommand(agentId, _opts) {
6499
+ async function agentsExecutionCommand(agentId, executionId, opts) {
6018
6500
  const cfg = requireConfig("api_url", "api_key", "workspace_id");
6019
6501
  const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
6020
6502
  const resolver = new ReferenceResolver(client, cfg);
6021
- const resolvedAgentId = await resolver.resolveAgent(agentId);
6022
- printError(
6023
- `Listing executions is not yet supported.
6024
- To inspect a specific run, use the execution ID returned by "agents message":
6025
- GET /v1/agents/${resolvedAgentId}/executions/<execution-id>`
6026
- );
6027
- process.exit(1);
6503
+ try {
6504
+ const resolvedAgentId = await resolver.resolveAgent(agentId);
6505
+ const result = await client.getAgentExecution(resolvedAgentId, executionId);
6506
+ if (opts.json) {
6507
+ printJson(result);
6508
+ return;
6509
+ }
6510
+ console.log(chalk9.magenta("\u2500".repeat(40)));
6511
+ console.log(chalk9.magenta.bold(" Execution Status"));
6512
+ console.log(chalk9.magenta("\u2500".repeat(40)));
6513
+ console.log(` ${chalk9.bold("Execution:")} ${executionId}`);
6514
+ console.log(` ${chalk9.bold("Agent:")} ${resolvedAgentId}`);
6515
+ console.log(` ${chalk9.bold("Status:")} ${result.status ?? "N/A"}`);
6516
+ if (result.started_at) console.log(` ${chalk9.bold("Started:")} ${result.started_at}`);
6517
+ if (result.completed_at) console.log(` ${chalk9.bold("Completed:")} ${result.completed_at}`);
6518
+ console.log(chalk9.magenta("\u2500".repeat(40)));
6519
+ } catch (err) {
6520
+ printError2(`Failed to get execution: ${err}`);
6521
+ process.exit(1);
6522
+ }
6523
+ }
6524
+ async function agentsExecutionResultCommand(agentId, executionId, opts) {
6525
+ const cfg = requireConfig("api_url", "api_key", "workspace_id");
6526
+ const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
6527
+ const resolver = new ReferenceResolver(client, cfg);
6528
+ try {
6529
+ const resolvedAgentId = await resolver.resolveAgent(agentId);
6530
+ const result = await client.getAgentExecutionResult(resolvedAgentId, executionId);
6531
+ if (opts.json) {
6532
+ printJson(result);
6533
+ return;
6534
+ }
6535
+ printSuccess(`Result for execution ${executionId}:`);
6536
+ printJson(result);
6537
+ } catch (err) {
6538
+ printError2(`Failed to get execution result: ${err}`);
6539
+ process.exit(1);
6540
+ }
6541
+ }
6542
+ async function agentsKillCommand(agentId, executionId, opts) {
6543
+ const cfg = requireConfig("api_url", "api_key", "workspace_id");
6544
+ const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
6545
+ const resolver = new ReferenceResolver(client, cfg);
6546
+ try {
6547
+ const resolvedAgentId = await resolver.resolveAgent(agentId);
6548
+ if (!opts.yes) {
6549
+ const ok = await confirm4({ message: `Kill execution ${executionId}?`, default: false });
6550
+ if (!ok) {
6551
+ console.log("Cancelled.");
6552
+ return;
6553
+ }
6554
+ }
6555
+ const result = await client.killAgentExecution(resolvedAgentId, executionId);
6556
+ printWriteResult(result, `Execution ${executionId} killed.`, opts.json);
6557
+ } catch (err) {
6558
+ printError2(`Failed to kill execution: ${err}`);
6559
+ process.exit(1);
6560
+ }
6028
6561
  }
6029
6562
  async function agentsSkillCommand(agentId, opts) {
6030
6563
  const cfg = requireConfig("api_url", "api_key", "workspace_id");
@@ -6044,7 +6577,7 @@ async function agentsSkillCommand(agentId, opts) {
6044
6577
  });
6045
6578
  printWriteResult(result, `Skill '${opts.name}' added to agent ${resolvedAgentId}.`, opts.json);
6046
6579
  } catch (err) {
6047
- printError(`Failed to add skill: ${err}`);
6580
+ printError2(`Failed to add skill: ${err}`);
6048
6581
  process.exit(1);
6049
6582
  }
6050
6583
  }
@@ -6069,6 +6602,7 @@ __export(work_items_exports, {
6069
6602
  workItemsReleaseCommand: () => workItemsReleaseCommand,
6070
6603
  workItemsShowCommand: () => workItemsShowCommand
6071
6604
  });
6605
+ import { confirm as confirm5 } from "@inquirer/prompts";
6072
6606
  import chalk10 from "chalk";
6073
6607
  function actorLabel2(record, key) {
6074
6608
  const actor = record[`${key}_actor`];
@@ -6097,7 +6631,7 @@ async function workItemsListCommand(opts) {
6097
6631
  else if (items.length === 0) console.log("No work items found.");
6098
6632
  else printWorkItemsTable(items);
6099
6633
  } catch (err) {
6100
- printError(`Failed to fetch work items: ${err}`);
6634
+ printError2(`Failed to fetch work items: ${err}`);
6101
6635
  process.exit(1);
6102
6636
  }
6103
6637
  }
@@ -6137,7 +6671,7 @@ async function workItemsShowCommand(workItemId, opts) {
6137
6671
  console.log(` ${chalk10.bold("Created at:")} ${w.created_at ?? "N/A"}`);
6138
6672
  console.log(chalk10.cyan("\u2500".repeat(40)));
6139
6673
  } catch (err) {
6140
- printError(`Failed to fetch work item: ${err}`);
6674
+ printError2(`Failed to fetch work item: ${err}`);
6141
6675
  process.exit(1);
6142
6676
  }
6143
6677
  }
@@ -6147,10 +6681,6 @@ async function workItemsCreateCommand(opts) {
6147
6681
  const resolver = new ReferenceResolver(client, cfg);
6148
6682
  try {
6149
6683
  const eid = await resolver.resolveEntity(opts.entityId);
6150
- if (!opts.category) {
6151
- printError("Missing required option: --category <category>");
6152
- process.exit(1);
6153
- }
6154
6684
  const data = { title: opts.title, category: opts.category };
6155
6685
  if (opts.description) data.description = opts.description;
6156
6686
  if (opts.deadline) data.deadline = opts.deadline;
@@ -6165,7 +6695,7 @@ async function workItemsCreateCommand(opts) {
6165
6695
  { jsonOnly: opts.json, referenceKind: "work_item", showReuseHint: true }
6166
6696
  );
6167
6697
  } catch (err) {
6168
- printError(`Failed to create work item: ${err}`);
6698
+ printError2(`Failed to create work item: ${err}`);
6169
6699
  process.exit(1);
6170
6700
  }
6171
6701
  }
@@ -6183,7 +6713,7 @@ async function workItemsClaimCommand(workItemId, opts) {
6183
6713
  const result = await client.claimWorkItem(eid, resolvedWorkItemId, data);
6184
6714
  printWriteResult(result, `Work item ${resolvedWorkItemId} claimed by ${opts.claimedBy}.`, opts.json);
6185
6715
  } catch (err) {
6186
- printError(`Failed to claim work item: ${err}`);
6716
+ printError2(`Failed to claim work item: ${err}`);
6187
6717
  process.exit(1);
6188
6718
  }
6189
6719
  }
@@ -6201,7 +6731,7 @@ async function workItemsCompleteCommand(workItemId, opts) {
6201
6731
  const result = await client.completeWorkItem(eid, resolvedWorkItemId, data);
6202
6732
  printWriteResult(result, `Work item ${resolvedWorkItemId} completed.`, opts.json);
6203
6733
  } catch (err) {
6204
- printError(`Failed to complete work item: ${err}`);
6734
+ printError2(`Failed to complete work item: ${err}`);
6205
6735
  process.exit(1);
6206
6736
  }
6207
6737
  }
@@ -6215,7 +6745,7 @@ async function workItemsReleaseCommand(workItemId, opts) {
6215
6745
  const result = await client.releaseWorkItem(eid, resolvedWorkItemId);
6216
6746
  printWriteResult(result, `Work item ${resolvedWorkItemId} claim released.`, opts.json);
6217
6747
  } catch (err) {
6218
- printError(`Failed to release work item: ${err}`);
6748
+ printError2(`Failed to release work item: ${err}`);
6219
6749
  process.exit(1);
6220
6750
  }
6221
6751
  }
@@ -6226,10 +6756,20 @@ async function workItemsCancelCommand(workItemId, opts) {
6226
6756
  try {
6227
6757
  const eid = await resolver.resolveEntity(opts.entityId);
6228
6758
  const resolvedWorkItemId = await resolver.resolveWorkItem(eid, workItemId);
6759
+ if (!opts.yes) {
6760
+ const ok = await confirm5({
6761
+ message: `Cancel work item ${resolvedWorkItemId}?`,
6762
+ default: false
6763
+ });
6764
+ if (!ok) {
6765
+ console.log("Cancelled.");
6766
+ return;
6767
+ }
6768
+ }
6229
6769
  const result = await client.cancelWorkItem(eid, resolvedWorkItemId);
6230
6770
  printWriteResult(result, `Work item ${resolvedWorkItemId} cancelled.`, opts.json);
6231
6771
  } catch (err) {
6232
- printError(`Failed to cancel work item: ${err}`);
6772
+ printError2(`Failed to cancel work item: ${err}`);
6233
6773
  process.exit(1);
6234
6774
  }
6235
6775
  }
@@ -6265,7 +6805,7 @@ async function servicesCatalogCommand(opts) {
6265
6805
  }
6266
6806
  printServiceCatalogTable(items);
6267
6807
  } catch (err) {
6268
- printError(`Failed to list service catalog: ${err}`);
6808
+ printError2(`Failed to list service catalog: ${err}`);
6269
6809
  process.exit(1);
6270
6810
  }
6271
6811
  }
@@ -6306,7 +6846,7 @@ async function servicesBuyCommand(slug, opts) {
6306
6846
  });
6307
6847
  }
6308
6848
  } catch (err) {
6309
- printError(`Failed to create service request: ${err}`);
6849
+ printError2(`Failed to create service request: ${err}`);
6310
6850
  process.exit(1);
6311
6851
  }
6312
6852
  }
@@ -6324,7 +6864,7 @@ async function servicesListCommand(opts) {
6324
6864
  }
6325
6865
  printServiceRequestsTable(stable);
6326
6866
  } catch (err) {
6327
- printError(`Failed to list service requests: ${err}`);
6867
+ printError2(`Failed to list service requests: ${err}`);
6328
6868
  process.exit(1);
6329
6869
  }
6330
6870
  }
@@ -6345,7 +6885,7 @@ async function servicesShowCommand(ref_, opts) {
6345
6885
  printReferenceSummary("service_request", result);
6346
6886
  printJson(result);
6347
6887
  } catch (err) {
6348
- printError(`Failed to show service request: ${err}`);
6888
+ printError2(`Failed to show service request: ${err}`);
6349
6889
  process.exit(1);
6350
6890
  }
6351
6891
  }
@@ -6370,7 +6910,7 @@ async function servicesFulfillCommand(ref_, opts) {
6370
6910
  printReferenceSummary("service_request", result, { showReuseHint: true });
6371
6911
  printJson(result);
6372
6912
  } catch (err) {
6373
- printError(`Failed to fulfill service request: ${err}`);
6913
+ printError2(`Failed to fulfill service request: ${err}`);
6374
6914
  process.exit(1);
6375
6915
  }
6376
6916
  }
@@ -6394,7 +6934,7 @@ async function servicesCancelCommand(ref_, opts) {
6394
6934
  printReferenceSummary("service_request", result, { showReuseHint: true });
6395
6935
  printJson(result);
6396
6936
  } catch (err) {
6397
- printError(`Failed to cancel service request: ${err}`);
6937
+ printError2(`Failed to cancel service request: ${err}`);
6398
6938
  process.exit(1);
6399
6939
  }
6400
6940
  }
@@ -6439,7 +6979,7 @@ async function billingCommand(opts) {
6439
6979
  if (opts.json) printJson({ status: enrichedStatus, plans });
6440
6980
  else printBillingPanel(enrichedStatus, plans);
6441
6981
  } catch (err) {
6442
- printError(`Failed to fetch billing info: ${err}`);
6982
+ printError2(`Failed to fetch billing info: ${err}`);
6443
6983
  process.exit(1);
6444
6984
  }
6445
6985
  }
@@ -6449,13 +6989,13 @@ async function billingPortalCommand() {
6449
6989
  const result = await client.createBillingPortal();
6450
6990
  const url = result.portal_url;
6451
6991
  if (!url) {
6452
- printError("No portal URL returned. Ensure you have an active subscription.");
6992
+ printError2("No portal URL returned. Ensure you have an active subscription.");
6453
6993
  process.exit(1);
6454
6994
  }
6455
6995
  printSuccess("Stripe Customer Portal URL:");
6456
6996
  console.log(url);
6457
6997
  } catch (err) {
6458
- printError(`Failed to create portal session: ${err}`);
6998
+ printError2(`Failed to create portal session: ${err}`);
6459
6999
  process.exit(1);
6460
7000
  }
6461
7001
  }
@@ -6465,13 +7005,13 @@ async function billingUpgradeCommand(opts) {
6465
7005
  const result = await client.createBillingCheckout(opts.plan);
6466
7006
  const url = result.checkout_url;
6467
7007
  if (!url) {
6468
- printError("No checkout URL returned.");
7008
+ printError2("No checkout URL returned.");
6469
7009
  process.exit(1);
6470
7010
  }
6471
7011
  printSuccess(`Stripe Checkout URL for ${opts.plan}:`);
6472
7012
  console.log(url);
6473
7013
  } catch (err) {
6474
- printError(`Failed to create checkout session: ${err}`);
7014
+ printError2(`Failed to create checkout session: ${err}`);
6475
7015
  process.exit(1);
6476
7016
  }
6477
7017
  }
@@ -6490,11 +7030,24 @@ __export(approvals_exports, {
6490
7030
  approvalsListCommand: () => approvalsListCommand,
6491
7031
  approvalsRespondCommand: () => approvalsRespondCommand
6492
7032
  });
7033
+ import chalk12 from "chalk";
6493
7034
  async function approvalsListCommand(_opts) {
6494
- printError(
6495
- "Approvals are managed through governance meetings.\n Use: corp governance convene ... to schedule a board meeting\n Use: corp governance vote <meeting-ref> <item-ref> ... to cast votes"
6496
- );
6497
- process.exit(1);
7035
+ console.log(chalk12.bold("Approvals in TheCorporation"));
7036
+ console.log();
7037
+ console.log("Approvals are handled through governance meetings and execution intents.");
7038
+ console.log("Use these commands to manage approvals:");
7039
+ console.log();
7040
+ console.log(chalk12.dim(" Board approval via meeting vote:"));
7041
+ console.log(` corp governance convene --body <body> --type board_meeting --title "Approve X"`);
7042
+ console.log(` corp governance vote <meeting> <item> --voter <contact> --vote for`);
7043
+ console.log();
7044
+ console.log(chalk12.dim(" Written consent (no meeting needed):"));
7045
+ console.log(` corp governance written-consent --body <body> --title "Approve X" --description "..."`);
7046
+ console.log();
7047
+ console.log(chalk12.dim(" View pending items:"));
7048
+ console.log(` corp governance meetings <body> # see scheduled meetings`);
7049
+ console.log(` corp governance agenda-items <meeting> # see items awaiting votes`);
7050
+ console.log(` corp cap-table valuations # see pending valuations`);
6498
7051
  }
6499
7052
  async function approvalsRespondCommand(_approvalId, _decision, _opts) {
6500
7053
  printError(
@@ -6505,7 +7058,6 @@ async function approvalsRespondCommand(_approvalId, _decision, _opts) {
6505
7058
  var init_approvals = __esm({
6506
7059
  "src/commands/approvals.ts"() {
6507
7060
  "use strict";
6508
- init_output();
6509
7061
  }
6510
7062
  });
6511
7063
 
@@ -6518,8 +7070,8 @@ __export(form_exports, {
6518
7070
  formCreateCommand: () => formCreateCommand,
6519
7071
  formFinalizeCommand: () => formFinalizeCommand
6520
7072
  });
6521
- import { input as input2, select as select2, confirm as confirm2, number } from "@inquirer/prompts";
6522
- import chalk12 from "chalk";
7073
+ import { input as input2, select as select2, confirm as confirm6, number } from "@inquirer/prompts";
7074
+ import chalk13 from "chalk";
6523
7075
  import Table3 from "cli-table3";
6524
7076
  import { readFileSync as readFileSync3, realpathSync as realpathSync2 } from "fs";
6525
7077
  import { relative as relative2, resolve as resolve2 } from "path";
@@ -6529,9 +7081,9 @@ function isCorp(entityType) {
6529
7081
  }
6530
7082
  function sectionHeader(title) {
6531
7083
  console.log();
6532
- console.log(chalk12.blue("\u2500".repeat(50)));
6533
- console.log(chalk12.blue.bold(` ${title}`));
6534
- console.log(chalk12.blue("\u2500".repeat(50)));
7084
+ console.log(chalk13.blue("\u2500".repeat(50)));
7085
+ console.log(chalk13.blue.bold(` ${title}`));
7086
+ console.log(chalk13.blue("\u2500".repeat(50)));
6535
7087
  }
6536
7088
  function officerTitleLabel(title) {
6537
7089
  switch (title) {
@@ -6587,7 +7139,7 @@ function normalizeFounderInfo(input3) {
6587
7139
  throw new Error("Founder JSON requires non-empty name, email, and role.");
6588
7140
  }
6589
7141
  const founder = { name, email, role };
6590
- const ownershipPct = input3.ownership_pct ?? input3.pct;
7142
+ const ownershipPct = input3.ownership_pct ?? input3.membership_pct ?? input3.pct;
6591
7143
  if (ownershipPct != null) founder.ownership_pct = Number(ownershipPct);
6592
7144
  const sharesPurchased = input3.shares_purchased ?? input3.shares;
6593
7145
  if (sharesPurchased != null) founder.shares_purchased = Number(sharesPurchased);
@@ -6703,7 +7255,7 @@ async function phaseEntityDetails(opts, serverCfg, scripted) {
6703
7255
  let name = opts.name;
6704
7256
  if (!name) {
6705
7257
  if (scripted) {
6706
- printError("--name is required in scripted mode");
7258
+ printError2("--name is required in scripted mode");
6707
7259
  process.exit(1);
6708
7260
  }
6709
7261
  name = await input2({ message: "Legal name" });
@@ -6725,7 +7277,7 @@ async function phaseEntityDetails(opts, serverCfg, scripted) {
6725
7277
  }
6726
7278
  }
6727
7279
  if (!companyAddress && !scripted) {
6728
- const wantAddress = await confirm2({ message: "Add company address?", default: false });
7280
+ const wantAddress = await confirm6({ message: "Add company address?", default: false });
6729
7281
  if (wantAddress) {
6730
7282
  companyAddress = await promptAddress();
6731
7283
  }
@@ -6733,7 +7285,7 @@ async function phaseEntityDetails(opts, serverCfg, scripted) {
6733
7285
  const fiscalYearEnd = opts.fiscalYearEnd ?? "12-31";
6734
7286
  let sCorpElection = opts.sCorp ?? false;
6735
7287
  if (!scripted && isCorp(entityType) && opts.sCorp === void 0) {
6736
- sCorpElection = await confirm2({ message: "S-Corp election?", default: false });
7288
+ sCorpElection = await confirm6({ message: "S-Corp election?", default: false });
6737
7289
  }
6738
7290
  return { entityType, name, jurisdiction, companyAddress, fiscalYearEnd, sCorpElection };
6739
7291
  }
@@ -6744,13 +7296,13 @@ async function phasePeople(opts, entityType, scripted) {
6744
7296
  try {
6745
7297
  return parseScriptedFounders(opts);
6746
7298
  } catch (err) {
6747
- printError(String(err));
7299
+ printError2(String(err));
6748
7300
  process.exit(1);
6749
7301
  }
6750
7302
  }
6751
7303
  const founderCount = await number({ message: "Number of founders (1-6)", default: 1 }) ?? 1;
6752
7304
  for (let i = 0; i < founderCount; i++) {
6753
- console.log(chalk12.dim(`
7305
+ console.log(chalk13.dim(`
6754
7306
  Founder ${i + 1} of ${founderCount}:`));
6755
7307
  const name = await input2({ message: ` Name` });
6756
7308
  const email = await input2({ message: ` Email` });
@@ -6765,11 +7317,11 @@ async function phasePeople(opts, entityType, scripted) {
6765
7317
  ]
6766
7318
  });
6767
7319
  }
6768
- const wantAddress = await confirm2({ message: " Add address?", default: false });
7320
+ const wantAddress = await confirm6({ message: " Add address?", default: false });
6769
7321
  const address = wantAddress ? await promptAddress() : void 0;
6770
7322
  let officerTitle;
6771
7323
  if (isCorp(entityType)) {
6772
- const wantOfficer = role === "officer" || await confirm2({ message: " Assign officer title?", default: i === 0 });
7324
+ const wantOfficer = role === "officer" || await confirm6({ message: " Assign officer title?", default: i === 0 });
6773
7325
  if (wantOfficer) {
6774
7326
  officerTitle = await select2({
6775
7327
  message: " Officer title",
@@ -6784,7 +7336,7 @@ async function phasePeople(opts, entityType, scripted) {
6784
7336
  if (isCorp(entityType) && i === 0 && founderCount === 1) {
6785
7337
  isIncorporator = true;
6786
7338
  } else if (isCorp(entityType)) {
6787
- isIncorporator = await confirm2({ message: " Designate as sole incorporator?", default: i === 0 });
7339
+ isIncorporator = await confirm6({ message: " Designate as sole incorporator?", default: i === 0 });
6788
7340
  }
6789
7341
  founders.push({ name, email, role, address, officer_title: officerTitle, is_incorporator: isIncorporator });
6790
7342
  }
@@ -6792,11 +7344,11 @@ async function phasePeople(opts, entityType, scripted) {
6792
7344
  }
6793
7345
  async function phaseStock(opts, entityType, founders, scripted) {
6794
7346
  if (!scripted) sectionHeader("Phase 3: Equity & Finalize");
6795
- const transferRestrictions = opts.transferRestrictions ?? (!scripted && isCorp(entityType) ? await confirm2({ message: "Transfer restrictions on shares?", default: true }) : isCorp(entityType));
6796
- const rofr = opts.rofr ?? (!scripted && isCorp(entityType) ? await confirm2({ message: "Right of first refusal?", default: true }) : isCorp(entityType));
7347
+ const transferRestrictions = opts.transferRestrictions ?? (!scripted && isCorp(entityType) ? await confirm6({ message: "Transfer restrictions on shares?", default: true }) : isCorp(entityType));
7348
+ const rofr = opts.rofr ?? (!scripted && isCorp(entityType) ? await confirm6({ message: "Right of first refusal?", default: true }) : isCorp(entityType));
6797
7349
  if (!scripted) {
6798
7350
  for (const f of founders) {
6799
- console.log(chalk12.dim(`
7351
+ console.log(chalk13.dim(`
6800
7352
  Equity for ${f.name}:`));
6801
7353
  if (isCorp(entityType)) {
6802
7354
  const shares = await number({ message: ` Shares to purchase`, default: 0 });
@@ -6813,7 +7365,7 @@ async function phaseStock(opts, entityType, founders, scripted) {
6813
7365
  f.ownership_pct = pct ?? 0;
6814
7366
  }
6815
7367
  if (isCorp(entityType)) {
6816
- const wantVesting = await confirm2({ message: " Add vesting schedule?", default: false });
7368
+ const wantVesting = await confirm6({ message: " Add vesting schedule?", default: false });
6817
7369
  if (wantVesting) {
6818
7370
  const totalMonths = await number({ message: " Total vesting months", default: 48 }) ?? 48;
6819
7371
  const cliffMonths = await number({ message: " Cliff months", default: 12 }) ?? 12;
@@ -6832,7 +7384,7 @@ async function phaseStock(opts, entityType, founders, scripted) {
6832
7384
  };
6833
7385
  }
6834
7386
  }
6835
- const wantIp = await confirm2({ message: " Contributing IP?", default: false });
7387
+ const wantIp = await confirm6({ message: " Contributing IP?", default: false });
6836
7388
  if (wantIp) {
6837
7389
  f.ip_description = await input2({ message: " Describe IP being contributed" });
6838
7390
  }
@@ -6842,17 +7394,17 @@ async function phaseStock(opts, entityType, founders, scripted) {
6842
7394
  }
6843
7395
  function printSummary(entityType, name, jurisdiction, fiscalYearEnd, sCorpElection, founders, transferRestrictions, rofr) {
6844
7396
  sectionHeader("Formation Summary");
6845
- console.log(` ${chalk12.bold("Entity:")} ${name}`);
6846
- console.log(` ${chalk12.bold("Type:")} ${entityType}`);
6847
- console.log(` ${chalk12.bold("Jurisdiction:")} ${jurisdiction}`);
6848
- console.log(` ${chalk12.bold("Fiscal Year End:")} ${fiscalYearEnd}`);
7397
+ console.log(` ${chalk13.bold("Entity:")} ${name}`);
7398
+ console.log(` ${chalk13.bold("Type:")} ${entityType}`);
7399
+ console.log(` ${chalk13.bold("Jurisdiction:")} ${jurisdiction}`);
7400
+ console.log(` ${chalk13.bold("Fiscal Year End:")} ${fiscalYearEnd}`);
6849
7401
  if (isCorp(entityType)) {
6850
- console.log(` ${chalk12.bold("S-Corp Election:")} ${sCorpElection ? "Yes" : "No"}`);
6851
- console.log(` ${chalk12.bold("Transfer Restrictions:")} ${transferRestrictions ? "Yes" : "No"}`);
6852
- console.log(` ${chalk12.bold("Right of First Refusal:")} ${rofr ? "Yes" : "No"}`);
7402
+ console.log(` ${chalk13.bold("S-Corp Election:")} ${sCorpElection ? "Yes" : "No"}`);
7403
+ console.log(` ${chalk13.bold("Transfer Restrictions:")} ${transferRestrictions ? "Yes" : "No"}`);
7404
+ console.log(` ${chalk13.bold("Right of First Refusal:")} ${rofr ? "Yes" : "No"}`);
6853
7405
  }
6854
7406
  const table = new Table3({
6855
- head: [chalk12.dim("Name"), chalk12.dim("Email"), chalk12.dim("Role"), chalk12.dim("Equity"), chalk12.dim("Officer")]
7407
+ head: [chalk13.dim("Name"), chalk13.dim("Email"), chalk13.dim("Role"), chalk13.dim("Equity"), chalk13.dim("Officer")]
6856
7408
  });
6857
7409
  for (const f of founders) {
6858
7410
  const equity = f.shares_purchased ? `${f.shares_purchased.toLocaleString()} shares` : f.ownership_pct ? `${f.ownership_pct}%` : "\u2014";
@@ -6865,21 +7417,36 @@ async function formCommand(opts) {
6865
7417
  const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
6866
7418
  const resolver = new ReferenceResolver(client, cfg);
6867
7419
  try {
7420
+ if (opts.type && !SUPPORTED_ENTITY_TYPES.includes(opts.type)) {
7421
+ printError2(`Unsupported entity type '${opts.type}'. Supported types: ${SUPPORTED_ENTITY_TYPES.join(", ")}`);
7422
+ process.exit(1);
7423
+ }
7424
+ if (opts.name != null && !opts.name.trim()) {
7425
+ printError2("--name cannot be empty or whitespace");
7426
+ process.exit(1);
7427
+ }
6868
7428
  let serverCfg = {};
6869
7429
  try {
6870
7430
  serverCfg = await client.getConfig();
6871
7431
  } catch {
6872
7432
  }
6873
- const scripted = Boolean(
7433
+ const hasMembers = Boolean(
6874
7434
  opts.member && opts.member.length > 0 || opts.memberJson && opts.memberJson.length > 0 || opts.membersFile
6875
7435
  );
7436
+ const scripted = hasMembers || opts.json || opts.dryRun || !process.stdout.isTTY;
7437
+ if (scripted && !hasMembers) {
7438
+ printError2("At least one --member, --member-json, or --members-file is required in non-interactive mode.");
7439
+ process.exit(1);
7440
+ }
6876
7441
  const { entityType, name, jurisdiction, companyAddress, fiscalYearEnd, sCorpElection } = await phaseEntityDetails(opts, serverCfg, scripted);
6877
7442
  const founders = await phasePeople(opts, entityType, scripted);
6878
7443
  const { transferRestrictions, rofr } = await phaseStock(opts, entityType, founders, scripted);
6879
- printSummary(entityType, name, jurisdiction, fiscalYearEnd, sCorpElection, founders, transferRestrictions, rofr);
6880
- const shouldProceed = scripted ? true : await confirm2({ message: "Proceed with formation?", default: true });
7444
+ if (!opts.quiet) {
7445
+ printSummary(entityType, name, jurisdiction, fiscalYearEnd, sCorpElection, founders, transferRestrictions, rofr);
7446
+ }
7447
+ const shouldProceed = scripted ? true : await confirm6({ message: "Proceed with formation?", default: true });
6881
7448
  if (!shouldProceed) {
6882
- console.log(chalk12.yellow("Formation cancelled."));
7449
+ console.log(chalk13.yellow("Formation cancelled."));
6883
7450
  return;
6884
7451
  }
6885
7452
  const members = founders.map((f) => {
@@ -6917,6 +7484,16 @@ async function formCommand(opts) {
6917
7484
  const result = await client.createFormationWithCapTable(payload);
6918
7485
  await resolver.stabilizeRecord("entity", result);
6919
7486
  resolver.rememberFromRecord("entity", result);
7487
+ if (result.entity_id) {
7488
+ setActiveEntityId(cfg, String(result.entity_id));
7489
+ saveConfig(cfg);
7490
+ console.log(chalk13.dim(` Active entity set to ${result.entity_id}`));
7491
+ }
7492
+ if (opts.quiet) {
7493
+ const id = result.entity_id ?? result.formation_id;
7494
+ if (id) console.log(String(id));
7495
+ return;
7496
+ }
6920
7497
  if (opts.json) {
6921
7498
  printJson(result);
6922
7499
  return;
@@ -6935,22 +7512,32 @@ async function formCommand(opts) {
6935
7512
  if (holders.length > 0) {
6936
7513
  console.log();
6937
7514
  const table = new Table3({
6938
- head: [chalk12.dim("Holder"), chalk12.dim("Shares"), chalk12.dim("Ownership %")]
7515
+ head: [chalk13.dim("Holder"), chalk13.dim("Shares"), chalk13.dim("Ownership %")]
6939
7516
  });
6940
7517
  for (const h of holders) {
6941
7518
  const pct = typeof h.ownership_pct === "number" ? `${h.ownership_pct.toFixed(1)}%` : "\u2014";
6942
7519
  table.push([String(h.name ?? "?"), String(h.shares ?? 0), pct]);
6943
7520
  }
6944
- console.log(chalk12.bold(" Cap Table:"));
7521
+ console.log(chalk13.bold(" Cap Table:"));
6945
7522
  console.log(table.toString());
6946
7523
  }
6947
7524
  if (result.next_action) {
6948
- console.log(chalk12.yellow(`
7525
+ console.log(chalk13.yellow(`
6949
7526
  Next: ${result.next_action}`));
6950
7527
  }
6951
7528
  } catch (err) {
6952
7529
  if (err instanceof Error && err.message.includes("exit")) throw err;
6953
- printError(`Failed to create formation: ${err}`);
7530
+ const msg = String(err);
7531
+ if (msg.includes("officers_list") || msg.includes("officer")) {
7532
+ printError2(
7533
+ `Formation failed: ${msg}
7534
+ Hint: C-Corp directors need an officer_title. Use --member with officer_title field, e.g.:
7535
+ --member 'name=Alice,email=a@co.com,role=director,officer_title=ceo,pct=100'
7536
+ Or use --member-json with {"officer_title": "ceo"}`
7537
+ );
7538
+ } else {
7539
+ printError2(`Failed to create formation: ${err}`);
7540
+ }
6954
7541
  process.exit(1);
6955
7542
  }
6956
7543
  }
@@ -7006,6 +7593,15 @@ async function formCreateCommand(opts) {
7006
7593
  const result = await client.createPendingEntity(payload);
7007
7594
  await resolver.stabilizeRecord("entity", result);
7008
7595
  resolver.rememberFromRecord("entity", result);
7596
+ if (result.entity_id) {
7597
+ setActiveEntityId(cfg, String(result.entity_id));
7598
+ saveConfig(cfg);
7599
+ }
7600
+ if (opts.quiet) {
7601
+ const id = result.entity_id;
7602
+ if (id) console.log(String(id));
7603
+ return;
7604
+ }
7009
7605
  if (opts.json) {
7010
7606
  printJson(result);
7011
7607
  return;
@@ -7016,10 +7612,10 @@ async function formCreateCommand(opts) {
7016
7612
  console.log(` Type: ${result.entity_type}`);
7017
7613
  console.log(` Jurisdiction: ${result.jurisdiction}`);
7018
7614
  console.log(` Status: ${result.formation_status}`);
7019
- console.log(chalk12.yellow(`
7615
+ console.log(chalk13.yellow(`
7020
7616
  Next: corp form add-founder @last:entity --name "..." --email "..." --role member --pct 50`));
7021
7617
  } catch (err) {
7022
- printError(`Failed to create pending entity: ${err}`);
7618
+ printError2(`Failed to create pending entity: ${err}`);
7023
7619
  process.exit(1);
7024
7620
  }
7025
7621
  }
@@ -7054,10 +7650,10 @@ async function formAddFounderCommand(entityId, opts) {
7054
7650
  const pct = typeof m.ownership_pct === "number" ? ` (${m.ownership_pct}%)` : "";
7055
7651
  console.log(` - ${m.name} <${m.email ?? "no email"}> [${m.role ?? "member"}]${pct}`);
7056
7652
  }
7057
- console.log(chalk12.yellow(`
7653
+ console.log(chalk13.yellow(`
7058
7654
  Next: add more founders or run: corp form finalize @last:entity`));
7059
7655
  } catch (err) {
7060
- printError(`Failed to add founder: ${err}`);
7656
+ printError2(`Failed to add founder: ${err}`);
7061
7657
  process.exit(1);
7062
7658
  }
7063
7659
  }
@@ -7118,21 +7714,30 @@ async function formFinalizeCommand(entityId, opts) {
7118
7714
  if (holders.length > 0) {
7119
7715
  console.log();
7120
7716
  const table = new Table3({
7121
- head: [chalk12.dim("Holder"), chalk12.dim("Shares"), chalk12.dim("Ownership %")]
7717
+ head: [chalk13.dim("Holder"), chalk13.dim("Shares"), chalk13.dim("Ownership %")]
7122
7718
  });
7123
7719
  for (const h of holders) {
7124
7720
  const pct = typeof h.ownership_pct === "number" ? `${h.ownership_pct.toFixed(1)}%` : "\u2014";
7125
7721
  table.push([String(h.name ?? "?"), String(h.shares ?? 0), pct]);
7126
7722
  }
7127
- console.log(chalk12.bold(" Cap Table:"));
7723
+ console.log(chalk13.bold(" Cap Table:"));
7128
7724
  console.log(table.toString());
7129
7725
  }
7130
7726
  if (result.next_action) {
7131
- console.log(chalk12.yellow(`
7727
+ console.log(chalk13.yellow(`
7132
7728
  Next: ${result.next_action}`));
7133
7729
  }
7134
7730
  } catch (err) {
7135
- printError(`Failed to finalize formation: ${err}`);
7731
+ const msg = String(err);
7732
+ if (msg.includes("officers_list") || msg.includes("officer")) {
7733
+ printError2(
7734
+ `Finalization failed: ${msg}
7735
+ Hint: C-Corp entities require at least one founder with an officer_title.
7736
+ Add a founder with: corp form add-founder @last:entity --name '...' --email '...' --role director --pct 100 --officer-title ceo`
7737
+ );
7738
+ } else {
7739
+ printError2(`Failed to finalize formation: ${err}`);
7740
+ }
7136
7741
  process.exit(1);
7137
7742
  }
7138
7743
  }
@@ -7179,12 +7784,12 @@ async function formActivateCommand(entityId, opts) {
7179
7784
  }
7180
7785
  console.log(` Signatures added: ${result.signatures_added}`);
7181
7786
  console.log(` Documents updated: ${result.documents_signed}`);
7182
- printJson(formation);
7183
7787
  } catch (err) {
7184
- printError(`Failed to activate formation: ${err}`);
7788
+ printError2(`Failed to activate formation: ${err}`);
7185
7789
  process.exit(1);
7186
7790
  }
7187
7791
  }
7792
+ var SUPPORTED_ENTITY_TYPES;
7188
7793
  var init_form = __esm({
7189
7794
  "src/commands/form.ts"() {
7190
7795
  "use strict";
@@ -7193,49 +7798,94 @@ var init_form = __esm({
7193
7798
  init_output();
7194
7799
  init_references();
7195
7800
  init_formation_automation();
7801
+ SUPPORTED_ENTITY_TYPES = ["llc", "c_corp", "s_corp", "corporation"];
7196
7802
  }
7197
7803
  });
7198
7804
 
7199
7805
  // src/commands/api-keys.ts
7200
7806
  var api_keys_exports = {};
7201
7807
  __export(api_keys_exports, {
7202
- apiKeysCommand: () => apiKeysCommand
7808
+ apiKeysCreateCommand: () => apiKeysCreateCommand,
7809
+ apiKeysListCommand: () => apiKeysListCommand,
7810
+ apiKeysRevokeCommand: () => apiKeysRevokeCommand,
7811
+ apiKeysRotateCommand: () => apiKeysRotateCommand
7203
7812
  });
7204
- import chalk13 from "chalk";
7205
- import Table4 from "cli-table3";
7206
- async function apiKeysCommand(opts) {
7813
+ import { confirm as confirm7 } from "@inquirer/prompts";
7814
+ async function apiKeysListCommand(opts) {
7207
7815
  const cfg = requireConfig("api_url", "api_key", "workspace_id");
7208
7816
  const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
7209
7817
  try {
7210
7818
  const keys = await client.listApiKeys();
7211
7819
  if (opts.json) {
7212
- printJson(keys.map((k) => ({
7213
- ...k,
7214
- ...k.key != null ? { key: maskKey(String(k.key)) } : {},
7215
- ...k.api_key != null ? { api_key: maskKey(String(k.api_key)) } : {}
7216
- })));
7820
+ printJson(keys);
7217
7821
  return;
7218
7822
  }
7219
7823
  if (keys.length === 0) {
7220
7824
  console.log("No API keys found.");
7221
7825
  return;
7222
7826
  }
7223
- console.log(`
7224
- ${chalk13.bold("API Keys")}`);
7225
- const table = new Table4({
7226
- head: [chalk13.dim("ID"), chalk13.dim("Name"), chalk13.dim("Key"), chalk13.dim("Created")]
7227
- });
7228
7827
  for (const k of keys) {
7229
- table.push([
7230
- String(k.key_id ?? k.id ?? k.api_key_id ?? "").slice(0, 12),
7231
- String(k.name ?? ""),
7232
- maskKey(String(k.key ?? k.api_key ?? "")),
7233
- String(k.created_at ?? "")
7234
- ]);
7828
+ const name = k.name ?? k.label ?? "unnamed";
7829
+ const id = k.key_id ?? k.id;
7830
+ const scopes = Array.isArray(k.scopes) ? k.scopes.join(", ") : "all";
7831
+ console.log(` ${name} [${id}] scopes: ${scopes}`);
7235
7832
  }
7236
- console.log(table.toString());
7237
7833
  } catch (err) {
7238
- printError(`Failed to fetch API keys: ${err}`);
7834
+ printError2(`Failed to list API keys: ${err}`);
7835
+ process.exit(1);
7836
+ }
7837
+ }
7838
+ async function apiKeysCreateCommand(opts) {
7839
+ const cfg = requireConfig("api_url", "api_key", "workspace_id");
7840
+ const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
7841
+ try {
7842
+ const data = { name: opts.name };
7843
+ if (opts.scopes) data.scopes = opts.scopes.split(",").map((s2) => s2.trim());
7844
+ const result = await client.createApiKey(data);
7845
+ printWriteResult(result, `API key created: ${result.key_id ?? "OK"}`, opts.json);
7846
+ if (!opts.json && result.api_key) {
7847
+ printSuccess(`Key: ${result.api_key}`);
7848
+ console.log(" Save this key \u2014 it will not be shown again.");
7849
+ }
7850
+ } catch (err) {
7851
+ printError2(`Failed to create API key: ${err}`);
7852
+ process.exit(1);
7853
+ }
7854
+ }
7855
+ async function apiKeysRevokeCommand(keyId, opts) {
7856
+ const cfg = requireConfig("api_url", "api_key", "workspace_id");
7857
+ const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
7858
+ try {
7859
+ if (!opts.yes) {
7860
+ const ok = await confirm7({ message: `Revoke API key ${keyId}? This cannot be undone.`, default: false });
7861
+ if (!ok) {
7862
+ console.log("Cancelled.");
7863
+ return;
7864
+ }
7865
+ }
7866
+ await client.revokeApiKey(keyId);
7867
+ if (opts.json) {
7868
+ printJson({ revoked: true, key_id: keyId });
7869
+ return;
7870
+ }
7871
+ printSuccess(`API key ${keyId} revoked.`);
7872
+ } catch (err) {
7873
+ printError2(`Failed to revoke API key: ${err}`);
7874
+ process.exit(1);
7875
+ }
7876
+ }
7877
+ async function apiKeysRotateCommand(keyId, opts) {
7878
+ const cfg = requireConfig("api_url", "api_key", "workspace_id");
7879
+ const client = new CorpAPIClient(cfg.api_url, cfg.api_key, cfg.workspace_id);
7880
+ try {
7881
+ const result = await client.rotateApiKey(keyId);
7882
+ printWriteResult(result, `API key ${keyId} rotated.`, opts.json);
7883
+ if (!opts.json && result.api_key) {
7884
+ printSuccess(`New key: ${result.api_key}`);
7885
+ console.log(" Save this key \u2014 it will not be shown again.");
7886
+ }
7887
+ } catch (err) {
7888
+ printError2(`Failed to rotate API key: ${err}`);
7239
7889
  process.exit(1);
7240
7890
  }
7241
7891
  }
@@ -7266,14 +7916,26 @@ function scenarioConfig(name, scenario) {
7266
7916
  email: "alice@example.com",
7267
7917
  role: "member",
7268
7918
  investor_type: "natural_person",
7269
- ownership_pct: 60
7919
+ ownership_pct: 60,
7920
+ address: {
7921
+ street: "251 Little Falls Dr",
7922
+ city: "Wilmington",
7923
+ state: "DE",
7924
+ zip: "19808"
7925
+ }
7270
7926
  },
7271
7927
  {
7272
7928
  name: "Bob Martinez",
7273
7929
  email: "bob@example.com",
7274
7930
  role: "member",
7275
7931
  investor_type: "natural_person",
7276
- ownership_pct: 40
7932
+ ownership_pct: 40,
7933
+ address: {
7934
+ street: "251 Little Falls Dr",
7935
+ city: "Wilmington",
7936
+ state: "DE",
7937
+ zip: "19808"
7938
+ }
7277
7939
  }
7278
7940
  ],
7279
7941
  fiscal_year_end: "12-31",
@@ -7295,14 +7957,26 @@ function scenarioConfig(name, scenario) {
7295
7957
  email: "rosa@example.com",
7296
7958
  role: "manager",
7297
7959
  investor_type: "natural_person",
7298
- ownership_pct: 55
7960
+ ownership_pct: 55,
7961
+ address: {
7962
+ street: "18 Market St",
7963
+ city: "Wilmington",
7964
+ state: "DE",
7965
+ zip: "19801"
7966
+ }
7299
7967
  },
7300
7968
  {
7301
7969
  name: "Noah Patel",
7302
7970
  email: "noah@example.com",
7303
7971
  role: "member",
7304
7972
  investor_type: "natural_person",
7305
- ownership_pct: 45
7973
+ ownership_pct: 45,
7974
+ address: {
7975
+ street: "18 Market St",
7976
+ city: "Wilmington",
7977
+ state: "DE",
7978
+ zip: "19801"
7979
+ }
7306
7980
  }
7307
7981
  ],
7308
7982
  fiscal_year_end: "12-31",
@@ -7331,7 +8005,13 @@ function scenarioConfig(name, scenario) {
7331
8005
  investor_type: "natural_person",
7332
8006
  shares_purchased: 6e6,
7333
8007
  officer_title: "ceo",
7334
- is_incorporator: true
8008
+ is_incorporator: true,
8009
+ address: {
8010
+ street: "251 Little Falls Dr",
8011
+ city: "Wilmington",
8012
+ state: "DE",
8013
+ zip: "19808"
8014
+ }
7335
8015
  },
7336
8016
  {
7337
8017
  name: "Bob Martinez",
@@ -7339,7 +8019,13 @@ function scenarioConfig(name, scenario) {
7339
8019
  role: "director",
7340
8020
  investor_type: "natural_person",
7341
8021
  shares_purchased: 4e6,
7342
- officer_title: "cto"
8022
+ officer_title: "cto",
8023
+ address: {
8024
+ street: "251 Little Falls Dr",
8025
+ city: "Wilmington",
8026
+ state: "DE",
8027
+ zip: "19808"
8028
+ }
7343
8029
  }
7344
8030
  ],
7345
8031
  fiscal_year_end: "12-31",
@@ -7484,7 +8170,7 @@ async function demoCommand(opts) {
7484
8170
  printReferenceSummary("bank_account", bankAccount, { showReuseHint: true });
7485
8171
  printJson(result);
7486
8172
  } catch (err) {
7487
- printError(`Failed to seed demo: ${err}`);
8173
+ printError2(`Failed to seed demo: ${err}`);
7488
8174
  process.exit(1);
7489
8175
  }
7490
8176
  }
@@ -7508,11 +8194,11 @@ __export(feedback_exports, {
7508
8194
  import chalk14 from "chalk";
7509
8195
  async function feedbackCommand(message, opts) {
7510
8196
  if (!message || message.trim().length === 0) {
7511
- printError("Feedback message cannot be empty");
8197
+ printError2("Feedback message cannot be empty");
7512
8198
  process.exit(1);
7513
8199
  }
7514
8200
  if (message.length > MAX_FEEDBACK_LENGTH) {
7515
- printError(`Feedback message must be at most ${MAX_FEEDBACK_LENGTH} characters (got ${message.length})`);
8201
+ printError2(`Feedback message must be at most ${MAX_FEEDBACK_LENGTH} characters (got ${message.length})`);
7516
8202
  process.exit(1);
7517
8203
  }
7518
8204
  const cfg = requireConfig("api_url", "api_key", "workspace_id");
@@ -7528,12 +8214,12 @@ ${chalk14.green("\u2713")} Feedback submitted (${chalk14.dim(result.feedback_id)
7528
8214
  } catch (err) {
7529
8215
  const detail = String(err);
7530
8216
  if (detail.includes("404")) {
7531
- printError(
8217
+ printError2(
7532
8218
  `Failed to submit feedback: ${detail}
7533
8219
  This server does not expose /v1/feedback. Local api-rs dev servers currently do not support feedback submission.`
7534
8220
  );
7535
8221
  } else {
7536
- printError(`Failed to submit feedback: ${detail}`);
8222
+ printError2(`Failed to submit feedback: ${detail}`);
7537
8223
  }
7538
8224
  process.exit(1);
7539
8225
  }
@@ -7618,24 +8304,30 @@ function inheritOption(localValue, parentValue) {
7618
8304
  // src/index.ts
7619
8305
  var require2 = createRequire(import.meta.url);
7620
8306
  var pkg = require2("../package.json");
7621
- var TAX_DOCUMENT_TYPE_CHOICES = [
8307
+ var TAX_DOCUMENT_TYPE_DISPLAY = [
7622
8308
  "1120",
7623
8309
  "1120s",
7624
8310
  "1065",
7625
8311
  "franchise_tax",
7626
8312
  "annual_report",
7627
8313
  "83b",
7628
- "form_1120",
7629
- "form_1120s",
7630
- "form_1065",
7631
8314
  "1099_nec",
7632
- "form_1099_nec",
7633
8315
  "k1",
7634
- "form_k1",
7635
8316
  "941",
7636
- "form_941",
7637
- "w2",
7638
- "form_w2"
8317
+ "w2"
8318
+ ];
8319
+ var TAX_DOCUMENT_TYPE_ALIASES = {
8320
+ form_1120: "1120",
8321
+ form_1120s: "1120s",
8322
+ form_1065: "1065",
8323
+ form_1099_nec: "1099_nec",
8324
+ form_k1: "k1",
8325
+ form_941: "941",
8326
+ form_w2: "w2"
8327
+ };
8328
+ var TAX_DOCUMENT_TYPE_CHOICES = [
8329
+ ...TAX_DOCUMENT_TYPE_DISPLAY,
8330
+ ...Object.keys(TAX_DOCUMENT_TYPE_ALIASES)
7639
8331
  ];
7640
8332
  var FINALIZE_ITEM_STATUS_CHOICES = [
7641
8333
  "discussed",
@@ -7644,7 +8336,11 @@ var FINALIZE_ITEM_STATUS_CHOICES = [
7644
8336
  "withdrawn"
7645
8337
  ];
7646
8338
  var program = new Command();
7647
- program.name("corp").description("corp \u2014 Corporate governance from the terminal").version(pkg.version);
8339
+ program.name("corp").description("corp \u2014 Corporate governance from the terminal").version(pkg.version).enablePositionalOptions();
8340
+ program.option("-q, --quiet", "Only output the resource ID (for scripting)");
8341
+ program.action(() => {
8342
+ program.outputHelp();
8343
+ });
7648
8344
  program.command("setup").description("Interactive setup wizard").action(async () => {
7649
8345
  const { setupCommand: setupCommand2 } = await Promise.resolve().then(() => (init_setup(), setup_exports));
7650
8346
  await setupCommand2();
@@ -7657,6 +8353,10 @@ program.command("context").alias("whoami").description("Show the active workspac
7657
8353
  const { contextCommand: contextCommand2 } = await Promise.resolve().then(() => (init_context(), context_exports));
7658
8354
  await contextCommand2(opts);
7659
8355
  });
8356
+ program.command("use <entity-ref>").description("Set the active entity by name, short ID, or reference").action(async (entityRef) => {
8357
+ const { useCommand: useCommand2 } = await Promise.resolve().then(() => (init_use(), use_exports));
8358
+ await useCommand2(entityRef);
8359
+ });
7660
8360
  program.command("schema").description("Dump the CLI command catalog as JSON").option("--compact", "Emit compact JSON").action(async (opts) => {
7661
8361
  const { schemaCommand: schemaCommand2 } = await Promise.resolve().then(() => (init_schema(), schema_exports));
7662
8362
  schemaCommand2(program, opts);
@@ -7686,7 +8386,7 @@ program.command("obligations").description("List obligations with urgency tiers"
7686
8386
  const { obligationsCommand: obligationsCommand2 } = await Promise.resolve().then(() => (init_obligations(), obligations_exports));
7687
8387
  await obligationsCommand2(opts);
7688
8388
  });
7689
- program.command("digest").description("View or trigger daily digests").option("--trigger", "Trigger digest now").option("--key <key>", "Get specific digest by key").option("--json", "Output as JSON").action(async (opts) => {
8389
+ program.command("digest").description("View or trigger daily digests").option("--trigger", "Trigger digest now").option("--key <key>", "Get specific digest by key").option("--entity-id <ref>", "Entity reference (ID, short ID, @last, or unique name)").option("--json", "Output as JSON").action(async (opts) => {
7690
8390
  const { digestCommand: digestCommand2 } = await Promise.resolve().then(() => (init_digest(), digest_exports));
7691
8391
  await digestCommand2(opts);
7692
8392
  });
@@ -7718,7 +8418,7 @@ entitiesCmd.command("convert <entity-ref>").requiredOption("--to <type>", "Targe
7718
8418
  const { entitiesConvertCommand: entitiesConvertCommand2 } = await Promise.resolve().then(() => (init_entities(), entities_exports));
7719
8419
  await entitiesConvertCommand2(entityId, opts);
7720
8420
  });
7721
- entitiesCmd.command("dissolve <entity-ref>").requiredOption("--reason <reason>", "Dissolution reason").option("--effective-date <date>", "Effective date (ISO 8601)").description("Dissolve an entity").action(async (entityId, opts) => {
8421
+ entitiesCmd.command("dissolve <entity-ref>").requiredOption("--reason <reason>", "Dissolution reason").option("--effective-date <date>", "Effective date (ISO 8601)").option("--yes, -y", "Skip confirmation prompt").description("Dissolve an entity").action(async (entityId, opts) => {
7722
8422
  const { entitiesDissolveCommand: entitiesDissolveCommand2 } = await Promise.resolve().then(() => (init_entities(), entities_exports));
7723
8423
  await entitiesDissolveCommand2(entityId, opts);
7724
8424
  });
@@ -7757,40 +8457,61 @@ var capTableCmd = program.command("cap-table").description("Cap table, equity gr
7757
8457
  const { capTableCommand: capTableCommand2 } = await Promise.resolve().then(() => (init_cap_table(), cap_table_exports));
7758
8458
  await capTableCommand2(opts);
7759
8459
  });
7760
- capTableCmd.command("safes").description("SAFE notes").action(async (_opts, cmd) => {
8460
+ capTableCmd.command("safes").option("--entity-id <ref>", "Entity reference").option("--json", "Output as JSON").description("SAFE notes").action(async (opts, cmd) => {
7761
8461
  const parent = cmd.parent.opts();
7762
8462
  const { safesCommand: safesCommand2 } = await Promise.resolve().then(() => (init_cap_table(), cap_table_exports));
7763
- await safesCommand2(parent);
8463
+ await safesCommand2({
8464
+ entityId: opts.entityId ?? parent.entityId,
8465
+ json: inheritOption(opts.json, parent.json)
8466
+ });
7764
8467
  });
7765
- capTableCmd.command("transfers").description("Share transfers").action(async (_opts, cmd) => {
8468
+ capTableCmd.command("transfers").option("--entity-id <ref>", "Entity reference").option("--json", "Output as JSON").description("Share transfers").action(async (opts, cmd) => {
7766
8469
  const parent = cmd.parent.opts();
7767
8470
  const { transfersCommand: transfersCommand2 } = await Promise.resolve().then(() => (init_cap_table(), cap_table_exports));
7768
- await transfersCommand2(parent);
8471
+ await transfersCommand2({
8472
+ entityId: opts.entityId ?? parent.entityId,
8473
+ json: inheritOption(opts.json, parent.json)
8474
+ });
7769
8475
  });
7770
- capTableCmd.command("instruments").description("Cap table instruments").action(async (_opts, cmd) => {
8476
+ capTableCmd.command("instruments").option("--entity-id <ref>", "Entity reference").option("--json", "Output as JSON").description("Cap table instruments").action(async (opts, cmd) => {
7771
8477
  const parent = cmd.parent.opts();
7772
8478
  const { instrumentsCommand: instrumentsCommand2 } = await Promise.resolve().then(() => (init_cap_table(), cap_table_exports));
7773
- await instrumentsCommand2(parent);
8479
+ await instrumentsCommand2({
8480
+ entityId: opts.entityId ?? parent.entityId,
8481
+ json: inheritOption(opts.json, parent.json)
8482
+ });
7774
8483
  });
7775
- capTableCmd.command("share-classes").description("Share classes").action(async (_opts, cmd) => {
8484
+ capTableCmd.command("share-classes").option("--entity-id <ref>", "Entity reference").option("--json", "Output as JSON").description("Share classes").action(async (opts, cmd) => {
7776
8485
  const parent = cmd.parent.opts();
7777
8486
  const { shareClassesCommand: shareClassesCommand2 } = await Promise.resolve().then(() => (init_cap_table(), cap_table_exports));
7778
- await shareClassesCommand2(parent);
8487
+ await shareClassesCommand2({
8488
+ entityId: opts.entityId ?? parent.entityId,
8489
+ json: inheritOption(opts.json, parent.json)
8490
+ });
7779
8491
  });
7780
- capTableCmd.command("rounds").description("Staged equity rounds").action(async (_opts, cmd) => {
8492
+ capTableCmd.command("rounds").option("--entity-id <ref>", "Entity reference").option("--json", "Output as JSON").description("Staged equity rounds").action(async (opts, cmd) => {
7781
8493
  const parent = cmd.parent.opts();
7782
8494
  const { roundsCommand: roundsCommand2 } = await Promise.resolve().then(() => (init_cap_table(), cap_table_exports));
7783
- await roundsCommand2(parent);
8495
+ await roundsCommand2({
8496
+ entityId: opts.entityId ?? parent.entityId,
8497
+ json: inheritOption(opts.json, parent.json)
8498
+ });
7784
8499
  });
7785
- capTableCmd.command("valuations").description("Valuations history").action(async (_opts, cmd) => {
8500
+ capTableCmd.command("valuations").option("--entity-id <ref>", "Entity reference").option("--json", "Output as JSON").description("Valuations history").action(async (opts, cmd) => {
7786
8501
  const parent = cmd.parent.opts();
7787
8502
  const { valuationsCommand: valuationsCommand2 } = await Promise.resolve().then(() => (init_cap_table(), cap_table_exports));
7788
- await valuationsCommand2(parent);
8503
+ await valuationsCommand2({
8504
+ entityId: opts.entityId ?? parent.entityId,
8505
+ json: inheritOption(opts.json, parent.json)
8506
+ });
7789
8507
  });
7790
- capTableCmd.command("409a").description("Current 409A valuation").action(async (_opts, cmd) => {
8508
+ capTableCmd.command("409a").option("--entity-id <ref>", "Entity reference").option("--json", "Output as JSON").description("Current 409A valuation").action(async (opts, cmd) => {
7791
8509
  const parent = cmd.parent.opts();
7792
8510
  const { fourOhNineACommand: fourOhNineACommand2 } = await Promise.resolve().then(() => (init_cap_table(), cap_table_exports));
7793
- await fourOhNineACommand2(parent);
8511
+ await fourOhNineACommand2({
8512
+ entityId: opts.entityId ?? parent.entityId,
8513
+ json: inheritOption(opts.json, parent.json)
8514
+ });
7794
8515
  });
7795
8516
  capTableCmd.command("create-instrument").requiredOption("--kind <kind>", "Instrument kind (common_equity, preferred_equity, membership_unit, option_grant, safe)").requiredOption("--symbol <symbol>", "Instrument symbol").option("--issuer-legal-entity-id <ref>", "Issuer legal entity reference (ID, short ID, @last, or unique name)").option("--authorized-units <n>", "Authorized units", parseInt).option("--issue-price-cents <n>", "Issue price in cents", parseInt).option("--terms-json <json>", "JSON object of instrument terms").option("--json", "Output as JSON").option("--dry-run", "Show the request without creating the instrument").description("Create a cap table instrument").action(async (opts, cmd) => {
7796
8517
  const parent = cmd.parent.opts();
@@ -7810,11 +8531,13 @@ capTableCmd.command("issue-equity").requiredOption("--grant-type <type>", "Grant
7810
8531
  json: inheritOption(opts.json, parent.json)
7811
8532
  });
7812
8533
  });
7813
- 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).option("--meeting-id <ref>", "Board meeting reference required when issuing under a board-governed entity").option("--resolution-id <ref>", "Board resolution reference required when issuing under a board-governed entity").option("--json", "Output as JSON").option("--dry-run", "Show the request without creating the round").description("Issue a SAFE note").action(async (opts, cmd) => {
8534
+ capTableCmd.command("issue-safe").requiredOption("--investor <name>", "Investor name").requiredOption("--amount-cents <n>", "Principal amount in cents (e.g. 5000000000 = $50M)", parseInt).option("--amount <n>", "", parseInt).option("--safe-type <type>", "SAFE type", "post_money").requiredOption("--valuation-cap-cents <n>", "Valuation cap in cents (e.g. 1000000000 = $10M)", parseInt).option("--valuation-cap <n>", "", parseInt).option("--meeting-id <ref>", "Board meeting reference required when issuing under a board-governed entity").option("--resolution-id <ref>", "Board resolution reference required when issuing under a board-governed entity").option("--json", "Output as JSON").option("--dry-run", "Show the request without creating the round").description("Issue a SAFE note").action(async (opts, cmd) => {
7814
8535
  const parent = cmd.parent.opts();
7815
8536
  const { issueSafeCommand: issueSafeCommand2 } = await Promise.resolve().then(() => (init_cap_table(), cap_table_exports));
7816
8537
  await issueSafeCommand2({
7817
8538
  ...opts,
8539
+ amountCents: opts.amountCents ?? opts.amount,
8540
+ valuationCapCents: opts.valuationCapCents ?? opts.valuationCap,
7818
8541
  entityId: parent.entityId,
7819
8542
  json: inheritOption(opts.json, parent.json)
7820
8543
  });
@@ -7828,11 +8551,12 @@ capTableCmd.command("transfer").requiredOption("--from <ref>", "Source contact r
7828
8551
  json: inheritOption(opts.json, parent.json)
7829
8552
  });
7830
8553
  });
7831
- capTableCmd.command("distribute").requiredOption("--amount <n>", "Total distribution amount in cents", parseInt).option("--type <type>", "Distribution type (dividend, return, liquidation)", "dividend").requiredOption("--description <desc>", "Distribution description").option("--json", "Output as JSON").option("--dry-run", "Show the request without calculating the distribution").description("Calculate a distribution").action(async (opts, cmd) => {
8554
+ capTableCmd.command("distribute").requiredOption("--amount-cents <n>", "Total distribution amount in cents (e.g. 100000 = $1,000.00)", parseInt).option("--amount <n>", "", parseInt).option("--type <type>", "Distribution type (dividend, return, liquidation)", "dividend").requiredOption("--description <desc>", "Distribution description").option("--json", "Output as JSON").option("--dry-run", "Show the request without calculating the distribution").description("Calculate a distribution").action(async (opts, cmd) => {
7832
8555
  const parent = cmd.parent.opts();
7833
8556
  const { distributeCommand: distributeCommand2 } = await Promise.resolve().then(() => (init_cap_table(), cap_table_exports));
7834
8557
  await distributeCommand2({
7835
8558
  ...opts,
8559
+ amountCents: opts.amountCents ?? opts.amount,
7836
8560
  entityId: parent.entityId,
7837
8561
  json: inheritOption(opts.json, parent.json)
7838
8562
  });
@@ -7893,6 +8617,50 @@ capTableCmd.command("approve-valuation <valuation-ref>").option("--resolution-id
7893
8617
  json: inheritOption(opts.json, parent.json)
7894
8618
  });
7895
8619
  });
8620
+ capTableCmd.command("preview-conversion").requiredOption("--safe-id <ref>", "SAFE note reference to convert").requiredOption("--price-per-share-cents <n>", "Conversion price per share in cents", parseInt).option("--json", "Output as JSON").description("Preview SAFE-to-equity conversion").action(async (opts, cmd) => {
8621
+ const parent = cmd.parent.opts();
8622
+ const { previewConversionCommand: previewConversionCommand2 } = await Promise.resolve().then(() => (init_cap_table(), cap_table_exports));
8623
+ await previewConversionCommand2({
8624
+ ...opts,
8625
+ entityId: parent.entityId,
8626
+ json: inheritOption(opts.json, parent.json)
8627
+ });
8628
+ });
8629
+ capTableCmd.command("convert").requiredOption("--safe-id <ref>", "SAFE note reference to convert").requiredOption("--price-per-share-cents <n>", "Conversion price per share in cents", parseInt).option("--json", "Output as JSON").option("--dry-run", "Show the request without executing").description("Execute SAFE-to-equity conversion").action(async (opts, cmd) => {
8630
+ const parent = cmd.parent.opts();
8631
+ const { executeConversionCommand: executeConversionCommand2 } = await Promise.resolve().then(() => (init_cap_table(), cap_table_exports));
8632
+ await executeConversionCommand2({
8633
+ ...opts,
8634
+ entityId: parent.entityId,
8635
+ json: inheritOption(opts.json, parent.json)
8636
+ });
8637
+ });
8638
+ capTableCmd.command("dilution").requiredOption("--round-id <ref>", "Round reference to model dilution for").option("--json", "Output as JSON").description("Preview dilution impact of a round").action(async (opts, cmd) => {
8639
+ const parent = cmd.parent.opts();
8640
+ const { dilutionPreviewCommand: dilutionPreviewCommand2 } = await Promise.resolve().then(() => (init_cap_table(), cap_table_exports));
8641
+ await dilutionPreviewCommand2({
8642
+ ...opts,
8643
+ entityId: parent.entityId,
8644
+ json: inheritOption(opts.json, parent.json)
8645
+ });
8646
+ });
8647
+ capTableCmd.command("control-map").option("--root-entity-id <ref>", "Root entity for ownership tree (defaults to active entity)").option("--json", "Output as JSON").description("View entity control/ownership map").action(async (opts, cmd) => {
8648
+ const parent = cmd.parent.opts();
8649
+ const { controlMapCommand: controlMapCommand2 } = await Promise.resolve().then(() => (init_cap_table(), cap_table_exports));
8650
+ await controlMapCommand2({
8651
+ ...opts,
8652
+ entityId: parent.entityId,
8653
+ json: inheritOption(opts.json, parent.json)
8654
+ });
8655
+ });
8656
+ capTableCmd.addHelpText("after", `
8657
+ Examples:
8658
+ $ corp cap-table # view full cap table
8659
+ $ corp cap-table issue-equity --grant-type common --shares 1000000 --recipient "Alice Smith"
8660
+ $ corp cap-table issue-safe --investor "Seed Fund" --amount-cents 50000000 --valuation-cap-cents 1000000000
8661
+ $ corp cap-table create-valuation --type four_oh_nine_a --date 2026-01-01 --methodology market
8662
+ $ corp cap-table transfer --from alice --to bob --shares 1000 --share-class-id COMMON --governing-doc-type bylaws --transferee-rights full_member
8663
+ `);
7896
8664
  var financeCmd = program.command("finance").description("Invoicing, payroll, payments, banking").option("--entity-id <ref>", "Entity reference (ID, short ID, @last, or unique name)").option("--json", "Output as JSON").action(async (opts) => {
7897
8665
  const { financeSummaryCommand: financeSummaryCommand2 } = await Promise.resolve().then(() => (init_finance(), finance_exports));
7898
8666
  await financeSummaryCommand2(opts);
@@ -7906,11 +8674,17 @@ financeCmd.command("invoices").option("--json", "Output as JSON").description("L
7906
8674
  json: inheritOption(opts.json, parent.json)
7907
8675
  });
7908
8676
  });
7909
- 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").option("--json", "Output as JSON").description("Create an invoice").action(async (opts, cmd) => {
8677
+ financeCmd.command("invoice").requiredOption("--customer <name>", "Customer name").option("--amount-cents <n>", "Amount in cents (e.g. 500000 = $5,000.00)", parseInt).option("--amount <n>", "Amount in dollars (converted to cents)", parseInt).requiredOption("--due-date <date>", "Due date (ISO 8601)").option("--description <desc>", "Description", "Services rendered").option("--json", "Output as JSON").description("Create an invoice").action(async (opts, cmd) => {
7910
8678
  const parent = cmd.parent.opts();
8679
+ const amountCents = opts.amountCents ?? (opts.amount != null ? opts.amount * 100 : void 0);
8680
+ if (amountCents == null) {
8681
+ cmd.error("required option '--amount-cents <n>' or '--amount <n>' not specified");
8682
+ return;
8683
+ }
7911
8684
  const { financeInvoiceCommand: financeInvoiceCommand2 } = await Promise.resolve().then(() => (init_finance(), finance_exports));
7912
8685
  await financeInvoiceCommand2({
7913
8686
  ...opts,
8687
+ amountCents,
7914
8688
  entityId: parent.entityId,
7915
8689
  json: inheritOption(opts.json, parent.json)
7916
8690
  });
@@ -7942,11 +8716,17 @@ financeCmd.command("payments").option("--json", "Output as JSON").description("L
7942
8716
  json: inheritOption(opts.json, parent.json)
7943
8717
  });
7944
8718
  });
7945
- financeCmd.command("pay").requiredOption("--amount <n>", "Amount in cents", parseInt).requiredOption("--recipient <name>", "Recipient name").option("--method <method>", "Payment method", "ach").option("--json", "Output as JSON").description("Submit a payment").action(async (opts, cmd) => {
8719
+ financeCmd.command("pay").option("--amount-cents <n>", "Amount in cents (e.g. 500000 = $5,000.00)", parseInt).option("--amount <n>", "Amount in dollars (converted to cents)", parseInt).requiredOption("--recipient <name>", "Recipient name").option("--method <method>", "Payment method", "ach").option("--json", "Output as JSON").description("Submit a payment").action(async (opts, cmd) => {
7946
8720
  const parent = cmd.parent.opts();
8721
+ const amountCents = opts.amountCents ?? (opts.amount != null ? opts.amount * 100 : void 0);
8722
+ if (amountCents == null) {
8723
+ cmd.error("required option '--amount-cents <n>' or '--amount <n>' not specified");
8724
+ return;
8725
+ }
7947
8726
  const { financePayCommand: financePayCommand2 } = await Promise.resolve().then(() => (init_finance(), finance_exports));
7948
8727
  await financePayCommand2({
7949
8728
  ...opts,
8729
+ amountCents,
7950
8730
  entityId: parent.entityId,
7951
8731
  json: inheritOption(opts.json, parent.json)
7952
8732
  });
@@ -7969,6 +8749,15 @@ financeCmd.command("open-account").option("--institution <name>", "Banking insti
7969
8749
  json: inheritOption(opts.json, parent.json)
7970
8750
  });
7971
8751
  });
8752
+ financeCmd.command("activate-account <account-ref>").option("--json", "Output as JSON").description("Activate a bank account (transitions from pending_review to active)").action(async (accountRef, opts, cmd) => {
8753
+ const parent = cmd.parent.opts();
8754
+ const { financeActivateAccountCommand: financeActivateAccountCommand2 } = await Promise.resolve().then(() => (init_finance(), finance_exports));
8755
+ await financeActivateAccountCommand2(accountRef, {
8756
+ ...opts,
8757
+ entityId: parent.entityId,
8758
+ json: inheritOption(opts.json, parent.json)
8759
+ });
8760
+ });
7972
8761
  financeCmd.command("classifications").option("--json", "Output as JSON").description("List contractor classifications").action(async (opts, cmd) => {
7973
8762
  const parent = cmd.parent.opts();
7974
8763
  const { financeClassificationsCommand: financeClassificationsCommand2 } = await Promise.resolve().then(() => (init_finance(), finance_exports));
@@ -7996,7 +8785,7 @@ financeCmd.command("reconciliations").option("--json", "Output as JSON").descrip
7996
8785
  json: inheritOption(opts.json, parent.json)
7997
8786
  });
7998
8787
  });
7999
- financeCmd.command("reconcile").requiredOption("--start-date <date>", "Period start").requiredOption("--end-date <date>", "Period end").option("--json", "Output as JSON").description("Reconcile ledger").action(async (opts, cmd) => {
8788
+ financeCmd.command("reconcile").requiredOption("--start-date <date>", "Period start (required, ISO 8601)").requiredOption("--end-date <date>", "Period end (required, ISO 8601)").option("--json", "Output as JSON").description("Reconcile ledger (requires --start-date and --end-date)").action(async (opts, cmd) => {
8000
8789
  const parent = cmd.parent.opts();
8001
8790
  const { financeReconcileCommand: financeReconcileCommand2 } = await Promise.resolve().then(() => (init_finance(), finance_exports));
8002
8791
  await financeReconcileCommand2({
@@ -8014,6 +8803,24 @@ financeCmd.command("distributions").option("--json", "Output as JSON").descripti
8014
8803
  json: inheritOption(opts.json, parent.json)
8015
8804
  });
8016
8805
  });
8806
+ financeCmd.command("statements").option("--period <period>", "Period (e.g. 2026-Q1, 2025)").option("--json", "Output as JSON").description("View financial statements (P&L, balance sheet)").action(async (opts, cmd) => {
8807
+ const parent = cmd.parent.opts();
8808
+ const { financeStatementsCommand: financeStatementsCommand2 } = await Promise.resolve().then(() => (init_finance(), finance_exports));
8809
+ await financeStatementsCommand2({
8810
+ ...opts,
8811
+ entityId: parent.entityId,
8812
+ json: inheritOption(opts.json, parent.json)
8813
+ });
8814
+ });
8815
+ financeCmd.addHelpText("after", `
8816
+ Examples:
8817
+ $ corp finance # financial summary
8818
+ $ corp finance invoice --customer "Client Co" --amount-cents 500000 --due-date 2026-04-01
8819
+ $ corp finance pay --amount-cents 250000 --recipient "Vendor" --method ach
8820
+ $ corp finance payroll --period-start 2026-03-01 --period-end 2026-03-15
8821
+ $ corp finance open-account --institution Mercury
8822
+ $ corp finance statements --period 2026-Q1
8823
+ `);
8017
8824
  var governanceCmd = program.command("governance").description("Governance bodies, seats, meetings, resolutions").option("--entity-id <ref>", "Entity reference (overrides active entity)").option("--json", "Output as JSON").action(async (opts) => {
8018
8825
  const { governanceListCommand: governanceListCommand2 } = await Promise.resolve().then(() => (init_governance(), governance_exports));
8019
8826
  await governanceListCommand2(opts);
@@ -8106,7 +8913,7 @@ governanceCmd.command("reopen <meeting-ref>").option("--json", "Output as JSON")
8106
8913
  json: inheritOption(opts.json, parent.json)
8107
8914
  });
8108
8915
  });
8109
- governanceCmd.command("cancel <meeting-ref>").option("--json", "Output as JSON").option("--dry-run", "Show the request without cancelling the meeting").description("Cancel a meeting").action(async (meetingId, opts, cmd) => {
8916
+ governanceCmd.command("cancel <meeting-ref>").option("--json", "Output as JSON").option("--dry-run", "Show the request without cancelling the meeting").option("--yes, -y", "Skip confirmation prompt").description("Cancel a meeting").action(async (meetingId, opts, cmd) => {
8110
8917
  const parent = cmd.parent.opts();
8111
8918
  const { cancelMeetingCommand: cancelMeetingCommand2 } = await Promise.resolve().then(() => (init_governance(), governance_exports));
8112
8919
  await cancelMeetingCommand2(meetingId, {
@@ -8152,6 +8959,56 @@ governanceCmd.command("written-consent").requiredOption("--body <ref>", "Governa
8152
8959
  json: inheritOption(opts.json, parent.json)
8153
8960
  });
8154
8961
  });
8962
+ governanceCmd.command("mode").addOption(new Option("--set <mode>", "Set governance mode").choices(["founder", "board", "executive", "normal", "incident_lockdown"])).option("--json", "Output as JSON").description("View or set governance mode").action(async (opts, cmd) => {
8963
+ const parent = cmd.parent.opts();
8964
+ const { governanceModeCommand: governanceModeCommand2 } = await Promise.resolve().then(() => (init_governance(), governance_exports));
8965
+ await governanceModeCommand2({
8966
+ ...opts,
8967
+ entityId: parent.entityId,
8968
+ json: inheritOption(opts.json, parent.json)
8969
+ });
8970
+ });
8971
+ governanceCmd.command("resign <seat-ref>").option("--body-id <ref>", "Governance body reference").option("--json", "Output as JSON").description("Resign from a governance seat").action(async (seatRef, opts, cmd) => {
8972
+ const parent = cmd.parent.opts();
8973
+ const { governanceResignCommand: governanceResignCommand2 } = await Promise.resolve().then(() => (init_governance(), governance_exports));
8974
+ await governanceResignCommand2(seatRef, {
8975
+ ...opts,
8976
+ entityId: parent.entityId,
8977
+ json: inheritOption(opts.json, parent.json)
8978
+ });
8979
+ });
8980
+ governanceCmd.command("incidents").option("--json", "Output as JSON").description("List governance incidents").action(async (opts, cmd) => {
8981
+ const parent = cmd.parent.opts();
8982
+ const { governanceIncidentsCommand: governanceIncidentsCommand2 } = await Promise.resolve().then(() => (init_governance(), governance_exports));
8983
+ await governanceIncidentsCommand2({
8984
+ ...opts,
8985
+ entityId: parent.entityId,
8986
+ json: inheritOption(opts.json, parent.json)
8987
+ });
8988
+ });
8989
+ governanceCmd.command("profile").option("--json", "Output as JSON").description("View governance profile and configuration").action(async (opts, cmd) => {
8990
+ const parent = cmd.parent.opts();
8991
+ const { governanceProfileCommand: governanceProfileCommand2 } = await Promise.resolve().then(() => (init_governance(), governance_exports));
8992
+ await governanceProfileCommand2({
8993
+ ...opts,
8994
+ entityId: parent.entityId,
8995
+ json: inheritOption(opts.json, parent.json)
8996
+ });
8997
+ });
8998
+ governanceCmd.addHelpText("after", `
8999
+ Examples:
9000
+ $ corp governance create-body --name "Board of Directors" --body-type board_of_directors
9001
+ $ corp governance add-seat @last:body --holder "alice"
9002
+ $ corp governance convene --body board --type board_meeting --title "Q1 Review" --agenda "Approve budget"
9003
+ $ corp governance open @last:meeting --present-seat alice-seat
9004
+ $ corp governance vote @last:meeting <item-ref> --voter alice --vote for
9005
+ $ corp governance written-consent --body board --title "Approve Option Plan" --description "Board approves 2026 option plan"
9006
+ $ corp governance mode
9007
+ $ corp governance mode --set board
9008
+ $ corp governance resign <seat-ref>
9009
+ $ corp governance incidents
9010
+ $ corp governance profile
9011
+ `);
8155
9012
  var documentsCmd = program.command("documents").description("Documents and signing").option("--entity-id <ref>", "Entity reference (ID, short ID, @last, or unique name)").option("--json", "Output as JSON").action(async (opts) => {
8156
9013
  const { documentsListCommand: documentsListCommand2 } = await Promise.resolve().then(() => (init_documents(), documents_exports));
8157
9014
  await documentsListCommand2(opts);
@@ -8197,7 +9054,10 @@ documentsCmd.command("preview-pdf").option("--definition-id <id>", "AST document
8197
9054
  entityId: parent.entityId
8198
9055
  });
8199
9056
  });
8200
- var taxCmd = program.command("tax").description("Tax filings and deadline tracking").option("--entity-id <ref>", "Entity reference (ID, short ID, @last, or unique name)").option("--json", "Output as JSON");
9057
+ var taxCmd = program.command("tax").description("Tax filings and deadline tracking").option("--entity-id <ref>", "Entity reference (ID, short ID, @last, or unique name)").option("--json", "Output as JSON").action(async (opts) => {
9058
+ const { taxSummaryCommand: taxSummaryCommand2 } = await Promise.resolve().then(() => (init_tax(), tax_exports));
9059
+ await taxSummaryCommand2(opts);
9060
+ });
8201
9061
  taxCmd.command("filings").option("--json", "Output as JSON").description("List tax filings").action(async (opts, cmd) => {
8202
9062
  const parent = cmd.parent.opts();
8203
9063
  const { taxFilingsCommand: taxFilingsCommand2 } = await Promise.resolve().then(() => (init_tax(), tax_exports));
@@ -8207,7 +9067,9 @@ taxCmd.command("filings").option("--json", "Output as JSON").description("List t
8207
9067
  json: inheritOption(opts.json, parent.json)
8208
9068
  });
8209
9069
  });
8210
- taxCmd.command("file").addOption(new Option("--type <type>", `Document type (${TAX_DOCUMENT_TYPE_CHOICES.join(", ")})`).choices([...TAX_DOCUMENT_TYPE_CHOICES]).makeOptionMandatory()).requiredOption("--year <year>", "Tax year", parseInt).option("--json", "Output as JSON").description("File a tax document").action(async (opts, cmd) => {
9070
+ taxCmd.command("file").addOption(
9071
+ new Option("--type <type>", `Document type (${TAX_DOCUMENT_TYPE_DISPLAY.join(", ")})`).choices([...TAX_DOCUMENT_TYPE_CHOICES]).makeOptionMandatory()
9072
+ ).requiredOption("--year <year>", "Tax year", parseInt).option("--json", "Output as JSON").description("File a tax document").action(async (opts, cmd) => {
8211
9073
  const parent = cmd.parent.opts();
8212
9074
  const { taxFileCommand: taxFileCommand2 } = await Promise.resolve().then(() => (init_tax(), tax_exports));
8213
9075
  await taxFileCommand2({
@@ -8225,11 +9087,16 @@ taxCmd.command("deadlines").option("--json", "Output as JSON").description("List
8225
9087
  json: inheritOption(opts.json, parent.json)
8226
9088
  });
8227
9089
  });
8228
- taxCmd.command("deadline").requiredOption("--type <type>", "Deadline type").requiredOption("--due-date <date>", "Due date (ISO 8601)").requiredOption("--description <desc>", "Description").option("--recurrence <recurrence>", "Recurrence (e.g. annual; 'yearly' is normalized)").option("--json", "Output as JSON").description("Track a compliance deadline").action(async (opts, cmd) => {
9090
+ taxCmd.command("deadline").requiredOption("--type <type>", "Deadline type").requiredOption("--due-date <date>", "Due date (ISO 8601)").requiredOption("--description <desc>", "Description").option("--recurrence <recurrence>", "Recurrence (e.g. annual; 'yearly' is normalized). Required for annual_report type.").option("--json", "Output as JSON").description("Track a compliance deadline").action(async (opts, cmd) => {
8229
9091
  const parent = cmd.parent.opts();
9092
+ let recurrence = opts.recurrence;
9093
+ if (!recurrence && opts.type === "annual_report") {
9094
+ recurrence = "annual";
9095
+ }
8230
9096
  const { taxDeadlineCommand: taxDeadlineCommand2 } = await Promise.resolve().then(() => (init_tax(), tax_exports));
8231
9097
  await taxDeadlineCommand2({
8232
9098
  ...opts,
9099
+ recurrence,
8233
9100
  entityId: parent.entityId,
8234
9101
  json: inheritOption(opts.json, parent.json)
8235
9102
  });
@@ -8268,11 +9135,12 @@ agentsCmd.command("resume <agent-ref>").option("--json", "Output as JSON").descr
8268
9135
  json: inheritOption(opts.json, parent.json)
8269
9136
  });
8270
9137
  });
8271
- agentsCmd.command("delete <agent-ref>").option("--json", "Output as JSON").description("Delete an agent").action(async (agentId, opts, cmd) => {
9138
+ agentsCmd.command("delete <agent-ref>").option("--json", "Output as JSON").option("--yes, -y", "Skip confirmation prompt").description("Delete an agent").action(async (agentId, opts, cmd) => {
8272
9139
  const parent = cmd.parent.opts();
8273
9140
  const { agentsDeleteCommand: agentsDeleteCommand2 } = await Promise.resolve().then(() => (init_agents(), agents_exports));
8274
9141
  await agentsDeleteCommand2(agentId, {
8275
- json: inheritOption(opts.json, parent.json)
9142
+ json: inheritOption(opts.json, parent.json),
9143
+ yes: opts.yes
8276
9144
  });
8277
9145
  });
8278
9146
  agentsCmd.command("message <agent-ref>").option("--body <text>", "Message text").option("--body-file <path>", "Read the message body from a file").option("--json", "Output as JSON").description("Send a message to an agent").action(async (agentId, opts, cmd) => {
@@ -8291,6 +9159,37 @@ agentsCmd.command("skill <agent-ref>").requiredOption("--name <name>", "Skill na
8291
9159
  json: inheritOption(opts.json, parent.json)
8292
9160
  });
8293
9161
  });
9162
+ agentsCmd.command("execution <agent-ref> <execution-id>").option("--json", "Output as JSON").description("Check execution status").action(async (agentId, executionId, opts, cmd) => {
9163
+ const parent = cmd.parent.opts();
9164
+ const { agentsExecutionCommand: agentsExecutionCommand2 } = await Promise.resolve().then(() => (init_agents(), agents_exports));
9165
+ await agentsExecutionCommand2(agentId, executionId, {
9166
+ json: opts.json ?? parent.json
9167
+ });
9168
+ });
9169
+ agentsCmd.command("execution-result <agent-ref> <execution-id>").option("--json", "Output as JSON").description("Get execution result").action(async (agentId, executionId, opts, cmd) => {
9170
+ const parent = cmd.parent.opts();
9171
+ const { agentsExecutionResultCommand: agentsExecutionResultCommand2 } = await Promise.resolve().then(() => (init_agents(), agents_exports));
9172
+ await agentsExecutionResultCommand2(agentId, executionId, {
9173
+ json: opts.json ?? parent.json
9174
+ });
9175
+ });
9176
+ agentsCmd.command("kill <agent-ref> <execution-id>").option("--yes", "Skip confirmation").option("--json", "Output as JSON").description("Kill a running execution").action(async (agentId, executionId, opts, cmd) => {
9177
+ const parent = cmd.parent.opts();
9178
+ const { agentsKillCommand: agentsKillCommand2 } = await Promise.resolve().then(() => (init_agents(), agents_exports));
9179
+ await agentsKillCommand2(agentId, executionId, {
9180
+ ...opts,
9181
+ json: opts.json ?? parent.json
9182
+ });
9183
+ });
9184
+ agentsCmd.addHelpText("after", `
9185
+ Examples:
9186
+ $ corp agents # list all agents
9187
+ $ corp agents create --name "bookkeeper" --prompt "You manage accounts payable"
9188
+ $ corp agents message @last:agent --body "Process this month's invoices"
9189
+ $ corp agents skill @last:agent --name invoice-processing --description "Process AP invoices"
9190
+ $ corp agents execution @last:agent <execution-id> # check execution status
9191
+ $ corp agents kill @last:agent <execution-id> # kill a running execution
9192
+ `);
8294
9193
  var workItemsCmd = program.command("work-items").description("Long-term work item coordination").option("--entity-id <ref>", "Entity reference (ID, short ID, @last, or unique name)").option("--json", "Output as JSON").option("--status <status>", "Filter by status (open, claimed, completed, cancelled)").option("--category <category>", "Filter by category").action(async (opts) => {
8295
9194
  const { workItemsListCommand: workItemsListCommand2 } = await Promise.resolve().then(() => (init_work_items(), work_items_exports));
8296
9195
  await workItemsListCommand2(opts);
@@ -8306,15 +9205,20 @@ workItemsCmd.command("show <item-ref>").option("--json", "Output as JSON").descr
8306
9205
  });
8307
9206
  workItemsCmd.command("create").requiredOption("--title <title>", "Work item title").option("--category <category>", "Work item category").option("--description <desc>", "Description").option("--deadline <date>", "Deadline (YYYY-MM-DD)").option("--asap", "Mark as ASAP priority").option("--created-by <name>", "Creator identifier").option("--json", "Output as JSON").description("Create a new work item").action(async (opts, cmd) => {
8308
9207
  const parent = cmd.parent.opts();
9208
+ const resolvedCategory = inheritOption(opts.category, parent.category);
9209
+ if (!resolvedCategory) {
9210
+ cmd.error("required option '--category <category>' not specified");
9211
+ return;
9212
+ }
8309
9213
  const { workItemsCreateCommand: workItemsCreateCommand2 } = await Promise.resolve().then(() => (init_work_items(), work_items_exports));
8310
9214
  await workItemsCreateCommand2({
8311
9215
  ...opts,
8312
- category: inheritOption(opts.category, parent.category),
9216
+ category: resolvedCategory,
8313
9217
  entityId: parent.entityId,
8314
9218
  json: inheritOption(opts.json, parent.json)
8315
9219
  });
8316
9220
  });
8317
- workItemsCmd.command("claim <item-ref>").option("--by <name>", "Agent or user claiming the item").option("--claimer <name>", "Alias for --by").option("--ttl <seconds>", "Auto-release TTL in seconds", parseInt).option("--json", "Output as JSON").description("Claim a work item").action(async (itemId, opts, cmd) => {
9221
+ workItemsCmd.command("claim <item-ref>").option("--by <name>", "Agent or user claiming the item (required)").option("--claimer <name>", "Alias for --by").option("--ttl <seconds>", "Auto-release TTL in seconds", parseInt).option("--json", "Output as JSON").description("Claim a work item").action(async (itemId, opts, cmd) => {
8318
9222
  const parent = cmd.parent.opts();
8319
9223
  const { workItemsClaimCommand: workItemsClaimCommand2 } = await Promise.resolve().then(() => (init_work_items(), work_items_exports));
8320
9224
  const claimedBy = opts.by ?? opts.claimer;
@@ -8329,7 +9233,7 @@ workItemsCmd.command("claim <item-ref>").option("--by <name>", "Agent or user cl
8329
9233
  json: inheritOption(opts.json, parent.json)
8330
9234
  });
8331
9235
  });
8332
- workItemsCmd.command("complete <item-ref>").option("--by <name>", "Agent or user completing the item").option("--completed-by <name>", "Alias for --by").option("--result <text>", "Completion result or notes").option("--notes <text>", "Alias for --result").option("--json", "Output as JSON").description("Mark a work item as completed").action(async (itemId, opts, cmd) => {
9236
+ workItemsCmd.command("complete <item-ref>").option("--by <name>", "Agent or user completing the item (required)").option("--completed-by <name>", "Alias for --by").option("--result <text>", "Completion result or notes").option("--notes <text>", "Alias for --result").option("--json", "Output as JSON").description("Mark a work item as completed").action(async (itemId, opts, cmd) => {
8333
9237
  const parent = cmd.parent.opts();
8334
9238
  const { workItemsCompleteCommand: workItemsCompleteCommand2 } = await Promise.resolve().then(() => (init_work_items(), work_items_exports));
8335
9239
  const completedBy = opts.by ?? opts.completedBy;
@@ -8352,15 +9256,26 @@ workItemsCmd.command("release <item-ref>").option("--json", "Output as JSON").de
8352
9256
  json: inheritOption(opts.json, parent.json)
8353
9257
  });
8354
9258
  });
8355
- workItemsCmd.command("cancel <item-ref>").option("--json", "Output as JSON").description("Cancel a work item").action(async (itemId, opts, cmd) => {
9259
+ workItemsCmd.command("cancel <item-ref>").option("--json", "Output as JSON").option("--yes, -y", "Skip confirmation prompt").description("Cancel a work item").action(async (itemId, opts, cmd) => {
8356
9260
  const parent = cmd.parent.opts();
8357
9261
  const { workItemsCancelCommand: workItemsCancelCommand2 } = await Promise.resolve().then(() => (init_work_items(), work_items_exports));
8358
9262
  await workItemsCancelCommand2(itemId, {
8359
9263
  entityId: parent.entityId,
8360
- json: inheritOption(opts.json, parent.json)
9264
+ json: inheritOption(opts.json, parent.json),
9265
+ yes: opts.yes
8361
9266
  });
8362
9267
  });
8363
- var servicesCmd = program.command("services").description("Service catalog and fulfillment").option("--entity-id <ref>", "Entity reference (ID, short ID, @last, or unique name)").option("--json", "Output as JSON");
9268
+ workItemsCmd.addHelpText("after", `
9269
+ Examples:
9270
+ $ corp work-items # list open work items
9271
+ $ corp work-items create --title "File Q1 taxes" --category compliance --deadline 2026-04-15
9272
+ $ corp work-items claim @last:work_item --by bookkeeper-agent
9273
+ $ corp work-items complete @last:work_item --by bookkeeper-agent --result "Filed 1120 for Q1"
9274
+ `);
9275
+ var servicesCmd = program.command("services").description("Service catalog and fulfillment").option("--entity-id <ref>", "Entity reference (ID, short ID, @last, or unique name)").option("--json", "Output as JSON").action(async (opts) => {
9276
+ const { servicesCatalogCommand: servicesCatalogCommand2 } = await Promise.resolve().then(() => (init_services(), services_exports));
9277
+ await servicesCatalogCommand2({ json: opts.json });
9278
+ });
8364
9279
  servicesCmd.command("catalog").option("--json", "Output as JSON").description("List the service catalog").action(async (opts, cmd) => {
8365
9280
  const parent = cmd.parent.opts();
8366
9281
  const { servicesCatalogCommand: servicesCatalogCommand2 } = await Promise.resolve().then(() => (init_services(), services_exports));
@@ -8429,20 +9344,44 @@ program.command("approvals").description("Approvals are managed through governan
8429
9344
  const { approvalsListCommand: approvalsListCommand2 } = await Promise.resolve().then(() => (init_approvals(), approvals_exports));
8430
9345
  await approvalsListCommand2({});
8431
9346
  });
8432
- var formCmd = program.command("form").description("Form a new entity with founders and cap table").option("--entity-type <type>", "Entity type (llc, c_corp)").option("--legal-name <name>", "Legal name").option("--jurisdiction <jurisdiction>", "Jurisdiction (e.g. US-DE, US-WY)").option("--member <member>", "Founder as 'name,email,role[,pct[,address[,officer_title[,is_incorporator]]]]' with address as street|city|state|zip, or key=value pairs like 'name=...,email=...,role=...,officer_title=cto,is_incorporator=true,address=street|city|state|zip' (repeatable)", (v, a) => [...a, v], []).option("--member-json <json>", "Founder JSON object (repeatable)", (v, a) => [...a, v], []).option("--members-file <path>", 'Path to a JSON array of founders or {"members": [...]}').option("--address <address>", "Company address as 'street,city,state,zip'").option("--fiscal-year-end <date>", "Fiscal year end (MM-DD)", "12-31").option("--s-corp", "Elect S-Corp status").option("--transfer-restrictions", "Enable transfer restrictions").option("--rofr", "Enable right of first refusal").option("--json", "Output as JSON").option("--dry-run", "Show the request without creating the entity").action(async (opts) => {
8433
- if (opts.entityType && !opts.type) opts.type = opts.entityType;
8434
- if (opts.legalName && !opts.name) opts.name = opts.legalName;
9347
+ var formCmd = program.command("form").enablePositionalOptions().passThroughOptions().description("Form a new entity with founders and cap table").option("--type <type>", "Entity type (llc, c_corp)").option("--name <name>", "Legal name").option("--jurisdiction <jurisdiction>", "Jurisdiction (e.g. US-DE, US-WY)").option("--member <member>", "Founder as 'name,email,role[,pct[,address[,officer_title[,is_incorporator]]]]' with address as street|city|state|zip, or key=value pairs like 'name=...,email=...,role=...,officer_title=cto,is_incorporator=true,address=street|city|state|zip' (repeatable)", (v, a) => [...a, v], []).option("--member-json <json>", "Founder JSON object (repeatable)", (v, a) => [...a, v], []).option("--members-file <path>", 'Path to a JSON array of founders or {"members": [...]}').option("--address <address>", "Company address as 'street,city,state,zip'").option("--fiscal-year-end <date>", "Fiscal year end (MM-DD)", "12-31").option("--s-corp", "Elect S-Corp status").option("--transfer-restrictions", "Enable transfer restrictions").option("--rofr", "Enable right of first refusal").option("--json", "Output as JSON").option("--dry-run", "Show the request without creating the entity").action(async (opts, cmd) => {
8435
9348
  const { formCommand: formCommand2 } = await Promise.resolve().then(() => (init_form(), form_exports));
8436
- await formCommand2(opts);
9349
+ await formCommand2({ ...opts, quiet: program.opts().quiet });
8437
9350
  });
8438
- formCmd.command("create").description("Create a pending entity (staged flow step 1)").requiredOption("--type <type>", "Entity type (llc, c_corp)").requiredOption("--name <name>", "Legal name").option("--jurisdiction <jurisdiction>", "Jurisdiction (e.g. US-DE, US-WY)").option("--registered-agent-name <name>", "Registered agent legal name").option("--registered-agent-address <address>", "Registered agent address line").option("--formation-date <date>", "Formation date (RFC3339 or YYYY-MM-DD)").option("--fiscal-year-end <date>", "Fiscal year end (MM-DD)").option("--s-corp", "Elect S-Corp status").option("--transfer-restrictions", "Enable transfer restrictions").option("--rofr", "Enable right of first refusal").option("--company-address <address>", "Company address as 'street,city,state,zip'").option("--json", "Output as JSON").option("--dry-run", "Show the request without creating the pending entity").action(async (opts, cmd) => {
9351
+ formCmd.command("create").description("Create a pending entity (staged flow step 1)").option("--type <type>", "Entity type (llc, c_corp)").option("--name <name>", "Legal name").option("--jurisdiction <jurisdiction>", "Jurisdiction (e.g. US-DE, US-WY)").option("--registered-agent-name <name>", "Registered agent legal name").option("--registered-agent-address <address>", "Registered agent address line").option("--formation-date <date>", "Formation date (RFC3339 or YYYY-MM-DD)").option("--fiscal-year-end <date>", "Fiscal year end (MM-DD)").option("--s-corp", "Elect S-Corp status").option("--transfer-restrictions", "Enable transfer restrictions").option("--rofr", "Enable right of first refusal").option("--company-address <address>", "Company address as 'street,city,state,zip'").option("--json", "Output as JSON").option("--dry-run", "Show the request without creating the pending entity").action(async (opts, cmd) => {
8439
9352
  const parent = cmd.parent.opts();
9353
+ const resolvedType = inheritOption(opts.type, parent.type);
9354
+ const resolvedName = inheritOption(opts.name, parent.name);
9355
+ if (!resolvedType) {
9356
+ cmd.error("required option '--type <type>' not specified");
9357
+ return;
9358
+ }
9359
+ const SUPPORTED_ENTITY_TYPES2 = ["llc", "c_corp", "s_corp", "corporation"];
9360
+ if (!SUPPORTED_ENTITY_TYPES2.includes(resolvedType)) {
9361
+ cmd.error(`unsupported entity type '${resolvedType}'. Supported types: ${SUPPORTED_ENTITY_TYPES2.join(", ")}`);
9362
+ return;
9363
+ }
9364
+ if (!resolvedName) {
9365
+ cmd.error("required option '--name <name>' not specified");
9366
+ return;
9367
+ }
9368
+ if (!resolvedName.trim()) {
9369
+ cmd.error("--name cannot be empty or whitespace");
9370
+ return;
9371
+ }
8440
9372
  const { formCreateCommand: formCreateCommand2 } = await Promise.resolve().then(() => (init_form(), form_exports));
8441
9373
  await formCreateCommand2({
8442
9374
  ...opts,
9375
+ type: resolvedType,
9376
+ name: resolvedName,
8443
9377
  jurisdiction: inheritOption(opts.jurisdiction, parent.jurisdiction),
9378
+ fiscalYearEnd: inheritOption(opts.fiscalYearEnd, parent.fiscalYearEnd),
9379
+ sCorp: inheritOption(opts.sCorp, parent.sCorp),
9380
+ transferRestrictions: inheritOption(opts.transferRestrictions, parent.transferRestrictions),
9381
+ rofr: inheritOption(opts.rofr, parent.rofr),
8444
9382
  json: inheritOption(opts.json, parent.json),
8445
- dryRun: inheritOption(opts.dryRun, parent.dryRun)
9383
+ dryRun: inheritOption(opts.dryRun, parent.dryRun),
9384
+ quiet: program.opts().quiet
8446
9385
  });
8447
9386
  });
8448
9387
  formCmd.command("add-founder <entity-ref>").description("Add a founder to a pending entity (staged flow step 2)").requiredOption("--name <name>", "Founder name").requiredOption("--email <email>", "Founder email").requiredOption("--role <role>", "Role: director|officer|manager|member|chair").requiredOption("--pct <pct>", "Ownership percentage").addOption(new Option("--officer-title <title>", "Officer title (corporations only)").choices(["ceo", "cfo", "cto", "coo", "secretary", "treasurer", "president", "vp", "other"])).option("--incorporator", "Mark as sole incorporator (corporations only)").option("--address <address>", "Founder address as 'street,city,state,zip'").option("--json", "Output as JSON").option("--dry-run", "Show the request without adding the founder").action(async (entityId, opts, cmd) => {
@@ -8469,9 +9408,30 @@ formCmd.command("activate <entity-ref>").description("Programmatically sign form
8469
9408
  dryRun: inheritOption(opts.dryRun, cmd.parent.opts().dryRun)
8470
9409
  });
8471
9410
  });
8472
- program.command("api-keys").description("List API keys").option("--json", "Output as JSON").action(async (opts) => {
8473
- const { apiKeysCommand: apiKeysCommand2 } = await Promise.resolve().then(() => (init_api_keys(), api_keys_exports));
8474
- await apiKeysCommand2(opts);
9411
+ formCmd.addHelpText("after", `
9412
+ Examples:
9413
+ $ corp form --type llc --name "My LLC" --member "Alice,alice@co.com,member,100"
9414
+ $ corp form --type c_corp --name "Acme Inc" --jurisdiction US-DE --member-json '{"name":"Bob","email":"bob@acme.com","role":"director","pct":100}'
9415
+ $ corp form create --type llc --name "My LLC"
9416
+ $ corp form add-founder @last:entity --name "Alice" --email "alice@co.com" --role member --pct 100
9417
+ $ corp form finalize @last:entity
9418
+ $ corp form activate @last:entity
9419
+ `);
9420
+ var apiKeysCmd = program.command("api-keys").description("API key management").option("--json", "Output as JSON").action(async (opts) => {
9421
+ const { apiKeysListCommand: apiKeysListCommand2 } = await Promise.resolve().then(() => (init_api_keys(), api_keys_exports));
9422
+ await apiKeysListCommand2(opts);
9423
+ });
9424
+ apiKeysCmd.command("create").requiredOption("--name <name>", "Key name/label").option("--scopes <scopes>", "Comma-separated scopes").option("--json", "Output as JSON").description("Create a new API key").action(async (opts) => {
9425
+ const { apiKeysCreateCommand: apiKeysCreateCommand2 } = await Promise.resolve().then(() => (init_api_keys(), api_keys_exports));
9426
+ await apiKeysCreateCommand2(opts);
9427
+ });
9428
+ apiKeysCmd.command("revoke <key-id>").option("--yes", "Skip confirmation").option("--json", "Output as JSON").description("Revoke an API key").action(async (keyId, opts) => {
9429
+ const { apiKeysRevokeCommand: apiKeysRevokeCommand2 } = await Promise.resolve().then(() => (init_api_keys(), api_keys_exports));
9430
+ await apiKeysRevokeCommand2(keyId, opts);
9431
+ });
9432
+ apiKeysCmd.command("rotate <key-id>").option("--json", "Output as JSON").description("Rotate an API key (returns new key)").action(async (keyId, opts) => {
9433
+ const { apiKeysRotateCommand: apiKeysRotateCommand2 } = await Promise.resolve().then(() => (init_api_keys(), api_keys_exports));
9434
+ await apiKeysRotateCommand2(keyId, opts);
8475
9435
  });
8476
9436
  program.command("demo").description("Create a usable demo workspace environment").requiredOption("--name <name>", "Corporation name").option("--scenario <scenario>", "Scenario to create (startup, llc, restaurant)", "startup").option("--minimal", "Use the minimal server-side demo seed instead of the full CLI workflow").option("--json", "Output as JSON").action(async (opts) => {
8477
9437
  const { demoCommand: demoCommand2 } = await Promise.resolve().then(() => (init_demo(), demo_exports));