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
@@ -722,3 +722,333 @@ export function _resetState() {
722
722
  _evidenceRetentionMs = COMPLIANCE_DEFAULT_EVIDENCE_RETENTION_MS;
723
723
  _reportRetentionMs = COMPLIANCE_DEFAULT_REPORT_RETENTION_MS;
724
724
  }
725
+
726
+ // =====================================================================
727
+ // compliance-manager V2 governance overlay (iter17)
728
+ // =====================================================================
729
+ export const CMGR_PROFILE_MATURITY_V2 = Object.freeze({
730
+ PENDING: "pending",
731
+ ACTIVE: "active",
732
+ DEPRECATED: "deprecated",
733
+ ARCHIVED: "archived",
734
+ });
735
+ export const CMGR_AUDIT_LIFECYCLE_V2 = Object.freeze({
736
+ QUEUED: "queued",
737
+ AUDITING: "auditing",
738
+ AUDITED: "audited",
739
+ FAILED: "failed",
740
+ CANCELLED: "cancelled",
741
+ });
742
+ const _cmgrPTrans = new Map([
743
+ [
744
+ CMGR_PROFILE_MATURITY_V2.PENDING,
745
+ new Set([
746
+ CMGR_PROFILE_MATURITY_V2.ACTIVE,
747
+ CMGR_PROFILE_MATURITY_V2.ARCHIVED,
748
+ ]),
749
+ ],
750
+ [
751
+ CMGR_PROFILE_MATURITY_V2.ACTIVE,
752
+ new Set([
753
+ CMGR_PROFILE_MATURITY_V2.DEPRECATED,
754
+ CMGR_PROFILE_MATURITY_V2.ARCHIVED,
755
+ ]),
756
+ ],
757
+ [
758
+ CMGR_PROFILE_MATURITY_V2.DEPRECATED,
759
+ new Set([
760
+ CMGR_PROFILE_MATURITY_V2.ACTIVE,
761
+ CMGR_PROFILE_MATURITY_V2.ARCHIVED,
762
+ ]),
763
+ ],
764
+ [CMGR_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
765
+ ]);
766
+ const _cmgrPTerminal = new Set([CMGR_PROFILE_MATURITY_V2.ARCHIVED]);
767
+ const _cmgrJTrans = new Map([
768
+ [
769
+ CMGR_AUDIT_LIFECYCLE_V2.QUEUED,
770
+ new Set([
771
+ CMGR_AUDIT_LIFECYCLE_V2.AUDITING,
772
+ CMGR_AUDIT_LIFECYCLE_V2.CANCELLED,
773
+ ]),
774
+ ],
775
+ [
776
+ CMGR_AUDIT_LIFECYCLE_V2.AUDITING,
777
+ new Set([
778
+ CMGR_AUDIT_LIFECYCLE_V2.AUDITED,
779
+ CMGR_AUDIT_LIFECYCLE_V2.FAILED,
780
+ CMGR_AUDIT_LIFECYCLE_V2.CANCELLED,
781
+ ]),
782
+ ],
783
+ [CMGR_AUDIT_LIFECYCLE_V2.AUDITED, new Set()],
784
+ [CMGR_AUDIT_LIFECYCLE_V2.FAILED, new Set()],
785
+ [CMGR_AUDIT_LIFECYCLE_V2.CANCELLED, new Set()],
786
+ ]);
787
+ const _cmgrPsV2 = new Map();
788
+ const _cmgrJsV2 = new Map();
789
+ let _cmgrMaxActive = 8,
790
+ _cmgrMaxPending = 20,
791
+ _cmgrIdleMs = 30 * 24 * 60 * 60 * 1000,
792
+ _cmgrStuckMs = 60 * 1000;
793
+ function _cmgrPos(n, label) {
794
+ const v = Math.floor(Number(n));
795
+ if (!Number.isFinite(v) || v <= 0)
796
+ throw new Error(`${label} must be positive integer`);
797
+ return v;
798
+ }
799
+ function _cmgrCheckP(from, to) {
800
+ const a = _cmgrPTrans.get(from);
801
+ if (!a || !a.has(to))
802
+ throw new Error(`invalid cmgr profile transition ${from} → ${to}`);
803
+ }
804
+ function _cmgrCheckJ(from, to) {
805
+ const a = _cmgrJTrans.get(from);
806
+ if (!a || !a.has(to))
807
+ throw new Error(`invalid cmgr audit transition ${from} → ${to}`);
808
+ }
809
+ function _cmgrCountActive(owner) {
810
+ let c = 0;
811
+ for (const p of _cmgrPsV2.values())
812
+ if (p.owner === owner && p.status === CMGR_PROFILE_MATURITY_V2.ACTIVE) c++;
813
+ return c;
814
+ }
815
+ function _cmgrCountPending(profileId) {
816
+ let c = 0;
817
+ for (const j of _cmgrJsV2.values())
818
+ if (
819
+ j.profileId === profileId &&
820
+ (j.status === CMGR_AUDIT_LIFECYCLE_V2.QUEUED ||
821
+ j.status === CMGR_AUDIT_LIFECYCLE_V2.AUDITING)
822
+ )
823
+ c++;
824
+ return c;
825
+ }
826
+ export function setMaxActiveCmgrProfilesPerOwnerV2(n) {
827
+ _cmgrMaxActive = _cmgrPos(n, "maxActiveCmgrProfilesPerOwner");
828
+ }
829
+ export function getMaxActiveCmgrProfilesPerOwnerV2() {
830
+ return _cmgrMaxActive;
831
+ }
832
+ export function setMaxPendingCmgrAuditsPerProfileV2(n) {
833
+ _cmgrMaxPending = _cmgrPos(n, "maxPendingCmgrAuditsPerProfile");
834
+ }
835
+ export function getMaxPendingCmgrAuditsPerProfileV2() {
836
+ return _cmgrMaxPending;
837
+ }
838
+ export function setCmgrProfileIdleMsV2(n) {
839
+ _cmgrIdleMs = _cmgrPos(n, "cmgrProfileIdleMs");
840
+ }
841
+ export function getCmgrProfileIdleMsV2() {
842
+ return _cmgrIdleMs;
843
+ }
844
+ export function setCmgrAuditStuckMsV2(n) {
845
+ _cmgrStuckMs = _cmgrPos(n, "cmgrAuditStuckMs");
846
+ }
847
+ export function getCmgrAuditStuckMsV2() {
848
+ return _cmgrStuckMs;
849
+ }
850
+ export function _resetStateComplianceManagerV2() {
851
+ _cmgrPsV2.clear();
852
+ _cmgrJsV2.clear();
853
+ _cmgrMaxActive = 8;
854
+ _cmgrMaxPending = 20;
855
+ _cmgrIdleMs = 30 * 24 * 60 * 60 * 1000;
856
+ _cmgrStuckMs = 60 * 1000;
857
+ }
858
+ export function registerCmgrProfileV2({ id, owner, framework, metadata } = {}) {
859
+ if (!id || !owner) throw new Error("id and owner required");
860
+ if (_cmgrPsV2.has(id)) throw new Error(`cmgr profile ${id} already exists`);
861
+ const now = Date.now();
862
+ const p = {
863
+ id,
864
+ owner,
865
+ framework: framework || "soc2",
866
+ status: CMGR_PROFILE_MATURITY_V2.PENDING,
867
+ createdAt: now,
868
+ updatedAt: now,
869
+ lastTouchedAt: now,
870
+ activatedAt: null,
871
+ archivedAt: null,
872
+ metadata: { ...(metadata || {}) },
873
+ };
874
+ _cmgrPsV2.set(id, p);
875
+ return { ...p, metadata: { ...p.metadata } };
876
+ }
877
+ export function activateCmgrProfileV2(id) {
878
+ const p = _cmgrPsV2.get(id);
879
+ if (!p) throw new Error(`cmgr profile ${id} not found`);
880
+ const isInitial = p.status === CMGR_PROFILE_MATURITY_V2.PENDING;
881
+ _cmgrCheckP(p.status, CMGR_PROFILE_MATURITY_V2.ACTIVE);
882
+ if (isInitial && _cmgrCountActive(p.owner) >= _cmgrMaxActive)
883
+ throw new Error(`max active cmgr profiles for owner ${p.owner} reached`);
884
+ const now = Date.now();
885
+ p.status = CMGR_PROFILE_MATURITY_V2.ACTIVE;
886
+ p.updatedAt = now;
887
+ p.lastTouchedAt = now;
888
+ if (!p.activatedAt) p.activatedAt = now;
889
+ return { ...p, metadata: { ...p.metadata } };
890
+ }
891
+ export function deprecateCmgrProfileV2(id) {
892
+ const p = _cmgrPsV2.get(id);
893
+ if (!p) throw new Error(`cmgr profile ${id} not found`);
894
+ _cmgrCheckP(p.status, CMGR_PROFILE_MATURITY_V2.DEPRECATED);
895
+ p.status = CMGR_PROFILE_MATURITY_V2.DEPRECATED;
896
+ p.updatedAt = Date.now();
897
+ return { ...p, metadata: { ...p.metadata } };
898
+ }
899
+ export function archiveCmgrProfileV2(id) {
900
+ const p = _cmgrPsV2.get(id);
901
+ if (!p) throw new Error(`cmgr profile ${id} not found`);
902
+ _cmgrCheckP(p.status, CMGR_PROFILE_MATURITY_V2.ARCHIVED);
903
+ const now = Date.now();
904
+ p.status = CMGR_PROFILE_MATURITY_V2.ARCHIVED;
905
+ p.updatedAt = now;
906
+ if (!p.archivedAt) p.archivedAt = now;
907
+ return { ...p, metadata: { ...p.metadata } };
908
+ }
909
+ export function touchCmgrProfileV2(id) {
910
+ const p = _cmgrPsV2.get(id);
911
+ if (!p) throw new Error(`cmgr profile ${id} not found`);
912
+ if (_cmgrPTerminal.has(p.status))
913
+ throw new Error(`cannot touch terminal cmgr profile ${id}`);
914
+ const now = Date.now();
915
+ p.lastTouchedAt = now;
916
+ p.updatedAt = now;
917
+ return { ...p, metadata: { ...p.metadata } };
918
+ }
919
+ export function getCmgrProfileV2(id) {
920
+ const p = _cmgrPsV2.get(id);
921
+ if (!p) return null;
922
+ return { ...p, metadata: { ...p.metadata } };
923
+ }
924
+ export function listCmgrProfilesV2() {
925
+ return [..._cmgrPsV2.values()].map((p) => ({
926
+ ...p,
927
+ metadata: { ...p.metadata },
928
+ }));
929
+ }
930
+ export function createCmgrAuditV2({ id, profileId, control, metadata } = {}) {
931
+ if (!id || !profileId) throw new Error("id and profileId required");
932
+ if (_cmgrJsV2.has(id)) throw new Error(`cmgr audit ${id} already exists`);
933
+ if (!_cmgrPsV2.has(profileId))
934
+ throw new Error(`cmgr profile ${profileId} not found`);
935
+ if (_cmgrCountPending(profileId) >= _cmgrMaxPending)
936
+ throw new Error(`max pending cmgr audits for profile ${profileId} reached`);
937
+ const now = Date.now();
938
+ const j = {
939
+ id,
940
+ profileId,
941
+ control: control || "",
942
+ status: CMGR_AUDIT_LIFECYCLE_V2.QUEUED,
943
+ createdAt: now,
944
+ updatedAt: now,
945
+ startedAt: null,
946
+ settledAt: null,
947
+ metadata: { ...(metadata || {}) },
948
+ };
949
+ _cmgrJsV2.set(id, j);
950
+ return { ...j, metadata: { ...j.metadata } };
951
+ }
952
+ export function auditingCmgrAuditV2(id) {
953
+ const j = _cmgrJsV2.get(id);
954
+ if (!j) throw new Error(`cmgr audit ${id} not found`);
955
+ _cmgrCheckJ(j.status, CMGR_AUDIT_LIFECYCLE_V2.AUDITING);
956
+ const now = Date.now();
957
+ j.status = CMGR_AUDIT_LIFECYCLE_V2.AUDITING;
958
+ j.updatedAt = now;
959
+ if (!j.startedAt) j.startedAt = now;
960
+ return { ...j, metadata: { ...j.metadata } };
961
+ }
962
+ export function completeAuditCmgrV2(id) {
963
+ const j = _cmgrJsV2.get(id);
964
+ if (!j) throw new Error(`cmgr audit ${id} not found`);
965
+ _cmgrCheckJ(j.status, CMGR_AUDIT_LIFECYCLE_V2.AUDITED);
966
+ const now = Date.now();
967
+ j.status = CMGR_AUDIT_LIFECYCLE_V2.AUDITED;
968
+ j.updatedAt = now;
969
+ if (!j.settledAt) j.settledAt = now;
970
+ return { ...j, metadata: { ...j.metadata } };
971
+ }
972
+ export function failCmgrAuditV2(id, reason) {
973
+ const j = _cmgrJsV2.get(id);
974
+ if (!j) throw new Error(`cmgr audit ${id} not found`);
975
+ _cmgrCheckJ(j.status, CMGR_AUDIT_LIFECYCLE_V2.FAILED);
976
+ const now = Date.now();
977
+ j.status = CMGR_AUDIT_LIFECYCLE_V2.FAILED;
978
+ j.updatedAt = now;
979
+ if (!j.settledAt) j.settledAt = now;
980
+ if (reason) j.metadata.failReason = String(reason);
981
+ return { ...j, metadata: { ...j.metadata } };
982
+ }
983
+ export function cancelCmgrAuditV2(id, reason) {
984
+ const j = _cmgrJsV2.get(id);
985
+ if (!j) throw new Error(`cmgr audit ${id} not found`);
986
+ _cmgrCheckJ(j.status, CMGR_AUDIT_LIFECYCLE_V2.CANCELLED);
987
+ const now = Date.now();
988
+ j.status = CMGR_AUDIT_LIFECYCLE_V2.CANCELLED;
989
+ j.updatedAt = now;
990
+ if (!j.settledAt) j.settledAt = now;
991
+ if (reason) j.metadata.cancelReason = String(reason);
992
+ return { ...j, metadata: { ...j.metadata } };
993
+ }
994
+ export function getCmgrAuditV2(id) {
995
+ const j = _cmgrJsV2.get(id);
996
+ if (!j) return null;
997
+ return { ...j, metadata: { ...j.metadata } };
998
+ }
999
+ export function listCmgrAuditsV2() {
1000
+ return [..._cmgrJsV2.values()].map((j) => ({
1001
+ ...j,
1002
+ metadata: { ...j.metadata },
1003
+ }));
1004
+ }
1005
+ export function autoDeprecateIdleCmgrProfilesV2({ now } = {}) {
1006
+ const t = now ?? Date.now();
1007
+ const flipped = [];
1008
+ for (const p of _cmgrPsV2.values())
1009
+ if (
1010
+ p.status === CMGR_PROFILE_MATURITY_V2.ACTIVE &&
1011
+ t - p.lastTouchedAt >= _cmgrIdleMs
1012
+ ) {
1013
+ p.status = CMGR_PROFILE_MATURITY_V2.DEPRECATED;
1014
+ p.updatedAt = t;
1015
+ flipped.push(p.id);
1016
+ }
1017
+ return { flipped, count: flipped.length };
1018
+ }
1019
+ export function autoFailStuckCmgrAuditsV2({ now } = {}) {
1020
+ const t = now ?? Date.now();
1021
+ const flipped = [];
1022
+ for (const j of _cmgrJsV2.values())
1023
+ if (
1024
+ j.status === CMGR_AUDIT_LIFECYCLE_V2.AUDITING &&
1025
+ j.startedAt != null &&
1026
+ t - j.startedAt >= _cmgrStuckMs
1027
+ ) {
1028
+ j.status = CMGR_AUDIT_LIFECYCLE_V2.FAILED;
1029
+ j.updatedAt = t;
1030
+ if (!j.settledAt) j.settledAt = t;
1031
+ j.metadata.failReason = "auto-fail-stuck";
1032
+ flipped.push(j.id);
1033
+ }
1034
+ return { flipped, count: flipped.length };
1035
+ }
1036
+ export function getComplianceManagerGovStatsV2() {
1037
+ const profilesByStatus = {};
1038
+ for (const v of Object.values(CMGR_PROFILE_MATURITY_V2))
1039
+ profilesByStatus[v] = 0;
1040
+ for (const p of _cmgrPsV2.values()) profilesByStatus[p.status]++;
1041
+ const auditsByStatus = {};
1042
+ for (const v of Object.values(CMGR_AUDIT_LIFECYCLE_V2)) auditsByStatus[v] = 0;
1043
+ for (const j of _cmgrJsV2.values()) auditsByStatus[j.status]++;
1044
+ return {
1045
+ totalCmgrProfilesV2: _cmgrPsV2.size,
1046
+ totalCmgrAuditsV2: _cmgrJsV2.size,
1047
+ maxActiveCmgrProfilesPerOwner: _cmgrMaxActive,
1048
+ maxPendingCmgrAuditsPerProfile: _cmgrMaxPending,
1049
+ cmgrProfileIdleMs: _cmgrIdleMs,
1050
+ cmgrAuditStuckMs: _cmgrStuckMs,
1051
+ profilesByStatus,
1052
+ auditsByStatus,
1053
+ };
1054
+ }