Skip to content

Make mnemon reachable inside the sandbox via the opt-in EXTRA_* mechanism#4

Open
audreyt wants to merge 3 commits into
bnivanov:mainfrom
audreyt:feat/mnemon-extra-opt-in
Open

Make mnemon reachable inside the sandbox via the opt-in EXTRA_* mechanism#4
audreyt wants to merge 3 commits into
bnivanov:mainfrom
audreyt:feat/mnemon-extra-opt-in

Conversation

@audreyt

@audreyt audreyt commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

Summary

Makes mnemon (recall + remember) reachable inside the sandbox via the general opt-in OMP_SANDBOX_EXTRA_WRITE / EXTRA_READ mechanism — the same knob users already use for any other extra writable/readable path.

On the real-dir-at-~/.mnemon setup (the symlink-into-~/.local era is over), the carve-out was functionally redundant with EXTRA_*: both produce byte-identical (subpath "$HOME/.mnemon") rules, and the per-$HOME-ancestor stat() walk that justified the ancestor-literal lines only applied to the symlink setup.

Behavior change (intended, opt-in)

mnemon is no longer automatic. A user who wants recall/remember inside the sandbox sets:

export OMP_SANDBOX_EXTRA_WRITE="$HOME/.mnemon"
export OMP_SANDBOX_EXTRA_READ="$HOME/.mnemon"   # or inherit from WRITE

EXTRA_READ must cover every EXTRA_WRITE path: Seatbelt file-write* and file-read* are independent classes — a path in EXTRA_WRITE but not EXTRA_READ is write-allowed-yet-read-denied, which breaks SQLite WAL and read-modify-write patterns. The ~/.zshrc shipped with this repo sets EXTRA_READ to inherit EXTRA_WRITE, which is the safe default.

MNEMON_DATA_DIR env forward and the OMP_SANDBOX_NO_MNEMON opt-out are dropped — neither is needed once the store is a real dir at the default path (mnemon resolves ~/.mnemon itself given $HOME, which the existing home-node metadata rule already covers).

Self-test hardening

The previous "fold ~/.mnemon into EXTRA_* then gen_profile" was a no-op in-process (EXTRA_RULES computed once at script entry; re-exporting the env var does not recompute the shell var gen_profile interpolates), and test 15 only passed as a side effect of test 13's clobber-then-restore of $PROFILE via a fresh --print-profile subprocess — reorder the tests and it would silently break.

  • _sbx_build_extra_rules() refactored into a function, called at top level and re-callable from the self-test.
  • Test 15 made self-contained: generates its OWN profile via a fresh "$0" --print-profile with EXTRA_*=~/.mnemon, then asserts recall returned a result (greps JSON for "id"), not just exit 0 — mnemon recall can exit 0 with empty output on failure modes, which would otherwise be a false pass.
  • Test 13's restore now restores $PROFILE to the pre-canary entry state (captured _entry_x*), no longer touching mnemon.

Verification (truly clean env — env -i, no EXTRA_*)

  • bash -n and /bin/bash -n (Apple stock bash 3.2): clean.
  • --self-test: 21 PASS. Lone FAIL is the pre-existing, unrelated --auto-approve flag accepted by omp (clean env) (omp version issue, not mnemon).
  • Test 15 detects its defect: a control with test 15's profile forced to lack mnemon → test 15 prints FAIL (no false pass).
  • Test 15 is order-independent: reordered before test 13 → still PASS.
  • Production e2e (EXTRA_*=~/.mnemon): --print-profile shows ~/.mnemon in write+read; mnemon recall jensen returns 1 real result. No phantom ~/.local/share/mnemon recreated.

Files

  • omp-sandboxed | 132 +- — refactor + self-test restructure + header comment refresh.
  • README.md | +7 — reframe write/read allowlist tables to "opt-in via EXTRA_*"; add a mnemon example.

Draft vs review

Marked ready for review. maintainer_can_modify is enabled so you can adjust on your end if needed.

audreyt and others added 3 commits June 27, 2026 11:35
…nism

The wrapper had a dedicated MNEMON_RULES carve-out block that allowlisted
omp's mnemon store (subpath read+write + $HOME-ancestor metadata stats)
unconditionally. On a real-dir-at-~/.mnemon setup this is functionally
redundant with the general OMP_SANDBOX_EXTRA_WRITE / EXTRA_READ opt-in:
both produce byte-identical (subpath "$HOME/.mnemon") rules, and the
per-ancestor stat() walk that justified the ancestor-literal lines only
applied in the symlink-into-~/.local era, which is gone (the store is now
a real dir at the default $HOME/.mnemon).

Remove the carve-out. mnemon is now opt-in: a user who wants recall (and
remember) inside the sandbox sets the same knob they use for any other
extra writable/readable path, e.g. in ~/.zshrc:

  export OMP_SANDBOX_EXTRA_WRITE="$HOME/.mnemon"
  export OMP_SANDBOX_EXTRA_READ="$HOME/.mnemon"   # or inherit from WRITE

This is necessary, not stylistic: Seatbelt file-write* and file-read* are
independent classes — a path in EXTRA_WRITE but not EXTRA_READ is
write-allowed-yet-read-denied, which breaks SQLite WAL and
read-modify-write patterns. EXTRA_READ inheriting EXTRA_WRITE (the
~/.zshrc that ships this) is the safe default.

Drop the now-unused MNEMON_DATA_DIR env forward and NO_MNEMON opt-out: the
real-dir-at-default store needs neither (mnemon resolves ~/.mnemon itself
given $HOME, which the existing home-node metadata rule already covers).

Harden the self-test so this stays true. The previous "fold ~/.mnemon into
EXTRA_* then gen_profile" was a no-op in-process (EXTRA_RULES are computed
once at script entry; re-exporting the env var does not recompute the shell
var gen_profile interpolates), and test 15 only passed as a side effect of
test 13's clobber-then-restore of $PROFILE via a fresh --print-profile
subprocess — reorder the tests and it would silently break.

  - Refactor EXTRA_RULES / EXTRA_READ_RULES build into a
    _sbx_build_extra_rules() function (called at top level and again from
    the self-test fold).
  - Make test 15 self-contained: it generates its OWN profile via a fresh
    "$0" --print-profile with EXTRA_*=~/.mnemon, then asserts recall
    RETURNED a result (greps JSON for '"id"'), not just exit 0 — `mnemon
    recall` can exit 0 with empty output on failure modes, which would
    otherwise be a false pass.
  - Capture the user's entry EXTRA_* so test 13's restore step restores
    $PROFILE to the pre-canary state, no longer touching mnemon.

Verified in a truly clean env (env -i, no EXTRA_*):
  - bash -n and /bin/bash -n (Apple stock 3.2): clean.
  - --self-test: 21 PASS, lone FAIL is the pre-existing unrelated
    --auto-approve omp-version issue.
  - test 15 detects its defect: forced-no-mnemon profile -> FAIL; reordered
    before test 13 -> still PASS (order-independent).
  - production --print-profile + recall with EXTRA_*=~/.mnemon returns 1
    real result; no phantom ~/.local/share/mnemon recreated.
- Permitted sandboxed processes to read the user's .bun directory alongside workspace and OMP data.
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