Problem
The identical helper
function describe(error: unknown): string {
return error instanceof Error ? error.message : String(error);
}
is defined separately in five modules, and the same expression is also inlined in a few more — there is no single home for "stringify an unknown error".
Verbatim describe copies:
packages/agentctx/src/hooks/lifecycle.ts:83
packages/agentctx/src/hooks/session-start.ts:90
packages/agentctx/src/hooks/user-prompt-submit.ts:114
packages/agentctx/src/extract/ingest.ts:230
packages/agentctx/src/extract/run.ts:194
Same expression inlined (not via a helper):
packages/agentctx/src/consolidate/run.ts:57 — error instanceof Error ? error.message : String(error)
packages/agentctx/src/mcp/server.ts:75 — same
packages/agentctx/src/mcp/tools.ts:464 — same (in callTool's fallback)
This is the same kind of duplication already tracked for projectId.slice(0, 12) in #79.
What done looks like
- One shared helper (e.g.
describeError(error: unknown): string in a small new packages/agentctx/src/errors.ts, or alongside an existing dependency-free util) is the only definition.
- The five
describe copies are deleted and import the shared helper; the inlined ternaries are switched to it too.
- No behavior change —
npm run check stays green. Bonus: a one-line unit test covering the Error and non-Error branches.
Scope: mechanical, single concern, no architecture impact — a good first contribution.
Problem
The identical helper
is defined separately in five modules, and the same expression is also inlined in a few more — there is no single home for "stringify an unknown error".
Verbatim
describecopies:packages/agentctx/src/hooks/lifecycle.ts:83packages/agentctx/src/hooks/session-start.ts:90packages/agentctx/src/hooks/user-prompt-submit.ts:114packages/agentctx/src/extract/ingest.ts:230packages/agentctx/src/extract/run.ts:194Same expression inlined (not via a helper):
packages/agentctx/src/consolidate/run.ts:57—error instanceof Error ? error.message : String(error)packages/agentctx/src/mcp/server.ts:75— samepackages/agentctx/src/mcp/tools.ts:464— same (incallTool's fallback)This is the same kind of duplication already tracked for
projectId.slice(0, 12)in #79.What done looks like
describeError(error: unknown): stringin a small newpackages/agentctx/src/errors.ts, or alongside an existing dependency-free util) is the only definition.describecopies are deleted and import the shared helper; the inlined ternaries are switched to it too.npm run checkstays green. Bonus: a one-line unit test covering theErrorand non-Errorbranches.Scope: mechanical, single concern, no architecture impact — a good first contribution.