chainlesschain 0.81.0 → 0.132.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. package/bin/chainlesschain.js +0 -0
  2. package/package.json +1 -1
  3. package/src/commands/agent-network.js +254 -1
  4. package/src/commands/audit.js +302 -0
  5. package/src/commands/automation.js +271 -1
  6. package/src/commands/codegen.js +224 -0
  7. package/src/commands/collab.js +341 -0
  8. package/src/commands/compliance.js +1035 -0
  9. package/src/commands/cowork.js +221 -0
  10. package/src/commands/dbevo.js +284 -0
  11. package/src/commands/dev.js +252 -0
  12. package/src/commands/did.js +358 -0
  13. package/src/commands/encrypt.js +341 -0
  14. package/src/commands/export.js +256 -1
  15. package/src/commands/fusion.js +258 -0
  16. package/src/commands/governance.js +325 -0
  17. package/src/commands/hardening.js +411 -0
  18. package/src/commands/hook.js +148 -0
  19. package/src/commands/import.js +252 -0
  20. package/src/commands/incentive.js +322 -0
  21. package/src/commands/infra.js +244 -0
  22. package/src/commands/instinct.js +260 -0
  23. package/src/commands/ipfs.js +318 -0
  24. package/src/commands/kg.js +387 -0
  25. package/src/commands/llm.js +263 -0
  26. package/src/commands/mcp.js +221 -0
  27. package/src/commands/memory.js +248 -0
  28. package/src/commands/multimodal.js +296 -0
  29. package/src/commands/nlprog.js +356 -0
  30. package/src/commands/note.js +244 -0
  31. package/src/commands/ops.js +354 -0
  32. package/src/commands/orchestrate.js +166 -0
  33. package/src/commands/org.js +277 -0
  34. package/src/commands/p2p.js +390 -0
  35. package/src/commands/perception.js +290 -0
  36. package/src/commands/permmem.js +251 -0
  37. package/src/commands/plugin-ecosystem.js +273 -0
  38. package/src/commands/pqc.js +393 -0
  39. package/src/commands/quantization.js +351 -0
  40. package/src/commands/rcache.js +271 -0
  41. package/src/commands/recommend.js +340 -0
  42. package/src/commands/runtime.js +307 -0
  43. package/src/commands/scim.js +262 -0
  44. package/src/commands/session.js +258 -0
  45. package/src/commands/skill.js +267 -1
  46. package/src/commands/social.js +256 -0
  47. package/src/commands/sso.js +186 -1
  48. package/src/commands/sync.js +256 -0
  49. package/src/commands/tech.js +338 -0
  50. package/src/commands/tenant.js +351 -0
  51. package/src/commands/tokens.js +269 -0
  52. package/src/commands/trust.js +249 -0
  53. package/src/commands/wallet.js +277 -0
  54. package/src/commands/workflow.js +171 -0
  55. package/src/index.js +4 -0
  56. package/src/lib/agent-coordinator.js +325 -0
  57. package/src/lib/agent-network.js +387 -0
  58. package/src/lib/agent-router.js +395 -0
  59. package/src/lib/aiops.js +478 -0
  60. package/src/lib/audit-logger.js +379 -0
  61. package/src/lib/automation-engine.js +330 -0
  62. package/src/lib/autonomous-developer.js +350 -0
  63. package/src/lib/code-agent.js +323 -0
  64. package/src/lib/collaboration-governance.js +364 -0
  65. package/src/lib/community-governance.js +436 -0
  66. package/src/lib/compliance-manager.js +434 -0
  67. package/src/lib/content-recommendation.js +469 -0
  68. package/src/lib/crypto-manager.js +350 -0
  69. package/src/lib/dbevo.js +338 -0
  70. package/src/lib/decentral-infra.js +340 -0
  71. package/src/lib/did-manager.js +367 -0
  72. package/src/lib/hardening-manager.js +348 -0
  73. package/src/lib/hook-manager.js +380 -0
  74. package/src/lib/instinct-manager.js +332 -0
  75. package/src/lib/ipfs-storage.js +334 -0
  76. package/src/lib/knowledge-exporter.js +381 -0
  77. package/src/lib/knowledge-graph.js +432 -0
  78. package/src/lib/knowledge-importer.js +379 -0
  79. package/src/lib/llm-providers.js +391 -0
  80. package/src/lib/mcp-registry.js +333 -0
  81. package/src/lib/memory-manager.js +330 -0
  82. package/src/lib/multimodal.js +346 -0
  83. package/src/lib/nl-programming.js +343 -0
  84. package/src/lib/note-versioning.js +327 -0
  85. package/src/lib/org-manager.js +323 -0
  86. package/src/lib/p2p-manager.js +387 -0
  87. package/src/lib/perception.js +346 -0
  88. package/src/lib/perf-tuning.js +4 -1
  89. package/src/lib/permanent-memory.js +320 -0
  90. package/src/lib/plugin-ecosystem.js +377 -0
  91. package/src/lib/pqc-manager.js +368 -0
  92. package/src/lib/protocol-fusion.js +417 -0
  93. package/src/lib/quantization.js +325 -0
  94. package/src/lib/response-cache.js +327 -0
  95. package/src/lib/scim-manager.js +329 -0
  96. package/src/lib/session-manager.js +329 -0
  97. package/src/lib/skill-loader.js +377 -0
  98. package/src/lib/social-manager.js +326 -0
  99. package/src/lib/sso-manager.js +332 -0
  100. package/src/lib/sync-manager.js +326 -0
  101. package/src/lib/tech-learning-engine.js +369 -0
  102. package/src/lib/tenant-saas.js +460 -0
  103. package/src/lib/threat-intel.js +335 -0
  104. package/src/lib/token-incentive.js +293 -0
  105. package/src/lib/token-tracker.js +329 -0
  106. package/src/lib/trust-security.js +390 -0
  107. package/src/lib/ueba.js +389 -0
  108. package/src/lib/universal-runtime.js +325 -0
  109. package/src/lib/wallet-manager.js +326 -0
  110. package/src/lib/workflow-engine.js +322 -0
