chainlesschain 0.143.0 → 0.145.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 (133) hide show
  1. package/package.json +1 -1
  2. package/src/commands/a2a.js +196 -28
  3. package/src/commands/activitypub.js +157 -27
  4. package/src/commands/agent.js +587 -103
  5. package/src/commands/audit.js +206 -0
  6. package/src/commands/bi.js +152 -27
  7. package/src/commands/bm25.js +111 -27
  8. package/src/commands/browse.js +190 -29
  9. package/src/commands/ccron.js +128 -28
  10. package/src/commands/chat.js +207 -0
  11. package/src/commands/compliance.js +414 -34
  12. package/src/commands/compt.js +127 -29
  13. package/src/commands/consol.js +8 -2
  14. package/src/commands/cowork.js +580 -34
  15. package/src/commands/crosschain.js +182 -28
  16. package/src/commands/dao.js +182 -28
  17. package/src/commands/dlp.js +172 -27
  18. package/src/commands/economy.js +205 -50
  19. package/src/commands/evolution.js +203 -50
  20. package/src/commands/evomap.js +182 -27
  21. package/src/commands/fflag.js +74 -22
  22. package/src/commands/git.js +177 -37
  23. package/src/commands/hardening.js +209 -0
  24. package/src/commands/hmemory.js +204 -50
  25. package/src/commands/incentive.js +209 -0
  26. package/src/commands/inference.js +170 -34
  27. package/src/commands/itbudget.js +149 -33
  28. package/src/commands/kg.js +206 -0
  29. package/src/commands/lowcode.js +195 -38
  30. package/src/commands/marketplace.js +206 -0
  31. package/src/commands/matrix.js +179 -27
  32. package/src/commands/mcpscaf.js +145 -33
  33. package/src/commands/meminj.js +145 -33
  34. package/src/commands/nostr.js +178 -27
  35. package/src/commands/orchestrate.js +217 -0
  36. package/src/commands/orchgov.js +144 -33
  37. package/src/commands/pdfp.js +109 -27
  38. package/src/commands/perf.js +169 -32
  39. package/src/commands/perm.js +144 -33
  40. package/src/commands/pipeline.js +207 -52
  41. package/src/commands/planmode.js +141 -32
  42. package/src/commands/privacy.js +203 -0
  43. package/src/commands/promcomp.js +111 -27
  44. package/src/commands/recommend.js +177 -34
  45. package/src/commands/reputation.js +208 -0
  46. package/src/commands/sandbox.js +206 -0
  47. package/src/commands/seshhook.js +145 -33
  48. package/src/commands/seshsearch.js +141 -33
  49. package/src/commands/seshtail.js +144 -33
  50. package/src/commands/seshu.js +152 -33
  51. package/src/commands/sganal.js +123 -29
  52. package/src/commands/siem.js +201 -34
  53. package/src/commands/sla.js +212 -0
  54. package/src/commands/slotfill.js +146 -33
  55. package/src/commands/social.js +157 -32
  56. package/src/commands/stress.js +206 -0
  57. package/src/commands/svccont.js +145 -33
  58. package/src/commands/terraform.js +206 -0
  59. package/src/commands/tms.js +171 -33
  60. package/src/commands/topiccls.js +146 -33
  61. package/src/commands/uprof.js +141 -32
  62. package/src/commands/vcheck.js +122 -28
  63. package/src/commands/webfetch.js +141 -32
  64. package/src/commands/zkp.js +184 -28
  65. package/src/index.js +40 -0
  66. package/src/lib/a2a-protocol.js +319 -51
  67. package/src/lib/activitypub-bridge.js +288 -50
  68. package/src/lib/agent-economy.js +304 -51
  69. package/src/lib/app-builder.js +279 -46
  70. package/src/lib/audit-logger.js +321 -0
  71. package/src/lib/autonomous-agent.js +284 -48
  72. package/src/lib/bi-engine.js +283 -49
  73. package/src/lib/bm25-search.js +301 -49
  74. package/src/lib/browser-automation.js +296 -49
  75. package/src/lib/chat-core.js +336 -0
  76. package/src/lib/claude-code-bridge.js +341 -0
  77. package/src/lib/compliance-framework-reporter.js +305 -51
  78. package/src/lib/compliance-manager.js +330 -0
  79. package/src/lib/compression-telemetry.js +301 -49
  80. package/src/lib/content-recommender.js +317 -52
  81. package/src/lib/cowork-cron.js +298 -49
  82. package/src/lib/cowork-learning.js +333 -0
  83. package/src/lib/cowork-task-runner.js +308 -51
  84. package/src/lib/cowork-workflow.js +327 -0
  85. package/src/lib/cross-chain.js +311 -51
  86. package/src/lib/dao-governance.js +280 -46
  87. package/src/lib/dlp-engine.js +287 -49
  88. package/src/lib/evolution-system.js +278 -47
  89. package/src/lib/evomap-manager.js +280 -46
  90. package/src/lib/execution-backend.js +294 -48
  91. package/src/lib/feature-flags.js +294 -49
  92. package/src/lib/git-integration.js +285 -47
  93. package/src/lib/hardening-manager.js +341 -0
  94. package/src/lib/hierarchical-memory.js +284 -48
  95. package/src/lib/inference-network.js +308 -51
  96. package/src/lib/iteration-budget.js +302 -50
  97. package/src/lib/knowledge-graph.js +333 -0
  98. package/src/lib/matrix-bridge.js +281 -47
  99. package/src/lib/mcp-scaffold.js +318 -54
  100. package/src/lib/memory-injection.js +288 -49
  101. package/src/lib/nostr-bridge.js +286 -49
  102. package/src/lib/orchestrator.js +293 -48
  103. package/src/lib/pdf-parser.js +298 -49
  104. package/src/lib/perf-tuning.js +309 -50
  105. package/src/lib/permission-engine.js +287 -49
  106. package/src/lib/pipeline-orchestrator.js +289 -49
  107. package/src/lib/plan-mode.js +298 -51
  108. package/src/lib/privacy-computing.js +335 -0
  109. package/src/lib/reputation-optimizer.js +340 -0
  110. package/src/lib/sandbox-v2.js +327 -0
  111. package/src/lib/service-container.js +313 -52
  112. package/src/lib/session-consolidator.js +296 -49
  113. package/src/lib/session-hooks.js +312 -53
  114. package/src/lib/session-search.js +304 -51
  115. package/src/lib/session-tail.js +288 -49
  116. package/src/lib/session-usage.js +298 -52
  117. package/src/lib/siem-exporter.js +298 -51
  118. package/src/lib/skill-marketplace.js +345 -0
  119. package/src/lib/sla-manager.js +341 -0
  120. package/src/lib/slot-filler.js +303 -51
  121. package/src/lib/social-graph-analytics.js +295 -49
  122. package/src/lib/social-graph.js +272 -49
  123. package/src/lib/stress-tester.js +342 -0
  124. package/src/lib/sub-agent-registry.js +302 -53
  125. package/src/lib/task-model-selector.js +302 -50
  126. package/src/lib/terraform-manager.js +333 -0
  127. package/src/lib/todo-manager.js +281 -47
  128. package/src/lib/token-incentive.js +341 -0
  129. package/src/lib/topic-classifier.js +297 -49
  130. package/src/lib/user-profile.js +294 -50
  131. package/src/lib/version-checker.js +304 -50
  132. package/src/lib/web-fetch.js +292 -51
  133. package/src/lib/zkp-engine.js +286 -49
