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
|
@@ -1000,3 +1000,338 @@ export function getPrivacyStatsV2() {
|
|
|
1000
1000
|
avgComputationTimeMs: timeCount > 0 ? Math.round(timeSum / timeCount) : 0,
|
|
1001
1001
|
};
|
|
1002
1002
|
}
|
|
1003
|
+
|
|
1004
|
+
// =====================================================================
|
|
1005
|
+
// privacy-computing V2 governance overlay (iter17)
|
|
1006
|
+
// =====================================================================
|
|
1007
|
+
export const PCGOV_PROFILE_MATURITY_V2 = Object.freeze({
|
|
1008
|
+
PENDING: "pending",
|
|
1009
|
+
ACTIVE: "active",
|
|
1010
|
+
SUSPENDED: "suspended",
|
|
1011
|
+
ARCHIVED: "archived",
|
|
1012
|
+
});
|
|
1013
|
+
export const PCGOV_JOB_LIFECYCLE_V2 = Object.freeze({
|
|
1014
|
+
QUEUED: "queued",
|
|
1015
|
+
COMPUTING: "computing",
|
|
1016
|
+
COMPUTED: "computed",
|
|
1017
|
+
FAILED: "failed",
|
|
1018
|
+
CANCELLED: "cancelled",
|
|
1019
|
+
});
|
|
1020
|
+
const _pcgovPTrans = new Map([
|
|
1021
|
+
[
|
|
1022
|
+
PCGOV_PROFILE_MATURITY_V2.PENDING,
|
|
1023
|
+
new Set([
|
|
1024
|
+
PCGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
1025
|
+
PCGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
1026
|
+
]),
|
|
1027
|
+
],
|
|
1028
|
+
[
|
|
1029
|
+
PCGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
1030
|
+
new Set([
|
|
1031
|
+
PCGOV_PROFILE_MATURITY_V2.SUSPENDED,
|
|
1032
|
+
PCGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
1033
|
+
]),
|
|
1034
|
+
],
|
|
1035
|
+
[
|
|
1036
|
+
PCGOV_PROFILE_MATURITY_V2.SUSPENDED,
|
|
1037
|
+
new Set([
|
|
1038
|
+
PCGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
1039
|
+
PCGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
1040
|
+
]),
|
|
1041
|
+
],
|
|
1042
|
+
[PCGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
|
|
1043
|
+
]);
|
|
1044
|
+
const _pcgovPTerminal = new Set([PCGOV_PROFILE_MATURITY_V2.ARCHIVED]);
|
|
1045
|
+
const _pcgovJTrans = new Map([
|
|
1046
|
+
[
|
|
1047
|
+
PCGOV_JOB_LIFECYCLE_V2.QUEUED,
|
|
1048
|
+
new Set([
|
|
1049
|
+
PCGOV_JOB_LIFECYCLE_V2.COMPUTING,
|
|
1050
|
+
PCGOV_JOB_LIFECYCLE_V2.CANCELLED,
|
|
1051
|
+
]),
|
|
1052
|
+
],
|
|
1053
|
+
[
|
|
1054
|
+
PCGOV_JOB_LIFECYCLE_V2.COMPUTING,
|
|
1055
|
+
new Set([
|
|
1056
|
+
PCGOV_JOB_LIFECYCLE_V2.COMPUTED,
|
|
1057
|
+
PCGOV_JOB_LIFECYCLE_V2.FAILED,
|
|
1058
|
+
PCGOV_JOB_LIFECYCLE_V2.CANCELLED,
|
|
1059
|
+
]),
|
|
1060
|
+
],
|
|
1061
|
+
[PCGOV_JOB_LIFECYCLE_V2.COMPUTED, new Set()],
|
|
1062
|
+
[PCGOV_JOB_LIFECYCLE_V2.FAILED, new Set()],
|
|
1063
|
+
[PCGOV_JOB_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
1064
|
+
]);
|
|
1065
|
+
const _pcgovPsV2 = new Map();
|
|
1066
|
+
const _pcgovJsV2 = new Map();
|
|
1067
|
+
let _pcgovMaxActive = 6,
|
|
1068
|
+
_pcgovMaxPending = 15,
|
|
1069
|
+
_pcgovIdleMs = 30 * 24 * 60 * 60 * 1000,
|
|
1070
|
+
_pcgovStuckMs = 60 * 1000;
|
|
1071
|
+
function _pcgovPos(n, label) {
|
|
1072
|
+
const v = Math.floor(Number(n));
|
|
1073
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
1074
|
+
throw new Error(`${label} must be positive integer`);
|
|
1075
|
+
return v;
|
|
1076
|
+
}
|
|
1077
|
+
function _pcgovCheckP(from, to) {
|
|
1078
|
+
const a = _pcgovPTrans.get(from);
|
|
1079
|
+
if (!a || !a.has(to))
|
|
1080
|
+
throw new Error(`invalid pcgov profile transition ${from} → ${to}`);
|
|
1081
|
+
}
|
|
1082
|
+
function _pcgovCheckJ(from, to) {
|
|
1083
|
+
const a = _pcgovJTrans.get(from);
|
|
1084
|
+
if (!a || !a.has(to))
|
|
1085
|
+
throw new Error(`invalid pcgov job transition ${from} → ${to}`);
|
|
1086
|
+
}
|
|
1087
|
+
function _pcgovCountActive(owner) {
|
|
1088
|
+
let c = 0;
|
|
1089
|
+
for (const p of _pcgovPsV2.values())
|
|
1090
|
+
if (p.owner === owner && p.status === PCGOV_PROFILE_MATURITY_V2.ACTIVE) c++;
|
|
1091
|
+
return c;
|
|
1092
|
+
}
|
|
1093
|
+
function _pcgovCountPending(profileId) {
|
|
1094
|
+
let c = 0;
|
|
1095
|
+
for (const j of _pcgovJsV2.values())
|
|
1096
|
+
if (
|
|
1097
|
+
j.profileId === profileId &&
|
|
1098
|
+
(j.status === PCGOV_JOB_LIFECYCLE_V2.QUEUED ||
|
|
1099
|
+
j.status === PCGOV_JOB_LIFECYCLE_V2.COMPUTING)
|
|
1100
|
+
)
|
|
1101
|
+
c++;
|
|
1102
|
+
return c;
|
|
1103
|
+
}
|
|
1104
|
+
export function setMaxActivePcgovProfilesPerOwnerV2(n) {
|
|
1105
|
+
_pcgovMaxActive = _pcgovPos(n, "maxActivePcgovProfilesPerOwner");
|
|
1106
|
+
}
|
|
1107
|
+
export function getMaxActivePcgovProfilesPerOwnerV2() {
|
|
1108
|
+
return _pcgovMaxActive;
|
|
1109
|
+
}
|
|
1110
|
+
export function setMaxPendingPcgovJobsPerProfileV2(n) {
|
|
1111
|
+
_pcgovMaxPending = _pcgovPos(n, "maxPendingPcgovJobsPerProfile");
|
|
1112
|
+
}
|
|
1113
|
+
export function getMaxPendingPcgovJobsPerProfileV2() {
|
|
1114
|
+
return _pcgovMaxPending;
|
|
1115
|
+
}
|
|
1116
|
+
export function setPcgovProfileIdleMsV2(n) {
|
|
1117
|
+
_pcgovIdleMs = _pcgovPos(n, "pcgovProfileIdleMs");
|
|
1118
|
+
}
|
|
1119
|
+
export function getPcgovProfileIdleMsV2() {
|
|
1120
|
+
return _pcgovIdleMs;
|
|
1121
|
+
}
|
|
1122
|
+
export function setPcgovJobStuckMsV2(n) {
|
|
1123
|
+
_pcgovStuckMs = _pcgovPos(n, "pcgovJobStuckMs");
|
|
1124
|
+
}
|
|
1125
|
+
export function getPcgovJobStuckMsV2() {
|
|
1126
|
+
return _pcgovStuckMs;
|
|
1127
|
+
}
|
|
1128
|
+
export function _resetStatePrivacyComputingV2() {
|
|
1129
|
+
_pcgovPsV2.clear();
|
|
1130
|
+
_pcgovJsV2.clear();
|
|
1131
|
+
_pcgovMaxActive = 6;
|
|
1132
|
+
_pcgovMaxPending = 15;
|
|
1133
|
+
_pcgovIdleMs = 30 * 24 * 60 * 60 * 1000;
|
|
1134
|
+
_pcgovStuckMs = 60 * 1000;
|
|
1135
|
+
}
|
|
1136
|
+
export function registerPcgovProfileV2({
|
|
1137
|
+
id,
|
|
1138
|
+
owner,
|
|
1139
|
+
technique,
|
|
1140
|
+
metadata,
|
|
1141
|
+
} = {}) {
|
|
1142
|
+
if (!id || !owner) throw new Error("id and owner required");
|
|
1143
|
+
if (_pcgovPsV2.has(id)) throw new Error(`pcgov profile ${id} already exists`);
|
|
1144
|
+
const now = Date.now();
|
|
1145
|
+
const p = {
|
|
1146
|
+
id,
|
|
1147
|
+
owner,
|
|
1148
|
+
technique: technique || "mpc",
|
|
1149
|
+
status: PCGOV_PROFILE_MATURITY_V2.PENDING,
|
|
1150
|
+
createdAt: now,
|
|
1151
|
+
updatedAt: now,
|
|
1152
|
+
lastTouchedAt: now,
|
|
1153
|
+
activatedAt: null,
|
|
1154
|
+
archivedAt: null,
|
|
1155
|
+
metadata: { ...(metadata || {}) },
|
|
1156
|
+
};
|
|
1157
|
+
_pcgovPsV2.set(id, p);
|
|
1158
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1159
|
+
}
|
|
1160
|
+
export function activatePcgovProfileV2(id) {
|
|
1161
|
+
const p = _pcgovPsV2.get(id);
|
|
1162
|
+
if (!p) throw new Error(`pcgov profile ${id} not found`);
|
|
1163
|
+
const isInitial = p.status === PCGOV_PROFILE_MATURITY_V2.PENDING;
|
|
1164
|
+
_pcgovCheckP(p.status, PCGOV_PROFILE_MATURITY_V2.ACTIVE);
|
|
1165
|
+
if (isInitial && _pcgovCountActive(p.owner) >= _pcgovMaxActive)
|
|
1166
|
+
throw new Error(`max active pcgov profiles for owner ${p.owner} reached`);
|
|
1167
|
+
const now = Date.now();
|
|
1168
|
+
p.status = PCGOV_PROFILE_MATURITY_V2.ACTIVE;
|
|
1169
|
+
p.updatedAt = now;
|
|
1170
|
+
p.lastTouchedAt = now;
|
|
1171
|
+
if (!p.activatedAt) p.activatedAt = now;
|
|
1172
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1173
|
+
}
|
|
1174
|
+
export function suspendPcgovProfileV2(id) {
|
|
1175
|
+
const p = _pcgovPsV2.get(id);
|
|
1176
|
+
if (!p) throw new Error(`pcgov profile ${id} not found`);
|
|
1177
|
+
_pcgovCheckP(p.status, PCGOV_PROFILE_MATURITY_V2.SUSPENDED);
|
|
1178
|
+
p.status = PCGOV_PROFILE_MATURITY_V2.SUSPENDED;
|
|
1179
|
+
p.updatedAt = Date.now();
|
|
1180
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1181
|
+
}
|
|
1182
|
+
export function archivePcgovProfileV2(id) {
|
|
1183
|
+
const p = _pcgovPsV2.get(id);
|
|
1184
|
+
if (!p) throw new Error(`pcgov profile ${id} not found`);
|
|
1185
|
+
_pcgovCheckP(p.status, PCGOV_PROFILE_MATURITY_V2.ARCHIVED);
|
|
1186
|
+
const now = Date.now();
|
|
1187
|
+
p.status = PCGOV_PROFILE_MATURITY_V2.ARCHIVED;
|
|
1188
|
+
p.updatedAt = now;
|
|
1189
|
+
if (!p.archivedAt) p.archivedAt = now;
|
|
1190
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1191
|
+
}
|
|
1192
|
+
export function touchPcgovProfileV2(id) {
|
|
1193
|
+
const p = _pcgovPsV2.get(id);
|
|
1194
|
+
if (!p) throw new Error(`pcgov profile ${id} not found`);
|
|
1195
|
+
if (_pcgovPTerminal.has(p.status))
|
|
1196
|
+
throw new Error(`cannot touch terminal pcgov profile ${id}`);
|
|
1197
|
+
const now = Date.now();
|
|
1198
|
+
p.lastTouchedAt = now;
|
|
1199
|
+
p.updatedAt = now;
|
|
1200
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1201
|
+
}
|
|
1202
|
+
export function getPcgovProfileV2(id) {
|
|
1203
|
+
const p = _pcgovPsV2.get(id);
|
|
1204
|
+
if (!p) return null;
|
|
1205
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1206
|
+
}
|
|
1207
|
+
export function listPcgovProfilesV2() {
|
|
1208
|
+
return [..._pcgovPsV2.values()].map((p) => ({
|
|
1209
|
+
...p,
|
|
1210
|
+
metadata: { ...p.metadata },
|
|
1211
|
+
}));
|
|
1212
|
+
}
|
|
1213
|
+
export function createPcgovJobV2({ id, profileId, dataset, metadata } = {}) {
|
|
1214
|
+
if (!id || !profileId) throw new Error("id and profileId required");
|
|
1215
|
+
if (_pcgovJsV2.has(id)) throw new Error(`pcgov job ${id} already exists`);
|
|
1216
|
+
if (!_pcgovPsV2.has(profileId))
|
|
1217
|
+
throw new Error(`pcgov profile ${profileId} not found`);
|
|
1218
|
+
if (_pcgovCountPending(profileId) >= _pcgovMaxPending)
|
|
1219
|
+
throw new Error(`max pending pcgov jobs for profile ${profileId} reached`);
|
|
1220
|
+
const now = Date.now();
|
|
1221
|
+
const j = {
|
|
1222
|
+
id,
|
|
1223
|
+
profileId,
|
|
1224
|
+
dataset: dataset || "",
|
|
1225
|
+
status: PCGOV_JOB_LIFECYCLE_V2.QUEUED,
|
|
1226
|
+
createdAt: now,
|
|
1227
|
+
updatedAt: now,
|
|
1228
|
+
startedAt: null,
|
|
1229
|
+
settledAt: null,
|
|
1230
|
+
metadata: { ...(metadata || {}) },
|
|
1231
|
+
};
|
|
1232
|
+
_pcgovJsV2.set(id, j);
|
|
1233
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1234
|
+
}
|
|
1235
|
+
export function computingPcgovJobV2(id) {
|
|
1236
|
+
const j = _pcgovJsV2.get(id);
|
|
1237
|
+
if (!j) throw new Error(`pcgov job ${id} not found`);
|
|
1238
|
+
_pcgovCheckJ(j.status, PCGOV_JOB_LIFECYCLE_V2.COMPUTING);
|
|
1239
|
+
const now = Date.now();
|
|
1240
|
+
j.status = PCGOV_JOB_LIFECYCLE_V2.COMPUTING;
|
|
1241
|
+
j.updatedAt = now;
|
|
1242
|
+
if (!j.startedAt) j.startedAt = now;
|
|
1243
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1244
|
+
}
|
|
1245
|
+
export function completeJobPcgovV2(id) {
|
|
1246
|
+
const j = _pcgovJsV2.get(id);
|
|
1247
|
+
if (!j) throw new Error(`pcgov job ${id} not found`);
|
|
1248
|
+
_pcgovCheckJ(j.status, PCGOV_JOB_LIFECYCLE_V2.COMPUTED);
|
|
1249
|
+
const now = Date.now();
|
|
1250
|
+
j.status = PCGOV_JOB_LIFECYCLE_V2.COMPUTED;
|
|
1251
|
+
j.updatedAt = now;
|
|
1252
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1253
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1254
|
+
}
|
|
1255
|
+
export function failPcgovJobV2(id, reason) {
|
|
1256
|
+
const j = _pcgovJsV2.get(id);
|
|
1257
|
+
if (!j) throw new Error(`pcgov job ${id} not found`);
|
|
1258
|
+
_pcgovCheckJ(j.status, PCGOV_JOB_LIFECYCLE_V2.FAILED);
|
|
1259
|
+
const now = Date.now();
|
|
1260
|
+
j.status = PCGOV_JOB_LIFECYCLE_V2.FAILED;
|
|
1261
|
+
j.updatedAt = now;
|
|
1262
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1263
|
+
if (reason) j.metadata.failReason = String(reason);
|
|
1264
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1265
|
+
}
|
|
1266
|
+
export function cancelPcgovJobV2(id, reason) {
|
|
1267
|
+
const j = _pcgovJsV2.get(id);
|
|
1268
|
+
if (!j) throw new Error(`pcgov job ${id} not found`);
|
|
1269
|
+
_pcgovCheckJ(j.status, PCGOV_JOB_LIFECYCLE_V2.CANCELLED);
|
|
1270
|
+
const now = Date.now();
|
|
1271
|
+
j.status = PCGOV_JOB_LIFECYCLE_V2.CANCELLED;
|
|
1272
|
+
j.updatedAt = now;
|
|
1273
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1274
|
+
if (reason) j.metadata.cancelReason = String(reason);
|
|
1275
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1276
|
+
}
|
|
1277
|
+
export function getPcgovJobV2(id) {
|
|
1278
|
+
const j = _pcgovJsV2.get(id);
|
|
1279
|
+
if (!j) return null;
|
|
1280
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1281
|
+
}
|
|
1282
|
+
export function listPcgovJobsV2() {
|
|
1283
|
+
return [..._pcgovJsV2.values()].map((j) => ({
|
|
1284
|
+
...j,
|
|
1285
|
+
metadata: { ...j.metadata },
|
|
1286
|
+
}));
|
|
1287
|
+
}
|
|
1288
|
+
export function autoSuspendIdlePcgovProfilesV2({ now } = {}) {
|
|
1289
|
+
const t = now ?? Date.now();
|
|
1290
|
+
const flipped = [];
|
|
1291
|
+
for (const p of _pcgovPsV2.values())
|
|
1292
|
+
if (
|
|
1293
|
+
p.status === PCGOV_PROFILE_MATURITY_V2.ACTIVE &&
|
|
1294
|
+
t - p.lastTouchedAt >= _pcgovIdleMs
|
|
1295
|
+
) {
|
|
1296
|
+
p.status = PCGOV_PROFILE_MATURITY_V2.SUSPENDED;
|
|
1297
|
+
p.updatedAt = t;
|
|
1298
|
+
flipped.push(p.id);
|
|
1299
|
+
}
|
|
1300
|
+
return { flipped, count: flipped.length };
|
|
1301
|
+
}
|
|
1302
|
+
export function autoFailStuckPcgovJobsV2({ now } = {}) {
|
|
1303
|
+
const t = now ?? Date.now();
|
|
1304
|
+
const flipped = [];
|
|
1305
|
+
for (const j of _pcgovJsV2.values())
|
|
1306
|
+
if (
|
|
1307
|
+
j.status === PCGOV_JOB_LIFECYCLE_V2.COMPUTING &&
|
|
1308
|
+
j.startedAt != null &&
|
|
1309
|
+
t - j.startedAt >= _pcgovStuckMs
|
|
1310
|
+
) {
|
|
1311
|
+
j.status = PCGOV_JOB_LIFECYCLE_V2.FAILED;
|
|
1312
|
+
j.updatedAt = t;
|
|
1313
|
+
if (!j.settledAt) j.settledAt = t;
|
|
1314
|
+
j.metadata.failReason = "auto-fail-stuck";
|
|
1315
|
+
flipped.push(j.id);
|
|
1316
|
+
}
|
|
1317
|
+
return { flipped, count: flipped.length };
|
|
1318
|
+
}
|
|
1319
|
+
export function getPrivacyComputingGovStatsV2() {
|
|
1320
|
+
const profilesByStatus = {};
|
|
1321
|
+
for (const v of Object.values(PCGOV_PROFILE_MATURITY_V2))
|
|
1322
|
+
profilesByStatus[v] = 0;
|
|
1323
|
+
for (const p of _pcgovPsV2.values()) profilesByStatus[p.status]++;
|
|
1324
|
+
const jobsByStatus = {};
|
|
1325
|
+
for (const v of Object.values(PCGOV_JOB_LIFECYCLE_V2)) jobsByStatus[v] = 0;
|
|
1326
|
+
for (const j of _pcgovJsV2.values()) jobsByStatus[j.status]++;
|
|
1327
|
+
return {
|
|
1328
|
+
totalPcgovProfilesV2: _pcgovPsV2.size,
|
|
1329
|
+
totalPcgovJobsV2: _pcgovJsV2.size,
|
|
1330
|
+
maxActivePcgovProfilesPerOwner: _pcgovMaxActive,
|
|
1331
|
+
maxPendingPcgovJobsPerProfile: _pcgovMaxPending,
|
|
1332
|
+
pcgovProfileIdleMs: _pcgovIdleMs,
|
|
1333
|
+
pcgovJobStuckMs: _pcgovStuckMs,
|
|
1334
|
+
profilesByStatus,
|
|
1335
|
+
jobsByStatus,
|
|
1336
|
+
};
|
|
1337
|
+
}
|
|
@@ -9,13 +9,4 @@
|
|
|
9
9
|
* in new code.
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
export
|
|
13
|
-
estimateTokens,
|
|
14
|
-
estimateMessagesTokens,
|
|
15
|
-
CONTEXT_WINDOWS,
|
|
16
|
-
getContextWindow,
|
|
17
|
-
COMPRESSION_VARIANTS,
|
|
18
|
-
getCompressionVariant,
|
|
19
|
-
adaptiveThresholds,
|
|
20
|
-
PromptCompressor,
|
|
21
|
-
} from "../harness/prompt-compressor.js";
|
|
12
|
+
export * from "../harness/prompt-compressor.js";
|
|
@@ -806,3 +806,343 @@ export function getReputationStatsV2() {
|
|
|
806
806
|
bestScoreEver: bestScore,
|
|
807
807
|
};
|
|
808
808
|
}
|
|
809
|
+
|
|
810
|
+
// =====================================================================
|
|
811
|
+
// reputation-optimizer V2 governance overlay (iter16)
|
|
812
|
+
// =====================================================================
|
|
813
|
+
export const REPGOV_PROFILE_MATURITY_V2 = Object.freeze({
|
|
814
|
+
PENDING: "pending",
|
|
815
|
+
ACTIVE: "active",
|
|
816
|
+
STALE: "stale",
|
|
817
|
+
ARCHIVED: "archived",
|
|
818
|
+
});
|
|
819
|
+
export const REPGOV_CYCLE_LIFECYCLE_V2 = Object.freeze({
|
|
820
|
+
QUEUED: "queued",
|
|
821
|
+
RUNNING: "running",
|
|
822
|
+
COMPLETED: "completed",
|
|
823
|
+
FAILED: "failed",
|
|
824
|
+
CANCELLED: "cancelled",
|
|
825
|
+
});
|
|
826
|
+
const _repgovPTrans = new Map([
|
|
827
|
+
[
|
|
828
|
+
REPGOV_PROFILE_MATURITY_V2.PENDING,
|
|
829
|
+
new Set([
|
|
830
|
+
REPGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
831
|
+
REPGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
832
|
+
]),
|
|
833
|
+
],
|
|
834
|
+
[
|
|
835
|
+
REPGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
836
|
+
new Set([
|
|
837
|
+
REPGOV_PROFILE_MATURITY_V2.STALE,
|
|
838
|
+
REPGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
839
|
+
]),
|
|
840
|
+
],
|
|
841
|
+
[
|
|
842
|
+
REPGOV_PROFILE_MATURITY_V2.STALE,
|
|
843
|
+
new Set([
|
|
844
|
+
REPGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
845
|
+
REPGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
846
|
+
]),
|
|
847
|
+
],
|
|
848
|
+
[REPGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
|
|
849
|
+
]);
|
|
850
|
+
const _repgovPTerminal = new Set([REPGOV_PROFILE_MATURITY_V2.ARCHIVED]);
|
|
851
|
+
const _repgovJTrans = new Map([
|
|
852
|
+
[
|
|
853
|
+
REPGOV_CYCLE_LIFECYCLE_V2.QUEUED,
|
|
854
|
+
new Set([
|
|
855
|
+
REPGOV_CYCLE_LIFECYCLE_V2.RUNNING,
|
|
856
|
+
REPGOV_CYCLE_LIFECYCLE_V2.CANCELLED,
|
|
857
|
+
]),
|
|
858
|
+
],
|
|
859
|
+
[
|
|
860
|
+
REPGOV_CYCLE_LIFECYCLE_V2.RUNNING,
|
|
861
|
+
new Set([
|
|
862
|
+
REPGOV_CYCLE_LIFECYCLE_V2.COMPLETED,
|
|
863
|
+
REPGOV_CYCLE_LIFECYCLE_V2.FAILED,
|
|
864
|
+
REPGOV_CYCLE_LIFECYCLE_V2.CANCELLED,
|
|
865
|
+
]),
|
|
866
|
+
],
|
|
867
|
+
[REPGOV_CYCLE_LIFECYCLE_V2.COMPLETED, new Set()],
|
|
868
|
+
[REPGOV_CYCLE_LIFECYCLE_V2.FAILED, new Set()],
|
|
869
|
+
[REPGOV_CYCLE_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
870
|
+
]);
|
|
871
|
+
const _repgovPsV2 = new Map();
|
|
872
|
+
const _repgovJsV2 = new Map();
|
|
873
|
+
let _repgovMaxActive = 8,
|
|
874
|
+
_repgovMaxPending = 20,
|
|
875
|
+
_repgovIdleMs = 30 * 24 * 60 * 60 * 1000,
|
|
876
|
+
_repgovStuckMs = 60 * 1000;
|
|
877
|
+
function _repgovPos(n, label) {
|
|
878
|
+
const v = Math.floor(Number(n));
|
|
879
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
880
|
+
throw new Error(`${label} must be positive integer`);
|
|
881
|
+
return v;
|
|
882
|
+
}
|
|
883
|
+
function _repgovCheckP(from, to) {
|
|
884
|
+
const a = _repgovPTrans.get(from);
|
|
885
|
+
if (!a || !a.has(to))
|
|
886
|
+
throw new Error(`invalid repgov profile transition ${from} → ${to}`);
|
|
887
|
+
}
|
|
888
|
+
function _repgovCheckJ(from, to) {
|
|
889
|
+
const a = _repgovJTrans.get(from);
|
|
890
|
+
if (!a || !a.has(to))
|
|
891
|
+
throw new Error(`invalid repgov cycle transition ${from} → ${to}`);
|
|
892
|
+
}
|
|
893
|
+
function _repgovCountActive(owner) {
|
|
894
|
+
let c = 0;
|
|
895
|
+
for (const p of _repgovPsV2.values())
|
|
896
|
+
if (p.owner === owner && p.status === REPGOV_PROFILE_MATURITY_V2.ACTIVE)
|
|
897
|
+
c++;
|
|
898
|
+
return c;
|
|
899
|
+
}
|
|
900
|
+
function _repgovCountPending(profileId) {
|
|
901
|
+
let c = 0;
|
|
902
|
+
for (const j of _repgovJsV2.values())
|
|
903
|
+
if (
|
|
904
|
+
j.profileId === profileId &&
|
|
905
|
+
(j.status === REPGOV_CYCLE_LIFECYCLE_V2.QUEUED ||
|
|
906
|
+
j.status === REPGOV_CYCLE_LIFECYCLE_V2.RUNNING)
|
|
907
|
+
)
|
|
908
|
+
c++;
|
|
909
|
+
return c;
|
|
910
|
+
}
|
|
911
|
+
export function setMaxActiveRepgovProfilesPerOwnerV2(n) {
|
|
912
|
+
_repgovMaxActive = _repgovPos(n, "maxActiveRepgovProfilesPerOwner");
|
|
913
|
+
}
|
|
914
|
+
export function getMaxActiveRepgovProfilesPerOwnerV2() {
|
|
915
|
+
return _repgovMaxActive;
|
|
916
|
+
}
|
|
917
|
+
export function setMaxPendingRepgovCyclesPerProfileV2(n) {
|
|
918
|
+
_repgovMaxPending = _repgovPos(n, "maxPendingRepgovCyclesPerProfile");
|
|
919
|
+
}
|
|
920
|
+
export function getMaxPendingRepgovCyclesPerProfileV2() {
|
|
921
|
+
return _repgovMaxPending;
|
|
922
|
+
}
|
|
923
|
+
export function setRepgovProfileIdleMsV2(n) {
|
|
924
|
+
_repgovIdleMs = _repgovPos(n, "repgovProfileIdleMs");
|
|
925
|
+
}
|
|
926
|
+
export function getRepgovProfileIdleMsV2() {
|
|
927
|
+
return _repgovIdleMs;
|
|
928
|
+
}
|
|
929
|
+
export function setRepgovCycleStuckMsV2(n) {
|
|
930
|
+
_repgovStuckMs = _repgovPos(n, "repgovCycleStuckMs");
|
|
931
|
+
}
|
|
932
|
+
export function getRepgovCycleStuckMsV2() {
|
|
933
|
+
return _repgovStuckMs;
|
|
934
|
+
}
|
|
935
|
+
export function _resetStateReputationOptimizerV2() {
|
|
936
|
+
_repgovPsV2.clear();
|
|
937
|
+
_repgovJsV2.clear();
|
|
938
|
+
_repgovMaxActive = 8;
|
|
939
|
+
_repgovMaxPending = 20;
|
|
940
|
+
_repgovIdleMs = 30 * 24 * 60 * 60 * 1000;
|
|
941
|
+
_repgovStuckMs = 60 * 1000;
|
|
942
|
+
}
|
|
943
|
+
export function registerRepgovProfileV2({
|
|
944
|
+
id,
|
|
945
|
+
owner,
|
|
946
|
+
objective,
|
|
947
|
+
metadata,
|
|
948
|
+
} = {}) {
|
|
949
|
+
if (!id || !owner) throw new Error("id and owner required");
|
|
950
|
+
if (_repgovPsV2.has(id))
|
|
951
|
+
throw new Error(`repgov profile ${id} already exists`);
|
|
952
|
+
const now = Date.now();
|
|
953
|
+
const p = {
|
|
954
|
+
id,
|
|
955
|
+
owner,
|
|
956
|
+
objective: objective || "quality",
|
|
957
|
+
status: REPGOV_PROFILE_MATURITY_V2.PENDING,
|
|
958
|
+
createdAt: now,
|
|
959
|
+
updatedAt: now,
|
|
960
|
+
lastTouchedAt: now,
|
|
961
|
+
activatedAt: null,
|
|
962
|
+
archivedAt: null,
|
|
963
|
+
metadata: { ...(metadata || {}) },
|
|
964
|
+
};
|
|
965
|
+
_repgovPsV2.set(id, p);
|
|
966
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
967
|
+
}
|
|
968
|
+
export function activateRepgovProfileV2(id) {
|
|
969
|
+
const p = _repgovPsV2.get(id);
|
|
970
|
+
if (!p) throw new Error(`repgov profile ${id} not found`);
|
|
971
|
+
const isInitial = p.status === REPGOV_PROFILE_MATURITY_V2.PENDING;
|
|
972
|
+
_repgovCheckP(p.status, REPGOV_PROFILE_MATURITY_V2.ACTIVE);
|
|
973
|
+
if (isInitial && _repgovCountActive(p.owner) >= _repgovMaxActive)
|
|
974
|
+
throw new Error(`max active repgov profiles for owner ${p.owner} reached`);
|
|
975
|
+
const now = Date.now();
|
|
976
|
+
p.status = REPGOV_PROFILE_MATURITY_V2.ACTIVE;
|
|
977
|
+
p.updatedAt = now;
|
|
978
|
+
p.lastTouchedAt = now;
|
|
979
|
+
if (!p.activatedAt) p.activatedAt = now;
|
|
980
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
981
|
+
}
|
|
982
|
+
export function staleRepgovProfileV2(id) {
|
|
983
|
+
const p = _repgovPsV2.get(id);
|
|
984
|
+
if (!p) throw new Error(`repgov profile ${id} not found`);
|
|
985
|
+
_repgovCheckP(p.status, REPGOV_PROFILE_MATURITY_V2.STALE);
|
|
986
|
+
p.status = REPGOV_PROFILE_MATURITY_V2.STALE;
|
|
987
|
+
p.updatedAt = Date.now();
|
|
988
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
989
|
+
}
|
|
990
|
+
export function archiveRepgovProfileV2(id) {
|
|
991
|
+
const p = _repgovPsV2.get(id);
|
|
992
|
+
if (!p) throw new Error(`repgov profile ${id} not found`);
|
|
993
|
+
_repgovCheckP(p.status, REPGOV_PROFILE_MATURITY_V2.ARCHIVED);
|
|
994
|
+
const now = Date.now();
|
|
995
|
+
p.status = REPGOV_PROFILE_MATURITY_V2.ARCHIVED;
|
|
996
|
+
p.updatedAt = now;
|
|
997
|
+
if (!p.archivedAt) p.archivedAt = now;
|
|
998
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
999
|
+
}
|
|
1000
|
+
export function touchRepgovProfileV2(id) {
|
|
1001
|
+
const p = _repgovPsV2.get(id);
|
|
1002
|
+
if (!p) throw new Error(`repgov profile ${id} not found`);
|
|
1003
|
+
if (_repgovPTerminal.has(p.status))
|
|
1004
|
+
throw new Error(`cannot touch terminal repgov profile ${id}`);
|
|
1005
|
+
const now = Date.now();
|
|
1006
|
+
p.lastTouchedAt = now;
|
|
1007
|
+
p.updatedAt = now;
|
|
1008
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1009
|
+
}
|
|
1010
|
+
export function getRepgovProfileV2(id) {
|
|
1011
|
+
const p = _repgovPsV2.get(id);
|
|
1012
|
+
if (!p) return null;
|
|
1013
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1014
|
+
}
|
|
1015
|
+
export function listRepgovProfilesV2() {
|
|
1016
|
+
return [..._repgovPsV2.values()].map((p) => ({
|
|
1017
|
+
...p,
|
|
1018
|
+
metadata: { ...p.metadata },
|
|
1019
|
+
}));
|
|
1020
|
+
}
|
|
1021
|
+
export function createRepgovCycleV2({ id, profileId, subject, metadata } = {}) {
|
|
1022
|
+
if (!id || !profileId) throw new Error("id and profileId required");
|
|
1023
|
+
if (_repgovJsV2.has(id)) throw new Error(`repgov cycle ${id} already exists`);
|
|
1024
|
+
if (!_repgovPsV2.has(profileId))
|
|
1025
|
+
throw new Error(`repgov profile ${profileId} not found`);
|
|
1026
|
+
if (_repgovCountPending(profileId) >= _repgovMaxPending)
|
|
1027
|
+
throw new Error(
|
|
1028
|
+
`max pending repgov cycles for profile ${profileId} reached`,
|
|
1029
|
+
);
|
|
1030
|
+
const now = Date.now();
|
|
1031
|
+
const j = {
|
|
1032
|
+
id,
|
|
1033
|
+
profileId,
|
|
1034
|
+
subject: subject || "",
|
|
1035
|
+
status: REPGOV_CYCLE_LIFECYCLE_V2.QUEUED,
|
|
1036
|
+
createdAt: now,
|
|
1037
|
+
updatedAt: now,
|
|
1038
|
+
startedAt: null,
|
|
1039
|
+
settledAt: null,
|
|
1040
|
+
metadata: { ...(metadata || {}) },
|
|
1041
|
+
};
|
|
1042
|
+
_repgovJsV2.set(id, j);
|
|
1043
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1044
|
+
}
|
|
1045
|
+
export function runningRepgovCycleV2(id) {
|
|
1046
|
+
const j = _repgovJsV2.get(id);
|
|
1047
|
+
if (!j) throw new Error(`repgov cycle ${id} not found`);
|
|
1048
|
+
_repgovCheckJ(j.status, REPGOV_CYCLE_LIFECYCLE_V2.RUNNING);
|
|
1049
|
+
const now = Date.now();
|
|
1050
|
+
j.status = REPGOV_CYCLE_LIFECYCLE_V2.RUNNING;
|
|
1051
|
+
j.updatedAt = now;
|
|
1052
|
+
if (!j.startedAt) j.startedAt = now;
|
|
1053
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1054
|
+
}
|
|
1055
|
+
export function completeCycleRepgovV2(id) {
|
|
1056
|
+
const j = _repgovJsV2.get(id);
|
|
1057
|
+
if (!j) throw new Error(`repgov cycle ${id} not found`);
|
|
1058
|
+
_repgovCheckJ(j.status, REPGOV_CYCLE_LIFECYCLE_V2.COMPLETED);
|
|
1059
|
+
const now = Date.now();
|
|
1060
|
+
j.status = REPGOV_CYCLE_LIFECYCLE_V2.COMPLETED;
|
|
1061
|
+
j.updatedAt = now;
|
|
1062
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1063
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1064
|
+
}
|
|
1065
|
+
export function failRepgovCycleV2(id, reason) {
|
|
1066
|
+
const j = _repgovJsV2.get(id);
|
|
1067
|
+
if (!j) throw new Error(`repgov cycle ${id} not found`);
|
|
1068
|
+
_repgovCheckJ(j.status, REPGOV_CYCLE_LIFECYCLE_V2.FAILED);
|
|
1069
|
+
const now = Date.now();
|
|
1070
|
+
j.status = REPGOV_CYCLE_LIFECYCLE_V2.FAILED;
|
|
1071
|
+
j.updatedAt = now;
|
|
1072
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1073
|
+
if (reason) j.metadata.failReason = String(reason);
|
|
1074
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1075
|
+
}
|
|
1076
|
+
export function cancelRepgovCycleV2(id, reason) {
|
|
1077
|
+
const j = _repgovJsV2.get(id);
|
|
1078
|
+
if (!j) throw new Error(`repgov cycle ${id} not found`);
|
|
1079
|
+
_repgovCheckJ(j.status, REPGOV_CYCLE_LIFECYCLE_V2.CANCELLED);
|
|
1080
|
+
const now = Date.now();
|
|
1081
|
+
j.status = REPGOV_CYCLE_LIFECYCLE_V2.CANCELLED;
|
|
1082
|
+
j.updatedAt = now;
|
|
1083
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1084
|
+
if (reason) j.metadata.cancelReason = String(reason);
|
|
1085
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1086
|
+
}
|
|
1087
|
+
export function getRepgovCycleV2(id) {
|
|
1088
|
+
const j = _repgovJsV2.get(id);
|
|
1089
|
+
if (!j) return null;
|
|
1090
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1091
|
+
}
|
|
1092
|
+
export function listRepgovCyclesV2() {
|
|
1093
|
+
return [..._repgovJsV2.values()].map((j) => ({
|
|
1094
|
+
...j,
|
|
1095
|
+
metadata: { ...j.metadata },
|
|
1096
|
+
}));
|
|
1097
|
+
}
|
|
1098
|
+
export function autoStaleIdleRepgovProfilesV2({ now } = {}) {
|
|
1099
|
+
const t = now ?? Date.now();
|
|
1100
|
+
const flipped = [];
|
|
1101
|
+
for (const p of _repgovPsV2.values())
|
|
1102
|
+
if (
|
|
1103
|
+
p.status === REPGOV_PROFILE_MATURITY_V2.ACTIVE &&
|
|
1104
|
+
t - p.lastTouchedAt >= _repgovIdleMs
|
|
1105
|
+
) {
|
|
1106
|
+
p.status = REPGOV_PROFILE_MATURITY_V2.STALE;
|
|
1107
|
+
p.updatedAt = t;
|
|
1108
|
+
flipped.push(p.id);
|
|
1109
|
+
}
|
|
1110
|
+
return { flipped, count: flipped.length };
|
|
1111
|
+
}
|
|
1112
|
+
export function autoFailStuckRepgovCyclesV2({ now } = {}) {
|
|
1113
|
+
const t = now ?? Date.now();
|
|
1114
|
+
const flipped = [];
|
|
1115
|
+
for (const j of _repgovJsV2.values())
|
|
1116
|
+
if (
|
|
1117
|
+
j.status === REPGOV_CYCLE_LIFECYCLE_V2.RUNNING &&
|
|
1118
|
+
j.startedAt != null &&
|
|
1119
|
+
t - j.startedAt >= _repgovStuckMs
|
|
1120
|
+
) {
|
|
1121
|
+
j.status = REPGOV_CYCLE_LIFECYCLE_V2.FAILED;
|
|
1122
|
+
j.updatedAt = t;
|
|
1123
|
+
if (!j.settledAt) j.settledAt = t;
|
|
1124
|
+
j.metadata.failReason = "auto-fail-stuck";
|
|
1125
|
+
flipped.push(j.id);
|
|
1126
|
+
}
|
|
1127
|
+
return { flipped, count: flipped.length };
|
|
1128
|
+
}
|
|
1129
|
+
export function getReputationOptimizerGovStatsV2() {
|
|
1130
|
+
const profilesByStatus = {};
|
|
1131
|
+
for (const v of Object.values(REPGOV_PROFILE_MATURITY_V2))
|
|
1132
|
+
profilesByStatus[v] = 0;
|
|
1133
|
+
for (const p of _repgovPsV2.values()) profilesByStatus[p.status]++;
|
|
1134
|
+
const cyclesByStatus = {};
|
|
1135
|
+
for (const v of Object.values(REPGOV_CYCLE_LIFECYCLE_V2))
|
|
1136
|
+
cyclesByStatus[v] = 0;
|
|
1137
|
+
for (const j of _repgovJsV2.values()) cyclesByStatus[j.status]++;
|
|
1138
|
+
return {
|
|
1139
|
+
totalRepgovProfilesV2: _repgovPsV2.size,
|
|
1140
|
+
totalRepgovCyclesV2: _repgovJsV2.size,
|
|
1141
|
+
maxActiveRepgovProfilesPerOwner: _repgovMaxActive,
|
|
1142
|
+
maxPendingRepgovCyclesPerProfile: _repgovMaxPending,
|
|
1143
|
+
repgovProfileIdleMs: _repgovIdleMs,
|
|
1144
|
+
repgovCycleStuckMs: _repgovStuckMs,
|
|
1145
|
+
profilesByStatus,
|
|
1146
|
+
cyclesByStatus,
|
|
1147
|
+
};
|
|
1148
|
+
}
|