@whybebabo/dsh-file-review-tab 0.0.0-stage → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js ADDED
@@ -0,0 +1,306 @@
1
+ import { lstat, readFile, realpath } from "node:fs/promises";
2
+ import { isAbsolute, relative, resolve } from "node:path";
3
+ import { writeFileAtomic } from "@deepseek-ai/dsh-atomic-write";
4
+ import { TypertRemoteService } from "@deepseek-ai/dsh-typert-protocol";
5
+ //#region src/file-review-service.ts
6
+ /** Host-side, workspace-contained undo / redo service for produced text diffs. */
7
+ /**
8
+ * The mutation tools' recorded hunks (both diff cards and Code Mode
9
+ * before/after values) ride the filesystem backend's LF-normalized basis,
10
+ * while files on disk may use CRLF. All hunk matching therefore runs on the
11
+ * normalized text; the write path restores the file's own line-ending style.
12
+ */
13
+ function normalizeNewlines(text) {
14
+ return text.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
15
+ }
16
+ function restoreNewlines(text, crlf) {
17
+ return crlf ? text.replace(/\n/g, "\r\n") : text;
18
+ }
19
+ function inside(root, candidate) {
20
+ const child = relative(root, candidate);
21
+ return child === "" || !child.startsWith("..") && !isAbsolute(child);
22
+ }
23
+ async function resolveFile(cwd, requestedPath) {
24
+ const root = await realpath(cwd);
25
+ const candidate = resolve(root, requestedPath);
26
+ if (!inside(root, candidate)) throw new Error("path is outside the session workspace");
27
+ const linkStat = await lstat(candidate);
28
+ if (linkStat.isSymbolicLink()) throw new Error("symbolic links are not supported");
29
+ if (!linkStat.isFile()) throw new Error("path is not a regular file");
30
+ const filename = await realpath(candidate);
31
+ if (!inside(root, filename)) throw new Error("resolved path is outside the session workspace");
32
+ const bytes = await readFile(filename);
33
+ const text = bytes.toString("utf8");
34
+ if (!Buffer.from(text, "utf8").equals(bytes)) throw new Error("file is not valid UTF-8 text");
35
+ const crlf = text.includes("\r");
36
+ return {
37
+ filename,
38
+ mode: linkStat.mode & 511,
39
+ bytes,
40
+ text,
41
+ crlf,
42
+ lfText: normalizeNewlines(text)
43
+ };
44
+ }
45
+ function offsetAtLine(text, line) {
46
+ if (!Number.isInteger(line) || line < 1) return null;
47
+ if (line === 1) return 0;
48
+ let offset = 0;
49
+ for (let current = 1; current < line; current += 1) {
50
+ const next = text.indexOf("\n", offset);
51
+ if (next === -1) return null;
52
+ offset = next + 1;
53
+ }
54
+ return offset;
55
+ }
56
+ function replaceHunk(text, source, replacement, line) {
57
+ let offset;
58
+ if (line !== void 0) {
59
+ const located = offsetAtLine(text, line);
60
+ if (located === null || text.slice(located, located + source.length) !== source) return null;
61
+ offset = located;
62
+ } else {
63
+ if (source === "") return null;
64
+ offset = text.indexOf(source);
65
+ if (offset === -1 || text.indexOf(source, offset + 1) !== -1) return null;
66
+ }
67
+ return text.slice(0, offset) + replacement + text.slice(offset + source.length);
68
+ }
69
+ function hunkSupported(diff, path) {
70
+ if (diff.path !== path || diff.oldText === null || diff.oldText === diff.newText) return false;
71
+ if (diff.oldText === "" && diff.oldStart === void 0) return false;
72
+ if (diff.newText === "" && diff.newStart === void 0) return false;
73
+ return true;
74
+ }
75
+ /** Apply a complete file's hunk sequence in memory, or report a strict mismatch. */
76
+ function transformFile(text, file, action) {
77
+ if (file.diffs.length === 0 || !file.diffs.every((diff) => hunkSupported(diff, file.path))) return null;
78
+ const diffs = action === "undo" ? [...file.diffs].reverse() : file.diffs;
79
+ let next = text;
80
+ for (const diff of diffs) {
81
+ const source = action === "undo" ? diff.newText : diff.oldText;
82
+ const replacement = action === "undo" ? diff.oldText : diff.newText;
83
+ if (source === null || replacement === null) return null;
84
+ const changed = replaceHunk(next, source, replacement, action === "undo" ? diff.newStart : diff.oldStart);
85
+ if (changed === null) return null;
86
+ next = changed;
87
+ }
88
+ return next;
89
+ }
90
+ function hunkSidePresent(text, file, side) {
91
+ for (const diff of file.diffs) {
92
+ const source = side === "old" ? diff.oldText : diff.newText;
93
+ if (source === null) continue;
94
+ const line = side === "old" ? diff.oldStart : diff.newStart;
95
+ if (line !== void 0) {
96
+ const located = offsetAtLine(text, line);
97
+ if (located === null || text.slice(located, located + source.length) !== source) return false;
98
+ } else if (text.indexOf(source) === -1) return false;
99
+ }
100
+ return true;
101
+ }
102
+ function inspectText(text, file) {
103
+ if (file.diffs.length === 0 || !file.diffs.every((diff) => hunkSupported(diff, file.path))) return {
104
+ state: "unsupported",
105
+ reason: "change has no complete reversible diff"
106
+ };
107
+ const undone = transformFile(text, file, "undo");
108
+ const redone = transformFile(text, file, "redo");
109
+ if (undone !== null && redone !== null) return hunkSidePresent(text, file, "new") ? {
110
+ state: "applied",
111
+ text,
112
+ nextText: undone
113
+ } : {
114
+ state: "undone",
115
+ text,
116
+ nextText: redone
117
+ };
118
+ if (undone !== null) return {
119
+ state: "applied",
120
+ text,
121
+ nextText: undone
122
+ };
123
+ if (redone !== null) return {
124
+ state: "undone",
125
+ text,
126
+ nextText: redone
127
+ };
128
+ return {
129
+ state: "conflict",
130
+ reason: "current content does not match the recorded change"
131
+ };
132
+ }
133
+ async function inspectOne(cwd, file) {
134
+ if (file.diffs.length === 0 || !file.diffs.every((diff) => hunkSupported(diff, file.path))) return {
135
+ path: file.path,
136
+ state: "unsupported",
137
+ changed: false,
138
+ reason: "change has no complete reversible diff"
139
+ };
140
+ try {
141
+ const inspected = inspectText((await resolveFile(cwd, file.path)).lfText, file);
142
+ return {
143
+ path: file.path,
144
+ state: inspected.state,
145
+ changed: false,
146
+ reason: inspected.reason
147
+ };
148
+ } catch (error) {
149
+ return {
150
+ path: file.path,
151
+ state: "error",
152
+ changed: false,
153
+ reason: error instanceof Error ? error.message : String(error)
154
+ };
155
+ }
156
+ }
157
+ async function applyOne(cwd, file, action) {
158
+ if (file.diffs.length === 0 || !file.diffs.every((diff) => hunkSupported(diff, file.path))) return {
159
+ path: file.path,
160
+ state: "unsupported",
161
+ changed: false,
162
+ reason: "change has no complete reversible diff"
163
+ };
164
+ try {
165
+ const resolved = await resolveFile(cwd, file.path);
166
+ const inspected = inspectText(resolved.lfText, file);
167
+ const sourceState = action === "undo" ? "applied" : "undone";
168
+ const targetState = action === "undo" ? "undone" : "applied";
169
+ if (inspected.state === targetState) return {
170
+ path: file.path,
171
+ state: targetState,
172
+ changed: false
173
+ };
174
+ if (inspected.state !== sourceState || inspected.nextText === void 0) return {
175
+ path: file.path,
176
+ state: inspected.state,
177
+ changed: false,
178
+ reason: inspected.reason
179
+ };
180
+ const current = await readFile(resolved.filename);
181
+ if (!Buffer.from(resolved.bytes).equals(current)) return {
182
+ path: file.path,
183
+ state: "conflict",
184
+ changed: false,
185
+ reason: "file changed while the operation was being prepared"
186
+ };
187
+ await writeFileAtomic(resolved.filename, restoreNewlines(inspected.nextText, resolved.crlf), { mode: resolved.mode });
188
+ return {
189
+ path: file.path,
190
+ state: targetState,
191
+ changed: true
192
+ };
193
+ } catch (error) {
194
+ return {
195
+ path: file.path,
196
+ state: "error",
197
+ changed: false,
198
+ reason: error instanceof Error ? error.message : String(error)
199
+ };
200
+ }
201
+ }
202
+ function sessionCwd(agent) {
203
+ const cwd = agent.session.header.cwd;
204
+ if (cwd === void 0 || cwd.trim() === "") throw new Error("session has no workspace directory");
205
+ return cwd;
206
+ }
207
+ /** Per-agent cap on recorded Code Mode mutations (oldest evicted first). */
208
+ const RECORDED_PER_AGENT_CAP = 4e3;
209
+ function agentKey(agent) {
210
+ return String(agent.id);
211
+ }
212
+ /** Host service published as the `fileReview` Remote namespace. */
213
+ var FileReviewService = class extends TypertRemoteService {
214
+ /** Per-agent record of Code Mode (`run_code`) file mutations, dispatch order. */
215
+ recordLog = /* @__PURE__ */ new Map();
216
+ constructor(ctx) {
217
+ super(ctx, "fileReview");
218
+ }
219
+ /** Append one nested (Code Mode) file mutation for the receiving agent. */
220
+ recordMutation(agent, mutation) {
221
+ const key = agentKey(agent);
222
+ const list = this.recordLog.get(key);
223
+ if (list === void 0) {
224
+ this.recordLog.set(key, [mutation]);
225
+ return;
226
+ }
227
+ list.push(mutation);
228
+ if (list.length > RECORDED_PER_AGENT_CAP) list.splice(0, list.length - RECORDED_PER_AGENT_CAP);
229
+ }
230
+ /** Return the recorded mutations for the requested `run_code` roots. */
231
+ async recorded(agent, request) {
232
+ const list = this.recordLog.get(agentKey(agent));
233
+ if (list === void 0 || request.rootCallIds.length === 0) return { mutations: [] };
234
+ const wanted = new Set(request.rootCallIds);
235
+ return { mutations: list.filter((mutation) => wanted.has(mutation.rootCallId)) };
236
+ }
237
+ /** Inspect current disk state without changing files. */
238
+ async status(agent, request) {
239
+ const cwd = sessionCwd(agent);
240
+ return { files: await Promise.all(request.files.map((file) => inspectOne(cwd, file))) };
241
+ }
242
+ /** Toggle every independently safe file while the receiving Agent is idle. */
243
+ async apply(agent, request) {
244
+ const cwd = sessionCwd(agent);
245
+ return agent.runMaintenance(async () => {
246
+ const files = [];
247
+ for (const file of request.files) files.push(await applyOne(cwd, file, request.action));
248
+ return { files };
249
+ });
250
+ }
251
+ };
252
+ //#endregion
253
+ //#region src/index.ts
254
+ /** Services required for the model guidance paired with the browser renderer. */
255
+ const inject = ["systemPrompt"];
256
+ /** Stable final-response guidance owned by the matching renderer. */
257
+ const FILE_REFERENCE_PROMPT = "When you successfully create or modify files, mention the primary outputs in your final response. To make those and any other changed-file references clickable in Web, format them as Markdown inline code using the exact file-tool path, or a basename when unique among the files changed in that turn.";
258
+ /**
259
+ * Register model guidance for the file-reference renderer shipped by this package,
260
+ * and the Code Mode (`run_code`) mutation recorder that backs the browser-side
261
+ * review tab.
262
+ *
263
+ * Nested dispatch results carry no wire views — the diff cards only ride
264
+ * model-direct tool/call frames — so reviewing programmatic file edits needs a
265
+ * second source: this listener snapshots the full `before`/`after` content of
266
+ * every nested file mutation (`edit`/`write` — recognized by result shape, not
267
+ * tool name) into the `fileReview` service, which the browser half later turns
268
+ * into line-level hunks and merges into the owning `run_code` turn.
269
+ * @param ctx - host context carrying the system-prompt registry and tool waterfall.
270
+ */
271
+ function apply(ctx) {
272
+ const service = new FileReviewService(ctx);
273
+ ctx.systemPrompt.section({
274
+ name: "ui:file-review-references",
275
+ order: 190,
276
+ text: FILE_REFERENCE_PROMPT
277
+ });
278
+ const emitter = ctx;
279
+ ctx.effect(() => {
280
+ const off = emitter.on("tools/post-execute", async (execRaw, resultRaw, nextRaw) => {
281
+ const exec = execRaw;
282
+ const result = resultRaw;
283
+ const decision = await nextRaw();
284
+ if (decision.kind !== "accept") return decision;
285
+ if (exec.parent === void 0 || exec.agent === void 0) return decision;
286
+ const value = result.value;
287
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return decision;
288
+ const candidate = value;
289
+ if (typeof candidate.path !== "string" || typeof candidate.after !== "string") return decision;
290
+ if (candidate.before !== null && typeof candidate.before !== "string") return decision;
291
+ service.recordMutation(exec.agent, {
292
+ rootCallId: String(exec.rootCallId ?? exec.callId),
293
+ name: exec.name,
294
+ path: candidate.path,
295
+ before: candidate.before ?? null,
296
+ after: candidate.after
297
+ });
298
+ return decision;
299
+ });
300
+ return () => {
301
+ off();
302
+ };
303
+ }, "file-review-tab: ptc recorder");
304
+ }
305
+ //#endregion
306
+ export { FileReviewService, apply, inject, transformFile };
package/lib/remote.js ADDED
@@ -0,0 +1,8 @@
1
+ import { n as PACKAGE_NAME, t as FILE_REVIEW_INVOCATIONS } from "./typert-descriptors.js";
2
+ //#region src/remote.ts
3
+ const TYPERT_REMOTE = {
4
+ package: PACKAGE_NAME,
5
+ descriptors: FILE_REVIEW_INVOCATIONS
6
+ };
7
+ //#endregion
8
+ export { TYPERT_REMOTE, TYPERT_REMOTE as default };
@@ -0,0 +1,132 @@
1
+ import { z } from "zod";
2
+ //#region src/typert-descriptors.ts
3
+ /** Strict Typert codecs shared by the Host and browser contribution artifacts. */
4
+ /**
5
+ * This package's npm name, which the Typert host face is keyed by.
6
+ *
7
+ * `typert-loader` rejects a host manifest whose `package` differs from the
8
+ * package that exports it ("the manifest must be owned by the package that
9
+ * exports it"), and the registry rejects a duplicate `package` registration —
10
+ * so this string has to be the real published name, not a display label.
11
+ */
12
+ const PACKAGE_NAME = "@whybebabo/dsh-file-review-tab";
13
+ /**
14
+ * dsh 0.2.0 replaced the strict codec's eager `schema` member with a lazy
15
+ * `create()` factory, so the process-realm schema is materialized on first
16
+ * boundary use instead of at contribution-load time. DSH's own generated
17
+ * codecs memoize one schema instance per codec behind that factory; these
18
+ * helpers keep the same shape for hand-written descriptors.
19
+ * @param build - creates the Zod schema on first call.
20
+ * @returns a memoized schema factory suitable for `codec.create`.
21
+ */
22
+ function lazySchema(build) {
23
+ let value;
24
+ return () => value ??= build();
25
+ }
26
+ /** One strict codec over a lazily materialized Zod schema. */
27
+ function strictCodec(typeSymbol, build) {
28
+ return {
29
+ mode: "strict",
30
+ typeSymbol,
31
+ create: lazySchema(build)
32
+ };
33
+ }
34
+ const diffSchema = z.object({
35
+ path: z.string(),
36
+ oldText: z.string().nullable(),
37
+ newText: z.string(),
38
+ oldStart: z.number().int().min(1).optional(),
39
+ newStart: z.number().int().min(1).optional()
40
+ });
41
+ const requestSchema = z.object({
42
+ action: z.enum(["undo", "redo"]),
43
+ files: z.array(z.object({
44
+ path: z.string(),
45
+ diffs: z.array(diffSchema)
46
+ }))
47
+ });
48
+ const resultSchema = z.object({ files: z.array(z.object({
49
+ path: z.string(),
50
+ state: z.enum([
51
+ "applied",
52
+ "undone",
53
+ "conflict",
54
+ "unsupported",
55
+ "error"
56
+ ]),
57
+ changed: z.boolean(),
58
+ reason: z.string().optional()
59
+ })) });
60
+ const agentCodec = strictCodec("@deepseek-ai/dsh-session/types#SessionId", () => z.intersection(z.string(), z.unknown()));
61
+ const requestCodec = strictCodec(`${PACKAGE_NAME}#FileReviewRequest`, () => requestSchema);
62
+ const resultCodec = strictCodec(`${PACKAGE_NAME}#FileReviewResult`, () => resultSchema);
63
+ const recordedMutationSchema = z.object({
64
+ rootCallId: z.string(),
65
+ name: z.string(),
66
+ path: z.string(),
67
+ before: z.string().nullable(),
68
+ after: z.string()
69
+ });
70
+ const recordedRequestSchema = z.object({ rootCallIds: z.array(z.string()) });
71
+ const recordedResultSchema = z.object({ mutations: z.array(recordedMutationSchema) });
72
+ const recordedRequestCodec = strictCodec(`${PACKAGE_NAME}#RecordedRequest`, () => recordedRequestSchema);
73
+ const recordedResultCodec = strictCodec(`${PACKAGE_NAME}#RecordedResult`, () => recordedResultSchema);
74
+ function descriptor(method) {
75
+ return {
76
+ id: `${PACKAGE_NAME}#fileReview/${method}`,
77
+ service: "fileReview",
78
+ namespace: "fileReview",
79
+ method,
80
+ invocation: { kind: "direct" },
81
+ scope: {
82
+ context: "agent",
83
+ wire: "agentId"
84
+ },
85
+ parameters: [{
86
+ name: "agent",
87
+ wire: "agentId",
88
+ source: "lookup",
89
+ lookup: "agent",
90
+ codec: agentCodec
91
+ }, {
92
+ name: "request",
93
+ wire: "request",
94
+ source: "json",
95
+ codec: requestCodec
96
+ }],
97
+ result: resultCodec
98
+ };
99
+ }
100
+ function recordedDescriptor() {
101
+ return {
102
+ id: `${PACKAGE_NAME}#fileReview/recorded`,
103
+ service: "fileReview",
104
+ namespace: "fileReview",
105
+ method: "recorded",
106
+ invocation: { kind: "direct" },
107
+ scope: {
108
+ context: "agent",
109
+ wire: "agentId"
110
+ },
111
+ parameters: [{
112
+ name: "agent",
113
+ wire: "agentId",
114
+ source: "lookup",
115
+ lookup: "agent",
116
+ codec: agentCodec
117
+ }, {
118
+ name: "request",
119
+ wire: "request",
120
+ source: "json",
121
+ codec: recordedRequestCodec
122
+ }],
123
+ result: recordedResultCodec
124
+ };
125
+ }
126
+ const FILE_REVIEW_INVOCATIONS = [
127
+ descriptor("status"),
128
+ descriptor("apply"),
129
+ recordedDescriptor()
130
+ ];
131
+ //#endregion
132
+ export { PACKAGE_NAME as n, FILE_REVIEW_INVOCATIONS as t };
@@ -0,0 +1,22 @@
1
+ import { n as PACKAGE_NAME, t as FILE_REVIEW_INVOCATIONS } from "./typert-descriptors.js";
2
+ //#region src/typert.host.ts
3
+ const TYPERT = {
4
+ package: PACKAGE_NAME,
5
+ face: "host",
6
+ schemas: [],
7
+ invocations: FILE_REVIEW_INVOCATIONS,
8
+ model: {
9
+ services: [{
10
+ key: "fileReview",
11
+ exportName: "FileReviewService",
12
+ summary: "Safely inspect and toggle one turn of produced text changes.",
13
+ tags: [],
14
+ members: [],
15
+ types: []
16
+ }],
17
+ events: [],
18
+ objects: []
19
+ }
20
+ };
21
+ //#endregion
22
+ export { TYPERT, TYPERT as default };
@@ -0,0 +1,89 @@
1
+ /** Shared wire vocabulary for inspecting and toggling one turn's text changes. */
2
+ /** One validated contextual diff hunk attached to a produced file. */
3
+ export interface ProducedFileDiff {
4
+ readonly path: string;
5
+ readonly oldText: string | null;
6
+ readonly newText: string;
7
+ readonly oldStart?: number | undefined;
8
+ readonly newStart?: number | undefined;
9
+ /**
10
+ * The engine reported that this hunk's old side did not exist, so the file was
11
+ * created in this turn.
12
+ *
13
+ * This is deliberately SEPARATE from `oldText === null`, which cannot carry
14
+ * the fact on its own: `null` also means "the prior content is not
15
+ * reconstructable", and `mutation-call.ts` synthesizes exactly that for a
16
+ * `write` overwrite, a `str_replace_editor insert` and an `edit` whose
17
+ * `old_string` is empty — all of which are edits to files that already
18
+ * existed. Only the two authoritative sources set this flag: the engine's
19
+ * `meta.diffs` (whose schema documents null as "None for new files") and the
20
+ * Host recorder's `before === null`.
21
+ */
22
+ readonly created?: true;
23
+ }
24
+ /** One produced file and the applied hunks available for review. */
25
+ export interface ProducedFileReview {
26
+ readonly path: string;
27
+ readonly diffs: readonly ProducedFileDiff[];
28
+ /**
29
+ * The turn's terminal commands deleted this path (dsh has no delete-file
30
+ * tool, so deletions arrive as parsed rm-family arguments). Deleted entries
31
+ * carry no hunks, no undo, and no openable file — review-display vocabulary
32
+ * only.
33
+ */
34
+ readonly deleted?: true;
35
+ }
36
+ /** Direction requested by the produced-files toggle. */
37
+ export type FileReviewAction = 'undo' | 'redo';
38
+ /** One turn-scoped file supplied to the Host toggle service. */
39
+ export interface FileReviewChange {
40
+ readonly path: string;
41
+ readonly diffs: readonly ProducedFileDiff[];
42
+ }
43
+ /** Host request for status inspection or one toggle direction. */
44
+ export interface FileReviewRequest {
45
+ readonly action: FileReviewAction;
46
+ readonly files: readonly FileReviewChange[];
47
+ }
48
+ /** Current relationship between a file and the recorded turn change. */
49
+ export type FileReviewFileState = 'applied' | 'undone' | 'conflict' | 'unsupported' | 'error';
50
+ /** Per-file result; a request never hides skipped or failed files. */
51
+ export interface FileReviewFileResult {
52
+ readonly path: string;
53
+ readonly state: FileReviewFileState;
54
+ readonly changed: boolean;
55
+ readonly reason?: string | undefined;
56
+ }
57
+ /** Complete result returned by both Host endpoints. */
58
+ export interface FileReviewResult {
59
+ readonly files: readonly FileReviewFileResult[];
60
+ }
61
+ /**
62
+ * One mutation a Code Mode `run_code` program dispatched to a file-editing
63
+ * tool, captured host-side with the FULL before/after content. The wire views
64
+ * (diff cards) only ride model-direct tool/call frames; nested dispatches
65
+ * carry neither a view nor hunks, so review of programmatic edits must
66
+ * reconstruct the diff from these two snapshots instead.
67
+ */
68
+ export interface RecordedMutation {
69
+ /** The `run_code` call that owns this dispatch (its `callId`). */
70
+ readonly rootCallId: string;
71
+ /** The dispatched tool name (`edit`, `write`, …). */
72
+ readonly name: string;
73
+ /** Display path the tool reported; resolved against the session cwd. */
74
+ readonly path: string;
75
+ /** Full file content before the mutation; `null` when the file was created. */
76
+ readonly before: string | null;
77
+ /** Full file content after the mutation. */
78
+ readonly after: string;
79
+ }
80
+ /** Host request for the recorded Code Mode mutations of one session. */
81
+ export interface RecordedRequest {
82
+ /** Root (`run_code`) call-ids whose recorded mutations are wanted. */
83
+ readonly rootCallIds: readonly string[];
84
+ }
85
+ /** Host response: every requested root's mutations, in dispatch order. */
86
+ export interface RecordedResult {
87
+ readonly mutations: readonly RecordedMutation[];
88
+ }
89
+ //# sourceMappingURL=change-types.d.ts.map
@@ -0,0 +1,20 @@
1
+ import type { Context } from '@deepseek-ai/cordis';
2
+ /** Tab component props (a narrowing of better-sidebar's TabComponentProps). */
3
+ export interface FileReviewTabProps {
4
+ readonly ctx: Context;
5
+ readonly sessionId: string;
6
+ readonly cwd: string | undefined;
7
+ /** Active tab + open panel; live status inspection pauses while false. */
8
+ readonly visible: boolean;
9
+ /**
10
+ * The sidebar tab handle. `meta.expandPaths` (string[]) is the deep link
11
+ * the chat turn-tail row writes via updateTab/openTab: a fresh meta
12
+ * reference replays as "expand those files' diffs and scroll to the first".
13
+ */
14
+ readonly tab: {
15
+ readonly meta?: unknown;
16
+ };
17
+ }
18
+ /** The sidebar tab body: per-turn change groups with inline diffs and undo. */
19
+ export declare function FileReviewTab({ ctx, sessionId, cwd, visible, tab }: FileReviewTabProps): import("react").JSX.Element;
20
+ //# sourceMappingURL=FileReviewTab.d.ts.map
@@ -0,0 +1,52 @@
1
+ /**
2
+ * The comparison surface: a faithful port of dsh's own FileDiff renderer.
3
+ *
4
+ * The sidebar review tab and the chat hover preview both draw this, so both look
5
+ * like the built-in comparison rather than a look-alike. Structure, class usage
6
+ * and the `data-diff-*` / `data-review-*` attributes match the native component
7
+ * (read out of the running app's asar) so the host's own styles, the chat card's
8
+ * preview rules, and anything else keying off those attributes keep working.
9
+ *
10
+ * Syntax highlighting rides the shared `useCodeHighlighter` from the primitives
11
+ * package — the same one the built-in diff uses — so grammars are loaded once for
12
+ * the whole app instead of per plugin.
13
+ */
14
+ import { type NativeDiffHunk } from './diff-hunks.ts';
15
+ /** Localized copy the comparison needs. */
16
+ export interface NativeDiffLabels {
17
+ readonly created: string;
18
+ readonly deleted: string;
19
+ readonly unchanged: string;
20
+ readonly truncated: (count: string) => string;
21
+ /** Shown while the comparison is still being resolved. */
22
+ readonly loading: string;
23
+ /** Shown when the two sides can no longer be reconstructed. */
24
+ readonly missing: string;
25
+ }
26
+ export interface NativeDiffProps {
27
+ readonly hunks: readonly NativeDiffHunk[];
28
+ /** Source path, used to pick the syntax grammar. */
29
+ readonly path: string;
30
+ /** Side-by-side when true (and the change is two-sided). */
31
+ readonly split: boolean;
32
+ /** Wrap long lines instead of scrolling them. */
33
+ readonly wrap: boolean;
34
+ /**
35
+ * Why the two sides differ in shape rather than content, when they do:
36
+ * 'created' and 'deleted' are native's own notes.
37
+ */
38
+ readonly note?: 'created' | 'deleted' | 'unchanged' | undefined;
39
+ /**
40
+ * Force one of native's non-content states instead of drawing hunks:
41
+ * 'loading' while the change is still being read, 'missing' when it is gone.
42
+ */
43
+ readonly status?: 'loading' | 'missing' | undefined;
44
+ readonly labels: NativeDiffLabels;
45
+ }
46
+ /**
47
+ * Render one file comparison.
48
+ * @param props - hunks, view mode, labels and the optional note.
49
+ * @returns The comparison body, in the layout the mode selects.
50
+ */
51
+ export declare function NativeDiff({ hunks, path, split, wrap, note, status, labels, }: NativeDiffProps): import("react").JSX.Element;
52
+ //# sourceMappingURL=NativeDiff.d.ts.map
@@ -0,0 +1,40 @@
1
+ import type { PropsLocale } from '@deepseek-ai/dsh-client-ui-slots';
2
+ import type { TurnTailOwnerProps } from '@deepseek-ai/dsh-client-ui-chat/client';
3
+ import type { FileReviewRequest, FileReviewResult } from '../change-types.ts';
4
+ import type { NS } from './chat-locales.ts';
5
+ /**
6
+ * Turn-tail owner currency plus the opener and locale supplied by the slot.
7
+ *
8
+ * dsh 0.2.0's `conversation.chat.turnTail` is a `list` slot, so there is no
9
+ * chain selector to receive a pre-matched value on: the component runs the
10
+ * claim test itself ({@link selectProducedFiles}) and renders nothing when the
11
+ * closing turn produced no files.
12
+ */
13
+ export type ProducedFilesProps = TurnTailOwnerProps & {
14
+ /** Session workspace root, used to resolve the hover preview's path label. */
15
+ projectRoot?: string | undefined;
16
+ /** Session key used to synchronize undo/redo state with the sidebar tab. */
17
+ reviewSessionId?: string | undefined;
18
+ inspectChanges?: (request: FileReviewRequest) => Promise<FileReviewResult>;
19
+ applyChanges?: (request: FileReviewRequest) => Promise<FileReviewResult>;
20
+ /**
21
+ * Open the plugin's sidebar tab with the given paths pre-expanded
22
+ * (the 审查 button passes every produced path; a file row passes its own).
23
+ * The owning turn number rides along so the tab expands only this turn's
24
+ * rows — a path that recurs in other turns stays collapsed there.
25
+ */
26
+ openInSidebarTab?: (paths: readonly string[], turn?: number) => void;
27
+ } & PropsLocale<typeof NS>;
28
+ /**
29
+ * Turn-tail list entry: claim the turn, then render the card.
30
+ *
31
+ * The claim test lives here rather than in a chain selector because
32
+ * `conversation.chat.turnTail` is an additive `list` in dsh 0.2.0. Splitting
33
+ * the test from the card keeps the card's hook order unconditional: the
34
+ * wrapper holds no hooks, so early-returning null for an unsettled turn can
35
+ * never change how many hooks the card below it calls.
36
+ * @param props - turn-tail owner currency plus the plugin's injected face.
37
+ * @returns the produced-files card, or null when this turn produced no files.
38
+ */
39
+ export declare function ProducedFiles(props: ProducedFilesProps): import("react").JSX.Element | null;
40
+ //# sourceMappingURL=ProducedFiles.d.ts.map