@cortexkit/opencode-magic-context 0.15.7 → 0.16.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 (191) hide show
  1. package/README.md +41 -15
  2. package/dist/agents/magic-context-prompt.d.ts +2 -13
  3. package/dist/agents/magic-context-prompt.d.ts.map +1 -1
  4. package/dist/cli/diagnostics.d.ts.map +1 -1
  5. package/dist/cli/migrate.d.ts +70 -0
  6. package/dist/cli/migrate.d.ts.map +1 -0
  7. package/dist/cli.js +666 -29
  8. package/dist/config/schema/magic-context.d.ts +67 -4
  9. package/dist/config/schema/magic-context.d.ts.map +1 -1
  10. package/dist/features/magic-context/compaction-marker.d.ts.map +1 -1
  11. package/dist/features/magic-context/compaction.d.ts +1 -1
  12. package/dist/features/magic-context/compaction.d.ts.map +1 -1
  13. package/dist/features/magic-context/compartment-storage.d.ts +1 -1
  14. package/dist/features/magic-context/compartment-storage.d.ts.map +1 -1
  15. package/dist/features/magic-context/compression-depth-storage.d.ts +1 -1
  16. package/dist/features/magic-context/compression-depth-storage.d.ts.map +1 -1
  17. package/dist/features/magic-context/dreamer/lease.d.ts +1 -1
  18. package/dist/features/magic-context/dreamer/lease.d.ts.map +1 -1
  19. package/dist/features/magic-context/dreamer/queue.d.ts +8 -3
  20. package/dist/features/magic-context/dreamer/queue.d.ts.map +1 -1
  21. package/dist/features/magic-context/dreamer/runner.d.ts +1 -1
  22. package/dist/features/magic-context/dreamer/runner.d.ts.map +1 -1
  23. package/dist/features/magic-context/dreamer/scheduler.d.ts +1 -1
  24. package/dist/features/magic-context/dreamer/scheduler.d.ts.map +1 -1
  25. package/dist/features/magic-context/dreamer/storage-dream-runs.d.ts +1 -1
  26. package/dist/features/magic-context/dreamer/storage-dream-runs.d.ts.map +1 -1
  27. package/dist/features/magic-context/dreamer/storage-dream-state.d.ts +1 -1
  28. package/dist/features/magic-context/dreamer/storage-dream-state.d.ts.map +1 -1
  29. package/dist/features/magic-context/git-commits/indexer.d.ts +1 -1
  30. package/dist/features/magic-context/git-commits/indexer.d.ts.map +1 -1
  31. package/dist/features/magic-context/git-commits/search-git-commits.d.ts +1 -1
  32. package/dist/features/magic-context/git-commits/search-git-commits.d.ts.map +1 -1
  33. package/dist/features/magic-context/git-commits/storage-git-commit-embeddings.d.ts +1 -1
  34. package/dist/features/magic-context/git-commits/storage-git-commit-embeddings.d.ts.map +1 -1
  35. package/dist/features/magic-context/git-commits/storage-git-commits.d.ts +1 -1
  36. package/dist/features/magic-context/git-commits/storage-git-commits.d.ts.map +1 -1
  37. package/dist/features/magic-context/key-files/identify-key-files.d.ts +1 -1
  38. package/dist/features/magic-context/key-files/identify-key-files.d.ts.map +1 -1
  39. package/dist/features/magic-context/key-files/read-stats.d.ts +1 -1
  40. package/dist/features/magic-context/key-files/read-stats.d.ts.map +1 -1
  41. package/dist/features/magic-context/key-files/storage-key-files.d.ts +1 -1
  42. package/dist/features/magic-context/key-files/storage-key-files.d.ts.map +1 -1
  43. package/dist/features/magic-context/memory/embedding-backfill.d.ts +1 -1
  44. package/dist/features/magic-context/memory/embedding-backfill.d.ts.map +1 -1
  45. package/dist/features/magic-context/memory/embedding-cache.d.ts +1 -1
  46. package/dist/features/magic-context/memory/embedding-cache.d.ts.map +1 -1
  47. package/dist/features/magic-context/memory/embedding-local.d.ts.map +1 -1
  48. package/dist/features/magic-context/memory/embedding.d.ts +1 -1
  49. package/dist/features/magic-context/memory/embedding.d.ts.map +1 -1
  50. package/dist/features/magic-context/memory/normalize-hash.d.ts.map +1 -1
  51. package/dist/features/magic-context/memory/project-identity.d.ts.map +1 -1
  52. package/dist/features/magic-context/memory/promotion.d.ts +1 -1
  53. package/dist/features/magic-context/memory/promotion.d.ts.map +1 -1
  54. package/dist/features/magic-context/memory/storage-memory-embeddings.d.ts +1 -1
  55. package/dist/features/magic-context/memory/storage-memory-embeddings.d.ts.map +1 -1
  56. package/dist/features/magic-context/memory/storage-memory-fts.d.ts +1 -1
  57. package/dist/features/magic-context/memory/storage-memory-fts.d.ts.map +1 -1
  58. package/dist/features/magic-context/memory/storage-memory.d.ts +1 -1
  59. package/dist/features/magic-context/memory/storage-memory.d.ts.map +1 -1
  60. package/dist/features/magic-context/message-index.d.ts +1 -1
  61. package/dist/features/magic-context/message-index.d.ts.map +1 -1
  62. package/dist/features/magic-context/migrations.d.ts +1 -1
  63. package/dist/features/magic-context/migrations.d.ts.map +1 -1
  64. package/dist/features/magic-context/mock-database.d.ts +1 -1
  65. package/dist/features/magic-context/mock-database.d.ts.map +1 -1
  66. package/dist/features/magic-context/plugin-messages.d.ts +1 -1
  67. package/dist/features/magic-context/plugin-messages.d.ts.map +1 -1
  68. package/dist/features/magic-context/search.d.ts +1 -1
  69. package/dist/features/magic-context/search.d.ts.map +1 -1
  70. package/dist/features/magic-context/sidekick/agent.d.ts +2 -1
  71. package/dist/features/magic-context/sidekick/agent.d.ts.map +1 -1
  72. package/dist/features/magic-context/sidekick/core.d.ts +38 -0
  73. package/dist/features/magic-context/sidekick/core.d.ts.map +1 -0
  74. package/dist/features/magic-context/storage-db.d.ts +20 -1
  75. package/dist/features/magic-context/storage-db.d.ts.map +1 -1
  76. package/dist/features/magic-context/storage-meta-persisted.d.ts +1 -1
  77. package/dist/features/magic-context/storage-meta-persisted.d.ts.map +1 -1
  78. package/dist/features/magic-context/storage-meta-session.d.ts +1 -1
  79. package/dist/features/magic-context/storage-meta-session.d.ts.map +1 -1
  80. package/dist/features/magic-context/storage-meta-shared.d.ts +1 -1
  81. package/dist/features/magic-context/storage-meta-shared.d.ts.map +1 -1
  82. package/dist/features/magic-context/storage-notes.d.ts +1 -1
  83. package/dist/features/magic-context/storage-notes.d.ts.map +1 -1
  84. package/dist/features/magic-context/storage-ops.d.ts +1 -1
  85. package/dist/features/magic-context/storage-ops.d.ts.map +1 -1
  86. package/dist/features/magic-context/storage-source.d.ts +1 -1
  87. package/dist/features/magic-context/storage-source.d.ts.map +1 -1
  88. package/dist/features/magic-context/storage-tags.d.ts +17 -1
  89. package/dist/features/magic-context/storage-tags.d.ts.map +1 -1
  90. package/dist/features/magic-context/tagger.d.ts +1 -1
  91. package/dist/features/magic-context/tagger.d.ts.map +1 -1
  92. package/dist/features/magic-context/user-memory/review-user-memories.d.ts +1 -1
  93. package/dist/features/magic-context/user-memory/review-user-memories.d.ts.map +1 -1
  94. package/dist/features/magic-context/user-memory/storage-user-memory.d.ts +1 -1
  95. package/dist/features/magic-context/user-memory/storage-user-memory.d.ts.map +1 -1
  96. package/dist/hooks/magic-context/auto-search-hint.d.ts.map +1 -1
  97. package/dist/hooks/magic-context/auto-search-runner.d.ts +1 -1
  98. package/dist/hooks/magic-context/auto-search-runner.d.ts.map +1 -1
  99. package/dist/hooks/magic-context/command-handler.d.ts +1 -1
  100. package/dist/hooks/magic-context/command-handler.d.ts.map +1 -1
  101. package/dist/hooks/magic-context/compaction-marker-manager.d.ts +1 -1
  102. package/dist/hooks/magic-context/compaction-marker-manager.d.ts.map +1 -1
  103. package/dist/hooks/magic-context/compartment-prompt.d.ts +1 -0
  104. package/dist/hooks/magic-context/compartment-prompt.d.ts.map +1 -1
  105. package/dist/hooks/magic-context/compartment-runner-compressor.d.ts +1 -1
  106. package/dist/hooks/magic-context/compartment-runner-compressor.d.ts.map +1 -1
  107. package/dist/hooks/magic-context/compartment-runner-drop-queue.d.ts +1 -1
  108. package/dist/hooks/magic-context/compartment-runner-drop-queue.d.ts.map +1 -1
  109. package/dist/hooks/magic-context/compartment-runner-incremental.d.ts +1 -0
  110. package/dist/hooks/magic-context/compartment-runner-incremental.d.ts.map +1 -1
  111. package/dist/hooks/magic-context/compartment-runner-recomp.d.ts.map +1 -1
  112. package/dist/hooks/magic-context/compartment-runner-types.d.ts +1 -1
  113. package/dist/hooks/magic-context/compartment-runner-types.d.ts.map +1 -1
  114. package/dist/hooks/magic-context/compartment-trigger.d.ts +1 -1
  115. package/dist/hooks/magic-context/compartment-trigger.d.ts.map +1 -1
  116. package/dist/hooks/magic-context/execute-flush.d.ts +1 -1
  117. package/dist/hooks/magic-context/execute-flush.d.ts.map +1 -1
  118. package/dist/hooks/magic-context/execute-status.d.ts +1 -1
  119. package/dist/hooks/magic-context/execute-status.d.ts.map +1 -1
  120. package/dist/hooks/magic-context/historian-state-file.d.ts +29 -0
  121. package/dist/hooks/magic-context/historian-state-file.d.ts.map +1 -0
  122. package/dist/hooks/magic-context/hook.d.ts.map +1 -1
  123. package/dist/hooks/magic-context/inject-compartments.d.ts +1 -1
  124. package/dist/hooks/magic-context/inject-compartments.d.ts.map +1 -1
  125. package/dist/hooks/magic-context/note-nudger.d.ts +1 -1
  126. package/dist/hooks/magic-context/note-nudger.d.ts.map +1 -1
  127. package/dist/hooks/magic-context/nudge-placement-store.d.ts +1 -1
  128. package/dist/hooks/magic-context/nudge-placement-store.d.ts.map +1 -1
  129. package/dist/hooks/magic-context/read-session-chunk.d.ts +39 -0
  130. package/dist/hooks/magic-context/read-session-chunk.d.ts.map +1 -1
  131. package/dist/hooks/magic-context/read-session-db.d.ts +1 -1
  132. package/dist/hooks/magic-context/read-session-db.d.ts.map +1 -1
  133. package/dist/hooks/magic-context/read-session-raw.d.ts +1 -1
  134. package/dist/hooks/magic-context/read-session-raw.d.ts.map +1 -1
  135. package/dist/hooks/magic-context/send-session-notification.d.ts.map +1 -1
  136. package/dist/hooks/magic-context/system-prompt-hash.d.ts +6 -5
  137. package/dist/hooks/magic-context/system-prompt-hash.d.ts.map +1 -1
  138. package/dist/hooks/magic-context/transform-postprocess-phase.d.ts.map +1 -1
  139. package/dist/hooks/magic-context/transform.d.ts.map +1 -1
  140. package/dist/index.js +8284 -8166
  141. package/dist/plugin/hooks/create-session-hooks.d.ts.map +1 -1
  142. package/dist/plugin/messages-transform.d.ts +1 -1
  143. package/dist/plugin/rpc-handlers.d.ts +4 -0
  144. package/dist/plugin/rpc-handlers.d.ts.map +1 -1
  145. package/dist/plugin/tool-registry.d.ts.map +1 -1
  146. package/dist/shared/conflict-detector.d.ts.map +1 -1
  147. package/dist/shared/data-path.d.ts +22 -0
  148. package/dist/shared/data-path.d.ts.map +1 -1
  149. package/dist/shared/harness.d.ts +43 -0
  150. package/dist/shared/harness.d.ts.map +1 -0
  151. package/dist/shared/rpc-notifications.d.ts +4 -2
  152. package/dist/shared/rpc-notifications.d.ts.map +1 -1
  153. package/dist/shared/sqlite-helpers.d.ts +16 -0
  154. package/dist/shared/sqlite-helpers.d.ts.map +1 -0
  155. package/dist/shared/sqlite.d.ts +55 -0
  156. package/dist/shared/sqlite.d.ts.map +1 -0
  157. package/dist/shared/subagent-runner.d.ts +202 -0
  158. package/dist/shared/subagent-runner.d.ts.map +1 -0
  159. package/dist/shared/tag-transcript.d.ts +66 -0
  160. package/dist/shared/tag-transcript.d.ts.map +1 -0
  161. package/dist/shared/transcript-opencode.d.ts +71 -0
  162. package/dist/shared/transcript-opencode.d.ts.map +1 -0
  163. package/dist/shared/transcript.d.ts +212 -0
  164. package/dist/shared/transcript.d.ts.map +1 -0
  165. package/dist/shared/tui-config.d.ts.map +1 -1
  166. package/dist/tools/ctx-memory/tools.d.ts.map +1 -1
  167. package/dist/tools/ctx-memory/types.d.ts +13 -2
  168. package/dist/tools/ctx-memory/types.d.ts.map +1 -1
  169. package/dist/tools/ctx-note/tools.d.ts +8 -2
  170. package/dist/tools/ctx-note/tools.d.ts.map +1 -1
  171. package/dist/tools/ctx-reduce/tools.d.ts +1 -1
  172. package/dist/tools/ctx-reduce/tools.d.ts.map +1 -1
  173. package/dist/tools/ctx-search/tools.d.ts.map +1 -1
  174. package/dist/tools/ctx-search/types.d.ts +8 -2
  175. package/dist/tools/ctx-search/types.d.ts.map +1 -1
  176. package/dist/tui/data/context-db.d.ts.map +1 -1
  177. package/package.json +7 -5
  178. package/src/shared/conflict-detector.test.ts +44 -1
  179. package/src/shared/conflict-detector.ts +24 -8
  180. package/src/shared/data-path.test.ts +53 -1
  181. package/src/shared/data-path.ts +28 -0
  182. package/src/shared/harness.ts +61 -0
  183. package/src/shared/rpc-notifications.ts +11 -5
  184. package/src/shared/sqlite-helpers.ts +27 -0
  185. package/src/shared/sqlite.ts +91 -0
  186. package/src/shared/subagent-runner.ts +206 -0
  187. package/src/shared/tag-transcript.ts +541 -0
  188. package/src/shared/transcript-opencode.ts +259 -0
  189. package/src/shared/transcript.ts +226 -0
  190. package/src/shared/tui-config.ts +34 -8
  191. package/src/tui/data/context-db.ts +5 -1
