chainlesschain 0.145.0 → 0.156.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/README.md +52 -3
- package/package.json +1 -1
- package/src/commands/a2a.js +201 -0
- package/src/commands/activitypub.js +207 -0
- package/src/commands/agent-network.js +217 -0
- package/src/commands/agent.js +1250 -0
- package/src/commands/automation.js +201 -0
- package/src/commands/bi.js +203 -0
- package/src/commands/browse.js +213 -0
- package/src/commands/chat.js +605 -0
- package/src/commands/cli-anything.js +426 -0
- package/src/commands/codegen.js +207 -0
- package/src/commands/collab.js +211 -0
- package/src/commands/compliance.js +822 -0
- package/src/commands/config.js +213 -0
- package/src/commands/cowork.js +1666 -0
- package/src/commands/crosschain.js +203 -0
- package/src/commands/dao.js +203 -0
- 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 +213 -0
- package/src/commands/economy.js +199 -0
- package/src/commands/encrypt.js +201 -0
- package/src/commands/evolution.js +199 -0
- package/src/commands/evomap.js +830 -0
- package/src/commands/export.js +213 -0
- package/src/commands/federation.js +209 -0
- package/src/commands/fusion.js +205 -0
- package/src/commands/governance.js +209 -0
- package/src/commands/hmemory.js +203 -0
- package/src/commands/hook.js +209 -0
- package/src/commands/import.js +209 -0
- package/src/commands/inference.js +207 -0
- package/src/commands/infra.js +203 -0
- package/src/commands/instinct.js +209 -0
- package/src/commands/ipfs.js +207 -0
- package/src/commands/kg.js +195 -0
- package/src/commands/llm.js +426 -0
- package/src/commands/matrix.js +207 -0
- package/src/commands/mcp.js +217 -0
- package/src/commands/memory.js +412 -0
- package/src/commands/multimodal.js +203 -0
- package/src/commands/nlprog.js +225 -0
- package/src/commands/nostr.js +209 -0
- package/src/commands/note.js +205 -0
- package/src/commands/ops.js +219 -0
- package/src/commands/orchestrate.js +406 -0
- package/src/commands/org.js +209 -0
- package/src/commands/p2p.js +209 -0
- package/src/commands/perception.js +209 -0
- package/src/commands/permmem.js +203 -0
- package/src/commands/pipeline.js +199 -0
- package/src/commands/planmode.js +426 -0
- package/src/commands/plugin-ecosystem.js +209 -0
- package/src/commands/plugin.js +209 -0
- package/src/commands/pqc.js +213 -0
- package/src/commands/quantization.js +207 -0
- package/src/commands/rcache.js +205 -0
- package/src/commands/recommend.js +233 -0
- package/src/commands/runtime.js +205 -0
- package/src/commands/scim.js +209 -0
- package/src/commands/services.js +207 -0
- package/src/commands/session.js +209 -0
- package/src/commands/setup.js +205 -0
- package/src/commands/skill.js +414 -0
- package/src/commands/social.js +201 -0
- package/src/commands/sso.js +209 -0
- package/src/commands/start.js +209 -0
- package/src/commands/stream.js +213 -0
- package/src/commands/sync.js +209 -0
- package/src/commands/tech.js +209 -0
- package/src/commands/tenant.js +217 -0
- package/src/commands/tokens.js +209 -0
- package/src/commands/trust.js +217 -0
- package/src/commands/ui.js +225 -0
- package/src/commands/wallet.js +209 -0
- package/src/commands/workflow.js +412 -0
- package/src/index.js +252 -0
- package/src/lib/a2a-protocol.js +332 -0
- package/src/lib/activitypub-bridge.js +334 -0
- package/src/lib/agent-coordinator.js +334 -0
- package/src/lib/agent-economy.js +334 -0
- package/src/lib/agent-network.js +341 -0
- package/src/lib/agent-router.js +333 -0
- package/src/lib/aiops.js +346 -0
- package/src/lib/automation-engine.js +335 -0
- package/src/lib/autonomous-agent.js +332 -0
- package/src/lib/autonomous-developer.js +332 -0
- package/src/lib/bi-engine.js +333 -0
- package/src/lib/browser-automation.js +334 -0
- package/src/lib/chat-core.js +335 -0
- package/src/lib/cli-anything-bridge.js +341 -0
- package/src/lib/cli-context-engineering.js +351 -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-manager.js +334 -0
- package/src/lib/content-recommendation.js +351 -0
- package/src/lib/cowork-adapter.js +336 -0
- package/src/lib/cowork-evomap-adapter.js +341 -0
- package/src/lib/cowork-mcp-tools.js +341 -0
- package/src/lib/cowork-observe-html.js +341 -0
- package/src/lib/cowork-observe.js +341 -0
- package/src/lib/cowork-share.js +338 -0
- package/src/lib/cowork-task-templates.js +342 -1
- package/src/lib/cowork-template-marketplace.js +340 -0
- package/src/lib/cross-chain.js +339 -0
- package/src/lib/crypto-manager.js +334 -0
- package/src/lib/dao-governance.js +339 -0
- 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 +339 -0
- package/src/lib/downloader.js +334 -0
- package/src/lib/evolution-system.js +334 -0
- package/src/lib/evomap-client.js +342 -0
- package/src/lib/evomap-federation.js +338 -0
- package/src/lib/evomap-governance.js +334 -0
- package/src/lib/evomap-manager.js +330 -0
- package/src/lib/execution-backend.js +330 -0
- package/src/lib/federation-hardening.js +340 -0
- package/src/lib/hashline.js +338 -0
- package/src/lib/hierarchical-memory.js +334 -0
- package/src/lib/hook-manager.js +341 -0
- package/src/lib/inference-network.js +341 -0
- package/src/lib/instinct-manager.js +346 -0
- package/src/lib/interaction-adapter.js +330 -0
- package/src/lib/interactive-planner.js +354 -0
- package/src/lib/ipfs-storage.js +334 -0
- package/src/lib/knowledge-exporter.js +341 -0
- package/src/lib/knowledge-graph.js +331 -0
- package/src/lib/knowledge-importer.js +341 -0
- package/src/lib/llm-providers.js +346 -0
- package/src/lib/matrix-bridge.js +339 -0
- package/src/lib/mcp-registry.js +346 -0
- 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 +336 -0
- package/src/lib/note-versioning.js +339 -0
- package/src/lib/org-manager.js +336 -0
- package/src/lib/p2p-manager.js +341 -0
- package/src/lib/perception.js +346 -0
- package/src/lib/permanent-memory.js +327 -0
- package/src/lib/pipeline-orchestrator.js +332 -0
- package/src/lib/plan-mode.js +336 -0
- package/src/lib/plugin-autodiscovery.js +334 -0
- package/src/lib/plugin-ecosystem.js +346 -0
- package/src/lib/pqc-manager.js +346 -0
- package/src/lib/process-manager.js +336 -0
- package/src/lib/protocol-fusion.js +338 -0
- package/src/lib/provider-options.js +346 -0
- package/src/lib/provider-stream.js +348 -0
- package/src/lib/quantization.js +337 -0
- package/src/lib/response-cache.js +333 -0
- package/src/lib/scim-manager.js +346 -0
- package/src/lib/service-manager.js +337 -0
- package/src/lib/session-core-singletons.js +341 -0
- package/src/lib/session-manager.js +334 -0
- package/src/lib/skill-loader.js +334 -0
- package/src/lib/skill-mcp.js +336 -0
- package/src/lib/social-manager.js +330 -0
- package/src/lib/sso-manager.js +340 -0
- package/src/lib/stix-parser.js +346 -0
- package/src/lib/sub-agent-context.js +343 -0
- package/src/lib/sub-agent-profiles.js +335 -0
- package/src/lib/sub-agent-registry.js +336 -0
- package/src/lib/sync-manager.js +336 -0
- package/src/lib/tech-learning-engine.js +341 -0
- package/src/lib/tenant-saas.js +341 -0
- package/src/lib/threat-intel.js +330 -0
- package/src/lib/todo-manager.js +336 -0
- package/src/lib/token-tracker.js +336 -0
- 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/wallet-manager.js +336 -0
- package/src/lib/web-ui-server.js +348 -0
- package/src/lib/workflow-engine.js +330 -0
- package/src/lib/workflow-expr.js +346 -0
- package/src/lib/ws-chat-handler.js +337 -0
|
@@ -468,3 +468,346 @@ export class SubAgentContext {
|
|
|
468
468
|
};
|
|
469
469
|
}
|
|
470
470
|
}
|
|
471
|
+
|
|
472
|
+
// =====================================================================
|
|
473
|
+
// sub-agent-context V2 governance overlay (iter26)
|
|
474
|
+
// =====================================================================
|
|
475
|
+
export const SACTXGOV_PROFILE_MATURITY_V2 = Object.freeze({
|
|
476
|
+
PENDING: "pending",
|
|
477
|
+
ACTIVE: "active",
|
|
478
|
+
STALE: "stale",
|
|
479
|
+
ARCHIVED: "archived",
|
|
480
|
+
});
|
|
481
|
+
export const SACTXGOV_HANDOFF_LIFECYCLE_V2 = Object.freeze({
|
|
482
|
+
QUEUED: "queued",
|
|
483
|
+
TRANSFERRING: "transferring",
|
|
484
|
+
TRANSFERRED: "transferred",
|
|
485
|
+
FAILED: "failed",
|
|
486
|
+
CANCELLED: "cancelled",
|
|
487
|
+
});
|
|
488
|
+
const _sactxgovPTrans = new Map([
|
|
489
|
+
[
|
|
490
|
+
SACTXGOV_PROFILE_MATURITY_V2.PENDING,
|
|
491
|
+
new Set([
|
|
492
|
+
SACTXGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
493
|
+
SACTXGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
494
|
+
]),
|
|
495
|
+
],
|
|
496
|
+
[
|
|
497
|
+
SACTXGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
498
|
+
new Set([
|
|
499
|
+
SACTXGOV_PROFILE_MATURITY_V2.STALE,
|
|
500
|
+
SACTXGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
501
|
+
]),
|
|
502
|
+
],
|
|
503
|
+
[
|
|
504
|
+
SACTXGOV_PROFILE_MATURITY_V2.STALE,
|
|
505
|
+
new Set([
|
|
506
|
+
SACTXGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
507
|
+
SACTXGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
508
|
+
]),
|
|
509
|
+
],
|
|
510
|
+
[SACTXGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
|
|
511
|
+
]);
|
|
512
|
+
const _sactxgovPTerminal = new Set([SACTXGOV_PROFILE_MATURITY_V2.ARCHIVED]);
|
|
513
|
+
const _sactxgovJTrans = new Map([
|
|
514
|
+
[
|
|
515
|
+
SACTXGOV_HANDOFF_LIFECYCLE_V2.QUEUED,
|
|
516
|
+
new Set([
|
|
517
|
+
SACTXGOV_HANDOFF_LIFECYCLE_V2.TRANSFERRING,
|
|
518
|
+
SACTXGOV_HANDOFF_LIFECYCLE_V2.CANCELLED,
|
|
519
|
+
]),
|
|
520
|
+
],
|
|
521
|
+
[
|
|
522
|
+
SACTXGOV_HANDOFF_LIFECYCLE_V2.TRANSFERRING,
|
|
523
|
+
new Set([
|
|
524
|
+
SACTXGOV_HANDOFF_LIFECYCLE_V2.TRANSFERRED,
|
|
525
|
+
SACTXGOV_HANDOFF_LIFECYCLE_V2.FAILED,
|
|
526
|
+
SACTXGOV_HANDOFF_LIFECYCLE_V2.CANCELLED,
|
|
527
|
+
]),
|
|
528
|
+
],
|
|
529
|
+
[SACTXGOV_HANDOFF_LIFECYCLE_V2.TRANSFERRED, new Set()],
|
|
530
|
+
[SACTXGOV_HANDOFF_LIFECYCLE_V2.FAILED, new Set()],
|
|
531
|
+
[SACTXGOV_HANDOFF_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
532
|
+
]);
|
|
533
|
+
const _sactxgovPsV2 = new Map();
|
|
534
|
+
const _sactxgovJsV2 = new Map();
|
|
535
|
+
let _sactxgovMaxActive = 8,
|
|
536
|
+
_sactxgovMaxPending = 20,
|
|
537
|
+
_sactxgovIdleMs = 30 * 24 * 60 * 60 * 1000,
|
|
538
|
+
_sactxgovStuckMs = 60 * 1000;
|
|
539
|
+
function _sactxgovPos(n, label) {
|
|
540
|
+
const v = Math.floor(Number(n));
|
|
541
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
542
|
+
throw new Error(`${label} must be positive integer`);
|
|
543
|
+
return v;
|
|
544
|
+
}
|
|
545
|
+
function _sactxgovCheckP(from, to) {
|
|
546
|
+
const a = _sactxgovPTrans.get(from);
|
|
547
|
+
if (!a || !a.has(to))
|
|
548
|
+
throw new Error(`invalid sactxgov profile transition ${from} → ${to}`);
|
|
549
|
+
}
|
|
550
|
+
function _sactxgovCheckJ(from, to) {
|
|
551
|
+
const a = _sactxgovJTrans.get(from);
|
|
552
|
+
if (!a || !a.has(to))
|
|
553
|
+
throw new Error(`invalid sactxgov handoff transition ${from} → ${to}`);
|
|
554
|
+
}
|
|
555
|
+
function _sactxgovCountActive(owner) {
|
|
556
|
+
let c = 0;
|
|
557
|
+
for (const p of _sactxgovPsV2.values())
|
|
558
|
+
if (p.owner === owner && p.status === SACTXGOV_PROFILE_MATURITY_V2.ACTIVE)
|
|
559
|
+
c++;
|
|
560
|
+
return c;
|
|
561
|
+
}
|
|
562
|
+
function _sactxgovCountPending(profileId) {
|
|
563
|
+
let c = 0;
|
|
564
|
+
for (const j of _sactxgovJsV2.values())
|
|
565
|
+
if (
|
|
566
|
+
j.profileId === profileId &&
|
|
567
|
+
(j.status === SACTXGOV_HANDOFF_LIFECYCLE_V2.QUEUED ||
|
|
568
|
+
j.status === SACTXGOV_HANDOFF_LIFECYCLE_V2.TRANSFERRING)
|
|
569
|
+
)
|
|
570
|
+
c++;
|
|
571
|
+
return c;
|
|
572
|
+
}
|
|
573
|
+
export function setMaxActiveSactxgovProfilesPerOwnerV2(n) {
|
|
574
|
+
_sactxgovMaxActive = _sactxgovPos(n, "maxActiveSactxgovProfilesPerOwner");
|
|
575
|
+
}
|
|
576
|
+
export function getMaxActiveSactxgovProfilesPerOwnerV2() {
|
|
577
|
+
return _sactxgovMaxActive;
|
|
578
|
+
}
|
|
579
|
+
export function setMaxPendingSactxgovHandoffsPerProfileV2(n) {
|
|
580
|
+
_sactxgovMaxPending = _sactxgovPos(n, "maxPendingSactxgovHandoffsPerProfile");
|
|
581
|
+
}
|
|
582
|
+
export function getMaxPendingSactxgovHandoffsPerProfileV2() {
|
|
583
|
+
return _sactxgovMaxPending;
|
|
584
|
+
}
|
|
585
|
+
export function setSactxgovProfileIdleMsV2(n) {
|
|
586
|
+
_sactxgovIdleMs = _sactxgovPos(n, "sactxgovProfileIdleMs");
|
|
587
|
+
}
|
|
588
|
+
export function getSactxgovProfileIdleMsV2() {
|
|
589
|
+
return _sactxgovIdleMs;
|
|
590
|
+
}
|
|
591
|
+
export function setSactxgovHandoffStuckMsV2(n) {
|
|
592
|
+
_sactxgovStuckMs = _sactxgovPos(n, "sactxgovHandoffStuckMs");
|
|
593
|
+
}
|
|
594
|
+
export function getSactxgovHandoffStuckMsV2() {
|
|
595
|
+
return _sactxgovStuckMs;
|
|
596
|
+
}
|
|
597
|
+
export function _resetStateSubAgentContextGovV2() {
|
|
598
|
+
_sactxgovPsV2.clear();
|
|
599
|
+
_sactxgovJsV2.clear();
|
|
600
|
+
_sactxgovMaxActive = 8;
|
|
601
|
+
_sactxgovMaxPending = 20;
|
|
602
|
+
_sactxgovIdleMs = 30 * 24 * 60 * 60 * 1000;
|
|
603
|
+
_sactxgovStuckMs = 60 * 1000;
|
|
604
|
+
}
|
|
605
|
+
export function registerSactxgovProfileV2({ id, owner, scope, metadata } = {}) {
|
|
606
|
+
if (!id || !owner) throw new Error("id and owner required");
|
|
607
|
+
if (_sactxgovPsV2.has(id))
|
|
608
|
+
throw new Error(`sactxgov profile ${id} already exists`);
|
|
609
|
+
const now = Date.now();
|
|
610
|
+
const p = {
|
|
611
|
+
id,
|
|
612
|
+
owner,
|
|
613
|
+
scope: scope || "task",
|
|
614
|
+
status: SACTXGOV_PROFILE_MATURITY_V2.PENDING,
|
|
615
|
+
createdAt: now,
|
|
616
|
+
updatedAt: now,
|
|
617
|
+
lastTouchedAt: now,
|
|
618
|
+
activatedAt: null,
|
|
619
|
+
archivedAt: null,
|
|
620
|
+
metadata: { ...(metadata || {}) },
|
|
621
|
+
};
|
|
622
|
+
_sactxgovPsV2.set(id, p);
|
|
623
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
624
|
+
}
|
|
625
|
+
export function activateSactxgovProfileV2(id) {
|
|
626
|
+
const p = _sactxgovPsV2.get(id);
|
|
627
|
+
if (!p) throw new Error(`sactxgov profile ${id} not found`);
|
|
628
|
+
const isInitial = p.status === SACTXGOV_PROFILE_MATURITY_V2.PENDING;
|
|
629
|
+
_sactxgovCheckP(p.status, SACTXGOV_PROFILE_MATURITY_V2.ACTIVE);
|
|
630
|
+
if (isInitial && _sactxgovCountActive(p.owner) >= _sactxgovMaxActive)
|
|
631
|
+
throw new Error(
|
|
632
|
+
`max active sactxgov profiles for owner ${p.owner} reached`,
|
|
633
|
+
);
|
|
634
|
+
const now = Date.now();
|
|
635
|
+
p.status = SACTXGOV_PROFILE_MATURITY_V2.ACTIVE;
|
|
636
|
+
p.updatedAt = now;
|
|
637
|
+
p.lastTouchedAt = now;
|
|
638
|
+
if (!p.activatedAt) p.activatedAt = now;
|
|
639
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
640
|
+
}
|
|
641
|
+
export function staleSactxgovProfileV2(id) {
|
|
642
|
+
const p = _sactxgovPsV2.get(id);
|
|
643
|
+
if (!p) throw new Error(`sactxgov profile ${id} not found`);
|
|
644
|
+
_sactxgovCheckP(p.status, SACTXGOV_PROFILE_MATURITY_V2.STALE);
|
|
645
|
+
p.status = SACTXGOV_PROFILE_MATURITY_V2.STALE;
|
|
646
|
+
p.updatedAt = Date.now();
|
|
647
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
648
|
+
}
|
|
649
|
+
export function archiveSactxgovProfileV2(id) {
|
|
650
|
+
const p = _sactxgovPsV2.get(id);
|
|
651
|
+
if (!p) throw new Error(`sactxgov profile ${id} not found`);
|
|
652
|
+
_sactxgovCheckP(p.status, SACTXGOV_PROFILE_MATURITY_V2.ARCHIVED);
|
|
653
|
+
const now = Date.now();
|
|
654
|
+
p.status = SACTXGOV_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 touchSactxgovProfileV2(id) {
|
|
660
|
+
const p = _sactxgovPsV2.get(id);
|
|
661
|
+
if (!p) throw new Error(`sactxgov profile ${id} not found`);
|
|
662
|
+
if (_sactxgovPTerminal.has(p.status))
|
|
663
|
+
throw new Error(`cannot touch terminal sactxgov 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 getSactxgovProfileV2(id) {
|
|
670
|
+
const p = _sactxgovPsV2.get(id);
|
|
671
|
+
if (!p) return null;
|
|
672
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
673
|
+
}
|
|
674
|
+
export function listSactxgovProfilesV2() {
|
|
675
|
+
return [..._sactxgovPsV2.values()].map((p) => ({
|
|
676
|
+
...p,
|
|
677
|
+
metadata: { ...p.metadata },
|
|
678
|
+
}));
|
|
679
|
+
}
|
|
680
|
+
export function createSactxgovHandoffV2({
|
|
681
|
+
id,
|
|
682
|
+
profileId,
|
|
683
|
+
subAgent,
|
|
684
|
+
metadata,
|
|
685
|
+
} = {}) {
|
|
686
|
+
if (!id || !profileId) throw new Error("id and profileId required");
|
|
687
|
+
if (_sactxgovJsV2.has(id))
|
|
688
|
+
throw new Error(`sactxgov handoff ${id} already exists`);
|
|
689
|
+
if (!_sactxgovPsV2.has(profileId))
|
|
690
|
+
throw new Error(`sactxgov profile ${profileId} not found`);
|
|
691
|
+
if (_sactxgovCountPending(profileId) >= _sactxgovMaxPending)
|
|
692
|
+
throw new Error(
|
|
693
|
+
`max pending sactxgov handoffs for profile ${profileId} reached`,
|
|
694
|
+
);
|
|
695
|
+
const now = Date.now();
|
|
696
|
+
const j = {
|
|
697
|
+
id,
|
|
698
|
+
profileId,
|
|
699
|
+
subAgent: subAgent || "",
|
|
700
|
+
status: SACTXGOV_HANDOFF_LIFECYCLE_V2.QUEUED,
|
|
701
|
+
createdAt: now,
|
|
702
|
+
updatedAt: now,
|
|
703
|
+
startedAt: null,
|
|
704
|
+
settledAt: null,
|
|
705
|
+
metadata: { ...(metadata || {}) },
|
|
706
|
+
};
|
|
707
|
+
_sactxgovJsV2.set(id, j);
|
|
708
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
709
|
+
}
|
|
710
|
+
export function transferringSactxgovHandoffV2(id) {
|
|
711
|
+
const j = _sactxgovJsV2.get(id);
|
|
712
|
+
if (!j) throw new Error(`sactxgov handoff ${id} not found`);
|
|
713
|
+
_sactxgovCheckJ(j.status, SACTXGOV_HANDOFF_LIFECYCLE_V2.TRANSFERRING);
|
|
714
|
+
const now = Date.now();
|
|
715
|
+
j.status = SACTXGOV_HANDOFF_LIFECYCLE_V2.TRANSFERRING;
|
|
716
|
+
j.updatedAt = now;
|
|
717
|
+
if (!j.startedAt) j.startedAt = now;
|
|
718
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
719
|
+
}
|
|
720
|
+
export function completeHandoffSactxgovV2(id) {
|
|
721
|
+
const j = _sactxgovJsV2.get(id);
|
|
722
|
+
if (!j) throw new Error(`sactxgov handoff ${id} not found`);
|
|
723
|
+
_sactxgovCheckJ(j.status, SACTXGOV_HANDOFF_LIFECYCLE_V2.TRANSFERRED);
|
|
724
|
+
const now = Date.now();
|
|
725
|
+
j.status = SACTXGOV_HANDOFF_LIFECYCLE_V2.TRANSFERRED;
|
|
726
|
+
j.updatedAt = now;
|
|
727
|
+
if (!j.settledAt) j.settledAt = now;
|
|
728
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
729
|
+
}
|
|
730
|
+
export function failSactxgovHandoffV2(id, reason) {
|
|
731
|
+
const j = _sactxgovJsV2.get(id);
|
|
732
|
+
if (!j) throw new Error(`sactxgov handoff ${id} not found`);
|
|
733
|
+
_sactxgovCheckJ(j.status, SACTXGOV_HANDOFF_LIFECYCLE_V2.FAILED);
|
|
734
|
+
const now = Date.now();
|
|
735
|
+
j.status = SACTXGOV_HANDOFF_LIFECYCLE_V2.FAILED;
|
|
736
|
+
j.updatedAt = now;
|
|
737
|
+
if (!j.settledAt) j.settledAt = now;
|
|
738
|
+
if (reason) j.metadata.failReason = String(reason);
|
|
739
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
740
|
+
}
|
|
741
|
+
export function cancelSactxgovHandoffV2(id, reason) {
|
|
742
|
+
const j = _sactxgovJsV2.get(id);
|
|
743
|
+
if (!j) throw new Error(`sactxgov handoff ${id} not found`);
|
|
744
|
+
_sactxgovCheckJ(j.status, SACTXGOV_HANDOFF_LIFECYCLE_V2.CANCELLED);
|
|
745
|
+
const now = Date.now();
|
|
746
|
+
j.status = SACTXGOV_HANDOFF_LIFECYCLE_V2.CANCELLED;
|
|
747
|
+
j.updatedAt = now;
|
|
748
|
+
if (!j.settledAt) j.settledAt = now;
|
|
749
|
+
if (reason) j.metadata.cancelReason = String(reason);
|
|
750
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
751
|
+
}
|
|
752
|
+
export function getSactxgovHandoffV2(id) {
|
|
753
|
+
const j = _sactxgovJsV2.get(id);
|
|
754
|
+
if (!j) return null;
|
|
755
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
756
|
+
}
|
|
757
|
+
export function listSactxgovHandoffsV2() {
|
|
758
|
+
return [..._sactxgovJsV2.values()].map((j) => ({
|
|
759
|
+
...j,
|
|
760
|
+
metadata: { ...j.metadata },
|
|
761
|
+
}));
|
|
762
|
+
}
|
|
763
|
+
export function autoStaleIdleSactxgovProfilesV2({ now } = {}) {
|
|
764
|
+
const t = now ?? Date.now();
|
|
765
|
+
const flipped = [];
|
|
766
|
+
for (const p of _sactxgovPsV2.values())
|
|
767
|
+
if (
|
|
768
|
+
p.status === SACTXGOV_PROFILE_MATURITY_V2.ACTIVE &&
|
|
769
|
+
t - p.lastTouchedAt >= _sactxgovIdleMs
|
|
770
|
+
) {
|
|
771
|
+
p.status = SACTXGOV_PROFILE_MATURITY_V2.STALE;
|
|
772
|
+
p.updatedAt = t;
|
|
773
|
+
flipped.push(p.id);
|
|
774
|
+
}
|
|
775
|
+
return { flipped, count: flipped.length };
|
|
776
|
+
}
|
|
777
|
+
export function autoFailStuckSactxgovHandoffsV2({ now } = {}) {
|
|
778
|
+
const t = now ?? Date.now();
|
|
779
|
+
const flipped = [];
|
|
780
|
+
for (const j of _sactxgovJsV2.values())
|
|
781
|
+
if (
|
|
782
|
+
j.status === SACTXGOV_HANDOFF_LIFECYCLE_V2.TRANSFERRING &&
|
|
783
|
+
j.startedAt != null &&
|
|
784
|
+
t - j.startedAt >= _sactxgovStuckMs
|
|
785
|
+
) {
|
|
786
|
+
j.status = SACTXGOV_HANDOFF_LIFECYCLE_V2.FAILED;
|
|
787
|
+
j.updatedAt = t;
|
|
788
|
+
if (!j.settledAt) j.settledAt = t;
|
|
789
|
+
j.metadata.failReason = "auto-fail-stuck";
|
|
790
|
+
flipped.push(j.id);
|
|
791
|
+
}
|
|
792
|
+
return { flipped, count: flipped.length };
|
|
793
|
+
}
|
|
794
|
+
export function getSubAgentContextGovStatsV2() {
|
|
795
|
+
const profilesByStatus = {};
|
|
796
|
+
for (const v of Object.values(SACTXGOV_PROFILE_MATURITY_V2))
|
|
797
|
+
profilesByStatus[v] = 0;
|
|
798
|
+
for (const p of _sactxgovPsV2.values()) profilesByStatus[p.status]++;
|
|
799
|
+
const handoffsByStatus = {};
|
|
800
|
+
for (const v of Object.values(SACTXGOV_HANDOFF_LIFECYCLE_V2))
|
|
801
|
+
handoffsByStatus[v] = 0;
|
|
802
|
+
for (const j of _sactxgovJsV2.values()) handoffsByStatus[j.status]++;
|
|
803
|
+
return {
|
|
804
|
+
totalSactxgovProfilesV2: _sactxgovPsV2.size,
|
|
805
|
+
totalSactxgovHandoffsV2: _sactxgovJsV2.size,
|
|
806
|
+
maxActiveSactxgovProfilesPerOwner: _sactxgovMaxActive,
|
|
807
|
+
maxPendingSactxgovHandoffsPerProfile: _sactxgovMaxPending,
|
|
808
|
+
sactxgovProfileIdleMs: _sactxgovIdleMs,
|
|
809
|
+
sactxgovHandoffStuckMs: _sactxgovStuckMs,
|
|
810
|
+
profilesByStatus,
|
|
811
|
+
handoffsByStatus,
|
|
812
|
+
};
|
|
813
|
+
}
|
|
@@ -162,3 +162,338 @@ export function buildSubagentSummaryLines() {
|
|
|
162
162
|
}
|
|
163
163
|
|
|
164
164
|
export const _deps = { _registry, _builtinProfiles };
|
|
165
|
+
|
|
166
|
+
// =====================================================================
|
|
167
|
+
// sub-agent-profiles V2 governance overlay (iter27)
|
|
168
|
+
// =====================================================================
|
|
169
|
+
export const SAPGOV_PROFILE_MATURITY_V2 = Object.freeze({
|
|
170
|
+
PENDING: "pending",
|
|
171
|
+
ACTIVE: "active",
|
|
172
|
+
SUSPENDED: "suspended",
|
|
173
|
+
ARCHIVED: "archived",
|
|
174
|
+
});
|
|
175
|
+
export const SAPGOV_APPLY_LIFECYCLE_V2 = Object.freeze({
|
|
176
|
+
QUEUED: "queued",
|
|
177
|
+
APPLYING: "applying",
|
|
178
|
+
APPLIED: "applied",
|
|
179
|
+
FAILED: "failed",
|
|
180
|
+
CANCELLED: "cancelled",
|
|
181
|
+
});
|
|
182
|
+
const _sapgovPTrans = new Map([
|
|
183
|
+
[
|
|
184
|
+
SAPGOV_PROFILE_MATURITY_V2.PENDING,
|
|
185
|
+
new Set([
|
|
186
|
+
SAPGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
187
|
+
SAPGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
188
|
+
]),
|
|
189
|
+
],
|
|
190
|
+
[
|
|
191
|
+
SAPGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
192
|
+
new Set([
|
|
193
|
+
SAPGOV_PROFILE_MATURITY_V2.SUSPENDED,
|
|
194
|
+
SAPGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
195
|
+
]),
|
|
196
|
+
],
|
|
197
|
+
[
|
|
198
|
+
SAPGOV_PROFILE_MATURITY_V2.SUSPENDED,
|
|
199
|
+
new Set([
|
|
200
|
+
SAPGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
201
|
+
SAPGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
202
|
+
]),
|
|
203
|
+
],
|
|
204
|
+
[SAPGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
|
|
205
|
+
]);
|
|
206
|
+
const _sapgovPTerminal = new Set([SAPGOV_PROFILE_MATURITY_V2.ARCHIVED]);
|
|
207
|
+
const _sapgovJTrans = new Map([
|
|
208
|
+
[
|
|
209
|
+
SAPGOV_APPLY_LIFECYCLE_V2.QUEUED,
|
|
210
|
+
new Set([
|
|
211
|
+
SAPGOV_APPLY_LIFECYCLE_V2.APPLYING,
|
|
212
|
+
SAPGOV_APPLY_LIFECYCLE_V2.CANCELLED,
|
|
213
|
+
]),
|
|
214
|
+
],
|
|
215
|
+
[
|
|
216
|
+
SAPGOV_APPLY_LIFECYCLE_V2.APPLYING,
|
|
217
|
+
new Set([
|
|
218
|
+
SAPGOV_APPLY_LIFECYCLE_V2.APPLIED,
|
|
219
|
+
SAPGOV_APPLY_LIFECYCLE_V2.FAILED,
|
|
220
|
+
SAPGOV_APPLY_LIFECYCLE_V2.CANCELLED,
|
|
221
|
+
]),
|
|
222
|
+
],
|
|
223
|
+
[SAPGOV_APPLY_LIFECYCLE_V2.APPLIED, new Set()],
|
|
224
|
+
[SAPGOV_APPLY_LIFECYCLE_V2.FAILED, new Set()],
|
|
225
|
+
[SAPGOV_APPLY_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
226
|
+
]);
|
|
227
|
+
const _sapgovPsV2 = new Map();
|
|
228
|
+
const _sapgovJsV2 = new Map();
|
|
229
|
+
let _sapgovMaxActive = 8,
|
|
230
|
+
_sapgovMaxPending = 20,
|
|
231
|
+
_sapgovIdleMs = 30 * 24 * 60 * 60 * 1000,
|
|
232
|
+
_sapgovStuckMs = 60 * 1000;
|
|
233
|
+
function _sapgovPos(n, label) {
|
|
234
|
+
const v = Math.floor(Number(n));
|
|
235
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
236
|
+
throw new Error(`${label} must be positive integer`);
|
|
237
|
+
return v;
|
|
238
|
+
}
|
|
239
|
+
function _sapgovCheckP(from, to) {
|
|
240
|
+
const a = _sapgovPTrans.get(from);
|
|
241
|
+
if (!a || !a.has(to))
|
|
242
|
+
throw new Error(`invalid sapgov profile transition ${from} → ${to}`);
|
|
243
|
+
}
|
|
244
|
+
function _sapgovCheckJ(from, to) {
|
|
245
|
+
const a = _sapgovJTrans.get(from);
|
|
246
|
+
if (!a || !a.has(to))
|
|
247
|
+
throw new Error(`invalid sapgov apply transition ${from} → ${to}`);
|
|
248
|
+
}
|
|
249
|
+
function _sapgovCountActive(owner) {
|
|
250
|
+
let c = 0;
|
|
251
|
+
for (const p of _sapgovPsV2.values())
|
|
252
|
+
if (p.owner === owner && p.status === SAPGOV_PROFILE_MATURITY_V2.ACTIVE)
|
|
253
|
+
c++;
|
|
254
|
+
return c;
|
|
255
|
+
}
|
|
256
|
+
function _sapgovCountPending(profileId) {
|
|
257
|
+
let c = 0;
|
|
258
|
+
for (const j of _sapgovJsV2.values())
|
|
259
|
+
if (
|
|
260
|
+
j.profileId === profileId &&
|
|
261
|
+
(j.status === SAPGOV_APPLY_LIFECYCLE_V2.QUEUED ||
|
|
262
|
+
j.status === SAPGOV_APPLY_LIFECYCLE_V2.APPLYING)
|
|
263
|
+
)
|
|
264
|
+
c++;
|
|
265
|
+
return c;
|
|
266
|
+
}
|
|
267
|
+
export function setMaxActiveSapgovProfilesPerOwnerV2(n) {
|
|
268
|
+
_sapgovMaxActive = _sapgovPos(n, "maxActiveSapgovProfilesPerOwner");
|
|
269
|
+
}
|
|
270
|
+
export function getMaxActiveSapgovProfilesPerOwnerV2() {
|
|
271
|
+
return _sapgovMaxActive;
|
|
272
|
+
}
|
|
273
|
+
export function setMaxPendingSapgovApplysPerProfileV2(n) {
|
|
274
|
+
_sapgovMaxPending = _sapgovPos(n, "maxPendingSapgovApplysPerProfile");
|
|
275
|
+
}
|
|
276
|
+
export function getMaxPendingSapgovApplysPerProfileV2() {
|
|
277
|
+
return _sapgovMaxPending;
|
|
278
|
+
}
|
|
279
|
+
export function setSapgovProfileIdleMsV2(n) {
|
|
280
|
+
_sapgovIdleMs = _sapgovPos(n, "sapgovProfileIdleMs");
|
|
281
|
+
}
|
|
282
|
+
export function getSapgovProfileIdleMsV2() {
|
|
283
|
+
return _sapgovIdleMs;
|
|
284
|
+
}
|
|
285
|
+
export function setSapgovApplyStuckMsV2(n) {
|
|
286
|
+
_sapgovStuckMs = _sapgovPos(n, "sapgovApplyStuckMs");
|
|
287
|
+
}
|
|
288
|
+
export function getSapgovApplyStuckMsV2() {
|
|
289
|
+
return _sapgovStuckMs;
|
|
290
|
+
}
|
|
291
|
+
export function _resetStateSubAgentProfilesGovV2() {
|
|
292
|
+
_sapgovPsV2.clear();
|
|
293
|
+
_sapgovJsV2.clear();
|
|
294
|
+
_sapgovMaxActive = 8;
|
|
295
|
+
_sapgovMaxPending = 20;
|
|
296
|
+
_sapgovIdleMs = 30 * 24 * 60 * 60 * 1000;
|
|
297
|
+
_sapgovStuckMs = 60 * 1000;
|
|
298
|
+
}
|
|
299
|
+
export function registerSapgovProfileV2({ id, owner, role, metadata } = {}) {
|
|
300
|
+
if (!id || !owner) throw new Error("id and owner required");
|
|
301
|
+
if (_sapgovPsV2.has(id))
|
|
302
|
+
throw new Error(`sapgov profile ${id} already exists`);
|
|
303
|
+
const now = Date.now();
|
|
304
|
+
const p = {
|
|
305
|
+
id,
|
|
306
|
+
owner,
|
|
307
|
+
role: role || "general",
|
|
308
|
+
status: SAPGOV_PROFILE_MATURITY_V2.PENDING,
|
|
309
|
+
createdAt: now,
|
|
310
|
+
updatedAt: now,
|
|
311
|
+
lastTouchedAt: now,
|
|
312
|
+
activatedAt: null,
|
|
313
|
+
archivedAt: null,
|
|
314
|
+
metadata: { ...(metadata || {}) },
|
|
315
|
+
};
|
|
316
|
+
_sapgovPsV2.set(id, p);
|
|
317
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
318
|
+
}
|
|
319
|
+
export function activateSapgovProfileV2(id) {
|
|
320
|
+
const p = _sapgovPsV2.get(id);
|
|
321
|
+
if (!p) throw new Error(`sapgov profile ${id} not found`);
|
|
322
|
+
const isInitial = p.status === SAPGOV_PROFILE_MATURITY_V2.PENDING;
|
|
323
|
+
_sapgovCheckP(p.status, SAPGOV_PROFILE_MATURITY_V2.ACTIVE);
|
|
324
|
+
if (isInitial && _sapgovCountActive(p.owner) >= _sapgovMaxActive)
|
|
325
|
+
throw new Error(`max active sapgov profiles for owner ${p.owner} reached`);
|
|
326
|
+
const now = Date.now();
|
|
327
|
+
p.status = SAPGOV_PROFILE_MATURITY_V2.ACTIVE;
|
|
328
|
+
p.updatedAt = now;
|
|
329
|
+
p.lastTouchedAt = now;
|
|
330
|
+
if (!p.activatedAt) p.activatedAt = now;
|
|
331
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
332
|
+
}
|
|
333
|
+
export function suspendSapgovProfileV2(id) {
|
|
334
|
+
const p = _sapgovPsV2.get(id);
|
|
335
|
+
if (!p) throw new Error(`sapgov profile ${id} not found`);
|
|
336
|
+
_sapgovCheckP(p.status, SAPGOV_PROFILE_MATURITY_V2.SUSPENDED);
|
|
337
|
+
p.status = SAPGOV_PROFILE_MATURITY_V2.SUSPENDED;
|
|
338
|
+
p.updatedAt = Date.now();
|
|
339
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
340
|
+
}
|
|
341
|
+
export function archiveSapgovProfileV2(id) {
|
|
342
|
+
const p = _sapgovPsV2.get(id);
|
|
343
|
+
if (!p) throw new Error(`sapgov profile ${id} not found`);
|
|
344
|
+
_sapgovCheckP(p.status, SAPGOV_PROFILE_MATURITY_V2.ARCHIVED);
|
|
345
|
+
const now = Date.now();
|
|
346
|
+
p.status = SAPGOV_PROFILE_MATURITY_V2.ARCHIVED;
|
|
347
|
+
p.updatedAt = now;
|
|
348
|
+
if (!p.archivedAt) p.archivedAt = now;
|
|
349
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
350
|
+
}
|
|
351
|
+
export function touchSapgovProfileV2(id) {
|
|
352
|
+
const p = _sapgovPsV2.get(id);
|
|
353
|
+
if (!p) throw new Error(`sapgov profile ${id} not found`);
|
|
354
|
+
if (_sapgovPTerminal.has(p.status))
|
|
355
|
+
throw new Error(`cannot touch terminal sapgov profile ${id}`);
|
|
356
|
+
const now = Date.now();
|
|
357
|
+
p.lastTouchedAt = now;
|
|
358
|
+
p.updatedAt = now;
|
|
359
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
360
|
+
}
|
|
361
|
+
export function getSapgovProfileV2(id) {
|
|
362
|
+
const p = _sapgovPsV2.get(id);
|
|
363
|
+
if (!p) return null;
|
|
364
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
365
|
+
}
|
|
366
|
+
export function listSapgovProfilesV2() {
|
|
367
|
+
return [..._sapgovPsV2.values()].map((p) => ({
|
|
368
|
+
...p,
|
|
369
|
+
metadata: { ...p.metadata },
|
|
370
|
+
}));
|
|
371
|
+
}
|
|
372
|
+
export function createSapgovApplyV2({ id, profileId, agentId, metadata } = {}) {
|
|
373
|
+
if (!id || !profileId) throw new Error("id and profileId required");
|
|
374
|
+
if (_sapgovJsV2.has(id)) throw new Error(`sapgov apply ${id} already exists`);
|
|
375
|
+
if (!_sapgovPsV2.has(profileId))
|
|
376
|
+
throw new Error(`sapgov profile ${profileId} not found`);
|
|
377
|
+
if (_sapgovCountPending(profileId) >= _sapgovMaxPending)
|
|
378
|
+
throw new Error(
|
|
379
|
+
`max pending sapgov applys for profile ${profileId} reached`,
|
|
380
|
+
);
|
|
381
|
+
const now = Date.now();
|
|
382
|
+
const j = {
|
|
383
|
+
id,
|
|
384
|
+
profileId,
|
|
385
|
+
agentId: agentId || "",
|
|
386
|
+
status: SAPGOV_APPLY_LIFECYCLE_V2.QUEUED,
|
|
387
|
+
createdAt: now,
|
|
388
|
+
updatedAt: now,
|
|
389
|
+
startedAt: null,
|
|
390
|
+
settledAt: null,
|
|
391
|
+
metadata: { ...(metadata || {}) },
|
|
392
|
+
};
|
|
393
|
+
_sapgovJsV2.set(id, j);
|
|
394
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
395
|
+
}
|
|
396
|
+
export function applyingSapgovApplyV2(id) {
|
|
397
|
+
const j = _sapgovJsV2.get(id);
|
|
398
|
+
if (!j) throw new Error(`sapgov apply ${id} not found`);
|
|
399
|
+
_sapgovCheckJ(j.status, SAPGOV_APPLY_LIFECYCLE_V2.APPLYING);
|
|
400
|
+
const now = Date.now();
|
|
401
|
+
j.status = SAPGOV_APPLY_LIFECYCLE_V2.APPLYING;
|
|
402
|
+
j.updatedAt = now;
|
|
403
|
+
if (!j.startedAt) j.startedAt = now;
|
|
404
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
405
|
+
}
|
|
406
|
+
export function completeApplySapgovV2(id) {
|
|
407
|
+
const j = _sapgovJsV2.get(id);
|
|
408
|
+
if (!j) throw new Error(`sapgov apply ${id} not found`);
|
|
409
|
+
_sapgovCheckJ(j.status, SAPGOV_APPLY_LIFECYCLE_V2.APPLIED);
|
|
410
|
+
const now = Date.now();
|
|
411
|
+
j.status = SAPGOV_APPLY_LIFECYCLE_V2.APPLIED;
|
|
412
|
+
j.updatedAt = now;
|
|
413
|
+
if (!j.settledAt) j.settledAt = now;
|
|
414
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
415
|
+
}
|
|
416
|
+
export function failSapgovApplyV2(id, reason) {
|
|
417
|
+
const j = _sapgovJsV2.get(id);
|
|
418
|
+
if (!j) throw new Error(`sapgov apply ${id} not found`);
|
|
419
|
+
_sapgovCheckJ(j.status, SAPGOV_APPLY_LIFECYCLE_V2.FAILED);
|
|
420
|
+
const now = Date.now();
|
|
421
|
+
j.status = SAPGOV_APPLY_LIFECYCLE_V2.FAILED;
|
|
422
|
+
j.updatedAt = now;
|
|
423
|
+
if (!j.settledAt) j.settledAt = now;
|
|
424
|
+
if (reason) j.metadata.failReason = String(reason);
|
|
425
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
426
|
+
}
|
|
427
|
+
export function cancelSapgovApplyV2(id, reason) {
|
|
428
|
+
const j = _sapgovJsV2.get(id);
|
|
429
|
+
if (!j) throw new Error(`sapgov apply ${id} not found`);
|
|
430
|
+
_sapgovCheckJ(j.status, SAPGOV_APPLY_LIFECYCLE_V2.CANCELLED);
|
|
431
|
+
const now = Date.now();
|
|
432
|
+
j.status = SAPGOV_APPLY_LIFECYCLE_V2.CANCELLED;
|
|
433
|
+
j.updatedAt = now;
|
|
434
|
+
if (!j.settledAt) j.settledAt = now;
|
|
435
|
+
if (reason) j.metadata.cancelReason = String(reason);
|
|
436
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
437
|
+
}
|
|
438
|
+
export function getSapgovApplyV2(id) {
|
|
439
|
+
const j = _sapgovJsV2.get(id);
|
|
440
|
+
if (!j) return null;
|
|
441
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
442
|
+
}
|
|
443
|
+
export function listSapgovApplysV2() {
|
|
444
|
+
return [..._sapgovJsV2.values()].map((j) => ({
|
|
445
|
+
...j,
|
|
446
|
+
metadata: { ...j.metadata },
|
|
447
|
+
}));
|
|
448
|
+
}
|
|
449
|
+
export function autoSuspendIdleSapgovProfilesV2({ now } = {}) {
|
|
450
|
+
const t = now ?? Date.now();
|
|
451
|
+
const flipped = [];
|
|
452
|
+
for (const p of _sapgovPsV2.values())
|
|
453
|
+
if (
|
|
454
|
+
p.status === SAPGOV_PROFILE_MATURITY_V2.ACTIVE &&
|
|
455
|
+
t - p.lastTouchedAt >= _sapgovIdleMs
|
|
456
|
+
) {
|
|
457
|
+
p.status = SAPGOV_PROFILE_MATURITY_V2.SUSPENDED;
|
|
458
|
+
p.updatedAt = t;
|
|
459
|
+
flipped.push(p.id);
|
|
460
|
+
}
|
|
461
|
+
return { flipped, count: flipped.length };
|
|
462
|
+
}
|
|
463
|
+
export function autoFailStuckSapgovApplysV2({ now } = {}) {
|
|
464
|
+
const t = now ?? Date.now();
|
|
465
|
+
const flipped = [];
|
|
466
|
+
for (const j of _sapgovJsV2.values())
|
|
467
|
+
if (
|
|
468
|
+
j.status === SAPGOV_APPLY_LIFECYCLE_V2.APPLYING &&
|
|
469
|
+
j.startedAt != null &&
|
|
470
|
+
t - j.startedAt >= _sapgovStuckMs
|
|
471
|
+
) {
|
|
472
|
+
j.status = SAPGOV_APPLY_LIFECYCLE_V2.FAILED;
|
|
473
|
+
j.updatedAt = t;
|
|
474
|
+
if (!j.settledAt) j.settledAt = t;
|
|
475
|
+
j.metadata.failReason = "auto-fail-stuck";
|
|
476
|
+
flipped.push(j.id);
|
|
477
|
+
}
|
|
478
|
+
return { flipped, count: flipped.length };
|
|
479
|
+
}
|
|
480
|
+
export function getSubAgentProfilesGovStatsV2() {
|
|
481
|
+
const profilesByStatus = {};
|
|
482
|
+
for (const v of Object.values(SAPGOV_PROFILE_MATURITY_V2))
|
|
483
|
+
profilesByStatus[v] = 0;
|
|
484
|
+
for (const p of _sapgovPsV2.values()) profilesByStatus[p.status]++;
|
|
485
|
+
const applysByStatus = {};
|
|
486
|
+
for (const v of Object.values(SAPGOV_APPLY_LIFECYCLE_V2))
|
|
487
|
+
applysByStatus[v] = 0;
|
|
488
|
+
for (const j of _sapgovJsV2.values()) applysByStatus[j.status]++;
|
|
489
|
+
return {
|
|
490
|
+
totalSapgovProfilesV2: _sapgovPsV2.size,
|
|
491
|
+
totalSapgovApplysV2: _sapgovJsV2.size,
|
|
492
|
+
maxActiveSapgovProfilesPerOwner: _sapgovMaxActive,
|
|
493
|
+
maxPendingSapgovApplysPerProfile: _sapgovMaxPending,
|
|
494
|
+
sapgovProfileIdleMs: _sapgovIdleMs,
|
|
495
|
+
sapgovApplyStuckMs: _sapgovStuckMs,
|
|
496
|
+
profilesByStatus,
|
|
497
|
+
applysByStatus,
|
|
498
|
+
};
|
|
499
|
+
}
|