chainlesschain 0.143.0 → 0.152.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 +364 -27
- package/src/commands/agent-network.js +217 -0
- package/src/commands/agent.js +587 -103
- package/src/commands/audit.js +206 -0
- package/src/commands/automation.js +201 -0
- package/src/commands/bi.js +355 -27
- package/src/commands/bm25.js +111 -27
- package/src/commands/browse.js +403 -29
- package/src/commands/ccron.js +128 -28
- package/src/commands/chat.js +207 -0
- package/src/commands/codegen.js +207 -0
- package/src/commands/collab.js +211 -0
- package/src/commands/compliance.js +824 -34
- package/src/commands/compt.js +127 -29
- package/src/commands/consol.js +8 -2
- package/src/commands/cowork.js +783 -34
- package/src/commands/crosschain.js +182 -28
- package/src/commands/dao.js +182 -28
- 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 +385 -27
- package/src/commands/economy.js +205 -50
- package/src/commands/evolution.js +203 -50
- package/src/commands/evomap.js +387 -27
- package/src/commands/export.js +213 -0
- package/src/commands/federation.js +209 -0
- package/src/commands/fflag.js +74 -22
- package/src/commands/fusion.js +205 -0
- package/src/commands/git.js +177 -37
- package/src/commands/governance.js +209 -0
- package/src/commands/hardening.js +209 -0
- package/src/commands/hmemory.js +204 -50
- package/src/commands/hook.js +209 -0
- package/src/commands/import.js +209 -0
- package/src/commands/incentive.js +209 -0
- package/src/commands/inference.js +170 -34
- package/src/commands/infra.js +203 -0
- package/src/commands/instinct.js +209 -0
- package/src/commands/ipfs.js +207 -0
- package/src/commands/itbudget.js +149 -33
- package/src/commands/kg.js +206 -0
- package/src/commands/llm.js +217 -0
- package/src/commands/lowcode.js +195 -38
- package/src/commands/marketplace.js +206 -0
- package/src/commands/matrix.js +386 -27
- package/src/commands/mcp.js +217 -0
- package/src/commands/mcpscaf.js +145 -33
- package/src/commands/meminj.js +145 -33
- package/src/commands/memory.js +209 -0
- package/src/commands/multimodal.js +203 -0
- package/src/commands/nlprog.js +225 -0
- package/src/commands/nostr.js +387 -27
- package/src/commands/note.js +205 -0
- package/src/commands/ops.js +219 -0
- package/src/commands/orchestrate.js +217 -0
- package/src/commands/orchgov.js +144 -33
- package/src/commands/org.js +209 -0
- package/src/commands/p2p.js +209 -0
- package/src/commands/pdfp.js +109 -27
- package/src/commands/perception.js +209 -0
- package/src/commands/perf.js +169 -32
- package/src/commands/perm.js +144 -33
- package/src/commands/permmem.js +203 -0
- package/src/commands/pipeline.js +207 -52
- package/src/commands/planmode.js +141 -32
- package/src/commands/plugin-ecosystem.js +209 -0
- package/src/commands/pqc.js +213 -0
- package/src/commands/privacy.js +203 -0
- package/src/commands/promcomp.js +111 -27
- package/src/commands/quantization.js +207 -0
- package/src/commands/rcache.js +205 -0
- package/src/commands/recommend.js +410 -34
- package/src/commands/reputation.js +208 -0
- package/src/commands/runtime.js +205 -0
- package/src/commands/sandbox.js +206 -0
- package/src/commands/scim.js +209 -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/session.js +209 -0
- package/src/commands/sganal.js +123 -29
- package/src/commands/siem.js +201 -34
- package/src/commands/skill.js +207 -0
- package/src/commands/sla.js +212 -0
- package/src/commands/slotfill.js +146 -33
- package/src/commands/social.js +358 -32
- package/src/commands/sso.js +209 -0
- package/src/commands/stress.js +206 -0
- package/src/commands/svccont.js +145 -33
- package/src/commands/sync.js +209 -0
- package/src/commands/tech.js +209 -0
- package/src/commands/tenant.js +217 -0
- package/src/commands/terraform.js +206 -0
- package/src/commands/tms.js +171 -33
- package/src/commands/tokens.js +209 -0
- package/src/commands/topiccls.js +146 -33
- package/src/commands/trust.js +217 -0
- package/src/commands/uprof.js +141 -32
- package/src/commands/vcheck.js +122 -28
- package/src/commands/wallet.js +209 -0
- package/src/commands/webfetch.js +141 -32
- package/src/commands/workflow.js +203 -0
- package/src/commands/zkp.js +184 -28
- package/src/index.js +180 -0
- package/src/lib/a2a-protocol.js +319 -51
- package/src/lib/activitypub-bridge.js +622 -50
- package/src/lib/agent-economy.js +304 -51
- package/src/lib/agent-network.js +341 -0
- package/src/lib/aiops.js +346 -0
- package/src/lib/app-builder.js +279 -46
- package/src/lib/audit-logger.js +321 -0
- package/src/lib/automation-engine.js +335 -0
- package/src/lib/autonomous-agent.js +284 -48
- package/src/lib/autonomous-developer.js +332 -0
- package/src/lib/bi-engine.js +616 -49
- package/src/lib/bm25-search.js +301 -49
- package/src/lib/browser-automation.js +630 -49
- package/src/lib/chat-core.js +336 -0
- package/src/lib/claude-code-bridge.js +341 -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-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-recommendation.js +351 -0
- 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-share.js +338 -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/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 +626 -49
- package/src/lib/evolution-system.js +278 -47
- package/src/lib/evomap-governance.js +334 -0
- 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/federation-hardening.js +340 -0
- 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/hook-manager.js +341 -0
- package/src/lib/inference-network.js +308 -51
- package/src/lib/instinct-manager.js +346 -0
- package/src/lib/ipfs-storage.js +334 -0
- package/src/lib/iteration-budget.js +302 -50
- package/src/lib/knowledge-exporter.js +341 -0
- package/src/lib/knowledge-graph.js +333 -0
- package/src/lib/knowledge-importer.js +341 -0
- package/src/lib/llm-providers.js +346 -0
- package/src/lib/matrix-bridge.js +620 -47
- package/src/lib/mcp-registry.js +346 -0
- package/src/lib/mcp-scaffold.js +318 -54
- package/src/lib/memory-injection.js +288 -49
- 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 +622 -49
- package/src/lib/note-versioning.js +339 -0
- package/src/lib/orchestrator.js +293 -48
- package/src/lib/org-manager.js +336 -0
- package/src/lib/p2p-manager.js +341 -0
- package/src/lib/pdf-parser.js +298 -49
- package/src/lib/perception.js +346 -0
- package/src/lib/perf-tuning.js +309 -50
- package/src/lib/permanent-memory.js +327 -0
- 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/plugin-ecosystem.js +346 -0
- package/src/lib/pqc-manager.js +346 -0
- package/src/lib/privacy-computing.js +335 -0
- package/src/lib/protocol-fusion.js +338 -0
- package/src/lib/quantization.js +337 -0
- package/src/lib/reputation-optimizer.js +340 -0
- package/src/lib/response-cache.js +333 -0
- package/src/lib/sandbox-v2.js +327 -0
- package/src/lib/scim-manager.js +346 -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-manager.js +334 -0
- 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-loader.js +334 -0
- 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/social-manager.js +330 -0
- package/src/lib/sso-manager.js +340 -0
- package/src/lib/stress-tester.js +342 -0
- package/src/lib/sub-agent-registry.js +302 -53
- package/src/lib/sync-manager.js +336 -0
- package/src/lib/task-model-selector.js +302 -50
- package/src/lib/tech-learning-engine.js +341 -0
- package/src/lib/tenant-saas.js +341 -0
- package/src/lib/terraform-manager.js +333 -0
- package/src/lib/threat-intel.js +330 -0
- package/src/lib/todo-manager.js +281 -47
- package/src/lib/token-incentive.js +341 -0
- package/src/lib/token-tracker.js +336 -0
- package/src/lib/topic-classifier.js +297 -49
- 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/user-profile.js +294 -50
- package/src/lib/version-checker.js +304 -50
- package/src/lib/wallet-manager.js +336 -0
- package/src/lib/web-fetch.js +292 -51
- package/src/lib/workflow-engine.js +330 -0
- package/src/lib/zkp-engine.js +286 -49
|
@@ -174,25 +174,59 @@ export const DEFAULT_ITERATION_BUDGET = DEFAULT_BUDGET;
|
|
|
174
174
|
export const BUDGET_WARNING_THRESHOLD = WARNING_THRESHOLD;
|
|
175
175
|
export const BUDGET_WRAPPING_UP_THRESHOLD = WRAPPING_UP_THRESHOLD;
|
|
176
176
|
|
|
177
|
-
|
|
178
177
|
// ===== V2 Surface: Iteration Budget governance overlay (CLI v0.140.0) =====
|
|
179
178
|
export const ITER_BUDGET_PROFILE_MATURITY_V2 = Object.freeze({
|
|
180
|
-
PENDING: "pending",
|
|
179
|
+
PENDING: "pending",
|
|
180
|
+
ACTIVE: "active",
|
|
181
|
+
PAUSED: "paused",
|
|
182
|
+
EXHAUSTED: "exhausted",
|
|
181
183
|
});
|
|
182
184
|
export const ITER_RUN_LIFECYCLE_V2 = Object.freeze({
|
|
183
|
-
QUEUED: "queued",
|
|
185
|
+
QUEUED: "queued",
|
|
186
|
+
RUNNING: "running",
|
|
187
|
+
COMPLETED: "completed",
|
|
188
|
+
FAILED: "failed",
|
|
189
|
+
CANCELLED: "cancelled",
|
|
184
190
|
});
|
|
185
191
|
|
|
186
192
|
const _ibpTrans = new Map([
|
|
187
|
-
[
|
|
188
|
-
|
|
189
|
-
|
|
193
|
+
[
|
|
194
|
+
ITER_BUDGET_PROFILE_MATURITY_V2.PENDING,
|
|
195
|
+
new Set([
|
|
196
|
+
ITER_BUDGET_PROFILE_MATURITY_V2.ACTIVE,
|
|
197
|
+
ITER_BUDGET_PROFILE_MATURITY_V2.EXHAUSTED,
|
|
198
|
+
]),
|
|
199
|
+
],
|
|
200
|
+
[
|
|
201
|
+
ITER_BUDGET_PROFILE_MATURITY_V2.ACTIVE,
|
|
202
|
+
new Set([
|
|
203
|
+
ITER_BUDGET_PROFILE_MATURITY_V2.PAUSED,
|
|
204
|
+
ITER_BUDGET_PROFILE_MATURITY_V2.EXHAUSTED,
|
|
205
|
+
]),
|
|
206
|
+
],
|
|
207
|
+
[
|
|
208
|
+
ITER_BUDGET_PROFILE_MATURITY_V2.PAUSED,
|
|
209
|
+
new Set([
|
|
210
|
+
ITER_BUDGET_PROFILE_MATURITY_V2.ACTIVE,
|
|
211
|
+
ITER_BUDGET_PROFILE_MATURITY_V2.EXHAUSTED,
|
|
212
|
+
]),
|
|
213
|
+
],
|
|
190
214
|
[ITER_BUDGET_PROFILE_MATURITY_V2.EXHAUSTED, new Set()],
|
|
191
215
|
]);
|
|
192
216
|
const _ibpTerminal = new Set([ITER_BUDGET_PROFILE_MATURITY_V2.EXHAUSTED]);
|
|
193
217
|
const _irTrans = new Map([
|
|
194
|
-
[
|
|
195
|
-
|
|
218
|
+
[
|
|
219
|
+
ITER_RUN_LIFECYCLE_V2.QUEUED,
|
|
220
|
+
new Set([ITER_RUN_LIFECYCLE_V2.RUNNING, ITER_RUN_LIFECYCLE_V2.CANCELLED]),
|
|
221
|
+
],
|
|
222
|
+
[
|
|
223
|
+
ITER_RUN_LIFECYCLE_V2.RUNNING,
|
|
224
|
+
new Set([
|
|
225
|
+
ITER_RUN_LIFECYCLE_V2.COMPLETED,
|
|
226
|
+
ITER_RUN_LIFECYCLE_V2.FAILED,
|
|
227
|
+
ITER_RUN_LIFECYCLE_V2.CANCELLED,
|
|
228
|
+
]),
|
|
229
|
+
],
|
|
196
230
|
[ITER_RUN_LIFECYCLE_V2.COMPLETED, new Set()],
|
|
197
231
|
[ITER_RUN_LIFECYCLE_V2.FAILED, new Set()],
|
|
198
232
|
[ITER_RUN_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
@@ -205,76 +239,294 @@ let _ibpMaxPendingRunsPerProfile = 8;
|
|
|
205
239
|
let _ibpIdleMs = 24 * 60 * 60 * 1000;
|
|
206
240
|
let _irStuckMs = 60 * 60 * 1000;
|
|
207
241
|
|
|
208
|
-
function _ibpPos(n, lbl) {
|
|
242
|
+
function _ibpPos(n, lbl) {
|
|
243
|
+
const v = Math.floor(Number(n));
|
|
244
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
245
|
+
throw new Error(`${lbl} must be positive integer`);
|
|
246
|
+
return v;
|
|
247
|
+
}
|
|
209
248
|
|
|
210
|
-
export function setMaxActiveIterBudgetProfilesPerOwnerV2(n) {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
export function
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
export function
|
|
217
|
-
|
|
249
|
+
export function setMaxActiveIterBudgetProfilesPerOwnerV2(n) {
|
|
250
|
+
_ibpMaxActivePerOwner = _ibpPos(n, "maxActiveIterBudgetProfilesPerOwner");
|
|
251
|
+
}
|
|
252
|
+
export function getMaxActiveIterBudgetProfilesPerOwnerV2() {
|
|
253
|
+
return _ibpMaxActivePerOwner;
|
|
254
|
+
}
|
|
255
|
+
export function setMaxPendingIterRunsPerProfileV2(n) {
|
|
256
|
+
_ibpMaxPendingRunsPerProfile = _ibpPos(n, "maxPendingIterRunsPerProfile");
|
|
257
|
+
}
|
|
258
|
+
export function getMaxPendingIterRunsPerProfileV2() {
|
|
259
|
+
return _ibpMaxPendingRunsPerProfile;
|
|
260
|
+
}
|
|
261
|
+
export function setIterBudgetProfileIdleMsV2(n) {
|
|
262
|
+
_ibpIdleMs = _ibpPos(n, "iterBudgetProfileIdleMs");
|
|
263
|
+
}
|
|
264
|
+
export function getIterBudgetProfileIdleMsV2() {
|
|
265
|
+
return _ibpIdleMs;
|
|
266
|
+
}
|
|
267
|
+
export function setIterRunStuckMsV2(n) {
|
|
268
|
+
_irStuckMs = _ibpPos(n, "iterRunStuckMs");
|
|
269
|
+
}
|
|
270
|
+
export function getIterRunStuckMsV2() {
|
|
271
|
+
return _irStuckMs;
|
|
272
|
+
}
|
|
218
273
|
|
|
219
274
|
export function _resetStateIterationBudgetV2() {
|
|
220
|
-
_ibpsV2.clear();
|
|
221
|
-
|
|
222
|
-
|
|
275
|
+
_ibpsV2.clear();
|
|
276
|
+
_irsV2.clear();
|
|
277
|
+
_ibpMaxActivePerOwner = 4;
|
|
278
|
+
_ibpMaxPendingRunsPerProfile = 8;
|
|
279
|
+
_ibpIdleMs = 24 * 60 * 60 * 1000;
|
|
280
|
+
_irStuckMs = 60 * 60 * 1000;
|
|
223
281
|
}
|
|
224
282
|
|
|
225
|
-
export function registerIterBudgetProfileV2({
|
|
283
|
+
export function registerIterBudgetProfileV2({
|
|
284
|
+
id,
|
|
285
|
+
owner,
|
|
286
|
+
budget,
|
|
287
|
+
metadata,
|
|
288
|
+
} = {}) {
|
|
226
289
|
if (!id || typeof id !== "string") throw new Error("id is required");
|
|
227
290
|
if (!owner || typeof owner !== "string") throw new Error("owner is required");
|
|
228
|
-
if (_ibpsV2.has(id))
|
|
291
|
+
if (_ibpsV2.has(id))
|
|
292
|
+
throw new Error(`iter budget profile ${id} already registered`);
|
|
229
293
|
const now = Date.now();
|
|
230
|
-
const p = {
|
|
294
|
+
const p = {
|
|
295
|
+
id,
|
|
296
|
+
owner,
|
|
297
|
+
budget: budget || 50,
|
|
298
|
+
status: ITER_BUDGET_PROFILE_MATURITY_V2.PENDING,
|
|
299
|
+
createdAt: now,
|
|
300
|
+
updatedAt: now,
|
|
301
|
+
activatedAt: null,
|
|
302
|
+
exhaustedAt: null,
|
|
303
|
+
lastTouchedAt: now,
|
|
304
|
+
metadata: { ...(metadata || {}) },
|
|
305
|
+
};
|
|
231
306
|
_ibpsV2.set(id, p);
|
|
232
307
|
return { ...p, metadata: { ...p.metadata } };
|
|
233
308
|
}
|
|
234
|
-
function _ibpCheckP(from, to) {
|
|
235
|
-
|
|
309
|
+
function _ibpCheckP(from, to) {
|
|
310
|
+
const a = _ibpTrans.get(from);
|
|
311
|
+
if (!a || !a.has(to))
|
|
312
|
+
throw new Error(`invalid iter budget profile transition ${from} → ${to}`);
|
|
313
|
+
}
|
|
314
|
+
function _ibpCountActive(owner) {
|
|
315
|
+
let n = 0;
|
|
316
|
+
for (const p of _ibpsV2.values())
|
|
317
|
+
if (
|
|
318
|
+
p.owner === owner &&
|
|
319
|
+
p.status === ITER_BUDGET_PROFILE_MATURITY_V2.ACTIVE
|
|
320
|
+
)
|
|
321
|
+
n++;
|
|
322
|
+
return n;
|
|
323
|
+
}
|
|
236
324
|
|
|
237
325
|
export function activateIterBudgetProfileV2(id) {
|
|
238
|
-
const p = _ibpsV2.get(id);
|
|
326
|
+
const p = _ibpsV2.get(id);
|
|
327
|
+
if (!p) throw new Error(`iter budget profile ${id} not found`);
|
|
239
328
|
_ibpCheckP(p.status, ITER_BUDGET_PROFILE_MATURITY_V2.ACTIVE);
|
|
240
329
|
const recovery = p.status === ITER_BUDGET_PROFILE_MATURITY_V2.PAUSED;
|
|
241
|
-
if (!recovery) {
|
|
242
|
-
|
|
330
|
+
if (!recovery) {
|
|
331
|
+
const c = _ibpCountActive(p.owner);
|
|
332
|
+
if (c >= _ibpMaxActivePerOwner)
|
|
333
|
+
throw new Error(
|
|
334
|
+
`max active iter budget profiles per owner (${_ibpMaxActivePerOwner}) reached for ${p.owner}`,
|
|
335
|
+
);
|
|
336
|
+
}
|
|
337
|
+
const now = Date.now();
|
|
338
|
+
p.status = ITER_BUDGET_PROFILE_MATURITY_V2.ACTIVE;
|
|
339
|
+
p.updatedAt = now;
|
|
340
|
+
p.lastTouchedAt = now;
|
|
341
|
+
if (!p.activatedAt) p.activatedAt = now;
|
|
342
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
343
|
+
}
|
|
344
|
+
export function pauseIterBudgetProfileV2(id) {
|
|
345
|
+
const p = _ibpsV2.get(id);
|
|
346
|
+
if (!p) throw new Error(`iter budget profile ${id} not found`);
|
|
347
|
+
_ibpCheckP(p.status, ITER_BUDGET_PROFILE_MATURITY_V2.PAUSED);
|
|
348
|
+
p.status = ITER_BUDGET_PROFILE_MATURITY_V2.PAUSED;
|
|
349
|
+
p.updatedAt = Date.now();
|
|
350
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
351
|
+
}
|
|
352
|
+
export function exhaustIterBudgetProfileV2(id) {
|
|
353
|
+
const p = _ibpsV2.get(id);
|
|
354
|
+
if (!p) throw new Error(`iter budget profile ${id} not found`);
|
|
355
|
+
_ibpCheckP(p.status, ITER_BUDGET_PROFILE_MATURITY_V2.EXHAUSTED);
|
|
356
|
+
const now = Date.now();
|
|
357
|
+
p.status = ITER_BUDGET_PROFILE_MATURITY_V2.EXHAUSTED;
|
|
358
|
+
p.updatedAt = now;
|
|
359
|
+
if (!p.exhaustedAt) p.exhaustedAt = now;
|
|
360
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
361
|
+
}
|
|
362
|
+
export function touchIterBudgetProfileV2(id) {
|
|
363
|
+
const p = _ibpsV2.get(id);
|
|
364
|
+
if (!p) throw new Error(`iter budget profile ${id} not found`);
|
|
365
|
+
if (_ibpTerminal.has(p.status))
|
|
366
|
+
throw new Error(`cannot touch terminal iter budget profile ${id}`);
|
|
367
|
+
const now = Date.now();
|
|
368
|
+
p.lastTouchedAt = now;
|
|
369
|
+
p.updatedAt = now;
|
|
370
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
371
|
+
}
|
|
372
|
+
export function getIterBudgetProfileV2(id) {
|
|
373
|
+
const p = _ibpsV2.get(id);
|
|
374
|
+
if (!p) return null;
|
|
243
375
|
return { ...p, metadata: { ...p.metadata } };
|
|
244
376
|
}
|
|
245
|
-
export function
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
377
|
+
export function listIterBudgetProfilesV2() {
|
|
378
|
+
return [..._ibpsV2.values()].map((p) => ({
|
|
379
|
+
...p,
|
|
380
|
+
metadata: { ...p.metadata },
|
|
381
|
+
}));
|
|
382
|
+
}
|
|
250
383
|
|
|
251
|
-
function _irCountPending(profileId) {
|
|
384
|
+
function _irCountPending(profileId) {
|
|
385
|
+
let n = 0;
|
|
386
|
+
for (const r of _irsV2.values())
|
|
387
|
+
if (
|
|
388
|
+
r.profileId === profileId &&
|
|
389
|
+
(r.status === ITER_RUN_LIFECYCLE_V2.QUEUED ||
|
|
390
|
+
r.status === ITER_RUN_LIFECYCLE_V2.RUNNING)
|
|
391
|
+
)
|
|
392
|
+
n++;
|
|
393
|
+
return n;
|
|
394
|
+
}
|
|
252
395
|
|
|
253
396
|
export function createIterRunV2({ id, profileId, goal, metadata } = {}) {
|
|
254
397
|
if (!id || typeof id !== "string") throw new Error("id is required");
|
|
255
|
-
if (!profileId || typeof profileId !== "string")
|
|
398
|
+
if (!profileId || typeof profileId !== "string")
|
|
399
|
+
throw new Error("profileId is required");
|
|
256
400
|
if (_irsV2.has(id)) throw new Error(`iter run ${id} already exists`);
|
|
257
|
-
if (!_ibpsV2.has(profileId))
|
|
401
|
+
if (!_ibpsV2.has(profileId))
|
|
402
|
+
throw new Error(`iter budget profile ${profileId} not found`);
|
|
258
403
|
const pending = _irCountPending(profileId);
|
|
259
|
-
if (pending >= _ibpMaxPendingRunsPerProfile)
|
|
404
|
+
if (pending >= _ibpMaxPendingRunsPerProfile)
|
|
405
|
+
throw new Error(
|
|
406
|
+
`max pending iter runs per profile (${_ibpMaxPendingRunsPerProfile}) reached for ${profileId}`,
|
|
407
|
+
);
|
|
260
408
|
const now = Date.now();
|
|
261
|
-
const r = {
|
|
409
|
+
const r = {
|
|
410
|
+
id,
|
|
411
|
+
profileId,
|
|
412
|
+
goal: goal || "",
|
|
413
|
+
status: ITER_RUN_LIFECYCLE_V2.QUEUED,
|
|
414
|
+
createdAt: now,
|
|
415
|
+
updatedAt: now,
|
|
416
|
+
startedAt: null,
|
|
417
|
+
settledAt: null,
|
|
418
|
+
metadata: { ...(metadata || {}) },
|
|
419
|
+
};
|
|
262
420
|
_irsV2.set(id, r);
|
|
263
421
|
return { ...r, metadata: { ...r.metadata } };
|
|
264
422
|
}
|
|
265
|
-
function _irCheckR(from, to) {
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
export function
|
|
271
|
-
|
|
423
|
+
function _irCheckR(from, to) {
|
|
424
|
+
const a = _irTrans.get(from);
|
|
425
|
+
if (!a || !a.has(to))
|
|
426
|
+
throw new Error(`invalid iter run transition ${from} → ${to}`);
|
|
427
|
+
}
|
|
428
|
+
export function startIterRunV2(id) {
|
|
429
|
+
const r = _irsV2.get(id);
|
|
430
|
+
if (!r) throw new Error(`iter run ${id} not found`);
|
|
431
|
+
_irCheckR(r.status, ITER_RUN_LIFECYCLE_V2.RUNNING);
|
|
432
|
+
const now = Date.now();
|
|
433
|
+
r.status = ITER_RUN_LIFECYCLE_V2.RUNNING;
|
|
434
|
+
r.updatedAt = now;
|
|
435
|
+
if (!r.startedAt) r.startedAt = now;
|
|
436
|
+
return { ...r, metadata: { ...r.metadata } };
|
|
437
|
+
}
|
|
438
|
+
export function completeIterRunV2(id) {
|
|
439
|
+
const r = _irsV2.get(id);
|
|
440
|
+
if (!r) throw new Error(`iter run ${id} not found`);
|
|
441
|
+
_irCheckR(r.status, ITER_RUN_LIFECYCLE_V2.COMPLETED);
|
|
442
|
+
const now = Date.now();
|
|
443
|
+
r.status = ITER_RUN_LIFECYCLE_V2.COMPLETED;
|
|
444
|
+
r.updatedAt = now;
|
|
445
|
+
if (!r.settledAt) r.settledAt = now;
|
|
446
|
+
return { ...r, metadata: { ...r.metadata } };
|
|
447
|
+
}
|
|
448
|
+
export function failIterRunV2(id, reason) {
|
|
449
|
+
const r = _irsV2.get(id);
|
|
450
|
+
if (!r) throw new Error(`iter run ${id} not found`);
|
|
451
|
+
_irCheckR(r.status, ITER_RUN_LIFECYCLE_V2.FAILED);
|
|
452
|
+
const now = Date.now();
|
|
453
|
+
r.status = ITER_RUN_LIFECYCLE_V2.FAILED;
|
|
454
|
+
r.updatedAt = now;
|
|
455
|
+
if (!r.settledAt) r.settledAt = now;
|
|
456
|
+
if (reason) r.metadata.failReason = String(reason);
|
|
457
|
+
return { ...r, metadata: { ...r.metadata } };
|
|
458
|
+
}
|
|
459
|
+
export function cancelIterRunV2(id, reason) {
|
|
460
|
+
const r = _irsV2.get(id);
|
|
461
|
+
if (!r) throw new Error(`iter run ${id} not found`);
|
|
462
|
+
_irCheckR(r.status, ITER_RUN_LIFECYCLE_V2.CANCELLED);
|
|
463
|
+
const now = Date.now();
|
|
464
|
+
r.status = ITER_RUN_LIFECYCLE_V2.CANCELLED;
|
|
465
|
+
r.updatedAt = now;
|
|
466
|
+
if (!r.settledAt) r.settledAt = now;
|
|
467
|
+
if (reason) r.metadata.cancelReason = String(reason);
|
|
468
|
+
return { ...r, metadata: { ...r.metadata } };
|
|
469
|
+
}
|
|
470
|
+
export function getIterRunV2(id) {
|
|
471
|
+
const r = _irsV2.get(id);
|
|
472
|
+
if (!r) return null;
|
|
473
|
+
return { ...r, metadata: { ...r.metadata } };
|
|
474
|
+
}
|
|
475
|
+
export function listIterRunsV2() {
|
|
476
|
+
return [..._irsV2.values()].map((r) => ({
|
|
477
|
+
...r,
|
|
478
|
+
metadata: { ...r.metadata },
|
|
479
|
+
}));
|
|
480
|
+
}
|
|
272
481
|
|
|
273
|
-
export function autoPauseIdleIterBudgetProfilesV2({ now } = {}) {
|
|
274
|
-
|
|
482
|
+
export function autoPauseIdleIterBudgetProfilesV2({ now } = {}) {
|
|
483
|
+
const t = now ?? Date.now();
|
|
484
|
+
const flipped = [];
|
|
485
|
+
for (const p of _ibpsV2.values())
|
|
486
|
+
if (
|
|
487
|
+
p.status === ITER_BUDGET_PROFILE_MATURITY_V2.ACTIVE &&
|
|
488
|
+
t - p.lastTouchedAt >= _ibpIdleMs
|
|
489
|
+
) {
|
|
490
|
+
p.status = ITER_BUDGET_PROFILE_MATURITY_V2.PAUSED;
|
|
491
|
+
p.updatedAt = t;
|
|
492
|
+
flipped.push(p.id);
|
|
493
|
+
}
|
|
494
|
+
return { flipped, count: flipped.length };
|
|
495
|
+
}
|
|
496
|
+
export function autoFailStuckIterRunsV2({ now } = {}) {
|
|
497
|
+
const t = now ?? Date.now();
|
|
498
|
+
const flipped = [];
|
|
499
|
+
for (const r of _irsV2.values())
|
|
500
|
+
if (
|
|
501
|
+
r.status === ITER_RUN_LIFECYCLE_V2.RUNNING &&
|
|
502
|
+
r.startedAt != null &&
|
|
503
|
+
t - r.startedAt >= _irStuckMs
|
|
504
|
+
) {
|
|
505
|
+
r.status = ITER_RUN_LIFECYCLE_V2.FAILED;
|
|
506
|
+
r.updatedAt = t;
|
|
507
|
+
if (!r.settledAt) r.settledAt = t;
|
|
508
|
+
r.metadata.failReason = "auto-fail-stuck";
|
|
509
|
+
flipped.push(r.id);
|
|
510
|
+
}
|
|
511
|
+
return { flipped, count: flipped.length };
|
|
512
|
+
}
|
|
275
513
|
|
|
276
514
|
export function getIterationBudgetGovStatsV2() {
|
|
277
|
-
const profilesByStatus = {};
|
|
278
|
-
|
|
279
|
-
|
|
515
|
+
const profilesByStatus = {};
|
|
516
|
+
for (const s of Object.values(ITER_BUDGET_PROFILE_MATURITY_V2))
|
|
517
|
+
profilesByStatus[s] = 0;
|
|
518
|
+
for (const p of _ibpsV2.values()) profilesByStatus[p.status]++;
|
|
519
|
+
const runsByStatus = {};
|
|
520
|
+
for (const s of Object.values(ITER_RUN_LIFECYCLE_V2)) runsByStatus[s] = 0;
|
|
521
|
+
for (const r of _irsV2.values()) runsByStatus[r.status]++;
|
|
522
|
+
return {
|
|
523
|
+
totalIterBudgetProfilesV2: _ibpsV2.size,
|
|
524
|
+
totalIterRunsV2: _irsV2.size,
|
|
525
|
+
maxActiveIterBudgetProfilesPerOwner: _ibpMaxActivePerOwner,
|
|
526
|
+
maxPendingIterRunsPerProfile: _ibpMaxPendingRunsPerProfile,
|
|
527
|
+
iterBudgetProfileIdleMs: _ibpIdleMs,
|
|
528
|
+
iterRunStuckMs: _irStuckMs,
|
|
529
|
+
profilesByStatus,
|
|
530
|
+
runsByStatus,
|
|
531
|
+
};
|
|
280
532
|
}
|