agentleFS
MicrosoftKnown publishermicrosoft/ContextShare/.github/copilot-instructions.md

ContextShare

Copilot instructions7 starsChanged 15 months agoMITView on GitHub

This VS Code extension manages AI assistant catalog resources (chat modes, instructions, prompts, tasks, MCP servers) across multiple repositories. It provides centralized discovery, activation, and "Hats" (preset) functionality for AI resources that enhance GitHub Copilot workflows.

The file

Show its rules and text

We split this copilot-instructions.md into the rules it gives an agent

16 rules. About 0 are common, 5 are distinctive, and 11 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈5

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 11

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    MCP Exception: Always targets {workspace}/.vscode/mcp.json (not under runtime dir)

    line 27
  2. Very specific:

    Root Override Priority: When rootCatalogOverride is set, it takes precedence over per-category overrides

    line 32
  3. Very specific:

    MockFileService: Use canonical version from test/fileService.mock.ts (avoid inline duplicates)

    line 38
  4. Distinctive:

    Path Assertions: Use cross-platform path comparison patterns consistently

    line 40
  5. Very specific:

    Run Order: Always npm run build && npm test before packaging

    line 41
  6. Very specific:

    JSON Comments: Use stripJsonComments() for commented JSON configs

    line 48
  7. Very specific:

    Target Path: Always .vscode/mcp.json, never under runtime directory

    line 49
  8. Very specific:

    Target Workspace Override: When copilotCatalog.targetWorkspace is set, use that absolute path

    line 53
  9. Very specific:

    Task Integration: Use VS Code tasks for build automation (npm run build, npm test)

    line 70
  10. Very specific:

    Command Pattern: All commands registered in extension.ts activation with consistent error handling

    line 83
  11. Distinctive:

    Scope Confinement: All file operations within designated runtime/target directories

    line 95
  12. Distinctive:

    User Asset Protection: Never delete user-created resources during deactivation

    line 96
  13. Very specific:

    Filename Conventions: Verify .chatmode.md, .instructions.md (preferred), .prompt.md, .task.json, .mcp.json

    line 103
  14. Distinctive:

    Path Resolution: Use VS Code output channel for resource discovery logging

    line 104
  15. Distinctive:

    JSON Syntax: Ensure MCP configs are valid JSON (comments stripped automatically)

    line 107
  16. Very specific:

    Sidecar Metadata: Check .copilot-catalog-mcp-meta.json for tracking issues

    line 108

≈ “Common” is an estimate: at least 1 in 5 of the 1,644 Copilot instructions files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
copilot-instructions.md
<!-- Copyright (c) Microsoft Corporation. Licensed under the MIT License. -->

GitHub Copilot Instructions for ContextShare

Project Overview

This VS Code extension manages AI assistant catalog resources (chat modes, instructions, prompts, tasks, MCP servers) across multiple repositories. It provides centralized discovery, activation, and "Hats" (preset) functionality for AI resources that enhance GitHub Copilot workflows.

Core Architecture

Service Layer Pattern

  • ResourceService (src/services/resourceService.ts): Resource discovery, activation/deactivation, state management, remote fetching with TTL caching
  • HatService (src/services/hatService.ts): Preset management across catalog/workspace/user storage locations
  • FileService (src/services/fileService.ts): Abstracted file system operations with mock support for testing

Data Flow

Catalogs (local/remote) → ResourceService.discoverResources() → Tree Providers → VS Code UI
User Actions → Commands → Service Methods → File Operations → State Updates → UI Refresh

Resource States & Origins

  • States: INACTIVE (discovered), ACTIVE (copied to runtime), MODIFIED (edited after activation)
  • Origins: catalog (from catalog dirs), user (runtime-only), remote (fetched from URLs)
  • Runtime Locations:
    • Most resources: {workspace}/.github/{category}/
    • MCP Exception: Always targets {workspace}/.vscode/mcp.json (not under runtime dir)

Key Development Patterns

