@cortexkit/opencode-magic-context 0.21.8 → 0.22.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +124 -323
- package/dist/agents/magic-context-prompt.d.ts.map +1 -1
- package/dist/agents/permissions.d.ts +29 -14
- package/dist/agents/permissions.d.ts.map +1 -1
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/migrate-experimental.d.ts +29 -0
- package/dist/config/migrate-experimental.d.ts.map +1 -0
- package/dist/config/schema/agent-overrides.d.ts.map +1 -1
- package/dist/config/schema/magic-context.d.ts +95 -104
- package/dist/config/schema/magic-context.d.ts.map +1 -1
- package/dist/features/builtin-commands/commands.d.ts.map +1 -1
- package/dist/features/magic-context/compartment-embedding.d.ts +34 -0
- package/dist/features/magic-context/compartment-embedding.d.ts.map +1 -0
- package/dist/features/magic-context/compartment-events.d.ts +50 -0
- package/dist/features/magic-context/compartment-events.d.ts.map +1 -0
- package/dist/features/magic-context/compartment-storage.d.ts +22 -0
- package/dist/features/magic-context/compartment-storage.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/lease.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/queue.d.ts +13 -2
- package/dist/features/magic-context/dreamer/queue.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/runner.d.ts +11 -0
- package/dist/features/magic-context/dreamer/runner.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/task-prompts.d.ts +1 -1
- package/dist/features/magic-context/dreamer/task-prompts.d.ts.map +1 -1
- package/dist/features/magic-context/git-commits/git-log-reader.d.ts.map +1 -1
- package/dist/features/magic-context/key-files/identify-key-files.d.ts +1 -1
- package/dist/features/magic-context/key-files/identify-key-files.d.ts.map +1 -1
- package/dist/features/magic-context/key-files/project-key-files.d.ts.map +1 -1
- package/dist/features/magic-context/key-files/read-stats.d.ts +1 -1
- package/dist/features/magic-context/key-files/read-stats.d.ts.map +1 -1
- package/dist/features/magic-context/memory/constants.d.ts +4 -0
- package/dist/features/magic-context/memory/constants.d.ts.map +1 -1
- package/dist/features/magic-context/memory/embedding-identity.d.ts.map +1 -1
- package/dist/features/magic-context/memory/embedding-local.d.ts.map +1 -1
- package/dist/features/magic-context/memory/embedding-openai.d.ts +6 -0
- package/dist/features/magic-context/memory/embedding-openai.d.ts.map +1 -1
- package/dist/features/magic-context/memory/embedding-probe.d.ts +5 -0
- package/dist/features/magic-context/memory/embedding-probe.d.ts.map +1 -1
- package/dist/features/magic-context/memory/embedding.d.ts.map +1 -1
- package/dist/features/magic-context/memory/index.d.ts +1 -1
- package/dist/features/magic-context/memory/index.d.ts.map +1 -1
- package/dist/features/magic-context/memory/memory-migration.d.ts +133 -0
- package/dist/features/magic-context/memory/memory-migration.d.ts.map +1 -0
- package/dist/features/magic-context/memory/project-identity.d.ts +38 -7
- package/dist/features/magic-context/memory/project-identity.d.ts.map +1 -1
- package/dist/features/magic-context/memory/storage-memory-fts.d.ts.map +1 -1
- package/dist/features/magic-context/memory/storage-memory.d.ts +15 -1
- package/dist/features/magic-context/memory/storage-memory.d.ts.map +1 -1
- package/dist/features/magic-context/memory/types.d.ts +3 -1
- package/dist/features/magic-context/memory/types.d.ts.map +1 -1
- package/dist/features/magic-context/message-index.d.ts.map +1 -1
- package/dist/features/magic-context/migrations.d.ts +7 -0
- package/dist/features/magic-context/migrations.d.ts.map +1 -1
- package/dist/features/magic-context/project-docs-hash.d.ts +6 -0
- package/dist/features/magic-context/project-docs-hash.d.ts.map +1 -0
- package/dist/features/magic-context/project-identity.d.ts +2 -0
- package/dist/features/magic-context/project-identity.d.ts.map +1 -0
- package/dist/features/magic-context/storage-db.d.ts +51 -7
- package/dist/features/magic-context/storage-db.d.ts.map +1 -1
- package/dist/features/magic-context/storage-historian-runs.d.ts +73 -0
- package/dist/features/magic-context/storage-historian-runs.d.ts.map +1 -0
- package/dist/features/magic-context/storage-identity-rekey-map.d.ts +11 -0
- package/dist/features/magic-context/storage-identity-rekey-map.d.ts.map +1 -0
- package/dist/features/magic-context/storage-m0-mutation-log.d.ts +22 -0
- package/dist/features/magic-context/storage-m0-mutation-log.d.ts.map +1 -0
- package/dist/features/magic-context/storage-memory-mutation-log.d.ts +25 -0
- package/dist/features/magic-context/storage-memory-mutation-log.d.ts.map +1 -0
- package/dist/features/magic-context/storage-meta-persisted.d.ts.map +1 -1
- package/dist/features/magic-context/storage-meta-session.d.ts.map +1 -1
- package/dist/features/magic-context/storage-meta-shared.d.ts +44 -0
- package/dist/features/magic-context/storage-meta-shared.d.ts.map +1 -1
- package/dist/features/magic-context/storage-meta.d.ts +1 -0
- package/dist/features/magic-context/storage-meta.d.ts.map +1 -1
- package/dist/features/magic-context/storage-project-state.d.ts +19 -0
- package/dist/features/magic-context/storage-project-state.d.ts.map +1 -0
- package/dist/features/magic-context/storage-subagent-invocations.d.ts +9 -0
- package/dist/features/magic-context/storage-subagent-invocations.d.ts.map +1 -1
- package/dist/features/magic-context/storage-tags.d.ts +21 -1
- package/dist/features/magic-context/storage-tags.d.ts.map +1 -1
- package/dist/features/magic-context/storage-v22-backfill-failures.d.ts +24 -0
- package/dist/features/magic-context/storage-v22-backfill-failures.d.ts.map +1 -0
- package/dist/features/magic-context/storage.d.ts +12 -3
- package/dist/features/magic-context/storage.d.ts.map +1 -1
- package/dist/features/magic-context/subagent-token-capture.d.ts +1 -1
- package/dist/features/magic-context/subagent-token-capture.d.ts.map +1 -1
- package/dist/features/magic-context/tagger.d.ts +15 -1
- package/dist/features/magic-context/tagger.d.ts.map +1 -1
- package/dist/features/magic-context/types.d.ts +21 -0
- package/dist/features/magic-context/types.d.ts.map +1 -1
- package/dist/features/magic-context/user-memory/review-user-memories.d.ts.map +1 -1
- package/dist/features/magic-context/user-memory/storage-user-memory.d.ts.map +1 -1
- package/dist/features/magic-context/v22-deferred-backfill.d.ts +46 -0
- package/dist/features/magic-context/v22-deferred-backfill.d.ts.map +1 -0
- package/dist/features/magic-context/work-metrics.d.ts +66 -0
- package/dist/features/magic-context/work-metrics.d.ts.map +1 -1
- package/dist/hooks/auto-update-checker/cache.d.ts.map +1 -1
- package/dist/hooks/auto-update-checker/checker.d.ts.map +1 -1
- package/dist/hooks/magic-context/cache-busting-signals.d.ts +9 -0
- package/dist/hooks/magic-context/cache-busting-signals.d.ts.map +1 -1
- package/dist/hooks/magic-context/command-handler.d.ts +13 -1
- package/dist/hooks/magic-context/command-handler.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-parser.d.ts +25 -0
- package/dist/hooks/magic-context/compartment-parser.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-prompt.d.ts +27 -16
- package/dist/hooks/magic-context/compartment-prompt.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner-incremental.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner-mapping.d.ts +6 -2
- package/dist/hooks/magic-context/compartment-runner-mapping.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner-partial-recomp.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner-recomp.d.ts +9 -1
- package/dist/hooks/magic-context/compartment-runner-recomp.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner-types.d.ts +67 -4
- package/dist/hooks/magic-context/compartment-runner-types.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner-validation.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner.d.ts.map +1 -1
- package/dist/hooks/magic-context/decay-curve.d.ts +78 -0
- package/dist/hooks/magic-context/decay-curve.d.ts.map +1 -0
- package/dist/hooks/magic-context/decay-render.d.ts +67 -0
- package/dist/hooks/magic-context/decay-render.d.ts.map +1 -0
- package/dist/hooks/magic-context/event-handler.d.ts +1 -1
- package/dist/hooks/magic-context/event-handler.d.ts.map +1 -1
- package/dist/hooks/magic-context/event-resolvers.d.ts +17 -0
- package/dist/hooks/magic-context/event-resolvers.d.ts.map +1 -1
- package/dist/hooks/magic-context/execute-status.d.ts.map +1 -1
- package/dist/hooks/magic-context/historian-prompt.generated.d.ts +2 -0
- package/dist/hooks/magic-context/historian-prompt.generated.d.ts.map +1 -0
- package/dist/hooks/magic-context/hook-handlers.d.ts +3 -0
- package/dist/hooks/magic-context/hook-handlers.d.ts.map +1 -1
- package/dist/hooks/magic-context/hook.d.ts +9 -21
- package/dist/hooks/magic-context/hook.d.ts.map +1 -1
- package/dist/hooks/magic-context/inject-compartments.d.ts +126 -0
- package/dist/hooks/magic-context/inject-compartments.d.ts.map +1 -1
- package/dist/hooks/magic-context/key-files-block.d.ts.map +1 -1
- package/dist/hooks/magic-context/live-session-state.d.ts +9 -0
- package/dist/hooks/magic-context/live-session-state.d.ts.map +1 -1
- package/dist/hooks/magic-context/m0-token-breakdown.d.ts +35 -0
- package/dist/hooks/magic-context/m0-token-breakdown.d.ts.map +1 -0
- package/dist/hooks/magic-context/read-session-chunk.d.ts +9 -0
- package/dist/hooks/magic-context/read-session-chunk.d.ts.map +1 -1
- package/dist/hooks/magic-context/read-session-db.d.ts +7 -0
- package/dist/hooks/magic-context/read-session-db.d.ts.map +1 -1
- package/dist/hooks/magic-context/recomp-orchestrator.d.ts +104 -0
- package/dist/hooks/magic-context/recomp-orchestrator.d.ts.map +1 -0
- package/dist/hooks/magic-context/reference-retrieval.d.ts +61 -0
- package/dist/hooks/magic-context/reference-retrieval.d.ts.map +1 -0
- package/dist/hooks/magic-context/reference-seeds.generated.d.ts +8 -0
- package/dist/hooks/magic-context/reference-seeds.generated.d.ts.map +1 -0
- package/dist/hooks/magic-context/send-session-notification.d.ts +1 -1
- package/dist/hooks/magic-context/send-session-notification.d.ts.map +1 -1
- package/dist/hooks/magic-context/system-prompt-hash.d.ts +5 -6
- package/dist/hooks/magic-context/system-prompt-hash.d.ts.map +1 -1
- package/dist/hooks/magic-context/tag-messages.d.ts.map +1 -1
- package/dist/hooks/magic-context/tokenizer-calibration.d.ts +6 -0
- package/dist/hooks/magic-context/tokenizer-calibration.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform-compartment-phase.d.ts +0 -7
- package/dist/hooks/magic-context/transform-compartment-phase.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform-postprocess-phase.d.ts +18 -0
- package/dist/hooks/magic-context/transform-postprocess-phase.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform.d.ts +9 -7
- package/dist/hooks/magic-context/transform.d.ts.map +1 -1
- package/dist/hooks/magic-context/upgrade-reminder.d.ts +73 -0
- package/dist/hooks/magic-context/upgrade-reminder.d.ts.map +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9435 -4001
- package/dist/plugin/conflict-warning-hook.d.ts +13 -0
- package/dist/plugin/conflict-warning-hook.d.ts.map +1 -1
- package/dist/plugin/dream-timer.d.ts.map +1 -1
- package/dist/plugin/event.d.ts +10 -0
- package/dist/plugin/event.d.ts.map +1 -1
- package/dist/plugin/hooks/create-session-hooks.d.ts.map +1 -1
- package/dist/plugin/messages-transform.d.ts.map +1 -1
- package/dist/plugin/rpc-handlers.d.ts.map +1 -1
- package/dist/plugin/tool-registry.d.ts.map +1 -1
- package/dist/shared/announcement.d.ts +17 -1
- package/dist/shared/announcement.d.ts.map +1 -1
- package/dist/shared/models-dev-cache.d.ts.map +1 -1
- package/dist/shared/rpc-client.d.ts +1 -0
- package/dist/shared/rpc-client.d.ts.map +1 -1
- package/dist/shared/rpc-notifications.d.ts +27 -5
- package/dist/shared/rpc-notifications.d.ts.map +1 -1
- package/dist/shared/rpc-server.d.ts +1 -0
- package/dist/shared/rpc-server.d.ts.map +1 -1
- package/dist/shared/rpc-types.d.ts +30 -2
- package/dist/shared/rpc-types.d.ts.map +1 -1
- package/dist/shared/rpc-utils.d.ts +9 -0
- package/dist/shared/rpc-utils.d.ts.map +1 -1
- package/dist/shared/sqlite-helpers.d.ts +7 -7
- package/dist/shared/sqlite.d.ts +23 -14
- package/dist/shared/sqlite.d.ts.map +1 -1
- package/dist/shared/tag-transcript.d.ts +10 -1
- package/dist/shared/tag-transcript.d.ts.map +1 -1
- package/dist/tools/ctx-expand/tools.d.ts +5 -1
- package/dist/tools/ctx-expand/tools.d.ts.map +1 -1
- package/dist/tools/ctx-memory/tools.d.ts.map +1 -1
- package/dist/tui/data/context-db.d.ts +16 -1
- package/dist/tui/data/context-db.d.ts.map +1 -1
- package/package.json +5 -7
- package/src/shared/announcement.test.ts +23 -7
- package/src/shared/announcement.ts +30 -8
- package/src/shared/conflict-detector.test.ts +15 -2
- package/src/shared/conflict-fixer.test.ts +5 -1
- package/src/shared/models-dev-cache.test.ts +72 -4
- package/src/shared/models-dev-cache.ts +47 -8
- package/src/shared/opencode-compaction-detector.test.ts +10 -2
- package/src/shared/rpc-client.test.ts +54 -3
- package/src/shared/rpc-client.ts +19 -9
- package/src/shared/rpc-notifications.test.ts +54 -1
- package/src/shared/rpc-notifications.ts +82 -13
- package/src/shared/rpc-server.ts +33 -4
- package/src/shared/rpc-types.ts +30 -2
- package/src/shared/rpc-utils.ts +10 -0
- package/src/shared/sqlite-helpers.ts +9 -9
- package/src/shared/sqlite.ts +99 -80
- package/src/shared/tag-transcript.test.ts +280 -0
- package/src/shared/tag-transcript.ts +162 -33
- package/src/tui/data/context-db.ts +75 -11
- package/src/tui/index.tsx +223 -32
- package/src/tui/slots/sidebar-content.tsx +366 -34
- package/dist/hooks/magic-context/compartment-runner-compressor.d.ts +0 -87
- package/dist/hooks/magic-context/compartment-runner-compressor.d.ts.map +0 -1
- package/dist/shared/native-binding.d.ts +0 -87
- package/dist/shared/native-binding.d.ts.map +0 -1
- package/src/shared/native-binding.ts +0 -311
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
<h1 align="center">Magic Context</h1>
|
|
2
2
|
|
|
3
3
|
<p align="center">
|
|
4
|
-
<strong>
|
|
5
|
-
|
|
4
|
+
<strong>Unbounded context. Memory that manages itself. One session, for life.</strong><br>
|
|
5
|
+
The hippocampus for coding agents, part of CortexKit.
|
|
6
6
|
</p>
|
|
7
7
|
|
|
8
8
|
<p align="center">
|
|
@@ -11,26 +11,21 @@
|
|
|
11
11
|
<a href="https://www.npmjs.com/package/@cortexkit/pi-magic-context"><img src="https://img.shields.io/npm/v/@cortexkit/pi-magic-context?label=pi&color=purple&style=flat-square" alt="npm @cortexkit/pi-magic-context"></a>
|
|
12
12
|
<a href="https://discord.gg/DSa65w8wuf"><img src="https://img.shields.io/discord/1488852091056295957?style=flat-square&logo=discord&logoColor=white&label=Discord&color=5865F2" alt="Discord"></a>
|
|
13
13
|
<a href="https://github.com/cortexkit/magic-context/stargazers"><img src="https://img.shields.io/github/stars/cortexkit/magic-context?style=flat-square&color=yellow" alt="stars"></a>
|
|
14
|
-
<a href="https://github.com/cortexkit/magic-context/commits"><img src="https://img.shields.io/github/last-commit/cortexkit/magic-context?style=flat-square&color=green" alt="last commit"></a>
|
|
15
14
|
<a href="https://github.com/cortexkit/magic-context/blob/master/LICENSE"><img src="https://img.shields.io/badge/license-MIT-green?style=flat-square" alt="MIT License"></a>
|
|
16
15
|
</p>
|
|
17
16
|
|
|
18
17
|
<p align="center">
|
|
19
|
-
|
|
18
|
+
<em>You don't hire a developer for one task and fire them when they ship.<br>Stop doing it to your agent.</em>
|
|
20
19
|
</p>
|
|
21
20
|
|
|
22
21
|
<p align="center">
|
|
23
|
-
<img src="https://raw.githubusercontent.com/cortexkit/magic-context/master/packages/plugin/docs/animation/out/optimized2.gif" alt="Magic Context in action" width="720">
|
|
24
|
-
</p>
|
|
25
|
-
|
|
26
|
-
<p align="center">
|
|
27
|
-
<a href="#get-started">Get Started</a> ·
|
|
28
22
|
<a href="#what-is-magic-context">What is Magic Context?</a> ·
|
|
29
|
-
<a href="#
|
|
30
|
-
<a href="#
|
|
31
|
-
<a href="
|
|
32
|
-
<a href="
|
|
33
|
-
<a href="
|
|
23
|
+
<a href="#quick-start">Quick Start</a> ·
|
|
24
|
+
<a href="#part-of-cortexkit">CortexKit</a> ·
|
|
25
|
+
<a href="#-context-management">Context</a> ·
|
|
26
|
+
<a href="#-capture">Capture</a> ·
|
|
27
|
+
<a href="#-consolidate">Consolidate</a> ·
|
|
28
|
+
<a href="#-recall">Recall</a> ·
|
|
34
29
|
<a href="https://discord.gg/DSa65w8wuf">💬 Discord</a>
|
|
35
30
|
</p>
|
|
36
31
|
|
|
@@ -38,53 +33,25 @@
|
|
|
38
33
|
|
|
39
34
|
## What is Magic Context?
|
|
40
35
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
**1.** Transparent context compaction via a **background historian** — the main agent keeps working while a separate model compresses older conversation. All operations are **cache-aware** and deferred to avoid wasting cached prefixes.
|
|
44
|
-
|
|
45
|
-
**2.** **Cross-session project memory** — architecture decisions, constraints, and preferences persist across conversations.
|
|
46
|
-
|
|
47
|
-
**3.** Overnight dreamer agent that consolidates, deduplicates, and promotes memories into canonical facts, plus maintains codebase documentation.
|
|
48
|
-
|
|
49
|
-
**4.** On-demand sidekick that augments prompts with relevant project context.
|
|
50
|
-
|
|
51
|
-
**5.** TUI sidebar with live context breakdown, token usage, historian status, and memory counts — right inside the terminal.
|
|
52
|
-
|
|
53
|
-
## Best way to use Magic Context?
|
|
54
|
-
|
|
55
|
-
Keep using the **same session** for **weeks**, **months**, or even **years**. **One session** per **project**!
|
|
56
|
-
|
|
57
|
-
---
|
|
58
|
-
|
|
59
|
-
### ✨ Recent Highlights
|
|
60
|
-
|
|
61
|
-
**Subagents now self-manage context (v0.15)** — subagent sessions now run age-based tool drops, reasoning clearing, and structural stripping at the execute threshold — the same way primary sessions with `ctx_reduce_enabled: false` behave. Previously they had no automatic reduction and grew silently until overflow. Nudges, historian/compartment runs, and the `<session-history>` block remain primary-only — subagents stay lean and parent-driven.
|
|
36
|
+
You don't hire a developer to fix one bug and fire them the moment it ships. You keep the good ones. They learn the codebase, remember why decisions were made, and get sharper every week.
|
|
62
37
|
|
|
63
|
-
|
|
38
|
+
Coding agents work the opposite way. Every task is a fresh hire with no memory of your project, and at the end of each session you fire them and start from zero. Mid-task they even hit "compaction" pauses that break the flow and quietly drop what they knew. It is anterograde amnesia, the same thing that happens when the hippocampus is damaged.
|
|
64
39
|
|
|
65
|
-
|
|
40
|
+
Magic Context gives them one. It is the **hippocampus** for coding agents, the part of the brain that forms memories, consolidates them, and recalls them, entirely in the background. One session stops being a disposable contractor and becomes a long-term teammate who was there for the whole project:
|
|
66
41
|
|
|
67
|
-
|
|
42
|
+
- **Capture.** As the historian compresses your history, it lifts the durable knowledge (decisions, constraints, conventions) into project memory. You get a memory system for free, from work you are already doing.
|
|
43
|
+
- **Consolidate.** Overnight, a dreamer agent does what sleep does for you: it merges duplicates, verifies memories against the codebase, retires the stale, and promotes what recurs.
|
|
44
|
+
- **Recall.** The right memories surface automatically every turn, and the agent can search across memories, past conversations, and git history on demand. Across sessions, and across OpenCode and Pi.
|
|
68
45
|
|
|
69
|
-
|
|
46
|
+
Two promises: your agent **never stops to manage its context** (no compaction pauses, no broken flow) and it **never forgets**.
|
|
70
47
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
**Age-tier caveman text compression (v0.15)** — opt-in companion to `ctx_reduce_enabled: false`. Older user/assistant text parts are progressively compressed using deterministic [caveman rules](https://github.com/cortexkit/magic-context/blob/master/packages/plugin/src/hooks/magic-context/caveman.ts) — the oldest 20% go to ultra-compressed, next 20% to full, next 20% to lite, newest 40% untouched. Tier shifts always recompress from the pristine original, never from an already-cavemaned intermediate, so the result is stable across passes. Cache-safe by design. Enable with `experimental.caveman_text_compression: { enabled: true }`. Only active when `ctx_reduce_enabled: false`.
|
|
74
|
-
|
|
75
|
-
**Temporal Awareness** — gives the agent real-time perception. Each user message gets a small `<!-- +5m -->`/`<!-- +2h 15m -->`/`<!-- +3d 4h -->` gap marker showing time since the previous message, and every compartment in `<session-history>` carries `start-date`/`end-date` attributes. Lets the agent reason correctly about how long a build ran, when a decision was made, or how stale a prior session is. Cache-safe — markers derive from immutable timestamps. Enable with `experimental.temporal_awareness: true`.
|
|
76
|
-
|
|
77
|
-
**Git Commit Indexing** — indexes HEAD git commits (skipping merges) from the project and makes them searchable through `ctx_search`. Commits are embedded so semantic queries like "when did we change the auth pattern" or "why did we pick X over Y" surface the right work. HEAD-only, windowed to the last year by default, capped at 2000 commits per project with oldest evicted. Enable with `experimental.git_commit_indexing.enabled: true`.
|
|
78
|
-
|
|
79
|
-
**Auto Search Hints** — before each turn, Magic Context runs a background `ctx_search` on your prompt. When highly relevant content exists, a compact "vague recall" hint is appended to your message with caveman-compressed fragments of the top matches — like a human feeling they almost remember something and going to check their notes. The agent then decides whether to run `ctx_search` for the full content. Cache-safe, fires on top-score ≥ 0.55 by default. Enable with `experimental.auto_search.enabled: true`.
|
|
48
|
+
Run one session per project and keep it going for weeks, months, or years. It remembers everything you've built together.
|
|
80
49
|
|
|
81
50
|
---
|
|
82
51
|
|
|
83
|
-
##
|
|
52
|
+
## Quick start
|
|
84
53
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
Run the interactive setup wizard — it detects your models, configures everything, and handles compatibility:
|
|
54
|
+
Run the interactive setup wizard. It detects your models, configures everything, and handles compatibility.
|
|
88
55
|
|
|
89
56
|
**macOS / Linux:**
|
|
90
57
|
```bash
|
|
@@ -101,271 +68,132 @@ irm https://raw.githubusercontent.com/cortexkit/magic-context/master/scripts/ins
|
|
|
101
68
|
npx @cortexkit/magic-context@latest setup
|
|
102
69
|
```
|
|
103
70
|
|
|
104
|
-
The
|
|
105
|
-
|
|
106
|
-
The wizard will:
|
|
107
|
-
1. Detect installed harnesses and available models
|
|
108
|
-
2. Add the plugin and disable built-in compaction
|
|
109
|
-
3. Help you pick models for historian, dreamer, and sidekick
|
|
110
|
-
4. Handle oh-my-opencode compatibility if needed
|
|
71
|
+
The wizard auto-detects which harnesses you have (OpenCode, Pi, or both), adds the plugin, disables built-in compaction, helps you pick models for the historian, dreamer, and sidekick, and resolves conflicts with other context-management plugins. Target a specific harness with `--harness opencode` or `--harness pi`.
|
|
111
72
|
|
|
112
|
-
|
|
73
|
+
> **Why disable built-in compaction?** Magic Context manages context itself. The host's compaction would interfere with its cache-aware deferred operations and double-compress.
|
|
113
74
|
|
|
114
|
-
|
|
75
|
+
**Manual setup** (OpenCode): add the plugin and turn compaction off in `opencode.json`, then drop a `magic-context.jsonc` in your project root. See the [configuration reference](./CONFIGURATION.md).
|
|
115
76
|
|
|
116
77
|
```jsonc
|
|
117
78
|
{
|
|
118
79
|
"plugin": ["@cortexkit/opencode-magic-context"],
|
|
119
|
-
"compaction": {
|
|
120
|
-
"auto": false,
|
|
121
|
-
"prune": false
|
|
122
|
-
}
|
|
80
|
+
"compaction": { "auto": false, "prune": false }
|
|
123
81
|
}
|
|
124
82
|
```
|
|
125
83
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
Create `magic-context.jsonc` in your project root, `.opencode/`, or `~/.config/opencode/`:
|
|
84
|
+
**Pi (beta):** `npx @cortexkit/magic-context@latest setup --harness pi` (requires Pi `>= 0.74.0`). The Pi extension shares the same database as OpenCode; project memories and embeddings pool across both.
|
|
129
85
|
|
|
130
|
-
|
|
131
|
-
{
|
|
132
|
-
"$schema": "https://raw.githubusercontent.com/cortexkit/magic-context/master/assets/magic-context.schema.json",
|
|
133
|
-
"enabled": true,
|
|
134
|
-
|
|
135
|
-
// Which model the historian uses for background compression,
|
|
136
|
-
// Prefer providers that charge by request instead of tokens
|
|
137
|
-
"historian": {
|
|
138
|
-
"model": "github-copilot/gpt-5.4",
|
|
139
|
-
"fallback_models": ["opencode-go/glm-5"]
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
```
|
|
86
|
+
**Troubleshooting:** `npx @cortexkit/magic-context@latest doctor` auto-detects your harnesses, checks for conflicts (compaction, OMO hooks, DCP), verifies the plugin and TUI sidebar, runs an integrity check on the database, and fixes what it can. Add `--issue` to file a ready-to-submit bug report.
|
|
143
87
|
|
|
144
|
-
>
|
|
88
|
+
<details>
|
|
89
|
+
<summary><strong>Compatibility with other context-management plugins</strong></summary>
|
|
145
90
|
|
|
146
|
-
|
|
91
|
+
<br>
|
|
147
92
|
|
|
148
|
-
|
|
93
|
+
Magic Context owns context management end to end, so it **disables itself** if another plugin is already doing that job. Running two context managers at once would double-compress your history and thrash the prompt cache. On startup it checks for the following; setup and `doctor` help you resolve each, and until they're resolved Magic Context stays off (fail-safe) and tells you why:
|
|
149
94
|
|
|
150
|
-
|
|
95
|
+
- **OpenCode built-in compaction** (`compaction.auto` / `compaction.prune`) — Magic Context replaces it. Setup turns it off.
|
|
96
|
+
- **DCP** (`opencode-dcp`) — a separate context-pruning plugin. The two cannot run together; remove it from your `plugin` list.
|
|
97
|
+
- **oh-my-opencode (OMO)** — setup offers to disable the three hooks that overlap:
|
|
98
|
+
- `preemptive-compaction` — triggers compaction that conflicts with the historian.
|
|
99
|
+
- `context-window-monitor` — injects usage warnings that overlap with Magic Context's nudges.
|
|
100
|
+
- `anthropic-context-window-limit-recovery` — triggers emergency compaction that bypasses the historian.
|
|
151
101
|
|
|
152
|
-
|
|
153
|
-
{
|
|
154
|
-
"disabled_hooks": [
|
|
155
|
-
"context-window-monitor",
|
|
156
|
-
"preemptive-compaction",
|
|
157
|
-
"anthropic-context-window-limit-recovery"
|
|
158
|
-
]
|
|
159
|
-
}
|
|
160
|
-
```
|
|
102
|
+
Run `npx @cortexkit/magic-context@latest doctor` any time to re-check and auto-fix.
|
|
161
103
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
### Doctor (Troubleshooting)
|
|
165
|
-
|
|
166
|
-
Already installed but something isn't working? Run the doctor to check and auto-fix configuration issues:
|
|
167
|
-
|
|
168
|
-
```bash
|
|
169
|
-
npx @cortexkit/magic-context@latest doctor
|
|
170
|
-
```
|
|
171
|
-
|
|
172
|
-
Doctor auto-detects installed harnesses and runs the right checks for each. Pass `--harness opencode` or `--harness pi` to target a specific harness when you have both installed.
|
|
173
|
-
|
|
174
|
-
Doctor checks for conflicts (compaction, DCP, OMO hooks), ensures the TUI sidebar is configured (OpenCode), verifies the plugin is registered, validates the magic-context.jsonc, runs `PRAGMA integrity_check` on the shared SQLite DB, and checks the npm cache — fixing what it can automatically. The summary line reports `PASS X / WARN Y / FAIL Z` so you can scan results at a glance.
|
|
175
|
-
|
|
176
|
-
Use `--force` to force-clear the plugin cache even when versions match (fixes broken transitive dependencies):
|
|
177
|
-
|
|
178
|
-
```bash
|
|
179
|
-
npx @cortexkit/magic-context@latest doctor --force
|
|
180
|
-
```
|
|
181
|
-
|
|
182
|
-
Hit a real bug? Use `--issue` to collect environment, sanitized config, and the last 400 log lines into a ready-to-submit report. It can also open the issue directly via `gh` if you have it installed:
|
|
183
|
-
|
|
184
|
-
```bash
|
|
185
|
-
npx @cortexkit/magic-context@latest doctor --issue
|
|
186
|
-
```
|
|
104
|
+
</details>
|
|
187
105
|
|
|
188
106
|
---
|
|
189
107
|
|
|
190
|
-
##
|
|
191
|
-
|
|
192
|
-
Magic Context is also available as a [Pi](https://github.com/earendil-works/pi-mono) extension, sharing the **same SQLite database** as the OpenCode plugin. Project memories, embeddings, dreamer state, and key-file pins are pooled across both harnesses; per-session state (tags, compartments, facts, notes) stays harness-scoped.
|
|
108
|
+
## Part of CortexKit
|
|
193
109
|
|
|
194
|
-
|
|
110
|
+
A brain isn't one organ. Neither is a capable coding agent.
|
|
195
111
|
|
|
196
|
-
|
|
197
|
-
# Setup wizard for Pi (uses the same unified CLI as OpenCode)
|
|
198
|
-
npx @cortexkit/magic-context@latest setup --harness pi
|
|
199
|
-
```
|
|
112
|
+
**CortexKit** is a family of plugins, each modeled on a different region of the brain. Install one and your agent gets sharper. Install all three and it has a brain.
|
|
200
113
|
|
|
201
|
-
|
|
114
|
+
| Plugin | Region | What it does |
|
|
115
|
+
|---|---|---|
|
|
116
|
+
| **Magic Context** *(you are here)* | Hippocampus & medial temporal lobe | Self-managing context and long-term memory. Keeps sessions running with no compaction pauses while it forms, consolidates, and recalls project knowledge across them. |
|
|
117
|
+
| **[AFT](https://github.com/cortexkit/aft)** | Sensorimotor cortex | Perceives code structure and acts on it precisely. A proper IDE and OS for your agent. |
|
|
118
|
+
| **Alfonso** *(coming soon)* | Prefrontal cortex | Executive control. Plans, decomposes work, chooses agents and models, and decides when to ask, verify, and commit. |
|
|
202
119
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
```bash
|
|
206
|
-
npx @cortexkit/magic-context@latest doctor --harness pi
|
|
207
|
-
```
|
|
120
|
+
Magic Context is **1 of the 3 plugins you'll ever need.** It remembers; AFT perceives and acts; Alfonso decides. They share one CortexKit store, so memory pools across harnesses and tools.
|
|
208
121
|
|
|
209
122
|
---
|
|
210
123
|
|
|
211
|
-
##
|
|
212
|
-
|
|
213
|
-
Magic Context injects structured context automatically and gives the agent five tools.
|
|
214
|
-
|
|
215
|
-
### `ctx_reduce` — Shed weight
|
|
216
|
-
|
|
217
|
-
After tool-heavy turns (large grep results, file reads, bash output), the agent calls `ctx_reduce` to mark stale content for removal. Drops are queued — not applied immediately — until the cache expires or context pressure forces it.
|
|
218
|
-
|
|
219
|
-
```
|
|
220
|
-
ctx_reduce(drop="3-5,12") // Drop tags 3, 4, 5, and 12
|
|
221
|
-
```
|
|
222
|
-
|
|
223
|
-
Recent tags (last 20 by default) are protected. Drops targeting them stay queued until they age out.
|
|
224
|
-
|
|
225
|
-
### `ctx_expand` — Decompress history
|
|
226
|
-
|
|
227
|
-
When the agent needs to recall details from a compressed history range, it can expand specific compartment ranges back to the original conversation transcript.
|
|
228
|
-
|
|
229
|
-
```
|
|
230
|
-
ctx_expand(start=100, end=200) // Expand raw messages 100-200
|
|
231
|
-
```
|
|
232
|
-
|
|
233
|
-
Returns the same compact `U:`/`A:` transcript format the historian sees, capped at ~15K tokens per request. Use `start`/`end` from compartment attributes visible in `<session-history>`.
|
|
124
|
+
## ⚡ Context management
|
|
234
125
|
|
|
235
|
-
|
|
126
|
+
*An unbounded session that manages itself.* The context window fills up as you work, and the usual fix, compaction, stops the agent cold to re-read everything. Magic Context handles it continuously in the background, so the session just keeps going.
|
|
236
127
|
|
|
237
|
-
|
|
128
|
+
- **Historian compartmentalization**: a background historian compresses old raw history into **tiered compartments**, chronological summaries that stand in for older messages. Each carries an importance score, so the live window stays small without losing the thread. Summarizing doesn't need your primary's coding muscle, so you can run the historian on a cheap or even fully local model while your main agent stays top-tier.
|
|
129
|
+
- **Decay rendering**: compartments render at the right fidelity for the moment, by a deterministic, no-LLM rule that self-tunes to the model's context window. Old history fades gracefully instead of dropping off a cliff, and because it is deterministic, the same history always renders the same way.
|
|
130
|
+
- **The agent hints what to drop, or it doesn't**: with agent-driven reduction on, the agent calls `ctx_reduce` to mark stale tool outputs or long messages for removal. Drops are **queued and cache-aware**, applied only at cache-safe moments so reduction never thrashes the cache. Switch it off and the agent stays out of context management entirely: stale output is shed automatically by age, with optional caveman compression of the oldest text.
|
|
131
|
+
- **Cache-stable layout**: all of this is structured so background work never invalidates the cached prefix of your prompt. Your cache survives the whole session.
|
|
238
132
|
|
|
239
|
-
|
|
240
|
-
ctx_note(action="write", content="After this fix, check if the compressor budget formula is correct")
|
|
241
|
-
ctx_note(action="read")
|
|
242
|
-
```
|
|
243
|
-
|
|
244
|
-
Notes surface automatically at natural work boundaries: after commits, after historian runs, and after all todos complete.
|
|
245
|
-
|
|
246
|
-
**Smart notes** are project-scoped notes with an open-ended `surface_condition` that the dreamer evaluates nightly. When the condition is met, the note surfaces in the next session:
|
|
247
|
-
|
|
248
|
-
```
|
|
249
|
-
ctx_note(action="write", content="Implement X because Y", surface_condition="When PR #42 is merged in this repo")
|
|
250
|
-
ctx_note(action="dismiss", note_id=1)
|
|
251
|
-
```
|
|
133
|
+
The result: one session runs for months, with no compaction pauses and low cost on cache-priced providers. You can watch it happen in OpenCode's TUI, where a live sidebar shows the context breakdown by source, historian status, and memory counts, updating after every message.
|
|
252
134
|
|
|
253
|
-
|
|
135
|
+
> *Optional (off by default):* **caveman text compression** progressively compresses the oldest user and assistant text by a deterministic age-tiered rule, for sessions that run with agent-driven reduction off.
|
|
254
136
|
|
|
255
|
-
|
|
137
|
+
---
|
|
256
138
|
|
|
257
|
-
|
|
139
|
+
## 🧠 Capture
|
|
258
140
|
|
|
259
|
-
|
|
260
|
-
ctx_memory(action="write", category="ARCHITECTURE_DECISIONS", content="Event sourcing for orders.")
|
|
261
|
-
ctx_memory(action="delete", id=42)
|
|
262
|
-
```
|
|
141
|
+
*Memory, for free.* To compress your history, the historian has to read all of it. So in the same pass it lifts out the knowledge worth keeping forever, decisions, constraints, conventions, config values, and promotes it into **project memory**, categorized and carried into every future session. Your memory builds itself from the work you are already doing.
|
|
263
142
|
|
|
264
|
-
|
|
143
|
+
The agent can also record memories explicitly, though most are captured automatically for it:
|
|
265
144
|
|
|
266
|
-
|
|
145
|
+
- **`ctx_memory`**: write or delete cross-session knowledge directly, in a small category taxonomy (`PROJECT_RULES`, `ARCHITECTURE`, `CONSTRAINTS`, `CONFIG_VALUES`, `NAMING`).
|
|
267
146
|
|
|
268
147
|
```
|
|
269
|
-
|
|
148
|
+
ctx_memory(action="write", category="ARCHITECTURE", content="Event sourcing for orders.")
|
|
270
149
|
```
|
|
271
150
|
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
### Automatic context injection
|
|
275
|
-
|
|
276
|
-
Every turn, Magic Context injects a `<session-history>` block containing:
|
|
277
|
-
|
|
278
|
-
- **Project memories** — cross-session decisions, constraints, and preferences
|
|
279
|
-
- **Compartments** — structured summaries replacing older raw history
|
|
280
|
-
- **Session facts** — durable categorized facts from the current session
|
|
281
|
-
|
|
282
|
-
This block is stable between historian runs. Memory writes persist immediately for search but don't change the injected block until the next historian run — so writes never bust the cache mid-conversation.
|
|
151
|
+
> **Temporal awareness** *(on by default)* gives the agent a sense of time, with gap markers like `+2h 15m` between messages and dated compartments, so it can reason about how long ago something happened. Set `temporal_awareness: false` to turn it off.
|
|
283
152
|
|
|
284
153
|
---
|
|
285
154
|
|
|
286
|
-
##
|
|
287
|
-
|
|
288
|
-
### Tagging
|
|
289
|
-
|
|
290
|
-
Every message, tool output, and file attachment gets a monotonically increasing `§N§` tag. The agent sees these inline and uses them to reference specific content when calling `ctx_reduce`. Tags persist in the database and resume across restarts.
|
|
291
|
-
|
|
292
|
-
### Queued reductions
|
|
293
|
-
|
|
294
|
-
When the agent calls `ctx_reduce`, drops go into a pending queue — not applied immediately. Two conditions trigger execution:
|
|
295
|
-
|
|
296
|
-
- **Cache expired** — enough time has passed that the cached prefix is likely stale (configurable per model, default 5 minutes)
|
|
297
|
-
- **Threshold reached** — context usage hits `execute_threshold_percentage` (default 65%)
|
|
298
|
-
|
|
299
|
-
Between triggers, the conversation continues unchanged. The agent doesn't need to think about timing.
|
|
300
|
-
|
|
301
|
-
### Background historian
|
|
155
|
+
## 🌙 Consolidate
|
|
302
156
|
|
|
303
|
-
|
|
157
|
+
*What sleep does for memory.* An optional **dreamer** agent runs overnight to keep memory quality high, spinning up ephemeral child sessions for each task:
|
|
304
158
|
|
|
305
|
-
- **
|
|
306
|
-
- **
|
|
159
|
+
- **Consolidate**: merge semantically similar memories into canonical facts.
|
|
160
|
+
- **Verify**: check memories against the current codebase (paths, configs, patterns).
|
|
161
|
+
- **Archive stale**: retire memories about removed features or old paths.
|
|
162
|
+
- **Improve**: rewrite verbose memories into terse, operational form.
|
|
163
|
+
- **Maintain docs**: keep `ARCHITECTURE.md` and `STRUCTURE.md` current from codebase changes.
|
|
164
|
+
- **User memories**: promote recurring observations about how you work (communication style, review focus, working patterns) into a `<user-profile>` that travels with every session.
|
|
165
|
+
- **Smart notes**: evaluate deferred notes whose `surface_condition` has come true and surface the ready ones.
|
|
307
166
|
|
|
308
|
-
|
|
167
|
+
Because it runs during idle time, the dreamer pairs well with local models, even slow ones. Nobody is waiting. Trigger a run any time with `/ctx-dream`.
|
|
309
168
|
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
### Nudging
|
|
313
|
-
|
|
314
|
-
As context usage grows, Magic Context sends rolling reminders suggesting the agent reduce. Cadence tightens as usage approaches the threshold — from gentle reminders to urgent warnings. If the agent recently called `ctx_reduce`, reminders are suppressed. At 85% Magic Context force-materializes queued drops and emergency cleanup; at 95% it blocks the turn until background historian completes.
|
|
315
|
-
|
|
316
|
-
### Cross-session memory
|
|
317
|
-
|
|
318
|
-
After each historian run, qualifying facts are promoted to the persistent memory store. On every subsequent turn, active memories are injected in `<session-history>`. New sessions inherit all project memories from previous sessions.
|
|
319
|
-
|
|
320
|
-
Memories are searchable via `ctx_search` alongside session facts and raw conversation history, using semantic embeddings (local by default) with full-text search as fallback.
|
|
321
|
-
|
|
322
|
-
### Dreamer
|
|
323
|
-
|
|
324
|
-
An optional background agent that maintains memory quality overnight:
|
|
325
|
-
|
|
326
|
-
- **Consolidate** — merge semantically similar memories into canonical facts
|
|
327
|
-
- **Verify** — check memories against current codebase (configs, paths, code patterns)
|
|
328
|
-
- **Archive stale** — retire memories referencing removed features or old paths
|
|
329
|
-
- **Improve** — rewrite verbose memories into terse operational form
|
|
330
|
-
- **Maintain docs** — update ARCHITECTURE.md and STRUCTURE.md from codebase changes
|
|
331
|
-
- **Evaluate smart notes** — check pending smart note conditions and surface ready notes
|
|
332
|
-
- **Review user memories** — promote recurring user behavior observations to stable memories
|
|
333
|
-
|
|
334
|
-
The dreamer runs during a configurable schedule window and creates ephemeral OpenCode child sessions for each task. Since it runs during idle time (typically overnight), it works well with local models — even slower ones like `ollama/mlx-qwen3.5-27b-claude-4.6-opus-reasoning-distilled` are fine since there's no user waiting.
|
|
335
|
-
|
|
336
|
-
When dreamer is enabled, ARCHITECTURE.md and STRUCTURE.md are automatically injected into the agent's system prompt (configurable via `inject_docs`). Content is cached per-session and refreshed on cache-busting passes.
|
|
169
|
+
---
|
|
337
170
|
|
|
338
|
-
|
|
171
|
+
## 🔎 Recall
|
|
339
172
|
|
|
340
|
-
|
|
173
|
+
*The right memory at the right moment.* Every turn, active project memories and the compacted session history are injected automatically and cache-stably. On demand, the agent reaches for:
|
|
341
174
|
|
|
342
|
-
|
|
175
|
+
- **`ctx_search`**: one query across three layers at once: project **memories**, raw **conversation** history, and indexed **git commits**. Semantic embeddings with full-text fallback.
|
|
343
176
|
|
|
344
|
-
|
|
177
|
+
```
|
|
178
|
+
ctx_search(query="why did we pick event sourcing for orders")
|
|
179
|
+
```
|
|
345
180
|
|
|
346
|
-
|
|
181
|
+
- **`ctx_expand`**: pull a compressed history range back to the original `U:`/`A:` transcript when the agent needs the exact details.
|
|
182
|
+
- **`ctx_note`**: a scratchpad for deferred intentions. Notes resurface at natural boundaries (after commits, after historian runs, when todos finish). **Smart notes** carry an open-ended condition the dreamer watches for.
|
|
347
183
|
|
|
348
|
-
|
|
184
|
+
Recall works **across sessions** (a new session inherits everything) and **across harnesses** (write a memory in OpenCode, retrieve it in Pi).
|
|
349
185
|
|
|
350
|
-
|
|
351
|
-
- **Historian status** — idle, running, or compartment/fact counts
|
|
352
|
-
- **Memory counts** — total project memories and how many are injected
|
|
353
|
-
- **Dreamer status** — last run time
|
|
354
|
-
- **Queue status** — pending operations count
|
|
186
|
+
> **Auto search hints** *(on by default)* run a background `ctx_search` each turn and whisper a "vague recall" when something relevant exists — like almost remembering a note you took. It appends only compact fragments, never full content; set `memory.auto_search.enabled: false` to turn it off. **Git commit indexing** *(opt-in)* makes your project history semantically searchable as a fourth `ctx_search` source — enable with `memory.git_commit_indexing.enabled: true`.
|
|
355
187
|
|
|
356
|
-
|
|
188
|
+
### Agent tools at a glance
|
|
357
189
|
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
### Startup conflict detection
|
|
367
|
-
|
|
368
|
-
On startup, Magic Context checks for common configuration problems — OpenCode's built-in compaction being enabled, DCP plugin being active alongside Magic Context, or conflicting oh-my-openagent hooks. When conflicts are detected, it warns the active session with a fix suggestion pointing to `npx @cortexkit/magic-context@latest doctor`.
|
|
190
|
+
| Tool | Section | What it does |
|
|
191
|
+
|------|-------|-------------|
|
|
192
|
+
| `ctx_reduce` | Context | Queue stale tagged content for removal, cache-aware |
|
|
193
|
+
| `ctx_memory` | Capture | Write or delete durable cross-session memories |
|
|
194
|
+
| `ctx_search` | Recall | Search memories, conversation history, and git commits |
|
|
195
|
+
| `ctx_expand` | Recall | Decompress a history range back to the transcript |
|
|
196
|
+
| `ctx_note` | Recall | Deferred intentions and dreamer-evaluated smart notes |
|
|
369
197
|
|
|
370
198
|
---
|
|
371
199
|
|
|
@@ -373,37 +201,37 @@ On startup, Magic Context checks for common configuration problems — OpenCode'
|
|
|
373
201
|
|
|
374
202
|
| Command | Description |
|
|
375
203
|
|---------|-------------|
|
|
376
|
-
| `/ctx-status` | Debug view: tags, pending drops, cache TTL, nudge state, historian progress, compartment coverage, history
|
|
204
|
+
| `/ctx-status` | Debug view: tags, pending drops, cache TTL, nudge state, historian progress, compartment coverage, history budget |
|
|
377
205
|
| `/ctx-flush` | Force all queued operations immediately, bypassing cache TTL |
|
|
378
|
-
| `/ctx-recomp` | Rebuild compartments
|
|
379
|
-
| `/ctx-
|
|
380
|
-
| `/ctx-
|
|
206
|
+
| `/ctx-recomp` | Rebuild compartments from raw history (accepts a `start-end` range). Use when stored state seems wrong |
|
|
207
|
+
| `/ctx-session-upgrade` | Upgrade this session to the latest history format: rebuild compartments and migrate project memories |
|
|
208
|
+
| `/ctx-aug` | Run sidekick augmentation on a prompt: retrieve relevant memories via a separate model |
|
|
209
|
+
| `/ctx-dream` | Run dreamer maintenance on demand: consolidate, verify, archive, improve |
|
|
381
210
|
|
|
382
211
|
---
|
|
383
212
|
|
|
384
|
-
##
|
|
213
|
+
## Desktop app
|
|
385
214
|
|
|
386
|
-
A companion desktop app for browsing and managing Magic Context state outside
|
|
215
|
+
A companion desktop app for browsing and managing Magic Context state outside the terminal.
|
|
387
216
|
|
|
388
217
|
<p align="center">
|
|
389
|
-
|
|
218
|
+
<a href="https://github.com/cortexkit/magic-context/releases"><strong>⬇️ Download for macOS · Windows · Linux</strong></a>
|
|
219
|
+
</p>
|
|
390
220
|
|
|
391
|
-
**
|
|
392
|
-
- **
|
|
393
|
-
- **
|
|
394
|
-
- **
|
|
395
|
-
- **
|
|
396
|
-
- **
|
|
397
|
-
- **Log Viewer** — live-tailing log viewer with search
|
|
398
|
-
- **System Tray** — quick access to dreamer status and controls
|
|
221
|
+
- **Memory browser**: search, filter, and edit project memories by category and project.
|
|
222
|
+
- **Session history**: browse compartments and notes for any session with timeline navigation.
|
|
223
|
+
- **Cache diagnostics**: real-time cache hit/miss timeline and bust-cause detection.
|
|
224
|
+
- **Dreamer management**: view dream-run history, trigger runs, inspect task results.
|
|
225
|
+
- **Configuration editor**: form-based editing for every setting, including model fallback chains.
|
|
226
|
+
- **Log viewer**: live-tailing logs with search.
|
|
399
227
|
|
|
400
|
-
|
|
228
|
+
It reads directly from Magic Context's SQLite database. No extra server, no API. Auto-updates built in.
|
|
401
229
|
|
|
402
230
|
---
|
|
403
231
|
|
|
404
232
|
## Configuration
|
|
405
233
|
|
|
406
|
-
|
|
234
|
+
Settings live in `magic-context.jsonc`. Everything has sensible defaults; project config merges on top of user-wide settings. See **[CONFIGURATION.md](./CONFIGURATION.md)** for the full reference: cache TTL tuning, per-model execute thresholds, historian and dreamer model selection, embedding providers, and memory settings.
|
|
407
235
|
|
|
408
236
|
**Config locations** (merged in order, project overrides user):
|
|
409
237
|
1. `<project-root>/magic-context.jsonc`
|
|
@@ -414,33 +242,17 @@ All settings live in `magic-context.jsonc` as flat top-level keys. See **[CONFIG
|
|
|
414
242
|
|
|
415
243
|
## Storage
|
|
416
244
|
|
|
417
|
-
All durable
|
|
245
|
+
All durable state lives in a local SQLite database under the shared CortexKit store (`~/.local/share/cortexkit/magic-context/context.db`, XDG-equivalent on Windows; legacy OpenCode-folder databases are migrated forward on first boot). If the database can't be opened, Magic Context disables itself and notifies you. Memories are keyed to a **stable project identity** derived from the repo, so they follow a project across worktrees, clones, and forks rather than being tied to a directory path.
|
|
418
246
|
|
|
419
|
-
|
|
420
|
-
~/.local/share/opencode/storage/plugin/magic-context/context.db
|
|
421
|
-
```
|
|
247
|
+
Magic Context also writes to a few other locations:
|
|
422
248
|
|
|
423
|
-
|
|
|
424
|
-
|
|
425
|
-
| `
|
|
426
|
-
| `
|
|
427
|
-
| `
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
| `notes` | Unified session notes and project-scoped smart notes |
|
|
431
|
-
| `session_meta` | Per-session state — usage, nudge flags, anchors |
|
|
432
|
-
| `memories` | Cross-session persistent memories |
|
|
433
|
-
| `memory_embeddings` | Embedding vectors for semantic search |
|
|
434
|
-
| `dream_state` | Dreamer lease locking and task progress |
|
|
435
|
-
| `dream_queue` | Queued projects awaiting dream processing |
|
|
436
|
-
| `dream_runs` | Per-project dream run history — task names, durations, memory changes |
|
|
437
|
-
| `compression_depth` | Per-message compression depth for weighted compressor selection |
|
|
438
|
-
| `message_history_fts` | FTS5 index of user/assistant message text for `ctx_search` |
|
|
439
|
-
| `message_history_index` | Tracks last indexed ordinal per session for incremental FTS population |
|
|
440
|
-
| `recomp_compartments` | Staging for `/ctx-recomp` partial progress |
|
|
441
|
-
| `recomp_facts` | Staging for `/ctx-recomp` partial progress |
|
|
442
|
-
| `user_memory_candidates` | User behavior observations from historian (experimental) |
|
|
443
|
-
| `user_memories` | Promoted stable user memories injected into all sessions (experimental) |
|
|
249
|
+
| Path | What | Persistence |
|
|
250
|
+
|---|---|---|
|
|
251
|
+
| `~/.local/share/cortexkit/magic-context/context.db` | SQLite database — tags, compartments, memories, all durable state (XDG-equivalent on Windows) | **Must persist.** Losing it loses your memory/history. |
|
|
252
|
+
| `~/.local/share/cortexkit/magic-context/models/` | Local embedding model cache (~90 MB `Xenova/all-MiniLM-L6-v2` ONNX), downloaded on first use when local embeddings are enabled | Should persist, else re-downloaded each run. Not used when `memory.enabled: false` or an `openai_compatible`/`ollama` embedding backend is configured. |
|
|
253
|
+
| `${TMPDIR}/opencode/magic-context/magic-context.log` (`pi/` for Pi) | Diagnostic log | Disposable. |
|
|
254
|
+
|
|
255
|
+
**Sandboxed / ephemeral environments (Docker, CI, disposable containers):** mount the `~/.local/share/cortexkit/magic-context/` directory on a persistent volume so the database and model cache survive between runs. If only the model cache is ephemeral, the model is simply re-downloaded; if the database is ephemeral, memory and history don't accumulate. To avoid the ~90 MB model download entirely, set `memory.enabled: false` or point `embedding` at a remote `openai_compatible`/`ollama` backend.
|
|
444
256
|
|
|
445
257
|
---
|
|
446
258
|
|
|
@@ -461,32 +273,21 @@ All durable states live in a local SQLite database. If the database can't be ope
|
|
|
461
273
|
**Requirements:** [Bun](https://bun.sh) ≥ 1.0
|
|
462
274
|
|
|
463
275
|
```sh
|
|
464
|
-
bun install
|
|
465
|
-
bun run build
|
|
466
|
-
bun run typecheck
|
|
467
|
-
bun test
|
|
468
|
-
bun run lint
|
|
469
|
-
bun run
|
|
470
|
-
bun run format # Format (Biome)
|
|
471
|
-
```
|
|
472
|
-
|
|
473
|
-
**Utility scripts:**
|
|
474
|
-
|
|
475
|
-
```sh
|
|
476
|
-
bun packages/plugin/scripts/tail-view.ts # Show post-compartment message tail
|
|
477
|
-
bun packages/plugin/scripts/context-dump/index.ts # Dump full context state for a session
|
|
478
|
-
bun packages/plugin/scripts/backfill-embeddings.ts # Backfill missing memory embeddings
|
|
276
|
+
bun install # Install dependencies
|
|
277
|
+
bun run build # Build the plugin
|
|
278
|
+
bun run typecheck # Type-check without emitting
|
|
279
|
+
bun test # Run tests
|
|
280
|
+
bun run lint # Lint (Biome)
|
|
281
|
+
bun run format # Format (Biome)
|
|
479
282
|
```
|
|
480
283
|
|
|
481
|
-
Dream execution requires a live OpenCode server
|
|
284
|
+
Dream execution requires a live OpenCode server (the dreamer creates ephemeral child sessions). Use `/ctx-dream` inside OpenCode for on-demand maintenance.
|
|
482
285
|
|
|
483
286
|
---
|
|
484
287
|
|
|
485
288
|
## Contributing
|
|
486
289
|
|
|
487
|
-
Bug reports and pull requests are welcome. For larger changes, open an issue first to discuss the approach.
|
|
488
|
-
|
|
489
|
-
Run `bun run format` before submitting — CI rejects unformatted code.
|
|
290
|
+
Bug reports and pull requests are welcome. For larger changes, open an issue first to discuss the approach. Run `bun run format` before submitting; CI rejects unformatted code.
|
|
490
291
|
|
|
491
292
|
---
|
|
492
293
|
|