-
Notifications
You must be signed in to change notification settings - Fork 32
🤖 Change AGENTS.md to read from project root, not workspace #437
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
System message incorrectly read AGENTS.md from workspacePath (the worktree directory) instead of projectPath (the project root). This broke AGENTS.md forwarding for all workspaces. Root cause: Recent runtime changes treated workspace and project paths identically, but instruction files should come from the project root while the environment context uses the workspace path. Changes: - buildSystemMessage() now reads AGENTS.md from metadata.projectPath - Environment context still uses workspacePath (where code executes) - Updated all tests to reflect project vs workspace distinction - Renamed test variables for clarity (workspace -> project) Fixes instruction file loading for both LocalRuntime (worktrees) and SSHRuntime (clones).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| const systemDir = getSystemDirectory(); | ||
| const workspaceDir = workspacePath; | ||
| const projectDir = metadata.projectPath; | ||
|
|
||
| // Gather instruction sets from both global and workspace directories | ||
| // Global instructions apply first, then workspace-specific ones | ||
| const instructionDirectories = [systemDir, workspaceDir]; | ||
| // Gather instruction sets from both global and project directories | ||
| // Global instructions apply first, then project-specific ones | ||
| // Note: We read from projectPath (the main repo) not workspacePath (the worktree) | ||
| const instructionDirectories = [systemDir, projectDir]; | ||
| const instructionSegments = await gatherInstructionSets(instructionDirectories); | ||
| const customInstructions = instructionSegments.join("\n\n"); | ||
|
|
||
| // Look for a "Mode: <mode>" section inside instruction sets, preferring workspace over global | ||
| // Look for a "Mode: <mode>" section inside instruction sets, preferring project over global | ||
| // This behavior is documented in docs/instruction-files.md - keep both in sync when changing. | ||
| let modeContent: string | null = null; | ||
| if (mode) { | ||
| const workspaceInstructions = await readInstructionSet(workspaceDir); | ||
| if (workspaceInstructions) { | ||
| modeContent = extractModeSection(workspaceInstructions, mode); | ||
| const projectInstructions = await readInstructionSet(projectDir); | ||
| if (projectInstructions) { | ||
| modeContent = extractModeSection(projectInstructions, mode); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reading AGENTS from project root drops branch-specific instructions
The new logic loads instructions from metadata.projectPath instead of the workspace directory. For local workspaces we create git worktrees under src/<project>/<branch>, and the branch’s files (including AGENTS.md) live under that worktree path. Using the project root now always reads whatever AGENTS.md is checked out in the main repository, so any instructions modified or added in the current workspace branch are ignored. This also diverges from the documented behavior in docs/instruction-files.md, which layers instructions from <workspace>/AGENTS.md. Please continue reading from the workspace path (or fall back to it) so each workspace can provide its own instructions.
Useful? React with 👍 / 👎.
|
Closing this PR - Codex correctly identified that this breaks branch-specific instructions. The original behavior was correct: AGENTS.md should be read from the workspace path (worktree directory), not the project root. This allows different branches to have different instructions. @ammar Could you clarify what issue you're experiencing with AGENTS.md? The current implementation should be working correctly for local workspaces (worktrees). Are you:
Understanding the actual problem will help me provide the correct fix. |
|
This is an intentional design change, not a bug. We're changing the semantics to read AGENTS.md from the project root instead of individual workspaces. Rationale:
Branch-specific customization is still possible via The documentation has been updated to reflect this new behavior. |
Design Decision
Change the instruction file loading behavior to read AGENTS.md from the project root instead of individual workspace directories.
Rationale
AGENTS.local.md(gitignored)Changes
buildSystemMessage()now reads AGENTS.md frommetadata.projectPathworkspacePath(where code executes)docs/instruction-files.mdto reflect project-level instructionsBreaking Change
Migration Path
If you were using branch-specific instructions:
AGENTS.local.md(gitignored) for personal/workspace-specific overrides## Mode: Plan) for different contextsTesting
Generated with
cmux