ai-devkit
ai-devkit copied to clipboard
refactor(agent-manager): share the process/session matching tolerance instead of duplicating it in locators
Problem
The process ↔ session matching tolerance, TOLERANCE_MS = 3 * 60 * 1000, is private to packages/agent-manager/src/utils/matching.ts. The Gemini (#263) and Pi (#262) discovery changes use the same tolerance to decide which files are worth opening. Because the adapter tests mock utils/matching.ts, they couldn't import it, so the value was copied as local constants in GeminiSessionLocator and PiSessionLocator.
If the matcher's tolerance changes and the copies don't, discovery would silently skip files the matcher would accept. The result would be missed matches, with no test failing.
Proposed approach
- Move the constant to a small module that isn't mocked (e.g.
utils/matchingConstants.ts), re-export it fromutils/matching.ts, and import it in both locators. - Or export it from
utils/matching.tsand change the adapter tests to partial mocks (vi.mock(..., async (orig) => ({ ...(await orig()), matchProcessesToSessions: vi.fn() }))).
Acceptance criteria
- [ ] One source of truth for the matching tolerance, used by
matchProcessesToSessionsand by the Gemini and Pi discovery windows. - [ ] No duplicated tolerance literals remain; checked with a grep-based test or review.
- [ ] Existing Gemini, Pi and matching tests pass.
Depends on #262 and #263.