chainlesschain 0.143.0 → 0.152.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 +364 -27
- package/src/commands/agent-network.js +217 -0
- package/src/commands/agent.js +587 -103
- package/src/commands/audit.js +206 -0
- package/src/commands/automation.js +201 -0
- package/src/commands/bi.js +355 -27
- package/src/commands/bm25.js +111 -27
- package/src/commands/browse.js +403 -29
- package/src/commands/ccron.js +128 -28
- package/src/commands/chat.js +207 -0
- package/src/commands/codegen.js +207 -0
- package/src/commands/collab.js +211 -0
- package/src/commands/compliance.js +824 -34
- package/src/commands/compt.js +127 -29
- package/src/commands/consol.js +8 -2
- package/src/commands/cowork.js +783 -34
- package/src/commands/crosschain.js +182 -28
- package/src/commands/dao.js +182 -28
- package/src/commands/dbevo.js +227 -0
- package/src/commands/dev.js +207 -0
- package/src/commands/did-v2.js +217 -0
- package/src/commands/did.js +221 -0
- package/src/commands/dlp.js +385 -27
- package/src/commands/economy.js +205 -50
- package/src/commands/evolution.js +203 -50
- package/src/commands/evomap.js +387 -27
- package/src/commands/export.js +213 -0
- package/src/commands/federation.js +209 -0
- package/src/commands/fflag.js +74 -22
- package/src/commands/fusion.js +205 -0
- package/src/commands/git.js +177 -37
- package/src/commands/governance.js +209 -0
- package/src/commands/hardening.js +209 -0
- package/src/commands/hmemory.js +204 -50
- package/src/commands/hook.js +209 -0
- package/src/commands/import.js +209 -0
- package/src/commands/incentive.js +209 -0
- package/src/commands/inference.js +170 -34
- package/src/commands/infra.js +203 -0
- package/src/commands/instinct.js +209 -0
- package/src/commands/ipfs.js +207 -0
- package/src/commands/itbudget.js +149 -33
- package/src/commands/kg.js +206 -0
- package/src/commands/llm.js +217 -0
- package/src/commands/lowcode.js +195 -38
- package/src/commands/marketplace.js +206 -0
- package/src/commands/matrix.js +386 -27
- package/src/commands/mcp.js +217 -0
- package/src/commands/mcpscaf.js +145 -33
- package/src/commands/meminj.js +145 -33
- package/src/commands/memory.js +209 -0
- package/src/commands/multimodal.js +203 -0
- package/src/commands/nlprog.js +225 -0
- package/src/commands/nostr.js +387 -27
- package/src/commands/note.js +205 -0
- package/src/commands/ops.js +219 -0
- package/src/commands/orchestrate.js +217 -0
- package/src/commands/orchgov.js +144 -33
- package/src/commands/org.js +209 -0
- package/src/commands/p2p.js +209 -0
- package/src/commands/pdfp.js +109 -27
- package/src/commands/perception.js +209 -0
- package/src/commands/perf.js +169 -32
- package/src/commands/perm.js +144 -33
- package/src/commands/permmem.js +203 -0
- package/src/commands/pipeline.js +207 -52
- package/src/commands/planmode.js +141 -32
- package/src/commands/plugin-ecosystem.js +209 -0
- package/src/commands/pqc.js +213 -0
- package/src/commands/privacy.js +203 -0
- package/src/commands/promcomp.js +111 -27
- package/src/commands/quantization.js +207 -0
- package/src/commands/rcache.js +205 -0
- package/src/commands/recommend.js +410 -34
- package/src/commands/reputation.js +208 -0
- package/src/commands/runtime.js +205 -0
- package/src/commands/sandbox.js +206 -0
- package/src/commands/scim.js +209 -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/session.js +209 -0
- package/src/commands/sganal.js +123 -29
- package/src/commands/siem.js +201 -34
- package/src/commands/skill.js +207 -0
- package/src/commands/sla.js +212 -0
- package/src/commands/slotfill.js +146 -33
- package/src/commands/social.js +358 -32
- package/src/commands/sso.js +209 -0
- package/src/commands/stress.js +206 -0
- package/src/commands/svccont.js +145 -33
- package/src/commands/sync.js +209 -0
- package/src/commands/tech.js +209 -0
- package/src/commands/tenant.js +217 -0
- package/src/commands/terraform.js +206 -0
- package/src/commands/tms.js +171 -33
- package/src/commands/tokens.js +209 -0
- package/src/commands/topiccls.js +146 -33
- package/src/commands/trust.js +217 -0
- package/src/commands/uprof.js +141 -32
- package/src/commands/vcheck.js +122 -28
- package/src/commands/wallet.js +209 -0
- package/src/commands/webfetch.js +141 -32
- package/src/commands/workflow.js +203 -0
- package/src/commands/zkp.js +184 -28
- package/src/index.js +180 -0
- package/src/lib/a2a-protocol.js +319 -51
- package/src/lib/activitypub-bridge.js +622 -50
- package/src/lib/agent-economy.js +304 -51
- package/src/lib/agent-network.js +341 -0
- package/src/lib/aiops.js +346 -0
- package/src/lib/app-builder.js +279 -46
- package/src/lib/audit-logger.js +321 -0
- package/src/lib/automation-engine.js +335 -0
- package/src/lib/autonomous-agent.js +284 -48
- package/src/lib/autonomous-developer.js +332 -0
- package/src/lib/bi-engine.js +616 -49
- package/src/lib/bm25-search.js +301 -49
- package/src/lib/browser-automation.js +630 -49
- package/src/lib/chat-core.js +336 -0
- package/src/lib/claude-code-bridge.js +341 -0
- package/src/lib/code-agent.js +339 -0
- package/src/lib/collaboration-governance.js +334 -0
- package/src/lib/community-governance.js +346 -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-recommendation.js +351 -0
- 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-share.js +338 -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/dbevo.js +351 -0
- package/src/lib/decentral-infra.js +330 -0
- package/src/lib/did-manager.js +341 -0
- package/src/lib/did-v2-manager.js +341 -0
- package/src/lib/dlp-engine.js +626 -49
- package/src/lib/evolution-system.js +278 -47
- package/src/lib/evomap-governance.js +334 -0
- 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/federation-hardening.js +340 -0
- 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/hook-manager.js +341 -0
- package/src/lib/inference-network.js +308 -51
- package/src/lib/instinct-manager.js +346 -0
- package/src/lib/ipfs-storage.js +334 -0
- package/src/lib/iteration-budget.js +302 -50
- package/src/lib/knowledge-exporter.js +341 -0
- package/src/lib/knowledge-graph.js +333 -0
- package/src/lib/knowledge-importer.js +341 -0
- package/src/lib/llm-providers.js +346 -0
- package/src/lib/matrix-bridge.js +620 -47
- package/src/lib/mcp-registry.js +346 -0
- package/src/lib/mcp-scaffold.js +318 -54
- package/src/lib/memory-injection.js +288 -49
- package/src/lib/memory-manager.js +336 -0
- package/src/lib/multimodal.js +330 -0
- package/src/lib/nl-programming.js +341 -0
- package/src/lib/nostr-bridge.js +622 -49
- package/src/lib/note-versioning.js +339 -0
- package/src/lib/orchestrator.js +293 -48
- package/src/lib/org-manager.js +336 -0
- package/src/lib/p2p-manager.js +341 -0
- package/src/lib/pdf-parser.js +298 -49
- package/src/lib/perception.js +346 -0
- package/src/lib/perf-tuning.js +309 -50
- package/src/lib/permanent-memory.js +327 -0
- 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/plugin-ecosystem.js +346 -0
- package/src/lib/pqc-manager.js +346 -0
- package/src/lib/privacy-computing.js +335 -0
- package/src/lib/protocol-fusion.js +338 -0
- package/src/lib/quantization.js +337 -0
- package/src/lib/reputation-optimizer.js +340 -0
- package/src/lib/response-cache.js +333 -0
- package/src/lib/sandbox-v2.js +327 -0
- package/src/lib/scim-manager.js +346 -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-manager.js +334 -0
- 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-loader.js +334 -0
- 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/social-manager.js +330 -0
- package/src/lib/sso-manager.js +340 -0
- package/src/lib/stress-tester.js +342 -0
- package/src/lib/sub-agent-registry.js +302 -53
- package/src/lib/sync-manager.js +336 -0
- package/src/lib/task-model-selector.js +302 -50
- package/src/lib/tech-learning-engine.js +341 -0
- package/src/lib/tenant-saas.js +341 -0
- package/src/lib/terraform-manager.js +333 -0
- package/src/lib/threat-intel.js +330 -0
- package/src/lib/todo-manager.js +281 -47
- package/src/lib/token-incentive.js +341 -0
- package/src/lib/token-tracker.js +336 -0
- package/src/lib/topic-classifier.js +297 -49
- package/src/lib/trust-security.js +343 -0
- package/src/lib/ueba.js +340 -0
- package/src/lib/universal-runtime.js +330 -0
- package/src/lib/user-profile.js +294 -50
- package/src/lib/version-checker.js +304 -50
- package/src/lib/wallet-manager.js +336 -0
- package/src/lib/web-fetch.js +292 -51
- package/src/lib/workflow-engine.js +330 -0
- 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",
|
|
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",
|
|
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
|
-
[
|
|
480
|
-
|
|
481
|
-
|
|
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
|
-
[
|
|
487
|
-
|
|
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) {
|
|
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) {
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
export function
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
export function
|
|
509
|
-
|
|
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();
|
|
513
|
-
|
|
514
|
-
|
|
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({
|
|
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))
|
|
586
|
+
if (_rpsV2.has(id))
|
|
587
|
+
throw new Error(`runner profile ${id} already registered`);
|
|
521
588
|
const now = Date.now();
|
|
522
|
-
const p = {
|
|
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) {
|
|
527
|
-
|
|
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);
|
|
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) {
|
|
534
|
-
|
|
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
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
669
|
+
export function listRunnerProfilesV2() {
|
|
670
|
+
return [..._rpsV2.values()].map((p) => ({
|
|
671
|
+
...p,
|
|
672
|
+
metadata: { ...p.metadata },
|
|
673
|
+
}));
|
|
674
|
+
}
|
|
542
675
|
|
|
543
|
-
function _reCountPending(profileId) {
|
|
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({
|
|
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")
|
|
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))
|
|
698
|
+
if (!_rpsV2.has(profileId))
|
|
699
|
+
throw new Error(`runner profile ${profileId} not found`);
|
|
550
700
|
const pending = _reCountPending(profileId);
|
|
551
|
-
if (pending >= _rpMaxPendingExecsPerProfile)
|
|
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 = {
|
|
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) {
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
export function
|
|
563
|
-
|
|
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 } = {}) {
|
|
566
|
-
|
|
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 = {};
|
|
570
|
-
|
|
571
|
-
|
|
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
|
}
|