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
@@ -6,87 +6,332 @@ export {
6
6
  getFlagInfo,
7
7
  } from "../harness/feature-flags.js";
8
8
 
9
-
10
9
  // =====================================================================
11
10
  // Feature Flags V2 governance overlay (in-memory, atop legacy flags)
12
11
  // =====================================================================
13
12
  export const FFLAG_PROFILE_MATURITY_V2 = Object.freeze({
14
- PENDING: "pending", ACTIVE: "active", PAUSED: "paused", ARCHIVED: "archived",
13
+ PENDING: "pending",
14
+ ACTIVE: "active",
15
+ PAUSED: "paused",
16
+ ARCHIVED: "archived",
15
17
  });
16
18
  export const FFLAG_EVAL_LIFECYCLE_V2 = Object.freeze({
17
- QUEUED: "queued", EVALUATING: "evaluating", EVALUATED: "evaluated", FAILED: "failed", CANCELLED: "cancelled",
19
+ QUEUED: "queued",
20
+ EVALUATING: "evaluating",
21
+ EVALUATED: "evaluated",
22
+ FAILED: "failed",
23
+ CANCELLED: "cancelled",
18
24
  });
19
25
  const _fflagPTrans = new Map([
20
- [FFLAG_PROFILE_MATURITY_V2.PENDING, new Set([FFLAG_PROFILE_MATURITY_V2.ACTIVE, FFLAG_PROFILE_MATURITY_V2.ARCHIVED])],
21
- [FFLAG_PROFILE_MATURITY_V2.ACTIVE, new Set([FFLAG_PROFILE_MATURITY_V2.PAUSED, FFLAG_PROFILE_MATURITY_V2.ARCHIVED])],
22
- [FFLAG_PROFILE_MATURITY_V2.PAUSED, new Set([FFLAG_PROFILE_MATURITY_V2.ACTIVE, FFLAG_PROFILE_MATURITY_V2.ARCHIVED])],
26
+ [
27
+ FFLAG_PROFILE_MATURITY_V2.PENDING,
28
+ new Set([
29
+ FFLAG_PROFILE_MATURITY_V2.ACTIVE,
30
+ FFLAG_PROFILE_MATURITY_V2.ARCHIVED,
31
+ ]),
32
+ ],
33
+ [
34
+ FFLAG_PROFILE_MATURITY_V2.ACTIVE,
35
+ new Set([
36
+ FFLAG_PROFILE_MATURITY_V2.PAUSED,
37
+ FFLAG_PROFILE_MATURITY_V2.ARCHIVED,
38
+ ]),
39
+ ],
40
+ [
41
+ FFLAG_PROFILE_MATURITY_V2.PAUSED,
42
+ new Set([
43
+ FFLAG_PROFILE_MATURITY_V2.ACTIVE,
44
+ FFLAG_PROFILE_MATURITY_V2.ARCHIVED,
45
+ ]),
46
+ ],
23
47
  [FFLAG_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
24
48
  ]);
25
49
  const _fflagPTerminal = new Set([FFLAG_PROFILE_MATURITY_V2.ARCHIVED]);
26
50
  const _fflagETrans = new Map([
27
- [FFLAG_EVAL_LIFECYCLE_V2.QUEUED, new Set([FFLAG_EVAL_LIFECYCLE_V2.EVALUATING, FFLAG_EVAL_LIFECYCLE_V2.CANCELLED])],
28
- [FFLAG_EVAL_LIFECYCLE_V2.EVALUATING, new Set([FFLAG_EVAL_LIFECYCLE_V2.EVALUATED, FFLAG_EVAL_LIFECYCLE_V2.FAILED, FFLAG_EVAL_LIFECYCLE_V2.CANCELLED])],
51
+ [
52
+ FFLAG_EVAL_LIFECYCLE_V2.QUEUED,
53
+ new Set([
54
+ FFLAG_EVAL_LIFECYCLE_V2.EVALUATING,
55
+ FFLAG_EVAL_LIFECYCLE_V2.CANCELLED,
56
+ ]),
57
+ ],
58
+ [
59
+ FFLAG_EVAL_LIFECYCLE_V2.EVALUATING,
60
+ new Set([
61
+ FFLAG_EVAL_LIFECYCLE_V2.EVALUATED,
62
+ FFLAG_EVAL_LIFECYCLE_V2.FAILED,
63
+ FFLAG_EVAL_LIFECYCLE_V2.CANCELLED,
64
+ ]),
65
+ ],
29
66
  [FFLAG_EVAL_LIFECYCLE_V2.EVALUATED, new Set()],
30
67
  [FFLAG_EVAL_LIFECYCLE_V2.FAILED, new Set()],
31
68
  [FFLAG_EVAL_LIFECYCLE_V2.CANCELLED, new Set()],
32
69
  ]);
33
70
  const _fflagPsV2 = new Map();
34
71
  const _fflagEsV2 = new Map();
35
- let _fflagMaxActive = 15, _fflagMaxPending = 30, _fflagIdleMs = 30 * 24 * 60 * 60 * 1000, _fflagStuckMs = 30 * 1000;
36
- function _fflagPos(n, label) { const v = Math.floor(Number(n)); if (!Number.isFinite(v) || v <= 0) throw new Error(`${label} must be positive integer`); return v; }
37
- function _fflagCheckP(from, to) { const a = _fflagPTrans.get(from); if (!a || !a.has(to)) throw new Error(`invalid fflag profile transition ${from} → ${to}`); }
38
- function _fflagCheckE(from, to) { const a = _fflagETrans.get(from); if (!a || !a.has(to)) throw new Error(`invalid fflag eval transition ${from} → ${to}`); }
39
- function _fflagCountActive(owner) { let c = 0; for (const p of _fflagPsV2.values()) if (p.owner === owner && p.status === FFLAG_PROFILE_MATURITY_V2.ACTIVE) c++; return c; }
40
- function _fflagCountPending(profileId) { let c = 0; for (const e of _fflagEsV2.values()) if (e.profileId === profileId && (e.status === FFLAG_EVAL_LIFECYCLE_V2.QUEUED || e.status === FFLAG_EVAL_LIFECYCLE_V2.EVALUATING)) c++; return c; }
41
- export function setMaxActiveFflagProfilesPerOwnerV2(n) { _fflagMaxActive = _fflagPos(n, "maxActiveFflagProfilesPerOwner"); }
42
- export function getMaxActiveFflagProfilesPerOwnerV2() { return _fflagMaxActive; }
43
- export function setMaxPendingFflagEvalsPerProfileV2(n) { _fflagMaxPending = _fflagPos(n, "maxPendingFflagEvalsPerProfile"); }
44
- export function getMaxPendingFflagEvalsPerProfileV2() { return _fflagMaxPending; }
45
- export function setFflagProfileIdleMsV2(n) { _fflagIdleMs = _fflagPos(n, "fflagProfileIdleMs"); }
46
- export function getFflagProfileIdleMsV2() { return _fflagIdleMs; }
47
- export function setFflagEvalStuckMsV2(n) { _fflagStuckMs = _fflagPos(n, "fflagEvalStuckMs"); }
48
- export function getFflagEvalStuckMsV2() { return _fflagStuckMs; }
49
- export function _resetStateFeatureFlagsV2() { _fflagPsV2.clear(); _fflagEsV2.clear(); _fflagMaxActive = 15; _fflagMaxPending = 30; _fflagIdleMs = 30 * 24 * 60 * 60 * 1000; _fflagStuckMs = 30 * 1000; }
72
+ let _fflagMaxActive = 15,
73
+ _fflagMaxPending = 30,
74
+ _fflagIdleMs = 30 * 24 * 60 * 60 * 1000,
75
+ _fflagStuckMs = 30 * 1000;
76
+ function _fflagPos(n, label) {
77
+ const v = Math.floor(Number(n));
78
+ if (!Number.isFinite(v) || v <= 0)
79
+ throw new Error(`${label} must be positive integer`);
80
+ return v;
81
+ }
82
+ function _fflagCheckP(from, to) {
83
+ const a = _fflagPTrans.get(from);
84
+ if (!a || !a.has(to))
85
+ throw new Error(`invalid fflag profile transition ${from} ${to}`);
86
+ }
87
+ function _fflagCheckE(from, to) {
88
+ const a = _fflagETrans.get(from);
89
+ if (!a || !a.has(to))
90
+ throw new Error(`invalid fflag eval transition ${from} → ${to}`);
91
+ }
92
+ function _fflagCountActive(owner) {
93
+ let c = 0;
94
+ for (const p of _fflagPsV2.values())
95
+ if (p.owner === owner && p.status === FFLAG_PROFILE_MATURITY_V2.ACTIVE) c++;
96
+ return c;
97
+ }
98
+ function _fflagCountPending(profileId) {
99
+ let c = 0;
100
+ for (const e of _fflagEsV2.values())
101
+ if (
102
+ e.profileId === profileId &&
103
+ (e.status === FFLAG_EVAL_LIFECYCLE_V2.QUEUED ||
104
+ e.status === FFLAG_EVAL_LIFECYCLE_V2.EVALUATING)
105
+ )
106
+ c++;
107
+ return c;
108
+ }
109
+ export function setMaxActiveFflagProfilesPerOwnerV2(n) {
110
+ _fflagMaxActive = _fflagPos(n, "maxActiveFflagProfilesPerOwner");
111
+ }
112
+ export function getMaxActiveFflagProfilesPerOwnerV2() {
113
+ return _fflagMaxActive;
114
+ }
115
+ export function setMaxPendingFflagEvalsPerProfileV2(n) {
116
+ _fflagMaxPending = _fflagPos(n, "maxPendingFflagEvalsPerProfile");
117
+ }
118
+ export function getMaxPendingFflagEvalsPerProfileV2() {
119
+ return _fflagMaxPending;
120
+ }
121
+ export function setFflagProfileIdleMsV2(n) {
122
+ _fflagIdleMs = _fflagPos(n, "fflagProfileIdleMs");
123
+ }
124
+ export function getFflagProfileIdleMsV2() {
125
+ return _fflagIdleMs;
126
+ }
127
+ export function setFflagEvalStuckMsV2(n) {
128
+ _fflagStuckMs = _fflagPos(n, "fflagEvalStuckMs");
129
+ }
130
+ export function getFflagEvalStuckMsV2() {
131
+ return _fflagStuckMs;
132
+ }
133
+ export function _resetStateFeatureFlagsV2() {
134
+ _fflagPsV2.clear();
135
+ _fflagEsV2.clear();
136
+ _fflagMaxActive = 15;
137
+ _fflagMaxPending = 30;
138
+ _fflagIdleMs = 30 * 24 * 60 * 60 * 1000;
139
+ _fflagStuckMs = 30 * 1000;
140
+ }
50
141
  export function registerFflagProfileV2({ id, owner, scope, metadata } = {}) {
51
142
  if (!id || !owner) throw new Error("id and owner required");
52
143
  if (_fflagPsV2.has(id)) throw new Error(`fflag profile ${id} already exists`);
53
144
  const now = Date.now();
54
- const p = { id, owner, scope: scope || "*", status: FFLAG_PROFILE_MATURITY_V2.PENDING, createdAt: now, updatedAt: now, lastTouchedAt: now, activatedAt: null, archivedAt: null, metadata: { ...(metadata || {}) } };
55
- _fflagPsV2.set(id, p); return { ...p, metadata: { ...p.metadata } };
145
+ const p = {
146
+ id,
147
+ owner,
148
+ scope: scope || "*",
149
+ status: FFLAG_PROFILE_MATURITY_V2.PENDING,
150
+ createdAt: now,
151
+ updatedAt: now,
152
+ lastTouchedAt: now,
153
+ activatedAt: null,
154
+ archivedAt: null,
155
+ metadata: { ...(metadata || {}) },
156
+ };
157
+ _fflagPsV2.set(id, p);
158
+ return { ...p, metadata: { ...p.metadata } };
56
159
  }
57
160
  export function activateFflagProfileV2(id) {
58
- const p = _fflagPsV2.get(id); if (!p) throw new Error(`fflag profile ${id} not found`);
161
+ const p = _fflagPsV2.get(id);
162
+ if (!p) throw new Error(`fflag profile ${id} not found`);
59
163
  const isInitial = p.status === FFLAG_PROFILE_MATURITY_V2.PENDING;
60
164
  _fflagCheckP(p.status, FFLAG_PROFILE_MATURITY_V2.ACTIVE);
61
- if (isInitial && _fflagCountActive(p.owner) >= _fflagMaxActive) throw new Error(`max active fflag profiles for owner ${p.owner} reached`);
62
- const now = Date.now(); p.status = FFLAG_PROFILE_MATURITY_V2.ACTIVE; p.updatedAt = now; p.lastTouchedAt = now;
165
+ if (isInitial && _fflagCountActive(p.owner) >= _fflagMaxActive)
166
+ throw new Error(`max active fflag profiles for owner ${p.owner} reached`);
167
+ const now = Date.now();
168
+ p.status = FFLAG_PROFILE_MATURITY_V2.ACTIVE;
169
+ p.updatedAt = now;
170
+ p.lastTouchedAt = now;
63
171
  if (!p.activatedAt) p.activatedAt = now;
64
172
  return { ...p, metadata: { ...p.metadata } };
65
173
  }
66
- export function pauseFflagProfileV2(id) { const p = _fflagPsV2.get(id); if (!p) throw new Error(`fflag profile ${id} not found`); _fflagCheckP(p.status, FFLAG_PROFILE_MATURITY_V2.PAUSED); p.status = FFLAG_PROFILE_MATURITY_V2.PAUSED; p.updatedAt = Date.now(); return { ...p, metadata: { ...p.metadata } }; }
67
- export function archiveFflagProfileV2(id) { const p = _fflagPsV2.get(id); if (!p) throw new Error(`fflag profile ${id} not found`); _fflagCheckP(p.status, FFLAG_PROFILE_MATURITY_V2.ARCHIVED); const now = Date.now(); p.status = FFLAG_PROFILE_MATURITY_V2.ARCHIVED; p.updatedAt = now; if (!p.archivedAt) p.archivedAt = now; return { ...p, metadata: { ...p.metadata } }; }
68
- export function touchFflagProfileV2(id) { const p = _fflagPsV2.get(id); if (!p) throw new Error(`fflag profile ${id} not found`); if (_fflagPTerminal.has(p.status)) throw new Error(`cannot touch terminal fflag profile ${id}`); const now = Date.now(); p.lastTouchedAt = now; p.updatedAt = now; return { ...p, metadata: { ...p.metadata } }; }
69
- export function getFflagProfileV2(id) { const p = _fflagPsV2.get(id); if (!p) return null; return { ...p, metadata: { ...p.metadata } }; }
70
- export function listFflagProfilesV2() { return [..._fflagPsV2.values()].map((p) => ({ ...p, metadata: { ...p.metadata } })); }
174
+ export function pauseFflagProfileV2(id) {
175
+ const p = _fflagPsV2.get(id);
176
+ if (!p) throw new Error(`fflag profile ${id} not found`);
177
+ _fflagCheckP(p.status, FFLAG_PROFILE_MATURITY_V2.PAUSED);
178
+ p.status = FFLAG_PROFILE_MATURITY_V2.PAUSED;
179
+ p.updatedAt = Date.now();
180
+ return { ...p, metadata: { ...p.metadata } };
181
+ }
182
+ export function archiveFflagProfileV2(id) {
183
+ const p = _fflagPsV2.get(id);
184
+ if (!p) throw new Error(`fflag profile ${id} not found`);
185
+ _fflagCheckP(p.status, FFLAG_PROFILE_MATURITY_V2.ARCHIVED);
186
+ const now = Date.now();
187
+ p.status = FFLAG_PROFILE_MATURITY_V2.ARCHIVED;
188
+ p.updatedAt = now;
189
+ if (!p.archivedAt) p.archivedAt = now;
190
+ return { ...p, metadata: { ...p.metadata } };
191
+ }
192
+ export function touchFflagProfileV2(id) {
193
+ const p = _fflagPsV2.get(id);
194
+ if (!p) throw new Error(`fflag profile ${id} not found`);
195
+ if (_fflagPTerminal.has(p.status))
196
+ throw new Error(`cannot touch terminal fflag profile ${id}`);
197
+ const now = Date.now();
198
+ p.lastTouchedAt = now;
199
+ p.updatedAt = now;
200
+ return { ...p, metadata: { ...p.metadata } };
201
+ }
202
+ export function getFflagProfileV2(id) {
203
+ const p = _fflagPsV2.get(id);
204
+ if (!p) return null;
205
+ return { ...p, metadata: { ...p.metadata } };
206
+ }
207
+ export function listFflagProfilesV2() {
208
+ return [..._fflagPsV2.values()].map((p) => ({
209
+ ...p,
210
+ metadata: { ...p.metadata },
211
+ }));
212
+ }
71
213
  export function createFflagEvalV2({ id, profileId, key, metadata } = {}) {
72
214
  if (!id || !profileId) throw new Error("id and profileId required");
73
215
  if (_fflagEsV2.has(id)) throw new Error(`fflag eval ${id} already exists`);
74
- if (!_fflagPsV2.has(profileId)) throw new Error(`fflag profile ${profileId} not found`);
75
- if (_fflagCountPending(profileId) >= _fflagMaxPending) throw new Error(`max pending fflag evals for profile ${profileId} reached`);
216
+ if (!_fflagPsV2.has(profileId))
217
+ throw new Error(`fflag profile ${profileId} not found`);
218
+ if (_fflagCountPending(profileId) >= _fflagMaxPending)
219
+ throw new Error(`max pending fflag evals for profile ${profileId} reached`);
220
+ const now = Date.now();
221
+ const e = {
222
+ id,
223
+ profileId,
224
+ key: key || "",
225
+ status: FFLAG_EVAL_LIFECYCLE_V2.QUEUED,
226
+ createdAt: now,
227
+ updatedAt: now,
228
+ startedAt: null,
229
+ settledAt: null,
230
+ metadata: { ...(metadata || {}) },
231
+ };
232
+ _fflagEsV2.set(id, e);
233
+ return { ...e, metadata: { ...e.metadata } };
234
+ }
235
+ export function evaluatingFflagEvalV2(id) {
236
+ const e = _fflagEsV2.get(id);
237
+ if (!e) throw new Error(`fflag eval ${id} not found`);
238
+ _fflagCheckE(e.status, FFLAG_EVAL_LIFECYCLE_V2.EVALUATING);
239
+ const now = Date.now();
240
+ e.status = FFLAG_EVAL_LIFECYCLE_V2.EVALUATING;
241
+ e.updatedAt = now;
242
+ if (!e.startedAt) e.startedAt = now;
243
+ return { ...e, metadata: { ...e.metadata } };
244
+ }
245
+ export function evaluateFflagEvalV2(id) {
246
+ const e = _fflagEsV2.get(id);
247
+ if (!e) throw new Error(`fflag eval ${id} not found`);
248
+ _fflagCheckE(e.status, FFLAG_EVAL_LIFECYCLE_V2.EVALUATED);
249
+ const now = Date.now();
250
+ e.status = FFLAG_EVAL_LIFECYCLE_V2.EVALUATED;
251
+ e.updatedAt = now;
252
+ if (!e.settledAt) e.settledAt = now;
253
+ return { ...e, metadata: { ...e.metadata } };
254
+ }
255
+ export function failFflagEvalV2(id, reason) {
256
+ const e = _fflagEsV2.get(id);
257
+ if (!e) throw new Error(`fflag eval ${id} not found`);
258
+ _fflagCheckE(e.status, FFLAG_EVAL_LIFECYCLE_V2.FAILED);
259
+ const now = Date.now();
260
+ e.status = FFLAG_EVAL_LIFECYCLE_V2.FAILED;
261
+ e.updatedAt = now;
262
+ if (!e.settledAt) e.settledAt = now;
263
+ if (reason) e.metadata.failReason = String(reason);
264
+ return { ...e, metadata: { ...e.metadata } };
265
+ }
266
+ export function cancelFflagEvalV2(id, reason) {
267
+ const e = _fflagEsV2.get(id);
268
+ if (!e) throw new Error(`fflag eval ${id} not found`);
269
+ _fflagCheckE(e.status, FFLAG_EVAL_LIFECYCLE_V2.CANCELLED);
76
270
  const now = Date.now();
77
- const e = { id, profileId, key: key || "", status: FFLAG_EVAL_LIFECYCLE_V2.QUEUED, createdAt: now, updatedAt: now, startedAt: null, settledAt: null, metadata: { ...(metadata || {}) } };
78
- _fflagEsV2.set(id, e); return { ...e, metadata: { ...e.metadata } };
79
- }
80
- export function evaluatingFflagEvalV2(id) { const e = _fflagEsV2.get(id); if (!e) throw new Error(`fflag eval ${id} not found`); _fflagCheckE(e.status, FFLAG_EVAL_LIFECYCLE_V2.EVALUATING); const now = Date.now(); e.status = FFLAG_EVAL_LIFECYCLE_V2.EVALUATING; e.updatedAt = now; if (!e.startedAt) e.startedAt = now; return { ...e, metadata: { ...e.metadata } }; }
81
- export function evaluateFflagEvalV2(id) { const e = _fflagEsV2.get(id); if (!e) throw new Error(`fflag eval ${id} not found`); _fflagCheckE(e.status, FFLAG_EVAL_LIFECYCLE_V2.EVALUATED); const now = Date.now(); e.status = FFLAG_EVAL_LIFECYCLE_V2.EVALUATED; e.updatedAt = now; if (!e.settledAt) e.settledAt = now; return { ...e, metadata: { ...e.metadata } }; }
82
- export function failFflagEvalV2(id, reason) { const e = _fflagEsV2.get(id); if (!e) throw new Error(`fflag eval ${id} not found`); _fflagCheckE(e.status, FFLAG_EVAL_LIFECYCLE_V2.FAILED); const now = Date.now(); e.status = FFLAG_EVAL_LIFECYCLE_V2.FAILED; e.updatedAt = now; if (!e.settledAt) e.settledAt = now; if (reason) e.metadata.failReason = String(reason); return { ...e, metadata: { ...e.metadata } }; }
83
- export function cancelFflagEvalV2(id, reason) { const e = _fflagEsV2.get(id); if (!e) throw new Error(`fflag eval ${id} not found`); _fflagCheckE(e.status, FFLAG_EVAL_LIFECYCLE_V2.CANCELLED); const now = Date.now(); e.status = FFLAG_EVAL_LIFECYCLE_V2.CANCELLED; e.updatedAt = now; if (!e.settledAt) e.settledAt = now; if (reason) e.metadata.cancelReason = String(reason); return { ...e, metadata: { ...e.metadata } }; }
84
- export function getFflagEvalV2(id) { const e = _fflagEsV2.get(id); if (!e) return null; return { ...e, metadata: { ...e.metadata } }; }
85
- export function listFflagEvalsV2() { return [..._fflagEsV2.values()].map((e) => ({ ...e, metadata: { ...e.metadata } })); }
86
- export function autoPauseIdleFflagProfilesV2({ now } = {}) { const t = now ?? Date.now(); const flipped = []; for (const p of _fflagPsV2.values()) if (p.status === FFLAG_PROFILE_MATURITY_V2.ACTIVE && (t - p.lastTouchedAt) >= _fflagIdleMs) { p.status = FFLAG_PROFILE_MATURITY_V2.PAUSED; p.updatedAt = t; flipped.push(p.id); } return { flipped, count: flipped.length }; }
87
- export function autoFailStuckFflagEvalsV2({ now } = {}) { const t = now ?? Date.now(); const flipped = []; for (const e of _fflagEsV2.values()) if (e.status === FFLAG_EVAL_LIFECYCLE_V2.EVALUATING && e.startedAt != null && (t - e.startedAt) >= _fflagStuckMs) { e.status = FFLAG_EVAL_LIFECYCLE_V2.FAILED; e.updatedAt = t; if (!e.settledAt) e.settledAt = t; e.metadata.failReason = "auto-fail-stuck"; flipped.push(e.id); } return { flipped, count: flipped.length }; }
271
+ e.status = FFLAG_EVAL_LIFECYCLE_V2.CANCELLED;
272
+ e.updatedAt = now;
273
+ if (!e.settledAt) e.settledAt = now;
274
+ if (reason) e.metadata.cancelReason = String(reason);
275
+ return { ...e, metadata: { ...e.metadata } };
276
+ }
277
+ export function getFflagEvalV2(id) {
278
+ const e = _fflagEsV2.get(id);
279
+ if (!e) return null;
280
+ return { ...e, metadata: { ...e.metadata } };
281
+ }
282
+ export function listFflagEvalsV2() {
283
+ return [..._fflagEsV2.values()].map((e) => ({
284
+ ...e,
285
+ metadata: { ...e.metadata },
286
+ }));
287
+ }
288
+ export function autoPauseIdleFflagProfilesV2({ now } = {}) {
289
+ const t = now ?? Date.now();
290
+ const flipped = [];
291
+ for (const p of _fflagPsV2.values())
292
+ if (
293
+ p.status === FFLAG_PROFILE_MATURITY_V2.ACTIVE &&
294
+ t - p.lastTouchedAt >= _fflagIdleMs
295
+ ) {
296
+ p.status = FFLAG_PROFILE_MATURITY_V2.PAUSED;
297
+ p.updatedAt = t;
298
+ flipped.push(p.id);
299
+ }
300
+ return { flipped, count: flipped.length };
301
+ }
302
+ export function autoFailStuckFflagEvalsV2({ now } = {}) {
303
+ const t = now ?? Date.now();
304
+ const flipped = [];
305
+ for (const e of _fflagEsV2.values())
306
+ if (
307
+ e.status === FFLAG_EVAL_LIFECYCLE_V2.EVALUATING &&
308
+ e.startedAt != null &&
309
+ t - e.startedAt >= _fflagStuckMs
310
+ ) {
311
+ e.status = FFLAG_EVAL_LIFECYCLE_V2.FAILED;
312
+ e.updatedAt = t;
313
+ if (!e.settledAt) e.settledAt = t;
314
+ e.metadata.failReason = "auto-fail-stuck";
315
+ flipped.push(e.id);
316
+ }
317
+ return { flipped, count: flipped.length };
318
+ }
88
319
  export function getFeatureFlagsGovStatsV2() {
89
- const profilesByStatus = {}; for (const v of Object.values(FFLAG_PROFILE_MATURITY_V2)) profilesByStatus[v] = 0; for (const p of _fflagPsV2.values()) profilesByStatus[p.status]++;
90
- const evalsByStatus = {}; for (const v of Object.values(FFLAG_EVAL_LIFECYCLE_V2)) evalsByStatus[v] = 0; for (const e of _fflagEsV2.values()) evalsByStatus[e.status]++;
91
- return { totalFflagProfilesV2: _fflagPsV2.size, totalFflagEvalsV2: _fflagEsV2.size, maxActiveFflagProfilesPerOwner: _fflagMaxActive, maxPendingFflagEvalsPerProfile: _fflagMaxPending, fflagProfileIdleMs: _fflagIdleMs, fflagEvalStuckMs: _fflagStuckMs, profilesByStatus, evalsByStatus };
320
+ const profilesByStatus = {};
321
+ for (const v of Object.values(FFLAG_PROFILE_MATURITY_V2))
322
+ profilesByStatus[v] = 0;
323
+ for (const p of _fflagPsV2.values()) profilesByStatus[p.status]++;
324
+ const evalsByStatus = {};
325
+ for (const v of Object.values(FFLAG_EVAL_LIFECYCLE_V2)) evalsByStatus[v] = 0;
326
+ for (const e of _fflagEsV2.values()) evalsByStatus[e.status]++;
327
+ return {
328
+ totalFflagProfilesV2: _fflagPsV2.size,
329
+ totalFflagEvalsV2: _fflagEsV2.size,
330
+ maxActiveFflagProfilesPerOwner: _fflagMaxActive,
331
+ maxPendingFflagEvalsPerProfile: _fflagMaxPending,
332
+ fflagProfileIdleMs: _fflagIdleMs,
333
+ fflagEvalStuckMs: _fflagStuckMs,
334
+ profilesByStatus,
335
+ evalsByStatus,
336
+ };
92
337
  }