dsh-better-edit 0.8.2 → 1.1.0
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/CHANGELOG.md +173 -99
- package/README.md +61 -33
- package/README.zh.md +20 -17
- package/cordis.patch.yml +1 -1
- package/lib/constants.js +19 -4
- package/lib/contract.js +136 -79
- package/lib/domain-errors.js +570 -0
- package/lib/edit-diff.js +33 -7
- package/lib/file-encoding-state.js +27 -7
- package/lib/file-view.js +305 -82
- package/lib/fs-bridge.js +23 -7
- package/lib/guidance/materialize.js +7 -7
- package/lib/guidance/resolve.js +13 -8
- package/lib/hash-store.js +404 -278
- package/lib/hashline/anchor-pipeline.js +586 -378
- package/lib/hashline/hash-assign.js +21 -22
- package/lib/hashline/hash.js +6 -6
- package/lib/hashline/index.js +1 -1
- package/lib/hashline/resolve.js +1 -1
- package/lib/hashline/served-guard.js +181 -0
- package/lib/index.js +37 -11
- package/lib/mutation/engine.js +392 -96
- package/lib/mutation.js +22 -130
- package/lib/noop-guard.js +20 -9
- package/lib/prompts.js +20 -18
- package/lib/read-and-serve.js +44 -20
- package/lib/sandbox.js +1 -1
- package/lib/session-view.js +57 -43
- package/lib/snapshot-store/index.js +97 -0
- package/lib/snapshot-store/lineage-store.js +400 -0
- package/lib/snapshot-store/migrate.js +80 -0
- package/lib/snapshot-store/pairing.js +412 -0
- package/lib/snapshot-store/txn.js +63 -0
- package/lib/snapshot-store/vacuum.js +243 -0
- package/lib/store-lifecycle.js +13 -1
- package/lib/store-retry.js +34 -0
- package/lib/tool-edit.js +90 -44
- package/lib/tool-read.js +29 -1
- package/lib/tool-str-replace-editor.js +26 -18
- package/lib/tool-undo.js +25 -8
- package/lib/types/constants.d.ts +5 -2
- package/lib/types/contract.d.ts +76 -71
- package/lib/types/domain-errors.d.ts +410 -0
- package/lib/types/edit-response.d.ts +1 -1
- package/lib/types/file-encoding-state.d.ts +1 -0
- package/lib/types/file-view.d.ts +35 -6
- package/lib/types/guidance/materialize.d.ts +2 -2
- package/lib/types/guidance/resolve.d.ts +14 -2
- package/lib/types/hash-store.d.ts +38 -19
- package/lib/types/hashline/anchor-pipeline.d.ts +117 -36
- package/lib/types/hashline/hash-assign.d.ts +5 -5
- package/lib/types/hashline/hash.d.ts +1 -1
- package/lib/types/hashline/index.d.ts +2 -2
- package/lib/types/hashline/served-guard.d.ts +100 -0
- package/lib/types/index.d.ts +3 -3
- package/lib/types/mutation/engine.d.ts +49 -30
- package/lib/types/mutation.d.ts +1 -39
- package/lib/types/noop-guard.d.ts +4 -4
- package/lib/types/prompts.d.ts +1 -1
- package/lib/types/read-and-serve.d.ts +6 -0
- package/lib/types/sandbox.d.ts +1 -1
- package/lib/types/session-view.d.ts +38 -9
- package/lib/types/snapshot-store/index.d.ts +28 -0
- package/lib/types/snapshot-store/lineage-store.d.ts +96 -0
- package/lib/types/snapshot-store/migrate.d.ts +16 -0
- package/lib/types/snapshot-store/pairing.d.ts +99 -0
- package/lib/types/snapshot-store/txn.d.ts +12 -0
- package/lib/types/snapshot-store/vacuum.d.ts +79 -0
- package/lib/types/store-lifecycle.d.ts +0 -1
- package/lib/types/store-retry.d.ts +6 -0
- package/lib/types/tool-edit.d.ts +2 -2
- package/lib/types/tool-str-replace-editor.d.ts +2 -2
- package/lib/types/utils.d.ts +5 -6
- package/lib/types/workspace-context.d.ts +10 -1
- package/lib/undo-edit.js +27 -11
- package/lib/utils.js +12 -12
- package/lib/workspace-context.js +27 -9
- package/lib/write-hook.js +13 -4
- package/package.json +28 -30
|
@@ -9,7 +9,7 @@ import { errCode } from "../utils.js";
|
|
|
9
9
|
import { isBlankOverride } from "./parse.js";
|
|
10
10
|
import { GUIDANCE_SECTIONS } from "./resolve.js";
|
|
11
11
|
/** The presets shipped by the harness, each seeded with editable guidance. */
|
|
12
|
-
export const DEFAULT_PRESETS = ["standard", "
|
|
12
|
+
export const DEFAULT_PRESETS = ["standard", "ptc", "minimal", "cordis"];
|
|
13
13
|
/**
|
|
14
14
|
* The root README: the per-preset customization convention users see in the
|
|
15
15
|
* plugin home.
|
|
@@ -17,7 +17,7 @@ export const DEFAULT_PRESETS = ["standard", "code", "minimal", "cordis"];
|
|
|
17
17
|
export const GUIDANCE_HOME_README = `# dsh-better-edit guidance
|
|
18
18
|
|
|
19
19
|
Each agent preset has its own guidance directory here: \`<preset>/<section>.md\`.
|
|
20
|
-
On first boot the plugin seeds the shipped presets (\`standard\`, \`
|
|
20
|
+
On first boot the plugin seeds the shipped presets (\`standard\`, \`ptc\`,
|
|
21
21
|
\`minimal\`, \`cordis\`) with the compiled defaults; existing files are never
|
|
22
22
|
overwritten, so your edits survive.
|
|
23
23
|
|
|
@@ -31,13 +31,13 @@ Each file is one tool section:
|
|
|
31
31
|
|
|
32
32
|
Edit the \`<section>.md\` file for the preset and section you want to change —
|
|
33
33
|
the file body IS the text the model reads for that section. Files are read once
|
|
34
|
-
per agent
|
|
34
|
+
per agent when it is created (\`agent/created\`), so edits apply to new sessions.
|
|
35
35
|
|
|
36
36
|
An optional YAML front-matter fence places the section at a custom position in
|
|
37
37
|
the assembled system prompt:
|
|
38
38
|
|
|
39
39
|
---
|
|
40
|
-
order:
|
|
40
|
+
order: 1100
|
|
41
41
|
---
|
|
42
42
|
|
|
43
43
|
<section text>
|
|
@@ -55,7 +55,7 @@ seeded directory, copy a seeded one to its name.
|
|
|
55
55
|
export const GUIDANCE_HOME_README_ZH = `# dsh-better-edit 指引
|
|
56
56
|
|
|
57
57
|
每个 agent preset 在这里都有自己的指引目录:\`<preset>/<section>.md\`。首次启动时
|
|
58
|
-
插件会为随附的 preset(\`standard\`、\`
|
|
58
|
+
插件会为随附的 preset(\`standard\`、\`ptc\`、\`minimal\`、\`cordis\`)写入编译内置的
|
|
59
59
|
默认内容;已有文件绝不被覆盖,因此你的编辑会保留。
|
|
60
60
|
|
|
61
61
|
每个文件对应一个工具片段:
|
|
@@ -67,12 +67,12 @@ export const GUIDANCE_HOME_README_ZH = `# dsh-better-edit 指引
|
|
|
67
67
|
## 自定义
|
|
68
68
|
|
|
69
69
|
编辑你想修改的 preset 与片段的 \`<section>.md\` 文件即可——文件正文就是该片段呈
|
|
70
|
-
现给模型的文本。文件在 agent
|
|
70
|
+
现给模型的文本。文件在 agent 创建时(\`agent/created\`)读取一次,因此修改只影响新会话。
|
|
71
71
|
|
|
72
72
|
可以用可选的 YAML front-matter 栅栏把片段放到组装后系统提示中的自定义位置:
|
|
73
73
|
|
|
74
74
|
---
|
|
75
|
-
order:
|
|
75
|
+
order: 1100
|
|
76
76
|
---
|
|
77
77
|
|
|
78
78
|
<片段文本>
|
package/lib/guidance/resolve.js
CHANGED
|
@@ -12,7 +12,7 @@ import { errCode } from "../utils.js";
|
|
|
12
12
|
import { isBlankOverride, parseSectionFile } from "./parse.js";
|
|
13
13
|
/**
|
|
14
14
|
* Render one tool's guidance as its intro line, a blank line, then bullets.
|
|
15
|
-
* Uniform across the
|
|
15
|
+
* Uniform across the three sections: no tool-schema description is duplicated
|
|
16
16
|
* (that already reaches the model through the tool catalog).
|
|
17
17
|
*/
|
|
18
18
|
function guidanceText(g) {
|
|
@@ -26,19 +26,22 @@ export const GUIDANCE_SECTIONS = [
|
|
|
26
26
|
{
|
|
27
27
|
name: "tool:read",
|
|
28
28
|
file: "read.md",
|
|
29
|
-
defaultOrder:
|
|
29
|
+
defaultOrder: 1100,
|
|
30
|
+
orderName: "TOOL_READ",
|
|
30
31
|
renderDefault: () => guidanceText(READ_GUIDANCE),
|
|
31
32
|
},
|
|
32
33
|
{
|
|
33
34
|
name: "tool:edit",
|
|
34
35
|
file: "edit.md",
|
|
35
|
-
defaultOrder:
|
|
36
|
+
defaultOrder: 1300,
|
|
37
|
+
orderName: "TOOL_EDIT",
|
|
36
38
|
renderDefault: () => guidanceText(EDIT_GUIDANCE),
|
|
37
39
|
},
|
|
38
40
|
{
|
|
39
41
|
name: "tool:undo_last_edit",
|
|
40
42
|
file: "undo_last_edit.md",
|
|
41
|
-
|
|
43
|
+
// Immediately after the edit slot it annotates; there is no TOOL_UNDO name.
|
|
44
|
+
defaultOrder: 1310,
|
|
42
45
|
renderDefault: () => guidanceText(UNDO_GUIDANCE),
|
|
43
46
|
},
|
|
44
47
|
];
|
|
@@ -67,6 +70,7 @@ export async function resolveSection(name, options) {
|
|
|
67
70
|
const section = SECTION_BY_NAME.get(name);
|
|
68
71
|
if (!section)
|
|
69
72
|
throw new Error(`unknown guidance section: ${name}`);
|
|
73
|
+
const defaultOrder = options.defaultOrder?.(section) ?? section.defaultOrder;
|
|
70
74
|
for (const candidate of overrideCandidates(section.file, options)) {
|
|
71
75
|
const content = await readFile(candidate, "utf-8").catch((error) => {
|
|
72
76
|
if (errCode(error) === "ENOENT")
|
|
@@ -80,7 +84,7 @@ export async function resolveSection(name, options) {
|
|
|
80
84
|
// A broken override must never reach the model. Resolve to the
|
|
81
85
|
// compiled default and report the file + parse reason to the caller.
|
|
82
86
|
return {
|
|
83
|
-
order:
|
|
87
|
+
order: defaultOrder,
|
|
84
88
|
text: section.renderDefault(),
|
|
85
89
|
malformed: {
|
|
86
90
|
file: candidate,
|
|
@@ -92,19 +96,20 @@ export async function resolveSection(name, options) {
|
|
|
92
96
|
// fallback chain rather than render an empty section.
|
|
93
97
|
if (isBlankOverride(content))
|
|
94
98
|
continue;
|
|
95
|
-
return { order: parsed.order ??
|
|
99
|
+
return { order: parsed.order ?? defaultOrder, text: parsed.text };
|
|
96
100
|
}
|
|
97
|
-
return { order:
|
|
101
|
+
return { order: defaultOrder, text: section.renderDefault() };
|
|
98
102
|
}
|
|
99
103
|
/**
|
|
100
104
|
* Resolve all three sections for a preset. `presetId === undefined` skips the
|
|
101
105
|
* `<preset>/` layer and resolves straight to the compiled defaults.
|
|
102
106
|
*/
|
|
103
|
-
export async function composeSections(presetId, homeDir) {
|
|
107
|
+
export async function composeSections(presetId, homeDir, defaultOrder) {
|
|
104
108
|
return Promise.all(GUIDANCE_SECTIONS.map(async (section) => {
|
|
105
109
|
const resolved = await resolveSection(section.name, {
|
|
106
110
|
presetId,
|
|
107
111
|
homeDir,
|
|
112
|
+
...(defaultOrder === undefined ? {} : { defaultOrder }),
|
|
108
113
|
});
|
|
109
114
|
return {
|
|
110
115
|
name: section.name,
|