@whybebabo/dsh-file-review-tab 0.0.0-stage → 0.7.1
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 +22 -0
- package/README.md +134 -2
- package/cordis.patch.yml +6 -0
- package/lib/client.js +8386 -0
- package/lib/client.js.map +1 -0
- package/lib/index.js +373 -0
- package/lib/remote.js +8 -0
- package/lib/typert-descriptors.js +136 -0
- package/lib/typert.host.js +22 -0
- package/lib/types/change-types.d.ts +117 -0
- package/lib/types/client/FileReviewTab.d.ts +20 -0
- package/lib/types/client/NativeDiff.d.ts +52 -0
- package/lib/types/client/ProducedFiles.d.ts +40 -0
- package/lib/types/client/chat-locales.d.ts +66 -0
- package/lib/types/client/deep-link.d.ts +83 -0
- package/lib/types/client/deleted-paths.d.ts +28 -0
- package/lib/types/client/diff-hunks.d.ts +86 -0
- package/lib/types/client/diff-text.d.ts +8 -0
- package/lib/types/client/index.d.ts +43 -0
- package/lib/types/client/locales.d.ts +79 -0
- package/lib/types/client/mutation-call.d.ts +34 -0
- package/lib/types/client/recorded-diffs.d.ts +10 -0
- package/lib/types/client/recorded-fetch.d.ts +30 -0
- package/lib/types/client/session-changes.d.ts +110 -0
- package/lib/types/client/snapshot-compat.d.ts +32 -0
- package/lib/types/client/turn-deliverables.d.ts +91 -0
- package/lib/types/file-review-service.d.ts +22 -0
- package/lib/types/index.d.ts +26 -0
- package/lib/types/mutation-order.d.ts +111 -0
- package/lib/types/remote.d.ts +26 -0
- package/lib/types/typert-descriptors.d.ts +13 -0
- package/lib/types/typert.host.d.ts +5 -0
- package/package.json +141 -6
package/lib/index.js
ADDED
|
@@ -0,0 +1,373 @@
|
|
|
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/mutation-order.ts
|
|
6
|
+
/**
|
|
7
|
+
* Order settlements by their recorded event sequence, so undo/redo walk the
|
|
8
|
+
* file's history in the order it actually happened.
|
|
9
|
+
*
|
|
10
|
+
* This is what keeps a `run_code` mutation and a model-direct edit to the same
|
|
11
|
+
* file from being applied out of order: the two arrive through different
|
|
12
|
+
* channels (the conversation snapshot vs. the Host recorder) and are merged
|
|
13
|
+
* asynchronously, so the array order is a merge artifact rather than history.
|
|
14
|
+
*
|
|
15
|
+
* Only when EVERY entry carries a sequence is the order provable. A partially
|
|
16
|
+
* stamped list keeps its incoming order, which is the conservative choice —
|
|
17
|
+
* guessing at the position of an unstamped settlement could silently corrupt a
|
|
18
|
+
* file. The sort is stable, so entries sharing one sequence (a single
|
|
19
|
+
* `run_code` root's nested dispatch chain) keep their dispatch order.
|
|
20
|
+
*
|
|
21
|
+
* @param entries - Settlements or events carrying an optional `seq`.
|
|
22
|
+
* @returns A new array in ascending event order, or the same order when unprovable.
|
|
23
|
+
*/
|
|
24
|
+
function orderBySequence(entries) {
|
|
25
|
+
if (entries.some((entry) => entry.seq === void 0)) return [...entries];
|
|
26
|
+
return [...entries].sort((left, right) => left.seq - right.seq);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Split one path's hunks into contiguous same-coordinate groups, in settlement
|
|
30
|
+
* order. Hunks that carry no `mutation` form a single group.
|
|
31
|
+
* @param diffs - One path's accumulated hunks, in settlement order.
|
|
32
|
+
* @returns The groups, in settlement order.
|
|
33
|
+
*/
|
|
34
|
+
function mutationGroups(diffs) {
|
|
35
|
+
const groups = [];
|
|
36
|
+
let current = null;
|
|
37
|
+
let currentStamp;
|
|
38
|
+
for (const diff of diffs) {
|
|
39
|
+
if (current === null || diff.mutation !== currentStamp) {
|
|
40
|
+
current = [];
|
|
41
|
+
currentStamp = diff.mutation;
|
|
42
|
+
groups.push(current);
|
|
43
|
+
}
|
|
44
|
+
current.push(diff);
|
|
45
|
+
}
|
|
46
|
+
return groups;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The order one settlement's hunks must be applied in: back-to-front by the
|
|
50
|
+
* anchor of the direction being applied, because a hunk that changes the line
|
|
51
|
+
* count would otherwise shift the anchors of the hunks behind it. This is what
|
|
52
|
+
* makes a multi-hunk redo land on the coordinates the hunks recorded instead of
|
|
53
|
+
* the ones left over after the first hunk moved them.
|
|
54
|
+
*
|
|
55
|
+
* Hunks without a line anchor are content-matched and so coordinate-free; they
|
|
56
|
+
* sort after the anchored ones, where they cannot invalidate a pending anchor.
|
|
57
|
+
* @param group - One settlement's hunks.
|
|
58
|
+
* @param action - Direction being applied.
|
|
59
|
+
* @returns The hunks in application order (descending anchor).
|
|
60
|
+
*/
|
|
61
|
+
function hunksForApply(group, action) {
|
|
62
|
+
const anchorOf = (diff) => {
|
|
63
|
+
return (action === "undo" ? diff.newStart : diff.oldStart) ?? Number.NEGATIVE_INFINITY;
|
|
64
|
+
};
|
|
65
|
+
return [...group].sort((left, right) => anchorOf(right) - anchorOf(left));
|
|
66
|
+
}
|
|
67
|
+
//#endregion
|
|
68
|
+
//#region src/file-review-service.ts
|
|
69
|
+
/** Host-side, workspace-contained undo / redo service for produced text diffs. */
|
|
70
|
+
/**
|
|
71
|
+
* The mutation tools' recorded hunks (both diff cards and Code Mode
|
|
72
|
+
* before/after values) ride the filesystem backend's LF-normalized basis,
|
|
73
|
+
* while files on disk may use CRLF. All hunk matching therefore runs on the
|
|
74
|
+
* normalized text; the write path restores the file's own line-ending style.
|
|
75
|
+
*/
|
|
76
|
+
function normalizeNewlines(text) {
|
|
77
|
+
return text.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
78
|
+
}
|
|
79
|
+
function restoreNewlines(text, crlf) {
|
|
80
|
+
return crlf ? text.replace(/\n/g, "\r\n") : text;
|
|
81
|
+
}
|
|
82
|
+
function inside(root, candidate) {
|
|
83
|
+
const child = relative(root, candidate);
|
|
84
|
+
return child === "" || !child.startsWith("..") && !isAbsolute(child);
|
|
85
|
+
}
|
|
86
|
+
async function resolveFile(cwd, requestedPath) {
|
|
87
|
+
const root = await realpath(cwd);
|
|
88
|
+
const candidate = resolve(root, requestedPath);
|
|
89
|
+
if (!inside(root, candidate)) throw new Error("path is outside the session workspace");
|
|
90
|
+
const linkStat = await lstat(candidate);
|
|
91
|
+
if (linkStat.isSymbolicLink()) throw new Error("symbolic links are not supported");
|
|
92
|
+
if (!linkStat.isFile()) throw new Error("path is not a regular file");
|
|
93
|
+
const filename = await realpath(candidate);
|
|
94
|
+
if (!inside(root, filename)) throw new Error("resolved path is outside the session workspace");
|
|
95
|
+
const bytes = await readFile(filename);
|
|
96
|
+
const text = bytes.toString("utf8");
|
|
97
|
+
if (!Buffer.from(text, "utf8").equals(bytes)) throw new Error("file is not valid UTF-8 text");
|
|
98
|
+
const crlf = text.includes("\r");
|
|
99
|
+
return {
|
|
100
|
+
filename,
|
|
101
|
+
mode: linkStat.mode & 511,
|
|
102
|
+
bytes,
|
|
103
|
+
text,
|
|
104
|
+
crlf,
|
|
105
|
+
lfText: normalizeNewlines(text)
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
function offsetAtLine(text, line) {
|
|
109
|
+
if (!Number.isInteger(line) || line < 1) return null;
|
|
110
|
+
if (line === 1) return 0;
|
|
111
|
+
let offset = 0;
|
|
112
|
+
for (let current = 1; current < line; current += 1) {
|
|
113
|
+
const next = text.indexOf("\n", offset);
|
|
114
|
+
if (next === -1) return null;
|
|
115
|
+
offset = next + 1;
|
|
116
|
+
}
|
|
117
|
+
return offset;
|
|
118
|
+
}
|
|
119
|
+
function replaceHunk(text, source, replacement, line) {
|
|
120
|
+
let offset;
|
|
121
|
+
if (line !== void 0) {
|
|
122
|
+
const located = offsetAtLine(text, line);
|
|
123
|
+
if (located === null || text.slice(located, located + source.length) !== source) return null;
|
|
124
|
+
offset = located;
|
|
125
|
+
} else {
|
|
126
|
+
if (source === "") return null;
|
|
127
|
+
offset = text.indexOf(source);
|
|
128
|
+
if (offset === -1 || text.indexOf(source, offset + 1) !== -1) return null;
|
|
129
|
+
}
|
|
130
|
+
return text.slice(0, offset) + replacement + text.slice(offset + source.length);
|
|
131
|
+
}
|
|
132
|
+
function hunkSupported(diff, path) {
|
|
133
|
+
if (diff.path !== path || diff.oldText === null || diff.oldText === diff.newText) return false;
|
|
134
|
+
if (diff.oldText === "" && diff.oldStart === void 0) return false;
|
|
135
|
+
if (diff.newText === "" && diff.newStart === void 0) return false;
|
|
136
|
+
return true;
|
|
137
|
+
}
|
|
138
|
+
/** Apply a complete file's hunk sequence in memory, or report a strict mismatch. */
|
|
139
|
+
function transformFile(text, file, action) {
|
|
140
|
+
if (file.diffs.length === 0 || !file.diffs.every((diff) => hunkSupported(diff, file.path))) return null;
|
|
141
|
+
const groups = orderBySequence(mutationGroups(file.diffs).map((group) => ({
|
|
142
|
+
seq: group[0]?.seq,
|
|
143
|
+
diffs: group
|
|
144
|
+
}))).map((settlement) => settlement.diffs);
|
|
145
|
+
const ordered = action === "undo" ? [...groups].reverse() : groups;
|
|
146
|
+
let next = text;
|
|
147
|
+
for (const group of ordered) for (const diff of hunksForApply(group, action)) {
|
|
148
|
+
const source = action === "undo" ? diff.newText : diff.oldText;
|
|
149
|
+
const replacement = action === "undo" ? diff.oldText : diff.newText;
|
|
150
|
+
if (source === null || replacement === null) return null;
|
|
151
|
+
const changed = replaceHunk(next, source, replacement, action === "undo" ? diff.newStart : diff.oldStart);
|
|
152
|
+
if (changed === null) return null;
|
|
153
|
+
next = changed;
|
|
154
|
+
}
|
|
155
|
+
return next;
|
|
156
|
+
}
|
|
157
|
+
function hunkSidePresent(text, file, side) {
|
|
158
|
+
for (const diff of file.diffs) {
|
|
159
|
+
const source = side === "old" ? diff.oldText : diff.newText;
|
|
160
|
+
if (source === null) continue;
|
|
161
|
+
const line = side === "old" ? diff.oldStart : diff.newStart;
|
|
162
|
+
if (line !== void 0) {
|
|
163
|
+
const located = offsetAtLine(text, line);
|
|
164
|
+
if (located === null || text.slice(located, located + source.length) !== source) return false;
|
|
165
|
+
} else if (text.indexOf(source) === -1) return false;
|
|
166
|
+
}
|
|
167
|
+
return true;
|
|
168
|
+
}
|
|
169
|
+
function inspectText(text, file) {
|
|
170
|
+
if (file.diffs.length === 0 || !file.diffs.every((diff) => hunkSupported(diff, file.path))) return {
|
|
171
|
+
state: "unsupported",
|
|
172
|
+
reason: "change has no complete reversible diff"
|
|
173
|
+
};
|
|
174
|
+
const undone = transformFile(text, file, "undo");
|
|
175
|
+
const redone = transformFile(text, file, "redo");
|
|
176
|
+
if (undone !== null && redone !== null) return hunkSidePresent(text, file, "new") ? {
|
|
177
|
+
state: "applied",
|
|
178
|
+
text,
|
|
179
|
+
nextText: undone
|
|
180
|
+
} : {
|
|
181
|
+
state: "undone",
|
|
182
|
+
text,
|
|
183
|
+
nextText: redone
|
|
184
|
+
};
|
|
185
|
+
if (undone !== null) return {
|
|
186
|
+
state: "applied",
|
|
187
|
+
text,
|
|
188
|
+
nextText: undone
|
|
189
|
+
};
|
|
190
|
+
if (redone !== null) return {
|
|
191
|
+
state: "undone",
|
|
192
|
+
text,
|
|
193
|
+
nextText: redone
|
|
194
|
+
};
|
|
195
|
+
return {
|
|
196
|
+
state: "conflict",
|
|
197
|
+
reason: "current content does not match the recorded change"
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
async function inspectOne(cwd, file) {
|
|
201
|
+
if (file.diffs.length === 0 || !file.diffs.every((diff) => hunkSupported(diff, file.path))) return {
|
|
202
|
+
path: file.path,
|
|
203
|
+
state: "unsupported",
|
|
204
|
+
changed: false,
|
|
205
|
+
reason: "change has no complete reversible diff"
|
|
206
|
+
};
|
|
207
|
+
try {
|
|
208
|
+
const inspected = inspectText((await resolveFile(cwd, file.path)).lfText, file);
|
|
209
|
+
return {
|
|
210
|
+
path: file.path,
|
|
211
|
+
state: inspected.state,
|
|
212
|
+
changed: false,
|
|
213
|
+
reason: inspected.reason
|
|
214
|
+
};
|
|
215
|
+
} catch (error) {
|
|
216
|
+
return {
|
|
217
|
+
path: file.path,
|
|
218
|
+
state: "error",
|
|
219
|
+
changed: false,
|
|
220
|
+
reason: error instanceof Error ? error.message : String(error)
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
async function applyOne(cwd, file, action) {
|
|
225
|
+
if (file.diffs.length === 0 || !file.diffs.every((diff) => hunkSupported(diff, file.path))) return {
|
|
226
|
+
path: file.path,
|
|
227
|
+
state: "unsupported",
|
|
228
|
+
changed: false,
|
|
229
|
+
reason: "change has no complete reversible diff"
|
|
230
|
+
};
|
|
231
|
+
try {
|
|
232
|
+
const resolved = await resolveFile(cwd, file.path);
|
|
233
|
+
const inspected = inspectText(resolved.lfText, file);
|
|
234
|
+
const sourceState = action === "undo" ? "applied" : "undone";
|
|
235
|
+
const targetState = action === "undo" ? "undone" : "applied";
|
|
236
|
+
if (inspected.state === targetState) return {
|
|
237
|
+
path: file.path,
|
|
238
|
+
state: targetState,
|
|
239
|
+
changed: false
|
|
240
|
+
};
|
|
241
|
+
if (inspected.state !== sourceState || inspected.nextText === void 0) return {
|
|
242
|
+
path: file.path,
|
|
243
|
+
state: inspected.state,
|
|
244
|
+
changed: false,
|
|
245
|
+
reason: inspected.reason
|
|
246
|
+
};
|
|
247
|
+
const current = await readFile(resolved.filename);
|
|
248
|
+
if (!Buffer.from(resolved.bytes).equals(current)) return {
|
|
249
|
+
path: file.path,
|
|
250
|
+
state: "conflict",
|
|
251
|
+
changed: false,
|
|
252
|
+
reason: "file changed while the operation was being prepared"
|
|
253
|
+
};
|
|
254
|
+
await writeFileAtomic(resolved.filename, restoreNewlines(inspected.nextText, resolved.crlf), { mode: resolved.mode });
|
|
255
|
+
return {
|
|
256
|
+
path: file.path,
|
|
257
|
+
state: targetState,
|
|
258
|
+
changed: true
|
|
259
|
+
};
|
|
260
|
+
} catch (error) {
|
|
261
|
+
return {
|
|
262
|
+
path: file.path,
|
|
263
|
+
state: "error",
|
|
264
|
+
changed: false,
|
|
265
|
+
reason: error instanceof Error ? error.message : String(error)
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
function sessionCwd(agent) {
|
|
270
|
+
const cwd = agent.session.header.cwd;
|
|
271
|
+
if (cwd === void 0 || cwd.trim() === "") throw new Error("session has no workspace directory");
|
|
272
|
+
return cwd;
|
|
273
|
+
}
|
|
274
|
+
/** Per-agent cap on recorded Code Mode mutations (oldest evicted first). */
|
|
275
|
+
const RECORDED_PER_AGENT_CAP = 4e3;
|
|
276
|
+
function agentKey(agent) {
|
|
277
|
+
return String(agent.id);
|
|
278
|
+
}
|
|
279
|
+
/** Host service published as the `fileReview` Remote namespace. */
|
|
280
|
+
var FileReviewService = class extends TypertRemoteService {
|
|
281
|
+
/** Per-agent record of Code Mode (`run_code`) file mutations, dispatch order. */
|
|
282
|
+
recordLog = /* @__PURE__ */ new Map();
|
|
283
|
+
constructor(ctx) {
|
|
284
|
+
super(ctx, "fileReview");
|
|
285
|
+
}
|
|
286
|
+
/** Append one nested (Code Mode) file mutation for the receiving agent. */
|
|
287
|
+
recordMutation(agent, mutation) {
|
|
288
|
+
const key = agentKey(agent);
|
|
289
|
+
const list = this.recordLog.get(key);
|
|
290
|
+
if (list === void 0) {
|
|
291
|
+
this.recordLog.set(key, [mutation]);
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
list.push(mutation);
|
|
295
|
+
if (list.length > RECORDED_PER_AGENT_CAP) list.splice(0, list.length - RECORDED_PER_AGENT_CAP);
|
|
296
|
+
}
|
|
297
|
+
/** Return the recorded mutations for the requested `run_code` roots. */
|
|
298
|
+
async recorded(agent, request) {
|
|
299
|
+
const list = this.recordLog.get(agentKey(agent));
|
|
300
|
+
if (list === void 0 || request.rootCallIds.length === 0) return { mutations: [] };
|
|
301
|
+
const wanted = new Set(request.rootCallIds);
|
|
302
|
+
return { mutations: list.filter((mutation) => wanted.has(mutation.rootCallId)) };
|
|
303
|
+
}
|
|
304
|
+
/** Inspect current disk state without changing files. */
|
|
305
|
+
async status(agent, request) {
|
|
306
|
+
const cwd = sessionCwd(agent);
|
|
307
|
+
return { files: await Promise.all(request.files.map((file) => inspectOne(cwd, file))) };
|
|
308
|
+
}
|
|
309
|
+
/** Toggle every independently safe file while the receiving Agent is idle. */
|
|
310
|
+
async apply(agent, request) {
|
|
311
|
+
const cwd = sessionCwd(agent);
|
|
312
|
+
return agent.runMaintenance(async () => {
|
|
313
|
+
const files = [];
|
|
314
|
+
for (const file of request.files) files.push(await applyOne(cwd, file, request.action));
|
|
315
|
+
return { files };
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
};
|
|
319
|
+
//#endregion
|
|
320
|
+
//#region src/index.ts
|
|
321
|
+
/** Services required for the model guidance paired with the browser renderer. */
|
|
322
|
+
const inject = ["systemPrompt"];
|
|
323
|
+
/** Stable final-response guidance owned by the matching renderer. */
|
|
324
|
+
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.";
|
|
325
|
+
/**
|
|
326
|
+
* Register model guidance for the file-reference renderer shipped by this package,
|
|
327
|
+
* and the Code Mode (`run_code`) mutation recorder that backs the browser-side
|
|
328
|
+
* review tab.
|
|
329
|
+
*
|
|
330
|
+
* Nested dispatch results carry no wire views — the diff cards only ride
|
|
331
|
+
* model-direct tool/call frames — so reviewing programmatic file edits needs a
|
|
332
|
+
* second source: this listener snapshots the full `before`/`after` content of
|
|
333
|
+
* every nested file mutation (`edit`/`write` — recognized by result shape, not
|
|
334
|
+
* tool name) into the `fileReview` service, which the browser half later turns
|
|
335
|
+
* into line-level hunks and merges into the owning `run_code` turn.
|
|
336
|
+
* @param ctx - host context carrying the system-prompt registry and tool waterfall.
|
|
337
|
+
*/
|
|
338
|
+
function apply(ctx) {
|
|
339
|
+
const service = new FileReviewService(ctx);
|
|
340
|
+
ctx.systemPrompt.section({
|
|
341
|
+
name: "ui:file-review-references",
|
|
342
|
+
order: 190,
|
|
343
|
+
text: FILE_REFERENCE_PROMPT
|
|
344
|
+
});
|
|
345
|
+
const emitter = ctx;
|
|
346
|
+
ctx.effect(() => {
|
|
347
|
+
const off = emitter.on("tools/post-execute", async (execRaw, resultRaw, nextRaw) => {
|
|
348
|
+
const exec = execRaw;
|
|
349
|
+
const result = resultRaw;
|
|
350
|
+
const decision = await nextRaw();
|
|
351
|
+
if (decision.kind !== "accept") return decision;
|
|
352
|
+
if (exec.parent === void 0 || exec.agent === void 0) return decision;
|
|
353
|
+
const value = result.value;
|
|
354
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return decision;
|
|
355
|
+
const candidate = value;
|
|
356
|
+
if (typeof candidate.path !== "string" || typeof candidate.after !== "string") return decision;
|
|
357
|
+
if (candidate.before !== null && typeof candidate.before !== "string") return decision;
|
|
358
|
+
service.recordMutation(exec.agent, {
|
|
359
|
+
rootCallId: String(exec.rootCallId ?? exec.callId),
|
|
360
|
+
name: exec.name,
|
|
361
|
+
path: candidate.path,
|
|
362
|
+
before: candidate.before ?? null,
|
|
363
|
+
after: candidate.after
|
|
364
|
+
});
|
|
365
|
+
return decision;
|
|
366
|
+
});
|
|
367
|
+
return () => {
|
|
368
|
+
off();
|
|
369
|
+
};
|
|
370
|
+
}, "file-review-tab: ptc recorder");
|
|
371
|
+
}
|
|
372
|
+
//#endregion
|
|
373
|
+
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,136 @@
|
|
|
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
|
+
/** Coordinate space, so hunks from several settlements stay separable. */
|
|
41
|
+
mutation: z.number().int().min(0).optional(),
|
|
42
|
+
/** Event sequence, so settlements merge in the order they happened. */
|
|
43
|
+
seq: z.number().int().min(0).optional()
|
|
44
|
+
});
|
|
45
|
+
const requestSchema = z.object({
|
|
46
|
+
action: z.enum(["undo", "redo"]),
|
|
47
|
+
files: z.array(z.object({
|
|
48
|
+
path: z.string(),
|
|
49
|
+
diffs: z.array(diffSchema)
|
|
50
|
+
}))
|
|
51
|
+
});
|
|
52
|
+
const resultSchema = z.object({ files: z.array(z.object({
|
|
53
|
+
path: z.string(),
|
|
54
|
+
state: z.enum([
|
|
55
|
+
"applied",
|
|
56
|
+
"undone",
|
|
57
|
+
"conflict",
|
|
58
|
+
"unsupported",
|
|
59
|
+
"error"
|
|
60
|
+
]),
|
|
61
|
+
changed: z.boolean(),
|
|
62
|
+
reason: z.string().optional()
|
|
63
|
+
})) });
|
|
64
|
+
const agentCodec = strictCodec("@deepseek-ai/dsh-session/types#SessionId", () => z.intersection(z.string(), z.unknown()));
|
|
65
|
+
const requestCodec = strictCodec(`${PACKAGE_NAME}#FileReviewRequest`, () => requestSchema);
|
|
66
|
+
const resultCodec = strictCodec(`${PACKAGE_NAME}#FileReviewResult`, () => resultSchema);
|
|
67
|
+
const recordedMutationSchema = z.object({
|
|
68
|
+
rootCallId: z.string(),
|
|
69
|
+
name: z.string(),
|
|
70
|
+
path: z.string(),
|
|
71
|
+
before: z.string().nullable(),
|
|
72
|
+
after: z.string()
|
|
73
|
+
});
|
|
74
|
+
const recordedRequestSchema = z.object({ rootCallIds: z.array(z.string()) });
|
|
75
|
+
const recordedResultSchema = z.object({ mutations: z.array(recordedMutationSchema) });
|
|
76
|
+
const recordedRequestCodec = strictCodec(`${PACKAGE_NAME}#RecordedRequest`, () => recordedRequestSchema);
|
|
77
|
+
const recordedResultCodec = strictCodec(`${PACKAGE_NAME}#RecordedResult`, () => recordedResultSchema);
|
|
78
|
+
function descriptor(method) {
|
|
79
|
+
return {
|
|
80
|
+
id: `${PACKAGE_NAME}#fileReview/${method}`,
|
|
81
|
+
service: "fileReview",
|
|
82
|
+
namespace: "fileReview",
|
|
83
|
+
method,
|
|
84
|
+
invocation: { kind: "direct" },
|
|
85
|
+
scope: {
|
|
86
|
+
context: "agent",
|
|
87
|
+
wire: "agentId"
|
|
88
|
+
},
|
|
89
|
+
parameters: [{
|
|
90
|
+
name: "agent",
|
|
91
|
+
wire: "agentId",
|
|
92
|
+
source: "lookup",
|
|
93
|
+
lookup: "agent",
|
|
94
|
+
codec: agentCodec
|
|
95
|
+
}, {
|
|
96
|
+
name: "request",
|
|
97
|
+
wire: "request",
|
|
98
|
+
source: "json",
|
|
99
|
+
codec: requestCodec
|
|
100
|
+
}],
|
|
101
|
+
result: resultCodec
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
function recordedDescriptor() {
|
|
105
|
+
return {
|
|
106
|
+
id: `${PACKAGE_NAME}#fileReview/recorded`,
|
|
107
|
+
service: "fileReview",
|
|
108
|
+
namespace: "fileReview",
|
|
109
|
+
method: "recorded",
|
|
110
|
+
invocation: { kind: "direct" },
|
|
111
|
+
scope: {
|
|
112
|
+
context: "agent",
|
|
113
|
+
wire: "agentId"
|
|
114
|
+
},
|
|
115
|
+
parameters: [{
|
|
116
|
+
name: "agent",
|
|
117
|
+
wire: "agentId",
|
|
118
|
+
source: "lookup",
|
|
119
|
+
lookup: "agent",
|
|
120
|
+
codec: agentCodec
|
|
121
|
+
}, {
|
|
122
|
+
name: "request",
|
|
123
|
+
wire: "request",
|
|
124
|
+
source: "json",
|
|
125
|
+
codec: recordedRequestCodec
|
|
126
|
+
}],
|
|
127
|
+
result: recordedResultCodec
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
const FILE_REVIEW_INVOCATIONS = [
|
|
131
|
+
descriptor("status"),
|
|
132
|
+
descriptor("apply"),
|
|
133
|
+
recordedDescriptor()
|
|
134
|
+
];
|
|
135
|
+
//#endregion
|
|
136
|
+
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,117 @@
|
|
|
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
|
+
* Coordinate space this hunk's `oldStart`/`newStart` are expressed in.
|
|
25
|
+
*
|
|
26
|
+
* One path mutated several times in one turn accumulates hunks from several
|
|
27
|
+
* settlements, and each settlement's line numbers refer to the text the
|
|
28
|
+
* PREVIOUS settlement left behind — they are not interchangeable. Hunks
|
|
29
|
+
* sharing this stamp are anchored in the same text and must be applied
|
|
30
|
+
* back-to-front within it; groups apply in settlement order forward and in
|
|
31
|
+
* reverse order backward (see `mutation-order.ts`).
|
|
32
|
+
*
|
|
33
|
+
* Optional: absent means "all of this path's hunks share one coordinate
|
|
34
|
+
* space", the correct reading for the single-settlement payloads that
|
|
35
|
+
* predate the field.
|
|
36
|
+
*/
|
|
37
|
+
readonly mutation?: number | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* Event sequence this settlement happened at, used to order settlements.
|
|
40
|
+
*
|
|
41
|
+
* A file's history can be split across two channels — the conversation
|
|
42
|
+
* snapshot (model-direct `edit`/`write`) and the Host recorder (nested
|
|
43
|
+
* `run_code` dispatches) — which the tab merges asynchronously. Array order is
|
|
44
|
+
* therefore a merge artifact, not history; this sequence is what restores the
|
|
45
|
+
* real order. For a snapshot settlement it is the tool-result node's `seq`,
|
|
46
|
+
* and for a recorded one the owning `run_code` root's `seq`.
|
|
47
|
+
*
|
|
48
|
+
* Optional: when absent the order is not provable and the array order stands.
|
|
49
|
+
*/
|
|
50
|
+
readonly seq?: number | undefined;
|
|
51
|
+
}
|
|
52
|
+
/** One produced file and the applied hunks available for review. */
|
|
53
|
+
export interface ProducedFileReview {
|
|
54
|
+
readonly path: string;
|
|
55
|
+
readonly diffs: readonly ProducedFileDiff[];
|
|
56
|
+
/**
|
|
57
|
+
* The turn's terminal commands deleted this path (dsh has no delete-file
|
|
58
|
+
* tool, so deletions arrive as parsed rm-family arguments). Deleted entries
|
|
59
|
+
* carry no hunks, no undo, and no openable file — review-display vocabulary
|
|
60
|
+
* only.
|
|
61
|
+
*/
|
|
62
|
+
readonly deleted?: true;
|
|
63
|
+
}
|
|
64
|
+
/** Direction requested by the produced-files toggle. */
|
|
65
|
+
export type FileReviewAction = 'undo' | 'redo';
|
|
66
|
+
/** One turn-scoped file supplied to the Host toggle service. */
|
|
67
|
+
export interface FileReviewChange {
|
|
68
|
+
readonly path: string;
|
|
69
|
+
readonly diffs: readonly ProducedFileDiff[];
|
|
70
|
+
}
|
|
71
|
+
/** Host request for status inspection or one toggle direction. */
|
|
72
|
+
export interface FileReviewRequest {
|
|
73
|
+
readonly action: FileReviewAction;
|
|
74
|
+
readonly files: readonly FileReviewChange[];
|
|
75
|
+
}
|
|
76
|
+
/** Current relationship between a file and the recorded turn change. */
|
|
77
|
+
export type FileReviewFileState = 'applied' | 'undone' | 'conflict' | 'unsupported' | 'error';
|
|
78
|
+
/** Per-file result; a request never hides skipped or failed files. */
|
|
79
|
+
export interface FileReviewFileResult {
|
|
80
|
+
readonly path: string;
|
|
81
|
+
readonly state: FileReviewFileState;
|
|
82
|
+
readonly changed: boolean;
|
|
83
|
+
readonly reason?: string | undefined;
|
|
84
|
+
}
|
|
85
|
+
/** Complete result returned by both Host endpoints. */
|
|
86
|
+
export interface FileReviewResult {
|
|
87
|
+
readonly files: readonly FileReviewFileResult[];
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* One mutation a Code Mode `run_code` program dispatched to a file-editing
|
|
91
|
+
* tool, captured host-side with the FULL before/after content. The wire views
|
|
92
|
+
* (diff cards) only ride model-direct tool/call frames; nested dispatches
|
|
93
|
+
* carry neither a view nor hunks, so review of programmatic edits must
|
|
94
|
+
* reconstruct the diff from these two snapshots instead.
|
|
95
|
+
*/
|
|
96
|
+
export interface RecordedMutation {
|
|
97
|
+
/** The `run_code` call that owns this dispatch (its `callId`). */
|
|
98
|
+
readonly rootCallId: string;
|
|
99
|
+
/** The dispatched tool name (`edit`, `write`, …). */
|
|
100
|
+
readonly name: string;
|
|
101
|
+
/** Display path the tool reported; resolved against the session cwd. */
|
|
102
|
+
readonly path: string;
|
|
103
|
+
/** Full file content before the mutation; `null` when the file was created. */
|
|
104
|
+
readonly before: string | null;
|
|
105
|
+
/** Full file content after the mutation. */
|
|
106
|
+
readonly after: string;
|
|
107
|
+
}
|
|
108
|
+
/** Host request for the recorded Code Mode mutations of one session. */
|
|
109
|
+
export interface RecordedRequest {
|
|
110
|
+
/** Root (`run_code`) call-ids whose recorded mutations are wanted. */
|
|
111
|
+
readonly rootCallIds: readonly string[];
|
|
112
|
+
}
|
|
113
|
+
/** Host response: every requested root's mutations, in dispatch order. */
|
|
114
|
+
export interface RecordedResult {
|
|
115
|
+
readonly mutations: readonly RecordedMutation[];
|
|
116
|
+
}
|
|
117
|
+
//# 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
|