chainlesschain 0.152.0 → 0.156.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/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
package/src/lib/agent-router.js
CHANGED
|
@@ -790,3 +790,336 @@ export function getAgentRouterStatsV2() {
|
|
|
790
790
|
dispatchesByStatus,
|
|
791
791
|
};
|
|
792
792
|
}
|
|
793
|
+
|
|
794
|
+
// =====================================================================
|
|
795
|
+
// agent-router V2 governance overlay (iter25)
|
|
796
|
+
// =====================================================================
|
|
797
|
+
export const ARGOV_PROFILE_MATURITY_V2 = Object.freeze({
|
|
798
|
+
PENDING: "pending",
|
|
799
|
+
ACTIVE: "active",
|
|
800
|
+
STALE: "stale",
|
|
801
|
+
ARCHIVED: "archived",
|
|
802
|
+
});
|
|
803
|
+
export const ARGOV_ROUTING_LIFECYCLE_V2 = Object.freeze({
|
|
804
|
+
QUEUED: "queued",
|
|
805
|
+
ROUTING_RUN: "routing",
|
|
806
|
+
ROUTED: "routed",
|
|
807
|
+
FAILED: "failed",
|
|
808
|
+
CANCELLED: "cancelled",
|
|
809
|
+
});
|
|
810
|
+
const _argovPTrans = new Map([
|
|
811
|
+
[
|
|
812
|
+
ARGOV_PROFILE_MATURITY_V2.PENDING,
|
|
813
|
+
new Set([
|
|
814
|
+
ARGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
815
|
+
ARGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
816
|
+
]),
|
|
817
|
+
],
|
|
818
|
+
[
|
|
819
|
+
ARGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
820
|
+
new Set([
|
|
821
|
+
ARGOV_PROFILE_MATURITY_V2.STALE,
|
|
822
|
+
ARGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
823
|
+
]),
|
|
824
|
+
],
|
|
825
|
+
[
|
|
826
|
+
ARGOV_PROFILE_MATURITY_V2.STALE,
|
|
827
|
+
new Set([
|
|
828
|
+
ARGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
829
|
+
ARGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
830
|
+
]),
|
|
831
|
+
],
|
|
832
|
+
[ARGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
|
|
833
|
+
]);
|
|
834
|
+
const _argovPTerminal = new Set([ARGOV_PROFILE_MATURITY_V2.ARCHIVED]);
|
|
835
|
+
const _argovJTrans = new Map([
|
|
836
|
+
[
|
|
837
|
+
ARGOV_ROUTING_LIFECYCLE_V2.QUEUED,
|
|
838
|
+
new Set([
|
|
839
|
+
ARGOV_ROUTING_LIFECYCLE_V2.ROUTING_RUN,
|
|
840
|
+
ARGOV_ROUTING_LIFECYCLE_V2.CANCELLED,
|
|
841
|
+
]),
|
|
842
|
+
],
|
|
843
|
+
[
|
|
844
|
+
ARGOV_ROUTING_LIFECYCLE_V2.ROUTING_RUN,
|
|
845
|
+
new Set([
|
|
846
|
+
ARGOV_ROUTING_LIFECYCLE_V2.ROUTED,
|
|
847
|
+
ARGOV_ROUTING_LIFECYCLE_V2.FAILED,
|
|
848
|
+
ARGOV_ROUTING_LIFECYCLE_V2.CANCELLED,
|
|
849
|
+
]),
|
|
850
|
+
],
|
|
851
|
+
[ARGOV_ROUTING_LIFECYCLE_V2.ROUTED, new Set()],
|
|
852
|
+
[ARGOV_ROUTING_LIFECYCLE_V2.FAILED, new Set()],
|
|
853
|
+
[ARGOV_ROUTING_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
854
|
+
]);
|
|
855
|
+
const _argovPsV2 = new Map();
|
|
856
|
+
const _argovJsV2 = new Map();
|
|
857
|
+
let _argovMaxActive = 8,
|
|
858
|
+
_argovMaxPending = 20,
|
|
859
|
+
_argovIdleMs = 30 * 24 * 60 * 60 * 1000,
|
|
860
|
+
_argovStuckMs = 60 * 1000;
|
|
861
|
+
function _argovPos(n, label) {
|
|
862
|
+
const v = Math.floor(Number(n));
|
|
863
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
864
|
+
throw new Error(`${label} must be positive integer`);
|
|
865
|
+
return v;
|
|
866
|
+
}
|
|
867
|
+
function _argovCheckP(from, to) {
|
|
868
|
+
const a = _argovPTrans.get(from);
|
|
869
|
+
if (!a || !a.has(to))
|
|
870
|
+
throw new Error(`invalid argov profile transition ${from} → ${to}`);
|
|
871
|
+
}
|
|
872
|
+
function _argovCheckJ(from, to) {
|
|
873
|
+
const a = _argovJTrans.get(from);
|
|
874
|
+
if (!a || !a.has(to))
|
|
875
|
+
throw new Error(`invalid argov routing transition ${from} → ${to}`);
|
|
876
|
+
}
|
|
877
|
+
function _argovCountActive(owner) {
|
|
878
|
+
let c = 0;
|
|
879
|
+
for (const p of _argovPsV2.values())
|
|
880
|
+
if (p.owner === owner && p.status === ARGOV_PROFILE_MATURITY_V2.ACTIVE) c++;
|
|
881
|
+
return c;
|
|
882
|
+
}
|
|
883
|
+
function _argovCountPending(profileId) {
|
|
884
|
+
let c = 0;
|
|
885
|
+
for (const j of _argovJsV2.values())
|
|
886
|
+
if (
|
|
887
|
+
j.profileId === profileId &&
|
|
888
|
+
(j.status === ARGOV_ROUTING_LIFECYCLE_V2.QUEUED ||
|
|
889
|
+
j.status === ARGOV_ROUTING_LIFECYCLE_V2.ROUTING_RUN)
|
|
890
|
+
)
|
|
891
|
+
c++;
|
|
892
|
+
return c;
|
|
893
|
+
}
|
|
894
|
+
export function setMaxActiveArgovProfilesPerOwnerV2(n) {
|
|
895
|
+
_argovMaxActive = _argovPos(n, "maxActiveArgovProfilesPerOwner");
|
|
896
|
+
}
|
|
897
|
+
export function getMaxActiveArgovProfilesPerOwnerV2() {
|
|
898
|
+
return _argovMaxActive;
|
|
899
|
+
}
|
|
900
|
+
export function setMaxPendingArgovRoutingsPerProfileV2(n) {
|
|
901
|
+
_argovMaxPending = _argovPos(n, "maxPendingArgovRoutingsPerProfile");
|
|
902
|
+
}
|
|
903
|
+
export function getMaxPendingArgovRoutingsPerProfileV2() {
|
|
904
|
+
return _argovMaxPending;
|
|
905
|
+
}
|
|
906
|
+
export function setArgovProfileIdleMsV2(n) {
|
|
907
|
+
_argovIdleMs = _argovPos(n, "argovProfileIdleMs");
|
|
908
|
+
}
|
|
909
|
+
export function getArgovProfileIdleMsV2() {
|
|
910
|
+
return _argovIdleMs;
|
|
911
|
+
}
|
|
912
|
+
export function setArgovRoutingStuckMsV2(n) {
|
|
913
|
+
_argovStuckMs = _argovPos(n, "argovRoutingStuckMs");
|
|
914
|
+
}
|
|
915
|
+
export function getArgovRoutingStuckMsV2() {
|
|
916
|
+
return _argovStuckMs;
|
|
917
|
+
}
|
|
918
|
+
export function _resetStateAgentRouterGovV2() {
|
|
919
|
+
_argovPsV2.clear();
|
|
920
|
+
_argovJsV2.clear();
|
|
921
|
+
_argovMaxActive = 8;
|
|
922
|
+
_argovMaxPending = 20;
|
|
923
|
+
_argovIdleMs = 30 * 24 * 60 * 60 * 1000;
|
|
924
|
+
_argovStuckMs = 60 * 1000;
|
|
925
|
+
}
|
|
926
|
+
export function registerArgovProfileV2({ id, owner, strategy, metadata } = {}) {
|
|
927
|
+
if (!id || !owner) throw new Error("id and owner required");
|
|
928
|
+
if (_argovPsV2.has(id)) throw new Error(`argov profile ${id} already exists`);
|
|
929
|
+
const now = Date.now();
|
|
930
|
+
const p = {
|
|
931
|
+
id,
|
|
932
|
+
owner,
|
|
933
|
+
strategy: strategy || "round-robin",
|
|
934
|
+
status: ARGOV_PROFILE_MATURITY_V2.PENDING,
|
|
935
|
+
createdAt: now,
|
|
936
|
+
updatedAt: now,
|
|
937
|
+
lastTouchedAt: now,
|
|
938
|
+
activatedAt: null,
|
|
939
|
+
archivedAt: null,
|
|
940
|
+
metadata: { ...(metadata || {}) },
|
|
941
|
+
};
|
|
942
|
+
_argovPsV2.set(id, p);
|
|
943
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
944
|
+
}
|
|
945
|
+
export function activateArgovProfileV2(id) {
|
|
946
|
+
const p = _argovPsV2.get(id);
|
|
947
|
+
if (!p) throw new Error(`argov profile ${id} not found`);
|
|
948
|
+
const isInitial = p.status === ARGOV_PROFILE_MATURITY_V2.PENDING;
|
|
949
|
+
_argovCheckP(p.status, ARGOV_PROFILE_MATURITY_V2.ACTIVE);
|
|
950
|
+
if (isInitial && _argovCountActive(p.owner) >= _argovMaxActive)
|
|
951
|
+
throw new Error(`max active argov profiles for owner ${p.owner} reached`);
|
|
952
|
+
const now = Date.now();
|
|
953
|
+
p.status = ARGOV_PROFILE_MATURITY_V2.ACTIVE;
|
|
954
|
+
p.updatedAt = now;
|
|
955
|
+
p.lastTouchedAt = now;
|
|
956
|
+
if (!p.activatedAt) p.activatedAt = now;
|
|
957
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
958
|
+
}
|
|
959
|
+
export function staleArgovProfileV2(id) {
|
|
960
|
+
const p = _argovPsV2.get(id);
|
|
961
|
+
if (!p) throw new Error(`argov profile ${id} not found`);
|
|
962
|
+
_argovCheckP(p.status, ARGOV_PROFILE_MATURITY_V2.STALE);
|
|
963
|
+
p.status = ARGOV_PROFILE_MATURITY_V2.STALE;
|
|
964
|
+
p.updatedAt = Date.now();
|
|
965
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
966
|
+
}
|
|
967
|
+
export function archiveArgovProfileV2(id) {
|
|
968
|
+
const p = _argovPsV2.get(id);
|
|
969
|
+
if (!p) throw new Error(`argov profile ${id} not found`);
|
|
970
|
+
_argovCheckP(p.status, ARGOV_PROFILE_MATURITY_V2.ARCHIVED);
|
|
971
|
+
const now = Date.now();
|
|
972
|
+
p.status = ARGOV_PROFILE_MATURITY_V2.ARCHIVED;
|
|
973
|
+
p.updatedAt = now;
|
|
974
|
+
if (!p.archivedAt) p.archivedAt = now;
|
|
975
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
976
|
+
}
|
|
977
|
+
export function touchArgovProfileV2(id) {
|
|
978
|
+
const p = _argovPsV2.get(id);
|
|
979
|
+
if (!p) throw new Error(`argov profile ${id} not found`);
|
|
980
|
+
if (_argovPTerminal.has(p.status))
|
|
981
|
+
throw new Error(`cannot touch terminal argov profile ${id}`);
|
|
982
|
+
const now = Date.now();
|
|
983
|
+
p.lastTouchedAt = now;
|
|
984
|
+
p.updatedAt = now;
|
|
985
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
986
|
+
}
|
|
987
|
+
export function getArgovProfileV2(id) {
|
|
988
|
+
const p = _argovPsV2.get(id);
|
|
989
|
+
if (!p) return null;
|
|
990
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
991
|
+
}
|
|
992
|
+
export function listArgovProfilesV2() {
|
|
993
|
+
return [..._argovPsV2.values()].map((p) => ({
|
|
994
|
+
...p,
|
|
995
|
+
metadata: { ...p.metadata },
|
|
996
|
+
}));
|
|
997
|
+
}
|
|
998
|
+
export function createArgovRoutingV2({ id, profileId, target, metadata } = {}) {
|
|
999
|
+
if (!id || !profileId) throw new Error("id and profileId required");
|
|
1000
|
+
if (_argovJsV2.has(id)) throw new Error(`argov routing ${id} already exists`);
|
|
1001
|
+
if (!_argovPsV2.has(profileId))
|
|
1002
|
+
throw new Error(`argov profile ${profileId} not found`);
|
|
1003
|
+
if (_argovCountPending(profileId) >= _argovMaxPending)
|
|
1004
|
+
throw new Error(
|
|
1005
|
+
`max pending argov routings for profile ${profileId} reached`,
|
|
1006
|
+
);
|
|
1007
|
+
const now = Date.now();
|
|
1008
|
+
const j = {
|
|
1009
|
+
id,
|
|
1010
|
+
profileId,
|
|
1011
|
+
target: target || "",
|
|
1012
|
+
status: ARGOV_ROUTING_LIFECYCLE_V2.QUEUED,
|
|
1013
|
+
createdAt: now,
|
|
1014
|
+
updatedAt: now,
|
|
1015
|
+
startedAt: null,
|
|
1016
|
+
settledAt: null,
|
|
1017
|
+
metadata: { ...(metadata || {}) },
|
|
1018
|
+
};
|
|
1019
|
+
_argovJsV2.set(id, j);
|
|
1020
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1021
|
+
}
|
|
1022
|
+
export function runningArgovRoutingV2(id) {
|
|
1023
|
+
const j = _argovJsV2.get(id);
|
|
1024
|
+
if (!j) throw new Error(`argov routing ${id} not found`);
|
|
1025
|
+
_argovCheckJ(j.status, ARGOV_ROUTING_LIFECYCLE_V2.ROUTING_RUN);
|
|
1026
|
+
const now = Date.now();
|
|
1027
|
+
j.status = ARGOV_ROUTING_LIFECYCLE_V2.ROUTING_RUN;
|
|
1028
|
+
j.updatedAt = now;
|
|
1029
|
+
if (!j.startedAt) j.startedAt = now;
|
|
1030
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1031
|
+
}
|
|
1032
|
+
export function completeRoutingArgovV2(id) {
|
|
1033
|
+
const j = _argovJsV2.get(id);
|
|
1034
|
+
if (!j) throw new Error(`argov routing ${id} not found`);
|
|
1035
|
+
_argovCheckJ(j.status, ARGOV_ROUTING_LIFECYCLE_V2.ROUTED);
|
|
1036
|
+
const now = Date.now();
|
|
1037
|
+
j.status = ARGOV_ROUTING_LIFECYCLE_V2.ROUTED;
|
|
1038
|
+
j.updatedAt = now;
|
|
1039
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1040
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1041
|
+
}
|
|
1042
|
+
export function failArgovRoutingV2(id, reason) {
|
|
1043
|
+
const j = _argovJsV2.get(id);
|
|
1044
|
+
if (!j) throw new Error(`argov routing ${id} not found`);
|
|
1045
|
+
_argovCheckJ(j.status, ARGOV_ROUTING_LIFECYCLE_V2.FAILED);
|
|
1046
|
+
const now = Date.now();
|
|
1047
|
+
j.status = ARGOV_ROUTING_LIFECYCLE_V2.FAILED;
|
|
1048
|
+
j.updatedAt = now;
|
|
1049
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1050
|
+
if (reason) j.metadata.failReason = String(reason);
|
|
1051
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1052
|
+
}
|
|
1053
|
+
export function cancelArgovRoutingV2(id, reason) {
|
|
1054
|
+
const j = _argovJsV2.get(id);
|
|
1055
|
+
if (!j) throw new Error(`argov routing ${id} not found`);
|
|
1056
|
+
_argovCheckJ(j.status, ARGOV_ROUTING_LIFECYCLE_V2.CANCELLED);
|
|
1057
|
+
const now = Date.now();
|
|
1058
|
+
j.status = ARGOV_ROUTING_LIFECYCLE_V2.CANCELLED;
|
|
1059
|
+
j.updatedAt = now;
|
|
1060
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1061
|
+
if (reason) j.metadata.cancelReason = String(reason);
|
|
1062
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1063
|
+
}
|
|
1064
|
+
export function getArgovRoutingV2(id) {
|
|
1065
|
+
const j = _argovJsV2.get(id);
|
|
1066
|
+
if (!j) return null;
|
|
1067
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1068
|
+
}
|
|
1069
|
+
export function listArgovRoutingsV2() {
|
|
1070
|
+
return [..._argovJsV2.values()].map((j) => ({
|
|
1071
|
+
...j,
|
|
1072
|
+
metadata: { ...j.metadata },
|
|
1073
|
+
}));
|
|
1074
|
+
}
|
|
1075
|
+
export function autoStaleIdleArgovProfilesV2({ now } = {}) {
|
|
1076
|
+
const t = now ?? Date.now();
|
|
1077
|
+
const flipped = [];
|
|
1078
|
+
for (const p of _argovPsV2.values())
|
|
1079
|
+
if (
|
|
1080
|
+
p.status === ARGOV_PROFILE_MATURITY_V2.ACTIVE &&
|
|
1081
|
+
t - p.lastTouchedAt >= _argovIdleMs
|
|
1082
|
+
) {
|
|
1083
|
+
p.status = ARGOV_PROFILE_MATURITY_V2.STALE;
|
|
1084
|
+
p.updatedAt = t;
|
|
1085
|
+
flipped.push(p.id);
|
|
1086
|
+
}
|
|
1087
|
+
return { flipped, count: flipped.length };
|
|
1088
|
+
}
|
|
1089
|
+
export function autoFailStuckArgovRoutingsV2({ now } = {}) {
|
|
1090
|
+
const t = now ?? Date.now();
|
|
1091
|
+
const flipped = [];
|
|
1092
|
+
for (const j of _argovJsV2.values())
|
|
1093
|
+
if (
|
|
1094
|
+
j.status === ARGOV_ROUTING_LIFECYCLE_V2.ROUTING_RUN &&
|
|
1095
|
+
j.startedAt != null &&
|
|
1096
|
+
t - j.startedAt >= _argovStuckMs
|
|
1097
|
+
) {
|
|
1098
|
+
j.status = ARGOV_ROUTING_LIFECYCLE_V2.FAILED;
|
|
1099
|
+
j.updatedAt = t;
|
|
1100
|
+
if (!j.settledAt) j.settledAt = t;
|
|
1101
|
+
j.metadata.failReason = "auto-fail-stuck";
|
|
1102
|
+
flipped.push(j.id);
|
|
1103
|
+
}
|
|
1104
|
+
return { flipped, count: flipped.length };
|
|
1105
|
+
}
|
|
1106
|
+
export function getAgentRouterGovStatsV2() {
|
|
1107
|
+
const profilesByStatus = {};
|
|
1108
|
+
for (const v of Object.values(ARGOV_PROFILE_MATURITY_V2))
|
|
1109
|
+
profilesByStatus[v] = 0;
|
|
1110
|
+
for (const p of _argovPsV2.values()) profilesByStatus[p.status]++;
|
|
1111
|
+
const routingsByStatus = {};
|
|
1112
|
+
for (const v of Object.values(ARGOV_ROUTING_LIFECYCLE_V2))
|
|
1113
|
+
routingsByStatus[v] = 0;
|
|
1114
|
+
for (const j of _argovJsV2.values()) routingsByStatus[j.status]++;
|
|
1115
|
+
return {
|
|
1116
|
+
totalArgovProfilesV2: _argovPsV2.size,
|
|
1117
|
+
totalArgovRoutingsV2: _argovJsV2.size,
|
|
1118
|
+
maxActiveArgovProfilesPerOwner: _argovMaxActive,
|
|
1119
|
+
maxPendingArgovRoutingsPerProfile: _argovMaxPending,
|
|
1120
|
+
argovProfileIdleMs: _argovIdleMs,
|
|
1121
|
+
argovRoutingStuckMs: _argovStuckMs,
|
|
1122
|
+
profilesByStatus,
|
|
1123
|
+
routingsByStatus,
|
|
1124
|
+
};
|
|
1125
|
+
}
|
|
@@ -833,3 +833,335 @@ export function getAutonomousAgentGovStatsV2() {
|
|
|
833
833
|
runsByStatus,
|
|
834
834
|
};
|
|
835
835
|
}
|
|
836
|
+
|
|
837
|
+
// === Iter28 V2 governance overlay: Autagov ===
|
|
838
|
+
export const AUTAGOV_PROFILE_MATURITY_V2 = Object.freeze({
|
|
839
|
+
PENDING: "pending",
|
|
840
|
+
ACTIVE: "active",
|
|
841
|
+
PAUSED: "paused",
|
|
842
|
+
ARCHIVED: "archived",
|
|
843
|
+
});
|
|
844
|
+
export const AUTAGOV_RUN_LIFECYCLE_V2 = Object.freeze({
|
|
845
|
+
QUEUED: "queued",
|
|
846
|
+
RUNNING: "running",
|
|
847
|
+
FINISHED: "finished",
|
|
848
|
+
FAILED: "failed",
|
|
849
|
+
CANCELLED: "cancelled",
|
|
850
|
+
});
|
|
851
|
+
const _autagovPTrans = new Map([
|
|
852
|
+
[
|
|
853
|
+
AUTAGOV_PROFILE_MATURITY_V2.PENDING,
|
|
854
|
+
new Set([
|
|
855
|
+
AUTAGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
856
|
+
AUTAGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
857
|
+
]),
|
|
858
|
+
],
|
|
859
|
+
[
|
|
860
|
+
AUTAGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
861
|
+
new Set([
|
|
862
|
+
AUTAGOV_PROFILE_MATURITY_V2.PAUSED,
|
|
863
|
+
AUTAGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
864
|
+
]),
|
|
865
|
+
],
|
|
866
|
+
[
|
|
867
|
+
AUTAGOV_PROFILE_MATURITY_V2.PAUSED,
|
|
868
|
+
new Set([
|
|
869
|
+
AUTAGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
870
|
+
AUTAGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
871
|
+
]),
|
|
872
|
+
],
|
|
873
|
+
[AUTAGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
|
|
874
|
+
]);
|
|
875
|
+
const _autagovPTerminal = new Set([AUTAGOV_PROFILE_MATURITY_V2.ARCHIVED]);
|
|
876
|
+
const _autagovJTrans = new Map([
|
|
877
|
+
[
|
|
878
|
+
AUTAGOV_RUN_LIFECYCLE_V2.QUEUED,
|
|
879
|
+
new Set([
|
|
880
|
+
AUTAGOV_RUN_LIFECYCLE_V2.RUNNING,
|
|
881
|
+
AUTAGOV_RUN_LIFECYCLE_V2.CANCELLED,
|
|
882
|
+
]),
|
|
883
|
+
],
|
|
884
|
+
[
|
|
885
|
+
AUTAGOV_RUN_LIFECYCLE_V2.RUNNING,
|
|
886
|
+
new Set([
|
|
887
|
+
AUTAGOV_RUN_LIFECYCLE_V2.FINISHED,
|
|
888
|
+
AUTAGOV_RUN_LIFECYCLE_V2.FAILED,
|
|
889
|
+
AUTAGOV_RUN_LIFECYCLE_V2.CANCELLED,
|
|
890
|
+
]),
|
|
891
|
+
],
|
|
892
|
+
[AUTAGOV_RUN_LIFECYCLE_V2.FINISHED, new Set()],
|
|
893
|
+
[AUTAGOV_RUN_LIFECYCLE_V2.FAILED, new Set()],
|
|
894
|
+
[AUTAGOV_RUN_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
895
|
+
]);
|
|
896
|
+
const _autagovPsV2 = new Map();
|
|
897
|
+
const _autagovJsV2 = new Map();
|
|
898
|
+
let _autagovMaxActive = 6,
|
|
899
|
+
_autagovMaxPending = 15,
|
|
900
|
+
_autagovIdleMs = 2592000000,
|
|
901
|
+
_autagovStuckMs = 60 * 1000;
|
|
902
|
+
function _autagovPos(n, label) {
|
|
903
|
+
const v = Math.floor(Number(n));
|
|
904
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
905
|
+
throw new Error(`${label} must be positive integer`);
|
|
906
|
+
return v;
|
|
907
|
+
}
|
|
908
|
+
function _autagovCheckP(from, to) {
|
|
909
|
+
const a = _autagovPTrans.get(from);
|
|
910
|
+
if (!a || !a.has(to))
|
|
911
|
+
throw new Error(`invalid autagov profile transition ${from} → ${to}`);
|
|
912
|
+
}
|
|
913
|
+
function _autagovCheckJ(from, to) {
|
|
914
|
+
const a = _autagovJTrans.get(from);
|
|
915
|
+
if (!a || !a.has(to))
|
|
916
|
+
throw new Error(`invalid autagov run transition ${from} → ${to}`);
|
|
917
|
+
}
|
|
918
|
+
function _autagovCountActive(owner) {
|
|
919
|
+
let c = 0;
|
|
920
|
+
for (const p of _autagovPsV2.values())
|
|
921
|
+
if (p.owner === owner && p.status === AUTAGOV_PROFILE_MATURITY_V2.ACTIVE)
|
|
922
|
+
c++;
|
|
923
|
+
return c;
|
|
924
|
+
}
|
|
925
|
+
function _autagovCountPending(profileId) {
|
|
926
|
+
let c = 0;
|
|
927
|
+
for (const j of _autagovJsV2.values())
|
|
928
|
+
if (
|
|
929
|
+
j.profileId === profileId &&
|
|
930
|
+
(j.status === AUTAGOV_RUN_LIFECYCLE_V2.QUEUED ||
|
|
931
|
+
j.status === AUTAGOV_RUN_LIFECYCLE_V2.RUNNING)
|
|
932
|
+
)
|
|
933
|
+
c++;
|
|
934
|
+
return c;
|
|
935
|
+
}
|
|
936
|
+
export function setMaxActiveAutagProfilesPerOwnerV2(n) {
|
|
937
|
+
_autagovMaxActive = _autagovPos(n, "maxActiveAutagProfilesPerOwner");
|
|
938
|
+
}
|
|
939
|
+
export function getMaxActiveAutagProfilesPerOwnerV2() {
|
|
940
|
+
return _autagovMaxActive;
|
|
941
|
+
}
|
|
942
|
+
export function setMaxPendingAutagRunsPerProfileV2(n) {
|
|
943
|
+
_autagovMaxPending = _autagovPos(n, "maxPendingAutagRunsPerProfile");
|
|
944
|
+
}
|
|
945
|
+
export function getMaxPendingAutagRunsPerProfileV2() {
|
|
946
|
+
return _autagovMaxPending;
|
|
947
|
+
}
|
|
948
|
+
export function setAutagProfileIdleMsV2(n) {
|
|
949
|
+
_autagovIdleMs = _autagovPos(n, "autagovProfileIdleMs");
|
|
950
|
+
}
|
|
951
|
+
export function getAutagProfileIdleMsV2() {
|
|
952
|
+
return _autagovIdleMs;
|
|
953
|
+
}
|
|
954
|
+
export function setAutagRunStuckMsV2(n) {
|
|
955
|
+
_autagovStuckMs = _autagovPos(n, "autagovRunStuckMs");
|
|
956
|
+
}
|
|
957
|
+
export function getAutagRunStuckMsV2() {
|
|
958
|
+
return _autagovStuckMs;
|
|
959
|
+
}
|
|
960
|
+
export function _resetStateAutagovV2() {
|
|
961
|
+
_autagovPsV2.clear();
|
|
962
|
+
_autagovJsV2.clear();
|
|
963
|
+
_autagovMaxActive = 6;
|
|
964
|
+
_autagovMaxPending = 15;
|
|
965
|
+
_autagovIdleMs = 2592000000;
|
|
966
|
+
_autagovStuckMs = 60 * 1000;
|
|
967
|
+
}
|
|
968
|
+
export function registerAutagProfileV2({ id, owner, tier, metadata } = {}) {
|
|
969
|
+
if (!id || !owner) throw new Error("id and owner required");
|
|
970
|
+
if (_autagovPsV2.has(id))
|
|
971
|
+
throw new Error(`autagov profile ${id} already exists`);
|
|
972
|
+
const now = Date.now();
|
|
973
|
+
const p = {
|
|
974
|
+
id,
|
|
975
|
+
owner,
|
|
976
|
+
tier: tier || "assist",
|
|
977
|
+
status: AUTAGOV_PROFILE_MATURITY_V2.PENDING,
|
|
978
|
+
createdAt: now,
|
|
979
|
+
updatedAt: now,
|
|
980
|
+
lastTouchedAt: now,
|
|
981
|
+
activatedAt: null,
|
|
982
|
+
archivedAt: null,
|
|
983
|
+
metadata: { ...(metadata || {}) },
|
|
984
|
+
};
|
|
985
|
+
_autagovPsV2.set(id, p);
|
|
986
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
987
|
+
}
|
|
988
|
+
export function activateAutagProfileV2(id) {
|
|
989
|
+
const p = _autagovPsV2.get(id);
|
|
990
|
+
if (!p) throw new Error(`autagov profile ${id} not found`);
|
|
991
|
+
const isInitial = p.status === AUTAGOV_PROFILE_MATURITY_V2.PENDING;
|
|
992
|
+
_autagovCheckP(p.status, AUTAGOV_PROFILE_MATURITY_V2.ACTIVE);
|
|
993
|
+
if (isInitial && _autagovCountActive(p.owner) >= _autagovMaxActive)
|
|
994
|
+
throw new Error(`max active autagov profiles for owner ${p.owner} reached`);
|
|
995
|
+
const now = Date.now();
|
|
996
|
+
p.status = AUTAGOV_PROFILE_MATURITY_V2.ACTIVE;
|
|
997
|
+
p.updatedAt = now;
|
|
998
|
+
p.lastTouchedAt = now;
|
|
999
|
+
if (!p.activatedAt) p.activatedAt = now;
|
|
1000
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1001
|
+
}
|
|
1002
|
+
export function pausedAutagProfileV2(id) {
|
|
1003
|
+
const p = _autagovPsV2.get(id);
|
|
1004
|
+
if (!p) throw new Error(`autagov profile ${id} not found`);
|
|
1005
|
+
_autagovCheckP(p.status, AUTAGOV_PROFILE_MATURITY_V2.PAUSED);
|
|
1006
|
+
p.status = AUTAGOV_PROFILE_MATURITY_V2.PAUSED;
|
|
1007
|
+
p.updatedAt = Date.now();
|
|
1008
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1009
|
+
}
|
|
1010
|
+
export function archiveAutagProfileV2(id) {
|
|
1011
|
+
const p = _autagovPsV2.get(id);
|
|
1012
|
+
if (!p) throw new Error(`autagov profile ${id} not found`);
|
|
1013
|
+
_autagovCheckP(p.status, AUTAGOV_PROFILE_MATURITY_V2.ARCHIVED);
|
|
1014
|
+
const now = Date.now();
|
|
1015
|
+
p.status = AUTAGOV_PROFILE_MATURITY_V2.ARCHIVED;
|
|
1016
|
+
p.updatedAt = now;
|
|
1017
|
+
if (!p.archivedAt) p.archivedAt = now;
|
|
1018
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1019
|
+
}
|
|
1020
|
+
export function touchAutagProfileV2(id) {
|
|
1021
|
+
const p = _autagovPsV2.get(id);
|
|
1022
|
+
if (!p) throw new Error(`autagov profile ${id} not found`);
|
|
1023
|
+
if (_autagovPTerminal.has(p.status))
|
|
1024
|
+
throw new Error(`cannot touch terminal autagov profile ${id}`);
|
|
1025
|
+
const now = Date.now();
|
|
1026
|
+
p.lastTouchedAt = now;
|
|
1027
|
+
p.updatedAt = now;
|
|
1028
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1029
|
+
}
|
|
1030
|
+
export function getAutagProfileV2(id) {
|
|
1031
|
+
const p = _autagovPsV2.get(id);
|
|
1032
|
+
if (!p) return null;
|
|
1033
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1034
|
+
}
|
|
1035
|
+
export function listAutagProfilesV2() {
|
|
1036
|
+
return [..._autagovPsV2.values()].map((p) => ({
|
|
1037
|
+
...p,
|
|
1038
|
+
metadata: { ...p.metadata },
|
|
1039
|
+
}));
|
|
1040
|
+
}
|
|
1041
|
+
export function createAutagRunV2({ id, profileId, runId, metadata } = {}) {
|
|
1042
|
+
if (!id || !profileId) throw new Error("id and profileId required");
|
|
1043
|
+
if (_autagovJsV2.has(id)) throw new Error(`autagov run ${id} already exists`);
|
|
1044
|
+
if (!_autagovPsV2.has(profileId))
|
|
1045
|
+
throw new Error(`autagov profile ${profileId} not found`);
|
|
1046
|
+
if (_autagovCountPending(profileId) >= _autagovMaxPending)
|
|
1047
|
+
throw new Error(
|
|
1048
|
+
`max pending autagov runs for profile ${profileId} reached`,
|
|
1049
|
+
);
|
|
1050
|
+
const now = Date.now();
|
|
1051
|
+
const j = {
|
|
1052
|
+
id,
|
|
1053
|
+
profileId,
|
|
1054
|
+
runId: runId || "",
|
|
1055
|
+
status: AUTAGOV_RUN_LIFECYCLE_V2.QUEUED,
|
|
1056
|
+
createdAt: now,
|
|
1057
|
+
updatedAt: now,
|
|
1058
|
+
startedAt: null,
|
|
1059
|
+
settledAt: null,
|
|
1060
|
+
metadata: { ...(metadata || {}) },
|
|
1061
|
+
};
|
|
1062
|
+
_autagovJsV2.set(id, j);
|
|
1063
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1064
|
+
}
|
|
1065
|
+
export function runningAutagRunV2(id) {
|
|
1066
|
+
const j = _autagovJsV2.get(id);
|
|
1067
|
+
if (!j) throw new Error(`autagov run ${id} not found`);
|
|
1068
|
+
_autagovCheckJ(j.status, AUTAGOV_RUN_LIFECYCLE_V2.RUNNING);
|
|
1069
|
+
const now = Date.now();
|
|
1070
|
+
j.status = AUTAGOV_RUN_LIFECYCLE_V2.RUNNING;
|
|
1071
|
+
j.updatedAt = now;
|
|
1072
|
+
if (!j.startedAt) j.startedAt = now;
|
|
1073
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1074
|
+
}
|
|
1075
|
+
export function completeRunAutagV2(id) {
|
|
1076
|
+
const j = _autagovJsV2.get(id);
|
|
1077
|
+
if (!j) throw new Error(`autagov run ${id} not found`);
|
|
1078
|
+
_autagovCheckJ(j.status, AUTAGOV_RUN_LIFECYCLE_V2.FINISHED);
|
|
1079
|
+
const now = Date.now();
|
|
1080
|
+
j.status = AUTAGOV_RUN_LIFECYCLE_V2.FINISHED;
|
|
1081
|
+
j.updatedAt = now;
|
|
1082
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1083
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1084
|
+
}
|
|
1085
|
+
export function failAutagRunV2(id, reason) {
|
|
1086
|
+
const j = _autagovJsV2.get(id);
|
|
1087
|
+
if (!j) throw new Error(`autagov run ${id} not found`);
|
|
1088
|
+
_autagovCheckJ(j.status, AUTAGOV_RUN_LIFECYCLE_V2.FAILED);
|
|
1089
|
+
const now = Date.now();
|
|
1090
|
+
j.status = AUTAGOV_RUN_LIFECYCLE_V2.FAILED;
|
|
1091
|
+
j.updatedAt = now;
|
|
1092
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1093
|
+
if (reason) j.metadata.failReason = String(reason);
|
|
1094
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1095
|
+
}
|
|
1096
|
+
export function cancelAutagRunV2(id, reason) {
|
|
1097
|
+
const j = _autagovJsV2.get(id);
|
|
1098
|
+
if (!j) throw new Error(`autagov run ${id} not found`);
|
|
1099
|
+
_autagovCheckJ(j.status, AUTAGOV_RUN_LIFECYCLE_V2.CANCELLED);
|
|
1100
|
+
const now = Date.now();
|
|
1101
|
+
j.status = AUTAGOV_RUN_LIFECYCLE_V2.CANCELLED;
|
|
1102
|
+
j.updatedAt = now;
|
|
1103
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1104
|
+
if (reason) j.metadata.cancelReason = String(reason);
|
|
1105
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1106
|
+
}
|
|
1107
|
+
export function getAutagRunV2(id) {
|
|
1108
|
+
const j = _autagovJsV2.get(id);
|
|
1109
|
+
if (!j) return null;
|
|
1110
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1111
|
+
}
|
|
1112
|
+
export function listAutagRunsV2() {
|
|
1113
|
+
return [..._autagovJsV2.values()].map((j) => ({
|
|
1114
|
+
...j,
|
|
1115
|
+
metadata: { ...j.metadata },
|
|
1116
|
+
}));
|
|
1117
|
+
}
|
|
1118
|
+
export function autoPausedIdleAutagProfilesV2({ now } = {}) {
|
|
1119
|
+
const t = now ?? Date.now();
|
|
1120
|
+
const flipped = [];
|
|
1121
|
+
for (const p of _autagovPsV2.values())
|
|
1122
|
+
if (
|
|
1123
|
+
p.status === AUTAGOV_PROFILE_MATURITY_V2.ACTIVE &&
|
|
1124
|
+
t - p.lastTouchedAt >= _autagovIdleMs
|
|
1125
|
+
) {
|
|
1126
|
+
p.status = AUTAGOV_PROFILE_MATURITY_V2.PAUSED;
|
|
1127
|
+
p.updatedAt = t;
|
|
1128
|
+
flipped.push(p.id);
|
|
1129
|
+
}
|
|
1130
|
+
return { flipped, count: flipped.length };
|
|
1131
|
+
}
|
|
1132
|
+
export function autoFailStuckAutagRunsV2({ now } = {}) {
|
|
1133
|
+
const t = now ?? Date.now();
|
|
1134
|
+
const flipped = [];
|
|
1135
|
+
for (const j of _autagovJsV2.values())
|
|
1136
|
+
if (
|
|
1137
|
+
j.status === AUTAGOV_RUN_LIFECYCLE_V2.RUNNING &&
|
|
1138
|
+
j.startedAt != null &&
|
|
1139
|
+
t - j.startedAt >= _autagovStuckMs
|
|
1140
|
+
) {
|
|
1141
|
+
j.status = AUTAGOV_RUN_LIFECYCLE_V2.FAILED;
|
|
1142
|
+
j.updatedAt = t;
|
|
1143
|
+
if (!j.settledAt) j.settledAt = t;
|
|
1144
|
+
j.metadata.failReason = "auto-fail-stuck";
|
|
1145
|
+
flipped.push(j.id);
|
|
1146
|
+
}
|
|
1147
|
+
return { flipped, count: flipped.length };
|
|
1148
|
+
}
|
|
1149
|
+
export function getAutagovStatsV2() {
|
|
1150
|
+
const profilesByStatus = {};
|
|
1151
|
+
for (const v of Object.values(AUTAGOV_PROFILE_MATURITY_V2))
|
|
1152
|
+
profilesByStatus[v] = 0;
|
|
1153
|
+
for (const p of _autagovPsV2.values()) profilesByStatus[p.status]++;
|
|
1154
|
+
const runsByStatus = {};
|
|
1155
|
+
for (const v of Object.values(AUTAGOV_RUN_LIFECYCLE_V2)) runsByStatus[v] = 0;
|
|
1156
|
+
for (const j of _autagovJsV2.values()) runsByStatus[j.status]++;
|
|
1157
|
+
return {
|
|
1158
|
+
totalAutagProfilesV2: _autagovPsV2.size,
|
|
1159
|
+
totalAutagRunsV2: _autagovJsV2.size,
|
|
1160
|
+
maxActiveAutagProfilesPerOwner: _autagovMaxActive,
|
|
1161
|
+
maxPendingAutagRunsPerProfile: _autagovMaxPending,
|
|
1162
|
+
autagovProfileIdleMs: _autagovIdleMs,
|
|
1163
|
+
autagovRunStuckMs: _autagovStuckMs,
|
|
1164
|
+
profilesByStatus,
|
|
1165
|
+
runsByStatus,
|
|
1166
|
+
};
|
|
1167
|
+
}
|