stageflow 0.40.0 → 0.44.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 (519) hide show
  1. package/README.md +15 -4
  2. package/dist/agent/activity.d.ts +18 -0
  3. package/dist/agent/claudeAdapter.js +7 -0
  4. package/dist/agent/claudeTools.d.ts +27 -18
  5. package/dist/agent/claudeTools.js +54 -15
  6. package/dist/agent/compactionEvents.d.ts +34 -0
  7. package/dist/agent/compactionEvents.js +37 -0
  8. package/dist/agent/openRouterRouting.d.ts +7 -0
  9. package/dist/agent/openRouterRouting.js +23 -0
  10. package/dist/agent/piAdapter.d.ts +6 -0
  11. package/dist/agent/piAdapter.js +128 -27
  12. package/dist/agent/piSettings.d.ts +7 -0
  13. package/dist/agent/piSettings.js +9 -0
  14. package/dist/agent/sandboxPiTools.d.ts +3 -1
  15. package/dist/agent/sandboxPiTools.js +8 -2
  16. package/dist/agent/stageTurnDriver.d.ts +11 -2
  17. package/dist/agent/stageTurnDriver.js +45 -4
  18. package/dist/agent/toolOutputBudget.d.ts +15 -1
  19. package/dist/agent/toolOutputBudget.js +18 -0
  20. package/dist/agent/toolOutputBudgetExtension.d.ts +2 -0
  21. package/dist/agent/toolOutputBudgetExtension.js +40 -3
  22. package/dist/agents/authorChat.d.ts +5 -0
  23. package/dist/agents/authorChat.js +120 -12
  24. package/dist/agents/authorSessionStore.d.ts +38 -0
  25. package/dist/agents/authorSessionStore.js +167 -0
  26. package/dist/agents/chatTurn.d.ts +2 -0
  27. package/dist/agents/chatTurn.js +17 -1
  28. package/dist/agents/errors.d.ts +1 -1
  29. package/dist/agents/errors.js +1 -0
  30. package/dist/agents/evalGate.d.ts +61 -0
  31. package/dist/agents/evalGate.js +103 -0
  32. package/dist/agents/evalSession.d.ts +26 -0
  33. package/dist/agents/evalSession.js +29 -0
  34. package/dist/agents/hostContext.d.ts +4 -1
  35. package/dist/agents/hostContext.js +4 -1
  36. package/dist/agents/runtime/piRuntime.d.ts +6 -2
  37. package/dist/agents/runtime/piRuntime.js +50 -16
  38. package/dist/agents/runtime/types.d.ts +3 -1
  39. package/dist/agents/service.d.ts +27 -2
  40. package/dist/agents/service.js +91 -15
  41. package/dist/agents/sessions.d.ts +8 -0
  42. package/dist/agents/sessions.js +53 -11
  43. package/dist/agents/store.d.ts +14 -3
  44. package/dist/agents/store.js +45 -7
  45. package/dist/agents/toolRisk.d.ts +21 -0
  46. package/dist/agents/toolRisk.js +50 -0
  47. package/dist/cli/doctorCommand.js +26 -0
  48. package/dist/cli/evalCommand.d.ts +20 -0
  49. package/dist/cli/evalCommand.js +720 -0
  50. package/dist/cli/exportAllCommand.js +1 -1
  51. package/dist/cli/hostClient.d.ts +60 -0
  52. package/dist/cli/hostClient.js +71 -0
  53. package/dist/cli/validateOutput.d.ts +2 -2
  54. package/dist/cli/validateOutput.js +2 -2
  55. package/dist/cli.js +10 -0
  56. package/dist/compaction/directives.d.ts +18 -0
  57. package/dist/compaction/directives.js +119 -0
  58. package/dist/compaction/extension.d.ts +20 -0
  59. package/dist/compaction/extension.js +78 -0
  60. package/dist/compaction/mask.d.ts +18 -0
  61. package/dist/compaction/mask.js +155 -0
  62. package/dist/compaction/pin.d.ts +21 -0
  63. package/dist/compaction/pin.js +270 -0
  64. package/dist/compaction/scrub.d.ts +7 -0
  65. package/dist/compaction/scrub.js +26 -0
  66. package/dist/compaction/sessionWiring.d.ts +22 -0
  67. package/dist/compaction/sessionWiring.js +26 -0
  68. package/dist/compaction/summarize.d.ts +79 -0
  69. package/dist/compaction/summarize.js +171 -0
  70. package/dist/compaction/toolPolicy.d.ts +3 -0
  71. package/dist/compaction/toolPolicy.js +33 -0
  72. package/dist/compaction/types.d.ts +45 -0
  73. package/dist/compaction/types.js +7 -0
  74. package/dist/compaction/workingState.d.ts +56 -0
  75. package/dist/compaction/workingState.js +198 -0
  76. package/dist/config/atomicWrite.d.ts +15 -0
  77. package/dist/config/atomicWrite.js +43 -0
  78. package/dist/config/browseCatalog.d.ts +2 -0
  79. package/dist/config/browseCatalog.js +4 -2
  80. package/dist/config/createPipeline.js +2 -0
  81. package/dist/config/createTrigger.js +7 -1
  82. package/dist/config/csv.d.ts +9 -0
  83. package/dist/config/csv.js +81 -0
  84. package/dist/config/datasetAgentCheck.d.ts +18 -0
  85. package/dist/config/datasetAgentCheck.js +109 -0
  86. package/dist/config/datasetCandidates.d.ts +22 -0
  87. package/dist/config/datasetCandidates.js +86 -0
  88. package/dist/config/datasetFromSessions.d.ts +34 -0
  89. package/dist/config/datasetFromSessions.js +105 -0
  90. package/dist/config/datasetHash.d.ts +1 -0
  91. package/dist/config/datasetHash.js +4 -0
  92. package/dist/config/datasetImport.d.ts +21 -0
  93. package/dist/config/datasetImport.js +120 -0
  94. package/dist/config/datasetStageCheck.d.ts +9 -0
  95. package/dist/config/datasetStageCheck.js +17 -0
  96. package/dist/config/datasetTypes.d.ts +27 -0
  97. package/dist/config/datasetTypes.js +1 -0
  98. package/dist/config/ensureCatalogScanRoot.d.ts +4 -1
  99. package/dist/config/ensureCatalogScanRoot.js +8 -6
  100. package/dist/config/evalCatalog.d.ts +22 -0
  101. package/dist/config/evalCatalog.js +95 -0
  102. package/dist/config/evalWriteRoots.d.ts +17 -0
  103. package/dist/config/evalWriteRoots.js +109 -0
  104. package/dist/config/githubTriggerAction.d.ts +8 -0
  105. package/dist/config/githubTriggerAction.js +29 -0
  106. package/dist/config/hostConfig.js +3 -0
  107. package/dist/config/installEvalSample.d.ts +34 -0
  108. package/dist/config/installEvalSample.js +182 -0
  109. package/dist/config/loadDataset.d.ts +16 -0
  110. package/dist/config/loadDataset.js +318 -0
  111. package/dist/config/loadEval.d.ts +32 -0
  112. package/dist/config/loadEval.js +1103 -0
  113. package/dist/config/loadOutcome.d.ts +5 -0
  114. package/dist/config/loadStageflowManifest.js +64 -0
  115. package/dist/config/pipelineNeeds.d.ts +2 -0
  116. package/dist/config/pipelineNeeds.js +16 -3
  117. package/dist/config/pipelineRoute.js +5 -4
  118. package/dist/config/resolveAgentTarget.d.ts +32 -0
  119. package/dist/config/resolveAgentTarget.js +118 -0
  120. package/dist/config/resolveEvalTarget.d.ts +21 -0
  121. package/dist/config/resolveEvalTarget.js +89 -0
  122. package/dist/config/scanCatalogPaths.d.ts +1 -1
  123. package/dist/config/scanCatalogPaths.js +17 -5
  124. package/dist/config/validateCatalog.d.ts +2 -2
  125. package/dist/config/validateCatalog.js +21 -1
  126. package/dist/config/validateEval.d.ts +36 -0
  127. package/dist/config/validateEval.js +446 -0
  128. package/dist/config/writeDataset.d.ts +54 -0
  129. package/dist/config/writeDataset.js +186 -0
  130. package/dist/config/writeEval.d.ts +25 -0
  131. package/dist/config/writeEval.js +398 -0
  132. package/dist/diagnostics/checks.js +1 -1
  133. package/dist/envelope/assertEmittedArtifacts.d.ts +12 -0
  134. package/dist/envelope/assertEmittedArtifacts.js +43 -0
  135. package/dist/envelope/preEmitChecks.d.ts +3 -0
  136. package/dist/evals/agentDiff.d.ts +13 -0
  137. package/dist/evals/agentDiff.js +11 -0
  138. package/dist/evals/canonical.d.ts +3 -0
  139. package/dist/evals/canonical.js +24 -0
  140. package/dist/evals/caseTask.d.ts +3 -0
  141. package/dist/evals/caseTask.js +9 -0
  142. package/dist/evals/compare.d.ts +94 -0
  143. package/dist/evals/compare.js +201 -0
  144. package/dist/evals/constants.d.ts +62 -0
  145. package/dist/evals/constants.js +97 -0
  146. package/dist/evals/engine/FakeEngine.d.ts +33 -0
  147. package/dist/evals/engine/FakeEngine.js +177 -0
  148. package/dist/evals/engine/index.d.ts +9 -0
  149. package/dist/evals/engine/index.js +19 -0
  150. package/dist/evals/engine/promptfoo/PromptfooEngine.d.ts +52 -0
  151. package/dist/evals/engine/promptfoo/PromptfooEngine.js +312 -0
  152. package/dist/evals/engine/promptfoo/errors.d.ts +5 -0
  153. package/dist/evals/engine/promptfoo/errors.js +8 -0
  154. package/dist/evals/engine/promptfoo/generate.d.ts +30 -0
  155. package/dist/evals/engine/promptfoo/generate.js +345 -0
  156. package/dist/evals/engine/promptfoo/guard.d.ts +10 -0
  157. package/dist/evals/engine/promptfoo/guard.js +116 -0
  158. package/dist/evals/engine/promptfoo/install.d.ts +17 -0
  159. package/dist/evals/engine/promptfoo/install.js +73 -0
  160. package/dist/evals/engine/promptfoo/judgeProviders.d.ts +2 -0
  161. package/dist/evals/engine/promptfoo/judgeProviders.js +9 -0
  162. package/dist/evals/engine/promptfoo/judgeServices.d.ts +6 -0
  163. package/dist/evals/engine/promptfoo/judgeServices.js +41 -0
  164. package/dist/evals/engine/promptfoo/locate.d.ts +21 -0
  165. package/dist/evals/engine/promptfoo/locate.js +68 -0
  166. package/dist/evals/engine/promptfoo/nodeVersion.d.ts +7 -0
  167. package/dist/evals/engine/promptfoo/nodeVersion.js +14 -0
  168. package/dist/evals/engine/promptfoo/normalize.d.ts +66 -0
  169. package/dist/evals/engine/promptfoo/normalize.js +261 -0
  170. package/dist/evals/engine/promptfoo/pinned.d.ts +5 -0
  171. package/dist/evals/engine/promptfoo/pinned.js +5 -0
  172. package/dist/evals/engine/promptfoo/rubricPrompt.d.ts +14 -0
  173. package/dist/evals/engine/promptfoo/rubricPrompt.js +105 -0
  174. package/dist/evals/engine/promptfoo/runTokens.d.ts +18 -0
  175. package/dist/evals/engine/promptfoo/runTokens.js +31 -0
  176. package/dist/evals/engine/promptfoo/status.d.ts +13 -0
  177. package/dist/evals/engine/promptfoo/status.js +16 -0
  178. package/dist/evals/estimate.d.ts +56 -0
  179. package/dist/evals/estimate.js +66 -0
  180. package/dist/evals/graders/codeGrader.d.ts +6 -0
  181. package/dist/evals/graders/codeGrader.js +85 -0
  182. package/dist/evals/graders/conversationCheckGrader.d.ts +6 -0
  183. package/dist/evals/graders/conversationCheckGrader.js +62 -0
  184. package/dist/evals/graders/fieldGrader.d.ts +11 -0
  185. package/dist/evals/graders/fieldGrader.js +117 -0
  186. package/dist/evals/graders/goal.d.ts +3 -0
  187. package/dist/evals/graders/goal.js +14 -0
  188. package/dist/evals/graders/index.d.ts +18 -0
  189. package/dist/evals/graders/index.js +34 -0
  190. package/dist/evals/graders/notApplicable.d.ts +5 -0
  191. package/dist/evals/graders/notApplicable.js +9 -0
  192. package/dist/evals/graders/path.d.ts +26 -0
  193. package/dist/evals/graders/path.js +75 -0
  194. package/dist/evals/graders/referenceGrader.d.ts +5 -0
  195. package/dist/evals/graders/referenceGrader.js +59 -0
  196. package/dist/evals/graders/schemaGrader.d.ts +5 -0
  197. package/dist/evals/graders/schemaGrader.js +29 -0
  198. package/dist/evals/graders/subject.d.ts +6 -0
  199. package/dist/evals/graders/subject.js +33 -0
  200. package/dist/evals/graders/toolCallsGrader.d.ts +6 -0
  201. package/dist/evals/graders/toolCallsGrader.js +100 -0
  202. package/dist/evals/graders/transcript.d.ts +12 -0
  203. package/dist/evals/graders/transcript.js +57 -0
  204. package/dist/evals/graders/types.d.ts +20 -0
  205. package/dist/evals/graders/types.js +1 -0
  206. package/dist/evals/judgeProviders.d.ts +16 -0
  207. package/dist/evals/judgeProviders.js +27 -0
  208. package/dist/evals/lineDiff.d.ts +5 -0
  209. package/dist/evals/lineDiff.js +34 -0
  210. package/dist/evals/listStatus.d.ts +31 -0
  211. package/dist/evals/listStatus.js +48 -0
  212. package/dist/evals/manager.d.ts +187 -0
  213. package/dist/evals/manager.js +795 -0
  214. package/dist/evals/plan.d.ts +65 -0
  215. package/dist/evals/plan.js +621 -0
  216. package/dist/evals/planInternalAgent.d.ts +19 -0
  217. package/dist/evals/planInternalAgent.js +205 -0
  218. package/dist/evals/providerKeys.d.ts +1 -0
  219. package/dist/evals/providerKeys.js +21 -0
  220. package/dist/evals/read/agentTargets.d.ts +37 -0
  221. package/dist/evals/read/agentTargets.js +101 -0
  222. package/dist/evals/read/api.d.ts +208 -0
  223. package/dist/evals/read/api.js +363 -0
  224. package/dist/evals/read/compare.d.ts +4 -0
  225. package/dist/evals/read/compare.js +39 -0
  226. package/dist/evals/read/datasets.d.ts +105 -0
  227. package/dist/evals/read/datasets.js +318 -0
  228. package/dist/evals/read/list.d.ts +66 -0
  229. package/dist/evals/read/list.js +182 -0
  230. package/dist/evals/read/results.d.ts +46 -0
  231. package/dist/evals/read/results.js +107 -0
  232. package/dist/evals/read/runs.d.ts +154 -0
  233. package/dist/evals/read/runs.js +295 -0
  234. package/dist/evals/read/suggestions.d.ts +43 -0
  235. package/dist/evals/read/suggestions.js +73 -0
  236. package/dist/evals/runner/FakeAgentBackend.d.ts +40 -0
  237. package/dist/evals/runner/FakeAgentBackend.js +82 -0
  238. package/dist/evals/runner/agentCaseRunner.d.ts +24 -0
  239. package/dist/evals/runner/agentCaseRunner.js +388 -0
  240. package/dist/evals/runner/caseRunner.d.ts +8 -0
  241. package/dist/evals/runner/caseRunner.js +28 -0
  242. package/dist/evals/runner/conversationSubject.d.ts +18 -0
  243. package/dist/evals/runner/conversationSubject.js +123 -0
  244. package/dist/evals/runner/internalAgentCaseRunner.d.ts +6 -0
  245. package/dist/evals/runner/internalAgentCaseRunner.js +250 -0
  246. package/dist/evals/runner/simulatorModel.d.ts +51 -0
  247. package/dist/evals/runner/simulatorModel.js +58 -0
  248. package/dist/evals/runner/simulatorPrompt.d.ts +29 -0
  249. package/dist/evals/runner/simulatorPrompt.js +59 -0
  250. package/dist/evals/runner/stageCaseRunner.d.ts +30 -0
  251. package/dist/evals/runner/stageCaseRunner.js +279 -0
  252. package/dist/evals/runner/userDriver.d.ts +71 -0
  253. package/dist/evals/runner/userDriver.js +104 -0
  254. package/dist/evals/scoring.d.ts +34 -0
  255. package/dist/evals/scoring.js +67 -0
  256. package/dist/evals/snapshot.d.ts +191 -0
  257. package/dist/evals/snapshot.js +70 -0
  258. package/dist/evals/stageDiff.d.ts +8 -0
  259. package/dist/evals/stageDiff.js +48 -0
  260. package/dist/evals/stats.d.ts +95 -0
  261. package/dist/evals/stats.js +220 -0
  262. package/dist/evals/statsAdapter.d.ts +4 -0
  263. package/dist/evals/statsAdapter.js +30 -0
  264. package/dist/evals/statsTypes.d.ts +51 -0
  265. package/dist/evals/statsTypes.js +18 -0
  266. package/dist/evals/storeError.d.ts +5 -0
  267. package/dist/evals/storeError.js +8 -0
  268. package/dist/evals/storeTypes.d.ts +207 -0
  269. package/dist/evals/storeTypes.js +1 -0
  270. package/dist/evals/tTable.d.ts +3 -0
  271. package/dist/evals/tTable.js +15 -0
  272. package/dist/evals/triage/constants.d.ts +26 -0
  273. package/dist/evals/triage/constants.js +33 -0
  274. package/dist/evals/triage/credentials.d.ts +13 -0
  275. package/dist/evals/triage/credentials.js +20 -0
  276. package/dist/evals/triage/jevClassifier.d.ts +14 -0
  277. package/dist/evals/triage/jevClassifier.js +124 -0
  278. package/dist/evals/triage/judgeClassifier.d.ts +10 -0
  279. package/dist/evals/triage/judgeClassifier.js +76 -0
  280. package/dist/evals/triage/prompts.d.ts +16 -0
  281. package/dist/evals/triage/prompts.js +64 -0
  282. package/dist/evals/triage/service.d.ts +79 -0
  283. package/dist/evals/triage/service.js +217 -0
  284. package/dist/evals/triage/stateBuilder.d.ts +19 -0
  285. package/dist/evals/triage/stateBuilder.js +125 -0
  286. package/dist/evals/triage/types.d.ts +60 -0
  287. package/dist/evals/triage/types.js +8 -0
  288. package/dist/evals/types.d.ts +357 -0
  289. package/dist/evals/types.js +4 -0
  290. package/dist/guide/cardContract.d.ts +133 -0
  291. package/dist/guide/cardContract.js +156 -0
  292. package/dist/guide/chat.d.ts +45 -0
  293. package/dist/guide/chat.js +378 -0
  294. package/dist/guide/knowledge/index.d.ts +14 -0
  295. package/dist/guide/knowledge/index.js +109 -0
  296. package/dist/guide/knowledge/topics/agents.d.ts +2 -0
  297. package/dist/guide/knowledge/topics/agents.js +58 -0
  298. package/dist/guide/knowledge/topics/bestPractices.d.ts +2 -0
  299. package/dist/guide/knowledge/topics/bestPractices.js +67 -0
  300. package/dist/guide/knowledge/topics/connections.d.ts +2 -0
  301. package/dist/guide/knowledge/topics/connections.js +66 -0
  302. package/dist/guide/knowledge/topics/consoleMap.d.ts +2 -0
  303. package/dist/guide/knowledge/topics/consoleMap.js +55 -0
  304. package/dist/guide/knowledge/topics/evals.d.ts +2 -0
  305. package/dist/guide/knowledge/topics/evals.js +72 -0
  306. package/dist/guide/knowledge/topics/limitations.d.ts +2 -0
  307. package/dist/guide/knowledge/topics/limitations.js +84 -0
  308. package/dist/guide/knowledge/topics/mcpSkillsBrowser.d.ts +2 -0
  309. package/dist/guide/knowledge/topics/mcpSkillsBrowser.js +57 -0
  310. package/dist/guide/knowledge/topics/memories.d.ts +2 -0
  311. package/dist/guide/knowledge/topics/memories.js +63 -0
  312. package/dist/guide/knowledge/topics/modelsAndProviders.d.ts +2 -0
  313. package/dist/guide/knowledge/topics/modelsAndProviders.js +56 -0
  314. package/dist/guide/knowledge/topics/overview.d.ts +2 -0
  315. package/dist/guide/knowledge/topics/overview.js +56 -0
  316. package/dist/guide/knowledge/topics/pipelines.d.ts +2 -0
  317. package/dist/guide/knowledge/topics/pipelines.js +93 -0
  318. package/dist/guide/knowledge/topics/stages.d.ts +2 -0
  319. package/dist/guide/knowledge/topics/stages.js +54 -0
  320. package/dist/guide/knowledge/topics/tasks.d.ts +2 -0
  321. package/dist/guide/knowledge/topics/tasks.js +52 -0
  322. package/dist/guide/knowledge/topics/triggers.d.ts +2 -0
  323. package/dist/guide/knowledge/topics/triggers.js +68 -0
  324. package/dist/guide/knowledge/topics/troubleshooting.d.ts +2 -0
  325. package/dist/guide/knowledge/topics/troubleshooting.js +85 -0
  326. package/dist/guide/knowledgeTools.d.ts +2 -0
  327. package/dist/guide/knowledgeTools.js +56 -0
  328. package/dist/guide/showUi.d.ts +6 -0
  329. package/dist/guide/showUi.js +546 -0
  330. package/dist/guide/threadStore.d.ts +48 -0
  331. package/dist/guide/threadStore.js +189 -0
  332. package/dist/guide/writeRoot.d.ts +11 -0
  333. package/dist/guide/writeRoot.js +70 -0
  334. package/dist/hosted/translate.js +2 -0
  335. package/dist/mcp/agentTools.js +12 -0
  336. package/dist/mcp/catalogTools.js +18 -20
  337. package/dist/mcp/catalogWriteTools.d.ts +8 -0
  338. package/dist/mcp/catalogWriteTools.js +225 -0
  339. package/dist/mcp/connectionTools.d.ts +3 -0
  340. package/dist/mcp/connectionTools.js +85 -0
  341. package/dist/mcp/controlTools.js +34 -1
  342. package/dist/mcp/deps.d.ts +16 -0
  343. package/dist/mcp/evalTools.d.ts +3 -0
  344. package/dist/mcp/evalTools.js +943 -0
  345. package/dist/mcp/memoryHostTools.d.ts +3 -0
  346. package/dist/mcp/memoryHostTools.js +72 -0
  347. package/dist/mcp/pipelineAuthorTools.js +14 -1
  348. package/dist/mcp/server.js +6 -0
  349. package/dist/mcp/tools.js +8 -0
  350. package/dist/mcp/triggerTools.js +77 -31
  351. package/dist/models/response.d.ts +7 -2
  352. package/dist/models/response.js +6 -1
  353. package/dist/operatorAgent/agentAuthorContext.d.ts +1 -1
  354. package/dist/operatorAgent/agentAuthorContext.js +1 -1
  355. package/dist/operatorAgent/evalGate.d.ts +22 -0
  356. package/dist/operatorAgent/evalGate.js +77 -0
  357. package/dist/operatorAgent/fakeHost.js +10 -2
  358. package/dist/operatorAgent/host.js +18 -2
  359. package/dist/operatorAgent/index.d.ts +1 -0
  360. package/dist/operatorAgent/index.js +1 -0
  361. package/dist/operatorAgent/internalAgents.d.ts +11 -0
  362. package/dist/operatorAgent/internalAgents.js +13 -0
  363. package/dist/operatorAgent/piModel.d.ts +5 -1
  364. package/dist/operatorAgent/piModel.js +32 -14
  365. package/dist/operatorAgent/profiles/agentAuthor.d.ts +3 -1
  366. package/dist/operatorAgent/profiles/agentAuthor.js +201 -32
  367. package/dist/operatorAgent/profiles/agentAuthorPlaybook.d.ts +1 -1
  368. package/dist/operatorAgent/profiles/agentAuthorPlaybook.js +48 -15
  369. package/dist/operatorAgent/profiles/authorReadable.d.ts +2 -0
  370. package/dist/operatorAgent/profiles/authorReadable.js +26 -0
  371. package/dist/operatorAgent/profiles/guideConfirm.d.ts +21 -0
  372. package/dist/operatorAgent/profiles/guideConfirm.js +100 -0
  373. package/dist/operatorAgent/profiles/guideTools.d.ts +7 -0
  374. package/dist/operatorAgent/profiles/guideTools.js +123 -0
  375. package/dist/operatorAgent/profiles/stageflowGuide.d.ts +7 -0
  376. package/dist/operatorAgent/profiles/stageflowGuide.js +132 -0
  377. package/dist/operatorAgent/profiles/workshopAuthor.js +23 -0
  378. package/dist/operatorAgent/profiles/workshopAuthorPlaybook.d.ts +1 -1
  379. package/dist/operatorAgent/profiles/workshopAuthorPlaybook.js +9 -1
  380. package/dist/operatorAgent/profiles/workshopAuthorTools.d.ts +2 -0
  381. package/dist/operatorAgent/profiles/workshopAuthorTools.js +197 -9
  382. package/dist/operatorAgent/types.d.ts +23 -0
  383. package/dist/package-meta.d.ts +1 -1
  384. package/dist/package-meta.js +1 -1
  385. package/dist/runstore/port.d.ts +43 -0
  386. package/dist/runstore/retention.d.ts +2 -1
  387. package/dist/runstore/retention.js +3 -7
  388. package/dist/runstore/runStatusClock.d.ts +17 -0
  389. package/dist/runstore/runStatusClock.js +19 -0
  390. package/dist/runstore/sqlite/SqliteRunStore.d.ts +29 -0
  391. package/dist/runstore/sqlite/SqliteRunStore.js +144 -50
  392. package/dist/runstore/sqlite/evalStore.d.ts +20 -0
  393. package/dist/runstore/sqlite/evalStore.js +541 -0
  394. package/dist/runstore/sqlite/migrations/015-evals.d.ts +12 -0
  395. package/dist/runstore/sqlite/migrations/015-evals.js +157 -0
  396. package/dist/runstore/sqlite/migrations/016-eval-subject-ref.d.ts +12 -0
  397. package/dist/runstore/sqlite/migrations/016-eval-subject-ref.js +20 -0
  398. package/dist/runstore/sqlite/migrations/017-eval-result-suggestions.d.ts +11 -0
  399. package/dist/runstore/sqlite/migrations/017-eval-result-suggestions.js +36 -0
  400. package/dist/runstore/sqlite/migrations/index.js +6 -0
  401. package/dist/runstore/sqlite/suggestionStore.d.ts +14 -0
  402. package/dist/runstore/sqlite/suggestionStore.js +132 -0
  403. package/dist/runstore/workspaceLayout.js +6 -1
  404. package/dist/runtime/artifactDiskInspect.d.ts +14 -0
  405. package/dist/runtime/artifactDiskInspect.js +52 -0
  406. package/dist/runtime/artifactPath.d.ts +24 -0
  407. package/dist/runtime/artifactPath.js +84 -0
  408. package/dist/runtime/completionCheckRunner.js +15 -43
  409. package/dist/runtime/githubPollSource.d.ts +22 -4
  410. package/dist/runtime/githubPollSource.js +93 -8
  411. package/dist/runtime/pipelineRunner.d.ts +2 -1
  412. package/dist/runtime/pipelineRunner.js +2 -0
  413. package/dist/runtime/priorArtifactGrants.d.ts +8 -0
  414. package/dist/runtime/priorArtifactGrants.js +105 -0
  415. package/dist/runtime/runActionEligibility.d.ts +46 -0
  416. package/dist/runtime/runActionEligibility.js +123 -0
  417. package/dist/runtime/runManager.d.ts +6 -2
  418. package/dist/runtime/runManager.js +60 -16
  419. package/dist/runtime/runRetentionSweep.js +2 -2
  420. package/dist/runtime/runRetryCoordinator.d.ts +2 -14
  421. package/dist/runtime/runRetryCoordinator.js +3 -67
  422. package/dist/runtime/sandboxContainer.d.ts +7 -0
  423. package/dist/runtime/sandboxContainer.js +48 -6
  424. package/dist/runtime/sandboxDesk.d.ts +2 -1
  425. package/dist/runtime/sandboxDesk.js +11 -12
  426. package/dist/runtime/stageEnvironment.js +1 -0
  427. package/dist/runtime/stageRoots.d.ts +12 -0
  428. package/dist/runtime/stageSandbox.d.ts +2 -1
  429. package/dist/runtime/stageSandbox.js +18 -2
  430. package/dist/runtime/stageWorker.js +20 -0
  431. package/dist/server/agentAuthorRoutes.js +59 -1
  432. package/dist/server/bootstrap.d.ts +13 -0
  433. package/dist/server/bootstrap.js +69 -0
  434. package/dist/server/controlToken.js +3 -0
  435. package/dist/server/evalInternalRoutes.d.ts +14 -0
  436. package/dist/server/evalInternalRoutes.js +87 -0
  437. package/dist/server/evalRouteContext.d.ts +46 -0
  438. package/dist/server/evalRouteContext.js +43 -0
  439. package/dist/server/evalRoutes.d.ts +5 -0
  440. package/dist/server/evalRoutes.js +1456 -0
  441. package/dist/server/evalTriageRoutes.d.ts +2 -0
  442. package/dist/server/evalTriageRoutes.js +95 -0
  443. package/dist/server/guideRoutes.d.ts +5 -0
  444. package/dist/server/guideRoutes.js +166 -0
  445. package/dist/server/http.d.ts +15 -0
  446. package/dist/server/http.js +67 -3
  447. package/dist/server/internalAgentRoutes.d.ts +6 -0
  448. package/dist/server/internalAgentRoutes.js +12 -0
  449. package/dist/server/mcpHost.js +5 -0
  450. package/dist/toolkit/meta.d.ts +1 -1
  451. package/dist/toolkit/meta.js +53 -0
  452. package/dist/toolkit/profiles.d.ts +5 -0
  453. package/dist/toolkit/profiles.js +13 -1
  454. package/dist/tools/askOperator.js +2 -1
  455. package/dist/tools/emitStageEnvelope.d.ts +17 -16
  456. package/dist/tools/emitStageEnvelope.js +46 -32
  457. package/dist/tools/stageToolNames.d.ts +4 -0
  458. package/dist/tools/stageToolNames.js +4 -0
  459. package/dist/tools/workingState.d.ts +40 -0
  460. package/dist/tools/workingState.js +108 -0
  461. package/dist/tools/writeStageArtifact.d.ts +0 -9
  462. package/dist/tools/writeStageArtifact.js +2 -1
  463. package/dist/types/stageflowManifest.d.ts +6 -0
  464. package/dist/ui/assets/{MarkdownText-D7tYaIFO.js → MarkdownText-S5C_vemc.js} +2 -2
  465. package/dist/ui/assets/adapters-C0l4ruiR.js +17 -0
  466. package/dist/ui/assets/chat-CjnsmvqR.js +2 -0
  467. package/dist/ui/assets/chat-DFDd4UjS.css +2 -0
  468. package/dist/ui/assets/{main-BFo79krC.css → main-Del1GeLf.css} +1 -1
  469. package/dist/ui/assets/main-_yXVqcW9.js +277 -0
  470. package/dist/ui/chat.html +3 -4
  471. package/dist/ui/index.html +3 -4
  472. package/dist/workshop/chatTurn.js +1 -1
  473. package/dist/workshop/workshopPin.d.ts +3 -3
  474. package/dist/workshop/workshopPin.js +16 -15
  475. package/examples/README.md +2 -0
  476. package/examples/compaction-stress/README.md +30 -0
  477. package/examples/compaction-stress/check-run.mjs +53 -0
  478. package/examples/compaction-stress/collect-evidence.yaml +60 -0
  479. package/examples/compaction-stress/compaction-stress.pipeline.yaml +141 -0
  480. package/examples/compaction-stress/compaction-stress.task.yaml +15 -0
  481. package/examples/compaction-stress/generate-evidence.mjs +110 -0
  482. package/examples/compaction-stress/root-cause.yaml +26 -0
  483. package/examples/compaction-stress/stageflow.yaml +9 -0
  484. package/examples/compaction-stress/write-postmortem.yaml +40 -0
  485. package/examples/document-policy-review/README.md +35 -0
  486. package/examples/document-policy-review/agents/compliance.agent.yaml +42 -0
  487. package/examples/document-policy-review/documents/acme-vendor-sow.md +15 -0
  488. package/examples/document-policy-review/documents/support-runbook.md +13 -0
  489. package/examples/document-policy-review/policies/acceptable-use.md +13 -0
  490. package/examples/document-policy-review/policies/data-handling.md +17 -0
  491. package/examples/document-policy-review/policies/vendor-security.md +17 -0
  492. package/examples/evals/README.md +141 -0
  493. package/examples/evals/critique-sample.dataset.jsonl +8 -0
  494. package/examples/evals/critique-sample.eval.yaml +34 -0
  495. package/examples/evals/critique-sample.task.yaml +4 -0
  496. package/examples/evals/eval-sample.pipeline.yaml +35 -0
  497. package/examples/evals/guide-behavior.dataset.jsonl +15 -0
  498. package/examples/evals/guide-behavior.eval.yaml +35 -0
  499. package/examples/evals/guide-depth.dataset.jsonl +35 -0
  500. package/examples/evals/guide-depth.eval.yaml +169 -0
  501. package/examples/evals/support-sample.agent.yaml +20 -0
  502. package/examples/evals/support-sample.dataset.jsonl +6 -0
  503. package/examples/evals/support-sample.eval.yaml +38 -0
  504. package/examples/memory/evals/guide-behavior.dataset.jsonl +15 -0
  505. package/examples/memory/evals/guide-behavior.eval.yaml +35 -0
  506. package/examples/memory/evals/guide-depth.dataset.jsonl +35 -0
  507. package/examples/memory/evals/guide-depth.eval.yaml +169 -0
  508. package/examples/stageflow.yaml +6 -0
  509. package/package.json +1 -1
  510. package/skills/stageflow/SKILL.md +5 -2
  511. package/skills/stageflow/references/control-surface.md +4 -2
  512. package/skills/stageflow/references/evals.md +68 -0
  513. package/skills/stageflow-author/SKILL.md +4 -0
  514. package/skills/stageflow-run/SKILL.md +4 -0
  515. package/dist/ui/assets/AssistantRuntimeProvider-CsiPFhCT.js +0 -9
  516. package/dist/ui/assets/ReadonlyStore-BfXqHykm.js +0 -6
  517. package/dist/ui/assets/chat-BbLukq9W.js +0 -5
  518. package/dist/ui/assets/chat-zIZU_bP1.css +0 -2
  519. package/dist/ui/assets/main-CijYMeM0.js +0 -259
