@agent-native/core 0.80.9 → 0.80.11

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 (148) hide show
  1. package/corpus/README.md +1 -1
  2. package/corpus/core/CHANGELOG.md +13 -0
  3. package/corpus/core/package.json +1 -1
  4. package/corpus/core/src/agent/production-agent.ts +108 -15
  5. package/corpus/core/src/cli/design-connect.ts +28 -2
  6. package/corpus/core/src/cli/skills.ts +45 -24
  7. package/corpus/core/src/client/AssistantChat.tsx +123 -26
  8. package/corpus/core/src/client/sse-event-processor.ts +9 -0
  9. package/corpus/templates/assets/.agents/skills/image-generation/SKILL.md +9 -2
  10. package/corpus/templates/assets/AGENTS.md +4 -0
  11. package/corpus/templates/assets/actions/_tool-activity.ts +46 -0
  12. package/corpus/templates/assets/actions/generate-image-batch.ts +26 -5
  13. package/corpus/templates/assets/actions/generate-image.ts +118 -67
  14. package/corpus/templates/assets/actions/list-draft-assets.ts +50 -0
  15. package/corpus/templates/assets/actions/rerun-generation-run.ts +52 -31
  16. package/corpus/templates/assets/app/components/create/RecentDraftsSection.tsx +100 -0
  17. package/corpus/templates/assets/app/i18n/zh-TW.ts +7 -0
  18. package/corpus/templates/assets/app/i18n-data.ts +61 -0
  19. package/corpus/templates/assets/app/routes/_index.tsx +4 -0
  20. package/corpus/templates/assets/app/routes/library.tsx +145 -38
  21. package/corpus/templates/assets/changelog/2026-06-29-image-generation-can-now-render-requested-text-and-respect-b.md +6 -0
  22. package/corpus/templates/assets/changelog/2026-06-30-image-generation-no-longer-looks-stuck-while-the-provider-is-still-working.md +6 -0
  23. package/corpus/templates/assets/changelog/2026-06-30-tagged-presets-now-control-the-image-aspect-ratio.md +6 -0
  24. package/corpus/templates/assets/server/lib/generation.ts +135 -11
  25. package/corpus/templates/assets/shared/api.ts +4 -0
  26. package/corpus/templates/clips/actions/list-ai-requests.ts +60 -0
  27. package/corpus/templates/clips/app/hooks/use-auto-title.ts +24 -25
  28. package/corpus/templates/design/DESIGN-STUDIO-PLAN.md +717 -0
  29. package/corpus/templates/design/actions/add-breakpoint.ts +143 -0
  30. package/corpus/templates/design/actions/add-localhost-screens.ts +5 -0
  31. package/corpus/templates/design/actions/apply-a11y-fix.ts +317 -0
  32. package/corpus/templates/design/actions/apply-component-prop-edit.ts +441 -0
  33. package/corpus/templates/design/actions/apply-design-state.ts +213 -0
  34. package/corpus/templates/design/actions/apply-design-token-edit.ts +202 -0
  35. package/corpus/templates/design/actions/apply-motion-edit.ts +413 -0
  36. package/corpus/templates/design/actions/apply-shader-fill.ts +404 -0
  37. package/corpus/templates/design/actions/apply-visual-edit.ts +191 -5
  38. package/corpus/templates/design/actions/capture-design-state.ts +224 -0
  39. package/corpus/templates/design/actions/connect-builder-app.ts +162 -0
  40. package/corpus/templates/design/actions/create-component.ts +447 -0
  41. package/corpus/templates/design/actions/create-design-branch.ts +263 -0
  42. package/corpus/templates/design/actions/create-design-state.ts +162 -0
  43. package/corpus/templates/design/actions/delete-design-state.ts +55 -0
  44. package/corpus/templates/design/actions/delete-design.ts +20 -0
  45. package/corpus/templates/design/actions/deploy-design-preview.ts +275 -0
  46. package/corpus/templates/design/actions/get-component-details.ts +251 -0
  47. package/corpus/templates/design/actions/get-design-branch-diff.ts +362 -0
  48. package/corpus/templates/design/actions/get-design-review.ts +314 -0
  49. package/corpus/templates/design/actions/get-design-surface-index.ts +582 -0
  50. package/corpus/templates/design/actions/get-motion-timeline.ts +99 -0
  51. package/corpus/templates/design/actions/index-components.ts +258 -0
  52. package/corpus/templates/design/actions/index-design-tokens.ts +277 -0
  53. package/corpus/templates/design/actions/list-design-extensions.ts +309 -0
  54. package/corpus/templates/design/actions/list-design-source-capabilities.ts +153 -0
  55. package/corpus/templates/design/actions/list-design-states.ts +90 -0
  56. package/corpus/templates/design/actions/migrate-inline-design-to-app.ts +298 -0
  57. package/corpus/templates/design/actions/open-component-source.ts +242 -0
  58. package/corpus/templates/design/actions/preview-component-prop-edit.ts +260 -0
  59. package/corpus/templates/design/actions/preview-design-token-edit.ts +113 -0
  60. package/corpus/templates/design/actions/preview-shader-fill.ts +187 -0
  61. package/corpus/templates/design/actions/remove-breakpoint.ts +103 -0
  62. package/corpus/templates/design/actions/remove-motion-timeline.ts +196 -0
  63. package/corpus/templates/design/actions/run-design-audit.ts +436 -0
  64. package/corpus/templates/design/actions/run-design-extension-action.ts +284 -0
  65. package/corpus/templates/design/actions/set-active-breakpoint.ts +39 -0
  66. package/corpus/templates/design/app/components/design/DesignCanvas.tsx +1550 -82
  67. package/corpus/templates/design/app/components/design/DesignExtensionsPanel.tsx +649 -43
  68. package/corpus/templates/design/app/components/design/DrawOverlay.tsx +1 -1
  69. package/corpus/templates/design/app/components/design/EditPanel.tsx +1788 -52
  70. package/corpus/templates/design/app/components/design/LayersPanel.tsx +114 -33
  71. package/corpus/templates/design/app/components/design/LocalSourceEditBanner.tsx +157 -0
  72. package/corpus/templates/design/app/components/design/MotionDock.tsx +1071 -0
  73. package/corpus/templates/design/app/components/design/MultiScreenCanvas.tsx +1053 -99
  74. package/corpus/templates/design/app/components/design/ReviewPanel.tsx +766 -0
  75. package/corpus/templates/design/app/components/design/StatesPanel.tsx +581 -0
  76. package/corpus/templates/design/app/components/design/TokensPanel.tsx +578 -0
  77. package/corpus/templates/design/app/components/design/canvas-primitive-style.ts +241 -0
  78. package/corpus/templates/design/app/components/design/index.ts +16 -0
  79. package/corpus/templates/design/app/components/design/inspector/AutoLayoutMatrix.tsx +15 -6
  80. package/corpus/templates/design/app/components/design/inspector/DesignColorPicker.tsx +66 -3
  81. package/corpus/templates/design/app/components/design/inspector/InspectorAiActions.tsx +145 -0
  82. package/corpus/templates/design/app/components/design/inspector/SHADER_INTEGRATION.md +42 -12
  83. package/corpus/templates/design/app/components/visual-editor/DrawOverlay.tsx +1 -1
  84. package/corpus/templates/design/app/hooks/useAgentEditRequest.ts +131 -0
  85. package/corpus/templates/design/app/hooks/useDesignHotkeys.ts +3 -1
  86. package/corpus/templates/design/app/i18n/zh-TW.ts +32 -0
  87. package/corpus/templates/design/app/i18n-data.ts +280 -0
  88. package/corpus/templates/design/app/pages/DesignEditor.tsx +3087 -490
  89. package/corpus/templates/design/changelog/2026-06-29-added-a-review-panel-in-the-design-editor-s-inspector-with-a.md +6 -0
  90. package/corpus/templates/design/changelog/2026-06-29-copying-and-pasting-layers-no-longer-shows-success-notificat.md +6 -0
  91. package/corpus/templates/design/changelog/2026-06-29-device-presets-in-all-screens-view-resize-the-selected-previ.md +6 -0
  92. package/corpus/templates/design/changelog/2026-06-29-layer-and-canvas-drags-keep-the-layer-list-stable-while-chan.md +6 -0
  93. package/corpus/templates/design/changelog/2026-06-29-layer-moves-can-be-undone-and-redone-without-flashing-the-ca.md +6 -0
  94. package/corpus/templates/design/changelog/2026-06-29-screen-previews-use-a-single-blue-hover-border-in-all-screen.md +6 -0
  95. package/corpus/templates/design/changelog/2026-06-29-selected-containers-show-draggable-padding-and-gap-guides-on.md +6 -0
  96. package/corpus/templates/design/changelog/2026-06-29-the-design-editor-adds-a-studio-layer-with-tokens-respon.md +6 -0
  97. package/corpus/templates/design/changelog/2026-06-30-accessibility-findings-now-offer-a-one-click-fix.md +6 -0
  98. package/corpus/templates/design/changelog/2026-06-30-component-instances-now-have-editable-props-in-the-inspe.md +6 -0
  99. package/corpus/templates/design/changelog/2026-06-30-design-token-edits-now-stay-visible-in-previews-and-token-li.md +6 -0
  100. package/corpus/templates/design/changelog/2026-06-30-inspect-code-now-shows-the-elements-opening-tag-at-a-gla.md +6 -0
  101. package/corpus/templates/design/changelog/2026-06-30-shader-fill-presets-can-now-be-applied-to-an-element.md +6 -0
  102. package/corpus/templates/design/changelog/2026-06-30-the-motion-timeline-can-now-add-a-track-to-any-element-a.md +6 -0
  103. package/corpus/templates/design/changelog/2026-06-30-visual-editor-selection-layer-paint-and-drawing-controls-are-more-reliable.md +6 -0
  104. package/corpus/templates/design/e2e/global-setup.ts +94 -2
  105. package/corpus/templates/design/e2e/helpers.ts +10 -4
  106. package/corpus/templates/design/server/db/schema.ts +123 -0
  107. package/corpus/templates/design/server/plugins/db.ts +90 -0
  108. package/corpus/templates/design/shared/builder-app.ts +297 -0
  109. package/corpus/templates/design/shared/capability-resolver.ts +123 -0
  110. package/corpus/templates/design/shared/capture-sanitize.ts +70 -0
  111. package/corpus/templates/design/shared/code-layer.ts +1016 -71
  112. package/corpus/templates/design/shared/component-model.ts +274 -0
  113. package/corpus/templates/design/shared/design-review.ts +275 -0
  114. package/corpus/templates/design/shared/design-source-capabilities.ts +286 -0
  115. package/corpus/templates/design/shared/design-state.ts +112 -0
  116. package/corpus/templates/design/shared/design-surface-index.ts +258 -0
  117. package/corpus/templates/design/shared/motion-compiler.ts +349 -0
  118. package/corpus/templates/design/shared/motion-timeline.ts +193 -0
  119. package/corpus/templates/design/shared/resolve-tweaks.ts +32 -9
  120. package/corpus/templates/design/shared/responsive-classes.ts +452 -0
  121. package/corpus/templates/design/shared/shader-fill.ts +323 -0
  122. package/corpus/templates/design/shared/source-mode.ts +245 -0
  123. package/corpus/templates/plan/app/components/plan/CanvasArea.tsx +6 -2
  124. package/corpus/templates/plan/changelog/2026-06-29-plan-canvases-open-without-an-initial-pan-and-zoom-flicker.md +6 -0
  125. package/dist/agent/production-agent.d.ts.map +1 -1
  126. package/dist/agent/production-agent.js +94 -10
  127. package/dist/agent/production-agent.js.map +1 -1
  128. package/dist/cli/design-connect.d.ts.map +1 -1
  129. package/dist/cli/design-connect.js +28 -2
  130. package/dist/cli/design-connect.js.map +1 -1
  131. package/dist/cli/skills.d.ts.map +1 -1
  132. package/dist/cli/skills.js +37 -21
  133. package/dist/cli/skills.js.map +1 -1
  134. package/dist/client/AssistantChat.d.ts +14 -0
  135. package/dist/client/AssistantChat.d.ts.map +1 -1
  136. package/dist/client/AssistantChat.js +115 -22
  137. package/dist/client/AssistantChat.js.map +1 -1
  138. package/dist/client/sse-event-processor.d.ts.map +1 -1
  139. package/dist/client/sse-event-processor.js +10 -0
  140. package/dist/client/sse-event-processor.js.map +1 -1
  141. package/dist/collab/routes.d.ts +1 -1
  142. package/dist/file-upload/actions/upload-image.d.ts +2 -2
  143. package/dist/notifications/routes.d.ts +2 -2
  144. package/dist/observability/routes.d.ts +8 -8
  145. package/dist/resources/handlers.d.ts +2 -2
  146. package/dist/server/agent-engine-api-key-route.d.ts +1 -1
  147. package/dist/server/transcribe-voice.d.ts +1 -1
  148. package/package.json +1 -1
