.maestro/playbooks/2026-02-25-CM-Issues-PRs/2026-02-25-Branch-Memory/BRANCH-MEMORY-04.md
This phase extends branch awareness to the MCP search tools — search, timeline, and get_observations. When users search memory, results are filtered to only show observations from ancestor branches, matching the same behavior as SessionStart context injection. This completes the branch isolation story across all memory access points.
Update MCP search tool input schemas to accept branch parameters:
src/servers/mcp-server.ts to find the tool definitions for search, timeline, and get_observationscommit_sha property (type: string or array of strings) to the search and timeline tool input schemas — this allows explicit filtering by commit ancestrycwd property (type: string) to search and timeline — this enables auto-detection of branch ancestry when the caller provides a working directoryget_observations (batch fetch by ID): add optional commit_sha filter to the input schema for consistency, though this tool fetches by explicit IDs so filtering is less criticalcommit_sha (oneOf string/array) and cwd to search/timeline schemas, commit_sha to get_observations schemaUpdate the get.ts query filter builder to support commit SHA filtering:
src/services/sqlite/observations/get.ts, the getObservationsByIds function uses an additionalConditions[] / params[] patterncommit_sha handling from GetObservationsByIdsOptions (the type was updated in Phase 01):
AND (commit_sha IS NULL OR commit_sha = ?)AND (commit_sha IS NULL OR commit_sha IN (?, ?, ...))OR commit_sha IS NULL clause ensures backward compatibility with pre-migration observationsgetObservationsByIds (get.ts), SessionStore.getObservationsByIds, SessionSearch.buildFilterClause, and SearchFilters typeUpdate SearchManager to apply branch filtering:
src/services/worker/SearchManager.ts to understand the search() and timeline() method signatures and how they delegate to SearchOrchestrator or SQLite queriessearch(): accept commit_sha and cwd parameters. When commit_sha is provided directly, use it as the filter. When only cwd is provided, auto-resolve using getUniqueCommitShasForProject + resolveVisibleCommitShas from Phase 02timeline(): apply the same branch filtering to both the anchor observation lookup and the surrounding observations returned as contextproject and type filters are threadedresolveBranchFilter() method; both search() and timeline() resolve commit_sha from direct param or cwd auto-detection; timeline post-filters observationsUpdate worker search routes to accept and pass branch parameters:
src/services/worker/http/routes/SearchRoutes.tsGET /api/search handler, extract commit_sha and cwd from req.query and pass them to searchManager.search()GET /api/timeline handler, extract the same parameters and pass to searchManager.timeline()POST /api/observations/batch route (if in a different file like DataRoutes.ts), extract commit_sha from the request body and pass to the query functionreq.query directly; DataRoutes updated to extract and pass commit_sha; normalizeParams handles comma-separated SHAsBuild and verify search respects branch boundaries:
npm run build-and-synctests/sqlite/observations-branch-filter.test.ts (6 tests) validating single/array commit_sha filtering with backward compatibility