@aitne/daemon 0.1.4 → 0.1.7

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 (272) hide show
  1. package/dist/adapters/notification-manager.d.ts +12 -0
  2. package/dist/adapters/notification-manager.d.ts.map +1 -1
  3. package/dist/adapters/notification-manager.js +39 -1
  4. package/dist/adapters/notification-manager.js.map +1 -1
  5. package/dist/api/routes/agent.d.ts.map +1 -1
  6. package/dist/api/routes/agent.js +7 -0
  7. package/dist/api/routes/agent.js.map +1 -1
  8. package/dist/api/routes/commands.d.ts.map +1 -1
  9. package/dist/api/routes/commands.js +16 -13
  10. package/dist/api/routes/commands.js.map +1 -1
  11. package/dist/api/routes/context.d.ts.map +1 -1
  12. package/dist/api/routes/context.js +13 -2
  13. package/dist/api/routes/context.js.map +1 -1
  14. package/dist/api/routes/dashboard.d.ts.map +1 -1
  15. package/dist/api/routes/dashboard.js +28 -0
  16. package/dist/api/routes/dashboard.js.map +1 -1
  17. package/dist/api/routes/fs.d.ts +23 -0
  18. package/dist/api/routes/fs.d.ts.map +1 -0
  19. package/dist/api/routes/fs.js +156 -0
  20. package/dist/api/routes/fs.js.map +1 -0
  21. package/dist/api/routes/fs.logic.d.ts +62 -0
  22. package/dist/api/routes/fs.logic.d.ts.map +1 -0
  23. package/dist/api/routes/fs.logic.js +137 -0
  24. package/dist/api/routes/fs.logic.js.map +1 -0
  25. package/dist/api/routes/health.d.ts.map +1 -1
  26. package/dist/api/routes/health.js +4 -2
  27. package/dist/api/routes/health.js.map +1 -1
  28. package/dist/api/routes/integrations.d.ts.map +1 -1
  29. package/dist/api/routes/integrations.js +8 -6
  30. package/dist/api/routes/integrations.js.map +1 -1
  31. package/dist/api/routes/metrics.d.ts +1 -0
  32. package/dist/api/routes/metrics.d.ts.map +1 -1
  33. package/dist/api/routes/metrics.js +24 -0
  34. package/dist/api/routes/metrics.js.map +1 -1
  35. package/dist/api/routes/observations.d.ts.map +1 -1
  36. package/dist/api/routes/observations.js +538 -25
  37. package/dist/api/routes/observations.js.map +1 -1
  38. package/dist/api/routes/skills.d.ts +9 -1
  39. package/dist/api/routes/skills.d.ts.map +1 -1
  40. package/dist/api/routes/skills.js +38 -16
  41. package/dist/api/routes/skills.js.map +1 -1
  42. package/dist/api/routes/wiki.d.ts +4 -0
  43. package/dist/api/routes/wiki.d.ts.map +1 -0
  44. package/dist/api/routes/wiki.js +1075 -0
  45. package/dist/api/routes/wiki.js.map +1 -0
  46. package/dist/api/server.d.ts +13 -0
  47. package/dist/api/server.d.ts.map +1 -1
  48. package/dist/api/server.js +27 -1
  49. package/dist/api/server.js.map +1 -1
  50. package/dist/config.d.ts.map +1 -1
  51. package/dist/config.js +26 -0
  52. package/dist/config.js.map +1 -1
  53. package/dist/core/agent-core.d.ts +25 -0
  54. package/dist/core/agent-core.d.ts.map +1 -1
  55. package/dist/core/agent-core.js.map +1 -1
  56. package/dist/core/backends/backend-router.d.ts +5 -1
  57. package/dist/core/backends/backend-router.d.ts.map +1 -1
  58. package/dist/core/backends/backend-router.js +10 -1
  59. package/dist/core/backends/backend-router.js.map +1 -1
  60. package/dist/core/backends/claude-code-core.d.ts.map +1 -1
  61. package/dist/core/backends/claude-code-core.js +62 -4
  62. package/dist/core/backends/claude-code-core.js.map +1 -1
  63. package/dist/core/backends/claude-tool-collection.d.ts +1 -1
  64. package/dist/core/backends/claude-tool-collection.d.ts.map +1 -1
  65. package/dist/core/backends/claude-tool-collection.js +327 -65
  66. package/dist/core/backends/claude-tool-collection.js.map +1 -1
  67. package/dist/core/backends/codex-core.d.ts.map +1 -1
  68. package/dist/core/backends/codex-core.js +36 -0
  69. package/dist/core/backends/codex-core.js.map +1 -1
  70. package/dist/core/backends/gemini-cli-core.d.ts +24 -5
  71. package/dist/core/backends/gemini-cli-core.d.ts.map +1 -1
  72. package/dist/core/backends/gemini-cli-core.js +62 -30
  73. package/dist/core/backends/gemini-cli-core.js.map +1 -1
  74. package/dist/core/backends/plan-presets.d.ts +3 -1
  75. package/dist/core/backends/plan-presets.d.ts.map +1 -1
  76. package/dist/core/backends/plan-presets.js +42 -2
  77. package/dist/core/backends/plan-presets.js.map +1 -1
  78. package/dist/core/bang-commands/commands-help.d.ts +5 -0
  79. package/dist/core/bang-commands/commands-help.d.ts.map +1 -0
  80. package/dist/core/bang-commands/commands-help.js +69 -0
  81. package/dist/core/bang-commands/commands-help.js.map +1 -0
  82. package/dist/core/bang-commands/commands-wiki.d.ts +75 -0
  83. package/dist/core/bang-commands/commands-wiki.d.ts.map +1 -0
  84. package/dist/core/bang-commands/commands-wiki.js +574 -0
  85. package/dist/core/bang-commands/commands-wiki.js.map +1 -0
  86. package/dist/core/bang-commands/index.d.ts +4 -2
  87. package/dist/core/bang-commands/index.d.ts.map +1 -1
  88. package/dist/core/bang-commands/index.js +15 -1
  89. package/dist/core/bang-commands/index.js.map +1 -1
  90. package/dist/core/bang-commands/registry.d.ts +47 -4
  91. package/dist/core/bang-commands/registry.d.ts.map +1 -1
  92. package/dist/core/bang-commands/registry.js +85 -15
  93. package/dist/core/bang-commands/registry.js.map +1 -1
  94. package/dist/core/context-builder.d.ts +17 -0
  95. package/dist/core/context-builder.d.ts.map +1 -1
  96. package/dist/core/context-builder.js +64 -6
  97. package/dist/core/context-builder.js.map +1 -1
  98. package/dist/core/daemon-api-cli.d.ts.map +1 -1
  99. package/dist/core/daemon-api-cli.js +50 -2
  100. package/dist/core/daemon-api-cli.js.map +1 -1
  101. package/dist/core/dispatcher-message-handler.d.ts.map +1 -1
  102. package/dist/core/dispatcher-message-handler.js +10 -0
  103. package/dist/core/dispatcher-message-handler.js.map +1 -1
  104. package/dist/core/dispatcher-morning-routine.d.ts.map +1 -1
  105. package/dist/core/dispatcher-morning-routine.js +17 -2
  106. package/dist/core/dispatcher-morning-routine.js.map +1 -1
  107. package/dist/core/dispatcher-result-processor.d.ts +23 -0
  108. package/dist/core/dispatcher-result-processor.d.ts.map +1 -1
  109. package/dist/core/dispatcher-result-processor.js +124 -5
  110. package/dist/core/dispatcher-result-processor.js.map +1 -1
  111. package/dist/core/dispatcher-scheduled-tasks.d.ts.map +1 -1
  112. package/dist/core/dispatcher-scheduled-tasks.js +114 -80
  113. package/dist/core/dispatcher-scheduled-tasks.js.map +1 -1
  114. package/dist/core/dispatcher-types.d.ts +116 -1
  115. package/dist/core/dispatcher-types.d.ts.map +1 -1
  116. package/dist/core/dispatcher-types.js.map +1 -1
  117. package/dist/core/dispatcher.d.ts +36 -0
  118. package/dist/core/dispatcher.d.ts.map +1 -1
  119. package/dist/core/dispatcher.js +94 -1
  120. package/dist/core/dispatcher.js.map +1 -1
  121. package/dist/core/integration-lifecycle.d.ts.map +1 -1
  122. package/dist/core/integration-lifecycle.js +6 -8
  123. package/dist/core/integration-lifecycle.js.map +1 -1
  124. package/dist/core/metrics.d.ts +127 -0
  125. package/dist/core/metrics.d.ts.map +1 -1
  126. package/dist/core/metrics.js +256 -1
  127. package/dist/core/metrics.js.map +1 -1
  128. package/dist/core/prompts.d.ts +2 -1
  129. package/dist/core/prompts.d.ts.map +1 -1
  130. package/dist/core/prompts.js +40 -0
  131. package/dist/core/prompts.js.map +1 -1
  132. package/dist/core/roadmap-validate.js +13 -1
  133. package/dist/core/roadmap-validate.js.map +1 -1
  134. package/dist/core/routine-acquisition-plan.d.ts +51 -0
  135. package/dist/core/routine-acquisition-plan.d.ts.map +1 -1
  136. package/dist/core/routine-acquisition-plan.js +111 -12
  137. package/dist/core/routine-acquisition-plan.js.map +1 -1
  138. package/dist/core/routine-fetch-window-retry.d.ts +109 -0
  139. package/dist/core/routine-fetch-window-retry.d.ts.map +1 -0
  140. package/dist/core/routine-fetch-window-retry.js +210 -0
  141. package/dist/core/routine-fetch-window-retry.js.map +1 -0
  142. package/dist/core/routine-fetch-window-runner.d.ts +258 -32
  143. package/dist/core/routine-fetch-window-runner.d.ts.map +1 -1
  144. package/dist/core/routine-fetch-window-runner.js +1115 -185
  145. package/dist/core/routine-fetch-window-runner.js.map +1 -1
  146. package/dist/core/routine-windows.d.ts +19 -4
  147. package/dist/core/routine-windows.d.ts.map +1 -1
  148. package/dist/core/routine-windows.js +47 -0
  149. package/dist/core/routine-windows.js.map +1 -1
  150. package/dist/core/scheduler.d.ts +50 -2
  151. package/dist/core/scheduler.d.ts.map +1 -1
  152. package/dist/core/scheduler.js +88 -7
  153. package/dist/core/scheduler.js.map +1 -1
  154. package/dist/core/skill-curation/declarations.d.ts.map +1 -1
  155. package/dist/core/skill-curation/declarations.js +11 -12
  156. package/dist/core/skill-curation/declarations.js.map +1 -1
  157. package/dist/core/skill-source-paths.d.ts +14 -0
  158. package/dist/core/skill-source-paths.d.ts.map +1 -0
  159. package/dist/core/skill-source-paths.js +82 -0
  160. package/dist/core/skill-source-paths.js.map +1 -0
  161. package/dist/core/skills-compiler.d.ts +18 -0
  162. package/dist/core/skills-compiler.d.ts.map +1 -1
  163. package/dist/core/skills-compiler.js +65 -18
  164. package/dist/core/skills-compiler.js.map +1 -1
  165. package/dist/core/skills-manifest.d.ts.map +1 -1
  166. package/dist/core/skills-manifest.js +46 -0
  167. package/dist/core/skills-manifest.js.map +1 -1
  168. package/dist/core/system-reset.d.ts +25 -0
  169. package/dist/core/system-reset.d.ts.map +1 -1
  170. package/dist/core/system-reset.js +47 -0
  171. package/dist/core/system-reset.js.map +1 -1
  172. package/dist/core/wiki/approval-queue.d.ts +31 -0
  173. package/dist/core/wiki/approval-queue.d.ts.map +1 -0
  174. package/dist/core/wiki/approval-queue.js +44 -0
  175. package/dist/core/wiki/approval-queue.js.map +1 -0
  176. package/dist/core/wiki/bridge.d.ts +74 -0
  177. package/dist/core/wiki/bridge.d.ts.map +1 -0
  178. package/dist/core/wiki/bridge.js +405 -0
  179. package/dist/core/wiki/bridge.js.map +1 -0
  180. package/dist/core/wiki/compile-lock.d.ts +42 -0
  181. package/dist/core/wiki/compile-lock.d.ts.map +1 -0
  182. package/dist/core/wiki/compile-lock.js +55 -0
  183. package/dist/core/wiki/compile-lock.js.map +1 -0
  184. package/dist/core/wiki/compile-preview.d.ts +8 -0
  185. package/dist/core/wiki/compile-preview.d.ts.map +1 -0
  186. package/dist/core/wiki/compile-preview.js +200 -0
  187. package/dist/core/wiki/compile-preview.js.map +1 -0
  188. package/dist/core/wiki/cost-estimate.d.ts +30 -0
  189. package/dist/core/wiki/cost-estimate.d.ts.map +1 -0
  190. package/dist/core/wiki/cost-estimate.js +243 -0
  191. package/dist/core/wiki/cost-estimate.js.map +1 -0
  192. package/dist/core/wiki/dispatcher.d.ts +48 -0
  193. package/dist/core/wiki/dispatcher.d.ts.map +1 -0
  194. package/dist/core/wiki/dispatcher.js +92 -0
  195. package/dist/core/wiki/dispatcher.js.map +1 -0
  196. package/dist/core/wiki/git-precompile.d.ts +86 -0
  197. package/dist/core/wiki/git-precompile.d.ts.map +1 -0
  198. package/dist/core/wiki/git-precompile.js +96 -0
  199. package/dist/core/wiki/git-precompile.js.map +1 -0
  200. package/dist/core/wiki/import-migrate.d.ts +38 -0
  201. package/dist/core/wiki/import-migrate.d.ts.map +1 -0
  202. package/dist/core/wiki/import-migrate.js +310 -0
  203. package/dist/core/wiki/import-migrate.js.map +1 -0
  204. package/dist/core/wiki/import-probe.d.ts +76 -0
  205. package/dist/core/wiki/import-probe.d.ts.map +1 -0
  206. package/dist/core/wiki/import-probe.js +245 -0
  207. package/dist/core/wiki/import-probe.js.map +1 -0
  208. package/dist/core/wiki/index-cache.d.ts +39 -0
  209. package/dist/core/wiki/index-cache.d.ts.map +1 -0
  210. package/dist/core/wiki/index-cache.js +152 -0
  211. package/dist/core/wiki/index-cache.js.map +1 -0
  212. package/dist/core/wiki/multi-url-dispatch.d.ts +52 -0
  213. package/dist/core/wiki/multi-url-dispatch.d.ts.map +1 -0
  214. package/dist/core/wiki/multi-url-dispatch.js +72 -0
  215. package/dist/core/wiki/multi-url-dispatch.js.map +1 -0
  216. package/dist/core/wiki/wiki-fts.d.ts +75 -0
  217. package/dist/core/wiki/wiki-fts.d.ts.map +1 -0
  218. package/dist/core/wiki/wiki-fts.js +265 -0
  219. package/dist/core/wiki/wiki-fts.js.map +1 -0
  220. package/dist/core/wiki/workspaces.d.ts +101 -0
  221. package/dist/core/wiki/workspaces.d.ts.map +1 -0
  222. package/dist/core/wiki/workspaces.js +352 -0
  223. package/dist/core/wiki/workspaces.js.map +1 -0
  224. package/dist/core/wiki/write-strategy.d.ts +70 -0
  225. package/dist/core/wiki/write-strategy.d.ts.map +1 -0
  226. package/dist/core/wiki/write-strategy.js +112 -0
  227. package/dist/core/wiki/write-strategy.js.map +1 -0
  228. package/dist/core/workdir.d.ts +8 -1
  229. package/dist/core/workdir.d.ts.map +1 -1
  230. package/dist/core/workdir.js +4 -1
  231. package/dist/core/workdir.js.map +1 -1
  232. package/dist/db/schema.d.ts.map +1 -1
  233. package/dist/db/schema.js +122 -0
  234. package/dist/db/schema.js.map +1 -1
  235. package/dist/db/wiki-store.d.ts +3 -0
  236. package/dist/db/wiki-store.d.ts.map +1 -0
  237. package/dist/db/wiki-store.js +7 -0
  238. package/dist/db/wiki-store.js.map +1 -0
  239. package/dist/index.js +87 -4
  240. package/dist/index.js.map +1 -1
  241. package/dist/messaging/setup-welcome-dm.d.ts +30 -0
  242. package/dist/messaging/setup-welcome-dm.d.ts.map +1 -0
  243. package/dist/messaging/setup-welcome-dm.js +86 -0
  244. package/dist/messaging/setup-welcome-dm.js.map +1 -0
  245. package/dist/messaging/url-extract.d.ts +8 -0
  246. package/dist/messaging/url-extract.d.ts.map +1 -0
  247. package/dist/messaging/url-extract.js +41 -0
  248. package/dist/messaging/url-extract.js.map +1 -0
  249. package/dist/observers/delegated-sync-worker.d.ts +33 -25
  250. package/dist/observers/delegated-sync-worker.d.ts.map +1 -1
  251. package/dist/observers/delegated-sync-worker.js +38 -31
  252. package/dist/observers/delegated-sync-worker.js.map +1 -1
  253. package/dist/observers/imminent-event-scheduler.d.ts +20 -7
  254. package/dist/observers/imminent-event-scheduler.d.ts.map +1 -1
  255. package/dist/observers/imminent-event-scheduler.js +134 -29
  256. package/dist/observers/imminent-event-scheduler.js.map +1 -1
  257. package/dist/safety/always-disallowed.d.ts +65 -0
  258. package/dist/safety/always-disallowed.d.ts.map +1 -1
  259. package/dist/safety/always-disallowed.js +106 -10
  260. package/dist/safety/always-disallowed.js.map +1 -1
  261. package/dist/safety/audit.d.ts +46 -1
  262. package/dist/safety/audit.d.ts.map +1 -1
  263. package/dist/safety/audit.js +79 -16
  264. package/dist/safety/audit.js.map +1 -1
  265. package/dist/safety/risk-classifier.d.ts.map +1 -1
  266. package/dist/safety/risk-classifier.js +29 -0
  267. package/dist/safety/risk-classifier.js.map +1 -1
  268. package/dist/settings/runtime-settings.d.ts +12 -1
  269. package/dist/settings/runtime-settings.d.ts.map +1 -1
  270. package/dist/settings/runtime-settings.js +59 -1
  271. package/dist/settings/runtime-settings.js.map +1 -1
  272. package/package.json +2 -2
