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
@@ -174,25 +174,59 @@ export const DEFAULT_ITERATION_BUDGET = DEFAULT_BUDGET;
174
174
  export const BUDGET_WARNING_THRESHOLD = WARNING_THRESHOLD;
175
175
  export const BUDGET_WRAPPING_UP_THRESHOLD = WRAPPING_UP_THRESHOLD;
176
176
 
177
-
178
177
  // ===== V2 Surface: Iteration Budget governance overlay (CLI v0.140.0) =====
179
178
  export const ITER_BUDGET_PROFILE_MATURITY_V2 = Object.freeze({
180
- PENDING: "pending", ACTIVE: "active", PAUSED: "paused", EXHAUSTED: "exhausted",
179
+ PENDING: "pending",
180
+ ACTIVE: "active",
181
+ PAUSED: "paused",
182
+ EXHAUSTED: "exhausted",
181
183
  });
182
184
  export const ITER_RUN_LIFECYCLE_V2 = Object.freeze({
183
- QUEUED: "queued", RUNNING: "running", COMPLETED: "completed", FAILED: "failed", CANCELLED: "cancelled",
185
+ QUEUED: "queued",
186
+ RUNNING: "running",
187
+ COMPLETED: "completed",
188
+ FAILED: "failed",
189
+ CANCELLED: "cancelled",
184
190
  });
185
191
 
186
192
  const _ibpTrans = new Map([
187
- [ITER_BUDGET_PROFILE_MATURITY_V2.PENDING, new Set([ITER_BUDGET_PROFILE_MATURITY_V2.ACTIVE, ITER_BUDGET_PROFILE_MATURITY_V2.EXHAUSTED])],
188
- [ITER_BUDGET_PROFILE_MATURITY_V2.ACTIVE, new Set([ITER_BUDGET_PROFILE_MATURITY_V2.PAUSED, ITER_BUDGET_PROFILE_MATURITY_V2.EXHAUSTED])],
189
- [ITER_BUDGET_PROFILE_MATURITY_V2.PAUSED, new Set([ITER_BUDGET_PROFILE_MATURITY_V2.ACTIVE, ITER_BUDGET_PROFILE_MATURITY_V2.EXHAUSTED])],
193
+ [
194
+ ITER_BUDGET_PROFILE_MATURITY_V2.PENDING,
195
+ new Set([
196
+ ITER_BUDGET_PROFILE_MATURITY_V2.ACTIVE,
197
+ ITER_BUDGET_PROFILE_MATURITY_V2.EXHAUSTED,
198
+ ]),
199
+ ],
200
+ [
201
+ ITER_BUDGET_PROFILE_MATURITY_V2.ACTIVE,
202
+ new Set([
203
+ ITER_BUDGET_PROFILE_MATURITY_V2.PAUSED,
204
+ ITER_BUDGET_PROFILE_MATURITY_V2.EXHAUSTED,
205
+ ]),
206
+ ],
207
+ [
208
+ ITER_BUDGET_PROFILE_MATURITY_V2.PAUSED,
209
+ new Set([
210
+ ITER_BUDGET_PROFILE_MATURITY_V2.ACTIVE,
211
+ ITER_BUDGET_PROFILE_MATURITY_V2.EXHAUSTED,
212
+ ]),
213
+ ],
190
214
  [ITER_BUDGET_PROFILE_MATURITY_V2.EXHAUSTED, new Set()],
191
215
  ]);
192
216
  const _ibpTerminal = new Set([ITER_BUDGET_PROFILE_MATURITY_V2.EXHAUSTED]);
