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
|
@@ -569,3 +569,342 @@ export function _resetStateNoteVersioningV2() {
|
|
|
569
569
|
_noteIdleMsV2 = NOTE_DEFAULT_NOTE_IDLE_MS;
|
|
570
570
|
_revStuckMsV2 = NOTE_DEFAULT_REV_STUCK_MS;
|
|
571
571
|
}
|
|
572
|
+
|
|
573
|
+
// =====================================================================
|
|
574
|
+
// note-versioning V2 governance overlay (iter23)
|
|
575
|
+
// =====================================================================
|
|
576
|
+
export const NTGOV_PROFILE_MATURITY_V2 = Object.freeze({
|
|
577
|
+
PENDING: "pending",
|
|
578
|
+
ACTIVE: "active",
|
|
579
|
+
STALE: "stale",
|
|
580
|
+
ARCHIVED: "archived",
|
|
581
|
+
});
|
|
582
|
+
export const NTGOV_REVISION_LIFECYCLE_V2 = Object.freeze({
|
|
583
|
+
QUEUED: "queued",
|
|
584
|
+
REVIEWING: "reviewing",
|
|
585
|
+
MERGED: "merged",
|
|
586
|
+
FAILED: "failed",
|
|
587
|
+
CANCELLED: "cancelled",
|
|
588
|
+
});
|
|
589
|
+
const _ntgovPTrans = new Map([
|
|
590
|
+
[
|
|
591
|
+
NTGOV_PROFILE_MATURITY_V2.PENDING,
|
|
592
|
+
new Set([
|
|
593
|
+
NTGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
594
|
+
NTGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
595
|
+
]),
|
|
596
|
+
],
|
|
597
|
+
[
|
|
598
|
+
NTGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
599
|
+
new Set([
|
|
600
|
+
NTGOV_PROFILE_MATURITY_V2.STALE,
|
|
601
|
+
NTGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
602
|
+
]),
|
|
603
|
+
],
|
|
604
|
+
[
|
|
605
|
+
NTGOV_PROFILE_MATURITY_V2.STALE,
|
|
606
|
+
new Set([
|
|
607
|
+
NTGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
608
|
+
NTGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
609
|
+
]),
|
|
610
|
+
],
|
|
611
|
+
[NTGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
|
|
612
|
+
]);
|
|
613
|
+
const _ntgovPTerminal = new Set([NTGOV_PROFILE_MATURITY_V2.ARCHIVED]);
|
|
614
|
+
const _ntgovJTrans = new Map([
|
|
615
|
+
[
|
|
616
|
+
NTGOV_REVISION_LIFECYCLE_V2.QUEUED,
|
|
617
|
+
new Set([
|
|
618
|
+
NTGOV_REVISION_LIFECYCLE_V2.REVIEWING,
|
|
619
|
+
NTGOV_REVISION_LIFECYCLE_V2.CANCELLED,
|
|
620
|
+
]),
|
|
621
|
+
],
|
|
622
|
+
[
|
|
623
|
+
NTGOV_REVISION_LIFECYCLE_V2.REVIEWING,
|
|
624
|
+
new Set([
|
|
625
|
+
NTGOV_REVISION_LIFECYCLE_V2.MERGED,
|
|
626
|
+
NTGOV_REVISION_LIFECYCLE_V2.FAILED,
|
|
627
|
+
NTGOV_REVISION_LIFECYCLE_V2.CANCELLED,
|
|
628
|
+
]),
|
|
629
|
+
],
|
|
630
|
+
[NTGOV_REVISION_LIFECYCLE_V2.MERGED, new Set()],
|
|
631
|
+
[NTGOV_REVISION_LIFECYCLE_V2.FAILED, new Set()],
|
|
632
|
+
[NTGOV_REVISION_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
633
|
+
]);
|
|
634
|
+
const _ntgovPsV2 = new Map();
|
|
635
|
+
const _ntgovJsV2 = new Map();
|
|
636
|
+
let _ntgovMaxActive = 10,
|
|
637
|
+
_ntgovMaxPending = 30,
|
|
638
|
+
_ntgovIdleMs = 30 * 24 * 60 * 60 * 1000,
|
|
639
|
+
_ntgovStuckMs = 60 * 1000;
|
|
640
|
+
function _ntgovPos(n, label) {
|
|
641
|
+
const v = Math.floor(Number(n));
|
|
642
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
643
|
+
throw new Error(`${label} must be positive integer`);
|
|
644
|
+
return v;
|
|
645
|
+
}
|
|
646
|
+
function _ntgovCheckP(from, to) {
|
|
647
|
+
const a = _ntgovPTrans.get(from);
|
|
648
|
+
if (!a || !a.has(to))
|
|
649
|
+
throw new Error(`invalid ntgov profile transition ${from} → ${to}`);
|
|
650
|
+
}
|
|
651
|
+
function _ntgovCheckJ(from, to) {
|
|
652
|
+
const a = _ntgovJTrans.get(from);
|
|
653
|
+
if (!a || !a.has(to))
|
|
654
|
+
throw new Error(`invalid ntgov revision transition ${from} → ${to}`);
|
|
655
|
+
}
|
|
656
|
+
function _ntgovCountActive(owner) {
|
|
657
|
+
let c = 0;
|
|
658
|
+
for (const p of _ntgovPsV2.values())
|
|
659
|
+
if (p.owner === owner && p.status === NTGOV_PROFILE_MATURITY_V2.ACTIVE) c++;
|
|
660
|
+
return c;
|
|
661
|
+
}
|
|
662
|
+
function _ntgovCountPending(profileId) {
|
|
663
|
+
let c = 0;
|
|
664
|
+
for (const j of _ntgovJsV2.values())
|
|
665
|
+
if (
|
|
666
|
+
j.profileId === profileId &&
|
|
667
|
+
(j.status === NTGOV_REVISION_LIFECYCLE_V2.QUEUED ||
|
|
668
|
+
j.status === NTGOV_REVISION_LIFECYCLE_V2.REVIEWING)
|
|
669
|
+
)
|
|
670
|
+
c++;
|
|
671
|
+
return c;
|
|
672
|
+
}
|
|
673
|
+
export function setMaxActiveNtgovProfilesPerOwnerV2(n) {
|
|
674
|
+
_ntgovMaxActive = _ntgovPos(n, "maxActiveNtgovProfilesPerOwner");
|
|
675
|
+
}
|
|
676
|
+
export function getMaxActiveNtgovProfilesPerOwnerV2() {
|
|
677
|
+
return _ntgovMaxActive;
|
|
678
|
+
}
|
|
679
|
+
export function setMaxPendingNtgovRevisionsPerProfileV2(n) {
|
|
680
|
+
_ntgovMaxPending = _ntgovPos(n, "maxPendingNtgovRevisionsPerProfile");
|
|
681
|
+
}
|
|
682
|
+
export function getMaxPendingNtgovRevisionsPerProfileV2() {
|
|
683
|
+
return _ntgovMaxPending;
|
|
684
|
+
}
|
|
685
|
+
export function setNtgovProfileIdleMsV2(n) {
|
|
686
|
+
_ntgovIdleMs = _ntgovPos(n, "ntgovProfileIdleMs");
|
|
687
|
+
}
|
|
688
|
+
export function getNtgovProfileIdleMsV2() {
|
|
689
|
+
return _ntgovIdleMs;
|
|
690
|
+
}
|
|
691
|
+
export function setNtgovRevisionStuckMsV2(n) {
|
|
692
|
+
_ntgovStuckMs = _ntgovPos(n, "ntgovRevisionStuckMs");
|
|
693
|
+
}
|
|
694
|
+
export function getNtgovRevisionStuckMsV2() {
|
|
695
|
+
return _ntgovStuckMs;
|
|
696
|
+
}
|
|
697
|
+
export function _resetStateNoteVersioningGovV2() {
|
|
698
|
+
_ntgovPsV2.clear();
|
|
699
|
+
_ntgovJsV2.clear();
|
|
700
|
+
_ntgovMaxActive = 10;
|
|
701
|
+
_ntgovMaxPending = 30;
|
|
702
|
+
_ntgovIdleMs = 30 * 24 * 60 * 60 * 1000;
|
|
703
|
+
_ntgovStuckMs = 60 * 1000;
|
|
704
|
+
}
|
|
705
|
+
export function registerNtgovProfileV2({ id, owner, series, metadata } = {}) {
|
|
706
|
+
if (!id || !owner) throw new Error("id and owner required");
|
|
707
|
+
if (_ntgovPsV2.has(id)) throw new Error(`ntgov profile ${id} already exists`);
|
|
708
|
+
const now = Date.now();
|
|
709
|
+
const p = {
|
|
710
|
+
id,
|
|
711
|
+
owner,
|
|
712
|
+
series: series || "default",
|
|
713
|
+
status: NTGOV_PROFILE_MATURITY_V2.PENDING,
|
|
714
|
+
createdAt: now,
|
|
715
|
+
updatedAt: now,
|
|
716
|
+
lastTouchedAt: now,
|
|
717
|
+
activatedAt: null,
|
|
718
|
+
archivedAt: null,
|
|
719
|
+
metadata: { ...(metadata || {}) },
|
|
720
|
+
};
|
|
721
|
+
_ntgovPsV2.set(id, p);
|
|
722
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
723
|
+
}
|
|
724
|
+
export function activateNtgovProfileV2(id) {
|
|
725
|
+
const p = _ntgovPsV2.get(id);
|
|
726
|
+
if (!p) throw new Error(`ntgov profile ${id} not found`);
|
|
727
|
+
const isInitial = p.status === NTGOV_PROFILE_MATURITY_V2.PENDING;
|
|
728
|
+
_ntgovCheckP(p.status, NTGOV_PROFILE_MATURITY_V2.ACTIVE);
|
|
729
|
+
if (isInitial && _ntgovCountActive(p.owner) >= _ntgovMaxActive)
|
|
730
|
+
throw new Error(`max active ntgov profiles for owner ${p.owner} reached`);
|
|
731
|
+
const now = Date.now();
|
|
732
|
+
p.status = NTGOV_PROFILE_MATURITY_V2.ACTIVE;
|
|
733
|
+
p.updatedAt = now;
|
|
734
|
+
p.lastTouchedAt = now;
|
|
735
|
+
if (!p.activatedAt) p.activatedAt = now;
|
|
736
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
737
|
+
}
|
|
738
|
+
export function staleNtgovProfileV2(id) {
|
|
739
|
+
const p = _ntgovPsV2.get(id);
|
|
740
|
+
if (!p) throw new Error(`ntgov profile ${id} not found`);
|
|
741
|
+
_ntgovCheckP(p.status, NTGOV_PROFILE_MATURITY_V2.STALE);
|
|
742
|
+
p.status = NTGOV_PROFILE_MATURITY_V2.STALE;
|
|
743
|
+
p.updatedAt = Date.now();
|
|
744
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
745
|
+
}
|
|
746
|
+
export function archiveNtgovProfileV2(id) {
|
|
747
|
+
const p = _ntgovPsV2.get(id);
|
|
748
|
+
if (!p) throw new Error(`ntgov profile ${id} not found`);
|
|
749
|
+
_ntgovCheckP(p.status, NTGOV_PROFILE_MATURITY_V2.ARCHIVED);
|
|
750
|
+
const now = Date.now();
|
|
751
|
+
p.status = NTGOV_PROFILE_MATURITY_V2.ARCHIVED;
|
|
752
|
+
p.updatedAt = now;
|
|
753
|
+
if (!p.archivedAt) p.archivedAt = now;
|
|
754
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
755
|
+
}
|
|
756
|
+
export function touchNtgovProfileV2(id) {
|
|
757
|
+
const p = _ntgovPsV2.get(id);
|
|
758
|
+
if (!p) throw new Error(`ntgov profile ${id} not found`);
|
|
759
|
+
if (_ntgovPTerminal.has(p.status))
|
|
760
|
+
throw new Error(`cannot touch terminal ntgov profile ${id}`);
|
|
761
|
+
const now = Date.now();
|
|
762
|
+
p.lastTouchedAt = now;
|
|
763
|
+
p.updatedAt = now;
|
|
764
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
765
|
+
}
|
|
766
|
+
export function getNtgovProfileV2(id) {
|
|
767
|
+
const p = _ntgovPsV2.get(id);
|
|
768
|
+
if (!p) return null;
|
|
769
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
770
|
+
}
|
|
771
|
+
export function listNtgovProfilesV2() {
|
|
772
|
+
return [..._ntgovPsV2.values()].map((p) => ({
|
|
773
|
+
...p,
|
|
774
|
+
metadata: { ...p.metadata },
|
|
775
|
+
}));
|
|
776
|
+
}
|
|
777
|
+
export function createNtgovRevisionV2({
|
|
778
|
+
id,
|
|
779
|
+
profileId,
|
|
780
|
+
author,
|
|
781
|
+
metadata,
|
|
782
|
+
} = {}) {
|
|
783
|
+
if (!id || !profileId) throw new Error("id and profileId required");
|
|
784
|
+
if (_ntgovJsV2.has(id))
|
|
785
|
+
throw new Error(`ntgov revision ${id} already exists`);
|
|
786
|
+
if (!_ntgovPsV2.has(profileId))
|
|
787
|
+
throw new Error(`ntgov profile ${profileId} not found`);
|
|
788
|
+
if (_ntgovCountPending(profileId) >= _ntgovMaxPending)
|
|
789
|
+
throw new Error(
|
|
790
|
+
`max pending ntgov revisions for profile ${profileId} reached`,
|
|
791
|
+
);
|
|
792
|
+
const now = Date.now();
|
|
793
|
+
const j = {
|
|
794
|
+
id,
|
|
795
|
+
profileId,
|
|
796
|
+
author: author || "",
|
|
797
|
+
status: NTGOV_REVISION_LIFECYCLE_V2.QUEUED,
|
|
798
|
+
createdAt: now,
|
|
799
|
+
updatedAt: now,
|
|
800
|
+
startedAt: null,
|
|
801
|
+
settledAt: null,
|
|
802
|
+
metadata: { ...(metadata || {}) },
|
|
803
|
+
};
|
|
804
|
+
_ntgovJsV2.set(id, j);
|
|
805
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
806
|
+
}
|
|
807
|
+
export function reviewingNtgovRevisionV2(id) {
|
|
808
|
+
const j = _ntgovJsV2.get(id);
|
|
809
|
+
if (!j) throw new Error(`ntgov revision ${id} not found`);
|
|
810
|
+
_ntgovCheckJ(j.status, NTGOV_REVISION_LIFECYCLE_V2.REVIEWING);
|
|
811
|
+
const now = Date.now();
|
|
812
|
+
j.status = NTGOV_REVISION_LIFECYCLE_V2.REVIEWING;
|
|
813
|
+
j.updatedAt = now;
|
|
814
|
+
if (!j.startedAt) j.startedAt = now;
|
|
815
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
816
|
+
}
|
|
817
|
+
export function completeRevisionNtgovV2(id) {
|
|
818
|
+
const j = _ntgovJsV2.get(id);
|
|
819
|
+
if (!j) throw new Error(`ntgov revision ${id} not found`);
|
|
820
|
+
_ntgovCheckJ(j.status, NTGOV_REVISION_LIFECYCLE_V2.MERGED);
|
|
821
|
+
const now = Date.now();
|
|
822
|
+
j.status = NTGOV_REVISION_LIFECYCLE_V2.MERGED;
|
|
823
|
+
j.updatedAt = now;
|
|
824
|
+
if (!j.settledAt) j.settledAt = now;
|
|
825
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
826
|
+
}
|
|
827
|
+
export function failNtgovRevisionV2(id, reason) {
|
|
828
|
+
const j = _ntgovJsV2.get(id);
|
|
829
|
+
if (!j) throw new Error(`ntgov revision ${id} not found`);
|
|
830
|
+
_ntgovCheckJ(j.status, NTGOV_REVISION_LIFECYCLE_V2.FAILED);
|
|
831
|
+
const now = Date.now();
|
|
832
|
+
j.status = NTGOV_REVISION_LIFECYCLE_V2.FAILED;
|
|
833
|
+
j.updatedAt = now;
|
|
834
|
+
if (!j.settledAt) j.settledAt = now;
|
|
835
|
+
if (reason) j.metadata.failReason = String(reason);
|
|
836
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
837
|
+
}
|
|
838
|
+
export function cancelNtgovRevisionV2(id, reason) {
|
|
839
|
+
const j = _ntgovJsV2.get(id);
|
|
840
|
+
if (!j) throw new Error(`ntgov revision ${id} not found`);
|
|
841
|
+
_ntgovCheckJ(j.status, NTGOV_REVISION_LIFECYCLE_V2.CANCELLED);
|
|
842
|
+
const now = Date.now();
|
|
843
|
+
j.status = NTGOV_REVISION_LIFECYCLE_V2.CANCELLED;
|
|
844
|
+
j.updatedAt = now;
|
|
845
|
+
if (!j.settledAt) j.settledAt = now;
|
|
846
|
+
if (reason) j.metadata.cancelReason = String(reason);
|
|
847
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
848
|
+
}
|
|
849
|
+
export function getNtgovRevisionV2(id) {
|
|
850
|
+
const j = _ntgovJsV2.get(id);
|
|
851
|
+
if (!j) return null;
|
|
852
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
853
|
+
}
|
|
854
|
+
export function listNtgovRevisionsV2() {
|
|
855
|
+
return [..._ntgovJsV2.values()].map((j) => ({
|
|
856
|
+
...j,
|
|
857
|
+
metadata: { ...j.metadata },
|
|
858
|
+
}));
|
|
859
|
+
}
|
|
860
|
+
export function autoStaleIdleNtgovProfilesV2({ now } = {}) {
|
|
861
|
+
const t = now ?? Date.now();
|
|
862
|
+
const flipped = [];
|
|
863
|
+
for (const p of _ntgovPsV2.values())
|
|
864
|
+
if (
|
|
865
|
+
p.status === NTGOV_PROFILE_MATURITY_V2.ACTIVE &&
|
|
866
|
+
t - p.lastTouchedAt >= _ntgovIdleMs
|
|
867
|
+
) {
|
|
868
|
+
p.status = NTGOV_PROFILE_MATURITY_V2.STALE;
|
|
869
|
+
p.updatedAt = t;
|
|
870
|
+
flipped.push(p.id);
|
|
871
|
+
}
|
|
872
|
+
return { flipped, count: flipped.length };
|
|
873
|
+
}
|
|
874
|
+
export function autoFailStuckNtgovRevisionsV2({ now } = {}) {
|
|
875
|
+
const t = now ?? Date.now();
|
|
876
|
+
const flipped = [];
|
|
877
|
+
for (const j of _ntgovJsV2.values())
|
|
878
|
+
if (
|
|
879
|
+
j.status === NTGOV_REVISION_LIFECYCLE_V2.REVIEWING &&
|
|
880
|
+
j.startedAt != null &&
|
|
881
|
+
t - j.startedAt >= _ntgovStuckMs
|
|
882
|
+
) {
|
|
883
|
+
j.status = NTGOV_REVISION_LIFECYCLE_V2.FAILED;
|
|
884
|
+
j.updatedAt = t;
|
|
885
|
+
if (!j.settledAt) j.settledAt = t;
|
|
886
|
+
j.metadata.failReason = "auto-fail-stuck";
|
|
887
|
+
flipped.push(j.id);
|
|
888
|
+
}
|
|
889
|
+
return { flipped, count: flipped.length };
|
|
890
|
+
}
|
|
891
|
+
export function getNoteVersioningGovStatsV2() {
|
|
892
|
+
const profilesByStatus = {};
|
|
893
|
+
for (const v of Object.values(NTGOV_PROFILE_MATURITY_V2))
|
|
894
|
+
profilesByStatus[v] = 0;
|
|
895
|
+
for (const p of _ntgovPsV2.values()) profilesByStatus[p.status]++;
|
|
896
|
+
const revisionsByStatus = {};
|
|
897
|
+
for (const v of Object.values(NTGOV_REVISION_LIFECYCLE_V2))
|
|
898
|
+
revisionsByStatus[v] = 0;
|
|
899
|
+
for (const j of _ntgovJsV2.values()) revisionsByStatus[j.status]++;
|
|
900
|
+
return {
|
|
901
|
+
totalNtgovProfilesV2: _ntgovPsV2.size,
|
|
902
|
+
totalNtgovRevisionsV2: _ntgovJsV2.size,
|
|
903
|
+
maxActiveNtgovProfilesPerOwner: _ntgovMaxActive,
|
|
904
|
+
maxPendingNtgovRevisionsPerProfile: _ntgovMaxPending,
|
|
905
|
+
ntgovProfileIdleMs: _ntgovIdleMs,
|
|
906
|
+
ntgovRevisionStuckMs: _ntgovStuckMs,
|
|
907
|
+
profilesByStatus,
|
|
908
|
+
revisionsByStatus,
|
|
909
|
+
};
|
|
910
|
+
}
|