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
|
@@ -219,25 +219,62 @@ export class SubAgentRegistry {
|
|
|
219
219
|
}
|
|
220
220
|
}
|
|
221
221
|
|
|
222
|
-
|
|
223
222
|
// ===== V2 Surface: Sub-Agent Registry governance overlay (CLI v0.133.0) =====
|
|
224
223
|
export const SUBAGENT_PROFILE_MATURITY_V2 = Object.freeze({
|
|
225
|
-
PENDING: "pending",
|
|
224
|
+
PENDING: "pending",
|
|
225
|
+
ACTIVE: "active",
|
|
226
|
+
PAUSED: "paused",
|
|
227
|
+
RETIRED: "retired",
|
|
226
228
|
});
|
|
227
229
|
export const SUBAGENT_TASK_LIFECYCLE_V2 = Object.freeze({
|
|
228
|
-
QUEUED: "queued",
|
|
230
|
+
QUEUED: "queued",
|
|
231
|
+
RUNNING: "running",
|
|
232
|
+
COMPLETED: "completed",
|
|
233
|
+
FAILED: "failed",
|
|
234
|
+
CANCELLED: "cancelled",
|
|
229
235
|
});
|
|
230
236
|
|
|
231
237
|
const _saProfileTrans = new Map([
|
|
232
|
-
[
|
|
233
|
-
|
|
234
|
-
|
|
238
|
+
[
|
|
239
|
+
SUBAGENT_PROFILE_MATURITY_V2.PENDING,
|
|
240
|
+
new Set([
|
|
241
|
+
SUBAGENT_PROFILE_MATURITY_V2.ACTIVE,
|
|
242
|
+
SUBAGENT_PROFILE_MATURITY_V2.RETIRED,
|
|
243
|
+
]),
|
|
244
|
+
],
|
|
245
|
+
[
|
|
246
|
+
SUBAGENT_PROFILE_MATURITY_V2.ACTIVE,
|
|
247
|
+
new Set([
|
|
248
|
+
SUBAGENT_PROFILE_MATURITY_V2.PAUSED,
|
|
249
|
+
SUBAGENT_PROFILE_MATURITY_V2.RETIRED,
|
|
250
|
+
]),
|
|
251
|
+
],
|
|
252
|
+
[
|
|
253
|
+
SUBAGENT_PROFILE_MATURITY_V2.PAUSED,
|
|
254
|
+
new Set([
|
|
255
|
+
SUBAGENT_PROFILE_MATURITY_V2.ACTIVE,
|
|
256
|
+
SUBAGENT_PROFILE_MATURITY_V2.RETIRED,
|
|
257
|
+
]),
|
|
258
|
+
],
|
|
235
259
|
[SUBAGENT_PROFILE_MATURITY_V2.RETIRED, new Set()],
|
|
236
260
|
]);
|
|
237
261
|
const _saProfileTerminal = new Set([SUBAGENT_PROFILE_MATURITY_V2.RETIRED]);
|
|
238
262
|
const _saTaskTrans = new Map([
|
|
239
|
-
[
|
|
240
|
-
|
|
263
|
+
[
|
|
264
|
+
SUBAGENT_TASK_LIFECYCLE_V2.QUEUED,
|
|
265
|
+
new Set([
|
|
266
|
+
SUBAGENT_TASK_LIFECYCLE_V2.RUNNING,
|
|
267
|
+
SUBAGENT_TASK_LIFECYCLE_V2.CANCELLED,
|
|
268
|
+
]),
|
|
269
|
+
],
|
|
270
|
+
[
|
|
271
|
+
SUBAGENT_TASK_LIFECYCLE_V2.RUNNING,
|
|
272
|
+
new Set([
|
|
273
|
+
SUBAGENT_TASK_LIFECYCLE_V2.COMPLETED,
|
|
274
|
+
SUBAGENT_TASK_LIFECYCLE_V2.FAILED,
|
|
275
|
+
SUBAGENT_TASK_LIFECYCLE_V2.CANCELLED,
|
|
276
|
+
]),
|
|
277
|
+
],
|
|
241
278
|
[SUBAGENT_TASK_LIFECYCLE_V2.COMPLETED, new Set()],
|
|
242
279
|
[SUBAGENT_TASK_LIFECYCLE_V2.FAILED, new Set()],
|
|
243
280
|
[SUBAGENT_TASK_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
@@ -250,81 +287,293 @@ let _saMaxPendingPerProfile = 24;
|
|
|
250
287
|
let _saProfileIdleMs = 2 * 60 * 60 * 1000;
|
|
251
288
|
let _saTaskStuckMs = 5 * 60 * 1000;
|
|
252
289
|
|
|
253
|
-
function _saPos(n, lbl) {
|
|
290
|
+
function _saPos(n, lbl) {
|
|
291
|
+
const v = Math.floor(Number(n));
|
|
292
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
293
|
+
throw new Error(`${lbl} must be positive integer`);
|
|
294
|
+
return v;
|
|
295
|
+
}
|
|
254
296
|
|
|
255
|
-
export function setMaxActiveSubagentsPerOwnerV2(n) {
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
export function
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
export function
|
|
262
|
-
|
|
297
|
+
export function setMaxActiveSubagentsPerOwnerV2(n) {
|
|
298
|
+
_saMaxActivePerOwner = _saPos(n, "maxActiveSubagentsPerOwner");
|
|
299
|
+
}
|
|
300
|
+
export function getMaxActiveSubagentsPerOwnerV2() {
|
|
301
|
+
return _saMaxActivePerOwner;
|
|
302
|
+
}
|
|
303
|
+
export function setMaxPendingTasksPerSubagentV2(n) {
|
|
304
|
+
_saMaxPendingPerProfile = _saPos(n, "maxPendingTasksPerSubagent");
|
|
305
|
+
}
|
|
306
|
+
export function getMaxPendingTasksPerSubagentV2() {
|
|
307
|
+
return _saMaxPendingPerProfile;
|
|
308
|
+
}
|
|
309
|
+
export function setSubagentIdleMsV2(n) {
|
|
310
|
+
_saProfileIdleMs = _saPos(n, "subagentIdleMs");
|
|
311
|
+
}
|
|
312
|
+
export function getSubagentIdleMsV2() {
|
|
313
|
+
return _saProfileIdleMs;
|
|
314
|
+
}
|
|
315
|
+
export function setSubagentTaskStuckMsV2(n) {
|
|
316
|
+
_saTaskStuckMs = _saPos(n, "subagentTaskStuckMs");
|
|
317
|
+
}
|
|
318
|
+
export function getSubagentTaskStuckMsV2() {
|
|
319
|
+
return _saTaskStuckMs;
|
|
320
|
+
}
|
|
263
321
|
|
|
264
322
|
export function _resetStateSubAgentRegistryV2() {
|
|
265
|
-
_saProfiles.clear();
|
|
266
|
-
|
|
267
|
-
|
|
323
|
+
_saProfiles.clear();
|
|
324
|
+
_saTasks.clear();
|
|
325
|
+
_saMaxActivePerOwner = 12;
|
|
326
|
+
_saMaxPendingPerProfile = 24;
|
|
327
|
+
_saProfileIdleMs = 2 * 60 * 60 * 1000;
|
|
328
|
+
_saTaskStuckMs = 5 * 60 * 1000;
|
|
268
329
|
}
|
|
269
330
|
|
|
270
331
|
export function registerSubagentProfileV2({ id, owner, role, metadata } = {}) {
|
|
271
332
|
if (!id || typeof id !== "string") throw new Error("id is required");
|
|
272
333
|
if (!owner || typeof owner !== "string") throw new Error("owner is required");
|
|
273
|
-
if (_saProfiles.has(id))
|
|
334
|
+
if (_saProfiles.has(id))
|
|
335
|
+
throw new Error(`subagent profile ${id} already registered`);
|
|
274
336
|
const now = Date.now();
|
|
275
|
-
const p = {
|
|
276
|
-
|
|
277
|
-
|
|
337
|
+
const p = {
|
|
338
|
+
id,
|
|
339
|
+
owner,
|
|
340
|
+
role: role || "generic",
|
|
341
|
+
status: SUBAGENT_PROFILE_MATURITY_V2.PENDING,
|
|
342
|
+
createdAt: now,
|
|
343
|
+
updatedAt: now,
|
|
344
|
+
activatedAt: null,
|
|
345
|
+
retiredAt: null,
|
|
346
|
+
lastTouchedAt: now,
|
|
347
|
+
metadata: { ...(metadata || {}) },
|
|
348
|
+
};
|
|
278
349
|
_saProfiles.set(id, p);
|
|
279
350
|
return { ...p, metadata: { ...p.metadata } };
|
|
280
351
|
}
|
|
281
352
|
|
|
282
|
-
function _saCheckP(from, to) {
|
|
283
|
-
|
|
353
|
+
function _saCheckP(from, to) {
|
|
354
|
+
const allowed = _saProfileTrans.get(from);
|
|
355
|
+
if (!allowed || !allowed.has(to))
|
|
356
|
+
throw new Error(`invalid subagent profile transition ${from} → ${to}`);
|
|
357
|
+
}
|
|
358
|
+
function _saCountActiveByOwner(owner) {
|
|
359
|
+
let n = 0;
|
|
360
|
+
for (const p of _saProfiles.values())
|
|
361
|
+
if (p.owner === owner && p.status === SUBAGENT_PROFILE_MATURITY_V2.ACTIVE)
|
|
362
|
+
n++;
|
|
363
|
+
return n;
|
|
364
|
+
}
|
|
284
365
|
|
|
285
366
|
export function activateSubagentProfileV2(id) {
|
|
286
|
-
const p = _saProfiles.get(id);
|
|
367
|
+
const p = _saProfiles.get(id);
|
|
368
|
+
if (!p) throw new Error(`subagent profile ${id} not found`);
|
|
287
369
|
_saCheckP(p.status, SUBAGENT_PROFILE_MATURITY_V2.ACTIVE);
|
|
288
370
|
const recovery = p.status === SUBAGENT_PROFILE_MATURITY_V2.PAUSED;
|
|
289
|
-
if (!recovery) {
|
|
290
|
-
|
|
371
|
+
if (!recovery) {
|
|
372
|
+
const a = _saCountActiveByOwner(p.owner);
|
|
373
|
+
if (a >= _saMaxActivePerOwner)
|
|
374
|
+
throw new Error(
|
|
375
|
+
`max active subagents per owner (${_saMaxActivePerOwner}) reached for ${p.owner}`,
|
|
376
|
+
);
|
|
377
|
+
}
|
|
378
|
+
const now = Date.now();
|
|
379
|
+
p.status = SUBAGENT_PROFILE_MATURITY_V2.ACTIVE;
|
|
380
|
+
p.updatedAt = now;
|
|
381
|
+
p.lastTouchedAt = now;
|
|
291
382
|
if (!p.activatedAt) p.activatedAt = now;
|
|
292
383
|
return { ...p, metadata: { ...p.metadata } };
|
|
293
384
|
}
|
|
294
|
-
export function pauseSubagentProfileV2(id) {
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
385
|
+
export function pauseSubagentProfileV2(id) {
|
|
386
|
+
const p = _saProfiles.get(id);
|
|
387
|
+
if (!p) throw new Error(`subagent profile ${id} not found`);
|
|
388
|
+
_saCheckP(p.status, SUBAGENT_PROFILE_MATURITY_V2.PAUSED);
|
|
389
|
+
p.status = SUBAGENT_PROFILE_MATURITY_V2.PAUSED;
|
|
390
|
+
p.updatedAt = Date.now();
|
|
391
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
392
|
+
}
|
|
393
|
+
export function retireSubagentProfileV2(id) {
|
|
394
|
+
const p = _saProfiles.get(id);
|
|
395
|
+
if (!p) throw new Error(`subagent profile ${id} not found`);
|
|
396
|
+
_saCheckP(p.status, SUBAGENT_PROFILE_MATURITY_V2.RETIRED);
|
|
397
|
+
const now = Date.now();
|
|
398
|
+
p.status = SUBAGENT_PROFILE_MATURITY_V2.RETIRED;
|
|
399
|
+
p.updatedAt = now;
|
|
400
|
+
if (!p.retiredAt) p.retiredAt = now;
|
|
401
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
402
|
+
}
|
|
403
|
+
export function touchSubagentProfileV2(id) {
|
|
404
|
+
const p = _saProfiles.get(id);
|
|
405
|
+
if (!p) throw new Error(`subagent profile ${id} not found`);
|
|
406
|
+
if (_saProfileTerminal.has(p.status))
|
|
407
|
+
throw new Error(`cannot touch terminal subagent profile ${id}`);
|
|
408
|
+
const now = Date.now();
|
|
409
|
+
p.lastTouchedAt = now;
|
|
410
|
+
p.updatedAt = now;
|
|
411
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
412
|
+
}
|
|
413
|
+
export function getSubagentProfileV2(id) {
|
|
414
|
+
const p = _saProfiles.get(id);
|
|
415
|
+
if (!p) return null;
|
|
416
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
417
|
+
}
|
|
418
|
+
export function listSubagentProfilesV2() {
|
|
419
|
+
return [..._saProfiles.values()].map((p) => ({
|
|
420
|
+
...p,
|
|
421
|
+
metadata: { ...p.metadata },
|
|
422
|
+
}));
|
|
423
|
+
}
|
|
299
424
|
|
|
300
|
-
function _saCountPendingByProfile(pid) {
|
|
425
|
+
function _saCountPendingByProfile(pid) {
|
|
426
|
+
let n = 0;
|
|
427
|
+
for (const t of _saTasks.values())
|
|
428
|
+
if (
|
|
429
|
+
t.profileId === pid &&
|
|
430
|
+
(t.status === SUBAGENT_TASK_LIFECYCLE_V2.QUEUED ||
|
|
431
|
+
t.status === SUBAGENT_TASK_LIFECYCLE_V2.RUNNING)
|
|
432
|
+
)
|
|
433
|
+
n++;
|
|
434
|
+
return n;
|
|
435
|
+
}
|
|
301
436
|
|
|
302
|
-
export function createSubagentTaskV2({
|
|
437
|
+
export function createSubagentTaskV2({
|
|
438
|
+
id,
|
|
439
|
+
profileId,
|
|
440
|
+
description,
|
|
441
|
+
metadata,
|
|
442
|
+
} = {}) {
|
|
303
443
|
if (!id || typeof id !== "string") throw new Error("id is required");
|
|
304
|
-
if (!profileId || typeof profileId !== "string")
|
|
444
|
+
if (!profileId || typeof profileId !== "string")
|
|
445
|
+
throw new Error("profileId is required");
|
|
305
446
|
if (_saTasks.has(id)) throw new Error(`subagent task ${id} already exists`);
|
|
306
|
-
if (!_saProfiles.has(profileId))
|
|
447
|
+
if (!_saProfiles.has(profileId))
|
|
448
|
+
throw new Error(`subagent profile ${profileId} not found`);
|
|
307
449
|
const pending = _saCountPendingByProfile(profileId);
|
|
308
|
-
if (pending >= _saMaxPendingPerProfile)
|
|
450
|
+
if (pending >= _saMaxPendingPerProfile)
|
|
451
|
+
throw new Error(
|
|
452
|
+
`max pending tasks per subagent (${_saMaxPendingPerProfile}) reached for ${profileId}`,
|
|
453
|
+
);
|
|
309
454
|
const now = Date.now();
|
|
310
|
-
const t = {
|
|
311
|
-
|
|
455
|
+
const t = {
|
|
456
|
+
id,
|
|
457
|
+
profileId,
|
|
458
|
+
description: description || "",
|
|
459
|
+
status: SUBAGENT_TASK_LIFECYCLE_V2.QUEUED,
|
|
460
|
+
createdAt: now,
|
|
461
|
+
updatedAt: now,
|
|
462
|
+
startedAt: null,
|
|
463
|
+
settledAt: null,
|
|
464
|
+
metadata: { ...(metadata || {}) },
|
|
465
|
+
};
|
|
312
466
|
_saTasks.set(id, t);
|
|
313
467
|
return { ...t, metadata: { ...t.metadata } };
|
|
314
468
|
}
|
|
315
|
-
function _saCheckT(from, to) {
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
export function
|
|
321
|
-
|
|
469
|
+
function _saCheckT(from, to) {
|
|
470
|
+
const allowed = _saTaskTrans.get(from);
|
|
471
|
+
if (!allowed || !allowed.has(to))
|
|
472
|
+
throw new Error(`invalid subagent task transition ${from} → ${to}`);
|
|
473
|
+
}
|
|
474
|
+
export function startSubagentTaskV2(id) {
|
|
475
|
+
const t = _saTasks.get(id);
|
|
476
|
+
if (!t) throw new Error(`subagent task ${id} not found`);
|
|
477
|
+
_saCheckT(t.status, SUBAGENT_TASK_LIFECYCLE_V2.RUNNING);
|
|
478
|
+
const now = Date.now();
|
|
479
|
+
t.status = SUBAGENT_TASK_LIFECYCLE_V2.RUNNING;
|
|
480
|
+
t.updatedAt = now;
|
|
481
|
+
if (!t.startedAt) t.startedAt = now;
|
|
482
|
+
return { ...t, metadata: { ...t.metadata } };
|
|
483
|
+
}
|
|
484
|
+
export function completeSubagentTaskV2(id) {
|
|
485
|
+
const t = _saTasks.get(id);
|
|
486
|
+
if (!t) throw new Error(`subagent task ${id} not found`);
|
|
487
|
+
_saCheckT(t.status, SUBAGENT_TASK_LIFECYCLE_V2.COMPLETED);
|
|
488
|
+
const now = Date.now();
|
|
489
|
+
t.status = SUBAGENT_TASK_LIFECYCLE_V2.COMPLETED;
|
|
490
|
+
t.updatedAt = now;
|
|
491
|
+
if (!t.settledAt) t.settledAt = now;
|
|
492
|
+
return { ...t, metadata: { ...t.metadata } };
|
|
493
|
+
}
|
|
494
|
+
export function failSubagentTaskV2(id, reason) {
|
|
495
|
+
const t = _saTasks.get(id);
|
|
496
|
+
if (!t) throw new Error(`subagent task ${id} not found`);
|
|
497
|
+
_saCheckT(t.status, SUBAGENT_TASK_LIFECYCLE_V2.FAILED);
|
|
498
|
+
const now = Date.now();
|
|
499
|
+
t.status = SUBAGENT_TASK_LIFECYCLE_V2.FAILED;
|
|
500
|
+
t.updatedAt = now;
|
|
501
|
+
if (!t.settledAt) t.settledAt = now;
|
|
502
|
+
if (reason) t.metadata.failReason = String(reason);
|
|
503
|
+
return { ...t, metadata: { ...t.metadata } };
|
|
504
|
+
}
|
|
505
|
+
export function cancelSubagentTaskV2(id, reason) {
|
|
506
|
+
const t = _saTasks.get(id);
|
|
507
|
+
if (!t) throw new Error(`subagent task ${id} not found`);
|
|
508
|
+
_saCheckT(t.status, SUBAGENT_TASK_LIFECYCLE_V2.CANCELLED);
|
|
509
|
+
const now = Date.now();
|
|
510
|
+
t.status = SUBAGENT_TASK_LIFECYCLE_V2.CANCELLED;
|
|
511
|
+
t.updatedAt = now;
|
|
512
|
+
if (!t.settledAt) t.settledAt = now;
|
|
513
|
+
if (reason) t.metadata.cancelReason = String(reason);
|
|
514
|
+
return { ...t, metadata: { ...t.metadata } };
|
|
515
|
+
}
|
|
516
|
+
export function getSubagentTaskV2(id) {
|
|
517
|
+
const t = _saTasks.get(id);
|
|
518
|
+
if (!t) return null;
|
|
519
|
+
return { ...t, metadata: { ...t.metadata } };
|
|
520
|
+
}
|
|
521
|
+
export function listSubagentTasksV2() {
|
|
522
|
+
return [..._saTasks.values()].map((t) => ({
|
|
523
|
+
...t,
|
|
524
|
+
metadata: { ...t.metadata },
|
|
525
|
+
}));
|
|
526
|
+
}
|
|
322
527
|
|
|
323
|
-
export function autoPauseIdleSubagentsV2({ now } = {}) {
|
|
324
|
-
|
|
528
|
+
export function autoPauseIdleSubagentsV2({ now } = {}) {
|
|
529
|
+
const t = now ?? Date.now();
|
|
530
|
+
const flipped = [];
|
|
531
|
+
for (const p of _saProfiles.values())
|
|
532
|
+
if (
|
|
533
|
+
p.status === SUBAGENT_PROFILE_MATURITY_V2.ACTIVE &&
|
|
534
|
+
t - p.lastTouchedAt >= _saProfileIdleMs
|
|
535
|
+
) {
|
|
536
|
+
p.status = SUBAGENT_PROFILE_MATURITY_V2.PAUSED;
|
|
537
|
+
p.updatedAt = t;
|
|
538
|
+
flipped.push(p.id);
|
|
539
|
+
}
|
|
540
|
+
return { flipped, count: flipped.length };
|
|
541
|
+
}
|
|
542
|
+
export function autoFailStuckSubagentTasksV2({ now } = {}) {
|
|
543
|
+
const t = now ?? Date.now();
|
|
544
|
+
const flipped = [];
|
|
545
|
+
for (const k of _saTasks.values())
|
|
546
|
+
if (
|
|
547
|
+
k.status === SUBAGENT_TASK_LIFECYCLE_V2.RUNNING &&
|
|
548
|
+
k.startedAt != null &&
|
|
549
|
+
t - k.startedAt >= _saTaskStuckMs
|
|
550
|
+
) {
|
|
551
|
+
k.status = SUBAGENT_TASK_LIFECYCLE_V2.FAILED;
|
|
552
|
+
k.updatedAt = t;
|
|
553
|
+
if (!k.settledAt) k.settledAt = t;
|
|
554
|
+
k.metadata.failReason = "auto-fail-stuck";
|
|
555
|
+
flipped.push(k.id);
|
|
556
|
+
}
|
|
557
|
+
return { flipped, count: flipped.length };
|
|
558
|
+
}
|
|
325
559
|
|
|
326
560
|
export function getSubAgentRegistryStatsV2() {
|
|
327
|
-
const profilesByStatus = {};
|
|
328
|
-
|
|
329
|
-
|
|
561
|
+
const profilesByStatus = {};
|
|
562
|
+
for (const s of Object.values(SUBAGENT_PROFILE_MATURITY_V2))
|
|
563
|
+
profilesByStatus[s] = 0;
|
|
564
|
+
for (const p of _saProfiles.values()) profilesByStatus[p.status]++;
|
|
565
|
+
const tasksByStatus = {};
|
|
566
|
+
for (const s of Object.values(SUBAGENT_TASK_LIFECYCLE_V2))
|
|
567
|
+
tasksByStatus[s] = 0;
|
|
568
|
+
for (const t of _saTasks.values()) tasksByStatus[t.status]++;
|
|
569
|
+
return {
|
|
570
|
+
totalProfilesV2: _saProfiles.size,
|
|
571
|
+
totalTasksV2: _saTasks.size,
|
|
572
|
+
maxActiveSubagentsPerOwner: _saMaxActivePerOwner,
|
|
573
|
+
maxPendingTasksPerSubagent: _saMaxPendingPerProfile,
|
|
574
|
+
subagentIdleMs: _saProfileIdleMs,
|
|
575
|
+
subagentTaskStuckMs: _saTaskStuckMs,
|
|
576
|
+
profilesByStatus,
|
|
577
|
+
tasksByStatus,
|
|
578
|
+
};
|
|
330
579
|
}
|