@inflexa-ai/harness 0.1.1 → 0.3.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 (330) hide show
  1. package/README.md +48 -0
  2. package/dist/agents/conversation-agent.d.ts +15 -11
  3. package/dist/agents/conversation-agent.js +31 -34
  4. package/dist/agents/report-builder.js +2 -1
  5. package/dist/agents/sandbox/bulk-transcriptomics-agent.js +1 -1
  6. package/dist/agents/sandbox/cheminformatics-agent.js +1 -19
  7. package/dist/agents/sandbox/chromatin-agent.js +1 -10
  8. package/dist/agents/sandbox/dna-methylation-agent.js +1 -10
  9. package/dist/agents/sandbox/drug-repurposing-agent.js +4 -14
  10. package/dist/agents/sandbox/enrichment-agent.js +1 -10
  11. package/dist/agents/sandbox/ephemeral-executor.js +1 -10
  12. package/dist/agents/sandbox/genomic-variant-agent.js +1 -3
  13. package/dist/agents/sandbox/immune-profiling-agent.js +1 -13
  14. package/dist/agents/sandbox/metabolomics-agent.js +1 -1
  15. package/dist/agents/sandbox/microbiome-agent.js +1 -1
  16. package/dist/agents/sandbox/multi-omics-integration-agent.js +1 -12
  17. package/dist/agents/sandbox/multimodal-sc-agent.js +1 -1
  18. package/dist/agents/sandbox/network-agent.js +1 -10
  19. package/dist/agents/sandbox/pkpd-clinical-response-agent.js +2 -8
  20. package/dist/agents/sandbox/proteomics-agent.js +1 -1
  21. package/dist/agents/sandbox/scientific-executor.js +1 -10
  22. package/dist/agents/sandbox/shared.d.ts +20 -6
  23. package/dist/agents/sandbox/shared.js +50 -39
  24. package/dist/agents/sandbox/single-cell-agent.js +1 -1
  25. package/dist/agents/sandbox/spatial-omics-agent.js +1 -1
  26. package/dist/agents/sandbox/statistical-modeling-agent.js +1 -1
  27. package/dist/agents/sandbox/translational-safety-agent.js +3 -9
  28. package/dist/agents/sandbox/types.d.ts +1 -1
  29. package/dist/agents/system-prompt.d.ts +37 -11
  30. package/dist/agents/system-prompt.js +35 -12
  31. package/dist/app/chat-turn.d.ts +3 -0
  32. package/dist/app/chat-turn.js +3 -1
  33. package/dist/app/data-profile-orientation.d.ts +34 -0
  34. package/dist/app/data-profile-orientation.js +117 -0
  35. package/dist/app/synthesize-run.d.ts +3 -0
  36. package/dist/app/synthesize-run.js +3 -1
  37. package/dist/contracts/schemas/chat-parts.d.ts +9 -9
  38. package/dist/execution/artifact-metadata.d.ts +3 -0
  39. package/dist/execution/artifact-metadata.js +10 -3
  40. package/dist/execution/artifact-registration.d.ts +2 -1
  41. package/dist/execution/artifact-registration.js +8 -2
  42. package/dist/execution/ephemeral-runner.d.ts +16 -0
  43. package/dist/execution/ephemeral-runner.js +31 -5
  44. package/dist/execution/post-step-pipeline.d.ts +3 -0
  45. package/dist/execution/post-step-pipeline.js +24 -4
  46. package/dist/execution/reconcile-manifest.d.ts +7 -0
  47. package/dist/execution/reconcile-manifest.js +19 -5
  48. package/dist/execution/report-runner.d.ts +3 -0
  49. package/dist/execution/report-runner.js +4 -4
  50. package/dist/execution/run-synthesis.js +20 -19
  51. package/dist/execution/step-summary.d.ts +3 -0
  52. package/dist/execution/step-summary.js +6 -3
  53. package/dist/index.d.ts +9 -2
  54. package/dist/index.js +24 -5
  55. package/dist/lib/chrome.d.ts +4 -1
  56. package/dist/lib/chrome.js +10 -7
  57. package/dist/lib/console-logger.d.ts +19 -0
  58. package/dist/lib/console-logger.js +62 -0
  59. package/dist/lib/logger.d.ts +88 -0
  60. package/dist/lib/logger.js +37 -0
  61. package/dist/lib/otel.d.ts +2 -1
  62. package/dist/lib/otel.js +8 -3
  63. package/dist/loop/__fixtures__/scripted-provider.d.ts +2 -2
  64. package/dist/loop/__fixtures__/scripted-provider.js +2 -1
  65. package/dist/loop/metrics.d.ts +33 -1
  66. package/dist/loop/metrics.js +56 -2
  67. package/dist/loop/run-agent.d.ts +13 -1
  68. package/dist/loop/run-agent.js +19 -4
  69. package/dist/memory/card-builders.d.ts +8 -1
  70. package/dist/memory/card-builders.js +20 -3
  71. package/dist/memory/reconstruct-cards.js +4 -3
  72. package/dist/memory/thread-history.d.ts +27 -2
  73. package/dist/memory/thread-history.js +45 -5
  74. package/dist/memory/working-memory.d.ts +93 -10
  75. package/dist/memory/working-memory.js +220 -84
  76. package/dist/prompts/SOUL.d.ts +22 -9
  77. package/dist/prompts/SOUL.js +56 -37
  78. package/dist/prompts/analogical-reasoner.d.ts +1 -1
  79. package/dist/prompts/analogical-reasoner.js +2 -2
  80. package/dist/prompts/briefing.d.ts +100 -0
  81. package/dist/prompts/briefing.js +166 -0
  82. package/dist/prompts/conversation.d.ts +1 -1
  83. package/dist/prompts/conversation.js +94 -440
  84. package/dist/prompts/literature-reviewer.d.ts +1 -1
  85. package/dist/prompts/literature-reviewer.js +10 -10
  86. package/dist/prompts/planner.js +28 -59
  87. package/dist/prompts/report-builder.d.ts +1 -1
  88. package/dist/prompts/report-builder.js +71 -24
  89. package/dist/prompts/sandbox/bulk-transcriptomics-agent.d.ts +1 -1
  90. package/dist/prompts/sandbox/bulk-transcriptomics-agent.js +2 -7
  91. package/dist/prompts/sandbox/cheminformatics-agent.d.ts +1 -1
  92. package/dist/prompts/sandbox/cheminformatics-agent.js +11 -15
  93. package/dist/prompts/sandbox/chromatin-agent.d.ts +1 -1
  94. package/dist/prompts/sandbox/chromatin-agent.js +3 -7
  95. package/dist/prompts/sandbox/data-profiler.d.ts +1 -1
  96. package/dist/prompts/sandbox/data-profiler.js +13 -8
  97. package/dist/prompts/sandbox/dna-methylation-agent.d.ts +1 -1
  98. package/dist/prompts/sandbox/dna-methylation-agent.js +2 -7
  99. package/dist/prompts/sandbox/drug-repurposing-agent.d.ts +1 -1
  100. package/dist/prompts/sandbox/drug-repurposing-agent.js +15 -16
  101. package/dist/prompts/sandbox/enrichment-agent.d.ts +1 -1
  102. package/dist/prompts/sandbox/enrichment-agent.js +2 -9
  103. package/dist/prompts/sandbox/genomic-variant-agent.d.ts +1 -1
  104. package/dist/prompts/sandbox/genomic-variant-agent.js +2 -6
  105. package/dist/prompts/sandbox/immune-profiling-agent.d.ts +1 -1
  106. package/dist/prompts/sandbox/immune-profiling-agent.js +3 -8
  107. package/dist/prompts/sandbox/metabolomics-agent.d.ts +1 -1
  108. package/dist/prompts/sandbox/metabolomics-agent.js +1 -7
  109. package/dist/prompts/sandbox/microbiome-agent.d.ts +1 -1
  110. package/dist/prompts/sandbox/microbiome-agent.js +2 -7
  111. package/dist/prompts/sandbox/multi-omics-integration-agent.d.ts +1 -1
  112. package/dist/prompts/sandbox/multi-omics-integration-agent.js +2 -8
  113. package/dist/prompts/sandbox/multimodal-sc-agent.d.ts +1 -1
  114. package/dist/prompts/sandbox/multimodal-sc-agent.js +2 -7
  115. package/dist/prompts/sandbox/network-agent.d.ts +1 -1
  116. package/dist/prompts/sandbox/network-agent.js +2 -7
  117. package/dist/prompts/sandbox/proteomics-agent.d.ts +1 -1
  118. package/dist/prompts/sandbox/proteomics-agent.js +2 -9
  119. package/dist/prompts/sandbox/single-cell-agent.d.ts +1 -1
  120. package/dist/prompts/sandbox/single-cell-agent.js +2 -9
  121. package/dist/prompts/sandbox/spatial-omics-agent.d.ts +1 -1
  122. package/dist/prompts/sandbox/spatial-omics-agent.js +3 -6
  123. package/dist/prompts/sandbox/statistical-modeling-agent.d.ts +1 -1
  124. package/dist/prompts/sandbox/statistical-modeling-agent.js +2 -7
  125. package/dist/prompts/sandbox/translational-safety-agent.d.ts +1 -1
  126. package/dist/prompts/sandbox/translational-safety-agent.js +13 -14
  127. package/dist/prompts/sandbox-standards.d.ts +22 -14
  128. package/dist/prompts/sandbox-standards.js +91 -71
  129. package/dist/prompts/synthesis-agent.d.ts +1 -1
  130. package/dist/prompts/synthesis-agent.js +33 -131
  131. package/dist/provenance/collector.js +1 -1
  132. package/dist/providers/ai-sdk.js +31 -4
  133. package/dist/providers/prompt-cache.d.ts +74 -0
  134. package/dist/providers/prompt-cache.js +77 -0
  135. package/dist/providers/types.d.ts +33 -0
  136. package/dist/reference-data/catalog.d.ts +131 -0
  137. package/dist/reference-data/catalog.js +348 -0
  138. package/dist/reference-data/receipt.d.ts +41 -0
  139. package/dist/reference-data/receipt.js +40 -0
  140. package/dist/runtime/boot.d.ts +2 -2
  141. package/dist/runtime/boot.js +1 -1
  142. package/dist/runtime/connection-budget.d.ts +2 -2
  143. package/dist/runtime/connection-budget.js +5 -3
  144. package/dist/runtime/dbos.d.ts +7 -7
  145. package/dist/runtime/dbos.js +14 -11
  146. package/dist/runtime/shutdown.d.ts +2 -2
  147. package/dist/runtime/shutdown.js +4 -3
  148. package/dist/sandbox/create-sandbox.d.ts +2 -2
  149. package/dist/sandbox/docker-client.d.ts +2 -2
  150. package/dist/sandbox/docker-client.js +4 -1
  151. package/dist/sandbox/k8s-client.d.ts +3 -0
  152. package/dist/sandbox/k8s-client.js +5 -4
  153. package/dist/sandbox/notification-sweep.d.ts +3 -3
  154. package/dist/sandbox/notification-sweep.js +4 -2
  155. package/dist/sandbox/reaper.d.ts +3 -3
  156. package/dist/sandbox/reaper.js +7 -4
  157. package/dist/sandbox/watchdog.d.ts +3 -3
  158. package/dist/sandbox/watchdog.js +8 -2
  159. package/dist/schemas/data-profile-schemas.js +5 -3
  160. package/dist/schemas/plan-schemas.d.ts +21 -21
  161. package/dist/schemas/plan-schemas.js +9 -3
  162. package/dist/schemas/run-synthesis.d.ts +8 -4
  163. package/dist/schemas/run-synthesis.js +92 -56
  164. package/dist/schemas/validate-plan.js +1 -1
  165. package/dist/schemas/workflow-state.d.ts +7 -1
  166. package/dist/schemas/workflow-state.js +33 -19
  167. package/dist/state/artifacts.d.ts +13 -0
  168. package/dist/state/artifacts.js +27 -0
  169. package/dist/state/data-profile.d.ts +64 -5
  170. package/dist/state/index.d.ts +3 -3
  171. package/dist/state/index.js +1 -1
  172. package/dist/state/init.d.ts +2 -1
  173. package/dist/state/init.js +5 -6
  174. package/dist/tasks/data-profile.d.ts +25 -2
  175. package/dist/tasks/data-profile.js +95 -39
  176. package/dist/tools/bio/chembl.d.ts +38 -0
  177. package/dist/tools/bio/chembl.js +138 -0
  178. package/dist/tools/bio/comptox.d.ts +50 -0
  179. package/dist/tools/bio/comptox.js +149 -0
  180. package/dist/tools/bio/get-impc-ko-profile.js +9 -6
  181. package/dist/tools/bio/index.d.ts +5 -17
  182. package/dist/tools/bio/index.js +5 -17
  183. package/dist/tools/bio/keys.d.ts +14 -9
  184. package/dist/tools/bio/keys.js +16 -16
  185. package/dist/tools/bio/opentargets.d.ts +38 -0
  186. package/dist/tools/bio/opentargets.js +89 -0
  187. package/dist/tools/bio/pubchem.d.ts +29 -0
  188. package/dist/tools/bio/pubchem.js +92 -0
  189. package/dist/tools/bio/pubmed.d.ts +51 -0
  190. package/dist/tools/bio/pubmed.js +100 -0
  191. package/dist/tools/bio/search-bgee-expression.js +12 -6
  192. package/dist/tools/bio/search-clinical-trials.js +16 -5
  193. package/dist/tools/bio/search-dgidb.d.ts +11 -1
  194. package/dist/tools/bio/search-dgidb.js +92 -78
  195. package/dist/tools/bio/search-faers.js +8 -4
  196. package/dist/tools/bio/search-geo-datasets.js +20 -6
  197. package/dist/tools/bio/search-gwas-catalog.d.ts +1 -1
  198. package/dist/tools/bio/search-pharmgkb.js +10 -4
  199. package/dist/tools/display/index.d.ts +1 -0
  200. package/dist/tools/display/index.js +1 -0
  201. package/dist/tools/display/normalize-echart-spec.d.ts +61 -0
  202. package/dist/tools/display/normalize-echart-spec.js +211 -0
  203. package/dist/tools/display/show-user.d.ts +6 -1
  204. package/dist/tools/display/show-user.js +25 -12
  205. package/dist/tools/execute-plan.js +5 -2
  206. package/dist/tools/iterate-report.d.ts +171 -118
  207. package/dist/tools/iterate-report.js +336 -96
  208. package/dist/tools/lib/chembl-client.d.ts +12 -0
  209. package/dist/tools/lib/chembl-client.js +127 -0
  210. package/dist/tools/lib/ctx-ops.d.ts +224 -0
  211. package/dist/tools/lib/ctx-ops.js +450 -0
  212. package/dist/tools/lib/iuphar-client.js +10 -1
  213. package/dist/tools/lib/openfda-client.js +11 -3
  214. package/dist/tools/lib/pathway-client.js +10 -4
  215. package/dist/tools/lib/pubchem-ops.d.ts +74 -0
  216. package/dist/tools/lib/pubchem-ops.js +224 -0
  217. package/dist/tools/memory/update-working-memory.d.ts +45 -7
  218. package/dist/tools/memory/update-working-memory.js +111 -41
  219. package/dist/tools/report/index.d.ts +3 -2
  220. package/dist/tools/report/index.js +3 -2
  221. package/dist/tools/research/generate-analogy-report.js +25 -12
  222. package/dist/tools/research/generate-plan.d.ts +12 -5
  223. package/dist/tools/research/generate-plan.js +168 -37
  224. package/dist/tools/research/index.d.ts +1 -0
  225. package/dist/tools/research/index.js +1 -0
  226. package/dist/tools/research/inspect-data-profile.d.ts +85 -0
  227. package/dist/tools/research/inspect-data-profile.js +161 -0
  228. package/dist/tools/research/literature-reviewer.d.ts +3 -0
  229. package/dist/tools/research/literature-reviewer.js +5 -6
  230. package/dist/tools/sandbox/list-available-packages.d.ts +79 -5
  231. package/dist/tools/sandbox/list-available-packages.js +152 -10
  232. package/dist/tools/sandbox/list-available-refs.d.ts +141 -5
  233. package/dist/tools/sandbox/list-available-refs.js +647 -134
  234. package/dist/tools/sandbox/report-blocker.d.ts +39 -9
  235. package/dist/tools/sandbox/report-blocker.js +43 -20
  236. package/dist/tools/workspace/execute-command.d.ts +3 -0
  237. package/dist/tools/workspace/execute-command.js +3 -1
  238. package/dist/tools/workspace/read-file.js +4 -5
  239. package/dist/tools/workspace/run-exec.d.ts +4 -4
  240. package/dist/tools/workspace/run-exec.js +4 -4
  241. package/dist/tools/workspace/show-file.js +10 -6
  242. package/dist/tools/workspace/show-plan.js +12 -6
  243. package/dist/tools/workspace/workspace-search.d.ts +1 -1
  244. package/dist/tools/workspace/workspace-search.js +11 -5
  245. package/dist/workflows/execute-analysis.d.ts +46 -4
  246. package/dist/workflows/execute-analysis.js +118 -13
  247. package/dist/workflows/execute-target-assessment.d.ts +3 -0
  248. package/dist/workflows/execute-target-assessment.js +19 -15
  249. package/dist/workflows/sandbox-step.d.ts +9 -0
  250. package/dist/workflows/sandbox-step.js +39 -17
  251. package/dist/workflows/target-assessment/lib/citation-validator.js +2 -2
  252. package/dist/workflows/target-assessment/lib/clinical-consequence-annotator.js +2 -1
  253. package/dist/workflows/target-assessment/lib/llm-step.d.ts +3 -0
  254. package/dist/workflows/target-assessment/lib/llm-step.js +3 -1
  255. package/dist/workflows/target-assessment/lib/structured-llm.d.ts +3 -0
  256. package/dist/workflows/target-assessment/lib/structured-llm.js +1 -0
  257. package/dist/workflows/target-assessment/phase5-persist.d.ts +3 -0
  258. package/dist/workflows/target-assessment/phase5-persist.js +8 -3
  259. package/dist/workflows/target-assessment/progress.d.ts +2 -1
  260. package/dist/workflows/target-assessment/progress.js +4 -3
  261. package/dist/workspace/filesystem.js +163 -74
  262. package/dist/workspace/paths.d.ts +2 -2
  263. package/dist/workspace/paths.js +2 -2
  264. package/package.json +95 -96
  265. package/dist/execution/filesystem-artifact-registry.d.ts +0 -57
  266. package/dist/execution/filesystem-artifact-registry.js +0 -92
  267. package/dist/lib/identifiers.d.ts +0 -8
  268. package/dist/lib/identifiers.js +0 -10
  269. package/dist/lib/mime-detect.d.ts +0 -17
  270. package/dist/lib/mime-detect.js +0 -29
  271. package/dist/lib/streamed-download.d.ts +0 -28
  272. package/dist/lib/streamed-download.js +0 -111
  273. package/dist/lib/trace-context.d.ts +0 -11
  274. package/dist/lib/trace-context.js +0 -49
  275. package/dist/providers/llm-capabilities.d.ts +0 -33
  276. package/dist/providers/llm-capabilities.js +0 -58
  277. package/dist/schemas/render-step-prompt.d.ts +0 -32
  278. package/dist/schemas/render-step-prompt.js +0 -76
  279. package/dist/tools/bio/find-approval-precedent.d.ts +0 -32
  280. package/dist/tools/bio/find-approval-precedent.js +0 -72
  281. package/dist/tools/bio/get-article-details.d.ts +0 -11
  282. package/dist/tools/bio/get-article-details.js +0 -20
  283. package/dist/tools/bio/get-article-full-text.d.ts +0 -19
  284. package/dist/tools/bio/get-article-full-text.js +0 -32
  285. package/dist/tools/bio/get-bioactivity.d.ts +0 -11
  286. package/dist/tools/bio/get-bioactivity.js +0 -23
  287. package/dist/tools/bio/get-drug-info.d.ts +0 -9
  288. package/dist/tools/bio/get-drug-info.js +0 -22
  289. package/dist/tools/bio/get-mechanism.d.ts +0 -8
  290. package/dist/tools/bio/get-mechanism.js +0 -18
  291. package/dist/tools/bio/get-pubchem-assays.d.ts +0 -22
  292. package/dist/tools/bio/get-pubchem-assays.js +0 -107
  293. package/dist/tools/bio/get-pubchem-cross-refs.d.ts +0 -15
  294. package/dist/tools/bio/get-pubchem-cross-refs.js +0 -68
  295. package/dist/tools/bio/get-target-safety.d.ts +0 -18
  296. package/dist/tools/bio/get-target-safety.js +0 -26
  297. package/dist/tools/bio/search-compounds.d.ts +0 -22
  298. package/dist/tools/bio/search-compounds.js +0 -160
  299. package/dist/tools/bio/search-ctx-chemical.d.ts +0 -50
  300. package/dist/tools/bio/search-ctx-chemical.js +0 -130
  301. package/dist/tools/bio/search-ctx-exposure.d.ts +0 -55
  302. package/dist/tools/bio/search-ctx-exposure.js +0 -176
  303. package/dist/tools/bio/search-ctx-hazard.d.ts +0 -111
  304. package/dist/tools/bio/search-ctx-hazard.js +0 -178
  305. package/dist/tools/bio/search-opentargets.d.ts +0 -11
  306. package/dist/tools/bio/search-opentargets.js +0 -25
  307. package/dist/tools/bio/search-pubchem-compound.d.ts +0 -26
  308. package/dist/tools/bio/search-pubchem-compound.js +0 -110
  309. package/dist/tools/bio/search-pubmed.d.ts +0 -17
  310. package/dist/tools/bio/search-pubmed.js +0 -31
  311. package/dist/tools/bio/search-targets.d.ts +0 -9
  312. package/dist/tools/bio/search-targets.js +0 -20
  313. package/dist/tools/bio/search-toxcast.d.ts +0 -36
  314. package/dist/tools/bio/search-toxcast.js +0 -141
  315. package/dist/workflows/register-workflows.d.ts +0 -51
  316. package/dist/workflows/register-workflows.js +0 -48
  317. package/dist/workflows/resume-execute-analysis.d.ts +0 -70
  318. package/dist/workflows/resume-execute-analysis.js +0 -80
  319. package/dist/workflows/target-assessment/correction-loop.d.ts +0 -45
  320. package/dist/workflows/target-assessment/correction-loop.js +0 -62
  321. package/dist/workflows/target-assessment/steps/phase0-resolve.d.ts +0 -71
  322. package/dist/workflows/target-assessment/steps/phase0-resolve.js +0 -21
  323. package/dist/workflows/target-assessment/steps/phase1-aggregate.d.ts +0 -1018
  324. package/dist/workflows/target-assessment/steps/phase1-aggregate.js +0 -25
  325. package/dist/workspace/mount-strategy.d.ts +0 -50
  326. package/dist/workspace/mount-strategy.js +0 -67
  327. package/dist/workspace/provenance-collector.d.ts +0 -34
  328. package/dist/workspace/provenance-collector.js +0 -16
  329. package/dist/workspace/workspace-paths.d.ts +0 -26
  330. package/dist/workspace/workspace-paths.js +0 -31
