chainlesschain 0.143.0 → 0.152.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 (227) hide show
  1. package/package.json +1 -1
  2. package/src/commands/a2a.js +196 -28
  3. package/src/commands/activitypub.js +364 -27
  4. package/src/commands/agent-network.js +217 -0
  5. package/src/commands/agent.js +587 -103
  6. package/src/commands/audit.js +206 -0
  7. package/src/commands/automation.js +201 -0
  8. package/src/commands/bi.js +355 -27
  9. package/src/commands/bm25.js +111 -27
  10. package/src/commands/browse.js +403 -29
  11. package/src/commands/ccron.js +128 -28
  12. package/src/commands/chat.js +207 -0
  13. package/src/commands/codegen.js +207 -0
  14. package/src/commands/collab.js +211 -0
  15. package/src/commands/compliance.js +824 -34
  16. package/src/commands/compt.js +127 -29
  17. package/src/commands/consol.js +8 -2
  18. package/src/commands/cowork.js +783 -34
  19. package/src/commands/crosschain.js +182 -28
  20. package/src/commands/dao.js +182 -28
  21. package/src/commands/dbevo.js +227 -0
  22. package/src/commands/dev.js +207 -0
  23. package/src/commands/did-v2.js +217 -0
  24. package/src/commands/did.js +221 -0
  25. package/src/commands/dlp.js +385 -27
  26. package/src/commands/economy.js +205 -50
  27. package/src/commands/evolution.js +203 -50
  28. package/src/commands/evomap.js +387 -27
  29. package/src/commands/export.js +213 -0
  30. package/src/commands/federation.js +209 -0
  31. package/src/commands/fflag.js +74 -22
  32. package/src/commands/fusion.js +205 -0
  33. package/src/commands/git.js +177 -37
  34. package/src/commands/governance.js +209 -0
  35. package/src/commands/hardening.js +209 -0
  36. package/src/commands/hmemory.js +204 -50
  37. package/src/commands/hook.js +209 -0
  38. package/src/commands/import.js +209 -0
  39. package/src/commands/incentive.js +209 -0
  40. package/src/commands/inference.js +170 -34
  41. package/src/commands/infra.js +203 -0
  42. package/src/commands/instinct.js +209 -0
  43. package/src/commands/ipfs.js +207 -0
  44. package/src/commands/itbudget.js +149 -33
  45. package/src/commands/kg.js +206 -0
  46. package/src/commands/llm.js +217 -0
  47. package/src/commands/lowcode.js +195 -38
  48. package/src/commands/marketplace.js +206 -0
  49. package/src/commands/matrix.js +386 -27
  50. package/src/commands/mcp.js +217 -0
  51. package/src/commands/mcpscaf.js +145 -33
  52. package/src/commands/meminj.js +145 -33
  53. package/src/commands/memory.js +209 -0
  54. package/src/commands/multimodal.js +203 -0
  55. package/src/commands/nlprog.js +225 -0
  56. package/src/commands/nostr.js +387 -27
  57. package/src/commands/note.js +205 -0
  58. package/src/commands/ops.js +219 -0
  59. package/src/commands/orchestrate.js +217 -0
  60. package/src/commands/orchgov.js +144 -33
  61. package/src/commands/org.js +209 -0
  62. package/src/commands/p2p.js +209 -0
  63. package/src/commands/pdfp.js +109 -27
  64. package/src/commands/perception.js +209 -0
  65. package/src/commands/perf.js +169 -32
  66. package/src/commands/perm.js +144 -33
  67. package/src/commands/permmem.js +203 -0
  68. package/src/commands/pipeline.js +207 -52
  69. package/src/commands/planmode.js +141 -32
  70. package/src/commands/plugin-ecosystem.js +209 -0
  71. package/src/commands/pqc.js +213 -0
  72. package/src/commands/privacy.js +203 -0
  73. package/src/commands/promcomp.js +111 -27
  74. package/src/commands/quantization.js +207 -0
  75. package/src/commands/rcache.js +205 -0
  76. package/src/commands/recommend.js +410 -34
  77. package/src/commands/reputation.js +208 -0
  78. package/src/commands/runtime.js +205 -0
  79. package/src/commands/sandbox.js +206 -0
  80. package/src/commands/scim.js +209 -0
  81. package/src/commands/seshhook.js +145 -33
  82. package/src/commands/seshsearch.js +141 -33
  83. package/src/commands/seshtail.js +144 -33
  84. package/src/commands/seshu.js +152 -33
  85. package/src/commands/session.js +209 -0
  86. package/src/commands/sganal.js +123 -29
  87. package/src/commands/siem.js +201 -34
  88. package/src/commands/skill.js +207 -0
  89. package/src/commands/sla.js +212 -0
  90. package/src/commands/slotfill.js +146 -33
  91. package/src/commands/social.js +358 -32
  92. package/src/commands/sso.js +209 -0
  93. package/src/commands/stress.js +206 -0
  94. package/src/commands/svccont.js +145 -33
  95. package/src/commands/sync.js +209 -0
  96. package/src/commands/tech.js +209 -0
  97. package/src/commands/tenant.js +217 -0
  98. package/src/commands/terraform.js +206 -0
  99. package/src/commands/tms.js +171 -33
  100. package/src/commands/tokens.js +209 -0
  101. package/src/commands/topiccls.js +146 -33
  102. package/src/commands/trust.js +217 -0
  103. package/src/commands/uprof.js +141 -32
  104. package/src/commands/vcheck.js +122 -28
  105. package/src/commands/wallet.js +209 -0
  106. package/src/commands/webfetch.js +141 -32
  107. package/src/commands/workflow.js +203 -0
  108. package/src/commands/zkp.js +184 -28
  109. package/src/index.js +180 -0
  110. package/src/lib/a2a-protocol.js +319 -51
  111. package/src/lib/activitypub-bridge.js +622 -50
  112. package/src/lib/agent-economy.js +304 -51
  113. package/src/lib/agent-network.js +341 -0
  114. package/src/lib/aiops.js +346 -0
  115. package/src/lib/app-builder.js +279 -46
  116. package/src/lib/audit-logger.js +321 -0
  117. package/src/lib/automation-engine.js +335 -0
  118. package/src/lib/autonomous-agent.js +284 -48
  119. package/src/lib/autonomous-developer.js +332 -0
  120. package/src/lib/bi-engine.js +616 -49
  121. package/src/lib/bm25-search.js +301 -49
  122. package/src/lib/browser-automation.js +630 -49
  123. package/src/lib/chat-core.js +336 -0
  124. package/src/lib/claude-code-bridge.js +341 -0
  125. package/src/lib/code-agent.js +339 -0
  126. package/src/lib/collaboration-governance.js +334 -0
  127. package/src/lib/community-governance.js +346 -0
  128. package/src/lib/compliance-framework-reporter.js +305 -51
  129. package/src/lib/compliance-manager.js +330 -0
  130. package/src/lib/compression-telemetry.js +301 -49
  131. package/src/lib/content-recommendation.js +351 -0
  132. package/src/lib/content-recommender.js +317 -52
  133. package/src/lib/cowork-cron.js +298 -49
  134. package/src/lib/cowork-learning.js +333 -0
  135. package/src/lib/cowork-share.js +338 -0
  136. package/src/lib/cowork-task-runner.js +308 -51
  137. package/src/lib/cowork-workflow.js +327 -0
  138. package/src/lib/cross-chain.js +311 -51
  139. package/src/lib/dao-governance.js +280 -46
  140. package/src/lib/dbevo.js +351 -0
  141. package/src/lib/decentral-infra.js +330 -0
  142. package/src/lib/did-manager.js +341 -0
  143. package/src/lib/did-v2-manager.js +341 -0
  144. package/src/lib/dlp-engine.js +626 -49
  145. package/src/lib/evolution-system.js +278 -47
  146. package/src/lib/evomap-governance.js +334 -0
  147. package/src/lib/evomap-manager.js +280 -46
  148. package/src/lib/execution-backend.js +294 -48
  149. package/src/lib/feature-flags.js +294 -49
  150. package/src/lib/federation-hardening.js +340 -0
  151. package/src/lib/git-integration.js +285 -47
  152. package/src/lib/hardening-manager.js +341 -0
  153. package/src/lib/hierarchical-memory.js +284 -48
  154. package/src/lib/hook-manager.js +341 -0
  155. package/src/lib/inference-network.js +308 -51
  156. package/src/lib/instinct-manager.js +346 -0
  157. package/src/lib/ipfs-storage.js +334 -0
  158. package/src/lib/iteration-budget.js +302 -50
  159. package/src/lib/knowledge-exporter.js +341 -0
  160. package/src/lib/knowledge-graph.js +333 -0
  161. package/src/lib/knowledge-importer.js +341 -0
  162. package/src/lib/llm-providers.js +346 -0
  163. package/src/lib/matrix-bridge.js +620 -47
  164. package/src/lib/mcp-registry.js +346 -0
  165. package/src/lib/mcp-scaffold.js +318 -54
  166. package/src/lib/memory-injection.js +288 -49
  167. package/src/lib/memory-manager.js +336 -0
  168. package/src/lib/multimodal.js +330 -0
  169. package/src/lib/nl-programming.js +341 -0
  170. package/src/lib/nostr-bridge.js +622 -49
  171. package/src/lib/note-versioning.js +339 -0
  172. package/src/lib/orchestrator.js +293 -48
  173. package/src/lib/org-manager.js +336 -0
  174. package/src/lib/p2p-manager.js +341 -0
  175. package/src/lib/pdf-parser.js +298 -49
  176. package/src/lib/perception.js +346 -0
  177. package/src/lib/perf-tuning.js +309 -50
  178. package/src/lib/permanent-memory.js +327 -0
  179. package/src/lib/permission-engine.js +287 -49
  180. package/src/lib/pipeline-orchestrator.js +289 -49
  181. package/src/lib/plan-mode.js +298 -51
  182. package/src/lib/plugin-ecosystem.js +346 -0
  183. package/src/lib/pqc-manager.js +346 -0
  184. package/src/lib/privacy-computing.js +335 -0
  185. package/src/lib/protocol-fusion.js +338 -0
  186. package/src/lib/quantization.js +337 -0
  187. package/src/lib/reputation-optimizer.js +340 -0
  188. package/src/lib/response-cache.js +333 -0
  189. package/src/lib/sandbox-v2.js +327 -0
  190. package/src/lib/scim-manager.js +346 -0
  191. package/src/lib/service-container.js +313 -52
  192. package/src/lib/session-consolidator.js +296 -49
  193. package/src/lib/session-hooks.js +312 -53
  194. package/src/lib/session-manager.js +334 -0
  195. package/src/lib/session-search.js +304 -51
  196. package/src/lib/session-tail.js +288 -49
  197. package/src/lib/session-usage.js +298 -52
  198. package/src/lib/siem-exporter.js +298 -51
  199. package/src/lib/skill-loader.js +334 -0
  200. package/src/lib/skill-marketplace.js +345 -0
  201. package/src/lib/sla-manager.js +341 -0
  202. package/src/lib/slot-filler.js +303 -51
  203. package/src/lib/social-graph-analytics.js +295 -49
  204. package/src/lib/social-graph.js +272 -49
  205. package/src/lib/social-manager.js +330 -0
  206. package/src/lib/sso-manager.js +340 -0
  207. package/src/lib/stress-tester.js +342 -0
  208. package/src/lib/sub-agent-registry.js +302 -53
  209. package/src/lib/sync-manager.js +336 -0
  210. package/src/lib/task-model-selector.js +302 -50
  211. package/src/lib/tech-learning-engine.js +341 -0
  212. package/src/lib/tenant-saas.js +341 -0
  213. package/src/lib/terraform-manager.js +333 -0
  214. package/src/lib/threat-intel.js +330 -0
  215. package/src/lib/todo-manager.js +281 -47
  216. package/src/lib/token-incentive.js +341 -0
  217. package/src/lib/token-tracker.js +336 -0
  218. package/src/lib/topic-classifier.js +297 -49
  219. package/src/lib/trust-security.js +343 -0
  220. package/src/lib/ueba.js +340 -0
  221. package/src/lib/universal-runtime.js +330 -0
  222. package/src/lib/user-profile.js +294 -50
  223. package/src/lib/version-checker.js +304 -50
  224. package/src/lib/wallet-manager.js +336 -0
  225. package/src/lib/web-fetch.js +292 -51
  226. package/src/lib/workflow-engine.js +330 -0
  227. package/src/lib/zkp-engine.js +286 -49
