@agent-native/core 0.80.9 → 0.80.10

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 (111) hide show
  1. package/corpus/README.md +1 -1
  2. package/corpus/core/CHANGELOG.md +7 -0
  3. package/corpus/core/package.json +1 -1
  4. package/corpus/core/src/cli/design-connect.ts +28 -2
  5. package/corpus/core/src/cli/skills.ts +45 -24
  6. package/corpus/templates/design/DESIGN-STUDIO-PLAN.md +717 -0
  7. package/corpus/templates/design/actions/add-breakpoint.ts +143 -0
  8. package/corpus/templates/design/actions/add-localhost-screens.ts +5 -0
  9. package/corpus/templates/design/actions/apply-a11y-fix.ts +317 -0
  10. package/corpus/templates/design/actions/apply-component-prop-edit.ts +433 -0
  11. package/corpus/templates/design/actions/apply-design-state.ts +200 -0
  12. package/corpus/templates/design/actions/apply-design-token-edit.ts +202 -0
  13. package/corpus/templates/design/actions/apply-motion-edit.ts +450 -0
  14. package/corpus/templates/design/actions/apply-shader-fill.ts +404 -0
  15. package/corpus/templates/design/actions/apply-visual-edit.ts +191 -5
  16. package/corpus/templates/design/actions/capture-design-state.ts +224 -0
  17. package/corpus/templates/design/actions/connect-builder-app.ts +162 -0
  18. package/corpus/templates/design/actions/create-component.ts +447 -0
  19. package/corpus/templates/design/actions/create-design-branch.ts +263 -0
  20. package/corpus/templates/design/actions/create-design-state.ts +162 -0
  21. package/corpus/templates/design/actions/delete-design-state.ts +55 -0
  22. package/corpus/templates/design/actions/deploy-design-preview.ts +275 -0
  23. package/corpus/templates/design/actions/get-component-details.ts +242 -0
  24. package/corpus/templates/design/actions/get-design-branch-diff.ts +362 -0
  25. package/corpus/templates/design/actions/get-design-review.ts +314 -0
  26. package/corpus/templates/design/actions/get-design-surface-index.ts +582 -0
  27. package/corpus/templates/design/actions/get-motion-timeline.ts +99 -0
  28. package/corpus/templates/design/actions/index-components.ts +258 -0
  29. package/corpus/templates/design/actions/index-design-tokens.ts +273 -0
  30. package/corpus/templates/design/actions/list-design-extensions.ts +309 -0
  31. package/corpus/templates/design/actions/list-design-source-capabilities.ts +153 -0
  32. package/corpus/templates/design/actions/list-design-states.ts +72 -0
  33. package/corpus/templates/design/actions/migrate-inline-design-to-app.ts +298 -0
  34. package/corpus/templates/design/actions/open-component-source.ts +237 -0
  35. package/corpus/templates/design/actions/preview-component-prop-edit.ts +254 -0
  36. package/corpus/templates/design/actions/preview-design-token-edit.ts +113 -0
  37. package/corpus/templates/design/actions/preview-shader-fill.ts +189 -0
  38. package/corpus/templates/design/actions/remove-breakpoint.ts +103 -0
  39. package/corpus/templates/design/actions/remove-motion-timeline.ts +196 -0
  40. package/corpus/templates/design/actions/run-design-audit.ts +421 -0
  41. package/corpus/templates/design/actions/run-design-extension-action.ts +284 -0
  42. package/corpus/templates/design/actions/set-active-breakpoint.ts +39 -0
  43. package/corpus/templates/design/app/components/design/DesignCanvas.tsx +1414 -71
  44. package/corpus/templates/design/app/components/design/DesignExtensionsPanel.tsx +632 -43
  45. package/corpus/templates/design/app/components/design/DrawOverlay.tsx +1 -1
  46. package/corpus/templates/design/app/components/design/EditPanel.tsx +1391 -52
  47. package/corpus/templates/design/app/components/design/LayersPanel.tsx +4 -3
  48. package/corpus/templates/design/app/components/design/LocalSourceEditBanner.tsx +157 -0
  49. package/corpus/templates/design/app/components/design/MotionDock.tsx +1062 -0
  50. package/corpus/templates/design/app/components/design/MultiScreenCanvas.tsx +1052 -98
  51. package/corpus/templates/design/app/components/design/ReviewPanel.tsx +759 -0
  52. package/corpus/templates/design/app/components/design/StatesPanel.tsx +579 -0
  53. package/corpus/templates/design/app/components/design/TokensPanel.tsx +573 -0
  54. package/corpus/templates/design/app/components/design/canvas-primitive-style.ts +241 -0
  55. package/corpus/templates/design/app/components/design/index.ts +16 -0
  56. package/corpus/templates/design/app/components/design/inspector/AutoLayoutMatrix.tsx +15 -6
  57. package/corpus/templates/design/app/components/design/inspector/DesignColorPicker.tsx +66 -3
  58. package/corpus/templates/design/app/components/design/inspector/InspectorAiActions.tsx +145 -0
  59. package/corpus/templates/design/app/components/design/inspector/SHADER_INTEGRATION.md +42 -12
  60. package/corpus/templates/design/app/components/visual-editor/DrawOverlay.tsx +1 -1
  61. package/corpus/templates/design/app/hooks/useAgentEditRequest.ts +131 -0
  62. package/corpus/templates/design/app/hooks/useDesignHotkeys.ts +3 -1
  63. package/corpus/templates/design/app/i18n/zh-TW.ts +31 -0
  64. package/corpus/templates/design/app/i18n-data.ts +269 -0
  65. package/corpus/templates/design/app/pages/DesignEditor.tsx +2478 -386
  66. package/corpus/templates/design/changelog/2026-06-29-added-a-review-panel-in-the-design-editor-s-inspector-with-a.md +6 -0
  67. package/corpus/templates/design/changelog/2026-06-29-copying-and-pasting-layers-no-longer-shows-success-notificat.md +6 -0
  68. package/corpus/templates/design/changelog/2026-06-29-device-presets-in-all-screens-view-resize-the-selected-previ.md +6 -0
  69. package/corpus/templates/design/changelog/2026-06-29-layer-and-canvas-drags-keep-the-layer-list-stable-while-chan.md +6 -0
  70. package/corpus/templates/design/changelog/2026-06-29-layer-moves-can-be-undone-and-redone-without-flashing-the-ca.md +6 -0
  71. package/corpus/templates/design/changelog/2026-06-29-screen-previews-use-a-single-blue-hover-border-in-all-screen.md +6 -0
  72. package/corpus/templates/design/changelog/2026-06-29-selected-containers-show-draggable-padding-and-gap-guides-on.md +6 -0
  73. package/corpus/templates/design/changelog/2026-06-29-the-design-editor-adds-a-studio-layer-with-tokens-respon.md +6 -0
  74. package/corpus/templates/design/changelog/2026-06-30-accessibility-findings-now-offer-a-one-click-fix.md +6 -0
  75. package/corpus/templates/design/changelog/2026-06-30-component-instances-now-have-editable-props-in-the-inspe.md +6 -0
  76. package/corpus/templates/design/changelog/2026-06-30-inspect-code-now-shows-the-elements-opening-tag-at-a-gla.md +6 -0
  77. package/corpus/templates/design/changelog/2026-06-30-shader-fill-presets-can-now-be-applied-to-an-element.md +6 -0
  78. package/corpus/templates/design/changelog/2026-06-30-the-motion-timeline-can-now-add-a-track-to-any-element-a.md +6 -0
  79. package/corpus/templates/design/changelog/2026-06-30-visual-editor-selection-layer-paint-and-drawing-controls-are-more-reliable.md +6 -0
  80. package/corpus/templates/design/e2e/helpers.ts +10 -4
  81. package/corpus/templates/design/server/db/schema.ts +123 -0
  82. package/corpus/templates/design/server/plugins/db.ts +90 -0
  83. package/corpus/templates/design/shared/builder-app.ts +297 -0
  84. package/corpus/templates/design/shared/capability-resolver.ts +123 -0
  85. package/corpus/templates/design/shared/capture-sanitize.ts +70 -0
  86. package/corpus/templates/design/shared/code-layer.ts +1016 -71
  87. package/corpus/templates/design/shared/component-model.ts +239 -0
  88. package/corpus/templates/design/shared/design-review.ts +275 -0
  89. package/corpus/templates/design/shared/design-source-capabilities.ts +286 -0
  90. package/corpus/templates/design/shared/design-state.ts +112 -0
  91. package/corpus/templates/design/shared/design-surface-index.ts +258 -0
  92. package/corpus/templates/design/shared/motion-compiler.ts +278 -0
  93. package/corpus/templates/design/shared/motion-timeline.ts +193 -0
  94. package/corpus/templates/design/shared/responsive-classes.ts +452 -0
  95. package/corpus/templates/design/shared/shader-fill.ts +323 -0
  96. package/corpus/templates/design/shared/source-mode.ts +245 -0
  97. package/corpus/templates/plan/app/components/plan/CanvasArea.tsx +6 -2
  98. package/corpus/templates/plan/changelog/2026-06-29-plan-canvases-open-without-an-initial-pan-and-zoom-flicker.md +6 -0
  99. package/dist/cli/design-connect.d.ts.map +1 -1
  100. package/dist/cli/design-connect.js +28 -2
  101. package/dist/cli/design-connect.js.map +1 -1
  102. package/dist/cli/skills.d.ts.map +1 -1
  103. package/dist/cli/skills.js +37 -21
  104. package/dist/cli/skills.js.map +1 -1
  105. package/dist/collab/routes.d.ts +1 -1
  106. package/dist/file-upload/actions/upload-image.d.ts +2 -2
  107. package/dist/notifications/routes.d.ts +2 -2
  108. package/dist/observability/routes.d.ts +7 -7
  109. package/dist/resources/handlers.d.ts +2 -2
  110. package/dist/server/transcribe-voice.d.ts +1 -1
  111. package/package.json +1 -1
