chainlesschain 0.66.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 (143) hide show
  1. package/bin/chainlesschain.js +0 -0
  2. package/package.json +1 -1
  3. package/src/commands/a2a.js +380 -0
  4. package/src/commands/agent-network.js +254 -1
  5. package/src/commands/audit.js +302 -0
  6. package/src/commands/automation.js +271 -1
  7. package/src/commands/bi.js +348 -0
  8. package/src/commands/codegen.js +224 -0
  9. package/src/commands/collab.js +341 -0
  10. package/src/commands/compliance.js +1035 -0
  11. package/src/commands/cowork.js +221 -0
  12. package/src/commands/crosschain.js +218 -0
  13. package/src/commands/dbevo.js +284 -0
  14. package/src/commands/dev.js +252 -0
  15. package/src/commands/did.js +358 -0
  16. package/src/commands/dlp.js +341 -0
  17. package/src/commands/encrypt.js +341 -0
  18. package/src/commands/evomap.js +394 -0
  19. package/src/commands/export.js +256 -1
  20. package/src/commands/federation.js +283 -0
  21. package/src/commands/fusion.js +258 -0
  22. package/src/commands/governance.js +325 -0
  23. package/src/commands/hardening.js +411 -0
  24. package/src/commands/hook.js +148 -0
  25. package/src/commands/import.js +252 -0
  26. package/src/commands/incentive.js +322 -0
  27. package/src/commands/inference.js +318 -0
  28. package/src/commands/infra.js +244 -0
  29. package/src/commands/instinct.js +260 -0
  30. package/src/commands/ipfs.js +318 -0
  31. package/src/commands/kg.js +387 -0
  32. package/src/commands/llm.js +263 -0
  33. package/src/commands/lowcode.js +356 -0
  34. package/src/commands/marketplace.js +256 -0
  35. package/src/commands/mcp.js +221 -0
  36. package/src/commands/memory.js +248 -0
  37. package/src/commands/multimodal.js +296 -0
  38. package/src/commands/nlprog.js +356 -0
  39. package/src/commands/note.js +244 -0
  40. package/src/commands/ops.js +354 -0
  41. package/src/commands/orchestrate.js +166 -0
  42. package/src/commands/org.js +277 -0
  43. package/src/commands/p2p.js +390 -0
  44. package/src/commands/perception.js +290 -0
  45. package/src/commands/permmem.js +251 -0
  46. package/src/commands/plugin-ecosystem.js +273 -0
  47. package/src/commands/pqc.js +393 -0
  48. package/src/commands/privacy.js +321 -0
  49. package/src/commands/quantization.js +351 -0
  50. package/src/commands/rcache.js +271 -0
  51. package/src/commands/recommend.js +340 -0
  52. package/src/commands/reputation.js +261 -0
  53. package/src/commands/runtime.js +307 -0
  54. package/src/commands/scim.js +262 -0
  55. package/src/commands/session.js +258 -0
  56. package/src/commands/siem.js +246 -0
  57. package/src/commands/skill.js +267 -1
  58. package/src/commands/sla.js +259 -0
  59. package/src/commands/social.js +256 -0
  60. package/src/commands/sso.js +186 -1
  61. package/src/commands/stress.js +230 -0
  62. package/src/commands/sync.js +256 -0
  63. package/src/commands/tech.js +338 -0
  64. package/src/commands/tenant.js +351 -0
  65. package/src/commands/terraform.js +245 -0
  66. package/src/commands/tokens.js +269 -0
  67. package/src/commands/trust.js +249 -0
  68. package/src/commands/wallet.js +277 -0
  69. package/src/commands/workflow.js +171 -0
  70. package/src/commands/zkp.js +335 -0
  71. package/src/index.js +4 -0
  72. package/src/lib/a2a-protocol.js +451 -0
  73. package/src/lib/agent-coordinator.js +325 -0
  74. package/src/lib/agent-network.js +387 -0
  75. package/src/lib/agent-router.js +395 -0
  76. package/src/lib/aiops.js +478 -0
  77. package/src/lib/app-builder.js +239 -0
  78. package/src/lib/audit-logger.js +379 -0
  79. package/src/lib/automation-engine.js +330 -0
  80. package/src/lib/autonomous-developer.js +350 -0
  81. package/src/lib/bi-engine.js +338 -0
  82. package/src/lib/code-agent.js +323 -0
  83. package/src/lib/collaboration-governance.js +364 -0
  84. package/src/lib/community-governance.js +436 -0
  85. package/src/lib/compliance-manager.js +434 -0
  86. package/src/lib/content-recommendation.js +469 -0
  87. package/src/lib/cross-chain.js +345 -0
  88. package/src/lib/crypto-manager.js +350 -0
  89. package/src/lib/dbevo.js +338 -0
  90. package/src/lib/decentral-infra.js +340 -0
  91. package/src/lib/did-manager.js +367 -0
  92. package/src/lib/dlp-engine.js +389 -0
  93. package/src/lib/evomap-federation.js +177 -0
  94. package/src/lib/evomap-governance.js +276 -0
  95. package/src/lib/federation-hardening.js +259 -0
  96. package/src/lib/hardening-manager.js +348 -0
  97. package/src/lib/hook-manager.js +380 -0
  98. package/src/lib/inference-network.js +330 -0
  99. package/src/lib/instinct-manager.js +332 -0
  100. package/src/lib/ipfs-storage.js +334 -0
  101. package/src/lib/knowledge-exporter.js +381 -0
  102. package/src/lib/knowledge-graph.js +432 -0
  103. package/src/lib/knowledge-importer.js +379 -0
  104. package/src/lib/llm-providers.js +391 -0
  105. package/src/lib/mcp-registry.js +333 -0
  106. package/src/lib/memory-manager.js +330 -0
  107. package/src/lib/multimodal.js +346 -0
  108. package/src/lib/nl-programming.js +343 -0
  109. package/src/lib/note-versioning.js +327 -0
  110. package/src/lib/org-manager.js +323 -0
  111. package/src/lib/p2p-manager.js +387 -0
  112. package/src/lib/perception.js +346 -0
  113. package/src/lib/perf-tuning.js +4 -1
  114. package/src/lib/permanent-memory.js +320 -0
  115. package/src/lib/plugin-ecosystem.js +377 -0
  116. package/src/lib/pqc-manager.js +368 -0
  117. package/src/lib/privacy-computing.js +427 -0
  118. package/src/lib/protocol-fusion.js +417 -0
  119. package/src/lib/quantization.js +325 -0
  120. package/src/lib/reputation-optimizer.js +299 -0
  121. package/src/lib/response-cache.js +327 -0
  122. package/src/lib/scim-manager.js +329 -0
  123. package/src/lib/session-manager.js +329 -0
  124. package/src/lib/siem-exporter.js +333 -0
  125. package/src/lib/skill-loader.js +377 -0
  126. package/src/lib/skill-marketplace.js +325 -0
  127. package/src/lib/sla-manager.js +275 -0
  128. package/src/lib/social-manager.js +326 -0
  129. package/src/lib/sso-manager.js +332 -0
  130. package/src/lib/stress-tester.js +330 -0
  131. package/src/lib/sync-manager.js +326 -0
  132. package/src/lib/tech-learning-engine.js +369 -0
  133. package/src/lib/tenant-saas.js +460 -0
  134. package/src/lib/terraform-manager.js +363 -0
  135. package/src/lib/threat-intel.js +335 -0
  136. package/src/lib/token-incentive.js +293 -0
  137. package/src/lib/token-tracker.js +329 -0
  138. package/src/lib/trust-security.js +390 -0
  139. package/src/lib/ueba.js +389 -0
  140. package/src/lib/universal-runtime.js +325 -0
  141. package/src/lib/wallet-manager.js +326 -0
  142. package/src/lib/workflow-engine.js +322 -0
  143. package/src/lib/zkp-engine.js +274 -0