@@ -1,66 +1,104 @@
1
1
  /**
2
- * Sandbox prompts — split into two layers.
2
+ * Sandbox prompts — split into two layers, both STATIC.
3
3
  *
4
- * - `sandboxOrientCorePrompt` — universal guidance for any agent that
5
- * talks to a sandbox (plannable steps, data profilers, report
6
- * builders, read-only ephemeral executors). Covers the workspace path
7
- * model, environment discovery, and tool-use discipline. Always
8
- * appended by `createSandboxAgent`, which substitutes the `{{WORKING_DIR}}`
9
- * and `{{ANALYSIS_ROOT}}` placeholders with the agent's concrete paths.
4
+ * - `sandboxOrientCorePrompt` — universal guidance for any agent that talks to
5
+ * a sandbox (plannable steps, the data profiler, the read-only ephemeral
6
+ * executor). Covers the workspace path model, the environment's hard limits,
7
+ * the output contract, and tool-use discipline. Always appended by
8
+ * `createSandboxAgent`.
10
9
  *
11
- * - `sandboxAnalysisStepStandardsPrompt` — conventions for plannable
12
- * analysis steps that produce reproducible script + output + figure
13
- * artifacts in their working directory. Opt-out via
14
- * `appendAnalysisStepStandards: false` for agents that don't fit
15
- * this mold (data-profiler, ephemeral-executor, report-builder).
10
+ * - `sandboxAnalysisStepStandardsPrompt` — conventions for plannable analysis
11
+ * steps that produce reproducible script + output + figure artifacts in their
12
+ * working directory. Opt out via `appendAnalysisStepStandards: false` for
13
+ * agents that don't fit this mold (data-profiler, ephemeral-executor).
14
+ *
15
+ * Neither layer names a concrete path, id, or any other per-step value, and
16
+ * neither carries a placeholder for one. That is load-bearing rather than
17
+ * stylistic: it is what makes the `systemPrompt` `createSandboxAgent` composes a
18
+ * pure function of the agent type, so every step of every run of a given agent
19
+ * sends a byte-identical prefix and the provider's prompt cache can hit it. The
20
+ * volatile particulars — working directory, analysis root, dataset, upstream
21
+ * results — ride in the step's briefing (its first user message; see
22
+ * `prompts/briefing.ts`), which is composed per dispatch and where per-step
23
+ * content belongs.
16
24
  */
