Problem
The exact same "not initialized" guard and error string is copy-pasted across five CLI commands:
if (!existsSync(env.dbPath)) {
env.io.err("agentctx is not initialized — run `agentctx init` first");
return 1;
}
packages/agentctx/src/cli/status.ts:38
packages/agentctx/src/cli/show.ts:40
packages/agentctx/src/cli/search.ts:66
packages/agentctx/src/cli/export.ts:50
packages/agentctx/src/cli/profile-cmd.ts:48 (wrapped in a local requireDb helper that emits the identical string)
If the message ever needs to change, it has to change in five places, and profile-cmd.ts already shows the intended shape (requireDb). This is the same "extract the shared helper" cleanup as #89 / #90.
What done looks like
- Add one shared helper in
src/cli/ (e.g. requireInitialized(env): boolean or reuse/relocate requireDb) that performs the existsSync(env.dbPath) check and emits the single canonical message.
- Replace the five inline copies with calls to it.
- Behavior and exit codes are unchanged;
npm run check stays green.
Problem
The exact same "not initialized" guard and error string is copy-pasted across five CLI commands:
packages/agentctx/src/cli/status.ts:38packages/agentctx/src/cli/show.ts:40packages/agentctx/src/cli/search.ts:66packages/agentctx/src/cli/export.ts:50packages/agentctx/src/cli/profile-cmd.ts:48(wrapped in a localrequireDbhelper that emits the identical string)If the message ever needs to change, it has to change in five places, and
profile-cmd.tsalready shows the intended shape (requireDb). This is the same "extract the shared helper" cleanup as #89 / #90.What done looks like
src/cli/(e.g.requireInitialized(env): booleanor reuse/relocaterequireDb) that performs theexistsSync(env.dbPath)check and emits the single canonical message.npm run checkstays green.