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

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.
package/dist/index.mjs CHANGED
@@ -13,25 +13,25 @@ import {
13
13
  resolveActionReferences,
14
14
  resolveImport,
15
15
  topologicalSort
16
- } from "./chunk-EJRBDQDP.mjs";
16
+ } from "./chunk-NTB7OEX2.mjs";
17
17
  import {
18
18
  decompile,
19
19
  decompileProject,
20
20
  shouldDecompileAsProject
21
- } from "./chunk-FKRO52XH.mjs";
21
+ } from "./chunk-WBYMW4NQ.mjs";
22
22
  import {
23
23
  createDevServer
24
- } from "./chunk-GCLGPOJZ.mjs";
25
- import "./chunk-72QWL54I.mjs";
24
+ } from "./chunk-5GUFFFGL.mjs";
25
+ import "./chunk-EO6SYNCG.mjs";
26
26
  import {
27
27
  buildEnvelope
28
- } from "./chunk-JLA5VNQ3.mjs";
28
+ } from "./chunk-J7JUAHS4.mjs";
29
29
  import {
30
30
  deploy
31
- } from "./chunk-EQGA6A6D.mjs";
31
+ } from "./chunk-52XHYD2V.mjs";
32
32
  import {
33
33
  build
34
- } from "./chunk-5RKTOVR5.mjs";
34
+ } from "./chunk-THFYE5ZX.mjs";
35
35
  import {
36
36
  computeEnvelopeId,
37
37
  createSourceEnvelope,
@@ -57,7 +57,7 @@ import {
57
57
  extractStates,
58
58
  extractTransitions,
59
59
  transformToFrontend
60
- } from "./chunk-FYT47UBU.mjs";
60
+ } from "./chunk-OPJKP747.mjs";
61
61
  import "./chunk-CIESM3BP.mjs";
62
62
 
63
63
  // src/babel/emitters/ir-to-tsx-emitter.ts
@@ -320,7 +320,214 @@ function validateSourceRoundTrip(source, filename = "test.workflow.tsx") {
320
320
  if (!ir) return null;
321
321
  return validateRoundTrip(ir);
322
322
  }
323
+
324
+ // src/diagnostics.ts
325
+ var DIAGNOSTIC_CODES = {
326
+ // -- Flow extractor (imperative workflows) --
327
+ FLOW001: "No default export async function found",
328
+ FLOW002: "Workflow function has no typed parameter",
329
+ FLOW003: "Interface not found for parameter type",
330
+ FLOW004: "Unknown function call in workflow body",
331
+ FLOW005: "userAction() without a following state (cannot resolve transition target)",
332
+ FLOW006: "Import could not be resolved as a service",
333
+ FLOW007: "validate() with unparseable condition",
334
+ // -- Middleware extractor --
335
+ MDLW001: "defineMiddleware() missing required 'name' field",
336
+ MDLW002: "Invalid match pattern format",
337
+ MDLW003: "No before/after/around handler defined",
338
+ // -- Constraint extractor --
339
+ CNST001: "Unknown built-in constraint name",
340
+ CNST002: "Empty constraint list",
341
+ // -- Actor extractor --
342
+ ACTR001: "Invalid supervision strategy",
343
+ ACTR002: "spawnActor() called outside workflow function",
344
+ // -- Hook-based visitor --
345
+ HOOK001: "Forbidden hook in strict mode",
346
+ HOOK002: "Raw useEffect in infer mode (component becomes opaque)",
347
+ HOOK003: "Forbidden import in strict mode",
348
+ // -- Model extractor --
349
+ MODL001: "defineModel() missing required fields",
350
+ MODL002: "Unknown field type in model definition",
351
+ // -- Emitter --
352
+ EMIT001: "Empty workflow \u2014 no states, fields, or experience extracted"
353
+ };
354
+ var DiagnosticCollector = class {
355
+ constructor() {
356
+ this.diagnostics = [];
357
+ }
358
+ /**
359
+ * Record an error diagnostic.
360
+ */
361
+ error(code, message, location, suggestion) {
362
+ this.diagnostics.push({
363
+ severity: "error",
364
+ code,
365
+ message,
366
+ file: location?.file,
367
+ line: location?.line,
368
+ column: location?.column,
369
+ suggestion
370
+ });
371
+ }
372
+ /**
373
+ * Record a warning diagnostic.
374
+ */
375
+ warning(code, message, location, suggestion) {
376
+ this.diagnostics.push({
377
+ severity: "warning",
378
+ code,
379
+ message,
380
+ file: location?.file,
381
+ line: location?.line,
382
+ column: location?.column,
383
+ suggestion
384
+ });
385
+ }
386
+ /**
387
+ * Record an informational diagnostic.
388
+ */
389
+ info(code, message) {
390
+ this.diagnostics.push({
391
+ severity: "info",
392
+ code,
393
+ message
394
+ });
395
+ }
396
+ /**
397
+ * Record a hint diagnostic (always includes a suggestion).
398
+ */
399
+ hint(code, message, suggestion) {
400
+ this.diagnostics.push({
401
+ severity: "hint",
402
+ code,
403
+ message,
404
+ suggestion
405
+ });
406
+ }
407
+ /**
408
+ * Whether any error-level diagnostics have been recorded.
409
+ */
410
+ hasErrors() {
411
+ return this.diagnostics.some((d) => d.severity === "error");
412
+ }
413
+ /**
414
+ * Whether any warning-level diagnostics have been recorded.
415
+ */
416
+ hasWarnings() {
417
+ return this.diagnostics.some((d) => d.severity === "warning");
418
+ }
419
+ /**
420
+ * Total number of diagnostics collected.
421
+ */
422
+ get count() {
423
+ return this.diagnostics.length;
424
+ }
425
+ /**
426
+ * Return all collected diagnostics.
427
+ */
428
+ getAll() {
429
+ return [...this.diagnostics];
430
+ }
431
+ /**
432
+ * Return only error-severity diagnostics.
433
+ */
434
+ getErrors() {
435
+ return this.diagnostics.filter((d) => d.severity === "error");
436
+ }
437
+ /**
438
+ * Return only warning-severity diagnostics.
439
+ */
440
+ getWarnings() {
441
+ return this.diagnostics.filter((d) => d.severity === "warning");
442
+ }
443
+ /**
444
+ * Return only info-severity diagnostics.
445
+ */
446
+ getInfos() {
447
+ return this.diagnostics.filter((d) => d.severity === "info");
448
+ }
449
+ /**
450
+ * Return only hint-severity diagnostics.
451
+ */
452
+ getHints() {
453
+ return this.diagnostics.filter((d) => d.severity === "hint");
454
+ }
455
+ /**
456
+ * Merge diagnostics from another collector into this one.
457
+ */
458
+ merge(other) {
459
+ this.diagnostics.push(...other.getAll());
460
+ }
461
+ /**
462
+ * Clear all collected diagnostics.
463
+ */
464
+ clear() {
465
+ this.diagnostics = [];
466
+ }
467
+ /**
468
+ * Pretty-print all diagnostics for terminal output.
469
+ *
470
+ * Format:
471
+ * error[FLOW001]: No default export async function found
472
+ * --> models/task.ts
473
+ * = hint: Add `export default async function taskWorkflow(task: Task) { ... }`
474
+ *
475
+ * warning[FLOW004]: Unknown function 'processData' in workflow body
476
+ * --> models/order.ts:15:5
477
+ * = note: Not a local async function, not imported, and not a stdlib function
478
+ * = hint: Did you mean to import it?
479
+ */
480
+ format() {
481
+ if (this.diagnostics.length === 0) return "";
482
+ const lines = [];
483
+ for (const d of this.diagnostics) {
484
+ lines.push(`${d.severity}[${d.code}]: ${d.message}`);
485
+ if (d.file || d.line != null) {
486
+ let loc = " --> ";
487
+ if (d.file) loc += d.file;
488
+ if (d.line != null) {
489
+ loc += (d.file ? ":" : "") + d.line;
490
+ if (d.column != null) loc += ":" + d.column;
491
+ }
492
+ lines.push(loc);
493
+ }
494
+ if (d.suggestion) {
495
+ lines.push(` = hint: ${d.suggestion}`);
496
+ }
497
+ lines.push("");
498
+ }
499
+ const errorCount = this.getErrors().length;
500
+ const warningCount = this.getWarnings().length;
501
+ const parts = [];
502
+ if (errorCount > 0) parts.push(`${errorCount} error${errorCount !== 1 ? "s" : ""}`);
503
+ if (warningCount > 0) parts.push(`${warningCount} warning${warningCount !== 1 ? "s" : ""}`);
504
+ if (parts.length > 0) {
505
+ lines.push(parts.join(", ") + " emitted");
506
+ }
507
+ return lines.join("\n");
508
+ }
509
+ /**
510
+ * Machine-readable JSON representation.
511
+ */
512
+ toJSON() {
513
+ return {
514
+ diagnostics: this.getAll(),
515
+ summary: {
516
+ errors: this.getErrors().length,
517
+ warnings: this.getWarnings().length,
518
+ infos: this.getInfos().length,
519
+ hints: this.getHints().length,
520
+ total: this.diagnostics.length
521
+ }
522
+ };
523
+ }
524
+ };
525
+ function createDiagnosticCollector() {
526
+ return new DiagnosticCollector();
527
+ }
323
528
  export {
529
+ DIAGNOSTIC_CODES,
530
+ DiagnosticCollector,
324
531
  IncrementalCache,
325
532
  IncrementalProjectCompiler,
326
533
  babelPlugin,
@@ -336,6 +543,7 @@ export {
336
543
  computeEnvelopeId,
337
544
  computeTransitiveDirtySet,
338
545
  createDevServer,
546
+ createDiagnosticCollector,
339
547
  createSourceEnvelope,
340
548
  createVisitor,
341
549
  decompile,
@@ -0,0 +1,369 @@
1
+ import "./chunk-CIESM3BP.mjs";
2
+
3
+ // src/cli/init.ts
4
+ import { mkdirSync, writeFileSync, existsSync } from "fs";
5
+ import { join } from "path";
6
+ function toTitleCase(slug) {
7
+ return slug.split("-").map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join(" ");
8
+ }
9
+ function toPascalCase(slug) {
10
+ return slug.split("-").map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join("");
11
+ }
12
+ function generatePackageJson(name) {
13
+ return JSON.stringify(
14
+ {
15
+ name: `@mindmatrix/blueprint-${name}`,
16
+ version: "0.1.0",
17
+ private: true,
18
+ type: "module",
19
+ scripts: {
20
+ build: "mmrc build --src . --out dist",
21
+ dev: "mmrc dev --src . --port 5199",
22
+ deploy: "mmrc deploy --build --src ."
23
+ },
24
+ dependencies: {
25
+ "@mmapp/react": "^0.1.0-alpha.1"
26
+ },
27
+ devDependencies: {
28
+ typescript: "^5.5.0",
29
+ "@types/react": "^18.0.0",
30
+ react: "^18.0.0"
31
+ }
32
+ },
33
+ null,
34
+ 2
35
+ );
36
+ }
37
+ function generateMmConfig(name, opts) {
38
+ const title = toTitleCase(name);
39
+ const desc = opts.description ?? `${title} blueprint.`;
40
+ const icon = opts.icon ?? "box";
41
+ const author = opts.author ?? "MindMatrix";
42
+ return `import { defineBlueprint } from '@mmapp/react';
43
+
44
+ export default defineBlueprint({
45
+ slug: '${name}',
46
+ name: '${title}',
47
+ version: '1.0.0',
48
+ description: '${desc}',
49
+ author: '${author}',
50
+ icon: '${icon}',
51
+ mode: 'infer',
52
+ defaultRuntime: 'collaborative',
53
+
54
+ models: [
55
+ 'models/item',
56
+ ],
57
+
58
+ routes: [
59
+ { path: '/', view: 'app/page', label: 'Home' },
60
+ ],
61
+
62
+ dependencies: [],
63
+ });
64
+ `;
65
+ }
66
+ function generateModel(name) {
67
+ const modelSlug = `${name}-item`;
68
+ const pascal = toPascalCase(name);
69
+ return `/**
70
+ * ${pascal} Item \u2014 data model with lifecycle states.
71
+ *
72
+ * States: draft \u2192 active \u2192 archived
73
+ */
74
+
75
+ import { defineModel } from '@mmapp/react';
76
+
77
+ export interface ${pascal}ItemFields {
78
+ title: string;
79
+ description: string;
80
+ priority: 'low' | 'medium' | 'high';
81
+ createdAt: number;
82
+ }
83
+
84
+ export default defineModel({
85
+ slug: '${modelSlug}',
86
+ version: '1.0.0',
87
+ category: ['model', '${name}'],
88
+
89
+ fields: {
90
+ title: { type: 'string', required: true },
91
+ description: { type: 'string', default: '' },
92
+ priority: { type: 'string', default: 'medium', enum: ['low', 'medium', 'high'] },
93
+ createdAt: { type: 'number', default: 0 },
94
+ },
95
+
96
+ states: {
97
+ draft: {
98
+ type: 'initial',
99
+ onEnter: [
100
+ { id: 'set-created', type: 'set_field', mode: 'auto', config: { field: 'createdAt', expression: 'NOW()' } },
101
+ ],
102
+ },
103
+ active: {
104
+ onEnter: [
105
+ { id: 'log-activated', type: 'log_event', mode: 'auto', config: { event: '${modelSlug}.activated' } },
106
+ ],
107
+ },
108
+ archived: {
109
+ type: 'end',
110
+ },
111
+ },
112
+
113
+ transitions: {
114
+ activate: {
115
+ from: 'draft',
116
+ to: 'active',
117
+ description: 'Publish this item',
118
+ },
119
+ archive: {
120
+ from: 'active',
121
+ to: 'archived',
122
+ description: 'Archive this item',
123
+ },
124
+ },
125
+ });
126
+ `;
127
+ }
128
+ function generateTsconfig() {
129
+ return JSON.stringify(
130
+ {
131
+ compilerOptions: {
132
+ target: "ES2020",
133
+ module: "ESNext",
134
+ moduleResolution: "bundler",
135
+ jsx: "react-jsx",
136
+ strict: true,
137
+ esModuleInterop: true,
138
+ skipLibCheck: true,
139
+ forceConsistentCasingInFileNames: true,
140
+ declaration: false,
141
+ noEmit: true
142
+ },
143
+ include: ["**/*.ts", "**/*.tsx"],
144
+ exclude: ["node_modules", "dist"]
145
+ },
146
+ null,
147
+ 2
148
+ );
149
+ }
150
+ function generateLayout(name) {
151
+ const title = toTitleCase(name);
152
+ return `/**
153
+ * @workflow slug="${name}-layout" version="1.0.0" category="view"
154
+ *
155
+ * Root layout with sidebar navigation.
156
+ */
157
+
158
+ import {
159
+ Row,
160
+ Stack,
161
+ Slot,
162
+ Text,
163
+ Icon,
164
+ Button,
165
+ Divider,
166
+ } from '@mmapp/react/atoms';
167
+ import { useRouter } from '@mmapp/react';
168
+
169
+ export default function Layout({ children }: { children: React.ReactNode }) {
170
+ const router = useRouter();
171
+
172
+ return (
173
+ <Row gap={0} height="100vh" overflow="hidden">
174
+ {/* Sidebar */}
175
+ <Stack
176
+ width={240}
177
+ borderRight="1px solid token:border"
178
+ height="100vh"
179
+ background="token:surface"
180
+ >
181
+ <Row padding={12} gap={8} align="center" borderBottom="1px solid token:border">
182
+ <Icon name="box" size={20} color="token:primary" />
183
+ <Text variant="label" size="sm" value="${title}" />
184
+ </Row>
185
+
186
+ <Stack padding={8} gap={4}>
187
+ <Button variant="ghost" onPress={() => router.push('/')}>
188
+ <Row gap={8} align="center">
189
+ <Icon name="home" size={16} />
190
+ <Text size="sm" value="Home" />
191
+ </Row>
192
+ </Button>
193
+ <Button variant="ghost" onPress={() => router.push('/settings')}>
194
+ <Row gap={8} align="center">
195
+ <Icon name="settings" size={16} />
196
+ <Text size="sm" value="Settings" />
197
+ </Row>
198
+ </Button>
199
+ </Stack>
200
+
201
+ <Divider />
202
+ <Stack flex={1} />
203
+ <Row padding={12}>
204
+ <Text variant="muted" size="xs" value="v1.0.0" />
205
+ </Row>
206
+ </Stack>
207
+
208
+ {/* Main content */}
209
+ <Stack flex={1} overflow="auto">
210
+ {children}
211
+ </Stack>
212
+ </Row>
213
+ );
214
+ }
215
+ `;
216
+ }
217
+ function generatePage(name) {
218
+ const title = toTitleCase(name);
219
+ const pascal = toPascalCase(name);
220
+ return `/**
221
+ * @workflow slug="${name}-home" version="1.0.0" category="page"
222
+ *
223
+ * Index page \u2014 lists items with create and search.
224
+ */
225
+
226
+ import { useState } from 'react';
227
+ import itemModel from '../models/item';
228
+ import {
229
+ useQuery, useMutation, useRouter,
230
+ Stack, Row, Text, Button, Icon, Card, Show, TextInput, Badge,
231
+ } from '@mmapp/react';
232
+
233
+ const PRIORITY_COLORS: Record<string, string> = {
234
+ high: 'token:error',
235
+ medium: 'token:warning',
236
+ low: 'token:success',
237
+ };
238
+
239
+ export default function ${pascal}Home() {
240
+ const { data: items, loading } = useQuery(itemModel);
241
+ const mutation = useMutation(itemModel);
242
+ const router = useRouter();
243
+ const [search, setSearch] = useState('');
244
+
245
+ const activeItems = items.filter(i => i.state !== 'archived');
246
+ const filtered = activeItems.filter(i =>
247
+ i.fields.title.toLowerCase().includes(search.toLowerCase())
248
+ );
249
+
250
+ const handleCreate = async () => {
251
+ await mutation.create({ title: 'New Item', priority: 'medium' });
252
+ };
253
+
254
+ return (
255
+ <Stack gap={24} padding={24}>
256
+ {/* Header */}
257
+ <Row justify="space-between" align="center">
258
+ <Stack gap={4}>
259
+ <Text variant="h3" weight="bold" value="${title}" />
260
+ <Text variant="muted" size="sm" value={\`\${activeItems.length} items\`} />
261
+ </Stack>
262
+ <Button variant="primary" onPress={handleCreate}>
263
+ <Row gap={6} align="center">
264
+ <Icon name="plus" size={16} />
265
+ <Text value="Add Item" />
266
+ </Row>
267
+ </Button>
268
+ </Row>
269
+
270
+ {/* Search */}
271
+ <TextInput
272
+ value={search}
273
+ onChange={setSearch}
274
+ placeholder="Search items..."
275
+ />
276
+
277
+ {/* Loading */}
278
+ <Show when={loading}>
279
+ <Card padding={32}>
280
+ <Stack align="center">
281
+ <Text variant="muted" value="Loading..." />
282
+ </Stack>
283
+ </Card>
284
+ </Show>
285
+
286
+ {/* Empty state */}
287
+ <Show when={!loading && filtered.length === 0}>
288
+ <Card padding={32}>
289
+ <Stack align="center" gap={12}>
290
+ <Icon name="inbox" size={40} color="token:muted" />
291
+ <Text variant="muted" value="No items yet" />
292
+ <Button variant="outline" onPress={handleCreate}>
293
+ <Text value="Create your first item" />
294
+ </Button>
295
+ </Stack>
296
+ </Card>
297
+ </Show>
298
+
299
+ {/* Item list */}
300
+ <Show when={!loading && filtered.length > 0}>
301
+ <Stack gap={4}>
302
+ {filtered.map((item: any) => (
303
+ <Card key={item.id} padding={12}>
304
+ <Row align="center" gap={12}>
305
+ <Stack flex={1} gap={2}>
306
+ <Text weight="medium" value={item.fields.title} />
307
+ <Show when={!!item.fields.description}>
308
+ <Text size="sm" variant="muted" value={item.fields.description} />
309
+ </Show>
310
+ </Stack>
311
+ <Badge value={item.fields.priority} />
312
+ <Badge value={item.state} variant={item.state === 'active' ? 'success' : 'default'} />
313
+ </Row>
314
+ </Card>
315
+ ))}
316
+ </Stack>
317
+ </Show>
318
+ </Stack>
319
+ );
320
+ }
321
+ `;
322
+ }
323
+ async function init(options) {
324
+ const { name } = options;
325
+ if (!/^[a-z][a-z0-9-]*$/.test(name)) {
326
+ console.error(`[mmrc] Error: Blueprint name must be lowercase alphanumeric with hyphens (got "${name}")`);
327
+ process.exit(1);
328
+ }
329
+ const cwd = process.cwd();
330
+ const packagesDir = existsSync(join(cwd, "packages")) ? join(cwd, "packages") : cwd;
331
+ const blueprintDir = join(packagesDir, `blueprint-${name}`);
332
+ if (existsSync(blueprintDir)) {
333
+ console.error(`[mmrc] Error: Directory already exists: ${blueprintDir}`);
334
+ process.exit(1);
335
+ }
336
+ console.log(`[mmrc] Creating blueprint: ${name}
337
+ `);
338
+ mkdirSync(join(blueprintDir, "models"), { recursive: true });
339
+ mkdirSync(join(blueprintDir, "app"), { recursive: true });
340
+ const { generateMmrcConfig } = await import("./config-PL24KEWL.mjs");
341
+ const files = [
342
+ ["package.json", generatePackageJson(name)],
343
+ ["tsconfig.json", generateTsconfig()],
344
+ ["mm.config.ts", generateMmConfig(name, options)],
345
+ ["mmrc.config.ts", generateMmrcConfig()],
346
+ ["models/item.ts", generateModel(name)],
347
+ ["app/layout.tsx", generateLayout(name)],
348
+ ["app/page.tsx", generatePage(name)]
349
+ ];
350
+ for (const [relPath, content] of files) {
351
+ const fullPath = join(blueprintDir, relPath);
352
+ writeFileSync(fullPath, content, "utf-8");
353
+ console.log(` + ${relPath}`);
354
+ }
355
+ const title = toTitleCase(name);
356
+ console.log(`
357
+ [mmrc] Blueprint "${title}" created at:
358
+ ${blueprintDir}
359
+
360
+ Next steps:
361
+ 1. cd ${blueprintDir.startsWith(cwd) ? blueprintDir.slice(cwd.length + 1) : blueprintDir}
362
+ 2. mmrc dev # Start dev server
363
+ 3. mmrc build # Compile to IR
364
+ 4. mmrc deploy --build # Build + deploy to backend
365
+ `);
366
+ }
367
+ export {
368
+ init
369
+ };
@@ -0,0 +1,10 @@
1
+ import {
2
+ IncrementalProjectCompiler,
3
+ compileProject
4
+ } from "./chunk-NTB7OEX2.mjs";
5
+ import "./chunk-OPJKP747.mjs";
6
+ import "./chunk-CIESM3BP.mjs";
7
+ export {
8
+ IncrementalProjectCompiler,
9
+ compileProject
10
+ };
@@ -0,0 +1,7 @@
1
+ import {
2
+ decompileProjectEnhanced
3
+ } from "./chunk-WBYMW4NQ.mjs";
4
+ import "./chunk-CIESM3BP.mjs";
5
+ export {
6
+ decompileProjectEnhanced
7
+ };