chainlesschain 0.143.0 → 0.152.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (227) hide show
  1. package/package.json +1 -1
  2. package/src/commands/a2a.js +196 -28
  3. package/src/commands/activitypub.js +364 -27
  4. package/src/commands/agent-network.js +217 -0
  5. package/src/commands/agent.js +587 -103
  6. package/src/commands/audit.js +206 -0
  7. package/src/commands/automation.js +201 -0
  8. package/src/commands/bi.js +355 -27
  9. package/src/commands/bm25.js +111 -27
  10. package/src/commands/browse.js +403 -29
  11. package/src/commands/ccron.js +128 -28
  12. package/src/commands/chat.js +207 -0
  13. package/src/commands/codegen.js +207 -0
  14. package/src/commands/collab.js +211 -0
  15. package/src/commands/compliance.js +824 -34
  16. package/src/commands/compt.js +127 -29
  17. package/src/commands/consol.js +8 -2
  18. package/src/commands/cowork.js +783 -34
  19. package/src/commands/crosschain.js +182 -28
  20. package/src/commands/dao.js +182 -28
  21. package/src/commands/dbevo.js +227 -0
  22. package/src/commands/dev.js +207 -0
  23. package/src/commands/did-v2.js +217 -0
  24. package/src/commands/did.js +221 -0
  25. package/src/commands/dlp.js +385 -27
  26. package/src/commands/economy.js +205 -50
  27. package/src/commands/evolution.js +203 -50
  28. package/src/commands/evomap.js +387 -27
  29. package/src/commands/export.js +213 -0
  30. package/src/commands/federation.js +209 -0
  31. package/src/commands/fflag.js +74 -22
  32. package/src/commands/fusion.js +205 -0
  33. package/src/commands/git.js +177 -37
  34. package/src/commands/governance.js +209 -0
  35. package/src/commands/hardening.js +209 -0
  36. package/src/commands/hmemory.js +204 -50
  37. package/src/commands/hook.js +209 -0
  38. package/src/commands/import.js +209 -0
  39. package/src/commands/incentive.js +209 -0
  40. package/src/commands/inference.js +170 -34
  41. package/src/commands/infra.js +203 -0
  42. package/src/commands/instinct.js +209 -0
  43. package/src/commands/ipfs.js +207 -0
  44. package/src/commands/itbudget.js +149 -33
  45. package/src/commands/kg.js +206 -0
  46. package/src/commands/llm.js +217 -0
  47. package/src/commands/lowcode.js +195 -38
  48. package/src/commands/marketplace.js +206 -0
  49. package/src/commands/matrix.js +386 -27
  50. package/src/commands/mcp.js +217 -0
  51. package/src/commands/mcpscaf.js +145 -33
  52. package/src/commands/meminj.js +145 -33
  53. package/src/commands/memory.js +209 -0
  54. package/src/commands/multimodal.js +203 -0
  55. package/src/commands/nlprog.js +225 -0
  56. package/src/commands/nostr.js +387 -27
  57. package/src/commands/note.js +205 -0
  58. package/src/commands/ops.js +219 -0
  59. package/src/commands/orchestrate.js +217 -0
  60. package/src/commands/orchgov.js +144 -33
  61. package/src/commands/org.js +209 -0
  62. package/src/commands/p2p.js +209 -0
  63. package/src/commands/pdfp.js +109 -27
  64. package/src/commands/perception.js +209 -0
  65. package/src/commands/perf.js +169 -32
  66. package/src/commands/perm.js +144 -33
  67. package/src/commands/permmem.js +203 -0
  68. package/src/commands/pipeline.js +207 -52
  69. package/src/commands/planmode.js +141 -32
  70. package/src/commands/plugin-ecosystem.js +209 -0
  71. package/src/commands/pqc.js +213 -0
  72. package/src/commands/privacy.js +203 -0
  73. package/src/commands/promcomp.js +111 -27
  74. package/src/commands/quantization.js +207 -0
  75. package/src/commands/rcache.js +205 -0
  76. package/src/commands/recommend.js +410 -34
  77. package/src/commands/reputation.js +208 -0
  78. package/src/commands/runtime.js +205 -0
  79. package/src/commands/sandbox.js +206 -0
  80. package/src/commands/scim.js +209 -0
  81. package/src/commands/seshhook.js +145 -33
  82. package/src/commands/seshsearch.js +141 -33
  83. package/src/commands/seshtail.js +144 -33
  84. package/src/commands/seshu.js +152 -33
  85. package/src/commands/session.js +209 -0
  86. package/src/commands/sganal.js +123 -29
  87. package/src/commands/siem.js +201 -34
  88. package/src/commands/skill.js +207 -0
  89. package/src/commands/sla.js +212 -0
  90. package/src/commands/slotfill.js +146 -33
  91. package/src/commands/social.js +358 -32
  92. package/src/commands/sso.js +209 -0
  93. package/src/commands/stress.js +206 -0
  94. package/src/commands/svccont.js +145 -33
  95. package/src/commands/sync.js +209 -0
  96. package/src/commands/tech.js +209 -0
  97. package/src/commands/tenant.js +217 -0
  98. package/src/commands/terraform.js +206 -0
  99. package/src/commands/tms.js +171 -33
  100. package/src/commands/tokens.js +209 -0
  101. package/src/commands/topiccls.js +146 -33
  102. package/src/commands/trust.js +217 -0
  103. package/src/commands/uprof.js +141 -32
  104. package/src/commands/vcheck.js +122 -28
  105. package/src/commands/wallet.js +209 -0
  106. package/src/commands/webfetch.js +141 -32
  107. package/src/commands/workflow.js +203 -0
  108. package/src/commands/zkp.js +184 -28
  109. package/src/index.js +180 -0
  110. package/src/lib/a2a-protocol.js +319 -51
  111. package/src/lib/activitypub-bridge.js +622 -50
  112. package/src/lib/agent-economy.js +304 -51
  113. package/src/lib/agent-network.js +341 -0
  114. package/src/lib/aiops.js +346 -0
  115. package/src/lib/app-builder.js +279 -46
  116. package/src/lib/audit-logger.js +321 -0
  117. package/src/lib/automation-engine.js +335 -0
  118. package/src/lib/autonomous-agent.js +284 -48
  119. package/src/lib/autonomous-developer.js +332 -0
  120. package/src/lib/bi-engine.js +616 -49
  121. package/src/lib/bm25-search.js +301 -49
  122. package/src/lib/browser-automation.js +630 -49
  123. package/src/lib/chat-core.js +336 -0
  124. package/src/lib/claude-code-bridge.js +341 -0
  125. package/src/lib/code-agent.js +339 -0
  126. package/src/lib/collaboration-governance.js +334 -0
  127. package/src/lib/community-governance.js +346 -0
  128. package/src/lib/compliance-framework-reporter.js +305 -51
  129. package/src/lib/compliance-manager.js +330 -0
  130. package/src/lib/compression-telemetry.js +301 -49
  131. package/src/lib/content-recommendation.js +351 -0
  132. package/src/lib/content-recommender.js +317 -52
  133. package/src/lib/cowork-cron.js +298 -49
  134. package/src/lib/cowork-learning.js +333 -0
  135. package/src/lib/cowork-share.js +338 -0
  136. package/src/lib/cowork-task-runner.js +308 -51
  137. package/src/lib/cowork-workflow.js +327 -0
  138. package/src/lib/cross-chain.js +311 -51
  139. package/src/lib/dao-governance.js +280 -46
  140. package/src/lib/dbevo.js +351 -0
  141. package/src/lib/decentral-infra.js +330 -0
  142. package/src/lib/did-manager.js +341 -0
  143. package/src/lib/did-v2-manager.js +341 -0
  144. package/src/lib/dlp-engine.js +626 -49
  145. package/src/lib/evolution-system.js +278 -47
  146. package/src/lib/evomap-governance.js +334 -0
  147. package/src/lib/evomap-manager.js +280 -46
  148. package/src/lib/execution-backend.js +294 -48
  149. package/src/lib/feature-flags.js +294 -49
  150. package/src/lib/federation-hardening.js +340 -0
  151. package/src/lib/git-integration.js +285 -47
  152. package/src/lib/hardening-manager.js +341 -0
  153. package/src/lib/hierarchical-memory.js +284 -48
  154. package/src/lib/hook-manager.js +341 -0
  155. package/src/lib/inference-network.js +308 -51
  156. package/src/lib/instinct-manager.js +346 -0
  157. package/src/lib/ipfs-storage.js +334 -0
  158. package/src/lib/iteration-budget.js +302 -50
  159. package/src/lib/knowledge-exporter.js +341 -0
  160. package/src/lib/knowledge-graph.js +333 -0
  161. package/src/lib/knowledge-importer.js +341 -0
  162. package/src/lib/llm-providers.js +346 -0
  163. package/src/lib/matrix-bridge.js +620 -47
  164. package/src/lib/mcp-registry.js +346 -0
  165. package/src/lib/mcp-scaffold.js +318 -54
  166. package/src/lib/memory-injection.js +288 -49
  167. package/src/lib/memory-manager.js +336 -0
  168. package/src/lib/multimodal.js +330 -0
  169. package/src/lib/nl-programming.js +341 -0
  170. package/src/lib/nostr-bridge.js +622 -49
  171. package/src/lib/note-versioning.js +339 -0
  172. package/src/lib/orchestrator.js +293 -48
  173. package/src/lib/org-manager.js +336 -0
  174. package/src/lib/p2p-manager.js +341 -0
  175. package/src/lib/pdf-parser.js +298 -49
  176. package/src/lib/perception.js +346 -0
  177. package/src/lib/perf-tuning.js +309 -50
  178. package/src/lib/permanent-memory.js +327 -0
  179. package/src/lib/permission-engine.js +287 -49
  180. package/src/lib/pipeline-orchestrator.js +289 -49
  181. package/src/lib/plan-mode.js +298 -51
  182. package/src/lib/plugin-ecosystem.js +346 -0
  183. package/src/lib/pqc-manager.js +346 -0
  184. package/src/lib/privacy-computing.js +335 -0
  185. package/src/lib/protocol-fusion.js +338 -0
  186. package/src/lib/quantization.js +337 -0
  187. package/src/lib/reputation-optimizer.js +340 -0
  188. package/src/lib/response-cache.js +333 -0
  189. package/src/lib/sandbox-v2.js +327 -0
  190. package/src/lib/scim-manager.js +346 -0
  191. package/src/lib/service-container.js +313 -52
  192. package/src/lib/session-consolidator.js +296 -49
  193. package/src/lib/session-hooks.js +312 -53
  194. package/src/lib/session-manager.js +334 -0
  195. package/src/lib/session-search.js +304 -51
  196. package/src/lib/session-tail.js +288 -49
  197. package/src/lib/session-usage.js +298 -52
  198. package/src/lib/siem-exporter.js +298 -51
  199. package/src/lib/skill-loader.js +334 -0
  200. package/src/lib/skill-marketplace.js +345 -0
  201. package/src/lib/sla-manager.js +341 -0
  202. package/src/lib/slot-filler.js +303 -51
  203. package/src/lib/social-graph-analytics.js +295 -49
  204. package/src/lib/social-graph.js +272 -49
  205. package/src/lib/social-manager.js +330 -0
  206. package/src/lib/sso-manager.js +340 -0
  207. package/src/lib/stress-tester.js +342 -0
  208. package/src/lib/sub-agent-registry.js +302 -53
  209. package/src/lib/sync-manager.js +336 -0
  210. package/src/lib/task-model-selector.js +302 -50
  211. package/src/lib/tech-learning-engine.js +341 -0
  212. package/src/lib/tenant-saas.js +341 -0
  213. package/src/lib/terraform-manager.js +333 -0
  214. package/src/lib/threat-intel.js +330 -0
  215. package/src/lib/todo-manager.js +281 -47
  216. package/src/lib/token-incentive.js +341 -0
  217. package/src/lib/token-tracker.js +336 -0
  218. package/src/lib/topic-classifier.js +297 -49
  219. package/src/lib/trust-security.js +343 -0
  220. package/src/lib/ueba.js +340 -0
  221. package/src/lib/universal-runtime.js +330 -0
  222. package/src/lib/user-profile.js +294 -50
  223. package/src/lib/version-checker.js +304 -50
  224. package/src/lib/wallet-manager.js +336 -0
  225. package/src/lib/web-fetch.js +292 -51
  226. package/src/lib/workflow-engine.js +330 -0
  227. package/src/lib/zkp-engine.js +286 -49
