@jungjaehoon/mama-os 0.22.1 → 0.24.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 (257) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/README.md +3 -1
  3. package/dist/agent/agent-loop.d.ts +3 -9
  4. package/dist/agent/agent-loop.d.ts.map +1 -1
  5. package/dist/agent/agent-loop.js +419 -216
  6. package/dist/agent/agent-loop.js.map +1 -1
  7. package/dist/agent/code-act/constants.d.ts +2 -2
  8. package/dist/agent/code-act/constants.d.ts.map +1 -1
  9. package/dist/agent/code-act/constants.js +16 -9
  10. package/dist/agent/code-act/constants.js.map +1 -1
  11. package/dist/agent/code-act/host-bridge.d.ts +12 -11
  12. package/dist/agent/code-act/host-bridge.d.ts.map +1 -1
  13. package/dist/agent/code-act/host-bridge.js +92 -15
  14. package/dist/agent/code-act/host-bridge.js.map +1 -1
  15. package/dist/agent/code-act/index.d.ts +2 -0
  16. package/dist/agent/code-act/index.d.ts.map +1 -1
  17. package/dist/agent/code-act/index.js +5 -1
  18. package/dist/agent/code-act/index.js.map +1 -1
  19. package/dist/agent/code-act/tool-policy.d.ts +42 -0
  20. package/dist/agent/code-act/tool-policy.d.ts.map +1 -0
  21. package/dist/agent/code-act/tool-policy.js +122 -0
  22. package/dist/agent/code-act/tool-policy.js.map +1 -0
  23. package/dist/agent/code-act/type-definition-generator.d.ts +4 -3
  24. package/dist/agent/code-act/type-definition-generator.d.ts.map +1 -1
  25. package/dist/agent/code-act/type-definition-generator.js +26 -48
  26. package/dist/agent/code-act/type-definition-generator.js.map +1 -1
  27. package/dist/agent/codex-app-server-process.d.ts +116 -0
  28. package/dist/agent/codex-app-server-process.d.ts.map +1 -0
  29. package/dist/agent/codex-app-server-process.js +1382 -0
  30. package/dist/agent/codex-app-server-process.js.map +1 -0
  31. package/dist/agent/codex-home.d.ts +9 -0
  32. package/dist/agent/codex-home.d.ts.map +1 -1
  33. package/dist/agent/codex-home.js +626 -4
  34. package/dist/agent/codex-home.js.map +1 -1
  35. package/dist/agent/codex-thread-registry.d.ts +63 -0
  36. package/dist/agent/codex-thread-registry.d.ts.map +1 -0
  37. package/dist/agent/codex-thread-registry.js +433 -0
  38. package/dist/agent/codex-thread-registry.js.map +1 -0
  39. package/dist/agent/gateway-tool-executor.d.ts +20 -7
  40. package/dist/agent/gateway-tool-executor.d.ts.map +1 -1
  41. package/dist/agent/gateway-tool-executor.js +254 -90
  42. package/dist/agent/gateway-tool-executor.js.map +1 -1
  43. package/dist/agent/gateway-tools.md +10 -5
  44. package/dist/agent/managed-agent-runtime-sync.d.ts.map +1 -1
  45. package/dist/agent/managed-agent-runtime-sync.js +0 -3
  46. package/dist/agent/managed-agent-runtime-sync.js.map +1 -1
  47. package/dist/agent/managed-agent-validation.js +1 -1
  48. package/dist/agent/managed-agent-validation.js.map +1 -1
  49. package/dist/agent/model-runner.d.ts +51 -3
  50. package/dist/agent/model-runner.d.ts.map +1 -1
  51. package/dist/agent/model-runner.js +1 -1
  52. package/dist/agent/model-runner.js.map +1 -1
  53. package/dist/agent/persistent-cli-adapter.d.ts +1 -0
  54. package/dist/agent/persistent-cli-adapter.d.ts.map +1 -1
  55. package/dist/agent/persistent-cli-adapter.js +3 -0
  56. package/dist/agent/persistent-cli-adapter.js.map +1 -1
  57. package/dist/agent/role-manager.d.ts +22 -1
  58. package/dist/agent/role-manager.d.ts.map +1 -1
  59. package/dist/agent/role-manager.js +39 -2
  60. package/dist/agent/role-manager.js.map +1 -1
  61. package/dist/agent/session-pool.d.ts +2 -2
  62. package/dist/agent/session-pool.d.ts.map +1 -1
  63. package/dist/agent/session-pool.js +6 -6
  64. package/dist/agent/session-pool.js.map +1 -1
  65. package/dist/agent/tool-registry.d.ts +14 -0
  66. package/dist/agent/tool-registry.d.ts.map +1 -1
  67. package/dist/agent/tool-registry.js +81 -12
  68. package/dist/agent/tool-registry.js.map +1 -1
  69. package/dist/agent/types.d.ts +49 -7
  70. package/dist/agent/types.d.ts.map +1 -1
  71. package/dist/agent/types.js.map +1 -1
  72. package/dist/api/graph-api.d.ts.map +1 -1
  73. package/dist/api/graph-api.js +62 -40
  74. package/dist/api/graph-api.js.map +1 -1
  75. package/dist/api/operator-tasks-handler.d.ts.map +1 -1
  76. package/dist/api/operator-tasks-handler.js +6 -2
  77. package/dist/api/operator-tasks-handler.js.map +1 -1
  78. package/dist/cli/commands/init.d.ts +1 -1
  79. package/dist/cli/commands/init.d.ts.map +1 -1
  80. package/dist/cli/commands/init.js +22 -14
  81. package/dist/cli/commands/init.js.map +1 -1
  82. package/dist/cli/commands/run.d.ts.map +1 -1
  83. package/dist/cli/commands/run.js +7 -4
  84. package/dist/cli/commands/run.js.map +1 -1
  85. package/dist/cli/commands/start.d.ts +2 -0
  86. package/dist/cli/commands/start.d.ts.map +1 -1
  87. package/dist/cli/commands/start.js +259 -23
  88. package/dist/cli/commands/start.js.map +1 -1
  89. package/dist/cli/commands/status.js +2 -2
  90. package/dist/cli/commands/status.js.map +1 -1
  91. package/dist/cli/config/config-manager.d.ts +0 -5
  92. package/dist/cli/config/config-manager.d.ts.map +1 -1
  93. package/dist/cli/config/config-manager.js +78 -6
  94. package/dist/cli/config/config-manager.js.map +1 -1
  95. package/dist/cli/config/types.d.ts +4 -4
  96. package/dist/cli/config/types.d.ts.map +1 -1
  97. package/dist/cli/config/types.js +36 -0
  98. package/dist/cli/config/types.js.map +1 -1
  99. package/dist/cli/index.js +2 -2
  100. package/dist/cli/index.js.map +1 -1
  101. package/dist/cli/runtime/agent-loop-init.d.ts +1 -1
  102. package/dist/cli/runtime/agent-loop-init.d.ts.map +1 -1
  103. package/dist/cli/runtime/agent-loop-init.js +106 -60
  104. package/dist/cli/runtime/agent-loop-init.js.map +1 -1
  105. package/dist/cli/runtime/api-routes-init.d.ts +3 -0
  106. package/dist/cli/runtime/api-routes-init.d.ts.map +1 -1
  107. package/dist/cli/runtime/api-routes-init.js +226 -51
  108. package/dist/cli/runtime/api-routes-init.js.map +1 -1
  109. package/dist/cli/runtime/connector-init.d.ts.map +1 -1
  110. package/dist/cli/runtime/connector-init.js +13 -17
  111. package/dist/cli/runtime/connector-init.js.map +1 -1
  112. package/dist/cli/runtime/envelope-bootstrap.d.ts.map +1 -1
  113. package/dist/cli/runtime/envelope-bootstrap.js +13 -1
  114. package/dist/cli/runtime/envelope-bootstrap.js.map +1 -1
  115. package/dist/cli/runtime/gateway-init.d.ts +1 -1
  116. package/dist/cli/runtime/gateway-init.d.ts.map +1 -1
  117. package/dist/cli/runtime/gateway-init.js +5 -0
  118. package/dist/cli/runtime/gateway-init.js.map +1 -1
  119. package/dist/cli/runtime/mama-core-init.d.ts +2 -2
  120. package/dist/cli/runtime/mama-core-init.d.ts.map +1 -1
  121. package/dist/cli/runtime/mama-core-init.js +17 -0
  122. package/dist/cli/runtime/mama-core-init.js.map +1 -1
  123. package/dist/cli/runtime/memory-agent-init.d.ts +1 -1
  124. package/dist/cli/runtime/memory-agent-init.d.ts.map +1 -1
  125. package/dist/cli/runtime/memory-agent-init.js +16 -6
  126. package/dist/cli/runtime/memory-agent-init.js.map +1 -1
  127. package/dist/cli/runtime/types.d.ts +4 -26
  128. package/dist/cli/runtime/types.d.ts.map +1 -1
  129. package/dist/cli/runtime/utilities.js +2 -2
  130. package/dist/cli/runtime/utilities.js.map +1 -1
  131. package/dist/connectors/config-loader.d.ts +24 -0
  132. package/dist/connectors/config-loader.d.ts.map +1 -0
  133. package/dist/connectors/config-loader.js +205 -0
  134. package/dist/connectors/config-loader.js.map +1 -0
  135. package/dist/connectors/framework/types.d.ts +2 -0
  136. package/dist/connectors/framework/types.d.ts.map +1 -1
  137. package/dist/connectors/kagemusha/query-tools.js +2 -2
  138. package/dist/connectors/kagemusha/query-tools.js.map +1 -1
  139. package/dist/envelope/reactive-config.d.ts +2 -2
  140. package/dist/envelope/reactive-config.d.ts.map +1 -1
  141. package/dist/envelope/reactive-config.js +36 -4
  142. package/dist/envelope/reactive-config.js.map +1 -1
  143. package/dist/gateways/context-injector.d.ts +2 -1
  144. package/dist/gateways/context-injector.d.ts.map +1 -1
  145. package/dist/gateways/context-injector.js.map +1 -1
  146. package/dist/gateways/message-router.d.ts +19 -1
  147. package/dist/gateways/message-router.d.ts.map +1 -1
  148. package/dist/gateways/message-router.js +179 -24
  149. package/dist/gateways/message-router.js.map +1 -1
  150. package/dist/gateways/telegram.d.ts.map +1 -1
  151. package/dist/gateways/telegram.js +13 -0
  152. package/dist/gateways/telegram.js.map +1 -1
  153. package/dist/gateways/types.d.ts +4 -1
  154. package/dist/gateways/types.d.ts.map +1 -1
  155. package/dist/memory/history-extractor.d.ts +0 -24
  156. package/dist/memory/history-extractor.d.ts.map +1 -1
  157. package/dist/memory/history-extractor.js +0 -132
  158. package/dist/memory/history-extractor.js.map +1 -1
  159. package/dist/memory/save-candidate-extractor.d.ts +3 -0
  160. package/dist/memory/save-candidate-extractor.d.ts.map +1 -1
  161. package/dist/memory/save-candidate-extractor.js +12 -1
  162. package/dist/memory/save-candidate-extractor.js.map +1 -1
  163. package/dist/memory/secret-filter.d.ts +22 -0
  164. package/dist/memory/secret-filter.d.ts.map +1 -0
  165. package/dist/memory/secret-filter.js +77 -0
  166. package/dist/memory/secret-filter.js.map +1 -0
  167. package/dist/multi-agent/agent-process-manager.d.ts +9 -1
  168. package/dist/multi-agent/agent-process-manager.d.ts.map +1 -1
  169. package/dist/multi-agent/agent-process-manager.js +197 -49
  170. package/dist/multi-agent/agent-process-manager.js.map +1 -1
  171. package/dist/multi-agent/multi-agent-base.d.ts.map +1 -1
  172. package/dist/multi-agent/multi-agent-base.js +2 -1
  173. package/dist/multi-agent/multi-agent-base.js.map +1 -1
  174. package/dist/multi-agent/runtime-process.d.ts +18 -15
  175. package/dist/multi-agent/runtime-process.d.ts.map +1 -1
  176. package/dist/multi-agent/runtime-process.js +63 -59
  177. package/dist/multi-agent/runtime-process.js.map +1 -1
  178. package/dist/multi-agent/types.d.ts +13 -7
  179. package/dist/multi-agent/types.d.ts.map +1 -1
  180. package/dist/multi-agent/types.js.map +1 -1
  181. package/dist/multi-agent/workflow-engine.js +3 -3
  182. package/dist/multi-agent/workflow-engine.js.map +1 -1
  183. package/dist/multi-agent/workflow-types.d.ts +2 -2
  184. package/dist/multi-agent/workflow-types.d.ts.map +1 -1
  185. package/dist/observability/code-audit.d.ts +4 -0
  186. package/dist/observability/code-audit.d.ts.map +1 -1
  187. package/dist/observability/code-audit.js +69 -0
  188. package/dist/observability/code-audit.js.map +1 -1
  189. package/dist/operator/briefs.d.ts +26 -0
  190. package/dist/operator/briefs.d.ts.map +1 -0
  191. package/dist/operator/briefs.js +128 -0
  192. package/dist/operator/briefs.js.map +1 -0
  193. package/dist/operator/operator-trigger-loop.d.ts +27 -0
  194. package/dist/operator/operator-trigger-loop.d.ts.map +1 -1
  195. package/dist/operator/operator-trigger-loop.js +72 -12
  196. package/dist/operator/operator-trigger-loop.js.map +1 -1
  197. package/dist/operator/report-carry.d.ts +29 -0
  198. package/dist/operator/report-carry.d.ts.map +1 -0
  199. package/dist/operator/report-carry.js +81 -0
  200. package/dist/operator/report-carry.js.map +1 -0
  201. package/dist/operator/report-run.d.ts +4 -4
  202. package/dist/operator/shadow-capture.d.ts +20 -0
  203. package/dist/operator/shadow-capture.d.ts.map +1 -0
  204. package/dist/operator/shadow-capture.js +34 -0
  205. package/dist/operator/shadow-capture.js.map +1 -0
  206. package/dist/operator/situation-report.d.ts +9 -0
  207. package/dist/operator/situation-report.d.ts.map +1 -1
  208. package/dist/operator/situation-report.js +56 -26
  209. package/dist/operator/situation-report.js.map +1 -1
  210. package/dist/operator/task-ledger.d.ts +90 -2
  211. package/dist/operator/task-ledger.d.ts.map +1 -1
  212. package/dist/operator/task-ledger.js +359 -23
  213. package/dist/operator/task-ledger.js.map +1 -1
  214. package/dist/operator/trigger-author.d.ts +35 -1
  215. package/dist/operator/trigger-author.d.ts.map +1 -1
  216. package/dist/operator/trigger-author.js +73 -10
  217. package/dist/operator/trigger-author.js.map +1 -1
  218. package/dist/operator/worker-run.d.ts +89 -0
  219. package/dist/operator/worker-run.d.ts.map +1 -0
  220. package/dist/operator/worker-run.js +127 -0
  221. package/dist/operator/worker-run.js.map +1 -0
  222. package/dist/operator/workorder-consumer.d.ts +121 -0
  223. package/dist/operator/workorder-consumer.d.ts.map +1 -0
  224. package/dist/operator/workorder-consumer.js +253 -0
  225. package/dist/operator/workorder-consumer.js.map +1 -0
  226. package/dist/operator/workorder-hooks.d.ts +30 -0
  227. package/dist/operator/workorder-hooks.d.ts.map +1 -0
  228. package/dist/operator/workorder-hooks.js +70 -0
  229. package/dist/operator/workorder-hooks.js.map +1 -0
  230. package/dist/operator/workorder-publishers.d.ts +68 -0
  231. package/dist/operator/workorder-publishers.d.ts.map +1 -0
  232. package/dist/operator/workorder-publishers.js +150 -0
  233. package/dist/operator/workorder-publishers.js.map +1 -0
  234. package/dist/security/security-monitor.d.ts +7 -0
  235. package/dist/security/security-monitor.d.ts.map +1 -1
  236. package/dist/security/security-monitor.js +17 -0
  237. package/dist/security/security-monitor.js.map +1 -1
  238. package/dist/setup/setup-prompt.d.ts +1 -1
  239. package/dist/setup/setup-prompt.d.ts.map +1 -1
  240. package/dist/setup/setup-prompt.js +4 -5
  241. package/dist/setup/setup-prompt.js.map +1 -1
  242. package/dist/utils/untrusted-content.d.ts +13 -0
  243. package/dist/utils/untrusted-content.d.ts.map +1 -1
  244. package/dist/utils/untrusted-content.js +43 -0
  245. package/dist/utils/untrusted-content.js.map +1 -1
  246. package/package.json +2 -2
  247. package/public/viewer/js/modules/agents.js +13 -9
  248. package/public/viewer/js/modules/settings.js +15 -10
  249. package/public/viewer/src/modules/agents.ts +12 -10
  250. package/public/viewer/src/modules/settings.ts +17 -12
  251. package/public/viewer/src/utils/api.ts +2 -2
  252. package/templates/AGENTS.codex.md +2 -23
  253. package/templates/personas/conductor.md +1 -1
  254. package/dist/agent/codex-mcp-process.d.ts +0 -105
  255. package/dist/agent/codex-mcp-process.d.ts.map +0 -1
  256. package/dist/agent/codex-mcp-process.js +0 -748
  257. package/dist/agent/codex-mcp-process.js.map +0 -1
