chainlesschain 0.81.0 → 0.143.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/bin/chainlesschain.js +0 -0
- package/package.json +1 -1
- package/src/commands/a2a.js +62 -0
- package/src/commands/activitypub.js +61 -0
- package/src/commands/agent-network.js +254 -1
- package/src/commands/agent.js +117 -0
- package/src/commands/audit.js +302 -0
- package/src/commands/automation.js +271 -1
- package/src/commands/bi.js +61 -0
- package/src/commands/bm25.js +78 -0
- package/src/commands/browse.js +64 -0
- package/src/commands/ccron.js +78 -0
- package/src/commands/codegen.js +224 -0
- package/src/commands/collab.js +341 -0
- package/src/commands/compliance.js +1075 -0
- package/src/commands/compt.js +78 -0
- package/src/commands/consol.js +231 -0
- package/src/commands/cowork.js +263 -0
- package/src/commands/crosschain.js +62 -0
- package/src/commands/dao.js +62 -0
- package/src/commands/dbevo.js +284 -0
- package/src/commands/dev.js +252 -0
- package/src/commands/did.js +358 -0
- package/src/commands/dlp.js +61 -0
- package/src/commands/economy.js +56 -0
- package/src/commands/encrypt.js +341 -0
- package/src/commands/evolution.js +56 -0
- package/src/commands/evomap.js +61 -0
- package/src/commands/export.js +256 -1
- package/src/commands/fflag.js +178 -0
- package/src/commands/fusion.js +258 -0
- package/src/commands/git.js +45 -0
- package/src/commands/governance.js +325 -0
- package/src/commands/hardening.js +411 -0
- package/src/commands/hmemory.js +56 -0
- package/src/commands/hook.js +148 -0
- package/src/commands/import.js +252 -0
- package/src/commands/incentive.js +322 -0
- package/src/commands/inference.js +42 -0
- package/src/commands/infra.js +244 -0
- package/src/commands/instinct.js +260 -0
- package/src/commands/ipfs.js +318 -0
- package/src/commands/itbudget.js +45 -0
- package/src/commands/kg.js +387 -0
- package/src/commands/llm.js +263 -0
- package/src/commands/lowcode.js +44 -0
- package/src/commands/matrix.js +62 -0
- package/src/commands/mcp.js +221 -0
- package/src/commands/mcpscaf.js +41 -0
- package/src/commands/meminj.js +41 -0
- package/src/commands/memory.js +248 -0
- package/src/commands/multimodal.js +296 -0
- package/src/commands/nlprog.js +356 -0
- package/src/commands/nostr.js +62 -0
- package/src/commands/note.js +244 -0
- package/src/commands/ops.js +354 -0
- package/src/commands/orchestrate.js +166 -0
- package/src/commands/orchgov.js +45 -0
- package/src/commands/org.js +277 -0
- package/src/commands/p2p.js +390 -0
- package/src/commands/pdfp.js +78 -0
- package/src/commands/perception.js +290 -0
- package/src/commands/perf.js +39 -0
- package/src/commands/perm.js +45 -0
- package/src/commands/permmem.js +251 -0
- package/src/commands/pipeline.js +57 -1
- package/src/commands/planmode.js +45 -0
- package/src/commands/plugin-ecosystem.js +273 -0
- package/src/commands/pqc.js +393 -0
- package/src/commands/promcomp.js +82 -0
- package/src/commands/quantization.js +351 -0
- package/src/commands/rcache.js +271 -0
- package/src/commands/recommend.js +382 -0
- package/src/commands/runtime.js +307 -0
- package/src/commands/scim.js +262 -0
- package/src/commands/seshhook.js +41 -0
- package/src/commands/seshsearch.js +41 -0
- package/src/commands/seshtail.js +41 -0
- package/src/commands/seshu.js +41 -0
- package/src/commands/session.js +258 -0
- package/src/commands/sganal.js +78 -0
- package/src/commands/siem.js +40 -0
- package/src/commands/skill.js +267 -1
- package/src/commands/slotfill.js +41 -0
- package/src/commands/social.js +290 -0
- package/src/commands/sso.js +186 -1
- package/src/commands/svccont.js +45 -0
- package/src/commands/sync.js +256 -0
- package/src/commands/tech.js +338 -0
- package/src/commands/tenant.js +351 -0
- package/src/commands/tms.js +45 -0
- package/src/commands/tokens.js +269 -0
- package/src/commands/topiccls.js +45 -0
- package/src/commands/trust.js +249 -0
- package/src/commands/uprof.js +45 -0
- package/src/commands/vcheck.js +78 -0
- package/src/commands/wallet.js +277 -0
- package/src/commands/webfetch.js +41 -0
- package/src/commands/workflow.js +171 -0
- package/src/commands/zkp.js +62 -0
- package/src/harness/prompt-compressor.js +331 -0
- package/src/index.js +65 -1
- package/src/lib/a2a-protocol.js +105 -0
- package/src/lib/activitypub-bridge.js +105 -0
- package/src/lib/agent-coordinator.js +325 -0
- package/src/lib/agent-economy.js +105 -0
- package/src/lib/agent-network.js +387 -0
- package/src/lib/agent-router.js +395 -0
- package/src/lib/aiops.js +478 -0
- package/src/lib/app-builder.js +105 -0
- package/src/lib/audit-logger.js +379 -0
- package/src/lib/automation-engine.js +330 -0
- package/src/lib/autonomous-agent.js +105 -0
- package/src/lib/autonomous-developer.js +350 -0
- package/src/lib/bi-engine.js +105 -0
- package/src/lib/bm25-search.js +81 -0
- package/src/lib/browser-automation.js +105 -0
- package/src/lib/code-agent.js +323 -0
- package/src/lib/collaboration-governance.js +364 -0
- package/src/lib/community-governance.js +436 -0
- package/src/lib/compliance-framework-reporter.js +105 -0
- package/src/lib/compliance-manager.js +434 -0
- package/src/lib/compression-telemetry.js +81 -0
- package/src/lib/content-recommendation.js +469 -0
- package/src/lib/content-recommender.js +105 -0
- package/src/lib/cowork-cron.js +81 -0
- package/src/lib/cowork-task-runner.js +105 -0
- package/src/lib/cross-chain.js +105 -0
- package/src/lib/crypto-manager.js +350 -0
- package/src/lib/dao-governance.js +105 -0
- package/src/lib/dbevo.js +338 -0
- package/src/lib/decentral-infra.js +340 -0
- package/src/lib/did-manager.js +367 -0
- package/src/lib/dlp-engine.js +105 -0
- package/src/lib/evolution-system.js +105 -0
- package/src/lib/evomap-manager.js +105 -0
- package/src/lib/execution-backend.js +105 -0
- package/src/lib/feature-flags.js +85 -0
- package/src/lib/git-integration.js +105 -0
- package/src/lib/hardening-manager.js +348 -0
- package/src/lib/hierarchical-memory.js +105 -0
- package/src/lib/hook-manager.js +380 -0
- package/src/lib/inference-network.js +105 -0
- package/src/lib/instinct-manager.js +332 -0
- package/src/lib/ipfs-storage.js +334 -0
- package/src/lib/iteration-budget.js +105 -0
- package/src/lib/knowledge-exporter.js +381 -0
- package/src/lib/knowledge-graph.js +432 -0
- package/src/lib/knowledge-importer.js +379 -0
- package/src/lib/llm-providers.js +391 -0
- package/src/lib/matrix-bridge.js +105 -0
- package/src/lib/mcp-registry.js +333 -0
- package/src/lib/mcp-scaffold.js +81 -0
- package/src/lib/memory-injection.js +81 -0
- package/src/lib/memory-manager.js +330 -0
- package/src/lib/multimodal.js +346 -0
- package/src/lib/nl-programming.js +343 -0
- package/src/lib/nostr-bridge.js +105 -0
- package/src/lib/note-versioning.js +327 -0
- package/src/lib/orchestrator.js +105 -0
- package/src/lib/org-manager.js +323 -0
- package/src/lib/p2p-manager.js +387 -0
- package/src/lib/pdf-parser.js +81 -0
- package/src/lib/perception.js +346 -0
- package/src/lib/perf-tuning.js +109 -1
- package/src/lib/permanent-memory.js +320 -0
- package/src/lib/permission-engine.js +81 -0
- package/src/lib/pipeline-orchestrator.js +105 -0
- package/src/lib/plan-mode.js +81 -0
- package/src/lib/plugin-ecosystem.js +377 -0
- package/src/lib/pqc-manager.js +368 -0
- package/src/lib/prompt-compressor.js +1 -10
- package/src/lib/protocol-fusion.js +417 -0
- package/src/lib/quantization.js +325 -0
- package/src/lib/response-cache.js +327 -0
- package/src/lib/scim-manager.js +329 -0
- package/src/lib/service-container.js +81 -0
- package/src/lib/session-consolidator.js +105 -0
- package/src/lib/session-hooks.js +81 -0
- package/src/lib/session-manager.js +329 -0
- package/src/lib/session-search.js +81 -0
- package/src/lib/session-tail.js +81 -0
- package/src/lib/session-usage.js +83 -0
- package/src/lib/siem-exporter.js +105 -0
- package/src/lib/skill-loader.js +377 -0
- package/src/lib/slot-filler.js +81 -0
- package/src/lib/social-graph-analytics.js +81 -0
- package/src/lib/social-graph.js +81 -0
- package/src/lib/social-manager.js +326 -0
- package/src/lib/sso-manager.js +332 -0
- package/src/lib/sub-agent-registry.js +110 -0
- package/src/lib/sync-manager.js +326 -0
- package/src/lib/task-model-selector.js +81 -0
- package/src/lib/tech-learning-engine.js +369 -0
- package/src/lib/tenant-saas.js +460 -0
- package/src/lib/threat-intel.js +335 -0
- package/src/lib/todo-manager.js +105 -0
- package/src/lib/token-incentive.js +293 -0
- package/src/lib/token-tracker.js +329 -0
- package/src/lib/topic-classifier.js +105 -0
- package/src/lib/trust-security.js +390 -0
- package/src/lib/ueba.js +389 -0
- package/src/lib/universal-runtime.js +325 -0
- package/src/lib/user-profile.js +81 -0
- package/src/lib/version-checker.js +81 -0
- package/src/lib/wallet-manager.js +326 -0
- package/src/lib/web-fetch.js +81 -0
- package/src/lib/workflow-engine.js +322 -0
- package/src/lib/zkp-engine.js +105 -0
package/src/lib/sync-manager.js
CHANGED
|
@@ -345,3 +345,329 @@ export function clearSyncData(db) {
|
|
|
345
345
|
db.prepare("DELETE FROM sync_log").run();
|
|
346
346
|
return true;
|
|
347
347
|
}
|
|
348
|
+
|
|
349
|
+
/* ═══════════════════════════════════════════════════════════════
|
|
350
|
+
* V2 Surface — Sync Manager governance layer.
|
|
351
|
+
* Tracks tracked-resource maturity + sync-run lifecycle independent
|
|
352
|
+
* of legacy registerResource/pushResources/pullResources flows above.
|
|
353
|
+
* ═══════════════════════════════════════════════════════════════ */
|
|
354
|
+
|
|
355
|
+
export const RESOURCE_MATURITY_V2 = Object.freeze({
|
|
356
|
+
PENDING: "pending",
|
|
357
|
+
ACTIVE: "active",
|
|
358
|
+
PAUSED: "paused",
|
|
359
|
+
ARCHIVED: "archived",
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
export const SYNC_RUN_V2 = Object.freeze({
|
|
363
|
+
QUEUED: "queued",
|
|
364
|
+
RUNNING: "running",
|
|
365
|
+
SUCCEEDED: "succeeded",
|
|
366
|
+
FAILED: "failed",
|
|
367
|
+
CANCELLED: "cancelled",
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
const RESOURCE_TRANSITIONS_V2 = new Map([
|
|
371
|
+
["pending", new Set(["active", "archived"])],
|
|
372
|
+
["active", new Set(["paused", "archived"])],
|
|
373
|
+
["paused", new Set(["active", "archived"])],
|
|
374
|
+
["archived", new Set()],
|
|
375
|
+
]);
|
|
376
|
+
const RESOURCE_TERMINALS_V2 = new Set(["archived"]);
|
|
377
|
+
|
|
378
|
+
const RUN_TRANSITIONS_V2 = new Map([
|
|
379
|
+
["queued", new Set(["running", "cancelled"])],
|
|
380
|
+
["running", new Set(["succeeded", "failed", "cancelled"])],
|
|
381
|
+
["succeeded", new Set()],
|
|
382
|
+
["failed", new Set()],
|
|
383
|
+
["cancelled", new Set()],
|
|
384
|
+
]);
|
|
385
|
+
const RUN_TERMINALS_V2 = new Set(["succeeded", "failed", "cancelled"]);
|
|
386
|
+
|
|
387
|
+
export const SYNC_DEFAULT_MAX_ACTIVE_RESOURCES_PER_OWNER = 200;
|
|
388
|
+
export const SYNC_DEFAULT_MAX_RUNNING_RUNS_PER_RESOURCE = 1;
|
|
389
|
+
export const SYNC_DEFAULT_RESOURCE_IDLE_MS = 1000 * 60 * 60 * 24 * 30; // 30 days
|
|
390
|
+
export const SYNC_DEFAULT_RUN_STUCK_MS = 1000 * 60 * 15; // 15 min
|
|
391
|
+
|
|
392
|
+
const _resourcesV2 = new Map();
|
|
393
|
+
const _runsV2 = new Map();
|
|
394
|
+
let _maxActiveResourcesPerOwnerV2 = SYNC_DEFAULT_MAX_ACTIVE_RESOURCES_PER_OWNER;
|
|
395
|
+
let _maxRunningRunsPerResourceV2 = SYNC_DEFAULT_MAX_RUNNING_RUNS_PER_RESOURCE;
|
|
396
|
+
let _resourceIdleMsV2 = SYNC_DEFAULT_RESOURCE_IDLE_MS;
|
|
397
|
+
let _runStuckMsV2 = SYNC_DEFAULT_RUN_STUCK_MS;
|
|
398
|
+
|
|
399
|
+
function _posIntSyncV2(n, label) {
|
|
400
|
+
const v = Math.floor(Number(n));
|
|
401
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
402
|
+
throw new Error(`${label} must be a positive integer`);
|
|
403
|
+
return v;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
export function getMaxActiveResourcesPerOwnerV2() {
|
|
407
|
+
return _maxActiveResourcesPerOwnerV2;
|
|
408
|
+
}
|
|
409
|
+
export function setMaxActiveResourcesPerOwnerV2(n) {
|
|
410
|
+
_maxActiveResourcesPerOwnerV2 = _posIntSyncV2(
|
|
411
|
+
n,
|
|
412
|
+
"maxActiveResourcesPerOwner",
|
|
413
|
+
);
|
|
414
|
+
}
|
|
415
|
+
export function getMaxRunningRunsPerResourceV2() {
|
|
416
|
+
return _maxRunningRunsPerResourceV2;
|
|
417
|
+
}
|
|
418
|
+
export function setMaxRunningRunsPerResourceV2(n) {
|
|
419
|
+
_maxRunningRunsPerResourceV2 = _posIntSyncV2(n, "maxRunningRunsPerResource");
|
|
420
|
+
}
|
|
421
|
+
export function getResourceIdleMsV2() {
|
|
422
|
+
return _resourceIdleMsV2;
|
|
423
|
+
}
|
|
424
|
+
export function setResourceIdleMsV2(n) {
|
|
425
|
+
_resourceIdleMsV2 = _posIntSyncV2(n, "resourceIdleMs");
|
|
426
|
+
}
|
|
427
|
+
export function getRunStuckMsV2() {
|
|
428
|
+
return _runStuckMsV2;
|
|
429
|
+
}
|
|
430
|
+
export function setRunStuckMsV2(n) {
|
|
431
|
+
_runStuckMsV2 = _posIntSyncV2(n, "runStuckMs");
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
export function getActiveResourceCountV2(owner) {
|
|
435
|
+
let n = 0;
|
|
436
|
+
for (const r of _resourcesV2.values()) {
|
|
437
|
+
if (r.owner === owner && r.status === "active") n += 1;
|
|
438
|
+
}
|
|
439
|
+
return n;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
export function getRunningRunCountV2(resourceId) {
|
|
443
|
+
let n = 0;
|
|
444
|
+
for (const j of _runsV2.values()) {
|
|
445
|
+
if (j.resourceId === resourceId && j.status === "running") n += 1;
|
|
446
|
+
}
|
|
447
|
+
return n;
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
function _copyResV2(r) {
|
|
451
|
+
return { ...r, metadata: { ...r.metadata } };
|
|
452
|
+
}
|
|
453
|
+
function _copyRunV2(j) {
|
|
454
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
export function registerResourceV2(
|
|
458
|
+
id,
|
|
459
|
+
{ owner, kind, metadata = {}, now = Date.now() } = {},
|
|
460
|
+
) {
|
|
461
|
+
if (!id || typeof id !== "string") throw new Error("id must be a string");
|
|
462
|
+
if (!owner || typeof owner !== "string")
|
|
463
|
+
throw new Error("owner must be a string");
|
|
464
|
+
if (!kind || typeof kind !== "string")
|
|
465
|
+
throw new Error("kind must be a string");
|
|
466
|
+
if (_resourcesV2.has(id)) throw new Error(`resource ${id} already exists`);
|
|
467
|
+
const r = {
|
|
468
|
+
id,
|
|
469
|
+
owner,
|
|
470
|
+
kind,
|
|
471
|
+
status: "pending",
|
|
472
|
+
createdAt: now,
|
|
473
|
+
lastSeenAt: now,
|
|
474
|
+
activatedAt: null,
|
|
475
|
+
archivedAt: null,
|
|
476
|
+
metadata: { ...metadata },
|
|
477
|
+
};
|
|
478
|
+
_resourcesV2.set(id, r);
|
|
479
|
+
return _copyResV2(r);
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
export function getResourceV2(id) {
|
|
483
|
+
const r = _resourcesV2.get(id);
|
|
484
|
+
return r ? _copyResV2(r) : null;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
export function listResourcesV2({ owner, kind, status } = {}) {
|
|
488
|
+
const out = [];
|
|
489
|
+
for (const r of _resourcesV2.values()) {
|
|
490
|
+
if (owner && r.owner !== owner) continue;
|
|
491
|
+
if (kind && r.kind !== kind) continue;
|
|
492
|
+
if (status && r.status !== status) continue;
|
|
493
|
+
out.push(_copyResV2(r));
|
|
494
|
+
}
|
|
495
|
+
return out;
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
export function setResourceStatusV2(id, next, { now = Date.now() } = {}) {
|
|
499
|
+
const r = _resourcesV2.get(id);
|
|
500
|
+
if (!r) throw new Error(`resource ${id} not found`);
|
|
501
|
+
if (!RESOURCE_TRANSITIONS_V2.has(next))
|
|
502
|
+
throw new Error(`unknown resource status: ${next}`);
|
|
503
|
+
if (RESOURCE_TERMINALS_V2.has(r.status))
|
|
504
|
+
throw new Error(`resource ${id} is in terminal state ${r.status}`);
|
|
505
|
+
const allowed = RESOURCE_TRANSITIONS_V2.get(r.status);
|
|
506
|
+
if (!allowed.has(next))
|
|
507
|
+
throw new Error(`cannot transition resource from ${r.status} to ${next}`);
|
|
508
|
+
if (next === "active") {
|
|
509
|
+
if (r.status === "pending") {
|
|
510
|
+
const count = getActiveResourceCountV2(r.owner);
|
|
511
|
+
if (count >= _maxActiveResourcesPerOwnerV2)
|
|
512
|
+
throw new Error(
|
|
513
|
+
`owner ${r.owner} already at active-resource cap (${_maxActiveResourcesPerOwnerV2})`,
|
|
514
|
+
);
|
|
515
|
+
}
|
|
516
|
+
if (!r.activatedAt) r.activatedAt = now;
|
|
517
|
+
}
|
|
518
|
+
if (next === "archived" && !r.archivedAt) r.archivedAt = now;
|
|
519
|
+
r.status = next;
|
|
520
|
+
r.lastSeenAt = now;
|
|
521
|
+
return _copyResV2(r);
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
export function activateResourceV2(id, opts) {
|
|
525
|
+
return setResourceStatusV2(id, "active", opts);
|
|
526
|
+
}
|
|
527
|
+
export function pauseResourceV2(id, opts) {
|
|
528
|
+
return setResourceStatusV2(id, "paused", opts);
|
|
529
|
+
}
|
|
530
|
+
export function archiveResourceV2(id, opts) {
|
|
531
|
+
return setResourceStatusV2(id, "archived", opts);
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
export function touchResourceV2(id, { now = Date.now() } = {}) {
|
|
535
|
+
const r = _resourcesV2.get(id);
|
|
536
|
+
if (!r) throw new Error(`resource ${id} not found`);
|
|
537
|
+
r.lastSeenAt = now;
|
|
538
|
+
return _copyResV2(r);
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
export function createSyncRunV2(
|
|
542
|
+
id,
|
|
543
|
+
{ resourceId, kind = "push", metadata = {}, now = Date.now() } = {},
|
|
544
|
+
) {
|
|
545
|
+
if (!id || typeof id !== "string") throw new Error("id must be a string");
|
|
546
|
+
if (!resourceId || typeof resourceId !== "string")
|
|
547
|
+
throw new Error("resourceId must be a string");
|
|
548
|
+
if (_runsV2.has(id)) throw new Error(`syncRun ${id} already exists`);
|
|
549
|
+
const j = {
|
|
550
|
+
id,
|
|
551
|
+
resourceId,
|
|
552
|
+
kind,
|
|
553
|
+
status: "queued",
|
|
554
|
+
createdAt: now,
|
|
555
|
+
lastSeenAt: now,
|
|
556
|
+
startedAt: null,
|
|
557
|
+
finishedAt: null,
|
|
558
|
+
metadata: { ...metadata },
|
|
559
|
+
};
|
|
560
|
+
_runsV2.set(id, j);
|
|
561
|
+
return _copyRunV2(j);
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
export function getSyncRunV2(id) {
|
|
565
|
+
const j = _runsV2.get(id);
|
|
566
|
+
return j ? _copyRunV2(j) : null;
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
export function listSyncRunsV2({ resourceId, status } = {}) {
|
|
570
|
+
const out = [];
|
|
571
|
+
for (const j of _runsV2.values()) {
|
|
572
|
+
if (resourceId && j.resourceId !== resourceId) continue;
|
|
573
|
+
if (status && j.status !== status) continue;
|
|
574
|
+
out.push(_copyRunV2(j));
|
|
575
|
+
}
|
|
576
|
+
return out;
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
export function setSyncRunStatusV2(id, next, { now = Date.now() } = {}) {
|
|
580
|
+
const j = _runsV2.get(id);
|
|
581
|
+
if (!j) throw new Error(`syncRun ${id} not found`);
|
|
582
|
+
if (!RUN_TRANSITIONS_V2.has(next))
|
|
583
|
+
throw new Error(`unknown syncRun status: ${next}`);
|
|
584
|
+
if (RUN_TERMINALS_V2.has(j.status))
|
|
585
|
+
throw new Error(`syncRun ${id} is in terminal state ${j.status}`);
|
|
586
|
+
const allowed = RUN_TRANSITIONS_V2.get(j.status);
|
|
587
|
+
if (!allowed.has(next))
|
|
588
|
+
throw new Error(`cannot transition syncRun from ${j.status} to ${next}`);
|
|
589
|
+
if (next === "running" && j.status === "queued") {
|
|
590
|
+
const count = getRunningRunCountV2(j.resourceId);
|
|
591
|
+
if (count >= _maxRunningRunsPerResourceV2)
|
|
592
|
+
throw new Error(
|
|
593
|
+
`resource ${j.resourceId} already at running-run cap (${_maxRunningRunsPerResourceV2})`,
|
|
594
|
+
);
|
|
595
|
+
if (!j.startedAt) j.startedAt = now;
|
|
596
|
+
}
|
|
597
|
+
if (RUN_TERMINALS_V2.has(next) && !j.finishedAt) j.finishedAt = now;
|
|
598
|
+
j.status = next;
|
|
599
|
+
j.lastSeenAt = now;
|
|
600
|
+
return _copyRunV2(j);
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
export function startSyncRunV2(id, opts) {
|
|
604
|
+
return setSyncRunStatusV2(id, "running", opts);
|
|
605
|
+
}
|
|
606
|
+
export function succeedSyncRunV2(id, opts) {
|
|
607
|
+
return setSyncRunStatusV2(id, "succeeded", opts);
|
|
608
|
+
}
|
|
609
|
+
export function failSyncRunV2(id, opts) {
|
|
610
|
+
return setSyncRunStatusV2(id, "failed", opts);
|
|
611
|
+
}
|
|
612
|
+
export function cancelSyncRunV2(id, opts) {
|
|
613
|
+
return setSyncRunStatusV2(id, "cancelled", opts);
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
export function autoArchiveIdleResourcesV2({ now = Date.now() } = {}) {
|
|
617
|
+
const flipped = [];
|
|
618
|
+
for (const r of _resourcesV2.values()) {
|
|
619
|
+
if (r.status === "archived" || r.status === "pending") continue;
|
|
620
|
+
if (now - r.lastSeenAt > _resourceIdleMsV2) {
|
|
621
|
+
r.status = "archived";
|
|
622
|
+
r.lastSeenAt = now;
|
|
623
|
+
if (!r.archivedAt) r.archivedAt = now;
|
|
624
|
+
flipped.push(_copyResV2(r));
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
return flipped;
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
export function autoFailStuckSyncRunsV2({ now = Date.now() } = {}) {
|
|
631
|
+
const flipped = [];
|
|
632
|
+
for (const j of _runsV2.values()) {
|
|
633
|
+
if (j.status !== "running") continue;
|
|
634
|
+
const ref = j.startedAt ?? j.lastSeenAt;
|
|
635
|
+
if (now - ref > _runStuckMsV2) {
|
|
636
|
+
j.status = "failed";
|
|
637
|
+
j.lastSeenAt = now;
|
|
638
|
+
if (!j.finishedAt) j.finishedAt = now;
|
|
639
|
+
flipped.push(_copyRunV2(j));
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
return flipped;
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
export function getSyncManagerStatsV2() {
|
|
646
|
+
const resourcesByStatus = {};
|
|
647
|
+
for (const v of Object.values(RESOURCE_MATURITY_V2)) resourcesByStatus[v] = 0;
|
|
648
|
+
for (const r of _resourcesV2.values()) resourcesByStatus[r.status] += 1;
|
|
649
|
+
|
|
650
|
+
const runsByStatus = {};
|
|
651
|
+
for (const v of Object.values(SYNC_RUN_V2)) runsByStatus[v] = 0;
|
|
652
|
+
for (const j of _runsV2.values()) runsByStatus[j.status] += 1;
|
|
653
|
+
|
|
654
|
+
return {
|
|
655
|
+
totalResourcesV2: _resourcesV2.size,
|
|
656
|
+
totalSyncRunsV2: _runsV2.size,
|
|
657
|
+
maxActiveResourcesPerOwner: _maxActiveResourcesPerOwnerV2,
|
|
658
|
+
maxRunningRunsPerResource: _maxRunningRunsPerResourceV2,
|
|
659
|
+
resourceIdleMs: _resourceIdleMsV2,
|
|
660
|
+
runStuckMs: _runStuckMsV2,
|
|
661
|
+
resourcesByStatus,
|
|
662
|
+
runsByStatus,
|
|
663
|
+
};
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
export function _resetStateSyncManagerV2() {
|
|
667
|
+
_resourcesV2.clear();
|
|
668
|
+
_runsV2.clear();
|
|
669
|
+
_maxActiveResourcesPerOwnerV2 = SYNC_DEFAULT_MAX_ACTIVE_RESOURCES_PER_OWNER;
|
|
670
|
+
_maxRunningRunsPerResourceV2 = SYNC_DEFAULT_MAX_RUNNING_RUNS_PER_RESOURCE;
|
|
671
|
+
_resourceIdleMsV2 = SYNC_DEFAULT_RESOURCE_IDLE_MS;
|
|
672
|
+
_runStuckMsV2 = SYNC_DEFAULT_RUN_STUCK_MS;
|
|
673
|
+
}
|
|
@@ -242,3 +242,84 @@ export function getTaskName(taskType) {
|
|
|
242
242
|
export function getTaskTypes() {
|
|
243
243
|
return { ...TaskType };
|
|
244
244
|
}
|
|
245
|
+
|
|
246
|
+
// ===== V2 Surface: Task Model Selector governance overlay (CLI v0.141.0) =====
|
|
247
|
+
export const TMS_PROFILE_MATURITY_V2 = Object.freeze({
|
|
248
|
+
PENDING: "pending", ACTIVE: "active", STALE: "stale", DECOMMISSIONED: "decommissioned",
|
|
249
|
+
});
|
|
250
|
+
export const TMS_SELECTION_LIFECYCLE_V2 = Object.freeze({
|
|
251
|
+
QUEUED: "queued", SCORING: "scoring", COMPLETED: "completed", FAILED: "failed", CANCELLED: "cancelled",
|
|
252
|
+
});
|
|
253
|
+
const _tmsPTrans = new Map([
|
|
254
|
+
[TMS_PROFILE_MATURITY_V2.PENDING, new Set([TMS_PROFILE_MATURITY_V2.ACTIVE, TMS_PROFILE_MATURITY_V2.DECOMMISSIONED])],
|
|
255
|
+
[TMS_PROFILE_MATURITY_V2.ACTIVE, new Set([TMS_PROFILE_MATURITY_V2.STALE, TMS_PROFILE_MATURITY_V2.DECOMMISSIONED])],
|
|
256
|
+
[TMS_PROFILE_MATURITY_V2.STALE, new Set([TMS_PROFILE_MATURITY_V2.ACTIVE, TMS_PROFILE_MATURITY_V2.DECOMMISSIONED])],
|
|
257
|
+
[TMS_PROFILE_MATURITY_V2.DECOMMISSIONED, new Set()],
|
|
258
|
+
]);
|
|
259
|
+
const _tmsPTerminal = new Set([TMS_PROFILE_MATURITY_V2.DECOMMISSIONED]);
|
|
260
|
+
const _tmsSTrans = new Map([
|
|
261
|
+
[TMS_SELECTION_LIFECYCLE_V2.QUEUED, new Set([TMS_SELECTION_LIFECYCLE_V2.SCORING, TMS_SELECTION_LIFECYCLE_V2.CANCELLED])],
|
|
262
|
+
[TMS_SELECTION_LIFECYCLE_V2.SCORING, new Set([TMS_SELECTION_LIFECYCLE_V2.COMPLETED, TMS_SELECTION_LIFECYCLE_V2.FAILED, TMS_SELECTION_LIFECYCLE_V2.CANCELLED])],
|
|
263
|
+
[TMS_SELECTION_LIFECYCLE_V2.COMPLETED, new Set()],
|
|
264
|
+
[TMS_SELECTION_LIFECYCLE_V2.FAILED, new Set()],
|
|
265
|
+
[TMS_SELECTION_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
266
|
+
]);
|
|
267
|
+
const _tmsPsV2 = new Map();
|
|
268
|
+
const _tmsSsV2 = new Map();
|
|
269
|
+
let _tmsMaxActivePerOwner = 8, _tmsMaxPendingSelPerProfile = 16, _tmsIdleMs = 14 * 24 * 60 * 60 * 1000, _tmsStuckMs = 2 * 60 * 1000;
|
|
270
|
+
function _tmsPos(n, label) { const v = Math.floor(Number(n)); if (!Number.isFinite(v) || v <= 0) throw new Error(`${label} must be positive integer`); return v; }
|
|
271
|
+
function _tmsCheckP(from, to) { const a = _tmsPTrans.get(from); if (!a || !a.has(to)) throw new Error(`invalid tms profile transition ${from} → ${to}`); }
|
|
272
|
+
function _tmsCheckS(from, to) { const a = _tmsSTrans.get(from); if (!a || !a.has(to)) throw new Error(`invalid tms selection transition ${from} → ${to}`); }
|
|
273
|
+
export function setMaxActiveTmsProfilesPerOwnerV2(n) { _tmsMaxActivePerOwner = _tmsPos(n, "maxActiveTmsProfilesPerOwner"); }
|
|
274
|
+
export function getMaxActiveTmsProfilesPerOwnerV2() { return _tmsMaxActivePerOwner; }
|
|
275
|
+
export function setMaxPendingTmsSelectionsPerProfileV2(n) { _tmsMaxPendingSelPerProfile = _tmsPos(n, "maxPendingTmsSelectionsPerProfile"); }
|
|
276
|
+
export function getMaxPendingTmsSelectionsPerProfileV2() { return _tmsMaxPendingSelPerProfile; }
|
|
277
|
+
export function setTmsProfileIdleMsV2(n) { _tmsIdleMs = _tmsPos(n, "tmsProfileIdleMs"); }
|
|
278
|
+
export function getTmsProfileIdleMsV2() { return _tmsIdleMs; }
|
|
279
|
+
export function setTmsSelectionStuckMsV2(n) { _tmsStuckMs = _tmsPos(n, "tmsSelectionStuckMs"); }
|
|
280
|
+
export function getTmsSelectionStuckMsV2() { return _tmsStuckMs; }
|
|
281
|
+
export function _resetStateTaskModelSelectorV2() { _tmsPsV2.clear(); _tmsSsV2.clear(); _tmsMaxActivePerOwner = 8; _tmsMaxPendingSelPerProfile = 16; _tmsIdleMs = 14 * 24 * 60 * 60 * 1000; _tmsStuckMs = 2 * 60 * 1000; }
|
|
282
|
+
export function registerTmsProfileV2({ id, owner, strategy, metadata } = {}) {
|
|
283
|
+
if (!id) throw new Error("tms profile id required"); if (!owner) throw new Error("tms profile owner required");
|
|
284
|
+
if (_tmsPsV2.has(id)) throw new Error(`tms profile ${id} already registered`);
|
|
285
|
+
const now = Date.now();
|
|
286
|
+
const p = { id, owner, strategy: strategy || "default", status: TMS_PROFILE_MATURITY_V2.PENDING, createdAt: now, updatedAt: now, activatedAt: null, decommissionedAt: null, lastTouchedAt: now, metadata: { ...(metadata || {}) } };
|
|
287
|
+
_tmsPsV2.set(id, p); return { ...p, metadata: { ...p.metadata } };
|
|
288
|
+
}
|
|
289
|
+
function _tmsCountActive(owner) { let n = 0; for (const p of _tmsPsV2.values()) if (p.owner === owner && p.status === TMS_PROFILE_MATURITY_V2.ACTIVE) n++; return n; }
|
|
290
|
+
export function activateTmsProfileV2(id) {
|
|
291
|
+
const p = _tmsPsV2.get(id); if (!p) throw new Error(`tms profile ${id} not found`);
|
|
292
|
+
_tmsCheckP(p.status, TMS_PROFILE_MATURITY_V2.ACTIVE);
|
|
293
|
+
const recovery = p.status === TMS_PROFILE_MATURITY_V2.STALE;
|
|
294
|
+
if (!recovery && _tmsCountActive(p.owner) >= _tmsMaxActivePerOwner) throw new Error(`max active tms profiles for owner ${p.owner} reached`);
|
|
295
|
+
const now = Date.now(); p.status = TMS_PROFILE_MATURITY_V2.ACTIVE; p.updatedAt = now; p.lastTouchedAt = now; if (!p.activatedAt) p.activatedAt = now;
|
|
296
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
297
|
+
}
|
|
298
|
+
export function staleTmsProfileV2(id) { const p = _tmsPsV2.get(id); if (!p) throw new Error(`tms profile ${id} not found`); _tmsCheckP(p.status, TMS_PROFILE_MATURITY_V2.STALE); p.status = TMS_PROFILE_MATURITY_V2.STALE; p.updatedAt = Date.now(); return { ...p, metadata: { ...p.metadata } }; }
|
|
299
|
+
export function decommissionTmsProfileV2(id) { const p = _tmsPsV2.get(id); if (!p) throw new Error(`tms profile ${id} not found`); _tmsCheckP(p.status, TMS_PROFILE_MATURITY_V2.DECOMMISSIONED); const now = Date.now(); p.status = TMS_PROFILE_MATURITY_V2.DECOMMISSIONED; p.updatedAt = now; if (!p.decommissionedAt) p.decommissionedAt = now; return { ...p, metadata: { ...p.metadata } }; }
|
|
300
|
+
export function touchTmsProfileV2(id) { const p = _tmsPsV2.get(id); if (!p) throw new Error(`tms profile ${id} not found`); if (_tmsPTerminal.has(p.status)) throw new Error(`cannot touch terminal tms profile ${id}`); const now = Date.now(); p.lastTouchedAt = now; p.updatedAt = now; return { ...p, metadata: { ...p.metadata } }; }
|
|
301
|
+
export function getTmsProfileV2(id) { const p = _tmsPsV2.get(id); if (!p) return null; return { ...p, metadata: { ...p.metadata } }; }
|
|
302
|
+
export function listTmsProfilesV2() { return [..._tmsPsV2.values()].map((p) => ({ ...p, metadata: { ...p.metadata } })); }
|
|
303
|
+
function _tmsCountPending(profileId) { let n = 0; for (const s of _tmsSsV2.values()) if (s.profileId === profileId && (s.status === TMS_SELECTION_LIFECYCLE_V2.QUEUED || s.status === TMS_SELECTION_LIFECYCLE_V2.SCORING)) n++; return n; }
|
|
304
|
+
export function createTmsSelectionV2({ id, profileId, task, metadata } = {}) {
|
|
305
|
+
if (!id) throw new Error("tms selection id required"); if (!profileId) throw new Error("tms selection profileId required");
|
|
306
|
+
if (_tmsSsV2.has(id)) throw new Error(`tms selection ${id} already exists`);
|
|
307
|
+
if (!_tmsPsV2.has(profileId)) throw new Error(`tms profile ${profileId} not found`);
|
|
308
|
+
if (_tmsCountPending(profileId) >= _tmsMaxPendingSelPerProfile) throw new Error(`max pending tms selections for profile ${profileId} reached`);
|
|
309
|
+
const now = Date.now();
|
|
310
|
+
const s = { id, profileId, task: task || "", status: TMS_SELECTION_LIFECYCLE_V2.QUEUED, createdAt: now, updatedAt: now, startedAt: null, settledAt: null, metadata: { ...(metadata || {}) } };
|
|
311
|
+
_tmsSsV2.set(id, s); return { ...s, metadata: { ...s.metadata } };
|
|
312
|
+
}
|
|
313
|
+
export function scoreTmsSelectionV2(id) { const s = _tmsSsV2.get(id); if (!s) throw new Error(`tms selection ${id} not found`); _tmsCheckS(s.status, TMS_SELECTION_LIFECYCLE_V2.SCORING); const now = Date.now(); s.status = TMS_SELECTION_LIFECYCLE_V2.SCORING; s.updatedAt = now; if (!s.startedAt) s.startedAt = now; return { ...s, metadata: { ...s.metadata } }; }
|
|
314
|
+
export function completeTmsSelectionV2(id) { const s = _tmsSsV2.get(id); if (!s) throw new Error(`tms selection ${id} not found`); _tmsCheckS(s.status, TMS_SELECTION_LIFECYCLE_V2.COMPLETED); const now = Date.now(); s.status = TMS_SELECTION_LIFECYCLE_V2.COMPLETED; s.updatedAt = now; if (!s.settledAt) s.settledAt = now; return { ...s, metadata: { ...s.metadata } }; }
|
|
315
|
+
export function failTmsSelectionV2(id, reason) { const s = _tmsSsV2.get(id); if (!s) throw new Error(`tms selection ${id} not found`); _tmsCheckS(s.status, TMS_SELECTION_LIFECYCLE_V2.FAILED); const now = Date.now(); s.status = TMS_SELECTION_LIFECYCLE_V2.FAILED; s.updatedAt = now; if (!s.settledAt) s.settledAt = now; if (reason) s.metadata.failReason = String(reason); return { ...s, metadata: { ...s.metadata } }; }
|
|
316
|
+
export function cancelTmsSelectionV2(id, reason) { const s = _tmsSsV2.get(id); if (!s) throw new Error(`tms selection ${id} not found`); _tmsCheckS(s.status, TMS_SELECTION_LIFECYCLE_V2.CANCELLED); const now = Date.now(); s.status = TMS_SELECTION_LIFECYCLE_V2.CANCELLED; s.updatedAt = now; if (!s.settledAt) s.settledAt = now; if (reason) s.metadata.cancelReason = String(reason); return { ...s, metadata: { ...s.metadata } }; }
|
|
317
|
+
export function getTmsSelectionV2(id) { const s = _tmsSsV2.get(id); if (!s) return null; return { ...s, metadata: { ...s.metadata } }; }
|
|
318
|
+
export function listTmsSelectionsV2() { return [..._tmsSsV2.values()].map((s) => ({ ...s, metadata: { ...s.metadata } })); }
|
|
319
|
+
export function autoStaleIdleTmsProfilesV2({ now } = {}) { const t = now ?? Date.now(); const flipped = []; for (const p of _tmsPsV2.values()) if (p.status === TMS_PROFILE_MATURITY_V2.ACTIVE && (t - p.lastTouchedAt) >= _tmsIdleMs) { p.status = TMS_PROFILE_MATURITY_V2.STALE; p.updatedAt = t; flipped.push(p.id); } return { flipped, count: flipped.length }; }
|
|
320
|
+
export function autoFailStuckTmsSelectionsV2({ now } = {}) { const t = now ?? Date.now(); const flipped = []; for (const s of _tmsSsV2.values()) if (s.status === TMS_SELECTION_LIFECYCLE_V2.SCORING && s.startedAt != null && (t - s.startedAt) >= _tmsStuckMs) { s.status = TMS_SELECTION_LIFECYCLE_V2.FAILED; s.updatedAt = t; if (!s.settledAt) s.settledAt = t; s.metadata.failReason = "auto-fail-stuck"; flipped.push(s.id); } return { flipped, count: flipped.length }; }
|
|
321
|
+
export function getTaskModelSelectorGovStatsV2() {
|
|
322
|
+
const profilesByStatus = {}; for (const v of Object.values(TMS_PROFILE_MATURITY_V2)) profilesByStatus[v] = 0; for (const p of _tmsPsV2.values()) profilesByStatus[p.status]++;
|
|
323
|
+
const selectionsByStatus = {}; for (const v of Object.values(TMS_SELECTION_LIFECYCLE_V2)) selectionsByStatus[v] = 0; for (const s of _tmsSsV2.values()) selectionsByStatus[s.status]++;
|
|
324
|
+
return { totalTmsProfilesV2: _tmsPsV2.size, totalTmsSelectionsV2: _tmsSsV2.size, maxActiveTmsProfilesPerOwner: _tmsMaxActivePerOwner, maxPendingTmsSelectionsPerProfile: _tmsMaxPendingSelPerProfile, tmsProfileIdleMs: _tmsIdleMs, tmsSelectionStuckMs: _tmsStuckMs, profilesByStatus, selectionsByStatus };
|
|
325
|
+
}
|