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
package/src/lib/audit-logger.js
CHANGED
|
@@ -741,3 +741,324 @@ export function _resetStateV2() {
|
|
|
741
741
|
_archiveRetentionMs = AUDIT_DEFAULT_ARCHIVE_RETENTION_MS;
|
|
742
742
|
_purgeRetentionMs = AUDIT_DEFAULT_PURGE_RETENTION_MS;
|
|
743
743
|
}
|
|
744
|
+
|
|
745
|
+
// =====================================================================
|
|
746
|
+
// audit-logger V2 governance overlay (iter16)
|
|
747
|
+
// =====================================================================
|
|
748
|
+
export const AUD_PROFILE_MATURITY_V2 = Object.freeze({
|
|
749
|
+
PENDING: "pending",
|
|
750
|
+
ACTIVE: "active",
|
|
751
|
+
SUSPENDED: "suspended",
|
|
752
|
+
ARCHIVED: "archived",
|
|
753
|
+
});
|
|
754
|
+
export const AUD_WRITE_LIFECYCLE_V2 = Object.freeze({
|
|
755
|
+
QUEUED: "queued",
|
|
756
|
+
WRITING: "writing",
|
|
757
|
+
WRITTEN: "written",
|
|
758
|
+
FAILED: "failed",
|
|
759
|
+
CANCELLED: "cancelled",
|
|
760
|
+
});
|
|
761
|
+
const _audPTrans = new Map([
|
|
762
|
+
[
|
|
763
|
+
AUD_PROFILE_MATURITY_V2.PENDING,
|
|
764
|
+
new Set([AUD_PROFILE_MATURITY_V2.ACTIVE, AUD_PROFILE_MATURITY_V2.ARCHIVED]),
|
|
765
|
+
],
|
|
766
|
+
[
|
|
767
|
+
AUD_PROFILE_MATURITY_V2.ACTIVE,
|
|
768
|
+
new Set([
|
|
769
|
+
AUD_PROFILE_MATURITY_V2.SUSPENDED,
|
|
770
|
+
AUD_PROFILE_MATURITY_V2.ARCHIVED,
|
|
771
|
+
]),
|
|
772
|
+
],
|
|
773
|
+
[
|
|
774
|
+
AUD_PROFILE_MATURITY_V2.SUSPENDED,
|
|
775
|
+
new Set([AUD_PROFILE_MATURITY_V2.ACTIVE, AUD_PROFILE_MATURITY_V2.ARCHIVED]),
|
|
776
|
+
],
|
|
777
|
+
[AUD_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
|
|
778
|
+
]);
|
|
779
|
+
const _audPTerminal = new Set([AUD_PROFILE_MATURITY_V2.ARCHIVED]);
|
|
780
|
+
const _audJTrans = new Map([
|
|
781
|
+
[
|
|
782
|
+
AUD_WRITE_LIFECYCLE_V2.QUEUED,
|
|
783
|
+
new Set([AUD_WRITE_LIFECYCLE_V2.WRITING, AUD_WRITE_LIFECYCLE_V2.CANCELLED]),
|
|
784
|
+
],
|
|
785
|
+
[
|
|
786
|
+
AUD_WRITE_LIFECYCLE_V2.WRITING,
|
|
787
|
+
new Set([
|
|
788
|
+
AUD_WRITE_LIFECYCLE_V2.WRITTEN,
|
|
789
|
+
AUD_WRITE_LIFECYCLE_V2.FAILED,
|
|
790
|
+
AUD_WRITE_LIFECYCLE_V2.CANCELLED,
|
|
791
|
+
]),
|
|
792
|
+
],
|
|
793
|
+
[AUD_WRITE_LIFECYCLE_V2.WRITTEN, new Set()],
|
|
794
|
+
[AUD_WRITE_LIFECYCLE_V2.FAILED, new Set()],
|
|
795
|
+
[AUD_WRITE_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
796
|
+
]);
|
|
797
|
+
const _audPsV2 = new Map();
|
|
798
|
+
const _audJsV2 = new Map();
|
|
799
|
+
let _audMaxActive = 8,
|
|
800
|
+
_audMaxPending = 30,
|
|
801
|
+
_audIdleMs = 30 * 24 * 60 * 60 * 1000,
|
|
802
|
+
_audStuckMs = 60 * 1000;
|
|
803
|
+
function _audPos(n, label) {
|
|
804
|
+
const v = Math.floor(Number(n));
|
|
805
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
806
|
+
throw new Error(`${label} must be positive integer`);
|
|
807
|
+
return v;
|
|
808
|
+
}
|
|
809
|
+
function _audCheckP(from, to) {
|
|
810
|
+
const a = _audPTrans.get(from);
|
|
811
|
+
if (!a || !a.has(to))
|
|
812
|
+
throw new Error(`invalid aud profile transition ${from} → ${to}`);
|
|
813
|
+
}
|
|
814
|
+
function _audCheckJ(from, to) {
|
|
815
|
+
const a = _audJTrans.get(from);
|
|
816
|
+
if (!a || !a.has(to))
|
|
817
|
+
throw new Error(`invalid aud write transition ${from} → ${to}`);
|
|
818
|
+
}
|
|
819
|
+
function _audCountActive(owner) {
|
|
820
|
+
let c = 0;
|
|
821
|
+
for (const p of _audPsV2.values())
|
|
822
|
+
if (p.owner === owner && p.status === AUD_PROFILE_MATURITY_V2.ACTIVE) c++;
|
|
823
|
+
return c;
|
|
824
|
+
}
|
|
825
|
+
function _audCountPending(profileId) {
|
|
826
|
+
let c = 0;
|
|
827
|
+
for (const j of _audJsV2.values())
|
|
828
|
+
if (
|
|
829
|
+
j.profileId === profileId &&
|
|
830
|
+
(j.status === AUD_WRITE_LIFECYCLE_V2.QUEUED ||
|
|
831
|
+
j.status === AUD_WRITE_LIFECYCLE_V2.WRITING)
|
|
832
|
+
)
|
|
833
|
+
c++;
|
|
834
|
+
return c;
|
|
835
|
+
}
|
|
836
|
+
export function setMaxActiveAudProfilesPerOwnerV2(n) {
|
|
837
|
+
_audMaxActive = _audPos(n, "maxActiveAudProfilesPerOwner");
|
|
838
|
+
}
|
|
839
|
+
export function getMaxActiveAudProfilesPerOwnerV2() {
|
|
840
|
+
return _audMaxActive;
|
|
841
|
+
}
|
|
842
|
+
export function setMaxPendingAudWritesPerProfileV2(n) {
|
|
843
|
+
_audMaxPending = _audPos(n, "maxPendingAudWritesPerProfile");
|
|
844
|
+
}
|
|
845
|
+
export function getMaxPendingAudWritesPerProfileV2() {
|
|
846
|
+
return _audMaxPending;
|
|
847
|
+
}
|
|
848
|
+
export function setAudProfileIdleMsV2(n) {
|
|
849
|
+
_audIdleMs = _audPos(n, "audProfileIdleMs");
|
|
850
|
+
}
|
|
851
|
+
export function getAudProfileIdleMsV2() {
|
|
852
|
+
return _audIdleMs;
|
|
853
|
+
}
|
|
854
|
+
export function setAudWriteStuckMsV2(n) {
|
|
855
|
+
_audStuckMs = _audPos(n, "audWriteStuckMs");
|
|
856
|
+
}
|
|
857
|
+
export function getAudWriteStuckMsV2() {
|
|
858
|
+
return _audStuckMs;
|
|
859
|
+
}
|
|
860
|
+
export function _resetStateAuditLoggerV2() {
|
|
861
|
+
_audPsV2.clear();
|
|
862
|
+
_audJsV2.clear();
|
|
863
|
+
_audMaxActive = 8;
|
|
864
|
+
_audMaxPending = 30;
|
|
865
|
+
_audIdleMs = 30 * 24 * 60 * 60 * 1000;
|
|
866
|
+
_audStuckMs = 60 * 1000;
|
|
867
|
+
}
|
|
868
|
+
export function registerAudProfileV2({ id, owner, level, metadata } = {}) {
|
|
869
|
+
if (!id || !owner) throw new Error("id and owner required");
|
|
870
|
+
if (_audPsV2.has(id)) throw new Error(`aud profile ${id} already exists`);
|
|
871
|
+
const now = Date.now();
|
|
872
|
+
const p = {
|
|
873
|
+
id,
|
|
874
|
+
owner,
|
|
875
|
+
level: level || "info",
|
|
876
|
+
status: AUD_PROFILE_MATURITY_V2.PENDING,
|
|
877
|
+
createdAt: now,
|
|
878
|
+
updatedAt: now,
|
|
879
|
+
lastTouchedAt: now,
|
|
880
|
+
activatedAt: null,
|
|
881
|
+
archivedAt: null,
|
|
882
|
+
metadata: { ...(metadata || {}) },
|
|
883
|
+
};
|
|
884
|
+
_audPsV2.set(id, p);
|
|
885
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
886
|
+
}
|
|
887
|
+
export function activateAudProfileV2(id) {
|
|
888
|
+
const p = _audPsV2.get(id);
|
|
889
|
+
if (!p) throw new Error(`aud profile ${id} not found`);
|
|
890
|
+
const isInitial = p.status === AUD_PROFILE_MATURITY_V2.PENDING;
|
|
891
|
+
_audCheckP(p.status, AUD_PROFILE_MATURITY_V2.ACTIVE);
|
|
892
|
+
if (isInitial && _audCountActive(p.owner) >= _audMaxActive)
|
|
893
|
+
throw new Error(`max active aud profiles for owner ${p.owner} reached`);
|
|
894
|
+
const now = Date.now();
|
|
895
|
+
p.status = AUD_PROFILE_MATURITY_V2.ACTIVE;
|
|
896
|
+
p.updatedAt = now;
|
|
897
|
+
p.lastTouchedAt = now;
|
|
898
|
+
if (!p.activatedAt) p.activatedAt = now;
|
|
899
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
900
|
+
}
|
|
901
|
+
export function suspendAudProfileV2(id) {
|
|
902
|
+
const p = _audPsV2.get(id);
|
|
903
|
+
if (!p) throw new Error(`aud profile ${id} not found`);
|
|
904
|
+
_audCheckP(p.status, AUD_PROFILE_MATURITY_V2.SUSPENDED);
|
|
905
|
+
p.status = AUD_PROFILE_MATURITY_V2.SUSPENDED;
|
|
906
|
+
p.updatedAt = Date.now();
|
|
907
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
908
|
+
}
|
|
909
|
+
export function archiveAudProfileV2(id) {
|
|
910
|
+
const p = _audPsV2.get(id);
|
|
911
|
+
if (!p) throw new Error(`aud profile ${id} not found`);
|
|
912
|
+
_audCheckP(p.status, AUD_PROFILE_MATURITY_V2.ARCHIVED);
|
|
913
|
+
const now = Date.now();
|
|
914
|
+
p.status = AUD_PROFILE_MATURITY_V2.ARCHIVED;
|
|
915
|
+
p.updatedAt = now;
|
|
916
|
+
if (!p.archivedAt) p.archivedAt = now;
|
|
917
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
918
|
+
}
|
|
919
|
+
export function touchAudProfileV2(id) {
|
|
920
|
+
const p = _audPsV2.get(id);
|
|
921
|
+
if (!p) throw new Error(`aud profile ${id} not found`);
|
|
922
|
+
if (_audPTerminal.has(p.status))
|
|
923
|
+
throw new Error(`cannot touch terminal aud profile ${id}`);
|
|
924
|
+
const now = Date.now();
|
|
925
|
+
p.lastTouchedAt = now;
|
|
926
|
+
p.updatedAt = now;
|
|
927
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
928
|
+
}
|
|
929
|
+
export function getAudProfileV2(id) {
|
|
930
|
+
const p = _audPsV2.get(id);
|
|
931
|
+
if (!p) return null;
|
|
932
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
933
|
+
}
|
|
934
|
+
export function listAudProfilesV2() {
|
|
935
|
+
return [..._audPsV2.values()].map((p) => ({
|
|
936
|
+
...p,
|
|
937
|
+
metadata: { ...p.metadata },
|
|
938
|
+
}));
|
|
939
|
+
}
|
|
940
|
+
export function createAudWriteV2({ id, profileId, key, metadata } = {}) {
|
|
941
|
+
if (!id || !profileId) throw new Error("id and profileId required");
|
|
942
|
+
if (_audJsV2.has(id)) throw new Error(`aud write ${id} already exists`);
|
|
943
|
+
if (!_audPsV2.has(profileId))
|
|
944
|
+
throw new Error(`aud profile ${profileId} not found`);
|
|
945
|
+
if (_audCountPending(profileId) >= _audMaxPending)
|
|
946
|
+
throw new Error(`max pending aud writes for profile ${profileId} reached`);
|
|
947
|
+
const now = Date.now();
|
|
948
|
+
const j = {
|
|
949
|
+
id,
|
|
950
|
+
profileId,
|
|
951
|
+
key: key || "",
|
|
952
|
+
status: AUD_WRITE_LIFECYCLE_V2.QUEUED,
|
|
953
|
+
createdAt: now,
|
|
954
|
+
updatedAt: now,
|
|
955
|
+
startedAt: null,
|
|
956
|
+
settledAt: null,
|
|
957
|
+
metadata: { ...(metadata || {}) },
|
|
958
|
+
};
|
|
959
|
+
_audJsV2.set(id, j);
|
|
960
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
961
|
+
}
|
|
962
|
+
export function writingAudWriteV2(id) {
|
|
963
|
+
const j = _audJsV2.get(id);
|
|
964
|
+
if (!j) throw new Error(`aud write ${id} not found`);
|
|
965
|
+
_audCheckJ(j.status, AUD_WRITE_LIFECYCLE_V2.WRITING);
|
|
966
|
+
const now = Date.now();
|
|
967
|
+
j.status = AUD_WRITE_LIFECYCLE_V2.WRITING;
|
|
968
|
+
j.updatedAt = now;
|
|
969
|
+
if (!j.startedAt) j.startedAt = now;
|
|
970
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
971
|
+
}
|
|
972
|
+
export function writeOkAudV2(id) {
|
|
973
|
+
const j = _audJsV2.get(id);
|
|
974
|
+
if (!j) throw new Error(`aud write ${id} not found`);
|
|
975
|
+
_audCheckJ(j.status, AUD_WRITE_LIFECYCLE_V2.WRITTEN);
|
|
976
|
+
const now = Date.now();
|
|
977
|
+
j.status = AUD_WRITE_LIFECYCLE_V2.WRITTEN;
|
|
978
|
+
j.updatedAt = now;
|
|
979
|
+
if (!j.settledAt) j.settledAt = now;
|
|
980
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
981
|
+
}
|
|
982
|
+
export function failAudWriteV2(id, reason) {
|
|
983
|
+
const j = _audJsV2.get(id);
|
|
984
|
+
if (!j) throw new Error(`aud write ${id} not found`);
|
|
985
|
+
_audCheckJ(j.status, AUD_WRITE_LIFECYCLE_V2.FAILED);
|
|
986
|
+
const now = Date.now();
|
|
987
|
+
j.status = AUD_WRITE_LIFECYCLE_V2.FAILED;
|
|
988
|
+
j.updatedAt = now;
|
|
989
|
+
if (!j.settledAt) j.settledAt = now;
|
|
990
|
+
if (reason) j.metadata.failReason = String(reason);
|
|
991
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
992
|
+
}
|
|
993
|
+
export function cancelAudWriteV2(id, reason) {
|
|
994
|
+
const j = _audJsV2.get(id);
|
|
995
|
+
if (!j) throw new Error(`aud write ${id} not found`);
|
|
996
|
+
_audCheckJ(j.status, AUD_WRITE_LIFECYCLE_V2.CANCELLED);
|
|
997
|
+
const now = Date.now();
|
|
998
|
+
j.status = AUD_WRITE_LIFECYCLE_V2.CANCELLED;
|
|
999
|
+
j.updatedAt = now;
|
|
1000
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1001
|
+
if (reason) j.metadata.cancelReason = String(reason);
|
|
1002
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1003
|
+
}
|
|
1004
|
+
export function getAudWriteV2(id) {
|
|
1005
|
+
const j = _audJsV2.get(id);
|
|
1006
|
+
if (!j) return null;
|
|
1007
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1008
|
+
}
|
|
1009
|
+
export function listAudWritesV2() {
|
|
1010
|
+
return [..._audJsV2.values()].map((j) => ({
|
|
1011
|
+
...j,
|
|
1012
|
+
metadata: { ...j.metadata },
|
|
1013
|
+
}));
|
|
1014
|
+
}
|
|
1015
|
+
export function autoSuspendIdleAudProfilesV2({ now } = {}) {
|
|
1016
|
+
const t = now ?? Date.now();
|
|
1017
|
+
const flipped = [];
|
|
1018
|
+
for (const p of _audPsV2.values())
|
|
1019
|
+
if (
|
|
1020
|
+
p.status === AUD_PROFILE_MATURITY_V2.ACTIVE &&
|
|
1021
|
+
t - p.lastTouchedAt >= _audIdleMs
|
|
1022
|
+
) {
|
|
1023
|
+
p.status = AUD_PROFILE_MATURITY_V2.SUSPENDED;
|
|
1024
|
+
p.updatedAt = t;
|
|
1025
|
+
flipped.push(p.id);
|
|
1026
|
+
}
|
|
1027
|
+
return { flipped, count: flipped.length };
|
|
1028
|
+
}
|
|
1029
|
+
export function autoFailStuckAudWritesV2({ now } = {}) {
|
|
1030
|
+
const t = now ?? Date.now();
|
|
1031
|
+
const flipped = [];
|
|
1032
|
+
for (const j of _audJsV2.values())
|
|
1033
|
+
if (
|
|
1034
|
+
j.status === AUD_WRITE_LIFECYCLE_V2.WRITING &&
|
|
1035
|
+
j.startedAt != null &&
|
|
1036
|
+
t - j.startedAt >= _audStuckMs
|
|
1037
|
+
) {
|
|
1038
|
+
j.status = AUD_WRITE_LIFECYCLE_V2.FAILED;
|
|
1039
|
+
j.updatedAt = t;
|
|
1040
|
+
if (!j.settledAt) j.settledAt = t;
|
|
1041
|
+
j.metadata.failReason = "auto-fail-stuck";
|
|
1042
|
+
flipped.push(j.id);
|
|
1043
|
+
}
|
|
1044
|
+
return { flipped, count: flipped.length };
|
|
1045
|
+
}
|
|
1046
|
+
export function getAuditLoggerGovStatsV2() {
|
|
1047
|
+
const profilesByStatus = {};
|
|
1048
|
+
for (const v of Object.values(AUD_PROFILE_MATURITY_V2))
|
|
1049
|
+
profilesByStatus[v] = 0;
|
|
1050
|
+
for (const p of _audPsV2.values()) profilesByStatus[p.status]++;
|
|
1051
|
+
const writesByStatus = {};
|
|
1052
|
+
for (const v of Object.values(AUD_WRITE_LIFECYCLE_V2)) writesByStatus[v] = 0;
|
|
1053
|
+
for (const j of _audJsV2.values()) writesByStatus[j.status]++;
|
|
1054
|
+
return {
|
|
1055
|
+
totalAudProfilesV2: _audPsV2.size,
|
|
1056
|
+
totalAudWritesV2: _audJsV2.size,
|
|
1057
|
+
maxActiveAudProfilesPerOwner: _audMaxActive,
|
|
1058
|
+
maxPendingAudWritesPerProfile: _audMaxPending,
|
|
1059
|
+
audProfileIdleMs: _audIdleMs,
|
|
1060
|
+
audWriteStuckMs: _audStuckMs,
|
|
1061
|
+
profilesByStatus,
|
|
1062
|
+
writesByStatus,
|
|
1063
|
+
};
|
|
1064
|
+
}
|