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
@@ -733,3 +733,337 @@ export function _resetStateSkillLoaderV2() {
733
733
  _stateV2.skillIdleMs = SKILL_DEFAULT_SKILL_IDLE_MS;
734
734
  _stateV2.execStuckMs = SKILL_DEFAULT_EXEC_STUCK_MS;
735
735
  }
736
+
737
+ // =====================================================================
738
+ // skill-loader V2 governance overlay (iter24)
739
+ // =====================================================================
740
+ export const SKLGOV_PROFILE_MATURITY_V2 = Object.freeze({
741
+ PENDING: "pending",
742
+ ACTIVE: "active",
743
+ STALE: "stale",
744
+ ARCHIVED: "archived",
745
+ });
746
+ export const SKLGOV_LOAD_LIFECYCLE_V2 = Object.freeze({
747
+ QUEUED: "queued",
748
+ LOADING: "loading",
749
+ LOADED: "loaded",
750
+ FAILED: "failed",
751
+ CANCELLED: "cancelled",
752
+ });
753
+ const _sklgovPTrans = new Map([
754
+ [
755
+ SKLGOV_PROFILE_MATURITY_V2.PENDING,
756
+ new Set([
757
+ SKLGOV_PROFILE_MATURITY_V2.ACTIVE,
758
+ SKLGOV_PROFILE_MATURITY_V2.ARCHIVED,
759
+ ]),
760
+ ],
761
+ [
762
+ SKLGOV_PROFILE_MATURITY_V2.ACTIVE,
763
+ new Set([
764
+ SKLGOV_PROFILE_MATURITY_V2.STALE,
765
+ SKLGOV_PROFILE_MATURITY_V2.ARCHIVED,
766
+ ]),
767
+ ],
768
+ [
769
+ SKLGOV_PROFILE_MATURITY_V2.STALE,
770
+ new Set([
771
+ SKLGOV_PROFILE_MATURITY_V2.ACTIVE,
772
+ SKLGOV_PROFILE_MATURITY_V2.ARCHIVED,
773
+ ]),
774
+ ],
775
+ [SKLGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
776
+ ]);
777
+ const _sklgovPTerminal = new Set([SKLGOV_PROFILE_MATURITY_V2.ARCHIVED]);
778
+ const _sklgovJTrans = new Map([
779
+ [
780
+ SKLGOV_LOAD_LIFECYCLE_V2.QUEUED,
781
+ new Set([
782
+ SKLGOV_LOAD_LIFECYCLE_V2.LOADING,
783
+ SKLGOV_LOAD_LIFECYCLE_V2.CANCELLED,
784
+ ]),
785
+ ],
786
+ [
787
+ SKLGOV_LOAD_LIFECYCLE_V2.LOADING,
788
+ new Set([
789
+ SKLGOV_LOAD_LIFECYCLE_V2.LOADED,
790
+ SKLGOV_LOAD_LIFECYCLE_V2.FAILED,
791
+ SKLGOV_LOAD_LIFECYCLE_V2.CANCELLED,
792
+ ]),
793
+ ],
794
+ [SKLGOV_LOAD_LIFECYCLE_V2.LOADED, new Set()],
795
+ [SKLGOV_LOAD_LIFECYCLE_V2.FAILED, new Set()],
796
+ [SKLGOV_LOAD_LIFECYCLE_V2.CANCELLED, new Set()],
797
+ ]);
798
+ const _sklgovPsV2 = new Map();
799
+ const _sklgovJsV2 = new Map();
800
+ let _sklgovMaxActive = 10,
801
+ _sklgovMaxPending = 25,
802
+ _sklgovIdleMs = 30 * 24 * 60 * 60 * 1000,
803
+ _sklgovStuckMs = 60 * 1000;
804
+ function _sklgovPos(n, label) {
805
+ const v = Math.floor(Number(n));
806
+ if (!Number.isFinite(v) || v <= 0)
807
+ throw new Error(`${label} must be positive integer`);
808
+ return v;
809
+ }
810
+ function _sklgovCheckP(from, to) {
811
+ const a = _sklgovPTrans.get(from);
812
+ if (!a || !a.has(to))
813
+ throw new Error(`invalid sklgov profile transition ${from} → ${to}`);
814
+ }
815
+ function _sklgovCheckJ(from, to) {
816
+ const a = _sklgovJTrans.get(from);
817
+ if (!a || !a.has(to))
818
+ throw new Error(`invalid sklgov load transition ${from} → ${to}`);
819
+ }
820
+ function _sklgovCountActive(owner) {
821
+ let c = 0;
822
+ for (const p of _sklgovPsV2.values())
823
+ if (p.owner === owner && p.status === SKLGOV_PROFILE_MATURITY_V2.ACTIVE)
824
+ c++;
825
+ return c;
826
+ }
827
+ function _sklgovCountPending(profileId) {
828
+ let c = 0;
829
+ for (const j of _sklgovJsV2.values())
830
+ if (
831
+ j.profileId === profileId &&
832
+ (j.status === SKLGOV_LOAD_LIFECYCLE_V2.QUEUED ||
833
+ j.status === SKLGOV_LOAD_LIFECYCLE_V2.LOADING)
834
+ )
835
+ c++;
836
+ return c;
837
+ }
838
+ export function setMaxActiveSklgovProfilesPerOwnerV2(n) {
839
+ _sklgovMaxActive = _sklgovPos(n, "maxActiveSklgovProfilesPerOwner");
840
+ }
841
+ export function getMaxActiveSklgovProfilesPerOwnerV2() {
842
+ return _sklgovMaxActive;
843
+ }
844
+ export function setMaxPendingSklgovLoadsPerProfileV2(n) {
845
+ _sklgovMaxPending = _sklgovPos(n, "maxPendingSklgovLoadsPerProfile");
846
+ }
847
+ export function getMaxPendingSklgovLoadsPerProfileV2() {
848
+ return _sklgovMaxPending;
849
+ }
850
+ export function setSklgovProfileIdleMsV2(n) {
851
+ _sklgovIdleMs = _sklgovPos(n, "sklgovProfileIdleMs");
852
+ }
853
+ export function getSklgovProfileIdleMsV2() {
854
+ return _sklgovIdleMs;
855
+ }
856
+ export function setSklgovLoadStuckMsV2(n) {
857
+ _sklgovStuckMs = _sklgovPos(n, "sklgovLoadStuckMs");
858
+ }
859
+ export function getSklgovLoadStuckMsV2() {
860
+ return _sklgovStuckMs;
861
+ }
862
+ export function _resetStateSkillLoaderGovV2() {
863
+ _sklgovPsV2.clear();
864
+ _sklgovJsV2.clear();
865
+ _sklgovMaxActive = 10;
866
+ _sklgovMaxPending = 25;
867
+ _sklgovIdleMs = 30 * 24 * 60 * 60 * 1000;
868
+ _sklgovStuckMs = 60 * 1000;
869
+ }
870
+ export function registerSklgovProfileV2({ id, owner, source, metadata } = {}) {
871
+ if (!id || !owner) throw new Error("id and owner required");
872
+ if (_sklgovPsV2.has(id))
873
+ throw new Error(`sklgov profile ${id} already exists`);
874
+ const now = Date.now();
875
+ const p = {
876
+ id,
877
+ owner,
878
+ source: source || "local",
879
+ status: SKLGOV_PROFILE_MATURITY_V2.PENDING,
880
+ createdAt: now,
881
+ updatedAt: now,
882
+ lastTouchedAt: now,
883
+ activatedAt: null,
884
+ archivedAt: null,
885
+ metadata: { ...(metadata || {}) },
886
+ };
887
+ _sklgovPsV2.set(id, p);
888
+ return { ...p, metadata: { ...p.metadata } };
889
+ }
890
+ export function activateSklgovProfileV2(id) {
891
+ const p = _sklgovPsV2.get(id);
892
+ if (!p) throw new Error(`sklgov profile ${id} not found`);
893
+ const isInitial = p.status === SKLGOV_PROFILE_MATURITY_V2.PENDING;
894
+ _sklgovCheckP(p.status, SKLGOV_PROFILE_MATURITY_V2.ACTIVE);
895
+ if (isInitial && _sklgovCountActive(p.owner) >= _sklgovMaxActive)
896
+ throw new Error(`max active sklgov profiles for owner ${p.owner} reached`);
897
+ const now = Date.now();
898
+ p.status = SKLGOV_PROFILE_MATURITY_V2.ACTIVE;
899
+ p.updatedAt = now;
900
+ p.lastTouchedAt = now;
901
+ if (!p.activatedAt) p.activatedAt = now;
902
+ return { ...p, metadata: { ...p.metadata } };
903
+ }
904
+ export function staleSklgovProfileV2(id) {
905
+ const p = _sklgovPsV2.get(id);
906
+ if (!p) throw new Error(`sklgov profile ${id} not found`);
907
+ _sklgovCheckP(p.status, SKLGOV_PROFILE_MATURITY_V2.STALE);
908
+ p.status = SKLGOV_PROFILE_MATURITY_V2.STALE;
909
+ p.updatedAt = Date.now();
910
+ return { ...p, metadata: { ...p.metadata } };
911
+ }
912
+ export function archiveSklgovProfileV2(id) {
913
+ const p = _sklgovPsV2.get(id);
914
+ if (!p) throw new Error(`sklgov profile ${id} not found`);
915
+ _sklgovCheckP(p.status, SKLGOV_PROFILE_MATURITY_V2.ARCHIVED);
916
+ const now = Date.now();
917
+ p.status = SKLGOV_PROFILE_MATURITY_V2.ARCHIVED;
918
+ p.updatedAt = now;
919
+ if (!p.archivedAt) p.archivedAt = now;
920
+ return { ...p, metadata: { ...p.metadata } };
921
+ }
922
+ export function touchSklgovProfileV2(id) {
923
+ const p = _sklgovPsV2.get(id);
924
+ if (!p) throw new Error(`sklgov profile ${id} not found`);
925
+ if (_sklgovPTerminal.has(p.status))
926
+ throw new Error(`cannot touch terminal sklgov profile ${id}`);
927
+ const now = Date.now();
928
+ p.lastTouchedAt = now;
929
+ p.updatedAt = now;
930
+ return { ...p, metadata: { ...p.metadata } };
931
+ }
932
+ export function getSklgovProfileV2(id) {
933
+ const p = _sklgovPsV2.get(id);
934
+ if (!p) return null;
935
+ return { ...p, metadata: { ...p.metadata } };
936
+ }
937
+ export function listSklgovProfilesV2() {
938
+ return [..._sklgovPsV2.values()].map((p) => ({
939
+ ...p,
940
+ metadata: { ...p.metadata },
941
+ }));
942
+ }
943
+ export function createSklgovLoadV2({ id, profileId, skillId, metadata } = {}) {
944
+ if (!id || !profileId) throw new Error("id and profileId required");
945
+ if (_sklgovJsV2.has(id)) throw new Error(`sklgov load ${id} already exists`);
946
+ if (!_sklgovPsV2.has(profileId))
947
+ throw new Error(`sklgov profile ${profileId} not found`);
948
+ if (_sklgovCountPending(profileId) >= _sklgovMaxPending)
949
+ throw new Error(
950
+ `max pending sklgov loads for profile ${profileId} reached`,
951
+ );
952
+ const now = Date.now();
953
+ const j = {
954
+ id,
955
+ profileId,
956
+ skillId: skillId || "",
957
+ status: SKLGOV_LOAD_LIFECYCLE_V2.QUEUED,
958
+ createdAt: now,
959
+ updatedAt: now,
960
+ startedAt: null,
961
+ settledAt: null,
962
+ metadata: { ...(metadata || {}) },
963
+ };
964
+ _sklgovJsV2.set(id, j);
965
+ return { ...j, metadata: { ...j.metadata } };
966
+ }
967
+ export function loadingSklgovLoadV2(id) {
968
+ const j = _sklgovJsV2.get(id);
969
+ if (!j) throw new Error(`sklgov load ${id} not found`);
970
+ _sklgovCheckJ(j.status, SKLGOV_LOAD_LIFECYCLE_V2.LOADING);
971
+ const now = Date.now();
972
+ j.status = SKLGOV_LOAD_LIFECYCLE_V2.LOADING;
973
+ j.updatedAt = now;
974
+ if (!j.startedAt) j.startedAt = now;
975
+ return { ...j, metadata: { ...j.metadata } };
976
+ }
977
+ export function completeLoadSklgovV2(id) {
978
+ const j = _sklgovJsV2.get(id);
979
+ if (!j) throw new Error(`sklgov load ${id} not found`);
980
+ _sklgovCheckJ(j.status, SKLGOV_LOAD_LIFECYCLE_V2.LOADED);
981
+ const now = Date.now();
982
+ j.status = SKLGOV_LOAD_LIFECYCLE_V2.LOADED;
983
+ j.updatedAt = now;
984
+ if (!j.settledAt) j.settledAt = now;
985
+ return { ...j, metadata: { ...j.metadata } };
986
+ }
987
+ export function failSklgovLoadV2(id, reason) {
988
+ const j = _sklgovJsV2.get(id);
989
+ if (!j) throw new Error(`sklgov load ${id} not found`);
990
+ _sklgovCheckJ(j.status, SKLGOV_LOAD_LIFECYCLE_V2.FAILED);
991
+ const now = Date.now();
992
+ j.status = SKLGOV_LOAD_LIFECYCLE_V2.FAILED;
993
+ j.updatedAt = now;
994
+ if (!j.settledAt) j.settledAt = now;
995
+ if (reason) j.metadata.failReason = String(reason);
996
+ return { ...j, metadata: { ...j.metadata } };
997
+ }
998
+ export function cancelSklgovLoadV2(id, reason) {
999
+ const j = _sklgovJsV2.get(id);
1000
+ if (!j) throw new Error(`sklgov load ${id} not found`);
1001
+ _sklgovCheckJ(j.status, SKLGOV_LOAD_LIFECYCLE_V2.CANCELLED);
1002
+ const now = Date.now();
1003
+ j.status = SKLGOV_LOAD_LIFECYCLE_V2.CANCELLED;
1004
+ j.updatedAt = now;
1005
+ if (!j.settledAt) j.settledAt = now;
1006
+ if (reason) j.metadata.cancelReason = String(reason);
1007
+ return { ...j, metadata: { ...j.metadata } };
1008
+ }
1009
+ export function getSklgovLoadV2(id) {
1010
+ const j = _sklgovJsV2.get(id);
1011
+ if (!j) return null;
1012
+ return { ...j, metadata: { ...j.metadata } };
1013
+ }
1014
+ export function listSklgovLoadsV2() {
1015
+ return [..._sklgovJsV2.values()].map((j) => ({
1016
+ ...j,
1017
+ metadata: { ...j.metadata },
1018
+ }));
1019
+ }
1020
+ export function autoStaleIdleSklgovProfilesV2({ now } = {}) {
1021
+ const t = now ?? Date.now();
1022
+ const flipped = [];
1023
+ for (const p of _sklgovPsV2.values())
1024
+ if (
1025
+ p.status === SKLGOV_PROFILE_MATURITY_V2.ACTIVE &&
1026
+ t - p.lastTouchedAt >= _sklgovIdleMs
1027
+ ) {
1028
+ p.status = SKLGOV_PROFILE_MATURITY_V2.STALE;
1029
+ p.updatedAt = t;
1030
+ flipped.push(p.id);
1031
+ }
1032
+ return { flipped, count: flipped.length };
1033
+ }
1034
+ export function autoFailStuckSklgovLoadsV2({ now } = {}) {
1035
+ const t = now ?? Date.now();
1036
+ const flipped = [];
1037
+ for (const j of _sklgovJsV2.values())
1038
+ if (
1039
+ j.status === SKLGOV_LOAD_LIFECYCLE_V2.LOADING &&
1040
+ j.startedAt != null &&
1041
+ t - j.startedAt >= _sklgovStuckMs
1042
+ ) {
1043
+ j.status = SKLGOV_LOAD_LIFECYCLE_V2.FAILED;
1044
+ j.updatedAt = t;
1045
+ if (!j.settledAt) j.settledAt = t;
1046
+ j.metadata.failReason = "auto-fail-stuck";
1047
+ flipped.push(j.id);
1048
+ }
1049
+ return { flipped, count: flipped.length };
1050
+ }
1051
+ export function getSkillLoaderGovStatsV2() {
1052
+ const profilesByStatus = {};
1053
+ for (const v of Object.values(SKLGOV_PROFILE_MATURITY_V2))
1054
+ profilesByStatus[v] = 0;
1055
+ for (const p of _sklgovPsV2.values()) profilesByStatus[p.status]++;
1056
+ const loadsByStatus = {};
1057
+ for (const v of Object.values(SKLGOV_LOAD_LIFECYCLE_V2)) loadsByStatus[v] = 0;
1058
+ for (const j of _sklgovJsV2.values()) loadsByStatus[j.status]++;
1059
+ return {
1060
+ totalSklgovProfilesV2: _sklgovPsV2.size,
1061
+ totalSklgovLoadsV2: _sklgovJsV2.size,
1062
+ maxActiveSklgovProfilesPerOwner: _sklgovMaxActive,
1063
+ maxPendingSklgovLoadsPerProfile: _sklgovMaxPending,
1064
+ sklgovProfileIdleMs: _sklgovIdleMs,
1065
+ sklgovLoadStuckMs: _sklgovStuckMs,
1066
+ profilesByStatus,
1067
+ loadsByStatus,
1068
+ };
1069
+ }
@@ -720,3 +720,348 @@ export function getMarketplaceStatsV2() {
720
720
  successRate,
721
721
  };
722
722
  }
