chainlesschain 0.143.0 → 0.145.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 (133) hide show
  1. package/package.json +1 -1
  2. package/src/commands/a2a.js +196 -28
  3. package/src/commands/activitypub.js +157 -27
  4. package/src/commands/agent.js +587 -103
  5. package/src/commands/audit.js +206 -0
  6. package/src/commands/bi.js +152 -27
  7. package/src/commands/bm25.js +111 -27
  8. package/src/commands/browse.js +190 -29
  9. package/src/commands/ccron.js +128 -28
  10. package/src/commands/chat.js +207 -0
  11. package/src/commands/compliance.js +414 -34
  12. package/src/commands/compt.js +127 -29
  13. package/src/commands/consol.js +8 -2
  14. package/src/commands/cowork.js +580 -34
  15. package/src/commands/crosschain.js +182 -28
  16. package/src/commands/dao.js +182 -28
  17. package/src/commands/dlp.js +172 -27
  18. package/src/commands/economy.js +205 -50
  19. package/src/commands/evolution.js +203 -50
  20. package/src/commands/evomap.js +182 -27
  21. package/src/commands/fflag.js +74 -22
  22. package/src/commands/git.js +177 -37
  23. package/src/commands/hardening.js +209 -0
  24. package/src/commands/hmemory.js +204 -50
  25. package/src/commands/incentive.js +209 -0
  26. package/src/commands/inference.js +170 -34
  27. package/src/commands/itbudget.js +149 -33
  28. package/src/commands/kg.js +206 -0
  29. package/src/commands/lowcode.js +195 -38
  30. package/src/commands/marketplace.js +206 -0
  31. package/src/commands/matrix.js +179 -27
  32. package/src/commands/mcpscaf.js +145 -33
  33. package/src/commands/meminj.js +145 -33
  34. package/src/commands/nostr.js +178 -27
  35. package/src/commands/orchestrate.js +217 -0
  36. package/src/commands/orchgov.js +144 -33
  37. package/src/commands/pdfp.js +109 -27
  38. package/src/commands/perf.js +169 -32
  39. package/src/commands/perm.js +144 -33
  40. package/src/commands/pipeline.js +207 -52
  41. package/src/commands/planmode.js +141 -32
  42. package/src/commands/privacy.js +203 -0
  43. package/src/commands/promcomp.js +111 -27
  44. package/src/commands/recommend.js +177 -34
  45. package/src/commands/reputation.js +208 -0
  46. package/src/commands/sandbox.js +206 -0
  47. package/src/commands/seshhook.js +145 -33
  48. package/src/commands/seshsearch.js +141 -33
  49. package/src/commands/seshtail.js +144 -33
  50. package/src/commands/seshu.js +152 -33
  51. package/src/commands/sganal.js +123 -29
  52. package/src/commands/siem.js +201 -34
  53. package/src/commands/sla.js +212 -0
  54. package/src/commands/slotfill.js +146 -33
  55. package/src/commands/social.js +157 -32
  56. package/src/commands/stress.js +206 -0
  57. package/src/commands/svccont.js +145 -33
  58. package/src/commands/terraform.js +206 -0
  59. package/src/commands/tms.js +171 -33
  60. package/src/commands/topiccls.js +146 -33
  61. package/src/commands/uprof.js +141 -32
  62. package/src/commands/vcheck.js +122 -28
  63. package/src/commands/webfetch.js +141 -32
  64. package/src/commands/zkp.js +184 -28
  65. package/src/index.js +40 -0
  66. package/src/lib/a2a-protocol.js +319 -51
  67. package/src/lib/activitypub-bridge.js +288 -50
  68. package/src/lib/agent-economy.js +304 -51
  69. package/src/lib/app-builder.js +279 -46
  70. package/src/lib/audit-logger.js +321 -0
  71. package/src/lib/autonomous-agent.js +284 -48
  72. package/src/lib/bi-engine.js +283 -49
  73. package/src/lib/bm25-search.js +301 -49
  74. package/src/lib/browser-automation.js +296 -49
  75. package/src/lib/chat-core.js +336 -0
  76. package/src/lib/claude-code-bridge.js +341 -0
  77. package/src/lib/compliance-framework-reporter.js +305 -51
  78. package/src/lib/compliance-manager.js +330 -0
  79. package/src/lib/compression-telemetry.js +301 -49
  80. package/src/lib/content-recommender.js +317 -52
  81. package/src/lib/cowork-cron.js +298 -49
  82. package/src/lib/cowork-learning.js +333 -0
  83. package/src/lib/cowork-task-runner.js +308 -51
  84. package/src/lib/cowork-workflow.js +327 -0
  85. package/src/lib/cross-chain.js +311 -51
  86. package/src/lib/dao-governance.js +280 -46
  87. package/src/lib/dlp-engine.js +287 -49
  88. package/src/lib/evolution-system.js +278 -47
  89. package/src/lib/evomap-manager.js +280 -46
  90. package/src/lib/execution-backend.js +294 -48
  91. package/src/lib/feature-flags.js +294 -49
  92. package/src/lib/git-integration.js +285 -47
  93. package/src/lib/hardening-manager.js +341 -0
  94. package/src/lib/hierarchical-memory.js +284 -48
  95. package/src/lib/inference-network.js +308 -51
  96. package/src/lib/iteration-budget.js +302 -50
  97. package/src/lib/knowledge-graph.js +333 -0
  98. package/src/lib/matrix-bridge.js +281 -47
  99. package/src/lib/mcp-scaffold.js +318 -54
  100. package/src/lib/memory-injection.js +288 -49
  101. package/src/lib/nostr-bridge.js +286 -49
  102. package/src/lib/orchestrator.js +293 -48
  103. package/src/lib/pdf-parser.js +298 -49
  104. package/src/lib/perf-tuning.js +309 -50
  105. package/src/lib/permission-engine.js +287 -49
  106. package/src/lib/pipeline-orchestrator.js +289 -49
  107. package/src/lib/plan-mode.js +298 -51
  108. package/src/lib/privacy-computing.js +335 -0
  109. package/src/lib/reputation-optimizer.js +340 -0
  110. package/src/lib/sandbox-v2.js +327 -0
  111. package/src/lib/service-container.js +313 -52
  112. package/src/lib/session-consolidator.js +296 -49
  113. package/src/lib/session-hooks.js +312 -53
  114. package/src/lib/session-search.js +304 -51
  115. package/src/lib/session-tail.js +288 -49
  116. package/src/lib/session-usage.js +298 -52
  117. package/src/lib/siem-exporter.js +298 -51
  118. package/src/lib/skill-marketplace.js +345 -0
  119. package/src/lib/sla-manager.js +341 -0
  120. package/src/lib/slot-filler.js +303 -51
  121. package/src/lib/social-graph-analytics.js +295 -49
  122. package/src/lib/social-graph.js +272 -49
  123. package/src/lib/stress-tester.js +342 -0
  124. package/src/lib/sub-agent-registry.js +302 -53
  125. package/src/lib/task-model-selector.js +302 -50
  126. package/src/lib/terraform-manager.js +333 -0
  127. package/src/lib/todo-manager.js +281 -47
  128. package/src/lib/token-incentive.js +341 -0
  129. package/src/lib/topic-classifier.js +297 -49
  130. package/src/lib/user-profile.js +294 -50
  131. package/src/lib/version-checker.js +304 -50
  132. package/src/lib/web-fetch.js +292 -51
  133. package/src/lib/zkp-engine.js +286 -49