@@ -42,6 +42,33 @@ import {
42
42
  listIdentityMappings,
43
43
  checkIdentityConflict,
44
44
  getStats,
45
+ PROVIDER_MATURITY_V2 as PMV2,
46
+ LOGIN_LIFECYCLE_V2 as LLV2,
47
+ registerProviderV2,
48
+ activateProviderV2,
49
+ deprecateProviderV2,
50
+ retireProviderV2,
51
+ touchProviderV2,
52
+ getProviderV2,
53
+ listProvidersV2,
54
+ createLoginV2,
55
+ startLoginV2,
56
+ completeLoginV2,
57
+ failLoginV2,
58
+ cancelLoginV2,
59
+ getLoginV2,
60
+ listLoginsV2,
61
+ autoDeprecateIdleProvidersV2,
62
+ autoFailStuckLoginsV2,
63
+ getSsoManagerStatsV2,
64
+ setMaxActiveProvidersPerOwnerV2,
65
+ setMaxPendingLoginsPerProviderV2,
66
+ setProviderIdleMsV2,
67
+ setLoginStuckMsV2,
68
+ getMaxActiveProvidersPerOwnerV2,
69
+ getMaxPendingLoginsPerProviderV2,
70
+ getProviderIdleMsV2,
71
+ getLoginStuckMsV2,
45
72
  } from "../lib/sso-manager.js";
46
73
 
47
74
  function _dbFromCtx(cmd) {
@@ -76,7 +103,8 @@ export function registerSsoCommand(program) {
76
103
  .description(
77
104
  "SSO enterprise authentication — SAML / OAuth2 / OIDC (Phase 14)",
78
105
  )
79
- .hook("preAction", async (thisCommand) => {
106
+ .hook("preAction", async (thisCommand, actionCommand) => {
107
+ if (actionCommand && actionCommand.name().endsWith("-v2")) return;
80
108
  const db = await _prepare(thisCommand);
81
109
  thisCommand._db = db;
82
110
  });
@@ -795,4 +823,161 @@ export function registerSsoCommand(program) {
795
823
  await shutdown();
796
824
  }
797
825
  });
826
+
827
+ // ===== V2 Commands (cli 0.130.0) =====
828
+ const _v2json = (o) => console.log(JSON.stringify(o, null, 2));
829
+ sso
830
+ .command("provider-maturities-v2")
831
+ .description("List V2 provider maturity states")
832
+ .action(() => Object.values(PMV2).forEach((s) => console.log(s)));
833
+ sso
834
+ .command("login-lifecycles-v2")
835
+ .description("List V2 login lifecycle states")
836
+ .action(() => Object.values(LLV2).forEach((s) => console.log(s)));
837
+ sso
838
+ .command("stats-v2")
839
+ .description("V2 stats")
840
+ .action(() => _v2json(getSsoManagerStatsV2()));
841
+ sso
842
+ .command("config-v2")
843
+ .description("V2 config")
844
+ .action(() => {
845
+ console.log(
846
+ `maxActiveProvidersPerOwner: ${getMaxActiveProvidersPerOwnerV2()}`,
847
+ );
848
+ console.log(
849
+ `maxPendingLoginsPerProvider: ${getMaxPendingLoginsPerProviderV2()}`,
850
+ );
851
+ console.log(`providerIdleMs: ${getProviderIdleMsV2()}`);
852
+ console.log(`loginStuckMs: ${getLoginStuckMsV2()}`);
853
+ });
854
+ sso
855
+ .command("set-max-active-providers-v2 <n>")
856
+ .description("Set V2 active provider cap")
857
+ .action((n) => {
858
+ setMaxActiveProvidersPerOwnerV2(Number(n));
859
+ console.log("ok");
860
+ });
861
+ sso
862
+ .command("set-max-pending-logins-v2 <n>")
863
+ .description("Set V2 pending login cap")
864
+ .action((n) => {
865
+ setMaxPendingLoginsPerProviderV2(Number(n));
866
+ console.log("ok");
867
+ });
868
+ sso
869
+ .command("set-provider-idle-ms-v2 <n>")
870
+ .description("Set V2 provider idle ms")
871
+ .action((n) => {
872
+ setProviderIdleMsV2(Number(n));
873
+ console.log("ok");
874
+ });
875
+ sso
876
+ .command("set-login-stuck-ms-v2 <n>")
877
+ .description("Set V2 login stuck ms")
878
+ .action((n) => {
879
+ setLoginStuckMsV2(Number(n));
880
+ console.log("ok");
881
+ });
882
+ sso
883
+ .command("register-provider-v2 <id>")
884
+ .description("V2 register provider")
885
+ .requiredOption("-o, --owner <o>")
886
+ .requiredOption("-p, --protocol <p>")
887
+ .option("-d, --display-name <n>")
888
+ .action((id, opts) =>
889
+ _v2json(
890
+ registerProviderV2({
891
+ id,
892
+ owner: opts.owner,
893
+ protocol: opts.protocol,
894
+ displayName: opts.displayName,
895
+ }),
896
+ ),
897
+ );
898
+ sso
899
+ .command("activate-provider-v2 <id>")
900
+ .description("V2 activate provider")
901
+ .action((id) => _v2json(activateProviderV2(id)));
902
+ sso
903
+ .command("deprecate-provider-v2 <id>")
904
+ .description("V2 deprecate provider")
905
+ .action((id) => _v2json(deprecateProviderV2(id)));
906
+ sso
907
+ .command("retire-provider-v2 <id>")
908
+ .description("V2 retire provider")
909
+ .action((id) => _v2json(retireProviderV2(id)));
910
+ sso
911
+ .command("touch-provider-v2 <id>")
912
+ .description("V2 touch provider")
913
+ .action((id) => _v2json(touchProviderV2(id)));
914
+ sso
915
+ .command("get-provider-v2 <id>")
916
+ .description("V2 get provider")
917
+ .action((id) => _v2json(getProviderV2(id)));
918
+ sso
919
+ .command("list-providers-v2")
920
+ .description("V2 list providers")
921
+ .option("-o, --owner <o>")
922
+ .option("-s, --status <s>")
923
+ .option("-p, --protocol <p>")
924
+ .action((opts) => _v2json(listProvidersV2(opts)));
925
+ sso
926
+ .command("create-login-v2 <id>")
927
+ .description("V2 create login")
928
+ .requiredOption("-p, --provider-id <p>")
929
+ .option("-s, --subject <s>")
930
+ .action((id, opts) =>
931
+ _v2json(
932
+ createLoginV2({
933
+ id,
934
+ providerId: opts.providerId,
935
+ subject: opts.subject,
936
+ }),
937
+ ),
938
+ );
939
+ sso
940
+ .command("start-login-v2 <id>")
941
+ .description("V2 start login")
942
+ .action((id) => _v2json(startLoginV2(id)));
943
+ sso
944
+ .command("complete-login-v2 <id>")
945
+ .description("V2 complete login")
946
+ .action((id) => _v2json(completeLoginV2(id)));
947
+ sso
948
+ .command("fail-login-v2 <id>")
949
+ .description("V2 fail login")
950
+ .option("-e, --error <e>")
951
+ .action((id, opts) => _v2json(failLoginV2(id, opts.error)));
952
+ sso
953
+ .command("cancel-login-v2 <id>")
954
+ .description("V2 cancel login")
955
+ .action((id) => _v2json(cancelLoginV2(id)));
956
+ sso
957
+ .command("get-login-v2 <id>")
958
+ .description("V2 get login")
959
+ .action((id) => _v2json(getLoginV2(id)));
960
+ sso
961
+ .command("list-logins-v2")
962
+ .description("V2 list logins")
963
+ .option("-p, --provider-id <p>")
964
+ .option("-s, --status <s>")
965
+ .option("-S, --subject <s>")
966
+ .action((opts) =>
967
+ _v2json(
968
+ listLoginsV2({
969
+ providerId: opts.providerId,
970
+ status: opts.status,
971
+ subject: opts.subject,
972
+ }),
973
+ ),
974
+ );
975
+ sso
976
+ .command("auto-deprecate-idle-providers-v2")
977
+ .description("V2 auto-deprecate idle")
978
+ .action(() => _v2json(autoDeprecateIdleProvidersV2()));
979
+ sso
980
+ .command("auto-fail-stuck-logins-v2")
981
+ .description("V2 auto-fail stuck")
982
+ .action(() => _v2json(autoFailStuckLoginsV2()));
798
983
  }
@@ -15,6 +15,22 @@ import {
15
15
  analyzeBottlenecks,
16
16
  generateCapacityPlan,
17
17
  listLoadLevels,
18
+ // V2
19
+ RUN_STATUS_V2,
20
+ LEVEL_NAME_V2,
21
+ BOTTLENECK_KIND_V2,
22
+ BOTTLENECK_SEVERITY_V2,
23
+ STRESS_DEFAULT_MAX_CONCURRENT,
24
+ setMaxConcurrentTests,
25
+ getMaxConcurrentTests,
26
+ getActiveTestCount,
27
+ startStressTestV2,
28
+ completeStressTest,
29
+ stopStressTestV2,
30
+ failStressTest,
31
+ setRunStatus,
32
+ recommendLevelV2,
33
+ getStressStatsV2,
18
34
  } from "../lib/stress-tester.js";
19
35
 
20
36
  function _dbFromCtx(ctx) {
@@ -249,4 +265,218 @@ export function registerStressCommand(program) {
249
265
  }
250
266
  }
251
267
  });
268
+
269
+ // ---------- V2 (Phase 59) ----------
270
+ const withDb = async (fn) => {
271
+ const ctx = await bootstrap({ verbose: program.opts().verbose });
272
+ if (!ctx.db) {
273
+ logger.error("Database not available");
274
+ process.exit(1);
275
+ }
276
+ try {
277
+ const db = ctx.db.getDatabase();
278
+ ensureStressTables(db);
279
+ return await fn(db);
280
+ } finally {
281
+ await shutdown();
282
+ }
283
+ };
284
+
285
+ stress
286
+ .command("run-statuses")
287
+ .description("List RUN_STATUS_V2 values")
288
+ .action(() => {
289
+ console.log(JSON.stringify(Object.values(RUN_STATUS_V2), null, 2));
290
+ });
291
+
292
+ stress
293
+ .command("level-names")
294
+ .description("List LEVEL_NAME_V2 values")
295
+ .action(() => {
296
+ console.log(JSON.stringify(Object.values(LEVEL_NAME_V2), null, 2));
297
+ });
298
+
299
+ stress
300
+ .command("bottleneck-kinds")
301
+ .description("List BOTTLENECK_KIND_V2 values")
302
+ .action(() => {
303
+ console.log(JSON.stringify(Object.values(BOTTLENECK_KIND_V2), null, 2));
304
+ });
305
+
306
+ stress
307
+ .command("bottleneck-severities")
308
+ .description("List BOTTLENECK_SEVERITY_V2 values")
309
+ .action(() => {
310
+ console.log(
311
+ JSON.stringify(Object.values(BOTTLENECK_SEVERITY_V2), null, 2),
312
+ );
313
+ });
314
+
315
+ stress
316
+ .command("default-max-concurrent")
317
+ .description("Show STRESS_DEFAULT_MAX_CONCURRENT")
318
+ .action(() => {
319
+ console.log(STRESS_DEFAULT_MAX_CONCURRENT);
320
+ });
321
+
322
+ stress
323
+ .command("max-concurrent")
324
+ .description("Show current max concurrent test limit")
325
+ .action(() => {
326
+ console.log(getMaxConcurrentTests());
327
+ });
328
+
329
+ stress
330
+ .command("active-test-count")
331
+ .description("Show current active (RUNNING) test count")
332
+ .action(() => {
333
+ console.log(getActiveTestCount());
334
+ });
335
+
336
+ stress
337
+ .command("set-max-concurrent <n>")
338
+ .description("Set max concurrent test admission limit")
339
+ .action((n) => {
340
+ try {
341
+ const v = setMaxConcurrentTests(Number(n));
342
+ logger.success(`maxConcurrentTests=${v}`);
343
+ } catch (err) {
344
+ logger.error(`Failed: ${err.message}`);
345
+ process.exit(1);
346
+ }
347
+ });
348
+
349
+ stress
350
+ .command("start-v2")
351
+ .description("Start a V2 stress run (RUNNING, no metrics until complete)")
352
+ .option(
353
+ "-l, --level <level>",
354
+ "Load level (light|medium|heavy|extreme)",
355
+ "medium",
356
+ )
357
+ .option("-c, --concurrency <n>", "Override concurrency", parseInt)
358
+ .option("-r, --rps <n>", "Override requests per second", parseInt)
359
+ .option("-d, --duration <ms>", "Override duration in ms", parseInt)
360
+ .option("--json", "Output as JSON")
361
+ .action(async (options) => {
362
+ try {
363
+ await withDb((db) => {
364
+ const run = startStressTestV2(db, {
365
+ level: options.level,
366
+ concurrency: options.concurrency,
367
+ requestsPerSecond: options.rps,
368
+ duration: options.duration,
369
+ });
370
+ if (options.json) {
371
+ console.log(JSON.stringify(run, null, 2));
372
+ } else {
373
+ logger.success(
374
+ `Started ${run.testId.slice(0, 8)} [${run.loadLevel}] → ${run.status}`,
375
+ );
376
+ }
377
+ });
378
+ } catch (err) {
379
+ logger.error(`Failed: ${err.message}`);
380
+ process.exit(1);
381
+ }
382
+ });
383
+
384
+ stress
385
+ .command("complete <test-id>")
386
+ .description("Complete a RUNNING run and compute metrics")
387
+ .option("--json", "Output as JSON")
388
+ .action(async (testId, options) => {
389
+ try {
390
+ await withDb((db) => {
391
+ const r = completeStressTest(db, testId);
392
+ if (options.json) {
393
+ console.log(JSON.stringify(r, null, 2));
394
+ } else {
395
+ logger.success(
396
+ `${r.testId.slice(0, 8)} → ${r.status} (tps=${r.result.tps})`,
397
+ );
398
+ }
399
+ });
400
+ } catch (err) {
401
+ logger.error(`Failed: ${err.message}`);
402
+ process.exit(1);
403
+ }
404
+ });
405
+
406
+ stress
407
+ .command("stop-v2 <test-id>")
408
+ .description("Stop a RUNNING run (→ STOPPED)")
409
+ .action(async (testId) => {
410
+ try {
411
+ await withDb((db) => {
412
+ const r = stopStressTestV2(db, testId);
413
+ logger.success(`${r.testId.slice(0, 8)} → ${r.status}`);
414
+ });
415
+ } catch (err) {
416
+ logger.error(`Failed: ${err.message}`);
417
+ process.exit(1);
418
+ }
419
+ });
420
+
421
+ stress
422
+ .command("fail <test-id> <error-message>")
423
+ .description("Fail a RUNNING run with an error message (→ FAILED)")
424
+ .action(async (testId, errorMessage) => {
425
+ try {
426
+ await withDb((db) => {
427
+ const r = failStressTest(db, testId, errorMessage);
428
+ logger.success(
429
+ `${r.testId.slice(0, 8)} → ${r.status} (${r.errorMessage})`,
430
+ );
431
+ });
432
+ } catch (err) {
433
+ logger.error(`Failed: ${err.message}`);
434
+ process.exit(1);
435
+ }
436
+ });
437
+
438
+ stress
439
+ .command("set-status <test-id> <status>")
440
+ .description("Transition run to a given status (state-machine guarded)")
441
+ .option("--error-message <msg>", "Attach error message (for failed)")
442
+ .action(async (testId, status, options) => {
443
+ try {
444
+ await withDb((db) => {
445
+ const patch = {};
446
+ if (options.errorMessage) patch.errorMessage = options.errorMessage;
447
+ const r = setRunStatus(db, testId, status, patch);
448
+ logger.success(`${r.testId.slice(0, 8)} → ${r.status}`);
449
+ });
450
+ } catch (err) {
451
+ logger.error(`Failed: ${err.message}`);
452
+ process.exit(1);
453
+ }
454
+ });
455
+
456
+ stress
457
+ .command("recommend-level <target-rps>")
458
+ .description("Recommend the largest built-in level ≤ targetRps")
459
+ .option("--json", "Output as JSON")
460
+ .action((targetRps, options) => {
461
+ try {
462
+ const level = recommendLevelV2(Number(targetRps));
463
+ if (options.json) {
464
+ console.log(JSON.stringify(level, null, 2));
465
+ } else {
466
+ logger.log(
467
+ ` ${chalk.cyan(level.name)} concurrency=${level.concurrency} rps=${level.requestsPerSecond} duration=${level.duration}ms`,
468
+ );
469
+ }
470
+ } catch (err) {
471
+ logger.error(`Failed: ${err.message}`);
472
+ process.exit(1);
473
+ }
474
+ });
475
+
476
+ stress
477
+ .command("stats-v2")
478
+ .description("Show aggregate V2 stats (byStatus/byLevel/bottlenecks)")
479
+ .action(() => {
480
+ console.log(JSON.stringify(getStressStatsV2(), null, 2));
481
+ });
252
482
  }
