magic-context icon indicating copy to clipboard operation
magic-context copied to clipboard

Add option for the notification interval

Open kecsap opened this issue 6 months ago • 4 comments


Summary by cubic

Adds a configurable toast duration for Magic Context notifications across the TUI. The TUI loads it via RPC and uses a unified showToast; dream and status flows use the configured duration, with explicit 10s overrides for setup/restart.

  • New Features

    • Added toast_duration_ms to config/schema (1000–60000, default 5000ms); documented in CONFIGURATION.md and exposed in the Dashboard Config Editor.
    • New toast-duration RPC; the TUI fetches and caches it on startup and uses a unified showToast with per-toast overrides.
    • NotificationParams carries toastDurationMs; server notifications are queued via RPC and respect the duration. StatusDetail exposes toastDurationMs.
  • Bug Fixes

    • Preserved toast_duration_ms in the session hook config and threaded it through getLiveNotificationParams and command handlers so dream notifications use the configured duration instead of falling back to 5s; added regression test.

Written for commit cfc5a93ac1e6d89b9afb3333b1623baf04166d9f. Summary will update on new commits.

Review in cubic

Greptile Summary

This PR adds a configurable toast_duration_ms setting (1000–60000 ms, default 5000 ms) for Magic Context TUI notifications. The config is validated via Zod, exposed in the Dashboard Config Editor and CONFIGURATION.md, fetched by the TUI on startup via a new toast-duration RPC, and threaded through NotificationParams so server-side notifications (dream, recomp outcomes) respect the configured duration.

  • New RPC endpoint toast-duration lets the TUI fetch and cache toast_duration_ms on startup; a unified showToast helper uses the cached value with per-call override support (durationOverrideMs).
  • create-session-hooks.ts now passes toast_duration_ms into the magic-context hook config so /ctx-dream notifications use the configured duration instead of always falling back to 5 s; a regression test covers this.
  • Restart-required toasts correctly carry durationOverrideMs: 10_000, matching the intent called out in the previous review round.

Confidence Score: 4/5

Safe to merge after addressing the polling retry loop; all core notification paths behave correctly.

The 500 ms message poller fires refreshToastDurationMs() on every tick when the toast duration equals the default value. Because 5000 ms is both the configured default and the error-path fallback, this condition is permanently true for any user who has not overridden the setting — the overwhelming majority. Everything else in the PR (schema, RPC handler, dream notification threading, restart-toast overrides) is straightforward and correct.

packages/plugin/src/tui/index.tsx — the poller's retry guard at line 838

Important Files Changed

Filename Overview
packages/plugin/src/tui/index.tsx Adds showToast helper, loadToastDurationMs on startup, and unified duration; restart toasts correctly carry durationOverrideMs: 10_000 — but the poller's retry guard fires every 500ms for default-config users
packages/plugin/src/plugin/rpc-handlers.ts Adds toast-duration RPC handler and populates StatusDetail.toastDurationMs; the toastDurationMs field on StatusDetail is computed and transported but never read by any TUI consumer
packages/plugin/src/hooks/magic-context/command-handler.ts Adds toastDurationMs to executeDreaming deps and dreamNotificationParams; correctly threads config value from createMagicContextCommandHandler
packages/plugin/src/plugin/hooks/create-session-hooks.ts Threads toast_duration_ms from pluginConfig into the magic-context hook config; regression test added
packages/plugin/src/shared/rpc-types.ts Adds toastDurationMs field to StatusDetail type with correct documentation
packages/plugin/src/tui/data/context-db.ts Adds loadToastDurationMs() RPC helper; clean implementation with safe fallback

Reviews (9): Last reviewed commit: "fix: thread toast duration through sessi..." | Re-trigger Greptile

kecsap avatar May 22 '26 06:05 kecsap

Thanks for this @kecsap — the implementation is clean and the feature is reasonable. Could you rebase onto current master? Two things have changed since you opened it that will conflict with our CI:

  1. Removed config keys. nudge_interval_tokens, auto_drop_tool_age, and drop_tool_structure were removed in the nudge redesign (v0.22.x). Your CONFIGURATION.md hunks add toast_duration_ms next to those now-deleted rows, and there's a removed-config-keys.test.ts guard that scans docs + schema and will fail on any reference to them. Please drop those neighboring lines when you rebase.

  2. Schema is now generated. assets/magic-context.schema.json is no longer hand-edited — it's generated from the Zod schema via bun packages/plugin/scripts/build-schema.ts. Your Zod change in magic-context.ts is the right source edit; just run the generator so the committed JSON stays in sync (there's a drift-guard test for this too).

Once rebased + schema regenerated and green, happy to merge. Appreciate the contribution.

alfonso-magic-context avatar Jun 08 '26 14:06 alfonso-magic-context

There were still problems with the dreamer notifications. It did not honor the new setting. Now, everything is addressed and fixed after rebasing.

kecsap avatar Jun 12 '26 12:06 kecsap

Thanks for this — toast_duration_ms is a clean, well-scoped addition and the wiring (schema → toast-duration RPC → TUI cache → unified showToast, plus the dashboard field and a regression test) looks right.

Two things before it can merge, both from the branch having been opened before our v0.23 nudge redesign:

  1. Rebase onto master and drop the deleted-key lines. Your CONFIGURATION.md hunk adds the toast_duration_ms row next to nudge_interval_tokens, auto_drop_tool_age, and drop_tool_structure — those three config keys were removed in v0.23.x. We have a guard test (removed-config-keys.test.ts) that scans the docs and schema and fails CI on any reference to them, so please remove those neighboring rows when you rebase.

  2. Generate the schema instead of hand-editing it. assets/magic-context.schema.json is now auto-generated from the Zod schema (there's a drift-guard test that fails if the committed file doesn't match the generator). So rather than editing the JSON directly, add the field to MagicContextConfigSchema in packages/plugin/src/config/schema/magic-context.ts with a .describe(...), then run bun packages/plugin/scripts/build-schema.ts to regenerate the asset.

After that, bun test in packages/plugin + bunx tsc should be green and we'll merge.

One non-blocking note for later: this is OpenCode-only — Pi delivers toasts via ctx.ui.notify, so full parity would want the duration honored there too. We can handle that as a follow-up; it doesn't hold up this PR.

alfonso-magic-context avatar Jun 14 '26 11:06 alfonso-magic-context

I rebased the commit. I think these two comments are not relevant anymore after the rebase.

kecsap avatar Jun 15 '26 11:06 kecsap

Merged to master (cherry-picked as 2981b810, your authorship preserved). Thank you — this is a genuinely useful knob and a few other users had asked for it.

Two follow-ups on top (commit 4e79d8f4):

  • toast_duration_ms: 0 now disables Magic Context toasts entirely (per a maintainer request) — the schema min is 0, and showToast skips when the effective duration is non-positive. Explicit positive per-call overrides (e.g. the restart-required toast) still show, so 0 silences routine notifications without hiding the critical ones.
  • Reworked the test: the module-level mock.module("../../hooks/magic-context") leaked process-globally under Bun (its mock.restore() doesn't undo mock.module) and broke 12 assertions in hook.test.ts when the full suite ran. I extracted a pure buildMagicContextHookConfig() and test that directly instead — same coverage of the toast-duration threading, no global-mock leak.

Closing as merged. Appreciate the contribution.

alfonso-magic-context avatar Jun 19 '26 10:06 alfonso-magic-context