Skip to content

feat(cli): hint when a tree filter looks shell-expanded from ~#94

Merged
cevian merged 2 commits into
mainfrom
cevian/fix-export
Jun 24, 2026
Merged

feat(cli): hint when a tree filter looks shell-expanded from ~#94
cevian merged 2 commits into
mainfrom
cevian/fix-export

Conversation

@cevian

@cevian cevian commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Problem

me export --tree ~/granola … silently reports "No memories found", while the quoted --tree '~/granola' finds them. This isn't an export bug — the shell expands an unquoted leading ~ before argv reaches the CLI:

  • --tree ~/granola--tree /Users/me/granola → normalizes to the ltree filter Users.me.granola → matches nothing.
  • --tree '~/granola' (quoted) reaches the CLI intact → expands to the caller's memory home → matches.

~/… is exactly the home form the docs recommend, so silent zero-results is a nasty trap. It affects every --tree-taking command, not just export.

Fix

Add shellTildeExpansionHint (packages/cli/util.ts). On a zero-result path, if the tree value is the caller's filesystem home or a child of it (the tell-tale of ~ expansion — a real tree path is never an absolute fs path, so this never fires on a legitimate filter), emit a one-line hint:

⚠ No memories found matching filters.
  Hint: your shell may have expanded '~'. Try: me export --tree '~/granola' /Users/me/Downloads/granola.bak

The suggestion is the full command as typed, reconstructed from process.argv, with the shell-expanded token swapped for the quoted ~ form (and any other arg POSIX-quoted only if needed) so it's copy-pasteable.

Warn-only — never rewrites the filter. Wired into every tree command's empty branch: search, export, count, tree, deltree, move, copy.

Test plan

  • New unit tests in packages/cli/util.test.ts (full-command rebuild, bare ~, spaces-in-query quoting, real-filter → null, sibling-prefix → null, empty//-home edges).
  • ./bun run check → green (typecheck clean, 649 pass / 0 fail).

🤖 Generated with Claude Code

An unquoted leading `~` is expanded by the shell before argv reaches the
CLI: `me export --tree ~/granola` arrives as `--tree /Users/me/granola`,
which normalizes to the ltree filter `Users.me.granola` and silently
matches nothing — exactly when the caller meant their memory home and
should have quoted it (`'~/granola'`).

Add `shellTildeExpansionHint` (packages/cli/util.ts): on a zero-result
path, if the tree value is the caller's filesystem home or a child of it
(the tell-tale of `~` expansion — a real tree path is never an absolute
fs path), emit a one-line hint with the full command requoted and ready
to paste. Wired into every tree command's empty branch: search, export,
count, tree, deltree, move, copy.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@cevian cevian requested a review from jgpruitt as a code owner June 24, 2026 09:31
@cevian cevian requested a review from murrayju June 24, 2026 09:35

@murrayju murrayju left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the hint. I'd just cut down on the duplication for the warning generation.

Comment on lines +619 to +623
clack.log.warn(
hint
? `No memories found under '${tree}'\n${hint}`
: `No memories found under '${tree}'`,
);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would prefer to DRY these up.

clack.log.warn(
  `No memories found under '${tree}'${hint ? `\n${hint}` : ''}`
)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 9793b1c — collapsed to the inline template you suggested (applied across export/deltree/move/copy). Thanks!

Address review: collapse the two-branch ternary (which repeated the base
message) into a single inline template that appends the hint when present.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@cevian cevian merged commit b5721aa into main Jun 24, 2026
4 of 5 checks passed
@cevian cevian deleted the cevian/fix-export branch June 24, 2026 14:00
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.

3 participants