Resource Discovery Algorithm

  1. Root Override Priority: When rootCatalogOverride is set, it takes precedence over per-category overrides
  2. Filename-Based Classification: Uses inferCategoryFromFilename() for recursive discovery (.chatmode.md, .instructions.md, etc.; legacy .instruction.md also supported)
  3. Remote Sources: Support HTTPS-only URLs with index.json manifest for directories
  4. User Asset Detection: Compare runtime vs catalog locations to identify user-created resources

Testing Framework (TDD Required)

  • MockFileService: Use canonical version from test/fileService.mock.ts (avoid inline duplicates)
  • Test Utilities: createTestPaths() in testUtils.ts for consistent path structures
  • Path Assertions: Use cross-platform path comparison patterns consistently
  • Run Order: Always npm run build && npm test before packaging

MCP Integration (Special Case)

Model Context Protocol servers require unique merge semantics:

  • Merge Strategy: Combines multiple catalog MCP configs into single target file
  • Conflict Resolution: Deduplicates identical server configs, renames conflicts with -catalog suffix
  • Sidecar Metadata: Tracks added server names in .copilot-catalog-mcp-meta.json for cleanup
  • JSON Comments: Use stripJsonComments() for commented JSON configs
  • Target Path: Always .vscode/mcp.json, never under runtime directory

Target Path Resolution Logic

The extension supports multiple workspace targeting modes:

  1. Target Workspace Override: When copilotCatalog.targetWorkspace is set, use that absolute path
  2. Current Workspace Root: Falls back to detected current workspace
  3. Repository Root: Final fallback to catalog repository root

Build & Package Workflow

Development Commands

npm run build          # TypeScript compilation to dist/
npm run watch          # Watch mode for development  
npm test              # Run all test suites

Cross-Platform VSIX Building

  • Primary: ./build_vsix.ps1 (PowerShell Core) with version bump support
  • Fallback: ./build_vsix.sh (Bash) for non-PowerShell environments
  • Version Management: Syncs package.json version ↔ vsix/extension.vsixmanifest
  • Task Integration: Use VS Code tasks for build automation (npm run build, npm test)

Configuration Discovery Modes

  1. Structured Mode: Explicit per-category paths (copilotCatalog.source.chatmodes, etc.)
  2. Root Override Mode: Single rootCatalogOverride path with recursive filename classification
  3. Auto-Discovery: Fallback to copilot_catalog/ folders in workspace

VS Code Integration Points

Tree Providers & UI

  • CategoryTreeProvider: Category-specific views with resource filtering by catalog name
  • State Icons: Different icons for INACTIVE/ACTIVE/MODIFIED states via computeIconId()
  • Context Menus: Activate/deactivate actions, diff viewing, user resource enable/disable
  • Command Pattern: All commands registered in extension.ts activation with consistent error handling

Configuration Schema Pattern

Settings in package.json use:

  • patternProperties for flexible catalog path mappings
  • order properties for settings UI organization
  • Dynamic validation for remote URL schemes (HTTPS-only)

Security & Privacy Considerations

  • Remote Safety: HTTPS-only remote sources, path traversal protection via isSafeRelativeEntry()
  • Filename Sanitization: sanitizeFilename() for all remote content
  • Scope Confinement: All file operations within designated runtime/target directories
  • User Asset Protection: Never delete user-created resources during deactivation
  • Cache Strategy: Local-only TTL caching, no external telemetry

Common Debugging Scenarios

Resource Discovery Issues

  1. Check Override Priority: Root catalog override trumps per-category settings
  2. Filename Conventions: Verify .chatmode.md, .instructions.md (preferred), .prompt.md, .task.json, .mcp.json
  3. Path Resolution: Use VS Code output channel for resource discovery logging

MCP Merge Failures

  1. JSON Syntax: Ensure MCP configs are valid JSON (comments stripped automatically)
  2. Sidecar Metadata: Check .copilot-catalog-mcp-meta.json for tracking issues
  3. Target Path: MCP always targets .vscode/mcp.json, not runtime directory

State Sync Problems

  • State determined by content comparison between catalog and runtime files
  • MODIFIED state indicates runtime file exists but differs from catalog source
  • User resources cannot be deactivated (protection mechanism)

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.