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
- Very specific: line 27
MCP Exception: Always targets {workspace}/.vscode/mcp.json (not under runtime dir)
- Very specific: line 32
Root Override Priority: When rootCatalogOverride is set, it takes precedence over per-category overrides
- Very specific: line 38
MockFileService: Use canonical version from test/fileService.mock.ts (avoid inline duplicates)
- Distinctive: line 40
Path Assertions: Use cross-platform path comparison patterns consistently
- Very specific: line 41
Run Order: Always npm run build && npm test before packaging
- Very specific: line 48
JSON Comments: Use stripJsonComments() for commented JSON configs
- Very specific: line 49
Target Path: Always .vscode/mcp.json, never under runtime directory
- Very specific: line 53
Target Workspace Override: When copilotCatalog.targetWorkspace is set, use that absolute path
- Very specific: line 70
Task Integration: Use VS Code tasks for build automation (npm run build, npm test)
- Very specific: line 83
Command Pattern: All commands registered in extension.ts activation with consistent error handling
- Distinctive: line 95
Scope Confinement: All file operations within designated runtime/target directories
- Distinctive: line 96
User Asset Protection: Never delete user-created resources during deactivation
- Very specific: line 103
Filename Conventions: Verify .chatmode.md, .instructions.md (preferred), .prompt.md, .task.json, .mcp.json
- Distinctive: line 104
Path Resolution: Use VS Code output channel for resource discovery logging
- Distinctive: line 107
JSON Syntax: Ensure MCP configs are valid JSON (comments stripped automatically)
- Very specific: line 108
Sidecar Metadata: Check .copilot-catalog-mcp-meta.json for tracking issues
≈ “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.
Files
<!-- 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 RefreshResource 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)
- Most resources:
Key Development Patterns
Resource Discovery Algorithm
- Root Override Priority: When
rootCatalogOverrideis set, it takes precedence over per-category overrides - Filename-Based Classification: Uses
inferCategoryFromFilename()for recursive discovery (.chatmode.md,.instructions.md, etc.; legacy.instruction.mdalso supported) - Remote Sources: Support HTTPS-only URLs with
index.jsonmanifest for directories - 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()intestUtils.tsfor consistent path structures - Path Assertions: Use cross-platform path comparison patterns consistently
- Run Order: Always
npm run build && npm testbefore 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
-catalogsuffix - Sidecar Metadata: Tracks added server names in
.copilot-catalog-mcp-meta.jsonfor 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:
- Target Workspace Override: When
copilotCatalog.targetWorkspaceis set, use that absolute path - Current Workspace Root: Falls back to detected current workspace
- 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 suitesCross-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.jsonversion ↔vsix/extension.vsixmanifest - Task Integration: Use VS Code tasks for build automation (
npm run build,npm test)
Configuration Discovery Modes
- Structured Mode: Explicit per-category paths (
copilotCatalog.source.chatmodes, etc.) - Root Override Mode: Single
rootCatalogOverridepath with recursive filename classification - 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.tsactivation with consistent error handling
Configuration Schema Pattern
Settings in package.json use:
patternPropertiesfor flexible catalog path mappingsorderproperties 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
- Check Override Priority: Root catalog override trumps per-category settings
- Filename Conventions: Verify
.chatmode.md,.instructions.md(preferred),.prompt.md,.task.json,.mcp.json - Path Resolution: Use VS Code output channel for resource discovery logging
MCP Merge Failures
- JSON Syntax: Ensure MCP configs are valid JSON (comments stripped automatically)
- Sidecar Metadata: Check
.copilot-catalog-mcp-meta.jsonfor tracking issues - 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)
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
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.