@@ -599,25 +599,62 @@ export function _resetState() {
599
599
  _customTemplates.clear();
600
600
  }
601
601
 
602
-
603
602
  // ===== V2 Surface: Compliance Framework Reporter governance overlay (CLI v0.138.0) =====
604
603
  export const COMPLIANCE_FW_MATURITY_V2 = Object.freeze({
605
- PENDING: "pending", ACTIVE: "active", DEPRECATED: "deprecated", ARCHIVED: "archived",
604
+ PENDING: "pending",
605
+ ACTIVE: "active",
606
+ DEPRECATED: "deprecated",
607
+ ARCHIVED: "archived",
606
608
  });
607
609
  export const COMPLIANCE_FW_REPORT_LIFECYCLE_V2 = Object.freeze({
608
- QUEUED: "queued", GENERATING: "generating", COMPLETED: "completed", FAILED: "failed", CANCELLED: "cancelled",
610
+ QUEUED: "queued",
611
+ GENERATING: "generating",
612
+ COMPLETED: "completed",
613
+ FAILED: "failed",
614
+ CANCELLED: "cancelled",
609
615
  });
610
616
 
611
617
  const _cfwTrans = new Map([
612
- [COMPLIANCE_FW_MATURITY_V2.PENDING, new Set([COMPLIANCE_FW_MATURITY_V2.ACTIVE, COMPLIANCE_FW_MATURITY_V2.ARCHIVED])],
613
- [COMPLIANCE_FW_MATURITY_V2.ACTIVE, new Set([COMPLIANCE_FW_MATURITY_V2.DEPRECATED, COMPLIANCE_FW_MATURITY_V2.ARCHIVED])],
614
- [COMPLIANCE_FW_MATURITY_V2.DEPRECATED, new Set([COMPLIANCE_FW_MATURITY_V2.ACTIVE, COMPLIANCE_FW_MATURITY_V2.ARCHIVED])],
618
+ [
619
+ COMPLIANCE_FW_MATURITY_V2.PENDING,
620
+ new Set([
621
+ COMPLIANCE_FW_MATURITY_V2.ACTIVE,
622
+ COMPLIANCE_FW_MATURITY_V2.ARCHIVED,
623
+ ]),
624
+ ],
625
+ [
626
+ COMPLIANCE_FW_MATURITY_V2.ACTIVE,
627
+ new Set([
628
+ COMPLIANCE_FW_MATURITY_V2.DEPRECATED,
629
+ COMPLIANCE_FW_MATURITY_V2.ARCHIVED,
630
+ ]),
631
+ ],
632
+ [
633
+ COMPLIANCE_FW_MATURITY_V2.DEPRECATED,
634
+ new Set([
635
+ COMPLIANCE_FW_MATURITY_V2.ACTIVE,
636
+ COMPLIANCE_FW_MATURITY_V2.ARCHIVED,
637
+ ]),
638
+ ],
615
639
  [COMPLIANCE_FW_MATURITY_V2.ARCHIVED, new Set()],
616
640
  ]);