@@ -1 +1 @@
1
- {"version":3,"file":"create-session-hooks.d.ts","sourceRoot":"","sources":["../../../src/plugin/hooks/create-session-hooks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AAU7D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,8CAA8C,CAAC;AACrF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAE9C,wBAAgB,kBAAkB,CAAC,IAAI,EAAE;IACrC,GAAG,EAAE,aAAa,CAAC;IACnB,YAAY,EAAE,wBAAwB,CAAC;IACvC,gBAAgB,EAAE,gBAAgB,CAAC;CACtC;;;;;;qBAmDu0E,CAAC;;;;;;;;;;;;qBAAqd,CAAC;mBAAyB,CAAC;iBAAuB,CAAC;iBAAuB,CAAC;0BAAc,CAAC;uBAAiB,CAAC;;;;;;0BAAi+mB,CAAC;;;;;;EAD32sB"}
1
+ {"version":3,"file":"create-session-hooks.d.ts","sourceRoot":"","sources":["../../../src/plugin/hooks/create-session-hooks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AAU7D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,8CAA8C,CAAC;AACrF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAE9C,wBAAgB,kBAAkB,CAAC,IAAI,EAAE;IACrC,GAAG,EAAE,aAAa,CAAC;IACnB,YAAY,EAAE,wBAAwB,CAAC;IACvC,gBAAgB,EAAE,gBAAgB,CAAC;CACtC;;;;;;qBAmD04E,CAAC;;;;;;;;;;;;qBAAkZ,CAAC;mBAAyB,CAAC;iBAAuB,CAAC;iBAAuB,CAAC;0BAAc,CAAC;uBAAiB,CAAC;;;;;;0BAAy7nB,CAAC;;;;;;EADn0tB"}
@@ -9,7 +9,7 @@ type MessagesTransformOutput = {
9
9
  * Top-level transform wrapper. Catches errors so OpenCode's prompt loop
10
10
  * always proceeds — without this guard, a transient DB contention event can
11
11
  * crash the user's turn through OpenCode's Effect pipeline. See issue #23:
12
- * https://github.com/cortexkit/opencode-magic-context/issues/23
12
+ * https://github.com/cortexkit/magic-context/issues/23
13
13
  *
14
14
  * Error handling is tiered:
15
15
  *
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Server-side RPC handlers. Queries the server's own SQLite DB
3
+ * and returns typed responses for TUI consumption.
4
+ */
1
5
  import type { MagicContextConfig } from "../config/schema/magic-context";
2
6
  import type { LiveSessionState } from "../hooks/magic-context/live-session-state";
3
7
  import type { MagicContextRpcServer } from "../shared/rpc-server";
@@ -1 +1 @@
1
- {"version":3,"file":"rpc-handlers.d.ts","sourceRoot":"","sources":["../../src/plugin/rpc-handlers.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAMzE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,2CAA2C,CAAC;AAQlF,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAkflE;;GAEG;AACH,wBAAgB,mBAAmB,CAC/B,SAAS,EAAE,qBAAqB,EAChC,IAAI,EAAE;IACF,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,kBAAkB,CAAC;IAC3B,MAAM,EAAE,OAAO,CAAC;IAChB,gBAAgB,EAAE,gBAAgB,CAAC;CACtC,GACF,IAAI,CA8HN"}
1
+ {"version":3,"file":"rpc-handlers.d.ts","sourceRoot":"","sources":["../../src/plugin/rpc-handlers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAMzE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,2CAA2C,CAAC;AAQlF,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAkflE;;GAEG;AACH,wBAAgB,mBAAmB,CAC/B,SAAS,EAAE,qBAAqB,EAChC,IAAI,EAAE;IACF,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,kBAAkB,CAAC;IAC3B,MAAM,EAAE,OAAO,CAAC;IAChB,gBAAgB,EAAE,gBAAgB,CAAC;CACtC,GACF,IAAI,CA8HN"}
@@ -1 +1 @@
1
- {"version":3,"file":"tool-registry.d.ts","sourceRoot":"","sources":["../../src/plugin/tool-registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,WAAW,CAAC;AAqB1D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C,wBAAgB,kBAAkB,CAAC,IAAI,EAAE;IACrC,GAAG,EAAE,aAAa,CAAC;IACnB,YAAY,EAAE,wBAAwB,CAAC;CAC1C,GAAG,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAsFjC"}
1
+ {"version":3,"file":"tool-registry.d.ts","sourceRoot":"","sources":["../../src/plugin/tool-registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,WAAW,CAAC;AAqB1D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C,wBAAgB,kBAAkB,CAAC,IAAI,EAAE;IACrC,GAAG,EAAE,aAAa,CAAC;IACnB,YAAY,EAAE,wBAAwB,CAAC;CAC1C,GAAG,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CA8GjC"}
@@ -1 +1 @@
1
- {"version":3,"file":"conflict-detector.d.ts","sourceRoot":"","sources":["../../src/shared/conflict-detector.ts"],"names":[],"mappings":"AAgBA,MAAM,WAAW,cAAc;IAC3B,8CAA8C;IAC9C,WAAW,EAAE,OAAO,CAAC;IACrB,+CAA+C;IAC/C,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,2DAA2D;IAC3D,SAAS,EAAE;QACP,cAAc,EAAE,OAAO,CAAC;QACxB,eAAe,EAAE,OAAO,CAAC;QACzB,SAAS,EAAE,OAAO,CAAC;QACnB,uBAAuB,EAAE,OAAO,CAAC;QACjC,uBAAuB,EAAE,OAAO,CAAC;QACjC,oBAAoB,EAAE,OAAO,CAAC;KACjC,CAAC;CACL;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,cAAc,CAyDjE;AAuPD;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,cAAc,GAAG,MAAM,CAWlE"}
1
+ {"version":3,"file":"conflict-detector.d.ts","sourceRoot":"","sources":["../../src/shared/conflict-detector.ts"],"names":[],"mappings":"AAiBA,MAAM,WAAW,cAAc;IAC3B,8CAA8C;IAC9C,WAAW,EAAE,OAAO,CAAC;IACrB,+CAA+C;IAC/C,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,2DAA2D;IAC3D,SAAS,EAAE;QACP,cAAc,EAAE,OAAO,CAAC;QACxB,eAAe,EAAE,OAAO,CAAC;QACzB,SAAS,EAAE,OAAO,CAAC;QACnB,uBAAuB,EAAE,OAAO,CAAC;QACjC,uBAAuB,EAAE,OAAO,CAAC;QACjC,oBAAoB,EAAE,OAAO,CAAC;KACjC,CAAC;CACL;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,cAAc,CAyDjE;AAsQD;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,cAAc,GAAG,MAAM,CAWlE"}
@@ -1,5 +1,27 @@
1
1
  export declare function getDataDir(): string;
2
2
  export declare function getOpenCodeStorageDir(): string;
3
+ /**
4
+ * Resolve the shared magic-context storage directory.
5
+ *
6
+ * Magic-context's own data (compartments, facts, memories, embeddings, dream
7
+ * runs, notes, etc.) lives at this path regardless of which harness loaded the
8
+ * plugin (OpenCode or Pi). This enables:
9
+ * - Shared project memories across harnesses
10
+ * - Shared embedding cache
11
+ * - Shared Dreamer runs (one per project per machine)
12
+ * - Future cross-harness session migration
13
+ *
14
+ * Layout: <XDG_DATA_HOME>/cortexkit/magic-context/
15
+ */
16
+ export declare function getMagicContextStorageDir(): string;
17
+ /**
18
+ * Legacy magic-context storage directory used by the OpenCode plugin before the
19
+ * shared cortexkit path. Used only for one-time migration of existing data into
20
+ * the new shared location. The legacy directory is left in place after copy so
21
+ * users can roll back if needed; manual cleanup is safe after one stable
22
+ * release.
23
+ */
24
+ export declare function getLegacyOpenCodeMagicContextStorageDir(): string;
3
25
  /**
4
26
  * Resolve OpenCode's cache base directory.
5
27
  *
@@ -1 +1 @@
1
- {"version":3,"file":"data-path.d.ts","sourceRoot":"","sources":["../../src/shared/data-path.ts"],"names":[],"mappings":"AAGA,wBAAgB,UAAU,IAAI,MAAM,CAEnC;AAED,wBAAgB,qBAAqB,IAAI,MAAM,CAE9C;AAED;;;;;;;;;GASG;AACH,wBAAgB,WAAW,IAAI,MAAM,CAEpC;AAED,wBAAgB,mBAAmB,IAAI,MAAM,CAE5C"}
1
+ {"version":3,"file":"data-path.d.ts","sourceRoot":"","sources":["../../src/shared/data-path.ts"],"names":[],"mappings":"AAGA,wBAAgB,UAAU,IAAI,MAAM,CAEnC;AAED,wBAAgB,qBAAqB,IAAI,MAAM,CAE9C;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,yBAAyB,IAAI,MAAM,CAElD;AAED;;;;;;GAMG;AACH,wBAAgB,uCAAuC,IAAI,MAAM,CAEhE;AAED;;;;;;;;;GASG;AACH,wBAAgB,WAAW,IAAI,MAAM,CAEpC;AAED,wBAAgB,mBAAmB,IAAI,MAAM,CAE5C"}
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Identifier for the host harness this plugin is running inside.
3
+ *
4
+ * Magic Context's SQLite database lives at a vendor-scoped path
5
+ * (`~/.local/share/cortexkit/magic-context/`) so OpenCode and Pi can share
6
+ * project memories, embedding cache, dreamer runs, and other project-scoped
7
+ * state. Session-scoped tables carry a `harness` column populated from this
8
+ * module so we can disambiguate which harness wrote each session row,
9
+ * filter by harness in the dashboard, and (eventually) migrate sessions
10
+ * between harnesses.
11
+ *
12
+ * Each plugin entry point sets this once at boot, before any DB write
13
+ * happens:
14
+ * - OpenCode plugin: relies on the default ("opencode") — no setHarness call
15
+ * needed
16
+ * - Pi plugin: calls `setHarness("pi")` before opening the database
17
+ *
18
+ * NEVER read this from configuration or session state — it is a
19
+ * boot-time constant per plugin instance. Cross-harness leakage is a
20
+ * correctness bug, not a feature.
21
+ */
22
+ export type HarnessId = "opencode" | "pi";
23
+ /**
24
+ * Set the harness identifier for this plugin instance. Must be called once
25
+ * at boot before any DB write happens. Subsequent calls with a different
26
+ * value throw to prevent accidental mid-session swaps that would corrupt
27
+ * the harness column and break per-harness session scoping.
28
+ *
29
+ * Calling with the same value as the current is a no-op (safe to call
30
+ * defensively).
31
+ */
32
+ export declare function setHarness(value: HarnessId): void;
33
+ /**
34
+ * Get the current harness identifier. Used by storage modules when
35
+ * INSERTing session-scoped rows so each row is correctly attributed.
36
+ */
37
+ export declare function getHarness(): HarnessId;
38
+ /**
39
+ * Test-only helper to reset harness state between test cases. Do NOT call
40
+ * from production code paths.
41
+ */
42
+ export declare function _resetHarnessForTesting(): void;
43
+ //# sourceMappingURL=harness.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"harness.d.ts","sourceRoot":"","sources":["../../src/shared/harness.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,MAAM,SAAS,GAAG,UAAU,GAAG,IAAI,CAAC;AAK1C;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI,CAQjD;AAED;;;GAGG;AACH,wBAAgB,UAAU,IAAI,SAAS,CAEtC;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,IAAI,IAAI,CAG9C"}
@@ -14,8 +14,10 @@ export interface RpcNotification {
14
14
  /** Push a notification for TUI to pick up via polling. */
15
15
  export declare function pushNotification(type: string, payload: Record<string, unknown>, sessionId?: string): void;
16
16
  /** Drain and return all pending notifications atomically.
17
- * Also marks TUI as connected since only TUI polls this. */
17
+ * Updates lastDrainAt so isTuiConnected() reflects recent activity. */
18
18
  export declare function drainNotifications(): RpcNotification[];
19
- /** Whether a TUI client has connected and is polling for notifications. */
19
+ /** Whether a TUI client is actively polling for notifications.
20
+ * Returns true only if the TUI has drained within the last 3 seconds.
21
+ * This prevents stale-connected state after TUI closes or disconnects. */
20
22
  export declare function isTuiConnected(): boolean;
21
23
  //# sourceMappingURL=rpc-notifications.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"rpc-notifications.d.ts","sourceRoot":"","sources":["../../src/shared/rpc-notifications.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,WAAW,eAAe;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB;AAKD,0DAA0D;AAC1D,wBAAgB,gBAAgB,CAC5B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,SAAS,CAAC,EAAE,MAAM,GACnB,IAAI,CAMN;AAED;6DAC6D;AAC7D,wBAAgB,kBAAkB,IAAI,eAAe,EAAE,CAKtD;AAED,2EAA2E;AAC3E,wBAAgB,cAAc,IAAI,OAAO,CAExC"}
1
+ {"version":3,"file":"rpc-notifications.d.ts","sourceRoot":"","sources":["../../src/shared/rpc-notifications.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,WAAW,eAAe;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB;AASD,0DAA0D;AAC1D,wBAAgB,gBAAgB,CAC5B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,SAAS,CAAC,EAAE,MAAM,GACnB,IAAI,CAMN;AAED;wEACwE;AACxE,wBAAgB,kBAAkB,IAAI,eAAe,EAAE,CAKtD;AAED;;2EAE2E;AAC3E,wBAAgB,cAAc,IAAI,OAAO,CAExC"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Cross-runtime helpers that smooth over the small bun:sqlite ↔ better-sqlite3
3
+ * API differences without leaking either library into call sites.
4
+ */
5
+ import type { Database } from "./sqlite";
6
+ /**
7
+ * Close a database, ignoring errors.
8
+ *
9
+ * bun:sqlite supports `db.close(throwOnError = false)`. better-sqlite3 has
10
+ * only `db.close()` and throws on already-closed databases. This helper
11
+ * mirrors the bun "swallow errors" semantics for both runtimes — useful in
12
+ * test teardown and `finally` blocks where the caller doesn't care whether
13
+ * the close succeeded.
14
+ */
15
+ export declare function closeQuietly(db: Database | null | undefined): void;
16
+ //# sourceMappingURL=sqlite-helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sqlite-helpers.d.ts","sourceRoot":"","sources":["../../src/shared/sqlite-helpers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEzC;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,EAAE,EAAE,QAAQ,GAAG,IAAI,GAAG,SAAS,GAAG,IAAI,CAUlE"}
@@ -0,0 +1,55 @@
1
+ /**
2
+ * SQLite chokepoint — runtime-detected backend selection.
3
+ *
4
+ * The same shipped plugin artifact must run under two different runtimes:
5
+ * - Bun (current OpenCode releases) → uses `bun:sqlite` (built-in, fast)
6
+ * - Node (OpenCode beta + future Pi plugin) → uses `better-sqlite3`
7
+ *
8
+ * Bun cannot load `better-sqlite3` (oven-sh/bun#4290), and Node has no
9
+ * `bun:sqlite` module. Static imports of either would crash at parse time
10
+ * in the wrong runtime, so we use dynamic imports gated by runtime detection.
11
+ *
12
+ * The Function-constructor wrapper around `import()` defeats bundler static
13
+ * analysis — without it, esbuild/bun build would try to resolve both modules
14
+ * during the bundle step, including the one that doesn't exist in the build
15
+ * runtime.
16
+ *
17
+ * Both libraries expose ~95% API parity:
18
+ * - new Database(path, { readonly?: boolean })
19
+ * - db.prepare(sql).run/get/all
20
+ * - db.exec(multistatement)
21
+ * - db.transaction(fn) → wrapped function
22
+ * - db.close()
23
+ *
24
+ * The 5% that differs (db.query, db.run, db.close(boolean), Database.open)
25
+ * is either rewritten to common-subset patterns or hidden behind the helpers
26
+ * in `./sqlite-helpers.ts`.
27
+ */
28
+ /**
29
+ * Database constructor compatible with both bun:sqlite and better-sqlite3.
30
+ *
31
+ * The TypeScript type intentionally references @types/better-sqlite3 because
32
+ * its definitions are richer than @types/bun's bun:sqlite types and bun:sqlite
33
+ * is a structural superset for the API surface we use. Calls written against
34
+ * this type work correctly under both runtimes at runtime.
35
+ *
36
+ * @types/better-sqlite3 uses `export = Database` (CommonJS interop), which
37
+ * surfaces in TypeScript as `import Database = require("better-sqlite3")`.
38
+ * We capture the DatabaseConstructor type from the namespace re-export.
39
+ */
40
+ import type BetterSqlite3 from "better-sqlite3";
41
+ export declare const Database: typeof BetterSqlite3;
42
+ /** Instance type alias used by helpers and storage modules. */
43
+ export type Database = BetterSqlite3.Database;
44
+ /**
45
+ * Statement instance type used for WeakMap caches throughout the codebase.
46
+ *
47
+ * We deliberately use the variadic Statement<unknown[], unknown> shape rather
48
+ * than `ReturnType<Database["prepare"]>` because the latter resolves through
49
+ * a conditional return type in @types/better-sqlite3 that confuses TypeScript
50
+ * about how many arguments .run/.get/.all accept. With this explicit type,
51
+ * cached statements accept any number of bind args (matching bun:sqlite's
52
+ * historical behavior in this codebase).
53
+ */
54
+ export type Statement = BetterSqlite3.Statement<unknown[], unknown>;
55
+ //# sourceMappingURL=sqlite.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sqlite.d.ts","sourceRoot":"","sources":["../../src/shared/sqlite.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAmCH;;;;;;;;;;;GAWG;AACH,OAAO,KAAK,aAAa,MAAM,gBAAgB,CAAC;AAEhD,eAAO,MAAM,QAAQ,EAAE,OAAO,aAA4B,CAAC;AAE3D,+DAA+D;AAC/D,MAAM,MAAM,QAAQ,GAAG,aAAa,CAAC,QAAQ,CAAC;AAE9C;;;;;;;;;GASG;AACH,MAAM,MAAM,SAAS,GAAG,aAAa,CAAC,SAAS,CAAC,OAAO,EAAE,EAAE,OAAO,CAAC,CAAC"}
@@ -0,0 +1,202 @@
1
+ /**
2
+ * Cross-harness subagent runner abstraction.
3
+ *
4
+ * Magic Context spawns three kinds of subagents — historian, dreamer, sidekick —
5
+ * each as a child "session" with its own model/prompt/tools. OpenCode and Pi
6
+ * have very different APIs for this:
7
+ *
8
+ * - OpenCode: `client.session.create({parentID}) → client.session.prompt() →
9
+ * client.session.messages() → client.session.delete()`. The plugin runs
10
+ * in-process with the OpenCode server and uses its SDK client directly.
11
+ *
12
+ * - Pi: no in-process child-session API. Instead `pi --print --mode=json`
13
+ * spawns a non-interactive subprocess that emits structured JSON events
14
+ * and exits when the agent loop finishes. Sessions are JSONL files on
15
+ * disk, optionally addressed via `--session <path>`.
16
+ *
17
+ * The runner interface below normalizes both into the same shape so the
18
+ * actual subagent business logic (historian XML parsing, dreamer task loop,
19
+ * sidekick augmentation) can stay harness-agnostic. Each harness ships its
20
+ * own runner implementation; agents take a `SubagentRunner` as a dep instead
21
+ * of reaching for `client.session.*` directly.
22
+ *
23
+ * Step 5a (this commit) defines the contract and ships `PiSubagentRunner`.
24
+ * Step 5b will refactor the OpenCode-side spawn paths in
25
+ * `compartment-runner-historian.ts`, `dreamer/runner.ts`, and
26
+ * `sidekick/agent.ts` onto an `OpenCodeSubagentRunner` so both harnesses
27
+ * share the agent business logic instead of duplicating it. Until 5b lands,
28
+ * OpenCode keeps its existing direct `client.session.*` calls untouched —
29
+ * the runner contract is purely additive on the OpenCode side.
30
+ */
31
+ /**
32
+ * Configuration for one subagent invocation.
33
+ *
34
+ * Mirrors the union of OpenCode's `session.create` + `session.prompt` body
35
+ * fields and Pi's `--print` CLI flags, picking the shared subset that all
36
+ * three subagent kinds (historian, dreamer, sidekick) actually use today.
37
+ *
38
+ * Fields:
39
+ * - `agent`: harness-specific agent name. OpenCode looks this up in its
40
+ * agent registry (`HISTORIAN_AGENT`, `DREAMER_AGENT`, `SIDEKICK_AGENT`).
41
+ * Pi has no concept of "agent name" beyond config, so this is ignored
42
+ * on the Pi side and used only by `OpenCodeSubagentRunner`.
43
+ * - `systemPrompt`: full system prompt for this child run. Replaces (not
44
+ * appends to) any harness-default system prompt.
45
+ * - `userMessage`: the single user-turn prompt. Subagent runs are always
46
+ * one-shot — no multi-turn conversation in the child.
47
+ * - `model`: provider/model identifier in the canonical "provider/model"
48
+ * shape (e.g. "anthropic/claude-sonnet-4-7"). Each runner is responsible
49
+ * for translating to its harness's native model selection.
50
+ * - `fallbackModels`: ordered list of models to try if `model` fails. Both
51
+ * harnesses retry on transient model failures.
52
+ * - `timeoutMs`: hard cap on the child run. The runner aborts the child on
53
+ * exceeding this and returns `{ ok: false, reason: "timeout" }`.
54
+ * - `cwd`: working directory for the child. OpenCode uses this for
55
+ * `query.directory`; Pi uses it as the spawn cwd so that `--cwd`-aware
56
+ * tools see the right project root.
57
+ * - `signal`: optional AbortSignal so callers can cancel an in-flight run
58
+ * (used by dreamer's lease-renewal-aborts-on-loss path).
59
+ */
60
+ export interface SubagentRunOptions {
61
+ agent: string;
62
+ systemPrompt: string;
63
+ userMessage: string;
64
+ model?: string | undefined;
65
+ fallbackModels?: readonly string[];
66
+ timeoutMs?: number | undefined;
67
+ cwd?: string | undefined;
68
+ signal?: AbortSignal | undefined;
69
+ /**
70
+ * Pi only: explicit thinking level, passed as `--thinking <level>` to the
71
+ * Pi subprocess. OpenCode ignores this field — thinking/reasoning is
72
+ * controlled via `variant` in the OpenCode agent config instead.
73
+ *
74
+ * Required when the configured historian/dreamer model supports reasoning
75
+ * (e.g. github-copilot/gpt-5.4) because Pi's own default resolution may
76
+ * pick a value the provider rejects. Set to "off" to disable thinking for
77
+ * speed (local models), or "medium"/"high" for better quality.
78
+ */
79
+ thinkingLevel?: string | undefined;
80
+ /**
81
+ * Optional progress callback. The runner invokes it for milestone events
82
+ * during the run: spawn, first event received, terminal stop reason
83
+ * detected, child exit. Used by historian/dreamer/sidekick to write
84
+ * lifecycle entries to the magic-context.log without polluting the
85
+ * normal stdout stream.
86
+ *
87
+ * Implementations must be non-throwing and fast — they're called on the
88
+ * runner's hot path. Errors are swallowed.
89
+ */
90
+ onProgress?: (event: SubagentProgressEvent) => void;
91
+ }
92
+ /**
93
+ * Progress events emitted by a runner during a run. Distinct from the final
94
+ * `SubagentRunResult` — these are mid-run milestones plus (optionally) every
95
+ * raw event the underlying harness emits, so callers can write a complete
96
+ * trace to the log when diagnosing hangs.
97
+ *
98
+ * Categories:
99
+ * - `spawned` / `child_exit` / `stderr` — process lifecycle.
100
+ * - `first_event` — convenience: first event received from the child, useful
101
+ * for measuring auth/network warmup time.
102
+ * - `terminal` — runner detected the final assistant turn (Pi: assistant
103
+ * message_end with terminal stopReason and no toolCall; OpenCode: SDK
104
+ * `agent_end` equivalent).
105
+ * - `raw_event` — every parsed event from the harness's structured output
106
+ * stream (Pi NDJSON / OpenCode SDK events). Emitted unconditionally so
107
+ * debug logs can capture the full timeline. The `event` payload is
108
+ * harness-shaped — callers should treat it as `unknown` and log it raw.
109
+ */
110
+ export type SubagentProgressEvent = {
111
+ type: "spawned";
112
+ argv: readonly string[];
113
+ pid: number | undefined;
114
+ } | {
115
+ type: "first_event";
116
+ eventType: string;
117
+ ms: number;
118
+ } | {
119
+ type: "raw_event";
120
+ eventType: string | undefined;
121
+ event: unknown;
122
+ ms: number;
123
+ } | {
124
+ type: "terminal";
125
+ stopReason: string | undefined;
126
+ textLength: number;
127
+ hasToolCall: boolean;
128
+ ms: number;
129
+ } | {
130
+ type: "stderr";
131
+ chunk: string;
132
+ } | {
133
+ type: "child_exit";
134
+ code: number | null;
135
+ signal: string | null;
136
+ ms: number;
137
+ };
138
+ /**
139
+ * Result of one subagent invocation.
140
+ *
141
+ * The runner contract is "fail soft": transient errors, timeouts, model
142
+ * failures, and aborts all surface as `{ ok: false, reason }` with a
143
+ * machine-readable reason and a human-readable message. Throwing is
144
+ * reserved for programmer errors (bad arguments, missing dependencies)
145
+ * that the agent code couldn't have caused.
146
+ *
147
+ * Fields:
148
+ * - `ok`: true iff the child produced a final assistant message.
149
+ * - `assistantText`: concatenated text content from the final assistant
150
+ * message, with leading/trailing whitespace trimmed. Empty string if the
151
+ * child finished but produced no text (rare — usually means the model
152
+ * only emitted tool calls and we didn't follow up).
153
+ * - `reason`: failure category, one of:
154
+ * - `"timeout"`: hit `timeoutMs` before the child finished
155
+ * - `"abort"`: caller's `signal` was triggered
156
+ * - `"model_failed"`: every configured model + fallback returned an error
157
+ * - `"spawn_failed"`: subprocess couldn't start (Pi only — binary missing,
158
+ * permission denied, etc.)
159
+ * - `"non_zero_exit"`: child exited unsuccessfully before a final answer
160
+ * - `"no_assistant"`: child completed without a final assistant message
161
+ * - `"parse_failed"`: child emitted output we couldn't parse (Pi only —
162
+ * JSON malformed or unexpected event ordering)
163
+ * - `error`: human-readable detail; safe to log, may include stack info.
164
+ * - `durationMs`: wall-clock time from runner-call to runner-return.
165
+ * - `meta`: optional harness-specific debug payload. Currently unused; left
166
+ * here so the OpenCode runner can surface the child session ID for log
167
+ * correlation when Step 5b lands.
168
+ */
169
+ export type SubagentRunResult = {
170
+ ok: true;
171
+ assistantText: string;
172
+ durationMs: number;
173
+ meta?: Record<string, unknown>;
174
+ } | {
175
+ ok: false;
176
+ reason: "timeout" | "abort" | "model_failed" | "spawn_failed" | "non_zero_exit" | "no_assistant" | "parse_failed";
177
+ error: string;
178
+ durationMs: number;
179
+ meta?: Record<string, unknown>;
180
+ };
181
+ /**
182
+ * Abstract runner contract.
183
+ *
184
+ * Each harness ships a single instance — the OpenCode plugin wires
185
+ * `OpenCodeSubagentRunner` and the Pi plugin wires `PiSubagentRunner` in
186
+ * its `extension` boot path. Agent code (historian, dreamer, sidekick)
187
+ * receives the runner as a dep and never reaches for harness-specific
188
+ * client APIs directly.
189
+ */
190
+ export interface SubagentRunner {
191
+ /** Human-readable harness name, for logging (`"opencode"` or `"pi"`). */
192
+ readonly harness: string;
193
+ /**
194
+ * Run one subagent invocation to completion.
195
+ *
196
+ * Always resolves with a `SubagentRunResult` — never throws for
197
+ * runtime/transport/model failures. Throwing is reserved for caller
198
+ * misuse (e.g. missing required option fields).
199
+ */
200
+ run(options: SubagentRunOptions): Promise<SubagentRunResult>;
201
+ }
202
+ //# sourceMappingURL=subagent-runner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subagent-runner.d.ts","sourceRoot":"","sources":["../../src/shared/subagent-runner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,WAAW,kBAAkB;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,cAAc,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACnC,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACzB,MAAM,CAAC,EAAE,WAAW,GAAG,SAAS,CAAC;IACjC;;;;;;;;;OASG;IACH,aAAa,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAEnC;;;;;;;;;OASG;IACH,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,qBAAqB,KAAK,IAAI,CAAC;CACvD;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,MAAM,qBAAqB,GAC3B;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,IAAI,EAAE,SAAS,MAAM,EAAE,CAAC;IAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,GACrE;IAAE,IAAI,EAAE,aAAa,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,GACtD;IACI,IAAI,EAAE,WAAW,CAAC;IAClB,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,KAAK,EAAE,OAAO,CAAC;IACf,EAAE,EAAE,MAAM,CAAC;CACd,GACD;IACI,IAAI,EAAE,UAAU,CAAC;IACjB,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,OAAO,CAAC;IACrB,EAAE,EAAE,MAAM,CAAC;CACd,GACD;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACjC;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,CAAC;AAErF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,MAAM,iBAAiB,GACvB;IACI,EAAE,EAAE,IAAI,CAAC;IACT,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC,GACD;IACI,EAAE,EAAE,KAAK,CAAC;IACV,MAAM,EACA,SAAS,GACT,OAAO,GACP,cAAc,GACd,cAAc,GACd,eAAe,GACf,cAAc,GACd,cAAc,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC,CAAC;AAER;;;;;;;;GAQG;AACH,MAAM,WAAW,cAAc;IAC3B,yEAAyE;IACzE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAEzB;;;;;;OAMG;IACH,GAAG,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;CAChE"}
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Harness-agnostic tagging over the Transcript interface.
3
+ *
4
+ * This is a deliberately minimal alternative to the OpenCode-specific
5
+ * `tag-messages.ts` that operates on `MessageLike[]`. The OpenCode flow
6
+ * carries 380+ lines of accumulated complexity:
7
+ *
8
+ * - source-content persistence (for cross-pass detag/restore behavior),
9
+ * - tool-call indexing across separate "tool" and "tool_result" parts,
10
+ * - reasoning-byte tracking for historian projection,
11
+ * - file-part stable IDs,
12
+ * - existing-tag resolver with content-id fallback.
13
+ *
14
+ * Most of that is OpenCode-specific (cache stability across multi-pass
15
+ * transforms, AI SDK part-id semantics, file part shapes). Pi's
16
+ * `pi.on("context", ...)` fires once per LLM call with a complete
17
+ * `AgentMessage[]`, so we can use a simpler tagging contract:
18
+ *
19
+ * 1. Walk the transcript in order.
20
+ * 2. For each tag-eligible part (text, tool_use, tool_result), assign
21
+ * a tag number via the shared `Tagger`.
22
+ * 3. Inject `§N§ ` prefix into the visible text (unless skipped).
23
+ * 4. Build a `TagTarget` so `applyPendingOperations` from
24
+ * `apply-operations.ts` can replace this part with a sentinel when
25
+ * a queued drop fires.
26
+ *
27
+ * Tool drops aggregate by call_id across both invocation and result
28
+ * occurrences (mirrors OpenCode tag-messages.ts:196-220). When a drop
29
+ * fires for a tool tag, BOTH the assistant `toolCall`/`tool_use` part
30
+ * and the user `toolResult`/`tool_result` part are mutated together so
31
+ * the LLM sees consistent dropped state. Without this aggregation:
32
+ *
33
+ * - Tool tag byte_size reflects only the args (~58 bytes for a `read`)
34
+ * because the FIRST occurrence (invocation) is tagged first and
35
+ * `assignTag` short-circuits the SECOND occurrence (result, ~4KB)
36
+ * to the same tag without updating byte_size.
37
+ * - Drops touch only the second occurrence (last write wins on
38
+ * `targets.set`), leaving the first in original form.
39
+ *
40
+ * Reuses unchanged from the OpenCode path:
41
+ *
42
+ * - `Tagger` (DB-backed counter + assignment store).
43
+ * - `applyPendingOperations` (operates on `Map<number, TagTarget>`).
44
+ * - `applyFlushedStatuses` (same).
45
+ * - Tag prefix primitives (`prependTag`, `stripTagPrefix`, `byteSize`).
46
+ */
47
+ import type { ContextDatabase } from "../features/magic-context/storage";
48
+ import type { Tagger } from "../features/magic-context/tagger";
49
+ import type { TagTarget } from "../hooks/magic-context/tag-messages";
50
+ import type { Transcript } from "./transcript";
51
+ export interface TagTranscriptOptions {
52
+ /**
53
+ * When true, skip injecting `§N§` prefix into visible text. Tags
54
+ * still get assigned in the DB so historian/drops can reference
55
+ * them; the agent just doesn't see the markers. Used when
56
+ * `ctx_reduce_enabled: false` (agent has no `ctx_reduce` tool to
57
+ * act on the markers). Cache-safe because skip behavior is
58
+ * consistent across passes.
59
+ */
60
+ skipPrefixInjection?: boolean;
61
+ }
62
+ export interface TagTranscriptResult {
63
+ targets: Map<number, TagTarget>;
64
+ }
65
+ export declare function tagTranscript(sessionId: string, transcript: Transcript, tagger: Tagger, db: ContextDatabase, options?: TagTranscriptOptions): TagTranscriptResult;
66
+ //# sourceMappingURL=tag-transcript.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tag-transcript.d.ts","sourceRoot":"","sources":["../../src/shared/tag-transcript.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AAGzE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kCAAkC,CAAC;AAM/D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qCAAqC,CAAC;AACrE,OAAO,KAAK,EAAE,UAAU,EAAkB,MAAM,cAAc,CAAC;AAE/D,MAAM,WAAW,oBAAoB;IACjC;;;;;;;OAOG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;CACjC;AAED,MAAM,WAAW,mBAAmB;IAChC,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;CACnC;AAyDD,wBAAgB,aAAa,CACzB,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,UAAU,EACtB,MAAM,EAAE,MAAM,EACd,EAAE,EAAE,eAAe,EACnB,OAAO,GAAE,oBAAyB,GACnC,mBAAmB,CA+JrB"}
@@ -0,0 +1,71 @@
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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transcript-opencode.d.ts","sourceRoot":"","sources":["../../src/shared/transcript-opencode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AAGH,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"}