@retaw106/mmc-pi 1.2.2 → 2.0.0
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 +49 -98
- package/dist/cli.js +7095 -0
- package/dist/config-init.js +5595 -0
- package/dist/{index-65ee50rm.js → index-dx9vhsy8.js} +3 -2
- package/dist/{index-ztb4k1mt.js → index-kxehmcmt.js} +4163 -3958
- package/dist/index.js +1847 -1812
- package/dist/{message-time-backfill-h02fzzp8.js → message-time-backfill-wnxmrd09.js} +1 -1
- package/dist/{read-session-chunk-af3sdznq.js → read-session-chunk-7m31yz4a.js} +1 -1
- package/dist/web/main.js +850 -150
- package/dist/web/ui/index.html +1 -0
- package/dist/web/ui/panel.css +5 -0
- package/dist/web/ui/panel.js +220 -70
- package/package.json +7 -2
package/README.md
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
# Magic Context — Pi
|
|
1
|
+
# Magic Context — Pi extension (mmc)
|
|
2
2
|
|
|
3
|
-
Cross-session memory and context management for [Pi coding agent](https://github.com/earendil-works/pi-mono)
|
|
3
|
+
Cross-session memory and context management for the [Pi coding agent](https://github.com/earendil-works/pi-mono). The extension shares its SQLite database with the OpenCode 2 plugin [`@retaw106/mmc-oc`](https://www.npmjs.com/package/@retaw106/mmc-oc).
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
This is the `moon-magic-context` fork of [magic-context](https://github.com/cortexkit/magic-context): the core transform pipeline, historian, and FTS5 memory retrieval only. The upstream embedding/semantic-search stack, dashboard, CLI, and OMP support are not part of this fork.
|
|
6
|
+
|
|
7
|
+
Requires `@earendil-works/pi-coding-agent` `>= 0.80.2`.
|
|
6
8
|
|
|
7
9
|
---
|
|
8
10
|
|
|
9
11
|
## What it does
|
|
10
12
|
|
|
11
|
-
Magic Context is a context engine that keeps long Pi sessions productive by:
|
|
12
|
-
|
|
13
13
|
| Feature | What it does |
|
|
14
14
|
|---|---|
|
|
15
15
|
| **Tagging + drops** | Tags every assistant/user/tool message with `§N§ ` so you can drop specific turns later via `mmc_reduce` |
|
|
16
16
|
| **Historian** | Background subagent compresses old conversation into compartments + facts at threshold pressure or commit boundaries |
|
|
17
|
-
|
|
|
18
|
-
| **Project memories** | Persistent cross-session knowledge store with
|
|
17
|
+
| **`m[0]`/`m[1]` history injection** | Renders compressed history and project memories into two synthetic leading messages every turn so the agent never loses context — without busting the provider's prompt cache on stable turns |
|
|
18
|
+
| **Project memories** | Persistent cross-session knowledge store with FTS5 full-text search |
|
|
19
19
|
| **Auto-search hint** | When user prompts mention previously-discussed topics, appends a compact memory hint |
|
|
20
20
|
| **Cross-harness sharing** | Memories written from OpenCode appear in Pi (and vice versa) for the same project |
|
|
21
21
|
|
|
@@ -23,90 +23,58 @@ Magic Context is a context engine that keeps long Pi sessions productive by:
|
|
|
23
23
|
|
|
24
24
|
## Installation
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
```bash
|
|
29
|
-
npx @retaw106/mmc-oc@latest setup --harness pi
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
This handles everything for you:
|
|
33
|
-
1. Adds `npm:@retaw106/mmc-pi` to Pi's `packages` array in `~/.pi/agent/settings.json` (the same place `pi install` writes to)
|
|
34
|
-
2. Creates `~/.pi/agent/mmc.jsonc` with defaults
|
|
35
|
-
3. Prompts you for historian and embedding model choices
|
|
36
|
-
4. Warns about provider-specific gotchas (e.g. GitHub Copilot reasoning models need an explicit `thinking_level`)
|
|
37
|
-
|
|
38
|
-
If you'd rather register the Pi extension package directly with Pi (skipping the wizard), use Pi's own installer:
|
|
26
|
+
Install the published package with Pi's own installer:
|
|
39
27
|
|
|
40
28
|
```bash
|
|
41
29
|
pi install npm:@retaw106/mmc-pi
|
|
42
30
|
```
|
|
43
31
|
|
|
44
|
-
This adds the extension to `~/.pi/agent/settings.json
|
|
45
|
-
|
|
46
|
-
To check installation health later:
|
|
47
|
-
|
|
48
|
-
```bash
|
|
49
|
-
npx @retaw106/mmc-oc@latest doctor --harness pi
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
### Oh My Pi (OMP)
|
|
53
|
-
|
|
54
|
-
Use the OMP-specific setup path. It installs the package through OMP's plugin manager, disables OMP native compaction and automatic memory to prevent duplicate context managers, and verifies the effective project plugin state:
|
|
55
|
-
|
|
56
|
-
```bash
|
|
57
|
-
npx @retaw106/mmc-oc@latest setup --harness omp
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
Manual installation is also supported:
|
|
61
|
-
|
|
62
|
-
```bash
|
|
63
|
-
omp plugin install @retaw106/mmc-pi
|
|
64
|
-
omp config set compaction.enabled false
|
|
65
|
-
omp config set memory.backend off
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
Verify with:
|
|
32
|
+
This adds the extension to `~/.pi/agent/settings.json`. Then create the config at `~/.pi/agent/mmc.jsonc` (see Configuration below) — hand-write it, or run the package's interactive `config-init` command (below). The historian model is required, or no summarization ever happens.
|
|
69
33
|
|
|
70
|
-
|
|
71
|
-
npx @retaw106/mmc-oc@latest doctor --harness omp
|
|
72
|
-
```
|
|
34
|
+
> 本 fork 没有上游的 `doctor` CLI(上游 `npx … setup` / `doctor` 在这里不存在)。mmc 各包自带 `config-init`(生成)与 `config-check`(只读自检)两个命令,随下一次发版以 npm bin 提供(当前 `latest` 尚未包含);命令不映射 `doctor`/`--force`,也不新增宿主命令(见 Configuration 节)。
|
|
73
35
|
|
|
74
|
-
|
|
36
|
+
To build from the monorepo instead (requires Bun `>= 1.4.0`): point Pi's `packages` array at `packages/pi-plugin` and run `bun run build` before starting Pi — the host loads the prebuilt `dist`.
|
|
75
37
|
|
|
76
38
|
---
|
|
77
39
|
|
|
78
40
|
## Configuration
|
|
79
41
|
|
|
80
|
-
|
|
42
|
+
mmc reads the Pi host's own config (project overrides user):
|
|
81
43
|
|
|
82
44
|
1. `$cwd/.mmc/mmc.jsonc`
|
|
83
45
|
2. `~/.pi/agent/mmc.jsonc`
|
|
84
46
|
|
|
85
|
-
Session discovery follows the active host. Relative `pi.subagent_extensions` are deliberately isolated by host: plain Pi resolves them from `~/.pi/agent`, while a positively identified OMP process uses `PI_CODING_AGENT_DIR` when set and otherwise derives the active `~/.omp` config/profile agent directory.
|
|
86
|
-
|
|
87
47
|
### Minimal config
|
|
88
48
|
|
|
89
49
|
```jsonc
|
|
90
50
|
{
|
|
91
|
-
"$schema": "https://raw.githubusercontent.com/cortexkit/magic-context/master/assets/magic-context.schema.json",
|
|
92
51
|
"enabled": true,
|
|
93
52
|
"historian": {
|
|
94
|
-
"
|
|
95
|
-
"model": "anthropic/claude-haiku-4-5"
|
|
96
|
-
},
|
|
97
|
-
"omp": {
|
|
98
|
-
"model": { "model": "opencode/claude-haiku-4-5", "thinking_level": "auto" }
|
|
99
|
-
}
|
|
100
|
-
},
|
|
101
|
-
"embedding": {
|
|
102
|
-
"provider": "local"
|
|
53
|
+
"model": "provider/your-model"
|
|
103
54
|
}
|
|
104
55
|
}
|
|
105
56
|
```
|
|
106
57
|
|
|
107
|
-
|
|
58
|
+
`historian.model` is required (no default) and takes a `provider/model` ID; optional `fallback_models`, and Pi reads `thinking_level` (OpenCode reads `variant`). Replace the placeholder with a model available in your host.
|
|
59
|
+
|
|
60
|
+
For the full configuration reference, see `docs/guides/配置说明.md` in the monorepo — OpenCode and Pi share the same schema (`assets/magic-context.schema.json`, regenerated by the plugin build).
|
|
61
|
+
|
|
62
|
+
### 生成与自检用户级配置(交互命令)
|
|
63
|
+
|
|
64
|
+
两包各带两个交互命令,**随下一次发版以 npm bin 提供**(当前 `latest` 尚未包含);以单一 bin 分发、按子命令分派,裸命令打印帮助、未知子命令被拒绝:
|
|
65
|
+
|
|
66
|
+
```sh
|
|
67
|
+
# Pi(本包)
|
|
68
|
+
npx @retaw106/mmc-pi@latest config-init # 生成首份用户级配置
|
|
69
|
+
npx @retaw106/mmc-pi@latest config-check # 只读自检(不写文件)
|
|
70
|
+
# OpenCode 2 侧的同一组命令在 @retaw106/mmc-oc 包内,用法相同
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
两个命令都**交互选择目标宿主**(OpenCode / Pi),只作用于所选宿主的**用户级**配置。`config-init` 按既有规则解析用户配置路径(Pi 固定 `~/.pi/agent/`),若目标已存在 `.jsonc`/`.json` 则提示退出、不改动已有文件。逐项询问语言、historian 主模型、`maintenance.enabled`、`compaction.enabled`、全局 `cache_ttl`、全局 `execute_threshold_percentage`:每项均可留空(不写入该项)。其中 historian 主模型留空即不配置历史摘要模型(摘要需之后配置模型才会启用);其余项留空沿用插件默认。只写显式设置项,产出带注释的精简 JSONC,预览确认后落盘;只涉及主模型,不含回退模型、reasoning、按模型映射或绝对 token 阈值。纯离线:不读凭据、不探测模型可调用性。`compaction.enabled=false` 只关闭 mmc 自身的上下文管理,**不会**自动启用宿主的原生压缩。
|
|
108
74
|
|
|
109
|
-
|
|
75
|
+
`config-check` 强制交互式终端;只读所选宿主的用户级配置,不读项目级配置、不检查安装或数据库、不写任何文件。它校验格式、字段值、`{env:VAR}`/`{file:path}` 外部引用与 `$schema`;未知字段**警告但不失败**;配置缺失视为正常(沿用默认值)。不可读、失效链接、语法错误、字段值错误或外部引用错误 → 退出码 1。退出码:`0`=无错误(可有警告),`1`=有错误或取消,`2`=非交互终端或用法错误。**不回显实际配置值。**
|
|
76
|
+
|
|
77
|
+
从本仓源码运行(备选):构建后直接以 Node 运行入口,例如 `node packages/pi-plugin/dist/config-init.js`。
|
|
110
78
|
|
|
111
79
|
---
|
|
112
80
|
|
|
@@ -125,42 +93,27 @@ All commands trigger `triggerTurn: false` (never sent to the LLM):
|
|
|
125
93
|
|
|
126
94
|
## Storage
|
|
127
95
|
|
|
128
|
-
|
|
96
|
+
mmc stores everything in a single shared SQLite database at:
|
|
129
97
|
|
|
130
98
|
```
|
|
131
99
|
~/.local/share/mmc/context.db
|
|
132
100
|
```
|
|
133
101
|
|
|
134
102
|
When a host isolates `XDG_DATA_HOME` per process, set
|
|
135
|
-
`MMC_STORAGE_DIR` to the absolute, complete shared
|
|
103
|
+
`MMC_STORAGE_DIR` to the absolute, complete shared mmc
|
|
136
104
|
storage directory. The explicit path takes precedence over the XDG-derived path
|
|
137
105
|
and does not change Pi's own configuration or session directories. The host must
|
|
138
|
-
propagate one identical value to every process that shares the database;
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
one directory still block migrations until all processes use a compatible build.
|
|
142
|
-
|
|
143
|
-
This is the **same database** the OpenCode plugin and OMP extension use. Tables are scoped by:
|
|
144
|
-
- `harness` column (`'pi'` or `'opencode'`) for session-scoped data; OMP intentionally uses `'pi'`
|
|
145
|
-
- `project_path` (resolved git root) for project-scoped data (memories, embeddings)
|
|
146
|
-
|
|
147
|
-
Memories are shared across all three harnesses for the same project; per-session tagging stays correctly attributed.
|
|
148
|
-
|
|
149
|
-
Storage failures are fatal — Magic Context will refuse to register hooks rather than run with ephemeral state, since that would let context grow unbounded across restarts.
|
|
150
|
-
|
|
151
|
-
---
|
|
106
|
+
propagate one identical value to every process that shares the database; mmc
|
|
107
|
+
never originates this variable from its default.
|
|
108
|
+
Mixed-version processes on one directory still block migrations until all processes use a compatible build.
|
|
152
109
|
|
|
153
|
-
|
|
110
|
+
This is the **same database** the OpenCode 2 plugin uses. Tables are scoped by:
|
|
111
|
+
- `harness` column (`'pi'` or `'opencode2'`; legacy rows may carry `'opencode'`) for session-scoped data
|
|
112
|
+
- `project_path` (resolved git root) for project-scoped data (memories)
|
|
154
113
|
|
|
155
|
-
|
|
114
|
+
Memories are shared across both harnesses for the same project; per-session tagging stays correctly attributed.
|
|
156
115
|
|
|
157
|
-
|
|
158
|
-
WARN embedding model mismatch detected for project ...:
|
|
159
|
-
stored vectors use "openai-compatible:Qwen/Qwen3-Embedding-8B" but Pi is configured with "local:Xenova/all-MiniLM-L6-v2".
|
|
160
|
-
Cross-harness search will return zero results until vectors are re-embedded.
|
|
161
|
-
```
|
|
162
|
-
|
|
163
|
-
Configure `embedding` once in the shared `~/.config/mmc/mmc.jsonc`; OpenCode, Pi, and OMP all read it. Use `$cwd/.mmc/mmc.jsonc` only when that project intentionally needs an override.
|
|
116
|
+
Storage failures are fatal — mmc will refuse to register hooks rather than run with ephemeral state, since that would let context grow unbounded across restarts.
|
|
164
117
|
|
|
165
118
|
---
|
|
166
119
|
|
|
@@ -174,29 +127,27 @@ Configure `embedding` once in the shared `~/.config/mmc/mmc.jsonc`; OpenCode, Pi
|
|
|
174
127
|
| `mmc_expand` | `start`/`end`, `message`, `verbose` | Recover complete messages or expand a compressed conversation range |
|
|
175
128
|
| `mmc_reduce` | `drop` | Queue tagged turns for cache-safe removal from the live context |
|
|
176
129
|
|
|
177
|
-
`mmc_note`, `mmc_expand`, and `mmc_reduce` are session-scoped and are exposed in primary Pi
|
|
130
|
+
`mmc_note`, `mmc_expand`, and `mmc_reduce` are session-scoped and are exposed in primary Pi sessions. mmc omits them from ephemeral `--no-session` child processes, where they would otherwise target the hidden child session; `mmc_reduce` is additionally omitted when compaction is disabled.
|
|
178
131
|
|
|
179
132
|
---
|
|
180
133
|
|
|
181
134
|
## Architecture & implementation
|
|
182
135
|
|
|
183
|
-
This package is part of the
|
|
136
|
+
This package is part of the moon-magic-context monorepo (`packages/pi-plugin`). Pi shares the adapter layer and core implementation with the OpenCode 2 plugin:
|
|
184
137
|
|
|
185
138
|
| Pi-specific module | Responsibility |
|
|
186
139
|
|---|---|
|
|
187
140
|
| `context-handler.ts` | Pi `pi.on("context", ...)` adapter — tags, drops, runs nudges and auto-search |
|
|
188
|
-
| `subagent-runner.ts` | Re-invokes the
|
|
141
|
+
| `subagent-runner.ts` | Re-invokes the Pi host with `--print --mode json --no-session` for hidden child sessions, with per-agent tool isolation |
|
|
189
142
|
| `tools/` | Pi `pi.registerTool` wrappers around the shared tool implementations |
|
|
190
143
|
| `commands/` | Pi `pi.registerCommand` wrappers for the four `/mmc-*` slash commands |
|
|
191
|
-
| `system-prompt.ts` | Pi `before_agent_start` injector for the `## Magic Context` guidance block and sticky date
|
|
192
|
-
| `config/` |
|
|
193
|
-
|
|
194
|
-
The unified [`@retaw106/mmc-oc`](https://www.npmjs.com/package/@retaw106%2Fmmc-oc) CLI exposes separate `pi` and `omp` setup/doctor pipelines while both use this runtime adapter.
|
|
144
|
+
| `system-prompt.ts` | Pi `before_agent_start` injector for the `## Magic Context` guidance block and sticky date |
|
|
145
|
+
| `config/` | Fork copy of the plugin config loader (divergences from the shared loader are registered in the monorepo root `UPSTREAM.md`) |
|
|
195
146
|
|
|
196
|
-
|
|
147
|
+
The OpenCode 2 plugin [`@retaw106/mmc-oc`](https://www.npmjs.com/package/@retaw106/mmc-oc) lives in the same monorepo (`packages/plugin`). For deeper architectural detail, see `ARCHITECTURE.md` in the monorepo root.
|
|
197
148
|
|
|
198
149
|
---
|
|
199
150
|
|
|
200
151
|
## License
|
|
201
152
|
|
|
202
|
-
MIT — see
|
|
153
|
+
MIT — see `LICENSE` in the monorepo root.
|