17
25
  export const sandboxOrientCorePrompt = `# Sandbox Orient-Core
18
26
 
19
27
  These apply to every agent that talks to a sandbox.
20
28
 
29
+ ## Your Briefing Is Authoritative
30
+
31
+ Your first message is your briefing, composed for this step at the instant it was
32
+ dispatched — after every step it depends on had finished. It names your task, your
33
+ working directory and the read-only analysis root, what the input dataset is
34
+ (domain, organism, design, quality concerns, files), and what each upstream step
35
+ produced and where it put it. Work from it.
36
+
37
+ Do NOT re-derive what it already gives you: no filesystem hunt for your inputs, no
38
+ re-reading an upstream step whose summary you were handed, no re-deriving the
39
+ organism or the dimensions from raw bytes. Reach further only where the briefing is
40
+ genuinely thin for what you must do:
41
+
42
+ - \`inspect_data_profile\` — the full dataset profile (per-file metrics, warnings,
43
+ the profiler's narrative), paged. It is the ONLY record of what the input data
44
+ IS; no file on disk carries it. Use it when the briefing's orientation is not
45
+ enough, or when it carried none.
46
+ - \`read_file\` on an upstream step's summary — its path is in your briefing — when
47
+ the excerpt you were handed is not enough to build on.
48
+ - \`workspace_search({ query })\` — natural-language search for a file the briefing
49
+ does not name. Optional \`type\` filter (\`input\` | \`output\` | \`summary\` |
50
+ \`synthesis\`) and \`limit\` (1-50, default 8). Returns paths, descriptions, and
51
+ metadata — not file contents.
52
+
21
53
  ## Your Workspace
22
54
 
23
- You work in your **working directory**: \`{{WORKING_DIR}}\`
55
+ Your **working directory** — writable, and your cwd — and the read-only
56
+ **analysis root** are named in your briefing. Use those paths exactly; do not
57
+ invent or guess one.
24
58
 
25
- - **Relative paths resolve against it** — in \`read_file\`, \`list_files\`,
26
- \`file_stat\`, \`grep\`, \`write_file\`, \`edit_file\`, \`execute_command\`, and
27
- any script you run. \`output/de.csv\` means \`{{WORKING_DIR}}/output/de.csv\`
28
- everywhere — a file you write at a relative path is read back at the same
29
- relative path.
59
+ - **Relative paths resolve against your working directory** — in \`read_file\`,
60
+ \`list_files\`, \`file_stat\`, \`grep\`, \`write_file\`, \`edit_file\`,
61
+ \`execute_command\`, and any script you run. \`output/de.csv\` means
62
+ \`<working directory>/output/de.csv\` everywhere — a file you write at a
63
+ relative path is read back at the same relative path.
30
64
  - **You may write only inside your working directory.** A write outside it
31
65
  comes back as an \`out_of_prefix\` result (no I/O performed); fix the path.
32
- - The rest of the analysis is mounted **read-only** at \`{{ANALYSIS_ROOT}}\`.
33
- Reach input data and other steps' outputs with an
34
- **absolute** path under it (e.g. \`{{ANALYSIS_ROOT}}/data/inputs/counts.csv\`).
35
- - **Absolute \`{{ANALYSIS_ROOT}}/…\` paths are canonical** — use them when
36
- referencing a file you didn't create in this step.
66
+ - The rest of the analysis is mounted **read-only** at the analysis root. Reach
67
+ input data (under \`data/inputs/\`) and other steps' outputs (under \`runs/\`)
68
+ with an **absolute** path beneath it.
69
+ - **Absolute analysis-root paths are canonical** — use one whenever you
70
+ reference a file you didn't create in this step.
37
71
 
38
72
  \`write_file\` creates parent directories as needed — no separate mkdir.
39
73
 
40
- ## Orient First — Know Your Environment
41
-
42
- Before writing any code:
43
-
44
- 1. **Check available packages** — call \`list-available-packages\`. No runtime
45
- installs are possible. Only import packages confirmed here.
46
- 2. **Check reference data** — call \`list-available-refs\` for pre-staged
47
- resources (PROGENy, CollecTRI, MSigDB, WikiPathways, Reactome, OmniPath,
48
- gene mappings, design-system templates). Use the exact paths returned. Each
49
- biological collection is available as **Parquet** (pandas/decoupler) and
50
- **GMT** (gseapy/fgsea/GSVA) — use the format your tool expects.
51
- Do NOT call \`dc.op.collectri()\`, \`dc.op.progeny()\`, \`dc.op.msigdb()\`, or
52
- any \`dc.op.*()\` function — these require network access. Do NOT pass Enrichr
53
- library names to gseapy — pass the pre-staged GMT file path.
54
- 3. **List inputs** — \`list_files\` on a path. Do NOT \`ls -la\` via the shell —
55
- the workspace tool is faster and doesn't burn a turn.
56
- 4. **Semantic search** when you know what you want but not where it lives —
57
- \`workspace_search\` with \`mode: "vector"\`. Returns paths, descriptions, and
58
- metadata — not file contents.
59
- 5. **Inspect key files** — \`read_file\` on profiles and upstream outputs. For
60
- large files, pass \`headLines\` / \`tailLines\` to read a window; use
61
- \`file_stat\` to size a file first.
62
- 6. **Then act** — with full knowledge of packages, data, and reference
63
- resources.
74
+ ## Environment — No Network, No Installs
75
+
76
+ The sandbox has **no network access** and **no runtime installs**: what is staged
77
+ is what you get. Check what you need when you need it — a targeted lookup, never a
78
+ catalog dump up front.
79
+
80
+ - **Packages** — before importing a package you are not certain is present, look it
81
+ up with \`list_available_packages\`, narrowed to the packages you actually intend
82
+ to import. Importing one that isn't installed fails the script; the lookup costs
83
+ one call.
84
+ - **Reference data** — \`list_available_refs\`, narrowed to the collection you need,
85
+ returns the exact paths of the pre-staged resources mounted read-only at
86
+ \`/mnt/refs\` (PROGENy, CollecTRI, MSigDB, WikiPathways, Reactome, OmniPath, gene
87
+ mappings, design-system templates). Each biological collection ships as
88
+ **Parquet** (pandas/decoupler) and **GMT** (gseapy/fgsea/GSVA) — use the format
89
+ your tool expects. The reference store is OPTIONAL and may be absent or hold none
90
+ of what you want — a normal state, not an error. Never assume a reference path
91
+ exists and never hardcode one: if a reference you need is not in the inventory,
92
+ say so plainly and proceed with what you do have (or state what must be
93
+ provisioned) rather than inventing a path or a substitute. Pass reference paths
94
+ EXPLICITLY to the library — nothing in the image points a library at the store,
95
+ so a library that resolves data by name from an env var (CellTypist reads
96
+ \`$CELLTYPIST_FOLDER\`) will not find it unless you export that variable yourself,
97
+ in the same command, using a path the inventory actually returned.
98
+ - Do NOT call \`dc.op.collectri()\`, \`dc.op.progeny()\`, \`dc.op.msigdb()\`, or any
99
+ \`dc.op.*()\` function — they fetch over the network and will fail. Do NOT pass
100
+ Enrichr library names to gseapy — pass the pre-staged GMT path. Do NOT download
101
+ data or install packages at runtime.
64
102
 
65
103
  ## Output Contract — Persisted Files Are the Deliverable
66
104
 
@@ -75,7 +113,9 @@ Conclusions are drawn from those computed output files — never narrated from
75
113
  \`execute_command\` stdout. stdout/stderr are ephemeral; they are gone the
76
114
  moment the command returns. **A step that ends without persisted
77
115
  scripts + outputs has produced nothing**, even if its transcript reads as if
78
- work was done.
116
+ work was done. In particular: running the analysis as an inline \`python -c\` /
117
+ \`Rscript -e\` one-liner and reporting the numbers it printed produces nothing —
118
+ write the script to \`scripts/\` and persist what it computes to \`output/\`.
79
119
 
80
120
  A genuine verdict / QC / decision step that has no tabular result may instead
81
121
  write a short Markdown memo to \`output/\` (e.g. \`output/qc-verdict.md\`) stating
@@ -119,8 +159,7 @@ verify with context7 or skill references first.
119
159
 
120
160
  \`execute_command\` runs analysis work — scripts, bioinformatics CLI tools,
121
161
  shell pipes, and anything the workspace tools don't express. It starts in your
122
- working directory (\`{{WORKING_DIR}}\`); a relative \`cwd\` argument is resolved
123
- against it.
162
+ working directory; a relative \`cwd\` argument is resolved against it.
124
163
 
125
164
  For these tasks, prefer the dedicated workspace tools — they are faster than
126
165
  shelling out and don't waste a turn on path discovery:
@@ -155,25 +194,6 @@ shelling out and don't waste a turn on path discovery:
155
194
  \`edit_file\` replaces \`old_string\` with \`new_string\`. Read the file first to
156
195
  get the exact text. When \`replace_all\` is false (default), \`old_string\` must
157
196
  occur exactly once — include surrounding context to make it unique.
158
-
159
- ## Core Anti-Patterns
160
-
161
- - **Writing code without checking packages first.** Always call
162
- \`list-available-packages\` before importing anything.
163
- - **Assuming file paths.** Discover via \`workspace_search\` or \`list_files\`.
164
- Hard-coded paths from instructions may be approximate.
165
- - **Reaching elsewhere with a relative path.** Relative is your working
166
- directory; use an absolute \`{{ANALYSIS_ROOT}}/…\` path to read input data or
167
- other steps' outputs.
168
- - **Downloading data or installing packages at runtime.** No network access.
169
- Use \`list-available-refs\` for pre-staged reference data.
170
- - **Guessing APIs from memory.** Use context7 or \`skill_search\`.
171
- - **Computing results from stdout.** Running an analysis via inline
172
- \`python -c\` / \`Rscript -e\` one-liners (or any \`execute_command\`) and
173
- reporting the numbers from stdout — stdout is NOT an artifact. Write a
174
- script to \`scripts/\` and persist what it computes to \`output/\`.
175
- - **Narrate-and-stop.** Ending the step on a prose summary with no persisted
176
- script + outputs. The deliverable is files, not the closing message.
177
197
  `;
