dsh-hashline-edit 0.5.1 → 0.5.4

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.
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Hashline guidance sections for the dsh host layer.
3
3
  *
4
- * Prompt sections are owned here — `tool:read`, `tool:codegraph`, `tool:diagnostics`,
4
+ * Prompt sections are owned here — `tool:read`, `tool:rg`, `tool:codegraph`, `tool:diagnostics`,
5
5
  * `tool:write`, `tool:apply_patch` and `tool:edit` — because the hashline tools
6
6
  * must bring their own brief. The compiled default text IS the
7
7
  * pi-side guidance (`prompts/*.md`) loaded through `src/prompts.ts`, so the dsh
@@ -23,11 +23,11 @@ export interface GuidanceSection {
23
23
  /** Order used when the harness registry names no slot for this section. */
24
24
  readonly defaultOrder: number;
25
25
  /** The `systemPrompt.getSectionOrder` slot this section shadows, when one exists. */
26
- readonly orderName?: "TOOL_READ" | "TOOL_WRITE" | "TOOL_EDIT" | "TOOL_APPLY_PATCH";
26
+ readonly orderName?: "TOOL_READ" | "TOOL_WRITE" | "TOOL_EDIT" | "TOOL_APPLY_PATCH" | "TOOL_GREP";
27
27
  /** The compiled default text. */
28
28
  renderDefault(): string;
29
29
  }
30
- /** The six sections, in default-order sequence. */
30
+ /** The seven sections, in default-order sequence. */
31
31
  export declare const GUIDANCE_SECTIONS: readonly GuidanceSection[];
32
32
  /** Render the compiled default text for one section. */
33
33
  export declare function renderSectionDefault(name: string): string;
