Files
gabrielvidalandClaude Opus 5.5 d880ab257f feat(form): YAML form files — sections keyed by title, fields by key, options by value
`ask-form create form.yaml` takes the whole form in one file: title,
description, lang and sections (each a page, keyed by its title), with
fields keyed by their key, options by their value and a table's columns by
their key, in the order written. A section takes an intro (markdown under
its title) and a showIf for the whole page. Plain lists of option texts and
the old lists (`key:` fields, `value:` options) are read too, and the flat
JSON field array still works byte for byte (--fields-file spec.json).

- internal/form/yaml.go: a strict YAML 1.2 subset reader, stdlib only.
  Ordered mappings (*form.Map), block and flow collections, | and >
  scalars, quotes, comments; refuses anchors, tags, ? keys, several
  documents, tab indentation and duplicate keys, with the line. Only
  true/false are booleans; a number keeps its text (json.Number).
- internal/form/doc.go: ParseDoc compiles a form file (YAML, or JSON of the
  same shape) into the flat field array: section title -> group, intro ->
  a markdown block, section showIf AND-ed into its fields'. The CLI does it
  before POST /v1/forms, so server, relay, store and MCP are unchanged and
  a new CLI works with an older serve.
- examples: spec.yaml + spec.fr.yaml replace the JSON specs (converted,
  each checked to normalise to the same fields); /spec.json still answers
  with the form compiled to JSON.
- SKILL.md, the claude.ai sandbox skill, agent-install, README and
  CLAUDE.md teach the YAML form file; a test keeps SKILL.md's YAML valid.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 11:52:10 +01:00

98 lines
4.9 KiB
YAML

title: 'Splitting server.ts: the plan'
description: |-
`api/server.ts` has grown to 2,412 lines: routes, validation, queries and emails in one file. Here is how I'd split it. Nothing moves until you've answered; my picks are pre-selected.
summary: |-
Sign off a refactor before any code moves: the plan drawn, then scope, PR strategy and how strict to be about behaviour.
order: 5
sections:
The plan:
fields:
before-after:
type: html
label: Before → after
html: |-
<svg viewBox="0 0 400 300" xmlns="http://www.w3.org/2000/svg" style="display:block;width:100%;max-width:520px;height:auto;margin:0 auto;font:14px system-ui,sans-serif">
<text x="8" y="16" fill="hsl(var(--muted-foreground))" font-size="12" letter-spacing=".06em">TODAY</text>
<rect x="8" y="26" width="384" height="52" rx="12" fill="hsl(var(--destructive) / .08)" stroke="hsl(var(--destructive) / .5)"/>
<text x="24" y="57" fill="hsl(var(--foreground))" font-weight="700" font-size="16">server.ts</text>
<text x="376" y="57" text-anchor="end" fill="hsl(var(--muted-foreground))">2,412 lines · 38 routes · 0 tests</text>
<path d="M200 86V104" stroke="hsl(var(--muted-foreground))" stroke-width="1.5"/><path d="M194 104l6 10 6-10z" fill="hsl(var(--muted-foreground))"/>
<text x="8" y="134" fill="hsl(var(--muted-foreground))" font-size="12" letter-spacing=".06em">AFTER</text>
<rect x="8" y="144" width="384" height="34" rx="10" fill="hsl(var(--card))" stroke="hsl(var(--border))"/>
<text x="200" y="166" text-anchor="middle" fill="hsl(var(--foreground))">server.ts · app + middleware · 60 lines</text>
<g fill="hsl(var(--primary) / .1)" stroke="hsl(var(--primary))">
<rect x="8" y="188" width="122" height="54" rx="10"/><rect x="139" y="188" width="122" height="54" rx="10"/><rect x="270" y="188" width="122" height="54" rx="10"/></g>
<g text-anchor="middle" fill="hsl(var(--foreground))" font-weight="600">
<text x="69" y="211">users/</text><text x="200" y="211">billing/</text><text x="331" y="211">projects/</text></g>
<g text-anchor="middle" fill="hsl(var(--muted-foreground))" font-size="12">
<text x="69" y="230">9 routes</text><text x="200" y="230">14 routes</text><text x="331" y="230">15 routes</text></g>
<rect x="8" y="252" width="384" height="34" rx="10" fill="hsl(var(--muted))" stroke="hsl(var(--border))"/>
<text x="200" y="274" text-anchor="middle" fill="hsl(var(--foreground))">shared/ · db · errors · validate · mail</text>
</svg>
what-changes:
type: markdown
label: What changes
text: |-
| | Before | After |
|---|---|---|
| Largest file | 2,412 lines | ~300 lines |
| Routes with a test | 0 of 38 | 38 of 38 (snapshot) |
| Circular imports | 4 | 0 |
Every route keeps its path, its input and its response. I record all 38 routes' responses before the move and diff them after.
layout:
type: radio
label: How should the code be grouped?
required: true
default: domain
options:
domain:
label: By domain
description: 'users/, billing/, projects/: a change to billing stays in billing/'
layer:
label: By layer
description: "routes/, services/, repos/: closer to today's habits"
Delivery:
fields:
delivery:
type: radio
label: How do you want to review it?
required: true
default: stacked
options:
one-pr: {label: One PR, description: '~3,000 lines moved, hard to read'}
stacked:
label: Four stacked PRs
description: shared/ first, then one per domain, each green on its own
main: {label: Straight to main, description: 'One commit per step, no PR'}
behaviour:
type: radio
label: How strict about behaviour?
required: true
default: identical
options:
identical:
label: Byte-identical responses
description: A pure move; the bugs I find go in a list
fixes:
label: Small fixes allowed
description: Status codes and error shapes, each listed in the PR
extras:
type: multiselect
label: While I'm in there
default: [snapshot-tests]
options:
snapshot-tests:
label: Keep the 38 snapshot tests
description: They cost nothing once recorded
zod: Replace hand-written validation with zod
kysely: Typed queries (Kysely) in the repos
freeze:
type: radio
label: Other branches touching server.ts
default: rebase
help: '`feat/teams` and `fix/login-redirect` both edit server.ts.'
options:
rebase: I rebase them onto the split when it lands
wait: Wait until they're merged, then split