@mariozechner/pi-coding-agent 0.26.0 → 0.27.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.
Files changed (101) hide show
  1. package/CHANGELOG.md +21 -1
  2. package/dist/cli/file-processor.d.ts.map +1 -1
  3. package/dist/cli/file-processor.js +1 -1
  4. package/dist/cli/file-processor.js.map +1 -1
  5. package/dist/core/agent-session.d.ts +7 -5
  6. package/dist/core/agent-session.d.ts.map +1 -1
  7. package/dist/core/agent-session.js +49 -15
  8. package/dist/core/agent-session.js.map +1 -1
  9. package/dist/core/hooks/index.d.ts +1 -1
  10. package/dist/core/hooks/index.d.ts.map +1 -1
  11. package/dist/core/hooks/index.js.map +1 -1
  12. package/dist/core/hooks/runner.d.ts +3 -3
  13. package/dist/core/hooks/runner.d.ts.map +1 -1
  14. package/dist/core/hooks/runner.js +7 -3
  15. package/dist/core/hooks/runner.js.map +1 -1
  16. package/dist/core/hooks/types.d.ts +30 -24
  17. package/dist/core/hooks/types.d.ts.map +1 -1
  18. package/dist/core/hooks/types.js.map +1 -1
  19. package/dist/core/sdk.d.ts +2 -2
  20. package/dist/core/sdk.d.ts.map +1 -1
  21. package/dist/core/sdk.js +7 -3
  22. package/dist/core/sdk.js.map +1 -1
  23. package/dist/core/system-prompt.d.ts.map +1 -1
  24. package/dist/core/system-prompt.js +1 -1
  25. package/dist/core/system-prompt.js.map +1 -1
  26. package/dist/core/tools/bash.d.ts +6 -1
  27. package/dist/core/tools/bash.d.ts.map +1 -1
  28. package/dist/core/tools/bash.js +149 -144
  29. package/dist/core/tools/bash.js.map +1 -1
  30. package/dist/core/tools/edit.d.ts +7 -1
  31. package/dist/core/tools/edit.d.ts.map +1 -1
  32. package/dist/core/tools/edit.js +105 -102
  33. package/dist/core/tools/edit.js.map +1 -1
  34. package/dist/core/tools/find.d.ts +7 -1
  35. package/dist/core/tools/find.d.ts.map +1 -1
  36. package/dist/core/tools/find.js +128 -124
  37. package/dist/core/tools/find.js.map +1 -1
  38. package/dist/core/tools/grep.d.ts +11 -1
  39. package/dist/core/tools/grep.d.ts.map +1 -1
  40. package/dist/core/tools/grep.js +198 -194
  41. package/dist/core/tools/grep.js.map +1 -1
  42. package/dist/core/tools/index.d.ts +19 -7
  43. package/dist/core/tools/index.d.ts.map +1 -1
  44. package/dist/core/tools/index.js +43 -17
  45. package/dist/core/tools/index.js.map +1 -1
  46. package/dist/core/tools/ls.d.ts +6 -1
  47. package/dist/core/tools/ls.d.ts.map +1 -1
  48. package/dist/core/tools/ls.js +90 -86
  49. package/dist/core/tools/ls.js.map +1 -1
  50. package/dist/core/tools/path-utils.d.ts +6 -1
  51. package/dist/core/tools/path-utils.d.ts.map +1 -1
  52. package/dist/core/tools/path-utils.js +17 -5
  53. package/dist/core/tools/path-utils.js.map +1 -1
  54. package/dist/core/tools/read.d.ts +7 -1
  55. package/dist/core/tools/read.d.ts.map +1 -1
  56. package/dist/core/tools/read.js +118 -115
  57. package/dist/core/tools/read.js.map +1 -1
  58. package/dist/core/tools/write.d.ts +6 -1
  59. package/dist/core/tools/write.d.ts.map +1 -1
  60. package/dist/core/tools/write.js +63 -59
  61. package/dist/core/tools/write.js.map +1 -1
  62. package/dist/index.d.ts +2 -2
  63. package/dist/index.d.ts.map +1 -1
  64. package/dist/index.js +4 -2
  65. package/dist/index.js.map +1 -1
  66. package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -1
  67. package/dist/modes/interactive/components/bash-execution.js +5 -5
  68. package/dist/modes/interactive/components/bash-execution.js.map +1 -1
  69. package/dist/modes/interactive/components/tool-execution.d.ts +8 -3
  70. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  71. package/dist/modes/interactive/components/tool-execution.js +73 -47
  72. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  73. package/dist/modes/interactive/components/visual-truncate.d.ts +24 -0
  74. package/dist/modes/interactive/components/visual-truncate.d.ts.map +1 -0
  75. package/dist/modes/interactive/components/visual-truncate.js +33 -0
  76. package/dist/modes/interactive/components/visual-truncate.js.map +1 -0
  77. package/dist/modes/interactive/interactive-mode.d.ts +1 -0
  78. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  79. package/dist/modes/interactive/interactive-mode.js +26 -9
  80. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  81. package/dist/modes/rpc/rpc-client.d.ts +10 -2
  82. package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
  83. package/dist/modes/rpc/rpc-client.js +7 -2
  84. package/dist/modes/rpc/rpc-client.js.map +1 -1
  85. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  86. package/dist/modes/rpc/rpc-mode.js +5 -5
  87. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  88. package/dist/modes/rpc/rpc-types.d.ts +7 -0
  89. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  90. package/dist/modes/rpc/rpc-types.js.map +1 -1
  91. package/docs/hooks.md +42 -28
  92. package/docs/rpc.md +26 -6
  93. package/docs/sdk.md +47 -2
  94. package/examples/hooks/README.md +19 -3
  95. package/examples/hooks/auto-commit-on-exit.ts +50 -0
  96. package/examples/hooks/confirm-destructive.ts +62 -0
  97. package/examples/hooks/dirty-repo-guard.ts +59 -0
  98. package/examples/hooks/git-checkpoint.ts +6 -5
  99. package/examples/sdk/05-tools.ts +30 -4
  100. package/examples/sdk/12-full-control.ts +12 -4
  101. package/package.json +4 -4
@@ -2,6 +2,10 @@
2
2
  * Tools Configuration
3
3
  *
4
4
  * Use built-in tool sets, individual tools, or add custom tools.
5
+ *
6
+ * IMPORTANT: When using a custom `cwd`, you must use the tool factory functions
7
+ * (createCodingTools, createReadOnlyTools, createReadTool, etc.) to ensure
8
+ * tools resolve paths relative to your cwd, not process.cwd().
5
9
  */
6
10
 
7
11
  import { Type } from "@sinclair/typebox";
@@ -9,28 +13,50 @@ import {
9
13
  createAgentSession,
10
14
  discoverCustomTools,
11
15
  SessionManager,
12
- codingTools, // read, bash, edit, write (default)
13
- readOnlyTools, // read, bash
16
+ codingTools, // read, bash, edit, write - uses process.cwd()
17
+ readOnlyTools, // read, grep, find, ls - uses process.cwd()
18
+ createCodingTools, // Factory: creates tools for specific cwd
19
+ createReadOnlyTools, // Factory: creates tools for specific cwd
20
+ createReadTool,
21
+ createBashTool,
22
+ createGrepTool,
14
23
  readTool,
15
24
  bashTool,
16
25
  grepTool,
17
26
  type CustomAgentTool,
18
27
  } from "../../src/index.js";
19
28
 
20
- // Read-only mode (no edit/write)
29
+ // Read-only mode (no edit/write) - uses process.cwd()
21
30
  const { session: readOnly } = await createAgentSession({
22
31
  tools: readOnlyTools,
23
32
  sessionManager: SessionManager.inMemory(),
24
33
  });
25
34
  console.log("Read-only session created");
26
35
 
27
- // Custom tool selection
36
+ // Custom tool selection - uses process.cwd()
28
37
  const { session: custom } = await createAgentSession({
29
38
  tools: [readTool, bashTool, grepTool],
30
39
  sessionManager: SessionManager.inMemory(),
31
40
  });