@@ -0,0 +1,253 @@
1
+ "use strict";
2
+ /**
3
+ * WorkOrderConsumer - the single host-code consumer of system workorders
4
+ * (Stage 2, plan S2-T3).
5
+ *
6
+ * A dedicated interval timer (60s default) claims pending workorders from the
7
+ * TaskLedger and runs each through workerRun on the operator lane. It runs
8
+ * UNCONDITIONALLY of MAMA_TRIGGER_LOOP (the publishers are unconditional, so
9
+ * coupling consumption to an opt-in loop would strand every workorder - plan
10
+ * A1 BLOCKER), gated only by MAMA_STAGE2_WORKORDERS=shadow|on.
11
+ *
12
+ * Serial consumption: one claim at a time, awaited to completion, with a tick
13
+ * re-entrancy guard (a 260s board run spans 4+ ticks - overlapping ticks skip,
14
+ * plan G4). Blocking bound = the runner's per-request timeout x maxTurns; no
15
+ * consumer-level watchdog (plan N2).
16
+ *
17
+ * Failure policy (plan G5/M4): failWorkOrder marks the row, then per-kind
18
+ * maxAttempts decides requeue (fresh row, attempts+1, same occurrence key)
19
+ * vs retries-exhausted (owner alarm, deduped per kind). Boot recovery routes
20
+ * stale in_progress claims (crash artifacts) through the SAME policy, with a
21
+ * separate stale-claim alarm.
22
+ *
23
+ * Completion hooks (plan E3/E4): per-kind before/after seams re-home the
24
+ * post-run host effects the legacy closures owned (board bracket
25
+ * verification, promotion event re-emission, wiki noUpdate reading). Hook
26
+ * errors are LOUD but never fail a completed run (observe, never block).
27
+ */
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.WorkOrderConsumer = exports.WORKORDER_MAX_ATTEMPTS = void 0;
30
+ const worker_run_js_1 = require("./worker-run.js");
31
+ /** Per-kind retry budget: attempts start at 1; board/promotion self-heal on
32
+ * the next publish cycle, wiki events do not re-fire so it retries once. */
33
+ exports.WORKORDER_MAX_ATTEMPTS = {
34
+ board: 1,
35
+ wiki: 2,
36
+ 'memory-curation': 1,
37
+ };
38
+ const DEFAULT_TICK_MS = 60_000;
39
+ const ALARM_DEDUP_MS = 6 * 60 * 60 * 1000;
40
+ class WorkOrderConsumer {
41
+ deps;
42
+ hooks = new Map();
43
+ lastAlarmAt = new Map();
44
+ timer = null;
45
+ consuming = false;
46
+ activeTick = null;
47
+ constructor(deps) {
48
+ this.deps = deps;
49
+ }
50
+ registerHook(kind, hook) {
51
+ if (this.hooks.has(kind)) {
52
+ throw new Error(`[workorder-consumer] hook for '${kind}' already registered`);
53
+ }
54
+ this.hooks.set(kind, hook);
55
+ }
56
+ /**
57
+ * Boot recovery (plan C4/M4): in_progress system rows are crash artifacts
58
+ * (single serial consumer). Each routes through the SAME failure policy
59
+ * (a crashed wiki batch requeues once; board/promotion do not), plus a
60
+ * separate stale-claim alarm.
61
+ */
62
+ bootRecover() {
63
+ for (const wo of this.deps.ledger.listStaleClaims()) {
64
+ this.log(`[workorder-consumer] stale claim recovered: ${wo.workKind}#${wo.id}`);
65
+ this.emitEvent({ type: 'stale-claim', workKind: wo.workKind, workOrderId: wo.id });
66
+ this.alarm(wo.workKind, `workorder ${wo.workKind}#${wo.id} stale claim (daemon crash?)`);
67
+ this.handleFailure(wo, 'stale-claim');
68
+ }
69
+ }
70
+ start() {
71
+ if (this.timer) {
72
+ throw new Error('[workorder-consumer] already started');
73
+ }
74
+ const tickMs = this.deps.tickMs ?? DEFAULT_TICK_MS;
75
+ this.timer = setInterval(() => {
76
+ // Only track a REAL tick: during a long run subsequent firings resolve
77
+ // 'skipped' instantly and would OVERWRITE activeTick - stop() would
78
+ // then await the skipped promise while the true tick still runs and
79
+ // the DB closes under it (round-2 review N1).
80
+ if (!this.consuming) {
81
+ this.activeTick = this.tick();
82
+ }
83
+ }, tickMs);
84
+ this.timer.unref?.();
85
+ this.log(`[workorder-consumer] started (tick every ${tickMs}ms)`);
86
+ }
87
+ isStarted() {
88
+ return this.timer !== null;
89
+ }
90
+ /** Graceful: awaits an in-flight tick so shutdown does not race the
91
+ * operator-DB close into "database is not open" noise (review m4). */
92
+ async stop() {
93
+ if (this.timer) {
94
+ clearInterval(this.timer);
95
+ this.timer = null;
96
+ }
97
+ if (this.activeTick) {
98
+ await this.activeTick.catch(() => { });
99
+ this.activeTick = null;
100
+ }
101
+ }
102
+ /**
103
+ * Drain pending workorders serially: claim -> await -> next claim. Returns
104
+ * 'skipped' when a previous tick is still consuming (re-entrancy guard,
105
+ * plan G4) - long runs span multiple tick firings.
106
+ */
107
+ async tick() {
108
+ if (this.consuming)
109
+ return 'skipped';
110
+ this.consuming = true;
111
+ try {
112
+ // Drain is BOUNDED by the pending count at tick start: a row requeued
113
+ // by this tick's failure policy waits for the NEXT tick (natural
114
+ // backoff - otherwise a failing order retries in a tight loop).
115
+ let remaining = this.deps.ledger.countPendingWorkOrders();
116
+ while (remaining > 0) {
117
+ const wo = this.deps.ledger.claimNextWorkOrder();
118
+ if (!wo)
119
+ break;
120
+ await this.runOne(wo);
121
+ remaining--;
122
+ }
123
+ return 'drained';
124
+ }
125
+ finally {
126
+ this.consuming = false;
127
+ }
128
+ }
129
+ async runOne(wo) {
130
+ let brief;
131
+ try {
132
+ brief = this.deps.loadBrief(wo.workKind);
133
+ }
134
+ catch (err) {
135
+ // I/O errors (permissions etc.) must fail THIS order, not abort the
136
+ // whole tick with a stranded claim (PR bot round).
137
+ this.handleFailure(wo, `brief-load-failed: ${errMessage(err)}`);
138
+ return;
139
+ }
140
+ if (!brief || !brief.trim()) {
141
+ this.log(`[workorder-consumer] brief missing for '${wo.workKind}' - failing #${wo.id}`);
142
+ this.handleFailure(wo, 'brief-missing');
143
+ return;
144
+ }
145
+ const hook = this.hooks.get(wo.workKind);
146
+ let beforeState;
147
+ if (hook?.before) {
148
+ try {
149
+ beforeState = hook.before(wo);
150
+ }
151
+ catch (err) {
152
+ // A broken before-hook must not strand the claim: fail the order loudly.
153
+ this.handleFailure(wo, `before-hook: ${errMessage(err)}`);
154
+ return;
155
+ }
156
+ }
157
+ let response;
158
+ try {
159
+ // Inside the try: a runOptionsFor throw/reject (shadow capture publisher
160
+ // missing, envelope issuance failure) fails the order instead of running
161
+ // with the live publisher / without an envelope.
162
+ const runOptions = await this.deps.runOptionsFor?.(wo);
163
+ response = await (0, worker_run_js_1.workerRun)(this.deps.runner, {
164
+ kind: wo.workKind,
165
+ brief,
166
+ input: JSON.stringify(wo.payload),
167
+ runOptions,
168
+ });
169
+ }
170
+ catch (err) {
171
+ this.handleFailure(wo, errMessage(err));
172
+ return;
173
+ }
174
+ if (hook?.after) {
175
+ try {
176
+ hook.after(wo, response, beforeState);
177
+ }
178
+ catch (err) {
179
+ // Observe, never block: a verification/emission failure is loud but
180
+ // does not fail a run that completed.
181
+ this.log(`[workorder-consumer] after-hook error (${wo.workKind}#${wo.id}): ${errMessage(err)}`);
182
+ }
183
+ }
184
+ // Shadow-gate diagnostics (§8.2): the worker's actual output decides
185
+ // whether the tool path works - log a bounded head, never the full body.
186
+ this.log(`[workorder-consumer] ${wo.workKind}#${wo.id} response head: ${response.slice(0, 200).replace(/\n/g, ' | ')}`);
187
+ this.deps.ledger.completeWorkOrder(wo.id);
188
+ this.emitEvent({ type: 'complete', workKind: wo.workKind, workOrderId: wo.id });
189
+ this.log(`[workorder-consumer] completed ${wo.workKind}#${wo.id}`);
190
+ }
191
+ /**
192
+ * Failure policy layer (plan G5): mark failed, then requeue (attempts+1,
193
+ * fresh row, same occurrence key - the terminal row freed it) or declare
194
+ * retries-exhausted with an owner alarm.
195
+ */
196
+ handleFailure(wo, reason) {
197
+ const maxAttempts = exports.WORKORDER_MAX_ATTEMPTS[wo.workKind];
198
+ if (wo.payload.attempts < maxAttempts) {
199
+ // Atomic fail+requeue (PR bot round): a crash between separate fail and
200
+ // enqueue calls would silently lose the retry.
201
+ const requeued = this.deps.ledger.requeueWorkOrder(wo, reason);
202
+ this.emitEvent({ type: 'failed', workKind: wo.workKind, workOrderId: wo.id, reason });
203
+ this.emitEvent({ type: 'requeued', workKind: wo.workKind, workOrderId: requeued.id });
204
+ this.log(`[workorder-consumer] failed ${wo.workKind}#${wo.id} (${reason}) -> requeued #${requeued.id} (attempt ${wo.payload.attempts + 1}/${maxAttempts})`);
205
+ return;
206
+ }
207
+ this.deps.ledger.failWorkOrder(wo.id, reason);
208
+ this.emitEvent({ type: 'failed', workKind: wo.workKind, workOrderId: wo.id, reason });
209
+ this.log(`[workorder-consumer] failed ${wo.workKind}#${wo.id}: ${reason}`);
210
+ this.emitEvent({ type: 'exhausted', workKind: wo.workKind, workOrderId: wo.id, reason });
211
+ this.alarm(wo.workKind, `workorder ${wo.workKind}#${wo.id} retries exhausted (${wo.payload.attempts}/${maxAttempts}): ${reason}`);
212
+ }
213
+ /** Owner alarm: passive notice + active telegram, deduped per kind (6h). */
214
+ alarm(kind, message) {
215
+ const now = this.deps.now?.() ?? Date.now();
216
+ const last = this.lastAlarmAt.get(kind);
217
+ if (last !== undefined && now - last < ALARM_DEDUP_MS) {
218
+ this.log(`[workorder-consumer] alarm deduped (${kind}): ${message}`);
219
+ return;
220
+ }
221
+ this.lastAlarmAt.set(kind, now);
222
+ try {
223
+ this.deps.noticeOwner(message);
224
+ }
225
+ catch (err) {
226
+ this.log(`[workorder-consumer] notice enqueue failed: ${errMessage(err)}`);
227
+ }
228
+ if (this.deps.opsAlarm.configured) {
229
+ void this.deps.opsAlarm.send(`⚠️ ${message}`).catch((err) => {
230
+ this.log(`[workorder-consumer] active alarm send failed: ${errMessage(err)}`);
231
+ });
232
+ }
233
+ else {
234
+ this.log(`[workorder-consumer] active alarm unconfigured - log-only: ${message}`);
235
+ }
236
+ }
237
+ emitEvent(event) {
238
+ try {
239
+ this.deps.onEvent?.(event);
240
+ }
241
+ catch {
242
+ /* telemetry only */
243
+ }
244
+ }
245
+ log(line) {
246
+ (this.deps.log ?? console.log)(line);
247
+ }
248
+ }
249
+ exports.WorkOrderConsumer = WorkOrderConsumer;
250
+ function errMessage(err) {
251
+ return err instanceof Error ? err.message : String(err);
252
+ }
253
+ //# sourceMappingURL=workorder-consumer.js.map
@@ -0,0 +1 @@
1
+ {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AC,CAAC,IAAI,CAAC,CAAC;IACvC,CAAC;CACF;AAhOD,8CAgOC;AAED,SAAS,UAAU,CAAC,GAAY;IAC9B,OAAO,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AAC1D,CAAC"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Extracted, testable pieces of the Stage-2 per-kind completion hooks
3
+ * (plan S2-T3; extraction demanded by implementation review round 1 - the
4
+ * hook bodies lived in registerApiRoutes closures where nothing could prove
5
+ * them, which is the green-test-trap class the plan bans).
6
+ *
7
+ * - buildWorkerTraceQueries: the G1 re-keyed verifier trace queries. Worker
8
+ * runs log gateway_tool_call rows with the worker's identity, NOT
9
+ * agent_id='dashboard-agent'; the ONLY schema-supported key is the details
10
+ * JSON (agent_activity has no channel_id column) - hence json_extract.
11
+ * - buildPromotionAfterHook: the PROMOTED <n> parse + event re-emission that
12
+ * keeps the memory:promoted -> wiki ingress chain alive (plan E4/R7).
13
+ * - buildWikiAfterHook: outcome reading only.
14
+ */
15
+ import type { SQLiteDatabase } from '../sqlite.js';
16
+ import type { WorkOrderRecord } from './task-ledger.js';
17
+ export interface WorkerTraceQueries {
18
+ getTraceMaxId: () => number;
19
+ countObligatedTraceRowsSince: (maxId: number) => number;
20
+ }
21
+ export declare function buildWorkerTraceQueries(sessionsDb: SQLiteDatabase | undefined, workerChannelId: string): WorkerTraceQueries;
22
+ export interface PromotionHookEvents {
23
+ emitAgentAction: (action: 'promoted' | 'no_update', target: string) => void;
24
+ emitMemoryPromoted: (saved: number) => void;
25
+ log?: (line: string) => void;
26
+ }
27
+ /** The wiki ingress chain's second link: losing this parse severs memory:promoted. */
28
+ export declare function buildPromotionAfterHook(events: PromotionHookEvents): (wo: WorkOrderRecord, response: string) => void;
29
+ export declare function buildWikiAfterHook(log: (line: string) => void): (wo: WorkOrderRecord, response: string) => void;
30
+ //# sourceMappingURL=workorder-hooks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workorder-hooks.d.ts","sourceRoot":"","sources":["../../src/operator/workorder-hooks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAEnD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAIxD,MAAM,WAAW,kBAAkB;IACjC,aAAa,EAAE,MAAM,MAAM,CAAC;IAC5B,4BAA4B,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;CACzD;AAED,wBAAgB,uBAAuB,CACrC,UAAU,EAAE,cAAc,GAAG,SAAS,EACtC,eAAe,EAAE,MAAM,GACtB,kBAAkB,CA0BpB;AAED,MAAM,WAAW,mBAAmB;IAClC,eAAe,EAAE,CAAC,MAAM,EAAE,UAAU,GAAG,WAAW,EAAE,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IAC5E,kBAAkB,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAC5C,GAAG,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CAC9B;AAED,sFAAsF;AACtF,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,mBAAmB,GAC1B,CAAC,EAAE,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,KAAK,IAAI,CAcjD;AAED,wBAAgB,kBAAkB,CAChC,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,GAC1B,CAAC,EAAE,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,KAAK,IAAI,CAQjD"}
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ /**
3
+ * Extracted, testable pieces of the Stage-2 per-kind completion hooks
4
+ * (plan S2-T3; extraction demanded by implementation review round 1 - the
5
+ * hook bodies lived in registerApiRoutes closures where nothing could prove
6
+ * them, which is the green-test-trap class the plan bans).
7
+ *
8
+ * - buildWorkerTraceQueries: the G1 re-keyed verifier trace queries. Worker
9
+ * runs log gateway_tool_call rows with the worker's identity, NOT
10
+ * agent_id='dashboard-agent'; the ONLY schema-supported key is the details
11
+ * JSON (agent_activity has no channel_id column) - hence json_extract.
12
+ * - buildPromotionAfterHook: the PROMOTED <n> parse + event re-emission that
13
+ * keeps the memory:promoted -> wiki ingress chain alive (plan E4/R7).
14
+ * - buildWikiAfterHook: outcome reading only.
15
+ */
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.buildWorkerTraceQueries = buildWorkerTraceQueries;
18
+ exports.buildPromotionAfterHook = buildPromotionAfterHook;
19
+ exports.buildWikiAfterHook = buildWikiAfterHook;
20
+ const action_verifier_js_1 = require("./action-verifier.js");
21
+ const TRACE_TOOL_LIST = action_verifier_js_1.OBLIGATED_TOOLS.map((t) => `'${t}'`).join(',');
22
+ function buildWorkerTraceQueries(sessionsDb, workerChannelId) {
23
+ return {
24
+ getTraceMaxId: () => {
25
+ if (!sessionsDb)
26
+ return 0;
27
+ const row = sessionsDb
28
+ .prepare(`SELECT MAX(id) AS max_id FROM agent_activity
29
+ WHERE type = 'gateway_tool_call'
30
+ AND json_extract(details, '$.channel_id') = ?`)
31
+ .get(workerChannelId);
32
+ return row.max_id ?? 0;
33
+ },
34
+ countObligatedTraceRowsSince: (maxId) => {
35
+ if (!sessionsDb)
36
+ return 0;
37
+ const row = sessionsDb
38
+ .prepare(`SELECT COUNT(*) AS n FROM agent_activity
39
+ WHERE type = 'gateway_tool_call'
40
+ AND json_extract(details, '$.channel_id') = ?
41
+ AND id > ? AND (normalized_tool_name IN (${TRACE_TOOL_LIST}) OR input_summary IN (${TRACE_TOOL_LIST}))`)
42
+ .get(workerChannelId, maxId);
43
+ return row.n;
44
+ },
45
+ };
46
+ }
47
+ /** The wiki ingress chain's second link: losing this parse severs memory:promoted. */
48
+ function buildPromotionAfterHook(events) {
49
+ return (_wo, response) => {
50
+ const promotedMatch = response.match(/PROMOTED\s+(\d+)/);
51
+ const saved = promotedMatch ? Number(promotedMatch[1]) : 0;
52
+ const noUpdate = response.includes('NO_UPDATE');
53
+ events.emitAgentAction(noUpdate || saved === 0 ? 'no_update' : 'promoted', `promotion run: ${saved} saved`);
54
+ if (saved > 0) {
55
+ events.emitMemoryPromoted(saved);
56
+ events.log?.(`[stage2] promotion worker: promoted ${saved} durable judgments`);
57
+ }
58
+ };
59
+ }
60
+ function buildWikiAfterHook(log) {
61
+ return (_wo, response) => {
62
+ if (response.includes('NO_UPDATE')) {
63
+ log('[stage2] wiki worker: no changes detected');
64
+ }
65
+ else {
66
+ log('[stage2] wiki worker: compilation complete');
67
+ }
68
+ };
69
+ }
70
+ //# sourceMappingURL=workorder-hooks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workorder-hooks.js","sourceRoot":"","sources":["../../src/operator/workorder-hooks.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;GAaG;;AAaH,0DA6BC;AASD,0DAgBC;AAED,gDAUC;AA5ED,6DAAuD;AAGvD,MAAM,eAAe,GAAG,oCAAe,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAOvE,SAAgB,uBAAuB,CACrC,UAAsC,EACtC,eAAuB;IAEvB,OAAO;QACL,aAAa,EAAE,GAAG,EAAE;YAClB,IAAI,CAAC,UAAU;gBAAE,OAAO,CAAC,CAAC;YAC1B,MAAM,GAAG,GAAG,UAAU;iBACnB,OAAO,CACN;;2DAEiD,CAClD;iBACA,GAAG,CAAC,eAAe,CAA8B,CAAC;YACrD,OAAO,GAAG,CAAC,MAAM,IAAI,CAAC,CAAC;QACzB,CAAC;QACD,4BAA4B,EAAE,CAAC,KAAa,EAAE,EAAE;YAC9C,IAAI,CAAC,UAAU;gBAAE,OAAO,CAAC,CAAC;YAC1B,MAAM,GAAG,GAAG,UAAU;iBACnB,OAAO,CACN;;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3
+ * the three system-agent run paths (dashboard/wiki/promotion) and the
4
+ * reconcile leg into workorder enqueues.
5
+ *
6
+ * The gate decision is a PURE function (plan E5) so every flag x kind combo is
7
+ * unit-testable outside the api-routes-init closures. The wiring sites call
8
+ * resolvePublishAction and act on 'legacy' | 'enqueue' | 'both'.
9
+ *
10
+ * Flag: MAMA_STAGE2_WORKORDERS=off|shadow|on (tri-state; deliberate deviation
11
+ * from the repo's `=== '1'` convention - documented in configuration-options).
12
+ * off - legacy direct runs (current behavior)
13
+ * shadow - board ONLY dual-runs: legacy keeps publishing live AND the same
14
+ * occurrence is enqueued for the capture consumer. wiki/promotion
15
+ * stay pure legacy - their side effects (Obsidian writes, mama_save)
16
+ * have no capture seam and must never double-execute (plan B1/C2).
17
+ * on - all three kinds (and the reconcile leg) enqueue; legacy stops.
18
+ *
19
+ * Plan: docs/superpowers/plans/2026-07-18-stage2-workorder-ownership.md S2-T2
20
+ */
21
+ import type { WorkOrderKind } from './task-ledger.js';
22
+ export declare const STAGE2_FLAG_ENV = "MAMA_STAGE2_WORKORDERS";
23
+ export declare const STAGE2_FLAGS: readonly ["off", "shadow", "on"];
24
+ export type Stage2Flag = (typeof STAGE2_FLAGS)[number];
25
+ export type PublishAction = 'legacy' | 'enqueue' | 'both';
26
+ /**
27
+ * Parse the tri-state flag. Absent/empty -> 'off'. Any other value is a
28
+ * misconfiguration and throws at boot (no-fallback: a typo silently reverting
29
+ * to legacy would mask a believed-active migration).
30
+ */
31
+ export declare function readStage2Flag(env?: NodeJS.ProcessEnv): Stage2Flag;
32
+ /** Pure gate decision for the three scheduled/boot/manual run paths. */
33
+ export declare function resolvePublishAction(flag: Stage2Flag, kind: WorkOrderKind): PublishAction;
34
+ /**
35
+ * The reconcile leg converts at 'on' ONLY (plan: shadow/off keep the legacy
36
+ * bracket-verified path; its verification moves to the consumer hook at 'on').
37
+ */
38
+ export declare function resolveReconcileAction(flag: Stage2Flag): 'legacy' | 'enqueue';
39
+ export declare function boardFullKey(now: number): string;
40
+ /** Manual/forced orders get their own key (plan M2): a forced refresh must
41
+ * never dedup against a pending scheduled FULL that lacks force. */
42
+ export declare function boardManualKey(now: number): string;
43
+ export declare function boardReconcileKey(channelKey: string, now: number): string;
44
+ export declare function wikiBatchKey(trigger: string, now: number): string;
45
+ export declare function promotionKey(now: number): string;
46
+ export declare function promotionManualKey(now: number): string;
47
+ export interface BoardPayload {
48
+ mode: 'full' | 'reconcile';
49
+ /** Owner-forced refresh: brief must publish even on NO_UPDATE. */
50
+ force?: boolean;
51
+ channelKey?: string;
52
+ deltaLines?: string[];
53
+ }
54
+ export interface WikiPayload {
55
+ batchId: string;
56
+ /** Trigger provenance; the run does its own novelty check, events carry no content. */
57
+ events: string[];
58
+ }
59
+ export interface PromotionPayload {
60
+ scheduledAt: string;
61
+ }
62
+ /**
63
+ * Validate a payload at enqueue time. Unknown fields are rejected LOUDLY -
64
+ * a misspelled field silently dropped would surface as a wrong run later.
65
+ * (`attempts` is ledger-managed and allowed everywhere.)
66
+ */
67
+ export declare function validateWorkOrderPayload(kind: WorkOrderKind, payload: Record<string, unknown>): void;
68
+ //# sourceMappingURL=workorder-publishers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workorder-publishers.d.ts","sourceRoot":"","sources":["../../src/operator/workorder-publishers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEtD,eAAO,MAAM,eAAe,2BAA2B,CAAC;AAExD,eAAO,MAAM,YAAY,kCAAmC,CAAC;AAC7D,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC;AAEvD,MAAM,MAAM,aAAa,GAAG,QAAQ,GAAG,SAAS,GAAG,MAAM,CAAC;AAE1D;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,GAAG,GAAE,MAAM,CAAC,UAAwB,GAAG,UAAU,CAS/E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
+ * the three system-agent run paths (dashboard/wiki/promotion) and the
5
+ * reconcile leg into workorder enqueues.
6
+ *
7
+ * The gate decision is a PURE function (plan E5) so every flag x kind combo is
8
+ * unit-testable outside the api-routes-init closures. The wiring sites call
9
+ * resolvePublishAction and act on 'legacy' | 'enqueue' | 'both'.
10
+ *
11
+ * Flag: MAMA_STAGE2_WORKORDERS=off|shadow|on (tri-state; deliberate deviation
12
+ * from the repo's `=== '1'` convention - documented in configuration-options).
13
+ * off - legacy direct runs (current behavior)
14
+ * shadow - board ONLY dual-runs: legacy keeps publishing live AND the same
15
+ * occurrence is enqueued for the capture consumer. wiki/promotion
16
+ * stay pure legacy - their side effects (Obsidian writes, mama_save)
17
+ * have no capture seam and must never double-execute (plan B1/C2).
18
+ * on - all three kinds (and the reconcile leg) enqueue; legacy stops.
19
+ *
20
+ * Plan: docs/superpowers/plans/2026-07-18-stage2-workorder-ownership.md S2-T2
21
+ */
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ exports.STAGE2_FLAGS = exports.STAGE2_FLAG_ENV = void 0;
24
+ exports.readStage2Flag = readStage2Flag;
25
+ exports.resolvePublishAction = resolvePublishAction;
26
+ exports.resolveReconcileAction = resolveReconcileAction;
27
+ exports.boardFullKey = boardFullKey;
28
+ exports.boardManualKey = boardManualKey;
29
+ exports.boardReconcileKey = boardReconcileKey;
30
+ exports.wikiBatchKey = wikiBatchKey;
31
+ exports.promotionKey = promotionKey;
32
+ exports.promotionManualKey = promotionManualKey;
33
+ exports.validateWorkOrderPayload = validateWorkOrderPayload;
34
+ exports.STAGE2_FLAG_ENV = 'MAMA_STAGE2_WORKORDERS';
35
+ exports.STAGE2_FLAGS = ['off', 'shadow', 'on'];
36
+ /**
37
+ * Parse the tri-state flag. Absent/empty -> 'off'. Any other value is a
38
+ * misconfiguration and throws at boot (no-fallback: a typo silently reverting
39
+ * to legacy would mask a believed-active migration).
40
+ */
41
+ function readStage2Flag(env = process.env) {
42
+ const raw = (env[exports.STAGE2_FLAG_ENV] ?? '').trim();
43
+ if (raw === '') {
44
+ return 'off';
45
+ }
46
+ if (exports.STAGE2_FLAGS.includes(raw))
47
+ return raw;
48
+ throw new Error(`${exports.STAGE2_FLAG_ENV} must be one of ${exports.STAGE2_FLAGS.join('|')} (or unset), got: '${raw}'`);
49
+ }
50
+ /** Pure gate decision for the three scheduled/boot/manual run paths. */
51
+ function resolvePublishAction(flag, kind) {
52
+ if (flag === 'off')
53
+ return 'legacy';
54
+ if (flag === 'on')
55
+ return 'enqueue';
56
+ // shadow: board dual-runs; wiki/promotion must not leak uncaptured writes.
57
+ return kind === 'board' ? 'both' : 'legacy';
58
+ }
59
+ /**
60
+ * The reconcile leg converts at 'on' ONLY (plan: shadow/off keep the legacy
61
+ * bracket-verified path; its verification moves to the consumer hook at 'on').
62
+ */
63
+ function resolveReconcileAction(flag) {
64
+ return flag === 'on' ? 'enqueue' : 'legacy';
65
+ }
66
+ // ── Occurrence keys (plan D5/M2) ──────────────────────────────────────────
67
+ // Keys identify one OCCURRENCE: same scheduled slot dedups against itself,
68
+ // the next slot (or any manual request) mints a fresh key. Terminal rows free
69
+ // their key (ledger index predicate), so retries insert fresh rows.
70
+ const BOARD_SLOT_MS = 30 * 60 * 1000;
71
+ const PROMOTION_SLOT_MS = 6 * 60 * 60 * 1000;
72
+ function boardFullKey(now) {
73
+ return `board:full:${Math.floor(now / BOARD_SLOT_MS)}`;
74
+ }
75
+ /** Manual/forced orders get their own key (plan M2): a forced refresh must
76
+ * never dedup against a pending scheduled FULL that lacks force. */
77
+ function boardManualKey(now) {
78
+ return `board:manual:${now}`;
79
+ }
80
+ function boardReconcileKey(channelKey, now) {
81
+ // Timestamp, not slot (PR bot round): distinct reconciles for one channel
82
+ // can fire within a 30-min window carrying DIFFERENT deltas - a slot key
83
+ // would dedup the later one against the open earlier row and drop its
84
+ // delta. The ReconcileScheduler's debounce is the coalescing layer; each
85
+ // scheduler fire is its own occurrence.
86
+ return `board:reconcile:${channelKey}:${now}`;
87
+ }
88
+ function wikiBatchKey(trigger, now) {
89
+ return `wiki:${now}-${trigger}`;
90
+ }
91
+ function promotionKey(now) {
92
+ return `promotion:${Math.floor(now / PROMOTION_SLOT_MS)}`;
93
+ }
94
+ function promotionManualKey(now) {
95
+ return `promotion:manual:${now}`;
96
+ }
97
+ const PAYLOAD_KEYS = {
98
+ board: ['mode', 'force', 'channelKey', 'deltaLines'],
99
+ wiki: ['batchId', 'events'],
100
+ 'memory-curation': ['scheduledAt'],
101
+ };
102
+ /**
103
+ * Validate a payload at enqueue time. Unknown fields are rejected LOUDLY -
104
+ * a misspelled field silently dropped would surface as a wrong run later.
105
+ * (`attempts` is ledger-managed and allowed everywhere.)
106
+ */
107
+ function validateWorkOrderPayload(kind, payload) {
108
+ const allowed = PAYLOAD_KEYS[kind];
109
+ for (const key of Object.keys(payload)) {
110
+ if (key !== 'attempts' && !allowed.includes(key)) {
111
+ throw new Error(`workorder payload (${kind}): unknown field '${key}'`);
112
+ }
113
+ }
114
+ if (kind === 'board') {
115
+ const mode = payload.mode;
116
+ if (mode !== 'full' && mode !== 'reconcile') {
117
+ throw new Error(`workorder payload (board): mode must be 'full'|'reconcile', got: ${String(mode)}`);
118
+ }
119
+ if (payload.force !== undefined && typeof payload.force !== 'boolean') {
120
+ throw new Error(`workorder payload (board): force must be a boolean`);
121
+ }
122
+ if (mode === 'reconcile') {
123
+ if (typeof payload.channelKey !== 'string' || payload.channelKey === '') {
124
+ throw new Error(`workorder payload (board reconcile): channelKey required`);
125
+ }
126
+ if (!Array.isArray(payload.deltaLines) || payload.deltaLines.length === 0) {
127
+ throw new Error(`workorder payload (board reconcile): non-empty deltaLines[] required`);
128
+ }
129
+ }
130
+ else if (payload.channelKey !== undefined || payload.deltaLines !== undefined) {
131
+ // Reconcile-only fields on a full run signal a caller bug - loud.
132
+ throw new Error(`workorder payload (board full): channelKey/deltaLines are reconcile-only`);
133
+ }
134
+ }
135
+ else if (kind === 'wiki') {
136
+ if (typeof payload.batchId !== 'string' || payload.batchId === '') {
137
+ throw new Error(`workorder payload (wiki): batchId required`);
138
+ }
139
+ if (!Array.isArray(payload.events) ||
140
+ payload.events.some((entry) => typeof entry !== 'string')) {
141
+ throw new Error(`workorder payload (wiki): events[] of strings required`);
142
+ }
143
+ }
144
+ else {
145
+ if (typeof payload.scheduledAt !== 'string' || payload.scheduledAt === '') {
146
+ throw new Error(`workorder payload (memory-curation): scheduledAt required`);
147
+ }
148
+ }
149
+ }
150
+ //# sourceMappingURL=workorder-publishers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workorder-publishers.js","sourceRoot":"","sources":["../../src/operator/workorder-publishers.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;GAmBG;;;AAgBH,wCASC;AAGD,oDAKC;AAMD,wDAEC;AAUD,oCAEC;AAID,wCAEC;AAED,8CAOC;AAED,oCAEC;AAED,oCAEC;AAED,gDAEC;AAiCD,4DA8CC;AA3JY,QAAA,eAAe,GAAG,wBAAwB,CAAC;AAE3C,QAAA,YAAY,GAAG,CAAC,KAAK,EAAE,QAAQ,EAAE,IAAI,CAAU,CAAC;AAK7D;;;;GAIG;AACH,SAAgB,cAAc,CAAC,MAAyB,OAAO,CAAC,GAAG;IACjE,MAAM,GAAG,GAAG,CAAC,GAAG,CAAC,uBAAe,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IAChD,IAAI,GAAG,KAAK,EAAE,EAAE,CAAC;QACf,OAAO,KAAK,CAAC;IACf,CAAC;IACD,IAAK,oBAAkC,CAAC,QAAQ,CAAC,GAAG,CAAC;QAAE,OAAO,GAAiB,CAAC;IAChF,MAAM,IAAI,KAAK,CACb,GAAG,uBAAe,mBAAmB,oBAAY,CAAC,IAAI,CAAC,GAAG,CAAC,sBAAsB,GAAG,GAAG,CACxF,CAAC;AACJ,CAAC;AAED,wEAAwE;AACxE,SAAgB,oBAAoB,CAAC,IAAgB,EAAE,IAAmB;IACxE,IAAI,IAAI,KAAK,K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AC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,OAAO,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBAC1E,MAAM,IAAI,KAAK,CAAC,sEAAsE,CAAC,CAAC;YAC1F,CAAC;QACH,CAAC;aAAM,IAAI,OAAO,CAAC,UAAU,KAAK,SAAS,IAAI,OAAO,CAAC,UAAU,KAAK,SAAS,EAAE,CAAC;YAChF,kEAAkE;YAClE,MAAM,IAAI,KAAK,CAAC,0EAA0E,CAAC,CAAC;QAC9F,CAAC;IACH,CAAC;SAAM,IAAI,IAAI,KAAK,MAAM,EAAE,CAAC;QAC3B,IAAI,OAAO,OAAO,CAAC,OAAO,KAAK,QAAQ,IAAI,OAAO,CAAC,OAAO,KAAK,EAAE,EAAE,CAAC;YAClE,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;QAChE,CAAC;QACD,IACE,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC;YAC9B,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC,EACzD,CAAC;YACD,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAC;QAC5E,CAAC;IACH,CAAC;SAAM,CAAC;QACN,IAAI,OAAO,OAAO,CAAC,WAAW,KAAK,QAAQ,IAAI,OAAO,CAAC,WAAW,KAAK,EAAE,EAAE,CAAC;YAC1E,MAAM,IAAI,KAAK,CAAC,2DAA2D,CAAC,CAAC;QAC/E,CAAC;IACH,CAAC;AACH,CAAC"}
@@ -29,6 +29,13 @@ declare function getCloudflareCustomListCsvPath(): string;
29
29
  declare function getCloudflareWafExpressionPath(): string;
30
30
  export declare function setSecurityAlertSender(sender: SecurityAlertSender | null): void;
31
31
  export declare function hasSecurityAlertSender(): boolean;
32
+ /**
33
+ * Record-only security event: appends to the security log (durable trail,
34
+ * surfaced by the code audit) and NOTHING else - no incident/denylist/RDAP
35
+ * fabrication (PR #151 lesson), no alert cooldown consumption, no throw when
36
+ * no sender is registered. For tripwires whose job is observability.
37
+ */
38
+ export declare function logSecurityEventOnly(event: SecurityEvent): void;
32
39
  /**
33
40
  * Deliver an alert through the registered sender WITHOUT the incident pipeline.
34
41
  *
@@ -1 +1 @@
1
- {"version":3,"file":"security-monitor.d.ts","sourceRoot":"","sources":["../../src/security/security-monitor.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAuD/D,wBAAgB,UAAU,CAAC,aAAa,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAO5E;AAED,wBAAgB,KAAK,CAAC,aAAa,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CASjE;AAED,wBAAgB,iBAAiB,CAAC,aAAa,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,IAAI,CAuBhF;AAiBD,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,MAAM,GAAG,UAAU,CAAC;AAE5D,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,gBAAgB,CAAC;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,OAAO,CAAC,EA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