dsh-hashline-edit 0.3.11 → 0.3.12
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/lib/index.js +45 -9
- package/lib/types/src/prompts-bundled.d.ts +11 -0
- package/package.json +3 -2
- package/src/prompts-bundled.ts +38 -0
- package/src/prompts.ts +21 -5
- package/prompts/apply-patch-guidelines.md +0 -10
- package/prompts/apply-patch.md +0 -1
- package/prompts/read-guidelines.md +0 -6
- package/prompts/read.md +0 -1
- package/prompts/undo-last-edit-guidelines.md +0 -2
- package/prompts/undo-last-edit-snippet.md +0 -1
- package/prompts/undo-last-edit.md +0 -1
- package/prompts/write-guidelines.md +0 -2
- package/prompts/write.md +0 -1
package/lib/index.js
CHANGED
|
@@ -1883,8 +1883,36 @@ function commandOf(args) {
|
|
|
1883
1883
|
return typeof command === "string" && command.length > 0 ? command : void 0;
|
|
1884
1884
|
}
|
|
1885
1885
|
|
|
1886
|
+
// src/prompts-bundled.ts
|
|
1887
|
+
var BUNDLED_PROMPTS = {
|
|
1888
|
+
"apply-patch-guidelines.md": `- apply_patch: one call = one transaction; batch related changes and split only when an earlier RESULT decides the next.
|
|
1889
|
+
- apply_patch: an identity hunk is \`@@<anchor>\` or \`@@<from>-<to>\` followed by \`+\` lines; an empty body deletes every row of the span. Minimal shape: \`*** Begin Patch\` / \`*** Update File: <path>\` / \`@@<anchor>\` / \`+<new line>\` / \`*** End Patch\`.
|
|
1890
|
+
- apply_patch: an identity anchor is the bare \`{{HASH_LEN}}\` characters before \`\u2502\` in a served row \u2014 never the whole row, never a line number; syntax is \`@@\` plus the anchor with no space between them.
|
|
1891
|
+
- apply_patch: served beats text \u2014 when this session served the file, an identity hunk is REQUIRED, not preferred; a fragment hunk is limited to a file or region this session never served, and a text match never licenses one.
|
|
1892
|
+
- apply_patch: anchors in hand mean no re-read \u2014 apply the identity hunk to the served rows instead of reading the file again; a rejection already serves the current rows back.
|
|
1893
|
+
- apply_patch: change only what the task changes \u2014 an identity hunk carries \`+\` lines for the edited region and no unchanged rows, so a small edit stays a small patch.
|
|
1894
|
+
- apply_patch: for a one-line or single-region change to a served file, one identity hunk is the whole call; do not switch to \`write\` because the file content is already in context.
|
|
1895
|
+
- apply_patch: hunks are validated against the pre-call file in order (overlapping ranges reject the batch); a fragment hunk must match exactly once \u2014 \`E_UNIQUE_MATCH\` writes nothing \u2014 while a stale or unknown anchor is rejected; both serve the current rows back.
|
|
1896
|
+
- apply_patch: a rejection writes nothing; retry from the served \`HASH\u2502content\` rows without another \`read\`.
|
|
1897
|
+
- apply_patch: success returns fresh anchors for the changed lines; a patch carries only the changed rows, so a new file or an every-line rewrite stays with \`write\`.`,
|
|
1898
|
+
"apply-patch.md": `Change an existing file with \`apply_patch\`; it is the default for every change to an existing file, including a one-line change. \`write\` is only for a new file or for a rewrite where every line changes; a partial change is never a whole-file replacement. Pass the complete patch as \`input\`. When this session already served the file \u2014 through \`read\`, \`grep\`, a \`bash\` view, or a previous \`apply_patch\` result \u2014 every hunk MUST be an identity hunk on a served row: reuse the bare anchor before \`\u2502\` (\`@@<anchor>\` to replace that row, \`@@<from>-<to>\` to replace a span whose anchors you hold), and add only the changed \`+\` lines rather than re-emitting rows you are not changing. Anchors already in hand need no re-read: patch them directly instead of calling \`read\` again. A fragment hunk (\`@@\` or \`@@ <context>\` matched by file text) is legal only for a file or region this session never served; if the file was served, a fragment hunk is the wrong tool even when the text matches, because it discards the anchor check that proves you edited the version you actually saw.`,
|
|
1899
|
+
"read-guidelines.md": `- read: call it for content the tool has never served you; a bash view or an auto-read already served the file, so \`apply_patch\` can use those rows.
|
|
1900
|
+
- read: batch several disjoint ranges in ONE call with \`windows\` \u2014 an offset/limit range, or \`around_anchor\` plus \`radius\` around a line this session served.
|
|
1901
|
+
- read: pass \`mode: "verbatim"\` when you will not \`apply_patch\` the file (config, docs, a README, skill files); otherwise omit it so the rows carry anchors.
|
|
1902
|
+
- read: a window of 61 lines or fewer may widen to its enclosing block; widened rows carry a \`[widened \u2026]\` note. Caps are 80 lines for code/Markdown and 40 for plain text.
|
|
1903
|
+
- read: read several files with parallel \`read\` calls, one file per call.
|
|
1904
|
+
- read: PNG/JPG/GIF/WebP files return as an image attachment for multimodal models; binary files and directories are refused.`,
|
|
1905
|
+
"read.md": `Reads a UTF-8 file as \`HASH\u2502content\` rows in served mode; each row's anchor is the \`apply_patch\` identity anchor for that line, and only the \`{{HASH_LEN}}\` characters before \`\u2502\` are the anchor. Pass \`mode: "verbatim"\` for plain text with no anchors when you will not apply_patch; verbatim is not capped by line budget. Batch disjoint ranges in one call with \`windows\` (offset/limit or \`around_anchor\`).`,
|
|
1906
|
+
"undo-last-edit-guidelines.md": `- undo_last_edit: reverts the most recent \`apply_patch\` batch that touched the file at \`path\`, and every member of that batch: text hunks plus file lifecycle actions (add/delete/move). The exception is a foreign \`cut\`: undo then restores the source file too. The file must still hold the edited bytes. An out-of-band write makes the call fail with \`E_UNDO_STALE\`, and the file stays byte-identical. Call it as soon as a result is bad.
|
|
1907
|
+
- undo_last_edit: a \`write\` to the file, or a later \`apply_patch\` batch, replaces the undo entry. A read, a bash view or an out-of-band write leaves the entry in place. An apply_patch result is bad when its diff shows \`-HASH\u2502\` rows for lines you meant to keep. Examples are a closing brace, an import, or a declaration.`,
|
|
1908
|
+
"undo-last-edit-snippet.md": `Undo the last \`apply_patch\` batch on the file at \`path\``,
|
|
1909
|
+
"undo-last-edit.md": `Undo the last \`apply_patch\` batch that touched the file at \`path\`, reverting the whole batch \u2014 every text hunk plus file lifecycle actions (add/delete/move) \u2014 to its previous state. Use when an \`apply_patch\` produced incorrect results (e.g., wrong content, duplicated lines, broken syntax). The file must be unchanged since that batch.`,
|
|
1910
|
+
"write-guidelines.md": `- write: the content is the complete file; a partial change stays an \`apply_patch\` identity hunk, even when the whole file is already in context.
|
|
1911
|
+
- write: never paste served \`HASH\u2502\` rows into the content; a line that reproduces a served row is refused as a served hash echo.`,
|
|
1912
|
+
"write.md": `Read a file before overwriting it with \`write\`. \`write\` replaces the whole file: use it for a new file, or for a rewrite where every line changes. For a change to part of an existing file, use \`apply_patch\` identity hunks on the served rows instead.`
|
|
1913
|
+
};
|
|
1914
|
+
|
|
1886
1915
|
// src/prompts.ts
|
|
1887
|
-
import { readFileSync } from "node:fs";
|
|
1888
1916
|
function applyReplacements(content, replacements) {
|
|
1889
1917
|
let out = content;
|
|
1890
1918
|
if (replacements) {
|
|
@@ -1894,13 +1922,21 @@ function applyReplacements(content, replacements) {
|
|
|
1894
1922
|
}
|
|
1895
1923
|
return out.split("{{HASH_LEN}}").join(String(HASH_LEN));
|
|
1896
1924
|
}
|
|
1925
|
+
function bundled(relativePath2) {
|
|
1926
|
+
const name2 = relativePath2.slice(relativePath2.lastIndexOf("/") + 1);
|
|
1927
|
+
const body = BUNDLED_PROMPTS[name2];
|
|
1928
|
+
if (body === void 0) {
|
|
1929
|
+
throw new Error(
|
|
1930
|
+
`unknown bundled prompt: ${relativePath2} (bundled: ${Object.keys(BUNDLED_PROMPTS).join(", ")})`
|
|
1931
|
+
);
|
|
1932
|
+
}
|
|
1933
|
+
return body;
|
|
1934
|
+
}
|
|
1897
1935
|
function loadP(relativePath2, replacements) {
|
|
1898
|
-
|
|
1899
|
-
return applyReplacements(content, replacements);
|
|
1936
|
+
return applyReplacements(bundled(relativePath2).trim(), replacements);
|
|
1900
1937
|
}
|
|
1901
1938
|
function loadGuide(relativePath2, replacements) {
|
|
1902
|
-
|
|
1903
|
-
return applyReplacements(content, replacements).split("\n").map((line) => line.trim()).filter((line) => line.startsWith("- ")).map((line) => line.slice(2));
|
|
1939
|
+
return applyReplacements(bundled(relativePath2), replacements).split("\n").map((line) => line.trim()).filter((line) => line.startsWith("- ")).map((line) => line.slice(2));
|
|
1904
1940
|
}
|
|
1905
1941
|
|
|
1906
1942
|
// dsh/guidance.ts
|
|
@@ -7104,7 +7140,7 @@ function findEnclosingScope(root, requestedStart, requestedEnd, scopeKinds) {
|
|
|
7104
7140
|
|
|
7105
7141
|
// src/read-expansion/grammar-cache.ts
|
|
7106
7142
|
import { createHash } from "node:crypto";
|
|
7107
|
-
import { existsSync as existsSync3, mkdirSync as mkdirSync5, readFileSync
|
|
7143
|
+
import { existsSync as existsSync3, mkdirSync as mkdirSync5, readFileSync, renameSync as renameSync4, rmSync, writeFileSync as writeFileSync2 } from "node:fs";
|
|
7108
7144
|
import { dirname as dirname7, join as join8 } from "node:path";
|
|
7109
7145
|
|
|
7110
7146
|
// src/read-expansion/grammar-manifest.ts
|
|
@@ -7199,7 +7235,7 @@ function readVerifiedCache(path, expected) {
|
|
|
7199
7235
|
if (!existsSync3(path)) return void 0;
|
|
7200
7236
|
let bytes;
|
|
7201
7237
|
try {
|
|
7202
|
-
bytes =
|
|
7238
|
+
bytes = readFileSync(path);
|
|
7203
7239
|
} catch {
|
|
7204
7240
|
discardCachedGrammar(path);
|
|
7205
7241
|
return void 0;
|
|
@@ -8479,7 +8515,7 @@ import {
|
|
|
8479
8515
|
constants as constants5,
|
|
8480
8516
|
existsSync as existsSync4,
|
|
8481
8517
|
mkdirSync as mkdirSync6,
|
|
8482
|
-
readFileSync as
|
|
8518
|
+
readFileSync as readFileSync2,
|
|
8483
8519
|
renameSync as renameSync5,
|
|
8484
8520
|
unlinkSync as unlinkSync2,
|
|
8485
8521
|
writeFileSync as writeFileSync3
|
|
@@ -8551,7 +8587,7 @@ function reasonOf2(error) {
|
|
|
8551
8587
|
function readConfigObject(path, onWarn) {
|
|
8552
8588
|
let raw;
|
|
8553
8589
|
try {
|
|
8554
|
-
raw =
|
|
8590
|
+
raw = readFileSync2(path, "utf-8");
|
|
8555
8591
|
} catch (error) {
|
|
8556
8592
|
if (!isMissingFile(error)) onWarn?.(`cannot read config ${path}: ${reasonOf2(error)}`);
|
|
8557
8593
|
return void 0;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GENERATED FILE — do not edit by hand.
|
|
3
|
+
*
|
|
4
|
+
* Source of truth: `prompts/*.md`. Regenerate with `node scripts/gen-prompts.mjs`
|
|
5
|
+
* (`pnpm run build` runs it first). The prose lives inline so reinstalling the plugin is
|
|
6
|
+
* the only way — and the only needed way — to change what the model reads.
|
|
7
|
+
*
|
|
8
|
+
* @module dsh-hashline-edit/prompts-bundled
|
|
9
|
+
*/
|
|
10
|
+
/** Every shipped prompt body, keyed by its `prompts/<name>.md` basename. */
|
|
11
|
+
export declare const BUNDLED_PROMPTS: Readonly<Record<string, string>>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-hashline-edit",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.12",
|
|
4
4
|
"description": "Hash-anchored read/apply_patch 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 is the only file-mutation entry point and commits one patch batch per transaction. Undo persists across restarts.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"anchors",
|
|
@@ -29,7 +29,6 @@
|
|
|
29
29
|
"files": [
|
|
30
30
|
"lib",
|
|
31
31
|
"cordis.patch.yml",
|
|
32
|
-
"prompts",
|
|
33
32
|
"src",
|
|
34
33
|
"README.md",
|
|
35
34
|
"LICENSE"
|
|
@@ -60,6 +59,8 @@
|
|
|
60
59
|
"format:fix": "oxfmt .",
|
|
61
60
|
"typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.dsh.json",
|
|
62
61
|
"build": "node scripts/build-dsh.mjs",
|
|
62
|
+
"prompts:gen": "node scripts/gen-prompts.mjs",
|
|
63
|
+
"prompts:check": "node scripts/gen-prompts.mjs --check",
|
|
63
64
|
"prepublishOnly": "node scripts/build-dsh.mjs && pnpm run typecheck && pnpm run lint && pnpm run test:win",
|
|
64
65
|
"canon:audit": "node scripts/canon-churn-audit.mjs",
|
|
65
66
|
"prepack": "node scripts/build-dsh.mjs",
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GENERATED FILE — do not edit by hand.
|
|
3
|
+
*
|
|
4
|
+
* Source of truth: `prompts/*.md`. Regenerate with `node scripts/gen-prompts.mjs`
|
|
5
|
+
* (`pnpm run build` runs it first). The prose lives inline so reinstalling the plugin is
|
|
6
|
+
* the only way — and the only needed way — to change what the model reads.
|
|
7
|
+
*
|
|
8
|
+
* @module dsh-hashline-edit/prompts-bundled
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/** Every shipped prompt body, keyed by its `prompts/<name>.md` basename. */
|
|
12
|
+
export const BUNDLED_PROMPTS: Readonly<Record<string, string>> = {
|
|
13
|
+
"apply-patch-guidelines.md": `- apply_patch: one call = one transaction; batch related changes and split only when an earlier RESULT decides the next.
|
|
14
|
+
- apply_patch: an identity hunk is \`@@<anchor>\` or \`@@<from>-<to>\` followed by \`+\` lines; an empty body deletes every row of the span. Minimal shape: \`*** Begin Patch\` / \`*** Update File: <path>\` / \`@@<anchor>\` / \`+<new line>\` / \`*** End Patch\`.
|
|
15
|
+
- apply_patch: an identity anchor is the bare \`{{HASH_LEN}}\` characters before \`│\` in a served row — never the whole row, never a line number; syntax is \`@@\` plus the anchor with no space between them.
|
|
16
|
+
- apply_patch: served beats text — when this session served the file, an identity hunk is REQUIRED, not preferred; a fragment hunk is limited to a file or region this session never served, and a text match never licenses one.
|
|
17
|
+
- apply_patch: anchors in hand mean no re-read — apply the identity hunk to the served rows instead of reading the file again; a rejection already serves the current rows back.
|
|
18
|
+
- apply_patch: change only what the task changes — an identity hunk carries \`+\` lines for the edited region and no unchanged rows, so a small edit stays a small patch.
|
|
19
|
+
- apply_patch: for a one-line or single-region change to a served file, one identity hunk is the whole call; do not switch to \`write\` because the file content is already in context.
|
|
20
|
+
- apply_patch: hunks are validated against the pre-call file in order (overlapping ranges reject the batch); a fragment hunk must match exactly once — \`E_UNIQUE_MATCH\` writes nothing — while a stale or unknown anchor is rejected; both serve the current rows back.
|
|
21
|
+
- apply_patch: a rejection writes nothing; retry from the served \`HASH│content\` rows without another \`read\`.
|
|
22
|
+
- apply_patch: success returns fresh anchors for the changed lines; a patch carries only the changed rows, so a new file or an every-line rewrite stays with \`write\`.`,
|
|
23
|
+
"apply-patch.md": `Change an existing file with \`apply_patch\`; it is the default for every change to an existing file, including a one-line change. \`write\` is only for a new file or for a rewrite where every line changes; a partial change is never a whole-file replacement. Pass the complete patch as \`input\`. When this session already served the file — through \`read\`, \`grep\`, a \`bash\` view, or a previous \`apply_patch\` result — every hunk MUST be an identity hunk on a served row: reuse the bare anchor before \`│\` (\`@@<anchor>\` to replace that row, \`@@<from>-<to>\` to replace a span whose anchors you hold), and add only the changed \`+\` lines rather than re-emitting rows you are not changing. Anchors already in hand need no re-read: patch them directly instead of calling \`read\` again. A fragment hunk (\`@@\` or \`@@ <context>\` matched by file text) is legal only for a file or region this session never served; if the file was served, a fragment hunk is the wrong tool even when the text matches, because it discards the anchor check that proves you edited the version you actually saw.`,
|
|
24
|
+
"read-guidelines.md": `- read: call it for content the tool has never served you; a bash view or an auto-read already served the file, so \`apply_patch\` can use those rows.
|
|
25
|
+
- read: batch several disjoint ranges in ONE call with \`windows\` — an offset/limit range, or \`around_anchor\` plus \`radius\` around a line this session served.
|
|
26
|
+
- read: pass \`mode: "verbatim"\` when you will not \`apply_patch\` the file (config, docs, a README, skill files); otherwise omit it so the rows carry anchors.
|
|
27
|
+
- read: a window of 61 lines or fewer may widen to its enclosing block; widened rows carry a \`[widened …]\` note. Caps are 80 lines for code/Markdown and 40 for plain text.
|
|
28
|
+
- read: read several files with parallel \`read\` calls, one file per call.
|
|
29
|
+
- read: PNG/JPG/GIF/WebP files return as an image attachment for multimodal models; binary files and directories are refused.`,
|
|
30
|
+
"read.md": `Reads a UTF-8 file as \`HASH│content\` rows in served mode; each row's anchor is the \`apply_patch\` identity anchor for that line, and only the \`{{HASH_LEN}}\` characters before \`│\` are the anchor. Pass \`mode: "verbatim"\` for plain text with no anchors when you will not apply_patch; verbatim is not capped by line budget. Batch disjoint ranges in one call with \`windows\` (offset/limit or \`around_anchor\`).`,
|
|
31
|
+
"undo-last-edit-guidelines.md": `- undo_last_edit: reverts the most recent \`apply_patch\` batch that touched the file at \`path\`, and every member of that batch: text hunks plus file lifecycle actions (add/delete/move). The exception is a foreign \`cut\`: undo then restores the source file too. The file must still hold the edited bytes. An out-of-band write makes the call fail with \`E_UNDO_STALE\`, and the file stays byte-identical. Call it as soon as a result is bad.
|
|
32
|
+
- undo_last_edit: a \`write\` to the file, or a later \`apply_patch\` batch, replaces the undo entry. A read, a bash view or an out-of-band write leaves the entry in place. An apply_patch result is bad when its diff shows \`-HASH│\` rows for lines you meant to keep. Examples are a closing brace, an import, or a declaration.`,
|
|
33
|
+
"undo-last-edit-snippet.md": `Undo the last \`apply_patch\` batch on the file at \`path\``,
|
|
34
|
+
"undo-last-edit.md": `Undo the last \`apply_patch\` batch that touched the file at \`path\`, reverting the whole batch — every text hunk plus file lifecycle actions (add/delete/move) — to its previous state. Use when an \`apply_patch\` produced incorrect results (e.g., wrong content, duplicated lines, broken syntax). The file must be unchanged since that batch.`,
|
|
35
|
+
"write-guidelines.md": `- write: the content is the complete file; a partial change stays an \`apply_patch\` identity hunk, even when the whole file is already in context.
|
|
36
|
+
- write: never paste served \`HASH│\` rows into the content; a line that reproduces a served row is refused as a served hash echo.`,
|
|
37
|
+
"write.md": `Read a file before overwriting it with \`write\`. \`write\` replaces the whole file: use it for a new file, or for a rewrite where every line changes. For a change to part of an existing file, use \`apply_patch\` identity hunks on the served rows instead.`,
|
|
38
|
+
};
|
package/src/prompts.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { readFileSync } from "node:fs";
|
|
2
1
|
import { HASH_LEN } from "./hashline/alphabet.js";
|
|
2
|
+
import { BUNDLED_PROMPTS } from "./prompts-bundled.js";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Resolve template variables in shipped prompt prose. Beyond caller-supplied replacements, the
|
|
@@ -16,14 +16,30 @@ function applyReplacements(content: string, replacements?: Record<string, string
|
|
|
16
16
|
return out.split("{{HASH_LEN}}").join(String(HASH_LEN));
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
/**
|
|
20
|
+
* Resolve one prompt path to its bundled body.
|
|
21
|
+
*
|
|
22
|
+
* WHY a path rather than a bare name: callers have always named the prompt by its `prompts/`
|
|
23
|
+
* path, and that argument IS the lookup key, so a typo fails at the call site instead of
|
|
24
|
+
* silently serving an empty prompt. Nothing is read from disk — see `prompts-bundled.ts`.
|
|
25
|
+
*/
|
|
26
|
+
function bundled(relativePath: string): string {
|
|
27
|
+
const name = relativePath.slice(relativePath.lastIndexOf("/") + 1);
|
|
28
|
+
const body = BUNDLED_PROMPTS[name];
|
|
29
|
+
if (body === undefined) {
|
|
30
|
+
throw new Error(
|
|
31
|
+
`unknown bundled prompt: ${relativePath} (bundled: ${Object.keys(BUNDLED_PROMPTS).join(", ")})`,
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
return body;
|
|
35
|
+
}
|
|
36
|
+
|
|
19
37
|
export function loadP(relativePath: string, replacements?: Record<string, string>): string {
|
|
20
|
-
|
|
21
|
-
return applyReplacements(content, replacements);
|
|
38
|
+
return applyReplacements(bundled(relativePath).trim(), replacements);
|
|
22
39
|
}
|
|
23
40
|
|
|
24
41
|
export function loadGuide(relativePath: string, replacements?: Record<string, string>): string[] {
|
|
25
|
-
|
|
26
|
-
return applyReplacements(content, replacements)
|
|
42
|
+
return applyReplacements(bundled(relativePath), replacements)
|
|
27
43
|
.split("\n")
|
|
28
44
|
.map((line) => line.trim())
|
|
29
45
|
.filter((line) => line.startsWith("- "))
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
- apply_patch: one call = one transaction; batch related changes and split only when an earlier RESULT decides the next.
|
|
2
|
-
- apply_patch: an identity hunk is `@@<anchor>` or `@@<from>-<to>` followed by `+` lines; an empty body deletes every row of the span. Minimal shape: `*** Begin Patch` / `*** Update File: <path>` / `@@<anchor>` / `+<new line>` / `*** End Patch`.
|
|
3
|
-
- apply_patch: an identity anchor is the bare `{{HASH_LEN}}` characters before `│` in a served row — never the whole row, never a line number; syntax is `@@` plus the anchor with no space between them.
|
|
4
|
-
- apply_patch: served beats text — when this session served the file, an identity hunk is REQUIRED, not preferred; a fragment hunk is limited to a file or region this session never served, and a text match never licenses one.
|
|
5
|
-
- apply_patch: anchors in hand mean no re-read — apply the identity hunk to the served rows instead of reading the file again; a rejection already serves the current rows back.
|
|
6
|
-
- apply_patch: change only what the task changes — an identity hunk carries `+` lines for the edited region and no unchanged rows, so a small edit stays a small patch.
|
|
7
|
-
- apply_patch: for a one-line or single-region change to a served file, one identity hunk is the whole call; do not switch to `write` because the file content is already in context.
|
|
8
|
-
- apply_patch: hunks are validated against the pre-call file in order (overlapping ranges reject the batch); a fragment hunk must match exactly once — `E_UNIQUE_MATCH` writes nothing — while a stale or unknown anchor is rejected; both serve the current rows back.
|
|
9
|
-
- apply_patch: a rejection writes nothing; retry from the served `HASH│content` rows without another `read`.
|
|
10
|
-
- apply_patch: success returns fresh anchors for the changed lines; a patch carries only the changed rows, so a new file or an every-line rewrite stays with `write`.
|
package/prompts/apply-patch.md
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
Change an existing file with `apply_patch`; it is the default for every change to an existing file, including a one-line change. `write` is only for a new file or for a rewrite where every line changes; a partial change is never a whole-file replacement. Pass the complete patch as `input`. When this session already served the file — through `read`, `grep`, a `bash` view, or a previous `apply_patch` result — every hunk MUST be an identity hunk on a served row: reuse the bare anchor before `│` (`@@<anchor>` to replace that row, `@@<from>-<to>` to replace a span whose anchors you hold), and add only the changed `+` lines rather than re-emitting rows you are not changing. Anchors already in hand need no re-read: patch them directly instead of calling `read` again. A fragment hunk (`@@` or `@@ <context>` matched by file text) is legal only for a file or region this session never served; if the file was served, a fragment hunk is the wrong tool even when the text matches, because it discards the anchor check that proves you edited the version you actually saw.
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
- read: call it for content the tool has never served you; a bash view or an auto-read already served the file, so `apply_patch` can use those rows.
|
|
2
|
-
- read: batch several disjoint ranges in ONE call with `windows` — an offset/limit range, or `around_anchor` plus `radius` around a line this session served.
|
|
3
|
-
- read: pass `mode: "verbatim"` when you will not `apply_patch` the file (config, docs, a README, skill files); otherwise omit it so the rows carry anchors.
|
|
4
|
-
- read: a window of 61 lines or fewer may widen to its enclosing block; widened rows carry a `[widened …]` note. Caps are 80 lines for code/Markdown and 40 for plain text.
|
|
5
|
-
- read: read several files with parallel `read` calls, one file per call.
|
|
6
|
-
- read: PNG/JPG/GIF/WebP files return as an image attachment for multimodal models; binary files and directories are refused.
|
package/prompts/read.md
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
Reads a UTF-8 file as `HASH│content` rows in served mode; each row's anchor is the `apply_patch` identity anchor for that line, and only the `{{HASH_LEN}}` characters before `│` are the anchor. Pass `mode: "verbatim"` for plain text with no anchors when you will not apply_patch; verbatim is not capped by line budget. Batch disjoint ranges in one call with `windows` (offset/limit or `around_anchor`).
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
- undo_last_edit: reverts the most recent `apply_patch` batch that touched the file at `path`, and every member of that batch: text hunks plus file lifecycle actions (add/delete/move). The exception is a foreign `cut`: undo then restores the source file too. The file must still hold the edited bytes. An out-of-band write makes the call fail with `E_UNDO_STALE`, and the file stays byte-identical. Call it as soon as a result is bad.
|
|
2
|
-
- undo_last_edit: a `write` to the file, or a later `apply_patch` batch, replaces the undo entry. A read, a bash view or an out-of-band write leaves the entry in place. An apply_patch result is bad when its diff shows `-HASH│` rows for lines you meant to keep. Examples are a closing brace, an import, or a declaration.
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
Undo the last `apply_patch` batch on the file at `path`
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
Undo the last `apply_patch` batch that touched the file at `path`, reverting the whole batch — every text hunk plus file lifecycle actions (add/delete/move) — to its previous state. Use when an `apply_patch` produced incorrect results (e.g., wrong content, duplicated lines, broken syntax). The file must be unchanged since that batch.
|
package/prompts/write.md
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
Read a file before overwriting it with `write`. `write` replaces the whole file: use it for a new file, or for a rewrite where every line changes. For a change to part of an existing file, use `apply_patch` identity hunks on the served rows instead.
|