@@ -16,6 +16,35 @@ import {
16
16
  clearSyncData,
17
17
  registerResource,
18
18
  getAllSyncStates,
19
+ RESOURCE_MATURITY_V2,
20
+ SYNC_RUN_V2,
21
+ getMaxActiveResourcesPerOwnerV2,
22
+ setMaxActiveResourcesPerOwnerV2,
23
+ getMaxRunningRunsPerResourceV2,
24
+ setMaxRunningRunsPerResourceV2,
25
+ getResourceIdleMsV2,
26
+ setResourceIdleMsV2,
27
+ getRunStuckMsV2,
28
+ setRunStuckMsV2,
29
+ getActiveResourceCountV2,
30
+ getRunningRunCountV2,
31
+ registerResourceV2,
32
+ getResourceV2,
33
+ listResourcesV2,
34
+ activateResourceV2,
35
+ pauseResourceV2,
36
+ archiveResourceV2,
37
+ touchResourceV2,
38
+ createSyncRunV2,
39
+ getSyncRunV2,
40
+ listSyncRunsV2,
41
+ startSyncRunV2,
42
+ succeedSyncRunV2,
43
+ failSyncRunV2,
44
+ cancelSyncRunV2,
45
+ autoArchiveIdleResourcesV2,
46
+ autoFailStuckSyncRunsV2,
47
+ getSyncManagerStatsV2,
19
48
  } from "../lib/sync-manager.js";
