@oh-my-pi/pi-coding-agent 3.20.1 → 3.24.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 (123) hide show
  1. package/CHANGELOG.md +107 -8
  2. package/docs/custom-tools.md +3 -3
  3. package/docs/extensions.md +226 -220
  4. package/docs/hooks.md +2 -2
  5. package/docs/sdk.md +50 -53
  6. package/examples/custom-tools/README.md +2 -17
  7. package/examples/extensions/README.md +76 -74
  8. package/examples/extensions/todo.ts +2 -5
  9. package/examples/hooks/custom-compaction.ts +2 -4
  10. package/examples/hooks/handoff.ts +1 -1
  11. package/examples/hooks/qna.ts +1 -1
  12. package/examples/sdk/02-custom-model.ts +1 -1
  13. package/examples/sdk/README.md +7 -11
  14. package/package.json +6 -6
  15. package/src/cli/args.ts +9 -6
  16. package/src/cli/file-processor.ts +1 -1
  17. package/src/cli/list-models.ts +1 -1
  18. package/src/core/agent-session.ts +16 -5
  19. package/src/core/auth-storage.ts +1 -1
  20. package/src/core/compaction/branch-summarization.ts +2 -2
  21. package/src/core/compaction/compaction.ts +2 -2
  22. package/src/core/compaction/utils.ts +1 -1
  23. package/src/core/custom-tools/types.ts +1 -1
  24. package/src/core/custom-tools/wrapper.ts +0 -1
  25. package/src/core/extensions/index.ts +1 -6
  26. package/src/core/extensions/runner.ts +1 -1
  27. package/src/core/extensions/types.ts +1 -1
  28. package/src/core/extensions/wrapper.ts +1 -8
  29. package/src/core/file-mentions.ts +5 -8
  30. package/src/core/hooks/runner.ts +2 -2
  31. package/src/core/hooks/types.ts +1 -1
  32. package/src/core/messages.ts +1 -1
  33. package/src/core/model-registry.ts +1 -1
  34. package/src/core/model-resolver.ts +1 -1
  35. package/src/core/sdk.ts +64 -105
  36. package/src/core/session-manager.ts +18 -22
  37. package/src/core/settings-manager.ts +66 -1
  38. package/src/core/slash-commands.ts +12 -5
  39. package/src/core/system-prompt.ts +49 -36
  40. package/src/core/title-generator.ts +2 -2
  41. package/src/core/tools/ask.ts +98 -4
  42. package/src/core/tools/bash-interceptor.ts +11 -4
  43. package/src/core/tools/bash.ts +121 -5
  44. package/src/core/tools/context.ts +7 -0
  45. package/src/core/tools/edit-diff.ts +73 -24
  46. package/src/core/tools/edit.ts +221 -34
  47. package/src/core/tools/exa/render.ts +4 -16
  48. package/src/core/tools/find.ts +149 -5
  49. package/src/core/tools/gemini-image.ts +279 -56
  50. package/src/core/tools/git.ts +17 -3
  51. package/src/core/tools/grep.ts +185 -5
  52. package/src/core/tools/index.test.ts +180 -0
  53. package/src/core/tools/index.ts +96 -242
  54. package/src/core/tools/ls.ts +133 -5
  55. package/src/core/tools/lsp/index.ts +32 -29
  56. package/src/core/tools/lsp/render.ts +21 -22
  57. package/src/core/tools/notebook.ts +112 -4
  58. package/src/core/tools/output.ts +175 -15
  59. package/src/core/tools/read.ts +127 -25
  60. package/src/core/tools/render-utils.ts +241 -0
  61. package/src/core/tools/renderers.ts +40 -828
  62. package/src/core/tools/review.ts +26 -25
  63. package/src/core/tools/rulebook.ts +11 -3
  64. package/src/core/tools/task/agents.ts +28 -7
  65. package/src/core/tools/task/discovery.ts +0 -6
  66. package/src/core/tools/task/executor.ts +264 -254
  67. package/src/core/tools/task/index.ts +48 -208
  68. package/src/core/tools/task/render.ts +26 -11
  69. package/src/core/tools/task/types.ts +7 -12
  70. package/src/core/tools/task/worker-protocol.ts +17 -0
  71. package/src/core/tools/task/worker.ts +238 -0
  72. package/src/core/tools/truncate.ts +27 -1
  73. package/src/core/tools/web-fetch.ts +25 -49
  74. package/src/core/tools/web-search/index.ts +132 -46
  75. package/src/core/tools/web-search/providers/anthropic.ts +7 -2
  76. package/src/core/tools/web-search/providers/exa.ts +2 -1
  77. package/src/core/tools/web-search/providers/perplexity.ts +6 -1
  78. package/src/core/tools/web-search/render.ts +6 -4
  79. package/src/core/tools/web-search/types.ts +13 -0
  80. package/src/core/tools/write.ts +96 -14
  81. package/src/core/voice.ts +1 -1
  82. package/src/discovery/helpers.test.ts +1 -1
  83. package/src/index.ts +5 -16
  84. package/src/main.ts +5 -5
  85. package/src/modes/interactive/components/assistant-message.ts +1 -1
  86. package/src/modes/interactive/components/custom-message.ts +1 -1
  87. package/src/modes/interactive/components/extensions/inspector-panel.ts +25 -22
  88. package/src/modes/interactive/components/extensions/state-manager.ts +12 -0
  89. package/src/modes/interactive/components/footer.ts +1 -1
  90. package/src/modes/interactive/components/hook-message.ts +1 -1
  91. package/src/modes/interactive/components/model-selector.ts +1 -1
  92. package/src/modes/interactive/components/oauth-selector.ts +1 -1
  93. package/src/modes/interactive/components/settings-defs.ts +49 -0
  94. package/src/modes/interactive/components/status-line.ts +1 -1
  95. package/src/modes/interactive/components/tool-execution.ts +93 -538
  96. package/src/modes/interactive/interactive-mode.ts +19 -7
  97. package/src/modes/interactive/theme/theme.ts +4 -4
  98. package/src/modes/print-mode.ts +1 -1
  99. package/src/modes/rpc/rpc-client.ts +1 -1
  100. package/src/modes/rpc/rpc-types.ts +1 -1
  101. package/src/prompts/system-prompt.md +4 -0
  102. package/src/prompts/task.md +0 -7
  103. package/src/prompts/tools/gemini-image.md +5 -1
  104. package/src/prompts/tools/output.md +6 -2
  105. package/src/prompts/tools/task.md +68 -0
  106. package/src/prompts/tools/web-fetch.md +1 -0
  107. package/src/prompts/tools/web-search.md +2 -0
  108. package/src/utils/image-convert.ts +8 -2
  109. package/src/utils/image-magick.ts +247 -0
  110. package/src/utils/image-resize.ts +53 -13
  111. package/examples/custom-tools/question/index.ts +0 -84
  112. package/examples/custom-tools/subagent/README.md +0 -172
  113. package/examples/custom-tools/subagent/agents/planner.md +0 -37
  114. package/examples/custom-tools/subagent/agents/scout.md +0 -50
  115. package/examples/custom-tools/subagent/agents/worker.md +0 -24
  116. package/examples/custom-tools/subagent/agents.ts +0 -156
  117. package/examples/custom-tools/subagent/commands/implement-and-review.md +0 -10
  118. package/examples/custom-tools/subagent/commands/implement.md +0 -10
  119. package/examples/custom-tools/subagent/commands/scout-and-plan.md +0 -9
  120. package/examples/custom-tools/subagent/index.ts +0 -1002
  121. package/examples/sdk/05-tools.ts +0 -94
  122. package/examples/sdk/12-full-control.ts +0 -95
  123. package/src/prompts/browser.md +0 -71