723
+
724
+ // =====================================================================
725
+ // skill-marketplace V2 governance overlay (iter16)
726
+ // =====================================================================
727
+ export const MKTGOV_PROFILE_MATURITY_V2 = Object.freeze({
728
+ PENDING: "pending",
729
+ ACTIVE: "active",
730
+ SUSPENDED: "suspended",
731
+ ARCHIVED: "archived",
732
+ });
733
+ export const MKTGOV_ORDER_LIFECYCLE_V2 = Object.freeze({
734
+ QUEUED: "queued",
735
+ PROCESSING: "processing",
736
+ PROCESSED: "processed",
737
+ FAILED: "failed",
738
+ CANCELLED: "cancelled",
739
+ });
740
+ const _mktgovPTrans = new Map([
741
+ [
742
+ MKTGOV_PROFILE_MATURITY_V2.PENDING,
743
+ new Set([
744
+ MKTGOV_PROFILE_MATURITY_V2.ACTIVE,
745
+ MKTGOV_PROFILE_MATURITY_V2.ARCHIVED,
746
+ ]),
747
+ ],
748
+ [
749
+ MKTGOV_PROFILE_MATURITY_V2.ACTIVE,
750
+ new Set([
751
+ MKTGOV_PROFILE_MATURITY_V2.SUSPENDED,
752
+ MKTGOV_PROFILE_MATURITY_V2.ARCHIVED,
753
+ ]),
754
+ ],
755
+ [
756
+ MKTGOV_PROFILE_MATURITY_V2.SUSPENDED,
757
+ new Set([
758
+ MKTGOV_PROFILE_MATURITY_V2.ACTIVE,
759
+ MKTGOV_PROFILE_MATURITY_V2.ARCHIVED,
760
+ ]),
761
+ ],
762
+ [MKTGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
763
+ ]);
764
+ const _mktgovPTerminal = new Set([MKTGOV_PROFILE_MATURITY_V2.ARCHIVED]);
765
+ const _mktgovJTrans = new Map([
766
+ [
767
+ MKTGOV_ORDER_LIFECYCLE_V2.QUEUED,
768
+ new Set([
769
+ MKTGOV_ORDER_LIFECYCLE_V2.PROCESSING,
770
+ MKTGOV_ORDER_LIFECYCLE_V2.CANCELLED,
771
+ ]),
772
+ ],
773
+ [
774
+ MKTGOV_ORDER_LIFECYCLE_V2.PROCESSING,
775
+ new Set([
776
+ MKTGOV_ORDER_LIFECYCLE_V2.PROCESSED,
777
+ MKTGOV_ORDER_LIFECYCLE_V2.FAILED,
778
+ MKTGOV_ORDER_LIFECYCLE_V2.CANCELLED,
779
+ ]),
780
+ ],
781
+ [MKTGOV_ORDER_LIFECYCLE_V2.PROCESSED, new Set()],
782
+ [MKTGOV_ORDER_LIFECYCLE_V2.FAILED, new Set()],
783
+ [MKTGOV_ORDER_LIFECYCLE_V2.CANCELLED, new Set()],
784
+ ]);
785
+ const _mktgovPsV2 = new Map();
786
+ const _mktgovJsV2 = new Map();
787
+ let _mktgovMaxActive = 10,
788
+ _mktgovMaxPending = 25,
789
+ _mktgovIdleMs = 30 * 24 * 60 * 60 * 1000,
790
+ _mktgovStuckMs = 60 * 1000;
791
+ function _mktgovPos(n, label) {
792
+ const v = Math.floor(Number(n));
793
+ if (!Number.isFinite(v) || v <= 0)
794
+ throw new Error(`${label} must be positive integer`);
795
+ return v;
796
+ }
797
+ function _mktgovCheckP(from, to) {
798
+ const a = _mktgovPTrans.get(from);
799
+ if (!a || !a.has(to))
800
+ throw new Error(`invalid mktgov profile transition ${from} → ${to}`);
801
+ }
802
+ function _mktgovCheckJ(from, to) {
803
+ const a = _mktgovJTrans.get(from);
804
+ if (!a || !a.has(to))
805
+ throw new Error(`invalid mktgov order transition ${from} → ${to}`);
806
+ }
807
+ function _mktgovCountActive(owner) {
808
+ let c = 0;
809
+ for (const p of _mktgovPsV2.values())
810
+ if (p.owner === owner && p.status === MKTGOV_PROFILE_MATURITY_V2.ACTIVE)
811
+ c++;
812
+ return c;
813
+ }
814
+ function _mktgovCountPending(profileId) {
815
+ let c = 0;
816
+ for (const j of _mktgovJsV2.values())
817
+ if (
818
+ j.profileId === profileId &&
819
+ (j.status === MKTGOV_ORDER_LIFECYCLE_V2.QUEUED ||
820
+ j.status === MKTGOV_ORDER_LIFECYCLE_V2.PROCESSING)
821
+ )
822
+ c++;
823
+ return c;
824
+ }
825
+ export function setMaxActiveMktgovProfilesPerOwnerV2(n) {
826
+ _mktgovMaxActive = _mktgovPos(n, "maxActiveMktgovProfilesPerOwner");
827
+ }
828
+ export function getMaxActiveMktgovProfilesPerOwnerV2() {
829
+ return _mktgovMaxActive;
830
+ }
831
+ export function setMaxPendingMktgovOrdersPerProfileV2(n) {
832
+ _mktgovMaxPending = _mktgovPos(n, "maxPendingMktgovOrdersPerProfile");
833
+ }
834
+ export function getMaxPendingMktgovOrdersPerProfileV2() {
835
+ return _mktgovMaxPending;
836
+ }
837
+ export function setMktgovProfileIdleMsV2(n) {
838
+ _mktgovIdleMs = _mktgovPos(n, "mktgovProfileIdleMs");
839
+ }
840
+ export function getMktgovProfileIdleMsV2() {
841
+ return _mktgovIdleMs;
842
+ }
843
+ export function setMktgovOrderStuckMsV2(n) {
844
+ _mktgovStuckMs = _mktgovPos(n, "mktgovOrderStuckMs");
845
+ }
846
+ export function getMktgovOrderStuckMsV2() {
847
+ return _mktgovStuckMs;
848
+ }
849
+ export function _resetStateSkillMarketplaceV2() {
850
+ _mktgovPsV2.clear();
851
+ _mktgovJsV2.clear();
852
+ _mktgovMaxActive = 10;
853
+ _mktgovMaxPending = 25;
854
+ _mktgovIdleMs = 30 * 24 * 60 * 60 * 1000;
855
+ _mktgovStuckMs = 60 * 1000;
856
+ }
857
+ export function registerMktgovProfileV2({
858
+ id,
859
+ owner,
860
+ category,
861
+ metadata,
862
+ } = {}) {
863
+ if (!id || !owner) throw new Error("id and owner required");
864
+ if (_mktgovPsV2.has(id))
865
+ throw new Error(`mktgov profile ${id} already exists`);
866
+ const now = Date.now();
867
+ const p = {
868
+ id,
869
+ owner,
870
+ category: category || "general",
871
+ status: MKTGOV_PROFILE_MATURITY_V2.PENDING,
872
+ createdAt: now,
873
+ updatedAt: now,
874
+ lastTouchedAt: now,
875
+ activatedAt: null,
876
+ archivedAt: null,
877
+ metadata: { ...(metadata || {}) },
878
+ };
879
+ _mktgovPsV2.set(id, p);
880
+ return { ...p, metadata: { ...p.metadata } };
881
+ }
882
+ export function activateMktgovProfileV2(id) {
883
+ const p = _mktgovPsV2.get(id);
884
+ if (!p) throw new Error(`mktgov profile ${id} not found`);
885
+ const isInitial = p.status === MKTGOV_PROFILE_MATURITY_V2.PENDING;
886
+ _mktgovCheckP(p.status, MKTGOV_PROFILE_MATURITY_V2.ACTIVE);
887
+ if (isInitial && _mktgovCountActive(p.owner) >= _mktgovMaxActive)
888
+ throw new Error(`max active mktgov profiles for owner ${p.owner} reached`);
889
+ const now = Date.now();
890
+ p.status = MKTGOV_PROFILE_MATURITY_V2.ACTIVE;
891
+ p.updatedAt = now;
892
+ p.lastTouchedAt = now;
893
+ if (!p.activatedAt) p.activatedAt = now;
894
+ return { ...p, metadata: { ...p.metadata } };
895
+ }
896
+ export function suspendMktgovProfileV2(id) {
897
+ const p = _mktgovPsV2.get(id);
898
+ if (!p) throw new Error(`mktgov profile ${id} not found`);
899
+ _mktgovCheckP(p.status, MKTGOV_PROFILE_MATURITY_V2.SUSPENDED);
900
+ p.status = MKTGOV_PROFILE_MATURITY_V2.SUSPENDED;
901
+ p.updatedAt = Date.now();
902
+ return { ...p, metadata: { ...p.metadata } };
903
+ }
904
+ export function archiveMktgovProfileV2(id) {
905
+ const p = _mktgovPsV2.get(id);
906
+ if (!p) throw new Error(`mktgov profile ${id} not found`);
907
+ _mktgovCheckP(p.status, MKTGOV_PROFILE_MATURITY_V2.ARCHIVED);
908
+ const now = Date.now();
909
+ p.status = MKTGOV_PROFILE_MATURITY_V2.ARCHIVED;
910
+ p.updatedAt = now;
911
+ if (!p.archivedAt) p.archivedAt = now;
912
+ return { ...p, metadata: { ...p.metadata } };
913
+ }
914
+ export function touchMktgovProfileV2(id) {
915
+ const p = _mktgovPsV2.get(id);
916
+ if (!p) throw new Error(`mktgov profile ${id} not found`);
917
+ if (_mktgovPTerminal.has(p.status))
918
+ throw new Error(`cannot touch terminal mktgov profile ${id}`);
919
+ const now = Date.now();
920
+ p.lastTouchedAt = now;
921
+ p.updatedAt = now;
922
+ return { ...p, metadata: { ...p.metadata } };
923
+ }
924
+ export function getMktgovProfileV2(id) {
925
+ const p = _mktgovPsV2.get(id);
926
+ if (!p) return null;
927
+ return { ...p, metadata: { ...p.metadata } };
928
+ }
929
+ export function listMktgovProfilesV2() {
930
+ return [..._mktgovPsV2.values()].map((p) => ({
931
+ ...p,
932
+ metadata: { ...p.metadata },
933
+ }));
934
+ }
935
+ export function createMktgovOrderV2({
936
+ id,
937
+ profileId,
938
+ listingId,
939
+ metadata,
940
+ } = {}) {
941
+ if (!id || !profileId) throw new Error("id and profileId required");
942
+ if (_mktgovJsV2.has(id)) throw new Error(`mktgov order ${id} already exists`);
943
+ if (!_mktgovPsV2.has(profileId))
944
+ throw new Error(`mktgov profile ${profileId} not found`);
945
+ if (_mktgovCountPending(profileId) >= _mktgovMaxPending)
946
+ throw new Error(
947
+ `max pending mktgov orders for profile ${profileId} reached`,
948
+ );
949
+ const now = Date.now();
950
+ const j = {
951
+ id,
952
+ profileId,
953
+ listingId: listingId || "",
954
+ status: MKTGOV_ORDER_LIFECYCLE_V2.QUEUED,
955
+ createdAt: now,
956
+ updatedAt: now,
957
+ startedAt: null,
958
+ settledAt: null,
959
+ metadata: { ...(metadata || {}) },
960
+ };
961
+ _mktgovJsV2.set(id, j);
962
+ return { ...j, metadata: { ...j.metadata } };
963
+ }
964
+ export function processingMktgovOrderV2(id) {
965
+ const j = _mktgovJsV2.get(id);
966
+ if (!j) throw new Error(`mktgov order ${id} not found`);
967
+ _mktgovCheckJ(j.status, MKTGOV_ORDER_LIFECYCLE_V2.PROCESSING);
968
+ const now = Date.now();
969
+ j.status = MKTGOV_ORDER_LIFECYCLE_V2.PROCESSING;
970
+ j.updatedAt = now;
971
+ if (!j.startedAt) j.startedAt = now;
972
+ return { ...j, metadata: { ...j.metadata } };
973
+ }
974
+ export function completeOrderMktgovV2(id) {
975
+ const j = _mktgovJsV2.get(id);
976
+ if (!j) throw new Error(`mktgov order ${id} not found`);
977
+ _mktgovCheckJ(j.status, MKTGOV_ORDER_LIFECYCLE_V2.PROCESSED);
978
+ const now = Date.now();
979
+ j.status = MKTGOV_ORDER_LIFECYCLE_V2.PROCESSED;
980
+ j.updatedAt = now;
981
+ if (!j.settledAt) j.settledAt = now;
982
+ return { ...j, metadata: { ...j.metadata } };
983
+ }
984
+ export function failMktgovOrderV2(id, reason) {
985
+ const j = _mktgovJsV2.get(id);
986
+ if (!j) throw new Error(`mktgov order ${id} not found`);
987
+ _mktgovCheckJ(j.status, MKTGOV_ORDER_LIFECYCLE_V2.FAILED);
988
+ const now = Date.now();
989
+ j.status = MKTGOV_ORDER_LIFECYCLE_V2.FAILED;
990
+ j.updatedAt = now;
991
+ if (!j.settledAt) j.settledAt = now;
992
+ if (reason) j.metadata.failReason = String(reason);
993
+ return { ...j, metadata: { ...j.metadata } };
994
+ }
995
+ export function cancelMktgovOrderV2(id, reason) {
996
+ const j = _mktgovJsV2.get(id);
997
+ if (!j) throw new Error(`mktgov order ${id} not found`);
998
+ _mktgovCheckJ(j.status, MKTGOV_ORDER_LIFECYCLE_V2.CANCELLED);
999
+ const now = Date.now();
1000
+ j.status = MKTGOV_ORDER_LIFECYCLE_V2.CANCELLED;
1001
+ j.updatedAt = now;
1002
+ if (!j.settledAt) j.settledAt = now;
1003
+ if (reason) j.metadata.cancelReason = String(reason);
1004
+ return { ...j, metadata: { ...j.metadata } };
1005
+ }
1006
+ export function getMktgovOrderV2(id) {
1007
+ const j = _mktgovJsV2.get(id);
1008
+ if (!j) return null;
1009
+ return { ...j, metadata: { ...j.metadata } };
1010
+ }
1011
+ export function listMktgovOrdersV2() {
1012
+ return [..._mktgovJsV2.values()].map((j) => ({
1013
+ ...j,
1014
+ metadata: { ...j.metadata },
1015
+ }));
1016
+ }
1017
+ export function autoSuspendIdleMktgovProfilesV2({ now } = {}) {
1018
+ const t = now ?? Date.now();
1019
+ const flipped = [];
1020
+ for (const p of _mktgovPsV2.values())
1021
+ if (
1022
+ p.status === MKTGOV_PROFILE_MATURITY_V2.ACTIVE &&
1023
+ t - p.lastTouchedAt >= _mktgovIdleMs
1024
+ ) {
1025
+ p.status = MKTGOV_PROFILE_MATURITY_V2.SUSPENDED;
1026
+ p.updatedAt = t;
1027
+ flipped.push(p.id);
1028
+ }
1029
+ return { flipped, count: flipped.length };
1030
+ }
1031
+ export function autoFailStuckMktgovOrdersV2({ now } = {}) {
1032
+ const t = now ?? Date.now();
1033
+ const flipped = [];
1034
+ for (const j of _mktgovJsV2.values())
1035
+ if (
1036
+ j.status === MKTGOV_ORDER_LIFECYCLE_V2.PROCESSING &&
1037
+ j.startedAt != null &&
1038
+ t - j.startedAt >= _mktgovStuckMs
1039
+ ) {
1040
+ j.status = MKTGOV_ORDER_LIFECYCLE_V2.FAILED;
1041
+ j.updatedAt = t;
1042
+ if (!j.settledAt) j.settledAt = t;
1043
+ j.metadata.failReason = "auto-fail-stuck";
1044
+ flipped.push(j.id);
1045
+ }
1046
+ return { flipped, count: flipped.length };
1047
+ }
1048
+ export function getSkillMarketplaceGovStatsV2() {
1049
+ const profilesByStatus = {};
1050
+ for (const v of Object.values(MKTGOV_PROFILE_MATURITY_V2))
1051
+ profilesByStatus[v] = 0;
1052
+ for (const p of _mktgovPsV2.values()) profilesByStatus[p.status]++;
1053
+ const ordersByStatus = {};
1054
+ for (const v of Object.values(MKTGOV_ORDER_LIFECYCLE_V2))
1055
+ ordersByStatus[v] = 0;
1056
+ for (const j of _mktgovJsV2.values()) ordersByStatus[j.status]++;
1057
+ return {
1058
+ totalMktgovProfilesV2: _mktgovPsV2.size,
1059
+ totalMktgovOrdersV2: _mktgovJsV2.size,
1060
+ maxActiveMktgovProfilesPerOwner: _mktgovMaxActive,
1061
+ maxPendingMktgovOrdersPerProfile: _mktgovMaxPending,
1062
+ mktgovProfileIdleMs: _mktgovIdleMs,
1063
+ mktgovOrderStuckMs: _mktgovStuckMs,
1064
+ profilesByStatus,
1065
+ ordersByStatus,
1066
+ };
1067
+ }