agentcut 0.0.0-stage → 0.1.0

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 (248) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +11 -2
  3. package/dist/bridge.d.ts +45 -0
  4. package/dist/bridge.js +691 -0
  5. package/dist/bridge.js.map +1 -0
  6. package/dist/config.d.ts +13 -0
  7. package/dist/config.js +50 -0
  8. package/dist/config.js.map +1 -0
  9. package/dist/index.d.ts +2 -0
  10. package/dist/index.js +35 -0
  11. package/dist/index.js.map +1 -0
  12. package/dist/log.d.ts +1 -0
  13. package/dist/log.js +14 -0
  14. package/dist/log.js.map +1 -0
  15. package/dist/studio/agents/claude.d.ts +7 -0
  16. package/dist/studio/agents/claude.js +155 -0
  17. package/dist/studio/agents/claude.js.map +1 -0
  18. package/dist/studio/agents/codex.d.ts +4 -0
  19. package/dist/studio/agents/codex.js +169 -0
  20. package/dist/studio/agents/codex.js.map +1 -0
  21. package/dist/studio/agents/index.d.ts +8 -0
  22. package/dist/studio/agents/index.js +50 -0
  23. package/dist/studio/agents/index.js.map +1 -0
  24. package/dist/studio/agents/types.d.ts +131 -0
  25. package/dist/studio/agents/types.js +11 -0
  26. package/dist/studio/agents/types.js.map +1 -0
  27. package/dist/studio/bundler.d.ts +29 -0
  28. package/dist/studio/bundler.js +136 -0
  29. package/dist/studio/bundler.js.map +1 -0
  30. package/dist/studio/chat.d.ts +147 -0
  31. package/dist/studio/chat.js +681 -0
  32. package/dist/studio/chat.js.map +1 -0
  33. package/dist/studio/cli.d.ts +2 -0
  34. package/dist/studio/cli.js +194 -0
  35. package/dist/studio/cli.js.map +1 -0
  36. package/dist/studio/components.d.ts +4 -0
  37. package/dist/studio/components.js +36 -0
  38. package/dist/studio/components.js.map +1 -0
  39. package/dist/studio/host.d.ts +105 -0
  40. package/dist/studio/host.js +634 -0
  41. package/dist/studio/host.js.map +1 -0
  42. package/dist/studio/http.d.ts +21 -0
  43. package/dist/studio/http.js +240 -0
  44. package/dist/studio/http.js.map +1 -0
  45. package/dist/studio/music.d.ts +35 -0
  46. package/dist/studio/music.js +130 -0
  47. package/dist/studio/music.js.map +1 -0
  48. package/dist/studio/proc.d.ts +11 -0
  49. package/dist/studio/proc.js +69 -0
  50. package/dist/studio/proc.js.map +1 -0
  51. package/dist/studio/projects.d.ts +84 -0
  52. package/dist/studio/projects.js +369 -0
  53. package/dist/studio/projects.js.map +1 -0
  54. package/dist/studio/render.d.ts +24 -0
  55. package/dist/studio/render.js +197 -0
  56. package/dist/studio/render.js.map +1 -0
  57. package/dist/studio/reveal.d.ts +7 -0
  58. package/dist/studio/reveal.js +49 -0
  59. package/dist/studio/reveal.js.map +1 -0
  60. package/dist/studio/schema.d.ts +4152 -0
  61. package/dist/studio/schema.js +358 -0
  62. package/dist/studio/schema.js.map +1 -0
  63. package/dist/studio/tools.d.ts +2 -0
  64. package/dist/studio/tools.js +165 -0
  65. package/dist/studio/tools.js.map +1 -0
  66. package/dist/studio/voice.d.ts +150 -0
  67. package/dist/studio/voice.js +434 -0
  68. package/dist/studio/voice.js.map +1 -0
  69. package/dist/studio/workspace.d.ts +31 -0
  70. package/dist/studio/workspace.js +187 -0
  71. package/dist/studio/workspace.js.map +1 -0
  72. package/package.json +50 -4
  73. package/template/AGENTS.md +13 -0
  74. package/template/components/CATALOG.md +1306 -0
  75. package/template/components/README.md +61 -0
  76. package/template/components/STYLES.md +246 -0
  77. package/template/components/arcade-title/ArcadeTitle.tsx +860 -0
  78. package/template/components/arcade-title/meta.json +28 -0
  79. package/template/components/aurora/Aurora.tsx +63 -0
  80. package/template/components/aurora/meta.json +28 -0
  81. package/template/components/bar-wipe-title/BarWipeTitle.tsx +94 -0
  82. package/template/components/bar-wipe-title/meta.json +29 -0
  83. package/template/components/before-after/BeforeAfter.tsx +89 -0
  84. package/template/components/before-after/meta.json +233 -0
  85. package/template/components/bento-grid/BentoGrid.tsx +202 -0
  86. package/template/components/bento-grid/meta.json +25 -0
  87. package/template/components/blur-in-title/BlurInTitle.tsx +121 -0
  88. package/template/components/blur-in-title/meta.json +32 -0
  89. package/template/components/catalog.json +8730 -0
  90. package/template/components/catalog.ts +103 -0
  91. package/template/components/chat-thread/ChatThread.tsx +128 -0
  92. package/template/components/chat-thread/meta.json +24 -0
  93. package/template/components/checklist/Checklist.tsx +129 -0
  94. package/template/components/checklist/meta.json +25 -0
  95. package/template/components/confetti/Confetti.tsx +109 -0
  96. package/template/components/confetti/meta.json +28 -0
  97. package/template/components/countdown/Countdown.tsx +166 -0
  98. package/template/components/countdown/meta.json +28 -0
  99. package/template/components/cut-and-paste/CutAndPaste.tsx +654 -0
  100. package/template/components/cut-and-paste/meta.json +29 -0
  101. package/template/components/decode-text/DecodeText.tsx +97 -0
  102. package/template/components/decode-text/meta.json +29 -0
  103. package/template/components/editorial-quote/EditorialQuote.tsx +122 -0
  104. package/template/components/editorial-quote/meta.json +28 -0
  105. package/template/components/glitch-title/GlitchTitle.tsx +171 -0
  106. package/template/components/glitch-title/meta.json +32 -0
  107. package/template/components/halftone-wave/HalftoneWave.tsx +106 -0
  108. package/template/components/halftone-wave/meta.json +28 -0
  109. package/template/components/highlighter/Highlighter.tsx +142 -0
  110. package/template/components/highlighter/meta.json +28 -0
  111. package/template/components/hook-card/HookCard.tsx +552 -0
  112. package/template/components/hook-card/meta.json +304 -0
  113. package/template/components/index.ts +149 -0
  114. package/template/components/iris-wipe/IrisWipe.tsx +76 -0
  115. package/template/components/iris-wipe/meta.json +24 -0
  116. package/template/components/kinetic-poster/KineticPoster.tsx +437 -0
  117. package/template/components/kinetic-poster/meta.json +31 -0
  118. package/template/components/kinetic-punch/KineticPunch.tsx +80 -0
  119. package/template/components/kinetic-punch/meta.json +30 -0
  120. package/template/components/lava-lamp/LavaLamp.tsx +92 -0
  121. package/template/components/lava-lamp/meta.json +28 -0
  122. package/template/components/letter-cascade/LetterCascade.tsx +102 -0
  123. package/template/components/letter-cascade/meta.json +29 -0
  124. package/template/components/lib.ts +179 -0
  125. package/template/components/light-leak/LightLeakTransition.tsx +43 -0
  126. package/template/components/light-leak/meta.json +74 -0
  127. package/template/components/line-diagram/LineDiagram.tsx +205 -0
  128. package/template/components/line-diagram/meta.json +217 -0
  129. package/template/components/list-card/ListCard.tsx +104 -0
  130. package/template/components/list-card/meta.json +232 -0
  131. package/template/components/logo-sting/LogoSting.tsx +129 -0
  132. package/template/components/logo-sting/meta.json +29 -0
  133. package/template/components/looks.tsx +1447 -0
  134. package/template/components/lower-third/LowerThird.tsx +100 -0
  135. package/template/components/lower-third/meta.json +24 -0
  136. package/template/components/marquee/Marquee.tsx +100 -0
  137. package/template/components/marquee/meta.json +30 -0
  138. package/template/components/notification/Notification.tsx +115 -0
  139. package/template/components/notification/meta.json +27 -0
  140. package/template/components/outline-fill/OutlineFill.tsx +106 -0
  141. package/template/components/outline-fill/meta.json +28 -0
  142. package/template/components/panel-sweep/PanelSweep.tsx +86 -0
  143. package/template/components/panel-sweep/meta.json +25 -0
  144. package/template/components/prompt-box/PromptBox.tsx +131 -0
  145. package/template/components/prompt-box/meta.json +24 -0
  146. package/template/components/props.ts +73 -0
  147. package/template/components/quote-card/QuoteCard.tsx +71 -0
  148. package/template/components/quote-card/meta.json +216 -0
  149. package/template/components/shape-shift/ShapeShift.tsx +420 -0
  150. package/template/components/shape-shift/meta.json +31 -0
  151. package/template/components/slide-zoom-message/SlideZoomMessage.tsx +179 -0
  152. package/template/components/slide-zoom-message/meta.json +199 -0
  153. package/template/components/social-post/SocialPost.tsx +185 -0
  154. package/template/components/social-post/meta.json +30 -0
  155. package/template/components/split-flap/SplitFlap.tsx +191 -0
  156. package/template/components/split-flap/meta.json +29 -0
  157. package/template/components/spotlight-grid/SpotlightGrid.tsx +84 -0
  158. package/template/components/spotlight-grid/meta.json +25 -0
  159. package/template/components/stat-counter/StatCounter.tsx +117 -0
  160. package/template/components/stat-counter/meta.json +27 -0
  161. package/template/components/sticker-badge/StickerBadge.tsx +46 -0
  162. package/template/components/sticker-badge/meta.json +220 -0
  163. package/template/components/sticker-slam/StickerSlam.tsx +941 -0
  164. package/template/components/sticker-slam/meta.json +34 -0
  165. package/template/components/style-layer.tsx +233 -0
  166. package/template/components/styles.json +762 -0
  167. package/template/components/styles.ts +113 -0
  168. package/template/components/target-lock/TargetLock.tsx +662 -0
  169. package/template/components/target-lock/meta.json +32 -0
  170. package/template/components/text-reveal/TextReveal.tsx +99 -0
  171. package/template/components/text-reveal/meta.json +28 -0
  172. package/template/components/tile-wipe/TileWipe.tsx +75 -0
  173. package/template/components/tile-wipe/meta.json +24 -0
  174. package/template/components/type-zoom/TypeZoom.tsx +103 -0
  175. package/template/components/type-zoom/meta.json +27 -0
  176. package/template/components/types.ts +66 -0
  177. package/template/components/typewriter/Typewriter.tsx +112 -0
  178. package/template/components/typewriter/meta.json +29 -0
  179. package/template/components/word-pop/WordPop.tsx +59 -0
  180. package/template/components/word-pop/meta.json +237 -0
  181. package/template/components/word-stack/WordStack.tsx +122 -0
  182. package/template/components/word-stack/meta.json +27 -0
  183. package/template/components/word-swap/WordSwap.tsx +127 -0
  184. package/template/components/word-swap/meta.json +30 -0
  185. package/template/presets/charcoal-sketch/PROMPT.md +48 -0
  186. package/template/presets/charcoal-sketch/assets/paper/grain-0.png +0 -0
  187. package/template/presets/charcoal-sketch/assets/paper/grain-1.png +0 -0
  188. package/template/presets/charcoal-sketch/assets/paper/grain-2.png +0 -0
  189. package/template/presets/charcoal-sketch/assets/paper/sketch-paper.jpg +0 -0
  190. package/template/presets/charcoal-sketch/assets/paper/smudge.png +0 -0
  191. package/template/presets/charcoal-sketch/poster.jpg +0 -0
  192. package/template/presets/charcoal-sketch/preset.json +17 -0
  193. package/template/presets/charcoal-sketch/preview.mp4 +0 -0
  194. package/template/presets/charcoal-sketch/scenes/Grain.tsx +23 -0
  195. package/template/presets/charcoal-sketch/scenes/Paper.tsx +17 -0
  196. package/template/presets/charcoal-sketch/scenes/examples/Agents.tsx +100 -0
  197. package/template/presets/charcoal-sketch/scenes/examples/Approvals.tsx +110 -0
  198. package/template/presets/charcoal-sketch/scenes/examples/Blog.tsx +105 -0
  199. package/template/presets/charcoal-sketch/scenes/examples/EndCard.tsx +41 -0
  200. package/template/presets/charcoal-sketch/scenes/examples/Hook.tsx +130 -0
  201. package/template/presets/charcoal-sketch/scenes/examples/Ideas.tsx +92 -0
  202. package/template/presets/charcoal-sketch/scenes/examples/Posting.tsx +128 -0
  203. package/template/presets/charcoal-sketch/scenes/lib/painfix.tsx +119 -0
  204. package/template/presets/charcoal-sketch/scenes/lib/sketch.tsx +291 -0
  205. package/template/presets/charcoal-sketch/scripts/build_layers.example.py +193 -0
  206. package/template/presets/charcoal-sketch/scripts/duck_music.py +34 -0
  207. package/template/presets/charcoal-sketch/scripts/make_textures.py +93 -0
  208. package/template/presets/punk-cut-paper/PROMPT.md +37 -0
  209. package/template/presets/punk-cut-paper/assets/paper/desk-cream.jpg +0 -0
  210. package/template/presets/punk-cut-paper/assets/paper/grain-overlay.png +0 -0
  211. package/template/presets/punk-cut-paper/assets/paper/halftone-black.png +0 -0
  212. package/template/presets/punk-cut-paper/assets/paper/halftone-red.png +0 -0
  213. package/template/presets/punk-cut-paper/assets/paper/halftone-yellow.png +0 -0
  214. package/template/presets/punk-cut-paper/assets/paper/kraft.jpg +0 -0
  215. package/template/presets/punk-cut-paper/assets/paper/newsprint.jpg +0 -0
  216. package/template/presets/punk-cut-paper/assets/paper/paper-cream.jpg +0 -0
  217. package/template/presets/punk-cut-paper/assets/paper/paper-white.jpg +0 -0
  218. package/template/presets/punk-cut-paper/assets/paper/tape.png +0 -0
  219. package/template/presets/punk-cut-paper/build_layers.example.py +150 -0
  220. package/template/presets/punk-cut-paper/poster.jpg +0 -0
  221. package/template/presets/punk-cut-paper/preset.json +15 -0
  222. package/template/presets/punk-cut-paper/preview.mp4 +0 -0
  223. package/template/presets/punk-cut-paper/scenes/Backdrop.tsx +76 -0
  224. package/template/presets/punk-cut-paper/scenes/Motif.tsx +376 -0
  225. package/template/presets/punk-cut-paper/scenes/Photo.tsx +73 -0
  226. package/template/presets/punk-cut-paper/scenes/Ransom.tsx +119 -0
  227. package/template/presets/punk-cut-paper/scenes/Xerox.tsx +31 -0
  228. package/template/presets/punk-cut-paper/scenes/lib/punk.tsx +208 -0
  229. package/template/runtime/composition.tsx +918 -0
  230. package/template/runtime/helpers.tsx +228 -0
  231. package/template/runtime/index.tsx +22 -0
  232. package/template/runtime/types.ts +248 -0
  233. package/template/skill/SKILL.md +149 -0
  234. package/template/skill/references/browser-export.md +61 -0
  235. package/template/skill/references/components.md +38 -0
  236. package/template/skill/references/craft.md +53 -0
  237. package/template/skill/references/cursor.md +91 -0
  238. package/template/skill/references/footage.md +73 -0
  239. package/template/skill/references/format.md +140 -0
  240. package/template/skill/references/presets.md +56 -0
  241. package/template/skill/references/sound.md +128 -0
  242. package/template/starter/.studio/chat.json +1 -0
  243. package/template/starter/assets/.keep +0 -0
  244. package/template/starter/layers.json +46 -0
  245. package/template/starter/notes.md +4 -0
  246. package/template/starter/project.json +13 -0
  247. package/template/starter/renders/.keep +0 -0
  248. package/template/starter/scenes/Title.tsx +38 -0
