Skip to content

"agentctx is not initialized" guard + message is duplicated across 5 CLI commands #97

Description

@Deepam02

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions