farmon 0.1.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 (106) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +163 -0
  3. package/dist/bin/farmon.js +12 -0
  4. package/dist/bin/farmon.js.map +1 -0
  5. package/dist/execute/agents/index.js +19 -0
  6. package/dist/execute/agents/index.js.map +1 -0
  7. package/dist/execute/agents/instruction-classifier-agent.js +16 -0
  8. package/dist/execute/agents/instruction-classifier-agent.js.map +1 -0
  9. package/dist/execute/agents/mutation-agent.js +272 -0
  10. package/dist/execute/agents/mutation-agent.js.map +1 -0
  11. package/dist/execute/agents/query-agent.js +118 -0
  12. package/dist/execute/agents/query-agent.js.map +1 -0
  13. package/dist/execute/helpers/analyzers.js +8 -0
  14. package/dist/execute/helpers/analyzers.js.map +1 -0
  15. package/dist/execute/helpers/ensurers.js +1053 -0
  16. package/dist/execute/helpers/ensurers.js.map +1 -0
  17. package/dist/execute/helpers/finders.js +1454 -0
  18. package/dist/execute/helpers/finders.js.map +1 -0
  19. package/dist/execute/helpers/general.js +3736 -0
  20. package/dist/execute/helpers/general.js.map +1 -0
  21. package/dist/execute/helpers/import-helpers.js +183 -0
  22. package/dist/execute/helpers/import-helpers.js.map +1 -0
  23. package/dist/execute/helpers/parsers.js +840 -0
  24. package/dist/execute/helpers/parsers.js.map +1 -0
  25. package/dist/execute/helpers/prompt-maker.js +1163 -0
  26. package/dist/execute/helpers/prompt-maker.js.map +1 -0
  27. package/dist/execute/helpers/validators.js +40 -0
  28. package/dist/execute/helpers/validators.js.map +1 -0
  29. package/dist/execute/history/history-manager.js +1030 -0
  30. package/dist/execute/history/history-manager.js.map +1 -0
  31. package/dist/execute/history/rollback-handlers.js +2524 -0
  32. package/dist/execute/history/rollback-handlers.js.map +1 -0
  33. package/dist/execute/index.js +44 -0
  34. package/dist/execute/index.js.map +1 -0
  35. package/dist/execute/llm/call.js +103 -0
  36. package/dist/execute/llm/call.js.map +1 -0
  37. package/dist/execute/tasks/ast.js +3819 -0
  38. package/dist/execute/tasks/ast.js.map +1 -0
  39. package/dist/execute/tasks/generators.js +96 -0
  40. package/dist/execute/tasks/generators.js.map +1 -0
  41. package/dist/execute/tasks/index.js +7 -0
  42. package/dist/execute/tasks/index.js.map +1 -0
  43. package/dist/execute/tasks/mutations.js +8139 -0
  44. package/dist/execute/tasks/mutations.js.map +1 -0
  45. package/dist/execute/tasks/query.js +248 -0
  46. package/dist/execute/tasks/query.js.map +1 -0
  47. package/dist/index.js +6 -0
  48. package/dist/index.js.map +1 -0
  49. package/dist/providers/index.js +15 -0
  50. package/dist/providers/index.js.map +1 -0
  51. package/dist/providers/ollama.js +40 -0
  52. package/dist/providers/ollama.js.map +1 -0
  53. package/dist/providers/openai-compatible.js +52 -0
  54. package/dist/providers/openai-compatible.js.map +1 -0
  55. package/dist/runtime/inject.js +250 -0
  56. package/dist/runtime/inject.js.map +1 -0
  57. package/dist/schemas/agent/action.schema.js +935 -0
  58. package/dist/schemas/agent/action.schema.js.map +1 -0
  59. package/dist/schemas/agent/index.js +4 -0
  60. package/dist/schemas/agent/index.js.map +1 -0
  61. package/dist/schemas/agent/llm.schema.js +16 -0
  62. package/dist/schemas/agent/llm.schema.js.map +1 -0
  63. package/dist/schemas/agent/planner.schema.js +17 -0
  64. package/dist/schemas/agent/planner.schema.js.map +1 -0
  65. package/dist/schemas/index.js +7 -0
  66. package/dist/schemas/index.js.map +1 -0
  67. package/dist/schemas/project/context.schema.js +2 -0
  68. package/dist/schemas/project/context.schema.js.map +1 -0
  69. package/dist/schemas/project/index.js +2 -0
  70. package/dist/schemas/project/index.js.map +1 -0
  71. package/dist/schemas/runtime/index.js +4 -0
  72. package/dist/schemas/runtime/index.js.map +1 -0
  73. package/dist/schemas/runtime/injector.schema.js +11 -0
  74. package/dist/schemas/runtime/injector.schema.js.map +1 -0
  75. package/dist/schemas/runtime/runtime.schema.js +73 -0
  76. package/dist/schemas/runtime/runtime.schema.js.map +1 -0
  77. package/dist/schemas/runtime/sse.schema.js +15 -0
  78. package/dist/schemas/runtime/sse.schema.js.map +1 -0
  79. package/dist/schemas/system/index.js +2 -0
  80. package/dist/schemas/system/index.js.map +1 -0
  81. package/dist/schemas/system/logger.schema.js +56 -0
  82. package/dist/schemas/system/logger.schema.js.map +1 -0
  83. package/dist/schemas/task/index.js +9 -0
  84. package/dist/schemas/task/index.js.map +1 -0
  85. package/dist/server/app-context.js +254 -0
  86. package/dist/server/app-context.js.map +1 -0
  87. package/dist/server/config.js +22 -0
  88. package/dist/server/config.js.map +1 -0
  89. package/dist/server/error.js +22 -0
  90. package/dist/server/error.js.map +1 -0
  91. package/dist/server/event-bus.js +60 -0
  92. package/dist/server/event-bus.js.map +1 -0
  93. package/dist/server/logger.js +57 -0
  94. package/dist/server/logger.js.map +1 -0
  95. package/dist/server/run.js +265 -0
  96. package/dist/server/run.js.map +1 -0
  97. package/dist/server/sse.js +143 -0
  98. package/dist/server/sse.js.map +1 -0
  99. package/dist/ui/assets/index-C4ydQSAw.css +2 -0
  100. package/dist/ui/assets/index-Dzo7S5xs.js +85 -0
  101. package/dist/ui/favicon.svg +1 -0
  102. package/dist/ui/icons.svg +24 -0
  103. package/dist/ui/index.html +14 -0
  104. package/dist/workers/prettier.js +11 -0
  105. package/dist/workers/prettier.js.map +1 -0
  106. package/package.json +114 -0
