Skip to content

Refactor: choose the contacts file in one place - #22

Merged
Skeyelab merged 1 commit into
refactor/terminal-seamfrom
refactor/contacts-file
Nov 13, 2026
Merged

Skeyelab merged 1 commit into
refactor/terminal-seamfrom
refactor/contacts-file

Conversation

@Skeyelab

Copy link
Copy Markdown
Member

Stacked on #21.

Summary

+choose_contacts_file(flag) -> ContactsFile(path, origin: flag|env|search, searched)
+  .load()        # $IMSG_AGENT_CONTACTS pointing at a missing file is still an error
+  .empty_hint()  # "add contacts to X" | "create X" | "create X + searched list"
 ContactBook.open(path)   -> choose_contacts_file(path).load()
-_run_config: args.contacts_file or contacts_path()
-main --contacts: re-derives flag/env precedence for the hint
+both ask choose_contacts_file

Evidence

  • test_one_choice_says_which_contacts_file_is_in_force_and_why, parametrized over flag, env and search (red → green).
  • Existing hint and precedence tests are unchanged and pass. $IMSG_AGENT_CONTACTS is now read only in the chooser and the candidates list.
  • 131 passed.

Merge Danger

Door: two-way

Blast Radius: none. Messages and precedence are identical.

🤖 Generated with Claude Code

https://claude.ai/code/session_01VCgWWsJbTMzsnA2WJkmsjC

choose_contacts_file(flag) -> ContactsFile(path, origin, searched) is the
only code that weighs --contacts-file, $IMSG_AGENT_CONTACTS and the search.
ContactBook.open, --config and the --contacts empty-file hint all ask it,
instead of each re-deriving flag/env precedence. Messages are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VCgWWsJbTMzsnA2WJkmsjC
@claude

claude Bot commented Nov 13, 2026

Copy link
Copy Markdown

Reviewed the diff (imsgread.py, test_imsgread.py). I couldn't run the test suite here (pytest isn't installed in this environment), so I'm relying on the PR's "131 passed".

Invariants: no problems found in the changed lines

  • No real identifiers added. The test uses friend, +1555 and +1888, which are placeholders. For consistency with the documented placeholder, consider +15555550123.
  • Nothing here touches read/send scoping, --robot handling or the mode=ro connection. The chat-identifier requirement and the interactive-only marker refusal are unchanged.
  • Lookup order is preserved: flag, then $IMSG_AGENT_CONTACTS (an error if that file is missing), then the first existing candidate, else CONFIG_CONTACTS. load_contact_entries(None) and ContactBook.open keep the missing-env error.

Gap in the "one place" claim
_run_config calls choose_contacts_file(...).path and then load_contact_entries(path) with an explicit path, so it skips ContactsFile.load(). If $IMSG_AGENT_CONTACTS names a missing file, config shows "(none configured)" instead of the error that --contacts and sends give. This behaviour was the same before the PR. It may be intended, since config is how you create the file, but the PR description says the chooser is the single decision point. Either use chosen.load() there or add a comment saying why it doesn't.

Minor

  • --contacts-file ~/x.toml isn't expanduser'd (the env path is). Shells usually expand it, so this is low priority and was already the case.
  • The new test covers origin, path and searched. It doesn't cover load() raising for a missing env file or empty_hint()'s three variants. Existing tests may cover them indirectly, but one direct assertion on each would pin the refactor.

I didn't review the typedstream decoder or the README install steps, since this PR doesn't touch them.

@Skeyelab
Skeyelab added this pull request to stack #25 November 13, 2026 17:08
@Skeyelab
Skeyelab merged commit 5b2169a into main Nov 13, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant