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
|
@@ -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
|
+
}
|
package/src/lib/cowork-share.js
CHANGED
|
@@ -320,3 +320,341 @@ export function importResultPacket(cwd, packet) {
|
|
|
320
320
|
_deps.writeFileSync(file, JSON.stringify(packet, null, 2), "utf-8");
|
|
321
321
|
return { file, taskId: packet.payload.taskId };
|
|
322
322
|
}
|
|
323
|
+
|
|
324
|
+
// =====================================================================
|
|
325
|
+
// cowork-share V2 governance overlay (iter22)
|
|
326
|
+
// =====================================================================
|
|
327
|
+
export const SHGOV_PROFILE_MATURITY_V2 = Object.freeze({
|
|
328
|
+
PENDING: "pending",
|
|
329
|
+
ACTIVE: "active",
|
|
330
|
+
PAUSED: "paused",
|
|
331
|
+
ARCHIVED: "archived",
|
|
332
|
+
});
|
|
333
|
+
export const SHGOV_SHARE_LIFECYCLE_V2 = Object.freeze({
|
|
334
|
+
QUEUED: "queued",
|
|
335
|
+
SHARING: "sharing",
|
|
336
|
+
SHARED: "shared",
|
|
337
|
+
FAILED: "failed",
|
|
338
|
+
CANCELLED: "cancelled",
|
|
339
|
+
});
|
|
340
|
+
const _shgovPTrans = new Map([
|
|
341
|
+
[
|
|
342
|
+
SHGOV_PROFILE_MATURITY_V2.PENDING,
|
|
343
|
+
new Set([
|
|
344
|
+
SHGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
345
|
+
SHGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
346
|
+
]),
|
|
347
|
+
],
|
|
348
|
+
[
|
|
349
|
+
SHGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
350
|
+
new Set([
|
|
351
|
+
SHGOV_PROFILE_MATURITY_V2.PAUSED,
|
|
352
|
+
SHGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
353
|
+
]),
|
|
354
|
+
],
|
|
355
|
+
[
|
|
356
|
+
SHGOV_PROFILE_MATURITY_V2.PAUSED,
|
|
357
|
+
new Set([
|
|
358
|
+
SHGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
359
|
+
SHGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
360
|
+
]),
|
|
361
|
+
],
|
|
362
|
+
[SHGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
|
|
363
|
+
]);
|
|
364
|
+
const _shgovPTerminal = new Set([SHGOV_PROFILE_MATURITY_V2.ARCHIVED]);
|
|
365
|
+
const _shgovJTrans = new Map([
|
|
366
|
+
[
|
|
367
|
+
SHGOV_SHARE_LIFECYCLE_V2.QUEUED,
|
|
368
|
+
new Set([
|
|
369
|
+
SHGOV_SHARE_LIFECYCLE_V2.SHARING,
|
|
370
|
+
SHGOV_SHARE_LIFECYCLE_V2.CANCELLED,
|
|
371
|
+
]),
|
|
372
|
+
],
|
|
373
|
+
[
|
|
374
|
+
SHGOV_SHARE_LIFECYCLE_V2.SHARING,
|
|
375
|
+
new Set([
|
|
376
|
+
SHGOV_SHARE_LIFECYCLE_V2.SHARED,
|
|
377
|
+
SHGOV_SHARE_LIFECYCLE_V2.FAILED,
|
|
378
|
+
SHGOV_SHARE_LIFECYCLE_V2.CANCELLED,
|
|
379
|
+
]),
|
|
380
|
+
],
|
|
381
|
+
[SHGOV_SHARE_LIFECYCLE_V2.SHARED, new Set()],
|
|
382
|
+
[SHGOV_SHARE_LIFECYCLE_V2.FAILED, new Set()],
|
|
383
|
+
[SHGOV_SHARE_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
384
|
+
]);
|
|
385
|
+
const _shgovPsV2 = new Map();
|
|
386
|
+
const _shgovJsV2 = new Map();
|
|
387
|
+
let _shgovMaxActive = 8,
|
|
388
|
+
_shgovMaxPending = 20,
|
|
389
|
+
_shgovIdleMs = 30 * 24 * 60 * 60 * 1000,
|
|
390
|
+
_shgovStuckMs = 60 * 1000;
|
|
391
|
+
function _shgovPos(n, label) {
|
|
392
|
+
const v = Math.floor(Number(n));
|
|
393
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
394
|
+
throw new Error(`${label} must be positive integer`);
|
|
395
|
+
return v;
|
|
396
|
+
}
|
|
397
|
+
function _shgovCheckP(from, to) {
|
|
398
|
+
const a = _shgovPTrans.get(from);
|
|
399
|
+
if (!a || !a.has(to))
|
|
400
|
+
throw new Error(`invalid shgov profile transition ${from} → ${to}`);
|
|
401
|
+
}
|
|
402
|
+
function _shgovCheckJ(from, to) {
|
|
403
|
+
const a = _shgovJTrans.get(from);
|
|
404
|
+
if (!a || !a.has(to))
|
|
405
|
+
throw new Error(`invalid shgov share transition ${from} → ${to}`);
|
|
406
|
+
}
|
|
407
|
+
function _shgovCountActive(owner) {
|
|
408
|
+
let c = 0;
|
|
409
|
+
for (const p of _shgovPsV2.values())
|
|
410
|
+
if (p.owner === owner && p.status === SHGOV_PROFILE_MATURITY_V2.ACTIVE) c++;
|
|
411
|
+
return c;
|
|
412
|
+
}
|
|
413
|
+
function _shgovCountPending(profileId) {
|
|
414
|
+
let c = 0;
|
|
415
|
+
for (const j of _shgovJsV2.values())
|
|
416
|
+
if (
|
|
417
|
+
j.profileId === profileId &&
|
|
418
|
+
(j.status === SHGOV_SHARE_LIFECYCLE_V2.QUEUED ||
|
|
419
|
+
j.status === SHGOV_SHARE_LIFECYCLE_V2.SHARING)
|
|
420
|
+
)
|
|
421
|
+
c++;
|
|
422
|
+
return c;
|
|
423
|
+
}
|
|
424
|
+
export function setMaxActiveShgovProfilesPerOwnerV2(n) {
|
|
425
|
+
_shgovMaxActive = _shgovPos(n, "maxActiveShgovProfilesPerOwner");
|
|
426
|
+
}
|
|
427
|
+
export function getMaxActiveShgovProfilesPerOwnerV2() {
|
|
428
|
+
return _shgovMaxActive;
|
|
429
|
+
}
|
|
430
|
+
export function setMaxPendingShgovSharesPerProfileV2(n) {
|
|
431
|
+
_shgovMaxPending = _shgovPos(n, "maxPendingShgovSharesPerProfile");
|
|
432
|
+
}
|
|
433
|
+
export function getMaxPendingShgovSharesPerProfileV2() {
|
|
434
|
+
return _shgovMaxPending;
|
|
435
|
+
}
|
|
436
|
+
export function setShgovProfileIdleMsV2(n) {
|
|
437
|
+
_shgovIdleMs = _shgovPos(n, "shgovProfileIdleMs");
|
|
438
|
+
}
|
|
439
|
+
export function getShgovProfileIdleMsV2() {
|
|
440
|
+
return _shgovIdleMs;
|
|
441
|
+
}
|
|
442
|
+
export function setShgovShareStuckMsV2(n) {
|
|
443
|
+
_shgovStuckMs = _shgovPos(n, "shgovShareStuckMs");
|
|
444
|
+
}
|
|
445
|
+
export function getShgovShareStuckMsV2() {
|
|
446
|
+
return _shgovStuckMs;
|
|
447
|
+
}
|
|
448
|
+
export function _resetStateCoworkShareGovV2() {
|
|
449
|
+
_shgovPsV2.clear();
|
|
450
|
+
_shgovJsV2.clear();
|
|
451
|
+
_shgovMaxActive = 8;
|
|
452
|
+
_shgovMaxPending = 20;
|
|
453
|
+
_shgovIdleMs = 30 * 24 * 60 * 60 * 1000;
|
|
454
|
+
_shgovStuckMs = 60 * 1000;
|
|
455
|
+
}
|
|
456
|
+
export function registerShgovProfileV2({
|
|
457
|
+
id,
|
|
458
|
+
owner,
|
|
459
|
+
visibility,
|
|
460
|
+
metadata,
|
|
461
|
+
} = {}) {
|
|
462
|
+
if (!id || !owner) throw new Error("id and owner required");
|
|
463
|
+
if (_shgovPsV2.has(id)) throw new Error(`shgov profile ${id} already exists`);
|
|
464
|
+
const now = Date.now();
|
|
465
|
+
const p = {
|
|
466
|
+
id,
|
|
467
|
+
owner,
|
|
468
|
+
visibility: visibility || "private",
|
|
469
|
+
status: SHGOV_PROFILE_MATURITY_V2.PENDING,
|
|
470
|
+
createdAt: now,
|
|
471
|
+
updatedAt: now,
|
|
472
|
+
lastTouchedAt: now,
|
|
473
|
+
activatedAt: null,
|
|
474
|
+
archivedAt: null,
|
|
475
|
+
metadata: { ...(metadata || {}) },
|
|
476
|
+
};
|
|
477
|
+
_shgovPsV2.set(id, p);
|
|
478
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
479
|
+
}
|
|
480
|
+
export function activateShgovProfileV2(id) {
|
|
481
|
+
const p = _shgovPsV2.get(id);
|
|
482
|
+
if (!p) throw new Error(`shgov profile ${id} not found`);
|
|
483
|
+
const isInitial = p.status === SHGOV_PROFILE_MATURITY_V2.PENDING;
|
|
484
|
+
_shgovCheckP(p.status, SHGOV_PROFILE_MATURITY_V2.ACTIVE);
|
|
485
|
+
if (isInitial && _shgovCountActive(p.owner) >= _shgovMaxActive)
|
|
486
|
+
throw new Error(`max active shgov profiles for owner ${p.owner} reached`);
|
|
487
|
+
const now = Date.now();
|
|
488
|
+
p.status = SHGOV_PROFILE_MATURITY_V2.ACTIVE;
|
|
489
|
+
p.updatedAt = now;
|
|
490
|
+
p.lastTouchedAt = now;
|
|
491
|
+
if (!p.activatedAt) p.activatedAt = now;
|
|
492
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
493
|
+
}
|
|
494
|
+
export function pauseShgovProfileV2(id) {
|
|
495
|
+
const p = _shgovPsV2.get(id);
|
|
496
|
+
if (!p) throw new Error(`shgov profile ${id} not found`);
|
|
497
|
+
_shgovCheckP(p.status, SHGOV_PROFILE_MATURITY_V2.PAUSED);
|
|
498
|
+
p.status = SHGOV_PROFILE_MATURITY_V2.PAUSED;
|
|
499
|
+
p.updatedAt = Date.now();
|
|
500
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
501
|
+
}
|
|
502
|
+
export function archiveShgovProfileV2(id) {
|
|
503
|
+
const p = _shgovPsV2.get(id);
|
|
504
|
+
if (!p) throw new Error(`shgov profile ${id} not found`);
|
|
505
|
+
_shgovCheckP(p.status, SHGOV_PROFILE_MATURITY_V2.ARCHIVED);
|
|
506
|
+
const now = Date.now();
|
|
507
|
+
p.status = SHGOV_PROFILE_MATURITY_V2.ARCHIVED;
|
|
508
|
+
p.updatedAt = now;
|
|
509
|
+
if (!p.archivedAt) p.archivedAt = now;
|
|
510
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
511
|
+
}
|
|
512
|
+
export function touchShgovProfileV2(id) {
|
|
513
|
+
const p = _shgovPsV2.get(id);
|
|
514
|
+
if (!p) throw new Error(`shgov profile ${id} not found`);
|
|
515
|
+
if (_shgovPTerminal.has(p.status))
|
|
516
|
+
throw new Error(`cannot touch terminal shgov profile ${id}`);
|
|
517
|
+
const now = Date.now();
|
|
518
|
+
p.lastTouchedAt = now;
|
|
519
|
+
p.updatedAt = now;
|
|
520
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
521
|
+
}
|
|
522
|
+
export function getShgovProfileV2(id) {
|
|
523
|
+
const p = _shgovPsV2.get(id);
|
|
524
|
+
if (!p) return null;
|
|
525
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
526
|
+
}
|
|
527
|
+
export function listShgovProfilesV2() {
|
|
528
|
+
return [..._shgovPsV2.values()].map((p) => ({
|
|
529
|
+
...p,
|
|
530
|
+
metadata: { ...p.metadata },
|
|
531
|
+
}));
|
|
532
|
+
}
|
|
533
|
+
export function createShgovShareV2({ id, profileId, target, metadata } = {}) {
|
|
534
|
+
if (!id || !profileId) throw new Error("id and profileId required");
|
|
535
|
+
if (_shgovJsV2.has(id)) throw new Error(`shgov share ${id} already exists`);
|
|
536
|
+
if (!_shgovPsV2.has(profileId))
|
|
537
|
+
throw new Error(`shgov profile ${profileId} not found`);
|
|
538
|
+
if (_shgovCountPending(profileId) >= _shgovMaxPending)
|
|
539
|
+
throw new Error(
|
|
540
|
+
`max pending shgov shares for profile ${profileId} reached`,
|
|
541
|
+
);
|
|
542
|
+
const now = Date.now();
|
|
543
|
+
const j = {
|
|
544
|
+
id,
|
|
545
|
+
profileId,
|
|
546
|
+
target: target || "",
|
|
547
|
+
status: SHGOV_SHARE_LIFECYCLE_V2.QUEUED,
|
|
548
|
+
createdAt: now,
|
|
549
|
+
updatedAt: now,
|
|
550
|
+
startedAt: null,
|
|
551
|
+
settledAt: null,
|
|
552
|
+
metadata: { ...(metadata || {}) },
|
|
553
|
+
};
|
|
554
|
+
_shgovJsV2.set(id, j);
|
|
555
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
556
|
+
}
|
|
557
|
+
export function sharingShgovShareV2(id) {
|
|
558
|
+
const j = _shgovJsV2.get(id);
|
|
559
|
+
if (!j) throw new Error(`shgov share ${id} not found`);
|
|
560
|
+
_shgovCheckJ(j.status, SHGOV_SHARE_LIFECYCLE_V2.SHARING);
|
|
561
|
+
const now = Date.now();
|
|
562
|
+
j.status = SHGOV_SHARE_LIFECYCLE_V2.SHARING;
|
|
563
|
+
j.updatedAt = now;
|
|
564
|
+
if (!j.startedAt) j.startedAt = now;
|
|
565
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
566
|
+
}
|
|
567
|
+
export function completeShareShgovV2(id) {
|
|
568
|
+
const j = _shgovJsV2.get(id);
|
|
569
|
+
if (!j) throw new Error(`shgov share ${id} not found`);
|
|
570
|
+
_shgovCheckJ(j.status, SHGOV_SHARE_LIFECYCLE_V2.SHARED);
|
|
571
|
+
const now = Date.now();
|
|
572
|
+
j.status = SHGOV_SHARE_LIFECYCLE_V2.SHARED;
|
|
573
|
+
j.updatedAt = now;
|
|
574
|
+
if (!j.settledAt) j.settledAt = now;
|
|
575
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
576
|
+
}
|
|
577
|
+
export function failShgovShareV2(id, reason) {
|
|
578
|
+
const j = _shgovJsV2.get(id);
|
|
579
|
+
if (!j) throw new Error(`shgov share ${id} not found`);
|
|
580
|
+
_shgovCheckJ(j.status, SHGOV_SHARE_LIFECYCLE_V2.FAILED);
|
|
581
|
+
const now = Date.now();
|
|
582
|
+
j.status = SHGOV_SHARE_LIFECYCLE_V2.FAILED;
|
|
583
|
+
j.updatedAt = now;
|
|
584
|
+
if (!j.settledAt) j.settledAt = now;
|
|
585
|
+
if (reason) j.metadata.failReason = String(reason);
|
|
586
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
587
|
+
}
|
|
588
|
+
export function cancelShgovShareV2(id, reason) {
|
|
589
|
+
const j = _shgovJsV2.get(id);
|
|
590
|
+
if (!j) throw new Error(`shgov share ${id} not found`);
|
|
591
|
+
_shgovCheckJ(j.status, SHGOV_SHARE_LIFECYCLE_V2.CANCELLED);
|
|
592
|
+
const now = Date.now();
|
|
593
|
+
j.status = SHGOV_SHARE_LIFECYCLE_V2.CANCELLED;
|
|
594
|
+
j.updatedAt = now;
|
|
595
|
+
if (!j.settledAt) j.settledAt = now;
|
|
596
|
+
if (reason) j.metadata.cancelReason = String(reason);
|
|
597
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
598
|
+
}
|
|
599
|
+
export function getShgovShareV2(id) {
|
|
600
|
+
const j = _shgovJsV2.get(id);
|
|
601
|
+
if (!j) return null;
|
|
602
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
603
|
+
}
|
|
604
|
+
export function listShgovSharesV2() {
|
|
605
|
+
return [..._shgovJsV2.values()].map((j) => ({
|
|
606
|
+
...j,
|
|
607
|
+
metadata: { ...j.metadata },
|
|
608
|
+
}));
|
|
609
|
+
}
|
|
610
|
+
export function autoPauseIdleShgovProfilesV2({ now } = {}) {
|
|
611
|
+
const t = now ?? Date.now();
|
|
612
|
+
const flipped = [];
|
|
613
|
+
for (const p of _shgovPsV2.values())
|
|
614
|
+
if (
|
|
615
|
+
p.status === SHGOV_PROFILE_MATURITY_V2.ACTIVE &&
|
|
616
|
+
t - p.lastTouchedAt >= _shgovIdleMs
|
|
617
|
+
) {
|
|
618
|
+
p.status = SHGOV_PROFILE_MATURITY_V2.PAUSED;
|
|
619
|
+
p.updatedAt = t;
|
|
620
|
+
flipped.push(p.id);
|
|
621
|
+
}
|
|
622
|
+
return { flipped, count: flipped.length };
|
|
623
|
+
}
|
|
624
|
+
export function autoFailStuckShgovSharesV2({ now } = {}) {
|
|
625
|
+
const t = now ?? Date.now();
|
|
626
|
+
const flipped = [];
|
|
627
|
+
for (const j of _shgovJsV2.values())
|
|
628
|
+
if (
|
|
629
|
+
j.status === SHGOV_SHARE_LIFECYCLE_V2.SHARING &&
|
|
630
|
+
j.startedAt != null &&
|
|
631
|
+
t - j.startedAt >= _shgovStuckMs
|
|
632
|
+
) {
|
|
633
|
+
j.status = SHGOV_SHARE_LIFECYCLE_V2.FAILED;
|
|
634
|
+
j.updatedAt = t;
|
|
635
|
+
if (!j.settledAt) j.settledAt = t;
|
|
636
|
+
j.metadata.failReason = "auto-fail-stuck";
|
|
637
|
+
flipped.push(j.id);
|
|
638
|
+
}
|
|
639
|
+
return { flipped, count: flipped.length };
|
|
640
|
+
}
|
|
641
|
+
export function getCoworkShareGovStatsV2() {
|
|
642
|
+
const profilesByStatus = {};
|
|
643
|
+
for (const v of Object.values(SHGOV_PROFILE_MATURITY_V2))
|
|
644
|
+
profilesByStatus[v] = 0;
|
|
645
|
+
for (const p of _shgovPsV2.values()) profilesByStatus[p.status]++;
|
|
646
|
+
const sharesByStatus = {};
|
|
647
|
+
for (const v of Object.values(SHGOV_SHARE_LIFECYCLE_V2))
|
|
648
|
+
sharesByStatus[v] = 0;
|
|
649
|
+
for (const j of _shgovJsV2.values()) sharesByStatus[j.status]++;
|
|
650
|
+
return {
|
|
651
|
+
totalShgovProfilesV2: _shgovPsV2.size,
|
|
652
|
+
totalShgovSharesV2: _shgovJsV2.size,
|
|
653
|
+
maxActiveShgovProfilesPerOwner: _shgovMaxActive,
|
|
654
|
+
maxPendingShgovSharesPerProfile: _shgovMaxPending,
|
|
655
|
+
shgovProfileIdleMs: _shgovIdleMs,
|
|
656
|
+
shgovShareStuckMs: _shgovStuckMs,
|
|
657
|
+
profilesByStatus,
|
|
658
|
+
sharesByStatus,
|
|
659
|
+
};
|
|
660
|
+
}
|