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
|
@@ -91,81 +91,320 @@ export function buildMemoryInjection(options = {}) {
|
|
|
91
91
|
|
|
92
92
|
// ===== V2 Surface: Memory Injection governance overlay (CLI v0.142.0) =====
|
|
93
93
|
export const MINJ_RULE_MATURITY_V2 = Object.freeze({
|
|
94
|
-
PENDING: "pending",
|
|
94
|
+
PENDING: "pending",
|
|
95
|
+
ACTIVE: "active",
|
|
96
|
+
PAUSED: "paused",
|
|
97
|
+
ARCHIVED: "archived",
|
|
95
98
|
});
|
|
96
99
|
export const MINJ_INJECTION_LIFECYCLE_V2 = Object.freeze({
|
|
97
|
-
QUEUED: "queued",
|
|
100
|
+
QUEUED: "queued",
|
|
101
|
+
INJECTING: "injecting",
|
|
102
|
+
APPLIED: "applied",
|
|
103
|
+
FAILED: "failed",
|
|
104
|
+
CANCELLED: "cancelled",
|
|
98
105
|
});
|
|
99
106
|
const _minjRTrans = new Map([
|
|
100
|
-
[
|
|
101
|
-
|
|
102
|
-
|
|
107
|
+
[
|
|
108
|
+
MINJ_RULE_MATURITY_V2.PENDING,
|
|
109
|
+
new Set([MINJ_RULE_MATURITY_V2.ACTIVE, MINJ_RULE_MATURITY_V2.ARCHIVED]),
|
|
110
|
+
],
|
|
111
|
+
[
|
|
112
|
+
MINJ_RULE_MATURITY_V2.ACTIVE,
|
|
113
|
+
new Set([MINJ_RULE_MATURITY_V2.PAUSED, MINJ_RULE_MATURITY_V2.ARCHIVED]),
|
|
114
|
+
],
|
|
115
|
+
[
|
|
116
|
+
MINJ_RULE_MATURITY_V2.PAUSED,
|
|
117
|
+
new Set([MINJ_RULE_MATURITY_V2.ACTIVE, MINJ_RULE_MATURITY_V2.ARCHIVED]),
|
|
118
|
+
],
|
|
103
119
|
[MINJ_RULE_MATURITY_V2.ARCHIVED, new Set()],
|
|
104
120
|
]);
|
|
105
121
|
const _minjRTerminal = new Set([MINJ_RULE_MATURITY_V2.ARCHIVED]);
|
|
106
122
|
const _minjITrans = new Map([
|
|
107
|
-
[
|
|
108
|
-
|
|
123
|
+
[
|
|
124
|
+
MINJ_INJECTION_LIFECYCLE_V2.QUEUED,
|
|
125
|
+
new Set([
|
|
126
|
+
MINJ_INJECTION_LIFECYCLE_V2.INJECTING,
|
|
127
|
+
MINJ_INJECTION_LIFECYCLE_V2.CANCELLED,
|
|
128
|
+
]),
|
|
129
|
+
],
|
|
130
|
+
[
|
|
131
|
+
MINJ_INJECTION_LIFECYCLE_V2.INJECTING,
|
|
132
|
+
new Set([
|
|
133
|
+
MINJ_INJECTION_LIFECYCLE_V2.APPLIED,
|
|
134
|
+
MINJ_INJECTION_LIFECYCLE_V2.FAILED,
|
|
135
|
+
MINJ_INJECTION_LIFECYCLE_V2.CANCELLED,
|
|
136
|
+
]),
|
|
137
|
+
],
|
|
109
138
|
[MINJ_INJECTION_LIFECYCLE_V2.APPLIED, new Set()],
|
|
110
139
|
[MINJ_INJECTION_LIFECYCLE_V2.FAILED, new Set()],
|
|
111
140
|
[MINJ_INJECTION_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
112
141
|
]);
|
|
113
142
|
const _minjRsV2 = new Map();
|
|
114
143
|
const _minjIsV2 = new Map();
|
|
115
|
-
let _minjMaxActive = 10,
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
144
|
+
let _minjMaxActive = 10,
|
|
145
|
+
_minjMaxPending = 25,
|
|
146
|
+
_minjIdleMs = 30 * 24 * 60 * 60 * 1000,
|
|
147
|
+
_minjStuckMs = 30 * 1000;
|
|
148
|
+
function _minjPos(n, label) {
|
|
149
|
+
const v = Math.floor(Number(n));
|
|
150
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
151
|
+
throw new Error(`${label} must be positive integer`);
|
|
152
|
+
return v;
|
|
153
|
+
}
|
|
154
|
+
function _minjCheckR(from, to) {
|
|
155
|
+
const a = _minjRTrans.get(from);
|
|
156
|
+
if (!a || !a.has(to))
|
|
157
|
+
throw new Error(`invalid minj rule transition ${from} → ${to}`);
|
|
158
|
+
}
|
|
159
|
+
function _minjCheckI(from, to) {
|
|
160
|
+
const a = _minjITrans.get(from);
|
|
161
|
+
if (!a || !a.has(to))
|
|
162
|
+
throw new Error(`invalid minj injection transition ${from} → ${to}`);
|
|
163
|
+
}
|
|
164
|
+
export function setMaxActiveMinjRulesPerOwnerV2(n) {
|
|
165
|
+
_minjMaxActive = _minjPos(n, "maxActiveMinjRulesPerOwner");
|
|
166
|
+
}
|
|
167
|
+
export function getMaxActiveMinjRulesPerOwnerV2() {
|
|
168
|
+
return _minjMaxActive;
|
|
169
|
+
}
|
|
170
|
+
export function setMaxPendingMinjInjectionsPerRuleV2(n) {
|
|
171
|
+
_minjMaxPending = _minjPos(n, "maxPendingMinjInjectionsPerRule");
|
|
172
|
+
}
|
|
173
|
+
export function getMaxPendingMinjInjectionsPerRuleV2() {
|
|
174
|
+
return _minjMaxPending;
|
|
175
|
+
}
|
|
176
|
+
export function setMinjRuleIdleMsV2(n) {
|
|
177
|
+
_minjIdleMs = _minjPos(n, "minjRuleIdleMs");
|
|
178
|
+
}
|
|
179
|
+
export function getMinjRuleIdleMsV2() {
|
|
180
|
+
return _minjIdleMs;
|
|
181
|
+
}
|
|
182
|
+
export function setMinjInjectionStuckMsV2(n) {
|
|
183
|
+
_minjStuckMs = _minjPos(n, "minjInjectionStuckMs");
|
|
184
|
+
}
|
|
185
|
+
export function getMinjInjectionStuckMsV2() {
|
|
186
|
+
return _minjStuckMs;
|
|
187
|
+
}
|
|
188
|
+
export function _resetStateMemoryInjectionV2() {
|
|
189
|
+
_minjRsV2.clear();
|
|
190
|
+
_minjIsV2.clear();
|
|
191
|
+
_minjMaxActive = 10;
|
|
192
|
+
_minjMaxPending = 25;
|
|
193
|
+
_minjIdleMs = 30 * 24 * 60 * 60 * 1000;
|
|
194
|
+
_minjStuckMs = 30 * 1000;
|
|
195
|
+
}
|
|
128
196
|
export function registerMinjRuleV2({ id, owner, scope, metadata } = {}) {
|
|
129
|
-
if (!id) throw new Error("minj rule id required");
|
|
197
|
+
if (!id) throw new Error("minj rule id required");
|
|
198
|
+
if (!owner) throw new Error("minj rule owner required");
|
|
130
199
|
if (_minjRsV2.has(id)) throw new Error(`minj rule ${id} already registered`);
|
|
131
200
|
const now = Date.now();
|
|
132
|
-
const r = {
|
|
133
|
-
|
|
201
|
+
const r = {
|
|
202
|
+
id,
|
|
203
|
+
owner,
|
|
204
|
+
scope: scope || "*",
|
|
205
|
+
status: MINJ_RULE_MATURITY_V2.PENDING,
|
|
206
|
+
createdAt: now,
|
|
207
|
+
updatedAt: now,
|
|
208
|
+
activatedAt: null,
|
|
209
|
+
archivedAt: null,
|
|
210
|
+
lastTouchedAt: now,
|
|
211
|
+
metadata: { ...(metadata || {}) },
|
|
212
|
+
};
|
|
213
|
+
_minjRsV2.set(id, r);
|
|
214
|
+
return { ...r, metadata: { ...r.metadata } };
|
|
215
|
+
}
|
|
216
|
+
function _minjCountActive(owner) {
|
|
217
|
+
let n = 0;
|
|
218
|
+
for (const r of _minjRsV2.values())
|
|
219
|
+
if (r.owner === owner && r.status === MINJ_RULE_MATURITY_V2.ACTIVE) n++;
|
|
220
|
+
return n;
|
|
134
221
|
}
|
|
135
|
-
function _minjCountActive(owner) { let n = 0; for (const r of _minjRsV2.values()) if (r.owner === owner && r.status === MINJ_RULE_MATURITY_V2.ACTIVE) n++; return n; }
|
|
136
222
|
export function activateMinjRuleV2(id) {
|
|
137
|
-
const r = _minjRsV2.get(id);
|
|
223
|
+
const r = _minjRsV2.get(id);
|
|
224
|
+
if (!r) throw new Error(`minj rule ${id} not found`);
|
|
138
225
|
_minjCheckR(r.status, MINJ_RULE_MATURITY_V2.ACTIVE);
|
|
139
226
|
const recovery = r.status === MINJ_RULE_MATURITY_V2.PAUSED;
|
|
140
|
-
if (!recovery && _minjCountActive(r.owner) >= _minjMaxActive)
|
|
141
|
-
|
|
227
|
+
if (!recovery && _minjCountActive(r.owner) >= _minjMaxActive)
|
|
228
|
+
throw new Error(`max active minj rules for owner ${r.owner} reached`);
|
|
229
|
+
const now = Date.now();
|
|
230
|
+
r.status = MINJ_RULE_MATURITY_V2.ACTIVE;
|
|
231
|
+
r.updatedAt = now;
|
|
232
|
+
r.lastTouchedAt = now;
|
|
233
|
+
if (!r.activatedAt) r.activatedAt = now;
|
|
234
|
+
return { ...r, metadata: { ...r.metadata } };
|
|
235
|
+
}
|
|
236
|
+
export function pauseMinjRuleV2(id) {
|
|
237
|
+
const r = _minjRsV2.get(id);
|
|
238
|
+
if (!r) throw new Error(`minj rule ${id} not found`);
|
|
239
|
+
_minjCheckR(r.status, MINJ_RULE_MATURITY_V2.PAUSED);
|
|
240
|
+
r.status = MINJ_RULE_MATURITY_V2.PAUSED;
|
|
241
|
+
r.updatedAt = Date.now();
|
|
242
|
+
return { ...r, metadata: { ...r.metadata } };
|
|
243
|
+
}
|
|
244
|
+
export function archiveMinjRuleV2(id) {
|
|
245
|
+
const r = _minjRsV2.get(id);
|
|
246
|
+
if (!r) throw new Error(`minj rule ${id} not found`);
|
|
247
|
+
_minjCheckR(r.status, MINJ_RULE_MATURITY_V2.ARCHIVED);
|
|
248
|
+
const now = Date.now();
|
|
249
|
+
r.status = MINJ_RULE_MATURITY_V2.ARCHIVED;
|
|
250
|
+
r.updatedAt = now;
|
|
251
|
+
if (!r.archivedAt) r.archivedAt = now;
|
|
252
|
+
return { ...r, metadata: { ...r.metadata } };
|
|
253
|
+
}
|
|
254
|
+
export function touchMinjRuleV2(id) {
|
|
255
|
+
const r = _minjRsV2.get(id);
|
|
256
|
+
if (!r) throw new Error(`minj rule ${id} not found`);
|
|
257
|
+
if (_minjRTerminal.has(r.status))
|
|
258
|
+
throw new Error(`cannot touch terminal minj rule ${id}`);
|
|
259
|
+
const now = Date.now();
|
|
260
|
+
r.lastTouchedAt = now;
|
|
261
|
+
r.updatedAt = now;
|
|
262
|
+
return { ...r, metadata: { ...r.metadata } };
|
|
263
|
+
}
|
|
264
|
+
export function getMinjRuleV2(id) {
|
|
265
|
+
const r = _minjRsV2.get(id);
|
|
266
|
+
if (!r) return null;
|
|
142
267
|
return { ...r, metadata: { ...r.metadata } };
|
|
143
268
|
}
|
|
144
|
-
export function
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
269
|
+
export function listMinjRulesV2() {
|
|
270
|
+
return [..._minjRsV2.values()].map((r) => ({
|
|
271
|
+
...r,
|
|
272
|
+
metadata: { ...r.metadata },
|
|
273
|
+
}));
|
|
274
|
+
}
|
|
275
|
+
function _minjCountPending(ruleId) {
|
|
276
|
+
let n = 0;
|
|
277
|
+
for (const i of _minjIsV2.values())
|
|
278
|
+
if (
|
|
279
|
+
i.ruleId === ruleId &&
|
|
280
|
+
(i.status === MINJ_INJECTION_LIFECYCLE_V2.QUEUED ||
|
|
281
|
+
i.status === MINJ_INJECTION_LIFECYCLE_V2.INJECTING)
|
|
282
|
+
)
|
|
283
|
+
n++;
|
|
284
|
+
return n;
|
|
285
|
+
}
|
|
150
286
|
export function createMinjInjectionV2({ id, ruleId, payload, metadata } = {}) {
|
|
151
|
-
if (!id) throw new Error("minj injection id required");
|
|
287
|
+
if (!id) throw new Error("minj injection id required");
|
|
288
|
+
if (!ruleId) throw new Error("minj injection ruleId required");
|
|
152
289
|
if (_minjIsV2.has(id)) throw new Error(`minj injection ${id} already exists`);
|
|
153
290
|
if (!_minjRsV2.has(ruleId)) throw new Error(`minj rule ${ruleId} not found`);
|
|
154
|
-
if (_minjCountPending(ruleId) >= _minjMaxPending)
|
|
291
|
+
if (_minjCountPending(ruleId) >= _minjMaxPending)
|
|
292
|
+
throw new Error(`max pending minj injections for rule ${ruleId} reached`);
|
|
155
293
|
const now = Date.now();
|
|
156
|
-
const i = {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
294
|
+
const i = {
|
|
295
|
+
id,
|
|
296
|
+
ruleId,
|
|
297
|
+
payload: payload || "",
|
|
298
|
+
status: MINJ_INJECTION_LIFECYCLE_V2.QUEUED,
|
|
299
|
+
createdAt: now,
|
|
300
|
+
updatedAt: now,
|
|
301
|
+
startedAt: null,
|
|
302
|
+
settledAt: null,
|
|
303
|
+
metadata: { ...(metadata || {}) },
|
|
304
|
+
};
|
|
305
|
+
_minjIsV2.set(id, i);
|
|
306
|
+
return { ...i, metadata: { ...i.metadata } };
|
|
307
|
+
}
|
|
308
|
+
export function injectingMinjInjectionV2(id) {
|
|
309
|
+
const i = _minjIsV2.get(id);
|
|
310
|
+
if (!i) throw new Error(`minj injection ${id} not found`);
|
|
311
|
+
_minjCheckI(i.status, MINJ_INJECTION_LIFECYCLE_V2.INJECTING);
|
|
312
|
+
const now = Date.now();
|
|
313
|
+
i.status = MINJ_INJECTION_LIFECYCLE_V2.INJECTING;
|
|
314
|
+
i.updatedAt = now;
|
|
315
|
+
if (!i.startedAt) i.startedAt = now;
|
|
316
|
+
return { ...i, metadata: { ...i.metadata } };
|
|
317
|
+
}
|
|
318
|
+
export function applyMinjInjectionV2(id) {
|
|
319
|
+
const i = _minjIsV2.get(id);
|
|
320
|
+
if (!i) throw new Error(`minj injection ${id} not found`);
|
|
321
|
+
_minjCheckI(i.status, MINJ_INJECTION_LIFECYCLE_V2.APPLIED);
|
|
322
|
+
const now = Date.now();
|
|
323
|
+
i.status = MINJ_INJECTION_LIFECYCLE_V2.APPLIED;
|
|
324
|
+
i.updatedAt = now;
|
|
325
|
+
if (!i.settledAt) i.settledAt = now;
|
|
326
|
+
return { ...i, metadata: { ...i.metadata } };
|
|
327
|
+
}
|
|
328
|
+
export function failMinjInjectionV2(id, reason) {
|
|
329
|
+
const i = _minjIsV2.get(id);
|
|
330
|
+
if (!i) throw new Error(`minj injection ${id} not found`);
|
|
331
|
+
_minjCheckI(i.status, MINJ_INJECTION_LIFECYCLE_V2.FAILED);
|
|
332
|
+
const now = Date.now();
|
|
333
|
+
i.status = MINJ_INJECTION_LIFECYCLE_V2.FAILED;
|
|
334
|
+
i.updatedAt = now;
|
|
335
|
+
if (!i.settledAt) i.settledAt = now;
|
|
336
|
+
if (reason) i.metadata.failReason = String(reason);
|
|
337
|
+
return { ...i, metadata: { ...i.metadata } };
|
|
338
|
+
}
|
|
339
|
+
export function cancelMinjInjectionV2(id, reason) {
|
|
340
|
+
const i = _minjIsV2.get(id);
|
|
341
|
+
if (!i) throw new Error(`minj injection ${id} not found`);
|
|
342
|
+
_minjCheckI(i.status, MINJ_INJECTION_LIFECYCLE_V2.CANCELLED);
|
|
343
|
+
const now = Date.now();
|
|
344
|
+
i.status = MINJ_INJECTION_LIFECYCLE_V2.CANCELLED;
|
|
345
|
+
i.updatedAt = now;
|
|
346
|
+
if (!i.settledAt) i.settledAt = now;
|
|
347
|
+
if (reason) i.metadata.cancelReason = String(reason);
|
|
348
|
+
return { ...i, metadata: { ...i.metadata } };
|
|
349
|
+
}
|
|
350
|
+
export function getMinjInjectionV2(id) {
|
|
351
|
+
const i = _minjIsV2.get(id);
|
|
352
|
+
if (!i) return null;
|
|
353
|
+
return { ...i, metadata: { ...i.metadata } };
|
|
354
|
+
}
|
|
355
|
+
export function listMinjInjectionsV2() {
|
|
356
|
+
return [..._minjIsV2.values()].map((i) => ({
|
|
357
|
+
...i,
|
|
358
|
+
metadata: { ...i.metadata },
|
|
359
|
+
}));
|
|
360
|
+
}
|
|
361
|
+
export function autoPauseIdleMinjRulesV2({ now } = {}) {
|
|
362
|
+
const t = now ?? Date.now();
|
|
363
|
+
const flipped = [];
|
|
364
|
+
for (const r of _minjRsV2.values())
|
|
365
|
+
if (
|
|
366
|
+
r.status === MINJ_RULE_MATURITY_V2.ACTIVE &&
|
|
367
|
+
t - r.lastTouchedAt >= _minjIdleMs
|
|
368
|
+
) {
|
|
369
|
+
r.status = MINJ_RULE_MATURITY_V2.PAUSED;
|
|
370
|
+
r.updatedAt = t;
|
|
371
|
+
flipped.push(r.id);
|
|
372
|
+
}
|
|
373
|
+
return { flipped, count: flipped.length };
|
|
374
|
+
}
|
|
375
|
+
export function autoFailStuckMinjInjectionsV2({ now } = {}) {
|
|
376
|
+
const t = now ?? Date.now();
|
|
377
|
+
const flipped = [];
|
|
378
|
+
for (const i of _minjIsV2.values())
|
|
379
|
+
if (
|
|
380
|
+
i.status === MINJ_INJECTION_LIFECYCLE_V2.INJECTING &&
|
|
381
|
+
i.startedAt != null &&
|
|
382
|
+
t - i.startedAt >= _minjStuckMs
|
|
383
|
+
) {
|
|
384
|
+
i.status = MINJ_INJECTION_LIFECYCLE_V2.FAILED;
|
|
385
|
+
i.updatedAt = t;
|
|
386
|
+
if (!i.settledAt) i.settledAt = t;
|
|
387
|
+
i.metadata.failReason = "auto-fail-stuck";
|
|
388
|
+
flipped.push(i.id);
|
|
389
|
+
}
|
|
390
|
+
return { flipped, count: flipped.length };
|
|
391
|
+
}
|
|
167
392
|
export function getMemoryInjectionGovStatsV2() {
|
|
168
|
-
const rulesByStatus = {};
|
|
169
|
-
|
|
170
|
-
|
|
393
|
+
const rulesByStatus = {};
|
|
394
|
+
for (const v of Object.values(MINJ_RULE_MATURITY_V2)) rulesByStatus[v] = 0;
|
|
395
|
+
for (const r of _minjRsV2.values()) rulesByStatus[r.status]++;
|
|
396
|
+
const injectionsByStatus = {};
|
|
397
|
+
for (const v of Object.values(MINJ_INJECTION_LIFECYCLE_V2))
|
|
398
|
+
injectionsByStatus[v] = 0;
|
|
399
|
+
for (const i of _minjIsV2.values()) injectionsByStatus[i.status]++;
|
|
400
|
+
return {
|
|
401
|
+
totalMinjRulesV2: _minjRsV2.size,
|
|
402
|
+
totalMinjInjectionsV2: _minjIsV2.size,
|
|
403
|
+
maxActiveMinjRulesPerOwner: _minjMaxActive,
|
|
404
|
+
maxPendingMinjInjectionsPerRule: _minjMaxPending,
|
|
405
|
+
minjRuleIdleMs: _minjIdleMs,
|
|
406
|
+
minjInjectionStuckMs: _minjStuckMs,
|
|
407
|
+
rulesByStatus,
|
|
408
|
+
injectionsByStatus,
|
|
409
|
+
};
|
|
171
410
|
}
|