@swirls/shuttle 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 (298) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/LICENSE +190 -0
  3. package/NOTICE +5 -0
  4. package/README.md +42 -2
  5. package/dist/api/auth.d.ts +18 -0
  6. package/dist/api/auth.js +15 -0
  7. package/dist/api/common.d.ts +8 -0
  8. package/dist/api/common.js +4 -0
  9. package/dist/api/connections.d.ts +292 -0
  10. package/dist/api/connections.js +114 -0
  11. package/dist/api/github.d.ts +20 -0
  12. package/dist/api/github.js +13 -0
  13. package/dist/api/harness.d.ts +97 -0
  14. package/dist/api/harness.js +47 -0
  15. package/dist/api/index.d.ts +2059 -0
  16. package/dist/api/index.js +37 -0
  17. package/dist/api/runners.d.ts +93 -0
  18. package/dist/api/runners.js +45 -0
  19. package/dist/api/sandbox.d.ts +550 -0
  20. package/dist/api/sandbox.js +210 -0
  21. package/dist/api/sessions.d.ts +318 -0
  22. package/dist/api/sessions.js +154 -0
  23. package/dist/api/tenant.d.ts +54 -0
  24. package/dist/api/tenant.js +19 -0
  25. package/dist/api/timings.d.ts +36 -0
  26. package/dist/api/timings.js +48 -0
  27. package/dist/api/workspace.d.ts +738 -0
  28. package/dist/api/workspace.js +246 -0
  29. package/dist/core/pulls.d.ts +1001 -0
  30. package/dist/core/pulls.js +170 -0
  31. package/dist/core/workspace.d.ts +985 -0
  32. package/dist/core/workspace.js +174 -0
  33. package/dist/react/components/command-palette.d.ts +22 -0
  34. package/dist/react/components/command-palette.js +66 -0
  35. package/dist/react/components/follow-list.d.ts +20 -0
  36. package/dist/react/components/follow-list.js +98 -0
  37. package/dist/react/components/json-tree.d.ts +11 -0
  38. package/dist/react/components/json-tree.js +120 -0
  39. package/dist/react/components/markdown.d.ts +5 -0
  40. package/dist/react/components/markdown.js +29 -0
  41. package/dist/react/components/shuttle-mark.d.ts +7 -0
  42. package/dist/react/components/shuttle-mark.js +9 -0
  43. package/dist/react/components/status-dot.d.ts +9 -0
  44. package/dist/react/components/status-dot.js +27 -0
  45. package/dist/react/components/status.d.ts +6 -0
  46. package/dist/react/components/status.js +66 -0
  47. package/dist/react/components/ui/badge.d.ts +7 -0
  48. package/dist/react/components/ui/badge.js +19 -0
  49. package/dist/react/components/ui/button.d.ts +10 -0
  50. package/dist/react/components/ui/button.js +40 -0
  51. package/dist/react/components/ui/dialog.d.ts +19 -0
  52. package/dist/react/components/ui/dialog.js +34 -0
  53. package/dist/react/components/ui/dropdown-menu.d.ts +14 -0
  54. package/dist/react/components/ui/dropdown-menu.js +33 -0
  55. package/dist/react/components/ui/input.d.ts +3 -0
  56. package/dist/react/components/ui/input.js +6 -0
  57. package/dist/react/components/ui/panel.d.ts +18 -0
  58. package/dist/react/components/ui/panel.js +22 -0
  59. package/dist/react/components/ui/popover.d.ts +7 -0
  60. package/dist/react/components/ui/popover.js +16 -0
  61. package/dist/react/components/ui/resizable.d.ts +7 -0
  62. package/dist/react/components/ui/resizable.js +14 -0
  63. package/dist/react/components/ui/scroll-area.d.ts +14 -0
  64. package/dist/react/components/ui/scroll-area.js +12 -0
  65. package/dist/react/components/ui/select.d.ts +10 -0
  66. package/dist/react/components/ui/select.js +20 -0
  67. package/dist/react/components/ui/sheet.d.ts +8 -0
  68. package/dist/react/components/ui/sheet.js +20 -0
  69. package/dist/react/components/ui/tabs.d.ts +7 -0
  70. package/dist/react/components/ui/tabs.js +16 -0
  71. package/dist/react/components/ui/textarea.d.ts +3 -0
  72. package/dist/react/components/ui/textarea.js +6 -0
  73. package/dist/react/components/ui/tooltip.d.ts +8 -0
  74. package/dist/react/components/ui/tooltip.js +17 -0
  75. package/dist/react/features/artifacts/artifact-links.d.ts +9 -0
  76. package/dist/react/features/artifacts/artifact-links.js +38 -0
  77. package/dist/react/features/artifacts/artifact-pane.d.ts +19 -0
  78. package/dist/react/features/artifacts/artifact-pane.js +64 -0
  79. package/dist/react/features/artifacts/artifact-types.d.ts +59 -0
  80. package/dist/react/features/artifacts/artifact-types.js +69 -0
  81. package/dist/react/features/artifacts/browser-viewer.d.ts +5 -0
  82. package/dist/react/features/artifacts/browser-viewer.js +60 -0
  83. package/dist/react/features/artifacts/diff-style.d.ts +10 -0
  84. package/dist/react/features/artifacts/diff-style.js +21 -0
  85. package/dist/react/features/artifacts/file-pane.d.ts +13 -0
  86. package/dist/react/features/artifacts/file-pane.js +305 -0
  87. package/dist/react/features/artifacts/file-quick-open.d.ts +15 -0
  88. package/dist/react/features/artifacts/file-quick-open.js +74 -0
  89. package/dist/react/features/artifacts/file-search.d.ts +12 -0
  90. package/dist/react/features/artifacts/file-search.js +90 -0
  91. package/dist/react/features/artifacts/media-viewer.d.ts +8 -0
  92. package/dist/react/features/artifacts/media-viewer.js +41 -0
  93. package/dist/react/features/artifacts/review-diff.d.ts +19 -0
  94. package/dist/react/features/artifacts/review-diff.js +59 -0
  95. package/dist/react/features/artifacts/review-viewer.d.ts +4 -0
  96. package/dist/react/features/artifacts/review-viewer.js +337 -0
  97. package/dist/react/features/artifacts/sandbox.d.ts +43 -0
  98. package/dist/react/features/artifacts/sandbox.js +109 -0
  99. package/dist/react/features/artifacts/tab-strip.d.ts +11 -0
  100. package/dist/react/features/artifacts/tab-strip.js +55 -0
  101. package/dist/react/features/artifacts/terminal-theme.d.ts +34 -0
  102. package/dist/react/features/artifacts/terminal-theme.js +62 -0
  103. package/dist/react/features/artifacts/terminal-viewer.d.ts +5 -0
  104. package/dist/react/features/artifacts/terminal-viewer.js +209 -0
  105. package/dist/react/features/artifacts/unified-diff.d.ts +16 -0
  106. package/dist/react/features/artifacts/unified-diff.js +55 -0
  107. package/dist/react/features/artifacts/workspace-viewer.d.ts +16 -0
  108. package/dist/react/features/artifacts/workspace-viewer.js +275 -0
  109. package/dist/react/features/connections/agent-sign-in.d.ts +71 -0
  110. package/dist/react/features/connections/agent-sign-in.js +251 -0
  111. package/dist/react/features/connections/connections-panel.d.ts +8 -0
  112. package/dist/react/features/connections/connections-panel.js +42 -0
  113. package/dist/react/features/connections/login.d.ts +24 -0
  114. package/dist/react/features/connections/login.js +35 -0
  115. package/dist/react/features/connections/places.d.ts +20 -0
  116. package/dist/react/features/connections/places.js +27 -0
  117. package/dist/react/features/connections/queries.d.ts +28 -0
  118. package/dist/react/features/connections/queries.js +8 -0
  119. package/dist/react/features/events/event-cache.d.ts +4 -0
  120. package/dist/react/features/events/event-cache.js +29 -0
  121. package/dist/react/features/events/event-catalog.d.ts +17 -0
  122. package/dist/react/features/events/event-catalog.js +261 -0
  123. package/dist/react/features/events/event-inspector.d.ts +7 -0
  124. package/dist/react/features/events/event-inspector.js +29 -0
  125. package/dist/react/features/events/event-row.d.ts +21 -0
  126. package/dist/react/features/events/event-row.js +34 -0
  127. package/dist/react/features/events/event-stream.d.ts +18 -0
  128. package/dist/react/features/events/event-stream.js +58 -0
  129. package/dist/react/features/events/global-events.d.ts +122 -0
  130. package/dist/react/features/events/global-events.js +329 -0
  131. package/dist/react/features/events/shuttle-events.d.ts +7 -0
  132. package/dist/react/features/events/shuttle-events.js +1 -0
  133. package/dist/react/features/playbook/playbook-page.d.ts +2 -0
  134. package/dist/react/features/playbook/playbook-page.js +36 -0
  135. package/dist/react/features/playbook/playbook-query.d.ts +111 -0
  136. package/dist/react/features/playbook/playbook-query.js +17 -0
  137. package/dist/react/features/pulls/linked-session.d.ts +12 -0
  138. package/dist/react/features/pulls/linked-session.js +22 -0
  139. package/dist/react/features/pulls/pull-detail-sheet.d.ts +10 -0
  140. package/dist/react/features/pulls/pull-detail-sheet.js +41 -0
  141. package/dist/react/features/pulls/pull-fixtures.d.ts +8 -0
  142. package/dist/react/features/pulls/pull-fixtures.js +258 -0
  143. package/dist/react/features/pulls/pull-glyphs.d.ts +24 -0
  144. package/dist/react/features/pulls/pull-glyphs.js +89 -0
  145. package/dist/react/features/pulls/pull-inbox-list.d.ts +13 -0
  146. package/dist/react/features/pulls/pull-inbox-list.js +230 -0
  147. package/dist/react/features/pulls/pull-inbox-pref.d.ts +2 -0
  148. package/dist/react/features/pulls/pull-inbox-pref.js +19 -0
  149. package/dist/react/features/pulls/pull-inbox.d.ts +30 -0
  150. package/dist/react/features/pulls/pull-inbox.js +110 -0
  151. package/dist/react/features/pulls/pull-threads.d.ts +39 -0
  152. package/dist/react/features/pulls/pull-threads.js +145 -0
  153. package/dist/react/features/pulls/pulls.d.ts +120 -0
  154. package/dist/react/features/pulls/pulls.js +414 -0
  155. package/dist/react/features/pulls/session-pull-groups.d.ts +14 -0
  156. package/dist/react/features/pulls/session-pull-groups.js +29 -0
  157. package/dist/react/features/pulls/stack-ladder.d.ts +9 -0
  158. package/dist/react/features/pulls/stack-ladder.js +32 -0
  159. package/dist/react/features/sessions/agent-tree.d.ts +16 -0
  160. package/dist/react/features/sessions/agent-tree.js +100 -0
  161. package/dist/react/features/sessions/agents.d.ts +34 -0
  162. package/dist/react/features/sessions/agents.js +146 -0
  163. package/dist/react/features/sessions/attention.d.ts +32 -0
  164. package/dist/react/features/sessions/attention.js +42 -0
  165. package/dist/react/features/sessions/composer-attachments.d.ts +33 -0
  166. package/dist/react/features/sessions/composer-attachments.js +126 -0
  167. package/dist/react/features/sessions/composer.d.ts +15 -0
  168. package/dist/react/features/sessions/composer.js +327 -0
  169. package/dist/react/features/sessions/context-usage-meter.d.ts +5 -0
  170. package/dist/react/features/sessions/context-usage-meter.js +122 -0
  171. package/dist/react/features/sessions/context-usage.d.ts +54 -0
  172. package/dist/react/features/sessions/context-usage.js +206 -0
  173. package/dist/react/features/sessions/conversation.d.ts +21 -0
  174. package/dist/react/features/sessions/conversation.js +549 -0
  175. package/dist/react/features/sessions/harness-switcher.d.ts +26 -0
  176. package/dist/react/features/sessions/harness-switcher.js +118 -0
  177. package/dist/react/features/sessions/intake-heuristic.d.ts +5 -0
  178. package/dist/react/features/sessions/intake-heuristic.js +28 -0
  179. package/dist/react/features/sessions/interjection-routes.d.ts +13 -0
  180. package/dist/react/features/sessions/interjection-routes.js +72 -0
  181. package/dist/react/features/sessions/llm-models.d.ts +128 -0
  182. package/dist/react/features/sessions/llm-models.js +174 -0
  183. package/dist/react/features/sessions/media-strip.d.ts +25 -0
  184. package/dist/react/features/sessions/media-strip.js +56 -0
  185. package/dist/react/features/sessions/media.d.ts +43 -0
  186. package/dist/react/features/sessions/media.js +115 -0
  187. package/dist/react/features/sessions/model-search.d.ts +6 -0
  188. package/dist/react/features/sessions/model-search.js +16 -0
  189. package/dist/react/features/sessions/model-switcher.d.ts +16 -0
  190. package/dist/react/features/sessions/model-switcher.js +262 -0
  191. package/dist/react/features/sessions/open-pull-request.d.ts +20 -0
  192. package/dist/react/features/sessions/open-pull-request.js +92 -0
  193. package/dist/react/features/sessions/pull-publish-card.d.ts +14 -0
  194. package/dist/react/features/sessions/pull-publish-card.js +88 -0
  195. package/dist/react/features/sessions/recent-sessions.d.ts +11 -0
  196. package/dist/react/features/sessions/recent-sessions.js +29 -0
  197. package/dist/react/features/sessions/seen-sessions.d.ts +16 -0
  198. package/dist/react/features/sessions/seen-sessions.js +108 -0
  199. package/dist/react/features/sessions/session-activity.d.ts +95 -0
  200. package/dist/react/features/sessions/session-activity.js +785 -0
  201. package/dist/react/features/sessions/session-context.d.ts +8 -0
  202. package/dist/react/features/sessions/session-context.js +98 -0
  203. package/dist/react/features/sessions/session-feed.d.ts +243 -0
  204. package/dist/react/features/sessions/session-feed.js +883 -0
  205. package/dist/react/features/sessions/session-header.d.ts +24 -0
  206. package/dist/react/features/sessions/session-header.js +97 -0
  207. package/dist/react/features/sessions/session-layout.d.ts +7 -0
  208. package/dist/react/features/sessions/session-layout.js +87 -0
  209. package/dist/react/features/sessions/session-panes.d.ts +49 -0
  210. package/dist/react/features/sessions/session-panes.js +142 -0
  211. package/dist/react/features/sessions/session-parts.d.ts +35 -0
  212. package/dist/react/features/sessions/session-parts.js +74 -0
  213. package/dist/react/features/sessions/session-place.d.ts +9 -0
  214. package/dist/react/features/sessions/session-place.js +109 -0
  215. package/dist/react/features/sessions/session-pr-pills.d.ts +7 -0
  216. package/dist/react/features/sessions/session-pr-pills.js +28 -0
  217. package/dist/react/features/sessions/session-queries.d.ts +172 -0
  218. package/dist/react/features/sessions/session-queries.js +90 -0
  219. package/dist/react/features/sessions/session-repos.d.ts +8 -0
  220. package/dist/react/features/sessions/session-repos.js +15 -0
  221. package/dist/react/features/sessions/session-share.d.ts +8 -0
  222. package/dist/react/features/sessions/session-share.js +112 -0
  223. package/dist/react/features/sessions/session-tabs.d.ts +38 -0
  224. package/dist/react/features/sessions/session-tabs.js +191 -0
  225. package/dist/react/features/sessions/session.d.ts +103 -0
  226. package/dist/react/features/sessions/session.js +216 -0
  227. package/dist/react/features/sessions/signals.d.ts +13 -0
  228. package/dist/react/features/sessions/signals.js +34 -0
  229. package/dist/react/features/sessions/tab-set.d.ts +20 -0
  230. package/dist/react/features/sessions/tab-set.js +58 -0
  231. package/dist/react/features/sessions/team.d.ts +16 -0
  232. package/dist/react/features/sessions/team.js +35 -0
  233. package/dist/react/features/sessions/timeline.d.ts +53 -0
  234. package/dist/react/features/sessions/timeline.js +153 -0
  235. package/dist/react/features/sessions/use-session-tabs.d.ts +18 -0
  236. package/dist/react/features/sessions/use-session-tabs.js +119 -0
  237. package/dist/react/features/sessions/vendor-models.d.ts +23 -0
  238. package/dist/react/features/sessions/vendor-models.js +61 -0
  239. package/dist/react/features/workspace/activity-dot.d.ts +15 -0
  240. package/dist/react/features/workspace/activity-dot.js +36 -0
  241. package/dist/react/features/workspace/app-sidebar.d.ts +16 -0
  242. package/dist/react/features/workspace/app-sidebar.js +227 -0
  243. package/dist/react/features/workspace/fixture-toggle.d.ts +2 -0
  244. package/dist/react/features/workspace/fixture-toggle.js +72 -0
  245. package/dist/react/features/workspace/folder-group.d.ts +18 -0
  246. package/dist/react/features/workspace/folder-group.js +83 -0
  247. package/dist/react/features/workspace/inline-name-input.d.ts +10 -0
  248. package/dist/react/features/workspace/inline-name-input.js +33 -0
  249. package/dist/react/features/workspace/link-repo-dialog.d.ts +9 -0
  250. package/dist/react/features/workspace/link-repo-dialog.js +76 -0
  251. package/dist/react/features/workspace/repo-chip.d.ts +13 -0
  252. package/dist/react/features/workspace/repo-chip.js +15 -0
  253. package/dist/react/features/workspace/session-row.d.ts +20 -0
  254. package/dist/react/features/workspace/session-row.js +23 -0
  255. package/dist/react/features/workspace/use-debounced.d.ts +2 -0
  256. package/dist/react/features/workspace/use-debounced.js +10 -0
  257. package/dist/react/features/workspace/workspace-context.d.ts +45 -0
  258. package/dist/react/features/workspace/workspace-context.js +245 -0
  259. package/dist/react/features/workspace/workspace-fixtures.d.ts +16 -0
  260. package/dist/react/features/workspace/workspace-fixtures.js +175 -0
  261. package/dist/react/features/workspace/workspace-tree.d.ts +30 -0
  262. package/dist/react/features/workspace/workspace-tree.js +69 -0
  263. package/dist/react/features/workspace/workspace.d.ts +107 -0
  264. package/dist/react/features/workspace/workspace.js +458 -0
  265. package/dist/react/index.d.ts +33 -0
  266. package/dist/react/index.js +35 -0
  267. package/dist/react/lib/cn.d.ts +6 -0
  268. package/dist/react/lib/cn.js +20 -0
  269. package/dist/react/lib/initials.d.ts +6 -0
  270. package/dist/react/lib/initials.js +32 -0
  271. package/dist/react/lib/json.d.ts +33 -0
  272. package/dist/react/lib/json.js +101 -0
  273. package/dist/react/lib/time.d.ts +8 -0
  274. package/dist/react/lib/time.js +57 -0
  275. package/dist/react/lib/use-media-query.d.ts +1 -0
  276. package/dist/react/lib/use-media-query.js +9 -0
  277. package/dist/react/lib/use-now.d.ts +2 -0
  278. package/dist/react/lib/use-now.js +10 -0
  279. package/dist/react/lib/use-width-bucket.d.ts +6 -0
  280. package/dist/react/lib/use-width-bucket.js +28 -0
  281. package/dist/react/parts/index.d.ts +43 -0
  282. package/dist/react/parts/index.js +43 -0
  283. package/dist/react/shuttle/device.d.ts +42 -0
  284. package/dist/react/shuttle/device.js +10 -0
  285. package/dist/react/shuttle/host.d.ts +1126 -0
  286. package/dist/react/shuttle/host.js +93 -0
  287. package/dist/react/shuttle/identity.d.ts +31 -0
  288. package/dist/react/shuttle/identity.js +20 -0
  289. package/dist/react/shuttle/index.d.ts +14 -0
  290. package/dist/react/shuttle/index.js +13 -0
  291. package/dist/react/shuttle/provider.d.ts +41 -0
  292. package/dist/react/shuttle/provider.js +59 -0
  293. package/dist/react/shuttle/router.d.ts +43 -0
  294. package/dist/react/shuttle/router.js +1 -0
  295. package/dist/react/theme.css +456 -0
  296. package/dist/react/ui.d.ts +19 -0
  297. package/dist/react/ui.js +19 -0
  298. package/package.json +100 -4