@@ -11,6 +11,37 @@ import {
11
11
  getTodayStats,
12
12
  getCostBreakdown,
13
13
  getRecentUsage,
14
+ BUDGET_MATURITY_V2,
15
+ USAGE_RECORD_LIFECYCLE_V2,
16
+ getMaxActiveBudgetsPerOwnerV2,
17
+ setMaxActiveBudgetsPerOwnerV2,
18
+ getMaxPendingRecordsPerBudgetV2,
19
+ setMaxPendingRecordsPerBudgetV2,
20
+ getBudgetIdleMsV2,
21
+ setBudgetIdleMsV2,
22
+ getRecordStuckMsV2,
23
+ setRecordStuckMsV2,
24
+ registerBudgetV2,
25
+ getBudgetV2,
26
+ listBudgetsV2,
27
+ setBudgetStatusV2,
28
+ activateBudgetV2,
29
+ suspendBudgetV2,
30
+ archiveBudgetV2,
31
+ touchBudgetV2,
32
+ getActiveBudgetCountV2,
33
+ createUsageRecordV2,
34
+ getUsageRecordV2,
35
+ listUsageRecordsV2,
36
+ setUsageRecordStatusV2,
37
+ recordUsageV2,
38
+ billUsageV2,
39
+ rejectUsageV2,
40
+ refundUsageV2,
41
+ getPendingRecordCountV2,
42
+ autoSuspendIdleBudgetsV2,
43
+ autoRejectStaleRecordsV2,
44
+ getTokenTrackerStatsV2,
14
45
  } from "../lib/token-tracker.js";
15
46
  import {
16
47
  getCacheStats,
@@ -211,4 +242,242 @@ export function registerTokensCommand(program) {
211
242
  process.exit(1);
212
243
  }
213
244
  });
