@cortexkit/opencode-magic-context 0.26.0 → 0.27.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 (285) hide show
  1. package/README.md +14 -12
  2. package/dist/agents/dreamer.d.ts +19 -0
  3. package/dist/agents/dreamer.d.ts.map +1 -1
  4. package/dist/agents/hidden-agent-registrations.d.ts +67 -0
  5. package/dist/agents/hidden-agent-registrations.d.ts.map +1 -0
  6. package/dist/agents/historian.d.ts +1 -0
  7. package/dist/agents/historian.d.ts.map +1 -1
  8. package/dist/agents/permissions.d.ts +15 -44
  9. package/dist/agents/permissions.d.ts.map +1 -1
  10. package/dist/agents/smart-note-compiler.d.ts +2 -0
  11. package/dist/agents/smart-note-compiler.d.ts.map +1 -0
  12. package/dist/config/index.d.ts +1 -1
  13. package/dist/config/index.d.ts.map +1 -1
  14. package/dist/config/migrate-config-location.d.ts +89 -0
  15. package/dist/config/migrate-config-location.d.ts.map +1 -0
  16. package/dist/config/migrate-dreamer-v2.d.ts +37 -0
  17. package/dist/config/migrate-dreamer-v2.d.ts.map +1 -0
  18. package/dist/config/migrate-experimental.d.ts.map +1 -1
  19. package/dist/config/project-security.d.ts +3 -0
  20. package/dist/config/project-security.d.ts.map +1 -1
  21. package/dist/config/prune-config-leaf.d.ts.map +1 -1
  22. package/dist/config/schema/magic-context.d.ts +584 -60
  23. package/dist/config/schema/magic-context.d.ts.map +1 -1
  24. package/dist/features/magic-context/compaction-marker.d.ts +9 -3
  25. package/dist/features/magic-context/compaction-marker.d.ts.map +1 -1
  26. package/dist/features/magic-context/compartment-chunk-embedding.d.ts +1 -1
  27. package/dist/features/magic-context/compartment-chunk-embedding.d.ts.map +1 -1
  28. package/dist/features/magic-context/dreamer/classify-prompt.d.ts +50 -0
  29. package/dist/features/magic-context/dreamer/classify-prompt.d.ts.map +1 -0
  30. package/dist/features/magic-context/dreamer/classify.d.ts +22 -0
  31. package/dist/features/magic-context/dreamer/classify.d.ts.map +1 -0
  32. package/dist/features/magic-context/dreamer/cron.d.ts +72 -0
  33. package/dist/features/magic-context/dreamer/cron.d.ts.map +1 -0
  34. package/dist/features/magic-context/dreamer/evaluate-smart-notes.d.ts +30 -0
  35. package/dist/features/magic-context/dreamer/evaluate-smart-notes.d.ts.map +1 -0
  36. package/dist/features/magic-context/dreamer/index.d.ts +1 -3
  37. package/dist/features/magic-context/dreamer/index.d.ts.map +1 -1
  38. package/dist/features/magic-context/dreamer/lease.d.ts +44 -6
  39. package/dist/features/magic-context/dreamer/lease.d.ts.map +1 -1
  40. package/dist/features/magic-context/dreamer/maintain-docs-protected-enforcement.d.ts +13 -0
  41. package/dist/features/magic-context/dreamer/maintain-docs-protected-enforcement.d.ts.map +1 -0
  42. package/dist/features/magic-context/dreamer/map-memories-prompt.d.ts +36 -0
  43. package/dist/features/magic-context/dreamer/map-memories-prompt.d.ts.map +1 -0
  44. package/dist/features/magic-context/dreamer/map-memories.d.ts +22 -0
  45. package/dist/features/magic-context/dreamer/map-memories.d.ts.map +1 -0
  46. package/dist/features/magic-context/dreamer/open-opencode-db.d.ts +7 -0
  47. package/dist/features/magic-context/dreamer/open-opencode-db.d.ts.map +1 -0
  48. package/dist/features/magic-context/dreamer/primer-seed.d.ts +25 -0
  49. package/dist/features/magic-context/dreamer/primer-seed.d.ts.map +1 -0
  50. package/dist/features/magic-context/dreamer/promote-primers.d.ts +21 -0
  51. package/dist/features/magic-context/dreamer/promote-primers.d.ts.map +1 -0
  52. package/dist/features/magic-context/dreamer/protected-regions.d.ts +19 -0
  53. package/dist/features/magic-context/dreamer/protected-regions.d.ts.map +1 -0
  54. package/dist/features/magic-context/dreamer/refresh-primers.d.ts +30 -0
  55. package/dist/features/magic-context/dreamer/refresh-primers.d.ts.map +1 -0
  56. package/dist/features/magic-context/dreamer/retrospective-learnings.d.ts +47 -0
  57. package/dist/features/magic-context/dreamer/retrospective-learnings.d.ts.map +1 -0
  58. package/dist/features/magic-context/dreamer/retrospective-orphan-sweep.d.ts +48 -0
  59. package/dist/features/magic-context/dreamer/retrospective-orphan-sweep.d.ts.map +1 -0
  60. package/dist/features/magic-context/dreamer/retrospective-raw-provider.d.ts +81 -0
  61. package/dist/features/magic-context/dreamer/retrospective-raw-provider.d.ts.map +1 -0
  62. package/dist/features/magic-context/dreamer/storage-dream-runs.d.ts +8 -0
  63. package/dist/features/magic-context/dreamer/storage-dream-runs.d.ts.map +1 -1
  64. package/dist/features/magic-context/dreamer/storage-task-schedule.d.ts +82 -0
  65. package/dist/features/magic-context/dreamer/storage-task-schedule.d.ts.map +1 -0
  66. package/dist/features/magic-context/dreamer/task-config.d.ts +28 -0
  67. package/dist/features/magic-context/dreamer/task-config.d.ts.map +1 -0
  68. package/dist/features/magic-context/dreamer/task-executor.d.ts +49 -0
  69. package/dist/features/magic-context/dreamer/task-executor.d.ts.map +1 -0
  70. package/dist/features/magic-context/dreamer/task-gates.d.ts +29 -0
  71. package/dist/features/magic-context/dreamer/task-gates.d.ts.map +1 -0
  72. package/dist/features/magic-context/dreamer/task-prompts.d.ts +37 -6
  73. package/dist/features/magic-context/dreamer/task-prompts.d.ts.map +1 -1
  74. package/dist/features/magic-context/dreamer/task-registry.d.ts +48 -0
  75. package/dist/features/magic-context/dreamer/task-registry.d.ts.map +1 -0
  76. package/dist/features/magic-context/dreamer/task-scheduler.d.ts +88 -0
  77. package/dist/features/magic-context/dreamer/task-scheduler.d.ts.map +1 -0
  78. package/dist/features/magic-context/dreamer/verify-gate.d.ts +43 -0
  79. package/dist/features/magic-context/dreamer/verify-gate.d.ts.map +1 -0
  80. package/dist/features/magic-context/dreamer/verify-prompt.d.ts +41 -0
  81. package/dist/features/magic-context/dreamer/verify-prompt.d.ts.map +1 -0
  82. package/dist/features/magic-context/dreamer/verify.d.ts +43 -0
  83. package/dist/features/magic-context/dreamer/verify.d.ts.map +1 -0
  84. package/dist/features/magic-context/git-commits/search-git-commits.d.ts +2 -0
  85. package/dist/features/magic-context/git-commits/search-git-commits.d.ts.map +1 -1
  86. package/dist/features/magic-context/git-commits/storage-git-commit-embeddings.d.ts +4 -4
  87. package/dist/features/magic-context/git-commits/storage-git-commit-embeddings.d.ts.map +1 -1
  88. package/dist/features/magic-context/index.d.ts +1 -0
  89. package/dist/features/magic-context/index.d.ts.map +1 -1
  90. package/dist/features/magic-context/memory/embedding-cache.d.ts +2 -2
  91. package/dist/features/magic-context/memory/embedding-cache.d.ts.map +1 -1
  92. package/dist/features/magic-context/memory/embedding-identity.d.ts.map +1 -1
  93. package/dist/features/magic-context/memory/embedding-local.d.ts.map +1 -1
  94. package/dist/features/magic-context/memory/embedding-openai.d.ts +12 -5
  95. package/dist/features/magic-context/memory/embedding-openai.d.ts.map +1 -1
  96. package/dist/features/magic-context/memory/embedding.d.ts +2 -2
  97. package/dist/features/magic-context/memory/embedding.d.ts.map +1 -1
  98. package/dist/features/magic-context/memory/index.d.ts +4 -1
  99. package/dist/features/magic-context/memory/index.d.ts.map +1 -1
  100. package/dist/features/magic-context/memory/memory-migration.d.ts +1 -0
  101. package/dist/features/magic-context/memory/memory-migration.d.ts.map +1 -1
  102. package/dist/features/magic-context/memory/promotion.d.ts +16 -4
  103. package/dist/features/magic-context/memory/promotion.d.ts.map +1 -1
  104. package/dist/features/magic-context/memory/storage-memory-embeddings.d.ts +2 -2
  105. package/dist/features/magic-context/memory/storage-memory-embeddings.d.ts.map +1 -1
  106. package/dist/features/magic-context/memory/storage-memory-verifications.d.ts +31 -0
  107. package/dist/features/magic-context/memory/storage-memory-verifications.d.ts.map +1 -0
  108. package/dist/features/magic-context/memory/storage-memory.d.ts +12 -1
  109. package/dist/features/magic-context/memory/storage-memory.d.ts.map +1 -1
  110. package/dist/features/magic-context/memory/types.d.ts +4 -0
  111. package/dist/features/magic-context/memory/types.d.ts.map +1 -1
  112. package/dist/features/magic-context/memory/verification-paths.d.ts +32 -0
  113. package/dist/features/magic-context/memory/verification-paths.d.ts.map +1 -0
  114. package/dist/features/magic-context/message-index.d.ts.map +1 -1
  115. package/dist/features/magic-context/migrations.d.ts.map +1 -1
  116. package/dist/features/magic-context/overflow-detection.d.ts.map +1 -1
  117. package/dist/features/magic-context/primer-clustering.d.ts +29 -0
  118. package/dist/features/magic-context/primer-clustering.d.ts.map +1 -0
  119. package/dist/features/magic-context/project-embedding-registry.d.ts +25 -1
  120. package/dist/features/magic-context/project-embedding-registry.d.ts.map +1 -1
  121. package/dist/features/magic-context/search.d.ts +12 -2
  122. package/dist/features/magic-context/search.d.ts.map +1 -1
  123. package/dist/features/magic-context/sidekick/agent.d.ts.map +1 -1
  124. package/dist/features/magic-context/smart-notes/capabilities.d.ts +31 -0
  125. package/dist/features/magic-context/smart-notes/capabilities.d.ts.map +1 -0
  126. package/dist/features/magic-context/smart-notes/compiler-prompt.d.ts +2 -0
  127. package/dist/features/magic-context/smart-notes/compiler-prompt.d.ts.map +1 -0
  128. package/dist/features/magic-context/smart-notes/compiler.d.ts +52 -0
  129. package/dist/features/magic-context/smart-notes/compiler.d.ts.map +1 -0
  130. package/dist/features/magic-context/smart-notes/index.d.ts +10 -0
  131. package/dist/features/magic-context/smart-notes/index.d.ts.map +1 -0
  132. package/dist/features/magic-context/smart-notes/runner.d.ts +18 -0
  133. package/dist/features/magic-context/smart-notes/runner.d.ts.map +1 -0
  134. package/dist/features/magic-context/smart-notes/sandbox-runner.d.ts +22 -0
  135. package/dist/features/magic-context/smart-notes/sandbox-runner.d.ts.map +1 -0
  136. package/dist/features/magic-context/smart-notes/schedule.d.ts +9 -0
  137. package/dist/features/magic-context/smart-notes/schedule.d.ts.map +1 -0
  138. package/dist/features/magic-context/smart-notes/ssrf-guard.d.ts +49 -0
  139. package/dist/features/magic-context/smart-notes/ssrf-guard.d.ts.map +1 -0
  140. package/dist/features/magic-context/smart-notes/storage.d.ts +27 -0
  141. package/dist/features/magic-context/smart-notes/storage.d.ts.map +1 -0
  142. package/dist/features/magic-context/smart-notes/types.d.ts +63 -0
  143. package/dist/features/magic-context/smart-notes/types.d.ts.map +1 -0
  144. package/dist/features/magic-context/storage-db.d.ts +5 -1
  145. package/dist/features/magic-context/storage-db.d.ts.map +1 -1
  146. package/dist/features/magic-context/storage-meta-persisted.d.ts +8 -4
  147. package/dist/features/magic-context/storage-meta-persisted.d.ts.map +1 -1
  148. package/dist/features/magic-context/storage-meta-session.d.ts.map +1 -1
  149. package/dist/features/magic-context/storage-meta-shared.d.ts +3 -1
  150. package/dist/features/magic-context/storage-meta-shared.d.ts.map +1 -1
  151. package/dist/features/magic-context/storage-notes.d.ts +15 -0
  152. package/dist/features/magic-context/storage-notes.d.ts.map +1 -1
  153. package/dist/features/magic-context/storage-primers.d.ts +85 -0
  154. package/dist/features/magic-context/storage-primers.d.ts.map +1 -0
  155. package/dist/features/magic-context/storage-tags.d.ts +20 -0
  156. package/dist/features/magic-context/storage-tags.d.ts.map +1 -1
  157. package/dist/features/magic-context/storage.d.ts +2 -1
  158. package/dist/features/magic-context/storage.d.ts.map +1 -1
  159. package/dist/features/magic-context/tagger.d.ts +6 -0
  160. package/dist/features/magic-context/tagger.d.ts.map +1 -1
  161. package/dist/features/magic-context/tool-owner-backfill.d.ts.map +1 -1
  162. package/dist/features/magic-context/transform-decision-log.d.ts +10 -0
  163. package/dist/features/magic-context/transform-decision-log.d.ts.map +1 -1
  164. package/dist/features/magic-context/types.d.ts +2 -0
  165. package/dist/features/magic-context/types.d.ts.map +1 -1
  166. package/dist/features/magic-context/user-memory/review-user-memories.d.ts +5 -0
  167. package/dist/features/magic-context/user-memory/review-user-memories.d.ts.map +1 -1
  168. package/dist/features/magic-context/user-memory/storage-user-memory.d.ts +18 -0
  169. package/dist/features/magic-context/user-memory/storage-user-memory.d.ts.map +1 -1
  170. package/dist/features/magic-context/v22-deferred-backfill.d.ts.map +1 -1
  171. package/dist/hooks/auto-update-checker/semver.d.ts +9 -0
  172. package/dist/hooks/auto-update-checker/semver.d.ts.map +1 -1
  173. package/dist/hooks/magic-context/auto-search-hint.d.ts.map +1 -1
  174. package/dist/hooks/magic-context/command-handler.d.ts +8 -15
  175. package/dist/hooks/magic-context/command-handler.d.ts.map +1 -1
  176. package/dist/hooks/magic-context/compaction-marker-manager.d.ts.map +1 -1
  177. package/dist/hooks/magic-context/compartment-parser.d.ts +9 -0
  178. package/dist/hooks/magic-context/compartment-parser.d.ts.map +1 -1
  179. package/dist/hooks/magic-context/compartment-prompt.d.ts +4 -1
  180. package/dist/hooks/magic-context/compartment-prompt.d.ts.map +1 -1
  181. package/dist/hooks/magic-context/compartment-runner-historian.d.ts +1 -0
  182. package/dist/hooks/magic-context/compartment-runner-historian.d.ts.map +1 -1
  183. package/dist/hooks/magic-context/compartment-runner-incremental.d.ts.map +1 -1
  184. package/dist/hooks/magic-context/compartment-runner-partial-recomp.d.ts.map +1 -1
  185. package/dist/hooks/magic-context/compartment-runner-recomp.d.ts.map +1 -1
  186. package/dist/hooks/magic-context/compartment-runner-types.d.ts +8 -0
  187. package/dist/hooks/magic-context/compartment-runner-types.d.ts.map +1 -1
  188. package/dist/hooks/magic-context/compartment-runner-validation.d.ts.map +1 -1
  189. package/dist/hooks/magic-context/compartment-trigger.d.ts.map +1 -1
  190. package/dist/hooks/magic-context/ctx-reduce-nudge.d.ts.map +1 -1
  191. package/dist/hooks/magic-context/event-handler.d.ts.map +1 -1
  192. package/dist/hooks/magic-context/event-resolvers.d.ts.map +1 -1
  193. package/dist/hooks/magic-context/historian-prompt.generated.d.ts +1 -1
  194. package/dist/hooks/magic-context/historian-prompt.generated.d.ts.map +1 -1
  195. package/dist/hooks/magic-context/historian-state-file.d.ts.map +1 -1
  196. package/dist/hooks/magic-context/hook-handlers.d.ts +2 -1
  197. package/dist/hooks/magic-context/hook-handlers.d.ts.map +1 -1
  198. package/dist/hooks/magic-context/hook.d.ts +1 -0
  199. package/dist/hooks/magic-context/hook.d.ts.map +1 -1
  200. package/dist/hooks/magic-context/inject-compartments.d.ts +0 -3
  201. package/dist/hooks/magic-context/inject-compartments.d.ts.map +1 -1
  202. package/dist/hooks/magic-context/send-session-notification.d.ts +2 -0
  203. package/dist/hooks/magic-context/send-session-notification.d.ts.map +1 -1
  204. package/dist/hooks/magic-context/system-prompt-hash.d.ts +17 -0
  205. package/dist/hooks/magic-context/system-prompt-hash.d.ts.map +1 -1
  206. package/dist/hooks/magic-context/transform-postprocess-phase.d.ts +8 -5
  207. package/dist/hooks/magic-context/transform-postprocess-phase.d.ts.map +1 -1
  208. package/dist/hooks/magic-context/transform.d.ts +0 -2
  209. package/dist/hooks/magic-context/transform.d.ts.map +1 -1
  210. package/dist/index.d.ts +2 -2
  211. package/dist/index.d.ts.map +1 -1
  212. package/dist/index.js +17028 -4059
  213. package/dist/plugin/dream-timer.d.ts +17 -9
  214. package/dist/plugin/dream-timer.d.ts.map +1 -1
  215. package/dist/plugin/embedding-bootstrap-helpers.d.ts +1 -1
  216. package/dist/plugin/embedding-bootstrap-helpers.d.ts.map +1 -1
  217. package/dist/plugin/embedding-bootstrap.d.ts.map +1 -1
  218. package/dist/plugin/hooks/create-session-hooks.d.ts +211 -0
  219. package/dist/plugin/hooks/create-session-hooks.d.ts.map +1 -1
  220. package/dist/plugin/instance-disposal.d.ts +2 -0
  221. package/dist/plugin/instance-disposal.d.ts.map +1 -0
  222. package/dist/plugin/rpc-handlers.d.ts.map +1 -1
  223. package/dist/shared/announcement.d.ts +1 -1
  224. package/dist/shared/announcement.d.ts.map +1 -1
  225. package/dist/shared/data-path.d.ts +26 -7
  226. package/dist/shared/data-path.d.ts.map +1 -1
  227. package/dist/shared/model-suggestion-retry.d.ts +48 -2
  228. package/dist/shared/model-suggestion-retry.d.ts.map +1 -1
  229. package/dist/shared/redaction.d.ts +7 -0
  230. package/dist/shared/redaction.d.ts.map +1 -0
  231. package/dist/shared/resolve-fallbacks.d.ts +12 -0
  232. package/dist/shared/resolve-fallbacks.d.ts.map +1 -1
  233. package/dist/shared/rpc-server.d.ts.map +1 -1
  234. package/dist/shared/rpc-types.d.ts +2 -0
  235. package/dist/shared/rpc-types.d.ts.map +1 -1
  236. package/dist/shared/subagent-runner.d.ts +12 -3
  237. package/dist/shared/subagent-runner.d.ts.map +1 -1
  238. package/dist/shared/tui-config.d.ts.map +1 -1
  239. package/dist/tools/ctx-memory/tools.d.ts.map +1 -1
  240. package/dist/tools/ctx-memory/types.d.ts.map +1 -1
  241. package/dist/tools/ctx-memory/verification-recording.d.ts +8 -0
  242. package/dist/tools/ctx-memory/verification-recording.d.ts.map +1 -0
  243. package/dist/tools/ctx-search/tools.d.ts.map +1 -1
  244. package/dist/tools/ctx-search/types.d.ts +1 -1
  245. package/dist/tools/ctx-search/types.d.ts.map +1 -1
  246. package/dist/tui/data/context-db.d.ts +2 -0
  247. package/dist/tui/data/context-db.d.ts.map +1 -1
  248. package/package.json +3 -1
  249. package/src/shared/announcement.test.ts +20 -0
  250. package/src/shared/announcement.ts +19 -7
  251. package/src/shared/data-path.test.ts +70 -6
  252. package/src/shared/data-path.ts +50 -8
  253. package/src/shared/model-suggestion-retry.test.ts +79 -2
  254. package/src/shared/model-suggestion-retry.ts +181 -3
  255. package/src/shared/redaction.test.ts +48 -0
  256. package/src/shared/redaction.ts +240 -0
  257. package/src/shared/resolve-fallbacks.ts +14 -0
  258. package/src/shared/rpc-server.ts +24 -0
  259. package/src/shared/rpc-types.ts +2 -0
  260. package/src/shared/subagent-runner.ts +12 -3
  261. package/src/shared/tui-config.test.ts +63 -0
  262. package/src/shared/tui-config.ts +67 -39
  263. package/src/tui/data/context-db.ts +12 -0
  264. package/src/tui/index.tsx +87 -17
  265. package/src/tui/slots/sidebar-content.tsx +4 -0
  266. package/dist/features/magic-context/dreamer/queue.d.ts +0 -55
  267. package/dist/features/magic-context/dreamer/queue.d.ts.map +0 -1
  268. package/dist/features/magic-context/dreamer/runner.d.ts +0 -92
  269. package/dist/features/magic-context/dreamer/runner.d.ts.map +0 -1
  270. package/dist/features/magic-context/dreamer/scheduler.d.ts +0 -29
  271. package/dist/features/magic-context/dreamer/scheduler.d.ts.map +0 -1
  272. package/dist/features/magic-context/key-files/aft-availability.d.ts +0 -11
  273. package/dist/features/magic-context/key-files/aft-availability.d.ts.map +0 -1
  274. package/dist/features/magic-context/key-files/identify-key-files.d.ts +0 -84
  275. package/dist/features/magic-context/key-files/identify-key-files.d.ts.map +0 -1
  276. package/dist/features/magic-context/key-files/project-key-files.d.ts +0 -42
  277. package/dist/features/magic-context/key-files/project-key-files.d.ts.map +0 -1
  278. package/dist/features/magic-context/key-files/read-history.d.ts +0 -26
  279. package/dist/features/magic-context/key-files/read-history.d.ts.map +0 -1
  280. package/dist/features/magic-context/key-files/read-stats.d.ts +0 -18
  281. package/dist/features/magic-context/key-files/read-stats.d.ts.map +0 -1
  282. package/dist/features/magic-context/key-files/storage-key-files.d.ts +0 -20
  283. package/dist/features/magic-context/key-files/storage-key-files.d.ts.map +0 -1
  284. package/dist/hooks/magic-context/key-files-block.d.ts +0 -27
  285. package/dist/hooks/magic-context/key-files-block.d.ts.map +0 -1
