chainlesschain 0.145.0 → 0.156.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/README.md +52 -3
- package/package.json +1 -1
- package/src/commands/a2a.js +201 -0
- package/src/commands/activitypub.js +207 -0
- package/src/commands/agent-network.js +217 -0
- package/src/commands/agent.js +1250 -0
- package/src/commands/automation.js +201 -0
- package/src/commands/bi.js +203 -0
- package/src/commands/browse.js +213 -0
- package/src/commands/chat.js +605 -0
- package/src/commands/cli-anything.js +426 -0
- package/src/commands/codegen.js +207 -0
- package/src/commands/collab.js +211 -0
- package/src/commands/compliance.js +822 -0
- package/src/commands/config.js +213 -0
- package/src/commands/cowork.js +1666 -0
- package/src/commands/crosschain.js +203 -0
- package/src/commands/dao.js +203 -0
- package/src/commands/dbevo.js +227 -0
- package/src/commands/dev.js +207 -0
- package/src/commands/did-v2.js +217 -0
- package/src/commands/did.js +221 -0
- package/src/commands/dlp.js +213 -0
- package/src/commands/economy.js +199 -0
- package/src/commands/encrypt.js +201 -0
- package/src/commands/evolution.js +199 -0
- package/src/commands/evomap.js +830 -0
- package/src/commands/export.js +213 -0
- package/src/commands/federation.js +209 -0
- package/src/commands/fusion.js +205 -0
- package/src/commands/governance.js +209 -0
- package/src/commands/hmemory.js +203 -0
- package/src/commands/hook.js +209 -0
- package/src/commands/import.js +209 -0
- package/src/commands/inference.js +207 -0
- package/src/commands/infra.js +203 -0
- package/src/commands/instinct.js +209 -0
- package/src/commands/ipfs.js +207 -0
- package/src/commands/kg.js +195 -0
- package/src/commands/llm.js +426 -0
- package/src/commands/matrix.js +207 -0
- package/src/commands/mcp.js +217 -0
- package/src/commands/memory.js +412 -0
- package/src/commands/multimodal.js +203 -0
- package/src/commands/nlprog.js +225 -0
- package/src/commands/nostr.js +209 -0
- package/src/commands/note.js +205 -0
- package/src/commands/ops.js +219 -0
- package/src/commands/orchestrate.js +406 -0
- package/src/commands/org.js +209 -0
- package/src/commands/p2p.js +209 -0
- package/src/commands/perception.js +209 -0
- package/src/commands/permmem.js +203 -0
- package/src/commands/pipeline.js +199 -0
- package/src/commands/planmode.js +426 -0
- package/src/commands/plugin-ecosystem.js +209 -0
- package/src/commands/plugin.js +209 -0
- package/src/commands/pqc.js +213 -0
- package/src/commands/quantization.js +207 -0
- package/src/commands/rcache.js +205 -0
- package/src/commands/recommend.js +233 -0
- package/src/commands/runtime.js +205 -0
- package/src/commands/scim.js +209 -0
- package/src/commands/services.js +207 -0
- package/src/commands/session.js +209 -0
- package/src/commands/setup.js +205 -0
- package/src/commands/skill.js +414 -0
- package/src/commands/social.js +201 -0
- package/src/commands/sso.js +209 -0
- package/src/commands/start.js +209 -0
- package/src/commands/stream.js +213 -0
- package/src/commands/sync.js +209 -0
- package/src/commands/tech.js +209 -0
- package/src/commands/tenant.js +217 -0
- package/src/commands/tokens.js +209 -0
- package/src/commands/trust.js +217 -0
- package/src/commands/ui.js +225 -0
- package/src/commands/wallet.js +209 -0
- package/src/commands/workflow.js +412 -0
- package/src/index.js +252 -0
- package/src/lib/a2a-protocol.js +332 -0
- package/src/lib/activitypub-bridge.js +334 -0
- package/src/lib/agent-coordinator.js +334 -0
- package/src/lib/agent-economy.js +334 -0
- package/src/lib/agent-network.js +341 -0
- package/src/lib/agent-router.js +333 -0
- package/src/lib/aiops.js +346 -0
- package/src/lib/automation-engine.js +335 -0
- package/src/lib/autonomous-agent.js +332 -0
- package/src/lib/autonomous-developer.js +332 -0
- package/src/lib/bi-engine.js +333 -0
- package/src/lib/browser-automation.js +334 -0
- package/src/lib/chat-core.js +335 -0
- package/src/lib/cli-anything-bridge.js +341 -0
- package/src/lib/cli-context-engineering.js +351 -0
- package/src/lib/code-agent.js +339 -0
- package/src/lib/collaboration-governance.js +334 -0
- package/src/lib/community-governance.js +346 -0
- package/src/lib/compliance-manager.js +334 -0
- package/src/lib/content-recommendation.js +351 -0
- package/src/lib/cowork-adapter.js +336 -0
- package/src/lib/cowork-evomap-adapter.js +341 -0
- package/src/lib/cowork-mcp-tools.js +341 -0
- package/src/lib/cowork-observe-html.js +341 -0
- package/src/lib/cowork-observe.js +341 -0
- package/src/lib/cowork-share.js +338 -0
- package/src/lib/cowork-task-templates.js +342 -1
- package/src/lib/cowork-template-marketplace.js +340 -0
- package/src/lib/cross-chain.js +339 -0
- package/src/lib/crypto-manager.js +334 -0
- package/src/lib/dao-governance.js +339 -0
- package/src/lib/dbevo.js +351 -0
- package/src/lib/decentral-infra.js +330 -0
- package/src/lib/did-manager.js +341 -0
- package/src/lib/did-v2-manager.js +341 -0
- package/src/lib/dlp-engine.js +339 -0
- package/src/lib/downloader.js +334 -0
- package/src/lib/evolution-system.js +334 -0
- package/src/lib/evomap-client.js +342 -0
- package/src/lib/evomap-federation.js +338 -0
- package/src/lib/evomap-governance.js +334 -0
- package/src/lib/evomap-manager.js +330 -0
- package/src/lib/execution-backend.js +330 -0
- package/src/lib/federation-hardening.js +340 -0
- package/src/lib/hashline.js +338 -0
- package/src/lib/hierarchical-memory.js +334 -0
- package/src/lib/hook-manager.js +341 -0
- package/src/lib/inference-network.js +341 -0
- package/src/lib/instinct-manager.js +346 -0
- package/src/lib/interaction-adapter.js +330 -0
- package/src/lib/interactive-planner.js +354 -0
- package/src/lib/ipfs-storage.js +334 -0
- package/src/lib/knowledge-exporter.js +341 -0
- package/src/lib/knowledge-graph.js +331 -0
- package/src/lib/knowledge-importer.js +341 -0
- package/src/lib/llm-providers.js +346 -0
- package/src/lib/matrix-bridge.js +339 -0
- package/src/lib/mcp-registry.js +346 -0
- package/src/lib/memory-manager.js +336 -0
- package/src/lib/multimodal.js +330 -0
- package/src/lib/nl-programming.js +341 -0
- package/src/lib/nostr-bridge.js +336 -0
- package/src/lib/note-versioning.js +339 -0
- package/src/lib/org-manager.js +336 -0
- package/src/lib/p2p-manager.js +341 -0
- package/src/lib/perception.js +346 -0
- package/src/lib/permanent-memory.js +327 -0
- package/src/lib/pipeline-orchestrator.js +332 -0
- package/src/lib/plan-mode.js +336 -0
- package/src/lib/plugin-autodiscovery.js +334 -0
- package/src/lib/plugin-ecosystem.js +346 -0
- package/src/lib/pqc-manager.js +346 -0
- package/src/lib/process-manager.js +336 -0
- package/src/lib/protocol-fusion.js +338 -0
- package/src/lib/provider-options.js +346 -0
- package/src/lib/provider-stream.js +348 -0
- package/src/lib/quantization.js +337 -0
- package/src/lib/response-cache.js +333 -0
- package/src/lib/scim-manager.js +346 -0
- package/src/lib/service-manager.js +337 -0
- package/src/lib/session-core-singletons.js +341 -0
- package/src/lib/session-manager.js +334 -0
- package/src/lib/skill-loader.js +334 -0
- package/src/lib/skill-mcp.js +336 -0
- package/src/lib/social-manager.js +330 -0
- package/src/lib/sso-manager.js +340 -0
- package/src/lib/stix-parser.js +346 -0
- package/src/lib/sub-agent-context.js +343 -0
- package/src/lib/sub-agent-profiles.js +335 -0
- package/src/lib/sub-agent-registry.js +336 -0
- package/src/lib/sync-manager.js +336 -0
- package/src/lib/tech-learning-engine.js +341 -0
- package/src/lib/tenant-saas.js +341 -0
- package/src/lib/threat-intel.js +330 -0
- package/src/lib/todo-manager.js +336 -0
- package/src/lib/token-tracker.js +336 -0
- package/src/lib/trust-security.js +343 -0
- package/src/lib/ueba.js +340 -0
- package/src/lib/universal-runtime.js +330 -0
- package/src/lib/wallet-manager.js +336 -0
- package/src/lib/web-ui-server.js +348 -0
- package/src/lib/workflow-engine.js +330 -0
- package/src/lib/workflow-expr.js +346 -0
- package/src/lib/ws-chat-handler.js +337 -0
|
@@ -1097,3 +1097,344 @@ export function getInferenceNetworkGovStatsV2() {
|
|
|
1097
1097
|
jobsByStatus,
|
|
1098
1098
|
};
|
|
1099
1099
|
}
|
|
1100
|
+
|
|
1101
|
+
// === Iter28 V2 governance overlay: Infnetgov ===
|
|
1102
|
+
export const INFNETGOV_PROFILE_MATURITY_V2 = Object.freeze({
|
|
1103
|
+
PENDING: "pending",
|
|
1104
|
+
ACTIVE: "active",
|
|
1105
|
+
STALE: "stale",
|
|
1106
|
+
ARCHIVED: "archived",
|
|
1107
|
+
});
|
|
1108
|
+
export const INFNETGOV_REQUEST_LIFECYCLE_V2 = Object.freeze({
|
|
1109
|
+
QUEUED: "queued",
|
|
1110
|
+
INFERRING: "inferring",
|
|
1111
|
+
INFERRED: "inferred",
|
|
1112
|
+
FAILED: "failed",
|
|
1113
|
+
CANCELLED: "cancelled",
|
|
1114
|
+
});
|
|
1115
|
+
const _infnetgovPTrans = new Map([
|
|
1116
|
+
[
|
|
1117
|
+
INFNETGOV_PROFILE_MATURITY_V2.PENDING,
|
|
1118
|
+
new Set([
|
|
1119
|
+
INFNETGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
1120
|
+
INFNETGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
1121
|
+
]),
|
|
1122
|
+
],
|
|
1123
|
+
[
|
|
1124
|
+
INFNETGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
1125
|
+
new Set([
|
|
1126
|
+
INFNETGOV_PROFILE_MATURITY_V2.STALE,
|
|
1127
|
+
INFNETGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
1128
|
+
]),
|
|
1129
|
+
],
|
|
1130
|
+
[
|
|
1131
|
+
INFNETGOV_PROFILE_MATURITY_V2.STALE,
|
|
1132
|
+
new Set([
|
|
1133
|
+
INFNETGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
1134
|
+
INFNETGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
1135
|
+
]),
|
|
1136
|
+
],
|
|
1137
|
+
[INFNETGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
|
|
1138
|
+
]);
|
|
1139
|
+
const _infnetgovPTerminal = new Set([INFNETGOV_PROFILE_MATURITY_V2.ARCHIVED]);
|
|
1140
|
+
const _infnetgovJTrans = new Map([
|
|
1141
|
+
[
|
|
1142
|
+
INFNETGOV_REQUEST_LIFECYCLE_V2.QUEUED,
|
|
1143
|
+
new Set([
|
|
1144
|
+
INFNETGOV_REQUEST_LIFECYCLE_V2.INFERRING,
|
|
1145
|
+
INFNETGOV_REQUEST_LIFECYCLE_V2.CANCELLED,
|
|
1146
|
+
]),
|
|
1147
|
+
],
|
|
1148
|
+
[
|
|
1149
|
+
INFNETGOV_REQUEST_LIFECYCLE_V2.INFERRING,
|
|
1150
|
+
new Set([
|
|
1151
|
+
INFNETGOV_REQUEST_LIFECYCLE_V2.INFERRED,
|
|
1152
|
+
INFNETGOV_REQUEST_LIFECYCLE_V2.FAILED,
|
|
1153
|
+
INFNETGOV_REQUEST_LIFECYCLE_V2.CANCELLED,
|
|
1154
|
+
]),
|
|
1155
|
+
],
|
|
1156
|
+
[INFNETGOV_REQUEST_LIFECYCLE_V2.INFERRED, new Set()],
|
|
1157
|
+
[INFNETGOV_REQUEST_LIFECYCLE_V2.FAILED, new Set()],
|
|
1158
|
+
[INFNETGOV_REQUEST_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
1159
|
+
]);
|
|
1160
|
+
const _infnetgovPsV2 = new Map();
|
|
1161
|
+
const _infnetgovJsV2 = new Map();
|
|
1162
|
+
let _infnetgovMaxActive = 8,
|
|
1163
|
+
_infnetgovMaxPending = 25,
|
|
1164
|
+
_infnetgovIdleMs = 2592000000,
|
|
1165
|
+
_infnetgovStuckMs = 60 * 1000;
|
|
1166
|
+
function _infnetgovPos(n, label) {
|
|
1167
|
+
const v = Math.floor(Number(n));
|
|
1168
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
1169
|
+
throw new Error(`${label} must be positive integer`);
|
|
1170
|
+
return v;
|
|
1171
|
+
}
|
|
1172
|
+
function _infnetgovCheckP(from, to) {
|
|
1173
|
+
const a = _infnetgovPTrans.get(from);
|
|
1174
|
+
if (!a || !a.has(to))
|
|
1175
|
+
throw new Error(`invalid infnetgov profile transition ${from} → ${to}`);
|
|
1176
|
+
}
|
|
1177
|
+
function _infnetgovCheckJ(from, to) {
|
|
1178
|
+
const a = _infnetgovJTrans.get(from);
|
|
1179
|
+
if (!a || !a.has(to))
|
|
1180
|
+
throw new Error(`invalid infnetgov request transition ${from} → ${to}`);
|
|
1181
|
+
}
|
|
1182
|
+
function _infnetgovCountActive(owner) {
|
|
1183
|
+
let c = 0;
|
|
1184
|
+
for (const p of _infnetgovPsV2.values())
|
|
1185
|
+
if (p.owner === owner && p.status === INFNETGOV_PROFILE_MATURITY_V2.ACTIVE)
|
|
1186
|
+
c++;
|
|
1187
|
+
return c;
|
|
1188
|
+
}
|
|
1189
|
+
function _infnetgovCountPending(profileId) {
|
|
1190
|
+
let c = 0;
|
|
1191
|
+
for (const j of _infnetgovJsV2.values())
|
|
1192
|
+
if (
|
|
1193
|
+
j.profileId === profileId &&
|
|
1194
|
+
(j.status === INFNETGOV_REQUEST_LIFECYCLE_V2.QUEUED ||
|
|
1195
|
+
j.status === INFNETGOV_REQUEST_LIFECYCLE_V2.INFERRING)
|
|
1196
|
+
)
|
|
1197
|
+
c++;
|
|
1198
|
+
return c;
|
|
1199
|
+
}
|
|
1200
|
+
export function setMaxActiveInfnetProfilesPerOwnerV2(n) {
|
|
1201
|
+
_infnetgovMaxActive = _infnetgovPos(n, "maxActiveInfnetProfilesPerOwner");
|
|
1202
|
+
}
|
|
1203
|
+
export function getMaxActiveInfnetProfilesPerOwnerV2() {
|
|
1204
|
+
return _infnetgovMaxActive;
|
|
1205
|
+
}
|
|
1206
|
+
export function setMaxPendingInfnetRequestsPerProfileV2(n) {
|
|
1207
|
+
_infnetgovMaxPending = _infnetgovPos(n, "maxPendingInfnetRequestsPerProfile");
|
|
1208
|
+
}
|
|
1209
|
+
export function getMaxPendingInfnetRequestsPerProfileV2() {
|
|
1210
|
+
return _infnetgovMaxPending;
|
|
1211
|
+
}
|
|
1212
|
+
export function setInfnetProfileIdleMsV2(n) {
|
|
1213
|
+
_infnetgovIdleMs = _infnetgovPos(n, "infnetgovProfileIdleMs");
|
|
1214
|
+
}
|
|
1215
|
+
export function getInfnetProfileIdleMsV2() {
|
|
1216
|
+
return _infnetgovIdleMs;
|
|
1217
|
+
}
|
|
1218
|
+
export function setInfnetRequestStuckMsV2(n) {
|
|
1219
|
+
_infnetgovStuckMs = _infnetgovPos(n, "infnetgovRequestStuckMs");
|
|
1220
|
+
}
|
|
1221
|
+
export function getInfnetRequestStuckMsV2() {
|
|
1222
|
+
return _infnetgovStuckMs;
|
|
1223
|
+
}
|
|
1224
|
+
export function _resetStateInfnetgovV2() {
|
|
1225
|
+
_infnetgovPsV2.clear();
|
|
1226
|
+
_infnetgovJsV2.clear();
|
|
1227
|
+
_infnetgovMaxActive = 8;
|
|
1228
|
+
_infnetgovMaxPending = 25;
|
|
1229
|
+
_infnetgovIdleMs = 2592000000;
|
|
1230
|
+
_infnetgovStuckMs = 60 * 1000;
|
|
1231
|
+
}
|
|
1232
|
+
export function registerInfnetProfileV2({ id, owner, node, metadata } = {}) {
|
|
1233
|
+
if (!id || !owner) throw new Error("id and owner required");
|
|
1234
|
+
if (_infnetgovPsV2.has(id))
|
|
1235
|
+
throw new Error(`infnetgov profile ${id} already exists`);
|
|
1236
|
+
const now = Date.now();
|
|
1237
|
+
const p = {
|
|
1238
|
+
id,
|
|
1239
|
+
owner,
|
|
1240
|
+
node: node || "default",
|
|
1241
|
+
status: INFNETGOV_PROFILE_MATURITY_V2.PENDING,
|
|
1242
|
+
createdAt: now,
|
|
1243
|
+
updatedAt: now,
|
|
1244
|
+
lastTouchedAt: now,
|
|
1245
|
+
activatedAt: null,
|
|
1246
|
+
archivedAt: null,
|
|
1247
|
+
metadata: { ...(metadata || {}) },
|
|
1248
|
+
};
|
|
1249
|
+
_infnetgovPsV2.set(id, p);
|
|
1250
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1251
|
+
}
|
|
1252
|
+
export function activateInfnetProfileV2(id) {
|
|
1253
|
+
const p = _infnetgovPsV2.get(id);
|
|
1254
|
+
if (!p) throw new Error(`infnetgov profile ${id} not found`);
|
|
1255
|
+
const isInitial = p.status === INFNETGOV_PROFILE_MATURITY_V2.PENDING;
|
|
1256
|
+
_infnetgovCheckP(p.status, INFNETGOV_PROFILE_MATURITY_V2.ACTIVE);
|
|
1257
|
+
if (isInitial && _infnetgovCountActive(p.owner) >= _infnetgovMaxActive)
|
|
1258
|
+
throw new Error(
|
|
1259
|
+
`max active infnetgov profiles for owner ${p.owner} reached`,
|
|
1260
|
+
);
|
|
1261
|
+
const now = Date.now();
|
|
1262
|
+
p.status = INFNETGOV_PROFILE_MATURITY_V2.ACTIVE;
|
|
1263
|
+
p.updatedAt = now;
|
|
1264
|
+
p.lastTouchedAt = now;
|
|
1265
|
+
if (!p.activatedAt) p.activatedAt = now;
|
|
1266
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1267
|
+
}
|
|
1268
|
+
export function staleInfnetProfileV2(id) {
|
|
1269
|
+
const p = _infnetgovPsV2.get(id);
|
|
1270
|
+
if (!p) throw new Error(`infnetgov profile ${id} not found`);
|
|
1271
|
+
_infnetgovCheckP(p.status, INFNETGOV_PROFILE_MATURITY_V2.STALE);
|
|
1272
|
+
p.status = INFNETGOV_PROFILE_MATURITY_V2.STALE;
|
|
1273
|
+
p.updatedAt = Date.now();
|
|
1274
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1275
|
+
}
|
|
1276
|
+
export function archiveInfnetProfileV2(id) {
|
|
1277
|
+
const p = _infnetgovPsV2.get(id);
|
|
1278
|
+
if (!p) throw new Error(`infnetgov profile ${id} not found`);
|
|
1279
|
+
_infnetgovCheckP(p.status, INFNETGOV_PROFILE_MATURITY_V2.ARCHIVED);
|
|
1280
|
+
const now = Date.now();
|
|
1281
|
+
p.status = INFNETGOV_PROFILE_MATURITY_V2.ARCHIVED;
|
|
1282
|
+
p.updatedAt = now;
|
|
1283
|
+
if (!p.archivedAt) p.archivedAt = now;
|
|
1284
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1285
|
+
}
|
|
1286
|
+
export function touchInfnetProfileV2(id) {
|
|
1287
|
+
const p = _infnetgovPsV2.get(id);
|
|
1288
|
+
if (!p) throw new Error(`infnetgov profile ${id} not found`);
|
|
1289
|
+
if (_infnetgovPTerminal.has(p.status))
|
|
1290
|
+
throw new Error(`cannot touch terminal infnetgov profile ${id}`);
|
|
1291
|
+
const now = Date.now();
|
|
1292
|
+
p.lastTouchedAt = now;
|
|
1293
|
+
p.updatedAt = now;
|
|
1294
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1295
|
+
}
|
|
1296
|
+
export function getInfnetProfileV2(id) {
|
|
1297
|
+
const p = _infnetgovPsV2.get(id);
|
|
1298
|
+
if (!p) return null;
|
|
1299
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1300
|
+
}
|
|
1301
|
+
export function listInfnetProfilesV2() {
|
|
1302
|
+
return [..._infnetgovPsV2.values()].map((p) => ({
|
|
1303
|
+
...p,
|
|
1304
|
+
metadata: { ...p.metadata },
|
|
1305
|
+
}));
|
|
1306
|
+
}
|
|
1307
|
+
export function createInfnetRequestV2({
|
|
1308
|
+
id,
|
|
1309
|
+
profileId,
|
|
1310
|
+
requestId,
|
|
1311
|
+
metadata,
|
|
1312
|
+
} = {}) {
|
|
1313
|
+
if (!id || !profileId) throw new Error("id and profileId required");
|
|
1314
|
+
if (_infnetgovJsV2.has(id))
|
|
1315
|
+
throw new Error(`infnetgov request ${id} already exists`);
|
|
1316
|
+
if (!_infnetgovPsV2.has(profileId))
|
|
1317
|
+
throw new Error(`infnetgov profile ${profileId} not found`);
|
|
1318
|
+
if (_infnetgovCountPending(profileId) >= _infnetgovMaxPending)
|
|
1319
|
+
throw new Error(
|
|
1320
|
+
`max pending infnetgov requests for profile ${profileId} reached`,
|
|
1321
|
+
);
|
|
1322
|
+
const now = Date.now();
|
|
1323
|
+
const j = {
|
|
1324
|
+
id,
|
|
1325
|
+
profileId,
|
|
1326
|
+
requestId: requestId || "",
|
|
1327
|
+
status: INFNETGOV_REQUEST_LIFECYCLE_V2.QUEUED,
|
|
1328
|
+
createdAt: now,
|
|
1329
|
+
updatedAt: now,
|
|
1330
|
+
startedAt: null,
|
|
1331
|
+
settledAt: null,
|
|
1332
|
+
metadata: { ...(metadata || {}) },
|
|
1333
|
+
};
|
|
1334
|
+
_infnetgovJsV2.set(id, j);
|
|
1335
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1336
|
+
}
|
|
1337
|
+
export function inferringInfnetRequestV2(id) {
|
|
1338
|
+
const j = _infnetgovJsV2.get(id);
|
|
1339
|
+
if (!j) throw new Error(`infnetgov request ${id} not found`);
|
|
1340
|
+
_infnetgovCheckJ(j.status, INFNETGOV_REQUEST_LIFECYCLE_V2.INFERRING);
|
|
1341
|
+
const now = Date.now();
|
|
1342
|
+
j.status = INFNETGOV_REQUEST_LIFECYCLE_V2.INFERRING;
|
|
1343
|
+
j.updatedAt = now;
|
|
1344
|
+
if (!j.startedAt) j.startedAt = now;
|
|
1345
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1346
|
+
}
|
|
1347
|
+
export function completeRequestInfnetV2(id) {
|
|
1348
|
+
const j = _infnetgovJsV2.get(id);
|
|
1349
|
+
if (!j) throw new Error(`infnetgov request ${id} not found`);
|
|
1350
|
+
_infnetgovCheckJ(j.status, INFNETGOV_REQUEST_LIFECYCLE_V2.INFERRED);
|
|
1351
|
+
const now = Date.now();
|
|
1352
|
+
j.status = INFNETGOV_REQUEST_LIFECYCLE_V2.INFERRED;
|
|
1353
|
+
j.updatedAt = now;
|
|
1354
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1355
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1356
|
+
}
|
|
1357
|
+
export function failInfnetRequestV2(id, reason) {
|
|
1358
|
+
const j = _infnetgovJsV2.get(id);
|
|
1359
|
+
if (!j) throw new Error(`infnetgov request ${id} not found`);
|
|
1360
|
+
_infnetgovCheckJ(j.status, INFNETGOV_REQUEST_LIFECYCLE_V2.FAILED);
|
|
1361
|
+
const now = Date.now();
|
|
1362
|
+
j.status = INFNETGOV_REQUEST_LIFECYCLE_V2.FAILED;
|
|
1363
|
+
j.updatedAt = now;
|
|
1364
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1365
|
+
if (reason) j.metadata.failReason = String(reason);
|
|
1366
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1367
|
+
}
|
|
1368
|
+
export function cancelInfnetRequestV2(id, reason) {
|
|
1369
|
+
const j = _infnetgovJsV2.get(id);
|
|
1370
|
+
if (!j) throw new Error(`infnetgov request ${id} not found`);
|
|
1371
|
+
_infnetgovCheckJ(j.status, INFNETGOV_REQUEST_LIFECYCLE_V2.CANCELLED);
|
|
1372
|
+
const now = Date.now();
|
|
1373
|
+
j.status = INFNETGOV_REQUEST_LIFECYCLE_V2.CANCELLED;
|
|
1374
|
+
j.updatedAt = now;
|
|
1375
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1376
|
+
if (reason) j.metadata.cancelReason = String(reason);
|
|
1377
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1378
|
+
}
|
|
1379
|
+
export function getInfnetRequestV2(id) {
|
|
1380
|
+
const j = _infnetgovJsV2.get(id);
|
|
1381
|
+
if (!j) return null;
|
|
1382
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1383
|
+
}
|
|
1384
|
+
export function listInfnetRequestsV2() {
|
|
1385
|
+
return [..._infnetgovJsV2.values()].map((j) => ({
|
|
1386
|
+
...j,
|
|
1387
|
+
metadata: { ...j.metadata },
|
|
1388
|
+
}));
|
|
1389
|
+
}
|
|
1390
|
+
export function autoStaleIdleInfnetProfilesV2({ now } = {}) {
|
|
1391
|
+
const t = now ?? Date.now();
|
|
1392
|
+
const flipped = [];
|
|
1393
|
+
for (const p of _infnetgovPsV2.values())
|
|
1394
|
+
if (
|
|
1395
|
+
p.status === INFNETGOV_PROFILE_MATURITY_V2.ACTIVE &&
|
|
1396
|
+
t - p.lastTouchedAt >= _infnetgovIdleMs
|
|
1397
|
+
) {
|
|
1398
|
+
p.status = INFNETGOV_PROFILE_MATURITY_V2.STALE;
|
|
1399
|
+
p.updatedAt = t;
|
|
1400
|
+
flipped.push(p.id);
|
|
1401
|
+
}
|
|
1402
|
+
return { flipped, count: flipped.length };
|
|
1403
|
+
}
|
|
1404
|
+
export function autoFailStuckInfnetRequestsV2({ now } = {}) {
|
|
1405
|
+
const t = now ?? Date.now();
|
|
1406
|
+
const flipped = [];
|
|
1407
|
+
for (const j of _infnetgovJsV2.values())
|
|
1408
|
+
if (
|
|
1409
|
+
j.status === INFNETGOV_REQUEST_LIFECYCLE_V2.INFERRING &&
|
|
1410
|
+
j.startedAt != null &&
|
|
1411
|
+
t - j.startedAt >= _infnetgovStuckMs
|
|
1412
|
+
) {
|
|
1413
|
+
j.status = INFNETGOV_REQUEST_LIFECYCLE_V2.FAILED;
|
|
1414
|
+
j.updatedAt = t;
|
|
1415
|
+
if (!j.settledAt) j.settledAt = t;
|
|
1416
|
+
j.metadata.failReason = "auto-fail-stuck";
|
|
1417
|
+
flipped.push(j.id);
|
|
1418
|
+
}
|
|
1419
|
+
return { flipped, count: flipped.length };
|
|
1420
|
+
}
|
|
1421
|
+
export function getInfnetgovStatsV2() {
|
|
1422
|
+
const profilesByStatus = {};
|
|
1423
|
+
for (const v of Object.values(INFNETGOV_PROFILE_MATURITY_V2))
|
|
1424
|
+
profilesByStatus[v] = 0;
|
|
1425
|
+
for (const p of _infnetgovPsV2.values()) profilesByStatus[p.status]++;
|
|
1426
|
+
const requestsByStatus = {};
|
|
1427
|
+
for (const v of Object.values(INFNETGOV_REQUEST_LIFECYCLE_V2))
|
|
1428
|
+
requestsByStatus[v] = 0;
|
|
1429
|
+
for (const j of _infnetgovJsV2.values()) requestsByStatus[j.status]++;
|
|
1430
|
+
return {
|
|
1431
|
+
totalInfnetProfilesV2: _infnetgovPsV2.size,
|
|
1432
|
+
totalInfnetRequestsV2: _infnetgovJsV2.size,
|
|
1433
|
+
maxActiveInfnetProfilesPerOwner: _infnetgovMaxActive,
|
|
1434
|
+
maxPendingInfnetRequestsPerProfile: _infnetgovMaxPending,
|
|
1435
|
+
infnetgovProfileIdleMs: _infnetgovIdleMs,
|
|
1436
|
+
infnetgovRequestStuckMs: _infnetgovStuckMs,
|
|
1437
|
+
profilesByStatus,
|
|
1438
|
+
requestsByStatus,
|
|
1439
|
+
};
|
|
1440
|
+
}
|
|
@@ -520,3 +520,349 @@ export function _resetStateInstinctManagerV2() {
|
|
|
520
520
|
_profileIdleMsV2 = INSTINCT_DEFAULT_PROFILE_IDLE_MS;
|
|
521
521
|
_obsStuckMsV2 = INSTINCT_DEFAULT_OBS_STUCK_MS;
|
|
522
522
|
}
|
|
523
|
+
|
|
524
|
+
// =====================================================================
|
|
525
|
+
// instinct-manager V2 governance overlay (iter18)
|
|
526
|
+
// =====================================================================
|
|
527
|
+
export const INSTGOV_PROFILE_MATURITY_V2 = Object.freeze({
|
|
528
|
+
PENDING: "pending",
|
|
529
|
+
ACTIVE: "active",
|
|
530
|
+
DORMANT: "dormant",
|
|
531
|
+
ARCHIVED: "archived",
|
|
532
|
+
});
|
|
533
|
+
export const INSTGOV_TRIGGER_LIFECYCLE_V2 = Object.freeze({
|
|
534
|
+
QUEUED: "queued",
|
|
535
|
+
FIRING: "firing",
|
|
536
|
+
FIRED: "fired",
|
|
537
|
+
FAILED: "failed",
|
|
538
|
+
CANCELLED: "cancelled",
|
|
539
|
+
});
|
|
540
|
+
const _instgovPTrans = new Map([
|
|
541
|
+
[
|
|
542
|
+
INSTGOV_PROFILE_MATURITY_V2.PENDING,
|
|
543
|
+
new Set([
|
|
544
|
+
INSTGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
545
|
+
INSTGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
546
|
+
]),
|
|
547
|
+
],
|
|
548
|
+
[
|
|
549
|
+
INSTGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
550
|
+
new Set([
|
|
551
|
+
INSTGOV_PROFILE_MATURITY_V2.DORMANT,
|
|
552
|
+
INSTGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
553
|
+
]),
|
|
554
|
+
],
|
|
555
|
+
[
|
|
556
|
+
INSTGOV_PROFILE_MATURITY_V2.DORMANT,
|
|
557
|
+
new Set([
|
|
558
|
+
INSTGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
559
|
+
INSTGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
560
|
+
]),
|
|
561
|
+
],
|
|
562
|
+
[INSTGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
|
|
563
|
+
]);
|
|
564
|
+
const _instgovPTerminal = new Set([INSTGOV_PROFILE_MATURITY_V2.ARCHIVED]);
|
|
565
|
+
const _instgovJTrans = new Map([
|
|
566
|
+
[
|
|
567
|
+
INSTGOV_TRIGGER_LIFECYCLE_V2.QUEUED,
|
|
568
|
+
new Set([
|
|
569
|
+
INSTGOV_TRIGGER_LIFECYCLE_V2.FIRING,
|
|
570
|
+
INSTGOV_TRIGGER_LIFECYCLE_V2.CANCELLED,
|
|
571
|
+
]),
|
|
572
|
+
],
|
|
573
|
+
[
|
|
574
|
+
INSTGOV_TRIGGER_LIFECYCLE_V2.FIRING,
|
|
575
|
+
new Set([
|
|
576
|
+
INSTGOV_TRIGGER_LIFECYCLE_V2.FIRED,
|
|
577
|
+
INSTGOV_TRIGGER_LIFECYCLE_V2.FAILED,
|
|
578
|
+
INSTGOV_TRIGGER_LIFECYCLE_V2.CANCELLED,
|
|
579
|
+
]),
|
|
580
|
+
],
|
|
581
|
+
[INSTGOV_TRIGGER_LIFECYCLE_V2.FIRED, new Set()],
|
|
582
|
+
[INSTGOV_TRIGGER_LIFECYCLE_V2.FAILED, new Set()],
|
|
583
|
+
[INSTGOV_TRIGGER_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
584
|
+
]);
|
|
585
|
+
const _instgovPsV2 = new Map();
|
|
586
|
+
const _instgovJsV2 = new Map();
|
|
587
|
+
let _instgovMaxActive = 8,
|
|
588
|
+
_instgovMaxPending = 20,
|
|
589
|
+
_instgovIdleMs = 30 * 24 * 60 * 60 * 1000,
|
|
590
|
+
_instgovStuckMs = 60 * 1000;
|
|
591
|
+
function _instgovPos(n, label) {
|
|
592
|
+
const v = Math.floor(Number(n));
|
|
593
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
594
|
+
throw new Error(`${label} must be positive integer`);
|
|
595
|
+
return v;
|
|
596
|
+
}
|
|
597
|
+
function _instgovCheckP(from, to) {
|
|
598
|
+
const a = _instgovPTrans.get(from);
|
|
599
|
+
if (!a || !a.has(to))
|
|
600
|
+
throw new Error(`invalid instgov profile transition ${from} → ${to}`);
|
|
601
|
+
}
|
|
602
|
+
function _instgovCheckJ(from, to) {
|
|
603
|
+
const a = _instgovJTrans.get(from);
|
|
604
|
+
if (!a || !a.has(to))
|
|
605
|
+
throw new Error(`invalid instgov trigger transition ${from} → ${to}`);
|
|
606
|
+
}
|
|
607
|
+
function _instgovCountActive(owner) {
|
|
608
|
+
let c = 0;
|
|
609
|
+
for (const p of _instgovPsV2.values())
|
|
610
|
+
if (p.owner === owner && p.status === INSTGOV_PROFILE_MATURITY_V2.ACTIVE)
|
|
611
|
+
c++;
|
|
612
|
+
return c;
|
|
613
|
+
}
|
|
614
|
+
function _instgovCountPending(profileId) {
|
|
615
|
+
let c = 0;
|
|
616
|
+
for (const j of _instgovJsV2.values())
|
|
617
|
+
if (
|
|
618
|
+
j.profileId === profileId &&
|
|
619
|
+
(j.status === INSTGOV_TRIGGER_LIFECYCLE_V2.QUEUED ||
|
|
620
|
+
j.status === INSTGOV_TRIGGER_LIFECYCLE_V2.FIRING)
|
|
621
|
+
)
|
|
622
|
+
c++;
|
|
623
|
+
return c;
|
|
624
|
+
}
|
|
625
|
+
export function setMaxActiveInstgovProfilesPerOwnerV2(n) {
|
|
626
|
+
_instgovMaxActive = _instgovPos(n, "maxActiveInstgovProfilesPerOwner");
|
|
627
|
+
}
|
|
628
|
+
export function getMaxActiveInstgovProfilesPerOwnerV2() {
|
|
629
|
+
return _instgovMaxActive;
|
|
630
|
+
}
|
|
631
|
+
export function setMaxPendingInstgovTriggersPerProfileV2(n) {
|
|
632
|
+
_instgovMaxPending = _instgovPos(n, "maxPendingInstgovTriggersPerProfile");
|
|
633
|
+
}
|
|
634
|
+
export function getMaxPendingInstgovTriggersPerProfileV2() {
|
|
635
|
+
return _instgovMaxPending;
|
|
636
|
+
}
|
|
637
|
+
export function setInstgovProfileIdleMsV2(n) {
|
|
638
|
+
_instgovIdleMs = _instgovPos(n, "instgovProfileIdleMs");
|
|
639
|
+
}
|
|
640
|
+
export function getInstgovProfileIdleMsV2() {
|
|
641
|
+
return _instgovIdleMs;
|
|
642
|
+
}
|
|
643
|
+
export function setInstgovTriggerStuckMsV2(n) {
|
|
644
|
+
_instgovStuckMs = _instgovPos(n, "instgovTriggerStuckMs");
|
|
645
|
+
}
|
|
646
|
+
export function getInstgovTriggerStuckMsV2() {
|
|
647
|
+
return _instgovStuckMs;
|
|
648
|
+
}
|
|
649
|
+
export function _resetStateInstinctManagerGovV2() {
|
|
650
|
+
_instgovPsV2.clear();
|
|
651
|
+
_instgovJsV2.clear();
|
|
652
|
+
_instgovMaxActive = 8;
|
|
653
|
+
_instgovMaxPending = 20;
|
|
654
|
+
_instgovIdleMs = 30 * 24 * 60 * 60 * 1000;
|
|
655
|
+
_instgovStuckMs = 60 * 1000;
|
|
656
|
+
}
|
|
657
|
+
export function registerInstgovProfileV2({
|
|
658
|
+
id,
|
|
659
|
+
owner,
|
|
660
|
+
priority,
|
|
661
|
+
metadata,
|
|
662
|
+
} = {}) {
|
|
663
|
+
if (!id || !owner) throw new Error("id and owner required");
|
|
664
|
+
if (_instgovPsV2.has(id))
|
|
665
|
+
throw new Error(`instgov profile ${id} already exists`);
|
|
666
|
+
const now = Date.now();
|
|
667
|
+
const p = {
|
|
668
|
+
id,
|
|
669
|
+
owner,
|
|
670
|
+
priority: priority || "normal",
|
|
671
|
+
status: INSTGOV_PROFILE_MATURITY_V2.PENDING,
|
|
672
|
+
createdAt: now,
|
|
673
|
+
updatedAt: now,
|
|
674
|
+
lastTouchedAt: now,
|
|
675
|
+
activatedAt: null,
|
|
676
|
+
archivedAt: null,
|
|
677
|
+
metadata: { ...(metadata || {}) },
|
|
678
|
+
};
|
|
679
|
+
_instgovPsV2.set(id, p);
|
|
680
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
681
|
+
}
|
|
682
|
+
export function activateInstgovProfileV2(id) {
|
|
683
|
+
const p = _instgovPsV2.get(id);
|
|
684
|
+
if (!p) throw new Error(`instgov profile ${id} not found`);
|
|
685
|
+
const isInitial = p.status === INSTGOV_PROFILE_MATURITY_V2.PENDING;
|
|
686
|
+
_instgovCheckP(p.status, INSTGOV_PROFILE_MATURITY_V2.ACTIVE);
|
|
687
|
+
if (isInitial && _instgovCountActive(p.owner) >= _instgovMaxActive)
|
|
688
|
+
throw new Error(`max active instgov profiles for owner ${p.owner} reached`);
|
|
689
|
+
const now = Date.now();
|
|
690
|
+
p.status = INSTGOV_PROFILE_MATURITY_V2.ACTIVE;
|
|
691
|
+
p.updatedAt = now;
|
|
692
|
+
p.lastTouchedAt = now;
|
|
693
|
+
if (!p.activatedAt) p.activatedAt = now;
|
|
694
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
695
|
+
}
|
|
696
|
+
export function dormantInstgovProfileV2(id) {
|
|
697
|
+
const p = _instgovPsV2.get(id);
|
|
698
|
+
if (!p) throw new Error(`instgov profile ${id} not found`);
|
|
699
|
+
_instgovCheckP(p.status, INSTGOV_PROFILE_MATURITY_V2.DORMANT);
|
|
700
|
+
p.status = INSTGOV_PROFILE_MATURITY_V2.DORMANT;
|
|
701
|
+
p.updatedAt = Date.now();
|
|
702
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
703
|
+
}
|
|
704
|
+
export function archiveInstgovProfileV2(id) {
|
|
705
|
+
const p = _instgovPsV2.get(id);
|
|
706
|
+
if (!p) throw new Error(`instgov profile ${id} not found`);
|
|
707
|
+
_instgovCheckP(p.status, INSTGOV_PROFILE_MATURITY_V2.ARCHIVED);
|
|
708
|
+
const now = Date.now();
|
|
709
|
+
p.status = INSTGOV_PROFILE_MATURITY_V2.ARCHIVED;
|
|
710
|
+
p.updatedAt = now;
|
|
711
|
+
if (!p.archivedAt) p.archivedAt = now;
|
|
712
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
713
|
+
}
|
|
714
|
+
export function touchInstgovProfileV2(id) {
|
|
715
|
+
const p = _instgovPsV2.get(id);
|
|
716
|
+
if (!p) throw new Error(`instgov profile ${id} not found`);
|
|
717
|
+
if (_instgovPTerminal.has(p.status))
|
|
718
|
+
throw new Error(`cannot touch terminal instgov profile ${id}`);
|
|
719
|
+
const now = Date.now();
|
|
720
|
+
p.lastTouchedAt = now;
|
|
721
|
+
p.updatedAt = now;
|
|
722
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
723
|
+
}
|
|
724
|
+
export function getInstgovProfileV2(id) {
|
|
725
|
+
const p = _instgovPsV2.get(id);
|
|
726
|
+
if (!p) return null;
|
|
727
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
728
|
+
}
|
|
729
|
+
export function listInstgovProfilesV2() {
|
|
730
|
+
return [..._instgovPsV2.values()].map((p) => ({
|
|
731
|
+
...p,
|
|
732
|
+
metadata: { ...p.metadata },
|
|
733
|
+
}));
|
|
734
|
+
}
|
|
735
|
+
export function createInstgovTriggerV2({
|
|
736
|
+
id,
|
|
737
|
+
profileId,
|
|
738
|
+
pattern,
|
|
739
|
+
metadata,
|
|
740
|
+
} = {}) {
|
|
741
|
+
if (!id || !profileId) throw new Error("id and profileId required");
|
|
742
|
+
if (_instgovJsV2.has(id))
|
|
743
|
+
throw new Error(`instgov trigger ${id} already exists`);
|
|
744
|
+
if (!_instgovPsV2.has(profileId))
|
|
745
|
+
throw new Error(`instgov profile ${profileId} not found`);
|
|
746
|
+
if (_instgovCountPending(profileId) >= _instgovMaxPending)
|
|
747
|
+
throw new Error(
|
|
748
|
+
`max pending instgov triggers for profile ${profileId} reached`,
|
|
749
|
+
);
|
|
750
|
+
const now = Date.now();
|
|
751
|
+
const j = {
|
|
752
|
+
id,
|
|
753
|
+
profileId,
|
|
754
|
+
pattern: pattern || "",
|
|
755
|
+
status: INSTGOV_TRIGGER_LIFECYCLE_V2.QUEUED,
|
|
756
|
+
createdAt: now,
|
|
757
|
+
updatedAt: now,
|
|
758
|
+
startedAt: null,
|
|
759
|
+
settledAt: null,
|
|
760
|
+
metadata: { ...(metadata || {}) },
|
|
761
|
+
};
|
|
762
|
+
_instgovJsV2.set(id, j);
|
|
763
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
764
|
+
}
|
|
765
|
+
export function firingInstgovTriggerV2(id) {
|
|
766
|
+
const j = _instgovJsV2.get(id);
|
|
767
|
+
if (!j) throw new Error(`instgov trigger ${id} not found`);
|
|
768
|
+
_instgovCheckJ(j.status, INSTGOV_TRIGGER_LIFECYCLE_V2.FIRING);
|
|
769
|
+
const now = Date.now();
|
|
770
|
+
j.status = INSTGOV_TRIGGER_LIFECYCLE_V2.FIRING;
|
|
771
|
+
j.updatedAt = now;
|
|
772
|
+
if (!j.startedAt) j.startedAt = now;
|
|
773
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
774
|
+
}
|
|
775
|
+
export function completeTriggerInstgovV2(id) {
|
|
776
|
+
const j = _instgovJsV2.get(id);
|
|
777
|
+
if (!j) throw new Error(`instgov trigger ${id} not found`);
|
|
778
|
+
_instgovCheckJ(j.status, INSTGOV_TRIGGER_LIFECYCLE_V2.FIRED);
|
|
779
|
+
const now = Date.now();
|
|
780
|
+
j.status = INSTGOV_TRIGGER_LIFECYCLE_V2.FIRED;
|
|
781
|
+
j.updatedAt = now;
|
|
782
|
+
if (!j.settledAt) j.settledAt = now;
|
|
783
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
784
|
+
}
|
|
785
|
+
export function failInstgovTriggerV2(id, reason) {
|
|
786
|
+
const j = _instgovJsV2.get(id);
|
|
787
|
+
if (!j) throw new Error(`instgov trigger ${id} not found`);
|
|
788
|
+
_instgovCheckJ(j.status, INSTGOV_TRIGGER_LIFECYCLE_V2.FAILED);
|
|
789
|
+
const now = Date.now();
|
|
790
|
+
j.status = INSTGOV_TRIGGER_LIFECYCLE_V2.FAILED;
|
|
791
|
+
j.updatedAt = now;
|
|
792
|
+
if (!j.settledAt) j.settledAt = now;
|
|
793
|
+
if (reason) j.metadata.failReason = String(reason);
|
|
794
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
795
|
+
}
|
|
796
|
+
export function cancelInstgovTriggerV2(id, reason) {
|
|
797
|
+
const j = _instgovJsV2.get(id);
|
|
798
|
+
if (!j) throw new Error(`instgov trigger ${id} not found`);
|
|
799
|
+
_instgovCheckJ(j.status, INSTGOV_TRIGGER_LIFECYCLE_V2.CANCELLED);
|
|
800
|
+
const now = Date.now();
|
|
801
|
+
j.status = INSTGOV_TRIGGER_LIFECYCLE_V2.CANCELLED;
|
|
802
|
+
j.updatedAt = now;
|
|
803
|
+
if (!j.settledAt) j.settledAt = now;
|
|
804
|
+
if (reason) j.metadata.cancelReason = String(reason);
|
|
805
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
806
|
+
}
|
|
807
|
+
export function getInstgovTriggerV2(id) {
|
|
808
|
+
const j = _instgovJsV2.get(id);
|
|
809
|
+
if (!j) return null;
|
|
810
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
811
|
+
}
|
|
812
|
+
export function listInstgovTriggersV2() {
|
|
813
|
+
return [..._instgovJsV2.values()].map((j) => ({
|
|
814
|
+
...j,
|
|
815
|
+
metadata: { ...j.metadata },
|
|
816
|
+
}));
|
|
817
|
+
}
|
|
818
|
+
export function autoDormantIdleInstgovProfilesV2({ now } = {}) {
|
|
819
|
+
const t = now ?? Date.now();
|
|
820
|
+
const flipped = [];
|
|
821
|
+
for (const p of _instgovPsV2.values())
|
|
822
|
+
if (
|
|
823
|
+
p.status === INSTGOV_PROFILE_MATURITY_V2.ACTIVE &&
|
|
824
|
+
t - p.lastTouchedAt >= _instgovIdleMs
|
|
825
|
+
) {
|
|
826
|
+
p.status = INSTGOV_PROFILE_MATURITY_V2.DORMANT;
|
|
827
|
+
p.updatedAt = t;
|
|
828
|
+
flipped.push(p.id);
|
|
829
|
+
}
|
|
830
|
+
return { flipped, count: flipped.length };
|
|
831
|
+
}
|
|
832
|
+
export function autoFailStuckInstgovTriggersV2({ now } = {}) {
|
|
833
|
+
const t = now ?? Date.now();
|
|
834
|
+
const flipped = [];
|
|
835
|
+
for (const j of _instgovJsV2.values())
|
|
836
|
+
if (
|
|
837
|
+
j.status === INSTGOV_TRIGGER_LIFECYCLE_V2.FIRING &&
|
|
838
|
+
j.startedAt != null &&
|
|
839
|
+
t - j.startedAt >= _instgovStuckMs
|
|
840
|
+
) {
|
|
841
|
+
j.status = INSTGOV_TRIGGER_LIFECYCLE_V2.FAILED;
|
|
842
|
+
j.updatedAt = t;
|
|
843
|
+
if (!j.settledAt) j.settledAt = t;
|
|
844
|
+
j.metadata.failReason = "auto-fail-stuck";
|
|
845
|
+
flipped.push(j.id);
|
|
846
|
+
}
|
|
847
|
+
return { flipped, count: flipped.length };
|
|
848
|
+
}
|
|
849
|
+
export function getInstinctManagerGovStatsV2() {
|
|
850
|
+
const profilesByStatus = {};
|
|
851
|
+
for (const v of Object.values(INSTGOV_PROFILE_MATURITY_V2))
|
|
852
|
+
profilesByStatus[v] = 0;
|
|
853
|
+
for (const p of _instgovPsV2.values()) profilesByStatus[p.status]++;
|
|
854
|
+
const triggersByStatus = {};
|
|
855
|
+
for (const v of Object.values(INSTGOV_TRIGGER_LIFECYCLE_V2))
|
|
856
|
+
triggersByStatus[v] = 0;
|
|
857
|
+
for (const j of _instgovJsV2.values()) triggersByStatus[j.status]++;
|
|
858
|
+
return {
|
|
859
|
+
totalInstgovProfilesV2: _instgovPsV2.size,
|
|
860
|
+
totalInstgovTriggersV2: _instgovJsV2.size,
|
|
861
|
+
maxActiveInstgovProfilesPerOwner: _instgovMaxActive,
|
|
862
|
+
maxPendingInstgovTriggersPerProfile: _instgovMaxPending,
|
|
863
|
+
instgovProfileIdleMs: _instgovIdleMs,
|
|
864
|
+
instgovTriggerStuckMs: _instgovStuckMs,
|
|
865
|
+
profilesByStatus,
|
|
866
|
+
triggersByStatus,
|
|
867
|
+
};
|
|
868
|
+
}
|