| 382 | } |
| 383 | |
| 384 | function toolWorkflowSection(): string { |
| 385 | return `## Data Workflow |
| 386 | |
| 387 | When tools are available, follow this workflow: |
| 388 | 1. FIRST: Call the most relevant tool to inspect the real data shape before generating code |
| 389 | 2. Use Query() for READ operations (data that should stay live) — NEVER hardcode tool results as literal arrays or objects |
| 390 | 3. Use Mutation() for WRITE operations (create, update, delete) — triggered by button clicks via Action([@Run(mutationRef)]) |
| 391 | 4. Use the real data from step 1 as condensed Query defaults (3-5 rows) so the UI renders immediately |
| 392 | 5. Use @-prefixed builtins (@Count, @Filter, @Sort, @Sum) on Query results for KPIs and aggregations — the runtime evaluates these live on every refresh |
| 393 | 6. Hardcoded arrays are ONLY for static display data (labels, options) where no tool exists |
| 394 | |
| 395 | WRONG — you called a tool and got data back, but you inlined the results: |
| 396 | \`\`\` |
| 397 | openCount = 2 |
| 398 | item1 = SomeComp("first item title") |
| 399 | item2 = SomeComp("second item title") |
| 400 | list = Stack([item1, item2]) |
| 401 | chart = SomeChart(["A", "B"], [12, 8]) |
| 402 | \`\`\` |
| 403 | This is static — it shows stale data and won't update. Creating item1, item2, item3... manually is ALWAYS wrong when a tool exists. |
| 404 | |
| 405 | RIGHT — use Query() for live data, Mutation() for writes, @builtins to derive values: |
| 406 | \`\`\` |
| 407 | data = Query("tool_name", {}, {rows: []}) |
| 408 | openCount = @Count(@Filter(data.rows, "field", "==", "value")) |
| 409 | list = @Each(data.rows, "item", SomeComp(item.title, item.field)) |
| 410 | createResult = Mutation("create_tool", {title: $title}) |
| 411 | submitBtn = Button("Create", Action([@Run(createResult), @Run(data), @Reset($title)])) |
| 412 | \`\`\` |
| 413 | Everything derives from the Query — when data refreshes, the entire dashboard updates automatically.`; |
| 414 | } |
| 415 | |
| 416 | function importantRules( |
| 417 | rootName: string, |