@whybebabo/dsh-file-review-tab 0.7.1 → 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.
@@ -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
@@ -1,18 +1,26 @@
1
1
  /**
2
- * File-review-tab plugin, node half. Registers the response-format guidance
3
- * that lets the browser half recognize final-response file references. The
4
- * browser half ships via exports["./client"], discovered through the
5
- * package.json dsh.client declaration.
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
- /** Services required for the model guidance paired with the browser renderer. */
20
+ /** No host services are required: the recorder only listens to the tool waterfall. */
11
21
  export declare const inject: string[];
12
22
  /**
13
- * Register model guidance for the file-reference renderer shipped by this package,
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 system-prompt registry and tool waterfall.
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
@@ -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.1",
4
+ "version": "0.7.2",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -75,7 +75,7 @@
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/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/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
+ "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"
79
79
  },
80
80
  "pnpm": {
81
81
  "ignoredBuiltDependencies": [
@@ -88,20 +88,19 @@
88
88
  },
89
89
  "peerDependencies": {
90
90
  "@deepseek-ai/cordis": "^4.0.2",
91
- "@deepseek-ai/dsh-agent": "^0.2.0-rc.2",
92
- "@deepseek-ai/dsh-api-remotes": "^0.2.0-rc.2",
93
- "@deepseek-ai/dsh-api-session-controller": "^0.2.0-rc.2",
94
- "@deepseek-ai/dsh-atomic-write": "^0.2.0-rc.2",
95
- "@deepseek-ai/dsh-client-locale": "^0.2.0-rc.2",
96
- "@deepseek-ai/dsh-client-ui-chat": "^0.2.0-rc.2",
97
- "@deepseek-ai/dsh-client-ui-conversation": "^0.2.0-rc.2",
98
- "@deepseek-ai/dsh-client-ui-primitives": "^0.2.0-rc.2",
99
- "@deepseek-ai/dsh-client-ui-renderer": "^0.2.0-rc.2",
100
- "@deepseek-ai/dsh-client-ui-slots": "^0.2.0-rc.2",
101
- "@deepseek-ai/dsh-session": "^0.2.0-rc.2",
102
- "@deepseek-ai/dsh-system-prompt": "^0.2.0-rc.2",
103
- "@deepseek-ai/dsh-typert-protocol": "^0.2.0-rc.2",
104
- "@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",
105
104
  "dsh-better-sidebar": ">=0.19.1",
106
105
  "react": "^18.2.0"
107
106
  },