@lukstei/dsh-client-review-git 0.0.0-stage → 0.2.2-rc.5.10
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/LICENSE +21 -0
- package/README.md +144 -2
- package/cordis.patch.yml +4 -0
- package/dist/client.js +3378 -0
- package/dist/host.js +1101 -0
- package/lib/typert.host.d.ts +3 -0
- package/lib/typert.host.js +611 -0
- package/lib/typert.remote-client.d.ts +37 -0
- package/lib/typert.remote-client.d.ts.map +1 -0
- package/lib/typert.remote-client.js +505 -0
- package/package.json +156 -3
- package/src/client/FileInspector.tsx +162 -0
- package/src/client/GitDiffPane.tsx +252 -0
- package/src/client/GitReviewCard.tsx +202 -0
- package/src/client/GitReviewRow.tsx +191 -0
- package/src/client/ReviewToolbar.tsx +470 -0
- package/src/client/contract.ts +27 -0
- package/src/client/css.d.ts +5 -0
- package/src/client/index.tsx +230 -0
- package/src/client/review-turn.ts +193 -0
- package/src/client/reviewSelection.ts +14 -0
- package/src/client/useLoad.ts +38 -0
- package/src/client/useReviewViewState.ts +244 -0
- package/src/git-service.ts +845 -0
- package/src/index.ts +67 -0
- package/src/review-tool.ts +85 -0
- package/src/workspace-review-service.ts +400 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ToolCallBlock,
|
|
3
|
+
UseChat,
|
|
4
|
+
} from "@deepseek-ai/dsh-client-ui-chat/client";
|
|
5
|
+
import type {
|
|
6
|
+
InjectFace,
|
|
7
|
+
PropsRuntime,
|
|
8
|
+
} from "@deepseek-ai/dsh-client-ui-slots";
|
|
9
|
+
import type { SessionId } from "@deepseek-ai/dsh-session/types";
|
|
10
|
+
import css, {
|
|
11
|
+
cssText,
|
|
12
|
+
} from "@lukstei/util-review-ui/client/GitDiffPane.module.css";
|
|
13
|
+
import { ReviewCard } from "@lukstei/util-review-ui/client/ReviewCard.tsx";
|
|
14
|
+
import {
|
|
15
|
+
branchLabel,
|
|
16
|
+
GIT_REVIEW_TOOL,
|
|
17
|
+
shortSha,
|
|
18
|
+
} from "@lukstei/util-review-ui/review";
|
|
19
|
+
import {
|
|
20
|
+
type GitReviewEntry,
|
|
21
|
+
type GitReviewScopeOrTarget,
|
|
22
|
+
isBranchReviewScope,
|
|
23
|
+
reviewScopeOrTargetSchema,
|
|
24
|
+
} from "./review-turn.ts";
|
|
25
|
+
|
|
26
|
+
/** Injected face: the split-view opener and availability probe. */
|
|
27
|
+
export interface GitReviewInjected {
|
|
28
|
+
openReview?: (sessionId: SessionId, scope: GitReviewScopeOrTarget) => void;
|
|
29
|
+
canOpen?: () => boolean;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export type GitReviewCardProps = (
|
|
33
|
+
| PropsRuntime<"conversation.chat.turnTail">
|
|
34
|
+
| {
|
|
35
|
+
sessionId: SessionId;
|
|
36
|
+
turn?: {
|
|
37
|
+
turn?: number;
|
|
38
|
+
data?: {
|
|
39
|
+
get: (
|
|
40
|
+
key: string,
|
|
41
|
+
) => { reviews: readonly GitReviewEntry[] } | undefined;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
useChat?: UseChat;
|
|
45
|
+
reviews?: readonly GitReviewEntry[];
|
|
46
|
+
}
|
|
47
|
+
) &
|
|
48
|
+
InjectFace<GitReviewInjected>;
|
|
49
|
+
|
|
50
|
+
function extractToolCall(block: unknown, key: string): GitReviewEntry | null {
|
|
51
|
+
if (!block || typeof block !== "object") return null;
|
|
52
|
+
const isError = "isError" in block && Boolean(block.isError);
|
|
53
|
+
if (isError) return null;
|
|
54
|
+
|
|
55
|
+
const call =
|
|
56
|
+
"call" in block && block.call
|
|
57
|
+
? block.call
|
|
58
|
+
: "kind" in block && (block as { call?: unknown }).call
|
|
59
|
+
? (block as { call?: unknown }).call
|
|
60
|
+
: block;
|
|
61
|
+
const isRecord = (v: unknown): v is Record<string, unknown> =>
|
|
62
|
+
typeof v === "object" && v !== null;
|
|
63
|
+
const toolName =
|
|
64
|
+
isRecord(call) && typeof call.name === "string" ? call.name : undefined;
|
|
65
|
+
if (toolName !== GIT_REVIEW_TOOL) return null;
|
|
66
|
+
|
|
67
|
+
const argsRaw =
|
|
68
|
+
isRecord(call) && typeof call.argsRaw === "string"
|
|
69
|
+
? call.argsRaw
|
|
70
|
+
: undefined;
|
|
71
|
+
if (typeof argsRaw !== "string") return null;
|
|
72
|
+
|
|
73
|
+
try {
|
|
74
|
+
const parsed = JSON.parse(argsRaw);
|
|
75
|
+
const target = reviewScopeOrTargetSchema.safeParse(parsed);
|
|
76
|
+
if (!target.success) return null;
|
|
77
|
+
const id =
|
|
78
|
+
"callId" in block && typeof block.callId === "string"
|
|
79
|
+
? block.callId
|
|
80
|
+
: isRecord(call) && typeof call.callId === "string"
|
|
81
|
+
? call.callId
|
|
82
|
+
: key;
|
|
83
|
+
return { id, scope: target.data };
|
|
84
|
+
} catch {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function useResolvedReviews(
|
|
90
|
+
props: GitReviewCardProps,
|
|
91
|
+
): readonly GitReviewEntry[] {
|
|
92
|
+
const manualReviews = "reviews" in props ? props.reviews : undefined;
|
|
93
|
+
const turnDataReviews =
|
|
94
|
+
"turn" in props && props.turn?.data !== undefined
|
|
95
|
+
? (props.turn.data.get("git-review")?.reviews ?? [])
|
|
96
|
+
: [];
|
|
97
|
+
const turnNumber =
|
|
98
|
+
"turn" in props && props.turn !== undefined
|
|
99
|
+
? typeof props.turn.turn === "number"
|
|
100
|
+
? props.turn.turn
|
|
101
|
+
: undefined
|
|
102
|
+
: undefined;
|
|
103
|
+
const useChat = "useChat" in props ? props.useChat : undefined;
|
|
104
|
+
|
|
105
|
+
const fallbackReviews = useChat
|
|
106
|
+
? // biome-ignore lint/correctness/useHookAtTopLevel: useChat presence is fixed per prop variant for a card's lifetime
|
|
107
|
+
useChat((snapshot) => {
|
|
108
|
+
if (
|
|
109
|
+
(manualReviews !== undefined && manualReviews.length > 0) ||
|
|
110
|
+
turnDataReviews.length > 0 ||
|
|
111
|
+
turnNumber === undefined
|
|
112
|
+
)
|
|
113
|
+
return [];
|
|
114
|
+
const keys = snapshot.locations.getTurn(turnNumber);
|
|
115
|
+
const results: GitReviewEntry[] = [];
|
|
116
|
+
for (const key of keys) {
|
|
117
|
+
const node = snapshot.nodes.get(key);
|
|
118
|
+
if (node?.kind === "assistant-step") {
|
|
119
|
+
const blocks = (node.data as { blocks?: unknown[] })?.blocks;
|
|
120
|
+
if (Array.isArray(blocks)) {
|
|
121
|
+
for (const block of blocks) {
|
|
122
|
+
const entry = extractToolCall(block, key);
|
|
123
|
+
if (entry && !results.some((r) => r.id === entry.id)) {
|
|
124
|
+
results.push(entry);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
if (node?.kind === "tool-call") {
|
|
130
|
+
const root = (node.data as { root?: ToolCallBlock })?.root;
|
|
131
|
+
const entry = extractToolCall(root, key);
|
|
132
|
+
if (entry && !results.some((r) => r.id === entry.id)) {
|
|
133
|
+
results.push(entry);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return results;
|
|
138
|
+
})
|
|
139
|
+
: [];
|
|
140
|
+
|
|
141
|
+
if (manualReviews !== undefined && manualReviews.length > 0)
|
|
142
|
+
return manualReviews;
|
|
143
|
+
if (turnDataReviews.length > 0) return turnDataReviews;
|
|
144
|
+
return fallbackReviews;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Render the persistent review card for a presented Git review target or scope.
|
|
149
|
+
* Intended for turn-tail rendering so it remains visible after turn completion.
|
|
150
|
+
* @param props - turn-tail runtime props and injected opener.
|
|
151
|
+
* @returns the cards, or null when no review target is present.
|
|
152
|
+
*/
|
|
153
|
+
export function GitReviewCard(props: GitReviewCardProps) {
|
|
154
|
+
const { sessionId, openReview, canOpen } = props;
|
|
155
|
+
const reviews = useResolvedReviews(props);
|
|
156
|
+
if (reviews.length === 0) return null;
|
|
157
|
+
|
|
158
|
+
const hasOpener =
|
|
159
|
+
canOpen !== undefined ? canOpen() : openReview !== undefined;
|
|
160
|
+
const onOpen = (scope: GitReviewScopeOrTarget) =>
|
|
161
|
+
hasOpener && openReview !== undefined
|
|
162
|
+
? () => openReview(sessionId, scope)
|
|
163
|
+
: undefined;
|
|
164
|
+
|
|
165
|
+
return (
|
|
166
|
+
<div className={css.reviewCardList} data-git-review-cards>
|
|
167
|
+
<style>{cssText}</style>
|
|
168
|
+
{reviews.map((review) => {
|
|
169
|
+
const scope = review.scope;
|
|
170
|
+
let branch: string;
|
|
171
|
+
let commitSha: string | null = null;
|
|
172
|
+
let commitSubject: string | null = null;
|
|
173
|
+
if (isBranchReviewScope(scope)) {
|
|
174
|
+
branch = scope.ref;
|
|
175
|
+
if (scope.revision.kind === "commit") {
|
|
176
|
+
commitSha = scope.revision.commit.sha;
|
|
177
|
+
commitSubject = scope.revision.commit.subject;
|
|
178
|
+
}
|
|
179
|
+
} else {
|
|
180
|
+
branch = scope.branch;
|
|
181
|
+
if (scope.commit !== undefined) {
|
|
182
|
+
commitSha = scope.commit;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
const description =
|
|
186
|
+
commitSha === null
|
|
187
|
+
? "All commits"
|
|
188
|
+
: commitSubject !== null
|
|
189
|
+
? `${shortSha(commitSha)} — ${commitSubject}`
|
|
190
|
+
: shortSha(commitSha);
|
|
191
|
+
return (
|
|
192
|
+
<ReviewCard
|
|
193
|
+
key={review.id}
|
|
194
|
+
title={branchLabel(branch)}
|
|
195
|
+
description={description}
|
|
196
|
+
onOpen={onOpen(review.scope)}
|
|
197
|
+
/>
|
|
198
|
+
);
|
|
199
|
+
})}
|
|
200
|
+
</div>
|
|
201
|
+
);
|
|
202
|
+
}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DisclosureRow,
|
|
3
|
+
IconBranchOutlineRegular,
|
|
4
|
+
} from "@deepseek-ai/dsh-client-ui-primitives";
|
|
5
|
+
import type {
|
|
6
|
+
InjectFace,
|
|
7
|
+
PropsRuntime,
|
|
8
|
+
} from "@deepseek-ai/dsh-client-ui-slots";
|
|
9
|
+
import type { SessionId } from "@deepseek-ai/dsh-session/types";
|
|
10
|
+
import { cssText } from "@lukstei/util-review-ui/client/GitDiffPane.module.css";
|
|
11
|
+
import { ReviewCard } from "@lukstei/util-review-ui/client/ReviewCard.tsx";
|
|
12
|
+
import {
|
|
13
|
+
branchLabel,
|
|
14
|
+
reviewTargetSchema,
|
|
15
|
+
shortSha,
|
|
16
|
+
} from "@lukstei/util-review-ui/review";
|
|
17
|
+
import type { ReviewTarget } from "@lukstei/util-review-ui/types";
|
|
18
|
+
import { useState } from "react";
|
|
19
|
+
import type { GitReviewInjected } from "./GitReviewCard.tsx";
|
|
20
|
+
|
|
21
|
+
export type GitReviewRowProps = PropsRuntime<"tool.call.toolview"> &
|
|
22
|
+
InjectFace<GitReviewInjected> & {
|
|
23
|
+
sessionId?: SessionId;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/* v8 ignore next */
|
|
27
|
+
const noop = (): void => undefined;
|
|
28
|
+
|
|
29
|
+
function formatTarget(argsRaw: string): string {
|
|
30
|
+
try {
|
|
31
|
+
const parsed = JSON.parse(argsRaw);
|
|
32
|
+
const target = reviewTargetSchema.safeParse(parsed);
|
|
33
|
+
if (target.success) {
|
|
34
|
+
const label = branchLabel(target.data.branch);
|
|
35
|
+
return target.data.commit !== undefined
|
|
36
|
+
? `${label} @ ${shortSha(target.data.commit)}`
|
|
37
|
+
: label;
|
|
38
|
+
}
|
|
39
|
+
} catch {
|
|
40
|
+
// Partial or streaming JSON
|
|
41
|
+
}
|
|
42
|
+
return argsRaw;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function parseTarget(argsRaw: string): ReviewTarget | undefined {
|
|
46
|
+
try {
|
|
47
|
+
const parsed = JSON.parse(argsRaw);
|
|
48
|
+
const target = reviewTargetSchema.safeParse(parsed);
|
|
49
|
+
return target.success ? target.data : undefined;
|
|
50
|
+
} catch {
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Render a git_review_present call during tool execution inside the process group.
|
|
57
|
+
* @param props - tool call props.
|
|
58
|
+
* @returns in-process disclosure row.
|
|
59
|
+
*/
|
|
60
|
+
export function GitReviewRow(props: GitReviewRowProps) {
|
|
61
|
+
const { block, inspect, phase, openReview, canOpen, sessionId } = props;
|
|
62
|
+
const [expanded, setExpanded] = useState(false);
|
|
63
|
+
|
|
64
|
+
if (phase === "preparing") {
|
|
65
|
+
return (
|
|
66
|
+
<div data-tool="git_review_present" data-state="preparing">
|
|
67
|
+
<DisclosureRow
|
|
68
|
+
title="Git Review"
|
|
69
|
+
icon={<IconBranchOutlineRegular size={14} />}
|
|
70
|
+
open={false}
|
|
71
|
+
expandable={false}
|
|
72
|
+
onToggle={noop}
|
|
73
|
+
running
|
|
74
|
+
/>
|
|
75
|
+
</div>
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const settled = block && "kind" in block;
|
|
80
|
+
const isError = block && "isError" in block && Boolean(block.isError);
|
|
81
|
+
const error = block && "error" in block ? block.error : undefined;
|
|
82
|
+
const state = !settled
|
|
83
|
+
? "running"
|
|
84
|
+
: error?.code === "interrupted"
|
|
85
|
+
? "stopped"
|
|
86
|
+
: isError
|
|
87
|
+
? "error"
|
|
88
|
+
: "ok";
|
|
89
|
+
const call = block && "call" in block ? block.call : block;
|
|
90
|
+
const args =
|
|
91
|
+
(call && "argsRaw" in call && typeof call.argsRaw === "string"
|
|
92
|
+
? call.argsRaw
|
|
93
|
+
: undefined) ?? "";
|
|
94
|
+
const output =
|
|
95
|
+
settled && "content" in block && Array.isArray(block.content)
|
|
96
|
+
? block.content
|
|
97
|
+
.map((item) =>
|
|
98
|
+
item.type === "text" ? item.text : JSON.stringify(item),
|
|
99
|
+
)
|
|
100
|
+
.join("\n")
|
|
101
|
+
: "";
|
|
102
|
+
const details =
|
|
103
|
+
output || (settled && error ? `${error.name}: ${error.code}` : "");
|
|
104
|
+
const target = parseTarget(args);
|
|
105
|
+
const hasContent = details !== "" || target !== undefined;
|
|
106
|
+
|
|
107
|
+
const hasOpener =
|
|
108
|
+
canOpen !== undefined ? canOpen() : openReview !== undefined;
|
|
109
|
+
const onOpen =
|
|
110
|
+
target && hasOpener && openReview !== undefined && sessionId !== undefined
|
|
111
|
+
? () => openReview(sessionId, target)
|
|
112
|
+
: undefined;
|
|
113
|
+
|
|
114
|
+
return (
|
|
115
|
+
<div data-tool="git_review_present" data-state={state}>
|
|
116
|
+
<DisclosureRow
|
|
117
|
+
title="Git Review"
|
|
118
|
+
icon={<IconBranchOutlineRegular size={14} />}
|
|
119
|
+
open={expanded && hasContent}
|
|
120
|
+
expandable={hasContent}
|
|
121
|
+
expandOnRowClick
|
|
122
|
+
keepContentWhenOpen
|
|
123
|
+
onToggle={() => {
|
|
124
|
+
setExpanded((value) => !value);
|
|
125
|
+
}}
|
|
126
|
+
collapsedContent={
|
|
127
|
+
<span
|
|
128
|
+
style={{
|
|
129
|
+
marginLeft: 8,
|
|
130
|
+
fontSize: 12,
|
|
131
|
+
display: "flex",
|
|
132
|
+
gap: 8,
|
|
133
|
+
alignItems: "center",
|
|
134
|
+
}}
|
|
135
|
+
>
|
|
136
|
+
<span>{formatTarget(args)}</span>
|
|
137
|
+
</span>
|
|
138
|
+
}
|
|
139
|
+
>
|
|
140
|
+
{details !== "" && (
|
|
141
|
+
<pre
|
|
142
|
+
style={{
|
|
143
|
+
margin: "8px 0",
|
|
144
|
+
padding: 12,
|
|
145
|
+
borderRadius: "var(--dsw-radius-lg)",
|
|
146
|
+
background: "var(--dsw-alias-bg-layer-1)",
|
|
147
|
+
color: "var(--dsw-alias-label-secondary)",
|
|
148
|
+
whiteSpace: "pre-wrap",
|
|
149
|
+
overflowWrap: "anywhere",
|
|
150
|
+
fontSize: 12,
|
|
151
|
+
}}
|
|
152
|
+
>
|
|
153
|
+
{details}
|
|
154
|
+
</pre>
|
|
155
|
+
)}
|
|
156
|
+
{target && (
|
|
157
|
+
<div style={{ marginTop: 8 }}>
|
|
158
|
+
<style>{cssText}</style>
|
|
159
|
+
<ReviewCard
|
|
160
|
+
title={branchLabel(target.branch)}
|
|
161
|
+
description={
|
|
162
|
+
target.commit !== undefined
|
|
163
|
+
? shortSha(target.commit)
|
|
164
|
+
: "All commits"
|
|
165
|
+
}
|
|
166
|
+
onOpen={onOpen}
|
|
167
|
+
/>
|
|
168
|
+
</div>
|
|
169
|
+
)}
|
|
170
|
+
{inspect && (
|
|
171
|
+
<button
|
|
172
|
+
type="button"
|
|
173
|
+
style={{
|
|
174
|
+
alignSelf: "flex-start",
|
|
175
|
+
border: "none",
|
|
176
|
+
padding: "4px 0",
|
|
177
|
+
background: "transparent",
|
|
178
|
+
color: "var(--dsw-alias-link)",
|
|
179
|
+
font: "inherit",
|
|
180
|
+
fontSize: 12,
|
|
181
|
+
cursor: "pointer",
|
|
182
|
+
}}
|
|
183
|
+
onClick={inspect}
|
|
184
|
+
>
|
|
185
|
+
Inspect
|
|
186
|
+
</button>
|
|
187
|
+
)}
|
|
188
|
+
</DisclosureRow>
|
|
189
|
+
</div>
|
|
190
|
+
);
|
|
191
|
+
}
|