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
|
@@ -844,3 +844,343 @@ export function getFederationHardeningStatsV2(db) {
|
|
|
844
844
|
healthByMetric,
|
|
845
845
|
};
|
|
846
846
|
}
|
|
847
|
+
|
|
848
|
+
// =====================================================================
|
|
849
|
+
// federation-hardening V2 governance overlay (iter20)
|
|
850
|
+
// =====================================================================
|
|
851
|
+
export const FEDGOV_PROFILE_MATURITY_V2 = Object.freeze({
|
|
852
|
+
PENDING: "pending",
|
|
853
|
+
ACTIVE: "active",
|
|
854
|
+
DEGRADED: "degraded",
|
|
855
|
+
ARCHIVED: "archived",
|
|
856
|
+
});
|
|
857
|
+
export const FEDGOV_PROBE_LIFECYCLE_V2 = Object.freeze({
|
|
858
|
+
QUEUED: "queued",
|
|
859
|
+
PROBING: "probing",
|
|
860
|
+
PROBED: "probed",
|
|
861
|
+
FAILED: "failed",
|
|
862
|
+
CANCELLED: "cancelled",
|
|
863
|
+
});
|
|
864
|
+
const _fedgovPTrans = new Map([
|
|
865
|
+
[
|
|
866
|
+
FEDGOV_PROFILE_MATURITY_V2.PENDING,
|
|
867
|
+
new Set([
|
|
868
|
+
FEDGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
869
|
+
FEDGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
870
|
+
]),
|
|
871
|
+
],
|
|
872
|
+
[
|
|
873
|
+
FEDGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
874
|
+
new Set([
|
|
875
|
+
FEDGOV_PROFILE_MATURITY_V2.DEGRADED,
|
|
876
|
+
FEDGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
877
|
+
]),
|
|
878
|
+
],
|
|
879
|
+
[
|
|
880
|
+
FEDGOV_PROFILE_MATURITY_V2.DEGRADED,
|
|
881
|
+
new Set([
|
|
882
|
+
FEDGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
883
|
+
FEDGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
884
|
+
]),
|
|
885
|
+
],
|
|
886
|
+
[FEDGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
|
|
887
|
+
]);
|
|
888
|
+
const _fedgovPTerminal = new Set([FEDGOV_PROFILE_MATURITY_V2.ARCHIVED]);
|
|
889
|
+
const _fedgovJTrans = new Map([
|
|
890
|
+
[
|
|
891
|
+
FEDGOV_PROBE_LIFECYCLE_V2.QUEUED,
|
|
892
|
+
new Set([
|
|
893
|
+
FEDGOV_PROBE_LIFECYCLE_V2.PROBING,
|
|
894
|
+
FEDGOV_PROBE_LIFECYCLE_V2.CANCELLED,
|
|
895
|
+
]),
|
|
896
|
+
],
|
|
897
|
+
[
|
|
898
|
+
FEDGOV_PROBE_LIFECYCLE_V2.PROBING,
|
|
899
|
+
new Set([
|
|
900
|
+
FEDGOV_PROBE_LIFECYCLE_V2.PROBED,
|
|
901
|
+
FEDGOV_PROBE_LIFECYCLE_V2.FAILED,
|
|
902
|
+
FEDGOV_PROBE_LIFECYCLE_V2.CANCELLED,
|
|
903
|
+
]),
|
|
904
|
+
],
|
|
905
|
+
[FEDGOV_PROBE_LIFECYCLE_V2.PROBED, new Set()],
|
|
906
|
+
[FEDGOV_PROBE_LIFECYCLE_V2.FAILED, new Set()],
|
|
907
|
+
[FEDGOV_PROBE_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
908
|
+
]);
|
|
909
|
+
const _fedgovPsV2 = new Map();
|
|
910
|
+
const _fedgovJsV2 = new Map();
|
|
911
|
+
let _fedgovMaxActive = 8,
|
|
912
|
+
_fedgovMaxPending = 20,
|
|
913
|
+
_fedgovIdleMs = 30 * 24 * 60 * 60 * 1000,
|
|
914
|
+
_fedgovStuckMs = 60 * 1000;
|
|
915
|
+
function _fedgovPos(n, label) {
|
|
916
|
+
const v = Math.floor(Number(n));
|
|
917
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
918
|
+
throw new Error(`${label} must be positive integer`);
|
|
919
|
+
return v;
|
|
920
|
+
}
|
|
921
|
+
function _fedgovCheckP(from, to) {
|
|
922
|
+
const a = _fedgovPTrans.get(from);
|
|
923
|
+
if (!a || !a.has(to))
|
|
924
|
+
throw new Error(`invalid fedgov profile transition ${from} → ${to}`);
|
|
925
|
+
}
|
|
926
|
+
function _fedgovCheckJ(from, to) {
|
|
927
|
+
const a = _fedgovJTrans.get(from);
|
|
928
|
+
if (!a || !a.has(to))
|
|
929
|
+
throw new Error(`invalid fedgov probe transition ${from} → ${to}`);
|
|
930
|
+
}
|
|
931
|
+
function _fedgovCountActive(owner) {
|
|
932
|
+
let c = 0;
|
|
933
|
+
for (const p of _fedgovPsV2.values())
|
|
934
|
+
if (p.owner === owner && p.status === FEDGOV_PROFILE_MATURITY_V2.ACTIVE)
|
|
935
|
+
c++;
|
|
936
|
+
return c;
|
|
937
|
+
}
|
|
938
|
+
function _fedgovCountPending(profileId) {
|
|
939
|
+
let c = 0;
|
|
940
|
+
for (const j of _fedgovJsV2.values())
|
|
941
|
+
if (
|
|
942
|
+
j.profileId === profileId &&
|
|
943
|
+
(j.status === FEDGOV_PROBE_LIFECYCLE_V2.QUEUED ||
|
|
944
|
+
j.status === FEDGOV_PROBE_LIFECYCLE_V2.PROBING)
|
|
945
|
+
)
|
|
946
|
+
c++;
|
|
947
|
+
return c;
|
|
948
|
+
}
|
|
949
|
+
export function setMaxActiveFedgovProfilesPerOwnerV2(n) {
|
|
950
|
+
_fedgovMaxActive = _fedgovPos(n, "maxActiveFedgovProfilesPerOwner");
|
|
951
|
+
}
|
|
952
|
+
export function getMaxActiveFedgovProfilesPerOwnerV2() {
|
|
953
|
+
return _fedgovMaxActive;
|
|
954
|
+
}
|
|
955
|
+
export function setMaxPendingFedgovProbesPerProfileV2(n) {
|
|
956
|
+
_fedgovMaxPending = _fedgovPos(n, "maxPendingFedgovProbesPerProfile");
|
|
957
|
+
}
|
|
958
|
+
export function getMaxPendingFedgovProbesPerProfileV2() {
|
|
959
|
+
return _fedgovMaxPending;
|
|
960
|
+
}
|
|
961
|
+
export function setFedgovProfileIdleMsV2(n) {
|
|
962
|
+
_fedgovIdleMs = _fedgovPos(n, "fedgovProfileIdleMs");
|
|
963
|
+
}
|
|
964
|
+
export function getFedgovProfileIdleMsV2() {
|
|
965
|
+
return _fedgovIdleMs;
|
|
966
|
+
}
|
|
967
|
+
export function setFedgovProbeStuckMsV2(n) {
|
|
968
|
+
_fedgovStuckMs = _fedgovPos(n, "fedgovProbeStuckMs");
|
|
969
|
+
}
|
|
970
|
+
export function getFedgovProbeStuckMsV2() {
|
|
971
|
+
return _fedgovStuckMs;
|
|
972
|
+
}
|
|
973
|
+
export function _resetStateFederationHardeningGovV2() {
|
|
974
|
+
_fedgovPsV2.clear();
|
|
975
|
+
_fedgovJsV2.clear();
|
|
976
|
+
_fedgovMaxActive = 8;
|
|
977
|
+
_fedgovMaxPending = 20;
|
|
978
|
+
_fedgovIdleMs = 30 * 24 * 60 * 60 * 1000;
|
|
979
|
+
_fedgovStuckMs = 60 * 1000;
|
|
980
|
+
}
|
|
981
|
+
export function registerFedgovProfileV2({ id, owner, region, metadata } = {}) {
|
|
982
|
+
if (!id || !owner) throw new Error("id and owner required");
|
|
983
|
+
if (_fedgovPsV2.has(id))
|
|
984
|
+
throw new Error(`fedgov profile ${id} already exists`);
|
|
985
|
+
const now = Date.now();
|
|
986
|
+
const p = {
|
|
987
|
+
id,
|
|
988
|
+
owner,
|
|
989
|
+
region: region || "default",
|
|
990
|
+
status: FEDGOV_PROFILE_MATURITY_V2.PENDING,
|
|
991
|
+
createdAt: now,
|
|
992
|
+
updatedAt: now,
|
|
993
|
+
lastTouchedAt: now,
|
|
994
|
+
activatedAt: null,
|
|
995
|
+
archivedAt: null,
|
|
996
|
+
metadata: { ...(metadata || {}) },
|
|
997
|
+
};
|
|
998
|
+
_fedgovPsV2.set(id, p);
|
|
999
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1000
|
+
}
|
|
1001
|
+
export function activateFedgovProfileV2(id) {
|
|
1002
|
+
const p = _fedgovPsV2.get(id);
|
|
1003
|
+
if (!p) throw new Error(`fedgov profile ${id} not found`);
|
|
1004
|
+
const isInitial = p.status === FEDGOV_PROFILE_MATURITY_V2.PENDING;
|
|
1005
|
+
_fedgovCheckP(p.status, FEDGOV_PROFILE_MATURITY_V2.ACTIVE);
|
|
1006
|
+
if (isInitial && _fedgovCountActive(p.owner) >= _fedgovMaxActive)
|
|
1007
|
+
throw new Error(`max active fedgov profiles for owner ${p.owner} reached`);
|
|
1008
|
+
const now = Date.now();
|
|
1009
|
+
p.status = FEDGOV_PROFILE_MATURITY_V2.ACTIVE;
|
|
1010
|
+
p.updatedAt = now;
|
|
1011
|
+
p.lastTouchedAt = now;
|
|
1012
|
+
if (!p.activatedAt) p.activatedAt = now;
|
|
1013
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1014
|
+
}
|
|
1015
|
+
export function degradeFedgovProfileV2(id) {
|
|
1016
|
+
const p = _fedgovPsV2.get(id);
|
|
1017
|
+
if (!p) throw new Error(`fedgov profile ${id} not found`);
|
|
1018
|
+
_fedgovCheckP(p.status, FEDGOV_PROFILE_MATURITY_V2.DEGRADED);
|
|
1019
|
+
p.status = FEDGOV_PROFILE_MATURITY_V2.DEGRADED;
|
|
1020
|
+
p.updatedAt = Date.now();
|
|
1021
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1022
|
+
}
|
|
1023
|
+
export function archiveFedgovProfileV2(id) {
|
|
1024
|
+
const p = _fedgovPsV2.get(id);
|
|
1025
|
+
if (!p) throw new Error(`fedgov profile ${id} not found`);
|
|
1026
|
+
_fedgovCheckP(p.status, FEDGOV_PROFILE_MATURITY_V2.ARCHIVED);
|
|
1027
|
+
const now = Date.now();
|
|
1028
|
+
p.status = FEDGOV_PROFILE_MATURITY_V2.ARCHIVED;
|
|
1029
|
+
p.updatedAt = now;
|
|
1030
|
+
if (!p.archivedAt) p.archivedAt = now;
|
|
1031
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1032
|
+
}
|
|
1033
|
+
export function touchFedgovProfileV2(id) {
|
|
1034
|
+
const p = _fedgovPsV2.get(id);
|
|
1035
|
+
if (!p) throw new Error(`fedgov profile ${id} not found`);
|
|
1036
|
+
if (_fedgovPTerminal.has(p.status))
|
|
1037
|
+
throw new Error(`cannot touch terminal fedgov profile ${id}`);
|
|
1038
|
+
const now = Date.now();
|
|
1039
|
+
p.lastTouchedAt = now;
|
|
1040
|
+
p.updatedAt = now;
|
|
1041
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1042
|
+
}
|
|
1043
|
+
export function getFedgovProfileV2(id) {
|
|
1044
|
+
const p = _fedgovPsV2.get(id);
|
|
1045
|
+
if (!p) return null;
|
|
1046
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1047
|
+
}
|
|
1048
|
+
export function listFedgovProfilesV2() {
|
|
1049
|
+
return [..._fedgovPsV2.values()].map((p) => ({
|
|
1050
|
+
...p,
|
|
1051
|
+
metadata: { ...p.metadata },
|
|
1052
|
+
}));
|
|
1053
|
+
}
|
|
1054
|
+
export function createFedgovProbeV2({
|
|
1055
|
+
id,
|
|
1056
|
+
profileId,
|
|
1057
|
+
endpoint,
|
|
1058
|
+
metadata,
|
|
1059
|
+
} = {}) {
|
|
1060
|
+
if (!id || !profileId) throw new Error("id and profileId required");
|
|
1061
|
+
if (_fedgovJsV2.has(id)) throw new Error(`fedgov probe ${id} already exists`);
|
|
1062
|
+
if (!_fedgovPsV2.has(profileId))
|
|
1063
|
+
throw new Error(`fedgov profile ${profileId} not found`);
|
|
1064
|
+
if (_fedgovCountPending(profileId) >= _fedgovMaxPending)
|
|
1065
|
+
throw new Error(
|
|
1066
|
+
`max pending fedgov probes for profile ${profileId} reached`,
|
|
1067
|
+
);
|
|
1068
|
+
const now = Date.now();
|
|
1069
|
+
const j = {
|
|
1070
|
+
id,
|
|
1071
|
+
profileId,
|
|
1072
|
+
endpoint: endpoint || "",
|
|
1073
|
+
status: FEDGOV_PROBE_LIFECYCLE_V2.QUEUED,
|
|
1074
|
+
createdAt: now,
|
|
1075
|
+
updatedAt: now,
|
|
1076
|
+
startedAt: null,
|
|
1077
|
+
settledAt: null,
|
|
1078
|
+
metadata: { ...(metadata || {}) },
|
|
1079
|
+
};
|
|
1080
|
+
_fedgovJsV2.set(id, j);
|
|
1081
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1082
|
+
}
|
|
1083
|
+
export function probingFedgovProbeV2(id) {
|
|
1084
|
+
const j = _fedgovJsV2.get(id);
|
|
1085
|
+
if (!j) throw new Error(`fedgov probe ${id} not found`);
|
|
1086
|
+
_fedgovCheckJ(j.status, FEDGOV_PROBE_LIFECYCLE_V2.PROBING);
|
|
1087
|
+
const now = Date.now();
|
|
1088
|
+
j.status = FEDGOV_PROBE_LIFECYCLE_V2.PROBING;
|
|
1089
|
+
j.updatedAt = now;
|
|
1090
|
+
if (!j.startedAt) j.startedAt = now;
|
|
1091
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1092
|
+
}
|
|
1093
|
+
export function completeProbeFedgovV2(id) {
|
|
1094
|
+
const j = _fedgovJsV2.get(id);
|
|
1095
|
+
if (!j) throw new Error(`fedgov probe ${id} not found`);
|
|
1096
|
+
_fedgovCheckJ(j.status, FEDGOV_PROBE_LIFECYCLE_V2.PROBED);
|
|
1097
|
+
const now = Date.now();
|
|
1098
|
+
j.status = FEDGOV_PROBE_LIFECYCLE_V2.PROBED;
|
|
1099
|
+
j.updatedAt = now;
|
|
1100
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1101
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1102
|
+
}
|
|
1103
|
+
export function failFedgovProbeV2(id, reason) {
|
|
1104
|
+
const j = _fedgovJsV2.get(id);
|
|
1105
|
+
if (!j) throw new Error(`fedgov probe ${id} not found`);
|
|
1106
|
+
_fedgovCheckJ(j.status, FEDGOV_PROBE_LIFECYCLE_V2.FAILED);
|
|
1107
|
+
const now = Date.now();
|
|
1108
|
+
j.status = FEDGOV_PROBE_LIFECYCLE_V2.FAILED;
|
|
1109
|
+
j.updatedAt = now;
|
|
1110
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1111
|
+
if (reason) j.metadata.failReason = String(reason);
|
|
1112
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1113
|
+
}
|
|
1114
|
+
export function cancelFedgovProbeV2(id, reason) {
|
|
1115
|
+
const j = _fedgovJsV2.get(id);
|
|
1116
|
+
if (!j) throw new Error(`fedgov probe ${id} not found`);
|
|
1117
|
+
_fedgovCheckJ(j.status, FEDGOV_PROBE_LIFECYCLE_V2.CANCELLED);
|
|
1118
|
+
const now = Date.now();
|
|
1119
|
+
j.status = FEDGOV_PROBE_LIFECYCLE_V2.CANCELLED;
|
|
1120
|
+
j.updatedAt = now;
|
|
1121
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1122
|
+
if (reason) j.metadata.cancelReason = String(reason);
|
|
1123
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1124
|
+
}
|
|
1125
|
+
export function getFedgovProbeV2(id) {
|
|
1126
|
+
const j = _fedgovJsV2.get(id);
|
|
1127
|
+
if (!j) return null;
|
|
1128
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1129
|
+
}
|
|
1130
|
+
export function listFedgovProbesV2() {
|
|
1131
|
+
return [..._fedgovJsV2.values()].map((j) => ({
|
|
1132
|
+
...j,
|
|
1133
|
+
metadata: { ...j.metadata },
|
|
1134
|
+
}));
|
|
1135
|
+
}
|
|
1136
|
+
export function autoDegradeIdleFedgovProfilesV2({ now } = {}) {
|
|
1137
|
+
const t = now ?? Date.now();
|
|
1138
|
+
const flipped = [];
|
|
1139
|
+
for (const p of _fedgovPsV2.values())
|
|
1140
|
+
if (
|
|
1141
|
+
p.status === FEDGOV_PROFILE_MATURITY_V2.ACTIVE &&
|
|
1142
|
+
t - p.lastTouchedAt >= _fedgovIdleMs
|
|
1143
|
+
) {
|
|
1144
|
+
p.status = FEDGOV_PROFILE_MATURITY_V2.DEGRADED;
|
|
1145
|
+
p.updatedAt = t;
|
|
1146
|
+
flipped.push(p.id);
|
|
1147
|
+
}
|
|
1148
|
+
return { flipped, count: flipped.length };
|
|
1149
|
+
}
|
|
1150
|
+
export function autoFailStuckFedgovProbesV2({ now } = {}) {
|
|
1151
|
+
const t = now ?? Date.now();
|
|
1152
|
+
const flipped = [];
|
|
1153
|
+
for (const j of _fedgovJsV2.values())
|
|
1154
|
+
if (
|
|
1155
|
+
j.status === FEDGOV_PROBE_LIFECYCLE_V2.PROBING &&
|
|
1156
|
+
j.startedAt != null &&
|
|
1157
|
+
t - j.startedAt >= _fedgovStuckMs
|
|
1158
|
+
) {
|
|
1159
|
+
j.status = FEDGOV_PROBE_LIFECYCLE_V2.FAILED;
|
|
1160
|
+
j.updatedAt = t;
|
|
1161
|
+
if (!j.settledAt) j.settledAt = t;
|
|
1162
|
+
j.metadata.failReason = "auto-fail-stuck";
|
|
1163
|
+
flipped.push(j.id);
|
|
1164
|
+
}
|
|
1165
|
+
return { flipped, count: flipped.length };
|
|
1166
|
+
}
|
|
1167
|
+
export function getFederationHardeningGovStatsV2() {
|
|
1168
|
+
const profilesByStatus = {};
|
|
1169
|
+
for (const v of Object.values(FEDGOV_PROFILE_MATURITY_V2))
|
|
1170
|
+
profilesByStatus[v] = 0;
|
|
1171
|
+
for (const p of _fedgovPsV2.values()) profilesByStatus[p.status]++;
|
|
1172
|
+
const probesByStatus = {};
|
|
1173
|
+
for (const v of Object.values(FEDGOV_PROBE_LIFECYCLE_V2))
|
|
1174
|
+
probesByStatus[v] = 0;
|
|
1175
|
+
for (const j of _fedgovJsV2.values()) probesByStatus[j.status]++;
|
|
1176
|
+
return {
|
|
1177
|
+
totalFedgovProfilesV2: _fedgovPsV2.size,
|
|
1178
|
+
totalFedgovProbesV2: _fedgovJsV2.size,
|
|
1179
|
+
maxActiveFedgovProfilesPerOwner: _fedgovMaxActive,
|
|
1180
|
+
maxPendingFedgovProbesPerProfile: _fedgovMaxPending,
|
|
1181
|
+
fedgovProfileIdleMs: _fedgovIdleMs,
|
|
1182
|
+
fedgovProbeStuckMs: _fedgovStuckMs,
|
|
1183
|
+
profilesByStatus,
|
|
1184
|
+
probesByStatus,
|
|
1185
|
+
};
|
|
1186
|
+
}
|
package/src/lib/hashline.js
CHANGED
|
@@ -206,3 +206,341 @@ export const _internals = {
|
|
|
206
206
|
EMPTY_HASH,
|
|
207
207
|
SEPARATOR,
|
|
208
208
|
};
|
|
209
|
+
|
|
210
|
+
// =====================================================================
|
|
211
|
+
// hashline V2 governance overlay (iter26)
|
|
212
|
+
// =====================================================================
|
|
213
|
+
export const HLGOV_PROFILE_MATURITY_V2 = Object.freeze({
|
|
214
|
+
PENDING: "pending",
|
|
215
|
+
ACTIVE: "active",
|
|
216
|
+
STALE: "stale",
|
|
217
|
+
ARCHIVED: "archived",
|
|
218
|
+
});
|
|
219
|
+
export const HLGOV_DIGEST_LIFECYCLE_V2 = Object.freeze({
|
|
220
|
+
QUEUED: "queued",
|
|
221
|
+
HASHING: "hashing",
|
|
222
|
+
HASHED: "hashed",
|
|
223
|
+
FAILED: "failed",
|
|
224
|
+
CANCELLED: "cancelled",
|
|
225
|
+
});
|
|
226
|
+
const _hlgovPTrans = new Map([
|
|
227
|
+
[
|
|
228
|
+
HLGOV_PROFILE_MATURITY_V2.PENDING,
|
|
229
|
+
new Set([
|
|
230
|
+
HLGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
231
|
+
HLGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
232
|
+
]),
|
|
233
|
+
],
|
|
234
|
+
[
|
|
235
|
+
HLGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
236
|
+
new Set([
|
|
237
|
+
HLGOV_PROFILE_MATURITY_V2.STALE,
|
|
238
|
+
HLGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
239
|
+
]),
|
|
240
|
+
],
|
|
241
|
+
[
|
|
242
|
+
HLGOV_PROFILE_MATURITY_V2.STALE,
|
|
243
|
+
new Set([
|
|
244
|
+
HLGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
245
|
+
HLGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
246
|
+
]),
|
|
247
|
+
],
|
|
248
|
+
[HLGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
|
|
249
|
+
]);
|
|
250
|
+
const _hlgovPTerminal = new Set([HLGOV_PROFILE_MATURITY_V2.ARCHIVED]);
|
|
251
|
+
const _hlgovJTrans = new Map([
|
|
252
|
+
[
|
|
253
|
+
HLGOV_DIGEST_LIFECYCLE_V2.QUEUED,
|
|
254
|
+
new Set([
|
|
255
|
+
HLGOV_DIGEST_LIFECYCLE_V2.HASHING,
|
|
256
|
+
HLGOV_DIGEST_LIFECYCLE_V2.CANCELLED,
|
|
257
|
+
]),
|
|
258
|
+
],
|
|
259
|
+
[
|
|
260
|
+
HLGOV_DIGEST_LIFECYCLE_V2.HASHING,
|
|
261
|
+
new Set([
|
|
262
|
+
HLGOV_DIGEST_LIFECYCLE_V2.HASHED,
|
|
263
|
+
HLGOV_DIGEST_LIFECYCLE_V2.FAILED,
|
|
264
|
+
HLGOV_DIGEST_LIFECYCLE_V2.CANCELLED,
|
|
265
|
+
]),
|
|
266
|
+
],
|
|
267
|
+
[HLGOV_DIGEST_LIFECYCLE_V2.HASHED, new Set()],
|
|
268
|
+
[HLGOV_DIGEST_LIFECYCLE_V2.FAILED, new Set()],
|
|
269
|
+
[HLGOV_DIGEST_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
270
|
+
]);
|
|
271
|
+
const _hlgovPsV2 = new Map();
|
|
272
|
+
const _hlgovJsV2 = new Map();
|
|
273
|
+
let _hlgovMaxActive = 8,
|
|
274
|
+
_hlgovMaxPending = 20,
|
|
275
|
+
_hlgovIdleMs = 30 * 24 * 60 * 60 * 1000,
|
|
276
|
+
_hlgovStuckMs = 60 * 1000;
|
|
277
|
+
function _hlgovPos(n, label) {
|
|
278
|
+
const v = Math.floor(Number(n));
|
|
279
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
280
|
+
throw new Error(`${label} must be positive integer`);
|
|
281
|
+
return v;
|
|
282
|
+
}
|
|
283
|
+
function _hlgovCheckP(from, to) {
|
|
284
|
+
const a = _hlgovPTrans.get(from);
|
|
285
|
+
if (!a || !a.has(to))
|
|
286
|
+
throw new Error(`invalid hlgov profile transition ${from} → ${to}`);
|
|
287
|
+
}
|
|
288
|
+
function _hlgovCheckJ(from, to) {
|
|
289
|
+
const a = _hlgovJTrans.get(from);
|
|
290
|
+
if (!a || !a.has(to))
|
|
291
|
+
throw new Error(`invalid hlgov digest transition ${from} → ${to}`);
|
|
292
|
+
}
|
|
293
|
+
function _hlgovCountActive(owner) {
|
|
294
|
+
let c = 0;
|
|
295
|
+
for (const p of _hlgovPsV2.values())
|
|
296
|
+
if (p.owner === owner && p.status === HLGOV_PROFILE_MATURITY_V2.ACTIVE) c++;
|
|
297
|
+
return c;
|
|
298
|
+
}
|
|
299
|
+
function _hlgovCountPending(profileId) {
|
|
300
|
+
let c = 0;
|
|
301
|
+
for (const j of _hlgovJsV2.values())
|
|
302
|
+
if (
|
|
303
|
+
j.profileId === profileId &&
|
|
304
|
+
(j.status === HLGOV_DIGEST_LIFECYCLE_V2.QUEUED ||
|
|
305
|
+
j.status === HLGOV_DIGEST_LIFECYCLE_V2.HASHING)
|
|
306
|
+
)
|
|
307
|
+
c++;
|
|
308
|
+
return c;
|
|
309
|
+
}
|
|
310
|
+
export function setMaxActiveHlgovProfilesPerOwnerV2(n) {
|
|
311
|
+
_hlgovMaxActive = _hlgovPos(n, "maxActiveHlgovProfilesPerOwner");
|
|
312
|
+
}
|
|
313
|
+
export function getMaxActiveHlgovProfilesPerOwnerV2() {
|
|
314
|
+
return _hlgovMaxActive;
|
|
315
|
+
}
|
|
316
|
+
export function setMaxPendingHlgovDigestsPerProfileV2(n) {
|
|
317
|
+
_hlgovMaxPending = _hlgovPos(n, "maxPendingHlgovDigestsPerProfile");
|
|
318
|
+
}
|
|
319
|
+
export function getMaxPendingHlgovDigestsPerProfileV2() {
|
|
320
|
+
return _hlgovMaxPending;
|
|
321
|
+
}
|
|
322
|
+
export function setHlgovProfileIdleMsV2(n) {
|
|
323
|
+
_hlgovIdleMs = _hlgovPos(n, "hlgovProfileIdleMs");
|
|
324
|
+
}
|
|
325
|
+
export function getHlgovProfileIdleMsV2() {
|
|
326
|
+
return _hlgovIdleMs;
|
|
327
|
+
}
|
|
328
|
+
export function setHlgovDigestStuckMsV2(n) {
|
|
329
|
+
_hlgovStuckMs = _hlgovPos(n, "hlgovDigestStuckMs");
|
|
330
|
+
}
|
|
331
|
+
export function getHlgovDigestStuckMsV2() {
|
|
332
|
+
return _hlgovStuckMs;
|
|
333
|
+
}
|
|
334
|
+
export function _resetStateHashlineGovV2() {
|
|
335
|
+
_hlgovPsV2.clear();
|
|
336
|
+
_hlgovJsV2.clear();
|
|
337
|
+
_hlgovMaxActive = 8;
|
|
338
|
+
_hlgovMaxPending = 20;
|
|
339
|
+
_hlgovIdleMs = 30 * 24 * 60 * 60 * 1000;
|
|
340
|
+
_hlgovStuckMs = 60 * 1000;
|
|
341
|
+
}
|
|
342
|
+
export function registerHlgovProfileV2({
|
|
343
|
+
id,
|
|
344
|
+
owner,
|
|
345
|
+
algorithm,
|
|
346
|
+
metadata,
|
|
347
|
+
} = {}) {
|
|
348
|
+
if (!id || !owner) throw new Error("id and owner required");
|
|
349
|
+
if (_hlgovPsV2.has(id)) throw new Error(`hlgov profile ${id} already exists`);
|
|
350
|
+
const now = Date.now();
|
|
351
|
+
const p = {
|
|
352
|
+
id,
|
|
353
|
+
owner,
|
|
354
|
+
algorithm: algorithm || "sha256",
|
|
355
|
+
status: HLGOV_PROFILE_MATURITY_V2.PENDING,
|
|
356
|
+
createdAt: now,
|
|
357
|
+
updatedAt: now,
|
|
358
|
+
lastTouchedAt: now,
|
|
359
|
+
activatedAt: null,
|
|
360
|
+
archivedAt: null,
|
|
361
|
+
metadata: { ...(metadata || {}) },
|
|
362
|
+
};
|
|
363
|
+
_hlgovPsV2.set(id, p);
|
|
364
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
365
|
+
}
|
|
366
|
+
export function activateHlgovProfileV2(id) {
|
|
367
|
+
const p = _hlgovPsV2.get(id);
|
|
368
|
+
if (!p) throw new Error(`hlgov profile ${id} not found`);
|
|
369
|
+
const isInitial = p.status === HLGOV_PROFILE_MATURITY_V2.PENDING;
|
|
370
|
+
_hlgovCheckP(p.status, HLGOV_PROFILE_MATURITY_V2.ACTIVE);
|
|
371
|
+
if (isInitial && _hlgovCountActive(p.owner) >= _hlgovMaxActive)
|
|
372
|
+
throw new Error(`max active hlgov profiles for owner ${p.owner} reached`);
|
|
373
|
+
const now = Date.now();
|
|
374
|
+
p.status = HLGOV_PROFILE_MATURITY_V2.ACTIVE;
|
|
375
|
+
p.updatedAt = now;
|
|
376
|
+
p.lastTouchedAt = now;
|
|
377
|
+
if (!p.activatedAt) p.activatedAt = now;
|
|
378
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
379
|
+
}
|
|
380
|
+
export function staleHlgovProfileV2(id) {
|
|
381
|
+
const p = _hlgovPsV2.get(id);
|
|
382
|
+
if (!p) throw new Error(`hlgov profile ${id} not found`);
|
|
383
|
+
_hlgovCheckP(p.status, HLGOV_PROFILE_MATURITY_V2.STALE);
|
|
384
|
+
p.status = HLGOV_PROFILE_MATURITY_V2.STALE;
|
|
385
|
+
p.updatedAt = Date.now();
|
|
386
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
387
|
+
}
|
|
388
|
+
export function archiveHlgovProfileV2(id) {
|
|
389
|
+
const p = _hlgovPsV2.get(id);
|
|
390
|
+
if (!p) throw new Error(`hlgov profile ${id} not found`);
|
|
391
|
+
_hlgovCheckP(p.status, HLGOV_PROFILE_MATURITY_V2.ARCHIVED);
|
|
392
|
+
const now = Date.now();
|
|
393
|
+
p.status = HLGOV_PROFILE_MATURITY_V2.ARCHIVED;
|
|
394
|
+
p.updatedAt = now;
|
|
395
|
+
if (!p.archivedAt) p.archivedAt = now;
|
|
396
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
397
|
+
}
|
|
398
|
+
export function touchHlgovProfileV2(id) {
|
|
399
|
+
const p = _hlgovPsV2.get(id);
|
|
400
|
+
if (!p) throw new Error(`hlgov profile ${id} not found`);
|
|
401
|
+
if (_hlgovPTerminal.has(p.status))
|
|
402
|
+
throw new Error(`cannot touch terminal hlgov profile ${id}`);
|
|
403
|
+
const now = Date.now();
|
|
404
|
+
p.lastTouchedAt = now;
|
|
405
|
+
p.updatedAt = now;
|
|
406
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
407
|
+
}
|
|
408
|
+
export function getHlgovProfileV2(id) {
|
|
409
|
+
const p = _hlgovPsV2.get(id);
|
|
410
|
+
if (!p) return null;
|
|
411
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
412
|
+
}
|
|
413
|
+
export function listHlgovProfilesV2() {
|
|
414
|
+
return [..._hlgovPsV2.values()].map((p) => ({
|
|
415
|
+
...p,
|
|
416
|
+
metadata: { ...p.metadata },
|
|
417
|
+
}));
|
|
418
|
+
}
|
|
419
|
+
export function createHlgovDigestV2({ id, profileId, content, metadata } = {}) {
|
|
420
|
+
if (!id || !profileId) throw new Error("id and profileId required");
|
|
421
|
+
if (_hlgovJsV2.has(id)) throw new Error(`hlgov digest ${id} already exists`);
|
|
422
|
+
if (!_hlgovPsV2.has(profileId))
|
|
423
|
+
throw new Error(`hlgov profile ${profileId} not found`);
|
|
424
|
+
if (_hlgovCountPending(profileId) >= _hlgovMaxPending)
|
|
425
|
+
throw new Error(
|
|
426
|
+
`max pending hlgov digests for profile ${profileId} reached`,
|
|
427
|
+
);
|
|
428
|
+
const now = Date.now();
|
|
429
|
+
const j = {
|
|
430
|
+
id,
|
|
431
|
+
profileId,
|
|
432
|
+
content: content || "",
|
|
433
|
+
status: HLGOV_DIGEST_LIFECYCLE_V2.QUEUED,
|
|
434
|
+
createdAt: now,
|
|
435
|
+
updatedAt: now,
|
|
436
|
+
startedAt: null,
|
|
437
|
+
settledAt: null,
|
|
438
|
+
metadata: { ...(metadata || {}) },
|
|
439
|
+
};
|
|
440
|
+
_hlgovJsV2.set(id, j);
|
|
441
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
442
|
+
}
|
|
443
|
+
export function hashingHlgovDigestV2(id) {
|
|
444
|
+
const j = _hlgovJsV2.get(id);
|
|
445
|
+
if (!j) throw new Error(`hlgov digest ${id} not found`);
|
|
446
|
+
_hlgovCheckJ(j.status, HLGOV_DIGEST_LIFECYCLE_V2.HASHING);
|
|
447
|
+
const now = Date.now();
|
|
448
|
+
j.status = HLGOV_DIGEST_LIFECYCLE_V2.HASHING;
|
|
449
|
+
j.updatedAt = now;
|
|
450
|
+
if (!j.startedAt) j.startedAt = now;
|
|
451
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
452
|
+
}
|
|
453
|
+
export function completeDigestHlgovV2(id) {
|
|
454
|
+
const j = _hlgovJsV2.get(id);
|
|
455
|
+
if (!j) throw new Error(`hlgov digest ${id} not found`);
|
|
456
|
+
_hlgovCheckJ(j.status, HLGOV_DIGEST_LIFECYCLE_V2.HASHED);
|
|
457
|
+
const now = Date.now();
|
|
458
|
+
j.status = HLGOV_DIGEST_LIFECYCLE_V2.HASHED;
|
|
459
|
+
j.updatedAt = now;
|
|
460
|
+
if (!j.settledAt) j.settledAt = now;
|
|
461
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
462
|
+
}
|
|
463
|
+
export function failHlgovDigestV2(id, reason) {
|
|
464
|
+
const j = _hlgovJsV2.get(id);
|
|
465
|
+
if (!j) throw new Error(`hlgov digest ${id} not found`);
|
|
466
|
+
_hlgovCheckJ(j.status, HLGOV_DIGEST_LIFECYCLE_V2.FAILED);
|
|
467
|
+
const now = Date.now();
|
|
468
|
+
j.status = HLGOV_DIGEST_LIFECYCLE_V2.FAILED;
|
|
469
|
+
j.updatedAt = now;
|
|
470
|
+
if (!j.settledAt) j.settledAt = now;
|
|
471
|
+
if (reason) j.metadata.failReason = String(reason);
|
|
472
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
473
|
+
}
|
|
474
|
+
export function cancelHlgovDigestV2(id, reason) {
|
|
475
|
+
const j = _hlgovJsV2.get(id);
|
|
476
|
+
if (!j) throw new Error(`hlgov digest ${id} not found`);
|
|
477
|
+
_hlgovCheckJ(j.status, HLGOV_DIGEST_LIFECYCLE_V2.CANCELLED);
|
|
478
|
+
const now = Date.now();
|
|
479
|
+
j.status = HLGOV_DIGEST_LIFECYCLE_V2.CANCELLED;
|
|
480
|
+
j.updatedAt = now;
|
|
481
|
+
if (!j.settledAt) j.settledAt = now;
|
|
482
|
+
if (reason) j.metadata.cancelReason = String(reason);
|
|
483
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
484
|
+
}
|
|
485
|
+
export function getHlgovDigestV2(id) {
|
|
486
|
+
const j = _hlgovJsV2.get(id);
|
|
487
|
+
if (!j) return null;
|
|
488
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
489
|
+
}
|
|
490
|
+
export function listHlgovDigestsV2() {
|
|
491
|
+
return [..._hlgovJsV2.values()].map((j) => ({
|
|
492
|
+
...j,
|
|
493
|
+
metadata: { ...j.metadata },
|
|
494
|
+
}));
|
|
495
|
+
}
|
|
496
|
+
export function autoStaleIdleHlgovProfilesV2({ now } = {}) {
|
|
497
|
+
const t = now ?? Date.now();
|
|
498
|
+
const flipped = [];
|
|
499
|
+
for (const p of _hlgovPsV2.values())
|
|
500
|
+
if (
|
|
501
|
+
p.status === HLGOV_PROFILE_MATURITY_V2.ACTIVE &&
|
|
502
|
+
t - p.lastTouchedAt >= _hlgovIdleMs
|
|
503
|
+
) {
|
|
504
|
+
p.status = HLGOV_PROFILE_MATURITY_V2.STALE;
|
|
505
|
+
p.updatedAt = t;
|
|
506
|
+
flipped.push(p.id);
|
|
507
|
+
}
|
|
508
|
+
return { flipped, count: flipped.length };
|
|
509
|
+
}
|
|
510
|
+
export function autoFailStuckHlgovDigestsV2({ now } = {}) {
|
|
511
|
+
const t = now ?? Date.now();
|
|
512
|
+
const flipped = [];
|
|
513
|
+
for (const j of _hlgovJsV2.values())
|
|
514
|
+
if (
|
|
515
|
+
j.status === HLGOV_DIGEST_LIFECYCLE_V2.HASHING &&
|
|
516
|
+
j.startedAt != null &&
|
|
517
|
+
t - j.startedAt >= _hlgovStuckMs
|
|
518
|
+
) {
|
|
519
|
+
j.status = HLGOV_DIGEST_LIFECYCLE_V2.FAILED;
|
|
520
|
+
j.updatedAt = t;
|
|
521
|
+
if (!j.settledAt) j.settledAt = t;
|
|
522
|
+
j.metadata.failReason = "auto-fail-stuck";
|
|
523
|
+
flipped.push(j.id);
|
|
524
|
+
}
|
|
525
|
+
return { flipped, count: flipped.length };
|
|
526
|
+
}
|
|
527
|
+
export function getHashlineGovStatsV2() {
|
|
528
|
+
const profilesByStatus = {};
|
|
529
|
+
for (const v of Object.values(HLGOV_PROFILE_MATURITY_V2))
|
|
530
|
+
profilesByStatus[v] = 0;
|
|
531
|
+
for (const p of _hlgovPsV2.values()) profilesByStatus[p.status]++;
|
|
532
|
+
const digestsByStatus = {};
|
|
533
|
+
for (const v of Object.values(HLGOV_DIGEST_LIFECYCLE_V2))
|
|
534
|
+
digestsByStatus[v] = 0;
|
|
535
|
+
for (const j of _hlgovJsV2.values()) digestsByStatus[j.status]++;
|
|
536
|
+
return {
|
|
537
|
+
totalHlgovProfilesV2: _hlgovPsV2.size,
|
|
538
|
+
totalHlgovDigestsV2: _hlgovJsV2.size,
|
|
539
|
+
maxActiveHlgovProfilesPerOwner: _hlgovMaxActive,
|
|
540
|
+
maxPendingHlgovDigestsPerProfile: _hlgovMaxPending,
|
|
541
|
+
hlgovProfileIdleMs: _hlgovIdleMs,
|
|
542
|
+
hlgovDigestStuckMs: _hlgovStuckMs,
|
|
543
|
+
profilesByStatus,
|
|
544
|
+
digestsByStatus,
|
|
545
|
+
};
|
|
546
|
+
}
|