dsh-hashline-edit 0.5.2 → 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.
@@ -42,6 +42,7 @@ export declare const Config: Schema<Schemastery.ObjectS<NoInfer<{
42
42
  diagnostics: Schema<boolean, boolean, "volatile-defined">;
43
43
  rg: Schema<boolean, boolean, "volatile-defined">;
44
44
  rgPath: Schema<string, string, "volatile-defined">;
45
+ writeAutoRead: Schema<boolean, boolean, "volatile-defined">;
45
46
  }>>, Schemastery.ObjectT<NoInfer<{
46
47
  read: Schema<boolean, boolean, "volatile-defined">;
47
48
  applyPatch: Schema<boolean, boolean, "volatile-defined">;
@@ -51,6 +52,7 @@ export declare const Config: Schema<Schemastery.ObjectS<NoInfer<{
51
52
  diagnostics: Schema<boolean, boolean, "volatile-defined">;
52
53
  rg: Schema<boolean, boolean, "volatile-defined">;
53
54
  rgPath: Schema<string, string, "volatile-defined">;
55
+ writeAutoRead: Schema<boolean, boolean, "volatile-defined">;
54
56
  }>>, "plain">;
55
57
  /** The plugin configuration the loader passes as the second `apply` argument. */
56
58
  export interface PluginConfig {
@@ -107,6 +109,13 @@ export interface PluginConfig {
107
109
  * ripgrep lives outside `PATH` or a specific install must be pinned.
108
110
  */
109
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;
110
119
  }
111
120
  /** The feature switches after the shipped defaults are applied. */
112
121
  export interface ResolvedSwitches {
@@ -118,8 +127,9 @@ export interface ResolvedSwitches {
118
127
  readonly diagnostics: boolean;
119
128
  readonly rg: boolean;
120
129
  readonly rgPath: string;
130
+ readonly writeAutoRead: boolean;
121
131
  }
122
- /** Resolve the plugin's switches with the shipped defaults: read, apply_patch and rg 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. */
123
133
  export declare function resolveSwitches(config?: PluginConfig): ResolvedSwitches;
124
134
  /**
125
135
  * Install the hashline toolset for one agent inside its own effect, so the
@@ -17,11 +17,13 @@
17
17
  * describes no longer resolves. This module owns the replacement brief (`tool:rg`, see
18
18
  * `prompts/rg-guidelines.md`).
19
19
  *
20
- * ## Serving contract: the native grep's canonical value shape
21
- * The result value is the host grep's `{ matches: [{ path, lineNumber, line }] }`, so the existing
22
- * `dsh/shell-hook.ts` grep view re-reads each matched row from disk, serves it as `HASH│content` and
23
- * leases it whenever the `read` switch is on. This module renders and never serves: anchors stay
24
- * owned by one seam.
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.
25
27
  *
26
28
  * @module dsh-hashline-edit/rg/tools
27
29
  */
@@ -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;
@@ -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.2",
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",
@@ -1,7 +1,7 @@
1
1
  # rg guidelines
2
2
 
3
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 as `HASH│content` and is already served, so `edit`/`apply_patch` can target those anchors with no separate `read`.
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
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
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
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.
@@ -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.