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.
- package/package.json +1 -1
- package/src/commands/a2a.js +196 -28
- package/src/commands/activitypub.js +157 -27
- package/src/commands/agent.js +587 -103
- package/src/commands/audit.js +206 -0
- package/src/commands/bi.js +152 -27
- package/src/commands/bm25.js +111 -27
- package/src/commands/browse.js +190 -29
- package/src/commands/ccron.js +128 -28
- package/src/commands/chat.js +207 -0
- package/src/commands/compliance.js +414 -34
- package/src/commands/compt.js +127 -29
- package/src/commands/consol.js +8 -2
- package/src/commands/cowork.js +580 -34
- package/src/commands/crosschain.js +182 -28
- package/src/commands/dao.js +182 -28
- package/src/commands/dlp.js +172 -27
- package/src/commands/economy.js +205 -50
- package/src/commands/evolution.js +203 -50
- package/src/commands/evomap.js +182 -27
- package/src/commands/fflag.js +74 -22
- package/src/commands/git.js +177 -37
- package/src/commands/hardening.js +209 -0
- package/src/commands/hmemory.js +204 -50
- package/src/commands/incentive.js +209 -0
- package/src/commands/inference.js +170 -34
- package/src/commands/itbudget.js +149 -33
- package/src/commands/kg.js +206 -0
- package/src/commands/lowcode.js +195 -38
- package/src/commands/marketplace.js +206 -0
- package/src/commands/matrix.js +179 -27
- package/src/commands/mcpscaf.js +145 -33
- package/src/commands/meminj.js +145 -33
- package/src/commands/nostr.js +178 -27
- package/src/commands/orchestrate.js +217 -0
- package/src/commands/orchgov.js +144 -33
- package/src/commands/pdfp.js +109 -27
- package/src/commands/perf.js +169 -32
- package/src/commands/perm.js +144 -33
- package/src/commands/pipeline.js +207 -52
- package/src/commands/planmode.js +141 -32
- package/src/commands/privacy.js +203 -0
- package/src/commands/promcomp.js +111 -27
- package/src/commands/recommend.js +177 -34
- package/src/commands/reputation.js +208 -0
- package/src/commands/sandbox.js +206 -0
- package/src/commands/seshhook.js +145 -33
- package/src/commands/seshsearch.js +141 -33
- package/src/commands/seshtail.js +144 -33
- package/src/commands/seshu.js +152 -33
- package/src/commands/sganal.js +123 -29
- package/src/commands/siem.js +201 -34
- package/src/commands/sla.js +212 -0
- package/src/commands/slotfill.js +146 -33
- package/src/commands/social.js +157 -32
- package/src/commands/stress.js +206 -0
- package/src/commands/svccont.js +145 -33
- package/src/commands/terraform.js +206 -0
- package/src/commands/tms.js +171 -33
- package/src/commands/topiccls.js +146 -33
- package/src/commands/uprof.js +141 -32
- package/src/commands/vcheck.js +122 -28
- package/src/commands/webfetch.js +141 -32
- package/src/commands/zkp.js +184 -28
- package/src/index.js +40 -0
- package/src/lib/a2a-protocol.js +319 -51
- package/src/lib/activitypub-bridge.js +288 -50
- package/src/lib/agent-economy.js +304 -51
- package/src/lib/app-builder.js +279 -46
- package/src/lib/audit-logger.js +321 -0
- package/src/lib/autonomous-agent.js +284 -48
- package/src/lib/bi-engine.js +283 -49
- package/src/lib/bm25-search.js +301 -49
- package/src/lib/browser-automation.js +296 -49
- package/src/lib/chat-core.js +336 -0
- package/src/lib/claude-code-bridge.js +341 -0
- package/src/lib/compliance-framework-reporter.js +305 -51
- package/src/lib/compliance-manager.js +330 -0
- package/src/lib/compression-telemetry.js +301 -49
- package/src/lib/content-recommender.js +317 -52
- package/src/lib/cowork-cron.js +298 -49
- package/src/lib/cowork-learning.js +333 -0
- package/src/lib/cowork-task-runner.js +308 -51
- package/src/lib/cowork-workflow.js +327 -0
- package/src/lib/cross-chain.js +311 -51
- package/src/lib/dao-governance.js +280 -46
- package/src/lib/dlp-engine.js +287 -49
- package/src/lib/evolution-system.js +278 -47
- package/src/lib/evomap-manager.js +280 -46
- package/src/lib/execution-backend.js +294 -48
- package/src/lib/feature-flags.js +294 -49
- package/src/lib/git-integration.js +285 -47
- package/src/lib/hardening-manager.js +341 -0
- package/src/lib/hierarchical-memory.js +284 -48
- package/src/lib/inference-network.js +308 -51
- package/src/lib/iteration-budget.js +302 -50
- package/src/lib/knowledge-graph.js +333 -0
- package/src/lib/matrix-bridge.js +281 -47
- package/src/lib/mcp-scaffold.js +318 -54
- package/src/lib/memory-injection.js +288 -49
- package/src/lib/nostr-bridge.js +286 -49
- package/src/lib/orchestrator.js +293 -48
- package/src/lib/pdf-parser.js +298 -49
- package/src/lib/perf-tuning.js +309 -50
- package/src/lib/permission-engine.js +287 -49
- package/src/lib/pipeline-orchestrator.js +289 -49
- package/src/lib/plan-mode.js +298 -51
- package/src/lib/privacy-computing.js +335 -0
- package/src/lib/reputation-optimizer.js +340 -0
- package/src/lib/sandbox-v2.js +327 -0
- package/src/lib/service-container.js +313 -52
- package/src/lib/session-consolidator.js +296 -49
- package/src/lib/session-hooks.js +312 -53
- package/src/lib/session-search.js +304 -51
- package/src/lib/session-tail.js +288 -49
- package/src/lib/session-usage.js +298 -52
- package/src/lib/siem-exporter.js +298 -51
- package/src/lib/skill-marketplace.js +345 -0
- package/src/lib/sla-manager.js +341 -0
- package/src/lib/slot-filler.js +303 -51
- package/src/lib/social-graph-analytics.js +295 -49
- package/src/lib/social-graph.js +272 -49
- package/src/lib/stress-tester.js +342 -0
- package/src/lib/sub-agent-registry.js +302 -53
- package/src/lib/task-model-selector.js +302 -50
- package/src/lib/terraform-manager.js +333 -0
- package/src/lib/todo-manager.js +281 -47
- package/src/lib/token-incentive.js +341 -0
- package/src/lib/topic-classifier.js +297 -49
- package/src/lib/user-profile.js +294 -50
- package/src/lib/version-checker.js +304 -50
- package/src/lib/web-fetch.js +292 -51
- package/src/lib/zkp-engine.js +286 -49
package/src/lib/cowork-cron.js
CHANGED
|
@@ -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({
|
|
481
|
-
|
|
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
|
-
[
|
|
484
|
-
|
|
485
|
-
|
|
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
|
-
[
|
|
491
|
-
|
|
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,
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
function
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
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 = {
|
|
518
|
-
|
|
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);
|
|
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)
|
|
525
|
-
|
|
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) {
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
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))
|
|
538
|
-
|
|
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
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
export function failCcronTickV2(id, reason) {
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
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 = {};
|
|
553
|
-
|
|
554
|
-
|
|
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
|
}
|