feat: thread cwd into observer/reflector agents for project-scope awareness - #50
Open
jingyulong wants to merge 1 commit into
Open
feat: thread cwd into observer/reflector agents for project-scope awareness#50jingyulong wants to merge 1 commit into
jingyulong wants to merge 1 commit into
Conversation
…reness The consolidation pipeline already has the session cwd available in ConsolidationCtx but never passes it to runObserver or runReflector. Neither agent's system prompt mentions the working directory or project relevance, so the LLM has no way to distinguish content that belongs to the current project from cross-project material that was read into the session (e.g. notes or files from a different project directory). This leads to off-topic observations being recorded and then crystallized into reflections that do not belong to the current project, polluting subsequent compaction summaries and system prompts with durable 'facts' about other codebases. Changes: - RunObserverArgs / RunReflectorArgs: add optional cwd field - runObserver / runReflector: inject a 'Working directory' line into the agent user text when cwd is provided - observer/reflector system prompts: add a 'Project scope' section guiding the agents to deprioritize or skip cross-project content and to prefer lower relevance when project membership is unclear - consolidation-trigger: pass cwd:ctx.cwd to both agent calls - tests: cover cwd injection, omission when absent, and end-to-end forwarding from the consolidation trigger
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.
PR: Thread cwd into observer/reflector agents for project-scope awareness
Problem
In a coding session for project A, the agent sometimes reads documentation, notes, or files that belong to a different project B (for example, referencing another codebase's debugging notes or a library writeup stored in a separate directory). Because the observer and reflector agents have no notion of the current working directory, they record these cross-project details as observations and crystallize them into reflections.
These reflections then propagate into compaction summaries and subsequent system prompts, so later turns in project A are oriented by durable "facts" about project B — facts the user never asked to remember for project A. Over multiple sessions this pollutes the reflection store with cross-project trivia that does not help (and sometimes misleads) future work in the current project.
Root cause
The consolidation pipeline already has the session
cwdavailable inConsolidationCtx, but:runObserverandrunReflectordo not receivecwd— neitherRunObserverArgsnorRunReflectorArgshas acwdfield.OBSERVER_SYSTEM,REFLECTOR_SYSTEM) mentions the working directory or asks the agent to weigh project relevance before recording/crystallizing.consolidation-trigger.tscallsrunObserverandrunReflectorwithout forwardingctx.cwd.So the LLM has no way to know which project a piece of content belongs to, and no instruction to filter cross-project material.
Changes
RunObserverArgs/RunReflectorArgs: add optionalcwd?: string.runObserver/runReflector: whencwdis provided, inject aWorking directory: <cwd>line into the agent user text (observer: after the timestamp; reflector: beforeCURRENT REFLECTIONS). Omitted entirely whencwdis absent — fully backward compatible.Project scopesection guiding the agents to:consolidation-trigger.ts: passcwd: ctx.cwdto bothrunObserverandrunReflector.observer.test.ts: cwd injected into user text when provided; omitted when absent.reflector.test.ts: same coverage.consolidation-trigger.test.ts: end-to-end —ctx.cwdis forwarded to both mocked agents.Design notes
cwdfield is optional on both arg types, so existing callers (tests, any other callers) keep working without changes.Verification
npm run typecheck— passes.npm test— 245 tests pass (25 files), including 5 new tests.Related