pi-lean-ctx 1.0.1 → 1.0.3
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 +5 -1
- package/extensions/index.ts +23 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -42,12 +42,16 @@ The `read` tool automatically selects the optimal lean-ctx mode:
|
|
|
42
42
|
| File Type | Size | Mode |
|
|
43
43
|
|-----------|------|------|
|
|
44
44
|
| `.md`, `.json`, `.toml`, `.yaml`, etc. | Any | `full` |
|
|
45
|
-
| Code files (
|
|
45
|
+
| Code files (55+ extensions) | < 24 KB | `full` |
|
|
46
46
|
| Code files | 24–160 KB | `map` (deps + API signatures) |
|
|
47
47
|
| Code files | > 160 KB | `signatures` (AST extraction) |
|
|
48
48
|
| Other files | < 48 KB | `full` |
|
|
49
49
|
| Other files | > 48 KB | `map` |
|
|
50
50
|
|
|
51
|
+
Code extensions include: `.rs`, `.ts`, `.tsx`, `.js`, `.jsx`, `.py`, `.go`, `.java`, `.c`, `.cpp`, `.cs`, `.rb`, `.php`, `.swift`, `.kt`, `.vue`, `.svelte`, `.astro`, `.html`, `.css`, `.scss`, `.lua`, `.zig`, `.dart`, `.scala`, `.sql`, `.graphql`, `.proto`, `.tf`, `.sh`, `.bash`, `.zsh`, `.fish`, `.ps1`, and more.
|
|
52
|
+
|
|
53
|
+
**Partial reads** (with `offset`/`limit`) are also routed through lean-ctx using `lines:N-M` mode for compression.
|
|
54
|
+
|
|
51
55
|
## Slash Command
|
|
52
56
|
|
|
53
57
|
Use `/lean-ctx` in Pi to check which binary is being used.
|
package/extensions/index.ts
CHANGED
|
@@ -18,6 +18,11 @@ import { homedir, platform } from "node:os";
|
|
|
18
18
|
const CODE_EXTENSIONS = new Set([
|
|
19
19
|
".rs", ".ts", ".tsx", ".js", ".jsx", ".php", ".py", ".go",
|
|
20
20
|
".java", ".c", ".cc", ".cpp", ".cxx", ".cs", ".kt", ".swift", ".rb",
|
|
21
|
+
".vue", ".svelte", ".astro", ".html", ".css", ".scss", ".sass", ".less",
|
|
22
|
+
".lua", ".zig", ".nim", ".ex", ".exs", ".erl", ".hs", ".ml", ".mli",
|
|
23
|
+
".r", ".jl", ".dart", ".scala", ".groovy", ".pl", ".pm", ".sh", ".bash",
|
|
24
|
+
".zsh", ".fish", ".ps1", ".bat", ".cmd", ".sql", ".graphql", ".gql",
|
|
25
|
+
".proto", ".thrift", ".tf", ".hcl", ".nix", ".dhall",
|
|
21
26
|
]);
|
|
22
27
|
|
|
23
28
|
const FULL_READ_EXTENSIONS = new Set([
|
|
@@ -346,11 +351,24 @@ export default function (pi: ExtensionAPI) {
|
|
|
346
351
|
const absolutePath = resolve(ctx.cwd, requestedPath);
|
|
347
352
|
|
|
348
353
|
if (params.offset !== undefined || params.limit !== undefined) {
|
|
349
|
-
const
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
+
const startLine = params.offset ?? 1;
|
|
355
|
+
const endLine = params.limit ? startLine + params.limit - 1 : 999999;
|
|
356
|
+
const args = ["read", absolutePath, "-m", `lines:${startLine}-${endLine}`];
|
|
357
|
+
try {
|
|
358
|
+
const output = await execLeanCtx(pi, args);
|
|
359
|
+
const originalSlice = await readSlice(absolutePath, params.offset, params.limit);
|
|
360
|
+
const decorated = withFooter(output, { originalText: originalSlice.text, always: true, preferEstimate: true });
|
|
361
|
+
return {
|
|
362
|
+
content: [{ type: "text", text: decorated.text }],
|
|
363
|
+
details: { path: absolutePath, lines: originalSlice.lines, source: "lean-ctx", mode: `lines:${startLine}-${endLine}`, compression: decorated.stats },
|
|
364
|
+
};
|
|
365
|
+
} catch {
|
|
366
|
+
const sliced = await readSlice(absolutePath, params.offset, params.limit);
|
|
367
|
+
return {
|
|
368
|
+
content: [{ type: "text", text: sliced.text }],
|
|
369
|
+
details: { path: absolutePath, lines: sliced.lines, source: "local-slice-fallback", truncated: sliced.truncated },
|
|
370
|
+
};
|
|
371
|
+
}
|
|
354
372
|
}
|
|
355
373
|
|
|
356
374
|
if (IMAGE_EXTENSIONS.has(extname(absolutePath).toLowerCase())) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-lean-ctx",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "Pi Coding Agent extension that routes bash, read, grep, find, and ls through lean-ctx for 60-90% token savings",
|
|
5
5
|
"keywords": ["pi-package", "lean-ctx", "token-optimization", "compression"],
|
|
6
6
|
"license": "MIT",
|