feat: Copilot governance engine, VS Code extension, recall parser, and Copilot CLI integration#45
Open
bilersan wants to merge 12 commits intoActiveMemory:mainfrom
Open
feat: Copilot governance engine, VS Code extension, recall parser, and Copilot CLI integration#45bilersan wants to merge 12 commits intoActiveMemory:mainfrom
bilersan wants to merge 12 commits intoActiveMemory:mainfrom
Conversation
This was referenced Mar 17, 2026
300d3a6 to
eb95695
Compare
josealekhine
requested changes
Mar 25, 2026
Member
josealekhine
left a comment
There was a problem hiding this comment.
@bilersan if you fix the merge conflicts, I will give it a whirl.
Sorry about the 20K-line refactoring; that's partially the reason for the merge conflicts.
Alternatively you can close the PR and re-patch the changes from top-of-tree.
I'm assuming main will be "relatively" stable for a while as I will have lesser "Batman time" from next week onwards ;).
Thanks for all your help 🙏 .
- Case-insensitive path comparison on Windows for boundary validation - Extract osWindows constant for goconst compliance Closes ActiveMemory#30 Supersedes ActiveMemory#31 Signed-off-by: ersan bilik <ersanbilik@gmail.com>
- CopilotParser implementing SessionParser interface with Matches() and ParseFile() - Platform-aware directory discovery for Code and Code Insiders - Typed Go structs for Copilot Chat JSONL format (snapshot+patch model) - Registration in parser.go and query scanning in query.go - ToolCopilot constant in config/session Closes ActiveMemory#28 Supersedes ActiveMemory#29 Signed-off-by: ersan bilik <ersanbilik@gmail.com>
- VS Code extension with @ctx chat participant and slash commands - .vscode/mcp.json generation in init and hook paths - VS Code-specific context overrides (CONSTITUTION, CONVENTIONS, etc.) - Session event CLI command for VS Code lifecycle integration - Detection ring: terminal watcher for dangerous commands - Detection ring: file edit watcher for sensitive file patterns - Violation recording to .context/state/violations.json - Extension tests and init/hook integration tests Supersedes ActiveMemory#36 Signed-off-by: ersan bilik <ersanbilik@gmail.com>
- Governance checker (CheckGovernance) appends contextual warnings to every MCP tool response: session-not-started, context-not-loaded, drift-stale, persist-nudge, and violation escalation - Per-tool state recording: RecordSessionStart, RecordContextLoaded, RecordDriftCheck, RecordContextWrite, IncrementCallsSinceWrite - Violation reading from .context/state/violations.json with automatic cleanup after escalation (read-and-clear pattern) - Governance wired into route/tool dispatch with appendGovernance - RecordSessionStart called on session event handler - copilot-instructions.md template with governance rules and detection ring documentation - 24 governance tests covering all check paths and edge cases Signed-off-by: ersan bilik <ersanbilik@gmail.com>
- Set activationEvents to onStartupFinished for reliable activation - Add /diag slash command for extension diagnostics - Add OutputChannel logging for activation tracing - Pass --force --caller vscode to init to prevent stdin hang - Skip stdin overwrite prompt when caller is set (run.go) - Add test-insiders-sim.js to .vscodeignore Root cause: VS Code Insiders 1.112 uses extensions.experimental.affinity to run GitHub.copilot-chat in a separate extension host process. Chat requests only route to that host. The fix requires adding activememory.ctx-context to the same affinity group in user settings. Signed-off-by: ersan bilik <ersanbilik@gmail.com>
- Fix gosec G101 lint path in .golangci.yml (constants moved to config/embed) - Fix TestTextDescKeysResolve path in embed_test.go - Add license header and doc.go for internal/config/embed - Add VS Code marketplace fields (extensionDependencies, pricing) - Add CHANGELOG.md and update .vscodeignore Signed-off-by: ersan bilik <ersanbilik@gmail.com>
- cmd.go: rename cmd.Flags() to c.Flags() (upstream variable rename) - sessionevent/cmd.go: update import core -> core/state (package split) - copilot.go: prefix Session/Message/ToolUse with entity. (types moved) DCO-1.1-Signed-off-by: ersan bilik <ersanbilik@gmail.com> Signed-off-by: ersan bilik <ersanbilik@gmail.com>
ce018c9 to
bf18bb0
Compare
DCO-1.1-Signed-off-by: ersan bilik <ersanbilik@gmail.com> Signed-off-by: ersan bilik <ersanbilik@gmail.com>
Add cross-platform hook generation for GitHub Copilot CLI integration. ctx hook copilot-cli --write generates .github/hooks/ctx-hooks.json with dual bash/PowerShell scripts for sessionStart, preToolUse, postToolUse, and sessionEnd lifecycle events. New files: - Embedded hook templates: ctx-hooks.json + 8 scripts (.sh/.ps1) - Asset readers: CopilotCLIHooksJSON(), CopilotCLIScripts() - WriteCopilotCLIHooks() in hook command run.go - Feature matrix spec: specs/copilot-cli-integration.md Constants added: ToolCopilotCLI, CLI event names, asset paths, text description keys, write output functions. DCO-1.1-Signed-off-by: ersan bilik <ersanbilik@gmail.com> Signed-off-by: ersan bilik <ersanbilik@gmail.com>
Add AGENTS.md generation (ctx hook agents --write) with universal agent instructions readable by all AI coding tools. Add Copilot CLI extras: .github/agents/ctx.md custom agent and .github/instructions/context.instructions.md path-specific guide. WriteCopilotCLIHooks now also generates agents/ctx.md and instructions/context.instructions.md alongside the hook scripts. WriteAgentsMd supports marker-based merge with existing AGENTS.md. New templates: agents.md, agents-ctx.md, instructions-context.md New constants: ToolAgents, AgentsMarker*, text keys, write functions DCO-1.1-Signed-off-by: ersan bilik <ersanbilik@gmail.com> Signed-off-by: ersan bilik <ersanbilik@gmail.com>
Phase 3A: MCP Registration - Add ensureCopilotCLIMCPConfig() to register ctx MCP server in ~/.copilot/mcp-config.json (respects COPILOT_HOME env var) - Merge-safe: reads existing config, adds ctx server, writes back - Uses official Copilot CLI mcpServers format with type=local - Called automatically from WriteCopilotCLIHooks() - Add DirCopilotHome, EnvCopilotHome, FileMCPConfigJSON constants Phase 3B: Copilot CLI Session Parser - Create CopilotCLIParser implementing SessionParser interface - Add ToolCopilotCLI constant to config/session/tool.go - Register parser in registeredParsers (parser.go) - Add CopilotCLISessionDirs() scanning ~/.copilot/sessions/, ~/.copilot/history/, and Windows LOCALAPPDATA paths - Wire into findSessionsWithFilter() query scanning (query.go) - Extract osWindows constant to satisfy goconst linter - Parser skeleton ready for format discovery as Copilot CLI session storage format stabilizes Ref: specs/copilot-cli-integration.md Phase 3 Signed-off-by: ersan bilik <ersanbilik@gmail.com>
Add 5 embedded skill templates for GitHub Copilot CLI integration: - ctx-status: context summary and health check - ctx-recall: session history browsing - ctx-drift: context drift detection - ctx-compact: archive completed tasks - ctx-next: advance to next task Each skill is written to .github/skills/<name>/SKILL.md when 'ctx hook copilot-cli --write' is invoked. Skills use YAML frontmatter (name, description) with Markdown instructions, following the Copilot CLI skill format. Wiring: - embed.go: glob for hooks/copilot-cli/skills/*/SKILL.md - agent.go: CopilotCLISkills() reader function - run.go: writeCopilotCLISkills() called from WriteCopilotCLIHooks() - asset.go: DirHooksCopilotCLISkills constant - hook.go: DirGitHubSkills, FileSKILLMd constants - text/hook.go: DescKeyWriteHookCopilotCLISkills key Signed-off-by: ersan bilik <ersanbilik@gmail.com>
1d54a06 to
31fdab2
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Three-layer governance architecture for VS Code Copilot and full GitHub Copilot CLI integration that closes the governance gap with Claude Code hooks, plus Copilot Chat session parser and Windows compatibility fixes.
Resolves #44
Closes #28
Closes #30
Closes #51
Supersedes #29, #31, #36
Architecture
Layer 1: Behavioral Rules (
copilot-instructions.md)Preventive/advisory rules in the system prompt — session lifecycle, when to call tools, governance response handling.
Layer 2: MCP Governance-in-Response
CheckGovernance()appends contextual warnings to every MCP tool response:ctx_session_event(start)ctx_status()ctx_drift()ctx_add()Layer 3: VS Code Detection Ring
Extension monitors terminal commands and file edits:
rm -rf /,git push --force, etc.).env,.pem, credentials)GitHub Copilot CLI Integration (Phases 1–4)
Phase 1 — Hook Generation
ctx hook copilot-cli --writegenerates.github/hooks/ctx-hooks.jsonPhase 2 — Agent Instructions
AGENTS.mdgeneration with universal agent instructions.github/agents/ctx.mdcustom agent +.github/instructions/context.instructions.mdPhase 3 — MCP Registration & Session Parser
~/.copilot/mcp-config.jsonCopilotCLIParserforctx recallwith cross-platform session dir detectionPhase 4 — Skills
.github/skills/<name>/SKILL.mdalongside hooksFeature Matrix
Full matrix: specs/copilot-cli-integration.md
Commits
ctx recallTesting