chainlesschain 0.66.0 → 0.132.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/bin/chainlesschain.js +0 -0
- package/package.json +1 -1
- package/src/commands/a2a.js +380 -0
- package/src/commands/agent-network.js +254 -1
- package/src/commands/audit.js +302 -0
- package/src/commands/automation.js +271 -1
- package/src/commands/bi.js +348 -0
- package/src/commands/codegen.js +224 -0
- package/src/commands/collab.js +341 -0
- package/src/commands/compliance.js +1035 -0
- package/src/commands/cowork.js +221 -0
- package/src/commands/crosschain.js +218 -0
- package/src/commands/dbevo.js +284 -0
- package/src/commands/dev.js +252 -0
- package/src/commands/did.js +358 -0
- package/src/commands/dlp.js +341 -0
- package/src/commands/encrypt.js +341 -0
- package/src/commands/evomap.js +394 -0
- package/src/commands/export.js +256 -1
- package/src/commands/federation.js +283 -0
- package/src/commands/fusion.js +258 -0
- package/src/commands/governance.js +325 -0
- package/src/commands/hardening.js +411 -0
- package/src/commands/hook.js +148 -0
- package/src/commands/import.js +252 -0
- package/src/commands/incentive.js +322 -0
- package/src/commands/inference.js +318 -0
- package/src/commands/infra.js +244 -0
- package/src/commands/instinct.js +260 -0
- package/src/commands/ipfs.js +318 -0
- package/src/commands/kg.js +387 -0
- package/src/commands/llm.js +263 -0
- package/src/commands/lowcode.js +356 -0
- package/src/commands/marketplace.js +256 -0
- package/src/commands/mcp.js +221 -0
- package/src/commands/memory.js +248 -0
- package/src/commands/multimodal.js +296 -0
- package/src/commands/nlprog.js +356 -0
- package/src/commands/note.js +244 -0
- package/src/commands/ops.js +354 -0
- package/src/commands/orchestrate.js +166 -0
- package/src/commands/org.js +277 -0
- package/src/commands/p2p.js +390 -0
- package/src/commands/perception.js +290 -0
- package/src/commands/permmem.js +251 -0
- package/src/commands/plugin-ecosystem.js +273 -0
- package/src/commands/pqc.js +393 -0
- package/src/commands/privacy.js +321 -0
- package/src/commands/quantization.js +351 -0
- package/src/commands/rcache.js +271 -0
- package/src/commands/recommend.js +340 -0
- package/src/commands/reputation.js +261 -0
- package/src/commands/runtime.js +307 -0
- package/src/commands/scim.js +262 -0
- package/src/commands/session.js +258 -0
- package/src/commands/siem.js +246 -0
- package/src/commands/skill.js +267 -1
- package/src/commands/sla.js +259 -0
- package/src/commands/social.js +256 -0
- package/src/commands/sso.js +186 -1
- package/src/commands/stress.js +230 -0
- package/src/commands/sync.js +256 -0
- package/src/commands/tech.js +338 -0
- package/src/commands/tenant.js +351 -0
- package/src/commands/terraform.js +245 -0
- package/src/commands/tokens.js +269 -0
- package/src/commands/trust.js +249 -0
- package/src/commands/wallet.js +277 -0
- package/src/commands/workflow.js +171 -0
- package/src/commands/zkp.js +335 -0
- package/src/index.js +4 -0
- package/src/lib/a2a-protocol.js +451 -0
- package/src/lib/agent-coordinator.js +325 -0
- package/src/lib/agent-network.js +387 -0
- package/src/lib/agent-router.js +395 -0
- package/src/lib/aiops.js +478 -0
- package/src/lib/app-builder.js +239 -0
- package/src/lib/audit-logger.js +379 -0
- package/src/lib/automation-engine.js +330 -0
- package/src/lib/autonomous-developer.js +350 -0
- package/src/lib/bi-engine.js +338 -0
- package/src/lib/code-agent.js +323 -0
- package/src/lib/collaboration-governance.js +364 -0
- package/src/lib/community-governance.js +436 -0
- package/src/lib/compliance-manager.js +434 -0
- package/src/lib/content-recommendation.js +469 -0
- package/src/lib/cross-chain.js +345 -0
- package/src/lib/crypto-manager.js +350 -0
- package/src/lib/dbevo.js +338 -0
- package/src/lib/decentral-infra.js +340 -0
- package/src/lib/did-manager.js +367 -0
- package/src/lib/dlp-engine.js +389 -0
- package/src/lib/evomap-federation.js +177 -0
- package/src/lib/evomap-governance.js +276 -0
- package/src/lib/federation-hardening.js +259 -0
- package/src/lib/hardening-manager.js +348 -0
- package/src/lib/hook-manager.js +380 -0
- package/src/lib/inference-network.js +330 -0
- package/src/lib/instinct-manager.js +332 -0
- package/src/lib/ipfs-storage.js +334 -0
- package/src/lib/knowledge-exporter.js +381 -0
- package/src/lib/knowledge-graph.js +432 -0
- package/src/lib/knowledge-importer.js +379 -0
- package/src/lib/llm-providers.js +391 -0
- package/src/lib/mcp-registry.js +333 -0
- package/src/lib/memory-manager.js +330 -0
- package/src/lib/multimodal.js +346 -0
- package/src/lib/nl-programming.js +343 -0
- package/src/lib/note-versioning.js +327 -0
- package/src/lib/org-manager.js +323 -0
- package/src/lib/p2p-manager.js +387 -0
- package/src/lib/perception.js +346 -0
- package/src/lib/perf-tuning.js +4 -1
- package/src/lib/permanent-memory.js +320 -0
- package/src/lib/plugin-ecosystem.js +377 -0
- package/src/lib/pqc-manager.js +368 -0
- package/src/lib/privacy-computing.js +427 -0
- package/src/lib/protocol-fusion.js +417 -0
- package/src/lib/quantization.js +325 -0
- package/src/lib/reputation-optimizer.js +299 -0
- package/src/lib/response-cache.js +327 -0
- package/src/lib/scim-manager.js +329 -0
- package/src/lib/session-manager.js +329 -0
- package/src/lib/siem-exporter.js +333 -0
- package/src/lib/skill-loader.js +377 -0
- package/src/lib/skill-marketplace.js +325 -0
- package/src/lib/sla-manager.js +275 -0
- package/src/lib/social-manager.js +326 -0
- package/src/lib/sso-manager.js +332 -0
- package/src/lib/stress-tester.js +330 -0
- package/src/lib/sync-manager.js +326 -0
- package/src/lib/tech-learning-engine.js +369 -0
- package/src/lib/tenant-saas.js +460 -0
- package/src/lib/terraform-manager.js +363 -0
- package/src/lib/threat-intel.js +335 -0
- package/src/lib/token-incentive.js +293 -0
- package/src/lib/token-tracker.js +329 -0
- package/src/lib/trust-security.js +390 -0
- package/src/lib/ueba.js +389 -0
- package/src/lib/universal-runtime.js +325 -0
- package/src/lib/wallet-manager.js +326 -0
- package/src/lib/workflow-engine.js +322 -0
- package/src/lib/zkp-engine.js +274 -0
|
@@ -681,4 +681,352 @@ export function deployCheck() {
|
|
|
681
681
|
export function _resetState() {
|
|
682
682
|
_baselines.clear();
|
|
683
683
|
_audits.clear();
|
|
684
|
+
_auditStatesV2.clear();
|
|
685
|
+
_baselineStatesV2.clear();
|
|
686
|
+
_maxConcurrentAudits = HARDENING_DEFAULT_MAX_CONCURRENT_AUDITS;
|
|
687
|
+
_baselineRetentionMs = HARDENING_DEFAULT_BASELINE_RETENTION_MS;
|
|
688
|
+
_auditTimeoutMs = HARDENING_DEFAULT_AUDIT_TIMEOUT_MS;
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
/* ──────────────────────────────────────────────────────────
|
|
692
|
+
* V2 — Phase 29 Production Hardening surface (strictly additive)
|
|
693
|
+
* ────────────────────────────────────────────────────────── */
|
|
694
|
+
|
|
695
|
+
export const AUDIT_STATUS_V2 = Object.freeze({
|
|
696
|
+
PENDING: "pending",
|
|
697
|
+
RUNNING: "running",
|
|
698
|
+
PASSED: "passed",
|
|
699
|
+
FAILED: "failed",
|
|
700
|
+
WARNING: "warning",
|
|
701
|
+
});
|
|
702
|
+
|
|
703
|
+
export const BASELINE_STATUS_V2 = Object.freeze({
|
|
704
|
+
DRAFT: "draft",
|
|
705
|
+
ACTIVE: "active",
|
|
706
|
+
SUPERSEDED: "superseded",
|
|
707
|
+
ARCHIVED: "archived",
|
|
708
|
+
});
|
|
709
|
+
|
|
710
|
+
export const SEVERITY_V2 = Object.freeze({
|
|
711
|
+
CRITICAL: "critical",
|
|
712
|
+
HIGH: "high",
|
|
713
|
+
MEDIUM: "medium",
|
|
714
|
+
LOW: "low",
|
|
715
|
+
INFO: "info",
|
|
716
|
+
});
|
|
717
|
+
|
|
718
|
+
export const HARDENING_DEFAULT_MAX_CONCURRENT_AUDITS = 5;
|
|
719
|
+
export const HARDENING_DEFAULT_BASELINE_RETENTION_MS = 90 * 24 * 60 * 60 * 1000; // 90 days
|
|
720
|
+
export const HARDENING_DEFAULT_AUDIT_TIMEOUT_MS = 300_000; // 5 minutes
|
|
721
|
+
|
|
722
|
+
const _auditStatesV2 = new Map();
|
|
723
|
+
const _baselineStatesV2 = new Map();
|
|
724
|
+
let _maxConcurrentAudits = HARDENING_DEFAULT_MAX_CONCURRENT_AUDITS;
|
|
725
|
+
let _baselineRetentionMs = HARDENING_DEFAULT_BASELINE_RETENTION_MS;
|
|
726
|
+
let _auditTimeoutMs = HARDENING_DEFAULT_AUDIT_TIMEOUT_MS;
|
|
727
|
+
|
|
728
|
+
const AUDIT_TRANSITIONS_V2 = new Map([
|
|
729
|
+
["pending", new Set(["running", "failed"])],
|
|
730
|
+
["running", new Set(["passed", "failed", "warning"])],
|
|
731
|
+
]);
|
|
732
|
+
const AUDIT_TERMINALS_V2 = new Set(["passed", "failed", "warning"]);
|
|
733
|
+
|
|
734
|
+
const BASELINE_TRANSITIONS_V2 = new Map([
|
|
735
|
+
["draft", new Set(["active", "archived"])],
|
|
736
|
+
["active", new Set(["superseded", "archived"])],
|
|
737
|
+
["superseded", new Set(["archived"])],
|
|
738
|
+
]);
|
|
739
|
+
const BASELINE_TERMINALS_V2 = new Set(["archived"]);
|
|
740
|
+
|
|
741
|
+
function _positiveIntV2(n, label) {
|
|
742
|
+
if (typeof n !== "number" || Number.isNaN(n) || n < 1) {
|
|
743
|
+
throw new Error(`${label} must be a positive integer`);
|
|
744
|
+
}
|
|
745
|
+
return Math.floor(n);
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
function _nowMs() {
|
|
749
|
+
return Date.now();
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
/* ── Config Mutators ──────────────────────────────────────── */
|
|
753
|
+
|
|
754
|
+
export function setMaxConcurrentAudits(n) {
|
|
755
|
+
_maxConcurrentAudits = _positiveIntV2(n, "maxConcurrentAudits");
|
|
756
|
+
}
|
|
757
|
+
export function getMaxConcurrentAudits() {
|
|
758
|
+
return _maxConcurrentAudits;
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
export function setBaselineRetentionMs(ms) {
|
|
762
|
+
_baselineRetentionMs = _positiveIntV2(ms, "baselineRetentionMs");
|
|
763
|
+
}
|
|
764
|
+
export function getBaselineRetentionMs() {
|
|
765
|
+
return _baselineRetentionMs;
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
export function setAuditTimeoutMs(ms) {
|
|
769
|
+
_auditTimeoutMs = _positiveIntV2(ms, "auditTimeoutMs");
|
|
770
|
+
}
|
|
771
|
+
export function getAuditTimeoutMs() {
|
|
772
|
+
return _auditTimeoutMs;
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
export function getRunningAuditCount() {
|
|
776
|
+
let count = 0;
|
|
777
|
+
for (const s of _auditStatesV2.values()) {
|
|
778
|
+
if (s.status === AUDIT_STATUS_V2.RUNNING) count += 1;
|
|
779
|
+
}
|
|
780
|
+
return count;
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
/* ── Audit Lifecycle V2 ───────────────────────────────────── */
|
|
784
|
+
|
|
785
|
+
export function registerAuditV2(db, { name, type, severity, metadata } = {}) {
|
|
786
|
+
if (!name) throw new Error("name is required");
|
|
787
|
+
if (
|
|
788
|
+
severity !== undefined &&
|
|
789
|
+
!Object.values(SEVERITY_V2).includes(severity)
|
|
790
|
+
) {
|
|
791
|
+
throw new Error(`Unknown severity: ${severity}`);
|
|
792
|
+
}
|
|
793
|
+
const id = crypto.randomUUID();
|
|
794
|
+
const now = _nowMs();
|
|
795
|
+
const entry = {
|
|
796
|
+
audit_id: id,
|
|
797
|
+
name,
|
|
798
|
+
type: type || "generic",
|
|
799
|
+
severity: severity || SEVERITY_V2.MEDIUM,
|
|
800
|
+
status: AUDIT_STATUS_V2.PENDING,
|
|
801
|
+
metadata: metadata || null,
|
|
802
|
+
registered_at: now,
|
|
803
|
+
started_at: null,
|
|
804
|
+
completed_at: null,
|
|
805
|
+
};
|
|
806
|
+
_auditStatesV2.set(id, entry);
|
|
807
|
+
return { ...entry };
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
export function startAudit(db, auditId) {
|
|
811
|
+
const entry = _auditStatesV2.get(auditId);
|
|
812
|
+
if (!entry) throw new Error(`Audit not found: ${auditId}`);
|
|
813
|
+
if (entry.status !== AUDIT_STATUS_V2.PENDING) {
|
|
814
|
+
throw new Error(
|
|
815
|
+
`Cannot start audit in status ${entry.status} (must be pending)`,
|
|
816
|
+
);
|
|
817
|
+
}
|
|
818
|
+
const running = getRunningAuditCount();
|
|
819
|
+
if (running >= _maxConcurrentAudits) {
|
|
820
|
+
throw new Error(
|
|
821
|
+
`Max concurrent audits reached (${running}/${_maxConcurrentAudits})`,
|
|
822
|
+
);
|
|
823
|
+
}
|
|
824
|
+
entry.status = AUDIT_STATUS_V2.RUNNING;
|
|
825
|
+
entry.started_at = _nowMs();
|
|
826
|
+
return { ...entry };
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
export function completeAudit(
|
|
830
|
+
db,
|
|
831
|
+
auditId,
|
|
832
|
+
{
|
|
833
|
+
passed = 0,
|
|
834
|
+
failed = 0,
|
|
835
|
+
score,
|
|
836
|
+
recommendations = [],
|
|
837
|
+
warningThreshold = 0.8,
|
|
838
|
+
} = {},
|
|
839
|
+
) {
|
|
840
|
+
const entry = _auditStatesV2.get(auditId);
|
|
841
|
+
if (!entry) throw new Error(`Audit not found: ${auditId}`);
|
|
842
|
+
if (entry.status !== AUDIT_STATUS_V2.RUNNING) {
|
|
843
|
+
throw new Error(
|
|
844
|
+
`Cannot complete audit in status ${entry.status} (must be running)`,
|
|
845
|
+
);
|
|
846
|
+
}
|
|
847
|
+
const total = passed + failed;
|
|
848
|
+
const computedScore =
|
|
849
|
+
typeof score === "number" ? score : total === 0 ? 1 : passed / total;
|
|
850
|
+
let newStatus;
|
|
851
|
+
if (failed === 0) newStatus = AUDIT_STATUS_V2.PASSED;
|
|
852
|
+
else if (computedScore >= warningThreshold)
|
|
853
|
+
newStatus = AUDIT_STATUS_V2.WARNING;
|
|
854
|
+
else newStatus = AUDIT_STATUS_V2.FAILED;
|
|
855
|
+
|
|
856
|
+
entry.status = newStatus;
|
|
857
|
+
entry.completed_at = _nowMs();
|
|
858
|
+
entry.passed = passed;
|
|
859
|
+
entry.failed = failed;
|
|
860
|
+
entry.score = computedScore;
|
|
861
|
+
entry.recommendations = recommendations;
|
|
862
|
+
return { ...entry };
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
export function setAuditStatusV2(db, auditId, newStatus, patch = {}) {
|
|
866
|
+
const entry = _auditStatesV2.get(auditId);
|
|
867
|
+
if (!entry) throw new Error(`Audit not found: ${auditId}`);
|
|
868
|
+
if (!Object.values(AUDIT_STATUS_V2).includes(newStatus)) {
|
|
869
|
+
throw new Error(`Unknown audit status: ${newStatus}`);
|
|
870
|
+
}
|
|
871
|
+
if (AUDIT_TERMINALS_V2.has(entry.status)) {
|
|
872
|
+
throw new Error(
|
|
873
|
+
`Invalid transition: ${entry.status} → ${newStatus} (terminal)`,
|
|
874
|
+
);
|
|
875
|
+
}
|
|
876
|
+
const allowed = AUDIT_TRANSITIONS_V2.get(entry.status);
|
|
877
|
+
if (!allowed || !allowed.has(newStatus)) {
|
|
878
|
+
throw new Error(`Invalid transition: ${entry.status} → ${newStatus}`);
|
|
879
|
+
}
|
|
880
|
+
if (
|
|
881
|
+
newStatus === AUDIT_STATUS_V2.RUNNING &&
|
|
882
|
+
entry.status !== AUDIT_STATUS_V2.RUNNING
|
|
883
|
+
) {
|
|
884
|
+
const running = getRunningAuditCount();
|
|
885
|
+
if (running >= _maxConcurrentAudits) {
|
|
886
|
+
throw new Error(
|
|
887
|
+
`Max concurrent audits reached (${running}/${_maxConcurrentAudits})`,
|
|
888
|
+
);
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
entry.status = newStatus;
|
|
892
|
+
if (AUDIT_TERMINALS_V2.has(newStatus)) entry.completed_at = _nowMs();
|
|
893
|
+
if (patch.errorMessage !== undefined) entry.errorMessage = patch.errorMessage;
|
|
894
|
+
if (patch.metadata !== undefined) entry.metadata = patch.metadata;
|
|
895
|
+
return { ...entry };
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
export function getAuditStatusV2(auditId) {
|
|
899
|
+
const entry = _auditStatesV2.get(auditId);
|
|
900
|
+
return entry ? { ...entry } : null;
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
export function autoTimeoutAudits(db) {
|
|
904
|
+
const now = _nowMs();
|
|
905
|
+
const timedOut = [];
|
|
906
|
+
for (const entry of _auditStatesV2.values()) {
|
|
907
|
+
if (entry.status !== AUDIT_STATUS_V2.RUNNING) continue;
|
|
908
|
+
if (entry.started_at == null) continue;
|
|
909
|
+
if (now - entry.started_at >= _auditTimeoutMs) {
|
|
910
|
+
entry.status = AUDIT_STATUS_V2.FAILED;
|
|
911
|
+
entry.completed_at = now;
|
|
912
|
+
entry.errorMessage = `auto-timeout after ${_auditTimeoutMs}ms`;
|
|
913
|
+
timedOut.push({ ...entry });
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
return timedOut;
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
/* ── Baseline Lifecycle V2 ────────────────────────────────── */
|
|
920
|
+
|
|
921
|
+
export function createBaselineV2(db, { name, version, metadata } = {}) {
|
|
922
|
+
if (!name) throw new Error("name is required");
|
|
923
|
+
const id = crypto.randomUUID();
|
|
924
|
+
const now = _nowMs();
|
|
925
|
+
const entry = {
|
|
926
|
+
baseline_id: id,
|
|
927
|
+
name,
|
|
928
|
+
version: version || "1.0.0",
|
|
929
|
+
status: BASELINE_STATUS_V2.DRAFT,
|
|
930
|
+
metadata: metadata || null,
|
|
931
|
+
created_at: now,
|
|
932
|
+
activated_at: null,
|
|
933
|
+
archived_at: null,
|
|
934
|
+
};
|
|
935
|
+
_baselineStatesV2.set(id, entry);
|
|
936
|
+
return { ...entry };
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
export function getBaselineStatusV2(baselineId) {
|
|
940
|
+
const entry = _baselineStatesV2.get(baselineId);
|
|
941
|
+
return entry ? { ...entry } : null;
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
export function setBaselineStatusV2(db, baselineId, newStatus, patch = {}) {
|
|
945
|
+
const entry = _baselineStatesV2.get(baselineId);
|
|
946
|
+
if (!entry) throw new Error(`Baseline not found: ${baselineId}`);
|
|
947
|
+
if (!Object.values(BASELINE_STATUS_V2).includes(newStatus)) {
|
|
948
|
+
throw new Error(`Unknown baseline status: ${newStatus}`);
|
|
949
|
+
}
|
|
950
|
+
if (BASELINE_TERMINALS_V2.has(entry.status)) {
|
|
951
|
+
throw new Error(
|
|
952
|
+
`Invalid transition: ${entry.status} → ${newStatus} (terminal)`,
|
|
953
|
+
);
|
|
954
|
+
}
|
|
955
|
+
const allowed = BASELINE_TRANSITIONS_V2.get(entry.status);
|
|
956
|
+
if (!allowed || !allowed.has(newStatus)) {
|
|
957
|
+
throw new Error(`Invalid transition: ${entry.status} → ${newStatus}`);
|
|
958
|
+
}
|
|
959
|
+
entry.status = newStatus;
|
|
960
|
+
if (newStatus === BASELINE_STATUS_V2.ACTIVE) entry.activated_at = _nowMs();
|
|
961
|
+
if (newStatus === BASELINE_STATUS_V2.ARCHIVED) entry.archived_at = _nowMs();
|
|
962
|
+
if (patch.metadata !== undefined) entry.metadata = patch.metadata;
|
|
963
|
+
if (patch.reason !== undefined) entry.reason = patch.reason;
|
|
964
|
+
return { ...entry };
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
export function activateBaseline(db, baselineId) {
|
|
968
|
+
const entry = _baselineStatesV2.get(baselineId);
|
|
969
|
+
if (!entry) throw new Error(`Baseline not found: ${baselineId}`);
|
|
970
|
+
if (entry.status !== BASELINE_STATUS_V2.DRAFT) {
|
|
971
|
+
throw new Error(
|
|
972
|
+
`Cannot activate baseline in status ${entry.status} (must be draft)`,
|
|
973
|
+
);
|
|
974
|
+
}
|
|
975
|
+
for (const other of _baselineStatesV2.values()) {
|
|
976
|
+
if (
|
|
977
|
+
other.baseline_id !== baselineId &&
|
|
978
|
+
other.status === BASELINE_STATUS_V2.ACTIVE
|
|
979
|
+
) {
|
|
980
|
+
other.status = BASELINE_STATUS_V2.SUPERSEDED;
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
entry.status = BASELINE_STATUS_V2.ACTIVE;
|
|
984
|
+
entry.activated_at = _nowMs();
|
|
985
|
+
return { ...entry };
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
export function autoArchiveStaleBaselines(db) {
|
|
989
|
+
const now = _nowMs();
|
|
990
|
+
const archived = [];
|
|
991
|
+
for (const entry of _baselineStatesV2.values()) {
|
|
992
|
+
if (entry.status !== BASELINE_STATUS_V2.SUPERSEDED) continue;
|
|
993
|
+
if (now - entry.created_at >= _baselineRetentionMs) {
|
|
994
|
+
entry.status = BASELINE_STATUS_V2.ARCHIVED;
|
|
995
|
+
entry.archived_at = now;
|
|
996
|
+
archived.push({ ...entry });
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
return archived;
|
|
1000
|
+
}
|
|
1001
|
+
|
|
1002
|
+
/* ── V2 Stats ─────────────────────────────────────────────── */
|
|
1003
|
+
|
|
1004
|
+
export function getHardeningStatsV2() {
|
|
1005
|
+
const auditsByStatus = {};
|
|
1006
|
+
for (const s of Object.values(AUDIT_STATUS_V2)) auditsByStatus[s] = 0;
|
|
1007
|
+
const auditsBySeverity = {};
|
|
1008
|
+
for (const s of Object.values(SEVERITY_V2)) auditsBySeverity[s] = 0;
|
|
1009
|
+
for (const a of _auditStatesV2.values()) {
|
|
1010
|
+
auditsByStatus[a.status] = (auditsByStatus[a.status] || 0) + 1;
|
|
1011
|
+
auditsBySeverity[a.severity] = (auditsBySeverity[a.severity] || 0) + 1;
|
|
1012
|
+
}
|
|
1013
|
+
|
|
1014
|
+
const baselinesByStatus = {};
|
|
1015
|
+
for (const s of Object.values(BASELINE_STATUS_V2)) baselinesByStatus[s] = 0;
|
|
1016
|
+
for (const b of _baselineStatesV2.values()) {
|
|
1017
|
+
baselinesByStatus[b.status] = (baselinesByStatus[b.status] || 0) + 1;
|
|
1018
|
+
}
|
|
1019
|
+
|
|
1020
|
+
return {
|
|
1021
|
+
totalAudits: _auditStatesV2.size,
|
|
1022
|
+
runningAudits: auditsByStatus[AUDIT_STATUS_V2.RUNNING],
|
|
1023
|
+
totalBaselines: _baselineStatesV2.size,
|
|
1024
|
+
activeBaselines: baselinesByStatus[BASELINE_STATUS_V2.ACTIVE],
|
|
1025
|
+
maxConcurrentAudits: _maxConcurrentAudits,
|
|
1026
|
+
baselineRetentionMs: _baselineRetentionMs,
|
|
1027
|
+
auditTimeoutMs: _auditTimeoutMs,
|
|
1028
|
+
auditsByStatus,
|
|
1029
|
+
auditsBySeverity,
|
|
1030
|
+
baselinesByStatus,
|
|
1031
|
+
};
|
|
684
1032
|
}
|