@@ -0,0 +1,210 @@
1
+ /**
2
+ * Retry-policy helpers for the pre-pass fan-out coordinator.
3
+ *
4
+ * PRE_PASS_FAN_OUT_DESIGN.md §4.4 — the coordinator spawns a fresh Haiku
5
+ * sub-session per attempt and consults `defaultRetryDecision` (or any
6
+ * `RetryDecisionFn`) between attempts to choose whether to spawn the
7
+ * next one. Keeping the policy as pure data (decision matrix in
8
+ * TypeScript, not in agent prose) makes the loop deterministic,
9
+ * testable, and free of per-model variance.
10
+ *
11
+ * Phase 0 ships these helpers + their unit tests. The fan-out
12
+ * coordinator that consumes them lands in Phase 1.
13
+ */
14
+ // ── Decision matrix (PRE_PASS_FAN_OUT_DESIGN.md §4.4) ─────────────────────
15
+ /**
16
+ * Stable reason identifiers. Centralised so the dashboard / audit feed
17
+ * can render them consistently and so test assertions don't drift from
18
+ * runtime values.
19
+ */
20
+ export const RETRY_REASONS = {
21
+ MAX_ATTEMPTS: "max-attempts-reached",
22
+ BUDGET_CAP: "per-integration-budget-cap",
23
+ FLIP_LOCKED: "flip-locked",
24
+ BUDGET_EXHAUSTED: "budget-exhausted",
25
+ AUTH_FAILED: "auth-failed",
26
+ FAILED_STATUS: "failed-status",
27
+ UPSTREAM_5XX: "upstream-5xx",
28
+ PARTIAL_NO_POST: "partial-no-post",
29
+ SUCCESS: "success",
30
+ PARTIAL_WITH_POST: "partial-with-progress",
31
+ SKIPPED: "skipped",
32
+ NO_PROGRESS: "no-progress",
33
+ };
34
+ /**
35
+ * Sum the cost across `priorAttempts` + the current `report`. Pure;
36
+ * exported for unit testing the budget-cap branch in isolation.
37
+ */
38
+ export function cumulativeAttemptCost(report, priorAttempts) {
39
+ let total = report.costUsd;
40
+ for (const att of priorAttempts)
41
+ total += att.costUsd;
42
+ return total;
43
+ }
44
+ function isFetchFailedWithStatus(err, predicate) {
45
+ if (err.type !== "fetch-failed")
46
+ return false;
47
+ // `status` may arrive as number or string — MCP transports stringify
48
+ // upstream HTTP codes inconsistently.
49
+ const raw = err.status;
50
+ const status = typeof raw === "number"
51
+ ? raw
52
+ : typeof raw === "string" && /^\d+$/.test(raw)
53
+ ? Number.parseInt(raw, 10)
54
+ : NaN;
55
+ if (Number.isNaN(status))
56
+ return false;
57
+ return predicate(status);
58
+ }
59
+ /**
60
+ * Default retry policy from §4.4. Pure: decision is fully determined by
61
+ * the inputs, no side effects, no shared state. Decision order:
62
+ *
63
+ * 1. Attempts cap (no retry, reason `max-attempts-reached`).
64
+ * 2. Per-integration cumulative budget cap.
65
+ * 3. Terminal error classes — flip-lock, budget-exhausted, auth (401/403).
66
+ * 4. Retry-worthy outcomes — failed status, upstream 5xx, partial-no-post.
67
+ * 5. Non-retry-by-default — success, partial-with-progress, skipped, no-progress.
68
+ *
69
+ * The motivating §1.1 failure ("Unknown name "limit"") lands
70
+ * as `status="partial"` with `fetched > 0`, `posted === 0` and a
71
+ * `fetch-failed` error — rule (4)'s `partial-no-post` branch catches it.
72
+ */
73
+ export const defaultRetryDecision = (report, attempt, policy, priorAttempts) => {
74
+ // (1) Attempts cap — the loop body checks this before spawning attempt N+1.
75
+ if (attempt >= policy.maxAttempts) {
76
+ return { retry: false, reason: RETRY_REASONS.MAX_ATTEMPTS };
77
+ }
78
+ // (2) Cumulative cost cap. Compare against the cost AFTER recording
79
+ // this attempt; if it's already at/over the cap, no point retrying.
80
+ const cumulative = cumulativeAttemptCost(report, priorAttempts);
81
+ if (cumulative >= policy.perIntegrationBudgetUsd) {
82
+ return { retry: false, reason: RETRY_REASONS.BUDGET_CAP };
83
+ }
84
+ // (3) Terminal error classes — first match wins.
85
+ for (const err of report.errors) {
86
+ if (err.type === "flip-locked") {
87
+ return { retry: false, reason: RETRY_REASONS.FLIP_LOCKED };
88
+ }
89
+ if (err.type === "budget-exhausted") {
90
+ return { retry: false, reason: RETRY_REASONS.BUDGET_EXHAUSTED };
91
+ }
92
+ if (isFetchFailedWithStatus(err, (s) => s === 401 || s === 403)) {
93
+ return { retry: false, reason: RETRY_REASONS.AUTH_FAILED };
94
+ }
95
+ }
96
+ // (4) Retry-worthy.
97
+ if (report.status === "failed") {
98
+ return { retry: true, reason: RETRY_REASONS.FAILED_STATUS };
99
+ }
100
+ for (const err of report.errors) {
101
+ if (isFetchFailedWithStatus(err, (s) => s >= 500 && s < 600)) {
102
+ return { retry: true, reason: RETRY_REASONS.UPSTREAM_5XX };
103
+ }
104
+ }
105
+ if (policy.retryOnPartial !== false
106
+ &&
107
+ report.status === "partial"
108
+ && report.posted === 0
109
+ && report.fetched > 0) {
110
+ return { retry: true, reason: RETRY_REASONS.PARTIAL_NO_POST };
111
+ }
112
+ // (5) Non-retry-by-default outcomes.
113
+ if (report.status === "success") {
114
+ return { retry: false, reason: RETRY_REASONS.SUCCESS };
115
+ }
116
+ if (report.status === "partial" && report.posted > 0) {
117
+ return { retry: false, reason: RETRY_REASONS.PARTIAL_WITH_POST };
118
+ }
119
+ if (report.status === "skipped") {
120
+ return { retry: false, reason: RETRY_REASONS.SKIPPED };
121
+ }
122
+ // Partial with fetched=0 and posted=0 — every fetch errored before
123
+ // returning items. The spec's matrix doesn't list this case; default
124
+ // to no-retry to keep the policy conservative (the §1.1 motivating
125
+ // failure is partial-no-post WITH fetched>0, which is already caught
126
+ // above). Operators who see this case in telemetry can override via
127
+ // `RetryPolicy.retryOn`.
128
+ return { retry: false, reason: RETRY_REASONS.NO_PROGRESS };
129
+ };
130
+ // ── Prior-attempt hint rendering (PRE_PASS_FAN_OUT_DESIGN.md §4.4) ────────
131
+ function xmlAttr(value) {
132
+ return value
133
+ .replace(/&/g, "&amp;")
134
+ .replace(/"/g, "&quot;")
135
+ .replace(/</g, "&lt;")
136
+ .replace(/>/g, "&gt;");
137
+ }
138
+ function xmlText(value) {
139
+ return value
140
+ .replace(/&/g, "&amp;")
141
+ .replace(/</g, "&lt;")
142
+ .replace(/>/g, "&gt;");
143
+ }
144
+ /**
145
+ * Generic MVP hint prose. §4.4 calls out the OQ-3 upgrade path
146
+ * (schema-aware classifier that promotes the hint to a specific
147
+ * substitution, e.g. `limit` → `maxResults`); the MVP stays generic so
148
+ * the hint-builder is not coupled to upstream argument-name schemas
149
+ * that drift independently.
150
+ */
151
+ const GENERIC_HINT_PROSE = "The previous attempt's call returned the error above. Re-read the partial body and try a different argument shape — the partial is the source of truth for tool argument names, not your memory of prior calls.";
152
+ function pickFirstError(errors) {
153
+ return errors.length > 0 ? errors[0] : undefined;
154
+ }
155
+ function renderErrorChild(err) {
156
+ const type = typeof err.type === "string" ? err.type : "unknown";
157
+ // Surface every string/number attribute (other than `type`) so the
158
+ // motivating §1.1 case carries `status="400"` and `message="…"`
159
+ // verbatim into the next attempt's prompt.
160
+ const attrEntries = Object.entries(err).filter(([k, v]) => k !== "type" && (typeof v === "string" || typeof v === "number"));
161
+ const attrs = attrEntries
162
+ .map(([k, v]) => `${xmlAttr(k)}="${xmlAttr(String(v))}"`)
163
+ .join(" ");
164
+ const tagName = xmlAttr(type.replace(/-/g, "_"));
165
+ return `<${tagName}${attrs ? " " + attrs : ""} />`;
166
+ }
167
+ function renderOnePriorAttempt(record, integrationKey) {
168
+ const openParts = [`attempt="${record.attempt}"`];
169
+ if (integrationKey !== undefined) {
170
+ openParts.push(`integration="${xmlAttr(integrationKey)}"`);
171
+ }
172
+ const lines = [`<prior_attempt_error ${openParts.join(" ")}>`];
173
+ const firstErr = pickFirstError(record.errors);
174
+ if (firstErr) {
175
+ lines.push(` ${renderErrorChild(firstErr)}`);
176
+ }
177
+ else if (record.parseError) {
178
+ lines.push(` <parse_failed reason="${xmlAttr(record.parseError)}" />`);
179
+ }
180
+ else {
181
+ // The attempt was retried but carried neither an explicit error nor
182
+ // a parseError — likely a coordinator-side timeout or quota error
183
+ // logged as a generic failed-status. Surface that explicitly so the
184
+ // model knows *something* went wrong, not just that retry was
185
+ // selected silently.
186
+ lines.push(` <failed status="${xmlAttr(record.status)}" />`);
187
+ }
188
+ lines.push(` <hint>${xmlText(GENERIC_HINT_PROSE)}</hint>`);
189
+ lines.push("</prior_attempt_error>");
190
+ return lines.join("\n");
191
+ }
192
+ /**
193
+ * Render the `<prior_attempt_error>` block sequence injected into a
194
+ * sub-session's prompt on attempt > 1. Returns the empty string when
195
+ * `attempts` is empty so callers can unconditionally concatenate the
196
+ * result.
197
+ *
198
+ * **Ordering.** Newest first — attempt N (most recent) appears before
199
+ * attempt N-1, etc. The model reads the most-recent failure top of
200
+ * page; deeper history is context-only.
201
+ */
202
+ export function buildPriorAttemptHintBlock(attempts, integrationKey) {
203
+ if (attempts.length === 0)
204
+ return "";
205
+ const newestFirst = [...attempts].reverse();
206
+ return newestFirst
207
+ .map((att) => renderOnePriorAttempt(att, integrationKey))
208
+ .join("\n");
209
+ }
210
+ //# sourceMappingURL=routine-fetch-window-retry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"routine-fetch-window-retry.js","sourceRoot":"","sources":["../../src/core/routine-fetch-window-retry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AA0DH,6EAA6E;AAE7E;;;;GAIG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,YAAY,EAAE,sBAAsB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S,CAAC,CAAC;IAC5D,KAAK,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC;IACrC,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,0BAA0B,CACxC,QAAqC,EACrC,cAA+B;IAE/B,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IACrC,MAAM,WAAW,GAAG,CAAC,GAAG,QAAQ,CAAC,CAAC,OAAO,EAAE,CAAC;IAC5C,OAAO,WAAW;SACf,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,qBAAqB,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC;SACxD,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC"}
@@ -1,33 +1,35 @@
1
1
  /**
2
- * `RoutineFetchWindowRunner` — Phase 4 / D1 pre-pass orchestration.
2
+ * `RoutineFetchWindowRunner` — pre-pass fan-out coordinator.
3
3
  *
4
- * ROUTINE_DATA_ACQUISITION_DESIGN.md §6.1.1 / Phase 4 D1 — every routine
5
- * dispatcher (morning_routine, today_refresh, hourly_check, evening /
6
- * weekly / monthly review) calls this runner immediately before
7
- * dispatching the parent session. The runner:
4
+ * ROUTINE_DATA_ACQUISITION_DESIGN.md §6.1.1 + PRE_PASS_FAN_OUT_DESIGN.md
5
+ * — every routine dispatcher (morning_routine, today_refresh,
6
+ * hourly_check, evening / weekly / monthly review) calls this runner
7
+ * immediately before dispatching the parent session. The runner:
8
8
  *
9
9
  * 1. Reads the per-routine plan from `ROUTINE_WINDOWS` and the current
10
- * integration state, fans out per-account where applicable, resolves
11
- * each row's predicate (`direct` / `delegated-same` / `delegated-cross`
12
- * / `native` / skip) via `buildAcquisitionPlan`, and renders an
13
- * `<acquisition-plan>` block.
14
- * 2. Synthesises a `routine.fetch_window` RoutineEvent, embeds the plan
15
- * block in `event.data.acquisitionPlanBlock` so ContextBuilder folds
16
- * it into the fetcher's prompt context, and routes the event
17
- * synchronously through the standard `IAgentRouter.execute` /
18
- * `PromptAssembler.assemble` pipeline. The session inherits the
19
- * `routine.fetch_window` ProcessKey binding (lite tier per F1 / §6.9)
20
- * and the dedicated `routine-fetch-window` agent profile.
21
- * 3. Parses the agent's single-JSON-line output into a structured
22
- * `FetchReport`, renders a `<fetch_report>` block, and logs one
23
- * `agent_actions` row via the dispatcher's audit logger.
24
- * 4. Returns the rendered block + parsed report so the caller can graft
25
- * the block into the **parent** routine event's
26
- * `event.data.fetchReportBlock`. ContextBuilder injects that block
27
- * verbatim into the parent session's prompt (mirrors the
28
- * `<gate_decision>` pattern used by hourly_check Stage 3).
10
+ * integration state, fans rows out per-account where applicable,
11
+ * resolves each row's predicate (`direct` / `delegated-same` /
12
+ * `delegated-cross` / `native` / skip), and partitions the plan
13
+ * by `IntegrationKey` via `splitAcquisitionPlanByIntegration`.
14
+ * 2. Spawns one lite-tier `routine.fetch_window` sub-session per
15
+ * integration in parallel (bounded by `prePassFanOutConcurrency`).
16
+ * Each sub-session sees exactly one partial the
17
+ * `{integration_partial}` placeholder in the
18
+ * `routine.fetch_window` task-flow is replaced with the body of
19
+ * `_partials/<integration prePassPartial>` so the lite-tier model
20
+ * never has to disambiguate cross-API argument names. Each
21
+ * sub-session runs through an independent retry loop bounded by
22
+ * `prePassMaxAttemptsPerIntegration`, `prePassBackoffMs`, and the
23
+ * per-integration / per-routine USD budget caps.
24
+ * 3. Merges the sub-reports into a single `FetchReport` (additive
25
+ * `<integration>` children on the `<fetch_report>` XML block) and
26
+ * returns it plus the rendered block.
27
+ * 4. The caller grafts the block into the **parent** routine event's
28
+ * `event.data.fetchReportBlock`. ContextBuilder injects it verbatim
29
+ * into the parent session's prompt (mirrors the `<gate_decision>`
30
+ * pattern used by hourly_check Stage 3).
29
31
  *
30
- * Failure-mode contract (Phase 4 D1 + design §11 R5 / OQ4):
32
+ * Failure-mode contract (PRE_PASS_FAN_OUT_DESIGN.md §5):
31
33
  *
32
34
  * - **No applicable rows** (routine has no windows in `ROUTINE_WINDOWS`,
33
35
  * every integration is disabled, every account list is empty) — the
@@ -35,16 +37,17 @@
35
37
  * `fetched=posted=duplicates=0`. The parent routine still runs; the
36
38
  * block is informational only.
37
39
  * - **Pre-pass session errors** (binding resolve fails, agent throws,
38
- * JSON parse fails) — the runner logs the failure and returns a
39
- * `<fetch_report status="failed">` with one `pre-pass-failed` error.
40
- * Pre-pass cost gains are forfeit for this tick; the parent routine
41
- * continues with whatever observations the rest of the plan produced.
40
+ * JSON parse fails) — recorded per-attempt; the retry loop fires up
41
+ * to `maxAttempts` before giving up. Final per-integration status
42
+ * surfaces in `<integration status="failed">`. Pre-pass cost gains
43
+ * are forfeit for that integration; siblings are unaffected.
42
44
  * Throwing here would otherwise propagate up and abort the parent
43
45
  * routine — the opposite of P3 ("Lite for Fetch, Medium for Decide").
44
46
  * - **Partial success** — the report's `errors` array carries per-row
45
- * failures (`no-surface`, `fetch-failed`, `budget-exhausted`). The
46
- * block surfaces them so the parent prompt can decide whether to
47
- * treat its observations view as complete.
47
+ * failures (`no-surface`, `fetch-failed`, `budget-exhausted`,
48
+ * `budget-cap`, `global-budget-cap`). The block surfaces them so the
49
+ * parent prompt can decide whether to treat its observations view as
50
+ * complete.
48
51
  */
49
52
  import type Database from "better-sqlite3";
50
53
  import type { BackendId, Event, IntegrationKey, IntegrationState } from "@aitne/shared";
@@ -80,6 +83,56 @@ export interface FetchReport {
80
83
  failureReason?: string;
81
84
  /** Stable ID for telemetry tie-back; mirrors the fetcher event's correlationId. */
82
85
  fetcherCorrelationId?: string;
86
+ /**
87
+ * PRE_PASS_FAN_OUT_DESIGN.md §4.5 — per-integration breakdown. Top-level
88
+ * counts above already aggregate the children; the breakdown lets
89
+ * downstream consumers (parent task-flow prose, dashboard renderers)
90
+ * branch per integration. Absent on the `skipped` / `failed` paths
91
+ * that short-circuit before fan-out (no-routine-key, no-windows,
92
+ * empty plan, plan-assembly-failed).
93
+ */
94
+ perIntegration?: ReadonlyArray<SubReport>;
95
+ }
96
+ /**
97
+ * PRE_PASS_FAN_OUT_DESIGN.md §4.3 — one attempt of one integration's
98
+ * sub-session. The fan-out coordinator records one of these per
99
+ * `agentRouter.execute` invocation; `defaultRetryDecision` consumes
100
+ * the latest record to decide whether to spawn another attempt.
101
+ */
102
+ export interface SubAttemptRecord {
103
+ /** 1-indexed. */
104
+ attempt: number;
105
+ status: FetchReport["status"];
106
+ fetched: number;
107
+ posted: number;
108
+ duplicates: number;
109
+ errors: ReadonlyArray<Record<string, unknown>>;
110
+ /** Set when the agent's output failed strict-JSON parse. */
111
+ parseError?: string;
112
+ fetcherCorrelationId: string;
113
+ /** ISO 8601 UTC. */
114
+ startedAt: string;
115
+ /** ISO 8601 UTC. */
116
+ endedAt: string;
117
+ costUsd: number;
118
+ numTurns: number;
119
+ }
120
+ /**
121
+ * PRE_PASS_FAN_OUT_DESIGN.md §4.3 — final per-integration verdict the
122
+ * coordinator emits after its retry loop terminates. Mirrors the
123
+ * fields of the last `SubAttemptRecord` (the final attempt's outcome
124
+ * is the integration's effective outcome) plus the integration key
125
+ * and the full attempt history.
126
+ */
127
+ export interface SubReport extends SubAttemptRecord {
128
+ integrationKey: IntegrationKey;
129
+ /** Full attempt history; `attempts[attempts.length - 1]` matches the inherited fields. */
130
+ attempts: ReadonlyArray<SubAttemptRecord>;
131
+ /**
132
+ * True iff the loop exhausted `maxAttempts` (or a budget/global cap
133
+ * tripped) without reaching a non-retryable success state.
134
+ */
135
+ retriesExhausted: boolean;
83
136
  }
84
137
  export interface RoutineFetchWindowResult {
85
138
  report: FetchReport;
@@ -100,6 +153,24 @@ export interface RoutineFetchWindowRunnerDeps {
100
153
  * doesn't need to depend on the registry directly.
101
154
  */
102
155
  getActiveMailAccounts: () => readonly MailAccount[];
156
+ /**
157
+ * Lazy accessor for the dashboard SSE event broadcaster (A2 / B2
158
+ * observability extension). When set, the runner emits
159
+ * `kind: "prepass_started"` / `"prepass_completed"` payloads to the
160
+ * default `event` SSE channel so the setup wizard can render the
161
+ * "Fetching your mail and Notion data…" sub-step distinctly from
162
+ * the parent routine's `routine_started` / `routine_completed`
163
+ * envelope. Returns `null` when the dispatcher has not wired a
164
+ * broadcaster yet (test paths, headless installs); the runner
165
+ * treats every call as fire-and-forget and never propagates a
166
+ * broadcaster failure into the parent dispatch.
167
+ *
168
+ * Optional — when undefined the runner runs exactly as it did
169
+ * pre-A2, including the empty-plan short-circuit.
170
+ */
171
+ getEventBroadcaster?: () => {
172
+ broadcastEvent: (data: unknown) => void;
173
+ } | null;
103
174
  }
104
175
  /**
105
176
  * Compose the per-execute `allowedToolsOverride` for the pre-pass. The
@@ -118,6 +189,22 @@ export interface RoutineFetchWindowRunnerDeps {
118
189
  * the partial records `no-surface` and the runner's report carries
119
190
  * the gap forward to the parent routine.
120
191
  *
192
+ * `ToolSearch` is appended for Claude sessions whenever at least one
193
+ * descriptor-bound MCP tool is present. Claude Code 2.1+ defers large
194
+ * MCP tool manifests (`mcp__claude_ai_Gmail__*`,
195
+ * `mcp__claude_ai_Google_Calendar__*`, `mcp__claude_ai_Notion__*`, …)
196
+ * behind `ToolSearch`, so the model must call `ToolSearch` to load a
197
+ * deferred tool's schema before it can be invoked. Without `ToolSearch`
198
+ * allowed, the Haiku fetcher emits a denied ToolSearch call on its
199
+ * first turn, gives up, and returns text with no JSON — the parent
200
+ * routine then sees `<fetch_report status="failed" reason="no-json-object">`.
201
+ * Mirrors the same workaround in `claude-delegated.ts` (delegated proxy
202
+ * `allowedTools: [toolName, "ToolSearch"]`). Codex / Gemini have no
203
+ * per-spawn allowedTools surface today and ignore the override entirely
204
+ * (CLAUDE.md acknowledges the gap), so the `ToolSearch` widening is
205
+ * gated on `sessionBackend === "claude"` to keep the list minimal for
206
+ * other backends.
207
+ *
121
208
  * Exported for unit testing — the runner consumes it via
122
209
  * `composePrePassAllowedTools` at dispatch time.
123
210
  */
@@ -162,6 +249,65 @@ export declare function renderFetchReportBlock(report: FetchReport, meta: {
162
249
  routine: RoutineWindowKey | string;
163
250
  agentDay: string;
164
251
  }): string;
252
+ /**
253
+ * Resolve the aggregate `<fetch_report>` status from a set of
254
+ * sub-reports' final statuses, per §4.5:
255
+ *
256
+ * - `success` iff every non-skipped sub-report is `success`. Skipped
257
+ * sub-reports do not count against success.
258
+ * - `failed` iff every non-skipped sub-report is `failed`.
259
+ * - `partial` for any other mix (incl. one success + one failed).
260
+ * - `skipped` only when the input is empty (the caller handles
261
+ * "every sub-report skipped" separately — the runner short-circuits
262
+ * before fan-out when no integrations are active).
263
+ *
264
+ * Exported for unit testing the status-resolution branch in isolation.
265
+ */
266
+ export declare function aggregateFanOutStatus(subReports: readonly SubReport[]): FetchReport["status"];
267
+ /** Headline numbers for one integration's full retry chain. */
268
+ export interface IntegrationSummary {
269
+ key: IntegrationKey;
270
+ status: FetchReport["status"];
271
+ attempts: number;
272
+ fetched: number;
273
+ posted: number;
274
+ duplicates: number;
275
+ costUsd: number;
276
+ durationMs: number;
277
+ /** Set only when status === "failed"; first error message of final attempt. */
278
+ finalError?: string;
279
+ }
280
+ /** Headline numbers for the whole fan-out routine. */
281
+ export interface AggregateSummary {
282
+ status: FetchReport["status"];
283
+ fetched: number;
284
+ posted: number;
285
+ duplicates: number;
286
+ costUsd: number;
287
+ }
288
+ export declare function summarizeIntegrationReport(sub: SubReport): IntegrationSummary;
289
+ export declare function summarizeFetchReport(report: FetchReport): AggregateSummary;
290
+ /**
291
+ * Merge fan-out sub-reports into a single `FetchReport` + the rendered
292
+ * `<fetch_report>` XML block the parent routine sees. §4.5.
293
+ *
294
+ * - Counts (`fetched`, `posted`, `duplicates`): arithmetic sum.
295
+ * - `errors`: concatenation, each error tagged with
296
+ * `integration: <key>` (and the per-attempt rows already carry
297
+ * `attempt: <n>` via the runner's per-attempt error-recording —
298
+ * `mergeSubReports` does not invent annotations beyond `integration`).
299
+ * - `status`: `aggregateFanOutStatus`.
300
+ * - `failureReason`: only when aggregate is `failed`; one-line summary
301
+ * listing the failed integrations and their attempt counts.
302
+ * - `perIntegration`: sorted by `INTEGRATION_KEYS` order regardless of
303
+ * completion order (deterministic — §4.6).
304
+ *
305
+ * Pure function: no side effects, no DB / clock dependencies.
306
+ */
307
+ export declare function mergeSubReports(subReports: readonly SubReport[], routine: RoutineWindowKey | string, agentDay: string): {
308
+ report: FetchReport;
309
+ block: string;
310
+ };
165
311
  export declare class RoutineFetchWindowRunner {
166
312
  private readonly db;
167
313
  private readonly config;
@@ -170,7 +316,21 @@ export declare class RoutineFetchWindowRunner {
170
316
  private readonly audit;
171
317
  private readonly prompt;
172
318
  private readonly getActiveMailAccounts;
319
+ private readonly getEventBroadcaster;
173
320
  constructor(deps: RoutineFetchWindowRunnerDeps);
321
+ /**
322
+ * Broadcast a single pre-pass progress event to the dashboard SSE
323
+ * channel. Failure is contained — the broadcaster contract is
324
+ * fire-and-forget and a misbehaving writer must not affect the
325
+ * runner's return value or the parent routine's dispatch.
326
+ *
327
+ * Schema (default `event` SSE channel, matches existing
328
+ * `kind: "main_backend_changed"` / `"routine_started"` pattern):
329
+ * { kind, routine, source, correlationId, timestamp, status? }
330
+ * `status` is set on `prepass_completed` only and reflects the
331
+ * FetchReport.status field (success / partial / failed / skipped).
332
+ */
333
+ private broadcastPrepassProgress;
174
334
  /**
175
335
  * Execute the pre-pass for `parentEvent`. Returns the fetch report
176
336
  * and rendered `<fetch_report>` block; callers graft the block into
@@ -183,6 +343,72 @@ export declare class RoutineFetchWindowRunner {
183
343
  * but the seam exists for future divergence).
184
344
  */
185
345
  run(parentEvent: Event, routineKey?: RoutineWindowKey): Promise<RoutineFetchWindowResult>;
346
+ private runImpl;
347
+ private buildFanOutPlanContext;
348
+ /**
349
+ * §5 BackendQuotaError row + §4.4 retryEscalationTier — re-derive the
350
+ * per-integration sub-plan against the CURRENT attempt's binding so a
351
+ * cross-backend swap (escalation tier flips main backend, or
352
+ * `prePassRetryEscalationTier` swaps the per-attempt tier) keeps the
353
+ * plan's `<fetch mode="…">` attribute aligned with the partial body's
354
+ * remaining mode-branch (the partial is filtered for the new backend
355
+ * via `renderPartialForFanOut`). Returns null only when the
356
+ * integration becomes unreachable on the new backend (e.g. native
357
+ * mode bound to A but the attempt re-resolves to B); the runner
358
+ * passes the call through to record the original sub-plan and let
359
+ * the agent emit `no-surface` errors organically.
360
+ *
361
+ * Pure: snapshot inputs (`integrationsSnapshot`, `accounts`,
362
+ * `timestamps`) are frozen at run() entry; only `sessionBackend`
363
+ * varies across attempts. Re-derivation is cheap —
364
+ * `splitAcquisitionPlanByIntegration` walks `ROUTINE_WINDOWS[routine]`
365
+ * (a small constant) without I/O.
366
+ */
367
+ private rebuildSubPlanForBackend;
368
+ private buildRetryPolicy;
369
+ private fanOutConcurrency;
370
+ private retryEscalationTier;
371
+ private runFanOut;
372
+ private runOneIntegrationWithRetry;
373
+ /**
374
+ * Emit `prepass_subsession_started` for an attempt that is about to run.
375
+ * Called at the TOP of every loop iteration so the started/completed
376
+ * pair is symmetric across all paths — including binding-resolve-failed
377
+ * and budget-cap short-circuits, which previously emitted neither.
378
+ */
379
+ private emitSubSessionStarted;
380
+ /**
381
+ * Emit `prepass_subsession_completed` for an attempt that has just
382
+ * recorded its outcome. Mirror of `emitSubSessionStarted` — invoked
383
+ * once per iteration after every code path that pushes a record
384
+ * (success, parse error, agent throw, binding-resolve-failed,
385
+ * global-budget-cap, per-integration-budget-cap).
386
+ */
387
+ private emitSubSessionCompleted;
388
+ private createFanOutFetcherEvent;
389
+ private sliceIntegrationSnapshot;
390
+ private attemptRecordFromResult;
391
+ private failedAttemptRecord;
392
+ private budgetCapAttemptRecord;
393
+ private didExhaustRetries;
394
+ private backoffForAttempt;
395
+ /**
396
+ * Unified audit-row companion for every fan-out failure mode —
397
+ * binding-resolve-failed, global-budget-cap, budget-cap (per-integration),
398
+ * context-build-failed, and agent-execute-failed. Routes through
399
+ * `audit.logError` (writes `result='failed'`) with a `prePass` payload
400
+ * so `MetricsCollector.collectPrePassMetrics` can see every failure
401
+ * mode without a parallel `result='success'` row. Before this helper
402
+ * existed, the four pre-execute branches wrote nothing at all and the
403
+ * agent-execute path wrote a `failureKind`-only row that the aggregator
404
+ * silently skipped (it filters on `detail.prePass` being a non-null
405
+ * object). Cost / tokens are intentionally NOT supplied — pre-execute
406
+ * paths have zero cost, the agent-execute throw path has no usable
407
+ * AgentResult, so any figure here would be a guess; the aggregator
408
+ * coalesces missing `cost_usd` to 0.
409
+ */
410
+ private logFanOutFailure;
411
+ private logFanOutAttempt;
186
412
  /**
187
413
  * Helper for the failure paths — renders a `<fetch_report status="failed">`
188
414
  * block and logs the underlying error. Never throws so the caller can
@@ -1 +1 @@
1
- {"version":3,"file":"routine-fetch-window-runner.d.ts","sourceRoot":"","sources":["../../src/core/routine-fetch-window-runner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AAEH,OAAO,KAAK,QAAQ,MAAM,gBAAgB,CAAC;AAC3C,OAAO,KAAK,EAEV,SAAS,EACT,KAAK,EACL,cAAc,EACd,gBAAgB,EAGjB,MAAM,eAAe,CAAC;AASvB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEhD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,KAAK,EACV,YAAY,EACZ,eAAe,EAChB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAGL,KAAK,gBAAgB,EACtB,MAAM,sBAAsB,CAAC;AAY9B;;;;;;;;;;;;;GAaG;AACH,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,SAAS,GAAG,SAAS,GAAG,QAAQ,GAAG,SAAS,CAAC;IACrD,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,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