@mmapp/react-compiler 0.1.0-alpha.15 → 0.1.0-alpha.17

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 (185) hide show
  1. package/dist/{chunk-NUPJYPFU.mjs → chunk-6LAII7OP.mjs} +79 -1
  2. package/dist/{chunk-UBDNXVL2.mjs → chunk-FPAMQXKB.mjs} +89 -3
  3. package/dist/cli/index.js +240 -9
  4. package/dist/cli/index.mjs +57 -9
  5. package/dist/dev-server.js +79 -1
  6. package/dist/dev-server.mjs +1 -1
  7. package/dist/index.js +79 -1
  8. package/dist/index.mjs +1 -1
  9. package/dist/{init-2CRSUGV5.mjs → init-CJCDWI33.mjs} +119 -0
  10. package/package.json +2 -2
  11. package/dist/chunk-26U577GB.mjs +0 -3465
  12. package/dist/chunk-2FBDFAX6.mjs +0 -2362
  13. package/dist/chunk-2L4QSMXG.mjs +0 -175
  14. package/dist/chunk-2REDFOER.mjs +0 -931
  15. package/dist/chunk-3USIFFE4.mjs +0 -2190
  16. package/dist/chunk-45YMGEVT.mjs +0 -186
  17. package/dist/chunk-46YKSHQR.mjs +0 -175
  18. package/dist/chunk-4FN2AISW.mjs +0 -148
  19. package/dist/chunk-4OPI5L7G.mjs +0 -2593
  20. package/dist/chunk-4RYTKOOJ.mjs +0 -186
  21. package/dist/chunk-4XHK6FWL.mjs +0 -2058
  22. package/dist/chunk-52XHYD2V.mjs +0 -214
  23. package/dist/chunk-5FTDWKHH.mjs +0 -244
  24. package/dist/chunk-5GUFFFGL.mjs +0 -148
  25. package/dist/chunk-5RKTOVR5.mjs +0 -244
  26. package/dist/chunk-5VNJ7C6N.mjs +0 -154
  27. package/dist/chunk-5YDMOO4X.mjs +0 -214
  28. package/dist/chunk-64ZWEMLJ.mjs +0 -148
  29. package/dist/chunk-6CQOAAMV.mjs +0 -1803
  30. package/dist/chunk-6SEVAAVT.mjs +0 -3516
  31. package/dist/chunk-6XP4KSWQ.mjs +0 -2190
  32. package/dist/chunk-6YLR5ZDA.mjs +0 -2829
  33. package/dist/chunk-72QWL54I.mjs +0 -175
  34. package/dist/chunk-7B4TRI7C.mjs +0 -4835
  35. package/dist/chunk-7JRAEFRB.mjs +0 -7510
  36. package/dist/chunk-7ZKGHTNB.mjs +0 -4952
  37. package/dist/chunk-AOGY2GK6.mjs +0 -3292
  38. package/dist/chunk-AXXUXRNA.mjs +0 -1434
  39. package/dist/chunk-CHLVKMQW.mjs +0 -175
  40. package/dist/chunk-CKGOZAB7.mjs +0 -939
  41. package/dist/chunk-D34RAZUX.mjs +0 -2223
  42. package/dist/chunk-DE3ZGQAC.mjs +0 -148
  43. package/dist/chunk-DMCY3BBG.mjs +0 -1933
  44. package/dist/chunk-DPIK3PJS.mjs +0 -244
  45. package/dist/chunk-E5IVH4RE.mjs +0 -186
  46. package/dist/chunk-E6FZNUR5.mjs +0 -4953
  47. package/dist/chunk-EJRBDQDP.mjs +0 -2607
  48. package/dist/chunk-ELO4TXJL.mjs +0 -186
  49. package/dist/chunk-EO6SYNCG.mjs +0 -175
  50. package/dist/chunk-EQGA6A6D.mjs +0 -121
  51. package/dist/chunk-EY2CSXYA.mjs +0 -822
  52. package/dist/chunk-FIQ65CDR.mjs +0 -925
  53. package/dist/chunk-FKRO52XH.mjs +0 -3446
  54. package/dist/chunk-FL4YAKU6.mjs +0 -4941
  55. package/dist/chunk-FOZXJFAR.mjs +0 -186
  56. package/dist/chunk-FX6URXWN.mjs +0 -186
  57. package/dist/chunk-FYT47UBU.mjs +0 -5076
  58. package/dist/chunk-G7SMOWOL.mjs +0 -828
  59. package/dist/chunk-GCLGPOJZ.mjs +0 -148
  60. package/dist/chunk-GGB4G5YY.mjs +0 -175
  61. package/dist/chunk-GXB4JOP7.mjs +0 -5072
  62. package/dist/chunk-HFXOUMTD.mjs +0 -175
  63. package/dist/chunk-HLRGCCIL.mjs +0 -4839
  64. package/dist/chunk-HOIUP6IF.mjs +0 -690
  65. package/dist/chunk-HRYR54PT.mjs +0 -175
  66. package/dist/chunk-HWIZ47US.mjs +0 -214
  67. package/dist/chunk-I3AU7GRD.mjs +0 -120
  68. package/dist/chunk-IB7MNPQL.mjs +0 -4953
  69. package/dist/chunk-ICSIHQCG.mjs +0 -148
  70. package/dist/chunk-ILFGMUVD.mjs +0 -1933
  71. package/dist/chunk-IPTX5MJU.mjs +0 -3223
  72. package/dist/chunk-ITGUSH2Z.mjs +0 -2783
  73. package/dist/chunk-IXHBCAMF.mjs +0 -3306
  74. package/dist/chunk-J7JUAHS4.mjs +0 -186
  75. package/dist/chunk-J7TWJ3TM.mjs +0 -2784
  76. package/dist/chunk-JDPLDGVF.mjs +0 -4810
  77. package/dist/chunk-JLA5VNQ3.mjs +0 -186
  78. package/dist/chunk-JQLWFCTM.mjs +0 -214
  79. package/dist/chunk-K53XP2DL.mjs +0 -148
  80. package/dist/chunk-K5HX2SVL.mjs +0 -1902
  81. package/dist/chunk-KFGYOOVS.mjs +0 -214
  82. package/dist/chunk-KFJJCQAL.mjs +0 -148
  83. package/dist/chunk-KFVVOS5N.mjs +0 -925
  84. package/dist/chunk-KJUIIEQE.mjs +0 -186
  85. package/dist/chunk-KNWTHRVQ.mjs +0 -175
  86. package/dist/chunk-KSG4XSZF.mjs +0 -175
  87. package/dist/chunk-L2OZ4CDV.mjs +0 -113
  88. package/dist/chunk-LF5N6DOU.mjs +0 -175
  89. package/dist/chunk-LJQCM2IM.mjs +0 -214
  90. package/dist/chunk-MIZV3TAN.mjs +0 -3293
  91. package/dist/chunk-NKKLQE5V.mjs +0 -148
  92. package/dist/chunk-NOW23XFZ.mjs +0 -186
  93. package/dist/chunk-NRXQKQ74.mjs +0 -148
  94. package/dist/chunk-NTB7OEX2.mjs +0 -2918
  95. package/dist/chunk-NW6555WJ.mjs +0 -186
  96. package/dist/chunk-O4AUS7EU.mjs +0 -148
  97. package/dist/chunk-OMZE6VLQ.mjs +0 -214
  98. package/dist/chunk-OPJKP747.mjs +0 -7506
  99. package/dist/chunk-OWI6XWCD.mjs +0 -3375
  100. package/dist/chunk-P4BR7WVO.mjs +0 -2190
  101. package/dist/chunk-PRUMNNDI.mjs +0 -3192
  102. package/dist/chunk-QQHVYH2X.mjs +0 -244
  103. package/dist/chunk-QTBD5B3F.mjs +0 -148
  104. package/dist/chunk-R57T26RR.mjs +0 -734
  105. package/dist/chunk-S5QLWLLT.mjs +0 -186
  106. package/dist/chunk-SCWGT2FY.mjs +0 -2190
  107. package/dist/chunk-SKSDPPNT.mjs +0 -3788
  108. package/dist/chunk-SMKJUSB3.mjs +0 -2190
  109. package/dist/chunk-SP2YUS33.mjs +0 -186
  110. package/dist/chunk-SU4E6E7B.mjs +0 -3153
  111. package/dist/chunk-SYUUKW5A.mjs +0 -3379
  112. package/dist/chunk-THFYE5ZX.mjs +0 -244
  113. package/dist/chunk-UDDTWG5J.mjs +0 -734
  114. package/dist/chunk-UL2XZEMA.mjs +0 -3128
  115. package/dist/chunk-VCAY2KGM.mjs +0 -175
  116. package/dist/chunk-VLTKQDJ3.mjs +0 -244
  117. package/dist/chunk-WBYMW4NQ.mjs +0 -3450
  118. package/dist/chunk-WECAV6QB.mjs +0 -148
  119. package/dist/chunk-WMKBXUCE.mjs +0 -3228
  120. package/dist/chunk-XAJ5BKKL.mjs +0 -4947
  121. package/dist/chunk-XG2X7AEA.mjs +0 -175
  122. package/dist/chunk-XG7Z23NQ.mjs +0 -148
  123. package/dist/chunk-XMWUHQVV.mjs +0 -939
  124. package/dist/chunk-XWZAOCQ7.mjs +0 -2607
  125. package/dist/chunk-XZNEDRGN.mjs +0 -3876
  126. package/dist/chunk-Y6FXYEAI.mjs +0 -10
  127. package/dist/chunk-Y6MA7ULW.mjs +0 -148
  128. package/dist/chunk-YFS6JMYO.mjs +0 -3342
  129. package/dist/chunk-YMS7Q7LG.mjs +0 -214
  130. package/dist/chunk-Z2G5RZ4H.mjs +0 -186
  131. package/dist/chunk-Z6AIQ4KL.mjs +0 -113
  132. package/dist/chunk-ZA37XTGA.mjs +0 -175
  133. package/dist/chunk-ZE3KCHBM.mjs +0 -2918
  134. package/dist/config-PL24KEWL.mjs +0 -219
  135. package/dist/dev-server-Bs_sz2DG.d.mts +0 -111
  136. package/dist/dev-server-Bs_sz2DG.d.ts +0 -111
  137. package/dist/dev-server-CjoufJ-u.d.mts +0 -109
  138. package/dist/dev-server-CjoufJ-u.d.ts +0 -109
  139. package/dist/dev-server-RmGHIntF.d.mts +0 -113
  140. package/dist/dev-server-RmGHIntF.d.ts +0 -113
  141. package/dist/engine-binary-QQUDACBJ.mjs +0 -455
  142. package/dist/envelope-DD7v0v6E.d.mts +0 -265
  143. package/dist/envelope-DD7v0v6E.d.ts +0 -265
  144. package/dist/envelope-vCVjrHlo.d.mts +0 -265
  145. package/dist/envelope-vCVjrHlo.d.ts +0 -265
  146. package/dist/index-B5gSgvnd.d.mts +0 -44
  147. package/dist/index-B5gSgvnd.d.ts +0 -44
  148. package/dist/index-Bs0MnR54.d.mts +0 -103
  149. package/dist/index-Bs0MnR54.d.ts +0 -103
  150. package/dist/index-DR0nNc_f.d.mts +0 -101
  151. package/dist/index-DR0nNc_f.d.ts +0 -101
  152. package/dist/index-revho_gS.d.mts +0 -104
  153. package/dist/index-revho_gS.d.ts +0 -104
  154. package/dist/init-7FJENUDK.mjs +0 -407
  155. package/dist/init-7JQMAAXS.mjs +0 -363
  156. package/dist/init-DQDX3QK6.mjs +0 -369
  157. package/dist/init-EHO4VQ22.mjs +0 -369
  158. package/dist/init-IXEE2RCF.mjs +0 -340
  159. package/dist/init-UC3FWPIW.mjs +0 -367
  160. package/dist/init-UNSMVKIK.mjs +0 -366
  161. package/dist/init-UNV5XIDE.mjs +0 -367
  162. package/dist/project-compiler-2P4N4DR7.mjs +0 -10
  163. package/dist/project-compiler-D2LCC27O.mjs +0 -10
  164. package/dist/project-compiler-EGJUTAJU.mjs +0 -10
  165. package/dist/project-compiler-EJ3GANJE.mjs +0 -10
  166. package/dist/project-compiler-LOQKVRZJ.mjs +0 -10
  167. package/dist/project-compiler-NNK32MPG.mjs +0 -10
  168. package/dist/project-compiler-OP2VVGJQ.mjs +0 -10
  169. package/dist/project-compiler-RQ6OQKRM.mjs +0 -10
  170. package/dist/project-compiler-VFR6CSDX.mjs +0 -10
  171. package/dist/project-compiler-VWNNCHGO.mjs +0 -10
  172. package/dist/project-compiler-XVAAU4C5.mjs +0 -10
  173. package/dist/project-compiler-YES5FGMD.mjs +0 -10
  174. package/dist/project-compiler-ZKMQDLGU.mjs +0 -10
  175. package/dist/project-decompiler-5GY2KSG4.mjs +0 -7
  176. package/dist/project-decompiler-FLXCEJHS.mjs +0 -7
  177. package/dist/project-decompiler-US7GAVIC.mjs +0 -7
  178. package/dist/project-decompiler-VLPR22QF.mjs +0 -7
  179. package/dist/pull-A2QUHW4K.mjs +0 -109
  180. package/dist/pull-FUS5QYZS.mjs +0 -109
  181. package/dist/pull-JBEQWVPE.mjs +0 -109
  182. package/dist/pull-LD5ENLGY.mjs +0 -109
  183. package/dist/pull-P44LDRWB.mjs +0 -109
  184. package/dist/verify-BYHUKARQ.mjs +0 -1833
  185. package/dist/verify-SEIXUGN4.mjs +0 -1833
