chainlesschain 0.132.0 → 0.145.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/package.json +1 -1
- package/src/commands/a2a.js +230 -0
- package/src/commands/activitypub.js +191 -0
- package/src/commands/agent.js +601 -0
- package/src/commands/audit.js +206 -0
- package/src/commands/bi.js +186 -0
- package/src/commands/bm25.js +162 -0
- package/src/commands/browse.js +225 -0
- package/src/commands/ccron.js +178 -0
- package/src/commands/chat.js +207 -0
- package/src/commands/compliance.js +420 -0
- package/src/commands/compt.js +176 -0
- package/src/commands/consol.js +237 -0
- package/src/commands/cowork.js +588 -0
- package/src/commands/crosschain.js +216 -0
- package/src/commands/dao.js +216 -0
- package/src/commands/dlp.js +206 -0
- package/src/commands/economy.js +211 -0
- package/src/commands/evolution.js +209 -0
- package/src/commands/evomap.js +216 -0
- package/src/commands/fflag.js +230 -0
- package/src/commands/git.js +185 -0
- package/src/commands/hardening.js +209 -0
- package/src/commands/hmemory.js +210 -0
- package/src/commands/incentive.js +209 -0
- package/src/commands/inference.js +178 -0
- package/src/commands/itbudget.js +161 -0
- package/src/commands/kg.js +206 -0
- package/src/commands/lowcode.js +201 -0
- package/src/commands/marketplace.js +206 -0
- package/src/commands/matrix.js +214 -0
- package/src/commands/mcpscaf.js +153 -0
- package/src/commands/meminj.js +153 -0
- package/src/commands/nostr.js +213 -0
- package/src/commands/orchestrate.js +217 -0
- package/src/commands/orchgov.js +156 -0
- package/src/commands/pdfp.js +160 -0
- package/src/commands/perf.js +176 -0
- package/src/commands/perm.js +156 -0
- package/src/commands/pipeline.js +211 -0
- package/src/commands/planmode.js +154 -0
- package/src/commands/privacy.js +203 -0
- package/src/commands/promcomp.js +166 -0
- package/src/commands/recommend.js +185 -0
- package/src/commands/reputation.js +208 -0
- package/src/commands/sandbox.js +206 -0
- package/src/commands/seshhook.js +153 -0
- package/src/commands/seshsearch.js +149 -0
- package/src/commands/seshtail.js +152 -0
- package/src/commands/seshu.js +160 -0
- package/src/commands/sganal.js +172 -0
- package/src/commands/siem.js +207 -0
- package/src/commands/sla.js +212 -0
- package/src/commands/slotfill.js +154 -0
- package/src/commands/social.js +159 -0
- package/src/commands/stress.js +206 -0
- package/src/commands/svccont.js +157 -0
- package/src/commands/terraform.js +206 -0
- package/src/commands/tms.js +183 -0
- package/src/commands/topiccls.js +158 -0
- package/src/commands/uprof.js +154 -0
- package/src/commands/vcheck.js +172 -0
- package/src/commands/webfetch.js +150 -0
- package/src/commands/zkp.js +218 -0
- package/src/harness/prompt-compressor.js +331 -0
- package/src/index.js +101 -1
- package/src/lib/a2a-protocol.js +373 -0
- package/src/lib/activitypub-bridge.js +343 -0
- package/src/lib/agent-economy.js +358 -0
- package/src/lib/app-builder.js +338 -0
- package/src/lib/audit-logger.js +321 -0
- package/src/lib/autonomous-agent.js +341 -0
- package/src/lib/bi-engine.js +339 -0
- package/src/lib/bm25-search.js +333 -0
- package/src/lib/browser-automation.js +352 -0
- package/src/lib/chat-core.js +336 -0
- package/src/lib/claude-code-bridge.js +341 -0
- package/src/lib/compliance-framework-reporter.js +359 -0
- package/src/lib/compliance-manager.js +330 -0
- package/src/lib/compression-telemetry.js +333 -0
- package/src/lib/content-recommender.js +370 -0
- package/src/lib/cowork-cron.js +330 -0
- package/src/lib/cowork-learning.js +333 -0
- package/src/lib/cowork-task-runner.js +362 -0
- package/src/lib/cowork-workflow.js +327 -0
- package/src/lib/cross-chain.js +365 -0
- package/src/lib/dao-governance.js +339 -0
- package/src/lib/dlp-engine.js +343 -0
- package/src/lib/evolution-system.js +336 -0
- package/src/lib/evomap-manager.js +339 -0
- package/src/lib/execution-backend.js +351 -0
- package/src/lib/feature-flags.js +330 -0
- package/src/lib/git-integration.js +343 -0
- package/src/lib/hardening-manager.js +341 -0
- package/src/lib/hierarchical-memory.js +341 -0
- package/src/lib/inference-network.js +362 -0
- package/src/lib/iteration-budget.js +357 -0
- package/src/lib/knowledge-graph.js +333 -0
- package/src/lib/matrix-bridge.js +339 -0
- package/src/lib/mcp-scaffold.js +345 -0
- package/src/lib/memory-injection.js +320 -0
- package/src/lib/nostr-bridge.js +342 -0
- package/src/lib/orchestrator.js +350 -0
- package/src/lib/pdf-parser.js +330 -0
- package/src/lib/perf-tuning.js +364 -0
- package/src/lib/permission-engine.js +319 -0
- package/src/lib/pipeline-orchestrator.js +345 -0
- package/src/lib/plan-mode.js +328 -0
- package/src/lib/privacy-computing.js +335 -0
- package/src/lib/prompt-compressor.js +1 -10
- package/src/lib/reputation-optimizer.js +340 -0
- package/src/lib/sandbox-v2.js +327 -0
- package/src/lib/service-container.js +342 -0
- package/src/lib/session-consolidator.js +352 -0
- package/src/lib/session-hooks.js +340 -0
- package/src/lib/session-search.js +334 -0
- package/src/lib/session-tail.js +320 -0
- package/src/lib/session-usage.js +329 -0
- package/src/lib/siem-exporter.js +352 -0
- package/src/lib/skill-marketplace.js +345 -0
- package/src/lib/sla-manager.js +341 -0
- package/src/lib/slot-filler.js +333 -0
- package/src/lib/social-graph-analytics.js +327 -0
- package/src/lib/social-graph.js +304 -0
- package/src/lib/stress-tester.js +342 -0
- package/src/lib/sub-agent-registry.js +359 -0
- package/src/lib/task-model-selector.js +333 -0
- package/src/lib/terraform-manager.js +333 -0
- package/src/lib/todo-manager.js +339 -0
- package/src/lib/token-incentive.js +341 -0
- package/src/lib/topic-classifier.js +353 -0
- package/src/lib/user-profile.js +325 -0
- package/src/lib/version-checker.js +335 -0
- package/src/lib/web-fetch.js +322 -0
- package/src/lib/zkp-engine.js +342 -0
|
@@ -598,3 +598,362 @@ export function generateFrameworkReport(frameworkId, opts = {}) {
|
|
|
598
598
|
export function _resetState() {
|
|
599
599
|
_customTemplates.clear();
|
|
600
600
|
}
|
|
601
|
+
|
|
602
|
+
// ===== V2 Surface: Compliance Framework Reporter governance overlay (CLI v0.138.0) =====
|
|
603
|
+
export const COMPLIANCE_FW_MATURITY_V2 = Object.freeze({
|
|
604
|
+
PENDING: "pending",
|
|
605
|
+
ACTIVE: "active",
|
|
606
|
+
DEPRECATED: "deprecated",
|
|
607
|
+
ARCHIVED: "archived",
|
|
608
|
+
});
|
|
609
|
+
export const COMPLIANCE_FW_REPORT_LIFECYCLE_V2 = Object.freeze({
|
|
610
|
+
QUEUED: "queued",
|
|
611
|
+
GENERATING: "generating",
|
|
612
|
+
COMPLETED: "completed",
|
|
613
|
+
FAILED: "failed",
|
|
614
|
+
CANCELLED: "cancelled",
|
|
615
|
+
});
|
|
616
|
+
|
|
617
|
+
const _cfwTrans = new Map([
|
|
618
|
+
[
|
|
619
|
+
COMPLIANCE_FW_MATURITY_V2.PENDING,
|
|
620
|
+
new Set([
|
|
621
|
+
COMPLIANCE_FW_MATURITY_V2.ACTIVE,
|
|
622
|
+
COMPLIANCE_FW_MATURITY_V2.ARCHIVED,
|
|
623
|
+
]),
|
|
624
|
+
],
|
|
625
|
+
[
|
|
626
|
+
COMPLIANCE_FW_MATURITY_V2.ACTIVE,
|
|
627
|
+
new Set([
|
|
628
|
+
COMPLIANCE_FW_MATURITY_V2.DEPRECATED,
|
|
629
|
+
COMPLIANCE_FW_MATURITY_V2.ARCHIVED,
|
|
630
|
+
]),
|
|
631
|
+
],
|
|
632
|
+
[
|
|
633
|
+
COMPLIANCE_FW_MATURITY_V2.DEPRECATED,
|
|
634
|
+
new Set([
|
|
635
|
+
COMPLIANCE_FW_MATURITY_V2.ACTIVE,
|
|
636
|
+
COMPLIANCE_FW_MATURITY_V2.ARCHIVED,
|
|
637
|
+
]),
|
|
638
|
+
],
|
|
639
|
+
[COMPLIANCE_FW_MATURITY_V2.ARCHIVED, new Set()],
|
|
640
|
+
]);
|
|
641
|
+
const _cfwTerminal = new Set([COMPLIANCE_FW_MATURITY_V2.ARCHIVED]);
|
|
642
|
+
const _cfwRepTrans = new Map([
|
|
643
|
+
[
|
|
644
|
+
COMPLIANCE_FW_REPORT_LIFECYCLE_V2.QUEUED,
|
|
645
|
+
new Set([
|
|
646
|
+
COMPLIANCE_FW_REPORT_LIFECYCLE_V2.GENERATING,
|
|
647
|
+
COMPLIANCE_FW_REPORT_LIFECYCLE_V2.CANCELLED,
|
|
648
|
+
]),
|
|
649
|
+
],
|
|
650
|
+
[
|
|
651
|
+
COMPLIANCE_FW_REPORT_LIFECYCLE_V2.GENERATING,
|
|
652
|
+
new Set([
|
|
653
|
+
COMPLIANCE_FW_REPORT_LIFECYCLE_V2.COMPLETED,
|
|
654
|
+
COMPLIANCE_FW_REPORT_LIFECYCLE_V2.FAILED,
|
|
655
|
+
COMPLIANCE_FW_REPORT_LIFECYCLE_V2.CANCELLED,
|
|
656
|
+
]),
|
|
657
|
+
],
|
|
658
|
+
[COMPLIANCE_FW_REPORT_LIFECYCLE_V2.COMPLETED, new Set()],
|
|
659
|
+
[COMPLIANCE_FW_REPORT_LIFECYCLE_V2.FAILED, new Set()],
|
|
660
|
+
[COMPLIANCE_FW_REPORT_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
661
|
+
]);
|
|
662
|
+
|
|
663
|
+
const _cfwsV2 = new Map();
|
|
664
|
+
const _cfwReports = new Map();
|
|
665
|
+
let _cfwMaxActivePerOwner = 8;
|
|
666
|
+
let _cfwMaxPendingReportsPerFw = 15;
|
|
667
|
+
let _cfwIdleMs = 90 * 24 * 60 * 60 * 1000;
|
|
668
|
+
let _cfwReportStuckMs = 10 * 60 * 1000;
|
|
669
|
+
|
|
670
|
+
function _cfwPos(n, lbl) {
|
|
671
|
+
const v = Math.floor(Number(n));
|
|
672
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
673
|
+
throw new Error(`${lbl} must be positive integer`);
|
|
674
|
+
return v;
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
export function setMaxActiveComplianceFwsPerOwnerV2(n) {
|
|
678
|
+
_cfwMaxActivePerOwner = _cfwPos(n, "maxActiveComplianceFwsPerOwner");
|
|
679
|
+
}
|
|
680
|
+
export function getMaxActiveComplianceFwsPerOwnerV2() {
|
|
681
|
+
return _cfwMaxActivePerOwner;
|
|
682
|
+
}
|
|
683
|
+
export function setMaxPendingComplianceFwReportsPerFwV2(n) {
|
|
684
|
+
_cfwMaxPendingReportsPerFw = _cfwPos(n, "maxPendingComplianceFwReportsPerFw");
|
|
685
|
+
}
|
|
686
|
+
export function getMaxPendingComplianceFwReportsPerFwV2() {
|
|
687
|
+
return _cfwMaxPendingReportsPerFw;
|
|
688
|
+
}
|
|
689
|
+
export function setComplianceFwIdleMsV2(n) {
|
|
690
|
+
_cfwIdleMs = _cfwPos(n, "complianceFwIdleMs");
|
|
691
|
+
}
|
|
692
|
+
export function getComplianceFwIdleMsV2() {
|
|
693
|
+
return _cfwIdleMs;
|
|
694
|
+
}
|
|
695
|
+
export function setComplianceFwReportStuckMsV2(n) {
|
|
696
|
+
_cfwReportStuckMs = _cfwPos(n, "complianceFwReportStuckMs");
|
|
697
|
+
}
|
|
698
|
+
export function getComplianceFwReportStuckMsV2() {
|
|
699
|
+
return _cfwReportStuckMs;
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
export function _resetStateComplianceFwReporterV2() {
|
|
703
|
+
_cfwsV2.clear();
|
|
704
|
+
_cfwReports.clear();
|
|
705
|
+
_cfwMaxActivePerOwner = 8;
|
|
706
|
+
_cfwMaxPendingReportsPerFw = 15;
|
|
707
|
+
_cfwIdleMs = 90 * 24 * 60 * 60 * 1000;
|
|
708
|
+
_cfwReportStuckMs = 10 * 60 * 1000;
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
export function registerComplianceFwV2({ id, owner, name, metadata } = {}) {
|
|
712
|
+
if (!id || typeof id !== "string") throw new Error("id is required");
|
|
713
|
+
if (!owner || typeof owner !== "string") throw new Error("owner is required");
|
|
714
|
+
if (_cfwsV2.has(id))
|
|
715
|
+
throw new Error(`compliance framework ${id} already registered`);
|
|
716
|
+
const now = Date.now();
|
|
717
|
+
const f = {
|
|
718
|
+
id,
|
|
719
|
+
owner,
|
|
720
|
+
name: name || id,
|
|
721
|
+
status: COMPLIANCE_FW_MATURITY_V2.PENDING,
|
|
722
|
+
createdAt: now,
|
|
723
|
+
updatedAt: now,
|
|
724
|
+
activatedAt: null,
|
|
725
|
+
archivedAt: null,
|
|
726
|
+
lastTouchedAt: now,
|
|
727
|
+
metadata: { ...(metadata || {}) },
|
|
728
|
+
};
|
|
729
|
+
_cfwsV2.set(id, f);
|
|
730
|
+
return { ...f, metadata: { ...f.metadata } };
|
|
731
|
+
}
|
|
732
|
+
function _cfwCheckF(from, to) {
|
|
733
|
+
const a = _cfwTrans.get(from);
|
|
734
|
+
if (!a || !a.has(to))
|
|
735
|
+
throw new Error(`invalid compliance framework transition ${from} → ${to}`);
|
|
736
|
+
}
|
|
737
|
+
function _cfwCountActive(owner) {
|
|
738
|
+
let n = 0;
|
|
739
|
+
for (const f of _cfwsV2.values())
|
|
740
|
+
if (f.owner === owner && f.status === COMPLIANCE_FW_MATURITY_V2.ACTIVE) n++;
|
|
741
|
+
return n;
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
export function activateComplianceFwV2(id) {
|
|
745
|
+
const f = _cfwsV2.get(id);
|
|
746
|
+
if (!f) throw new Error(`compliance framework ${id} not found`);
|
|
747
|
+
_cfwCheckF(f.status, COMPLIANCE_FW_MATURITY_V2.ACTIVE);
|
|
748
|
+
const recovery = f.status === COMPLIANCE_FW_MATURITY_V2.DEPRECATED;
|
|
749
|
+
if (!recovery) {
|
|
750
|
+
const c = _cfwCountActive(f.owner);
|
|
751
|
+
if (c >= _cfwMaxActivePerOwner)
|
|
752
|
+
throw new Error(
|
|
753
|
+
`max active compliance frameworks per owner (${_cfwMaxActivePerOwner}) reached for ${f.owner}`,
|
|
754
|
+
);
|
|
755
|
+
}
|
|
756
|
+
const now = Date.now();
|
|
757
|
+
f.status = COMPLIANCE_FW_MATURITY_V2.ACTIVE;
|
|
758
|
+
f.updatedAt = now;
|
|
759
|
+
f.lastTouchedAt = now;
|
|
760
|
+
if (!f.activatedAt) f.activatedAt = now;
|
|
761
|
+
return { ...f, metadata: { ...f.metadata } };
|
|
762
|
+
}
|
|
763
|
+
export function deprecateComplianceFwV2(id) {
|
|
764
|
+
const f = _cfwsV2.get(id);
|
|
765
|
+
if (!f) throw new Error(`compliance framework ${id} not found`);
|
|
766
|
+
_cfwCheckF(f.status, COMPLIANCE_FW_MATURITY_V2.DEPRECATED);
|
|
767
|
+
f.status = COMPLIANCE_FW_MATURITY_V2.DEPRECATED;
|
|
768
|
+
f.updatedAt = Date.now();
|
|
769
|
+
return { ...f, metadata: { ...f.metadata } };
|
|
770
|
+
}
|
|
771
|
+
export function archiveComplianceFwV2(id) {
|
|
772
|
+
const f = _cfwsV2.get(id);
|
|
773
|
+
if (!f) throw new Error(`compliance framework ${id} not found`);
|
|
774
|
+
_cfwCheckF(f.status, COMPLIANCE_FW_MATURITY_V2.ARCHIVED);
|
|
775
|
+
const now = Date.now();
|
|
776
|
+
f.status = COMPLIANCE_FW_MATURITY_V2.ARCHIVED;
|
|
777
|
+
f.updatedAt = now;
|
|
778
|
+
if (!f.archivedAt) f.archivedAt = now;
|
|
779
|
+
return { ...f, metadata: { ...f.metadata } };
|
|
780
|
+
}
|
|
781
|
+
export function touchComplianceFwV2(id) {
|
|
782
|
+
const f = _cfwsV2.get(id);
|
|
783
|
+
if (!f) throw new Error(`compliance framework ${id} not found`);
|
|
784
|
+
if (_cfwTerminal.has(f.status))
|
|
785
|
+
throw new Error(`cannot touch terminal compliance framework ${id}`);
|
|
786
|
+
const now = Date.now();
|
|
787
|
+
f.lastTouchedAt = now;
|
|
788
|
+
f.updatedAt = now;
|
|
789
|
+
return { ...f, metadata: { ...f.metadata } };
|
|
790
|
+
}
|
|
791
|
+
export function getComplianceFwV2(id) {
|
|
792
|
+
const f = _cfwsV2.get(id);
|
|
793
|
+
if (!f) return null;
|
|
794
|
+
return { ...f, metadata: { ...f.metadata } };
|
|
795
|
+
}
|
|
796
|
+
export function listComplianceFwsV2() {
|
|
797
|
+
return [..._cfwsV2.values()].map((f) => ({
|
|
798
|
+
...f,
|
|
799
|
+
metadata: { ...f.metadata },
|
|
800
|
+
}));
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
function _cfwCountPendingReports(frameworkId) {
|
|
804
|
+
let n = 0;
|
|
805
|
+
for (const r of _cfwReports.values())
|
|
806
|
+
if (
|
|
807
|
+
r.frameworkId === frameworkId &&
|
|
808
|
+
(r.status === COMPLIANCE_FW_REPORT_LIFECYCLE_V2.QUEUED ||
|
|
809
|
+
r.status === COMPLIANCE_FW_REPORT_LIFECYCLE_V2.GENERATING)
|
|
810
|
+
)
|
|
811
|
+
n++;
|
|
812
|
+
return n;
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
export function createComplianceFwReportV2({
|
|
816
|
+
id,
|
|
817
|
+
frameworkId,
|
|
818
|
+
format,
|
|
819
|
+
metadata,
|
|
820
|
+
} = {}) {
|
|
821
|
+
if (!id || typeof id !== "string") throw new Error("id is required");
|
|
822
|
+
if (!frameworkId || typeof frameworkId !== "string")
|
|
823
|
+
throw new Error("frameworkId is required");
|
|
824
|
+
if (_cfwReports.has(id))
|
|
825
|
+
throw new Error(`compliance framework report ${id} already exists`);
|
|
826
|
+
if (!_cfwsV2.has(frameworkId))
|
|
827
|
+
throw new Error(`compliance framework ${frameworkId} not found`);
|
|
828
|
+
const pending = _cfwCountPendingReports(frameworkId);
|
|
829
|
+
if (pending >= _cfwMaxPendingReportsPerFw)
|
|
830
|
+
throw new Error(
|
|
831
|
+
`max pending compliance framework reports per framework (${_cfwMaxPendingReportsPerFw}) reached for ${frameworkId}`,
|
|
832
|
+
);
|
|
833
|
+
const now = Date.now();
|
|
834
|
+
const r = {
|
|
835
|
+
id,
|
|
836
|
+
frameworkId,
|
|
837
|
+
format: format || "markdown",
|
|
838
|
+
status: COMPLIANCE_FW_REPORT_LIFECYCLE_V2.QUEUED,
|
|
839
|
+
createdAt: now,
|
|
840
|
+
updatedAt: now,
|
|
841
|
+
startedAt: null,
|
|
842
|
+
settledAt: null,
|
|
843
|
+
metadata: { ...(metadata || {}) },
|
|
844
|
+
};
|
|
845
|
+
_cfwReports.set(id, r);
|
|
846
|
+
return { ...r, metadata: { ...r.metadata } };
|
|
847
|
+
}
|
|
848
|
+
function _cfwCheckR(from, to) {
|
|
849
|
+
const a = _cfwRepTrans.get(from);
|
|
850
|
+
if (!a || !a.has(to))
|
|
851
|
+
throw new Error(
|
|
852
|
+
`invalid compliance framework report transition ${from} → ${to}`,
|
|
853
|
+
);
|
|
854
|
+
}
|
|
855
|
+
export function startComplianceFwReportV2(id) {
|
|
856
|
+
const r = _cfwReports.get(id);
|
|
857
|
+
if (!r) throw new Error(`compliance framework report ${id} not found`);
|
|
858
|
+
_cfwCheckR(r.status, COMPLIANCE_FW_REPORT_LIFECYCLE_V2.GENERATING);
|
|
859
|
+
const now = Date.now();
|
|
860
|
+
r.status = COMPLIANCE_FW_REPORT_LIFECYCLE_V2.GENERATING;
|
|
861
|
+
r.updatedAt = now;
|
|
862
|
+
if (!r.startedAt) r.startedAt = now;
|
|
863
|
+
return { ...r, metadata: { ...r.metadata } };
|
|
864
|
+
}
|
|
865
|
+
export function completeComplianceFwReportV2(id) {
|
|
866
|
+
const r = _cfwReports.get(id);
|
|
867
|
+
if (!r) throw new Error(`compliance framework report ${id} not found`);
|
|
868
|
+
_cfwCheckR(r.status, COMPLIANCE_FW_REPORT_LIFECYCLE_V2.COMPLETED);
|
|
869
|
+
const now = Date.now();
|
|
870
|
+
r.status = COMPLIANCE_FW_REPORT_LIFECYCLE_V2.COMPLETED;
|
|
871
|
+
r.updatedAt = now;
|
|
872
|
+
if (!r.settledAt) r.settledAt = now;
|
|
873
|
+
return { ...r, metadata: { ...r.metadata } };
|
|
874
|
+
}
|
|
875
|
+
export function failComplianceFwReportV2(id, reason) {
|
|
876
|
+
const r = _cfwReports.get(id);
|
|
877
|
+
if (!r) throw new Error(`compliance framework report ${id} not found`);
|
|
878
|
+
_cfwCheckR(r.status, COMPLIANCE_FW_REPORT_LIFECYCLE_V2.FAILED);
|
|
879
|
+
const now = Date.now();
|
|
880
|
+
r.status = COMPLIANCE_FW_REPORT_LIFECYCLE_V2.FAILED;
|
|
881
|
+
r.updatedAt = now;
|
|
882
|
+
if (!r.settledAt) r.settledAt = now;
|
|
883
|
+
if (reason) r.metadata.failReason = String(reason);
|
|
884
|
+
return { ...r, metadata: { ...r.metadata } };
|
|
885
|
+
}
|
|
886
|
+
export function cancelComplianceFwReportV2(id, reason) {
|
|
887
|
+
const r = _cfwReports.get(id);
|
|
888
|
+
if (!r) throw new Error(`compliance framework report ${id} not found`);
|
|
889
|
+
_cfwCheckR(r.status, COMPLIANCE_FW_REPORT_LIFECYCLE_V2.CANCELLED);
|
|
890
|
+
const now = Date.now();
|
|
891
|
+
r.status = COMPLIANCE_FW_REPORT_LIFECYCLE_V2.CANCELLED;
|
|
892
|
+
r.updatedAt = now;
|
|
893
|
+
if (!r.settledAt) r.settledAt = now;
|
|
894
|
+
if (reason) r.metadata.cancelReason = String(reason);
|
|
895
|
+
return { ...r, metadata: { ...r.metadata } };
|
|
896
|
+
}
|
|
897
|
+
export function getComplianceFwReportV2(id) {
|
|
898
|
+
const r = _cfwReports.get(id);
|
|
899
|
+
if (!r) return null;
|
|
900
|
+
return { ...r, metadata: { ...r.metadata } };
|
|
901
|
+
}
|
|
902
|
+
export function listComplianceFwReportsV2() {
|
|
903
|
+
return [..._cfwReports.values()].map((r) => ({
|
|
904
|
+
...r,
|
|
905
|
+
metadata: { ...r.metadata },
|
|
906
|
+
}));
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
export function autoDeprecateIdleComplianceFwsV2({ now } = {}) {
|
|
910
|
+
const t = now ?? Date.now();
|
|
911
|
+
const flipped = [];
|
|
912
|
+
for (const f of _cfwsV2.values())
|
|
913
|
+
if (
|
|
914
|
+
f.status === COMPLIANCE_FW_MATURITY_V2.ACTIVE &&
|
|
915
|
+
t - f.lastTouchedAt >= _cfwIdleMs
|
|
916
|
+
) {
|
|
917
|
+
f.status = COMPLIANCE_FW_MATURITY_V2.DEPRECATED;
|
|
918
|
+
f.updatedAt = t;
|
|
919
|
+
flipped.push(f.id);
|
|
920
|
+
}
|
|
921
|
+
return { flipped, count: flipped.length };
|
|
922
|
+
}
|
|
923
|
+
export function autoFailStuckComplianceFwReportsV2({ now } = {}) {
|
|
924
|
+
const t = now ?? Date.now();
|
|
925
|
+
const flipped = [];
|
|
926
|
+
for (const r of _cfwReports.values())
|
|
927
|
+
if (
|
|
928
|
+
r.status === COMPLIANCE_FW_REPORT_LIFECYCLE_V2.GENERATING &&
|
|
929
|
+
r.startedAt != null &&
|
|
930
|
+
t - r.startedAt >= _cfwReportStuckMs
|
|
931
|
+
) {
|
|
932
|
+
r.status = COMPLIANCE_FW_REPORT_LIFECYCLE_V2.FAILED;
|
|
933
|
+
r.updatedAt = t;
|
|
934
|
+
if (!r.settledAt) r.settledAt = t;
|
|
935
|
+
r.metadata.failReason = "auto-fail-stuck";
|
|
936
|
+
flipped.push(r.id);
|
|
937
|
+
}
|
|
938
|
+
return { flipped, count: flipped.length };
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
export function getComplianceFwReporterGovStatsV2() {
|
|
942
|
+
const fwsByStatus = {};
|
|
943
|
+
for (const s of Object.values(COMPLIANCE_FW_MATURITY_V2)) fwsByStatus[s] = 0;
|
|
944
|
+
for (const f of _cfwsV2.values()) fwsByStatus[f.status]++;
|
|
945
|
+
const reportsByStatus = {};
|
|
946
|
+
for (const s of Object.values(COMPLIANCE_FW_REPORT_LIFECYCLE_V2))
|
|
947
|
+
reportsByStatus[s] = 0;
|
|
948
|
+
for (const r of _cfwReports.values()) reportsByStatus[r.status]++;
|
|
949
|
+
return {
|
|
950
|
+
totalComplianceFwsV2: _cfwsV2.size,
|
|
951
|
+
totalComplianceFwReportsV2: _cfwReports.size,
|
|
952
|
+
maxActiveComplianceFwsPerOwner: _cfwMaxActivePerOwner,
|
|
953
|
+
maxPendingComplianceFwReportsPerFw: _cfwMaxPendingReportsPerFw,
|
|
954
|
+
complianceFwIdleMs: _cfwIdleMs,
|
|
955
|
+
complianceFwReportStuckMs: _cfwReportStuckMs,
|
|
956
|
+
fwsByStatus,
|
|
957
|
+
reportsByStatus,
|
|
958
|
+
};
|
|
959
|
+
}
|
|
@@ -722,3 +722,333 @@ export function _resetState() {
|
|
|
722
722
|
_evidenceRetentionMs = COMPLIANCE_DEFAULT_EVIDENCE_RETENTION_MS;
|
|
723
723
|
_reportRetentionMs = COMPLIANCE_DEFAULT_REPORT_RETENTION_MS;
|
|
724
724
|
}
|
|
725
|
+
|
|
726
|
+
// =====================================================================
|
|
727
|
+
// compliance-manager V2 governance overlay (iter17)
|
|
728
|
+
// =====================================================================
|
|
729
|
+
export const CMGR_PROFILE_MATURITY_V2 = Object.freeze({
|
|
730
|
+
PENDING: "pending",
|
|
731
|
+
ACTIVE: "active",
|
|
732
|
+
DEPRECATED: "deprecated",
|
|
733
|
+
ARCHIVED: "archived",
|
|
734
|
+
});
|
|
735
|
+
export const CMGR_AUDIT_LIFECYCLE_V2 = Object.freeze({
|
|
736
|
+
QUEUED: "queued",
|
|
737
|
+
AUDITING: "auditing",
|
|
738
|
+
AUDITED: "audited",
|
|
739
|
+
FAILED: "failed",
|
|
740
|
+
CANCELLED: "cancelled",
|
|
741
|
+
});
|
|
742
|
+
const _cmgrPTrans = new Map([
|
|
743
|
+
[
|
|
744
|
+
CMGR_PROFILE_MATURITY_V2.PENDING,
|
|
745
|
+
new Set([
|
|
746
|
+
CMGR_PROFILE_MATURITY_V2.ACTIVE,
|
|
747
|
+
CMGR_PROFILE_MATURITY_V2.ARCHIVED,
|
|
748
|
+
]),
|
|
749
|
+
],
|
|
750
|
+
[
|
|
751
|
+
CMGR_PROFILE_MATURITY_V2.ACTIVE,
|
|
752
|
+
new Set([
|
|
753
|
+
CMGR_PROFILE_MATURITY_V2.DEPRECATED,
|
|
754
|
+
CMGR_PROFILE_MATURITY_V2.ARCHIVED,
|
|
755
|
+
]),
|
|
756
|
+
],
|
|
757
|
+
[
|
|
758
|
+
CMGR_PROFILE_MATURITY_V2.DEPRECATED,
|
|
759
|
+
new Set([
|
|
760
|
+
CMGR_PROFILE_MATURITY_V2.ACTIVE,
|
|
761
|
+
CMGR_PROFILE_MATURITY_V2.ARCHIVED,
|
|
762
|
+
]),
|
|
763
|
+
],
|
|
764
|
+
[CMGR_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
|
|
765
|
+
]);
|
|
766
|
+
const _cmgrPTerminal = new Set([CMGR_PROFILE_MATURITY_V2.ARCHIVED]);
|
|
767
|
+
const _cmgrJTrans = new Map([
|
|
768
|
+
[
|
|
769
|
+
CMGR_AUDIT_LIFECYCLE_V2.QUEUED,
|
|
770
|
+
new Set([
|
|
771
|
+
CMGR_AUDIT_LIFECYCLE_V2.AUDITING,
|
|
772
|
+
CMGR_AUDIT_LIFECYCLE_V2.CANCELLED,
|
|
773
|
+
]),
|
|
774
|
+
],
|
|
775
|
+
[
|
|
776
|
+
CMGR_AUDIT_LIFECYCLE_V2.AUDITING,
|
|
777
|
+
new Set([
|
|
778
|
+
CMGR_AUDIT_LIFECYCLE_V2.AUDITED,
|
|
779
|
+
CMGR_AUDIT_LIFECYCLE_V2.FAILED,
|
|
780
|
+
CMGR_AUDIT_LIFECYCLE_V2.CANCELLED,
|
|
781
|
+
]),
|
|
782
|
+
],
|
|
783
|
+
[CMGR_AUDIT_LIFECYCLE_V2.AUDITED, new Set()],
|
|
784
|
+
[CMGR_AUDIT_LIFECYCLE_V2.FAILED, new Set()],
|
|
785
|
+
[CMGR_AUDIT_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
786
|
+
]);
|
|
787
|
+
const _cmgrPsV2 = new Map();
|
|
788
|
+
const _cmgrJsV2 = new Map();
|
|
789
|
+
let _cmgrMaxActive = 8,
|
|
790
|
+
_cmgrMaxPending = 20,
|
|
791
|
+
_cmgrIdleMs = 30 * 24 * 60 * 60 * 1000,
|
|
792
|
+
_cmgrStuckMs = 60 * 1000;
|
|
793
|
+
function _cmgrPos(n, label) {
|
|
794
|
+
const v = Math.floor(Number(n));
|
|
795
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
796
|
+
throw new Error(`${label} must be positive integer`);
|
|
797
|
+
return v;
|
|
798
|
+
}
|
|
799
|
+
function _cmgrCheckP(from, to) {
|
|
800
|
+
const a = _cmgrPTrans.get(from);
|
|
801
|
+
if (!a || !a.has(to))
|
|
802
|
+
throw new Error(`invalid cmgr profile transition ${from} → ${to}`);
|
|
803
|
+
}
|
|
804
|
+
function _cmgrCheckJ(from, to) {
|
|
805
|
+
const a = _cmgrJTrans.get(from);
|
|
806
|
+
if (!a || !a.has(to))
|
|
807
|
+
throw new Error(`invalid cmgr audit transition ${from} → ${to}`);
|
|
808
|
+
}
|
|
809
|
+
function _cmgrCountActive(owner) {
|
|
810
|
+
let c = 0;
|
|
811
|
+
for (const p of _cmgrPsV2.values())
|
|
812
|
+
if (p.owner === owner && p.status === CMGR_PROFILE_MATURITY_V2.ACTIVE) c++;
|
|
813
|
+
return c;
|
|
814
|
+
}
|
|
815
|
+
function _cmgrCountPending(profileId) {
|
|
816
|
+
let c = 0;
|
|
817
|
+
for (const j of _cmgrJsV2.values())
|
|
818
|
+
if (
|
|
819
|
+
j.profileId === profileId &&
|
|
820
|
+
(j.status === CMGR_AUDIT_LIFECYCLE_V2.QUEUED ||
|
|
821
|
+
j.status === CMGR_AUDIT_LIFECYCLE_V2.AUDITING)
|
|
822
|
+
)
|
|
823
|
+
c++;
|
|
824
|
+
return c;
|
|
825
|
+
}
|
|
826
|
+
export function setMaxActiveCmgrProfilesPerOwnerV2(n) {
|
|
827
|
+
_cmgrMaxActive = _cmgrPos(n, "maxActiveCmgrProfilesPerOwner");
|
|
828
|
+
}
|
|
829
|
+
export function getMaxActiveCmgrProfilesPerOwnerV2() {
|
|
830
|
+
return _cmgrMaxActive;
|
|
831
|
+
}
|
|
832
|
+
export function setMaxPendingCmgrAuditsPerProfileV2(n) {
|
|
833
|
+
_cmgrMaxPending = _cmgrPos(n, "maxPendingCmgrAuditsPerProfile");
|
|
834
|
+
}
|
|
835
|
+
export function getMaxPendingCmgrAuditsPerProfileV2() {
|
|
836
|
+
return _cmgrMaxPending;
|
|
837
|
+
}
|
|
838
|
+
export function setCmgrProfileIdleMsV2(n) {
|
|
839
|
+
_cmgrIdleMs = _cmgrPos(n, "cmgrProfileIdleMs");
|
|
840
|
+
}
|
|
841
|
+
export function getCmgrProfileIdleMsV2() {
|
|
842
|
+
return _cmgrIdleMs;
|
|
843
|
+
}
|
|
844
|
+
export function setCmgrAuditStuckMsV2(n) {
|
|
845
|
+
_cmgrStuckMs = _cmgrPos(n, "cmgrAuditStuckMs");
|
|
846
|
+
}
|
|
847
|
+
export function getCmgrAuditStuckMsV2() {
|
|
848
|
+
return _cmgrStuckMs;
|
|
849
|
+
}
|
|
850
|
+
export function _resetStateComplianceManagerV2() {
|
|
851
|
+
_cmgrPsV2.clear();
|
|
852
|
+
_cmgrJsV2.clear();
|
|
853
|
+
_cmgrMaxActive = 8;
|
|
854
|
+
_cmgrMaxPending = 20;
|
|
855
|
+
_cmgrIdleMs = 30 * 24 * 60 * 60 * 1000;
|
|
856
|
+
_cmgrStuckMs = 60 * 1000;
|
|
857
|
+
}
|
|
858
|
+
export function registerCmgrProfileV2({ id, owner, framework, metadata } = {}) {
|
|
859
|
+
if (!id || !owner) throw new Error("id and owner required");
|
|
860
|
+
if (_cmgrPsV2.has(id)) throw new Error(`cmgr profile ${id} already exists`);
|
|
861
|
+
const now = Date.now();
|
|
862
|
+
const p = {
|
|
863
|
+
id,
|
|
864
|
+
owner,
|
|
865
|
+
framework: framework || "soc2",
|
|
866
|
+
status: CMGR_PROFILE_MATURITY_V2.PENDING,
|
|
867
|
+
createdAt: now,
|
|
868
|
+
updatedAt: now,
|
|
869
|
+
lastTouchedAt: now,
|
|
870
|
+
activatedAt: null,
|
|
871
|
+
archivedAt: null,
|
|
872
|
+
metadata: { ...(metadata || {}) },
|
|
873
|
+
};
|
|
874
|
+
_cmgrPsV2.set(id, p);
|
|
875
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
876
|
+
}
|
|
877
|
+
export function activateCmgrProfileV2(id) {
|
|
878
|
+
const p = _cmgrPsV2.get(id);
|
|
879
|
+
if (!p) throw new Error(`cmgr profile ${id} not found`);
|
|
880
|
+
const isInitial = p.status === CMGR_PROFILE_MATURITY_V2.PENDING;
|
|
881
|
+
_cmgrCheckP(p.status, CMGR_PROFILE_MATURITY_V2.ACTIVE);
|
|
882
|
+
if (isInitial && _cmgrCountActive(p.owner) >= _cmgrMaxActive)
|
|
883
|
+
throw new Error(`max active cmgr profiles for owner ${p.owner} reached`);
|
|
884
|
+
const now = Date.now();
|
|
885
|
+
p.status = CMGR_PROFILE_MATURITY_V2.ACTIVE;
|
|
886
|
+
p.updatedAt = now;
|
|
887
|
+
p.lastTouchedAt = now;
|
|
888
|
+
if (!p.activatedAt) p.activatedAt = now;
|
|
889
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
890
|
+
}
|
|
891
|
+
export function deprecateCmgrProfileV2(id) {
|
|
892
|
+
const p = _cmgrPsV2.get(id);
|
|
893
|
+
if (!p) throw new Error(`cmgr profile ${id} not found`);
|
|
894
|
+
_cmgrCheckP(p.status, CMGR_PROFILE_MATURITY_V2.DEPRECATED);
|
|
895
|
+
p.status = CMGR_PROFILE_MATURITY_V2.DEPRECATED;
|
|
896
|
+
p.updatedAt = Date.now();
|
|
897
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
898
|
+
}
|
|
899
|
+
export function archiveCmgrProfileV2(id) {
|
|
900
|
+
const p = _cmgrPsV2.get(id);
|
|
901
|
+
if (!p) throw new Error(`cmgr profile ${id} not found`);
|
|
902
|
+
_cmgrCheckP(p.status, CMGR_PROFILE_MATURITY_V2.ARCHIVED);
|
|
903
|
+
const now = Date.now();
|
|
904
|
+
p.status = CMGR_PROFILE_MATURITY_V2.ARCHIVED;
|
|
905
|
+
p.updatedAt = now;
|
|
906
|
+
if (!p.archivedAt) p.archivedAt = now;
|
|
907
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
908
|
+
}
|
|
909
|
+
export function touchCmgrProfileV2(id) {
|
|
910
|
+
const p = _cmgrPsV2.get(id);
|
|
911
|
+
if (!p) throw new Error(`cmgr profile ${id} not found`);
|
|
912
|
+
if (_cmgrPTerminal.has(p.status))
|
|
913
|
+
throw new Error(`cannot touch terminal cmgr profile ${id}`);
|
|
914
|
+
const now = Date.now();
|
|
915
|
+
p.lastTouchedAt = now;
|
|
916
|
+
p.updatedAt = now;
|
|
917
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
918
|
+
}
|
|
919
|
+
export function getCmgrProfileV2(id) {
|
|
920
|
+
const p = _cmgrPsV2.get(id);
|
|
921
|
+
if (!p) return null;
|
|
922
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
923
|
+
}
|
|
924
|
+
export function listCmgrProfilesV2() {
|
|
925
|
+
return [..._cmgrPsV2.values()].map((p) => ({
|
|
926
|
+
...p,
|
|
927
|
+
metadata: { ...p.metadata },
|
|
928
|
+
}));
|
|
929
|
+
}
|
|
930
|
+
export function createCmgrAuditV2({ id, profileId, control, metadata } = {}) {
|
|
931
|
+
if (!id || !profileId) throw new Error("id and profileId required");
|
|
932
|
+
if (_cmgrJsV2.has(id)) throw new Error(`cmgr audit ${id} already exists`);
|
|
933
|
+
if (!_cmgrPsV2.has(profileId))
|
|
934
|
+
throw new Error(`cmgr profile ${profileId} not found`);
|
|
935
|
+
if (_cmgrCountPending(profileId) >= _cmgrMaxPending)
|
|
936
|
+
throw new Error(`max pending cmgr audits for profile ${profileId} reached`);
|
|
937
|
+
const now = Date.now();
|
|
938
|
+
const j = {
|
|
939
|
+
id,
|
|
940
|
+
profileId,
|
|
941
|
+
control: control || "",
|
|
942
|
+
status: CMGR_AUDIT_LIFECYCLE_V2.QUEUED,
|
|
943
|
+
createdAt: now,
|
|
944
|
+
updatedAt: now,
|
|
945
|
+
startedAt: null,
|
|
946
|
+
settledAt: null,
|
|
947
|
+
metadata: { ...(metadata || {}) },
|
|
948
|
+
};
|
|
949
|
+
_cmgrJsV2.set(id, j);
|
|
950
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
951
|
+
}
|
|
952
|
+
export function auditingCmgrAuditV2(id) {
|
|
953
|
+
const j = _cmgrJsV2.get(id);
|
|
954
|
+
if (!j) throw new Error(`cmgr audit ${id} not found`);
|
|
955
|
+
_cmgrCheckJ(j.status, CMGR_AUDIT_LIFECYCLE_V2.AUDITING);
|
|
956
|
+
const now = Date.now();
|
|
957
|
+
j.status = CMGR_AUDIT_LIFECYCLE_V2.AUDITING;
|
|
958
|
+
j.updatedAt = now;
|
|
959
|
+
if (!j.startedAt) j.startedAt = now;
|
|
960
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
961
|
+
}
|
|
962
|
+
export function completeAuditCmgrV2(id) {
|
|
963
|
+
const j = _cmgrJsV2.get(id);
|
|
964
|
+
if (!j) throw new Error(`cmgr audit ${id} not found`);
|
|
965
|
+
_cmgrCheckJ(j.status, CMGR_AUDIT_LIFECYCLE_V2.AUDITED);
|
|
966
|
+
const now = Date.now();
|
|
967
|
+
j.status = CMGR_AUDIT_LIFECYCLE_V2.AUDITED;
|
|
968
|
+
j.updatedAt = now;
|
|
969
|
+
if (!j.settledAt) j.settledAt = now;
|
|
970
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
971
|
+
}
|
|
972
|
+
export function failCmgrAuditV2(id, reason) {
|
|
973
|
+
const j = _cmgrJsV2.get(id);
|
|
974
|
+
if (!j) throw new Error(`cmgr audit ${id} not found`);
|
|
975
|
+
_cmgrCheckJ(j.status, CMGR_AUDIT_LIFECYCLE_V2.FAILED);
|
|
976
|
+
const now = Date.now();
|
|
977
|
+
j.status = CMGR_AUDIT_LIFECYCLE_V2.FAILED;
|
|
978
|
+
j.updatedAt = now;
|
|
979
|
+
if (!j.settledAt) j.settledAt = now;
|
|
980
|
+
if (reason) j.metadata.failReason = String(reason);
|
|
981
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
982
|
+
}
|
|
983
|
+
export function cancelCmgrAuditV2(id, reason) {
|
|
984
|
+
const j = _cmgrJsV2.get(id);
|
|
985
|
+
if (!j) throw new Error(`cmgr audit ${id} not found`);
|
|
986
|
+
_cmgrCheckJ(j.status, CMGR_AUDIT_LIFECYCLE_V2.CANCELLED);
|
|
987
|
+
const now = Date.now();
|
|
988
|
+
j.status = CMGR_AUDIT_LIFECYCLE_V2.CANCELLED;
|
|
989
|
+
j.updatedAt = now;
|
|
990
|
+
if (!j.settledAt) j.settledAt = now;
|
|
991
|
+
if (reason) j.metadata.cancelReason = String(reason);
|
|
992
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
993
|
+
}
|
|
994
|
+
export function getCmgrAuditV2(id) {
|
|
995
|
+
const j = _cmgrJsV2.get(id);
|
|
996
|
+
if (!j) return null;
|
|
997
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
998
|
+
}
|
|
999
|
+
export function listCmgrAuditsV2() {
|
|
1000
|
+
return [..._cmgrJsV2.values()].map((j) => ({
|
|
1001
|
+
...j,
|
|
1002
|
+
metadata: { ...j.metadata },
|
|
1003
|
+
}));
|
|
1004
|
+
}
|
|
1005
|
+
export function autoDeprecateIdleCmgrProfilesV2({ now } = {}) {
|
|
1006
|
+
const t = now ?? Date.now();
|
|
1007
|
+
const flipped = [];
|
|
1008
|
+
for (const p of _cmgrPsV2.values())
|
|
1009
|
+
if (
|
|
1010
|
+
p.status === CMGR_PROFILE_MATURITY_V2.ACTIVE &&
|
|
1011
|
+
t - p.lastTouchedAt >= _cmgrIdleMs
|
|
1012
|
+
) {
|
|
1013
|
+
p.status = CMGR_PROFILE_MATURITY_V2.DEPRECATED;
|
|
1014
|
+
p.updatedAt = t;
|
|
1015
|
+
flipped.push(p.id);
|
|
1016
|
+
}
|
|
1017
|
+
return { flipped, count: flipped.length };
|
|
1018
|
+
}
|
|
1019
|
+
export function autoFailStuckCmgrAuditsV2({ now } = {}) {
|
|
1020
|
+
const t = now ?? Date.now();
|
|
1021
|
+
const flipped = [];
|
|
1022
|
+
for (const j of _cmgrJsV2.values())
|
|
1023
|
+
if (
|
|
1024
|
+
j.status === CMGR_AUDIT_LIFECYCLE_V2.AUDITING &&
|
|
1025
|
+
j.startedAt != null &&
|
|
1026
|
+
t - j.startedAt >= _cmgrStuckMs
|
|
1027
|
+
) {
|
|
1028
|
+
j.status = CMGR_AUDIT_LIFECYCLE_V2.FAILED;
|
|
1029
|
+
j.updatedAt = t;
|
|
1030
|
+
if (!j.settledAt) j.settledAt = t;
|
|
1031
|
+
j.metadata.failReason = "auto-fail-stuck";
|
|
1032
|
+
flipped.push(j.id);
|
|
1033
|
+
}
|
|
1034
|
+
return { flipped, count: flipped.length };
|
|
1035
|
+
}
|
|
1036
|
+
export function getComplianceManagerGovStatsV2() {
|
|
1037
|
+
const profilesByStatus = {};
|
|
1038
|
+
for (const v of Object.values(CMGR_PROFILE_MATURITY_V2))
|
|
1039
|
+
profilesByStatus[v] = 0;
|
|
1040
|
+
for (const p of _cmgrPsV2.values()) profilesByStatus[p.status]++;
|
|
1041
|
+
const auditsByStatus = {};
|
|
1042
|
+
for (const v of Object.values(CMGR_AUDIT_LIFECYCLE_V2)) auditsByStatus[v] = 0;
|
|
1043
|
+
for (const j of _cmgrJsV2.values()) auditsByStatus[j.status]++;
|
|
1044
|
+
return {
|
|
1045
|
+
totalCmgrProfilesV2: _cmgrPsV2.size,
|
|
1046
|
+
totalCmgrAuditsV2: _cmgrJsV2.size,
|
|
1047
|
+
maxActiveCmgrProfilesPerOwner: _cmgrMaxActive,
|
|
1048
|
+
maxPendingCmgrAuditsPerProfile: _cmgrMaxPending,
|
|
1049
|
+
cmgrProfileIdleMs: _cmgrIdleMs,
|
|
1050
|
+
cmgrAuditStuckMs: _cmgrStuckMs,
|
|
1051
|
+
profilesByStatus,
|
|
1052
|
+
auditsByStatus,
|
|
1053
|
+
};
|
|
1054
|
+
}
|