feat: add read-only JSON memory CLI for SSH/cron automation#124
Merged
Conversation
Adds sandbox-friendly read-only commands that open ai-memory/brain.db in SQLite read-only mode (PRAGMA query_only=ON) without shelling out through Doppler: pt memory search --query ... --json pt memory recent --json pt memory stats --json pt memory export --format ndjson pt config show --effective --json pt doctor --json pt --version Existing human `pt memory search "query"` behavior is preserved; JSON/filter mode uses the direct read-only query path.
- Drop the `--json in sys.argv` short-circuit in cli(): it was too broad (silently suppressed migration warnings for every existing --json consumer like `pt info list --json`). The migration warning already goes to stderr, the banner is already TTY-gated, and PT_SUPPRESS_MIGRATION_WARNING is the documented opt-out for cron/SSH. - Annotate _emit_json_error as NoReturn so type checkers know variables in the surrounding scope are unreachable on the error path. No runtime change — SystemExit propagation was already correct. - Route memory_export errors to stderr via a new err= kwarg on _emit_json_error. NDJSON streams must keep stdout exclusively for data lines; an error JSON object mid-stream would corrupt downstream parsers. Other JSON commands keep stdout-on-error since they emit a single object the consumer can branch on. - Add three memory_export tests: ndjson shape, --project filter, error-routing-to-stderr.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ai-memory/brain.dbdirectly in SQLite read-only mode (PRAGMA query_only = ON) without shelling through Doppler.pt memory search --query ... --json,pt memory recent --json,pt memory stats --json,pt memory export --format ndjson,pt config show --effective --json,pt doctor --json,pt --version.pt memory search "query"behavior is preserved; JSON/filter mode uses the new direct read-only path.Design notes
schema_versionstring (pt.memory.v1,pt.config.v1,pt.doctor.v1).2validation,3backend unavailable,4query failure,5auth.search/recent/stats) emit error JSON to stdout (consumer branches onok);memory exportemits errors to stderr so its NDJSON stdout stream stays exclusively a data channel._emit_json_erroris annotatedNoReturnto make the control flow legible to type checkers._warn_unapplied_migrationswrites to stderr only, banner is TTY-gated, andPT_SUPPRESS_MIGRATION_WARNING=1is the documented opt-out for cron/SSH.Test plan
PT_SKIP_DOPPLER=1 ./pt doctor --jsonreturns a validpt.doctor.v1payload with all checks ok on a healthy box../pt memory recent --since 7d --limit 5 --jsonreturns apt.memory.v1envelope with stablepaginationfields../pt memory export --project project-tracker --format ndjsonprints one JSON object per line on stdout, nothing on stderr; exit code 0.PT_MEMORY_DB_PATH=/tmp/missing.db ./pt memory exportprints nothing on stdout, a structuredbackend_unavailableJSON object on stderr, exit code 3../pt memory search "MCP" --top 3(no--json, no filters) still hits the existing brain.py path and behaves identically to main../pt info list --json(existing command) still emits the same output as main — confirms the migration-warning gate change did not regress unrelated--jsonconsumers.pytest tests/test_memory_cli.py— 8/8 green.Related