@@ -1,94 +0,0 @@
1
- /**
2
- * Tools Configuration
3
- *
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().
9
- */
10
-
11
- import {
12
- bashTool, // read, bash, edit, write - uses process.cwd()
13
- type CustomTool,
14
- createAgentSession,
15
- createBashTool,
16
- createCodingTools, // Factory: creates tools for specific cwd
17
- createGrepTool,
18
- createReadTool,
19
- grepTool,
20
- readOnlyTools, // read, grep, find, ls - uses process.cwd()
21
- readTool,
22
- SessionManager,
23
- } from "@oh-my-pi/pi-coding-agent";
24
- import { Type } from "@sinclair/typebox";
25
-
26
- // Read-only mode (no edit/write) - uses process.cwd()
27
- await createAgentSession({
28
- tools: readOnlyTools,
29
- sessionManager: SessionManager.inMemory(),
30
- });
31
- console.log("Read-only session created");
32
-
33
- // Custom tool selection - uses process.cwd()
34
- await createAgentSession({
35
- tools: [readTool, bashTool, grepTool],
36
- sessionManager: SessionManager.inMemory(),
37
- });
38
- console.log("Custom tools session created");
39
-
40
- // With custom cwd - MUST use factory functions!
41
- const customCwd = "/path/to/project";
42
- const customTools = await createCodingTools(customCwd);
43
- await createAgentSession({
44
- cwd: customCwd,
45
- tools: customTools, // Tools resolve paths relative to customCwd
46
- sessionManager: SessionManager.inMemory(),
47
- });
48
- console.log("Custom cwd session created");
49
-
50
- // Or pick specific tools for custom cwd
51
- const customReadTool = await createReadTool(customCwd);
52
- const customBashTool = await createBashTool(customCwd);
53
- const customGrepTool = await createGrepTool(customCwd);
54
- await createAgentSession({
55
- cwd: customCwd,
56
- tools: [customReadTool, customBashTool, customGrepTool],
57
- sessionManager: SessionManager.inMemory(),
58
- });
59
- console.log("Specific tools with custom cwd session created");
60
-
61
- // Inline custom tool (needs TypeBox schema)
62
- const weatherTool: CustomTool = {
63
- name: "get_weather",
64
- label: "Get Weather",
65
- description: "Get current weather for a city",
66
- parameters: Type.Object({
67
- city: Type.String({ description: "City name" }),
68
- }),
69
- execute: async (_toolCallId, params) => ({
70
- content: [{ type: "text", text: `Weather in ${(params as { city: string }).city}: 22°C, sunny` }],
71
- details: {},
72
- }),
73
- };
74
-
75
- const { session } = await createAgentSession({
76
- customTools: [weatherTool],
77
- sessionManager: SessionManager.inMemory(),
78
- });
79
-
80
- session.subscribe((event) => {
81
- if (event.type === "message_update" && event.assistantMessageEvent.type === "text_delta") {
82
- process.stdout.write(event.assistantMessageEvent.delta);
83
- }
84
- });
85
-
86
- await session.prompt("What's the weather in Tokyo?");
87
- console.log();
88
-
89
- // Merge with discovered tools from cwd/.omp/tools and ~/.omp/agent/tools:
90
- // const discovered = await discoverCustomTools();
91
- // customTools: [...discovered, { tool: myTool }]
92
-
93
- // Or add paths without replacing discovery:
94
- // additionalCustomToolPaths: ["/extra/tools"]
@@ -1,95 +0,0 @@
1
- /**
2
- * Full Control
3
- *
4
- * Replace everything - no discovery, explicit configuration.
5
- *
6
- * IMPORTANT: When providing `tools` with a custom `cwd`, use the tool factory
7
- * functions (createReadTool, createBashTool, etc.) to ensure tools resolve
8
- * paths relative to your cwd.
9
- */
10
-
11
- import { getModel } from "@oh-my-pi/pi-ai";
12
- import {
13
- AuthStorage,
14
- type CustomTool,
15
- createAgentSession,
16
- createBashTool,
17
- createReadTool,
18
- type ExtensionFactory,
19
- ModelRegistry,
20
- SessionManager,
21
- SettingsManager,
22
- } from "@oh-my-pi/pi-coding-agent";
23
- import { Type } from "@sinclair/typebox";
24
-
25
- // Custom auth storage location
26
- const authStorage = new AuthStorage("/tmp/my-agent/auth.json");
27
-
28
- // Runtime API key override (not persisted)
29
- if (process.env.MY_ANTHROPIC_KEY) {
30
- authStorage.setRuntimeApiKey("anthropic", process.env.MY_ANTHROPIC_KEY);
31
- }
32
-
33
- // Model registry with no custom models.json
34
- const modelRegistry = new ModelRegistry(authStorage);
35
-
36
- // Inline extension
37
- const auditHook: ExtensionFactory = (api) => {
38
- api.on("tool_call", async (event) => {
39
- console.log(`[Audit] ${event.toolName}`);
40
- return undefined;
41
- });
42
- };
43
-
44
- // Inline custom tool
45
- const statusTool: CustomTool = {
46
- name: "status",
47
- label: "Status",
48
- description: "Get system status",
49
- parameters: Type.Object({}),
50
- execute: async () => ({
51
- content: [{ type: "text", text: `Uptime: ${process.uptime()}s, Node: ${process.version}` }],
52
- details: {},
53
- }),
54
- };
55
-
56
- const model = getModel("anthropic", "claude-opus-4-5");
57
- if (!model) throw new Error("Model not found");
58
-
59
- // In-memory settings with overrides
60
- const settingsManager = SettingsManager.inMemory({
61
- compaction: { enabled: false },
62
- retry: { enabled: true, maxRetries: 2 },
63
- });
64
-
65
- // When using a custom cwd with explicit tools, use the factory functions
66
- const cwd = process.cwd();
67
-
68
- const { session } = await createAgentSession({
69
- cwd,
70
- agentDir: "/tmp/my-agent",
71
- model,
72
- thinkingLevel: "off",
73
- authStorage,
74
- modelRegistry,
75
- systemPrompt: `You are a minimal assistant.
76
- Available: read, bash, status. Be concise.`,
77
- // Use factory functions with the same cwd to ensure path resolution works correctly
78
- tools: [createReadTool(cwd), createBashTool(cwd)],
79
- customTools: [statusTool],
80
- extensions: [auditHook],
81
- skills: [],
82
- contextFiles: [],
83
- promptTemplates: [],
84
- sessionManager: SessionManager.inMemory(),
85
- settingsManager,
86
- });
87
-
88
- session.subscribe((event) => {
89
- if (event.type === "message_update" && event.assistantMessageEvent.type === "text_delta") {
90
- process.stdout.write(event.assistantMessageEvent.delta);
91
- }
92
- });
93
-
94
- await session.prompt("Get status and list files.");
95
- console.log();
@@ -1,71 +0,0 @@
1
- ---
2
- name: browser
3
- description: Fetches and renders a single URL into clean, digestible text for extraction
4
- tools: bash
5
- model: claude-haiku-4-5, haiku, flash, mini
6
- ---
7
-
8
- You are a web content extraction specialist. Your job is to fetch a single URL, render it into clean readable text, and extract the specific information requested.
9
-
10
- === CRITICAL: EXTRACTION ONLY ===
11
- This is a SINGLE-URL extraction task. You are STRICTLY PROHIBITED from:
12
-
13
- - Following links to other pages (unless explicitly part of the URL)
14
- - Performing web searches or investigations
15
- - Running commands that install software or change system state
16
-
17
- Your role is EXCLUSIVELY to fetch, render, and extract from ONE URL.
18
-
19
- === HOW TO FETCH ===
20
-
21
- Use the `omp render-web` command to fetch and render the URL:
22
-
23
- ```bash
24
- omp render-web "<URL>"
25
- ```
26
-
27
- This command automatically:
28
-
29
- 1. Checks for LLM-friendly endpoints (llms.txt, llms.md)
30
- 2. Tries content negotiation for markdown/plain text
31
- 3. Looks for page-specific alternate feeds (RSS, Atom)
32
- 4. Falls back to lynx for HTML→text rendering
33
- 5. Pretty-prints JSON/XML if applicable
34
- 6. Reports any issues (JS-gated pages, truncation, etc.)
35
-
36
- Options:
37
-
38
- - `--raw` — Output only the content, no metadata headers
39
- - `--json` — Structured JSON output with metadata
40
- - `--timeout <seconds>` — Request timeout (default: 20)
41
-
42
- === WORKFLOW ===
43
-
44
- 1. Run `omp render-web "<URL>"` to fetch the page
45
- 2. Review the output — check the "Method" and "Notes" fields for any issues
46
- 3. If the page appears JS-gated or incomplete, note this in your response
47
- 4. Extract the specific information requested by the caller
48
- 5. Format your findings clearly
49
-
50
- === OUTPUT FORMAT ===
51
-
52
- Always structure your response as:
53
-
54
- ## URL
55
-
56
- The final URL after redirects.
57
-
58
- ## Metadata
59
-
60
- ```
61
- Content-Type: <type>
62
- Method: <how it was rendered>
63
- ```
64
-
65
- ## Extracted Information
66
-
67
- The specific information requested by the caller, clearly formatted.
68
-
69
- ## Notes
70
-
71
- Any issues encountered (JS-gated, paywall, truncated, etc).