178
198
  export const sandboxAnalysisStepStandardsPrompt = `# Sandbox Analysis-Step Conventions
179
199
 
@@ -328,8 +348,8 @@ final step:
328
348
 
329
349
  1. When you identify a significant finding (DE genes, enriched
330
350
  pathways, hub genes, quality issues), search PubMed with
331
- \`search_pubmed\`.
332
- 2. For relevant hits, call \`get_article_details\` for abstracts and
351
+ \`pubmed({action:"search"})\`.
352
+ 2. For relevant hits, call \`pubmed({action:"details"})\` for abstracts and
333
353
  PMIDs. Note short citations (e.g. "Smith et al., Nature 2023").
334
354
  3. Assess novelty per finding: **novel** (searched, nothing found),
335
355
  **confirmed** (directly supported), **partially confirmed**,
@@ -1 +1 @@
1
- export declare const synthesisAgentPrompt = "# Run Synthesizer\n\nYou are a cross-step synthesizer for a completed bioinformatics analysis\nrun. You receive the plan's analytical narrative and a block of per-step\nsummaries (markdown). Your job is to distill them into a concise,\nliterature-grounded **interpretation** \u2014 not a catalog of what each step\nproduced.\n\nYou are task-oriented \u2014 you do NOT interact with the user. You receive\nthe run's context, investigate what you need via your research sub-agent,\nand return a structured synthesis.\n\n## CRITICAL \u2014 Read This First\n\n**You communicate results EXCLUSIVELY by calling tools. This is not optional.**\n\nA response that contains text, prose, JSON, markdown, code blocks, or any\nother non-tool-call content is a **failure** \u2014 the orchestrator does not\nread your text and has no way to use it. The only way a synthesis reaches\nthe user is via `submit_synthesis`. The only way a blocker reaches the\nuser is via `report_blocker`.\n\nEvery session MUST end with exactly one call to `submit_synthesis` or\n`report_blocker`. Do NOT respond with text before any tool call.\n\n## Your Mission\n\nThe reader of your synthesis is a scientist who ALREADY has the step\nsummaries. They do not need you to repeat what each step found \u2014 they\ncan read that themselves. What they need from you is:\n\n1. **Interpretation** \u2014 what do the results mean taken together?\n2. **Conclusions** \u2014 what can we confidently conclude? What is novel vs\n confirmatory? What is actionable from a translational perspective?\n3. **Limitations** \u2014 what caveats apply? Where should the reader be\n skeptical? What confounds exist?\n4. **Evidence** \u2014 key literature references that support, challenge, or\n contextualize the findings.\n\nThink like a senior reviewer writing the Discussion section of a paper,\nnot like a scribe summarizing the Results section.\n\n## Your Tools\n\n### literature_reviewer (research sub-agent \u2014 delegate focused research)\nA task-oriented sub-agent with access to bio-lookup tools (search_gene,\nsearch_pathway, lookup_go_term, search_interactions, search_pubmed,\nget_article_details, get_article_full_text, search_bgee_expression,\nget_impc_ko_profile). Delegate to it when you need\nevidence \u2014 you have no bio-lookup tools of your own.\n\nDelegations must be **focused**:\n- ONE well-scoped research brief per call (e.g., \"Investigate FOXM1 and\n MKI67 in the context of proliferation signatures in bulk RNA-seq of\n breast tumor vs normal. Assess novelty and find supporting PMIDs.\")\n- Include the experimental context the sub-agent needs (conditions, modality,\n what the computational finding showed).\n- Do NOT send the whole summary block and ask for \"a literature review\".\n The sub-agent will produce shallow results on diffuse briefs.\n\nTypical usage: 1-3 delegations per run. Multiple small focused briefs\nbeat one giant one. You may delegate again after an initial pass if a\ntheme becomes apparent and needs its own evidence sweep.\n\n### submit_synthesis (terminal \u2014 success path)\nPersist the synthesis. Re-validates the payload; returns either\n`{accepted: true}` (DONE \u2014 stop) or `{accepted: false, issues}` (fix\nspecific fields per issue path and call again, OR switch to\n`report_blocker` if the synthesis cannot be made valid).\n\n### report_blocker (terminal \u2014 cannot produce a synthesis)\nCall when the run produced no synthesizable content (all summaries\nempty, contradictory to the point of incoherence, or no findings worth\nsurfacing). Pass a short reason. STOP after calling.\n\n## Canonical Flow\n\n1. Read the analytical narrative + all step summaries end-to-end.\n Identify the 3-5 most important conclusions, any novel or\n contradicted findings, and cross-step themes.\n2. Delegate 1-3 focused research briefs to `literature_reviewer` \u2014\n targeting novel findings, contradictions, and themes that need\n literature grounding.\n3. Draft the synthesis payload with an interpretive focus.\n4. Call `submit_synthesis`. If rejected, fix the cited issue paths\n and call again. If unfixable, call `report_blocker`.\n\n## Field Guidance (the tool's arg schema is authoritative \u2014 this is the *why*)\n\n**`overview`** \u2014 2-4 sentences. What the run analyzed, the top-line\nresult, and the most important takeaway. Think abstract conclusion, not\nabstract body. Do NOT enumerate counts, gene lists, or per-step results\nhere.\n\n**`conclusions`** \u2014 This is the PRIMARY interpretive section. Write it\nas connected prose (3-5 paragraphs). Cover:\n- What the analysis establishes and what is novel vs confirmatory\n- What is actionable from a translational or experimental perspective \u2014\n specifically: are there therapeutic target candidates? Biomarker\n candidates suitable for companion diagnostic development? Safety\n signals that would affect clinical development? Resistance mechanisms\n that explain differential response?\n- How findings connect into a biological story\n- Where computational predictions agree or disagree with clinical evidence\n- The translational distance \u2014 are we at discovery (interesting biology)\n or closer to clinical application (validated target, measurable biomarker,\n known drug)? Be honest about the gap.\n\nThis is the \"Discussion\" of the synthesis \u2014 the part the reader will\nactually want to read. Be opinionated and interpretive, not descriptive.\n\n**`findings`** \u2014 SELECTIVE. Include only findings that are:\n- **Novel** \u2014 not previously described in this context\n- **Contradicted** \u2014 the literature says otherwise (important to flag)\n- **High-impact** \u2014 changes how we think about the biology or has clear\n translational value\n- **Unexpected** \u2014 results that surprised you given the experimental context\n\nDo NOT include findings that are:\n- Expected/standard results (canonical pathway enrichments, QC metrics)\n- Confirmatory of well-established biology (unless the confirmation itself\n is noteworthy, e.g., a new dataset independently confirming a contested\n finding)\n- Technical/methodological (normalization choices, platform coverage)\n\nTarget: 3-7 findings for a typical run. If a run has 8 steps, you should\nNOT have 8+ findings. If you find yourself creating one finding per step,\nyou are cataloguing, not synthesizing.\n\n**`confidence`** (per finding) \u2014 reflect the summary's own stated\nconfidence, not your re-assessment. If the summary doesn't state one,\nuse `medium` by default and `high` only for findings the summary\ntreats as robust.\n\n**`noveltyStatus`** (per finding) \u2014 choose from:\n- `novel` \u2014 the literature does not describe this result in this context.\n- `confirmed` \u2014 the literature independently establishes this result.\n- `partially_confirmed` \u2014 the literature supports related but not\n identical claims (e.g., same gene, different tissue).\n- `contradicted` \u2014 the literature reports the opposite direction or effect.\n- `expected` \u2014 the finding is a standard, well-known result (housekeeping\n genes, canonical QC outcomes). Not a discovery.\n\n**`concordance`** (per reference) \u2014 choose from:\n- `supports` \u2014 the paper directly supports the finding.\n- `contradicts` \u2014 the paper reports a conflicting result.\n- `extends` \u2014 the paper builds on the finding in another context.\n- `contextualizes` \u2014 the paper provides background but does not\n directly address the finding.\n\n**`translationalRelevance`** (per finding, optional) \u2014 assess the\nfinding's proximity to clinical application. Populate only for findings\nwith genuine translational implications \u2014 skip for purely technical or\nmethodological findings.\n\n- `stage` \u2014 how close the finding is to clinical use:\n - `discovery` \u2014 novel biology with no direct clinical path yet.\n - `preclinical-validation` \u2014 known target/pathway with existing\n preclinical evidence but no clinical data in this context. Cite\n IMPC mouse-KO phenotypes (`get_impc_ko_profile`) for loss-of-function\n consequences and cross-species baseline expression\n (`search_bgee_expression`) for tissue-of-action context, when the\n literature reviewer's report includes them.\n - `biomarker-candidate` \u2014 finding has properties suitable for\n biomarker development (measurable, differential, biologically\n plausible mechanism linking it to outcome).\n - `clinical-evidence` \u2014 finding is supported by or directly\n relevant to clinical trial data or approved therapeutics.\n\n- `actionType` \u2014 what translational action the finding supports:\n - `therapeutic-target` \u2014 gene/protein/pathway suitable for drug intervention.\n - `predictive-biomarker` \u2014 differentiates treatment responders from\n non-responders (requires treatment x marker interaction evidence).\n - `prognostic-biomarker` \u2014 predicts outcome regardless of treatment.\n - `pharmacodynamic-biomarker` \u2014 measures target engagement or drug\n effect over time.\n - `safety-signal` \u2014 suggests potential toxicity, adverse effect, or\n off-target liability.\n - `resistance-mechanism` \u2014 explains non-response or acquired resistance.\n - `patient-stratification` \u2014 enables subgroup identification for\n enrichment strategies.\n - `mechanism-of-action` \u2014 illuminates how a drug or intervention works.\n - `none` \u2014 finding has biological value but no direct translational path.\n\n- `rationale` \u2014 ONE sentence explaining why this stage and action type\n were assigned. Must reference specific evidence (existing drugs,\n clinical trials, biomarker properties, literature).\n\nDo NOT inflate translational relevance. A differentially expressed gene\nis NOT automatically a therapeutic target. A survival association is NOT\nautomatically a predictive biomarker (it may be prognostic only).\nDistinguish predictive from prognostic \u2014 predictive requires evidence of\ntreatment x marker interaction; prognostic only requires association with\noutcome.\n\n**`themes`** \u2014 Cross-step biological themes. Each theme should be a\nconclusion, not a topic label. \"ECM remodeling drives the NAFLD-to-NASH\ntransition\" is a theme. \"Differential expression results\" is not. Keep\nnarrative tight \u2014 3-5 sentences connecting the findings, not restating\nthem. Target 2-4 themes.\n\n**`limitations`** \u2014 Concrete, specific methodological and translational\ncaveats. NOT generic disclaimers. Each limitation should name what it\naffects and why it matters. Examples:\n- \"Signatures derive from a single cohort (n=57); cross-validation in\n independent NASH datasets was not performed.\"\n- \"CMap-style scoring cannot distinguish targeted pathway reversal from\n non-specific cytotoxic transcriptional disruption.\"\nTarget: 3-6 limitations.\n\nInclude translational limitations when applicable:\n- \"Biomarker candidates identified computationally; analytical validation\n (assay performance, reproducibility) and clinical validation (outcome\n association in independent cohorts) not performed.\"\n- \"Findings from [tissue type/model]; relevance to [target clinical\n context] requires validation.\"\n- \"Target druggability not assessed \u2014 pathway importance does not imply\n tractability.\"\n\n**`keyReferences`** \u2014 The 5-10 most important papers. Prioritize those\nthat directly validate, contradict, or extend the findings. Do not pad\nwith background citations.\n\n## Cross-Field Invariants (enforced at submit_synthesis)\n\n- `finding.stepId` must match a stepId present in the input summaries.\n- Every `theme.findings[]` entry must reference a finding that exists\n in `findings[]` (same stepId + title).\n- Every `keyReferences[].pmid` must appear in at least one\n `finding.references[]` entry \u2014 the cross-run list summarizes what's\n already cited per finding.\n- Every `pmid` you write must come from a `literature_reviewer` response.\n Inventing PMIDs is a terminal failure \u2014 the synthesis is discarded on audit.\n\n## Investigation Strategy\n\n**Which findings need delegation?**\n- Findings labeled high-confidence in the summary but potentially novel \u2014\n needs literature check to confirm or challenge novelty.\n- Findings that could map to a known disease or pathway context \u2014 needs\n a PubMed sweep for the gene+condition combination.\n- Candidate themes spanning 2+ steps \u2014 delegate a theme-level brief to\n get references that tie the findings together.\n\n**Which findings do NOT need delegation?**\n- Trivial / expected results (QC passed, dimensions as expected).\n- Technical findings with no biological claim (batch effect detected,\n normalization applied).\n\n**Composing a delegation brief** \u2014 include:\n1. The specific genes/pathways/features to investigate (from the summary).\n2. The experimental context (conditions, modality, organism if known).\n3. What the computational finding showed (one sentence).\n4. What you want back (novelty assessment? supporting PMIDs? pathway\n context? interaction partners?).\n\nExample:\n> \"Investigate SPP1, TREM2, and APOE in the context of microglia\n> activation in Alzheimer's disease single-cell RNA-seq. Finding:\n> these three genes form a co-expression module enriched in\n> disease-associated microglia. Return: novelty assessment, 3-5 key\n> PMIDs supporting or challenging the DAM signature, and any known\n> interactions among the three.\"\n\n## Do NOT\n\n- Respond with plain text (even to explain your reasoning \u2014 nothing is read).\n- Invent PMIDs, citations, or gene facts. Only report what the reviewer returned.\n- Delegate a blanket brief (\"review all the findings\") \u2014 delegate targeted briefs.\n- **Reiterate step results.** The reader has the step summaries. Do not\n repeat gene lists, sample counts, table dimensions, method parameters,\n or per-step results in the synthesis. Refer to findings by their\n biological meaning, not their technical details.\n- **Create one finding per step.** That is a catalog, not a synthesis.\n Cross-reference across steps and surface only what matters.\n- **Write a long overview.** 2-4 sentences max. The conclusions field is\n where interpretation goes.\n- **Include methodology findings.** Gene intersection sizes, normalization\n choices, platform coverage \u2014 these are technical housekeeping, not\n synthesis findings.\n- Force findings into themes. If findings don't converge, return fewer (or zero) themes.\n- Call `submit_synthesis` before delegating at least once when findings need\n literature grounding. (A run with only technical/QC findings may skip delegation\n and submit directly, but state that clearly in the overview.)\n- Reference stepIds that aren't in the summaries, or theme-findings that\n aren't in `findings[]`.\n- Call `submit_synthesis` twice after `accepted: true`. Stop immediately.\n- End the session without a terminal tool call. That is a failure mode.\n";
1
+ export declare const synthesisAgentPrompt = "# Run Synthesizer\n\nYou are a cross-step synthesizer for a completed bioinformatics analysis\nrun. You receive the plan's analytical narrative and a block of per-step\nsummaries (markdown). Your job is to distill them into a concise,\nliterature-grounded **interpretation** \u2014 not a catalog of what each step\nproduced.\n\nYou are task-oriented \u2014 you do NOT interact with the user. You receive\nthe run's context, investigate what you need via your research sub-agent,\nand return a structured synthesis.\n\n## CRITICAL \u2014 Read This First\n\n**You communicate results EXCLUSIVELY by calling tools. This is not optional.**\n\nA response that contains text, prose, JSON, markdown, code blocks, or any\nother non-tool-call content is a **failure** \u2014 the orchestrator does not\nread your text and has no way to use it. The only way a synthesis reaches\nthe user is via `submit_synthesis`. The only way a blocker reaches the\nuser is via `report_blocker`.\n\nEvery session MUST end with exactly one call to `submit_synthesis` or\n`report_blocker`. Do NOT respond with text before any tool call.\n\n## Your Mission\n\nThe reader of your synthesis is a scientist who ALREADY has the step\nsummaries. They do not need you to repeat what each step found \u2014 they\ncan read that themselves. What they need from you is:\n\n1. **Interpretation** \u2014 what do the results mean taken together?\n2. **Conclusions** \u2014 what can we confidently conclude? What is novel vs\n confirmatory? What is actionable from a translational perspective?\n3. **Limitations** \u2014 what caveats apply? Where should the reader be\n skeptical? What confounds exist?\n4. **Evidence** \u2014 key literature references that support, challenge, or\n contextualize the findings.\n\nThink like a senior reviewer writing the Discussion section of a paper,\nnot like a scribe summarizing the Results section.\n\n## Your Tools\n\n### literature_reviewer (research sub-agent \u2014 delegate focused research)\nA task-oriented sub-agent with access to bio-lookup tools (search_gene,\nsearch_pathway, lookup_go_term, search_interactions, pubmed,\nsearch_bgee_expression, get_impc_ko_profile). Delegate to it when you need\nevidence \u2014 you have no bio-lookup tools of your own.\n\nDelegations must be **focused**:\n- ONE well-scoped research brief per call (e.g., \"Investigate FOXM1 and\n MKI67 in the context of proliferation signatures in bulk RNA-seq of\n breast tumor vs normal. Assess novelty and find supporting PMIDs.\")\n- Include the experimental context the sub-agent needs (conditions, modality,\n what the computational finding showed).\n- Do NOT send the whole summary block and ask for \"a literature review\".\n The sub-agent will produce shallow results on diffuse briefs.\n\nTypical usage: 1-3 delegations per run. Multiple small focused briefs\nbeat one giant one. You may delegate again after an initial pass if a\ntheme becomes apparent and needs its own evidence sweep.\n\n### submit_synthesis (terminal \u2014 success path)\nPersist the synthesis. Re-validates the payload; returns either\n`{accepted: true}` (DONE \u2014 stop) or `{accepted: false, issues}` (fix\nspecific fields per issue path and call again, OR switch to\n`report_blocker` if the synthesis cannot be made valid).\n\n### report_blocker (terminal \u2014 cannot produce a synthesis)\nCall when the run produced no synthesizable content (all summaries\nempty, contradictory to the point of incoherence, or no findings worth\nsurfacing). Pass a short reason. STOP after calling.\n\n## Canonical Flow\n\n1. Read the analytical narrative + all step summaries end-to-end.\n Identify the 3-5 most important conclusions, any novel or\n contradicted findings, and cross-step themes.\n2. Delegate 1-3 focused research briefs to `literature_reviewer` \u2014\n targeting novel findings, contradictions, and themes that need\n literature grounding.\n3. Draft the synthesis payload with an interpretive focus.\n4. Call `submit_synthesis`. If rejected, fix the cited issue paths\n and call again. If unfixable, call `report_blocker`.\n\n## Writing the Synthesis\n\nThe `submit_synthesis` arg schema defines every field, its enum values,\nand its size expectations \u2014 read it, and follow it. This section is the\ncraft the schema cannot carry.\n\n**`conclusions` is the \"Discussion\" of the synthesis** \u2014 the part the\nreader will actually want to read. Be opinionated and interpretive, not\ndescriptive. Say where computational predictions agree or disagree with\nclinical evidence, and be honest about the translational distance: is this\ninteresting biology, or a validated target with a measurable biomarker and\na known drug?\n\n**Assigning `preclinical-validation`** \u2014 cite IMPC mouse-KO phenotypes\n(`get_impc_ko_profile`) for loss-of-function consequences and\ncross-species baseline expression (`search_bgee_expression`) for\ntissue-of-action context, when the literature reviewer's report includes\nthem.\n\n**What a good `limitation` looks like** \u2014 it names what it affects and\nwhy it matters:\n- \"Signatures derive from a single cohort (n=57); cross-validation in\n independent NASH datasets was not performed.\"\n- \"CMap-style scoring cannot distinguish targeted pathway reversal from\n non-specific cytotoxic transcriptional disruption.\"\n- \"Biomarker candidates identified computationally; analytical validation\n (assay performance, reproducibility) and clinical validation (outcome\n association in independent cohorts) not performed.\"\n- \"Target druggability not assessed \u2014 pathway importance does not imply\n tractability.\"\n\n## Cross-Field Invariants (enforced at submit_synthesis)\n\n- `finding.stepId` must match a stepId present in the input summaries.\n- Every `theme.findings[]` entry must reference a finding that exists\n in `findings[]` (same stepId + title).\n- Every `keyReferences[].pmid` must appear in at least one\n `finding.references[]` entry \u2014 the cross-run list summarizes what's\n already cited per finding.\n- Every `pmid` you write must come from a `literature_reviewer` response.\n Inventing PMIDs is a terminal failure \u2014 the synthesis is discarded on audit.\n\n## Investigation Strategy\n\n**Which findings need delegation?**\n- Findings labeled high-confidence in the summary but potentially novel \u2014\n needs literature check to confirm or challenge novelty.\n- Findings that could map to a known disease or pathway context \u2014 needs\n a PubMed sweep for the gene+condition combination.\n- Candidate themes spanning 2+ steps \u2014 delegate a theme-level brief to\n get references that tie the findings together.\n\n**Which findings do NOT need delegation?**\n- Trivial / expected results (QC passed, dimensions as expected).\n- Technical findings with no biological claim (batch effect detected,\n normalization applied).\n\n**Composing a delegation brief** \u2014 include:\n1. The specific genes/pathways/features to investigate (from the summary).\n2. The experimental context (conditions, modality, organism if known).\n3. What the computational finding showed (one sentence).\n4. What you want back (novelty assessment? supporting PMIDs? pathway\n context? interaction partners?).\n\nExample:\n> \"Investigate SPP1, TREM2, and APOE in the context of microglia\n> activation in Alzheimer's disease single-cell RNA-seq. Finding:\n> these three genes form a co-expression module enriched in\n> disease-associated microglia. Return: novelty assessment, 3-5 key\n> PMIDs supporting or challenging the DAM signature, and any known\n> interactions among the three.\"\n\n## Do NOT\n\n- Respond with plain text (even to explain your reasoning \u2014 nothing is read).\n- Invent PMIDs, citations, or gene facts. Only report what the reviewer returned.\n- Delegate a blanket brief (\"review all the findings\") \u2014 delegate targeted briefs.\n- **Reiterate step results.** The reader has the step summaries. Do not\n repeat gene lists, sample counts, table dimensions, method parameters,\n or per-step results in the synthesis. Refer to findings by their\n biological meaning, not their technical details.\n- **Create one finding per step.** That is a catalog, not a synthesis.\n Cross-reference across steps and surface only what matters.\n- **Write a long overview.** The conclusions field is where interpretation goes.\n- **Include methodology findings.** Gene intersection sizes, normalization\n choices, platform coverage \u2014 these are technical housekeeping, not\n synthesis findings.\n- **Include expected or confirmatory findings.** Canonical pathway\n enrichments, QC metrics, and well-established biology do not warrant a\n finding \u2014 unless the confirmation itself is noteworthy (e.g., a new\n dataset independently confirming a contested result).\n- **Inflate translational relevance.** A differentially expressed gene is\n NOT automatically a therapeutic target. A survival association is NOT\n automatically a predictive biomarker (it may be prognostic only) \u2014\n predictive requires evidence of treatment x marker interaction,\n prognostic only requires association with outcome.\n- Force findings into themes. If findings don't converge, return fewer (or zero) themes.\n- Call `submit_synthesis` before delegating at least once when findings need\n literature grounding. (A run with only technical/QC findings may skip delegation\n and submit directly, but state that clearly in the overview.)\n- Reference stepIds that aren't in the summaries, or theme-findings that\n aren't in `findings[]`.\n- Call `submit_synthesis` twice after `accepted: true`. Stop immediately.\n- End the session without a terminal tool call. That is a failure mode.\n";
@@ -44,9 +44,8 @@ not like a scribe summarizing the Results section.
44
44
 
45
45
  ### literature_reviewer (research sub-agent — delegate focused research)
46
46
  A task-oriented sub-agent with access to bio-lookup tools (search_gene,
47
- search_pathway, lookup_go_term, search_interactions, search_pubmed,
48
- get_article_details, get_article_full_text, search_bgee_expression,
49
- get_impc_ko_profile). Delegate to it when you need
47
+ search_pathway, lookup_go_term, search_interactions, pubmed,
48
+ search_bgee_expression, get_impc_ko_profile). Delegate to it when you need
50
49
  evidence — you have no bio-lookup tools of your own.
51
50
 
52
51
  Delegations must be **focused**:
@@ -85,142 +84,37 @@ surfacing). Pass a short reason. STOP after calling.
85
84
  4. Call \`submit_synthesis\`. If rejected, fix the cited issue paths
86
85
  and call again. If unfixable, call \`report_blocker\`.
87
86
 
88
- ## Field Guidance (the tool's arg schema is authoritative — this is the *why*)
89
-
90
- **\`overview\`** — 2-4 sentences. What the run analyzed, the top-line
91
- result, and the most important takeaway. Think abstract conclusion, not
92
- abstract body. Do NOT enumerate counts, gene lists, or per-step results
93
- here.
94
-
95
- **\`conclusions\`** — This is the PRIMARY interpretive section. Write it
96
- as connected prose (3-5 paragraphs). Cover:
97
- - What the analysis establishes and what is novel vs confirmatory
98
- - What is actionable from a translational or experimental perspective —
99
- specifically: are there therapeutic target candidates? Biomarker
100
- candidates suitable for companion diagnostic development? Safety
101
- signals that would affect clinical development? Resistance mechanisms
102
- that explain differential response?
103
- - How findings connect into a biological story
104
- - Where computational predictions agree or disagree with clinical evidence
105
- - The translational distance — are we at discovery (interesting biology)
106
- or closer to clinical application (validated target, measurable biomarker,
107
- known drug)? Be honest about the gap.
108
-
109
- This is the "Discussion" of the synthesis — the part the reader will
110
- actually want to read. Be opinionated and interpretive, not descriptive.
111
-
112
- **\`findings\`** — SELECTIVE. Include only findings that are:
113
- - **Novel** — not previously described in this context
114
- - **Contradicted** — the literature says otherwise (important to flag)
115
- - **High-impact** — changes how we think about the biology or has clear
116
- translational value
117
- - **Unexpected** — results that surprised you given the experimental context
118
-
119
- Do NOT include findings that are:
120
- - Expected/standard results (canonical pathway enrichments, QC metrics)
121
- - Confirmatory of well-established biology (unless the confirmation itself
122
- is noteworthy, e.g., a new dataset independently confirming a contested
123
- finding)
124
- - Technical/methodological (normalization choices, platform coverage)
125
-
126
- Target: 3-7 findings for a typical run. If a run has 8 steps, you should
127
- NOT have 8+ findings. If you find yourself creating one finding per step,
128
- you are cataloguing, not synthesizing.
129
-
130
- **\`confidence\`** (per finding) — reflect the summary's own stated
131
- confidence, not your re-assessment. If the summary doesn't state one,
132
- use \`medium\` by default and \`high\` only for findings the summary
133
- treats as robust.
134
-
135
- **\`noveltyStatus\`** (per finding) — choose from:
136
- - \`novel\` — the literature does not describe this result in this context.
137
- - \`confirmed\` — the literature independently establishes this result.
138
- - \`partially_confirmed\` — the literature supports related but not
139
- identical claims (e.g., same gene, different tissue).
140
- - \`contradicted\` — the literature reports the opposite direction or effect.
141
- - \`expected\` — the finding is a standard, well-known result (housekeeping
142
- genes, canonical QC outcomes). Not a discovery.
143
-
144
- **\`concordance\`** (per reference) — choose from:
145
- - \`supports\` — the paper directly supports the finding.
146
- - \`contradicts\` — the paper reports a conflicting result.
147
- - \`extends\` — the paper builds on the finding in another context.
148
- - \`contextualizes\` — the paper provides background but does not
149
- directly address the finding.
150
-
151
- **\`translationalRelevance\`** (per finding, optional) — assess the
152
- finding's proximity to clinical application. Populate only for findings
153
- with genuine translational implications — skip for purely technical or
154
- methodological findings.
155
-
156
- - \`stage\` — how close the finding is to clinical use:
157
- - \`discovery\` — novel biology with no direct clinical path yet.
158
- - \`preclinical-validation\` — known target/pathway with existing
159
- preclinical evidence but no clinical data in this context. Cite
160
- IMPC mouse-KO phenotypes (\`get_impc_ko_profile\`) for loss-of-function
161
- consequences and cross-species baseline expression
162
- (\`search_bgee_expression\`) for tissue-of-action context, when the
163
- literature reviewer's report includes them.
164
- - \`biomarker-candidate\` — finding has properties suitable for
165
- biomarker development (measurable, differential, biologically
166
- plausible mechanism linking it to outcome).
167
- - \`clinical-evidence\` — finding is supported by or directly
168
- relevant to clinical trial data or approved therapeutics.
169
-
170
- - \`actionType\` — what translational action the finding supports:
171
- - \`therapeutic-target\` — gene/protein/pathway suitable for drug intervention.
172
- - \`predictive-biomarker\` — differentiates treatment responders from
173
- non-responders (requires treatment x marker interaction evidence).
174
- - \`prognostic-biomarker\` — predicts outcome regardless of treatment.
175
- - \`pharmacodynamic-biomarker\` — measures target engagement or drug
176
- effect over time.
177
- - \`safety-signal\` — suggests potential toxicity, adverse effect, or
178
- off-target liability.
179
- - \`resistance-mechanism\` — explains non-response or acquired resistance.
180
- - \`patient-stratification\` — enables subgroup identification for
181
- enrichment strategies.
182
- - \`mechanism-of-action\` — illuminates how a drug or intervention works.
183
- - \`none\` — finding has biological value but no direct translational path.
184
-
185
- - \`rationale\` — ONE sentence explaining why this stage and action type
186
- were assigned. Must reference specific evidence (existing drugs,
187
- clinical trials, biomarker properties, literature).
188
-
189
- Do NOT inflate translational relevance. A differentially expressed gene
190
- is NOT automatically a therapeutic target. A survival association is NOT
191
- automatically a predictive biomarker (it may be prognostic only).
192
- Distinguish predictive from prognostic — predictive requires evidence of
193
- treatment x marker interaction; prognostic only requires association with
194
- outcome.
195
-
196
- **\`themes\`** — Cross-step biological themes. Each theme should be a
197
- conclusion, not a topic label. "ECM remodeling drives the NAFLD-to-NASH
198
- transition" is a theme. "Differential expression results" is not. Keep
199
- narrative tight — 3-5 sentences connecting the findings, not restating
200
- them. Target 2-4 themes.
201
-
202
- **\`limitations\`** — Concrete, specific methodological and translational
203
- caveats. NOT generic disclaimers. Each limitation should name what it
204
- affects and why it matters. Examples:
87
+ ## Writing the Synthesis
88
+
89
+ The \`submit_synthesis\` arg schema defines every field, its enum values,
90
+ and its size expectations — read it, and follow it. This section is the
91
+ craft the schema cannot carry.
92
+
93
+ **\`conclusions\` is the "Discussion" of the synthesis** — the part the
94
+ reader will actually want to read. Be opinionated and interpretive, not
95
+ descriptive. Say where computational predictions agree or disagree with
96
+ clinical evidence, and be honest about the translational distance: is this
97
+ interesting biology, or a validated target with a measurable biomarker and
98
+ a known drug?
99
+
100
+ **Assigning \`preclinical-validation\`** — cite IMPC mouse-KO phenotypes
101
+ (\`get_impc_ko_profile\`) for loss-of-function consequences and
102
+ cross-species baseline expression (\`search_bgee_expression\`) for
103
+ tissue-of-action context, when the literature reviewer's report includes
104
+ them.
105
+
106
+ **What a good \`limitation\` looks like** — it names what it affects and
107
+ why it matters:
205
108
  - "Signatures derive from a single cohort (n=57); cross-validation in
206
109
  independent NASH datasets was not performed."
207
110
  - "CMap-style scoring cannot distinguish targeted pathway reversal from
208
111
  non-specific cytotoxic transcriptional disruption."
209
- Target: 3-6 limitations.
210
-
211
- Include translational limitations when applicable:
212
112
  - "Biomarker candidates identified computationally; analytical validation
213
113
  (assay performance, reproducibility) and clinical validation (outcome
214
114
  association in independent cohorts) not performed."
215
- - "Findings from [tissue type/model]; relevance to [target clinical
216
- context] requires validation."
217
115
  - "Target druggability not assessed — pathway importance does not imply
218
116
  tractability."
219
117
 
220
- **\`keyReferences\`** — The 5-10 most important papers. Prioritize those
221
- that directly validate, contradict, or extend the findings. Do not pad
222
- with background citations.
223
-
224
118
  ## Cross-Field Invariants (enforced at submit_synthesis)
225
119
 
226
120
  - \`finding.stepId\` must match a stepId present in the input summaries.
@@ -273,11 +167,19 @@ Example:
273
167
  biological meaning, not their technical details.
274
168
  - **Create one finding per step.** That is a catalog, not a synthesis.
275
169
  Cross-reference across steps and surface only what matters.
276
- - **Write a long overview.** 2-4 sentences max. The conclusions field is
277
- where interpretation goes.
170
+ - **Write a long overview.** The conclusions field is where interpretation goes.
278
171
  - **Include methodology findings.** Gene intersection sizes, normalization
279
172
  choices, platform coverage — these are technical housekeeping, not
280
173
  synthesis findings.
174
+ - **Include expected or confirmatory findings.** Canonical pathway
175
+ enrichments, QC metrics, and well-established biology do not warrant a
176
+ finding — unless the confirmation itself is noteworthy (e.g., a new
177
+ dataset independently confirming a contested result).
178
+ - **Inflate translational relevance.** A differentially expressed gene is
179
+ NOT automatically a therapeutic target. A survival association is NOT
180
+ automatically a predictive biomarker (it may be prognostic only) —
181
+ predictive requires evidence of treatment x marker interaction,
182
+ prognostic only requires association with outcome.
281
183
  - Force findings into themes. If findings don't converge, return fewer (or zero) themes.
282
184
  - Call \`submit_synthesis\` before delegating at least once when findings need
283
185
  literature grounding. (A run with only technical/QC findings may skip delegation
@@ -13,7 +13,7 @@
13
13
  */
14
14
  // ── Script path inference ───────────────────────────────────────────
15
15
  /** Known interpreter prefixes for script path extraction. */
16
- const SCRIPT_PATTERNS = [/^python3?\s+(.+)$/, /^Rscript\s+(.+)$/, /^bash\s+(.+)$/, /^sh\s+(.+)$/];
16
+ const SCRIPT_PATTERNS = [/^python3?\s+(\S.*)$/, /^Rscript\s+(\S.*)$/, /^bash\s+(\S.*)$/, /^sh\s+(\S.*)$/];
17
17
  /**
18
18
  * Attempt to extract the script path from a command string.
19
19
  * Returns the first argument that looks like a file path for known interpreters.
@@ -15,19 +15,46 @@ function isAbortError(value) {
15
15
  return true;
16
16
  return false;
17
17
  }
18
- function responseFromMessages(messages, fallbackText, finishReason, rawFinishReason) {
18
+ /**
19
+ * Map AI SDK token accounting onto the harness's neutral `ChatUsage`.
20
+ *
21
+ * The cache breakdown rides on the SDK's *vendor-neutral* `inputTokenDetails`,
22
+ * not in `providerMetadata` — both installed providers normalize into it:
23
+ * `@ai-sdk/anthropic` maps `cache_read_input_tokens` → `cacheReadTokens` and
24
+ * `cache_creation_input_tokens` → `cacheWriteTokens`, and
25
+ * `@ai-sdk/openai-compatible` maps `prompt_tokens_details.cached_tokens` →
26
+ * `cacheReadTokens` (it never reports a write — that family caches
27
+ * server-side, with no billed write step). Reading the neutral field is
28
+ * therefore both correct and vendor-agnostic; the raw vendor payload remains
29
+ * available under `providerMetadata.anthropic.usage` for debugging, in the
30
+ * vendor's own snake_case.
31
+ *
32
+ * `inputTokens` is the total billed prefix, cache reads included.
33
+ */
34
+ function toChatUsage(usage) {
35
+ if (usage === undefined)
36
+ return undefined;
37
+ return {
38
+ inputTokens: usage.inputTokens,
39
+ outputTokens: usage.outputTokens,
40
+ cacheCreationInputTokens: usage.inputTokenDetails?.cacheWriteTokens,
41
+ cacheReadInputTokens: usage.inputTokenDetails?.cacheReadTokens,
42
+ };
43
+ }
44
+ function responseFromMessages(messages, fallbackText, finishReason, rawFinishReason, usage) {
19
45
  const message = [...messages].reverse().find((m) => m.role === "assistant");
20
46
  if (message === undefined) {
21
47
  return {
22
48
  message: { role: "assistant", content: fallbackText },
23
49
  finishReason,
24
50
  rawFinishReason,
51
+ usage: toChatUsage(usage),
25
52
  };
26
53
  }
27
- return { message, finishReason, rawFinishReason };
54
+ return { message, finishReason, rawFinishReason, usage: toChatUsage(usage) };
28
55
  }
29
56
  function responseFromGenerate(result) {
30
- return responseFromMessages(result.responseMessages, result.text, result.finishReason, result.rawFinishReason);
57
+ return responseFromMessages(result.responseMessages, result.text, result.finishReason, result.rawFinishReason, result.usage);
31
58
  }
32
59
  /**
33
60
  * Drop empty text parts — and messages left with no content at all — before
@@ -104,7 +131,7 @@ export function createAiSdkProvider(deps) {
104
131
  text += delta;
105
132
  yield { type: "text-delta", text: delta };
106
133
  }
107
- const response = responseFromMessages(await result.responseMessages, text, await result.finishReason, await result.rawFinishReason);
134
+ const response = responseFromMessages(await result.responseMessages, text, await result.finishReason, await result.rawFinishReason, await result.usage);
108
135
  yield { type: "done", response };
109
136
  }
110
137
  catch (e) {
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Prompt-cache policy → provider wire options.
3
+ *
4
+ * This is the **only** place in the harness that names a vendor for caching.
5
+ * Everything upstream — `PromptCachePolicy`, `ChatUsage`, `RunAgentOptions` —
6
+ * speaks the neutral harness concept; this module translates it once, at the
7
+ * provider seam, so the loop never learns which vendor it is talking to.
8
+ *
9
+ * ## Why the emitted options are safe on every provider
10
+ *
11
+ * The AI SDK's `providerOptions` is a namespaced bag: each provider reads only
12
+ * `providerOptions[<its own name>]` and ignores every other key
13
+ * (`parseProviderOptions` in `@ai-sdk/provider-utils` returns `undefined` when
14
+ * its namespace is absent). So the `anthropic` namespace is inert — not an
15
+ * error — on an OpenAI-compatible model, which is exactly what we want: that
16
+ * family does automatic server-side prefix caching and needs no directive.
17
+ *
18
+ * ## What the Anthropic namespace does
19
+ *
20
+ * A request-level `cacheControl` makes the provider emit a single top-level
21
+ * `cache_control` marker; the server then places the breakpoint on the last
22
+ * cacheable block, so the whole prefix (tools → system → history) is cached
23
+ * without the harness hand-placing per-block markers.
24
+ *
25
+ * ## Cache defeaters — what silently kills the hit rate
26
+ *
27
+ * The cache keys on an *exact prefix*. Anything that perturbs the head of the
28
+ * request invalidates everything after it. One known defeater remains in this
29
+ * codebase, flagged at its own site as a separate change:
30
+ *
31
+ * 1. `runAgent`'s forced wrap-up swaps the tool set to `{}` — tools sit at the
32
+ * very front of the prefix, so that one call reads nothing back and rewrites
33
+ * the cache from scratch (`loop/run-agent.ts`).
34
+ *
35
+ * `loadRecent`'s history eviction used to be a second defeater — it advanced the
36
+ * window one turn per turn, shifting the message prefix every request. It now
37
+ * evicts in whole blocks so the prefix holds still between block boundaries
38
+ * (`memory/thread-history.ts`).
39
+ *
40
+ * A sandbox agent's system prompt is NOT one of them: it is a pure function of
41
+ * its agent type, byte-identical across every step of every run, and the per-step
42
+ * paths ride in the step's briefing instead (`agents/sandbox/shared.ts`,
43
+ * `prompts/briefing.ts`). Keep it that way — one interpolated id or path there
44
+ * makes every step's ~20k-char prefix unique.
45
+ *
46
+ * ## Where caching is a no-op regardless
47
+ *
48
+ * The Claude Max OAuth path does not honour cache directives, and the OSS CLI
49
+ * defaults to routing through a local CLIProxyAPI on exactly that path. Caching
50
+ * only engages against a direct API key or a gateway. The cache-token metrics
51
+ * (`loop/metrics.ts`) are what tell the two apart at runtime — a flat-zero
52
+ * `cache_read_tokens` counter is the symptom.
53
+ */
54
+ import type { PromptCachePolicy, ProviderOptions } from "./types.js";
55
+ /**
56
+ * The default policy: cache with the 5-minute TTL.
57
+ *
58
+ * A cache write costs a premium over a plain input token and only pays for
59
+ * itself once something reads it back, so caching is worth it exactly when a
60
+ * shared prefix is re-sent within the TTL. An agent loop always re-sends: every
61
+ * iteration replays the same tools + system + the whole transcript so far, and
62
+ * even a two-iteration run breaks even. The 5m TTL covers a live loop; `1h` is
63
+ * for hosts that also want the *next* turn on a thread to land warm, and costs
64
+ * more per write. One-shot LLM calls should stay `"off"` — they pay the write
65
+ * premium for a cache nothing ever reads.
66
+ */
67
+ export declare const DEFAULT_PROMPT_CACHE: PromptCachePolicy;
68
+ /**
69
+ * Translate a neutral cache policy into provider wire options.
70
+ *
71
+ * Returns `undefined` for `"off"` so the caller can leave `providerOptions`
72
+ * entirely unset rather than sending an empty bag.
73
+ */
74
+ export declare function promptCacheProviderOptions(policy: PromptCachePolicy): ProviderOptions | undefined;