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
|
@@ -493,25 +493,53 @@ Reply with a JSON object: { "action": "retry|add_step|skip", "newParams": {...},
|
|
|
493
493
|
}
|
|
494
494
|
}
|
|
495
495
|
|
|
496
|
-
|
|
497
496
|
// ===== V2 Surface: Autonomous Agent governance overlay (CLI v0.138.0) =====
|
|
498
497
|
export const AUTOAGENT_MATURITY_V2 = Object.freeze({
|
|
499
|
-
PENDING: "pending",
|
|
498
|
+
PENDING: "pending",
|
|
499
|
+
ACTIVE: "active",
|
|
500
|
+
PAUSED: "paused",
|
|
501
|
+
ARCHIVED: "archived",
|
|
500
502
|
});
|
|
501
503
|
export const AUTOAGENT_RUN_LIFECYCLE_V2 = Object.freeze({
|
|
502
|
-
QUEUED: "queued",
|
|
504
|
+
QUEUED: "queued",
|
|
505
|
+
RUNNING: "running",
|
|
506
|
+
COMPLETED: "completed",
|
|
507
|
+
FAILED: "failed",
|
|
508
|
+
CANCELLED: "cancelled",
|
|
503
509
|
});
|
|
504
510
|
|
|
505
511
|
const _aaTrans = new Map([
|
|
506
|
-
[
|
|
507
|
-
|
|
508
|
-
|
|
512
|
+
[
|
|
513
|
+
AUTOAGENT_MATURITY_V2.PENDING,
|
|
514
|
+
new Set([AUTOAGENT_MATURITY_V2.ACTIVE, AUTOAGENT_MATURITY_V2.ARCHIVED]),
|
|
515
|
+
],
|
|
516
|
+
[
|
|
517
|
+
AUTOAGENT_MATURITY_V2.ACTIVE,
|
|
518
|
+
new Set([AUTOAGENT_MATURITY_V2.PAUSED, AUTOAGENT_MATURITY_V2.ARCHIVED]),
|
|
519
|
+
],
|
|
520
|
+
[
|
|
521
|
+
AUTOAGENT_MATURITY_V2.PAUSED,
|
|
522
|
+
new Set([AUTOAGENT_MATURITY_V2.ACTIVE, AUTOAGENT_MATURITY_V2.ARCHIVED]),
|
|
523
|
+
],
|
|
509
524
|
[AUTOAGENT_MATURITY_V2.ARCHIVED, new Set()],
|
|
510
525
|
]);
|
|
511
526
|
const _aaTerminal = new Set([AUTOAGENT_MATURITY_V2.ARCHIVED]);
|
|
512
527
|
const _aaRunTrans = new Map([
|
|
513
|
-
[
|
|
514
|
-
|
|
528
|
+
[
|
|
529
|
+
AUTOAGENT_RUN_LIFECYCLE_V2.QUEUED,
|
|
530
|
+
new Set([
|
|
531
|
+
AUTOAGENT_RUN_LIFECYCLE_V2.RUNNING,
|
|
532
|
+
AUTOAGENT_RUN_LIFECYCLE_V2.CANCELLED,
|
|
533
|
+
]),
|
|
534
|
+
],
|
|
535
|
+
[
|
|
536
|
+
AUTOAGENT_RUN_LIFECYCLE_V2.RUNNING,
|
|
537
|
+
new Set([
|
|
538
|
+
AUTOAGENT_RUN_LIFECYCLE_V2.COMPLETED,
|
|
539
|
+
AUTOAGENT_RUN_LIFECYCLE_V2.FAILED,
|
|
540
|
+
AUTOAGENT_RUN_LIFECYCLE_V2.CANCELLED,
|
|
541
|
+
]),
|
|
542
|
+
],
|
|
515
543
|
[AUTOAGENT_RUN_LIFECYCLE_V2.COMPLETED, new Set()],
|
|
516
544
|
[AUTOAGENT_RUN_LIFECYCLE_V2.FAILED, new Set()],
|
|
517
545
|
[AUTOAGENT_RUN_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
@@ -524,21 +552,45 @@ let _aaMaxPendingRunsPerAgent = 10;
|
|
|
524
552
|
let _aaAgentIdleMs = 7 * 24 * 60 * 60 * 1000;
|
|
525
553
|
let _aaRunStuckMs = 30 * 60 * 1000;
|
|
526
554
|
|
|
527
|
-
function _aaPos(n, lbl) {
|
|
555
|
+
function _aaPos(n, lbl) {
|
|
556
|
+
const v = Math.floor(Number(n));
|
|
557
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
558
|
+
throw new Error(`${lbl} must be positive integer`);
|
|
559
|
+
return v;
|
|
560
|
+
}
|
|
528
561
|
|
|
529
|
-
export function setMaxActiveAutoAgentsPerOwnerV2(n) {
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
export function
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
export function
|
|
536
|
-
|
|
562
|
+
export function setMaxActiveAutoAgentsPerOwnerV2(n) {
|
|
563
|
+
_aaMaxActivePerOwner = _aaPos(n, "maxActiveAutoAgentsPerOwner");
|
|
564
|
+
}
|
|
565
|
+
export function getMaxActiveAutoAgentsPerOwnerV2() {
|
|
566
|
+
return _aaMaxActivePerOwner;
|
|
567
|
+
}
|
|
568
|
+
export function setMaxPendingAutoAgentRunsPerAgentV2(n) {
|
|
569
|
+
_aaMaxPendingRunsPerAgent = _aaPos(n, "maxPendingAutoAgentRunsPerAgent");
|
|
570
|
+
}
|
|
571
|
+
export function getMaxPendingAutoAgentRunsPerAgentV2() {
|
|
572
|
+
return _aaMaxPendingRunsPerAgent;
|
|
573
|
+
}
|
|
574
|
+
export function setAutoAgentIdleMsV2(n) {
|
|
575
|
+
_aaAgentIdleMs = _aaPos(n, "autoAgentIdleMs");
|
|
576
|
+
}
|
|
577
|
+
export function getAutoAgentIdleMsV2() {
|
|
578
|
+
return _aaAgentIdleMs;
|
|
579
|
+
}
|
|
580
|
+
export function setAutoAgentRunStuckMsV2(n) {
|
|
581
|
+
_aaRunStuckMs = _aaPos(n, "autoAgentRunStuckMs");
|
|
582
|
+
}
|
|
583
|
+
export function getAutoAgentRunStuckMsV2() {
|
|
584
|
+
return _aaRunStuckMs;
|
|
585
|
+
}
|
|
537
586
|
|
|
538
587
|
export function _resetStateAutonomousAgentV2() {
|
|
539
|
-
_aaAgents.clear();
|
|
540
|
-
|
|
541
|
-
|
|
588
|
+
_aaAgents.clear();
|
|
589
|
+
_aaRuns.clear();
|
|
590
|
+
_aaMaxActivePerOwner = 5;
|
|
591
|
+
_aaMaxPendingRunsPerAgent = 10;
|
|
592
|
+
_aaAgentIdleMs = 7 * 24 * 60 * 60 * 1000;
|
|
593
|
+
_aaRunStuckMs = 30 * 60 * 1000;
|
|
542
594
|
}
|
|
543
595
|
|
|
544
596
|
export function registerAutoAgentV2({ id, owner, goal, metadata } = {}) {
|
|
@@ -546,54 +598,238 @@ export function registerAutoAgentV2({ id, owner, goal, metadata } = {}) {
|
|
|
546
598
|
if (!owner || typeof owner !== "string") throw new Error("owner is required");
|
|
547
599
|
if (_aaAgents.has(id)) throw new Error(`auto-agent ${id} already registered`);
|
|
548
600
|
const now = Date.now();
|
|
549
|
-
const a = {
|
|
601
|
+
const a = {
|
|
602
|
+
id,
|
|
603
|
+
owner,
|
|
604
|
+
goal: goal || "",
|
|
605
|
+
status: AUTOAGENT_MATURITY_V2.PENDING,
|
|
606
|
+
createdAt: now,
|
|
607
|
+
updatedAt: now,
|
|
608
|
+
activatedAt: null,
|
|
609
|
+
archivedAt: null,
|
|
610
|
+
lastTouchedAt: now,
|
|
611
|
+
metadata: { ...(metadata || {}) },
|
|
612
|
+
};
|
|
550
613
|
_aaAgents.set(id, a);
|
|
551
614
|
return { ...a, metadata: { ...a.metadata } };
|
|
552
615
|
}
|
|
553
|
-
function _aaCheckA(from, to) {
|
|
554
|
-
|
|
616
|
+
function _aaCheckA(from, to) {
|
|
617
|
+
const a = _aaTrans.get(from);
|
|
618
|
+
if (!a || !a.has(to))
|
|
619
|
+
throw new Error(`invalid auto-agent transition ${from} → ${to}`);
|
|
620
|
+
}
|
|
621
|
+
function _aaCountActive(owner) {
|
|
622
|
+
let n = 0;
|
|
623
|
+
for (const a of _aaAgents.values())
|
|
624
|
+
if (a.owner === owner && a.status === AUTOAGENT_MATURITY_V2.ACTIVE) n++;
|
|
625
|
+
return n;
|
|
626
|
+
}
|
|
555
627
|
|
|
556
628
|
export function activateAutoAgentV2(id) {
|
|
557
|
-
const a = _aaAgents.get(id);
|
|
629
|
+
const a = _aaAgents.get(id);
|
|
630
|
+
if (!a) throw new Error(`auto-agent ${id} not found`);
|
|
558
631
|
_aaCheckA(a.status, AUTOAGENT_MATURITY_V2.ACTIVE);
|
|
559
632
|
const recovery = a.status === AUTOAGENT_MATURITY_V2.PAUSED;
|
|
560
|
-
if (!recovery) {
|
|
561
|
-
|
|
633
|
+
if (!recovery) {
|
|
634
|
+
const c = _aaCountActive(a.owner);
|
|
635
|
+
if (c >= _aaMaxActivePerOwner)
|
|
636
|
+
throw new Error(
|
|
637
|
+
`max active auto-agents per owner (${_aaMaxActivePerOwner}) reached for ${a.owner}`,
|
|
638
|
+
);
|
|
639
|
+
}
|
|
640
|
+
const now = Date.now();
|
|
641
|
+
a.status = AUTOAGENT_MATURITY_V2.ACTIVE;
|
|
642
|
+
a.updatedAt = now;
|
|
643
|
+
a.lastTouchedAt = now;
|
|
644
|
+
if (!a.activatedAt) a.activatedAt = now;
|
|
645
|
+
return { ...a, metadata: { ...a.metadata } };
|
|
646
|
+
}
|
|
647
|
+
export function pauseAutoAgentV2(id) {
|
|
648
|
+
const a = _aaAgents.get(id);
|
|
649
|
+
if (!a) throw new Error(`auto-agent ${id} not found`);
|
|
650
|
+
_aaCheckA(a.status, AUTOAGENT_MATURITY_V2.PAUSED);
|
|
651
|
+
a.status = AUTOAGENT_MATURITY_V2.PAUSED;
|
|
652
|
+
a.updatedAt = Date.now();
|
|
562
653
|
return { ...a, metadata: { ...a.metadata } };
|
|
563
654
|
}
|
|
564
|
-
export function
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
655
|
+
export function archiveAutoAgentV2(id) {
|
|
656
|
+
const a = _aaAgents.get(id);
|
|
657
|
+
if (!a) throw new Error(`auto-agent ${id} not found`);
|
|
658
|
+
_aaCheckA(a.status, AUTOAGENT_MATURITY_V2.ARCHIVED);
|
|
659
|
+
const now = Date.now();
|
|
660
|
+
a.status = AUTOAGENT_MATURITY_V2.ARCHIVED;
|
|
661
|
+
a.updatedAt = now;
|
|
662
|
+
if (!a.archivedAt) a.archivedAt = now;
|
|
663
|
+
return { ...a, metadata: { ...a.metadata } };
|
|
664
|
+
}
|
|
665
|
+
export function touchAutoAgentV2(id) {
|
|
666
|
+
const a = _aaAgents.get(id);
|
|
667
|
+
if (!a) throw new Error(`auto-agent ${id} not found`);
|
|
668
|
+
if (_aaTerminal.has(a.status))
|
|
669
|
+
throw new Error(`cannot touch terminal auto-agent ${id}`);
|
|
670
|
+
const now = Date.now();
|
|
671
|
+
a.lastTouchedAt = now;
|
|
672
|
+
a.updatedAt = now;
|
|
673
|
+
return { ...a, metadata: { ...a.metadata } };
|
|
674
|
+
}
|
|
675
|
+
export function getAutoAgentV2(id) {
|
|
676
|
+
const a = _aaAgents.get(id);
|
|
677
|
+
if (!a) return null;
|
|
678
|
+
return { ...a, metadata: { ...a.metadata } };
|
|
679
|
+
}
|
|
680
|
+
export function listAutoAgentsV2() {
|
|
681
|
+
return [..._aaAgents.values()].map((a) => ({
|
|
682
|
+
...a,
|
|
683
|
+
metadata: { ...a.metadata },
|
|
684
|
+
}));
|
|
685
|
+
}
|
|
569
686
|
|
|
570
|
-
function _aaCountPendingRuns(aid) {
|
|
687
|
+
function _aaCountPendingRuns(aid) {
|
|
688
|
+
let n = 0;
|
|
689
|
+
for (const r of _aaRuns.values())
|
|
690
|
+
if (
|
|
691
|
+
r.agentId === aid &&
|
|
692
|
+
(r.status === AUTOAGENT_RUN_LIFECYCLE_V2.QUEUED ||
|
|
693
|
+
r.status === AUTOAGENT_RUN_LIFECYCLE_V2.RUNNING)
|
|
694
|
+
)
|
|
695
|
+
n++;
|
|
696
|
+
return n;
|
|
697
|
+
}
|
|
571
698
|
|
|
572
699
|
export function createAutoAgentRunV2({ id, agentId, prompt, metadata } = {}) {
|
|
573
700
|
if (!id || typeof id !== "string") throw new Error("id is required");
|
|
574
|
-
if (!agentId || typeof agentId !== "string")
|
|
701
|
+
if (!agentId || typeof agentId !== "string")
|
|
702
|
+
throw new Error("agentId is required");
|
|
575
703
|
if (_aaRuns.has(id)) throw new Error(`auto-agent run ${id} already exists`);
|
|
576
|
-
if (!_aaAgents.has(agentId))
|
|
704
|
+
if (!_aaAgents.has(agentId))
|
|
705
|
+
throw new Error(`auto-agent ${agentId} not found`);
|
|
577
706
|
const pending = _aaCountPendingRuns(agentId);
|
|
578
|
-
if (pending >= _aaMaxPendingRunsPerAgent)
|
|
707
|
+
if (pending >= _aaMaxPendingRunsPerAgent)
|
|
708
|
+
throw new Error(
|
|
709
|
+
`max pending auto-agent runs per agent (${_aaMaxPendingRunsPerAgent}) reached for ${agentId}`,
|
|
710
|
+
);
|
|
579
711
|
const now = Date.now();
|
|
580
|
-
const r = {
|
|
712
|
+
const r = {
|
|
713
|
+
id,
|
|
714
|
+
agentId,
|
|
715
|
+
prompt: prompt || "",
|
|
716
|
+
status: AUTOAGENT_RUN_LIFECYCLE_V2.QUEUED,
|
|
717
|
+
createdAt: now,
|
|
718
|
+
updatedAt: now,
|
|
719
|
+
startedAt: null,
|
|
720
|
+
settledAt: null,
|
|
721
|
+
metadata: { ...(metadata || {}) },
|
|
722
|
+
};
|
|
581
723
|
_aaRuns.set(id, r);
|
|
582
724
|
return { ...r, metadata: { ...r.metadata } };
|
|
583
725
|
}
|
|
584
|
-
function _aaCheckR(from, to) {
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
export function
|
|
590
|
-
|
|
726
|
+
function _aaCheckR(from, to) {
|
|
727
|
+
const a = _aaRunTrans.get(from);
|
|
728
|
+
if (!a || !a.has(to))
|
|
729
|
+
throw new Error(`invalid auto-agent run transition ${from} → ${to}`);
|
|
730
|
+
}
|
|
731
|
+
export function startAutoAgentRunV2(id) {
|
|
732
|
+
const r = _aaRuns.get(id);
|
|
733
|
+
if (!r) throw new Error(`auto-agent run ${id} not found`);
|
|
734
|
+
_aaCheckR(r.status, AUTOAGENT_RUN_LIFECYCLE_V2.RUNNING);
|
|
735
|
+
const now = Date.now();
|
|
736
|
+
r.status = AUTOAGENT_RUN_LIFECYCLE_V2.RUNNING;
|
|
737
|
+
r.updatedAt = now;
|
|
738
|
+
if (!r.startedAt) r.startedAt = now;
|
|
739
|
+
return { ...r, metadata: { ...r.metadata } };
|
|
740
|
+
}
|
|
741
|
+
export function completeAutoAgentRunV2(id) {
|
|
742
|
+
const r = _aaRuns.get(id);
|
|
743
|
+
if (!r) throw new Error(`auto-agent run ${id} not found`);
|
|
744
|
+
_aaCheckR(r.status, AUTOAGENT_RUN_LIFECYCLE_V2.COMPLETED);
|
|
745
|
+
const now = Date.now();
|
|
746
|
+
r.status = AUTOAGENT_RUN_LIFECYCLE_V2.COMPLETED;
|
|
747
|
+
r.updatedAt = now;
|
|
748
|
+
if (!r.settledAt) r.settledAt = now;
|
|
749
|
+
return { ...r, metadata: { ...r.metadata } };
|
|
750
|
+
}
|
|
751
|
+
export function failAutoAgentRunV2(id, reason) {
|
|
752
|
+
const r = _aaRuns.get(id);
|
|
753
|
+
if (!r) throw new Error(`auto-agent run ${id} not found`);
|
|
754
|
+
_aaCheckR(r.status, AUTOAGENT_RUN_LIFECYCLE_V2.FAILED);
|
|
755
|
+
const now = Date.now();
|
|
756
|
+
r.status = AUTOAGENT_RUN_LIFECYCLE_V2.FAILED;
|
|
757
|
+
r.updatedAt = now;
|
|
758
|
+
if (!r.settledAt) r.settledAt = now;
|
|
759
|
+
if (reason) r.metadata.failReason = String(reason);
|
|
760
|
+
return { ...r, metadata: { ...r.metadata } };
|
|
761
|
+
}
|
|
762
|
+
export function cancelAutoAgentRunV2(id, reason) {
|
|
763
|
+
const r = _aaRuns.get(id);
|
|
764
|
+
if (!r) throw new Error(`auto-agent run ${id} not found`);
|
|
765
|
+
_aaCheckR(r.status, AUTOAGENT_RUN_LIFECYCLE_V2.CANCELLED);
|
|
766
|
+
const now = Date.now();
|
|
767
|
+
r.status = AUTOAGENT_RUN_LIFECYCLE_V2.CANCELLED;
|
|
768
|
+
r.updatedAt = now;
|
|
769
|
+
if (!r.settledAt) r.settledAt = now;
|
|
770
|
+
if (reason) r.metadata.cancelReason = String(reason);
|
|
771
|
+
return { ...r, metadata: { ...r.metadata } };
|
|
772
|
+
}
|
|
773
|
+
export function getAutoAgentRunV2(id) {
|
|
774
|
+
const r = _aaRuns.get(id);
|
|
775
|
+
if (!r) return null;
|
|
776
|
+
return { ...r, metadata: { ...r.metadata } };
|
|
777
|
+
}
|
|
778
|
+
export function listAutoAgentRunsV2() {
|
|
779
|
+
return [..._aaRuns.values()].map((r) => ({
|
|
780
|
+
...r,
|
|
781
|
+
metadata: { ...r.metadata },
|
|
782
|
+
}));
|
|
783
|
+
}
|
|
591
784
|
|
|
592
|
-
export function autoPauseIdleAutoAgentsV2({ now } = {}) {
|
|
593
|
-
|
|
785
|
+
export function autoPauseIdleAutoAgentsV2({ now } = {}) {
|
|
786
|
+
const t = now ?? Date.now();
|
|
787
|
+
const flipped = [];
|
|
788
|
+
for (const a of _aaAgents.values())
|
|
789
|
+
if (
|
|
790
|
+
a.status === AUTOAGENT_MATURITY_V2.ACTIVE &&
|
|
791
|
+
t - a.lastTouchedAt >= _aaAgentIdleMs
|
|
792
|
+
) {
|
|
793
|
+
a.status = AUTOAGENT_MATURITY_V2.PAUSED;
|
|
794
|
+
a.updatedAt = t;
|
|
795
|
+
flipped.push(a.id);
|
|
796
|
+
}
|
|
797
|
+
return { flipped, count: flipped.length };
|
|
798
|
+
}
|
|
799
|
+
export function autoFailStuckAutoAgentRunsV2({ now } = {}) {
|
|
800
|
+
const t = now ?? Date.now();
|
|
801
|
+
const flipped = [];
|
|
802
|
+
for (const r of _aaRuns.values())
|
|
803
|
+
if (
|
|
804
|
+
r.status === AUTOAGENT_RUN_LIFECYCLE_V2.RUNNING &&
|
|
805
|
+
r.startedAt != null &&
|
|
806
|
+
t - r.startedAt >= _aaRunStuckMs
|
|
807
|
+
) {
|
|
808
|
+
r.status = AUTOAGENT_RUN_LIFECYCLE_V2.FAILED;
|
|
809
|
+
r.updatedAt = t;
|
|
810
|
+
if (!r.settledAt) r.settledAt = t;
|
|
811
|
+
r.metadata.failReason = "auto-fail-stuck";
|
|
812
|
+
flipped.push(r.id);
|
|
813
|
+
}
|
|
814
|
+
return { flipped, count: flipped.length };
|
|
815
|
+
}
|
|
594
816
|
|
|
595
817
|
export function getAutonomousAgentGovStatsV2() {
|
|
596
|
-
const agentsByStatus = {};
|
|
597
|
-
|
|
598
|
-
|
|
818
|
+
const agentsByStatus = {};
|
|
819
|
+
for (const s of Object.values(AUTOAGENT_MATURITY_V2)) agentsByStatus[s] = 0;
|
|
820
|
+
for (const a of _aaAgents.values()) agentsByStatus[a.status]++;
|
|
821
|
+
const runsByStatus = {};
|
|
822
|
+
for (const s of Object.values(AUTOAGENT_RUN_LIFECYCLE_V2))
|
|
823
|
+
runsByStatus[s] = 0;
|
|
824
|
+
for (const r of _aaRuns.values()) runsByStatus[r.status]++;
|
|
825
|
+
return {
|
|
826
|
+
totalAutoAgentsV2: _aaAgents.size,
|
|
827
|
+
totalAutoAgentRunsV2: _aaRuns.size,
|
|
828
|
+
maxActiveAutoAgentsPerOwner: _aaMaxActivePerOwner,
|
|
829
|
+
maxPendingAutoAgentRunsPerAgent: _aaMaxPendingRunsPerAgent,
|
|
830
|
+
autoAgentIdleMs: _aaAgentIdleMs,
|
|
831
|
+
autoAgentRunStuckMs: _aaRunStuckMs,
|
|
832
|
+
agentsByStatus,
|
|
833
|
+
runsByStatus,
|
|
834
|
+
};
|
|
599
835
|
}
|