@@ -1,113 +0,0 @@
1
- import { ViteDevServer } from 'vite';
2
- import { IRWorkflowDefinition } from '@mindmatrix/player-core';
3
-
4
- /**
5
- * CLI Build Command — compiles workflow files to Pure Form JSON.
6
- *
7
- * Supports three file types:
8
- * - *.workflow.tsx — React workflow components
9
- * - models/*.ts — TypeScript model files
10
- * - *.server.ts — Server action files
11
- *
12
- * Produces:
13
- * - *.workflow.json — IR (Pure Form)
14
- * - *.json — Engine-compatible definition
15
- * - envelope.json — Source envelope with file manifest
16
- */
17
-
18
- interface BuildOptions {
19
- src?: string;
20
- outDir?: string;
21
- mode?: 'strict' | 'infer';
22
- /** Generate source envelope. */
23
- envelope?: boolean;
24
- /** Blueprint slug for envelope. */
25
- slug?: string;
26
- /** Blueprint version for envelope. */
27
- version?: string;
28
- /** Skip TypeScript type checking (not recommended). */
29
- skipTypeCheck?: boolean;
30
- /** Watch mode: auto-recompile on file changes. */
31
- watch?: boolean;
32
- }
33
- interface BuildResult {
34
- compiled: number;
35
- errors: number;
36
- warnings: number;
37
- definitions: IRWorkflowDefinition[];
38
- errorDetails: {
39
- file: string;
40
- message: string;
41
- line?: number;
42
- }[];
43
- }
44
- declare function build(options?: BuildOptions): Promise<BuildResult>;
45
-
46
- /**
47
- * Dev Server — Vite-based development server for MindMatrix React workflows.
48
- *
49
- * Uses the Vite plugin to watch .workflow.tsx files. On file change:
50
- * 1. Compile through Babel plugin → extract IR
51
- * 2. Diff IR against last known state
52
- * 3. Notify connected frontends via WebSocket
53
- * 4. Optionally seed definitions to the dev API
54
- *
55
- * Usage (programmatic):
56
- * import { createDevServer } from '@mindmatrix/react-compiler';
57
- * const server = await createDevServer({ port: 5199 });
58
- * // ... server.close() to stop
59
- *
60
- * Usage (CLI):
61
- * mmrc dev --port 5199 --src src/workflows --seed
62
- */
63
-
64
- /** Minimal WebSocket interface — avoids requiring @types/ws at compile time */
65
- interface WsClient {
66
- readyState: number;
67
- send(data: string): void;
68
- close(): void;
69
- on(event: string, listener: (...args: unknown[]) => void): void;
70
- }
71
- interface DevServerOptions {
72
- /** Port for the dev server. Default: 5199 */
73
- port?: number;
74
- /** Source directory to watch. Default: 'src/workflows' */
75
- src?: string;
76
- /** Compilation mode. Default: 'infer' */
77
- mode?: 'strict' | 'infer';
78
- /** Glob patterns for workflow files. Default: ['**\/*.workflow.tsx'] */
79
- include?: string[];
80
- /** Output directory for .workflow.json sidecar files. Default: 'dist/workflows' */
81
- outDir?: string;
82
- /** Seed compiled definitions to the dev API on change. Default: false */
83
- seed?: boolean;
84
- /** Dev API base URL. Default: 'http://localhost:4200/api/v1' */
85
- apiUrl?: string;
86
- /** Auth token for dev API. Default: reads from MINDMATRIX_TOKEN env */
87
- authToken?: string;
88
- /** Enable WebSocket notification channel. Default: true */
89
- ws?: boolean;
90
- /** Open browser on start. Default: false */
91
- open?: boolean;
92
- }
93
- interface DevServerInstance {
94
- /** The underlying Vite dev server */
95
- vite: ViteDevServer;
96
- /** Port the server is running on */
97
- port: number;
98
- /** Connected WebSocket clients */
99
- clients: Set<WsClient>;
100
- /** Trigger a full rebuild of all workflow files */
101
- rebuild: () => Promise<BuildResult>;
102
- /** Stop the dev server */
103
- close: () => Promise<void>;
104
- }
105
- /**
106
- * Create and start a MindMatrix dev server.
107
- *
108
- * This is a thin Vite server configured with the mindmatrixReact plugin,
109
- * plus a WebSocket channel that pushes compile events to connected editors.
110
- */
111
- declare function createDevServer(options?: DevServerOptions): Promise<DevServerInstance>;
112
-
113
- export { type BuildOptions as B, type DevServerOptions as D, type DevServerInstance as a, build as b, createDevServer as c, type BuildResult as d };
@@ -1,113 +0,0 @@
1
- import { ViteDevServer } from 'vite';
2
- import { IRWorkflowDefinition } from '@mindmatrix/player-core';
3
-
4
- /**
5
- * CLI Build Command — compiles workflow files to Pure Form JSON.
6
- *
7
- * Supports three file types:
8
- * - *.workflow.tsx — React workflow components
9
- * - models/*.ts — TypeScript model files
10
- * - *.server.ts — Server action files
11
- *
12
- * Produces:
13
- * - *.workflow.json — IR (Pure Form)
14
- * - *.json — Engine-compatible definition
15
- * - envelope.json — Source envelope with file manifest
16
- */
17
-
18
- interface BuildOptions {
19
- src?: string;
20
- outDir?: string;
21
- mode?: 'strict' | 'infer';
22
- /** Generate source envelope. */
23
- envelope?: boolean;
24
- /** Blueprint slug for envelope. */
25
- slug?: string;
26
- /** Blueprint version for envelope. */
27
- version?: string;
28
- /** Skip TypeScript type checking (not recommended). */
29
- skipTypeCheck?: boolean;
30
- /** Watch mode: auto-recompile on file changes. */
31
- watch?: boolean;
32
- }
33
- interface BuildResult {
34
- compiled: number;
35
- errors: number;
36
- warnings: number;
37
- definitions: IRWorkflowDefinition[];
38
- errorDetails: {
39
- file: string;
40
- message: string;
41
- line?: number;
42
- }[];
43
- }
44
- declare function build(options?: BuildOptions): Promise<BuildResult>;
45
-
46
- /**
47
- * Dev Server — Vite-based development server for MindMatrix React workflows.
48
- *
49
- * Uses the Vite plugin to watch .workflow.tsx files. On file change:
50
- * 1. Compile through Babel plugin → extract IR
51
- * 2. Diff IR against last known state
52
- * 3. Notify connected frontends via WebSocket
53
- * 4. Optionally seed definitions to the dev API
54
- *
55
- * Usage (programmatic):
56
- * import { createDevServer } from '@mindmatrix/react-compiler';
57
- * const server = await createDevServer({ port: 5199 });
58
- * // ... server.close() to stop
59
- *
60
- * Usage (CLI):
61
- * mmrc dev --port 5199 --src src/workflows --seed
62
- */
63
-
64
- /** Minimal WebSocket interface — avoids requiring @types/ws at compile time */
65
- interface WsClient {
66
- readyState: number;
67
- send(data: string): void;
68
- close(): void;
69
- on(event: string, listener: (...args: unknown[]) => void): void;
70
- }
71
- interface DevServerOptions {
72
- /** Port for the dev server. Default: 5199 */
73
- port?: number;
74
- /** Source directory to watch. Default: 'src/workflows' */
75
- src?: string;
76
- /** Compilation mode. Default: 'infer' */
77
- mode?: 'strict' | 'infer';
78
- /** Glob patterns for workflow files. Default: ['**\/*.workflow.tsx'] */
79
- include?: string[];
80
- /** Output directory for .workflow.json sidecar files. Default: 'dist/workflows' */
81
- outDir?: string;
82
- /** Seed compiled definitions to the dev API on change. Default: false */
83
- seed?: boolean;
84
- /** Dev API base URL. Default: 'http://localhost:4200/api/v1' */
85
- apiUrl?: string;
86
- /** Auth token for dev API. Default: reads from MINDMATRIX_TOKEN env */
87
- authToken?: string;
88
- /** Enable WebSocket notification channel. Default: true */
89
- ws?: boolean;
90
- /** Open browser on start. Default: false */
91
- open?: boolean;
92
- }
93
- interface DevServerInstance {
94
- /** The underlying Vite dev server */
95
- vite: ViteDevServer;
96
- /** Port the server is running on */
97
- port: number;
98
- /** Connected WebSocket clients */
99
- clients: Set<WsClient>;
100
- /** Trigger a full rebuild of all workflow files */
101
- rebuild: () => Promise<BuildResult>;
102
- /** Stop the dev server */
103
- close: () => Promise<void>;
104
- }
105
- /**
106
- * Create and start a MindMatrix dev server.
107
- *
108
- * This is a thin Vite server configured with the mindmatrixReact plugin,
109
- * plus a WebSocket channel that pushes compile events to connected editors.
110
- */
111
- declare function createDevServer(options?: DevServerOptions): Promise<DevServerInstance>;
112
-
113
- export { type BuildOptions as B, type DevServerOptions as D, type DevServerInstance as a, build as b, createDevServer as c, type BuildResult as d };
@@ -1,455 +0,0 @@
1
- import {
2
- __require
3
- } from "./chunk-CIESM3BP.mjs";
4
-
5
- // src/cli/engine-binary.ts
6
- import { existsSync, mkdirSync, writeFileSync, readFileSync, chmodSync, createWriteStream, copyFileSync } from "fs";
7
- import { join, resolve } from "path";
8
- import { homedir, platform, arch } from "os";
9
- import { pipeline } from "stream/promises";
10
- import { spawn as nodeSpawn, execSync } from "child_process";
11
- var MMRC_BIN_DIR = join(homedir(), ".mmrc", "bin");
12
- var BINARY_NAME = platform() === "win32" ? "mm-api.exe" : "mm-api";
13
- var MANAGED_BINARY_PATH = join(MMRC_BIN_DIR, BINARY_NAME);
14
- var VERSION_FILE_PATH = join(MMRC_BIN_DIR, "mm-api.version");
15
- var METADATA_PATH = join(MMRC_BIN_DIR, "mm-api.json");
16
- var GITHUB_RELEASE_BASE = "https://github.com/dev-nested/mm-app/releases/download";
17
- var PROJECT_SEARCH_PATHS = [
18
- "engine/target/release/mm-server",
19
- "engine/target/debug/mm-server",
20
- "mm-core/target/release/mm-server",
21
- "mm-core/target/debug/mm-server",
22
- "target/release/mm-server",
23
- "target/debug/mm-server"
24
- ];
25
- function detectPlatform() {
26
- const os = platform();
27
- const a = arch();
28
- let triple;
29
- let releasePlatform = null;
30
- if (os === "linux" && a === "x64") {
31
- triple = "x86_64-unknown-linux-gnu";
32
- releasePlatform = "linux-x64";
33
- } else if (os === "linux" && a === "arm64") {
34
- triple = "aarch64-unknown-linux-gnu";
35
- releasePlatform = "linux-arm64";
36
- } else if (os === "darwin" && a === "x64") {
37
- triple = "x86_64-apple-darwin";
38
- releasePlatform = "darwin-x64";
39
- } else if (os === "darwin" && a === "arm64") {
40
- triple = "aarch64-apple-darwin";
41
- releasePlatform = "darwin-arm64";
42
- } else if (os === "win32" && a === "x64") {
43
- triple = "x86_64-pc-windows-msvc";
44
- releasePlatform = "windows-x64";
45
- } else {
46
- triple = `${a}-unknown-${os}`;
47
- }
48
- return { os, arch: a, triple, releasePlatform };
49
- }
50
- function getCachedVersion() {
51
- try {
52
- if (existsSync(VERSION_FILE_PATH)) {
53
- return readFileSync(VERSION_FILE_PATH, "utf-8").trim();
54
- }
55
- } catch {
56
- }
57
- return null;
58
- }
59
- function setCachedVersion(version) {
60
- mkdirSync(MMRC_BIN_DIR, { recursive: true });
61
- writeFileSync(VERSION_FILE_PATH, version, "utf-8");
62
- }
63
- function readMetadata() {
64
- try {
65
- if (!existsSync(METADATA_PATH)) return null;
66
- return JSON.parse(readFileSync(METADATA_PATH, "utf-8"));
67
- } catch {
68
- return null;
69
- }
70
- }
71
- function writeMetadata(meta) {
72
- mkdirSync(MMRC_BIN_DIR, { recursive: true });
73
- writeFileSync(METADATA_PATH, JSON.stringify(meta, null, 2), "utf-8");
74
- }
75
- async function verifyBinary(binaryPath) {
76
- if (!existsSync(binaryPath)) {
77
- return { ok: false, error: `Binary not found at ${binaryPath}` };
78
- }
79
- return new Promise((resolve2) => {
80
- try {
81
- const proc = nodeSpawn(binaryPath, ["--version"], {
82
- stdio: ["ignore", "pipe", "pipe"],
83
- timeout: 1e4
84
- });
85
- let stdout = "";
86
- let stderr = "";
87
- proc.stdout?.on("data", (d) => {
88
- stdout += d.toString();
89
- });
90
- proc.stderr?.on("data", (d) => {
91
- stderr += d.toString();
92
- });
93
- proc.on("error", (err) => {
94
- resolve2({ ok: false, error: `Failed to execute: ${err.message}` });
95
- });
96
- proc.on("close", (code) => {
97
- if (code === 0) {
98
- const output = stdout.trim() || stderr.trim();
99
- const version = output.replace(/^mm[-_](?:server|api)\s*/i, "").trim() || "unknown";
100
- resolve2({ ok: true, version });
101
- } else {
102
- resolve2({ ok: false, error: `Exited with code ${code}. ${stderr.trim()}` });
103
- }
104
- });
105
- } catch (e) {
106
- resolve2({ ok: false, error: `Spawn failed: ${e instanceof Error ? e.message : String(e)}` });
107
- }
108
- });
109
- }
110
- async function healthCheck(url, timeoutMs = 5e3) {
111
- try {
112
- const resp = await fetch(url, { signal: AbortSignal.timeout(timeoutMs) });
113
- if (resp.ok) {
114
- const data = await resp.json();
115
- return { ok: true, version: data.version, db: data.database };
116
- }
117
- return { ok: resp.status < 500 };
118
- } catch {
119
- return { ok: false };
120
- }
121
- }
122
- async function getEngineStatus(explicitPath) {
123
- const plat = detectPlatform();
124
- const resolution = findEngineBinary(explicitPath);
125
- const meta = readMetadata();
126
- let version = null;
127
- let verified = false;
128
- if (resolution.path) {
129
- const verify = await verifyBinary(resolution.path);
130
- if (verify.ok) {
131
- version = verify.version ?? null;
132
- verified = true;
133
- }
134
- }
135
- return {
136
- installed: resolution.path !== null,
137
- path: resolution.path,
138
- source: resolution.source,
139
- version,
140
- platform: plat,
141
- metadata: meta,
142
- verified
143
- };
144
- }
145
- async function installEngine(options) {
146
- const { force = false, preferBuild = false, version = "latest", cwd, prompt, fetch: fetchFn } = options ?? {};
147
- const plat = detectPlatform();
148
- if (!force && existsSync(MANAGED_BINARY_PATH)) {
149
- const meta = readMetadata();
150
- if (meta?.verified) {
151
- console.error(`[mmrc] Found cached binary (${meta.version}, ${meta.platform})`);
152
- }
153
- const verify = await verifyBinary(MANAGED_BINARY_PATH);
154
- if (verify.ok) {
155
- console.error(`[mmrc] Cached binary verified: ${verify.version}`);
156
- return { path: MANAGED_BINARY_PATH, source: "managed" };
157
- }
158
- console.error("[mmrc] Cached binary failed verification \u2014 reinstalling.");
159
- }
160
- if (preferBuild) {
161
- return await installViaBuild(plat, version, cwd, prompt);
162
- }
163
- if (plat.releasePlatform) {
164
- const dl = await downloadBinary({ version, platform: plat.releasePlatform, fetch: fetchFn });
165
- if (dl.success) {
166
- console.error("[mmrc] Verifying downloaded binary...");
167
- const verify = await verifyBinary(dl.path);
168
- if (verify.ok) {
169
- console.error(`[mmrc] Verification passed: ${verify.version}`);
170
- writeMetadata({
171
- version: verify.version ?? version,
172
- platform: plat.releasePlatform,
173
- triple: plat.triple,
174
- downloadedAt: (/* @__PURE__ */ new Date()).toISOString(),
175
- verified: true,
176
- source: "download",
177
- path: dl.path
178
- });
179
- return { path: dl.path, source: "downloaded" };
180
- }
181
- console.error(`[mmrc] Binary verification FAILED: ${verify.error}`);
182
- console.error("");
183
- console.error(` Platform: ${plat.releasePlatform} (${plat.triple})`);
184
- console.error(" This usually means:");
185
- console.error(" - Wrong architecture (e.g., ARM binary on x86)");
186
- console.error(" - Missing shared libraries (try: ldd " + dl.path + ")");
187
- console.error(" - Glibc version mismatch");
188
- console.error("");
189
- console.error("[mmrc] Falling back to build from source...\n");
190
- } else {
191
- console.error(`[mmrc] Download failed: ${dl.error}`);
192
- }
193
- } else {
194
- console.error(`[mmrc] No pre-built binary for ${plat.os}/${plat.arch}.`);
195
- }
196
- return await installViaBuild(plat, version, cwd, prompt);
197
- }
198
- async function installViaBuild(plat, version, cwd, prompt) {
199
- if (!hasCargoInstalled()) {
200
- console.error("[mmrc] Rust toolchain not found (cargo not in PATH).");
201
- console.error("");
202
- if (platform() === "win32") {
203
- console.error(" Install Rust from https://rustup.rs");
204
- } else {
205
- console.error(" Install Rust:");
206
- console.error(' curl --proto "=https" --tlsv1.2 -sSf https://sh.rustup.rs | sh');
207
- }
208
- console.error("");
209
- console.error(" Then restart your shell and run: mmrc engine build");
210
- return { path: null, source: "not-found" };
211
- }
212
- const built = await buildFromSource({ cwd, prompt });
213
- if (!built) return { path: null, source: "not-found" };
214
- console.error("[mmrc] Verifying built binary...");
215
- const verify = await verifyBinary(built);
216
- if (verify.ok) {
217
- console.error(`[mmrc] Build verified: ${verify.version}`);
218
- writeMetadata({
219
- version: verify.version ?? version,
220
- platform: plat.releasePlatform ?? `${plat.os}-${plat.arch}`,
221
- triple: plat.triple,
222
- downloadedAt: (/* @__PURE__ */ new Date()).toISOString(),
223
- verified: true,
224
- source: "build",
225
- path: built
226
- });
227
- return { path: built, source: "built" };
228
- }
229
- console.error(`[mmrc] Built binary also failed verification: ${verify.error}`);
230
- return { path: null, source: "not-found" };
231
- }
232
- function buildDownloadUrl(version, releasePlatform) {
233
- const tag = version.startsWith("v") ? version : `v${version}`;
234
- return `${GITHUB_RELEASE_BASE}/${tag}/mm-api-${releasePlatform}`;
235
- }
236
- async function downloadBinary(options) {
237
- const plat = options.platform ?? detectPlatform().releasePlatform;
238
- const dest = options.dest ?? MANAGED_BINARY_PATH;
239
- const fetchFn = options.fetch ?? globalThis.fetch;
240
- if (!plat) {
241
- return { success: false, path: dest, error: "Unsupported platform for pre-built binaries" };
242
- }
243
- const url = buildDownloadUrl(options.version, plat);
244
- console.error(`[mmrc] Downloading mm-api ${options.version} for ${plat}...`);
245
- console.error(`[mmrc] ${url}`);
246
- try {
247
- const response = await fetchFn(url, { redirect: "follow" });
248
- if (!response.ok) {
249
- return {
250
- success: false,
251
- path: dest,
252
- error: `HTTP ${response.status}: ${response.statusText} (${url})`
253
- };
254
- }
255
- mkdirSync(MMRC_BIN_DIR, { recursive: true });
256
- const body = response.body;
257
- if (!body) {
258
- return { success: false, path: dest, error: "Empty response body" };
259
- }
260
- const fileStream = createWriteStream(dest);
261
- await pipeline(body, fileStream);
262
- chmodSync(dest, 493);
263
- setCachedVersion(options.version);
264
- console.error(`[mmrc] Downloaded to ${dest}`);
265
- return { success: true, path: dest };
266
- } catch (err) {
267
- const message = err instanceof Error ? err.message : String(err);
268
- return { success: false, path: dest, error: message };
269
- }
270
- }
271
- function hasCargoInstalled() {
272
- try {
273
- execSync("cargo --version", { encoding: "utf-8", timeout: 5e3, stdio: "pipe" });
274
- return true;
275
- } catch {
276
- return false;
277
- }
278
- }
279
- async function askUser(question) {
280
- const readline = __require("readline");
281
- const rl = readline.createInterface({ input: process.stdin, output: process.stderr });
282
- return new Promise((resolve2) => {
283
- rl.question(question, (answer) => {
284
- rl.close();
285
- resolve2(answer.trim().toLowerCase());
286
- });
287
- });
288
- }
289
- async function buildFromSource(options) {
290
- const promptFn = options?.prompt ?? askUser;
291
- const cwd = options?.cwd ?? process.cwd();
292
- if (hasCargoInstalled()) {
293
- const answer = await promptFn("[mmrc] No pre-built binary available. Build from source? (y/n) ");
294
- if (answer !== "y" && answer !== "yes") return null;
295
- } else {
296
- const answer = await promptFn(
297
- "[mmrc] No pre-built binary available and Rust is not installed.\n Install Rust and build from source? (y/n) "
298
- );
299
- if (answer !== "y" && answer !== "yes") return null;
300
- console.error("[mmrc] Installing Rust via rustup...");
301
- try {
302
- execSync('curl --proto "=https" --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y', {
303
- stdio: "inherit",
304
- cwd,
305
- timeout: 3e5
306
- });
307
- const cargoEnv = join(homedir(), ".cargo", "env");
308
- if (existsSync(cargoEnv)) {
309
- execSync(`. ${cargoEnv}`, { stdio: "pipe" });
310
- }
311
- } catch (err) {
312
- console.error("[mmrc] Failed to install Rust:", err instanceof Error ? err.message : err);
313
- return null;
314
- }
315
- }
316
- console.error("[mmrc] Building mm-api from source (this may take a few minutes)...");
317
- try {
318
- execSync("cargo build --release -p mm-api", {
319
- stdio: "inherit",
320
- cwd,
321
- timeout: 6e5
322
- });
323
- } catch (err) {
324
- console.error("[mmrc] Build failed:", err instanceof Error ? err.message : err);
325
- return null;
326
- }
327
- const candidates = [
328
- join(cwd, "mm-core", "target", "release", "mm-server"),
329
- join(cwd, "target", "release", "mm-server")
330
- ];
331
- for (const p of candidates) {
332
- if (existsSync(p)) {
333
- mkdirSync(MMRC_BIN_DIR, { recursive: true });
334
- copyFileSync(p, MANAGED_BINARY_PATH);
335
- chmodSync(MANAGED_BINARY_PATH, 493);
336
- console.error(`[mmrc] Installed to ${MANAGED_BINARY_PATH}`);
337
- return MANAGED_BINARY_PATH;
338
- }
339
- }
340
- console.error("[mmrc] Build completed but binary not found in expected locations.");
341
- return null;
342
- }
343
- function findEngineBinary(explicitPath, cwd) {
344
- const workDir = cwd ?? process.cwd();
345
- if (explicitPath) {
346
- if (existsSync(explicitPath)) {
347
- return { path: explicitPath, source: "explicit" };
348
- }
349
- return { path: null, source: "not-found" };
350
- }
351
- if (existsSync(MANAGED_BINARY_PATH)) {
352
- return { path: MANAGED_BINARY_PATH, source: "managed" };
353
- }
354
- for (const rel of PROJECT_SEARCH_PATHS) {
355
- const abs = resolve(workDir, rel);
356
- if (existsSync(abs)) {
357
- return { path: abs, source: "project" };
358
- }
359
- }
360
- try {
361
- const cmd = platform() === "win32" ? "where mm-server 2>nul || where mm-api 2>nul" : "which mm-server 2>/dev/null || which mm-api 2>/dev/null";
362
- const result = execSync(cmd, { encoding: "utf-8", timeout: 5e3 }).trim();
363
- if (result) {
364
- return { path: result.split("\n")[0], source: "path" };
365
- }
366
- } catch {
367
- }
368
- return { path: null, source: "not-found" };
369
- }
370
- async function ensureEngineBinary(options) {
371
- const found = findEngineBinary(options?.explicitPath, options?.cwd);
372
- if (found.path) return found;
373
- const plat = detectPlatform();
374
- const version = options?.version ?? "latest";
375
- if (plat.releasePlatform) {
376
- const result = await downloadBinary({
377
- version,
378
- platform: plat.releasePlatform,
379
- fetch: options?.fetch
380
- });
381
- if (result.success) {
382
- return { path: result.path, source: "downloaded" };
383
- }
384
- console.error(`[mmrc] Download failed: ${result.error}`);
385
- } else {
386
- console.error(`[mmrc] No pre-built binary for ${plat.os}/${plat.arch}`);
387
- }
388
- if (!options?.nonInteractive) {
389
- const built = await buildFromSource({
390
- prompt: options?.prompt,
391
- cwd: options?.cwd
392
- });
393
- if (built) {
394
- return { path: built, source: "built" };
395
- }
396
- }
397
- return { path: null, source: "not-found" };
398
- }
399
- function printInstallGuide() {
400
- const plat = detectPlatform();
401
- console.error("[mmrc] MindMatrix engine binary not found.\n");
402
- console.error("The engine binary (mm-api) is required for local development.");
403
- console.error("Choose one of the following options:\n");
404
- console.error(" 1. Auto-download (recommended):");
405
- console.error(" mmrc dev # auto-downloads the binary");
406
- console.error("");
407
- console.error(" 2. Build from source (requires Rust toolchain):");
408
- console.error(' curl --proto "=https" --tlsv1.2 -sSf https://sh.rustup.rs | sh');
409
- console.error(" cargo build --release -p mm-api");
410
- console.error("");
411
- console.error(" 3. Download manually:");
412
- if (plat.releasePlatform) {
413
- console.error(` curl -L -o ~/.mmrc/bin/mm-api \\`);
414
- console.error(` ${GITHUB_RELEASE_BASE}/v0.1.0/mm-api-${plat.releasePlatform}`);
415
- console.error(` chmod +x ~/.mmrc/bin/mm-api`);
416
- } else {
417
- console.error(` # No pre-built binary for ${plat.triple} \u2014 build from source`);
418
- }
419
- console.error("");
420
- console.error(" 4. Use a remote backend instead of local:");
421
- console.error(" mmrc dev --api-url https://dev.mindmatrix.club/api/v1");
422
- console.error("");
423
- }
424
- function requireEngineBinary(explicitPath) {
425
- const result = findEngineBinary(explicitPath);
426
- if (!result.path) {
427
- printInstallGuide();
428
- process.exit(1);
429
- }
430
- return result.path;
431
- }
432
- export {
433
- GITHUB_RELEASE_BASE,
434
- MANAGED_BINARY_PATH,
435
- METADATA_PATH,
436
- VERSION_FILE_PATH,
437
- askUser,
438
- buildDownloadUrl,
439
- buildFromSource,
440
- detectPlatform,
441
- downloadBinary,
442
- ensureEngineBinary,
443
- findEngineBinary,
444
- getCachedVersion,
445
- getEngineStatus,
446
- hasCargoInstalled,
447
- healthCheck,
448
- installEngine,
449
- printInstallGuide,
450
- readMetadata,
451
- requireEngineBinary,
452
- setCachedVersion,
453
- verifyBinary,
454
- writeMetadata
455
- };