@@ -0,0 +1,286 @@
1
+ /**
2
+ * Source capability vocabulary for the Design Studio.
3
+ *
4
+ * Every source (inline, localhost, fusion) advertises an explicit capability
5
+ * set. The UI gates controls on this — never on `sourceType` alone. The
6
+ * agent reads the same map and never claims a write the source cannot perform.
7
+ *
8
+ * Relation to `source-mode.ts`:
9
+ * - `DesignBridgeOperation` ("select" | "resolveNodeToFile" | "readFile" |
10
+ * "applyEdit" | "writeFile" | "captureSnapshot" | "captureState") describes
11
+ * the low-level bridge RPC surface.
12
+ * - `DesignCapabilityName` below is the *higher-level* capability vocabulary
13
+ * that UI panels and agent actions read. Several capabilities build on one
14
+ * or more bridge operations; others (e.g. `previewMotion`, `writeTokens`) are
15
+ * implemented above the bridge layer and have no direct bridge op.
16
+ * - `DesignBridgeOperationStatus` ("available" | "planned" | "disabled") is
17
+ * reused here as `CapabilityStatus`.
18
+ */
19
+
20
+ import type { DesignBridgeOperationStatus } from "./source-mode";
21
+
22
+ // ─── Capability name vocabulary ──────────────────────────────────────────────
23
+
24
+ /**
25
+ * The full set of named capabilities a design source can advertise.
26
+ *
27
+ * - **readFile / writeFile / applyEdit** — low-level file I/O; bridge-backed.
28
+ * - **resolveNodeToFile** — resolve a DOM node → source file + span.
29
+ * - **previewPatch / diffPatch** — preview or diff a proposed source edit
30
+ * without committing it.
31
+ * - **captureSnapshot / captureState** — snapshot the rendered iframe or
32
+ * capture running-app route+data state.
33
+ * - **indexComponents** — static AST or runtime parse of React/TS components.
34
+ * - **indexTokens** — parse CSS vars / Tailwind config / theme JSON for tokens.
35
+ * - **writeTokens** — write token changes back to the real source files.
36
+ * - **previewMotion** — scrub/play keyframe animations without writing to DB.
37
+ * - **writeMotion** — commit a motion timeline (managed `<style>` block or
38
+ * real CSS module, depending on tier).
39
+ * - **branch** — create/manage a Builder-hosted branch (fusion tier only).
40
+ * - **deployPreview** — deploy a branch preview URL.
41
+ * - **deploy** — merge/publish the branch to production.
42
+ */
43
+ export const DESIGN_CAPABILITY_NAMES = [
44
+ "readFile",
45
+ "writeFile",
46
+ "applyEdit",
47
+ "resolveNodeToFile",
48
+ "previewPatch",
49
+ "diffPatch",
50
+ "captureSnapshot",
51
+ "captureState",
52
+ "indexComponents",
53
+ "indexTokens",
54
+ "writeTokens",
55
+ "previewMotion",
56
+ "writeMotion",
57
+ "branch",
58
+ "deployPreview",
59
+ "deploy",
60
+ ] as const;
61
+
62
+ export type DesignCapabilityName = (typeof DESIGN_CAPABILITY_NAMES)[number];
63
+
64
+ // ─── Status ───────────────────────────────────────────────────────────────────
65
+
66
+ /**
67
+ * Mirrors `DesignBridgeOperationStatus` from `source-mode.ts` so callers can
68
+ * import a single type.
69
+ *
70
+ * - `available` — the source can perform this operation right now.
71
+ * - `planned` — the operation is understood but not yet hardened/enabled.
72
+ * - `unavailable` — not supported for this source type; show a migration CTA.
73
+ */
74
+ export type CapabilityStatus = DesignBridgeOperationStatus | "unavailable";
75
+
76
+ // ─── Per-capability entry ─────────────────────────────────────────────────────
77
+
78
+ export interface DesignSourceCapabilityEntry {
79
+ status: CapabilityStatus;
80
+ /** Optional human-readable explanation surfaced in CTA / tooltip copy. */
81
+ reason?: string;
82
+ }
83
+
84
+ // ─── Full capability map ──────────────────────────────────────────────────────
85
+
86
+ /**
87
+ * A map of every `DesignCapabilityName` to its status for a given source.
88
+ * Read by UI panels and server-side actions to decide whether to enable,
89
+ * preview-only, or show a migration CTA.
90
+ */
91
+ export type DesignSourceCapabilities = Record<
92
+ DesignCapabilityName,
93
+ DesignSourceCapabilityEntry
94
+ >;
95
+
96
+ // ─── Helper ───────────────────────────────────────────────────────────────────
97
+
98
+ /**
99
+ * Pure helper — returns `true` only when the named capability is `available`.
100
+ * All other statuses ("planned", "unavailable", "disabled") return `false`.
101
+ *
102
+ * Usage:
103
+ * ```ts
104
+ * if (hasCapability(caps, "writeTokens")) { ... }
105
+ * ```
106
+ */
107
+ export function hasCapability(
108
+ caps: DesignSourceCapabilities,
109
+ name: DesignCapabilityName,
110
+ ): boolean {
111
+ return caps[name]?.status === "available";
112
+ }
113
+
114
+ // ─── Factory helpers ──────────────────────────────────────────────────────────
115
+
116
+ /**
117
+ * Build a `DesignSourceCapabilityEntry` with status `available`.
118
+ * Convenience for constructing canonical capability maps.
119
+ */
120
+ export function available(reason?: string): DesignSourceCapabilityEntry {
121
+ return { status: "available", ...(reason !== undefined ? { reason } : {}) };
122
+ }
123
+
124
+ /**
125
+ * Build a `DesignSourceCapabilityEntry` with status `planned`.
126
+ * Used for capabilities that are understood by the bridge but not yet hardened.
127
+ */
128
+ export function planned(reason?: string): DesignSourceCapabilityEntry {
129
+ return { status: "planned", ...(reason !== undefined ? { reason } : {}) };
130
+ }
131
+
132
+ /**
133
+ * Build a `DesignSourceCapabilityEntry` with status `unavailable`.
134
+ * Used to signal a migration CTA to the UI.
135
+ */
136
+ export function unavailable(reason?: string): DesignSourceCapabilityEntry {
137
+ return {
138
+ status: "unavailable",
139
+ ...(reason !== undefined ? { reason } : {}),
140
+ };
141
+ }
142
+
143
+ // ─── Well-known default maps per source tier ──────────────────────────────────
144
+
145
+ /**
146
+ * Default capability map for **inline** (HTML/Alpine/SQL) designs.
147
+ *
148
+ * - CSS-var token edits and motion are available through the Tweaks loop and
149
+ * the managed `<style data-agent-native-motion>` block respectively.
150
+ * - File-level write ops (`readFile`, `writeFile`, `applyEdit`) are `planned`
151
+ * pending bridge write hardening.
152
+ * - Real-app-only capabilities (`indexComponents`, `writeTokens`, `branch`,
153
+ * `deploy*`) are `unavailable` and trigger the "Make it real" CTA.
154
+ */
155
+ export const INLINE_DEFAULT_CAPABILITIES: DesignSourceCapabilities = {
156
+ readFile: planned("Local file reads require bridge hardening"),
157
+ writeFile: planned("Local file writes require bridge hardening"),
158
+ applyEdit: planned("Source edits require bridge hardening"),
159
+ resolveNodeToFile: available(),
160
+ previewPatch: available(),
161
+ diffPatch: available(),
162
+ captureSnapshot: available(),
163
+ captureState: available(),
164
+ indexComponents: unavailable("Connect Builder to index real components"),
165
+ indexTokens: available(),
166
+ writeTokens: unavailable("Token source write-back requires a real app"),
167
+ previewMotion: available(),
168
+ writeMotion: available(),
169
+ branch: unavailable("Branching requires a connected Builder app"),
170
+ deployPreview: unavailable("Deploy previews require a connected Builder app"),
171
+ deploy: unavailable("Deploy requires a connected Builder app"),
172
+ };
173
+
174
+ /**
175
+ * Default capability map for **localhost** designs.
176
+ *
177
+ * Starts read-only / preview-only; write ops become `available` after bridge
178
+ * hardening. Real-app features (`indexComponents`, `writeTokens`, etc.) are
179
+ * `planned` and light up once the bridge proves capability.
180
+ */
181
+ export const LOCALHOST_DEFAULT_CAPABILITIES: DesignSourceCapabilities = {
182
+ readFile: planned("Local file reads require the next bridge hardening pass"),
183
+ writeFile: planned(
184
+ "Local file writes require the next bridge hardening pass",
185
+ ),
186
+ applyEdit: planned("Source edits require the next bridge hardening pass"),
187
+ resolveNodeToFile: available(),
188
+ previewPatch: available(),
189
+ diffPatch: available(),
190
+ captureSnapshot: available(),
191
+ captureState: available(),
192
+ indexComponents: planned("Component indexing lands with bridge hardening"),
193
+ indexTokens: available(),
194
+ writeTokens: planned("Token write-back lands with bridge hardening"),
195
+ previewMotion: available(),
196
+ writeMotion: available(),
197
+ branch: unavailable("Branching requires a connected Builder app"),
198
+ deployPreview: unavailable("Deploy previews require a connected Builder app"),
199
+ deploy: unavailable("Deploy requires a connected Builder app"),
200
+ };
201
+
202
+ /**
203
+ * Default capability map for a **fusion** (Builder-hosted) design where Builder
204
+ * is **not yet connected** (no credentials / no branch project configured).
205
+ *
206
+ * Preview-only: the canvas can render and snapshot the remote app but no
207
+ * real-app operations (`indexComponents`, `branch`, `deployPreview`, `deploy`,
208
+ * write ops) are available until Builder credentials are confirmed.
209
+ *
210
+ * Use `FUSION_CONNECTED_CAPABILITIES` once `resolveHasCompleteBuilderConnection`
211
+ * returns `true` and a branch project is configured.
212
+ */
213
+ export const FUSION_DISCONNECTED_CAPABILITIES: DesignSourceCapabilities = {
214
+ readFile: planned("Connect Builder to enable file reads on fusion sources"),
215
+ writeFile: unavailable("Connect Builder to enable source writes"),
216
+ applyEdit: unavailable("Connect Builder to enable source edits"),
217
+ resolveNodeToFile: available(),
218
+ previewPatch: available(),
219
+ diffPatch: available(),
220
+ captureSnapshot: available(),
221
+ captureState: available(),
222
+ indexComponents: unavailable("Connect Builder to index real components"),
223
+ indexTokens: available(),
224
+ writeTokens: unavailable("Connect Builder to enable token write-back"),
225
+ previewMotion: available(),
226
+ writeMotion: planned(
227
+ "Motion write-back to real source requires bridge hardening",
228
+ ),
229
+ branch: unavailable("Connect Builder to create branches"),
230
+ deployPreview: unavailable("Connect Builder to deploy previews"),
231
+ deploy: unavailable("Connect Builder to deploy"),
232
+ };
233
+
234
+ /**
235
+ * Capability map for a **fusion** (Builder-hosted) design where Builder **is
236
+ * connected** (credentials present + branch project configured).
237
+ *
238
+ * Per DESIGN-STUDIO-PLAN.md §5:
239
+ * - `indexComponents`, `branch`, `deployPreview`, `deploy` are **available**.
240
+ * - Source writes (`writeFile`, `writeTokens`, `writeMotion` to real source)
241
+ * remain **planned** until bridge hardening is complete.
242
+ * - `readFile`, `applyEdit`, `previewPatch`, `diffPatch`, `captureSnapshot`,
243
+ * `captureState`, `indexTokens`, and `previewMotion` are **available**.
244
+ */
245
+ export const FUSION_CONNECTED_CAPABILITIES: DesignSourceCapabilities = {
246
+ readFile: available(),
247
+ writeFile: planned(
248
+ "Source file writes remain planned until bridge hardening",
249
+ ),
250
+ applyEdit: planned("Source edits remain planned until bridge hardening"),
251
+ resolveNodeToFile: available(),
252
+ previewPatch: available(),
253
+ diffPatch: available(),
254
+ captureSnapshot: available(),
255
+ captureState: available(),
256
+ indexComponents: available(),
257
+ indexTokens: available(),
258
+ writeTokens: planned(
259
+ "Token write-back remains planned until bridge hardening",
260
+ ),
261
+ previewMotion: available(),
262
+ writeMotion: planned(
263
+ "Motion write-back to real source remains planned until bridge hardening",
264
+ ),
265
+ branch: available(),
266
+ deployPreview: available(),
267
+ deploy: available(),
268
+ };
269
+
270
+ /**
271
+ * Default capability map for **fusion** (Builder-hosted) designs.
272
+ *
273
+ * This is the **conservative default** for when connection status is unknown.
274
+ * It is equivalent to `FUSION_DISCONNECTED_CAPABILITIES` — preview-only with
275
+ * no real-app write operations available.
276
+ *
277
+ * Callers that know the Builder connection is active should use
278
+ * `FUSION_CONNECTED_CAPABILITIES` (or call `resolveFusionCapabilities(true)`
279
+ * from `capability-resolver.ts`) to get the fuller capability set.
280
+ *
281
+ * @deprecated Prefer `FUSION_DISCONNECTED_CAPABILITIES` or
282
+ * `FUSION_CONNECTED_CAPABILITIES` for clarity. This alias is kept for
283
+ * backward compatibility with callers that import the default map.
284
+ */
285
+ export const FUSION_DEFAULT_CAPABILITIES: DesignSourceCapabilities =
286
+ FUSION_DISCONNECTED_CAPABILITIES;
@@ -0,0 +1,112 @@
1
+ /**
2
+ * Design state, breakpoint, and capture types for the Design Studio
3
+ * states/responsive panel (§6.4 + §4.3).
4
+ *
5
+ * States and breakpoints are orthogonal axes: any state can be viewed at any
6
+ * breakpoint. Both persist in application state and are agent-visible via
7
+ * `view-screen`.
8
+ */
9
+
10
+ // ---------------------------------------------------------------------------
11
+ // Breakpoints
12
+ // ---------------------------------------------------------------------------
13
+
14
+ /**
15
+ * Tailwind responsive prefix for a breakpoint frame.
16
+ * `"base"` maps to unprefixed classes (the mobile-first default).
17
+ */
18
+ export type TailwindBreakpointPrefix =
19
+ | "base"
20
+ | "sm"
21
+ | "md"
22
+ | "lg"
23
+ | "xl"
24
+ | "2xl";
25
+
26
+ export interface BreakpointDefinition {
27
+ id: string;
28
+ /** Human-readable label shown in the canvas header (e.g. "Mobile", "Tablet"). */
29
+ label: string;
30
+ /** Frame width in pixels (e.g. 390, 768, 1280). */
31
+ widthPx: number;
32
+ /**
33
+ * The Tailwind responsive prefix this frame is the edit scope for.
34
+ * Editing a layer in this frame writes classes with this prefix
35
+ * (or unprefixed classes when `"base"`).
36
+ */
37
+ prefix: TailwindBreakpointPrefix;
38
+ }
39
+
40
+ /**
41
+ * The ordered set of breakpoint frames rendered side-by-side for a screen.
42
+ * Frames are ordered Mobile → Tablet → Desktop (left to right).
43
+ */
44
+ export interface BreakpointSet {
45
+ id: string;
46
+ /** The breakpoints in display order. */
47
+ breakpoints: BreakpointDefinition[];
48
+ }
49
+
50
+ // ---------------------------------------------------------------------------
51
+ // Design states
52
+ // ---------------------------------------------------------------------------
53
+
54
+ export const DESIGN_STATE_KINDS = ["state", "fixture", "capture"] as const;
55
+
56
+ export type DesignStateKind = (typeof DESIGN_STATE_KINDS)[number];
57
+
58
+ export const DESIGN_STATE_BREAKPOINTS = [
59
+ "auto",
60
+ "desktop",
61
+ "tablet",
62
+ "mobile",
63
+ ] as const;
64
+
65
+ export type DesignStateBreakpoint = (typeof DESIGN_STATE_BREAKPOINTS)[number];
66
+
67
+ /**
68
+ * A named design state, data fixture, or live capture scoped to a design.
69
+ *
70
+ * - `"state"` — an alternate DOM/Alpine `x-data` snapshot (e.g. logged-out,
71
+ * empty, loading, error).
72
+ * - `"fixture"` — a real-app data fixture with route + props seeded from
73
+ * `fixtureData`.
74
+ * - `"capture"` — a live capture of the running app's route + data taken via
75
+ * the bridge `captureState` operation.
76
+ */
77
+ export interface DesignState {
78
+ id: string;
79
+ designId: string;
80
+ /**
81
+ * Opaque source reference (fileId for inline, routeId for localhost/fusion).
82
+ * `null` when scoped to the entire design.
83
+ */
84
+ sourceRef: string | null;
85
+ name: string;
86
+ kind: DesignStateKind;
87
+ /**
88
+ * Which breakpoint context this state was captured or is intended for.
89
+ * `"auto"` means it applies at all breakpoints.
90
+ */
91
+ breakpoint: DesignStateBreakpoint;
92
+ /** App route path at the time of capture or fixture definition (e.g. "/dashboard"). */
93
+ route?: string;
94
+ /**
95
+ * Structured fixture data (props, query params, mock API responses) for
96
+ * `"fixture"` and `"capture"` states. Real-app only; `null` for inline states.
97
+ */
98
+ fixtureData: Record<string, unknown> | null;
99
+ /**
100
+ * Serialised DOM/Alpine snapshot for `"state"` and `"capture"` states.
101
+ * For inline designs this is the alternate `x-data` / HTML payload.
102
+ * For real apps this is the captured component tree or route data.
103
+ */
104
+ captureData: Record<string, unknown> | null;
105
+ /**
106
+ * Reference to the preview snapshot (image URL or snapshotRef id) produced
107
+ * when this state was captured.
108
+ */
109
+ previewRef: string | null;
110
+ createdAt: string;
111
+ updatedAt: string;
112
+ }
@@ -0,0 +1,258 @@
1
+ /**
2
+ * Design Surface Index — normalized read-model types.
3
+ *
4
+ * A lazy, queryable surface that UI panels and agent actions read to understand
5
+ * what is present in a design: source metadata, selectable nodes, components,
6
+ * tokens, motion timelines, design states, and accessibility review results.
7
+ *
8
+ * **Types only — no DB, no runtime code.** The index is grown lazily from the
9
+ * existing `code-layer.ts` projection and per-feature needs. A persistent
10
+ * cache table (`design_surface_indexes`) is added only when re-parsing proves
11
+ * to be a real performance problem.
12
+ *
13
+ * See `DESIGN-STUDIO-PLAN.md` §4.2 for rationale.
14
+ */
15
+
16
+ import type { CodeLayerNode } from "./code-layer";
17
+ import type { DesignCapabilityName } from "./design-source-capabilities";
18
+ import type { DesignSourceType } from "./source-mode";
19
+
20
+ // ─── Source metadata ──────────────────────────────────────────────────────────
21
+
22
+ /** Lightweight description of the source backing this index snapshot. */
23
+ export interface DesignSurfaceSourceMeta {
24
+ sourceType: DesignSourceType;
25
+ /** design_files.id for inline; route id or artboard id for real-app sources. */
26
+ sourceRef: string;
27
+ /**
28
+ * Hash of the source content at index time (file content hash for inline;
29
+ * git ref or build hash for real-app sources). Used to detect staleness.
30
+ */
31
+ contentHash?: string;
32
+ /** ISO-8601 timestamp when this index snapshot was built. */
33
+ indexedAt: string;
34
+ /** The capabilities that were `available` when this snapshot was taken. */
35
+ availableCapabilities: DesignCapabilityName[];
36
+ }
37
+
38
+ // ─── Node summary ─────────────────────────────────────────────────────────────
39
+
40
+ /**
41
+ * A lightweight node summary derived from `CodeLayerNode`. The full
42
+ * `CodeLayerProjection` is the authoritative source; this slice carries what
43
+ * panel headers and the agent's `view-screen` response need at a glance.
44
+ */
45
+ export interface DesignSurfaceNode {
46
+ /** Stable `data-agent-native-node-id` value. */
47
+ nodeId: string;
48
+ /** Resolved human-readable layer name. */
49
+ layerName: string;
50
+ tag: string;
51
+ selector: string;
52
+ parentNodeId?: string;
53
+ childNodeIds: string[];
54
+ /** Whether this node is currently the edit-scope selection. */
55
+ selected?: boolean;
56
+ }
57
+
58
+ // ─── Component entries ────────────────────────────────────────────────────────
59
+
60
+ /**
61
+ * Kind of component: an annotated Alpine region or a fully-indexed real
62
+ * React/TS component.
63
+ */
64
+ export type DesignComponentKind = "alpine-annotation" | "react-component";
65
+
66
+ export interface DesignSurfaceComponentProp {
67
+ name: string;
68
+ type: string;
69
+ required: boolean;
70
+ defaultValue?: unknown;
71
+ /** When sourced from `cva` or `tailwind-variants`, the allowed variant keys. */
72
+ enumValues?: string[];
73
+ }
74
+
75
+ export interface DesignSurfaceComponent {
76
+ /** Stable component id (matches `component_index.id` when persisted). */
77
+ componentId: string;
78
+ kind: DesignComponentKind;
79
+ name: string;
80
+ /** Source file path relative to the project root (real-app only). */
81
+ filePath?: string;
82
+ /** Named export identifier in the source file (real-app only). */
83
+ exportName?: string;
84
+ props?: DesignSurfaceComponentProp[];
85
+ /** Variant names from `cva` / `tailwind-variants` (real-app only). */
86
+ variants?: Record<string, string[]>;
87
+ /** `data-agent-native-node-id` values of DOM instances of this component. */
88
+ instanceNodeIds: string[];
89
+ }
90
+
91
+ // ─── Token entries ────────────────────────────────────────────────────────────
92
+
93
+ export type DesignTokenKind =
94
+ | "color"
95
+ | "typography"
96
+ | "spacing"
97
+ | "radius"
98
+ | "shadow"
99
+ | "motion"
100
+ | "other";
101
+
102
+ export interface DesignSurfaceToken {
103
+ /** Stable token id — typically the CSS custom-property name, e.g. `--color-primary`. */
104
+ tokenId: string;
105
+ kind: DesignTokenKind;
106
+ /** Friendly display label, e.g. "Primary". */
107
+ label: string;
108
+ /** CSS custom-property name, e.g. `--color-primary`. */
109
+ cssVar: string;
110
+ /** Resolved value at index time, e.g. `#3b82f6`. */
111
+ resolvedValue: string;
112
+ /**
113
+ * Source file where this token is defined (real-app only; `globals.css`,
114
+ * `tailwind.config.ts`, etc.).
115
+ */
116
+ sourceFile?: string;
117
+ }
118
+
119
+ // ─── Motion timeline summary ──────────────────────────────────────────────────
120
+
121
+ export interface DesignSurfaceMotionTrack {
122
+ /** `data-agent-native-node-id` of the animated element. */
123
+ targetNodeId: string;
124
+ /** CSS property being animated, e.g. `opacity`, `transform`. */
125
+ property: string;
126
+ keyframeCount: number;
127
+ }
128
+
129
+ export interface DesignSurfaceMotionTimeline {
130
+ /** Matches `motion_timeline.id` when persisted. */
131
+ timelineId: string;
132
+ /** `motion_timeline.source_ref` — the file or screen this timeline targets. */
133
+ sourceRef: string;
134
+ durationMs: number;
135
+ tracks: DesignSurfaceMotionTrack[];
136
+ /** SHA of the compiled CSS, used to detect drift from the JSON tracks. */
137
+ compiledHash?: string;
138
+ }
139
+
140
+ // ─── Design state / capture entries ──────────────────────────────────────────
141
+
142
+ export type DesignStateKind = "state" | "fixture" | "capture";
143
+
144
+ export type DesignBreakpoint = "auto" | "desktop" | "tablet" | "mobile";
145
+
146
+ export interface DesignSurfaceState {
147
+ /** Matches `design_state.id` when persisted. */
148
+ stateId: string;
149
+ kind: DesignStateKind;
150
+ name: string;
151
+ breakpoint: DesignBreakpoint;
152
+ /** Route path snapped for this state (real-app captures only). */
153
+ route?: string;
154
+ /** Whether fixture/capture data is present. */
155
+ hasData: boolean;
156
+ /** URL of a preview screenshot, if captured. */
157
+ previewRef?: string;
158
+ }
159
+
160
+ // ─── Accessibility / review summary ──────────────────────────────────────────
161
+
162
+ export type DesignReviewFindingSeverity = "error" | "warning" | "info";
163
+
164
+ export type DesignReviewFindingKind =
165
+ | "contrast"
166
+ | "tap-target"
167
+ | "focus-visibility"
168
+ | "missing-alt"
169
+ | "missing-label"
170
+ | "missing-role"
171
+ | "reduced-motion"
172
+ | "other";
173
+
174
+ export interface DesignReviewFinding {
175
+ findingId: string;
176
+ severity: DesignReviewFindingSeverity;
177
+ kind: DesignReviewFindingKind;
178
+ message: string;
179
+ /** `data-agent-native-node-id` of the affected element, when resolvable. */
180
+ nodeId?: string;
181
+ /** CSS selector fallback when `nodeId` is unavailable. */
182
+ selector?: string;
183
+ /** Whether a `apply-a11y-fix` action is available (real-app only). */
184
+ fixAvailable: boolean;
185
+ }
186
+
187
+ export interface DesignSurfaceReview {
188
+ /**
189
+ * Matches `design_review_snapshot.id` when persisted. `null` means the
190
+ * review has not been run yet for this index snapshot.
191
+ */
192
+ snapshotId: string | null;
193
+ /**
194
+ * ISO-8601 timestamp of the last audit run, or `null` if not yet run.
195
+ */
196
+ auditedAt: string | null;
197
+ findings: DesignReviewFinding[];
198
+ /** `design_versions.id` used as the base for the visual diff. */
199
+ baseVersionId?: string;
200
+ /** `design_versions.id` used as the compare target for the visual diff. */
201
+ compareVersionId?: string;
202
+ }
203
+
204
+ // ─── Top-level index ──────────────────────────────────────────────────────────
205
+
206
+ /**
207
+ * The normalized, queryable read-model for a single design source/screen.
208
+ *
209
+ * Both UI panels and agent actions read from this shape. Each section is
210
+ * optional so callers can build the index lazily — a panel that only needs
211
+ * tokens doesn't have to wait for component indexing to finish.
212
+ */
213
+ export interface DesignSurfaceIndex {
214
+ /** Version sentinel — increment when the shape changes in a breaking way. */
215
+ version: 1;
216
+
217
+ /** Metadata about the source and when this snapshot was built. */
218
+ source: DesignSurfaceSourceMeta;
219
+
220
+ /**
221
+ * Flat node list derived from the `CodeLayerProjection`. Keyed by `nodeId`
222
+ * for O(1) lookup from UI selection events.
223
+ */
224
+ nodes?: Record<string, DesignSurfaceNode>;
225
+
226
+ /**
227
+ * Component entries found in this source.
228
+ * - Alpine designs: `alpine-annotation` entries from `data-agent-native-component`.
229
+ * - Real apps: `react-component` entries from the component index action.
230
+ */
231
+ components?: DesignSurfaceComponent[];
232
+
233
+ /**
234
+ * Design token entries parsed from CSS vars / Tailwind config / theme JSON.
235
+ * Available for both inline and real-app sources.
236
+ */
237
+ tokens?: DesignSurfaceToken[];
238
+
239
+ /**
240
+ * Motion timelines keyed by `timelineId`. Both tiers support the managed
241
+ * `<style data-agent-native-motion>` block; real apps additionally support
242
+ * CSS module write-back.
243
+ */
244
+ motion?: Record<string, DesignSurfaceMotionTimeline>;
245
+
246
+ /**
247
+ * Design states, fixtures, and real-app captures.
248
+ * Breakpoints and states are orthogonal axes — any state can be viewed at
249
+ * any breakpoint.
250
+ */
251
+ states?: DesignSurfaceState[];
252
+
253
+ /**
254
+ * Most-recent accessibility audit results, or `null` if `run-design-audit`
255
+ * has not been called yet.
256
+ */
257
+ review?: DesignSurfaceReview;
258
+ }