32
41
  console.log("Custom tools session created");
33
42
 
43
+ // With custom cwd - MUST use factory functions!
44
+ const customCwd = "/path/to/project";
45
+ const { session: customCwdSession } = await createAgentSession({
46
+ cwd: customCwd,
47
+ tools: createCodingTools(customCwd), // Tools resolve paths relative to customCwd
48
+ sessionManager: SessionManager.inMemory(),
49
+ });
50
+ console.log("Custom cwd session created");
51
+
52
+ // Or pick specific tools for custom cwd
53
+ const { session: specificTools } = await createAgentSession({
54
+ cwd: customCwd,
55
+ tools: [createReadTool(customCwd), createBashTool(customCwd), createGrepTool(customCwd)],
56
+ sessionManager: SessionManager.inMemory(),
57
+ });
58
+ console.log("Specific tools with custom cwd session created");
59
+
34
60
  // Inline custom tool (needs TypeBox schema)
35
61
  const weatherTool: CustomAgentTool = {
36
62
  name: "get_weather",
@@ -3,6 +3,10 @@
3
3
  *
4
4
  * Replace everything - no discovery, explicit configuration.
5
5
  * Still uses OAuth from ~/.pi/agent for convenience.
6
+ *
7
+ * IMPORTANT: When providing `tools` with a custom `cwd`, use the tool factory
8
+ * functions (createReadTool, createBashTool, etc.) to ensure tools resolve
9
+ * paths relative to your cwd.
6
10
  */
7
11
 
8
12
  import { Type } from "@sinclair/typebox";
@@ -13,8 +17,8 @@ import {
13
17
  findModel,
14
18
  SessionManager,
15
19
  SettingsManager,
16
- readTool,
17
- bashTool,
20
+ createReadTool,
21
+ createBashTool,
18
22
  type HookFactory,
19
23
  type CustomAgentTool,
20
24
  } from "../../src/index.js";
@@ -60,8 +64,11 @@ const settingsManager = SettingsManager.inMemory({
60
64
  retry: { enabled: true, maxRetries: 2 },
61
65
  });
62
66
 
67
+ // When using a custom cwd with explicit tools, use the factory functions
68
+ const cwd = process.cwd();
69
+
63
70
  const { session } = await createAgentSession({
64
- cwd: process.cwd(),
71
+ cwd,
65
72
  agentDir: "/tmp/my-agent",
66
73
 
67
74
  model,
@@ -71,7 +78,8 @@ const { session } = await createAgentSession({
71
78
  systemPrompt: `You are a minimal assistant.
72
79
  Available: read, bash, status. Be concise.`,
73
80
 
74
- tools: [readTool, bashTool],
81
+ // Use factory functions with the same cwd to ensure path resolution works correctly
82
+ tools: [createReadTool(cwd), createBashTool(cwd)],
75
83
  customTools: [{ tool: statusTool }],
76
84
  hooks: [{ factory: auditHook }],
77
85
  skills: [],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mariozechner/pi-coding-agent",
3
- "version": "0.26.0",
3
+ "version": "0.27.0",
4
4
  "description": "Coding agent CLI with read, bash, edit, write tools and session management",
5
5
  "type": "module",
6
6
  "piConfig": {
@@ -39,9 +39,9 @@
39
39
  "prepublishOnly": "npm run clean && npm run build"
40
40
  },
41
41
  "dependencies": {
42
- "@mariozechner/pi-agent-core": "^0.26.0",
43
- "@mariozechner/pi-ai": "^0.26.0",
44
- "@mariozechner/pi-tui": "^0.26.0",
42
+ "@mariozechner/pi-agent-core": "^0.27.0",
43
+ "@mariozechner/pi-ai": "^0.27.0",
44
+ "@mariozechner/pi-tui": "^0.27.0",
45
45
  "chalk": "^5.5.0",
46
46
  "cli-highlight": "^2.1.11",
47
47
  "diff": "^8.0.2",