20
49
 
21
50
  export function registerSyncCommand(program) {
@@ -246,4 +275,231 @@ export function registerSyncCommand(program) {
246
275
  process.exit(1);
247
276
  }
248
277
  });
278
+
279
+ // ─────────────────────────────────────────────────────────────
280
+ // V2 Surface — resource + sync-run lifecycle (in-memory, throwing API)
281
+ // ─────────────────────────────────────────────────────────────
282
+
283
+ sync
284
+ .command("resource-maturities-v2")
285
+ .description("List V2 resource maturity states")
286
+ .option("--json", "Output as JSON")
287
+ .action((options) => {
288
+ const v = Object.values(RESOURCE_MATURITY_V2);
289
+ if (options.json) console.log(JSON.stringify(v));
290
+ else logger.log(v.join(", "));
291
+ });
292
+
293
+ sync
294
+ .command("run-lifecycles-v2")
295
+ .description("List V2 sync-run lifecycle states")
296
+ .option("--json", "Output as JSON")
297
+ .action((options) => {
298
+ const v = Object.values(SYNC_RUN_V2);
299
+ if (options.json) console.log(JSON.stringify(v));
300
+ else logger.log(v.join(", "));
301
+ });
302
+
303
+ sync
304
+ .command("stats-v2")
305
+ .description("Show V2 sync stats")
306
+ .option("--json", "Output as JSON")
307
+ .action((options) => {
308
+ const stats = getSyncManagerStatsV2();
309
+ if (options.json) console.log(JSON.stringify(stats, null, 2));
310
+ else logger.log(JSON.stringify(stats, null, 2));
311
+ });
312
+
313
+ sync
314
+ .command("get-max-active-resources-v2")
315
+ .description("Get max active resources per owner")
316
+ .action(() => logger.log(String(getMaxActiveResourcesPerOwnerV2())));
317
+ sync
318
+ .command("set-max-active-resources-v2 <n>")
319
+ .description("Set max active resources per owner")
320
+ .action((n) => {
321
+ setMaxActiveResourcesPerOwnerV2(Number(n));
322
+ logger.log(String(getMaxActiveResourcesPerOwnerV2()));
323
+ });
324
+ sync
325
+ .command("get-max-running-runs-v2")
326
+ .description("Get max running runs per resource")
327
+ .action(() => logger.log(String(getMaxRunningRunsPerResourceV2())));
328
+ sync
329
+ .command("set-max-running-runs-v2 <n>")
330
+ .description("Set max running runs per resource")
331
+ .action((n) => {
332
+ setMaxRunningRunsPerResourceV2(Number(n));
333
+ logger.log(String(getMaxRunningRunsPerResourceV2()));
334
+ });
335
+ sync
336
+ .command("get-resource-idle-ms-v2")
337
+ .description("Get resource idle ms")
338
+ .action(() => logger.log(String(getResourceIdleMsV2())));
339
+ sync
340
+ .command("set-resource-idle-ms-v2 <ms>")
341
+ .description("Set resource idle ms")
342
+ .action((ms) => {
343
+ setResourceIdleMsV2(Number(ms));
344
+ logger.log(String(getResourceIdleMsV2()));
345
+ });
346
+ sync
347
+ .command("get-run-stuck-ms-v2")
348
+ .description("Get run stuck ms")
349
+ .action(() => logger.log(String(getRunStuckMsV2())));
350
+ sync
351
+ .command("set-run-stuck-ms-v2 <ms>")
352
+ .description("Set run stuck ms")
353
+ .action((ms) => {
354
+ setRunStuckMsV2(Number(ms));
355
+ logger.log(String(getRunStuckMsV2()));
356
+ });
357
+
358
+ sync
359
+ .command("active-resource-count-v2 <owner>")
360
+ .description("Count active resources for owner")
361
+ .action((owner) => logger.log(String(getActiveResourceCountV2(owner))));
362
+ sync
363
+ .command("running-run-count-v2 <resourceId>")
364
+ .description("Count running runs for resource")
365
+ .action((resourceId) =>
366
+ logger.log(String(getRunningRunCountV2(resourceId))),
367
+ );
368
+
369
+ sync
370
+ .command("register-resource-v2 <id>")
371
+ .description("Register V2 resource (initial=pending)")
372
+ .requiredOption("-o, --owner <owner>", "owner")
373
+ .requiredOption("-k, --kind <kind>", "kind (file/note/...)")
374
+ .option("-m, --metadata <json>", "metadata JSON", "{}")
375
+ .action((id, opts) => {
376
+ const meta = JSON.parse(opts.metadata);
377
+ const r = registerResourceV2(id, {
378
+ owner: opts.owner,
379
+ kind: opts.kind,
380
+ metadata: meta,
381
+ });
382
+ console.log(JSON.stringify(r, null, 2));
383
+ });
384
+
385
+ sync
386
+ .command("get-resource-v2 <id>")
387
+ .description("Get V2 resource by id")
388
+ .action((id) => {
389
+ const r = getResourceV2(id);
390
+ if (!r) {
391
+ logger.error(`resource ${id} not found`);
392
+ process.exit(1);
393
+ }
394
+ console.log(JSON.stringify(r, null, 2));
395
+ });
396
+
397
+ sync
398
+ .command("list-resources-v2")
399
+ .description("List V2 resources")
400
+ .option("-o, --owner <owner>", "filter by owner")
401
+ .option("-k, --kind <kind>", "filter by kind")
402
+ .option("-s, --status <state>", "filter by status")
403
+ .action((opts) => {
404
+ const out = listResourcesV2({
405
+ owner: opts.owner,
406
+ kind: opts.kind,
407
+ status: opts.status,
408
+ });
409
+ console.log(JSON.stringify(out, null, 2));
410
+ });
411
+
412
+ sync
413
+ .command("activate-resource-v2 <id>")
414
+ .description("Transition resource → active")
415
+ .action((id) =>
416
+ console.log(JSON.stringify(activateResourceV2(id), null, 2)),
417
+ );
418
+ sync
419
+ .command("pause-resource-v2 <id>")
420
+ .description("Transition resource → paused")
421
+ .action((id) => console.log(JSON.stringify(pauseResourceV2(id), null, 2)));
422
+ sync
423
+ .command("archive-resource-v2 <id>")
424
+ .description("Transition resource → archived (terminal)")
425
+ .action((id) =>
426
+ console.log(JSON.stringify(archiveResourceV2(id), null, 2)),
427
+ );
428
+ sync
429
+ .command("touch-resource-v2 <id>")
430
+ .description("Update resource lastSeenAt")
431
+ .action((id) => console.log(JSON.stringify(touchResourceV2(id), null, 2)));
432
+
433
+ sync
434
+ .command("create-sync-run-v2 <id>")
435
+ .description("Create V2 sync run (initial=queued)")
436
+ .requiredOption("-r, --resource <id>", "resource id")
437
+ .option("-k, --kind <kind>", "run kind", "push")
438
+ .option("-m, --metadata <json>", "metadata JSON", "{}")
439
+ .action((id, opts) => {
440
+ const meta = JSON.parse(opts.metadata);
441
+ const j = createSyncRunV2(id, {
442
+ resourceId: opts.resource,
443
+ kind: opts.kind,
444
+ metadata: meta,
445
+ });
446
+ console.log(JSON.stringify(j, null, 2));
447
+ });
448
+
449
+ sync
450
+ .command("get-sync-run-v2 <id>")
451
+ .description("Get V2 sync run by id")
452
+ .action((id) => {
453
+ const j = getSyncRunV2(id);
454
+ if (!j) {
455
+ logger.error(`syncRun ${id} not found`);
456
+ process.exit(1);
457
+ }
458
+ console.log(JSON.stringify(j, null, 2));
459
+ });
460
+
461
+ sync
462
+ .command("list-sync-runs-v2")
463
+ .description("List V2 sync runs")
464
+ .option("-r, --resource <id>", "filter by resource")
465
+ .option("-s, --status <state>", "filter by status")
466
+ .action((opts) => {
467
+ const out = listSyncRunsV2({
468
+ resourceId: opts.resource,
469
+ status: opts.status,
470
+ });
471
+ console.log(JSON.stringify(out, null, 2));
472
+ });
473
+
474
+ sync
475
+ .command("start-sync-run-v2 <id>")
476
+ .description("Transition sync run → running")
477
+ .action((id) => console.log(JSON.stringify(startSyncRunV2(id), null, 2)));
478
+ sync
479
+ .command("succeed-sync-run-v2 <id>")
480
+ .description("Transition sync run → succeeded (terminal)")
481
+ .action((id) => console.log(JSON.stringify(succeedSyncRunV2(id), null, 2)));
482
+ sync
483
+ .command("fail-sync-run-v2 <id>")
484
+ .description("Transition sync run → failed (terminal)")
485
+ .action((id) => console.log(JSON.stringify(failSyncRunV2(id), null, 2)));
486
+ sync
487
+ .command("cancel-sync-run-v2 <id>")
488
+ .description("Transition sync run → cancelled (terminal)")
489
+ .action((id) => console.log(JSON.stringify(cancelSyncRunV2(id), null, 2)));
490
+
491
+ sync
492
+ .command("auto-archive-idle-v2")
493
+ .description("Auto-archive idle resources; output flipped")
494
+ .action(() => {
495
+ const flipped = autoArchiveIdleResourcesV2();
496
+ console.log(JSON.stringify(flipped, null, 2));
497
+ });
498
+ sync
499
+ .command("auto-fail-stuck-runs-v2")
500
+ .description("Auto-fail stuck running syncs; output flipped")
501
+ .action(() => {
502
+ const flipped = autoFailStuckSyncRunsV2();
503
+ console.log(JSON.stringify(flipped, null, 2));
504
+ });
249
505
  }