feat: Add push_repo_memory MCP tool for early size validation#19977
feat: Add push_repo_memory MCP tool for early size validation#19977
Conversation
Adds a new `push_repo_memory` safe output MCP tool that allows the AI agent to validate repo-memory file sizes during its session, before the post-run push job runs. When memory exceeds configured limits, the tool returns a clear error message suggesting the agent reduce content size. Changes: - Add `push_repo_memory` tool to safe_outputs_tools.json - Add `pushRepoMemoryHandler` to safe_outputs_handlers.cjs - Register handler in safe_outputs_tools_loader.cjs - Update safe_outputs_generation.go to include repo-memory config in safe outputs JSON when repo-memory is configured - Update repo_memory_prompt.md and repo_memory_prompt_multi.md to instruct agents to call push_repo_memory after writing memory - Update TestGetSafeOutputsToolsJSON to include push_repo_memory Co-authored-by: dsyme <7204669+dsyme@users.noreply.github.com>
…h_repo_memory Address code review: only add push_repo_memory to actions/setup/js/safe_outputs_tools.json without bringing in unrelated sync changes from pkg/workflow/js/safe_outputs_tools.json. Also improve handler comments and error message clarity. Co-authored-by: dsyme <7204669+dsyme@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds a new push_repo_memory MCP tool to allow agents to validate repo-memory size constraints during the session (before the post-run push_repo_memory.cjs job), and wires the tool into the safe-outputs MCP server when repo-memory is configured.
Changes:
- Inject
push_repo_memoryconfiguration (memories + limits) into safe-outputsconfig.jsonand enable the tool in filteredtools.jsonwhen repo-memory is present. - Add
pushRepoMemoryHandlerto scan repo-memory directories and enforce file size / file count / total size limits with the same 20% overhead approach as the post-run push job. - Update repo-memory prompts to instruct agents to call
push_repo_memoryafter writing memory files.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/workflow/safe_outputs_tools_test.go | Updates embedded tools JSON test to include push_repo_memory. |
| pkg/workflow/safe_outputs_generation.go | Adds safe-outputs config/tool enablement for push_repo_memory based on repo-memory config. |
| pkg/workflow/js/safe_outputs_tools.json | Adds the push_repo_memory tool schema to the embedded tools list. |
| actions/setup/md/repo_memory_prompt.md | Instructs agents to call push_repo_memory after writing memory files (single-memory prompt). |
| actions/setup/md/repo_memory_prompt_multi.md | Instructs agents to call push_repo_memory after writing memory files (multi-memory prompt). |
| actions/setup/js/safe_outputs_tools_loader.cjs | Registers push_repo_memory handler in the tool handler map. |
| actions/setup/js/safe_outputs_tools.json | Adds push_repo_memory tool schema to the runtime tools list used by the MCP server. |
| actions/setup/js/safe_outputs_handlers.cjs | Implements pushRepoMemoryHandler and exports it via createHandlers. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Add push_repo_memory config if repo-memory is configured | ||
| // This enables the push_repo_memory MCP tool for early size validation during agent session | ||
| if data.RepoMemoryConfig != nil && len(data.RepoMemoryConfig.Memories) > 0 { | ||
| var memories []map[string]any | ||
| for _, memory := range data.RepoMemoryConfig.Memories { | ||
| memories = append(memories, map[string]any{ | ||
| "id": memory.ID, | ||
| "dir": "/tmp/gh-aw/repo-memory/" + memory.ID, | ||
| "max_file_size": memory.MaxFileSize, | ||
| "max_patch_size": memory.MaxPatchSize, | ||
| "max_file_count": memory.MaxFileCount, | ||
| }) | ||
| } | ||
| safeOutputsConfig["push_repo_memory"] = map[string]any{ | ||
| "memories": memories, | ||
| } | ||
| safeOutputsConfigLog.Printf("Added push_repo_memory config with %d memory entries", len(memories)) |
There was a problem hiding this comment.
The new push_repo_memory safe-outputs config/tool enablement is not covered by existing Go unit tests for config/tool generation. Please add tests that verify: (1) generateSafeOutputsConfig includes the expected push_repo_memory.memories entries when RepoMemoryConfig is present, and (2) generateFilteredToolsJSON includes push_repo_memory only when repo-memory is configured.
There was a problem hiding this comment.
Added 6 Go unit tests in commit 13419cc:
generateSafeOutputsConfig tests (in safe_outputs_config_generation_test.go):
TestGenerateSafeOutputsConfigRepoMemory— verifiespush_repo_memory.memoriesentries are populated with correctid,dir, and size limits whenRepoMemoryConfigis presentTestGenerateSafeOutputsConfigNoRepoMemory— verifiespush_repo_memoryis absent whenRepoMemoryConfigis nilTestGenerateSafeOutputsConfigEmptyRepoMemory— verifiespush_repo_memoryis absent whenMemoriesslice is empty
generateFilteredToolsJSON tests (in safe_outputs_tools_generation_test.go):
TestGenerateFilteredToolsJSONIncludesPushRepoMemoryWithRepoMemoryConfig— verifiespush_repo_memoryis included whenRepoMemoryConfighas entriesTestGenerateFilteredToolsJSONExcludesPushRepoMemoryWithoutRepoMemoryConfig— verifiespush_repo_memoryis excluded whenRepoMemoryConfigis nilTestGenerateFilteredToolsJSONExcludesPushRepoMemoryWithEmptyMemories— verifiespush_repo_memoryis excluded whenMemoriesis empty
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…rs.test.cjs Covers: unknown memory_id, missing memory dir, oversized file, too many files, total size over limit, default memory_id, recursive subdirectory scanning, and handler structure export check. Co-authored-by: dsyme <7204669+dsyme@users.noreply.github.com>
- TestGenerateSafeOutputsConfigRepoMemory: verifies memories array is populated - TestGenerateSafeOutputsConfigNoRepoMemory: verifies absent when config is nil - TestGenerateSafeOutputsConfigEmptyRepoMemory: verifies absent with empty memories - TestGenerateFilteredToolsJSONIncludesPushRepoMemoryWithRepoMemoryConfig - TestGenerateFilteredToolsJSONExcludesPushRepoMemoryWithoutRepoMemoryConfig - TestGenerateFilteredToolsJSONExcludesPushRepoMemoryWithEmptyMemories Co-authored-by: dsyme <7204669+dsyme@users.noreply.github.com>
|
@copilot the core object should always be available since the shim.cjs file is loaded in the MCP JavaScript. Review and simplify code. |
…s available via shim.cjs Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Simplified in commit Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
|
✅ All tools validated successfully! Agent Container Smoke Test confirms agent container is ready. |
|
🌑 The shadows whisper... Smoke Codex failed. The oracle requires further meditation... |
|
🎬 THE END — Smoke Claude MISSION: ACCOMPLISHED! The hero saves the day! ✨ |
|
📰 BREAKING: Smoke Copilot is now investigating this pull request. Sources say the story is developing... |
Agent Container Tool Check
Result: 12/12 tools available ✅ Overall Status: PASS
|
|
Commit pushed:
|
|
🤖 Smoke test check-in from your friendly Copilot agent! Quick results for run §22808419281:
Overall: PR author:
|
There was a problem hiding this comment.
PR adds push_repo_memory as a new safe-output tool to enable early size validation before workflows complete. The changes are consistent across all workflow lock files and the Go generation code. One minor note about nil-vs-empty slice serialization on the memories array, but overall the implementation looks solid and well-tested.
📰 BREAKING: Report filed by Smoke Copilot
| } | ||
| safeOutputsConfig["push_repo_memory"] = map[string]any{ | ||
| "memories": memories, | ||
| } |
There was a problem hiding this comment.
Nice addition of push_repo_memory to the safe-outputs config! One small thought: if memories ends up being an empty slice (e.g., all memory configs are filtered out), the config entry would have "memories": null. Consider initializing with memories := make([]map[string]any, 0, len(data.RepoMemoryConfig.Memories)) to ensure it serializes as [] rather than null.
| // Add push_repo_memory tool if repo-memory is configured | ||
| // This tool enables early size validation during the agent session | ||
| if data.RepoMemoryConfig != nil && len(data.RepoMemoryConfig.Memories) > 0 { | ||
| enabledTools["push_repo_memory"] = true |
There was a problem hiding this comment.
Good symmetry — enabling push_repo_memory in the tools list mirrors the config generation above. This ensures the tool only appears in the schema when repo-memory is actually configured, keeping the tool surface clean.
|
📰 VERDICT: Smoke Copilot has concluded. All systems operational. This is a developing story. 🎤 |
Smoke Test Results — Run §22808419278Core tests #1–#10: ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ Overall: PARTIAL (close PR skipped — no safe test PR)
|
There was a problem hiding this comment.
💥 Automated smoke test review - all systems nominal!
💥 [THE END] — Illustrated by Smoke Claude
push_repo_memorytool topkg/workflow/js/safe_outputs_tools.jsonpush_repo_memorytool toactions/setup/js/safe_outputs_tools.jsonpkg/workflow/safe_outputs_generation.goto include repo-memory config in safe outputs config JSON and enable the tool in filtered toolspushRepoMemoryHandlertoactions/setup/js/safe_outputs_handlers.cjsactions/setup/js/safe_outputs_tools_loader.cjsactions/setup/md/repo_memory_prompt.mdto instruct agent to callpush_repo_memory(conditional on tool availability)actions/setup/md/repo_memory_prompt_multi.mdfor multi-memory workflows (conditional on tool availability)TestGetSafeOutputsToolsJSONtest to includepush_repo_memorypushRepoMemoryHandlerinsafe_outputs_handlers.test.cjs(9 new test cases)generateSafeOutputsConfigwithRepoMemoryConfig(3 tests)generateFilteredToolsJSONinclusion/exclusion ofpush_repo_memory(3 tests)pushRepoMemoryHandlerto usecore.debug(always available via shim.cjs) instead ofserver.debug💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.
Changeset
push_repo_memorysafe output tool that validates repo memory limits early in setup prompts and tests.Warning
The following domains were blocked by the firewall during workflow execution:
ab.chatgpt.comgithub.comTo allow these domains, add them to the
network.allowedlist in your workflow frontmatter:See Network Configuration for more information.
✨ PR Review Safe Output Test - Run 22808419278