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
@@ -466,25 +466,62 @@ function _appendHistory(cwd, entry, userMessage) {
466
466
  }
467
467
  }
468
468
 
469
-
470
469
  // ===== V2 Surface: Cowork Task Runner governance overlay (CLI v0.139.0) =====
471
470
  export const RUNNER_PROFILE_MATURITY_V2 = Object.freeze({
472
- PENDING: "pending", ACTIVE: "active", PAUSED: "paused", RETIRED: "retired",
471
+ PENDING: "pending",
472
+ ACTIVE: "active",
473
+ PAUSED: "paused",
474
+ RETIRED: "retired",
473
475
  });
474
476
  export const RUNNER_EXEC_LIFECYCLE_V2 = Object.freeze({
475
- QUEUED: "queued", RUNNING: "running", SUCCEEDED: "succeeded", FAILED: "failed", CANCELLED: "cancelled",
477
+ QUEUED: "queued",
478
+ RUNNING: "running",
479
+ SUCCEEDED: "succeeded",
480
+ FAILED: "failed",
481
+ CANCELLED: "cancelled",
476
482
  });
477
483
 
478
484
  const _rpTrans = new Map([
479
- [RUNNER_PROFILE_MATURITY_V2.PENDING, new Set([RUNNER_PROFILE_MATURITY_V2.ACTIVE, RUNNER_PROFILE_MATURITY_V2.RETIRED])],
480
- [RUNNER_PROFILE_MATURITY_V2.ACTIVE, new Set([RUNNER_PROFILE_MATURITY_V2.PAUSED, RUNNER_PROFILE_MATURITY_V2.RETIRED])],
481
- [RUNNER_PROFILE_MATURITY_V2.PAUSED, new Set([RUNNER_PROFILE_MATURITY_V2.ACTIVE, RUNNER_PROFILE_MATURITY_V2.RETIRED])],
485
+ [
486
+ RUNNER_PROFILE_MATURITY_V2.PENDING,
487
+ new Set([
488
+ RUNNER_PROFILE_MATURITY_V2.ACTIVE,
489
+ RUNNER_PROFILE_MATURITY_V2.RETIRED,
490
+ ]),
491
+ ],
492
+ [
493
+ RUNNER_PROFILE_MATURITY_V2.ACTIVE,
494
+ new Set([
495
+ RUNNER_PROFILE_MATURITY_V2.PAUSED,
496
+ RUNNER_PROFILE_MATURITY_V2.RETIRED,
497
+ ]),
498
+ ],
499
+ [
500
+ RUNNER_PROFILE_MATURITY_V2.PAUSED,
501
+ new Set([
502
+ RUNNER_PROFILE_MATURITY_V2.ACTIVE,
503
+ RUNNER_PROFILE_MATURITY_V2.RETIRED,
504
+ ]),
505
+ ],
482
506
  [RUNNER_PROFILE_MATURITY_V2.RETIRED, new Set()],
483
507
  ]);
484
508
  const _rpTerminal = new Set([RUNNER_PROFILE_MATURITY_V2.RETIRED]);
