Skip to content

Set the default knowledge base from the command line #793

Description

@williamthorsen

Problem

The default_kb pointer in kb.yaml (introduced in #779) can only be changed by hand-editing the registry file. There is no command-line way to choose, change, or remove the default knowledge base, so a user must know the registry's location, its syntax, and the exact registered name to set the default correctly — and must hand-edit again to clear it.

Context

  • default_kb is a top-level key in the user-global ~/.agents/kb.yaml registry. It names one registered KB as the machine's default, and the agents (kb-add, kb-retrieve, capture-event) fall back to it when no store is named or discovered.
  • An absent default_kb is a fully supported state: every consumer branches on it and falls back to discovery or a clear "no default configured" error. Removing the default is therefore a legitimate thing a user may want.
  • kb create already registers KBs in the user-global registry and preserves existing comments when it writes — the same write target and behavior this command should follow.
  • The kb CLI dispatches subcommands through a dispatcher whose commands return a result rather than performing terminal I/O directly. This is the first command to require interactive input.
  • Scope is the user-global registry only. Project-local defaults (.agents/kb.yaml) remain hand-edited; a --project flag is a possible later addition, not part of this work.
  • Set the default KB when creating a knowledge base #792 (kb create auto-default) depends on this command and reuses its building blocks, so those blocks must be importable independently of the CLI handler.

Proposed solution

Add a kb set-default subcommand covering set and clear:

  • kb set-default <name> sets default_kb to the named KB, erroring if that name is not registered.
  • kb set-default --none clears default_kb.
  • kb set-default with no arguments presents an interactive selection of the registered KBs — marking the one that is currently the default and offering a (none) choice to clear it — and writes the selection.

The command operates on the user-global ~/.agents/kb.yaml, validates any target name against the KBs registered there, and preserves existing comments and formatting on write (consistent with kb create). The interactive prompt follows established CLI selection conventions: a numbered list, a clear cancel path, and a graceful error when stdin is non-interactive rather than a hang. On success it confirms the completed change; cancelling leaves the registry unchanged.

The logic is layered so the building blocks are reusable: a pair of registry writers (set/clear), an interactive picker, and the no-argument interactive flow — each importable on its own, not reachable only through the CLI handler.

Acceptance criteria

Must have

  • kb set-default <name> sets default_kb to <name> in the user-global registry and reports success.
  • kb set-default <name> exits with a usage error when <name> is not a registered KB, leaving the registry unchanged.
  • kb set-default --none clears default_kb and reports success.
  • Supplying both <name> and --none exits with a usage error.
  • kb set-default with no arguments lists the registered KBs, indicates which is currently the default, offers a (none) option to clear the default, and applies the selection.
  • Cancelling the interactive selection leaves the registry unchanged.
  • The no-argument form exits with a usage error when stdin is not interactive, rather than hanging.
  • The name and interactive forms exit with a clear usage error — directing the user to kb create — when no KBs are registered.
  • Writing or clearing default_kb preserves existing comments and formatting in kb.yaml.
  • Success messages read as completed actions, not imperatives (e.g. Default knowledge base has been set to "personal". and The default knowledge base has been cleared.).
  • The selection-and-write building blocks are importable independently of the CLI handler — the default_kb writers, the interactive picker, and the no-argument set-default flow — so other commands (e.g. kb create, Set the default KB when creating a knowledge base #792) can reuse them.
  • New and modified behavior is covered by tests.
  • The kb help text and the package README document the set-default command, including --none.

Should have

  • Invalid interactive input (non-numeric or out of range) re-prompts rather than aborting.
  • Setting the current default again, or clearing when no default is set, succeeds idempotently rather than erroring.

Metadata

Metadata

Labels

featureAdded or improved external functionalityscope:kb

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions