feat(prompts/tools): clarified hashline block boundary handling with examples

- Improved hashline tool documentation with clearer guidance on block boundary handling and closing delimiter duplication prevention.
- Added concrete example demonstrating correct anchor placement when replacing entire blocks including closing braces.
- Reorganized boundary duplication warnings into actionable self-check guidance with visual comparison steps.
This commit is contained in:
can1357
2026-03-27 00:13:01 +01:00
parent 0513097761
commit 736aac3dfc
3 changed files with 51 additions and 11 deletions
+30 -5
View File
@@ -822,7 +822,7 @@
},
"global.anthropic.claude-haiku-4-5-20251001-v1:0": {
"id": "global.anthropic.claude-haiku-4-5-20251001-v1:0",
"name": "Claude Haiku 4.5 (Global)",
"name": "Claude Haiku 4.5",
"api": "bedrock-converse-stream",
"provider": "amazon-bedrock",
"baseUrl": "https://bedrock-runtime.us-east-1.amazonaws.com",
@@ -947,7 +947,7 @@
},
"global.anthropic.claude-sonnet-4-6": {
"id": "global.anthropic.claude-sonnet-4-6",
"name": "Claude Sonnet 4.6",
"name": "Claude Sonnet 4.6 (Global)",
"api": "bedrock-converse-stream",
"provider": "amazon-bedrock",
"baseUrl": "https://bedrock-runtime.us-east-1.amazonaws.com",
@@ -1801,7 +1801,7 @@
},
"us.anthropic.claude-opus-4-1-20250805-v1:0": {
"id": "us.anthropic.claude-opus-4-1-20250805-v1:0",
"name": "Claude Opus 4.1",
"name": "Claude Opus 4.1 (US)",
"api": "bedrock-converse-stream",
"provider": "amazon-bedrock",
"baseUrl": "https://bedrock-runtime.us-east-1.amazonaws.com",
@@ -25896,6 +25896,31 @@
"contextWindow": 222222,
"maxTokens": 8888
},
"qwen/qwen3.5-9b": {
"id": "qwen/qwen3.5-9b",
"name": "Qwen: Qwen3.5-9B",
"api": "openai-completions",
"provider": "nanogpt",
"baseUrl": "https://nano-gpt.com/api/v1",
"reasoning": true,
"input": [
"text",
"image"
],
"cost": {
"input": 0.049999999999999996,
"output": 0.15,
"cacheRead": 0,
"cacheWrite": 0
},
"contextWindow": 256000,
"maxTokens": 65536,
"thinking": {
"mode": "effort",
"minLevel": "minimal",
"maxLevel": "high"
}
},
"qwen/qwen3.5-plus": {
"id": "qwen/qwen3.5-plus",
"name": "Qwen3.5 Plus",
@@ -37505,8 +37530,8 @@
"image"
],
"cost": {
"input": 0.19999999999999998,
"output": 0.19999999999999998,
"input": 0.09999999999999999,
"output": 0.09999999999999999,
"cacheRead": 0,
"cacheWrite": 0
},
+1 -1
View File
@@ -1,7 +1,6 @@
# Changelog
## [Unreleased]
### Added
- Implemented root path alias: bare `/` in tool inputs now resolves to the session working directory instead of the filesystem root
@@ -9,6 +8,7 @@
### Changed
- Improved hashline tool documentation with clearer guidance on block boundary handling and closing delimiter duplication prevention
- Updated screenshot path resolution to use `resolveToCwd` for consistent workspace-relative path handling
- Updated hook editor hint text to include `ctrl+g external editor` option when using prompt style
- Refactored question result formatting to consistently include question ID in output
@@ -2,8 +2,6 @@ Applies precise file edits using `LINE#ID` anchors from `read` output.
Read the file first. Copy anchors exactly from the latest `read` output. In one `edit` call, batch all edits for one file. After any successful edit, re-read before editing that file again.
This matters: your output is checked against the real file state. Invalid anchors, duplicated boundary lines, or semantically equivalent rewrites will fail.
<operations>
**Top level**
- `path` — file path
@@ -61,6 +59,24 @@ Replace only the catch body. Do not target the shared boundary line `} catch (er
```
</example>
<example name="replace whole block including closing brace">
Replace the entire body of `alpha`, including its closing `}`. `end` **MUST** be {{hlineref 7 "}"}} because `content` includes `}`.
```
{
path: "util.ts",
edits: [{
loc: { block: { pos: {{hlineref 6 "\tlog();"}}, end: {{hlineref 7 "}"}} } },
content: [
"\tvalidate();",
"\tlog();",
"}"
]
}]
}
```
**Wrong**: using `end: {{hlineref 6 "\tlog();"}}` with the same content — line 7 (`}`) survives the replacement AND content emits `}`, producing two closing braces.
</example>
<example name="replace one line">
```
{
@@ -108,9 +124,8 @@ When adding a sibling declaration, prefer `prepend` on the next declaration.
- Make the minimum exact edit. Do not rewrite nearby code unless the consumed range requires it.
- Use anchors exactly as `N#ID` from the latest `read` output.
- `block` requires both `pos` and `end`. Other anchored ops require one anchor.
- Replace exactly the owned span. If `content` re-emits content beyond `end`, it will duplicate.
- **Boundary duplication trap**: when replacing a block, `end` must be the **last line of the block** (e.g. the closing `}`), not the last *content* line before it. Otherwise the closing delimiter survives and your replacement adds a second copy.
- Do not target shared boundary lines such as `} else {`, `} catch (…) {`, `}),`, or `},{`.
- When your replacement `content` ends with a closing delimiter (`}`, `*/`, `)`, `]`), verify `end` includes the original line carrying that delimiter. If `end` stops one line too early, the original delimiter survives and your content adds a second copy.
- **Self-check**: compare the last line of `content` with the line immediately after `end` in the file. If they match (e.g., both are `}`), extend `end` to include that line.
- For a block, either replace only the body or replace the whole block. Do not split block boundaries.
- `content` must be literal file content with matching indentation. If the file uses tabs, use real tabs.
- Do not use this tool to reformat or clean up unrelated code.