@cortexkit/opencode-magic-context 0.40.1 → 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 (158) hide show
  1. package/README.md +1 -1
  2. package/dist/{announcement-5eg4t64s.js → announcement-3g9xg433.js} +2 -2
  3. package/dist/{conflict-warning-hook-f406ggbw.js → conflict-warning-hook-xj1r88a7.js} +4 -4
  4. package/dist/{derive-budgets-xk8cy5e6.js → derive-budgets-3xfyphvk.js} +3 -3
  5. package/dist/features/builtin-commands/commands.d.ts +35 -2
  6. package/dist/features/builtin-commands/commands.d.ts.map +1 -1
  7. package/dist/features/magic-context/context-authority.d.ts +10 -0
  8. package/dist/features/magic-context/context-authority.d.ts.map +1 -1
  9. package/dist/features/magic-context/dreamer/classify.d.ts +1 -0
  10. package/dist/features/magic-context/dreamer/classify.d.ts.map +1 -1
  11. package/dist/features/magic-context/dreamer/lease.d.ts +12 -27
  12. package/dist/features/magic-context/dreamer/lease.d.ts.map +1 -1
  13. package/dist/features/magic-context/dreamer/map-memories-prompt.d.ts +1 -1
  14. package/dist/features/magic-context/dreamer/map-memories-prompt.d.ts.map +1 -1
  15. package/dist/features/magic-context/dreamer/map-memories.d.ts +2 -0
  16. package/dist/features/magic-context/dreamer/map-memories.d.ts.map +1 -1
  17. package/dist/features/magic-context/dreamer/memory-claim-safety.d.ts +9 -0
  18. package/dist/features/magic-context/dreamer/memory-claim-safety.d.ts.map +1 -0
  19. package/dist/features/magic-context/dreamer/task-executor.d.ts.map +1 -1
  20. package/dist/features/magic-context/dreamer/task-registry.d.ts +2 -0
  21. package/dist/features/magic-context/dreamer/task-registry.d.ts.map +1 -1
  22. package/dist/features/magic-context/dreamer/verify-prompt.d.ts +7 -2
  23. package/dist/features/magic-context/dreamer/verify-prompt.d.ts.map +1 -1
  24. package/dist/features/magic-context/dreamer/verify.d.ts +13 -10
  25. package/dist/features/magic-context/dreamer/verify.d.ts.map +1 -1
  26. package/dist/features/magic-context/memory/storage-memory-verifications.d.ts +5 -1
  27. package/dist/features/magic-context/memory/storage-memory-verifications.d.ts.map +1 -1
  28. package/dist/features/magic-context/memory/storage-memory.d.ts.map +1 -1
  29. package/dist/features/magic-context/migrations.d.ts.map +1 -1
  30. package/dist/features/magic-context/project-embedding-registry.d.ts +3 -0
  31. package/dist/features/magic-context/project-embedding-registry.d.ts.map +1 -1
  32. package/dist/features/magic-context/storage-db.d.ts +1 -1
  33. package/dist/features/magic-context/storage-db.d.ts.map +1 -1
  34. package/dist/features/magic-context/storage-identity-merge.d.ts.map +1 -1
  35. package/dist/features/magic-context/storage-meta-persisted.d.ts +29 -3
  36. package/dist/features/magic-context/storage-meta-persisted.d.ts.map +1 -1
  37. package/dist/features/magic-context/storage-meta-session.d.ts.map +1 -1
  38. package/dist/features/magic-context/storage-meta.d.ts +1 -1
  39. package/dist/features/magic-context/storage-meta.d.ts.map +1 -1
  40. package/dist/features/magic-context/storage-tags.d.ts +7 -0
  41. package/dist/features/magic-context/storage-tags.d.ts.map +1 -1
  42. package/dist/features/magic-context/storage.d.ts +1 -1
  43. package/dist/features/magic-context/storage.d.ts.map +1 -1
  44. package/dist/hooks/magic-context/channel2-delivery.d.ts +2 -4
  45. package/dist/hooks/magic-context/channel2-delivery.d.ts.map +1 -1
  46. package/dist/hooks/magic-context/command-handler.d.ts +7 -0
  47. package/dist/hooks/magic-context/command-handler.d.ts.map +1 -1
  48. package/dist/hooks/magic-context/compaction-marker-manager.d.ts.map +1 -1
  49. package/dist/hooks/magic-context/compartment-runner-incremental.d.ts.map +1 -1
  50. package/dist/hooks/magic-context/compartment-runner-recomp.d.ts.map +1 -1
  51. package/dist/hooks/magic-context/compartment-trigger.d.ts +1 -0
  52. package/dist/hooks/magic-context/compartment-trigger.d.ts.map +1 -1
  53. package/dist/hooks/magic-context/ctx-reduce-nudge.d.ts +15 -14
  54. package/dist/hooks/magic-context/ctx-reduce-nudge.d.ts.map +1 -1
  55. package/dist/hooks/magic-context/emergency-drop.d.ts +6 -8
  56. package/dist/hooks/magic-context/emergency-drop.d.ts.map +1 -1
  57. package/dist/hooks/magic-context/event-resolvers.d.ts +2 -2
  58. package/dist/hooks/magic-context/execute-status.d.ts +4 -1
  59. package/dist/hooks/magic-context/execute-status.d.ts.map +1 -1
  60. package/dist/hooks/magic-context/heuristic-cleanup.d.ts +6 -0
  61. package/dist/hooks/magic-context/heuristic-cleanup.d.ts.map +1 -1
  62. package/dist/hooks/magic-context/hook-handlers.d.ts +21 -8
  63. package/dist/hooks/magic-context/hook-handlers.d.ts.map +1 -1
  64. package/dist/hooks/magic-context/hook.d.ts +16 -1
  65. package/dist/hooks/magic-context/hook.d.ts.map +1 -1
  66. package/dist/hooks/magic-context/inject-compartments.d.ts +6 -16
  67. package/dist/hooks/magic-context/inject-compartments.d.ts.map +1 -1
  68. package/dist/hooks/magic-context/maintenance-authority.d.ts +3 -0
  69. package/dist/hooks/magic-context/maintenance-authority.d.ts.map +1 -0
  70. package/dist/hooks/magic-context/module-transport.d.ts.map +1 -1
  71. package/dist/hooks/magic-context/module-wire.d.ts.map +1 -1
  72. package/dist/hooks/magic-context/protected-tail-boundary.d.ts.map +1 -1
  73. package/dist/hooks/magic-context/read-session-true-raw-tokens.d.ts +1 -0
  74. package/dist/hooks/magic-context/read-session-true-raw-tokens.d.ts.map +1 -1
  75. package/dist/hooks/magic-context/rust-mode-transform.d.ts +9 -0
  76. package/dist/hooks/magic-context/rust-mode-transform.d.ts.map +1 -1
  77. package/dist/hooks/magic-context/strip-content.d.ts +8 -0
  78. package/dist/hooks/magic-context/strip-content.d.ts.map +1 -1
  79. package/dist/hooks/magic-context/stripped-command.d.ts +19 -0
  80. package/dist/hooks/magic-context/stripped-command.d.ts.map +1 -0
  81. package/dist/hooks/magic-context/supersession-reclaim.d.ts +11 -0
  82. package/dist/hooks/magic-context/supersession-reclaim.d.ts.map +1 -1
  83. package/dist/hooks/magic-context/tag-messages.d.ts +6 -0
  84. package/dist/hooks/magic-context/tag-messages.d.ts.map +1 -1
  85. package/dist/hooks/magic-context/tail-hygiene-walk.d.ts +11 -0
  86. package/dist/hooks/magic-context/tail-hygiene-walk.d.ts.map +1 -1
  87. package/dist/hooks/magic-context/transform-operations.d.ts +1 -1
  88. package/dist/hooks/magic-context/transform-operations.d.ts.map +1 -1
  89. package/dist/hooks/magic-context/transform-postprocess-phase.d.ts +5 -1
  90. package/dist/hooks/magic-context/transform-postprocess-phase.d.ts.map +1 -1
  91. package/dist/hooks/magic-context/transform.d.ts.map +1 -1
  92. package/dist/{index-pck9vadr.js → index-26ds03jd.js} +1 -1
  93. package/dist/{index-mg1yx1ph.js → index-2bykz3bx.js} +2 -2
  94. package/dist/{index-mmrhhk9a.js → index-37yzyeca.js} +36 -8
  95. package/dist/{index-btj2qhmc.js → index-88za3sz8.js} +3 -3
  96. package/dist/index-b4gv9f7g.js +284 -0
  97. package/dist/{index-ehpzdy0v.js → index-bf799gbq.js} +8 -1
  98. package/dist/{index-1h9t9xb5.js → index-dmgbar7r.js} +2 -2
  99. package/dist/{index-qf20mv7e.js → index-dmvy29z0.js} +1 -1
  100. package/dist/{index-sw8gnq34.js → index-jmwq2wxr.js} +2 -2
  101. package/dist/{index-3dkzzh0t.js → index-knna83k0.js} +1 -1
  102. package/dist/{index-x64cmpej.js → index-w8rkbhn6.js} +505 -301
  103. package/dist/{index-rw0qrkvq.js → index-x9dmzyp5.js} +17 -4
  104. package/dist/index.d.ts.map +1 -1
  105. package/dist/index.js +2892 -2302
  106. package/dist/{model-resolution-r9jbcz86.js → model-resolution-jgrkt0z2.js} +3 -1
  107. package/dist/plugin/dream-timer.d.ts.map +1 -1
  108. package/dist/plugin/hooks/create-session-hooks.d.ts +14 -0
  109. package/dist/plugin/hooks/create-session-hooks.d.ts.map +1 -1
  110. package/dist/plugin/rpc-handlers.d.ts +10 -0
  111. package/dist/plugin/rpc-handlers.d.ts.map +1 -1
  112. package/dist/{recomp-orchestrator-dtgww0f0.js → recomp-orchestrator-1w4xj6jt.js} +7 -7
  113. package/dist/{safe-notification-target-tepzc2xa.js → safe-notification-target-p0c0csxw.js} +3 -3
  114. package/dist/{send-session-notification-6v5b72b4.js → send-session-notification-kn34g7mx.js} +4 -4
  115. package/dist/shared/data-path.d.ts +12 -3
  116. package/dist/shared/data-path.d.ts.map +1 -1
  117. package/dist/shared/logger.d.ts.map +1 -1
  118. package/dist/shared/model-resolution.d.ts +1 -0
  119. package/dist/shared/model-resolution.d.ts.map +1 -1
  120. package/dist/shared/rpc-types.d.ts +5 -0
  121. package/dist/shared/rpc-types.d.ts.map +1 -1
  122. package/dist/shared/rust-mode-status.d.ts +3 -0
  123. package/dist/shared/rust-mode-status.d.ts.map +1 -0
  124. package/dist/shared/status-detail-text.d.ts.map +1 -1
  125. package/dist/shared/subagent-runner.d.ts +4 -0
  126. package/dist/shared/subagent-runner.d.ts.map +1 -1
  127. package/dist/shared/write-transaction-timing.d.ts +11 -0
  128. package/dist/shared/write-transaction-timing.d.ts.map +1 -0
  129. package/dist/{storage-meta-session-yvtbaw7c.js → storage-meta-session-snbzd26z.js} +4 -4
  130. package/dist/{task-config-a1qmj9bx.js → task-config-ty08ptc2.js} +2 -2
  131. package/dist/tools/ctx-expand/tools.d.ts.map +1 -1
  132. package/dist/tools/ctx-memory/tools.d.ts.map +1 -1
  133. package/dist/tui/data/context-db.d.ts +10 -3
  134. package/dist/tui/data/context-db.d.ts.map +1 -1
  135. package/dist/tui-compiled/data/context-db.d.ts +10 -3
  136. package/dist/tui-compiled/data/context-db.d.ts.map +1 -1
  137. package/package.json +1 -1
  138. package/src/config/index.test.ts +38 -0
  139. package/src/features/magic-context/dreamer/task-registry.ts +2 -0
  140. package/src/shared/data-path.test.ts +44 -4
  141. package/src/shared/data-path.ts +54 -11
  142. package/src/shared/logger.test.ts +15 -0
  143. package/src/shared/logger.ts +9 -4
  144. package/src/shared/model-resolution.test.ts +39 -0
  145. package/src/shared/model-resolution.ts +8 -0
  146. package/src/shared/redaction.ts +2 -2
  147. package/src/shared/rpc-types.ts +5 -0
  148. package/src/shared/rust-mode-status.ts +3 -0
  149. package/src/shared/status-detail-text.test.ts +13 -0
  150. package/src/shared/status-detail-text.ts +2 -0
  151. package/src/shared/subagent-runner.ts +4 -0
  152. package/src/shared/write-transaction-timing.ts +25 -0
  153. package/src/tui/data/context-db.test.ts +31 -1
  154. package/src/tui/data/context-db.ts +17 -61
  155. package/src/tui/index.tsx +36 -5
  156. package/src/tui-compiled/data/context-db.ts +17 -61
  157. package/src/tui-compiled/index.tsx +229 -191
  158. package/dist/index-8pqfcghm.js +0 -81
@@ -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)) {