245
+
246
+ // ── V2 Surface ──
247
+
248
+ const out = (json, obj) => {
249
+ if (json) console.log(JSON.stringify(obj, null, 2));
250
+ else console.log(JSON.stringify(obj, null, 2));
251
+ };
252
+ const tryRun = (fn) => {
253
+ try {
254
+ fn();
255
+ } catch (err) {
256
+ logger.error(err.message);
257
+ process.exit(1);
258
+ }
259
+ };
260
+
261
+ tokens
262
+ .command("budget-maturities-v2")
263
+ .description("List V2 budget maturity states")
264
+ .action(() => out(true, Object.values(BUDGET_MATURITY_V2)));
265
+
266
+ tokens
267
+ .command("usage-record-lifecycles-v2")
268
+ .description("List V2 usage record lifecycle states")
269
+ .action(() => out(true, Object.values(USAGE_RECORD_LIFECYCLE_V2)));
270
+
271
+ tokens
272
+ .command("stats-v2")
273
+ .description("V2 token-tracker stats")
274
+ .action(() => out(true, getTokenTrackerStatsV2()));
275
+
276
+ tokens
277
+ .command("get-max-active-budgets-v2")
278
+ .description("Get max active budgets per owner (V2)")
279
+ .action(() =>
280
+ out(true, { maxActiveBudgetsPerOwner: getMaxActiveBudgetsPerOwnerV2() }),
281
+ );
282
+
283
+ tokens
284
+ .command("set-max-active-budgets-v2 <n>")
285
+ .description("Set max active budgets per owner (V2)")
286
+ .action((n) =>
287
+ tryRun(() => {
288
+ setMaxActiveBudgetsPerOwnerV2(Number(n));
289
+ out(true, {
290
+ maxActiveBudgetsPerOwner: getMaxActiveBudgetsPerOwnerV2(),
291
+ });
292
+ }),
293
+ );
294
+
295
+ tokens
296
+ .command("get-max-pending-records-v2")
297
+ .description("Get max pending records per budget (V2)")
298
+ .action(() =>
299
+ out(true, {
300
+ maxPendingRecordsPerBudget: getMaxPendingRecordsPerBudgetV2(),
301
+ }),
302
+ );
303
+
304
+ tokens
305
+ .command("set-max-pending-records-v2 <n>")
306
+ .description("Set max pending records per budget (V2)")
307
+ .action((n) =>
308
+ tryRun(() => {
309
+ setMaxPendingRecordsPerBudgetV2(Number(n));
310
+ out(true, {
311
+ maxPendingRecordsPerBudget: getMaxPendingRecordsPerBudgetV2(),
312
+ });
313
+ }),
314
+ );
315
+
316
+ tokens
317
+ .command("get-budget-idle-ms-v2")
318
+ .description("Get budget idle threshold (V2)")
319
+ .action(() => out(true, { budgetIdleMs: getBudgetIdleMsV2() }));
320
+
321
+ tokens
322
+ .command("set-budget-idle-ms-v2 <ms>")
323
+ .description("Set budget idle threshold (V2)")
324
+ .action((ms) =>
325
+ tryRun(() => {
326
+ setBudgetIdleMsV2(Number(ms));
327
+ out(true, { budgetIdleMs: getBudgetIdleMsV2() });
328
+ }),
329
+ );
330
+
331
+ tokens
332
+ .command("get-record-stuck-ms-v2")
333
+ .description("Get record stuck threshold (V2)")
334
+ .action(() => out(true, { recordStuckMs: getRecordStuckMsV2() }));
335
+
336
+ tokens
337
+ .command("set-record-stuck-ms-v2 <ms>")
338
+ .description("Set record stuck threshold (V2)")
339
+ .action((ms) =>
340
+ tryRun(() => {
341
+ setRecordStuckMsV2(Number(ms));
342
+ out(true, { recordStuckMs: getRecordStuckMsV2() });
343
+ }),
344
+ );
345
+
346
+ tokens
347
+ .command("active-budget-count-v2 <ownerId>")
348
+ .description("Active budget count for owner (V2)")
349
+ .action((ownerId) =>
350
+ out(true, { ownerId, count: getActiveBudgetCountV2(ownerId) }),
351
+ );
352
+
353
+ tokens
354
+ .command("pending-record-count-v2 <budgetId>")
355
+ .description("Pending record count for budget (V2)")
356
+ .action((budgetId) =>
357
+ out(true, { budgetId, count: getPendingRecordCountV2(budgetId) }),
358
+ );
359
+
360
+ tokens
361
+ .command("register-budget-v2 <id>")
362
+ .description("Register a V2 budget")
363
+ .requiredOption("-o, --owner <id>", "owner id")
364
+ .requiredOption("-l, --label <label>", "budget label")
365
+ .action((id, opts) =>
366
+ tryRun(() =>
367
+ out(
368
+ true,
369
+ registerBudgetV2(id, { ownerId: opts.owner, label: opts.label }),
370
+ ),
371
+ ),
372
+ );
373
+
374
+ tokens
375
+ .command("get-budget-v2 <id>")
376
+ .description("Get a V2 budget")
377
+ .action((id) => out(true, getBudgetV2(id)));
378
+
379
+ tokens
380
+ .command("list-budgets-v2")
381
+ .description("List V2 budgets")
382
+ .option("-o, --owner <id>", "filter by owner")
383
+ .option("-s, --status <status>", "filter by status")
384
+ .action((opts) =>
385
+ out(true, listBudgetsV2({ ownerId: opts.owner, status: opts.status })),
386
+ );
387
+
388
+ tokens
389
+ .command("set-budget-status-v2 <id> <next>")
390
+ .description("Set V2 budget status")
391
+ .action((id, next) => tryRun(() => out(true, setBudgetStatusV2(id, next))));
392
+
393
+ tokens
394
+ .command("activate-budget-v2 <id>")
395
+ .description("Activate a V2 budget")
396
+ .action((id) => tryRun(() => out(true, activateBudgetV2(id))));
397
+
398
+ tokens
399
+ .command("suspend-budget-v2 <id>")
400
+ .description("Suspend a V2 budget")
401
+ .action((id) => tryRun(() => out(true, suspendBudgetV2(id))));
402
+
403
+ tokens
404
+ .command("archive-budget-v2 <id>")
405
+ .description("Archive a V2 budget")
406
+ .action((id) => tryRun(() => out(true, archiveBudgetV2(id))));
407
+
408
+ tokens
409
+ .command("touch-budget-v2 <id>")
410
+ .description("Touch a V2 budget")
411
+ .action((id) => tryRun(() => out(true, touchBudgetV2(id))));
412
+
413
+ tokens
414
+ .command("create-usage-record-v2 <id>")
415
+ .description("Create a V2 usage record")
416
+ .requiredOption("-b, --budget <id>", "budget id")
417
+ .requiredOption("-u, --units <n>", "usage units")
418
+ .action((id, opts) =>
419
+ tryRun(() =>
420
+ out(
421
+ true,
422
+ createUsageRecordV2(id, {
423
+ budgetId: opts.budget,
424
+ units: Number(opts.units),
425
+ }),
426
+ ),
427
+ ),
428
+ );
429
+
430
+ tokens
431
+ .command("get-usage-record-v2 <id>")
432
+ .description("Get a V2 usage record")
433
+ .action((id) => out(true, getUsageRecordV2(id)));
434
+
435
+ tokens
436
+ .command("list-usage-records-v2")
437
+ .description("List V2 usage records")
438
+ .option("-b, --budget <id>", "filter by budget")
439
+ .option("-s, --status <status>", "filter by status")
440
+ .action((opts) =>
441
+ out(
442
+ true,
443
+ listUsageRecordsV2({ budgetId: opts.budget, status: opts.status }),
444
+ ),
445
+ );
446
+
447
+ tokens
448
+ .command("set-usage-record-status-v2 <id> <next>")
449
+ .description("Set V2 usage record status")
450
+ .action((id, next) =>
451
+ tryRun(() => out(true, setUsageRecordStatusV2(id, next))),
452
+ );
453
+
454
+ tokens
455
+ .command("record-usage-v2 <id>")
456
+ .description("Mark V2 usage record recorded")
457
+ .action((id) => tryRun(() => out(true, recordUsageV2(id))));
458
+
459
+ tokens
460
+ .command("bill-usage-v2 <id>")
461
+ .description("Bill V2 usage record")
462
+ .action((id) => tryRun(() => out(true, billUsageV2(id))));
463
+
464
+ tokens
465
+ .command("reject-usage-v2 <id>")
466
+ .description("Reject V2 usage record")
467
+ .action((id) => tryRun(() => out(true, rejectUsageV2(id))));
468
+
469
+ tokens
470
+ .command("refund-usage-v2 <id>")
471
+ .description("Refund V2 usage record")
472
+ .action((id) => tryRun(() => out(true, refundUsageV2(id))));
473
+
474
+ tokens
475
+ .command("auto-suspend-idle-budgets-v2")
476
+ .description("Auto-suspend idle V2 budgets")
477
+ .action(() => out(true, autoSuspendIdleBudgetsV2()));
478
+
479
+ tokens
480
+ .command("auto-reject-stale-records-v2")
481
+ .description("Auto-reject stale V2 records")
482
+ .action(() => out(true, autoRejectStaleRecordsV2()));
214
483
  }
