Problem
The formatAge(recordedAt, nowMs) helper that renders compact age labels (12m, 5h, 3d, 2mo) exists as two identical copies:
packages/agentctx/src/cli/search.ts:103 (exported)
packages/agentctx/src/mcp/tools.ts:540 (private)
Both implementations are byte-for-byte equivalent (only the local variable name differs: ageMs vs ms). This is the same "duplicated helper" smell already tracked for describe(error) (#89) and the truncation helper (#90).
What done looks like
- Move
formatAge into a single shared module (e.g. src/hooks/tokens.ts already holds shared formatting-style helpers, or a small src/format.ts) and import it from both cli/search.ts and mcp/tools.ts.
- Delete the two local copies.
npm run check stays green.
Note
formatAge is also the subject of #37 (it never renders "1mo"). Consolidating into one copy first means that logic fix only has to be made in one place — coordinate with whoever picks up #37, or fold both into one PR.
Problem
The
formatAge(recordedAt, nowMs)helper that renders compact age labels (12m,5h,3d,2mo) exists as two identical copies:packages/agentctx/src/cli/search.ts:103(exported)packages/agentctx/src/mcp/tools.ts:540(private)Both implementations are byte-for-byte equivalent (only the local variable name differs:
ageMsvsms). This is the same "duplicated helper" smell already tracked fordescribe(error)(#89) and the truncation helper (#90).What done looks like
formatAgeinto a single shared module (e.g.src/hooks/tokens.tsalready holds shared formatting-style helpers, or a smallsrc/format.ts) and import it from bothcli/search.tsandmcp/tools.ts.npm run checkstays green.Note
formatAgeis also the subject of #37 (it never renders"1mo"). Consolidating into one copy first means that logic fix only has to be made in one place — coordinate with whoever picks up #37, or fold both into one PR.