pi-lean-ctx 3.4.1 → 3.4.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.
Files changed (2) hide show
  1. package/extensions/index.ts +36 -18
  2. package/package.json +12 -4
@@ -271,19 +271,37 @@ export default function (pi: ExtensionAPI) {
271
271
  },
272
272
  });
273
273
 
274
+ const rawBash = createBashToolDefinition(process.cwd());
275
+
276
+ const bashSchemaWithRaw = Type.Object({
277
+ command: Type.String({ description: "Bash command to execute" }),
278
+ timeout: Type.Optional(Type.Number({ description: "Timeout in seconds to prevent hanging commands" })),
279
+ raw: Type.Optional(Type.Boolean({ description: "Skip compression, return full uncompressed output" })),
280
+ });
281
+
274
282
  pi.registerTool({
275
283
  ...baseBashTool,
284
+ parameters: bashSchemaWithRaw,
276
285
  description:
277
- "Execute a bash command through lean-ctx compression for 60-90% smaller output.",
278
- promptSnippet: "Run shell commands through lean-ctx compression.",
286
+ "Execute a bash command. Output is auto-compressed by lean-ctx. "
287
+ + "IMPORTANT: Do NOT use bash to read files (cat/head/tail) — use the read tool instead. "
288
+ + "Do NOT use bash for grep/find/ls — use the dedicated tools. "
289
+ + "Set raw=true to skip compression when exact output matters. "
290
+ + "Use timeout (seconds) to prevent hanging commands.",
291
+ promptSnippet: "Run shell commands (not for file reading — use read tool)",
279
292
  promptGuidelines: [
280
- "Use bash normally commands are automatically routed through lean-ctx.",
281
- "lean-ctx compresses verbose CLI output (git, cargo, npm, docker, kubectl, etc.) automatically.",
293
+ "Use bash only for commands with side effects: build, test, install, git, run scripts.",
282
294
  ],
283
295
  async execute(toolCallId, params, signal, onUpdate, ctx) {
296
+ const isRaw = !!params.raw;
297
+ const toolParams = { command: params.command, timeout: params.timeout };
298
+ const tool = isRaw ? rawBash : baseBashTool;
284
299
  try {
285
- const result = await baseBashTool.execute(toolCallId, params, signal, onUpdate, ctx);
300
+ const result = await tool.execute(toolCallId, toolParams, signal, onUpdate, ctx);
286
301
  const text = result.content?.[0]?.type === "text" ? result.content[0].text : "";
302
+ if (isRaw) {
303
+ return { ...result, content: [{ type: "text", text }], details: { raw: true } };
304
+ }
287
305
  const decorated = withFooter(text, { always: true });
288
306
  return {
289
307
  ...result,
@@ -292,6 +310,7 @@ export default function (pi: ExtensionAPI) {
292
310
  };
293
311
  } catch (error) {
294
312
  if (error instanceof Error) {
313
+ if (isRaw) throw error;
295
314
  const decorated = withFooter(error.message, { always: true });
296
315
  throw new Error(decorated.text);
297
316
  }
@@ -306,11 +325,13 @@ export default function (pi: ExtensionAPI) {
306
325
  name: "read",
307
326
  label: "Read",
308
327
  description:
309
- "Read file contents through lean-ctx with automatic mode selection (full/map/signatures) based on file type and size.",
310
- promptSnippet: "Read files through lean-ctx compression with smart mode selection.",
328
+ "Read file contents. ALWAYS use this instead of cat/head/tail via bash. "
329
+ + "Auto-selects mode: configs (.yaml/.json/.toml/.env) are always full-read. "
330
+ + "Code files: full (<8KB), map (8-96KB), signatures (>96KB). "
331
+ + "Use offset and limit to read specific line ranges.",
332
+ promptSnippet: "Read file contents (always use instead of cat)",
311
333
  promptGuidelines: [
312
- "Use read normally lean-ctx automatically selects the optimal compression mode.",
313
- "Small files get full reads, large code files get map/signatures mode.",
334
+ "Use read to inspect file contents instead of cat or less.",
314
335
  ],
315
336
  parameters: readSchema,
316
337
  renderCall(args, theme, context) {
@@ -410,9 +431,8 @@ export default function (pi: ExtensionAPI) {
410
431
  pi.registerTool({
411
432
  name: "ls",
412
433
  label: "ls",
413
- description: "List directory contents through lean-ctx compression.",
414
- promptSnippet: "List directory contents with token-optimized output.",
415
- promptGuidelines: ["Use ls normally — output is automatically compressed by lean-ctx."],
434
+ description: "List directory contents. Use limit to reduce output size.",
435
+ promptSnippet: "List directory contents",
416
436
  parameters: lsSchema,
417
437
  async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
418
438
  const requestedPath = normalizePathArg(params.path || ".");
@@ -429,9 +449,8 @@ export default function (pi: ExtensionAPI) {
429
449
  pi.registerTool({
430
450
  name: "find",
431
451
  label: "find",
432
- description: "Find files by glob pattern through lean-ctx compression.",
433
- promptSnippet: "Find files with compressed output.",
434
- promptGuidelines: ["Use find normally — output respects .gitignore and is compressed by lean-ctx."],
452
+ description: "Find files by glob pattern (respects .gitignore). Use limit to reduce output size.",
453
+ promptSnippet: "Find files by glob pattern",
435
454
  parameters: findSchema,
436
455
  async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
437
456
  const requestedPath = normalizePathArg(params.path || ".");
@@ -448,9 +467,8 @@ export default function (pi: ExtensionAPI) {
448
467
  pi.registerTool({
449
468
  name: "grep",
450
469
  label: "grep",
451
- description: "Search file contents through ripgrep + lean-ctx compression.",
452
- promptSnippet: "Search code with compressed, grouped results.",
453
- promptGuidelines: ["Use grep normally — results are compressed and grouped by lean-ctx."],
470
+ description: "Search file contents with ripgrep. Use limit to cap matches and context for surrounding lines.",
471
+ promptSnippet: "Search file contents for patterns",
454
472
  parameters: grepSchema,
455
473
  async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
456
474
  const requestedPath = normalizePathArg(params.path || ".");
package/package.json CHANGED
@@ -1,8 +1,14 @@
1
1
  {
2
2
  "name": "pi-lean-ctx",
3
- "version": "3.4.1",
4
- "description": "Pi Coding Agent extension with first-class MCP support routes bash, read, grep, find, and ls through lean-ctx CLI, and exposes all 46 lean-ctx MCP tools (ctx_session, ctx_knowledge, ctx_semantic_search, ctx_impact, ctx_architecture, ctx_workflow, ctx_gain, etc.) natively in Pi",
5
- "keywords": ["pi-package", "lean-ctx", "token-optimization", "compression", "mcp"],
3
+ "version": "3.4.3",
4
+ "description": "Pi Coding Agent extension with first-class MCP support \u2014 routes bash, read, grep, find, and ls through lean-ctx CLI, and exposes all 46 lean-ctx MCP tools (ctx_session, ctx_knowledge, ctx_semantic_search, ctx_impact, ctx_architecture, ctx_workflow, ctx_gain, etc.) natively in Pi",
5
+ "keywords": [
6
+ "pi-package",
7
+ "lean-ctx",
8
+ "token-optimization",
9
+ "compression",
10
+ "mcp"
11
+ ],
6
12
  "license": "Apache-2.0",
7
13
  "author": "Yves Gugger",
8
14
  "repository": {
@@ -22,7 +28,9 @@
22
28
  "@mariozechner/pi-tui": "*"
23
29
  },
24
30
  "pi": {
25
- "extensions": ["./extensions"]
31
+ "extensions": [
32
+ "./extensions/index.ts"
33
+ ]
26
34
  },
27
35
  "files": [
28
36
  "extensions/",