@@ -437,25 +437,62 @@ function _extractChangedFiles(output) {
437
437
  return matches.map((m) => m.split(/:\s+/)[1]).filter(Boolean);
438
438
  }
439
439
 
440
-
441
440
  // ===== V2 Surface: Orchestrator governance overlay (CLI v0.140.0) =====
442
441
  export const ORCH_PROFILE_MATURITY_V2 = Object.freeze({
443
- PENDING: "pending", ACTIVE: "active", PAUSED: "paused", RETIRED: "retired",
442
+ PENDING: "pending",
443
+ ACTIVE: "active",
444
+ PAUSED: "paused",
445
+ RETIRED: "retired",
444
446
  });
445
447
  export const ORCH_TASK_LIFECYCLE_V2 = Object.freeze({
446
- QUEUED: "queued", DISPATCHING: "dispatching", COMPLETED: "completed", FAILED: "failed", CANCELLED: "cancelled",
448
+ QUEUED: "queued",
449
+ DISPATCHING: "dispatching",
450
+ COMPLETED: "completed",
451
+ FAILED: "failed",
452
+ CANCELLED: "cancelled",
447
453
  });
448
454
 
449
455
  const _opTrans = new Map([
450
- [ORCH_PROFILE_MATURITY_V2.PENDING, new Set([ORCH_PROFILE_MATURITY_V2.ACTIVE, ORCH_PROFILE_MATURITY_V2.RETIRED])],
451
- [ORCH_PROFILE_MATURITY_V2.ACTIVE, new Set([ORCH_PROFILE_MATURITY_V2.PAUSED, ORCH_PROFILE_MATURITY_V2.RETIRED])],
452
- [ORCH_PROFILE_MATURITY_V2.PAUSED, new Set([ORCH_PROFILE_MATURITY_V2.ACTIVE, ORCH_PROFILE_MATURITY_V2.RETIRED])],
456
+ [
457
+ ORCH_PROFILE_MATURITY_V2.PENDING,
458
+ new Set([
459
+ ORCH_PROFILE_MATURITY_V2.ACTIVE,
460
+ ORCH_PROFILE_MATURITY_V2.RETIRED,
461
+ ]),
462
+ ],
463
+ [
464
+ ORCH_PROFILE_MATURITY_V2.ACTIVE,
465
+ new Set([
466
+ ORCH_PROFILE_MATURITY_V2.PAUSED,
467
+ ORCH_PROFILE_MATURITY_V2.RETIRED,
468
+ ]),
469
+ ],
470
+ [
471
+ ORCH_PROFILE_MATURITY_V2.PAUSED,
472
+ new Set([
473
+ ORCH_PROFILE_MATURITY_V2.ACTIVE,
474
+ ORCH_PROFILE_MATURITY_V2.RETIRED,
475
+ ]),
476
+ ],
453
477
  [ORCH_PROFILE_MATURITY_V2.RETIRED, new Set()],
454
478
  ]);
