@cortexkit/opencode-magic-context 0.40.0 → 0.41.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.
Files changed (165) hide show
  1. package/README.md +1 -1
  2. package/dist/agents/permissions.d.ts +5 -3
  3. package/dist/agents/permissions.d.ts.map +1 -1
  4. package/dist/{announcement-5eg4t64s.js → announcement-3g9xg433.js} +2 -2
  5. package/dist/{conflict-warning-hook-f406ggbw.js → conflict-warning-hook-xj1r88a7.js} +4 -4
  6. package/dist/{derive-budgets-xk8cy5e6.js → derive-budgets-3xfyphvk.js} +3 -3
  7. package/dist/features/builtin-commands/commands.d.ts +35 -2
  8. package/dist/features/builtin-commands/commands.d.ts.map +1 -1
  9. package/dist/features/magic-context/context-authority.d.ts +10 -0
  10. package/dist/features/magic-context/context-authority.d.ts.map +1 -1
  11. package/dist/features/magic-context/dreamer/classify.d.ts +1 -0
  12. package/dist/features/magic-context/dreamer/classify.d.ts.map +1 -1
  13. package/dist/features/magic-context/dreamer/lease.d.ts +12 -27
  14. package/dist/features/magic-context/dreamer/lease.d.ts.map +1 -1
  15. package/dist/features/magic-context/dreamer/map-memories-prompt.d.ts +1 -1
  16. package/dist/features/magic-context/dreamer/map-memories-prompt.d.ts.map +1 -1
  17. package/dist/features/magic-context/dreamer/map-memories.d.ts +2 -0
  18. package/dist/features/magic-context/dreamer/map-memories.d.ts.map +1 -1
  19. package/dist/features/magic-context/dreamer/memory-claim-safety.d.ts +9 -0
  20. package/dist/features/magic-context/dreamer/memory-claim-safety.d.ts.map +1 -0
  21. package/dist/features/magic-context/dreamer/task-executor.d.ts.map +1 -1
  22. package/dist/features/magic-context/dreamer/task-registry.d.ts +2 -0
  23. package/dist/features/magic-context/dreamer/task-registry.d.ts.map +1 -1
  24. package/dist/features/magic-context/dreamer/verify-prompt.d.ts +7 -2
  25. package/dist/features/magic-context/dreamer/verify-prompt.d.ts.map +1 -1
  26. package/dist/features/magic-context/dreamer/verify.d.ts +13 -10
  27. package/dist/features/magic-context/dreamer/verify.d.ts.map +1 -1
  28. package/dist/features/magic-context/memory/embedding-local.d.ts +19 -0
  29. package/dist/features/magic-context/memory/embedding-local.d.ts.map +1 -1
  30. package/dist/features/magic-context/memory/storage-memory-verifications.d.ts +5 -1
  31. package/dist/features/magic-context/memory/storage-memory-verifications.d.ts.map +1 -1
  32. package/dist/features/magic-context/memory/storage-memory.d.ts.map +1 -1
  33. package/dist/features/magic-context/migrations.d.ts.map +1 -1
  34. package/dist/features/magic-context/project-embedding-registry.d.ts +3 -0
  35. package/dist/features/magic-context/project-embedding-registry.d.ts.map +1 -1
  36. package/dist/features/magic-context/storage-db.d.ts +1 -1
  37. package/dist/features/magic-context/storage-db.d.ts.map +1 -1
  38. package/dist/features/magic-context/storage-identity-merge.d.ts.map +1 -1
  39. package/dist/features/magic-context/storage-meta-persisted.d.ts +29 -3
  40. package/dist/features/magic-context/storage-meta-persisted.d.ts.map +1 -1
  41. package/dist/features/magic-context/storage-meta-session.d.ts.map +1 -1
  42. package/dist/features/magic-context/storage-meta.d.ts +1 -1
  43. package/dist/features/magic-context/storage-meta.d.ts.map +1 -1
  44. package/dist/features/magic-context/storage-tags.d.ts +7 -0
  45. package/dist/features/magic-context/storage-tags.d.ts.map +1 -1
  46. package/dist/features/magic-context/storage.d.ts +1 -1
  47. package/dist/features/magic-context/storage.d.ts.map +1 -1
  48. package/dist/hooks/magic-context/channel2-delivery.d.ts +2 -4
  49. package/dist/hooks/magic-context/channel2-delivery.d.ts.map +1 -1
  50. package/dist/hooks/magic-context/command-handler.d.ts +7 -0
  51. package/dist/hooks/magic-context/command-handler.d.ts.map +1 -1
  52. package/dist/hooks/magic-context/compaction-marker-manager.d.ts.map +1 -1
  53. package/dist/hooks/magic-context/compartment-runner-incremental.d.ts.map +1 -1
  54. package/dist/hooks/magic-context/compartment-runner-recomp.d.ts.map +1 -1
  55. package/dist/hooks/magic-context/compartment-trigger.d.ts +1 -0
  56. package/dist/hooks/magic-context/compartment-trigger.d.ts.map +1 -1
  57. package/dist/hooks/magic-context/ctx-reduce-nudge.d.ts +15 -14
  58. package/dist/hooks/magic-context/ctx-reduce-nudge.d.ts.map +1 -1
  59. package/dist/hooks/magic-context/emergency-drop.d.ts +6 -8
  60. package/dist/hooks/magic-context/emergency-drop.d.ts.map +1 -1
  61. package/dist/hooks/magic-context/event-resolvers.d.ts +2 -2
  62. package/dist/hooks/magic-context/execute-status.d.ts +4 -1
  63. package/dist/hooks/magic-context/execute-status.d.ts.map +1 -1
  64. package/dist/hooks/magic-context/heuristic-cleanup.d.ts +6 -0
  65. package/dist/hooks/magic-context/heuristic-cleanup.d.ts.map +1 -1
  66. package/dist/hooks/magic-context/hook-handlers.d.ts +21 -8
  67. package/dist/hooks/magic-context/hook-handlers.d.ts.map +1 -1
  68. package/dist/hooks/magic-context/hook.d.ts +16 -1
  69. package/dist/hooks/magic-context/hook.d.ts.map +1 -1
  70. package/dist/hooks/magic-context/inject-compartments.d.ts +6 -16
  71. package/dist/hooks/magic-context/inject-compartments.d.ts.map +1 -1
  72. package/dist/hooks/magic-context/maintenance-authority.d.ts +3 -0
  73. package/dist/hooks/magic-context/maintenance-authority.d.ts.map +1 -0
  74. package/dist/hooks/magic-context/module-transport.d.ts.map +1 -1
  75. package/dist/hooks/magic-context/module-wire.d.ts.map +1 -1
  76. package/dist/hooks/magic-context/protected-tail-boundary.d.ts.map +1 -1
  77. package/dist/hooks/magic-context/read-session-true-raw-tokens.d.ts +1 -0
  78. package/dist/hooks/magic-context/read-session-true-raw-tokens.d.ts.map +1 -1
  79. package/dist/hooks/magic-context/rust-mode-transform.d.ts +9 -0
  80. package/dist/hooks/magic-context/rust-mode-transform.d.ts.map +1 -1
  81. package/dist/hooks/magic-context/strip-content.d.ts +8 -0
  82. package/dist/hooks/magic-context/strip-content.d.ts.map +1 -1
  83. package/dist/hooks/magic-context/stripped-command.d.ts +19 -0
  84. package/dist/hooks/magic-context/stripped-command.d.ts.map +1 -0
  85. package/dist/hooks/magic-context/supersession-reclaim.d.ts +11 -0
  86. package/dist/hooks/magic-context/supersession-reclaim.d.ts.map +1 -1
  87. package/dist/hooks/magic-context/tag-messages.d.ts +6 -0
  88. package/dist/hooks/magic-context/tag-messages.d.ts.map +1 -1
  89. package/dist/hooks/magic-context/tail-hygiene-walk.d.ts +11 -0
  90. package/dist/hooks/magic-context/tail-hygiene-walk.d.ts.map +1 -1
  91. package/dist/hooks/magic-context/temporal-awareness.d.ts +1 -1
  92. package/dist/hooks/magic-context/temporal-awareness.d.ts.map +1 -1
  93. package/dist/hooks/magic-context/transform-operations.d.ts +1 -1
  94. package/dist/hooks/magic-context/transform-operations.d.ts.map +1 -1
  95. package/dist/hooks/magic-context/transform-postprocess-phase.d.ts +5 -1
  96. package/dist/hooks/magic-context/transform-postprocess-phase.d.ts.map +1 -1
  97. package/dist/hooks/magic-context/transform.d.ts.map +1 -1
  98. package/dist/{index-pck9vadr.js → index-26ds03jd.js} +1 -1
  99. package/dist/{index-mg1yx1ph.js → index-2bykz3bx.js} +2 -2
  100. package/dist/{index-mmrhhk9a.js → index-37yzyeca.js} +36 -8
  101. package/dist/{index-btj2qhmc.js → index-88za3sz8.js} +3 -3
  102. package/dist/index-b4gv9f7g.js +284 -0
  103. package/dist/{index-ehpzdy0v.js → index-bf799gbq.js} +8 -1
  104. package/dist/{index-1h9t9xb5.js → index-dmgbar7r.js} +2 -2
  105. package/dist/{index-qf20mv7e.js → index-dmvy29z0.js} +1 -1
  106. package/dist/{index-sw8gnq34.js → index-jmwq2wxr.js} +2 -2
  107. package/dist/{index-3dkzzh0t.js → index-knna83k0.js} +1 -1
  108. package/dist/{index-axpym70t.js → index-w8rkbhn6.js} +617 -324
  109. package/dist/{index-rw0qrkvq.js → index-x9dmzyp5.js} +17 -4
  110. package/dist/index.d.ts.map +1 -1
  111. package/dist/index.js +2901 -2305
  112. package/dist/{model-resolution-r9jbcz86.js → model-resolution-jgrkt0z2.js} +3 -1
  113. package/dist/plugin/dream-timer.d.ts.map +1 -1
  114. package/dist/plugin/hooks/create-session-hooks.d.ts +14 -0
  115. package/dist/plugin/hooks/create-session-hooks.d.ts.map +1 -1
  116. package/dist/plugin/rpc-handlers.d.ts +10 -0
  117. package/dist/plugin/rpc-handlers.d.ts.map +1 -1
  118. package/dist/{recomp-orchestrator-dmyvqekw.js → recomp-orchestrator-1w4xj6jt.js} +7 -7
  119. package/dist/{safe-notification-target-tepzc2xa.js → safe-notification-target-p0c0csxw.js} +3 -3
  120. package/dist/{send-session-notification-6v5b72b4.js → send-session-notification-kn34g7mx.js} +4 -4
  121. package/dist/shared/data-path.d.ts +12 -3
  122. package/dist/shared/data-path.d.ts.map +1 -1
  123. package/dist/shared/logger.d.ts.map +1 -1
  124. package/dist/shared/model-resolution.d.ts +1 -0
  125. package/dist/shared/model-resolution.d.ts.map +1 -1
  126. package/dist/shared/rpc-types.d.ts +5 -0
  127. package/dist/shared/rpc-types.d.ts.map +1 -1
  128. package/dist/shared/rust-mode-status.d.ts +3 -0
  129. package/dist/shared/rust-mode-status.d.ts.map +1 -0
  130. package/dist/shared/status-detail-text.d.ts.map +1 -1
  131. package/dist/shared/subagent-runner.d.ts +4 -0
  132. package/dist/shared/subagent-runner.d.ts.map +1 -1
  133. package/dist/shared/write-transaction-timing.d.ts +11 -0
  134. package/dist/shared/write-transaction-timing.d.ts.map +1 -0
  135. package/dist/{storage-meta-session-yvtbaw7c.js → storage-meta-session-snbzd26z.js} +4 -4
  136. package/dist/{task-config-a1qmj9bx.js → task-config-ty08ptc2.js} +2 -2
  137. package/dist/tools/ctx-expand/tools.d.ts.map +1 -1
  138. package/dist/tools/ctx-memory/tools.d.ts.map +1 -1
  139. package/dist/tui/data/context-db.d.ts +10 -3
  140. package/dist/tui/data/context-db.d.ts.map +1 -1
  141. package/dist/tui-compiled/data/context-db.d.ts +10 -3
  142. package/dist/tui-compiled/data/context-db.d.ts.map +1 -1
  143. package/package.json +2 -1
  144. package/src/agents/permissions.ts +14 -4
  145. package/src/config/index.test.ts +38 -0
  146. package/src/features/magic-context/dreamer/task-registry.ts +2 -0
  147. package/src/shared/data-path.test.ts +44 -4
  148. package/src/shared/data-path.ts +54 -11
  149. package/src/shared/logger.test.ts +15 -0
  150. package/src/shared/logger.ts +9 -4
  151. package/src/shared/model-resolution.test.ts +39 -0
  152. package/src/shared/model-resolution.ts +8 -0
  153. package/src/shared/redaction.ts +2 -2
  154. package/src/shared/rpc-types.ts +5 -0
  155. package/src/shared/rust-mode-status.ts +3 -0
  156. package/src/shared/status-detail-text.test.ts +13 -0
  157. package/src/shared/status-detail-text.ts +2 -0
  158. package/src/shared/subagent-runner.ts +4 -0
  159. package/src/shared/write-transaction-timing.ts +25 -0
  160. package/src/tui/data/context-db.test.ts +31 -1
  161. package/src/tui/data/context-db.ts +17 -61
  162. package/src/tui/index.tsx +36 -5
  163. package/src/tui-compiled/data/context-db.ts +17 -61
  164. package/src/tui-compiled/index.tsx +229 -191
  165. package/dist/index-8pqfcghm.js +0 -81
