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
package/src/lib/pqc-manager.js
CHANGED
|
@@ -694,3 +694,349 @@ export function _resetStatePqcManagerV2() {
|
|
|
694
694
|
_keyIdleMsV2 = PQC_DEFAULT_KEY_IDLE_MS;
|
|
695
695
|
_migrationStuckMsV2 = PQC_DEFAULT_MIGRATION_STUCK_MS;
|
|
696
696
|
}
|
|
697
|
+
|
|
698
|
+
// =====================================================================
|
|
699
|
+
// pqc-manager V2 governance overlay (iter22)
|
|
700
|
+
// =====================================================================
|
|
701
|
+
export const PQCGOV_PROFILE_MATURITY_V2 = Object.freeze({
|
|
702
|
+
PENDING: "pending",
|
|
703
|
+
ACTIVE: "active",
|
|
704
|
+
DEPRECATED: "deprecated",
|
|
705
|
+
ARCHIVED: "archived",
|
|
706
|
+
});
|
|
707
|
+
export const PQCGOV_KEYGEN_LIFECYCLE_V2 = Object.freeze({
|
|
708
|
+
QUEUED: "queued",
|
|
709
|
+
GENERATING: "generating",
|
|
710
|
+
GENERATED: "generated",
|
|
711
|
+
FAILED: "failed",
|
|
712
|
+
CANCELLED: "cancelled",
|
|
713
|
+
});
|
|
714
|
+
const _pqcgovPTrans = new Map([
|
|
715
|
+
[
|
|
716
|
+
PQCGOV_PROFILE_MATURITY_V2.PENDING,
|
|
717
|
+
new Set([
|
|
718
|
+
PQCGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
719
|
+
PQCGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
720
|
+
]),
|
|
721
|
+
],
|
|
722
|
+
[
|
|
723
|
+
PQCGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
724
|
+
new Set([
|
|
725
|
+
PQCGOV_PROFILE_MATURITY_V2.DEPRECATED,
|
|
726
|
+
PQCGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
727
|
+
]),
|
|
728
|
+
],
|
|
729
|
+
[
|
|
730
|
+
PQCGOV_PROFILE_MATURITY_V2.DEPRECATED,
|
|
731
|
+
new Set([
|
|
732
|
+
PQCGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
733
|
+
PQCGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
734
|
+
]),
|
|
735
|
+
],
|
|
736
|
+
[PQCGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
|
|
737
|
+
]);
|
|
738
|
+
const _pqcgovPTerminal = new Set([PQCGOV_PROFILE_MATURITY_V2.ARCHIVED]);
|
|
739
|
+
const _pqcgovJTrans = new Map([
|
|
740
|
+
[
|
|
741
|
+
PQCGOV_KEYGEN_LIFECYCLE_V2.QUEUED,
|
|
742
|
+
new Set([
|
|
743
|
+
PQCGOV_KEYGEN_LIFECYCLE_V2.GENERATING,
|
|
744
|
+
PQCGOV_KEYGEN_LIFECYCLE_V2.CANCELLED,
|
|
745
|
+
]),
|
|
746
|
+
],
|
|
747
|
+
[
|
|
748
|
+
PQCGOV_KEYGEN_LIFECYCLE_V2.GENERATING,
|
|
749
|
+
new Set([
|
|
750
|
+
PQCGOV_KEYGEN_LIFECYCLE_V2.GENERATED,
|
|
751
|
+
PQCGOV_KEYGEN_LIFECYCLE_V2.FAILED,
|
|
752
|
+
PQCGOV_KEYGEN_LIFECYCLE_V2.CANCELLED,
|
|
753
|
+
]),
|
|
754
|
+
],
|
|
755
|
+
[PQCGOV_KEYGEN_LIFECYCLE_V2.GENERATED, new Set()],
|
|
756
|
+
[PQCGOV_KEYGEN_LIFECYCLE_V2.FAILED, new Set()],
|
|
757
|
+
[PQCGOV_KEYGEN_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
758
|
+
]);
|
|
759
|
+
const _pqcgovPsV2 = new Map();
|
|
760
|
+
const _pqcgovJsV2 = new Map();
|
|
761
|
+
let _pqcgovMaxActive = 6,
|
|
762
|
+
_pqcgovMaxPending = 12,
|
|
763
|
+
_pqcgovIdleMs = 30 * 24 * 60 * 60 * 1000,
|
|
764
|
+
_pqcgovStuckMs = 60 * 1000;
|
|
765
|
+
function _pqcgovPos(n, label) {
|
|
766
|
+
const v = Math.floor(Number(n));
|
|
767
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
768
|
+
throw new Error(`${label} must be positive integer`);
|
|
769
|
+
return v;
|
|
770
|
+
}
|
|
771
|
+
function _pqcgovCheckP(from, to) {
|
|
772
|
+
const a = _pqcgovPTrans.get(from);
|
|
773
|
+
if (!a || !a.has(to))
|
|
774
|
+
throw new Error(`invalid pqcgov profile transition ${from} → ${to}`);
|
|
775
|
+
}
|
|
776
|
+
function _pqcgovCheckJ(from, to) {
|
|
777
|
+
const a = _pqcgovJTrans.get(from);
|
|
778
|
+
if (!a || !a.has(to))
|
|
779
|
+
throw new Error(`invalid pqcgov keygen transition ${from} → ${to}`);
|
|
780
|
+
}
|
|
781
|
+
function _pqcgovCountActive(owner) {
|
|
782
|
+
let c = 0;
|
|
783
|
+
for (const p of _pqcgovPsV2.values())
|
|
784
|
+
if (p.owner === owner && p.status === PQCGOV_PROFILE_MATURITY_V2.ACTIVE)
|
|
785
|
+
c++;
|
|
786
|
+
return c;
|
|
787
|
+
}
|
|
788
|
+
function _pqcgovCountPending(profileId) {
|
|
789
|
+
let c = 0;
|
|
790
|
+
for (const j of _pqcgovJsV2.values())
|
|
791
|
+
if (
|
|
792
|
+
j.profileId === profileId &&
|
|
793
|
+
(j.status === PQCGOV_KEYGEN_LIFECYCLE_V2.QUEUED ||
|
|
794
|
+
j.status === PQCGOV_KEYGEN_LIFECYCLE_V2.GENERATING)
|
|
795
|
+
)
|
|
796
|
+
c++;
|
|
797
|
+
return c;
|
|
798
|
+
}
|
|
799
|
+
export function setMaxActivePqcgovProfilesPerOwnerV2(n) {
|
|
800
|
+
_pqcgovMaxActive = _pqcgovPos(n, "maxActivePqcgovProfilesPerOwner");
|
|
801
|
+
}
|
|
802
|
+
export function getMaxActivePqcgovProfilesPerOwnerV2() {
|
|
803
|
+
return _pqcgovMaxActive;
|
|
804
|
+
}
|
|
805
|
+
export function setMaxPendingPqcgovKeygensPerProfileV2(n) {
|
|
806
|
+
_pqcgovMaxPending = _pqcgovPos(n, "maxPendingPqcgovKeygensPerProfile");
|
|
807
|
+
}
|
|
808
|
+
export function getMaxPendingPqcgovKeygensPerProfileV2() {
|
|
809
|
+
return _pqcgovMaxPending;
|
|
810
|
+
}
|
|
811
|
+
export function setPqcgovProfileIdleMsV2(n) {
|
|
812
|
+
_pqcgovIdleMs = _pqcgovPos(n, "pqcgovProfileIdleMs");
|
|
813
|
+
}
|
|
814
|
+
export function getPqcgovProfileIdleMsV2() {
|
|
815
|
+
return _pqcgovIdleMs;
|
|
816
|
+
}
|
|
817
|
+
export function setPqcgovKeygenStuckMsV2(n) {
|
|
818
|
+
_pqcgovStuckMs = _pqcgovPos(n, "pqcgovKeygenStuckMs");
|
|
819
|
+
}
|
|
820
|
+
export function getPqcgovKeygenStuckMsV2() {
|
|
821
|
+
return _pqcgovStuckMs;
|
|
822
|
+
}
|
|
823
|
+
export function _resetStatePqcManagerGovV2() {
|
|
824
|
+
_pqcgovPsV2.clear();
|
|
825
|
+
_pqcgovJsV2.clear();
|
|
826
|
+
_pqcgovMaxActive = 6;
|
|
827
|
+
_pqcgovMaxPending = 12;
|
|
828
|
+
_pqcgovIdleMs = 30 * 24 * 60 * 60 * 1000;
|
|
829
|
+
_pqcgovStuckMs = 60 * 1000;
|
|
830
|
+
}
|
|
831
|
+
export function registerPqcgovProfileV2({
|
|
832
|
+
id,
|
|
833
|
+
owner,
|
|
834
|
+
algorithm,
|
|
835
|
+
metadata,
|
|
836
|
+
} = {}) {
|
|
837
|
+
if (!id || !owner) throw new Error("id and owner required");
|
|
838
|
+
if (_pqcgovPsV2.has(id))
|
|
839
|
+
throw new Error(`pqcgov profile ${id} already exists`);
|
|
840
|
+
const now = Date.now();
|
|
841
|
+
const p = {
|
|
842
|
+
id,
|
|
843
|
+
owner,
|
|
844
|
+
algorithm: algorithm || "kyber",
|
|
845
|
+
status: PQCGOV_PROFILE_MATURITY_V2.PENDING,
|
|
846
|
+
createdAt: now,
|
|
847
|
+
updatedAt: now,
|
|
848
|
+
lastTouchedAt: now,
|
|
849
|
+
activatedAt: null,
|
|
850
|
+
archivedAt: null,
|
|
851
|
+
metadata: { ...(metadata || {}) },
|
|
852
|
+
};
|
|
853
|
+
_pqcgovPsV2.set(id, p);
|
|
854
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
855
|
+
}
|
|
856
|
+
export function activatePqcgovProfileV2(id) {
|
|
857
|
+
const p = _pqcgovPsV2.get(id);
|
|
858
|
+
if (!p) throw new Error(`pqcgov profile ${id} not found`);
|
|
859
|
+
const isInitial = p.status === PQCGOV_PROFILE_MATURITY_V2.PENDING;
|
|
860
|
+
_pqcgovCheckP(p.status, PQCGOV_PROFILE_MATURITY_V2.ACTIVE);
|
|
861
|
+
if (isInitial && _pqcgovCountActive(p.owner) >= _pqcgovMaxActive)
|
|
862
|
+
throw new Error(`max active pqcgov profiles for owner ${p.owner} reached`);
|
|
863
|
+
const now = Date.now();
|
|
864
|
+
p.status = PQCGOV_PROFILE_MATURITY_V2.ACTIVE;
|
|
865
|
+
p.updatedAt = now;
|
|
866
|
+
p.lastTouchedAt = now;
|
|
867
|
+
if (!p.activatedAt) p.activatedAt = now;
|
|
868
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
869
|
+
}
|
|
870
|
+
export function deprecatePqcgovProfileV2(id) {
|
|
871
|
+
const p = _pqcgovPsV2.get(id);
|
|
872
|
+
if (!p) throw new Error(`pqcgov profile ${id} not found`);
|
|
873
|
+
_pqcgovCheckP(p.status, PQCGOV_PROFILE_MATURITY_V2.DEPRECATED);
|
|
874
|
+
p.status = PQCGOV_PROFILE_MATURITY_V2.DEPRECATED;
|
|
875
|
+
p.updatedAt = Date.now();
|
|
876
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
877
|
+
}
|
|
878
|
+
export function archivePqcgovProfileV2(id) {
|
|
879
|
+
const p = _pqcgovPsV2.get(id);
|
|
880
|
+
if (!p) throw new Error(`pqcgov profile ${id} not found`);
|
|
881
|
+
_pqcgovCheckP(p.status, PQCGOV_PROFILE_MATURITY_V2.ARCHIVED);
|
|
882
|
+
const now = Date.now();
|
|
883
|
+
p.status = PQCGOV_PROFILE_MATURITY_V2.ARCHIVED;
|
|
884
|
+
p.updatedAt = now;
|
|
885
|
+
if (!p.archivedAt) p.archivedAt = now;
|
|
886
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
887
|
+
}
|
|
888
|
+
export function touchPqcgovProfileV2(id) {
|
|
889
|
+
const p = _pqcgovPsV2.get(id);
|
|
890
|
+
if (!p) throw new Error(`pqcgov profile ${id} not found`);
|
|
891
|
+
if (_pqcgovPTerminal.has(p.status))
|
|
892
|
+
throw new Error(`cannot touch terminal pqcgov profile ${id}`);
|
|
893
|
+
const now = Date.now();
|
|
894
|
+
p.lastTouchedAt = now;
|
|
895
|
+
p.updatedAt = now;
|
|
896
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
897
|
+
}
|
|
898
|
+
export function getPqcgovProfileV2(id) {
|
|
899
|
+
const p = _pqcgovPsV2.get(id);
|
|
900
|
+
if (!p) return null;
|
|
901
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
902
|
+
}
|
|
903
|
+
export function listPqcgovProfilesV2() {
|
|
904
|
+
return [..._pqcgovPsV2.values()].map((p) => ({
|
|
905
|
+
...p,
|
|
906
|
+
metadata: { ...p.metadata },
|
|
907
|
+
}));
|
|
908
|
+
}
|
|
909
|
+
export function createPqcgovKeygenV2({
|
|
910
|
+
id,
|
|
911
|
+
profileId,
|
|
912
|
+
purpose,
|
|
913
|
+
metadata,
|
|
914
|
+
} = {}) {
|
|
915
|
+
if (!id || !profileId) throw new Error("id and profileId required");
|
|
916
|
+
if (_pqcgovJsV2.has(id))
|
|
917
|
+
throw new Error(`pqcgov keygen ${id} already exists`);
|
|
918
|
+
if (!_pqcgovPsV2.has(profileId))
|
|
919
|
+
throw new Error(`pqcgov profile ${profileId} not found`);
|
|
920
|
+
if (_pqcgovCountPending(profileId) >= _pqcgovMaxPending)
|
|
921
|
+
throw new Error(
|
|
922
|
+
`max pending pqcgov keygens for profile ${profileId} reached`,
|
|
923
|
+
);
|
|
924
|
+
const now = Date.now();
|
|
925
|
+
const j = {
|
|
926
|
+
id,
|
|
927
|
+
profileId,
|
|
928
|
+
purpose: purpose || "",
|
|
929
|
+
status: PQCGOV_KEYGEN_LIFECYCLE_V2.QUEUED,
|
|
930
|
+
createdAt: now,
|
|
931
|
+
updatedAt: now,
|
|
932
|
+
startedAt: null,
|
|
933
|
+
settledAt: null,
|
|
934
|
+
metadata: { ...(metadata || {}) },
|
|
935
|
+
};
|
|
936
|
+
_pqcgovJsV2.set(id, j);
|
|
937
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
938
|
+
}
|
|
939
|
+
export function generatingPqcgovKeygenV2(id) {
|
|
940
|
+
const j = _pqcgovJsV2.get(id);
|
|
941
|
+
if (!j) throw new Error(`pqcgov keygen ${id} not found`);
|
|
942
|
+
_pqcgovCheckJ(j.status, PQCGOV_KEYGEN_LIFECYCLE_V2.GENERATING);
|
|
943
|
+
const now = Date.now();
|
|
944
|
+
j.status = PQCGOV_KEYGEN_LIFECYCLE_V2.GENERATING;
|
|
945
|
+
j.updatedAt = now;
|
|
946
|
+
if (!j.startedAt) j.startedAt = now;
|
|
947
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
948
|
+
}
|
|
949
|
+
export function completeKeygenPqcgovV2(id) {
|
|
950
|
+
const j = _pqcgovJsV2.get(id);
|
|
951
|
+
if (!j) throw new Error(`pqcgov keygen ${id} not found`);
|
|
952
|
+
_pqcgovCheckJ(j.status, PQCGOV_KEYGEN_LIFECYCLE_V2.GENERATED);
|
|
953
|
+
const now = Date.now();
|
|
954
|
+
j.status = PQCGOV_KEYGEN_LIFECYCLE_V2.GENERATED;
|
|
955
|
+
j.updatedAt = now;
|
|
956
|
+
if (!j.settledAt) j.settledAt = now;
|
|
957
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
958
|
+
}
|
|
959
|
+
export function failPqcgovKeygenV2(id, reason) {
|
|
960
|
+
const j = _pqcgovJsV2.get(id);
|
|
961
|
+
if (!j) throw new Error(`pqcgov keygen ${id} not found`);
|
|
962
|
+
_pqcgovCheckJ(j.status, PQCGOV_KEYGEN_LIFECYCLE_V2.FAILED);
|
|
963
|
+
const now = Date.now();
|
|
964
|
+
j.status = PQCGOV_KEYGEN_LIFECYCLE_V2.FAILED;
|
|
965
|
+
j.updatedAt = now;
|
|
966
|
+
if (!j.settledAt) j.settledAt = now;
|
|
967
|
+
if (reason) j.metadata.failReason = String(reason);
|
|
968
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
969
|
+
}
|
|
970
|
+
export function cancelPqcgovKeygenV2(id, reason) {
|
|
971
|
+
const j = _pqcgovJsV2.get(id);
|
|
972
|
+
if (!j) throw new Error(`pqcgov keygen ${id} not found`);
|
|
973
|
+
_pqcgovCheckJ(j.status, PQCGOV_KEYGEN_LIFECYCLE_V2.CANCELLED);
|
|
974
|
+
const now = Date.now();
|
|
975
|
+
j.status = PQCGOV_KEYGEN_LIFECYCLE_V2.CANCELLED;
|
|
976
|
+
j.updatedAt = now;
|
|
977
|
+
if (!j.settledAt) j.settledAt = now;
|
|
978
|
+
if (reason) j.metadata.cancelReason = String(reason);
|
|
979
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
980
|
+
}
|
|
981
|
+
export function getPqcgovKeygenV2(id) {
|
|
982
|
+
const j = _pqcgovJsV2.get(id);
|
|
983
|
+
if (!j) return null;
|
|
984
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
985
|
+
}
|
|
986
|
+
export function listPqcgovKeygensV2() {
|
|
987
|
+
return [..._pqcgovJsV2.values()].map((j) => ({
|
|
988
|
+
...j,
|
|
989
|
+
metadata: { ...j.metadata },
|
|
990
|
+
}));
|
|
991
|
+
}
|
|
992
|
+
export function autoDeprecateIdlePqcgovProfilesV2({ now } = {}) {
|
|
993
|
+
const t = now ?? Date.now();
|
|
994
|
+
const flipped = [];
|
|
995
|
+
for (const p of _pqcgovPsV2.values())
|
|
996
|
+
if (
|
|
997
|
+
p.status === PQCGOV_PROFILE_MATURITY_V2.ACTIVE &&
|
|
998
|
+
t - p.lastTouchedAt >= _pqcgovIdleMs
|
|
999
|
+
) {
|
|
1000
|
+
p.status = PQCGOV_PROFILE_MATURITY_V2.DEPRECATED;
|
|
1001
|
+
p.updatedAt = t;
|
|
1002
|
+
flipped.push(p.id);
|
|
1003
|
+
}
|
|
1004
|
+
return { flipped, count: flipped.length };
|
|
1005
|
+
}
|
|
1006
|
+
export function autoFailStuckPqcgovKeygensV2({ now } = {}) {
|
|
1007
|
+
const t = now ?? Date.now();
|
|
1008
|
+
const flipped = [];
|
|
1009
|
+
for (const j of _pqcgovJsV2.values())
|
|
1010
|
+
if (
|
|
1011
|
+
j.status === PQCGOV_KEYGEN_LIFECYCLE_V2.GENERATING &&
|
|
1012
|
+
j.startedAt != null &&
|
|
1013
|
+
t - j.startedAt >= _pqcgovStuckMs
|
|
1014
|
+
) {
|
|
1015
|
+
j.status = PQCGOV_KEYGEN_LIFECYCLE_V2.FAILED;
|
|
1016
|
+
j.updatedAt = t;
|
|
1017
|
+
if (!j.settledAt) j.settledAt = t;
|
|
1018
|
+
j.metadata.failReason = "auto-fail-stuck";
|
|
1019
|
+
flipped.push(j.id);
|
|
1020
|
+
}
|
|
1021
|
+
return { flipped, count: flipped.length };
|
|
1022
|
+
}
|
|
1023
|
+
export function getPqcManagerGovStatsV2() {
|
|
1024
|
+
const profilesByStatus = {};
|
|
1025
|
+
for (const v of Object.values(PQCGOV_PROFILE_MATURITY_V2))
|
|
1026
|
+
profilesByStatus[v] = 0;
|
|
1027
|
+
for (const p of _pqcgovPsV2.values()) profilesByStatus[p.status]++;
|
|
1028
|
+
const keygensByStatus = {};
|
|
1029
|
+
for (const v of Object.values(PQCGOV_KEYGEN_LIFECYCLE_V2))
|
|
1030
|
+
keygensByStatus[v] = 0;
|
|
1031
|
+
for (const j of _pqcgovJsV2.values()) keygensByStatus[j.status]++;
|
|
1032
|
+
return {
|
|
1033
|
+
totalPqcgovProfilesV2: _pqcgovPsV2.size,
|
|
1034
|
+
totalPqcgovKeygensV2: _pqcgovJsV2.size,
|
|
1035
|
+
maxActivePqcgovProfilesPerOwner: _pqcgovMaxActive,
|
|
1036
|
+
maxPendingPqcgovKeygensPerProfile: _pqcgovMaxPending,
|
|
1037
|
+
pqcgovProfileIdleMs: _pqcgovIdleMs,
|
|
1038
|
+
pqcgovKeygenStuckMs: _pqcgovStuckMs,
|
|
1039
|
+
profilesByStatus,
|
|
1040
|
+
keygensByStatus,
|
|
1041
|
+
};
|
|
1042
|
+
}
|
|
@@ -147,3 +147,339 @@ function searchDir(dir, extension, results) {
|
|
|
147
147
|
}
|
|
148
148
|
}
|
|
149
149
|
}
|
|
150
|
+
|
|
151
|
+
// =====================================================================
|
|
152
|
+
// process-manager V2 governance overlay (iter27)
|
|
153
|
+
// =====================================================================
|
|
154
|
+
export const PMGRGOV_PROFILE_MATURITY_V2 = Object.freeze({
|
|
155
|
+
PENDING: "pending",
|
|
156
|
+
ACTIVE: "active",
|
|
157
|
+
STOPPED: "stopped",
|
|
158
|
+
ARCHIVED: "archived",
|
|
159
|
+
});
|
|
160
|
+
export const PMGRGOV_PROC_LIFECYCLE_V2 = Object.freeze({
|
|
161
|
+
QUEUED: "queued",
|
|
162
|
+
STARTING: "starting",
|
|
163
|
+
RUNNING: "running",
|
|
164
|
+
FAILED: "failed",
|
|
165
|
+
CANCELLED: "cancelled",
|
|
166
|
+
});
|
|
167
|
+
const _pmgrgovPTrans = new Map([
|
|
168
|
+
[
|
|
169
|
+
PMGRGOV_PROFILE_MATURITY_V2.PENDING,
|
|
170
|
+
new Set([
|
|
171
|
+
PMGRGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
172
|
+
PMGRGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
173
|
+
]),
|
|
174
|
+
],
|
|
175
|
+
[
|
|
176
|
+
PMGRGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
177
|
+
new Set([
|
|
178
|
+
PMGRGOV_PROFILE_MATURITY_V2.STOPPED,
|
|
179
|
+
PMGRGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
180
|
+
]),
|
|
181
|
+
],
|
|
182
|
+
[
|
|
183
|
+
PMGRGOV_PROFILE_MATURITY_V2.STOPPED,
|
|
184
|
+
new Set([
|
|
185
|
+
PMGRGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
186
|
+
PMGRGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
187
|
+
]),
|
|
188
|
+
],
|
|
189
|
+
[PMGRGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
|
|
190
|
+
]);
|
|
191
|
+
const _pmgrgovPTerminal = new Set([PMGRGOV_PROFILE_MATURITY_V2.ARCHIVED]);
|
|
192
|
+
const _pmgrgovJTrans = new Map([
|
|
193
|
+
[
|
|
194
|
+
PMGRGOV_PROC_LIFECYCLE_V2.QUEUED,
|
|
195
|
+
new Set([
|
|
196
|
+
PMGRGOV_PROC_LIFECYCLE_V2.STARTING,
|
|
197
|
+
PMGRGOV_PROC_LIFECYCLE_V2.CANCELLED,
|
|
198
|
+
]),
|
|
199
|
+
],
|
|
200
|
+
[
|
|
201
|
+
PMGRGOV_PROC_LIFECYCLE_V2.STARTING,
|
|
202
|
+
new Set([
|
|
203
|
+
PMGRGOV_PROC_LIFECYCLE_V2.RUNNING,
|
|
204
|
+
PMGRGOV_PROC_LIFECYCLE_V2.FAILED,
|
|
205
|
+
PMGRGOV_PROC_LIFECYCLE_V2.CANCELLED,
|
|
206
|
+
]),
|
|
207
|
+
],
|
|
208
|
+
[PMGRGOV_PROC_LIFECYCLE_V2.RUNNING, new Set()],
|
|
209
|
+
[PMGRGOV_PROC_LIFECYCLE_V2.FAILED, new Set()],
|
|
210
|
+
[PMGRGOV_PROC_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
211
|
+
]);
|
|
212
|
+
const _pmgrgovPsV2 = new Map();
|
|
213
|
+
const _pmgrgovJsV2 = new Map();
|
|
214
|
+
let _pmgrgovMaxActive = 8,
|
|
215
|
+
_pmgrgovMaxPending = 20,
|
|
216
|
+
_pmgrgovIdleMs = 30 * 24 * 60 * 60 * 1000,
|
|
217
|
+
_pmgrgovStuckMs = 60 * 1000;
|
|
218
|
+
function _pmgrgovPos(n, label) {
|
|
219
|
+
const v = Math.floor(Number(n));
|
|
220
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
221
|
+
throw new Error(`${label} must be positive integer`);
|
|
222
|
+
return v;
|
|
223
|
+
}
|
|
224
|
+
function _pmgrgovCheckP(from, to) {
|
|
225
|
+
const a = _pmgrgovPTrans.get(from);
|
|
226
|
+
if (!a || !a.has(to))
|
|
227
|
+
throw new Error(`invalid pmgrgov profile transition ${from} → ${to}`);
|
|
228
|
+
}
|
|
229
|
+
function _pmgrgovCheckJ(from, to) {
|
|
230
|
+
const a = _pmgrgovJTrans.get(from);
|
|
231
|
+
if (!a || !a.has(to))
|
|
232
|
+
throw new Error(`invalid pmgrgov proc transition ${from} → ${to}`);
|
|
233
|
+
}
|
|
234
|
+
function _pmgrgovCountActive(owner) {
|
|
235
|
+
let c = 0;
|
|
236
|
+
for (const p of _pmgrgovPsV2.values())
|
|
237
|
+
if (p.owner === owner && p.status === PMGRGOV_PROFILE_MATURITY_V2.ACTIVE)
|
|
238
|
+
c++;
|
|
239
|
+
return c;
|
|
240
|
+
}
|
|
241
|
+
function _pmgrgovCountPending(profileId) {
|
|
242
|
+
let c = 0;
|
|
243
|
+
for (const j of _pmgrgovJsV2.values())
|
|
244
|
+
if (
|
|
245
|
+
j.profileId === profileId &&
|
|
246
|
+
(j.status === PMGRGOV_PROC_LIFECYCLE_V2.QUEUED ||
|
|
247
|
+
j.status === PMGRGOV_PROC_LIFECYCLE_V2.STARTING)
|
|
248
|
+
)
|
|
249
|
+
c++;
|
|
250
|
+
return c;
|
|
251
|
+
}
|
|
252
|
+
export function setMaxActivePmgrgovProfilesPerOwnerV2(n) {
|
|
253
|
+
_pmgrgovMaxActive = _pmgrgovPos(n, "maxActivePmgrgovProfilesPerOwner");
|
|
254
|
+
}
|
|
255
|
+
export function getMaxActivePmgrgovProfilesPerOwnerV2() {
|
|
256
|
+
return _pmgrgovMaxActive;
|
|
257
|
+
}
|
|
258
|
+
export function setMaxPendingPmgrgovProcsPerProfileV2(n) {
|
|
259
|
+
_pmgrgovMaxPending = _pmgrgovPos(n, "maxPendingPmgrgovProcsPerProfile");
|
|
260
|
+
}
|
|
261
|
+
export function getMaxPendingPmgrgovProcsPerProfileV2() {
|
|
262
|
+
return _pmgrgovMaxPending;
|
|
263
|
+
}
|
|
264
|
+
export function setPmgrgovProfileIdleMsV2(n) {
|
|
265
|
+
_pmgrgovIdleMs = _pmgrgovPos(n, "pmgrgovProfileIdleMs");
|
|
266
|
+
}
|
|
267
|
+
export function getPmgrgovProfileIdleMsV2() {
|
|
268
|
+
return _pmgrgovIdleMs;
|
|
269
|
+
}
|
|
270
|
+
export function setPmgrgovProcStuckMsV2(n) {
|
|
271
|
+
_pmgrgovStuckMs = _pmgrgovPos(n, "pmgrgovProcStuckMs");
|
|
272
|
+
}
|
|
273
|
+
export function getPmgrgovProcStuckMsV2() {
|
|
274
|
+
return _pmgrgovStuckMs;
|
|
275
|
+
}
|
|
276
|
+
export function _resetStateProcessManagerGovV2() {
|
|
277
|
+
_pmgrgovPsV2.clear();
|
|
278
|
+
_pmgrgovJsV2.clear();
|
|
279
|
+
_pmgrgovMaxActive = 8;
|
|
280
|
+
_pmgrgovMaxPending = 20;
|
|
281
|
+
_pmgrgovIdleMs = 30 * 24 * 60 * 60 * 1000;
|
|
282
|
+
_pmgrgovStuckMs = 60 * 1000;
|
|
283
|
+
}
|
|
284
|
+
export function registerPmgrgovProfileV2({ id, owner, kind, metadata } = {}) {
|
|
285
|
+
if (!id || !owner) throw new Error("id and owner required");
|
|
286
|
+
if (_pmgrgovPsV2.has(id))
|
|
287
|
+
throw new Error(`pmgrgov profile ${id} already exists`);
|
|
288
|
+
const now = Date.now();
|
|
289
|
+
const p = {
|
|
290
|
+
id,
|
|
291
|
+
owner,
|
|
292
|
+
kind: kind || "service",
|
|
293
|
+
status: PMGRGOV_PROFILE_MATURITY_V2.PENDING,
|
|
294
|
+
createdAt: now,
|
|
295
|
+
updatedAt: now,
|
|
296
|
+
lastTouchedAt: now,
|
|
297
|
+
activatedAt: null,
|
|
298
|
+
archivedAt: null,
|
|
299
|
+
metadata: { ...(metadata || {}) },
|
|
300
|
+
};
|
|
301
|
+
_pmgrgovPsV2.set(id, p);
|
|
302
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
303
|
+
}
|
|
304
|
+
export function activatePmgrgovProfileV2(id) {
|
|
305
|
+
const p = _pmgrgovPsV2.get(id);
|
|
306
|
+
if (!p) throw new Error(`pmgrgov profile ${id} not found`);
|
|
307
|
+
const isInitial = p.status === PMGRGOV_PROFILE_MATURITY_V2.PENDING;
|
|
308
|
+
_pmgrgovCheckP(p.status, PMGRGOV_PROFILE_MATURITY_V2.ACTIVE);
|
|
309
|
+
if (isInitial && _pmgrgovCountActive(p.owner) >= _pmgrgovMaxActive)
|
|
310
|
+
throw new Error(`max active pmgrgov profiles for owner ${p.owner} reached`);
|
|
311
|
+
const now = Date.now();
|
|
312
|
+
p.status = PMGRGOV_PROFILE_MATURITY_V2.ACTIVE;
|
|
313
|
+
p.updatedAt = now;
|
|
314
|
+
p.lastTouchedAt = now;
|
|
315
|
+
if (!p.activatedAt) p.activatedAt = now;
|
|
316
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
317
|
+
}
|
|
318
|
+
export function stopPmgrgovProfileV2(id) {
|
|
319
|
+
const p = _pmgrgovPsV2.get(id);
|
|
320
|
+
if (!p) throw new Error(`pmgrgov profile ${id} not found`);
|
|
321
|
+
_pmgrgovCheckP(p.status, PMGRGOV_PROFILE_MATURITY_V2.STOPPED);
|
|
322
|
+
p.status = PMGRGOV_PROFILE_MATURITY_V2.STOPPED;
|
|
323
|
+
p.updatedAt = Date.now();
|
|
324
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
325
|
+
}
|
|
326
|
+
export function archivePmgrgovProfileV2(id) {
|
|
327
|
+
const p = _pmgrgovPsV2.get(id);
|
|
328
|
+
if (!p) throw new Error(`pmgrgov profile ${id} not found`);
|
|
329
|
+
_pmgrgovCheckP(p.status, PMGRGOV_PROFILE_MATURITY_V2.ARCHIVED);
|
|
330
|
+
const now = Date.now();
|
|
331
|
+
p.status = PMGRGOV_PROFILE_MATURITY_V2.ARCHIVED;
|
|
332
|
+
p.updatedAt = now;
|
|
333
|
+
if (!p.archivedAt) p.archivedAt = now;
|
|
334
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
335
|
+
}
|
|
336
|
+
export function touchPmgrgovProfileV2(id) {
|
|
337
|
+
const p = _pmgrgovPsV2.get(id);
|
|
338
|
+
if (!p) throw new Error(`pmgrgov profile ${id} not found`);
|
|
339
|
+
if (_pmgrgovPTerminal.has(p.status))
|
|
340
|
+
throw new Error(`cannot touch terminal pmgrgov profile ${id}`);
|
|
341
|
+
const now = Date.now();
|
|
342
|
+
p.lastTouchedAt = now;
|
|
343
|
+
p.updatedAt = now;
|
|
344
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
345
|
+
}
|
|
346
|
+
export function getPmgrgovProfileV2(id) {
|
|
347
|
+
const p = _pmgrgovPsV2.get(id);
|
|
348
|
+
if (!p) return null;
|
|
349
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
350
|
+
}
|
|
351
|
+
export function listPmgrgovProfilesV2() {
|
|
352
|
+
return [..._pmgrgovPsV2.values()].map((p) => ({
|
|
353
|
+
...p,
|
|
354
|
+
metadata: { ...p.metadata },
|
|
355
|
+
}));
|
|
356
|
+
}
|
|
357
|
+
export function createPmgrgovProcV2({ id, profileId, command, metadata } = {}) {
|
|
358
|
+
if (!id || !profileId) throw new Error("id and profileId required");
|
|
359
|
+
if (_pmgrgovJsV2.has(id))
|
|
360
|
+
throw new Error(`pmgrgov proc ${id} already exists`);
|
|
361
|
+
if (!_pmgrgovPsV2.has(profileId))
|
|
362
|
+
throw new Error(`pmgrgov profile ${profileId} not found`);
|
|
363
|
+
if (_pmgrgovCountPending(profileId) >= _pmgrgovMaxPending)
|
|
364
|
+
throw new Error(
|
|
365
|
+
`max pending pmgrgov procs for profile ${profileId} reached`,
|
|
366
|
+
);
|
|
367
|
+
const now = Date.now();
|
|
368
|
+
const j = {
|
|
369
|
+
id,
|
|
370
|
+
profileId,
|
|
371
|
+
command: command || "",
|
|
372
|
+
status: PMGRGOV_PROC_LIFECYCLE_V2.QUEUED,
|
|
373
|
+
createdAt: now,
|
|
374
|
+
updatedAt: now,
|
|
375
|
+
startedAt: null,
|
|
376
|
+
settledAt: null,
|
|
377
|
+
metadata: { ...(metadata || {}) },
|
|
378
|
+
};
|
|
379
|
+
_pmgrgovJsV2.set(id, j);
|
|
380
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
381
|
+
}
|
|
382
|
+
export function startingPmgrgovProcV2(id) {
|
|
383
|
+
const j = _pmgrgovJsV2.get(id);
|
|
384
|
+
if (!j) throw new Error(`pmgrgov proc ${id} not found`);
|
|
385
|
+
_pmgrgovCheckJ(j.status, PMGRGOV_PROC_LIFECYCLE_V2.STARTING);
|
|
386
|
+
const now = Date.now();
|
|
387
|
+
j.status = PMGRGOV_PROC_LIFECYCLE_V2.STARTING;
|
|
388
|
+
j.updatedAt = now;
|
|
389
|
+
if (!j.startedAt) j.startedAt = now;
|
|
390
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
391
|
+
}
|
|
392
|
+
export function completeProcPmgrgovV2(id) {
|
|
393
|
+
const j = _pmgrgovJsV2.get(id);
|
|
394
|
+
if (!j) throw new Error(`pmgrgov proc ${id} not found`);
|
|
395
|
+
_pmgrgovCheckJ(j.status, PMGRGOV_PROC_LIFECYCLE_V2.RUNNING);
|
|
396
|
+
const now = Date.now();
|
|
397
|
+
j.status = PMGRGOV_PROC_LIFECYCLE_V2.RUNNING;
|
|
398
|
+
j.updatedAt = now;
|
|
399
|
+
if (!j.settledAt) j.settledAt = now;
|
|
400
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
401
|
+
}
|
|
402
|
+
export function failPmgrgovProcV2(id, reason) {
|
|
403
|
+
const j = _pmgrgovJsV2.get(id);
|
|
404
|
+
if (!j) throw new Error(`pmgrgov proc ${id} not found`);
|
|
405
|
+
_pmgrgovCheckJ(j.status, PMGRGOV_PROC_LIFECYCLE_V2.FAILED);
|
|
406
|
+
const now = Date.now();
|
|
407
|
+
j.status = PMGRGOV_PROC_LIFECYCLE_V2.FAILED;
|
|
408
|
+
j.updatedAt = now;
|
|
409
|
+
if (!j.settledAt) j.settledAt = now;
|
|
410
|
+
if (reason) j.metadata.failReason = String(reason);
|
|
411
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
412
|
+
}
|
|
413
|
+
export function cancelPmgrgovProcV2(id, reason) {
|
|
414
|
+
const j = _pmgrgovJsV2.get(id);
|
|
415
|
+
if (!j) throw new Error(`pmgrgov proc ${id} not found`);
|
|
416
|
+
_pmgrgovCheckJ(j.status, PMGRGOV_PROC_LIFECYCLE_V2.CANCELLED);
|
|
417
|
+
const now = Date.now();
|
|
418
|
+
j.status = PMGRGOV_PROC_LIFECYCLE_V2.CANCELLED;
|
|
419
|
+
j.updatedAt = now;
|
|
420
|
+
if (!j.settledAt) j.settledAt = now;
|
|
421
|
+
if (reason) j.metadata.cancelReason = String(reason);
|
|
422
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
423
|
+
}
|
|
424
|
+
export function getPmgrgovProcV2(id) {
|
|
425
|
+
const j = _pmgrgovJsV2.get(id);
|
|
426
|
+
if (!j) return null;
|
|
427
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
428
|
+
}
|
|
429
|
+
export function listPmgrgovProcsV2() {
|
|
430
|
+
return [..._pmgrgovJsV2.values()].map((j) => ({
|
|
431
|
+
...j,
|
|
432
|
+
metadata: { ...j.metadata },
|
|
433
|
+
}));
|
|
434
|
+
}
|
|
435
|
+
export function autoStopIdlePmgrgovProfilesV2({ now } = {}) {
|
|
436
|
+
const t = now ?? Date.now();
|
|
437
|
+
const flipped = [];
|
|
438
|
+
for (const p of _pmgrgovPsV2.values())
|
|
439
|
+
if (
|
|
440
|
+
p.status === PMGRGOV_PROFILE_MATURITY_V2.ACTIVE &&
|
|
441
|
+
t - p.lastTouchedAt >= _pmgrgovIdleMs
|
|
442
|
+
) {
|
|
443
|
+
p.status = PMGRGOV_PROFILE_MATURITY_V2.STOPPED;
|
|
444
|
+
p.updatedAt = t;
|
|
445
|
+
flipped.push(p.id);
|
|
446
|
+
}
|
|
447
|
+
return { flipped, count: flipped.length };
|
|
448
|
+
}
|
|
449
|
+
export function autoFailStuckPmgrgovProcsV2({ now } = {}) {
|
|
450
|
+
const t = now ?? Date.now();
|
|
451
|
+
const flipped = [];
|
|
452
|
+
for (const j of _pmgrgovJsV2.values())
|
|
453
|
+
if (
|
|
454
|
+
j.status === PMGRGOV_PROC_LIFECYCLE_V2.STARTING &&
|
|
455
|
+
j.startedAt != null &&
|
|
456
|
+
t - j.startedAt >= _pmgrgovStuckMs
|
|
457
|
+
) {
|
|
458
|
+
j.status = PMGRGOV_PROC_LIFECYCLE_V2.FAILED;
|
|
459
|
+
j.updatedAt = t;
|
|
460
|
+
if (!j.settledAt) j.settledAt = t;
|
|
461
|
+
j.metadata.failReason = "auto-fail-stuck";
|
|
462
|
+
flipped.push(j.id);
|
|
463
|
+
}
|
|
464
|
+
return { flipped, count: flipped.length };
|
|
465
|
+
}
|
|
466
|
+
export function getProcessManagerGovStatsV2() {
|
|
467
|
+
const profilesByStatus = {};
|
|
468
|
+
for (const v of Object.values(PMGRGOV_PROFILE_MATURITY_V2))
|
|
469
|
+
profilesByStatus[v] = 0;
|
|
470
|
+
for (const p of _pmgrgovPsV2.values()) profilesByStatus[p.status]++;
|
|
471
|
+
const procsByStatus = {};
|
|
472
|
+
for (const v of Object.values(PMGRGOV_PROC_LIFECYCLE_V2))
|
|
473
|
+
procsByStatus[v] = 0;
|
|
474
|
+
for (const j of _pmgrgovJsV2.values()) procsByStatus[j.status]++;
|
|
475
|
+
return {
|
|
476
|
+
totalPmgrgovProfilesV2: _pmgrgovPsV2.size,
|
|
477
|
+
totalPmgrgovProcsV2: _pmgrgovJsV2.size,
|
|
478
|
+
maxActivePmgrgovProfilesPerOwner: _pmgrgovMaxActive,
|
|
479
|
+
maxPendingPmgrgovProcsPerProfile: _pmgrgovMaxPending,
|
|
480
|
+
pmgrgovProfileIdleMs: _pmgrgovIdleMs,
|
|
481
|
+
pmgrgovProcStuckMs: _pmgrgovStuckMs,
|
|
482
|
+
profilesByStatus,
|
|
483
|
+
procsByStatus,
|
|
484
|
+
};
|
|
485
|
+
}
|