chainlesschain 0.152.0 → 0.156.2
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/README.md +52 -3
- package/package.json +1 -1
- package/src/commands/a2a.js +201 -0
- package/src/commands/agent.js +1250 -0
- package/src/commands/chat.js +605 -0
- package/src/commands/cli-anything.js +426 -0
- package/src/commands/compliance.js +412 -0
- package/src/commands/config.js +213 -0
- package/src/commands/cowork.js +1463 -0
- package/src/commands/crosschain.js +203 -0
- package/src/commands/dao.js +203 -0
- package/src/commands/economy.js +199 -0
- package/src/commands/encrypt.js +201 -0
- package/src/commands/evolution.js +199 -0
- package/src/commands/evomap.js +625 -0
- package/src/commands/hmemory.js +203 -0
- package/src/commands/inference.js +207 -0
- package/src/commands/kg.js +195 -0
- package/src/commands/llm.js +209 -0
- package/src/commands/memory.js +203 -0
- package/src/commands/orchestrate.js +406 -0
- package/src/commands/pipeline.js +199 -0
- package/src/commands/planmode.js +426 -0
- package/src/commands/plugin.js +209 -0
- package/src/commands/services.js +207 -0
- package/src/commands/setup.js +205 -0
- package/src/commands/skill.js +207 -0
- package/src/commands/start.js +209 -0
- package/src/commands/stream.js +213 -0
- package/src/commands/ui.js +225 -0
- package/src/commands/workflow.js +209 -0
- package/src/index.js +112 -0
- package/src/lib/a2a-protocol.js +332 -0
- package/src/lib/agent-coordinator.js +334 -0
- package/src/lib/agent-economy.js +334 -0
- package/src/lib/agent-router.js +333 -0
- package/src/lib/autonomous-agent.js +332 -0
- package/src/lib/chat-core.js +335 -0
- package/src/lib/cli-anything-bridge.js +341 -0
- package/src/lib/cli-context-engineering.js +351 -0
- package/src/lib/compliance-manager.js +334 -0
- package/src/lib/cowork-adapter.js +336 -0
- package/src/lib/cowork-evomap-adapter.js +341 -0
- package/src/lib/cowork-mcp-tools.js +341 -0
- package/src/lib/cowork-observe-html.js +341 -0
- package/src/lib/cowork-observe.js +341 -0
- package/src/lib/cowork-task-templates.js +342 -1
- package/src/lib/cowork-template-marketplace.js +340 -0
- package/src/lib/cross-chain.js +339 -0
- package/src/lib/crypto-manager.js +334 -0
- package/src/lib/dao-governance.js +339 -0
- package/src/lib/downloader.js +334 -0
- package/src/lib/evolution-system.js +334 -0
- package/src/lib/evomap-client.js +342 -0
- package/src/lib/evomap-federation.js +338 -0
- package/src/lib/evomap-manager.js +330 -0
- package/src/lib/execution-backend.js +330 -0
- package/src/lib/hashline.js +338 -0
- package/src/lib/hierarchical-memory.js +334 -0
- package/src/lib/inference-network.js +341 -0
- package/src/lib/interaction-adapter.js +330 -0
- package/src/lib/interactive-planner.js +354 -0
- package/src/lib/knowledge-graph.js +331 -0
- package/src/lib/pipeline-orchestrator.js +332 -0
- package/src/lib/plan-mode.js +336 -0
- package/src/lib/plugin-autodiscovery.js +334 -0
- package/src/lib/process-manager.js +336 -0
- package/src/lib/provider-options.js +346 -0
- package/src/lib/provider-stream.js +348 -0
- package/src/lib/service-manager.js +337 -0
- package/src/lib/session-core-singletons.js +341 -0
- package/src/lib/skill-mcp.js +336 -0
- package/src/lib/stix-parser.js +346 -0
- package/src/lib/sub-agent-context.js +343 -0
- package/src/lib/sub-agent-profiles.js +335 -0
- package/src/lib/sub-agent-registry.js +336 -0
- package/src/lib/todo-manager.js +336 -0
- package/src/lib/web-ui-server.js +348 -0
- package/src/lib/workflow-expr.js +346 -0
- package/src/lib/ws-chat-handler.js +337 -0
|
@@ -577,3 +577,339 @@ export function getSubAgentRegistryStatsV2() {
|
|
|
577
577
|
tasksByStatus,
|
|
578
578
|
};
|
|
579
579
|
}
|
|
580
|
+
|
|
581
|
+
// =====================================================================
|
|
582
|
+
// sub-agent-registry V2 governance overlay (iter25)
|
|
583
|
+
// =====================================================================
|
|
584
|
+
export const SAREGOV_PROFILE_MATURITY_V2 = Object.freeze({
|
|
585
|
+
PENDING: "pending",
|
|
586
|
+
ACTIVE: "active",
|
|
587
|
+
SUSPENDED: "suspended",
|
|
588
|
+
ARCHIVED: "archived",
|
|
589
|
+
});
|
|
590
|
+
export const SAREGOV_SPAWN_LIFECYCLE_V2 = Object.freeze({
|
|
591
|
+
QUEUED: "queued",
|
|
592
|
+
SPAWNING: "spawning",
|
|
593
|
+
SPAWNED: "spawned",
|
|
594
|
+
FAILED: "failed",
|
|
595
|
+
CANCELLED: "cancelled",
|
|
596
|
+
});
|
|
597
|
+
const _saregovPTrans = new Map([
|
|
598
|
+
[
|
|
599
|
+
SAREGOV_PROFILE_MATURITY_V2.PENDING,
|
|
600
|
+
new Set([
|
|
601
|
+
SAREGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
602
|
+
SAREGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
603
|
+
]),
|
|
604
|
+
],
|
|
605
|
+
[
|
|
606
|
+
SAREGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
607
|
+
new Set([
|
|
608
|
+
SAREGOV_PROFILE_MATURITY_V2.SUSPENDED,
|
|
609
|
+
SAREGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
610
|
+
]),
|
|
611
|
+
],
|
|
612
|
+
[
|
|
613
|
+
SAREGOV_PROFILE_MATURITY_V2.SUSPENDED,
|
|
614
|
+
new Set([
|
|
615
|
+
SAREGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
616
|
+
SAREGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
617
|
+
]),
|
|
618
|
+
],
|
|
619
|
+
[SAREGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
|
|
620
|
+
]);
|
|
621
|
+
const _saregovPTerminal = new Set([SAREGOV_PROFILE_MATURITY_V2.ARCHIVED]);
|
|
622
|
+
const _saregovJTrans = new Map([
|
|
623
|
+
[
|
|
624
|
+
SAREGOV_SPAWN_LIFECYCLE_V2.QUEUED,
|
|
625
|
+
new Set([
|
|
626
|
+
SAREGOV_SPAWN_LIFECYCLE_V2.SPAWNING,
|
|
627
|
+
SAREGOV_SPAWN_LIFECYCLE_V2.CANCELLED,
|
|
628
|
+
]),
|
|
629
|
+
],
|
|
630
|
+
[
|
|
631
|
+
SAREGOV_SPAWN_LIFECYCLE_V2.SPAWNING,
|
|
632
|
+
new Set([
|
|
633
|
+
SAREGOV_SPAWN_LIFECYCLE_V2.SPAWNED,
|
|
634
|
+
SAREGOV_SPAWN_LIFECYCLE_V2.FAILED,
|
|
635
|
+
SAREGOV_SPAWN_LIFECYCLE_V2.CANCELLED,
|
|
636
|
+
]),
|
|
637
|
+
],
|
|
638
|
+
[SAREGOV_SPAWN_LIFECYCLE_V2.SPAWNED, new Set()],
|
|
639
|
+
[SAREGOV_SPAWN_LIFECYCLE_V2.FAILED, new Set()],
|
|
640
|
+
[SAREGOV_SPAWN_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
641
|
+
]);
|
|
642
|
+
const _saregovPsV2 = new Map();
|
|
643
|
+
const _saregovJsV2 = new Map();
|
|
644
|
+
let _saregovMaxActive = 10,
|
|
645
|
+
_saregovMaxPending = 25,
|
|
646
|
+
_saregovIdleMs = 30 * 24 * 60 * 60 * 1000,
|
|
647
|
+
_saregovStuckMs = 60 * 1000;
|
|
648
|
+
function _saregovPos(n, label) {
|
|
649
|
+
const v = Math.floor(Number(n));
|
|
650
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
651
|
+
throw new Error(`${label} must be positive integer`);
|
|
652
|
+
return v;
|
|
653
|
+
}
|
|
654
|
+
function _saregovCheckP(from, to) {
|
|
655
|
+
const a = _saregovPTrans.get(from);
|
|
656
|
+
if (!a || !a.has(to))
|
|
657
|
+
throw new Error(`invalid saregov profile transition ${from} → ${to}`);
|
|
658
|
+
}
|
|
659
|
+
function _saregovCheckJ(from, to) {
|
|
660
|
+
const a = _saregovJTrans.get(from);
|
|
661
|
+
if (!a || !a.has(to))
|
|
662
|
+
throw new Error(`invalid saregov spawn transition ${from} → ${to}`);
|
|
663
|
+
}
|
|
664
|
+
function _saregovCountActive(owner) {
|
|
665
|
+
let c = 0;
|
|
666
|
+
for (const p of _saregovPsV2.values())
|
|
667
|
+
if (p.owner === owner && p.status === SAREGOV_PROFILE_MATURITY_V2.ACTIVE)
|
|
668
|
+
c++;
|
|
669
|
+
return c;
|
|
670
|
+
}
|
|
671
|
+
function _saregovCountPending(profileId) {
|
|
672
|
+
let c = 0;
|
|
673
|
+
for (const j of _saregovJsV2.values())
|
|
674
|
+
if (
|
|
675
|
+
j.profileId === profileId &&
|
|
676
|
+
(j.status === SAREGOV_SPAWN_LIFECYCLE_V2.QUEUED ||
|
|
677
|
+
j.status === SAREGOV_SPAWN_LIFECYCLE_V2.SPAWNING)
|
|
678
|
+
)
|
|
679
|
+
c++;
|
|
680
|
+
return c;
|
|
681
|
+
}
|
|
682
|
+
export function setMaxActiveSaregovProfilesPerOwnerV2(n) {
|
|
683
|
+
_saregovMaxActive = _saregovPos(n, "maxActiveSaregovProfilesPerOwner");
|
|
684
|
+
}
|
|
685
|
+
export function getMaxActiveSaregovProfilesPerOwnerV2() {
|
|
686
|
+
return _saregovMaxActive;
|
|
687
|
+
}
|
|
688
|
+
export function setMaxPendingSaregovSpawnsPerProfileV2(n) {
|
|
689
|
+
_saregovMaxPending = _saregovPos(n, "maxPendingSaregovSpawnsPerProfile");
|
|
690
|
+
}
|
|
691
|
+
export function getMaxPendingSaregovSpawnsPerProfileV2() {
|
|
692
|
+
return _saregovMaxPending;
|
|
693
|
+
}
|
|
694
|
+
export function setSaregovProfileIdleMsV2(n) {
|
|
695
|
+
_saregovIdleMs = _saregovPos(n, "saregovProfileIdleMs");
|
|
696
|
+
}
|
|
697
|
+
export function getSaregovProfileIdleMsV2() {
|
|
698
|
+
return _saregovIdleMs;
|
|
699
|
+
}
|
|
700
|
+
export function setSaregovSpawnStuckMsV2(n) {
|
|
701
|
+
_saregovStuckMs = _saregovPos(n, "saregovSpawnStuckMs");
|
|
702
|
+
}
|
|
703
|
+
export function getSaregovSpawnStuckMsV2() {
|
|
704
|
+
return _saregovStuckMs;
|
|
705
|
+
}
|
|
706
|
+
export function _resetStateSubAgentRegistryGovV2() {
|
|
707
|
+
_saregovPsV2.clear();
|
|
708
|
+
_saregovJsV2.clear();
|
|
709
|
+
_saregovMaxActive = 10;
|
|
710
|
+
_saregovMaxPending = 25;
|
|
711
|
+
_saregovIdleMs = 30 * 24 * 60 * 60 * 1000;
|
|
712
|
+
_saregovStuckMs = 60 * 1000;
|
|
713
|
+
}
|
|
714
|
+
export function registerSaregovProfileV2({ id, owner, kind, metadata } = {}) {
|
|
715
|
+
if (!id || !owner) throw new Error("id and owner required");
|
|
716
|
+
if (_saregovPsV2.has(id))
|
|
717
|
+
throw new Error(`saregov profile ${id} already exists`);
|
|
718
|
+
const now = Date.now();
|
|
719
|
+
const p = {
|
|
720
|
+
id,
|
|
721
|
+
owner,
|
|
722
|
+
kind: kind || "general",
|
|
723
|
+
status: SAREGOV_PROFILE_MATURITY_V2.PENDING,
|
|
724
|
+
createdAt: now,
|
|
725
|
+
updatedAt: now,
|
|
726
|
+
lastTouchedAt: now,
|
|
727
|
+
activatedAt: null,
|
|
728
|
+
archivedAt: null,
|
|
729
|
+
metadata: { ...(metadata || {}) },
|
|
730
|
+
};
|
|
731
|
+
_saregovPsV2.set(id, p);
|
|
732
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
733
|
+
}
|
|
734
|
+
export function activateSaregovProfileV2(id) {
|
|
735
|
+
const p = _saregovPsV2.get(id);
|
|
736
|
+
if (!p) throw new Error(`saregov profile ${id} not found`);
|
|
737
|
+
const isInitial = p.status === SAREGOV_PROFILE_MATURITY_V2.PENDING;
|
|
738
|
+
_saregovCheckP(p.status, SAREGOV_PROFILE_MATURITY_V2.ACTIVE);
|
|
739
|
+
if (isInitial && _saregovCountActive(p.owner) >= _saregovMaxActive)
|
|
740
|
+
throw new Error(`max active saregov profiles for owner ${p.owner} reached`);
|
|
741
|
+
const now = Date.now();
|
|
742
|
+
p.status = SAREGOV_PROFILE_MATURITY_V2.ACTIVE;
|
|
743
|
+
p.updatedAt = now;
|
|
744
|
+
p.lastTouchedAt = now;
|
|
745
|
+
if (!p.activatedAt) p.activatedAt = now;
|
|
746
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
747
|
+
}
|
|
748
|
+
export function suspendSaregovProfileV2(id) {
|
|
749
|
+
const p = _saregovPsV2.get(id);
|
|
750
|
+
if (!p) throw new Error(`saregov profile ${id} not found`);
|
|
751
|
+
_saregovCheckP(p.status, SAREGOV_PROFILE_MATURITY_V2.SUSPENDED);
|
|
752
|
+
p.status = SAREGOV_PROFILE_MATURITY_V2.SUSPENDED;
|
|
753
|
+
p.updatedAt = Date.now();
|
|
754
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
755
|
+
}
|
|
756
|
+
export function archiveSaregovProfileV2(id) {
|
|
757
|
+
const p = _saregovPsV2.get(id);
|
|
758
|
+
if (!p) throw new Error(`saregov profile ${id} not found`);
|
|
759
|
+
_saregovCheckP(p.status, SAREGOV_PROFILE_MATURITY_V2.ARCHIVED);
|
|
760
|
+
const now = Date.now();
|
|
761
|
+
p.status = SAREGOV_PROFILE_MATURITY_V2.ARCHIVED;
|
|
762
|
+
p.updatedAt = now;
|
|
763
|
+
if (!p.archivedAt) p.archivedAt = now;
|
|
764
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
765
|
+
}
|
|
766
|
+
export function touchSaregovProfileV2(id) {
|
|
767
|
+
const p = _saregovPsV2.get(id);
|
|
768
|
+
if (!p) throw new Error(`saregov profile ${id} not found`);
|
|
769
|
+
if (_saregovPTerminal.has(p.status))
|
|
770
|
+
throw new Error(`cannot touch terminal saregov profile ${id}`);
|
|
771
|
+
const now = Date.now();
|
|
772
|
+
p.lastTouchedAt = now;
|
|
773
|
+
p.updatedAt = now;
|
|
774
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
775
|
+
}
|
|
776
|
+
export function getSaregovProfileV2(id) {
|
|
777
|
+
const p = _saregovPsV2.get(id);
|
|
778
|
+
if (!p) return null;
|
|
779
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
780
|
+
}
|
|
781
|
+
export function listSaregovProfilesV2() {
|
|
782
|
+
return [..._saregovPsV2.values()].map((p) => ({
|
|
783
|
+
...p,
|
|
784
|
+
metadata: { ...p.metadata },
|
|
785
|
+
}));
|
|
786
|
+
}
|
|
787
|
+
export function createSaregovSpawnV2({ id, profileId, task, metadata } = {}) {
|
|
788
|
+
if (!id || !profileId) throw new Error("id and profileId required");
|
|
789
|
+
if (_saregovJsV2.has(id))
|
|
790
|
+
throw new Error(`saregov spawn ${id} already exists`);
|
|
791
|
+
if (!_saregovPsV2.has(profileId))
|
|
792
|
+
throw new Error(`saregov profile ${profileId} not found`);
|
|
793
|
+
if (_saregovCountPending(profileId) >= _saregovMaxPending)
|
|
794
|
+
throw new Error(
|
|
795
|
+
`max pending saregov spawns for profile ${profileId} reached`,
|
|
796
|
+
);
|
|
797
|
+
const now = Date.now();
|
|
798
|
+
const j = {
|
|
799
|
+
id,
|
|
800
|
+
profileId,
|
|
801
|
+
task: task || "",
|
|
802
|
+
status: SAREGOV_SPAWN_LIFECYCLE_V2.QUEUED,
|
|
803
|
+
createdAt: now,
|
|
804
|
+
updatedAt: now,
|
|
805
|
+
startedAt: null,
|
|
806
|
+
settledAt: null,
|
|
807
|
+
metadata: { ...(metadata || {}) },
|
|
808
|
+
};
|
|
809
|
+
_saregovJsV2.set(id, j);
|
|
810
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
811
|
+
}
|
|
812
|
+
export function spawningSaregovSpawnV2(id) {
|
|
813
|
+
const j = _saregovJsV2.get(id);
|
|
814
|
+
if (!j) throw new Error(`saregov spawn ${id} not found`);
|
|
815
|
+
_saregovCheckJ(j.status, SAREGOV_SPAWN_LIFECYCLE_V2.SPAWNING);
|
|
816
|
+
const now = Date.now();
|
|
817
|
+
j.status = SAREGOV_SPAWN_LIFECYCLE_V2.SPAWNING;
|
|
818
|
+
j.updatedAt = now;
|
|
819
|
+
if (!j.startedAt) j.startedAt = now;
|
|
820
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
821
|
+
}
|
|
822
|
+
export function completeSpawnSaregovV2(id) {
|
|
823
|
+
const j = _saregovJsV2.get(id);
|
|
824
|
+
if (!j) throw new Error(`saregov spawn ${id} not found`);
|
|
825
|
+
_saregovCheckJ(j.status, SAREGOV_SPAWN_LIFECYCLE_V2.SPAWNED);
|
|
826
|
+
const now = Date.now();
|
|
827
|
+
j.status = SAREGOV_SPAWN_LIFECYCLE_V2.SPAWNED;
|
|
828
|
+
j.updatedAt = now;
|
|
829
|
+
if (!j.settledAt) j.settledAt = now;
|
|
830
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
831
|
+
}
|
|
832
|
+
export function failSaregovSpawnV2(id, reason) {
|
|
833
|
+
const j = _saregovJsV2.get(id);
|
|
834
|
+
if (!j) throw new Error(`saregov spawn ${id} not found`);
|
|
835
|
+
_saregovCheckJ(j.status, SAREGOV_SPAWN_LIFECYCLE_V2.FAILED);
|
|
836
|
+
const now = Date.now();
|
|
837
|
+
j.status = SAREGOV_SPAWN_LIFECYCLE_V2.FAILED;
|
|
838
|
+
j.updatedAt = now;
|
|
839
|
+
if (!j.settledAt) j.settledAt = now;
|
|
840
|
+
if (reason) j.metadata.failReason = String(reason);
|
|
841
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
842
|
+
}
|
|
843
|
+
export function cancelSaregovSpawnV2(id, reason) {
|
|
844
|
+
const j = _saregovJsV2.get(id);
|
|
845
|
+
if (!j) throw new Error(`saregov spawn ${id} not found`);
|
|
846
|
+
_saregovCheckJ(j.status, SAREGOV_SPAWN_LIFECYCLE_V2.CANCELLED);
|
|
847
|
+
const now = Date.now();
|
|
848
|
+
j.status = SAREGOV_SPAWN_LIFECYCLE_V2.CANCELLED;
|
|
849
|
+
j.updatedAt = now;
|
|
850
|
+
if (!j.settledAt) j.settledAt = now;
|
|
851
|
+
if (reason) j.metadata.cancelReason = String(reason);
|
|
852
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
853
|
+
}
|
|
854
|
+
export function getSaregovSpawnV2(id) {
|
|
855
|
+
const j = _saregovJsV2.get(id);
|
|
856
|
+
if (!j) return null;
|
|
857
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
858
|
+
}
|
|
859
|
+
export function listSaregovSpawnsV2() {
|
|
860
|
+
return [..._saregovJsV2.values()].map((j) => ({
|
|
861
|
+
...j,
|
|
862
|
+
metadata: { ...j.metadata },
|
|
863
|
+
}));
|
|
864
|
+
}
|
|
865
|
+
export function autoSuspendIdleSaregovProfilesV2({ now } = {}) {
|
|
866
|
+
const t = now ?? Date.now();
|
|
867
|
+
const flipped = [];
|
|
868
|
+
for (const p of _saregovPsV2.values())
|
|
869
|
+
if (
|
|
870
|
+
p.status === SAREGOV_PROFILE_MATURITY_V2.ACTIVE &&
|
|
871
|
+
t - p.lastTouchedAt >= _saregovIdleMs
|
|
872
|
+
) {
|
|
873
|
+
p.status = SAREGOV_PROFILE_MATURITY_V2.SUSPENDED;
|
|
874
|
+
p.updatedAt = t;
|
|
875
|
+
flipped.push(p.id);
|
|
876
|
+
}
|
|
877
|
+
return { flipped, count: flipped.length };
|
|
878
|
+
}
|
|
879
|
+
export function autoFailStuckSaregovSpawnsV2({ now } = {}) {
|
|
880
|
+
const t = now ?? Date.now();
|
|
881
|
+
const flipped = [];
|
|
882
|
+
for (const j of _saregovJsV2.values())
|
|
883
|
+
if (
|
|
884
|
+
j.status === SAREGOV_SPAWN_LIFECYCLE_V2.SPAWNING &&
|
|
885
|
+
j.startedAt != null &&
|
|
886
|
+
t - j.startedAt >= _saregovStuckMs
|
|
887
|
+
) {
|
|
888
|
+
j.status = SAREGOV_SPAWN_LIFECYCLE_V2.FAILED;
|
|
889
|
+
j.updatedAt = t;
|
|
890
|
+
if (!j.settledAt) j.settledAt = t;
|
|
891
|
+
j.metadata.failReason = "auto-fail-stuck";
|
|
892
|
+
flipped.push(j.id);
|
|
893
|
+
}
|
|
894
|
+
return { flipped, count: flipped.length };
|
|
895
|
+
}
|
|
896
|
+
export function getSubAgentRegistryGovStatsV2() {
|
|
897
|
+
const profilesByStatus = {};
|
|
898
|
+
for (const v of Object.values(SAREGOV_PROFILE_MATURITY_V2))
|
|
899
|
+
profilesByStatus[v] = 0;
|
|
900
|
+
for (const p of _saregovPsV2.values()) profilesByStatus[p.status]++;
|
|
901
|
+
const spawnsByStatus = {};
|
|
902
|
+
for (const v of Object.values(SAREGOV_SPAWN_LIFECYCLE_V2))
|
|
903
|
+
spawnsByStatus[v] = 0;
|
|
904
|
+
for (const j of _saregovJsV2.values()) spawnsByStatus[j.status]++;
|
|
905
|
+
return {
|
|
906
|
+
totalSaregovProfilesV2: _saregovPsV2.size,
|
|
907
|
+
totalSaregovSpawnsV2: _saregovJsV2.size,
|
|
908
|
+
maxActiveSaregovProfilesPerOwner: _saregovMaxActive,
|
|
909
|
+
maxPendingSaregovSpawnsPerProfile: _saregovMaxPending,
|
|
910
|
+
saregovProfileIdleMs: _saregovIdleMs,
|
|
911
|
+
saregovSpawnStuckMs: _saregovStuckMs,
|
|
912
|
+
profilesByStatus,
|
|
913
|
+
spawnsByStatus,
|
|
914
|
+
};
|
|
915
|
+
}
|
package/src/lib/todo-manager.js
CHANGED
|
@@ -445,3 +445,339 @@ export function getTodoManagerStatsV2() {
|
|
|
445
445
|
itemsByStatus,
|
|
446
446
|
};
|
|
447
447
|
}
|
|
448
|
+
|
|
449
|
+
// =====================================================================
|
|
450
|
+
// todo-manager V2 governance overlay (iter25)
|
|
451
|
+
// =====================================================================
|
|
452
|
+
export const TODOGOV_PROFILE_MATURITY_V2 = Object.freeze({
|
|
453
|
+
PENDING: "pending",
|
|
454
|
+
ACTIVE: "active",
|
|
455
|
+
PAUSED: "paused",
|
|
456
|
+
ARCHIVED: "archived",
|
|
457
|
+
});
|
|
458
|
+
export const TODOGOV_STEP_LIFECYCLE_V2 = Object.freeze({
|
|
459
|
+
QUEUED: "queued",
|
|
460
|
+
DOING: "doing",
|
|
461
|
+
DONE: "done",
|
|
462
|
+
FAILED: "failed",
|
|
463
|
+
CANCELLED: "cancelled",
|
|
464
|
+
});
|
|
465
|
+
const _todogovPTrans = new Map([
|
|
466
|
+
[
|
|
467
|
+
TODOGOV_PROFILE_MATURITY_V2.PENDING,
|
|
468
|
+
new Set([
|
|
469
|
+
TODOGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
470
|
+
TODOGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
471
|
+
]),
|
|
472
|
+
],
|
|
473
|
+
[
|
|
474
|
+
TODOGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
475
|
+
new Set([
|
|
476
|
+
TODOGOV_PROFILE_MATURITY_V2.PAUSED,
|
|
477
|
+
TODOGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
478
|
+
]),
|
|
479
|
+
],
|
|
480
|
+
[
|
|
481
|
+
TODOGOV_PROFILE_MATURITY_V2.PAUSED,
|
|
482
|
+
new Set([
|
|
483
|
+
TODOGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
484
|
+
TODOGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
485
|
+
]),
|
|
486
|
+
],
|
|
487
|
+
[TODOGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
|
|
488
|
+
]);
|
|
489
|
+
const _todogovPTerminal = new Set([TODOGOV_PROFILE_MATURITY_V2.ARCHIVED]);
|
|
490
|
+
const _todogovJTrans = new Map([
|
|
491
|
+
[
|
|
492
|
+
TODOGOV_STEP_LIFECYCLE_V2.QUEUED,
|
|
493
|
+
new Set([
|
|
494
|
+
TODOGOV_STEP_LIFECYCLE_V2.DOING,
|
|
495
|
+
TODOGOV_STEP_LIFECYCLE_V2.CANCELLED,
|
|
496
|
+
]),
|
|
497
|
+
],
|
|
498
|
+
[
|
|
499
|
+
TODOGOV_STEP_LIFECYCLE_V2.DOING,
|
|
500
|
+
new Set([
|
|
501
|
+
TODOGOV_STEP_LIFECYCLE_V2.DONE,
|
|
502
|
+
TODOGOV_STEP_LIFECYCLE_V2.FAILED,
|
|
503
|
+
TODOGOV_STEP_LIFECYCLE_V2.CANCELLED,
|
|
504
|
+
]),
|
|
505
|
+
],
|
|
506
|
+
[TODOGOV_STEP_LIFECYCLE_V2.DONE, new Set()],
|
|
507
|
+
[TODOGOV_STEP_LIFECYCLE_V2.FAILED, new Set()],
|
|
508
|
+
[TODOGOV_STEP_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
509
|
+
]);
|
|
510
|
+
const _todogovPsV2 = new Map();
|
|
511
|
+
const _todogovJsV2 = new Map();
|
|
512
|
+
let _todogovMaxActive = 10,
|
|
513
|
+
_todogovMaxPending = 30,
|
|
514
|
+
_todogovIdleMs = 30 * 24 * 60 * 60 * 1000,
|
|
515
|
+
_todogovStuckMs = 60 * 1000;
|
|
516
|
+
function _todogovPos(n, label) {
|
|
517
|
+
const v = Math.floor(Number(n));
|
|
518
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
519
|
+
throw new Error(`${label} must be positive integer`);
|
|
520
|
+
return v;
|
|
521
|
+
}
|
|
522
|
+
function _todogovCheckP(from, to) {
|
|
523
|
+
const a = _todogovPTrans.get(from);
|
|
524
|
+
if (!a || !a.has(to))
|
|
525
|
+
throw new Error(`invalid todogov profile transition ${from} → ${to}`);
|
|
526
|
+
}
|
|
527
|
+
function _todogovCheckJ(from, to) {
|
|
528
|
+
const a = _todogovJTrans.get(from);
|
|
529
|
+
if (!a || !a.has(to))
|
|
530
|
+
throw new Error(`invalid todogov step transition ${from} → ${to}`);
|
|
531
|
+
}
|
|
532
|
+
function _todogovCountActive(owner) {
|
|
533
|
+
let c = 0;
|
|
534
|
+
for (const p of _todogovPsV2.values())
|
|
535
|
+
if (p.owner === owner && p.status === TODOGOV_PROFILE_MATURITY_V2.ACTIVE)
|
|
536
|
+
c++;
|
|
537
|
+
return c;
|
|
538
|
+
}
|
|
539
|
+
function _todogovCountPending(profileId) {
|
|
540
|
+
let c = 0;
|
|
541
|
+
for (const j of _todogovJsV2.values())
|
|
542
|
+
if (
|
|
543
|
+
j.profileId === profileId &&
|
|
544
|
+
(j.status === TODOGOV_STEP_LIFECYCLE_V2.QUEUED ||
|
|
545
|
+
j.status === TODOGOV_STEP_LIFECYCLE_V2.DOING)
|
|
546
|
+
)
|
|
547
|
+
c++;
|
|
548
|
+
return c;
|
|
549
|
+
}
|
|
550
|
+
export function setMaxActiveTodogovProfilesPerOwnerV2(n) {
|
|
551
|
+
_todogovMaxActive = _todogovPos(n, "maxActiveTodogovProfilesPerOwner");
|
|
552
|
+
}
|
|
553
|
+
export function getMaxActiveTodogovProfilesPerOwnerV2() {
|
|
554
|
+
return _todogovMaxActive;
|
|
555
|
+
}
|
|
556
|
+
export function setMaxPendingTodogovStepsPerProfileV2(n) {
|
|
557
|
+
_todogovMaxPending = _todogovPos(n, "maxPendingTodogovStepsPerProfile");
|
|
558
|
+
}
|
|
559
|
+
export function getMaxPendingTodogovStepsPerProfileV2() {
|
|
560
|
+
return _todogovMaxPending;
|
|
561
|
+
}
|
|
562
|
+
export function setTodogovProfileIdleMsV2(n) {
|
|
563
|
+
_todogovIdleMs = _todogovPos(n, "todogovProfileIdleMs");
|
|
564
|
+
}
|
|
565
|
+
export function getTodogovProfileIdleMsV2() {
|
|
566
|
+
return _todogovIdleMs;
|
|
567
|
+
}
|
|
568
|
+
export function setTodogovStepStuckMsV2(n) {
|
|
569
|
+
_todogovStuckMs = _todogovPos(n, "todogovStepStuckMs");
|
|
570
|
+
}
|
|
571
|
+
export function getTodogovStepStuckMsV2() {
|
|
572
|
+
return _todogovStuckMs;
|
|
573
|
+
}
|
|
574
|
+
export function _resetStateTodoManagerGovV2() {
|
|
575
|
+
_todogovPsV2.clear();
|
|
576
|
+
_todogovJsV2.clear();
|
|
577
|
+
_todogovMaxActive = 10;
|
|
578
|
+
_todogovMaxPending = 30;
|
|
579
|
+
_todogovIdleMs = 30 * 24 * 60 * 60 * 1000;
|
|
580
|
+
_todogovStuckMs = 60 * 1000;
|
|
581
|
+
}
|
|
582
|
+
export function registerTodogovProfileV2({ id, owner, list, metadata } = {}) {
|
|
583
|
+
if (!id || !owner) throw new Error("id and owner required");
|
|
584
|
+
if (_todogovPsV2.has(id))
|
|
585
|
+
throw new Error(`todogov profile ${id} already exists`);
|
|
586
|
+
const now = Date.now();
|
|
587
|
+
const p = {
|
|
588
|
+
id,
|
|
589
|
+
owner,
|
|
590
|
+
list: list || "default",
|
|
591
|
+
status: TODOGOV_PROFILE_MATURITY_V2.PENDING,
|
|
592
|
+
createdAt: now,
|
|
593
|
+
updatedAt: now,
|
|
594
|
+
lastTouchedAt: now,
|
|
595
|
+
activatedAt: null,
|
|
596
|
+
archivedAt: null,
|
|
597
|
+
metadata: { ...(metadata || {}) },
|
|
598
|
+
};
|
|
599
|
+
_todogovPsV2.set(id, p);
|
|
600
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
601
|
+
}
|
|
602
|
+
export function activateTodogovProfileV2(id) {
|
|
603
|
+
const p = _todogovPsV2.get(id);
|
|
604
|
+
if (!p) throw new Error(`todogov profile ${id} not found`);
|
|
605
|
+
const isInitial = p.status === TODOGOV_PROFILE_MATURITY_V2.PENDING;
|
|
606
|
+
_todogovCheckP(p.status, TODOGOV_PROFILE_MATURITY_V2.ACTIVE);
|
|
607
|
+
if (isInitial && _todogovCountActive(p.owner) >= _todogovMaxActive)
|
|
608
|
+
throw new Error(`max active todogov profiles for owner ${p.owner} reached`);
|
|
609
|
+
const now = Date.now();
|
|
610
|
+
p.status = TODOGOV_PROFILE_MATURITY_V2.ACTIVE;
|
|
611
|
+
p.updatedAt = now;
|
|
612
|
+
p.lastTouchedAt = now;
|
|
613
|
+
if (!p.activatedAt) p.activatedAt = now;
|
|
614
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
615
|
+
}
|
|
616
|
+
export function pauseTodogovProfileV2(id) {
|
|
617
|
+
const p = _todogovPsV2.get(id);
|
|
618
|
+
if (!p) throw new Error(`todogov profile ${id} not found`);
|
|
619
|
+
_todogovCheckP(p.status, TODOGOV_PROFILE_MATURITY_V2.PAUSED);
|
|
620
|
+
p.status = TODOGOV_PROFILE_MATURITY_V2.PAUSED;
|
|
621
|
+
p.updatedAt = Date.now();
|
|
622
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
623
|
+
}
|
|
624
|
+
export function archiveTodogovProfileV2(id) {
|
|
625
|
+
const p = _todogovPsV2.get(id);
|
|
626
|
+
if (!p) throw new Error(`todogov profile ${id} not found`);
|
|
627
|
+
_todogovCheckP(p.status, TODOGOV_PROFILE_MATURITY_V2.ARCHIVED);
|
|
628
|
+
const now = Date.now();
|
|
629
|
+
p.status = TODOGOV_PROFILE_MATURITY_V2.ARCHIVED;
|
|
630
|
+
p.updatedAt = now;
|
|
631
|
+
if (!p.archivedAt) p.archivedAt = now;
|
|
632
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
633
|
+
}
|
|
634
|
+
export function touchTodogovProfileV2(id) {
|
|
635
|
+
const p = _todogovPsV2.get(id);
|
|
636
|
+
if (!p) throw new Error(`todogov profile ${id} not found`);
|
|
637
|
+
if (_todogovPTerminal.has(p.status))
|
|
638
|
+
throw new Error(`cannot touch terminal todogov profile ${id}`);
|
|
639
|
+
const now = Date.now();
|
|
640
|
+
p.lastTouchedAt = now;
|
|
641
|
+
p.updatedAt = now;
|
|
642
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
643
|
+
}
|
|
644
|
+
export function getTodogovProfileV2(id) {
|
|
645
|
+
const p = _todogovPsV2.get(id);
|
|
646
|
+
if (!p) return null;
|
|
647
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
648
|
+
}
|
|
649
|
+
export function listTodogovProfilesV2() {
|
|
650
|
+
return [..._todogovPsV2.values()].map((p) => ({
|
|
651
|
+
...p,
|
|
652
|
+
metadata: { ...p.metadata },
|
|
653
|
+
}));
|
|
654
|
+
}
|
|
655
|
+
export function createTodogovStepV2({ id, profileId, title, metadata } = {}) {
|
|
656
|
+
if (!id || !profileId) throw new Error("id and profileId required");
|
|
657
|
+
if (_todogovJsV2.has(id))
|
|
658
|
+
throw new Error(`todogov step ${id} already exists`);
|
|
659
|
+
if (!_todogovPsV2.has(profileId))
|
|
660
|
+
throw new Error(`todogov profile ${profileId} not found`);
|
|
661
|
+
if (_todogovCountPending(profileId) >= _todogovMaxPending)
|
|
662
|
+
throw new Error(
|
|
663
|
+
`max pending todogov steps for profile ${profileId} reached`,
|
|
664
|
+
);
|
|
665
|
+
const now = Date.now();
|
|
666
|
+
const j = {
|
|
667
|
+
id,
|
|
668
|
+
profileId,
|
|
669
|
+
title: title || "",
|
|
670
|
+
status: TODOGOV_STEP_LIFECYCLE_V2.QUEUED,
|
|
671
|
+
createdAt: now,
|
|
672
|
+
updatedAt: now,
|
|
673
|
+
startedAt: null,
|
|
674
|
+
settledAt: null,
|
|
675
|
+
metadata: { ...(metadata || {}) },
|
|
676
|
+
};
|
|
677
|
+
_todogovJsV2.set(id, j);
|
|
678
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
679
|
+
}
|
|
680
|
+
export function doingTodogovStepV2(id) {
|
|
681
|
+
const j = _todogovJsV2.get(id);
|
|
682
|
+
if (!j) throw new Error(`todogov step ${id} not found`);
|
|
683
|
+
_todogovCheckJ(j.status, TODOGOV_STEP_LIFECYCLE_V2.DOING);
|
|
684
|
+
const now = Date.now();
|
|
685
|
+
j.status = TODOGOV_STEP_LIFECYCLE_V2.DOING;
|
|
686
|
+
j.updatedAt = now;
|
|
687
|
+
if (!j.startedAt) j.startedAt = now;
|
|
688
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
689
|
+
}
|
|
690
|
+
export function completeStepTodogovV2(id) {
|
|
691
|
+
const j = _todogovJsV2.get(id);
|
|
692
|
+
if (!j) throw new Error(`todogov step ${id} not found`);
|
|
693
|
+
_todogovCheckJ(j.status, TODOGOV_STEP_LIFECYCLE_V2.DONE);
|
|
694
|
+
const now = Date.now();
|
|
695
|
+
j.status = TODOGOV_STEP_LIFECYCLE_V2.DONE;
|
|
696
|
+
j.updatedAt = now;
|
|
697
|
+
if (!j.settledAt) j.settledAt = now;
|
|
698
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
699
|
+
}
|
|
700
|
+
export function failTodogovStepV2(id, reason) {
|
|
701
|
+
const j = _todogovJsV2.get(id);
|
|
702
|
+
if (!j) throw new Error(`todogov step ${id} not found`);
|
|
703
|
+
_todogovCheckJ(j.status, TODOGOV_STEP_LIFECYCLE_V2.FAILED);
|
|
704
|
+
const now = Date.now();
|
|
705
|
+
j.status = TODOGOV_STEP_LIFECYCLE_V2.FAILED;
|
|
706
|
+
j.updatedAt = now;
|
|
707
|
+
if (!j.settledAt) j.settledAt = now;
|
|
708
|
+
if (reason) j.metadata.failReason = String(reason);
|
|
709
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
710
|
+
}
|
|
711
|
+
export function cancelTodogovStepV2(id, reason) {
|
|
712
|
+
const j = _todogovJsV2.get(id);
|
|
713
|
+
if (!j) throw new Error(`todogov step ${id} not found`);
|
|
714
|
+
_todogovCheckJ(j.status, TODOGOV_STEP_LIFECYCLE_V2.CANCELLED);
|
|
715
|
+
const now = Date.now();
|
|
716
|
+
j.status = TODOGOV_STEP_LIFECYCLE_V2.CANCELLED;
|
|
717
|
+
j.updatedAt = now;
|
|
718
|
+
if (!j.settledAt) j.settledAt = now;
|
|
719
|
+
if (reason) j.metadata.cancelReason = String(reason);
|
|
720
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
721
|
+
}
|
|
722
|
+
export function getTodogovStepV2(id) {
|
|
723
|
+
const j = _todogovJsV2.get(id);
|
|
724
|
+
if (!j) return null;
|
|
725
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
726
|
+
}
|
|
727
|
+
export function listTodogovStepsV2() {
|
|
728
|
+
return [..._todogovJsV2.values()].map((j) => ({
|
|
729
|
+
...j,
|
|
730
|
+
metadata: { ...j.metadata },
|
|
731
|
+
}));
|
|
732
|
+
}
|
|
733
|
+
export function autoPauseIdleTodogovProfilesV2({ now } = {}) {
|
|
734
|
+
const t = now ?? Date.now();
|
|
735
|
+
const flipped = [];
|
|
736
|
+
for (const p of _todogovPsV2.values())
|
|
737
|
+
if (
|
|
738
|
+
p.status === TODOGOV_PROFILE_MATURITY_V2.ACTIVE &&
|
|
739
|
+
t - p.lastTouchedAt >= _todogovIdleMs
|
|
740
|
+
) {
|
|
741
|
+
p.status = TODOGOV_PROFILE_MATURITY_V2.PAUSED;
|
|
742
|
+
p.updatedAt = t;
|
|
743
|
+
flipped.push(p.id);
|
|
744
|
+
}
|
|
745
|
+
return { flipped, count: flipped.length };
|
|
746
|
+
}
|
|
747
|
+
export function autoFailStuckTodogovStepsV2({ now } = {}) {
|
|
748
|
+
const t = now ?? Date.now();
|
|
749
|
+
const flipped = [];
|
|
750
|
+
for (const j of _todogovJsV2.values())
|
|
751
|
+
if (
|
|
752
|
+
j.status === TODOGOV_STEP_LIFECYCLE_V2.DOING &&
|
|
753
|
+
j.startedAt != null &&
|
|
754
|
+
t - j.startedAt >= _todogovStuckMs
|
|
755
|
+
) {
|
|
756
|
+
j.status = TODOGOV_STEP_LIFECYCLE_V2.FAILED;
|
|
757
|
+
j.updatedAt = t;
|
|
758
|
+
if (!j.settledAt) j.settledAt = t;
|
|
759
|
+
j.metadata.failReason = "auto-fail-stuck";
|
|
760
|
+
flipped.push(j.id);
|
|
761
|
+
}
|
|
762
|
+
return { flipped, count: flipped.length };
|
|
763
|
+
}
|
|
764
|
+
export function getTodoManagerGovStatsV2() {
|
|
765
|
+
const profilesByStatus = {};
|
|
766
|
+
for (const v of Object.values(TODOGOV_PROFILE_MATURITY_V2))
|
|
767
|
+
profilesByStatus[v] = 0;
|
|
768
|
+
for (const p of _todogovPsV2.values()) profilesByStatus[p.status]++;
|
|
769
|
+
const stepsByStatus = {};
|
|
770
|
+
for (const v of Object.values(TODOGOV_STEP_LIFECYCLE_V2))
|
|
771
|
+
stepsByStatus[v] = 0;
|
|
772
|
+
for (const j of _todogovJsV2.values()) stepsByStatus[j.status]++;
|
|
773
|
+
return {
|
|
774
|
+
totalTodogovProfilesV2: _todogovPsV2.size,
|
|
775
|
+
totalTodogovStepsV2: _todogovJsV2.size,
|
|
776
|
+
maxActiveTodogovProfilesPerOwner: _todogovMaxActive,
|
|
777
|
+
maxPendingTodogovStepsPerProfile: _todogovMaxPending,
|
|
778
|
+
todogovProfileIdleMs: _todogovIdleMs,
|
|
779
|
+
todogovStepStuckMs: _todogovStuckMs,
|
|
780
|
+
profilesByStatus,
|
|
781
|
+
stepsByStatus,
|
|
782
|
+
};
|
|
783
|
+
}
|