pi-lean-ctx 3.4.2 → 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 -27
  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.",
278
- promptSnippet: "Run shell commands (compressed output)",
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 for any shell command—output (auto-compressed)",
281
- "Avoid for interactive prompts; lean-ctx buffers output.",
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: "Smart file read",
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
- "Auto-selects mode: full (<8KB), map (8-96KB), signatures (>96KB) for code.",
313
- "Text/configs always full-read; images passthrough.",
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,12 +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: "Directory listing (Compressed)",
415
- promptGuidelines: [
416
- "ls → compressed output (respects .gitignore).",
417
- "Use limit param to truncate long lists.",
418
- ],
434
+ description: "List directory contents. Use limit to reduce output size.",
435
+ promptSnippet: "List directory contents",
419
436
  parameters: lsSchema,
420
437
  async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
421
438
  const requestedPath = normalizePathArg(params.path || ".");
@@ -432,12 +449,8 @@ export default function (pi: ExtensionAPI) {
432
449
  pi.registerTool({
433
450
  name: "find",
434
451
  label: "find",
435
- description: "Find files by glob pattern through lean-ctx compression.",
436
- promptSnippet: "File search (Compressed)",
437
- promptGuidelines: [
438
- "find [pattern] → lean-ctx compressed results.",
439
- "Combines with .gitignore; use limit to cap results.",
440
- ],
452
+ description: "Find files by glob pattern (respects .gitignore). Use limit to reduce output size.",
453
+ promptSnippet: "Find files by glob pattern",
441
454
  parameters: findSchema,
442
455
  async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
443
456
  const requestedPath = normalizePathArg(params.path || ".");
@@ -454,12 +467,8 @@ export default function (pi: ExtensionAPI) {
454
467
  pi.registerTool({
455
468
  name: "grep",
456
469
  label: "grep",
457
- description: "Search file contents through ripgrep + lean-ctx compression.",
458
- promptSnippet: "Compressed code search (grouped results)",
459
- promptGuidelines: [
460
- "rg → lean-ctx compressed output (line numbers, no color).",
461
- "Supports standard rg flags: -i, -F, -C, -m, --glob.",
462
- ],
470
+ description: "Search file contents with ripgrep. Use limit to cap matches and context for surrounding lines.",
471
+ promptSnippet: "Search file contents for patterns",
463
472
  parameters: grepSchema,
464
473
  async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
465
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.2",
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/",