@whybebabo/dsh-file-review-tab 0.7.0 → 0.7.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.md +27 -16
- package/lib/client.js +865 -166
- package/lib/client.js.map +1 -1
- package/lib/index.js +258 -27
- package/lib/typert-descriptors.js +60 -2
- package/lib/types/anchor-locate.d.ts +35 -0
- package/lib/types/change-types.d.ts +98 -0
- package/lib/types/client/ProducedFiles.d.ts +10 -1
- package/lib/types/client/deep-link.d.ts +45 -0
- package/lib/types/client/diff-hunks.d.ts +15 -4
- package/lib/types/client/hunk-anchors.d.ts +81 -0
- package/lib/types/client/recorded-fetch.d.ts +30 -0
- package/lib/types/client/session-changes.d.ts +40 -6
- package/lib/types/file-review-service.d.ts +34 -1
- package/lib/types/hunk-anchors.d.ts +33 -0
- package/lib/types/index.d.ts +17 -9
- package/lib/types/mutation-order.d.ts +111 -0
- package/lib/types/remote.d.ts +4 -1
- package/lib/types/reversible.d.ts +35 -0
- package/package.json +16 -16
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* trimming context the same way, so a one-line edit in a long file renders as one
|
|
12
12
|
* small hunk instead of the whole file.
|
|
13
13
|
*/
|
|
14
|
-
import type { ProducedFileDiff } from '../change-types.ts';
|
|
14
|
+
import type { HunkAnchor, ProducedFileDiff } from '../change-types.ts';
|
|
15
15
|
/** How one drawn line relates to the two sides of the comparison. */
|
|
16
16
|
export type DiffLineKind = 'context' | 'del' | 'add';
|
|
17
17
|
/** One line of a comparison, already numbered against both sides. */
|
|
@@ -41,8 +41,16 @@ export interface NativeDiffHunk {
|
|
|
41
41
|
}
|
|
42
42
|
/** Whether a comparison touches only one side, which forces the unified view. */
|
|
43
43
|
export declare function isOneSided(hunks: readonly NativeDiffHunk[]): boolean;
|
|
44
|
-
/**
|
|
45
|
-
|
|
44
|
+
/**
|
|
45
|
+
* Pair one recorded before/after snapshot into numbered lines.
|
|
46
|
+
*
|
|
47
|
+
* `anchor` overrides where the pairing starts. The wire hunks the conversation
|
|
48
|
+
* snapshot carries are context fragments with no line numbers at all, so without
|
|
49
|
+
* an anchor their numbering can only start at 1 — a per-hunk counter, not the
|
|
50
|
+
* file's lines. The Host knows each mutation's real coordinates (see
|
|
51
|
+
* {@link HunkAnchor}) and this is where they enter the drawing.
|
|
52
|
+
*/
|
|
53
|
+
export declare function pairLines(diff: ProducedFileDiff, anchor?: HunkAnchor | undefined): DiffLine[];
|
|
46
54
|
/** Count added and removed lines using the viewer's exact line-diff algorithm. */
|
|
47
55
|
export declare function summarizeDiffs(diffs: readonly ProducedFileDiff[]): DiffStats;
|
|
48
56
|
/**
|
|
@@ -74,13 +82,16 @@ export declare function diffNote(diffs: readonly ProducedFileDiff[], hunks: read
|
|
|
74
82
|
* @returns the copy to show.
|
|
75
83
|
*/
|
|
76
84
|
export declare function missingMessage(deleted: boolean, deletedHint: string, missing: string): string;
|
|
85
|
+
/** Recorded coordinates by the call that applied them. */
|
|
86
|
+
export type HunkAnchorLookup = ReadonlyMap<string, readonly HunkAnchor[]>;
|
|
77
87
|
/**
|
|
78
88
|
* Convert recorded comparisons into dsh's served hunk shape.
|
|
79
89
|
* @param diffs - the recorded before/after snapshots for one file.
|
|
80
90
|
* @param contextLines - unchanged lines kept on each side of a change.
|
|
91
|
+
* @param anchors - recorded absolute coordinates by call id, when known.
|
|
81
92
|
* @returns the hunks to render, in order.
|
|
82
93
|
*/
|
|
83
|
-
export declare function toNativeHunks(diffs: readonly ProducedFileDiff[], contextLines?: number): NativeDiffHunk[];
|
|
94
|
+
export declare function toNativeHunks(diffs: readonly ProducedFileDiff[], contextLines?: number, anchors?: HunkAnchorLookup | undefined): NativeDiffHunk[];
|
|
84
95
|
/** Serialize recorded hunks as one plain-text unified diff. */
|
|
85
96
|
export declare function nativeDiffText(hunks: readonly NativeDiffHunk[]): string;
|
|
86
97
|
//# sourceMappingURL=diff-hunks.d.ts.map
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client cache and hook for the Host's per-mutation hunk coordinates.
|
|
3
|
+
*
|
|
4
|
+
* The comparison surfaces read the conversation snapshot, and its hunks are the
|
|
5
|
+
* engine's context fragments — text only, no line numbers. Numbering those from
|
|
6
|
+
* 1 puts a change at the end of a long file on "line 1". The Host recorded each
|
|
7
|
+
* mutation's real coordinates at settlement (see the node half's hunk-anchors
|
|
8
|
+
* module); this module fetches them once per session and hands them to the
|
|
9
|
+
* renderer.
|
|
10
|
+
*
|
|
11
|
+
* Deliberately a cache rather than view state: a call's coordinates never change
|
|
12
|
+
* once recorded, so the sidebar tab, a chat hover preview and every remount reuse
|
|
13
|
+
* the same answer. Only the FIRST lookup of a call id costs a round trip, and a
|
|
14
|
+
* call the recorder never saw stays marked as asked — a session whose mutations
|
|
15
|
+
* happened outside the tool pipeline must not turn every render into a request.
|
|
16
|
+
*/
|
|
17
|
+
import type { AnchorCall, RecordedAnchor } from '../change-types.ts';
|
|
18
|
+
import type { ProducedFileDiff } from '../change-types.ts';
|
|
19
|
+
import type { HunkAnchorLookup } from './diff-hunks.ts';
|
|
20
|
+
/**
|
|
21
|
+
* Group one file's hunks into the calls that produced them.
|
|
22
|
+
*
|
|
23
|
+
* Fragments of a call are consecutive and keep the engine's hunk order, so this
|
|
24
|
+
* both names the calls to ask about and supplies the text the Host needs to place
|
|
25
|
+
* a hunk whose coordinates were never recorded. Hunks without a call id (the
|
|
26
|
+
* recorded Code Mode path, which already carries coordinates) are skipped.
|
|
27
|
+
* @param diffs - the file's hunks, in settlement order.
|
|
28
|
+
* @returns one entry per call, in first-seen order.
|
|
29
|
+
*/
|
|
30
|
+
export declare function anchorCalls(diffs: readonly ProducedFileDiff[]): AnchorCall[];
|
|
31
|
+
/**
|
|
32
|
+
* Coordinates remembered for one session, as the lookup the renderer takes.
|
|
33
|
+
* @param sessionId - the session whose anchors are wanted.
|
|
34
|
+
* @returns the cached map (empty before any lookup completes).
|
|
35
|
+
*/
|
|
36
|
+
export declare function cachedHunkAnchors(sessionId: string): HunkAnchorLookup;
|
|
37
|
+
/** Merge a Host answer into the cache and return the new lookup. */
|
|
38
|
+
export declare function rememberHunkAnchors(sessionId: string, entries: readonly RecordedAnchor[]): HunkAnchorLookup;
|
|
39
|
+
/**
|
|
40
|
+
* Drop a session's cache. Called when a session is disposed: a later session can
|
|
41
|
+
* reuse neither the id nor the call ids.
|
|
42
|
+
* @param sessionId - the session leaving.
|
|
43
|
+
*/
|
|
44
|
+
export declare function forgetHunkAnchors(sessionId: string): void;
|
|
45
|
+
/**
|
|
46
|
+
* Claim the ids that still need a lookup, marking them as asked.
|
|
47
|
+
*
|
|
48
|
+
* Claiming before the request is what stops two surfaces painting the same hunk
|
|
49
|
+
* in one commit from fetching it twice. An id marked this way is never asked
|
|
50
|
+
* again unless {@link releaseCallIds} returns it: a call the recorder never saw
|
|
51
|
+
* answers successfully with no coordinates, and that must not become a request
|
|
52
|
+
* per render.
|
|
53
|
+
* @param sessionId - session key for the shared cache.
|
|
54
|
+
* @param callIds - the calls the painted hunks came from.
|
|
55
|
+
* @returns the ids to ask about now; empty when nothing new is wanted.
|
|
56
|
+
*/
|
|
57
|
+
export declare function claimCallIds(sessionId: string, callIds: readonly string[]): string[];
|
|
58
|
+
/**
|
|
59
|
+
* Un-claim ids whose lookup failed.
|
|
60
|
+
*
|
|
61
|
+
* A thrown lookup is NOT the Host saying "this call has no coordinates" — it is
|
|
62
|
+
* the Host not answering (an unmounted Remote, a transport error). Releasing the
|
|
63
|
+
* ids is what lets a later attempt (new hunks, a now-visible tab, a remount) ask
|
|
64
|
+
* again instead of leaving those hunks permanently unanchored.
|
|
65
|
+
* @param sessionId - session key for the shared cache.
|
|
66
|
+
* @param callIds - the ids whose request failed.
|
|
67
|
+
*/
|
|
68
|
+
export declare function releaseCallIds(sessionId: string, callIds: readonly string[]): void;
|
|
69
|
+
/**
|
|
70
|
+
* Coordinates for the calls a set of painted hunks came from, fetched on demand.
|
|
71
|
+
*
|
|
72
|
+
* Call it unconditionally from the component that draws the hunks; the request
|
|
73
|
+
* lives in an effect, so a surface that never paints a diff never asks the Host.
|
|
74
|
+
* @param sessionId - session key for the shared cache.
|
|
75
|
+
* @param callIds - the calls the painted hunks came from, in any order.
|
|
76
|
+
* @param load - Host lookup; undefined while the Remote is unavailable.
|
|
77
|
+
* @param enabled - false pauses the lookup (a hidden tab, a closed preview).
|
|
78
|
+
* @returns the lookup `toNativeHunks` takes.
|
|
79
|
+
*/
|
|
80
|
+
export declare function useHunkAnchors(sessionId: string, callIds: readonly string[], load: ((ids: readonly string[]) => Promise<readonly RecordedAnchor[]>) | undefined, enabled?: boolean): HunkAnchorLookup;
|
|
81
|
+
//# sourceMappingURL=hunk-anchors.d.ts.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pacing for the client's `recorded` (Code Mode mutation) fetch.
|
|
3
|
+
*
|
|
4
|
+
* The fetch re-arms whenever a root's settled-dispatch count changes, and a busy
|
|
5
|
+
* `run_code` can change it rapidly. Two ways to get that wrong, both of which
|
|
6
|
+
* leave the tab showing only the mutations recorded before it first looked:
|
|
7
|
+
*
|
|
8
|
+
* - Debouncing from each update (restarting the timer whenever one arrives)
|
|
9
|
+
* pushes the fetch out for as long as updates keep coming.
|
|
10
|
+
* - Anchoring on "the last fetch" alone starves the FIRST fetch: while updates
|
|
11
|
+
* keep arriving, no fetch has completed, so the anchor never exists and the
|
|
12
|
+
* window is re-armed forever.
|
|
13
|
+
*
|
|
14
|
+
* So the delay is always measured from a real instant — the last fetch, or the
|
|
15
|
+
* moment the fetch was first armed when none has completed yet. An update can
|
|
16
|
+
* then only ever schedule the next fetch for `anchor + interval`, and nothing an
|
|
17
|
+
* update does can push it later.
|
|
18
|
+
*/
|
|
19
|
+
/** Minimum gap between two `recorded` fetches, in milliseconds. */
|
|
20
|
+
export declare const RECORDED_FETCH_INTERVAL = 200;
|
|
21
|
+
/**
|
|
22
|
+
* Delay before the next `recorded` fetch.
|
|
23
|
+
* @param anchor - Timestamp of the last completed fetch, or of the moment the
|
|
24
|
+
* fetch was first armed when none has completed yet. Must never be a value that
|
|
25
|
+
* an incoming update can reset, or the fetch starves.
|
|
26
|
+
* @param now - Current timestamp.
|
|
27
|
+
* @returns Milliseconds to wait; 0 once the interval has already elapsed.
|
|
28
|
+
*/
|
|
29
|
+
export declare function recordedFetchDelay(anchor: number, now: number): number;
|
|
30
|
+
//# sourceMappingURL=recorded-fetch.d.ts.map
|
|
@@ -19,6 +19,13 @@ export interface SessionFileChange {
|
|
|
19
19
|
readonly diffs: readonly ProducedFileDiff[];
|
|
20
20
|
/** Terminal commands deleted this path in this turn (display-only). */
|
|
21
21
|
readonly deleted?: true;
|
|
22
|
+
/**
|
|
23
|
+
* Event sequence the pending deletion happened at. A deletion is an event, so
|
|
24
|
+
* a cross-channel write with a LATER sequence proves the path was recreated
|
|
25
|
+
* and clears the flag. Absent when the snapshot omitted the sequence, in which
|
|
26
|
+
* case the deletion is kept (the conservative reading).
|
|
27
|
+
*/
|
|
28
|
+
readonly deletedSeq?: number | undefined;
|
|
22
29
|
}
|
|
23
30
|
/** One turn's produced files, in first-seen order. */
|
|
24
31
|
export interface TurnFileChanges {
|
|
@@ -40,17 +47,44 @@ export interface SessionRoot {
|
|
|
40
47
|
readonly turn: number;
|
|
41
48
|
readonly live: boolean;
|
|
42
49
|
readonly rootCallId: string;
|
|
50
|
+
/**
|
|
51
|
+
* The root node's event sequence, or undefined when the snapshot omitted it.
|
|
52
|
+
* A recorded mutation is a nested dispatch of this root, so this is the
|
|
53
|
+
* sequence its changes are ordered by — it is what lets a `run_code` edit be
|
|
54
|
+
* merged into the right position among the turn's model-direct edits. When it
|
|
55
|
+
* is unknown the merge keeps array order rather than guessing.
|
|
56
|
+
*/
|
|
57
|
+
readonly seq: number | undefined;
|
|
58
|
+
/**
|
|
59
|
+
* How many nested dispatches of this root have SETTLED so far.
|
|
60
|
+
*
|
|
61
|
+
* The Host recorder keeps appending mutations under the SAME `rootCallId`
|
|
62
|
+
* while a long `run_code` runs, so a call-id-only dependency would never
|
|
63
|
+
* re-arm the client's `recorded` fetch: the tab would show only the mutations
|
|
64
|
+
* that landed before its first fetch. A nested dispatch settles exactly when
|
|
65
|
+
* the recorder sees it, so this count grows with the recorded data and gives
|
|
66
|
+
* the fetch a dependency that tracks it.
|
|
67
|
+
*/
|
|
68
|
+
readonly progress: number;
|
|
43
69
|
}
|
|
44
70
|
/** Every `run_code` tool-result node whose nested changes are not in the snapshot. */
|
|
45
71
|
export declare function deriveSessionRoots(snapshot: ConversationSnapshot): SessionRoot[];
|
|
46
72
|
/**
|
|
47
73
|
* Merge Host-recorded Code Mode mutations into the snapshot-derived turns:
|
|
48
|
-
* hunks rebuilt from the full before/after are
|
|
49
|
-
* file groups
|
|
50
|
-
*
|
|
51
|
-
* programmatic edits exactly like model-direct ones.
|
|
52
|
-
*
|
|
53
|
-
*
|
|
74
|
+
* hunks rebuilt from the full before/after are inserted into the owning turn's
|
|
75
|
+
* file groups at the position their EVENT SEQUENCE puts them (same-path entries
|
|
76
|
+
* stay one row), so the tab's diff rendering, status inspection and undo all
|
|
77
|
+
* work on programmatic edits exactly like model-direct ones.
|
|
78
|
+
*
|
|
79
|
+
* Ordering is by sequence rather than "snapshot first, recorded after": the two
|
|
80
|
+
* sources are separate channels merged asynchronously, so appending recorded
|
|
81
|
+
* mutations could invert them. A `run_code` insert at the top of a file followed
|
|
82
|
+
* by a model-direct edit near its end must replay in that order — reversed, the
|
|
83
|
+
* rear edit's line anchors describe text the front insert already shifted, and
|
|
84
|
+
* BOTH undo and redo fail on a file that was perfectly reviewable.
|
|
85
|
+
*
|
|
86
|
+
* All inputs are immutable; the result is a fresh array only when a recorded
|
|
87
|
+
* mutation matched a visible root.
|
|
54
88
|
*/
|
|
55
89
|
export declare function mergeRecordedTurns(turns: readonly TurnFileChanges[], roots: readonly SessionRoot[], recorded: readonly RecordedMutation[]): readonly TurnFileChanges[];
|
|
56
90
|
/** Count distinct changed paths across every turn (the sidebar badge count). */
|
|
@@ -2,16 +2,49 @@
|
|
|
2
2
|
import type { Context } from '@deepseek-ai/cordis';
|
|
3
3
|
import type { Agent } from '@deepseek-ai/dsh-agent';
|
|
4
4
|
import { TypertRemoteService } from '@deepseek-ai/dsh-typert-protocol';
|
|
5
|
-
import type { FileReviewAction, FileReviewChange, FileReviewRequest, FileReviewResult, RecordedMutation, RecordedRequest, RecordedResult } from './change-types.ts';
|
|
5
|
+
import type { AnchorRequest, AnchorResult, FileReviewAction, FileReviewChange, FileReviewRequest, FileReviewResult, RecordedAnchor, RecordedMutation, RecordedRequest, RecordedResult } from './change-types.ts';
|
|
6
6
|
/** Apply a complete file's hunk sequence in memory, or report a strict mismatch. */
|
|
7
7
|
export declare function transformFile(text: string, file: FileReviewChange, action: FileReviewAction): string | null;
|
|
8
8
|
/** Host service published as the `fileReview` Remote namespace. */
|
|
9
9
|
export declare class FileReviewService extends TypertRemoteService {
|
|
10
10
|
/** Per-agent record of Code Mode (`run_code`) file mutations, dispatch order. */
|
|
11
11
|
private readonly recordLog;
|
|
12
|
+
/**
|
|
13
|
+
* Per-agent map of call id to the hunk coordinates that call applied.
|
|
14
|
+
*
|
|
15
|
+
* Keyed by call id alone: a mutation call writes one path, so the id already
|
|
16
|
+
* names the settlement the anchors belong to. Re-recording an id replaces its
|
|
17
|
+
* entry (a replay never duplicates), and insertion order is what the cap
|
|
18
|
+
* evicts by.
|
|
19
|
+
*/
|
|
20
|
+
private readonly anchorLog;
|
|
12
21
|
constructor(ctx: Context);
|
|
13
22
|
/** Append one nested (Code Mode) file mutation for the receiving agent. */
|
|
14
23
|
recordMutation(agent: Agent, mutation: RecordedMutation): void;
|
|
24
|
+
/**
|
|
25
|
+
* Record one mutation's hunk coordinates, model-direct calls included.
|
|
26
|
+
*
|
|
27
|
+
* Called from `tools/post-execute` for every settled file mutation — that hook
|
|
28
|
+
* is the last place the full before/after text exists, and therefore the only
|
|
29
|
+
* place a hunk's absolute line numbers can still be recovered once the engine
|
|
30
|
+
* has trimmed it down to context fragments.
|
|
31
|
+
* @param agent - the agent that ran the mutation.
|
|
32
|
+
* @param entry - the call id, path and per-hunk coordinates.
|
|
33
|
+
*/
|
|
34
|
+
recordAnchors(agent: Agent, entry: RecordedAnchor): void;
|
|
35
|
+
/**
|
|
36
|
+
* Coordinates for the requested mutation calls.
|
|
37
|
+
*
|
|
38
|
+
* Two sources, in order. A call the recorder saw answers with the coordinates
|
|
39
|
+
* captured at settlement — exact, and immune to later edits. A call it did not
|
|
40
|
+
* (the plugin was installed or restarted after the change) is placed in the
|
|
41
|
+
* file as it stands now, which is where the reviewer wants to look anyway, and
|
|
42
|
+
* only when every one of its fragments matches exactly one place in the file.
|
|
43
|
+
* A call that resolves neither way is simply absent: the client keeps that
|
|
44
|
+
* hunk's fragment-relative count, so a missing entry can only cost the
|
|
45
|
+
* improvement, never the diff itself.
|
|
46
|
+
*/
|
|
47
|
+
anchors(agent: Agent, request: AnchorRequest): Promise<AnchorResult>;
|
|
15
48
|
/** Return the recorded mutations for the requested `run_code` roots. */
|
|
16
49
|
recorded(agent: Agent, request: RecordedRequest): Promise<RecordedResult>;
|
|
17
50
|
/** Inspect current disk state without changing files. */
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Absolute hunk coordinates for one settled file mutation.
|
|
3
|
+
*
|
|
4
|
+
* The review surfaces can only ever draw what the conversation snapshot carries,
|
|
5
|
+
* and that is the engine's `meta.diffs`: one context-trimmed fragment pair per
|
|
6
|
+
* applied hunk, with no line numbers in it ({@link FileDiff} is `path` +
|
|
7
|
+
* `oldText` + `newText`). Numbering those fragments from 1 — the only reading
|
|
8
|
+
* the payload allows on its own — invents a per-hunk counter and puts a change
|
|
9
|
+
* near the end of a file on "line 1".
|
|
10
|
+
*
|
|
11
|
+
* At settlement, though, the tool has already handed back the mutation's full
|
|
12
|
+
* before/after text, so this module recomputes the very same patch the engine
|
|
13
|
+
* used (`structuredPatch` over the two sides, {@link ANCHOR_CONTEXT} context
|
|
14
|
+
* lines — dsh-tool-fs's `computeHunkDiffs` is exactly this call) and keeps only
|
|
15
|
+
* each hunk's starting coordinates. The fragment list therefore lines up with
|
|
16
|
+
* the engine's one-for-one, while the payload stays a couple of integers per
|
|
17
|
+
* hunk instead of a second copy of the file.
|
|
18
|
+
*/
|
|
19
|
+
import type { HunkAnchor } from './change-types.ts';
|
|
20
|
+
/**
|
|
21
|
+
* Context lines around each change. dsh-tool-fs's `DIFF_CONTEXT` — the value the
|
|
22
|
+
* engine's own hunk fragments were trimmed with, which is what makes the anchor
|
|
23
|
+
* list and the `meta.diffs` fragment list the same length.
|
|
24
|
+
*/
|
|
25
|
+
export declare const ANCHOR_CONTEXT = 3;
|
|
26
|
+
/**
|
|
27
|
+
* Hunk coordinates for one mutation, in the engine's hunk order.
|
|
28
|
+
* @param before - file text before the mutation, or null when it did not exist.
|
|
29
|
+
* @param after - file text after the mutation.
|
|
30
|
+
* @returns one anchor per applied hunk; empty when the texts do not differ.
|
|
31
|
+
*/
|
|
32
|
+
export declare function hunkAnchors(before: string | null, after: string): HunkAnchor[];
|
|
33
|
+
//# sourceMappingURL=hunk-anchors.d.ts.map
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,18 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* File-review-tab plugin, node half.
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
2
|
+
* File-review-tab plugin, node half. Records every settled file mutation's full
|
|
3
|
+
* before/after text so the browser half can review Code Mode (`run_code`)
|
|
4
|
+
* dispatches, and stamps each mutation call with the hunk coordinates that let
|
|
5
|
+
* both review surfaces number a change by the file's real lines. The browser
|
|
6
|
+
* half ships via exports["./client"], discovered through the package.json
|
|
7
|
+
* dsh.client declaration.
|
|
8
|
+
*
|
|
9
|
+
* This half deliberately registers NO system-prompt section: the Web
|
|
10
|
+
* composition already owns the file-reference guidance
|
|
11
|
+
* (`ui:deliverable-file-references`, contributed by
|
|
12
|
+
* dsh-deliverable-file-references), and the older section this plugin used to
|
|
13
|
+
* add contradicted it in every request. The browser half's inline-code mention
|
|
14
|
+
* resolver keeps working without guidance of its own — it only matches paths
|
|
15
|
+
* the model already wrote, and the host's prompt is what tells it how.
|
|
6
16
|
*/
|
|
7
17
|
import type { Context } from '@deepseek-ai/cordis';
|
|
8
18
|
export type * from './change-types.ts';
|
|
9
19
|
export { FileReviewService, transformFile } from './file-review-service.ts';
|
|
10
|
-
/**
|
|
20
|
+
/** No host services are required: the recorder only listens to the tool waterfall. */
|
|
11
21
|
export declare const inject: string[];
|
|
12
22
|
/**
|
|
13
|
-
*
|
|
14
|
-
* and the Code Mode (`run_code`) mutation recorder that backs the browser-side
|
|
15
|
-
* review tab.
|
|
23
|
+
* Record every settled file mutation for the browser-side review surfaces.
|
|
16
24
|
*
|
|
17
25
|
* Nested dispatch results carry no wire views — the diff cards only ride
|
|
18
26
|
* model-direct tool/call frames — so reviewing programmatic file edits needs a
|
|
@@ -20,7 +28,7 @@ export declare const inject: string[];
|
|
|
20
28
|
* every nested file mutation (`edit`/`write` — recognized by result shape, not
|
|
21
29
|
* tool name) into the `fileReview` service, which the browser half later turns
|
|
22
30
|
* into line-level hunks and merges into the owning `run_code` turn.
|
|
23
|
-
* @param ctx - host context carrying the
|
|
31
|
+
* @param ctx - host context carrying the tool waterfall.
|
|
24
32
|
*/
|
|
25
33
|
export declare function apply(ctx: Context): void;
|
|
26
34
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mutation grouping: the coordinate space each recorded hunk is anchored in.
|
|
3
|
+
*
|
|
4
|
+
* One file is often mutated several times in a single turn (`edit`, then
|
|
5
|
+
* `write`, then a Code Mode dispatch), and the review surfaces concatenate every
|
|
6
|
+
* mutation's hunks into ONE list per path. Those hunks do NOT share a coordinate
|
|
7
|
+
* space: mutation 1's `oldStart` is a line number in the text as it existed
|
|
8
|
+
* before mutation 1, mutation 2's is a line number in the text mutation 1 left
|
|
9
|
+
* behind, and so on. Replaying them as one flat list therefore applies hunks
|
|
10
|
+
* against coordinates that no longer exist.
|
|
11
|
+
*
|
|
12
|
+
* A group is the set of hunks one settlement produced (one tool result's
|
|
13
|
+
* `meta.diffs`, or one Code Mode `before`/`after` pair). Two rules follow:
|
|
14
|
+
*
|
|
15
|
+
* - settlements replay in settlement order going forward (redo) and in reverse
|
|
16
|
+
* order going back (undo), because each one is anchored in the text the
|
|
17
|
+
* previous one produced;
|
|
18
|
+
* - inside ONE settlement the hunks are anchored in the same text, so a hunk
|
|
19
|
+
* that changes the line count shifts every anchor still waiting behind it —
|
|
20
|
+
* they must be applied back-to-front.
|
|
21
|
+
*
|
|
22
|
+
* `mutation` is optional so a payload produced before this field existed
|
|
23
|
+
* degrades to a single group, which for the overwhelmingly common
|
|
24
|
+
* one-mutation payload is exactly the correct answer.
|
|
25
|
+
*/
|
|
26
|
+
import type { ProducedFileDiff } from './change-types.ts';
|
|
27
|
+
/**
|
|
28
|
+
* Append one settlement's hunks, stamping them with the coordinate space they
|
|
29
|
+
* were recorded in and the event sequence that orders them.
|
|
30
|
+
*
|
|
31
|
+
* The stamp is the accumulator's current length, which is strictly increasing
|
|
32
|
+
* per path, so two settlements can never share one — that uniqueness is what
|
|
33
|
+
* lets {@link mutationGroups} split a path's hunks back into settlements.
|
|
34
|
+
*
|
|
35
|
+
* `seq` is the ordering key: the conversation node's sequence for a
|
|
36
|
+
* snapshot-derived settlement, or the owning `run_code` root's sequence for a
|
|
37
|
+
* Host-recorded one. It is recorded separately from `mutation` because the two
|
|
38
|
+
* answer different questions — a chain of nested dispatches produces several
|
|
39
|
+
* distinct settlements that all share one node sequence.
|
|
40
|
+
*
|
|
41
|
+
* @param target - The path's accumulated hunks, mutated in place.
|
|
42
|
+
* @param diffs - One settlement's hunks, all anchored in the same text.
|
|
43
|
+
* @param seq - Event sequence that orders this settlement, when known.
|
|
44
|
+
*/
|
|
45
|
+
export declare function appendMutation(target: ProducedFileDiff[], diffs: readonly ProducedFileDiff[], seq?: number | undefined): void;
|
|
46
|
+
/**
|
|
47
|
+
* Order settlements by their recorded event sequence, so undo/redo walk the
|
|
48
|
+
* file's history in the order it actually happened.
|
|
49
|
+
*
|
|
50
|
+
* This is what keeps a `run_code` mutation and a model-direct edit to the same
|
|
51
|
+
* file from being applied out of order: the two arrive through different
|
|
52
|
+
* channels (the conversation snapshot vs. the Host recorder) and are merged
|
|
53
|
+
* asynchronously, so the array order is a merge artifact rather than history.
|
|
54
|
+
*
|
|
55
|
+
* Only when EVERY entry carries a sequence is the order provable. A partially
|
|
56
|
+
* stamped list keeps its incoming order, which is the conservative choice —
|
|
57
|
+
* guessing at the position of an unstamped settlement could silently corrupt a
|
|
58
|
+
* file. The sort is stable, so entries sharing one sequence (a single
|
|
59
|
+
* `run_code` root's nested dispatch chain) keep their dispatch order.
|
|
60
|
+
*
|
|
61
|
+
* @param entries - Settlements or events carrying an optional `seq`.
|
|
62
|
+
* @returns A new array in ascending event order, or the same order when unprovable.
|
|
63
|
+
*/
|
|
64
|
+
export declare function orderBySequence<T extends {
|
|
65
|
+
readonly seq: number | undefined;
|
|
66
|
+
}>(entries: readonly T[]): T[];
|
|
67
|
+
/** One settlement recovered from a path's accumulated hunks. */
|
|
68
|
+
export interface Settlement {
|
|
69
|
+
readonly seq: number | undefined;
|
|
70
|
+
readonly diffs: readonly ProducedFileDiff[];
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Recover the settlements one path's flat hunk list was built from.
|
|
74
|
+
* @param diffs - One path's accumulated hunks.
|
|
75
|
+
* @returns One entry per coordinate space, in the order they were appended.
|
|
76
|
+
*/
|
|
77
|
+
export declare function settlementsOf(diffs: readonly ProducedFileDiff[]): Settlement[];
|
|
78
|
+
/**
|
|
79
|
+
* Re-stamp a settlement list back into one flat hunk list, in event order.
|
|
80
|
+
*
|
|
81
|
+
* Stamps are reassigned rather than preserved because they encode POSITION
|
|
82
|
+
* (`mutation` is the append offset), and reordering invalidates the old values;
|
|
83
|
+
* leaving them stale would make {@link mutationGroups} split the same
|
|
84
|
+
* coordinate space into several groups.
|
|
85
|
+
*
|
|
86
|
+
* @param settlements - Settlements, in any order.
|
|
87
|
+
* @returns The flat hunk list, ordered by `seq` with fresh stamps.
|
|
88
|
+
*/
|
|
89
|
+
export declare function flattenSettlements(settlements: readonly Settlement[]): ProducedFileDiff[];
|
|
90
|
+
/**
|
|
91
|
+
* Split one path's hunks into contiguous same-coordinate groups, in settlement
|
|
92
|
+
* order. Hunks that carry no `mutation` form a single group.
|
|
93
|
+
* @param diffs - One path's accumulated hunks, in settlement order.
|
|
94
|
+
* @returns The groups, in settlement order.
|
|
95
|
+
*/
|
|
96
|
+
export declare function mutationGroups(diffs: readonly ProducedFileDiff[]): readonly (readonly ProducedFileDiff[])[];
|
|
97
|
+
/**
|
|
98
|
+
* The order one settlement's hunks must be applied in: back-to-front by the
|
|
99
|
+
* anchor of the direction being applied, because a hunk that changes the line
|
|
100
|
+
* count would otherwise shift the anchors of the hunks behind it. This is what
|
|
101
|
+
* makes a multi-hunk redo land on the coordinates the hunks recorded instead of
|
|
102
|
+
* the ones left over after the first hunk moved them.
|
|
103
|
+
*
|
|
104
|
+
* Hunks without a line anchor are content-matched and so coordinate-free; they
|
|
105
|
+
* sort after the anchored ones, where they cannot invalidate a pending anchor.
|
|
106
|
+
* @param group - One settlement's hunks.
|
|
107
|
+
* @param action - Direction being applied.
|
|
108
|
+
* @returns The hunks in application order (descending anchor).
|
|
109
|
+
*/
|
|
110
|
+
export declare function hunksForApply(group: readonly ProducedFileDiff[], action: 'undo' | 'redo'): readonly ProducedFileDiff[];
|
|
111
|
+
//# sourceMappingURL=mutation-order.d.ts.map
|
package/lib/types/remote.d.ts
CHANGED
|
@@ -1,24 +1,27 @@
|
|
|
1
1
|
/** Browser Typert contribution for the Host file-review service. */
|
|
2
2
|
import type { SessionId } from '@deepseek-ai/dsh-session/types';
|
|
3
3
|
import type { RemoteResult, TypertRemoteContribution } from '@deepseek-ai/dsh-typert-protocol';
|
|
4
|
-
import type { FileReviewRequest, FileReviewResult, RecordedRequest, RecordedResult } from './change-types.ts';
|
|
4
|
+
import type { AnchorRequest, AnchorResult, FileReviewRequest, FileReviewResult, RecordedRequest, RecordedResult } from './change-types.ts';
|
|
5
5
|
declare module '@deepseek-ai/dsh-typert-protocol' {
|
|
6
6
|
interface TypertRemoteNamespaceMap {
|
|
7
7
|
fileReview: {
|
|
8
8
|
status: (agentId: SessionId, request: FileReviewRequest) => Promise<RemoteResult<FileReviewResult>>;
|
|
9
9
|
apply: (agentId: SessionId, request: FileReviewRequest) => Promise<RemoteResult<FileReviewResult>>;
|
|
10
10
|
recorded: (agentId: SessionId, request: RecordedRequest) => Promise<RemoteResult<RecordedResult>>;
|
|
11
|
+
anchors: (agentId: SessionId, request: AnchorRequest) => Promise<RemoteResult<AnchorResult>>;
|
|
11
12
|
};
|
|
12
13
|
}
|
|
13
14
|
interface TypertRemoteMap {
|
|
14
15
|
'fileReview/status': (agentId: SessionId, request: FileReviewRequest) => Promise<RemoteResult<FileReviewResult>>;
|
|
15
16
|
'fileReview/apply': (agentId: SessionId, request: FileReviewRequest) => Promise<RemoteResult<FileReviewResult>>;
|
|
16
17
|
'fileReview/recorded': (agentId: SessionId, request: RecordedRequest) => Promise<RemoteResult<RecordedResult>>;
|
|
18
|
+
'fileReview/anchors': (agentId: SessionId, request: AnchorRequest) => Promise<RemoteResult<AnchorResult>>;
|
|
17
19
|
}
|
|
18
20
|
interface TypertRemoteScopeMap {
|
|
19
21
|
'agent:fileReview/status': (request: FileReviewRequest) => Promise<RemoteResult<FileReviewResult>>;
|
|
20
22
|
'agent:fileReview/apply': (request: FileReviewRequest) => Promise<RemoteResult<FileReviewResult>>;
|
|
21
23
|
'agent:fileReview/recorded': (request: RecordedRequest) => Promise<RemoteResult<RecordedResult>>;
|
|
24
|
+
'agent:fileReview/anchors': (request: AnchorRequest) => Promise<RemoteResult<AnchorResult>>;
|
|
22
25
|
}
|
|
23
26
|
}
|
|
24
27
|
export declare const TYPERT_REMOTE: TypertRemoteContribution;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The reversibility rule shared by the Host undo service and both review
|
|
3
|
+
* surfaces.
|
|
4
|
+
*
|
|
5
|
+
* A recorded hunk is reversible only when BOTH sides are known and placeable:
|
|
6
|
+
* `oldText === null` means the prior content is not reconstructable (a `write`
|
|
7
|
+
* overwrite, a `str_replace_editor insert`, an `edit` with an empty
|
|
8
|
+
* `old_string`, or a file creation), and an empty side without a line anchor
|
|
9
|
+
* cannot be located in the file. The Host REPLAYS these hunks to undo/redo, so
|
|
10
|
+
* a hunk that fails this test must never reach it — and a surface must not put
|
|
11
|
+
* such a file into a toggle batch, or a mixed turn reports a partial failure
|
|
12
|
+
* for files the service was always going to refuse.
|
|
13
|
+
*
|
|
14
|
+
* One module for all three call sites is what keeps them from drifting: the
|
|
15
|
+
* service decides what it will apply, the sidebar tab decides which rows and
|
|
16
|
+
* turn batches are reversible, and the chat card decides whether its Undo is
|
|
17
|
+
* enabled.
|
|
18
|
+
*/
|
|
19
|
+
import type { ProducedFileDiff } from './change-types.ts';
|
|
20
|
+
/**
|
|
21
|
+
* Whether one hunk carries both sides completely enough to replay exactly.
|
|
22
|
+
* @param diff - the hunk under test.
|
|
23
|
+
* @param path - the file the hunk claims to belong to.
|
|
24
|
+
* @returns true when the hunk can be undone/redone by exact replacement.
|
|
25
|
+
*/
|
|
26
|
+
export declare function hunkReversible(diff: ProducedFileDiff, path: string): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Whether a file's whole change set is reversible: non-empty and every hunk
|
|
29
|
+
* passes {@link hunkReversible}.
|
|
30
|
+
* @param path - the path every hunk must name.
|
|
31
|
+
* @param diffs - the file's hunks, in settlement order.
|
|
32
|
+
* @returns true when the Host can replay the complete change.
|
|
33
|
+
*/
|
|
34
|
+
export declare function changeReversible(path: string, diffs: readonly ProducedFileDiff[]): boolean;
|
|
35
|
+
//# sourceMappingURL=reversible.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@whybebabo/dsh-file-review-tab",
|
|
3
3
|
"description": "Review agent-produced file changes (line-level red/green diff + undo) both as a chat turn-tail row and as a dsh-better-sidebar tab; a port of left0ver's dsh-file-review.",
|
|
4
|
-
"version": "0.7.
|
|
4
|
+
"version": "0.7.2",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -74,7 +74,8 @@
|
|
|
74
74
|
"build:types": "tsc --emitDeclarationOnly --outDir lib/types",
|
|
75
75
|
"build": "npm run build:types && tsdown",
|
|
76
76
|
"typecheck": "tsc --noEmit",
|
|
77
|
-
"
|
|
77
|
+
"pretest": "npm run build",
|
|
78
|
+
"test": "node test/typert-descriptors.mjs && node test/slot-registration.mjs && node test/host-apply.mjs && node test/anchor-locate.mjs && node test/undo-redo.mjs && node test/interleaved-mutations.mjs && node test/review-invalidation.mjs && node test/deep-link.mjs && node test/diff-hunks.mjs && node test/hunk-anchors.mjs && node test/mutation-order.mjs && node test/deleted-paths.mjs && node test/client-bundle.mjs && node test/card-render.mjs && node test/tab-render.mjs && node test/diff-render.mjs"
|
|
78
79
|
},
|
|
79
80
|
"pnpm": {
|
|
80
81
|
"ignoredBuiltDependencies": [
|
|
@@ -87,20 +88,19 @@
|
|
|
87
88
|
},
|
|
88
89
|
"peerDependencies": {
|
|
89
90
|
"@deepseek-ai/cordis": "^4.0.2",
|
|
90
|
-
"@deepseek-ai/dsh-agent": "^0.2.
|
|
91
|
-
"@deepseek-ai/dsh-api-remotes": "^0.2.
|
|
92
|
-
"@deepseek-ai/dsh-api-session-controller": "^0.2.
|
|
93
|
-
"@deepseek-ai/dsh-atomic-write": "^0.2.
|
|
94
|
-
"@deepseek-ai/dsh-client-locale": "^0.2.
|
|
95
|
-
"@deepseek-ai/dsh-client-ui-chat": "^0.2.
|
|
96
|
-
"@deepseek-ai/dsh-client-ui-conversation": "^0.2.
|
|
97
|
-
"@deepseek-ai/dsh-client-ui-primitives": "^0.2.
|
|
98
|
-
"@deepseek-ai/dsh-client-ui-renderer": "^0.2.
|
|
99
|
-
"@deepseek-ai/dsh-client-ui-slots": "^0.2.
|
|
100
|
-
"@deepseek-ai/dsh-session": "^0.2.
|
|
101
|
-
"@deepseek-ai/dsh-
|
|
102
|
-
"@deepseek-ai/dsh-typert-
|
|
103
|
-
"@deepseek-ai/dsh-typert-registry": "^0.2.0-rc.2",
|
|
91
|
+
"@deepseek-ai/dsh-agent": "^0.2.2-rc.2",
|
|
92
|
+
"@deepseek-ai/dsh-api-remotes": "^0.2.2-rc.2",
|
|
93
|
+
"@deepseek-ai/dsh-api-session-controller": "^0.2.2-rc.2",
|
|
94
|
+
"@deepseek-ai/dsh-atomic-write": "^0.2.2-rc.2",
|
|
95
|
+
"@deepseek-ai/dsh-client-locale": "^0.2.2-rc.2",
|
|
96
|
+
"@deepseek-ai/dsh-client-ui-chat": "^0.2.2-rc.2",
|
|
97
|
+
"@deepseek-ai/dsh-client-ui-conversation": "^0.2.2-rc.2",
|
|
98
|
+
"@deepseek-ai/dsh-client-ui-primitives": "^0.2.2-rc.2",
|
|
99
|
+
"@deepseek-ai/dsh-client-ui-renderer": "^0.2.2-rc.2",
|
|
100
|
+
"@deepseek-ai/dsh-client-ui-slots": "^0.2.2-rc.2",
|
|
101
|
+
"@deepseek-ai/dsh-session": "^0.2.2-rc.2",
|
|
102
|
+
"@deepseek-ai/dsh-typert-protocol": "^0.2.2-rc.2",
|
|
103
|
+
"@deepseek-ai/dsh-typert-registry": "^0.2.2-rc.2",
|
|
104
104
|
"dsh-better-sidebar": ">=0.19.1",
|
|
105
105
|
"react": "^18.2.0"
|
|
106
106
|
},
|