package/src/tui/index.tsx CHANGED
@@ -12,6 +12,7 @@ import { closeRpc, dismissUpgradeReminder, getAnnouncement, getCompartmentCount,
12
12
  import { startNotificationSocket, stopNotificationSocket, type SocketNotification } from "./data/notification-socket"
13
13
  import { formatThresholdPercent } from "../shared/format-threshold"
14
14
  import { formatTailHygiene } from "../shared/tail-hygiene-status"
15
+ import { RUST_MODE_HOST_PATHS_LINE } from "../shared/rust-mode-status"
15
16
  import { formatWindowDerivationLine } from "../shared/window-geometry"
16
17
  import { compactionOffSidebarRows, nativeCompactionContextLabel } from "./compaction-off"
17
18
  import { isCompactionEnabled } from "../config/agent-disable"
@@ -321,6 +322,13 @@ const StatusDialog = (props: { api: TuiPluginApi; s: StatusDetail }) => {
321
322
  )
322
323
  })()}
323
324
 
325
+ {s().hostBackendsModuleSide && (
326
+ <box marginTop={1} width="100%" flexDirection="column">
327
+ <text fg={t().text}><b>Rust Mode</b></text>
328
+ <text fg={t().textMuted}>{RUST_MODE_HOST_PATHS_LINE}</text>
329
+ </box>
330
+ )}
331
+
324
332
  <box flexDirection="row" width="100%" marginTop={1} gap={4}>
