#!/usr/bin/env node /** * cli:apply-form-directives — Persist the /ui-design judgment into a pagespec. * * Writes a namespaced `uiDesign` overlay (formLayout + per-field currentUserFk / * section / control + order) into the pagespec's machine block, so the judgment * is DURABLE and reproducible. The `/ui-design` skill decides the directives; this * CLI only applies them. scaffold-component still RENDERS the page (the overlay * feeds the spec it is given). * * npx tsx skills/ui-design/cli/apply-form-directives/index.ts --spec '' */ import { parseArgs } from 'node:util' import { validate } from './validate.js' import { execute } from './execute.js' import { generateEnvelope, failGenerate, printEnvelope } from '../../../lib/output.js' import type { ApplyFormDirectivesInput } from './types.js' const COMMAND = 'apply-form-directives' function main(): void { const { values } = parseArgs({ options: { spec: { type: 'string' } }, strict: true, }) if (!values.spec) { printEnvelope(failGenerate(COMMAND, ['--spec is required'])) process.exit(1) } let raw: unknown try { raw = JSON.parse(values.spec) } catch { printEnvelope(failGenerate(COMMAND, ['Invalid JSON'])) process.exit(1) } const validation = validate(raw) if (!validation.valid) { printEnvelope(failGenerate(COMMAND, validation.errors)) process.exit(1) } try { const { pagespecPath, overlay, warnings } = execute(raw as ApplyFormDirectivesInput) printEnvelope(generateEnvelope(COMMAND, { data: { pagespecPath, uiDesign: overlay, warnings: [...validation.warnings, ...warnings] }, filesModified: [pagespecPath], nextSteps: [ 'Re-scaffold the page with scaffold-component (the overlay feeds the spec) so the judgment renders live', 'Run /ui-components to fix mechanical tokens on the result', ], })) } catch (e) { printEnvelope(failGenerate(COMMAND, [e instanceof Error ? e.message : String(e)])) process.exit(1) } } main()