@@ -27,8 +27,48 @@ import {
27
27
  listHsmDevices,
28
28
  signWithHsm,
29
29
  getTrustSecurityStats,
30
+ HSM_MATURITY_V2,
31
+ TRANSMISSION_V2,
32
+ getMaxActiveDevicesPerOperator,
33
+ setMaxActiveDevicesPerOperator,
34
+ getMaxPendingTransmissionsPerDevice,
35
+ setMaxPendingTransmissionsPerDevice,
36
+ getDeviceIdleMs,
37
+ setDeviceIdleMs,
38
+ getTransmissionStuckMs,
39
+ setTransmissionStuckMs,
40
+ getActiveDeviceCount,
41
+ getPendingTransmissionCount,
42
+ registerDeviceV2,
43
+ getDeviceV2,
44
+ listDevicesV2,
45
+ setDeviceMaturityV2,
46
+ activateDevice,
47
+ degradeDevice,
48
+ retireDevice,
49
+ touchDeviceUsage,
50
+ enqueueTransmissionV2,
51
+ getTransmissionV2,
52
+ listTransmissionsV2,
53
+ setTransmissionStatusV2,
54
+ startTransmission,
55
+ confirmTransmission,
56
+ failTransmission,
57
+ cancelTransmission,
58
+ autoRetireIdleDevices,
59
+ autoFailStuckTransmissions,
60
+ getTrustSecurityStatsV2,
30
61
  } from "../lib/trust-security.js";