325
333
  {compactionOff() ? (
326
334
  <box flexDirection="column" flexGrow={1} flexBasis={0}>
@@ -344,8 +352,24 @@ const StatusDialog = (props: { api: TuiPluginApi; s: StatusDetail }) => {
344
352
  <>
345
353
  <box flexDirection="column" flexGrow={1} flexBasis={0}>
346
354
  <text fg={t().text}><b>Tags</b></text>
347
- <R t={t()} l="Active" v={`${s().activeTags} (~${fmtBytes(s().activeBytes)})`} />
348
- <R t={t()} l="Dropped" v={String(s().droppedTags)} />
355
+ <R
356
+ t={t()}
357
+ l="Active"
358
+ v={
359
+ s().tagCountsAuthoritative === false
360
+ ? "n/a (module total only)"
361
+ : `${s().activeTags} (~${fmtBytes(s().activeBytes)})`
362
+ }
363
+ />
364
+ <R
365
+ t={t()}
366
+ l="Dropped"
367
+ v={
368
+ s().tagCountsAuthoritative === false
369
+ ? "n/a (module total only)"
370
+ : String(s().droppedTags)
371
+ }
372
+ />
349
373
  <R t={t()} l="Total" v={String(s().totalTags)} fg={t().textMuted} />
350
374
  <box marginTop={1}>
351
375
  <text fg={t().text}><b>Pending Queue</b></text>
@@ -459,7 +483,7 @@ async function showRecompDialog(api: TuiPluginApi, targetSessionId = getSessionI
459
483
  return false
460
484
  }
461
485
 
462
- const countResult = await getCompartmentCount(sessionId)
486
+ const countResult = await getCompartmentCount(sessionId, api.state.path.directory ?? "")
463
487
  // Ack only after the dialog is actually shown for the same active session;
464
488
  // route switches while the RPC detail load is in flight must leave it pending.
465
489
  if (getSessionId(api) !== sessionId) return false
@@ -588,10 +612,17 @@ async function showStatusDialog(api: TuiPluginApi, targetSessionId = getSessionI
588
612
 
589
613
  const directory = api.state.path.directory ?? ""
590
614
  const modelKey = getModelKeyFromMessages(api, sessionId)
591
- const detail = await loadStatusDetail(sessionId, directory, modelKey)
615
+ const result = await loadStatusDetail(sessionId, directory, modelKey)
592
616
  if (getSessionId(api) !== sessionId) return false
617
+ if (!result.ok) {
618
+ showToast(api, {
619
+ message: `Status unavailable: ${result.error}`,
620
+ variant: "warning",
621
+ })
622
+ return false
623
+ }
593
624
 
594
- api.ui.dialog.replace(() => <StatusDialog api={api} s={detail} />)
625
+ api.ui.dialog.replace(() => <StatusDialog api={api} s={result.detail} />)
595
626
  return true
596
627
  }
597
628
 
@@ -2,8 +2,7 @@
2
2
  * TUI data layer — pure RPC client, no direct SQLite access.
3
3
  * All data is fetched from the server plugin via HTTP RPC.
4
4
  */
5
- import os from "node:os";
6
- import path from "node:path";
5
+ import { getMagicContextStorageDir } from "../../shared/data-path";
7
6
  import { MagicContextRpcClient } from "../../shared/rpc-client";
8
7
  import type { EmbedDetail, SidebarSnapshot, StatusDetail } from "../../shared/rpc-types";
9
8
 
@@ -12,18 +11,9 @@ export type { EmbedDetail, SidebarSnapshot, StatusDetail };
12
11
  let rpcClient: MagicContextRpcClient | null = null;
13
12
  let rpcGeneration = 0;
14
13
 
15
- function getStorageDir(): string {
16
- // Plugin v0.16+ uses the shared cortexkit/magic-context path so OpenCode
17
- // and Pi can share state. The TUI just needs to point its RPC client at
18
- // the same storage directory the server plugin uses for the lock-file
19
- // discovery convention.
20
- const dataDir = process.env.XDG_DATA_HOME ?? path.join(os.homedir(), ".local", "share");
21
- return path.join(dataDir, "cortexkit", "magic-context");
22
- }
23
-
24
14
  /** Initialize the RPC client. Call once on TUI startup. */
25
15
  export function initRpcClient(directory: string): void {
26
- const storageDir = getStorageDir();
16
+ const storageDir = getMagicContextStorageDir();
27
17
  // Bump the generation before replacing the client so late notification
28
18
  // responses from a disposed client are ignored (the WS socket observes the
29
19
  // new generation and abandons its in-flight connect).
@@ -172,63 +162,26 @@ export async function loadSidebarSnapshot(
172
162
  }
173
163
  }
174
164
 
175
- /** Fetch full status detail from the server via RPC. */
165
+ export type StatusDetailResult = { ok: true; detail: StatusDetail } | { ok: false; error: string };
166
+
167
+ /** Fetch full status detail without presenting transport failure as an empty session. */
176
168
  export async function loadStatusDetail(
177
169
  sessionId: string,
178
170
  directory: string,
179
171
  modelKey?: string,
180
- ): Promise<StatusDetail> {
181
- const emptyDetail: StatusDetail = {
182
- ...EMPTY_SNAPSHOT,
183
- sessionId,
184
- activeProfile: null,
185
- tagCounter: 0,
186
- activeTags: 0,
187
- droppedTags: 0,
188
- totalTags: 0,
189
- activeBytes: 0,
190
- lastResponseTime: 0,
191
- lastNudgeTokens: 0,
192
- lastTransformError: null,
193
- isSubagent: false,
194
- pendingOps: [],
195
- contextLimit: 0,
196
- cacheTtlMs: 0,
197
- cacheRemainingMs: 0,
198
- cacheExpired: false,
199
- cacheNeverExpires: false,
200
- executeThreshold: 65,
201
- executeThresholdMode: "percentage",
202
- protectedTagCount: 20,
203
- historyBudgetPercentage: 0.15,
204
- historyBlockTokens: 0,
205
- compressionBudget: null,
206
- compressionUsage: null,
207
- toastDurationMs: 5000,
208
- loggerDiagnostics: {
209
- swallowedWriteCount: 0,
210
- lastErrorMessage: null,
211
- lastErrorTime: null,
212
- },
213
- storage_versions: {
214
- context_db_schema_version: null,
215
- plugin_supported_version: 0,
216
- },
217
- };
218
-
219
- if (!rpcClient) return emptyDetail;
172
+ ): Promise<StatusDetailResult> {
173
+ if (!rpcClient) return { ok: false, error: "RPC client is not initialized" };
220
174
  try {
221
175
  const result = await rpcClient.call<StatusDetail>("status-detail", {
222
176
  sessionId,
223
177
  directory,
224
178
  modelKey,
225
179
  });
226
- if ((result as unknown as Record<string, unknown>).error) {
227
- return emptyDetail;
228
- }
229
- return result;
230
- } catch {
231
- return emptyDetail;
180
+ const error = (result as unknown as Record<string, unknown>).error;
181
+ if (typeof error === "string") return { ok: false, error };
182
+ return { ok: true, detail: result };
183
+ } catch (error) {
184
+ return { ok: false, error: error instanceof Error ? error.message : String(error) };
232
185
  }
233
186
  }
234
187
 
@@ -262,12 +215,15 @@ export async function loadEmbedDetail(sessionId: string, directory: string): Pro
262
215
  export type CompartmentCountResult = { ok: true; count: number } | { ok: false; error: string };
263
216
 
264
217
  /** Get compartment count without making transport failure look like a real zero. */
265
- export async function getCompartmentCount(sessionId: string): Promise<CompartmentCountResult> {
218
+ export async function getCompartmentCount(
219
+ sessionId: string,
220
+ directory?: string,
221
+ ): Promise<CompartmentCountResult> {
266
222
  if (!rpcClient) return { ok: false, error: "RPC client is not initialized" };
267
223
  try {
268
224
  const result = await rpcClient.call<{ count?: number; error?: string }>(
269
225
  "compartment-count",
270
- { sessionId },
226
+ { sessionId, directory },
271
227
  );
272
228
  if (typeof result.error === "string") return { ok: false, error: result.error };
273
229
  if (typeof result.count !== "number" || !Number.isFinite(result.count)) {