@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,337 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { PatchDiff } from '@pierre/diffs/react';
|
|
3
|
+
import { useMutation, useQuery } from '@tanstack/react-query';
|
|
4
|
+
import { Check, ChevronRight, ExternalLink, GitPullRequest, LoaderCircle, RefreshCw, } from 'lucide-react';
|
|
5
|
+
import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';
|
|
6
|
+
import { useProjection, useRunStore } from '@swirls/looms/react';
|
|
7
|
+
import { Markdown } from '../../components/markdown.js';
|
|
8
|
+
import { Button } from '../../components/ui/button.js';
|
|
9
|
+
import { EmptyState } from '../../components/ui/panel.js';
|
|
10
|
+
import { ScrollArea } from '../../components/ui/scroll-area.js';
|
|
11
|
+
import { Textarea } from '../../components/ui/textarea.js';
|
|
12
|
+
import { cn, errorMessage } from '../../lib/cn.js';
|
|
13
|
+
import { compactRelativeTime, fullDateTime } from '../../lib/time.js';
|
|
14
|
+
import { useNow } from '../../lib/use-now.js';
|
|
15
|
+
import { useApi, useShuttle, useShuttleHost } from '../../shuttle/index.js';
|
|
16
|
+
import { GithubNotConnectedError, postPullComment, pullThreads, setPullThreadResolved, syncPullThreads, } from '../pulls/pull-threads.js';
|
|
17
|
+
import { pullInbox, pullKey, pullOfSession, usePullsRunId } from '../pulls/pulls.js';
|
|
18
|
+
import { sessionFeed } from '../sessions/session-feed.js';
|
|
19
|
+
import { decideStructuredApproval } from '../sessions/signals.js';
|
|
20
|
+
import { FILE_OPTIONS, SURFACE_STYLE } from './diff-style.js';
|
|
21
|
+
import { anchorsIn, reviewFiles } from './review-diff.js';
|
|
22
|
+
import { patchOf } from './sandbox.js';
|
|
23
|
+
// Long lines wrap: the tab is narrow, and a diff that scrolls sideways carries the threads on
|
|
24
|
+
// it out of view along with the code.
|
|
25
|
+
const DIFF_OPTIONS = {
|
|
26
|
+
...FILE_OPTIONS,
|
|
27
|
+
diffStyle: 'unified',
|
|
28
|
+
overflow: 'wrap',
|
|
29
|
+
};
|
|
30
|
+
const sideOf = (side) => (side === 'deletions' ? 'LEFT' : 'RIGHT');
|
|
31
|
+
/** The lines picked with the gutter button, first to last whichever way they were dragged. */
|
|
32
|
+
function commentRange(picked) {
|
|
33
|
+
const from = { line: picked.start, side: sideOf(picked.side) };
|
|
34
|
+
const to = { line: picked.end, side: sideOf(picked.endSide ?? picked.side) };
|
|
35
|
+
const [first, last] = from.line <= to.line ? [from, to] : [to, from];
|
|
36
|
+
return { startLine: first.line, startSide: first.side, line: last.line, side: last.side };
|
|
37
|
+
}
|
|
38
|
+
const linesLabel = (start, end) => start === end ? `line ${end}` : `lines ${start}–${end}`;
|
|
39
|
+
const ReviewActionsContext = createContext(null);
|
|
40
|
+
const VERDICT_LABEL = {
|
|
41
|
+
comment: 'Comment',
|
|
42
|
+
approve: 'Approve',
|
|
43
|
+
request_changes: 'Request changes',
|
|
44
|
+
};
|
|
45
|
+
/** A comment's text as GitHub shows it, with a proposed replacement as a suggestion block. */
|
|
46
|
+
function withSuggestion(body, suggestion) {
|
|
47
|
+
return suggestion ? `${body}\n\n\`\`\`suggestion\n${suggestion}\n\`\`\`` : body;
|
|
48
|
+
}
|
|
49
|
+
const plural = (count, one, many = `${one}s`) => `${count} ${count === 1 ? one : many}`;
|
|
50
|
+
export function ReviewViewer({ runId, folderId }) {
|
|
51
|
+
const host = useShuttleHost();
|
|
52
|
+
const api = useApi();
|
|
53
|
+
const feed = useProjection(useRunStore(runId), sessionFeed);
|
|
54
|
+
const pullsStore = useRunStore(usePullsRunId());
|
|
55
|
+
const inbox = useProjection(pullsStore, pullInbox);
|
|
56
|
+
const mirrored = useProjection(pullsStore, pullThreads);
|
|
57
|
+
const pull = useMemo(() => pullOfSession(inbox, runId), [inbox, runId]);
|
|
58
|
+
const threads = useMemo(() => (pull ? (mirrored.pulls[pullKey(pull.fullName, pull.number)] ?? []) : []), [mirrored, pull]);
|
|
59
|
+
// Every repository's changes, as one patch. Read when the review opens, and again when the
|
|
60
|
+
// session's events say its files changed (see `ArtifactPane`).
|
|
61
|
+
const diff = useQuery(api.sandbox.diff.queryOptions({ input: { id: runId }, staleTime: 0, select: patchOf }));
|
|
62
|
+
// Null while the changes are being read. A read that failed leaves nothing to show.
|
|
63
|
+
const diffText = diff.data ?? (diff.isError ? '' : null);
|
|
64
|
+
const diffError = diff.error && diff.data === undefined ? diff.error.message : null;
|
|
65
|
+
// Until someone edits them, the summary and verdict are the ones the reviewer proposed.
|
|
66
|
+
const [summaryEdit, setSummary] = useState(null);
|
|
67
|
+
const [verdictEdit, setVerdict] = useState(null);
|
|
68
|
+
const summary = summaryEdit ?? feed.reviewProposal?.summary ?? '';
|
|
69
|
+
const verdict = verdictEdit ?? feed.reviewProposal?.verdict ?? 'comment';
|
|
70
|
+
const outcome = feed.reviewOutcome;
|
|
71
|
+
const approvalId = feed.pendingReviewApprovalId;
|
|
72
|
+
const [edits, setEdits] = useState({});
|
|
73
|
+
const drafts = useMemo(() => feed.draftReviewComments.map((draft) => {
|
|
74
|
+
const edit = edits[draft.commentId];
|
|
75
|
+
return {
|
|
76
|
+
...draft,
|
|
77
|
+
enabled: edit?.enabled ?? true,
|
|
78
|
+
editedBody: edit?.editedBody ?? draft.body,
|
|
79
|
+
};
|
|
80
|
+
}), [edits, feed.draftReviewComments]);
|
|
81
|
+
const updateDraft = useCallback((next) => {
|
|
82
|
+
setEdits((prev) => ({
|
|
83
|
+
...prev,
|
|
84
|
+
[next.commentId]: { enabled: next.enabled, editedBody: next.editedBody },
|
|
85
|
+
}));
|
|
86
|
+
}, []);
|
|
87
|
+
// Webhooks keep the threads current, but only from when Shuttle was connected and only when
|
|
88
|
+
// every delivery arrives, so GitHub is asked for the whole set whenever the review is opened.
|
|
89
|
+
const fullName = pull?.fullName;
|
|
90
|
+
const number = pull?.number;
|
|
91
|
+
const pullOnGithub = useMemo(() => (folderId && fullName && number !== undefined ? { folderId, fullName, number } : null), [folderId, fullName, number]);
|
|
92
|
+
const sync = useMutation({
|
|
93
|
+
mutationFn: (target) => syncPullThreads(host, target.folderId, target.fullName, target.number),
|
|
94
|
+
});
|
|
95
|
+
const syncing = sync.isPending;
|
|
96
|
+
const syncError = sync.error ? errorMessage(sync.error) : null;
|
|
97
|
+
const { mutate: syncThreads } = sync;
|
|
98
|
+
const synced = useRef(null);
|
|
99
|
+
// The sync is a request to GitHub made once per pull request this tab shows, not a read of
|
|
100
|
+
// something the page keeps: what it finds arrives through the pull requests' event stream.
|
|
101
|
+
useEffect(() => {
|
|
102
|
+
const key = pullOnGithub ? `${pullOnGithub.fullName}#${pullOnGithub.number}` : null;
|
|
103
|
+
if (pullOnGithub && key && synced.current !== key) {
|
|
104
|
+
synced.current = key;
|
|
105
|
+
syncThreads(pullOnGithub);
|
|
106
|
+
}
|
|
107
|
+
}, [pullOnGithub, syncThreads]);
|
|
108
|
+
const actions = useMemo(() => folderId && fullName && number !== undefined
|
|
109
|
+
? {
|
|
110
|
+
comment: (target, body) => postPullComment(host, folderId, fullName, number, target, body),
|
|
111
|
+
resolve: (rootId, resolved) => setPullThreadResolved(host, folderId, fullName, number, rootId, resolved),
|
|
112
|
+
}
|
|
113
|
+
: null, [host, folderId, fullName, number]);
|
|
114
|
+
const files = useMemo(() => (diffText ? reviewFiles(diffText) : []), [diffText]);
|
|
115
|
+
// Everything said, sorted into the file it is about, and within it onto a line when the diff
|
|
116
|
+
// still shows that line. The rest is listed above the file's diff, or under no file at all.
|
|
117
|
+
const placed = useMemo(() => {
|
|
118
|
+
const byPath = new Map(files.map((file) => [file.path, file]));
|
|
119
|
+
const perFile = new Map();
|
|
120
|
+
const elsewhere = {
|
|
121
|
+
drafts: [],
|
|
122
|
+
threads: [],
|
|
123
|
+
};
|
|
124
|
+
const slot = (path) => {
|
|
125
|
+
let entry = perFile.get(path);
|
|
126
|
+
if (!entry) {
|
|
127
|
+
entry = { lines: new Map(), loose: { drafts: [], threads: [] } };
|
|
128
|
+
perFile.set(path, entry);
|
|
129
|
+
}
|
|
130
|
+
return entry;
|
|
131
|
+
};
|
|
132
|
+
const onLine = (file, side, line, add) => {
|
|
133
|
+
const { lines } = slot(file.path);
|
|
134
|
+
const key = `${side}:${line}`;
|
|
135
|
+
lines.set(key, add(lines.get(key) ?? { drafts: [], threads: [] }));
|
|
136
|
+
};
|
|
137
|
+
for (const draft of drafts) {
|
|
138
|
+
const file = byPath.get(draft.path);
|
|
139
|
+
if (!file) {
|
|
140
|
+
elsewhere.drafts.push(draft);
|
|
141
|
+
}
|
|
142
|
+
else if (anchorsIn(file, draft.side, draft.line)) {
|
|
143
|
+
onLine(file, draft.side, draft.line, (notes) => ({
|
|
144
|
+
...notes,
|
|
145
|
+
drafts: [...notes.drafts, draft],
|
|
146
|
+
}));
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
slot(file.path).loose.drafts.push(draft);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
for (const thread of threads) {
|
|
153
|
+
const first = thread.comments[0];
|
|
154
|
+
if (!first) {
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
const file = byPath.get(first.path);
|
|
158
|
+
if (!file) {
|
|
159
|
+
elsewhere.threads.push(thread);
|
|
160
|
+
}
|
|
161
|
+
else if (!first.outdated &&
|
|
162
|
+
first.line !== null &&
|
|
163
|
+
anchorsIn(file, first.side, first.line)) {
|
|
164
|
+
onLine(file, first.side, first.line, (notes) => ({
|
|
165
|
+
...notes,
|
|
166
|
+
threads: [...notes.threads, thread],
|
|
167
|
+
}));
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
slot(file.path).loose.threads.push(thread);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return { perFile, elsewhere };
|
|
174
|
+
}, [drafts, files, threads]);
|
|
175
|
+
const included = drafts.filter((draft) => draft.enabled).length;
|
|
176
|
+
const open = threads.filter((thread) => !thread.resolved).length;
|
|
177
|
+
const send = useMutation({
|
|
178
|
+
mutationFn: (approval) => decideStructuredApproval(host, runId, approval, {
|
|
179
|
+
actionId: 'submit',
|
|
180
|
+
outcome: 'approve',
|
|
181
|
+
payload: {
|
|
182
|
+
summary: summary.trim() || 'Shuttle review',
|
|
183
|
+
verdict,
|
|
184
|
+
comments: drafts
|
|
185
|
+
.filter((draft) => draft.enabled)
|
|
186
|
+
.map((draft) => ({
|
|
187
|
+
path: draft.path,
|
|
188
|
+
line: draft.line,
|
|
189
|
+
side: draft.side,
|
|
190
|
+
body: withSuggestion(draft.editedBody.trim() || draft.body, draft.suggestion),
|
|
191
|
+
})),
|
|
192
|
+
},
|
|
193
|
+
}),
|
|
194
|
+
});
|
|
195
|
+
const pending = send.isPending;
|
|
196
|
+
const error = send.error ? errorMessage(send.error) : null;
|
|
197
|
+
const nothingYet = drafts.length === 0 && threads.length === 0 && files.length === 0;
|
|
198
|
+
if (nothingYet && diffText !== null && !syncing) {
|
|
199
|
+
return (_jsx(EmptyState, { icon: _jsx(GitPullRequest, {}), title: "Nothing to review yet", children: diffError ??
|
|
200
|
+
'The pull request’s changes, the threads on it and the comments the reviewer drafts all show up here.' }));
|
|
201
|
+
}
|
|
202
|
+
const showForm = Boolean(approvalId) || drafts.length > 0 || outcome !== undefined;
|
|
203
|
+
return (_jsx(ReviewActionsContext.Provider, { value: actions, children: _jsxs("div", { className: "flex h-full min-h-0 flex-col", children: [_jsxs("div", { className: "text-muted-foreground flex h-8 shrink-0 items-center gap-2 border-b px-2.5 text-[11px]", children: [_jsx(GitPullRequest, { "aria-hidden": true, className: "size-3 shrink-0" }), pull ? (_jsxs("a", { href: pull.url, target: "_blank", rel: "noreferrer", title: `${pull.fullName}#${pull.number}: ${pull.title}`, className: "text-foreground hover:text-brand min-w-0 truncate outline-none focus-visible:underline", children: [_jsxs("span", { className: "tabular-nums", children: ["#", pull.number] }), " ", pull.title] })) : (_jsx("span", { className: "text-foreground", children: "Review" })), _jsx("span", { className: "ml-auto shrink-0 tabular-nums", children: [
|
|
204
|
+
drafts.length > 0 ? plural(drafts.length, 'draft') : null,
|
|
205
|
+
threads.length > 0
|
|
206
|
+
? `${open} open of ${plural(threads.length, 'thread')}`
|
|
207
|
+
: 'no threads on GitHub',
|
|
208
|
+
]
|
|
209
|
+
.filter(Boolean)
|
|
210
|
+
.join(' · ') }), folderId && pull ? (_jsx("button", { type: "button", onClick: () => pullOnGithub && syncThreads(pullOnGithub), disabled: syncing, title: syncError ?? 'Fetch the threads on this pull request from GitHub again', "aria-label": "Refresh threads from GitHub", className: cn('hover:text-foreground focus-visible:ring-ring/50 shrink-0 rounded-sm p-0.5 outline-none focus-visible:ring-2', syncError && 'text-status-failed'), children: _jsx(RefreshCw, { className: cn('size-3', syncing && 'animate-spin') }) })) : null] }), syncError ? (_jsxs("p", { role: "alert", className: "text-status-failed shrink-0 border-b px-3 py-1.5 text-[11.5px]", children: ["The threads on GitHub could not be read, so these may be out of date. ", syncError] })) : null, showForm ? (_jsxs("div", { className: "flex shrink-0 flex-col gap-2 border-b px-3 py-2.5", children: [_jsx(Textarea, { value: summary, onChange: (event) => setSummary(event.target.value), placeholder: "Summary of the review", "aria-label": "Summary of the review", className: "min-h-14 resize-none text-[12.5px]", disabled: pending || !approvalId }), _jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [['comment', 'approve', 'request_changes'].map((option) => (_jsx("button", { type: "button", disabled: pending || !approvalId, "aria-pressed": verdict === option, onClick: () => setVerdict(option), className: cn('rounded-full border px-2.5 py-1 text-[11px] font-medium transition-colors', verdict === option
|
|
211
|
+
? 'border-brand/40 bg-brand/10 text-brand'
|
|
212
|
+
: 'text-muted-foreground hover:text-foreground'), children: VERDICT_LABEL[option] }, option))), _jsxs("div", { className: "ml-auto flex items-center gap-2", children: [error ? _jsx("span", { className: "text-status-failed text-[11px]", children: error }) : null, approvalId ? (_jsxs(Button, { type: "button", variant: "brand", size: "sm", disabled: pending, onClick: () => send.mutate(approvalId), children: [pending ? (_jsx(LoaderCircle, { className: "size-3.5 animate-spin" })) : (_jsx(Check, { className: "size-3.5" })), "Send ", included > 0 ? plural(included, 'comment') : 'review'] })) : (_jsx("span", { className: "text-muted-foreground text-[11px]", children: outcome?.status === 'submitted'
|
|
213
|
+
? 'Sent to GitHub'
|
|
214
|
+
: outcome?.status === 'failed'
|
|
215
|
+
? 'Not sent'
|
|
216
|
+
: 'The reviewer is still drafting…' }))] })] })] })) : null, outcome?.status === 'failed' ? (_jsxs("p", { role: "alert", className: "text-status-failed shrink-0 border-b px-3 py-2 text-[12px] leading-snug wrap-anywhere", children: ["GitHub did not take the review, so nothing was posted. ", outcome.error, " Ask the reviewer to submit again once this is sorted out."] })) : outcome?.status === 'submitted' ? (_jsxs("p", { className: "text-muted-foreground shrink-0 border-b px-3 py-2 text-[12px] leading-snug", children: ["Review sent to GitHub with ", plural(outcome.commentCount, 'inline comment'), ".", outcome.unanchoredCount > 0
|
|
217
|
+
? ` ${outcome.unanchoredCount} more could not be placed on a line of the diff and went in the review's summary.`
|
|
218
|
+
: ''] })) : null, _jsx(ScrollArea, { className: "min-h-0 flex-1", children: _jsxs("div", { className: "flex flex-col gap-5 py-3", children: [diffError && !nothingYet ? (_jsxs("p", { className: "text-status-failed px-3 text-xs", children: ["The pull request\u2019s changes could not be loaded. ", diffError] })) : diffText === null ? (_jsx("p", { className: "text-muted-foreground px-3 text-xs", children: "Loading changes\u2026" })) : null, files.map((file) => (_jsx(FileReview, { file: file, notes: placed.perFile.get(file.path), onDraftChange: updateDraft }, file.path))), placed.elsewhere.drafts.length > 0 || placed.elsewhere.threads.length > 0 ? (_jsxs("section", { className: "flex flex-col gap-2 px-3", children: [_jsx("h3", { className: "text-muted-foreground text-[11px] font-medium", children: "On files these changes no longer touch" }), _jsx(NoteList, { drafts: placed.elsewhere.drafts, threads: placed.elsewhere.threads, onDraftChange: updateDraft, showPath: true })] })) : null] }) })] }) }));
|
|
219
|
+
}
|
|
220
|
+
/** One file of the pull request: its diff, with what was said about it on the lines it is about. */
|
|
221
|
+
function FileReview({ file, notes, onDraftChange, }) {
|
|
222
|
+
const actions = useContext(ReviewActionsContext);
|
|
223
|
+
// The lines a new comment is being written on. It sits under the last of them.
|
|
224
|
+
const [range, setRange] = useState(null);
|
|
225
|
+
const composing = range ? `${range.side}:${range.line}` : null;
|
|
226
|
+
const annotations = useMemo(() => {
|
|
227
|
+
const lines = new Map(notes?.lines);
|
|
228
|
+
if (composing && !lines.has(composing)) {
|
|
229
|
+
lines.set(composing, { drafts: [], threads: [] });
|
|
230
|
+
}
|
|
231
|
+
return [...lines].map(([key, metadata]) => {
|
|
232
|
+
const [side, line] = key.split(':');
|
|
233
|
+
return {
|
|
234
|
+
side: side === 'LEFT' ? 'deletions' : 'additions',
|
|
235
|
+
lineNumber: Number(line),
|
|
236
|
+
metadata: { ...metadata, key },
|
|
237
|
+
};
|
|
238
|
+
});
|
|
239
|
+
}, [notes, composing]);
|
|
240
|
+
// The diff's own gutter button starts a comment on the line it is pressed on, or on every
|
|
241
|
+
// line it is dragged across.
|
|
242
|
+
const options = useMemo(() => actions
|
|
243
|
+
? {
|
|
244
|
+
...DIFF_OPTIONS,
|
|
245
|
+
enableGutterUtility: true,
|
|
246
|
+
onGutterUtilityClick: (picked) => setRange(commentRange(picked)),
|
|
247
|
+
}
|
|
248
|
+
: DIFF_OPTIONS, [actions]);
|
|
249
|
+
// The diff keeps a pressed line selected, and pins its gutter button there, until told
|
|
250
|
+
// otherwise. Only the line being commented on stays selected; with none, nothing is.
|
|
251
|
+
const selected = useMemo(() => range
|
|
252
|
+
? {
|
|
253
|
+
start: range.startLine,
|
|
254
|
+
side: range.startSide === 'LEFT' ? 'deletions' : 'additions',
|
|
255
|
+
end: range.line,
|
|
256
|
+
endSide: range.side === 'LEFT' ? 'deletions' : 'additions',
|
|
257
|
+
}
|
|
258
|
+
: null, [range]);
|
|
259
|
+
const count = (notes?.loose.drafts.length ?? 0) +
|
|
260
|
+
(notes?.loose.threads.length ?? 0) +
|
|
261
|
+
annotations.reduce((total, annotation) => total + annotation.metadata.drafts.length + annotation.metadata.threads.length, 0);
|
|
262
|
+
return (_jsxs("section", { className: "min-w-0", children: [_jsxs("header", { className: "bg-background sticky top-0 z-10 flex items-baseline gap-2 border-b px-3 py-1.5 font-mono text-[11px]", children: [_jsx("span", { className: "text-foreground min-w-0 truncate font-medium", title: file.path, children: file.path }), _jsxs("span", { className: "text-status-completed shrink-0 tabular-nums", children: ["+", file.additions] }), _jsxs("span", { className: "text-destructive shrink-0 tabular-nums", children: ["\u2212", file.deletions] }), count > 0 ? (_jsx("span", { className: "text-muted-foreground ml-auto shrink-0 font-sans tabular-nums", children: plural(count, 'comment thread') })) : null] }), notes && (notes.loose.drafts.length > 0 || notes.loose.threads.length > 0) ? (_jsxs("div", { className: "flex flex-col gap-2 border-b px-3 py-2", children: [_jsx("p", { className: "text-muted-foreground text-[11px]", children: "On lines these changes no longer show" }), _jsx(NoteList, { drafts: notes.loose.drafts, threads: notes.loose.threads, onDraftChange: onDraftChange })] })) : null, _jsx("div", { style: SURFACE_STYLE, children: _jsx(PatchDiff, { patch: file.patch, options: options, selectedLines: selected, lineAnnotations: annotations, renderAnnotation: (annotation) => {
|
|
263
|
+
const { key, drafts, threads } = annotation.metadata;
|
|
264
|
+
return (_jsxs("div", { className: "bg-muted/30 border-border/60 flex w-0 min-w-full flex-col gap-2 border-y px-3 py-2 font-sans", children: [_jsx(NoteList, { drafts: drafts, threads: threads, onDraftChange: onDraftChange }), actions && range && composing === key ? (_jsx(Composer, { label: `Comment on ${file.path} ${linesLabel(range.startLine, range.line)}`, placeholder: range.startLine === range.line
|
|
265
|
+
? 'Start a thread on this line'
|
|
266
|
+
: `Start a thread on ${linesLabel(range.startLine, range.line)}`, send: "Comment", autoFocus: true, onCancel: () => setRange(null), onSend: async (body) => {
|
|
267
|
+
await actions.comment({
|
|
268
|
+
path: file.path,
|
|
269
|
+
line: range.line,
|
|
270
|
+
side: range.side,
|
|
271
|
+
...(range.startLine === range.line
|
|
272
|
+
? {}
|
|
273
|
+
: { startLine: range.startLine, startSide: range.startSide }),
|
|
274
|
+
}, body);
|
|
275
|
+
setRange(null);
|
|
276
|
+
} })) : null] }));
|
|
277
|
+
} }) })] }));
|
|
278
|
+
}
|
|
279
|
+
function NoteList({ drafts, threads, onDraftChange, showPath, }) {
|
|
280
|
+
return (_jsxs(_Fragment, { children: [threads.map((thread) => (_jsx(ThreadCard, { thread: thread, showPath: showPath }, thread.rootId))), drafts.map((draft) => (_jsx(DraftCard, { draft: draft, onChange: onDraftChange, showPath: showPath }, draft.commentId)))] }));
|
|
281
|
+
}
|
|
282
|
+
/** A thread from GitHub. A resolved one is folded to a line until it is opened. */
|
|
283
|
+
function ThreadCard({ thread, showPath }) {
|
|
284
|
+
const now = useNow();
|
|
285
|
+
const actions = useContext(ReviewActionsContext);
|
|
286
|
+
const [replying, setReplying] = useState(false);
|
|
287
|
+
const resolve = useMutation({
|
|
288
|
+
mutationFn: (to) => to.resolve(thread.rootId, to.resolved),
|
|
289
|
+
});
|
|
290
|
+
const resolving = resolve.isPending;
|
|
291
|
+
const resolveError = resolve.error ? errorMessage(resolve.error) : null;
|
|
292
|
+
const [opened, setOpened] = useState(null);
|
|
293
|
+
const expanded = opened ?? !thread.resolved;
|
|
294
|
+
const first = thread.comments[0];
|
|
295
|
+
if (!first) {
|
|
296
|
+
return null;
|
|
297
|
+
}
|
|
298
|
+
return (_jsxs("div", { className: "bg-card rounded-md border text-[12px]", children: [_jsxs("button", { type: "button", "aria-expanded": expanded, onClick: () => setOpened(!expanded), className: "text-muted-foreground hover:text-foreground focus-visible:ring-ring/50 flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-[11px] outline-none focus-visible:ring-2", children: [_jsx(ChevronRight, { "aria-hidden": true, className: cn('size-3 shrink-0 transition-transform', expanded && 'rotate-90') }), _jsx("span", { className: "text-foreground shrink-0 font-medium", children: first.author.login }), thread.comments.length > 1 ? (_jsxs("span", { className: "shrink-0", children: ["+", plural(thread.comments.length - 1, 'reply', 'replies')] })) : null, showPath || first.outdated ? (_jsxs("span", { className: "min-w-0 truncate font-mono", children: [first.path, first.line === null ? '' : `:${first.line}`] })) : null, first.startLine !== undefined && first.line !== null && first.startLine !== first.line ? (_jsx("span", { className: "shrink-0", children: linesLabel(first.startLine, first.line) })) : null, expanded ? null : _jsx("span", { className: "min-w-0 flex-1 truncate", children: first.body }), _jsxs("span", { className: "ml-auto flex shrink-0 items-center gap-1.5", children: [first.outdated ? _jsx("span", { children: "Outdated" }) : null, thread.resolved ? (_jsxs("span", { className: "text-status-completed flex items-center gap-0.5", children: [_jsx(Check, { "aria-hidden": true, className: "size-3" }), "Resolved"] })) : null] })] }), expanded ? (_jsx("ul", { className: "flex flex-col border-t", children: thread.comments.map((comment) => (_jsxs("li", { className: "flex gap-2 px-2 py-1.5 not-first:border-t", children: [comment.author.avatarUrl ? (_jsx("img", { src: comment.author.avatarUrl, alt: "", className: "mt-0.5 size-4 shrink-0 rounded-full" })) : (_jsx("span", { "aria-hidden": true, className: "bg-muted mt-0.5 size-4 shrink-0 rounded-full" })), _jsxs("div", { className: "min-w-0 flex-1", children: [_jsxs("p", { className: "text-muted-foreground flex items-center gap-1.5 text-[11px]", children: [_jsx("span", { className: "text-foreground font-medium", children: comment.author.login }), _jsx("time", { title: fullDateTime(comment.createdAt), children: compactRelativeTime(comment.createdAt, now) }), comment.updatedAt > comment.createdAt ? _jsx("span", { children: "edited" }) : null, _jsx("a", { href: comment.url, target: "_blank", rel: "noreferrer", "aria-label": "Open this comment on GitHub", title: "Open on GitHub", className: "hover:text-foreground ml-auto shrink-0 outline-none focus-visible:underline", children: _jsx(ExternalLink, { className: "size-3" }) })] }), _jsx(Markdown, { text: comment.body, className: "text-[12px] leading-relaxed wrap-anywhere" })] })] }, comment.commentId))) })) : null, expanded && actions ? (_jsxs("div", { className: "flex flex-col gap-1.5 border-t px-2 py-1.5", children: [replying ? (_jsx(Composer, { label: `Reply to ${first.author.login}`, placeholder: "Reply", send: "Reply", autoFocus: true, onCancel: () => setReplying(false), onSend: async (body) => {
|
|
299
|
+
await actions.comment({ rootId: thread.rootId }, body);
|
|
300
|
+
setReplying(false);
|
|
301
|
+
} })) : (_jsxs("div", { className: "flex items-center gap-2", children: [_jsx("button", { type: "button", onClick: () => setReplying(true), className: "text-muted-foreground hover:text-foreground focus-visible:ring-ring/50 bg-background min-w-0 flex-1 rounded-sm border px-2 py-1 text-left text-[11.5px] outline-none focus-visible:ring-2", children: "Reply\u2026" }), _jsxs(Button, { type: "button", variant: "outline", size: "sm", disabled: resolving, onClick: () => resolve.mutate({ resolve: actions.resolve, resolved: !thread.resolved }), children: [resolving ? _jsx(LoaderCircle, { className: "size-3.5 animate-spin" }) : null, thread.resolved ? 'Reopen' : 'Resolve'] })] })), resolveError ? (_jsx("p", { role: "alert", className: "text-status-failed text-[11px] wrap-anywhere", children: resolveError })) : null] })) : null] }));
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Where the person writes something that goes to GitHub in their own name. Nothing is posted
|
|
305
|
+
* until they send it, and what they wrote stays put if GitHub does not take it.
|
|
306
|
+
*/
|
|
307
|
+
function Composer({ label, placeholder, send, autoFocus, onSend, onCancel, }) {
|
|
308
|
+
const { connectGithub } = useShuttle().identity;
|
|
309
|
+
const [body, setBody] = useState('');
|
|
310
|
+
const post = useMutation({ mutationFn: onSend });
|
|
311
|
+
const pending = post.isPending;
|
|
312
|
+
const error = post.error ? errorMessage(post.error) : null;
|
|
313
|
+
const needsGithub = post.error instanceof GithubNotConnectedError;
|
|
314
|
+
function submit() {
|
|
315
|
+
if (body.trim() && !pending) {
|
|
316
|
+
post.mutate(body.trim());
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
return (_jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx(Textarea, { value: body, onChange: (event) => setBody(event.target.value), onKeyDown: (event) => {
|
|
320
|
+
if (event.key === 'Enter' && (event.metaKey || event.ctrlKey)) {
|
|
321
|
+
event.preventDefault();
|
|
322
|
+
submit();
|
|
323
|
+
}
|
|
324
|
+
else if (event.key === 'Escape' && !body.trim()) {
|
|
325
|
+
onCancel();
|
|
326
|
+
}
|
|
327
|
+
}, placeholder: placeholder, "aria-label": label, autoFocus: autoFocus, disabled: pending, className: "bg-background min-h-14 resize-none text-[12px]" }), error ? (_jsx("p", { role: "alert", className: "text-status-failed text-[11px] wrap-anywhere", children: error })) : null, _jsxs("div", { className: "flex flex-wrap items-center justify-end gap-x-2 gap-y-1.5", children: [_jsx("span", { className: "text-muted-foreground mr-auto text-[11px] whitespace-nowrap", children: "Posts to GitHub as you" }), _jsxs("div", { className: "flex shrink-0 items-center gap-1.5", children: [needsGithub && connectGithub ? (_jsx(Button, { type: "button", variant: "outline", size: "sm", onClick: connectGithub, children: "Connect GitHub" })) : null, _jsx(Button, { type: "button", variant: "ghost", size: "sm", disabled: pending, onClick: onCancel, children: "Cancel" }), _jsxs(Button, { type: "button", variant: "brand", size: "sm", disabled: pending || !body.trim(), onClick: submit, children: [pending ? _jsx(LoaderCircle, { className: "size-3.5 animate-spin" }) : null, send] })] })] })] }));
|
|
328
|
+
}
|
|
329
|
+
/** A comment the reviewer drafted. Nothing here is on GitHub until the review is sent. */
|
|
330
|
+
function DraftCard({ draft, onChange, showPath, }) {
|
|
331
|
+
const tint = draft.severity === 'error'
|
|
332
|
+
? 'border-destructive/40 bg-destructive/8'
|
|
333
|
+
: draft.severity === 'warning'
|
|
334
|
+
? 'border-status-waiting/40 bg-status-waiting/8'
|
|
335
|
+
: 'border-brand/30 bg-brand/6';
|
|
336
|
+
return (_jsxs("div", { className: cn('rounded-md border p-2', tint, !draft.enabled && 'opacity-50'), children: [_jsxs("div", { className: "mb-1.5 flex items-center gap-2 text-[11px]", children: [_jsxs("label", { className: "flex items-center gap-1.5 font-medium", children: [_jsx("input", { type: "checkbox", checked: draft.enabled, onChange: (event) => onChange({ ...draft, enabled: event.target.checked }), className: "size-3" }), "Draft"] }), _jsx("span", { className: "text-muted-foreground", children: draft.severity }), showPath ? (_jsxs("span", { className: "text-muted-foreground min-w-0 truncate font-mono", children: [draft.path, ":", draft.line] })) : null, _jsx("span", { className: "text-muted-foreground ml-auto shrink-0", children: draft.enabled ? 'Will be sent' : 'Left out' })] }), _jsx(Textarea, { value: draft.editedBody, onChange: (event) => onChange({ ...draft, editedBody: event.target.value }), disabled: !draft.enabled, "aria-label": `Draft comment on ${draft.path} line ${draft.line}`, className: "min-h-14 resize-none text-[12px]" }), draft.suggestion ? (_jsxs("div", { className: "mt-1.5", children: [_jsx("p", { className: "text-muted-foreground mb-1 text-[10px] font-medium", children: "Suggested change" }), _jsx("pre", { className: "bg-status-completed/10 overflow-x-auto rounded-sm px-2 py-1.5 font-mono text-[11px] leading-[18px] whitespace-pre", children: draft.suggestion })] })) : null] }));
|
|
337
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { QueryClient } from '@tanstack/react-query';
|
|
2
|
+
import type { ChangeStatus, SandboxDiffs, SandboxFileDiff, SandboxPlace, SandboxWorkspaceRepo } from '@swirls/shuttle/api';
|
|
3
|
+
import { type ShuttleHost } from '../../shuttle/index.js';
|
|
4
|
+
/**
|
|
5
|
+
* The session's sandbox as the page asks about it. What the Worker answers is typed by the
|
|
6
|
+
* contract in `@swirls/shuttle/api`; views read it with `api.sandbox.….queryOptions(…)`. Here are the
|
|
7
|
+
* few things every view shares: which reads go stale together, how to tell the two answers of
|
|
8
|
+
* the diff route apart, and the addresses of the terminal and of previews.
|
|
9
|
+
*/
|
|
10
|
+
export type { ChangeStatus, SandboxPlace };
|
|
11
|
+
/** One repository in a session's workspace. Named as the workspace tree knows it. */
|
|
12
|
+
export type WorkspaceRepo = SandboxWorkspaceRepo;
|
|
13
|
+
/**
|
|
14
|
+
* Marks everything read from a session's worktree as out of date: its files, their contents,
|
|
15
|
+
* the changes, and what the language server said. Views that are showing any of it read again;
|
|
16
|
+
* the rest do when they are next shown.
|
|
17
|
+
*/
|
|
18
|
+
export declare function invalidateWorktree({ api }: ShuttleHost, queries: QueryClient, runId: string): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* The diff route answers with one file's changes when asked about a file, and with every
|
|
21
|
+
* repository's otherwise. This is the patch either way: the file's, or all of them joined.
|
|
22
|
+
*/
|
|
23
|
+
export declare function patchOf(answer: SandboxFileDiff | SandboxDiffs): string;
|
|
24
|
+
export interface SandboxIdentity {
|
|
25
|
+
readonly runId: string;
|
|
26
|
+
readonly folderId?: string;
|
|
27
|
+
}
|
|
28
|
+
export declare function sandboxTerminalUrl(host: ShuttleHost, identity: SandboxIdentity, options: {
|
|
29
|
+
cwd?: string;
|
|
30
|
+
cols?: number;
|
|
31
|
+
rows?: number;
|
|
32
|
+
}): string;
|
|
33
|
+
/** Where previews are served from: the backend, and the port when previews have their own. */
|
|
34
|
+
export type PreviewBackend = Pick<ShuttleHost, 'origin' | 'previewPort'>;
|
|
35
|
+
/**
|
|
36
|
+
* Preview host for sandbox ports: `p3000-<label>.localhost:8790` locally. Previews are
|
|
37
|
+
* subdomains of the backend, which is the page's own origin unless `backend` says otherwise.
|
|
38
|
+
*/
|
|
39
|
+
export declare function previewUrl(port: number, folderId: string, previewHost?: string, backend?: PreviewBackend): string;
|
|
40
|
+
export declare function sanitizeFolderLabel(folderId: string): string;
|
|
41
|
+
/** Extract a localhost / loopback port for sandbox preview rewriting. */
|
|
42
|
+
export declare function loopbackPreviewPort(target: string): number | null;
|
|
43
|
+
export declare function resolveBrowserTarget(target: string, folderId: string | undefined, previewHost?: string, backend?: PreviewBackend): string;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import {} from '../../shuttle/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Marks everything read from a session's worktree as out of date: its files, their contents,
|
|
4
|
+
* the changes, and what the language server said. Views that are showing any of it read again;
|
|
5
|
+
* the rest do when they are next shown.
|
|
6
|
+
*/
|
|
7
|
+
export function invalidateWorktree({ api }, queries, runId) {
|
|
8
|
+
const input = { id: runId };
|
|
9
|
+
return Promise.all([
|
|
10
|
+
queries.invalidateQueries({ queryKey: api.sandbox.workspace.key({ input }) }),
|
|
11
|
+
queries.invalidateQueries({ queryKey: api.sandbox.files.key({ input }) }),
|
|
12
|
+
queries.invalidateQueries({ queryKey: api.sandbox.file.key({ input }) }),
|
|
13
|
+
queries.invalidateQueries({ queryKey: api.sandbox.diff.key({ input }) }),
|
|
14
|
+
queries.invalidateQueries({ queryKey: api.sandbox.diagnostics.saved.key({ input }) }),
|
|
15
|
+
]).then(() => { });
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The diff route answers with one file's changes when asked about a file, and with every
|
|
19
|
+
* repository's otherwise. This is the patch either way: the file's, or all of them joined.
|
|
20
|
+
*/
|
|
21
|
+
export function patchOf(answer) {
|
|
22
|
+
return 'diffs' in answer ? answer.diffs.map((entry) => entry.diff).join('\n') : answer.diff;
|
|
23
|
+
}
|
|
24
|
+
function sandboxQuery(identity, extra) {
|
|
25
|
+
const params = new URLSearchParams(extra);
|
|
26
|
+
if (identity.folderId) {
|
|
27
|
+
params.set('folderId', identity.folderId);
|
|
28
|
+
}
|
|
29
|
+
const query = params.toString();
|
|
30
|
+
return query ? `?${query}` : '';
|
|
31
|
+
}
|
|
32
|
+
function sandboxBase(runId) {
|
|
33
|
+
return `/sessions/${encodeURIComponent(runId)}/sandbox`;
|
|
34
|
+
}
|
|
35
|
+
export function sandboxTerminalUrl(host, identity, options) {
|
|
36
|
+
const params = {};
|
|
37
|
+
if (options.cwd) {
|
|
38
|
+
params.cwd = options.cwd;
|
|
39
|
+
}
|
|
40
|
+
if (options.cols) {
|
|
41
|
+
params.cols = String(options.cols);
|
|
42
|
+
}
|
|
43
|
+
if (options.rows) {
|
|
44
|
+
params.rows = String(options.rows);
|
|
45
|
+
}
|
|
46
|
+
const query = sandboxQuery(identity, params);
|
|
47
|
+
return host.socketUrl(`${sandboxBase(identity.runId)}/terminal${query}`);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Preview host for sandbox ports: `p3000-<label>.localhost:8790` locally. Previews are
|
|
51
|
+
* subdomains of the backend, which is the page's own origin unless `backend` says otherwise.
|
|
52
|
+
*/
|
|
53
|
+
export function previewUrl(port, folderId, previewHost, backend) {
|
|
54
|
+
const at = backend
|
|
55
|
+
? new URL(backend.origin())
|
|
56
|
+
: typeof window !== 'undefined'
|
|
57
|
+
? window.location
|
|
58
|
+
: undefined;
|
|
59
|
+
const host = previewHost ?? `${at?.hostname.replace(/^www\./, '') ?? ''}`;
|
|
60
|
+
const workerPort = backend?.previewPort
|
|
61
|
+
? `:${backend.previewPort}`
|
|
62
|
+
: at?.port
|
|
63
|
+
? `:${at.port}`
|
|
64
|
+
: '';
|
|
65
|
+
// A preview needs a subdomain, which an IP address cannot have. Loopback addresses map to
|
|
66
|
+
// `localhost`, whose subdomains browsers resolve to the same machine.
|
|
67
|
+
const loopback = host.includes('localhost') || host.endsWith('.local') || isLoopbackAddress(host);
|
|
68
|
+
const baseHost = loopback ? 'localhost' : host;
|
|
69
|
+
// A page served over https cannot frame an http one, and a deployment only answers https.
|
|
70
|
+
const secure = !loopback && at?.protocol === 'https:';
|
|
71
|
+
return `${secure ? 'https' : 'http'}://p${port}-${sanitizeFolderLabel(folderId)}.${baseHost}${workerPort}`;
|
|
72
|
+
}
|
|
73
|
+
function isLoopbackAddress(host) {
|
|
74
|
+
return (/^127(\.\d{1,3}){3}$/.test(host) || host === '0.0.0.0' || host === '[::1]' || host === '::1');
|
|
75
|
+
}
|
|
76
|
+
export function sanitizeFolderLabel(folderId) {
|
|
77
|
+
return folderId.replace(/[^a-zA-Z0-9-]/g, '').slice(0, 48) || 'folder';
|
|
78
|
+
}
|
|
79
|
+
/** Extract a localhost / loopback port for sandbox preview rewriting. */
|
|
80
|
+
export function loopbackPreviewPort(target) {
|
|
81
|
+
const trimmed = target.trim();
|
|
82
|
+
if (/^\d+$/.test(trimmed)) {
|
|
83
|
+
const port = Number(trimmed);
|
|
84
|
+
return Number.isFinite(port) && port >= 1 && port <= 65535 ? port : null;
|
|
85
|
+
}
|
|
86
|
+
const match = trimmed.match(/^(?:https?:\/\/)?(?:localhost|127\.0\.0\.1|\[::1\])(?::(\d+))?(?:[/?#]|$)/i);
|
|
87
|
+
if (!match) {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
const port = match[1] ? Number(match[1]) : 80;
|
|
91
|
+
return Number.isFinite(port) && port >= 1 && port <= 65535 ? port : null;
|
|
92
|
+
}
|
|
93
|
+
export function resolveBrowserTarget(target, folderId, previewHost, backend) {
|
|
94
|
+
const trimmed = target.trim();
|
|
95
|
+
if (!trimmed) {
|
|
96
|
+
return '';
|
|
97
|
+
}
|
|
98
|
+
const loopbackPort = loopbackPreviewPort(trimmed);
|
|
99
|
+
if (loopbackPort != null && folderId) {
|
|
100
|
+
return previewUrl(loopbackPort, folderId, previewHost, backend);
|
|
101
|
+
}
|
|
102
|
+
if (/^https?:\/\//i.test(trimmed)) {
|
|
103
|
+
return trimmed;
|
|
104
|
+
}
|
|
105
|
+
if (trimmed.startsWith('//')) {
|
|
106
|
+
return `http:${trimmed}`;
|
|
107
|
+
}
|
|
108
|
+
return `http://${trimmed}`;
|
|
109
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ArtifactTab, ArtifactTabKind } from '../workspace/workspace.js';
|
|
2
|
+
import { type ArtifactType } from './artifact-types.js';
|
|
3
|
+
export declare function TabStrip({ tabs, types, activeTabId, onSelect, onClose, onReorder, onOpen, }: {
|
|
4
|
+
tabs: readonly ArtifactTab[];
|
|
5
|
+
types: readonly ArtifactType[];
|
|
6
|
+
activeTabId: string | null;
|
|
7
|
+
onSelect: (tabId: string) => void;
|
|
8
|
+
onClose: (tabId: string) => void;
|
|
9
|
+
onReorder: (tabIds: string[]) => void;
|
|
10
|
+
onOpen: (kind: ArtifactTabKind) => void;
|
|
11
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Plus, X } from 'lucide-react';
|
|
3
|
+
import { useRef, useState } from 'react';
|
|
4
|
+
import { Button } from '../../components/ui/button.js';
|
|
5
|
+
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from '../../components/ui/dropdown-menu.js';
|
|
6
|
+
import { ScrollArea } from '../../components/ui/scroll-area.js';
|
|
7
|
+
import { cn } from '../../lib/cn.js';
|
|
8
|
+
import { artifactTypeFor, launchableArtifactTypes } from './artifact-types.js';
|
|
9
|
+
export function TabStrip({ tabs, types, activeTabId, onSelect, onClose, onReorder, onOpen, }) {
|
|
10
|
+
const [draggingId, setDraggingId] = useState(null);
|
|
11
|
+
const dragOverId = useRef(null);
|
|
12
|
+
const order = tabs.map((tab) => tab.tabId);
|
|
13
|
+
function dropOn(targetId) {
|
|
14
|
+
if (!draggingId || draggingId === targetId) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const next = order.filter((id) => id !== draggingId);
|
|
18
|
+
const index = next.indexOf(targetId);
|
|
19
|
+
if (index < 0) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
next.splice(index, 0, draggingId);
|
|
23
|
+
onReorder(next);
|
|
24
|
+
}
|
|
25
|
+
return (_jsxs("div", { className: "flex h-12 shrink-0 items-center gap-0.5 border-b px-1.5", children: [_jsx(ScrollArea, { horizontal: true, vertical: false, barClassName: "h-1.5", className: "min-w-0 flex-1", viewportClassName: "[&>div]:flex! [&>div]:h-12 [&>div]:w-max [&>div]:items-center [&>div]:gap-0.5", children: tabs.map((tab) => {
|
|
26
|
+
const active = tab.tabId === activeTabId;
|
|
27
|
+
const type = artifactTypeFor(types, tab.kind);
|
|
28
|
+
const label = type?.tabLabel?.(tab) ?? tab.title;
|
|
29
|
+
return (_jsxs("button", { type: "button", draggable: true, onDragStart: (event) => {
|
|
30
|
+
setDraggingId(tab.tabId);
|
|
31
|
+
event.dataTransfer.effectAllowed = 'move';
|
|
32
|
+
event.dataTransfer.setData('text/plain', tab.tabId);
|
|
33
|
+
}, onDragEnd: () => {
|
|
34
|
+
setDraggingId(null);
|
|
35
|
+
dragOverId.current = null;
|
|
36
|
+
}, onDragOver: (event) => {
|
|
37
|
+
event.preventDefault();
|
|
38
|
+
dragOverId.current = tab.tabId;
|
|
39
|
+
}, onDrop: (event) => {
|
|
40
|
+
event.preventDefault();
|
|
41
|
+
dropOn(tab.tabId);
|
|
42
|
+
setDraggingId(null);
|
|
43
|
+
}, onClick: () => onSelect(tab.tabId), onAuxClick: (event) => {
|
|
44
|
+
if (event.button === 1) {
|
|
45
|
+
event.preventDefault();
|
|
46
|
+
onClose(tab.tabId);
|
|
47
|
+
}
|
|
48
|
+
}, title: label, className: cn('group relative inline-flex h-7 max-w-44 shrink-0 items-center gap-1.5 rounded-md px-2 text-[12px] transition-[color,background-color,opacity] duration-100 ease-out', active
|
|
49
|
+
? 'bg-background text-foreground shadow-sm'
|
|
50
|
+
: 'text-muted-foreground hover:bg-accent/50 hover:text-foreground', draggingId === tab.tabId && 'opacity-50'), children: [_jsx("span", { className: "text-muted-foreground [&_svg]:size-3.5", children: type?.icon }), _jsx("span", { className: "min-w-0 truncate", dir: "auto", children: label }), _jsx("span", { role: "button", tabIndex: -1, "aria-label": `Close ${label}`, onClick: (event) => {
|
|
51
|
+
event.stopPropagation();
|
|
52
|
+
onClose(tab.tabId);
|
|
53
|
+
}, className: cn('text-muted-foreground hover:text-foreground hover:bg-background/70 -mr-0.5 flex size-4 shrink-0 items-center justify-center rounded-sm transition-opacity duration-100', active ? 'opacity-70' : 'opacity-0 group-hover:opacity-70'), children: _jsx(X, { className: "size-3" }) })] }, tab.tabId));
|
|
54
|
+
}) }), _jsxs(DropdownMenu, { children: [_jsx(DropdownMenuTrigger, { asChild: true, children: _jsx(Button, { variant: "ghost", size: "icon-sm", "aria-label": "Open artifact", className: "shrink-0", children: _jsx(Plus, {}) }) }), _jsx(DropdownMenuContent, { align: "end", children: launchableArtifactTypes(types).map((type) => (_jsxs(DropdownMenuItem, { onSelect: () => onOpen(type.kind), children: [type.icon, type.label] }, type.kind))) })] })] }));
|
|
55
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
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 declare function resolveColor(value: string, fallback: string): string;
|
|
8
|
+
/** The app's monospace font list, as a value a canvas can use. */
|
|
9
|
+
export declare function terminalFontFamily(): string;
|
|
10
|
+
/** The terminal's colours: the app's surface and text, and sixteen ANSI colours tuned to sit on it. */
|
|
11
|
+
export declare function terminalTheme(): {
|
|
12
|
+
background: string;
|
|
13
|
+
foreground: string;
|
|
14
|
+
cursor: string;
|
|
15
|
+
cursorAccent: string;
|
|
16
|
+
selectionBackground: string;
|
|
17
|
+
selectionInactiveBackground: string;
|
|
18
|
+
black: string;
|
|
19
|
+
red: string;
|
|
20
|
+
green: string;
|
|
21
|
+
yellow: string;
|
|
22
|
+
blue: string;
|
|
23
|
+
magenta: string;
|
|
24
|
+
cyan: string;
|
|
25
|
+
white: string;
|
|
26
|
+
brightBlack: string;
|
|
27
|
+
brightRed: string;
|
|
28
|
+
brightGreen: string;
|
|
29
|
+
brightYellow: string;
|
|
30
|
+
brightBlue: string;
|
|
31
|
+
brightMagenta: string;
|
|
32
|
+
brightCyan: string;
|
|
33
|
+
brightWhite: string;
|
|
34
|
+
};
|