@deepseek-ai/dsh-experimental-client-ui-forge 0.2.2-alpha.3 → 0.2.2-rc.2
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/README.i18n.yaml +8 -8
- package/README.md +41 -14
- package/README.zh.md +40 -13
- package/lib/client.js +13 -11800
- package/lib/client.js.map +1 -0
- package/lib/index.js +1340 -115
- package/lib/typert.host.js +1715 -212
- package/lib/typert.remote-client.d.ts +42 -5
- package/lib/typert.remote-client.d.ts.map +1 -0
- package/lib/typert.remote-client.js +1523 -244
- package/lib/types/client/ActionToast.d.ts.map +1 -0
- package/lib/types/client/ActionToast.js.map +1 -0
- package/lib/types/client/BaseMenu.d.ts +30 -0
- package/lib/types/client/BaseMenu.d.ts.map +1 -0
- package/lib/types/client/BaseMenu.js.map +1 -0
- package/lib/types/client/ChangeRequestCard.d.ts +9 -5
- package/lib/types/client/ChangeRequestCard.d.ts.map +1 -0
- package/lib/types/client/ChangeRequestCard.js.map +1 -0
- package/lib/types/client/ChangeRequestOverview.d.ts +124 -0
- package/lib/types/client/ChangeRequestOverview.d.ts.map +1 -0
- package/lib/types/client/ChangeRequestOverview.js.map +1 -0
- package/lib/types/client/ChangedFiles.d.ts +2 -0
- package/lib/types/client/ChangedFiles.d.ts.map +1 -0
- package/lib/types/client/ChangedFiles.js.map +1 -0
- package/lib/types/client/ChangesTab.d.ts +30 -5
- package/lib/types/client/ChangesTab.d.ts.map +1 -0
- package/lib/types/client/ChangesTab.js.map +1 -0
- package/lib/types/client/ChangesTabTitle.d.ts.map +1 -0
- package/lib/types/client/ChangesTabTitle.js.map +1 -0
- package/lib/types/client/CommitMenu.d.ts +41 -0
- package/lib/types/client/CommitMenu.d.ts.map +1 -0
- package/lib/types/client/CommitMenu.js.map +1 -0
- package/lib/types/client/DiffFile.d.ts +47 -15
- package/lib/types/client/DiffFile.d.ts.map +1 -0
- package/lib/types/client/DiffFile.js.map +1 -0
- package/lib/types/client/FileLabel.d.ts.map +1 -0
- package/lib/types/client/FileLabel.js.map +1 -0
- package/lib/types/client/FileTreePane.d.ts +4 -2
- package/lib/types/client/FileTreePane.d.ts.map +1 -0
- package/lib/types/client/FileTreePane.js.map +1 -0
- package/lib/types/client/ForgeTab.d.ts +9 -1
- package/lib/types/client/ForgeTab.d.ts.map +1 -0
- package/lib/types/client/ForgeTab.js.map +1 -0
- package/lib/types/client/ForgeTabTitle.d.ts.map +1 -0
- package/lib/types/client/ForgeTabTitle.js.map +1 -0
- package/lib/types/client/HeaderButton.d.ts.map +1 -0
- package/lib/types/client/HeaderButton.js.map +1 -0
- package/lib/types/client/LocalChangesCard.d.ts.map +1 -0
- package/lib/types/client/LocalChangesCard.js.map +1 -0
- package/lib/types/client/RefreshGlyph.d.ts.map +1 -0
- package/lib/types/client/RefreshGlyph.js.map +1 -0
- package/lib/types/client/ReviewComposer.d.ts +20 -6
- package/lib/types/client/ReviewComposer.d.ts.map +1 -0
- package/lib/types/client/ReviewComposer.js.map +1 -0
- package/lib/types/client/ReviewControls.d.ts +79 -0
- package/lib/types/client/ReviewControls.d.ts.map +1 -0
- package/lib/types/client/ReviewControls.js.map +1 -0
- package/lib/types/client/ReviewThread.d.ts +4 -4
- package/lib/types/client/ReviewThread.d.ts.map +1 -0
- package/lib/types/client/ReviewThread.js.map +1 -0
- package/lib/types/client/ReviewThreads.d.ts +108 -0
- package/lib/types/client/ReviewThreads.d.ts.map +1 -0
- package/lib/types/client/ReviewThreads.js.map +1 -0
- package/lib/types/client/SessionHoverForge.d.ts.map +1 -0
- package/lib/types/client/SessionHoverForge.js.map +1 -0
- package/lib/types/client/SessionRowForge.d.ts +1 -1
- package/lib/types/client/SessionRowForge.d.ts.map +1 -0
- package/lib/types/client/SessionRowForge.js.map +1 -0
- package/lib/types/client/SubmitReview.d.ts +12 -4
- package/lib/types/client/SubmitReview.d.ts.map +1 -0
- package/lib/types/client/SubmitReview.js.map +1 -0
- package/lib/types/client/ThreadList.d.ts +43 -0
- package/lib/types/client/ThreadList.d.ts.map +1 -0
- package/lib/types/client/ThreadList.js.map +1 -0
- package/lib/types/client/ViewOptionsMenu.d.ts +31 -0
- package/lib/types/client/ViewOptionsMenu.d.ts.map +1 -0
- package/lib/types/client/ViewOptionsMenu.js.map +1 -0
- package/lib/types/client/WorktreeProgress.d.ts.map +1 -0
- package/lib/types/client/WorktreeProgress.js.map +1 -0
- package/lib/types/client/WorktreeSettings.d.ts +12 -0
- package/lib/types/client/WorktreeSettings.d.ts.map +1 -0
- package/lib/types/client/WorktreeSettings.js.map +1 -0
- package/lib/types/client/WorktreeToggle.d.ts.map +1 -0
- package/lib/types/client/WorktreeToggle.js.map +1 -0
- package/lib/types/client/changes-address.d.ts.map +1 -0
- package/lib/types/client/changes-address.js.map +1 -0
- package/lib/types/client/changes-store.d.ts +20 -5
- package/lib/types/client/changes-store.d.ts.map +1 -0
- package/lib/types/client/changes-store.js.map +1 -0
- package/lib/types/client/checkout.d.ts.map +1 -0
- package/lib/types/client/checkout.js.map +1 -0
- package/lib/types/client/code-selection.d.ts.map +1 -0
- package/lib/types/client/code-selection.js.map +1 -0
- package/lib/types/client/diff-rows.d.ts.map +1 -0
- package/lib/types/client/diff-rows.js.map +1 -0
- package/lib/types/client/file-tree.d.ts.map +1 -0
- package/lib/types/client/file-tree.js.map +1 -0
- package/lib/types/client/format.d.ts.map +1 -0
- package/lib/types/client/format.js.map +1 -0
- package/lib/types/client/glyphs.d.ts +4 -2
- package/lib/types/client/glyphs.d.ts.map +1 -0
- package/lib/types/client/glyphs.js.map +1 -0
- package/lib/types/client/host-viewed.d.ts +84 -0
- package/lib/types/client/host-viewed.d.ts.map +1 -0
- package/lib/types/client/host-viewed.js.map +1 -0
- package/lib/types/client/index.d.ts.map +1 -0
- package/lib/types/client/index.js.map +1 -0
- package/lib/types/client/locales.d.ts +175 -3
- package/lib/types/client/locales.d.ts.map +1 -0
- package/lib/types/client/locales.js.map +1 -0
- package/lib/types/client/menu-search.d.ts +10 -0
- package/lib/types/client/menu-search.d.ts.map +1 -0
- package/lib/types/client/menu-search.js.map +1 -0
- package/lib/types/client/mount.d.ts +4 -0
- package/lib/types/client/mount.d.ts.map +1 -0
- package/lib/types/client/mount.js.map +1 -0
- package/lib/types/client/review-queue.d.ts +5 -8
- package/lib/types/client/review-queue.d.ts.map +1 -0
- package/lib/types/client/review-queue.js.map +1 -0
- package/lib/types/client/review-threads.d.ts +108 -0
- package/lib/types/client/review-threads.d.ts.map +1 -0
- package/lib/types/client/review-threads.js.map +1 -0
- package/lib/types/client/review.d.ts +31 -4
- package/lib/types/client/review.d.ts.map +1 -0
- package/lib/types/client/review.js.map +1 -0
- package/lib/types/client/section-reach.d.ts +26 -0
- package/lib/types/client/section-reach.d.ts.map +1 -0
- package/lib/types/client/section-reach.js.map +1 -0
- package/lib/types/client/session-list.d.ts.map +1 -0
- package/lib/types/client/session-list.js.map +1 -0
- package/lib/types/client/source.d.ts.map +1 -0
- package/lib/types/client/source.js.map +1 -0
- package/lib/types/client/status.d.ts.map +1 -0
- package/lib/types/client/status.js.map +1 -0
- package/lib/types/client/thread-state.d.ts +68 -0
- package/lib/types/client/thread-state.d.ts.map +1 -0
- package/lib/types/client/thread-state.js.map +1 -0
- package/lib/types/client/toolbar-fold.d.ts +19 -0
- package/lib/types/client/toolbar-fold.d.ts.map +1 -0
- package/lib/types/client/toolbar-fold.js.map +1 -0
- package/lib/types/client/viewed-files.d.ts +70 -0
- package/lib/types/client/viewed-files.d.ts.map +1 -0
- package/lib/types/client/viewed-files.js.map +1 -0
- package/lib/types/client/worktree-settings-form.d.ts +32 -0
- package/lib/types/client/worktree-settings-form.d.ts.map +1 -0
- package/lib/types/client/worktree-settings-form.js.map +1 -0
- package/lib/types/commit-range.d.ts +17 -0
- package/lib/types/commit-range.d.ts.map +1 -0
- package/lib/types/commit-range.js.map +1 -0
- package/lib/types/diff.d.ts +10 -2
- package/lib/types/diff.d.ts.map +1 -0
- package/lib/types/diff.js.map +1 -0
- package/lib/types/git.d.ts.map +1 -0
- package/lib/types/git.js.map +1 -0
- package/lib/types/index.d.ts +194 -14
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/index.js.map +1 -0
- package/lib/types/layers.d.ts +66 -0
- package/lib/types/layers.d.ts.map +1 -0
- package/lib/types/layers.js.map +1 -0
- package/lib/types/local-diff.d.ts +54 -6
- package/lib/types/local-diff.d.ts.map +1 -0
- package/lib/types/local-diff.js.map +1 -0
- package/lib/types/panel.d.ts.map +1 -0
- package/lib/types/panel.js.map +1 -0
- package/lib/types/parse.d.ts +16 -0
- package/lib/types/parse.d.ts.map +1 -0
- package/lib/types/parse.js.map +1 -0
- package/lib/types/patch-cache.d.ts +12 -7
- package/lib/types/patch-cache.d.ts.map +1 -0
- package/lib/types/patch-cache.js.map +1 -0
- package/lib/types/review-cache.d.ts +54 -0
- package/lib/types/review-cache.d.ts.map +1 -0
- package/lib/types/review-cache.js.map +1 -0
- package/lib/types/states.d.ts.map +1 -0
- package/lib/types/states.js.map +1 -0
- package/lib/types/types.d.ts +113 -11
- package/lib/types/types.d.ts.map +1 -0
- package/lib/types/types.js.map +1 -0
- package/lib/types/wildmatch.d.ts +14 -0
- package/lib/types/wildmatch.d.ts.map +1 -0
- package/lib/types/wildmatch.js.map +1 -0
- package/lib/types/worktree.d.ts +8 -6
- package/lib/types/worktree.d.ts.map +1 -0
- package/lib/types/worktree.js.map +1 -0
- package/package.json +59 -49
- package/src/client/ActionToast.tsx +38 -0
- package/src/client/BaseMenu.module.css +153 -0
- package/src/client/BaseMenu.tsx +180 -0
- package/src/client/ChangeRequestCard.tsx +439 -0
- package/src/client/ChangeRequestOverview.module.css +196 -0
- package/src/client/ChangeRequestOverview.tsx +620 -0
- package/src/client/ChangedFiles.module.css +26 -0
- package/src/client/ChangedFiles.tsx +144 -0
- package/src/client/ChangesTab.module.css +984 -0
- package/src/client/ChangesTab.tsx +1288 -0
- package/src/client/ChangesTabTitle.tsx +28 -0
- package/src/client/CommitMenu.module.css +139 -0
- package/src/client/CommitMenu.tsx +186 -0
- package/src/client/DiffFile.tsx +621 -0
- package/src/client/FileLabel.module.css +53 -0
- package/src/client/FileLabel.tsx +66 -0
- package/src/client/FileTreePane.module.css +10 -0
- package/src/client/FileTreePane.tsx +79 -0
- package/src/client/ForgeTab.module.css +627 -0
- package/src/client/ForgeTab.tsx +263 -0
- package/src/client/ForgeTabTitle.tsx +21 -0
- package/src/client/HeaderButton.module.css +29 -0
- package/src/client/HeaderButton.tsx +68 -0
- package/src/client/LocalChangesCard.tsx +83 -0
- package/src/client/RefreshGlyph.module.css +22 -0
- package/src/client/RefreshGlyph.tsx +35 -0
- package/src/client/ReviewComposer.module.css +37 -0
- package/src/client/ReviewComposer.tsx +128 -0
- package/src/client/ReviewControls.module.css +162 -0
- package/src/client/ReviewControls.tsx +191 -0
- package/src/client/ReviewThread.tsx +96 -0
- package/src/client/ReviewThreads.module.css +326 -0
- package/src/client/ReviewThreads.tsx +443 -0
- package/src/client/SessionHoverForge.tsx +72 -0
- package/src/client/SessionList.module.css +85 -0
- package/src/client/SessionRowForge.tsx +86 -0
- package/src/client/SubmitReview.module.css +26 -0
- package/src/client/SubmitReview.tsx +95 -0
- package/src/client/ThreadList.module.css +218 -0
- package/src/client/ThreadList.tsx +165 -0
- package/src/client/ViewOptionsMenu.tsx +79 -0
- package/src/client/WorktreeProgress.module.css +226 -0
- package/src/client/WorktreeProgress.tsx +280 -0
- package/src/client/WorktreeSettings.module.css +29 -0
- package/src/client/WorktreeSettings.tsx +42 -0
- package/src/client/WorktreeToggle.module.css +132 -0
- package/src/client/WorktreeToggle.tsx +165 -0
- package/src/client/changes-address.ts +110 -0
- package/src/client/changes-store.ts +155 -0
- package/src/client/checkout.ts +75 -0
- package/src/client/code-selection.ts +53 -0
- package/src/client/diff-rows.ts +199 -0
- package/src/client/file-tree.ts +86 -0
- package/src/client/format.ts +37 -0
- package/src/client/glyphs.tsx +151 -0
- package/src/client/host-viewed.ts +195 -0
- package/src/client/index.ts +31 -0
- package/src/client/locales.ts +3446 -0
- package/src/client/menu-search.ts +16 -0
- package/src/client/mount.ts +439 -0
- package/src/client/review-queue.ts +256 -0
- package/src/client/review-threads.ts +204 -0
- package/src/client/review.ts +120 -0
- package/src/client/section-reach.ts +61 -0
- package/src/client/session-list.ts +79 -0
- package/src/client/source.ts +274 -0
- package/src/client/status.ts +171 -0
- package/src/client/thread-state.ts +127 -0
- package/src/client/toolbar-fold.ts +70 -0
- package/src/client/viewed-files.ts +178 -0
- package/src/client/worktree-settings-form.ts +43 -0
- package/src/commit-range.ts +27 -0
- package/src/css-modules.d.ts +5 -0
- package/src/diff.ts +162 -0
- package/src/git.ts +293 -0
- package/src/index.ts +1162 -0
- package/src/layers.ts +163 -0
- package/src/local-diff.ts +438 -0
- package/src/panel.ts +422 -0
- package/src/parse.ts +137 -0
- package/src/patch-cache.ts +73 -0
- package/src/review-cache.ts +98 -0
- package/src/states.ts +350 -0
- package/src/types.ts +504 -0
- package/src/wildmatch.ts +121 -0
- package/src/worktree.ts +576 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/** Width-driven folding of the changes toolbar into its More menu. */
|
|
2
|
+
|
|
3
|
+
/** Fold levels, from none to the deepest: level 1 folds the line totals, expansion, side by side, and wrapping; level 2
|
|
4
|
+
* the test switch, with the progress label shortened to the bare count beside its ring; level 3 refresh. */
|
|
5
|
+
export const DEEPEST_FOLD = 3
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Read the fold level a toolbar shows.
|
|
9
|
+
* @param inside - an element inside the toolbar, such as its More button.
|
|
10
|
+
* @returns the level, or the deepest level outside a measured toolbar.
|
|
11
|
+
*/
|
|
12
|
+
export function foldOf(inside: Element): number {
|
|
13
|
+
const level = Number.parseInt(inside.closest('[data-fold]')?.getAttribute('data-fold') ?? '', 10)
|
|
14
|
+
return Number.isInteger(level) ? level : DEEPEST_FOLD
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Width the row's displayed items need on one line: each item but the spacer at its own width, and one column gap
|
|
19
|
+
* between neighbours, the spacer included.
|
|
20
|
+
* @param row - the toolbar row.
|
|
21
|
+
* @param gap - its column gap in pixels.
|
|
22
|
+
* @returns the width in pixels.
|
|
23
|
+
*/
|
|
24
|
+
function demand(row: HTMLElement, gap: number): number {
|
|
25
|
+
let width = 0
|
|
26
|
+
let items = 0
|
|
27
|
+
for (const child of row.children) {
|
|
28
|
+
const spacer = child.hasAttribute('data-fold-spacer')
|
|
29
|
+
const own = spacer ? 0 : child.getBoundingClientRect().width
|
|
30
|
+
if (!spacer && own === 0) continue
|
|
31
|
+
width += own
|
|
32
|
+
items += 1
|
|
33
|
+
}
|
|
34
|
+
return width + Math.max(0, items - 1) * gap
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Keep a toolbar row on one line by setting `data-fold` to the shallowest level whose items fit, measuring each level's
|
|
39
|
+
* demand synchronously; the row's styles hide each level's items and show the More button. Content, size, and font
|
|
40
|
+
* changes measure again.
|
|
41
|
+
* @param row - the toolbar row; its children are the items, and the one with `data-fold-spacer` takes the slack.
|
|
42
|
+
* @returns Disconnect the observers and the font listener.
|
|
43
|
+
*/
|
|
44
|
+
export function observeToolbarFold(row: HTMLElement): () => void {
|
|
45
|
+
const resize = new ResizeObserver(() => { measure() })
|
|
46
|
+
const measure = (): void => {
|
|
47
|
+
// Items React adds after the first measure are observed too; observing an observed element again does nothing.
|
|
48
|
+
for (const child of row.children) resize.observe(child)
|
|
49
|
+
const style = getComputedStyle(row)
|
|
50
|
+
const available = row.getBoundingClientRect().width - parseFloat(style.paddingLeft) - parseFloat(style.paddingRight)
|
|
51
|
+
const gap = parseFloat(style.columnGap)
|
|
52
|
+
let level = 0
|
|
53
|
+
for (; level < DEEPEST_FOLD; level += 1) {
|
|
54
|
+
row.setAttribute('data-fold', String(level))
|
|
55
|
+
if (demand(row, gap) <= available) break
|
|
56
|
+
}
|
|
57
|
+
row.setAttribute('data-fold', String(level))
|
|
58
|
+
}
|
|
59
|
+
resize.observe(row)
|
|
60
|
+
const mutation = new MutationObserver(measure)
|
|
61
|
+
mutation.observe(row, { subtree: true, childList: true, characterData: true })
|
|
62
|
+
const fonts = document.fonts
|
|
63
|
+
fonts.addEventListener('loadingdone', measure)
|
|
64
|
+
measure()
|
|
65
|
+
return () => {
|
|
66
|
+
resize.disconnect()
|
|
67
|
+
mutation.disconnect()
|
|
68
|
+
fonts.removeEventListener('loadingdone', measure)
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser-persisted viewed marks of changed files. Each Session keeps one storage entry that maps a diff source,
|
|
3
|
+
* such as a change request or a local scope with its base ref and chosen commits, to the digest of each file's
|
|
4
|
+
* change when the reader marked it viewed. A mark whose digest differs from the file's current change reports the
|
|
5
|
+
* file as changed since it was viewed. Several browser tabs of one Session share the entry: each mark rewrites the
|
|
6
|
+
* entry as storage holds it, and marks saved by another tab reach this one through the `storage` event.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { z } from 'zod'
|
|
10
|
+
|
|
11
|
+
/** Prefix of every storage key; the index of Sessions with marks uses it with the `sessions` suffix. */
|
|
12
|
+
const PREFIX = 'dsh.forge-viewed.v1'
|
|
13
|
+
|
|
14
|
+
/** Sessions whose marks the browser keeps; marking a file in another Session drops the least recently marked one's. */
|
|
15
|
+
const MAX_SESSIONS = 50
|
|
16
|
+
|
|
17
|
+
/** Diff sources whose marks one Session keeps; marking a file in another source drops the least recently marked one's. */
|
|
18
|
+
const MAX_SOURCES = 20
|
|
19
|
+
|
|
20
|
+
const source = z.object({ at: z.number(), files: z.record(z.string(), z.string()) })
|
|
21
|
+
const saved = z.record(z.string(), source)
|
|
22
|
+
const index = z.array(z.string())
|
|
23
|
+
|
|
24
|
+
type Sources = Readonly<Record<string, z.infer<typeof source>>>
|
|
25
|
+
|
|
26
|
+
/** Viewed state of one file in the diff a reader sees. */
|
|
27
|
+
export type ViewedState = 'viewed' | 'changed' | 'unviewed'
|
|
28
|
+
|
|
29
|
+
/** Digests of the files marked viewed in one source, by path; stable until a mark in that source changes. */
|
|
30
|
+
export type ViewedMarks = ReadonlyMap<string, string>
|
|
31
|
+
|
|
32
|
+
const NO_MARKS: ViewedMarks = new Map()
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Classify a file by its mark.
|
|
36
|
+
* @param marks - the marks of the source the diff shows.
|
|
37
|
+
* @param path - the file's path.
|
|
38
|
+
* @param digest - the digest of the file's current change.
|
|
39
|
+
* @returns `viewed` for a mark of this change, `changed` for a mark of an earlier change, else `unviewed`.
|
|
40
|
+
*/
|
|
41
|
+
export function viewedStateOf(marks: ViewedMarks, path: string, digest: string): ViewedState {
|
|
42
|
+
const marked = marks.get(path)
|
|
43
|
+
return marked === undefined ? 'unviewed' : marked === digest ? 'viewed' : 'changed'
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* One Session's viewed marks. Unreadable storage shows no marks and refuses writes while it stays unreadable. While
|
|
48
|
+
* anything subscribes, marks another tab saves replace the ones shown.
|
|
49
|
+
*/
|
|
50
|
+
export class ViewedFiles {
|
|
51
|
+
private sources: Sources
|
|
52
|
+
private readonly listeners = new Set<() => void>()
|
|
53
|
+
private readonly snapshots = new Map<string, ViewedMarks>()
|
|
54
|
+
private readonly key: string
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* @param session - storage identity of the Session, such as its id.
|
|
58
|
+
* @param now - clock of the least-recently-marked bounds.
|
|
59
|
+
*/
|
|
60
|
+
constructor(private readonly session: string, private readonly now: () => number = Date.now) {
|
|
61
|
+
this.key = `${PREFIX}.${JSON.stringify(session)}`
|
|
62
|
+
this.sources = this.load() ?? {}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Read the marks of one source.
|
|
67
|
+
* @param key - identity of the diff source.
|
|
68
|
+
* @returns digests by path, the same object until a mark in the source changes.
|
|
69
|
+
*/
|
|
70
|
+
readonly marksOf = (key: string): ViewedMarks => {
|
|
71
|
+
let marks = this.snapshots.get(key)
|
|
72
|
+
if (marks === undefined) {
|
|
73
|
+
const files = this.sources[key]?.files
|
|
74
|
+
marks = files === undefined ? NO_MARKS : new Map(Object.entries(files))
|
|
75
|
+
this.snapshots.set(key, marks)
|
|
76
|
+
}
|
|
77
|
+
return marks
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Observe changed marks.
|
|
82
|
+
* @param listener - called after each saved mark.
|
|
83
|
+
* @returns unsubscribe.
|
|
84
|
+
*/
|
|
85
|
+
readonly subscribe = (listener: () => void): (() => void) => {
|
|
86
|
+
// Storage events that arrived while nothing listened are lost, so the first subscriber reads storage again.
|
|
87
|
+
if (this.listeners.size === 0) {
|
|
88
|
+
window.addEventListener('storage', this.stored)
|
|
89
|
+
this.reload()
|
|
90
|
+
}
|
|
91
|
+
this.listeners.add(listener)
|
|
92
|
+
return () => {
|
|
93
|
+
this.listeners.delete(listener)
|
|
94
|
+
if (this.listeners.size === 0) window.removeEventListener('storage', this.stored)
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Mark one file viewed at its current change or clear its mark, dropping the marks of paths the diff no longer has.
|
|
100
|
+
* @param key - identity of the diff source.
|
|
101
|
+
* @param files - every file of the diff with the digest of its change.
|
|
102
|
+
* @param path - the file to mark.
|
|
103
|
+
* @param viewed - whether the file is viewed.
|
|
104
|
+
* @returns whether the mark was saved; the marks are unchanged when storage is unreadable or refuses the write.
|
|
105
|
+
*/
|
|
106
|
+
mark(key: string, files: readonly { readonly path: string; readonly digest: string }[], path: string, viewed: boolean): boolean {
|
|
107
|
+
const file = files.find(item => item.path === path)
|
|
108
|
+
// Another tab of the Session may have saved marks since this one last read them; the write keeps theirs.
|
|
109
|
+
const current = this.load()
|
|
110
|
+
if (current === undefined || file === undefined) return false
|
|
111
|
+
const present = new Set(files.map(item => item.path))
|
|
112
|
+
const kept = Object.entries(current[key]?.files ?? {}).filter(([marked]) => marked !== path && present.has(marked))
|
|
113
|
+
const sources = {
|
|
114
|
+
...current,
|
|
115
|
+
[key]: { at: this.now(), files: Object.fromEntries(viewed ? [...kept, [path, file.digest]] : kept) },
|
|
116
|
+
}
|
|
117
|
+
const recent = Object.entries(sources).sort(([, left], [, right]) => right.at - left.at).slice(0, MAX_SOURCES)
|
|
118
|
+
const next = Object.fromEntries(recent)
|
|
119
|
+
try {
|
|
120
|
+
localStorage.setItem(this.key, JSON.stringify(next))
|
|
121
|
+
} catch (_error) {
|
|
122
|
+
return false
|
|
123
|
+
}
|
|
124
|
+
this.replace(next)
|
|
125
|
+
this.remember()
|
|
126
|
+
return true
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** The saved marks of this Session, or undefined when storage cannot be read or holds an entry it cannot parse. */
|
|
130
|
+
private load(): Sources | undefined {
|
|
131
|
+
try {
|
|
132
|
+
const raw = localStorage.getItem(this.key)
|
|
133
|
+
return raw === null ? {} : saved.parse(JSON.parse(raw))
|
|
134
|
+
} catch (_error) {
|
|
135
|
+
return undefined
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** Show the saved marks when they differ from the shown ones. */
|
|
140
|
+
private reload(): void {
|
|
141
|
+
const sources = this.load() ?? {}
|
|
142
|
+
if (JSON.stringify(sources) !== JSON.stringify(this.sources)) this.replace(sources)
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
private replace(sources: Sources): void {
|
|
146
|
+
this.sources = sources
|
|
147
|
+
this.snapshots.clear()
|
|
148
|
+
for (const listener of this.listeners) listener()
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** Another document changed this Session's entry, or with a null key cleared the whole storage. */
|
|
152
|
+
private readonly stored = (event: StorageEvent): void => {
|
|
153
|
+
if (event.key === this.key || event.key === null) this.reload()
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** Move this Session to the front of the index and drop the marks of Sessions beyond {@link MAX_SESSIONS}. */
|
|
157
|
+
private remember(): void {
|
|
158
|
+
const key = `${PREFIX}.sessions`
|
|
159
|
+
let listed: readonly string[] = []
|
|
160
|
+
try {
|
|
161
|
+
listed = index.parse(JSON.parse(localStorage.getItem(key) ?? '[]'))
|
|
162
|
+
} catch (_error) {
|
|
163
|
+
// An unreadable index is replaced by one that lists only this Session.
|
|
164
|
+
}
|
|
165
|
+
const sessions = [this.session, ...listed.filter(item => item !== this.session)]
|
|
166
|
+
try {
|
|
167
|
+
writeIndex(key, sessions)
|
|
168
|
+
} catch (_error) {
|
|
169
|
+
// The index only bounds storage; a Session left out keeps its marks until a later write lists it.
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** Keep the first {@link MAX_SESSIONS} Sessions in the index and remove the marks of the rest. */
|
|
175
|
+
function writeIndex(key: string, sessions: readonly string[]): void {
|
|
176
|
+
for (const dropped of sessions.slice(MAX_SESSIONS)) localStorage.removeItem(`${PREFIX}.${JSON.stringify(dropped)}`)
|
|
177
|
+
localStorage.setItem(key, JSON.stringify(sessions.slice(0, MAX_SESSIONS)))
|
|
178
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/** Staged worktree row settings using the shared Plugins form model. */
|
|
2
|
+
import { SettingsFormModel, type SettingsFieldState, type SettingsFormActions, type SettingsFormScope,
|
|
3
|
+
type SettingsFormShell } from '@deepseek-ai/dsh-client-ui-primitives'
|
|
4
|
+
import type { SnapshotStore } from '@deepseek-ai/dsh-client-store'
|
|
5
|
+
|
|
6
|
+
/** The volatile fields of the worktree service's Config. */
|
|
7
|
+
export interface WorktreeSettings {
|
|
8
|
+
retainOnArchive: boolean
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** Current drafts and the shared form status. */
|
|
12
|
+
export interface WorktreeFormState extends SettingsFormShell {
|
|
13
|
+
retainOnArchive: SettingsFieldState
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Registration-side form observable and edit callbacks. */
|
|
17
|
+
export interface WorktreeSettingsInjected extends SettingsFormActions {
|
|
18
|
+
hooks: { worktreeForm: SnapshotStore<WorktreeFormState> }
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Stages the retain switch until the reader saves it; the draft text is `true` or `false`. */
|
|
22
|
+
export class WorktreeSettingsForm {
|
|
23
|
+
private readonly form: SettingsFormModel<WorktreeSettings>
|
|
24
|
+
private readonly state: SnapshotStore<WorktreeFormState>
|
|
25
|
+
|
|
26
|
+
/** @param scope - Host-backed configuration form of the worktree row. */
|
|
27
|
+
constructor(scope: SettingsFormScope<WorktreeSettings>) {
|
|
28
|
+
this.form = new SettingsFormModel(scope, [{
|
|
29
|
+
field: 'retainOnArchive',
|
|
30
|
+
format: value => value === true ? 'true' : 'false',
|
|
31
|
+
parse: text => text === 'true' ? { kind: 'set', value: true } : text === 'false' ? { kind: 'set', value: false } : undefined,
|
|
32
|
+
}])
|
|
33
|
+
this.state = this.form.bind(() => ({ ...this.form.shell(), retainOnArchive: this.form.field('retainOnArchive') }))
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Build the registration face for the row page.
|
|
38
|
+
* @returns draft observable and shared edit/save actions.
|
|
39
|
+
*/
|
|
40
|
+
inject(): WorktreeSettingsInjected { return { hooks: { worktreeForm: this.state }, ...this.form.actions() } }
|
|
41
|
+
/** Release the accepted-value subscription. */
|
|
42
|
+
dispose(): void { this.form.dispose() }
|
|
43
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks of a chosen run of commits against a commit list, shared by the Host, which reads the run's changes, and the
|
|
3
|
+
* commit picker, which refuses a run before asking for them.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { ForgeCommit } from '@deepseek-ai/dsh-experimental-forge/types'
|
|
7
|
+
import type { ForgeCommitRange } from './types.ts'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Find the first commit of a chosen run in a commit list. Two ends describe the run only when each commit after the
|
|
11
|
+
* first has the commit listed before it as its first parent, so the changes from the first commit's first parent to the
|
|
12
|
+
* last commit are exactly the run's changes.
|
|
13
|
+
* @param commits - listed commits, oldest first.
|
|
14
|
+
* @param range - the chosen run.
|
|
15
|
+
* @returns the first chosen commit; `missing` when an end is not listed or `to` is listed before `from`; `not-linear`
|
|
16
|
+
* when a commit of the run does not have the commit listed before it as its first parent.
|
|
17
|
+
*/
|
|
18
|
+
export function rangeStart(commits: readonly ForgeCommit[], range: ForgeCommitRange): ForgeCommit | 'missing' | 'not-linear' {
|
|
19
|
+
const first = commits.findIndex(commit => commit.sha === range.from)
|
|
20
|
+
const last = commits.findIndex(commit => commit.sha === range.to)
|
|
21
|
+
const start = commits[first]
|
|
22
|
+
if (start === undefined || last < first) return 'missing'
|
|
23
|
+
for (let index = first + 1; index <= last; index++) {
|
|
24
|
+
if (commits[index]?.parent !== commits[index - 1]?.sha) return 'not-linear'
|
|
25
|
+
}
|
|
26
|
+
return start
|
|
27
|
+
}
|
package/src/diff.ts
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/** Unified patch parsing into the panel's browser-safe diff model, and the diff and size of an untracked file. */
|
|
2
|
+
|
|
3
|
+
import { createHash } from 'node:crypto'
|
|
4
|
+
import { parsePatch } from 'diff'
|
|
5
|
+
import type { ForgeChangedFile, ForgeDiffFile, ForgeDiffHunk, ForgeDiffStatus } from './types.ts'
|
|
6
|
+
|
|
7
|
+
/** A changed file before its path is classified into a review layer. */
|
|
8
|
+
export type ParsedDiffFile = Omit<ForgeDiffFile, 'layer'>
|
|
9
|
+
|
|
10
|
+
/** Git's name for the missing side of an added or deleted file. */
|
|
11
|
+
const NULL_PATH = '/dev/null'
|
|
12
|
+
|
|
13
|
+
/** Bytes Git inspects for a NUL byte before it calls content binary. */
|
|
14
|
+
const BINARY_PROBE_BYTES = 8000
|
|
15
|
+
|
|
16
|
+
/** Blob names of both sides on a Git `index` header line, which identify a binary change that carries no hunks. */
|
|
17
|
+
const INDEX_LINE = /^index ([0-9a-f]+\.\.[0-9a-f]+)/m
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Parse a Git-style unified patch, as `git diff` or a code host prints it,
|
|
21
|
+
* with `a/` and `b/` path prefixes. Hunk ranges follow jsdiff: a range that
|
|
22
|
+
* covers no line starts at the line it comes before.
|
|
23
|
+
* @param patch - the patch text.
|
|
24
|
+
* @returns one file per patch section in patch order.
|
|
25
|
+
*/
|
|
26
|
+
export function parseDiff(patch: string): ParsedDiffFile[] {
|
|
27
|
+
const parsed = parsePatch(patch)
|
|
28
|
+
// Hunk lines start with a space, `+`, `-`, or `\`, so only a Git section header starts a line with `diff --git `.
|
|
29
|
+
const headers = patch.split(/^(?=diff --git )/m).filter(section => section.startsWith('diff --git '))
|
|
30
|
+
return parsed.flatMap((section, index) => {
|
|
31
|
+
const before = pathOf(section.oldFileName, 'a/')
|
|
32
|
+
const after = pathOf(section.newFileName, 'b/')
|
|
33
|
+
const path = after ?? before
|
|
34
|
+
if (path === null) return []
|
|
35
|
+
const status: ForgeDiffStatus = section.isCreate === true || before === null ? 'added'
|
|
36
|
+
: section.isDelete === true || after === null ? 'deleted'
|
|
37
|
+
: section.isRename === true ? 'renamed' : 'modified'
|
|
38
|
+
let additions = 0
|
|
39
|
+
let deletions = 0
|
|
40
|
+
for (const hunk of section.hunks) {
|
|
41
|
+
for (const line of hunk.lines) {
|
|
42
|
+
if (line.startsWith('+')) additions++
|
|
43
|
+
else if (line.startsWith('-')) deletions++
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const binary = section.isBinary === true
|
|
47
|
+
const previousPath = status === 'renamed' ? before : null
|
|
48
|
+
const hunks = section.hunks.map(({ oldStart, oldLines, newStart, newLines, lines }) => (
|
|
49
|
+
{ oldStart, oldLines, newStart, newLines, lines }))
|
|
50
|
+
// Each header matches its parsed section only when every section starts with a Git header.
|
|
51
|
+
const header = binary && headers.length === parsed.length ? String(headers[index]) : ''
|
|
52
|
+
const blobs = INDEX_LINE.exec(header)?.[1] ?? ''
|
|
53
|
+
// A mode change, such as `chmod +x`, shows only in the `old mode` and `new mode` header lines.
|
|
54
|
+
const modes = `${section.oldMode ?? ''}..${section.newMode ?? ''}`
|
|
55
|
+
return [{
|
|
56
|
+
path, previousPath, status, binary, oversized: false, untracked: false, additions, deletions, hunks,
|
|
57
|
+
digest: changeDigest(path, previousPath, status, hunks, blobs, modes),
|
|
58
|
+
}]
|
|
59
|
+
})
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Digest of one change: its paths, status, hunks, file modes, and the identity of content that hunks do not show. */
|
|
63
|
+
function changeDigest(
|
|
64
|
+
path: string, previousPath: string | null, status: ForgeDiffStatus, hunks: readonly ForgeDiffHunk[], content: string, modes: string,
|
|
65
|
+
): string {
|
|
66
|
+
return createHash('sha256').update(JSON.stringify([path, previousPath, status, hunks, content, modes])).digest('hex').slice(0, 32)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Describe an untracked file as added in full.
|
|
71
|
+
* @param path - path relative to the repository root.
|
|
72
|
+
* @param content - the file's bytes.
|
|
73
|
+
* @returns the file with one hunk of added lines, none when it is empty, or none and `binary` when its content is not text.
|
|
74
|
+
*/
|
|
75
|
+
export function untrackedFile(path: string, content: Uint8Array): ParsedDiffFile {
|
|
76
|
+
const text = decodeText(content)
|
|
77
|
+
if (text === undefined) return addedFile(path, [], { binary: true, oversized: false, content: createHash('sha256').update(content).digest('hex') })
|
|
78
|
+
if (text.length === 0) return addedFile(path, [], { binary: false, oversized: false, content: '' })
|
|
79
|
+
const lines = text.split('\n')
|
|
80
|
+
const ended = lines.at(-1) === ''
|
|
81
|
+
if (ended) lines.pop()
|
|
82
|
+
return addedFile(path, [{
|
|
83
|
+
oldStart: 1,
|
|
84
|
+
oldLines: 0,
|
|
85
|
+
newStart: 1,
|
|
86
|
+
newLines: lines.length,
|
|
87
|
+
lines: [...lines.map(line => `+${line}`), ...ended ? [] : ['\']],
|
|
88
|
+
}], { binary: false, oversized: false, content: '' })
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Describe an untracked file over `maxDiffBytes`, which carries no hunks and whose content is not read.
|
|
93
|
+
* @param path - path relative to the repository root.
|
|
94
|
+
* @returns the oversized added file.
|
|
95
|
+
*/
|
|
96
|
+
export function oversizedUntrackedFile(path: string): ParsedDiffFile {
|
|
97
|
+
return addedFile(path, [], { binary: false, oversized: true, content: 'oversized' })
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** An untracked file as added, whose digest also covers `content`, the identity of content its hunks do not show. */
|
|
101
|
+
function addedFile(path: string, hunks: readonly ForgeDiffHunk[], { binary, oversized, content }: {
|
|
102
|
+
readonly binary: boolean
|
|
103
|
+
readonly oversized: boolean
|
|
104
|
+
readonly content: string
|
|
105
|
+
}): ParsedDiffFile {
|
|
106
|
+
return {
|
|
107
|
+
path, previousPath: null, status: 'added', binary, oversized, untracked: true,
|
|
108
|
+
additions: hunks[0]?.newLines ?? 0, deletions: 0, hunks, digest: changeDigest(path, null, 'added', hunks, content, ''),
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Decode file content as text the way Git decides it is not binary: no NUL
|
|
114
|
+
* byte among the first 8000 bytes, and, here, valid UTF-8 throughout.
|
|
115
|
+
* @param content - the bytes.
|
|
116
|
+
* @returns the text, or undefined for binary content.
|
|
117
|
+
*/
|
|
118
|
+
export function decodeText(content: Uint8Array): string | undefined {
|
|
119
|
+
if (content.subarray(0, BINARY_PROBE_BYTES).includes(0)) return undefined
|
|
120
|
+
try {
|
|
121
|
+
return new TextDecoder('utf-8', { fatal: true }).decode(content)
|
|
122
|
+
} catch (error) {
|
|
123
|
+
void error // Bytes that are not UTF-8 render as binary, as a NUL byte does.
|
|
124
|
+
return undefined
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Parse `git diff --numstat -z` output, in which a rename prints its counts,
|
|
130
|
+
* an empty path, and then the old and new paths as separate fields.
|
|
131
|
+
* @param output - the command's standard output.
|
|
132
|
+
* @returns one file per record, named by its new path; a binary file counts no lines.
|
|
133
|
+
*/
|
|
134
|
+
export function parseNumstat(output: string): ForgeChangedFile[] {
|
|
135
|
+
const fields = output.split('\0')
|
|
136
|
+
const files: ForgeChangedFile[] = []
|
|
137
|
+
let skip = 0
|
|
138
|
+
for (const [index, record] of fields.entries()) {
|
|
139
|
+
if (skip > 0) {
|
|
140
|
+
skip--
|
|
141
|
+
continue
|
|
142
|
+
}
|
|
143
|
+
if (record.length === 0) continue
|
|
144
|
+
const [added = '', deleted = ''] = record.split('\t', 2)
|
|
145
|
+
let path = record.slice(added.length + deleted.length + 2)
|
|
146
|
+
if (path.length === 0) {
|
|
147
|
+
const renamed = fields[index + 2]
|
|
148
|
+
// A rename record that the output limit cut off ends the list.
|
|
149
|
+
if (renamed === undefined) break
|
|
150
|
+
path = renamed
|
|
151
|
+
skip = 2
|
|
152
|
+
}
|
|
153
|
+
const binary = added === '-'
|
|
154
|
+
files.push({ path, additions: binary ? 0 : Number(added), deletions: binary ? 0 : Number(deleted), binary })
|
|
155
|
+
}
|
|
156
|
+
return files
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function pathOf(name: string | undefined, prefix: string): string | null {
|
|
160
|
+
if (name === undefined || name === NULL_PATH) return null
|
|
161
|
+
return name.startsWith(prefix) ? name.slice(prefix.length) : name
|
|
162
|
+
}
|