Skip to content

feat: folder context IPC + filetools built-in AI tools#83

Merged
andrewchumchal merged 7 commits into
devfrom
feat/folder-context
May 22, 2026
Merged

feat: folder context IPC + filetools built-in AI tools#83
andrewchumchal merged 7 commits into
devfrom
feat/folder-context

Conversation

@andrewchumchal

Copy link
Copy Markdown
Contributor

Summary

Electron-side implementation for folder context + built-in AI file tools.

Depends on: OpenConduit/core#72

Changes

src/main/ipc.ts

  • folder:pick — opens native folder picker dialog
  • folder: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_SEND handler: prepends folder file contents as <file path="..."> blocks to the last user message when folderContext is present; injects FILE_TOOL_DEFS into the tools array when folderContext.rootPath is set; routes FILE_SERVER_ID tool calls to callFileTool

src/main/filetools/index.ts (new)

  • FILE_SERVER_ID = '__filetools__' — analogous to BUILTIN_SERVER_ID for web tools
  • Tool schemas (McpTool[]) for file_read, file_write, file_delete, file_list
  • callFileTool(tc, rootPath) — sandboxed to the user-picked folder via path traversal guard; returns McpToolResult

src/preload.ts + src/renderer/env.d.ts

  • Expose window.api.folder.{pick, readFiles, writeFile, deleteEntry} via context bridge

Security

All file operations validate that the resolved target path starts with the user-chosen rootPath prefix. Access outside the folder is rejected with an Access denied error.

andrewchumchal and others added 7 commits May 22, 2026 15:35
- 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
@andrewchumchal andrewchumchal merged commit 27e5863 into dev May 22, 2026
3 checks passed
@andrewchumchal andrewchumchal deleted the feat/folder-context branch May 22, 2026 22:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant