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
@@ -861,3 +861,346 @@ export function _resetStateV2() {
861
861
  _tsDeviceIdleMs = TS_DEFAULT_DEVICE_IDLE_MS;
862
862
  _tsTransmissionStuckMs = TS_DEFAULT_TRANSMISSION_STUCK_MS;
863
863
  }
864
+
865
+ // =====================================================================
866
+ // trust-security V2 governance overlay (iter18)
867
+ // =====================================================================
868
+ export const TRUSTGOV_PROFILE_MATURITY_V2 = Object.freeze({
869
+ PENDING: "pending",
870
+ ACTIVE: "active",
871
+ SUSPENDED: "suspended",
872
+ ARCHIVED: "archived",
873
+ });
874
+ export const TRUSTGOV_CHECK_LIFECYCLE_V2 = Object.freeze({
875
+ QUEUED: "queued",
876
+ VERIFYING: "verifying",
877
+ VERIFIED: "verified",
878
+ FAILED: "failed",
879
+ CANCELLED: "cancelled",
880
+ });
881
+ const _trustgovPTrans = new Map([
882
+ [
883
+ TRUSTGOV_PROFILE_MATURITY_V2.PENDING,
884
+ new Set([
885
+ TRUSTGOV_PROFILE_MATURITY_V2.ACTIVE,
886
+ TRUSTGOV_PROFILE_MATURITY_V2.ARCHIVED,
887
+ ]),
888
+ ],
889
+ [
890
+ TRUSTGOV_PROFILE_MATURITY_V2.ACTIVE,
891
+ new Set([
892
+ TRUSTGOV_PROFILE_MATURITY_V2.SUSPENDED,
893
+ TRUSTGOV_PROFILE_MATURITY_V2.ARCHIVED,
894
+ ]),
895
+ ],
896
+ [
897
+ TRUSTGOV_PROFILE_MATURITY_V2.SUSPENDED,
898
+ new Set([
899
+ TRUSTGOV_PROFILE_MATURITY_V2.ACTIVE,
900
+ TRUSTGOV_PROFILE_MATURITY_V2.ARCHIVED,
901
+ ]),
902
+ ],
903
+ [TRUSTGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
904
+ ]);
905
+ const _trustgovPTerminal = new Set([TRUSTGOV_PROFILE_MATURITY_V2.ARCHIVED]);
906
+ const _trustgovJTrans = new Map([
907
+ [
908
+ TRUSTGOV_CHECK_LIFECYCLE_V2.QUEUED,
909
+ new Set([
910
+ TRUSTGOV_CHECK_LIFECYCLE_V2.VERIFYING,
911
+ TRUSTGOV_CHECK_LIFECYCLE_V2.CANCELLED,
912
+ ]),
913
+ ],
914
+ [
915
+ TRUSTGOV_CHECK_LIFECYCLE_V2.VERIFYING,
916
+ new Set([
917
+ TRUSTGOV_CHECK_LIFECYCLE_V2.VERIFIED,
918
+ TRUSTGOV_CHECK_LIFECYCLE_V2.FAILED,
919
+ TRUSTGOV_CHECK_LIFECYCLE_V2.CANCELLED,
920
+ ]),
921
+ ],
922
+ [TRUSTGOV_CHECK_LIFECYCLE_V2.VERIFIED, new Set()],
923
+ [TRUSTGOV_CHECK_LIFECYCLE_V2.FAILED, new Set()],
924
+ [TRUSTGOV_CHECK_LIFECYCLE_V2.CANCELLED, new Set()],
925
+ ]);
926
+ const _trustgovPsV2 = new Map();
927
+ const _trustgovJsV2 = new Map();
928
+ let _trustgovMaxActive = 8,
929
+ _trustgovMaxPending = 20,
930
+ _trustgovIdleMs = 30 * 24 * 60 * 60 * 1000,
931
+ _trustgovStuckMs = 60 * 1000;
932
+ function _trustgovPos(n, label) {
933
+ const v = Math.floor(Number(n));
934
+ if (!Number.isFinite(v) || v <= 0)
935
+ throw new Error(`${label} must be positive integer`);
936
+ return v;
937
+ }
938
+ function _trustgovCheckP(from, to) {
939
+ const a = _trustgovPTrans.get(from);
940
+ if (!a || !a.has(to))
941
+ throw new Error(`invalid trustgov profile transition ${from} → ${to}`);
942
+ }
943
+ function _trustgovCheckJ(from, to) {
944
+ const a = _trustgovJTrans.get(from);
945
+ if (!a || !a.has(to))
946
+ throw new Error(`invalid trustgov check transition ${from} → ${to}`);
947
+ }
948
+ function _trustgovCountActive(owner) {
949
+ let c = 0;
950
+ for (const p of _trustgovPsV2.values())
951
+ if (p.owner === owner && p.status === TRUSTGOV_PROFILE_MATURITY_V2.ACTIVE)
952
+ c++;
953
+ return c;
954
+ }
955
+ function _trustgovCountPending(profileId) {
956
+ let c = 0;
957
+ for (const j of _trustgovJsV2.values())
958
+ if (
959
+ j.profileId === profileId &&
960
+ (j.status === TRUSTGOV_CHECK_LIFECYCLE_V2.QUEUED ||
961
+ j.status === TRUSTGOV_CHECK_LIFECYCLE_V2.VERIFYING)
962
+ )
963
+ c++;
964
+ return c;
965
+ }
966
+ export function setMaxActiveTrustgovProfilesPerOwnerV2(n) {
967
+ _trustgovMaxActive = _trustgovPos(n, "maxActiveTrustgovProfilesPerOwner");
968
+ }
969
+ export function getMaxActiveTrustgovProfilesPerOwnerV2() {
970
+ return _trustgovMaxActive;
971
+ }
972
+ export function setMaxPendingTrustgovChecksPerProfileV2(n) {
973
+ _trustgovMaxPending = _trustgovPos(n, "maxPendingTrustgovChecksPerProfile");
974
+ }
975
+ export function getMaxPendingTrustgovChecksPerProfileV2() {
976
+ return _trustgovMaxPending;
977
+ }
978
+ export function setTrustgovProfileIdleMsV2(n) {
979
+ _trustgovIdleMs = _trustgovPos(n, "trustgovProfileIdleMs");
980
+ }
981
+ export function getTrustgovProfileIdleMsV2() {
982
+ return _trustgovIdleMs;
983
+ }
984
+ export function setTrustgovCheckStuckMsV2(n) {
985
+ _trustgovStuckMs = _trustgovPos(n, "trustgovCheckStuckMs");
986
+ }
987
+ export function getTrustgovCheckStuckMsV2() {
988
+ return _trustgovStuckMs;
989
+ }
990
+ export function _resetStateTrustSecurityGovV2() {
991
+ _trustgovPsV2.clear();
992
+ _trustgovJsV2.clear();
993
+ _trustgovMaxActive = 8;
994
+ _trustgovMaxPending = 20;
995
+ _trustgovIdleMs = 30 * 24 * 60 * 60 * 1000;
996
+ _trustgovStuckMs = 60 * 1000;
997
+ }
998
+ export function registerTrustgovProfileV2({ id, owner, level, metadata } = {}) {
999
+ if (!id || !owner) throw new Error("id and owner required");
1000
+ if (_trustgovPsV2.has(id))
1001
+ throw new Error(`trustgov profile ${id} already exists`);
1002
+ const now = Date.now();
1003
+ const p = {
1004
+ id,
1005
+ owner,
1006
+ level: level || "medium",
1007
+ status: TRUSTGOV_PROFILE_MATURITY_V2.PENDING,
1008
+ createdAt: now,
1009
+ updatedAt: now,
1010
+ lastTouchedAt: now,
1011
+ activatedAt: null,
1012
+ archivedAt: null,
1013
+ metadata: { ...(metadata || {}) },
1014
+ };
1015
+ _trustgovPsV2.set(id, p);
1016
+ return { ...p, metadata: { ...p.metadata } };
1017
+ }
1018
+ export function activateTrustgovProfileV2(id) {
1019
+ const p = _trustgovPsV2.get(id);
1020
+ if (!p) throw new Error(`trustgov profile ${id} not found`);
1021
+ const isInitial = p.status === TRUSTGOV_PROFILE_MATURITY_V2.PENDING;
1022
+ _trustgovCheckP(p.status, TRUSTGOV_PROFILE_MATURITY_V2.ACTIVE);
1023
+ if (isInitial && _trustgovCountActive(p.owner) >= _trustgovMaxActive)
1024
+ throw new Error(
1025
+ `max active trustgov profiles for owner ${p.owner} reached`,
1026
+ );
1027
+ const now = Date.now();
1028
+ p.status = TRUSTGOV_PROFILE_MATURITY_V2.ACTIVE;
1029
+ p.updatedAt = now;
1030
+ p.lastTouchedAt = now;
1031
+ if (!p.activatedAt) p.activatedAt = now;
1032
+ return { ...p, metadata: { ...p.metadata } };
1033
+ }
1034
+ export function suspendTrustgovProfileV2(id) {
1035
+ const p = _trustgovPsV2.get(id);
1036
+ if (!p) throw new Error(`trustgov profile ${id} not found`);
1037
+ _trustgovCheckP(p.status, TRUSTGOV_PROFILE_MATURITY_V2.SUSPENDED);
1038
+ p.status = TRUSTGOV_PROFILE_MATURITY_V2.SUSPENDED;
1039
+ p.updatedAt = Date.now();
1040
+ return { ...p, metadata: { ...p.metadata } };
1041
+ }
1042
+ export function archiveTrustgovProfileV2(id) {
1043
+ const p = _trustgovPsV2.get(id);
1044
+ if (!p) throw new Error(`trustgov profile ${id} not found`);
1045
+ _trustgovCheckP(p.status, TRUSTGOV_PROFILE_MATURITY_V2.ARCHIVED);
1046
+ const now = Date.now();
1047
+ p.status = TRUSTGOV_PROFILE_MATURITY_V2.ARCHIVED;
1048
+ p.updatedAt = now;
1049
+ if (!p.archivedAt) p.archivedAt = now;
1050
+ return { ...p, metadata: { ...p.metadata } };
1051
+ }
1052
+ export function touchTrustgovProfileV2(id) {
1053
+ const p = _trustgovPsV2.get(id);
1054
+ if (!p) throw new Error(`trustgov profile ${id} not found`);
1055
+ if (_trustgovPTerminal.has(p.status))
1056
+ throw new Error(`cannot touch terminal trustgov profile ${id}`);
1057
+ const now = Date.now();
1058
+ p.lastTouchedAt = now;
1059
+ p.updatedAt = now;
1060
+ return { ...p, metadata: { ...p.metadata } };
1061
+ }
1062
+ export function getTrustgovProfileV2(id) {
1063
+ const p = _trustgovPsV2.get(id);
1064
+ if (!p) return null;
1065
+ return { ...p, metadata: { ...p.metadata } };
1066
+ }
1067
+ export function listTrustgovProfilesV2() {
1068
+ return [..._trustgovPsV2.values()].map((p) => ({
1069
+ ...p,
1070
+ metadata: { ...p.metadata },
1071
+ }));
1072
+ }
1073
+ export function createTrustgovCheckV2({
1074
+ id,
1075
+ profileId,
1076
+ subject,
1077
+ metadata,
1078
+ } = {}) {
1079
+ if (!id || !profileId) throw new Error("id and profileId required");
1080
+ if (_trustgovJsV2.has(id))
1081
+ throw new Error(`trustgov check ${id} already exists`);
1082
+ if (!_trustgovPsV2.has(profileId))
1083
+ throw new Error(`trustgov profile ${profileId} not found`);
1084
+ if (_trustgovCountPending(profileId) >= _trustgovMaxPending)
1085
+ throw new Error(
1086
+ `max pending trustgov checks for profile ${profileId} reached`,
1087
+ );
1088
+ const now = Date.now();
1089
+ const j = {
1090
+ id,
1091
+ profileId,
1092
+ subject: subject || "",
1093
+ status: TRUSTGOV_CHECK_LIFECYCLE_V2.QUEUED,
1094
+ createdAt: now,
1095
+ updatedAt: now,
1096
+ startedAt: null,
1097
+ settledAt: null,
1098
+ metadata: { ...(metadata || {}) },
1099
+ };
1100
+ _trustgovJsV2.set(id, j);
1101
+ return { ...j, metadata: { ...j.metadata } };
1102
+ }
1103
+ export function verifyingTrustgovCheckV2(id) {
1104
+ const j = _trustgovJsV2.get(id);
1105
+ if (!j) throw new Error(`trustgov check ${id} not found`);
1106
+ _trustgovCheckJ(j.status, TRUSTGOV_CHECK_LIFECYCLE_V2.VERIFYING);
1107
+ const now = Date.now();
1108
+ j.status = TRUSTGOV_CHECK_LIFECYCLE_V2.VERIFYING;
1109
+ j.updatedAt = now;
1110
+ if (!j.startedAt) j.startedAt = now;
1111
+ return { ...j, metadata: { ...j.metadata } };
1112
+ }
1113
+ export function completeCheckTrustgovV2(id) {
1114
+ const j = _trustgovJsV2.get(id);
1115
+ if (!j) throw new Error(`trustgov check ${id} not found`);
1116
+ _trustgovCheckJ(j.status, TRUSTGOV_CHECK_LIFECYCLE_V2.VERIFIED);
1117
+ const now = Date.now();
1118
+ j.status = TRUSTGOV_CHECK_LIFECYCLE_V2.VERIFIED;
1119
+ j.updatedAt = now;
1120
+ if (!j.settledAt) j.settledAt = now;
1121
+ return { ...j, metadata: { ...j.metadata } };
1122
+ }
1123
+ export function failTrustgovCheckV2(id, reason) {
1124
+ const j = _trustgovJsV2.get(id);
1125
+ if (!j) throw new Error(`trustgov check ${id} not found`);
1126
+ _trustgovCheckJ(j.status, TRUSTGOV_CHECK_LIFECYCLE_V2.FAILED);
1127
+ const now = Date.now();
1128
+ j.status = TRUSTGOV_CHECK_LIFECYCLE_V2.FAILED;
1129
+ j.updatedAt = now;
1130
+ if (!j.settledAt) j.settledAt = now;
1131
+ if (reason) j.metadata.failReason = String(reason);
1132
+ return { ...j, metadata: { ...j.metadata } };
1133
+ }
1134
+ export function cancelTrustgovCheckV2(id, reason) {
1135
+ const j = _trustgovJsV2.get(id);
1136
+ if (!j) throw new Error(`trustgov check ${id} not found`);
1137
+ _trustgovCheckJ(j.status, TRUSTGOV_CHECK_LIFECYCLE_V2.CANCELLED);
1138
+ const now = Date.now();
1139
+ j.status = TRUSTGOV_CHECK_LIFECYCLE_V2.CANCELLED;
1140
+ j.updatedAt = now;
1141
+ if (!j.settledAt) j.settledAt = now;
1142
+ if (reason) j.metadata.cancelReason = String(reason);
1143
+ return { ...j, metadata: { ...j.metadata } };
1144
+ }
1145
+ export function getTrustgovCheckV2(id) {
1146
+ const j = _trustgovJsV2.get(id);
1147
+ if (!j) return null;
1148
+ return { ...j, metadata: { ...j.metadata } };
1149
+ }
1150
+ export function listTrustgovChecksV2() {
1151
+ return [..._trustgovJsV2.values()].map((j) => ({
1152
+ ...j,
1153
+ metadata: { ...j.metadata },
1154
+ }));
1155
+ }
1156
+ export function autoSuspendIdleTrustgovProfilesV2({ now } = {}) {
1157
+ const t = now ?? Date.now();
1158
+ const flipped = [];
1159
+ for (const p of _trustgovPsV2.values())
1160
+ if (
1161
+ p.status === TRUSTGOV_PROFILE_MATURITY_V2.ACTIVE &&
1162
+ t - p.lastTouchedAt >= _trustgovIdleMs
1163
+ ) {
1164
+ p.status = TRUSTGOV_PROFILE_MATURITY_V2.SUSPENDED;
1165
+ p.updatedAt = t;
1166
+ flipped.push(p.id);
1167
+ }
1168
+ return { flipped, count: flipped.length };
1169
+ }
1170
+ export function autoFailStuckTrustgovChecksV2({ now } = {}) {
1171
+ const t = now ?? Date.now();
1172
+ const flipped = [];
1173
+ for (const j of _trustgovJsV2.values())
1174
+ if (
1175
+ j.status === TRUSTGOV_CHECK_LIFECYCLE_V2.VERIFYING &&
1176
+ j.startedAt != null &&
1177
+ t - j.startedAt >= _trustgovStuckMs
1178
+ ) {
1179
+ j.status = TRUSTGOV_CHECK_LIFECYCLE_V2.FAILED;
1180
+ j.updatedAt = t;
1181
+ if (!j.settledAt) j.settledAt = t;
1182
+ j.metadata.failReason = "auto-fail-stuck";
1183
+ flipped.push(j.id);
1184
+ }
1185
+ return { flipped, count: flipped.length };
1186
+ }
1187
+ export function getTrustSecurityGovStatsV2() {
1188
+ const profilesByStatus = {};
1189
+ for (const v of Object.values(TRUSTGOV_PROFILE_MATURITY_V2))
1190
+ profilesByStatus[v] = 0;
1191
+ for (const p of _trustgovPsV2.values()) profilesByStatus[p.status]++;
1192
+ const checksByStatus = {};
1193
+ for (const v of Object.values(TRUSTGOV_CHECK_LIFECYCLE_V2))
1194
+ checksByStatus[v] = 0;
1195
+ for (const j of _trustgovJsV2.values()) checksByStatus[j.status]++;
1196
+ return {
1197
+ totalTrustgovProfilesV2: _trustgovPsV2.size,
1198
+ totalTrustgovChecksV2: _trustgovJsV2.size,
1199
+ maxActiveTrustgovProfilesPerOwner: _trustgovMaxActive,
1200
+ maxPendingTrustgovChecksPerProfile: _trustgovMaxPending,
1201
+ trustgovProfileIdleMs: _trustgovIdleMs,
1202
+ trustgovCheckStuckMs: _trustgovStuckMs,
1203
+ profilesByStatus,
1204
+ checksByStatus,
1205
+ };
1206
+ }
package/src/lib/ueba.js CHANGED
@@ -790,3 +790,343 @@ export function _resetStateUebaV2() {
790
790
  _uebaBaselineStaleMs = UEBA_DEFAULT_BASELINE_STALE_MS;
791
791
  _uebaInvestigationStuckMs = UEBA_DEFAULT_INVESTIGATION_STUCK_MS;
792
792
  }
793
+
794
+ // =====================================================================
795
+ // ueba V2 governance overlay (iter24)
796
+ // =====================================================================
797
+ export const UEBGOV_PROFILE_MATURITY_V2 = Object.freeze({
798
+ PENDING: "pending",
799
+ ACTIVE: "active",
800
+ SUPPRESSED: "suppressed",
801
+ ARCHIVED: "archived",
802
+ });
803
+ export const UEBGOV_ALERT_LIFECYCLE_V2 = Object.freeze({
804
+ QUEUED: "queued",
805
+ ANALYZING: "analyzing",
806
+ TRIAGED: "triaged",
807
+ FAILED: "failed",
808
+ CANCELLED: "cancelled",
809
+ });
810
+ const _uebgovPTrans = new Map([
811
+ [
812
+ UEBGOV_PROFILE_MATURITY_V2.PENDING,
813
+ new Set([
814
+ UEBGOV_PROFILE_MATURITY_V2.ACTIVE,
815
+ UEBGOV_PROFILE_MATURITY_V2.ARCHIVED,
816
+ ]),
817
+ ],
818
+ [
819
+ UEBGOV_PROFILE_MATURITY_V2.ACTIVE,
820
+ new Set([
821
+ UEBGOV_PROFILE_MATURITY_V2.SUPPRESSED,
822
+ UEBGOV_PROFILE_MATURITY_V2.ARCHIVED,
823
+ ]),
824
+ ],
825
+ [
826
+ UEBGOV_PROFILE_MATURITY_V2.SUPPRESSED,
827
+ new Set([
828
+ UEBGOV_PROFILE_MATURITY_V2.ACTIVE,
829
+ UEBGOV_PROFILE_MATURITY_V2.ARCHIVED,
830
+ ]),
831
+ ],
832
+ [UEBGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
833
+ ]);
834
+ const _uebgovPTerminal = new Set([UEBGOV_PROFILE_MATURITY_V2.ARCHIVED]);
835
+ const _uebgovJTrans = new Map([
836
+ [
837
+ UEBGOV_ALERT_LIFECYCLE_V2.QUEUED,
838
+ new Set([
839
+ UEBGOV_ALERT_LIFECYCLE_V2.ANALYZING,
840
+ UEBGOV_ALERT_LIFECYCLE_V2.CANCELLED,
841
+ ]),
842
+ ],
843
+ [
844
+ UEBGOV_ALERT_LIFECYCLE_V2.ANALYZING,
845
+ new Set([
846
+ UEBGOV_ALERT_LIFECYCLE_V2.TRIAGED,
847
+ UEBGOV_ALERT_LIFECYCLE_V2.FAILED,
848
+ UEBGOV_ALERT_LIFECYCLE_V2.CANCELLED,
849
+ ]),
850
+ ],
851
+ [UEBGOV_ALERT_LIFECYCLE_V2.TRIAGED, new Set()],
852
+ [UEBGOV_ALERT_LIFECYCLE_V2.FAILED, new Set()],
853
+ [UEBGOV_ALERT_LIFECYCLE_V2.CANCELLED, new Set()],
854
+ ]);
855
+ const _uebgovPsV2 = new Map();
856
+ const _uebgovJsV2 = new Map();
857
+ let _uebgovMaxActive = 8,
858
+ _uebgovMaxPending = 20,
859
+ _uebgovIdleMs = 30 * 24 * 60 * 60 * 1000,
860
+ _uebgovStuckMs = 60 * 1000;
861
+ function _uebgovPos(n, label) {
862
+ const v = Math.floor(Number(n));
863
+ if (!Number.isFinite(v) || v <= 0)
864
+ throw new Error(`${label} must be positive integer`);
865
+ return v;
866
+ }
867
+ function _uebgovCheckP(from, to) {
868
+ const a = _uebgovPTrans.get(from);
869
+ if (!a || !a.has(to))
870
+ throw new Error(`invalid uebgov profile transition ${from} → ${to}`);
871
+ }
872
+ function _uebgovCheckJ(from, to) {
873
+ const a = _uebgovJTrans.get(from);
874
+ if (!a || !a.has(to))
875
+ throw new Error(`invalid uebgov alert transition ${from} → ${to}`);
876
+ }
877
+ function _uebgovCountActive(owner) {
878
+ let c = 0;
879
+ for (const p of _uebgovPsV2.values())
880
+ if (p.owner === owner && p.status === UEBGOV_PROFILE_MATURITY_V2.ACTIVE)
881
+ c++;
882
+ return c;
883
+ }
884
+ function _uebgovCountPending(profileId) {
885
+ let c = 0;
886
+ for (const j of _uebgovJsV2.values())
887
+ if (
888
+ j.profileId === profileId &&
889
+ (j.status === UEBGOV_ALERT_LIFECYCLE_V2.QUEUED ||
890
+ j.status === UEBGOV_ALERT_LIFECYCLE_V2.ANALYZING)
891
+ )
892
+ c++;
893
+ return c;
894
+ }
895
+ export function setMaxActiveUebgovProfilesPerOwnerV2(n) {
896
+ _uebgovMaxActive = _uebgovPos(n, "maxActiveUebgovProfilesPerOwner");
897
+ }
898
+ export function getMaxActiveUebgovProfilesPerOwnerV2() {
899
+ return _uebgovMaxActive;
900
+ }
901
+ export function setMaxPendingUebgovAlertsPerProfileV2(n) {
902
+ _uebgovMaxPending = _uebgovPos(n, "maxPendingUebgovAlertsPerProfile");
903
+ }
904
+ export function getMaxPendingUebgovAlertsPerProfileV2() {
905
+ return _uebgovMaxPending;
906
+ }
907
+ export function setUebgovProfileIdleMsV2(n) {
908
+ _uebgovIdleMs = _uebgovPos(n, "uebgovProfileIdleMs");
909
+ }
910
+ export function getUebgovProfileIdleMsV2() {
911
+ return _uebgovIdleMs;
912
+ }
913
+ export function setUebgovAlertStuckMsV2(n) {
914
+ _uebgovStuckMs = _uebgovPos(n, "uebgovAlertStuckMs");
915
+ }
916
+ export function getUebgovAlertStuckMsV2() {
917
+ return _uebgovStuckMs;
918
+ }
919
+ export function _resetStateUebaGovV2() {
920
+ _uebgovPsV2.clear();
921
+ _uebgovJsV2.clear();
922
+ _uebgovMaxActive = 8;
923
+ _uebgovMaxPending = 20;
924
+ _uebgovIdleMs = 30 * 24 * 60 * 60 * 1000;
925
+ _uebgovStuckMs = 60 * 1000;
926
+ }
927
+ export function registerUebgovProfileV2({ id, owner, entity, metadata } = {}) {
928
+ if (!id || !owner) throw new Error("id and owner required");
929
+ if (_uebgovPsV2.has(id))
930
+ throw new Error(`uebgov profile ${id} already exists`);
931
+ const now = Date.now();
932
+ const p = {
933
+ id,
934
+ owner,
935
+ entity: entity || "user",
936
+ status: UEBGOV_PROFILE_MATURITY_V2.PENDING,
937
+ createdAt: now,
938
+ updatedAt: now,
939
+ lastTouchedAt: now,
940
+ activatedAt: null,
941
+ archivedAt: null,
942
+ metadata: { ...(metadata || {}) },
943
+ };
944
+ _uebgovPsV2.set(id, p);
945
+ return { ...p, metadata: { ...p.metadata } };
946
+ }
947
+ export function activateUebgovProfileV2(id) {
948
+ const p = _uebgovPsV2.get(id);
949
+ if (!p) throw new Error(`uebgov profile ${id} not found`);
950
+ const isInitial = p.status === UEBGOV_PROFILE_MATURITY_V2.PENDING;
951
+ _uebgovCheckP(p.status, UEBGOV_PROFILE_MATURITY_V2.ACTIVE);
952
+ if (isInitial && _uebgovCountActive(p.owner) >= _uebgovMaxActive)
953
+ throw new Error(`max active uebgov profiles for owner ${p.owner} reached`);
954
+ const now = Date.now();
955
+ p.status = UEBGOV_PROFILE_MATURITY_V2.ACTIVE;
956
+ p.updatedAt = now;
957
+ p.lastTouchedAt = now;
958
+ if (!p.activatedAt) p.activatedAt = now;
959
+ return { ...p, metadata: { ...p.metadata } };
960
+ }
961
+ export function suppressUebgovProfileV2(id) {
962
+ const p = _uebgovPsV2.get(id);
963
+ if (!p) throw new Error(`uebgov profile ${id} not found`);
964
+ _uebgovCheckP(p.status, UEBGOV_PROFILE_MATURITY_V2.SUPPRESSED);
965
+ p.status = UEBGOV_PROFILE_MATURITY_V2.SUPPRESSED;
966
+ p.updatedAt = Date.now();
967
+ return { ...p, metadata: { ...p.metadata } };
968
+ }
969
+ export function archiveUebgovProfileV2(id) {
970
+ const p = _uebgovPsV2.get(id);
971
+ if (!p) throw new Error(`uebgov profile ${id} not found`);
972
+ _uebgovCheckP(p.status, UEBGOV_PROFILE_MATURITY_V2.ARCHIVED);
973
+ const now = Date.now();
974
+ p.status = UEBGOV_PROFILE_MATURITY_V2.ARCHIVED;
975
+ p.updatedAt = now;
976
+ if (!p.archivedAt) p.archivedAt = now;
977
+ return { ...p, metadata: { ...p.metadata } };
978
+ }
979
+ export function touchUebgovProfileV2(id) {
980
+ const p = _uebgovPsV2.get(id);
981
+ if (!p) throw new Error(`uebgov profile ${id} not found`);
982
+ if (_uebgovPTerminal.has(p.status))
983
+ throw new Error(`cannot touch terminal uebgov profile ${id}`);
984
+ const now = Date.now();
985
+ p.lastTouchedAt = now;
986
+ p.updatedAt = now;
987
+ return { ...p, metadata: { ...p.metadata } };
988
+ }
989
+ export function getUebgovProfileV2(id) {
990
+ const p = _uebgovPsV2.get(id);
991
+ if (!p) return null;
992
+ return { ...p, metadata: { ...p.metadata } };
993
+ }
994
+ export function listUebgovProfilesV2() {
995
+ return [..._uebgovPsV2.values()].map((p) => ({
996
+ ...p,
997
+ metadata: { ...p.metadata },
998
+ }));
999
+ }
1000
+ export function createUebgovAlertV2({
1001
+ id,
1002
+ profileId,
1003
+ behavior,
1004
+ metadata,
1005
+ } = {}) {
1006
+ if (!id || !profileId) throw new Error("id and profileId required");
1007
+ if (_uebgovJsV2.has(id)) throw new Error(`uebgov alert ${id} already exists`);
1008
+ if (!_uebgovPsV2.has(profileId))
1009
+ throw new Error(`uebgov profile ${profileId} not found`);
1010
+ if (_uebgovCountPending(profileId) >= _uebgovMaxPending)
1011
+ throw new Error(
1012
+ `max pending uebgov alerts for profile ${profileId} reached`,
1013
+ );
1014
+ const now = Date.now();
1015
+ const j = {
1016
+ id,
1017
+ profileId,
1018
+ behavior: behavior || "",
1019
+ status: UEBGOV_ALERT_LIFECYCLE_V2.QUEUED,
1020
+ createdAt: now,
1021
+ updatedAt: now,
1022
+ startedAt: null,
1023
+ settledAt: null,
1024
+ metadata: { ...(metadata || {}) },
1025
+ };
1026
+ _uebgovJsV2.set(id, j);
1027
+ return { ...j, metadata: { ...j.metadata } };
1028
+ }
1029
+ export function analyzingUebgovAlertV2(id) {
1030
+ const j = _uebgovJsV2.get(id);
1031
+ if (!j) throw new Error(`uebgov alert ${id} not found`);
1032
+ _uebgovCheckJ(j.status, UEBGOV_ALERT_LIFECYCLE_V2.ANALYZING);
1033
+ const now = Date.now();
1034
+ j.status = UEBGOV_ALERT_LIFECYCLE_V2.ANALYZING;
1035
+ j.updatedAt = now;
1036
+ if (!j.startedAt) j.startedAt = now;
1037
+ return { ...j, metadata: { ...j.metadata } };
1038
+ }
1039
+ export function completeAlertUebgovV2(id) {
1040
+ const j = _uebgovJsV2.get(id);
1041
+ if (!j) throw new Error(`uebgov alert ${id} not found`);
1042
+ _uebgovCheckJ(j.status, UEBGOV_ALERT_LIFECYCLE_V2.TRIAGED);
1043
+ const now = Date.now();
1044
+ j.status = UEBGOV_ALERT_LIFECYCLE_V2.TRIAGED;
1045
+ j.updatedAt = now;
1046
+ if (!j.settledAt) j.settledAt = now;
1047
+ return { ...j, metadata: { ...j.metadata } };
1048
+ }
1049
+ export function failUebgovAlertV2(id, reason) {
1050
+ const j = _uebgovJsV2.get(id);
1051
+ if (!j) throw new Error(`uebgov alert ${id} not found`);
1052
+ _uebgovCheckJ(j.status, UEBGOV_ALERT_LIFECYCLE_V2.FAILED);
1053
+ const now = Date.now();
1054
+ j.status = UEBGOV_ALERT_LIFECYCLE_V2.FAILED;
1055
+ j.updatedAt = now;
1056
+ if (!j.settledAt) j.settledAt = now;
1057
+ if (reason) j.metadata.failReason = String(reason);
1058
+ return { ...j, metadata: { ...j.metadata } };
1059
+ }
1060
+ export function cancelUebgovAlertV2(id, reason) {
1061
+ const j = _uebgovJsV2.get(id);
1062
+ if (!j) throw new Error(`uebgov alert ${id} not found`);
1063
+ _uebgovCheckJ(j.status, UEBGOV_ALERT_LIFECYCLE_V2.CANCELLED);
1064
+ const now = Date.now();
1065
+ j.status = UEBGOV_ALERT_LIFECYCLE_V2.CANCELLED;
1066
+ j.updatedAt = now;
1067
+ if (!j.settledAt) j.settledAt = now;
1068
+ if (reason) j.metadata.cancelReason = String(reason);
1069
+ return { ...j, metadata: { ...j.metadata } };
1070
+ }
1071
+ export function getUebgovAlertV2(id) {
1072
+ const j = _uebgovJsV2.get(id);
1073
+ if (!j) return null;
1074
+ return { ...j, metadata: { ...j.metadata } };
1075
+ }
1076
+ export function listUebgovAlertsV2() {
1077
+ return [..._uebgovJsV2.values()].map((j) => ({
1078
+ ...j,
1079
+ metadata: { ...j.metadata },
1080
+ }));
1081
+ }
1082
+ export function autoSuppressIdleUebgovProfilesV2({ now } = {}) {
1083
+ const t = now ?? Date.now();
1084
+ const flipped = [];
1085
+ for (const p of _uebgovPsV2.values())
1086
+ if (
1087
+ p.status === UEBGOV_PROFILE_MATURITY_V2.ACTIVE &&
1088
+ t - p.lastTouchedAt >= _uebgovIdleMs
1089
+ ) {
1090
+ p.status = UEBGOV_PROFILE_MATURITY_V2.SUPPRESSED;
1091
+ p.updatedAt = t;
1092
+ flipped.push(p.id);
1093
+ }
1094
+ return { flipped, count: flipped.length };
1095
+ }
1096
+ export function autoFailStuckUebgovAlertsV2({ now } = {}) {
1097
+ const t = now ?? Date.now();
1098
+ const flipped = [];
1099
+ for (const j of _uebgovJsV2.values())
1100
+ if (
1101
+ j.status === UEBGOV_ALERT_LIFECYCLE_V2.ANALYZING &&
1102
+ j.startedAt != null &&
1103
+ t - j.startedAt >= _uebgovStuckMs
1104
+ ) {
1105
+ j.status = UEBGOV_ALERT_LIFECYCLE_V2.FAILED;
1106
+ j.updatedAt = t;
1107
+ if (!j.settledAt) j.settledAt = t;
1108
+ j.metadata.failReason = "auto-fail-stuck";
1109
+ flipped.push(j.id);
1110
+ }
1111
+ return { flipped, count: flipped.length };
1112
+ }
1113
+ export function getUebaGovStatsV2() {
1114
+ const profilesByStatus = {};
1115
+ for (const v of Object.values(UEBGOV_PROFILE_MATURITY_V2))
1116
+ profilesByStatus[v] = 0;
1117
+ for (const p of _uebgovPsV2.values()) profilesByStatus[p.status]++;
1118
+ const alertsByStatus = {};
1119
+ for (const v of Object.values(UEBGOV_ALERT_LIFECYCLE_V2))
1120
+ alertsByStatus[v] = 0;
1121
+ for (const j of _uebgovJsV2.values()) alertsByStatus[j.status]++;
1122
+ return {
1123
+ totalUebgovProfilesV2: _uebgovPsV2.size,
1124
+ totalUebgovAlertsV2: _uebgovJsV2.size,
1125
+ maxActiveUebgovProfilesPerOwner: _uebgovMaxActive,
1126
+ maxPendingUebgovAlertsPerProfile: _uebgovMaxPending,
1127
+ uebgovProfileIdleMs: _uebgovIdleMs,
1128
+ uebgovAlertStuckMs: _uebgovStuckMs,
1129
+ profilesByStatus,
1130
+ alertsByStatus,
1131
+ };
1132
+ }