@swirls/shuttle 0.0.0-stage → 0.1.1
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.
- package/CHANGELOG.md +18 -0
- package/LICENSE +190 -0
- package/NOTICE +5 -0
- package/README.md +42 -2
- package/dist/api/auth.d.ts +18 -0
- package/dist/api/auth.js +15 -0
- package/dist/api/common.d.ts +8 -0
- package/dist/api/common.js +4 -0
- package/dist/api/connections.d.ts +292 -0
- package/dist/api/connections.js +114 -0
- package/dist/api/github.d.ts +20 -0
- package/dist/api/github.js +13 -0
- package/dist/api/harness.d.ts +97 -0
- package/dist/api/harness.js +47 -0
- package/dist/api/index.d.ts +2059 -0
- package/dist/api/index.js +37 -0
- package/dist/api/runners.d.ts +93 -0
- package/dist/api/runners.js +45 -0
- package/dist/api/sandbox.d.ts +550 -0
- package/dist/api/sandbox.js +210 -0
- package/dist/api/sessions.d.ts +318 -0
- package/dist/api/sessions.js +154 -0
- package/dist/api/tenant.d.ts +54 -0
- package/dist/api/tenant.js +19 -0
- package/dist/api/timings.d.ts +36 -0
- package/dist/api/timings.js +48 -0
- package/dist/api/workspace.d.ts +738 -0
- package/dist/api/workspace.js +246 -0
- package/dist/core/pulls.d.ts +1001 -0
- package/dist/core/pulls.js +170 -0
- package/dist/core/workspace.d.ts +985 -0
- package/dist/core/workspace.js +174 -0
- package/dist/react/components/command-palette.d.ts +22 -0
- package/dist/react/components/command-palette.js +66 -0
- package/dist/react/components/follow-list.d.ts +20 -0
- package/dist/react/components/follow-list.js +98 -0
- package/dist/react/components/json-tree.d.ts +11 -0
- package/dist/react/components/json-tree.js +120 -0
- package/dist/react/components/markdown.d.ts +5 -0
- package/dist/react/components/markdown.js +29 -0
- package/dist/react/components/shuttle-mark.d.ts +7 -0
- package/dist/react/components/shuttle-mark.js +9 -0
- package/dist/react/components/status-dot.d.ts +9 -0
- package/dist/react/components/status-dot.js +27 -0
- package/dist/react/components/status.d.ts +6 -0
- package/dist/react/components/status.js +66 -0
- package/dist/react/components/ui/badge.d.ts +7 -0
- package/dist/react/components/ui/badge.js +19 -0
- package/dist/react/components/ui/button.d.ts +10 -0
- package/dist/react/components/ui/button.js +40 -0
- package/dist/react/components/ui/dialog.d.ts +19 -0
- package/dist/react/components/ui/dialog.js +34 -0
- package/dist/react/components/ui/dropdown-menu.d.ts +14 -0
- package/dist/react/components/ui/dropdown-menu.js +33 -0
- package/dist/react/components/ui/input.d.ts +3 -0
- package/dist/react/components/ui/input.js +6 -0
- package/dist/react/components/ui/panel.d.ts +18 -0
- package/dist/react/components/ui/panel.js +22 -0
- package/dist/react/components/ui/popover.d.ts +7 -0
- package/dist/react/components/ui/popover.js +16 -0
- package/dist/react/components/ui/resizable.d.ts +7 -0
- package/dist/react/components/ui/resizable.js +14 -0
- package/dist/react/components/ui/scroll-area.d.ts +14 -0
- package/dist/react/components/ui/scroll-area.js +12 -0
- package/dist/react/components/ui/select.d.ts +10 -0
- package/dist/react/components/ui/select.js +20 -0
- package/dist/react/components/ui/sheet.d.ts +8 -0
- package/dist/react/components/ui/sheet.js +20 -0
- package/dist/react/components/ui/tabs.d.ts +7 -0
- package/dist/react/components/ui/tabs.js +16 -0
- package/dist/react/components/ui/textarea.d.ts +3 -0
- package/dist/react/components/ui/textarea.js +6 -0
- package/dist/react/components/ui/tooltip.d.ts +8 -0
- package/dist/react/components/ui/tooltip.js +17 -0
- package/dist/react/features/artifacts/artifact-links.d.ts +9 -0
- package/dist/react/features/artifacts/artifact-links.js +38 -0
- package/dist/react/features/artifacts/artifact-pane.d.ts +19 -0
- package/dist/react/features/artifacts/artifact-pane.js +75 -0
- package/dist/react/features/artifacts/artifact-types.d.ts +59 -0
- package/dist/react/features/artifacts/artifact-types.js +69 -0
- package/dist/react/features/artifacts/browser-viewer.d.ts +5 -0
- package/dist/react/features/artifacts/browser-viewer.js +60 -0
- package/dist/react/features/artifacts/diff-style.d.ts +10 -0
- package/dist/react/features/artifacts/diff-style.js +21 -0
- package/dist/react/features/artifacts/file-pane.d.ts +13 -0
- package/dist/react/features/artifacts/file-pane.js +305 -0
- package/dist/react/features/artifacts/file-quick-open.d.ts +15 -0
- package/dist/react/features/artifacts/file-quick-open.js +74 -0
- package/dist/react/features/artifacts/file-search.d.ts +12 -0
- package/dist/react/features/artifacts/file-search.js +90 -0
- package/dist/react/features/artifacts/media-viewer.d.ts +8 -0
- package/dist/react/features/artifacts/media-viewer.js +41 -0
- package/dist/react/features/artifacts/review-diff.d.ts +19 -0
- package/dist/react/features/artifacts/review-diff.js +59 -0
- package/dist/react/features/artifacts/review-viewer.d.ts +4 -0
- package/dist/react/features/artifacts/review-viewer.js +337 -0
- package/dist/react/features/artifacts/sandbox.d.ts +43 -0
- package/dist/react/features/artifacts/sandbox.js +109 -0
- package/dist/react/features/artifacts/tab-strip.d.ts +11 -0
- package/dist/react/features/artifacts/tab-strip.js +55 -0
- package/dist/react/features/artifacts/terminal-theme.d.ts +34 -0
- package/dist/react/features/artifacts/terminal-theme.js +62 -0
- package/dist/react/features/artifacts/terminal-viewer.d.ts +5 -0
- package/dist/react/features/artifacts/terminal-viewer.js +209 -0
- package/dist/react/features/artifacts/unified-diff.d.ts +16 -0
- package/dist/react/features/artifacts/unified-diff.js +55 -0
- package/dist/react/features/artifacts/workspace-viewer.d.ts +16 -0
- package/dist/react/features/artifacts/workspace-viewer.js +275 -0
- package/dist/react/features/connections/agent-sign-in.d.ts +71 -0
- package/dist/react/features/connections/agent-sign-in.js +251 -0
- package/dist/react/features/connections/connections-panel.d.ts +8 -0
- package/dist/react/features/connections/connections-panel.js +42 -0
- package/dist/react/features/connections/login.d.ts +24 -0
- package/dist/react/features/connections/login.js +35 -0
- package/dist/react/features/connections/places.d.ts +20 -0
- package/dist/react/features/connections/places.js +27 -0
- package/dist/react/features/connections/queries.d.ts +28 -0
- package/dist/react/features/connections/queries.js +8 -0
- package/dist/react/features/events/event-cache.d.ts +4 -0
- package/dist/react/features/events/event-cache.js +29 -0
- package/dist/react/features/events/event-catalog.d.ts +17 -0
- package/dist/react/features/events/event-catalog.js +261 -0
- package/dist/react/features/events/event-inspector.d.ts +7 -0
- package/dist/react/features/events/event-inspector.js +29 -0
- package/dist/react/features/events/event-row.d.ts +21 -0
- package/dist/react/features/events/event-row.js +34 -0
- package/dist/react/features/events/event-stream.d.ts +18 -0
- package/dist/react/features/events/event-stream.js +58 -0
- package/dist/react/features/events/global-events.d.ts +122 -0
- package/dist/react/features/events/global-events.js +329 -0
- package/dist/react/features/events/shuttle-events.d.ts +7 -0
- package/dist/react/features/events/shuttle-events.js +1 -0
- package/dist/react/features/playbook/playbook-page.d.ts +2 -0
- package/dist/react/features/playbook/playbook-page.js +36 -0
- package/dist/react/features/playbook/playbook-query.d.ts +111 -0
- package/dist/react/features/playbook/playbook-query.js +17 -0
- package/dist/react/features/pulls/linked-session.d.ts +12 -0
- package/dist/react/features/pulls/linked-session.js +22 -0
- package/dist/react/features/pulls/pull-detail-sheet.d.ts +10 -0
- package/dist/react/features/pulls/pull-detail-sheet.js +41 -0
- package/dist/react/features/pulls/pull-fixtures.d.ts +8 -0
- package/dist/react/features/pulls/pull-fixtures.js +258 -0
- package/dist/react/features/pulls/pull-glyphs.d.ts +24 -0
- package/dist/react/features/pulls/pull-glyphs.js +89 -0
- package/dist/react/features/pulls/pull-inbox-list.d.ts +13 -0
- package/dist/react/features/pulls/pull-inbox-list.js +230 -0
- package/dist/react/features/pulls/pull-inbox-pref.d.ts +2 -0
- package/dist/react/features/pulls/pull-inbox-pref.js +19 -0
- package/dist/react/features/pulls/pull-inbox.d.ts +30 -0
- package/dist/react/features/pulls/pull-inbox.js +110 -0
- package/dist/react/features/pulls/pull-threads.d.ts +39 -0
- package/dist/react/features/pulls/pull-threads.js +145 -0
- package/dist/react/features/pulls/pulls.d.ts +120 -0
- package/dist/react/features/pulls/pulls.js +414 -0
- package/dist/react/features/pulls/session-pull-groups.d.ts +14 -0
- package/dist/react/features/pulls/session-pull-groups.js +29 -0
- package/dist/react/features/pulls/stack-ladder.d.ts +9 -0
- package/dist/react/features/pulls/stack-ladder.js +32 -0
- package/dist/react/features/sessions/agent-tree.d.ts +16 -0
- package/dist/react/features/sessions/agent-tree.js +100 -0
- package/dist/react/features/sessions/agents.d.ts +34 -0
- package/dist/react/features/sessions/agents.js +146 -0
- package/dist/react/features/sessions/attention.d.ts +32 -0
- package/dist/react/features/sessions/attention.js +42 -0
- package/dist/react/features/sessions/composer-attachments.d.ts +33 -0
- package/dist/react/features/sessions/composer-attachments.js +126 -0
- package/dist/react/features/sessions/composer.d.ts +15 -0
- package/dist/react/features/sessions/composer.js +327 -0
- package/dist/react/features/sessions/context-usage-meter.d.ts +5 -0
- package/dist/react/features/sessions/context-usage-meter.js +122 -0
- package/dist/react/features/sessions/context-usage.d.ts +54 -0
- package/dist/react/features/sessions/context-usage.js +206 -0
- package/dist/react/features/sessions/conversation.d.ts +21 -0
- package/dist/react/features/sessions/conversation.js +549 -0
- package/dist/react/features/sessions/harness-switcher.d.ts +26 -0
- package/dist/react/features/sessions/harness-switcher.js +118 -0
- package/dist/react/features/sessions/intake-heuristic.d.ts +5 -0
- package/dist/react/features/sessions/intake-heuristic.js +28 -0
- package/dist/react/features/sessions/interjection-routes.d.ts +13 -0
- package/dist/react/features/sessions/interjection-routes.js +72 -0
- package/dist/react/features/sessions/llm-models.d.ts +128 -0
- package/dist/react/features/sessions/llm-models.js +174 -0
- package/dist/react/features/sessions/media-strip.d.ts +25 -0
- package/dist/react/features/sessions/media-strip.js +56 -0
- package/dist/react/features/sessions/media.d.ts +43 -0
- package/dist/react/features/sessions/media.js +115 -0
- package/dist/react/features/sessions/model-search.d.ts +6 -0
- package/dist/react/features/sessions/model-search.js +16 -0
- package/dist/react/features/sessions/model-switcher.d.ts +16 -0
- package/dist/react/features/sessions/model-switcher.js +262 -0
- package/dist/react/features/sessions/open-pull-request.d.ts +20 -0
- package/dist/react/features/sessions/open-pull-request.js +92 -0
- package/dist/react/features/sessions/pull-publish-card.d.ts +14 -0
- package/dist/react/features/sessions/pull-publish-card.js +88 -0
- package/dist/react/features/sessions/recent-sessions.d.ts +11 -0
- package/dist/react/features/sessions/recent-sessions.js +29 -0
- package/dist/react/features/sessions/seen-sessions.d.ts +16 -0
- package/dist/react/features/sessions/seen-sessions.js +108 -0
- package/dist/react/features/sessions/session-activity.d.ts +95 -0
- package/dist/react/features/sessions/session-activity.js +785 -0
- package/dist/react/features/sessions/session-context.d.ts +8 -0
- package/dist/react/features/sessions/session-context.js +98 -0
- package/dist/react/features/sessions/session-feed.d.ts +243 -0
- package/dist/react/features/sessions/session-feed.js +883 -0
- package/dist/react/features/sessions/session-header.d.ts +24 -0
- package/dist/react/features/sessions/session-header.js +97 -0
- package/dist/react/features/sessions/session-layout.d.ts +7 -0
- package/dist/react/features/sessions/session-layout.js +87 -0
- package/dist/react/features/sessions/session-panes.d.ts +49 -0
- package/dist/react/features/sessions/session-panes.js +142 -0
- package/dist/react/features/sessions/session-parts.d.ts +35 -0
- package/dist/react/features/sessions/session-parts.js +74 -0
- package/dist/react/features/sessions/session-place.d.ts +9 -0
- package/dist/react/features/sessions/session-place.js +109 -0
- package/dist/react/features/sessions/session-pr-pills.d.ts +7 -0
- package/dist/react/features/sessions/session-pr-pills.js +28 -0
- package/dist/react/features/sessions/session-queries.d.ts +172 -0
- package/dist/react/features/sessions/session-queries.js +90 -0
- package/dist/react/features/sessions/session-repos.d.ts +8 -0
- package/dist/react/features/sessions/session-repos.js +15 -0
- package/dist/react/features/sessions/session-share.d.ts +8 -0
- package/dist/react/features/sessions/session-share.js +112 -0
- package/dist/react/features/sessions/session-tabs.d.ts +38 -0
- package/dist/react/features/sessions/session-tabs.js +191 -0
- package/dist/react/features/sessions/session.d.ts +103 -0
- package/dist/react/features/sessions/session.js +216 -0
- package/dist/react/features/sessions/signals.d.ts +13 -0
- package/dist/react/features/sessions/signals.js +34 -0
- package/dist/react/features/sessions/tab-set.d.ts +20 -0
- package/dist/react/features/sessions/tab-set.js +58 -0
- package/dist/react/features/sessions/team.d.ts +16 -0
- package/dist/react/features/sessions/team.js +35 -0
- package/dist/react/features/sessions/timeline.d.ts +53 -0
- package/dist/react/features/sessions/timeline.js +153 -0
- package/dist/react/features/sessions/use-session-tabs.d.ts +18 -0
- package/dist/react/features/sessions/use-session-tabs.js +119 -0
- package/dist/react/features/sessions/vendor-models.d.ts +23 -0
- package/dist/react/features/sessions/vendor-models.js +61 -0
- package/dist/react/features/workspace/activity-dot.d.ts +15 -0
- package/dist/react/features/workspace/activity-dot.js +36 -0
- package/dist/react/features/workspace/app-sidebar.d.ts +16 -0
- package/dist/react/features/workspace/app-sidebar.js +227 -0
- package/dist/react/features/workspace/fixture-toggle.d.ts +2 -0
- package/dist/react/features/workspace/fixture-toggle.js +72 -0
- package/dist/react/features/workspace/folder-group.d.ts +18 -0
- package/dist/react/features/workspace/folder-group.js +83 -0
- package/dist/react/features/workspace/inline-name-input.d.ts +10 -0
- package/dist/react/features/workspace/inline-name-input.js +33 -0
- package/dist/react/features/workspace/link-repo-dialog.d.ts +9 -0
- package/dist/react/features/workspace/link-repo-dialog.js +76 -0
- package/dist/react/features/workspace/repo-chip.d.ts +13 -0
- package/dist/react/features/workspace/repo-chip.js +15 -0
- package/dist/react/features/workspace/session-row.d.ts +20 -0
- package/dist/react/features/workspace/session-row.js +23 -0
- package/dist/react/features/workspace/use-debounced.d.ts +2 -0
- package/dist/react/features/workspace/use-debounced.js +10 -0
- package/dist/react/features/workspace/workspace-context.d.ts +45 -0
- package/dist/react/features/workspace/workspace-context.js +245 -0
- package/dist/react/features/workspace/workspace-fixtures.d.ts +16 -0
- package/dist/react/features/workspace/workspace-fixtures.js +175 -0
- package/dist/react/features/workspace/workspace-tree.d.ts +30 -0
- package/dist/react/features/workspace/workspace-tree.js +69 -0
- package/dist/react/features/workspace/workspace.d.ts +107 -0
- package/dist/react/features/workspace/workspace.js +458 -0
- package/dist/react/index.d.ts +33 -0
- package/dist/react/index.js +35 -0
- package/dist/react/lib/cn.d.ts +6 -0
- package/dist/react/lib/cn.js +20 -0
- package/dist/react/lib/initials.d.ts +6 -0
- package/dist/react/lib/initials.js +32 -0
- package/dist/react/lib/json.d.ts +33 -0
- package/dist/react/lib/json.js +101 -0
- package/dist/react/lib/time.d.ts +8 -0
- package/dist/react/lib/time.js +57 -0
- package/dist/react/lib/use-media-query.d.ts +1 -0
- package/dist/react/lib/use-media-query.js +9 -0
- package/dist/react/lib/use-now.d.ts +2 -0
- package/dist/react/lib/use-now.js +10 -0
- package/dist/react/lib/use-width-bucket.d.ts +6 -0
- package/dist/react/lib/use-width-bucket.js +28 -0
- package/dist/react/parts/index.d.ts +43 -0
- package/dist/react/parts/index.js +43 -0
- package/dist/react/shuttle/device.d.ts +42 -0
- package/dist/react/shuttle/device.js +10 -0
- package/dist/react/shuttle/host.d.ts +1126 -0
- package/dist/react/shuttle/host.js +93 -0
- package/dist/react/shuttle/identity.d.ts +31 -0
- package/dist/react/shuttle/identity.js +20 -0
- package/dist/react/shuttle/index.d.ts +14 -0
- package/dist/react/shuttle/index.js +13 -0
- package/dist/react/shuttle/provider.d.ts +41 -0
- package/dist/react/shuttle/provider.js +59 -0
- package/dist/react/shuttle/router.d.ts +43 -0
- package/dist/react/shuttle/router.js +1 -0
- package/dist/react/theme.css +456 -0
- package/dist/react/ui.d.ts +19 -0
- package/dist/react/ui.js +19 -0
- package/package.json +100 -4
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Colours and font for the terminal. xterm draws to a canvas, so it needs real colour values and
|
|
3
|
+
* a real font list: it cannot follow CSS variables the way the rest of the app does. These are
|
|
4
|
+
* read from the app's theme once, when a terminal opens.
|
|
5
|
+
*/
|
|
6
|
+
/** A CSS colour (any syntax the browser accepts, including `var()` and `oklch()`) as `#rrggbb`. */
|
|
7
|
+
export function resolveColor(value, fallback) {
|
|
8
|
+
try {
|
|
9
|
+
const probe = document.createElement('span');
|
|
10
|
+
probe.style.color = value;
|
|
11
|
+
probe.style.display = 'none';
|
|
12
|
+
document.body.append(probe);
|
|
13
|
+
const computed = getComputedStyle(probe).color;
|
|
14
|
+
probe.remove();
|
|
15
|
+
const context = document.createElement('canvas').getContext('2d', { willReadFrequently: true });
|
|
16
|
+
if (!context || !computed) {
|
|
17
|
+
return fallback;
|
|
18
|
+
}
|
|
19
|
+
context.fillStyle = computed;
|
|
20
|
+
context.fillRect(0, 0, 1, 1);
|
|
21
|
+
const [red = 0, green = 0, blue = 0] = context.getImageData(0, 0, 1, 1).data;
|
|
22
|
+
return `#${[red, green, blue].map((part) => part.toString(16).padStart(2, '0')).join('')}`;
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return fallback;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/** The app's monospace font list, as a value a canvas can use. */
|
|
29
|
+
export function terminalFontFamily() {
|
|
30
|
+
const declared = getComputedStyle(document.documentElement).getPropertyValue('--font-mono').trim();
|
|
31
|
+
return declared || 'ui-monospace, SFMono-Regular, Menlo, Consolas, monospace';
|
|
32
|
+
}
|
|
33
|
+
/** The terminal's colours: the app's surface and text, and sixteen ANSI colours tuned to sit on it. */
|
|
34
|
+
export function terminalTheme() {
|
|
35
|
+
const background = resolveColor('var(--background)', '#101114');
|
|
36
|
+
const foreground = resolveColor('var(--foreground)', '#e9eaee');
|
|
37
|
+
const muted = resolveColor('var(--muted-foreground)', '#9a9ca6');
|
|
38
|
+
return {
|
|
39
|
+
background,
|
|
40
|
+
foreground,
|
|
41
|
+
cursor: resolveColor('var(--brand)', '#6cb0f0'),
|
|
42
|
+
cursorAccent: background,
|
|
43
|
+
selectionBackground: `${resolveColor('var(--brand)', '#6cb0f0')}55`,
|
|
44
|
+
selectionInactiveBackground: `${muted}33`,
|
|
45
|
+
black: resolveColor('var(--secondary)', '#22232a'),
|
|
46
|
+
red: resolveColor('oklch(0.7 0.17 25)', '#f0706a'),
|
|
47
|
+
green: resolveColor('oklch(0.78 0.14 155)', '#62c98b'),
|
|
48
|
+
yellow: resolveColor('oklch(0.82 0.13 85)', '#e0b85c'),
|
|
49
|
+
blue: resolveColor('oklch(0.74 0.13 250)', '#6ca8f0'),
|
|
50
|
+
magenta: resolveColor('oklch(0.74 0.13 310)', '#c58be6'),
|
|
51
|
+
cyan: resolveColor('oklch(0.8 0.1 205)', '#62c6d6'),
|
|
52
|
+
white: resolveColor('oklch(0.86 0.006 265)', '#d2d3d8'),
|
|
53
|
+
brightBlack: muted,
|
|
54
|
+
brightRed: resolveColor('oklch(0.77 0.15 25)', '#ff8f88'),
|
|
55
|
+
brightGreen: resolveColor('oklch(0.85 0.14 155)', '#7fe0a4'),
|
|
56
|
+
brightYellow: resolveColor('oklch(0.88 0.13 90)', '#f0cf7a'),
|
|
57
|
+
brightBlue: resolveColor('oklch(0.81 0.11 250)', '#8fc0ff'),
|
|
58
|
+
brightMagenta: resolveColor('oklch(0.81 0.12 310)', '#d9a6f5'),
|
|
59
|
+
brightCyan: resolveColor('oklch(0.87 0.09 205)', '#86dcea'),
|
|
60
|
+
brightWhite: resolveColor('oklch(0.98 0.003 265)', '#f8f8fa'),
|
|
61
|
+
};
|
|
62
|
+
}
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useQuery } from '@tanstack/react-query';
|
|
3
|
+
import { RotateCw, SquareTerminal } from 'lucide-react';
|
|
4
|
+
import { useEffect, useRef, useState } from 'react';
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
import { Button } from '../../components/ui/button.js';
|
|
7
|
+
import { EmptyState } from '../../components/ui/panel.js';
|
|
8
|
+
import { cn } from '../../lib/cn.js';
|
|
9
|
+
import { possessive, useApi, useOrgPeople, useShuttleHost, useTenant } from '../../shuttle/index.js';
|
|
10
|
+
import { sandboxTerminalUrl } from './sandbox.js';
|
|
11
|
+
import { terminalFontFamily, terminalTheme } from './terminal-theme.js';
|
|
12
|
+
/** What Shuttle sends down the terminal socket in place of output when something is wrong. */
|
|
13
|
+
const TerminalNotice = z.object({ type: z.string().optional(), error: z.string().optional() });
|
|
14
|
+
const FONT_SIZE = 12.5;
|
|
15
|
+
const dim = (text) => `\u001B[2m${text}\u001B[0m`;
|
|
16
|
+
export function TerminalViewer({ runId, folderId, cwd, }) {
|
|
17
|
+
const host = useShuttleHost();
|
|
18
|
+
const api = useApi();
|
|
19
|
+
const containerRef = useRef(null);
|
|
20
|
+
const reconnectRef = useRef(() => { });
|
|
21
|
+
const [status, setStatus] = useState('connecting');
|
|
22
|
+
const [error, setError] = useState(null);
|
|
23
|
+
const [unsupported, setUnsupported] = useState(false);
|
|
24
|
+
// Asked whenever the terminal is opened, since the session may have moved since.
|
|
25
|
+
const { data: place = null } = useQuery(api.sandbox.place.get.queryOptions({ input: { id: runId }, staleTime: 0 }));
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
const el = containerRef.current;
|
|
28
|
+
if (!el) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
let disposed = false;
|
|
32
|
+
let socket = null;
|
|
33
|
+
let dispose = () => { };
|
|
34
|
+
async function start(element) {
|
|
35
|
+
const [{ Terminal }, { FitAddon }, { WebglAddon }] = await Promise.all([
|
|
36
|
+
import('@xterm/xterm'),
|
|
37
|
+
import('@xterm/addon-fit'),
|
|
38
|
+
import('@xterm/addon-webgl'),
|
|
39
|
+
import('@xterm/xterm/css/xterm.css'),
|
|
40
|
+
]);
|
|
41
|
+
const fontFamily = terminalFontFamily();
|
|
42
|
+
// The cell size is measured from the font when the terminal opens. Measured before the web
|
|
43
|
+
// font has loaded, every character afterwards sits in a cell of the wrong width.
|
|
44
|
+
await document.fonts.load(`${FONT_SIZE}px ${fontFamily}`).catch(() => { });
|
|
45
|
+
if (disposed) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const term = new Terminal({
|
|
49
|
+
fontFamily,
|
|
50
|
+
fontSize: FONT_SIZE,
|
|
51
|
+
lineHeight: 1.3,
|
|
52
|
+
fontWeight: '400',
|
|
53
|
+
fontWeightBold: '600',
|
|
54
|
+
cursorBlink: true,
|
|
55
|
+
cursorStyle: 'bar',
|
|
56
|
+
cursorInactiveStyle: 'outline',
|
|
57
|
+
scrollback: 10_000,
|
|
58
|
+
macOptionIsMeta: true,
|
|
59
|
+
// Bold stays the colour it was given, as modern terminals do.
|
|
60
|
+
drawBoldTextInBrightColors: false,
|
|
61
|
+
// Lifts colours a program picks that would be unreadable on this background.
|
|
62
|
+
minimumContrastRatio: 4.5,
|
|
63
|
+
theme: terminalTheme(),
|
|
64
|
+
});
|
|
65
|
+
const fit = new FitAddon();
|
|
66
|
+
term.loadAddon(fit);
|
|
67
|
+
term.open(element);
|
|
68
|
+
// The GPU renderer draws box characters and dense output cleanly. Where a browser has no
|
|
69
|
+
// WebGL, or loses the context, xterm's own renderer carries on.
|
|
70
|
+
try {
|
|
71
|
+
const webgl = new WebglAddon();
|
|
72
|
+
webgl.onContextLoss(() => webgl.dispose());
|
|
73
|
+
term.loadAddon(webgl);
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
// No WebGL here.
|
|
77
|
+
}
|
|
78
|
+
const refit = () => {
|
|
79
|
+
// A hidden tab has no size; fitting to it would shrink the shell to nothing.
|
|
80
|
+
if (element.clientWidth > 0 && element.clientHeight > 0) {
|
|
81
|
+
fit.fit();
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
refit();
|
|
85
|
+
term.focus();
|
|
86
|
+
const send = (data) => {
|
|
87
|
+
if (socket?.readyState === WebSocket.OPEN) {
|
|
88
|
+
socket.send(data);
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
const connect = () => {
|
|
92
|
+
setStatus('connecting');
|
|
93
|
+
setError(null);
|
|
94
|
+
const opened = new WebSocket(sandboxTerminalUrl(host, { runId, folderId }, { cwd: cwd || undefined, cols: term.cols, rows: term.rows }));
|
|
95
|
+
opened.binaryType = 'arraybuffer';
|
|
96
|
+
socket = opened;
|
|
97
|
+
opened.addEventListener('open', () => {
|
|
98
|
+
if (!disposed) {
|
|
99
|
+
setStatus('connected');
|
|
100
|
+
// The size may have changed while the sandbox was waking.
|
|
101
|
+
send(JSON.stringify({ type: 'resize', cols: term.cols, rows: term.rows }));
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
opened.addEventListener('message', (event) => {
|
|
105
|
+
if (typeof event.data !== 'string') {
|
|
106
|
+
term.write(new Uint8Array(event.data));
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
// Text starting with a brace may be a notice from Shuttle rather than output.
|
|
110
|
+
if (event.data.startsWith('{')) {
|
|
111
|
+
try {
|
|
112
|
+
const message = TerminalNotice.parse(JSON.parse(event.data));
|
|
113
|
+
if (message.type === 'error') {
|
|
114
|
+
if (message.error === 'container-mode-required') {
|
|
115
|
+
setUnsupported(true);
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
setError(message.error ?? 'Terminal error');
|
|
119
|
+
}
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
catch {
|
|
124
|
+
// Output after all.
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
term.write(event.data);
|
|
128
|
+
});
|
|
129
|
+
opened.addEventListener('close', (event) => {
|
|
130
|
+
if (disposed || socket !== opened) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
if (event.code === 1011 || event.reason.includes('container-mode-required')) {
|
|
134
|
+
setUnsupported(true);
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
setStatus('closed');
|
|
138
|
+
term.write(`\r\n${dim('Disconnected. Press Enter to reconnect.')}\r\n`);
|
|
139
|
+
});
|
|
140
|
+
};
|
|
141
|
+
reconnectRef.current = () => {
|
|
142
|
+
socket?.close();
|
|
143
|
+
term.reset();
|
|
144
|
+
connect();
|
|
145
|
+
term.focus();
|
|
146
|
+
};
|
|
147
|
+
term.onData((data) => {
|
|
148
|
+
if (socket?.readyState === WebSocket.OPEN) {
|
|
149
|
+
socket.send(data);
|
|
150
|
+
}
|
|
151
|
+
else if (socket?.readyState === WebSocket.CLOSED && data === '\r') {
|
|
152
|
+
reconnectRef.current();
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
term.onResize(({ cols, rows }) => send(JSON.stringify({ type: 'resize', cols, rows })));
|
|
156
|
+
let frame = 0;
|
|
157
|
+
const resizeObserver = new ResizeObserver(() => {
|
|
158
|
+
cancelAnimationFrame(frame);
|
|
159
|
+
frame = requestAnimationFrame(refit);
|
|
160
|
+
});
|
|
161
|
+
resizeObserver.observe(element);
|
|
162
|
+
dispose = () => {
|
|
163
|
+
cancelAnimationFrame(frame);
|
|
164
|
+
resizeObserver.disconnect();
|
|
165
|
+
term.dispose();
|
|
166
|
+
};
|
|
167
|
+
connect();
|
|
168
|
+
}
|
|
169
|
+
start(el).catch((cause) => {
|
|
170
|
+
if (!disposed) {
|
|
171
|
+
setError(cause instanceof Error ? cause.message : 'Failed to start terminal');
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
return () => {
|
|
175
|
+
disposed = true;
|
|
176
|
+
socket?.close();
|
|
177
|
+
dispose();
|
|
178
|
+
};
|
|
179
|
+
}, [host, runId, folderId, cwd]);
|
|
180
|
+
if (unsupported) {
|
|
181
|
+
return (_jsx(EmptyState, { icon: _jsx(SquareTerminal, {}), title: "Terminal unavailable", children: "This deployment runs sessions without a sandbox, so there is no shell to open." }));
|
|
182
|
+
}
|
|
183
|
+
return (_jsxs("div", { className: "flex h-full min-h-0 flex-col", children: [_jsx(TerminalBar, { place: place, status: status, error: error, onReconnect: () => reconnectRef.current() }), _jsx("div", { className: "bg-background min-h-0 flex-1 py-2 pr-1 pl-3", children: _jsx("div", { ref: containerRef, className: "h-full w-full" }) })] }));
|
|
184
|
+
}
|
|
185
|
+
/** Says whose sandbox the shell is in, whether the session's files are there, and its state. */
|
|
186
|
+
function TerminalBar({ place, status, error, onReconnect, }) {
|
|
187
|
+
const me = useTenant().user.id;
|
|
188
|
+
const people = useOrgPeople();
|
|
189
|
+
const where = place?.personal ? 'Your sandbox' : 'Session sandbox';
|
|
190
|
+
const elsewhere = place?.personal && !place.here
|
|
191
|
+
? place.holderId
|
|
192
|
+
? `This session's files are in ${possessive(place.holderId, me, people)} sandbox, not here.`
|
|
193
|
+
: 'This session has not worked in a sandbox yet, so its files are not here.'
|
|
194
|
+
: null;
|
|
195
|
+
const state = error
|
|
196
|
+
? error
|
|
197
|
+
: status === 'connecting'
|
|
198
|
+
? place?.personal
|
|
199
|
+
? 'Waking your sandbox…'
|
|
200
|
+
: 'Connecting…'
|
|
201
|
+
: status === 'closed'
|
|
202
|
+
? 'Disconnected'
|
|
203
|
+
: null;
|
|
204
|
+
return (_jsxs("div", { className: "text-muted-foreground flex h-7 shrink-0 items-center gap-2 border-b px-3 text-[11px]", children: [_jsx("span", { "aria-hidden": true, className: cn('size-1.5 shrink-0 rounded-full', error || status === 'closed'
|
|
205
|
+
? 'bg-status-failed'
|
|
206
|
+
: status === 'connected'
|
|
207
|
+
? 'bg-status-completed'
|
|
208
|
+
: 'bg-status-waiting animate-pulse') }), _jsx("span", { className: "text-foreground shrink-0 font-medium", children: where }), elsewhere ? (_jsx("span", { className: "min-w-0 truncate", title: elsewhere, children: elsewhere })) : null, _jsxs("span", { className: "ml-auto flex shrink-0 items-center gap-1.5", role: "status", children: [state, error || status === 'closed' ? (_jsxs(Button, { variant: "ghost", size: "sm", className: "h-5 px-1.5 text-[11px]", onClick: onReconnect, children: [_jsx(RotateCw, {}), "Reconnect"] })) : null] })] }));
|
|
209
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type DiffLineKind = 'ctx' | 'add' | 'del' | 'hunk' | 'meta';
|
|
2
|
+
export interface DiffLine {
|
|
3
|
+
readonly kind: DiffLineKind;
|
|
4
|
+
readonly text: string;
|
|
5
|
+
/** 1-based line number on the new (RIGHT) side, when applicable. */
|
|
6
|
+
readonly newLine?: number;
|
|
7
|
+
/** 1-based line number on the old (LEFT) side, when applicable. */
|
|
8
|
+
readonly oldLine?: number;
|
|
9
|
+
}
|
|
10
|
+
export interface DiffFile {
|
|
11
|
+
readonly repo: string;
|
|
12
|
+
readonly path: string;
|
|
13
|
+
readonly lines: DiffLine[];
|
|
14
|
+
}
|
|
15
|
+
/** Parse a unified diff into per-file line rows with optional old/new line numbers. */
|
|
16
|
+
export declare function parseUnifiedDiff(diff: string, repo: string): DiffFile[];
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/** Parse a unified diff into per-file line rows with optional old/new line numbers. */
|
|
2
|
+
export function parseUnifiedDiff(diff, repo) {
|
|
3
|
+
if (!diff.trim()) {
|
|
4
|
+
return [];
|
|
5
|
+
}
|
|
6
|
+
const files = [];
|
|
7
|
+
let current = null;
|
|
8
|
+
let newLine = 0;
|
|
9
|
+
let oldLine = 0;
|
|
10
|
+
for (const raw of diff.split('\n')) {
|
|
11
|
+
if (raw.startsWith('diff --git ')) {
|
|
12
|
+
const match = raw.match(/b\/(.+)$/);
|
|
13
|
+
current = {
|
|
14
|
+
repo,
|
|
15
|
+
path: match?.[1] ?? 'unknown',
|
|
16
|
+
lines: [],
|
|
17
|
+
};
|
|
18
|
+
files.push(current);
|
|
19
|
+
newLine = 0;
|
|
20
|
+
oldLine = 0;
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
if (!current) {
|
|
24
|
+
current = { repo, path: 'patch', lines: [] };
|
|
25
|
+
files.push(current);
|
|
26
|
+
}
|
|
27
|
+
if (raw.startsWith('+++ ') || raw.startsWith('--- ') || raw.startsWith('index ')) {
|
|
28
|
+
current.lines.push({ kind: 'meta', text: raw });
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
if (raw.startsWith('@@')) {
|
|
32
|
+
const match = raw.match(/@@\s+-(\d+)(?:,\d+)?\s+\+(\d+)(?:,\d+)?/);
|
|
33
|
+
if (match?.[1] && match[2]) {
|
|
34
|
+
oldLine = Number(match[1]);
|
|
35
|
+
newLine = Number(match[2]);
|
|
36
|
+
}
|
|
37
|
+
current.lines.push({ kind: 'hunk', text: raw });
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
if (raw.startsWith('+')) {
|
|
41
|
+
current.lines.push({ kind: 'add', text: raw, newLine });
|
|
42
|
+
newLine += 1;
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
if (raw.startsWith('-')) {
|
|
46
|
+
current.lines.push({ kind: 'del', text: raw, oldLine });
|
|
47
|
+
oldLine += 1;
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
current.lines.push({ kind: 'ctx', text: raw, newLine, oldLine });
|
|
51
|
+
newLine += 1;
|
|
52
|
+
oldLine += 1;
|
|
53
|
+
}
|
|
54
|
+
return files;
|
|
55
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type WorkspaceFilter } from '../workspace/workspace-tree.js';
|
|
2
|
+
/**
|
|
3
|
+
* The Workspace tab: everything the session is working on, in one place. Each repository's
|
|
4
|
+
* files, which of them the session has changed, and the file or its changes beside the tree.
|
|
5
|
+
* It reads the same whether there is no repository, one or several, and whoever's sandbox the
|
|
6
|
+
* work happens to be in. Give it the session as its `key` so it starts fresh for another one.
|
|
7
|
+
*/
|
|
8
|
+
export declare function WorkspaceViewer({ runId, initialPath, initialFilter, searchToken, }: {
|
|
9
|
+
runId: string;
|
|
10
|
+
/** A file to have open from the start. */
|
|
11
|
+
initialPath?: string;
|
|
12
|
+
/** The filter to start on. Left out, it starts on the changes when there are any. */
|
|
13
|
+
initialFilter?: WorkspaceFilter;
|
|
14
|
+
/** When the file-search shortcut was last pressed, in milliseconds. Zero if never. */
|
|
15
|
+
searchToken?: number;
|
|
16
|
+
}): import("react").JSX.Element;
|