@cortexkit/opencode-magic-context 0.33.0 → 0.34.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 (265) hide show
  1. package/dist/config/agent-disable.d.ts +22 -0
  2. package/dist/config/agent-disable.d.ts.map +1 -1
  3. package/dist/config/index.d.ts.map +1 -1
  4. package/dist/config/project-security.d.ts +7 -0
  5. package/dist/config/project-security.d.ts.map +1 -1
  6. package/dist/config/schema/magic-context.d.ts +144 -24
  7. package/dist/config/schema/magic-context.d.ts.map +1 -1
  8. package/dist/config/transform-mode.d.ts +2 -0
  9. package/dist/config/transform-mode.d.ts.map +1 -1
  10. package/dist/{conflict-warning-hook-bwa99a04.js → conflict-warning-hook-fvpfvt0w.js} +1 -1
  11. package/dist/{derive-budgets-e9j09sjr.js → derive-budgets-9crp0cvd.js} +1 -1
  12. package/dist/features/builtin-commands/commands.d.ts +1 -1
  13. package/dist/features/builtin-commands/commands.d.ts.map +1 -1
  14. package/dist/features/magic-context/compaction-marker.d.ts +106 -0
  15. package/dist/features/magic-context/compaction-marker.d.ts.map +1 -1
  16. package/dist/features/magic-context/compartment-chunk-embedding.d.ts +0 -2
  17. package/dist/features/magic-context/compartment-chunk-embedding.d.ts.map +1 -1
  18. package/dist/features/magic-context/dreamer/classify.d.ts.map +1 -1
  19. package/dist/features/magic-context/dreamer/evaluate-smart-notes.d.ts.map +1 -1
  20. package/dist/features/magic-context/dreamer/map-memories.d.ts.map +1 -1
  21. package/dist/features/magic-context/dreamer/refresh-primers.d.ts.map +1 -1
  22. package/dist/features/magic-context/dreamer/task-executor.d.ts.map +1 -1
  23. package/dist/features/magic-context/dreamer/task-registry.d.ts +0 -1
  24. package/dist/features/magic-context/dreamer/task-registry.d.ts.map +1 -1
  25. package/dist/features/magic-context/dreamer/verify.d.ts.map +1 -1
  26. package/dist/features/magic-context/fail-closed-block.d.ts +10 -0
  27. package/dist/features/magic-context/fail-closed-block.d.ts.map +1 -1
  28. package/dist/features/magic-context/git-commits/index.d.ts +2 -2
  29. package/dist/features/magic-context/git-commits/index.d.ts.map +1 -1
  30. package/dist/features/magic-context/git-commits/storage-git-commit-embeddings.d.ts +0 -2
  31. package/dist/features/magic-context/git-commits/storage-git-commit-embeddings.d.ts.map +1 -1
  32. package/dist/features/magic-context/git-commits/storage-git-commits.d.ts +0 -13
  33. package/dist/features/magic-context/git-commits/storage-git-commits.d.ts.map +1 -1
  34. package/dist/features/magic-context/memory/embedding-identity.d.ts.map +1 -1
  35. package/dist/features/magic-context/memory/embedding-local.d.ts +7 -1
  36. package/dist/features/magic-context/memory/embedding-local.d.ts.map +1 -1
  37. package/dist/features/magic-context/memory/embedding.d.ts +1 -2
  38. package/dist/features/magic-context/memory/embedding.d.ts.map +1 -1
  39. package/dist/features/magic-context/memory/memory-migration.d.ts +0 -6
  40. package/dist/features/magic-context/memory/memory-migration.d.ts.map +1 -1
  41. package/dist/features/magic-context/memory/project-identity.d.ts +2 -6
  42. package/dist/features/magic-context/memory/project-identity.d.ts.map +1 -1
  43. package/dist/features/magic-context/memory/storage-memory-embeddings.d.ts +0 -1
  44. package/dist/features/magic-context/memory/storage-memory-embeddings.d.ts.map +1 -1
  45. package/dist/features/magic-context/memory/storage-memory.d.ts +1 -6
  46. package/dist/features/magic-context/memory/storage-memory.d.ts.map +1 -1
  47. package/dist/features/magic-context/memory/verification-paths.d.ts +0 -1
  48. package/dist/features/magic-context/memory/verification-paths.d.ts.map +1 -1
  49. package/dist/features/magic-context/migrations.d.ts.map +1 -1
  50. package/dist/features/magic-context/mural/compress-cues.d.ts.map +1 -1
  51. package/dist/features/magic-context/mural/render-mural.d.ts.map +1 -1
  52. package/dist/features/magic-context/mural/storage-mural.d.ts +0 -1
  53. package/dist/features/magic-context/mural/storage-mural.d.ts.map +1 -1
  54. package/dist/features/magic-context/overflow-detection.d.ts +8 -1
  55. package/dist/features/magic-context/overflow-detection.d.ts.map +1 -1
  56. package/dist/features/magic-context/project-embedding-registry.d.ts +16 -2
  57. package/dist/features/magic-context/project-embedding-registry.d.ts.map +1 -1
  58. package/dist/features/magic-context/scheduler.d.ts.map +1 -1
  59. package/dist/features/magic-context/schema-fence-probe.d.ts +28 -0
  60. package/dist/features/magic-context/schema-fence-probe.d.ts.map +1 -0
  61. package/dist/features/magic-context/sidekick/agent.d.ts.map +1 -1
  62. package/dist/features/magic-context/smart-notes/capabilities.d.ts +0 -2
  63. package/dist/features/magic-context/smart-notes/capabilities.d.ts.map +1 -1
  64. package/dist/features/magic-context/smart-notes/compiler.d.ts +0 -1
  65. package/dist/features/magic-context/smart-notes/compiler.d.ts.map +1 -1
  66. package/dist/features/magic-context/smart-notes/types.d.ts +0 -16
  67. package/dist/features/magic-context/smart-notes/types.d.ts.map +1 -1
  68. package/dist/features/magic-context/storage-db.d.ts +35 -1
  69. package/dist/features/magic-context/storage-db.d.ts.map +1 -1
  70. package/dist/features/magic-context/storage-meta-persisted.d.ts +38 -5
  71. package/dist/features/magic-context/storage-meta-persisted.d.ts.map +1 -1
  72. package/dist/features/magic-context/storage-meta.d.ts +1 -1
  73. package/dist/features/magic-context/storage-meta.d.ts.map +1 -1
  74. package/dist/features/magic-context/storage.d.ts +1 -1
  75. package/dist/features/magic-context/storage.d.ts.map +1 -1
  76. package/dist/features/magic-context/user-memory/review-user-memories.d.ts.map +1 -1
  77. package/dist/features/magic-context/user-memory/storage-user-memory.d.ts +0 -2
  78. package/dist/features/magic-context/user-memory/storage-user-memory.d.ts.map +1 -1
  79. package/dist/hooks/auto-update-checker/types.d.ts +0 -3
  80. package/dist/hooks/auto-update-checker/types.d.ts.map +1 -1
  81. package/dist/hooks/magic-context/boundary-execution.d.ts +1 -1
  82. package/dist/hooks/magic-context/boundary-execution.d.ts.map +1 -1
  83. package/dist/hooks/magic-context/cache-busting-signals.d.ts +1 -1
  84. package/dist/hooks/magic-context/cache-busting-signals.d.ts.map +1 -1
  85. package/dist/hooks/magic-context/channel2-delivery.d.ts.map +1 -1
  86. package/dist/hooks/magic-context/child-session-spawn.d.ts +26 -0
  87. package/dist/hooks/magic-context/child-session-spawn.d.ts.map +1 -0
  88. package/dist/hooks/magic-context/command-handler.d.ts +2 -0
  89. package/dist/hooks/magic-context/command-handler.d.ts.map +1 -1
  90. package/dist/hooks/magic-context/compaction-marker-manager.d.ts +49 -0
  91. package/dist/hooks/magic-context/compaction-marker-manager.d.ts.map +1 -1
  92. package/dist/hooks/magic-context/compaction-off-transition.d.ts +96 -0
  93. package/dist/hooks/magic-context/compaction-off-transition.d.ts.map +1 -0
  94. package/dist/hooks/magic-context/compartment-parser.d.ts +12 -0
  95. package/dist/hooks/magic-context/compartment-parser.d.ts.map +1 -1
  96. package/dist/hooks/magic-context/compartment-runner-historian.d.ts +2 -0
  97. package/dist/hooks/magic-context/compartment-runner-historian.d.ts.map +1 -1
  98. package/dist/hooks/magic-context/compartment-runner-incremental.d.ts.map +1 -1
  99. package/dist/hooks/magic-context/compartment-runner-mapping.d.ts +0 -12
  100. package/dist/hooks/magic-context/compartment-runner-mapping.d.ts.map +1 -1
  101. package/dist/hooks/magic-context/compartment-runner-partial-recomp.d.ts.map +1 -1
  102. package/dist/hooks/magic-context/compartment-runner-recomp.d.ts.map +1 -1
  103. package/dist/hooks/magic-context/compartment-trigger.d.ts +12 -5
  104. package/dist/hooks/magic-context/compartment-trigger.d.ts.map +1 -1
  105. package/dist/hooks/magic-context/ctx-reduce-availability.d.ts +47 -1
  106. package/dist/hooks/magic-context/ctx-reduce-availability.d.ts.map +1 -1
  107. package/dist/hooks/magic-context/emergency-drop.d.ts +2 -2
  108. package/dist/hooks/magic-context/event-handler.d.ts +7 -0
  109. package/dist/hooks/magic-context/event-handler.d.ts.map +1 -1
  110. package/dist/hooks/magic-context/event-resolvers.d.ts +13 -21
  111. package/dist/hooks/magic-context/event-resolvers.d.ts.map +1 -1
  112. package/dist/hooks/magic-context/final-wire-token-estimate.d.ts +2 -0
  113. package/dist/hooks/magic-context/final-wire-token-estimate.d.ts.map +1 -1
  114. package/dist/hooks/magic-context/heuristic-cleanup.d.ts +1 -1
  115. package/dist/hooks/magic-context/historian-prompt.generated.d.ts +1 -1
  116. package/dist/hooks/magic-context/historian-prompt.generated.d.ts.map +1 -1
  117. package/dist/hooks/magic-context/hook-handlers.d.ts +1 -0
  118. package/dist/hooks/magic-context/hook-handlers.d.ts.map +1 -1
  119. package/dist/hooks/magic-context/hook.d.ts +11 -1
  120. package/dist/hooks/magic-context/hook.d.ts.map +1 -1
  121. package/dist/hooks/magic-context/inject-compartments.d.ts +18 -0
  122. package/dist/hooks/magic-context/inject-compartments.d.ts.map +1 -1
  123. package/dist/hooks/magic-context/protected-tail-boundary.d.ts.map +1 -1
  124. package/dist/hooks/magic-context/read-session-db.d.ts.map +1 -1
  125. package/dist/hooks/magic-context/read-session-true-raw-tokens.d.ts.map +1 -1
  126. package/dist/hooks/magic-context/rust-mode-transform.d.ts +3 -0
  127. package/dist/hooks/magic-context/rust-mode-transform.d.ts.map +1 -1
  128. package/dist/hooks/magic-context/send-session-notification.d.ts +20 -1
  129. package/dist/hooks/magic-context/send-session-notification.d.ts.map +1 -1
  130. package/dist/hooks/magic-context/sentinel.d.ts +39 -0
  131. package/dist/hooks/magic-context/sentinel.d.ts.map +1 -1
  132. package/dist/hooks/magic-context/tag-messages.d.ts.map +1 -1
  133. package/dist/hooks/magic-context/tool-drop-target.d.ts +19 -0
  134. package/dist/hooks/magic-context/tool-drop-target.d.ts.map +1 -1
  135. package/dist/hooks/magic-context/transform-compartment-phase.d.ts +3 -0
  136. package/dist/hooks/magic-context/transform-compartment-phase.d.ts.map +1 -1
  137. package/dist/hooks/magic-context/transform-postprocess-phase.d.ts +30 -0
  138. package/dist/hooks/magic-context/transform-postprocess-phase.d.ts.map +1 -1
  139. package/dist/hooks/magic-context/transform.d.ts +27 -0
  140. package/dist/hooks/magic-context/transform.d.ts.map +1 -1
  141. package/dist/{index-kxz4tn6m.js → index-56yjaeb2.js} +56 -4
  142. package/dist/{index-bmkea2dq.js → index-b563sga5.js} +40 -287
  143. package/dist/{index-y1c9tcm3.js → index-cn960ffd.js} +101 -20
  144. package/dist/{index-k5y60ymm.js → index-dtas91s5.js} +27 -6
  145. package/dist/index-fcyvznch.js +279 -0
  146. package/dist/{index-63dq2g4d.js → index-ry8rh8cv.js} +138 -24
  147. package/dist/{index-h86twgsp.js → index-s0mdn690.js} +2113 -1067
  148. package/dist/index.d.ts.map +1 -1
  149. package/dist/index.js +1356 -627
  150. package/dist/plugin/embedding-bootstrap.d.ts.map +1 -1
  151. package/dist/plugin/hooks/create-session-hooks.d.ts +19 -8
  152. package/dist/plugin/hooks/create-session-hooks.d.ts.map +1 -1
  153. package/dist/plugin/messages-transform.d.ts +10 -0
  154. package/dist/plugin/messages-transform.d.ts.map +1 -1
  155. package/dist/plugin/rpc-handlers.d.ts +3 -7
  156. package/dist/plugin/rpc-handlers.d.ts.map +1 -1
  157. package/dist/plugin/tool-registry.d.ts +8 -0
  158. package/dist/plugin/tool-registry.d.ts.map +1 -1
  159. package/dist/{recomp-orchestrator-yh7pepvx.js → recomp-orchestrator-8e82vmvb.js} +6 -5
  160. package/dist/send-session-notification-6njqewzk.js +20 -0
  161. package/dist/shared/conflict-detector.d.ts +38 -1
  162. package/dist/shared/conflict-detector.d.ts.map +1 -1
  163. package/dist/shared/conflict-fixer.d.ts +18 -1
  164. package/dist/shared/conflict-fixer.d.ts.map +1 -1
  165. package/dist/shared/context-limit-provenance.d.ts +3 -0
  166. package/dist/shared/context-limit-provenance.d.ts.map +1 -0
  167. package/dist/shared/escalation-bands.d.ts +9 -0
  168. package/dist/shared/escalation-bands.d.ts.map +1 -0
  169. package/dist/shared/format-threshold.d.ts +1 -1
  170. package/dist/shared/models-dev-cache.d.ts +29 -3
  171. package/dist/shared/models-dev-cache.d.ts.map +1 -1
  172. package/dist/shared/rpc-server.d.ts.map +1 -1
  173. package/dist/shared/rpc-types.d.ts +46 -1
  174. package/dist/shared/rpc-types.d.ts.map +1 -1
  175. package/dist/shared/sqlite.d.ts +9 -4
  176. package/dist/shared/sqlite.d.ts.map +1 -1
  177. package/dist/shared/storage-permissions.d.ts +5 -0
  178. package/dist/shared/storage-permissions.d.ts.map +1 -0
  179. package/dist/{storage-meta-session-1phy0b1z.js → storage-meta-session-xt41zbw4.js} +2 -1
  180. package/dist/{task-config-dn9k9szr.js → task-config-5nx3qfz8.js} +1 -2
  181. package/dist/tui/compaction-off.d.ts +13 -0
  182. package/dist/tui/compaction-off.d.ts.map +1 -0
  183. package/dist/tui/data/context-db.d.ts.map +1 -1
  184. package/dist/tui-compiled/compaction-off.d.ts +13 -0
  185. package/dist/tui-compiled/compaction-off.d.ts.map +1 -0
  186. package/dist/tui-compiled/data/context-db.d.ts.map +1 -1
  187. package/package.json +8 -3
  188. package/src/agents/dreamer.ts +68 -0
  189. package/src/agents/hidden-agent-registrations.ts +331 -0
  190. package/src/agents/historian.ts +3 -0
  191. package/src/agents/language-directive.test.ts +138 -0
  192. package/src/agents/language-directive.ts +121 -0
  193. package/src/agents/magic-context-prompt.language.test.ts +35 -0
  194. package/src/agents/magic-context-prompt.test.ts +292 -0
  195. package/src/agents/magic-context-prompt.ts +182 -0
  196. package/src/agents/permissions.test.ts +252 -0
  197. package/src/agents/permissions.ts +186 -0
  198. package/src/agents/sidekick.ts +1 -0
  199. package/src/agents/smart-note-compiler.ts +1 -0
  200. package/src/config/agent-disable.ts +106 -0
  201. package/src/config/compaction-accessor-guard.test.ts +82 -0
  202. package/src/config/compaction-backcompat.test.ts +52 -0
  203. package/src/config/index.test.ts +904 -0
  204. package/src/config/index.ts +601 -0
  205. package/src/config/migrate-config-location.test.ts +332 -0
  206. package/src/config/migrate-config-location.ts +635 -0
  207. package/src/config/migrate-dreamer-v2.test.ts +287 -0
  208. package/src/config/migrate-dreamer-v2.ts +336 -0
  209. package/src/config/migrate-experimental.ts +159 -0
  210. package/src/config/project-security.test.ts +366 -0
  211. package/src/config/project-security.ts +588 -0
  212. package/src/config/prune-config-leaf.test.ts +78 -0
  213. package/src/config/prune-config-leaf.ts +68 -0
  214. package/src/config/removed-config-keys.test.ts +116 -0
  215. package/src/config/schema/agent-overrides.ts +45 -0
  216. package/src/config/schema/magic-context.test.ts +358 -0
  217. package/src/config/schema/magic-context.ts +1002 -0
  218. package/src/config/transform-mode.test.ts +62 -0
  219. package/src/config/transform-mode.ts +34 -0
  220. package/src/config/variable.test.ts +323 -0
  221. package/src/config/variable.ts +192 -0
  222. package/src/features/magic-context/defaults.ts +1 -0
  223. package/src/features/magic-context/dreamer/cron.ts +243 -0
  224. package/src/features/magic-context/dreamer/task-registry.ts +104 -0
  225. package/src/shared/conflict-detector.test.ts +251 -1
  226. package/src/shared/conflict-detector.ts +84 -5
  227. package/src/shared/conflict-fixer.test.ts +309 -0
  228. package/src/shared/conflict-fixer.ts +82 -5
  229. package/src/shared/context-limit-provenance.ts +6 -0
  230. package/src/shared/escalation-bands.test.ts +23 -0
  231. package/src/shared/escalation-bands.ts +18 -0
  232. package/src/shared/format-threshold.ts +1 -1
  233. package/src/shared/models-dev-cache.test.ts +171 -0
  234. package/src/shared/models-dev-cache.ts +195 -38
  235. package/src/shared/rpc-server.ts +27 -18
  236. package/src/shared/rpc-types.ts +46 -1
  237. package/src/shared/sqlite.ts +13 -33
  238. package/src/shared/storage-permissions.ts +20 -0
  239. package/src/tui/compaction-off.test.ts +56 -0
  240. package/src/tui/compaction-off.ts +29 -0
  241. package/src/tui/data/context-db.ts +6 -0
  242. package/src/tui/index.tsx +113 -65
  243. package/src/tui/slots/sidebar-content.tsx +139 -83
  244. package/src/tui-compiled/compaction-off.ts +29 -0
  245. package/src/tui-compiled/data/context-db.ts +6 -0
  246. package/src/tui-compiled/index.tsx +558 -455
  247. package/src/tui-compiled/slots/sidebar-content.tsx +237 -161
  248. package/dist/config/schema.d.ts +0 -3
  249. package/dist/config/schema.d.ts.map +0 -1
  250. package/dist/features/magic-context/plugin-messages.d.ts +0 -75
  251. package/dist/features/magic-context/plugin-messages.d.ts.map +0 -1
  252. package/dist/hooks/magic-context/compartment-runner-state-xml.d.ts +0 -21
  253. package/dist/hooks/magic-context/compartment-runner-state-xml.d.ts.map +0 -1
  254. package/dist/index-anhrfygk.js +0 -57
  255. package/dist/send-session-notification-tghq9gnh.js +0 -11
  256. package/dist/shared/opencode-compaction-detector.d.ts +0 -2
  257. package/dist/shared/opencode-compaction-detector.d.ts.map +0 -1
  258. package/dist/shared/transcript-opencode.d.ts +0 -71
  259. package/dist/shared/transcript-opencode.d.ts.map +0 -1
  260. package/dist/tools/index.d.ts +0 -6
  261. package/dist/tools/index.d.ts.map +0 -1
  262. package/src/shared/opencode-compaction-detector.test.ts +0 -239
  263. package/src/shared/opencode-compaction-detector.ts +0 -81
  264. package/src/shared/transcript-opencode.ts +0 -302
  265. /package/dist/{index-v7fmc1s2.js → index-ygcng9t8.js} +0 -0