31
62
 
63
+ function _parseJsonV2(s) {
64
+ if (!s) return undefined;
65
+ try {
66
+ return JSON.parse(s);
67
+ } catch {
68
+ throw new Error(`invalid JSON: ${s}`);
69
+ }
70
+ }
71
+
32
72
  function _dbFromCtx(cmd) {
33
73
  const root = cmd?.parent?.parent ?? cmd?.parent;
34
74
  return root?._db;
@@ -362,5 +402,214 @@ export function registerTrustCommand(program) {
362
402
  console.log(`HSM Devices: ${s.hsm.total}`);
363
403
  });
364
404
 
405
+ /* ── V2 Surface (Phase 68-71) ─────────────────────────── */
406
+
407
+ tr.command("hsm-maturities-v2")
408
+ .description("List HSM_MATURITY_V2 enum")
409
+ .action(() => {
410
+ for (const v of Object.values(HSM_MATURITY_V2)) console.log(` ${v}`);
411
+ });
412
+
413
+ tr.command("transmissions-v2")
414
+ .description("List TRANSMISSION_V2 enum")
415
+ .action(() => {
416
+ for (const v of Object.values(TRANSMISSION_V2)) console.log(` ${v}`);
417
+ });
418
+
419
+ tr.command("max-active-devices-per-operator")
420
+ .description("Get current max-active-devices-per-operator cap")
421
+ .action(() => console.log(getMaxActiveDevicesPerOperator()));
422
+ tr.command("set-max-active-devices-per-operator <n>").action((n) =>
423
+ console.log(setMaxActiveDevicesPerOperator(Number(n))),
424
+ );
425
+
426
+ tr.command("max-pending-transmissions-per-device")
427
+ .description("Get current max-pending-transmissions-per-device cap")
428
+ .action(() => console.log(getMaxPendingTransmissionsPerDevice()));
429
+ tr.command("set-max-pending-transmissions-per-device <n>").action((n) =>
430
+ console.log(setMaxPendingTransmissionsPerDevice(Number(n))),
431
+ );
432
+
433
+ tr.command("device-idle-ms")
434
+ .description("Get current device-idle-ms threshold")
435
+ .action(() => console.log(getDeviceIdleMs()));
436
+ tr.command("set-device-idle-ms <n>").action((n) =>
437
+ console.log(setDeviceIdleMs(Number(n))),
438
+ );
439
+
440
+ tr.command("transmission-stuck-ms")
441
+ .description("Get current transmission-stuck-ms threshold")
442
+ .action(() => console.log(getTransmissionStuckMs()));
443
+ tr.command("set-transmission-stuck-ms <n>").action((n) =>
444
+ console.log(setTransmissionStuckMs(Number(n))),
445
+ );
446
+
447
+ tr.command("active-device-count")
448
+ .description("Count active+degraded devices (optionally by operator)")
449
+ .option("-o, --operator <operator>", "scope to operator")
450
+ .action((opts) => console.log(getActiveDeviceCount(opts.operator)));
451
+
452
+ tr.command("pending-transmission-count")
453
+ .description("Count non-terminal transmissions (optionally by device)")
454
+ .option("-d, --device <device>", "scope to device")
455
+ .action((opts) => console.log(getPendingTransmissionCount(opts.device)));
456
+
457
+ tr.command("register-device-v2 <device-id>")
458
+ .description("Register V2 HSM device")
459
+ .requiredOption("-o, --operator <operator>", "operator id")
460
+ .requiredOption("-v, --vendor <vendor>", "HSM vendor")
461
+ .option(
462
+ "-i, --initial <status>",
463
+ "initial status",
464
+ HSM_MATURITY_V2.PROVISIONAL,
465
+ )
466
+ .option("--metadata <json>", "metadata JSON")
467
+ .action((id, opts) => {
468
+ const d = registerDeviceV2({
469
+ id,
470
+ operator: opts.operator,
471
+ vendor: opts.vendor,
472
+ initialStatus: opts.initial,
473
+ metadata: _parseJsonV2(opts.metadata),
474
+ });
475
+ console.log(JSON.stringify(d, null, 2));
476
+ });
477
+
478
+ tr.command("device-v2 <device-id>")
479
+ .description("Show V2 device")
480
+ .action((id) => {
481
+ const d = getDeviceV2(id);
482
+ if (!d) return console.error(`device ${id} not found`);
483
+ console.log(JSON.stringify(d, null, 2));
484
+ });
485
+
486
+ tr.command("list-devices-v2")
487
+ .description("List V2 devices")
488
+ .option("-o, --operator <operator>", "filter by operator")
489
+ .option("-s, --status <status>", "filter by status")
490
+ .action((opts) =>
491
+ console.log(JSON.stringify(listDevicesV2(opts), null, 2)),
492
+ );
493
+
494
+ tr.command("set-device-maturity-v2 <device-id> <status>")
495
+ .description("Transition V2 device maturity")
496
+ .option("-r, --reason <reason>", "transition reason")
497
+ .option("--metadata <json>", "metadata patch JSON")
498
+ .action((id, status, opts) => {
499
+ const d = setDeviceMaturityV2(id, status, {
500
+ reason: opts.reason,
501
+ metadata: _parseJsonV2(opts.metadata),
502
+ });
503
+ console.log(JSON.stringify(d, null, 2));
504
+ });
505
+
506
+ for (const [name, fn] of [
507
+ ["activate-device", activateDevice],
508
+ ["degrade-device", degradeDevice],
509
+ ["retire-device", retireDevice],
510
+ ]) {
511
+ tr.command(`${name} <device-id>`)
512
+ .description(`Shortcut for ${name.replace("-device", "")} transition`)
513
+ .option("-r, --reason <reason>", "transition reason")
514
+ .action((id, opts) => {
515
+ const d = fn(id, { reason: opts.reason });
516
+ console.log(JSON.stringify(d, null, 2));
517
+ });
518
+ }
519
+
520
+ tr.command("touch-device-usage <device-id>")
521
+ .description("Mark V2 device as used now")
522
+ .action((id) => {
523
+ const d = touchDeviceUsage(id);
524
+ console.log(JSON.stringify(d, null, 2));
525
+ });
526
+
527
+ tr.command("enqueue-transmission-v2 <transmission-id>")
528
+ .description("Enqueue V2 satellite transmission")
529
+ .requiredOption("-d, --device <device>", "device id")
530
+ .requiredOption("-p, --provider <provider>", "satellite provider")
531
+ .requiredOption("-x, --payload <payload>", "message payload")
532
+ .option("--metadata <json>", "metadata JSON")
533
+ .action((id, opts) => {
534
+ const t = enqueueTransmissionV2({
535
+ id,
536
+ deviceId: opts.device,
537
+ provider: opts.provider,
538
+ payload: opts.payload,
539
+ metadata: _parseJsonV2(opts.metadata),
540
+ });
541
+ console.log(JSON.stringify(t, null, 2));
542
+ });
543
+
544
+ tr.command("transmission-v2 <transmission-id>")
545
+ .description("Show V2 transmission")
546
+ .action((id) => {
547
+ const t = getTransmissionV2(id);
548
+ if (!t) return console.error(`transmission ${id} not found`);
549
+ console.log(JSON.stringify(t, null, 2));
550
+ });
551
+
552
+ tr.command("list-transmissions-v2")
553
+ .description("List V2 transmissions")
554
+ .option("-d, --device <device>", "filter by device")
555
+ .option("-s, --status <status>", "filter by status")
556
+ .action((opts) =>
557
+ console.log(JSON.stringify(listTransmissionsV2(opts), null, 2)),
558
+ );
559
+
560
+ tr.command("set-transmission-status-v2 <transmission-id> <status>")
561
+ .option("-r, --reason <reason>", "transition reason")
562
+ .option("--metadata <json>", "metadata patch JSON")
563
+ .action((id, status, opts) => {
564
+ const t = setTransmissionStatusV2(id, status, {
565
+ reason: opts.reason,
566
+ metadata: _parseJsonV2(opts.metadata),
567
+ });
568
+ console.log(JSON.stringify(t, null, 2));
569
+ });
570
+
571
+ for (const [name, fn] of [
572
+ ["start-transmission", startTransmission],
573
+ ["confirm-transmission", confirmTransmission],
574
+ ["fail-transmission", failTransmission],
575
+ ["cancel-transmission", cancelTransmission],
576
+ ]) {
577
+ tr.command(`${name} <transmission-id>`)
578
+ .description(
579
+ `Shortcut for ${name.replace("-transmission", "")} transition`,
580
+ )
581
+ .option("-r, --reason <reason>", "transition reason")
582
+ .action((id, opts) => {
583
+ const t = fn(id, { reason: opts.reason });
584
+ console.log(JSON.stringify(t, null, 2));
585
+ });
586
+ }
587
+
588
+ tr.command("auto-retire-idle-devices")
589
+ .description(
590
+ "Bulk-retire ACTIVE/DEGRADED devices whose lastUsedAt is older than deviceIdleMs",
591
+ )
592
+ .action(() =>
593
+ console.log(
594
+ JSON.stringify({ flipped: autoRetireIdleDevices() }, null, 2),
595
+ ),
596
+ );
597
+
598
+ tr.command("auto-fail-stuck-transmissions")
599
+ .description(
600
+ "Bulk-fail SENDING transmissions whose startedAt is older than transmissionStuckMs",
601
+ )
602
+ .action(() =>
603
+ console.log(
604
+ JSON.stringify({ flipped: autoFailStuckTransmissions() }, null, 2),
605
+ ),
606
+ );
607
+
608
+ tr.command("stats-v2")
609
+ .description("Show V2 trust/security stats")
610
+ .action(() =>
611
+ console.log(JSON.stringify(getTrustSecurityStatsV2(), null, 2)),
612
+ );
613
+
365
614
  program.addCommand(tr);
366
615
  }