sensorium-mcp 3.1.3 → 3.1.5

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 (203) hide show
  1. package/Install-Sensorium.ps1 +251 -39
  2. package/dist/config/agent-settings.d.ts +11 -0
  3. package/dist/config/agent-settings.d.ts.map +1 -1
  4. package/dist/config/agent-settings.js +79 -0
  5. package/dist/config/agent-settings.js.map +1 -1
  6. package/dist/config/index.d.ts +1 -0
  7. package/dist/config/index.d.ts.map +1 -1
  8. package/dist/config/index.js +12 -0
  9. package/dist/config/index.js.map +1 -1
  10. package/dist/config/misc-settings.d.ts +7 -0
  11. package/dist/config/misc-settings.d.ts.map +1 -1
  12. package/dist/config/misc-settings.js +38 -1
  13. package/dist/config/misc-settings.js.map +1 -1
  14. package/dist/dashboard/routes/codex.d.ts +14 -0
  15. package/dist/dashboard/routes/codex.d.ts.map +1 -0
  16. package/dist/dashboard/routes/codex.js +92 -0
  17. package/dist/dashboard/routes/codex.js.map +1 -0
  18. package/dist/dashboard/routes/prompts.d.ts +2 -2
  19. package/dist/dashboard/routes/prompts.d.ts.map +1 -1
  20. package/dist/dashboard/routes/prompts.js +2 -2
  21. package/dist/dashboard/routes/prompts.js.map +1 -1
  22. package/dist/dashboard/routes/threads-read.d.ts +10 -7
  23. package/dist/dashboard/routes/threads-read.d.ts.map +1 -1
  24. package/dist/dashboard/routes/threads-read.js +21 -16
  25. package/dist/dashboard/routes/threads-read.js.map +1 -1
  26. package/dist/dashboard/routes.d.ts.map +1 -1
  27. package/dist/dashboard/routes.js +3 -0
  28. package/dist/dashboard/routes.js.map +1 -1
  29. package/dist/dashboard/spa.html +11 -11
  30. package/dist/data/memory/bootstrap.d.ts +1 -8
  31. package/dist/data/memory/bootstrap.d.ts.map +1 -1
  32. package/dist/data/memory/bootstrap.js +27 -37
  33. package/dist/data/memory/bootstrap.js.map +1 -1
  34. package/dist/data/memory/consolidation.d.ts +20 -1
  35. package/dist/data/memory/consolidation.d.ts.map +1 -1
  36. package/dist/data/memory/consolidation.js +53 -3
  37. package/dist/data/memory/consolidation.js.map +1 -1
  38. package/dist/data/memory/index.d.ts +0 -4
  39. package/dist/data/memory/index.d.ts.map +1 -1
  40. package/dist/data/memory/index.js +0 -4
  41. package/dist/data/memory/index.js.map +1 -1
  42. package/dist/data/memory/key-knowledge.d.ts +51 -0
  43. package/dist/data/memory/key-knowledge.d.ts.map +1 -0
  44. package/dist/data/memory/key-knowledge.js +128 -0
  45. package/dist/data/memory/key-knowledge.js.map +1 -0
  46. package/dist/data/memory/migration-runner.d.ts +1 -1
  47. package/dist/data/memory/migration-runner.d.ts.map +1 -1
  48. package/dist/data/memory/migration-runner.js +23 -1
  49. package/dist/data/memory/migration-runner.js.map +1 -1
  50. package/dist/data/memory/narrative-lint.d.ts +2 -2
  51. package/dist/data/memory/narrative-lint.d.ts.map +1 -1
  52. package/dist/data/memory/narrative-lint.js +23 -13
  53. package/dist/data/memory/narrative-lint.js.map +1 -1
  54. package/dist/data/memory/narrative-resolutions.d.ts +7 -2
  55. package/dist/data/memory/narrative-resolutions.d.ts.map +1 -1
  56. package/dist/data/memory/narrative-resolutions.js +7 -8
  57. package/dist/data/memory/narrative-resolutions.js.map +1 -1
  58. package/dist/data/memory/narrative-sources.d.ts +1 -1
  59. package/dist/data/memory/narrative-sources.d.ts.map +1 -1
  60. package/dist/data/memory/narrative-sources.js +8 -3
  61. package/dist/data/memory/narrative-sources.js.map +1 -1
  62. package/dist/data/memory/narrative-store.d.ts +14 -0
  63. package/dist/data/memory/narrative-store.d.ts.map +1 -1
  64. package/dist/data/memory/narrative-store.js +36 -0
  65. package/dist/data/memory/narrative-store.js.map +1 -1
  66. package/dist/data/memory/narrative.d.ts.map +1 -1
  67. package/dist/data/memory/narrative.js +47 -29
  68. package/dist/data/memory/narrative.js.map +1 -1
  69. package/dist/data/memory/note-archival.d.ts +1 -1
  70. package/dist/data/memory/note-archival.d.ts.map +1 -1
  71. package/dist/data/memory/note-archival.js +7 -3
  72. package/dist/data/memory/note-archival.js.map +1 -1
  73. package/dist/data/memory/note-embeddings.d.ts +7 -0
  74. package/dist/data/memory/note-embeddings.d.ts.map +1 -1
  75. package/dist/data/memory/note-embeddings.js +6 -2
  76. package/dist/data/memory/note-embeddings.js.map +1 -1
  77. package/dist/data/memory/schema-ddl.d.ts +1 -1
  78. package/dist/data/memory/schema-ddl.d.ts.map +1 -1
  79. package/dist/data/memory/schema-ddl.js +3 -1
  80. package/dist/data/memory/schema-ddl.js.map +1 -1
  81. package/dist/data/memory/semantic-notes.d.ts +13 -8
  82. package/dist/data/memory/semantic-notes.d.ts.map +1 -1
  83. package/dist/data/memory/semantic-notes.js +12 -17
  84. package/dist/data/memory/semantic-notes.js.map +1 -1
  85. package/dist/data/memory/thread-registry.d.ts +7 -1
  86. package/dist/data/memory/thread-registry.d.ts.map +1 -1
  87. package/dist/data/memory/thread-registry.js +14 -5
  88. package/dist/data/memory/thread-registry.js.map +1 -1
  89. package/dist/data/memory/utils.d.ts +6 -0
  90. package/dist/data/memory/utils.d.ts.map +1 -1
  91. package/dist/data/memory/utils.js +13 -0
  92. package/dist/data/memory/utils.js.map +1 -1
  93. package/dist/integrations/openai/speech.js +4 -4
  94. package/dist/integrations/openai/speech.js.map +1 -1
  95. package/dist/lib/http-retry.d.ts +91 -0
  96. package/dist/lib/http-retry.d.ts.map +1 -0
  97. package/dist/lib/http-retry.js +177 -0
  98. package/dist/lib/http-retry.js.map +1 -0
  99. package/dist/lib/usage-metering/pricing.js +1 -1
  100. package/dist/lib/usage-metering/pricing.js.map +1 -1
  101. package/dist/llm/prompts/narrative.d.ts.map +1 -1
  102. package/dist/llm/prompts/narrative.js +27 -86
  103. package/dist/llm/prompts/narrative.js.map +1 -1
  104. package/dist/services/claude-spawn.service.d.ts.map +1 -1
  105. package/dist/services/claude-spawn.service.js +6 -1
  106. package/dist/services/claude-spawn.service.js.map +1 -1
  107. package/dist/services/codex-spawn.service.d.ts +2 -2
  108. package/dist/services/codex-spawn.service.d.ts.map +1 -1
  109. package/dist/services/codex-spawn.service.js +64 -58
  110. package/dist/services/codex-spawn.service.js.map +1 -1
  111. package/dist/services/consolidation.service.d.ts.map +1 -1
  112. package/dist/services/consolidation.service.js +10 -43
  113. package/dist/services/consolidation.service.js.map +1 -1
  114. package/dist/services/copilot-spawn.service.d.ts.map +1 -1
  115. package/dist/services/copilot-spawn.service.js +6 -1
  116. package/dist/services/copilot-spawn.service.js.map +1 -1
  117. package/dist/services/daily-session.d.ts +22 -11
  118. package/dist/services/daily-session.d.ts.map +1 -1
  119. package/dist/services/daily-session.js +69 -24
  120. package/dist/services/daily-session.js.map +1 -1
  121. package/dist/services/dispatcher/poller.d.ts.map +1 -1
  122. package/dist/services/dispatcher/poller.js +8 -15
  123. package/dist/services/dispatcher/poller.js.map +1 -1
  124. package/dist/services/http-retry.d.ts +1 -90
  125. package/dist/services/http-retry.d.ts.map +1 -1
  126. package/dist/services/http-retry.js +1 -176
  127. package/dist/services/http-retry.js.map +1 -1
  128. package/dist/services/mcp-config.service.d.ts.map +1 -1
  129. package/dist/services/mcp-config.service.js +14 -1
  130. package/dist/services/mcp-config.service.js.map +1 -1
  131. package/dist/services/memory-briefing.service.d.ts +1 -1
  132. package/dist/services/memory-briefing.service.d.ts.map +1 -1
  133. package/dist/services/memory-briefing.service.js +27 -73
  134. package/dist/services/memory-briefing.service.js.map +1 -1
  135. package/dist/services/memory-pruning.service.d.ts.map +1 -1
  136. package/dist/services/memory-pruning.service.js +22 -4
  137. package/dist/services/memory-pruning.service.js.map +1 -1
  138. package/dist/services/predefined-prompts.d.ts +11 -0
  139. package/dist/services/predefined-prompts.d.ts.map +1 -0
  140. package/dist/services/predefined-prompts.js +25 -0
  141. package/dist/services/predefined-prompts.js.map +1 -0
  142. package/dist/services/spawn-common.d.ts +10 -2
  143. package/dist/services/spawn-common.d.ts.map +1 -1
  144. package/dist/services/spawn-common.js +25 -4
  145. package/dist/services/spawn-common.js.map +1 -1
  146. package/dist/services/telegram.d.ts +7 -5
  147. package/dist/services/telegram.d.ts.map +1 -1
  148. package/dist/services/telegram.js +18 -13
  149. package/dist/services/telegram.js.map +1 -1
  150. package/dist/sessions/mcp-registry.d.ts +7 -2
  151. package/dist/sessions/mcp-registry.d.ts.map +1 -1
  152. package/dist/sessions/mcp-registry.js +52 -30
  153. package/dist/sessions/mcp-registry.js.map +1 -1
  154. package/dist/tools/defs/memory-defs.d.ts.map +1 -1
  155. package/dist/tools/defs/memory-defs.js +4 -0
  156. package/dist/tools/defs/memory-defs.js.map +1 -1
  157. package/dist/tools/delegate-tool.js +2 -2
  158. package/dist/tools/delegate-tool.js.map +1 -1
  159. package/dist/tools/memory-tools.d.ts.map +1 -1
  160. package/dist/tools/memory-tools.js +9 -1
  161. package/dist/tools/memory-tools.js.map +1 -1
  162. package/dist/tools/start-session-tool.d.ts.map +1 -1
  163. package/dist/tools/start-session-tool.js +13 -1
  164. package/dist/tools/start-session-tool.js.map +1 -1
  165. package/dist/tools/wait/consolidation-strategy.d.ts +42 -0
  166. package/dist/tools/wait/consolidation-strategy.d.ts.map +1 -0
  167. package/dist/tools/wait/consolidation-strategy.js +50 -0
  168. package/dist/tools/wait/consolidation-strategy.js.map +1 -0
  169. package/dist/tools/wait/drive-handler.d.ts +5 -7
  170. package/dist/tools/wait/drive-handler.d.ts.map +1 -1
  171. package/dist/tools/wait/drive-handler.js +45 -59
  172. package/dist/tools/wait/drive-handler.js.map +1 -1
  173. package/dist/tools/wait/message-delivery.d.ts.map +1 -1
  174. package/dist/tools/wait/message-delivery.js +4 -21
  175. package/dist/tools/wait/message-delivery.js.map +1 -1
  176. package/dist/tools/wait/message-processing.d.ts.map +1 -1
  177. package/dist/tools/wait/message-processing.js +2 -1
  178. package/dist/tools/wait/message-processing.js.map +1 -1
  179. package/dist/tools/wait/poll-loop.d.ts.map +1 -1
  180. package/dist/tools/wait/poll-loop.js +8 -8
  181. package/dist/tools/wait/poll-loop.js.map +1 -1
  182. package/package.json +1 -1
  183. package/templates/increment-pr-pipeline.default.md +79 -0
  184. package/dist/data/memory/reflection-dedup.d.ts +0 -17
  185. package/dist/data/memory/reflection-dedup.d.ts.map +0 -1
  186. package/dist/data/memory/reflection-dedup.js +0 -55
  187. package/dist/data/memory/reflection-dedup.js.map +0 -1
  188. package/dist/data/memory/reflection-gates.d.ts +0 -40
  189. package/dist/data/memory/reflection-gates.d.ts.map +0 -1
  190. package/dist/data/memory/reflection-gates.js +0 -220
  191. package/dist/data/memory/reflection-gates.js.map +0 -1
  192. package/dist/data/memory/reflection-sources.d.ts +0 -13
  193. package/dist/data/memory/reflection-sources.d.ts.map +0 -1
  194. package/dist/data/memory/reflection-sources.js +0 -115
  195. package/dist/data/memory/reflection-sources.js.map +0 -1
  196. package/dist/data/memory/reflection.d.ts +0 -43
  197. package/dist/data/memory/reflection.d.ts.map +0 -1
  198. package/dist/data/memory/reflection.js +0 -329
  199. package/dist/data/memory/reflection.js.map +0 -1
  200. package/dist/llm/prompts/reflection.d.ts +0 -6
  201. package/dist/llm/prompts/reflection.d.ts.map +0 -1
  202. package/dist/llm/prompts/reflection.js +0 -77
  203. package/dist/llm/prompts/reflection.js.map +0 -1