@@ -1,57 +0,0 @@
1
- // src/features/magic-context/dreamer/task-registry.ts
2
- var CANONICAL_DREAM_TASKS = [
3
- "map-memories",
4
- "verify",
5
- "verify-broad",
6
- "curate",
7
- "compress-cues",
8
- "classify-memories",
9
- "retrospective",
10
- "maintain-docs",
11
- "evaluate-smart-notes",
12
- "review-user-memories",
13
- "promote-primers",
14
- "refresh-primers"
15
- ];
16
- var AGENTIC_DREAM_TASKS = ["curate", "maintain-docs"];
17
- var MEMORY_DOMAIN_TASKS = [
18
- "map-memories",
19
- "verify",
20
- "verify-broad",
21
- "curate",
22
- "compress-cues",
23
- "classify-memories",
24
- "retrospective",
25
- "promote-primers",
26
- "refresh-primers"
27
- ];
28
- var MEMORY_DOMAIN_SET = new Set(MEMORY_DOMAIN_TASKS);
29
- function leaseKindFor(task) {
30
- if (MEMORY_DOMAIN_SET.has(task))
31
- return "memory";
32
- switch (task) {
33
- case "review-user-memories":
34
- return "user-memories";
35
- case "promote-primers":
36
- case "refresh-primers":
37
- return "memory";
38
- case "maintain-docs":
39
- return "maintain-docs";
40
- case "evaluate-smart-notes":
41
- return "evaluate-smart-notes";
42
- default:
43
- return "memory";
44
- }
45
- }
46
- function leaseKeyFor(task, projectIdentity) {
47
- const kind = leaseKindFor(task);
48
- return kind === "user-memories" ? "user-memories" : `${kind}:${projectIdentity}`;
49
- }
50
- function isCanonicalDreamTask(value) {
51
- return CANONICAL_DREAM_TASKS.includes(value);
52
- }
53
- function compareTaskOrder(a, b) {
54
- return CANONICAL_DREAM_TASKS.indexOf(a) - CANONICAL_DREAM_TASKS.indexOf(b);
55
- }
56
-
57
- export { CANONICAL_DREAM_TASKS, AGENTIC_DREAM_TASKS, leaseKindFor, leaseKeyFor, isCanonicalDreamTask, compareTaskOrder };
@@ -1,11 +0,0 @@
1
- import {
2
- sendIgnoredMessage,
3
- sendUserPrompt
4
- } from "./index-y1c9tcm3.js";
5
- import"./index-k1esqfwk.js";
6
- import"./index-kvrcg31b.js";
7
- import"./index-wckvcay0.js";
8
- export {
9
- sendUserPrompt,
10
- sendIgnoredMessage
11
- };
@@ -1,2 +0,0 @@
1
- export declare function isOpenCodeAutoCompactionEnabled(directory: string): boolean;
2
- //# sourceMappingURL=opencode-compaction-detector.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"opencode-compaction-detector.d.ts","sourceRoot":"","sources":["../../src/shared/opencode-compaction-detector.ts"],"names":[],"mappings":"AAqBA,wBAAgB,+BAA+B,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAsB1E"}
@@ -1,71 +0,0 @@
1
- /**
2
- * OpenCode adapter for the harness-agnostic transcript interface.
3
- *
4
- * This is a thin proxy over OpenCode's `MessageLike[]` (i.e. `{ info,
5
- * parts: unknown[] }[]`) — it does NOT copy data. Mutations through
6
- * `setText`/`setToolOutput`/`replaceWithSentinel` write directly into
7
- * the source `parts[]` arrays, exactly as the existing OpenCode-only
8
- * transform code does today. `commit()` is a no-op because OpenCode's
9
- * AI SDK reads `parts[]` back from the same array we mutated.
10
- *
11
- * This module is the boundary that lets the rest of the transform code
12
- * (which moves to use the Transcript interface in 4b.2) work both for
13
- * OpenCode and Pi without branching on harness type. By the end of 4b
14
- * the only OpenCode-aware code in the plugin is this file plus
15
- * `messages-transform.ts`.
16
- *
17
- * ## Mutation contract recap
18
- *
19
- * Magic Context's transform mutates message parts in three ways:
20
- *
21
- * 1. **Tag prefix injection** — prepends `§N§ ` to text parts and
22
- * tool result outputs. Repeated tagging is idempotent because
23
- * `prependTag` strips any existing prefix first.
24
- *
25
- * 2. **Sentinel replacement** — when a queued drop fires, the part is
26
- * replaced with a `[dropped §N§]` or `[truncated §N§]` placeholder.
27
- * The original tag number is preserved so the agent's mental
28
- * model of "what was here" survives.
29
- *
30
- * 3. **Structural noise stripping** — `step-start`/`step-finish`
31
- * wrappers and similar structural metadata are replaced with empty
32
- * sentinel parts so they don't consume tag numbers or get tagged
33
- * themselves.
34
- *
35
- * The OpenCode adapter implements (1) and (2) by editing `part.text` /
36
- * `part.state.output` in place. For (3), structural parts surface as
37
- * `kind: "structural"` so callers can filter them out. Adapter does NOT
38
- * itself perform stripping — that's the transform pipeline's job, called
39
- * after the adapter wraps the messages.
40
- *
41
- * Step 4b.1 ships the adapter alone. The existing OpenCode transform
42
- * code keeps using `MessageLike[]` directly until 4b.2 migrates the
43
- * tagging+drops layer to use Transcript instances.
44
- */
45
- import type { Transcript } from "./transcript";
46
- /**
47
- * The OpenCode `MessageLike` shape. Re-declared here to avoid a circular
48
- * import with `tag-messages.ts` (which lives in the magic-context hooks
49
- * tree and depends on storage). Keeping a local minimal type also makes
50
- * the adapter trivially unit-testable without booting OpenCode SDK
51
- * types.
52
- *
53
- * MUST stay structurally compatible with `tag-messages.ts MessageLike` —
54
- * if that file's MessageLike adds a required field, this one needs to
55
- * add it too. The build will fail loudly if the shapes diverge.
56
- */
57
- export interface OpenCodeMessageLike {
58
- info: {
59
- id?: string;
60
- role?: string;
61
- sessionID?: string;
62
- };
63
- parts: unknown[];
64
- }
65
- /**
66
- * Wrap an existing `MessageLike[]` as a Transcript. Zero copies — every
67
- * `TranscriptPart` returned proxies the matching entry in the source
68
- * `parts` array, and mutations are reflected immediately.
69
- */
70
- export declare function createOpenCodeTranscript(messages: OpenCodeMessageLike[]): Transcript;
71
- //# sourceMappingURL=transcript-opencode.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"transcript-opencode.d.ts","sourceRoot":"","sources":["../../src/shared/transcript-opencode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AAIH,OAAO,KAAK,EACR,UAAU,EAIb,MAAM,cAAc,CAAC;AAEtB;;;;;;;;;;GAUG;AACH,MAAM,WAAW,mBAAmB;IAChC,IAAI,EAAE;QAAE,EAAE,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACzD,KAAK,EAAE,OAAO,EAAE,CAAC;CACpB;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,mBAAmB,EAAE,GAAG,UAAU,CA2BpF"}
@@ -1,6 +0,0 @@
1
- export * from "./ctx-expand";
2
- export * from "./ctx-memory";
3
- export * from "./ctx-note";
4
- export * from "./ctx-reduce";
5
- export * from "./ctx-search";
6
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC"}
@@ -1,239 +0,0 @@
1
- import { afterEach, beforeEach, describe, expect, it, spyOn } from "bun:test";
2
- import { mkdirSync, rmSync, writeFileSync } from "node:fs";
3
- import { join } from "node:path";
4
- import { isOpenCodeAutoCompactionEnabled } from "./opencode-compaction-detector";
5
- import * as configDir from "./opencode-config-dir";
6
-
7
- describe("opencode-compaction-detector", () => {
8
- let tmpDir: string;
9
- let previousDisableAutocompact: string | undefined;
10
- let restoreConfigPaths: () => void;
11
-
12
- beforeEach(() => {
13
- tmpDir = join("/tmp", `compaction-detector-test-${Date.now()}`);
14
- mkdirSync(join(tmpDir, ".opencode"), { recursive: true });
15
- previousDisableAutocompact = process.env.OPENCODE_DISABLE_AUTOCOMPACT;
16
- delete process.env.OPENCODE_DISABLE_AUTOCOMPACT;
17
- const configPathsSpy = spyOn(configDir, "getOpenCodeConfigPaths").mockReturnValue({
18
- configJson: join(tmpDir, "user-config", "opencode.json"),
19
- configJsonc: join(tmpDir, "user-config", "opencode.jsonc"),
20
- } as ReturnType<typeof configDir.getOpenCodeConfigPaths>);
21
- restoreConfigPaths = () => configPathsSpy.mockRestore();
22
- });
23
-
24
- afterEach(() => {
25
- restoreConfigPaths();
26
- try {
27
- rmSync(tmpDir, { recursive: true, force: true, maxRetries: 10, retryDelay: 100 });
28
- } catch {
29
- /* Ignore EBUSY on Windows */
30
- }
31
- if (previousDisableAutocompact === undefined) {
32
- delete process.env.OPENCODE_DISABLE_AUTOCOMPACT;
33
- } else {
34
- process.env.OPENCODE_DISABLE_AUTOCOMPACT = previousDisableAutocompact;
35
- }
36
- });
37
-
38
- describe("#given no config exists", () => {
39
- it("#then returns true (default: compaction enabled)", () => {
40
- const emptyDir = join("/tmp", `compaction-empty-${Date.now()}`);
41
- mkdirSync(emptyDir, { recursive: true });
42
-
43
- const result = isOpenCodeAutoCompactionEnabled(emptyDir);
44
-
45
- expect(result).toBe(true);
46
- try {
47
- rmSync(emptyDir, { recursive: true, force: true, maxRetries: 10, retryDelay: 100 });
48
- } catch {
49
- /* Ignore EBUSY on Windows */
50
- }
51
- });
52
- });
53
-
54
- describe("#given OPENCODE_DISABLE_AUTOCOMPACT env flag is set", () => {
55
- it("#then returns false", () => {
56
- process.env.OPENCODE_DISABLE_AUTOCOMPACT = "1";
57
-
58
- const result = isOpenCodeAutoCompactionEnabled(tmpDir);
59
-
60
- expect(result).toBe(false);
61
- });
62
- });
63
-
64
- describe("#given project config has compaction.auto = false", () => {
65
- it("#when opencode.json #then returns false", () => {
66
- writeFileSync(
67
- join(tmpDir, ".opencode", "opencode.json"),
68
- JSON.stringify({ compaction: { auto: false } }),
69
- );
70
-
71
- const result = isOpenCodeAutoCompactionEnabled(tmpDir);
72
-
73
- expect(result).toBe(false);
74
- });
75
-
76
- it("#when opencode.jsonc #then returns false", () => {
77
- writeFileSync(
78
- join(tmpDir, ".opencode", "opencode.jsonc"),
79
- `{
80
- // compaction disabled
81
- "compaction": { "auto": false }
82
- }`,
83
- );
84
-
85
- const result = isOpenCodeAutoCompactionEnabled(tmpDir);
86
-
87
- expect(result).toBe(false);
88
- });
89
- });
90
-
91
- describe("#given project config has compaction.auto = true", () => {
92
- it("#then returns true", () => {
93
- writeFileSync(
94
- join(tmpDir, ".opencode", "opencode.json"),
95
- JSON.stringify({ compaction: { auto: true } }),
96
- );
97
-
98
- const result = isOpenCodeAutoCompactionEnabled(tmpDir);
99
-
100
- expect(result).toBe(true);
101
- });
102
- });
103
-
104
- describe("#given project config has compaction.prune = true", () => {
105
- it("#then returns true (conflict enabled)", () => {
106
- writeFileSync(
107
- join(tmpDir, ".opencode", "opencode.json"),
108
- JSON.stringify({ compaction: { auto: false, prune: true } }),
109
- );
110
-
111
- const result = isOpenCodeAutoCompactionEnabled(tmpDir);
112
-
113
- expect(result).toBe(true);
114
- });
115
- });
116
-
117
- describe("#given project config has auto/prune both false", () => {
118
- it("#then returns false", () => {
119
- writeFileSync(
120
- join(tmpDir, ".opencode", "opencode.json"),
121
- JSON.stringify({ compaction: { auto: false, prune: false } }),
122
- );
123
-
124
- const result = isOpenCodeAutoCompactionEnabled(tmpDir);
125
-
126
- expect(result).toBe(false);
127
- });
128
- });
129
-
130
- describe("#given project config has only compaction.prune = false", () => {
131
- it("#then returns false", () => {
132
- writeFileSync(
133
- join(tmpDir, ".opencode", "opencode.json"),
134
- JSON.stringify({ compaction: { prune: false } }),
135
- );
136
-
137
- const result = isOpenCodeAutoCompactionEnabled(tmpDir);
138
-
139
- expect(result).toBe(false);
140
- });
141
- });
142
-
143
- describe("#given jsonc and json both exist", () => {
144
- it("#then jsonc takes precedence", () => {
145
- writeFileSync(
146
- join(tmpDir, ".opencode", "opencode.json"),
147
- JSON.stringify({ compaction: { auto: true } }),
148
- );
149
- writeFileSync(
150
- join(tmpDir, ".opencode", "opencode.jsonc"),
151
- `{ "compaction": { "auto": false } }`,
152
- );
153
-
154
- const result = isOpenCodeAutoCompactionEnabled(tmpDir);
155
-
156
- expect(result).toBe(false);
157
- });
158
- });
159
-
160
- describe("#given config exists but no compaction field", () => {
161
- it("#then returns true (default)", () => {
162
- writeFileSync(
163
- join(tmpDir, ".opencode", "opencode.json"),
164
- JSON.stringify({ model: "claude-opus-4-6" }),
165
- );
166
-
167
- const result = isOpenCodeAutoCompactionEnabled(tmpDir);
168
-
169
- expect(result).toBe(true);
170
- });
171
- });
172
-
173
- describe("#given env flag overrides config", () => {
174
- it("#then env flag wins even when config has auto: true", () => {
175
- process.env.OPENCODE_DISABLE_AUTOCOMPACT = "true";
176
- writeFileSync(
177
- join(tmpDir, ".opencode", "opencode.json"),
178
- JSON.stringify({ compaction: { auto: true } }),
179
- );
180
-
181
- const result = isOpenCodeAutoCompactionEnabled(tmpDir);
182
-
183
- expect(result).toBe(false);
184
- });
185
- });
186
-
187
- describe("#given root-level project config", () => {
188
- it("#when root opencode.json has compaction.auto = false #then returns false", () => {
189
- writeFileSync(
190
- join(tmpDir, "opencode.json"),
191
- JSON.stringify({ compaction: { auto: false } }),
192
- );
193
-
194
- const result = isOpenCodeAutoCompactionEnabled(tmpDir);
195
-
196
- expect(result).toBe(false);
197
- });
198
-
199
- it("#when root opencode.jsonc has compaction.auto = false #then returns false", () => {
200
- writeFileSync(join(tmpDir, "opencode.jsonc"), `{ "compaction": { "auto": false } }`);
201
-
202
- const result = isOpenCodeAutoCompactionEnabled(tmpDir);
203
-
204
- expect(result).toBe(false);
205
- });
206
- });
207
-
208
- describe("#given .opencode/ overrides root-level config", () => {
209
- it("#when root says false but .opencode says true #then .opencode wins", () => {
210
- writeFileSync(
211
- join(tmpDir, "opencode.json"),
212
- JSON.stringify({ compaction: { auto: false } }),
213
- );
214
- writeFileSync(
215
- join(tmpDir, ".opencode", "opencode.json"),
216
- JSON.stringify({ compaction: { auto: true } }),
217
- );
218
-
219
- const result = isOpenCodeAutoCompactionEnabled(tmpDir);
220
-
221
- expect(result).toBe(true);
222
- });
223
-
224
- it("#when root says true but .opencode says false #then .opencode wins", () => {
225
- writeFileSync(
226
- join(tmpDir, "opencode.json"),
227
- JSON.stringify({ compaction: { auto: true } }),
228
- );
229
- writeFileSync(
230
- join(tmpDir, ".opencode", "opencode.json"),
231
- JSON.stringify({ compaction: { auto: false } }),
232
- );
233
-
234
- const result = isOpenCodeAutoCompactionEnabled(tmpDir);
235
-
236
- expect(result).toBe(false);
237
- });
238
- });
239
- });
@@ -1,81 +0,0 @@
1
- import { join } from "node:path";
2
- import { readJsoncFile } from "./jsonc-parser";
3
- import { log } from "./logger";
4
- import { getOpenCodeConfigPaths } from "./opencode-config-dir";
5
-
6
- interface OpenCodeConfig {
7
- compaction?: {
8
- auto?: boolean;
9
- prune?: boolean;
10
- };
11
- }
12
-
13
- function hasCompactionConflict(
14
- compaction: OpenCodeConfig["compaction"] | undefined,
15
- ): boolean | undefined {
16
- if (!compaction) return undefined;
17
- const hasExplicitSetting = compaction.auto !== undefined || compaction.prune !== undefined;
18
- if (!hasExplicitSetting) return undefined;
19
- return compaction.auto === true || compaction.prune === true;
20
- }
21
-
22
- export function isOpenCodeAutoCompactionEnabled(directory: string): boolean {
23
- if (process.env.OPENCODE_DISABLE_AUTOCOMPACT) {
24
- log(
25
- "[compaction-detector] OPENCODE_DISABLE_AUTOCOMPACT env flag set — auto compaction disabled",
26
- );
27
- return false;
28
- }
29
-
30
- const projectCompaction = readProjectCompactionConfig(directory);
31
- if (projectCompaction !== undefined) {
32
- log("[compaction-detector] project config compaction conflict =", projectCompaction);
33
- return projectCompaction;
34
- }
35
-
36
- const userCompaction = readUserCompactionConfig(directory);
37
- if (userCompaction !== undefined) {
38
- log("[compaction-detector] user config compaction conflict =", userCompaction);
39
- return userCompaction;
40
- }
41
-
42
- log("[compaction-detector] no compaction config found — default is enabled");
43
- return true;
44
- }
45
-
46
- function readProjectCompactionConfig(directory: string): boolean | undefined {
47
- // .opencode/ dir config has higher precedence than root-level config in OpenCode's loading order.
48
- // Check highest precedence first — if .opencode/ sets compaction.auto, that wins.
49
- const dotOpenCodeJsonc = join(directory, ".opencode", "opencode.jsonc");
50
- const dotOpenCodeJson = join(directory, ".opencode", "opencode.json");
51
- const dotOpenCodeConfig =
52
- readJsoncFile<OpenCodeConfig>(dotOpenCodeJsonc) ??
53
- readJsoncFile<OpenCodeConfig>(dotOpenCodeJson);
54
-
55
- const dotOpenCodeCompactionConflict = hasCompactionConflict(dotOpenCodeConfig?.compaction);
56
- if (dotOpenCodeCompactionConflict !== undefined) {
57
- return dotOpenCodeCompactionConflict;
58
- }
59
-
60
- // Root-level project config (lower precedence than .opencode/)
61
- const rootJsonc = join(directory, "opencode.jsonc");
62
- const rootJson = join(directory, "opencode.json");
63
- const rootConfig =
64
- readJsoncFile<OpenCodeConfig>(rootJsonc) ?? readJsoncFile<OpenCodeConfig>(rootJson);
65
-
66
- return hasCompactionConflict(rootConfig?.compaction);
67
- }
68
-
69
- function readUserCompactionConfig(_directory: string): boolean | undefined {
70
- try {
71
- const paths = getOpenCodeConfigPaths({ binary: "opencode" });
72
- const config =
73
- readJsoncFile<OpenCodeConfig>(paths.configJsonc) ??
74
- readJsoncFile<OpenCodeConfig>(paths.configJson);
75
-
76
- return hasCompactionConflict(config?.compaction);
77
- } catch {
78
- // Intentional: config read is best-effort; missing/unreadable config is not an error
79
- return undefined;
80
- }
81
- }