@@ -9,12 +9,15 @@ import type { ContactInfo } from "../channels/types.js";
9
9
  import type { McpToolDeps } from "../mcp/deps.js";
10
10
  import { AgentService, type AgentEnvironment } from "./service.js";
11
11
  import type { ConversationBackend } from "./sessions.js";
12
+ import { EvalGateRegistry } from "./evalGate.js";
12
13
  import { PublicWebChat } from "./webChat/publicChat.js";
13
14
  export type AgentHostContext = {
14
15
  service: AgentService;
15
16
  inbound: AgentInboundRouter;
16
17
  publicChat: PublicWebChat;
17
18
  chat: AgentChatController;
19
+ /** Eval tool gates by session id; the eval runner registers a gate for each eval session it opens. */
20
+ evalGates: EvalGateRegistry;
18
21
  backend: ConversationBackend;
19
22
  /** Streams held open to AgentMail and iMessage; absent unless the Host listens (not in tests). */
20
23
  channelListeners?: ChannelSupervisor;
@@ -50,5 +53,5 @@ export declare function createAgentHostContext(options: {
50
53
  /** Host services the Stageflow tools need; agent services are added here. Without it agents get no Stageflow tools. */
51
54
  /** Hold streams open to AgentMail and iMessage for agents linked to them. Only a running Host does this. */
52
55
  listenOnChannels?: boolean;
53
- toolkitDeps?: Pick<McpToolDeps, "manager" | "store" | "agentDir" | "providerAuthContext" | "projectRoot" | "providerBoot">;
56
+ toolkitDeps?: Pick<McpToolDeps, "manager" | "store" | "agentDir" | "providerAuthContext" | "projectRoot" | "providerBoot" | "channels" | "memories" | "evalRunManager">;
54
57
  }): AgentHostContext;
@@ -12,6 +12,7 @@ import { buildToolkit } from "../toolkit/index.js";
12
12
  import { createPiAgentRuntime } from "./runtime/piRuntime.js";
13
13
  import { AgentService } from "./service.js";
14
14
  import { getModelCatalog } from "../models/catalog.js";
15
+ import { EvalGateRegistry } from "./evalGate.js";
15
16
  import { defaultAgentProjectRoot } from "./projectRoot.js";
16
17
  import { PublicWebChat } from "./webChat/publicChat.js";
17
18
  import { AgentStore } from "./store.js";
@@ -82,9 +83,11 @@ export function createAgentHostContext(options) {
82
83
  }
83
84
  : {}),
