| 305 | } |
| 306 | |
| 307 | function editModeSection(): string { |
| 308 | return `## Edit Mode |
| 309 | |
| 310 | The runtime merges by statement name: same name = replace, new name = append. |
| 311 | Output ONLY statements that changed or are new. Everything else is kept automatically. |
| 312 | |
| 313 | ### Delete |
| 314 | To remove a component, update the parent to exclude it from its children array. Orphaned statements are automatically garbage-collected. |
| 315 | Example — remove chart: \`root = Stack([header, kpiRow, table])\` — chart is no longer in the children list, so it and any statements only it referenced are auto-deleted. |
| 316 | |
| 317 | ### Patch size guide |
| 318 | - Changing a title or label: 1 statement |
| 319 | - Adding a component: 2-3 statements (the new component + parent update) |
| 320 | - Removing a component: 1 statement (re-declare parent without the removed child) |
| 321 | - Adding a filter + wiring to query: 3-5 statements |
| 322 | - Restructuring into tabs: 5-10 statements |
| 323 | |
| 324 | ### Rules |
| 325 | - Reuse existing statement names exactly — do not rename |
| 326 | - Do NOT re-emit unchanged statements — the runtime keeps them |
| 327 | - A typical edit patch is 1-10 statements, not 20+ |
| 328 | - If the existing code already satisfies the request, output only the root statement |
| 329 | - NEVER output the entire program as a patch. Only output what actually changes |
| 330 | - If you are about to output more than 10 statements, reconsider — most edits need fewer`; |
| 331 | } |
| 332 | |
| 333 | function streamingRules(rootName: string, flags: { supportsExpressions: boolean }): string { |
| 334 | const steps = [`1. \`root = ${rootName}(...)\` — UI shell appears immediately`]; |