@@ -1,115 +0,0 @@
1
- /**
2
- * Reflection source data — episode gathering, narrative building, and
3
- * keyword extraction for the reflection pipeline.
4
- */
5
- import { rowToEpisode } from "./episodes.js";
6
- /** Extract text from an episode's content object. */
7
- function episodeText(ep) {
8
- const c = ep.content;
9
- if (typeof c === "string")
10
- return c;
11
- return c.text ?? c.caption ?? JSON.stringify(c);
12
- }
13
- /** Build a time-ordered narrative from a list of episodes. */
14
- export function buildNarrative(episodes) {
15
- return episodes
16
- .sort((a, b) => a.timestamp.localeCompare(b.timestamp))
17
- .map((ep) => `[${ep.episodeId}] (${ep.type}/${ep.modality}, ${ep.timestamp}) ${episodeText(ep)}`)
18
- .join("\n");
19
- }
20
- /** Gather consolidated episodes: last N recent + random sample of older ones. */
21
- export function gatherEpisodes(db, threadId, maxRecent, oldSampleSize) {
22
- // Recent consolidated episodes
23
- const recentRows = db
24
- .prepare(`SELECT * FROM episodes
25
- WHERE thread_id = ? AND consolidated = 1
26
- ORDER BY timestamp DESC
27
- LIMIT ?`)
28
- .all(threadId, maxRecent);
29
- const recentIds = new Set(recentRows.map((r) => r.episode_id));
30
- // Random sample of older consolidated episodes from the past 7 days
31
- // (excluding the ones already in the recent set)
32
- const olderRows = db
33
- .prepare(`SELECT * FROM episodes
34
- WHERE thread_id = ? AND consolidated = 1
35
- AND timestamp >= datetime('now', '-7 days')
36
- ORDER BY RANDOM()
37
- LIMIT ?`)
38
- .all(threadId, oldSampleSize + recentRows.length);
39
- const olderFiltered = olderRows
40
- .filter((r) => !recentIds.has(r.episode_id))
41
- .slice(0, oldSampleSize);
42
- const allRows = [...recentRows, ...olderFiltered];
43
- return allRows.map(rowToEpisode);
44
- }
45
- // ─── Keyword extraction ──────────────────────────────────────────────────────
46
- const STOP_WORDS = new Set([
47
- "this",
48
- "that",
49
- "with",
50
- "from",
51
- "have",
52
- "been",
53
- "will",
54
- "would",
55
- "could",
56
- "should",
57
- "about",
58
- "there",
59
- "their",
60
- "which",
61
- "when",
62
- "what",
63
- "were",
64
- "they",
65
- "than",
66
- "then",
67
- "also",
68
- "just",
69
- "more",
70
- "some",
71
- "into",
72
- "over",
73
- "after",
74
- "before",
75
- "other",
76
- "very",
77
- "your",
78
- "here",
79
- "does",
80
- "because",
81
- "instead",
82
- "agent",
83
- "operator",
84
- "the",
85
- "and",
86
- "for",
87
- "are",
88
- "but",
89
- "not",
90
- "you",
91
- "all",
92
- "can",
93
- "had",
94
- "her",
95
- "was",
96
- "one",
97
- "our",
98
- "out",
99
- ]);
100
- /** Extract up to 5 meaningful keywords from free-text content. */
101
- export function extractKeywords(text) {
102
- const words = text
103
- .toLowerCase()
104
- .replace(/[^a-z0-9\s]/g, " ")
105
- .split(/\s+/)
106
- .filter((w) => w.length > 3 && !STOP_WORDS.has(w));
107
- const freq = new Map();
108
- for (const w of words)
109
- freq.set(w, (freq.get(w) ?? 0) + 1);
110
- return [...freq.entries()]
111
- .sort((a, b) => b[1] - a[1])
112
- .slice(0, 5)
113
- .map(([w]) => w);
114
- }
115
- //# sourceMappingURL=reflection-sources.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"reflection-sources.js","sourceRoot":"","sources":["../../../src/data/memory/reflection-sources.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAgB,YAAY,EAAE,MAAM,eAAe,CAAC;AAE3D,qDAAqD;AACrD,SAAS,WAAW,CAAC,EAAW;IAC9B,MAAM,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC;IACrB,IAAI,OAAO,CAAC,KAAK,QAAQ;QAAE,OAAO,CAAC,CAAC;IACpC,OAAQ,CAAC,CAAC,IAAe,IAAK,CAAC,CAAC,OAAkB,IAAI,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;AAC1E,CAAC;AAED,8DAA8D;AAC9D,MAAM,UAAU,cAAc,CAAC,QAAmB;IAChD,OAAO,QAAQ;SACZ,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;SACtD,GAAG,CACF,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC,SAAS,MAAM,EAAE,CAAC,IAAI,IAAI,EAAE,CAAC,QAAQ,KAAK,EAAE,CAAC,SAAS,KAAK,WAAW,CAAC,EAAE,CAAC,EAAE,CAC5F;SACA,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC;AAED,iFAAiF;AACjF,MAAM,UAAU,cAAc,CAC5B,EAAY,EACZ,QAAgB,EAChB,SAAiB,EACjB,aAAqB;IAErB,+BAA+B;IAC/B,MAAM,UAAU,GAAG,EAAE;SAClB,OAAO,CACN;;;eAGS,CACV;SACA,GAAG,CAAC,QAAQ,EAAE,SAAS,CAA8B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KAAK;IACL,KAAK;IACL,KAAK;CACN,CAAC,CAAC;AAEH,kEAAkE;AAClE,MAAM,UAAU,eAAe,CAAC,IAAY;IAC1C,MAAM,KAAK,GAAG,IAAI;SACf,WAAW,EAAE;SACb,OAAO,CAAC,cAAc,EAAE,GAAG,CAAC;SAC5B,KAAK,CAAC,KAAK,CAAC;SACZ,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAErD,MAAM,IAAI,GAAG,IAAI,GAAG,EAAkB,CAAC;IACvC,KAAK,MAAM,CAAC,IAAI,KAAK;QAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IAE3D,OAAO,CAAC,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;SACvB,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;SAC3B,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC;SACX,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;AACrB,CAAC"}
@@ -1,43 +0,0 @@
1
- /**
2
- * Reflection pipeline — the "dreaming" phase that generates deeper insights
3
- * from episodic memories after consolidation.
4
- *
5
- * Unlike consolidation (which extracts facts and preferences), reflection
6
- * finds causal chains, recurring patterns, counterfactuals, and
7
- * self-assessments across episodes. It runs post-consolidation when
8
- * enough episodes exist, rate-limited to once per 4 hours.
9
- *
10
- * Split into: reflection-gates (quality/structural gates + field parsing),
11
- * reflection-dedup (embedding-based duplicate checks), reflection-sources
12
- * (episode gathering, narrative building, keyword extraction). This module
13
- * keeps the orchestrating pipeline and buffer maintenance.
14
- */
15
- import type { Database } from "./schema.js";
16
- interface ReflectionInsight {
17
- type: "causal" | "pattern" | "self_assessment" | "counterfactual";
18
- content: string;
19
- confidence: number;
20
- relatedEpisodeIds: string[];
21
- }
22
- interface ReflectionResult {
23
- insights: ReflectionInsight[];
24
- processedEpisodeCount: number;
25
- duration: number;
26
- }
27
- /**
28
- * Run the reflection pipeline on recent consolidated episodes.
29
- * Generates deeper insights beyond simple fact/preference extraction.
30
- *
31
- * Pipeline:
32
- * 1. Gate check — enough episodes, rate limit, API key present
33
- * 2. Gather episodes — recent + random sample of older ones
34
- * 3. Build a narrative from episode content
35
- * 4. Send to OpenAI with the reflection prompt
36
- * 5. Parse insights, de-duplicate, and save as semantic notes
37
- */
38
- export declare function runReflection(db: Database, threadId: number, options?: {
39
- maxEpisodes?: number;
40
- includeOldSample?: boolean;
41
- }): Promise<ReflectionResult>;
42
- export {};
43
- //# sourceMappingURL=reflection.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"reflection.d.ts","sourceRoot":"","sources":["../../../src/data/memory/reflection.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAwB5C,UAAU,iBAAiB;IACzB,IAAI,EAAE,QAAQ,GAAG,SAAS,GAAG,iBAAiB,GAAG,gBAAgB,CAAC;IAClE,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,iBAAiB,EAAE,MAAM,EAAE,CAAC;CAC7B;AAED,UAAU,gBAAgB;IACxB,QAAQ,EAAE,iBAAiB,EAAE,CAAC;IAC9B,qBAAqB,EAAE,MAAM,CAAC;IAC9B,QAAQ,EAAE,MAAM,CAAC;CAClB;AAiFD;;;;;;;;;;GAUG;AACH,wBAAsB,aAAa,CACjC,EAAE,EAAE,QAAQ,EACZ,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE;IAAE,WAAW,CAAC,EAAE,MAAM,CAAC;IAAC,gBAAgB,CAAC,EAAE,OAAO,CAAA;CAAE,GAC7D,OAAO,CAAC,gBAAgB,CAAC,CA4B3B"}
@@ -1,329 +0,0 @@
1
- /**
2
- * Reflection pipeline — the "dreaming" phase that generates deeper insights
3
- * from episodic memories after consolidation.
4
- *
5
- * Unlike consolidation (which extracts facts and preferences), reflection
6
- * finds causal chains, recurring patterns, counterfactuals, and
7
- * self-assessments across episodes. It runs post-consolidation when
8
- * enough episodes exist, rate-limited to once per 4 hours.
9
- *
10
- * Split into: reflection-gates (quality/structural gates + field parsing),
11
- * reflection-dedup (embedding-based duplicate checks), reflection-sources
12
- * (episode gathering, narrative building, keyword extraction). This module
13
- * keeps the orchestrating pipeline and buffer maintenance.
14
- */
15
- import { saveSemanticNote } from "./semantic-notes.js";
16
- import { saveNoteEmbedding } from "./note-embeddings.js";
17
- import { passesQualityGate, passesStructuralGate } from "./reflection-gates.js";
18
- import { checkDuplicate, checkLessonDuplicate } from "./reflection-dedup.js";
19
- import { buildNarrative, gatherEpisodes, extractKeywords } from "./reflection-sources.js";
20
- import { nowISO } from "./utils.js";
21
- import { repairAndParseJSON } from "../../llm/json.js";
22
- import { REFLECTION_ANALYZE_PROMPT, REFLECTION_STRUCTURE_PROMPT, } from "../../llm/prompts/reflection.js";
23
- import { log } from "../../lib/logger.js";
24
- import { getThread } from "./thread-registry.js";
25
- import { chatCompletion, generateEmbedding, } from "../../integrations/openai/chat.js";
26
- import { errorMessage } from "../../lib/utils.js";
27
- // ─── Rate-limiting ───────────────────────────────────────────────────────────
28
- const REFLECTION_COOLDOWN_MS = 4 * 60 * 60 * 1000; // 4 hours
29
- const MIN_EPISODES_FOR_REFLECTION = 20;
30
- // ─── Buffer cap ──────────────────────────────────────────────────────────────
31
- const MAX_ACTIVE_REFLECTIONS = 75;
32
- const STALE_REFLECTION_DAYS = 30;
33
- // Domain tags are freeform short labels (1-2 words) generated by the LLM.
34
- /** Per-thread timestamp of the last successful reflection run. */
35
- const lastReflectionAt = new Map();
36
- /** Per-thread guard against concurrent reflection runs. */
37
- const reflectionInProgress = new Set();
38
- /** Expire stale reflections (>30 days old, never accessed) and enforce buffer cap. */
39
- function enforceReflectionCap(db, threadId) {
40
- const knowledgeThreadId = threadId;
41
- let expired = 0;
42
- // Phase 1: Expire stale never-accessed reflections
43
- const staleResult = db
44
- .prepare(`UPDATE semantic_notes
45
- SET valid_to = ?, expiry_reason = 'reflection-cap'
46
- WHERE valid_to IS NULL AND superseded_by IS NULL
47
- AND content LIKE '[REFLECTION]%'
48
- AND access_count = 0
49
- AND created_at < datetime('now', '-' || ? || ' days')
50
- AND (thread_id = ? OR thread_id IS NULL)`)
51
- .run(nowISO(), STALE_REFLECTION_DAYS, knowledgeThreadId);
52
- expired += staleResult.changes;
53
- // Phase 2: Enforce hard cap — if still over limit, expire lowest-value
54
- const countRow = db
55
- .prepare(`SELECT COUNT(*) as c FROM semantic_notes
56
- WHERE valid_to IS NULL AND superseded_by IS NULL
57
- AND content LIKE '[REFLECTION]%'
58
- AND (thread_id = ? OR thread_id IS NULL)`)
59
- .get(knowledgeThreadId);
60
- if (countRow.c > MAX_ACTIVE_REFLECTIONS) {
61
- const excess = countRow.c - MAX_ACTIVE_REFLECTIONS;
62
- const toExpire = db
63
- .prepare(`SELECT note_id FROM semantic_notes
64
- WHERE valid_to IS NULL AND superseded_by IS NULL
65
- AND content LIKE '[REFLECTION]%'
66
- AND pinned = 0 AND is_guardrail = 0
67
- AND (thread_id = ? OR thread_id IS NULL)
68
- ORDER BY access_count ASC, created_at ASC
69
- LIMIT ?`)
70
- .all(knowledgeThreadId, excess);
71
- if (toExpire.length > 0) {
72
- const now = nowISO();
73
- const stmt = db.prepare(`UPDATE semantic_notes SET valid_to = ?, expiry_reason = 'reflection-cap' WHERE note_id = ?`);
74
- db.transaction(() => {
75
- for (const row of toExpire)
76
- stmt.run(now, row.note_id);
77
- })();
78
- expired += toExpire.length;
79
- }
80
- }
81
- if (expired > 0) {
82
- log.info(`[reflection] Buffer maintenance: expired ${expired} stale/excess reflections`);
83
- }
84
- return { expired };
85
- }
86
- // ─── Core Pipeline ───────────────────────────────────────────────────────────
87
- /**
88
- * Run the reflection pipeline on recent consolidated episodes.
89
- * Generates deeper insights beyond simple fact/preference extraction.
90
- *
91
- * Pipeline:
92
- * 1. Gate check — enough episodes, rate limit, API key present
93
- * 2. Gather episodes — recent + random sample of older ones
94
- * 3. Build a narrative from episode content
95
- * 4. Send to OpenAI with the reflection prompt
96
- * 5. Parse insights, de-duplicate, and save as semantic notes
97
- */
98
- export async function runReflection(db, threadId, options) {
99
- const startMs = Date.now();
100
- const maxRecent = options?.maxEpisodes ?? 30;
101
- const oldSampleSize = options?.includeOldSample !== false ? 10 : 0;
102
- // ── Gate: worker thread ───────────────────────────────────────────────────
103
- const threadEntry = getThread(db, threadId);
104
- if (threadEntry?.type === "worker") {
105
- log.info(`[reflection] Skipping — thread ${threadId} is a worker thread`);
106
- return { insights: [], processedEpisodeCount: 0, duration: Date.now() - startMs };
107
- }
108
- // ── Gate: rate limit ──────────────────────────────────────────────────────
109
- const lastRun = lastReflectionAt.get(threadId) ?? 0;
110
- if (Date.now() - lastRun < REFLECTION_COOLDOWN_MS) {
111
- log.info("[reflection] Skipped — cooldown not elapsed");
112
- return { insights: [], processedEpisodeCount: 0, duration: Date.now() - startMs };
113
- }
114
- if (reflectionInProgress.has(threadId)) {
115
- log.info("[reflection] Skipped — already running for this thread");
116
- return { insights: [], processedEpisodeCount: 0, duration: Date.now() - startMs };
117
- }
118
- reflectionInProgress.add(threadId);
119
- try {
120
- return await runReflectionInner(db, threadId, startMs, maxRecent, oldSampleSize);
121
- }
122
- finally {
123
- reflectionInProgress.delete(threadId);
124
- }
125
- }
126
- async function runReflectionInner(db, threadId, startMs, maxRecent, oldSampleSize) {
127
- // ── Gate: environment ─────────────────────────────────────────────────────
128
- const apiKey = process.env.OPENAI_API_KEY;
129
- if (!apiKey) {
130
- log.warn("[reflection] Skipped — OPENAI_API_KEY not set");
131
- return { insights: [], processedEpisodeCount: 0, duration: Date.now() - startMs };
132
- }
133
- const reflectionEnabled = process.env.REFLECTION_ENABLED;
134
- if (reflectionEnabled === "false" || reflectionEnabled === "0") {
135
- return { insights: [], processedEpisodeCount: 0, duration: Date.now() - startMs };
136
- }
137
- // ── Gate: episode count ───────────────────────────────────────────────────
138
- const countRow = db
139
- .prepare("SELECT COUNT(*) as c FROM episodes WHERE thread_id = ? AND consolidated = 1")
140
- .get(threadId);
141
- if (countRow.c < MIN_EPISODES_FOR_REFLECTION) {
142
- log.info(`[reflection] Skipped — only ${countRow.c} consolidated episodes (need ${MIN_EPISODES_FOR_REFLECTION})`);
143
- return { insights: [], processedEpisodeCount: 0, duration: Date.now() - startMs };
144
- }
145
- const knowledgeThreadId = threadId;
146
- // ── Step 0: Buffer maintenance — expire stale, enforce cap ─────────────
147
- enforceReflectionCap(db, threadId);
148
- // ── Step 1: Gather episodes ───────────────────────────────────────────────
149
- const episodes = gatherEpisodes(db, threadId, maxRecent, oldSampleSize);
150
- if (episodes.length === 0) {
151
- return { insights: [], processedEpisodeCount: 0, duration: Date.now() - startMs };
152
- }
153
- // ── Step 2: Build narrative ───────────────────────────────────────────────
154
- const narrative = buildNarrative(episodes);
155
- // ── Step 3a: ANALYZE — free-form reasoning ───────────────────────────────
156
- const analyzeMessages = [
157
- { role: "system", content: REFLECTION_ANALYZE_PROMPT },
158
- {
159
- role: "user",
160
- content: `## Episodes to analyze:\n${narrative}\n\nAnalyze the episodes above. What patterns, cause-effect chains, mistakes, or recurring situations do you see? Think deeply. Write 2-3 paragraphs of free-form reasoning.`,
161
- },
162
- ];
163
- let analysis;
164
- try {
165
- analysis = await chatCompletion(analyzeMessages, apiKey, {
166
- model: process.env.REFLECTION_MODEL ?? process.env.CONSOLIDATION_MODEL ?? "gpt-4o",
167
- category: "reflection",
168
- threadId,
169
- maxTokens: 1500,
170
- temperature: 0.55,
171
- timeoutMs: 90_000,
172
- });
173
- }
174
- catch (err) {
175
- log.error(`[reflection] Analyze step failed: ${errorMessage(err)}`);
176
- return { insights: [], processedEpisodeCount: episodes.length, duration: Date.now() - startMs };
177
- }
178
- if (!analysis.trim()) {
179
- log.warn("[reflection] Analyze step returned empty response — skipping structure step");
180
- return { insights: [], processedEpisodeCount: episodes.length, duration: Date.now() - startMs };
181
- }
182
- log.debug(`[reflection] Analyze step complete (${analysis.length} chars): ${analysis.slice(0, 120)}…`);
183
- // ── Step 3b: STRUCTURE — mechanical formatting ────────────────────────────
184
- const structureMessages = [
185
- { role: "system", content: REFLECTION_STRUCTURE_PROMPT },
186
- {
187
- role: "user",
188
- content: `## Free-form analysis:\n${analysis}\n\n## Original episodes (for episode_refs):\n${narrative}\n\nExtract only the genuinely valuable, project-specific insights into the structured JSON format. Returning {"insights": []} is the correct default — include an insight only if it clears the bar.`,
189
- },
190
- ];
191
- let raw;
192
- try {
193
- raw = await chatCompletion(structureMessages, apiKey, {
194
- model: process.env.REFLECTION_MODEL ?? process.env.CONSOLIDATION_MODEL ?? "gpt-4o",
195
- category: "reflection",
196
- threadId,
197
- maxTokens: 4096,
198
- temperature: 0.25,
199
- responseFormat: { type: "json_object" },
200
- timeoutMs: 90_000,
201
- });
202
- }
203
- catch (err) {
204
- log.error(`[reflection] Structure step failed: ${errorMessage(err)} — analysis was: ${analysis.slice(0, 200)}`);
205
- return { insights: [], processedEpisodeCount: episodes.length, duration: Date.now() - startMs };
206
- }
207
- // ── Step 4: Parse response ────────────────────────────────────────────────
208
- let parsed;
209
- try {
210
- parsed = repairAndParseJSON(raw);
211
- }
212
- catch (err) {
213
- log.error(`[reflection] JSON parse failed: ${errorMessage(err)}`);
214
- return { insights: [], processedEpisodeCount: episodes.length, duration: Date.now() - startMs };
215
- }
216
- const rawInsights = parsed.insights ?? [];
217
- const validTypes = new Set(["causal", "pattern", "self_assessment", "counterfactual"]);
218
- // ── Step 5: Save insights ─────────────────────────────────────────────────
219
- const savedInsights = [];
220
- const episodeIdSet = new Set(episodes.map((e) => e.episodeId));
221
- for (const ins of rawInsights) {
222
- // Validate all 5 template fields are present and non-trivial
223
- const fields = [ins.decision, ins.context, ins.outcome, ins.root_cause, ins.lesson];
224
- if (fields.some((f) => !f || typeof f !== "string" || f.length < 10)) {
225
- log.info(`[reflection] Skipped — incomplete template fields`);
226
- continue;
227
- }
228
- // Compile structured fields into a single rich content string.
229
- // Strip trailing punctuation from each field so the ". " separator doesn't
230
- // produce double periods when the LLM ends a field with its own period.
231
- const stripTrailing = (s) => s.trim().replace(/[.!?]+$/, "");
232
- const content = [
233
- `Decision: ${stripTrailing(ins.decision)}`,
234
- `Context: ${stripTrailing(ins.context)}`,
235
- `Outcome: ${stripTrailing(ins.outcome)}`,
236
- `Root cause: ${stripTrailing(ins.root_cause)}`,
237
- `Lesson: ${stripTrailing(ins.lesson)}`,
238
- ].join(". ");
239
- const insightType = validTypes.has(ins.type) ? ins.type : "pattern";
240
- const confidence = Math.max(0, Math.min(1, ins.confidence ?? 0.5));
241
- const refs = (ins.episode_refs ?? []).filter((id) => typeof id === "string" && episodeIdSet.has(id));
242
- // Normalize freeform domain tag
243
- const domain = typeof ins.domain === "string" && ins.domain.trim().length > 0
244
- ? ins.domain.trim().toLowerCase().slice(0, 30)
245
- : "general";
246
- // Quality gate — reject vague/generic insights before expensive dedup
247
- const quality = passesQualityGate(content, confidence);
248
- if (!quality.pass) {
249
- log.info(`[reflection] Quality gate rejected: ${quality.reason} — "${content.slice(0, 60)}…"`);
250
- continue;
251
- }
252
- // Structural gate — reject insights where root_cause restates outcome or lesson is not actionable
253
- const structural = passesStructuralGate({
254
- decision: ins.decision,
255
- context: ins.context,
256
- outcome: ins.outcome,
257
- root_cause: ins.root_cause,
258
- lesson: ins.lesson,
259
- });
260
- if (!structural.pass) {
261
- log.info(`[reflection] Structural gate rejected: ${structural.reason} — "${content.slice(0, 60)}…"`);
262
- continue;
263
- }
264
- // De-duplicate against existing reflections (embedding is cached for reuse)
265
- const prefixedContent = `[REFLECTION] [${insightType.toUpperCase()}] [${domain}] ${content}`;
266
- const { isDuplicate: duplicate, embedding: cachedEmbedding } = await checkDuplicate(db, prefixedContent, apiKey, knowledgeThreadId);
267
- if (duplicate) {
268
- log.info(`[reflection] Skipped duplicate insight: ${content.slice(0, 60)}…`);
269
- continue;
270
- }
271
- // Lesson-level dedup — catches semantically similar lessons at a lower threshold
272
- const lessonDuplicate = await checkLessonDuplicate(db, ins.lesson, apiKey, knowledgeThreadId);
273
- if (lessonDuplicate) {
274
- log.info(`[reflection] Skipped lesson-level duplicate: "${ins.lesson.slice(0, 60)}…"`);
275
- continue;
276
- }
277
- // Generate keywords from content + add domain as keyword
278
- const keywords = extractKeywords(content);
279
- // Save as a semantic note of type "pattern" (reflection insights are patterns)
280
- const noteId = saveSemanticNote(db, {
281
- type: "pattern",
282
- content: prefixedContent,
283
- keywords: ["reflection", insightType, domain, ...keywords],
284
- confidence,
285
- priority: confidence >= 0.8 ? 1 : 0,
286
- threadId: knowledgeThreadId,
287
- sourceEpisodes: refs,
288
- });
289
- // Reuse the embedding from dedup check — avoids a second API call
290
- if (cachedEmbedding) {
291
- saveNoteEmbedding(db, noteId, cachedEmbedding);
292
- }
293
- else {
294
- try {
295
- const embedding = await generateEmbedding(prefixedContent, apiKey, threadId);
296
- saveNoteEmbedding(db, noteId, embedding);
297
- }
298
- catch (err) {
299
- log.debug(`[reflection] Embedding save failed (backfill will retry): ${errorMessage(err)}`);
300
- }
301
- }
302
- savedInsights.push({
303
- type: insightType,
304
- content,
305
- confidence,
306
- relatedEpisodeIds: refs,
307
- });
308
- }
309
- // ── Log result ────────────────────────────────────────────────────────────
310
- logReflection(db, {
311
- episodesProcessed: episodes.length,
312
- insightsCreated: savedInsights.length,
313
- durationMs: Date.now() - startMs,
314
- });
315
- lastReflectionAt.set(threadId, Date.now());
316
- log.info(`[reflection] Completed: ${episodes.length} episodes → ${savedInsights.length} insights (${Date.now() - startMs}ms)`);
317
- return {
318
- insights: savedInsights,
319
- processedEpisodeCount: episodes.length,
320
- duration: Date.now() - startMs,
321
- };
322
- }
323
- // ─── Consolidation log ───────────────────────────────────────────────────────
324
- function logReflection(db, entry) {
325
- db.prepare(`INSERT INTO meta_consolidation_log
326
- (run_at, episodes_processed, notes_created, duration_ms)
327
- VALUES (?, ?, ?, ?)`).run(nowISO(), entry.episodesProcessed, entry.insightsCreated, entry.durationMs);
328
- }
329
- //# sourceMappingURL=reflection.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"reflection.js","sourceRoot":"","sources":["../../../src/data/memory/reflection.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAChF,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC7E,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAE1F,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EACL,yBAAyB,EACzB,2BAA2B,GAC5B,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EACL,cAAc,EACd,iBAAiB,GAElB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAiBlD,gFAAgF;AAEhF,MAAM,sBAAsB,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,UAAU;AAC7D,MAAM,2BAA2B,GAAG,EAAE,CAAC;AAEvC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a,CACpB,EAAY,EACZ,KAAiF;IAEjF,EAAE,CAAC,OAAO,CACR;;yBAEqB,CACtB,CAAC,GAAG,CAAC,MAAM,EAAE,EAAE,KAAK,CAAC,iBAAiB,EAAE,KAAK,CAAC,eAAe,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;AACpF,CAAC"}
@@ -1,6 +0,0 @@
1
- /**
2
- * System prompts for the two-step reflection pipeline (analyze, then structure).
3
- */
4
- export declare const REFLECTION_ANALYZE_PROMPT = "You are a reflective reasoning system analyzing your own recent experiences. Your job is to think deeply and freely \u2014 no templates, no JSON, no structured output.\n\nAnalyze the episodes for patterns, cause-effect chains, mistakes, recurring situations, and missed opportunities. Write in first person (\"I\"). Produce 2-3 paragraphs of genuine free-form reasoning. Focus on WHY things happened, not just WHAT happened. Dig into root causes and underlying mechanisms.\n\n## BANNED topics \u2014 do NOT analyze:\n- The memory system, consolidation, audits, cleanup, deduplication, or memory quality\n- The agent's own internal operations or meta-processes\n- How the agent manages its own notes, reflections, or knowledge base\n- Only reflect on EXTERNAL work: the project, codebase, operator interactions, technical decisions.";
5
- export declare const REFLECTION_STRUCTURE_PROMPT = "You are a reflective reasoning system. You will receive a free-form analysis and the original episodes it was based on. Your job is to extract ONLY genuinely valuable, project-specific insights \u2014 usually zero, occasionally one or two. Returning an empty list is the correct and expected outcome for a routine session.\n\nFor each insight, you MUST fill in ALL 5 template fields. If the analysis does not support filling every field with specific, concrete information, SKIP that insight entirely. Do not produce vague filler.\n\n## The bar for including an insight (ALL must hold):\n- It is specific to THIS project/operator \u2014 not general engineering or PM knowledge any competent agent already has.\n- The lesson names something concrete: a file, component, version, identifier, command, person, or number. Generic maxims (\"Always communicate clearly\", \"Break tasks into steps\", \"Always use UtcNow\") are REJECTED.\n- It would actually change what the agent does in a future session. If it wouldn't, drop it.\n- It is not already obvious from the fact/preference notes the system extracts separately.\nWhen in doubt, leave it out. Two truly project-specific insights per week is healthy; five per session is failure.\n\n## Template fields (ALL required):\n\n1. **decision** \u2014 What specific action or choice was made? Name the exact thing that happened.\n2. **context** \u2014 What was the situation that triggered this? What were the conditions?\n3. **outcome** \u2014 What was the concrete result? Was it positive or negative? Be specific.\n4. **root_cause** \u2014 WHY did this outcome happen? This must NOT restate the outcome. Dig deeper. What was the actual mechanism?\n5. **lesson** \u2014 A concrete, executable instruction for next time that names a specific file, component, version, command, or number. Start with a verb. \"Set DeployBook maxRetries above 0\" is good; \"Always configure retries properly\" is a rejected platitude.\n\n## Task domain (required):\n\nClassify each insight with a short freeform domain tag (1-2 words, kebab-case). Examples: debugging, linkedin-strategy, memory-system, hiring, content-marketing, architecture. Pick whatever fits the topic naturally.\n\n## Insight types:\n\n- \"causal\": cause-effect chains \u2014 \"When [X], it led to [Y] because [Z]\"\n- \"pattern\": recurring behaviors or situations\n- \"counterfactual\": what could have been done differently\n- \"self_assessment\": strengths and weaknesses\n\nRespond in JSON format:\n{\n \"insights\": [\n {\n \"type\": \"causal\" | \"pattern\" | \"self_assessment\" | \"counterfactual\",\n \"decision\": \"The specific action taken\",\n \"context\": \"What triggered it\",\n \"outcome\": \"What happened as a result\",\n \"root_cause\": \"The underlying WHY\",\n \"lesson\": \"Concrete instruction for next time\",\n \"domain\": \"short-kebab-case-tag\",\n \"confidence\": 0.0-1.0,\n \"episode_refs\": [\"ep_xxx\", \"ep_yyy\"]\n }\n ]\n}\n\n## Anti-patterns (your output WILL BE REJECTED if it contains these):\n\n- \"The agent tends to...\" / \"I tend to...\" \u2014 vague observation, not actionable\n- \"Should consider...\" \u2014 wishy-washy, not a concrete instruction\n- \"In general...\" / \"Overall...\" / \"significant progress\" / \"notable improvements\" \u2014 too abstract\n- \"various features\" / \"several enhancements\" / \"multiple improvements\" \u2014 unspecific\n- Restating the outcome as the root cause\n- Lesson that doesn't start with a verb\n- Any field shorter than 10 characters\n\nRules:\n- Minimum 0, maximum 5 insights \u2014 returning zero is common and correct; never invent an insight to fill the list\n- Each insight must reference specific episodes by their ID (from the original episodes provided)\n- Confidence should reflect how well-supported the insight is by evidence\n- Causal insights are most valuable \u2014 prioritize cause-and-effect\n- Quality over quantity: one project-specific insight beats five generic ones\n- Return {\"insights\": []} if the analysis does not support any deep, project-specific insight \u2014 this is the default";
6
- //# sourceMappingURL=reflection.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"reflection.d.ts","sourceRoot":"","sources":["../../../src/llm/prompts/reflection.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,eAAO,MAAM,yBAAyB,o0BAQ8D,CAAC;AAErG,eAAO,MAAM,2BAA2B,qkIA+D4E,CAAC"}
@@ -1,77 +0,0 @@
1
- /**
2
- * System prompts for the two-step reflection pipeline (analyze, then structure).
3
- */
4
- export const REFLECTION_ANALYZE_PROMPT = `You are a reflective reasoning system analyzing your own recent experiences. Your job is to think deeply and freely — no templates, no JSON, no structured output.
5
-
6
- Analyze the episodes for patterns, cause-effect chains, mistakes, recurring situations, and missed opportunities. Write in first person ("I"). Produce 2-3 paragraphs of genuine free-form reasoning. Focus on WHY things happened, not just WHAT happened. Dig into root causes and underlying mechanisms.
7
-
8
- ## BANNED topics — do NOT analyze:
9
- - The memory system, consolidation, audits, cleanup, deduplication, or memory quality
10
- - The agent's own internal operations or meta-processes
11
- - How the agent manages its own notes, reflections, or knowledge base
12
- - Only reflect on EXTERNAL work: the project, codebase, operator interactions, technical decisions.`;
13
- export const REFLECTION_STRUCTURE_PROMPT = `You are a reflective reasoning system. You will receive a free-form analysis and the original episodes it was based on. Your job is to extract ONLY genuinely valuable, project-specific insights — usually zero, occasionally one or two. Returning an empty list is the correct and expected outcome for a routine session.
14
-
15
- For each insight, you MUST fill in ALL 5 template fields. If the analysis does not support filling every field with specific, concrete information, SKIP that insight entirely. Do not produce vague filler.
16
-
17
- ## The bar for including an insight (ALL must hold):
18
- - It is specific to THIS project/operator — not general engineering or PM knowledge any competent agent already has.
19
- - The lesson names something concrete: a file, component, version, identifier, command, person, or number. Generic maxims ("Always communicate clearly", "Break tasks into steps", "Always use UtcNow") are REJECTED.
20
- - It would actually change what the agent does in a future session. If it wouldn't, drop it.
21
- - It is not already obvious from the fact/preference notes the system extracts separately.
22
- When in doubt, leave it out. Two truly project-specific insights per week is healthy; five per session is failure.
23
-
24
- ## Template fields (ALL required):
25
-
26
- 1. **decision** — What specific action or choice was made? Name the exact thing that happened.
27
- 2. **context** — What was the situation that triggered this? What were the conditions?
28
- 3. **outcome** — What was the concrete result? Was it positive or negative? Be specific.
29
- 4. **root_cause** — WHY did this outcome happen? This must NOT restate the outcome. Dig deeper. What was the actual mechanism?
30
- 5. **lesson** — A concrete, executable instruction for next time that names a specific file, component, version, command, or number. Start with a verb. "Set DeployBook maxRetries above 0" is good; "Always configure retries properly" is a rejected platitude.
31
-
32
- ## Task domain (required):
33
-
34
- Classify each insight with a short freeform domain tag (1-2 words, kebab-case). Examples: debugging, linkedin-strategy, memory-system, hiring, content-marketing, architecture. Pick whatever fits the topic naturally.
35
-
36
- ## Insight types:
37
-
38
- - "causal": cause-effect chains — "When [X], it led to [Y] because [Z]"
39
- - "pattern": recurring behaviors or situations
40
- - "counterfactual": what could have been done differently
41
- - "self_assessment": strengths and weaknesses
42
-
43
- Respond in JSON format:
44
- {
45
- "insights": [
46
- {
47
- "type": "causal" | "pattern" | "self_assessment" | "counterfactual",
48
- "decision": "The specific action taken",
49
- "context": "What triggered it",
50
- "outcome": "What happened as a result",
51
- "root_cause": "The underlying WHY",
52
- "lesson": "Concrete instruction for next time",
53
- "domain": "short-kebab-case-tag",
54
- "confidence": 0.0-1.0,
55
- "episode_refs": ["ep_xxx", "ep_yyy"]
56
- }
57
- ]
58
- }
59
-
60
- ## Anti-patterns (your output WILL BE REJECTED if it contains these):
61
-
62
- - "The agent tends to..." / "I tend to..." — vague observation, not actionable
63
- - "Should consider..." — wishy-washy, not a concrete instruction
64
- - "In general..." / "Overall..." / "significant progress" / "notable improvements" — too abstract
65
- - "various features" / "several enhancements" / "multiple improvements" — unspecific
66
- - Restating the outcome as the root cause
67
- - Lesson that doesn't start with a verb
68
- - Any field shorter than 10 characters
69
-
70
- Rules:
71
- - Minimum 0, maximum 5 insights — returning zero is common and correct; never invent an insight to fill the list
72
- - Each insight must reference specific episodes by their ID (from the original episodes provided)
73
- - Confidence should reflect how well-supported the insight is by evidence
74
- - Causal insights are most valuable — prioritize cause-and-effect
75
- - Quality over quantity: one project-specific insight beats five generic ones
76
- - Return {"insights": []} if the analysis does not support any deep, project-specific insight — this is the default`;
77
- //# sourceMappingURL=reflection.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"reflection.js","sourceRoot":"","sources":["../../../src/llm/prompts/reflection.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,CAAC,MAAM,yBAAyB,GAAG;;;;;;;;oGAQ2D,CAAC;AAErG,MAAM,CAAC,MAAM,2BAA2B,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;oHA+DyE,CAAC"}