@lukstei/dsh-client-review-git 0.0.0-stage → 0.2.2-rc.5.3

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.
@@ -0,0 +1,470 @@
1
+ import {
2
+ Button,
3
+ IconChevronDownOutlineRegular,
4
+ IconRefreshOutlineRegular,
5
+ Menu,
6
+ Tooltip,
7
+ } from "@deepseek-ai/dsh-client-ui-primitives";
8
+ import type { TypertRemoteNamespace } from "@deepseek-ai/dsh-typert-protocol";
9
+ import styles from "@lukstei/util-review-ui/client/GitDiffPane.module.css";
10
+ import { formatRelativeTime } from "@lukstei/util-review-ui/client/relativeTime.ts";
11
+ import {
12
+ COMMIT_PAGE_SIZE,
13
+ type GitRepository,
14
+ MAX_BRANCH_AGE_MS,
15
+ type ReviewCatalog,
16
+ type ReviewScope,
17
+ type ReviewSelection,
18
+ } from "@lukstei/util-review-ui/types";
19
+ import { useCallback, useState } from "react";
20
+ import { useLoad } from "./useLoad.ts";
21
+
22
+ export function ReviewToolbar({
23
+ catalog,
24
+ activeRepository,
25
+ onSelectRepository,
26
+ selection,
27
+ base,
28
+ revision,
29
+ select,
30
+ api,
31
+ sessionId,
32
+ refresh,
33
+ }: {
34
+ catalog: ReviewCatalog | null;
35
+ activeRepository: GitRepository | null;
36
+ onSelectRepository: (cwd: string) => void;
37
+ selection: ReviewScope | null;
38
+ base: string;
39
+ revision: number;
40
+ select: (selection: ReviewScope) => void;
41
+ api: TypertRemoteNamespace<"workspaceReview">;
42
+ sessionId: string;
43
+ refresh: () => void;
44
+ }) {
45
+ const [scopeOpen, setScopeOpen] = useState(false);
46
+ const [repoOpen, setRepoOpen] = useState(false);
47
+ const [baselineOpen, setBaselineOpen] = useState(false);
48
+ const active = activeRepository;
49
+ const allBranches =
50
+ active !== null
51
+ ? active.branches.filter((branch) => branch.ref.startsWith("refs/heads/"))
52
+ : [];
53
+ const branches = allBranches.filter(
54
+ (branch) => Date.now() - branch.modifiedAt <= MAX_BRANCH_AGE_MS,
55
+ );
56
+ const options: {
57
+ id: string;
58
+ label: string;
59
+ value: ReviewScope;
60
+ disabled: boolean;
61
+ }[] = [
62
+ ...(active !== null
63
+ ? [
64
+ ...allBranches.map((branch) => ({
65
+ id: branch.ref,
66
+ label: branch.label,
67
+ disabled: false,
68
+ value: {
69
+ kind: "branch" as const,
70
+ repository: active.cwd,
71
+ ref: branch.ref,
72
+ base: { kind: "automatic" as const },
73
+ revision: { kind: "all-commits" as const },
74
+ },
75
+ })),
76
+ {
77
+ id: "staged",
78
+ label: "Staged changes",
79
+ value: {
80
+ kind: "uncommitted" as const,
81
+ repository: active.cwd,
82
+ stage: "staged" as const,
83
+ },
84
+ disabled: false,
85
+ },
86
+ {
87
+ id: "unstaged",
88
+ label: "Unstaged changes",
89
+ value: {
90
+ kind: "uncommitted" as const,
91
+ repository: active.cwd,
92
+ stage: "unstaged" as const,
93
+ },
94
+ disabled: false,
95
+ },
96
+ ]
97
+ : []),
98
+ ];
99
+ const selectedId =
100
+ selection === null
101
+ ? ""
102
+ : selection.kind === "branch"
103
+ ? selection.ref
104
+ : selection.stage;
105
+ const selectedOption = options.find((option) => option.id === selectedId);
106
+ const scopeLabel =
107
+ selectedOption === undefined ? "Select scope" : selectedOption.label;
108
+ const selectedBaseline =
109
+ active === null
110
+ ? undefined
111
+ : active.baselines.find((item) => item.ref === base);
112
+ const baselineLabel =
113
+ selectedBaseline === undefined ? "Baseline" : selectedBaseline.label;
114
+ const cwd =
115
+ active !== null
116
+ ? active.cwd
117
+ : catalog === null
118
+ ? "Repository"
119
+ : catalog.kind === "git"
120
+ ? catalog.repository.cwd
121
+ : catalog.cwd;
122
+ const nameOf = (path: string) =>
123
+ path.slice(Math.max(path.lastIndexOf("/"), path.lastIndexOf("\\")) + 1);
124
+ const name = nameOf(cwd);
125
+ let context = "";
126
+ if (active !== null) {
127
+ const comparisonBase =
128
+ selection !== null && selection.kind === "branch" ? base : active.target;
129
+ const baseline = active.baselines.find(
130
+ (item) => item.ref === comparisonBase,
131
+ );
132
+ if (baseline !== undefined) context = `vs ${baseline.label}`;
133
+ }
134
+ if (selection !== null && selection.kind === "uncommitted")
135
+ context =
136
+ selection.stage === "staged" ? "HEAD → Index" : "Index → Working tree";
137
+
138
+ const isMultiRepo =
139
+ catalog !== null &&
140
+ catalog.kind === "git" &&
141
+ catalog.repositories.length > 1;
142
+
143
+ return (
144
+ <div className={styles.header}>
145
+ {isMultiRepo && active !== null ? (
146
+ <Menu
147
+ open={repoOpen}
148
+ onClose={() => setRepoOpen(false)}
149
+ selectedId={active.cwd}
150
+ portal
151
+ compact
152
+ autoFocus
153
+ className={styles.scopePicker}
154
+ anchor={
155
+ <Button
156
+ size="sm"
157
+ variant="ghost"
158
+ className={styles.branchButton}
159
+ aria-label="Repository"
160
+ aria-haspopup="menu"
161
+ aria-expanded={repoOpen}
162
+ title={active.cwd}
163
+ onClick={() => setRepoOpen(!repoOpen)}
164
+ >
165
+ <span className={styles.truncate}>
166
+ {nameOf(active.cwd) === "" ? active.cwd : nameOf(active.cwd)}
167
+ </span>
168
+ <IconChevronDownOutlineRegular className={styles.icon} />
169
+ </Button>
170
+ }
171
+ items={catalog.repositories.map((repo) => ({
172
+ id: repo.cwd,
173
+ label: nameOf(repo.cwd) === "" ? repo.cwd : nameOf(repo.cwd),
174
+ }))}
175
+ onSelect={(id) => {
176
+ onSelectRepository(id);
177
+ setRepoOpen(false);
178
+ }}
179
+ />
180
+ ) : (
181
+ <Tooltip label={cwd} side="bottom" portal>
182
+ <span className={styles.repositoryName}>
183
+ {name === "" ? cwd : name}
184
+ </span>
185
+ </Tooltip>
186
+ )}
187
+ <Menu
188
+ open={scopeOpen}
189
+ onClose={() => setScopeOpen(false)}
190
+ selectedId={selectedId}
191
+ portal
192
+ compact
193
+ autoFocus
194
+ className={`${styles.scopePicker} ${styles.scopeSelector}`}
195
+ anchor={
196
+ <Button
197
+ size="sm"
198
+ variant="ghost"
199
+ className={styles.branchButton}
200
+ aria-label="Scope"
201
+ aria-haspopup="menu"
202
+ aria-expanded={scopeOpen}
203
+ title={scopeLabel}
204
+ onClick={() => setScopeOpen(!scopeOpen)}
205
+ >
206
+ <span className={styles.truncate}>{scopeLabel}</span>
207
+ <IconChevronDownOutlineRegular className={styles.icon} />
208
+ </Button>
209
+ }
210
+ items={[
211
+ { type: "label", id: "branches-label", text: "Branches" },
212
+ ...branches.map((branch) => ({
213
+ id: branch.ref,
214
+ label: (
215
+ <BranchLabel name={branch.label} modifiedAt={branch.modifiedAt} />
216
+ ),
217
+ })),
218
+ { type: "separator", id: "working-divider" },
219
+ { type: "label", id: "working-label", text: "Working tree" },
220
+ ...options
221
+ .filter((item) => item.value.kind === "uncommitted")
222
+ .map(({ id, label, disabled }) => ({ id, label, disabled })),
223
+ ]}
224
+ onSelect={(id) => {
225
+ const option = options.find((item) => item.id === id);
226
+ if (option === undefined) throw new Error("Scope must exist");
227
+ select(option.value);
228
+ setScopeOpen(false);
229
+ }}
230
+ />
231
+ {selection !== null && selection.kind === "branch" && (
232
+ <CommitPicker
233
+ key={`${selection.ref}:${base}`}
234
+ api={api}
235
+ sessionId={sessionId}
236
+ selection={{ ...selection, base }}
237
+ revision={revision}
238
+ selectRevision={(revision) => select({ ...selection, revision })}
239
+ />
240
+ )}
241
+ {selection !== null &&
242
+ selection.kind === "branch" &&
243
+ active !== null &&
244
+ (selection.base.kind === "manual" || base === "") && (
245
+ <Menu
246
+ open={baselineOpen}
247
+ onClose={() => setBaselineOpen(false)}
248
+ selectedId={base}
249
+ portal
250
+ compact
251
+ autoFocus
252
+ className={styles.scopePicker}
253
+ anchor={
254
+ <Button
255
+ size="sm"
256
+ variant="ghost"
257
+ className={styles.branchButton}
258
+ aria-label="Baseline"
259
+ aria-haspopup="menu"
260
+ aria-expanded={baselineOpen}
261
+ title={baselineLabel}
262
+ onClick={() => setBaselineOpen(!baselineOpen)}
263
+ >
264
+ <span className={styles.truncate}>{baselineLabel}</span>
265
+ <IconChevronDownOutlineRegular className={styles.icon} />
266
+ </Button>
267
+ }
268
+ items={active.baselines.map((item) => ({
269
+ id: item.ref,
270
+ label: item.label,
271
+ }))}
272
+ onSelect={(id) => {
273
+ select({
274
+ ...selection,
275
+ base: { kind: "manual", ref: id },
276
+ revision: { kind: "all-commits" },
277
+ });
278
+ setBaselineOpen(false);
279
+ }}
280
+ />
281
+ )}
282
+ <span className={styles.baseline} title={context}>
283
+ {context}
284
+ </span>
285
+ <Tooltip label="Refresh" side="bottom" align="end" portal>
286
+ <Button
287
+ size="sm"
288
+ variant="ghost"
289
+ aria-label="Refresh"
290
+ icon={<IconRefreshOutlineRegular className={styles.icon} />}
291
+ onClick={refresh}
292
+ />
293
+ </Tooltip>
294
+ </div>
295
+ );
296
+ }
297
+
298
+ function BranchLabel({
299
+ name,
300
+ modifiedAt,
301
+ }: {
302
+ name: string;
303
+ modifiedAt: number;
304
+ }) {
305
+ return (
306
+ <span className={styles.branchMenuLabel}>
307
+ <span className={styles.truncate}>{name}</span>
308
+ <time
309
+ className={styles.meta}
310
+ dateTime={new Date(modifiedAt).toISOString()}
311
+ title={`Latest commit: ${new Date(modifiedAt).toLocaleString()}`}
312
+ >
313
+ {formatRelativeTime(modifiedAt)}
314
+ </time>
315
+ </span>
316
+ );
317
+ }
318
+
319
+ function CommitPicker({
320
+ api,
321
+ sessionId,
322
+ selection,
323
+ revision,
324
+ selectRevision,
325
+ }: {
326
+ api: TypertRemoteNamespace<"workspaceReview">;
327
+ sessionId: string;
328
+ selection: Extract<ReviewSelection, { kind: "branch" }>;
329
+ revision: number;
330
+ selectRevision: (
331
+ revision: Extract<ReviewSelection, { kind: "branch" }>["revision"],
332
+ ) => void;
333
+ }) {
334
+ const [offset, setOffset] = useState(0);
335
+ const [open, setOpen] = useState(false);
336
+ const load = useCallback(
337
+ (signal: AbortSignal) => {
338
+ // smell: loader identity refreshes the page even when branch, baseline and offset are unchanged.
339
+ void revision;
340
+ return selection.base === ""
341
+ ? Promise.resolve({
342
+ ok: true as const,
343
+ value: { commits: [], hasMore: false },
344
+ })
345
+ : api.commits(
346
+ sessionId,
347
+ selection.repository,
348
+ selection.ref,
349
+ selection.base,
350
+ offset,
351
+ signal,
352
+ );
353
+ },
354
+ [
355
+ api,
356
+ sessionId,
357
+ selection.repository,
358
+ selection.ref,
359
+ selection.base,
360
+ offset,
361
+ revision,
362
+ ],
363
+ );
364
+ const result = useLoad(load);
365
+ const label =
366
+ selection.revision.kind === "all-commits"
367
+ ? "All commits"
368
+ : `${selection.revision.commit.sha.slice(0, 8)} ${selection.revision.commit.subject}`;
369
+ return (
370
+ <Menu
371
+ open={open}
372
+ onClose={() => setOpen(false)}
373
+ selectedId={
374
+ selection.revision.kind === "all-commits"
375
+ ? "all"
376
+ : selection.revision.commit.sha
377
+ }
378
+ portal
379
+ compact
380
+ autoFocus
381
+ className={styles.scopePicker}
382
+ anchor={
383
+ <Button
384
+ size="sm"
385
+ variant="ghost"
386
+ className={styles.branchButton}
387
+ aria-label="Commit"
388
+ aria-haspopup="menu"
389
+ aria-expanded={open}
390
+ title={label}
391
+ disabled={selection.base === ""}
392
+ onClick={() => setOpen(!open)}
393
+ >
394
+ <span className={styles.truncate}>{label}</span>
395
+ <IconChevronDownOutlineRegular className={styles.icon} />
396
+ </Button>
397
+ }
398
+ items={[
399
+ { id: "all", label: "All commits" },
400
+ ...(result.status === "ready"
401
+ ? result.value.commits.length === 0
402
+ ? [
403
+ {
404
+ type: "label" as const,
405
+ id: "empty",
406
+ text: "No commits on this branch",
407
+ },
408
+ ]
409
+ : result.value.commits.map((commit) => ({
410
+ id: commit.sha,
411
+ label: (
412
+ <span className={styles.commitLabel}>
413
+ <span className={styles.truncate}>{commit.subject}</span>
414
+ <span className={styles.meta}>
415
+ {commit.sha.slice(0, 8)} · {commit.author} ·{" "}
416
+ <time
417
+ dateTime={commit.date}
418
+ title={new Date(commit.date).toLocaleString()}
419
+ >
420
+ {formatRelativeTime(Date.parse(commit.date))}
421
+ </time>
422
+ </span>
423
+ </span>
424
+ ),
425
+ }))
426
+ : [
427
+ {
428
+ type: "label" as const,
429
+ id: "status",
430
+ text:
431
+ result.status === "loading"
432
+ ? "Loading commits…"
433
+ : result.message,
434
+ },
435
+ ]),
436
+ ]}
437
+ footer={
438
+ result.status === "ready" && result.value.commits.length > 0
439
+ ? [
440
+ {
441
+ id: "previous",
442
+ label: "Previous commits",
443
+ disabled: offset === 0,
444
+ },
445
+ {
446
+ id: "more",
447
+ label: "More commits",
448
+ disabled: !result.value.hasMore,
449
+ },
450
+ ]
451
+ : []
452
+ }
453
+ onSelect={(id) => {
454
+ if (id === "previous") setOffset(offset - COMMIT_PAGE_SIZE);
455
+ else if (id === "more") setOffset(offset + COMMIT_PAGE_SIZE);
456
+ else {
457
+ if (id === "all") selectRevision({ kind: "all-commits" });
458
+ else {
459
+ if (result.status !== "ready")
460
+ throw new Error("Commits must be loaded");
461
+ const commit = result.value.commits.find((item) => item.sha === id);
462
+ if (commit === undefined) throw new Error("Commit must exist");
463
+ selectRevision({ kind: "commit", commit });
464
+ }
465
+ setOpen(false);
466
+ }
467
+ }}
468
+ />
469
+ );
470
+ }
@@ -0,0 +1,27 @@
1
+ import type { ToolCallBlock } from "@deepseek-ai/dsh-client-ui-chat/client";
2
+ import type { TypertRemoteNamespace } from "@deepseek-ai/dsh-typert-protocol";
3
+ import type { BranchReviewScope } from "@lukstei/util-review-ui/types";
4
+ import type {} from "../../lib/typert.remote-client.js";
5
+
6
+ declare module "@deepseek-ai/dsh-client-ui-slots" {
7
+ interface SlotFactoryMap {
8
+ "gitdiff.review": {
9
+ scope: "session";
10
+ props: { scope?: BranchReviewScope };
11
+ inject: { api: TypertRemoteNamespace<"workspaceReview"> };
12
+ };
13
+ }
14
+ interface SlotMap {
15
+ "tool.call.toolview": {
16
+ kind: "keyed";
17
+ scope: "session";
18
+ owner: {
19
+ callId: string;
20
+ toolName: string;
21
+ phase?: "preparing" | "start" | "result";
22
+ block: ToolCallBlock;
23
+ inspect?: () => void;
24
+ };
25
+ };
26
+ }
27
+ }
@@ -0,0 +1,5 @@
1
+ declare module "*.module.css" {
2
+ const classes: Record<string, string>;
3
+ export const cssText: string;
4
+ export default classes;
5
+ }