@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,141 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OPERATOR_REPORT_SESSION_KEY = void 0;
4
+ exports.summarizeReportToolUse = summarizeReportToolUse;
5
+ exports.formatReportToolAudit = formatReportToolAudit;
6
+ exports.createPersonaReportAsk = createPersonaReportAsk;
7
+ /** Dedicated persona session lane for operator reports; isolates the multi-turn gather loop from
8
+ * chat. runWithContent honors options.sessionKey (agent-loop.ts:879). */
9
+ exports.OPERATOR_REPORT_SESSION_KEY = 'operator:report';
10
+ /** Gateway READ tools the full report is instructed to gather with (gateway-tools.md:12,14,22-25). */
11
+ const GATHER_TOOLS = new Set([
12
+ 'kagemusha_overview',
13
+ 'kagemusha_entities',
14
+ 'kagemusha_tasks',
15
+ 'kagemusha_messages',
16
+ 'mama_recall',
17
+ 'mama_search',
18
+ 'context_compile',
19
+ ]);
20
+ /** Gateway WRITE tools. mama_save is the M3 hand; the rest are classified only for honest
21
+ * observability if they ever appear (report_publish/wiki_publish are NOT instructed in M3 -
22
+ * see plan finding F6). (gateway-tools.md:11,17,18,65,66) */
23
+ const WRITE_TOOLS = new Set([
24
+ 'mama_save',
25
+ 'mama_add',
26
+ 'mama_ingest',
27
+ 'report_publish',
28
+ 'wiki_publish',
29
+ ]);
30
+ /** True when a tool_result proves the call did NOT execute: errored, or denied by the envelope
31
+ * layer with {"success":false,...,"code":"envelope_missing"} (gateway-tool-executor.ts:1090-1142).
32
+ * The gateway loop serializes the tool-result OBJECT as the content (JSON.stringify in
33
+ * executeTools), so parse and inspect the ROOT properties first - a substring regex alone
34
+ * false-positives on a SUCCESSFUL result whose nested payload merely mentions
35
+ * '"success":false' (PR #119 review). The substring heuristic remains only as the
36
+ * conservative fallback for unparseable content. */
37
+ function isErroredOrDenied(block) {
38
+ if (block.is_error === true) {
39
+ return true;
40
+ }
41
+ const body = typeof block.content === 'string' ? block.content : JSON.stringify(block.content ?? '');
42
+ try {
43
+ const parsed = JSON.parse(body);
44
+ if (typeof parsed === 'object' && parsed !== null && !Array.isArray(parsed)) {
45
+ const root = parsed;
46
+ return root.success === false || root.code === 'envelope_missing';
47
+ }
48
+ }
49
+ catch {
50
+ // Not JSON - fall through to the conservative substring heuristic.
51
+ }
52
+ return /"success"\s*:\s*false/.test(body) || body.includes('envelope_missing');
53
+ }
54
+ /** Pair assistant tool_use blocks with their tool_result and classify EXECUTIONS as gather vs
55
+ * write. `all` inventories every emission (executed or not) for honest logging. */
56
+ function summarizeReportToolUse(history) {
57
+ // Pass 1: index result health by tool_use_id (results live in the user messages the agent loop
58
+ // pushes after each tool batch - agent-loop.ts:1408-1411).
59
+ const resultOkById = new Map();
60
+ for (const msg of history) {
61
+ if (!msg || msg.role !== 'user' || !Array.isArray(msg.content))
62
+ continue;
63
+ for (const block of msg.content) {
64
+ if (!block || block.type !== 'tool_result' || typeof block.tool_use_id !== 'string')
65
+ continue;
66
+ resultOkById.set(block.tool_use_id, !isErroredOrDenied(block));
67
+ }
68
+ }
69
+ // Pass 2: classify assistant tool_use blocks; only a paired healthy result counts as executed.
70
+ const gatherTools = [];
71
+ const writeTools = [];
72
+ const all = [];
73
+ for (const msg of history) {
74
+ if (!msg || msg.role !== 'assistant' || !Array.isArray(msg.content))
75
+ continue;
76
+ for (const block of msg.content) {
77
+ if (!block || block.type !== 'tool_use' || typeof block.name !== 'string')
78
+ continue;
79
+ all.push(block.name);
80
+ const executed = typeof block.id === 'string' && resultOkById.get(block.id) === true;
81
+ if (!executed)
82
+ continue;
83
+ if (GATHER_TOOLS.has(block.name))
84
+ gatherTools.push(block.name);
85
+ else if (WRITE_TOOLS.has(block.name))
86
+ writeTools.push(block.name);
87
+ }
88
+ }
89
+ return { gatherTools, writeTools, all };
90
+ }
91
+ function uniq(names) {
92
+ return [...new Set(names)];
93
+ }
94
+ /**
95
+ * Build the operator-log lines for one report.
96
+ * isFullReport gates the no-fallback gather WARNING (only the FULL report is instructed to gather;
97
+ * the digest is intentionally tool-free, so absence of gather tools there is normal).
98
+ */
99
+ function formatReportToolAudit(audit, isFullReport) {
100
+ const lines = [];
101
+ if (audit.writeTools.length > 0) {
102
+ lines.push(`[trigger-loop] full report: agent wrote via ${uniq(audit.writeTools).join(', ')}`);
103
+ }
104
+ if (isFullReport) {
105
+ if (audit.gatherTools.length === 0) {
106
+ lines.push('[trigger-loop] full report WARNING: agent executed NO gateway gather tools ' +
107
+ '(none called, or every call errored/denied) - task-board substance NOT verified; ' +
108
+ 'the report may reflect native-tool, denied, or window-only gathering');
109
+ }
110
+ else {
111
+ lines.push(`[trigger-loop] full report: agent gathered via ${uniq(audit.gatherTools).join(', ')}`);
112
+ }
113
+ }
114
+ return lines;
115
+ }
116
+ /**
117
+ * Build the report-composition AskAgent (M3). Envelope-first: gateway 'model_tool' executions are
118
+ * envelope-gated (gateway-tool-executor.ts:252-256), so issue the per-report scoped envelope
119
+ * BEFORE running - without one every call is denied with code 'envelope_missing' (:1090-1142),
120
+ * the enforcement that killed the ancestor scheduled-report path. Issuance failure propagates
121
+ * loudly (no-fallback; the buffer is kept and the next cadence retries). Then run the persona
122
+ * agent (injected runner isolates the report into its own session lane and carries the envelope),
123
+ * audit + log the gateway tools it actually EXECUTED (no-fallback WARNING when a full report
124
+ * executed none; observability line for every write), and enforce the empty-report guard
125
+ * (M2 semantics).
126
+ */
127
+ function createPersonaReportAsk(deps) {
128
+ return async (prompt) => {
129
+ const envelope = deps.issueEnvelope ? await deps.issueEnvelope() : undefined;
130
+ const { response, history } = await deps.run(prompt, envelope);
131
+ const isFull = prompt.includes(deps.fullReportTag);
132
+ for (const line of formatReportToolAudit(summarizeReportToolUse(history), isFull)) {
133
+ deps.log(line);
134
+ }
135
+ if (!response || response.trim() === '') {
136
+ throw new Error('persona agent returned an empty report response');
137
+ }
138
+ return response;
139
+ };
140
+ }
141
+ //# sourceMappingURL=report-run.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"report-run.js","sourceRoot":"","sources":["../../src/operator/report-run.ts"],"names":[],"mappings":";;;AAuFA,wDAkCC;AAWD,sDAmBC;AAoCD,wDAaC;AAnLD;0EAC0E;AAC7D,QAAA,2BAA2B,GAAG,iBAAiB,CAAC;AAE7D,sGAAsG;AACtG,MAAM,YAAY,GAAG,IAAI,GAAG,CAAS;IACnC,oBAAoB;IACpB,oBAAoB;IACpB,iBAAiB;IACjB,oBAAoB;IACpB,aAAa;IACb,aAAa;IACb,iBAAiB;CAClB,CAAC,CAAC;AAEH;;8DAE8D;AAC9D,MAAM,WAAW,GAAG,IAAI,GAAG,CAAS;IAClC,WAAW;IACX,UAAU;IACV,aAAa;IACb,gBAAgB;IAChB,cAAc;CACf,CAAC,CAAC;AAeH;;;;;;qDAMqD;AACrD,SAAS,iBAAiB,CAAC,KAAgD;IACzE,IAAI,KAAK,CAAC,QAAQ,KAAK,IAAI,EAAE,CAAC;QAC5B,OAAO,IAAI,CAAC;IACd,CAAC;IACD,MAAM,IAAI,GACR,OAAO,KAAK,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC;IAC1F,IAAI,CAAC;QACH,MAAM,MAAM,GAAY,IAAI,CAAC,KAA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1,66 @@
1
+ /** Injectable schedule seam - the loop depends on this, not the concrete class (DI + testability). */
2
+ export interface ReportSchedule {
3
+ shouldFire(now: Date): {
4
+ fire: boolean;
5
+ hourKey: string;
6
+ };
7
+ markFired(hourKey: string): void;
8
+ /** Anchor timestamp (ISO) of the last SUCCESSFUL full report, for delta-scoped gathers. */
9
+ loadLastSuccess(): string | null;
10
+ /** Persist the anchor after a full report is delivered (failures must never advance it). */
11
+ markSuccess(iso: string): void;
12
+ }
13
+ /** Persist/restore the last-fired hour key (so a restart within the same hour does not re-send). */
14
+ export interface ReportScheduleStore {
15
+ load(): string | null;
16
+ save(hourKey: string): void;
17
+ /** Anchor timestamp (ISO) of the last SUCCESSFUL full report; null before the first one. */
18
+ loadLastSuccess(): string | null;
19
+ /** Persist the success anchor (read-modify-write so it never clobbers the fired-hour key). */
20
+ markSuccess(iso: string): void;
21
+ }
22
+ /** Local-time "YYYY-MM-DD:HH" bucket. Two ticks in the same local hour share a key. */
23
+ export declare function hourKeyLocal(now: Date): string;
24
+ /**
25
+ * Parse an env string like "8,13,18" into sorted, deduped LOCAL hours in [0,23].
26
+ * Empty/garbage -> [] (feature off). Ports Kagemusha normalizeFullReportHours
27
+ * (~/project/mama-suite/apps/kagemusha/src/config/ai-config.ts:203) but generic + ASCII, no
28
+ * personal defaults.
29
+ */
30
+ export declare function parseReportHours(raw: string): number[];
31
+ export declare class ReportScheduler implements ReportSchedule {
32
+ private hours;
33
+ private store;
34
+ private lastFiredHourKey;
35
+ constructor(hours: number[], store: ReportScheduleStore);
36
+ /** Pure: does a full report fire at now? Robust to ticks not landing on the hour boundary. */
37
+ shouldFire(now: Date): {
38
+ fire: boolean;
39
+ hourKey: string;
40
+ };
41
+ /** Mark this hour delivered (persist) so we fire once per configured hour, restart-safe. */
42
+ markFired(hourKey: string): void;
43
+ /** Anchor of the last SUCCESSFUL full report (delegates to the store). */
44
+ loadLastSuccess(): string | null;
45
+ /** Persist the success anchor (delegates to the store; called ONLY on a delivered report). */
46
+ markSuccess(iso: string): void;
47
+ }
48
+ /** File-backed store under ~/.mama - mirrors ConnectorDeltaRepo's atomic cursor file. */
49
+ export declare class FileReportScheduleStore implements ReportScheduleStore {
50
+ private path;
51
+ constructor(path: string);
52
+ /**
53
+ * Read-parse the whole state object. MISSING file -> {} (silent, as today). A corrupt/empty
54
+ * or non-object state file is disposable bookkeeping: rather than throw and permanently break
55
+ * the report leg, reset LOUDLY and return {}. Worst case after a reset is one duplicate report
56
+ * plus a wide gather window - both self-heal on the next successful report.
57
+ */
58
+ private readState;
59
+ /** Atomic full-object write (tmp+rename) - callers do read-modify-write to preserve sibling fields. */
60
+ private writeState;
61
+ load(): string | null;
62
+ save(hourKey: string): void;
63
+ loadLastSuccess(): string | null;
64
+ markSuccess(iso: string): void;
65
+ }
66
+ //# sourceMappingURL=report-scheduler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"report-scheduler.d.ts","sourceRoot":"","sources":["../../src/operator/report-scheduler.ts"],"names":[],"mappings":"AAeA,sGAAsG;AACtG,MAAM,WAAW,cAAc;IAC7B,UAAU,CAAC,GAAG,EAAE,IAAI,GAAG;QAAE,IAAI,EAAE,OAAO,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IAC1D,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,2FAA2F;IAC3F,eAAe,IAAI,MAAM,GAAG,IAAI,CAAC;IACjC,4FAA4F;IAC5F,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC;AAED,oGAAoG;AACpG,MAAM,WAAW,mBAAmB;IAClC,IAAI,IAAI,MAAM,GAAG,IAAI,CAAC;IACtB,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,4FAA4F;IAC5F,eAAe,IAAI,MAAM,GAAG,IAAI,CAAC;IACjC,8FAA8F;IAC9F,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC;AAED,uFAAuF;AACvF,wBAAgB,YAAY,CAAC,GAAG,EAAE,IAAI,GAAG,MAAM,CAG9C;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CAQtD;AAED,qBAAa,eAAgB,YAAW,cAAc;IACpD,OAAO,CAAC,KAAK,CAAW;IACxB,OAAO,CAAC,KAAK,CAAsB;IACnC,OAAO,CAAC,gBAAgB,CAAgB;gBAE5B,KAAK,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,mBAAmB;IAMvD,8FAA8F;IAC9F,UAAU,CAAC,GAAG,EAAE,IAAI,GAAG;QAAE,IAAI,EAAE,OAAO,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE;IAMzD,4FAA4F;IAC5F,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAKhC,0EAA0E;IAC1E,eAAe,IAAI,MAAM,GAAG,IAAI;IAIhC,8FAA8F;IAC9F,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;CAG/B;AAED,yFAAyF;AACzF,qBAAa,uBAAwB,YAAW,mBAAmB;IACjE,OAAO,CAAC,IAAI,CAAS;gBAET,IAAI,EAAE,MAAM;IAIxB;;;;;OAKG;IACH,OAAO,CAAC,SAAS;IAwBjB,uGAAuG;IACvG,OAAO,CAAC,UAAU;IAOlB,IAAI,IAAI,MAAM,GAAG,IAAI;IAKrB,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAS3B,eAAe,IAAI,MAAM,GAAG,IAAI;IAKhC,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;CAU/B"}
@@ -0,0 +1,135 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FileReportScheduleStore = exports.ReportScheduler = void 0;
4
+ exports.hourKeyLocal = hourKeyLocal;
5
+ exports.parseReportHours = parseReportHours;
6
+ /**
7
+ * ReportScheduler - the scheduled full-report cadence (M2-T0).
8
+ *
9
+ * Ports the schedule-firing MECHANISM from Kagemusha AgentAwareness.tickScheduledReports
10
+ * (~/project/mama-suite/apps/kagemusha/src/runtime/agent-awareness.ts:1371 + buildHourKey:1483):
11
+ * fire once when the current hour is one of the configured hours and this hour has not been fired
12
+ * yet. Kagemusha keys on Asia/Seoul; MAMA uses LOCAL hours (Date.getHours) per the M2 brief - the
13
+ * owner timezone stays a runtime property, never a source constant.
14
+ *
15
+ * Pure decision (shouldFire) + a persisted last-fired hour key (survives restart -> no
16
+ * double-send). NO personal data: the hours are injected from env/config, never hardcoded here.
17
+ */
18
+ const node_fs_1 = require("node:fs");
19
+ const node_path_1 = require("node:path");
20
+ /** Local-time "YYYY-MM-DD:HH" bucket. Two ticks in the same local hour share a key. */
21
+ function hourKeyLocal(now) {
22
+ const pad = (n) => String(n).padStart(2, '0');
23
+ return `${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())}:${pad(now.getHours())}`;
24
+ }
25
+ /**
26
+ * Parse an env string like "8,13,18" into sorted, deduped LOCAL hours in [0,23].
27
+ * Empty/garbage -> [] (feature off). Ports Kagemusha normalizeFullReportHours
28
+ * (~/project/mama-suite/apps/kagemusha/src/config/ai-config.ts:203) but generic + ASCII, no
29
+ * personal defaults.
30
+ */
31
+ function parseReportHours(raw) {
32
+ const hours = raw
33
+ .split(',')
34
+ .map((part) => part.trim())
35
+ .filter((part) => part !== '') // drop empty tokens BEFORE Number(): Number('') === 0 would sneak in hour 0
36
+ .map(Number)
37
+ .filter((n) => Number.isInteger(n) && n >= 0 && n <= 23);
38
+ return [...new Set(hours)].sort((a, b) => a - b);
39
+ }
40
+ class ReportScheduler {
41
+ hours;
42
+ store;
43
+ lastFiredHourKey;
44
+ constructor(hours, store) {
45
+ this.hours = hours;
46
+ this.store = store;
47
+ this.lastFiredHourKey = store.load(); // restore across restart
48
+ }
49
+ /** Pure: does a full report fire at now? Robust to ticks not landing on the hour boundary. */
50
+ shouldFire(now) {
51
+ const hourKey = hourKeyLocal(now);
52
+ const fire = this.hours.includes(now.getHours()) && this.lastFiredHourKey !== hourKey;
53
+ return { fire, hourKey };
54
+ }
55
+ /** Mark this hour delivered (persist) so we fire once per configured hour, restart-safe. */
56
+ markFired(hourKey) {
57
+ this.lastFiredHourKey = hourKey;
58
+ this.store.save(hourKey);
59
+ }
60
+ /** Anchor of the last SUCCESSFUL full report (delegates to the store). */
61
+ loadLastSuccess() {
62
+ return this.store.loadLastSuccess();
63
+ }
64
+ /** Persist the success anchor (delegates to the store; called ONLY on a delivered report). */
65
+ markSuccess(iso) {
66
+ this.store.markSuccess(iso);
67
+ }
68
+ }
69
+ exports.ReportScheduler = ReportScheduler;
70
+ /** File-backed store under ~/.mama - mirrors ConnectorDeltaRepo's atomic cursor file. */
71
+ class FileReportScheduleStore {
72
+ path;
73
+ constructor(path) {
74
+ this.path = path;
75
+ }
76
+ /**
77
+ * Read-parse the whole state object. MISSING file -> {} (silent, as today). A corrupt/empty
78
+ * or non-object state file is disposable bookkeeping: rather than throw and permanently break
79
+ * the report leg, reset LOUDLY and return {}. Worst case after a reset is one duplicate report
80
+ * plus a wide gather window - both self-heal on the next successful report.
81
+ */
82
+ readState() {
83
+ if (!(0, node_fs_1.existsSync)(this.path)) {
84
+ return {};
85
+ }
86
+ let parsed;
87
+ try {
88
+ parsed = JSON.parse((0, node_fs_1.readFileSync)(this.path, 'utf8'));
89
+ }
90
+ catch (error) {
91
+ console.error('[report-scheduler] state file corrupt or unreadable - resetting schedule state:', error);
92
+ return {};
93
+ }
94
+ if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {
95
+ console.error('[report-scheduler] state file corrupt or unreadable - resetting schedule state:', `not a plain object: ${this.path}`);
96
+ return {};
97
+ }
98
+ return parsed;
99
+ }
100
+ /** Atomic full-object write (tmp+rename) - callers do read-modify-write to preserve sibling fields. */
101
+ writeState(state) {
102
+ (0, node_fs_1.mkdirSync)((0, node_path_1.dirname)(this.path), { recursive: true });
103
+ const tmp = (0, node_path_1.join)((0, node_path_1.dirname)(this.path), `.report-schedule.${process.pid}.tmp`);
104
+ (0, node_fs_1.writeFileSync)(tmp, JSON.stringify(state), 'utf8');
105
+ (0, node_fs_1.renameSync)(tmp, this.path); // atomic replace
106
+ }
107
+ load() {
108
+ const key = this.readState().lastFiredHourKey;
109
+ return typeof key === 'string' ? key : null;
110
+ }
111
+ save(hourKey) {
112
+ // Read-modify-write: markFired must NOT clobber the success anchor.
113
+ const state = this.readState();
114
+ this.writeState({
115
+ lastFiredHourKey: hourKey,
116
+ ...(typeof state.lastSuccessIso === 'string' ? { lastSuccessIso: state.lastSuccessIso } : {}),
117
+ });
118
+ }
119
+ loadLastSuccess() {
120
+ const iso = this.readState().lastSuccessIso;
121
+ return typeof iso === 'string' ? iso : null;
122
+ }
123
+ markSuccess(iso) {
124
+ // Read-modify-write: advancing the anchor must NOT clobber the fired-hour key.
125
+ const state = this.readState();
126
+ this.writeState({
127
+ ...(typeof state.lastFiredHourKey === 'string'
128
+ ? { lastFiredHourKey: state.lastFiredHourKey }
129
+ : {}),
130
+ lastSuccessIso: iso,
131
+ });
132
+ }
133
+ }
134
+ exports.FileReportScheduleStore = FileReportScheduleStore;
135
+ //# sourceMappingURL=report-scheduler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"report-scheduler.js","sourceRoot":"","sources":["../../src/operator/report-scheduler.ts"],"names":[],"mappings":";;;AAoCA,oCAGC;AAQD,4CAQC;AAvDD;;;;;;;;;;;GAWG;AACH,qCAAyF;AACzF,yCAA0C;AAsB1C,uFAAuF;AACvF,SAAgB,YAAY,CAAC,GAAS;IACpC,MAAM,GAAG,GAAG,CAAC,CAAS,EAAU,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IAC9D,OAAO,GAAG,GAAG,CAAC,WAAW,EAAE,IAAI,GAAG,CAAC,GAAG,CAAC,QAAQ,EAAE,G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CAAC;IAED,WAAW,CAAC,GAAW;QACrB,+EAA+E;QAC/E,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;QAC/B,IAAI,CAAC,UAAU,CAAC;YACd,GAAG,CAAC,OAAO,KAAK,CAAC,gBAAgB,KAAK,QAAQ;gBAC5C,CAAC,CAAC,EAAE,gBAAgB,EAAE,KAAK,CAAC,gBAAgB,EAAE;gBAC9C,CAAC,CAAC,EAAE,CAAC;YACP,cAAc,EAAE,GAAG;SACpB,CAAC,CAAC;IACL,CAAC;CACF;AA1ED,0DA0EC"}
@@ -0,0 +1,90 @@
1
+ /**
2
+ * SituationReporter - the OUTPUT leg of the trigger loop (M2), superseding TriggerReporter (M1.5).
3
+ *
4
+ * Accumulates a BOUNDED window of drained events (per-channel counts + last-K excerpts), plus
5
+ * fire/author activity and the memory those fires recalled (agent-authored memoryQuery drove the
6
+ * recall - trigger-fire.ts:33-34). On a report cadence the AGENT composes an owner situation
7
+ * report from the AGGREGATE (agent-first: the agent judges content and may reply NOTHING to
8
+ * suppress); the system only windows/schedules/sends.
9
+ *
10
+ * Two framings share one accumulator + send machinery:
11
+ * - 'digest': the short periodic update (the M1.5 fire digest, now window-aware).
12
+ * - 'full' : the fuller scheduled report covering the whole window since the last full report.
13
+ *
14
+ * No activity -> no agent call, no send (no spam). Send failure propagates loudly (no-fallback)
15
+ * and keeps the buffer so the next cadence retries. English default; the agent is told to answer
16
+ * in the owner's language if inferable. NO personal strings in this source.
17
+ */
18
+ import type { OperatorChannelEvent, OutputSink } from './operator-interfaces.js';
19
+ import type { AskAgent } from './trigger-author.js';
20
+ /**
21
+ * Machine frame tag prepended to the FULL report prompt so the report-run wiring can tell a full
22
+ * report from a digest for tool-use auditing (report-run.ts). Kagemusha frames its scheduled full
23
+ * report with the same bracketed-tag convention (report-prompts.ts buildFullReportPrompt).
24
+ */
25
+ export declare const OPERATOR_FULL_REPORT_TAG = "[operator_full_report]";
26
+ export interface FireActivity {
27
+ triggerId: string;
28
+ kind: string;
29
+ channelId: string;
30
+ recalled: {
31
+ topic: string;
32
+ content: string;
33
+ }[];
34
+ }
35
+ export type ReportMode = 'digest' | 'full';
36
+ export interface SituationReporterOptions {
37
+ /**
38
+ * M2.3: tool-call instructions injected into the FULL report framing so the agent
39
+ * ACTIVELY gathers current context (channels, tasks, memory) before writing - the
40
+ * lesson from Kagemusha, whose report prompt instructs its agent to call its tools
41
+ * (and which deleted its deterministic report builder for low quality). The lines
42
+ * are injected from the runtime wiring (which knows the daemon's toolset); this
43
+ * module stays generic. Digest mode never uses them (frequent + must stay light).
44
+ *
45
+ * A zero-arg provider is resolved at fire time (buildPrompt runs per report),
46
+ * so runtime wiring can inject freshly anchored gather lines (e.g. a delta
47
+ * `since=<last successful report>`) without rebuilding the reporter.
48
+ */
49
+ selfGatherLines?: string[] | (() => string[]);
50
+ /**
51
+ * Kagemusha dual-output mechanism: lines instructing the FULL report run to also
52
+ * publish the operator board slots (report_publish) before writing the text
53
+ * report. Injected from runtime wiring (board-slot-instructions.ts); digest mode
54
+ * never publishes the board.
55
+ */
56
+ boardPublishLines?: string[];
57
+ /**
58
+ * G2 success signal: called with the trigger ids the agent says it actually
59
+ * drew on for the sent report (parsed from the stripped USED_TRIGGERS
60
+ * trailer, validated against this window's fires). The wiring records
61
+ * 'succeeded' outcomes so evolution finally gets a positive signal instead
62
+ * of being elimination-only. Uncited fires stay NEUTRAL - not failures.
63
+ */
64
+ recordTriggerUse?: (triggerIds: string[]) => void;
65
+ }
66
+ export declare class SituationReporter {
67
+ private windowByChannel;
68
+ private windowTotal;
69
+ private fireAgg;
70
+ private authored;
71
+ private recalled;
72
+ private opts;
73
+ constructor(opts?: SituationReporterOptions);
74
+ /** Fold a batch of drained events into the bounded per-channel window. */
75
+ recordWindow(events: OperatorChannelEvent[]): void;
76
+ /** Fold one fire into the aggregate; merge the memory it recalled (agent-query-driven). */
77
+ recordFire(activity: FireActivity): void;
78
+ recordAuthored(count: number): void;
79
+ /** Any window events, fires, or authored triggers accumulated since the last reset. */
80
+ hasActivity(): boolean;
81
+ /**
82
+ * Agent composes the report from the aggregate; sink delivers it. Returns true if a report was
83
+ * sent, false if there was nothing to say or the agent suppressed it (NOTHING).
84
+ */
85
+ report(askAgent: AskAgent, output: Pick<OutputSink, 'send'>, mode: ReportMode): Promise<boolean>;
86
+ private reset;
87
+ /** Public for testability. Aggregate window + fire activity + recalled memory -> agent prompt. */
88
+ buildPrompt(mode: ReportMode): string;
89
+ }
90
+ //# sourceMappingURL=situation-report.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"situation-report.d.ts","sourceRoot":"","sources":["../../src/operator/situation-report.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,KAAK,EAAE,oBAAoB,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACjF,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAEpD;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,2BAA2B,CAAC;AAEjE,MAAM,WAAW,YAAY;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CAChD;AAED,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,MAAM,CAAC;AAqB3C,MAAM,WAAW,wBAAwB;IACvC;;;;;;;;;;;OAWG;IACH,eAAe,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,MAAM,EAAE,CAAC,CAAC;IAC9C;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC7B;;;;;;OAMG;IACH,gBAAgB,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC;CACnD;AAKD,qBAAa,iBAAiB;IAC5B,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