@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,79 @@
|
|
|
1
|
+
/** The forge facts a Session row shows, from the Session list and the change request states every row shares. */
|
|
2
|
+
|
|
3
|
+
import { useMemo } from 'react'
|
|
4
|
+
import type { HostObservable, SnapshotSelectorHook } from '@deepseek-ai/dsh-client-ui-slots'
|
|
5
|
+
import type { UseSessions } from '@deepseek-ai/dsh-client-ui-session/client'
|
|
6
|
+
import type {} from '@deepseek-ai/dsh-experimental-forge-session/types'
|
|
7
|
+
import type { SessionId } from '@deepseek-ai/dsh-session/types'
|
|
8
|
+
import type { SessionProjectionSummaryValues } from '@deepseek-ai/dsh-session-projection/types'
|
|
9
|
+
import type { ForgeChangeRequestListState, ForgeSessionWorktree } from '../types.ts'
|
|
10
|
+
import type { StreamSnapshot } from './source.ts'
|
|
11
|
+
import { toneOf, type ChangeRequestTone } from './status.ts'
|
|
12
|
+
|
|
13
|
+
/** Change request states by URL as the Host streams them. */
|
|
14
|
+
export type ChangeRequestStates = StreamSnapshot<ReadonlyMap<string, ForgeChangeRequestListState>>
|
|
15
|
+
|
|
16
|
+
/** Business face of the Session row entries: the change request states every row shares. */
|
|
17
|
+
export interface SessionListInjected {
|
|
18
|
+
readonly hooks: {
|
|
19
|
+
/** States by URL; the renderer binds it as `useStates`. */
|
|
20
|
+
readonly states: HostObservable<ChangeRequestStates>
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** One visible change request of a Session with its last polled state, when known. */
|
|
25
|
+
export interface SessionListChangeRequest {
|
|
26
|
+
readonly url: string
|
|
27
|
+
readonly state: ForgeChangeRequestListState | undefined
|
|
28
|
+
readonly tone: ChangeRequestTone
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** What a Session row and its hover card show. */
|
|
32
|
+
export interface SessionForgeFacts {
|
|
33
|
+
/** The worktree the panel created for the Session, while the Session works in it. */
|
|
34
|
+
readonly worktree: ForgeSessionWorktree | null
|
|
35
|
+
/** Visible change requests, most urgent first; equally urgent ones keep their binding order. */
|
|
36
|
+
readonly changeRequests: readonly SessionListChangeRequest[]
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const URGENCY: Record<ChangeRequestTone, number> = { blocked: 0, open: 1, draft: 2, unknown: 3, merged: 4, closed: 5 }
|
|
40
|
+
|
|
41
|
+
const NO_FACTS: SessionForgeFacts = { worktree: null, changeRequests: [] }
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Derive a Session's facts from its listed projection values.
|
|
45
|
+
* @param values - the Session's projection values in the Session list, undefined before it is listed.
|
|
46
|
+
* @param states - change request states by URL.
|
|
47
|
+
* @returns the facts; a Session without a worktree or change requests shares one empty value.
|
|
48
|
+
*/
|
|
49
|
+
export function sessionForgeFacts(
|
|
50
|
+
values: Readonly<Partial<SessionProjectionSummaryValues>> | undefined,
|
|
51
|
+
states: ReadonlyMap<string, ForgeChangeRequestListState>,
|
|
52
|
+
): SessionForgeFacts {
|
|
53
|
+
const worktree = values?.forgeWorktree ?? null
|
|
54
|
+
const changeRequests = (values?.forgeChangeRequests ?? [])
|
|
55
|
+
.filter(binding => !binding.dismissed)
|
|
56
|
+
.map((binding): SessionListChangeRequest => {
|
|
57
|
+
const state = states.get(binding.url)
|
|
58
|
+
return { url: binding.url, state, tone: toneOf(state ?? null) }
|
|
59
|
+
})
|
|
60
|
+
.sort((left, right) => URGENCY[left.tone] - URGENCY[right.tone])
|
|
61
|
+
return worktree === null && changeRequests.length === 0 ? NO_FACTS : { worktree, changeRequests }
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Read one Session's facts, recomputed only when its listed values or the shared states change.
|
|
66
|
+
* @param useSessions - selector hook over the Session list.
|
|
67
|
+
* @param useStates - selector hook over the change request states.
|
|
68
|
+
* @param sessionId - the row's Session.
|
|
69
|
+
* @returns the facts.
|
|
70
|
+
*/
|
|
71
|
+
export function useSessionForgeFacts(
|
|
72
|
+
useSessions: UseSessions,
|
|
73
|
+
useStates: SnapshotSelectorHook<ChangeRequestStates>,
|
|
74
|
+
sessionId: SessionId,
|
|
75
|
+
): SessionForgeFacts {
|
|
76
|
+
const values = useSessions(state => state.byId[sessionId]?.projectionValues)
|
|
77
|
+
const states = useStates(snapshot => snapshot.state)
|
|
78
|
+
return useMemo(() => sessionForgeFacts(values, states), [values, states])
|
|
79
|
+
}
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host stream sources (per-Session panel states and the change request states
|
|
3
|
+
* of the Session list), the store behind action notices, and the tab visibility store.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { HostObservable } from '@deepseek-ai/dsh-client-ui-slots'
|
|
7
|
+
import type { ForgeChangeRequestListState, ForgeChangeRequestStatesFrame, ForgePanelState } from '../types.ts'
|
|
8
|
+
import type { ForgePanelKey } from './locales.ts'
|
|
9
|
+
|
|
10
|
+
/** What a stream source publishes: the value its frames built, and whether the stream ended while read. */
|
|
11
|
+
export interface StreamSnapshot<S> {
|
|
12
|
+
/** Value built from the frames so far. */
|
|
13
|
+
readonly state: S
|
|
14
|
+
/** Whether the stream ended while surfaces still read it. */
|
|
15
|
+
readonly disconnected: boolean
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** What the panel surfaces of one Session read; `state` is null before the first one arrives. */
|
|
19
|
+
export type PanelSnapshot = StreamSnapshot<ForgePanelState | null>
|
|
20
|
+
|
|
21
|
+
/** One open Host stream. */
|
|
22
|
+
export interface HostStream<F> extends AsyncIterable<F> {
|
|
23
|
+
/** Close the stream. */
|
|
24
|
+
dispose: () => void
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** One open stream of panel states. */
|
|
28
|
+
export type PanelStream = HostStream<ForgePanelState>
|
|
29
|
+
|
|
30
|
+
/** Stream opener and connection-reset subscription of a source. */
|
|
31
|
+
export interface StreamSourceDeps<F> {
|
|
32
|
+
/**
|
|
33
|
+
* Open the Host stream.
|
|
34
|
+
* @param signal - aborts the stream.
|
|
35
|
+
* @returns the stream.
|
|
36
|
+
*/
|
|
37
|
+
readonly open: (signal: AbortSignal) => HostStream<F>
|
|
38
|
+
/**
|
|
39
|
+
* Subscribe to transport resets, after which an open stream no longer delivers.
|
|
40
|
+
* @param listener - called on each reset.
|
|
41
|
+
* @returns the unsubscribe function.
|
|
42
|
+
*/
|
|
43
|
+
readonly subscribeReset: (listener: () => void) => () => void
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Stream opener and connection-reset subscription of one Session's panel source. */
|
|
47
|
+
export type PanelSourceDeps = StreamSourceDeps<ForgePanelState>
|
|
48
|
+
|
|
49
|
+
/** A value built from a Host stream that runs only while a surface subscribes. */
|
|
50
|
+
export interface StreamSource<S> {
|
|
51
|
+
/** Snapshot observable; the renderer binds it as a selector hook. */
|
|
52
|
+
readonly observable: HostObservable<StreamSnapshot<S>>
|
|
53
|
+
/** Open the stream again after it ended; a no-op while it runs or nobody subscribes. */
|
|
54
|
+
readonly reconnect: () => void
|
|
55
|
+
/** Close the stream and the reset subscription and drop every subscriber. */
|
|
56
|
+
readonly close: () => void
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Panel state of one Session, streamed only while a surface subscribes. */
|
|
60
|
+
export interface PanelSource {
|
|
61
|
+
/** Snapshot observable; the renderer binds it as `usePanel`. */
|
|
62
|
+
readonly hooks: { readonly panel: HostObservable<PanelSnapshot> }
|
|
63
|
+
/** Open the stream again after it ended; a no-op while it runs or nobody subscribes. */
|
|
64
|
+
readonly reconnect: () => void
|
|
65
|
+
/** Close the stream and the reset subscription and drop every subscriber. */
|
|
66
|
+
readonly close: () => void
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Create a source that folds a Host stream into one value. The first
|
|
71
|
+
* subscriber opens the stream and the last one closes it; the value stays
|
|
72
|
+
* readable for the next subscriber. A stream that ends or fails while
|
|
73
|
+
* subscribed marks the snapshot disconnected until `reconnect` or a transport
|
|
74
|
+
* reset reopens it.
|
|
75
|
+
* @param deps - stream opener and reset subscription.
|
|
76
|
+
* @param initial - value before the first frame.
|
|
77
|
+
* @param fold - the value after one frame.
|
|
78
|
+
* @returns the source.
|
|
79
|
+
*/
|
|
80
|
+
export function createStreamSource<F, S>(deps: StreamSourceDeps<F>, initial: S, fold: (state: S, frame: F) => S): StreamSource<S> {
|
|
81
|
+
let snapshot: StreamSnapshot<S> = { state: initial, disconnected: false }
|
|
82
|
+
const listeners = new Set<() => void>()
|
|
83
|
+
let running: { readonly controller: AbortController; readonly stream: HostStream<F> } | undefined
|
|
84
|
+
let stopReset: (() => void) | undefined
|
|
85
|
+
const publish = (next: StreamSnapshot<S>): void => {
|
|
86
|
+
snapshot = next
|
|
87
|
+
for (const listener of [...listeners]) listener()
|
|
88
|
+
}
|
|
89
|
+
const stop = (): void => {
|
|
90
|
+
const stopped = running
|
|
91
|
+
running = undefined
|
|
92
|
+
stopped?.controller.abort()
|
|
93
|
+
stopped?.stream.dispose()
|
|
94
|
+
}
|
|
95
|
+
const start = (): void => {
|
|
96
|
+
const controller = new AbortController()
|
|
97
|
+
const opened = { controller, stream: deps.open(controller.signal) }
|
|
98
|
+
running = opened
|
|
99
|
+
if (snapshot.disconnected) publish({ ...snapshot, disconnected: false })
|
|
100
|
+
void (async () => {
|
|
101
|
+
try {
|
|
102
|
+
for await (const frame of opened.stream) {
|
|
103
|
+
if (running !== opened) return
|
|
104
|
+
publish({ state: fold(snapshot.state, frame), disconnected: false })
|
|
105
|
+
}
|
|
106
|
+
} catch (error) {
|
|
107
|
+
void error // A failed stream is reported as the disconnection below.
|
|
108
|
+
}
|
|
109
|
+
if (running !== opened) return
|
|
110
|
+
running = undefined
|
|
111
|
+
publish({ ...snapshot, disconnected: true })
|
|
112
|
+
})()
|
|
113
|
+
}
|
|
114
|
+
const reconnect = (): void => {
|
|
115
|
+
if (listeners.size === 0 || running !== undefined) return
|
|
116
|
+
start()
|
|
117
|
+
}
|
|
118
|
+
const close = (): void => {
|
|
119
|
+
listeners.clear()
|
|
120
|
+
stopReset?.()
|
|
121
|
+
stopReset = undefined
|
|
122
|
+
stop()
|
|
123
|
+
}
|
|
124
|
+
return {
|
|
125
|
+
observable: {
|
|
126
|
+
getSnapshot: () => snapshot,
|
|
127
|
+
subscribe(listener) {
|
|
128
|
+
listeners.add(listener)
|
|
129
|
+
if (listeners.size === 1) {
|
|
130
|
+
stopReset = deps.subscribeReset(() => {
|
|
131
|
+
stop()
|
|
132
|
+
reconnect()
|
|
133
|
+
})
|
|
134
|
+
start()
|
|
135
|
+
}
|
|
136
|
+
return () => {
|
|
137
|
+
listeners.delete(listener)
|
|
138
|
+
if (listeners.size === 0) close()
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
reconnect,
|
|
143
|
+
close,
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Create the panel source of one Session: the latest state the Host streamed.
|
|
149
|
+
* @param deps - stream opener and reset subscription.
|
|
150
|
+
* @returns the source.
|
|
151
|
+
*/
|
|
152
|
+
export function createPanelSource(deps: PanelSourceDeps): PanelSource {
|
|
153
|
+
const source = createStreamSource<ForgePanelState, ForgePanelState | null>(deps, null, (_previous, state) => state)
|
|
154
|
+
return { hooks: { panel: source.observable }, reconnect: source.reconnect, close: source.close }
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* The known change request states after one `changeRequestStates` frame: a
|
|
159
|
+
* baseline replaces them, and a change replaces the states it carries.
|
|
160
|
+
* @param states - states by URL before the frame.
|
|
161
|
+
* @param frame - the frame.
|
|
162
|
+
* @returns states by URL after the frame.
|
|
163
|
+
*/
|
|
164
|
+
export function foldStates(
|
|
165
|
+
states: ReadonlyMap<string, ForgeChangeRequestListState>,
|
|
166
|
+
frame: ForgeChangeRequestStatesFrame,
|
|
167
|
+
): ReadonlyMap<string, ForgeChangeRequestListState> {
|
|
168
|
+
const next = frame.type === 'baseline' ? new Map<string, ForgeChangeRequestListState>() : new Map(states)
|
|
169
|
+
for (const state of frame.states) next.set(state.url, state)
|
|
170
|
+
return next
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** One action notice; `seq` keys the toast so a repeated notice restarts it. */
|
|
174
|
+
export interface ActionNotice {
|
|
175
|
+
/** Dictionary key of the notice text. */
|
|
176
|
+
readonly key: ForgePanelKey
|
|
177
|
+
/** Values interpolated into the text. */
|
|
178
|
+
readonly params: Readonly<Record<string, string | number>>
|
|
179
|
+
/** `success` reports a completed action; `failure` a refused or failed one. */
|
|
180
|
+
readonly tone: 'success' | 'failure'
|
|
181
|
+
/** Reverts the reported action, or undefined when it cannot be undone. */
|
|
182
|
+
readonly undo: (() => void) | undefined
|
|
183
|
+
/** Increasing report number. */
|
|
184
|
+
readonly seq: number
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/** Optional parts of a reported notice. */
|
|
188
|
+
export interface NoticeOptions {
|
|
189
|
+
/** Values interpolated into the text. */
|
|
190
|
+
readonly params?: Readonly<Record<string, string | number>>
|
|
191
|
+
/** Defaults to `failure`. */
|
|
192
|
+
readonly tone?: ActionNotice['tone']
|
|
193
|
+
/** Reverts the reported action. */
|
|
194
|
+
readonly undo?: () => void
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** Store that action wiring reports into and one `shell.overlay` entry reads. */
|
|
198
|
+
export interface NoticeSource {
|
|
199
|
+
/** Current notice, or null while none shows; the renderer binds it as `useNotice`. */
|
|
200
|
+
readonly hooks: { readonly notice: HostObservable<ActionNotice | null> }
|
|
201
|
+
/**
|
|
202
|
+
* Show one notice, replacing the shown one.
|
|
203
|
+
* @param key - dictionary key of the text.
|
|
204
|
+
* @param options - interpolated values, tone, and undo action.
|
|
205
|
+
*/
|
|
206
|
+
readonly report: (key: ForgePanelKey, options?: NoticeOptions) => void
|
|
207
|
+
/** Clear the shown notice. */
|
|
208
|
+
readonly dismiss: () => void
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Create the action notice store.
|
|
213
|
+
* @returns the store.
|
|
214
|
+
*/
|
|
215
|
+
export function createNoticeSource(): NoticeSource {
|
|
216
|
+
let notice: ActionNotice | null = null
|
|
217
|
+
let seq = 0
|
|
218
|
+
const listeners = new Set<() => void>()
|
|
219
|
+
const publish = (next: ActionNotice | null): void => {
|
|
220
|
+
notice = next
|
|
221
|
+
for (const listener of [...listeners]) listener()
|
|
222
|
+
}
|
|
223
|
+
return {
|
|
224
|
+
hooks: {
|
|
225
|
+
notice: {
|
|
226
|
+
getSnapshot: () => notice,
|
|
227
|
+
subscribe(listener) {
|
|
228
|
+
listeners.add(listener)
|
|
229
|
+
return () => { listeners.delete(listener) }
|
|
230
|
+
},
|
|
231
|
+
},
|
|
232
|
+
},
|
|
233
|
+
report: (key, options = {}) => {
|
|
234
|
+
publish({ key, params: options.params ?? {}, tone: options.tone ?? 'failure', undo: options.undo, seq: ++seq })
|
|
235
|
+
},
|
|
236
|
+
dismiss: () => { publish(null) },
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/** Whether one Session's forge tab is visible; the header entry reads it for its pressed state. */
|
|
241
|
+
export interface VisibilitySource {
|
|
242
|
+
/** Current visibility; the renderer binds it as `useVisible`. */
|
|
243
|
+
readonly hooks: { readonly visible: HostObservable<boolean> }
|
|
244
|
+
/**
|
|
245
|
+
* Record the tab's visibility.
|
|
246
|
+
* @param visible - whether the tab is visible.
|
|
247
|
+
*/
|
|
248
|
+
readonly set: (visible: boolean) => void
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Create the visibility store of one Session's forge tab, initially hidden.
|
|
253
|
+
* @returns the store.
|
|
254
|
+
*/
|
|
255
|
+
export function createVisibilitySource(): VisibilitySource {
|
|
256
|
+
let visible = false
|
|
257
|
+
const listeners = new Set<() => void>()
|
|
258
|
+
return {
|
|
259
|
+
hooks: {
|
|
260
|
+
visible: {
|
|
261
|
+
getSnapshot: () => visible,
|
|
262
|
+
subscribe(listener) {
|
|
263
|
+
listeners.add(listener)
|
|
264
|
+
return () => { listeners.delete(listener) }
|
|
265
|
+
},
|
|
266
|
+
},
|
|
267
|
+
},
|
|
268
|
+
set: (next) => {
|
|
269
|
+
if (next === visible) return
|
|
270
|
+
visible = next
|
|
271
|
+
for (const listener of [...listeners]) listener()
|
|
272
|
+
},
|
|
273
|
+
}
|
|
274
|
+
}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/** Status derivations shared by the header entry, the change request cards, and the changes view. */
|
|
2
|
+
|
|
3
|
+
import type { ChangeRequestCheck, ChangeRequestSnapshot, ChecksRollup } from '@deepseek-ai/dsh-experimental-forge/types'
|
|
4
|
+
import type { ForgePanelChangeRequest, ForgePanelState } from '../types.ts'
|
|
5
|
+
import type { ForgePanelKey } from './locales.ts'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Glyph tone of a change request: its lifecycle state, `blocked` for an open
|
|
9
|
+
* one, not a draft, that needs its author, or `unknown` before the first snapshot.
|
|
10
|
+
*/
|
|
11
|
+
export type ChangeRequestTone = 'open' | 'blocked' | 'draft' | 'merged' | 'closed' | 'unknown'
|
|
12
|
+
|
|
13
|
+
/** Dictionary key of each tone's state name. */
|
|
14
|
+
export const TONE_LABEL: Record<ChangeRequestTone, ForgePanelKey> = {
|
|
15
|
+
open: 'change.state.open',
|
|
16
|
+
blocked: 'change.state.blocked',
|
|
17
|
+
draft: 'change.state.draft',
|
|
18
|
+
merged: 'change.state.merged',
|
|
19
|
+
closed: 'change.state.closed',
|
|
20
|
+
unknown: 'change.state.unknown',
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Combined check outcome shown on a collapsed card. */
|
|
24
|
+
export type CiSummary =
|
|
25
|
+
| { readonly kind: 'none' }
|
|
26
|
+
| { readonly kind: 'running' }
|
|
27
|
+
| { readonly kind: 'passed' }
|
|
28
|
+
/** `count` is the number of failed checks the host listed, which can be zero when the list is truncated. */
|
|
29
|
+
| { readonly kind: 'failed'; readonly count: number }
|
|
30
|
+
| { readonly kind: 'cancelled'; readonly count: number }
|
|
31
|
+
|
|
32
|
+
/** Checks grouped by outcome; `other` holds neutral and skipped checks. */
|
|
33
|
+
export interface CheckCounts {
|
|
34
|
+
readonly failed: number
|
|
35
|
+
readonly running: number
|
|
36
|
+
readonly passed: number
|
|
37
|
+
readonly cancelled: number
|
|
38
|
+
readonly other: number
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const SETTLED: Record<Exclude<ChecksRollup, 'failure'>, Exclude<CiSummary['kind'], 'failed' | 'cancelled'>> = {
|
|
42
|
+
none: 'none',
|
|
43
|
+
pending: 'running',
|
|
44
|
+
success: 'passed',
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** The most urgent fact of an open change request that the collapsed card names. */
|
|
48
|
+
export type ChangeRequestFlag = 'changesRequested' | 'conflicting' | 'draft'
|
|
49
|
+
|
|
50
|
+
/** The facts of a change request that decide its tone. */
|
|
51
|
+
export type ToneFacts = Pick<ChangeRequestSnapshot, 'state' | 'draft' | 'checksRollup' | 'reviewDecision' | 'mergeability'>
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Pick the glyph tone of a change request: an open draft is always `draft`;
|
|
55
|
+
* any other open one is `blocked` while its checks failed, changes were
|
|
56
|
+
* requested, or it conflicts with its base, and running checks, a pending
|
|
57
|
+
* review, and an unknown mergeability only wait and keep it `open`.
|
|
58
|
+
* @param snapshot - latest snapshot or listed state, or null before the first one.
|
|
59
|
+
* @returns the tone.
|
|
60
|
+
*/
|
|
61
|
+
export function toneOf(snapshot: ToneFacts | null): ChangeRequestTone {
|
|
62
|
+
if (snapshot === null) return 'unknown'
|
|
63
|
+
if (snapshot.state !== 'open') return snapshot.state
|
|
64
|
+
if (snapshot.draft) return 'draft'
|
|
65
|
+
if (snapshot.checksRollup === 'failure' || snapshot.reviewDecision === 'changes-requested' || snapshot.mergeability === 'conflicting') {
|
|
66
|
+
return 'blocked'
|
|
67
|
+
}
|
|
68
|
+
return 'open'
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Count the listed checks by outcome.
|
|
73
|
+
* @param checks - checks of the head commit.
|
|
74
|
+
* @returns the counts.
|
|
75
|
+
*/
|
|
76
|
+
export function checkCounts(checks: readonly ChangeRequestCheck[]): CheckCounts {
|
|
77
|
+
let failed = 0
|
|
78
|
+
let running = 0
|
|
79
|
+
let passed = 0
|
|
80
|
+
let cancelled = 0
|
|
81
|
+
for (const check of checks) {
|
|
82
|
+
if (check.state === 'failure') failed++
|
|
83
|
+
else if (check.state === 'pending') running++
|
|
84
|
+
else if (check.state === 'success') passed++
|
|
85
|
+
else if (check.state === 'cancelled') cancelled++
|
|
86
|
+
}
|
|
87
|
+
return { failed, running, passed, cancelled, other: checks.length - failed - running - passed - cancelled }
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Summarize the checks of a change request from the host's combined outcome.
|
|
92
|
+
* @param snapshot - change request status.
|
|
93
|
+
* @returns the combined outcome with its failure or cancellation count.
|
|
94
|
+
*/
|
|
95
|
+
export function ciSummary(snapshot: ChangeRequestSnapshot): CiSummary {
|
|
96
|
+
if (snapshot.checksRollup === 'failure') {
|
|
97
|
+
if (snapshot.checksTruncated) return { kind: 'failed', count: 0 }
|
|
98
|
+
const counts = checkCounts(snapshot.checks)
|
|
99
|
+
return counts.failed === 0 && counts.cancelled > 0
|
|
100
|
+
? { kind: 'cancelled', count: counts.cancelled }
|
|
101
|
+
: { kind: 'failed', count: counts.failed }
|
|
102
|
+
}
|
|
103
|
+
return { kind: SETTLED[snapshot.checksRollup] }
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Pick the flag a collapsed card names: requested changes before merge
|
|
108
|
+
* conflicts before draft state; only open change requests carry one.
|
|
109
|
+
* @param snapshot - change request status.
|
|
110
|
+
* @returns the flag, or undefined when none applies.
|
|
111
|
+
*/
|
|
112
|
+
export function flagOf(snapshot: ChangeRequestSnapshot): ChangeRequestFlag | undefined {
|
|
113
|
+
if (snapshot.state !== 'open') return undefined
|
|
114
|
+
if (snapshot.reviewDecision === 'changes-requested') return 'changesRequested'
|
|
115
|
+
if (snapshot.mergeability === 'conflicting') return 'conflicting'
|
|
116
|
+
return snapshot.draft ? 'draft' : undefined
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Whether a change request needs the user, the condition its card draws as `blocked`.
|
|
121
|
+
* @param entry - bound change request.
|
|
122
|
+
* @returns whether the header marks it.
|
|
123
|
+
*/
|
|
124
|
+
export function needsAttention(entry: ForgePanelChangeRequest): boolean {
|
|
125
|
+
return toneOf(entry.snapshot) === 'blocked'
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Pick the cards a Session's panel opens before the user expands or collapses
|
|
130
|
+
* one: the only open change request, drafts included, when exactly one is open.
|
|
131
|
+
* @param entries - bound change requests.
|
|
132
|
+
* @returns the URLs of the cards that start expanded.
|
|
133
|
+
*/
|
|
134
|
+
export function defaultExpanded(entries: readonly ForgePanelChangeRequest[]): ReadonlySet<string> {
|
|
135
|
+
const open = entries.filter(entry => entry.snapshot?.state === 'open')
|
|
136
|
+
return new Set(open.length === 1 ? open.map(entry => entry.url) : [])
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Find the open change request, drafts included, whose head is the checked-out branch.
|
|
141
|
+
* @param state - panel state of the Session.
|
|
142
|
+
* @returns the change request, or undefined without one or while HEAD is detached.
|
|
143
|
+
*/
|
|
144
|
+
export function openChangeRequestOf(state: ForgePanelState): ForgePanelChangeRequest | undefined {
|
|
145
|
+
const branch = state.checkout.state === 'ready' ? state.checkout.checkout.branch : null
|
|
146
|
+
if (branch === null) return undefined
|
|
147
|
+
return state.changeRequests.find(entry => entry.snapshot?.state === 'open' && entry.snapshot.headBranch === branch)
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Read the change request number: the provider's reference, else the number at the end of the URL path.
|
|
152
|
+
* @param entry - bound change request.
|
|
153
|
+
* @returns the number, or null when neither names one.
|
|
154
|
+
*/
|
|
155
|
+
export function numberOf(entry: Pick<ForgePanelChangeRequest, 'ref' | 'url'>): number | null {
|
|
156
|
+
if (entry.ref !== null) return entry.ref.number
|
|
157
|
+
const [, digits = ''] = /\/(\d+)\/?(?:[?#].*)?$/s.exec(entry.url) ?? []
|
|
158
|
+
const number = Number(digits)
|
|
159
|
+
return digits.length > 0 && Number.isSafeInteger(number) ? number : null
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Measure how long a completed check ran.
|
|
164
|
+
* @param check - one check.
|
|
165
|
+
* @returns elapsed milliseconds, or undefined when either time is unknown or they are out of order.
|
|
166
|
+
*/
|
|
167
|
+
export function checkDuration(check: ChangeRequestCheck): number | undefined {
|
|
168
|
+
if (check.startedAt === null || check.completedAt === null) return undefined
|
|
169
|
+
const elapsed = Date.parse(check.completedAt) - Date.parse(check.startedAt)
|
|
170
|
+
return Number.isFinite(elapsed) && elapsed >= 0 ? elapsed : undefined
|
|
171
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/** Reads the review threads of the change request a changes view shows and places them in its files. */
|
|
2
|
+
|
|
3
|
+
import { useEffect, useMemo, useRef, useState } from 'react'
|
|
4
|
+
import type { ForgeReviewData, ForgeReviewThread } from '@deepseek-ai/dsh-experimental-forge/types'
|
|
5
|
+
import type { RemoteResult } from '@deepseek-ai/dsh-typert-protocol'
|
|
6
|
+
import type { LineThread } from './ReviewThreads.tsx'
|
|
7
|
+
import { placeThread, type ThreadPlace, type ThreadView } from './review-threads.ts'
|
|
8
|
+
|
|
9
|
+
/** What the changes view knows about its change request when it reads threads. */
|
|
10
|
+
export interface ThreadReadInput {
|
|
11
|
+
/** Whether the view is visible; a hidden view reads nothing. */
|
|
12
|
+
readonly visible: boolean
|
|
13
|
+
/** Binding URL of the change request, or null for local changes. */
|
|
14
|
+
readonly url: string | null
|
|
15
|
+
/** Head commit of the latest status, or null before one. */
|
|
16
|
+
readonly head: string | null
|
|
17
|
+
/** Update time of the latest status, or null before one. */
|
|
18
|
+
readonly updatedAt: string | null
|
|
19
|
+
/** Epoch milliseconds of the latest status, so every status asks the Host again; the Host answers from memory until the threads age. */
|
|
20
|
+
readonly statusAt: number | null
|
|
21
|
+
/** Changes on each refresh. */
|
|
22
|
+
readonly attempt: number
|
|
23
|
+
/** Changes after each write that may have changed the threads, which the Host no longer answers from memory. */
|
|
24
|
+
readonly revision: number
|
|
25
|
+
/** Read the threads at a head commit; `fresh` skips the threads the host keeps. */
|
|
26
|
+
readonly read: (url: string, headSha: string, fresh: boolean, signal: AbortSignal) => Promise<RemoteResult<ForgeReviewData>>
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** The last threads read and why the latest read failed. */
|
|
30
|
+
export interface ThreadReadState {
|
|
31
|
+
/** Threads of the last successful read for the URL, at any head, or null. */
|
|
32
|
+
readonly review: ForgeReviewData | null
|
|
33
|
+
/** Message of the latest failed read, or null, also when the provider cannot read reviews. */
|
|
34
|
+
readonly failure: string | null
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Read the threads at the head of each status while the view is visible. A read refused because the head moved
|
|
39
|
+
* keeps the previous threads; the next status names the new head and reads again. The first read after a refresh
|
|
40
|
+
* asks the host to skip the threads it keeps, which a resolved thread leaves unchanged.
|
|
41
|
+
* @param input - the change request and the reader.
|
|
42
|
+
* @returns the last threads and the latest failure.
|
|
43
|
+
*/
|
|
44
|
+
export function useThreadRead(input: ThreadReadInput): ThreadReadState {
|
|
45
|
+
const { visible, url, head, updatedAt, statusAt, attempt, revision, read } = input
|
|
46
|
+
const [state, setState] = useState<ThreadReadState & { readonly url: string | null }>({ url: null, review: null, failure: null })
|
|
47
|
+
const readAttempt = useRef(attempt)
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
if (!visible || url === null || head === null) return
|
|
50
|
+
const fresh = readAttempt.current !== attempt
|
|
51
|
+
readAttempt.current = attempt
|
|
52
|
+
const controller = new AbortController()
|
|
53
|
+
void read(url, head, fresh, controller.signal).then((result) => {
|
|
54
|
+
if (controller.signal.aborted) return
|
|
55
|
+
if (result.ok) {
|
|
56
|
+
setState({ url, review: result.value, failure: null })
|
|
57
|
+
return
|
|
58
|
+
}
|
|
59
|
+
const { code, message } = result.error
|
|
60
|
+
if (code === 'forgePanel/stale-head') return
|
|
61
|
+
setState(previous => ({ url, review: previous.url === url ? previous.review : null,
|
|
62
|
+
failure: code === 'forgePanel/review-unsupported' ? null : message }))
|
|
63
|
+
})
|
|
64
|
+
return () => { controller.abort() }
|
|
65
|
+
}, [visible, url, head, updatedAt, statusAt, attempt, revision, read])
|
|
66
|
+
return state.url === url ? state : { review: null, failure: null }
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Threads of one file grouped by where they show, and how many of them are unresolved. */
|
|
70
|
+
export interface PlacedFileThreads {
|
|
71
|
+
readonly lines: readonly LineThread[]
|
|
72
|
+
readonly file: readonly ForgeReviewThread[]
|
|
73
|
+
readonly outdated: readonly ForgeReviewThread[]
|
|
74
|
+
readonly unresolved: number
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** One thread and where the shown changes place it. */
|
|
78
|
+
export interface PlacedThread {
|
|
79
|
+
readonly thread: ForgeReviewThread
|
|
80
|
+
readonly place: ThreadPlace
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Every thread with its place and the threads of each file. */
|
|
84
|
+
export interface PlacedThreads {
|
|
85
|
+
/** Every thread in host order with its place. */
|
|
86
|
+
readonly entries: readonly PlacedThread[]
|
|
87
|
+
/** Threads of each path. */
|
|
88
|
+
readonly files: ReadonlyMap<string, PlacedFileThreads>
|
|
89
|
+
/** Unresolved threads by path, for the file tree. */
|
|
90
|
+
readonly unresolved: ReadonlyMap<string, number>
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const NONE: PlacedThreads = { entries: [], files: new Map(), unresolved: new Map() }
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Place the threads of a review in the shown changes.
|
|
97
|
+
* @param review - threads read at the head of the latest status, or null.
|
|
98
|
+
* @param view - the shown changes, or null before they load.
|
|
99
|
+
* @returns places, per-file groups, and unresolved counts.
|
|
100
|
+
*/
|
|
101
|
+
export function usePlacedThreads(review: ForgeReviewData | null, view: ThreadView | null): PlacedThreads {
|
|
102
|
+
const commits = view?.commits ?? null
|
|
103
|
+
const end = view?.end ?? null
|
|
104
|
+
return useMemo(() => {
|
|
105
|
+
if (review === null || end === null) return NONE
|
|
106
|
+
const entries: PlacedThread[] = []
|
|
107
|
+
const files = new Map<string, { lines: LineThread[]; file: ForgeReviewThread[]; outdated: ForgeReviewThread[]; unresolved: number }>()
|
|
108
|
+
const unresolved = new Map<string, number>()
|
|
109
|
+
for (const thread of review.threads) {
|
|
110
|
+
const place = placeThread(thread, { head: review.headSha, end, commits })
|
|
111
|
+
entries.push({ thread, place })
|
|
112
|
+
let group = files.get(thread.path)
|
|
113
|
+
if (group === undefined) {
|
|
114
|
+
group = { lines: [], file: [], outdated: [], unresolved: 0 }
|
|
115
|
+
files.set(thread.path, group)
|
|
116
|
+
}
|
|
117
|
+
if (place.kind === 'line') group.lines.push({ thread, place })
|
|
118
|
+
else if (place.kind === 'file') group.file.push(thread)
|
|
119
|
+
else if (place.kind === 'outdated') group.outdated.push(thread)
|
|
120
|
+
if (!thread.resolved) {
|
|
121
|
+
group.unresolved += 1
|
|
122
|
+
unresolved.set(thread.path, group.unresolved)
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return { entries, files, unresolved }
|
|
126
|
+
}, [review, end, commits])
|
|
127
|
+
}
|