Skip to content

formatAge is duplicated verbatim in cli/search.ts and mcp/tools.ts #96

Description

@Deepam02

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions