Skip to content

agentHost: run repository hooks only in folders trusted in VS Code - #349330

Merged
Vritant Bhardwaj (vritant24) merged 4 commits into
mainfrom
dev/vritant24/hooks-trust
Nov 20, 2026
Merged

Vritant Bhardwaj (vritant24) merged 4 commits into
mainfrom
dev/vritant24/hooks-trust

Conversation

@vritant24

Copy link
Copy Markdown
Member

Refs #345931

What this changes

In a Copilot session, the Copilot runtime runs a repository's .github/hooks files whenever the host turns on repository hooks, and leaves the trust decision to the host. VS Code turned them on for every folder, so these hooks ran in folders the user had not trusted.

  • Repository hooks are now turned on only when VS Code trusts the session's working folder, and never for virtual workspaces.
  • Chat Customizations lists the hook files of an untrusted folder with a Won't run badge and "Won't run until you trust this folder." It no longer lists repository hooks that the runtime reports only because of its own trusted-folder list.
  • The hook list refreshes when workspace trust changes.

This covers the untrusted-folder half of #345931. Whether hooks run in a trusted folder on Windows has not been checked on Windows.

How to test

  1. Open a folder (a git repository) containing .github/hooks/log.json with a sessionStart hook that appends a line to a file.
  2. In Restricted Mode, open Chat Customizations > Hooks with the Copilot harness: the file appears with a Won't run badge. Start a Copilot session: the hook does not run.
  3. Trust the folder: the badge disappears without reopening the editor. Start a new session: the hook runs.

Validation

  • ./scripts/test.sh --reporter dot --run src/vs/platform/agentHost/test/node/copilotSessionLauncher.test.ts --run src/vs/platform/agentHost/test/node/sessionCustomizationDiscovery.test.ts --run src/vs/platform/agentHost/test/node/copilotAgent.test.ts --run src/vs/workbench/contrib/chat/test/browser/agentSessions/agentCustomizationItemProvider.test.ts --run src/vs/workbench/contrib/chat/test/browser/aiCustomization/customizationMigration.test.ts --run src/vs/workbench/contrib/chat/test/browser/aiCustomization/customizationMigrationServiceImpl.test.ts: passed (1,545 passing, 1 pending)
  • pnpm run typecheck-client: passed
  • oxlint (pre-commit hygiene): passed
  • Checked manually in Code OSS on macOS with a trusted and an untrusted folder.
  • Not run: copilotSdkCustomizationDiscovery.integrationTest.ts (updated; needs the integration runner).

The Copilot runtime loads a repository's `.github/hooks` whenever the host
enables repository hooks, and leaves the trust check to the host. VS Code
enabled them for every folder, so these hooks ran in untrusted folders.

Repository hooks are now enabled only when VS Code trusts the session's
working folder. Chat Customizations lists the hook files of an untrusted
folder as "Won't run until you trust this folder", drops repository hooks the
runtime reports through its own trusted folders, and no longer passes an
untrusted folder to the hook listing workaround. The list updates when
workspace trust changes.

Refs #345931

Co-authored-by: Copilot <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Repository hooks lacking both path fields remain visible as enabled when the primary folder is untrusted, contradicting the session’s disabled-hook behavior.

1 open issue
What changed in this PR

This PR ties Copilot Agent Host repository-hook execution to VS Code workspace trust, addressing the untrusted-folder portion of #345931. The reported trusted-folder issue on Windows remains outside the validated scope.

Changes:

  • Enables repository hooks only for trusted working folders, excluding virtual workspaces.
  • Shows untrusted hook files with a Won't run badge and refreshes discovery when trust changes.
  • Adds trust-gating and badge-propagation tests, and updates integration-test setup.
File Description
src/​vs/​workbench/​contrib/​chat/​test/​browser/​agentSessions/​agentCustomizationItemProvider.test.ts Tests disabled-hook status through file expansion.
src/​vs/​workbench/​contrib/​chat/​browser/​aiCustomization/​aiCustomizationItemSource.ts Preserves badges when expanding hook files.
src/​vs/​workbench/​contrib/​chat/​browser/​agentSessions/​agentHost/​agentCustomizationItemProvider.ts Adds the Won't run status to disabled hooks.
src/​vs/​platform/​agentHost/​test/​node/​sessionCustomizationDiscovery.test.ts Tests untrusted-hook discovery and trust-change notifications.
src/​vs/​platform/​agentHost/​test/​node/​copilotSessionLauncher.test.ts Tests repository-hook gating during create and resume.
src/​vs/​platform/​agentHost/​test/​node/​copilotSdkCustomizationDiscovery.integrationTest.ts Supplies explicit trust configuration for discovery tests.
src/​vs/​platform/​agentHost/​node/​copilot/​sessionCustomizationDiscovery.ts Filters runtime hooks, lists untrusted files, and observes trust changes.
src/​vs/​platform/​agentHost/​node/​copilot/​copilotSessionLauncher.ts Gates repository-hook execution on workspace trust.

Review effort: Balanced

A repository hook the runtime reports with neither a project path nor a
definition file could not be tied to a folder, so it stayed listed as enabled
next to the "Won't run" files of an untrusted folder. Such hooks are now
dropped whenever a queried folder is untrusted.

Co-authored-by: Copilot <[email protected]>
@vritant24
Vritant Bhardwaj (vritant24) marked this pull request as ready for review November 19, 2026 22:03
…gration test

Sessions now list a repository's hook files as not running when the folder is
not trusted. The test's agent host had no workspace trust configuration, so
its workspace hook was listed as untrusted. The suite now turns workspace
trust off, as in VS Code without workspace trust.

Co-authored-by: Copilot <[email protected]>
Repository hooks of an untrusted folder are now listed as not running, and
this suite's agent host had no workspace trust configuration. Its sessions now
trust their workspace before they are created, as VS Code does for a trusted
folder.

Co-authored-by: Copilot <[email protected]>
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.

3 participants