@jungjaehoon/mama-os 0.20.1 → 0.22.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 (264) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/README.md +12 -4
  3. package/dist/agent/agent-loop.d.ts.map +1 -1
  4. package/dist/agent/agent-loop.js +76 -11
  5. package/dist/agent/agent-loop.js.map +1 -1
  6. package/dist/agent/code-act/host-bridge.d.ts.map +1 -1
  7. package/dist/agent/code-act/host-bridge.js +88 -3
  8. package/dist/agent/code-act/host-bridge.js.map +1 -1
  9. package/dist/agent/codex-mcp-process.d.ts +1 -0
  10. package/dist/agent/codex-mcp-process.d.ts.map +1 -1
  11. package/dist/agent/codex-mcp-process.js +3 -2
  12. package/dist/agent/codex-mcp-process.js.map +1 -1
  13. package/dist/agent/gateway-tool-executor.d.ts +24 -11
  14. package/dist/agent/gateway-tool-executor.d.ts.map +1 -1
  15. package/dist/agent/gateway-tool-executor.js +349 -30
  16. package/dist/agent/gateway-tool-executor.js.map +1 -1
  17. package/dist/agent/gateway-tools.md +7 -2
  18. package/dist/agent/model-runner.d.ts +8 -0
  19. package/dist/agent/model-runner.d.ts.map +1 -1
  20. package/dist/agent/model-runner.js.map +1 -1
  21. package/dist/agent/os-agent-capabilities.md +13 -12
  22. package/dist/agent/persistent-cli-adapter.d.ts +6 -0
  23. package/dist/agent/persistent-cli-adapter.d.ts.map +1 -1
  24. package/dist/agent/persistent-cli-adapter.js +21 -10
  25. package/dist/agent/persistent-cli-adapter.js.map +1 -1
  26. package/dist/agent/tool-registry.d.ts.map +1 -1
  27. package/dist/agent/tool-registry.js +33 -2
  28. package/dist/agent/tool-registry.js.map +1 -1
  29. package/dist/agent/types.d.ts +30 -2
  30. package/dist/agent/types.d.ts.map +1 -1
  31. package/dist/agent/types.js.map +1 -1
  32. package/dist/api/graph-api.d.ts.map +1 -1
  33. package/dist/api/graph-api.js +78 -5
  34. package/dist/api/graph-api.js.map +1 -1
  35. package/dist/api/index.d.ts +8 -1
  36. package/dist/api/index.d.ts.map +1 -1
  37. package/dist/api/index.js +18 -12
  38. package/dist/api/index.js.map +1 -1
  39. package/dist/api/operator-handler.d.ts +19 -0
  40. package/dist/api/operator-handler.d.ts.map +1 -0
  41. package/dist/api/operator-handler.js +106 -0
  42. package/dist/api/operator-handler.js.map +1 -0
  43. package/dist/api/operator-summary.d.ts +3 -0
  44. package/dist/api/operator-summary.d.ts.map +1 -0
  45. package/dist/api/operator-summary.js +72 -0
  46. package/dist/api/operator-summary.js.map +1 -0
  47. package/dist/api/operator-tasks-handler.d.ts +7 -0
  48. package/dist/api/operator-tasks-handler.d.ts.map +1 -0
  49. package/dist/api/operator-tasks-handler.js +165 -0
  50. package/dist/api/operator-tasks-handler.js.map +1 -0
  51. package/dist/api/report-handler.d.ts +7 -0
  52. package/dist/api/report-handler.d.ts.map +1 -1
  53. package/dist/api/report-handler.js +30 -0
  54. package/dist/api/report-handler.js.map +1 -1
  55. package/dist/api/report-persistence.d.ts +17 -0
  56. package/dist/api/report-persistence.d.ts.map +1 -0
  57. package/dist/api/report-persistence.js +91 -0
  58. package/dist/api/report-persistence.js.map +1 -0
  59. package/dist/cli/commands/start.d.ts.map +1 -1
  60. package/dist/cli/commands/start.js +402 -250
  61. package/dist/cli/commands/start.js.map +1 -1
  62. package/dist/cli/config/config-manager.d.ts.map +1 -1
  63. package/dist/cli/config/config-manager.js +93 -55
  64. package/dist/cli/config/config-manager.js.map +1 -1
  65. package/dist/cli/config/types.d.ts +17 -2
  66. package/dist/cli/config/types.d.ts.map +1 -1
  67. package/dist/cli/config/types.js +4 -0
  68. package/dist/cli/config/types.js.map +1 -1
  69. package/dist/cli/runtime/agent-loop-init.d.ts +3 -1
  70. package/dist/cli/runtime/agent-loop-init.d.ts.map +1 -1
  71. package/dist/cli/runtime/agent-loop-init.js +16 -7
  72. package/dist/cli/runtime/agent-loop-init.js.map +1 -1
  73. package/dist/cli/runtime/api-routes-init.d.ts.map +1 -1
  74. package/dist/cli/runtime/api-routes-init.js +503 -259
  75. package/dist/cli/runtime/api-routes-init.js.map +1 -1
  76. package/dist/cli/runtime/api-server-init.d.ts.map +1 -1
  77. package/dist/cli/runtime/api-server-init.js +12 -7
  78. package/dist/cli/runtime/api-server-init.js.map +1 -1
  79. package/dist/cli/runtime/connector-init.d.ts +19 -1
  80. package/dist/cli/runtime/connector-init.d.ts.map +1 -1
  81. package/dist/cli/runtime/connector-init.js +32 -2
  82. package/dist/cli/runtime/connector-init.js.map +1 -1
  83. package/dist/cli/runtime/gateway-init.d.ts.map +1 -1
  84. package/dist/cli/runtime/gateway-init.js +3 -1
  85. package/dist/cli/runtime/gateway-init.js.map +1 -1
  86. package/dist/cli/runtime/memory-agent-init.d.ts +2 -1
  87. package/dist/cli/runtime/memory-agent-init.d.ts.map +1 -1
  88. package/dist/cli/runtime/memory-agent-init.js +15 -3
  89. package/dist/cli/runtime/memory-agent-init.js.map +1 -1
  90. package/dist/cli/runtime/message-router-config.d.ts +4 -0
  91. package/dist/cli/runtime/message-router-config.d.ts.map +1 -0
  92. package/dist/cli/runtime/message-router-config.js +11 -0
  93. package/dist/cli/runtime/message-router-config.js.map +1 -0
  94. package/dist/cli/runtime/scheduler-init.d.ts.map +1 -1
  95. package/dist/cli/runtime/scheduler-init.js +12 -12
  96. package/dist/cli/runtime/scheduler-init.js.map +1 -1
  97. package/dist/connectors/framework/polling-scheduler.d.ts.map +1 -1
  98. package/dist/connectors/framework/polling-scheduler.js +53 -2
  99. package/dist/connectors/framework/polling-scheduler.js.map +1 -1
  100. package/dist/connectors/framework/types.d.ts +8 -0
  101. package/dist/connectors/framework/types.d.ts.map +1 -1
  102. package/dist/connectors/kagemusha/query-tools.d.ts.map +1 -1
  103. package/dist/connectors/kagemusha/query-tools.js +14 -3
  104. package/dist/connectors/kagemusha/query-tools.js.map +1 -1
  105. package/dist/connectors/slack/index.d.ts.map +1 -1
  106. package/dist/connectors/slack/index.js +3 -1
  107. package/dist/connectors/slack/index.js.map +1 -1
  108. package/dist/connectors/trello/index.d.ts.map +1 -1
  109. package/dist/connectors/trello/index.js +6 -2
  110. package/dist/connectors/trello/index.js.map +1 -1
  111. package/dist/db/agent-store.d.ts +5 -0
  112. package/dist/db/agent-store.d.ts.map +1 -1
  113. package/dist/db/agent-store.js +6 -3
  114. package/dist/db/agent-store.js.map +1 -1
  115. package/dist/db/migrations/agent-activity-tool-name.d.ts +8 -0
  116. package/dist/db/migrations/agent-activity-tool-name.d.ts.map +1 -0
  117. package/dist/db/migrations/agent-activity-tool-name.js +24 -0
  118. package/dist/db/migrations/agent-activity-tool-name.js.map +1 -0
  119. package/dist/db/migrations/wiki-artifacts.d.ts +3 -0
  120. package/dist/db/migrations/wiki-artifacts.d.ts.map +1 -0
  121. package/dist/db/migrations/wiki-artifacts.js +24 -0
  122. package/dist/db/migrations/wiki-artifacts.js.map +1 -0
  123. package/dist/envelope/run-guard.d.ts +10 -0
  124. package/dist/envelope/run-guard.d.ts.map +1 -0
  125. package/dist/envelope/run-guard.js +19 -0
  126. package/dist/envelope/run-guard.js.map +1 -0
  127. package/dist/gateways/message-router.d.ts.map +1 -1
  128. package/dist/gateways/message-router.js +15 -3
  129. package/dist/gateways/message-router.js.map +1 -1
  130. package/dist/gateways/types.d.ts +4 -0
  131. package/dist/gateways/types.d.ts.map +1 -1
  132. package/dist/multi-agent/agent-event-bus.d.ts +14 -0
  133. package/dist/multi-agent/agent-event-bus.d.ts.map +1 -1
  134. package/dist/multi-agent/agent-event-bus.js +34 -0
  135. package/dist/multi-agent/agent-event-bus.js.map +1 -1
  136. package/dist/multi-agent/conductor-persona.js +2 -2
  137. package/dist/multi-agent/dashboard-agent-persona.d.ts +6 -2
  138. package/dist/multi-agent/dashboard-agent-persona.d.ts.map +1 -1
  139. package/dist/multi-agent/dashboard-agent-persona.js +65 -32
  140. package/dist/multi-agent/dashboard-agent-persona.js.map +1 -1
  141. package/dist/multi-agent/memory-agent-persona.d.ts +1 -1
  142. package/dist/multi-agent/memory-agent-persona.d.ts.map +1 -1
  143. package/dist/multi-agent/memory-agent-persona.js +25 -4
  144. package/dist/multi-agent/memory-agent-persona.js.map +1 -1
  145. package/dist/multi-agent/runtime-process.d.ts +4 -2
  146. package/dist/multi-agent/runtime-process.d.ts.map +1 -1
  147. package/dist/multi-agent/runtime-process.js +7 -4
  148. package/dist/multi-agent/runtime-process.js.map +1 -1
  149. package/dist/multi-agent/types.d.ts +1 -1
  150. package/dist/multi-agent/wiki-agent-persona.d.ts +7 -1
  151. package/dist/multi-agent/wiki-agent-persona.d.ts.map +1 -1
  152. package/dist/multi-agent/wiki-agent-persona.js +82 -68
  153. package/dist/multi-agent/wiki-agent-persona.js.map +1 -1
  154. package/dist/operator/action-verifier.d.ts +50 -0
  155. package/dist/operator/action-verifier.d.ts.map +1 -0
  156. package/dist/operator/action-verifier.js +68 -0
  157. package/dist/operator/action-verifier.js.map +1 -0
  158. package/dist/operator/board-reconcile.d.ts +62 -0
  159. package/dist/operator/board-reconcile.d.ts.map +1 -0
  160. package/dist/operator/board-reconcile.js +160 -0
  161. package/dist/operator/board-reconcile.js.map +1 -0
  162. package/dist/operator/board-slot-instructions.d.ts +26 -0
  163. package/dist/operator/board-slot-instructions.d.ts.map +1 -0
  164. package/dist/operator/board-slot-instructions.js +76 -0
  165. package/dist/operator/board-slot-instructions.js.map +1 -0
  166. package/dist/operator/connector-delta-repo.d.ts +33 -0
  167. package/dist/operator/connector-delta-repo.d.ts.map +1 -0
  168. package/dist/operator/connector-delta-repo.js +0 -0
  169. package/dist/operator/connector-delta-repo.js.map +1 -0
  170. package/dist/operator/mama-memory-port.d.ts +13 -0
  171. package/dist/operator/mama-memory-port.d.ts.map +1 -0
  172. package/dist/operator/mama-memory-port.js +35 -0
  173. package/dist/operator/mama-memory-port.js.map +1 -0
  174. package/dist/operator/operator-interfaces.d.ts +136 -0
  175. package/dist/operator/operator-interfaces.d.ts.map +1 -0
  176. package/dist/operator/operator-interfaces.js +15 -0
  177. package/dist/operator/operator-interfaces.js.map +1 -0
  178. package/dist/operator/operator-trigger-loop.d.ts +119 -0
  179. package/dist/operator/operator-trigger-loop.d.ts.map +1 -0
  180. package/dist/operator/operator-trigger-loop.js +267 -0
  181. package/dist/operator/operator-trigger-loop.js.map +1 -0
  182. package/dist/operator/report-run.d.ts +78 -0
  183. package/dist/operator/report-run.d.ts.map +1 -0
  184. package/dist/operator/report-run.js +141 -0
  185. package/dist/operator/report-run.js.map +1 -0
  186. package/dist/operator/report-scheduler.d.ts +66 -0
  187. package/dist/operator/report-scheduler.d.ts.map +1 -0
  188. package/dist/operator/report-scheduler.js +135 -0
  189. package/dist/operator/report-scheduler.js.map +1 -0
  190. package/dist/operator/situation-report.d.ts +90 -0
  191. package/dist/operator/situation-report.d.ts.map +1 -0
  192. package/dist/operator/situation-report.js +221 -0
  193. package/dist/operator/situation-report.js.map +1 -0
  194. package/dist/operator/task-ledger.d.ts +96 -0
  195. package/dist/operator/task-ledger.d.ts.map +1 -0
  196. package/dist/operator/task-ledger.js +277 -0
  197. package/dist/operator/task-ledger.js.map +1 -0
  198. package/dist/operator/trigger-author.d.ts +45 -0
  199. package/dist/operator/trigger-author.d.ts.map +1 -0
  200. package/dist/operator/trigger-author.js +217 -0
  201. package/dist/operator/trigger-author.js.map +1 -0
  202. package/dist/operator/trigger-evolve.d.ts +31 -0
  203. package/dist/operator/trigger-evolve.d.ts.map +1 -0
  204. package/dist/operator/trigger-evolve.js +51 -0
  205. package/dist/operator/trigger-evolve.js.map +1 -0
  206. package/dist/operator/trigger-fire.d.ts +29 -0
  207. package/dist/operator/trigger-fire.d.ts.map +1 -0
  208. package/dist/operator/trigger-fire.js +41 -0
  209. package/dist/operator/trigger-fire.js.map +1 -0
  210. package/dist/operator/trigger-matcher.d.ts +19 -0
  211. package/dist/operator/trigger-matcher.d.ts.map +1 -0
  212. package/dist/operator/trigger-matcher.js +61 -0
  213. package/dist/operator/trigger-matcher.js.map +1 -0
  214. package/dist/operator/trigger-registry.d.ts +36 -0
  215. package/dist/operator/trigger-registry.d.ts.map +1 -0
  216. package/dist/operator/trigger-registry.js +135 -0
  217. package/dist/operator/trigger-registry.js.map +1 -0
  218. package/dist/operator/trigger-review.d.ts +23 -0
  219. package/dist/operator/trigger-review.d.ts.map +1 -0
  220. package/dist/operator/trigger-review.js +127 -0
  221. package/dist/operator/trigger-review.js.map +1 -0
  222. package/dist/operator/trigger-types.d.ts +84 -0
  223. package/dist/operator/trigger-types.d.ts.map +1 -0
  224. package/dist/operator/trigger-types.js +14 -0
  225. package/dist/operator/trigger-types.js.map +1 -0
  226. package/dist/scheduler/cron-worker.d.ts.map +1 -1
  227. package/dist/scheduler/cron-worker.js +3 -1
  228. package/dist/scheduler/cron-worker.js.map +1 -1
  229. package/dist/security/security-monitor.d.ts.map +1 -1
  230. package/dist/security/security-monitor.js +1 -0
  231. package/dist/security/security-monitor.js.map +1 -1
  232. package/dist/wiki/obsidian-writer.d.ts +1 -1
  233. package/dist/wiki/obsidian-writer.d.ts.map +1 -1
  234. package/dist/wiki/obsidian-writer.js +67 -27
  235. package/dist/wiki/obsidian-writer.js.map +1 -1
  236. package/dist/wiki/path-safety.d.ts +2 -0
  237. package/dist/wiki/path-safety.d.ts.map +1 -0
  238. package/dist/wiki/path-safety.js +40 -0
  239. package/dist/wiki/path-safety.js.map +1 -0
  240. package/dist/wiki/types.d.ts +4 -2
  241. package/dist/wiki/types.d.ts.map +1 -1
  242. package/dist/wiki/types.js +1 -1
  243. package/dist/wiki/types.js.map +1 -1
  244. package/dist/wiki-artifacts/normalization.d.ts +8 -0
  245. package/dist/wiki-artifacts/normalization.d.ts.map +1 -0
  246. package/dist/wiki-artifacts/normalization.js +41 -0
  247. package/dist/wiki-artifacts/normalization.js.map +1 -0
  248. package/dist/wiki-artifacts/types.d.ts +52 -0
  249. package/dist/wiki-artifacts/types.d.ts.map +1 -0
  250. package/dist/wiki-artifacts/types.js +3 -0
  251. package/dist/wiki-artifacts/types.js.map +1 -0
  252. package/dist/wiki-artifacts/wiki-publish-adapter.d.ts +14 -0
  253. package/dist/wiki-artifacts/wiki-publish-adapter.d.ts.map +1 -0
  254. package/dist/wiki-artifacts/wiki-publish-adapter.js +71 -0
  255. package/dist/wiki-artifacts/wiki-publish-adapter.js.map +1 -0
  256. package/package.json +5 -3
  257. package/public/ui/assets/index-CKOJQYXA.css +1 -0
  258. package/public/ui/assets/index-OSgiwL24.js +62 -0
  259. package/public/ui/index.html +14 -0
  260. package/public/ui/theme-init.js +20 -0
  261. package/public/viewer/js/utils/api.js +2 -2
  262. package/public/viewer/src/utils/api.ts +9 -2
  263. package/public/viewer/sw.js +1 -1
  264. package/public/viewer/viewer.html +17 -27
