pi-rg-fd 0.0.0-stage → 0.2.0

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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Li Tianyu
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,65 @@
1
- # Temporary Holding Version
1
+ # pi-rg-fd
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
+ Pi coding agent extension that always rewrites the default system prompt's `grep` and `find` advice to `rg` and `fd`.
4
+
5
+ Pi 1.4's bash tool line names `grep` and `find`, and the default guideline still names `find`, so models reach for those commands. This package replaces those two exact lines in place. The usual prompt gets shorter, and text that is not one of those Pi 1.4 lines is left as Pi wrote it. You confirm that `rg` and `fd` run on your machine.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ pi install npm:pi-rg-fd
11
+ ```
12
+
13
+ For one session without saving the install: `pi -e npm:pi-rg-fd`.
14
+
15
+ Requires [Pi](https://github.com/earendil-works/pi) 1.4.x (`@earendil-works/pi-coding-agent`).
16
+
17
+ ## Replaced lines
18
+
19
+ Verified against the published `@earendil-works/pi-coding-agent@1.4.0` sources (`dist/core/tools/bash.js` and `dist/core/system-prompt.js`). These are the only default prompt lines that name the `grep` or `find` commands. The read, edit, write, and ls tool snippets do not. The optional `grep` and `find` tools are separate Pi tools (they already shell out to `rg` and `fd`); their lines are left alone.
20
+
21
+ Bash tool snippet, before:
22
+
23
+ ```text
24
+ Execute bash commands (ls, grep, find, etc.)
25
+ ```
26
+
27
+ Default guideline (bash enabled, and the grep/find/ls tools off), before:
28
+
29
+ ```text
30
+ Use bash for file operations like ls, rg, find
31
+ ```
32
+
33
+ Those lines are always rewritten to:
34
+
35
+ ```text
36
+ Execute bash commands (ls, rg, fd, etc.)
37
+ Use bash for file operations like ls, rg, fd
38
+ ```
39
+
40
+ `rg` and `fd` are shorter than `grep` and `find`. If neither line is present (a custom system prompt, or a future Pi release that rewords them), the hook returns without changing the prompt. The `before_agent_start` hook is a string replace cached by the prompt text, so the same input always yields the same output.
41
+
42
+ Pi's interactive mode downloads `rg` and `fd` when they are missing, into `~/.pi/agent/bin` (or `$PI_CODING_AGENT_DIR/bin` when that variable is set; a leading `~` is expanded). Bash calls see that directory on `PATH`. The managed files are named `rg` and `fd`, plus `.exe` on Windows.
43
+
44
+ Debian and Ubuntu's apt package `fd-find` installs the binary as `fdfind`. Alias it so the rewritten prompt matches a command on `PATH`:
45
+
46
+ ```bash
47
+ alias fd=fdfind
48
+ ```
49
+
50
+ ## Prompt text only
51
+
52
+ `pi-cli-guard` and `pi-prefer-rg` rewrite or block bash commands when the model runs them. `pi-rg-fd` edits the system prompt Pi already built. Commands the model still emits run unchanged.
53
+
54
+ ## Compatibility
55
+
56
+ With `@earendil-works/pi-coding-agent` installed, `npm run compat` builds Pi's default system prompt from that package and loads this extension through Pi's extension loader. CI runs the same check on Ubuntu and Windows against the latest Pi release, every day and on manual dispatch.
57
+
58
+ ```bash
59
+ npm install --no-save @earendil-works/pi-coding-agent@latest
60
+ npm run compat
61
+ ```
62
+
63
+ ## License
64
+
65
+ MIT
package/index.js ADDED
@@ -0,0 +1,29 @@
1
+ import { rewritePrompt } from "./prompt.js";
2
+
3
+ const CACHE_LIMIT = 8;
4
+
5
+ export function createExtension() {
6
+ /** @type {Map<string, string>} */
7
+ const cache = new Map();
8
+
9
+ return function piRgFd(pi) {
10
+ pi.on("before_agent_start", (event) => {
11
+ const input = event.systemPrompt;
12
+ if (typeof input !== "string") return;
13
+
14
+ let output = cache.get(input);
15
+ if (output !== undefined) {
16
+ cache.delete(input);
17
+ cache.set(input, output);
18
+ } else {
19
+ output = rewritePrompt(input);
20
+ cache.set(input, output);
21
+ if (cache.size > CACHE_LIMIT) cache.delete(cache.keys().next().value);
22
+ }
23
+
24
+ if (output !== input) return { systemPrompt: output };
25
+ });
26
+ };
27
+ }
28
+
29
+ export default createExtension();
package/package.json CHANGED
@@ -1,6 +1,42 @@
1
1
  {
2
2
  "name": "pi-rg-fd",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.0",
4
+ "description": "Pi extension that rewrites the default grep/find prompt lines to rg and fd.",
5
+ "type": "module",
6
+ "main": "index.js",
7
+ "license": "MIT",
8
+ "author": "Li Tianyu",
9
+ "keywords": [
10
+ "pi-package",
11
+ "pi",
12
+ "extension",
13
+ "ripgrep",
14
+ "fd"
15
+ ],
16
+ "files": [
17
+ "index.js",
18
+ "prompt.js",
19
+ "README.md",
20
+ "LICENSE"
21
+ ],
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "git+https://github.com/TomXPRIME/pi-rg-fd.git"
25
+ },
26
+ "homepage": "https://github.com/TomXPRIME/pi-rg-fd",
27
+ "bugs": {
28
+ "url": "https://github.com/TomXPRIME/pi-rg-fd/issues"
29
+ },
30
+ "engines": {
31
+ "node": ">=22.19.0"
32
+ },
33
+ "scripts": {
34
+ "test": "node --test",
35
+ "compat": "node scripts/compat.js"
36
+ },
37
+ "pi": {
38
+ "extensions": [
39
+ "./index.js"
40
+ ]
41
+ }
42
+ }
package/prompt.js ADDED
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Default bash tool line in @earendil-works/pi-coding-agent 1.4.0
3
+ * (`bashToolSystemPromptContribution.snippet`).
4
+ */
5
+ export const BASH_SNIPPET = "Execute bash commands (ls, grep, find, etc.)";
6
+
7
+ /**
8
+ * Default guideline in Pi 1.4.0 when bash is enabled and the grep, find, and
9
+ * ls tools are not (`buildRules` in `system-prompt.js`).
10
+ */
11
+ export const BASH_RULE = "Use bash for file operations like ls, rg, find";
12
+
13
+ const REWRITTEN_SNIPPET = "Execute bash commands (ls, rg, fd, etc.)";
14
+ const REWRITTEN_RULE = "Use bash for file operations like ls, rg, fd";
15
+
16
+ /**
17
+ * @param {string} text
18
+ * @param {string} from
19
+ * @param {string} to
20
+ */
21
+ function replaceExact(text, from, to) {
22
+ if (from === to || !text.includes(from)) return text;
23
+ return text.replaceAll(from, to);
24
+ }
25
+
26
+ /**
27
+ * Replace Pi's default grep/find lines in place. Unknown text is returned
28
+ * unchanged (same string when nothing matches).
29
+ *
30
+ * @param {string} prompt
31
+ */
32
+ export function rewritePrompt(prompt) {
33
+ let next = replaceExact(prompt, BASH_SNIPPET, REWRITTEN_SNIPPET);
34
+ next = replaceExact(next, BASH_RULE, REWRITTEN_RULE);
35
+ return next;
36
+ }