@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.
- package/CHANGELOG.md +10 -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 +64 -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,275 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
|
3
|
+
import { ChevronRight, File, Files, Folder, FolderOpen, GitBranch, GitPullRequest, Moon, Package, PanelRight, Search, TriangleAlert, X, } from 'lucide-react';
|
|
4
|
+
import { lazy, Suspense, useEffect, useMemo, useRef, useState } from 'react';
|
|
5
|
+
import { useProjection, useRunStore } from '@swirls/looms/react';
|
|
6
|
+
import { Button } from '../../components/ui/button.js';
|
|
7
|
+
import { EmptyState, Kbd } from '../../components/ui/panel.js';
|
|
8
|
+
import { ResizableHandle, ResizablePanel, ResizablePanelGroup } from '../../components/ui/resizable.js';
|
|
9
|
+
import { ScrollArea } from '../../components/ui/scroll-area.js';
|
|
10
|
+
import { cn } from '../../lib/cn.js';
|
|
11
|
+
import { fullDateTime, relativeTime } from '../../lib/time.js';
|
|
12
|
+
import { useNow } from '../../lib/use-now.js';
|
|
13
|
+
import { useWidthBucket } from '../../lib/use-width-bucket.js';
|
|
14
|
+
import { useApi, useOrgPeople, useShuttleHost, useTenant } from '../../shuttle/index.js';
|
|
15
|
+
import { authoredPullsForSession, pullInbox, reviewedPullForSession, usePullsRunId, } from '../pulls/pulls.js';
|
|
16
|
+
import { changeAt, changeCount, initiallyExpanded, workspaceFiles, workspaceTree, } from '../workspace/workspace-tree.js';
|
|
17
|
+
import { FileQuickOpen, quickOpenShortcut } from './file-quick-open.js';
|
|
18
|
+
import { invalidateWorktree } from './sandbox.js';
|
|
19
|
+
/** The file pane brings the code and diff renderer with it, so it loads when a file is first opened. */
|
|
20
|
+
const FilePane = lazy(() => import('./file-pane.js'));
|
|
21
|
+
const POLL_MS = 4_000;
|
|
22
|
+
/** A saved copy only changes when the session works again, so it is checked less often. */
|
|
23
|
+
const SAVED_POLL_MS = 15_000;
|
|
24
|
+
/** Below this width the tree and the file take turns instead of sitting side by side. */
|
|
25
|
+
const SIDE_BY_SIDE_PX = 420;
|
|
26
|
+
/** How recent a search request must be for a tab that has just appeared to act on it. */
|
|
27
|
+
const SEARCH_REQUEST_FRESH_MS = 1_500;
|
|
28
|
+
/** The most files kept open at once. Opening another closes the one opened longest ago. */
|
|
29
|
+
const MAX_OPEN = 12;
|
|
30
|
+
const NONE_OPEN = { paths: [], active: null };
|
|
31
|
+
function storageKey(runId) {
|
|
32
|
+
return `shuttle:open-files:${runId}`;
|
|
33
|
+
}
|
|
34
|
+
/** The files this browser tab had open in a session, so a reload comes back to them. */
|
|
35
|
+
function readOpenFiles(runId) {
|
|
36
|
+
try {
|
|
37
|
+
const stored = JSON.parse(sessionStorage.getItem(storageKey(runId)) ?? 'null');
|
|
38
|
+
if (stored && typeof stored === 'object' && 'paths' in stored && Array.isArray(stored.paths)) {
|
|
39
|
+
const paths = stored.paths.filter((path) => typeof path === 'string');
|
|
40
|
+
const active = 'active' in stored && typeof stored.active === 'string' ? stored.active : null;
|
|
41
|
+
return { paths, active: active && paths.includes(active) ? active : (paths.at(-1) ?? null) };
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
// Nothing stored, or storage is unavailable.
|
|
46
|
+
}
|
|
47
|
+
return NONE_OPEN;
|
|
48
|
+
}
|
|
49
|
+
function withOpened(open, path) {
|
|
50
|
+
if (open.paths.includes(path)) {
|
|
51
|
+
return { ...open, active: path };
|
|
52
|
+
}
|
|
53
|
+
return { paths: [...open.paths, path].slice(-MAX_OPEN), active: path };
|
|
54
|
+
}
|
|
55
|
+
function withClosed(open, path) {
|
|
56
|
+
const at = open.paths.indexOf(path);
|
|
57
|
+
const paths = open.paths.filter((item) => item !== path);
|
|
58
|
+
// Closing the file in view moves to its neighbour, as editors do.
|
|
59
|
+
const active = open.active === path ? (paths[Math.min(at, paths.length - 1)] ?? null) : open.active;
|
|
60
|
+
return { paths, active };
|
|
61
|
+
}
|
|
62
|
+
const STATUS_LABEL = { A: 'Added', M: 'Modified', D: 'Deleted' };
|
|
63
|
+
const STATUS_CLASS = {
|
|
64
|
+
A: 'text-status-completed',
|
|
65
|
+
M: 'text-status-waiting',
|
|
66
|
+
D: 'text-destructive',
|
|
67
|
+
};
|
|
68
|
+
/** A repository as people know it: its GitHub name, or "Scratch" for a folder with none linked. */
|
|
69
|
+
function repoLabel(repo) {
|
|
70
|
+
return repo.fullName ?? 'Scratch';
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* The Workspace tab: everything the session is working on, in one place. Each repository's
|
|
74
|
+
* files, which of them the session has changed, and the file or its changes beside the tree.
|
|
75
|
+
* It reads the same whether there is no repository, one or several, and whoever's sandbox the
|
|
76
|
+
* work happens to be in. Give it the session as its `key` so it starts fresh for another one.
|
|
77
|
+
*/
|
|
78
|
+
export function WorkspaceViewer({ runId, initialPath, initialFilter, searchToken = 0, }) {
|
|
79
|
+
const api = useApi();
|
|
80
|
+
// The workspace is read again every few seconds while the tab's window is in front, and at
|
|
81
|
+
// once when a save, a stray moved in, or the session's events say its files changed.
|
|
82
|
+
const { data: workspace, error } = useQuery(api.sandbox.workspace.queryOptions({
|
|
83
|
+
input: { id: runId },
|
|
84
|
+
staleTime: 0,
|
|
85
|
+
refetchInterval: (query) => query.state.data && query.state.data.source !== 'sandbox' ? SAVED_POLL_MS : POLL_MS,
|
|
86
|
+
}));
|
|
87
|
+
const [filter, setFilter] = useState(initialFilter ?? null);
|
|
88
|
+
const [expanded, setExpanded] = useState(null);
|
|
89
|
+
const [unsaved, setUnsaved] = useState(false);
|
|
90
|
+
const [open, setOpen] = useState(() => {
|
|
91
|
+
const stored = readOpenFiles(runId);
|
|
92
|
+
return initialPath ? withOpened(stored, initialPath) : stored;
|
|
93
|
+
});
|
|
94
|
+
const [treeShown, setTreeShown] = useState(true);
|
|
95
|
+
const [searching, setSearching] = useState(false);
|
|
96
|
+
// The search opens when the pane asks for it: on a new request, or when this tab was only
|
|
97
|
+
// just created by one. Adjusted during render, the way React asks for state derived from props.
|
|
98
|
+
const [seenSearch, setSeenSearch] = useState(() => Date.now() - searchToken < SEARCH_REQUEST_FRESH_MS ? 0 : searchToken);
|
|
99
|
+
if (seenSearch !== searchToken) {
|
|
100
|
+
setSeenSearch(searchToken);
|
|
101
|
+
setSearching(true);
|
|
102
|
+
}
|
|
103
|
+
const [containerRef, bucket] = useWidthBucket([SIDE_BY_SIDE_PX]);
|
|
104
|
+
const sideBySide = bucket > 0;
|
|
105
|
+
useEffect(() => {
|
|
106
|
+
try {
|
|
107
|
+
sessionStorage.setItem(storageKey(runId), JSON.stringify(open));
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
// Storage is unavailable; the open files last until the page reloads.
|
|
111
|
+
}
|
|
112
|
+
}, [runId, open]);
|
|
113
|
+
const repos = useMemo(() => workspace?.repos ?? [], [workspace]);
|
|
114
|
+
const changes = changeCount(repos);
|
|
115
|
+
// Starts on what the session has done when it has done anything, and on everything otherwise.
|
|
116
|
+
const shown = filter ?? (changes > 0 ? 'changed' : 'all');
|
|
117
|
+
const tree = useMemo(() => workspaceTree(repos, shown), [repos, shown]);
|
|
118
|
+
const paths = useMemo(() => workspaceFiles(repos), [repos]);
|
|
119
|
+
const openFolders = expanded ?? initiallyExpanded(tree);
|
|
120
|
+
if (error && !workspace) {
|
|
121
|
+
return (_jsx(EmptyState, { icon: _jsx(Files, {}), title: "Workspace unavailable", children: error.message }));
|
|
122
|
+
}
|
|
123
|
+
if (!workspace) {
|
|
124
|
+
return (_jsx("div", { className: "text-muted-foreground flex h-full items-center justify-center text-xs", children: "Loading the workspace\u2026" }));
|
|
125
|
+
}
|
|
126
|
+
const empty = paths.length === 0 && changes === 0;
|
|
127
|
+
const openFile = (path) => {
|
|
128
|
+
if (unsaved &&
|
|
129
|
+
path !== open.active &&
|
|
130
|
+
!window.confirm('Discard your unsaved edit to this file?')) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
setUnsaved(false);
|
|
134
|
+
setOpen((current) => withOpened(current, path));
|
|
135
|
+
// With room for only one of them, picking a file moves to it.
|
|
136
|
+
if (!sideBySide) {
|
|
137
|
+
setTreeShown(false);
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
const toggle = (path) => {
|
|
141
|
+
const next = new Set(openFolders);
|
|
142
|
+
if (next.has(path)) {
|
|
143
|
+
next.delete(path);
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
next.add(path);
|
|
147
|
+
}
|
|
148
|
+
setExpanded(next);
|
|
149
|
+
};
|
|
150
|
+
// One repository needs no heading of its own in the tree: the bar above already names it.
|
|
151
|
+
const single = repos.length === 1 ? repos[0] : undefined;
|
|
152
|
+
const roots = single ? (tree[0]?.children ?? []) : tree;
|
|
153
|
+
const explorer = (_jsxs("div", { className: "flex h-full min-h-0 flex-col", children: [_jsxs("button", { type: "button", onClick: () => setSearching(true), className: "text-muted-foreground hover:text-foreground focus-visible:ring-ring/50 flex h-8 shrink-0 items-center gap-1.5 border-b px-2.5 text-left text-[11.5px] outline-none focus-visible:ring-2 focus-visible:ring-inset", children: [_jsx(Search, { className: "size-3.5 shrink-0" }), _jsx("span", { className: "min-w-0 flex-1 truncate", children: "Go to file\u2026" }), _jsx(Kbd, { children: quickOpenShortcut() })] }), _jsx(ScrollArea, { className: "min-h-0 flex-1", children: roots.length === 0 || (shown === 'changed' && changes === 0) ? (_jsx("p", { className: "text-muted-foreground px-3 py-4 text-[12px] leading-relaxed text-pretty", children: shown === 'changed'
|
|
154
|
+
? 'Nothing has changed since the session started.'
|
|
155
|
+
: 'No files yet. They appear here as agents write them.' })) : (_jsx("ul", { className: "py-1.5 text-[12px]", role: "tree", "aria-label": "Workspace files", children: roots.map((node) => (_jsx(TreeNode, { node: node, depth: 0, repos: repos, runId: runId, expanded: openFolders, activePath: open.active, onToggle: toggle, onOpenFile: openFile }, node.path))) })) })] }));
|
|
156
|
+
const active = open.active;
|
|
157
|
+
// An edit in progress is not thrown away by moving to another file without being asked.
|
|
158
|
+
const leaving = (go) => {
|
|
159
|
+
if (!unsaved || window.confirm('Discard your unsaved edit to this file?')) {
|
|
160
|
+
setUnsaved(false);
|
|
161
|
+
go();
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
const editBlock = workspace.source !== 'sandbox'
|
|
165
|
+
? 'A saved copy cannot be edited. Send a message to wake the sandbox.'
|
|
166
|
+
: workspace.working
|
|
167
|
+
? 'Agents are working. Edit once they have finished.'
|
|
168
|
+
: null;
|
|
169
|
+
const contents = (_jsxs("div", { className: "bg-background flex h-full min-h-0 min-w-0 flex-col", children: [_jsx(OpenFileStrip, { open: open, treeShown: treeShown, onToggleTree: () => setTreeShown((isShown) => !isShown), onSelect: (path) => leaving(() => setOpen((current) => ({ ...current, active: path }))), onClose: (path) => path === open.active
|
|
170
|
+
? leaving(() => setOpen((current) => withClosed(current, path)))
|
|
171
|
+
: setOpen((current) => withClosed(current, path)) }), _jsx("div", { className: "min-h-0 flex-1", children: active ? (_jsx(Suspense, { fallback: _jsx("div", { className: "text-muted-foreground flex h-full items-center justify-center text-xs", children: "Loading\u2026" }), children: _jsx(FilePane, { runId: runId, path: active, status: changeAt(repos, active), editBlock: editBlock, onDirtyChange: setUnsaved }, active) })) : (_jsx(EmptyState, { icon: _jsx(File, {}), title: "No file open", children: "Pick a file from the tree to read it here." })) })] }));
|
|
172
|
+
return (_jsxs("div", { ref: containerRef, className: "flex h-full min-h-0 flex-col", children: [_jsx(WorkspaceBar, { workspace: workspace, runId: runId, single: single, changes: changes, filter: shown, onFilter: (next) => {
|
|
173
|
+
setFilter(next);
|
|
174
|
+
setExpanded(null);
|
|
175
|
+
} }), workspace.strays.map((stray) => (_jsx(StrayNotice, { runId: runId, stray: stray }, stray.path))), _jsx(FileQuickOpen, { open: searching, onOpenChange: setSearching, paths: paths, recent: open.paths, onPick: openFile }), _jsx("div", { className: "min-h-0 flex-1", children: empty ? (_jsx(EmptyState, { icon: _jsx(Files, {}), title: "Nothing here yet", children: workspace.source === 'asleep'
|
|
176
|
+
? 'The sandbox for this session is asleep and no saved copy exists yet. Send a message to wake it.'
|
|
177
|
+
: 'Files appear here as agents write them.' })) : sideBySide && treeShown ? (_jsxs(ResizablePanelGroup, { orientation: "horizontal", children: [_jsx(ResizablePanel, { id: "file-contents", minSize: 200, children: contents }), _jsx(ResizableHandle, {}), _jsx(ResizablePanel, { id: "file-tree", defaultSize: "34", minSize: 130, maxSize: "60", children: explorer })] })) : treeShown ? (_jsxs("div", { className: "flex h-full min-h-0 flex-col", children: [open.active ? (_jsxs("button", { type: "button", onClick: () => setTreeShown(false), className: "text-muted-foreground hover:text-foreground focus-visible:ring-ring/50 flex h-8 shrink-0 items-center gap-1.5 border-b px-2.5 text-left text-[11.5px] outline-none focus-visible:ring-2 focus-visible:ring-inset", children: [_jsx(ChevronRight, { className: "size-3 rotate-180" }), _jsxs("span", { className: "truncate", children: ["Back to ", open.active.split('/').pop()] })] })) : null, _jsx("div", { className: "min-h-0 flex-1", children: explorer })] })) : (contents) })] }));
|
|
178
|
+
}
|
|
179
|
+
/** A two- or three-way switch drawn as one control. */
|
|
180
|
+
function Segmented({ label, value, onChange, options, }) {
|
|
181
|
+
return (_jsx("div", { role: "radiogroup", "aria-label": label, className: "ml-auto flex shrink-0 rounded-md border p-px", children: options.map((option) => (_jsxs("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 gap-1 rounded-[5px] px-1.5 text-[11px] outline-none focus-visible:ring-2', option.value === value
|
|
182
|
+
? 'bg-accent text-foreground'
|
|
183
|
+
: 'text-muted-foreground hover:text-foreground'), children: [option.label, option.count ? _jsx("span", { className: "tabular-nums opacity-70", children: option.count }) : null] }, option.value))) }));
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* The line under the tabs: whether this is the live workspace or a saved copy, whose sandbox it
|
|
187
|
+
* is in when that is not yours, the repository when there is only one, and the filter.
|
|
188
|
+
*/
|
|
189
|
+
function WorkspaceBar({ workspace, runId, single, changes, filter, onFilter, }) {
|
|
190
|
+
const now = useNow();
|
|
191
|
+
const me = useTenant().user.id;
|
|
192
|
+
const people = useOrgPeople();
|
|
193
|
+
const holder = workspace.holderId && workspace.holderId !== me ? workspace.holderId : null;
|
|
194
|
+
const state = workspace.source === 'saved'
|
|
195
|
+
? workspace.savedAt
|
|
196
|
+
? `Saved ${relativeTime(workspace.savedAt, now)}`
|
|
197
|
+
: 'Saved copy'
|
|
198
|
+
: workspace.source === 'asleep'
|
|
199
|
+
? 'Asleep'
|
|
200
|
+
: holder
|
|
201
|
+
? `Live · ${people.get(holder) ?? 'a teammate'}`
|
|
202
|
+
: 'Live';
|
|
203
|
+
const explained = workspace.source === 'saved'
|
|
204
|
+
? `The sandbox is asleep. This is the work as it was last saved${workspace.savedAt ? `, ${fullDateTime(workspace.savedAt)}` : ''}.`
|
|
205
|
+
: workspace.source === 'asleep'
|
|
206
|
+
? 'The sandbox is asleep and nothing has been saved yet.'
|
|
207
|
+
: holder
|
|
208
|
+
? `Read live from ${people.get(holder) ?? 'a teammate'}'s sandbox, where the session is working.`
|
|
209
|
+
: 'Read live from the sandbox the session is working in.';
|
|
210
|
+
return (_jsxs("div", { className: "text-muted-foreground flex h-8 shrink-0 items-center gap-2 border-b px-2.5 text-[11px]", children: [_jsxs("span", { className: "flex shrink-0 items-center gap-1.5", title: explained, children: [workspace.source === 'sandbox' ? (_jsx("span", { "aria-hidden": true, className: "bg-status-completed size-1.5 rounded-full" })) : (_jsx(Moon, { "aria-hidden": true, className: "size-3" })), _jsx("span", { className: "text-foreground font-medium", children: state })] }), single ? _jsx(RepoFacts, { repo: single, runId: runId }) : null, _jsx(Segmented, { label: "Files to show", value: filter, onChange: onFilter, options: [
|
|
211
|
+
{ value: 'all', label: 'All' },
|
|
212
|
+
{ value: 'changed', label: 'Changed', count: changes },
|
|
213
|
+
] })] }));
|
|
214
|
+
}
|
|
215
|
+
/** A repository's name, the branch its changes are measured from, and its pull requests. */
|
|
216
|
+
function RepoFacts({ repo, runId, counted, }) {
|
|
217
|
+
const inbox = useProjection(useRunStore(usePullsRunId()), pullInbox);
|
|
218
|
+
const pulls = repo.fullName
|
|
219
|
+
? authoredPullsForSession(inbox, runId).filter((pull) => pull.fullName === repo.fullName)
|
|
220
|
+
: [];
|
|
221
|
+
// A review session has a pull request checked out, not a branch cut from the default one.
|
|
222
|
+
const reviewed = reviewedPullForSession(inbox, runId);
|
|
223
|
+
const reviewing = repo.fullName && reviewed?.fullName === repo.fullName ? reviewed : undefined;
|
|
224
|
+
const Icon = repo.fullName ? GitBranch : Package;
|
|
225
|
+
return (_jsxs("span", { className: "flex min-w-0 items-center gap-1.5", children: [_jsx(Icon, { "aria-hidden": true, className: "size-3 shrink-0" }), _jsx("span", { className: "text-foreground min-w-0 truncate", title: repoLabel(repo), children: repoLabel(repo) }), reviewing ? (_jsxs("span", { className: "flex min-w-0 items-center gap-1", title: `Pull request ${reviewing.number}: ${reviewing.title}\nChecked out at ${reviewing.headRef}. Changes are measured from ${reviewing.baseRef}.`, children: [_jsx(GitPullRequest, { "aria-hidden": true, className: "size-3 shrink-0" }), _jsx("span", { className: "shrink-0 tabular-nums", children: reviewing.number }), _jsxs("span", { className: "min-w-0 truncate", children: [reviewing.headRef, " \u2192 ", reviewing.baseRef] })] })) : repo.fullName ? (_jsx("span", { className: "shrink-0", title: `Changes are measured from ${repo.defaultBranch}`, children: repo.defaultBranch })) : (_jsx("span", { className: "shrink-0", title: "This folder has no repository linked, so the work is not on GitHub.", children: "not on GitHub" })), counted && repo.changes.length > 0 ? (_jsxs("span", { className: "text-foreground shrink-0 tabular-nums", children: ["+", repo.changes.length] })) : null, pulls.map((pull) =>
|
|
226
|
+
// Inside a tree row, which is itself a button, the number is shown but is not a link.
|
|
227
|
+
counted ? (_jsxs("span", { className: "flex shrink-0 items-center gap-0.5", children: [_jsx(GitPullRequest, { "aria-hidden": true, className: "size-3" }), pull.number] }, pull.number)) : (_jsxs("a", { href: pull.url, target: "_blank", rel: "noreferrer", className: "hover:text-foreground focus-visible:ring-ring/50 flex shrink-0 items-center gap-0.5 rounded-sm outline-none focus-visible:ring-2", title: `Pull request ${pull.number}${pull.draft ? ' (draft)' : ''}`, children: [_jsx(GitPullRequest, { "aria-hidden": true, className: "size-3" }), pull.number] }, pull.number)))] }));
|
|
228
|
+
}
|
|
229
|
+
/** Says an agent left work outside the workspace, where nobody else can see it, and offers to move it in. */
|
|
230
|
+
function StrayNotice({ runId, stray, }) {
|
|
231
|
+
const host = useShuttleHost();
|
|
232
|
+
const api = useApi();
|
|
233
|
+
const queryClient = useQueryClient();
|
|
234
|
+
// What was moved in shows up among the workspace's files, and the notice about it goes.
|
|
235
|
+
const adopt = useMutation(api.sandbox.adopt.mutationOptions({
|
|
236
|
+
onSuccess: () => invalidateWorktree(host, queryClient, runId),
|
|
237
|
+
}));
|
|
238
|
+
return (_jsxs("div", { className: "flex shrink-0 items-start gap-2 border-b px-2.5 py-2 text-[11.5px] leading-snug", children: [_jsx(TriangleAlert, { "aria-hidden": true, className: "text-status-waiting mt-px size-3.5 shrink-0" }), _jsxs("p", { className: "text-muted-foreground min-w-0 flex-1 text-pretty", children: [_jsx("span", { className: "text-foreground font-mono", children: stray.path }), " was written outside the workspace", stray.files > 0 ? ` (${stray.files} ${stray.files === 1 ? 'file' : 'files'})` : '', ", so it is not shown, saved or shared.", adopt.error ? (_jsxs("span", { role: "alert", className: "text-destructive", children: [' ', adopt.error.message] })) : null] }), _jsx(Button, { variant: "outline", size: "sm", className: "h-6 shrink-0 px-2 text-[11px]", disabled: adopt.isPending, onClick: () => adopt.mutate({ id: runId, path: stray.path }), children: adopt.isPending ? 'Moving…' : 'Move in' })] }));
|
|
239
|
+
}
|
|
240
|
+
/** The files open in this tab, with the one in view marked, and the button that shows the tree. */
|
|
241
|
+
function OpenFileStrip({ open, treeShown, onToggleTree, onSelect, onClose, }) {
|
|
242
|
+
const stripRef = useRef(null);
|
|
243
|
+
// Keeps the file in view in the strip when it is picked from the tree or the search.
|
|
244
|
+
useEffect(() => {
|
|
245
|
+
if (open.active) {
|
|
246
|
+
stripRef.current
|
|
247
|
+
?.querySelector(`[data-path="${CSS.escape(open.active)}"]`)
|
|
248
|
+
?.scrollIntoView({ block: 'nearest', inline: 'nearest' });
|
|
249
|
+
}
|
|
250
|
+
}, [open.active]);
|
|
251
|
+
// Two open files with the same name are told apart by their folder.
|
|
252
|
+
const names = open.paths.map((path) => path.split('/').pop() ?? path);
|
|
253
|
+
return (_jsxs("div", { ref: stripRef, className: "flex h-8 shrink-0 items-stretch border-b", children: [_jsx(ScrollArea, { horizontal: true, vertical: false, barClassName: "h-1.5", className: "min-w-0 flex-1", viewportClassName: "[&>div]:flex! [&>div]:h-8 [&>div]:w-max [&>div]:items-stretch", children: open.paths.map((path, index) => {
|
|
254
|
+
const active = path === open.active;
|
|
255
|
+
const name = names[index] ?? path;
|
|
256
|
+
const twin = names.indexOf(name) !== names.lastIndexOf(name);
|
|
257
|
+
const folder = path.split('/').slice(-2, -1)[0];
|
|
258
|
+
return (_jsxs("div", { "data-path": path, role: "presentation", className: cn('group flex shrink-0 items-center border-r text-[11.5px]', active
|
|
259
|
+
? 'bg-accent/50 text-foreground'
|
|
260
|
+
: 'text-muted-foreground hover:bg-accent/25'), children: [_jsxs("button", { type: "button", role: "tab", "aria-selected": active, title: path, onClick: () => onSelect(path), className: "focus-visible:ring-ring/50 h-full max-w-48 truncate py-0 pr-1 pl-2.5 font-mono outline-none focus-visible:ring-2 focus-visible:ring-inset", children: [name, twin && folder ? _jsxs("span", { className: "text-muted-foreground", children: [" \u00B7 ", folder] }) : null] }), _jsx("button", { type: "button", "aria-label": `Close ${name}`, onClick: () => onClose(path), className: cn('hover:bg-accent hover:text-foreground focus-visible:ring-ring/50 mr-1 flex size-4 items-center justify-center rounded-sm outline-none focus-visible:opacity-100 focus-visible:ring-2', active ? 'opacity-70' : 'opacity-0 group-hover:opacity-70'), children: _jsx(X, { className: "size-3" }) })] }, path));
|
|
261
|
+
}) }), _jsx("button", { type: "button", onClick: onToggleTree, "aria-label": treeShown ? 'Hide file tree' : 'Show file tree', "aria-pressed": treeShown, className: "text-muted-foreground hover:text-foreground focus-visible:ring-ring/50 flex w-8 shrink-0 items-center justify-center border-l outline-none focus-visible:ring-2 focus-visible:ring-inset", children: _jsx(PanelRight, { className: "size-3.5" }) })] }));
|
|
262
|
+
}
|
|
263
|
+
function TreeNode({ node, depth, repos, runId, expanded, activePath, onToggle, onOpenFile, }) {
|
|
264
|
+
const open = expanded.has(node.path);
|
|
265
|
+
const rowClass = 'focus-visible:ring-ring/50 flex h-6 w-full items-center gap-1.5 pr-2.5 text-left outline-none transition-colors duration-100 focus-visible:ring-2 focus-visible:ring-inset';
|
|
266
|
+
if (node.kind === 'file') {
|
|
267
|
+
const active = node.path === activePath;
|
|
268
|
+
return (_jsx("li", { role: "treeitem", "aria-selected": active, children: _jsxs("button", { type: "button", onClick: () => onOpenFile(node.path), className: cn(rowClass, active ? 'bg-accent text-foreground' : 'text-muted-foreground hover:bg-accent/50'),
|
|
269
|
+
// Files line up with the names of the folders beside them, past the folder chevron.
|
|
270
|
+
style: { paddingLeft: 8 + depth * 12 + 14 }, title: node.path, children: [_jsx(File, { className: "size-3.5 shrink-0 opacity-60" }), _jsx("span", { className: cn('min-w-0 flex-1 truncate', node.status === 'D' && 'line-through'), children: node.name }), node.status ? (_jsx("span", { className: cn('shrink-0 font-mono text-[10.5px]', STATUS_CLASS[node.status]), title: STATUS_LABEL[node.status], children: node.status })) : null] }) }));
|
|
271
|
+
}
|
|
272
|
+
const repo = node.kind === 'repo' ? repos.find((item) => item.name === node.name) : undefined;
|
|
273
|
+
const FolderIcon = open ? FolderOpen : Folder;
|
|
274
|
+
return (_jsxs("li", { role: "treeitem", "aria-expanded": open, children: [_jsxs("button", { type: "button", onClick: () => onToggle(node.path), className: cn(rowClass, 'hover:bg-accent/50', repo && 'text-muted-foreground mt-1 h-7 text-[11px] first:mt-0'), style: { paddingLeft: 8 + depth * 12 }, title: node.path, children: [_jsx(ChevronRight, { className: cn('text-muted-foreground size-3 shrink-0 transition-transform duration-100', open && 'rotate-90') }), repo ? (_jsx(RepoFacts, { repo: repo, runId: runId, counted: true })) : (_jsxs(_Fragment, { children: [_jsx(FolderIcon, { className: "text-muted-foreground size-3.5 shrink-0" }), _jsx("span", { className: "min-w-0 flex-1 truncate", children: node.name }), node.changed > 0 ? (_jsx("span", { "aria-hidden": true, className: "bg-status-waiting size-1.5 shrink-0 rounded-full" })) : null] }))] }), open ? (_jsx("ul", { role: "group", children: node.children.map((child) => (_jsx(TreeNode, { node: child, depth: depth + 1, repos: repos, runId: runId, expanded: expanded, activePath: activePath, onToggle: onToggle, onOpenFile: onOpenFile }, child.path))) })) : null] }));
|
|
275
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { Connection } from '@swirls/shuttle/api';
|
|
2
|
+
import { type SignInPlace } from './places.js';
|
|
3
|
+
export type SignInStep = {
|
|
4
|
+
readonly step: 'starting';
|
|
5
|
+
} | {
|
|
6
|
+
readonly step: 'prompt';
|
|
7
|
+
readonly loginId: string;
|
|
8
|
+
readonly url: string;
|
|
9
|
+
readonly code: string;
|
|
10
|
+
readonly needsCode: boolean;
|
|
11
|
+
readonly codeSent: boolean;
|
|
12
|
+
} | {
|
|
13
|
+
readonly step: 'failed';
|
|
14
|
+
readonly error: string;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* One agent's sign-in at one place, run by the vendor CLI in that place's sandbox. Once the CLI
|
|
18
|
+
* reports success, everything that shows connections reads them again and `onDone` is called.
|
|
19
|
+
*/
|
|
20
|
+
export declare function useSignIn(harness: Connection['harness'], place: SignInPlace, onDone?: () => Promise<unknown> | void): {
|
|
21
|
+
signIn: SignInStep | null;
|
|
22
|
+
/** True from the moment sign-in starts until it succeeds, fails or is cancelled. */
|
|
23
|
+
busy: boolean;
|
|
24
|
+
start: () => void;
|
|
25
|
+
cancel: () => void;
|
|
26
|
+
submitCode: (code: string) => void;
|
|
27
|
+
};
|
|
28
|
+
/** What a sign-in under way needs from the person: the page to open, a code, or patience. */
|
|
29
|
+
export declare function SignInProgress({ label, place, signIn, onSubmitCode, }: {
|
|
30
|
+
label: string;
|
|
31
|
+
place: SignInPlace;
|
|
32
|
+
signIn: SignInStep | null;
|
|
33
|
+
onSubmitCode: (code: string) => void;
|
|
34
|
+
}): import("react").JSX.Element | null;
|
|
35
|
+
/**
|
|
36
|
+
* Where a new session will run: on this machine when the desktop app's sandbox is up and set
|
|
37
|
+
* to take new sessions, otherwise in the cloud. Mirrors `startsOnThisMachine` in workspace.ts.
|
|
38
|
+
*/
|
|
39
|
+
export declare function useStartPlace(): SignInPlace;
|
|
40
|
+
/**
|
|
41
|
+
* Shown in a message box whose agent is not signed in where the session runs. Signs in right
|
|
42
|
+
* there, or offers the other place where the agent is already signed in.
|
|
43
|
+
*/
|
|
44
|
+
export declare function SignInGate({ connection, place, onSignedIn, onMoveToCloud, upcoming, }: {
|
|
45
|
+
connection: Connection;
|
|
46
|
+
place: SignInPlace;
|
|
47
|
+
/** For a session not started yet, which will run at `place`. */
|
|
48
|
+
upcoming?: boolean;
|
|
49
|
+
/** Called once signed in. The connections are read again without it. */
|
|
50
|
+
onSignedIn?: () => Promise<unknown> | void;
|
|
51
|
+
/** Offered when the agent is signed in in the cloud and the session can move there. */
|
|
52
|
+
onMoveToCloud?: () => void;
|
|
53
|
+
}): import("react").JSX.Element;
|
|
54
|
+
/**
|
|
55
|
+
* Whether `harness` has to be signed in at `place` before a session there can use it, with the
|
|
56
|
+
* agent's connection for the gate that offers it. Nothing is blocked until the connections are in.
|
|
57
|
+
*/
|
|
58
|
+
export declare function useAgentGate(harness: string, place: SignInPlace | null): {
|
|
59
|
+
connection: Connection | undefined;
|
|
60
|
+
blocked: boolean;
|
|
61
|
+
reload: () => Promise<void>;
|
|
62
|
+
connections: readonly Connection[] | null;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Where a session runs, as far as sign-ins go: this machine, the cloud, or null for another of
|
|
66
|
+
* the viewer's machines (or not known yet), whose sign-ins cannot be checked from here.
|
|
67
|
+
*/
|
|
68
|
+
export declare function useSessionRunsAt(runId: string): {
|
|
69
|
+
place: SignInPlace | null;
|
|
70
|
+
moveToCloud: () => Promise<void>;
|
|
71
|
+
};
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { skipToken, useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
|
3
|
+
import { AlertCircle, Check, Copy, ExternalLink, Loader2 } from 'lucide-react';
|
|
4
|
+
import { useEffect, useEffectEvent, useRef, useState } from 'react';
|
|
5
|
+
import { Button } from '../../components/ui/button.js';
|
|
6
|
+
import { Input } from '../../components/ui/input.js';
|
|
7
|
+
import { useApi, useDevice, useShuttleHost, } from '../../shuttle/index.js';
|
|
8
|
+
import { loginOutcome, loginSettled, mergeProgress } from './login.js';
|
|
9
|
+
import { atPlace, needsSignIn, placeContext } from './places.js';
|
|
10
|
+
import { connectionsQuery } from './queries.js';
|
|
11
|
+
const POLL_MS = 1_500;
|
|
12
|
+
/**
|
|
13
|
+
* One agent's sign-in at one place, run by the vendor CLI in that place's sandbox. Once the CLI
|
|
14
|
+
* reports success, everything that shows connections reads them again and `onDone` is called.
|
|
15
|
+
*/
|
|
16
|
+
export function useSignIn(harness, place, onDone) {
|
|
17
|
+
const host = useShuttleHost();
|
|
18
|
+
const api = useApi();
|
|
19
|
+
const { client } = useShuttleHost();
|
|
20
|
+
const queryClient = useQueryClient();
|
|
21
|
+
const context = placeContext(host, place);
|
|
22
|
+
// Goes up with every sign-in asked for and every one given up, so a sign-in that finishes
|
|
23
|
+
// starting can tell whether it is still the one wanted.
|
|
24
|
+
const wanted = useRef(0);
|
|
25
|
+
// The prompt a code was last passed back for. The CLI asks again after a wrong code, and that
|
|
26
|
+
// new prompt needs a code of its own.
|
|
27
|
+
const [codeSentFor, setCodeSentFor] = useState(null);
|
|
28
|
+
const stop = useMutation(api.connections.login.cancel.mutationOptions({ context }));
|
|
29
|
+
const sendCode = useMutation(api.connections.login.sendCode.mutationOptions({ context }));
|
|
30
|
+
const begin = useMutation(api.connections.login.start.mutationOptions({ context }));
|
|
31
|
+
const loginId = begin.data?.loginId;
|
|
32
|
+
const loginKey = api.connections.login.follow.queryKey({
|
|
33
|
+
input: loginId ? { harness, loginId } : skipToken,
|
|
34
|
+
});
|
|
35
|
+
// One entry per sign-in, holding everything it has said so far: what a single read from the
|
|
36
|
+
// start would return. Each poll asks only for what came after the last one and adds it on.
|
|
37
|
+
const follow = useQuery(api.connections.login.follow.queryOptions({
|
|
38
|
+
input: loginId ? { harness, loginId } : skipToken,
|
|
39
|
+
context,
|
|
40
|
+
queryFn: loginId
|
|
41
|
+
? async ({ client: cache, signal }) => {
|
|
42
|
+
const soFar = cache.getQueryData(loginKey);
|
|
43
|
+
// Reading past the end of a finished sign-in would lose how it ended.
|
|
44
|
+
if (soFar && loginSettled(soFar)) {
|
|
45
|
+
return soFar;
|
|
46
|
+
}
|
|
47
|
+
const page = await client.connections.login.follow({ harness, loginId, offset: soFar?.offset ?? 0 }, { context, signal });
|
|
48
|
+
return mergeProgress(soFar, page);
|
|
49
|
+
}
|
|
50
|
+
: skipToken,
|
|
51
|
+
// Only the poll below asks again: what is held is never out of date, only incomplete.
|
|
52
|
+
staleTime: Infinity,
|
|
53
|
+
refetchInterval: ({ state }) => state.status === 'error' || (state.data && loginSettled(state.data)) ? false : POLL_MS,
|
|
54
|
+
// Signing in happens in another tab, and the answer should be here on the way back.
|
|
55
|
+
refetchIntervalInBackground: true,
|
|
56
|
+
}));
|
|
57
|
+
const outcome = follow.data ? loginOutcome(follow.data) : null;
|
|
58
|
+
const connected = outcome?.status === 'connected';
|
|
59
|
+
const signedIn = useEffectEvent(() => {
|
|
60
|
+
void queryClient.invalidateQueries({ queryKey: api.connections.key() });
|
|
61
|
+
void onDone?.();
|
|
62
|
+
});
|
|
63
|
+
// The sign-in connecting is news from the sandbox, told once to everything that shows it.
|
|
64
|
+
useEffect(() => {
|
|
65
|
+
if (connected) {
|
|
66
|
+
signedIn();
|
|
67
|
+
}
|
|
68
|
+
}, [connected]);
|
|
69
|
+
function start() {
|
|
70
|
+
const turn = ++wanted.current;
|
|
71
|
+
sendCode.reset();
|
|
72
|
+
setCodeSentFor(null);
|
|
73
|
+
begin.mutateAsync({ harness }).then(({ loginId: started }) => {
|
|
74
|
+
// Cancelled while it was starting. Nobody is following it, so end it in the sandbox too.
|
|
75
|
+
if (turn !== wanted.current) {
|
|
76
|
+
stop.mutate({ harness, loginId: started });
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
// Why it could not start is shown from the mutation itself.
|
|
80
|
+
() => { });
|
|
81
|
+
}
|
|
82
|
+
function cancel() {
|
|
83
|
+
wanted.current += 1;
|
|
84
|
+
begin.reset();
|
|
85
|
+
sendCode.reset();
|
|
86
|
+
setCodeSentFor(null);
|
|
87
|
+
if (loginId) {
|
|
88
|
+
// Best effort: the sign-in is no longer followed either way.
|
|
89
|
+
stop.mutate({ harness, loginId });
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
const prompt = outcome?.status === 'waiting' ? outcome.prompt : null;
|
|
93
|
+
function submitCode(code) {
|
|
94
|
+
if (!loginId || !prompt || !code.trim()) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
sendCode.mutate({ harness, loginId, code: code.trim() }, { onSuccess: () => setCodeSentFor(prompt.seq) });
|
|
98
|
+
}
|
|
99
|
+
const signIn = (() => {
|
|
100
|
+
if (begin.isPending) {
|
|
101
|
+
return { step: 'starting' };
|
|
102
|
+
}
|
|
103
|
+
if (begin.error) {
|
|
104
|
+
return { step: 'failed', error: begin.error.message };
|
|
105
|
+
}
|
|
106
|
+
if (!loginId || connected) {
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
if (outcome?.status === 'failed') {
|
|
110
|
+
return { step: 'failed', error: outcome.error };
|
|
111
|
+
}
|
|
112
|
+
const failure = follow.error ?? sendCode.error;
|
|
113
|
+
if (failure) {
|
|
114
|
+
return { step: 'failed', error: failure.message };
|
|
115
|
+
}
|
|
116
|
+
if (!prompt) {
|
|
117
|
+
return { step: 'starting' };
|
|
118
|
+
}
|
|
119
|
+
return {
|
|
120
|
+
step: 'prompt',
|
|
121
|
+
loginId,
|
|
122
|
+
url: prompt.url,
|
|
123
|
+
code: prompt.code,
|
|
124
|
+
needsCode: prompt.needsCode === true,
|
|
125
|
+
codeSent: codeSentFor === prompt.seq,
|
|
126
|
+
};
|
|
127
|
+
})();
|
|
128
|
+
return {
|
|
129
|
+
signIn,
|
|
130
|
+
/** True from the moment sign-in starts until it succeeds, fails or is cancelled. */
|
|
131
|
+
busy: signIn !== null && signIn.step !== 'failed',
|
|
132
|
+
start,
|
|
133
|
+
cancel,
|
|
134
|
+
submitCode,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
/** What a sign-in under way needs from the person: the page to open, a code, or patience. */
|
|
138
|
+
export function SignInProgress({ label, place, signIn, onSubmitCode, }) {
|
|
139
|
+
const [codeInput, setCodeInput] = useState('');
|
|
140
|
+
const [copied, setCopied] = useState(false);
|
|
141
|
+
if (!signIn) {
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
if (signIn.step === 'starting') {
|
|
145
|
+
return (_jsxs("p", { className: "text-muted-foreground flex items-center gap-2 text-xs", children: [_jsx(Loader2, { className: "size-3.5 shrink-0 animate-spin" }), "Starting ", label, " sign-in ", atPlace(place), ".", place === 'cloud' ? ' The first start of the sandbox can take a minute.' : ''] }));
|
|
146
|
+
}
|
|
147
|
+
if (signIn.step === 'failed') {
|
|
148
|
+
return _jsx("p", { className: "text-status-failed text-xs wrap-anywhere", children: signIn.error });
|
|
149
|
+
}
|
|
150
|
+
return (_jsxs("div", { className: "flex flex-col gap-2 text-xs", children: [_jsxs("a", { href: signIn.url, target: "_blank", rel: "noreferrer", className: "text-foreground inline-flex w-fit items-center gap-1 underline underline-offset-2", children: ["Open the ", label, " sign-in page ", _jsx(ExternalLink, { className: "size-3" })] }), signIn.code ? (_jsxs("div", { className: "flex items-center gap-2", children: [_jsx("span", { className: "text-muted-foreground", children: "Enter this code there:" }), _jsx("code", { className: "bg-muted text-foreground rounded px-2 py-1 font-mono text-sm tracking-wider", children: signIn.code }), _jsx(Button, { size: "icon-sm", variant: "ghost", "aria-label": "Copy code", onClick: () => {
|
|
151
|
+
void navigator.clipboard.writeText(signIn.code).then(() => setCopied(true));
|
|
152
|
+
}, children: copied ? _jsx(Check, {}) : _jsx(Copy, {}) })] })) : null, signIn.needsCode && !signIn.codeSent ? (_jsxs("form", { className: "flex items-center gap-2", onSubmit: (event) => {
|
|
153
|
+
event.preventDefault();
|
|
154
|
+
onSubmitCode(codeInput);
|
|
155
|
+
}, children: [_jsx(Input, { value: codeInput, onChange: (event) => setCodeInput(event.target.value), placeholder: `Paste the code ${label} gives you`, autoComplete: "off", className: "h-8 flex-1 font-mono text-xs" }), _jsx(Button, { size: "sm", type: "submit", disabled: !codeInput.trim(), children: "Submit" })] })) : null, _jsxs("p", { className: "text-muted-foreground flex items-center gap-2", children: [_jsx(Loader2, { className: "size-3.5 animate-spin" }), signIn.needsCode && !signIn.codeSent
|
|
156
|
+
? 'Waiting for the code'
|
|
157
|
+
: `Waiting for ${label} to confirm`] })] }));
|
|
158
|
+
}
|
|
159
|
+
/** The viewer's connections, for something that sits in another page and must not hold it up. */
|
|
160
|
+
function useConnections() {
|
|
161
|
+
const host = useShuttleHost();
|
|
162
|
+
return useQuery({
|
|
163
|
+
...connectionsQuery(host),
|
|
164
|
+
// A sign-in made elsewhere, such as in another window, shows when the page is back.
|
|
165
|
+
refetchOnWindowFocus: 'always',
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Where a new session will run: on this machine when the desktop app's sandbox is up and set
|
|
170
|
+
* to take new sessions, otherwise in the cloud. Mirrors `startsOnThisMachine` in workspace.ts.
|
|
171
|
+
*/
|
|
172
|
+
export function useStartPlace() {
|
|
173
|
+
const app = useDevice();
|
|
174
|
+
const [runner, setRunner] = useState(null);
|
|
175
|
+
const [wanted, setWanted] = useState(true);
|
|
176
|
+
// The desktop app's runner is outside the page: it is asked once, then tells of each change.
|
|
177
|
+
useEffect(() => {
|
|
178
|
+
if (!app) {
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
void app.runnerStatus().then(setRunner, () => { });
|
|
182
|
+
void app.startsLocally().then(setWanted, () => { });
|
|
183
|
+
return app.onRunnerStatus((status) => {
|
|
184
|
+
setRunner(status);
|
|
185
|
+
void app.startsLocally().then(setWanted, () => { });
|
|
186
|
+
});
|
|
187
|
+
}, [app]);
|
|
188
|
+
return app && wanted && runner?.status === 'online' ? 'local' : 'cloud';
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Shown in a message box whose agent is not signed in where the session runs. Signs in right
|
|
192
|
+
* there, or offers the other place where the agent is already signed in.
|
|
193
|
+
*/
|
|
194
|
+
export function SignInGate({ connection, place, onSignedIn, onMoveToCloud, upcoming = false, }) {
|
|
195
|
+
const { label } = connection;
|
|
196
|
+
const flow = useSignIn(connection.harness, place, onSignedIn);
|
|
197
|
+
const cloudInstead = place === 'local' && connection.cloud && onMoveToCloud;
|
|
198
|
+
return (_jsxs("div", { className: "bg-muted/40 mx-1 mt-1 mb-1.5 flex flex-col gap-2 rounded-lg border px-3 py-2.5", children: [_jsxs("div", { className: "flex flex-wrap items-center gap-x-3 gap-y-2", children: [_jsxs("p", { className: "text-foreground flex min-w-0 flex-1 items-start gap-2 text-xs leading-relaxed text-pretty", children: [_jsx(AlertCircle, { className: "mt-0.5 size-3.5 shrink-0 text-amber-500" }), _jsxs("span", { children: [label, " is not signed in ", atPlace(place), ", where this session", ' ', upcoming ? 'will run' : 'runs', connection.connected
|
|
199
|
+
? ` (it is signed in ${atPlace(place === 'local' ? 'cloud' : 'local')})`
|
|
200
|
+
: '', "."] })] }), flow.busy ? (_jsx(Button, { size: "sm", variant: "ghost", onClick: flow.cancel, children: "Cancel" })) : (_jsxs("div", { className: "flex items-center gap-1.5", children: [cloudInstead ? (_jsx(Button, { size: "sm", variant: "ghost", onClick: onMoveToCloud, children: "Move to cloud" })) : null, _jsx(Button, { size: "sm", onClick: flow.start, children: flow.signIn?.step === 'failed' ? 'Try again' : `Sign in ${atPlace(place)}` })] }))] }), _jsx(SignInProgress, { label: label, place: place, signIn: flow.signIn, onSubmitCode: flow.submitCode })] }));
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Whether `harness` has to be signed in at `place` before a session there can use it, with the
|
|
204
|
+
* agent's connection for the gate that offers it. Nothing is blocked until the connections are in.
|
|
205
|
+
*/
|
|
206
|
+
export function useAgentGate(harness, place) {
|
|
207
|
+
const api = useApi();
|
|
208
|
+
const queryClient = useQueryClient();
|
|
209
|
+
const { data } = useConnections();
|
|
210
|
+
const connection = data?.connections.find((entry) => entry.harness === harness);
|
|
211
|
+
return {
|
|
212
|
+
connection,
|
|
213
|
+
blocked: needsSignIn(connection, place),
|
|
214
|
+
// A read already under way is joined, not started over: a sign-in that has just finished
|
|
215
|
+
// has asked for one, and that is the read this is after.
|
|
216
|
+
reload: () => queryClient.invalidateQueries({ queryKey: api.connections.key() }, { cancelRefetch: false }),
|
|
217
|
+
connections: data?.connections ?? null,
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
function signInPlaceOf(place, app) {
|
|
221
|
+
if (place.sandbox.location === 'cloud') {
|
|
222
|
+
return 'cloud';
|
|
223
|
+
}
|
|
224
|
+
return app && place.sandbox.deviceId === app.deviceId ? 'local' : null;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Where a session runs, as far as sign-ins go: this machine, the cloud, or null for another of
|
|
228
|
+
* the viewer's machines (or not known yet), whose sign-ins cannot be checked from here.
|
|
229
|
+
*/
|
|
230
|
+
export function useSessionRunsAt(runId) {
|
|
231
|
+
const api = useApi();
|
|
232
|
+
const device = useDevice();
|
|
233
|
+
const queryClient = useQueryClient();
|
|
234
|
+
const placeKey = api.sandbox.place.get.queryKey({ input: { id: runId } });
|
|
235
|
+
const { data } = useQuery(api.sandbox.place.get.queryOptions({
|
|
236
|
+
input: { id: runId },
|
|
237
|
+
// The session can be moved from another window, so the answer is checked on the way back.
|
|
238
|
+
refetchOnWindowFocus: 'always',
|
|
239
|
+
}));
|
|
240
|
+
const move = useMutation(api.sandbox.place.move.mutationOptions({
|
|
241
|
+
onSuccess: (next) => {
|
|
242
|
+
queryClient.setQueryData(placeKey, next);
|
|
243
|
+
},
|
|
244
|
+
}));
|
|
245
|
+
return {
|
|
246
|
+
place: data ? signInPlaceOf(data, device) : null,
|
|
247
|
+
moveToCloud: async () => {
|
|
248
|
+
await move.mutateAsync({ id: runId, to: 'cloud' });
|
|
249
|
+
},
|
|
250
|
+
};
|
|
251
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Connect, check and remove coding agent subscriptions. Each agent shows every place it can be
|
|
3
|
+
* signed in at once: in the desktop app that is this machine and the cloud, which keep separate
|
|
4
|
+
* sign-ins because a session uses the one where it runs.
|
|
5
|
+
*
|
|
6
|
+
* The page's loader has the connections ready before this renders.
|
|
7
|
+
*/
|
|
8
|
+
export declare function ConnectionsPanel(): import("react").JSX.Element;
|