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
@@ -386,81 +386,345 @@ function renderGitignore() {
386
386
 
387
387
  // ===== V2 Surface: MCP Scaffold governance overlay (CLI v0.142.0) =====
388
388
  export const MSCAF_PROFILE_MATURITY_V2 = Object.freeze({
389
- PENDING: "pending", ACTIVE: "active", STALE: "stale", ARCHIVED: "archived",
389
+ PENDING: "pending",
390
+ ACTIVE: "active",
391
+ STALE: "stale",
392
+ ARCHIVED: "archived",
390
393
  });
391
394
  export const MSCAF_GENERATION_LIFECYCLE_V2 = Object.freeze({
392
- QUEUED: "queued", GENERATING: "generating", GENERATED: "generated", FAILED: "failed", CANCELLED: "cancelled",
395
+ QUEUED: "queued",
396
+ GENERATING: "generating",
397
+ GENERATED: "generated",
398
+ FAILED: "failed",
399
+ CANCELLED: "cancelled",
393
400
  });
394
401
  const _mscafPTrans = new Map([
395
- [MSCAF_PROFILE_MATURITY_V2.PENDING, new Set([MSCAF_PROFILE_MATURITY_V2.ACTIVE, MSCAF_PROFILE_MATURITY_V2.ARCHIVED])],
396
- [MSCAF_PROFILE_MATURITY_V2.ACTIVE, new Set([MSCAF_PROFILE_MATURITY_V2.STALE, MSCAF_PROFILE_MATURITY_V2.ARCHIVED])],
397
- [MSCAF_PROFILE_MATURITY_V2.STALE, new Set([MSCAF_PROFILE_MATURITY_V2.ACTIVE, MSCAF_PROFILE_MATURITY_V2.ARCHIVED])],
402
+ [
403
+ MSCAF_PROFILE_MATURITY_V2.PENDING,
404
+ new Set([
405
+ MSCAF_PROFILE_MATURITY_V2.ACTIVE,
406
+ MSCAF_PROFILE_MATURITY_V2.ARCHIVED,
407
+ ]),
408
+ ],
409
+ [
410
+ MSCAF_PROFILE_MATURITY_V2.ACTIVE,
411
+ new Set([
412
+ MSCAF_PROFILE_MATURITY_V2.STALE,
413
+ MSCAF_PROFILE_MATURITY_V2.ARCHIVED,
414
+ ]),
415
+ ],
416
+ [
417
+ MSCAF_PROFILE_MATURITY_V2.STALE,
418
+ new Set([
419
+ MSCAF_PROFILE_MATURITY_V2.ACTIVE,
420
+ MSCAF_PROFILE_MATURITY_V2.ARCHIVED,
421
+ ]),
422
+ ],
398
423
  [MSCAF_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
399
424
  ]);
400
425
  const _mscafPTerminal = new Set([MSCAF_PROFILE_MATURITY_V2.ARCHIVED]);
401
426
  const _mscafGTrans = new Map([
402
- [MSCAF_GENERATION_LIFECYCLE_V2.QUEUED, new Set([MSCAF_GENERATION_LIFECYCLE_V2.GENERATING, MSCAF_GENERATION_LIFECYCLE_V2.CANCELLED])],
403
- [MSCAF_GENERATION_LIFECYCLE_V2.GENERATING, new Set([MSCAF_GENERATION_LIFECYCLE_V2.GENERATED, MSCAF_GENERATION_LIFECYCLE_V2.FAILED, MSCAF_GENERATION_LIFECYCLE_V2.CANCELLED])],
427
+ [
428
+ MSCAF_GENERATION_LIFECYCLE_V2.QUEUED,
429
+ new Set([
430
+ MSCAF_GENERATION_LIFECYCLE_V2.GENERATING,
431
+ MSCAF_GENERATION_LIFECYCLE_V2.CANCELLED,
432
+ ]),
433
+ ],
434
+ [
435
+ MSCAF_GENERATION_LIFECYCLE_V2.GENERATING,
436
+ new Set([
437
+ MSCAF_GENERATION_LIFECYCLE_V2.GENERATED,
438
+ MSCAF_GENERATION_LIFECYCLE_V2.FAILED,
439
+ MSCAF_GENERATION_LIFECYCLE_V2.CANCELLED,
440
+ ]),
441
+ ],
404
442
  [MSCAF_GENERATION_LIFECYCLE_V2.GENERATED, new Set()],
405
443
  [MSCAF_GENERATION_LIFECYCLE_V2.FAILED, new Set()],
406
444
  [MSCAF_GENERATION_LIFECYCLE_V2.CANCELLED, new Set()],
407
445
  ]);
408
446
  const _mscafPsV2 = new Map();
409
447
  const _mscafGsV2 = new Map();
410
- let _mscafMaxActive = 6, _mscafMaxPending = 15, _mscafIdleMs = 30 * 24 * 60 * 60 * 1000, _mscafStuckMs = 60 * 1000;
411
- function _mscafPos(n, label) { const v = Math.floor(Number(n)); if (!Number.isFinite(v) || v <= 0) throw new Error(`${label} must be positive integer`); return v; }
412
- function _mscafCheckP(from, to) { const a = _mscafPTrans.get(from); if (!a || !a.has(to)) throw new Error(`invalid mscaf profile transition ${from} → ${to}`); }
413
- function _mscafCheckG(from, to) { const a = _mscafGTrans.get(from); if (!a || !a.has(to)) throw new Error(`invalid mscaf generation transition ${from} → ${to}`); }
414
- export function setMaxActiveMscafProfilesPerOwnerV2(n) { _mscafMaxActive = _mscafPos(n, "maxActiveMscafProfilesPerOwner"); }
415
- export function getMaxActiveMscafProfilesPerOwnerV2() { return _mscafMaxActive; }
416
- export function setMaxPendingMscafGenerationsPerProfileV2(n) { _mscafMaxPending = _mscafPos(n, "maxPendingMscafGenerationsPerProfile"); }
417
- export function getMaxPendingMscafGenerationsPerProfileV2() { return _mscafMaxPending; }
418
- export function setMscafProfileIdleMsV2(n) { _mscafIdleMs = _mscafPos(n, "mscafProfileIdleMs"); }
419
- export function getMscafProfileIdleMsV2() { return _mscafIdleMs; }
420
- export function setMscafGenerationStuckMsV2(n) { _mscafStuckMs = _mscafPos(n, "mscafGenerationStuckMs"); }
421
- export function getMscafGenerationStuckMsV2() { return _mscafStuckMs; }
422
- export function _resetStateMcpScaffoldV2() { _mscafPsV2.clear(); _mscafGsV2.clear(); _mscafMaxActive = 6; _mscafMaxPending = 15; _mscafIdleMs = 30 * 24 * 60 * 60 * 1000; _mscafStuckMs = 60 * 1000; }
423
- export function registerMscafProfileV2({ id, owner, transport, metadata } = {}) {
424
- if (!id) throw new Error("mscaf profile id required"); if (!owner) throw new Error("mscaf profile owner required");
425
- if (_mscafPsV2.has(id)) throw new Error(`mscaf profile ${id} already registered`);
448
+ let _mscafMaxActive = 6,
449
+ _mscafMaxPending = 15,
450
+ _mscafIdleMs = 30 * 24 * 60 * 60 * 1000,
451
+ _mscafStuckMs = 60 * 1000;
452
+ function _mscafPos(n, label) {
453
+ const v = Math.floor(Number(n));
454
+ if (!Number.isFinite(v) || v <= 0)
455
+ throw new Error(`${label} must be positive integer`);
456
+ return v;
457
+ }
458
+ function _mscafCheckP(from, to) {
459
+ const a = _mscafPTrans.get(from);
460
+ if (!a || !a.has(to))
461
+ throw new Error(`invalid mscaf profile transition ${from} ${to}`);
462
+ }
463
+ function _mscafCheckG(from, to) {
464
+ const a = _mscafGTrans.get(from);
465
+ if (!a || !a.has(to))
466
+ throw new Error(`invalid mscaf generation transition ${from} → ${to}`);
467
+ }
468
+ export function setMaxActiveMscafProfilesPerOwnerV2(n) {
469
+ _mscafMaxActive = _mscafPos(n, "maxActiveMscafProfilesPerOwner");
470
+ }
471
+ export function getMaxActiveMscafProfilesPerOwnerV2() {
472
+ return _mscafMaxActive;
473
+ }
474
+ export function setMaxPendingMscafGenerationsPerProfileV2(n) {
475
+ _mscafMaxPending = _mscafPos(n, "maxPendingMscafGenerationsPerProfile");
476
+ }
477
+ export function getMaxPendingMscafGenerationsPerProfileV2() {
478
+ return _mscafMaxPending;
479
+ }
480
+ export function setMscafProfileIdleMsV2(n) {
481
+ _mscafIdleMs = _mscafPos(n, "mscafProfileIdleMs");
482
+ }
483
+ export function getMscafProfileIdleMsV2() {
484
+ return _mscafIdleMs;
485
+ }
486
+ export function setMscafGenerationStuckMsV2(n) {
487
+ _mscafStuckMs = _mscafPos(n, "mscafGenerationStuckMs");
488
+ }
489
+ export function getMscafGenerationStuckMsV2() {
490
+ return _mscafStuckMs;
491
+ }
492
+ export function _resetStateMcpScaffoldV2() {
493
+ _mscafPsV2.clear();
494
+ _mscafGsV2.clear();
495
+ _mscafMaxActive = 6;
496
+ _mscafMaxPending = 15;
497
+ _mscafIdleMs = 30 * 24 * 60 * 60 * 1000;
498
+ _mscafStuckMs = 60 * 1000;
499
+ }
500
+ export function registerMscafProfileV2({
501
+ id,
502
+ owner,
503
+ transport,
504
+ metadata,
505
+ } = {}) {
506
+ if (!id) throw new Error("mscaf profile id required");
507
+ if (!owner) throw new Error("mscaf profile owner required");
508
+ if (_mscafPsV2.has(id))
509
+ throw new Error(`mscaf profile ${id} already registered`);
426
510
  const now = Date.now();
427
- const p = { id, owner, transport: transport || "stdio", status: MSCAF_PROFILE_MATURITY_V2.PENDING, createdAt: now, updatedAt: now, activatedAt: null, archivedAt: null, lastTouchedAt: now, metadata: { ...(metadata || {}) } };
428
- _mscafPsV2.set(id, p); return { ...p, metadata: { ...p.metadata } };
511
+ const p = {
512
+ id,
513
+ owner,
514
+ transport: transport || "stdio",
515
+ status: MSCAF_PROFILE_MATURITY_V2.PENDING,
516
+ createdAt: now,
517
+ updatedAt: now,
518
+ activatedAt: null,
519
+ archivedAt: null,
520
+ lastTouchedAt: now,
521
+ metadata: { ...(metadata || {}) },
522
+ };
523
+ _mscafPsV2.set(id, p);
524
+ return { ...p, metadata: { ...p.metadata } };
525
+ }
526
+ function _mscafCountActive(owner) {
527
+ let n = 0;
528
+ for (const p of _mscafPsV2.values())
529
+ if (p.owner === owner && p.status === MSCAF_PROFILE_MATURITY_V2.ACTIVE) n++;
530
+ return n;
429
531
  }
430
- function _mscafCountActive(owner) { let n = 0; for (const p of _mscafPsV2.values()) if (p.owner === owner && p.status === MSCAF_PROFILE_MATURITY_V2.ACTIVE) n++; return n; }
431
532
  export function activateMscafProfileV2(id) {
432
- const p = _mscafPsV2.get(id); if (!p) throw new Error(`mscaf profile ${id} not found`);
533
+ const p = _mscafPsV2.get(id);
534
+ if (!p) throw new Error(`mscaf profile ${id} not found`);
433
535
  _mscafCheckP(p.status, MSCAF_PROFILE_MATURITY_V2.ACTIVE);
434
536
  const recovery = p.status === MSCAF_PROFILE_MATURITY_V2.STALE;
435
- if (!recovery && _mscafCountActive(p.owner) >= _mscafMaxActive) throw new Error(`max active mscaf profiles for owner ${p.owner} reached`);
436
- const now = Date.now(); p.status = MSCAF_PROFILE_MATURITY_V2.ACTIVE; p.updatedAt = now; p.lastTouchedAt = now; if (!p.activatedAt) p.activatedAt = now;
537
+ if (!recovery && _mscafCountActive(p.owner) >= _mscafMaxActive)
538
+ throw new Error(`max active mscaf profiles for owner ${p.owner} reached`);
539
+ const now = Date.now();
540
+ p.status = MSCAF_PROFILE_MATURITY_V2.ACTIVE;
541
+ p.updatedAt = now;
542
+ p.lastTouchedAt = now;
543
+ if (!p.activatedAt) p.activatedAt = now;
544
+ return { ...p, metadata: { ...p.metadata } };
545
+ }
546
+ export function staleMscafProfileV2(id) {
547
+ const p = _mscafPsV2.get(id);
548
+ if (!p) throw new Error(`mscaf profile ${id} not found`);
549
+ _mscafCheckP(p.status, MSCAF_PROFILE_MATURITY_V2.STALE);
550
+ p.status = MSCAF_PROFILE_MATURITY_V2.STALE;
551
+ p.updatedAt = Date.now();
552
+ return { ...p, metadata: { ...p.metadata } };
553
+ }
554
+ export function archiveMscafProfileV2(id) {
555
+ const p = _mscafPsV2.get(id);
556
+ if (!p) throw new Error(`mscaf profile ${id} not found`);
557
+ _mscafCheckP(p.status, MSCAF_PROFILE_MATURITY_V2.ARCHIVED);
558
+ const now = Date.now();
559
+ p.status = MSCAF_PROFILE_MATURITY_V2.ARCHIVED;
560
+ p.updatedAt = now;
561
+ if (!p.archivedAt) p.archivedAt = now;
562
+ return { ...p, metadata: { ...p.metadata } };
563
+ }
564
+ export function touchMscafProfileV2(id) {
565
+ const p = _mscafPsV2.get(id);
566
+ if (!p) throw new Error(`mscaf profile ${id} not found`);
567
+ if (_mscafPTerminal.has(p.status))
568
+ throw new Error(`cannot touch terminal mscaf profile ${id}`);
569
+ const now = Date.now();
570
+ p.lastTouchedAt = now;
571
+ p.updatedAt = now;
572
+ return { ...p, metadata: { ...p.metadata } };
573
+ }
574
+ export function getMscafProfileV2(id) {
575
+ const p = _mscafPsV2.get(id);
576
+ if (!p) return null;
437
577
  return { ...p, metadata: { ...p.metadata } };
438
578
  }
439
- export function staleMscafProfileV2(id) { const p = _mscafPsV2.get(id); if (!p) throw new Error(`mscaf profile ${id} not found`); _mscafCheckP(p.status, MSCAF_PROFILE_MATURITY_V2.STALE); p.status = MSCAF_PROFILE_MATURITY_V2.STALE; p.updatedAt = Date.now(); return { ...p, metadata: { ...p.metadata } }; }
440
- export function archiveMscafProfileV2(id) { const p = _mscafPsV2.get(id); if (!p) throw new Error(`mscaf profile ${id} not found`); _mscafCheckP(p.status, MSCAF_PROFILE_MATURITY_V2.ARCHIVED); const now = Date.now(); p.status = MSCAF_PROFILE_MATURITY_V2.ARCHIVED; p.updatedAt = now; if (!p.archivedAt) p.archivedAt = now; return { ...p, metadata: { ...p.metadata } }; }
441
- export function touchMscafProfileV2(id) { const p = _mscafPsV2.get(id); if (!p) throw new Error(`mscaf profile ${id} not found`); if (_mscafPTerminal.has(p.status)) throw new Error(`cannot touch terminal mscaf profile ${id}`); const now = Date.now(); p.lastTouchedAt = now; p.updatedAt = now; return { ...p, metadata: { ...p.metadata } }; }
442
- export function getMscafProfileV2(id) { const p = _mscafPsV2.get(id); if (!p) return null; return { ...p, metadata: { ...p.metadata } }; }
443
- export function listMscafProfilesV2() { return [..._mscafPsV2.values()].map((p) => ({ ...p, metadata: { ...p.metadata } })); }
444
- function _mscafCountPending(profileId) { let n = 0; for (const g of _mscafGsV2.values()) if (g.profileId === profileId && (g.status === MSCAF_GENERATION_LIFECYCLE_V2.QUEUED || g.status === MSCAF_GENERATION_LIFECYCLE_V2.GENERATING)) n++; return n; }
445
- export function createMscafGenerationV2({ id, profileId, target, metadata } = {}) {
446
- if (!id) throw new Error("mscaf generation id required"); if (!profileId) throw new Error("mscaf generation profileId required");
447
- if (_mscafGsV2.has(id)) throw new Error(`mscaf generation ${id} already exists`);
448
- if (!_mscafPsV2.has(profileId)) throw new Error(`mscaf profile ${profileId} not found`);
449
- if (_mscafCountPending(profileId) >= _mscafMaxPending) throw new Error(`max pending mscaf generations for profile ${profileId} reached`);
579
+ export function listMscafProfilesV2() {
580
+ return [..._mscafPsV2.values()].map((p) => ({
581
+ ...p,
582
+ metadata: { ...p.metadata },
583
+ }));
584
+ }
585
+ function _mscafCountPending(profileId) {
586
+ let n = 0;
587
+ for (const g of _mscafGsV2.values())
588
+ if (
589
+ g.profileId === profileId &&
590
+ (g.status === MSCAF_GENERATION_LIFECYCLE_V2.QUEUED ||
591
+ g.status === MSCAF_GENERATION_LIFECYCLE_V2.GENERATING)
592
+ )
593
+ n++;
594
+ return n;
595
+ }
596
+ export function createMscafGenerationV2({
597
+ id,
598
+ profileId,
599
+ target,
600
+ metadata,
601
+ } = {}) {
602
+ if (!id) throw new Error("mscaf generation id required");
603
+ if (!profileId) throw new Error("mscaf generation profileId required");
604
+ if (_mscafGsV2.has(id))
605
+ throw new Error(`mscaf generation ${id} already exists`);
606
+ if (!_mscafPsV2.has(profileId))
607
+ throw new Error(`mscaf profile ${profileId} not found`);
608
+ if (_mscafCountPending(profileId) >= _mscafMaxPending)
609
+ throw new Error(
610
+ `max pending mscaf generations for profile ${profileId} reached`,
611
+ );
612
+ const now = Date.now();
613
+ const g = {
614
+ id,
615
+ profileId,
616
+ target: target || "",
617
+ status: MSCAF_GENERATION_LIFECYCLE_V2.QUEUED,
618
+ createdAt: now,
619
+ updatedAt: now,
620
+ startedAt: null,
621
+ settledAt: null,
622
+ metadata: { ...(metadata || {}) },
623
+ };
624
+ _mscafGsV2.set(id, g);
625
+ return { ...g, metadata: { ...g.metadata } };
626
+ }
627
+ export function generatingMscafGenerationV2(id) {
628
+ const g = _mscafGsV2.get(id);
629
+ if (!g) throw new Error(`mscaf generation ${id} not found`);
630
+ _mscafCheckG(g.status, MSCAF_GENERATION_LIFECYCLE_V2.GENERATING);
631
+ const now = Date.now();
632
+ g.status = MSCAF_GENERATION_LIFECYCLE_V2.GENERATING;
633
+ g.updatedAt = now;
634
+ if (!g.startedAt) g.startedAt = now;
635
+ return { ...g, metadata: { ...g.metadata } };
636
+ }
637
+ export function generateMscafGenerationV2(id) {
638
+ const g = _mscafGsV2.get(id);
639
+ if (!g) throw new Error(`mscaf generation ${id} not found`);
640
+ _mscafCheckG(g.status, MSCAF_GENERATION_LIFECYCLE_V2.GENERATED);
450
641
  const now = Date.now();
451
- const g = { id, profileId, target: target || "", status: MSCAF_GENERATION_LIFECYCLE_V2.QUEUED, createdAt: now, updatedAt: now, startedAt: null, settledAt: null, metadata: { ...(metadata || {}) } };
452
- _mscafGsV2.set(id, g); return { ...g, metadata: { ...g.metadata } };
453
- }
454
- export function generatingMscafGenerationV2(id) { const g = _mscafGsV2.get(id); if (!g) throw new Error(`mscaf generation ${id} not found`); _mscafCheckG(g.status, MSCAF_GENERATION_LIFECYCLE_V2.GENERATING); const now = Date.now(); g.status = MSCAF_GENERATION_LIFECYCLE_V2.GENERATING; g.updatedAt = now; if (!g.startedAt) g.startedAt = now; return { ...g, metadata: { ...g.metadata } }; }
455
- export function generateMscafGenerationV2(id) { const g = _mscafGsV2.get(id); if (!g) throw new Error(`mscaf generation ${id} not found`); _mscafCheckG(g.status, MSCAF_GENERATION_LIFECYCLE_V2.GENERATED); const now = Date.now(); g.status = MSCAF_GENERATION_LIFECYCLE_V2.GENERATED; g.updatedAt = now; if (!g.settledAt) g.settledAt = now; return { ...g, metadata: { ...g.metadata } }; }
456
- export function failMscafGenerationV2(id, reason) { const g = _mscafGsV2.get(id); if (!g) throw new Error(`mscaf generation ${id} not found`); _mscafCheckG(g.status, MSCAF_GENERATION_LIFECYCLE_V2.FAILED); const now = Date.now(); g.status = MSCAF_GENERATION_LIFECYCLE_V2.FAILED; g.updatedAt = now; if (!g.settledAt) g.settledAt = now; if (reason) g.metadata.failReason = String(reason); return { ...g, metadata: { ...g.metadata } }; }
457
- export function cancelMscafGenerationV2(id, reason) { const g = _mscafGsV2.get(id); if (!g) throw new Error(`mscaf generation ${id} not found`); _mscafCheckG(g.status, MSCAF_GENERATION_LIFECYCLE_V2.CANCELLED); const now = Date.now(); g.status = MSCAF_GENERATION_LIFECYCLE_V2.CANCELLED; g.updatedAt = now; if (!g.settledAt) g.settledAt = now; if (reason) g.metadata.cancelReason = String(reason); return { ...g, metadata: { ...g.metadata } }; }
458
- export function getMscafGenerationV2(id) { const g = _mscafGsV2.get(id); if (!g) return null; return { ...g, metadata: { ...g.metadata } }; }
459
- export function listMscafGenerationsV2() { return [..._mscafGsV2.values()].map((g) => ({ ...g, metadata: { ...g.metadata } })); }
460
- export function autoStaleIdleMscafProfilesV2({ now } = {}) { const t = now ?? Date.now(); const flipped = []; for (const p of _mscafPsV2.values()) if (p.status === MSCAF_PROFILE_MATURITY_V2.ACTIVE && (t - p.lastTouchedAt) >= _mscafIdleMs) { p.status = MSCAF_PROFILE_MATURITY_V2.STALE; p.updatedAt = t; flipped.push(p.id); } return { flipped, count: flipped.length }; }
461
- export function autoFailStuckMscafGenerationsV2({ now } = {}) { const t = now ?? Date.now(); const flipped = []; for (const g of _mscafGsV2.values()) if (g.status === MSCAF_GENERATION_LIFECYCLE_V2.GENERATING && g.startedAt != null && (t - g.startedAt) >= _mscafStuckMs) { g.status = MSCAF_GENERATION_LIFECYCLE_V2.FAILED; g.updatedAt = t; if (!g.settledAt) g.settledAt = t; g.metadata.failReason = "auto-fail-stuck"; flipped.push(g.id); } return { flipped, count: flipped.length }; }
642
+ g.status = MSCAF_GENERATION_LIFECYCLE_V2.GENERATED;
643
+ g.updatedAt = now;
644
+ if (!g.settledAt) g.settledAt = now;
645
+ return { ...g, metadata: { ...g.metadata } };
646
+ }
647
+ export function failMscafGenerationV2(id, reason) {
648
+ const g = _mscafGsV2.get(id);
649
+ if (!g) throw new Error(`mscaf generation ${id} not found`);
650
+ _mscafCheckG(g.status, MSCAF_GENERATION_LIFECYCLE_V2.FAILED);
651
+ const now = Date.now();
652
+ g.status = MSCAF_GENERATION_LIFECYCLE_V2.FAILED;
653
+ g.updatedAt = now;
654
+ if (!g.settledAt) g.settledAt = now;
655
+ if (reason) g.metadata.failReason = String(reason);
656
+ return { ...g, metadata: { ...g.metadata } };
657
+ }
658
+ export function cancelMscafGenerationV2(id, reason) {
659
+ const g = _mscafGsV2.get(id);
660
+ if (!g) throw new Error(`mscaf generation ${id} not found`);
661
+ _mscafCheckG(g.status, MSCAF_GENERATION_LIFECYCLE_V2.CANCELLED);
662
+ const now = Date.now();
663
+ g.status = MSCAF_GENERATION_LIFECYCLE_V2.CANCELLED;
664
+ g.updatedAt = now;
665
+ if (!g.settledAt) g.settledAt = now;
666
+ if (reason) g.metadata.cancelReason = String(reason);
667
+ return { ...g, metadata: { ...g.metadata } };
668
+ }
669
+ export function getMscafGenerationV2(id) {
670
+ const g = _mscafGsV2.get(id);
671
+ if (!g) return null;
672
+ return { ...g, metadata: { ...g.metadata } };
673
+ }
674
+ export function listMscafGenerationsV2() {
675
+ return [..._mscafGsV2.values()].map((g) => ({
676
+ ...g,
677
+ metadata: { ...g.metadata },
678
+ }));
679
+ }
680
+ export function autoStaleIdleMscafProfilesV2({ now } = {}) {
681
+ const t = now ?? Date.now();
682
+ const flipped = [];
683
+ for (const p of _mscafPsV2.values())
684
+ if (
685
+ p.status === MSCAF_PROFILE_MATURITY_V2.ACTIVE &&
686
+ t - p.lastTouchedAt >= _mscafIdleMs
687
+ ) {
688
+ p.status = MSCAF_PROFILE_MATURITY_V2.STALE;
689
+ p.updatedAt = t;
690
+ flipped.push(p.id);
691
+ }
692
+ return { flipped, count: flipped.length };
693
+ }
694
+ export function autoFailStuckMscafGenerationsV2({ now } = {}) {
695
+ const t = now ?? Date.now();
696
+ const flipped = [];
697
+ for (const g of _mscafGsV2.values())
698
+ if (
699
+ g.status === MSCAF_GENERATION_LIFECYCLE_V2.GENERATING &&
700
+ g.startedAt != null &&
701
+ t - g.startedAt >= _mscafStuckMs
702
+ ) {
703
+ g.status = MSCAF_GENERATION_LIFECYCLE_V2.FAILED;
704
+ g.updatedAt = t;
705
+ if (!g.settledAt) g.settledAt = t;
706
+ g.metadata.failReason = "auto-fail-stuck";
707
+ flipped.push(g.id);
708
+ }
709
+ return { flipped, count: flipped.length };
710
+ }
462
711
  export function getMcpScaffoldGovStatsV2() {
463
- const profilesByStatus = {}; for (const v of Object.values(MSCAF_PROFILE_MATURITY_V2)) profilesByStatus[v] = 0; for (const p of _mscafPsV2.values()) profilesByStatus[p.status]++;
464
- const generationsByStatus = {}; for (const v of Object.values(MSCAF_GENERATION_LIFECYCLE_V2)) generationsByStatus[v] = 0; for (const g of _mscafGsV2.values()) generationsByStatus[g.status]++;
465
- return { totalMscafProfilesV2: _mscafPsV2.size, totalMscafGenerationsV2: _mscafGsV2.size, maxActiveMscafProfilesPerOwner: _mscafMaxActive, maxPendingMscafGenerationsPerProfile: _mscafMaxPending, mscafProfileIdleMs: _mscafIdleMs, mscafGenerationStuckMs: _mscafStuckMs, profilesByStatus, generationsByStatus };
712
+ const profilesByStatus = {};
713
+ for (const v of Object.values(MSCAF_PROFILE_MATURITY_V2))
714
+ profilesByStatus[v] = 0;
715
+ for (const p of _mscafPsV2.values()) profilesByStatus[p.status]++;
716
+ const generationsByStatus = {};
717
+ for (const v of Object.values(MSCAF_GENERATION_LIFECYCLE_V2))
718
+ generationsByStatus[v] = 0;
719
+ for (const g of _mscafGsV2.values()) generationsByStatus[g.status]++;
720
+ return {
721
+ totalMscafProfilesV2: _mscafPsV2.size,
722
+ totalMscafGenerationsV2: _mscafGsV2.size,
723
+ maxActiveMscafProfilesPerOwner: _mscafMaxActive,
724
+ maxPendingMscafGenerationsPerProfile: _mscafMaxPending,
725
+ mscafProfileIdleMs: _mscafIdleMs,
726
+ mscafGenerationStuckMs: _mscafStuckMs,
727
+ profilesByStatus,
728
+ generationsByStatus,
729
+ };
466
730
  }