@@ -706,83 +706,329 @@ export function analyticsStats(snapshot, opts = {}) {
706
706
  };
707
707
  }
708
708
 
709
-
710
709
  // =====================================================================
711
710
  // Social Graph Analytics V2 governance overlay
712
711
  // =====================================================================
713
- export const SGAN_PROFILE_MATURITY_V2 = Object.freeze({ PENDING: "pending", ACTIVE: "active", STALE: "stale", ARCHIVED: "archived" });
714
- export const SGAN_RUN_LIFECYCLE_V2 = Object.freeze({ QUEUED: "queued", RUNNING: "running", COMPLETED: "completed", FAILED: "failed", CANCELLED: "cancelled" });
712
+ export const SGAN_PROFILE_MATURITY_V2 = Object.freeze({
713
+ PENDING: "pending",
714
+ ACTIVE: "active",
715
+ STALE: "stale",
716
+ ARCHIVED: "archived",
717
+ });
718
+ export const SGAN_RUN_LIFECYCLE_V2 = Object.freeze({
719
+ QUEUED: "queued",
720
+ RUNNING: "running",
721
+ COMPLETED: "completed",
722
+ FAILED: "failed",
723
+ CANCELLED: "cancelled",
724
+ });
715
725
  const _sganPTrans = new Map([
716
- [SGAN_PROFILE_MATURITY_V2.PENDING, new Set([SGAN_PROFILE_MATURITY_V2.ACTIVE, SGAN_PROFILE_MATURITY_V2.ARCHIVED])],
717
- [SGAN_PROFILE_MATURITY_V2.ACTIVE, new Set([SGAN_PROFILE_MATURITY_V2.STALE, SGAN_PROFILE_MATURITY_V2.ARCHIVED])],
718
- [SGAN_PROFILE_MATURITY_V2.STALE, new Set([SGAN_PROFILE_MATURITY_V2.ACTIVE, SGAN_PROFILE_MATURITY_V2.ARCHIVED])],
726
+ [
727
+ SGAN_PROFILE_MATURITY_V2.PENDING,
728
+ new Set([
729
+ SGAN_PROFILE_MATURITY_V2.ACTIVE,
730
+ SGAN_PROFILE_MATURITY_V2.ARCHIVED,
731
+ ]),
732
+ ],
733
+ [
734
+ SGAN_PROFILE_MATURITY_V2.ACTIVE,
735
+ new Set([
736
+ SGAN_PROFILE_MATURITY_V2.STALE,
737
+ SGAN_PROFILE_MATURITY_V2.ARCHIVED,
738
+ ]),
739
+ ],
740
+ [
741
+ SGAN_PROFILE_MATURITY_V2.STALE,
742
+ new Set([
743
+ SGAN_PROFILE_MATURITY_V2.ACTIVE,
744
+ SGAN_PROFILE_MATURITY_V2.ARCHIVED,
745
+ ]),
746
+ ],
719
747
  [SGAN_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
720
748
  ]);
721
749
  const _sganPTerminal = new Set([SGAN_PROFILE_MATURITY_V2.ARCHIVED]);
722
750
  const _sganJTrans = new Map([
723
- [SGAN_RUN_LIFECYCLE_V2.QUEUED, new Set([SGAN_RUN_LIFECYCLE_V2.RUNNING, SGAN_RUN_LIFECYCLE_V2.CANCELLED])],
724
- [SGAN_RUN_LIFECYCLE_V2.RUNNING, new Set([SGAN_RUN_LIFECYCLE_V2.COMPLETED, SGAN_RUN_LIFECYCLE_V2.FAILED, SGAN_RUN_LIFECYCLE_V2.CANCELLED])],
751
+ [
752
+ SGAN_RUN_LIFECYCLE_V2.QUEUED,
753
+ new Set([SGAN_RUN_LIFECYCLE_V2.RUNNING, SGAN_RUN_LIFECYCLE_V2.CANCELLED]),
754
+ ],
755
+ [
756
+ SGAN_RUN_LIFECYCLE_V2.RUNNING,
757
+ new Set([
758
+ SGAN_RUN_LIFECYCLE_V2.COMPLETED,
759
+ SGAN_RUN_LIFECYCLE_V2.FAILED,
760
+ SGAN_RUN_LIFECYCLE_V2.CANCELLED,
761
+ ]),
762
+ ],
725
763
  [SGAN_RUN_LIFECYCLE_V2.COMPLETED, new Set()],
726
764
  [SGAN_RUN_LIFECYCLE_V2.FAILED, new Set()],
727
765
  [SGAN_RUN_LIFECYCLE_V2.CANCELLED, new Set()],
728
766
  ]);
729
767
  const _sganPsV2 = new Map();
730
768
  const _sganJsV2 = new Map();
731
- let _sganMaxActive = 6, _sganMaxPending = 12, _sganIdleMs = 30 * 24 * 60 * 60 * 1000, _sganStuckMs = 60 * 1000;
732
- function _sganPos(n, label) { const v = Math.floor(Number(n)); if (!Number.isFinite(v) || v <= 0) throw new Error(`${label} must be positive integer`); return v; }
733
- function _sganCheckP(from, to) { const a = _sganPTrans.get(from); if (!a || !a.has(to)) throw new Error(`invalid sgan profile transition ${from} → ${to}`); }
734
- function _sganCheckJ(from, to) { const a = _sganJTrans.get(from); if (!a || !a.has(to)) throw new Error(`invalid sgan run transition ${from} → ${to}`); }
735
- function _sganCountActive(owner) { let c = 0; for (const p of _sganPsV2.values()) if (p.owner === owner && p.status === SGAN_PROFILE_MATURITY_V2.ACTIVE) c++; return c; }
736
- function _sganCountPending(profileId) { let c = 0; for (const j of _sganJsV2.values()) if (j.profileId === profileId && (j.status === SGAN_RUN_LIFECYCLE_V2.QUEUED || j.status === SGAN_RUN_LIFECYCLE_V2.RUNNING)) c++; return c; }
737
- export function setMaxActiveSganProfilesPerOwnerV2(n) { _sganMaxActive = _sganPos(n, "maxActiveSganProfilesPerOwner"); }
738
- export function getMaxActiveSganProfilesPerOwnerV2() { return _sganMaxActive; }
739
- export function setMaxPendingSganRunsPerProfileV2(n) { _sganMaxPending = _sganPos(n, "maxPendingSganRunsPerProfile"); }
740
- export function getMaxPendingSganRunsPerProfileV2() { return _sganMaxPending; }
741
- export function setSganProfileIdleMsV2(n) { _sganIdleMs = _sganPos(n, "sganProfileIdleMs"); }
742
- export function getSganProfileIdleMsV2() { return _sganIdleMs; }
743
- export function setSganRunStuckMsV2(n) { _sganStuckMs = _sganPos(n, "sganRunStuckMs"); }
744
- export function getSganRunStuckMsV2() { return _sganStuckMs; }
745
- export function _resetStateSocialGraphAnalyticsV2() { _sganPsV2.clear(); _sganJsV2.clear(); _sganMaxActive = 6; _sganMaxPending = 12; _sganIdleMs = 30 * 24 * 60 * 60 * 1000; _sganStuckMs = 60 * 1000; }
769
+ let _sganMaxActive = 6,
770
+ _sganMaxPending = 12,
771
+ _sganIdleMs = 30 * 24 * 60 * 60 * 1000,
772
+ _sganStuckMs = 60 * 1000;
773
+ function _sganPos(n, label) {
774
+ const v = Math.floor(Number(n));
775
+ if (!Number.isFinite(v) || v <= 0)
776
+ throw new Error(`${label} must be positive integer`);
777
+ return v;
778
+ }
779
+ function _sganCheckP(from, to) {
780
+ const a = _sganPTrans.get(from);
781
+ if (!a || !a.has(to))
782
+ throw new Error(`invalid sgan profile transition ${from} ${to}`);
783
+ }
784
+ function _sganCheckJ(from, to) {
785
+ const a = _sganJTrans.get(from);
786
+ if (!a || !a.has(to))
787
+ throw new Error(`invalid sgan run transition ${from} → ${to}`);
788
+ }
789
+ function _sganCountActive(owner) {
790
+ let c = 0;
791
+ for (const p of _sganPsV2.values())
792
+ if (p.owner === owner && p.status === SGAN_PROFILE_MATURITY_V2.ACTIVE) c++;
793
+ return c;
794
+ }
795
+ function _sganCountPending(profileId) {
796
+ let c = 0;
797
+ for (const j of _sganJsV2.values())
798
+ if (
799
+ j.profileId === profileId &&
800
+ (j.status === SGAN_RUN_LIFECYCLE_V2.QUEUED ||
801
+ j.status === SGAN_RUN_LIFECYCLE_V2.RUNNING)
802
+ )
803
+ c++;
804
+ return c;
805
+ }
806
+ export function setMaxActiveSganProfilesPerOwnerV2(n) {
807
+ _sganMaxActive = _sganPos(n, "maxActiveSganProfilesPerOwner");
808
+ }
809
+ export function getMaxActiveSganProfilesPerOwnerV2() {
810
+ return _sganMaxActive;
811
+ }
812
+ export function setMaxPendingSganRunsPerProfileV2(n) {
813
+ _sganMaxPending = _sganPos(n, "maxPendingSganRunsPerProfile");
814
+ }
815
+ export function getMaxPendingSganRunsPerProfileV2() {
816
+ return _sganMaxPending;
817
+ }
818
+ export function setSganProfileIdleMsV2(n) {
819
+ _sganIdleMs = _sganPos(n, "sganProfileIdleMs");
820
+ }
821
+ export function getSganProfileIdleMsV2() {
822
+ return _sganIdleMs;
823
+ }
824
+ export function setSganRunStuckMsV2(n) {
825
+ _sganStuckMs = _sganPos(n, "sganRunStuckMs");
826
+ }
827
+ export function getSganRunStuckMsV2() {
828
+ return _sganStuckMs;
829
+ }
830
+ export function _resetStateSocialGraphAnalyticsV2() {
831
+ _sganPsV2.clear();
832
+ _sganJsV2.clear();
833
+ _sganMaxActive = 6;
834
+ _sganMaxPending = 12;
835
+ _sganIdleMs = 30 * 24 * 60 * 60 * 1000;
836
+ _sganStuckMs = 60 * 1000;
837
+ }
746
838
  export function registerSganProfileV2({ id, owner, algorithm, metadata } = {}) {
747
839
  if (!id || !owner) throw new Error("id and owner required");
748
840
  if (_sganPsV2.has(id)) throw new Error(`sgan profile ${id} already exists`);
749
841
  const now = Date.now();
750
- const p = { id, owner, algorithm: algorithm || "centrality", status: SGAN_PROFILE_MATURITY_V2.PENDING, createdAt: now, updatedAt: now, lastTouchedAt: now, activatedAt: null, archivedAt: null, metadata: { ...(metadata || {}) } };
751
- _sganPsV2.set(id, p); return { ...p, metadata: { ...p.metadata } };
842
+ const p = {
843
+ id,
844
+ owner,
845
+ algorithm: algorithm || "centrality",
846
+ status: SGAN_PROFILE_MATURITY_V2.PENDING,
847
+ createdAt: now,
848
+ updatedAt: now,
849
+ lastTouchedAt: now,
850
+ activatedAt: null,
851
+ archivedAt: null,
852
+ metadata: { ...(metadata || {}) },
853
+ };
854
+ _sganPsV2.set(id, p);
855
+ return { ...p, metadata: { ...p.metadata } };
752
856
  }
753
857
  export function activateSganProfileV2(id) {
754
- const p = _sganPsV2.get(id); if (!p) throw new Error(`sgan profile ${id} not found`);
858
+ const p = _sganPsV2.get(id);
859
+ if (!p) throw new Error(`sgan profile ${id} not found`);
755
860
  const isInitial = p.status === SGAN_PROFILE_MATURITY_V2.PENDING;
756
861
  _sganCheckP(p.status, SGAN_PROFILE_MATURITY_V2.ACTIVE);
757
- if (isInitial && _sganCountActive(p.owner) >= _sganMaxActive) throw new Error(`max active sgan profiles for owner ${p.owner} reached`);
758
- const now = Date.now(); p.status = SGAN_PROFILE_MATURITY_V2.ACTIVE; p.updatedAt = now; p.lastTouchedAt = now;
862
+ if (isInitial && _sganCountActive(p.owner) >= _sganMaxActive)
863
+ throw new Error(`max active sgan profiles for owner ${p.owner} reached`);
864
+ const now = Date.now();
865
+ p.status = SGAN_PROFILE_MATURITY_V2.ACTIVE;
866
+ p.updatedAt = now;
867
+ p.lastTouchedAt = now;
759
868
  if (!p.activatedAt) p.activatedAt = now;
760
869
  return { ...p, metadata: { ...p.metadata } };
761
870
  }
762
- export function staleSganProfileV2(id) { const p = _sganPsV2.get(id); if (!p) throw new Error(`sgan profile ${id} not found`); _sganCheckP(p.status, SGAN_PROFILE_MATURITY_V2.STALE); p.status = SGAN_PROFILE_MATURITY_V2.STALE; p.updatedAt = Date.now(); return { ...p, metadata: { ...p.metadata } }; }
763
- export function archiveSganProfileV2(id) { const p = _sganPsV2.get(id); if (!p) throw new Error(`sgan profile ${id} not found`); _sganCheckP(p.status, SGAN_PROFILE_MATURITY_V2.ARCHIVED); const now = Date.now(); p.status = SGAN_PROFILE_MATURITY_V2.ARCHIVED; p.updatedAt = now; if (!p.archivedAt) p.archivedAt = now; return { ...p, metadata: { ...p.metadata } }; }
764
- export function touchSganProfileV2(id) { const p = _sganPsV2.get(id); if (!p) throw new Error(`sgan profile ${id} not found`); if (_sganPTerminal.has(p.status)) throw new Error(`cannot touch terminal sgan profile ${id}`); const now = Date.now(); p.lastTouchedAt = now; p.updatedAt = now; return { ...p, metadata: { ...p.metadata } }; }
765
- export function getSganProfileV2(id) { const p = _sganPsV2.get(id); if (!p) return null; return { ...p, metadata: { ...p.metadata } }; }
766
- export function listSganProfilesV2() { return [..._sganPsV2.values()].map((p) => ({ ...p, metadata: { ...p.metadata } })); }
871
+ export function staleSganProfileV2(id) {
872
+ const p = _sganPsV2.get(id);
873
+ if (!p) throw new Error(`sgan profile ${id} not found`);
874
+ _sganCheckP(p.status, SGAN_PROFILE_MATURITY_V2.STALE);
875
+ p.status = SGAN_PROFILE_MATURITY_V2.STALE;
876
+ p.updatedAt = Date.now();
877
+ return { ...p, metadata: { ...p.metadata } };
878
+ }
879
+ export function archiveSganProfileV2(id) {
880
+ const p = _sganPsV2.get(id);
881
+ if (!p) throw new Error(`sgan profile ${id} not found`);
882
+ _sganCheckP(p.status, SGAN_PROFILE_MATURITY_V2.ARCHIVED);
883
+ const now = Date.now();
884
+ p.status = SGAN_PROFILE_MATURITY_V2.ARCHIVED;
885
+ p.updatedAt = now;
886
+ if (!p.archivedAt) p.archivedAt = now;
887
+ return { ...p, metadata: { ...p.metadata } };
888
+ }
889
+ export function touchSganProfileV2(id) {
890
+ const p = _sganPsV2.get(id);
891
+ if (!p) throw new Error(`sgan profile ${id} not found`);
892
+ if (_sganPTerminal.has(p.status))
893
+ throw new Error(`cannot touch terminal sgan profile ${id}`);
894
+ const now = Date.now();
895
+ p.lastTouchedAt = now;
896
+ p.updatedAt = now;
897
+ return { ...p, metadata: { ...p.metadata } };
898
+ }
899
+ export function getSganProfileV2(id) {
900
+ const p = _sganPsV2.get(id);
901
+ if (!p) return null;
902
+ return { ...p, metadata: { ...p.metadata } };
903
+ }
904
+ export function listSganProfilesV2() {
905
+ return [..._sganPsV2.values()].map((p) => ({
906
+ ...p,
907
+ metadata: { ...p.metadata },
908
+ }));
909
+ }
767
910
  export function createSganRunV2({ id, profileId, snapshotId, metadata } = {}) {
768
911
  if (!id || !profileId) throw new Error("id and profileId required");
769
912
  if (_sganJsV2.has(id)) throw new Error(`sgan run ${id} already exists`);
770
- if (!_sganPsV2.has(profileId)) throw new Error(`sgan profile ${profileId} not found`);
771
- if (_sganCountPending(profileId) >= _sganMaxPending) throw new Error(`max pending sgan runs for profile ${profileId} reached`);
913
+ if (!_sganPsV2.has(profileId))
914
+ throw new Error(`sgan profile ${profileId} not found`);
915
+ if (_sganCountPending(profileId) >= _sganMaxPending)
916
+ throw new Error(`max pending sgan runs for profile ${profileId} reached`);
917
+ const now = Date.now();
918
+ const j = {
919
+ id,
920
+ profileId,
921
+ snapshotId: snapshotId || "",
922
+ status: SGAN_RUN_LIFECYCLE_V2.QUEUED,
923
+ createdAt: now,
924
+ updatedAt: now,
925
+ startedAt: null,
926
+ settledAt: null,
927
+ metadata: { ...(metadata || {}) },
928
+ };
929
+ _sganJsV2.set(id, j);
930
+ return { ...j, metadata: { ...j.metadata } };
931
+ }
932
+ export function runningSganRunV2(id) {
933
+ const j = _sganJsV2.get(id);
934
+ if (!j) throw new Error(`sgan run ${id} not found`);
935
+ _sganCheckJ(j.status, SGAN_RUN_LIFECYCLE_V2.RUNNING);
936
+ const now = Date.now();
937
+ j.status = SGAN_RUN_LIFECYCLE_V2.RUNNING;
938
+ j.updatedAt = now;
939
+ if (!j.startedAt) j.startedAt = now;
940
+ return { ...j, metadata: { ...j.metadata } };
941
+ }
942
+ export function completeSganRunV2(id) {
943
+ const j = _sganJsV2.get(id);
944
+ if (!j) throw new Error(`sgan run ${id} not found`);
945
+ _sganCheckJ(j.status, SGAN_RUN_LIFECYCLE_V2.COMPLETED);
946
+ const now = Date.now();
947
+ j.status = SGAN_RUN_LIFECYCLE_V2.COMPLETED;
948
+ j.updatedAt = now;
949
+ if (!j.settledAt) j.settledAt = now;
950
+ return { ...j, metadata: { ...j.metadata } };
951
+ }
952
+ export function failSganRunV2(id, reason) {
953
+ const j = _sganJsV2.get(id);
954
+ if (!j) throw new Error(`sgan run ${id} not found`);
955
+ _sganCheckJ(j.status, SGAN_RUN_LIFECYCLE_V2.FAILED);
772
956
  const now = Date.now();
773
- const j = { id, profileId, snapshotId: snapshotId || "", status: SGAN_RUN_LIFECYCLE_V2.QUEUED, createdAt: now, updatedAt: now, startedAt: null, settledAt: null, metadata: { ...(metadata || {}) } };
774
- _sganJsV2.set(id, j); return { ...j, metadata: { ...j.metadata } };
775
- }
776
- export function runningSganRunV2(id) { const j = _sganJsV2.get(id); if (!j) throw new Error(`sgan run ${id} not found`); _sganCheckJ(j.status, SGAN_RUN_LIFECYCLE_V2.RUNNING); const now = Date.now(); j.status = SGAN_RUN_LIFECYCLE_V2.RUNNING; j.updatedAt = now; if (!j.startedAt) j.startedAt = now; return { ...j, metadata: { ...j.metadata } }; }
777
- export function completeSganRunV2(id) { const j = _sganJsV2.get(id); if (!j) throw new Error(`sgan run ${id} not found`); _sganCheckJ(j.status, SGAN_RUN_LIFECYCLE_V2.COMPLETED); const now = Date.now(); j.status = SGAN_RUN_LIFECYCLE_V2.COMPLETED; j.updatedAt = now; if (!j.settledAt) j.settledAt = now; return { ...j, metadata: { ...j.metadata } }; }
778
- export function failSganRunV2(id, reason) { const j = _sganJsV2.get(id); if (!j) throw new Error(`sgan run ${id} not found`); _sganCheckJ(j.status, SGAN_RUN_LIFECYCLE_V2.FAILED); const now = Date.now(); j.status = SGAN_RUN_LIFECYCLE_V2.FAILED; j.updatedAt = now; if (!j.settledAt) j.settledAt = now; if (reason) j.metadata.failReason = String(reason); return { ...j, metadata: { ...j.metadata } }; }
779
- export function cancelSganRunV2(id, reason) { const j = _sganJsV2.get(id); if (!j) throw new Error(`sgan run ${id} not found`); _sganCheckJ(j.status, SGAN_RUN_LIFECYCLE_V2.CANCELLED); const now = Date.now(); j.status = SGAN_RUN_LIFECYCLE_V2.CANCELLED; j.updatedAt = now; if (!j.settledAt) j.settledAt = now; if (reason) j.metadata.cancelReason = String(reason); return { ...j, metadata: { ...j.metadata } }; }
780
- export function getSganRunV2(id) { const j = _sganJsV2.get(id); if (!j) return null; return { ...j, metadata: { ...j.metadata } }; }
781
- export function listSganRunsV2() { return [..._sganJsV2.values()].map((j) => ({ ...j, metadata: { ...j.metadata } })); }
782
- export function autoStaleIdleSganProfilesV2({ now } = {}) { const t = now ?? Date.now(); const flipped = []; for (const p of _sganPsV2.values()) if (p.status === SGAN_PROFILE_MATURITY_V2.ACTIVE && (t - p.lastTouchedAt) >= _sganIdleMs) { p.status = SGAN_PROFILE_MATURITY_V2.STALE; p.updatedAt = t; flipped.push(p.id); } return { flipped, count: flipped.length }; }
783
- export function autoFailStuckSganRunsV2({ now } = {}) { const t = now ?? Date.now(); const flipped = []; for (const j of _sganJsV2.values()) if (j.status === SGAN_RUN_LIFECYCLE_V2.RUNNING && j.startedAt != null && (t - j.startedAt) >= _sganStuckMs) { j.status = SGAN_RUN_LIFECYCLE_V2.FAILED; j.updatedAt = t; if (!j.settledAt) j.settledAt = t; j.metadata.failReason = "auto-fail-stuck"; flipped.push(j.id); } return { flipped, count: flipped.length }; }
957
+ j.status = SGAN_RUN_LIFECYCLE_V2.FAILED;
958
+ j.updatedAt = now;
959
+ if (!j.settledAt) j.settledAt = now;
960
+ if (reason) j.metadata.failReason = String(reason);
961
+ return { ...j, metadata: { ...j.metadata } };
962
+ }
963
+ export function cancelSganRunV2(id, reason) {
964
+ const j = _sganJsV2.get(id);
965
+ if (!j) throw new Error(`sgan run ${id} not found`);
966
+ _sganCheckJ(j.status, SGAN_RUN_LIFECYCLE_V2.CANCELLED);
967
+ const now = Date.now();
968
+ j.status = SGAN_RUN_LIFECYCLE_V2.CANCELLED;
969
+ j.updatedAt = now;
970
+ if (!j.settledAt) j.settledAt = now;
971
+ if (reason) j.metadata.cancelReason = String(reason);
972
+ return { ...j, metadata: { ...j.metadata } };
973
+ }
974
+ export function getSganRunV2(id) {
975
+ const j = _sganJsV2.get(id);
976
+ if (!j) return null;
977
+ return { ...j, metadata: { ...j.metadata } };
978
+ }
979
+ export function listSganRunsV2() {
980
+ return [..._sganJsV2.values()].map((j) => ({
981
+ ...j,
982
+ metadata: { ...j.metadata },
983
+ }));
984
+ }
985
+ export function autoStaleIdleSganProfilesV2({ now } = {}) {
986
+ const t = now ?? Date.now();
987
+ const flipped = [];
988
+ for (const p of _sganPsV2.values())
989
+ if (
990
+ p.status === SGAN_PROFILE_MATURITY_V2.ACTIVE &&
991
+ t - p.lastTouchedAt >= _sganIdleMs
992
+ ) {
993
+ p.status = SGAN_PROFILE_MATURITY_V2.STALE;
994
+ p.updatedAt = t;
995
+ flipped.push(p.id);
996
+ }
997
+ return { flipped, count: flipped.length };
998
+ }
999
+ export function autoFailStuckSganRunsV2({ now } = {}) {
1000
+ const t = now ?? Date.now();
1001
+ const flipped = [];
1002
+ for (const j of _sganJsV2.values())
1003
+ if (
1004
+ j.status === SGAN_RUN_LIFECYCLE_V2.RUNNING &&
1005
+ j.startedAt != null &&
1006
+ t - j.startedAt >= _sganStuckMs
1007
+ ) {
1008
+ j.status = SGAN_RUN_LIFECYCLE_V2.FAILED;
1009
+ j.updatedAt = t;
1010
+ if (!j.settledAt) j.settledAt = t;
1011
+ j.metadata.failReason = "auto-fail-stuck";
1012
+ flipped.push(j.id);
1013
+ }
1014
+ return { flipped, count: flipped.length };
1015
+ }
784
1016
  export function getSocialGraphAnalyticsGovStatsV2() {
785
- const profilesByStatus = {}; for (const v of Object.values(SGAN_PROFILE_MATURITY_V2)) profilesByStatus[v] = 0; for (const p of _sganPsV2.values()) profilesByStatus[p.status]++;
786
- const runsByStatus = {}; for (const v of Object.values(SGAN_RUN_LIFECYCLE_V2)) runsByStatus[v] = 0; for (const j of _sganJsV2.values()) runsByStatus[j.status]++;
787
- return { totalSganProfilesV2: _sganPsV2.size, totalSganRunsV2: _sganJsV2.size, maxActiveSganProfilesPerOwner: _sganMaxActive, maxPendingSganRunsPerProfile: _sganMaxPending, sganProfileIdleMs: _sganIdleMs, sganRunStuckMs: _sganStuckMs, profilesByStatus, runsByStatus };
1017
+ const profilesByStatus = {};
1018
+ for (const v of Object.values(SGAN_PROFILE_MATURITY_V2))
1019
+ profilesByStatus[v] = 0;
1020
+ for (const p of _sganPsV2.values()) profilesByStatus[p.status]++;
1021
+ const runsByStatus = {};
1022
+ for (const v of Object.values(SGAN_RUN_LIFECYCLE_V2)) runsByStatus[v] = 0;
1023
+ for (const j of _sganJsV2.values()) runsByStatus[j.status]++;
1024
+ return {
1025
+ totalSganProfilesV2: _sganPsV2.size,
1026
+ totalSganRunsV2: _sganJsV2.size,
1027
+ maxActiveSganProfilesPerOwner: _sganMaxActive,
1028
+ maxPendingSganRunsPerProfile: _sganMaxPending,
1029
+ sganProfileIdleMs: _sganIdleMs,
1030
+ sganRunStuckMs: _sganStuckMs,
1031
+ profilesByStatus,
1032
+ runsByStatus,
1033
+ };
788
1034
  }