@@ -0,0 +1,64 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useQueryClient } from '@tanstack/react-query';
3
+ import { LayoutPanelTop } from 'lucide-react';
4
+ import { useEffect, useMemo, useState } from 'react';
5
+ import { Button } from '../../components/ui/button.js';
6
+ import { EmptyState } from '../../components/ui/panel.js';
7
+ import { cn } from '../../lib/cn.js';
8
+ import { useShuttleHost } from '../../shuttle/index.js';
9
+ import { artifactTypeFor, defaultArtifactTypes, launchableArtifactTypes, } from './artifact-types.js';
10
+ import { invalidateWorktree } from './sandbox.js';
11
+ import { TabStrip } from './tab-strip.js';
12
+ export function ArtifactPane({ runId, folderId, events, media, identities, controller, onReveal, types = defaultArtifactTypes, }) {
13
+ const host = useShuttleHost();
14
+ const { tabs, activeTabId, setActiveTabId, openTab, closeTab, reorderTabs, retargetTab } = controller;
15
+ const orderedTabs = useMemo(() => tabs.order.flatMap((id) => (tabs.tabs[id] ? [tabs.tabs[id]] : [])), [tabs]);
16
+ // Tools are how agents change files, so each tool event in the session's stream marks what
17
+ // the tabs have read from the worktree as out of date. The tabs showing it read it again.
18
+ const toolEvents = useMemo(() => events.filter((event) => event.type.startsWith('agent.tool') || event.type.includes('tool'))
19
+ .length, [events]);
20
+ const queryClient = useQueryClient();
21
+ useEffect(() => {
22
+ if (toolEvents > 0) {
23
+ void invalidateWorktree(host, queryClient, runId);
24
+ }
25
+ }, [host, queryClient, runId, toolEvents]);
26
+ // Go to file, on the shortcut editors use for it. It brings the Files tab forward and opens
27
+ // its search, from anywhere on the page.
28
+ const [searchToken, setSearchToken] = useState(0);
29
+ useEffect(() => {
30
+ const onKeyDown = (event) => {
31
+ const mac = /mac|iphone|ipad/i.test(navigator.userAgent);
32
+ const chord = mac ? event.metaKey && !event.ctrlKey : event.ctrlKey && !event.metaKey;
33
+ if (!chord || event.altKey || event.shiftKey || event.key.toLowerCase() !== 'p') {
34
+ return;
35
+ }
36
+ // In a terminal Ctrl+P belongs to the shell: it recalls the previous command.
37
+ if (!mac && event.target instanceof Element && event.target.closest('.xterm')) {
38
+ return;
39
+ }
40
+ event.preventDefault();
41
+ onReveal?.();
42
+ void openTab({ kind: 'files' });
43
+ setSearchToken(Date.now());
44
+ };
45
+ window.addEventListener('keydown', onKeyDown, true);
46
+ return () => window.removeEventListener('keydown', onKeyDown, true);
47
+ }, [openTab, onReveal]);
48
+ return (_jsxs("div", { className: "bg-sidebar flex h-full min-h-0 flex-col", children: [_jsx(TabStrip, { tabs: orderedTabs, types: types, activeTabId: activeTabId, onSelect: setActiveTabId, onClose: (tabId) => void closeTab(tabId), onReorder: (tabIds) => void reorderTabs(tabIds), onOpen: (kind) => void openTab({ kind }) }), orderedTabs.length === 0 ? (_jsxs(EmptyState, { icon: _jsx(LayoutPanelTop, {}), title: "Nothing open yet", children: [_jsx("span", { className: "mb-3 block", children: "Open the workspace to see files and changes, or start a terminal or a browser preview." }), _jsx("span", { className: "flex flex-wrap justify-center gap-1.5", children: launchableArtifactTypes(types)
49
+ .filter((type) => type.launcher?.starter)
50
+ .map((type) => (_jsxs(Button, { variant: "secondary", size: "sm", onClick: () => void openTab({ kind: type.kind }), children: [type.icon, type.label] }, type.kind))) })] })) : (_jsx("div", { className: "relative min-h-0 flex-1", children: orderedTabs.map((tab) => {
51
+ const active = tab.tabId === activeTabId;
52
+ return (_jsx("div", { "data-artifact-tab": tab.tabId, "data-artifact-kind": tab.kind, "data-active": active ? 'true' : 'false',
53
+ // `hidden` (display:none) — not `invisible` — so inactive panels can't paint over the active one.
54
+ className: cn('absolute inset-0 flex min-h-0 flex-col', !active && 'hidden'), "aria-hidden": !active, children: artifactTypeFor(types, tab.kind)?.render({
55
+ tab,
56
+ runId,
57
+ folderId,
58
+ searchToken,
59
+ media,
60
+ identities,
61
+ retarget: (title, target) => void retargetTab(tab.tabId, title, target),
62
+ }) }, tab.tabId));
63
+ }) }))] }));
64
+ }
@@ -0,0 +1,59 @@
1
+ import type { ReactNode } from 'react';
2
+ import type { AgentIdentity } from '../sessions/agents.js';
3
+ import type { SessionMedia } from '../sessions/media.js';
4
+ import type { ArtifactTab, ArtifactTabKind } from '../workspace/workspace.js';
5
+ /** What an artifact type is given to draw one of its tabs. */
6
+ export interface ArtifactViewProps {
7
+ readonly tab: ArtifactTab;
8
+ readonly runId: string;
9
+ readonly folderId?: string;
10
+ /** The session's files: what people attached and what agents shared. */
11
+ readonly media: readonly SessionMedia[];
12
+ readonly identities: ReadonlyMap<string, AgentIdentity>;
13
+ /** Changes each time "go to file" is asked for, for a type that has a file search to open. */
14
+ readonly searchToken: number;
15
+ /** Renames the tab and points it somewhere else, as a browser does when it follows a link. */
16
+ readonly retarget: (title: string, target: string) => void;
17
+ }
18
+ /**
19
+ * One kind of tab in the artifacts pane: what it is called, and how it is drawn. The pane knows
20
+ * nothing about any kind beyond what is registered here, so the set a session is given is the
21
+ * set it can show. `<Shuttle.Session artifactTypes={[...defaultArtifactTypes, mine]}>` adds one.
22
+ *
23
+ * A type of the host's own names its kind `<namespace>:<name>`, as in `acme:designs`, which
24
+ * keeps it apart from Shuttle's kinds. The backend keeps such a tab, with its title and its
25
+ * `target`, without knowing what it shows: `target` is the type's to give meaning to (an id, a
26
+ * path, an address).
27
+ */
28
+ export interface ArtifactType {
29
+ readonly kind: ArtifactTabKind;
30
+ readonly label: string;
31
+ readonly icon: ReactNode;
32
+ /**
33
+ * There is one tab of this kind at most: opening it again brings the one that is open
34
+ * forward. Left out, each opening is a new tab. Shuttle's own kinds decide this themselves.
35
+ */
36
+ readonly single?: boolean;
37
+ /** What a new tab is called, given what it was opened on. Left out, it is the label. */
38
+ readonly title?: (target: string) => string;
39
+ /**
40
+ * Offers the type wherever a tab can be opened by hand: the pane's "+" menu and the command
41
+ * palette. Left out, tabs of this kind are only opened by something else, such as a link in
42
+ * a message.
43
+ */
44
+ readonly launcher?: {
45
+ /** More words the command palette finds it by. */
46
+ readonly keywords?: string;
47
+ /** Also offered as a button in the empty pane. */
48
+ readonly starter?: boolean;
49
+ };
50
+ /** The tab's name in the strip, when it is not the title the tab was saved with. */
51
+ readonly tabLabel?: (tab: ArtifactTab) => string;
52
+ readonly render: (props: ArtifactViewProps) => ReactNode;
53
+ }
54
+ /** The artifact types Shuttle comes with. */
55
+ export declare const defaultArtifactTypes: readonly ArtifactType[];
56
+ /** The type that draws tabs of `kind`. The last one registered for a kind wins. */
57
+ export declare function artifactTypeFor(types: readonly ArtifactType[], kind: string): ArtifactType | undefined;
58
+ /** The types a person can open a tab of by hand, in the order they were registered. */
59
+ export declare function launchableArtifactTypes(types: readonly ArtifactType[]): readonly ArtifactType[];
@@ -0,0 +1,69 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { FileCode2, Files, GitCompareArrows, Globe, Images, ListTree, SquareTerminal, } from 'lucide-react';
3
+ import { BrowserViewer } from './browser-viewer.js';
4
+ import { MediaViewer } from './media-viewer.js';
5
+ import { ReviewViewer } from './review-viewer.js';
6
+ import { TerminalViewer } from './terminal-viewer.js';
7
+ import { WorkspaceViewer } from './workspace-viewer.js';
8
+ /** A file tab's target as a path under the session's worktree, which is how the workspace names files. */
9
+ function worktreePath(runId, target) {
10
+ const root = `/workspace/.wt/${runId}/`;
11
+ return target.startsWith(root) ? target.slice(root.length) : target;
12
+ }
13
+ // One tab shows the workspace. Tabs saved under its earlier names open it too: a Changes tab on
14
+ // what changed, a single-file tab on that file.
15
+ function workspace({ tab, runId, searchToken }) {
16
+ return (_jsx(WorkspaceViewer, { runId: runId, searchToken: searchToken, initialFilter: tab.kind === 'changes' ? 'changed' : undefined, initialPath: tab.kind === 'file' ? worktreePath(runId, tab.target) : undefined }, runId));
17
+ }
18
+ /** The artifact types Shuttle comes with. */
19
+ export const defaultArtifactTypes = [
20
+ {
21
+ kind: 'files',
22
+ label: 'Workspace',
23
+ icon: _jsx(Files, {}),
24
+ launcher: { keywords: 'files changes diff code', starter: true },
25
+ // The workspace tab was once called Files, and tabs saved then still say so.
26
+ tabLabel: () => 'Workspace',
27
+ render: workspace,
28
+ },
29
+ {
30
+ kind: 'terminal',
31
+ label: 'Terminal',
32
+ icon: _jsx(SquareTerminal, {}),
33
+ launcher: { keywords: 'shell console', starter: true },
34
+ render: ({ tab, runId, folderId }) => (_jsx(TerminalViewer, { runId: runId, folderId: folderId, cwd: tab.target })),
35
+ },
36
+ {
37
+ kind: 'browser',
38
+ label: 'Browser',
39
+ icon: _jsx(Globe, {}),
40
+ launcher: { keywords: 'preview web page', starter: true },
41
+ render: ({ tab, runId, retarget }) => (_jsx(BrowserViewer, { runId: runId, target: tab.target, onRetarget: retarget })),
42
+ },
43
+ {
44
+ kind: 'review',
45
+ label: 'Review',
46
+ icon: _jsx(GitCompareArrows, {}),
47
+ launcher: { keywords: 'pull request diff' },
48
+ render: ({ runId, folderId }) => _jsx(ReviewViewer, { runId: runId, folderId: folderId }),
49
+ },
50
+ {
51
+ kind: 'media',
52
+ label: 'Media',
53
+ icon: _jsx(Images, {}),
54
+ launcher: { keywords: 'images video audio files attachments assets generated' },
55
+ render: ({ runId, media, identities }) => (_jsx(MediaViewer, { runId: runId, media: media, identities: identities })),
56
+ },
57
+ { kind: 'changes', label: 'Changes', icon: _jsx(GitCompareArrows, {}), render: workspace },
58
+ { kind: 'file', label: 'File', icon: _jsx(FileCode2, {}), render: workspace },
59
+ // Event history opens as a drawer under the session; it is never shown as a tab.
60
+ { kind: 'events', label: 'Events', icon: _jsx(ListTree, {}), render: () => null },
61
+ ];
62
+ /** The type that draws tabs of `kind`. The last one registered for a kind wins. */
63
+ export function artifactTypeFor(types, kind) {
64
+ return types.findLast((type) => type.kind === kind);
65
+ }
66
+ /** The types a person can open a tab of by hand, in the order they were registered. */
67
+ export function launchableArtifactTypes(types) {
68
+ return types.filter((type) => type.launcher && artifactTypeFor(types, type.kind) === type);
69
+ }
@@ -0,0 +1,5 @@
1
+ export declare function BrowserViewer({ runId, target, onRetarget, }: {
2
+ runId: string;
3
+ target: string;
4
+ onRetarget: (title: string, nextTarget: string) => void;
5
+ }): import("react").JSX.Element;
@@ -0,0 +1,60 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useQuery } from '@tanstack/react-query';
3
+ import { ArrowLeft, ArrowRight, ExternalLink, Globe, RotateCw } from 'lucide-react';
4
+ import { useMemo, useRef, useState } from 'react';
5
+ import { Button } from '../../components/ui/button.js';
6
+ import { Input } from '../../components/ui/input.js';
7
+ import { EmptyState } from '../../components/ui/panel.js';
8
+ import { useApi, useShuttleHost } from '../../shuttle/index.js';
9
+ import { tabTitleForKind } from '../sessions/session-tabs.js';
10
+ import { resolveBrowserTarget } from './sandbox.js';
11
+ export function BrowserViewer({ runId, target, onRetarget, }) {
12
+ const api = useApi();
13
+ const host = useShuttleHost();
14
+ // Where this session's sandbox answers previews. It does not change, so it is asked once.
15
+ const { data: preview } = useQuery(api.sandbox.preview.queryOptions({ input: { id: runId }, staleTime: Infinity }));
16
+ const iframeRef = useRef(null);
17
+ const [draft, setDraft] = useState(target);
18
+ const [syncedTarget, setSyncedTarget] = useState(target);
19
+ const [history, setHistory] = useState(() => (target ? [target] : []));
20
+ const [index, setIndex] = useState(0);
21
+ const [blocked, setBlocked] = useState(false);
22
+ // Keep the address bar in sync when the tab target changes externally.
23
+ if (target !== syncedTarget) {
24
+ setSyncedTarget(target);
25
+ setDraft(target);
26
+ }
27
+ const src = useMemo(() => resolveBrowserTarget(target, preview?.label, preview?.host, host), [target, preview, host]);
28
+ function navigate(next) {
29
+ const resolved = next.trim();
30
+ if (!resolved) {
31
+ return;
32
+ }
33
+ setBlocked(false);
34
+ onRetarget(tabTitleForKind('browser', resolved), resolved);
35
+ setHistory((prev) => [...prev.slice(0, index + 1), resolved]);
36
+ setIndex((prev) => prev + 1);
37
+ }
38
+ function go(delta) {
39
+ const nextIndex = index + delta;
40
+ const entry = history[nextIndex];
41
+ if (!entry) {
42
+ return;
43
+ }
44
+ setIndex(nextIndex);
45
+ setDraft(entry);
46
+ onRetarget(tabTitleForKind('browser', entry), entry);
47
+ }
48
+ return (_jsxs("div", { className: "flex h-full min-h-0 flex-col", children: [_jsxs("div", { className: "flex h-9 shrink-0 items-center gap-1 border-b px-2", children: [_jsx(Button, { variant: "ghost", size: "icon-sm", disabled: index <= 0, onClick: () => go(-1), "aria-label": "Back", children: _jsx(ArrowLeft, {}) }), _jsx(Button, { variant: "ghost", size: "icon-sm", disabled: index >= history.length - 1, onClick: () => go(1), "aria-label": "Forward", children: _jsx(ArrowRight, {}) }), _jsx(Button, { variant: "ghost", size: "icon-sm", onClick: () => {
49
+ const frame = iframeRef.current;
50
+ if (frame && src) {
51
+ frame.src = src;
52
+ }
53
+ }, "aria-label": "Reload", children: _jsx(RotateCw, {}) }), _jsx("form", { className: "min-w-0 flex-1", onSubmit: (event) => {
54
+ event.preventDefault();
55
+ navigate(draft);
56
+ }, children: _jsx(Input, { value: draft, onChange: (event) => setDraft(event.target.value), placeholder: "Port or URL", "aria-label": "Browser address", className: "h-7 w-full rounded-md font-mono text-[11px]" }) }), src ? (_jsx(Button, { variant: "ghost", size: "icon-sm", asChild: true, "aria-label": "Open externally", children: _jsx("a", { href: src, target: "_blank", rel: "noreferrer", children: _jsx(ExternalLink, {}) }) })) : null] }), !src ? (_jsxs(EmptyState, { icon: _jsx(Globe, {}), title: "Open a preview", children: ["Enter a port (e.g. ", _jsx("code", { className: "font-mono", children: "3000" }), " or", ' ', _jsx("code", { className: "font-mono", children: "localhost:3000" }), "). Both proxy through the sandbox container \u2014 not your Mac loopback."] })) : blocked ? (_jsx(EmptyState, { icon: _jsx(Globe, {}), title: "Page blocked framing", children: "This site refuses to load in an iframe. Open it externally instead." })) : (_jsx("iframe", { ref: iframeRef, title: "Browser preview", src: src, className: "bg-background min-h-0 flex-1 border-0",
57
+ // Scripts + same-origin are required for local Vite HMR previews.
58
+ // eslint-disable-next-line react/iframe-missing-sandbox -- intentional for sandbox previews
59
+ sandbox: "allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox allow-scripts allow-same-origin allow-downloads", onError: () => setBlocked(true) }))] }));
60
+ }
@@ -0,0 +1,10 @@
1
+ import type { CSSProperties } from 'react';
2
+ export declare const FILE_OPTIONS: {
3
+ readonly theme: "github-dark-default";
4
+ readonly themeType: 'dark';
5
+ readonly disableFileHeader: true;
6
+ readonly overflow: 'scroll';
7
+ readonly unsafeCSS: ":host, pre { --diffs-bg: var(--background) !important; }";
8
+ };
9
+ /** Diffs draws inside a shadow root, so it is styled through its own variables, not classes. */
10
+ export declare const SURFACE_STYLE: CSSProperties;
@@ -0,0 +1,21 @@
1
+ /** How Pierre's Diffs is drawn wherever the app shows code: the file pane and the review tab. */
2
+ const THEME = 'github-dark-default';
3
+ /**
4
+ * The theme sets its own background on the code. This puts the app's surface there instead, so
5
+ * the code sits on the same colour as everything around it.
6
+ */
7
+ const ON_APP_SURFACE = ':host, pre { --diffs-bg: var(--background) !important; }';
8
+ export const FILE_OPTIONS = {
9
+ theme: THEME,
10
+ themeType: 'dark',
11
+ disableFileHeader: true,
12
+ overflow: 'scroll',
13
+ unsafeCSS: ON_APP_SURFACE,
14
+ };
15
+ /** Diffs draws inside a shadow root, so it is styled through its own variables, not classes. */
16
+ export const SURFACE_STYLE = {
17
+ '--diffs-font-family': 'var(--font-mono)',
18
+ '--diffs-font-size': '12px',
19
+ '--diffs-line-height': '19px',
20
+ '--diffs-tab-size': '2',
21
+ };
@@ -0,0 +1,13 @@
1
+ import { type ChangeStatus } from '@swirls/shuttle/api';
2
+ /** Why a file cannot be edited right now, in words for the person looking at it. Null when it can. */
3
+ export type EditBlock = string | null;
4
+ export default function FilePane({ runId, path, status, editBlock, onDirtyChange, }: {
5
+ runId: string;
6
+ /** `<repository>/<path>`. */
7
+ path: string;
8
+ /** How the session changed this file, if it did. */
9
+ status: ChangeStatus | undefined;
10
+ editBlock: EditBlock;
11
+ /** Told when there is an unsaved edit, and when there no longer is. */
12
+ onDirtyChange: (dirty: boolean) => void;
13
+ }): import("react").JSX.Element;
@@ -0,0 +1,305 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { File as CodeFile, EditProvider, MultiFileDiff, PatchDiff } from '@pierre/diffs/react';
3
+ import { keepPreviousData, useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
4
+ import { FileCode2, FileQuestion, Pencil } from 'lucide-react';
5
+ import { useEffect, useMemo, useRef, useState } from 'react';
6
+ import { MAX_DIAGNOSTICS_CHARS, } from '@swirls/shuttle/api';
7
+ import { Button } from '../../components/ui/button.js';
8
+ import { EmptyState } from '../../components/ui/panel.js';
9
+ import { cn } from '../../lib/cn.js';
10
+ import { statusOf, useApi, useShuttleHost } from '../../shuttle/index.js';
11
+ import { FILE_OPTIONS, SURFACE_STYLE } from './diff-style.js';
12
+ import { invalidateWorktree, patchOf } from './sandbox.js';
13
+ const STATUS_LABEL = { A: 'Added', M: 'Modified', D: 'Deleted' };
14
+ const STATUS_CLASS = {
15
+ A: 'text-status-completed',
16
+ M: 'text-status-waiting',
17
+ D: 'text-destructive',
18
+ };
19
+ /** The editor is loaded the first time someone edits, and kept for the rest of the visit. */
20
+ let editorModule = null;
21
+ const createEditor = (type, options, key) => {
22
+ if (!editorModule) {
23
+ throw new Error('The editor has not loaded yet');
24
+ }
25
+ return new editorModule.Editor(type, options, key);
26
+ };
27
+ /** How long after the last keystroke an edit is sent to the language server. */
28
+ const CHECK_AFTER_TYPING_MS = 350;
29
+ /** How long to wait before asking a language server that was still starting again. */
30
+ const CHECK_AGAIN_MS = 2000;
31
+ const SEVERITY_CLASS = {
32
+ error: 'text-destructive',
33
+ warning: 'text-status-waiting',
34
+ info: 'text-muted-foreground',
35
+ hint: 'text-muted-foreground',
36
+ };
37
+ /** Problems worth a line of their own under the code. Hints stay out of the way. */
38
+ const SHOWN_INLINE = new Set(['error', 'warning']);
39
+ /** `TS2322`, or whatever the server calls the rule. */
40
+ function diagnosticCode(diagnostic) {
41
+ if (!diagnostic.code) {
42
+ return null;
43
+ }
44
+ return (diagnostic.source === 'ts' || diagnostic.source === 'typescript') &&
45
+ /^\d+$/.test(diagnostic.code)
46
+ ? `TS${diagnostic.code}`
47
+ : diagnostic.code;
48
+ }
49
+ /** The editor's squiggles: one per problem, with the message shown on hover. */
50
+ function toMarkers(diagnostics) {
51
+ return diagnostics.map((diagnostic) => {
52
+ const code = diagnosticCode(diagnostic);
53
+ return {
54
+ start: { line: diagnostic.line - 1, character: diagnostic.column - 1 },
55
+ end: { line: diagnostic.endLine - 1, character: diagnostic.endColumn - 1 },
56
+ severity: diagnostic.severity,
57
+ message: code ? `${diagnostic.message} (${code})` : diagnostic.message,
58
+ ...(diagnostic.source ? { source: diagnostic.source } : {}),
59
+ };
60
+ });
61
+ }
62
+ /** Problems grouped under the line they start on, for the read-only views. */
63
+ function byLine(diagnostics) {
64
+ const lines = new Map();
65
+ for (const diagnostic of diagnostics) {
66
+ if (SHOWN_INLINE.has(diagnostic.severity)) {
67
+ lines.set(diagnostic.line, [...(lines.get(diagnostic.line) ?? []), diagnostic]);
68
+ }
69
+ }
70
+ return lines;
71
+ }
72
+ function countLabel(diagnostics) {
73
+ const errors = diagnostics.filter((diagnostic) => diagnostic.severity === 'error').length;
74
+ const warnings = diagnostics.filter((diagnostic) => diagnostic.severity === 'warning').length;
75
+ const parts = [
76
+ errors > 0 ? `${errors} ${errors === 1 ? 'error' : 'errors'}` : null,
77
+ warnings > 0 ? `${warnings} ${warnings === 1 ? 'warning' : 'warnings'}` : null,
78
+ ].filter(Boolean);
79
+ return parts.length > 0 ? parts.join(', ') : null;
80
+ }
81
+ /** The problems on one line, drawn under it. */
82
+ function LineProblems({ problems }) {
83
+ return (_jsx("div", { className: "bg-muted/40 border-border/60 border-y px-3 py-1 font-sans text-[11px] leading-4", children: problems.map((problem) => (_jsxs("div", { className: "flex items-baseline gap-2", children: [_jsx("span", { className: cn('shrink-0 font-medium', SEVERITY_CLASS[problem.severity]), children: problem.severity }), _jsx("span", { className: "text-foreground min-w-0 whitespace-pre-wrap", children: problem.message }), diagnosticCode(problem) ? (_jsx("span", { className: "text-muted-foreground shrink-0", children: diagnosticCode(problem) })) : null] }, `${problem.column}:${problem.code ?? ''}:${problem.message}`))) }));
84
+ }
85
+ /** The file as it is now. `missing` when it is gone, null until that is known. */
86
+ function currentOf(file, gone) {
87
+ if (gone || file?.content === null) {
88
+ return 'missing';
89
+ }
90
+ return file
91
+ ? { content: file.content, binary: Boolean(file.binary), truncated: Boolean(file.truncated) }
92
+ : null;
93
+ }
94
+ /** A language server's answer, once it has one. It has none while it is still starting. */
95
+ function settled(answer) {
96
+ return answer?.status === 'pending' ? undefined : answer;
97
+ }
98
+ /** A language server that is still starting is asked again shortly. */
99
+ const askAgainWhileStarting = (query) => query.state.data?.status === 'pending' ? CHECK_AGAIN_MS : false;
100
+ export default function FilePane({ runId, path, status, editBlock, onDirtyChange, }) {
101
+ const host = useShuttleHost();
102
+ const api = useApi();
103
+ const name = path.split('/').pop() ?? path;
104
+ const queryClient = useQueryClient();
105
+ const [chosenView, setChosenView] = useState('diff');
106
+ const [diffStyle, setDiffStyle] = useState('unified');
107
+ const [editing, setEditing] = useState(false);
108
+ const [dirty, setDirty] = useState(false);
109
+ const [editorError, setEditorError] = useState(null);
110
+ const draft = useRef(null);
111
+ const decision = useRef('reject');
112
+ /** The editor's unsaved text as of a moment after typing stopped. Null until something is typed. */
113
+ const [typed, setTyped] = useState(null);
114
+ const typing = useRef(undefined);
115
+ const editor = useRef(null);
116
+ useEffect(() => () => clearTimeout(typing.current), []);
117
+ // A deleted file has only its changes to show, an unchanged one only itself, and an edit
118
+ // happens on the whole file.
119
+ const view = editing || !status ? 'file' : status === 'D' ? 'diff' : chosenView;
120
+ // Each of these is read again whenever the tab shows the file, and whenever the session's
121
+ // events say its files may have changed (see `ArtifactPane`).
122
+ const fileQuery = useQuery(api.sandbox.file.queryOptions({
123
+ input: { id: runId, path },
124
+ staleTime: 0,
125
+ // The editor owns the text while someone is typing; reloading would pull it out from
126
+ // under them.
127
+ enabled: !editing,
128
+ }));
129
+ // A deleted file is expected to be gone.
130
+ const current = currentOf(fileQuery.data, statusOf(fileQuery.error) === 404);
131
+ const baseQuery = useQuery(api.sandbox.file.queryOptions({
132
+ input: { id: runId, path, version: 'base' },
133
+ staleTime: 0,
134
+ enabled: view === 'diff',
135
+ }));
136
+ // Older saved copies do not record where the session started. Without the starting point,
137
+ // the patch still says what changed.
138
+ const baseUnknown = statusOf(baseQuery.error) === 404;
139
+ const patchQuery = useQuery(api.sandbox.diff.queryOptions({
140
+ input: { id: runId, path },
141
+ staleTime: 0,
142
+ enabled: view === 'diff' && baseUnknown,
143
+ select: patchOf,
144
+ }));
145
+ /** `unknown` when the session's starting point is not recorded: the patch is shown instead. */
146
+ const base = baseUnknown
147
+ ? patchQuery.data === undefined
148
+ ? null
149
+ : 'unknown'
150
+ : (baseQuery.data ?? null);
151
+ const patch = patchQuery.data ?? null;
152
+ const error = (current === 'missing' ? null : fileQuery.error) ??
153
+ (view === 'diff' && !base ? (baseUnknown ? patchQuery.error : baseQuery.error) : null);
154
+ const content = current && current !== 'missing' ? current.content : null;
155
+ const checkable = content !== null && !(current !== 'missing' && current?.binary);
156
+ // Ask the language server about the file: as saved while reading, as typed while editing.
157
+ const savedCheck = useQuery(api.sandbox.diagnostics.saved.queryOptions({
158
+ input: { id: runId, path },
159
+ staleTime: 0,
160
+ enabled: checkable && typed === null,
161
+ refetchInterval: askAgainWhileStarting,
162
+ }));
163
+ // Keyed on the text it is a check of. An answer is kept under the text it was for and only
164
+ // the latest text's answer is read, so a slow answer to an earlier keystroke is never shown
165
+ // over a later one; the request for text that has been typed over is dropped.
166
+ const draftCheck = useQuery(api.sandbox.diagnostics.draft.queryOptions({
167
+ input: { params: { id: runId }, query: { path }, body: { content: typed ?? '' } },
168
+ enabled: checkable && editing && typed !== null && typed.length <= MAX_DIAGNOSTICS_CHARS,
169
+ // The problems found in the text before stay until this text's are known.
170
+ placeholderData: keepPreviousData,
171
+ // No earlier draft is worth keeping once it has been typed over.
172
+ gcTime: 0,
173
+ refetchInterval: askAgainWhileStarting,
174
+ }));
175
+ // Until the first check of an edit answers, what was found in the saved file still stands.
176
+ const checked = (typed === null ? undefined : settled(draftCheck.data)) ?? settled(savedCheck.data);
177
+ const diagnostics = useMemo(() => (checkable && checked?.status === 'ok' ? checked.diagnostics : []), [checkable, checked]);
178
+ // While editing, problems are squiggles in the editor, which keeps them in place as text moves.
179
+ const markers = useRef([]);
180
+ useEffect(() => {
181
+ markers.current = toMarkers(diagnostics);
182
+ if (editing) {
183
+ editor.current?.setMarkers(markers.current);
184
+ }
185
+ }, [editing, diagnostics]);
186
+ const editorOptions = useMemo(() => ({
187
+ onAttach: (attached) => {
188
+ editor.current = attached;
189
+ // The editor attaches after the problems are known, so it is given them here too.
190
+ attached.setMarkers(markers.current);
191
+ },
192
+ }), []);
193
+ // While reading, they are lines under the code. The editor owns annotations during an edit.
194
+ const fileAnnotations = useMemo(() => editing
195
+ ? undefined
196
+ : [...byLine(diagnostics)].map(([lineNumber, metadata]) => ({ lineNumber, metadata })), [editing, diagnostics]);
197
+ const diffAnnotations = useMemo(() => [...byLine(diagnostics)].map(([lineNumber, metadata]) => ({
198
+ side: 'additions',
199
+ lineNumber,
200
+ metadata,
201
+ })), [diagnostics]);
202
+ const problemCount = countLabel(diagnostics);
203
+ const file = useMemo(() => (content === null ? null : { name, contents: content }), [name, content]);
204
+ const oldFile = useMemo(() => base && base !== 'unknown' && base.content !== null ? { name, contents: base.content } : null, [name, base]);
205
+ const diffOptions = useMemo(() => ({ ...FILE_OPTIONS, diffStyle }), [diffStyle]);
206
+ // The cache is brought up to date here, so it happens even if the file's tab has been left by
207
+ // the time the save answers. Leaving the editor is the save button's own business, below.
208
+ const write = useMutation(api.sandbox.write.mutationOptions({
209
+ onSuccess: (_saved, sent) => {
210
+ // What was saved is the file now; the editor's text is kept as it is.
211
+ queryClient.setQueryData(api.sandbox.file.queryKey({ input: { id: runId, path } }), (was) => was && { ...was, content: sent.content });
212
+ // If the last check was of this very text, it is what the saved file's check will say.
213
+ const last = settled(draftCheck.data);
214
+ if (last && typed === sent.content && !draftCheck.isPlaceholderData) {
215
+ queryClient.setQueryData(api.sandbox.diagnostics.saved.queryKey({ input: { id: runId, path } }), last);
216
+ }
217
+ // The workspace's list of changes, this file's diff and its problems follow the save.
218
+ void invalidateWorktree(host, queryClient, runId);
219
+ },
220
+ }));
221
+ const saving = write.isPending;
222
+ const saveError = write.error?.message ?? editorError;
223
+ function stopEditing(outcome) {
224
+ clearTimeout(typing.current);
225
+ decision.current = outcome;
226
+ draft.current = null;
227
+ editor.current = null;
228
+ setTyped(null);
229
+ setEditing(false);
230
+ setDirty(false);
231
+ setEditorError(null);
232
+ write.reset();
233
+ onDirtyChange(false);
234
+ }
235
+ function save() {
236
+ const next = draft.current;
237
+ if (saving) {
238
+ return;
239
+ }
240
+ if (content === null || next === null || next === content) {
241
+ stopEditing('reject');
242
+ return;
243
+ }
244
+ // `expected` is the text the edit started from: the save is refused if the file has
245
+ // changed since, and while agents are working.
246
+ write.mutate({ id: runId, path, content: next, expected: content }, { onSuccess: () => stopEditing('accept') });
247
+ }
248
+ const startEditing = () => {
249
+ setEditorError(null);
250
+ write.reset();
251
+ void import('@pierre/diffs/edit')
252
+ .then((loaded) => {
253
+ editorModule = loaded;
254
+ decision.current = 'reject';
255
+ setEditing(true);
256
+ })
257
+ .catch(() => setEditorError('The editor could not be loaded'));
258
+ };
259
+ if (error && (!current || (view === 'diff' && !base))) {
260
+ return (_jsx(EmptyState, { icon: _jsx(FileQuestion, {}), title: "Could not open file", children: error.message }));
261
+ }
262
+ if (!current || (view === 'diff' && !base)) {
263
+ return (_jsx("div", { className: "text-muted-foreground flex h-full items-center justify-center text-xs", children: "Loading\u2026" }));
264
+ }
265
+ if (current !== 'missing' && current.binary) {
266
+ return (_jsxs(EmptyState, { icon: _jsx(FileCode2, {}), title: "Binary file", children: [name, " cannot be shown as text."] }));
267
+ }
268
+ if (current === 'missing' && view === 'file') {
269
+ return (_jsxs(EmptyState, { icon: _jsx(FileQuestion, {}), title: "Could not open file", children: [path, " is not in the session's files any more."] }));
270
+ }
271
+ const truncated = current !== 'missing' && current.truncated;
272
+ const blocked = editBlock ??
273
+ (status === 'D' ? 'Deleted files cannot be edited.' : null) ??
274
+ (truncated ? 'This file is too large to edit here.' : null);
275
+ return (_jsxs("div", { className: "flex h-full min-h-0 flex-col", onKeyDown: (event) => {
276
+ if (editing && (event.metaKey || event.ctrlKey) && event.key.toLowerCase() === 's') {
277
+ event.preventDefault();
278
+ event.stopPropagation();
279
+ save();
280
+ }
281
+ }, children: [_jsxs("div", { className: "flex h-7 shrink-0 items-center gap-2 border-b px-2.5 text-[11px]", children: [status ? (_jsx("span", { className: cn('shrink-0 font-medium', STATUS_CLASS[status]), children: STATUS_LABEL[status] })) : null, editing ? (_jsx("span", { className: "text-muted-foreground min-w-0 truncate", role: "status", children: saveError ?? (dirty ? 'Unsaved changes' : 'Editing') })) : saveError ? (_jsx("span", { className: "text-destructive min-w-0 truncate", role: "alert", children: saveError })) : blocked ? (_jsx("span", { className: "text-muted-foreground min-w-0 truncate", title: blocked, children: blocked })) : null, problemCount ? (_jsx("span", { className: "text-destructive shrink-0", role: "status", children: problemCount })) : null, _jsx("span", { className: "ml-auto flex shrink-0 items-center gap-1.5", children: editing ? (_jsxs(_Fragment, { children: [_jsx(Button, { variant: "ghost", size: "sm", className: "h-5 px-1.5 text-[11px]", disabled: saving, onClick: () => stopEditing('reject'), children: "Cancel" }), _jsx(Button, { size: "sm", className: "h-5 px-2 text-[11px]", disabled: saving, onClick: save, children: saving ? 'Saving…' : 'Save' })] })) : (_jsxs(_Fragment, { children: [view === 'diff' ? (_jsx(Switch, { label: "Layout", value: diffStyle, onChange: setDiffStyle, options: [
282
+ { value: 'unified', label: 'Unified' },
283
+ { value: 'split', label: 'Split' },
284
+ ] })) : null, status && status !== 'D' ? (_jsx(Switch, { label: "Show", value: view, onChange: setChosenView, options: [
285
+ { value: 'diff', label: 'Changes' },
286
+ { value: 'file', label: 'File' },
287
+ ] })) : null, blocked ? null : (_jsxs(Button, { variant: "ghost", size: "sm", className: "h-5 px-1.5 text-[11px]", onClick: startEditing, children: [_jsx(Pencil, {}), "Edit"] }))] })) })] }), _jsxs("div", { className: "min-h-0 flex-1 overflow-auto", style: SURFACE_STYLE, children: [_jsx(EditProvider, { createEditor: createEditor, children: view === 'file' && file ? (_jsx(CodeFile, { file: file, options: FILE_OPTIONS, edit: editing, editorOptions: editorOptions, lineAnnotations: fileAnnotations, renderAnnotation: (annotation) => _jsx(LineProblems, { problems: annotation.metadata }), onEditChange: (event) => {
288
+ draft.current = event.file.contents;
289
+ // The language server is asked a moment after typing stops, not on every key.
290
+ clearTimeout(typing.current);
291
+ typing.current = setTimeout(() => setTyped(draft.current), CHECK_AFTER_TYPING_MS);
292
+ const changed = event.file.contents !== content;
293
+ if (changed !== dirty) {
294
+ setDirty(changed);
295
+ onDirtyChange(changed);
296
+ }
297
+ }, onEditComplete: () => decision.current })) : base === 'unknown' ? (patch?.trim() ? (_jsx(PatchDiff, { patch: patch, options: diffOptions })) : (_jsx(EmptyState, { icon: _jsx(FileCode2, {}), title: "No changes", children: "This file is the same as when the session started." }))) : // The component takes a file on each side, or exactly one missing side.
298
+ oldFile && file ? (_jsx(MultiFileDiff, { oldFile: oldFile, newFile: file, options: diffOptions, lineAnnotations: diffAnnotations, renderAnnotation: (annotation) => _jsx(LineProblems, { problems: annotation.metadata }) })) : file ? (_jsx(MultiFileDiff, { oldFile: null, newFile: file, options: diffOptions, lineAnnotations: diffAnnotations, renderAnnotation: (annotation) => _jsx(LineProblems, { problems: annotation.metadata }) })) : oldFile ? (_jsx(MultiFileDiff, { oldFile: oldFile, newFile: null, options: diffOptions })) : (_jsx(EmptyState, { icon: _jsx(FileCode2, {}), title: "No changes", children: "This file is the same as when the session started." })) }), truncated ? (_jsx("p", { className: "text-muted-foreground px-4 py-2 text-[11px]", children: "This file is too large to show in full. The rest is cut off." })) : null] })] }));
299
+ }
300
+ /** A two-way switch drawn as one control. */
301
+ function Switch({ label, value, onChange, options, }) {
302
+ return (_jsx("div", { role: "radiogroup", "aria-label": label, className: "flex shrink-0 rounded-md border p-px", children: options.map((option) => (_jsx("button", { type: "button", role: "radio", "aria-checked": option.value === value, onClick: () => onChange(option.value), className: cn('focus-visible:ring-ring/50 flex h-[18px] items-center rounded-[5px] px-1.5 text-[11px] outline-none focus-visible:ring-2', option.value === value
303
+ ? 'bg-accent text-foreground'
304
+ : 'text-muted-foreground hover:text-foreground'), children: option.label }, option.value))) }));
305
+ }
@@ -0,0 +1,15 @@
1
+ /** The hint for the shortcut that opens file search, as this platform writes it. */
2
+ export declare function quickOpenShortcut(): string;
3
+ /**
4
+ * Go to file: type part of a name, arrow to a result, Enter to open it. With nothing typed it
5
+ * lists the files already open, most recent first, then the rest.
6
+ */
7
+ export declare function FileQuickOpen({ open, onOpenChange, paths, recent, onPick, }: {
8
+ open: boolean;
9
+ onOpenChange: (open: boolean) => void;
10
+ /** Every file, as a path under the session's worktree. */
11
+ paths: readonly string[];
12
+ /** Files already open, in the order they were opened. */
13
+ recent: readonly string[];
14
+ onPick: (path: string) => void;
15
+ }): import("react").JSX.Element;