coquibot/coqui-toolkit-code-edit
Composer 安装命令:
composer require coquibot/coqui-toolkit-code-edit
包简介
Surgical file editing toolkit for Coqui — replace, insert, remove, indent, batch operations with undo history
README 文档
README
Surgical file editing toolkit for Coqui. Provides precise, token-efficient code editing operations with full undo history — replace, insert, remove, indent, batch operations, all sandboxed to the workspace.
Requirements
- PHP 8.4+
- Coqui (auto-discovered via Composer)
Installation
composer require coquibot/coqui-toolkit-code-edit
When installed alongside Coqui, the toolkit is auto-discovered via Composer's extra.php-agents.toolkits — no manual registration needed.
Tools Provided
replace_in_file
Replace text in a file using plain string or PCRE regex matching.
| Parameter | Type | Required | Description |
|---|---|---|---|
path |
string | Yes | File path relative to workspace |
search |
string | Yes | Text or regex pattern to search for |
replace |
string | Yes | Replacement text (supports backreferences for regex) |
is_regex |
bool | No | Treat search as PCRE regex (default: false) |
flags |
string | No | PCRE modifier flags, e.g. "msi" |
insert_before
Insert content before lines matching an anchor pattern.
| Parameter | Type | Required | Description |
|---|---|---|---|
path |
string | Yes | File path relative to workspace |
anchor |
string | Yes | Text or regex to match lines against |
content |
string | Yes | Content to insert before each match |
is_regex |
bool | No | Treat anchor as PCRE regex (default: false) |
occurrences |
int | No | Matches to affect: 0=all, 1=first (default: 1) |
insert_after
Insert content after lines matching an anchor pattern.
| Parameter | Type | Required | Description |
|---|---|---|---|
path |
string | Yes | File path relative to workspace |
anchor |
string | Yes | Text or regex to match lines against |
content |
string | Yes | Content to insert after each match |
is_regex |
bool | No | Treat anchor as PCRE regex (default: false) |
occurrences |
int | No | Matches to affect: 0=all, 1=first (default: 1) |
replace_block
Replace a block of content between start and end markers (inclusive).
| Parameter | Type | Required | Description |
|---|---|---|---|
path |
string | Yes | File path relative to workspace |
start_marker |
string | Yes | Text or regex marking block start |
end_marker |
string | Yes | Text or regex marking block end |
new_content |
string | Yes | Content to replace the block with |
is_regex |
bool | No | Treat markers as PCRE regex (default: false) |
remove_lines
Remove a range of lines from a file.
| Parameter | Type | Required | Description |
|---|---|---|---|
path |
string | Yes | File path relative to workspace |
from |
int | Yes | Start line (1-based, inclusive) |
to |
int | Yes | End line (1-based, inclusive) |
extract_lines
Extract a range of lines from a file (read-only, does not modify the file).
| Parameter | Type | Required | Description |
|---|---|---|---|
path |
string | Yes | File path relative to workspace |
from |
int | Yes | Start line (1-based, inclusive) |
to |
int | Yes | End line (1-based, inclusive) |
batch_replace
Run search/replace across multiple files matching a glob pattern.
| Parameter | Type | Required | Description |
|---|---|---|---|
glob |
string | Yes | Glob pattern (e.g. "src/**/*.php") |
search |
string | Yes | Text or regex pattern |
replace |
string | Yes | Replacement text |
is_regex |
bool | No | Treat search as PCRE regex (default: false) |
flags |
string | No | PCRE modifier flags |
append_to_file
Append text to the end of a file. Creates the file if it doesn't exist.
| Parameter | Type | Required | Description |
|---|---|---|---|
path |
string | Yes | File path relative to workspace |
content |
string | Yes | Content to append |
write_lines
Overwrite a specific range of lines with new content.
| Parameter | Type | Required | Description |
|---|---|---|---|
path |
string | Yes | File path relative to workspace |
from |
int | Yes | Start line (1-based, inclusive) |
to |
int | Yes | End line (1-based, inclusive) |
content |
string | Yes | New content (can be more or fewer lines) |
indent_lines
Indent or outdent a range of lines.
| Parameter | Type | Required | Description |
|---|---|---|---|
path |
string | Yes | File path relative to workspace |
from |
int | Yes | Start line (1-based, inclusive) |
to |
int | Yes | End line (1-based, inclusive) |
direction |
enum | Yes | indent or outdent |
size |
int | No | Spaces per level (default: 4) |
use_tabs |
bool | No | Use tabs instead of spaces (default: false) |
undo_edit
Undo previous code-edit operations by restoring original file content.
| Parameter | Type | Required | Description |
|---|---|---|---|
edit_id |
int | No | Undo a specific edit by ID |
file |
string | No | File path to undo edits for (with count) |
count |
int | No | Number of recent edits to undo (default: 1) |
list_only |
bool | No | List recent edits without undoing (default: false) |
prune_days |
int | No | Remove backups older than N days |
Architecture
src/
├── CodeEditToolkit.php # Main toolkit — registers all tools
├── Exception/
│ └── CodeEditException.php # Domain exceptions
├── Storage/
│ └── EditHistory.php # SQLite edit log + file backups
├── Support/
│ ├── FileOperations.php # Atomic reads/writes, EOL detection
│ └── PathResolver.php # Workspace sandbox enforcement
└── Tool/
├── AppendToFileTool.php
├── BatchReplaceTool.php
├── ExtractLinesTool.php
├── IndentTool.php
├── InsertAfterTool.php
├── InsertBeforeTool.php
├── RemoveLinesTool.php
├── ReplaceBlockTool.php
├── ReplaceInFileTool.php
├── UndoEditTool.php
└── WriteLinesTool.php
Key Design Decisions
| Decision | Rationale |
|---|---|
| Separate tool classes | Each tool has distinct parameter shapes; keeps schemas clean for LLM consumption |
| Atomic writes (temp + rename) | Prevents partial writes from corrupting files on crash |
| SQLite edit history | Lightweight undo with per-edit granularity; auto-prune keeps storage bounded |
| Path sandboxing via PathResolver | All paths validated against workspace root; blocks directory traversal |
| EOL detection + preservation | Maintains CRLF/LF consistency when editing Windows or Unix files |
| Read-only extract_lines | No history overhead for inspection — only mutating ops record history |
Notes
- All paths are relative to the workspace root and sandboxed — directory traversal is blocked.
- Regex uses PCRE with
~as delimiter (no need to escape/in patterns). - Writes are atomic via temp file + rename to prevent corruption.
- Edit history is stored in
.workspace/code-edit/history.dbwith file backups in.workspace/code-edit/backups/. - Use
undo_edit(prune_days: 7)periodically to clean up old backups.
Development
composer install composer test # Run Pest tests composer analyse # Run PHPStan (level 8)
License
MIT
coquibot/coqui-toolkit-code-edit 适用场景与选型建议
coquibot/coqui-toolkit-code-edit 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 03 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「toolkit」 「refactoring」 「search-replace」 「php-agents」 「coqui」 「code-edit」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 coquibot/coqui-toolkit-code-edit 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 coquibot/coqui-toolkit-code-edit 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 coquibot/coqui-toolkit-code-edit 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Editable JSON AST with visitor traversal and formatting-preserving printing.
An extensible package of custom Rector rules for automated PHP refactoring and coding standard enforcement.
Symfony2 Bundle that adds basic user account entity and city/state/country setup as well
Database Search & Replace
Opinionated Rector rules for PHP — strict-assertion enforcement, no @phpstan-ignore, no env-checks in src, no superglobals, PSR Clock requirement, no direct DB / event-dispatch / assert() inside functional tests, and a comment-stripper that keeps only PHPStan tag blocks.
Common helpers and classes for ICanBoogie
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 42
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-03-17