84
85
  });
86
+ const evalGates = new EvalGateRegistry();
85
87
  const chat = new AgentChatController({
86
88
  service,
87
89
  backend,
90
+ evalGates,
88
91
  otlpSink: "otlpSink" in options ? options.otlpSink : otlpSinkFromEnv(),
89
92
  logError: (message) => console.error(message),
90
93
  });
@@ -147,7 +150,7 @@ export function createAgentHostContext(options) {
147
150
  delivery.start();
148
151
  if (options.listenOnChannels)
149
152
  void inbound.resumeInterrupted().catch((error) => console.error(`agent resume failed: ${String(error)}`));
150
- return { service, chat, backend, inbound, publicChat, channelContact, ...(channelListeners ? { channelListeners } : {}), delivery, stop: async () => {
153
+ return { service, chat, evalGates, backend, inbound, publicChat, channelContact, ...(channelListeners ? { channelListeners } : {}), delivery, stop: async () => {
151
154
  delivery.stop();
152
155
  await channelListeners?.stop();
153
156
  // The Host owns every runtime session's lifetime: nothing outlives it.
@@ -1,4 +1,4 @@
1
- import { type AgentSession } from "@earendil-works/pi-coding-agent";
1
+ import { type AgentSession, type ExtensionFactory } from "@earendil-works/pi-coding-agent";
2
2
  import { type AgentDefinition } from "../../config/loadAgent.js";
3
3
  import { type StageMemory } from "../../memory/access.js";
4
4
  import { type SandboxRunner } from "../sandbox.js";
@@ -34,10 +34,12 @@ export type OpenSessionInput = {
34
34
  reason: string;
35
35
  terminate?: boolean;
36
36
  } | undefined>;
37
- delegateTool?: (agentId: string, message: string) => Promise<string>;
37
+ delegateTool?: (agentId: string, message: string, callId: string) => Promise<string>;
38
38
  /** Stageflow tools this agent is granted. */
39
39
  stageflowTools?: ToolkitTool[];
40
40
  memory?: StageMemory;
41
+ /** Defaults to true; one-shot judge sessions have no use for it. */
42
+ workingState?: boolean;
41
43
  hooks: () => TurnHooks | undefined;
42
44
  };
43
45
  export type OpenedSession = {
@@ -48,5 +50,7 @@ export type OpenedSession = {
48
50
  toolNames: string[];
49
51
  shutdown(): Promise<void>;
50
52
  };
53
+ /** Runs the agent tool gate before every call, except for tools the session wiring marks as internal. */
54
+ export declare function createAgentGateExtension(gate: OpenSessionInput["gate"], isInternalTool: (toolName: string) => boolean): ExtensionFactory;
51
55
  export declare const DEFAULT_IDLE_RELEASE_MS: number;
52
56
  export declare function createPiAgentRuntime(options: PiRuntimeOptions): ConversationBackend;
@@ -1,11 +1,13 @@
1
1
  import { mkdir, readFile } from "node:fs/promises";
2
2
  import path from "node:path";
3
- import { defineTool, ModelRuntime, resolveCliModel, SessionManager, SettingsManager, } from "@earendil-works/pi-coding-agent";
3
+ import { defineTool, ModelRuntime, resolveCliModel, SessionManager, } from "@earendil-works/pi-coding-agent";
4
4
  import { Type } from "typebox";
5
5
  import { collectMcpExtensionToolNames, mcpToolMetadataMissing } from "../../agent/piAdapter.js";
6
6
  import { attachIsolatedMcp } from "../../agent/piIsolatedMcp.js";
7
7
  import { warmIsolatedMcpMetadata } from "../../agent/piIsolatedMcpProbe.js";
8
8
  import { createPiAgentSession, createSealedResourceLoader } from "../../agent/piSessionFactory.js";
9
+ import { createPiSettingsManager } from "../../agent/piSettings.js";
10
+ import { createSessionContextWiring } from "../../compaction/sessionWiring.js";
9
11
  import { bindCursorApiKey, isCursorModelRef } from "../../agent/cursorProvider.js";
10
12
  import { findProviderSupport } from "../../agent/providerSupport.js";
11
13
  import { grantedBuiltinTools } from "../../config/loadAgent.js";
@@ -19,11 +21,22 @@ import { isUsableAuthFile, resolveCredentialBinding } from "../../runtime/creden
19
21
  import { getModelCatalog } from "../../models/catalog.js";
20
22
  import { AgentError } from "../errors.js";
21
23
  import { MEMORY_STORE_BASH_DENIED, memoryStorePathInCommand } from "../../memory/bashDeny.js";
24
+ import { compactionUsageCost } from "../../agent/compactionEvents.js";
22
25
  import { memoryHome } from "../../memory/host.js";
23
26
  import { forbiddenWriteTarget } from "../policy.js";
24
27
  import { prepareExecutionLaunch } from "../sandbox.js";
25
28
  import { grantedStageflowTools, isOperatorOnlyTool } from "../../toolkit/index.js";
26
29
  import { grantIdForPiTool, STAGEFLOW_PI_PREFIX } from "./types.js";
30
+ /** Runs the agent tool gate before every call, except for tools the session wiring marks as internal. */
31
+ export function createAgentGateExtension(gate, isInternalTool) {
32
+ return (pi) => {
33
+ pi.on("tool_call", async (event) => {
34
+ if (isInternalTool(event.toolName))
35
+ return undefined;
36
+ return gate({ toolCallId: event.toolCallId, toolName: event.toolName, input: event.input });
37
+ });
38
+ };
39
+ }
27
40
  function piToolNames(definition) {
28
41
  return grantedBuiltinTools(definition);
29
42
  }
@@ -84,7 +97,7 @@ async function openPiSession(options, input) {
84
97
  try {
85
98
  await mkdir(options.agentDir, { recursive: true });
86
99
  const modelRuntime = await ModelRuntime.create({ authPath, modelsPath: path.join(path.dirname(authPath), "models.json") });
87
- const settingsManager = SettingsManager.inMemory({ compaction: { enabled: true } });
100
+ const settingsManager = createPiSettingsManager();
88
101
  const mcpServers = Object.keys(definition.tools.mcp);
89
102
  const resolvedMcp = mcpServers.length > 0
90
103
  ? await resolveStageMcpServers({ projectRoot, allowlist: mcpServers, env: {}, scope: { kind: "agent" } })
@@ -97,18 +110,18 @@ async function openPiSession(options, input) {
97
110
  throw new AgentError("agent.backend_unavailable", `Skill "${name}" is not installed`);
98
111
  skillPaths.push(skill.filePath);
99
112
  }
100
- const gateExtension = (pi) => {
101
- pi.on("tool_call", async (event) => {
102
- const outcome = await input.gate({ toolCallId: event.toolCallId, toolName: event.toolName, input: event.input });
103
- return outcome;
104
- });
105
- };
106
- const extensionFactories = [{ name: "stageflow-agent-gate", factory: gateExtension }, ...(attached.extensionFactories ?? [])];
113
+ const contextWiring = createSessionContextWiring({ workingState: input.workingState !== false });
114
+ const gateExtension = createAgentGateExtension(input.gate, contextWiring.isInternalTool);
115
+ const extensionFactories = [
116
+ { name: "stageflow-agent-gate", factory: gateExtension },
117
+ ...contextWiring.extensions,
118
+ ...(attached.extensionFactories ?? []),
119
+ ];
107
120
  const loader = createSealedResourceLoader({
108
121
  cwd: projectRoot,
109
122
  agentDir: options.agentDir,
110
123
  settingsManager,
111
- systemPrompt: input.systemPrompt,
124
+ systemPrompt: contextWiring.guidance ? `${input.systemPrompt}\n\n${contextWiring.guidance}` : input.systemPrompt,
112
125
  additionalExtensionPaths: extensionPaths,
113
126
  ...(skillPaths.length > 0 ? { additionalSkillPaths: skillPaths } : {}),
114
127
  extensionFactories,
@@ -127,6 +140,7 @@ async function openPiSession(options, input) {
127
140
  throw new AgentError("agent.backend_unavailable", `Failed to load extension(s): ${errors.map((e) => `${e.path}: ${e.error}`).join("; ")}`);
128
141
  }
129
142
  const toolNames = [...input.toolNames];
143
+ toolNames.push(...contextWiring.toolNames);
130
144
  if (attached.extensionFactories) {
131
145
  const mcp = collectMcpExtensionToolNames(loader);
132
146
  if (!mcp.ok)
@@ -149,8 +163,9 @@ async function openPiSession(options, input) {
149
163
  label: `Ask ${agentId}`,
150
164
  description: `Hand a task to the "${agentId}" agent and get its reply.`,
151
165
  parameters: Type.Object({ message: Type.String({ description: "The task or question for the agent." }) }),
152
- execute: async (_id, args) => {
153
- const reply = await input.delegateTool(agentId, args.message);
166
+ constrainedSampling: { type: "json_schema", strict: "prefer" },
167
+ execute: async (callId, args) => {
168
+ const reply = await input.delegateTool(agentId, args.message, callId);
154
169
  return { content: [{ type: "text", text: reply }], details: {} };
155
170
  },
156
171
  }));
@@ -159,7 +174,10 @@ async function openPiSession(options, input) {
159
174
  }
160
175
  if (input.memory) {
161
176
  for (const definition of memorySession(input.memory).tools) {
162
- customTools.push(defineTool(definition));
177
+ customTools.push(defineTool({
178
+ ...definition,
179
+ constrainedSampling: { type: "json_schema", strict: "prefer" },
180
+ }));
163
181
  toolNames.push(definition.name);
164
182
  }
165
183
  }
@@ -169,6 +187,7 @@ async function openPiSession(options, input) {
169
187
  label: tool.name,
170
188
  description: tool.description,
171
189
  parameters: Type.Unsafe(tool.parameters),
190
+ constrainedSampling: { type: "json_schema", strict: "prefer" },
172
191
  execute: async (_id, args, signal) => {
173
192
  const result = await tool.run(args ?? {}, { signal: signal ?? new AbortController().signal, caller: { agentId: definition.id, definition } });
174
193
  if (!result.ok)
@@ -296,7 +315,7 @@ export function createPiAgentRuntime(options) {
296
315
  hooks: () => state.hooks,
297
316
  ...(memory ? { memory } : {}),
298
317
  ...(stageflowTools.length > 0 ? { stageflowTools } : {}),
299
- ...(subAgents.length > 0 ? { delegateTool: (agentId, message) => state.hooks.delegate(agentId, message) } : {}),
318
+ ...(subAgents.length > 0 ? { delegateTool: (agentId, message, callId) => state.hooks.delegate(agentId, message, callId) } : {}),
300
319
  gate: async (call) => {
301
320
  const hooks = state.hooks;
302
321
  if (!hooks)
@@ -334,6 +353,7 @@ export function createPiAgentRuntime(options) {
334
353
  let text = "";
335
354
  const usage = { inputTokens: 0, outputTokens: 0, costUsd: 0 };
336
355
  let startedAt = new Date();
356
+ let compactionStartedAt;
337
357
  const calls = new Map();
338
358
  // A model call that goes quiet (provider queue, dropped connection) must not hold the session forever.
339
359
  // Waiting on a person (approval), a running tool or a sub-agent is not a stall.
@@ -370,7 +390,20 @@ export function createPiAgentRuntime(options) {
370
390
  const unsubscribe = session.subscribe((event) => {
371
391
  arm();
372
392
  const e = event;
373
- if (e.type === "message_start" && e.message?.role === "assistant")
393
+ if (e.type === "compaction_start")
394
+ compactionStartedAt = new Date();
395
+ else if (e.type === "compaction_end") {
396
+ const end = event;
397
+ const info = compactionUsageCost(end);
398
+ usage.inputTokens += info.inputTokens;
399
+ usage.outputTokens += info.outputTokens;
400
+ usage.costUsd += info.costUsd;
401
+ const model = session.model?.id;
402
+ if (end.result?.usage) {
403
+ input.hooks.modelFinished({ startedAt: compactionStartedAt ?? new Date(), endedAt: new Date(), ...info, ...(model ? { model } : {}) });
404
+ }
405
+ }
406
+ else if (e.type === "message_start" && e.message?.role === "assistant")
374
407
  startedAt = new Date();
375
408
  else if (e.type === "message_update" && e.assistantMessageEvent?.type === "text_delta" && typeof e.assistantMessageEvent.delta === "string") {
376
409
  text += e.assistantMessageEvent.delta;
@@ -433,8 +466,9 @@ export function createPiAgentRuntime(options) {
433
466
  const opened = await open({
434
467
  projectRoot: input.projectRoot,
435
468
  definition: { ...input.definition, tools: { ...input.definition.tools, builtin: [], builtin_tools: [], mcp: {}, skills: [] }, sub_agents: [] },
436
- systemPrompt: "You are a strict evaluator. Answer only with the requested number.",
469
+ systemPrompt: input.systemPrompt ?? "You are a strict evaluator. Answer only with the requested number.",
437
470
  toolNames: [],
471
+ workingState: false,
438
472
  gate: async () => ({ block: true, reason: "No tools" }),
439
473
  hooks: () => undefined,
440
474
  });
@@ -39,7 +39,7 @@ export type TurnHooks = {
39
39
  model?: string;
40
40
  }): void;
41
41
  /** Run another agent for a `agent:<id>` call and return its reply. */
42
- delegate(agentId: string, message: string): Promise<string>;
42
+ delegate(agentId: string, message: string, callId?: string): Promise<string>;
43
43
  };
44
44
  export type CompleteInput = {
45
45
  sessionId: string;
@@ -64,6 +64,8 @@ export type ConversationBackend = {
64
64
  projectRoot: string;
65
65
  definition: AgentDefinition;
66
66
  prompt: string;
67
+ /** Replaces the default "strict evaluator" system prompt. */
68
+ systemPrompt?: string;
67
69
  signal: AbortSignal;
68
70
  }): Promise<string>;
69
71
  /** Drop any cached model session for a conversation session. */
@@ -3,6 +3,7 @@ import { type AgentInboundMessage } from "./communications/port.js";
3
3
  import { ApprovalBroker } from "./approvalBroker.js";
4
4
  import { type DeliveryLedger, type ScheduleLedger } from "./ledgers.js";
5
5
  import { type FinishInput } from "./turnLifecycle.js";
6
+ import { type EvalSessionOverrides } from "./evalSession.js";
6
7
  import { type DiffLine } from "./lineDiff.js";
7
8
  import { AgentStore, type AgentApproval, type AgentEvalScore, type AgentMessage, type AgentRevision, type AgentRevisionMeta, type AgentSession, type AgentSessionListItem, type AgentDelivery, type AgentSpan, type AgentTurn, type ApprovalActor, type RevisionSource, type SessionQuery, type SessionStats, type SessionStatus } from "./store.js";
8
9
  /** Lookups outside the agents directory, used only to produce non-blocking warnings. */
@@ -88,6 +89,8 @@ export declare class AgentService {
88
89
  private readonly environment;
89
90
  private readonly now;
90
91
  private readonly tails;
92
+ /** Overrides of open eval sessions. Memory only: eval sessions do not survive a Host restart. */
93
+ private readonly evalOverrides;
91
94
  /** Wakes a turn paused at an ask-first tool when its approval is decided. */
92
95
  readonly approvalBroker: ApprovalBroker;
93
96
  /** Owns every legal change of a turn, its session and its approval. */
@@ -140,6 +143,25 @@ export declare class AgentService {
140
143
  get(projectRoot: string, agentId: string): Promise<AgentDetail>;
141
144
  /** The definition a session is pinned to. */
142
145
  definitionAt(projectRoot: string, agentId: string, revision: number): Promise<AgentDefinition>;
146
+ /** The pinned definition, with an eval session's overrides applied. Real sessions get it unchanged. */
147
+ private effectiveDefinition;
148
+ /** The overrides an eval session was opened with (sub-agent sessions inherit them), or undefined for a real session. */
149
+ evalOverridesOf(sessionId: string): EvalSessionOverrides | undefined;
150
+ /** Every eval session below this one (sub-agents and theirs). */
151
+ listChildSessions(sessionId: string): AgentSession[];
152
+ /** Delete eval sessions and everything below them. Refuses a session that is not an eval session. */
153
+ deleteEvalSessions(projectRoot: string, sessionIds: string[]): Promise<string[]>;
154
+ /**
155
+ * Boot cleanup of eval sessions: those of the given (recovered) eval runs, and older root sessions no eval result
156
+ * references. Returns how many sessions were deleted, descendants included.
157
+ */
158
+ sweepEvalSessions(input: {
159
+ runIds: string[];
160
+ olderThanMs: number;
161
+ isReferenced: (sessionId: string) => Promise<boolean> | boolean;
162
+ }): Promise<number>;
163
+ /** Forget a finished eval session's in-memory overrides. The rows stay readable. */
164
+ forgetEvalSession(sessionId: string): void;
143
165
  private warningsFor;
144
166
  /**
145
167
  * Web chat defaults and links: a new agent starts with web chat on, an enabled block without a link
@@ -182,10 +204,11 @@ export declare class AgentService {
182
204
  sourceRef?: string | null;
183
205
  threadKey?: string | null;
184
206
  title?: string | null;
207
+ eval?: EvalSessionOverrides;
185
208
  }): Promise<AgentSession>;
186
209
  /** Id of the session's pending approval, if a turn is waiting on a person. */
187
210
  pendingApprovalFor(_projectRoot: string, sessionId: string): string | null;
188
- listSessionsForRef(projectRoot: string, agentId: string, source: string, sourceRef: string, limit: number): AgentSession[];
211
+ listSessionsForRef(projectRoot: string, agentId: string, source: string, sourceRef: string, limit: number, includeEval?: boolean): AgentSession[];
189
212
  private sessionInProject;
190
213
  getSession(projectRoot: string, sessionId: string): Promise<AgentSessionDetail>;
191
214
  listSessions(projectRoot: string, agentId: string, query: SessionQuery): Promise<{
@@ -274,7 +297,9 @@ export declare class AgentService {
274
297
  turnId?: string | null;
275
298
  }): Promise<AgentApproval>;
276
299
  decideApproval(projectRoot: string, sessionId: string, decision: "approve" | "deny", actor: ApprovalActor): Promise<AgentApproval>;
277
- pendingApprovals(projectRoot: string): Promise<Array<AgentApproval & {
300
+ pendingApprovals(projectRoot: string, options?: {
301
+ includeEval?: boolean;
302
+ }): Promise<Array<AgentApproval & {
278
303
  agentId: string;
279
304
  }>>;
280
305
  receive(projectRoot: string, message: AgentInboundMessage): Promise<{
@@ -11,6 +11,7 @@ import { ApprovalBroker } from "./approvalBroker.js";
11
11
  import { deliveryLedger, scheduleLedger } from "./ledgers.js";
12
12
  import { TurnLifecycle } from "./turnLifecycle.js";
13
13
  import { AgentError } from "./errors.js";
14
+ import { applyEvalOverrides, EVAL_SESSION_SOURCE, isEvalSession } from "./evalSession.js";
14
15
  import { agentMemoryIssues } from "../memory/agentIssues.js";
15
16
  import { diffLines } from "./lineDiff.js";
16
17
  import { exportTurnsToOtlp } from "./otlpExport.js";
@@ -38,6 +39,8 @@ export class AgentService {
38
39
  environment;
39
40
  now;
40
41
  tails = new Map();
42
+ /** Overrides of open eval sessions. Memory only: eval sessions do not survive a Host restart. */
43
+ evalOverrides = new Map();
41
44
  /** Wakes a turn paused at an ask-first tool when its approval is decided. */
42
45
  approvalBroker = new ApprovalBroker();
43
46
  /** Owns every legal change of a turn, its session and its approval. */
@@ -311,6 +314,64 @@ export class AgentService {
311
314
  throw new AgentError("agent.revision_not_found");
312
315
  return found.definition;
313
316
  }
317
+ /** The pinned definition, with an eval session's overrides applied. Real sessions get it unchanged. */
318
+ async effectiveDefinition(projectRoot, session) {
319
+ const base = await this.definitionAt(projectRoot, session.agentId, session.revision);
320
+ return isEvalSession(session) ? applyEvalOverrides(base, this.evalOverrides.get(session.id) ?? {}) : base;
321
+ }
322
+ /** The overrides an eval session was opened with (sub-agent sessions inherit them), or undefined for a real session. */
323
+ evalOverridesOf(sessionId) {
324
+ return this.evalOverrides.get(sessionId);
325
+ }
326
+ /** Every eval session below this one (sub-agents and theirs). */
327
+ listChildSessions(sessionId) {
328
+ return this.store.listChildSessions(sessionId);
329
+ }
330
+ /** Delete eval sessions and everything below them. Refuses a session that is not an eval session. */
331
+ async deleteEvalSessions(projectRoot, sessionIds) {
332
+ const roots = sessionIds.map((sessionId) => this.sessionInProject(projectRoot, sessionId));
333
+ const refused = roots.find((session) => !isEvalSession(session));
334
+ if (refused)
335
+ throw new AgentError("agent.invalid", `Session ${refused.id} is not an eval session`);
336
+ const all = new Set(roots.map((session) => session.id));
337
+ for (const root of roots)
338
+ for (const child of this.store.listChildSessions(root.id))
339
+ all.add(child.id);
340
+ const ids = [...all];
341
+ this.store.deleteSessions(ids);
342
+ for (const sessionId of ids)
343
+ this.evalOverrides.delete(sessionId);
344
+ return ids;
345
+ }
346
+ /**
347
+ * Boot cleanup of eval sessions: those of the given (recovered) eval runs, and older root sessions no eval result
348
+ * references. Returns how many sessions were deleted, descendants included.
349
+ */
350
+ async sweepEvalSessions(input) {
351
+ const roots = new Map();
352
+ for (const session of this.store.listEvalRootSessions({ sourceRefs: input.runIds }))
353
+ roots.set(session.id, session);
354
+ const cutoff = new Date(this.clockMs() - input.olderThanMs).toISOString();
355
+ for (const session of this.store.listEvalRootSessions({ createdBefore: cutoff })) {
356
+ if (!roots.has(session.id) && !(await input.isReferenced(session.id)))
357
+ roots.set(session.id, session);
358
+ }
359
+ const all = new Set();
360
+ for (const root of roots.values()) {
361
+ all.add(root.id);
362
+ for (const child of this.store.listChildSessions(root.id))
363
+ all.add(child.id);
364
+ }
365
+ const ids = [...all];
366
+ this.store.deleteSessions(ids);
367
+ for (const sessionId of ids)
368
+ this.evalOverrides.delete(sessionId);
369
+ return ids.length;
370
+ }
371
+ /** Forget a finished eval session's in-memory overrides. The rows stay readable. */
372
+ forgetEvalSession(sessionId) {
373
+ this.evalOverrides.delete(sessionId);
374
+ }
314
375
  /* ---------- validation ---------- */
315
376
  async warningsFor(projectRoot, definition) {
316
377
  const warnings = [];
@@ -515,8 +576,9 @@ export class AgentService {
515
576
  return false;
516
577
  throw error;
517
578
  });
518
- if (onDisk || (existing && !existing.archived))
519
- throw new AgentError("agent.exists");
579
+ if (onDisk || (existing && !existing.archived)) {
580
+ throw new AgentError("agent.exists", `An agent with id "${definition.id}" already exists`);
581
+ }
520
582
  // A new agent always starts disabled (R1); enabling is its own revision.
521
583
  await this.writeRevision(projectRoot, { ...definition, enabled: false }, actor, "Created");
522
584
  });
@@ -636,10 +698,20 @@ export class AgentService {
636
698
  }
637
699
  /* ---------- sessions ---------- */
638
700
  async openSession(projectRoot, agentId, input) {
701
+ if (input.eval && input.source !== EVAL_SESSION_SOURCE)
702
+ throw new AgentError("agent.invalid", "Eval overrides need an eval session");
639
703
  return this.exclusive(projectRoot, async () => {
640
704
  await this.sync(projectRoot);
641
- const { revision } = this.currentRevision(projectRoot, agentId);
642
- if (!revision.definition.enabled)
705
+ const isEval = input.source === EVAL_SESSION_SOURCE;
706
+ const { revision: current } = this.currentRevision(projectRoot, agentId);
707
+ let revision = current;
708
+ if (input.eval?.revision !== undefined && input.eval.revision !== current.revision) {
709
+ const pinned = this.store.getRevision(agentProjectKey(projectRoot), agentId, input.eval.revision);
710
+ if (!pinned)
711
+ throw new AgentError("agent.revision_not_found");
712
+ revision = pinned;
713
+ }
714
+ if (!isEval && !revision.definition.enabled)
643
715
  throw new AgentError("agent.disabled");
644
716
  const now = this.iso();
645
717
  const session = {
@@ -656,6 +728,8 @@ export class AgentService {
656
728
  updatedAt: now,
657
729
  };
658
730
  this.store.insertSession(agentProjectKey(projectRoot), session);
731
+ if (isEval)
732
+ this.evalOverrides.set(session.id, input.eval ?? {});
659
733
  return session;
660
734
  });
661
735
  }
@@ -663,8 +737,8 @@ export class AgentService {
663
737
  pendingApprovalFor(_projectRoot, sessionId) {
664
738
  return this.store.listApprovals(sessionId).find((approval) => approval.status === "pending")?.id ?? null;
665
739
  }
666
- listSessionsForRef(projectRoot, agentId, source, sourceRef, limit) {
667
- return this.store.listSessionsForRef(agentProjectKey(projectRoot), agentId, source, sourceRef, limit);
740
+ listSessionsForRef(projectRoot, agentId, source, sourceRef, limit, includeEval) {
741
+ return this.store.listSessionsForRef(agentProjectKey(projectRoot), agentId, source, sourceRef, limit, includeEval);
668
742
  }
669
743
  sessionInProject(projectRoot, sessionId) {
670
744
  const session = this.store.getSession(sessionId);
@@ -698,7 +772,7 @@ export class AgentService {
698
772
  const since = new Date(this.now().getTime() - RECENT_WINDOW_MS).toISOString();
699
773
  return {
700
774
  ...this.store.listSessions(projectKey, agentId, query),
701
- stats: this.store.sessionStats(projectKey, agentId, since),
775
+ stats: this.store.sessionStats(projectKey, agentId, since, query.includeEval),
702
776
  };
703
777
  });
704
778
  }
@@ -711,7 +785,7 @@ export class AgentService {
711
785
  const since = new Date(this.now().getTime() - RECENT_WINDOW_MS).toISOString();
712
786
  return {
713
787
  ...this.store.listSessions(projectKey, agentId, query),
714
- stats: this.store.sessionStats(projectKey, agentId, since),
788
+ stats: this.store.sessionStats(projectKey, agentId, since, query.includeEval),
715
789
  };
716
790
  });
717
791
  }
@@ -745,11 +819,11 @@ export class AgentService {
745
819
  await this.sync(projectRoot);
746
820
  const session = this.sessionInProject(projectRoot, sessionId);
747
821
  const { revision: live } = this.currentRevision(projectRoot, session.agentId);
748
- if (!live.definition.enabled)
822
+ if (!live.definition.enabled && !isEvalSession(session))
749
823
  throw new AgentError("agent.disabled");
750
824
  if (session.status === "running" || session.status === "waiting")
751
825
  throw new AgentError("agent.session_busy");
752
- const definition = await this.definitionAt(projectRoot, session.agentId, session.revision);
826
+ const definition = await this.effectiveDefinition(projectRoot, session);
753
827
  this.assertWithinLimits(definition, session);
754
828
  const now = this.iso();
755
829
  return this.store.transaction(() => {
@@ -930,9 +1004,9 @@ export class AgentService {
930
1004
  this.expireApprovals();
931
1005
  const session = this.sessionInProject(projectRoot, sessionId);
932
1006
  const { revision: live } = this.currentRevision(projectRoot, session.agentId);
933
- if (!live.definition.enabled)
1007
+ if (!live.definition.enabled && !isEvalSession(session))
934
1008
  throw new AgentError("agent.disabled");
935
- const definition = await this.definitionAt(projectRoot, session.agentId, session.revision);
1009
+ const definition = await this.effectiveDefinition(projectRoot, session);
936
1010
  if (!isToolGranted(definition, input.tool))
937
1011
  throw new AgentError("agent.tool_not_granted");
938
1012
  if (!requiresAskFirst(definition, input.tool))
@@ -975,7 +1049,9 @@ export class AgentService {
975
1049
  return this.exclusive(projectRoot, async () => {
976
1050
  await this.sync(projectRoot);
977
1051
  const session = this.sessionInProject(projectRoot, sessionId);
978
- const definition = await this.definitionAt(projectRoot, session.agentId, session.revision);
1052
+ if (isEvalSession(session))
1053
+ throw new AgentError("agent.session_eval_readonly", "Eval sessions are read only");
1054
+ const definition = await this.effectiveDefinition(projectRoot, session);
979
1055
  if (!canApprove(definition, actor))
980
1056
  throw new AgentError("agent.approval_forbidden");
981
1057
  const pending = this.store.getPendingApproval(sessionId);
@@ -997,9 +1073,9 @@ export class AgentService {
997
1073
  return decided.approval;
998
1074
  });
999
1075
  }
1000
- async pendingApprovals(projectRoot) {
1076
+ async pendingApprovals(projectRoot, options = {}) {
1001
1077
  this.expireApprovals();
1002
- return this.store.listPendingApprovals(agentProjectKey(projectRoot));
1078
+ return this.store.listPendingApprovals(agentProjectKey(projectRoot), options.includeEval);
1003
1079
  }
1004
1080
  /* ---------- communications ---------- */
1005
1081
  async receive(projectRoot, message) {
@@ -1,3 +1,5 @@
1
+ import type { EvalGateRegistry } from "./evalGate.js";
2
+ import { type EvalSessionOverrides } from "./evalSession.js";
1
3
  import type { OtlpSink } from "./otlpSink.js";
2
4
  import type { ConversationBackend } from "./runtime/types.js";
3
5
  import type { AgentService, AgentSessionDetail } from "./service.js";
@@ -11,6 +13,10 @@ export type SendTurnInput = {
11
13
  author?: string | null;
12
14
  /** Where a new session came from: console, cli, mcp, schedule, or a provider id. */
13
15
  source?: string;
16
+ /** Where a new session points to; defaults to the author. Eval sessions point at their eval run or parent session. */
17
+ sourceRef?: string | null;
18
+ /** Overrides for a new eval session (needs `source: "eval"`). */
19
+ eval?: EvalSessionOverrides;
14
20
  onDelta?: (text: string) => void;
15
21
  onSessionOpened?: (sessionId: string) => void;
16
22
  /** Retry this earlier, interrupted turn: its user message is reused, not asked again. */
@@ -20,6 +26,8 @@ export type ConversationOptions = {
20
26
  service: AgentService;
21
27
  backend: ConversationBackend;
22
28
  otlpSink?: OtlpSink | undefined;
29
+ /** Eval tool gates by session id. An eval session without one is denied every tool. */
30
+ evalGates?: EvalGateRegistry;
23
31
  logError?: (message: string) => void;
24
32
  };
25
33
  /** One turn: open (if needed) → record user message → model + tools → guardrails → record reply. */