@@ -0,0 +1,47 @@
1
+ import type { Database } from "../../../shared/sqlite";
2
+ import type { MemoryCategory } from "../memory/types";
3
+ export type RetrospectiveLearningRoute = "memory" | "observation";
4
+ export interface ParsedRetrospectiveLearning {
5
+ route: RetrospectiveLearningRoute;
6
+ content: string;
7
+ category?: MemoryCategory;
8
+ }
9
+ export interface RetrospectiveApplyResult {
10
+ memoryWritten: number;
11
+ observationsInserted: number;
12
+ observationsDropped: number;
13
+ rejected: Array<{
14
+ content: string;
15
+ reason: string;
16
+ }>;
17
+ }
18
+ export declare function parseRetrospectiveLearnings(text: string): ParsedRetrospectiveLearning[];
19
+ export declare const MAX_SOURCE_WORD_RUN = 7;
20
+ export declare const MAX_SOURCE_WORD_RUN_RATIO = 0.5;
21
+ export declare const MAX_OVERLAP_LEARNING_WORDS = 200;
22
+ /**
23
+ * True when `content` reads as a near-transcription of any source user line:
24
+ * it shares a contiguous run of ≥ runCap words (an absolute cap of
25
+ * MAX_SOURCE_WORD_RUN, or half the learning's own length for very short
26
+ * learnings). This is the structural enforcement of "distill, don't transcribe"
27
+ * — the regexes catch quotes/dates/anger; this catches a lightly-reworded user
28
+ * sentence that would otherwise pass.
29
+ *
30
+ * Implementation: since runCap ≤ MAX_SOURCE_WORD_RUN (small), "a shared run ≥
31
+ * runCap exists" is equivalent to "some runCap-gram of the learning occurs in the
32
+ * source". We build the learning's runCap-grams once (≤ learning length) and
33
+ * stream each FULL source past them — O(Σ source words) time, O(learning) memory,
34
+ * with NO source truncation (a verbatim run at any offset is caught).
35
+ */
36
+ export declare function hasHighSourceOverlap(content: string, sourceUserTexts: string[]): boolean;
37
+ export declare function validateRetrospectiveLearningText(content: string, sourceUserTexts?: readonly string[]): string | null;
38
+ export declare function applyRetrospectiveLearnings(args: {
39
+ db: Database;
40
+ projectIdentity: string;
41
+ sourceSessionId: string;
42
+ learnings: ParsedRetrospectiveLearning[];
43
+ userMemoryCollectionEnabled: boolean;
44
+ /** The raw source user lines, for the near-transcription reject check. */
45
+ sourceUserTexts?: readonly string[];
46
+ }): RetrospectiveApplyResult;
47
+ //# sourceMappingURL=retrospective-learnings.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retrospective-learnings.d.ts","sourceRoot":"","sources":["../../../../src/features/magic-context/dreamer/retrospective-learnings.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAGvD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAWtD,MAAM,MAAM,0BAA0B,GAAG,QAAQ,GAAG,aAAa,CAAC;AAElE,MAAM,WAAW,2BAA2B;IACxC,KAAK,EAAE,0BAA0B,CAAC;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,cAAc,CAAC;CAC7B;AAED,MAAM,WAAW,wBAAwB;IACrC,aAAa,EAAE,MAAM,CAAC;IACtB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,mBAAmB,EAAE,MAAM,CAAC;IAC5B,QAAQ,EAAE,KAAK,CAAC;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACxD;AAgBD,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,MAAM,GAAG,2BAA2B,EAAE,CAuBvF;AAKD,eAAO,MAAM,mBAAmB,IAAI,CAAC;AACrC,eAAO,MAAM,yBAAyB,MAAM,CAAC;AAK7C,eAAO,MAAM,0BAA0B,MAAM,CAAC;AAW9C;;;;;;;;;;;;;GAaG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,EAAE,GAAG,OAAO,CAwBxF;AAED,wBAAgB,iCAAiC,CAC7C,OAAO,EAAE,MAAM,EACf,eAAe,GAAE,SAAS,MAAM,EAAO,GACxC,MAAM,GAAG,IAAI,CAMf;AAED,wBAAgB,2BAA2B,CAAC,IAAI,EAAE;IAC9C,EAAE,EAAE,QAAQ,CAAC;IACb,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,EAAE,MAAM,CAAC;IACxB,SAAS,EAAE,2BAA2B,EAAE,CAAC;IACzC,2BAA2B,EAAE,OAAO,CAAC;IACrC,0EAA0E;IAC1E,eAAe,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CACvC,GAAG,wBAAwB,CA8D3B"}
@@ -0,0 +1,48 @@
1
+ import type { PluginContext } from "../../../plugin/types";
2
+ import type { Database } from "../../../shared/sqlite";
3
+ type OpencodeClient = PluginContext["client"];
4
+ /**
5
+ * Privacy backstop for dreamer children that carry raw user or project text.
6
+ *
7
+ * These child sessions normally delete themselves in `finally`, but a hard
8
+ * SIGKILL/OOM BETWEEN session-create and that delete would leave their prompts
9
+ * on disk. This sweep removes such crash-orphaned children.
10
+ *
11
+ * CONCURRENCY: `session.delete` has no cross-process "active session" lease (OC
12
+ * peer confirmed), so the ONLY safe filter is AGE — a child older than any
13
+ * legitimate run cannot belong to a live run on another OpenCode process.
14
+ * OpenCode sets `title` + `time_created` immediately at create (not lazily), so
15
+ * the age gate is airtight. 404 on delete = already-swept = success.
16
+ */
17
+ export declare const RETROSPECTIVE_CHILD_TITLE = "magic-context-dream-retrospective";
18
+ export declare const USER_MEMORIES_CHILD_TITLE = "magic-context-dream-user-memories";
19
+ export declare const CURATE_CHILD_TITLE = "magic-context-dream-curate";
20
+ export declare const MAINTAIN_DOCS_CHILD_TITLE = "magic-context-dream-maintain-docs";
21
+ export declare const REFRESH_PRIMERS_CHILD_TITLE = "magic-context-dream-refresh-primers";
22
+ export declare const SMART_NOTE_COMPILE_CHILD_TITLE_PREFIX = "magic-context-smart-note-compile-";
23
+ export declare const SMART_NOTE_CONFIRM_CHILD_TITLE_PREFIX = "magic-context-smart-note-confirm-";
24
+ export declare const PRIVACY_SENSITIVE_CHILD_TASKS: readonly ["retrospective", "review-user-memories", "curate", "maintain-docs", "refresh-primers", "evaluate-smart-notes"];
25
+ export interface PrivacySensitiveChildTitleMatches {
26
+ exact: readonly string[];
27
+ prefixes: readonly string[];
28
+ }
29
+ export declare const PRIVACY_SENSITIVE_CHILD_TITLE_MATCHES: PrivacySensitiveChildTitleMatches;
30
+ /** Stale threshold from task timeout(s): max(60min, maxTimeout×3) — comfortably
31
+ * past every swept child type so a live child is never swept. */
32
+ export declare function retrospectiveOrphanStaleMs(taskTimeoutMinutes: number | undefined | readonly (number | undefined)[]): number;
33
+ /**
34
+ * Delete crash-orphaned privacy-sensitive dreamer children for THIS project
35
+ * directory when they are older than `staleMs`. Best-effort + fail-open: any
36
+ * DB/schema/API error is logged and skipped (never throws into the caller's
37
+ * sweep). Returns the count deleted.
38
+ */
39
+ export declare function sweepOrphanedRetrospectiveChildren(args: {
40
+ opencodeDb: Database | null;
41
+ client: OpencodeClient;
42
+ sessionDirectory: string;
43
+ staleMs: number;
44
+ titleMatches?: PrivacySensitiveChildTitleMatches;
45
+ now?: number;
46
+ }): Promise<number>;
47
+ export {};
48
+ //# sourceMappingURL=retrospective-orphan-sweep.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retrospective-orphan-sweep.d.ts","sourceRoot":"","sources":["../../../../src/features/magic-context/dreamer/retrospective-orphan-sweep.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAE3D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAGvD,KAAK,cAAc,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC;AAE9C;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,yBAAyB,sCAAsC,CAAC;AAC7E,eAAO,MAAM,yBAAyB,sCAAsC,CAAC;AAC7E,eAAO,MAAM,kBAAkB,+BAA+B,CAAC;AAC/D,eAAO,MAAM,yBAAyB,sCAAsC,CAAC;AAC7E,eAAO,MAAM,2BAA2B,wCAAwC,CAAC;AACjF,eAAO,MAAM,qCAAqC,sCAAsC,CAAC;AACzF,eAAO,MAAM,qCAAqC,sCAAsC,CAAC;AAEzF,eAAO,MAAM,6BAA6B,0HAOG,CAAC;AAE9C,MAAM,WAAW,iCAAiC;IAC9C,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;IACzB,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;CAC/B;AAED,eAAO,MAAM,qCAAqC,EAAE,iCASnD,CAAC;AAEF;kEACkE;AAClE,wBAAgB,0BAA0B,CACtC,kBAAkB,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS,CAAC,MAAM,GAAG,SAAS,CAAC,EAAE,GACzE,MAAM,CAUR;AAOD;;;;;GAKG;AACH,wBAAsB,kCAAkC,CAAC,IAAI,EAAE;IAC3D,UAAU,EAAE,QAAQ,GAAG,IAAI,CAAC;IAC5B,MAAM,EAAE,cAAc,CAAC;IACvB,gBAAgB,EAAE,MAAM,CAAC;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,iCAAiC,CAAC;IACjD,GAAG,CAAC,EAAE,MAAM,CAAC;CAChB,GAAG,OAAO,CAAC,MAAM,CAAC,CAoDlB"}
@@ -0,0 +1,81 @@
1
+ import type { Database } from "../../../shared/sqlite";
2
+ export declare const RETROSPECTIVE_MAX_MESSAGES_PER_SESSION = 80;
3
+ export declare const RETROSPECTIVE_MAX_MESSAGES_PER_RUN = 240;
4
+ export declare const RETROSPECTIVE_MAX_SESSIONS_PER_RUN = 20;
5
+ export type RetrospectiveMessageRole = "user" | "assistant" | "tool";
6
+ export interface RetrospectiveProjectSession {
7
+ sessionId: string;
8
+ path?: string;
9
+ updatedAt?: number;
10
+ }
11
+ export interface RetrospectiveRawMessage {
12
+ sessionId: string;
13
+ ordinal: number;
14
+ role: RetrospectiveMessageRole;
15
+ text: string;
16
+ toolName?: string;
17
+ isError?: boolean;
18
+ ts: number;
19
+ }
20
+ /** A per-session since-read. `truncated` is the EXACT saturation signal (the
21
+ * underlying read hit `capPerSession` with more rows available) — never inferred
22
+ * from `messages.length`, because normalization both drops rows (assistant/empty)
23
+ * and adds rows (one assistant message → many tool rows), so a length-based guess
24
+ * can false-NEGATIVE and lose data. */
25
+ export interface RetrospectiveSinceRead {
26
+ messages: RetrospectiveRawMessage[];
27
+ truncated: boolean;
28
+ }
29
+ export interface RetrospectiveRawProvider {
30
+ listProjectSessions(projectIdentity: string): RetrospectiveProjectSession[] | Promise<RetrospectiveProjectSession[]>;
31
+ readUserMessagesSince(sessionId: string, sinceMs: number, capPerSession: number): RetrospectiveSinceRead | Promise<RetrospectiveSinceRead>;
32
+ /** The ~`count` most recent typed USER messages at or before `beforeMs` — the
33
+ * run-boundary overlap so friction spanning two runs isn't missed. */
34
+ readUserMessagesBefore(sessionId: string, beforeMs: number, count: number): RetrospectiveRawMessage[] | Promise<RetrospectiveRawMessage[]>;
35
+ /** Release any reused resources (e.g. a pooled DB handle) after a run. */
36
+ dispose?(): void;
37
+ }
38
+ interface OpenCodeRetrospectiveRawProviderDeps {
39
+ contextDb: Database;
40
+ openOpenCodeDb?: () => Database | null;
41
+ /** Test-only shortcut: when provided, this connection is not closed by the provider. */
42
+ opencodeDb?: Database;
43
+ }
44
+ export declare class OpenCodeRetrospectiveRawProvider implements RetrospectiveRawProvider {
45
+ private readonly deps;
46
+ private readonly openDb;
47
+ private sharedDb;
48
+ private sharedDbOpened;
49
+ constructor(deps: OpenCodeRetrospectiveRawProviderDeps);
50
+ listProjectSessions(projectIdentity: string): RetrospectiveProjectSession[];
51
+ private resolveDb;
52
+ readUserMessagesSince(sessionId: string, sinceMs: number, capPerSession: number): RetrospectiveSinceRead;
53
+ readUserMessagesBefore(sessionId: string, beforeMs: number, count: number): RetrospectiveRawMessage[];
54
+ /** Close the reused read-only handle. Safe to call multiple times. */
55
+ dispose(): void;
56
+ }
57
+ export interface RetrospectiveScanWindow {
58
+ /** All scanned messages (user rows + tool metadata), oldest→newest, ordinals
59
+ * reassigned globally. Includes the pre-watermark overlap (user-only). */
60
+ messages: RetrospectiveRawMessage[];
61
+ /** The max message ts ACTUALLY scanned this run (the content watermark to
62
+ * persist on completion). Never less than `watermarkMs` (overlap rows are
63
+ * ≤ watermark and cannot pull it back). */
64
+ maxScannedTs: number;
65
+ }
66
+ /**
67
+ * The retrospective scan window for one run: everything new since the content
68
+ * watermark, PLUS the ~`overlapUserCount` user lines immediately before the
69
+ * watermark for sessions that have kept new rows (so friction straddling a run
70
+ * boundary isn't missed).
71
+ * The since portion carries user rows + tool metadata (the deepen context); the
72
+ * overlap portion is user-only (gate context). Ordinals are reassigned globally.
73
+ */
74
+ export declare function readRetrospectiveScanWindow(provider: RetrospectiveRawProvider, projectIdentity: string, watermarkMs: number, overlapUserCount: number, options?: {
75
+ maxMessagesPerRun?: number;
76
+ capPerSession?: number;
77
+ maxSessionsPerRun?: number;
78
+ }): Promise<RetrospectiveScanWindow>;
79
+ export declare function sameResolvedPath(a: string, b: string): boolean;
80
+ export {};
81
+ //# sourceMappingURL=retrospective-raw-provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retrospective-raw-provider.d.ts","sourceRoot":"","sources":["../../../../src/features/magic-context/dreamer/retrospective-raw-provider.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAIvD,eAAO,MAAM,sCAAsC,KAAK,CAAC;AACzD,eAAO,MAAM,kCAAkC,MAAM,CAAC;AAItD,eAAO,MAAM,kCAAkC,KAAK,CAAC;AAErD,MAAM,MAAM,wBAAwB,GAAG,MAAM,GAAG,WAAW,GAAG,MAAM,CAAC;AAErE,MAAM,WAAW,2BAA2B;IACxC,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,uBAAuB;IACpC,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,wBAAwB,CAAC;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,EAAE,EAAE,MAAM,CAAC;CACd;AAED;;;;wCAIwC;AACxC,MAAM,WAAW,sBAAsB;IACnC,QAAQ,EAAE,uBAAuB,EAAE,CAAC;IACpC,SAAS,EAAE,OAAO,CAAC;CACtB;AAED,MAAM,WAAW,wBAAwB;IACrC,mBAAmB,CACf,eAAe,EAAE,MAAM,GACxB,2BAA2B,EAAE,GAAG,OAAO,CAAC,2BAA2B,EAAE,CAAC,CAAC;IAC1E,qBAAqB,CACjB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,EACf,aAAa,EAAE,MAAM,GACtB,sBAAsB,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAAC;IAC5D;2EACuE;IACvE,sBAAsB,CAClB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,GACd,uBAAuB,EAAE,GAAG,OAAO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F,OAAO,CAAC,uBAAuB,CAAC,CAmGlC;AAqOD,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAE9D"}
@@ -10,6 +10,10 @@ export interface DreamRunMemoryChanges {
10
10
  deleted: number;
11
11
  archived: number;
12
12
  merged: number;
13
+ writtenIds?: number[];
14
+ deletedIds?: number[];
15
+ archivedIds?: number[];
16
+ mergedIds?: number[];
13
17
  }
