feat: folder context IPC + filetools built-in AI tools#83
Merged
Conversation
- folder:pick — opens native directory picker dialog - folder:read-files — recursively reads text files under a path (capped at 100 files and 2 MB total; binary files skipped) - Preload bridge exposes folder.pick() and folder.readFiles() - env.d.ts: window.api.folder typed - ipc.ts CHAT_SEND: injects folderContext files into the last user message as a fenced code block before forwarding to the provider
- folder:write-file — creates/overwrites a file at relativePath inside folderPath (creates parent dirs as needed) - folder:delete-entry — deletes a file or directory recursively - Both handlers validate the resolved path is strictly inside folderPath to prevent path traversal attacks - Preload and env.d.ts updated with writeFile() and deleteEntry()
When context is truncated, a tool_use block may be dropped while its corresponding tool_result survives. Anthropic rejects this with a 400. Fix: cross-reference tool_result ids against the immediately preceding assistant message's tool_use blocks and drop any that don't match.
- In agent mode (folderContext.rootPath set): inject only a file listing
into the user message instead of all file contents. The AI uses
file_read to fetch files on demand, saving significant tokens each turn.
- In read-only mode (no rootPath): keep existing full-content inlining.
- Compute effectiveSystemPrompt: when rootPath is set, prepend agent
instructions ('You are in agent mode. Project root: /path. Use
file_read/write/delete/list...') before any existing system prompt.
All five provider stream calls use effectiveSystemPrompt.
chore: bump @openconduit/core to 2.0.0-alpha.9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Electron-side implementation for folder context + built-in AI file tools.
Depends on: OpenConduit/core#72
Changes
src/main/ipc.tsfolder:pick— opens native folder picker dialogfolder:read-files— reads all text files in picked folder (respects ignore patterns)folder:write-file— writes a file at a relative path (path traversal protected)folder:delete-entry— deletes a file or directory (path traversal protected)CHAT_SENDhandler: prepends folder file contents as<file path="...">blocks to the last user message whenfolderContextis present; injectsFILE_TOOL_DEFSinto the tools array whenfolderContext.rootPathis set; routesFILE_SERVER_IDtool calls tocallFileToolsrc/main/filetools/index.ts(new)FILE_SERVER_ID = '__filetools__'— analogous toBUILTIN_SERVER_IDfor web toolsMcpTool[]) forfile_read,file_write,file_delete,file_listcallFileTool(tc, rootPath)— sandboxed to the user-picked folder via path traversal guard; returnsMcpToolResultsrc/preload.ts+src/renderer/env.d.tswindow.api.folder.{pick, readFiles, writeFile, deleteEntry}via context bridgeSecurity
All file operations validate that the resolved target path starts with the user-chosen
rootPathprefix. Access outside the folder is rejected with anAccess deniederror.