Skip to content

Add custom tool override capability for domain-specific operations#33

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/add-tool-override-capability
Draft

Add custom tool override capability for domain-specific operations#33
Copilot wants to merge 2 commits intomainfrom
copilot/add-tool-override-capability

Conversation

Copy link
Contributor

Copilot AI commented Mar 4, 2026

Leverages the Copilot SDK's SessionHooks API (onPreToolUse/onPostToolUse) to enforce workspace safety, reduce redundant I/O, and expose per-task tool usage stats during execution.

New: src/services/tool-overrides.ts

  • ToolOverrideConfig — loaded from / saved to .planeteer/config.json; master enabled switch plus per-tool toggles
  • createSessionHooks(config, onToolUse?) — builds SessionHooks with:
    • edit_file / str_replace_editor: denies writes to paths outside process.cwd()
    • read_file: serves in-memory cache on repeated reads (denies the tool call, injects cached content into the denial reason); warns agent when file exceeds configurable size limit (default 100 KB)
    • grep: injects deduplicated exclude_dirs (node_modules, .git, dist, etc.) into modified args and provides --exclude-dir hint as additional context
  • ToolUsageStats (reads, edits, greps) + createEmptyStats()

src/services/copilot.ts

  • Loads ToolOverrideConfig and attaches hooks on every createSession() call
  • Adds onToolUse?: (toolName: string) => void to StreamCallbacks and sendPromptSync options

src/services/executor.ts

  • onToolUse?: (taskId, toolName) => void added to ExecutionCallbacks, threaded through init and regular task execution

src/screens/execute.tsx

  • Tracks Record<string, ToolUsageStats> per task; renders inline 📖/✏️/🔍 counters next to each task row

Configuration example (.planeteer/config.json)

{
  "enabled": true,
  "editFile": { "enabled": true },
  "readFile": { "enabled": true, "maxSizeKb": 100 },
  "grep": {
    "enabled": true,
    "excludePatterns": ["node_modules", ".git", "dist", ".planeteer"]
  }
}

Tests

14 new tests in src/services/copilot.test.ts covering path validation (allow/deny/disabled), grep deduplication, cache serving, onToolUse callback, and config loading.

Original prompt

This section details on the original issue you should resolve

<issue_title>[enhancement] Add custom tool override capability for domain-specific operations</issue_title>
<issue_description>## Background

The Copilot SDK v0.1.30 (released March 3, 2026) adds support for overriding built-in tools like grep, edit_file, or read_file, implemented by Steve Sanderson in commit f843c80.

This feature allows applications to customize how Copilot agents interact with files and code, enabling domain-specific optimizations and constraints.

Proposal

Leverage tool overriding to implement Planeteer-specific file operation constraints and workspace scoping:

  1. Override edit_file tool to:

    • Enforce that agents only edit files within the current working directory
    • Prevent accidental modification of system files or directories outside the project
    • Add pre/post-edit validation hooks (e.g., syntax checking, formatting)
    • Log all file modifications for audit trail in the Execute screen
  2. Override read_file tool to:

    • Implement intelligent file size limits (warn/truncate for files >100KB)
    • Cache frequently-read files to reduce redundant operations
    • Track which files each task has accessed for dependency inference
  3. Override grep tool to:

    • Scope searches to project-relevant directories (exclude node_modules, .git, etc.)
    • Add search result caching for repeated queries
    • Provide more context lines by default for better agent understanding
  4. Configuration in Settings - Add .planeteer/config.json to allow users to enable/disable overrides or customize behavior

Benefit

  • Safety: Prevent agents from accidentally modifying files outside the project workspace
  • Performance: Caching and scoping reduce redundant operations and improve execution speed
  • Observability: Better logging and tracking of tool usage during execution
  • Customization: Users can tailor tool behavior to their project requirements

Acceptance Criteria

  • src/services/copilot.ts registers custom tool overrides with overridesBuiltInTool: true flag
  • edit_file override validates paths are within process.cwd() before executing
  • read_file override implements size limits and caching logic
  • grep override excludes common ignore patterns (node_modules, .git, etc.)
  • Settings file .planeteer/config.json allows enabling/disabling overrides
  • Execute screen displays tool usage statistics (reads, edits, greps per task)
  • Tests in src/services/copilot.test.ts verify override behavior
  • Documentation in README explains tool overrides and configuration options

AI generated by Weekly Enhancement Suggestions

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: colindembovsky <1932561+colindembovsky@users.noreply.github.com>
Copilot AI changed the title [WIP] Enhance SDK with custom tool override capability Add custom tool override capability for domain-specific operations Mar 4, 2026
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.

[enhancement] Add custom tool override capability for domain-specific operations

2 participants