@@ -670,3 +670,344 @@ export function _resetStateKnowledgeImporterV2() {
670
670
  _stateV2.sourceIdleMs = IMPORTER_DEFAULT_SOURCE_IDLE_MS;
671
671
  _stateV2.jobStuckMs = IMPORTER_DEFAULT_JOB_STUCK_MS;
672
672
  }
673
+
674
+ // =====================================================================
675
+ // knowledge-importer V2 governance overlay (iter22)
676
+ // =====================================================================
677
+ export const KIMPGOV_PROFILE_MATURITY_V2 = Object.freeze({
678
+ PENDING: "pending",
679
+ ACTIVE: "active",
680
+ STALE: "stale",
681
+ ARCHIVED: "archived",
682
+ });
683
+ export const KIMPGOV_IMPORT_LIFECYCLE_V2 = Object.freeze({
684
+ QUEUED: "queued",
685
+ IMPORTING: "importing",
686
+ IMPORTED: "imported",
687
+ FAILED: "failed",
688
+ CANCELLED: "cancelled",
689
+ });
690
+ const _kimpgovPTrans = new Map([
691
+ [
692
+ KIMPGOV_PROFILE_MATURITY_V2.PENDING,
693
+ new Set([
694
+ KIMPGOV_PROFILE_MATURITY_V2.ACTIVE,
695
+ KIMPGOV_PROFILE_MATURITY_V2.ARCHIVED,
696
+ ]),
697
+ ],
698
+ [
699
+ KIMPGOV_PROFILE_MATURITY_V2.ACTIVE,
700
+ new Set([
701
+ KIMPGOV_PROFILE_MATURITY_V2.STALE,
702
+ KIMPGOV_PROFILE_MATURITY_V2.ARCHIVED,
703
+ ]),
704
+ ],
705
+ [
706
+ KIMPGOV_PROFILE_MATURITY_V2.STALE,
707
+ new Set([
708
+ KIMPGOV_PROFILE_MATURITY_V2.ACTIVE,
709
+ KIMPGOV_PROFILE_MATURITY_V2.ARCHIVED,
710
+ ]),
711
+ ],
712
+ [KIMPGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
713
+ ]);
714
+ const _kimpgovPTerminal = new Set([KIMPGOV_PROFILE_MATURITY_V2.ARCHIVED]);
715
+ const _kimpgovJTrans = new Map([
716
+ [
717
+ KIMPGOV_IMPORT_LIFECYCLE_V2.QUEUED,
718
+ new Set([
719
+ KIMPGOV_IMPORT_LIFECYCLE_V2.IMPORTING,
720
+ KIMPGOV_IMPORT_LIFECYCLE_V2.CANCELLED,
721
+ ]),
722
+ ],
723
+ [
724
+ KIMPGOV_IMPORT_LIFECYCLE_V2.IMPORTING,
725
+ new Set([
726
+ KIMPGOV_IMPORT_LIFECYCLE_V2.IMPORTED,
727
+ KIMPGOV_IMPORT_LIFECYCLE_V2.FAILED,
728
+ KIMPGOV_IMPORT_LIFECYCLE_V2.CANCELLED,
729
+ ]),
730
+ ],
731
+ [KIMPGOV_IMPORT_LIFECYCLE_V2.IMPORTED, new Set()],
732
+ [KIMPGOV_IMPORT_LIFECYCLE_V2.FAILED, new Set()],
733
+ [KIMPGOV_IMPORT_LIFECYCLE_V2.CANCELLED, new Set()],
734
+ ]);
735
+ const _kimpgovPsV2 = new Map();
736
+ const _kimpgovJsV2 = new Map();
737
+ let _kimpgovMaxActive = 6,
738
+ _kimpgovMaxPending = 15,
739
+ _kimpgovIdleMs = 30 * 24 * 60 * 60 * 1000,
740
+ _kimpgovStuckMs = 60 * 1000;
741
+ function _kimpgovPos(n, label) {
742
+ const v = Math.floor(Number(n));
743
+ if (!Number.isFinite(v) || v <= 0)
744
+ throw new Error(`${label} must be positive integer`);
745
+ return v;
746
+ }
747
+ function _kimpgovCheckP(from, to) {
748
+ const a = _kimpgovPTrans.get(from);
749
+ if (!a || !a.has(to))
750
+ throw new Error(`invalid kimpgov profile transition ${from} → ${to}`);
751
+ }
752
+ function _kimpgovCheckJ(from, to) {
753
+ const a = _kimpgovJTrans.get(from);
754
+ if (!a || !a.has(to))
755
+ throw new Error(`invalid kimpgov import transition ${from} → ${to}`);
756
+ }
757
+ function _kimpgovCountActive(owner) {
758
+ let c = 0;
759
+ for (const p of _kimpgovPsV2.values())
760
+ if (p.owner === owner && p.status === KIMPGOV_PROFILE_MATURITY_V2.ACTIVE)
761
+ c++;
762
+ return c;
763
+ }
764
+ function _kimpgovCountPending(profileId) {
765
+ let c = 0;
766
+ for (const j of _kimpgovJsV2.values())
767
+ if (
768
+ j.profileId === profileId &&
769
+ (j.status === KIMPGOV_IMPORT_LIFECYCLE_V2.QUEUED ||
770
+ j.status === KIMPGOV_IMPORT_LIFECYCLE_V2.IMPORTING)
771
+ )
772
+ c++;
773
+ return c;
774
+ }
775
+ export function setMaxActiveKimpgovProfilesPerOwnerV2(n) {
776
+ _kimpgovMaxActive = _kimpgovPos(n, "maxActiveKimpgovProfilesPerOwner");
777
+ }
778
+ export function getMaxActiveKimpgovProfilesPerOwnerV2() {
779
+ return _kimpgovMaxActive;
780
+ }
781
+ export function setMaxPendingKimpgovImportsPerProfileV2(n) {
782
+ _kimpgovMaxPending = _kimpgovPos(n, "maxPendingKimpgovImportsPerProfile");
783
+ }
784
+ export function getMaxPendingKimpgovImportsPerProfileV2() {
785
+ return _kimpgovMaxPending;
786
+ }
787
+ export function setKimpgovProfileIdleMsV2(n) {
788
+ _kimpgovIdleMs = _kimpgovPos(n, "kimpgovProfileIdleMs");
789
+ }
790
+ export function getKimpgovProfileIdleMsV2() {
791
+ return _kimpgovIdleMs;
792
+ }
793
+ export function setKimpgovImportStuckMsV2(n) {
794
+ _kimpgovStuckMs = _kimpgovPos(n, "kimpgovImportStuckMs");
795
+ }
796
+ export function getKimpgovImportStuckMsV2() {
797
+ return _kimpgovStuckMs;
798
+ }
799
+ export function _resetStateKnowledgeImporterGovV2() {
800
+ _kimpgovPsV2.clear();
801
+ _kimpgovJsV2.clear();
802
+ _kimpgovMaxActive = 6;
803
+ _kimpgovMaxPending = 15;
804
+ _kimpgovIdleMs = 30 * 24 * 60 * 60 * 1000;
805
+ _kimpgovStuckMs = 60 * 1000;
806
+ }
807
+ export function registerKimpgovProfileV2({ id, owner, format, metadata } = {}) {
808
+ if (!id || !owner) throw new Error("id and owner required");
809
+ if (_kimpgovPsV2.has(id))
810
+ throw new Error(`kimpgov profile ${id} already exists`);
811
+ const now = Date.now();
812
+ const p = {
813
+ id,
814
+ owner,
815
+ format: format || "json",
816
+ status: KIMPGOV_PROFILE_MATURITY_V2.PENDING,
817
+ createdAt: now,
818
+ updatedAt: now,
819
+ lastTouchedAt: now,
820
+ activatedAt: null,
821
+ archivedAt: null,
822
+ metadata: { ...(metadata || {}) },
823
+ };
824
+ _kimpgovPsV2.set(id, p);
825
+ return { ...p, metadata: { ...p.metadata } };
826
+ }
827
+ export function activateKimpgovProfileV2(id) {
828
+ const p = _kimpgovPsV2.get(id);
829
+ if (!p) throw new Error(`kimpgov profile ${id} not found`);
830
+ const isInitial = p.status === KIMPGOV_PROFILE_MATURITY_V2.PENDING;
831
+ _kimpgovCheckP(p.status, KIMPGOV_PROFILE_MATURITY_V2.ACTIVE);
832
+ if (isInitial && _kimpgovCountActive(p.owner) >= _kimpgovMaxActive)
833
+ throw new Error(`max active kimpgov profiles for owner ${p.owner} reached`);
834
+ const now = Date.now();
835
+ p.status = KIMPGOV_PROFILE_MATURITY_V2.ACTIVE;
836
+ p.updatedAt = now;
837
+ p.lastTouchedAt = now;
838
+ if (!p.activatedAt) p.activatedAt = now;
839
+ return { ...p, metadata: { ...p.metadata } };
840
+ }
841
+ export function staleKimpgovProfileV2(id) {
842
+ const p = _kimpgovPsV2.get(id);
843
+ if (!p) throw new Error(`kimpgov profile ${id} not found`);
844
+ _kimpgovCheckP(p.status, KIMPGOV_PROFILE_MATURITY_V2.STALE);
845
+ p.status = KIMPGOV_PROFILE_MATURITY_V2.STALE;
846
+ p.updatedAt = Date.now();
847
+ return { ...p, metadata: { ...p.metadata } };
848
+ }
849
+ export function archiveKimpgovProfileV2(id) {
850
+ const p = _kimpgovPsV2.get(id);
851
+ if (!p) throw new Error(`kimpgov profile ${id} not found`);
852
+ _kimpgovCheckP(p.status, KIMPGOV_PROFILE_MATURITY_V2.ARCHIVED);
853
+ const now = Date.now();
854
+ p.status = KIMPGOV_PROFILE_MATURITY_V2.ARCHIVED;
855
+ p.updatedAt = now;
856
+ if (!p.archivedAt) p.archivedAt = now;
857
+ return { ...p, metadata: { ...p.metadata } };
858
+ }
859
+ export function touchKimpgovProfileV2(id) {
860
+ const p = _kimpgovPsV2.get(id);
861
+ if (!p) throw new Error(`kimpgov profile ${id} not found`);
862
+ if (_kimpgovPTerminal.has(p.status))
863
+ throw new Error(`cannot touch terminal kimpgov profile ${id}`);
864
+ const now = Date.now();
865
+ p.lastTouchedAt = now;
866
+ p.updatedAt = now;
867
+ return { ...p, metadata: { ...p.metadata } };
868
+ }
869
+ export function getKimpgovProfileV2(id) {
870
+ const p = _kimpgovPsV2.get(id);
871
+ if (!p) return null;
872
+ return { ...p, metadata: { ...p.metadata } };
873
+ }
874
+ export function listKimpgovProfilesV2() {
875
+ return [..._kimpgovPsV2.values()].map((p) => ({
876
+ ...p,
877
+ metadata: { ...p.metadata },
878
+ }));
879
+ }
880
+ export function createKimpgovImportV2({
881
+ id,
882
+ profileId,
883
+ source,
884
+ metadata,
885
+ } = {}) {
886
+ if (!id || !profileId) throw new Error("id and profileId required");
887
+ if (_kimpgovJsV2.has(id))
888
+ throw new Error(`kimpgov import ${id} already exists`);
889
+ if (!_kimpgovPsV2.has(profileId))
890
+ throw new Error(`kimpgov profile ${profileId} not found`);
891
+ if (_kimpgovCountPending(profileId) >= _kimpgovMaxPending)
892
+ throw new Error(
893
+ `max pending kimpgov imports for profile ${profileId} reached`,
894
+ );
895
+ const now = Date.now();
896
+ const j = {
897
+ id,
898
+ profileId,
899
+ source: source || "",
900
+ status: KIMPGOV_IMPORT_LIFECYCLE_V2.QUEUED,
901
+ createdAt: now,
902
+ updatedAt: now,
903
+ startedAt: null,
904
+ settledAt: null,
905
+ metadata: { ...(metadata || {}) },
906
+ };
907
+ _kimpgovJsV2.set(id, j);
908
+ return { ...j, metadata: { ...j.metadata } };
909
+ }
910
+ export function importingKimpgovImportV2(id) {
911
+ const j = _kimpgovJsV2.get(id);
912
+ if (!j) throw new Error(`kimpgov import ${id} not found`);
913
+ _kimpgovCheckJ(j.status, KIMPGOV_IMPORT_LIFECYCLE_V2.IMPORTING);
914
+ const now = Date.now();
915
+ j.status = KIMPGOV_IMPORT_LIFECYCLE_V2.IMPORTING;
916
+ j.updatedAt = now;
917
+ if (!j.startedAt) j.startedAt = now;
918
+ return { ...j, metadata: { ...j.metadata } };
919
+ }
920
+ export function completeImportKimpgovV2(id) {
921
+ const j = _kimpgovJsV2.get(id);
922
+ if (!j) throw new Error(`kimpgov import ${id} not found`);
923
+ _kimpgovCheckJ(j.status, KIMPGOV_IMPORT_LIFECYCLE_V2.IMPORTED);
924
+ const now = Date.now();
925
+ j.status = KIMPGOV_IMPORT_LIFECYCLE_V2.IMPORTED;
926
+ j.updatedAt = now;
927
+ if (!j.settledAt) j.settledAt = now;
928
+ return { ...j, metadata: { ...j.metadata } };
929
+ }
930
+ export function failKimpgovImportV2(id, reason) {
931
+ const j = _kimpgovJsV2.get(id);
932
+ if (!j) throw new Error(`kimpgov import ${id} not found`);
933
+ _kimpgovCheckJ(j.status, KIMPGOV_IMPORT_LIFECYCLE_V2.FAILED);
934
+ const now = Date.now();
935
+ j.status = KIMPGOV_IMPORT_LIFECYCLE_V2.FAILED;
936
+ j.updatedAt = now;
937
+ if (!j.settledAt) j.settledAt = now;
938
+ if (reason) j.metadata.failReason = String(reason);
939
+ return { ...j, metadata: { ...j.metadata } };
940
+ }
941
+ export function cancelKimpgovImportV2(id, reason) {
942
+ const j = _kimpgovJsV2.get(id);
943
+ if (!j) throw new Error(`kimpgov import ${id} not found`);
944
+ _kimpgovCheckJ(j.status, KIMPGOV_IMPORT_LIFECYCLE_V2.CANCELLED);
945
+ const now = Date.now();
946
+ j.status = KIMPGOV_IMPORT_LIFECYCLE_V2.CANCELLED;
947
+ j.updatedAt = now;
948
+ if (!j.settledAt) j.settledAt = now;
949
+ if (reason) j.metadata.cancelReason = String(reason);
950
+ return { ...j, metadata: { ...j.metadata } };
951
+ }
952
+ export function getKimpgovImportV2(id) {
953
+ const j = _kimpgovJsV2.get(id);
954
+ if (!j) return null;
955
+ return { ...j, metadata: { ...j.metadata } };
956
+ }
957
+ export function listKimpgovImportsV2() {
958
+ return [..._kimpgovJsV2.values()].map((j) => ({
959
+ ...j,
960
+ metadata: { ...j.metadata },
961
+ }));
962
+ }
963
+ export function autoStaleIdleKimpgovProfilesV2({ now } = {}) {
964
+ const t = now ?? Date.now();
965
+ const flipped = [];
966
+ for (const p of _kimpgovPsV2.values())
967
+ if (
968
+ p.status === KIMPGOV_PROFILE_MATURITY_V2.ACTIVE &&
969
+ t - p.lastTouchedAt >= _kimpgovIdleMs
970
+ ) {
971
+ p.status = KIMPGOV_PROFILE_MATURITY_V2.STALE;
972
+ p.updatedAt = t;
973
+ flipped.push(p.id);
974
+ }
975
+ return { flipped, count: flipped.length };
976
+ }
977
+ export function autoFailStuckKimpgovImportsV2({ now } = {}) {
978
+ const t = now ?? Date.now();
979
+ const flipped = [];
980
+ for (const j of _kimpgovJsV2.values())
981
+ if (
982
+ j.status === KIMPGOV_IMPORT_LIFECYCLE_V2.IMPORTING &&
983
+ j.startedAt != null &&
984
+ t - j.startedAt >= _kimpgovStuckMs
985
+ ) {
986
+ j.status = KIMPGOV_IMPORT_LIFECYCLE_V2.FAILED;
987
+ j.updatedAt = t;
988
+ if (!j.settledAt) j.settledAt = t;
989
+ j.metadata.failReason = "auto-fail-stuck";
990
+ flipped.push(j.id);
991
+ }
992
+ return { flipped, count: flipped.length };
993
+ }
994
+ export function getKnowledgeImporterGovStatsV2() {
995
+ const profilesByStatus = {};
996
+ for (const v of Object.values(KIMPGOV_PROFILE_MATURITY_V2))
997
+ profilesByStatus[v] = 0;
998
+ for (const p of _kimpgovPsV2.values()) profilesByStatus[p.status]++;
999
+ const importsByStatus = {};
1000
+ for (const v of Object.values(KIMPGOV_IMPORT_LIFECYCLE_V2))
1001
+ importsByStatus[v] = 0;
1002
+ for (const j of _kimpgovJsV2.values()) importsByStatus[j.status]++;
1003
+ return {
1004
+ totalKimpgovProfilesV2: _kimpgovPsV2.size,
1005
+ totalKimpgovImportsV2: _kimpgovJsV2.size,
1006
+ maxActiveKimpgovProfilesPerOwner: _kimpgovMaxActive,
1007
+ maxPendingKimpgovImportsPerProfile: _kimpgovMaxPending,
1008
+ kimpgovProfileIdleMs: _kimpgovIdleMs,
1009
+ kimpgovImportStuckMs: _kimpgovStuckMs,
1010
+ profilesByStatus,
1011
+ importsByStatus,
1012
+ };
1013
+ }
@@ -756,3 +756,349 @@ export function _resetStateLlmProvidersV2() {
756
756
  _stateLlmV2.profileIdleMs = PROVIDER_DEFAULT_PROFILE_IDLE_MS;
757
757
  _stateLlmV2.requestStuckMs = PROVIDER_DEFAULT_REQUEST_STUCK_MS;
758
758
  }
759
+
760
+ // =====================================================================
761
+ // llm-providers V2 governance overlay (iter22)
762
+ // =====================================================================
763
+ export const LLMGOV_PROFILE_MATURITY_V2 = Object.freeze({
764
+ PENDING: "pending",
765
+ ACTIVE: "active",
766
+ DEGRADED: "degraded",
767
+ ARCHIVED: "archived",
768
+ });
769
+ export const LLMGOV_COMPLETION_LIFECYCLE_V2 = Object.freeze({
770
+ QUEUED: "queued",
771
+ INFERRING: "inferring",
772
+ INFERRED: "inferred",
773
+ FAILED: "failed",
774
+ CANCELLED: "cancelled",
775
+ });
776
+ const _llmgovPTrans = new Map([
777
+ [
778
+ LLMGOV_PROFILE_MATURITY_V2.PENDING,
779
+ new Set([
780
+ LLMGOV_PROFILE_MATURITY_V2.ACTIVE,
781
+ LLMGOV_PROFILE_MATURITY_V2.ARCHIVED,
782
+ ]),
783
+ ],
784
+ [
785
+ LLMGOV_PROFILE_MATURITY_V2.ACTIVE,
786
+ new Set([
787
+ LLMGOV_PROFILE_MATURITY_V2.DEGRADED,
788
+ LLMGOV_PROFILE_MATURITY_V2.ARCHIVED,
789
+ ]),
790
+ ],
791
+ [
792
+ LLMGOV_PROFILE_MATURITY_V2.DEGRADED,
793
+ new Set([
794
+ LLMGOV_PROFILE_MATURITY_V2.ACTIVE,
795
+ LLMGOV_PROFILE_MATURITY_V2.ARCHIVED,
796
+ ]),
797
+ ],
798
+ [LLMGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
799
+ ]);
800
+ const _llmgovPTerminal = new Set([LLMGOV_PROFILE_MATURITY_V2.ARCHIVED]);
801
+ const _llmgovJTrans = new Map([
802
+ [
803
+ LLMGOV_COMPLETION_LIFECYCLE_V2.QUEUED,
804
+ new Set([
805
+ LLMGOV_COMPLETION_LIFECYCLE_V2.INFERRING,
806
+ LLMGOV_COMPLETION_LIFECYCLE_V2.CANCELLED,
807
+ ]),
808
+ ],
809
+ [
810
+ LLMGOV_COMPLETION_LIFECYCLE_V2.INFERRING,
811
+ new Set([
812
+ LLMGOV_COMPLETION_LIFECYCLE_V2.INFERRED,
813
+ LLMGOV_COMPLETION_LIFECYCLE_V2.FAILED,
814
+ LLMGOV_COMPLETION_LIFECYCLE_V2.CANCELLED,
815
+ ]),
816
+ ],
817
+ [LLMGOV_COMPLETION_LIFECYCLE_V2.INFERRED, new Set()],
818
+ [LLMGOV_COMPLETION_LIFECYCLE_V2.FAILED, new Set()],
819
+ [LLMGOV_COMPLETION_LIFECYCLE_V2.CANCELLED, new Set()],
820
+ ]);
821
+ const _llmgovPsV2 = new Map();
822
+ const _llmgovJsV2 = new Map();
823
+ let _llmgovMaxActive = 8,
824
+ _llmgovMaxPending = 25,
825
+ _llmgovIdleMs = 30 * 24 * 60 * 60 * 1000,
826
+ _llmgovStuckMs = 60 * 1000;
827
+ function _llmgovPos(n, label) {
828
+ const v = Math.floor(Number(n));
829
+ if (!Number.isFinite(v) || v <= 0)
830
+ throw new Error(`${label} must be positive integer`);
831
+ return v;
832
+ }
833
+ function _llmgovCheckP(from, to) {
834
+ const a = _llmgovPTrans.get(from);
835
+ if (!a || !a.has(to))
836
+ throw new Error(`invalid llmgov profile transition ${from} → ${to}`);
837
+ }
838
+ function _llmgovCheckJ(from, to) {
839
+ const a = _llmgovJTrans.get(from);
840
+ if (!a || !a.has(to))
841
+ throw new Error(`invalid llmgov completion transition ${from} → ${to}`);
842
+ }
843
+ function _llmgovCountActive(owner) {
844
+ let c = 0;
845
+ for (const p of _llmgovPsV2.values())
846
+ if (p.owner === owner && p.status === LLMGOV_PROFILE_MATURITY_V2.ACTIVE)
847
+ c++;
848
+ return c;
849
+ }
850
+ function _llmgovCountPending(profileId) {
851
+ let c = 0;
852
+ for (const j of _llmgovJsV2.values())
853
+ if (
854
+ j.profileId === profileId &&
855
+ (j.status === LLMGOV_COMPLETION_LIFECYCLE_V2.QUEUED ||
856
+ j.status === LLMGOV_COMPLETION_LIFECYCLE_V2.INFERRING)
857
+ )
858
+ c++;
859
+ return c;
860
+ }
861
+ export function setMaxActiveLlmgovProfilesPerOwnerV2(n) {
862
+ _llmgovMaxActive = _llmgovPos(n, "maxActiveLlmgovProfilesPerOwner");
863
+ }
864
+ export function getMaxActiveLlmgovProfilesPerOwnerV2() {
865
+ return _llmgovMaxActive;
866
+ }
867
+ export function setMaxPendingLlmgovCompletionsPerProfileV2(n) {
868
+ _llmgovMaxPending = _llmgovPos(n, "maxPendingLlmgovCompletionsPerProfile");
869
+ }
870
+ export function getMaxPendingLlmgovCompletionsPerProfileV2() {
871
+ return _llmgovMaxPending;
872
+ }
873
+ export function setLlmgovProfileIdleMsV2(n) {
874
+ _llmgovIdleMs = _llmgovPos(n, "llmgovProfileIdleMs");
875
+ }
876
+ export function getLlmgovProfileIdleMsV2() {
877
+ return _llmgovIdleMs;
878
+ }
879
+ export function setLlmgovCompletionStuckMsV2(n) {
880
+ _llmgovStuckMs = _llmgovPos(n, "llmgovCompletionStuckMs");
881
+ }
882
+ export function getLlmgovCompletionStuckMsV2() {
883
+ return _llmgovStuckMs;
884
+ }
885
+ export function _resetStateLlmProvidersGovV2() {
886
+ _llmgovPsV2.clear();
887
+ _llmgovJsV2.clear();
888
+ _llmgovMaxActive = 8;
889
+ _llmgovMaxPending = 25;
890
+ _llmgovIdleMs = 30 * 24 * 60 * 60 * 1000;
891
+ _llmgovStuckMs = 60 * 1000;
892
+ }
893
+ export function registerLlmgovProfileV2({
894
+ id,
895
+ owner,
896
+ provider,
897
+ metadata,
898
+ } = {}) {
899
+ if (!id || !owner) throw new Error("id and owner required");
900
+ if (_llmgovPsV2.has(id))
901
+ throw new Error(`llmgov profile ${id} already exists`);
902
+ const now = Date.now();
903
+ const p = {
904
+ id,
905
+ owner,
906
+ provider: provider || "ollama",
907
+ status: LLMGOV_PROFILE_MATURITY_V2.PENDING,
908
+ createdAt: now,
909
+ updatedAt: now,
910
+ lastTouchedAt: now,
911
+ activatedAt: null,
912
+ archivedAt: null,
913
+ metadata: { ...(metadata || {}) },
914
+ };
915
+ _llmgovPsV2.set(id, p);
916
+ return { ...p, metadata: { ...p.metadata } };
917
+ }
918
+ export function activateLlmgovProfileV2(id) {
919
+ const p = _llmgovPsV2.get(id);
920
+ if (!p) throw new Error(`llmgov profile ${id} not found`);
921
+ const isInitial = p.status === LLMGOV_PROFILE_MATURITY_V2.PENDING;
922
+ _llmgovCheckP(p.status, LLMGOV_PROFILE_MATURITY_V2.ACTIVE);
923
+ if (isInitial && _llmgovCountActive(p.owner) >= _llmgovMaxActive)
924
+ throw new Error(`max active llmgov profiles for owner ${p.owner} reached`);
925
+ const now = Date.now();
926
+ p.status = LLMGOV_PROFILE_MATURITY_V2.ACTIVE;
927
+ p.updatedAt = now;
928
+ p.lastTouchedAt = now;
929
+ if (!p.activatedAt) p.activatedAt = now;
930
+ return { ...p, metadata: { ...p.metadata } };
931
+ }
932
+ export function degradeLlmgovProfileV2(id) {
933
+ const p = _llmgovPsV2.get(id);
934
+ if (!p) throw new Error(`llmgov profile ${id} not found`);
935
+ _llmgovCheckP(p.status, LLMGOV_PROFILE_MATURITY_V2.DEGRADED);
936
+ p.status = LLMGOV_PROFILE_MATURITY_V2.DEGRADED;
937
+ p.updatedAt = Date.now();
938
+ return { ...p, metadata: { ...p.metadata } };
939
+ }
940
+ export function archiveLlmgovProfileV2(id) {
941
+ const p = _llmgovPsV2.get(id);
942
+ if (!p) throw new Error(`llmgov profile ${id} not found`);
943
+ _llmgovCheckP(p.status, LLMGOV_PROFILE_MATURITY_V2.ARCHIVED);
944
+ const now = Date.now();
945
+ p.status = LLMGOV_PROFILE_MATURITY_V2.ARCHIVED;
946
+ p.updatedAt = now;
947
+ if (!p.archivedAt) p.archivedAt = now;
948
+ return { ...p, metadata: { ...p.metadata } };
949
+ }
950
+ export function touchLlmgovProfileV2(id) {
951
+ const p = _llmgovPsV2.get(id);
952
+ if (!p) throw new Error(`llmgov profile ${id} not found`);
953
+ if (_llmgovPTerminal.has(p.status))
954
+ throw new Error(`cannot touch terminal llmgov profile ${id}`);
955
+ const now = Date.now();
956
+ p.lastTouchedAt = now;
957
+ p.updatedAt = now;
958
+ return { ...p, metadata: { ...p.metadata } };
959
+ }
960
+ export function getLlmgovProfileV2(id) {
961
+ const p = _llmgovPsV2.get(id);
962
+ if (!p) return null;
963
+ return { ...p, metadata: { ...p.metadata } };
964
+ }
965
+ export function listLlmgovProfilesV2() {
966
+ return [..._llmgovPsV2.values()].map((p) => ({
967
+ ...p,
968
+ metadata: { ...p.metadata },
969
+ }));
970
+ }
971
+ export function createLlmgovCompletionV2({
972
+ id,
973
+ profileId,
974
+ model,
975
+ metadata,
976
+ } = {}) {
977
+ if (!id || !profileId) throw new Error("id and profileId required");
978
+ if (_llmgovJsV2.has(id))
979
+ throw new Error(`llmgov completion ${id} already exists`);
980
+ if (!_llmgovPsV2.has(profileId))
981
+ throw new Error(`llmgov profile ${profileId} not found`);
982
+ if (_llmgovCountPending(profileId) >= _llmgovMaxPending)
983
+ throw new Error(
984
+ `max pending llmgov completions for profile ${profileId} reached`,
985
+ );
986
+ const now = Date.now();
987
+ const j = {
988
+ id,
989
+ profileId,
990
+ model: model || "",
991
+ status: LLMGOV_COMPLETION_LIFECYCLE_V2.QUEUED,
992
+ createdAt: now,
993
+ updatedAt: now,
994
+ startedAt: null,
995
+ settledAt: null,
996
+ metadata: { ...(metadata || {}) },
997
+ };
998
+ _llmgovJsV2.set(id, j);
999
+ return { ...j, metadata: { ...j.metadata } };
1000
+ }
1001
+ export function inferringLlmgovCompletionV2(id) {
1002
+ const j = _llmgovJsV2.get(id);
1003
+ if (!j) throw new Error(`llmgov completion ${id} not found`);
1004
+ _llmgovCheckJ(j.status, LLMGOV_COMPLETION_LIFECYCLE_V2.INFERRING);
1005
+ const now = Date.now();
1006
+ j.status = LLMGOV_COMPLETION_LIFECYCLE_V2.INFERRING;
1007
+ j.updatedAt = now;
1008
+ if (!j.startedAt) j.startedAt = now;
1009
+ return { ...j, metadata: { ...j.metadata } };
1010
+ }
1011
+ export function completeCompletionLlmgovV2(id) {
1012
+ const j = _llmgovJsV2.get(id);
1013
+ if (!j) throw new Error(`llmgov completion ${id} not found`);
1014
+ _llmgovCheckJ(j.status, LLMGOV_COMPLETION_LIFECYCLE_V2.INFERRED);
1015
+ const now = Date.now();
1016
+ j.status = LLMGOV_COMPLETION_LIFECYCLE_V2.INFERRED;
1017
+ j.updatedAt = now;
1018
+ if (!j.settledAt) j.settledAt = now;
1019
+ return { ...j, metadata: { ...j.metadata } };
1020
+ }
1021
+ export function failLlmgovCompletionV2(id, reason) {
1022
+ const j = _llmgovJsV2.get(id);
1023
+ if (!j) throw new Error(`llmgov completion ${id} not found`);
1024
+ _llmgovCheckJ(j.status, LLMGOV_COMPLETION_LIFECYCLE_V2.FAILED);
1025
+ const now = Date.now();
1026
+ j.status = LLMGOV_COMPLETION_LIFECYCLE_V2.FAILED;
1027
+ j.updatedAt = now;
1028
+ if (!j.settledAt) j.settledAt = now;
1029
+ if (reason) j.metadata.failReason = String(reason);
1030
+ return { ...j, metadata: { ...j.metadata } };
1031
+ }
1032
+ export function cancelLlmgovCompletionV2(id, reason) {
1033
+ const j = _llmgovJsV2.get(id);
1034
+ if (!j) throw new Error(`llmgov completion ${id} not found`);
1035
+ _llmgovCheckJ(j.status, LLMGOV_COMPLETION_LIFECYCLE_V2.CANCELLED);
1036
+ const now = Date.now();
1037
+ j.status = LLMGOV_COMPLETION_LIFECYCLE_V2.CANCELLED;
1038
+ j.updatedAt = now;
1039
+ if (!j.settledAt) j.settledAt = now;
1040
+ if (reason) j.metadata.cancelReason = String(reason);
1041
+ return { ...j, metadata: { ...j.metadata } };
1042
+ }
1043
+ export function getLlmgovCompletionV2(id) {
1044
+ const j = _llmgovJsV2.get(id);
1045
+ if (!j) return null;
1046
+ return { ...j, metadata: { ...j.metadata } };
1047
+ }
1048
+ export function listLlmgovCompletionsV2() {
1049
+ return [..._llmgovJsV2.values()].map((j) => ({
1050
+ ...j,
1051
+ metadata: { ...j.metadata },
1052
+ }));
1053
+ }
1054
+ export function autoDegradeIdleLlmgovProfilesV2({ now } = {}) {
1055
+ const t = now ?? Date.now();
1056
+ const flipped = [];
1057
+ for (const p of _llmgovPsV2.values())
1058
+ if (
1059
+ p.status === LLMGOV_PROFILE_MATURITY_V2.ACTIVE &&
1060
+ t - p.lastTouchedAt >= _llmgovIdleMs
1061
+ ) {
1062
+ p.status = LLMGOV_PROFILE_MATURITY_V2.DEGRADED;
1063
+ p.updatedAt = t;
1064
+ flipped.push(p.id);
1065
+ }
1066
+ return { flipped, count: flipped.length };
1067
+ }
1068
+ export function autoFailStuckLlmgovCompletionsV2({ now } = {}) {
1069
+ const t = now ?? Date.now();
1070
+ const flipped = [];
1071
+ for (const j of _llmgovJsV2.values())
1072
+ if (
1073
+ j.status === LLMGOV_COMPLETION_LIFECYCLE_V2.INFERRING &&
1074
+ j.startedAt != null &&
1075
+ t - j.startedAt >= _llmgovStuckMs
1076
+ ) {
1077
+ j.status = LLMGOV_COMPLETION_LIFECYCLE_V2.FAILED;
1078
+ j.updatedAt = t;
1079
+ if (!j.settledAt) j.settledAt = t;
1080
+ j.metadata.failReason = "auto-fail-stuck";
1081
+ flipped.push(j.id);
1082
+ }
1083
+ return { flipped, count: flipped.length };
1084
+ }
1085
+ export function getLlmProvidersGovStatsV2() {
1086
+ const profilesByStatus = {};
1087
+ for (const v of Object.values(LLMGOV_PROFILE_MATURITY_V2))
1088
+ profilesByStatus[v] = 0;
1089
+ for (const p of _llmgovPsV2.values()) profilesByStatus[p.status]++;
1090
+ const completionsByStatus = {};
1091
+ for (const v of Object.values(LLMGOV_COMPLETION_LIFECYCLE_V2))
1092
+ completionsByStatus[v] = 0;
1093
+ for (const j of _llmgovJsV2.values()) completionsByStatus[j.status]++;
1094
+ return {
1095
+ totalLlmgovProfilesV2: _llmgovPsV2.size,
1096
+ totalLlmgovCompletionsV2: _llmgovJsV2.size,
1097
+ maxActiveLlmgovProfilesPerOwner: _llmgovMaxActive,
1098
+ maxPendingLlmgovCompletionsPerProfile: _llmgovMaxPending,
1099
+ llmgovProfileIdleMs: _llmgovIdleMs,
1100
+ llmgovCompletionStuckMs: _llmgovStuckMs,
1101
+ profilesByStatus,
1102
+ completionsByStatus,
1103
+ };
1104
+ }