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
|
@@ -238,25 +238,62 @@ export function createBackend(config = {}) {
|
|
|
238
238
|
}
|
|
239
239
|
}
|
|
240
240
|
|
|
241
|
-
|
|
242
241
|
// ===== V2 Surface: Execution Backend governance overlay (CLI v0.133.0) =====
|
|
243
242
|
export const EXECBE_BACKEND_MATURITY_V2 = Object.freeze({
|
|
244
|
-
PENDING: "pending",
|
|
243
|
+
PENDING: "pending",
|
|
244
|
+
ACTIVE: "active",
|
|
245
|
+
DEGRADED: "degraded",
|
|
246
|
+
RETIRED: "retired",
|
|
245
247
|
});
|
|
246
248
|
export const EXECBE_JOB_LIFECYCLE_V2 = Object.freeze({
|
|
247
|
-
QUEUED: "queued",
|
|
249
|
+
QUEUED: "queued",
|
|
250
|
+
RUNNING: "running",
|
|
251
|
+
SUCCEEDED: "succeeded",
|
|
252
|
+
FAILED: "failed",
|
|
253
|
+
CANCELLED: "cancelled",
|
|
248
254
|
});
|
|
249
255
|
|
|
250
256
|
const _ebBackendTrans = new Map([
|
|
251
|
-
[
|
|
252
|
-
|
|
253
|
-
|
|
257
|
+
[
|
|
258
|
+
EXECBE_BACKEND_MATURITY_V2.PENDING,
|
|
259
|
+
new Set([
|
|
260
|
+
EXECBE_BACKEND_MATURITY_V2.ACTIVE,
|
|
261
|
+
EXECBE_BACKEND_MATURITY_V2.RETIRED,
|
|
262
|
+
]),
|
|
263
|
+
],
|
|
264
|
+
[
|
|
265
|
+
EXECBE_BACKEND_MATURITY_V2.ACTIVE,
|
|
266
|
+
new Set([
|
|
267
|
+
EXECBE_BACKEND_MATURITY_V2.DEGRADED,
|
|
268
|
+
EXECBE_BACKEND_MATURITY_V2.RETIRED,
|
|
269
|
+
]),
|
|
270
|
+
],
|
|
271
|
+
[
|
|
272
|
+
EXECBE_BACKEND_MATURITY_V2.DEGRADED,
|
|
273
|
+
new Set([
|
|
274
|
+
EXECBE_BACKEND_MATURITY_V2.ACTIVE,
|
|
275
|
+
EXECBE_BACKEND_MATURITY_V2.RETIRED,
|
|
276
|
+
]),
|
|
277
|
+
],
|
|
254
278
|
[EXECBE_BACKEND_MATURITY_V2.RETIRED, new Set()],
|
|
255
279
|
]);
|
|
256
280
|
const _ebBackendTerminal = new Set([EXECBE_BACKEND_MATURITY_V2.RETIRED]);
|
|
257
281
|
const _ebJobTrans = new Map([
|
|
258
|
-
[
|
|
259
|
-
|
|
282
|
+
[
|
|
283
|
+
EXECBE_JOB_LIFECYCLE_V2.QUEUED,
|
|
284
|
+
new Set([
|
|
285
|
+
EXECBE_JOB_LIFECYCLE_V2.RUNNING,
|
|
286
|
+
EXECBE_JOB_LIFECYCLE_V2.CANCELLED,
|
|
287
|
+
]),
|
|
288
|
+
],
|
|
289
|
+
[
|
|
290
|
+
EXECBE_JOB_LIFECYCLE_V2.RUNNING,
|
|
291
|
+
new Set([
|
|
292
|
+
EXECBE_JOB_LIFECYCLE_V2.SUCCEEDED,
|
|
293
|
+
EXECBE_JOB_LIFECYCLE_V2.FAILED,
|
|
294
|
+
EXECBE_JOB_LIFECYCLE_V2.CANCELLED,
|
|
295
|
+
]),
|
|
296
|
+
],
|
|
260
297
|
[EXECBE_JOB_LIFECYCLE_V2.SUCCEEDED, new Set()],
|
|
261
298
|
[EXECBE_JOB_LIFECYCLE_V2.FAILED, new Set()],
|
|
262
299
|
[EXECBE_JOB_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
@@ -269,21 +306,45 @@ let _ebMaxPendingPerBackend = 20;
|
|
|
269
306
|
let _ebBackendIdleMs = 12 * 60 * 60 * 1000;
|
|
270
307
|
let _ebJobStuckMs = 10 * 60 * 1000;
|
|
271
308
|
|
|
272
|
-
function _ebPos(n, lbl) {
|
|
309
|
+
function _ebPos(n, lbl) {
|
|
310
|
+
const v = Math.floor(Number(n));
|
|
311
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
312
|
+
throw new Error(`${lbl} must be positive integer`);
|
|
313
|
+
return v;
|
|
314
|
+
}
|
|
273
315
|
|
|
274
|
-
export function setMaxActiveBackendsPerOwnerV2(n) {
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
export function
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
export function
|
|
281
|
-
|
|
316
|
+
export function setMaxActiveBackendsPerOwnerV2(n) {
|
|
317
|
+
_ebMaxActivePerOwner = _ebPos(n, "maxActiveBackendsPerOwner");
|
|
318
|
+
}
|
|
319
|
+
export function getMaxActiveBackendsPerOwnerV2() {
|
|
320
|
+
return _ebMaxActivePerOwner;
|
|
321
|
+
}
|
|
322
|
+
export function setMaxPendingJobsPerBackendV2(n) {
|
|
323
|
+
_ebMaxPendingPerBackend = _ebPos(n, "maxPendingJobsPerBackend");
|
|
324
|
+
}
|
|
325
|
+
export function getMaxPendingJobsPerBackendV2() {
|
|
326
|
+
return _ebMaxPendingPerBackend;
|
|
327
|
+
}
|
|
328
|
+
export function setBackendIdleMsV2(n) {
|
|
329
|
+
_ebBackendIdleMs = _ebPos(n, "backendIdleMs");
|
|
330
|
+
}
|
|
331
|
+
export function getBackendIdleMsV2() {
|
|
332
|
+
return _ebBackendIdleMs;
|
|
333
|
+
}
|
|
334
|
+
export function setExecJobStuckMsV2(n) {
|
|
335
|
+
_ebJobStuckMs = _ebPos(n, "execJobStuckMs");
|
|
336
|
+
}
|
|
337
|
+
export function getExecJobStuckMsV2() {
|
|
338
|
+
return _ebJobStuckMs;
|
|
339
|
+
}
|
|
282
340
|
|
|
283
341
|
export function _resetStateExecutionBackendV2() {
|
|
284
|
-
_ebBackends.clear();
|
|
285
|
-
|
|
286
|
-
|
|
342
|
+
_ebBackends.clear();
|
|
343
|
+
_ebJobs.clear();
|
|
344
|
+
_ebMaxActivePerOwner = 6;
|
|
345
|
+
_ebMaxPendingPerBackend = 20;
|
|
346
|
+
_ebBackendIdleMs = 12 * 60 * 60 * 1000;
|
|
347
|
+
_ebJobStuckMs = 10 * 60 * 1000;
|
|
287
348
|
}
|
|
288
349
|
|
|
289
350
|
export function registerBackendV2({ id, owner, kind, metadata } = {}) {
|
|
@@ -291,54 +352,239 @@ export function registerBackendV2({ id, owner, kind, metadata } = {}) {
|
|
|
291
352
|
if (!owner || typeof owner !== "string") throw new Error("owner is required");
|
|
292
353
|
if (_ebBackends.has(id)) throw new Error(`backend ${id} already registered`);
|
|
293
354
|
const now = Date.now();
|
|
294
|
-
const b = {
|
|
355
|
+
const b = {
|
|
356
|
+
id,
|
|
357
|
+
owner,
|
|
358
|
+
kind: kind || "local",
|
|
359
|
+
status: EXECBE_BACKEND_MATURITY_V2.PENDING,
|
|
360
|
+
createdAt: now,
|
|
361
|
+
updatedAt: now,
|
|
362
|
+
activatedAt: null,
|
|
363
|
+
retiredAt: null,
|
|
364
|
+
lastTouchedAt: now,
|
|
365
|
+
metadata: { ...(metadata || {}) },
|
|
366
|
+
};
|
|
295
367
|
_ebBackends.set(id, b);
|
|
296
368
|
return { ...b, metadata: { ...b.metadata } };
|
|
297
369
|
}
|
|
298
|
-
function _ebCheckB(from, to) {
|
|
299
|
-
|
|
370
|
+
function _ebCheckB(from, to) {
|
|
371
|
+
const allowed = _ebBackendTrans.get(from);
|
|
372
|
+
if (!allowed || !allowed.has(to))
|
|
373
|
+
throw new Error(`invalid backend transition ${from} → ${to}`);
|
|
374
|
+
}
|
|
375
|
+
function _ebCountActive(owner) {
|
|
376
|
+
let n = 0;
|
|
377
|
+
for (const b of _ebBackends.values())
|
|
378
|
+
if (b.owner === owner && b.status === EXECBE_BACKEND_MATURITY_V2.ACTIVE)
|
|
379
|
+
n++;
|
|
380
|
+
return n;
|
|
381
|
+
}
|
|
300
382
|
|
|
301
383
|
export function activateBackendV2(id) {
|
|
302
|
-
const b = _ebBackends.get(id);
|
|
384
|
+
const b = _ebBackends.get(id);
|
|
385
|
+
if (!b) throw new Error(`backend ${id} not found`);
|
|
303
386
|
_ebCheckB(b.status, EXECBE_BACKEND_MATURITY_V2.ACTIVE);
|
|
304
387
|
const recovery = b.status === EXECBE_BACKEND_MATURITY_V2.DEGRADED;
|
|
305
|
-
if (!recovery) {
|
|
306
|
-
|
|
388
|
+
if (!recovery) {
|
|
389
|
+
const a = _ebCountActive(b.owner);
|
|
390
|
+
if (a >= _ebMaxActivePerOwner)
|
|
391
|
+
throw new Error(
|
|
392
|
+
`max active backends per owner (${_ebMaxActivePerOwner}) reached for ${b.owner}`,
|
|
393
|
+
);
|
|
394
|
+
}
|
|
395
|
+
const now = Date.now();
|
|
396
|
+
b.status = EXECBE_BACKEND_MATURITY_V2.ACTIVE;
|
|
397
|
+
b.updatedAt = now;
|
|
398
|
+
b.lastTouchedAt = now;
|
|
399
|
+
if (!b.activatedAt) b.activatedAt = now;
|
|
400
|
+
return { ...b, metadata: { ...b.metadata } };
|
|
401
|
+
}
|
|
402
|
+
export function degradeBackendV2(id) {
|
|
403
|
+
const b = _ebBackends.get(id);
|
|
404
|
+
if (!b) throw new Error(`backend ${id} not found`);
|
|
405
|
+
_ebCheckB(b.status, EXECBE_BACKEND_MATURITY_V2.DEGRADED);
|
|
406
|
+
b.status = EXECBE_BACKEND_MATURITY_V2.DEGRADED;
|
|
407
|
+
b.updatedAt = Date.now();
|
|
408
|
+
return { ...b, metadata: { ...b.metadata } };
|
|
409
|
+
}
|
|
410
|
+
export function retireBackendV2(id) {
|
|
411
|
+
const b = _ebBackends.get(id);
|
|
412
|
+
if (!b) throw new Error(`backend ${id} not found`);
|
|
413
|
+
_ebCheckB(b.status, EXECBE_BACKEND_MATURITY_V2.RETIRED);
|
|
414
|
+
const now = Date.now();
|
|
415
|
+
b.status = EXECBE_BACKEND_MATURITY_V2.RETIRED;
|
|
416
|
+
b.updatedAt = now;
|
|
417
|
+
if (!b.retiredAt) b.retiredAt = now;
|
|
418
|
+
return { ...b, metadata: { ...b.metadata } };
|
|
419
|
+
}
|
|
420
|
+
export function touchBackendV2(id) {
|
|
421
|
+
const b = _ebBackends.get(id);
|
|
422
|
+
if (!b) throw new Error(`backend ${id} not found`);
|
|
423
|
+
if (_ebBackendTerminal.has(b.status))
|
|
424
|
+
throw new Error(`cannot touch terminal backend ${id}`);
|
|
425
|
+
const now = Date.now();
|
|
426
|
+
b.lastTouchedAt = now;
|
|
427
|
+
b.updatedAt = now;
|
|
428
|
+
return { ...b, metadata: { ...b.metadata } };
|
|
429
|
+
}
|
|
430
|
+
export function getBackendV2(id) {
|
|
431
|
+
const b = _ebBackends.get(id);
|
|
432
|
+
if (!b) return null;
|
|
307
433
|
return { ...b, metadata: { ...b.metadata } };
|
|
308
434
|
}
|
|
309
|
-
export function
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
435
|
+
export function listBackendsV2() {
|
|
436
|
+
return [..._ebBackends.values()].map((b) => ({
|
|
437
|
+
...b,
|
|
438
|
+
metadata: { ...b.metadata },
|
|
439
|
+
}));
|
|
440
|
+
}
|
|
314
441
|
|
|
315
|
-
function _ebCountPending(bid) {
|
|
442
|
+
function _ebCountPending(bid) {
|
|
443
|
+
let n = 0;
|
|
444
|
+
for (const j of _ebJobs.values())
|
|
445
|
+
if (
|
|
446
|
+
j.backendId === bid &&
|
|
447
|
+
(j.status === EXECBE_JOB_LIFECYCLE_V2.QUEUED ||
|
|
448
|
+
j.status === EXECBE_JOB_LIFECYCLE_V2.RUNNING)
|
|
449
|
+
)
|
|
450
|
+
n++;
|
|
451
|
+
return n;
|
|
452
|
+
}
|
|
316
453
|
|
|
317
454
|
export function createExecJobV2({ id, backendId, command, metadata } = {}) {
|
|
318
455
|
if (!id || typeof id !== "string") throw new Error("id is required");
|
|
319
|
-
if (!backendId || typeof backendId !== "string")
|
|
456
|
+
if (!backendId || typeof backendId !== "string")
|
|
457
|
+
throw new Error("backendId is required");
|
|
320
458
|
if (_ebJobs.has(id)) throw new Error(`exec job ${id} already exists`);
|
|
321
|
-
if (!_ebBackends.has(backendId))
|
|
459
|
+
if (!_ebBackends.has(backendId))
|
|
460
|
+
throw new Error(`backend ${backendId} not found`);
|
|
322
461
|
const pending = _ebCountPending(backendId);
|
|
323
|
-
if (pending >= _ebMaxPendingPerBackend)
|
|
462
|
+
if (pending >= _ebMaxPendingPerBackend)
|
|
463
|
+
throw new Error(
|
|
464
|
+
`max pending jobs per backend (${_ebMaxPendingPerBackend}) reached for ${backendId}`,
|
|
465
|
+
);
|
|
324
466
|
const now = Date.now();
|
|
325
|
-
const j = {
|
|
467
|
+
const j = {
|
|
468
|
+
id,
|
|
469
|
+
backendId,
|
|
470
|
+
command: command || "",
|
|
471
|
+
status: EXECBE_JOB_LIFECYCLE_V2.QUEUED,
|
|
472
|
+
createdAt: now,
|
|
473
|
+
updatedAt: now,
|
|
474
|
+
startedAt: null,
|
|
475
|
+
settledAt: null,
|
|
476
|
+
metadata: { ...(metadata || {}) },
|
|
477
|
+
};
|
|
326
478
|
_ebJobs.set(id, j);
|
|
327
479
|
return { ...j, metadata: { ...j.metadata } };
|
|
328
480
|
}
|
|
329
|
-
function _ebCheckJ(from, to) {
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
export function
|
|
335
|
-
|
|
481
|
+
function _ebCheckJ(from, to) {
|
|
482
|
+
const allowed = _ebJobTrans.get(from);
|
|
483
|
+
if (!allowed || !allowed.has(to))
|
|
484
|
+
throw new Error(`invalid exec job transition ${from} → ${to}`);
|
|
485
|
+
}
|
|
486
|
+
export function startExecJobV2(id) {
|
|
487
|
+
const j = _ebJobs.get(id);
|
|
488
|
+
if (!j) throw new Error(`exec job ${id} not found`);
|
|
489
|
+
_ebCheckJ(j.status, EXECBE_JOB_LIFECYCLE_V2.RUNNING);
|
|
490
|
+
const now = Date.now();
|
|
491
|
+
j.status = EXECBE_JOB_LIFECYCLE_V2.RUNNING;
|
|
492
|
+
j.updatedAt = now;
|
|
493
|
+
if (!j.startedAt) j.startedAt = now;
|
|
494
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
495
|
+
}
|
|
496
|
+
export function succeedExecJobV2(id) {
|
|
497
|
+
const j = _ebJobs.get(id);
|
|
498
|
+
if (!j) throw new Error(`exec job ${id} not found`);
|
|
499
|
+
_ebCheckJ(j.status, EXECBE_JOB_LIFECYCLE_V2.SUCCEEDED);
|
|
500
|
+
const now = Date.now();
|
|
501
|
+
j.status = EXECBE_JOB_LIFECYCLE_V2.SUCCEEDED;
|
|
502
|
+
j.updatedAt = now;
|
|
503
|
+
if (!j.settledAt) j.settledAt = now;
|
|
504
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
505
|
+
}
|
|
506
|
+
export function failExecJobV2(id, reason) {
|
|
507
|
+
const j = _ebJobs.get(id);
|
|
508
|
+
if (!j) throw new Error(`exec job ${id} not found`);
|
|
509
|
+
_ebCheckJ(j.status, EXECBE_JOB_LIFECYCLE_V2.FAILED);
|
|
510
|
+
const now = Date.now();
|
|
511
|
+
j.status = EXECBE_JOB_LIFECYCLE_V2.FAILED;
|
|
512
|
+
j.updatedAt = now;
|
|
513
|
+
if (!j.settledAt) j.settledAt = now;
|
|
514
|
+
if (reason) j.metadata.failReason = String(reason);
|
|
515
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
516
|
+
}
|
|
517
|
+
export function cancelExecJobV2(id, reason) {
|
|
518
|
+
const j = _ebJobs.get(id);
|
|
519
|
+
if (!j) throw new Error(`exec job ${id} not found`);
|
|
520
|
+
_ebCheckJ(j.status, EXECBE_JOB_LIFECYCLE_V2.CANCELLED);
|
|
521
|
+
const now = Date.now();
|
|
522
|
+
j.status = EXECBE_JOB_LIFECYCLE_V2.CANCELLED;
|
|
523
|
+
j.updatedAt = now;
|
|
524
|
+
if (!j.settledAt) j.settledAt = now;
|
|
525
|
+
if (reason) j.metadata.cancelReason = String(reason);
|
|
526
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
527
|
+
}
|
|
528
|
+
export function getExecJobV2(id) {
|
|
529
|
+
const j = _ebJobs.get(id);
|
|
530
|
+
if (!j) return null;
|
|
531
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
532
|
+
}
|
|
533
|
+
export function listExecJobsV2() {
|
|
534
|
+
return [..._ebJobs.values()].map((j) => ({
|
|
535
|
+
...j,
|
|
536
|
+
metadata: { ...j.metadata },
|
|
537
|
+
}));
|
|
538
|
+
}
|
|
336
539
|
|
|
337
|
-
export function autoDegradeIdleBackendsV2({ now } = {}) {
|
|
338
|
-
|
|
540
|
+
export function autoDegradeIdleBackendsV2({ now } = {}) {
|
|
541
|
+
const t = now ?? Date.now();
|
|
542
|
+
const flipped = [];
|
|
543
|
+
for (const b of _ebBackends.values())
|
|
544
|
+
if (
|
|
545
|
+
b.status === EXECBE_BACKEND_MATURITY_V2.ACTIVE &&
|
|
546
|
+
t - b.lastTouchedAt >= _ebBackendIdleMs
|
|
547
|
+
) {
|
|
548
|
+
b.status = EXECBE_BACKEND_MATURITY_V2.DEGRADED;
|
|
549
|
+
b.updatedAt = t;
|
|
550
|
+
flipped.push(b.id);
|
|
551
|
+
}
|
|
552
|
+
return { flipped, count: flipped.length };
|
|
553
|
+
}
|
|
554
|
+
export function autoFailStuckExecJobsV2({ now } = {}) {
|
|
555
|
+
const t = now ?? Date.now();
|
|
556
|
+
const flipped = [];
|
|
557
|
+
for (const j of _ebJobs.values())
|
|
558
|
+
if (
|
|
559
|
+
j.status === EXECBE_JOB_LIFECYCLE_V2.RUNNING &&
|
|
560
|
+
j.startedAt != null &&
|
|
561
|
+
t - j.startedAt >= _ebJobStuckMs
|
|
562
|
+
) {
|
|
563
|
+
j.status = EXECBE_JOB_LIFECYCLE_V2.FAILED;
|
|
564
|
+
j.updatedAt = t;
|
|
565
|
+
if (!j.settledAt) j.settledAt = t;
|
|
566
|
+
j.metadata.failReason = "auto-fail-stuck";
|
|
567
|
+
flipped.push(j.id);
|
|
568
|
+
}
|
|
569
|
+
return { flipped, count: flipped.length };
|
|
570
|
+
}
|
|
339
571
|
|
|
340
572
|
export function getExecutionBackendStatsV2() {
|
|
341
|
-
const backendsByStatus = {};
|
|
342
|
-
|
|
343
|
-
|
|
573
|
+
const backendsByStatus = {};
|
|
574
|
+
for (const s of Object.values(EXECBE_BACKEND_MATURITY_V2))
|
|
575
|
+
backendsByStatus[s] = 0;
|
|
576
|
+
for (const b of _ebBackends.values()) backendsByStatus[b.status]++;
|
|
577
|
+
const jobsByStatus = {};
|
|
578
|
+
for (const s of Object.values(EXECBE_JOB_LIFECYCLE_V2)) jobsByStatus[s] = 0;
|
|
579
|
+
for (const j of _ebJobs.values()) jobsByStatus[j.status]++;
|
|
580
|
+
return {
|
|
581
|
+
totalBackendsV2: _ebBackends.size,
|
|
582
|
+
totalJobsV2: _ebJobs.size,
|
|
583
|
+
maxActiveBackendsPerOwner: _ebMaxActivePerOwner,
|
|
584
|
+
maxPendingJobsPerBackend: _ebMaxPendingPerBackend,
|
|
585
|
+
backendIdleMs: _ebBackendIdleMs,
|
|
586
|
+
execJobStuckMs: _ebJobStuckMs,
|
|
587
|
+
backendsByStatus,
|
|
588
|
+
jobsByStatus,
|
|
589
|
+
};
|
|
344
590
|
}
|