Repository navigation
fix(prompt): skip duplicate gentle-ai orchestration blocks from ancestor AGENTS.md (#1722) - #1769
Conversation
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Context-file filtering behavior lib/child-context-files.ts |
Managed-block filtering now accepts a removal predicate. New session filtering removes all managed blocks from ancestor files, removes orchestrator-only blocks from project-local files, and omits ancestor files left empty. |
Primary-session wiring and validation extensions/gentle-ai.ts, tests/child-context-files.test.ts, tests/append-system-prompt-route.test.ts, odd/tasks/fix-1722-deduplicate-orchestration-rules.md |
The primary-session hook filters context files using the session working directory before prompt construction. Tests cover ancestor detection, block removal, omitted files, and hook integration. The task document records the objective and verification checks. |
Priority:
Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Bug fix · Severity of issue fixed: Medium
Sequence Diagram(s)
sequenceDiagram
participant gentleAiExtension
participant filterSessionContextFiles
participant systemPromptOptions
participant promptConstruction
gentleAiExtension->>filterSessionContextFiles: Pass context options and session working directory
filterSessionContextFiles->>systemPromptOptions: Remove selected managed blocks and omit empty ancestor files
gentleAiExtension->>promptConstruction: Build prompt with filtered context options
Suggested reviewers: alan-thegentleman
Merge Risk: 
Low · up to 4c40a
-
A malformed ancestor context file can retain duplicate orchestration rules, but this is a narrow follow-up risk and does not block normal sessions from completing.
Architecture risk: 
Medium · up to 49a80
-
The change affects 4 systems.
Changed systems:
lib,extensions,tests,oddArchitecture concerns
No architecture-level concerns identified.Review details
-
Systems and components
- observed — lib (service) was modified; 1 changed file maps to changed impact.
- observed — extensions (service) was modified; 1 changed file maps to changed impact.
- observed — tests (service) was modified; 2 changed files map to changed impact.
- observed — odd (service) was modified; 1 changed file maps to changed impact.
Before / after behavior
- observed — Modified behavior in extensions/gentle-ai.ts: Imports
filterSessionContextFilesfor use in primary-session context setup. - observed — Modified behavior in extensions/gentle-ai.ts: Before prompt construction, primary sessions filter
event.systemPromptOptionsusingctx.cwd, falling back toprocess.cwd(). The added comments describe skipping duplicate Gentle AI orchestration blocks from ancestorAGENTS.mdfiles and retaining unmanaged text and non-orchestrator guidance. - observed — Modified behavior in lib/child-context-files.ts: The module comments now describe filtering ancestor context files for primary sessions, and imports add home-directory and path utilities.
- observed — Modified behavior in lib/child-context-files.ts: The former
filterOrchestratorOnlyBlocksimplementation is generalized as exportedfilterManagedBlocks, with a predicate parameter defaulting to the existing orchestrator-only managed-block set.
Reliability and maintainability
- inferred — Risk-relevant change factors for lib: blast_radius_1; direct_dependents_1
-
Pre-merge checks: 
5
-
Full details: Linked Issues check
-
Explanation
[
#1722] The PR filters all listedgentle-aimanaged blocks from ancestor context files before the primary-session prompt is built. It omits ancestor files that become blank and preserves unmanaged content. The primarybefore_agent_startflow runs the filter before appending the canonical orchestrator prompt. Tests cover ancestor detection, filtering, preservation, omission, and prompt routing.
Full details: Out of Scope Changes check
-
Explanation
The changes stay within prompt deduplication for [
#1722]. The parser generalization supports selective block removal. Project-local orchestrator filtering prevents stale orchestration rules from conflicting with the canonical prompt. Tests and task documentation support the implementation. No unrelated change is evident.
-
Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands.
49a8062 to
06d386d
Compare
06d386d to
4c40a71
Compare
|
The linked issue #1722 was closed after more than 21 days without activity, so this pull request is being closed with it. Reopen it together with the issue if the work should continue. |
Fixes #1722
Problem
When a
~/AGENTS.md(or any ancestorAGENTS.md) written bygentle-aiexists, agentle-shellsession started in any project under$HOMEloads the orchestration rules twice:gentle-shell's own injected harness (appendSystemPromptinextensions/gentle-ai.tscontaining## el Gentleman Identity and Harnessand# el Gentleman Orchestrator).AGENTS.mdloaded into Pi'ssystemPromptOptions.contextFiles(~59 KB containinggentle-ai:orchestrator,gentle-ai:agent-routing,gentle-ai:sdd-orchestrator,gentle-ai:sdd-model-assignments,gentle-ai:engram-protocol,gentle-ai:remote-authorization, andgentle-ai:codegraph-guidance).This results in:
Change
lib/child-context-files.ts:filterManagedBlocksto accept a custom block-removal predicate while preserving byte-for-byte all unmanaged project text, code fences, and structure.isAncestorContextFile(filePath, cwd, home)to detect when a context file is$HOME/AGENTS.md,$HOME/CLAUDE.md, or located in an ancestor directory abovecwd.filterSessionContextFiles(options, cwd, home):~/AGENTS.md), strip all duplicategentle-aimanaged blocks (orchestrator,sdd-orchestrator,sdd-model-assignments,agent-routing,engram-protocol,remote-authorization,codegraph-guidance,persona,strict-tdd-mode), while keeping unmanaged user/workspace instructions byte-for-byte. If an ancestor file becomes entirely blank after filtering, omit it fromcontextFilesto prevent rendering empty instruction blocks.ORCHESTRATOR_ONLY_MANAGED_BLOCKS(orchestrator,sdd-orchestrator,sdd-model-assignments,agent-routing) to prevent stale prompt overrides, while keeping project-local tools and non-orchestrator guidance.extensions/gentle-ai.ts:filterSessionContextFilesintobefore_agent_startfor primary sessions before the orchestrator prompt is appended, ensuring exactly one canonical copy of orchestration rules reaches the model.tests/child-context-files.test.ts: testisAncestorContextFileedge cases (home, parent, cwd, subfolder, unrelated) andfilterSessionContextFilesstripping / omitting.tests/append-system-prompt-route.test.ts: test primary sessionbefore_agent_startfiltering ancestor context files while appendinggentlePrompt.Verification
tests/child-context-files.test.tstests/append-system-prompt-route.test.tstests/orchestrator-budget.test.tsnode scripts/check-types.mjsclean (186 recorded diagnostics, 0 regressions).node scripts/build-runtime-modules.mjs --checkmatches TypeScript sources.Summary by CodeRabbit