Skip to content

fix: the basics, verified in a real shell, and release 0.5.2 - #31

Merged
matinsaurralde merged 8 commits into
masterfrom
fix/demo-basics
Sep 24, 2026
Merged

matinsaurralde merged 8 commits into
masterfrom
fix/demo-basics

Conversation

@matinsaurralde

Copy link
Copy Markdown
Owner

Summary

Every documented claim was re-checked against the installed 0.5.1 binary, driven through real interactive zsh and bash sessions rather than fixtures. This fixes what that turned up in the core path — capture, search, the repo column, patterns — and releases 0.5.2.

  • mem recorded its own invocations. A repeated search answered with the earlier search, the concept map never ran for a question asked twice, and mem forget X wrote X back as it deleted it. One rule, ranking.canonical(), now decides what a command is (mem's own invocations rejected, surrounding whitespace dropped) and is applied at capture, on every read, in import and in mem save '!', so stores written by 0.5.1 are cleaned without being rewritten.
  • The repo column printed a cut path, so every repo under a home directory read /Users/mati…. Listings now show the repo name (ranking.repo_name(), shared with the finder).
  • A tool run by path wrote its patterns outside ~/.mem and tightened that directory to 0700; one tool's failure ended the whole sync, and retention with it. Tools are filed by name, pattern_file() refuses paths, failures are per tool, and rotation has its own try.
  • Listing a command could control the terminal. Escape sequences in stored text reached the terminal through safe()/plain(). The finder's rule moves to _text.printable() and every surface shares it.
  • mem forget "" deleted the whole store. A blank query is now a usage error.
  • README rewritten around the basics, with every example checked against the binary; the bash hook goes in ~/.bash_profile, which macOS terminals read.
  • Release 0.5.2, and Python 3.13 declared (CI already tests it).

Test plan

  • pytest -W error: 1567 passed, 4 skipped
  • pytest -m perf: 4 passed
  • ruff check . and ruff format --check . clean
  • Every new test fails on the parent commit; the end-to-end test replays the reported transcript in real zsh and bash sessions
  • Checked against a copy of a real 362-command store: repeated question returns lsof -i :8080, ls appears once, repo names shown, -p lists patterns
  • CI green on macOS × Python 3.10–3.13
  • Tag v0.5.2 on the merge commit; release.yml publishes to PyPI, GitHub Releases and the Homebrew tap

🤖 Generated with Claude Code

…answered itself

The shell hooks hand every typed line to `mem _capture`, mem's own included,
and nothing filtered them. Three silent failures followed, all exit code 0:

- Asking a question twice matched the first asking on every word. The literal
  pass answered with it and the concept map never ran, so the README's own
  example, `mem "how do I see what's listening on a port"` -> `lsof -i :8080`,
  worked at most once per question.
- `mem forget "API_KEY=sk-..."` deleted the key, then the hook captured the
  line that deleted it and wrote the secret back. `mem run api TOKEN=...` and
  `mem vars set NAME value` stored their secrets the same way.
- After one session following the README, 118 of 218 records were mem itself.

`ranking.canonical()` now decides what a command is: surrounding whitespace
removed, so `ls` and `ls ` stop being two results with half the frequency
each, and mem's own invocations rejected. It is applied at capture, on every
read (`storage.read_commands` and the finder's `parse_entry`, so stores written
by 0.5.1 are cleaned without rewriting them), in the shell-history import, and
in `mem save '!'`. It lives in ranking.py because the finder cannot import
Pydantic.

The new end-to-end test replays the reported transcript in real zsh and bash
sessions. It and every new unit test failed before this change.
…e same

Search, forget, session and stats listings printed the first characters of
the repo's absolute path. Every repo under a home directory rendered as
`/Users/mati…`, so the column that is meant to show which repo a command
came from could not tell any two apart, and never looked like the README's
`infra` / `backend` example.

`ranking.repo_name()` returns the repo's directory name, and every listing
uses it, including the finder, which already did this with its own copy. The
full path is unchanged in `--json`.

The test stores commands from two repos under one parent and checks both
names appear and no path does; it failed before this change.
A pattern file was named after a command's raw first word. For
`/abs/dir/tool.sh` run five times, `MEM_DIR/"patterns"/"/abs/dir/tool.sh.json"`
resolved to `/abs/dir/tool.sh.json`: the file landed beside the script,
outside ~/.mem where `forget` never looks, and the directory was tightened to
0700. Where that directory was not writable, the OSError ended the whole
background sync, so every other tool stopped getting patterns and, because
rotation shared the same `try`, 90-day retention stopped with it. No message,
no exit code.

- `storage.tool_name()` files a program under its name (`/usr/bin/git` is
  `git`), for extraction and for `mem <tool> -p` alike.
- `storage.pattern_file()` refuses anything but a plain name.
- One tool's failure is logged and skipped instead of ending the sync.
- Rotation runs in its own `try` after extraction.

Each of the four tests failed before this change.
…characters

`safe()` and `plain()` neutralised Rich markup but passed escape sequences
through, and the session replay prompt printed stored text raw. History is
whatever somebody pasted into a shell, so listing a command containing
`ESC ]0;…BEL` or `ESC [2J` retitled the window or cleared the screen: the
command acted on the terminal instead of being shown. The finder already
replaced these characters; the CLI never did.

The finder's rule moves to `_text.printable()`, standard library only so the
finder can still use it, and every CLI surface now shares it: `safe()`,
`plain()`, the session panel (built line by line, so its own newlines are
not data) and the replay confirmation.

The new tests seed an OSC title change and a clear-screen into every listing
surface and the replay prompt; all seven failed before this change.
An empty string is a substring of every command, so `mem forget ""`, or
`mem forget "$UNSET" --yes` in a script, matched everything. The confirmation
counted only history lines ("Delete all 15?") and never said that every saved
command, runbook, variable and pattern would go too.

A blank query is now a usage error, raised before anything is previewed or
touched. Both tests (empty and whitespace-only) failed before this change.
The README had grown to 751 lines and made promises the code does not keep
for a new user: the bash hook went into ~/.bashrc, which macOS terminals never
read, so bash users captured nothing; `mem save "!"` is eaten by the shell's
history expansion; the variables example quoted `$API_TOKEN` in single quotes,
which sends the literal text; and "<5 ms" per prompt measured only the fork.

It now follows the structure of the July README: install, search, the Ctrl+R
finder, patterns, scoping, groups, variables, then how it works, storage and
privacy, with every example checked against the installed binary. The search
listing shows repo names, as it now does, and the variables block is the
real output of `mem list <group>`.
pyproject listed 3.10 to 3.12 while the CI matrix runs 3.10 to 3.13, so PyPI
advertised less than the project verifies.
@matinsaurralde
matinsaurralde merged commit 7752267 into master Sep 24, 2026
5 checks passed

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 96451dc594

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/mem/ranking.py
Comment on lines +177 to +181
for word in command.split():
name, equals, _ = word.partition("=")
if equals and name.isidentifier():
continue
return os.path.basename(word) == "mem"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Detect wrapped and compound mem invocations

When mem is invoked through a shell wrapper or later in a compound command—such as command mem forget SECRET, env FOO=bar mem stats, sudo mem ..., or echo ok; mem forget SECRET—the first non-assignment word is not mem, so this function returns false and the hook records the entire line. Quoted assignments such as FOO='a b' mem ... are also split incorrectly. These cases preserve the original secret-recapture bug that this filter is intended to prevent.

Useful? React with 👍 / 👎.

Comment thread src/mem/storage.py
Comment on lines +589 to +591
command = ranking.canonical(cmd.command)
if command is None:
continue

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Keep hidden self-invocations discoverable by forget

When a query exists only in an old self-invocation—for example an invocation imported by 0.5.1, or one whose 30-day session copy has already rotated—this filter removes it from the read_all_commands() preview used by mem forget. forget_targets() does not scan repo history, so the CLI concludes there are no matches and returns without calling forget_commands; consequently even mem forget SECRET --yes cannot delete that raw history line.

Useful? React with 👍 / 👎.

Comment thread src/mem/cli.py
Comment on lines +383 to +385
panel_content = Text("\n").join(
plain(f" {j:>2} {cmd}") for j, cmd in enumerate(s.commands, 1)
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Filter legacy mem invocations from session listings

For users upgrading from 0.5.1, persisted work sessions can already contain mem ... commands, but read_all_sessions() does not apply ranking.canonical() and this loop still renders every stored command and subsequently offers it for replay. Thus mem session continues to list legacy self-invocations even though command-history readers now hide them; session commands and summaries need equivalent normalization.

Useful? React with 👍 / 👎.

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