@@ -0,0 +1,1163 @@
1
+ import utils from "../../execute/helpers/general.js";
2
+ const plannerIdentity = `
3
+ You are Looma Planner.
4
+
5
+ Your job is to convert a user's UI editing request
6
+ into a deterministic action plan.
7
+
8
+ You DO NOT generate code.
9
+
10
+ You ONLY generate structured tasks.
11
+
12
+ You MUST ONLY use the provided task list.
13
+ Never invent task names.
14
+
15
+ You MUST scope all mutations to the selected component
16
+ unless explicitly required otherwise.
17
+ `;
18
+ const architecturalRules = `
19
+ - One component per file
20
+ - Component file name matches component name
21
+ - Function declarations only
22
+ - Single root DOM node per component
23
+ - CSS lives in component CSS file
24
+ - Prefer deterministic AST-safe mutations
25
+ - Never rewrite entire file unless unavoidable
26
+ - Never delete unrelated code
27
+ - Never create duplicate imports
28
+ - Never create duplicate variables/functions/components
29
+ `;
30
+ const planningRules = `
31
+ - Reuse existing project libraries whenever possible.
32
+ - Prefer modifying existing components over creating new ones.
33
+ - Prefer component-level changes over low-level code mutations.
34
+ - Avoid unnecessary file operations.
35
+ - Avoid installing new libraries unless absolutely required.
36
+ - Maintain existing project architecture and styling patterns.
37
+ - Keep task chains minimal and deterministic.
38
+ - Prefer stable UI patterns already present in the project.`;
39
+ const taskRules = `
40
+ - Use only the provided tasks.
41
+ - Return only task calls.
42
+ - Use the minimum number of tasks required.
43
+ - Prefer Code Transformation Tasks over Mutation Tasks when modifying existing code.
44
+ - Use Mutation Tasks only when files, directories, or project structure must change.
45
+ - Use Generator Tasks when new code must be created.
46
+ - Task outputs may be used as inputs to later tasks.
47
+ - Tasks must be ordered sequentially.
48
+ - Prefer the smallest possible change to achieve the goal.
49
+ `;
50
+ const taskReferencingRules = `
51
+ Tasks may reference values returned by previous tasks or values available in the componentContext.
52
+
53
+ Use this format:
54
+
55
+ {
56
+ "$ref": {
57
+ "source": "<taskId | componentContext>",
58
+ "path": "<fieldPath>"
59
+ }
60
+ }
61
+
62
+ Example:
63
+
64
+ {
65
+ "taskId": "task_1",
66
+ "task": "createComponent",
67
+ "payload": {
68
+ "componentName": "Header"
69
+ }
70
+ }
71
+
72
+ Suppose task_1 returns:
73
+
74
+ {
75
+ "componentPath": "src/components/Header/Header.jsx",
76
+ "componentCode": "..."
77
+ }
78
+
79
+ Another task may reference its outputs:
80
+
81
+ {
82
+ "taskId": "task_2",
83
+ "task": "insertJSX",
84
+ "payload": {
85
+ "componentPath": {
86
+ "$ref": {
87
+ "source": "task_1",
88
+ "path": "componentPath"
89
+ }
90
+ },
91
+ "targetElement": "App",
92
+ "position": "inside",
93
+ "jsx": "<Header />"
94
+ }
95
+ }
96
+
97
+ Values from componentContext may also be referenced:
98
+
99
+ {
100
+ "$ref": {
101
+ "source": "componentContext",
102
+ "path": "componentCode"
103
+ }
104
+ }
105
+
106
+ or
107
+
108
+ {
109
+ "$ref": {
110
+ "source": "componentContext",
111
+ "path": "cssCode"
112
+ }
113
+ }
114
+
115
+ Rules:
116
+
117
+ - Never use placeholder strings such as {{OUTPUT_OF_PREVIOUS_TASK}}.
118
+ - References must point to an existing previous task or to componentContext.
119
+ - Only reference fields defined in task return contracts or fields available in componentContext.
120
+ - Do not invent output fields.
121
+ - Prefer referencing existing code from componentContext instead of rewriting or regenerating it.
122
+ - Existing code should be transformed, not recreated.
123
+ - When modifying a component, prefer using references to componentContext.componentCode and componentContext.cssCode rather than emitting duplicated code.
124
+ `;
125
+ const outputRules = `
126
+ Return ONLY a JSON array.
127
+
128
+ Do NOT return:
129
+ - markdown
130
+ - explanations
131
+ - comments
132
+ - prose
133
+ - code fences
134
+
135
+ Each item must follow this structure:
136
+
137
+ {
138
+ "taskId": "task_1"
139
+ "task": "taskName",
140
+ "reason": "short reason",
141
+ "confidence": "confidence level from 0 to 1",
142
+ "payload": {}
143
+ }
144
+
145
+ Payload must contain only relevant fields.`;
146
+ /**
147
+ * Builds a strict JSX generation prompt for Looma.
148
+ *
149
+ * ------------------------------------------------------------
150
+ * WHY THIS FUNCTION EXISTS
151
+ * ------------------------------------------------------------
152
+ *
153
+ * Raw user prompts are too ambiguous for reliable JSX generation.
154
+ *
155
+ * Example:
156
+ *
157
+ * "add a modern navbar"
158
+ *
159
+ * Without constraints, LLM may:
160
+ *
161
+ * - generate invalid JSX
162
+ * - generate full components
163
+ * - hallucinate imports
164
+ * - generate inline styles
165
+ * - generate state/hooks unnecessarily
166
+ * - generate unrelated wrappers
167
+ *
168
+ * This function decorates planner prompts
169
+ * with strict JSX generation rules.
170
+ *
171
+ * ------------------------------------------------------------
172
+ * WHAT THIS FUNCTION DOES
173
+ * ------------------------------------------------------------
174
+ *
175
+ * - injects JSX generation rules
176
+ * - injects architecture constraints
177
+ * - injects formatting requirements
178
+ * - injects project context
179
+ * - enforces deterministic output
180
+ *
181
+ * ------------------------------------------------------------
182
+ * IMPORTANT
183
+ * ------------------------------------------------------------
184
+ *
185
+ * This prompt is ONLY for generating JSX fragments.
186
+ *
187
+ * NOT:
188
+ * - full component files
189
+ * - CSS
190
+ * - hooks
191
+ * - imports
192
+ * - business logic
193
+ *
194
+ * ------------------------------------------------------------
195
+ * PARAMS
196
+ * ------------------------------------------------------------
197
+ *
198
+ * @param {Object} params
199
+ *
200
+ * @param {string} params.userPrompt
201
+ * Planner generated JSX request.
202
+ *
203
+ * Example:
204
+ *
205
+ * "Generate a responsive hero section
206
+ * with heading, description and CTA"
207
+ *
208
+ * @param {string[]} params.availableComponents
209
+ * Existing reusable project components.
210
+ *
211
+ * @param {string[]} params.projectDependencies
212
+ * Installed project dependencies.
213
+ *
214
+ * @param {string} params.selectedComponentContext
215
+ * Nearby JSX/component context.
216
+ *
217
+ * @param {string} params.targetElement
218
+ * JSX target location description.
219
+ *
220
+ * ------------------------------------------------------------
221
+ * RETURNS
222
+ * ------------------------------------------------------------
223
+ *
224
+ * @returns {string}
225
+ *
226
+ * Final decorated JSX generation prompt.
227
+ *
228
+ */
229
+ function buildGenerateJSXPrompt({ userPrompt, availableComponents = [], projectDependencies = [], selectedComponentContext = "", targetElement = "", }) {
230
+ let prompt = `
231
+ You are a JSX generation engine for Looma.
232
+
233
+ Your task is to generate ONLY JSX.
234
+
235
+ --------------------------------------------------
236
+ CORE RULES
237
+ --------------------------------------------------
238
+
239
+ - Return ONLY valid JSON
240
+ - Do NOT return markdown
241
+ - Do NOT explain anything
242
+ - Do NOT generate full React component files
243
+ - Do NOT generate imports
244
+ - Do NOT generate exports
245
+ - Do NOT generate hooks
246
+ - Do NOT generate state
247
+ - Do NOT generate event logic unless explicitly requested
248
+ - Do NOT generate CSS
249
+ - Do NOT generate inline styles unless explicitly requested
250
+ - Do NOT generate mock data unless explicitly requested
251
+ - Do NOT generate comments
252
+ - Do NOT wrap output in React.Fragment unless necessary
253
+ - JSX must always be syntactically valid
254
+ - All JSX tags must be properly closed
255
+ - Output must contain a single valid JSX root
256
+ - Prefer semantic HTML
257
+ - Prefer reusable project components
258
+ - Prefer minimal and clean structure
259
+ - Avoid unnecessary nesting
260
+ - Avoid deeply nested div structures
261
+ - Use className instead of style
262
+ - Generated JSX must be production-ready
263
+ - Use existing project architecture patterns
264
+ - Do NOT hallucinate unavailable libraries/components
265
+ - Only use dependencies listed below
266
+ - Use meaningful class names
267
+ - Add data-farmon-id ONLY if explicitly requested
268
+ - Keep output deterministic and concise
269
+
270
+ --------------------------------------------------
271
+ AVAILABLE PROJECT DEPENDENCIES
272
+ --------------------------------------------------
273
+
274
+ ${projectDependencies.join("\n")}
275
+
276
+ --------------------------------------------------
277
+ AVAILABLE REUSABLE COMPONENTS
278
+ --------------------------------------------------
279
+
280
+ ${availableComponents.join("\n")}
281
+
282
+ --------------------------------------------------
283
+ TARGET ELEMENT
284
+ --------------------------------------------------
285
+
286
+ ${targetElement || "Not provided"}
287
+
288
+ --------------------------------------------------
289
+ SELECTED COMPONENT CONTEXT
290
+ --------------------------------------------------
291
+
292
+ ${selectedComponentContext || "No additional context provided"}
293
+
294
+ --------------------------------------------------
295
+ USER REQUEST
296
+ --------------------------------------------------
297
+
298
+ ${userPrompt}
299
+
300
+ --------------------------------------------------
301
+ RETURN FORMAT
302
+ --------------------------------------------------
303
+
304
+ { "jsx": string }
305
+ `;
306
+ return prompt;
307
+ }
308
+ /**
309
+ * Builds a prompt for generating CSS styles.
310
+ */
311
+ function buildGenerateCSSPrompt({ userPrompt, existingCSS = "", existingClassNames = [], componentName = "", projectStyleRules = "", }) {
312
+ return `
313
+ You are a CSS generation engine for Looma.
314
+
315
+ Your task is to generate ONLY CSS.
316
+
317
+ --------------------------------------------------
318
+ RULES
319
+ --------------------------------------------------
320
+
321
+ - Return ONLY valid JSON
322
+ - Do NOT return markdown
323
+ - Do NOT explain anything
324
+ - Do NOT generate JSX
325
+ - Do NOT generate JavaScript
326
+ - Do NOT generate React code
327
+ - Do NOT generate imports
328
+ - Do NOT generate comments
329
+ - CSS must be syntactically valid
330
+ - Prefer clean and minimal CSS
331
+ - Avoid duplicated selectors
332
+ - Avoid global selectors unless explicitly requested
333
+ - Prefer component-scoped class names
334
+ - Prefer existing class names when possible
335
+ - Do NOT generate inline styles
336
+ - Avoid !important unless explicitly required
337
+ - Prefer flexbox/grid for layouts
338
+ - Prefer semantic responsive styling
339
+ - Preserve existing naming conventions
340
+ - Do NOT overwrite unrelated styles
341
+ - Keep output deterministic and concise
342
+
343
+ --------------------------------------------------
344
+ COMPONENT NAME
345
+ --------------------------------------------------
346
+
347
+ ${componentName || "Unknown"}
348
+
349
+ --------------------------------------------------
350
+ EXISTING CLASS NAMES
351
+ --------------------------------------------------
352
+
353
+ ${existingClassNames.join("\n")}
354
+
355
+ --------------------------------------------------
356
+ EXISTING CSS
357
+ --------------------------------------------------
358
+
359
+ ${existingCSS || "No existing CSS provided"}
360
+
361
+ --------------------------------------------------
362
+ PROJECT STYLE RULES
363
+ --------------------------------------------------
364
+
365
+ ${projectStyleRules || "No additional style rules provided"}
366
+
367
+ --------------------------------------------------
368
+ USER REQUEST
369
+ --------------------------------------------------
370
+
371
+ ${userPrompt}
372
+
373
+ --------------------------------------------------
374
+ RETURN FORMAT
375
+ --------------------------------------------------
376
+
377
+ { "css": string }
378
+ `;
379
+ }
380
+ /**
381
+ * Builds a prompt for generating React component logic.
382
+ */
383
+ function buildGenerateComponentLogicPrompt({ userPrompt, existingLogic = "", existingState = [], existingHandlers = [], availableHooks = [], projectDependencies = [], componentContext = "", }) {
384
+ return `
385
+ You are a React component logic generation engine for Looma.
386
+
387
+ Your task is to generate ONLY component logic.
388
+
389
+ --------------------------------------------------
390
+ RULES
391
+ --------------------------------------------------
392
+
393
+ - Return ONLY valid JSON
394
+ - Do NOT return markdown
395
+ - Do NOT explain anything
396
+ - Do NOT generate JSX
397
+ - Do NOT generate CSS
398
+ - Do NOT generate imports
399
+ - Do NOT generate exports
400
+ - Do NOT generate full components
401
+ - Do NOT generate unnecessary state
402
+ - Do NOT generate unnecessary hooks
403
+ - Do NOT generate unnecessary effects
404
+ - Do NOT generate mock data unless explicitly requested
405
+ - Generated code must be syntactically valid
406
+ - Prefer clean and minimal logic
407
+ - Prefer reusable helper functions
408
+ - Avoid duplicated logic
409
+ - Prefer deterministic and predictable state updates
410
+ - Avoid deeply nested conditions
411
+ - Avoid unnecessary async logic
412
+ - Use only available hooks and dependencies
413
+ - Preserve existing architecture patterns
414
+ - Keep output concise and production-ready
415
+
416
+ --------------------------------------------------
417
+ AVAILABLE HOOKS
418
+ --------------------------------------------------
419
+
420
+ ${availableHooks.join("\n")}
421
+
422
+ --------------------------------------------------
423
+ PROJECT DEPENDENCIES
424
+ --------------------------------------------------
425
+
426
+ ${projectDependencies.join("\n")}
427
+
428
+ --------------------------------------------------
429
+ EXISTING STATE
430
+ --------------------------------------------------
431
+
432
+ ${existingState.join("\n")}
433
+
434
+ --------------------------------------------------
435
+ EXISTING HANDLERS
436
+ --------------------------------------------------
437
+
438
+ ${existingHandlers.join("\n")}
439
+
440
+ --------------------------------------------------
441
+ EXISTING LOGIC
442
+ --------------------------------------------------
443
+
444
+ ${existingLogic || "No existing logic provided"}
445
+
446
+ --------------------------------------------------
447
+ COMPONENT CONTEXT
448
+ --------------------------------------------------
449
+
450
+ ${componentContext || "No additional context provided"}
451
+
452
+ --------------------------------------------------
453
+ USER REQUEST
454
+ --------------------------------------------------
455
+
456
+ ${userPrompt}
457
+
458
+ --------------------------------------------------
459
+ RETURN FORMAT
460
+ --------------------------------------------------
461
+
462
+ {
463
+ componentName: string;
464
+ jsx: string;
465
+ css?: string;
466
+ }
467
+ `;
468
+ }
469
+ /**
470
+ * Builds a prompt for generating React component props.
471
+ */
472
+ function buildGeneratePropsPrompt({ userPrompt, componentName = "", jsxContext = "", existingProps = [], projectConventions = "", availableTypes = [], }) {
473
+ return `
474
+ You are a React props generation engine for Looma.
475
+
476
+ Your task is to generate ONLY component props definitions.
477
+
478
+ --------------------------------------------------
479
+ RULES
480
+ --------------------------------------------------
481
+
482
+ - Return ONLY valid JSON
483
+ - Do NOT return markdown
484
+ - Do NOT explain anything
485
+ - Do NOT generate JSX
486
+ - Do NOT generate CSS
487
+ - Do NOT generate component logic
488
+ - Do NOT generate imports
489
+ - Do NOT generate exports
490
+ - Do NOT generate unnecessary props
491
+ - Prefer semantic prop names
492
+ - Prefer reusable and scalable prop structures
493
+ - Prefer primitive types unless object structure is necessary
494
+ - Avoid deeply nested props unless required
495
+ - Infer required vs optional props carefully
496
+ - Infer event handlers only if needed
497
+ - Infer default values only if obvious
498
+ - Preserve existing project naming conventions
499
+ - Keep props concise and production-ready
500
+ - Generated props must align with provided JSX/context
501
+ - Use only available types/conventions
502
+
503
+ --------------------------------------------------
504
+ COMPONENT NAME
505
+ --------------------------------------------------
506
+
507
+ ${componentName || "Unknown"}
508
+
509
+ --------------------------------------------------
510
+ AVAILABLE TYPES
511
+ --------------------------------------------------
512
+
513
+ ${availableTypes.join("\n")}
514
+
515
+ --------------------------------------------------
516
+ EXISTING PROPS
517
+ --------------------------------------------------
518
+
519
+ ${existingProps.join("\n")}
520
+
521
+ --------------------------------------------------
522
+ PROJECT CONVENTIONS
523
+ --------------------------------------------------
524
+
525
+ ${projectConventions || "No additional conventions provided"}
526
+
527
+ --------------------------------------------------
528
+ JSX CONTEXT
529
+ --------------------------------------------------
530
+
531
+ ${jsxContext || "No JSX context provided"}
532
+
533
+ --------------------------------------------------
534
+ USER REQUEST
535
+ --------------------------------------------------
536
+
537
+ ${userPrompt}
538
+
539
+ --------------------------------------------------
540
+ RETURN FORMAT
541
+ --------------------------------------------------
542
+
543
+ {
544
+ "props": [
545
+ {
546
+ "name": "",
547
+ "type": "",
548
+ "required": false,
549
+ "defaultValue": null,
550
+ "description": ""
551
+ }
552
+ ],
553
+ "warnings": []
554
+ }
555
+ `;
556
+ }
557
+ /**
558
+ * Builds a prompt for generating React component state definitions.
559
+ */
560
+ function buildGenerateStatesPrompt({ userPrompt, componentName = "", jsxContext = "", existingStates = [], existingHandlers = [], projectConventions = "", }) {
561
+ return `
562
+ You are a React state generation engine for Looma.
563
+
564
+ Your task is to generate ONLY component state definitions.
565
+
566
+ --------------------------------------------------
567
+ RULES
568
+ --------------------------------------------------
569
+
570
+ - Return ONLY valid JSON
571
+ - Do NOT return markdown
572
+ - Do NOT explain anything
573
+ - Do NOT generate JSX
574
+ - Do NOT generate CSS
575
+ - Do NOT generate imports
576
+ - Do NOT generate exports
577
+ - Do NOT generate full component code
578
+ - Do NOT generate unnecessary state
579
+ - Prefer minimal state architecture
580
+ - Prefer primitive state values when possible
581
+ - Avoid duplicated or derived state
582
+ - Prefer predictable and scalable state structure
583
+ - Infer initial values carefully
584
+ - Infer loading/error state only if needed
585
+ - Preserve existing naming conventions
586
+ - Use semantic state names
587
+ - Keep generated state concise and production-ready
588
+ - Generated state must align with component purpose and JSX context
589
+
590
+ --------------------------------------------------
591
+ COMPONENT NAME
592
+ --------------------------------------------------
593
+
594
+ ${componentName || "Unknown"}
595
+
596
+ --------------------------------------------------
597
+ EXISTING STATES
598
+ --------------------------------------------------
599
+
600
+ ${existingStates.join("\n")}
601
+
602
+ --------------------------------------------------
603
+ EXISTING HANDLERS
604
+ --------------------------------------------------
605
+
606
+ ${existingHandlers.join("\n")}
607
+
608
+ --------------------------------------------------
609
+ PROJECT CONVENTIONS
610
+ --------------------------------------------------
611
+
612
+ ${projectConventions || "No additional conventions provided"}
613
+
614
+ --------------------------------------------------
615
+ JSX CONTEXT
616
+ --------------------------------------------------
617
+
618
+ ${jsxContext || "No JSX context provided"}
619
+
620
+ --------------------------------------------------
621
+ USER REQUEST
622
+ --------------------------------------------------
623
+
624
+ ${userPrompt}
625
+
626
+ --------------------------------------------------
627
+ RETURN FORMAT
628
+ --------------------------------------------------
629
+
630
+ {
631
+ "states": [
632
+ {
633
+ "name": "",
634
+ "initialValue": null,
635
+ "type": "",
636
+ "purpose": ""
637
+ }
638
+ ],
639
+ "warnings": []
640
+ }
641
+ `;
642
+ }
643
+ /**
644
+ * Builds a prompt for generating React event handlers.
645
+ */
646
+ function buildGenerateHandlerPrompt({ userPrompt, componentName = "", jsxContext = "", existingStates = [], existingHandlers = [], availableUtilities = [], projectConventions = "", }) {
647
+ return `
648
+ You are a React handler generation engine for Looma.
649
+
650
+ Your task is to generate ONLY event handler logic.
651
+
652
+ --------------------------------------------------
653
+ RULES
654
+ --------------------------------------------------
655
+
656
+ - Return ONLY valid JSON
657
+ - Do NOT return markdown
658
+ - Do NOT explain anything
659
+ - Do NOT generate JSX
660
+ - Do NOT generate CSS
661
+ - Do NOT generate imports
662
+ - Do NOT generate exports
663
+ - Do NOT generate full component code
664
+ - Do NOT generate unnecessary handlers
665
+ - Prefer concise and deterministic logic
666
+ - Prefer pure functions when possible
667
+ - Prefer readable and maintainable logic
668
+ - Avoid deeply nested conditions
669
+ - Avoid duplicated logic
670
+ - Avoid unnecessary async operations
671
+ - Avoid direct DOM manipulation unless explicitly required
672
+ - Use existing state names and conventions
673
+ - Use semantic handler names
674
+ - Preserve existing project architecture patterns
675
+ - Generated handlers must align with JSX context and component purpose
676
+ - Keep generated code production-ready
677
+
678
+ --------------------------------------------------
679
+ COMPONENT NAME
680
+ --------------------------------------------------
681
+
682
+ ${componentName || "Unknown"}
683
+
684
+ --------------------------------------------------
685
+ EXISTING STATES
686
+ --------------------------------------------------
687
+
688
+ ${existingStates.join("\n")}
689
+
690
+ --------------------------------------------------
691
+ EXISTING HANDLERS
692
+ --------------------------------------------------
693
+
694
+ ${existingHandlers.join("\n")}
695
+
696
+ --------------------------------------------------
697
+ AVAILABLE UTILITIES
698
+ --------------------------------------------------
699
+
700
+ ${availableUtilities.join("\n")}
701
+
702
+ --------------------------------------------------
703
+ PROJECT CONVENTIONS
704
+ --------------------------------------------------
705
+
706
+ ${projectConventions || "No additional conventions provided"}
707
+
708
+ --------------------------------------------------
709
+ JSX CONTEXT
710
+ --------------------------------------------------
711
+
712
+ ${jsxContext || "No JSX context provided"}
713
+
714
+ --------------------------------------------------
715
+ USER REQUEST
716
+ --------------------------------------------------
717
+
718
+ ${userPrompt}
719
+
720
+ --------------------------------------------------
721
+ RETURN FORMAT
722
+ --------------------------------------------------
723
+
724
+ {
725
+ "handlers": [
726
+ {
727
+ "name": "",
728
+ "code": "",
729
+ "dependsOnStates": [],
730
+ "warnings": []
731
+ }
732
+ ]
733
+ }
734
+ `;
735
+ }
736
+ /**
737
+ * Builds a prompt for generating responsive CSS styles.
738
+ */
739
+ function buildGenerateResponsiveStylesPrompt({ userPrompt, componentName = "", existingCSS = "", existingClassNames = [], supportedBreakpoints = [], projectStyleRules = "", }) {
740
+ return `
741
+ You are a responsive CSS generation engine for Looma.
742
+
743
+ Your task is to generate ONLY responsive CSS styles.
744
+
745
+ --------------------------------------------------
746
+ RULES
747
+ --------------------------------------------------
748
+
749
+ - Return ONLY valid JSON
750
+ - Do NOT return markdown
751
+ - Do NOT explain anything
752
+ - Do NOT generate JSX
753
+ - Do NOT generate JavaScript
754
+ - Do NOT generate React code
755
+ - Do NOT generate imports
756
+ - Do NOT generate comments
757
+ - CSS must be syntactically valid
758
+ - Prefer mobile-first responsive design
759
+ - Prefer minimal and maintainable media queries
760
+ - Avoid duplicated responsive rules
761
+ - Avoid unnecessary breakpoints
762
+ - Prefer flexbox and grid layouts
763
+ - Preserve existing class names and architecture
764
+ - Do NOT overwrite unrelated styles
765
+ - Avoid !important unless explicitly required
766
+ - Prefer semantic spacing and layout scaling
767
+ - Keep responsive styles concise and production-ready
768
+ - Use only provided breakpoints
769
+
770
+ --------------------------------------------------
771
+ COMPONENT NAME
772
+ --------------------------------------------------
773
+
774
+ ${componentName || "Unknown"}
775
+
776
+ --------------------------------------------------
777
+ SUPPORTED BREAKPOINTS
778
+ --------------------------------------------------
779
+
780
+ ${supportedBreakpoints.join("\n")}
781
+
782
+ --------------------------------------------------
783
+ EXISTING CLASS NAMES
784
+ --------------------------------------------------
785
+
786
+ ${existingClassNames.join("\n")}
787
+
788
+ --------------------------------------------------
789
+ EXISTING CSS
790
+ --------------------------------------------------
791
+
792
+ ${existingCSS || "No existing CSS provided"}
793
+
794
+ --------------------------------------------------
795
+ PROJECT STYLE RULES
796
+ --------------------------------------------------
797
+
798
+ ${projectStyleRules || "No additional style rules provided"}
799
+
800
+ --------------------------------------------------
801
+ USER REQUEST
802
+ --------------------------------------------------
803
+
804
+ ${userPrompt}
805
+
806
+ --------------------------------------------------
807
+ RETURN FORMAT
808
+ --------------------------------------------------
809
+
810
+ {
811
+ "css": "",
812
+ "mediaQueries": [],
813
+ "affectedSelectors": [],
814
+ "warnings": []
815
+ }
816
+ `;
817
+ }
818
+ function buildInstructionClassifierPrompt(command) {
819
+ return `
820
+ You are an instruction classifier.
821
+
822
+ Your task is to classify the user's request into exactly one category.
823
+
824
+ QUERY
825
+ - User wants information.
826
+ - User is asking a question.
827
+ - User wants to inspect the project.
828
+ - User wants to inspect runtime state.
829
+ - User wants to understand code.
830
+
831
+ Examples:
832
+ "Is zustand installed?"
833
+ "Which routes exist?"
834
+ "What component renders this button?"
835
+ "Show me package dependencies."
836
+ "Why is this component rendering twice?"
837
+
838
+ MUTATION
839
+ - User wants to modify code.
840
+ - User wants to modify styles.
841
+ - User wants to create files.
842
+ - User wants to delete files.
843
+ - User wants to refactor code.
844
+ - User wants to change runtime behavior.
845
+
846
+ Examples:
847
+ "Make the button blue."
848
+ "Create a footer component."
849
+ "Remove unused imports."
850
+ "Rename UserCard to ProfileCard."
851
+ "Add dark mode."
852
+
853
+ Return ONLY valid JSON.
854
+
855
+ {
856
+ "category": "QUERY" | "MUTATION"
857
+ }
858
+
859
+ User Request:
860
+ ${command}
861
+ `;
862
+ }
863
+ function createQueryAgentPrompt({ command, taskDocs, previousResults, }) {
864
+ return `
865
+ You are a Project Query Agent.
866
+
867
+ Your goal is to answer the user's question.
868
+
869
+ You may execute tasks to gather information.
870
+
871
+ Available Tasks:
872
+
873
+ ${taskDocs}
874
+
875
+ Previous Task Results:
876
+
877
+ ${previousResults}
878
+
879
+ User Question:
880
+
881
+ ${command}
882
+
883
+ Rules:
884
+
885
+ - Use tasks when information is needed.
886
+ - Never invent information.
887
+ - When enough information exists, return done.
888
+ - Return ONLY valid JSON.
889
+
890
+ Respond with ONLY a valid JSON object.
891
+ - Do not use markdown.
892
+ - Do not use code fences.
893
+ - Do not explain your reasoning.
894
+ - Do not write any text before or after the JSON.
895
+
896
+ Continue format:
897
+
898
+ {
899
+ "status": "continue",
900
+ "task": "taskName",
901
+ "reason": "why",
902
+ "payload": {}
903
+ }
904
+
905
+ Done format:
906
+
907
+ {
908
+ "status": "done",
909
+ "response": "answer"
910
+ }
911
+
912
+ ❌ Incorrect
913
+
914
+ To answer this question...
915
+
916
+ {
917
+ ...
918
+ }
919
+
920
+ ✅ Correct
921
+
922
+ {
923
+ ...
924
+ }
925
+ `;
926
+ }
927
+ /**
928
+ * Generates Looma planner prompt.
929
+ *
930
+ * ------------------------------------------------------------
931
+ * WHAT THIS FUNCTION DOES
932
+ * ------------------------------------------------------------
933
+ *
934
+ * This function creates the final prompt sent to the LLM.
935
+ *
936
+ * The prompt is responsible for:
937
+ *
938
+ * - understanding user intent
939
+ * - understanding selected component context
940
+ * - generating deterministic mutation tasks
941
+ *
942
+ * IMPORTANT:
943
+ *
944
+ * This prompt does NOT ask LLM to generate code.
945
+ *
946
+ * It ONLY asks LLM to generate:
947
+ *
948
+ * action plan JSON
949
+ *
950
+ * ------------------------------------------------------------
951
+ * WHY THIS IS IMPORTANT
952
+ * ------------------------------------------------------------
953
+ *
954
+ * Separating:
955
+ *
956
+ * planning
957
+ * from
958
+ * execution
959
+ *
960
+ * makes the system:
961
+ *
962
+ * - more deterministic
963
+ * - safer
964
+ * - debuggable
965
+ * - retryable
966
+ *
967
+ * ------------------------------------------------------------
968
+ * PARAMS
969
+ * ------------------------------------------------------------
970
+ *
971
+ * @param {Object} params
972
+ *
973
+ * @param {string} params.userCommand
974
+ * User natural language command.
975
+ *
976
+ * Example:
977
+ *
978
+ * "make header red"
979
+ *
980
+ * @param {Object} params.componentContext
981
+ * Selected component context object.
982
+ *
983
+ * @param {string[]} params.availableTasks
984
+ * Allowed Looma task names.
985
+ *
986
+ * ------------------------------------------------------------
987
+ * RETURNS
988
+ * ------------------------------------------------------------
989
+ *
990
+ * @returns {string}
991
+ * Fully generated LLM planner prompt.
992
+ *
993
+ */
994
+ async function generatePlannerPrompt({ command, componentContext, projectDependencies, }) {
995
+ const {
996
+ // astTasks,
997
+ mutationTasks, generatorTasks, } = await utils.generateTasksDocs();
998
+ // ----------------------------------------------------------
999
+ // STEP 1:
1000
+ // Convert component context into formatted JSON
1001
+ // ----------------------------------------------------------
1002
+ const formattedContext = JSON.stringify(componentContext, null, 2);
1003
+ // ----------------------------------------------------------
1004
+ // STEP 2:
1005
+ // Convert available tasks into formatted JSON
1006
+ // ----------------------------------------------------------
1007
+ // const formattedTasks = JSON.stringify(availableTasks, null, 2);
1008
+ // ----------------------------------------------------------
1009
+ // STEP 3:
1010
+ // Convert dependencies into formatted JSON
1011
+ // ----------------------------------------------------------
1012
+ const formattedDependencies = JSON.stringify(projectDependencies.allPackages, null, 2);
1013
+ // ----------------------------------------------------------
1014
+ // STEP 4:
1015
+ // Build final planner prompt
1016
+ // ----------------------------------------------------------
1017
+ const prompt = `${plannerIdentity}
1018
+
1019
+ --------------------------------------------------
1020
+ ARCHITECTURE RULES
1021
+ --------------------------------------------------
1022
+
1023
+ ${architecturalRules}
1024
+
1025
+ --------------------------------------------------
1026
+ AVAILABLE TASKS
1027
+ --------------------------------------------------
1028
+
1029
+ You have access to three categories of tasks:
1030
+
1031
+ 1. Mutation Tasks
1032
+ These tasks modify the project structure or filesystem.
1033
+
1034
+ ${mutationTasks}
1035
+
1036
+ 2. Generator Tasks
1037
+ Used when new code must be created and the required code does not already exist.
1038
+
1039
+ ${generatorTasks}
1040
+
1041
+ --------------------------------------------------
1042
+ TASK RULES
1043
+ --------------------------------------------------
1044
+
1045
+ ${taskRules}
1046
+
1047
+ --------------------------------------------------
1048
+ PROJECT DEPENDENCIES
1049
+ --------------------------------------------------
1050
+
1051
+ Installed Packages:
1052
+ ${formattedDependencies}
1053
+
1054
+
1055
+ --------------------------------------------------
1056
+ PLANNING RULES
1057
+ --------------------------------------------------
1058
+
1059
+ ${planningRules}
1060
+
1061
+ --------------------------------------------------
1062
+ OUTPUT RULES
1063
+ --------------------------------------------------
1064
+
1065
+ ${outputRules}
1066
+
1067
+ --------------------------------------------------
1068
+ TASK REFERENCING RULES
1069
+ --------------------------------------------------
1070
+
1071
+ ${taskReferencingRules}
1072
+
1073
+ --------------------------------------------------
1074
+ USER IS SEEING HIS WEB APP AND USER HAS SELECTED THIS HTML(REACTJS) COMPONENT
1075
+ --------------------------------------------------
1076
+
1077
+ ${formattedContext}
1078
+
1079
+ --------------------------------------------------
1080
+ USER HAS TYPED THIS COMMAND
1081
+ --------------------------------------------------
1082
+
1083
+ ${command}
1084
+
1085
+ --------------------------------------------------
1086
+ GENERATE TASK PLAN
1087
+ --------------------------------------------------
1088
+ `;
1089
+ // ----------------------------------------------------------
1090
+ // STEP 4:
1091
+ // Return generated prompt
1092
+ // ----------------------------------------------------------
1093
+ return prompt;
1094
+ }
1095
+ function buildComponentCodePrompt({ userPrompt }) {
1096
+ const userRequest = `
1097
+ You are a React component generation engine for Looma.
1098
+
1099
+ Your task is to generate production-ready React component code.
1100
+
1101
+ RULES:
1102
+
1103
+ - Use only Function declarations only
1104
+ - Return ONLY valid JSON
1105
+ - Do NOT return markdown
1106
+ - Do NOT explain anything
1107
+ - Do NOT include comments unless explicitly requested
1108
+ - Generated code must be syntactically valid
1109
+ - Component must use functional React components
1110
+ - Prefer clean and minimal JSX structure
1111
+ - Keep component modular and readable
1112
+ - Avoid unnecessary nesting
1113
+ - Avoid inline styles unless explicitly requested
1114
+ - Prefer semantic HTML tags
1115
+ - Use className for styling
1116
+ - Assume CSS file already exists unless told otherwise
1117
+ - Do NOT generate mock data unless requested
1118
+ - Do NOT generate unnecessary state
1119
+ - Do NOT generate unnecessary useEffect hooks
1120
+ - Do NOT generate unnecessary libraries/imports
1121
+ - Preserve existing project architecture and naming conventions
1122
+ - Component names must be PascalCase
1123
+ - CSS classes must follow Looma naming conventions
1124
+ - Output must be deterministic and concise
1125
+ - Do NOT hallucinate unavailable libraries
1126
+ - Only use libraries present in provided dependencies list
1127
+ - Reuse existing components when possible
1128
+ - Prefer composition over duplication
1129
+ - JSX must always have a single valid root
1130
+ - Avoid deeply coupled logic
1131
+ - Avoid giant components
1132
+ - Prefer extracting repeated UI blocks into child components
1133
+ - Generated code must be directly writable into a project file
1134
+
1135
+ USER REQUEST:
1136
+ ${userPrompt}
1137
+
1138
+ RETURN FORMAT:
1139
+
1140
+ {
1141
+ "componentName": "",
1142
+ "imports": [],
1143
+ "componentCode": "",
1144
+ "cssClasses": [],
1145
+ "childComponents": [],
1146
+ "warnings": []
1147
+ }`;
1148
+ return userRequest;
1149
+ }
1150
+ export default {
1151
+ buildGenerateJSXPrompt,
1152
+ buildGenerateCSSPrompt,
1153
+ buildGenerateComponentLogicPrompt,
1154
+ buildGeneratePropsPrompt,
1155
+ buildGenerateStatesPrompt,
1156
+ buildGenerateHandlerPrompt,
1157
+ buildGenerateResponsiveStylesPrompt,
1158
+ buildInstructionClassifierPrompt,
1159
+ createQueryAgentPrompt,
1160
+ generatePlannerPrompt,
1161
+ buildComponentCodePrompt,
1162
+ };
1163
+ //# sourceMappingURL=prompt-maker.js.map