pi-repoprompt-cli 0.2.0 → 0.2.5
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/README.md +44 -2
- package/extensions/repoprompt-cli/README.md +94 -0
- package/extensions/repoprompt-cli/config.json.example +3 -0
- package/extensions/repoprompt-cli/config.ts +47 -0
- package/extensions/repoprompt-cli/index.ts +1671 -0
- package/extensions/repoprompt-cli/readcache/LICENSE +23 -0
- package/extensions/repoprompt-cli/readcache/constants.ts +38 -0
- package/extensions/repoprompt-cli/readcache/diff.ts +129 -0
- package/extensions/repoprompt-cli/readcache/meta.ts +241 -0
- package/extensions/repoprompt-cli/readcache/object-store.ts +184 -0
- package/extensions/repoprompt-cli/readcache/read-file.ts +438 -0
- package/extensions/repoprompt-cli/readcache/replay.ts +366 -0
- package/extensions/repoprompt-cli/readcache/resolve.ts +235 -0
- package/extensions/repoprompt-cli/readcache/text.ts +43 -0
- package/extensions/repoprompt-cli/readcache/types.ts +73 -0
- package/extensions/repoprompt-cli/types.ts +6 -0
- package/package.json +26 -3
package/README.md
CHANGED
|
@@ -6,8 +6,14 @@ Provides two tools:
|
|
|
6
6
|
- `rp_bind` — bind a RepoPrompt window + compose tab (routing)
|
|
7
7
|
- `rp_exec` — run `rp-cli -e <cmd>` against that binding (quiet defaults + output truncation)
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
Optional:
|
|
10
|
+
- [Gurpartap/pi-readcache](https://github.com/Gurpartap/pi-readcache)-like caching for `rp_exec` calls that read files (`read` / `cat` / `read_file`) to save on tokens
|
|
11
|
+
- returns unchanged markers and diffs on repeat reads
|
|
12
|
+
|
|
13
|
+
Also provides convenience commands:
|
|
10
14
|
- `/rpbind <window_id> <tab>`
|
|
15
|
+
- `/rpcli-readcache-status`
|
|
16
|
+
- `/rpcli-readcache-refresh <path> [start-end]`
|
|
11
17
|
|
|
12
18
|
## Install
|
|
13
19
|
|
|
@@ -26,7 +32,7 @@ Add to `~/.pi/agent/settings.json` (or replace an existing unfiltered `git:githu
|
|
|
26
32
|
"packages": [
|
|
27
33
|
{
|
|
28
34
|
"source": "git:github.com/w-winter/dot314",
|
|
29
|
-
"extensions": ["extensions/repoprompt-cli.ts"],
|
|
35
|
+
"extensions": ["extensions/repoprompt-cli/index.ts"],
|
|
30
36
|
"skills": [],
|
|
31
37
|
"themes": [],
|
|
32
38
|
"prompts": []
|
|
@@ -39,6 +45,18 @@ Add to `~/.pi/agent/settings.json` (or replace an existing unfiltered `git:githu
|
|
|
39
45
|
|
|
40
46
|
- `rp-cli` must be installed and available on `PATH`
|
|
41
47
|
|
|
48
|
+
## Configuration
|
|
49
|
+
|
|
50
|
+
Enable readcache (optional):
|
|
51
|
+
|
|
52
|
+
Create `~/.pi/agent/extensions/repoprompt-cli/config.json`:
|
|
53
|
+
|
|
54
|
+
```json
|
|
55
|
+
{
|
|
56
|
+
"readcacheReadFile": true
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
42
60
|
## Quick start
|
|
43
61
|
|
|
44
62
|
1) Find your RepoPrompt window + tab (from a terminal):
|
|
@@ -60,6 +78,30 @@ rp-cli -e "workspace tabs"
|
|
|
60
78
|
Use rp_exec with cmd: "get_file_tree type=files max_depth=4".
|
|
61
79
|
```
|
|
62
80
|
|
|
81
|
+
If `readcacheReadFile` is enabled, repeat reads can be token-optimized:
|
|
82
|
+
|
|
83
|
+
```text
|
|
84
|
+
Use rp_exec with cmd: "read path=src/main.ts start_line=1 limit=120".
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
To force baseline output for a specific read:
|
|
88
|
+
|
|
89
|
+
```text
|
|
90
|
+
Use rp_exec with cmd: "read path=src/main.ts start_line=1 limit=120 bypass_cache=true".
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Notes:
|
|
94
|
+
- Readcache only triggers for **single-command** reads. Compound commands (`&&`, `;`, `|`) fail open to baseline output
|
|
95
|
+
- When `just-bash` AST parsing is unavailable, caching only applies to unquoted/unescaped single-command reads; quoted/escaped forms fail open
|
|
96
|
+
- `rawJson=true` disables caching
|
|
97
|
+
|
|
98
|
+
## Readcache gotchas
|
|
99
|
+
|
|
100
|
+
- `rawJson=true` disables readcache. Don't use unless debugging
|
|
101
|
+
- Need full content? rerun with `bypass_cache=true`
|
|
102
|
+
- Single-command reads only (no `&&` / `;` / `|`)
|
|
103
|
+
- Multi-root: use absolute or specific relative paths
|
|
104
|
+
|
|
63
105
|
## Safety behavior (by default)
|
|
64
106
|
|
|
65
107
|
- Blocks delete-like commands unless `allowDelete: true`
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# RepoPrompt CLI extension for Pi (`repoprompt-cli`)
|
|
2
|
+
|
|
3
|
+
This folder contains the Pi extension that integrates the **RepoPrompt CLI** (`rp-cli`) into Pi.
|
|
4
|
+
|
|
5
|
+
It provides two Pi tools:
|
|
6
|
+
|
|
7
|
+
- `rp_bind` — bind to a specific RepoPrompt **window id** + **compose tab** (routing)
|
|
8
|
+
- `rp_exec` — run `rp-cli -e <cmd>` against that binding
|
|
9
|
+
|
|
10
|
+
## Optional: readcache for `rp_exec read`
|
|
11
|
+
|
|
12
|
+
If enabled, `rp_exec` will apply [Gurpartap/pi-readcache](https://github.com/Gurpartap/pi-readcache)-like token savings for single-command file reads, returning:
|
|
13
|
+
|
|
14
|
+
- an *unchanged marker* on repeat reads, or
|
|
15
|
+
- a *unified diff* when a reread changed and the diff is small/useful, otherwise
|
|
16
|
+
- baseline output (fail-open)
|
|
17
|
+
|
|
18
|
+
### Enable
|
|
19
|
+
|
|
20
|
+
Create:
|
|
21
|
+
|
|
22
|
+
- `~/.pi/agent/extensions/repoprompt-cli/config.json`
|
|
23
|
+
|
|
24
|
+
```json
|
|
25
|
+
{
|
|
26
|
+
"readcacheReadFile": true
|
|
27
|
+
}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Note: when enabled, the extension may persist UTF-8 file snapshots to an on-disk content-addressed store under
|
|
31
|
+
`<repo-root>/.pi/readcache/objects` to compute diffs/unchanged markers across calls. Common secret filenames (e.g. `.env*`, `*.pem`) are excluded,
|
|
32
|
+
but this is best-effort
|
|
33
|
+
|
|
34
|
+
### Supported read forms (cached)
|
|
35
|
+
|
|
36
|
+
Caching only triggers when `cmd` is a **single** read-like invocation (no chains / pipes):
|
|
37
|
+
|
|
38
|
+
- `read <path> [start] [limit]`
|
|
39
|
+
- `read <path> -N` (tail)
|
|
40
|
+
- `cat <path> [start] [limit]`
|
|
41
|
+
- `read_file path=<path> start_line=<n> limit=<n>`
|
|
42
|
+
- slice suffix: `read <path>:<start>-<end>` (or `path=<path>:<start>-<end>`)
|
|
43
|
+
|
|
44
|
+
### Bypass for a single call
|
|
45
|
+
|
|
46
|
+
Add `bypass_cache=true` to the `cmd`:
|
|
47
|
+
|
|
48
|
+
```text
|
|
49
|
+
rp_exec cmd="read path=src/main.ts start_line=1 limit=120 bypass_cache=true"
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Readcache gotchas
|
|
53
|
+
|
|
54
|
+
- `rawJson=true` disables readcache. Don't use unless debugging
|
|
55
|
+
- Need full content? rerun with `bypass_cache=true`
|
|
56
|
+
- Single-command reads only (no `&&` / `;` / `|`)
|
|
57
|
+
- Multi-root: use absolute or specific relative paths
|
|
58
|
+
|
|
59
|
+
### When caching will NOT trigger
|
|
60
|
+
|
|
61
|
+
`rp_exec` intentionally fails open to baseline output when parsing is ambiguous or unsafe. Caching is disabled for:
|
|
62
|
+
|
|
63
|
+
- **fallback parser limitation**: when `just-bash` AST parsing is unavailable, only unquoted/unescaped single-command reads are parsed for caching. Quoted/escaped forms (e.g. paths with spaces) will fail open to baseline output
|
|
64
|
+
|
|
65
|
+
- compound commands: `&&`, `;`, pipelines (`|`)
|
|
66
|
+
- multiple top-level invocations in one `cmd`
|
|
67
|
+
- `rawJson=true`
|
|
68
|
+
- unbound execution (no window/tab)
|
|
69
|
+
- read requests with unknown flags/args that prevent canonicalization
|
|
70
|
+
|
|
71
|
+
## Slash commands
|
|
72
|
+
|
|
73
|
+
These are **Pi slash commands** (for the chat UI), not `rp_exec` commands:
|
|
74
|
+
|
|
75
|
+
- `/rpbind <window_id> <tab>`
|
|
76
|
+
- `/rpcli-readcache-status`
|
|
77
|
+
- `/rpcli-readcache-refresh <path> [start-end]`
|
|
78
|
+
|
|
79
|
+
## Smoke test
|
|
80
|
+
|
|
81
|
+
1) Bind:
|
|
82
|
+
|
|
83
|
+
```text
|
|
84
|
+
/rpbind 4 Compose
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
2) Read the same range twice:
|
|
88
|
+
|
|
89
|
+
```text
|
|
90
|
+
Use rp_exec with cmd: "read src/main.ts 1 40".
|
|
91
|
+
Use rp_exec with cmd: "read src/main.ts 1 40".
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
The second call should return a `[readcache: ...]` marker.
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// config.ts - configuration loading for the repoprompt-cli extension
|
|
2
|
+
|
|
3
|
+
import * as fs from "node:fs";
|
|
4
|
+
import * as os from "node:os";
|
|
5
|
+
import * as path from "node:path";
|
|
6
|
+
|
|
7
|
+
import type { RpCliConfig } from "./types.js";
|
|
8
|
+
|
|
9
|
+
const DEFAULT_CONFIG: Required<RpCliConfig> = {
|
|
10
|
+
readcacheReadFile: false,
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const CONFIG_LOCATIONS = [
|
|
14
|
+
() => path.join(os.homedir(), ".pi", "agent", "extensions", "repoprompt-cli", "config.json"),
|
|
15
|
+
];
|
|
16
|
+
|
|
17
|
+
function tryReadJson<T>(filePath: string): T | null {
|
|
18
|
+
try {
|
|
19
|
+
const content = fs.readFileSync(filePath, "utf-8");
|
|
20
|
+
return JSON.parse(content) as T;
|
|
21
|
+
} catch {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function loadConfig(overrides?: Partial<RpCliConfig>): Required<RpCliConfig> {
|
|
27
|
+
let config: Required<RpCliConfig> = { ...DEFAULT_CONFIG };
|
|
28
|
+
|
|
29
|
+
for (const getPath of CONFIG_LOCATIONS) {
|
|
30
|
+
const candidate = getPath();
|
|
31
|
+
if (!fs.existsSync(candidate)) {
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const fileConfig = tryReadJson<Partial<RpCliConfig>>(candidate);
|
|
36
|
+
if (fileConfig) {
|
|
37
|
+
config = { ...config, ...fileConfig };
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (overrides) {
|
|
43
|
+
config = { ...config, ...overrides };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return config;
|
|
47
|
+
}
|