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
@@ -473,83 +473,332 @@ function _secondKey(date) {
473
473
  return `${_minuteKey(date)}-${date.getSeconds()}`;
474
474
  }
475
475
 
476
-
477
476
  // =====================================================================
478
477
  // Cowork Cron V2 governance overlay
479
478
  // =====================================================================
480
- export const CCRON_PROFILE_MATURITY_V2 = Object.freeze({ PENDING: "pending", ACTIVE: "active", PAUSED: "paused", ARCHIVED: "archived" });
481
- export const CCRON_TICK_LIFECYCLE_V2 = Object.freeze({ QUEUED: "queued", RUNNING: "running", COMPLETED: "completed", FAILED: "failed", CANCELLED: "cancelled" });
479
+ export const CCRON_PROFILE_MATURITY_V2 = Object.freeze({
480
+ PENDING: "pending",
481
+ ACTIVE: "active",
482
+ PAUSED: "paused",
483
+ ARCHIVED: "archived",
484
+ });
485
+ export const CCRON_TICK_LIFECYCLE_V2 = Object.freeze({
486
+ QUEUED: "queued",
487
+ RUNNING: "running",
488
+ COMPLETED: "completed",
489
+ FAILED: "failed",
490
+ CANCELLED: "cancelled",
491
+ });
482
492
  const _ccronPTrans = new Map([
483
- [CCRON_PROFILE_MATURITY_V2.PENDING, new Set([CCRON_PROFILE_MATURITY_V2.ACTIVE, CCRON_PROFILE_MATURITY_V2.ARCHIVED])],
484
- [CCRON_PROFILE_MATURITY_V2.ACTIVE, new Set([CCRON_PROFILE_MATURITY_V2.PAUSED, CCRON_PROFILE_MATURITY_V2.ARCHIVED])],
485
- [CCRON_PROFILE_MATURITY_V2.PAUSED, new Set([CCRON_PROFILE_MATURITY_V2.ACTIVE, CCRON_PROFILE_MATURITY_V2.ARCHIVED])],
493
+ [
494
+ CCRON_PROFILE_MATURITY_V2.PENDING,
495
+ new Set([
496
+ CCRON_PROFILE_MATURITY_V2.ACTIVE,
497
+ CCRON_PROFILE_MATURITY_V2.ARCHIVED,
498
+ ]),
499
+ ],
500
+ [
501
+ CCRON_PROFILE_MATURITY_V2.ACTIVE,
502
+ new Set([
503
+ CCRON_PROFILE_MATURITY_V2.PAUSED,
504
+ CCRON_PROFILE_MATURITY_V2.ARCHIVED,
505
+ ]),
506
+ ],
507
+ [
508
+ CCRON_PROFILE_MATURITY_V2.PAUSED,
509
+ new Set([
510
+ CCRON_PROFILE_MATURITY_V2.ACTIVE,
511
+ CCRON_PROFILE_MATURITY_V2.ARCHIVED,
512
+ ]),
513
+ ],
486
514
  [CCRON_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
487
515
  ]);
488
516
  const _ccronPTerminal = new Set([CCRON_PROFILE_MATURITY_V2.ARCHIVED]);
489
517
  const _ccronTTrans = new Map([
490
- [CCRON_TICK_LIFECYCLE_V2.QUEUED, new Set([CCRON_TICK_LIFECYCLE_V2.RUNNING, CCRON_TICK_LIFECYCLE_V2.CANCELLED])],
491
- [CCRON_TICK_LIFECYCLE_V2.RUNNING, new Set([CCRON_TICK_LIFECYCLE_V2.COMPLETED, CCRON_TICK_LIFECYCLE_V2.FAILED, CCRON_TICK_LIFECYCLE_V2.CANCELLED])],
518
+ [
519
+ CCRON_TICK_LIFECYCLE_V2.QUEUED,
520
+ new Set([
521
+ CCRON_TICK_LIFECYCLE_V2.RUNNING,
522
+ CCRON_TICK_LIFECYCLE_V2.CANCELLED,
523
+ ]),
524
+ ],
525
+ [
526
+ CCRON_TICK_LIFECYCLE_V2.RUNNING,
527
+ new Set([
528
+ CCRON_TICK_LIFECYCLE_V2.COMPLETED,
529
+ CCRON_TICK_LIFECYCLE_V2.FAILED,
530
+ CCRON_TICK_LIFECYCLE_V2.CANCELLED,
531
+ ]),
532
+ ],
492
533
  [CCRON_TICK_LIFECYCLE_V2.COMPLETED, new Set()],
493
534
  [CCRON_TICK_LIFECYCLE_V2.FAILED, new Set()],
494
535
  [CCRON_TICK_LIFECYCLE_V2.CANCELLED, new Set()],
495
536
  ]);
496
537
  const _ccronPsV2 = new Map();
497
538
  const _ccronTsV2 = new Map();
498
- let _ccronMaxActive = 6, _ccronMaxPending = 15, _ccronIdleMs = 30 * 24 * 60 * 60 * 1000, _ccronStuckMs = 60 * 1000;
499
- function _ccronPos(n, label) { const v = Math.floor(Number(n)); if (!Number.isFinite(v) || v <= 0) throw new Error(`${label} must be positive integer`); return v; }
500
- function _ccronCheckP(from, to) { const a = _ccronPTrans.get(from); if (!a || !a.has(to)) throw new Error(`invalid ccron profile transition ${from} → ${to}`); }
501
- function _ccronCheckT(from, to) { const a = _ccronTTrans.get(from); if (!a || !a.has(to)) throw new Error(`invalid ccron tick transition ${from} → ${to}`); }
502
- function _ccronCountActive(owner) { let c = 0; for (const p of _ccronPsV2.values()) if (p.owner === owner && p.status === CCRON_PROFILE_MATURITY_V2.ACTIVE) c++; return c; }
503
- function _ccronCountPending(profileId) { let c = 0; for (const t of _ccronTsV2.values()) if (t.profileId === profileId && (t.status === CCRON_TICK_LIFECYCLE_V2.QUEUED || t.status === CCRON_TICK_LIFECYCLE_V2.RUNNING)) c++; return c; }
504
- export function setMaxActiveCcronProfilesPerOwnerV2(n) { _ccronMaxActive = _ccronPos(n, "maxActiveCcronProfilesPerOwner"); }
505
- export function getMaxActiveCcronProfilesPerOwnerV2() { return _ccronMaxActive; }
506
- export function setMaxPendingCcronTicksPerProfileV2(n) { _ccronMaxPending = _ccronPos(n, "maxPendingCcronTicksPerProfile"); }
507
- export function getMaxPendingCcronTicksPerProfileV2() { return _ccronMaxPending; }
508
- export function setCcronProfileIdleMsV2(n) { _ccronIdleMs = _ccronPos(n, "ccronProfileIdleMs"); }
509
- export function getCcronProfileIdleMsV2() { return _ccronIdleMs; }
510
- export function setCcronTickStuckMsV2(n) { _ccronStuckMs = _ccronPos(n, "ccronTickStuckMs"); }
511
- export function getCcronTickStuckMsV2() { return _ccronStuckMs; }
512
- export function _resetStateCoworkCronV2() { _ccronPsV2.clear(); _ccronTsV2.clear(); _ccronMaxActive = 6; _ccronMaxPending = 15; _ccronIdleMs = 30 * 24 * 60 * 60 * 1000; _ccronStuckMs = 60 * 1000; }
539
+ let _ccronMaxActive = 6,
540
+ _ccronMaxPending = 15,
541
+ _ccronIdleMs = 30 * 24 * 60 * 60 * 1000,
542
+ _ccronStuckMs = 60 * 1000;
543
+ function _ccronPos(n, label) {
544
+ const v = Math.floor(Number(n));
545
+ if (!Number.isFinite(v) || v <= 0)
546
+ throw new Error(`${label} must be positive integer`);
547
+ return v;
548
+ }
549
+ function _ccronCheckP(from, to) {
550
+ const a = _ccronPTrans.get(from);
551
+ if (!a || !a.has(to))
552
+ throw new Error(`invalid ccron profile transition ${from} ${to}`);
553
+ }
554
+ function _ccronCheckT(from, to) {
555
+ const a = _ccronTTrans.get(from);
556
+ if (!a || !a.has(to))
557
+ throw new Error(`invalid ccron tick transition ${from} → ${to}`);
558
+ }
559
+ function _ccronCountActive(owner) {
560
+ let c = 0;
561
+ for (const p of _ccronPsV2.values())
562
+ if (p.owner === owner && p.status === CCRON_PROFILE_MATURITY_V2.ACTIVE) c++;
563
+ return c;
564
+ }
565
+ function _ccronCountPending(profileId) {
566
+ let c = 0;
567
+ for (const t of _ccronTsV2.values())
568
+ if (
569
+ t.profileId === profileId &&
570
+ (t.status === CCRON_TICK_LIFECYCLE_V2.QUEUED ||
571
+ t.status === CCRON_TICK_LIFECYCLE_V2.RUNNING)
572
+ )
573
+ c++;
574
+ return c;
575
+ }
576
+ export function setMaxActiveCcronProfilesPerOwnerV2(n) {
577
+ _ccronMaxActive = _ccronPos(n, "maxActiveCcronProfilesPerOwner");
578
+ }
579
+ export function getMaxActiveCcronProfilesPerOwnerV2() {
580
+ return _ccronMaxActive;
581
+ }
582
+ export function setMaxPendingCcronTicksPerProfileV2(n) {
583
+ _ccronMaxPending = _ccronPos(n, "maxPendingCcronTicksPerProfile");
584
+ }
585
+ export function getMaxPendingCcronTicksPerProfileV2() {
586
+ return _ccronMaxPending;
587
+ }
588
+ export function setCcronProfileIdleMsV2(n) {
589
+ _ccronIdleMs = _ccronPos(n, "ccronProfileIdleMs");
590
+ }
591
+ export function getCcronProfileIdleMsV2() {
592
+ return _ccronIdleMs;
593
+ }
594
+ export function setCcronTickStuckMsV2(n) {
595
+ _ccronStuckMs = _ccronPos(n, "ccronTickStuckMs");
596
+ }
597
+ export function getCcronTickStuckMsV2() {
598
+ return _ccronStuckMs;
599
+ }
600
+ export function _resetStateCoworkCronV2() {
601
+ _ccronPsV2.clear();
602
+ _ccronTsV2.clear();
603
+ _ccronMaxActive = 6;
604
+ _ccronMaxPending = 15;
605
+ _ccronIdleMs = 30 * 24 * 60 * 60 * 1000;
606
+ _ccronStuckMs = 60 * 1000;
607
+ }
513
608
  export function registerCcronProfileV2({ id, owner, expr, metadata } = {}) {
514
609
  if (!id || !owner) throw new Error("id and owner required");
515
610
  if (_ccronPsV2.has(id)) throw new Error(`ccron profile ${id} already exists`);
516
611
  const now = Date.now();
517
- const p = { id, owner, expr: expr || "0 0 * * *", status: CCRON_PROFILE_MATURITY_V2.PENDING, createdAt: now, updatedAt: now, lastTouchedAt: now, activatedAt: null, archivedAt: null, metadata: { ...(metadata || {}) } };
518
- _ccronPsV2.set(id, p); return { ...p, metadata: { ...p.metadata } };
612
+ const p = {
613
+ id,
614
+ owner,
615
+ expr: expr || "0 0 * * *",
616
+ status: CCRON_PROFILE_MATURITY_V2.PENDING,
617
+ createdAt: now,
618
+ updatedAt: now,
619
+ lastTouchedAt: now,
620
+ activatedAt: null,
621
+ archivedAt: null,
622
+ metadata: { ...(metadata || {}) },
623
+ };
624
+ _ccronPsV2.set(id, p);
625
+ return { ...p, metadata: { ...p.metadata } };
519
626
  }
520
627
  export function activateCcronProfileV2(id) {
521
- const p = _ccronPsV2.get(id); if (!p) throw new Error(`ccron profile ${id} not found`);
628
+ const p = _ccronPsV2.get(id);
629
+ if (!p) throw new Error(`ccron profile ${id} not found`);
522
630
  const isInitial = p.status === CCRON_PROFILE_MATURITY_V2.PENDING;
523
631
  _ccronCheckP(p.status, CCRON_PROFILE_MATURITY_V2.ACTIVE);
524
- if (isInitial && _ccronCountActive(p.owner) >= _ccronMaxActive) throw new Error(`max active ccron profiles for owner ${p.owner} reached`);
525
- const now = Date.now(); p.status = CCRON_PROFILE_MATURITY_V2.ACTIVE; p.updatedAt = now; p.lastTouchedAt = now;
632
+ if (isInitial && _ccronCountActive(p.owner) >= _ccronMaxActive)
633
+ throw new Error(`max active ccron profiles for owner ${p.owner} reached`);
634
+ const now = Date.now();
635
+ p.status = CCRON_PROFILE_MATURITY_V2.ACTIVE;
636
+ p.updatedAt = now;
637
+ p.lastTouchedAt = now;
526
638
  if (!p.activatedAt) p.activatedAt = now;
527
639
  return { ...p, metadata: { ...p.metadata } };
528
640
  }
529
- export function pauseCcronProfileV2(id) { const p = _ccronPsV2.get(id); if (!p) throw new Error(`ccron profile ${id} not found`); _ccronCheckP(p.status, CCRON_PROFILE_MATURITY_V2.PAUSED); p.status = CCRON_PROFILE_MATURITY_V2.PAUSED; p.updatedAt = Date.now(); return { ...p, metadata: { ...p.metadata } }; }
530
- export function archiveCcronProfileV2(id) { const p = _ccronPsV2.get(id); if (!p) throw new Error(`ccron profile ${id} not found`); _ccronCheckP(p.status, CCRON_PROFILE_MATURITY_V2.ARCHIVED); const now = Date.now(); p.status = CCRON_PROFILE_MATURITY_V2.ARCHIVED; p.updatedAt = now; if (!p.archivedAt) p.archivedAt = now; return { ...p, metadata: { ...p.metadata } }; }
531
- export function touchCcronProfileV2(id) { const p = _ccronPsV2.get(id); if (!p) throw new Error(`ccron profile ${id} not found`); if (_ccronPTerminal.has(p.status)) throw new Error(`cannot touch terminal ccron profile ${id}`); const now = Date.now(); p.lastTouchedAt = now; p.updatedAt = now; return { ...p, metadata: { ...p.metadata } }; }
532
- export function getCcronProfileV2(id) { const p = _ccronPsV2.get(id); if (!p) return null; return { ...p, metadata: { ...p.metadata } }; }
533
- export function listCcronProfilesV2() { return [..._ccronPsV2.values()].map((p) => ({ ...p, metadata: { ...p.metadata } })); }
641
+ export function pauseCcronProfileV2(id) {
642
+ const p = _ccronPsV2.get(id);
643
+ if (!p) throw new Error(`ccron profile ${id} not found`);
644
+ _ccronCheckP(p.status, CCRON_PROFILE_MATURITY_V2.PAUSED);
645
+ p.status = CCRON_PROFILE_MATURITY_V2.PAUSED;
646
+ p.updatedAt = Date.now();
647
+ return { ...p, metadata: { ...p.metadata } };
648
+ }
649
+ export function archiveCcronProfileV2(id) {
650
+ const p = _ccronPsV2.get(id);
651
+ if (!p) throw new Error(`ccron profile ${id} not found`);
652
+ _ccronCheckP(p.status, CCRON_PROFILE_MATURITY_V2.ARCHIVED);
653
+ const now = Date.now();
654
+ p.status = CCRON_PROFILE_MATURITY_V2.ARCHIVED;
655
+ p.updatedAt = now;
656
+ if (!p.archivedAt) p.archivedAt = now;
657
+ return { ...p, metadata: { ...p.metadata } };
658
+ }
659
+ export function touchCcronProfileV2(id) {
660
+ const p = _ccronPsV2.get(id);
661
+ if (!p) throw new Error(`ccron profile ${id} not found`);
662
+ if (_ccronPTerminal.has(p.status))
663
+ throw new Error(`cannot touch terminal ccron profile ${id}`);
664
+ const now = Date.now();
665
+ p.lastTouchedAt = now;
666
+ p.updatedAt = now;
667
+ return { ...p, metadata: { ...p.metadata } };
668
+ }
669
+ export function getCcronProfileV2(id) {
670
+ const p = _ccronPsV2.get(id);
671
+ if (!p) return null;
672
+ return { ...p, metadata: { ...p.metadata } };
673
+ }
674
+ export function listCcronProfilesV2() {
675
+ return [..._ccronPsV2.values()].map((p) => ({
676
+ ...p,
677
+ metadata: { ...p.metadata },
678
+ }));
679
+ }
534
680
  export function createCcronTickV2({ id, profileId, tickAt, metadata } = {}) {
535
681
  if (!id || !profileId) throw new Error("id and profileId required");
536
682
  if (_ccronTsV2.has(id)) throw new Error(`ccron tick ${id} already exists`);
537
- if (!_ccronPsV2.has(profileId)) throw new Error(`ccron profile ${profileId} not found`);
538
- if (_ccronCountPending(profileId) >= _ccronMaxPending) throw new Error(`max pending ccron ticks for profile ${profileId} reached`);
683
+ if (!_ccronPsV2.has(profileId))
684
+ throw new Error(`ccron profile ${profileId} not found`);
685
+ if (_ccronCountPending(profileId) >= _ccronMaxPending)
686
+ throw new Error(`max pending ccron ticks for profile ${profileId} reached`);
687
+ const now = Date.now();
688
+ const t = {
689
+ id,
690
+ profileId,
691
+ tickAt: tickAt || now,
692
+ status: CCRON_TICK_LIFECYCLE_V2.QUEUED,
693
+ createdAt: now,
694
+ updatedAt: now,
695
+ startedAt: null,
696
+ settledAt: null,
697
+ metadata: { ...(metadata || {}) },
698
+ };
699
+ _ccronTsV2.set(id, t);
700
+ return { ...t, metadata: { ...t.metadata } };
701
+ }
702
+ export function runningCcronTickV2(id) {
703
+ const t = _ccronTsV2.get(id);
704
+ if (!t) throw new Error(`ccron tick ${id} not found`);
705
+ _ccronCheckT(t.status, CCRON_TICK_LIFECYCLE_V2.RUNNING);
706
+ const now = Date.now();
707
+ t.status = CCRON_TICK_LIFECYCLE_V2.RUNNING;
708
+ t.updatedAt = now;
709
+ if (!t.startedAt) t.startedAt = now;
710
+ return { ...t, metadata: { ...t.metadata } };
711
+ }
712
+ export function completeCcronTickV2(id) {
713
+ const t = _ccronTsV2.get(id);
714
+ if (!t) throw new Error(`ccron tick ${id} not found`);
715
+ _ccronCheckT(t.status, CCRON_TICK_LIFECYCLE_V2.COMPLETED);
539
716
  const now = Date.now();
540
- const t = { id, profileId, tickAt: tickAt || now, status: CCRON_TICK_LIFECYCLE_V2.QUEUED, createdAt: now, updatedAt: now, startedAt: null, settledAt: null, metadata: { ...(metadata || {}) } };
541
- _ccronTsV2.set(id, t); return { ...t, metadata: { ...t.metadata } };
542
- }
543
- export function runningCcronTickV2(id) { const t = _ccronTsV2.get(id); if (!t) throw new Error(`ccron tick ${id} not found`); _ccronCheckT(t.status, CCRON_TICK_LIFECYCLE_V2.RUNNING); const now = Date.now(); t.status = CCRON_TICK_LIFECYCLE_V2.RUNNING; t.updatedAt = now; if (!t.startedAt) t.startedAt = now; return { ...t, metadata: { ...t.metadata } }; }
544
- export function completeCcronTickV2(id) { const t = _ccronTsV2.get(id); if (!t) throw new Error(`ccron tick ${id} not found`); _ccronCheckT(t.status, CCRON_TICK_LIFECYCLE_V2.COMPLETED); const now = Date.now(); t.status = CCRON_TICK_LIFECYCLE_V2.COMPLETED; t.updatedAt = now; if (!t.settledAt) t.settledAt = now; return { ...t, metadata: { ...t.metadata } }; }
545
- export function failCcronTickV2(id, reason) { const t = _ccronTsV2.get(id); if (!t) throw new Error(`ccron tick ${id} not found`); _ccronCheckT(t.status, CCRON_TICK_LIFECYCLE_V2.FAILED); const now = Date.now(); t.status = CCRON_TICK_LIFECYCLE_V2.FAILED; t.updatedAt = now; if (!t.settledAt) t.settledAt = now; if (reason) t.metadata.failReason = String(reason); return { ...t, metadata: { ...t.metadata } }; }
546
- export function cancelCcronTickV2(id, reason) { const t = _ccronTsV2.get(id); if (!t) throw new Error(`ccron tick ${id} not found`); _ccronCheckT(t.status, CCRON_TICK_LIFECYCLE_V2.CANCELLED); const now = Date.now(); t.status = CCRON_TICK_LIFECYCLE_V2.CANCELLED; t.updatedAt = now; if (!t.settledAt) t.settledAt = now; if (reason) t.metadata.cancelReason = String(reason); return { ...t, metadata: { ...t.metadata } }; }
547
- export function getCcronTickV2(id) { const t = _ccronTsV2.get(id); if (!t) return null; return { ...t, metadata: { ...t.metadata } }; }
548
- export function listCcronTicksV2() { return [..._ccronTsV2.values()].map((t) => ({ ...t, metadata: { ...t.metadata } })); }
549
- export function autoPauseIdleCcronProfilesV2({ now } = {}) { const t = now ?? Date.now(); const flipped = []; for (const p of _ccronPsV2.values()) if (p.status === CCRON_PROFILE_MATURITY_V2.ACTIVE && (t - p.lastTouchedAt) >= _ccronIdleMs) { p.status = CCRON_PROFILE_MATURITY_V2.PAUSED; p.updatedAt = t; flipped.push(p.id); } return { flipped, count: flipped.length }; }
550
- export function autoFailStuckCcronTicksV2({ now } = {}) { const t = now ?? Date.now(); const flipped = []; for (const x of _ccronTsV2.values()) if (x.status === CCRON_TICK_LIFECYCLE_V2.RUNNING && x.startedAt != null && (t - x.startedAt) >= _ccronStuckMs) { x.status = CCRON_TICK_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 }; }
717
+ t.status = CCRON_TICK_LIFECYCLE_V2.COMPLETED;
718
+ t.updatedAt = now;
719
+ if (!t.settledAt) t.settledAt = now;
720
+ return { ...t, metadata: { ...t.metadata } };
721
+ }
722
+ export function failCcronTickV2(id, reason) {
723
+ const t = _ccronTsV2.get(id);
724
+ if (!t) throw new Error(`ccron tick ${id} not found`);
725
+ _ccronCheckT(t.status, CCRON_TICK_LIFECYCLE_V2.FAILED);
726
+ const now = Date.now();
727
+ t.status = CCRON_TICK_LIFECYCLE_V2.FAILED;
728
+ t.updatedAt = now;
729
+ if (!t.settledAt) t.settledAt = now;
730
+ if (reason) t.metadata.failReason = String(reason);
731
+ return { ...t, metadata: { ...t.metadata } };
732
+ }
733
+ export function cancelCcronTickV2(id, reason) {
734
+ const t = _ccronTsV2.get(id);
735
+ if (!t) throw new Error(`ccron tick ${id} not found`);
736
+ _ccronCheckT(t.status, CCRON_TICK_LIFECYCLE_V2.CANCELLED);
737
+ const now = Date.now();
738
+ t.status = CCRON_TICK_LIFECYCLE_V2.CANCELLED;
739
+ t.updatedAt = now;
740
+ if (!t.settledAt) t.settledAt = now;
741
+ if (reason) t.metadata.cancelReason = String(reason);
742
+ return { ...t, metadata: { ...t.metadata } };
743
+ }
744
+ export function getCcronTickV2(id) {
745
+ const t = _ccronTsV2.get(id);
746
+ if (!t) return null;
747
+ return { ...t, metadata: { ...t.metadata } };
748
+ }
749
+ export function listCcronTicksV2() {
750
+ return [..._ccronTsV2.values()].map((t) => ({
751
+ ...t,
752
+ metadata: { ...t.metadata },
753
+ }));
754
+ }
755
+ export function autoPauseIdleCcronProfilesV2({ now } = {}) {
756
+ const t = now ?? Date.now();
757
+ const flipped = [];
758
+ for (const p of _ccronPsV2.values())
759
+ if (
760
+ p.status === CCRON_PROFILE_MATURITY_V2.ACTIVE &&
761
+ t - p.lastTouchedAt >= _ccronIdleMs
762
+ ) {
763
+ p.status = CCRON_PROFILE_MATURITY_V2.PAUSED;
764
+ p.updatedAt = t;
765
+ flipped.push(p.id);
766
+ }
767
+ return { flipped, count: flipped.length };
768
+ }
769
+ export function autoFailStuckCcronTicksV2({ now } = {}) {
770
+ const t = now ?? Date.now();
771
+ const flipped = [];
772
+ for (const x of _ccronTsV2.values())
773
+ if (
774
+ x.status === CCRON_TICK_LIFECYCLE_V2.RUNNING &&
775
+ x.startedAt != null &&
776
+ t - x.startedAt >= _ccronStuckMs
777
+ ) {
778
+ x.status = CCRON_TICK_LIFECYCLE_V2.FAILED;
779
+ x.updatedAt = t;
780
+ if (!x.settledAt) x.settledAt = t;
781
+ x.metadata.failReason = "auto-fail-stuck";
782
+ flipped.push(x.id);
783
+ }
784
+ return { flipped, count: flipped.length };
785
+ }
551
786
  export function getCoworkCronGovStatsV2() {
552
- const profilesByStatus = {}; for (const v of Object.values(CCRON_PROFILE_MATURITY_V2)) profilesByStatus[v] = 0; for (const p of _ccronPsV2.values()) profilesByStatus[p.status]++;
553
- const ticksByStatus = {}; for (const v of Object.values(CCRON_TICK_LIFECYCLE_V2)) ticksByStatus[v] = 0; for (const t of _ccronTsV2.values()) ticksByStatus[t.status]++;
554
- return { totalCcronProfilesV2: _ccronPsV2.size, totalCcronTicksV2: _ccronTsV2.size, maxActiveCcronProfilesPerOwner: _ccronMaxActive, maxPendingCcronTicksPerProfile: _ccronMaxPending, ccronProfileIdleMs: _ccronIdleMs, ccronTickStuckMs: _ccronStuckMs, profilesByStatus, ticksByStatus };
787
+ const profilesByStatus = {};
788
+ for (const v of Object.values(CCRON_PROFILE_MATURITY_V2))
789
+ profilesByStatus[v] = 0;
790
+ for (const p of _ccronPsV2.values()) profilesByStatus[p.status]++;
791
+ const ticksByStatus = {};
792
+ for (const v of Object.values(CCRON_TICK_LIFECYCLE_V2)) ticksByStatus[v] = 0;
793
+ for (const t of _ccronTsV2.values()) ticksByStatus[t.status]++;
794
+ return {
795
+ totalCcronProfilesV2: _ccronPsV2.size,
796
+ totalCcronTicksV2: _ccronTsV2.size,
797
+ maxActiveCcronProfilesPerOwner: _ccronMaxActive,
798
+ maxPendingCcronTicksPerProfile: _ccronMaxPending,
799
+ ccronProfileIdleMs: _ccronIdleMs,
800
+ ccronTickStuckMs: _ccronStuckMs,
801
+ profilesByStatus,
802
+ ticksByStatus,
803
+ };
555
804
  }