193
217
  const _irTrans = new Map([
194
- [ITER_RUN_LIFECYCLE_V2.QUEUED, new Set([ITER_RUN_LIFECYCLE_V2.RUNNING, ITER_RUN_LIFECYCLE_V2.CANCELLED])],
195
- [ITER_RUN_LIFECYCLE_V2.RUNNING, new Set([ITER_RUN_LIFECYCLE_V2.COMPLETED, ITER_RUN_LIFECYCLE_V2.FAILED, ITER_RUN_LIFECYCLE_V2.CANCELLED])],
218
+ [
219
+ ITER_RUN_LIFECYCLE_V2.QUEUED,
220
+ new Set([ITER_RUN_LIFECYCLE_V2.RUNNING, ITER_RUN_LIFECYCLE_V2.CANCELLED]),
221
+ ],
222
+ [
223
+ ITER_RUN_LIFECYCLE_V2.RUNNING,
224
+ new Set([
225
+ ITER_RUN_LIFECYCLE_V2.COMPLETED,
226
+ ITER_RUN_LIFECYCLE_V2.FAILED,
227
+ ITER_RUN_LIFECYCLE_V2.CANCELLED,
228
+ ]),
229
+ ],
196
230
  [ITER_RUN_LIFECYCLE_V2.COMPLETED, new Set()],
197
231
  [ITER_RUN_LIFECYCLE_V2.FAILED, new Set()],
198
232
  [ITER_RUN_LIFECYCLE_V2.CANCELLED, new Set()],
@@ -205,76 +239,294 @@ let _ibpMaxPendingRunsPerProfile = 8;
205
239
  let _ibpIdleMs = 24 * 60 * 60 * 1000;
206
240
  let _irStuckMs = 60 * 60 * 1000;
207
241
 
208
- function _ibpPos(n, lbl) { const v = Math.floor(Number(n)); if (!Number.isFinite(v) || v <= 0) throw new Error(`${lbl} must be positive integer`); return v; }
242
+ function _ibpPos(n, lbl) {
243
+ const v = Math.floor(Number(n));
244
+ if (!Number.isFinite(v) || v <= 0)
245
+ throw new Error(`${lbl} must be positive integer`);
246
+ return v;
247
+ }
209
248
 
210
- export function setMaxActiveIterBudgetProfilesPerOwnerV2(n) { _ibpMaxActivePerOwner = _ibpPos(n, "maxActiveIterBudgetProfilesPerOwner"); }
211
- export function getMaxActiveIterBudgetProfilesPerOwnerV2() { return _ibpMaxActivePerOwner; }
212
- export function setMaxPendingIterRunsPerProfileV2(n) { _ibpMaxPendingRunsPerProfile = _ibpPos(n, "maxPendingIterRunsPerProfile"); }
213
- export function getMaxPendingIterRunsPerProfileV2() { return _ibpMaxPendingRunsPerProfile; }
214
- export function setIterBudgetProfileIdleMsV2(n) { _ibpIdleMs = _ibpPos(n, "iterBudgetProfileIdleMs"); }
215
- export function getIterBudgetProfileIdleMsV2() { return _ibpIdleMs; }
216
- export function setIterRunStuckMsV2(n) { _irStuckMs = _ibpPos(n, "iterRunStuckMs"); }
217
- export function getIterRunStuckMsV2() { return _irStuckMs; }
249
+ export function setMaxActiveIterBudgetProfilesPerOwnerV2(n) {
250
+ _ibpMaxActivePerOwner = _ibpPos(n, "maxActiveIterBudgetProfilesPerOwner");
251
+ }
252
+ export function getMaxActiveIterBudgetProfilesPerOwnerV2() {
253
+ return _ibpMaxActivePerOwner;
254
+ }
255
+ export function setMaxPendingIterRunsPerProfileV2(n) {
256
+ _ibpMaxPendingRunsPerProfile = _ibpPos(n, "maxPendingIterRunsPerProfile");
257
+ }
258
+ export function getMaxPendingIterRunsPerProfileV2() {
259
+ return _ibpMaxPendingRunsPerProfile;
260
+ }
261
+ export function setIterBudgetProfileIdleMsV2(n) {
262
+ _ibpIdleMs = _ibpPos(n, "iterBudgetProfileIdleMs");
263
+ }
264
+ export function getIterBudgetProfileIdleMsV2() {
265
+ return _ibpIdleMs;
266
+ }
267
+ export function setIterRunStuckMsV2(n) {
268
+ _irStuckMs = _ibpPos(n, "iterRunStuckMs");
269
+ }
270
+ export function getIterRunStuckMsV2() {
271
+ return _irStuckMs;
272
+ }
218
273
 
219
274
  export function _resetStateIterationBudgetV2() {
220
- _ibpsV2.clear(); _irsV2.clear();
221
- _ibpMaxActivePerOwner = 4; _ibpMaxPendingRunsPerProfile = 8;
222
- _ibpIdleMs = 24 * 60 * 60 * 1000; _irStuckMs = 60 * 60 * 1000;
275
+ _ibpsV2.clear();
276
+ _irsV2.clear();
277
+ _ibpMaxActivePerOwner = 4;
278
+ _ibpMaxPendingRunsPerProfile = 8;
279
+ _ibpIdleMs = 24 * 60 * 60 * 1000;
280
+ _irStuckMs = 60 * 60 * 1000;
223
281
  }
224
282
 
225
- export function registerIterBudgetProfileV2({ id, owner, budget, metadata } = {}) {
283
+ export function registerIterBudgetProfileV2({
284
+ id,
285
+ owner,
286
+ budget,
287
+ metadata,
288
+ } = {}) {
226
289
  if (!id || typeof id !== "string") throw new Error("id is required");
227
290
  if (!owner || typeof owner !== "string") throw new Error("owner is required");
228
- if (_ibpsV2.has(id)) throw new Error(`iter budget profile ${id} already registered`);
291
+ if (_ibpsV2.has(id))
292
+ throw new Error(`iter budget profile ${id} already registered`);
229
293
  const now = Date.now();
230
- const p = { id, owner, budget: budget || 50, status: ITER_BUDGET_PROFILE_MATURITY_V2.PENDING, createdAt: now, updatedAt: now, activatedAt: null, exhaustedAt: null, lastTouchedAt: now, metadata: { ...(metadata || {}) } };
294
+ const p = {
295
+ id,
296
+ owner,
297
+ budget: budget || 50,
298
+ status: ITER_BUDGET_PROFILE_MATURITY_V2.PENDING,
299
+ createdAt: now,
300
+ updatedAt: now,
301
+ activatedAt: null,
302
+ exhaustedAt: null,
303
+ lastTouchedAt: now,
304
+ metadata: { ...(metadata || {}) },
305
+ };
231
306
  _ibpsV2.set(id, p);
232
307
  return { ...p, metadata: { ...p.metadata } };
233
308
  }
234
- function _ibpCheckP(from, to) { const a = _ibpTrans.get(from); if (!a || !a.has(to)) throw new Error(`invalid iter budget profile transition ${from} → ${to}`); }
235
- function _ibpCountActive(owner) { let n = 0; for (const p of _ibpsV2.values()) if (p.owner === owner && p.status === ITER_BUDGET_PROFILE_MATURITY_V2.ACTIVE) n++; return n; }
309
+ function _ibpCheckP(from, to) {
310
+ const a = _ibpTrans.get(from);
311
+ if (!a || !a.has(to))
312
+ throw new Error(`invalid iter budget profile transition ${from} → ${to}`);
313
+ }
314
+ function _ibpCountActive(owner) {
315
+ let n = 0;
316
+ for (const p of _ibpsV2.values())
317
+ if (
318
+ p.owner === owner &&
319
+ p.status === ITER_BUDGET_PROFILE_MATURITY_V2.ACTIVE
320
+ )
321
+ n++;
322
+ return n;
323
+ }
236
324
 
237
325
  export function activateIterBudgetProfileV2(id) {
238
- const p = _ibpsV2.get(id); if (!p) throw new Error(`iter budget profile ${id} not found`);
326
+ const p = _ibpsV2.get(id);
327
+ if (!p) throw new Error(`iter budget profile ${id} not found`);
239
328
  _ibpCheckP(p.status, ITER_BUDGET_PROFILE_MATURITY_V2.ACTIVE);
240
329
  const recovery = p.status === ITER_BUDGET_PROFILE_MATURITY_V2.PAUSED;
241
- if (!recovery) { const c = _ibpCountActive(p.owner); if (c >= _ibpMaxActivePerOwner) throw new Error(`max active iter budget profiles per owner (${_ibpMaxActivePerOwner}) reached for ${p.owner}`); }
242
- const now = Date.now(); p.status = ITER_BUDGET_PROFILE_MATURITY_V2.ACTIVE; p.updatedAt = now; p.lastTouchedAt = now; if (!p.activatedAt) p.activatedAt = now;
330
+ if (!recovery) {
331
+ const c = _ibpCountActive(p.owner);
332
+ if (c >= _ibpMaxActivePerOwner)
333
+ throw new Error(
334
+ `max active iter budget profiles per owner (${_ibpMaxActivePerOwner}) reached for ${p.owner}`,
335
+ );
336
+ }
337
+ const now = Date.now();
338
+ p.status = ITER_BUDGET_PROFILE_MATURITY_V2.ACTIVE;
339
+ p.updatedAt = now;
340
+ p.lastTouchedAt = now;
341
+ if (!p.activatedAt) p.activatedAt = now;
342
+ return { ...p, metadata: { ...p.metadata } };
343
+ }
344
+ export function pauseIterBudgetProfileV2(id) {
345
+ const p = _ibpsV2.get(id);
346
+ if (!p) throw new Error(`iter budget profile ${id} not found`);
347
+ _ibpCheckP(p.status, ITER_BUDGET_PROFILE_MATURITY_V2.PAUSED);
348
+ p.status = ITER_BUDGET_PROFILE_MATURITY_V2.PAUSED;
349
+ p.updatedAt = Date.now();
350
+ return { ...p, metadata: { ...p.metadata } };
351
+ }
352
+ export function exhaustIterBudgetProfileV2(id) {
353
+ const p = _ibpsV2.get(id);
354
+ if (!p) throw new Error(`iter budget profile ${id} not found`);
355
+ _ibpCheckP(p.status, ITER_BUDGET_PROFILE_MATURITY_V2.EXHAUSTED);
356
+ const now = Date.now();
357
+ p.status = ITER_BUDGET_PROFILE_MATURITY_V2.EXHAUSTED;
358
+ p.updatedAt = now;
359
+ if (!p.exhaustedAt) p.exhaustedAt = now;
360
+ return { ...p, metadata: { ...p.metadata } };
361
+ }
362
+ export function touchIterBudgetProfileV2(id) {
363
+ const p = _ibpsV2.get(id);
364
+ if (!p) throw new Error(`iter budget profile ${id} not found`);
365
+ if (_ibpTerminal.has(p.status))
366
+ throw new Error(`cannot touch terminal iter budget profile ${id}`);
367
+ const now = Date.now();
368
+ p.lastTouchedAt = now;
369
+ p.updatedAt = now;
370
+ return { ...p, metadata: { ...p.metadata } };
371
+ }
372
+ export function getIterBudgetProfileV2(id) {
373
+ const p = _ibpsV2.get(id);
374
+ if (!p) return null;
243
375
  return { ...p, metadata: { ...p.metadata } };
244
376
  }
245
- export function pauseIterBudgetProfileV2(id) { const p = _ibpsV2.get(id); if (!p) throw new Error(`iter budget profile ${id} not found`); _ibpCheckP(p.status, ITER_BUDGET_PROFILE_MATURITY_V2.PAUSED); p.status = ITER_BUDGET_PROFILE_MATURITY_V2.PAUSED; p.updatedAt = Date.now(); return { ...p, metadata: { ...p.metadata } }; }
246
- export function exhaustIterBudgetProfileV2(id) { const p = _ibpsV2.get(id); if (!p) throw new Error(`iter budget profile ${id} not found`); _ibpCheckP(p.status, ITER_BUDGET_PROFILE_MATURITY_V2.EXHAUSTED); const now = Date.now(); p.status = ITER_BUDGET_PROFILE_MATURITY_V2.EXHAUSTED; p.updatedAt = now; if (!p.exhaustedAt) p.exhaustedAt = now; return { ...p, metadata: { ...p.metadata } }; }
247
- export function touchIterBudgetProfileV2(id) { const p = _ibpsV2.get(id); if (!p) throw new Error(`iter budget profile ${id} not found`); if (_ibpTerminal.has(p.status)) throw new Error(`cannot touch terminal iter budget profile ${id}`); const now = Date.now(); p.lastTouchedAt = now; p.updatedAt = now; return { ...p, metadata: { ...p.metadata } }; }
248
- export function getIterBudgetProfileV2(id) { const p = _ibpsV2.get(id); if (!p) return null; return { ...p, metadata: { ...p.metadata } }; }
249
- export function listIterBudgetProfilesV2() { return [..._ibpsV2.values()].map((p) => ({ ...p, metadata: { ...p.metadata } })); }
377
+ export function listIterBudgetProfilesV2() {
378
+ return [..._ibpsV2.values()].map((p) => ({
379
+ ...p,
380
+ metadata: { ...p.metadata },
381
+ }));
382
+ }
250
383
 
251
- function _irCountPending(profileId) { let n = 0; for (const r of _irsV2.values()) if (r.profileId === profileId && (r.status === ITER_RUN_LIFECYCLE_V2.QUEUED || r.status === ITER_RUN_LIFECYCLE_V2.RUNNING)) n++; return n; }
384
+ function _irCountPending(profileId) {
385
+ let n = 0;
386
+ for (const r of _irsV2.values())
387
+ if (
388
+ r.profileId === profileId &&
389
+ (r.status === ITER_RUN_LIFECYCLE_V2.QUEUED ||
390
+ r.status === ITER_RUN_LIFECYCLE_V2.RUNNING)
391
+ )
392
+ n++;
393
+ return n;
394
+ }
252
395
 
253
396
  export function createIterRunV2({ id, profileId, goal, metadata } = {}) {
254
397
  if (!id || typeof id !== "string") throw new Error("id is required");
255
- if (!profileId || typeof profileId !== "string") throw new Error("profileId is required");
398
+ if (!profileId || typeof profileId !== "string")
399
+ throw new Error("profileId is required");
256
400
  if (_irsV2.has(id)) throw new Error(`iter run ${id} already exists`);
257
- if (!_ibpsV2.has(profileId)) throw new Error(`iter budget profile ${profileId} not found`);
401
+ if (!_ibpsV2.has(profileId))
402
+ throw new Error(`iter budget profile ${profileId} not found`);
258
403
  const pending = _irCountPending(profileId);
259
- if (pending >= _ibpMaxPendingRunsPerProfile) throw new Error(`max pending iter runs per profile (${_ibpMaxPendingRunsPerProfile}) reached for ${profileId}`);
404
+ if (pending >= _ibpMaxPendingRunsPerProfile)
405
+ throw new Error(
406
+ `max pending iter runs per profile (${_ibpMaxPendingRunsPerProfile}) reached for ${profileId}`,
407
+ );
260
408
  const now = Date.now();
261
- const r = { id, profileId, goal: goal || "", status: ITER_RUN_LIFECYCLE_V2.QUEUED, createdAt: now, updatedAt: now, startedAt: null, settledAt: null, metadata: { ...(metadata || {}) } };
409
+ const r = {
410
+ id,
411
+ profileId,
412
+ goal: goal || "",
413
+ status: ITER_RUN_LIFECYCLE_V2.QUEUED,
414
+ createdAt: now,
415
+ updatedAt: now,
416
+ startedAt: null,
417
+ settledAt: null,
418
+ metadata: { ...(metadata || {}) },
419
+ };
262
420
  _irsV2.set(id, r);
263
421
  return { ...r, metadata: { ...r.metadata } };
264
422
  }
265
- function _irCheckR(from, to) { const a = _irTrans.get(from); if (!a || !a.has(to)) throw new Error(`invalid iter run transition ${from} → ${to}`); }
266
- export function startIterRunV2(id) { const r = _irsV2.get(id); if (!r) throw new Error(`iter run ${id} not found`); _irCheckR(r.status, ITER_RUN_LIFECYCLE_V2.RUNNING); const now = Date.now(); r.status = ITER_RUN_LIFECYCLE_V2.RUNNING; r.updatedAt = now; if (!r.startedAt) r.startedAt = now; return { ...r, metadata: { ...r.metadata } }; }
267
- export function completeIterRunV2(id) { const r = _irsV2.get(id); if (!r) throw new Error(`iter run ${id} not found`); _irCheckR(r.status, ITER_RUN_LIFECYCLE_V2.COMPLETED); const now = Date.now(); r.status = ITER_RUN_LIFECYCLE_V2.COMPLETED; r.updatedAt = now; if (!r.settledAt) r.settledAt = now; return { ...r, metadata: { ...r.metadata } }; }
268
- export function failIterRunV2(id, reason) { const r = _irsV2.get(id); if (!r) throw new Error(`iter run ${id} not found`); _irCheckR(r.status, ITER_RUN_LIFECYCLE_V2.FAILED); const now = Date.now(); r.status = ITER_RUN_LIFECYCLE_V2.FAILED; r.updatedAt = now; if (!r.settledAt) r.settledAt = now; if (reason) r.metadata.failReason = String(reason); return { ...r, metadata: { ...r.metadata } }; }
269
- export function cancelIterRunV2(id, reason) { const r = _irsV2.get(id); if (!r) throw new Error(`iter run ${id} not found`); _irCheckR(r.status, ITER_RUN_LIFECYCLE_V2.CANCELLED); const now = Date.now(); r.status = ITER_RUN_LIFECYCLE_V2.CANCELLED; r.updatedAt = now; if (!r.settledAt) r.settledAt = now; if (reason) r.metadata.cancelReason = String(reason); return { ...r, metadata: { ...r.metadata } }; }
270
- export function getIterRunV2(id) { const r = _irsV2.get(id); if (!r) return null; return { ...r, metadata: { ...r.metadata } }; }
271
- export function listIterRunsV2() { return [..._irsV2.values()].map((r) => ({ ...r, metadata: { ...r.metadata } })); }
423
+ function _irCheckR(from, to) {
424
+ const a = _irTrans.get(from);
425
+ if (!a || !a.has(to))
426
+ throw new Error(`invalid iter run transition ${from} ${to}`);
427
+ }
428
+ export function startIterRunV2(id) {
429
+ const r = _irsV2.get(id);
430
+ if (!r) throw new Error(`iter run ${id} not found`);
431
+ _irCheckR(r.status, ITER_RUN_LIFECYCLE_V2.RUNNING);
432
+ const now = Date.now();
433
+ r.status = ITER_RUN_LIFECYCLE_V2.RUNNING;
434
+ r.updatedAt = now;
435
+ if (!r.startedAt) r.startedAt = now;
436
+ return { ...r, metadata: { ...r.metadata } };
437
+ }
438
+ export function completeIterRunV2(id) {
439
+ const r = _irsV2.get(id);
440
+ if (!r) throw new Error(`iter run ${id} not found`);
441
+ _irCheckR(r.status, ITER_RUN_LIFECYCLE_V2.COMPLETED);
442
+ const now = Date.now();
443
+ r.status = ITER_RUN_LIFECYCLE_V2.COMPLETED;
444
+ r.updatedAt = now;
445
+ if (!r.settledAt) r.settledAt = now;
446
+ return { ...r, metadata: { ...r.metadata } };
447
+ }
448
+ export function failIterRunV2(id, reason) {
449
+ const r = _irsV2.get(id);
450
+ if (!r) throw new Error(`iter run ${id} not found`);
451
+ _irCheckR(r.status, ITER_RUN_LIFECYCLE_V2.FAILED);
452
+ const now = Date.now();
453
+ r.status = ITER_RUN_LIFECYCLE_V2.FAILED;
454
+ r.updatedAt = now;
455
+ if (!r.settledAt) r.settledAt = now;
456
+ if (reason) r.metadata.failReason = String(reason);
457
+ return { ...r, metadata: { ...r.metadata } };
458
+ }
459
+ export function cancelIterRunV2(id, reason) {
460
+ const r = _irsV2.get(id);
461
+ if (!r) throw new Error(`iter run ${id} not found`);
462
+ _irCheckR(r.status, ITER_RUN_LIFECYCLE_V2.CANCELLED);
463
+ const now = Date.now();
464
+ r.status = ITER_RUN_LIFECYCLE_V2.CANCELLED;
465
+ r.updatedAt = now;
466
+ if (!r.settledAt) r.settledAt = now;
467
+ if (reason) r.metadata.cancelReason = String(reason);
468
+ return { ...r, metadata: { ...r.metadata } };
469
+ }
470
+ export function getIterRunV2(id) {
471
+ const r = _irsV2.get(id);
472
+ if (!r) return null;
473
+ return { ...r, metadata: { ...r.metadata } };
474
+ }
475
+ export function listIterRunsV2() {
476
+ return [..._irsV2.values()].map((r) => ({
477
+ ...r,
478
+ metadata: { ...r.metadata },
479
+ }));
480
+ }
272
481
 
273
- export function autoPauseIdleIterBudgetProfilesV2({ now } = {}) { const t = now ?? Date.now(); const flipped = []; for (const p of _ibpsV2.values()) if (p.status === ITER_BUDGET_PROFILE_MATURITY_V2.ACTIVE && (t - p.lastTouchedAt) >= _ibpIdleMs) { p.status = ITER_BUDGET_PROFILE_MATURITY_V2.PAUSED; p.updatedAt = t; flipped.push(p.id); } return { flipped, count: flipped.length }; }
274
- export function autoFailStuckIterRunsV2({ now } = {}) { const t = now ?? Date.now(); const flipped = []; for (const r of _irsV2.values()) if (r.status === ITER_RUN_LIFECYCLE_V2.RUNNING && r.startedAt != null && (t - r.startedAt) >= _irStuckMs) { r.status = ITER_RUN_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 }; }
482
+ export function autoPauseIdleIterBudgetProfilesV2({ now } = {}) {
483
+ const t = now ?? Date.now();
484
+ const flipped = [];
485
+ for (const p of _ibpsV2.values())
486
+ if (
487
+ p.status === ITER_BUDGET_PROFILE_MATURITY_V2.ACTIVE &&
488
+ t - p.lastTouchedAt >= _ibpIdleMs
489
+ ) {
490
+ p.status = ITER_BUDGET_PROFILE_MATURITY_V2.PAUSED;
491
+ p.updatedAt = t;
492
+ flipped.push(p.id);
493
+ }
494
+ return { flipped, count: flipped.length };
495
+ }
496
+ export function autoFailStuckIterRunsV2({ now } = {}) {
497
+ const t = now ?? Date.now();
498
+ const flipped = [];
499
+ for (const r of _irsV2.values())
500
+ if (
501
+ r.status === ITER_RUN_LIFECYCLE_V2.RUNNING &&
502
+ r.startedAt != null &&
503
+ t - r.startedAt >= _irStuckMs
504
+ ) {
505
+ r.status = ITER_RUN_LIFECYCLE_V2.FAILED;
506
+ r.updatedAt = t;
507
+ if (!r.settledAt) r.settledAt = t;
508
+ r.metadata.failReason = "auto-fail-stuck";
509
+ flipped.push(r.id);
510
+ }
511
+ return { flipped, count: flipped.length };
512
+ }
275
513
 
276
514
  export function getIterationBudgetGovStatsV2() {
277
- const profilesByStatus = {}; for (const s of Object.values(ITER_BUDGET_PROFILE_MATURITY_V2)) profilesByStatus[s] = 0; for (const p of _ibpsV2.values()) profilesByStatus[p.status]++;
278
- const runsByStatus = {}; for (const s of Object.values(ITER_RUN_LIFECYCLE_V2)) runsByStatus[s] = 0; for (const r of _irsV2.values()) runsByStatus[r.status]++;
279
- return { totalIterBudgetProfilesV2: _ibpsV2.size, totalIterRunsV2: _irsV2.size, maxActiveIterBudgetProfilesPerOwner: _ibpMaxActivePerOwner, maxPendingIterRunsPerProfile: _ibpMaxPendingRunsPerProfile, iterBudgetProfileIdleMs: _ibpIdleMs, iterRunStuckMs: _irStuckMs, profilesByStatus, runsByStatus };
515
+ const profilesByStatus = {};
516
+ for (const s of Object.values(ITER_BUDGET_PROFILE_MATURITY_V2))
517
+ profilesByStatus[s] = 0;
518
+ for (const p of _ibpsV2.values()) profilesByStatus[p.status]++;
519
+ const runsByStatus = {};
520
+ for (const s of Object.values(ITER_RUN_LIFECYCLE_V2)) runsByStatus[s] = 0;
521
+ for (const r of _irsV2.values()) runsByStatus[r.status]++;
522
+ return {
523
+ totalIterBudgetProfilesV2: _ibpsV2.size,
524
+ totalIterRunsV2: _irsV2.size,
525
+ maxActiveIterBudgetProfilesPerOwner: _ibpMaxActivePerOwner,
526
+ maxPendingIterRunsPerProfile: _ibpMaxPendingRunsPerProfile,
527
+ iterBudgetProfileIdleMs: _ibpIdleMs,
528
+ iterRunStuckMs: _irStuckMs,
529
+ profilesByStatus,
530
+ runsByStatus,
531
+ };
280
532
  }