@@ -0,0 +1,131 @@
1
+ /**
2
+ * A coding agent CLI the studio chat can drive (Claude Code, Codex, …).
3
+ *
4
+ * The chat engine (../chat.ts) owns everything agent-independent: history, the queue, cancel,
5
+ * hand-offs between agents, the pictures shown in the chat. An adapter only knows how to start
6
+ * its CLI for one turn and how to turn the CLI's output into `AgentEvent`s.
7
+ *
8
+ * Adding an agent: write one file that exports an `AgentAdapter` and list it in ./index.ts.
9
+ */
10
+ /** What the page shows about an agent (also printed by the CLI). */
11
+ export interface AgentInfo {
12
+ id: string;
13
+ /** Short name used in the chat copy: "Claude is working". */
14
+ name: string;
15
+ /** The product to install: "Claude Code". */
16
+ product: string;
17
+ found: boolean;
18
+ path: string | null;
19
+ version: string | null;
20
+ error?: string;
21
+ installUrl: string;
22
+ /** What to run once in a terminal to sign in, e.g. `claude`. */
23
+ loginCommand: string;
24
+ }
25
+ /** The MCP server the agent connects to (the agentcut tools). */
26
+ export interface McpServerSpec {
27
+ name: string;
28
+ command: string;
29
+ args: string[];
30
+ env: Record<string, string>;
31
+ }
32
+ /** Everything an adapter needs to start one turn. */
33
+ export interface AgentRun {
34
+ /** The full prompt (studio context + the user's text). Always sent on stdin, never in argv. */
35
+ prompt: string;
36
+ /** Resume this session (an id the adapter reported earlier), or start a new one. */
37
+ sessionId: string | null;
38
+ /** Absolute paths of images attached to this message (frames, pointed-at pictures). */
39
+ images: string[];
40
+ /** The workspace folder (cwd of the process). */
41
+ workspace: string;
42
+ mcp: McpServerSpec;
43
+ /** The same server as a Claude-style `{ mcpServers }` JSON file, for CLIs that take one. */
44
+ mcpConfigPath: string;
45
+ /** Let the agent run shell commands (`--no-bash` turns it off where the CLI allows it). */
46
+ allowShell: boolean;
47
+ /** Extra folders the agent may read but must not change. */
48
+ readDirs: string[];
49
+ }
50
+ /**
51
+ * Tool calls are reported in one vocabulary so the chat (summaries, icons, "files changed",
52
+ * pictures) works the same for every agent:
53
+ *
54
+ * - `Read`, `Write`, `Edit` with `input.file_path`
55
+ * - `Glob`, `Grep` with `input.pattern`
56
+ * - `Bash` with `input.command` (and optional `input.description`)
57
+ * - `WebSearch` with `input.query`, `WebFetch` with `input.url`
58
+ * - `TodoWrite`, `Skill` (`input.skill`)
59
+ * - MCP tools as `mcp__<server>__<tool>` with the tool's arguments
60
+ *
61
+ * Anything else is shown by its name.
62
+ */
63
+ export type AgentEvent =
64
+ /** The CLI's session id: saved so the next turn resumes it. */
65
+ {
66
+ type: "session";
67
+ sessionId: string;
68
+ }
69
+ /** A new assistant message begins (the chat separates it from the previous text). */
70
+ | {
71
+ type: "message-start";
72
+ }
73
+ /** Assistant text: streamed deltas or whole blocks, never both for the same text. */
74
+ | {
75
+ type: "text";
76
+ text: string;
77
+ } | {
78
+ type: "tool-start";
79
+ id: string;
80
+ name: string;
81
+ input: Record<string, unknown>;
82
+ }
83
+ /** `content` is the raw tool result (the chat looks in it for captured frames). */
84
+ | {
85
+ type: "tool-end";
86
+ id: string;
87
+ ok: boolean;
88
+ error?: string;
89
+ content?: unknown;
90
+ }
91
+ /** A problem the CLI reported; used as the turn's error if it ends without a result. */
92
+ | {
93
+ type: "error";
94
+ message: string;
95
+ }
96
+ /** The turn finished. */
97
+ | {
98
+ type: "result";
99
+ ok: boolean;
100
+ error?: string;
101
+ text?: string;
102
+ costUsd?: number;
103
+ durationMs?: number;
104
+ sessionId?: string;
105
+ };
106
+ /** Turns the CLI's stdout lines into events. One parser per turn (it may keep state). */
107
+ export interface AgentParser {
108
+ line(line: string): AgentEvent[];
109
+ }
110
+ export interface AgentAdapter {
111
+ id: string;
112
+ name: string;
113
+ product: string;
114
+ /** The command looked up on PATH. */
115
+ command: string;
116
+ /** Env var that points at the CLI explicitly (skips the PATH lookup). */
117
+ envOverride: string;
118
+ installUrl: string;
119
+ loginCommand: string;
120
+ /** Instructions file the CLI reads from the workspace root (written on every helper start). */
121
+ instructionsFile: string;
122
+ /** Folder (relative to the workspace) where the CLI discovers project skills. */
123
+ skillsDir: string;
124
+ /** How the prompt tells the agent to look at an attached image, e.g. "open it with Read". */
125
+ imageHint: string;
126
+ /** Arguments for one turn. The prompt goes on stdin. */
127
+ buildArgs(run: AgentRun): string[];
128
+ createParser(): AgentParser;
129
+ /** The saved session can't be resumed (stderr of a failed run): start a fresh one. */
130
+ isLostSession(stderr: string): boolean;
131
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * A coding agent CLI the studio chat can drive (Claude Code, Codex, …).
3
+ *
4
+ * The chat engine (../chat.ts) owns everything agent-independent: history, the queue, cancel,
5
+ * hand-offs between agents, the pictures shown in the chat. An adapter only knows how to start
6
+ * its CLI for one turn and how to turn the CLI's output into `AgentEvent`s.
7
+ *
8
+ * Adding an agent: write one file that exports an `AgentAdapter` and list it in ./index.ts.
9
+ */
10
+ export {};
11
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/studio/agents/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG"}
@@ -0,0 +1,29 @@
1
+ import type { WorkspacePaths } from "./workspace.js";
2
+ /**
3
+ * Packages the web app provides to bundles (one copy of React/Remotion on the page).
4
+ * Must match lib/studio/modules.ts (repo root).
5
+ */
6
+ export declare const SHARED_MODULES: string[];
7
+ export interface BundleMessage {
8
+ text: string;
9
+ file?: string;
10
+ line?: number;
11
+ column?: number;
12
+ lineText?: string;
13
+ }
14
+ export interface BundleState {
15
+ slug: string;
16
+ revision: number;
17
+ code: string | null;
18
+ ok: boolean;
19
+ errors: BundleMessage[];
20
+ warnings: BundleMessage[];
21
+ scenes: string[];
22
+ builtAt: number;
23
+ durationMs: number;
24
+ }
25
+ export declare function buildEntrySource(paths: WorkspacePaths, slug: string, scenes: string[]): string;
26
+ /** Build one project's browser bundle (CommonJS, shared modules external). */
27
+ export declare function buildProjectBundle(paths: WorkspacePaths, slug: string, previous: BundleState | undefined): Promise<BundleState>;
28
+ /** Entry for a local `remotion render` (registerRoot with one composition per variant). */
29
+ export declare function buildRenderEntrySource(paths: WorkspacePaths, slug: string, scenes: string[]): string;
@@ -0,0 +1,136 @@
1
+ import { join } from "node:path";
2
+ import { listSceneNames, projectDir } from "./projects.js";
3
+ /**
4
+ * Packages the web app provides to bundles (one copy of React/Remotion on the page).
5
+ * Must match lib/studio/modules.ts (repo root).
6
+ */
7
+ export const SHARED_MODULES = [
8
+ "react",
9
+ "react/jsx-runtime",
10
+ "react/jsx-dev-runtime",
11
+ "react-dom",
12
+ "remotion",
13
+ "@remotion/media",
14
+ "@remotion/transitions",
15
+ "@remotion/shapes",
16
+ "@remotion/paths",
17
+ "@remotion/noise",
18
+ "agentcut/components",
19
+ ];
20
+ const SHARED_PATTERN = /^(react|react-dom|remotion|@remotion\/(media|transitions|shapes|paths|noise))(\/.*)?$|^agentcut\/components$/;
21
+ const toPosix = (path) => path.replace(/\\/g, "/");
22
+ export function buildEntrySource(paths, slug, scenes) {
23
+ const dir = projectDir(paths, slug);
24
+ const lines = [
25
+ `import { createStudioModule } from ${JSON.stringify(toPosix(join(paths.runtime, "index.tsx")))};`,
26
+ ];
27
+ scenes.forEach((scene, index) => {
28
+ lines.push(`import Scene${index} from ${JSON.stringify(toPosix(join(dir, "scenes", scene)))};`);
29
+ });
30
+ lines.push(`export default createStudioModule({ ${scenes
31
+ .map((scene, index) => `${JSON.stringify(scene)}: Scene${index}`)
32
+ .join(", ")} });`);
33
+ return `${lines.join("\n")}\n`;
34
+ }
35
+ function studioPlugin(paths) {
36
+ return {
37
+ name: "agentcut",
38
+ setup(build) {
39
+ build.onResolve({ filter: /^agentcut$/ }, () => ({
40
+ path: join(paths.runtime, "helpers.tsx"),
41
+ }));
42
+ build.onResolve({ filter: SHARED_PATTERN }, (args) => ({ path: args.path, external: true }));
43
+ build.onResolve({ filter: /\.css$/ }, (args) => ({
44
+ errors: [
45
+ {
46
+ text: `CSS imports are not supported in Studio scenes (${args.path}). Use inline styles.`,
47
+ },
48
+ ],
49
+ }));
50
+ },
51
+ };
52
+ }
53
+ function toMessages(list) {
54
+ return list.slice(0, 30).map((message) => ({
55
+ text: message.text,
56
+ file: message.location?.file,
57
+ line: message.location?.line,
58
+ column: message.location?.column,
59
+ lineText: message.location?.lineText,
60
+ }));
61
+ }
62
+ /** Build one project's browser bundle (CommonJS, shared modules external). */
63
+ export async function buildProjectBundle(paths, slug, previous) {
64
+ const esbuild = await import("esbuild");
65
+ const scenes = listSceneNames(projectDir(paths, slug));
66
+ const started = Date.now();
67
+ const revision = (previous?.revision ?? 0) + 1;
68
+ try {
69
+ const result = await esbuild.build({
70
+ stdin: {
71
+ contents: buildEntrySource(paths, slug, scenes),
72
+ resolveDir: paths.render,
73
+ sourcefile: `${slug}.entry.tsx`,
74
+ loader: "tsx",
75
+ },
76
+ bundle: true,
77
+ write: false,
78
+ format: "cjs",
79
+ platform: "browser",
80
+ target: "es2022",
81
+ jsx: "automatic",
82
+ // Fixed compiler settings: esbuild then never searches parent folders for a
83
+ // tsconfig.json (a stray or broken one, e.g. C:\tsconfig.json, breaks the build).
84
+ tsconfigRaw: { compilerOptions: { jsx: "react-jsx", useDefineForClassFields: true, verbatimModuleSyntax: false } },
85
+ sourcemap: "inline",
86
+ logLevel: "silent",
87
+ nodePaths: [join(paths.root, "node_modules")],
88
+ define: { "process.env.NODE_ENV": '"development"' },
89
+ loader: { ".json": "json", ".svg": "text", ".txt": "text" },
90
+ plugins: [studioPlugin(paths)],
91
+ });
92
+ const code = result.outputFiles?.[0]?.text ?? "";
93
+ return {
94
+ slug,
95
+ revision,
96
+ code,
97
+ ok: true,
98
+ errors: [],
99
+ warnings: toMessages(result.warnings),
100
+ scenes,
101
+ builtAt: Date.now(),
102
+ durationMs: Date.now() - started,
103
+ };
104
+ }
105
+ catch (error) {
106
+ const failure = error;
107
+ return {
108
+ slug,
109
+ revision,
110
+ // Keep serving the last good code so the preview keeps playing.
111
+ code: previous?.code ?? null,
112
+ ok: false,
113
+ errors: failure.errors ? toMessages(failure.errors) : [{ text: failure.message ?? String(error) }],
114
+ warnings: failure.warnings ? toMessages(failure.warnings) : [],
115
+ scenes,
116
+ builtAt: Date.now(),
117
+ durationMs: Date.now() - started,
118
+ };
119
+ }
120
+ }
121
+ /** Entry for a local `remotion render` (registerRoot with one composition per variant). */
122
+ export function buildRenderEntrySource(paths, slug, scenes) {
123
+ const dir = projectDir(paths, slug);
124
+ const lines = [
125
+ `import { Composition, registerRoot } from "remotion";`,
126
+ `import { createStudioModule } from ${JSON.stringify(toPosix(join(paths.runtime, "index.tsx")))};`,
127
+ `import project from ${JSON.stringify(toPosix(join(dir, "project.json")))};`,
128
+ `import layers from ${JSON.stringify(toPosix(join(dir, "layers.json")))};`,
129
+ ];
130
+ scenes.forEach((scene, index) => {
131
+ lines.push(`import Scene${index} from ${JSON.stringify(toPosix(join(dir, "scenes", scene)))};`);
132
+ });
133
+ lines.push(`const mod = createStudioModule({ ${scenes.map((s, i) => `${JSON.stringify(s)}: Scene${i}`).join(", ")} });`, `const Root = () => (`, ` <>`, ` {Object.entries(project.variants).map(([variant, size]) => (`, ` <Composition`, ` key={variant}`, ` id={"studio-" + variant}`, ` component={mod.StudioComposition as never}`, ` width={(size as { width: number }).width}`, ` height={(size as { height: number }).height}`, ` fps={project.fps}`, ` durationInFrames={project.durationInFrames}`, ` defaultProps={{ project, layers, variant, assetBase: "", libraryBase: "" } as never}`, ` />`, ` ))}`, ` </>`, `);`, `registerRoot(Root);`);
134
+ return `${lines.join("\n")}\n`;
135
+ }
136
+ //# sourceMappingURL=bundler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bundler.js","sourceRoot":"","sources":["../../src/studio/bundler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAG3D;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,OAAO;IACP,mBAAmB;IACnB,uBAAuB;IACvB,WAAW;IACX,UAAU;IACV,iBAAiB;IACjB,uBAAuB;IACvB,kBAAkB;IAClB,iBAAiB;IACjB,iBAAiB;IACjB,qBAAqB;CACtB,CAAC;AAEF,MAAM,cAAc,GAClB,8GAA8G,CAAC;AAsBjH,MAAM,OAAO,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;AAE3D,MAAM,UAAU,gBAAgB,CAAC,KAAqB,EAAE,IAAY,EAAE,MAAgB;IACpF,MAAM,GAAG,GAAG,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACpC,MAAM,KAAK,GAAG;QACZ,sCAAsC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC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,CAAC,CAAC,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAC5G,sBAAsB,EACtB,MAAM,EACN,kEAAkE,EAClE,oBAAoB,EACpB,uBAAuB,EACvB,kCAAkC,EAClC,oDAAoD,EACpD,mDAAmD,EACnD,sDAAsD,EACtD,2BAA2B,EAC3B,qDAAqD,EACrD,8FAA8F,EAC9F,UAAU,EACV,SAAS,EACT,OAAO,EACP,IAAI,EACJ,qBAAqB,CACtB,CAAC;IACF,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;AACjC,CAAC"}
@@ -0,0 +1,147 @@
1
+ import { type AgentInfo, type McpServerSpec } from "./agents/index.js";
2
+ import type { WorkspacePaths } from "./workspace.js";
3
+ export type ChatPart = {
4
+ type: "text";
5
+ text: string;
6
+ } | {
7
+ type: "tool";
8
+ id: string;
9
+ name: string;
10
+ summary: string;
11
+ file?: string;
12
+ status: "running" | "done" | "error";
13
+ error?: string;
14
+ /** Pictures the agent looked at in this step (project-relative, served by /studio/files). */
15
+ images?: string[];
16
+ };
17
+ export interface ChatMessage {
18
+ id: string;
19
+ role: "user" | "assistant";
20
+ at: number;
21
+ /** assistant: the agent that wrote it (see ./agents). */
22
+ agent?: string;
23
+ text?: string;
24
+ parts?: ChatPart[];
25
+ /** user messages: "queued" while waiting for the running turn; assistant: the turn state. */
26
+ status?: "running" | "done" | "error" | "cancelled" | "queued";
27
+ error?: string;
28
+ costUsd?: number;
29
+ durationMs?: number;
30
+ attachments?: string[];
31
+ /** Project files the user pointed at with this message (assets panel, drag and drop). */
32
+ references?: ChatReference[];
33
+ }
34
+ export interface ChatReference {
35
+ path: string;
36
+ kind: string;
37
+ }
38
+ export interface ChatEngineDeps {
39
+ paths: WorkspacePaths;
40
+ allowBash: boolean;
41
+ emit(event: string, data: unknown): void;
42
+ /** Every agent with its install state (see ./agents). */
43
+ getAgents(): Promise<AgentInfo[]>;
44
+ /** The agent to use when the page doesn't pick one and the chat has none yet. */
45
+ defaultAgent(): Promise<string | null>;
46
+ /** The agentcut MCP server every agent connects to. */
47
+ mcp: McpServerSpec;
48
+ getPageContext(): Record<string, unknown> | null;
49
+ /** Extra folders the agent may read, e.g. the app's repo. */
50
+ addDirs: string[];
51
+ }
52
+ export declare class ChatEngine {
53
+ private readonly deps;
54
+ private readonly turns;
55
+ /** One agent at a time: messages wait here and run in order when the current turn ends. */
56
+ private readonly queue;
57
+ constructor(deps: ChatEngineDeps);
58
+ private chatPath;
59
+ private load;
60
+ private save;
61
+ private upsertMessage;
62
+ private saveSession;
63
+ history(slug: string): {
64
+ sessionId: string | null;
65
+ agent: string | null;
66
+ messages: ChatMessage[];
67
+ running: string | null | undefined;
68
+ };
69
+ reset(slug: string): {
70
+ ok: boolean;
71
+ };
72
+ cancel(slug: string): {
73
+ ok: boolean;
74
+ cancelled: boolean;
75
+ };
76
+ /** The running turn (there is at most one). */
77
+ runningSlug(): string | null;
78
+ /**
79
+ * The agent created a new project from a chat in another one: the conversation moves with
80
+ * it, so the new project's chat shows the work in progress and later messages resume
81
+ * the same session there.
82
+ */
83
+ moveRunningTurn(to: string): boolean;
84
+ cancelAll(): void;
85
+ /** The agent for a message: the one the page picked, else the chat's, else the default. */
86
+ private resolveAgent;
87
+ /**
88
+ * The context block sent with a message, plus the images to attach. Captured when the user
89
+ * sends it (a queued message keeps the playhead it was sent with).
90
+ */
91
+ private buildContext;
92
+ /**
93
+ * The conversation so far, for an agent that takes over a chat another agent started
94
+ * (sessions can't move between CLIs). The project files stay the source of truth.
95
+ */
96
+ private handoff;
97
+ send(slug: string, text: string, context: Record<string, unknown>, agentId?: unknown): Promise<{
98
+ queued: boolean;
99
+ position: number;
100
+ userMessageId: string;
101
+ turnId?: undefined;
102
+ } | {
103
+ turnId: string;
104
+ userMessageId: string;
105
+ queued?: undefined;
106
+ position?: undefined;
107
+ }>;
108
+ /** Synchronous once the agent is resolved, so no other turn can start in between. */
109
+ private startTurn;
110
+ /** Start the next queued message once nothing is running. */
111
+ private drain;
112
+ /** The waiting messages, in order (for the page). */
113
+ queued(): {
114
+ slug: string;
115
+ messageId: string;
116
+ position: number;
117
+ }[];
118
+ /** Edit a message that hasn't started yet. */
119
+ editQueued(slug: string, messageId: string, text: string): {
120
+ ok: boolean;
121
+ };
122
+ /** Take a message out of the queue (it never reaches the agent). */
123
+ removeQueued(slug: string, messageId: string): {
124
+ ok: boolean;
125
+ removed: boolean;
126
+ };
127
+ /** "Stop and send this now": move it to the front and stop the running turn. */
128
+ sendQueuedNow(slug: string, messageId: string): {
129
+ ok: boolean;
130
+ };
131
+ /** Forget the messages waiting for a project (it is being deleted or reset). */
132
+ dropQueued(slug: string): void;
133
+ private startProcess;
134
+ private finishRunningTools;
135
+ private relativeFile;
136
+ /**
137
+ * The pictures a step showed the agent, so the chat can show them too: frames the studio captured
138
+ * (copied out of the bridge's scratch folder, which it prunes) and images it read from the project.
139
+ * (The folder keeps its old name so earlier chats still find their pictures.)
140
+ */
141
+ private imagesFor;
142
+ private pruneFrames;
143
+ private toolSummary;
144
+ private appendText;
145
+ /** Apply one agent event to the running turn: chat parts, session, result. */
146
+ private handleEvent;
147
+ }