@pixel-point/toolcraft 0.0.12 → 0.0.14

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 (37) hide show
  1. package/README.md +4 -2
  2. package/package.json +1 -1
  3. package/src/cli.mjs +18 -45
  4. package/src/cli.test.mjs +141 -6
  5. package/src/command-runner.mjs +71 -0
  6. package/src/dependency-install.mjs +87 -0
  7. package/src/generate.mjs +32 -4
  8. package/src/generate.test.mjs +116 -15
  9. package/src/package-json.mjs +11 -2
  10. package/src/package-json.test.mjs +27 -0
  11. package/src/package-manager.mjs +123 -0
  12. package/src/package-manager.test.mjs +80 -0
  13. package/templates/runtime/contracts/component-contracts.test.ts +1 -1
  14. package/templates/runtime/contracts/component-contracts.ts +1 -1
  15. package/templates/starter/AGENTS.md +4 -3
  16. package/templates/starter/docs/toolcraft/README.md +15 -0
  17. package/templates/starter/docs/toolcraft/acceptance-testing.md +2 -0
  18. package/templates/starter/docs/toolcraft/assembly-workflow.md +35 -171
  19. package/templates/starter/docs/toolcraft/component-rules.md +12 -188
  20. package/templates/starter/docs/toolcraft/core/control-selection.md +93 -0
  21. package/templates/starter/docs/toolcraft/core/layout.md +104 -0
  22. package/templates/starter/docs/toolcraft/core/media-upload.md +85 -0
  23. package/templates/starter/docs/toolcraft/core/performance.md +83 -0
  24. package/templates/starter/docs/toolcraft/core/reference-study.md +115 -0
  25. package/templates/starter/docs/toolcraft/core/runtime-boundary.md +53 -0
  26. package/templates/starter/docs/toolcraft/core/setup-export.md +86 -0
  27. package/templates/starter/docs/toolcraft/core/timeline-animation.md +67 -0
  28. package/templates/starter/docs/toolcraft/custom-controls.md +2 -0
  29. package/templates/starter/docs/toolcraft/performance.md +2 -0
  30. package/templates/starter/docs/toolcraft/renderer-technique.md +2 -0
  31. package/templates/starter/docs/toolcraft/schema-reference.md +117 -367
  32. package/templates/starter/docs/toolcraft/workflow.md +12 -10
  33. package/templates/starter/package.json +1 -0
  34. package/templates/starter/scripts/check-toolcraft-docs.mjs +28 -6
  35. package/templates/starter/scripts/run-vite-on-free-port.mjs +25 -6
  36. package/templates/starter/src/app/starter-acceptance.test.ts +24 -15
  37. package/templates/starter/src/app/starter-performance.test.ts +17 -7
