mirror of
https://github.com/rtk-ai/rtk.git
synced 2026-09-19 07:33:17 +08:00
56160d8399
* feat: add OpenClaw plugin for transparent exec rewriting Adds an OpenClaw plugin that intercepts exec tool calls via the before_tool_call hook and rewrites commands to their RTK equivalents. This is the OpenClaw equivalent of hooks/rtk-rewrite.sh for Claude Code. The plugin: - Registers a before_tool_call hook on the exec tool - Rewrites git, grep, find, ls, gh, docker, kubectl, and test commands - Guards against rewriting piped/compound commands and heredocs - Returns properly typed PluginHookBeforeToolCallResult - Supports enabled/verbose config options Measured savings: 48-87% token reduction on common commands. Files: - openclaw/index.ts — plugin source - openclaw/openclaw.plugin.json — plugin manifest - openclaw/README.md — installation and usage docs * refactor: delegate OpenClaw plugin to rtk rewrite Replace 60+ hardcoded regex rules with a single call to `rtk rewrite`, matching the OpenCode plugin pattern (hooks/opencode-rtk.ts). Benefits: - Zero maintenance: new RTK filters work automatically - Single source of truth: rewrite logic in Rust (src/discover/registry.rs) - 122 → 73 lines, no rule duplication Also: rebase on develop, fix homepage URL, bump version to 1.0.0. Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu> * feat: add package.json for npm publishing Enables `openclaw plugins install @rtk-ai/rtk-rewrite` for OpenClaw users. Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu> --------- Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu> Co-authored-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu>
87 lines
2.1 KiB
Markdown
87 lines
2.1 KiB
Markdown
# RTK Plugin for OpenClaw
|
|
|
|
Transparently rewrites shell commands executed via OpenClaw's `exec` tool to their RTK equivalents, achieving 60-90% LLM token savings.
|
|
|
|
This is the OpenClaw equivalent of the Claude Code hooks in `hooks/rtk-rewrite.sh`.
|
|
|
|
## How it works
|
|
|
|
The plugin registers a `before_tool_call` hook that intercepts `exec` tool calls. When the agent runs a command like `git status`, the plugin delegates to `rtk rewrite` which returns the optimized command (e.g. `rtk git status`). The compressed output enters the agent's context window, saving tokens.
|
|
|
|
All rewrite logic lives in RTK itself (`rtk rewrite`). This plugin is a thin delegate -- when new filters are added to RTK, the plugin picks them up automatically with zero changes.
|
|
|
|
## Installation
|
|
|
|
### Prerequisites
|
|
|
|
RTK must be installed and available in `$PATH`:
|
|
|
|
```bash
|
|
brew install rtk
|
|
# or
|
|
curl -fsSL https://raw.githubusercontent.com/rtk-ai/rtk/refs/heads/master/install.sh | sh
|
|
```
|
|
|
|
### Install the plugin
|
|
|
|
```bash
|
|
# Copy the plugin to OpenClaw's extensions directory
|
|
mkdir -p ~/.openclaw/extensions/rtk-rewrite
|
|
cp openclaw/index.ts openclaw/openclaw.plugin.json ~/.openclaw/extensions/rtk-rewrite/
|
|
|
|
# Restart the gateway
|
|
openclaw gateway restart
|
|
```
|
|
|
|
### Or install via OpenClaw CLI
|
|
|
|
```bash
|
|
openclaw plugins install ./openclaw
|
|
```
|
|
|
|
## Configuration
|
|
|
|
In `openclaw.json`:
|
|
|
|
```json5
|
|
{
|
|
plugins: {
|
|
entries: {
|
|
"rtk-rewrite": {
|
|
enabled: true,
|
|
config: {
|
|
enabled: true, // Toggle rewriting on/off
|
|
verbose: false // Log rewrites to console
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
```
|
|
|
|
## What gets rewritten
|
|
|
|
Everything that `rtk rewrite` supports (30+ commands). See the [full command list](https://github.com/rtk-ai/rtk#commands).
|
|
|
|
## What's NOT rewritten
|
|
|
|
Handled by `rtk rewrite` guards:
|
|
- Commands already using `rtk`
|
|
- Piped commands (`|`, `&&`, `;`)
|
|
- Heredocs (`<<`)
|
|
- Commands without an RTK filter
|
|
|
|
## Measured savings
|
|
|
|
| Command | Token savings |
|
|
|---------|--------------|
|
|
| `git log --stat` | 87% |
|
|
| `ls -la` | 78% |
|
|
| `git status` | 66% |
|
|
| `grep` (single file) | 52% |
|
|
| `find -name` | 48% |
|
|
|
|
## License
|
|
|
|
MIT -- same as RTK.
|