chainlesschain 0.81.0 → 0.143.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/bin/chainlesschain.js +0 -0
- package/package.json +1 -1
- package/src/commands/a2a.js +62 -0
- package/src/commands/activitypub.js +61 -0
- package/src/commands/agent-network.js +254 -1
- package/src/commands/agent.js +117 -0
- package/src/commands/audit.js +302 -0
- package/src/commands/automation.js +271 -1
- package/src/commands/bi.js +61 -0
- package/src/commands/bm25.js +78 -0
- package/src/commands/browse.js +64 -0
- package/src/commands/ccron.js +78 -0
- package/src/commands/codegen.js +224 -0
- package/src/commands/collab.js +341 -0
- package/src/commands/compliance.js +1075 -0
- package/src/commands/compt.js +78 -0
- package/src/commands/consol.js +231 -0
- package/src/commands/cowork.js +263 -0
- package/src/commands/crosschain.js +62 -0
- package/src/commands/dao.js +62 -0
- package/src/commands/dbevo.js +284 -0
- package/src/commands/dev.js +252 -0
- package/src/commands/did.js +358 -0
- package/src/commands/dlp.js +61 -0
- package/src/commands/economy.js +56 -0
- package/src/commands/encrypt.js +341 -0
- package/src/commands/evolution.js +56 -0
- package/src/commands/evomap.js +61 -0
- package/src/commands/export.js +256 -1
- package/src/commands/fflag.js +178 -0
- package/src/commands/fusion.js +258 -0
- package/src/commands/git.js +45 -0
- package/src/commands/governance.js +325 -0
- package/src/commands/hardening.js +411 -0
- package/src/commands/hmemory.js +56 -0
- package/src/commands/hook.js +148 -0
- package/src/commands/import.js +252 -0
- package/src/commands/incentive.js +322 -0
- package/src/commands/inference.js +42 -0
- package/src/commands/infra.js +244 -0
- package/src/commands/instinct.js +260 -0
- package/src/commands/ipfs.js +318 -0
- package/src/commands/itbudget.js +45 -0
- package/src/commands/kg.js +387 -0
- package/src/commands/llm.js +263 -0
- package/src/commands/lowcode.js +44 -0
- package/src/commands/matrix.js +62 -0
- package/src/commands/mcp.js +221 -0
- package/src/commands/mcpscaf.js +41 -0
- package/src/commands/meminj.js +41 -0
- package/src/commands/memory.js +248 -0
- package/src/commands/multimodal.js +296 -0
- package/src/commands/nlprog.js +356 -0
- package/src/commands/nostr.js +62 -0
- package/src/commands/note.js +244 -0
- package/src/commands/ops.js +354 -0
- package/src/commands/orchestrate.js +166 -0
- package/src/commands/orchgov.js +45 -0
- package/src/commands/org.js +277 -0
- package/src/commands/p2p.js +390 -0
- package/src/commands/pdfp.js +78 -0
- package/src/commands/perception.js +290 -0
- package/src/commands/perf.js +39 -0
- package/src/commands/perm.js +45 -0
- package/src/commands/permmem.js +251 -0
- package/src/commands/pipeline.js +57 -1
- package/src/commands/planmode.js +45 -0
- package/src/commands/plugin-ecosystem.js +273 -0
- package/src/commands/pqc.js +393 -0
- package/src/commands/promcomp.js +82 -0
- package/src/commands/quantization.js +351 -0
- package/src/commands/rcache.js +271 -0
- package/src/commands/recommend.js +382 -0
- package/src/commands/runtime.js +307 -0
- package/src/commands/scim.js +262 -0
- package/src/commands/seshhook.js +41 -0
- package/src/commands/seshsearch.js +41 -0
- package/src/commands/seshtail.js +41 -0
- package/src/commands/seshu.js +41 -0
- package/src/commands/session.js +258 -0
- package/src/commands/sganal.js +78 -0
- package/src/commands/siem.js +40 -0
- package/src/commands/skill.js +267 -1
- package/src/commands/slotfill.js +41 -0
- package/src/commands/social.js +290 -0
- package/src/commands/sso.js +186 -1
- package/src/commands/svccont.js +45 -0
- package/src/commands/sync.js +256 -0
- package/src/commands/tech.js +338 -0
- package/src/commands/tenant.js +351 -0
- package/src/commands/tms.js +45 -0
- package/src/commands/tokens.js +269 -0
- package/src/commands/topiccls.js +45 -0
- package/src/commands/trust.js +249 -0
- package/src/commands/uprof.js +45 -0
- package/src/commands/vcheck.js +78 -0
- package/src/commands/wallet.js +277 -0
- package/src/commands/webfetch.js +41 -0
- package/src/commands/workflow.js +171 -0
- package/src/commands/zkp.js +62 -0
- package/src/harness/prompt-compressor.js +331 -0
- package/src/index.js +65 -1
- package/src/lib/a2a-protocol.js +105 -0
- package/src/lib/activitypub-bridge.js +105 -0
- package/src/lib/agent-coordinator.js +325 -0
- package/src/lib/agent-economy.js +105 -0
- package/src/lib/agent-network.js +387 -0
- package/src/lib/agent-router.js +395 -0
- package/src/lib/aiops.js +478 -0
- package/src/lib/app-builder.js +105 -0
- package/src/lib/audit-logger.js +379 -0
- package/src/lib/automation-engine.js +330 -0
- package/src/lib/autonomous-agent.js +105 -0
- package/src/lib/autonomous-developer.js +350 -0
- package/src/lib/bi-engine.js +105 -0
- package/src/lib/bm25-search.js +81 -0
- package/src/lib/browser-automation.js +105 -0
- package/src/lib/code-agent.js +323 -0
- package/src/lib/collaboration-governance.js +364 -0
- package/src/lib/community-governance.js +436 -0
- package/src/lib/compliance-framework-reporter.js +105 -0
- package/src/lib/compliance-manager.js +434 -0
- package/src/lib/compression-telemetry.js +81 -0
- package/src/lib/content-recommendation.js +469 -0
- package/src/lib/content-recommender.js +105 -0
- package/src/lib/cowork-cron.js +81 -0
- package/src/lib/cowork-task-runner.js +105 -0
- package/src/lib/cross-chain.js +105 -0
- package/src/lib/crypto-manager.js +350 -0
- package/src/lib/dao-governance.js +105 -0
- package/src/lib/dbevo.js +338 -0
- package/src/lib/decentral-infra.js +340 -0
- package/src/lib/did-manager.js +367 -0
- package/src/lib/dlp-engine.js +105 -0
- package/src/lib/evolution-system.js +105 -0
- package/src/lib/evomap-manager.js +105 -0
- package/src/lib/execution-backend.js +105 -0
- package/src/lib/feature-flags.js +85 -0
- package/src/lib/git-integration.js +105 -0
- package/src/lib/hardening-manager.js +348 -0
- package/src/lib/hierarchical-memory.js +105 -0
- package/src/lib/hook-manager.js +380 -0
- package/src/lib/inference-network.js +105 -0
- package/src/lib/instinct-manager.js +332 -0
- package/src/lib/ipfs-storage.js +334 -0
- package/src/lib/iteration-budget.js +105 -0
- package/src/lib/knowledge-exporter.js +381 -0
- package/src/lib/knowledge-graph.js +432 -0
- package/src/lib/knowledge-importer.js +379 -0
- package/src/lib/llm-providers.js +391 -0
- package/src/lib/matrix-bridge.js +105 -0
- package/src/lib/mcp-registry.js +333 -0
- package/src/lib/mcp-scaffold.js +81 -0
- package/src/lib/memory-injection.js +81 -0
- package/src/lib/memory-manager.js +330 -0
- package/src/lib/multimodal.js +346 -0
- package/src/lib/nl-programming.js +343 -0
- package/src/lib/nostr-bridge.js +105 -0
- package/src/lib/note-versioning.js +327 -0
- package/src/lib/orchestrator.js +105 -0
- package/src/lib/org-manager.js +323 -0
- package/src/lib/p2p-manager.js +387 -0
- package/src/lib/pdf-parser.js +81 -0
- package/src/lib/perception.js +346 -0
- package/src/lib/perf-tuning.js +109 -1
- package/src/lib/permanent-memory.js +320 -0
- package/src/lib/permission-engine.js +81 -0
- package/src/lib/pipeline-orchestrator.js +105 -0
- package/src/lib/plan-mode.js +81 -0
- package/src/lib/plugin-ecosystem.js +377 -0
- package/src/lib/pqc-manager.js +368 -0
- package/src/lib/prompt-compressor.js +1 -10
- package/src/lib/protocol-fusion.js +417 -0
- package/src/lib/quantization.js +325 -0
- package/src/lib/response-cache.js +327 -0
- package/src/lib/scim-manager.js +329 -0
- package/src/lib/service-container.js +81 -0
- package/src/lib/session-consolidator.js +105 -0
- package/src/lib/session-hooks.js +81 -0
- package/src/lib/session-manager.js +329 -0
- package/src/lib/session-search.js +81 -0
- package/src/lib/session-tail.js +81 -0
- package/src/lib/session-usage.js +83 -0
- package/src/lib/siem-exporter.js +105 -0
- package/src/lib/skill-loader.js +377 -0
- package/src/lib/slot-filler.js +81 -0
- package/src/lib/social-graph-analytics.js +81 -0
- package/src/lib/social-graph.js +81 -0
- package/src/lib/social-manager.js +326 -0
- package/src/lib/sso-manager.js +332 -0
- package/src/lib/sub-agent-registry.js +110 -0
- package/src/lib/sync-manager.js +326 -0
- package/src/lib/task-model-selector.js +81 -0
- package/src/lib/tech-learning-engine.js +369 -0
- package/src/lib/tenant-saas.js +460 -0
- package/src/lib/threat-intel.js +335 -0
- package/src/lib/todo-manager.js +105 -0
- package/src/lib/token-incentive.js +293 -0
- package/src/lib/token-tracker.js +329 -0
- package/src/lib/topic-classifier.js +105 -0
- package/src/lib/trust-security.js +390 -0
- package/src/lib/ueba.js +389 -0
- package/src/lib/universal-runtime.js +325 -0
- package/src/lib/user-profile.js +81 -0
- package/src/lib/version-checker.js +81 -0
- package/src/lib/wallet-manager.js +326 -0
- package/src/lib/web-fetch.js +81 -0
- package/src/lib/workflow-engine.js +322 -0
- package/src/lib/zkp-engine.js +105 -0
package/src/lib/sso-manager.js
CHANGED
|
@@ -839,3 +839,335 @@ export function getStats(db) {
|
|
|
839
839
|
},
|
|
840
840
|
};
|
|
841
841
|
}
|
|
842
|
+
|
|
843
|
+
// ===== V2 Surface (cli 0.130.0) — in-memory governance =====
|
|
844
|
+
export const PROVIDER_MATURITY_V2 = Object.freeze({
|
|
845
|
+
PENDING: "pending",
|
|
846
|
+
ACTIVE: "active",
|
|
847
|
+
DEPRECATED: "deprecated",
|
|
848
|
+
RETIRED: "retired",
|
|
849
|
+
});
|
|
850
|
+
export const LOGIN_LIFECYCLE_V2 = Object.freeze({
|
|
851
|
+
QUEUED: "queued",
|
|
852
|
+
AUTHENTICATING: "authenticating",
|
|
853
|
+
AUTHENTICATED: "authenticated",
|
|
854
|
+
FAILED: "failed",
|
|
855
|
+
CANCELLED: "cancelled",
|
|
856
|
+
});
|
|
857
|
+
|
|
858
|
+
const _PM_V2 = PROVIDER_MATURITY_V2;
|
|
859
|
+
const _LL_V2 = LOGIN_LIFECYCLE_V2;
|
|
860
|
+
const _PM_TRANS_V2 = new Map([
|
|
861
|
+
[_PM_V2.PENDING, new Set([_PM_V2.ACTIVE, _PM_V2.RETIRED])],
|
|
862
|
+
[_PM_V2.ACTIVE, new Set([_PM_V2.DEPRECATED, _PM_V2.RETIRED])],
|
|
863
|
+
[_PM_V2.DEPRECATED, new Set([_PM_V2.ACTIVE, _PM_V2.RETIRED])],
|
|
864
|
+
[_PM_V2.RETIRED, new Set()],
|
|
865
|
+
]);
|
|
866
|
+
const _LL_TRANS_V2 = new Map([
|
|
867
|
+
[_LL_V2.QUEUED, new Set([_LL_V2.AUTHENTICATING, _LL_V2.CANCELLED])],
|
|
868
|
+
[
|
|
869
|
+
_LL_V2.AUTHENTICATING,
|
|
870
|
+
new Set([_LL_V2.AUTHENTICATED, _LL_V2.FAILED, _LL_V2.CANCELLED]),
|
|
871
|
+
],
|
|
872
|
+
[_LL_V2.AUTHENTICATED, new Set()],
|
|
873
|
+
[_LL_V2.FAILED, new Set()],
|
|
874
|
+
[_LL_V2.CANCELLED, new Set()],
|
|
875
|
+
]);
|
|
876
|
+
const _LL_TERM_V2 = new Set([
|
|
877
|
+
_LL_V2.AUTHENTICATED,
|
|
878
|
+
_LL_V2.FAILED,
|
|
879
|
+
_LL_V2.CANCELLED,
|
|
880
|
+
]);
|
|
881
|
+
|
|
882
|
+
const SSO_DEFAULT_MAX_ACTIVE_PROVIDERS_PER_OWNER = 8;
|
|
883
|
+
const SSO_DEFAULT_MAX_PENDING_LOGINS_PER_PROVIDER = 16;
|
|
884
|
+
const SSO_DEFAULT_PROVIDER_IDLE_MS = 30 * 24 * 60 * 60 * 1000;
|
|
885
|
+
const SSO_DEFAULT_LOGIN_STUCK_MS = 5 * 60 * 1000;
|
|
886
|
+
|
|
887
|
+
const _ssoProvidersV2 = new Map();
|
|
888
|
+
const _ssoLoginsV2 = new Map();
|
|
889
|
+
let _ssoConfigV2 = {
|
|
890
|
+
maxActiveProvidersPerOwner: SSO_DEFAULT_MAX_ACTIVE_PROVIDERS_PER_OWNER,
|
|
891
|
+
maxPendingLoginsPerProvider: SSO_DEFAULT_MAX_PENDING_LOGINS_PER_PROVIDER,
|
|
892
|
+
providerIdleMs: SSO_DEFAULT_PROVIDER_IDLE_MS,
|
|
893
|
+
loginStuckMs: SSO_DEFAULT_LOGIN_STUCK_MS,
|
|
894
|
+
};
|
|
895
|
+
|
|
896
|
+
function _ssoPosIntV2(n, label) {
|
|
897
|
+
if (typeof n !== "number" || !isFinite(n) || isNaN(n))
|
|
898
|
+
throw new Error(`${label} must be positive integer`);
|
|
899
|
+
const v = Math.floor(n);
|
|
900
|
+
if (v <= 0) throw new Error(`${label} must be positive integer`);
|
|
901
|
+
return v;
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
export function _resetStateSsoManagerV2() {
|
|
905
|
+
_ssoProvidersV2.clear();
|
|
906
|
+
_ssoLoginsV2.clear();
|
|
907
|
+
_ssoConfigV2 = {
|
|
908
|
+
maxActiveProvidersPerOwner: SSO_DEFAULT_MAX_ACTIVE_PROVIDERS_PER_OWNER,
|
|
909
|
+
maxPendingLoginsPerProvider: SSO_DEFAULT_MAX_PENDING_LOGINS_PER_PROVIDER,
|
|
910
|
+
providerIdleMs: SSO_DEFAULT_PROVIDER_IDLE_MS,
|
|
911
|
+
loginStuckMs: SSO_DEFAULT_LOGIN_STUCK_MS,
|
|
912
|
+
};
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
export function setMaxActiveProvidersPerOwnerV2(n) {
|
|
916
|
+
_ssoConfigV2.maxActiveProvidersPerOwner = _ssoPosIntV2(
|
|
917
|
+
n,
|
|
918
|
+
"maxActiveProvidersPerOwner",
|
|
919
|
+
);
|
|
920
|
+
}
|
|
921
|
+
export function setMaxPendingLoginsPerProviderV2(n) {
|
|
922
|
+
_ssoConfigV2.maxPendingLoginsPerProvider = _ssoPosIntV2(
|
|
923
|
+
n,
|
|
924
|
+
"maxPendingLoginsPerProvider",
|
|
925
|
+
);
|
|
926
|
+
}
|
|
927
|
+
export function setProviderIdleMsV2(n) {
|
|
928
|
+
_ssoConfigV2.providerIdleMs = _ssoPosIntV2(n, "providerIdleMs");
|
|
929
|
+
}
|
|
930
|
+
export function setLoginStuckMsV2(n) {
|
|
931
|
+
_ssoConfigV2.loginStuckMs = _ssoPosIntV2(n, "loginStuckMs");
|
|
932
|
+
}
|
|
933
|
+
export function getMaxActiveProvidersPerOwnerV2() {
|
|
934
|
+
return _ssoConfigV2.maxActiveProvidersPerOwner;
|
|
935
|
+
}
|
|
936
|
+
export function getMaxPendingLoginsPerProviderV2() {
|
|
937
|
+
return _ssoConfigV2.maxPendingLoginsPerProvider;
|
|
938
|
+
}
|
|
939
|
+
export function getProviderIdleMsV2() {
|
|
940
|
+
return _ssoConfigV2.providerIdleMs;
|
|
941
|
+
}
|
|
942
|
+
export function getLoginStuckMsV2() {
|
|
943
|
+
return _ssoConfigV2.loginStuckMs;
|
|
944
|
+
}
|
|
945
|
+
|
|
946
|
+
function _copyProviderV2(p) {
|
|
947
|
+
return { ...p, metadata: { ...(p.metadata || {}) } };
|
|
948
|
+
}
|
|
949
|
+
function _copyLoginV2(l) {
|
|
950
|
+
return { ...l, metadata: { ...(l.metadata || {}) } };
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
export function registerProviderV2({
|
|
954
|
+
id,
|
|
955
|
+
owner,
|
|
956
|
+
protocol,
|
|
957
|
+
displayName,
|
|
958
|
+
metadata,
|
|
959
|
+
} = {}) {
|
|
960
|
+
if (!id || typeof id !== "string") throw new Error("id required");
|
|
961
|
+
if (!owner || typeof owner !== "string") throw new Error("owner required");
|
|
962
|
+
if (!protocol || typeof protocol !== "string")
|
|
963
|
+
throw new Error("protocol required");
|
|
964
|
+
if (_ssoProvidersV2.has(id))
|
|
965
|
+
throw new Error(`provider ${id} already registered`);
|
|
966
|
+
const now = Date.now();
|
|
967
|
+
const p = {
|
|
968
|
+
id,
|
|
969
|
+
owner,
|
|
970
|
+
protocol,
|
|
971
|
+
displayName: displayName || id,
|
|
972
|
+
status: _PM_V2.PENDING,
|
|
973
|
+
activatedAt: null,
|
|
974
|
+
retiredAt: null,
|
|
975
|
+
lastSeenAt: now,
|
|
976
|
+
createdAt: now,
|
|
977
|
+
metadata: metadata && typeof metadata === "object" ? { ...metadata } : {},
|
|
978
|
+
};
|
|
979
|
+
_ssoProvidersV2.set(id, p);
|
|
980
|
+
return _copyProviderV2(p);
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
function _activeProviderCountForOwnerV2(owner) {
|
|
984
|
+
let c = 0;
|
|
985
|
+
for (const p of _ssoProvidersV2.values())
|
|
986
|
+
if (p.owner === owner && p.status === _PM_V2.ACTIVE) c++;
|
|
987
|
+
return c;
|
|
988
|
+
}
|
|
989
|
+
|
|
990
|
+
function _transitionProviderV2(id, next) {
|
|
991
|
+
const p = _ssoProvidersV2.get(id);
|
|
992
|
+
if (!p) throw new Error(`provider ${id} not found`);
|
|
993
|
+
const allowed = _PM_TRANS_V2.get(p.status);
|
|
994
|
+
if (!allowed || !allowed.has(next))
|
|
995
|
+
throw new Error(`invalid transition ${p.status} -> ${next}`);
|
|
996
|
+
if (next === _PM_V2.ACTIVE && p.status === _PM_V2.PENDING) {
|
|
997
|
+
if (
|
|
998
|
+
_activeProviderCountForOwnerV2(p.owner) >=
|
|
999
|
+
_ssoConfigV2.maxActiveProvidersPerOwner
|
|
1000
|
+
) {
|
|
1001
|
+
throw new Error(
|
|
1002
|
+
`owner ${p.owner} active-provider cap reached (${_ssoConfigV2.maxActiveProvidersPerOwner})`,
|
|
1003
|
+
);
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
const now = Date.now();
|
|
1007
|
+
p.status = next;
|
|
1008
|
+
if (next === _PM_V2.ACTIVE && !p.activatedAt) p.activatedAt = now;
|
|
1009
|
+
if (next === _PM_V2.RETIRED && !p.retiredAt) p.retiredAt = now;
|
|
1010
|
+
p.lastSeenAt = now;
|
|
1011
|
+
return _copyProviderV2(p);
|
|
1012
|
+
}
|
|
1013
|
+
|
|
1014
|
+
export function activateProviderV2(id) {
|
|
1015
|
+
return _transitionProviderV2(id, _PM_V2.ACTIVE);
|
|
1016
|
+
}
|
|
1017
|
+
export function deprecateProviderV2(id) {
|
|
1018
|
+
return _transitionProviderV2(id, _PM_V2.DEPRECATED);
|
|
1019
|
+
}
|
|
1020
|
+
export function retireProviderV2(id) {
|
|
1021
|
+
return _transitionProviderV2(id, _PM_V2.RETIRED);
|
|
1022
|
+
}
|
|
1023
|
+
export function touchProviderV2(id) {
|
|
1024
|
+
const p = _ssoProvidersV2.get(id);
|
|
1025
|
+
if (!p) throw new Error(`provider ${id} not found`);
|
|
1026
|
+
p.lastSeenAt = Date.now();
|
|
1027
|
+
return _copyProviderV2(p);
|
|
1028
|
+
}
|
|
1029
|
+
export function getProviderV2(id) {
|
|
1030
|
+
const p = _ssoProvidersV2.get(id);
|
|
1031
|
+
return p ? _copyProviderV2(p) : null;
|
|
1032
|
+
}
|
|
1033
|
+
export function listProvidersV2({ owner, status, protocol } = {}) {
|
|
1034
|
+
const out = [];
|
|
1035
|
+
for (const p of _ssoProvidersV2.values()) {
|
|
1036
|
+
if (owner && p.owner !== owner) continue;
|
|
1037
|
+
if (status && p.status !== status) continue;
|
|
1038
|
+
if (protocol && p.protocol !== protocol) continue;
|
|
1039
|
+
out.push(_copyProviderV2(p));
|
|
1040
|
+
}
|
|
1041
|
+
return out;
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
function _pendingLoginCountForProviderV2(providerId) {
|
|
1045
|
+
let c = 0;
|
|
1046
|
+
for (const l of _ssoLoginsV2.values()) {
|
|
1047
|
+
if (l.providerId !== providerId) continue;
|
|
1048
|
+
if (l.status === _LL_V2.QUEUED || l.status === _LL_V2.AUTHENTICATING) c++;
|
|
1049
|
+
}
|
|
1050
|
+
return c;
|
|
1051
|
+
}
|
|
1052
|
+
|
|
1053
|
+
export function createLoginV2({ id, providerId, subject, metadata } = {}) {
|
|
1054
|
+
if (!id || typeof id !== "string") throw new Error("id required");
|
|
1055
|
+
if (!providerId || typeof providerId !== "string")
|
|
1056
|
+
throw new Error("providerId required");
|
|
1057
|
+
if (_ssoLoginsV2.has(id)) throw new Error(`login ${id} already exists`);
|
|
1058
|
+
const provider = _ssoProvidersV2.get(providerId);
|
|
1059
|
+
if (!provider) throw new Error(`provider ${providerId} not found`);
|
|
1060
|
+
if (provider.status === _PM_V2.RETIRED)
|
|
1061
|
+
throw new Error(`provider ${providerId} retired`);
|
|
1062
|
+
if (
|
|
1063
|
+
_pendingLoginCountForProviderV2(providerId) >=
|
|
1064
|
+
_ssoConfigV2.maxPendingLoginsPerProvider
|
|
1065
|
+
) {
|
|
1066
|
+
throw new Error(
|
|
1067
|
+
`provider ${providerId} pending-login cap reached (${_ssoConfigV2.maxPendingLoginsPerProvider})`,
|
|
1068
|
+
);
|
|
1069
|
+
}
|
|
1070
|
+
const now = Date.now();
|
|
1071
|
+
const l = {
|
|
1072
|
+
id,
|
|
1073
|
+
providerId,
|
|
1074
|
+
subject: subject || "anonymous",
|
|
1075
|
+
status: _LL_V2.QUEUED,
|
|
1076
|
+
startedAt: null,
|
|
1077
|
+
settledAt: null,
|
|
1078
|
+
createdAt: now,
|
|
1079
|
+
metadata: metadata && typeof metadata === "object" ? { ...metadata } : {},
|
|
1080
|
+
};
|
|
1081
|
+
_ssoLoginsV2.set(id, l);
|
|
1082
|
+
return _copyLoginV2(l);
|
|
1083
|
+
}
|
|
1084
|
+
|
|
1085
|
+
function _transitionLoginV2(id, next, extra = {}) {
|
|
1086
|
+
const l = _ssoLoginsV2.get(id);
|
|
1087
|
+
if (!l) throw new Error(`login ${id} not found`);
|
|
1088
|
+
const allowed = _LL_TRANS_V2.get(l.status);
|
|
1089
|
+
if (!allowed || !allowed.has(next))
|
|
1090
|
+
throw new Error(`invalid transition ${l.status} -> ${next}`);
|
|
1091
|
+
const now = Date.now();
|
|
1092
|
+
l.status = next;
|
|
1093
|
+
if (next === _LL_V2.AUTHENTICATING && !l.startedAt) l.startedAt = now;
|
|
1094
|
+
if (_LL_TERM_V2.has(next) && !l.settledAt) l.settledAt = now;
|
|
1095
|
+
if (extra.error) l.metadata.error = extra.error;
|
|
1096
|
+
return _copyLoginV2(l);
|
|
1097
|
+
}
|
|
1098
|
+
|
|
1099
|
+
export function startLoginV2(id) {
|
|
1100
|
+
return _transitionLoginV2(id, _LL_V2.AUTHENTICATING);
|
|
1101
|
+
}
|
|
1102
|
+
export function completeLoginV2(id) {
|
|
1103
|
+
return _transitionLoginV2(id, _LL_V2.AUTHENTICATED);
|
|
1104
|
+
}
|
|
1105
|
+
export function failLoginV2(id, error) {
|
|
1106
|
+
return _transitionLoginV2(id, _LL_V2.FAILED, { error });
|
|
1107
|
+
}
|
|
1108
|
+
export function cancelLoginV2(id) {
|
|
1109
|
+
return _transitionLoginV2(id, _LL_V2.CANCELLED);
|
|
1110
|
+
}
|
|
1111
|
+
|
|
1112
|
+
export function getLoginV2(id) {
|
|
1113
|
+
const l = _ssoLoginsV2.get(id);
|
|
1114
|
+
return l ? _copyLoginV2(l) : null;
|
|
1115
|
+
}
|
|
1116
|
+
export function listLoginsV2({ providerId, status, subject } = {}) {
|
|
1117
|
+
const out = [];
|
|
1118
|
+
for (const l of _ssoLoginsV2.values()) {
|
|
1119
|
+
if (providerId && l.providerId !== providerId) continue;
|
|
1120
|
+
if (status && l.status !== status) continue;
|
|
1121
|
+
if (subject && l.subject !== subject) continue;
|
|
1122
|
+
out.push(_copyLoginV2(l));
|
|
1123
|
+
}
|
|
1124
|
+
return out;
|
|
1125
|
+
}
|
|
1126
|
+
|
|
1127
|
+
export function autoDeprecateIdleProvidersV2({ now } = {}) {
|
|
1128
|
+
const t = typeof now === "number" ? now : Date.now();
|
|
1129
|
+
const flipped = [];
|
|
1130
|
+
for (const p of _ssoProvidersV2.values()) {
|
|
1131
|
+
if (p.status !== _PM_V2.ACTIVE) continue;
|
|
1132
|
+
if (t - p.lastSeenAt > _ssoConfigV2.providerIdleMs) {
|
|
1133
|
+
p.status = _PM_V2.DEPRECATED;
|
|
1134
|
+
p.lastSeenAt = t;
|
|
1135
|
+
flipped.push(_copyProviderV2(p));
|
|
1136
|
+
}
|
|
1137
|
+
}
|
|
1138
|
+
return flipped;
|
|
1139
|
+
}
|
|
1140
|
+
|
|
1141
|
+
export function autoFailStuckLoginsV2({ now } = {}) {
|
|
1142
|
+
const t = typeof now === "number" ? now : Date.now();
|
|
1143
|
+
const flipped = [];
|
|
1144
|
+
for (const l of _ssoLoginsV2.values()) {
|
|
1145
|
+
if (l.status !== _LL_V2.AUTHENTICATING) continue;
|
|
1146
|
+
if (l.startedAt && t - l.startedAt > _ssoConfigV2.loginStuckMs) {
|
|
1147
|
+
l.status = _LL_V2.FAILED;
|
|
1148
|
+
l.settledAt = t;
|
|
1149
|
+
l.metadata.error = "stuck-timeout";
|
|
1150
|
+
flipped.push(_copyLoginV2(l));
|
|
1151
|
+
}
|
|
1152
|
+
}
|
|
1153
|
+
return flipped;
|
|
1154
|
+
}
|
|
1155
|
+
|
|
1156
|
+
export function getSsoManagerStatsV2() {
|
|
1157
|
+
const providersByStatus = {};
|
|
1158
|
+
for (const s of Object.values(_PM_V2)) providersByStatus[s] = 0;
|
|
1159
|
+
for (const p of _ssoProvidersV2.values()) providersByStatus[p.status]++;
|
|
1160
|
+
const loginsByStatus = {};
|
|
1161
|
+
for (const s of Object.values(_LL_V2)) loginsByStatus[s] = 0;
|
|
1162
|
+
for (const l of _ssoLoginsV2.values()) loginsByStatus[l.status]++;
|
|
1163
|
+
return {
|
|
1164
|
+
totalProvidersV2: _ssoProvidersV2.size,
|
|
1165
|
+
totalLoginsV2: _ssoLoginsV2.size,
|
|
1166
|
+
maxActiveProvidersPerOwner: _ssoConfigV2.maxActiveProvidersPerOwner,
|
|
1167
|
+
maxPendingLoginsPerProvider: _ssoConfigV2.maxPendingLoginsPerProvider,
|
|
1168
|
+
providerIdleMs: _ssoConfigV2.providerIdleMs,
|
|
1169
|
+
loginStuckMs: _ssoConfigV2.loginStuckMs,
|
|
1170
|
+
providersByStatus,
|
|
1171
|
+
loginsByStatus,
|
|
1172
|
+
};
|
|
1173
|
+
}
|
|
@@ -218,3 +218,113 @@ export class SubAgentRegistry {
|
|
|
218
218
|
};
|
|
219
219
|
}
|
|
220
220
|
}
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
// ===== V2 Surface: Sub-Agent Registry governance overlay (CLI v0.133.0) =====
|
|
224
|
+
export const SUBAGENT_PROFILE_MATURITY_V2 = Object.freeze({
|
|
225
|
+
PENDING: "pending", ACTIVE: "active", PAUSED: "paused", RETIRED: "retired",
|
|
226
|
+
});
|
|
227
|
+
export const SUBAGENT_TASK_LIFECYCLE_V2 = Object.freeze({
|
|
228
|
+
QUEUED: "queued", RUNNING: "running", COMPLETED: "completed", FAILED: "failed", CANCELLED: "cancelled",
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
const _saProfileTrans = new Map([
|
|
232
|
+
[SUBAGENT_PROFILE_MATURITY_V2.PENDING, new Set([SUBAGENT_PROFILE_MATURITY_V2.ACTIVE, SUBAGENT_PROFILE_MATURITY_V2.RETIRED])],
|
|
233
|
+
[SUBAGENT_PROFILE_MATURITY_V2.ACTIVE, new Set([SUBAGENT_PROFILE_MATURITY_V2.PAUSED, SUBAGENT_PROFILE_MATURITY_V2.RETIRED])],
|
|
234
|
+
[SUBAGENT_PROFILE_MATURITY_V2.PAUSED, new Set([SUBAGENT_PROFILE_MATURITY_V2.ACTIVE, SUBAGENT_PROFILE_MATURITY_V2.RETIRED])],
|
|
235
|
+
[SUBAGENT_PROFILE_MATURITY_V2.RETIRED, new Set()],
|
|
236
|
+
]);
|
|
237
|
+
const _saProfileTerminal = new Set([SUBAGENT_PROFILE_MATURITY_V2.RETIRED]);
|
|
238
|
+
const _saTaskTrans = new Map([
|
|
239
|
+
[SUBAGENT_TASK_LIFECYCLE_V2.QUEUED, new Set([SUBAGENT_TASK_LIFECYCLE_V2.RUNNING, SUBAGENT_TASK_LIFECYCLE_V2.CANCELLED])],
|
|
240
|
+
[SUBAGENT_TASK_LIFECYCLE_V2.RUNNING, new Set([SUBAGENT_TASK_LIFECYCLE_V2.COMPLETED, SUBAGENT_TASK_LIFECYCLE_V2.FAILED, SUBAGENT_TASK_LIFECYCLE_V2.CANCELLED])],
|
|
241
|
+
[SUBAGENT_TASK_LIFECYCLE_V2.COMPLETED, new Set()],
|
|
242
|
+
[SUBAGENT_TASK_LIFECYCLE_V2.FAILED, new Set()],
|
|
243
|
+
[SUBAGENT_TASK_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
244
|
+
]);
|
|
245
|
+
|
|
246
|
+
const _saProfiles = new Map();
|
|
247
|
+
const _saTasks = new Map();
|
|
248
|
+
let _saMaxActivePerOwner = 12;
|
|
249
|
+
let _saMaxPendingPerProfile = 24;
|
|
250
|
+
let _saProfileIdleMs = 2 * 60 * 60 * 1000;
|
|
251
|
+
let _saTaskStuckMs = 5 * 60 * 1000;
|
|
252
|
+
|
|
253
|
+
function _saPos(n, lbl) { const v = Math.floor(Number(n)); if (!Number.isFinite(v) || v <= 0) throw new Error(`${lbl} must be positive integer`); return v; }
|
|
254
|
+
|
|
255
|
+
export function setMaxActiveSubagentsPerOwnerV2(n) { _saMaxActivePerOwner = _saPos(n, "maxActiveSubagentsPerOwner"); }
|
|
256
|
+
export function getMaxActiveSubagentsPerOwnerV2() { return _saMaxActivePerOwner; }
|
|
257
|
+
export function setMaxPendingTasksPerSubagentV2(n) { _saMaxPendingPerProfile = _saPos(n, "maxPendingTasksPerSubagent"); }
|
|
258
|
+
export function getMaxPendingTasksPerSubagentV2() { return _saMaxPendingPerProfile; }
|
|
259
|
+
export function setSubagentIdleMsV2(n) { _saProfileIdleMs = _saPos(n, "subagentIdleMs"); }
|
|
260
|
+
export function getSubagentIdleMsV2() { return _saProfileIdleMs; }
|
|
261
|
+
export function setSubagentTaskStuckMsV2(n) { _saTaskStuckMs = _saPos(n, "subagentTaskStuckMs"); }
|
|
262
|
+
export function getSubagentTaskStuckMsV2() { return _saTaskStuckMs; }
|
|
263
|
+
|
|
264
|
+
export function _resetStateSubAgentRegistryV2() {
|
|
265
|
+
_saProfiles.clear(); _saTasks.clear();
|
|
266
|
+
_saMaxActivePerOwner = 12; _saMaxPendingPerProfile = 24;
|
|
267
|
+
_saProfileIdleMs = 2 * 60 * 60 * 1000; _saTaskStuckMs = 5 * 60 * 1000;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
export function registerSubagentProfileV2({ id, owner, role, metadata } = {}) {
|
|
271
|
+
if (!id || typeof id !== "string") throw new Error("id is required");
|
|
272
|
+
if (!owner || typeof owner !== "string") throw new Error("owner is required");
|
|
273
|
+
if (_saProfiles.has(id)) throw new Error(`subagent profile ${id} already registered`);
|
|
274
|
+
const now = Date.now();
|
|
275
|
+
const p = { id, owner, role: role || "generic", status: SUBAGENT_PROFILE_MATURITY_V2.PENDING,
|
|
276
|
+
createdAt: now, updatedAt: now, activatedAt: null, retiredAt: null, lastTouchedAt: now,
|
|
277
|
+
metadata: { ...(metadata || {}) } };
|
|
278
|
+
_saProfiles.set(id, p);
|
|
279
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
function _saCheckP(from, to) { const allowed = _saProfileTrans.get(from); if (!allowed || !allowed.has(to)) throw new Error(`invalid subagent profile transition ${from} → ${to}`); }
|
|
283
|
+
function _saCountActiveByOwner(owner) { let n = 0; for (const p of _saProfiles.values()) if (p.owner === owner && p.status === SUBAGENT_PROFILE_MATURITY_V2.ACTIVE) n++; return n; }
|
|
284
|
+
|
|
285
|
+
export function activateSubagentProfileV2(id) {
|
|
286
|
+
const p = _saProfiles.get(id); if (!p) throw new Error(`subagent profile ${id} not found`);
|
|
287
|
+
_saCheckP(p.status, SUBAGENT_PROFILE_MATURITY_V2.ACTIVE);
|
|
288
|
+
const recovery = p.status === SUBAGENT_PROFILE_MATURITY_V2.PAUSED;
|
|
289
|
+
if (!recovery) { const a = _saCountActiveByOwner(p.owner); if (a >= _saMaxActivePerOwner) throw new Error(`max active subagents per owner (${_saMaxActivePerOwner}) reached for ${p.owner}`); }
|
|
290
|
+
const now = Date.now(); p.status = SUBAGENT_PROFILE_MATURITY_V2.ACTIVE; p.updatedAt = now; p.lastTouchedAt = now;
|
|
291
|
+
if (!p.activatedAt) p.activatedAt = now;
|
|
292
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
293
|
+
}
|
|
294
|
+
export function pauseSubagentProfileV2(id) { const p = _saProfiles.get(id); if (!p) throw new Error(`subagent profile ${id} not found`); _saCheckP(p.status, SUBAGENT_PROFILE_MATURITY_V2.PAUSED); p.status = SUBAGENT_PROFILE_MATURITY_V2.PAUSED; p.updatedAt = Date.now(); return { ...p, metadata: { ...p.metadata } }; }
|
|
295
|
+
export function retireSubagentProfileV2(id) { const p = _saProfiles.get(id); if (!p) throw new Error(`subagent profile ${id} not found`); _saCheckP(p.status, SUBAGENT_PROFILE_MATURITY_V2.RETIRED); const now = Date.now(); p.status = SUBAGENT_PROFILE_MATURITY_V2.RETIRED; p.updatedAt = now; if (!p.retiredAt) p.retiredAt = now; return { ...p, metadata: { ...p.metadata } }; }
|
|
296
|
+
export function touchSubagentProfileV2(id) { const p = _saProfiles.get(id); if (!p) throw new Error(`subagent profile ${id} not found`); if (_saProfileTerminal.has(p.status)) throw new Error(`cannot touch terminal subagent profile ${id}`); const now = Date.now(); p.lastTouchedAt = now; p.updatedAt = now; return { ...p, metadata: { ...p.metadata } }; }
|
|
297
|
+
export function getSubagentProfileV2(id) { const p = _saProfiles.get(id); if (!p) return null; return { ...p, metadata: { ...p.metadata } }; }
|
|
298
|
+
export function listSubagentProfilesV2() { return [..._saProfiles.values()].map((p) => ({ ...p, metadata: { ...p.metadata } })); }
|
|
299
|
+
|
|
300
|
+
function _saCountPendingByProfile(pid) { let n = 0; for (const t of _saTasks.values()) if (t.profileId === pid && (t.status === SUBAGENT_TASK_LIFECYCLE_V2.QUEUED || t.status === SUBAGENT_TASK_LIFECYCLE_V2.RUNNING)) n++; return n; }
|
|
301
|
+
|
|
302
|
+
export function createSubagentTaskV2({ id, profileId, description, metadata } = {}) {
|
|
303
|
+
if (!id || typeof id !== "string") throw new Error("id is required");
|
|
304
|
+
if (!profileId || typeof profileId !== "string") throw new Error("profileId is required");
|
|
305
|
+
if (_saTasks.has(id)) throw new Error(`subagent task ${id} already exists`);
|
|
306
|
+
if (!_saProfiles.has(profileId)) throw new Error(`subagent profile ${profileId} not found`);
|
|
307
|
+
const pending = _saCountPendingByProfile(profileId);
|
|
308
|
+
if (pending >= _saMaxPendingPerProfile) throw new Error(`max pending tasks per subagent (${_saMaxPendingPerProfile}) reached for ${profileId}`);
|
|
309
|
+
const now = Date.now();
|
|
310
|
+
const t = { id, profileId, description: description || "", status: SUBAGENT_TASK_LIFECYCLE_V2.QUEUED,
|
|
311
|
+
createdAt: now, updatedAt: now, startedAt: null, settledAt: null, metadata: { ...(metadata || {}) } };
|
|
312
|
+
_saTasks.set(id, t);
|
|
313
|
+
return { ...t, metadata: { ...t.metadata } };
|
|
314
|
+
}
|
|
315
|
+
function _saCheckT(from, to) { const allowed = _saTaskTrans.get(from); if (!allowed || !allowed.has(to)) throw new Error(`invalid subagent task transition ${from} → ${to}`); }
|
|
316
|
+
export function startSubagentTaskV2(id) { const t = _saTasks.get(id); if (!t) throw new Error(`subagent task ${id} not found`); _saCheckT(t.status, SUBAGENT_TASK_LIFECYCLE_V2.RUNNING); const now = Date.now(); t.status = SUBAGENT_TASK_LIFECYCLE_V2.RUNNING; t.updatedAt = now; if (!t.startedAt) t.startedAt = now; return { ...t, metadata: { ...t.metadata } }; }
|
|
317
|
+
export function completeSubagentTaskV2(id) { const t = _saTasks.get(id); if (!t) throw new Error(`subagent task ${id} not found`); _saCheckT(t.status, SUBAGENT_TASK_LIFECYCLE_V2.COMPLETED); const now = Date.now(); t.status = SUBAGENT_TASK_LIFECYCLE_V2.COMPLETED; t.updatedAt = now; if (!t.settledAt) t.settledAt = now; return { ...t, metadata: { ...t.metadata } }; }
|
|
318
|
+
export function failSubagentTaskV2(id, reason) { const t = _saTasks.get(id); if (!t) throw new Error(`subagent task ${id} not found`); _saCheckT(t.status, SUBAGENT_TASK_LIFECYCLE_V2.FAILED); const now = Date.now(); t.status = SUBAGENT_TASK_LIFECYCLE_V2.FAILED; t.updatedAt = now; if (!t.settledAt) t.settledAt = now; if (reason) t.metadata.failReason = String(reason); return { ...t, metadata: { ...t.metadata } }; }
|
|
319
|
+
export function cancelSubagentTaskV2(id, reason) { const t = _saTasks.get(id); if (!t) throw new Error(`subagent task ${id} not found`); _saCheckT(t.status, SUBAGENT_TASK_LIFECYCLE_V2.CANCELLED); const now = Date.now(); t.status = SUBAGENT_TASK_LIFECYCLE_V2.CANCELLED; t.updatedAt = now; if (!t.settledAt) t.settledAt = now; if (reason) t.metadata.cancelReason = String(reason); return { ...t, metadata: { ...t.metadata } }; }
|
|
320
|
+
export function getSubagentTaskV2(id) { const t = _saTasks.get(id); if (!t) return null; return { ...t, metadata: { ...t.metadata } }; }
|
|
321
|
+
export function listSubagentTasksV2() { return [..._saTasks.values()].map((t) => ({ ...t, metadata: { ...t.metadata } })); }
|
|
322
|
+
|
|
323
|
+
export function autoPauseIdleSubagentsV2({ now } = {}) { const t = now ?? Date.now(); const flipped = []; for (const p of _saProfiles.values()) if (p.status === SUBAGENT_PROFILE_MATURITY_V2.ACTIVE && (t - p.lastTouchedAt) >= _saProfileIdleMs) { p.status = SUBAGENT_PROFILE_MATURITY_V2.PAUSED; p.updatedAt = t; flipped.push(p.id); } return { flipped, count: flipped.length }; }
|
|
324
|
+
export function autoFailStuckSubagentTasksV2({ now } = {}) { const t = now ?? Date.now(); const flipped = []; for (const k of _saTasks.values()) if (k.status === SUBAGENT_TASK_LIFECYCLE_V2.RUNNING && k.startedAt != null && (t - k.startedAt) >= _saTaskStuckMs) { k.status = SUBAGENT_TASK_LIFECYCLE_V2.FAILED; k.updatedAt = t; if (!k.settledAt) k.settledAt = t; k.metadata.failReason = "auto-fail-stuck"; flipped.push(k.id); } return { flipped, count: flipped.length }; }
|
|
325
|
+
|
|
326
|
+
export function getSubAgentRegistryStatsV2() {
|
|
327
|
+
const profilesByStatus = {}; for (const s of Object.values(SUBAGENT_PROFILE_MATURITY_V2)) profilesByStatus[s] = 0; for (const p of _saProfiles.values()) profilesByStatus[p.status]++;
|
|
328
|
+
const tasksByStatus = {}; for (const s of Object.values(SUBAGENT_TASK_LIFECYCLE_V2)) tasksByStatus[s] = 0; for (const t of _saTasks.values()) tasksByStatus[t.status]++;
|
|
329
|
+
return { totalProfilesV2: _saProfiles.size, totalTasksV2: _saTasks.size, maxActiveSubagentsPerOwner: _saMaxActivePerOwner, maxPendingTasksPerSubagent: _saMaxPendingPerProfile, subagentIdleMs: _saProfileIdleMs, subagentTaskStuckMs: _saTaskStuckMs, profilesByStatus, tasksByStatus };
|
|
330
|
+
}
|