1
24
近 7 天 4
28.5
生态多维模型
1 个月前
2026-06-29
快速安装与配置
opencode.json写入当前项目的 opencode.json,只对这个仓库生效。
opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["@debugtalk/opencode-hashline@0.2.1"]
}写入 ~/.config/opencode/opencode.json,对所有项目生效。
~/.config/opencode/opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["@debugtalk/opencode-hashline@0.2.1"]
}若你要在本地改造这个插件,先装到项目里再从本地路径引用。
shell
pnpm add -D @debugtalk/opencode-hashlineopencode 启动时会通过内嵌运行时自动加载 npm 依赖并缓存至本地目录,无需手动在全局环境执行安装。
OpenCode plugin adapter for hashline — compact, line-anchored, tag-verified file edits. Powered by @oh-my-pi/hashline.
Instead of exact-string matching (which forces models to re-type old content and risks drift), hashline uses line-number anchors combined with content-hash tags so every edit is validated against the exact file snapshot the model saw. This plugin wraps the hashline engine as an OpenCode edit tool override and snapshot injection hook.
Package name: Published as
@debugtalk/opencode-hashlineon npm. The unscoped nameopencode-hashlineis used by a different package on the public registry.
Installation
opencode plugin @debugtalk/opencode-hashline
Install globally:
opencode plugin @debugtalk/opencode-hashline --global
Restart OpenCode. No build step — OpenCode loads the TypeScript plugin entry directly.
Upgrade
opencode plugin @debugtalk/opencode-hashline --force
Verify
grep "opencode-hashline" ~/.local/share/opencode/log/opencode.log
opencode-hashline plugin loaded → success.
How It Works
The plugin overrides the built-in edit tool and injects snapshot tags into read output:
- Read — output starts with
[path/file.ts#A1B2](4-hex content hash of the file) - Edit —
[path/file.ts#A1B2]plus line-anchored ops; tag must match current file content - Drift — mismatch rejects the edit (with recovery when possible); re-read and retry
Edit syntax (format v2)
[src/foo.ts#A1B2]
SWAP 2.=2:
+ return newValue
INS.POST 10:
+ // new comment
DEL 5.=7
INS.HEAD:
+# SPDX-License-Identifier: MIT
| Operation | Syntax | Description |
|---|---|---|
| Replace lines | SWAP N.=M: |
Replace inclusive range N..M with + body rows |
| Delete lines | DEL N.=M or DEL N |
Delete range; no body |
| Insert before | INS.PRE N: |
Insert before line N |
| Insert after | INS.POST N: |
Insert after line N |
| Insert head | INS.HEAD: |
Insert at file start |
| Insert tail | INS.TAIL: |
Insert at file end |
| Delete file | REM |
Remove entire file (section header required) |
| Move/rename | MV dest/path |
Move file to dest/path |
Body rows are +TEXT only. The range deletes; the body is the final content for that range.
Rules
- Line numbers refer to the original file; they do not shift as hunks apply in one patch
- Every successful edit returns a new
#TAG— use it for the next edit or re-read - Ranges should cover only lines that change
- On stale tag or unexpected result: stop and re-read
Configuration
No configuration required.
Programmatic use (hashline core)
Use the upstream package directly:
import { Patch, Patcher, NodeFilesystem, InMemorySnapshotStore } from "@oh-my-pi/hashline";
Limitations
SWAP.BLK N:not supported — tree-sitter block resolver not bundled; useSWAP N.=M:line ranges- OpenCode only — this npm package targets the OpenCode plugin runtime; see
docs/cross-platform-plugins.mdfor other agents
Docs
License
MIT