@@ -0,0 +1,297 @@
1
+ /**
2
+ * Builder app helpers for the Design Studio.
3
+ *
4
+ * Provides two capabilities:
5
+ *
6
+ * 1. **Connection status** — resolve whether Builder is configured for the
7
+ * current request (credentials + project ID), without duplicating Builder
8
+ * auth logic. Delegates entirely to the core `resolveBuilderCredentials` /
9
+ * `resolveIsBuilderBranchingEnabled` helpers; no credential values are
10
+ * surfaced in return types.
11
+ *
12
+ * 2. **Migration seed** — build the prompt seed handed to the Builder cloud
13
+ * agent when migrating an inline Alpine/HTML design to a real React + Tailwind
14
+ * app. The seed carries:
15
+ * - The design's semantic HTML (up to `MAX_HTML_BYTES` per file).
16
+ * - The `:root` CSS custom-property block extracted from each file.
17
+ * - Any Brand Kit token summary from the linked design system.
18
+ * - Human-readable migration instructions for the Builder cloud agent.
19
+ *
20
+ * Nothing in this module calls the Builder API directly. API calls happen in
21
+ * `migrate-inline-design-to-app.ts` (action) via `runBuilderAgent`.
22
+ *
23
+ * Security note: credential values are never included in return types or seed
24
+ * content. The `resolveBuilderStatus` function returns only boolean flags and
25
+ * the pre-built `connectUrl` from the core browser helpers.
26
+ */
27
+
28
+ import {
29
+ resolveBuilderBranchProjectId,
30
+ resolveIsBuilderBranchingEnabled,
31
+ } from "@agent-native/core/server";
32
+ import { resolveHasCompleteBuilderConnection } from "@agent-native/core/server";
33
+ import { getRequestUserEmail } from "@agent-native/core/server/request-context";
34
+
35
+ // ---------------------------------------------------------------------------
36
+ // Types
37
+ // ---------------------------------------------------------------------------
38
+
39
+ export interface BuilderConnectionStatus {
40
+ /** True when Builder credentials are configured and valid. */
41
+ connected: boolean;
42
+ /** True when a Builder branch project is also configured (= agents can run). */
43
+ builderEnabled: boolean;
44
+ /** The resolved Builder branch project ID, empty string when not configured. */
45
+ branchProjectId: string;
46
+ /** The email of the currently authenticated user (for routing the Builder job). */
47
+ ownerEmail: string | null;
48
+ }
49
+
50
+ export interface MigrationSeed {
51
+ /**
52
+ * The full migration prompt to hand to `runBuilderAgent`.
53
+ * Contains the design HTML, extracted CSS vars, token summary, and
54
+ * detailed instructions for the Builder cloud agent.
55
+ */
56
+ prompt: string;
57
+ /**
58
+ * The number of design files included in the seed (capped at
59
+ * `MAX_SEED_FILES`).
60
+ */
61
+ fileCount: number;
62
+ /**
63
+ * Total HTML bytes included in the seed (before any truncation).
64
+ */
65
+ totalBytes: number;
66
+ }
67
+
68
+ // ---------------------------------------------------------------------------
69
+ // Constants
70
+ // ---------------------------------------------------------------------------
71
+
72
+ /**
73
+ * Maximum number of files to include in the migration seed.
74
+ * Inline designs rarely exceed this; the cap keeps the Builder prompt
75
+ * within a safe token budget.
76
+ */
77
+ const MAX_SEED_FILES = 10;
78
+
79
+ /**
80
+ * Maximum bytes per HTML file included in the migration seed.
81
+ * Files larger than this are truncated with an ellipsis notice so the
82
+ * Builder agent still sees the overall structure without exceeding its
83
+ * prompt limit.
84
+ */
85
+ const MAX_HTML_BYTES_PER_FILE = 80_000;
86
+
87
+ // ---------------------------------------------------------------------------
88
+ // Connection status
89
+ // ---------------------------------------------------------------------------
90
+
91
+ /**
92
+ * Return the Builder connection status for the current request context.
93
+ *
94
+ * Delegates to core helpers (`resolveHasCompleteBuilderConnection`,
95
+ * `resolveIsBuilderBranchingEnabled`, `resolveBuilderBranchProjectId`) so
96
+ * credential resolution lives in one place and is never duplicated here.
97
+ *
98
+ * Usage:
99
+ * ```ts
100
+ * const status = await resolveBuilderStatus();
101
+ * if (!status.builderEnabled) {
102
+ * return { cta: "connect-builder" };
103
+ * }
104
+ * ```
105
+ */
106
+ export async function resolveBuilderStatus(): Promise<BuilderConnectionStatus> {
107
+ const [connected, builderEnabled, branchProjectId] = await Promise.all([
108
+ resolveHasCompleteBuilderConnection(),
109
+ resolveIsBuilderBranchingEnabled(),
110
+ resolveBuilderBranchProjectId(),
111
+ ]);
112
+
113
+ return {
114
+ connected,
115
+ builderEnabled,
116
+ branchProjectId,
117
+ ownerEmail: getRequestUserEmail() ?? null,
118
+ };
119
+ }
120
+
121
+ // ---------------------------------------------------------------------------
122
+ // CSS-var extraction
123
+ // ---------------------------------------------------------------------------
124
+
125
+ /**
126
+ * Extract the `:root` block(s) from a raw HTML/CSS string.
127
+ *
128
+ * Returns only the lines inside `:root { … }` declarations to keep the
129
+ * migration seed focused on custom-property tokens rather than the full
130
+ * stylesheet. Falls back to the empty string when no `:root` block is found.
131
+ */
132
+ function extractRootCssVars(html: string): string {
133
+ // Match one or more :root { … } blocks (non-greedy, handles multi-block files).
134
+ const matches = [...html.matchAll(/:root\s*\{([^}]*)\}/g)];
135
+ if (matches.length === 0) return "";
136
+
137
+ const lines: string[] = [];
138
+ for (const match of matches) {
139
+ const block = match[1] ?? "";
140
+ for (const line of block.split("\n")) {
141
+ const trimmed = line.trim();
142
+ // Only include CSS custom property declarations (--var: value;).
143
+ if (trimmed.startsWith("--") && trimmed.includes(":")) {
144
+ lines.push(` ${trimmed}`);
145
+ }
146
+ }
147
+ }
148
+ return lines.length > 0 ? `:root {\n${lines.join("\n")}\n}` : "";
149
+ }
150
+
151
+ // ---------------------------------------------------------------------------
152
+ // Migration seed builder
153
+ // ---------------------------------------------------------------------------
154
+
155
+ /**
156
+ * Build the migration seed prompt for the Builder cloud agent.
157
+ *
158
+ * @param params.title - Human-readable design title (used in the prompt header).
159
+ * @param params.files - Current design files (id + filename + content + fileType).
160
+ * @param params.resolvedCssVars - Resolved CSS-var → value map from tweak selections.
161
+ * @param params.brandKitSummary - Optional human-readable token summary from the
162
+ * linked design system (e.g. from `index-design-tokens`).
163
+ *
164
+ * The caller is responsible for fetching the design snapshot first. This
165
+ * function is pure (no DB or network calls) so it is easy to test and reuse.
166
+ */
167
+ export function buildMigrationSeed(params: {
168
+ title: string;
169
+ files: Array<{
170
+ filename: string;
171
+ content: string;
172
+ fileType: string;
173
+ }>;
174
+ resolvedCssVars?: Record<string, string>;
175
+ brandKitSummary?: string;
176
+ }): MigrationSeed {
177
+ const { title, files, resolvedCssVars, brandKitSummary } = params;
178
+
179
+ // Limit file count.
180
+ const seedFiles = files.slice(0, MAX_SEED_FILES);
181
+ let totalBytes = 0;
182
+
183
+ // Build per-file sections.
184
+ const fileSections: string[] = [];
185
+ for (const file of seedFiles) {
186
+ const rawBytes = new TextEncoder().encode(file.content).length;
187
+ totalBytes += rawBytes;
188
+
189
+ let content = file.content;
190
+ let truncationNote = "";
191
+ if (rawBytes > MAX_HTML_BYTES_PER_FILE) {
192
+ content = file.content.slice(0, MAX_HTML_BYTES_PER_FILE);
193
+ truncationNote = `\n<!-- [TRUNCATED: original file was ${rawBytes} bytes; only the first ${MAX_HTML_BYTES_PER_FILE} bytes are shown] -->`;
194
+ }
195
+
196
+ // Extract :root CSS vars from each file for the token block.
197
+ const cssVars = extractRootCssVars(content);
198
+
199
+ const section = [
200
+ `### File: ${file.filename}`,
201
+ "```html",
202
+ content,
203
+ truncationNote,
204
+ "```",
205
+ ...(cssVars
206
+ ? [
207
+ "",
208
+ "**Extracted CSS custom properties (design tokens):**",
209
+ "```css",
210
+ cssVars,
211
+ "```",
212
+ ]
213
+ : []),
214
+ ]
215
+ .filter((l) => l !== "")
216
+ .join("\n");
217
+
218
+ fileSections.push(section);
219
+ }
220
+
221
+ // Build the resolved CSS vars block (from tweak selections).
222
+ let resolvedVarsBlock = "";
223
+ if (resolvedCssVars && Object.keys(resolvedCssVars).length > 0) {
224
+ const lines = Object.entries(resolvedCssVars)
225
+ .map(([k, v]) => ` ${k}: ${v};`)
226
+ .join("\n");
227
+ resolvedVarsBlock = [
228
+ "",
229
+ "## User-tuned token overrides (apply these values in the real app)",
230
+ "```css",
231
+ `:root {\n${lines}\n}`,
232
+ "```",
233
+ ].join("\n");
234
+ }
235
+
236
+ // Brand Kit summary block.
237
+ const brandKitBlock =
238
+ brandKitSummary && brandKitSummary.trim()
239
+ ? [
240
+ "",
241
+ "## Brand Kit / Design System tokens",
242
+ brandKitSummary.trim(),
243
+ ].join("\n")
244
+ : "";
245
+
246
+ // Build the full prompt.
247
+ const omittedFilesNote =
248
+ files.length > MAX_SEED_FILES
249
+ ? `\n> Note: ${files.length - MAX_SEED_FILES} additional file(s) were omitted to stay within the prompt limit.\n`
250
+ : "";
251
+
252
+ const prompt = [
253
+ `# Migrate inline design to React app: "${title}"`,
254
+ "",
255
+ "You are a Builder cloud agent. The user has an inline Alpine.js / Tailwind HTML prototype",
256
+ "that they want to migrate to a real React + TypeScript + Tailwind app.",
257
+ "",
258
+ "## Your task",
259
+ "1. Convert the HTML prototype below into a production-quality React + TypeScript + Tailwind",
260
+ " application, preserving the visual design and UX faithfully.",
261
+ "2. Map Alpine.js `x-data` / `x-show` / `x-bind` patterns to React state, conditional",
262
+ " rendering, and event handlers.",
263
+ "3. Extract inline styles and repeated patterns into reusable React components with",
264
+ " Tailwind classes. Preserve the `:root` CSS custom properties as a `globals.css` file",
265
+ " and wire them into the Tailwind theme config.",
266
+ "4. Carry all design tokens (color, typography, spacing, radius) from the `:root` block",
267
+ " into the generated `globals.css` and `tailwind.config.ts` so the visual identity is",
268
+ " identical to the original prototype.",
269
+ "5. Do not introduce placeholder data or lorem ipsum. Keep the structural content",
270
+ " from the original design.",
271
+ "6. Use shadcn/ui primitives (Button, Card, Dialog, Input, etc.) where the HTML uses",
272
+ " semantically equivalent patterns.",
273
+ "7. The app must compile and render without errors.",
274
+ "",
275
+ "## Source design files",
276
+ omittedFilesNote,
277
+ ...fileSections,
278
+ resolvedVarsBlock,
279
+ brandKitBlock,
280
+ "",
281
+ "## Output expectations",
282
+ "- A fully working React app in the current project branch.",
283
+ "- `src/app/globals.css` containing all `:root` CSS custom properties from above.",
284
+ "- `tailwind.config.ts` wiring those vars into the Tailwind theme.",
285
+ "- At least one page component that renders the migrated design.",
286
+ "- All Alpine `x-data` patterns converted to React hooks / state.",
287
+ "- All Tailwind CDN classes preserved as-is in JSX.",
288
+ ]
289
+ .filter((l) => l !== undefined && l !== null)
290
+ .join("\n");
291
+
292
+ return {
293
+ prompt,
294
+ fileCount: seedFiles.length,
295
+ totalBytes,
296
+ };
297
+ }
@@ -0,0 +1,123 @@
1
+ /**
2
+ * Source capability resolver — pure, no DB, no side effects.
3
+ *
4
+ * Maps a `DesignSourceType` (inline | localhost | fusion) to the concrete
5
+ * `DesignSourceCapabilities` map. Callers that have already proven a richer
6
+ * capability set (e.g. a localhost bridge that has verified `readFile`) should
7
+ * override the defaults after calling this function.
8
+ *
9
+ * The canonical tier semantics live in `DESIGN-STUDIO-PLAN.md` §5:
10
+ *
11
+ * - **inline** — HTML/CSS preview + controlled writes via the deterministic
12
+ * `replace-document-content` / `apply-tweaks` path; `previewMotion` + Tier-A
13
+ * `writeMotion` (managed `<style data-agent-native-motion>` block) and CSS-var
14
+ * token edits are available without a file-write bridge.
15
+ * - **localhost** — starts read-only/preview-only; `readFile` / `applyEdit` /
16
+ * `writeFile` and real-app capabilities (`indexComponents`, `writeTokens`)
17
+ * become `available` only after bridge hardening.
18
+ * - **fusion (Builder)** — starts preview-only; unlocks the full set
19
+ * (`indexComponents`, `writeTokens`, `writeMotion`, `branch`, `deploy`) once
20
+ * the bridge proves capabilities.
21
+ *
22
+ * The UI must never infer write ability from `sourceType` alone; it must always
23
+ * read the capability map returned here (or an overridden variant).
24
+ */
25
+
26
+ import {
27
+ available,
28
+ planned,
29
+ unavailable,
30
+ INLINE_DEFAULT_CAPABILITIES,
31
+ LOCALHOST_DEFAULT_CAPABILITIES,
32
+ FUSION_DISCONNECTED_CAPABILITIES,
33
+ FUSION_CONNECTED_CAPABILITIES,
34
+ type DesignSourceCapabilities,
35
+ } from "./design-source-capabilities";
36
+ import type { DesignSourceType } from "./source-mode";
37
+
38
+ /**
39
+ * Return the default `DesignSourceCapabilities` for the given `sourceType`.
40
+ *
41
+ * These are **defaults** — they represent the conservative starting point for
42
+ * a freshly connected source. Callers that have runtime evidence of a richer
43
+ * capability set (e.g. a bridge handshake that confirmed `readFile` works)
44
+ * should spread/override specific entries rather than calling this function
45
+ * again.
46
+ *
47
+ * ```ts
48
+ * const caps = resolveSourceCapabilities(design.sourceType);
49
+ * // Override after bridge handshake:
50
+ * const proven: DesignSourceCapabilities = {
51
+ * ...caps,
52
+ * readFile: available("Bridge verified"),
53
+ * };
54
+ * ```
55
+ *
56
+ * @param sourceType - The source type from `DesignSourceType`.
57
+ * @returns A read-only snapshot of the default capability map.
58
+ */
59
+ export function resolveSourceCapabilities(
60
+ sourceType: DesignSourceType,
61
+ ): DesignSourceCapabilities {
62
+ switch (sourceType) {
63
+ case "inline":
64
+ return INLINE_DEFAULT_CAPABILITIES;
65
+ case "localhost":
66
+ return LOCALHOST_DEFAULT_CAPABILITIES;
67
+ case "fusion":
68
+ // Conservative default for fusion when connection status is unknown.
69
+ // Use resolveFusionCapabilities(connected) when Builder connection status
70
+ // is known, or resolveDescriptorCapabilities() which honours the
71
+ // descriptor's proven capabilities map.
72
+ return FUSION_DISCONNECTED_CAPABILITIES;
73
+ default: {
74
+ // Exhaustive check — TypeScript will catch unhandled variants.
75
+ const _exhaustive: never = sourceType;
76
+ void _exhaustive;
77
+ // Fallback: safest option is inline (no file writes, no real-app ops).
78
+ return INLINE_DEFAULT_CAPABILITIES;
79
+ }
80
+ }
81
+ }
82
+
83
+ /**
84
+ * Return the correct `DesignSourceCapabilities` for a **fusion** source based
85
+ * on the current Builder connection status.
86
+ *
87
+ * Per DESIGN-STUDIO-PLAN.md §5:
88
+ * - **Not connected** (`connected = false`): preview-only. No real-app write
89
+ * operations (`indexComponents`, `branch`, `deployPreview`, `deploy`,
90
+ * `writeFile`, `writeTokens`, `writeMotion`) are available.
91
+ * - **Connected** (`connected = true`): `indexComponents`, `branch`,
92
+ * `deployPreview`, and `deploy` are **available**. Source writes
93
+ * (`writeFile`, `writeTokens`, `writeMotion`) remain **planned** until
94
+ * bridge hardening is complete.
95
+ *
96
+ * Usage (in an action that already resolved Builder status):
97
+ * ```ts
98
+ * import { resolveFusionCapabilities } from "../shared/capability-resolver.js";
99
+ * import { resolveIsBuilderBranchingEnabled } from "@agent-native/core/server";
100
+ *
101
+ * const connected = await resolveIsBuilderBranchingEnabled();
102
+ * const caps = resolveFusionCapabilities(connected);
103
+ * if (hasCapability(caps, "branch")) { ... }
104
+ * ```
105
+ *
106
+ * @param connected - `true` when Builder credentials are configured AND a
107
+ * branch project is set (i.e. `resolveIsBuilderBranchingEnabled()` returns
108
+ * `true`).
109
+ */
110
+ export function resolveFusionCapabilities(
111
+ connected: boolean,
112
+ ): DesignSourceCapabilities {
113
+ return connected
114
+ ? FUSION_CONNECTED_CAPABILITIES
115
+ : FUSION_DISCONNECTED_CAPABILITIES;
116
+ }
117
+
118
+ // Re-export factory helpers so callers only need this module to build
119
+ // capability maps with override entries.
120
+ export { available, planned, unavailable };
121
+ export type { DesignSourceCapabilities };
122
+ // Re-export the fusion constants for callers that prefer direct access.
123
+ export { FUSION_CONNECTED_CAPABILITIES, FUSION_DISCONNECTED_CAPABILITIES };
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Shared sanitization helpers for design state capture payloads.
3
+ *
4
+ * Used by both create-design-state and capture-design-state to enforce a
5
+ * consistent stored-XSS guard and size cap before persisting arbitrary
6
+ * caller-supplied markup / DOM snapshots into `design_state` rows.
7
+ */
8
+
9
+ /**
10
+ * Maximum serialised size of a captured/replayed `captureData` or
11
+ * `fixtureData` payload. Caps single-row size to protect the DB and the
12
+ * shareable content each row feeds.
13
+ */
14
+ export const CAPTURE_DATA_MAX_BYTES = 256 * 1024; // 256 KB
15
+
16
+ /**
17
+ * Strip stored-XSS vectors out of an HTML/markup string before it is persisted
18
+ * and later replayed into shareable design content. Mirrors the framework's
19
+ * text-edit HTML sanitiser: removes script/style/iframe/object/embed/link/meta/
20
+ * base tags, inline `on*` handlers, and `javascript:` / `vbscript:` / `data:`
21
+ * URLs in `href` / `src` / `xlink:href`.
22
+ */
23
+ export function sanitizeMarkup(html: string): string {
24
+ return html
25
+ .replace(
26
+ /<\s*(script|style|iframe|object|embed|link|meta|base)\b[\s\S]*?<\s*\/\s*\1\s*>/gi,
27
+ "",
28
+ )
29
+ .replace(
30
+ /<\s*(script|style|iframe|object|embed|link|meta|base)\b[^>]*\/?\s*>/gi,
31
+ "",
32
+ )
33
+ .replace(/\s+on[A-Za-z]+\s*=\s*(?:"[^"]*"|'[^']*'|[^\s>]+)/g, "")
34
+ .replace(
35
+ /\s+(href|src|xlink:href)\s*=\s*(?:(["'])\s*(?:javascript|vbscript|data):[\s\S]*?\2|(?:javascript|vbscript|data):[^\s>]*)/gi,
36
+ "",
37
+ );
38
+ }
39
+
40
+ /**
41
+ * A string "looks like markup" — and is therefore worth sanitising — when it
42
+ * contains an angle-bracket tag opener or an Alpine `x-`/`@`/`:` binding that
43
+ * could carry script. Plain data strings (route names, ids) are left untouched.
44
+ */
45
+ export function looksLikeMarkup(value: string): boolean {
46
+ return /<[a-zA-Z!/]/.test(value) || value.includes("</");
47
+ }
48
+
49
+ /**
50
+ * Recursively sanitise every string value inside a captured/replayed
51
+ * `captureData` or `fixtureData` object (e.g. `domHtml`, `domSnapshot`,
52
+ * `x-data` markup) so no untrusted DOM is persisted raw. Non-string leaves
53
+ * pass through unchanged.
54
+ */
55
+ export function sanitizeCaptureData(value: unknown): unknown {
56
+ if (typeof value === "string") {
57
+ return looksLikeMarkup(value) ? sanitizeMarkup(value) : value;
58
+ }
59
+ if (Array.isArray(value)) {
60
+ return value.map((entry) => sanitizeCaptureData(entry));
61
+ }
62
+ if (value && typeof value === "object") {
63
+ const out: Record<string, unknown> = {};
64
+ for (const [k, v] of Object.entries(value as Record<string, unknown>)) {
65
+ out[k] = sanitizeCaptureData(v);
66
+ }
67
+ return out;
68
+ }
69
+ return value;
70
+ }