dsh-hashline-edit 0.5.0 → 0.5.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 +84 -7
- package/cordis.patch.yml +20 -2
- package/lib/client.js +13 -3
- package/lib/index.js +2643 -78
- package/lib/types/dsh/codegraph/cli.d.ts +61 -0
- package/lib/types/dsh/codegraph/project.d.ts +27 -0
- package/lib/types/dsh/codegraph/tools.d.ts +36 -0
- package/lib/types/dsh/codegraph/view.d.ts +25 -0
- package/lib/types/dsh/diagnostics/cli.d.ts +76 -0
- package/lib/types/dsh/diagnostics/messages.d.ts +37 -0
- package/lib/types/dsh/diagnostics/parse.d.ts +39 -0
- package/lib/types/dsh/diagnostics/tools.d.ts +20 -0
- package/lib/types/dsh/diagnostics/view.d.ts +31 -0
- package/lib/types/dsh/guidance.d.ts +10 -4
- package/lib/types/dsh/hide.d.ts +6 -0
- package/lib/types/dsh/index.d.ts +51 -3
- package/lib/types/dsh/rg/cli.d.ts +67 -0
- package/lib/types/dsh/rg/command.d.ts +70 -0
- package/lib/types/dsh/rg/tools.d.ts +47 -0
- package/lib/types/dsh/rg/view.d.ts +81 -0
- package/lib/types/dsh/shell-view.d.ts +2 -2
- package/lib/types/dsh/tools/edit.d.ts +15 -1
- package/lib/types/dsh/tools/read-folded.d.ts +85 -0
- package/lib/types/src/domain-errors.d.ts +12 -1
- package/lib/types/src/edit-tool.d.ts +9 -1
- package/lib/types/src/mutation-engine/edit-expand.d.ts +36 -0
- package/lib/types/src/mutation-engine/edit-indent.d.ts +49 -0
- package/lib/types/src/mutation-engine/edit-request.d.ts +4 -0
- package/lib/types/src/mutation-engine/types.d.ts +57 -0
- package/lib/types/src/payload-contract.d.ts +4 -0
- package/lib/types/src/read-expansion/fold-skeleton.d.ts +32 -0
- package/lib/types/src/read-expansion/span-expansion.d.ts +26 -0
- package/package.json +1 -1
- package/prompts/codegraph-guidelines.md +8 -0
- package/prompts/diagnostics-guidelines.md +8 -0
- package/prompts/edit-guidelines.md +3 -1
- package/prompts/edit.md +3 -1
- package/prompts/read-description.md +1 -1
- package/prompts/read-guidelines.md +3 -1
- package/prompts/rg-guidelines.md +8 -0
- package/src/domain-errors.ts +52 -1
- package/src/edit-tool.ts +12 -1
- package/src/mutation-engine/edit-expand.ts +328 -0
- package/src/mutation-engine/edit-indent.ts +121 -0
- package/src/mutation-engine/edit-request.ts +4 -0
- package/src/mutation-engine/pipeline.ts +134 -48
- package/src/mutation-engine/types.ts +54 -0
- package/src/payload-contract.ts +74 -4
- package/src/read-expansion/ast-provider.ts +32 -0
- package/src/read-expansion/fold-skeleton.ts +56 -0
- package/src/read-expansion/qualified-names.ts +7 -0
- package/src/read-expansion/read-provider.ts +9 -0
- package/src/read-expansion/span-expansion.ts +26 -0
|
@@ -0,0 +1,47 @@
|
|
|
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 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.
|
|
25
|
+
*
|
|
26
|
+
* @module dsh-hashline-edit/rg/tools
|
|
27
|
+
*/
|
|
28
|
+
import { type ToolDefinition } from "@deepseek-ai/dsh-tools";
|
|
29
|
+
import { type RgInvocation, type RgResolution, type RgRunOptions, type RgRunResult } from "./cli.js";
|
|
30
|
+
/** The tool name this module registers: the executable it runs, deliberately not `grep`. */
|
|
31
|
+
export declare const RG_TOOL_NAME = "rg";
|
|
32
|
+
/** What one agent install hands the tool. */
|
|
33
|
+
export interface RgToolOptions {
|
|
34
|
+
/** ripgrep locator; defaults to the real PATH resolution. Re-run per call, so a PATH change is seen. */
|
|
35
|
+
readonly resolveRg?: (() => RgResolution) | undefined;
|
|
36
|
+
/** Search runner; defaults to the real spawn. */
|
|
37
|
+
readonly run?: ((invocation: RgInvocation, args: readonly string[], options: RgRunOptions) => Promise<RgRunResult>) | undefined;
|
|
38
|
+
/** Per-call wall clock budget; defaults to {@link RG_TIMEOUT_MS}. */
|
|
39
|
+
readonly timeoutMs?: number | undefined;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Build the `rg` tool definition.
|
|
43
|
+
*
|
|
44
|
+
* @param options - optional seams: a ripgrep locator, a runner and the wall clock budget.
|
|
45
|
+
* @returns the tool definition, ready for a scoped registration.
|
|
46
|
+
*/
|
|
47
|
+
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 {};
|
|
@@ -95,8 +95,8 @@ export declare function align(stdoutLines: readonly string[], fileLines: readonl
|
|
|
95
95
|
* @returns the plan, or `undefined` when the host must pass the output through.
|
|
96
96
|
*/
|
|
97
97
|
export declare function plan(deps: ToolDependencies, request: ShellViewRequest): Promise<ShellViewPlan | undefined>;
|
|
98
|
-
/**
|
|
99
|
-
export declare const
|
|
98
|
+
/** Every tool whose result this view serves — the native grep and this plugin's `rg`. */
|
|
99
|
+
export declare const GREP_TOOL_NAMES: readonly string[];
|
|
100
100
|
/** The host `grepMaxMatches` default (`@deepseek-ai/dsh-tool-fs-search` `Config`). */
|
|
101
101
|
export declare const GREP_INLINE_MAX_MATCHES = 250;
|
|
102
102
|
/**
|
|
@@ -1,3 +1,17 @@
|
|
|
1
1
|
import type { ToolDefinition } from "@deepseek-ai/dsh-tools";
|
|
2
2
|
import type { ToolDependencies } from "../contracts.js";
|
|
3
|
-
|
|
3
|
+
import type { SpanProvider } from "../../src/read-expansion/span-expansion.js";
|
|
4
|
+
/**
|
|
5
|
+
* Optional seams of the dsh edit adapter; `spanProvider` overrides the AST span provider an
|
|
6
|
+
* `expand: "item"` payload reads (ADR-0031).
|
|
7
|
+
*/
|
|
8
|
+
export interface EditToolOptions {
|
|
9
|
+
spanProvider?: SpanProvider;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Build the dsh `edit` tool for one agent install.
|
|
13
|
+
* @param deps - the host seams this tool may touch; `sandbox` advertises and resolves escalation.
|
|
14
|
+
* @param options - optional span provider override for `expand: "item"`.
|
|
15
|
+
* @returns a registry-ready dsh tool definition named `edit`.
|
|
16
|
+
*/
|
|
17
|
+
export declare function buildEditTool(deps: ToolDependencies, options?: EditToolOptions): ToolDefinition;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The folded read mode: a large file's structural skeleton instead of every line.
|
|
3
|
+
*
|
|
4
|
+
* One output row per retained syntax item, in file order, showing the item's own verbatim opening
|
|
5
|
+
* line and the item's range anchors — `HASH│line` for a single-line item, `HASH1..HASH2│line` for a
|
|
6
|
+
* multi-line one — so a whole item is one anchored range a following edit can replace or delete
|
|
7
|
+
* without ever finding its closing brace. A run of lines that belongs to no retained item becomes
|
|
8
|
+
* ONE elided-gap row carrying the run's own first..last anchors and its exact line count, so the
|
|
9
|
+
* model can see what it did not see.
|
|
10
|
+
*
|
|
11
|
+
* WHY the rows reuse the served seam: both anchors of a range row must be the real served anchors of
|
|
12
|
+
* the item's first and last line, leased to this session, or the range edit this mode exists for
|
|
13
|
+
* fails with `E_UNKNOWN_ANCHOR`. This module owns the layout; the caller serves the lines through
|
|
14
|
+
* the read tool's own serve path and hands back each line's anchor and text.
|
|
15
|
+
*
|
|
16
|
+
* Fail open: a file with no grammar, an unparsable tree or an unanchorable skeleton is not an error.
|
|
17
|
+
* The caller renders the exact served page with one note row instead — never a guessed row.
|
|
18
|
+
*
|
|
19
|
+
* @module dsh-hashline-edit/tools/read-folded
|
|
20
|
+
*/
|
|
21
|
+
import { type AdmittedRequest, type RawReadParams } from "../../src/file-content/admission.js";
|
|
22
|
+
import type { SkeletonItem, SpanDecline } from "../../src/read-expansion/span-expansion.js";
|
|
23
|
+
/** One anchored line the caller served for this page. */
|
|
24
|
+
interface FoldedLine {
|
|
25
|
+
/** 1-based line number the anchor addresses. */
|
|
26
|
+
readonly line: number;
|
|
27
|
+
/** The line's served anchor. */
|
|
28
|
+
readonly hash: string;
|
|
29
|
+
/** The line's decoded text, without the anchor prefix. */
|
|
30
|
+
readonly text: string;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Serves exactly these 1-based lines and returns each one's anchor and text. Structurally the read
|
|
34
|
+
* tool's own served-row shape, redeclared here so the layout module does not import the tool that
|
|
35
|
+
* imports it.
|
|
36
|
+
*/
|
|
37
|
+
type FoldedServe = (lineNumbers: readonly number[]) => Promise<readonly FoldedLine[]>;
|
|
38
|
+
/** A folded read's admitted payload: the plain request under it, and the depth it reveals. */
|
|
39
|
+
export interface FoldedRead {
|
|
40
|
+
readonly request: AdmittedRequest;
|
|
41
|
+
readonly foldDepth: number;
|
|
42
|
+
}
|
|
43
|
+
/** Everything one folded page needs from the read it belongs to. */
|
|
44
|
+
export interface FoldedPageInput {
|
|
45
|
+
/** The file as the caller named it; the page header labels it with this spelling. */
|
|
46
|
+
readonly file: string;
|
|
47
|
+
/** The file's total visible lines — never the retained count. */
|
|
48
|
+
readonly totalLines: number;
|
|
49
|
+
readonly foldDepth: number;
|
|
50
|
+
readonly items: readonly SkeletonItem[];
|
|
51
|
+
readonly serve: FoldedServe;
|
|
52
|
+
}
|
|
53
|
+
/** The rendered skeleton text: the page header followed by one row per region. */
|
|
54
|
+
export interface FoldedPage {
|
|
55
|
+
readonly text: string;
|
|
56
|
+
}
|
|
57
|
+
/** Why a folded read fell open to the served page. */
|
|
58
|
+
export type FoldedUnavailable = SpanDecline["refusal"] | "provider_error" | "unanchored" | "empty_file";
|
|
59
|
+
/**
|
|
60
|
+
* Admits `mode: "folded"`: the depth it reveals, plus the plain request underneath it.
|
|
61
|
+
*
|
|
62
|
+
* WHY it strips the folded fields before handing the rest to the shared admission: the folded page
|
|
63
|
+
* never reaches `prepareFile` (whose render mode is `served`/`verbatim`), so the fields that shape
|
|
64
|
+
* a window page are refused here rather than silently ignored — a folded read always covers the
|
|
65
|
+
* whole file. An out-of-range depth and a depth without the mode both fail closed.
|
|
66
|
+
*
|
|
67
|
+
* @param params - the raw tool payload.
|
|
68
|
+
* @returns the folded admission, or `undefined` when the payload is not a folded read.
|
|
69
|
+
*/
|
|
70
|
+
export declare function admitFoldedRequest(params: RawReadParams): FoldedRead | undefined;
|
|
71
|
+
/**
|
|
72
|
+
* Render the skeleton page: one row per region, in file order, each carrying its anchors.
|
|
73
|
+
*
|
|
74
|
+
* @param input - the file, its total, the depth and the served lines' anchors.
|
|
75
|
+
* @returns the page, or `undefined` when a region's first or last line has no served anchor (the
|
|
76
|
+
* caller then falls open to the served page — a row with a guessed anchor is never emitted).
|
|
77
|
+
*/
|
|
78
|
+
export declare function renderFoldedPage(input: FoldedPageInput): Promise<FoldedPage | undefined>;
|
|
79
|
+
/**
|
|
80
|
+
* The one note row a folded read that fell open states first, so the model never mistakes the served
|
|
81
|
+
* page that follows for a skeleton.
|
|
82
|
+
* @param reason - why folding was unavailable.
|
|
83
|
+
*/
|
|
84
|
+
export declare function foldedUnavailableNote(reason: FoldedUnavailable): string;
|
|
85
|
+
export {};
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
* See ADR-0047.
|
|
29
29
|
*/
|
|
30
30
|
export type Audience = "MODEL" | "USER";
|
|
31
|
-
export type DomainErrorCode = "E_BAD_PAYLOAD" | "E_EMPTY_RANGE" | "E_STALE_ANCHOR" | "E_UNKNOWN_ANCHOR" | "E_FOREIGN_ANCHOR" | "E_STALE_RANGE" | "E_TARGET_LOST" | "E_UNVERIFIED_RANGE" | "E_MALFORMED_ANCHOR" | "E_SUSPICIOUS_TEXT" | "E_BATCH_ABORT" | "E_NOOP_LOOP" | "E_UNSUPPORTED_FILE" | "E_ACCESS" | "E_NOT_FOUND" | "E_UNDO_STALE" | "E_UNDO_UNAVAILABLE" | "E_LOSSY_TEXT" | "E_UNDO_REVERT_FAILED" | "E_UNKNOWN" | "E_LARGE_FILE" | "E_INTERNAL_INVARIANT" | "E_PATCH_SYNTAX" | "E_UNIQUE_MATCH";
|
|
31
|
+
export type DomainErrorCode = "E_BAD_PAYLOAD" | "E_EMPTY_RANGE" | "E_STALE_ANCHOR" | "E_UNKNOWN_ANCHOR" | "E_FOREIGN_ANCHOR" | "E_STALE_RANGE" | "E_TARGET_LOST" | "E_UNVERIFIED_RANGE" | "E_MALFORMED_ANCHOR" | "E_SUSPICIOUS_TEXT" | "E_BATCH_ABORT" | "E_NOOP_LOOP" | "E_UNSUPPORTED_FILE" | "E_ACCESS" | "E_NOT_FOUND" | "E_UNDO_STALE" | "E_UNDO_UNAVAILABLE" | "E_LOSSY_TEXT" | "E_UNDO_REVERT_FAILED" | "E_UNKNOWN" | "E_LARGE_FILE" | "E_INTERNAL_INVARIANT" | "E_PATCH_SYNTAX" | "E_UNIQUE_MATCH" | "E_EXPAND_UNAVAILABLE";
|
|
32
32
|
/**
|
|
33
33
|
* The registered tool whose call produced an `E_BAD_PAYLOAD`. WHY the registered name: the model
|
|
34
34
|
* reads the tool list, so `undo_last_edit` names the call it must repair and a short form would
|
|
@@ -56,6 +56,12 @@ export interface ServedRow {
|
|
|
56
56
|
}
|
|
57
57
|
export type RangeCause = "retirement" | "never-served" | "served-range staleness" | "anchor staleness" | "served span";
|
|
58
58
|
export declare function isRangeCause(value: unknown): value is RangeCause;
|
|
59
|
+
/**
|
|
60
|
+
* Why `expand: "item"` could not place the anchor in one syntax item (ADR-0031). Registry-owned so
|
|
61
|
+
* the payload union and its renderer cannot drift; the AST provider's own refusal vocabulary stays
|
|
62
|
+
* internal to the expansion seam and never reaches the model.
|
|
63
|
+
*/
|
|
64
|
+
export type ExpandUnavailableReason = "non-code" | "grammar-unavailable" | "no-enclosing-item" | "stale-content";
|
|
59
65
|
export interface ErrorPayloadMap {
|
|
60
66
|
E_BAD_PAYLOAD: {
|
|
61
67
|
message: string;
|
|
@@ -194,6 +200,11 @@ export interface ErrorPayloadMap {
|
|
|
194
200
|
servedRows?: ServedRow[];
|
|
195
201
|
servedBlock?: string;
|
|
196
202
|
};
|
|
203
|
+
E_EXPAND_UNAVAILABLE: {
|
|
204
|
+
path: string;
|
|
205
|
+
line: number;
|
|
206
|
+
reason: ExpandUnavailableReason;
|
|
207
|
+
};
|
|
197
208
|
}
|
|
198
209
|
export interface CodeSpec<P> {
|
|
199
210
|
audience: Audience;
|
|
@@ -9,6 +9,14 @@
|
|
|
9
9
|
* Typed boundaries: validate once at admission (payload-contract via normReq/assertReq),
|
|
10
10
|
* trust inside. Immutable state: never mutates caller-owned request.
|
|
11
11
|
*/
|
|
12
|
+
import type { SpanProvider } from "./read-expansion/span-expansion.js";
|
|
13
|
+
/**
|
|
14
|
+
* The optional seams of the edit use case. `spanProvider` overrides the AST span provider an
|
|
15
|
+
* `expand: "item"` payload reads (ADR-0031); absent uses the engine's lazily created AST provider.
|
|
16
|
+
*/
|
|
17
|
+
export interface EditToolOptions {
|
|
18
|
+
spanProvider?: SpanProvider;
|
|
19
|
+
}
|
|
12
20
|
type EditToolContext = {
|
|
13
21
|
cwd: string;
|
|
14
22
|
sessionManager?: {
|
|
@@ -37,5 +45,5 @@ export interface EditTool {
|
|
|
37
45
|
/** SAFETY: Preview without persisting — mirrors pi's compPreview(request, cwd, ctx). The ctx must carry the session whose serves the anchors came from (#165). */
|
|
38
46
|
preview(request: unknown, cwd: string, ctx: PreviewContext): Promise<PreviewResult>;
|
|
39
47
|
}
|
|
40
|
-
export declare function createEditTool(): EditTool;
|
|
48
|
+
export declare function createEditTool(options?: EditToolOptions): EditTool;
|
|
41
49
|
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type HEdit, type LeaseSpanSource } from "../hashline/resolve.js";
|
|
2
|
+
import type { SpanProvider } from "../read-expansion/span-expansion.js";
|
|
3
|
+
import type { HashStore } from "../hash-store.js";
|
|
4
|
+
import type { ItemApplyOutcome } from "./types.js";
|
|
5
|
+
/** Everything the expansion needs from the pipeline's per-item state. */
|
|
6
|
+
export interface ExpandedItemInput {
|
|
7
|
+
/** The parsed item: its bounds name the licensing anchor, its `content_lines` the replacement. */
|
|
8
|
+
edit: HEdit;
|
|
9
|
+
/** The item's admitted `indent` mode, when it carried one. */
|
|
10
|
+
indent?: "auto";
|
|
11
|
+
/** The working buffer this item applies to. */
|
|
12
|
+
content: string;
|
|
13
|
+
/** Content hashes of `content`, indexed by line. */
|
|
14
|
+
hashes: string[];
|
|
15
|
+
/** The session's served mirror, used by the served hash echo gate only. */
|
|
16
|
+
served: (string | null)[];
|
|
17
|
+
/** Canon digests parallel to `served`; empty means no evidence. */
|
|
18
|
+
canonDigests: (string | null)[];
|
|
19
|
+
identity: LeaseSpanSource;
|
|
20
|
+
absolutePath: string;
|
|
21
|
+
/** The path the model named, for refusal text. */
|
|
22
|
+
filePath: string;
|
|
23
|
+
mode: "general" | "literal";
|
|
24
|
+
sessionKey: string;
|
|
25
|
+
store: HashStore;
|
|
26
|
+
blockedHashes?: ReadonlySet<string>;
|
|
27
|
+
/** Override seam; absent means the lazily created AST provider. */
|
|
28
|
+
provider: SpanProvider | undefined;
|
|
29
|
+
signal?: AbortSignal;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Apply one `expand: "item"` item: license the anchor, resolve the enclosing item, splice the
|
|
33
|
+
* replacement, and return the same outcome shape a range edit returns so every later stage (identity
|
|
34
|
+
* bookkeeping, drift, undo, commit, serve) is shared.
|
|
35
|
+
*/
|
|
36
|
+
export declare function applyExpandedItem(input: ExpandedItemInput): Promise<ItemApplyOutcome>;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auto relative indentation for `edit` payloads (`indent: "auto"`, ADR-0030).
|
|
3
|
+
*
|
|
4
|
+
* The anchor line supplies the base indentation; the payload supplies the block. A snippet written
|
|
5
|
+
* flush-left — or uniformly indented, as a model naturally writes one — is re-based onto the anchor
|
|
6
|
+
* line so the written bytes land at the depth the model meant, without the model having to count the
|
|
7
|
+
* anchor's columns and without a re-read to learn them.
|
|
8
|
+
*
|
|
9
|
+
* The transform is pure and literal: the common prefix is measured over the payload's own characters,
|
|
10
|
+
* so a tab stays a tab and a space stays a space, and an empty (or whitespace-only) line is never
|
|
11
|
+
* padded. Nothing here mutates; the pipeline decides where the result goes.
|
|
12
|
+
*/
|
|
13
|
+
/** The leading whitespace of one line — spaces and tabs only, matched as written. */
|
|
14
|
+
export declare function leadingWhitespaceOf(line: string): string;
|
|
15
|
+
/** What one `indent: "auto"` transform did, so the model channel can report it without a re-read. */
|
|
16
|
+
export interface AutoIndentResult {
|
|
17
|
+
/** The payload text with the shared prefix removed and the base indent written onto every line. */
|
|
18
|
+
text: string;
|
|
19
|
+
/** True when at least one byte of the payload changed. */
|
|
20
|
+
changed: boolean;
|
|
21
|
+
/** How many non-blank payload lines differ from the submitted ones. */
|
|
22
|
+
changedLines: number;
|
|
23
|
+
/** The literal prefix removed from every non-blank line (`""` when none was shared). */
|
|
24
|
+
strippedPrefix: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Re-base `text` onto `baseIndent`: strip the payload's own longest common leading-whitespace prefix,
|
|
28
|
+
* then prefix every non-blank line with the base indent. Blank lines are carried through untouched
|
|
29
|
+
* (they are written as the model wrote them, never padded).
|
|
30
|
+
*/
|
|
31
|
+
export declare function applyAutoIndent(text: string, baseIndent: string): AutoIndentResult;
|
|
32
|
+
/** The applied-indentation facts one item reports through the warnings channel. */
|
|
33
|
+
export interface IndentSummary {
|
|
34
|
+
/** The anchor line's leading whitespace the payload was aligned to. */
|
|
35
|
+
baseIndent: string;
|
|
36
|
+
/** The payload's own shared prefix that was removed before the base indent was written. */
|
|
37
|
+
strippedPrefix: string;
|
|
38
|
+
/** How many non-blank payload lines moved. */
|
|
39
|
+
changedLines: number;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The model-facing note for one applied auto-indent. It reports facts only (the anchor's indentation,
|
|
43
|
+
* the removed prefix, the number of lines) so the model can see the written indentation without a
|
|
44
|
+
* re-read; it never asks the model to do anything.
|
|
45
|
+
*/
|
|
46
|
+
export declare function buildIndentNote(args: {
|
|
47
|
+
ref: string;
|
|
48
|
+
summary: IndentSummary;
|
|
49
|
+
}): string;
|
|
@@ -29,6 +29,10 @@ export type NormalizedEditItem = {
|
|
|
29
29
|
at: Placement;
|
|
30
30
|
payload: DesiredContent;
|
|
31
31
|
file?: string;
|
|
32
|
+
/** Admitted `indent` mode (ADR-0030); absent is `"as-is"`. */
|
|
33
|
+
indent?: "auto";
|
|
34
|
+
/** Admitted `expand` mode (ADR-0031): the AST decides the target span's end. */
|
|
35
|
+
expand?: "item";
|
|
32
36
|
};
|
|
33
37
|
export type NormalizedEditRequest = {
|
|
34
38
|
file: string;
|
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
import type { LineEnding } from "../edit-diff.js";
|
|
8
8
|
import type { ResolvedRange } from "../served-session/serve-render.js";
|
|
9
9
|
import type { HashStore } from "../hash-store.js";
|
|
10
|
+
import type { SpanProvider } from "../read-expansion/span-expansion.js";
|
|
11
|
+
import type { IndentSummary } from "./edit-indent.js";
|
|
10
12
|
export interface PipelineOptions {
|
|
11
13
|
/** Workspace root used to re-assert lifecycle path boundaries at commit time. */
|
|
12
14
|
workspaceRoot?: string;
|
|
@@ -36,6 +38,11 @@ export interface PipelineOptions {
|
|
|
36
38
|
* destination content is rewritten, so the rollback of that in-flight member is exercised.
|
|
37
39
|
*/
|
|
38
40
|
onAfterMoveRename?: (toAbsolutePath: string) => void | Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* Override seam for `expand: "item"` (ADR-0031): the AST span provider the expansion reads. Absent
|
|
43
|
+
* uses the lazily created AST provider, so a caller that never expands a node wires nothing.
|
|
44
|
+
*/
|
|
45
|
+
spanProvider?: SpanProvider;
|
|
39
46
|
}
|
|
40
47
|
/**
|
|
41
48
|
* The honest outcome of a failed multi-member commit's rollback attempt. `restored` members are
|
|
@@ -128,3 +135,53 @@ export interface ProcessedEditFile {
|
|
|
128
135
|
*/
|
|
129
136
|
lifecycle?: MemberLifecycle;
|
|
130
137
|
}
|
|
138
|
+
/** Where one item's replacement landed, in pre-item coordinates. */
|
|
139
|
+
interface ItemMutationSpan {
|
|
140
|
+
startLine: number;
|
|
141
|
+
endLine: number;
|
|
142
|
+
inserted: number;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* The outcome of applying ONE edit item. Both the range path (`applyOneEdit`) and the
|
|
146
|
+
* `expand: "item"` path (`applyExpandedItem`) return it, so the mutate loop's identity bookkeeping,
|
|
147
|
+
* counting, drift scan and commit are shared rather than forked per payload shape.
|
|
148
|
+
*/
|
|
149
|
+
interface AppliedItemOutcome {
|
|
150
|
+
kind: "applied";
|
|
151
|
+
content: string;
|
|
152
|
+
hashes: string[];
|
|
153
|
+
removedHashes: Set<string>;
|
|
154
|
+
range: ResolvedRange;
|
|
155
|
+
firstChangedLine: number | undefined;
|
|
156
|
+
lastChangedLine: number | undefined;
|
|
157
|
+
anchorWarnings: string[] | undefined;
|
|
158
|
+
literalBypass: boolean;
|
|
159
|
+
neverServedCount: number;
|
|
160
|
+
/** A span-ref move's retired source span, in pre-item coordinates. */
|
|
161
|
+
sourceRange: ResolvedRange | undefined;
|
|
162
|
+
/** Every line region the item mutated; the identity map splices exactly these. */
|
|
163
|
+
mutationSpans: ItemMutationSpan[] | undefined;
|
|
164
|
+
/** Honest per-item line counts for a span-ref item. */
|
|
165
|
+
mutationStats: {
|
|
166
|
+
addedLines: number;
|
|
167
|
+
removedLines: number;
|
|
168
|
+
} | undefined;
|
|
169
|
+
/** The applied auto-indentation, when `indent: "auto"` changed the payload. */
|
|
170
|
+
indent?: IndentSummary;
|
|
171
|
+
}
|
|
172
|
+
/** The outcome of an item whose replacement left the bytes unchanged. */
|
|
173
|
+
interface NoopItemOutcome {
|
|
174
|
+
kind: "noop";
|
|
175
|
+
range: ResolvedRange;
|
|
176
|
+
noopEdit: {
|
|
177
|
+
loc: string;
|
|
178
|
+
currentContent: string;
|
|
179
|
+
} | undefined;
|
|
180
|
+
anchorWarnings: string[] | undefined;
|
|
181
|
+
literalBypass: boolean;
|
|
182
|
+
neverServedCount: number;
|
|
183
|
+
indent?: IndentSummary;
|
|
184
|
+
}
|
|
185
|
+
/** One item's outcome: applied, or a noop that wrote nothing. */
|
|
186
|
+
export type ItemApplyOutcome = AppliedItemOutcome | NoopItemOutcome;
|
|
187
|
+
export {};
|
|
@@ -55,6 +55,10 @@ type NormalizedEditItem = {
|
|
|
55
55
|
target: AnchorSpan;
|
|
56
56
|
at: Placement;
|
|
57
57
|
payload: DesiredContent;
|
|
58
|
+
/** Admitted `indent` mode (ADR-0030); absent is `"as-is"`. */
|
|
59
|
+
indent?: "auto";
|
|
60
|
+
/** Admitted `expand` mode (ADR-0031): the AST decides the target span's end. */
|
|
61
|
+
expand?: "item";
|
|
58
62
|
};
|
|
59
63
|
export type NormalizedEditRequest = {
|
|
60
64
|
file: string;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The folded read's grammar side: which of a parsed file's nodes are its items, and how deeply each
|
|
3
|
+
* one nests.
|
|
4
|
+
*
|
|
5
|
+
* WHY the walk lives here and not in the read path: the answer is a property of the language's
|
|
6
|
+
* grammar and its decoration tables, exactly like the enclosing-scope seam beside it, so another
|
|
7
|
+
* grammar gains a skeleton by adding a kind table — never by teaching `read` a second tree walk.
|
|
8
|
+
*
|
|
9
|
+
* The walk reuses the enclosing-scope rules: only a node type the language's table owns is an item,
|
|
10
|
+
* and the file root is never one (it is the whole file, not a member of it).
|
|
11
|
+
*
|
|
12
|
+
* @module dsh-hashline-edit/read-expansion/fold-skeleton
|
|
13
|
+
*/
|
|
14
|
+
import type { SyntaxNodeLike } from "./ast-span.js";
|
|
15
|
+
import type { ScopeDecorator } from "./scope-decoration.js";
|
|
16
|
+
import type { SkeletonItem } from "./span-expansion.js";
|
|
17
|
+
import type { SpanKindTable } from "./span-kind.js";
|
|
18
|
+
/**
|
|
19
|
+
* Collect one parsed file's items in file order, each with its nesting level.
|
|
20
|
+
*
|
|
21
|
+
* A node is an item when the language's kind table owns its grammar type; the decorator then widens
|
|
22
|
+
* that node to the declaration's wrappers and leading documentation, so an item's span is the same
|
|
23
|
+
* span an enclosing-scope read would serve. Every other node is walked through unchanged, which is
|
|
24
|
+
* how a declaration wrapped in `export_statement` or reached through a `variable_declarator` is
|
|
25
|
+
* still found at the top level of its file.
|
|
26
|
+
*
|
|
27
|
+
* @param root - the parsed file's root node.
|
|
28
|
+
* @param kinds - the language's grammar-type to note-kind table.
|
|
29
|
+
* @param decorate - the language's scope decorator (wrapper ascent plus leading decoration).
|
|
30
|
+
* @returns every item, in file order, at its 1-based nesting depth.
|
|
31
|
+
*/
|
|
32
|
+
export declare function collectSkeletonItems(root: SyntaxNodeLike, kinds: SpanKindTable, decorate: ScopeDecorator): SkeletonItem[];
|
|
@@ -21,6 +21,26 @@ interface AnchorWindow {
|
|
|
21
21
|
}
|
|
22
22
|
/** The window shape the seam accepts; `read` delegates anchor resolution to admission. */
|
|
23
23
|
export type SpanWindow = OffsetWindow | AnchorWindow;
|
|
24
|
+
/**
|
|
25
|
+
* One retained syntax item of a folded read: the 1-indexed, inclusive lines its span covers and its
|
|
26
|
+
* nesting level. The span is the language's decorated item — wrappers and leading documentation
|
|
27
|
+
* included — so a range built from it is the whole item an edit replaces or deletes.
|
|
28
|
+
*/
|
|
29
|
+
export interface SkeletonItem {
|
|
30
|
+
/** 1-indexed first line of the item's span. */
|
|
31
|
+
readonly startLine: number;
|
|
32
|
+
/** 1-indexed last line of the item's span. */
|
|
33
|
+
readonly endLine: number;
|
|
34
|
+
/** 1 is a top-level item; a declaration nested inside another item is one deeper. */
|
|
35
|
+
readonly depth: number;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* What a skeleton attempt answered: the file's items in file order, or the typed reason it has no
|
|
39
|
+
* skeleton. A decline is not an error — the folded read renders the exact served page instead.
|
|
40
|
+
*/
|
|
41
|
+
export type SkeletonAnswer = {
|
|
42
|
+
readonly items: readonly SkeletonItem[];
|
|
43
|
+
} | SpanDecline;
|
|
24
44
|
/**
|
|
25
45
|
* The boundary provider seam. A provider may answer synchronously now and asynchronously once a
|
|
26
46
|
* grammar has to be fetched, so the read path always awaits it. `around_anchor` windows reach the
|
|
@@ -33,6 +53,12 @@ export interface SpanProvider {
|
|
|
33
53
|
readonly runtimeAbsent?: boolean;
|
|
34
54
|
/** Start grammar fetches off the read path; session_start calls this without awaiting. */
|
|
35
55
|
prefetch?: (cwd?: string) => void | Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* Optional: the whole file's structural skeleton, for the folded read mode. A provider that can
|
|
58
|
+
* name a file's items answers them in file order; one that cannot declines with the same typed
|
|
59
|
+
* vocabulary `enclosingSpan` uses.
|
|
60
|
+
*/
|
|
61
|
+
skeleton?(file: string): SkeletonAnswer | Promise<SkeletonAnswer>;
|
|
36
62
|
}
|
|
37
63
|
/**
|
|
38
64
|
* Only a folded requested span at or below this size triggers expansion. Folding happens first, so
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-hashline-edit",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.2",
|
|
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",
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# codegraph guidelines
|
|
2
|
+
|
|
3
|
+
- Prefer `codegraph_explore` over grep/find for structural questions — architecture, a flow from X to Y, where a symbol lives, what would break — whenever the workspace has a `.codegraph` index: one call returns the relevant source plus the call paths a text search cannot follow.
|
|
4
|
+
- Source returned by `codegraph_explore`, `codegraph_node` and `codegraph_context` is served as `HASH│content` rows and is therefore already read: edit it with the anchors it shows instead of reading the file again.
|
|
5
|
+
- Use `codegraph_search`, `codegraph_callers`, `codegraph_callees`, `codegraph_impact` and `codegraph_implementations` for one-hop follow-ups; they return locations only, so call `codegraph_node` when a body is needed.
|
|
6
|
+
- A call that reports no `.codegraph` index means the workspace is not indexed: do not index it yourself, ask the user first (`codegraph init` in the repository root).
|
|
7
|
+
- The `.codegraph` index is derived state: when a call reports stale or empty results, `codegraph sync` in the project root refreshes it.
|
|
8
|
+
- Served rows stay editable for the rest of the session while the file is unchanged: anchor leases survive later edits (unchanged lines keep their anchors, changed lines come back with fresh ones), so chain edits without re-reading. An external write to the file, or a different session, invalidates them — a refusal returns the current rows as a fresh serve.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# diagnostics guidelines
|
|
2
|
+
|
|
3
|
+
- Prefer `diagnostics` over re-reading a build log: one call turns a compiler's or linter's errors and warnings into anchored rows for the files it names.
|
|
4
|
+
- Every block is served as `HASH│content` rows and is therefore already read: fix the file with those anchors instead of reading it again.
|
|
5
|
+
- The row a diagnostic points at is named in the header above its block (`— path:line:col`); the rows stay byte-identical to a `read` page, so the marker never appears inside them.
|
|
6
|
+
- `tool` picks the toolchain: `cargo-check` and `cargo-clippy` for Rust, `tsc` for TypeScript. Run it from — or pass `cwd` as — the directory the toolchain expects: the cargo workspace root, or the one holding `tsconfig.json`.
|
|
7
|
+
- Narrow the report with `maxDiagnostics` and widen each snippet with `contextLines` (1-10) rather than reading a whole file around one error.
|
|
8
|
+
- A result that reports a missing toolchain, a missing `tsconfig.json` or no parseable output is guidance, not a failure: fix the invocation or ask the user how the project is built instead of retrying blindly.
|
|
@@ -6,5 +6,7 @@
|
|
|
6
6
|
- edit: a stale or unknown anchor, or an overlapping range, rejects the whole call and writes nothing. A `text` payload echoing served rows in default top-level `mode: "general"` is refused (`E_SUSPICIOUS_TEXT`); prefer `text_ref` to duplicate or move served spans, or set top-level `mode: "literal"` when `text` must intentionally reproduce served lines.
|
|
7
7
|
- edit: anchors already in context (from `read`, an auto-read, or an intercepted shell view that output `HASH│content` rows) need no re-read; an anchor rejection serves the current `HASH│content` rows back, so repair directly from those rows instead of re-reading or guessing.
|
|
8
8
|
- edit: to insert without touching the anchor line, use `after` or `before` — `{ "anchor_from": "aB3", "after": " x: 1," }` adds one line below; the payload is bare file content and never restates the anchor line (`at` + `text` is the older spelling of the same insertion and still accepted).
|
|
9
|
+
- edit: `indent: "auto"` (optional; default `"as-is"`) writes a flush-left or uniformly indented `text`/`after`/`before` payload at the depth of the `anchor_from` line — the tool strips the payload's shared leading-whitespace prefix and keeps tabs, spaces and blank lines as written. `text_ref` refuses `indent` (copied bytes are verbatim). The result's notes report the lines it moved.
|
|
10
|
+
- edit: `expand: "item"` (optional) replaces the whole syntax item containing `anchor_from` — its leading doc comment/attributes and its closing brace included — so name only `anchor_from` and send a `text` payload; `anchor_to`, `text_ref`, `after`/`before` and a non-in-place `at` are refused. Prefer it over a hand-written multi-line range when the intent is "replace this function/class/method": you do not reproduce the doc comment or the closing brace, and the diff shows the whole replaced node. It needs a shipped code grammar (rust, typescript, tsx, vue, python, go, java); a non-code file, an unavailable grammar, or an anchor outside any item refuses (`E_EXPAND_UNAVAILABLE`) and writes nothing. One expanded item per call.
|
|
9
11
|
- edit: a successful call that turns a clean file into one with parse errors appends a `[W_SYNTAX]` warning naming the damaged line; the write already landed, so re-read around that line and correct the range instead of repeating the call.
|
|
10
|
-
- edit: `write` is the whole-file path — use `write` to create a new file or replace every line, never `edit`.
|
|
12
|
+
- edit: `write` is the whole-file path — use `write` to create a new file or replace every line, never `edit`.
|
package/prompts/edit.md
CHANGED
|
@@ -1 +1,3 @@
|
|
|
1
|
-
Change one or more line ranges in one target text file with hash anchors: pass `file`, `edits` (one item per change), and optional top-level `mode` (`"general"` by default, or `"literal"`). Each item names one inclusive bare `{{HASH_LEN}}`-character anchor from before `│` in served rows (`anchor_from`), an optional second one closing a multi-line range (`anchor_to` — omit it to edit the single line `anchor_from` names; pass the identical hash to spell a single line explicitly), optional `at` (`"in-place"` by default; `"before"` or `"after"` inserts at a single-line target), and exactly one payload — `text` for replacement content (`""` deletes the span when `at` is `"in-place"`, and is a no-op with `"before"`/`"after"`) or `text_ref` (`{ anchor_from, anchor_to, file?, mode: "copy" | "cut" }`, whose two bounds are always required, where required `mode` `"copy"` re-inserts the served span's bytes and `"cut"` also deletes the source lines). One call targets one `file`; only `text_ref.file` may reference another served file as the copy/cut source (with `"cut"` deleting those source lines in the same correlated transaction). A rejected call writes nothing. Two shortcuts cover the common pure insertions: `after` and `before` each carry the exact lines to place immediately below or above the single line `anchor_from` names, instead of spelling `at` plus `text`. An item still carries exactly one payload — `text`, `text_ref`, `after`, or `before`.
|
|
1
|
+
Change one or more line ranges in one target text file with hash anchors: pass `file`, `edits` (one item per change), and optional top-level `mode` (`"general"` by default, or `"literal"`). Each item names one inclusive bare `{{HASH_LEN}}`-character anchor from before `│` in served rows (`anchor_from`), an optional second one closing a multi-line range (`anchor_to` — omit it to edit the single line `anchor_from` names; pass the identical hash to spell a single line explicitly), optional `at` (`"in-place"` by default; `"before"` or `"after"` inserts at a single-line target), and exactly one payload — `text` for replacement content (`""` deletes the span when `at` is `"in-place"`, and is a no-op with `"before"`/`"after"`) or `text_ref` (`{ anchor_from, anchor_to, file?, mode: "copy" | "cut" }`, whose two bounds are always required, where required `mode` `"copy"` re-inserts the served span's bytes and `"cut"` also deletes the source lines). One call targets one `file`; only `text_ref.file` may reference another served file as the copy/cut source (with `"cut"` deleting those source lines in the same correlated transaction). A rejected call writes nothing. Two shortcuts cover the common pure insertions: `after` and `before` each carry the exact lines to place immediately below or above the single line `anchor_from` names, instead of spelling `at` plus `text`. An item still carries exactly one payload — `text`, `text_ref`, `after`, or `before`.
|
|
2
|
+
|
|
3
|
+
Two optional modifiers change where and how much the payload replaces. `indent: "auto"` (default `"as-is"`) re-bases a `text`/`after`/`before` payload on the leading whitespace of the line `anchor_from` names: write the snippet flush-left — or at any uniform extra indentation — and the tool drops the snippet's own shared leading-whitespace prefix, then writes every non-blank line at the anchor line's depth. Tabs and spaces stay literal (no conversion), blank lines are left as written, and `text_ref` refuses `indent` because those bytes are copied verbatim; the result's notes name the depth it landed at. `expand: "item"` replaces the whole syntax item that contains `anchor_from` — its leading doc comment/attributes/decorators and its matching closing brace — instead of a range you spell out: name only `anchor_from` (`anchor_to` is refused, because the AST decides the end) with a `text` payload, on a shipped code grammar (rust, typescript, tsx, vue, python, go, java). Prefer `expand` over hand-writing a whole function, class or method: you never have to reproduce the doc comment or the closing brace, and the diff shows the expanded range it replaced. A non-code file, an unavailable grammar, or an anchor outside any syntax item refuses and writes nothing. An expanded item must be the only item in its call.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
Read a UTF-8 text file as hash-anchored `HASH│content` rows. Each anchor is the `edit` identity for that line, and only the bare `{{HASH_LEN}}` characters before `│` are the anchor. Served mode is the default; `mode: "verbatim"` returns plain text with no anchors and no line-budget cap (and does not register anchors for `edit`)
|
|
1
|
+
Read a UTF-8 text file as hash-anchored `HASH│content` rows. Each anchor is the `edit` identity for that line, and only the bare `{{HASH_LEN}}` characters before `│` are the anchor. Served mode is the default; `mode: "verbatim"` returns plain text with no anchors and no line-budget cap (and does not register anchors for `edit`); `mode: "folded"` returns the file's structural skeleton — one row per syntax item carrying that item's first and last anchors as `HASH1..HASH2│opening line` — and always covers the whole file, so it refuses `offset`/`limit`/`windows`. Supports `offset`/`limit` paging and `windows` to batch up to 16 disjoint ranges (`offset`/`limit`, or `around_anchor` + `radius` for an anchor already served in this session) in one call. Image, binary, and directory paths are refused (`E_UNSUPPORTED_FILE`).
|
|
@@ -2,4 +2,6 @@
|
|
|
2
2
|
- read: batch up to 16 disjoint ranges of a file in ONE call with `windows` — each using `offset`/`limit`, or `around_anchor` plus `radius` around an anchor already served in this session (unserved anchors are omitted with a warning). Read multiple files with parallel `read` calls, one file per call.
|
|
3
3
|
- read: keep requested windows compact (61 lines or fewer) — the tool automatically widens compact windows to their enclosing syntax block (capped at 80 lines for code/Markdown and 40 for plain text, noted `[widened …]`), so do not manually pad `offset`/`limit` margins. Single-page output is also bounded by a byte budget.
|
|
4
4
|
- read: omit `mode` for any file you might later edit (code, configs, READMEs) so rows carry anchors; pass `mode: "verbatim"` only for strictly read-only reference files (e.g., skill files), as `verbatim` is uncapped and records no anchors for `edit`.
|
|
5
|
-
- read: `read` accepts UTF-8 text files only — images, binary files, and directories are refused (`E_UNSUPPORTED_FILE`).
|
|
5
|
+
- read: `read` accepts UTF-8 text files only — images, binary files, and directories are refused (`E_UNSUPPORTED_FILE`).
|
|
6
|
+
- read: pass `mode: "folded"` to survey a large source file as its structural skeleton — one row per syntax item carrying that item's first and last anchors (`HASH1..HASH2│opening line`, or one anchor for a single-line item), with `foldDepth` 1-3 (default 1) revealing nested members. A folded read always covers the whole file and refuses `offset`/`limit`/`windows`.
|
|
7
|
+
- read: a folded range row is a whole-item target — copy its two anchors into `anchor_from` and `anchor_to` to replace or delete the item. A `… (N lines) …` row is a run the page did not show: its first..last anchors are served but its lines are not, so read that range with `offset`/`limit` before editing inside it.
|