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
@@ -743,25 +743,53 @@ export function _resetV2State() {
743
743
  _v2StatusHistory.clear();
744
744
  }
745
745
 
746
-
747
746
  // ===== V2 Surface: App Builder governance overlay (CLI v0.138.0) =====
748
747
  export const APP_MATURITY_V2 = Object.freeze({
749
- PENDING: "pending", ACTIVE: "active", PAUSED: "paused", ARCHIVED: "archived",
748
+ PENDING: "pending",
749
+ ACTIVE: "active",
750
+ PAUSED: "paused",
751
+ ARCHIVED: "archived",
750
752
  });
751
753
  export const APP_BUILD_LIFECYCLE_V2 = Object.freeze({
752
- QUEUED: "queued", BUILDING: "building", SUCCEEDED: "succeeded", FAILED: "failed", CANCELLED: "cancelled",
754
+ QUEUED: "queued",
755
+ BUILDING: "building",
756
+ SUCCEEDED: "succeeded",
757
+ FAILED: "failed",
758
+ CANCELLED: "cancelled",
753
759
  });
754
760
 
755
761
  const _appTrans = new Map([
756
- [APP_MATURITY_V2.PENDING, new Set([APP_MATURITY_V2.ACTIVE, APP_MATURITY_V2.ARCHIVED])],
757
- [APP_MATURITY_V2.ACTIVE, new Set([APP_MATURITY_V2.PAUSED, APP_MATURITY_V2.ARCHIVED])],
758
- [APP_MATURITY_V2.PAUSED, new Set([APP_MATURITY_V2.ACTIVE, APP_MATURITY_V2.ARCHIVED])],
762
+ [
763
+ APP_MATURITY_V2.PENDING,
764
+ new Set([APP_MATURITY_V2.ACTIVE, APP_MATURITY_V2.ARCHIVED]),
765
+ ],
766
+ [
767
+ APP_MATURITY_V2.ACTIVE,
768
+ new Set([APP_MATURITY_V2.PAUSED, APP_MATURITY_V2.ARCHIVED]),
769
+ ],
770
+ [
771
+ APP_MATURITY_V2.PAUSED,
772
+ new Set([APP_MATURITY_V2.ACTIVE, APP_MATURITY_V2.ARCHIVED]),
773
+ ],
759
774
  [APP_MATURITY_V2.ARCHIVED, new Set()],
760
775
  ]);
761
776
  const _appTerminal = new Set([APP_MATURITY_V2.ARCHIVED]);
762
777
  const _appBuildTrans = new Map([
763
- [APP_BUILD_LIFECYCLE_V2.QUEUED, new Set([APP_BUILD_LIFECYCLE_V2.BUILDING, APP_BUILD_LIFECYCLE_V2.CANCELLED])],
764
- [APP_BUILD_LIFECYCLE_V2.BUILDING, new Set([APP_BUILD_LIFECYCLE_V2.SUCCEEDED, APP_BUILD_LIFECYCLE_V2.FAILED, APP_BUILD_LIFECYCLE_V2.CANCELLED])],
778
+ [
779
+ APP_BUILD_LIFECYCLE_V2.QUEUED,
780
+ new Set([
781
+ APP_BUILD_LIFECYCLE_V2.BUILDING,
782
+ APP_BUILD_LIFECYCLE_V2.CANCELLED,
783
+ ]),
784
+ ],
785
+ [
786
+ APP_BUILD_LIFECYCLE_V2.BUILDING,
787
+ new Set([
788
+ APP_BUILD_LIFECYCLE_V2.SUCCEEDED,
789
+ APP_BUILD_LIFECYCLE_V2.FAILED,
790
+ APP_BUILD_LIFECYCLE_V2.CANCELLED,
791
+ ]),
792
+ ],
765
793
  [APP_BUILD_LIFECYCLE_V2.SUCCEEDED, new Set()],
766
794
  [APP_BUILD_LIFECYCLE_V2.FAILED, new Set()],
767
795
  [APP_BUILD_LIFECYCLE_V2.CANCELLED, new Set()],
@@ -774,21 +802,45 @@ let _appMaxPendingBuildsPerApp = 20;
774
802
  let _appIdleMs = 30 * 24 * 60 * 60 * 1000;
775
803
  let _appBuildStuckMs = 10 * 60 * 1000;
776
804
 
777
- function _appPos(n, lbl) { const v = Math.floor(Number(n)); if (!Number.isFinite(v) || v <= 0) throw new Error(`${lbl} must be positive integer`); return v; }
805
+ function _appPos(n, lbl) {
806
+ const v = Math.floor(Number(n));
807
+ if (!Number.isFinite(v) || v <= 0)
808
+ throw new Error(`${lbl} must be positive integer`);
809
+ return v;
810
+ }
778
811
 
779
- export function setMaxActiveAppsPerOwnerV2(n) { _appMaxActivePerOwner = _appPos(n, "maxActiveAppsPerOwner"); }
780
- export function getMaxActiveAppsPerOwnerV2() { return _appMaxActivePerOwner; }
781
- export function setMaxPendingAppBuildsPerAppV2(n) { _appMaxPendingBuildsPerApp = _appPos(n, "maxPendingAppBuildsPerApp"); }
782
- export function getMaxPendingAppBuildsPerAppV2() { return _appMaxPendingBuildsPerApp; }
783
- export function setAppIdleMsV2(n) { _appIdleMs = _appPos(n, "appIdleMs"); }
784
- export function getAppIdleMsV2() { return _appIdleMs; }
785
- export function setAppBuildStuckMsV2(n) { _appBuildStuckMs = _appPos(n, "appBuildStuckMs"); }
786
- export function getAppBuildStuckMsV2() { return _appBuildStuckMs; }
812
+ export function setMaxActiveAppsPerOwnerV2(n) {
813
+ _appMaxActivePerOwner = _appPos(n, "maxActiveAppsPerOwner");
814
+ }
815
+ export function getMaxActiveAppsPerOwnerV2() {
816
+ return _appMaxActivePerOwner;
817
+ }
818
+ export function setMaxPendingAppBuildsPerAppV2(n) {
819
+ _appMaxPendingBuildsPerApp = _appPos(n, "maxPendingAppBuildsPerApp");
820
+ }
821
+ export function getMaxPendingAppBuildsPerAppV2() {
822
+ return _appMaxPendingBuildsPerApp;
823
+ }
824
+ export function setAppIdleMsV2(n) {
825
+ _appIdleMs = _appPos(n, "appIdleMs");
826
+ }
827
+ export function getAppIdleMsV2() {
828
+ return _appIdleMs;
829
+ }
830
+ export function setAppBuildStuckMsV2(n) {
831
+ _appBuildStuckMs = _appPos(n, "appBuildStuckMs");
832
+ }
833
+ export function getAppBuildStuckMsV2() {
834
+ return _appBuildStuckMs;
835
+ }
787
836
 
788
837
  export function _resetStateAppBuilderV2() {
789
- _appsV2.clear(); _appBuilds.clear();
790
- _appMaxActivePerOwner = 10; _appMaxPendingBuildsPerApp = 20;
791
- _appIdleMs = 30 * 24 * 60 * 60 * 1000; _appBuildStuckMs = 10 * 60 * 1000;
838
+ _appsV2.clear();
839
+ _appBuilds.clear();
840
+ _appMaxActivePerOwner = 10;
841
+ _appMaxPendingBuildsPerApp = 20;
842
+ _appIdleMs = 30 * 24 * 60 * 60 * 1000;
843
+ _appBuildStuckMs = 10 * 60 * 1000;
792
844
  }
793
845
 
794
846
  export function registerAppV2({ id, owner, name, metadata } = {}) {
@@ -796,28 +848,103 @@ export function registerAppV2({ id, owner, name, metadata } = {}) {
796
848
  if (!owner || typeof owner !== "string") throw new Error("owner is required");
797
849
  if (_appsV2.has(id)) throw new Error(`app ${id} already registered`);
798
850
  const now = Date.now();
799
- const a = { id, owner, name: name || id, status: APP_MATURITY_V2.PENDING, createdAt: now, updatedAt: now, activatedAt: null, archivedAt: null, lastTouchedAt: now, metadata: { ...(metadata || {}) } };
851
+ const a = {
852
+ id,
853
+ owner,
854
+ name: name || id,
855
+ status: APP_MATURITY_V2.PENDING,
856
+ createdAt: now,
857
+ updatedAt: now,
858
+ activatedAt: null,
859
+ archivedAt: null,
860
+ lastTouchedAt: now,
861
+ metadata: { ...(metadata || {}) },
862
+ };
800
863
  _appsV2.set(id, a);
801
864
  return { ...a, metadata: { ...a.metadata } };
802
865
  }
803
- function _appCheckA(from, to) { const a = _appTrans.get(from); if (!a || !a.has(to)) throw new Error(`invalid app transition ${from} → ${to}`); }
804
- function _appCountActive(owner) { let n = 0; for (const a of _appsV2.values()) if (a.owner === owner && a.status === APP_MATURITY_V2.ACTIVE) n++; return n; }
866
+ function _appCheckA(from, to) {
867
+ const a = _appTrans.get(from);
868
+ if (!a || !a.has(to))
869
+ throw new Error(`invalid app transition ${from} → ${to}`);
870
+ }
871
+ function _appCountActive(owner) {
872
+ let n = 0;
873
+ for (const a of _appsV2.values())
874
+ if (a.owner === owner && a.status === APP_MATURITY_V2.ACTIVE) n++;
875
+ return n;
876
+ }
805
877
 
806
878
  export function activateAppV2(id) {
807
- const a = _appsV2.get(id); if (!a) throw new Error(`app ${id} not found`);
879
+ const a = _appsV2.get(id);
880
+ if (!a) throw new Error(`app ${id} not found`);
808
881
  _appCheckA(a.status, APP_MATURITY_V2.ACTIVE);
809
882
  const recovery = a.status === APP_MATURITY_V2.PAUSED;
810
- if (!recovery) { const c = _appCountActive(a.owner); if (c >= _appMaxActivePerOwner) throw new Error(`max active apps per owner (${_appMaxActivePerOwner}) reached for ${a.owner}`); }
811
- const now = Date.now(); a.status = APP_MATURITY_V2.ACTIVE; a.updatedAt = now; a.lastTouchedAt = now; if (!a.activatedAt) a.activatedAt = now;
883
+ if (!recovery) {
884
+ const c = _appCountActive(a.owner);
885
+ if (c >= _appMaxActivePerOwner)
886
+ throw new Error(
887
+ `max active apps per owner (${_appMaxActivePerOwner}) reached for ${a.owner}`,
888
+ );
889
+ }
890
+ const now = Date.now();
891
+ a.status = APP_MATURITY_V2.ACTIVE;
892
+ a.updatedAt = now;
893
+ a.lastTouchedAt = now;
894
+ if (!a.activatedAt) a.activatedAt = now;
895
+ return { ...a, metadata: { ...a.metadata } };
896
+ }
897
+ export function pauseAppV2(id) {
898
+ const a = _appsV2.get(id);
899
+ if (!a) throw new Error(`app ${id} not found`);
900
+ _appCheckA(a.status, APP_MATURITY_V2.PAUSED);
901
+ a.status = APP_MATURITY_V2.PAUSED;
902
+ a.updatedAt = Date.now();
903
+ return { ...a, metadata: { ...a.metadata } };
904
+ }
905
+ export function archiveAppV2(id) {
906
+ const a = _appsV2.get(id);
907
+ if (!a) throw new Error(`app ${id} not found`);
908
+ _appCheckA(a.status, APP_MATURITY_V2.ARCHIVED);
909
+ const now = Date.now();
910
+ a.status = APP_MATURITY_V2.ARCHIVED;
911
+ a.updatedAt = now;
912
+ if (!a.archivedAt) a.archivedAt = now;
812
913
  return { ...a, metadata: { ...a.metadata } };
813
914
  }
814
- export function pauseAppV2(id) { const a = _appsV2.get(id); if (!a) throw new Error(`app ${id} not found`); _appCheckA(a.status, APP_MATURITY_V2.PAUSED); a.status = APP_MATURITY_V2.PAUSED; a.updatedAt = Date.now(); return { ...a, metadata: { ...a.metadata } }; }
815
- export function archiveAppV2(id) { const a = _appsV2.get(id); if (!a) throw new Error(`app ${id} not found`); _appCheckA(a.status, APP_MATURITY_V2.ARCHIVED); const now = Date.now(); a.status = APP_MATURITY_V2.ARCHIVED; a.updatedAt = now; if (!a.archivedAt) a.archivedAt = now; return { ...a, metadata: { ...a.metadata } }; }
816
- export function touchAppV2(id) { const a = _appsV2.get(id); if (!a) throw new Error(`app ${id} not found`); if (_appTerminal.has(a.status)) throw new Error(`cannot touch terminal app ${id}`); const now = Date.now(); a.lastTouchedAt = now; a.updatedAt = now; return { ...a, metadata: { ...a.metadata } }; }
817
- export function getAppV2(id) { const a = _appsV2.get(id); if (!a) return null; return { ...a, metadata: { ...a.metadata } }; }
818
- export function listAppsV2() { return [..._appsV2.values()].map((a) => ({ ...a, metadata: { ...a.metadata } })); }
915
+ export function touchAppV2(id) {
916
+ const a = _appsV2.get(id);
917
+ if (!a) throw new Error(`app ${id} not found`);
918
+ if (_appTerminal.has(a.status))
919
+ throw new Error(`cannot touch terminal app ${id}`);
920
+ const now = Date.now();
921
+ a.lastTouchedAt = now;
922
+ a.updatedAt = now;
923
+ return { ...a, metadata: { ...a.metadata } };
924
+ }
925
+ export function getAppV2(id) {
926
+ const a = _appsV2.get(id);
927
+ if (!a) return null;
928
+ return { ...a, metadata: { ...a.metadata } };
929
+ }
930
+ export function listAppsV2() {
931
+ return [..._appsV2.values()].map((a) => ({
932
+ ...a,
933
+ metadata: { ...a.metadata },
934
+ }));
935
+ }
819
936
 
820
- function _appCountPendingBuilds(appId) { let n = 0; for (const b of _appBuilds.values()) if (b.appId === appId && (b.status === APP_BUILD_LIFECYCLE_V2.QUEUED || b.status === APP_BUILD_LIFECYCLE_V2.BUILDING)) n++; return n; }
937
+ function _appCountPendingBuilds(appId) {
938
+ let n = 0;
939
+ for (const b of _appBuilds.values())
940
+ if (
941
+ b.appId === appId &&
942
+ (b.status === APP_BUILD_LIFECYCLE_V2.QUEUED ||
943
+ b.status === APP_BUILD_LIFECYCLE_V2.BUILDING)
944
+ )
945
+ n++;
946
+ return n;
947
+ }
821
948
 
822
949
  export function createAppBuildV2({ id, appId, target, metadata } = {}) {
823
950
  if (!id || typeof id !== "string") throw new Error("id is required");
@@ -825,25 +952,131 @@ export function createAppBuildV2({ id, appId, target, metadata } = {}) {
825
952
  if (_appBuilds.has(id)) throw new Error(`app build ${id} already exists`);
826
953
  if (!_appsV2.has(appId)) throw new Error(`app ${appId} not found`);
827
954
  const pending = _appCountPendingBuilds(appId);
828
- if (pending >= _appMaxPendingBuildsPerApp) throw new Error(`max pending app builds per app (${_appMaxPendingBuildsPerApp}) reached for ${appId}`);
955
+ if (pending >= _appMaxPendingBuildsPerApp)
956
+ throw new Error(
957
+ `max pending app builds per app (${_appMaxPendingBuildsPerApp}) reached for ${appId}`,
958
+ );
829
959
  const now = Date.now();
830
- const b = { id, appId, target: target || "web", status: APP_BUILD_LIFECYCLE_V2.QUEUED, createdAt: now, updatedAt: now, startedAt: null, settledAt: null, metadata: { ...(metadata || {}) } };
960
+ const b = {
961
+ id,
962
+ appId,
963
+ target: target || "web",
964
+ status: APP_BUILD_LIFECYCLE_V2.QUEUED,
965
+ createdAt: now,
966
+ updatedAt: now,
967
+ startedAt: null,
968
+ settledAt: null,
969
+ metadata: { ...(metadata || {}) },
970
+ };
831
971
  _appBuilds.set(id, b);
832
972
  return { ...b, metadata: { ...b.metadata } };
833
973
  }
834
- function _appCheckB(from, to) { const a = _appBuildTrans.get(from); if (!a || !a.has(to)) throw new Error(`invalid app build transition ${from} → ${to}`); }
835
- export function startAppBuildV2(id) { const b = _appBuilds.get(id); if (!b) throw new Error(`app build ${id} not found`); _appCheckB(b.status, APP_BUILD_LIFECYCLE_V2.BUILDING); const now = Date.now(); b.status = APP_BUILD_LIFECYCLE_V2.BUILDING; b.updatedAt = now; if (!b.startedAt) b.startedAt = now; return { ...b, metadata: { ...b.metadata } }; }
836
- export function succeedAppBuildV2(id) { const b = _appBuilds.get(id); if (!b) throw new Error(`app build ${id} not found`); _appCheckB(b.status, APP_BUILD_LIFECYCLE_V2.SUCCEEDED); const now = Date.now(); b.status = APP_BUILD_LIFECYCLE_V2.SUCCEEDED; b.updatedAt = now; if (!b.settledAt) b.settledAt = now; return { ...b, metadata: { ...b.metadata } }; }
837
- export function failAppBuildV2(id, reason) { const b = _appBuilds.get(id); if (!b) throw new Error(`app build ${id} not found`); _appCheckB(b.status, APP_BUILD_LIFECYCLE_V2.FAILED); const now = Date.now(); b.status = APP_BUILD_LIFECYCLE_V2.FAILED; b.updatedAt = now; if (!b.settledAt) b.settledAt = now; if (reason) b.metadata.failReason = String(reason); return { ...b, metadata: { ...b.metadata } }; }
838
- export function cancelAppBuildV2(id, reason) { const b = _appBuilds.get(id); if (!b) throw new Error(`app build ${id} not found`); _appCheckB(b.status, APP_BUILD_LIFECYCLE_V2.CANCELLED); const now = Date.now(); b.status = APP_BUILD_LIFECYCLE_V2.CANCELLED; b.updatedAt = now; if (!b.settledAt) b.settledAt = now; if (reason) b.metadata.cancelReason = String(reason); return { ...b, metadata: { ...b.metadata } }; }
839
- export function getAppBuildV2(id) { const b = _appBuilds.get(id); if (!b) return null; return { ...b, metadata: { ...b.metadata } }; }
840
- export function listAppBuildsV2() { return [..._appBuilds.values()].map((b) => ({ ...b, metadata: { ...b.metadata } })); }
974
+ function _appCheckB(from, to) {
975
+ const a = _appBuildTrans.get(from);
976
+ if (!a || !a.has(to))
977
+ throw new Error(`invalid app build transition ${from} ${to}`);
978
+ }
979
+ export function startAppBuildV2(id) {
980
+ const b = _appBuilds.get(id);
981
+ if (!b) throw new Error(`app build ${id} not found`);
982
+ _appCheckB(b.status, APP_BUILD_LIFECYCLE_V2.BUILDING);
983
+ const now = Date.now();
984
+ b.status = APP_BUILD_LIFECYCLE_V2.BUILDING;
985
+ b.updatedAt = now;
986
+ if (!b.startedAt) b.startedAt = now;
987
+ return { ...b, metadata: { ...b.metadata } };
988
+ }
989
+ export function succeedAppBuildV2(id) {
990
+ const b = _appBuilds.get(id);
991
+ if (!b) throw new Error(`app build ${id} not found`);
992
+ _appCheckB(b.status, APP_BUILD_LIFECYCLE_V2.SUCCEEDED);
993
+ const now = Date.now();
994
+ b.status = APP_BUILD_LIFECYCLE_V2.SUCCEEDED;
995
+ b.updatedAt = now;
996
+ if (!b.settledAt) b.settledAt = now;
997
+ return { ...b, metadata: { ...b.metadata } };
998
+ }
999
+ export function failAppBuildV2(id, reason) {
1000
+ const b = _appBuilds.get(id);
1001
+ if (!b) throw new Error(`app build ${id} not found`);
1002
+ _appCheckB(b.status, APP_BUILD_LIFECYCLE_V2.FAILED);
1003
+ const now = Date.now();
1004
+ b.status = APP_BUILD_LIFECYCLE_V2.FAILED;
1005
+ b.updatedAt = now;
1006
+ if (!b.settledAt) b.settledAt = now;
1007
+ if (reason) b.metadata.failReason = String(reason);
1008
+ return { ...b, metadata: { ...b.metadata } };
1009
+ }
1010
+ export function cancelAppBuildV2(id, reason) {
1011
+ const b = _appBuilds.get(id);
1012
+ if (!b) throw new Error(`app build ${id} not found`);
1013
+ _appCheckB(b.status, APP_BUILD_LIFECYCLE_V2.CANCELLED);
1014
+ const now = Date.now();
1015
+ b.status = APP_BUILD_LIFECYCLE_V2.CANCELLED;
1016
+ b.updatedAt = now;
1017
+ if (!b.settledAt) b.settledAt = now;
1018
+ if (reason) b.metadata.cancelReason = String(reason);
1019
+ return { ...b, metadata: { ...b.metadata } };
1020
+ }
1021
+ export function getAppBuildV2(id) {
1022
+ const b = _appBuilds.get(id);
1023
+ if (!b) return null;
1024
+ return { ...b, metadata: { ...b.metadata } };
1025
+ }
1026
+ export function listAppBuildsV2() {
1027
+ return [..._appBuilds.values()].map((b) => ({
1028
+ ...b,
1029
+ metadata: { ...b.metadata },
1030
+ }));
1031
+ }
841
1032
 
842
- export function autoPauseIdleAppsV2({ now } = {}) { const t = now ?? Date.now(); const flipped = []; for (const a of _appsV2.values()) if (a.status === APP_MATURITY_V2.ACTIVE && (t - a.lastTouchedAt) >= _appIdleMs) { a.status = APP_MATURITY_V2.PAUSED; a.updatedAt = t; flipped.push(a.id); } return { flipped, count: flipped.length }; }
843
- export function autoFailStuckAppBuildsV2({ now } = {}) { const t = now ?? Date.now(); const flipped = []; for (const b of _appBuilds.values()) if (b.status === APP_BUILD_LIFECYCLE_V2.BUILDING && b.startedAt != null && (t - b.startedAt) >= _appBuildStuckMs) { b.status = APP_BUILD_LIFECYCLE_V2.FAILED; b.updatedAt = t; if (!b.settledAt) b.settledAt = t; b.metadata.failReason = "auto-fail-stuck"; flipped.push(b.id); } return { flipped, count: flipped.length }; }
1033
+ export function autoPauseIdleAppsV2({ now } = {}) {
1034
+ const t = now ?? Date.now();
1035
+ const flipped = [];
1036
+ for (const a of _appsV2.values())
1037
+ if (
1038
+ a.status === APP_MATURITY_V2.ACTIVE &&
1039
+ t - a.lastTouchedAt >= _appIdleMs
1040
+ ) {
1041
+ a.status = APP_MATURITY_V2.PAUSED;
1042
+ a.updatedAt = t;
1043
+ flipped.push(a.id);
1044
+ }
1045
+ return { flipped, count: flipped.length };
1046
+ }
1047
+ export function autoFailStuckAppBuildsV2({ now } = {}) {
1048
+ const t = now ?? Date.now();
1049
+ const flipped = [];
1050
+ for (const b of _appBuilds.values())
1051
+ if (
1052
+ b.status === APP_BUILD_LIFECYCLE_V2.BUILDING &&
1053
+ b.startedAt != null &&
1054
+ t - b.startedAt >= _appBuildStuckMs
1055
+ ) {
1056
+ b.status = APP_BUILD_LIFECYCLE_V2.FAILED;
1057
+ b.updatedAt = t;
1058
+ if (!b.settledAt) b.settledAt = t;
1059
+ b.metadata.failReason = "auto-fail-stuck";
1060
+ flipped.push(b.id);
1061
+ }
1062
+ return { flipped, count: flipped.length };
1063
+ }
844
1064
 
845
1065
  export function getAppBuilderGovStatsV2() {
846
- const appsByStatus = {}; for (const s of Object.values(APP_MATURITY_V2)) appsByStatus[s] = 0; for (const a of _appsV2.values()) appsByStatus[a.status]++;
847
- const buildsByStatus = {}; for (const s of Object.values(APP_BUILD_LIFECYCLE_V2)) buildsByStatus[s] = 0; for (const b of _appBuilds.values()) buildsByStatus[b.status]++;
848
- return { totalAppsV2: _appsV2.size, totalAppBuildsV2: _appBuilds.size, maxActiveAppsPerOwner: _appMaxActivePerOwner, maxPendingAppBuildsPerApp: _appMaxPendingBuildsPerApp, appIdleMs: _appIdleMs, appBuildStuckMs: _appBuildStuckMs, appsByStatus, buildsByStatus };
1066
+ const appsByStatus = {};
1067
+ for (const s of Object.values(APP_MATURITY_V2)) appsByStatus[s] = 0;
1068
+ for (const a of _appsV2.values()) appsByStatus[a.status]++;
1069
+ const buildsByStatus = {};
1070
+ for (const s of Object.values(APP_BUILD_LIFECYCLE_V2)) buildsByStatus[s] = 0;
1071
+ for (const b of _appBuilds.values()) buildsByStatus[b.status]++;
1072
+ return {
1073
+ totalAppsV2: _appsV2.size,
1074
+ totalAppBuildsV2: _appBuilds.size,
1075
+ maxActiveAppsPerOwner: _appMaxActivePerOwner,
1076
+ maxPendingAppBuildsPerApp: _appMaxPendingBuildsPerApp,
1077
+ appIdleMs: _appIdleMs,
1078
+ appBuildStuckMs: _appBuildStuckMs,
1079
+ appsByStatus,
1080
+ buildsByStatus,
1081
+ };
849
1082
  }