ai-devkit icon indicating copy to clipboard operation
ai-devkit copied to clipboard

refactor(agent-manager): share the process/session matching tolerance instead of duplicating it in locators

Open codeaholicguy opened this issue 2 months ago • 0 comments

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 from utils/matching.ts, and import it in both locators.
  • Or export it from utils/matching.ts and 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 matchProcessesToSessions and 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.

codeaholicguy avatar Sep 28 '26 11:09 codeaholicguy