Fix managed_section ignored in distributed and single-agents compile paths#1768
Open
sergio-sisternes-epam wants to merge 1 commit into
Open
Conversation
Route root AGENTS.md writes through _write_output_file_with_config() when agents_md_mode is managed_section, so hand-written content outside the APM markers is preserved instead of silently overwritten. - _write_distributed_file: check if agents_path is the root AGENTS.md and config is managed_section before choosing the write path. Sub-directory files remain fully overwritten (APM-generated). - --single-agents CLI path: after constitution injection, honour managed_section via _write_output_file_with_config instead of direct CompiledOutputWriter.write. - Add 3 regression tests covering distributed+managed_section (root preserved, non-root overwritten, full mode overwritten). Fixes #1764 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a regression where compilation.agents_md.mode: managed_section was ignored in the active compilation paths (distributed default and --single-agents), causing silent full overwrite of AGENTS.md instead of marker-bounded replacement.
Changes:
- Route distributed compilation root
AGENTS.mdwrites through_write_output_file_with_config()whenagents_md_mode == "managed_section". - Route the
--single-agentsCLI write path through_write_output_file_with_config()whenmanaged_sectionis configured, and broaden error handling. - Add unit regression tests covering root vs subdirectory behavior for
managed_sectionandfullmodes.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/apm_cli/compilation/agents_compiler.py |
Adds a root-file-only managed-section write path in distributed compilation. |
src/apm_cli/commands/compile/cli.py |
Ensures --single-agents honors managed-section mode when writing final output. |
tests/unit/compilation/test_managed_section.py |
Adds regression tests for distributed root/subdir semantics and full overwrite behavior. |
Comment on lines
+1556
to
+1561
| # Honour managed_section mode for the root AGENTS.md (issue #1764). | ||
| # Sub-directory files are fully APM-generated and always overwritten. | ||
| is_root = agents_path.parent.resolve() == self.base_dir.resolve() | ||
| if is_root and config.agents_md_mode == "managed_section": | ||
| self._write_output_file_with_config(str(agents_path), final_content, config) | ||
| return |
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.
Description
apply_managed_section()exists and works correctly, but neither the distributed compilation path (default since Task 7) nor the--single-agentsCLI path routes through it. Users who configuremode: managed_sectioninapm.ymlexperience silent full-file overwrite of AGENTS.md instead of selective marker-bounded replacement -- erasing hand-written content without warning.The fix routes root AGENTS.md writes through
_write_output_file_with_config()whenagents_md_modeismanaged_section, so the existingapply_managed_section()logic is honoured. Sub-directory AGENTS.md files in distributed mode remain fully overwritten since they are entirely APM-generated.Fixes #1764
Type of change
Testing
Changes
_write_distributed_file(agents_compiler.py): Before writing, checks whether the target is the root AGENTS.md (agents_path.parent == self.base_dir) andagents_md_mode == "managed_section". If both hold, delegates to_write_output_file_with_config()which preserves content outside the markers. Sub-directory files skip this check and remain fully overwritten.--single-agentsCLI path (commands/compile/cli.py): After constitution injection, checksconfig.agents_md_modeand routes throughcompiler._write_output_file_with_config()instead of directCompiledOutputWriter.write(). Also catchesValueError(parent ofManagedSectionError) for clean error reporting.Regression tests (test_managed_section.py): 3 new tests:
managed_sectionmodemanaged_sectionfull(negative test)Spec conformance (OpenAPM v0.1)