npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@buddhilive/dsh-tool-str-replace-editor

v0.1.2-alpha.3

Published

Model-facing view, create, literal replace, and line insert tool over the Harness filesystem service

Readme


description: "基于 ctx.fs 的独立 str_replace_editor 工具:供组合 Claude Code 风格文件编辑能力的用户与维护者使用。" kind: "package-reference"

@buddhilive/dsh-tool-str-replace-editor

English | 中文

概述

dsh-tool-str-replace-editor 提供基于 ctx.fs 的独立面向模型 str_replace_editor 工具:view 显示带行号的文件内容或浅层目录列表,create 创建新文件,str_replace 应用唯一的字面量替换,insert 在选定的边界处插入行。它可以与持久 Bash、一次性 Bash、沙箱 Bash 或其他终端接口组合。修改操作遵守与 fs 家族其余部分相同的编辑前读取策略与沙箱围栏,具体由所挂载的后端与策略插件强制执行。当部署需要 Claude Code 风格、使用绝对路径的单一编辑器工具时选择它;dsh-tool-fs 包提供替代的 read/write/edit 套件。

目录


使用本包

当模型应通过熟悉的 view/create/str_replace/insert 命令词汇在绝对路径上编辑文件时,把工具与 ctx.fs 后端(以及需要防护变更时的策略插件)一起挂载。

最小组合

一个后端、可选地加策略插件,然后是工具;编辑器可与任何终端接口组合。

- name: '@buddhilive/dsh-fs-local'
- name: '@buddhilive/dsh-fs-observation-policy'
- name: '@buddhilive/dsh-tool-str-replace-editor'

配置

| 键 | 默认值 | 含义 | |---|---|---| | maxOutputChars | 16000 | 文件和目录查看结果保留的前缀字符数 | | description | Custom editing tool for viewing, creating and editing files(多行) | 面向模型的工具描述 |

命令

view 返回从 1 开始编号的文件内容(保留制表符,因此显示的文本仍可作为有效的字面量替换输入)或忽略隐藏、依赖与 Python 缓存条目的两层目录列表。create 创建新文件,并拒绝覆盖现有文件。选定命令不使用的专用字段可以包含 null 占位符;必填字段仍保持必填,view_range: null 选择完整视图,str_replace.new_str: null 会被拒绝,因此删除内容必须省略该字段。str_replace 要求字面量唯一匹配,错误只使用公开的 old_str 词汇;insert 遵循所选的零基插入边界,不会隐式补尾换行。修改操作会保留请求编辑范围之外的制表符。

失败与恢复

viewstr_replaceinsert 发生元数据未命中时,工具会在返回 FS_NOT_FOUND 前记录确认缺失,因此后续 create 可以通过已挂载策略的防护创建流程恢复外部删除的路径;缺失状态绝不会授权 str_replaceinsert。防护变更继承策略插件的错误码与恢复指令——FS_NOT_OBSERVED(先读取文件再重试)、FS_STALE_VERSION(先重新读取再重试)——沙箱拒绝则表现为 [sandbox: file access denied under <mode> mode] 标记。路径必须是绝对路径;相对路径会被拒绝并给出提示。


理解实现

本节解释编辑器工具背后的设计决策,并指出实现它们的代码位置;可观察行为已在使用本包中完整说明。

设计理念

该工具是基于 ctx.fs 的单一 schema、四个命令。修改操作绝不带着自己的假设直接触碰提供方:每个操作都运行 fs/write-intentfs/edit-intent waterfall 以取得策略插件的防护,在已挂载的 ctx.fs 实施沙箱限制时解析按调用沙箱策略,并把强制执行委托给提供方。str_replaceinsert 还会重新读取文件,并在没有策略插件提供防护时把观察到的版本作为比较并交换的基础。

源码地图

| 文件 | 职责 | |---|---| | src/index.ts | 整个工具:schema、命令分派、查看渲染、修改策略 |

各命令如何运行

每个命令都先解析绝对路径;修改操作随后遵循同一条共享流程——策略防护、提供方强制执行、成功后记录 fs/observed——而 view 只执行 stat 并渲染。整个工具——schema、命令分派与查看渲染——都位于 src/index.ts


进一步探索

当包级约定不够用时阅读以下页面。它们从工具逐步进入它所组合的约定、策略与后端。


模型体验

工具 schema

模型看到的内容

生成的 str_replace_editor schema,包含配置的 description。本插件不贡献独立系统提示词段。

Token 影响

str_replace_editor 可见时产生固定的 schema 成本。

KV Cache 影响

配置的描述与 schema 不变时前缀稳定。

工具结果

模型看到的内容

查看操作返回带行号文本或浅层目录列表。调用会提供文件位置,创建/替换调用还会向展示层提供 diff 卡片。修改操作返回简洁确认。长查看结果保留前缀并追加截断提示。

Token 影响

随数据变化,并受 maxOutputChars 与固定截断提示约束。

KV Cache 影响

工具结果以追加方式位于可复用请求前缀之后。

已知限制与延期工作

这些限制说明编辑器工具何时不合适,或何时需要特别的运维注意。它们是当前包约束,不是通用编辑器对比或任务积压。

  • 操作面向 UTF-8 文本——不支持二进制文件。
  • str_replace 刻意拒绝零匹配或多匹配——它没有 replace_all 参数。
  • 每个修改操作都会经过已挂载的策略与沙箱——fs/write-intentfs/edit-intent 解析当前会话的沙箱策略,并把强制执行委托给已挂载的文件系统与策略插件,因此未挂载它们的部署会得到无条件变更。

开发备注

无。