@wolfx/opencode-magic-context 0.21.8-patch.1

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 (544) hide show
  1. package/dist/agents/dreamer.d.ts +2 -0
  2. package/dist/agents/dreamer.d.ts.map +1 -0
  3. package/dist/agents/historian.d.ts +3 -0
  4. package/dist/agents/historian.d.ts.map +1 -0
  5. package/dist/agents/magic-context-prompt.d.ts +3 -0
  6. package/dist/agents/magic-context-prompt.d.ts.map +1 -0
  7. package/dist/agents/permissions.d.ts +142 -0
  8. package/dist/agents/permissions.d.ts.map +1 -0
  9. package/dist/agents/sidekick.d.ts +2 -0
  10. package/dist/agents/sidekick.d.ts.map +1 -0
  11. package/dist/config/agent-disable.d.ts +26 -0
  12. package/dist/config/agent-disable.d.ts.map +1 -0
  13. package/dist/config/index.d.ts +33 -0
  14. package/dist/config/index.d.ts.map +1 -0
  15. package/dist/config/schema/agent-overrides.d.ts +55 -0
  16. package/dist/config/schema/agent-overrides.d.ts.map +1 -0
  17. package/dist/config/schema/magic-context.d.ts +841 -0
  18. package/dist/config/schema/magic-context.d.ts.map +1 -0
  19. package/dist/config/schema.d.ts +3 -0
  20. package/dist/config/schema.d.ts.map +1 -0
  21. package/dist/config/variable.d.ts +48 -0
  22. package/dist/config/variable.d.ts.map +1 -0
  23. package/dist/features/builtin-commands/commands.d.ts +3 -0
  24. package/dist/features/builtin-commands/commands.d.ts.map +1 -0
  25. package/dist/features/builtin-commands/types.d.ts +5 -0
  26. package/dist/features/builtin-commands/types.d.ts.map +1 -0
  27. package/dist/features/magic-context/compaction-marker.d.ts +91 -0
  28. package/dist/features/magic-context/compaction-marker.d.ts.map +1 -0
  29. package/dist/features/magic-context/compaction.d.ts +7 -0
  30. package/dist/features/magic-context/compaction.d.ts.map +1 -0
  31. package/dist/features/magic-context/compartment-lease.d.ts +14 -0
  32. package/dist/features/magic-context/compartment-lease.d.ts.map +1 -0
  33. package/dist/features/magic-context/compartment-storage.d.ts +130 -0
  34. package/dist/features/magic-context/compartment-storage.d.ts.map +1 -0
  35. package/dist/features/magic-context/compression-depth-storage.d.ts +14 -0
  36. package/dist/features/magic-context/compression-depth-storage.d.ts.map +1 -0
  37. package/dist/features/magic-context/defaults.d.ts +2 -0
  38. package/dist/features/magic-context/defaults.d.ts.map +1 -0
  39. package/dist/features/magic-context/dreamer/index.d.ts +8 -0
  40. package/dist/features/magic-context/dreamer/index.d.ts.map +1 -0
  41. package/dist/features/magic-context/dreamer/lease.d.ts +8 -0
  42. package/dist/features/magic-context/dreamer/lease.d.ts.map +1 -0
  43. package/dist/features/magic-context/dreamer/queue.d.ts +44 -0
  44. package/dist/features/magic-context/dreamer/queue.d.ts.map +1 -0
  45. package/dist/features/magic-context/dreamer/runner.d.ts +81 -0
  46. package/dist/features/magic-context/dreamer/runner.d.ts.map +1 -0
  47. package/dist/features/magic-context/dreamer/scheduler.d.ts +33 -0
  48. package/dist/features/magic-context/dreamer/scheduler.d.ts.map +1 -0
  49. package/dist/features/magic-context/dreamer/storage-dream-runs.d.ts +41 -0
  50. package/dist/features/magic-context/dreamer/storage-dream-runs.d.ts.map +1 -0
  51. package/dist/features/magic-context/dreamer/storage-dream-state.d.ts +5 -0
  52. package/dist/features/magic-context/dreamer/storage-dream-state.d.ts.map +1 -0
  53. package/dist/features/magic-context/dreamer/task-prompts.d.ts +26 -0
  54. package/dist/features/magic-context/dreamer/task-prompts.d.ts.map +1 -0
  55. package/dist/features/magic-context/git-commits/git-log-reader.d.ts +57 -0
  56. package/dist/features/magic-context/git-commits/git-log-reader.d.ts.map +1 -0
  57. package/dist/features/magic-context/git-commits/index.d.ts +7 -0
  58. package/dist/features/magic-context/git-commits/index.d.ts.map +1 -0
  59. package/dist/features/magic-context/git-commits/indexer.d.ts +43 -0
  60. package/dist/features/magic-context/git-commits/indexer.d.ts.map +1 -0
  61. package/dist/features/magic-context/git-commits/search-git-commits.d.ts +32 -0
  62. package/dist/features/magic-context/git-commits/search-git-commits.d.ts.map +1 -0
  63. package/dist/features/magic-context/git-commits/storage-git-commit-embeddings.d.ts +19 -0
  64. package/dist/features/magic-context/git-commits/storage-git-commit-embeddings.d.ts.map +1 -0
  65. package/dist/features/magic-context/git-commits/storage-git-commits.d.ts +47 -0
  66. package/dist/features/magic-context/git-commits/storage-git-commits.d.ts.map +1 -0
  67. package/dist/features/magic-context/index.d.ts +12 -0
  68. package/dist/features/magic-context/index.d.ts.map +1 -0
  69. package/dist/features/magic-context/key-files/aft-availability.d.ts +11 -0
  70. package/dist/features/magic-context/key-files/aft-availability.d.ts.map +1 -0
  71. package/dist/features/magic-context/key-files/identify-key-files.d.ts +84 -0
  72. package/dist/features/magic-context/key-files/identify-key-files.d.ts.map +1 -0
  73. package/dist/features/magic-context/key-files/project-key-files.d.ts +42 -0
  74. package/dist/features/magic-context/key-files/project-key-files.d.ts.map +1 -0
  75. package/dist/features/magic-context/key-files/read-history.d.ts +26 -0
  76. package/dist/features/magic-context/key-files/read-history.d.ts.map +1 -0
  77. package/dist/features/magic-context/key-files/read-stats.d.ts +20 -0
  78. package/dist/features/magic-context/key-files/read-stats.d.ts.map +1 -0
  79. package/dist/features/magic-context/key-files/storage-key-files.d.ts +25 -0
  80. package/dist/features/magic-context/key-files/storage-key-files.d.ts.map +1 -0
  81. package/dist/features/magic-context/memory/constants.d.ts +5 -0
  82. package/dist/features/magic-context/memory/constants.d.ts.map +1 -0
  83. package/dist/features/magic-context/memory/cosine-similarity.d.ts +2 -0
  84. package/dist/features/magic-context/memory/cosine-similarity.d.ts.map +1 -0
  85. package/dist/features/magic-context/memory/embedding-backfill.d.ts +9 -0
  86. package/dist/features/magic-context/memory/embedding-backfill.d.ts.map +1 -0
  87. package/dist/features/magic-context/memory/embedding-cache.d.ts +8 -0
  88. package/dist/features/magic-context/memory/embedding-cache.d.ts.map +1 -0
  89. package/dist/features/magic-context/memory/embedding-identity.d.ts +11 -0
  90. package/dist/features/magic-context/memory/embedding-identity.d.ts.map +1 -0
  91. package/dist/features/magic-context/memory/embedding-local.d.ts +20 -0
  92. package/dist/features/magic-context/memory/embedding-local.d.ts.map +1 -0
  93. package/dist/features/magic-context/memory/embedding-openai.d.ts +44 -0
  94. package/dist/features/magic-context/memory/embedding-openai.d.ts.map +1 -0
  95. package/dist/features/magic-context/memory/embedding-probe.d.ts +69 -0
  96. package/dist/features/magic-context/memory/embedding-probe.d.ts.map +1 -0
  97. package/dist/features/magic-context/memory/embedding-provider.d.ts +15 -0
  98. package/dist/features/magic-context/memory/embedding-provider.d.ts.map +1 -0
  99. package/dist/features/magic-context/memory/embedding.d.ts +39 -0
  100. package/dist/features/magic-context/memory/embedding.d.ts.map +1 -0
  101. package/dist/features/magic-context/memory/index.d.ts +12 -0
  102. package/dist/features/magic-context/memory/index.d.ts.map +1 -0
  103. package/dist/features/magic-context/memory/normalize-hash.d.ts +3 -0
  104. package/dist/features/magic-context/memory/normalize-hash.d.ts.map +1 -0
  105. package/dist/features/magic-context/memory/project-identity.d.ts +23 -0
  106. package/dist/features/magic-context/memory/project-identity.d.ts.map +1 -0
  107. package/dist/features/magic-context/memory/promotion.d.ts +13 -0
  108. package/dist/features/magic-context/memory/promotion.d.ts.map +1 -0
  109. package/dist/features/magic-context/memory/storage-memory-embeddings.d.ts +8 -0
  110. package/dist/features/magic-context/memory/storage-memory-embeddings.d.ts.map +1 -0
  111. package/dist/features/magic-context/memory/storage-memory-fts.d.ts +12 -0
  112. package/dist/features/magic-context/memory/storage-memory-fts.d.ts.map +1 -0
  113. package/dist/features/magic-context/memory/storage-memory.d.ts +31 -0
  114. package/dist/features/magic-context/memory/storage-memory.d.ts.map +1 -0
  115. package/dist/features/magic-context/memory/types.d.ts +37 -0
  116. package/dist/features/magic-context/memory/types.d.ts.map +1 -0
  117. package/dist/features/magic-context/message-index-async.d.ts +12 -0
  118. package/dist/features/magic-context/message-index-async.d.ts.map +1 -0
  119. package/dist/features/magic-context/message-index.d.ts +10 -0
  120. package/dist/features/magic-context/message-index.d.ts.map +1 -0
  121. package/dist/features/magic-context/migrations.d.ts +33 -0
  122. package/dist/features/magic-context/migrations.d.ts.map +1 -0
  123. package/dist/features/magic-context/mock-database.d.ts +3 -0
  124. package/dist/features/magic-context/mock-database.d.ts.map +1 -0
  125. package/dist/features/magic-context/overflow-detection.d.ts +51 -0
  126. package/dist/features/magic-context/overflow-detection.d.ts.map +1 -0
  127. package/dist/features/magic-context/plugin-messages.d.ts +75 -0
  128. package/dist/features/magic-context/plugin-messages.d.ts.map +1 -0
  129. package/dist/features/magic-context/project-embedding-registry.d.ts +44 -0
  130. package/dist/features/magic-context/project-embedding-registry.d.ts.map +1 -0
  131. package/dist/features/magic-context/range-parser.d.ts +13 -0
  132. package/dist/features/magic-context/range-parser.d.ts.map +1 -0
  133. package/dist/features/magic-context/resolve-subagent-fallback.d.ts +40 -0
  134. package/dist/features/magic-context/resolve-subagent-fallback.d.ts.map +1 -0
  135. package/dist/features/magic-context/scheduler.d.ts +18 -0
  136. package/dist/features/magic-context/scheduler.d.ts.map +1 -0
  137. package/dist/features/magic-context/search.d.ts +69 -0
  138. package/dist/features/magic-context/search.d.ts.map +1 -0
  139. package/dist/features/magic-context/sidekick/agent.d.ts +13 -0
  140. package/dist/features/magic-context/sidekick/agent.d.ts.map +1 -0
  141. package/dist/features/magic-context/sidekick/core.d.ts +38 -0
  142. package/dist/features/magic-context/sidekick/core.d.ts.map +1 -0
  143. package/dist/features/magic-context/sidekick/index.d.ts +3 -0
  144. package/dist/features/magic-context/sidekick/index.d.ts.map +1 -0
  145. package/dist/features/magic-context/storage-db.d.ts +48 -0
  146. package/dist/features/magic-context/storage-db.d.ts.map +1 -0
  147. package/dist/features/magic-context/storage-meta-persisted.d.ts +246 -0
  148. package/dist/features/magic-context/storage-meta-persisted.d.ts.map +1 -0
  149. package/dist/features/magic-context/storage-meta-session.d.ts +6 -0
  150. package/dist/features/magic-context/storage-meta-session.d.ts.map +1 -0
  151. package/dist/features/magic-context/storage-meta-shared.d.ts +31 -0
  152. package/dist/features/magic-context/storage-meta-shared.d.ts.map +1 -0
  153. package/dist/features/magic-context/storage-meta.d.ts +3 -0
  154. package/dist/features/magic-context/storage-meta.d.ts.map +1 -0
  155. package/dist/features/magic-context/storage-notes.d.ts +62 -0
  156. package/dist/features/magic-context/storage-notes.d.ts.map +1 -0
  157. package/dist/features/magic-context/storage-ops.d.ts +7 -0
  158. package/dist/features/magic-context/storage-ops.d.ts.map +1 -0
  159. package/dist/features/magic-context/storage-source.d.ts +5 -0
  160. package/dist/features/magic-context/storage-source.d.ts.map +1 -0
  161. package/dist/features/magic-context/storage-subagent-invocations.d.ts +52 -0
  162. package/dist/features/magic-context/storage-subagent-invocations.d.ts.map +1 -0
  163. package/dist/features/magic-context/storage-tags.d.ts +206 -0
  164. package/dist/features/magic-context/storage-tags.d.ts.map +1 -0
  165. package/dist/features/magic-context/storage.d.ts +11 -0
  166. package/dist/features/magic-context/storage.d.ts.map +1 -0
  167. package/dist/features/magic-context/subagent-token-capture.d.ts +33 -0
  168. package/dist/features/magic-context/subagent-token-capture.d.ts.map +1 -0
  169. package/dist/features/magic-context/tagger.d.ts +64 -0
  170. package/dist/features/magic-context/tagger.d.ts.map +1 -0
  171. package/dist/features/magic-context/tool-definition-tokens.d.ts +79 -0
  172. package/dist/features/magic-context/tool-definition-tokens.d.ts.map +1 -0
  173. package/dist/features/magic-context/tool-owner-backfill.d.ts +90 -0
  174. package/dist/features/magic-context/tool-owner-backfill.d.ts.map +1 -0
  175. package/dist/features/magic-context/types.d.ts +72 -0
  176. package/dist/features/magic-context/types.d.ts.map +1 -0
  177. package/dist/features/magic-context/user-memory/review-user-memories.d.ts +22 -0
  178. package/dist/features/magic-context/user-memory/review-user-memories.d.ts.map +1 -0
  179. package/dist/features/magic-context/user-memory/storage-user-memory.d.ts +33 -0
  180. package/dist/features/magic-context/user-memory/storage-user-memory.d.ts.map +1 -0
  181. package/dist/features/magic-context/work-metrics.d.ts +13 -0
  182. package/dist/features/magic-context/work-metrics.d.ts.map +1 -0
  183. package/dist/hooks/auto-update-checker/cache.d.ts +23 -0
  184. package/dist/hooks/auto-update-checker/cache.d.ts.map +1 -0
  185. package/dist/hooks/auto-update-checker/checker.d.ts +13 -0
  186. package/dist/hooks/auto-update-checker/checker.d.ts.map +1 -0
  187. package/dist/hooks/auto-update-checker/constants.d.ts +10 -0
  188. package/dist/hooks/auto-update-checker/constants.d.ts.map +1 -0
  189. package/dist/hooks/auto-update-checker/index.d.ts +40 -0
  190. package/dist/hooks/auto-update-checker/index.d.ts.map +1 -0
  191. package/dist/hooks/auto-update-checker/types.d.ts +50 -0
  192. package/dist/hooks/auto-update-checker/types.d.ts.map +1 -0
  193. package/dist/hooks/is-anthropic-provider.d.ts +2 -0
  194. package/dist/hooks/is-anthropic-provider.d.ts.map +1 -0
  195. package/dist/hooks/magic-context/apply-context-nudge.d.ts +5 -0
  196. package/dist/hooks/magic-context/apply-context-nudge.d.ts.map +1 -0
  197. package/dist/hooks/magic-context/apply-operations.d.ts +7 -0
  198. package/dist/hooks/magic-context/apply-operations.d.ts.map +1 -0
  199. package/dist/hooks/magic-context/auto-search-hint.d.ts +34 -0
  200. package/dist/hooks/magic-context/auto-search-hint.d.ts.map +1 -0
  201. package/dist/hooks/magic-context/auto-search-runner.d.ts +53 -0
  202. package/dist/hooks/magic-context/auto-search-runner.d.ts.map +1 -0
  203. package/dist/hooks/magic-context/boundary-execution.d.ts +24 -0
  204. package/dist/hooks/magic-context/boundary-execution.d.ts.map +1 -0
  205. package/dist/hooks/magic-context/cache-busting-signals.d.ts +10 -0
  206. package/dist/hooks/magic-context/cache-busting-signals.d.ts.map +1 -0
  207. package/dist/hooks/magic-context/caveman-cleanup.d.ts +86 -0
  208. package/dist/hooks/magic-context/caveman-cleanup.d.ts.map +1 -0
  209. package/dist/hooks/magic-context/caveman.d.ts +35 -0
  210. package/dist/hooks/magic-context/caveman.d.ts.map +1 -0
  211. package/dist/hooks/magic-context/command-handler.d.ts +89 -0
  212. package/dist/hooks/magic-context/command-handler.d.ts.map +1 -0
  213. package/dist/hooks/magic-context/compaction-marker-manager.d.ts +106 -0
  214. package/dist/hooks/magic-context/compaction-marker-manager.d.ts.map +1 -0
  215. package/dist/hooks/magic-context/compartment-parser.d.ts +18 -0
  216. package/dist/hooks/magic-context/compartment-parser.d.ts.map +1 -0
  217. package/dist/hooks/magic-context/compartment-prompt.d.ts +19 -0
  218. package/dist/hooks/magic-context/compartment-prompt.d.ts.map +1 -0
  219. package/dist/hooks/magic-context/compartment-runner-compressor.d.ts +87 -0
  220. package/dist/hooks/magic-context/compartment-runner-compressor.d.ts.map +1 -0
  221. package/dist/hooks/magic-context/compartment-runner-drop-queue.d.ts +26 -0
  222. package/dist/hooks/magic-context/compartment-runner-drop-queue.d.ts.map +1 -0
  223. package/dist/hooks/magic-context/compartment-runner-historian.d.ts +42 -0
  224. package/dist/hooks/magic-context/compartment-runner-historian.d.ts.map +1 -0
  225. package/dist/hooks/magic-context/compartment-runner-incremental.d.ts +6 -0
  226. package/dist/hooks/magic-context/compartment-runner-incremental.d.ts.map +1 -0
  227. package/dist/hooks/magic-context/compartment-runner-mapping.d.ts +33 -0
  228. package/dist/hooks/magic-context/compartment-runner-mapping.d.ts.map +1 -0
  229. package/dist/hooks/magic-context/compartment-runner-partial-recomp.d.ts +29 -0
  230. package/dist/hooks/magic-context/compartment-runner-partial-recomp.d.ts.map +1 -0
  231. package/dist/hooks/magic-context/compartment-runner-recomp.d.ts +3 -0
  232. package/dist/hooks/magic-context/compartment-runner-recomp.d.ts.map +1 -0
  233. package/dist/hooks/magic-context/compartment-runner-state-xml.d.ts +21 -0
  234. package/dist/hooks/magic-context/compartment-runner-state-xml.d.ts.map +1 -0
  235. package/dist/hooks/magic-context/compartment-runner-types.d.ts +102 -0
  236. package/dist/hooks/magic-context/compartment-runner-types.d.ts.map +1 -0
  237. package/dist/hooks/magic-context/compartment-runner-validation.d.ts +28 -0
  238. package/dist/hooks/magic-context/compartment-runner-validation.d.ts.map +1 -0
  239. package/dist/hooks/magic-context/compartment-runner.d.ts +54 -0
  240. package/dist/hooks/magic-context/compartment-runner.d.ts.map +1 -0
  241. package/dist/hooks/magic-context/compartment-trigger.d.ts +17 -0
  242. package/dist/hooks/magic-context/compartment-trigger.d.ts.map +1 -0
  243. package/dist/hooks/magic-context/derive-budgets.d.ts +57 -0
  244. package/dist/hooks/magic-context/derive-budgets.d.ts.map +1 -0
  245. package/dist/hooks/magic-context/drop-stale-reduce-calls.d.ts +4 -0
  246. package/dist/hooks/magic-context/drop-stale-reduce-calls.d.ts.map +1 -0
  247. package/dist/hooks/magic-context/event-handler.d.ts +49 -0
  248. package/dist/hooks/magic-context/event-handler.d.ts.map +1 -0
  249. package/dist/hooks/magic-context/event-payloads.d.ts +62 -0
  250. package/dist/hooks/magic-context/event-payloads.d.ts.map +1 -0
  251. package/dist/hooks/magic-context/event-resolvers.d.ts +72 -0
  252. package/dist/hooks/magic-context/event-resolvers.d.ts.map +1 -0
  253. package/dist/hooks/magic-context/execute-flush.d.ts +3 -0
  254. package/dist/hooks/magic-context/execute-flush.d.ts.map +1 -0
  255. package/dist/hooks/magic-context/execute-status.d.ts +12 -0
  256. package/dist/hooks/magic-context/execute-status.d.ts.map +1 -0
  257. package/dist/hooks/magic-context/format-bytes.d.ts +2 -0
  258. package/dist/hooks/magic-context/format-bytes.d.ts.map +1 -0
  259. package/dist/hooks/magic-context/heuristic-cleanup.d.ts +22 -0
  260. package/dist/hooks/magic-context/heuristic-cleanup.d.ts.map +1 -0
  261. package/dist/hooks/magic-context/historian-state-file.d.ts +43 -0
  262. package/dist/hooks/magic-context/historian-state-file.d.ts.map +1 -0
  263. package/dist/hooks/magic-context/hook-handlers.d.ts +165 -0
  264. package/dist/hooks/magic-context/hook-handlers.d.ts.map +1 -0
  265. package/dist/hooks/magic-context/hook.d.ts +118 -0
  266. package/dist/hooks/magic-context/hook.d.ts.map +1 -0
  267. package/dist/hooks/magic-context/image-token-estimate.d.ts +6 -0
  268. package/dist/hooks/magic-context/image-token-estimate.d.ts.map +1 -0
  269. package/dist/hooks/magic-context/index.d.ts +3 -0
  270. package/dist/hooks/magic-context/index.d.ts.map +1 -0
  271. package/dist/hooks/magic-context/inject-compartments.d.ts +52 -0
  272. package/dist/hooks/magic-context/inject-compartments.d.ts.map +1 -0
  273. package/dist/hooks/magic-context/key-files-block.d.ts +27 -0
  274. package/dist/hooks/magic-context/key-files-block.d.ts.map +1 -0
  275. package/dist/hooks/magic-context/live-session-state.d.ts +42 -0
  276. package/dist/hooks/magic-context/live-session-state.d.ts.map +1 -0
  277. package/dist/hooks/magic-context/note-nudger.d.ts +71 -0
  278. package/dist/hooks/magic-context/note-nudger.d.ts.map +1 -0
  279. package/dist/hooks/magic-context/note-visibility.d.ts +43 -0
  280. package/dist/hooks/magic-context/note-visibility.d.ts.map +1 -0
  281. package/dist/hooks/magic-context/nudge-bands.d.ts +6 -0
  282. package/dist/hooks/magic-context/nudge-bands.d.ts.map +1 -0
  283. package/dist/hooks/magic-context/nudge-injection.d.ts +7 -0
  284. package/dist/hooks/magic-context/nudge-injection.d.ts.map +1 -0
  285. package/dist/hooks/magic-context/nudge-placement-store.d.ts +15 -0
  286. package/dist/hooks/magic-context/nudge-placement-store.d.ts.map +1 -0
  287. package/dist/hooks/magic-context/nudger.d.ts +21 -0
  288. package/dist/hooks/magic-context/nudger.d.ts.map +1 -0
  289. package/dist/hooks/magic-context/read-session-chunk.d.ts +99 -0
  290. package/dist/hooks/magic-context/read-session-chunk.d.ts.map +1 -0
  291. package/dist/hooks/magic-context/read-session-db.d.ts +21 -0
  292. package/dist/hooks/magic-context/read-session-db.d.ts.map +1 -0
  293. package/dist/hooks/magic-context/read-session-formatting.d.ts +35 -0
  294. package/dist/hooks/magic-context/read-session-formatting.d.ts.map +1 -0
  295. package/dist/hooks/magic-context/read-session-raw.d.ts +10 -0
  296. package/dist/hooks/magic-context/read-session-raw.d.ts.map +1 -0
  297. package/dist/hooks/magic-context/send-session-notification.d.ts +13 -0
  298. package/dist/hooks/magic-context/send-session-notification.d.ts.map +1 -0
  299. package/dist/hooks/magic-context/sentinel.d.ts +102 -0
  300. package/dist/hooks/magic-context/sentinel.d.ts.map +1 -0
  301. package/dist/hooks/magic-context/strip-content.d.ts +140 -0
  302. package/dist/hooks/magic-context/strip-content.d.ts.map +1 -0
  303. package/dist/hooks/magic-context/strip-structural-noise.d.ts +17 -0
  304. package/dist/hooks/magic-context/strip-structural-noise.d.ts.map +1 -0
  305. package/dist/hooks/magic-context/system-injection-stripper.d.ts +2 -0
  306. package/dist/hooks/magic-context/system-injection-stripper.d.ts.map +1 -0
  307. package/dist/hooks/magic-context/system-prompt-hash.d.ts +85 -0
  308. package/dist/hooks/magic-context/system-prompt-hash.d.ts.map +1 -0
  309. package/dist/hooks/magic-context/tag-content-primitives.d.ts +6 -0
  310. package/dist/hooks/magic-context/tag-content-primitives.d.ts.map +1 -0
  311. package/dist/hooks/magic-context/tag-id-fallback.d.ts +9 -0
  312. package/dist/hooks/magic-context/tag-id-fallback.d.ts.map +1 -0
  313. package/dist/hooks/magic-context/tag-messages.d.ts +48 -0
  314. package/dist/hooks/magic-context/tag-messages.d.ts.map +1 -0
  315. package/dist/hooks/magic-context/tag-part-guards.d.ts +23 -0
  316. package/dist/hooks/magic-context/tag-part-guards.d.ts.map +1 -0
  317. package/dist/hooks/magic-context/temporal-awareness.d.ts +73 -0
  318. package/dist/hooks/magic-context/temporal-awareness.d.ts.map +1 -0
  319. package/dist/hooks/magic-context/text-complete.d.ts +8 -0
  320. package/dist/hooks/magic-context/text-complete.d.ts.map +1 -0
  321. package/dist/hooks/magic-context/todo-view.d.ts +102 -0
  322. package/dist/hooks/magic-context/todo-view.d.ts.map +1 -0
  323. package/dist/hooks/magic-context/tokenizer-calibration.d.ts +85 -0
  324. package/dist/hooks/magic-context/tokenizer-calibration.d.ts.map +1 -0
  325. package/dist/hooks/magic-context/tool-drop-target.d.ts +48 -0
  326. package/dist/hooks/magic-context/tool-drop-target.d.ts.map +1 -0
  327. package/dist/hooks/magic-context/transform-compartment-phase.d.ts +66 -0
  328. package/dist/hooks/magic-context/transform-compartment-phase.d.ts.map +1 -0
  329. package/dist/hooks/magic-context/transform-context-state.d.ts +12 -0
  330. package/dist/hooks/magic-context/transform-context-state.d.ts.map +1 -0
  331. package/dist/hooks/magic-context/transform-message-helpers.d.ts +29 -0
  332. package/dist/hooks/magic-context/transform-message-helpers.d.ts.map +1 -0
  333. package/dist/hooks/magic-context/transform-operations.d.ts +5 -0
  334. package/dist/hooks/magic-context/transform-operations.d.ts.map +1 -0
  335. package/dist/hooks/magic-context/transform-postprocess-phase.d.ts +100 -0
  336. package/dist/hooks/magic-context/transform-postprocess-phase.d.ts.map +1 -0
  337. package/dist/hooks/magic-context/transform-stage-logger.d.ts +2 -0
  338. package/dist/hooks/magic-context/transform-stage-logger.d.ts.map +1 -0
  339. package/dist/hooks/magic-context/transform.d.ts +145 -0
  340. package/dist/hooks/magic-context/transform.d.ts.map +1 -0
  341. package/dist/index.d.ts +4 -0
  342. package/dist/index.d.ts.map +1 -0
  343. package/dist/index.js +179800 -0
  344. package/dist/plugin/conflict-warning-hook.d.ts +34 -0
  345. package/dist/plugin/conflict-warning-hook.d.ts.map +1 -0
  346. package/dist/plugin/dream-timer.d.ts +44 -0
  347. package/dist/plugin/dream-timer.d.ts.map +1 -0
  348. package/dist/plugin/embedding-bootstrap-helpers.d.ts +35 -0
  349. package/dist/plugin/embedding-bootstrap-helpers.d.ts.map +1 -0
  350. package/dist/plugin/embedding-bootstrap.d.ts +3 -0
  351. package/dist/plugin/embedding-bootstrap.d.ts.map +1 -0
  352. package/dist/plugin/event.d.ts +13 -0
  353. package/dist/plugin/event.d.ts.map +1 -0
  354. package/dist/plugin/hooks/create-session-hooks.d.ts +44 -0
  355. package/dist/plugin/hooks/create-session-hooks.d.ts.map +1 -0
  356. package/dist/plugin/messages-transform.d.ts +46 -0
  357. package/dist/plugin/messages-transform.d.ts.map +1 -0
  358. package/dist/plugin/normalize-tool-arg-schemas.d.ts +7 -0
  359. package/dist/plugin/normalize-tool-arg-schemas.d.ts.map +1 -0
  360. package/dist/plugin/rpc-handlers.d.ts +21 -0
  361. package/dist/plugin/rpc-handlers.d.ts.map +1 -0
  362. package/dist/plugin/sidebar-snapshot-cache.d.ts +19 -0
  363. package/dist/plugin/sidebar-snapshot-cache.d.ts.map +1 -0
  364. package/dist/plugin/tool-registry.d.ts +8 -0
  365. package/dist/plugin/tool-registry.d.ts.map +1 -0
  366. package/dist/plugin/types.d.ts +3 -0
  367. package/dist/plugin/types.d.ts.map +1 -0
  368. package/dist/shared/announcement.d.ts +55 -0
  369. package/dist/shared/announcement.d.ts.map +1 -0
  370. package/dist/shared/assistant-message-extractor.d.ts +2 -0
  371. package/dist/shared/assistant-message-extractor.d.ts.map +1 -0
  372. package/dist/shared/bounded-session-map.d.ts +45 -0
  373. package/dist/shared/bounded-session-map.d.ts.map +1 -0
  374. package/dist/shared/conflict-detector.d.ts +74 -0
  375. package/dist/shared/conflict-detector.d.ts.map +1 -0
  376. package/dist/shared/conflict-fixer.d.ts +3 -0
  377. package/dist/shared/conflict-fixer.d.ts.map +1 -0
  378. package/dist/shared/data-path.d.ts +121 -0
  379. package/dist/shared/data-path.d.ts.map +1 -0
  380. package/dist/shared/error-message.d.ts +32 -0
  381. package/dist/shared/error-message.d.ts.map +1 -0
  382. package/dist/shared/format-bytes.d.ts +2 -0
  383. package/dist/shared/format-bytes.d.ts.map +1 -0
  384. package/dist/shared/format-threshold.d.ts +24 -0
  385. package/dist/shared/format-threshold.d.ts.map +1 -0
  386. package/dist/shared/harness.d.ts +43 -0
  387. package/dist/shared/harness.d.ts.map +1 -0
  388. package/dist/shared/index.d.ts +6 -0
  389. package/dist/shared/index.d.ts.map +1 -0
  390. package/dist/shared/internal-initiator-marker.d.ts +2 -0
  391. package/dist/shared/internal-initiator-marker.d.ts.map +1 -0
  392. package/dist/shared/jsonc-parser.d.ts +8 -0
  393. package/dist/shared/jsonc-parser.d.ts.map +1 -0
  394. package/dist/shared/logger.d.ts +10 -0
  395. package/dist/shared/logger.d.ts.map +1 -0
  396. package/dist/shared/model-requirements.d.ts +26 -0
  397. package/dist/shared/model-requirements.d.ts.map +1 -0
  398. package/dist/shared/model-suggestion-retry.d.ts +68 -0
  399. package/dist/shared/model-suggestion-retry.d.ts.map +1 -0
  400. package/dist/shared/models-dev-cache.d.ts +65 -0
  401. package/dist/shared/models-dev-cache.d.ts.map +1 -0
  402. package/dist/shared/native-binding.d.ts +87 -0
  403. package/dist/shared/native-binding.d.ts.map +1 -0
  404. package/dist/shared/normalize-sdk-response.d.ts +5 -0
  405. package/dist/shared/normalize-sdk-response.d.ts.map +1 -0
  406. package/dist/shared/opencode-compaction-detector.d.ts +2 -0
  407. package/dist/shared/opencode-compaction-detector.d.ts.map +1 -0
  408. package/dist/shared/opencode-config-dir-types.d.ts +14 -0
  409. package/dist/shared/opencode-config-dir-types.d.ts.map +1 -0
  410. package/dist/shared/opencode-config-dir.d.ts +5 -0
  411. package/dist/shared/opencode-config-dir.d.ts.map +1 -0
  412. package/dist/shared/record-type-guard.d.ts +2 -0
  413. package/dist/shared/record-type-guard.d.ts.map +1 -0
  414. package/dist/shared/resolve-fallbacks.d.ts +32 -0
  415. package/dist/shared/resolve-fallbacks.d.ts.map +1 -0
  416. package/dist/shared/rpc-client.d.ts +17 -0
  417. package/dist/shared/rpc-client.d.ts.map +1 -0
  418. package/dist/shared/rpc-notifications.d.ts +24 -0
  419. package/dist/shared/rpc-notifications.d.ts.map +1 -0
  420. package/dist/shared/rpc-server.d.ts +20 -0
  421. package/dist/shared/rpc-server.d.ts.map +1 -0
  422. package/dist/shared/rpc-types.d.ts +105 -0
  423. package/dist/shared/rpc-types.d.ts.map +1 -0
  424. package/dist/shared/rpc-utils.d.ts +19 -0
  425. package/dist/shared/rpc-utils.d.ts.map +1 -0
  426. package/dist/shared/sqlite-helpers.d.ts +16 -0
  427. package/dist/shared/sqlite-helpers.d.ts.map +1 -0
  428. package/dist/shared/sqlite.d.ts +43 -0
  429. package/dist/shared/sqlite.d.ts.map +1 -0
  430. package/dist/shared/stable-json.d.ts +21 -0
  431. package/dist/shared/stable-json.d.ts.map +1 -0
  432. package/dist/shared/subagent-runner.d.ts +208 -0
  433. package/dist/shared/subagent-runner.d.ts.map +1 -0
  434. package/dist/shared/system-directive.d.ts +3 -0
  435. package/dist/shared/system-directive.d.ts.map +1 -0
  436. package/dist/shared/tag-transcript.d.ts +66 -0
  437. package/dist/shared/tag-transcript.d.ts.map +1 -0
  438. package/dist/shared/transcript-opencode.d.ts +71 -0
  439. package/dist/shared/transcript-opencode.d.ts.map +1 -0
  440. package/dist/shared/transcript.d.ts +212 -0
  441. package/dist/shared/transcript.d.ts.map +1 -0
  442. package/dist/shared/tui-config.d.ts +10 -0
  443. package/dist/shared/tui-config.d.ts.map +1 -0
  444. package/dist/tools/ctx-expand/constants.d.ts +3 -0
  445. package/dist/tools/ctx-expand/constants.d.ts.map +1 -0
  446. package/dist/tools/ctx-expand/index.d.ts +2 -0
  447. package/dist/tools/ctx-expand/index.d.ts.map +1 -0
  448. package/dist/tools/ctx-expand/tools.d.ts +3 -0
  449. package/dist/tools/ctx-expand/tools.d.ts.map +1 -0
  450. package/dist/tools/ctx-expand/types.d.ts +5 -0
  451. package/dist/tools/ctx-expand/types.d.ts.map +1 -0
  452. package/dist/tools/ctx-memory/constants.d.ts +4 -0
  453. package/dist/tools/ctx-memory/constants.d.ts.map +1 -0
  454. package/dist/tools/ctx-memory/index.d.ts +4 -0
  455. package/dist/tools/ctx-memory/index.d.ts.map +1 -0
  456. package/dist/tools/ctx-memory/tools.d.ts +4 -0
  457. package/dist/tools/ctx-memory/tools.d.ts.map +1 -0
  458. package/dist/tools/ctx-memory/types.d.ts +35 -0
  459. package/dist/tools/ctx-memory/types.d.ts.map +1 -0
  460. package/dist/tools/ctx-note/constants.d.ts +2 -0
  461. package/dist/tools/ctx-note/constants.d.ts.map +1 -0
  462. package/dist/tools/ctx-note/index.d.ts +4 -0
  463. package/dist/tools/ctx-note/index.d.ts.map +1 -0
  464. package/dist/tools/ctx-note/tools.d.ts +15 -0
  465. package/dist/tools/ctx-note/tools.d.ts.map +1 -0
  466. package/dist/tools/ctx-note/types.d.ts +9 -0
  467. package/dist/tools/ctx-note/types.d.ts.map +1 -0
  468. package/dist/tools/ctx-reduce/constants.d.ts +2 -0
  469. package/dist/tools/ctx-reduce/constants.d.ts.map +1 -0
  470. package/dist/tools/ctx-reduce/index.d.ts +4 -0
  471. package/dist/tools/ctx-reduce/index.d.ts.map +1 -0
  472. package/dist/tools/ctx-reduce/tools.d.ts +9 -0
  473. package/dist/tools/ctx-reduce/tools.d.ts.map +1 -0
  474. package/dist/tools/ctx-reduce/types.d.ts +4 -0
  475. package/dist/tools/ctx-reduce/types.d.ts.map +1 -0
  476. package/dist/tools/ctx-search/constants.d.ts +4 -0
  477. package/dist/tools/ctx-search/constants.d.ts.map +1 -0
  478. package/dist/tools/ctx-search/index.d.ts +4 -0
  479. package/dist/tools/ctx-search/index.d.ts.map +1 -0
  480. package/dist/tools/ctx-search/tools.d.ts +4 -0
  481. package/dist/tools/ctx-search/tools.d.ts.map +1 -0
  482. package/dist/tools/ctx-search/types.d.ts +34 -0
  483. package/dist/tools/ctx-search/types.d.ts.map +1 -0
  484. package/dist/tools/index.d.ts +6 -0
  485. package/dist/tools/index.d.ts.map +1 -0
  486. package/dist/tui/data/context-db.d.ts +36 -0
  487. package/dist/tui/data/context-db.d.ts.map +1 -0
  488. package/package.json +80 -0
  489. package/src/shared/announcement.test.ts +143 -0
  490. package/src/shared/announcement.ts +97 -0
  491. package/src/shared/assistant-message-extractor.ts +74 -0
  492. package/src/shared/bounded-session-map.test.ts +97 -0
  493. package/src/shared/bounded-session-map.ts +84 -0
  494. package/src/shared/conflict-detector.test.ts +232 -0
  495. package/src/shared/conflict-detector.ts +371 -0
  496. package/src/shared/conflict-fixer.test.ts +124 -0
  497. package/src/shared/conflict-fixer.ts +222 -0
  498. package/src/shared/data-path.test.ts +159 -0
  499. package/src/shared/data-path.ts +155 -0
  500. package/src/shared/error-message.test.ts +94 -0
  501. package/src/shared/error-message.ts +115 -0
  502. package/src/shared/format-bytes.ts +5 -0
  503. package/src/shared/format-threshold.ts +28 -0
  504. package/src/shared/harness.ts +61 -0
  505. package/src/shared/index.ts +5 -0
  506. package/src/shared/internal-initiator-marker.ts +1 -0
  507. package/src/shared/jsonc-parser.ts +138 -0
  508. package/src/shared/logger.ts +94 -0
  509. package/src/shared/model-requirements.ts +86 -0
  510. package/src/shared/model-suggestion-retry.test.ts +251 -0
  511. package/src/shared/model-suggestion-retry.ts +348 -0
  512. package/src/shared/models-dev-cache.test.ts +394 -0
  513. package/src/shared/models-dev-cache.ts +337 -0
  514. package/src/shared/native-binding.ts +311 -0
  515. package/src/shared/normalize-sdk-response.ts +40 -0
  516. package/src/shared/opencode-compaction-detector.test.ts +222 -0
  517. package/src/shared/opencode-compaction-detector.ts +81 -0
  518. package/src/shared/opencode-config-dir-types.ts +15 -0
  519. package/src/shared/opencode-config-dir.ts +38 -0
  520. package/src/shared/record-type-guard.ts +3 -0
  521. package/src/shared/resolve-fallbacks.test.ts +136 -0
  522. package/src/shared/resolve-fallbacks.ts +76 -0
  523. package/src/shared/rpc-client.test.ts +161 -0
  524. package/src/shared/rpc-client.ts +183 -0
  525. package/src/shared/rpc-notifications.test.ts +20 -0
  526. package/src/shared/rpc-notifications.ts +53 -0
  527. package/src/shared/rpc-server.ts +174 -0
  528. package/src/shared/rpc-types.ts +104 -0
  529. package/src/shared/rpc-utils.ts +72 -0
  530. package/src/shared/session-messages-bounded.test.ts +112 -0
  531. package/src/shared/sqlite-helpers.ts +27 -0
  532. package/src/shared/sqlite.ts +134 -0
  533. package/src/shared/stable-json.test.ts +87 -0
  534. package/src/shared/stable-json.ts +37 -0
  535. package/src/shared/subagent-runner.ts +222 -0
  536. package/src/shared/system-directive.ts +9 -0
  537. package/src/shared/tag-transcript.ts +553 -0
  538. package/src/shared/transcript-opencode.ts +259 -0
  539. package/src/shared/transcript.ts +226 -0
  540. package/src/shared/tui-config.ts +99 -0
  541. package/src/tui/data/context-db.ts +303 -0
  542. package/src/tui/index.tsx +692 -0
  543. package/src/tui/slots/sidebar-content.tsx +482 -0
  544. package/src/tui/types/opencode-plugin-tui.d.ts +232 -0
