@deathbeam/pi-rtk 0.0.0-stage → 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +42 -2
  3. package/index.ts +41 -0
  4. package/package.json +33 -4
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Tomas Slusny
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,43 @@
1
- # Temporary Holding Version
1
+ # [@deathbeam/pi-rtk](https://www.npmjs.com/package/@deathbeam/pi-rtk)
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Rewrite bash commands to [RTK](https://github.com/rtk-ai/rtk) (`rtk ...`) so tool output costs fewer tokens.
4
+
5
+ This is the RTK Pi hook packaged for the `packages` setting, so it replaces `rtk init -g --agent pi`, which
6
+ drops a loose file into `~/.pi/agent/extensions`. The decision logic stays in `rtk rewrite`; this package only
7
+ delegates to it. Adapted from [rtk-ai/rtk `hooks/pi/rtk.ts`](https://github.com/rtk-ai/rtk/blob/develop/hooks/pi/rtk.ts)
8
+ (Apache-2.0).
9
+
10
+ ## Installation
11
+
12
+ `rtk` must be in `PATH`.
13
+
14
+ ```sh
15
+ # Choose one:
16
+ pi install npm:@deathbeam/pi-rtk # this package
17
+ pi install git:github.com/deathbeam/pi-packages # all my packages
18
+ ```
19
+
20
+ Or add it to `packages` in `~/.pi/agent/settings.json` or `.pi/settings.json`:
21
+
22
+ ```json
23
+ {
24
+ "packages": ["npm:@deathbeam/pi-rtk"]
25
+ }
26
+ ```
27
+
28
+ ## Usage
29
+
30
+ Every bash command is passed to `rtk rewrite` before it runs. A rewrite replaces the command; no rewrite or a
31
+ missing `rtk` leaves it untouched.
32
+
33
+ `/rtk` shows the `rtk gain` report.
34
+
35
+ ## Development
36
+
37
+ From this package directory:
38
+
39
+ ```sh
40
+ npm install
41
+ npm test
42
+ pi install .
43
+ ```
package/index.ts ADDED
@@ -0,0 +1,41 @@
1
+ import type { BashToolCallEvent, ExecResult, ExtensionAPI, ToolCallEvent } from "@earendil-works/pi-coding-agent";
2
+
3
+ const isBash = (event: ToolCallEvent): event is BashToolCallEvent => event.toolName === "bash";
4
+
5
+ export function rewrittenCommand(result: ExecResult): string | null {
6
+ if (result.killed || (result.code !== 0 && result.code !== 3)) return null;
7
+ return result.stdout.trim() || null;
8
+ }
9
+
10
+ export default async function (pi: ExtensionAPI) {
11
+ if ((await pi.exec("rtk", ["--version"]).catch(() => null))?.code !== 0) return;
12
+
13
+ pi.on("tool_call", async (event, ctx) => {
14
+ if (!isBash(event)) return;
15
+ try {
16
+ const result = await pi.exec("rtk", ["rewrite", event.input.command], {
17
+ timeout: 2_000,
18
+ signal: ctx.signal,
19
+ });
20
+ const rewritten = rewrittenCommand(result);
21
+ if (rewritten) event.input.command = rewritten;
22
+ } catch {}
23
+ });
24
+
25
+ pi.registerCommand("rtk", {
26
+ description: "Show RTK token savings (rtk gain)",
27
+ handler: async (_args, ctx) => {
28
+ const result = await pi.exec("rtk", ["gain"], { timeout: 10_000 });
29
+ if (result.code !== 0) {
30
+ ctx.ui.notify(`rtk gain failed: ${result.stderr.trim() || `exit ${result.code}`}`, "error");
31
+ return;
32
+ }
33
+ pi.appendEntry("rtk-gain", result.stdout.trim());
34
+ },
35
+ });
36
+
37
+ pi.registerEntryRenderer("rtk-gain", (entry) => ({
38
+ render: () => String(entry.data ?? "").split("\n"),
39
+ invalidate: () => {},
40
+ }));
41
+ }
package/package.json CHANGED
@@ -1,6 +1,35 @@
1
1
  {
2
2
  "name": "@deathbeam/pi-rtk",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.0.1",
4
+ "description": "Minimal extension for rewriting bash commands to RTK (Rust Token Killer) for token savings.",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/deathbeam/pi-packages.git",
10
+ "directory": "packages/pi-rtk"
11
+ },
12
+ "keywords": [
13
+ "pi-package",
14
+ "pi-extension"
15
+ ],
16
+ "engines": {
17
+ "node": ">=22.19.0"
18
+ },
19
+ "files": [
20
+ "index.ts",
21
+ "README.md",
22
+ "LICENSE"
23
+ ],
24
+ "pi": {
25
+ "extensions": [
26
+ "./index.ts"
27
+ ]
28
+ },
29
+ "scripts": {
30
+ "test": "node check.mjs"
31
+ },
32
+ "peerDependencies": {
33
+ "@earendil-works/pi-coding-agent": "*"
34
+ }
35
+ }