@@ -0,0 +1,221 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SituationReporter = exports.OPERATOR_FULL_REPORT_TAG = void 0;
4
+ /**
5
+ * Machine frame tag prepended to the FULL report prompt so the report-run wiring can tell a full
6
+ * report from a digest for tool-use auditing (report-run.ts). Kagemusha frames its scheduled full
7
+ * report with the same bracketed-tag convention (report-prompts.ts buildFullReportPrompt).
8
+ */
9
+ exports.OPERATOR_FULL_REPORT_TAG = '[operator_full_report]';
10
+ /** Deterministic prompt-size bounds (mind memory + prompt length; see plan design decision 4). */
11
+ const MAX_EXCERPTS_PER_CHANNEL = 5;
12
+ const MAX_EXCERPT_CHARS = 160;
13
+ const MAX_CHANNELS_IN_PROMPT = 12;
14
+ const MAX_RECALLED = 20;
15
+ /** Machine trailer the agent appends; stripped before the owner sees the report. */
16
+ const USED_TRIGGERS_PATTERN = /\n?^USED_TRIGGERS:\s*(.*)\s*$/im;
17
+ class SituationReporter {
18
+ windowByChannel = new Map();
19
+ windowTotal = 0;
20
+ fireAgg = new Map();
21
+ authored = 0;
22
+ recalled = new Map(); // topic -> content (deduped, bounded)
23
+ opts;
24
+ constructor(opts = {}) {
25
+ this.opts = opts;
26
+ }
27
+ /** Fold a batch of drained events into the bounded per-channel window. */
28
+ recordWindow(events) {
29
+ for (const e of events) {
30
+ const w = this.windowByChannel.get(e.channelId) ?? { count: 0, excerpts: [] };
31
+ w.count += 1;
32
+ const text = e.content.trim();
33
+ if (text) {
34
+ w.excerpts.push(text.slice(0, MAX_EXCERPT_CHARS));
35
+ if (w.excerpts.length > MAX_EXCERPTS_PER_CHANNEL) {
36
+ w.excerpts.shift();
37
+ }
38
+ }
39
+ this.windowByChannel.set(e.channelId, w);
40
+ this.windowTotal += 1;
41
+ }
42
+ }
43
+ /** Fold one fire into the aggregate; merge the memory it recalled (agent-query-driven). */
44
+ recordFire(activity) {
45
+ const key = `${activity.triggerId}|${activity.channelId}`;
46
+ const agg = this.fireAgg.get(key) ?? {
47
+ triggerId: activity.triggerId,
48
+ kind: activity.kind,
49
+ channelId: activity.channelId,
50
+ count: 0,
51
+ topics: new Set(),
52
+ };
53
+ agg.count += 1;
54
+ for (const r of activity.recalled) {
55
+ agg.topics.add(r.topic);
56
+ if (!this.recalled.has(r.topic) && this.recalled.size < MAX_RECALLED) {
57
+ this.recalled.set(r.topic, r.content.slice(0, MAX_EXCERPT_CHARS));
58
+ }
59
+ }
60
+ this.fireAgg.set(key, agg);
61
+ }
62
+ recordAuthored(count) {
63
+ this.authored += count;
64
+ }
65
+ /** Any window events, fires, or authored triggers accumulated since the last reset. */
66
+ hasActivity() {
67
+ return this.windowTotal > 0 || this.fireAgg.size > 0 || this.authored > 0;
68
+ }
69
+ /**
70
+ * Agent composes the report from the aggregate; sink delivers it. Returns true if a report was
71
+ * sent, false if there was nothing to say or the agent suppressed it (NOTHING).
72
+ */
73
+ async report(askAgent, output, mode) {
74
+ // M2.1: the scheduled FULL report is a duty report - it composes even on an empty window
75
+ // (the owner relies on it arriving; a quiet window is itself the news). Digests stay gated.
76
+ if (mode !== 'full' && !this.hasActivity())
77
+ return false;
78
+ const raw = (await askAgent(this.buildPrompt(mode))).trim();
79
+ if (raw === '' || /^NOTHING\b/i.test(raw)) {
80
+ this.reset(); // agent judged nothing worth reporting - drop the buffer quietly
81
+ return false;
82
+ }
83
+ // Parse + strip the USED_TRIGGERS machine trailer (the owner never sees it)
84
+ // and validate the ids against THIS window's fires (no hallucinated credit).
85
+ const match = raw.match(USED_TRIGGERS_PATTERN);
86
+ const text = raw.replace(USED_TRIGGERS_PATTERN, '').trim();
87
+ let cited = [];
88
+ if (match) {
89
+ const windowIds = new Set([...this.fireAgg.values()].map((f) => f.triggerId));
90
+ cited = [
91
+ ...new Set(match[1]
92
+ .split(',')
93
+ .map((id) => id.trim())
94
+ .filter((id) => id.length > 0 && id.toLowerCase() !== 'none' && windowIds.has(id))),
95
+ ];
96
+ }
97
+ if (text === '') {
98
+ this.reset(); // trailer-only reply: nothing was delivered, so no credit either
99
+ return false;
100
+ }
101
+ await output.send(text); // throws loudly on failure; buffer kept for retry (no-fallback)
102
+ // Credit only AFTER a successful send: success means "cited in a DELIVERED
103
+ // report". Crediting before send would double-count on the retry path
104
+ // (send throws -> buffer kept -> next cadence re-cites the same fires).
105
+ if (cited.length > 0) {
106
+ this.opts.recordTriggerUse?.(cited);
107
+ }
108
+ this.reset();
109
+ return true;
110
+ }
111
+ reset() {
112
+ this.windowByChannel.clear();
113
+ this.windowTotal = 0;
114
+ this.fireAgg.clear();
115
+ this.authored = 0;
116
+ this.recalled.clear();
117
+ }
118
+ /** Public for testability. Aggregate window + fire activity + recalled memory -> agent prompt. */
119
+ buildPrompt(mode) {
120
+ const channels = [...this.windowByChannel.entries()].sort((a, b) => b[1].count - a[1].count);
121
+ const shown = channels.slice(0, MAX_CHANNELS_IN_PROMPT);
122
+ const windowLines = shown.map(([channelId, w]) => `- ${channelId}: ${w.count} msg(s); recent: ${w.excerpts.join(' | ') || '(none)'}`);
123
+ if (channels.length > shown.length) {
124
+ const restCount = channels.slice(shown.length).reduce((n, [, w]) => n + w.count, 0);
125
+ windowLines.push(`- (+${channels.length - shown.length} more channel(s), ${restCount} msg(s))`);
126
+ }
127
+ const fireLines = [...this.fireAgg.values()].map((f) => `- trigger "${f.kind}" [id: ${f.triggerId}] fired ${f.count}x on ${f.channelId}; recalled: ${[...f.topics].join(', ') || '(none)'}`);
128
+ const memoryLines = [...this.recalled.entries()].map(([topic, content]) => `- ${topic}: ${content}`);
129
+ // Resolve the gather lines only for the FULL report - the digest framing never renders
130
+ // them, so a zero-arg PROVIDER must not be invoked (it may do real gather work) just to
131
+ // build a digest prompt. The guard below stays anchored on the RESOLVED array: a zero-arg
132
+ // provider's `.length` is its arity (0), so guarding on the raw opts value would compile
133
+ // cleanly and silently drop the ENTIRE gather block on every production report.
134
+ const gatherLines = mode === 'full'
135
+ ? typeof this.opts.selfGatherLines === 'function'
136
+ ? this.opts.selfGatherLines()
137
+ : (this.opts.selfGatherLines ?? [])
138
+ : [];
139
+ // M2.1 posture: the full report is a DUTY report (always arrives - a quiet window is
140
+ // reported as quiet, the aliveness signal owners rely on); the digest defaults to briefing
141
+ // and keeps NOTHING only for pure noise.
142
+ const framing = mode === 'full'
143
+ ? [
144
+ exports.OPERATOR_FULL_REPORT_TAG,
145
+ 'You are the operator agent. Write your scheduled FULLER situation report for your owner',
146
+ 'covering the whole window below (multiple channels, since the last full report). Group',
147
+ "what recurred, what is new, and what needs the owner's attention. Plain language, no",
148
+ 'markdown tables. This scheduled report must ALWAYS arrive: if the window was quiet,',
149
+ 'say so in one or two lines instead of skipping.',
150
+ "Structure the report with these sections (render the headings in the owner's language;",
151
+ 'omit a section only when it is truly empty):',
152
+ '1) Key situation 2) Action required 3) Decisions needed 4) Pipeline 5) Next actions',
153
+ ...(gatherLines.length > 0
154
+ ? [
155
+ '',
156
+ 'Before writing, ACTIVELY gather current context by CALLING your gateway tools.',
157
+ 'Emit each call as a fenced tool_call JSON block and wait for the result before',
158
+ 'the next call. The block format is exactly:',
159
+ '```tool_call',
160
+ '{"name": "kagemusha_tasks", "input": {"status": "in_progress"}}',
161
+ '```',
162
+ 'Gather with these gateway tool calls:',
163
+ ...gatherLines.map((line) => `- ${line}`),
164
+ 'These gateway tools are NOT native or deferred CLI tools: ToolSearch cannot',
165
+ 'load them and will find nothing. Invoke them ONLY as fenced tool_call JSON',
166
+ 'blocks in your reply text - do not search for them, and do not fall back to',
167
+ 'Bash or curl against any API.',
168
+ 'Use ONLY these gateway tool_call blocks to gather. Do NOT read log files,',
169
+ 'databases, or the filesystem with Bash, Read, or other native tools - those are',
170
+ 'not the task board and will make the report wrong. Your gateway tool findings',
171
+ 'are the primary source; the window summary below is only a hint.',
172
+ '',
173
+ 'After gathering, if the window contains a durable decision or lesson worth',
174
+ 'keeping, persist exactly ONE with a gateway tool_call to mama_save (type',
175
+ '"decision", with topic, decision, reasoning). Only save when it is genuinely',
176
+ 'durable; skip the save otherwise. This is your judgement, not a requirement.',
177
+ ]
178
+ : []),
179
+ ...(this.opts.boardPublishLines && this.opts.boardPublishLines.length > 0
180
+ ? ['', ...this.opts.boardPublishLines]
181
+ : []),
182
+ ]
183
+ : [
184
+ 'You are the operator agent. Write a SHORT proactive digest for your owner about the',
185
+ 'situation below - what happened, what recurred, and what the owner may want to look at.',
186
+ '2-6 lines, plain language, no markdown tables. Default to sending the brief when there',
187
+ 'is meaningful activity; reply exactly NOTHING only if this window is pure noise',
188
+ '(duplicates, bot chatter) with nothing the owner could act on.',
189
+ ];
190
+ return [
191
+ ...framing,
192
+ // Attribution discipline (owner feedback: the only quality complaint on day-1
193
+ // reports was merged sender/room identities).
194
+ 'Attribute people and rooms EXACTLY as they appear in the source lines: a channel/room',
195
+ 'name is never a person, and a sender is never a room. If you cannot tell who said',
196
+ 'something, write "(sender unclear)" instead of guessing or merging names.',
197
+ // G2 success signal: machine trailer, stripped before delivery.
198
+ 'After the report body, add ONE final line exactly in this form:',
199
+ 'USED_TRIGGERS: <comma-separated ids of the fired triggers (from [id: ...] in the fire',
200
+ 'activity below) whose fire or recalled memory you actually drew on>, or',
201
+ 'USED_TRIGGERS: none if you drew on none. This line is machine-read and stripped',
202
+ 'before the owner sees the report.',
203
+ 'Reply in the language the owner uses on these channels if you can tell; otherwise English.',
204
+ // Local wall-clock, not UTC: the first live report stamped itself in UTC because the
205
+ // agent had no local time reference (Kagemusha injects local time the same way).
206
+ `Current local time: ${new Date().toLocaleString()}. Use LOCAL time in the report, never UTC.`,
207
+ '',
208
+ 'Window (per channel; excerpts truncated):',
209
+ ...(windowLines.length > 0 ? windowLines : ['- (no channel messages this window)']),
210
+ '',
211
+ `Triggers newly authored this window: ${this.authored}`,
212
+ 'Fire activity:',
213
+ ...(fireLines.length > 0 ? fireLines : ['- (no triggers fired this window)']),
214
+ '',
215
+ 'Memory your triggers surfaced this window:',
216
+ ...(memoryLines.length > 0 ? memoryLines : ['- (none)']),
217
+ ].join('\n');
218
+ }
219
+ }
220
+ exports.SituationReporter = SituationReporter;
221
+ //# sourceMappingURL=situation-report.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"situation-report.js","sourceRoot":"","sources":["../../src/operator/situation-report.ts"],"names":[],"mappings":";;;AAoBA;;;;GAIG;AACU,QAAA,wBAAwB,GAAG,wBAAwB,CAAC;AAWjE,kGAAkG;AAClG,MAAM,wBAAwB,GAAG,CAAC,CAAC;AACnC,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAC9B,MAAM,sBAAsB,GAAG,EAAE,CAAC;AAClC,MAAM,YAAY,GAAG,EAAE,CAAC;AA8CxB,oFAAoF;AACpF,MAAM,qBAAqB,GAAG,iCAAiC,CAAC;AAEhE,MAAa,iBAAiB;IACpB,eAAe,GAAG,IAAI,GAAG,EAAyB,CAAC;IACnD,WAAW,GAAG,CAAC,CAAC;IAChB,OAAO,GAAG,IAAI,GAAG,EAAmB,CAAC;IACrC,QAAQ,GAAG,CAAC,CAAC;IACb,QAAQ,GAAG,IAAI,GAAG,EAAkB,CAAC,CAAC,sCAAsC;IAC5E,IAAI,CAA2B;IAEvC,YAAY,OAAiC,EAAE;QAC7C,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAED,0EAA0E;IAC1E,YAA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QAAQ,EAAE;YACvD,gBAAgB;YAChB,GAAG,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,mCAAmC,CAAC,CAAC;YAC7E,EAAE;YACF,4CAA4C;YAC5C,GAAG,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC;SACzD,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACf,CAAC;CACF;AA1OD,8CA0OC"}
@@ -0,0 +1,96 @@
1
+ /**
2
+ * TaskLedger - the operator-owned native work-item ledger (M8 Task 0.1).
3
+ *
4
+ * Ports the SHAPE of Kagemusha's proven task store (11 columns: id/title/status/
5
+ * priority/deadline/source/auto_created/confirmed/timestamps) plus `assignee`
6
+ * and an idempotency key. Implements the pre-existing `TaskSource` interface
7
+ * (operator-interfaces.ts) so the board projects ONE task model, not two.
8
+ *
9
+ * Reconcile runs create/update rows through the task_create/task_update gateway
10
+ * tools; the pipeline board slot is a projection of `list({order:
11
+ * 'deadline_priority'})`. The AGENT makes every judgment about what becomes a
12
+ * task; this store only persists.
13
+ *
14
+ * Schema-extension note: CREATE TABLE IF NOT EXISTS is a no-op on existing
15
+ * tables. Any post-ship column addition needs an explicit ALTER TABLE guarded
16
+ * by a PRAGMA table_info check, added to runMigration().
17
+ *
18
+ * The db handle is SHARED with TriggerRegistry and owned by the caller
19
+ * (start.ts opens and closes it once) - deliberately no close() here.
20
+ */
21
+ import type { SQLiteDatabase } from '../sqlite.js';
22
+ import type { OperatorTask, TaskSource } from './operator-interfaces.js';
23
+ export declare const TASK_STATUSES: readonly ["pending", "in_progress", "review", "blocked", "done", "cancelled"];
24
+ export type TaskStatus = (typeof TASK_STATUSES)[number];
25
+ export declare const TASK_PRIORITIES: readonly ["high", "normal", "low"];
26
+ export type TaskPriority = (typeof TASK_PRIORITIES)[number];
27
+ /** Extended record: satisfies OperatorTask (numeric deadline) and carries the ISO original. */
28
+ export interface TaskRecord extends OperatorTask {
29
+ status: TaskStatus;
30
+ priority: TaskPriority;
31
+ /** ISO YYYY-MM-DD as stored; `deadline` (OperatorTask) is its UTC-midnight epoch ms. */
32
+ deadlineIso: string | null;
33
+ assignee: string | null;
34
+ sourceChannel: string | null;
35
+ sourceEventId: string | null;
36
+ latestEvent: string | null;
37
+ autoCreated: boolean;
38
+ confirmed: boolean;
39
+ }
40
+ export interface CreateTaskInput {
41
+ title: string;
42
+ status?: TaskStatus;
43
+ priority?: TaskPriority;
44
+ assignee?: string;
45
+ /** ISO YYYY-MM-DD */
46
+ deadline?: string;
47
+ /** channelKey: "<connector>:<channelId>" */
48
+ source_channel?: string;
49
+ /** Idempotency key from the connector event; duplicate (channel, event) UPSERTS. */
50
+ source_event_id?: string;
51
+ latest_event?: string;
52
+ confirmed?: boolean;
53
+ }
54
+ export interface UpdateTaskInput {
55
+ status?: TaskStatus;
56
+ priority?: TaskPriority;
57
+ assignee?: string | null;
58
+ deadline?: string | null;
59
+ latest_event?: string;
60
+ confirmed?: boolean;
61
+ title?: string;
62
+ }
63
+ export interface ListTasksFilter {
64
+ status?: TaskStatus;
65
+ channel?: string;
66
+ search?: string;
67
+ limit?: number;
68
+ /** 'deadline_priority' = deadline asc NULLS LAST, then high>normal>low, then id. */
69
+ order?: 'deadline_priority' | 'updated';
70
+ }
71
+ export declare class TaskLedger implements TaskSource {
72
+ private db;
73
+ constructor(db: SQLiteDatabase);
74
+ private runMigration;
75
+ /** TaskSource conformance: open items in canonical board order. */
76
+ getTasks(): OperatorTask[];
77
+ countOpenUnconfirmed(): number;
78
+ list(filter?: ListTasksFilter): TaskRecord[];
79
+ getById(id: number): TaskRecord | null;
80
+ /**
81
+ * Create a task. Idempotent under at-least-once delivery: a duplicate
82
+ * (source_channel, source_event_id) UPSERTS - the existing row gets the new
83
+ * latest_event (and title stays) instead of a near-duplicate row appearing.
84
+ */
85
+ create(input: CreateTaskInput): TaskRecord;
86
+ update(id: number, patch: UpdateTaskInput): TaskRecord;
87
+ /** Stable hash over ordered rows - the Phase-2 verifier's ledger snapshot. */
88
+ payloadHash(): string;
89
+ /** contract_no_update: silence as a verifiable judgment, scoped to one reconcile run. */
90
+ recordNoUpdate(scope: string, reason: string): {
91
+ id: number;
92
+ };
93
+ /** Max no-update note id, optionally scoped - the verifier's note snapshot. */
94
+ maxNoUpdateId(scope?: string): number;
95
+ }
96
+ //# sourceMappingURL=task-ledger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"task-ledger.d.ts","sourceRoot":"","sources":["../../src/operator/task-ledger.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAGH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAEzE,eAAO,MAAM,aAAa,+EAOhB,CAAC;AACX,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,CAAC,CAAC;AAExD,eAAO,MAAM,eAAe,oCAAqC,CAAC;AAClE,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,eAAe,CAAC,CAAC,MAAM,CAAC,CAAC;AAE5D,+FAA+F;AAC/F,MAAM,WAAW,UAAW,SAAQ,YAAY;IAC9C,MAAM,EAAE,UAAU,CAAC;IACnB,QAAQ,EAAE,YAAY,CAAC;IACvB,wFAAwF;IACxF,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,WAAW,EAAE,OAAO,CAAC;IACrB,SAAS,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW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AAI;IAOtC;;;;OAIG;IACH,MAAM,CAAC,KAAK,EAAE,eAAe,GAAG,UAAU;IAqD1C,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,eAAe,GAAG,UAAU;IA8BtD,8EAA8E;IAC9E,WAAW,IAAI,MAAM;IAWrB,yFAAyF;IACzF,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE;IAU7D,+EAA+E;IAC/E,aAAa,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM;CAUtC"}
@@ -0,0 +1,277 @@
1
+ "use strict";
2
+ /**
3
+ * TaskLedger - the operator-owned native work-item ledger (M8 Task 0.1).
4
+ *
5
+ * Ports the SHAPE of Kagemusha's proven task store (11 columns: id/title/status/
6
+ * priority/deadline/source/auto_created/confirmed/timestamps) plus `assignee`
7
+ * and an idempotency key. Implements the pre-existing `TaskSource` interface
8
+ * (operator-interfaces.ts) so the board projects ONE task model, not two.
9
+ *
10
+ * Reconcile runs create/update rows through the task_create/task_update gateway
11
+ * tools; the pipeline board slot is a projection of `list({order:
12
+ * 'deadline_priority'})`. The AGENT makes every judgment about what becomes a
13
+ * task; this store only persists.
14
+ *
15
+ * Schema-extension note: CREATE TABLE IF NOT EXISTS is a no-op on existing
16
+ * tables. Any post-ship column addition needs an explicit ALTER TABLE guarded
17
+ * by a PRAGMA table_info check, added to runMigration().
18
+ *
19
+ * The db handle is SHARED with TriggerRegistry and owned by the caller
20
+ * (start.ts opens and closes it once) - deliberately no close() here.
21
+ */
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ exports.TaskLedger = exports.TASK_PRIORITIES = exports.TASK_STATUSES = void 0;
24
+ const node_crypto_1 = require("node:crypto");
25
+ exports.TASK_STATUSES = [
26
+ 'pending',
27
+ 'in_progress',
28
+ 'review',
29
+ 'blocked',
30
+ 'done',
31
+ 'cancelled',
32
+ ];
33
+ exports.TASK_PRIORITIES = ['high', 'normal', 'low'];
34
+ const ISO_DATE_PATTERN = /^\d{4}-\d{2}-\d{2}$/;
35
+ function isoToEpochMs(iso) {
36
+ if (!iso)
37
+ return null;
38
+ const ms = Date.parse(`${iso}T00:00:00Z`);
39
+ return Number.isNaN(ms) ? null : ms;
40
+ }
41
+ function assertEnum(value, allowed, field) {
42
+ if (!allowed.includes(value)) {
43
+ throw new Error(`${field} must be one of ${allowed.join('|')}, got: ${value}`);
44
+ }
45
+ }
46
+ function assertIsoDate(value, field) {
47
+ const match = ISO_DATE_PATTERN.exec(value);
48
+ if (!match) {
49
+ throw new Error(`${field} must be an ISO date (YYYY-MM-DD), got: ${value}`);
50
+ }
51
+ const [year, month, day] = value.split('-').map(Number);
52
+ const date = new Date(Date.UTC(year, month - 1, day));
53
+ const isRoundTrip = date.getUTCFullYear() === year && date.getUTCMonth() === month - 1 && date.getUTCDate() === day;
54
+ if (!isRoundTrip) {
55
+ throw new Error(`${field} must be an ISO date (YYYY-MM-DD), got: ${value}`);
56
+ }
57
+ }
58
+ function rowToRecord(row) {
59
+ return {
60
+ id: row.id,
61
+ title: row.title,
62
+ status: row.status,
63
+ priority: row.priority,
64
+ deadline: isoToEpochMs(row.deadline),
65
+ deadlineIso: row.deadline,
66
+ assignee: row.assignee,
67
+ sourceChannel: row.source_channel,
68
+ sourceEventId: row.source_event_id,
69
+ latestEvent: row.latest_event,
70
+ autoCreated: row.auto_created === 1,
71
+ confirmed: row.confirmed === 1,
72
+ createdAt: row.created_at,
73
+ updatedAt: row.updated_at,
74
+ };
75
+ }
76
+ class TaskLedger {
77
+ db;
78
+ constructor(db) {
79
+ this.db = db;
80
+ this.runMigration();
81
+ }
82
+ runMigration() {
83
+ this.db.exec(`
84
+ CREATE TABLE IF NOT EXISTS operator_tasks (
85
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
86
+ title TEXT NOT NULL,
87
+ status TEXT NOT NULL DEFAULT 'pending'
88
+ CHECK (status IN ('pending','in_progress','review','blocked','done','cancelled')),
89
+ priority TEXT NOT NULL DEFAULT 'normal' CHECK (priority IN ('high','normal','low')),
90
+ assignee TEXT,
91
+ deadline TEXT,
92
+ source_channel TEXT,
93
+ source_event_id TEXT,
94
+ latest_event TEXT,
95
+ auto_created INTEGER NOT NULL DEFAULT 1,
96
+ confirmed INTEGER NOT NULL DEFAULT 0,
97
+ created_at INTEGER NOT NULL,
98
+ updated_at INTEGER NOT NULL
99
+ );
100
+ CREATE UNIQUE INDEX IF NOT EXISTS idx_operator_tasks_source
101
+ ON operator_tasks(source_channel, source_event_id)
102
+ WHERE source_event_id IS NOT NULL;
103
+ CREATE INDEX IF NOT EXISTS idx_operator_tasks_status ON operator_tasks(status);
104
+ CREATE INDEX IF NOT EXISTS idx_operator_tasks_deadline ON operator_tasks(deadline);
105
+
106
+ CREATE TABLE IF NOT EXISTS operator_no_update_notes (
107
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
108
+ scope TEXT NOT NULL,
109
+ reason TEXT NOT NULL,
110
+ created_at INTEGER NOT NULL
111
+ );
112
+ CREATE INDEX IF NOT EXISTS idx_operator_no_update_scope
113
+ ON operator_no_update_notes(scope, id);
114
+ `);
115
+ }
116
+ /** TaskSource conformance: open items in canonical board order. */
117
+ getTasks() {
118
+ return this.list({ order: 'deadline_priority' });
119
+ }
120
+ countOpenUnconfirmed() {
121
+ const row = this.db
122
+ .prepare(`SELECT COUNT(*) AS count
123
+ FROM operator_tasks
124
+ WHERE auto_created = 1
125
+ AND confirmed = 0
126
+ AND status NOT IN ('done', 'cancelled')`)
127
+ .get();
128
+ return row.count;
129
+ }
130
+ list(filter = {}) {
131
+ const where = [];
132
+ const params = [];
133
+ if (filter.status) {
134
+ where.push('status = ?');
135
+ params.push(filter.status);
136
+ }
137
+ if (filter.channel) {
138
+ where.push('source_channel = ?');
139
+ params.push(filter.channel);
140
+ }
141
+ if (filter.search) {
142
+ where.push('(title LIKE ? OR latest_event LIKE ? OR assignee LIKE ?)');
143
+ const like = `%${filter.search}%`;
144
+ params.push(like, like, like);
145
+ }
146
+ const order = filter.order === 'updated'
147
+ ? 'updated_at DESC, id DESC'
148
+ : // deadline asc NULLS LAST, then priority high>normal>low, then id.
149
+ // LIMIT applies AFTER ordering so the true top-N is returned.
150
+ `CASE WHEN deadline IS NULL THEN 1 ELSE 0 END ASC, deadline ASC,
151
+ CASE priority WHEN 'high' THEN 0 WHEN 'normal' THEN 1 ELSE 2 END ASC, id ASC`;
152
+ const rawLimit = Number(filter.limit);
153
+ const limit = Number.isFinite(rawLimit) ? Math.max(1, Math.min(200, Math.floor(rawLimit))) : 50;
154
+ const rows = this.db
155
+ .prepare(`SELECT * FROM operator_tasks
156
+ ${where.length > 0 ? `WHERE ${where.join(' AND ')}` : ''}
157
+ ORDER BY ${order}
158
+ LIMIT ?`)
159
+ .all(...params, limit);
160
+ return rows.map(rowToRecord);
161
+ }
162
+ getById(id) {
163
+ const row = this.db.prepare(`SELECT * FROM operator_tasks WHERE id = ?`).get(id);
164
+ return row ? rowToRecord(row) : null;
165
+ }
166
+ /**
167
+ * Create a task. Idempotent under at-least-once delivery: a duplicate
168
+ * (source_channel, source_event_id) UPSERTS - the existing row gets the new
169
+ * latest_event (and title stays) instead of a near-duplicate row appearing.
170
+ */
171
+ create(input) {
172
+ if (!input.title || input.title.trim() === '') {
173
+ throw new Error('task title must be a non-empty string');
174
+ }
175
+ if (input.status !== undefined)
176
+ assertEnum(input.status, exports.TASK_STATUSES, 'status');
177
+ if (input.priority !== undefined)
178
+ assertEnum(input.priority, exports.TASK_PRIORITIES, 'priority');
179
+ if (input.deadline !== undefined)
180
+ assertIsoDate(input.deadline, 'deadline');
181
+ const now = Date.now();
182
+ if (input.source_channel && input.source_event_id) {
183
+ const existing = this.db
184
+ .prepare(`SELECT * FROM operator_tasks WHERE source_channel = ? AND source_event_id = ?`)
185
+ .get(input.source_channel, input.source_event_id);
186
+ if (existing) {
187
+ // Upsert carries every provided field EXCEPT title (the original naming
188
+ // stays stable across retries; movement and state updates flow through).
189
+ return this.update(existing.id, {
190
+ ...(input.status !== undefined ? { status: input.status } : {}),
191
+ ...(input.priority !== undefined ? { priority: input.priority } : {}),
192
+ ...(input.assignee !== undefined ? { assignee: input.assignee } : {}),
193
+ ...(input.deadline !== undefined ? { deadline: input.deadline } : {}),
194
+ ...(input.confirmed !== undefined ? { confirmed: input.confirmed } : {}),
195
+ ...(input.latest_event !== undefined ? { latest_event: input.latest_event } : {}),
196
+ });
197
+ }
198
+ }
199
+ const result = this.db
200
+ .prepare(`INSERT INTO operator_tasks
201
+ (title, status, priority, assignee, deadline, source_channel, source_event_id,
202
+ latest_event, auto_created, confirmed, created_at, updated_at)
203
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
204
+ .run(input.title.trim(), input.status ?? 'pending', input.priority ?? 'normal', input.assignee ?? null, input.deadline ?? null, input.source_channel ?? null, input.source_event_id ?? null, input.latest_event ?? null, 1, input.confirmed ? 1 : 0, now, now);
205
+ const created = this.getById(Number(result.lastInsertRowid));
206
+ if (!created)
207
+ throw new Error('task_create: inserted row could not be read back');
208
+ return created;
209
+ }
210
+ update(id, patch) {
211
+ const existing = this.getById(id);
212
+ if (!existing)
213
+ throw new Error(`task_update: no task with id ${id}`);
214
+ if (patch.status !== undefined)
215
+ assertEnum(patch.status, exports.TASK_STATUSES, 'status');
216
+ if (patch.priority !== undefined)
217
+ assertEnum(patch.priority, exports.TASK_PRIORITIES, 'priority');
218
+ if (patch.deadline !== undefined && patch.deadline !== null) {
219
+ assertIsoDate(patch.deadline, 'deadline');
220
+ }
221
+ if (patch.title !== undefined && patch.title.trim() === '') {
222
+ throw new Error('task title must be a non-empty string');
223
+ }
224
+ const sets = ['updated_at = ?'];
225
+ const params = [Date.now()];
226
+ const assign = (column, value) => {
227
+ sets.push(`${column} = ?`);
228
+ params.push(value);
229
+ };
230
+ if (patch.title !== undefined)
231
+ assign('title', patch.title.trim());
232
+ if (patch.status !== undefined)
233
+ assign('status', patch.status);
234
+ if (patch.priority !== undefined)
235
+ assign('priority', patch.priority);
236
+ if (patch.assignee !== undefined)
237
+ assign('assignee', patch.assignee);
238
+ if (patch.deadline !== undefined)
239
+ assign('deadline', patch.deadline);
240
+ if (patch.latest_event !== undefined)
241
+ assign('latest_event', patch.latest_event);
242
+ if (patch.confirmed !== undefined)
243
+ assign('confirmed', patch.confirmed ? 1 : 0);
244
+ this.db.prepare(`UPDATE operator_tasks SET ${sets.join(', ')} WHERE id = ?`).run(...params, id);
245
+ return this.getById(id);
246
+ }
247
+ /** Stable hash over ordered rows - the Phase-2 verifier's ledger snapshot. */
248
+ payloadHash() {
249
+ const rows = this.db
250
+ .prepare(`SELECT id, title, status, priority, assignee, deadline, latest_event, confirmed,
251
+ updated_at
252
+ FROM operator_tasks ORDER BY id ASC`)
253
+ .all();
254
+ return (0, node_crypto_1.createHash)('sha256').update(JSON.stringify(rows)).digest('hex');
255
+ }
256
+ /** contract_no_update: silence as a verifiable judgment, scoped to one reconcile run. */
257
+ recordNoUpdate(scope, reason) {
258
+ if (!scope || !reason) {
259
+ throw new Error('contract_no_update requires both scope and reason');
260
+ }
261
+ const result = this.db
262
+ .prepare(`INSERT INTO operator_no_update_notes (scope, reason, created_at) VALUES (?, ?, ?)`)
263
+ .run(scope, reason, Date.now());
264
+ return { id: Number(result.lastInsertRowid) };
265
+ }
266
+ /** Max no-update note id, optionally scoped - the verifier's note snapshot. */
267
+ maxNoUpdateId(scope) {
268
+ const row = (scope
269
+ ? this.db
270
+ .prepare(`SELECT MAX(id) AS max_id FROM operator_no_update_notes WHERE scope = ?`)
271
+ .get(scope)
272
+ : this.db.prepare(`SELECT MAX(id) AS max_id FROM operator_no_update_notes`).get());
273
+ return row.max_id ?? 0;
274
+ }
275
+ }
276
+ exports.TaskLedger = TaskLedger;
277
+ //# sourceMappingURL=task-ledger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"task-ledger.js","sourceRoot":"","sources":["../../src/operator/task-ledger.ts"],"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