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
|
@@ -577,3 +577,339 @@ export function getSubAgentRegistryStatsV2() {
|
|
|
577
577
|
tasksByStatus,
|
|
578
578
|
};
|
|
579
579
|
}
|
|
580
|
+
|
|
581
|
+
// =====================================================================
|
|
582
|
+
// sub-agent-registry V2 governance overlay (iter25)
|
|
583
|
+
// =====================================================================
|
|
584
|
+
export const SAREGOV_PROFILE_MATURITY_V2 = Object.freeze({
|
|
585
|
+
PENDING: "pending",
|
|
586
|
+
ACTIVE: "active",
|
|
587
|
+
SUSPENDED: "suspended",
|
|
588
|
+
ARCHIVED: "archived",
|
|
589
|
+
});
|
|
590
|
+
export const SAREGOV_SPAWN_LIFECYCLE_V2 = Object.freeze({
|
|
591
|
+
QUEUED: "queued",
|
|
592
|
+
SPAWNING: "spawning",
|
|
593
|
+
SPAWNED: "spawned",
|
|
594
|
+
FAILED: "failed",
|
|
595
|
+
CANCELLED: "cancelled",
|
|
596
|
+
});
|
|
597
|
+
const _saregovPTrans = new Map([
|
|
598
|
+
[
|
|
599
|
+
SAREGOV_PROFILE_MATURITY_V2.PENDING,
|
|
600
|
+
new Set([
|
|
601
|
+
SAREGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
602
|
+
SAREGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
603
|
+
]),
|
|
604
|
+
],
|
|
605
|
+
[
|
|
606
|
+
SAREGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
607
|
+
new Set([
|
|
608
|
+
SAREGOV_PROFILE_MATURITY_V2.SUSPENDED,
|
|
609
|
+
SAREGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
610
|
+
]),
|
|
611
|
+
],
|
|
612
|
+
[
|
|
613
|
+
SAREGOV_PROFILE_MATURITY_V2.SUSPENDED,
|
|
614
|
+
new Set([
|
|
615
|
+
SAREGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
616
|
+
SAREGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
617
|
+
]),
|
|
618
|
+
],
|
|
619
|
+
[SAREGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
|
|
620
|
+
]);
|
|
621
|
+
const _saregovPTerminal = new Set([SAREGOV_PROFILE_MATURITY_V2.ARCHIVED]);
|
|
622
|
+
const _saregovJTrans = new Map([
|
|
623
|
+
[
|
|
624
|
+
SAREGOV_SPAWN_LIFECYCLE_V2.QUEUED,
|
|
625
|
+
new Set([
|
|
626
|
+
SAREGOV_SPAWN_LIFECYCLE_V2.SPAWNING,
|
|
627
|
+
SAREGOV_SPAWN_LIFECYCLE_V2.CANCELLED,
|
|
628
|
+
]),
|
|
629
|
+
],
|
|
630
|
+
[
|
|
631
|
+
SAREGOV_SPAWN_LIFECYCLE_V2.SPAWNING,
|
|
632
|
+
new Set([
|
|
633
|
+
SAREGOV_SPAWN_LIFECYCLE_V2.SPAWNED,
|
|
634
|
+
SAREGOV_SPAWN_LIFECYCLE_V2.FAILED,
|
|
635
|
+
SAREGOV_SPAWN_LIFECYCLE_V2.CANCELLED,
|
|
636
|
+
]),
|
|
637
|
+
],
|
|
638
|
+
[SAREGOV_SPAWN_LIFECYCLE_V2.SPAWNED, new Set()],
|
|
639
|
+
[SAREGOV_SPAWN_LIFECYCLE_V2.FAILED, new Set()],
|
|
640
|
+
[SAREGOV_SPAWN_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
641
|
+
]);
|
|
642
|
+
const _saregovPsV2 = new Map();
|
|
643
|
+
const _saregovJsV2 = new Map();
|
|
644
|
+
let _saregovMaxActive = 10,
|
|
645
|
+
_saregovMaxPending = 25,
|
|
646
|
+
_saregovIdleMs = 30 * 24 * 60 * 60 * 1000,
|
|
647
|
+
_saregovStuckMs = 60 * 1000;
|
|
648
|
+
function _saregovPos(n, label) {
|
|
649
|
+
const v = Math.floor(Number(n));
|
|
650
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
651
|
+
throw new Error(`${label} must be positive integer`);
|
|
652
|
+
return v;
|
|
653
|
+
}
|
|
654
|
+
function _saregovCheckP(from, to) {
|
|
655
|
+
const a = _saregovPTrans.get(from);
|
|
656
|
+
if (!a || !a.has(to))
|
|
657
|
+
throw new Error(`invalid saregov profile transition ${from} → ${to}`);
|
|
658
|
+
}
|
|
659
|
+
function _saregovCheckJ(from, to) {
|
|
660
|
+
const a = _saregovJTrans.get(from);
|
|
661
|
+
if (!a || !a.has(to))
|
|
662
|
+
throw new Error(`invalid saregov spawn transition ${from} → ${to}`);
|
|
663
|
+
}
|
|
664
|
+
function _saregovCountActive(owner) {
|
|
665
|
+
let c = 0;
|
|
666
|
+
for (const p of _saregovPsV2.values())
|
|
667
|
+
if (p.owner === owner && p.status === SAREGOV_PROFILE_MATURITY_V2.ACTIVE)
|
|
668
|
+
c++;
|
|
669
|
+
return c;
|
|
670
|
+
}
|
|
671
|
+
function _saregovCountPending(profileId) {
|
|
672
|
+
let c = 0;
|
|
673
|
+
for (const j of _saregovJsV2.values())
|
|
674
|
+
if (
|
|
675
|
+
j.profileId === profileId &&
|
|
676
|
+
(j.status === SAREGOV_SPAWN_LIFECYCLE_V2.QUEUED ||
|
|
677
|
+
j.status === SAREGOV_SPAWN_LIFECYCLE_V2.SPAWNING)
|
|
678
|
+
)
|
|
679
|
+
c++;
|
|
680
|
+
return c;
|
|
681
|
+
}
|
|
682
|
+
export function setMaxActiveSaregovProfilesPerOwnerV2(n) {
|
|
683
|
+
_saregovMaxActive = _saregovPos(n, "maxActiveSaregovProfilesPerOwner");
|
|
684
|
+
}
|
|
685
|
+
export function getMaxActiveSaregovProfilesPerOwnerV2() {
|
|
686
|
+
return _saregovMaxActive;
|
|
687
|
+
}
|
|
688
|
+
export function setMaxPendingSaregovSpawnsPerProfileV2(n) {
|
|
689
|
+
_saregovMaxPending = _saregovPos(n, "maxPendingSaregovSpawnsPerProfile");
|
|
690
|
+
}
|
|
691
|
+
export function getMaxPendingSaregovSpawnsPerProfileV2() {
|
|
692
|
+
return _saregovMaxPending;
|
|
693
|
+
}
|
|
694
|
+
export function setSaregovProfileIdleMsV2(n) {
|
|
695
|
+
_saregovIdleMs = _saregovPos(n, "saregovProfileIdleMs");
|
|
696
|
+
}
|
|
697
|
+
export function getSaregovProfileIdleMsV2() {
|
|
698
|
+
return _saregovIdleMs;
|
|
699
|
+
}
|
|
700
|
+
export function setSaregovSpawnStuckMsV2(n) {
|
|
701
|
+
_saregovStuckMs = _saregovPos(n, "saregovSpawnStuckMs");
|
|
702
|
+
}
|
|
703
|
+
export function getSaregovSpawnStuckMsV2() {
|
|
704
|
+
return _saregovStuckMs;
|
|
705
|
+
}
|
|
706
|
+
export function _resetStateSubAgentRegistryGovV2() {
|
|
707
|
+
_saregovPsV2.clear();
|
|
708
|
+
_saregovJsV2.clear();
|
|
709
|
+
_saregovMaxActive = 10;
|
|
710
|
+
_saregovMaxPending = 25;
|
|
711
|
+
_saregovIdleMs = 30 * 24 * 60 * 60 * 1000;
|
|
712
|
+
_saregovStuckMs = 60 * 1000;
|
|
713
|
+
}
|
|
714
|
+
export function registerSaregovProfileV2({ id, owner, kind, metadata } = {}) {
|
|
715
|
+
if (!id || !owner) throw new Error("id and owner required");
|
|
716
|
+
if (_saregovPsV2.has(id))
|
|
717
|
+
throw new Error(`saregov profile ${id} already exists`);
|
|
718
|
+
const now = Date.now();
|
|
719
|
+
const p = {
|
|
720
|
+
id,
|
|
721
|
+
owner,
|
|
722
|
+
kind: kind || "general",
|
|
723
|
+
status: SAREGOV_PROFILE_MATURITY_V2.PENDING,
|
|
724
|
+
createdAt: now,
|
|
725
|
+
updatedAt: now,
|
|
726
|
+
lastTouchedAt: now,
|
|
727
|
+
activatedAt: null,
|
|
728
|
+
archivedAt: null,
|
|
729
|
+
metadata: { ...(metadata || {}) },
|
|
730
|
+
};
|
|
731
|
+
_saregovPsV2.set(id, p);
|
|
732
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
733
|
+
}
|
|
734
|
+
export function activateSaregovProfileV2(id) {
|
|
735
|
+
const p = _saregovPsV2.get(id);
|
|
736
|
+
if (!p) throw new Error(`saregov profile ${id} not found`);
|
|
737
|
+
const isInitial = p.status === SAREGOV_PROFILE_MATURITY_V2.PENDING;
|
|
738
|
+
_saregovCheckP(p.status, SAREGOV_PROFILE_MATURITY_V2.ACTIVE);
|
|
739
|
+
if (isInitial && _saregovCountActive(p.owner) >= _saregovMaxActive)
|
|
740
|
+
throw new Error(`max active saregov profiles for owner ${p.owner} reached`);
|
|
741
|
+
const now = Date.now();
|
|
742
|
+
p.status = SAREGOV_PROFILE_MATURITY_V2.ACTIVE;
|
|
743
|
+
p.updatedAt = now;
|
|
744
|
+
p.lastTouchedAt = now;
|
|
745
|
+
if (!p.activatedAt) p.activatedAt = now;
|
|
746
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
747
|
+
}
|
|
748
|
+
export function suspendSaregovProfileV2(id) {
|
|
749
|
+
const p = _saregovPsV2.get(id);
|
|
750
|
+
if (!p) throw new Error(`saregov profile ${id} not found`);
|
|
751
|
+
_saregovCheckP(p.status, SAREGOV_PROFILE_MATURITY_V2.SUSPENDED);
|
|
752
|
+
p.status = SAREGOV_PROFILE_MATURITY_V2.SUSPENDED;
|
|
753
|
+
p.updatedAt = Date.now();
|
|
754
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
755
|
+
}
|
|
756
|
+
export function archiveSaregovProfileV2(id) {
|
|
757
|
+
const p = _saregovPsV2.get(id);
|
|
758
|
+
if (!p) throw new Error(`saregov profile ${id} not found`);
|
|
759
|
+
_saregovCheckP(p.status, SAREGOV_PROFILE_MATURITY_V2.ARCHIVED);
|
|
760
|
+
const now = Date.now();
|
|
761
|
+
p.status = SAREGOV_PROFILE_MATURITY_V2.ARCHIVED;
|
|
762
|
+
p.updatedAt = now;
|
|
763
|
+
if (!p.archivedAt) p.archivedAt = now;
|
|
764
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
765
|
+
}
|
|
766
|
+
export function touchSaregovProfileV2(id) {
|
|
767
|
+
const p = _saregovPsV2.get(id);
|
|
768
|
+
if (!p) throw new Error(`saregov profile ${id} not found`);
|
|
769
|
+
if (_saregovPTerminal.has(p.status))
|
|
770
|
+
throw new Error(`cannot touch terminal saregov profile ${id}`);
|
|
771
|
+
const now = Date.now();
|
|
772
|
+
p.lastTouchedAt = now;
|
|
773
|
+
p.updatedAt = now;
|
|
774
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
775
|
+
}
|
|
776
|
+
export function getSaregovProfileV2(id) {
|
|
777
|
+
const p = _saregovPsV2.get(id);
|
|
778
|
+
if (!p) return null;
|
|
779
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
780
|
+
}
|
|
781
|
+
export function listSaregovProfilesV2() {
|
|
782
|
+
return [..._saregovPsV2.values()].map((p) => ({
|
|
783
|
+
...p,
|
|
784
|
+
metadata: { ...p.metadata },
|
|
785
|
+
}));
|
|
786
|
+
}
|
|
787
|
+
export function createSaregovSpawnV2({ id, profileId, task, metadata } = {}) {
|
|
788
|
+
if (!id || !profileId) throw new Error("id and profileId required");
|
|
789
|
+
if (_saregovJsV2.has(id))
|
|
790
|
+
throw new Error(`saregov spawn ${id} already exists`);
|
|
791
|
+
if (!_saregovPsV2.has(profileId))
|
|
792
|
+
throw new Error(`saregov profile ${profileId} not found`);
|
|
793
|
+
if (_saregovCountPending(profileId) >= _saregovMaxPending)
|
|
794
|
+
throw new Error(
|
|
795
|
+
`max pending saregov spawns for profile ${profileId} reached`,
|
|
796
|
+
);
|
|
797
|
+
const now = Date.now();
|
|
798
|
+
const j = {
|
|
799
|
+
id,
|
|
800
|
+
profileId,
|
|
801
|
+
task: task || "",
|
|
802
|
+
status: SAREGOV_SPAWN_LIFECYCLE_V2.QUEUED,
|
|
803
|
+
createdAt: now,
|
|
804
|
+
updatedAt: now,
|
|
805
|
+
startedAt: null,
|
|
806
|
+
settledAt: null,
|
|
807
|
+
metadata: { ...(metadata || {}) },
|
|
808
|
+
};
|
|
809
|
+
_saregovJsV2.set(id, j);
|
|
810
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
811
|
+
}
|
|
812
|
+
export function spawningSaregovSpawnV2(id) {
|
|
813
|
+
const j = _saregovJsV2.get(id);
|
|
814
|
+
if (!j) throw new Error(`saregov spawn ${id} not found`);
|
|
815
|
+
_saregovCheckJ(j.status, SAREGOV_SPAWN_LIFECYCLE_V2.SPAWNING);
|
|
816
|
+
const now = Date.now();
|
|
817
|
+
j.status = SAREGOV_SPAWN_LIFECYCLE_V2.SPAWNING;
|
|
818
|
+
j.updatedAt = now;
|
|
819
|
+
if (!j.startedAt) j.startedAt = now;
|
|
820
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
821
|
+
}
|
|
822
|
+
export function completeSpawnSaregovV2(id) {
|
|
823
|
+
const j = _saregovJsV2.get(id);
|
|
824
|
+
if (!j) throw new Error(`saregov spawn ${id} not found`);
|
|
825
|
+
_saregovCheckJ(j.status, SAREGOV_SPAWN_LIFECYCLE_V2.SPAWNED);
|
|
826
|
+
const now = Date.now();
|
|
827
|
+
j.status = SAREGOV_SPAWN_LIFECYCLE_V2.SPAWNED;
|
|
828
|
+
j.updatedAt = now;
|
|
829
|
+
if (!j.settledAt) j.settledAt = now;
|
|
830
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
831
|
+
}
|
|
832
|
+
export function failSaregovSpawnV2(id, reason) {
|
|
833
|
+
const j = _saregovJsV2.get(id);
|
|
834
|
+
if (!j) throw new Error(`saregov spawn ${id} not found`);
|
|
835
|
+
_saregovCheckJ(j.status, SAREGOV_SPAWN_LIFECYCLE_V2.FAILED);
|
|
836
|
+
const now = Date.now();
|
|
837
|
+
j.status = SAREGOV_SPAWN_LIFECYCLE_V2.FAILED;
|
|
838
|
+
j.updatedAt = now;
|
|
839
|
+
if (!j.settledAt) j.settledAt = now;
|
|
840
|
+
if (reason) j.metadata.failReason = String(reason);
|
|
841
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
842
|
+
}
|
|
843
|
+
export function cancelSaregovSpawnV2(id, reason) {
|
|
844
|
+
const j = _saregovJsV2.get(id);
|
|
845
|
+
if (!j) throw new Error(`saregov spawn ${id} not found`);
|
|
846
|
+
_saregovCheckJ(j.status, SAREGOV_SPAWN_LIFECYCLE_V2.CANCELLED);
|
|
847
|
+
const now = Date.now();
|
|
848
|
+
j.status = SAREGOV_SPAWN_LIFECYCLE_V2.CANCELLED;
|
|
849
|
+
j.updatedAt = now;
|
|
850
|
+
if (!j.settledAt) j.settledAt = now;
|
|
851
|
+
if (reason) j.metadata.cancelReason = String(reason);
|
|
852
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
853
|
+
}
|
|
854
|
+
export function getSaregovSpawnV2(id) {
|
|
855
|
+
const j = _saregovJsV2.get(id);
|
|
856
|
+
if (!j) return null;
|
|
857
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
858
|
+
}
|
|
859
|
+
export function listSaregovSpawnsV2() {
|
|
860
|
+
return [..._saregovJsV2.values()].map((j) => ({
|
|
861
|
+
...j,
|
|
862
|
+
metadata: { ...j.metadata },
|
|
863
|
+
}));
|
|
864
|
+
}
|
|
865
|
+
export function autoSuspendIdleSaregovProfilesV2({ now } = {}) {
|
|
866
|
+
const t = now ?? Date.now();
|
|
867
|
+
const flipped = [];
|
|
868
|
+
for (const p of _saregovPsV2.values())
|
|
869
|
+
if (
|
|
870
|
+
p.status === SAREGOV_PROFILE_MATURITY_V2.ACTIVE &&
|
|
871
|
+
t - p.lastTouchedAt >= _saregovIdleMs
|
|
872
|
+
) {
|
|
873
|
+
p.status = SAREGOV_PROFILE_MATURITY_V2.SUSPENDED;
|
|
874
|
+
p.updatedAt = t;
|
|
875
|
+
flipped.push(p.id);
|
|
876
|
+
}
|
|
877
|
+
return { flipped, count: flipped.length };
|
|
878
|
+
}
|
|
879
|
+
export function autoFailStuckSaregovSpawnsV2({ now } = {}) {
|
|
880
|
+
const t = now ?? Date.now();
|
|
881
|
+
const flipped = [];
|
|
882
|
+
for (const j of _saregovJsV2.values())
|
|
883
|
+
if (
|
|
884
|
+
j.status === SAREGOV_SPAWN_LIFECYCLE_V2.SPAWNING &&
|
|
885
|
+
j.startedAt != null &&
|
|
886
|
+
t - j.startedAt >= _saregovStuckMs
|
|
887
|
+
) {
|
|
888
|
+
j.status = SAREGOV_SPAWN_LIFECYCLE_V2.FAILED;
|
|
889
|
+
j.updatedAt = t;
|
|
890
|
+
if (!j.settledAt) j.settledAt = t;
|
|
891
|
+
j.metadata.failReason = "auto-fail-stuck";
|
|
892
|
+
flipped.push(j.id);
|
|
893
|
+
}
|
|
894
|
+
return { flipped, count: flipped.length };
|
|
895
|
+
}
|
|
896
|
+
export function getSubAgentRegistryGovStatsV2() {
|
|
897
|
+
const profilesByStatus = {};
|
|
898
|
+
for (const v of Object.values(SAREGOV_PROFILE_MATURITY_V2))
|
|
899
|
+
profilesByStatus[v] = 0;
|
|
900
|
+
for (const p of _saregovPsV2.values()) profilesByStatus[p.status]++;
|
|
901
|
+
const spawnsByStatus = {};
|
|
902
|
+
for (const v of Object.values(SAREGOV_SPAWN_LIFECYCLE_V2))
|
|
903
|
+
spawnsByStatus[v] = 0;
|
|
904
|
+
for (const j of _saregovJsV2.values()) spawnsByStatus[j.status]++;
|
|
905
|
+
return {
|
|
906
|
+
totalSaregovProfilesV2: _saregovPsV2.size,
|
|
907
|
+
totalSaregovSpawnsV2: _saregovJsV2.size,
|
|
908
|
+
maxActiveSaregovProfilesPerOwner: _saregovMaxActive,
|
|
909
|
+
maxPendingSaregovSpawnsPerProfile: _saregovMaxPending,
|
|
910
|
+
saregovProfileIdleMs: _saregovIdleMs,
|
|
911
|
+
saregovSpawnStuckMs: _saregovStuckMs,
|
|
912
|
+
profilesByStatus,
|
|
913
|
+
spawnsByStatus,
|
|
914
|
+
};
|
|
915
|
+
}
|
package/src/lib/sync-manager.js
CHANGED
|
@@ -671,3 +671,339 @@ export function _resetStateSyncManagerV2() {
|
|
|
671
671
|
_resourceIdleMsV2 = SYNC_DEFAULT_RESOURCE_IDLE_MS;
|
|
672
672
|
_runStuckMsV2 = SYNC_DEFAULT_RUN_STUCK_MS;
|
|
673
673
|
}
|
|
674
|
+
|
|
675
|
+
// =====================================================================
|
|
676
|
+
// sync-manager V2 governance overlay (iter19)
|
|
677
|
+
// =====================================================================
|
|
678
|
+
export const SYNCGOV_PROFILE_MATURITY_V2 = Object.freeze({
|
|
679
|
+
PENDING: "pending",
|
|
680
|
+
ACTIVE: "active",
|
|
681
|
+
STALE: "stale",
|
|
682
|
+
ARCHIVED: "archived",
|
|
683
|
+
});
|
|
684
|
+
export const SYNCGOV_BATCH_LIFECYCLE_V2 = Object.freeze({
|
|
685
|
+
QUEUED: "queued",
|
|
686
|
+
REPLICATING: "replicating",
|
|
687
|
+
REPLICATED: "replicated",
|
|
688
|
+
FAILED: "failed",
|
|
689
|
+
CANCELLED: "cancelled",
|
|
690
|
+
});
|
|
691
|
+
const _syncgovPTrans = new Map([
|
|
692
|
+
[
|
|
693
|
+
SYNCGOV_PROFILE_MATURITY_V2.PENDING,
|
|
694
|
+
new Set([
|
|
695
|
+
SYNCGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
696
|
+
SYNCGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
697
|
+
]),
|
|
698
|
+
],
|
|
699
|
+
[
|
|
700
|
+
SYNCGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
701
|
+
new Set([
|
|
702
|
+
SYNCGOV_PROFILE_MATURITY_V2.STALE,
|
|
703
|
+
SYNCGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
704
|
+
]),
|
|
705
|
+
],
|
|
706
|
+
[
|
|
707
|
+
SYNCGOV_PROFILE_MATURITY_V2.STALE,
|
|
708
|
+
new Set([
|
|
709
|
+
SYNCGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
710
|
+
SYNCGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
711
|
+
]),
|
|
712
|
+
],
|
|
713
|
+
[SYNCGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
|
|
714
|
+
]);
|
|
715
|
+
const _syncgovPTerminal = new Set([SYNCGOV_PROFILE_MATURITY_V2.ARCHIVED]);
|
|
716
|
+
const _syncgovJTrans = new Map([
|
|
717
|
+
[
|
|
718
|
+
SYNCGOV_BATCH_LIFECYCLE_V2.QUEUED,
|
|
719
|
+
new Set([
|
|
720
|
+
SYNCGOV_BATCH_LIFECYCLE_V2.REPLICATING,
|
|
721
|
+
SYNCGOV_BATCH_LIFECYCLE_V2.CANCELLED,
|
|
722
|
+
]),
|
|
723
|
+
],
|
|
724
|
+
[
|
|
725
|
+
SYNCGOV_BATCH_LIFECYCLE_V2.REPLICATING,
|
|
726
|
+
new Set([
|
|
727
|
+
SYNCGOV_BATCH_LIFECYCLE_V2.REPLICATED,
|
|
728
|
+
SYNCGOV_BATCH_LIFECYCLE_V2.FAILED,
|
|
729
|
+
SYNCGOV_BATCH_LIFECYCLE_V2.CANCELLED,
|
|
730
|
+
]),
|
|
731
|
+
],
|
|
732
|
+
[SYNCGOV_BATCH_LIFECYCLE_V2.REPLICATED, new Set()],
|
|
733
|
+
[SYNCGOV_BATCH_LIFECYCLE_V2.FAILED, new Set()],
|
|
734
|
+
[SYNCGOV_BATCH_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
735
|
+
]);
|
|
736
|
+
const _syncgovPsV2 = new Map();
|
|
737
|
+
const _syncgovJsV2 = new Map();
|
|
738
|
+
let _syncgovMaxActive = 8,
|
|
739
|
+
_syncgovMaxPending = 20,
|
|
740
|
+
_syncgovIdleMs = 30 * 24 * 60 * 60 * 1000,
|
|
741
|
+
_syncgovStuckMs = 60 * 1000;
|
|
742
|
+
function _syncgovPos(n, label) {
|
|
743
|
+
const v = Math.floor(Number(n));
|
|
744
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
745
|
+
throw new Error(`${label} must be positive integer`);
|
|
746
|
+
return v;
|
|
747
|
+
}
|
|
748
|
+
function _syncgovCheckP(from, to) {
|
|
749
|
+
const a = _syncgovPTrans.get(from);
|
|
750
|
+
if (!a || !a.has(to))
|
|
751
|
+
throw new Error(`invalid syncgov profile transition ${from} → ${to}`);
|
|
752
|
+
}
|
|
753
|
+
function _syncgovCheckJ(from, to) {
|
|
754
|
+
const a = _syncgovJTrans.get(from);
|
|
755
|
+
if (!a || !a.has(to))
|
|
756
|
+
throw new Error(`invalid syncgov batch transition ${from} → ${to}`);
|
|
757
|
+
}
|
|
758
|
+
function _syncgovCountActive(owner) {
|
|
759
|
+
let c = 0;
|
|
760
|
+
for (const p of _syncgovPsV2.values())
|
|
761
|
+
if (p.owner === owner && p.status === SYNCGOV_PROFILE_MATURITY_V2.ACTIVE)
|
|
762
|
+
c++;
|
|
763
|
+
return c;
|
|
764
|
+
}
|
|
765
|
+
function _syncgovCountPending(profileId) {
|
|
766
|
+
let c = 0;
|
|
767
|
+
for (const j of _syncgovJsV2.values())
|
|
768
|
+
if (
|
|
769
|
+
j.profileId === profileId &&
|
|
770
|
+
(j.status === SYNCGOV_BATCH_LIFECYCLE_V2.QUEUED ||
|
|
771
|
+
j.status === SYNCGOV_BATCH_LIFECYCLE_V2.REPLICATING)
|
|
772
|
+
)
|
|
773
|
+
c++;
|
|
774
|
+
return c;
|
|
775
|
+
}
|
|
776
|
+
export function setMaxActiveSyncgovProfilesPerOwnerV2(n) {
|
|
777
|
+
_syncgovMaxActive = _syncgovPos(n, "maxActiveSyncgovProfilesPerOwner");
|
|
778
|
+
}
|
|
779
|
+
export function getMaxActiveSyncgovProfilesPerOwnerV2() {
|
|
780
|
+
return _syncgovMaxActive;
|
|
781
|
+
}
|
|
782
|
+
export function setMaxPendingSyncgovBatchsPerProfileV2(n) {
|
|
783
|
+
_syncgovMaxPending = _syncgovPos(n, "maxPendingSyncgovBatchsPerProfile");
|
|
784
|
+
}
|
|
785
|
+
export function getMaxPendingSyncgovBatchsPerProfileV2() {
|
|
786
|
+
return _syncgovMaxPending;
|
|
787
|
+
}
|
|
788
|
+
export function setSyncgovProfileIdleMsV2(n) {
|
|
789
|
+
_syncgovIdleMs = _syncgovPos(n, "syncgovProfileIdleMs");
|
|
790
|
+
}
|
|
791
|
+
export function getSyncgovProfileIdleMsV2() {
|
|
792
|
+
return _syncgovIdleMs;
|
|
793
|
+
}
|
|
794
|
+
export function setSyncgovBatchStuckMsV2(n) {
|
|
795
|
+
_syncgovStuckMs = _syncgovPos(n, "syncgovBatchStuckMs");
|
|
796
|
+
}
|
|
797
|
+
export function getSyncgovBatchStuckMsV2() {
|
|
798
|
+
return _syncgovStuckMs;
|
|
799
|
+
}
|
|
800
|
+
export function _resetStateSyncManagerGovV2() {
|
|
801
|
+
_syncgovPsV2.clear();
|
|
802
|
+
_syncgovJsV2.clear();
|
|
803
|
+
_syncgovMaxActive = 8;
|
|
804
|
+
_syncgovMaxPending = 20;
|
|
805
|
+
_syncgovIdleMs = 30 * 24 * 60 * 60 * 1000;
|
|
806
|
+
_syncgovStuckMs = 60 * 1000;
|
|
807
|
+
}
|
|
808
|
+
export function registerSyncgovProfileV2({ id, owner, target, metadata } = {}) {
|
|
809
|
+
if (!id || !owner) throw new Error("id and owner required");
|
|
810
|
+
if (_syncgovPsV2.has(id))
|
|
811
|
+
throw new Error(`syncgov profile ${id} already exists`);
|
|
812
|
+
const now = Date.now();
|
|
813
|
+
const p = {
|
|
814
|
+
id,
|
|
815
|
+
owner,
|
|
816
|
+
target: target || "primary",
|
|
817
|
+
status: SYNCGOV_PROFILE_MATURITY_V2.PENDING,
|
|
818
|
+
createdAt: now,
|
|
819
|
+
updatedAt: now,
|
|
820
|
+
lastTouchedAt: now,
|
|
821
|
+
activatedAt: null,
|
|
822
|
+
archivedAt: null,
|
|
823
|
+
metadata: { ...(metadata || {}) },
|
|
824
|
+
};
|
|
825
|
+
_syncgovPsV2.set(id, p);
|
|
826
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
827
|
+
}
|
|
828
|
+
export function activateSyncgovProfileV2(id) {
|
|
829
|
+
const p = _syncgovPsV2.get(id);
|
|
830
|
+
if (!p) throw new Error(`syncgov profile ${id} not found`);
|
|
831
|
+
const isInitial = p.status === SYNCGOV_PROFILE_MATURITY_V2.PENDING;
|
|
832
|
+
_syncgovCheckP(p.status, SYNCGOV_PROFILE_MATURITY_V2.ACTIVE);
|
|
833
|
+
if (isInitial && _syncgovCountActive(p.owner) >= _syncgovMaxActive)
|
|
834
|
+
throw new Error(`max active syncgov profiles for owner ${p.owner} reached`);
|
|
835
|
+
const now = Date.now();
|
|
836
|
+
p.status = SYNCGOV_PROFILE_MATURITY_V2.ACTIVE;
|
|
837
|
+
p.updatedAt = now;
|
|
838
|
+
p.lastTouchedAt = now;
|
|
839
|
+
if (!p.activatedAt) p.activatedAt = now;
|
|
840
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
841
|
+
}
|
|
842
|
+
export function staleSyncgovProfileV2(id) {
|
|
843
|
+
const p = _syncgovPsV2.get(id);
|
|
844
|
+
if (!p) throw new Error(`syncgov profile ${id} not found`);
|
|
845
|
+
_syncgovCheckP(p.status, SYNCGOV_PROFILE_MATURITY_V2.STALE);
|
|
846
|
+
p.status = SYNCGOV_PROFILE_MATURITY_V2.STALE;
|
|
847
|
+
p.updatedAt = Date.now();
|
|
848
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
849
|
+
}
|
|
850
|
+
export function archiveSyncgovProfileV2(id) {
|
|
851
|
+
const p = _syncgovPsV2.get(id);
|
|
852
|
+
if (!p) throw new Error(`syncgov profile ${id} not found`);
|
|
853
|
+
_syncgovCheckP(p.status, SYNCGOV_PROFILE_MATURITY_V2.ARCHIVED);
|
|
854
|
+
const now = Date.now();
|
|
855
|
+
p.status = SYNCGOV_PROFILE_MATURITY_V2.ARCHIVED;
|
|
856
|
+
p.updatedAt = now;
|
|
857
|
+
if (!p.archivedAt) p.archivedAt = now;
|
|
858
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
859
|
+
}
|
|
860
|
+
export function touchSyncgovProfileV2(id) {
|
|
861
|
+
const p = _syncgovPsV2.get(id);
|
|
862
|
+
if (!p) throw new Error(`syncgov profile ${id} not found`);
|
|
863
|
+
if (_syncgovPTerminal.has(p.status))
|
|
864
|
+
throw new Error(`cannot touch terminal syncgov profile ${id}`);
|
|
865
|
+
const now = Date.now();
|
|
866
|
+
p.lastTouchedAt = now;
|
|
867
|
+
p.updatedAt = now;
|
|
868
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
869
|
+
}
|
|
870
|
+
export function getSyncgovProfileV2(id) {
|
|
871
|
+
const p = _syncgovPsV2.get(id);
|
|
872
|
+
if (!p) return null;
|
|
873
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
874
|
+
}
|
|
875
|
+
export function listSyncgovProfilesV2() {
|
|
876
|
+
return [..._syncgovPsV2.values()].map((p) => ({
|
|
877
|
+
...p,
|
|
878
|
+
metadata: { ...p.metadata },
|
|
879
|
+
}));
|
|
880
|
+
}
|
|
881
|
+
export function createSyncgovBatchV2({ id, profileId, scope, metadata } = {}) {
|
|
882
|
+
if (!id || !profileId) throw new Error("id and profileId required");
|
|
883
|
+
if (_syncgovJsV2.has(id))
|
|
884
|
+
throw new Error(`syncgov batch ${id} already exists`);
|
|
885
|
+
if (!_syncgovPsV2.has(profileId))
|
|
886
|
+
throw new Error(`syncgov profile ${profileId} not found`);
|
|
887
|
+
if (_syncgovCountPending(profileId) >= _syncgovMaxPending)
|
|
888
|
+
throw new Error(
|
|
889
|
+
`max pending syncgov batchs for profile ${profileId} reached`,
|
|
890
|
+
);
|
|
891
|
+
const now = Date.now();
|
|
892
|
+
const j = {
|
|
893
|
+
id,
|
|
894
|
+
profileId,
|
|
895
|
+
scope: scope || "",
|
|
896
|
+
status: SYNCGOV_BATCH_LIFECYCLE_V2.QUEUED,
|
|
897
|
+
createdAt: now,
|
|
898
|
+
updatedAt: now,
|
|
899
|
+
startedAt: null,
|
|
900
|
+
settledAt: null,
|
|
901
|
+
metadata: { ...(metadata || {}) },
|
|
902
|
+
};
|
|
903
|
+
_syncgovJsV2.set(id, j);
|
|
904
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
905
|
+
}
|
|
906
|
+
export function replicatingSyncgovBatchV2(id) {
|
|
907
|
+
const j = _syncgovJsV2.get(id);
|
|
908
|
+
if (!j) throw new Error(`syncgov batch ${id} not found`);
|
|
909
|
+
_syncgovCheckJ(j.status, SYNCGOV_BATCH_LIFECYCLE_V2.REPLICATING);
|
|
910
|
+
const now = Date.now();
|
|
911
|
+
j.status = SYNCGOV_BATCH_LIFECYCLE_V2.REPLICATING;
|
|
912
|
+
j.updatedAt = now;
|
|
913
|
+
if (!j.startedAt) j.startedAt = now;
|
|
914
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
915
|
+
}
|
|
916
|
+
export function completeBatchSyncgovV2(id) {
|
|
917
|
+
const j = _syncgovJsV2.get(id);
|
|
918
|
+
if (!j) throw new Error(`syncgov batch ${id} not found`);
|
|
919
|
+
_syncgovCheckJ(j.status, SYNCGOV_BATCH_LIFECYCLE_V2.REPLICATED);
|
|
920
|
+
const now = Date.now();
|
|
921
|
+
j.status = SYNCGOV_BATCH_LIFECYCLE_V2.REPLICATED;
|
|
922
|
+
j.updatedAt = now;
|
|
923
|
+
if (!j.settledAt) j.settledAt = now;
|
|
924
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
925
|
+
}
|
|
926
|
+
export function failSyncgovBatchV2(id, reason) {
|
|
927
|
+
const j = _syncgovJsV2.get(id);
|
|
928
|
+
if (!j) throw new Error(`syncgov batch ${id} not found`);
|
|
929
|
+
_syncgovCheckJ(j.status, SYNCGOV_BATCH_LIFECYCLE_V2.FAILED);
|
|
930
|
+
const now = Date.now();
|
|
931
|
+
j.status = SYNCGOV_BATCH_LIFECYCLE_V2.FAILED;
|
|
932
|
+
j.updatedAt = now;
|
|
933
|
+
if (!j.settledAt) j.settledAt = now;
|
|
934
|
+
if (reason) j.metadata.failReason = String(reason);
|
|
935
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
936
|
+
}
|
|
937
|
+
export function cancelSyncgovBatchV2(id, reason) {
|
|
938
|
+
const j = _syncgovJsV2.get(id);
|
|
939
|
+
if (!j) throw new Error(`syncgov batch ${id} not found`);
|
|
940
|
+
_syncgovCheckJ(j.status, SYNCGOV_BATCH_LIFECYCLE_V2.CANCELLED);
|
|
941
|
+
const now = Date.now();
|
|
942
|
+
j.status = SYNCGOV_BATCH_LIFECYCLE_V2.CANCELLED;
|
|
943
|
+
j.updatedAt = now;
|
|
944
|
+
if (!j.settledAt) j.settledAt = now;
|
|
945
|
+
if (reason) j.metadata.cancelReason = String(reason);
|
|
946
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
947
|
+
}
|
|
948
|
+
export function getSyncgovBatchV2(id) {
|
|
949
|
+
const j = _syncgovJsV2.get(id);
|
|
950
|
+
if (!j) return null;
|
|
951
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
952
|
+
}
|
|
953
|
+
export function listSyncgovBatchsV2() {
|
|
954
|
+
return [..._syncgovJsV2.values()].map((j) => ({
|
|
955
|
+
...j,
|
|
956
|
+
metadata: { ...j.metadata },
|
|
957
|
+
}));
|
|
958
|
+
}
|
|
959
|
+
export function autoStaleIdleSyncgovProfilesV2({ now } = {}) {
|
|
960
|
+
const t = now ?? Date.now();
|
|
961
|
+
const flipped = [];
|
|
962
|
+
for (const p of _syncgovPsV2.values())
|
|
963
|
+
if (
|
|
964
|
+
p.status === SYNCGOV_PROFILE_MATURITY_V2.ACTIVE &&
|
|
965
|
+
t - p.lastTouchedAt >= _syncgovIdleMs
|
|
966
|
+
) {
|
|
967
|
+
p.status = SYNCGOV_PROFILE_MATURITY_V2.STALE;
|
|
968
|
+
p.updatedAt = t;
|
|
969
|
+
flipped.push(p.id);
|
|
970
|
+
}
|
|
971
|
+
return { flipped, count: flipped.length };
|
|
972
|
+
}
|
|
973
|
+
export function autoFailStuckSyncgovBatchsV2({ now } = {}) {
|
|
974
|
+
const t = now ?? Date.now();
|
|
975
|
+
const flipped = [];
|
|
976
|
+
for (const j of _syncgovJsV2.values())
|
|
977
|
+
if (
|
|
978
|
+
j.status === SYNCGOV_BATCH_LIFECYCLE_V2.REPLICATING &&
|
|
979
|
+
j.startedAt != null &&
|
|
980
|
+
t - j.startedAt >= _syncgovStuckMs
|
|
981
|
+
) {
|
|
982
|
+
j.status = SYNCGOV_BATCH_LIFECYCLE_V2.FAILED;
|
|
983
|
+
j.updatedAt = t;
|
|
984
|
+
if (!j.settledAt) j.settledAt = t;
|
|
985
|
+
j.metadata.failReason = "auto-fail-stuck";
|
|
986
|
+
flipped.push(j.id);
|
|
987
|
+
}
|
|
988
|
+
return { flipped, count: flipped.length };
|
|
989
|
+
}
|
|
990
|
+
export function getSyncManagerGovStatsV2() {
|
|
991
|
+
const profilesByStatus = {};
|
|
992
|
+
for (const v of Object.values(SYNCGOV_PROFILE_MATURITY_V2))
|
|
993
|
+
profilesByStatus[v] = 0;
|
|
994
|
+
for (const p of _syncgovPsV2.values()) profilesByStatus[p.status]++;
|
|
995
|
+
const batchsByStatus = {};
|
|
996
|
+
for (const v of Object.values(SYNCGOV_BATCH_LIFECYCLE_V2))
|
|
997
|
+
batchsByStatus[v] = 0;
|
|
998
|
+
for (const j of _syncgovJsV2.values()) batchsByStatus[j.status]++;
|
|
999
|
+
return {
|
|
1000
|
+
totalSyncgovProfilesV2: _syncgovPsV2.size,
|
|
1001
|
+
totalSyncgovBatchsV2: _syncgovJsV2.size,
|
|
1002
|
+
maxActiveSyncgovProfilesPerOwner: _syncgovMaxActive,
|
|
1003
|
+
maxPendingSyncgovBatchsPerProfile: _syncgovMaxPending,
|
|
1004
|
+
syncgovProfileIdleMs: _syncgovIdleMs,
|
|
1005
|
+
syncgovBatchStuckMs: _syncgovStuckMs,
|
|
1006
|
+
profilesByStatus,
|
|
1007
|
+
batchsByStatus,
|
|
1008
|
+
};
|
|
1009
|
+
}
|