@flotiarenor/dsh-tool-text-editor 1.1.1 → 1.1.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 +7 -2
- package/README.zh.md +8 -4
- package/lib/core.mjs +19 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -102,16 +102,21 @@ Both tools return the same canonical value (`OUTPUT_SCHEMA`). Field contents and
|
|
|
102
102
|
| `path` | the target path as supplied by the caller, echoed back | — |
|
|
103
103
|
| `ok` / `wrote` / `dryRun` | outcome flags | — |
|
|
104
104
|
| `brief` | warning lines plus one stat line, e.g. `replace@60 +1/-1` | model context |
|
|
105
|
-
| `diff` | a unified diff of the changed lines only (0 context lines), limited by `maxDiffLines` | model context |
|
|
105
|
+
| `diff` | a unified diff of the changed lines only (`@@` hunk headers, 0 context lines, no `---` / `+++` file headers), limited by `maxDiffLines` | model context |
|
|
106
106
|
| `stdout` | the full human record: path header, complete diff with context lines, backup filename | UI / logs / triage |
|
|
107
107
|
| `stderr` | failure reason (non-empty on failure) | model context |
|
|
108
108
|
|
|
109
109
|
The model-facing text consists of `brief` and `diff`, with the path appearing once in the leading
|
|
110
|
-
line
|
|
110
|
+
line; the `diff` body carries no `---` / `+++` file headers, so the path never recurs inside it. The
|
|
111
|
+
complete diff is additionally projected by `output.presentationMeta` into a list of
|
|
111
112
|
`{ path, oldText, newText }`, the same card vocabulary the built-in `edit` / `write` tools use, and
|
|
112
113
|
handed to the Web UI by `presentResult`; that metadata is persisted with `tool/result` and never
|
|
113
114
|
enters the model context.
|
|
114
115
|
|
|
116
|
+
On failure neither `brief` nor `diff` is returned: the model-facing text is `FAIL` plus the target
|
|
117
|
+
path, followed by the complete failure reason. That reason is produced by the core and usually
|
|
118
|
+
contains the workspace-relative path once more (a failure favours a complete reason).
|
|
119
|
+
|
|
115
120
|
The `diff` argument selects the detail level of the `diff` field:
|
|
116
121
|
|
|
117
122
|
| Value | Behavior |
|
package/README.zh.md
CHANGED
|
@@ -103,13 +103,17 @@ dsh --profile web --dump-config # 应当能看到 "# == @flotiarenor/dsh-tool-
|
|
|
103
103
|
| `path` | 调用方给出的目标路径(原样回填) | — |
|
|
104
104
|
| `ok` / `wrote` / `dryRun` | 执行结果标志 | — |
|
|
105
105
|
| `brief` | 警告行与一行统计,如 `replace@60 +1/-1` | 模型上下文 |
|
|
106
|
-
| `diff` |
|
|
106
|
+
| `diff` | 只含 `@@` 块头与改动行的 unified diff(0 上下文行、无 `---` / `+++` 文件头),受 `maxDiffLines` 限制 | 模型上下文 |
|
|
107
107
|
| `stdout` | 人读全文:路径头、含上下文行的完整 diff、备份文件名 | UI / 日志 / 排查 |
|
|
108
108
|
| `stderr` | 失败原因(失败时非空) | 模型上下文 |
|
|
109
109
|
|
|
110
|
-
模型可见文本由 `brief` 与 `diff`
|
|
111
|
-
`output.presentationMeta` 投影为
|
|
112
|
-
|
|
110
|
+
模型可见文本由 `brief` 与 `diff` 组成,路径在起始行出现一次;`diff` 正文不含 `---` / `+++` 文件头,
|
|
111
|
+
因此路径不会在正文中再次出现。完整 diff 另经 `output.presentationMeta` 投影为
|
|
112
|
+
`{ path, oldText, newText }` 列表,与原生 `edit` / `write` 的卡片词汇同形,由 `presentResult` 交给
|
|
113
|
+
Web UI;该元数据随 `tool/result` 持久化,不进入模型上下文。
|
|
114
|
+
|
|
115
|
+
失败时不返回 `brief` 与 `diff`:模型可见文本为 `FAIL` 加目标路径,其后是完整的失败原因;原因文本由
|
|
116
|
+
核心生成,其中通常再包含一次工作区相对路径(失败路径优先保证原因完整)。
|
|
113
117
|
|
|
114
118
|
`diff` 参数决定 `diff` 字段的详细程度:
|
|
115
119
|
|
package/lib/core.mjs
CHANGED
|
@@ -600,6 +600,24 @@ export function diffBudget(text, mode, maxLines = DEFAULT_MAX_DIFF_LINES) {
|
|
|
600
600
|
].join('\n')
|
|
601
601
|
}
|
|
602
602
|
|
|
603
|
+
/**
|
|
604
|
+
* 去掉 unified diff 顶部的 `--- a/…` 与 `+++ b/…` 头两行。
|
|
605
|
+
*
|
|
606
|
+
* 模型可见正文里路径已在结果首行出现过一次,头部两行属于重复;标准形式仍完整保留在 `stdout`
|
|
607
|
+
* 与 UI 卡片中。
|
|
608
|
+
*
|
|
609
|
+
* @param text - unified diff 文本。
|
|
610
|
+
* @returns 去掉文件头之后的文本(没有头部时原样返回)。
|
|
611
|
+
*/
|
|
612
|
+
function withoutDiffHeaders(text) {
|
|
613
|
+
const lines = text.split('\n')
|
|
614
|
+
let from = 0
|
|
615
|
+
while (from < lines.length && (lines[from].startsWith('---') || lines[from].startsWith('+++'))) {
|
|
616
|
+
from += 1
|
|
617
|
+
}
|
|
618
|
+
return lines.slice(from).join('\n')
|
|
619
|
+
}
|
|
620
|
+
|
|
603
621
|
/**
|
|
604
622
|
* 把 unified diff 文本解析为 UI diff 卡片的词汇:`{ path, oldText, newText }` 列表,
|
|
605
623
|
* 与原生 `edit` / `write` 的 `presentationMeta` 同形(纯新增的 hunk 用 `oldText: null`)。
|
|
@@ -999,7 +1017,7 @@ export async function applyPlan(plan, context) {
|
|
|
999
1017
|
// 正文使用 0 上下文行:调用方刚完成这次编辑,周边内容或已读取过,或可自行读取。
|
|
1000
1018
|
// 完整 diff(含上下文行)只出现在 stdout 与 UI 卡片中,不进入这条路径。
|
|
1001
1019
|
const brief = [...warnings, `${kinds} +${stat.added}/-${stat.removed}`].join('\n')
|
|
1002
|
-
const visibleDiff = diffBudget(unifiedDiff(label, original, output, 0), diffMode, maxDiffLines)
|
|
1020
|
+
const visibleDiff = diffBudget(withoutDiffHeaders(unifiedDiff(label, original, output, 0)), diffMode, maxDiffLines)
|
|
1003
1021
|
|
|
1004
1022
|
if (plan.dryRun) {
|
|
1005
1023
|
return {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flotiarenor/dsh-tool-text-editor",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "Byte-faithful text editing tools (edit_text / write_text) for DeepSeek Harness: they preserve a UTF-8 BOM and the file's own CRLF/LF style (the built-in write/edit tools do not), back the previous content up, accept grep/lines anchors, and return a bounded result: one stat line plus a diff body limited by maxDiffLines, while the complete diff is projected to the UI card and never enters the model context. Pure Node and in-process: no external runtime, no child process, no third-party package, no build step, no imports beyond node: builtins.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/editor.mjs",
|