Skip to content

Add --account flag to search command#165

Merged
wesm merged 9 commits intowesm:mainfrom
davidggphy:feat/search-account-flag
Mar 14, 2026
Merged

Add --account flag to search command#165
wesm merged 9 commits intowesm:mainfrom
davidggphy:feat/search-account-flag

Conversation

@davidggphy
Copy link
Copy Markdown
Contributor

@davidggphy davidggphy commented Mar 2, 2026

Add --account flag to msgvault search to scope results to a single account when multiple accounts are synced into the same archive.

$ msgvault search "budget proposal" --account alice@work.com
# only messages belonging to alice@work.com

The flag also works standalone to list all messages for an account:

$ msgvault search --account alice@work.com

Additional fixes included in this PR:

  • Reject --account in remote mode with a clear error instead of silently ignoring it
  • Fail fast on invalid queries before opening the database
  • Add AccountID to Query.IsEmpty() so it is treated as a valid filter criterion
  • Extract shared output helpers (formatSize, printJSON, aggregate formatters) from search.go into output.go

Closes #164.

@roborev-ci
Copy link
Copy Markdown

roborev-ci bot commented Mar 2, 2026

roborev: Combined Review (6fbb1a0)

Verdict: All successful
reviews found no issues, and the code appears clean.

(Note: Two automated review agents failed to complete their scans, but the successful review reported no findings.)


Synthesized from 3 reviews (agents: codex, gemini | types: default, security)

@davidggphy davidggphy marked this pull request as draft March 10, 2026 17:01
@davidggphy davidggphy marked this pull request as ready for review March 10, 2026 17:01
davidggphy and others added 7 commits March 13, 2026 13:59
Allows scoping search results to a single account when multiple
accounts are synced into the same archive.

Resolves the account identifier to a source_id via GetSourceByIdentifier
and sets q.AccountID directly on the parsed search.Query, which
buildSearchQueryParts already handles. No interface changes needed.
The --account flag was silently ignored when remote mode was active,
giving users unfiltered results without any indication. Fail fast
with a clear error instead.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Move account resolution before the IsEmpty() check so that
`search --account foo@bar.com` lists all messages for that account.
Add AccountID to Query.IsEmpty() and accept zero positional args
when --account is provided.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Extract aggregate flags, aggregate output formatters, formatSize,
and printJSON into output.go. These utilities are used by
list-labels, list-domains, list-senders, show-message, and
create-subset — not search-specific.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Reject --account in remote mode with clear error
- Accept --account without positional search terms (local mode)
- Require at least a query or --account flag
- Query with only AccountID set is not empty

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Assert Execute() returns nil and seed two accounts with messages
to verify the --account filter includes the correct account and
excludes the other. Use stdout capture to check JSON output.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Use io.ReadAll in a goroutine to fully drain the pipe, preventing
truncation on large output and deadlock if the command fills the
OS pipe buffer.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@wesm wesm force-pushed the feat/search-account-flag branch from 6fbb1a0 to ed87911 Compare March 13, 2026 19:02
When --account is not set, check IsEmpty() before store.Open so
that bad input like "before:not-a-date" gets rejected without
touching the database.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@roborev-ci
Copy link
Copy Markdown

roborev-ci bot commented Mar 13, 2026

roborev: Combined Review (ed87911)

Summary: The changes successfully introduce the --account flag for local searches
and extract output helpers, but there is one medium severity issue regarding CLI flag state management.

Medium

  • State Leakage in CLI Invocation: In search.go, the new search Account flag path stores the parsed value in a package-global variable and then reads that global during execution. With Cobra, if the command is executed a second time in the same process without --account, the old value remains and the next search is still account-filtered.
    • Suggested fix: Read -- account directly from cmd.Flags().GetString("account") inside RunE/runLocalSearch instead of relying on shared package state, and add a regression test with two back-to-back Execute() calls.

Synthesized from 3 reviews (agents: codex, gemini | types: default, security)

- TestSearchCmd_InvalidQueryFailsFastWithoutDB: config points at
  a non-existent directory, so any DB access would fail; asserts
  that "before:not-a-date" returns "empty search query" without
  touching the database.
- TestSearchCmd_AccountFlagDoesNotLeakAcrossInvocations: runs two
  back-to-back Execute() calls, first with --account and then
  without, verifying the second search is not account-filtered.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@roborev-ci
Copy link
Copy Markdown

roborev-ci bot commented Mar 13, 2026

roborev: Combined Review (2468dac)

Verdict: The changes to add the --account flag and refactor search output are clean, with no medium, high, or critical issues found across all reviews.


Synthesized from 3 reviews (agents: codex, gemini | types: default, security)

@wesm wesm merged commit efe77f8 into wesm:main Mar 14, 2026
4 checks passed
wesm added a commit that referenced this pull request Mar 14, 2026
…port

* origin/main:
  Add --account flag to search command (#165)
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.

Feature request: --account flag for search command

2 participants