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
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.
6481d38 to
31501a1
Compare
Let users redirect the diagnostic log away from the harness temp-dir default, which matters in sandboxed/ephemeral setups (Docker, CI) where TMPDIR is disposable or the plugin and dashboard need to agree on a shared path. The override is read at the single chokepoint getMagicContextLogPath (TS) and its Rust mirror resolve_log_path_for, so both the plugin logger and the dashboard log tail honor it; blank/whitespace is treated as unset. Docs updated in three places. Reimplemented from @kecsap's PR #183 onto current master (the PR branch predated the v0.30.2 WebSocket migration and carried a large stale revert). Co-authored-by: kecsap <kecsap@users.noreply.github.com>
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. Both the plugin and dashboard trim and ignore blank values, defaulting to${TMPDIR}/<harness>/magic-context/magic-context.log.New Features
packages/plugin:getMagicContextLogPathreads trimmedMAGIC_CONTEXT_LOG_PATHwith harness-temp fallback.packages/dashboard:resolve_log_path_formirrors the override; docs updated inREADME.md, dashboardREADME.md, and docs reference.Bug Fixes
packages/dashboard: Tests serialize env var mutations with aOnceLock<Mutex>to avoid parallel races; cover override, blank, and fallback.packages/plugin: Added tests for unset, override, and blank ingetMagicContextLogPath.Written for commit 2ae175f. Summary will update on new commits.
Greptile Summary
Adds
MAGIC_CONTEXT_LOG_PATHenvironment variable support to override the default per-harness log file path in both the TypeScript plugin and Rust dashboard; when unset or blank, both sides fall back to the existing${TMPDIR}/<harness>/magic-context/magic-context.loglayout.data-path.ts):getMagicContextLogPathnow reads, trims, and honorsMAGIC_CONTEXT_LOG_PATHbefore falling back to the harness-based temp path; three new tests cover unset, override, and blank-string cases.log_parser.rs):resolve_log_path_formirrors the same logic in Rust, with tests serialized via aOnceLock<Mutex<()>>guard to prevent env-mutation races.MAGIC_CONTEXT_LOG_PATHand its fallback behaviour.Confidence Score: 5/5
Safe to merge — the change is a small, well-tested additive feature with no modifications to existing logic.
Both the TypeScript and Rust implementations follow the same trim-and-fallback pattern, the env-mutation race condition raised in a prior review has been properly addressed with a shared mutex, and all three test suites cover the unset, override, and blank-whitespace cases. No existing call sites are affected.
No files require special attention.
Important Files Changed
Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A[Call getMagicContextLogPath / resolve_log_path_for] --> B{MAGIC_CONTEXT_LOG_PATH set?} B -- "Yes (non-blank after trim)" --> C[Return env var value as path] B -- "No / blank / whitespace-only" --> D{Which harness?} D -- opencode --> E["${TMPDIR}/opencode/magic-context/magic-context.log"] D -- pi --> F["${TMPDIR}/pi/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[Call getMagicContextLogPath / resolve_log_path_for] --> B{MAGIC_CONTEXT_LOG_PATH set?} B -- "Yes (non-blank after trim)" --> C[Return env var value as path] B -- "No / blank / whitespace-only" --> D{Which harness?} D -- opencode --> E["${TMPDIR}/opencode/magic-context/magic-context.log"] D -- pi --> F["${TMPDIR}/pi/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 (5): Last reviewed commit: "Override the default log file path by en..." | Re-trigger Greptile