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
|
@@ -436,3 +436,336 @@ export function applyPromptPatch(cwd, patch) {
|
|
|
436
436
|
systemPromptExtension: extended,
|
|
437
437
|
};
|
|
438
438
|
}
|
|
439
|
+
|
|
440
|
+
// =====================================================================
|
|
441
|
+
// cowork-learning V2 governance overlay (iter17)
|
|
442
|
+
// =====================================================================
|
|
443
|
+
export const LEARN_PROFILE_MATURITY_V2 = Object.freeze({
|
|
444
|
+
PENDING: "pending",
|
|
445
|
+
ACTIVE: "active",
|
|
446
|
+
STALE: "stale",
|
|
447
|
+
ARCHIVED: "archived",
|
|
448
|
+
});
|
|
449
|
+
export const LEARN_SAMPLE_LIFECYCLE_V2 = Object.freeze({
|
|
450
|
+
QUEUED: "queued",
|
|
451
|
+
TRAINING: "training",
|
|
452
|
+
TRAINED: "trained",
|
|
453
|
+
FAILED: "failed",
|
|
454
|
+
CANCELLED: "cancelled",
|
|
455
|
+
});
|
|
456
|
+
const _learnPTrans = new Map([
|
|
457
|
+
[
|
|
458
|
+
LEARN_PROFILE_MATURITY_V2.PENDING,
|
|
459
|
+
new Set([
|
|
460
|
+
LEARN_PROFILE_MATURITY_V2.ACTIVE,
|
|
461
|
+
LEARN_PROFILE_MATURITY_V2.ARCHIVED,
|
|
462
|
+
]),
|
|
463
|
+
],
|
|
464
|
+
[
|
|
465
|
+
LEARN_PROFILE_MATURITY_V2.ACTIVE,
|
|
466
|
+
new Set([
|
|
467
|
+
LEARN_PROFILE_MATURITY_V2.STALE,
|
|
468
|
+
LEARN_PROFILE_MATURITY_V2.ARCHIVED,
|
|
469
|
+
]),
|
|
470
|
+
],
|
|
471
|
+
[
|
|
472
|
+
LEARN_PROFILE_MATURITY_V2.STALE,
|
|
473
|
+
new Set([
|
|
474
|
+
LEARN_PROFILE_MATURITY_V2.ACTIVE,
|
|
475
|
+
LEARN_PROFILE_MATURITY_V2.ARCHIVED,
|
|
476
|
+
]),
|
|
477
|
+
],
|
|
478
|
+
[LEARN_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
|
|
479
|
+
]);
|
|
480
|
+
const _learnPTerminal = new Set([LEARN_PROFILE_MATURITY_V2.ARCHIVED]);
|
|
481
|
+
const _learnJTrans = new Map([
|
|
482
|
+
[
|
|
483
|
+
LEARN_SAMPLE_LIFECYCLE_V2.QUEUED,
|
|
484
|
+
new Set([
|
|
485
|
+
LEARN_SAMPLE_LIFECYCLE_V2.TRAINING,
|
|
486
|
+
LEARN_SAMPLE_LIFECYCLE_V2.CANCELLED,
|
|
487
|
+
]),
|
|
488
|
+
],
|
|
489
|
+
[
|
|
490
|
+
LEARN_SAMPLE_LIFECYCLE_V2.TRAINING,
|
|
491
|
+
new Set([
|
|
492
|
+
LEARN_SAMPLE_LIFECYCLE_V2.TRAINED,
|
|
493
|
+
LEARN_SAMPLE_LIFECYCLE_V2.FAILED,
|
|
494
|
+
LEARN_SAMPLE_LIFECYCLE_V2.CANCELLED,
|
|
495
|
+
]),
|
|
496
|
+
],
|
|
497
|
+
[LEARN_SAMPLE_LIFECYCLE_V2.TRAINED, new Set()],
|
|
498
|
+
[LEARN_SAMPLE_LIFECYCLE_V2.FAILED, new Set()],
|
|
499
|
+
[LEARN_SAMPLE_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
500
|
+
]);
|
|
501
|
+
const _learnPsV2 = new Map();
|
|
502
|
+
const _learnJsV2 = new Map();
|
|
503
|
+
let _learnMaxActive = 6,
|
|
504
|
+
_learnMaxPending = 20,
|
|
505
|
+
_learnIdleMs = 30 * 24 * 60 * 60 * 1000,
|
|
506
|
+
_learnStuckMs = 60 * 1000;
|
|
507
|
+
function _learnPos(n, label) {
|
|
508
|
+
const v = Math.floor(Number(n));
|
|
509
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
510
|
+
throw new Error(`${label} must be positive integer`);
|
|
511
|
+
return v;
|
|
512
|
+
}
|
|
513
|
+
function _learnCheckP(from, to) {
|
|
514
|
+
const a = _learnPTrans.get(from);
|
|
515
|
+
if (!a || !a.has(to))
|
|
516
|
+
throw new Error(`invalid learn profile transition ${from} → ${to}`);
|
|
517
|
+
}
|
|
518
|
+
function _learnCheckJ(from, to) {
|
|
519
|
+
const a = _learnJTrans.get(from);
|
|
520
|
+
if (!a || !a.has(to))
|
|
521
|
+
throw new Error(`invalid learn sample transition ${from} → ${to}`);
|
|
522
|
+
}
|
|
523
|
+
function _learnCountActive(owner) {
|
|
524
|
+
let c = 0;
|
|
525
|
+
for (const p of _learnPsV2.values())
|
|
526
|
+
if (p.owner === owner && p.status === LEARN_PROFILE_MATURITY_V2.ACTIVE) c++;
|
|
527
|
+
return c;
|
|
528
|
+
}
|
|
529
|
+
function _learnCountPending(profileId) {
|
|
530
|
+
let c = 0;
|
|
531
|
+
for (const j of _learnJsV2.values())
|
|
532
|
+
if (
|
|
533
|
+
j.profileId === profileId &&
|
|
534
|
+
(j.status === LEARN_SAMPLE_LIFECYCLE_V2.QUEUED ||
|
|
535
|
+
j.status === LEARN_SAMPLE_LIFECYCLE_V2.TRAINING)
|
|
536
|
+
)
|
|
537
|
+
c++;
|
|
538
|
+
return c;
|
|
539
|
+
}
|
|
540
|
+
export function setMaxActiveLearnProfilesPerOwnerV2(n) {
|
|
541
|
+
_learnMaxActive = _learnPos(n, "maxActiveLearnProfilesPerOwner");
|
|
542
|
+
}
|
|
543
|
+
export function getMaxActiveLearnProfilesPerOwnerV2() {
|
|
544
|
+
return _learnMaxActive;
|
|
545
|
+
}
|
|
546
|
+
export function setMaxPendingLearnSamplesPerProfileV2(n) {
|
|
547
|
+
_learnMaxPending = _learnPos(n, "maxPendingLearnSamplesPerProfile");
|
|
548
|
+
}
|
|
549
|
+
export function getMaxPendingLearnSamplesPerProfileV2() {
|
|
550
|
+
return _learnMaxPending;
|
|
551
|
+
}
|
|
552
|
+
export function setLearnProfileIdleMsV2(n) {
|
|
553
|
+
_learnIdleMs = _learnPos(n, "learnProfileIdleMs");
|
|
554
|
+
}
|
|
555
|
+
export function getLearnProfileIdleMsV2() {
|
|
556
|
+
return _learnIdleMs;
|
|
557
|
+
}
|
|
558
|
+
export function setLearnSampleStuckMsV2(n) {
|
|
559
|
+
_learnStuckMs = _learnPos(n, "learnSampleStuckMs");
|
|
560
|
+
}
|
|
561
|
+
export function getLearnSampleStuckMsV2() {
|
|
562
|
+
return _learnStuckMs;
|
|
563
|
+
}
|
|
564
|
+
export function _resetStateCoworkLearningV2() {
|
|
565
|
+
_learnPsV2.clear();
|
|
566
|
+
_learnJsV2.clear();
|
|
567
|
+
_learnMaxActive = 6;
|
|
568
|
+
_learnMaxPending = 20;
|
|
569
|
+
_learnIdleMs = 30 * 24 * 60 * 60 * 1000;
|
|
570
|
+
_learnStuckMs = 60 * 1000;
|
|
571
|
+
}
|
|
572
|
+
export function registerLearnProfileV2({ id, owner, topic, metadata } = {}) {
|
|
573
|
+
if (!id || !owner) throw new Error("id and owner required");
|
|
574
|
+
if (_learnPsV2.has(id)) throw new Error(`learn profile ${id} already exists`);
|
|
575
|
+
const now = Date.now();
|
|
576
|
+
const p = {
|
|
577
|
+
id,
|
|
578
|
+
owner,
|
|
579
|
+
topic: topic || "general",
|
|
580
|
+
status: LEARN_PROFILE_MATURITY_V2.PENDING,
|
|
581
|
+
createdAt: now,
|
|
582
|
+
updatedAt: now,
|
|
583
|
+
lastTouchedAt: now,
|
|
584
|
+
activatedAt: null,
|
|
585
|
+
archivedAt: null,
|
|
586
|
+
metadata: { ...(metadata || {}) },
|
|
587
|
+
};
|
|
588
|
+
_learnPsV2.set(id, p);
|
|
589
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
590
|
+
}
|
|
591
|
+
export function activateLearnProfileV2(id) {
|
|
592
|
+
const p = _learnPsV2.get(id);
|
|
593
|
+
if (!p) throw new Error(`learn profile ${id} not found`);
|
|
594
|
+
const isInitial = p.status === LEARN_PROFILE_MATURITY_V2.PENDING;
|
|
595
|
+
_learnCheckP(p.status, LEARN_PROFILE_MATURITY_V2.ACTIVE);
|
|
596
|
+
if (isInitial && _learnCountActive(p.owner) >= _learnMaxActive)
|
|
597
|
+
throw new Error(`max active learn profiles for owner ${p.owner} reached`);
|
|
598
|
+
const now = Date.now();
|
|
599
|
+
p.status = LEARN_PROFILE_MATURITY_V2.ACTIVE;
|
|
600
|
+
p.updatedAt = now;
|
|
601
|
+
p.lastTouchedAt = now;
|
|
602
|
+
if (!p.activatedAt) p.activatedAt = now;
|
|
603
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
604
|
+
}
|
|
605
|
+
export function staleLearnProfileV2(id) {
|
|
606
|
+
const p = _learnPsV2.get(id);
|
|
607
|
+
if (!p) throw new Error(`learn profile ${id} not found`);
|
|
608
|
+
_learnCheckP(p.status, LEARN_PROFILE_MATURITY_V2.STALE);
|
|
609
|
+
p.status = LEARN_PROFILE_MATURITY_V2.STALE;
|
|
610
|
+
p.updatedAt = Date.now();
|
|
611
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
612
|
+
}
|
|
613
|
+
export function archiveLearnProfileV2(id) {
|
|
614
|
+
const p = _learnPsV2.get(id);
|
|
615
|
+
if (!p) throw new Error(`learn profile ${id} not found`);
|
|
616
|
+
_learnCheckP(p.status, LEARN_PROFILE_MATURITY_V2.ARCHIVED);
|
|
617
|
+
const now = Date.now();
|
|
618
|
+
p.status = LEARN_PROFILE_MATURITY_V2.ARCHIVED;
|
|
619
|
+
p.updatedAt = now;
|
|
620
|
+
if (!p.archivedAt) p.archivedAt = now;
|
|
621
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
622
|
+
}
|
|
623
|
+
export function touchLearnProfileV2(id) {
|
|
624
|
+
const p = _learnPsV2.get(id);
|
|
625
|
+
if (!p) throw new Error(`learn profile ${id} not found`);
|
|
626
|
+
if (_learnPTerminal.has(p.status))
|
|
627
|
+
throw new Error(`cannot touch terminal learn profile ${id}`);
|
|
628
|
+
const now = Date.now();
|
|
629
|
+
p.lastTouchedAt = now;
|
|
630
|
+
p.updatedAt = now;
|
|
631
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
632
|
+
}
|
|
633
|
+
export function getLearnProfileV2(id) {
|
|
634
|
+
const p = _learnPsV2.get(id);
|
|
635
|
+
if (!p) return null;
|
|
636
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
637
|
+
}
|
|
638
|
+
export function listLearnProfilesV2() {
|
|
639
|
+
return [..._learnPsV2.values()].map((p) => ({
|
|
640
|
+
...p,
|
|
641
|
+
metadata: { ...p.metadata },
|
|
642
|
+
}));
|
|
643
|
+
}
|
|
644
|
+
export function createLearnSampleV2({ id, profileId, signal, metadata } = {}) {
|
|
645
|
+
if (!id || !profileId) throw new Error("id and profileId required");
|
|
646
|
+
if (_learnJsV2.has(id)) throw new Error(`learn sample ${id} already exists`);
|
|
647
|
+
if (!_learnPsV2.has(profileId))
|
|
648
|
+
throw new Error(`learn profile ${profileId} not found`);
|
|
649
|
+
if (_learnCountPending(profileId) >= _learnMaxPending)
|
|
650
|
+
throw new Error(
|
|
651
|
+
`max pending learn samples for profile ${profileId} reached`,
|
|
652
|
+
);
|
|
653
|
+
const now = Date.now();
|
|
654
|
+
const j = {
|
|
655
|
+
id,
|
|
656
|
+
profileId,
|
|
657
|
+
signal: signal || "",
|
|
658
|
+
status: LEARN_SAMPLE_LIFECYCLE_V2.QUEUED,
|
|
659
|
+
createdAt: now,
|
|
660
|
+
updatedAt: now,
|
|
661
|
+
startedAt: null,
|
|
662
|
+
settledAt: null,
|
|
663
|
+
metadata: { ...(metadata || {}) },
|
|
664
|
+
};
|
|
665
|
+
_learnJsV2.set(id, j);
|
|
666
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
667
|
+
}
|
|
668
|
+
export function trainingLearnSampleV2(id) {
|
|
669
|
+
const j = _learnJsV2.get(id);
|
|
670
|
+
if (!j) throw new Error(`learn sample ${id} not found`);
|
|
671
|
+
_learnCheckJ(j.status, LEARN_SAMPLE_LIFECYCLE_V2.TRAINING);
|
|
672
|
+
const now = Date.now();
|
|
673
|
+
j.status = LEARN_SAMPLE_LIFECYCLE_V2.TRAINING;
|
|
674
|
+
j.updatedAt = now;
|
|
675
|
+
if (!j.startedAt) j.startedAt = now;
|
|
676
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
677
|
+
}
|
|
678
|
+
export function completeSampleLearnV2(id) {
|
|
679
|
+
const j = _learnJsV2.get(id);
|
|
680
|
+
if (!j) throw new Error(`learn sample ${id} not found`);
|
|
681
|
+
_learnCheckJ(j.status, LEARN_SAMPLE_LIFECYCLE_V2.TRAINED);
|
|
682
|
+
const now = Date.now();
|
|
683
|
+
j.status = LEARN_SAMPLE_LIFECYCLE_V2.TRAINED;
|
|
684
|
+
j.updatedAt = now;
|
|
685
|
+
if (!j.settledAt) j.settledAt = now;
|
|
686
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
687
|
+
}
|
|
688
|
+
export function failLearnSampleV2(id, reason) {
|
|
689
|
+
const j = _learnJsV2.get(id);
|
|
690
|
+
if (!j) throw new Error(`learn sample ${id} not found`);
|
|
691
|
+
_learnCheckJ(j.status, LEARN_SAMPLE_LIFECYCLE_V2.FAILED);
|
|
692
|
+
const now = Date.now();
|
|
693
|
+
j.status = LEARN_SAMPLE_LIFECYCLE_V2.FAILED;
|
|
694
|
+
j.updatedAt = now;
|
|
695
|
+
if (!j.settledAt) j.settledAt = now;
|
|
696
|
+
if (reason) j.metadata.failReason = String(reason);
|
|
697
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
698
|
+
}
|
|
699
|
+
export function cancelLearnSampleV2(id, reason) {
|
|
700
|
+
const j = _learnJsV2.get(id);
|
|
701
|
+
if (!j) throw new Error(`learn sample ${id} not found`);
|
|
702
|
+
_learnCheckJ(j.status, LEARN_SAMPLE_LIFECYCLE_V2.CANCELLED);
|
|
703
|
+
const now = Date.now();
|
|
704
|
+
j.status = LEARN_SAMPLE_LIFECYCLE_V2.CANCELLED;
|
|
705
|
+
j.updatedAt = now;
|
|
706
|
+
if (!j.settledAt) j.settledAt = now;
|
|
707
|
+
if (reason) j.metadata.cancelReason = String(reason);
|
|
708
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
709
|
+
}
|
|
710
|
+
export function getLearnSampleV2(id) {
|
|
711
|
+
const j = _learnJsV2.get(id);
|
|
712
|
+
if (!j) return null;
|
|
713
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
714
|
+
}
|
|
715
|
+
export function listLearnSamplesV2() {
|
|
716
|
+
return [..._learnJsV2.values()].map((j) => ({
|
|
717
|
+
...j,
|
|
718
|
+
metadata: { ...j.metadata },
|
|
719
|
+
}));
|
|
720
|
+
}
|
|
721
|
+
export function autoStaleIdleLearnProfilesV2({ now } = {}) {
|
|
722
|
+
const t = now ?? Date.now();
|
|
723
|
+
const flipped = [];
|
|
724
|
+
for (const p of _learnPsV2.values())
|
|
725
|
+
if (
|
|
726
|
+
p.status === LEARN_PROFILE_MATURITY_V2.ACTIVE &&
|
|
727
|
+
t - p.lastTouchedAt >= _learnIdleMs
|
|
728
|
+
) {
|
|
729
|
+
p.status = LEARN_PROFILE_MATURITY_V2.STALE;
|
|
730
|
+
p.updatedAt = t;
|
|
731
|
+
flipped.push(p.id);
|
|
732
|
+
}
|
|
733
|
+
return { flipped, count: flipped.length };
|
|
734
|
+
}
|
|
735
|
+
export function autoFailStuckLearnSamplesV2({ now } = {}) {
|
|
736
|
+
const t = now ?? Date.now();
|
|
737
|
+
const flipped = [];
|
|
738
|
+
for (const j of _learnJsV2.values())
|
|
739
|
+
if (
|
|
740
|
+
j.status === LEARN_SAMPLE_LIFECYCLE_V2.TRAINING &&
|
|
741
|
+
j.startedAt != null &&
|
|
742
|
+
t - j.startedAt >= _learnStuckMs
|
|
743
|
+
) {
|
|
744
|
+
j.status = LEARN_SAMPLE_LIFECYCLE_V2.FAILED;
|
|
745
|
+
j.updatedAt = t;
|
|
746
|
+
if (!j.settledAt) j.settledAt = t;
|
|
747
|
+
j.metadata.failReason = "auto-fail-stuck";
|
|
748
|
+
flipped.push(j.id);
|
|
749
|
+
}
|
|
750
|
+
return { flipped, count: flipped.length };
|
|
751
|
+
}
|
|
752
|
+
export function getCoworkLearningGovStatsV2() {
|
|
753
|
+
const profilesByStatus = {};
|
|
754
|
+
for (const v of Object.values(LEARN_PROFILE_MATURITY_V2))
|
|
755
|
+
profilesByStatus[v] = 0;
|
|
756
|
+
for (const p of _learnPsV2.values()) profilesByStatus[p.status]++;
|
|
757
|
+
const samplesByStatus = {};
|
|
758
|
+
for (const v of Object.values(LEARN_SAMPLE_LIFECYCLE_V2))
|
|
759
|
+
samplesByStatus[v] = 0;
|
|
760
|
+
for (const j of _learnJsV2.values()) samplesByStatus[j.status]++;
|
|
761
|
+
return {
|
|
762
|
+
totalLearnProfilesV2: _learnPsV2.size,
|
|
763
|
+
totalLearnSamplesV2: _learnJsV2.size,
|
|
764
|
+
maxActiveLearnProfilesPerOwner: _learnMaxActive,
|
|
765
|
+
maxPendingLearnSamplesPerProfile: _learnMaxPending,
|
|
766
|
+
learnProfileIdleMs: _learnIdleMs,
|
|
767
|
+
learnSampleStuckMs: _learnStuckMs,
|
|
768
|
+
profilesByStatus,
|
|
769
|
+
samplesByStatus,
|
|
770
|
+
};
|
|
771
|
+
}
|