@thincoder/core 0.11.1 → 0.11.3
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 +64 -2
- package/advisor/compaction.mjs +7 -5
- package/advisor/convergence.mjs +34 -3
- package/advisor/history.mjs +24 -11
- package/advisor/loop.mjs +49 -12
- package/advisor/messages.mjs +114 -33
- package/advisor/project-context.mjs +171 -42
- package/advisor/run.mjs +24 -10
- package/advisor.mjs +36 -46
- package/agent/batch-attribution.mjs +87 -0
- package/agent/batch-changed-surface.mjs +129 -0
- package/agent/chat-call.mjs +14 -9
- package/agent/completion.mjs +70 -41
- package/agent/continue-decision.mjs +14 -8
- package/agent/digest-account.mjs +133 -59
- package/agent/dispatch-gates.mjs +6 -0
- package/agent/dispatch-run.mjs +1 -1
- package/agent/dispatch.mjs +10 -4
- package/agent/family-tools.mjs +37 -23
- package/agent/helpers.mjs +139 -73
- package/agent/image-heal.mjs +18 -4
- package/agent/offload.mjs +25 -29
- package/agent/post-turn.mjs +36 -35
- package/agent/record-results.mjs +39 -7
- package/agent/run-stages.mjs +132 -52
- package/agent/run-start.mjs +150 -78
- package/agent/setup-reminders.mjs +194 -91
- package/agent/setup.mjs +219 -140
- package/agent/spawn-child.mjs +40 -3
- package/agent/suspension.mjs +43 -15
- package/agent/timers.mjs +9 -4
- package/agent/turn-domain-text.mjs +105 -0
- package/agent/turn-loop.mjs +84 -27
- package/agent/turn-projection.mjs +286 -0
- package/agent/turn-task-state.mjs +274 -0
- package/agent/turn-tool-process.mjs +163 -0
- package/agent/write-gate-ledger.mjs +569 -0
- package/agent/write-gate.mjs +29 -352
- package/agent-tools/advisor-async.mjs +35 -172
- package/agent-tools/advisor-launch.mjs +178 -0
- package/agent-tools/advisor-settle.mjs +28 -1
- package/agent-tools/advisor.mjs +37 -48
- package/agent-tools/async-discard.mjs +7 -2
- package/agent-tools/async-settle.mjs +18 -12
- package/agent-tools/audit-block.mjs +6 -6
- package/agent-tools/bash-async.mjs +5 -2
- package/agent-tools/batch-closeout.mjs +223 -35
- package/agent-tools/batch-gate.mjs +142 -342
- package/agent-tools/batch-ledger-bind.mjs +240 -20
- package/agent-tools/batch-ledger-view.mjs +109 -0
- package/agent-tools/batch-lifecycle.mjs +197 -48
- package/agent-tools/batch-paths.mjs +29 -8
- package/agent-tools/batch-read.mjs +151 -4
- package/agent-tools/batch-record-write.mjs +417 -0
- package/agent-tools/batch-regions.mjs +215 -0
- package/agent-tools/batch-reopen.mjs +23 -11
- package/agent-tools/batch-segment-vocab.mjs +459 -0
- package/agent-tools/batch-skeleton.mjs +196 -239
- package/agent-tools/batch-supersede.mjs +232 -0
- package/agent-tools/batch-tier-gate.mjs +214 -0
- package/agent-tools/batch.mjs +192 -439
- package/agent-tools/browser-async.mjs +5 -2
- package/agent-tools/consult.mjs +17 -11
- package/agent-tools/context.mjs +76 -33
- package/agent-tools/design-review-record.mjs +225 -0
- package/agent-tools/design-slots.mjs +1 -1
- package/agent-tools/design-token.mjs +279 -81
- package/agent-tools/digest-budget.mjs +10 -9
- package/agent-tools/doc-check.mjs +43 -33
- package/agent-tools/doc-graph.mjs +140 -0
- package/agent-tools/eng.mjs +12 -12
- package/agent-tools/escalate-async.mjs +5 -5
- package/agent-tools/goal.mjs +5 -2
- package/agent-tools/judge-domain.mjs +347 -0
- package/agent-tools/manifest.mjs +34 -18
- package/agent-tools/parent-channel.mjs +6 -3
- package/agent-tools/plan.mjs +11 -10
- package/agent-tools/read-history.mjs +112 -11
- package/agent-tools/review-facts.mjs +19 -6
- package/agent-tools/settings.mjs +23 -2
- package/agent-tools/skill.mjs +7 -8
- package/agent-tools/spawn-gates.mjs +14 -24
- package/agent-tools/ssh-session.mjs +8 -5
- package/agent-tools/ssh-text.mjs +155 -0
- package/agent-tools/ssh-transfer.mjs +1 -1
- package/agent-tools/ssh-transport.mjs +19 -148
- package/agent-tools/subagent-actions-query.mjs +10 -6
- package/agent-tools/subagent-actions.mjs +2 -2
- package/agent-tools/subagent-async.mjs +19 -17
- package/agent-tools/subagent-brief.mjs +76 -0
- package/agent-tools/subagent-design-token.mjs +168 -0
- package/agent-tools/subagent-run.mjs +1 -1
- package/agent-tools/subagent-scheduler.mjs +13 -13
- package/agent-tools/subagent-spawn.mjs +92 -112
- package/agent-tools/subagent.mjs +16 -28
- package/agent-tools/task.mjs +0 -8
- package/agent-tools/taskbook-block.mjs +94 -0
- package/agent-tools/timer.mjs +12 -8
- package/agent-tools/verify.mjs +13 -4
- package/agent-tools.mjs +7 -3
- package/agent.mjs +26 -7
- package/attachments.mjs +3 -3
- package/auto-think.mjs +5 -2
- package/browser/actions.mjs +9 -3
- package/browser/cdp.mjs +45 -17
- package/browser/launch.mjs +25 -43
- package/browser/pool.mjs +299 -0
- package/browser/queue.mjs +2 -0
- package/browser/session-state.mjs +450 -0
- package/browser/session.mjs +127 -151
- package/browser/snapshot.mjs +89 -0
- package/client-identity.mjs +1 -1
- package/compaction-work-state.mjs +230 -0
- package/compress-form.mjs +41 -6
- package/config-defaults.mjs +7 -3
- package/config-migrate.mjs +40 -0
- package/config-normalize.mjs +28 -2
- package/config-reload.mjs +59 -0
- package/config.mjs +110 -110
- package/context-degrade.mjs +93 -34
- package/context-echo.mjs +6 -15
- package/context-push.mjs +328 -31
- package/context.mjs +298 -170
- package/conventions.mjs +11 -9
- package/declaration.mjs +126 -22
- package/declared-repos.mjs +94 -0
- package/doc-check/doc-names.mjs +73 -0
- package/doc-check/doc-tokens.mjs +110 -0
- package/doc-check/existence.mjs +160 -0
- package/doc-check/index.mjs +309 -213
- package/doc-check/line-refs.mjs +27 -101
- package/doc-check/paragraph.mjs +218 -102
- package/doc-graph/anchors.mjs +474 -0
- package/doc-graph/doc-batch-face.mjs +59 -0
- package/doc-graph/doc-suffix.mjs +27 -0
- package/doc-graph/graph-tokens.mjs +160 -0
- package/doc-graph.mjs +778 -0
- package/escape.mjs +6 -5
- package/explore-distill.mjs +41 -8
- package/generate-title.mjs +10 -1
- package/i18n.mjs +1 -1
- package/instance-inbox-watch.mjs +272 -0
- package/instance-inbox.mjs +218 -0
- package/instance-registry.mjs +179 -0
- package/knowledge/README.md +3 -0
- package/knowledge/prompt-resources.md +10 -0
- package/ledger-close-proof.mjs +100 -49
- package/ledger-close.mjs +188 -0
- package/ledger-cmd.mjs +47 -91
- package/ledger-consistency.mjs +113 -0
- package/ledger-db.mjs +47 -15
- package/ledger-executors.mjs +1 -1
- package/ledger-tools.mjs +121 -62
- package/ledger-write-ops.mjs +162 -46
- package/ledger.mjs +1 -1
- package/manifest-discovery.mjs +3 -1
- package/manifest-schema.mjs +27 -5
- package/memory/docs.mjs +51 -15
- package/memory/file-list.mjs +6 -0
- package/memory/schema.mjs +2 -2
- package/model-specs.mjs +87 -21
- package/origin-guard.mjs +190 -0
- package/package.json +3 -1
- package/path-resolve.mjs +338 -57
- package/prompt-files.mjs +114 -2
- package/prompt-overlays.mjs +21 -11
- package/prompts/advisor-design.md +96 -36
- package/prompts/advisor-round1.md +48 -4
- package/prompts/advisor-round2.md +54 -10
- package/prompts/advisor-round3.md +53 -9
- package/prompts/common.md +99 -434
- package/prompts/consult-base.md +7 -4
- package/prompts/discipline-engineering.md +504 -295
- package/prompts/discipline-normal.md +106 -281
- package/prompts/knowledge/business-gates.md +30 -0
- package/prompts/knowledge/decision-quality.md +21 -0
- package/prompts/knowledge/doc-lookup.md +30 -0
- package/prompts/knowledge/document-writing.md +33 -0
- package/prompts/knowledge/documentation-evaluation.md +48 -0
- package/prompts/knowledge/evidence-discipline.md +38 -0
- package/prompts/knowledge/normal-coding-workflow.md +110 -0
- package/prompts/knowledge/normal-delivery-collaboration.md +124 -0
- package/prompts/knowledge/normal-work-management.md +60 -0
- package/prompts/knowledge/product-security.md +28 -0
- package/prompts/knowledge/project-records.md +73 -0
- package/prompts/knowledge/tool-advisor.md +29 -0
- package/prompts/knowledge/tool-apply-patch.md +17 -0
- package/prompts/knowledge/tool-bash.md +48 -0
- package/prompts/knowledge/tool-batch-eng-coder.md +19 -0
- package/prompts/knowledge/tool-batch-eng-designer.md +20 -0
- package/prompts/knowledge/tool-batch-review.md +18 -0
- package/prompts/knowledge/tool-batch.md +94 -0
- package/prompts/knowledge/tool-browser.md +68 -0
- package/prompts/knowledge/tool-code-search.md +4 -0
- package/prompts/knowledge/tool-consult-start.md +12 -0
- package/prompts/knowledge/tool-consult-stop.md +6 -0
- package/prompts/knowledge/tool-context.md +6 -0
- package/prompts/knowledge/tool-delete.md +21 -0
- package/prompts/knowledge/tool-doc-check.md +71 -0
- package/prompts/knowledge/tool-doc-graph-read.md +20 -0
- package/prompts/knowledge/tool-doc-graph.md +49 -0
- package/prompts/knowledge/tool-doc-search.md +6 -0
- package/prompts/knowledge/tool-edit.md +41 -0
- package/prompts/knowledge/tool-eng.md +2 -0
- package/prompts/knowledge/tool-execute.md +21 -0
- package/prompts/knowledge/tool-fetch.md +18 -0
- package/prompts/knowledge/tool-file-ops.md +21 -0
- package/prompts/knowledge/tool-get-current-time.md +7 -0
- package/prompts/knowledge/tool-git-read.md +21 -0
- package/prompts/knowledge/tool-git.md +29 -0
- package/prompts/knowledge/tool-glob.md +17 -0
- package/prompts/knowledge/tool-goal.md +8 -0
- package/prompts/knowledge/tool-grep.md +21 -0
- package/prompts/knowledge/tool-hashline-edit.md +16 -0
- package/prompts/knowledge/tool-insert-after.md +17 -0
- package/prompts/knowledge/tool-instance-list.md +6 -0
- package/prompts/knowledge/tool-instance-send.md +10 -0
- package/prompts/knowledge/tool-knowledge.md +18 -0
- package/prompts/knowledge/tool-ledger-read.md +28 -0
- package/prompts/knowledge/tool-ledger.md +46 -0
- package/prompts/knowledge/tool-lint.md +16 -0
- package/prompts/knowledge/tool-ls.md +15 -0
- package/prompts/knowledge/tool-lsp.md +11 -0
- package/prompts/knowledge/tool-main-history.md +2 -0
- package/prompts/knowledge/tool-manifest-read.md +14 -0
- package/prompts/knowledge/tool-manifest.md +34 -0
- package/prompts/knowledge/tool-memory-read.md +20 -0
- package/prompts/knowledge/tool-memory.md +19 -0
- package/prompts/knowledge/tool-notify-parent.md +12 -0
- package/prompts/knowledge/tool-operations.md +102 -0
- package/prompts/knowledge/tool-peer-instances.md +2 -0
- package/prompts/knowledge/tool-plan.md +5 -0
- package/prompts/knowledge/tool-process-read.md +13 -0
- package/prompts/knowledge/tool-process.md +15 -0
- package/prompts/knowledge/tool-question.md +16 -0
- package/prompts/knowledge/tool-read-history-batch.md +22 -0
- package/prompts/knowledge/tool-read-history.md +35 -0
- package/prompts/knowledge/tool-read-image.md +11 -0
- package/prompts/knowledge/tool-read.md +22 -0
- package/prompts/knowledge/tool-recent-changes.md +6 -0
- package/prompts/knowledge/tool-repo-outline.md +4 -0
- package/prompts/knowledge/tool-settings-read.md +12 -0
- package/prompts/knowledge/tool-settings.md +17 -0
- package/prompts/knowledge/tool-skill.md +6 -0
- package/prompts/knowledge/tool-ssh.md +74 -0
- package/prompts/knowledge/tool-subagent.md +57 -0
- package/prompts/knowledge/tool-task.md +14 -0
- package/prompts/knowledge/tool-team-ledger-read.md +11 -0
- package/prompts/knowledge/tool-team-ledger.md +15 -0
- package/prompts/knowledge/tool-timer.md +23 -0
- package/prompts/knowledge/tool-tree.md +16 -0
- package/prompts/knowledge/tool-verify.md +19 -0
- package/prompts/knowledge/tool-wait-for.md +25 -0
- package/prompts/knowledge/tool-websearch.md +19 -0
- package/prompts/knowledge/tool-write.md +12 -0
- package/prompts/knowledge/upstream-protocol.md +45 -0
- package/prompts/persona-coder.md +1 -3
- package/prompts/persona-eng-coder.md +24 -6
- package/prompts/persona-eng-designer.md +150 -171
- package/prompts/persona-engineering.md +531 -442
- package/prompts/persona-explore.md +1 -3
- package/prompts/persona-normal.md +17 -9
- package/prompts/persona-plan.md +5 -3
- package/prompts/persona-tester.md +0 -2
- package/prompts/subagent-base.md +2 -2
- package/provider/anthropic.mjs +10 -6
- package/provider/core.mjs +8 -5
- package/provider/errors.mjs +63 -4
- package/provider/google.mjs +29 -10
- package/provider/reasoning-echo.mjs +16 -0
- package/provider/responses.mjs +7 -3
- package/provider/sse.mjs +11 -6
- package/provider-flows.mjs +2 -2
- package/rules.mjs +11 -10
- package/session-index-build.mjs +1 -1
- package/session-index-pass.mjs +1 -1
- package/session-index-query.mjs +1 -1
- package/session-index.mjs +1 -1
- package/session-lifecycle.mjs +131 -42
- package/session-slot-write.mjs +38 -6
- package/session.mjs +30 -11
- package/shell-identity.mjs +129 -22
- package/skip-dirs.mjs +26 -2
- package/team-ledger.mjs +34 -30
- package/text-budget.mjs +1 -1
- package/think-off.mjs +27 -0
- package/token-ttl.mjs +74 -5
- package/token-window.mjs +371 -47
- package/tool-docs/advisor.md +2 -27
- package/tool-docs/apply_patch.md +1 -15
- package/tool-docs/bash.md +2 -43
- package/tool-docs/batch-eng-coder.md +3 -0
- package/tool-docs/batch-eng-designer.md +3 -0
- package/tool-docs/batch-review.md +3 -0
- package/tool-docs/batch.md +2 -84
- package/tool-docs/browser.md +2 -49
- package/tool-docs/code_search.md +2 -2
- package/tool-docs/consult_start.md +2 -8
- package/tool-docs/consult_stop.md +2 -4
- package/tool-docs/context.md +1 -5
- package/tool-docs/delete.md +2 -17
- package/tool-docs/doc_check.md +2 -107
- package/tool-docs/doc_graph-read.md +3 -0
- package/tool-docs/doc_graph.md +3 -0
- package/tool-docs/doc_search.md +2 -4
- package/tool-docs/edit.md +1 -38
- package/tool-docs/eng.md +3 -1
- package/tool-docs/execute.md +2 -18
- package/tool-docs/fetch.md +2 -14
- package/tool-docs/file_ops.md +2 -18
- package/tool-docs/get_current_time.md +1 -6
- package/tool-docs/git-read.md +3 -0
- package/tool-docs/git.md +2 -35
- package/tool-docs/glob.md +2 -10
- package/tool-docs/goal.md +1 -6
- package/tool-docs/grep.md +2 -18
- package/tool-docs/hashline_edit.md +2 -15
- package/tool-docs/insert_after.md +2 -16
- package/tool-docs/instance_list.md +3 -0
- package/tool-docs/instance_send.md +3 -0
- package/tool-docs/knowledge.md +3 -0
- package/tool-docs/ledger-read.md +3 -0
- package/tool-docs/ledger.md +3 -8
- package/tool-docs/lint.md +2 -10
- package/tool-docs/ls.md +2 -11
- package/tool-docs/lsp.md +2 -9
- package/tool-docs/main_history.md +3 -1
- package/tool-docs/manifest-read.md +2 -8
- package/tool-docs/manifest.md +2 -35
- package/tool-docs/memory-read.md +3 -0
- package/tool-docs/memory.md +2 -20
- package/tool-docs/notify_parent.md +2 -13
- package/tool-docs/peer_instances.md +3 -1
- package/tool-docs/plan.md +1 -5
- package/tool-docs/process-read.md +3 -0
- package/tool-docs/process.md +2 -13
- package/tool-docs/question.md +3 -17
- package/tool-docs/read.md +2 -19
- package/tool-docs/read_history-batch.md +3 -0
- package/tool-docs/read_history.md +2 -18
- package/tool-docs/read_image.md +2 -9
- package/tool-docs/recent_changes.md +2 -2
- package/tool-docs/repo_outline.md +2 -2
- package/tool-docs/settings-read.md +3 -0
- package/tool-docs/settings.md +1 -12
- package/tool-docs/skill.md +2 -6
- package/tool-docs/ssh.md +1 -62
- package/tool-docs/subagent.md +2 -100
- package/tool-docs/task.md +1 -7
- package/tool-docs/team_ledger-read.md +3 -0
- package/tool-docs/team_ledger.md +3 -9
- package/tool-docs/timer.md +2 -19
- package/tool-docs/tree.md +2 -13
- package/tool-docs/verify.md +2 -12
- package/tool-docs/wait_for.md +2 -32
- package/tool-docs/websearch.md +2 -19
- package/tool-docs/write.md +2 -12
- package/tools/browser.mjs +54 -9
- package/tools/doc-write-gate.mjs +73 -0
- package/tools/edit-batch.mjs +170 -92
- package/tools/edit-diff.mjs +78 -62
- package/tools/edit-receipt.mjs +39 -0
- package/tools/execute.mjs +3 -3
- package/tools/file.mjs +28 -14
- package/tools/git.mjs +36 -21
- package/tools/index.mjs +6 -0
- package/tools/knowledge.mjs +143 -0
- package/tools/linter.mjs +3 -3
- package/tools/ops.mjs +5 -3
- package/tools/patch.mjs +124 -44
- package/tools/process-doc-mark.mjs +33 -4
- package/tools/repomap.mjs +25 -3
- package/tools/search.mjs +74 -26
- package/tools/shared.mjs +29 -27
- package/tools/ssh.mjs +5 -5
- package/tools/tree.mjs +32 -10
- package/tools/web-deepseek.mjs +1 -1
- package/tools/web.mjs +2 -2
- package/tools/write-gate-params.mjs +31 -0
- package/tools/write-path.mjs +16 -4
- package/window-policy.mjs +243 -0
- package/doc-check/anchors.mjs +0 -235
package/tools/edit-diff.mjs
CHANGED
|
@@ -1,24 +1,25 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* edit-diff.mjs — edit 工具的行级 diff 内核(权威语义 = EDIT.md——2026-09-04 拆出)。
|
|
3
3
|
*
|
|
4
|
-
* edit 语义(权威 = EDIT.md
|
|
4
|
+
* edit 语义(权威 = EDIT.md——2026-09-08 语义升级 D1/D2/D3 已并入):两种定位形态(互斥)——
|
|
5
5
|
* ① 按行号改(D1/F1):line(单行)/ startLine+endLine(1-based 闭区间)→ 直接替换该
|
|
6
6
|
* 行/行范围为 new_string(无需 old_string——实现落点 edit-batch.mjs applyLineEdit);
|
|
7
7
|
* **先过行号锚护栏**(判据与拒文单源 = write-path.mjs 的 lineAnchorVerdict /
|
|
8
8
|
* lineAnchorRefusal——上一笔写之后目标区落在受影响区内即拒);
|
|
9
|
-
* 阶段 2 删行形态(EDIT.md §
|
|
9
|
+
* 阶段 2 删行形态(EDIT.md §1「参数」——空值矩阵):省略 new_string 或传空串 = 删除该行/范围
|
|
10
|
+
* (有界意图——删行意图由行号表达,两种写法同一结局);
|
|
10
11
|
* ② 内容定位:old_string = 变化区**当前内容**(单次匹配——匹配档位:逐字 → P15.11 唯一
|
|
11
12
|
* 空白差异窗口 → D2/F2 模糊匹配(行级 normalize 后 ≥90% 行相等——edit-batch.mjs
|
|
12
13
|
* findFuzzyWindow));new_string = 该区的**期望结果**。判定序:
|
|
13
|
-
* 0. 分支 0
|
|
14
|
+
* 0. 分支 0(单行精确替换):old 单行 && new 单行 && old 全文唯一 &&
|
|
14
15
|
* new 非空 → **就地替换该行**(行数不变——EOL 由调用方 joinWithEol 恢复);
|
|
15
16
|
* 1. 零重叠(old 每一行都不出现在 new 行集中)→ **替换即删**(D3/F3,2026-09-08——
|
|
16
17
|
* breaking:old 行整体删除、new 取而代之——旧行不再保留;新增行用 insert_after);
|
|
17
18
|
* 2. 有公共行(≥1)→ 行级 LCS——公共行保留、差异行增删;
|
|
18
19
|
* 3. new 与 old 行级完全一致 → 原样替换(no-op 语义——仍报成功)。
|
|
19
20
|
* 内容形态空 new_string(纯删除意图)→ 显式报错(不静默——先于分支 0——单行替换永不
|
|
20
|
-
*
|
|
21
|
-
*
|
|
21
|
+
* 成删除;无界意图:replace_all 配空串会删掉全部匹配);**行号形态省略 new_string 或
|
|
22
|
+
* 传空串 = 删行/范围**(同一结局——归一落点 applyLineEdit,EDIT.md §1「参数」/§2「匹配与应用」);
|
|
22
23
|
* 分支 0 只在 computeEditEntry 条目判定层(壳/桥/批量自动继承)——
|
|
23
24
|
* applyPatchLines(纯 diff 层)语义不动。old/new 行数各上限 1000(超限报错)。
|
|
24
25
|
*
|
|
@@ -38,24 +39,21 @@ import {
|
|
|
38
39
|
// 写盘经单一写路径点(§2.13.5)——本档不再直调 fs。
|
|
39
40
|
import { appendWriteContext } from "./file.mjs"
|
|
40
41
|
import { writeThroughPath, lastWriteOf, isDirty, lineAnchorVerdict, lineAnchorRefusal } from "./write-path.mjs"
|
|
41
|
-
// D1/D2 落点(EDIT.md §
|
|
42
|
+
// D1/D2 落点(EDIT.md §2「匹配与应用」——edit-batch.mjs):按行号改 + 模糊匹配纯函数。
|
|
42
43
|
import { applyLineEdit, findFuzzyWindow, FUZZY_MATCH_NOTE } from "./edit-batch.mjs"
|
|
43
44
|
|
|
44
45
|
export const MAX_DIFF_LINES = 1000
|
|
45
46
|
export const REGION_TOO_LARGE = "edit region too large — narrow the change"
|
|
46
|
-
export const EMPTY_NEW_STRING = "empty new_string
|
|
47
|
-
export const EMPTY_NEW_STRING_LINE = "empty new_string with line-based targeting is an explicit error — OMIT new_string to delete the line/range (deleting by number is explicit intent; an empty replacement is a mistake, not a delete)"
|
|
47
|
+
export const EMPTY_NEW_STRING = "empty new_string is an explicit error for content-based targeting (old_string) — a content entry's delete intent can only be expressed by the content, and replace_all + \"\" would delete every match with no bound; to delete, use line-based targeting (line / startLine+endLine), where new_string may be omitted or passed as an empty string"
|
|
48
48
|
export const EDIT_ARGS_MUTEX = "edits array is mutually exclusive with top-level old_string/new_string/line/startLine/endLine — a top-level path is allowed (default for entries without their own path); provide each change's targeting (old_string or line range) and new_string inside its edits entry"
|
|
49
49
|
|
|
50
|
-
// ─── #325
|
|
50
|
+
// ─── #325 入参守卫文案(单源——核 edit-batch 与 ACP 桥 bridge.mjs 同调用)───
|
|
51
51
|
/** 容器级成形错误(真值非数组 / 空数组——同一错误面)。 */
|
|
52
52
|
export const EDITS_CONTAINER_ERROR = "edits must be a non-empty array of {path, old_string | line/startLine+endLine, new_string}"
|
|
53
53
|
/** 条目级成形错误(i = 数组下标;非对象条目 = null / 字符串 / 数字 / 数组)。 */
|
|
54
54
|
export const editsEntryError = (i) => `edits[${i}] must be an object of {path, old_string | line/startLine+endLine, new_string}`
|
|
55
55
|
/** 条目缺 path 且无顶层默认路径。 */
|
|
56
56
|
export const EDIT_ENTRY_NO_PATH = "each edit must have a path — give each entry its own path or pass a top-level path"
|
|
57
|
-
/** 批量原子失败前缀(条目判定失败时拼在消息前的 abortPrefix)。 */
|
|
58
|
-
export const EDIT_ABORT_PREFIX = "edit aborted (atomic — no files written): "
|
|
59
57
|
/** 批量条目校验前缀(validateEditEntry 的 opts.label)。 */
|
|
60
58
|
export const editEntryLabel = (path) => `edit for ${path}: `
|
|
61
59
|
|
|
@@ -135,7 +133,7 @@ function lcsMerge(a, b) {
|
|
|
135
133
|
}
|
|
136
134
|
|
|
137
135
|
/**
|
|
138
|
-
* (2026-09-05
|
|
136
|
+
* (2026-09-05 用户裁定——顶层 path + edits 并存合法化:顶层 path = 无自带
|
|
139
137
|
* path 条目的默认——模型直觉形态「顶层 path + 数组条目」不再拒绝;条目自带 path 优先)。
|
|
140
138
|
* 互斥收窄为只对顶层 old_string/new_string(+ 2026-09-08 D1 的 line/startLine/endLine)——
|
|
141
139
|
* edits 下它们无批语义可解释——顶层 path 不再触发。
|
|
@@ -146,31 +144,24 @@ export function assertEditArgsExclusive(args) {
|
|
|
146
144
|
}
|
|
147
145
|
}
|
|
148
146
|
|
|
149
|
-
/** 入参容器守卫(#325
|
|
147
|
+
/** 入参容器守卫(#325):edits 真值非数组 / 空数组 ⇒ 成形错误(同句单源——
|
|
150
148
|
* 核 edit-batch 与 ACP 桥 bridge.mjs 同调用)。批量判定序:容器 → 互斥 → 条目预扫 → 条目循环。 */
|
|
151
149
|
export function assertEditsContainer(edits) {
|
|
152
150
|
if (!Array.isArray(edits) || edits.length === 0) throw new Error(EDITS_CONTAINER_ERROR)
|
|
153
151
|
}
|
|
154
152
|
|
|
155
|
-
/** 入参条目守卫(#325——EDIT.md §5):条目非对象(null / 字符串 / 数字 / 数组)⇒ 含下标成形
|
|
156
|
-
* 错误——预扫于条目循环之前(不读盘、不触盘、零部分应用)。 */
|
|
157
|
-
export function assertEditEntries(edits) {
|
|
158
|
-
for (let i = 0; i < edits.length; i++) {
|
|
159
|
-
const e = edits[i]
|
|
160
|
-
if (e === null || typeof e !== "object" || Array.isArray(e)) throw new Error(editsEntryError(i))
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
153
|
/**
|
|
165
154
|
* 前置校验——内容形态:空 old / 非字符串 new;按行号改形态(D1,2026-09-08;阶段 2
|
|
166
|
-
* 删行——EDIT.md §
|
|
155
|
+
* 删行——EDIT.md §1「参数」):与 old_string 互斥 / line 与 startLine|endLine 互斥 /
|
|
167
156
|
* startLine+endLine 须成对 / 正整数 / endLine ≥ startLine / replace_all 不适用 /
|
|
168
|
-
* new_string:省略(undefined
|
|
157
|
+
* new_string:省略(undefined)或空串 = 删行(同一结局——除行号外不给别的结局)/ 其他类型报错。
|
|
169
158
|
* error 文本按调用形态(单形态 rich / 批量 label)。
|
|
170
|
-
* opts: { label = ""(批量前缀 = editEntryLabel(path)), rich = true
|
|
159
|
+
* opts: { label = ""(批量前缀 = editEntryLabel(path)), rich = true(单形态完整文本),
|
|
160
|
+
* scope = "batch" 时一律按 rich=false(批面不带写盘结论——EDIT.md §3「写与桥」) }
|
|
171
161
|
*/
|
|
172
162
|
export function validateEditEntry(entry, opts = {}) {
|
|
173
163
|
const label = opts.label ?? ""
|
|
164
|
+
const rich = opts.scope === "batch" ? false : opts.rich !== false
|
|
174
165
|
if (hasLineParams(entry)) {
|
|
175
166
|
if (entry.old_string !== undefined) {
|
|
176
167
|
throw new Error(label + "line/startLine/endLine are mutually exclusive with old_string — target by line number OR by content, not both")
|
|
@@ -192,37 +183,34 @@ export function validateEditEntry(entry, opts = {}) {
|
|
|
192
183
|
if (entry.replace_all) {
|
|
193
184
|
throw new Error(label + "replace_all does not apply to line-based edits (a line range is already a single explicit target)")
|
|
194
185
|
}
|
|
195
|
-
if (entry.new_string === "") {
|
|
196
|
-
throw new Error(label + EMPTY_NEW_STRING_LINE + (opts.rich === false ? "" : " — nothing written"))
|
|
197
|
-
}
|
|
198
186
|
if (entry.new_string !== undefined && typeof entry.new_string !== "string") {
|
|
199
187
|
throw new Error(
|
|
200
188
|
label + `new_string must be a string (got ${typeof entry.new_string})` +
|
|
201
|
-
(
|
|
189
|
+
(rich ? " — nothing written" : "")
|
|
202
190
|
)
|
|
203
191
|
}
|
|
204
192
|
return
|
|
205
193
|
}
|
|
206
194
|
if (!entry.old_string) {
|
|
207
195
|
throw new Error(
|
|
208
|
-
label + "old_string must not be empty" + (
|
|
196
|
+
label + "old_string must not be empty" + (rich ? " (empty string matches everywhere and would corrupt the file)" : "")
|
|
209
197
|
)
|
|
210
198
|
}
|
|
211
199
|
if (entry.new_string === "") {
|
|
212
|
-
// 空串 vs 省略矩阵(EDIT.md §
|
|
200
|
+
// 空串 vs 省略矩阵(EDIT.md §1「参数」):内容形态空串 = 显式错(无界意图防静默)——
|
|
213
201
|
// 先于 replace_all 分支(否则 replace_all + 空串会静默删除全部 occurrences——绕过保护)
|
|
214
|
-
throw new Error(label + EMPTY_NEW_STRING + (
|
|
202
|
+
throw new Error(label + EMPTY_NEW_STRING + (rich ? " — nothing written" : ""))
|
|
215
203
|
}
|
|
216
204
|
if (typeof entry.new_string !== "string") {
|
|
217
205
|
throw new Error(
|
|
218
206
|
label + `new_string must be a string${entry.new_string === undefined ? " (missing)" : ` (got ${typeof entry.new_string})`}` +
|
|
219
|
-
(
|
|
207
|
+
(rich ? " — nothing written" : "")
|
|
220
208
|
)
|
|
221
209
|
}
|
|
222
210
|
}
|
|
223
211
|
|
|
224
212
|
/**
|
|
225
|
-
* 分支 0
|
|
213
|
+
* 分支 0 形态判定:old/new 各为单行——无内部换行(splitLines
|
|
226
214
|
* 语义:尾随单个换行符是行终止而非新行——old/new 行内容均不含 \n)——且 new 非空
|
|
227
215
|
* ("" 经 splitLines 切分为 []——由下方 !== "" 守卫先拦截——空 new 不落本分支——落
|
|
228
216
|
* applyPatchLines 的空 new 显式错误——单行替换永不成删除)。多匹配与 replace_all 不落
|
|
@@ -237,12 +225,15 @@ function isSingleLineReplace(entry) {
|
|
|
237
225
|
}
|
|
238
226
|
|
|
239
227
|
/**
|
|
240
|
-
* 条目级判定+应用(单形态与批量共用——EDIT.md §
|
|
228
|
+
* 条目级判定+应用(单形态与批量共用——EDIT.md §2「匹配与应用」):
|
|
241
229
|
* 匹配校验(精确存在——非 replace_all 单次)→ 按判定序应用(分支 0 单行替换 / 零重叠替换即删 /
|
|
242
230
|
* LCS 替换 / replace_all 字面)→
|
|
243
231
|
* 元数据(受影响区首行/行数差/次数——recordWrite 与结果回显用)。
|
|
244
232
|
* 返回 { updated, editStartLine, lineShift, occurrences, note?, deleted? };失败抛错(含路径/引导)。
|
|
245
|
-
* opts: { path,
|
|
233
|
+
* opts: { path, absPath, scope }
|
|
234
|
+
* `scope:"batch"` = 两个批面(EDIT.md §3「写与桥」):错误文本**不带任何写盘结论**
|
|
235
|
+
* ——不带 ` — nothing written` 后缀(批面逐条报,那句在批面为假);
|
|
236
|
+
* 其余取值(含缺省)= 单档面,照 `rich` 的既有取法(带后缀)。
|
|
246
237
|
*/
|
|
247
238
|
/**
|
|
248
239
|
* P15.11(2026-09-05 用户裁定——edit 连续失败分析):old_string 逐字 not-found 时——
|
|
@@ -280,10 +271,13 @@ function findWhitespaceVariant(content, old) {
|
|
|
280
271
|
export const WHITESPACE_VARIANT_NOTE = "applied to the unique whitespace-only match (content identical, leading/trailing whitespace differs from your old_string)"
|
|
281
272
|
|
|
282
273
|
export function computeEditEntry(content, entry, opts = {}) {
|
|
283
|
-
|
|
284
|
-
//
|
|
285
|
-
|
|
286
|
-
|
|
274
|
+
// 写盘结论面(EDIT.md §3「写与桥」):`scope:"batch"` 这一个开关压掉
|
|
275
|
+
// ` — nothing written` 后缀(批面逐条报,那句在批面为假)。前缀形已退役,不再有要拼的。
|
|
276
|
+
const batchScope = opts.scope === "batch"
|
|
277
|
+
validateEditEntry(entry, { ...opts, rich: !batchScope })
|
|
278
|
+
// D1 按行号改(EDIT.md §1「参数」/§2「匹配与应用」):行号定位条目直接按行替换(applyLineEdit——落点
|
|
279
|
+
// edit-batch.mjs),不走 old_string 匹配/判定序;省略 new_string 或传空串 = 删行(同一
|
|
280
|
+
// 结局,归一在 applyLineEdit 内落一次);互斥/越界在 validateEditEntry/applyLineEdit 显式报错。
|
|
287
281
|
if (hasLineParams(entry)) return applyLineEdit(content, entry, opts)
|
|
288
282
|
// P15.11:not-found 时先查唯一空白差异窗口——命中则以其原文为实际 old 继续(内容零差异
|
|
289
283
|
// ——自动落点 + note 明示);实质差异/歧义仍走下方 not-found 报错(不猜内容)。
|
|
@@ -312,7 +306,7 @@ export function computeEditEntry(content, entry, opts = {}) {
|
|
|
312
306
|
candText = "\n" + header + "\n" + cands.map((c) => ` L${c.line}: ${c.preview} (${Math.round(c.score * 100)}%)`).join("\n")
|
|
313
307
|
}
|
|
314
308
|
throw new Error(
|
|
315
|
-
|
|
309
|
+
`old_string not found in ${opts.path ?? "file"}\n` +
|
|
316
310
|
` searched: "${preview}${entry.old_string.length > 100 ? "…" : ""}" — use grep to locate the actual content\n` +
|
|
317
311
|
(opts.absPath && lastWriteOf(opts.absPath)?.type === "write"
|
|
318
312
|
? ` hints: this file was modified since your last read (write 全文重写后内容全变) — re-read it to refresh your copy of the content, then retry\n`
|
|
@@ -324,7 +318,7 @@ export function computeEditEntry(content, entry, opts = {}) {
|
|
|
324
318
|
}
|
|
325
319
|
if (occurrences > 1 && !entry.replace_all) {
|
|
326
320
|
throw new Error(
|
|
327
|
-
|
|
321
|
+
`old_string matches ${occurrences} times in ${opts.path ?? "file"}; provide more context or set replace_all`
|
|
328
322
|
)
|
|
329
323
|
}
|
|
330
324
|
const matchIdx = content.indexOf(old)
|
|
@@ -332,11 +326,11 @@ export function computeEditEntry(content, entry, opts = {}) {
|
|
|
332
326
|
let updated
|
|
333
327
|
let resultForShift
|
|
334
328
|
if (entry.replace_all) {
|
|
335
|
-
// 字面替换——不做插入规则(old 多处时"插到哪处"无定义)——不落分支 0
|
|
329
|
+
// 字面替换——不做插入规则(old 多处时"插到哪处"无定义)——不落分支 0
|
|
336
330
|
updated = content.split(old).join(entry.new_string)
|
|
337
331
|
resultForShift = entry.new_string
|
|
338
332
|
} else if (isSingleLineReplace(entry)) {
|
|
339
|
-
// 分支 0
|
|
333
|
+
// 分支 0(单行精确替换):old 单行 && new 单行 && old 唯一匹配
|
|
340
334
|
// (occ==1 既有校验保证)&& new 非空(空 new 显式错误先于本分支——防删除)→ **就地
|
|
341
335
|
// 替换该行**——不再零重叠插入(P15.8——行尾段编辑反复踩的插入坑)。只替换行内容段:
|
|
342
336
|
// old/new 的尾随换行符属文件结构而非行内容——留在原位——行数不变——EOL 由调用方
|
|
@@ -360,14 +354,17 @@ export function computeEditEntry(content, entry, opts = {}) {
|
|
|
360
354
|
}
|
|
361
355
|
|
|
362
356
|
/**
|
|
363
|
-
*
|
|
357
|
+
* `EDIT-HELPERS.md` §4「批量帧」的 R1–R4——同档多条 `edits` 的应用顺序:行号条目先全部应用、按 `startLine` 降序
|
|
364
358
|
* (从下往上改,上方行号不被同批自己顶偏);内容条目随后按数组序(位置无关寻址无帧问题)。
|
|
365
359
|
*
|
|
366
360
|
* **零 IO**(只看条目自身的行号):两个通道(本地 `edit-batch` ∥ ACP 桥)调同一份排法,
|
|
367
361
|
* 各自只提供自己的 IO——抄一份组循环就是本机制要根治的形状。
|
|
368
362
|
*
|
|
369
|
-
* @returns {{ order: number[]
|
|
370
|
-
*
|
|
363
|
+
* @returns {{ order: number[], rejections: {index: number, reason: string}[] }}
|
|
364
|
+
* `order` = **未被拒**条目的应用序(下标指向传入的 `entries`,回显仍按调用序取原位);
|
|
365
|
+
* `rejections` = R3 重叠:**互指的每一条各得一行**(原因互指对方行范围——`EDIT-HELPERS.md` §4
|
|
366
|
+
* 「批量帧」,同档其余条照应用)。拒因是**纯原因句**——不带前缀、不带写盘结论
|
|
367
|
+
* (「no files written」在逐条模式为假);回执行由调用方按骨架组装。
|
|
371
368
|
* `path`(可选)= 拒文里点名的目标档(条目自带 path 优先——顶层 path 不在条目上)。
|
|
372
369
|
*/
|
|
373
370
|
export function planEditEntries(entries, path = null) {
|
|
@@ -376,34 +373,52 @@ export function planEditEntries(entries, path = null) {
|
|
|
376
373
|
const contentIdx = []
|
|
377
374
|
entries.forEach((e, i) => { (hasLineParams(e) ? lineIdx : contentIdx).push(i) })
|
|
378
375
|
// R3:两条行号条目的范围在快照坐标上重叠 ⇒ 先改哪一条决定结果,模型意图在此矛盾
|
|
376
|
+
// ——两条都废(先改哪条都改意),互指对方行范围。
|
|
377
|
+
const rejected = new Map() // 条目下标 → 拒因
|
|
379
378
|
const byStart = [...lineIdx].sort((a, b) => rangeOf(entries[a])[0] - rangeOf(entries[b])[0])
|
|
380
379
|
for (let i = 1; i < byStart.length; i++) {
|
|
381
|
-
const
|
|
382
|
-
const
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
380
|
+
const a = byStart[i - 1]
|
|
381
|
+
const b = byStart[i]
|
|
382
|
+
const ra = rangeOf(entries[a])
|
|
383
|
+
const rb = rangeOf(entries[b])
|
|
384
|
+
if (rb[0] > ra[1]) continue
|
|
385
|
+
const label = entries[b].path ?? entries[a].path ?? path ?? "file"
|
|
386
|
+
const reason =
|
|
387
|
+
`line-number entries L${ra[0]}-L${ra[1]} and L${rb[0]}-L${rb[1]} (${label}) overlap — ` +
|
|
388
|
+
`two changes to the same region cannot both be anchored on the numbers you read; split them into separate calls`
|
|
389
|
+
if (!rejected.has(a)) rejected.set(a, reason)
|
|
390
|
+
if (!rejected.has(b)) rejected.set(b, reason)
|
|
392
391
|
}
|
|
392
|
+
const rejections = [...rejected.entries()]
|
|
393
|
+
.sort((x, y) => x[0] - y[0])
|
|
394
|
+
.map(([index, reason]) => ({ index, reason }))
|
|
393
395
|
// R2:降序(同档起始行不会相等——相等即重叠,已在 R3 拒掉)
|
|
394
|
-
const
|
|
395
|
-
|
|
396
|
+
const alive = lineIdx.filter((i) => !rejected.has(i))
|
|
397
|
+
const desc = [...alive].sort((a, b) => rangeOf(entries[b])[0] - rangeOf(entries[a])[0])
|
|
398
|
+
return { order: [...desc, ...contentIdx], rejections }
|
|
396
399
|
}
|
|
397
400
|
|
|
398
401
|
/**
|
|
399
402
|
* 按 `planEditEntries` 排出的应用序逐条 `computeEditEntry` 累积——**零 IO**。
|
|
400
403
|
* `results` 按调用序回到原位(回显顺序不变),元数据形同 `computeEditEntry` 返回。
|
|
404
|
+
*
|
|
405
|
+
* opts.onEntryError:`"throw"`(缺省——整批拒的调用面)∥ `"collect"`(逐条成败:一条抛错
|
|
406
|
+
* 就记它自己一行、累积内容不动、继续下一条——EDIT.md §2「匹配与应用」)。
|
|
401
407
|
*/
|
|
402
408
|
export function applyPlannedEntries(content, entries, order, opts = {}) {
|
|
403
409
|
let cur = content
|
|
404
410
|
const results = new Array(entries.length)
|
|
411
|
+
const failures = []
|
|
412
|
+
const collect = opts.onEntryError === "collect"
|
|
405
413
|
for (const i of order) {
|
|
406
|
-
|
|
414
|
+
let out
|
|
415
|
+
try {
|
|
416
|
+
out = computeEditEntry(cur, entries[i], opts)
|
|
417
|
+
} catch (err) {
|
|
418
|
+
if (!collect) throw err
|
|
419
|
+
failures.push({ index: i, reason: err?.message ?? String(err) })
|
|
420
|
+
continue
|
|
421
|
+
}
|
|
407
422
|
results[i] = {
|
|
408
423
|
editStartLine: out.editStartLine,
|
|
409
424
|
lineShift: out.lineShift,
|
|
@@ -413,7 +428,7 @@ export function applyPlannedEntries(content, entries, order, opts = {}) {
|
|
|
413
428
|
}
|
|
414
429
|
cur = out.updated
|
|
415
430
|
}
|
|
416
|
-
return { content: cur, results }
|
|
431
|
+
return { content: cur, results, failures }
|
|
417
432
|
}
|
|
418
433
|
|
|
419
434
|
/**
|
|
@@ -438,6 +453,7 @@ export async function runSingleEdit(args, ctx) {
|
|
|
438
453
|
// 单一写路径点:默认 = writeFile + 记账;端侧注入 ⇒ 编辑器径(§2.13.5)。
|
|
439
454
|
await writeThroughPath(abs, joinWithEol(normalizeEOL(out.updated).split("\n"), raw), {
|
|
440
455
|
op: "write",
|
|
456
|
+
agent: ctx.agent,
|
|
441
457
|
record: { type: "edit", startLine: out.editStartLine, shift: out.lineShift },
|
|
442
458
|
})
|
|
443
459
|
const diff = await gitDiffOne(ctx.cwd, abs)
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* edit-receipt.mjs — 批级回执文案**单源**(两个具名构造器各领各的)。
|
|
3
|
+
*
|
|
4
|
+
* 契约 = `docs/core/design/EDIT.md` §2「匹配与应用」(回执按调用序、报真实条目/文件数);骨架单源 =
|
|
5
|
+
* `docs/core/design/EDIT-HELPERS.md` §4「批量帧」(回执由 editEntryFailureLine/editBatchSummary 统一构造)。
|
|
6
|
+
*
|
|
7
|
+
* 两个构造器:
|
|
8
|
+
* - 逐条 / 逐档失败行 ← `editEntryFailureLine(label, reason)`——`<定位> — failed: <原因原文>`,
|
|
9
|
+
* `— failed: ` 这一段逐字同形;定位由各工具填自己的天然坐标(`edits[<i>]` ∥ `<path>` / `<path> hunk <n>`),
|
|
10
|
+
* 所以入参是**定位串**而不是下标:两个工具共用同一个字面量,改一处就同时改到另一处。
|
|
11
|
+
* - 汇总行与其 `<K> file(s) written` 计数 ← `editBatchSummary({ tool, applied, total, unit, filesWritten })`。
|
|
12
|
+
*
|
|
13
|
+
* **末段存废由「报单位是不是档」定**(`FILE_UNIT`):`edit` 批面报条目、写档(`K ≤ M` ⇒ 末段带信息);
|
|
14
|
+
* `apply_patch` 报档、写档(两个数恒相等 ⇒ 末段只把同一个数印两遍,省)。第三个写入工具接入时
|
|
15
|
+
* 自己回答「我的单位是不是档」,不照抄一段多余的话。
|
|
16
|
+
*
|
|
17
|
+
* 为什么住在自己这一档而不进 `thincoder-core/tools/edit-diff.mjs`:后者已贴近 500 行硬线,
|
|
18
|
+
* 本批为它零增长。
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/** 报单位 = 档时的单位词——末段 ` — <K> file(s) written` 的存在与否由 `unit` 与它是否相等决定。 */
|
|
22
|
+
export const FILE_UNIT = "file(s)"
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* 失败行(逐条 ∥ 逐档):`<定位> — failed: <原因原文>`。
|
|
26
|
+
* `reason` = 抛出的错误文本逐字(可以跨多行——不提炼、不改写)。
|
|
27
|
+
*/
|
|
28
|
+
export const editEntryFailureLine = (label, reason) => `${label} — failed: ${reason}`
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* 末行汇总:`<tool>: <k>/<M> <unit> applied, <M−k> failed`,`unit` ≠ 档时再接 ` — <K> file(s) written`;
|
|
32
|
+
* `filesWritten` 非空(`K ≥ 1`)时后接 `: ` + 路径清单(调用方已按各自的序排好、以 `, ` 分隔)。
|
|
33
|
+
*/
|
|
34
|
+
export function editBatchSummary({ tool, applied, total, unit, filesWritten = [] }) {
|
|
35
|
+
const head = `${tool}: ${applied}/${total} ${unit} applied, ${total - applied} failed`
|
|
36
|
+
const tail = unit === FILE_UNIT ? "" : ` — ${filesWritten.length} file(s) written`
|
|
37
|
+
const list = filesWritten.length >= 1 ? `: ${filesWritten.join(", ")}` : ""
|
|
38
|
+
return head + tail + list
|
|
39
|
+
}
|
package/tools/execute.mjs
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* process is killed like bash).
|
|
12
12
|
*
|
|
13
13
|
* The child runs PURE node ESM — no helpers are injected (exec-prelude.mjs
|
|
14
|
-
* retired 2026-09-03
|
|
14
|
+
* retired 2026-09-03: preloaded readFile/writeFile/glob/grep/log
|
|
15
15
|
* helpers made execute look like a file tool, bypassing the dedicated
|
|
16
16
|
* read/ls/glob/grep/write/edit tools). Scripts that need fs/path import the
|
|
17
17
|
* node: modules themselves — same boundary as bash, no fake sandbox.
|
|
@@ -174,11 +174,11 @@ export const executeTool = {
|
|
|
174
174
|
properties: {
|
|
175
175
|
code: {
|
|
176
176
|
type: "string",
|
|
177
|
-
description: "JavaScript
|
|
177
|
+
description: "JavaScript to run (top-level await and dynamic import() supported). Pure node ESM — no preloaded globals; import `node:` modules yourself when needed. File reads and writes go through the dedicated tools. Use this OR scriptFile.",
|
|
178
178
|
},
|
|
179
179
|
scriptFile: {
|
|
180
180
|
type: "string",
|
|
181
|
-
description: "Run a .mjs/.js file with node (self-contained —
|
|
181
|
+
description: "Run a .mjs/.js file with node (self-contained — it imports what it needs). Path relative to workdir, no directory restriction. Use this OR code. For `node <script>` / `node --test <file>` / `node --check <file>`.",
|
|
182
182
|
},
|
|
183
183
|
nodeArgs: {
|
|
184
184
|
type: "array",
|
package/tools/file.mjs
CHANGED
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
majorityEol,
|
|
13
13
|
FFFD_WARNING,
|
|
14
14
|
LEDGER_PARAM_DESC,
|
|
15
|
+
PROJECT_PARAM_DESC,
|
|
15
16
|
} from "./shared.mjs";
|
|
16
17
|
import { applyEditBatch } from "./edit-batch.mjs";
|
|
17
18
|
import { runSingleEdit } from "./edit-diff.mjs";
|
|
@@ -19,6 +20,9 @@ import { runSingleEdit } from "./edit-diff.mjs";
|
|
|
19
20
|
// 记账面同源住该档(下面只做再导出——保既有 import 面稳定)。
|
|
20
21
|
import { writeThroughPath, clearDirty, clearLastWrite, lineAnchorVerdict, lineAnchorRefusal } from "./write-path.mjs";
|
|
21
22
|
import { specForModel } from "../config.mjs";
|
|
23
|
+
// 层标识(机制 = `docs/core/design/DOC-SYSTEM.md` §3.1「层标识」):`read` 的输出就是一份档,
|
|
24
|
+
// 所以它带层标识;它**不**参与默认排除(点名读是显式请求——`docs/core/design/TOOLS.md` §7.1)。
|
|
25
|
+
import { docLayerName } from "./process-doc-mark.mjs";
|
|
22
26
|
import { createHash } from "node:crypto";
|
|
23
27
|
import { mkdir, readFile, stat } from "node:fs/promises";
|
|
24
28
|
import { join, relative, dirname } from "node:path";
|
|
@@ -89,6 +93,9 @@ export const readTool = {
|
|
|
89
93
|
clearDirty(abs)
|
|
90
94
|
clearLastWrite(abs) // 2026-08-31:read 同时清写入快照(新视图以 read 为准)
|
|
91
95
|
const lines = content.split("\n")
|
|
96
|
+
// 层标识单起一行:掺进正文行会破坏 `L<n>\t<正文>` 这个逐字格式。图片走 `read_image`(另一条出口),
|
|
97
|
+
// 失败走 throw——两者都没有这一行,因为那里没有编号正文。
|
|
98
|
+
const layerLine = `[${docLayerName(abs)}]`
|
|
92
99
|
const offset = Math.max(1, args.offset ?? 1)
|
|
93
100
|
const limit = Math.min(args.limit ?? MAX_READ_LINES, MAX_READ_LINES)
|
|
94
101
|
const windowEnd = offset - 1 + limit // index just past the requested window
|
|
@@ -104,7 +111,7 @@ export const readTool = {
|
|
|
104
111
|
// 也走旧路径。与 hashes 模式照常交互(头尾行 hash 照算)。
|
|
105
112
|
if (windowEnd >= lines.length || lines.length <= MAX_READ_LINES) {
|
|
106
113
|
const suffix = windowEnd < lines.length ? `\n... (${lines.length} lines total, use offset to continue)` : ""
|
|
107
|
-
return truncate(render(lines.slice(offset - 1, windowEnd), offset) + suffix)
|
|
114
|
+
return `${layerLine}\n${truncate(render(lines.slice(offset - 1, windowEnd), offset) + suffix)}`
|
|
108
115
|
}
|
|
109
116
|
const head = render(lines.slice(offset - 1, windowEnd), offset)
|
|
110
117
|
// 尾区 = 文件末 READ_TAIL_LINES 行;尾区起点落在窗口内(重叠)→ 尾区从窗口后开始
|
|
@@ -113,8 +120,8 @@ export const readTool = {
|
|
|
113
120
|
const middle = tailStart - windowEnd
|
|
114
121
|
const tail = render(lines.slice(tailStart), tailStart + 1)
|
|
115
122
|
return middle > 0
|
|
116
|
-
? `${head}\n…(truncated: ${middle} lines in middle, use offset to continue)\n${tail}`
|
|
117
|
-
: `${head}\n${tail}`
|
|
123
|
+
? `${layerLine}\n${head}\n…(truncated: ${middle} lines in middle, use offset to continue)\n${tail}`
|
|
124
|
+
: `${layerLine}\n${head}\n${tail}`
|
|
118
125
|
},
|
|
119
126
|
}
|
|
120
127
|
|
|
@@ -194,6 +201,8 @@ export const writeTool = {
|
|
|
194
201
|
path: { type: "string", description: "File path (relative to cwd or absolute)" },
|
|
195
202
|
content: { type: "string", description: "Full content to write" },
|
|
196
203
|
ledger: { type: "string", description: LEDGER_PARAM_DESC },
|
|
204
|
+
// 工作区根窄口(设计档 §2.3.1):目标取不到项目根时才被读;目标有根时以路径为准(定位参数优先)。
|
|
205
|
+
project: { type: "string", description: PROJECT_PARAM_DESC },
|
|
197
206
|
},
|
|
198
207
|
required: ["path", "content"],
|
|
199
208
|
},
|
|
@@ -210,7 +219,7 @@ export const writeTool = {
|
|
|
210
219
|
const eol = prev != null ? detectFileEol(prev) : majorityEol(dirname(abs))
|
|
211
220
|
const content = eol === "\r\n" ? normalizeEOL(args.content).replace(/\n/g, "\r\n") : args.content
|
|
212
221
|
// 单一写路径点:默认 = writeFile + 记账;端侧注入 ⇒ 编辑器径(§2.13.5)。
|
|
213
|
-
await writeThroughPath(abs, content, { op: "write", record: { type: "write", startLine: 1, shift: 0 } }) // 全文重写——全文件受影响
|
|
222
|
+
await writeThroughPath(abs, content, { op: "write", agent: ctx.agent, record: { type: "write", startLine: 1, shift: 0 } }) // 全文重写——全文件受影响
|
|
214
223
|
const diff = await gitDiffOne(ctx.cwd, abs)
|
|
215
224
|
return `Wrote ${args.content.length} chars to ${args.path}${diff ? "\n" + diff : ""}${await autoSyntaxCheck(abs)}`
|
|
216
225
|
},
|
|
@@ -224,16 +233,16 @@ export const editTool = {
|
|
|
224
233
|
parameters: {
|
|
225
234
|
type: "object",
|
|
226
235
|
properties: {
|
|
227
|
-
path: { type: "string", description: "
|
|
228
|
-
old_string: { type: "string", description: "
|
|
229
|
-
new_string: { type: "string", description: "Replacement text
|
|
230
|
-
line: { type: "integer", description: "1-based line
|
|
231
|
-
startLine: { type: "integer", description: "1-based first line of the range
|
|
232
|
-
endLine: { type: "integer", description: "1-based last line of the range
|
|
233
|
-
replace_all: { type: "boolean", description: "Replace
|
|
236
|
+
path: { type: "string", description: "Path. Required in single form; with `edits`, a default for entries lacking their own." },
|
|
237
|
+
old_string: { type: "string", description: "Text to replace. Match order: exact, then whitespace-only variant, then fuzzy at ≥90% line equality (whitespace, indent and quotes normalized). Mutually exclusive with line/startLine/endLine." },
|
|
238
|
+
new_string: { type: "string", description: "Replacement text. Content targeting requires it, and an empty string is an error there (with replace_all it would delete every match). Line targeting may omit it or pass \"\" — both delete the range." },
|
|
239
|
+
line: { type: "integer", description: "1-based line to replace. Omit new_string to delete it. Mutually exclusive with old_string, startLine and endLine." },
|
|
240
|
+
startLine: { type: "integer", description: "1-based first line of the range. Requires endLine. Omit new_string to delete the range." },
|
|
241
|
+
endLine: { type: "integer", description: "1-based last line of the range. Requires startLine. Omit new_string to delete the range." },
|
|
242
|
+
replace_all: { type: "boolean", description: "Replace every occurrence (default false)." },
|
|
234
243
|
edits: {
|
|
235
244
|
type: "array",
|
|
236
|
-
description: "Batch form
|
|
245
|
+
description: "Batch form: several edits in one call, each reported separately. A failing entry does not stop the rest; but if the file's final content is rejected, that file writes nothing. Files already written are never rolled back. Line entries apply first, descending by startLine, ranges non-overlapping; content entries then in array order. Top-level path defaults entries without one (an entry's own path wins). No top-level targeting params here — put them inside each entry.",
|
|
237
246
|
items: {
|
|
238
247
|
type: "object",
|
|
239
248
|
properties: {
|
|
@@ -248,6 +257,7 @@ export const editTool = {
|
|
|
248
257
|
},
|
|
249
258
|
},
|
|
250
259
|
ledger: { type: "string", description: LEDGER_PARAM_DESC },
|
|
260
|
+
project: { type: "string", description: PROJECT_PARAM_DESC },
|
|
251
261
|
},
|
|
252
262
|
required: [],
|
|
253
263
|
},
|
|
@@ -271,8 +281,8 @@ export const editTool = {
|
|
|
271
281
|
// (应用逻辑在 edit-batch.mjs——2026-09-01 拆出,500 行硬限,先例 git-ext.mjs)
|
|
272
282
|
if (args.edits) return applyEditBatch(args, ctx)
|
|
273
283
|
|
|
274
|
-
// 单文件(现状路径)——执行体整段迁出至 edit-diff.mjs
|
|
275
|
-
//
|
|
284
|
+
// 单文件(现状路径)——执行体整段迁出至 edit-diff.mjs(判定序:零重叠→替换即删 /
|
|
285
|
+
// 一般 diff→行级 LCS / 空 new→显式报错)
|
|
276
286
|
return runSingleEdit(args, ctx)
|
|
277
287
|
},
|
|
278
288
|
}
|
|
@@ -290,6 +300,7 @@ export const insertAfterTool = {
|
|
|
290
300
|
after_regex: { type: "string", description: "JavaScript regex to find the line to insert after (must match exactly one line)" },
|
|
291
301
|
content: { type: "string", description: "Text to insert (with leading newline if you need a blank line)" },
|
|
292
302
|
ledger: { type: "string", description: LEDGER_PARAM_DESC },
|
|
303
|
+
project: { type: "string", description: PROJECT_PARAM_DESC },
|
|
293
304
|
},
|
|
294
305
|
required: ["path", "content"],
|
|
295
306
|
},
|
|
@@ -347,6 +358,7 @@ export const insertAfterTool = {
|
|
|
347
358
|
const updated = joinWithEol(lines, raw)
|
|
348
359
|
await writeThroughPath(abs, updated, {
|
|
349
360
|
op: "write",
|
|
361
|
+
agent: ctx.agent,
|
|
350
362
|
record: { type: "insert", startLine: targetLine, shift: normalizeEOL(args.content).split("\n").length },
|
|
351
363
|
})
|
|
352
364
|
const diff = await gitDiffOne(ctx.cwd, abs)
|
|
@@ -375,6 +387,7 @@ export const hashlineEditTool = {
|
|
|
375
387
|
old_hashes: { type: "array", items: { type: "string" }, description: "SHA256 hashes (12 chars) of the lines to replace. Read the file with hashes=true first to obtain these hashes. Single line: pass 1 hash; multiple lines: pass the exact sequence of hashes." },
|
|
376
388
|
new_content: { type: "string", description: "Replacement text (can span multiple lines)" },
|
|
377
389
|
ledger: { type: "string", description: LEDGER_PARAM_DESC },
|
|
390
|
+
project: { type: "string", description: PROJECT_PARAM_DESC },
|
|
378
391
|
},
|
|
379
392
|
required: ["path", "old_hashes", "new_content"],
|
|
380
393
|
},
|
|
@@ -443,6 +456,7 @@ export const hashlineEditTool = {
|
|
|
443
456
|
const updated = joinWithEol(lines, raw)
|
|
444
457
|
await writeThroughPath(abs, updated, {
|
|
445
458
|
op: "write",
|
|
459
|
+
agent: ctx.agent,
|
|
446
460
|
record: { type: "edit", startLine: pos + 1, shift: newLines.length - target.length },
|
|
447
461
|
})
|
|
448
462
|
const diff = await gitDiffOne(ctx.cwd, abs)
|