Override the default log file path by environment variable MAGIC_CONTEXT_LOG_PATH#183
Override the default log file path by environment variable MAGIC_CONTEXT_LOG_PATH#183kecsap wants to merge 1 commit into
Conversation
| ## Logs | ||
|
|
||
| Optional **log tail** for `magic-context.log` with filtering — useful alongside Cache when correlating busts with plugin log lines. Open from the sidebar **Logs** item. | ||
| Optional **log tail** for `MAGIC_CONTEXT_LOG_PATH` (fallback: `${TMPDIR}/opencode/magic-context/magic-context.log`) with filtering — useful alongside Cache when correlating busts with plugin log lines. Open from the sidebar **Logs** item. |
There was a problem hiding this comment.
The two README files both mention
pi/ as the Pi-harness fallback subdirectory, but this docs page omits it, leaving the description inconsistent.
| Optional **log tail** for `MAGIC_CONTEXT_LOG_PATH` (fallback: `${TMPDIR}/opencode/magic-context/magic-context.log`) with filtering — useful alongside Cache when correlating busts with plugin log lines. Open from the sidebar **Logs** item. | |
| Optional **log tail** for `MAGIC_CONTEXT_LOG_PATH` (fallback: `${TMPDIR}/opencode/magic-context/magic-context.log`, `pi/` for Pi) with filtering — useful alongside Cache when correlating busts with plugin log lines. Open from the sidebar **Logs** item. |
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
alfonso-magic-context
left a comment
There was a problem hiding this comment.
Thanks for this, the MAGIC_CONTEXT_LOG_PATH override is a good idea and the plugin-side change is clean (single choke point in getMagicContextLogPath, trims and ignores blank, with tests). A couple of changes needed before merge:
-
Please rebase onto
master. The branch currently conflicts. We landed the config-location cutover (config + artifacts moved to the shared CortexKit location) since this PR was opened, which touches nearby docs/paths. -
The dashboard doc change overstates support. The PR updates
packages/dashboard/README.mdand the docsdashboard.mdto say the dashboard Logs tab honorsMAGIC_CONTEXT_LOG_PATH, but the dashboard's Rust log resolver (packages/dashboard/src-tauri/src/log_parser.rs,resolve_log_path_for) readsstd::env::temp_dir()and does not read that env var. As written, a user who setsMAGIC_CONTEXT_LOG_PATHwould have the plugin write to the custom path while the dashboard keeps reading the default tmp path, so the docs would be wrong.Two ways to resolve, either is fine:
- Simplest: drop the dashboard doc edits from this PR and keep it plugin-only (the env override still works for the plugin's own log file).
- Complete: also make
resolve_log_path_forhonorMAGIC_CONTEXT_LOG_PATH(read the env var first, fall back to the tmp path) so the dashboard Logs tab reads the same file the plugin writes. If you'd rather not touch Rust, say so and I'll add that part.
Everything else looks good. Once it's rebased and the dashboard claim is either dropped or backed by the Rust read, I'll merge.
Need help on this PR? Tag
/codesmithwith what you need. Autofix is disabled.Summary by cubic
Allow overriding the Magic Context log file path via
MAGIC_CONTEXT_LOG_PATH. If unset or blank, it falls back to${TMPDIR}/<harness>/magic-context/magic-context.log(e.g.,opencodeorpi).packages/plugin:getMagicContextLogPathreadsMAGIC_CONTEXT_LOG_PATHand ignores blank values.README.md, dashboard README, and docs to document the new env var and fallback path.Written for commit 706d9cc. Summary will update on new commits.
Greptile Summary
This PR adds support for overriding the magic-context log file path via the
MAGIC_CONTEXT_LOG_PATHenvironment variable, with trimming to ignore blank/whitespace-only values and falling back to the existing per-harness temp-dir path when unset.getMagicContextLogPathindata-path.tsnow checksMAGIC_CONTEXT_LOG_PATHfirst, returning it (trimmed) if non-empty, otherwise falling back to the harness-specific path underos.tmpdir().before/afterEach.packages/docs/src/content/docs/reference/dashboard.mdomits the Pi-harness fallback subdirectory (pi/) that the other two docs include.Confidence Score: 4/5
Safe to merge; the implementation is minimal and correct, with good test coverage of the new env-var logic.
The two-line change is straightforward, tests exercise every branch, and env state is properly saved/restored. The only rough edges are a stale JSDoc that no longer accurately describes the harness-separation guarantee and a minor omission in one docs file — neither affects runtime behaviour.
packages/plugin/src/shared/data-path.ts — the JSDoc comment about harness-separated logs needs updating to reflect that MAGIC_CONTEXT_LOG_PATH bypasses that separation; packages/docs/src/content/docs/reference/dashboard.md — missing the Pi fallback path notation.
Important Files Changed
Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A["getMagicContextLogPath(harness)"] --> B{"MAGIC_CONTEXT_LOG_PATH set\nand non-blank?"} B -->|Yes| C["Return env var value\n(harness ignored)"] B -->|No| D["getMagicContextTempDir(harness)"] D --> E["path.join(os.tmpdir(), harness, 'magic-context')"] E --> F["Return harness-specific path\ne.g. /tmp/opencode/magic-context/magic-context.log"]%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%% flowchart TD A["getMagicContextLogPath(harness)"] --> B{"MAGIC_CONTEXT_LOG_PATH set\nand non-blank?"} B -->|Yes| C["Return env var value\n(harness ignored)"] B -->|No| D["getMagicContextTempDir(harness)"] D --> E["path.join(os.tmpdir(), harness, 'magic-context')"] E --> F["Return harness-specific path\ne.g. /tmp/opencode/magic-context/magic-context.log"]Comments Outside Diff (1)
packages/plugin/src/shared/data-path.ts, line 39-46 (link)MAGIC_CONTEXT_LOG_PATHis set. Both harnesses will resolve to the same file, interleaving their session traces. The comment should be updated to reflect the override, and users should be warned about this behaviour.Reviews (1): Last reviewed commit: "Override the default log file path by en..." | Re-trigger Greptile