@mmapp/react-compiler 0.1.0-alpha.3 → 0.1.0-alpha.4

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 (117) hide show
  1. package/dist/auth-3UK75242.mjs +17 -0
  2. package/dist/babel/index.d.mts +2 -2
  3. package/dist/babel/index.d.ts +2 -2
  4. package/dist/babel/index.js +2736 -306
  5. package/dist/babel/index.mjs +1 -1
  6. package/dist/chunk-52XHYD2V.mjs +214 -0
  7. package/dist/chunk-5FTDWKHH.mjs +244 -0
  8. package/dist/chunk-5GUFFFGL.mjs +148 -0
  9. package/dist/chunk-7JRAEFRB.mjs +7510 -0
  10. package/dist/chunk-7T6Q5KAA.mjs +7506 -0
  11. package/dist/chunk-ABYPKRSB.mjs +215 -0
  12. package/dist/chunk-BZEXUPDH.mjs +175 -0
  13. package/dist/chunk-EO6SYNCG.mjs +175 -0
  14. package/dist/chunk-HRYR54PT.mjs +175 -0
  15. package/dist/chunk-J3M4GUS7.mjs +161 -0
  16. package/dist/chunk-J7JUAHS4.mjs +186 -0
  17. package/dist/chunk-JRGFBWTN.mjs +2918 -0
  18. package/dist/chunk-NTB7OEX2.mjs +2918 -0
  19. package/dist/chunk-O4AUS7EU.mjs +148 -0
  20. package/dist/chunk-OPJKP747.mjs +7506 -0
  21. package/dist/chunk-R2DD5GTY.mjs +186 -0
  22. package/dist/chunk-THFYE5ZX.mjs +244 -0
  23. package/dist/chunk-UDDTWG5J.mjs +734 -0
  24. package/dist/chunk-VLTKQDJ3.mjs +244 -0
  25. package/dist/chunk-WBYMW4NQ.mjs +3450 -0
  26. package/dist/chunk-WVYY32LD.mjs +939 -0
  27. package/dist/chunk-XDVM4YHX.mjs +3450 -0
  28. package/dist/chunk-Z2G5RZ4H.mjs +186 -0
  29. package/dist/chunk-ZE3KCHBM.mjs +2918 -0
  30. package/dist/cli/index.js +10378 -4107
  31. package/dist/cli/index.mjs +224 -183
  32. package/dist/codemod/cli.js +1 -1
  33. package/dist/codemod/cli.mjs +1 -1
  34. package/dist/codemod/index.d.mts +3 -3
  35. package/dist/codemod/index.d.ts +3 -3
  36. package/dist/codemod/index.js +1 -1
  37. package/dist/codemod/index.mjs +1 -1
  38. package/dist/config-PL24KEWL.mjs +219 -0
  39. package/dist/deploy-YAJGW6II.mjs +9 -0
  40. package/dist/dev-server-CrQ041KP.d.mts +79 -0
  41. package/dist/dev-server-CrQ041KP.d.ts +79 -0
  42. package/dist/dev-server.d.mts +2 -2
  43. package/dist/dev-server.d.ts +2 -2
  44. package/dist/dev-server.js +4319 -421
  45. package/dist/dev-server.mjs +4 -4
  46. package/dist/envelope-ChEkuHij.d.mts +265 -0
  47. package/dist/envelope-ChEkuHij.d.ts +265 -0
  48. package/dist/envelope.d.mts +2 -2
  49. package/dist/envelope.d.ts +2 -2
  50. package/dist/envelope.js +2734 -304
  51. package/dist/envelope.mjs +2 -2
  52. package/dist/index-CEKyyazf.d.mts +104 -0
  53. package/dist/index-CEKyyazf.d.ts +104 -0
  54. package/dist/index.d.mts +164 -9
  55. package/dist/index.d.ts +164 -9
  56. package/dist/index.js +4730 -734
  57. package/dist/index.mjs +216 -8
  58. package/dist/init-7FJENUDK.mjs +407 -0
  59. package/dist/init-DQDX3QK6.mjs +369 -0
  60. package/dist/project-compiler-NNK32MPG.mjs +10 -0
  61. package/dist/project-compiler-OP2VVGJQ.mjs +10 -0
  62. package/dist/project-compiler-ZB4RUYVL.mjs +10 -0
  63. package/dist/project-decompiler-U55HQUHW.mjs +7 -0
  64. package/dist/project-decompiler-US7GAVIC.mjs +7 -0
  65. package/dist/pull-KOL2QAYQ.mjs +109 -0
  66. package/dist/pull-P44LDRWB.mjs +109 -0
  67. package/dist/seed-KOGEPGOJ.mjs +154 -0
  68. package/dist/server-VW6UPCHO.mjs +277 -0
  69. package/dist/testing/index.d.mts +8 -8
  70. package/dist/testing/index.d.ts +8 -8
  71. package/dist/testing/index.js +2744 -314
  72. package/dist/testing/index.mjs +1 -1
  73. package/dist/verify-BYHUKARQ.mjs +1833 -0
  74. package/dist/verify-OQDEQYMS.mjs +1833 -0
  75. package/dist/verify-SEIXUGN4.mjs +1833 -0
  76. package/dist/vite/index.d.mts +1 -1
  77. package/dist/vite/index.d.ts +1 -1
  78. package/dist/vite/index.js +2735 -305
  79. package/dist/vite/index.mjs +2 -2
  80. package/examples/authentication/main.workflow.tsx +1 -1
  81. package/examples/authentication/mm.config.ts +1 -1
  82. package/examples/authentication/pages/LoginPage.tsx +2 -2
  83. package/examples/authentication/pages/SignupPage.tsx +2 -2
  84. package/examples/counter.workflow.tsx +1 -1
  85. package/examples/dashboard.workflow.tsx +1 -1
  86. package/examples/invoice-approval/actions/invoice.server.ts +1 -1
  87. package/examples/invoice-approval/main.workflow.tsx +1 -1
  88. package/examples/invoice-approval/mm.config.ts +1 -1
  89. package/examples/invoice-approval/pages/InvoiceDetailPage.tsx +1 -1
  90. package/examples/invoice-approval/pages/InvoiceFormPage.tsx +1 -1
  91. package/examples/invoice-approval/pages/InvoiceListPage.tsx +1 -1
  92. package/examples/todo-app.workflow.tsx +1 -1
  93. package/examples/uber-app/actions/matching.server.ts +1 -1
  94. package/examples/uber-app/actions/notifications.server.ts +1 -1
  95. package/examples/uber-app/actions/payments.server.ts +1 -1
  96. package/examples/uber-app/actions/pricing.server.ts +1 -1
  97. package/examples/uber-app/app/admin/analytics.tsx +2 -2
  98. package/examples/uber-app/app/admin/fleet.tsx +2 -2
  99. package/examples/uber-app/app/admin/surge-pricing.tsx +2 -2
  100. package/examples/uber-app/app/driver/dashboard.tsx +2 -2
  101. package/examples/uber-app/app/driver/earnings.tsx +2 -2
  102. package/examples/uber-app/app/driver/navigation.tsx +2 -2
  103. package/examples/uber-app/app/driver/ride-acceptance.tsx +2 -2
  104. package/examples/uber-app/app/rider/home.tsx +2 -2
  105. package/examples/uber-app/app/rider/payment-methods.tsx +2 -2
  106. package/examples/uber-app/app/rider/ride-history.tsx +2 -2
  107. package/examples/uber-app/app/rider/ride-tracking.tsx +2 -2
  108. package/examples/uber-app/components/DriverCard.tsx +1 -1
  109. package/examples/uber-app/components/MapView.tsx +3 -3
  110. package/examples/uber-app/components/RatingStars.tsx +2 -2
  111. package/examples/uber-app/components/RideCard.tsx +1 -1
  112. package/examples/uber-app/mm.config.ts +1 -1
  113. package/examples/uber-app/workflows/dispute-resolution.workflow.tsx +2 -2
  114. package/examples/uber-app/workflows/driver-onboarding.workflow.tsx +2 -2
  115. package/examples/uber-app/workflows/payment-processing.workflow.tsx +2 -2
  116. package/examples/uber-app/workflows/ride-request.workflow.tsx +2 -2
  117. package/package.json +8 -3
@@ -0,0 +1,175 @@
1
+ import {
2
+ babelPlugin
3
+ } from "./chunk-7JRAEFRB.mjs";
4
+
5
+ // src/vite/index.ts
6
+ import { transformSync } from "@babel/core";
7
+ import { writeFileSync, mkdirSync } from "fs";
8
+ import { dirname, join, relative, basename } from "path";
9
+ function mindmatrixReact(options) {
10
+ const include = options?.include ?? ["**/*.workflow.tsx"];
11
+ const mode = options?.mode ?? "infer";
12
+ const outDir = options?.outDir ?? "dist/workflows";
13
+ const seedOnCompile = options?.seedOnCompile ?? false;
14
+ const apiUrl = options?.apiUrl ?? "http://localhost:4200/api/v1";
15
+ const authToken = options?.authToken ?? process.env.MINDMATRIX_TOKEN;
16
+ let enableSourceMaps = options?.sourceMaps;
17
+ let enableSourceAnnotations = options?.sourceAnnotations;
18
+ let isDev = true;
19
+ const compiledFiles = /* @__PURE__ */ new Map();
20
+ function shouldTransform(id) {
21
+ return include.some((pattern) => {
22
+ const regex = pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*\*/g, "<<GLOBSTAR>>").replace(/\*/g, "[^/]*").replace(/<<GLOBSTAR>>/g, ".*").replace(/\?/g, ".");
23
+ return new RegExp(regex).test(id);
24
+ });
25
+ }
26
+ async function seedToApi(ir, filePath) {
27
+ if (!seedOnCompile || !authToken) return;
28
+ try {
29
+ const body = {
30
+ slug: ir.slug,
31
+ name: ir.name,
32
+ version: ir.version,
33
+ category: ir.category || "workflow",
34
+ fields: ir.fields || [],
35
+ states: ir.states || [],
36
+ transitions: ir.transitions || [],
37
+ experience: ir.experience || {},
38
+ metadata: {
39
+ ...ir.metadata || {},
40
+ source_file: relative(process.cwd(), filePath),
41
+ compiled_at: (/* @__PURE__ */ new Date()).toISOString()
42
+ }
43
+ };
44
+ const resp = await fetch(`${apiUrl}/workflow/definitions`, {
45
+ method: "POST",
46
+ headers: {
47
+ "Content-Type": "application/json",
48
+ "Authorization": `Bearer ${authToken}`
49
+ },
50
+ body: JSON.stringify(body)
51
+ });
52
+ if (resp.ok) {
53
+ console.log(`[mindmatrix-react] Seeded ${ir.slug} to ${apiUrl}`);
54
+ } else if (resp.status === 409) {
55
+ const existing = await fetch(
56
+ `${apiUrl}/workflow/definitions?slug=${encodeURIComponent(ir.slug)}&version=${encodeURIComponent(ir.version)}`,
57
+ { headers: { "Authorization": `Bearer ${authToken}` } }
58
+ );
59
+ if (existing.ok) {
60
+ const data = await existing.json();
61
+ const defId = Array.isArray(data) ? data[0]?.id : data?.id;
62
+ if (defId) {
63
+ await fetch(`${apiUrl}/workflow/definitions/${defId}`, {
64
+ method: "PATCH",
65
+ headers: {
66
+ "Content-Type": "application/json",
67
+ "Authorization": `Bearer ${authToken}`
68
+ },
69
+ body: JSON.stringify(body)
70
+ });
71
+ console.log(`[mindmatrix-react] Updated ${ir.slug} (PATCH)`);
72
+ }
73
+ }
74
+ } else {
75
+ const text = await resp.text().catch(() => "");
76
+ console.warn(`[mindmatrix-react] Seed failed (${resp.status}): ${text.slice(0, 200)}`);
77
+ }
78
+ } catch (e) {
79
+ console.warn(`[mindmatrix-react] Seed failed:`, e instanceof Error ? e.message : e);
80
+ }
81
+ }
82
+ return {
83
+ name: "mindmatrix-react",
84
+ enforce: "pre",
85
+ configResolved(config) {
86
+ isDev = config.command === "serve";
87
+ if (enableSourceMaps === void 0) enableSourceMaps = isDev;
88
+ if (enableSourceAnnotations === void 0) enableSourceAnnotations = isDev;
89
+ },
90
+ transform(code, id) {
91
+ if (!shouldTransform(id)) return null;
92
+ try {
93
+ const wantMaps = enableSourceMaps !== false;
94
+ const result = transformSync(code, {
95
+ filename: id,
96
+ plugins: [[babelPlugin, { mode, filename: id, sourceAnnotations: enableSourceAnnotations }]],
97
+ parserOpts: { plugins: ["jsx", "typescript"] },
98
+ sourceMaps: wantMaps,
99
+ // Embed original source in the source map so debuggers can show .workflow.tsx
100
+ ...wantMaps ? { sourceFileName: basename(id) } : {}
101
+ });
102
+ if (!result?.code) return null;
103
+ const metadata = result.metadata || {};
104
+ const ir = metadata.mindmatrixIR;
105
+ const warnings = metadata.mindmatrixWarnings;
106
+ const errors = metadata.mindmatrixErrors;
107
+ if (warnings?.length) {
108
+ for (const w of warnings) {
109
+ console.warn(`[mindmatrix-react] ${basename(id)}: ${w.message}`);
110
+ }
111
+ }
112
+ if (errors?.length) {
113
+ for (const e of errors) {
114
+ if (mode === "strict") {
115
+ this.error(`${basename(id)}: ${e.message}`);
116
+ } else {
117
+ this.warn(`${basename(id)}: ${e.message}`);
118
+ }
119
+ }
120
+ }
121
+ if (ir) {
122
+ compiledFiles.set(id, ir);
123
+ const outputFileName = basename(id).replace(/\.tsx?$/, ".workflow.json");
124
+ const outputPath = join(process.cwd(), outDir, outputFileName);
125
+ mkdirSync(dirname(outputPath), { recursive: true });
126
+ writeFileSync(outputPath, JSON.stringify(ir, null, 2), "utf-8");
127
+ console.log(`[mindmatrix-react] Compiled ${basename(id)} \u2192 ${outputFileName}`);
128
+ seedToApi(ir, id);
129
+ }
130
+ if (!enableSourceAnnotations && ir) {
131
+ stripSourceAnnotations(ir);
132
+ }
133
+ return {
134
+ code: result.code,
135
+ map: wantMaps ? result.map : void 0
136
+ };
137
+ } catch (error) {
138
+ const msg = error instanceof Error ? error.message : String(error);
139
+ if (mode === "strict") {
140
+ this.error(`Failed to compile ${basename(id)}: ${msg}`);
141
+ } else {
142
+ console.error(`[mindmatrix-react] Error compiling ${basename(id)}:`, msg);
143
+ }
144
+ return null;
145
+ }
146
+ },
147
+ handleHotUpdate(ctx) {
148
+ if (!shouldTransform(ctx.file)) return;
149
+ console.log(`[mindmatrix-react] HMR: ${basename(ctx.file)} changed`);
150
+ return void 0;
151
+ }
152
+ };
153
+ }
154
+ function stripSourceAnnotations(ir) {
155
+ const strip = (obj) => {
156
+ if (!obj || typeof obj !== "object") return;
157
+ if (Array.isArray(obj)) {
158
+ for (const item of obj) strip(item);
159
+ return;
160
+ }
161
+ const rec = obj;
162
+ delete rec.__source;
163
+ for (const val of Object.values(rec)) {
164
+ if (val && typeof val === "object") strip(val);
165
+ }
166
+ };
167
+ strip(ir.fields);
168
+ strip(ir.states);
169
+ strip(ir.transitions);
170
+ strip(ir.experience);
171
+ }
172
+
173
+ export {
174
+ mindmatrixReact
175
+ };
@@ -0,0 +1,161 @@
1
+ import {
2
+ __require
3
+ } from "./chunk-CIESM3BP.mjs";
4
+
5
+ // src/cli/auth.ts
6
+ import { readFileSync, writeFileSync, mkdirSync, existsSync, unlinkSync } from "fs";
7
+ import { join } from "path";
8
+ import { homedir } from "os";
9
+ import { createInterface } from "readline";
10
+ var MMRC_DIR = join(homedir(), ".mmrc");
11
+ var CREDENTIALS_PATH = join(MMRC_DIR, "credentials.json");
12
+ function loadCredentials() {
13
+ if (!existsSync(CREDENTIALS_PATH)) return {};
14
+ try {
15
+ return JSON.parse(readFileSync(CREDENTIALS_PATH, "utf-8"));
16
+ } catch {
17
+ return {};
18
+ }
19
+ }
20
+ function saveCredentials(apiUrl, token) {
21
+ mkdirSync(MMRC_DIR, { recursive: true, mode: 448 });
22
+ const creds = loadCredentials();
23
+ creds[apiUrl] = { token, savedAt: (/* @__PURE__ */ new Date()).toISOString() };
24
+ writeFileSync(CREDENTIALS_PATH, JSON.stringify(creds, null, 2), "utf-8");
25
+ try {
26
+ const { chmodSync } = __require("fs");
27
+ chmodSync(CREDENTIALS_PATH, 384);
28
+ } catch {
29
+ }
30
+ }
31
+ function removeCredentials(apiUrl) {
32
+ if (!existsSync(CREDENTIALS_PATH)) return;
33
+ if (!apiUrl) {
34
+ unlinkSync(CREDENTIALS_PATH);
35
+ return;
36
+ }
37
+ const creds = loadCredentials();
38
+ delete creds[apiUrl];
39
+ if (Object.keys(creds).length === 0) {
40
+ unlinkSync(CREDENTIALS_PATH);
41
+ } else {
42
+ writeFileSync(CREDENTIALS_PATH, JSON.stringify(creds, null, 2), "utf-8");
43
+ }
44
+ }
45
+ function resolveToken(apiUrl, explicitToken) {
46
+ if (explicitToken) return explicitToken;
47
+ const envToken = process.env.MMRC_TOKEN;
48
+ if (envToken) return envToken;
49
+ const creds = loadCredentials();
50
+ const entry = creds[apiUrl];
51
+ if (entry?.token) return entry.token;
52
+ return null;
53
+ }
54
+ function prompt(question, hidden = false) {
55
+ return new Promise((resolve) => {
56
+ const rl = createInterface({
57
+ input: process.stdin,
58
+ output: process.stdout
59
+ });
60
+ if (hidden && process.stdin.isTTY) {
61
+ const origWrite = process.stdout.write.bind(process.stdout);
62
+ process.stdout.write = ((chunk, encodingOrCb, cb) => {
63
+ if (typeof chunk === "string" && chunk.includes(question)) {
64
+ return origWrite(chunk, encodingOrCb, cb);
65
+ }
66
+ if (typeof chunk === "string" && !chunk.includes("\n")) {
67
+ return true;
68
+ }
69
+ return origWrite(chunk, encodingOrCb, cb);
70
+ });
71
+ rl.question(question, (answer) => {
72
+ process.stdout.write = origWrite;
73
+ console.log();
74
+ rl.close();
75
+ resolve(answer.trim());
76
+ });
77
+ } else {
78
+ rl.question(question, (answer) => {
79
+ rl.close();
80
+ resolve(answer.trim());
81
+ });
82
+ }
83
+ });
84
+ }
85
+ async function login(apiUrl, email, password) {
86
+ if (!email) {
87
+ email = await prompt("Email: ");
88
+ }
89
+ if (!password) {
90
+ password = await prompt("Password: ", true);
91
+ }
92
+ if (!email || !password) {
93
+ throw new Error("Email and password are required");
94
+ }
95
+ console.log(`[mmrc] Logging in to ${apiUrl}...`);
96
+ const res = await fetch(`${apiUrl}/auth/login`, {
97
+ method: "POST",
98
+ headers: { "Content-Type": "application/json" },
99
+ body: JSON.stringify({ email, password })
100
+ });
101
+ if (!res.ok) {
102
+ const text = await res.text();
103
+ throw new Error(`Login failed: ${res.status} ${text}`);
104
+ }
105
+ const data = await res.json();
106
+ const token = data.token ?? data.access_token ?? data.accessToken;
107
+ if (!token) {
108
+ throw new Error("Login succeeded but no token in response");
109
+ }
110
+ saveCredentials(apiUrl, token);
111
+ const userName = data.name ?? data.user?.name ?? data.user?.email ?? email;
112
+ console.log(`[mmrc] Logged in as ${userName}`);
113
+ console.log(`[mmrc] Token saved to ${CREDENTIALS_PATH}`);
114
+ return token;
115
+ }
116
+ function logout(apiUrl) {
117
+ if (apiUrl) {
118
+ removeCredentials(apiUrl);
119
+ console.log(`[mmrc] Credentials removed for ${apiUrl}`);
120
+ } else {
121
+ removeCredentials();
122
+ console.log("[mmrc] All saved credentials removed");
123
+ }
124
+ }
125
+ async function whoami(apiUrl) {
126
+ const token = resolveToken(apiUrl);
127
+ if (!token) {
128
+ console.log("[mmrc] Not logged in. Run `mmrc login` to authenticate.");
129
+ return;
130
+ }
131
+ try {
132
+ const res = await fetch(`${apiUrl}/auth/me`, {
133
+ headers: { Authorization: `Bearer ${token}` }
134
+ });
135
+ if (!res.ok) {
136
+ if (res.status === 401) {
137
+ console.log("[mmrc] Token is expired or invalid. Run `mmrc login` to re-authenticate.");
138
+ return;
139
+ }
140
+ console.log(`[mmrc] Failed to fetch user info: ${res.status}`);
141
+ return;
142
+ }
143
+ const user = await res.json();
144
+ console.log(`[mmrc] Logged in to ${apiUrl}`);
145
+ console.log(` Name: ${user.name ?? "(unknown)"}`);
146
+ console.log(` Email: ${user.email ?? "(unknown)"}`);
147
+ if (user.id) console.log(` ID: ${user.id}`);
148
+ if (user.role) console.log(` Role: ${user.role}`);
149
+ } catch (error) {
150
+ console.log(`[mmrc] Could not connect to ${apiUrl}: ${error.message}`);
151
+ }
152
+ }
153
+
154
+ export {
155
+ loadCredentials,
156
+ saveCredentials,
157
+ resolveToken,
158
+ login,
159
+ logout,
160
+ whoami
161
+ };
@@ -0,0 +1,186 @@
1
+ import {
2
+ createSourceEnvelope,
3
+ generateFsTree
4
+ } from "./chunk-5M7DKKBC.mjs";
5
+ import {
6
+ babelPlugin
7
+ } from "./chunk-OPJKP747.mjs";
8
+
9
+ // src/envelope.ts
10
+ import { createHash } from "crypto";
11
+ import { readFileSync } from "fs";
12
+ import { resolve, relative, basename } from "path";
13
+ import { glob } from "glob";
14
+ import { transformSync } from "@babel/core";
15
+ async function buildEnvelope(projectDir, options = {}) {
16
+ const root = resolve(projectDir);
17
+ const slug = options.slug ?? basename(root);
18
+ const version = options.version ?? "0.1.0";
19
+ const mode = options.mode ?? "infer";
20
+ const patterns = options.include ?? [
21
+ `${root}/**/*.workflow.{tsx,ts,jsx,js}`,
22
+ `${root}/**/models/**/*.{ts,tsx}`,
23
+ `${root}/**/*.server.{ts,tsx,js,jsx}`
24
+ ];
25
+ const discoveredFiles = [];
26
+ for (const pattern of patterns) {
27
+ const matches = await glob(pattern, { absolute: true });
28
+ discoveredFiles.push(...matches);
29
+ }
30
+ const uniqueFiles = [...new Set(discoveredFiles)];
31
+ const allSourceFiles = await glob(`${root}/**/*.{ts,tsx,js,jsx,css,json}`, {
32
+ absolute: true,
33
+ ignore: ["**/node_modules/**", "**/dist/**", "**/.git/**"]
34
+ });
35
+ const fsTree = generateFsTree(allSourceFiles, root);
36
+ const definitions = [];
37
+ const envelopeFiles = [];
38
+ const errors = [];
39
+ const sourceBindings = [];
40
+ for (const file of uniqueFiles) {
41
+ const relativePath = relative(root, file);
42
+ let fileContent;
43
+ try {
44
+ fileContent = readFileSync(file);
45
+ } catch {
46
+ errors.push({ file: relativePath, message: "Could not read file" });
47
+ continue;
48
+ }
49
+ const fileHash = createHash("sha256").update(fileContent).digest("hex");
50
+ const code = fileContent.toString("utf-8");
51
+ try {
52
+ const hasTsx = /\.(tsx|jsx)$/.test(file);
53
+ const parserPlugins = ["typescript"];
54
+ if (hasTsx) parserPlugins.push("jsx");
55
+ const result = transformSync(code, {
56
+ filename: file,
57
+ plugins: [[babelPlugin, { mode }]],
58
+ parserOpts: { plugins: parserPlugins, attachComment: true },
59
+ sourceMaps: true
60
+ });
61
+ const ir = result?.metadata?.mindmatrixIR;
62
+ if (ir) {
63
+ definitions.push(ir);
64
+ const bindings = extractSourceBindings(ir, relativePath);
65
+ sourceBindings.push(...bindings);
66
+ const irErrors = ir.metadata?.errors;
67
+ if (irErrors?.length) {
68
+ for (const e of irErrors) {
69
+ errors.push({ file: relativePath, message: e.message, line: e.line });
70
+ }
71
+ }
72
+ envelopeFiles.push({
73
+ path: relativePath,
74
+ hash: fileHash,
75
+ size: fileContent.length,
76
+ slug: ir.slug,
77
+ compiled: true
78
+ });
79
+ } else {
80
+ envelopeFiles.push({
81
+ path: relativePath,
82
+ hash: fileHash,
83
+ size: fileContent.length,
84
+ compiled: false
85
+ });
86
+ }
87
+ } catch (error) {
88
+ const msg = error instanceof Error ? error.message : String(error);
89
+ errors.push({ file: relativePath, message: msg });
90
+ envelopeFiles.push({
91
+ path: relativePath,
92
+ hash: fileHash,
93
+ size: fileContent.length,
94
+ compiled: false
95
+ });
96
+ }
97
+ }
98
+ const envelope = createSourceEnvelope({
99
+ blueprintSlug: slug,
100
+ blueprintVersion: version,
101
+ definitions,
102
+ fsTree,
103
+ sourceBindings,
104
+ environment: options.environment,
105
+ mode
106
+ });
107
+ const envelopeJson = JSON.stringify(envelope);
108
+ const manifestHash = createHash("sha256").update(envelopeJson).digest("hex");
109
+ const manifest = {
110
+ hash: manifestHash,
111
+ files: envelopeFiles,
112
+ version,
113
+ timestamp: envelope.createdAt,
114
+ definitionCount: definitions.length,
115
+ errorCount: errors.length
116
+ };
117
+ return {
118
+ envelope,
119
+ manifest,
120
+ files: envelopeFiles,
121
+ definitions,
122
+ errors
123
+ };
124
+ }
125
+ function extractSourceBindings(ir, filePath) {
126
+ const bindings = [];
127
+ const slug = ir.slug ?? "";
128
+ for (const field of ir.fields) {
129
+ const source = field.__source;
130
+ bindings.push({
131
+ kind: "field",
132
+ name: field.name,
133
+ workflowSlug: slug,
134
+ file: filePath,
135
+ startLine: source?.line ?? 0,
136
+ startColumn: source?.column ?? 0,
137
+ endLine: source?.endLine,
138
+ endColumn: source?.endColumn
139
+ });
140
+ }
141
+ for (const state of ir.states) {
142
+ const source = state.__source;
143
+ bindings.push({
144
+ kind: "state",
145
+ name: state.name,
146
+ workflowSlug: slug,
147
+ file: filePath,
148
+ startLine: source?.line ?? 0,
149
+ startColumn: source?.column ?? 0,
150
+ endLine: source?.endLine,
151
+ endColumn: source?.endColumn
152
+ });
153
+ }
154
+ for (const transition of ir.transitions) {
155
+ const source = transition.__source;
156
+ bindings.push({
157
+ kind: "transition",
158
+ name: transition.name,
159
+ workflowSlug: slug,
160
+ file: filePath,
161
+ startLine: source?.line ?? 0,
162
+ startColumn: source?.column ?? 0,
163
+ endLine: source?.endLine,
164
+ endColumn: source?.endColumn
165
+ });
166
+ }
167
+ if (ir.extensions) {
168
+ for (const [tag, islands] of Object.entries(ir.extensions)) {
169
+ for (const island of islands) {
170
+ bindings.push({
171
+ kind: "grammar-island",
172
+ name: `${tag}:${island.contextTag}`,
173
+ workflowSlug: slug,
174
+ file: filePath,
175
+ startLine: island.__source?.line ?? 0,
176
+ startColumn: island.__source?.column ?? 0
177
+ });
178
+ }
179
+ }
180
+ }
181
+ return bindings;
182
+ }
183
+
184
+ export {
185
+ buildEnvelope
186
+ };