@@ -0,0 +1,93 @@
1
+ # Control Selection
2
+
3
+ Read this module before adding, replacing, grouping, or custom-rendering controls.
4
+
5
+ ## Built-In First
6
+
7
+ - Choose controls by product value model before UI appearance.
8
+ - Use built-in Toolcraft controls before custom controls.
9
+ - If multiple built-ins can work, choose the closest one and record the reason.
10
+ - If a built-in owner is discovered after a custom workaround, replace the workaround with the built-in.
11
+ - Custom controls are allowed only after documenting checked built-ins and why the closest one is insufficient.
12
+
13
+ ## Control Selection Inventory
14
+
15
+ Before writing schema controls, map every user-visible product setting or action:
16
+
17
+ ```txt
18
+ Product need:
19
+ Value model:
20
+ Candidate built-ins checked:
21
+ Best built-in:
22
+ Why:
23
+ Rejected alternatives:
24
+ Target:
25
+ Renderer/export mapping:
26
+ Acceptance coverage:
27
+ ```
28
+
29
+ This inventory can be in implementation notes, `starterControlSectionInventory`, or `docs/toolcraft/agent-worklog.md`, but the decision must exist before custom UI is introduced.
30
+
31
+ ## Exact Owners
32
+
33
+ - Use `gradient` for adjustable gradients, color transitions, gradient fills, stops, type, and angle. Do not replace it with two `color` controls.
34
+ - Use `fontPicker` for typography that includes font family, weight, size, text case, text color/opacity, letter spacing, or line height.
35
+ - Use `colorOpacity` when one product entity owns both color and opacity.
36
+ - Use `rangeSlider` or `rangeInput` for lower/upper bounds or from/to ranges.
37
+ - Use `curves` for editable tone, response, easing, remapping, opacity, depth, mask, or channel curves.
38
+ - Use `vector` only for stable manually-authored two-axis product parameters such as position, offset, direction, focus, anchor, light direction, white balance, color balance, chroma offset, or tone bias.
39
+ - Use `fileDrop` for source material uploads.
40
+ - Use `imagePicker` for choosing one visual option from a set.
41
+ - Use `palette` only for constrained design-token color choices with both family and shade.
42
+ - Use `actions` for local section commands that affect only the nearby entity.
43
+ - Use `collectionActions` for repeatable product entities whose actual item list can grow or shrink.
44
+ - Use `panelActions` for sticky final product actions such as export, copy, generate, apply, or download.
45
+
46
+ ## Compound Controls Are Atomic
47
+
48
+ - `fontPicker` owns font family, weight, size, text case, text color/opacity, letter spacing, and line height.
49
+ - `gradient` owns gradient type, angle, draggable stop track, and Stops list.
50
+ - RGB `curves`, `channelMixer`, `palette`, and `collectionActions` are also compound controls.
51
+ - Do not split owned fields into neighboring schema controls.
52
+ - If a needed owned field is missing from a built-in, extend the kit instead of composing a parallel control.
53
+
54
+ ## Collection Actions
55
+
56
+ - Use `collectionActions` when users edit the actual growable/shrinkable set: colors, glyphs, symbols, points, rules, variants, objects, style entries, or similar repeatable entities.
57
+ - Adding/removing items must update runtime state and product preview/export.
58
+ - Do not use a count slider plus hidden fixed item controls when the user needs to add or remove actual entities.
59
+ - The collection control shows the collection label on the left and remove/add icon buttons on the right.
60
+ - Homogeneous repeated items do not show visible per-item labels when the collection label already names the group.
61
+ - Plain color items may use equal 50% columns; color+opacity items stay stacked.
62
+
63
+ ## Actions
64
+
65
+ - Use schema `actions` for local section commands such as randomize palette, normalize weights, sort glyphs, clear selection, duplicate item, or reset current stop.
66
+ - If there is one `actions` button, the control label and button label must not be identical. Keep the button as the command verb and make the label a concise context.
67
+ - If an `actions` control has a visible label, the label is above the buttons.
68
+ - Actions render in 50% cells: one button uses the left half, two buttons fill one row, and larger groups continue in two columns.
69
+ - Do not stretch an odd trailing action full-width or center it.
70
+ - Keep final product actions in `panelActions`, keep timeline transport in the top timeline, and keep global reset in the controls panel header.
71
+
72
+ ## Vector Ownership
73
+
74
+ Use Vector only when the user is meant to manually author a stable two-axis product parameter.
75
+
76
+ Before adding Vector to an animated or interactive product, classify movement ownership:
77
+
78
+ - `direct-authored`: stable user-authored parameter such as light direction, focus, anchor, or object offset. This can be Vector.
79
+ - `timeline-driven`: movement comes from playback/keyframes. Use timeline, speed, duration, path, step, or amplitude controls instead.
80
+ - `keyboard/pointer-driven`: movement comes from user input on the canvas/app. Keep current position/direction in interaction state and expose only useful tuning controls.
81
+ - `simulation-owned`: movement comes from physics/procedural state. Keep current pose/velocity internal and expose high-level tuning controls.
82
+
83
+ Do not expose a pad for current animation state, keyboard movement, pointer movement, physics state, timeline phase, velocity, target pose, current pose, or simulated position/direction just because the internal value has `x` and `y`.
84
+
85
+ ## Custom Control Gate
86
+
87
+ - Custom controls are for product interactions that built-ins cannot represent.
88
+ - Custom controls must use Toolcraft primitives, tokens, spacing, typography, and action affordances.
89
+ - Custom controls must expose the minimum UI needed to understand and operate the product value.
90
+ - Every visible custom-control element must have a job: choose, order, preview, delete, upload, edit, or show useful status.
91
+ - Remove file names, helper text, and captions that do not help distinguish items or explain state.
92
+ - Do not make tiny item-level action buttons below kit comfort sizes.
93
+ - Do not recreate built-in controls, panels, toolbar, timeline, layers, canvas shell, or runtime surfaces.
@@ -0,0 +1,104 @@
1
+ # Controls Layout
2
+
3
+ Read this module before changing sections, labels, helper icons, inline rows, dividers, action layouts, or panel density.
4
+
5
+ ## Sections
6
+
7
+ - Build controls-panel sections from product entities and workflow stages, not component types.
8
+ - Before writing controls, export `starterControlSectionInventory`. Each product section declares title, product entity or workflow stage, targets, and grouping reason.
9
+ - Keep sections discrete. Two to seven product controls is the normal size.
10
+ - Split sections that grow past seven controls or mix several meanings.
11
+ - Do not reuse the same section title for multiple sections.
12
+ - Bad titles: `Controls`, `Settings`, `Options`, `Sliders`, `Inputs`, `Buttons`, `Color`, `Colors`.
13
+ - Good titles name the edited thing: `Background`, `Object`, `Token Pattern`, `Motion`, `Tone Mapping`, `Export`.
14
+ - Every app-authored controls-panel body section has a short meaningful visible title.
15
+ - Runtime `Setup` is the first visible headerless controls block. Sticky footer export actions render without a visible heading.
16
+
17
+ ## Dependency Cohesion
18
+
19
+ - A selector that controls mode, type, source, variant, or include state stays with the controls it gates when they share the same product entity.
20
+ - Use `visibleWhen` for inactive product branches so the panel shows only usable controls.
21
+ - Do not create a separate section that merely mirrors one selector option unless that branch is a genuinely separate product entity with its own workflow evidence.
22
+ - A section with no visible controls is hidden automatically.
23
+ - Do not use `disabled: true` or `disabledWhen` for generated product controls.
24
+
25
+ ## Section Headers And Reset
26
+
27
+ - Every visible section title renders through the standard 36px collapsible header row.
28
+ - Do not hand-build section headers in generated apps.
29
+ - Section expand/collapse uses the standard runtime height/opacity animation.
30
+ - Collapsed/expanded state persists as per-app runtime UI preference.
31
+ - Collapsed/expanded state is not undo/redo state, settings import/export state, or Reset controls state.
32
+ - Ordinary section headers expose the runtime section reset action before the collapse button.
33
+ - Section reset dispatches `controls.resetTargets` and restores only that section's targets to schema `defaultValue`.
34
+ - Runtime `Setup` is not collapsible and has no reset action. Sticky footer export sections are not collapsible.
35
+
36
+ ## Section Spacing
37
+
38
+ - Runtime `Setup` and ordinary body sections use 8px top spacing and 24px bottom spacing for control content.
39
+ - Sticky footer action sections keep their dedicated spacing.
40
+ - Do not add custom padding in generated apps to compensate for a local section issue. Fix the shared layout rule.
41
+
42
+ ## Dividers
43
+
44
+ - Full-width dividers belong only to panel sections.
45
+ - Large built-in compound controls inside a section render content-width internal dividers only when their parent section contains more than one visible control item.
46
+ - Keep 18px between each rendered internal divider and compound-control content.
47
+ - If the compound control is the first item in that section, render only its bottom internal divider and remove top internal padding.
48
+ - If the compound control is the last item, render only its top internal divider and remove bottom internal padding.
49
+ - If a section contains exactly one control, simple or compound, render only the parent section dividers.
50
+ - Do not add full-width borders inside a compound control.
51
+ - Do not put dividers only around an internal subsection such as Gradient Stops.
52
+ - Small compound fields such as `colorOpacity` and `rangeInput` stay inline fields without section dividers.
53
+
54
+ ## Labels And Help
55
+
56
+ - Keep labels short but semantically sufficient with the nearest visible section/group context.
57
+ - Put product-specific behavior help in schema `description`.
58
+ - Runtime shows the help icon only when `description` adds meaning beyond the label.
59
+ - Do not use descriptions that recap the label, such as `Adjusts Opacity`.
60
+ - Do not add helper icons to obvious homogeneous groups when the section title and label already explain the control.
61
+ - In toggle components, do not prefix labels with `Enable`; the switch already communicates on/off.
62
+ - When a section title supplies the context, remove repeated nouns from nearby labels. For example, in `Background`, the switch label is `Include`, not `Include background`.
63
+
64
+ ## Inline Rows
65
+
66
+ - Inline rows are allowed only when the controls are related, short, and preserve internal padding.
67
+ - Every 50/50 inline row uses the same horizontal column gap as paired select controls.
68
+ - Controls in a 50/50 row each occupy half the available content width.
69
+ - If any label or value clips, truncates, or loses internal padding, stack the controls and record the fit reason.
70
+ - Toggle-plus-parameter rows are allowed when the toggle enables/includes the same entity and the parameter is short. Keep the toggle label visible and set the non-toggle parameter `label: false`.
71
+ - If the non-toggle parameter label is necessary, stack the controls instead.
72
+ - Sliders and range sliders are full-width and do not sit in inline rows.
73
+ - Segmented controls are full-width and do not sit beside Switch, Color, Select, or another control.
74
+ - Standalone selects are full-width with label above dropdown. Use two-column select rows only for related short pairs such as export `Format` and `Resolution`.
75
+
76
+ ## Actions Layout
77
+
78
+ - If an `actions` control has a visible label, the label is above the buttons.
79
+ - One action button occupies the left 50% cell.
80
+ - Two action buttons fill one row.
81
+ - Larger groups continue in two columns.
82
+ - Odd trailing actions stay in the left 50% cell.
83
+ - Sticky footer `panelActions` use the sticky footer action layout, where a final odd action can span the full row.
84
+
85
+ ## Colors In Rows
86
+
87
+ - First identify the semantic entity the color belongs to: background, object, connector, glow, tone mapping, brand, export, or named product object.
88
+ - Keep color inside the entity section when it configures the same entity as nearby controls.
89
+ - Use a standalone color section only when color is the whole semantic section.
90
+ - Standalone color section titles must describe product role. Never create a section titled `Color` or `Colors`.
91
+ - Omit per-item labels such as `Color 1`, `Color 2`, or `Color 3` when colors only add variety to one shared palette/color bank.
92
+ - Keep visible labels when each color edits a distinct user-facing entity or role.
93
+ - Apply label visibility to the whole semantic color group; do not mix labeled and unlabeled items inside one bank.
94
+ - Multiple related plain colors render at most two per row.
95
+ - An odd trailing plain `color` keeps the same half-width footprint instead of stretching to full width.
96
+ - If any color has opacity, keep it stacked instead of placing it in a two-column row.
97
+ - `colorOpacity` owns color plus opacity for one entity and must not be split into color plus opacity slider/input.
98
+
99
+ ## Select And Segmented Fit
100
+
101
+ - Standalone `select` controls render stacked and full-width.
102
+ - Use compact two-column select layout only for related short pairs that tune one workflow or entity.
103
+ - Segmented controls are full-width compact choices with at most four options, no option label longer than nine characters, and no more than twenty-four total option-label characters.
104
+ - If segmented cells clip, collide, lose padding, or force labels into adjacent cells, shorten labels first. If compact labels still fail, use `select`.
@@ -0,0 +1,85 @@
1
+ # Media Upload
2
+
3
+ Read this module before changing image upload, file upload, source material import, media defaults, source images, sorting, or image transform actions.
4
+
5
+ ## FileDrop Ownership
6
+
7
+ - Use `fileDrop` for source material uploads in the controls panel.
8
+ - Do not place upload UI on the canvas.
9
+ - Do not build custom file lists, custom upload buttons, or custom sorting when `fileDrop` can represent the source set.
10
+ - Use `assetKind: "image"` for image-only source uploads.
11
+ - Use `assetKind: "file"` for arbitrary uploaded files.
12
+ - Image mode accepts images only by default.
13
+ - File mode accepts any file by default unless `accept` narrows extensions or MIME types.
14
+
15
+ ## Empty Source State
16
+
17
+ - When upload/import is part of the source-material flow, the empty product canvas stays neutral.
18
+ - Do not invent canvas placeholder artwork, CTA copy, helper text, fake sample output, decorative placeholder, or agent-made source preset before real content exists.
19
+ - A default procedural/reference source is allowed only when the prompt or reference explicitly defines it and the worklog records the evidence.
20
+
21
+ ## Image Uploads
22
+
23
+ - In single-layer apps, the runtime shows uploaded image preview and clear button in the file control.
24
+ - Clearing removes the attached source from the renderer and canvas.
25
+ - With exactly one uploaded image, image transform actions are visible immediately.
26
+ - With multiple uploaded images, users select a thumbnail first; until then transform actions are hidden.
27
+ - Once selected, transform actions apply only to that selected image.
28
+ - The FileDrop panel preview is not product canvas rendering. It keeps a stable preview frame across rotate/flip actions and contains the transformed bitmap inside that frame.
29
+ - Horizontal or vertical uploads must not be cropped by the control preview.
30
+
31
+ ## Image Transform Actions
32
+
33
+ - Runtime owns image transform actions directly below image uploaders.
34
+ - Actions render through the built-in `actions` control, not through a custom image action grid.
35
+ - Use one row of three compact action buttons:
36
+ - `90°` for rotate right;
37
+ - `Flip H`;
38
+ - `Flip V`.
39
+ - Keep a 6px vertical gap between uploader and action row.
40
+ - Product preview/export consumes `state.mediaAssets[].transform`.
41
+ - Do not keep separate product-only image transform state.
42
+
43
+ ## Multiple Uploads And Sorting
44
+
45
+ - Use `multiple: true` when the app needs several uploaded images or files as one source set.
46
+ - Multiple image uploads render as a sortable four-column thumbnail grid.
47
+ - The add-more tile is last.
48
+ - Per-image removal stays inside the file control.
49
+ - Dragging thumbnails updates runtime media order.
50
+ - Product renderers and exports consume runtime media order instead of keeping a separate product-only order.
51
+
52
+ ## File Uploads
53
+
54
+ - In file mode, uploaded files render as a sortable list with a paperclip icon, filename, remove button, and `--border/5` separators.
55
+ - Long filenames fade/truncate at the end instead of hard-clipping.
56
+ - The last item has no bottom separator.
57
+ - The add row is part of the file control and uses the same width and hover behavior as list rows.
58
+ - When an app contains both image and file uploaders, canvas drops route by asset kind:
59
+ - image files prefer visible image uploaders;
60
+ - non-image files prefer visible file uploaders;
61
+ - file uploaders may accept images only when no image uploader matches.
62
+ - Product renderers filter `state.mediaAssets` by `sourceTarget`.
63
+
64
+ ## Canvas Source Images
65
+
66
+ - Uploaded background/source images inside product canvases use `editable-output`.
67
+ - Uploaded source images do not change `canvas.size`.
68
+ - Setup canvas controls remain visible.
69
+ - Draw source/background images as cover/crop inside current canvas bounds without letterbox or aspect distortion.
70
+ - Scale proportionally until the current canvas bounds are fully covered, then crop overflow at canvas bounds.
71
+ - Reserve `intrinsic-media` for true media-viewer/source-native products where imported media natural dimensions intentionally own `canvas.size`, and prove that with acceptance coverage.
72
+
73
+ ## Default Assets
74
+
75
+ - Use `media.defaultAssets` when an app starts with predefined files, source images, masks, symbol sets, or background images.
76
+ - Each default asset sets `sourceTarget` to the matching `fileDrop` target.
77
+ - Runtime treats these as attached files: users see them in the uploader, can remove them, and Reset restores them.
78
+ - If removal, reorder, or transforms of predefined media should survive reload, add `"media"` to `persistence.include`.
79
+ - Do not mirror the file list into product `values`.
80
+ - Do not hard-code default source files inside `canvasContent` or the renderer.
81
+
82
+ ## Layers
83
+
84
+ - In multi-layer apps, deletion and visibility belong to the Layers panel.
85
+ - `fileDrop` stays an upload target.
@@ -0,0 +1,83 @@
1
+ # Performance
2
+
3
+ Read this module before changing renderer technique, animation, canvas, media, export, render scale, heavy controls, or performance tests.
4
+
5
+ ## Verification Triggers
6
+
7
+ Run a full performance checkpoint only when:
8
+
9
+ - the first working product app version exists;
10
+ - the user explicitly asks to optimize performance, fix lag, remove jank, speed up animation, stabilize drag/zoom, or otherwise complains about performance.
11
+
12
+ After the first working version, feature loops do not run the full performance suite by default. Renderer, canvas, animation, export, timeline, layers, `canvas.renderScale`, bug fixes, and performance-sensitive controls still need targeted functional/browser checks first, plus targeted performance scenarios only when they directly exercise the touched workload, viewport, or export path.
13
+
14
+ ## Verification Tiers
15
+
16
+ - Tier 0-1: targeted docs/typecheck/unit plus focused browser when visual.
17
+ - Tier 2: `pnpm verify:quick` plus relevant browser acceptance.
18
+ - Tier 3: `pnpm verify:quick`, targeted browser acceptance, and targeted performance scenarios for touched workload/viewport/export paths.
19
+ - Tier 4: `pnpm verify:final`; for the first working product version also run and pass a browser performance checkpoint with the current AI agent's controlled browser when available, using `pnpm verify:perf` only as fallback.
20
+
21
+ Record skipped full performance runs and reason in the verification note or worklog.
22
+
23
+ ## Workload Fixtures
24
+
25
+ - Performance scenarios declare `stressFixture` for the tested control value.
26
+ - Browser perf tests use `getToolcraftPerformanceStressValue(appPerformance, scenarioId)` so heavy-case tests cannot use toy values.
27
+ - When the tested control is not itself the whole heavy source, declare `workloadFixture` and apply it first.
28
+ - Numeric maximums, density, item counts, canvas/media size, and combined heavy states declare `loadProfile` with `hardLimit`, `smoothTarget`, and `smoothTargetRatio`.
29
+ - Try the hard limit first.
30
+ - Lower the guaranteed smooth target only in 10 percent steps with failed-measurement and optimization evidence.
31
+ - Ranges above `smoothTarget` are experimental, not silently guaranteed.
32
+
33
+ ## Media And Pixel Workloads
34
+
35
+ - Media import and image-processing workloads use realistic `kind: "media"` fixtures at least `1920x1080`-equivalent.
36
+ - Heavy upload/preview tests must cover realistic source dimensions such as 2K/4K when the app accepts images.
37
+ - Heavy pixel/media Canvas 2D must evaluate WebGL or WebGPU with measured evidence before staying on CPU.
38
+ - Do not stay on CPU for millions of per-pixel operations on the main thread unless measurement proves it remains responsive and alternatives were evaluated.
39
+
40
+ ## Render Scale
41
+
42
+ - Non-vector raster, Canvas 2D, WebGL, and WebGPU previews set `canvas.renderScale: true`.
43
+ - Runtime `Resolution scale` defaults to `2` and changes backing pixels without changing CSS/output size.
44
+ - Performance fixes must preserve selected render scale and visible output quality.
45
+ - Do not downsample, blur, stretch low-resolution backing pixels, or clamp render scale below the user's chosen value to pass budgets.
46
+
47
+ ## Slider Responsiveness
48
+
49
+ - Slider and range slider controls are live canvas controls.
50
+ - Dragging a thumb updates runtime state and product output while the drag is in progress.
51
+ - If live updates are slow, fix renderer path first:
52
+ - update uniforms or stable buffers;
53
+ - cache decoded media and expensive derived inputs;
54
+ - coalesce preview work to `requestAnimationFrame`;
55
+ - cancel stale async renders;
56
+ - move heavy work off React renders;
57
+ - change renderer strategy when measured evidence supports it.
58
+ - Only at an extreme measured ceiling may the app use degraded live preview or delayed heavy refinement; even then, immediate canvas feedback is required.
59
+
60
+ ## Renderer Pipeline Inventory
61
+
62
+ Custom renderer apps declare a typed `rendererPipeline`:
63
+
64
+ - render passes;
65
+ - cache keys;
66
+ - execution location;
67
+ - preview/export quality;
68
+ - interaction invalidation;
69
+ - control-to-pass mapping.
70
+
71
+ Every performance-sensitive control maps to the pass it invalidates.
72
+
73
+ ## Optimization Evidence
74
+
75
+ Optimization worklogs record:
76
+
77
+ - bottleneck diagnosis;
78
+ - renderer technique evaluated;
79
+ - fixtures used;
80
+ - measurements before and after;
81
+ - rejected alternatives;
82
+ - remaining risks;
83
+ - why quality was preserved.
@@ -0,0 +1,115 @@
1
+ # Reference Study
2
+
3
+ Read this module before porting, auditing, or rebuilding from a reference app, Figma file, video, GIF, screen recording, contact sheet, or extracted frames.
4
+
5
+ ## Reference Runtime Clone
6
+
7
+ When porting an existing app, use `transferMode: "reference-runtime-clone"` unless the user explicitly asks for redesign.
8
+
9
+ Preserve the reference runtime as source of truth:
10
+
11
+ - animation loop and time ownership;
12
+ - refs and mutable renderer state;
13
+ - particles, objects, connections, spawn cadence, and lifetime rules;
14
+ - pause/resume, restart, progress, export, and copy semantics;
15
+ - canvas sizing and media lifecycle;
16
+ - control-to-renderer mapping.
17
+
18
+ Toolcraft still owns the shell: schema, controls, canvas, panels, toolbar, file upload, sticky footer actions, and `canvasContent`.
19
+
20
+ Do not iframe the reference, replace the route with copied original UI, or rebuild the app as a different shell.
21
+
22
+ ## Feature Inventory
23
+
24
+ Before implementation, create `starterTransferMode.referenceFeatureInventory` from inspected reference source/runtime/UI.
25
+
26
+ Include every user-visible and output-affecting behavior:
27
+
28
+ - controls;
29
+ - modes;
30
+ - generated objects;
31
+ - renderer state;
32
+ - media import lifecycle;
33
+ - canvas sizing;
34
+ - layers and selection;
35
+ - timeline and transport;
36
+ - export/copy;
37
+ - persistence;
38
+ - randomization;
39
+ - reset behavior.
40
+
41
+ Each inventory item names the reference feature, cites source evidence, cites feature-level behavior evidence, describes original behavior, describes Toolcraft mapping, and points to an `acceptanceId` that proves the behavior.
42
+
43
+ Use `status: "ported"` when the behavior is carried over directly and `status: "toolcraft-native"` when Toolcraft owns the same behavior. If behavior is intentionally changed or omitted, mark it `status: "intentionally-changed"` and set `userApprovedChangeReason` with explicit user approval or redesign/change-request evidence.
44
+
45
+ Do not rely on the user to find missing reference functionality after delivery.
46
+
47
+ ## Reference Study Record
48
+
49
+ Declare `starterTransferMode.referenceStudy` and record:
50
+
51
+ - where the reference lives;
52
+ - which source/runtime files, routes, assets, and handlers were inspected;
53
+ - how the original was run or restored locally in the Toolcraft environment;
54
+ - which runtime/browser behaviors were checked.
55
+
56
+ Use:
57
+
58
+ - `status: "ran-original"` when the original can run as-is;
59
+ - `status: "restored-local"` when enough of the reference was reconstructed locally to observe behavior;
60
+ - `status: "source-inspection-only"` only when running or restoring is blocked. Set `sourceOnlyReason` to the concrete blocker and compensate with stronger source evidence and acceptance coverage.
61
+
62
+ Reference clones also declare `referenceTimeline` with mode `none`, `toolcraft-playback`, `toolcraft-keyframes`, or `custom-reference-timeline`. Custom reference transport such as state buttons, trim handles, selected ranges, or range export uses `referenceTimeline.mode: "custom-reference-timeline"` plus browser-backed `referenceTimelineCoverage`.
63
+
64
+ ## Figma Source
65
+
66
+ When a prompt provides a Figma URL, treat the Figma file as the design source of truth.
67
+
68
+ Required flow:
69
+
70
+ - Use Figma MCP/design context before implementation.
71
+ - Inspect the target node, layer tree, component instances, variants, text nodes, variables, styles, and assets.
72
+ - Recreate the design from the Figma structure and Toolcraft runtime/component contracts.
73
+ - Use screenshots only for final visual QA after reading the file structure.
74
+
75
+ Do not implement a Figma design by eye from an image, screenshot, exported PNG, or rough visual memory.
76
+
77
+ ## Video References
78
+
79
+ When the prompt provides a video, GIF, screen recording, contact sheet, or extracted-frame sequence, study it as behavior before implementation.
80
+
81
+ Write a Video Reference Study before coding. Record:
82
+
83
+ - `referenceLocation`;
84
+ - `extractionEvidence`;
85
+ - `storyboard` with timecoded frames, visible state, and behavior observations;
86
+ - `transitionAnalysis` with frame-to-frame deltas;
87
+ - `behaviorDecomposition`;
88
+ - `acceptanceMapping`.
89
+
90
+ The transition analysis explains what changes between frames: entities, anchors, state persistence, releases, retargeting, input, timeline state, and copied behavior.
91
+
92
+ Do not implement video references from a single screenshot, generic visual summary, or a few static style observations.
93
+
94
+ ## Acceptance Mapping
95
+
96
+ Every reference feature maps to acceptance coverage.
97
+
98
+ Each `acceptanceMapping` item points to a real acceptance row that proves the copied behavior with automated and browser coverage.
99
+
100
+ The port is incomplete until inventory and acceptance coverage prove that reference functionality was reviewed and transferred.
101
+
102
+ ## Worklog Evidence
103
+
104
+ `docs/toolcraft/agent-worklog.md` records:
105
+
106
+ - explicit reference inputs;
107
+ - source/reference checked;
108
+ - contract rules applied;
109
+ - decisions;
110
+ - alternatives rejected;
111
+ - state/output mapping;
112
+ - verification;
113
+ - risks or follow-ups.
114
+
115
+ If a worklog cites a video, GIF, screen recording, contact sheet, extracted frames, Figma URL, or reference app, it must include the corresponding study evidence.
@@ -0,0 +1,53 @@
1
+ # Runtime Boundary
2
+
3
+ Read this module before changing app assembly, routes, runtime surfaces, custom renderers, canvas output, panels, toolbar, timeline, layers, or controls.
4
+
5
+ ## Required Runtime Shell
6
+
7
+ - Build through `defineToolcraft`.
8
+ - Render through `ToolcraftApp`.
9
+ - Read `appSchema.assembly` before adding custom JSX. It lists the enabled runtime surfaces, capabilities, commands, and assumptions for the current app.
10
+ - Keep app state in the Toolcraft runtime schema and runtime commands.
11
+ - Keep route files thin: routes compose the schema-backed Toolcraft app and product renderers.
12
+ - Do not replace Toolcraft with copied reference UI, route-local panels, standalone forms, or hand-built editor chrome.
13
+
14
+ ## Allowed Extension Points
15
+
16
+ Use only these app-specific extension points unless you are intentionally changing the shared Toolcraft runtime:
17
+
18
+ - schema controls;
19
+ - schema `canvas`, `panels`, `toolbar`, `panelActions`, `persistence`, `media`, `assembly`, and transfer-mode metadata;
20
+ - `canvasContent` for product output only;
21
+ - `renderDefaultCanvasMedia={false}` only when a product renderer replaces the default media preview;
22
+ - `controlRenderers` only for true custom controls that pass the built-in fit check;
23
+ - `onPanelAction` for sticky product actions;
24
+ - runtime commands and hooks.
25
+
26
+ ## Forbidden Rebuilds
27
+
28
+ - Do not hand-compose `ToolcraftRoot`, `CanvasShell`, `ControlsPanel`, `LayersPanel`, `TimelinePanel`, `ToolbarPanel`, or panel containers in product routes.
29
+ - Do not render built-in control components such as `SliderControl`, `SelectControl`, `ColorControl`, `GradientControl`, `FontPickerControl`, `FileDropControl`, or `PanelActionsControl` directly in app code.
30
+ - Do not recreate controls, panels, toolbar, timeline, layers, canvas shell, drag handles, section headers, section reset, history, or runtime surfaces by hand.
31
+ - If a shared behavior is wrong, fix the shared runtime/template source and regenerate or sync the copied Toolcraft source instead of patching one exported app.
32
+
33
+ ## Canvas Boundary
34
+
35
+ - `canvasContent` contains product output only: WebGL, Canvas 2D, SVG, DOM product text, shaders, generated previews, export previews, or product editing handles.
36
+ - App UI, CTAs, upload prompts, helper copy, placeholder instructions, buttons, menus, forms, and settings do not belong in `canvasContent`.
37
+ - If upload/import is part of the source-material flow, the pre-content canvas stays neutral and runtime-backed. Upload affordance belongs in `fileDrop`.
38
+ - DOM product text rendered inside `canvasContent` must be marked with `data-toolcraft-product-output` or `data-toolcraft-product-text` so tests and performance fixtures can target product output instead of app chrome.
39
+ - Product editing handles must be textless overlays, write to runtime state, and stay out of export/copy output.
40
+ - Preserve the runtime canvas backing. Product renderers may draw their own product background, but must not hide, replace, or make the Toolcraft canvas shell/backing transparent.
41
+
42
+ ## State Boundary
43
+
44
+ - Bind every visible control to runtime schema state or a runtime command side effect.
45
+ - Use `defaultValue` for resettable controls.
46
+ - Use runtime commands such as `controls.reset`, `controls.resetTargets`, `media.import`, `media.delete`, `canvas.center`, `history.undo`, and `history.redo`.
47
+ - Do not keep final product settings in isolated local React state when they need reset, persistence, import/export, keyframes, browser acceptance, or product export.
48
+
49
+ ## Generated App Source Boundary
50
+
51
+ - Generated applications keep their public editing surface in `src/app/app-schema.ts` and app-specific files under `src/app` and `src/routes`.
52
+ - Do not edit `src/toolcraft` in one generated app unless the task is intentionally changing the local copied runtime. Prefer fixing the monorepo runtime and regenerating or syncing.
53
+ - Generated apps must not contain monorepo app/package folders, workspace-protocol dependencies, or workspace package imports.
@@ -0,0 +1,86 @@
1
+ # Setup, Background, And Export
2
+
3
+ Read this module before changing Setup, canvas sizing, background, image export, video export, sticky actions, render scale, or timeline visibility.
4
+
5
+ ## Runtime Setup
6
+
7
+ - Runtime `Setup` is always the first visible controls block in generated product apps.
8
+ - `Setup` is headerless, not collapsible, and has no section reset action.
9
+ - `Setup` always contains `Export Settings` and `Import Settings`.
10
+ - Do not implement settings import/export through `panelActions`, route-local file inputs, or app-authored controls.
11
+ - Do not gate settings import/export by app complexity.
12
+ - Product-output, exportable, shader, procedural, reference-clone, and uploaded-background/source apps use `editable-output`.
13
+ - With `editable-output`, Setup contains `Aspect ratio`, `Canvas width`, and `Canvas height` after settings transfer.
14
+ - App-authored sections must not declare runtime Setup targets: `runtime.settingsTransfer`, `canvas.aspectRatio`, `canvas.size.width`, `canvas.size.height`, `canvas.renderScale`, or `panels.timeline.extended`.
15
+
16
+ ## Canvas Size Defaults
17
+
18
+ - When no explicit product size is provided, the default canvas size is `16:9` / `1920x1080`.
19
+ - Runtime aspect presets apply canonical canvas sizes; `16:9` is `1920x1080`.
20
+ - A prompt-provided, reference, fixed-format, or base/default size is only the initial `canvas.size`.
21
+ - Fixed/reference/base dimensions are not reasons to hide `Aspect ratio`, `Canvas width`, or `Canvas height`.
22
+ - Manual Canvas width/height edits keep the typed dimension, keep the other dimension unchanged, switch Aspect ratio to Custom, and show the reduced current ratio in the custom ratio inputs.
23
+
24
+ ## Resolution Scale
25
+
26
+ - Non-vector raster, Canvas 2D, WebGL, and WebGPU previews set `canvas.renderScale: true`.
27
+ - Runtime then appends `Resolution scale` after canvas sizing.
28
+ - `Resolution scale` changes backing pixels from `1` to `2` without changing visible CSS size or product output dimensions.
29
+ - DOM/SVG/vector-native previews should not use render scale.
30
+ - Performance fixes must preserve the user's selected render scale. Do not pass budgets by silently downsampling, stretching a lower-resolution backing canvas, blurring output, or clamping render scale below the chosen value.
31
+
32
+ ## Timeline Setup Switch
33
+
34
+ - When `panels.timeline` is enabled, runtime appends a `Timeline` switch as the last Setup control.
35
+ - Off shows compact Play-only transport.
36
+ - On shows the extended timeline with scrubber, duration, loop, and keyframe UI.
37
+ - The switch controls runtime presentation only. It does not pause playback, change product values, remove keyframes, alter export, or reset with `Reset controls`.
38
+ - When `panels.timeline` is omitted, the Timeline switch must not appear.
39
+
40
+ ## Background
41
+
42
+ - Every product app exposes a required `Background` section directly before the first export settings section.
43
+ - The section contains one equal-width inline row:
44
+ - `export.includeBackground` as a switch labeled `Include`;
45
+ - the product background color control with `label: false`.
46
+ - Use a schema `color` target such as `appearance.background` or `scene.background`.
47
+ - Do not hardcode a configurable background in CSS, Canvas `fillStyle`, or WebGL clear color.
48
+ - Live preview calls `shouldIncludeToolcraftPreviewBackground(state)` and hides only the product-rendered background when Include is off.
49
+ - PNG export passes the Include value to the standard PNG export helper.
50
+ - Video export keeps the background even when Include is off.
51
+
52
+ ## Image Export
53
+
54
+ - Every app with `Export PNG` exposes a separate `Image Export` section.
55
+ - `Image Export` uses two `select` controls in one compact two-column inline row:
56
+ - `export.image.format`, default `png`, with baseline `PNG` and `JPG` options;
57
+ - `export.image.resolution`, default `4k`, with baseline `2K`, `4K`, and `8K` options.
58
+ - Still-output apps place `Image Export` directly above sticky footer actions.
59
+ - Animated apps with both image and video export place `Image Export` immediately before `Video Export`.
60
+ - PNG export calls `createToolcraftPngExportCanvas({ includeBackground, resolution, state, render })`.
61
+ - The selected `export.image.resolution` must produce real 2048/4096/8192px long-edge PNG output for 2K/4K/8K. Retina sizing is only the fallback for current/omitted resolution.
62
+
63
+ ## Video Export
64
+
65
+ - Animated product apps expose `Export Video` and `Export PNG`.
66
+ - Any app with `Export Video` must enable the top Toolcraft timeline.
67
+ - Animated apps expose a separate `Video Export` section directly above sticky footer export buttons, after `Image Export`.
68
+ - `Video Export` uses two `select` controls in one compact two-column inline row by default:
69
+ - `export.video.format`, default `mp4`, with baseline `MP4` and `WebM` options;
70
+ - `export.video.resolution`, default `current`, with baseline `Current` and `4K` options.
71
+ - Stack the pair only when labels or selected values would clip, and record that fit reason in the worklog.
72
+ - Use `MediaRecorder.isTypeSupported(...)` or an explicit encoder/transcoder capability check before choosing the actual MIME/container.
73
+ - `MOV` and `ProRes` are not baseline browser outputs; use them only with a custom encoder/transcoder plus acceptance and performance coverage.
74
+ - Use `getToolcraftVideoExportSize` for video dimensions. `current` uses current canvas/output size with even encoder-safe rounding; `4k` fits inside 3840x2160, preserves aspect ratio, and returns even dimensions.
75
+ - Offline rendered-frame video export must write timeline-based timestamps. `canvas.captureStream()` plus `MediaRecorder` records wall-clock time and cannot be the only duration mechanism for heavy renderers.
76
+ - Browser acceptance must load the exported blob as a video, wait for metadata, and compare `video.duration` with the runtime timeline duration.
77
+
78
+ ## Sticky Product Actions
79
+
80
+ - Product apps always expose export in sticky `panelActions`.
81
+ - Still products expose `Export PNG`.
82
+ - Animated products expose `Export Video` plus `Export PNG`.
83
+ - Clipboard copy is optional and never replaces export.
84
+ - Export PNG and Export Video use `icon: "upload-simple"` to match the runtime `Export Settings` action.
85
+ - Async export/download/copy/generate/apply handlers return the real Promise from `onPanelAction`. The runtime shows the sticky footer top accent indicator while the Promise is pending.
86
+ - Use `reportProgress(0..1)` for determinate progress when available.