@@ -0,0 +1,553 @@
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
+
48
+ import type { ContextDatabase } from "../features/magic-context/storage";
49
+ import { saveSourceContent } from "../features/magic-context/storage-source";
50
+ import { updateTagByteSize, updateTagInputByteSize } from "../features/magic-context/storage-tags";
51
+ import type { Tagger } from "../features/magic-context/tagger";
52
+ import {
53
+ byteSize,
54
+ prependTag,
55
+ stripTagPrefix,
56
+ } from "../hooks/magic-context/tag-content-primitives";
57
+ import type { TagTarget } from "../hooks/magic-context/tag-messages";
58
+ import type { Transcript, TranscriptPart } from "./transcript";
59
+
60
+ export interface TagTranscriptOptions {
61
+ /**
62
+ * When true, skip injecting `§N§` prefix into visible text. Tags
63
+ * still get assigned in the DB so historian/drops can reference
64
+ * them; the agent just doesn't see the markers. Used when
65
+ * `ctx_reduce_enabled: false` (agent has no `ctx_reduce` tool to
66
+ * act on the markers). Cache-safe because skip behavior is
67
+ * consistent across passes.
68
+ */
69
+ skipPrefixInjection?: boolean;
70
+ }
71
+
72
+ export interface TagTranscriptResult {
73
+ targets: Map<number, TagTarget>;
74
+ }
75
+
76
+ /**
77
+ * Tag eligible parts of a transcript and build TagTargets for them.
78
+ *
79
+ * "Eligible" means: parts that contribute meaningfully to the LLM input
80
+ * and whose content can be replaced when dropped. Specifically:
81
+ *
82
+ * - text parts (user or assistant): tagged as type "message", inject
83
+ * prefix into the visible text, target supports setContent.
84
+ * - thinking parts: NOT tagged. Reasoning content has provider-
85
+ * specific signed-content semantics (Anthropic redacted_thinking,
86
+ * etc.) and replacing them mid-conversation breaks signature
87
+ * verification. The historian's clear-reasoning pass handles them
88
+ * separately if needed.
89
+ * - tool_use parts (assistant tool invocations): tagged as type
90
+ * "tool", target supports drop/truncate via the tag-content
91
+ * primitives.
92
+ * - tool_result parts (folded into user messages by the Pi adapter):
93
+ * tagged as type "tool", paired with the corresponding invocation
94
+ * for full-pair drops.
95
+ * - image, file, structural, unknown: skipped.
96
+ *
97
+ * The contentId we pass to the tagger uses the part's stable id when
98
+ * available, otherwise a synthetic locator. Pi's adapter exposes:
99
+ * - tool_use parts: id = ToolCall.id (from pi-ai)
100
+ * - tool_result parts: id = ToolResultMessage.toolCallId
101
+ * - text parts: id = undefined → we synthesize from message+ordinal
102
+ */
103
+ /**
104
+ * Per-callId aggregation of tool occurrences across the transcript.
105
+ * Built up during the walk and used to:
106
+ * 1. Assign one tag per call_id with byte_size from the LARGEST
107
+ * occurrence (typically the result, ~4KB) instead of the args
108
+ * (~58 bytes). Without this, drop projection underestimates
109
+ * reclaimable bytes by ~70× per tool.
110
+ * 2. Build a single aggregate TagTarget that mutates BOTH the
111
+ * invocation and result occurrences atomically, so a queued drop
112
+ * replaces both halves with a sentinel instead of last-write-wins.
113
+ */
114
+ interface ToolOccurrence {
115
+ message: { info: { id?: string; role: string } };
116
+ part: TranscriptPart;
117
+ kind: "tool_use" | "tool_result";
118
+ }
119
+
120
+ interface ToolAggregate {
121
+ callId: string;
122
+ occurrences: ToolOccurrence[];
123
+ /** Largest byteSize seen across occurrences — used as the tag size. */
124
+ maxByteSize: number;
125
+ /** Tool name from the first occurrence we see one on. */
126
+ toolName: string | null;
127
+ /** Input byte size from the invocation occurrence (for storage projection). */
128
+ inputByteSize: number;
129
+ }
130
+
131
+ export function tagTranscript(
132
+ sessionId: string,
133
+ transcript: Transcript,
134
+ tagger: Tagger,
135
+ db: ContextDatabase,
136
+ options: TagTranscriptOptions = {},
137
+ ): TagTranscriptResult {
138
+ const skipPrefixInjection = options.skipPrefixInjection === true;
139
+ const targets = new Map<number, TagTarget>();
140
+
141
+ // Per-callId tool aggregation tracked across the single walk. Tags
142
+ // get allocated in transcript order (first occurrence reserves the
143
+ // tag number); subsequent occurrences reuse the same tag and merge
144
+ // their occurrence into the aggregate's TagTarget. This preserves
145
+ // chronological tag numbering while still aggregating drop behavior
146
+ // across both invocation and result.
147
+ const toolAggregates = new Map<string, ToolAggregate & { tagId: number }>();
148
+
149
+ // v3.3.1 Layer C (plan v3.3.1 Finding #16): the previous outer
150
+ // db.transaction() wrapper rolled back EVERY tag insert + savedSource
151
+ // when a single UNIQUE collision fired late in the walk. Per-tag
152
+ // SAVEPOINTs inside `assignToolTag` / `assignTag` already give us the
153
+ // atomicity we need. Removing the wrapper matches OpenCode's
154
+ // tag-messages.ts design — see the long comment there for the
155
+ // rationale (cache-bust amplifier story).
156
+ for (let msgIndex = 0; msgIndex < transcript.messages.length; msgIndex += 1) {
157
+ const message = transcript.messages[msgIndex];
158
+ if (message === undefined) continue;
159
+ const messageId = message.info.id;
160
+
161
+ let textOrdinal = 0;
162
+ const parts = message.parts;
163
+
164
+ for (let partIndex = 0; partIndex < parts.length; partIndex += 1) {
165
+ const part = parts[partIndex];
166
+ if (part === undefined) continue;
167
+
168
+ if (part.kind === "text") {
169
+ // Synthetic message ids (Pi tail synthetic user with
170
+ // no id) cannot be tagged — there's no stable handle
171
+ // to bind a tag to across passes. Pass through
172
+ // untagged; this is rare (only happens for the
173
+ // dangling tool-result tail case in Pi).
174
+ if (messageId === undefined) {
175
+ textOrdinal += 1;
176
+ continue;
177
+ }
178
+ tagTextPart({
179
+ sessionId,
180
+ message,
181
+ messageId,
182
+ msgIndex,
183
+ textOrdinal,
184
+ part,
185
+ tagger,
186
+ db,
187
+ targets,
188
+ skipPrefixInjection,
189
+ });
190
+ textOrdinal += 1;
191
+ continue;
192
+ }
193
+
194
+ if (part.kind === "tool_use" || part.kind === "tool_result") {
195
+ if (messageId === undefined) continue;
196
+
197
+ const callId = part.id;
198
+ const text = part.getText() ?? "";
199
+ const meta = part.getToolMetadata();
200
+
201
+ if (typeof callId !== "string" || callId.length === 0) {
202
+ // No stable callId to aggregate on. Tag independently.
203
+ tagToolPart({
204
+ sessionId,
205
+ message,
206
+ messageId,
207
+ msgIndex,
208
+ partIndex,
209
+ part,
210
+ tagger,
211
+ db,
212
+ targets,
213
+ skipPrefixInjection,
214
+ });
215
+ continue;
216
+ }
217
+
218
+ const existing = toolAggregates.get(callId);
219
+ if (existing) {
220
+ // Second (or later) occurrence for this call_id.
221
+ // Merge into the existing aggregate, update byte_size
222
+ // in DB if larger, and rebuild the TagTarget so the
223
+ // closures over `occurrences` see all parts.
224
+ existing.occurrences.push({
225
+ message,
226
+ part,
227
+ kind: part.kind,
228
+ });
229
+ const newByteSize = byteSize(text);
230
+ if (newByteSize > existing.maxByteSize) {
231
+ existing.maxByteSize = newByteSize;
232
+ updateTagByteSize(db, sessionId, existing.tagId, newByteSize);
233
+ }
234
+ if (existing.toolName === null && meta.toolName) {
235
+ existing.toolName = meta.toolName;
236
+ }
237
+ if (
238
+ existing.inputByteSize === 0 &&
239
+ part.kind === "tool_use" &&
240
+ meta.inputByteSize > 0
241
+ ) {
242
+ existing.inputByteSize = meta.inputByteSize;
243
+ updateTagInputByteSize(db, sessionId, existing.tagId, meta.inputByteSize);
244
+ }
245
+ // Inject §N§ prefix into this tool_result occurrence
246
+ // (matches OpenCode behavior — only result gets the prefix).
247
+ if (!skipPrefixInjection && part.kind === "tool_result") {
248
+ part.setText(prependTag(existing.tagId, text));
249
+ }
250
+ // Rebuild the aggregate target so it walks the now-
251
+ // longer occurrences list.
252
+ targets.set(
253
+ existing.tagId,
254
+ buildAggregateTarget(existing.tagId, existing.occurrences),
255
+ );
256
+ } else {
257
+ // First occurrence — reserve the tag number.
258
+ // v3.3.1 Layer C: Pi main aggregation path. Owner
259
+ // is the Pi message hosting the tool aggregate.
260
+ // Owner stays stable across passes because Pi
261
+ // re-emits the full transcript each time and
262
+ // message ids are durable.
263
+ const tagId = tagger.assignToolTag(
264
+ sessionId,
265
+ callId,
266
+ messageId,
267
+ byteSize(text),
268
+ db,
269
+ 0,
270
+ meta.toolName ?? null,
271
+ meta.inputByteSize,
272
+ );
273
+ const aggregate = {
274
+ callId,
275
+ tagId,
276
+ occurrences: [
277
+ {
278
+ message,
279
+ part,
280
+ kind: part.kind,
281
+ },
282
+ ],
283
+ maxByteSize: byteSize(text),
284
+ toolName: meta.toolName ?? null,
285
+ inputByteSize: part.kind === "tool_use" ? meta.inputByteSize : 0,
286
+ };
287
+ toolAggregates.set(callId, aggregate);
288
+ // Inject §N§ prefix into this occurrence's visible text
289
+ // when it's a tool_result. (OpenCode parity: prefix
290
+ // only goes on the result, not the invocation.)
291
+ if (!skipPrefixInjection && part.kind === "tool_result") {
292
+ part.setText(prependTag(tagId, text));
293
+ }
294
+ targets.set(tagId, buildAggregateTarget(tagId, aggregate.occurrences));
295
+ }
296
+ }
297
+ // thinking, image, file, structural, unknown → skip.
298
+ }
299
+ }
300
+
301
+ return { targets };
302
+ }
303
+
304
+ interface TagTextPartArgs {
305
+ sessionId: string;
306
+ message: { info: { id?: string; role: string } };
307
+ messageId: string;
308
+ msgIndex: number;
309
+ textOrdinal: number;
310
+ part: TranscriptPart;
311
+ tagger: Tagger;
312
+ db: ContextDatabase;
313
+ targets: Map<number, TagTarget>;
314
+ skipPrefixInjection: boolean;
315
+ }
316
+
317
+ function tagTextPart(args: TagTextPartArgs): void {
318
+ const text = args.part.getText() ?? "";
319
+ const contentId = `${args.messageId}:p${args.textOrdinal}`;
320
+ const tagId = args.tagger.assignTag(
321
+ args.sessionId,
322
+ contentId,
323
+ "message",
324
+ byteSize(text),
325
+ args.db,
326
+ );
327
+
328
+ // Persist the original (pre-tagged) source content so caveman
329
+ // compression and other "compress from original" heuristics have
330
+ // pristine text to read on later passes. saveSourceContent uses
331
+ // INSERT OR IGNORE — first write wins; later passes that re-tag
332
+ // the same (sessionId, tagId) pair from already-prefixed text won't
333
+ // overwrite the original. Cache-stable.
334
+ //
335
+ // We strip any existing §N§ prefix before saving in case a previous
336
+ // pass already injected one and the persisted source got lost
337
+ // (e.g. legacy session created before this code shipped). For new
338
+ // sessions stripTagPrefix is a no-op on the very first pass.
339
+ const sourceContent = stripTagPrefix(text);
340
+ if (sourceContent.trim().length > 0) {
341
+ saveSourceContent(args.db, args.sessionId, tagId, sourceContent);
342
+ }
343
+
344
+ if (!args.skipPrefixInjection) {
345
+ args.part.setText(prependTag(tagId, text));
346
+ }
347
+
348
+ args.targets.set(tagId, buildTextTarget(args.part, args.message));
349
+ }
350
+
351
+ interface TagToolPartArgs {
352
+ sessionId: string;
353
+ message: { info: { id?: string; role: string } };
354
+ messageId: string;
355
+ msgIndex: number;
356
+ partIndex: number;
357
+ part: TranscriptPart;
358
+ tagger: Tagger;
359
+ db: ContextDatabase;
360
+ targets: Map<number, TagTarget>;
361
+ skipPrefixInjection: boolean;
362
+ }
363
+
364
+ function tagToolPart(args: TagToolPartArgs): void {
365
+ // Prefer the part's stable id (tool call id from Pi/OpenCode); fall
366
+ // back to a synthetic locator. Tool calls and their results MAY
367
+ // share an id (Pi sets toolCallId on ToolResultMessage to match the
368
+ // originating ToolCall.id); when that happens, both tag operations
369
+ // resolve to the same tag number — desired behavior, since drops
370
+ // target the call-id pair as a unit.
371
+ const stableId = args.part.id;
372
+ const contentId = stableId ?? `${args.messageId}:t${args.partIndex}`;
373
+ const text = args.part.getText() ?? "";
374
+ const meta = args.part.getToolMetadata();
375
+ // v3.3.1 Layer C: synthetic ownership for the no-callId Pi
376
+ // fallback. Owner == callId == contentId. The composite key
377
+ // collapses to a unique synthetic identifier per part, preserving
378
+ // the legacy "each part gets its own tag" behavior while
379
+ // satisfying the composite-identity contract (TagEntry.tool_owner_message_id
380
+ // is non-null, lazy-adoption path is correctly bypassed).
381
+ const tagId = args.tagger.assignToolTag(
382
+ args.sessionId,
383
+ contentId,
384
+ contentId,
385
+ byteSize(text),
386
+ args.db,
387
+ 0,
388
+ meta.toolName ?? null,
389
+ meta.inputByteSize,
390
+ );
391
+
392
+ // For tool parts, the visible payload is the tool result text. We
393
+ // can inject the tag prefix into it for in-text references; this
394
+ // matches the OpenCode behavior of tagging tool outputs.
395
+ if (!args.skipPrefixInjection && args.part.kind === "tool_result") {
396
+ const tagged = prependTag(tagId, text);
397
+ args.part.setText(tagged);
398
+ }
399
+
400
+ args.targets.set(tagId, buildToolTarget(args.part, args.message));
401
+ }
402
+
403
+ /**
404
+ * Build a TagTarget that walks ALL occurrences of a tool call (invocation
405
+ * + result) when mutating. This is the per-callId aggregate target used
406
+ * by `tagTranscript` so a single drop replaces both halves.
407
+ *
408
+ * The closures hold a reference to the same `occurrences` array stored
409
+ * on the aggregate, so when the array gets mutated (a second occurrence
410
+ * is pushed mid-walk), the next call to setContent/drop/truncate sees
411
+ * all occurrences automatically. Callers MUST rebuild the target after
412
+ * pushing a new occurrence so the targets map points to a fresh closure
413
+ * over the updated array — otherwise consumers that captured the target
414
+ * before the push won't see the new occurrence.
415
+ *
416
+ * Mirrors OpenCode's createToolDropTarget semantics in tool-drop-target.ts.
417
+ */
418
+ function buildAggregateTarget(tagId: number, occurrences: ToolOccurrence[]): TagTarget {
419
+ const role = occurrences[0]?.message.info.role ?? "user";
420
+ const messageId = occurrences[0]?.message.info.id;
421
+
422
+ return {
423
+ setContent(content: string): boolean {
424
+ // Walk all occurrences; mutate every one. Return true if at
425
+ // least one occurrence's content actually changed (used to
426
+ // gate sentinel-replay re-writes).
427
+ let changed = false;
428
+ for (const occ of occurrences) {
429
+ // Try setToolOutput first (works on tool_result-shaped parts);
430
+ // fall back to setText so tool_use parts also get sentinelized.
431
+ if (occ.part.setToolOutput(content)) {
432
+ changed = true;
433
+ } else if (occ.part.setText(content)) {
434
+ changed = true;
435
+ }
436
+ }
437
+ return changed;
438
+ },
439
+ getContent(): string | null {
440
+ // Prefer the result occurrence's content (the bulky payload).
441
+ for (const occ of occurrences) {
442
+ if (occ.kind === "tool_result") {
443
+ return occ.part.getText() ?? null;
444
+ }
445
+ }
446
+ return occurrences[0]?.part.getText() ?? null;
447
+ },
448
+ drop(): "removed" | "absent" {
449
+ // Replace BOTH halves with the dropped sentinel.
450
+ const sentinel = `[dropped \u00a7${tagId}\u00a7]`;
451
+ let any = false;
452
+ for (const occ of occurrences) {
453
+ if (occ.part.replaceWithSentinel(sentinel)) any = true;
454
+ }
455
+ return any ? "removed" : "absent";
456
+ },
457
+ truncate(): "truncated" | "absent" {
458
+ // Truncate BOTH halves. For tool_use, this typically truncates
459
+ // the args; for tool_result, the output. The sentinel string
460
+ // matches OpenCode's truncate sentinel exactly.
461
+ const sentinel = "[truncated]";
462
+ let any = false;
463
+ for (const occ of occurrences) {
464
+ if (occ.part.setToolOutput(sentinel) || occ.part.setText(sentinel)) {
465
+ any = true;
466
+ }
467
+ }
468
+ return any ? "truncated" : "absent";
469
+ },
470
+ message: {
471
+ info: { id: messageId, role },
472
+ parts: [],
473
+ },
474
+ };
475
+ }
476
+
477
+ /**
478
+ * TagTarget for a tag-eligible text part. The shared
479
+ * `applyPendingOperations` flow calls `setContent` to swap in a
480
+ * sentinel like `[dropped §N§]` when a queued drop fires; `getContent`
481
+ * returns the current visible text so the truncated-preview path can
482
+ * compute its before/after.
483
+ *
484
+ * The `message.info.role` is used by `buildReplacementContent` in
485
+ * `apply-operations.ts` to differentiate user-message drops (which
486
+ * preserve a truncated preview) from assistant drops (full sentinel).
487
+ */
488
+ function buildTextTarget(
489
+ part: TranscriptPart,
490
+ message: { info: { id?: string; role: string } },
491
+ ): TagTarget {
492
+ return {
493
+ setContent(content: string): boolean {
494
+ return part.setText(content);
495
+ },
496
+ getContent(): string | null {
497
+ return part.getText() ?? null;
498
+ },
499
+ // `message` is typed as MessageLike, which has parts: unknown[].
500
+ // We don't carry parts here (the apply-operations flow only
501
+ // reads `info.role` on this field), so a minimal stub is
502
+ // sufficient.
503
+ message: {
504
+ info: { id: message.info.id, role: message.info.role },
505
+ parts: [],
506
+ },
507
+ };
508
+ }
509
+
510
+ /**
511
+ * TagTarget for a tag-eligible tool part. Tool parts get full-drop
512
+ * (replace with `[dropped §N§]`) or truncated-drop (replace with
513
+ * `[truncated]`) treatment from `applyFlushedStatuses` based on the
514
+ * stored `drop_mode` column. We expose both via the standard target
515
+ * surface; replaceWithSentinel is the canonical mutation, with
516
+ * truncated-drop using the "[truncated]" string.
517
+ */
518
+ function buildToolTarget(
519
+ part: TranscriptPart,
520
+ message: { info: { id?: string; role: string } },
521
+ ): TagTarget {
522
+ return {
523
+ setContent(content: string): boolean {
524
+ return part.setToolOutput(content) || part.setText(content);
525
+ },
526
+ getContent(): string | null {
527
+ return part.getText() ?? null;
528
+ },
529
+ drop(): "removed" | "absent" {
530
+ // Replace the tool part's visible content with a "[dropped]"
531
+ // shell. We can't physically remove the part because Pi
532
+ // requires tool_use ↔ tool_result pairing for the LLM call
533
+ // to validate; instead we shrink the content to a sentinel.
534
+ // For Pi the current Transcript contract treats both
535
+ // invocation and result parts symmetrically — both expose
536
+ // setText / setToolOutput.
537
+ const replaced = part.replaceWithSentinel(`[dropped \u00a7${part.id ?? "?"}\u00a7]`);
538
+ return replaced ? "removed" : "absent";
539
+ },
540
+ truncate(): "truncated" | "absent" {
541
+ // Truncate the tool output to a fixed sentinel string. Done
542
+ // via setToolOutput so the underlying tool_result content
543
+ // gets the truncation; falls back to setText for cases
544
+ // where the part type doesn't support setToolOutput.
545
+ const ok = part.setToolOutput("[truncated]") || part.setText("[truncated]");
546
+ return ok ? "truncated" : "absent";
547
+ },
548
+ message: {
549
+ info: { id: message.info.id, role: message.info.role },
550
+ parts: [],
551
+ },
552
+ };
553
+ }