455
479
  const _opTerminal = new Set([ORCH_PROFILE_MATURITY_V2.RETIRED]);
456
480
  const _otTrans = new Map([
457
- [ORCH_TASK_LIFECYCLE_V2.QUEUED, new Set([ORCH_TASK_LIFECYCLE_V2.DISPATCHING, ORCH_TASK_LIFECYCLE_V2.CANCELLED])],
458
- [ORCH_TASK_LIFECYCLE_V2.DISPATCHING, new Set([ORCH_TASK_LIFECYCLE_V2.COMPLETED, ORCH_TASK_LIFECYCLE_V2.FAILED, ORCH_TASK_LIFECYCLE_V2.CANCELLED])],
481
+ [
482
+ ORCH_TASK_LIFECYCLE_V2.QUEUED,
483
+ new Set([
484
+ ORCH_TASK_LIFECYCLE_V2.DISPATCHING,
485
+ ORCH_TASK_LIFECYCLE_V2.CANCELLED,
486
+ ]),
487
+ ],
488
+ [
489
+ ORCH_TASK_LIFECYCLE_V2.DISPATCHING,
490
+ new Set([
491
+ ORCH_TASK_LIFECYCLE_V2.COMPLETED,
492
+ ORCH_TASK_LIFECYCLE_V2.FAILED,
493
+ ORCH_TASK_LIFECYCLE_V2.CANCELLED,
494
+ ]),
495
+ ],
459
496
  [ORCH_TASK_LIFECYCLE_V2.COMPLETED, new Set()],
460
497
  [ORCH_TASK_LIFECYCLE_V2.FAILED, new Set()],
461
498
  [ORCH_TASK_LIFECYCLE_V2.CANCELLED, new Set()],
@@ -468,21 +505,45 @@ let _opMaxPendingTasksPerProfile = 12;
468
505
  let _opIdleMs = 14 * 24 * 60 * 60 * 1000;
469
506
  let _otStuckMs = 15 * 60 * 1000;
470
507
 
471
- function _opPos(n, lbl) { const v = Math.floor(Number(n)); if (!Number.isFinite(v) || v <= 0) throw new Error(`${lbl} must be positive integer`); return v; }
508
+ function _opPos(n, lbl) {
509
+ const v = Math.floor(Number(n));
510
+ if (!Number.isFinite(v) || v <= 0)
511
+ throw new Error(`${lbl} must be positive integer`);
512
+ return v;
513
+ }
472
514
 
473
- export function setMaxActiveOrchProfilesPerOwnerV2(n) { _opMaxActivePerOwner = _opPos(n, "maxActiveOrchProfilesPerOwner"); }
474
- export function getMaxActiveOrchProfilesPerOwnerV2() { return _opMaxActivePerOwner; }
475
- export function setMaxPendingOrchTasksPerProfileV2(n) { _opMaxPendingTasksPerProfile = _opPos(n, "maxPendingOrchTasksPerProfile"); }
476
- export function getMaxPendingOrchTasksPerProfileV2() { return _opMaxPendingTasksPerProfile; }
477
- export function setOrchProfileIdleMsV2(n) { _opIdleMs = _opPos(n, "orchProfileIdleMs"); }
478
- export function getOrchProfileIdleMsV2() { return _opIdleMs; }
479
- export function setOrchTaskStuckMsV2(n) { _otStuckMs = _opPos(n, "orchTaskStuckMs"); }
480
- export function getOrchTaskStuckMsV2() { return _otStuckMs; }
515
+ export function setMaxActiveOrchProfilesPerOwnerV2(n) {
516
+ _opMaxActivePerOwner = _opPos(n, "maxActiveOrchProfilesPerOwner");
517
+ }
518
+ export function getMaxActiveOrchProfilesPerOwnerV2() {
519
+ return _opMaxActivePerOwner;
520
+ }
521
+ export function setMaxPendingOrchTasksPerProfileV2(n) {
522
+ _opMaxPendingTasksPerProfile = _opPos(n, "maxPendingOrchTasksPerProfile");
523
+ }
524
+ export function getMaxPendingOrchTasksPerProfileV2() {
525
+ return _opMaxPendingTasksPerProfile;
526
+ }
527
+ export function setOrchProfileIdleMsV2(n) {
528
+ _opIdleMs = _opPos(n, "orchProfileIdleMs");
529
+ }
530
+ export function getOrchProfileIdleMsV2() {
531
+ return _opIdleMs;
532
+ }
533
+ export function setOrchTaskStuckMsV2(n) {
534
+ _otStuckMs = _opPos(n, "orchTaskStuckMs");
535
+ }
536
+ export function getOrchTaskStuckMsV2() {
537
+ return _otStuckMs;
538
+ }
481
539
 
482
540
  export function _resetStateOrchestratorV2() {
483
- _opsV2.clear(); _otsV2.clear();
484
- _opMaxActivePerOwner = 6; _opMaxPendingTasksPerProfile = 12;
485
- _opIdleMs = 14 * 24 * 60 * 60 * 1000; _otStuckMs = 15 * 60 * 1000;
541
+ _opsV2.clear();
542
+ _otsV2.clear();
543
+ _opMaxActivePerOwner = 6;
544
+ _opMaxPendingTasksPerProfile = 12;
545
+ _opIdleMs = 14 * 24 * 60 * 60 * 1000;
546
+ _otStuckMs = 15 * 60 * 1000;
486
547
  }
487
548
 
488
549
  export function registerOrchProfileV2({ id, owner, source, metadata } = {}) {
@@ -490,54 +551,238 @@ export function registerOrchProfileV2({ id, owner, source, metadata } = {}) {
490
551
  if (!owner || typeof owner !== "string") throw new Error("owner is required");
491
552
  if (_opsV2.has(id)) throw new Error(`orch profile ${id} already registered`);
492
553
  const now = Date.now();
493
- const p = { id, owner, source: source || "cli", status: ORCH_PROFILE_MATURITY_V2.PENDING, createdAt: now, updatedAt: now, activatedAt: null, retiredAt: null, lastTouchedAt: now, metadata: { ...(metadata || {}) } };
554
+ const p = {
555
+ id,
556
+ owner,
557
+ source: source || "cli",
558
+ status: ORCH_PROFILE_MATURITY_V2.PENDING,
559
+ createdAt: now,
560
+ updatedAt: now,
561
+ activatedAt: null,
562
+ retiredAt: null,
563
+ lastTouchedAt: now,
564
+ metadata: { ...(metadata || {}) },
565
+ };
494
566
  _opsV2.set(id, p);
495
567
  return { ...p, metadata: { ...p.metadata } };
496
568
  }
497
- function _opCheckP(from, to) { const a = _opTrans.get(from); if (!a || !a.has(to)) throw new Error(`invalid orch profile transition ${from} → ${to}`); }
498
- function _opCountActive(owner) { let n = 0; for (const p of _opsV2.values()) if (p.owner === owner && p.status === ORCH_PROFILE_MATURITY_V2.ACTIVE) n++; return n; }
569
+ function _opCheckP(from, to) {
570
+ const a = _opTrans.get(from);
571
+ if (!a || !a.has(to))
572
+ throw new Error(`invalid orch profile transition ${from} → ${to}`);
573
+ }
574
+ function _opCountActive(owner) {
575
+ let n = 0;
576
+ for (const p of _opsV2.values())
577
+ if (p.owner === owner && p.status === ORCH_PROFILE_MATURITY_V2.ACTIVE) n++;
578
+ return n;
579
+ }
499
580
 
500
581
  export function activateOrchProfileV2(id) {
501
- const p = _opsV2.get(id); if (!p) throw new Error(`orch profile ${id} not found`);
582
+ const p = _opsV2.get(id);
583
+ if (!p) throw new Error(`orch profile ${id} not found`);
502
584
  _opCheckP(p.status, ORCH_PROFILE_MATURITY_V2.ACTIVE);
503
585
  const recovery = p.status === ORCH_PROFILE_MATURITY_V2.PAUSED;
504
- if (!recovery) { const c = _opCountActive(p.owner); if (c >= _opMaxActivePerOwner) throw new Error(`max active orch profiles per owner (${_opMaxActivePerOwner}) reached for ${p.owner}`); }
505
- const now = Date.now(); p.status = ORCH_PROFILE_MATURITY_V2.ACTIVE; p.updatedAt = now; p.lastTouchedAt = now; if (!p.activatedAt) p.activatedAt = now;
586
+ if (!recovery) {
587
+ const c = _opCountActive(p.owner);
588
+ if (c >= _opMaxActivePerOwner)
589
+ throw new Error(
590
+ `max active orch profiles per owner (${_opMaxActivePerOwner}) reached for ${p.owner}`,
591
+ );
592
+ }
593
+ const now = Date.now();
594
+ p.status = ORCH_PROFILE_MATURITY_V2.ACTIVE;
595
+ p.updatedAt = now;
596
+ p.lastTouchedAt = now;
597
+ if (!p.activatedAt) p.activatedAt = now;
598
+ return { ...p, metadata: { ...p.metadata } };
599
+ }
600
+ export function pauseOrchProfileV2(id) {
601
+ const p = _opsV2.get(id);
602
+ if (!p) throw new Error(`orch profile ${id} not found`);
603
+ _opCheckP(p.status, ORCH_PROFILE_MATURITY_V2.PAUSED);
604
+ p.status = ORCH_PROFILE_MATURITY_V2.PAUSED;
605
+ p.updatedAt = Date.now();
606
+ return { ...p, metadata: { ...p.metadata } };
607
+ }
608
+ export function retireOrchProfileV2(id) {
609
+ const p = _opsV2.get(id);
610
+ if (!p) throw new Error(`orch profile ${id} not found`);
611
+ _opCheckP(p.status, ORCH_PROFILE_MATURITY_V2.RETIRED);
612
+ const now = Date.now();
613
+ p.status = ORCH_PROFILE_MATURITY_V2.RETIRED;
614
+ p.updatedAt = now;
615
+ if (!p.retiredAt) p.retiredAt = now;
616
+ return { ...p, metadata: { ...p.metadata } };
617
+ }
618
+ export function touchOrchProfileV2(id) {
619
+ const p = _opsV2.get(id);
620
+ if (!p) throw new Error(`orch profile ${id} not found`);
621
+ if (_opTerminal.has(p.status))
622
+ throw new Error(`cannot touch terminal orch profile ${id}`);
623
+ const now = Date.now();
624
+ p.lastTouchedAt = now;
625
+ p.updatedAt = now;
506
626
  return { ...p, metadata: { ...p.metadata } };
507
627
  }
508
- export function pauseOrchProfileV2(id) { const p = _opsV2.get(id); if (!p) throw new Error(`orch profile ${id} not found`); _opCheckP(p.status, ORCH_PROFILE_MATURITY_V2.PAUSED); p.status = ORCH_PROFILE_MATURITY_V2.PAUSED; p.updatedAt = Date.now(); return { ...p, metadata: { ...p.metadata } }; }
509
- export function retireOrchProfileV2(id) { const p = _opsV2.get(id); if (!p) throw new Error(`orch profile ${id} not found`); _opCheckP(p.status, ORCH_PROFILE_MATURITY_V2.RETIRED); const now = Date.now(); p.status = ORCH_PROFILE_MATURITY_V2.RETIRED; p.updatedAt = now; if (!p.retiredAt) p.retiredAt = now; return { ...p, metadata: { ...p.metadata } }; }
510
- export function touchOrchProfileV2(id) { const p = _opsV2.get(id); if (!p) throw new Error(`orch profile ${id} not found`); if (_opTerminal.has(p.status)) throw new Error(`cannot touch terminal orch profile ${id}`); const now = Date.now(); p.lastTouchedAt = now; p.updatedAt = now; return { ...p, metadata: { ...p.metadata } }; }
511
- export function getOrchProfileV2(id) { const p = _opsV2.get(id); if (!p) return null; return { ...p, metadata: { ...p.metadata } }; }
512
- export function listOrchProfilesV2() { return [..._opsV2.values()].map((p) => ({ ...p, metadata: { ...p.metadata } })); }
628
+ export function getOrchProfileV2(id) {
629
+ const p = _opsV2.get(id);
630
+ if (!p) return null;
631
+ return { ...p, metadata: { ...p.metadata } };
632
+ }
633
+ export function listOrchProfilesV2() {
634
+ return [..._opsV2.values()].map((p) => ({
635
+ ...p,
636
+ metadata: { ...p.metadata },
637
+ }));
638
+ }
513
639
 
514
- function _otCountPending(profileId) { let n = 0; for (const t of _otsV2.values()) if (t.profileId === profileId && (t.status === ORCH_TASK_LIFECYCLE_V2.QUEUED || t.status === ORCH_TASK_LIFECYCLE_V2.DISPATCHING)) n++; return n; }
640
+ function _otCountPending(profileId) {
641
+ let n = 0;
642
+ for (const t of _otsV2.values())
643
+ if (
644
+ t.profileId === profileId &&
645
+ (t.status === ORCH_TASK_LIFECYCLE_V2.QUEUED ||
646
+ t.status === ORCH_TASK_LIFECYCLE_V2.DISPATCHING)
647
+ )
648
+ n++;
649
+ return n;
650
+ }
515
651
 
516
652
  export function createOrchTaskV2({ id, profileId, prompt, metadata } = {}) {
517
653
  if (!id || typeof id !== "string") throw new Error("id is required");
518
- if (!profileId || typeof profileId !== "string") throw new Error("profileId is required");
654
+ if (!profileId || typeof profileId !== "string")
655
+ throw new Error("profileId is required");
519
656
  if (_otsV2.has(id)) throw new Error(`orch task ${id} already exists`);
520
- if (!_opsV2.has(profileId)) throw new Error(`orch profile ${profileId} not found`);
657
+ if (!_opsV2.has(profileId))
658
+ throw new Error(`orch profile ${profileId} not found`);
521
659
  const pending = _otCountPending(profileId);
522
- if (pending >= _opMaxPendingTasksPerProfile) throw new Error(`max pending orch tasks per profile (${_opMaxPendingTasksPerProfile}) reached for ${profileId}`);
660
+ if (pending >= _opMaxPendingTasksPerProfile)
661
+ throw new Error(
662
+ `max pending orch tasks per profile (${_opMaxPendingTasksPerProfile}) reached for ${profileId}`,
663
+ );
523
664
  const now = Date.now();
524
- const t = { id, profileId, prompt: prompt || "", status: ORCH_TASK_LIFECYCLE_V2.QUEUED, createdAt: now, updatedAt: now, startedAt: null, settledAt: null, metadata: { ...(metadata || {}) } };
665
+ const t = {
666
+ id,
667
+ profileId,
668
+ prompt: prompt || "",
669
+ status: ORCH_TASK_LIFECYCLE_V2.QUEUED,
670
+ createdAt: now,
671
+ updatedAt: now,
672
+ startedAt: null,
673
+ settledAt: null,
674
+ metadata: { ...(metadata || {}) },
675
+ };
525
676
  _otsV2.set(id, t);
526
677
  return { ...t, metadata: { ...t.metadata } };
527
678
  }
528
- function _otCheckT(from, to) { const a = _otTrans.get(from); if (!a || !a.has(to)) throw new Error(`invalid orch task transition ${from} → ${to}`); }
529
- export function dispatchOrchTaskV2(id) { const t = _otsV2.get(id); if (!t) throw new Error(`orch task ${id} not found`); _otCheckT(t.status, ORCH_TASK_LIFECYCLE_V2.DISPATCHING); const now = Date.now(); t.status = ORCH_TASK_LIFECYCLE_V2.DISPATCHING; t.updatedAt = now; if (!t.startedAt) t.startedAt = now; return { ...t, metadata: { ...t.metadata } }; }
530
- export function completeOrchTaskV2(id) { const t = _otsV2.get(id); if (!t) throw new Error(`orch task ${id} not found`); _otCheckT(t.status, ORCH_TASK_LIFECYCLE_V2.COMPLETED); const now = Date.now(); t.status = ORCH_TASK_LIFECYCLE_V2.COMPLETED; t.updatedAt = now; if (!t.settledAt) t.settledAt = now; return { ...t, metadata: { ...t.metadata } }; }
531
- export function failOrchTaskV2(id, reason) { const t = _otsV2.get(id); if (!t) throw new Error(`orch task ${id} not found`); _otCheckT(t.status, ORCH_TASK_LIFECYCLE_V2.FAILED); const now = Date.now(); t.status = ORCH_TASK_LIFECYCLE_V2.FAILED; t.updatedAt = now; if (!t.settledAt) t.settledAt = now; if (reason) t.metadata.failReason = String(reason); return { ...t, metadata: { ...t.metadata } }; }
532
- export function cancelOrchTaskV2(id, reason) { const t = _otsV2.get(id); if (!t) throw new Error(`orch task ${id} not found`); _otCheckT(t.status, ORCH_TASK_LIFECYCLE_V2.CANCELLED); const now = Date.now(); t.status = ORCH_TASK_LIFECYCLE_V2.CANCELLED; t.updatedAt = now; if (!t.settledAt) t.settledAt = now; if (reason) t.metadata.cancelReason = String(reason); return { ...t, metadata: { ...t.metadata } }; }
533
- export function getOrchTaskV2(id) { const t = _otsV2.get(id); if (!t) return null; return { ...t, metadata: { ...t.metadata } }; }
534
- export function listOrchTasksV2() { return [..._otsV2.values()].map((t) => ({ ...t, metadata: { ...t.metadata } })); }
679
+ function _otCheckT(from, to) {
680
+ const a = _otTrans.get(from);
681
+ if (!a || !a.has(to))
682
+ throw new Error(`invalid orch task transition ${from} ${to}`);
683
+ }
684
+ export function dispatchOrchTaskV2(id) {
685
+ const t = _otsV2.get(id);
686
+ if (!t) throw new Error(`orch task ${id} not found`);
687
+ _otCheckT(t.status, ORCH_TASK_LIFECYCLE_V2.DISPATCHING);
688
+ const now = Date.now();
689
+ t.status = ORCH_TASK_LIFECYCLE_V2.DISPATCHING;
690
+ t.updatedAt = now;
691
+ if (!t.startedAt) t.startedAt = now;
692
+ return { ...t, metadata: { ...t.metadata } };
693
+ }
694
+ export function completeOrchTaskV2(id) {
695
+ const t = _otsV2.get(id);
696
+ if (!t) throw new Error(`orch task ${id} not found`);
697
+ _otCheckT(t.status, ORCH_TASK_LIFECYCLE_V2.COMPLETED);
698
+ const now = Date.now();
699
+ t.status = ORCH_TASK_LIFECYCLE_V2.COMPLETED;
700
+ t.updatedAt = now;
701
+ if (!t.settledAt) t.settledAt = now;
702
+ return { ...t, metadata: { ...t.metadata } };
703
+ }
704
+ export function failOrchTaskV2(id, reason) {
705
+ const t = _otsV2.get(id);
706
+ if (!t) throw new Error(`orch task ${id} not found`);
707
+ _otCheckT(t.status, ORCH_TASK_LIFECYCLE_V2.FAILED);
708
+ const now = Date.now();
709
+ t.status = ORCH_TASK_LIFECYCLE_V2.FAILED;
710
+ t.updatedAt = now;
711
+ if (!t.settledAt) t.settledAt = now;
712
+ if (reason) t.metadata.failReason = String(reason);
713
+ return { ...t, metadata: { ...t.metadata } };
714
+ }
715
+ export function cancelOrchTaskV2(id, reason) {
716
+ const t = _otsV2.get(id);
717
+ if (!t) throw new Error(`orch task ${id} not found`);
718
+ _otCheckT(t.status, ORCH_TASK_LIFECYCLE_V2.CANCELLED);
719
+ const now = Date.now();
720
+ t.status = ORCH_TASK_LIFECYCLE_V2.CANCELLED;
721
+ t.updatedAt = now;
722
+ if (!t.settledAt) t.settledAt = now;
723
+ if (reason) t.metadata.cancelReason = String(reason);
724
+ return { ...t, metadata: { ...t.metadata } };
725
+ }
726
+ export function getOrchTaskV2(id) {
727
+ const t = _otsV2.get(id);
728
+ if (!t) return null;
729
+ return { ...t, metadata: { ...t.metadata } };
730
+ }
731
+ export function listOrchTasksV2() {
732
+ return [..._otsV2.values()].map((t) => ({
733
+ ...t,
734
+ metadata: { ...t.metadata },
735
+ }));
736
+ }
535
737
 
536
- export function autoPauseIdleOrchProfilesV2({ now } = {}) { const t = now ?? Date.now(); const flipped = []; for (const p of _opsV2.values()) if (p.status === ORCH_PROFILE_MATURITY_V2.ACTIVE && (t - p.lastTouchedAt) >= _opIdleMs) { p.status = ORCH_PROFILE_MATURITY_V2.PAUSED; p.updatedAt = t; flipped.push(p.id); } return { flipped, count: flipped.length }; }
537
- export function autoFailStuckOrchTasksV2({ now } = {}) { const t = now ?? Date.now(); const flipped = []; for (const x of _otsV2.values()) if (x.status === ORCH_TASK_LIFECYCLE_V2.DISPATCHING && x.startedAt != null && (t - x.startedAt) >= _otStuckMs) { x.status = ORCH_TASK_LIFECYCLE_V2.FAILED; x.updatedAt = t; if (!x.settledAt) x.settledAt = t; x.metadata.failReason = "auto-fail-stuck"; flipped.push(x.id); } return { flipped, count: flipped.length }; }
738
+ export function autoPauseIdleOrchProfilesV2({ now } = {}) {
739
+ const t = now ?? Date.now();
740
+ const flipped = [];
741
+ for (const p of _opsV2.values())
742
+ if (
743
+ p.status === ORCH_PROFILE_MATURITY_V2.ACTIVE &&
744
+ t - p.lastTouchedAt >= _opIdleMs
745
+ ) {
746
+ p.status = ORCH_PROFILE_MATURITY_V2.PAUSED;
747
+ p.updatedAt = t;
748
+ flipped.push(p.id);
749
+ }
750
+ return { flipped, count: flipped.length };
751
+ }
752
+ export function autoFailStuckOrchTasksV2({ now } = {}) {
753
+ const t = now ?? Date.now();
754
+ const flipped = [];
755
+ for (const x of _otsV2.values())
756
+ if (
757
+ x.status === ORCH_TASK_LIFECYCLE_V2.DISPATCHING &&
758
+ x.startedAt != null &&
759
+ t - x.startedAt >= _otStuckMs
760
+ ) {
761
+ x.status = ORCH_TASK_LIFECYCLE_V2.FAILED;
762
+ x.updatedAt = t;
763
+ if (!x.settledAt) x.settledAt = t;
764
+ x.metadata.failReason = "auto-fail-stuck";
765
+ flipped.push(x.id);
766
+ }
767
+ return { flipped, count: flipped.length };
768
+ }
538
769
 
539
770
  export function getOrchestratorGovStatsV2() {
540
- const profilesByStatus = {}; for (const s of Object.values(ORCH_PROFILE_MATURITY_V2)) profilesByStatus[s] = 0; for (const p of _opsV2.values()) profilesByStatus[p.status]++;
541
- const tasksByStatus = {}; for (const s of Object.values(ORCH_TASK_LIFECYCLE_V2)) tasksByStatus[s] = 0; for (const t of _otsV2.values()) tasksByStatus[t.status]++;
542
- return { totalOrchProfilesV2: _opsV2.size, totalOrchTasksV2: _otsV2.size, maxActiveOrchProfilesPerOwner: _opMaxActivePerOwner, maxPendingOrchTasksPerProfile: _opMaxPendingTasksPerProfile, orchProfileIdleMs: _opIdleMs, orchTaskStuckMs: _otStuckMs, profilesByStatus, tasksByStatus };
771
+ const profilesByStatus = {};
772
+ for (const s of Object.values(ORCH_PROFILE_MATURITY_V2))
773
+ profilesByStatus[s] = 0;
774
+ for (const p of _opsV2.values()) profilesByStatus[p.status]++;
775
+ const tasksByStatus = {};
776
+ for (const s of Object.values(ORCH_TASK_LIFECYCLE_V2)) tasksByStatus[s] = 0;
777
+ for (const t of _otsV2.values()) tasksByStatus[t.status]++;
778
+ return {
779
+ totalOrchProfilesV2: _opsV2.size,
780
+ totalOrchTasksV2: _otsV2.size,
781
+ maxActiveOrchProfilesPerOwner: _opMaxActivePerOwner,
782
+ maxPendingOrchTasksPerProfile: _opMaxPendingTasksPerProfile,
783
+ orchProfileIdleMs: _opIdleMs,
784
+ orchTaskStuckMs: _otStuckMs,
785
+ profilesByStatus,
786
+ tasksByStatus,
787
+ };
543
788
  }