617
641
  const _cfwTerminal = new Set([COMPLIANCE_FW_MATURITY_V2.ARCHIVED]);
618
642
  const _cfwRepTrans = new Map([
619
- [COMPLIANCE_FW_REPORT_LIFECYCLE_V2.QUEUED, new Set([COMPLIANCE_FW_REPORT_LIFECYCLE_V2.GENERATING, COMPLIANCE_FW_REPORT_LIFECYCLE_V2.CANCELLED])],
620
- [COMPLIANCE_FW_REPORT_LIFECYCLE_V2.GENERATING, new Set([COMPLIANCE_FW_REPORT_LIFECYCLE_V2.COMPLETED, COMPLIANCE_FW_REPORT_LIFECYCLE_V2.FAILED, COMPLIANCE_FW_REPORT_LIFECYCLE_V2.CANCELLED])],
643
+ [
644
+ COMPLIANCE_FW_REPORT_LIFECYCLE_V2.QUEUED,
645
+ new Set([
646
+ COMPLIANCE_FW_REPORT_LIFECYCLE_V2.GENERATING,
647
+ COMPLIANCE_FW_REPORT_LIFECYCLE_V2.CANCELLED,
648
+ ]),
649
+ ],
650
+ [
651
+ COMPLIANCE_FW_REPORT_LIFECYCLE_V2.GENERATING,
652
+ new Set([
653
+ COMPLIANCE_FW_REPORT_LIFECYCLE_V2.COMPLETED,
654
+ COMPLIANCE_FW_REPORT_LIFECYCLE_V2.FAILED,
655
+ COMPLIANCE_FW_REPORT_LIFECYCLE_V2.CANCELLED,
656
+ ]),
657
+ ],
621
658
  [COMPLIANCE_FW_REPORT_LIFECYCLE_V2.COMPLETED, new Set()],
622
659
  [COMPLIANCE_FW_REPORT_LIFECYCLE_V2.FAILED, new Set()],
623
660
  [COMPLIANCE_FW_REPORT_LIFECYCLE_V2.CANCELLED, new Set()],
@@ -630,76 +667,293 @@ let _cfwMaxPendingReportsPerFw = 15;
630
667
  let _cfwIdleMs = 90 * 24 * 60 * 60 * 1000;
631
668
  let _cfwReportStuckMs = 10 * 60 * 1000;
632
669
 
633
- function _cfwPos(n, lbl) { const v = Math.floor(Number(n)); if (!Number.isFinite(v) || v <= 0) throw new Error(`${lbl} must be positive integer`); return v; }
670
+ function _cfwPos(n, lbl) {
671
+ const v = Math.floor(Number(n));
672
+ if (!Number.isFinite(v) || v <= 0)
673
+ throw new Error(`${lbl} must be positive integer`);
674
+ return v;
675
+ }
634
676
 
635
- export function setMaxActiveComplianceFwsPerOwnerV2(n) { _cfwMaxActivePerOwner = _cfwPos(n, "maxActiveComplianceFwsPerOwner"); }
636
- export function getMaxActiveComplianceFwsPerOwnerV2() { return _cfwMaxActivePerOwner; }
637
- export function setMaxPendingComplianceFwReportsPerFwV2(n) { _cfwMaxPendingReportsPerFw = _cfwPos(n, "maxPendingComplianceFwReportsPerFw"); }
638
- export function getMaxPendingComplianceFwReportsPerFwV2() { return _cfwMaxPendingReportsPerFw; }
639
- export function setComplianceFwIdleMsV2(n) { _cfwIdleMs = _cfwPos(n, "complianceFwIdleMs"); }
640
- export function getComplianceFwIdleMsV2() { return _cfwIdleMs; }
641
- export function setComplianceFwReportStuckMsV2(n) { _cfwReportStuckMs = _cfwPos(n, "complianceFwReportStuckMs"); }
642
- export function getComplianceFwReportStuckMsV2() { return _cfwReportStuckMs; }
677
+ export function setMaxActiveComplianceFwsPerOwnerV2(n) {
678
+ _cfwMaxActivePerOwner = _cfwPos(n, "maxActiveComplianceFwsPerOwner");
679
+ }
680
+ export function getMaxActiveComplianceFwsPerOwnerV2() {
681
+ return _cfwMaxActivePerOwner;
682
+ }
683
+ export function setMaxPendingComplianceFwReportsPerFwV2(n) {
684
+ _cfwMaxPendingReportsPerFw = _cfwPos(n, "maxPendingComplianceFwReportsPerFw");
685
+ }
686
+ export function getMaxPendingComplianceFwReportsPerFwV2() {
687
+ return _cfwMaxPendingReportsPerFw;
688
+ }
689
+ export function setComplianceFwIdleMsV2(n) {
690
+ _cfwIdleMs = _cfwPos(n, "complianceFwIdleMs");
691
+ }
692
+ export function getComplianceFwIdleMsV2() {
693
+ return _cfwIdleMs;
694
+ }
695
+ export function setComplianceFwReportStuckMsV2(n) {
696
+ _cfwReportStuckMs = _cfwPos(n, "complianceFwReportStuckMs");
697
+ }
698
+ export function getComplianceFwReportStuckMsV2() {
699
+ return _cfwReportStuckMs;
700
+ }
643
701
 
644
702
  export function _resetStateComplianceFwReporterV2() {
645
- _cfwsV2.clear(); _cfwReports.clear();
646
- _cfwMaxActivePerOwner = 8; _cfwMaxPendingReportsPerFw = 15;
647
- _cfwIdleMs = 90 * 24 * 60 * 60 * 1000; _cfwReportStuckMs = 10 * 60 * 1000;
703
+ _cfwsV2.clear();
704
+ _cfwReports.clear();
705
+ _cfwMaxActivePerOwner = 8;
706
+ _cfwMaxPendingReportsPerFw = 15;
707
+ _cfwIdleMs = 90 * 24 * 60 * 60 * 1000;
708
+ _cfwReportStuckMs = 10 * 60 * 1000;
648
709
  }
649
710
 
650
711
  export function registerComplianceFwV2({ id, owner, name, metadata } = {}) {
651
712
  if (!id || typeof id !== "string") throw new Error("id is required");
652
713
  if (!owner || typeof owner !== "string") throw new Error("owner is required");
653
- if (_cfwsV2.has(id)) throw new Error(`compliance framework ${id} already registered`);
714
+ if (_cfwsV2.has(id))
715
+ throw new Error(`compliance framework ${id} already registered`);
654
716
  const now = Date.now();
655
- const f = { id, owner, name: name || id, status: COMPLIANCE_FW_MATURITY_V2.PENDING, createdAt: now, updatedAt: now, activatedAt: null, archivedAt: null, lastTouchedAt: now, metadata: { ...(metadata || {}) } };
717
+ const f = {
718
+ id,
719
+ owner,
720
+ name: name || id,
721
+ status: COMPLIANCE_FW_MATURITY_V2.PENDING,
722
+ createdAt: now,
723
+ updatedAt: now,
724
+ activatedAt: null,
725
+ archivedAt: null,
726
+ lastTouchedAt: now,
727
+ metadata: { ...(metadata || {}) },
728
+ };
656
729
  _cfwsV2.set(id, f);
657
730
  return { ...f, metadata: { ...f.metadata } };
658
731
  }
659
- function _cfwCheckF(from, to) { const a = _cfwTrans.get(from); if (!a || !a.has(to)) throw new Error(`invalid compliance framework transition ${from} → ${to}`); }
660
- function _cfwCountActive(owner) { let n = 0; for (const f of _cfwsV2.values()) if (f.owner === owner && f.status === COMPLIANCE_FW_MATURITY_V2.ACTIVE) n++; return n; }
732
+ function _cfwCheckF(from, to) {
733
+ const a = _cfwTrans.get(from);
734
+ if (!a || !a.has(to))
735
+ throw new Error(`invalid compliance framework transition ${from} → ${to}`);
736
+ }
737
+ function _cfwCountActive(owner) {
738
+ let n = 0;
739
+ for (const f of _cfwsV2.values())
740
+ if (f.owner === owner && f.status === COMPLIANCE_FW_MATURITY_V2.ACTIVE) n++;
741
+ return n;
742
+ }
661
743
 
662
744
  export function activateComplianceFwV2(id) {
663
- const f = _cfwsV2.get(id); if (!f) throw new Error(`compliance framework ${id} not found`);
745
+ const f = _cfwsV2.get(id);
746
+ if (!f) throw new Error(`compliance framework ${id} not found`);
664
747
  _cfwCheckF(f.status, COMPLIANCE_FW_MATURITY_V2.ACTIVE);
665
748
  const recovery = f.status === COMPLIANCE_FW_MATURITY_V2.DEPRECATED;
666
- if (!recovery) { const c = _cfwCountActive(f.owner); if (c >= _cfwMaxActivePerOwner) throw new Error(`max active compliance frameworks per owner (${_cfwMaxActivePerOwner}) reached for ${f.owner}`); }
667
- const now = Date.now(); f.status = COMPLIANCE_FW_MATURITY_V2.ACTIVE; f.updatedAt = now; f.lastTouchedAt = now; if (!f.activatedAt) f.activatedAt = now;
749
+ if (!recovery) {
750
+ const c = _cfwCountActive(f.owner);
751
+ if (c >= _cfwMaxActivePerOwner)
752
+ throw new Error(
753
+ `max active compliance frameworks per owner (${_cfwMaxActivePerOwner}) reached for ${f.owner}`,
754
+ );
755
+ }
756
+ const now = Date.now();
757
+ f.status = COMPLIANCE_FW_MATURITY_V2.ACTIVE;
758
+ f.updatedAt = now;
759
+ f.lastTouchedAt = now;
760
+ if (!f.activatedAt) f.activatedAt = now;
761
+ return { ...f, metadata: { ...f.metadata } };
762
+ }
763
+ export function deprecateComplianceFwV2(id) {
764
+ const f = _cfwsV2.get(id);
765
+ if (!f) throw new Error(`compliance framework ${id} not found`);
766
+ _cfwCheckF(f.status, COMPLIANCE_FW_MATURITY_V2.DEPRECATED);
767
+ f.status = COMPLIANCE_FW_MATURITY_V2.DEPRECATED;
768
+ f.updatedAt = Date.now();
668
769
  return { ...f, metadata: { ...f.metadata } };
669
770
  }
670
- export function deprecateComplianceFwV2(id) { const f = _cfwsV2.get(id); if (!f) throw new Error(`compliance framework ${id} not found`); _cfwCheckF(f.status, COMPLIANCE_FW_MATURITY_V2.DEPRECATED); f.status = COMPLIANCE_FW_MATURITY_V2.DEPRECATED; f.updatedAt = Date.now(); return { ...f, metadata: { ...f.metadata } }; }
671
- export function archiveComplianceFwV2(id) { const f = _cfwsV2.get(id); if (!f) throw new Error(`compliance framework ${id} not found`); _cfwCheckF(f.status, COMPLIANCE_FW_MATURITY_V2.ARCHIVED); const now = Date.now(); f.status = COMPLIANCE_FW_MATURITY_V2.ARCHIVED; f.updatedAt = now; if (!f.archivedAt) f.archivedAt = now; return { ...f, metadata: { ...f.metadata } }; }
672
- export function touchComplianceFwV2(id) { const f = _cfwsV2.get(id); if (!f) throw new Error(`compliance framework ${id} not found`); if (_cfwTerminal.has(f.status)) throw new Error(`cannot touch terminal compliance framework ${id}`); const now = Date.now(); f.lastTouchedAt = now; f.updatedAt = now; return { ...f, metadata: { ...f.metadata } }; }
673
- export function getComplianceFwV2(id) { const f = _cfwsV2.get(id); if (!f) return null; return { ...f, metadata: { ...f.metadata } }; }
674
- export function listComplianceFwsV2() { return [..._cfwsV2.values()].map((f) => ({ ...f, metadata: { ...f.metadata } })); }
771
+ export function archiveComplianceFwV2(id) {
772
+ const f = _cfwsV2.get(id);
773
+ if (!f) throw new Error(`compliance framework ${id} not found`);
774
+ _cfwCheckF(f.status, COMPLIANCE_FW_MATURITY_V2.ARCHIVED);
775
+ const now = Date.now();
776
+ f.status = COMPLIANCE_FW_MATURITY_V2.ARCHIVED;
777
+ f.updatedAt = now;
778
+ if (!f.archivedAt) f.archivedAt = now;
779
+ return { ...f, metadata: { ...f.metadata } };
780
+ }
781
+ export function touchComplianceFwV2(id) {
782
+ const f = _cfwsV2.get(id);
783
+ if (!f) throw new Error(`compliance framework ${id} not found`);
784
+ if (_cfwTerminal.has(f.status))
785
+ throw new Error(`cannot touch terminal compliance framework ${id}`);
786
+ const now = Date.now();
787
+ f.lastTouchedAt = now;
788
+ f.updatedAt = now;
789
+ return { ...f, metadata: { ...f.metadata } };
790
+ }
791
+ export function getComplianceFwV2(id) {
792
+ const f = _cfwsV2.get(id);
793
+ if (!f) return null;
794
+ return { ...f, metadata: { ...f.metadata } };
795
+ }
796
+ export function listComplianceFwsV2() {
797
+ return [..._cfwsV2.values()].map((f) => ({
798
+ ...f,
799
+ metadata: { ...f.metadata },
800
+ }));
801
+ }
675
802
 
676
- function _cfwCountPendingReports(frameworkId) { let n = 0; for (const r of _cfwReports.values()) if (r.frameworkId === frameworkId && (r.status === COMPLIANCE_FW_REPORT_LIFECYCLE_V2.QUEUED || r.status === COMPLIANCE_FW_REPORT_LIFECYCLE_V2.GENERATING)) n++; return n; }
803
+ function _cfwCountPendingReports(frameworkId) {
804
+ let n = 0;
805
+ for (const r of _cfwReports.values())
806
+ if (
807
+ r.frameworkId === frameworkId &&
808
+ (r.status === COMPLIANCE_FW_REPORT_LIFECYCLE_V2.QUEUED ||
809
+ r.status === COMPLIANCE_FW_REPORT_LIFECYCLE_V2.GENERATING)
810
+ )
811
+ n++;
812
+ return n;
813
+ }
677
814
 
678
- export function createComplianceFwReportV2({ id, frameworkId, format, metadata } = {}) {
815
+ export function createComplianceFwReportV2({
816
+ id,
817
+ frameworkId,
818
+ format,
819
+ metadata,
820
+ } = {}) {
679
821
  if (!id || typeof id !== "string") throw new Error("id is required");
680
- if (!frameworkId || typeof frameworkId !== "string") throw new Error("frameworkId is required");
681
- if (_cfwReports.has(id)) throw new Error(`compliance framework report ${id} already exists`);
682
- if (!_cfwsV2.has(frameworkId)) throw new Error(`compliance framework ${frameworkId} not found`);
822
+ if (!frameworkId || typeof frameworkId !== "string")
823
+ throw new Error("frameworkId is required");
824
+ if (_cfwReports.has(id))
825
+ throw new Error(`compliance framework report ${id} already exists`);
826
+ if (!_cfwsV2.has(frameworkId))
827
+ throw new Error(`compliance framework ${frameworkId} not found`);
683
828
  const pending = _cfwCountPendingReports(frameworkId);
684
- if (pending >= _cfwMaxPendingReportsPerFw) throw new Error(`max pending compliance framework reports per framework (${_cfwMaxPendingReportsPerFw}) reached for ${frameworkId}`);
829
+ if (pending >= _cfwMaxPendingReportsPerFw)
830
+ throw new Error(
831
+ `max pending compliance framework reports per framework (${_cfwMaxPendingReportsPerFw}) reached for ${frameworkId}`,
832
+ );
685
833
  const now = Date.now();
686
- const r = { id, frameworkId, format: format || "markdown", status: COMPLIANCE_FW_REPORT_LIFECYCLE_V2.QUEUED, createdAt: now, updatedAt: now, startedAt: null, settledAt: null, metadata: { ...(metadata || {}) } };
834
+ const r = {
835
+ id,
836
+ frameworkId,
837
+ format: format || "markdown",
838
+ status: COMPLIANCE_FW_REPORT_LIFECYCLE_V2.QUEUED,
839
+ createdAt: now,
840
+ updatedAt: now,
841
+ startedAt: null,
842
+ settledAt: null,
843
+ metadata: { ...(metadata || {}) },
844
+ };
687
845
  _cfwReports.set(id, r);
688
846
  return { ...r, metadata: { ...r.metadata } };
689
847
  }
690
- function _cfwCheckR(from, to) { const a = _cfwRepTrans.get(from); if (!a || !a.has(to)) throw new Error(`invalid compliance framework report transition ${from} → ${to}`); }
691
- export function startComplianceFwReportV2(id) { const r = _cfwReports.get(id); if (!r) throw new Error(`compliance framework report ${id} not found`); _cfwCheckR(r.status, COMPLIANCE_FW_REPORT_LIFECYCLE_V2.GENERATING); const now = Date.now(); r.status = COMPLIANCE_FW_REPORT_LIFECYCLE_V2.GENERATING; r.updatedAt = now; if (!r.startedAt) r.startedAt = now; return { ...r, metadata: { ...r.metadata } }; }
692
- export function completeComplianceFwReportV2(id) { const r = _cfwReports.get(id); if (!r) throw new Error(`compliance framework report ${id} not found`); _cfwCheckR(r.status, COMPLIANCE_FW_REPORT_LIFECYCLE_V2.COMPLETED); const now = Date.now(); r.status = COMPLIANCE_FW_REPORT_LIFECYCLE_V2.COMPLETED; r.updatedAt = now; if (!r.settledAt) r.settledAt = now; return { ...r, metadata: { ...r.metadata } }; }
693
- export function failComplianceFwReportV2(id, reason) { const r = _cfwReports.get(id); if (!r) throw new Error(`compliance framework report ${id} not found`); _cfwCheckR(r.status, COMPLIANCE_FW_REPORT_LIFECYCLE_V2.FAILED); const now = Date.now(); r.status = COMPLIANCE_FW_REPORT_LIFECYCLE_V2.FAILED; r.updatedAt = now; if (!r.settledAt) r.settledAt = now; if (reason) r.metadata.failReason = String(reason); return { ...r, metadata: { ...r.metadata } }; }
694
- export function cancelComplianceFwReportV2(id, reason) { const r = _cfwReports.get(id); if (!r) throw new Error(`compliance framework report ${id} not found`); _cfwCheckR(r.status, COMPLIANCE_FW_REPORT_LIFECYCLE_V2.CANCELLED); const now = Date.now(); r.status = COMPLIANCE_FW_REPORT_LIFECYCLE_V2.CANCELLED; r.updatedAt = now; if (!r.settledAt) r.settledAt = now; if (reason) r.metadata.cancelReason = String(reason); return { ...r, metadata: { ...r.metadata } }; }
695
- export function getComplianceFwReportV2(id) { const r = _cfwReports.get(id); if (!r) return null; return { ...r, metadata: { ...r.metadata } }; }
696
- export function listComplianceFwReportsV2() { return [..._cfwReports.values()].map((r) => ({ ...r, metadata: { ...r.metadata } })); }
848
+ function _cfwCheckR(from, to) {
849
+ const a = _cfwRepTrans.get(from);
850
+ if (!a || !a.has(to))
851
+ throw new Error(
852
+ `invalid compliance framework report transition ${from} ${to}`,
853
+ );
854
+ }
855
+ export function startComplianceFwReportV2(id) {
856
+ const r = _cfwReports.get(id);
857
+ if (!r) throw new Error(`compliance framework report ${id} not found`);
858
+ _cfwCheckR(r.status, COMPLIANCE_FW_REPORT_LIFECYCLE_V2.GENERATING);
859
+ const now = Date.now();
860
+ r.status = COMPLIANCE_FW_REPORT_LIFECYCLE_V2.GENERATING;
861
+ r.updatedAt = now;
862
+ if (!r.startedAt) r.startedAt = now;
863
+ return { ...r, metadata: { ...r.metadata } };
864
+ }
865
+ export function completeComplianceFwReportV2(id) {
866
+ const r = _cfwReports.get(id);
867
+ if (!r) throw new Error(`compliance framework report ${id} not found`);
868
+ _cfwCheckR(r.status, COMPLIANCE_FW_REPORT_LIFECYCLE_V2.COMPLETED);
869
+ const now = Date.now();
870
+ r.status = COMPLIANCE_FW_REPORT_LIFECYCLE_V2.COMPLETED;
871
+ r.updatedAt = now;
872
+ if (!r.settledAt) r.settledAt = now;
873
+ return { ...r, metadata: { ...r.metadata } };
874
+ }
875
+ export function failComplianceFwReportV2(id, reason) {
876
+ const r = _cfwReports.get(id);
877
+ if (!r) throw new Error(`compliance framework report ${id} not found`);
878
+ _cfwCheckR(r.status, COMPLIANCE_FW_REPORT_LIFECYCLE_V2.FAILED);
879
+ const now = Date.now();
880
+ r.status = COMPLIANCE_FW_REPORT_LIFECYCLE_V2.FAILED;
881
+ r.updatedAt = now;
882
+ if (!r.settledAt) r.settledAt = now;
883
+ if (reason) r.metadata.failReason = String(reason);
884
+ return { ...r, metadata: { ...r.metadata } };
885
+ }
886
+ export function cancelComplianceFwReportV2(id, reason) {
887
+ const r = _cfwReports.get(id);
888
+ if (!r) throw new Error(`compliance framework report ${id} not found`);
889
+ _cfwCheckR(r.status, COMPLIANCE_FW_REPORT_LIFECYCLE_V2.CANCELLED);
890
+ const now = Date.now();
891
+ r.status = COMPLIANCE_FW_REPORT_LIFECYCLE_V2.CANCELLED;
892
+ r.updatedAt = now;
893
+ if (!r.settledAt) r.settledAt = now;
894
+ if (reason) r.metadata.cancelReason = String(reason);
895
+ return { ...r, metadata: { ...r.metadata } };
896
+ }
897
+ export function getComplianceFwReportV2(id) {
898
+ const r = _cfwReports.get(id);
899
+ if (!r) return null;
900
+ return { ...r, metadata: { ...r.metadata } };
901
+ }
902
+ export function listComplianceFwReportsV2() {
903
+ return [..._cfwReports.values()].map((r) => ({
904
+ ...r,
905
+ metadata: { ...r.metadata },
906
+ }));
907
+ }
697
908
 
698
- export function autoDeprecateIdleComplianceFwsV2({ now } = {}) { const t = now ?? Date.now(); const flipped = []; for (const f of _cfwsV2.values()) if (f.status === COMPLIANCE_FW_MATURITY_V2.ACTIVE && (t - f.lastTouchedAt) >= _cfwIdleMs) { f.status = COMPLIANCE_FW_MATURITY_V2.DEPRECATED; f.updatedAt = t; flipped.push(f.id); } return { flipped, count: flipped.length }; }
699
- export function autoFailStuckComplianceFwReportsV2({ now } = {}) { const t = now ?? Date.now(); const flipped = []; for (const r of _cfwReports.values()) if (r.status === COMPLIANCE_FW_REPORT_LIFECYCLE_V2.GENERATING && r.startedAt != null && (t - r.startedAt) >= _cfwReportStuckMs) { r.status = COMPLIANCE_FW_REPORT_LIFECYCLE_V2.FAILED; r.updatedAt = t; if (!r.settledAt) r.settledAt = t; r.metadata.failReason = "auto-fail-stuck"; flipped.push(r.id); } return { flipped, count: flipped.length }; }
909
+ export function autoDeprecateIdleComplianceFwsV2({ now } = {}) {
910
+ const t = now ?? Date.now();
911
+ const flipped = [];
912
+ for (const f of _cfwsV2.values())
913
+ if (
914
+ f.status === COMPLIANCE_FW_MATURITY_V2.ACTIVE &&
915
+ t - f.lastTouchedAt >= _cfwIdleMs
916
+ ) {
917
+ f.status = COMPLIANCE_FW_MATURITY_V2.DEPRECATED;
918
+ f.updatedAt = t;
919
+ flipped.push(f.id);
920
+ }
921
+ return { flipped, count: flipped.length };
922
+ }
923
+ export function autoFailStuckComplianceFwReportsV2({ now } = {}) {
924
+ const t = now ?? Date.now();
925
+ const flipped = [];
926
+ for (const r of _cfwReports.values())
927
+ if (
928
+ r.status === COMPLIANCE_FW_REPORT_LIFECYCLE_V2.GENERATING &&
929
+ r.startedAt != null &&
930
+ t - r.startedAt >= _cfwReportStuckMs
931
+ ) {
932
+ r.status = COMPLIANCE_FW_REPORT_LIFECYCLE_V2.FAILED;
933
+ r.updatedAt = t;
934
+ if (!r.settledAt) r.settledAt = t;
935
+ r.metadata.failReason = "auto-fail-stuck";
936
+ flipped.push(r.id);
937
+ }
938
+ return { flipped, count: flipped.length };
939
+ }
700
940
 
701
941
  export function getComplianceFwReporterGovStatsV2() {
702
- const fwsByStatus = {}; for (const s of Object.values(COMPLIANCE_FW_MATURITY_V2)) fwsByStatus[s] = 0; for (const f of _cfwsV2.values()) fwsByStatus[f.status]++;
703
- const reportsByStatus = {}; for (const s of Object.values(COMPLIANCE_FW_REPORT_LIFECYCLE_V2)) reportsByStatus[s] = 0; for (const r of _cfwReports.values()) reportsByStatus[r.status]++;
704
- return { totalComplianceFwsV2: _cfwsV2.size, totalComplianceFwReportsV2: _cfwReports.size, maxActiveComplianceFwsPerOwner: _cfwMaxActivePerOwner, maxPendingComplianceFwReportsPerFw: _cfwMaxPendingReportsPerFw, complianceFwIdleMs: _cfwIdleMs, complianceFwReportStuckMs: _cfwReportStuckMs, fwsByStatus, reportsByStatus };
942
+ const fwsByStatus = {};
943
+ for (const s of Object.values(COMPLIANCE_FW_MATURITY_V2)) fwsByStatus[s] = 0;
944
+ for (const f of _cfwsV2.values()) fwsByStatus[f.status]++;
945
+ const reportsByStatus = {};
946
+ for (const s of Object.values(COMPLIANCE_FW_REPORT_LIFECYCLE_V2))
947
+ reportsByStatus[s] = 0;
948
+ for (const r of _cfwReports.values()) reportsByStatus[r.status]++;
949
+ return {
950
+ totalComplianceFwsV2: _cfwsV2.size,
951
+ totalComplianceFwReportsV2: _cfwReports.size,
952
+ maxActiveComplianceFwsPerOwner: _cfwMaxActivePerOwner,
953
+ maxPendingComplianceFwReportsPerFw: _cfwMaxPendingReportsPerFw,
954
+ complianceFwIdleMs: _cfwIdleMs,
955
+ complianceFwReportStuckMs: _cfwReportStuckMs,
956
+ fwsByStatus,
957
+ reportsByStatus,
958
+ };
705
959
  }