@@ -36,6 +36,8 @@ export interface GuidanceToggles {
36
36
  readonly read: boolean;
37
37
  readonly applyPatch: boolean;
38
38
  readonly edit: boolean;
39
+ /** Whether the system-`rg` search tool registered; absent keeps its section dark. */
40
+ readonly rg?: boolean;
39
41
  /** Whether the codegraph tool set registered; absent keeps its section dark. */
40
42
  readonly codegraph?: boolean;
41
43
  /** Whether the diagnostics tool registered; absent keeps its section dark. */
@@ -8,6 +8,12 @@ export interface NativeHideConfig {
8
8
  readonly hideNativeWriteTools?: BooleanSource;
9
9
  /** Extra global tool names to hide alongside the native set. */
10
10
  readonly hiddenToolNames?: readonly string[];
11
+ /**
12
+ * The denial text for one hidden name when the default editor wording would be wrong.
13
+ * The caller that configured the name is the only party that knows what replaces it;
14
+ * this layer only knows the names. Returning `undefined` keeps the editor wording.
15
+ */
16
+ readonly denialText?: ((name: string) => string | undefined) | undefined;
11
17
  /** Guidance sections to empty because this plugin provides no such tool. */
12
18
  readonly guidanceToClear?: readonly string[];
13
19
  /** The Agent scope key used for the agent-view probe; absent keeps the global probe. */
@@ -40,6 +40,9 @@ export declare const Config: Schema<Schemastery.ObjectS<NoInfer<{
40
40
  codegraph: Schema<boolean, boolean, "volatile-defined">;
41
41
  codegraphPath: Schema<string, string, "volatile-defined">;
42
42
  diagnostics: Schema<boolean, boolean, "volatile-defined">;
43
+ rg: Schema<boolean, boolean, "volatile-defined">;
44
+ rgPath: Schema<string, string, "volatile-defined">;
45
+ writeAutoRead: Schema<boolean, boolean, "volatile-defined">;
43
46
  }>>, Schemastery.ObjectT<NoInfer<{
44
47
  read: Schema<boolean, boolean, "volatile-defined">;
45
48
  applyPatch: Schema<boolean, boolean, "volatile-defined">;
@@ -47,6 +50,9 @@ export declare const Config: Schema<Schemastery.ObjectS<NoInfer<{
47
50
  codegraph: Schema<boolean, boolean, "volatile-defined">;
48
51
  codegraphPath: Schema<string, string, "volatile-defined">;
49
52
  diagnostics: Schema<boolean, boolean, "volatile-defined">;
53
+ rg: Schema<boolean, boolean, "volatile-defined">;
54
+ rgPath: Schema<string, string, "volatile-defined">;
55
+ writeAutoRead: Schema<boolean, boolean, "volatile-defined">;
50
56
  }>>, "plain">;
51
57
  /** The plugin configuration the loader passes as the second `apply` argument. */
52
58
  export interface PluginConfig {
@@ -90,6 +96,26 @@ export interface PluginConfig {
90
96
  * it needs that toolchain on the machine, and a missing one is reported as call text.
91
97
  */
92
98
  diagnostics?: boolean;
99
+ /**
100
+ * Expose the `rg` tool: file-content search executed by the system `rg`, so the user's own
101
+ * ripgrep, its version and its config are what runs. Defaults to true; while it is on the
102
+ * native `grep` tool and its `tool:grep` brief are hidden in favour of this surface, and
103
+ * its matches come back in the native grep's value shape so the read switch's grep view
104
+ * still serves them as `HASH│content` rows.
105
+ */
106
+ rg?: boolean;
107
+ /**
108
+ * Executable used for `rg` calls. Empty uses the first `rg` on `PATH`; set it when
109
+ * ripgrep lives outside `PATH` or a specific install must be pinned.
110
+ */
111
+ rgPath?: string;
112
+ /**
113
+ * Append the written file's anchored page to the built-in `write` result, so the next
114
+ * `edit` needs no `read`. Defaults to **false**: the write returns the native one-line
115
+ * success, and the whole-file page is never injected unasked. The served hash-echo
116
+ * refusal guard runs either way.
117
+ */
118
+ writeAutoRead?: boolean;
93
119
  }
94
120
  /** The feature switches after the shipped defaults are applied. */
95
121
  export interface ResolvedSwitches {
@@ -99,8 +125,11 @@ export interface ResolvedSwitches {
99
125
  readonly codegraph: boolean;
100
126
  readonly codegraphPath: string;
101
127
  readonly diagnostics: boolean;
128
+ readonly rg: boolean;
129
+ readonly rgPath: string;
130
+ readonly writeAutoRead: boolean;
102
131
  }
103
- /** Resolve the plugin's switches with the shipped defaults: read and apply_patch on, edit, codegraph and diagnostics off. */
132
+ /** Resolve the plugin's switches with the shipped defaults: read, apply_patch and rg on; edit, codegraph, diagnostics and the write auto-read off. */
104
133
  export declare function resolveSwitches(config?: PluginConfig): ResolvedSwitches;
105
134
  /**
106
135
  * Install the hashline toolset for one agent inside its own effect, so the
@@ -0,0 +1,67 @@
1
+ /** One located executable plus the arguments that always precede the call's own arguments. */
2
+ export interface RgInvocation {
3
+ /** Executable to spawn. */
4
+ readonly command: string;
5
+ /** Arguments that always precede the call arguments (unused today; a script layout would fill it). */
6
+ readonly prefixArgs: readonly string[];
7
+ /** The entry point that was found, for refusal text and diagnostics. */
8
+ readonly source: string;
9
+ }
10
+ /** A located ripgrep, or the reason none could be located. */
11
+ export type RgResolution = {
12
+ readonly ok: true;
13
+ readonly invocation: RgInvocation;
14
+ } | {
15
+ readonly ok: false;
16
+ readonly problem: string;
17
+ };
18
+ /** Inputs of {@link resolveRgInvocation}; every ambient fact is injectable for tests. */
19
+ export interface ResolveRgOptions {
20
+ /** The plugin's `rgPath` config; an empty or absent value falls back to `PATH`. */
21
+ readonly explicitPath?: string | undefined;
22
+ /** The `PATH` value to scan; defaults to `process.env.PATH`. */
23
+ readonly pathValue?: string | undefined;
24
+ /** Target platform; defaults to `process.platform`. */
25
+ readonly platform?: NodeJS.Platform | undefined;
26
+ /** Existence oracle; defaults to `existsSync`. */
27
+ readonly exists?: ((candidate: string) => boolean) | undefined;
28
+ }
29
+ /**
30
+ * Locate the ripgrep executable: an explicit `rgPath` wins, then the first `rg` entry on `PATH`.
31
+ *
32
+ * A `.cmd`/`.bat` shim is refused rather than run through a shell — a shell would re-quote the
33
+ * pattern and target this plugin passes as plain argv.
34
+ */
35
+ export declare function resolveRgInvocation(options?: ResolveRgOptions): RgResolution;
36
+ /** Default wall clock one search may take before it is killed. */
37
+ export declare const RG_TIMEOUT_MS = 30000;
38
+ /** One search's process facts. */
39
+ export interface RgRunOptions {
40
+ /** Working directory the search runs in (the live session directory). */
41
+ readonly cwd: string;
42
+ /** Caller cancellation; aborts the child and rejects with the abort reason. */
43
+ readonly signal: AbortSignal | undefined;
44
+ /** Wall clock budget; defaults to {@link RG_TIMEOUT_MS}. */
45
+ readonly timeoutMs?: number | undefined;
46
+ /** Extra environment entries layered over the host environment. */
47
+ readonly env?: NodeJS.ProcessEnv | undefined;
48
+ }
49
+ /** A finished search: both streams, the exit code, and how it ended. */
50
+ export interface RgRunResult {
51
+ readonly stdout: string;
52
+ readonly stderr: string;
53
+ /** Ripgrep's exit code: `0` matches found, `1` none, `2` an error (bad pattern, unreadable target). */
54
+ readonly code: number | null;
55
+ /** Whether the deadline killed it. */
56
+ readonly timedOut: boolean;
57
+ /** Whether the capture ceiling was reached (the stdout is then incomplete). */
58
+ readonly overflow: boolean;
59
+ }
60
+ /**
61
+ * Run one ripgrep command and capture its output.
62
+ *
63
+ * The promise resolves for every outcome the caller can report — a non-zero exit, a timeout, a
64
+ * capture overflow — and rejects only for cancellation, so a failed search never becomes an
65
+ * opaque tool error.
66
+ */
67
+ export declare function runRg(invocation: RgInvocation, args: readonly string[], options: RgRunOptions): Promise<RgRunResult>;
@@ -0,0 +1,70 @@
1
+ /** One matched line as ripgrep reported it, before display-path normalization. */
2
+ export interface RgMatch {
3
+ /** The path ripgrep printed for the match (relative to its working directory, or as given). */
4
+ readonly path: string;
5
+ /** 1-based line number of the match inside that file. */
6
+ readonly lineNumber: number;
7
+ /** The matched line's text, without its line terminator. */
8
+ readonly line: string;
9
+ }
10
+ /** Validated `grep` arguments. */
11
+ export interface RgInput {
12
+ /** The ripgrep regular expression (or literal text when {@link RgInput.fixedStrings}). */
13
+ readonly pattern: string;
14
+ /** File or directory to search; absent searches the working directory. */
15
+ readonly path?: string;
16
+ /** One positive glob filter for which files to search. */
17
+ readonly include?: string;
18
+ /** Force a case-insensitive search (`-i`); absent keeps ripgrep's smart case. */
19
+ readonly ignoreCase?: boolean;
20
+ /** Treat the pattern as literal text (`-F`) instead of a regular expression. */
21
+ readonly fixedStrings?: boolean;
22
+ /** Only match whole words (`-w`). */
23
+ readonly wordMatch?: boolean;
24
+ /** Also search hidden files and directories (`--hidden`). */
25
+ readonly hidden?: boolean;
26
+ /** Ignore `.gitignore`/`.ignore` rules and search every file (`--no-ignore`). */
27
+ readonly noIgnore?: boolean;
28
+ }
29
+ /**
30
+ * Validate the raw tool arguments into {@link RgInput}.
31
+ *
32
+ * The parameter schema already refuses a wrong type; this admission keeps the contract explicit for
33
+ * a direct (nested `run_code`) call and for the value constraints the schema cannot express: a
34
+ * non-EMPTY `pattern` (whitespace is a legitimate regex), a non-blank `path` when given, and a
35
+ * single positive `include` glob. An exact empty `include` is treated as omitted.
36
+ *
37
+ * @param raw - the tool call's raw arguments.
38
+ * @returns the accepted input.
39
+ */
40
+ export declare function parseRgArgs(raw: unknown): RgInput;
41
+ /**
42
+ * Build the fixed `rg --json` argv for one `grep` call.
43
+ *
44
+ * Every model-controlled value is a plain argv element — no shell layer exists, so no quoting
45
+ * applies. The pattern rides in `--regexp=` form and the target behind `--`, so a leading-dash
46
+ * value can never be parsed as a flag.
47
+ *
48
+ * @param input - the validated arguments.
49
+ * @returns the complete ripgrep argument vector (excluding the binary itself).
50
+ */
51
+ export declare function buildRgCommand(input: RgInput): string[];
52
+ /**
53
+ * Parse complete `rg --json` stdout into flat matches, in output order (ripgrep emits one file's
54
+ * matches contiguously and in ascending line order, which the grep view relies on).
55
+ *
56
+ * @param stdout - the complete raw `rg --json` stdout.
57
+ * @returns the flat matches; empty for output with no match records.
58
+ */
59
+ export declare function parseRgOutput(stdout: string): RgMatch[];
60
+ /**
61
+ * The model-facing path of one match: `./` stripped, and an absolute path inside the working
62
+ * directory shown relative to it.
63
+ *
64
+ * WHY: ripgrep echoes the operand it was given, so `grep path: "."` would otherwise print
65
+ * `./src/a.ts` and an absolute target would print the whole drive path. Neither is wrong, but the
66
+ * grep view resolves matches back against the working directory and the model reads the shorter
67
+ * form; a path outside the directory is kept absolute because relativizing it would invent `..`
68
+ * segments the search never named.
69
+ */
70
+ export declare function displayPath(rawPath: string, cwd: string): string;
@@ -0,0 +1,49 @@
1
+ /**
2
+ * The `rg` tool: file-content search executed by the system `rg` executable.
3
+ *
4
+ * ## Why a replacement instead of the host's grep
5
+ * The host's `grep` (`@deepseek-ai/dsh-tool-fs-search`) spawns the ripgrep binary vendored in
6
+ * `@vscode/ripgrep` with one fixed argv. This plugin is personal tooling on machines that already
7
+ * have ripgrep installed and configured (`RIPGREP_CONFIG_PATH`), and the user's own `rg` is the one
8
+ * they keep current; a first-class tool also exposes the matching switches that fixed argv cannot
9
+ * (`ignoreCase`, `fixedStrings`, `wordMatch`, `hidden`, `noIgnore`) without a shell command.
10
+ *
11
+ * ## Naming contract: `rg`, and the native `grep` is hidden
12
+ * The tool is named `rg` — the executable it runs — never `grep`: a call therefore cannot be
13
+ * confused with the host's built-in `grep` tool or with a shell `grep`/`rg` command, and no
14
+ * same-name shadowing has to be reasoned about. While the `rg` switch is on, `dsh/index.ts`
15
+ * removes the native `grep` from the agent's tool view through the native-hide lane
16
+ * (`dsh/hide.ts`), and the native `tool:grep` prompt section goes dark because the name it
17
+ * describes no longer resolves. This module owns the replacement brief (`tool:rg`, see
18
+ * `prompts/rg-guidelines.md`).
19
+ *
20
+ * ## Serving contract: the native grep's value shape, plus the served anchor
21
+ * The result value keeps the host grep's `{ matches: [{ path, lineNumber, line }] }`, so the
22
+ * existing `dsh/shell-hook.ts` grep view can re-read each matched row from disk, serve it as
23
+ * `HASH│content` and lease it whenever the `read` switch is on. That seam writes each served
24
+ * anchor onto its match as `hash` — the value channel, which is also the only one a nested
25
+ * `run_code` dispatch receives — and this module's renderer turns those rows into the shared
26
+ * search page. This module never serves: anchors stay owned by that one seam.
27
+ *
28
+ * @module dsh-hashline-edit/rg/tools
29
+ */
30
+ import { type ToolDefinition } from "@deepseek-ai/dsh-tools";
31
+ import { type RgInvocation, type RgResolution, type RgRunOptions, type RgRunResult } from "./cli.js";
32
+ /** The tool name this module registers: the executable it runs, deliberately not `grep`. */
33
+ export declare const RG_TOOL_NAME = "rg";
34
+ /** What one agent install hands the tool. */
35
+ export interface RgToolOptions {
36
+ /** ripgrep locator; defaults to the real PATH resolution. Re-run per call, so a PATH change is seen. */
37
+ readonly resolveRg?: (() => RgResolution) | undefined;
38
+ /** Search runner; defaults to the real spawn. */
39
+ readonly run?: ((invocation: RgInvocation, args: readonly string[], options: RgRunOptions) => Promise<RgRunResult>) | undefined;
40
+ /** Per-call wall clock budget; defaults to {@link RG_TIMEOUT_MS}. */
41
+ readonly timeoutMs?: number | undefined;
42
+ }
43
+ /**
44
+ * Build the `rg` tool definition.
45
+ *
46
+ * @param options - optional seams: a ripgrep locator, a runner and the wall clock budget.
47
+ * @returns the tool definition, ready for a scoped registration.
48
+ */
49
+ export declare function buildRgTool(options?: RgToolOptions): ToolDefinition;
@@ -0,0 +1,81 @@
1
+ /**
2
+ * Rendering for the `rg` tool: the model-facing match text and the search-card
3
+ * projection a UI renders.
4
+ *
5
+ * WHY the same caps the grep view enforces: this tool's canonical value carries EVERY parsed match
6
+ * (so the shell/grep view can prove and serve all of them), while the text a model reads is capped
7
+ * exactly like the host grep's — at most {@link GREP_INLINE_MAX_MATCHES} matches and a bounded
8
+ * per-line preview. A result over the cap is reported as a count, never silently shortened.
9
+ *
10
+ * WHY `presentationMeta` at all: the canonical value never crosses the wire — only the rendered
11
+ * text and this metadata do — so the structured by-file shape a search card renders rides here,
12
+ * bounded to a payload small enough to persist in the session log beside every result.
13
+ *
14
+ * @module dsh-hashline-edit/rg/view
15
+ */
16
+ import type { SearchResultView } from "@deepseek-ai/dsh-tools";
17
+ import type { RgMatch } from "./command.js";
18
+ /** One match page after the inline cap was applied. */
19
+ interface RetainedMatches {
20
+ /** The matches kept inline, in output order. */
21
+ readonly items: readonly RgMatch[];
22
+ /** Every match the search found, before the cap. */
23
+ readonly seen: number;
24
+ /** Whether the cap dropped any match. */
25
+ readonly truncated: boolean;
26
+ }
27
+ /**
28
+ * Cut one matched line at a byte budget without splitting a UTF-8 code point.
29
+ *
30
+ * WHY a byte budget and not a character count: the cap exists to bound what a very long
31
+ * minified/generated line costs the model, and the cut must never emit a broken code point.
32
+ */
33
+ export declare function previewLine(line: string, maxBytes?: number): string;
34
+ /** Apply the inline match cap: the first `maxMatches` matches, plus what the search really found. */
35
+ export declare function retainMatches(matches: readonly RgMatch[], maxMatches?: number): RetainedMatches;
36
+ /**
37
+ * The model-facing `rg` text: a found-count header, the retained matches grouped by file, then —
38
+ * when the result was capped — a footer naming how many matches were not shown. A zero-match search
39
+ * reads `No matches found`, the text the host grep uses for the same state.
40
+ *
41
+ * @param matches - every match the search found, in output order.
42
+ * @returns the model-facing text.
43
+ */
44
+ export declare function formatRgText(matches: readonly RgMatch[]): string;
45
+ /**
46
+ * The private `tool/result` metadata payload: the capped, structured search result a search card
47
+ * renders on the live and replayed paths alike. `failed` marks a result that carries guidance
48
+ * instead of a search (no `rg`, a rejected pattern, the deadline), so a caller never presents it as
49
+ * an empty result; it is omitted for a real zero-match search.
50
+ */
51
+ export type RgSearchMeta = {
52
+ shape: "matches";
53
+ files: {
54
+ path: string;
55
+ matches: {
56
+ lineNumber: number;
57
+ line: string;
58
+ }[];
59
+ }[];
60
+ truncated: boolean;
61
+ total: number;
62
+ failed?: true;
63
+ };
64
+ /**
65
+ * Project the retained matches into {@link RgSearchMeta} for the search card.
66
+ *
67
+ * @param matches - every match the search found, in output order.
68
+ * @param failed - whether the call carried guidance instead of a search result.
69
+ * @returns the byte-bounded metadata.
70
+ */
71
+ export declare function rgMeta(matches: readonly RgMatch[], failed?: boolean): RgSearchMeta;
72
+ /**
73
+ * Narrow opaque live or replayed result metadata back to a search card. Malformed metadata, or a
74
+ * result that carried guidance instead of a search, returns `undefined` so the caller keeps the
75
+ * generic card instead of rendering a wrong one.
76
+ *
77
+ * @param meta - the metadata this tool projected through `output.presentationMeta`.
78
+ * @returns the search view, or `undefined` for the generic fallback.
79
+ */
80
+ export declare function searchViewFromMeta(meta: unknown): SearchResultView | undefined;
81
+ export {};
@@ -4,8 +4,10 @@
4
4
  *
5
5
  * Three steps, each fail-closed:
6
6
  * - {@link parse} admits only commands whose output is the file's own lines
7
+ * - {@link parse} admits only commands whose output is the file's own lines
7
8
  * (`Get-Content`/`type`/`cat`, a `Select-Object -First|-Last|-Skip` bound or
8
- * the `-Skip N -First M` window, `Select-String`, and `rg` with one explicit file);
9
+ * the `-Skip N -First M` window, `Select-String`, `rg` and `grep` over one explicit file,
10
+ * and `head`/`tail` over one explicit file);
9
11
  * - {@link align} maps the stdout lines back to disk lines with a monotonic
10
12
  * match that must be unique — duplicate content without a unique position is
11
13
  * ambiguous and refuses;
@@ -36,6 +38,10 @@ export type ParsedShellCommand = {
36
38
  readonly path: string;
37
39
  readonly skip: number;
38
40
  readonly count: number;
41
+ } | {
42
+ /** Matched lines without a line number (`grep <pattern> <file>`): content alignment only. */
43
+ readonly kind: "bare";
44
+ readonly path: string;
39
45
  } | {
40
46
  readonly kind: "search";
41
47
  readonly path: string;
@@ -95,8 +101,8 @@ export declare function align(stdoutLines: readonly string[], fileLines: readonl
95
101
  * @returns the plan, or `undefined` when the host must pass the output through.
96
102
  */
97
103
  export declare function plan(deps: ToolDependencies, request: ShellViewRequest): Promise<ShellViewPlan | undefined>;
98
- /** The host tool whose canonical value is `{ matches: [{ path, lineNumber, line }] }`. */
99
- export declare const GREP_TOOL_NAME = "grep";
104
+ /** Every tool whose result this view serves — the native grep and this plugin's `rg`. */
105
+ export declare const GREP_TOOL_NAMES: readonly string[];
100
106
  /** The host `grepMaxMatches` default (`@deepseek-ai/dsh-tool-fs-search` `Config`). */
101
107
  export declare const GREP_INLINE_MAX_MATCHES = 250;
102
108
  /**
@@ -127,11 +133,29 @@ export interface GrepViewRequest {
127
133
  export interface GrepViewPlan {
128
134
  /** The shared search banner, one count header per file, and anchored `HASH│content` rows. */
129
135
  readonly text: string;
136
+ /** The served anchors behind {@link GrepViewPlan.text}, one per matched line, in page order. */
137
+ readonly rows: readonly GrepViewRow[];
130
138
  /** Total rows served (and leased) by this plan. */
131
139
  readonly servedLines: number;
132
140
  /** The served files, in first-seen match order. */
133
141
  readonly paths: readonly string[];
134
142
  }
143
+ /** One served match row: its file, its 1-based line, its anchor and its text. */
144
+ export interface GrepViewRow {
145
+ readonly path: string;
146
+ readonly lineNumber: number;
147
+ readonly hash: string;
148
+ readonly text: string;
149
+ }
150
+ /**
151
+ * One rendered grep page: the shared search banner over per-file count headers and
152
+ * `HASH│content` rows, in first-seen file order.
153
+ *
154
+ * WHY rows and not pre-rendered strings: the same served set is projected into two channels —
155
+ * this page (the native `grep` tool's model-facing text) and this plugin's own `rg` value,
156
+ * where each match carries its anchor so a nested `run_code` caller can edit without a read.
157
+ */
158
+ export declare function grepRowsPage(rows: readonly GrepViewRow[]): string;
135
159
  /**
136
160
  * Turn one built-in `grep` result into anchored rows for the files it matched,
137
161
  * serving (and leasing) exactly those lines.
@@ -57,6 +57,12 @@ export interface WriteHookDeps {
57
57
  * here; a composition without the channel silently skips the announcement.
58
58
  */
59
59
  readonly observations?: FsObservationChannel;
60
+ /**
61
+ * Whether the post-write auto-read runs and appends the written file's anchored page to the
62
+ * result. Absent or false returns the write's own result untouched — the native one-line
63
+ * success — so the whole-file page is never injected unasked.
64
+ */
65
+ readonly autoReadEnabled?: boolean;
60
66
  /** Host diagnostic sink; the hook must never throw through this. */
61
67
  warn(message: string): void;
62
68
  }
@@ -71,8 +77,16 @@ export interface WriteHooks {
71
77
  * `agentCtx.on` binding over them.
72
78
  */
73
79
  export declare function createWriteHooks(deps: WriteHookDeps): WriteHooks;
80
+ /** Options for the write integration. The auto-read is opt-in: absent means off. */
81
+ export interface WriteHookOptions {
82
+ /**
83
+ * Append the written file's anchored page to the `write` result so the next `edit` needs no
84
+ * `read`. Off by default — the whole-file page is context the write call did not ask for.
85
+ */
86
+ readonly autoReadEnabled?: boolean;
87
+ }
74
88
  /** The production dependency set: the byte seam plus core served state, core read pipeline, local paths. */
75
- export declare function defaultWriteHookDeps(warn: (message: string) => void, io: FileIO, observations?: FsObservationChannel): WriteHookDeps;
89
+ export declare function defaultWriteHookDeps(warn: (message: string) => void, io: FileIO, observations?: FsObservationChannel, options?: WriteHookOptions): WriteHookDeps;
76
90
  /**
77
91
  * Register the write integration for one agent on its own scope layer.
78
92
  *
@@ -82,4 +96,4 @@ export declare function defaultWriteHookDeps(warn: (message: string) => void, io
82
96
  * @param io - the host byte seam: the auto-read decodes the written bytes through it.
83
97
  * @returns the exact disposer that unregisters both listeners.
84
98
  */
85
- export declare function registerWriteHook(rootCtx: Context, agentCtx: Context, io: FileIO, observations?: FsObservationChannel): () => void;
99
+ export declare function registerWriteHook(rootCtx: Context, agentCtx: Context, io: FileIO, observations?: FsObservationChannel, options?: WriteHookOptions): () => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-hashline-edit",
3
- "version": "0.5.1",
3
+ "version": "0.5.4",
4
4
  "description": "Hash-anchored read/apply_patch/edit tools for DeepSeek Harness (dsh). Every line gets a unique 3- or 4-char hash (A-Za-z0-9, configurable) that stays stable across edits; apply_patch and the anchored range edit tool are the file-mutation entry points, each committing its whole batch as one transaction.",
5
5
  "keywords": [
6
6
  "anchors",
@@ -49,6 +49,25 @@
49
49
  },
50
50
  "./package.json": "./package.json"
51
51
  },
52
+ "scripts": {
53
+ "test": "vitest run",
54
+ "test:watch": "vitest",
55
+ "test:coverage": "vitest run --coverage --coverage.thresholds.lines=85 --coverage.thresholds.statements=85 --coverage.thresholds.functions=85 --coverage.thresholds.branches=80",
56
+ "test:win": "vitest run --config vitest.config.windows.ts",
57
+ "test:win:3": "node scripts/test-width.mjs 3 dsh",
58
+ "test:win:coverage": "vitest run --config vitest.config.windows.ts --coverage --coverage.thresholds.lines=85 --coverage.thresholds.statements=85 --coverage.thresholds.functions=85 --coverage.thresholds.branches=80",
59
+ "lint": "oxlint . && knip --max-issues 0",
60
+ "lint:knip": "knip --max-issues 0",
61
+ "format": "oxfmt --check .",
62
+ "format:fix": "oxfmt .",
63
+ "typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.dsh.json",
64
+ "build": "node scripts/build-dsh.mjs",
65
+ "prepublishOnly": "node scripts/build-dsh.mjs && pnpm run typecheck && pnpm run lint && pnpm run test:win",
66
+ "canon:audit": "node scripts/canon-churn-audit.mjs",
67
+ "prepack": "node scripts/build-dsh.mjs",
68
+ "audit": "pnpm audit --audit-level high --registry https://registry.npmjs.org/",
69
+ "verify": "pnpm run lint && pnpm run format && pnpm run typecheck && pnpm run test:win:coverage"
70
+ },
52
71
  "dependencies": {
53
72
  "diff": "^8.0.2",
54
73
  "file-type": "^21.3.0",
@@ -96,6 +115,7 @@
96
115
  "dsh": ">=0.2.2-rc.1 <0.2.3-0",
97
116
  "node": ">=24.0.0"
98
117
  },
118
+ "packageManager": "pnpm@12.0.0",
99
119
  "dsh": {
100
120
  "bundle": {
101
121
  "patch": "./cordis.patch.yml"
@@ -112,22 +132,5 @@
112
132
  "platform": "web",
113
133
  "immediately": true
114
134
  }
115
- },
116
- "scripts": {
117
- "test": "vitest run",
118
- "test:watch": "vitest",
119
- "test:coverage": "vitest run --coverage --coverage.thresholds.lines=85 --coverage.thresholds.statements=85 --coverage.thresholds.functions=85 --coverage.thresholds.branches=80",
120
- "test:win": "vitest run --config vitest.config.windows.ts",
121
- "test:win:3": "node scripts/test-width.mjs 3 dsh",
122
- "test:win:coverage": "vitest run --config vitest.config.windows.ts --coverage --coverage.thresholds.lines=85 --coverage.thresholds.statements=85 --coverage.thresholds.functions=85 --coverage.thresholds.branches=80",
123
- "lint": "oxlint . && knip --max-issues 0",
124
- "lint:knip": "knip --max-issues 0",
125
- "format": "oxfmt --check .",
126
- "format:fix": "oxfmt .",
127
- "typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.dsh.json",
128
- "build": "node scripts/build-dsh.mjs",
129
- "canon:audit": "node scripts/canon-churn-audit.mjs",
130
- "audit": "pnpm audit --audit-level high --registry https://registry.npmjs.org/",
131
- "verify": "pnpm run lint && pnpm run format && pnpm run typecheck && pnpm run test:win:coverage"
132
135
  }
133
- }
136
+ }
@@ -0,0 +1,8 @@
1
+ # rg guidelines
2
+
3
+ - `rg` is the file-content search tool: call it instead of a shell `grep`/`rg` command, and instead of the built-in `grep`, which this profile hides while `rg` is on.
4
+ - Prefer one `rg` call over a search-then-read loop: with `read` on, every matched line comes back served and leased — as `HASH│content` on a direct call's page, and as each match's `hash` (the anchor of that same served row) inside `run_code` — so `edit`/`apply_patch` can target those anchors with no separate `read`.
5
+ - The default is ripgrep's smart case (insensitive only when the pattern has no uppercase); pass `ignoreCase` to force `-i`, `fixedStrings` for literal text, `wordMatch` for whole words.
6
+ - `hidden` adds dotfiles and directories, `noIgnore` drops `.gitignore`/`.ignore` filtering: use them to reach a file the default search skipped, not by default.
7
+ - Narrow instead of enlarging: `include` takes ONE positive glob (`*.ts`, `*.{js,jsx}`) and `path` scopes the search to a file or directory. Past 250 matches the result is reported as a count and passes through unserved.
8
+ - A result that reports no `rg` on PATH, a pattern ripgrep rejected or the time budget is guidance, not a failure: fix `rgPath`, simplify the pattern, or narrow the path rather than repeating the call.
@@ -1,3 +1,4 @@
1
1
  - write: read the file before overwriting it; `write` replaces the whole file, so use it for a new file or a rewrite where every line changes.
2
2
  - write: a partial change is not a whole-file rewrite even when the whole file is already in context — use `edit` on the served rows instead.
3
3
  - write: never paste served `HASH│` rows into the content; a line that reproduces a served row is refused as a served hash echo.
4
+ - write: the result is the native one-line success — no anchors come back with it (the opt-in `writeAutoRead` switch restores an appended anchored page). `read` the file when a follow-up `edit` needs anchors.