14
18
  export interface DreamRunRow {
15
19
  id: number;
@@ -35,6 +39,10 @@ export interface DreamRunInput {
35
39
  smartNotesSurfaced: number;
36
40
  smartNotesPending: number;
37
41
  memoryChanges?: DreamRunMemoryChanges | null;
42
+ /** Dreamer child session that produced this run — lets the dashboard scope
43
+ * the token join to this run (avoids cross-summing concurrent same-name
44
+ * cross-project runs). null when no parent session was resolved. */
45
+ parentSessionId?: string | null;
38
46
  }
39
47
  export declare function insertDreamRun(db: Database, run: DreamRunInput): void;
40
48
  export declare function getDreamRuns(db: Database, projectPath: string, limit?: number): DreamRunRow[];
@@ -1 +1 @@
1
- {"version":3,"file":"storage-dream-runs.d.ts","sourceRoot":"","sources":["../../../../src/features/magic-context/dreamer/storage-dream-runs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAkC,MAAM,wBAAwB,CAAC;AAEvF,MAAM,WAAW,mBAAmB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,qBAAqB;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,WAAW;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,MAAM,CAAC;IACxB,YAAY,EAAE,MAAM,CAAC;IACrB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,mBAAmB,EAAE,MAAM,CAAC;IAC5B,mBAAmB,EAAE,MAAM,GAAG,IAAI,CAAC;CACtC;AAED,MAAM,WAAW,aAAa;IAC1B,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,mBAAmB,EAAE,CAAC;IAC7B,cAAc,EAAE,MAAM,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;IACpB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,aAAa,CAAC,EAAE,qBAAqB,GAAG,IAAI,CAAC;CAChD;AAwDD,wBAAgB,cAAc,CAAC,EAAE,EAAE,QAAQ,EAAE,GAAG,EAAE,aAAa,GAAG,IAAI,CAarE;AAED,wBAAgB,YAAY,CAAC,EAAE,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,EAAE,KAAK,SAAK,GAAG,WAAW,EAAE,CAMzF"}
1
+ {"version":3,"file":"storage-dream-runs.d.ts","sourceRoot":"","sources":["../../../../src/features/magic-context/dreamer/storage-dream-runs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAkC,MAAM,wBAAwB,CAAC;AAEvF,MAAM,WAAW,mBAAmB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,qBAAqB;IAClC,OAAO,EAAE,MAAM,C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EAAE,MAAM,EAAE,KAAK,SAAK,GAAG,WAAW,EAAE,CAMzF"}
@@ -0,0 +1,82 @@
1
+ import type { Database } from "../../../shared/sqlite";
2
+ /**
3
+ * Per-task dreamer scheduling state (Dreamer v2). One row per (project, task):
4
+ * when it last ran, when it's next due, and its last outcome. Replaces the
5
+ * project-level `dream_queue` + the single `last_dream_at:<project>` key — drains
6
+ * run straight off this table + keyed leases (see lease.ts).
7
+ *
8
+ * Project-scoped, NOT session-scoped → intentionally absent from clearSession().
9
+ */
10
+ export interface TaskScheduleStateRow {
11
+ projectPath: string;
12
+ task: string;
13
+ /** Epoch ms of the last actual run (success or fail). null = never run. */
14
+ lastRunAt: number | null;
15
+ /** Epoch ms of the next scheduled fire. null = never due (disabled / impossible cron). */
16
+ nextDueAt: number | null;
17
+ /** The cron `schedule` string `next_due_at` was last computed FROM. The
18
+ * scheduler reconciles this against the live config each pass: when the
19
+ * config schedule differs, `next_due_at` is recomputed so config is always
20
+ * authoritative (a disabled/enabled/changed task takes effect immediately,
21
+ * not only after the stale slot fires once). null on legacy rows. */
22
+ schedule: string | null;
23
+ lastStatus: "completed" | "failed" | "skipped" | null;
24
+ lastError: string | null;
25
+ retryCount: number;
26
+ /** LEGACY/INERT: the old verify commit watermark. Verify now gates per-memory
27
+ * on each memory's own `verified_at` (map records the file→memory mapping
28
+ * first), so no global commit watermark is written. Column kept (v43) to
29
+ * avoid a DROP-COLUMN migration; field kept for a faithful round-trip. Do
30
+ * NOT read it for new logic. */
31
+ lastCheckedCommit?: string | null;
32
+ /** LEGACY/INERT: the old internal broad-pass cadence watermark. Broad is now
33
+ * its own scheduled task (`verify-broad`); nothing writes a meaningful value.
34
+ * Column kept (v43) to avoid a DROP-COLUMN migration; field kept so the
35
+ * COALESCE round-trip is faithful. Do NOT read it for new logic. */
36
+ lastBroadRunAt?: number | null;
37
+ /** retrospective CONTENT watermark: max message ts actually scanned. Distinct
38
+ * from lastRunAt (schedule-completion time) — lastRunAt as a content cutoff
39
+ * loses messages that arrive mid-run. Undefined on writes preserves the DB
40
+ * value. */
41
+ retrospectiveWatermarkMs?: number | null;
42
+ }
43
+ export declare function getTaskScheduleState(db: Database, projectPath: string, task: string): TaskScheduleStateRow | null;
44
+ export declare function getTaskScheduleStatesForProject(db: Database, projectPath: string): TaskScheduleStateRow[];
45
+ /**
46
+ * Delete task_schedule_state rows for a project whose `task` is NOT in the given
47
+ * keep-set. Used to garbage-collect RETIRED task names (e.g. the v1
48
+ * improve/consolidate/archive-stale rows superseded by the verify/curate split):
49
+ * reconcile adds/updates canonical tasks but never removed obsolete rows, so they
50
+ * lingered forever as perpetually-"due" garbage that polluted the dashboard.
51
+ * Returns the number of rows deleted.
52
+ */
53
+ export declare function pruneNonCanonicalTaskRows(db: Database, projectPath: string, canonicalTasks: readonly string[]): number;
54
+ /**
55
+ * Delete ALL task_schedule_state rows for a project. Used to GC a fully-orphaned
56
+ * project — a `dir:<md5>` identity whose backing directory is gone (e.g. a
57
+ * finalized mason worktree). NEVER call this for a `git:` identity: that is
58
+ * shared across worktrees/clones of the same repo, so a single dead worktree
59
+ * must not delete the shared project's schedule. Returns rows deleted.
60
+ */
61
+ export declare function deleteTaskScheduleRowsForProject(db: Database, projectPath: string): number;
62
+ /**
63
+ * Idempotent first-seed: insert the row only if absent. Concurrent processes can
64
+ * both call this safely — ON CONFLICT DO NOTHING means the first writer wins and
65
+ * the second is a no-op (both compute the same next_due_at from the same cron).
66
+ */
67
+ export declare function seedTaskScheduleState(db: Database, projectPath: string, task: string, nextDueAt: number | null, lastRunAt: number | null, schedule: string): void;
68
+ /** Full upsert of a row's schedule fields (used on run completion / gate-skip /
69
+ * retry advancement / schedule reconciliation). Callers that read-then-write
70
+ * should wrap in BEGIN IMMEDIATE; run-completion writes are already
71
+ * single-writer under the domain lease. */
72
+ export declare function writeTaskScheduleState(db: Database, row: TaskScheduleStateRow): void;
73
+ /**
74
+ * Source-window idempotence for the retrospective task. A friction window
75
+ * re-seen across the run-overlap (the ~12 user lines re-read before the
76
+ * watermark) must not re-extract the same learning. `windowKey` is a stable hash
77
+ * over the flagged user lines' (sessionId:ts) anchors — NOT prompt ordinals,
78
+ * which are batch-local and unstable.
79
+ */
80
+ export declare function isRetrospectiveWindowProcessed(db: Database, projectPath: string, windowKey: string): boolean;
81
+ export declare function recordRetrospectiveWindowProcessed(db: Database, projectPath: string, windowKey: string): void;
82
+ //# sourceMappingURL=storage-task-schedule.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage-task-schedule.d.ts","sourceRoot":"","sources":["../../../../src/features/magic-context/dreamer/storage-task-schedule.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAEvD;;;;;;;GAOG;AAEH,MAAM,WAAW,oBAAoB;IACjC,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,2EAA2E;IAC3E,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,0FAA0F;IAC1F,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB;;;;0EAIsE;IACtE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,UAAU,EAAE,WAAW,GAAG,QAAQ,GAAG,SAAS,GAAG,IAAI,CAAC;IACtD,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB;;;;qCAIiC;IACjC,iBAAiB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC;;;yEAGqE;IACrE,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B;;;iBAGa;IACb,wBAAwB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5C;AAmCD,wBAAgB,oBAAoB,CAChC,EAAE,EAAE,QAAQ,EACZ,WAAW,EAAE,MAAM,EACnB,IAAI,EAAE,MAAM,GACb,oBAAoB,GAAG,IAAI,CAO7B;AAED,wBAAgB,+BAA+B,CAC3C,EAAE,EAAE,QAAQ,EACZ,WAAW,EAAE,MAAM,GACpB,oBAAoB,EAAE,CAOxB;AAED;;;;;;;GAOG;AACH,wBAAgB,yBAAyB,CACrC,EAAE,EAAE,QAAQ,EACZ,WAAW,EAAE,MAAM,EACnB,cAAc,EAAE,SAAS,MAAM,EAAE,GAClC,MAAM,CASR;AAED;;;;;;GAMG;AACH,wBAAgB,gCAAgC,CAAC,EAAE,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,CAK1F;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CACjC,EAAE,EAAE,QAAQ,EACZ,WAAW,EAAE,MAAM,EACnB,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,MAAM,GAAG,IAAI,EACxB,SAAS,EAAE,MAAM,GAAG,IAAI,EACxB,QAAQ,EAAE,MAAM,GACjB,IAAI,CAIN;AAED;;;4CAG4C;AAC5C,wBAAgB,sBAAsB,CAAC,EAAE,EAAE,QAAQ,EAAE,GAAG,EAAE,oBAAoB,GAAG,IAAI,CA4BpF;AAED;;;;;;GAMG;AACH,wBAAgB,8BAA8B,CAC1C,EAAE,EAAE,QAAQ,EACZ,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,GAClB,OAAO,CAOT;AAED,wBAAgB,kCAAkC,CAC9C,EAAE,EAAE,QAAQ,EACZ,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,GAClB,IAAI,CAIN"}
@@ -0,0 +1,28 @@
1
+ import type { DreamerConfig } from "../../../config/schema/magic-context";
2
+ import { type DreamTaskName } from "./task-registry";
3
+ import type { DreamTaskRuntimeConfig } from "./task-scheduler";
4
+ /**
5
+ * Resolve the full per-task runtime config the scheduler consumes from the
6
+ * validated dreamer config: each task's schedule + its effective model chain
7
+ * (task override → dreamer-level default), thinking level, timeout, and
8
+ * task-specific params. One place owns the inheritance rule.
9
+ */
10
+ export declare function buildDreamTaskRuntimeConfigs(dreamer: DreamerConfig): DreamTaskRuntimeConfig[];
11
+ /**
12
+ * The collection privacy gate (Option C): user-behavior observation candidates
13
+ * are stored during historian runs ONLY when the user has scheduled the
14
+ * review-user-memories task (schedule != ""). Replaces the v1
15
+ * `user_memories.enabled` flag, which both gated collection AND review.
16
+ */
17
+ export declare function userMemoryCollectionEnabled(dreamer: DreamerConfig | undefined): boolean;
18
+ /** The promotion threshold for user-memory review (collection + review share it). */
19
+ export declare function userMemoryPromotionThreshold(dreamer: DreamerConfig | undefined): number;
20
+ /** True when a task is scheduled (schedule != ""). Generic enable check. */
21
+ export declare function dreamTaskScheduled(dreamer: DreamerConfig | undefined, task: keyof NonNullable<DreamerConfig["tasks"]>): boolean;
22
+ /** Names of the tasks the user has scheduled (schedule != ""), in canonical order. */
23
+ export declare function enabledDreamTasks(dreamer: DreamerConfig | undefined): DreamTaskName[];
24
+ /** A compact `/ctx-status`-style schedule summary, e.g.
25
+ * "verify 0 3 * * *, curate 0 4 * * 0" — or "manual-only" when nothing is
26
+ * scheduled. */
27
+ export declare function summarizeDreamSchedule(dreamer: DreamerConfig | undefined): string;
28
+ //# sourceMappingURL=task-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"task-config.d.ts","sourceRoot":"","sources":["../../../../src/features/magic-context/dreamer/task-config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAmB,MAAM,sCAAsC,CAAC;AAE3F,OAAO,EAAyB,KAAK,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC5E,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAE/D;;;;;GAKG;AACH,wBAAgB,4BAA4B,CAAC,OAAO,EAAE,aAAa,GAAG,sBAAsB,EAAE,CAyB7F;AAED;;;;;GAKG;AACH,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,aAAa,GAAG,SAAS,GAAG,OAAO,CAGvF;AAED,qFAAqF;AACrF,wBAAgB,4BAA4B,CAAC,OAAO,EAAE,aAAa,GAAG,SAAS,GAAG,MAAM,CAEvF;AAED,4EAA4E;AAC5E,wBAAgB,kBAAkB,CAC9B,OAAO,EAAE,aAAa,GAAG,SAAS,EAClC,IAAI,EAAE,MAAM,WAAW,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,GAChD,OAAO,CAGT;AAED,sFAAsF;AACtF,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,aAAa,GAAG,SAAS,GAAG,aAAa,EAAE,CAGrF;AAED;;iBAEiB;AACjB,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,aAAa,GAAG,SAAS,GAAG,MAAM,CAIjF"}
@@ -0,0 +1,49 @@
1
+ import type { RawMessageProvider } from "../../../hooks/magic-context/read-session-chunk";
2
+ import type { PluginContext } from "../../../plugin/types";
3
+ import type { Database } from "../../../shared/sqlite";
4
+ import { type RetrospectiveRawProvider } from "./retrospective-raw-provider";
5
+ import { isAgenticTask } from "./task-registry";
6
+ import type { TaskExecutor } from "./task-scheduler";
7
+ export interface DreamTaskExecutorDeps {
8
+ client: PluginContext["client"];
9
+ /** Filesystem directory of the project this drain owns (NOT the identity). */
10
+ sessionDirectory: string;
11
+ /** Opens the OpenCode DB read-only (for the key-files candidate scan). The
12
+ * dream-timer owns the path resolution; null when unavailable. */
13
+ openOpenCodeDb: () => Database | null;
14
+ retrospectiveRawProvider?: RetrospectiveRawProvider | ((db: Database, projectIdentity: string) => RetrospectiveRawProvider | null);
15
+ /** Host-side privacy gate for route="observation" learnings. */
16
+ userMemoryCollectionEnabled?: boolean;
17
+ /** Ensure the project embedding provider is registered before primer clustering embeds candidates. */
18
+ ensureProjectRegistered?: (directory: string, db: Database) => Promise<void> | void;
19
+ /**
20
+ * Pi only: builds a RawMessageProvider for an arbitrary historical session id
21
+ * so refresh-primers can render the orientation seed from Pi JSONL. OpenCode
22
+ * leaves this undefined (the seed read falls to the read-only opencode.db
23
+ * path). Returning null for a session → refresh falls back to closed-book.
24
+ */
25
+ primerRawProviderFactory?: (sessionId: string) => Promise<RawMessageProvider | null> | RawMessageProvider | null;
26
+ }
27
+ /**
28
+ * Build the TaskExecutor the v2 scheduler drives. The scheduler owns the keyed
29
+ * domain lease + holderId and hands them in; this executor runs one task's actual
30
+ * work (LLM loop / specialized runner), renews the lease during the run, aborts
31
+ * if the lease is lost, and writes one per-task dream_runs telemetry row.
32
+ */
33
+ export declare function createDreamTaskExecutor(deps: DreamTaskExecutorDeps): TaskExecutor;
34
+ /** Parse the gate's verdict. Expected shape: a single line `n` (no friction) or
35
+ * `y: 3, 7` (flagged ordinals). Robust to a model that wraps it in prose:
36
+ * - scan LINE BY LINE for the first verdict-leading line (`y`/`yes`/`n`/`no`);
37
+ * - ordinals are taken ONLY from that verdict line (so a stray year/number in
38
+ * surrounding prose can't fabricate a deepen);
39
+ * - if no verdict-leading line exists, look for an embedded `y: <nums>` pattern;
40
+ * - anything unparseable → NO hit (fail safe — the caller still advances the
41
+ * watermark on a clean run, so a garbled verdict can't wedge progress).
42
+ * A `y` with zero ordinals is NOT a hit (there are no lines to deepen on). */
43
+ export declare function parseFrictionGateVerdict(verdict: string): {
44
+ hit: boolean;
45
+ ordinals: number[];
46
+ };
47
+ /** Re-export for the dream-timer's executor wiring. */
48
+ export { isAgenticTask };
49
+ //# sourceMappingURL=task-executor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"task-executor.d.ts","sourceRoot":"","sources":["../../../../src/features/magic-context/dreamer/task-executor.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iDAAiD,CAAC;AAC1F,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAM3D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAyBvD,OAAO,EAEH,KAAK,wBAAwB,EAEhC,MAAM,8BAA8B,CAAC;AAkBtC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,KAAK,EAA2C,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAG9F,MAAM,WAAW,qBAAqB;IAClC,MAAM,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAC;IAChC,8EAA8E;IAC9E,gBAAgB,EAAE,MAAM,CAAC;IACzB;uEACmE;IACnE,cAAc,EAAE,MAAM,QAAQ,GAAG,IAAI,CAAC;IACtC,wBAAwB,CAAC,EACnB,wBAAwB,GACxB,CAAC,CAAC,EAAE,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,KAAK,wBAAwB,GAAG,IAAI,CAAC,CAAC;IACnF,gEAAgE;IAChE,2BAA2B,CAAC,EAAE,OAAO,CAAC;IACtC,sGAAsG;IACtG,uBAAuB,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,EAAE,EAAE,QAAQ,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IACpF;;;;;OAKG;IACH,wBAAwB,CAAC,EAAE,CACvB,SAAS,EAAE,MAAM,KAChB,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC,GAAG,kBAAkB,GAAG,IAAI,CAAC;CACvE;AAoDD;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,qBAAqB,GAAG,YAAY,CAyRjF;AA4BD;;;;;;;;+EAQ+E;AAC/E,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,MAAM,GAAG;IAAE,GAAG,EAAE,OAAO,CAAC;IAAC,QAAQ,EAAE,MAAM,EAAE,CAAA;CAAE,CA+B9F;AAgdD,uDAAuD;AACvD,OAAO,EAAE,aAAa,EAAE,CAAC"}
@@ -0,0 +1,29 @@
1
+ import type { Database } from "../../../shared/sqlite";
2
+ import type { DreamTaskName } from "./task-registry";
3
+ /**
4
+ * Per-task activity gates (Dreamer v2 A+B). A due task runs ONLY if its gate
5
+ * passes, so cron cadence never burns a 60-turn agentic loop on an unchanged
6
+ * pool. Gates are conservative — allow when uncertain — and cheap (count
7
+ * queries, no full-row loads, no LLM).
8
+ *
9
+ * `lastRunAt` is the task's own `task_schedule_state.last_run_at` (null = never
10
+ * run → treat "changed since" gates as "is there anything at all").
11
+ */
12
+ export interface TaskGateContext {
13
+ db: Database;
14
+ projectIdentity: string;
15
+ lastRunAt: number | null;
16
+ /** retrospective content watermark (max message ts scanned). Distinct from
17
+ * lastRunAt: a session updated mid-run is newer than its scanned content but
18
+ * older than the run-completion time, so gating on lastRunAt would skip it. */
19
+ retrospectiveWatermarkMs?: number | null;
20
+ /** review-user-memories: min candidate observations before a review is worthwhile. */
21
+ promotionThreshold: number;
22
+ }
23
+ /**
24
+ * Evaluate a task's activity gate. Returns true if the task has work to do.
25
+ * Throwing DB errors propagate to the caller (a gate that can't read is a real
26
+ * problem, not silently "no work").
27
+ */
28
+ export declare function evaluateTaskGate(task: DreamTaskName, ctx: TaskGateContext): boolean;
29
+ //# sourceMappingURL=task-gates.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"task-gates.d.ts","sourceRoot":"","sources":["../../../../src/features/magic-context/dreamer/task-gates.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAQvD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAErD;;;;;;;;GAQG;AAEH,MAAM,WAAW,eAAe;IAC5B,EAAE,EAAE,QAAQ,CAAC;IACb,eAAe,EAAE,MAAM,CAAC;IACxB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB;;oFAEgF;IAChF,wBAAwB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzC,sFAAsF;IACtF,kBAAkB,EAAE,MAAM,CAAC;CAC9B;AA4DD;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,aAAa,EAAE,GAAG,EAAE,eAAe,GAAG,OAAO,CAoEnF"}
@@ -1,12 +1,40 @@
1
1
  import type { DreamingTask } from "../../../config/schema/magic-context";
2
- export declare const DREAMER_SYSTEM_PROMPT = "You are a memory maintenance agent for the magic-context system.\nYou run during scheduled dream windows to maintain a project's cross-session memory store and codebase documentation.\n\n## Available Tools\n\n**Memory operations** (ctx_memory with extended dreamer actions):\n- `action=\"list\"` \u2014 browse all active memories, optionally filter by category\n- `action=\"update\", ids=[N], content=\"...\"` \u2014 rewrite a memory's content\n- `action=\"merge\", ids=[N,M,...], content=\"...\", category=\"...\"` \u2014 consolidate duplicates into one canonical memory\n- `action=\"archive\", ids=[N], reason=\"...\"` \u2014 remove a stale memory (soft-archive, with provenance)\n- `action=\"write\", category=\"...\", content=\"...\"` \u2014 create a new memory\n\n**Codebase tools** (standard OpenCode tools):\n- Read files, grep, glob, bash \u2014 for verification against actual code\n\n## Rules\n\n1. **Work methodically.** Decide your own batch size based on the task \u2014 process as many items per round as makes sense.\n2. **Always verify against actual files** before declaring a memory stale or updating it.\n3. **Be conservative with archives.** Only archive when the codebase clearly contradicts the memory.\n4. **Explain reasoning briefly** before each action \u2014 one line is enough.\n5. **Use present-tense operational language** in all memory rewrites. \"X uses Y\" not \"X was changed to use Y.\"\n6. **One rule/fact per memory.** Split compound memories during improvement.\n7. **Never read or quote secrets** from .env, credentials, keys, or similar sensitive files.\n8. **Do not commit changes.** The user handles git operations.\n\n## Memory Taxonomy (5 categories)\n\nProject memory uses exactly 5 categories. Every memory belongs to one:\n- **PROJECT_RULES** \u2014 durable process/workflow rules for this repo (releases, commits, testing, debugging conventions).\n- **ARCHITECTURE** \u2014 load-bearing design decisions and WHY they hold (not WHAT a file does).\n- **CONSTRAINTS** \u2014 hard limits imposed by EXTERNAL systems (APIs, providers, platforms, protocols). Not our own code's behavior.\n- **CONFIG_VALUES** \u2014 stable configuration keys/values and conventions. Not transient measurements (test counts, sizes, versions).\n- **NAMING** \u2014 naming conventions and canonical names. Not inventories.\n\n**Legacy categories during transition:** older memories may still carry pre-v2 category names. When you touch one, map it to its 5-category home with `action=\"update\"` (or `merge`): WORKFLOW_RULES\u2192PROJECT_RULES, ARCHITECTURE_DECISIONS\u2192ARCHITECTURE, CONFIG_DEFAULTS\u2192CONFIG_VALUES, ENVIRONMENT\u2192CONFIG_VALUES (paths) or CONSTRAINTS, KNOWN_ISSUES\u2192CONSTRAINTS only if it's an external-system limit (otherwise archive \u2014 our own fixed bugs are not world facts). USER_DIRECTIVES / USER_PREFERENCES are NOT project categories \u2014 they live in the global user profile; archive project copies only when they add zero project-specific detail.";
3
- export declare function buildConsolidatePrompt(projectPath: string): string;
4
- export declare function buildVerifyPrompt(projectPath: string): string;
5
- export declare function buildArchiveStalePrompt(projectPath: string, userMemories?: Array<{
2
+ /** Memory shape the curate prompt renders (verify now has its own runner/prompt). */
3
+ export interface CuratePromptMemory {
6
4
  id: number;
5
+ category: string;
7
6
  content: string;
8
- }>): string;
9
- export declare function buildImprovePrompt(projectPath: string): string;
7
+ mappedFiles: string[];
8
+ hasNoFileSentinel: boolean;
9
+ }
10
+ export declare const DREAMER_SYSTEM_PROMPT = "You are a background maintenance agent for the magic-context system, running during a scheduled dream window. Your task and its full instructions arrive in the message below. Never read or quote secrets from .env, credentials, or key files, and never commit \u2014 the user handles git.";
11
+ export declare const CURATE_SYSTEM_PROMPT = "You are a memory-pool curator for the magic-context system. You run during a scheduled dream window to keep a project's cross-session memory store lean and well-formed.\n\n## Memory operations (ctx_memory)\n- `action=\"list\"` \u2014 browse active memories, optionally filter by category\n- `action=\"merge\", ids=[N,M,...], content=\"...\", category=\"...\"` \u2014 consolidate duplicates into one canonical memory\n- `action=\"update\", ids=[N], content=\"...\"` \u2014 rewrite a memory's content\n- `action=\"write\", category=\"...\", content=\"...\"` \u2014 create a memory (SPLITS ONLY \u2014 never mint new facts)\n- `action=\"archive\", ids=[N], reason=\"...\"` \u2014 soft-archive a stale or low-value memory\n\n## Rules\n1. **Assume the pool is accurate.** A separate verify task checks memories against code. You handle QUALITY only \u2014 duplicates, wording, low-value entries \u2014 never correctness, and you do NOT read the codebase.\n2. **Work methodically.** Choose your own batch size.\n3. **Be conservative with archives.** Use the task's archive criteria.\n4. **Present-tense operational language.** \"X uses Y\" not \"X was changed to use Y.\"\n5. **One rule/fact per memory.**\n6. **Never mint new facts** \u2014 that is the historian's job. `write` is for splitting a compound memory only.\n\n## Memory taxonomy (5 categories)\n\nProject memory uses exactly 5 categories. Every memory belongs to one:\n- **PROJECT_RULES** \u2014 durable process/workflow rules for this repo (releases, commits, testing, debugging conventions).\n- **ARCHITECTURE** \u2014 load-bearing design decisions and WHY they hold (not WHAT a file does).\n- **CONSTRAINTS** \u2014 hard limits imposed by EXTERNAL systems (APIs, providers, platforms, protocols). Not our own code's behavior.\n- **CONFIG_VALUES** \u2014 stable configuration keys/values and conventions. Not transient measurements (test counts, sizes, versions).\n- **NAMING** \u2014 naming conventions and canonical names. Not inventories.\n\n**Legacy categories during transition:** older memories may still carry pre-v2 category names. When you touch one, map it to its 5-category home with `action=\"update\"` (or `merge`): WORKFLOW_RULES\u2192PROJECT_RULES, ARCHITECTURE_DECISIONS\u2192ARCHITECTURE, CONFIG_DEFAULTS\u2192CONFIG_VALUES, ENVIRONMENT\u2192CONFIG_VALUES (paths) or CONSTRAINTS, KNOWN_ISSUES\u2192CONSTRAINTS only if it's an external-system limit (otherwise archive \u2014 our own fixed bugs are not world facts). USER_DIRECTIVES / USER_PREFERENCES are NOT project categories \u2014 they live in the global user profile; archive project copies only when they add zero project-specific detail.";
12
+ export declare const MAINTAIN_DOCS_SYSTEM_PROMPT = "You are a documentation maintainer for the magic-context system. You run during a scheduled dream window to keep a project's root `ARCHITECTURE.md` and `STRUCTURE.md` synchronized with the actual code.\n\n## Tools\n- Read files, grep, glob, bash \u2014 explore the codebase to verify current state.\n- Write / edit \u2014 update the two docs (project root only, never `.planning/`).\n\n## Rules\n- **NEVER touch protected regions.** Any content between `<!-- mc:protected START ... -->` and `<!-- mc:protected END -->` is hand-authored and cache-critical. Reproduce it BYTE-FOR-BYTE \u2014 do not edit, reword, reorder, summarize, trim, or drop a single line, and keep the marker comments. Only a human edits that region.\n- **Be prescriptive** (\"Use X pattern\", not \"X pattern is used\"). **Current state only** \u2014 no temporal language, no history.\n- **Verify before writing** \u2014 read the actual files, never guess. All file paths in the docs must point to files that exist.";
13
+ export declare const REVIEW_USER_MEMORIES_SYSTEM_PROMPT = "You are a user-profile reviewer for the magic-context system. You run during a scheduled dream window to decide which recurring behavioral observations about the human user are real, persistent patterns worth keeping in their global user profile.\n\nYou do NOT call any tools and you do NOT touch project memories \u2014 you read the candidate observations the host gives you and return a JSON verdict. Distill durable patterns; never transcribe a single moment. Output only the JSON the task asks for, with no surrounding prose.";
14
+ export declare const PRIMER_INVESTIGATOR_SYSTEM_PROMPT = "You are a read-only code investigator for the magic-context system. You run during a scheduled dream window to answer a single standing question about THIS codebase by reading its current source.\n\n## Tools (read-only)\n`read`, `grep`, `glob`, `aft_outline`, `aft_zoom`, `aft_search`. You have no write, edit, bash, or memory tools \u2014 you investigate and report, you change nothing.\n\n## Rules\n- **Ground every claim in code you actually opened this run.** Open the files the question points at and verify against them. A paraphrase that reads no files is not an answer.\n- **Answer directly and concretely** \u2014 name paths, symbols, and mechanisms, in present tense.";
15
+ export declare function buildCuratePrompt(args: {
16
+ projectPath: string;
17
+ memories: CuratePromptMemory[];
18
+ userProfile?: string;
19
+ }): string;
20
+ export interface RetrospectivePromptEvent {
21
+ sessionId: string;
22
+ kind: string;
23
+ fields: Record<string, string>;
24
+ createdAt: number;
25
+ }
26
+ export declare const RETROSPECTIVE_SYSTEM_PROMPT = "You are a retrospective learning agent for Magic Context.\n\nYou learn only from recurring user-friction moments where the user had to correct, re-explain, or recover from the assistant's repeated behavior. You receive a pre-rendered friction window from the host and may use ctx_search to look for corroborating prior patterns.\n\nRules:\n1. Pattern, not one-off: extract only recurring behavior that is likely to happen again. Zero learnings is fine.\n2. Distill, do not transcribe: never quote the user, never include dates, and never preserve session-local anger.\n3. Root cause + correction: the learning must tell a future agent what to do differently.\n4. Privacy by host-apply: do not call memory-writing tools. Emit only the XML schema requested by the prompt.";
27
+ /** Tiny system prompt for the cheap LLM gate (turn 1): it reads only U: lines
28
+ * and answers "n" or "y: <ordinals>". Kept minimal so the gate is cheap. */
29
+ export declare const FRICTION_GATE_SYSTEM_PROMPT = "You are a conservative friction detector for a coding agent. You read recent user message lines and decide whether the user was correcting, re-explaining to, or frustrated with the assistant. Output exactly one line and nothing else.";
30
+ export declare function buildFrictionGatePrompt(args: {
31
+ userLines: string[];
32
+ }): string;
33
+ export declare function buildRetrospectivePrompt(args: {
34
+ projectPath: string;
35
+ frictionWindow: string;
36
+ events: RetrospectivePromptEvent[];
37
+ }): string;
10
38
  export declare function buildMaintainDocsPrompt(projectPath: string, lastDreamAt: string | null, existingDocs: {
11
39
  architecture: boolean;
12
40
  structure: boolean;
@@ -22,5 +50,8 @@ export declare function buildDreamTaskPrompt(task: DreamingTask, args: {
22
50
  id: number;
23
51
  content: string;
24
52
  }>;
53
+ curate?: {
54
+ memories: CuratePromptMemory[];
55
+ };
25
56
  }): string;
26
57
  //# sourceMappingURL=task-prompts.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"task-prompts.d.ts","sourceRoot":"","sources":["../../../../src/features/magic-context/dreamer/task-prompts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sCAAsC,CAAC;AAIzE,eAAO,MAAM,qBAAqB,y8FAmCulB,CAAC;AAI1nB,wBAAgB,sBAAsB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CA+BlE;AAID,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAiC7D;AAID,wBAAgB,uBAAuB,CACnC,WAAW,EAAE,MAAM,EACnB,YAAY,CAAC,EAAE,KAAK,CAAC;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC,GACtD,MAAM,CA0ER;AAID,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CA0C9D;AAID,wBAAgB,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AAC;CACL,GACF,MAAM,CAeR"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Canonical Dreamer v2 task registry (pure — no DB imports, so the config schema
3
+ * can import the task names without pulling runtime code).
4
+ *
5
+ * v2 promotes the former post-phases (review-user-memories, key-files,
6
+ * evaluate-smart-notes) to first-class scheduled tasks alongside the agentic
7
+ * maintenance tasks, and assigns each a LEASE DOMAIN so disjoint-state tasks run
8
+ * concurrently while memory-mutating tasks serialize. See lease.ts + the A+B spec.
9
+ */
10
+ export declare const CANONICAL_DREAM_TASKS: readonly ["map-memories", "verify", "verify-broad", "curate", "classify-memories", "retrospective", "maintain-docs", "evaluate-smart-notes", "review-user-memories", "promote-primers", "refresh-primers"];
11
+ export type DreamTaskName = (typeof CANONICAL_DREAM_TASKS)[number];
12
+ /**
13
+ * The agentic tasks — those run as a generic dreamer agent session driven by
14
+ * `buildDreamTaskPrompt`. The other canonical tasks (map-memories, verify,
15
+ * verify-broad, classify-memories, review-user-memories, evaluate-smart-notes,
16
+ * primers, retrospective) have their own specialized runners and do NOT go
17
+ * through the prompt builder.
18
+ */
19
+ export declare const AGENTIC_DREAM_TASKS: readonly ["curate", "maintain-docs"];
20
+ export type AgenticDreamTask = (typeof AGENTIC_DREAM_TASKS)[number];
21
+ export declare function isAgenticTask(task: DreamTaskName): task is AgenticDreamTask;
22
+ /**
23
+ * Tasks that read-modify-write the project `memories` table (+ epoch +
24
+ * supersede-delta rows). They SHARE one per-project "memory" lease so they
25
+ * serialize with each other — concurrent runs race semantically (stale-view
26
+ * merges/splits). Canonical run order when several are due in one drain.
27
+ */
28
+ export declare const MEMORY_DOMAIN_TASKS: readonly DreamTaskName[];
29
+ /**
30
+ * Lease KIND per task. `memory` + the three independent kinds are per-project;
31
+ * `user-memories` is GLOBAL (mutates the cross-project user-profile pool, so two
32
+ * different projects' dreamers must not review concurrently).
33
+ */
34
+ export type LeaseKind = "memory" | "maintain-docs" | "evaluate-smart-notes" | "user-memories";
35
+ export declare function leaseKindFor(task: DreamTaskName): LeaseKind;
36
+ /**
37
+ * Resolve the concrete lease key for a task in a project. The global
38
+ * `user-memories` lease is NOT project-scoped (one reviewer across all projects);
39
+ * every other domain is keyed by project so different projects never block.
40
+ */
41
+ export declare function leaseKeyFor(task: DreamTaskName, projectIdentity: string): string;
42
+ export declare function isCanonicalDreamTask(value: string): value is DreamTaskName;
43
+ /**
44
+ * Stable canonical ordering used when multiple due tasks share a lease domain
45
+ * (preserves the suite order for the memory domain).
46
+ */
47
+ export declare function compareTaskOrder(a: DreamTaskName, b: DreamTaskName): number;
48
+ //# sourceMappingURL=task-registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"task-registry.d.ts","sourceRoot":"","sources":["../../../../src/features/magic-context/dreamer/task-registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,eAAO,MAAM,qBAAqB,4MAcxB,CAAC;AAEX,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,qBAAqB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEnE;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,sCAAuC,CAAC;AAExE,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,mBAAmB,CAAC,CAAC,MAAM,CAAC,CAAC;AAIpE,wBAAgB,aAAa,CAAC,IAAI,EAAE,aAAa,GAAG,IAAI,IAAI,gBAAgB,CAE3E;AAED;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,EAAE,SAAS,aAAa,EASvD,CAAC;AAIF;;;;GAIG;AACH,MAAM,MAAM,SAAS,GAAG,QAAQ,GAAG,eAAe,GAAG,sBAAsB,GAAG,eAAe,CAAC;AAE9F,wBAAgB,YAAY,CAAC,IAAI,EAAE,aAAa,GAAG,SAAS,CAgB3D;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,GAAG,MAAM,CAGhF;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,aAAa,CAE1E;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,aAAa,EAAE,CAAC,EAAE,aAAa,GAAG,MAAM,CAE3E"}