485
509
  const _reTrans = new Map([
486
- [RUNNER_EXEC_LIFECYCLE_V2.QUEUED, new Set([RUNNER_EXEC_LIFECYCLE_V2.RUNNING, RUNNER_EXEC_LIFECYCLE_V2.CANCELLED])],
487
- [RUNNER_EXEC_LIFECYCLE_V2.RUNNING, new Set([RUNNER_EXEC_LIFECYCLE_V2.SUCCEEDED, RUNNER_EXEC_LIFECYCLE_V2.FAILED, RUNNER_EXEC_LIFECYCLE_V2.CANCELLED])],
510
+ [
511
+ RUNNER_EXEC_LIFECYCLE_V2.QUEUED,
512
+ new Set([
513
+ RUNNER_EXEC_LIFECYCLE_V2.RUNNING,
514
+ RUNNER_EXEC_LIFECYCLE_V2.CANCELLED,
515
+ ]),
516
+ ],
517
+ [
518
+ RUNNER_EXEC_LIFECYCLE_V2.RUNNING,
519
+ new Set([
520
+ RUNNER_EXEC_LIFECYCLE_V2.SUCCEEDED,
521
+ RUNNER_EXEC_LIFECYCLE_V2.FAILED,
522
+ RUNNER_EXEC_LIFECYCLE_V2.CANCELLED,
523
+ ]),
524
+ ],
488
525
  [RUNNER_EXEC_LIFECYCLE_V2.SUCCEEDED, new Set()],
489
526
  [RUNNER_EXEC_LIFECYCLE_V2.FAILED, new Set()],
490
527
  [RUNNER_EXEC_LIFECYCLE_V2.CANCELLED, new Set()],
@@ -497,76 +534,296 @@ let _rpMaxPendingExecsPerProfile = 15;
497
534
  let _rpIdleMs = 14 * 24 * 60 * 60 * 1000;
498
535
  let _reStuckMs = 20 * 60 * 1000;
499
536
 
500
- function _rpPos(n, lbl) { const v = Math.floor(Number(n)); if (!Number.isFinite(v) || v <= 0) throw new Error(`${lbl} must be positive integer`); return v; }
537
+ function _rpPos(n, lbl) {
538
+ const v = Math.floor(Number(n));
539
+ if (!Number.isFinite(v) || v <= 0)
540
+ throw new Error(`${lbl} must be positive integer`);
541
+ return v;
542
+ }
501
543
 
502
- export function setMaxActiveRunnerProfilesPerOwnerV2(n) { _rpMaxActivePerOwner = _rpPos(n, "maxActiveRunnerProfilesPerOwner"); }
503
- export function getMaxActiveRunnerProfilesPerOwnerV2() { return _rpMaxActivePerOwner; }
504
- export function setMaxPendingRunnerExecsPerProfileV2(n) { _rpMaxPendingExecsPerProfile = _rpPos(n, "maxPendingRunnerExecsPerProfile"); }
505
- export function getMaxPendingRunnerExecsPerProfileV2() { return _rpMaxPendingExecsPerProfile; }
506
- export function setRunnerProfileIdleMsV2(n) { _rpIdleMs = _rpPos(n, "runnerProfileIdleMs"); }
507
- export function getRunnerProfileIdleMsV2() { return _rpIdleMs; }
508
- export function setRunnerExecStuckMsV2(n) { _reStuckMs = _rpPos(n, "runnerExecStuckMs"); }
509
- export function getRunnerExecStuckMsV2() { return _reStuckMs; }
544
+ export function setMaxActiveRunnerProfilesPerOwnerV2(n) {
545
+ _rpMaxActivePerOwner = _rpPos(n, "maxActiveRunnerProfilesPerOwner");
546
+ }
547
+ export function getMaxActiveRunnerProfilesPerOwnerV2() {
548
+ return _rpMaxActivePerOwner;
549
+ }
550
+ export function setMaxPendingRunnerExecsPerProfileV2(n) {
551
+ _rpMaxPendingExecsPerProfile = _rpPos(n, "maxPendingRunnerExecsPerProfile");
552
+ }
553
+ export function getMaxPendingRunnerExecsPerProfileV2() {
554
+ return _rpMaxPendingExecsPerProfile;
555
+ }
556
+ export function setRunnerProfileIdleMsV2(n) {
557
+ _rpIdleMs = _rpPos(n, "runnerProfileIdleMs");
558
+ }
559
+ export function getRunnerProfileIdleMsV2() {
560
+ return _rpIdleMs;
561
+ }
562
+ export function setRunnerExecStuckMsV2(n) {
563
+ _reStuckMs = _rpPos(n, "runnerExecStuckMs");
564
+ }
565
+ export function getRunnerExecStuckMsV2() {
566
+ return _reStuckMs;
567
+ }
510
568
 
511
569
  export function _resetStateRunnerV2() {
512
- _rpsV2.clear(); _resV2.clear();
513
- _rpMaxActivePerOwner = 8; _rpMaxPendingExecsPerProfile = 15;
514
- _rpIdleMs = 14 * 24 * 60 * 60 * 1000; _reStuckMs = 20 * 60 * 1000;
570
+ _rpsV2.clear();
571
+ _resV2.clear();
572
+ _rpMaxActivePerOwner = 8;
573
+ _rpMaxPendingExecsPerProfile = 15;
574
+ _rpIdleMs = 14 * 24 * 60 * 60 * 1000;
575
+ _reStuckMs = 20 * 60 * 1000;
515
576
  }
516
577
 
517
- export function registerRunnerProfileV2({ id, owner, template, metadata } = {}) {
578
+ export function registerRunnerProfileV2({
579
+ id,
580
+ owner,
581
+ template,
582
+ metadata,
583
+ } = {}) {
518
584
  if (!id || typeof id !== "string") throw new Error("id is required");
519
585
  if (!owner || typeof owner !== "string") throw new Error("owner is required");
520
- if (_rpsV2.has(id)) throw new Error(`runner profile ${id} already registered`);
586
+ if (_rpsV2.has(id))
587
+ throw new Error(`runner profile ${id} already registered`);
521
588
  const now = Date.now();
522
- const p = { id, owner, template: template || "default", status: RUNNER_PROFILE_MATURITY_V2.PENDING, createdAt: now, updatedAt: now, activatedAt: null, retiredAt: null, lastTouchedAt: now, metadata: { ...(metadata || {}) } };
589
+ const p = {
590
+ id,
591
+ owner,
592
+ template: template || "default",
593
+ status: RUNNER_PROFILE_MATURITY_V2.PENDING,
594
+ createdAt: now,
595
+ updatedAt: now,
596
+ activatedAt: null,
597
+ retiredAt: null,
598
+ lastTouchedAt: now,
599
+ metadata: { ...(metadata || {}) },
600
+ };
523
601
  _rpsV2.set(id, p);
524
602
  return { ...p, metadata: { ...p.metadata } };
525
603
  }
526
- function _rpCheckP(from, to) { const a = _rpTrans.get(from); if (!a || !a.has(to)) throw new Error(`invalid runner profile transition ${from} → ${to}`); }
527
- function _rpCountActive(owner) { let n = 0; for (const p of _rpsV2.values()) if (p.owner === owner && p.status === RUNNER_PROFILE_MATURITY_V2.ACTIVE) n++; return n; }
604
+ function _rpCheckP(from, to) {
605
+ const a = _rpTrans.get(from);
606
+ if (!a || !a.has(to))
607
+ throw new Error(`invalid runner profile transition ${from} → ${to}`);
608
+ }
609
+ function _rpCountActive(owner) {
610
+ let n = 0;
611
+ for (const p of _rpsV2.values())
612
+ if (p.owner === owner && p.status === RUNNER_PROFILE_MATURITY_V2.ACTIVE)
613
+ n++;
614
+ return n;
615
+ }
528
616
 
529
617
  export function activateRunnerProfileV2(id) {
530
- const p = _rpsV2.get(id); if (!p) throw new Error(`runner profile ${id} not found`);
618
+ const p = _rpsV2.get(id);
619
+ if (!p) throw new Error(`runner profile ${id} not found`);
531
620
  _rpCheckP(p.status, RUNNER_PROFILE_MATURITY_V2.ACTIVE);
532
621
  const recovery = p.status === RUNNER_PROFILE_MATURITY_V2.PAUSED;
533
- if (!recovery) { const c = _rpCountActive(p.owner); if (c >= _rpMaxActivePerOwner) throw new Error(`max active runner profiles per owner (${_rpMaxActivePerOwner}) reached for ${p.owner}`); }
534
- const now = Date.now(); p.status = RUNNER_PROFILE_MATURITY_V2.ACTIVE; p.updatedAt = now; p.lastTouchedAt = now; if (!p.activatedAt) p.activatedAt = now;
622
+ if (!recovery) {
623
+ const c = _rpCountActive(p.owner);
624
+ if (c >= _rpMaxActivePerOwner)
625
+ throw new Error(
626
+ `max active runner profiles per owner (${_rpMaxActivePerOwner}) reached for ${p.owner}`,
627
+ );
628
+ }
629
+ const now = Date.now();
630
+ p.status = RUNNER_PROFILE_MATURITY_V2.ACTIVE;
631
+ p.updatedAt = now;
632
+ p.lastTouchedAt = now;
633
+ if (!p.activatedAt) p.activatedAt = now;
634
+ return { ...p, metadata: { ...p.metadata } };
635
+ }
636
+ export function pauseRunnerProfileV2(id) {
637
+ const p = _rpsV2.get(id);
638
+ if (!p) throw new Error(`runner profile ${id} not found`);
639
+ _rpCheckP(p.status, RUNNER_PROFILE_MATURITY_V2.PAUSED);
640
+ p.status = RUNNER_PROFILE_MATURITY_V2.PAUSED;
641
+ p.updatedAt = Date.now();
642
+ return { ...p, metadata: { ...p.metadata } };
643
+ }
644
+ export function retireRunnerProfileV2(id) {
645
+ const p = _rpsV2.get(id);
646
+ if (!p) throw new Error(`runner profile ${id} not found`);
647
+ _rpCheckP(p.status, RUNNER_PROFILE_MATURITY_V2.RETIRED);
648
+ const now = Date.now();
649
+ p.status = RUNNER_PROFILE_MATURITY_V2.RETIRED;
650
+ p.updatedAt = now;
651
+ if (!p.retiredAt) p.retiredAt = now;
652
+ return { ...p, metadata: { ...p.metadata } };
653
+ }
654
+ export function touchRunnerProfileV2(id) {
655
+ const p = _rpsV2.get(id);
656
+ if (!p) throw new Error(`runner profile ${id} not found`);
657
+ if (_rpTerminal.has(p.status))
658
+ throw new Error(`cannot touch terminal runner profile ${id}`);
659
+ const now = Date.now();
660
+ p.lastTouchedAt = now;
661
+ p.updatedAt = now;
662
+ return { ...p, metadata: { ...p.metadata } };
663
+ }
664
+ export function getRunnerProfileV2(id) {
665
+ const p = _rpsV2.get(id);
666
+ if (!p) return null;
535
667
  return { ...p, metadata: { ...p.metadata } };
536
668
  }
537
- export function pauseRunnerProfileV2(id) { const p = _rpsV2.get(id); if (!p) throw new Error(`runner profile ${id} not found`); _rpCheckP(p.status, RUNNER_PROFILE_MATURITY_V2.PAUSED); p.status = RUNNER_PROFILE_MATURITY_V2.PAUSED; p.updatedAt = Date.now(); return { ...p, metadata: { ...p.metadata } }; }
538
- export function retireRunnerProfileV2(id) { const p = _rpsV2.get(id); if (!p) throw new Error(`runner profile ${id} not found`); _rpCheckP(p.status, RUNNER_PROFILE_MATURITY_V2.RETIRED); const now = Date.now(); p.status = RUNNER_PROFILE_MATURITY_V2.RETIRED; p.updatedAt = now; if (!p.retiredAt) p.retiredAt = now; return { ...p, metadata: { ...p.metadata } }; }
539
- export function touchRunnerProfileV2(id) { const p = _rpsV2.get(id); if (!p) throw new Error(`runner profile ${id} not found`); if (_rpTerminal.has(p.status)) throw new Error(`cannot touch terminal runner profile ${id}`); const now = Date.now(); p.lastTouchedAt = now; p.updatedAt = now; return { ...p, metadata: { ...p.metadata } }; }
540
- export function getRunnerProfileV2(id) { const p = _rpsV2.get(id); if (!p) return null; return { ...p, metadata: { ...p.metadata } }; }
541
- export function listRunnerProfilesV2() { return [..._rpsV2.values()].map((p) => ({ ...p, metadata: { ...p.metadata } })); }
669
+ export function listRunnerProfilesV2() {
670
+ return [..._rpsV2.values()].map((p) => ({
671
+ ...p,
672
+ metadata: { ...p.metadata },
673
+ }));
674
+ }
542
675
 
543
- function _reCountPending(profileId) { let n = 0; for (const e of _resV2.values()) if (e.profileId === profileId && (e.status === RUNNER_EXEC_LIFECYCLE_V2.QUEUED || e.status === RUNNER_EXEC_LIFECYCLE_V2.RUNNING)) n++; return n; }
676
+ function _reCountPending(profileId) {
677
+ let n = 0;
678
+ for (const e of _resV2.values())
679
+ if (
680
+ e.profileId === profileId &&
681
+ (e.status === RUNNER_EXEC_LIFECYCLE_V2.QUEUED ||
682
+ e.status === RUNNER_EXEC_LIFECYCLE_V2.RUNNING)
683
+ )
684
+ n++;
685
+ return n;
686
+ }
544
687
 
545
- export function createRunnerExecV2({ id, profileId, taskInput, metadata } = {}) {
688
+ export function createRunnerExecV2({
689
+ id,
690
+ profileId,
691
+ taskInput,
692
+ metadata,
693
+ } = {}) {
546
694
  if (!id || typeof id !== "string") throw new Error("id is required");
547
- if (!profileId || typeof profileId !== "string") throw new Error("profileId is required");
695
+ if (!profileId || typeof profileId !== "string")
696
+ throw new Error("profileId is required");
548
697
  if (_resV2.has(id)) throw new Error(`runner exec ${id} already exists`);
549
- if (!_rpsV2.has(profileId)) throw new Error(`runner profile ${profileId} not found`);
698
+ if (!_rpsV2.has(profileId))
699
+ throw new Error(`runner profile ${profileId} not found`);
550
700
  const pending = _reCountPending(profileId);
551
- if (pending >= _rpMaxPendingExecsPerProfile) throw new Error(`max pending runner execs per profile (${_rpMaxPendingExecsPerProfile}) reached for ${profileId}`);
701
+ if (pending >= _rpMaxPendingExecsPerProfile)
702
+ throw new Error(
703
+ `max pending runner execs per profile (${_rpMaxPendingExecsPerProfile}) reached for ${profileId}`,
704
+ );
552
705
  const now = Date.now();
553
- const e = { id, profileId, taskInput: taskInput || "", status: RUNNER_EXEC_LIFECYCLE_V2.QUEUED, createdAt: now, updatedAt: now, startedAt: null, settledAt: null, metadata: { ...(metadata || {}) } };
706
+ const e = {
707
+ id,
708
+ profileId,
709
+ taskInput: taskInput || "",
710
+ status: RUNNER_EXEC_LIFECYCLE_V2.QUEUED,
711
+ createdAt: now,
712
+ updatedAt: now,
713
+ startedAt: null,
714
+ settledAt: null,
715
+ metadata: { ...(metadata || {}) },
716
+ };
554
717
  _resV2.set(id, e);
555
718
  return { ...e, metadata: { ...e.metadata } };
556
719
  }
557
- function _reCheckE(from, to) { const a = _reTrans.get(from); if (!a || !a.has(to)) throw new Error(`invalid runner exec transition ${from} → ${to}`); }
558
- export function startRunnerExecV2(id) { const e = _resV2.get(id); if (!e) throw new Error(`runner exec ${id} not found`); _reCheckE(e.status, RUNNER_EXEC_LIFECYCLE_V2.RUNNING); const now = Date.now(); e.status = RUNNER_EXEC_LIFECYCLE_V2.RUNNING; e.updatedAt = now; if (!e.startedAt) e.startedAt = now; return { ...e, metadata: { ...e.metadata } }; }
559
- export function succeedRunnerExecV2(id) { const e = _resV2.get(id); if (!e) throw new Error(`runner exec ${id} not found`); _reCheckE(e.status, RUNNER_EXEC_LIFECYCLE_V2.SUCCEEDED); const now = Date.now(); e.status = RUNNER_EXEC_LIFECYCLE_V2.SUCCEEDED; e.updatedAt = now; if (!e.settledAt) e.settledAt = now; return { ...e, metadata: { ...e.metadata } }; }
560
- export function failRunnerExecV2(id, reason) { const e = _resV2.get(id); if (!e) throw new Error(`runner exec ${id} not found`); _reCheckE(e.status, RUNNER_EXEC_LIFECYCLE_V2.FAILED); const now = Date.now(); e.status = RUNNER_EXEC_LIFECYCLE_V2.FAILED; e.updatedAt = now; if (!e.settledAt) e.settledAt = now; if (reason) e.metadata.failReason = String(reason); return { ...e, metadata: { ...e.metadata } }; }
561
- export function cancelRunnerExecV2(id, reason) { const e = _resV2.get(id); if (!e) throw new Error(`runner exec ${id} not found`); _reCheckE(e.status, RUNNER_EXEC_LIFECYCLE_V2.CANCELLED); const now = Date.now(); e.status = RUNNER_EXEC_LIFECYCLE_V2.CANCELLED; e.updatedAt = now; if (!e.settledAt) e.settledAt = now; if (reason) e.metadata.cancelReason = String(reason); return { ...e, metadata: { ...e.metadata } }; }
562
- export function getRunnerExecV2(id) { const e = _resV2.get(id); if (!e) return null; return { ...e, metadata: { ...e.metadata } }; }
563
- export function listRunnerExecsV2() { return [..._resV2.values()].map((e) => ({ ...e, metadata: { ...e.metadata } })); }
720
+ function _reCheckE(from, to) {
721
+ const a = _reTrans.get(from);
722
+ if (!a || !a.has(to))
723
+ throw new Error(`invalid runner exec transition ${from} ${to}`);
724
+ }
725
+ export function startRunnerExecV2(id) {
726
+ const e = _resV2.get(id);
727
+ if (!e) throw new Error(`runner exec ${id} not found`);
728
+ _reCheckE(e.status, RUNNER_EXEC_LIFECYCLE_V2.RUNNING);
729
+ const now = Date.now();
730
+ e.status = RUNNER_EXEC_LIFECYCLE_V2.RUNNING;
731
+ e.updatedAt = now;
732
+ if (!e.startedAt) e.startedAt = now;
733
+ return { ...e, metadata: { ...e.metadata } };
734
+ }
735
+ export function succeedRunnerExecV2(id) {
736
+ const e = _resV2.get(id);
737
+ if (!e) throw new Error(`runner exec ${id} not found`);
738
+ _reCheckE(e.status, RUNNER_EXEC_LIFECYCLE_V2.SUCCEEDED);
739
+ const now = Date.now();
740
+ e.status = RUNNER_EXEC_LIFECYCLE_V2.SUCCEEDED;
741
+ e.updatedAt = now;
742
+ if (!e.settledAt) e.settledAt = now;
743
+ return { ...e, metadata: { ...e.metadata } };
744
+ }
745
+ export function failRunnerExecV2(id, reason) {
746
+ const e = _resV2.get(id);
747
+ if (!e) throw new Error(`runner exec ${id} not found`);
748
+ _reCheckE(e.status, RUNNER_EXEC_LIFECYCLE_V2.FAILED);
749
+ const now = Date.now();
750
+ e.status = RUNNER_EXEC_LIFECYCLE_V2.FAILED;
751
+ e.updatedAt = now;
752
+ if (!e.settledAt) e.settledAt = now;
753
+ if (reason) e.metadata.failReason = String(reason);
754
+ return { ...e, metadata: { ...e.metadata } };
755
+ }
756
+ export function cancelRunnerExecV2(id, reason) {
757
+ const e = _resV2.get(id);
758
+ if (!e) throw new Error(`runner exec ${id} not found`);
759
+ _reCheckE(e.status, RUNNER_EXEC_LIFECYCLE_V2.CANCELLED);
760
+ const now = Date.now();
761
+ e.status = RUNNER_EXEC_LIFECYCLE_V2.CANCELLED;
762
+ e.updatedAt = now;
763
+ if (!e.settledAt) e.settledAt = now;
764
+ if (reason) e.metadata.cancelReason = String(reason);
765
+ return { ...e, metadata: { ...e.metadata } };
766
+ }
767
+ export function getRunnerExecV2(id) {
768
+ const e = _resV2.get(id);
769
+ if (!e) return null;
770
+ return { ...e, metadata: { ...e.metadata } };
771
+ }
772
+ export function listRunnerExecsV2() {
773
+ return [..._resV2.values()].map((e) => ({
774
+ ...e,
775
+ metadata: { ...e.metadata },
776
+ }));
777
+ }
564
778
 
565
- export function autoPauseIdleRunnerProfilesV2({ now } = {}) { const t = now ?? Date.now(); const flipped = []; for (const p of _rpsV2.values()) if (p.status === RUNNER_PROFILE_MATURITY_V2.ACTIVE && (t - p.lastTouchedAt) >= _rpIdleMs) { p.status = RUNNER_PROFILE_MATURITY_V2.PAUSED; p.updatedAt = t; flipped.push(p.id); } return { flipped, count: flipped.length }; }
566
- export function autoFailStuckRunnerExecsV2({ now } = {}) { const t = now ?? Date.now(); const flipped = []; for (const e of _resV2.values()) if (e.status === RUNNER_EXEC_LIFECYCLE_V2.RUNNING && e.startedAt != null && (t - e.startedAt) >= _reStuckMs) { e.status = RUNNER_EXEC_LIFECYCLE_V2.FAILED; e.updatedAt = t; if (!e.settledAt) e.settledAt = t; e.metadata.failReason = "auto-fail-stuck"; flipped.push(e.id); } return { flipped, count: flipped.length }; }
779
+ export function autoPauseIdleRunnerProfilesV2({ now } = {}) {
780
+ const t = now ?? Date.now();
781
+ const flipped = [];
782
+ for (const p of _rpsV2.values())
783
+ if (
784
+ p.status === RUNNER_PROFILE_MATURITY_V2.ACTIVE &&
785
+ t - p.lastTouchedAt >= _rpIdleMs
786
+ ) {
787
+ p.status = RUNNER_PROFILE_MATURITY_V2.PAUSED;
788
+ p.updatedAt = t;
789
+ flipped.push(p.id);
790
+ }
791
+ return { flipped, count: flipped.length };
792
+ }
793
+ export function autoFailStuckRunnerExecsV2({ now } = {}) {
794
+ const t = now ?? Date.now();
795
+ const flipped = [];
796
+ for (const e of _resV2.values())
797
+ if (
798
+ e.status === RUNNER_EXEC_LIFECYCLE_V2.RUNNING &&
799
+ e.startedAt != null &&
800
+ t - e.startedAt >= _reStuckMs
801
+ ) {
802
+ e.status = RUNNER_EXEC_LIFECYCLE_V2.FAILED;
803
+ e.updatedAt = t;
804
+ if (!e.settledAt) e.settledAt = t;
805
+ e.metadata.failReason = "auto-fail-stuck";
806
+ flipped.push(e.id);
807
+ }
808
+ return { flipped, count: flipped.length };
809
+ }
567
810
 
568
811
  export function getRunnerGovStatsV2() {
569
- const profilesByStatus = {}; for (const s of Object.values(RUNNER_PROFILE_MATURITY_V2)) profilesByStatus[s] = 0; for (const p of _rpsV2.values()) profilesByStatus[p.status]++;
570
- const execsByStatus = {}; for (const s of Object.values(RUNNER_EXEC_LIFECYCLE_V2)) execsByStatus[s] = 0; for (const e of _resV2.values()) execsByStatus[e.status]++;
571
- return { totalRunnerProfilesV2: _rpsV2.size, totalRunnerExecsV2: _resV2.size, maxActiveRunnerProfilesPerOwner: _rpMaxActivePerOwner, maxPendingRunnerExecsPerProfile: _rpMaxPendingExecsPerProfile, runnerProfileIdleMs: _rpIdleMs, runnerExecStuckMs: _reStuckMs, profilesByStatus, execsByStatus };
812
+ const profilesByStatus = {};
813
+ for (const s of Object.values(RUNNER_PROFILE_MATURITY_V2))
814
+ profilesByStatus[s] = 0;
815
+ for (const p of _rpsV2.values()) profilesByStatus[p.status]++;
816
+ const execsByStatus = {};
817
+ for (const s of Object.values(RUNNER_EXEC_LIFECYCLE_V2)) execsByStatus[s] = 0;
818
+ for (const e of _resV2.values()) execsByStatus[e.status]++;
819
+ return {
820
+ totalRunnerProfilesV2: _rpsV2.size,
821
+ totalRunnerExecsV2: _resV2.size,
822
+ maxActiveRunnerProfilesPerOwner: _rpMaxActivePerOwner,
823
+ maxPendingRunnerExecsPerProfile: _rpMaxPendingExecsPerProfile,
824
+ runnerProfileIdleMs: _rpIdleMs,
825
+ runnerExecStuckMs: _reStuckMs,
826
+ profilesByStatus,
827
+ execsByStatus,
828
+ };
572
829
  }