chainlesschain 0.143.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 +196 -28
- package/src/commands/activitypub.js +157 -27
- package/src/commands/agent.js +587 -103
- package/src/commands/audit.js +206 -0
- package/src/commands/bi.js +152 -27
- package/src/commands/bm25.js +111 -27
- package/src/commands/browse.js +190 -29
- package/src/commands/ccron.js +128 -28
- package/src/commands/chat.js +207 -0
- package/src/commands/compliance.js +414 -34
- package/src/commands/compt.js +127 -29
- package/src/commands/consol.js +8 -2
- package/src/commands/cowork.js +580 -34
- package/src/commands/crosschain.js +182 -28
- package/src/commands/dao.js +182 -28
- package/src/commands/dlp.js +172 -27
- package/src/commands/economy.js +205 -50
- package/src/commands/evolution.js +203 -50
- package/src/commands/evomap.js +182 -27
- package/src/commands/fflag.js +74 -22
- package/src/commands/git.js +177 -37
- package/src/commands/hardening.js +209 -0
- package/src/commands/hmemory.js +204 -50
- package/src/commands/incentive.js +209 -0
- package/src/commands/inference.js +170 -34
- package/src/commands/itbudget.js +149 -33
- package/src/commands/kg.js +206 -0
- package/src/commands/lowcode.js +195 -38
- package/src/commands/marketplace.js +206 -0
- package/src/commands/matrix.js +179 -27
- package/src/commands/mcpscaf.js +145 -33
- package/src/commands/meminj.js +145 -33
- package/src/commands/nostr.js +178 -27
- package/src/commands/orchestrate.js +217 -0
- package/src/commands/orchgov.js +144 -33
- package/src/commands/pdfp.js +109 -27
- package/src/commands/perf.js +169 -32
- package/src/commands/perm.js +144 -33
- package/src/commands/pipeline.js +207 -52
- package/src/commands/planmode.js +141 -32
- package/src/commands/privacy.js +203 -0
- package/src/commands/promcomp.js +111 -27
- package/src/commands/recommend.js +177 -34
- package/src/commands/reputation.js +208 -0
- package/src/commands/sandbox.js +206 -0
- package/src/commands/seshhook.js +145 -33
- package/src/commands/seshsearch.js +141 -33
- package/src/commands/seshtail.js +144 -33
- package/src/commands/seshu.js +152 -33
- package/src/commands/sganal.js +123 -29
- package/src/commands/siem.js +201 -34
- package/src/commands/sla.js +212 -0
- package/src/commands/slotfill.js +146 -33
- package/src/commands/social.js +157 -32
- package/src/commands/stress.js +206 -0
- package/src/commands/svccont.js +145 -33
- package/src/commands/terraform.js +206 -0
- package/src/commands/tms.js +171 -33
- package/src/commands/topiccls.js +146 -33
- package/src/commands/uprof.js +141 -32
- package/src/commands/vcheck.js +122 -28
- package/src/commands/webfetch.js +141 -32
- package/src/commands/zkp.js +184 -28
- package/src/index.js +40 -0
- package/src/lib/a2a-protocol.js +319 -51
- package/src/lib/activitypub-bridge.js +288 -50
- package/src/lib/agent-economy.js +304 -51
- package/src/lib/app-builder.js +279 -46
- package/src/lib/audit-logger.js +321 -0
- package/src/lib/autonomous-agent.js +284 -48
- package/src/lib/bi-engine.js +283 -49
- package/src/lib/bm25-search.js +301 -49
- package/src/lib/browser-automation.js +296 -49
- package/src/lib/chat-core.js +336 -0
- package/src/lib/claude-code-bridge.js +341 -0
- package/src/lib/compliance-framework-reporter.js +305 -51
- package/src/lib/compliance-manager.js +330 -0
- package/src/lib/compression-telemetry.js +301 -49
- package/src/lib/content-recommender.js +317 -52
- package/src/lib/cowork-cron.js +298 -49
- package/src/lib/cowork-learning.js +333 -0
- package/src/lib/cowork-task-runner.js +308 -51
- package/src/lib/cowork-workflow.js +327 -0
- package/src/lib/cross-chain.js +311 -51
- package/src/lib/dao-governance.js +280 -46
- package/src/lib/dlp-engine.js +287 -49
- package/src/lib/evolution-system.js +278 -47
- package/src/lib/evomap-manager.js +280 -46
- package/src/lib/execution-backend.js +294 -48
- package/src/lib/feature-flags.js +294 -49
- package/src/lib/git-integration.js +285 -47
- package/src/lib/hardening-manager.js +341 -0
- package/src/lib/hierarchical-memory.js +284 -48
- package/src/lib/inference-network.js +308 -51
- package/src/lib/iteration-budget.js +302 -50
- package/src/lib/knowledge-graph.js +333 -0
- package/src/lib/matrix-bridge.js +281 -47
- package/src/lib/mcp-scaffold.js +318 -54
- package/src/lib/memory-injection.js +288 -49
- package/src/lib/nostr-bridge.js +286 -49
- package/src/lib/orchestrator.js +293 -48
- package/src/lib/pdf-parser.js +298 -49
- package/src/lib/perf-tuning.js +309 -50
- package/src/lib/permission-engine.js +287 -49
- package/src/lib/pipeline-orchestrator.js +289 -49
- package/src/lib/plan-mode.js +298 -51
- package/src/lib/privacy-computing.js +335 -0
- package/src/lib/reputation-optimizer.js +340 -0
- package/src/lib/sandbox-v2.js +327 -0
- package/src/lib/service-container.js +313 -52
- package/src/lib/session-consolidator.js +296 -49
- package/src/lib/session-hooks.js +312 -53
- package/src/lib/session-search.js +304 -51
- package/src/lib/session-tail.js +288 -49
- package/src/lib/session-usage.js +298 -52
- package/src/lib/siem-exporter.js +298 -51
- package/src/lib/skill-marketplace.js +345 -0
- package/src/lib/sla-manager.js +341 -0
- package/src/lib/slot-filler.js +303 -51
- package/src/lib/social-graph-analytics.js +295 -49
- package/src/lib/social-graph.js +272 -49
- package/src/lib/stress-tester.js +342 -0
- package/src/lib/sub-agent-registry.js +302 -53
- package/src/lib/task-model-selector.js +302 -50
- package/src/lib/terraform-manager.js +333 -0
- package/src/lib/todo-manager.js +281 -47
- package/src/lib/token-incentive.js +341 -0
- package/src/lib/topic-classifier.js +297 -49
- package/src/lib/user-profile.js +294 -50
- package/src/lib/version-checker.js +304 -50
- package/src/lib/web-fetch.js +292 -51
- package/src/lib/zkp-engine.js +286 -49
|
@@ -599,25 +599,62 @@ export function _resetState() {
|
|
|
599
599
|
_customTemplates.clear();
|
|
600
600
|
}
|
|
601
601
|
|
|
602
|
-
|
|
603
602
|
// ===== V2 Surface: Compliance Framework Reporter governance overlay (CLI v0.138.0) =====
|
|
604
603
|
export const COMPLIANCE_FW_MATURITY_V2 = Object.freeze({
|
|
605
|
-
PENDING: "pending",
|
|
604
|
+
PENDING: "pending",
|
|
605
|
+
ACTIVE: "active",
|
|
606
|
+
DEPRECATED: "deprecated",
|
|
607
|
+
ARCHIVED: "archived",
|
|
606
608
|
});
|
|
607
609
|
export const COMPLIANCE_FW_REPORT_LIFECYCLE_V2 = Object.freeze({
|
|
608
|
-
QUEUED: "queued",
|
|
610
|
+
QUEUED: "queued",
|
|
611
|
+
GENERATING: "generating",
|
|
612
|
+
COMPLETED: "completed",
|
|
613
|
+
FAILED: "failed",
|
|
614
|
+
CANCELLED: "cancelled",
|
|
609
615
|
});
|
|
610
616
|
|
|
611
617
|
const _cfwTrans = new Map([
|
|
612
|
-
[
|
|
613
|
-
|
|
614
|
-
|
|
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
|
+
],
|
|
615
639
|
[COMPLIANCE_FW_MATURITY_V2.ARCHIVED, new Set()],
|
|
616
640
|
]);
|
|
617
641
|
const _cfwTerminal = new Set([COMPLIANCE_FW_MATURITY_V2.ARCHIVED]);
|
|
618
642
|
const _cfwRepTrans = new Map([
|
|
619
|
-
[
|
|
620
|
-
|
|
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
|
+
],
|
|
621
658
|
[COMPLIANCE_FW_REPORT_LIFECYCLE_V2.COMPLETED, new Set()],
|
|
622
659
|
[COMPLIANCE_FW_REPORT_LIFECYCLE_V2.FAILED, new Set()],
|
|
623
660
|
[COMPLIANCE_FW_REPORT_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
@@ -630,76 +667,293 @@ let _cfwMaxPendingReportsPerFw = 15;
|
|
|
630
667
|
let _cfwIdleMs = 90 * 24 * 60 * 60 * 1000;
|
|
631
668
|
let _cfwReportStuckMs = 10 * 60 * 1000;
|
|
632
669
|
|
|
633
|
-
function _cfwPos(n, lbl) {
|
|
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
|
+
}
|
|
634
676
|
|
|
635
|
-
export function setMaxActiveComplianceFwsPerOwnerV2(n) {
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
export function
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
export function
|
|
642
|
-
|
|
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
|
+
}
|
|
643
701
|
|
|
644
702
|
export function _resetStateComplianceFwReporterV2() {
|
|
645
|
-
_cfwsV2.clear();
|
|
646
|
-
|
|
647
|
-
|
|
703
|
+
_cfwsV2.clear();
|
|
704
|
+
_cfwReports.clear();
|
|
705
|
+
_cfwMaxActivePerOwner = 8;
|
|
706
|
+
_cfwMaxPendingReportsPerFw = 15;
|
|
707
|
+
_cfwIdleMs = 90 * 24 * 60 * 60 * 1000;
|
|
708
|
+
_cfwReportStuckMs = 10 * 60 * 1000;
|
|
648
709
|
}
|
|
649
710
|
|
|
650
711
|
export function registerComplianceFwV2({ id, owner, name, metadata } = {}) {
|
|
651
712
|
if (!id || typeof id !== "string") throw new Error("id is required");
|
|
652
713
|
if (!owner || typeof owner !== "string") throw new Error("owner is required");
|
|
653
|
-
if (_cfwsV2.has(id))
|
|
714
|
+
if (_cfwsV2.has(id))
|
|
715
|
+
throw new Error(`compliance framework ${id} already registered`);
|
|
654
716
|
const now = Date.now();
|
|
655
|
-
const f = {
|
|
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
|
+
};
|
|
656
729
|
_cfwsV2.set(id, f);
|
|
657
730
|
return { ...f, metadata: { ...f.metadata } };
|
|
658
731
|
}
|
|
659
|
-
function _cfwCheckF(from, to) {
|
|
660
|
-
|
|
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
|
+
}
|
|
661
743
|
|
|
662
744
|
export function activateComplianceFwV2(id) {
|
|
663
|
-
const f = _cfwsV2.get(id);
|
|
745
|
+
const f = _cfwsV2.get(id);
|
|
746
|
+
if (!f) throw new Error(`compliance framework ${id} not found`);
|
|
664
747
|
_cfwCheckF(f.status, COMPLIANCE_FW_MATURITY_V2.ACTIVE);
|
|
665
748
|
const recovery = f.status === COMPLIANCE_FW_MATURITY_V2.DEPRECATED;
|
|
666
|
-
if (!recovery) {
|
|
667
|
-
|
|
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();
|
|
668
769
|
return { ...f, metadata: { ...f.metadata } };
|
|
669
770
|
}
|
|
670
|
-
export function
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
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
|
+
}
|
|
675
802
|
|
|
676
|
-
function _cfwCountPendingReports(frameworkId) {
|
|
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
|
+
}
|
|
677
814
|
|
|
678
|
-
export function createComplianceFwReportV2({
|
|
815
|
+
export function createComplianceFwReportV2({
|
|
816
|
+
id,
|
|
817
|
+
frameworkId,
|
|
818
|
+
format,
|
|
819
|
+
metadata,
|
|
820
|
+
} = {}) {
|
|
679
821
|
if (!id || typeof id !== "string") throw new Error("id is required");
|
|
680
|
-
if (!frameworkId || typeof frameworkId !== "string")
|
|
681
|
-
|
|
682
|
-
if (
|
|
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`);
|
|
683
828
|
const pending = _cfwCountPendingReports(frameworkId);
|
|
684
|
-
if (pending >= _cfwMaxPendingReportsPerFw)
|
|
829
|
+
if (pending >= _cfwMaxPendingReportsPerFw)
|
|
830
|
+
throw new Error(
|
|
831
|
+
`max pending compliance framework reports per framework (${_cfwMaxPendingReportsPerFw}) reached for ${frameworkId}`,
|
|
832
|
+
);
|
|
685
833
|
const now = Date.now();
|
|
686
|
-
const r = {
|
|
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
|
+
};
|
|
687
845
|
_cfwReports.set(id, r);
|
|
688
846
|
return { ...r, metadata: { ...r.metadata } };
|
|
689
847
|
}
|
|
690
|
-
function _cfwCheckR(from, to) {
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
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
|
+
}
|
|
697
908
|
|
|
698
|
-
export function autoDeprecateIdleComplianceFwsV2({ now } = {}) {
|
|
699
|
-
|
|
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
|
+
}
|
|
700
940
|
|
|
701
941
|
export function getComplianceFwReporterGovStatsV2() {
|
|
702
|
-
const fwsByStatus = {};
|
|
703
|
-
|
|
704
|
-
|
|
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
|
+
};
|
|
705
959
|
}
|