patchwork-os 0.2.0-beta.1 → 0.2.0-beta.10.canary.95

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 (652) hide show
  1. package/README.bridge.md +14 -14
  2. package/README.md +201 -34
  3. package/deploy/README.md +1 -1
  4. package/deploy/bootstrap-vps.sh +14 -9
  5. package/deploy/deploy-dashboard.sh +25 -1
  6. package/deploy/macos/README.md +153 -0
  7. package/deploy/macos/com.patchwork.bridge.plist.template +54 -0
  8. package/deploy/macos/com.patchwork.tunnel.plist.template +76 -0
  9. package/deploy/macos/install-mac-bridge.sh +244 -0
  10. package/deploy/macos/uninstall-mac-bridge.sh +22 -0
  11. package/dist/activityLog.d.ts +6 -0
  12. package/dist/activityLog.js +63 -26
  13. package/dist/activityLog.js.map +1 -1
  14. package/dist/adapters/claude.js +22 -16
  15. package/dist/adapters/claude.js.map +1 -1
  16. package/dist/adapters/gemini.js +15 -11
  17. package/dist/adapters/gemini.js.map +1 -1
  18. package/dist/adapters/openai.js +9 -9
  19. package/dist/adapters/openai.js.map +1 -1
  20. package/dist/ajv2020.d.ts +25 -0
  21. package/dist/ajv2020.js +33 -0
  22. package/dist/ajv2020.js.map +1 -0
  23. package/dist/analyticsAggregator.js +1 -1
  24. package/dist/analyticsAggregator.js.map +1 -1
  25. package/dist/analyticsConfig.d.ts +29 -0
  26. package/dist/analyticsConfig.js +102 -0
  27. package/dist/analyticsConfig.js.map +1 -0
  28. package/dist/analyticsPrefs.d.ts +38 -2
  29. package/dist/analyticsPrefs.js +148 -23
  30. package/dist/analyticsPrefs.js.map +1 -1
  31. package/dist/analyticsSend.d.ts +17 -1
  32. package/dist/analyticsSend.js +67 -5
  33. package/dist/analyticsSend.js.map +1 -1
  34. package/dist/approvalHttp.d.ts +14 -0
  35. package/dist/approvalHttp.js +212 -9
  36. package/dist/approvalHttp.js.map +1 -1
  37. package/dist/approvalInsights.js +13 -5
  38. package/dist/approvalInsights.js.map +1 -1
  39. package/dist/approvalQueue.d.ts +97 -3
  40. package/dist/approvalQueue.js +193 -19
  41. package/dist/approvalQueue.js.map +1 -1
  42. package/dist/approvalSignals.js +19 -11
  43. package/dist/approvalSignals.js.map +1 -1
  44. package/dist/automation.d.ts +35 -10
  45. package/dist/automation.js +133 -37
  46. package/dist/automation.js.map +1 -1
  47. package/dist/automationSuggestions.js +10 -8
  48. package/dist/automationSuggestions.js.map +1 -1
  49. package/dist/bridge.d.ts +2 -0
  50. package/dist/bridge.js +202 -25
  51. package/dist/bridge.js.map +1 -1
  52. package/dist/bridgeLockDiscovery.d.ts +27 -1
  53. package/dist/bridgeLockDiscovery.js +38 -11
  54. package/dist/bridgeLockDiscovery.js.map +1 -1
  55. package/dist/bridgeToken.js +3 -2
  56. package/dist/bridgeToken.js.map +1 -1
  57. package/dist/claudeDriver.js +23 -8
  58. package/dist/claudeDriver.js.map +1 -1
  59. package/dist/claudeOrchestrator.d.ts +1 -1
  60. package/dist/claudeOrchestrator.js +87 -44
  61. package/dist/claudeOrchestrator.js.map +1 -1
  62. package/dist/commands/analytics.d.ts +8 -0
  63. package/dist/commands/analytics.js +134 -0
  64. package/dist/commands/analytics.js.map +1 -0
  65. package/dist/commands/auditEnv.d.ts +36 -0
  66. package/dist/commands/auditEnv.js +202 -0
  67. package/dist/commands/auditEnv.js.map +1 -0
  68. package/dist/commands/dashboard.js +8 -1
  69. package/dist/commands/dashboard.js.map +1 -1
  70. package/dist/commands/doctor.d.ts +35 -0
  71. package/dist/commands/doctor.js +51 -0
  72. package/dist/commands/doctor.js.map +1 -0
  73. package/dist/commands/install.js +3 -0
  74. package/dist/commands/install.js.map +1 -1
  75. package/dist/commands/launchd.js +15 -16
  76. package/dist/commands/launchd.js.map +1 -1
  77. package/dist/commands/patchworkInit.d.ts +5 -0
  78. package/dist/commands/patchworkInit.js +89 -7
  79. package/dist/commands/patchworkInit.js.map +1 -1
  80. package/dist/commands/recipe.d.ts +110 -0
  81. package/dist/commands/recipe.js +512 -9
  82. package/dist/commands/recipe.js.map +1 -1
  83. package/dist/commands/recipeInstall.js +11 -4
  84. package/dist/commands/recipeInstall.js.map +1 -1
  85. package/dist/commands/shadowScan.d.ts +34 -0
  86. package/dist/commands/shadowScan.js +142 -0
  87. package/dist/commands/shadowScan.js.map +1 -0
  88. package/dist/commands/task.js +2 -2
  89. package/dist/commands/task.js.map +1 -1
  90. package/dist/commands/tools.d.ts +20 -1
  91. package/dist/commands/tools.js +112 -3
  92. package/dist/commands/tools.js.map +1 -1
  93. package/dist/commands/tracesImport.js +21 -4
  94. package/dist/commands/tracesImport.js.map +1 -1
  95. package/dist/commitIssueLinkLog.d.ts +16 -0
  96. package/dist/commitIssueLinkLog.js +110 -24
  97. package/dist/commitIssueLinkLog.js.map +1 -1
  98. package/dist/companions/registry.js +15 -7
  99. package/dist/companions/registry.js.map +1 -1
  100. package/dist/config.d.ts +47 -3
  101. package/dist/config.js +111 -21
  102. package/dist/config.js.map +1 -1
  103. package/dist/connectorRoutes.js +866 -57
  104. package/dist/connectorRoutes.js.map +1 -1
  105. package/dist/connectors/airtable.d.ts +230 -0
  106. package/dist/connectors/airtable.js +700 -0
  107. package/dist/connectors/airtable.js.map +1 -0
  108. package/dist/connectors/asana.js +13 -9
  109. package/dist/connectors/asana.js.map +1 -1
  110. package/dist/connectors/baseConnector.js +25 -3
  111. package/dist/connectors/baseConnector.js.map +1 -1
  112. package/dist/connectors/caldiy.d.ts +137 -0
  113. package/dist/connectors/caldiy.js +424 -0
  114. package/dist/connectors/caldiy.js.map +1 -0
  115. package/dist/connectors/circleci.d.ts +162 -0
  116. package/dist/connectors/circleci.js +576 -0
  117. package/dist/connectors/circleci.js.map +1 -0
  118. package/dist/connectors/cloudflare.d.ts +132 -0
  119. package/dist/connectors/cloudflare.js +622 -0
  120. package/dist/connectors/cloudflare.js.map +1 -0
  121. package/dist/connectors/confluence.js +35 -0
  122. package/dist/connectors/confluence.js.map +1 -1
  123. package/dist/connectors/connectorRedirectUri.d.ts +30 -0
  124. package/dist/connectors/connectorRedirectUri.js +38 -0
  125. package/dist/connectors/connectorRedirectUri.js.map +1 -0
  126. package/dist/connectors/connectorRegistry.d.ts +63 -0
  127. package/dist/connectors/connectorRegistry.js +354 -0
  128. package/dist/connectors/connectorRegistry.js.map +1 -0
  129. package/dist/connectors/datadog.js +33 -4
  130. package/dist/connectors/datadog.js.map +1 -1
  131. package/dist/connectors/discord.js +14 -10
  132. package/dist/connectors/discord.js.map +1 -1
  133. package/dist/connectors/elasticsearch.d.ts +141 -0
  134. package/dist/connectors/elasticsearch.js +601 -0
  135. package/dist/connectors/elasticsearch.js.map +1 -0
  136. package/dist/connectors/figma.d.ts +130 -0
  137. package/dist/connectors/figma.js +387 -0
  138. package/dist/connectors/figma.js.map +1 -0
  139. package/dist/connectors/github.d.ts +17 -0
  140. package/dist/connectors/github.js +53 -2
  141. package/dist/connectors/github.js.map +1 -1
  142. package/dist/connectors/gitlab.js +12 -6
  143. package/dist/connectors/gitlab.js.map +1 -1
  144. package/dist/connectors/gmail.js +72 -21
  145. package/dist/connectors/gmail.js.map +1 -1
  146. package/dist/connectors/googleCalendar.js +8 -8
  147. package/dist/connectors/googleCalendar.js.map +1 -1
  148. package/dist/connectors/googleDocs.d.ts +103 -0
  149. package/dist/connectors/googleDocs.js +409 -0
  150. package/dist/connectors/googleDocs.js.map +1 -0
  151. package/dist/connectors/googleDrive.d.ts +12 -0
  152. package/dist/connectors/googleDrive.js +35 -8
  153. package/dist/connectors/googleDrive.js.map +1 -1
  154. package/dist/connectors/grafana.d.ts +133 -0
  155. package/dist/connectors/grafana.js +478 -0
  156. package/dist/connectors/grafana.js.map +1 -0
  157. package/dist/connectors/jira.d.ts +25 -0
  158. package/dist/connectors/jira.js +227 -1
  159. package/dist/connectors/jira.js.map +1 -1
  160. package/dist/connectors/linear.js +1 -1
  161. package/dist/connectors/linear.js.map +1 -1
  162. package/dist/connectors/mcpOAuth.js +78 -16
  163. package/dist/connectors/mcpOAuth.js.map +1 -1
  164. package/dist/connectors/monday.d.ts +217 -0
  165. package/dist/connectors/monday.js +655 -0
  166. package/dist/connectors/monday.js.map +1 -0
  167. package/dist/connectors/mongodb.d.ts +139 -0
  168. package/dist/connectors/mongodb.js +455 -0
  169. package/dist/connectors/mongodb.js.map +1 -0
  170. package/dist/connectors/oauthStateStore.d.ts +20 -0
  171. package/dist/connectors/oauthStateStore.js +94 -4
  172. package/dist/connectors/oauthStateStore.js.map +1 -1
  173. package/dist/connectors/obsidian.d.ts +83 -0
  174. package/dist/connectors/obsidian.js +441 -0
  175. package/dist/connectors/obsidian.js.map +1 -0
  176. package/dist/connectors/paystack.d.ts +159 -0
  177. package/dist/connectors/paystack.js +607 -0
  178. package/dist/connectors/paystack.js.map +1 -0
  179. package/dist/connectors/pipedrive.d.ts +189 -0
  180. package/dist/connectors/pipedrive.js +559 -0
  181. package/dist/connectors/pipedrive.js.map +1 -0
  182. package/dist/connectors/postgres.d.ts +127 -0
  183. package/dist/connectors/postgres.js +512 -0
  184. package/dist/connectors/postgres.js.map +1 -0
  185. package/dist/connectors/posthog.d.ts +119 -0
  186. package/dist/connectors/posthog.js +479 -0
  187. package/dist/connectors/posthog.js.map +1 -0
  188. package/dist/connectors/redis.d.ts +140 -0
  189. package/dist/connectors/redis.js +571 -0
  190. package/dist/connectors/redis.js.map +1 -0
  191. package/dist/connectors/resend.d.ts +131 -0
  192. package/dist/connectors/resend.js +529 -0
  193. package/dist/connectors/resend.js.map +1 -0
  194. package/dist/connectors/salesforce.d.ts +136 -0
  195. package/dist/connectors/salesforce.js +603 -0
  196. package/dist/connectors/salesforce.js.map +1 -0
  197. package/dist/connectors/secrets.d.ts +51 -0
  198. package/dist/connectors/secrets.js +102 -0
  199. package/dist/connectors/secrets.js.map +1 -0
  200. package/dist/connectors/sendgrid.d.ts +102 -0
  201. package/dist/connectors/sendgrid.js +423 -0
  202. package/dist/connectors/sendgrid.js.map +1 -0
  203. package/dist/connectors/shopify.d.ts +145 -0
  204. package/dist/connectors/shopify.js +502 -0
  205. package/dist/connectors/shopify.js.map +1 -0
  206. package/dist/connectors/slack.d.ts +1 -1
  207. package/dist/connectors/slack.js +61 -9
  208. package/dist/connectors/slack.js.map +1 -1
  209. package/dist/connectors/snowflake.d.ts +119 -0
  210. package/dist/connectors/snowflake.js +615 -0
  211. package/dist/connectors/snowflake.js.map +1 -0
  212. package/dist/connectors/supabase.d.ts +92 -0
  213. package/dist/connectors/supabase.js +630 -0
  214. package/dist/connectors/supabase.js.map +1 -0
  215. package/dist/connectors/todoist.d.ts +117 -0
  216. package/dist/connectors/todoist.js +485 -0
  217. package/dist/connectors/todoist.js.map +1 -0
  218. package/dist/connectors/tokenStorage.js +56 -14
  219. package/dist/connectors/tokenStorage.js.map +1 -1
  220. package/dist/connectors/twilio.d.ts +118 -0
  221. package/dist/connectors/twilio.js +475 -0
  222. package/dist/connectors/twilio.js.map +1 -0
  223. package/dist/connectors/vercel.d.ts +110 -0
  224. package/dist/connectors/vercel.js +479 -0
  225. package/dist/connectors/vercel.js.map +1 -0
  226. package/dist/connectors/webflow.d.ts +118 -0
  227. package/dist/connectors/webflow.js +393 -0
  228. package/dist/connectors/webflow.js.map +1 -0
  229. package/dist/connectors/woocommerce.d.ts +220 -0
  230. package/dist/connectors/woocommerce.js +464 -0
  231. package/dist/connectors/woocommerce.js.map +1 -0
  232. package/dist/crypto.js +7 -2
  233. package/dist/crypto.js.map +1 -1
  234. package/dist/decisionReplay.js +15 -6
  235. package/dist/decisionReplay.js.map +1 -1
  236. package/dist/decisionTraceLog.d.ts +28 -0
  237. package/dist/decisionTraceLog.js +156 -29
  238. package/dist/decisionTraceLog.js.map +1 -1
  239. package/dist/drivers/claude/api.js +5 -4
  240. package/dist/drivers/claude/api.js.map +1 -1
  241. package/dist/drivers/claude/envSanitizer.d.ts +0 -6
  242. package/dist/drivers/claude/envSanitizer.js +17 -2
  243. package/dist/drivers/claude/envSanitizer.js.map +1 -1
  244. package/dist/drivers/claude/streamParser.js +5 -4
  245. package/dist/drivers/claude/streamParser.js.map +1 -1
  246. package/dist/drivers/claude/subprocess.js +22 -3
  247. package/dist/drivers/claude/subprocess.js.map +1 -1
  248. package/dist/drivers/gemini/index.d.ts +22 -0
  249. package/dist/drivers/gemini/index.js +256 -129
  250. package/dist/drivers/gemini/index.js.map +1 -1
  251. package/dist/drivers/local/index.d.ts +17 -0
  252. package/dist/drivers/local/index.js +99 -0
  253. package/dist/drivers/local/index.js.map +1 -1
  254. package/dist/drivers/openai/index.js +30 -2
  255. package/dist/drivers/openai/index.js.map +1 -1
  256. package/dist/extensionClient.d.ts +37 -4
  257. package/dist/extensionClient.js +58 -16
  258. package/dist/extensionClient.js.map +1 -1
  259. package/dist/featureFlags.d.ts +91 -0
  260. package/dist/featureFlags.js +174 -3
  261. package/dist/featureFlags.js.map +1 -1
  262. package/dist/fileLock.js +21 -12
  263. package/dist/fileLock.js.map +1 -1
  264. package/dist/fileLockSync.d.ts +67 -0
  265. package/dist/fileLockSync.js +126 -0
  266. package/dist/fileLockSync.js.map +1 -0
  267. package/dist/fp/activityAnalytics.js +26 -12
  268. package/dist/fp/activityAnalytics.js.map +1 -1
  269. package/dist/fp/automationInterpreter.d.ts +15 -1
  270. package/dist/fp/automationInterpreter.js +217 -82
  271. package/dist/fp/automationInterpreter.js.map +1 -1
  272. package/dist/fp/automationProgram.d.ts +30 -0
  273. package/dist/fp/automationProgram.js.map +1 -1
  274. package/dist/fp/automationState.d.ts +24 -5
  275. package/dist/fp/automationState.js +56 -9
  276. package/dist/fp/automationState.js.map +1 -1
  277. package/dist/fp/automationUtils.js +1 -1
  278. package/dist/fp/automationUtils.js.map +1 -1
  279. package/dist/fp/commandDescription.js +7 -1
  280. package/dist/fp/commandDescription.js.map +1 -1
  281. package/dist/fp/extensionSnapshot.js +8 -2
  282. package/dist/fp/extensionSnapshot.js.map +1 -1
  283. package/dist/fp/interpreterContext.d.ts +66 -1
  284. package/dist/fp/interpreterContext.js +91 -1
  285. package/dist/fp/interpreterContext.js.map +1 -1
  286. package/dist/fp/policyParser.js +29 -1
  287. package/dist/fp/policyParser.js.map +1 -1
  288. package/dist/fsWatchWithFallback.d.ts +36 -0
  289. package/dist/fsWatchWithFallback.js +128 -0
  290. package/dist/fsWatchWithFallback.js.map +1 -0
  291. package/dist/haltPushDispatch.d.ts +33 -0
  292. package/dist/haltPushDispatch.js +103 -0
  293. package/dist/haltPushDispatch.js.map +1 -0
  294. package/dist/httpBodyValidation.d.ts +41 -0
  295. package/dist/httpBodyValidation.js +45 -0
  296. package/dist/httpBodyValidation.js.map +1 -0
  297. package/dist/inboxRoutes.d.ts +22 -0
  298. package/dist/inboxRoutes.js +61 -1
  299. package/dist/inboxRoutes.js.map +1 -1
  300. package/dist/index.js +1053 -76
  301. package/dist/index.js.map +1 -1
  302. package/dist/installGuard.js +6 -2
  303. package/dist/installGuard.js.map +1 -1
  304. package/dist/lockfile.js +31 -4
  305. package/dist/lockfile.js.map +1 -1
  306. package/dist/oauth.d.ts +9 -0
  307. package/dist/oauth.js +33 -0
  308. package/dist/oauth.js.map +1 -1
  309. package/dist/oauthRoutes.d.ts +1 -1
  310. package/dist/oauthRoutes.js +5 -3
  311. package/dist/oauthRoutes.js.map +1 -1
  312. package/dist/orchestrator/childBridgeRegistry.js +29 -11
  313. package/dist/orchestrator/childBridgeRegistry.js.map +1 -1
  314. package/dist/patchworkConfig.d.ts +44 -1
  315. package/dist/patchworkConfig.js +28 -3
  316. package/dist/patchworkConfig.js.map +1 -1
  317. package/dist/pluginLoader.js +10 -1
  318. package/dist/pluginLoader.js.map +1 -1
  319. package/dist/pluginWatcher.js +12 -14
  320. package/dist/pluginWatcher.js.map +1 -1
  321. package/dist/preToolUseHook.js +3 -2
  322. package/dist/preToolUseHook.js.map +1 -1
  323. package/dist/processTree.d.ts +34 -0
  324. package/dist/processTree.js +105 -0
  325. package/dist/processTree.js.map +1 -0
  326. package/dist/prompts.js +3 -3
  327. package/dist/prompts.js.map +1 -1
  328. package/dist/recipeOrchestration.d.ts +9 -0
  329. package/dist/recipeOrchestration.js +341 -24
  330. package/dist/recipeOrchestration.js.map +1 -1
  331. package/dist/recipeRoutes.d.ts +58 -2
  332. package/dist/recipeRoutes.js +744 -115
  333. package/dist/recipeRoutes.js.map +1 -1
  334. package/dist/recipes/RecipeOrchestrator.d.ts +2 -0
  335. package/dist/recipes/RecipeOrchestrator.js +6 -1
  336. package/dist/recipes/RecipeOrchestrator.js.map +1 -1
  337. package/dist/recipes/agentExecutor.d.ts +25 -5
  338. package/dist/recipes/agentExecutor.js.map +1 -1
  339. package/dist/recipes/chainedRunner.d.ts +2 -0
  340. package/dist/recipes/chainedRunner.js +142 -5
  341. package/dist/recipes/chainedRunner.js.map +1 -1
  342. package/dist/recipes/connectorPreflight.d.ts +66 -0
  343. package/dist/recipes/connectorPreflight.js +169 -0
  344. package/dist/recipes/connectorPreflight.js.map +1 -0
  345. package/dist/recipes/dependencyGraph.js +13 -5
  346. package/dist/recipes/dependencyGraph.js.map +1 -1
  347. package/dist/recipes/githubInstallSource.d.ts +128 -0
  348. package/dist/recipes/githubInstallSource.js +206 -0
  349. package/dist/recipes/githubInstallSource.js.map +1 -0
  350. package/dist/recipes/haltCategory.d.ts +119 -0
  351. package/dist/recipes/haltCategory.js +188 -0
  352. package/dist/recipes/haltCategory.js.map +1 -0
  353. package/dist/recipes/idempotencyKey.d.ts +134 -0
  354. package/dist/recipes/idempotencyKey.js +322 -0
  355. package/dist/recipes/idempotencyKey.js.map +1 -0
  356. package/dist/recipes/installer.js +48 -2
  357. package/dist/recipes/installer.js.map +1 -1
  358. package/dist/recipes/judgeSummary.d.ts +50 -0
  359. package/dist/recipes/judgeSummary.js +47 -0
  360. package/dist/recipes/judgeSummary.js.map +1 -0
  361. package/dist/recipes/judgeVerdict.d.ts +48 -0
  362. package/dist/recipes/judgeVerdict.js +174 -0
  363. package/dist/recipes/judgeVerdict.js.map +1 -0
  364. package/dist/recipes/migrations/index.d.ts +9 -0
  365. package/dist/recipes/migrations/index.js +133 -0
  366. package/dist/recipes/migrations/index.js.map +1 -1
  367. package/dist/recipes/names.d.ts +20 -0
  368. package/dist/recipes/names.js +25 -0
  369. package/dist/recipes/names.js.map +1 -1
  370. package/dist/recipes/parser.js +88 -5
  371. package/dist/recipes/parser.js.map +1 -1
  372. package/dist/recipes/replayRun.js +1 -1
  373. package/dist/recipes/replayRun.js.map +1 -1
  374. package/dist/recipes/runBudget.d.ts +70 -0
  375. package/dist/recipes/runBudget.js +109 -0
  376. package/dist/recipes/runBudget.js.map +1 -0
  377. package/dist/recipes/scheduler.d.ts +30 -0
  378. package/dist/recipes/scheduler.js +69 -19
  379. package/dist/recipes/scheduler.js.map +1 -1
  380. package/dist/recipes/schema.d.ts +36 -0
  381. package/dist/recipes/schemaGenerator.js +103 -5
  382. package/dist/recipes/schemaGenerator.js.map +1 -1
  383. package/dist/recipes/stepObservation.js +9 -0
  384. package/dist/recipes/stepObservation.js.map +1 -1
  385. package/dist/recipes/toolRegistry.js +20 -3
  386. package/dist/recipes/toolRegistry.js.map +1 -1
  387. package/dist/recipes/tools/fanOut.d.ts +20 -0
  388. package/dist/recipes/tools/fanOut.js +199 -0
  389. package/dist/recipes/tools/fanOut.js.map +1 -0
  390. package/dist/recipes/tools/file.js +5 -2
  391. package/dist/recipes/tools/file.js.map +1 -1
  392. package/dist/recipes/tools/github.d.ts +1 -1
  393. package/dist/recipes/tools/github.js +75 -1
  394. package/dist/recipes/tools/github.js.map +1 -1
  395. package/dist/recipes/tools/gmail.js +27 -5
  396. package/dist/recipes/tools/gmail.js.map +1 -1
  397. package/dist/recipes/tools/googleDrive.js +64 -0
  398. package/dist/recipes/tools/googleDrive.js.map +1 -1
  399. package/dist/recipes/tools/http.d.ts +10 -0
  400. package/dist/recipes/tools/http.js +176 -0
  401. package/dist/recipes/tools/http.js.map +1 -0
  402. package/dist/recipes/tools/index.d.ts +2 -0
  403. package/dist/recipes/tools/index.js +2 -0
  404. package/dist/recipes/tools/index.js.map +1 -1
  405. package/dist/recipes/tools/slack.js +1 -1
  406. package/dist/recipes/validation.d.ts +17 -0
  407. package/dist/recipes/validation.js +29 -11
  408. package/dist/recipes/validation.js.map +1 -1
  409. package/dist/recipes/workspaceRoot.d.ts +37 -0
  410. package/dist/recipes/workspaceRoot.js +73 -0
  411. package/dist/recipes/workspaceRoot.js.map +1 -0
  412. package/dist/recipes/yamlPositions.d.ts +56 -0
  413. package/dist/recipes/yamlPositions.js +183 -0
  414. package/dist/recipes/yamlPositions.js.map +1 -0
  415. package/dist/recipes/yamlRunner.d.ts +182 -8
  416. package/dist/recipes/yamlRunner.js +877 -217
  417. package/dist/recipes/yamlRunner.js.map +1 -1
  418. package/dist/recipesHttp.d.ts +19 -3
  419. package/dist/recipesHttp.js +67 -11
  420. package/dist/recipesHttp.js.map +1 -1
  421. package/dist/resources.js +21 -13
  422. package/dist/resources.js.map +1 -1
  423. package/dist/runLog.d.ts +58 -5
  424. package/dist/runLog.js +98 -21
  425. package/dist/runLog.js.map +1 -1
  426. package/dist/sanitizeParsedJson.d.ts +39 -0
  427. package/dist/sanitizeParsedJson.js +55 -0
  428. package/dist/sanitizeParsedJson.js.map +1 -0
  429. package/dist/schemas/recipe.v1.json +885 -196
  430. package/dist/server.d.ts +160 -3
  431. package/dist/server.js +1099 -122
  432. package/dist/server.js.map +1 -1
  433. package/dist/sessionCheckpoint.d.ts +8 -0
  434. package/dist/sessionCheckpoint.js +33 -3
  435. package/dist/sessionCheckpoint.js.map +1 -1
  436. package/dist/ssrfGuard.d.ts +16 -0
  437. package/dist/ssrfGuard.js +87 -4
  438. package/dist/ssrfGuard.js.map +1 -1
  439. package/dist/streamableHttp.d.ts +9 -4
  440. package/dist/streamableHttp.js +76 -20
  441. package/dist/streamableHttp.js.map +1 -1
  442. package/dist/telemetry.js +19 -12
  443. package/dist/telemetry.js.map +1 -1
  444. package/dist/testing/shadowRun.d.ts +52 -0
  445. package/dist/testing/shadowRun.js +71 -0
  446. package/dist/testing/shadowRun.js.map +1 -0
  447. package/dist/tools/batchLsp.d.ts +3 -0
  448. package/dist/tools/bridgeDoctor.d.ts +11 -0
  449. package/dist/tools/bridgeDoctor.js +48 -2
  450. package/dist/tools/bridgeDoctor.js.map +1 -1
  451. package/dist/tools/bridgeStatus.d.ts +0 -12
  452. package/dist/tools/bridgeStatus.js +2 -28
  453. package/dist/tools/bridgeStatus.js.map +1 -1
  454. package/dist/tools/cancelClaudeTask.d.ts +1 -0
  455. package/dist/tools/clipboard.d.ts +2 -0
  456. package/dist/tools/closeTabs.d.ts +1 -0
  457. package/dist/tools/codeLens.d.ts +1 -0
  458. package/dist/tools/createIssueFromAIComment.d.ts +1 -0
  459. package/dist/tools/ctxGetTaskContext.d.ts +9 -0
  460. package/dist/tools/ctxGetTaskContext.js +50 -2
  461. package/dist/tools/ctxGetTaskContext.js.map +1 -1
  462. package/dist/tools/ctxQueryTraces.js +32 -24
  463. package/dist/tools/ctxQueryTraces.js.map +1 -1
  464. package/dist/tools/ctxSaveTrace.d.ts +1 -0
  465. package/dist/tools/debug.d.ts +4 -0
  466. package/dist/tools/decorations.d.ts +2 -0
  467. package/dist/tools/detectUnusedCode.js +9 -7
  468. package/dist/tools/detectUnusedCode.js.map +1 -1
  469. package/dist/tools/documentLinks.d.ts +1 -0
  470. package/dist/tools/editText.d.ts +1 -0
  471. package/dist/tools/editText.js +2 -1
  472. package/dist/tools/editText.js.map +1 -1
  473. package/dist/tools/enrichCommit.d.ts +1 -0
  474. package/dist/tools/enrichStackTrace.js +11 -5
  475. package/dist/tools/enrichStackTrace.js.map +1 -1
  476. package/dist/tools/explainDiagnostic.d.ts +1 -0
  477. package/dist/tools/explainSymbol.d.ts +1 -0
  478. package/dist/tools/fileOperations.d.ts +3 -0
  479. package/dist/tools/fileOperations.js +2 -1
  480. package/dist/tools/fileOperations.js.map +1 -1
  481. package/dist/tools/fileWatcher.d.ts +2 -0
  482. package/dist/tools/fileWatcher.js +8 -2
  483. package/dist/tools/fileWatcher.js.map +1 -1
  484. package/dist/tools/findFiles.d.ts +1 -0
  485. package/dist/tools/fixAllLintErrors.d.ts +1 -0
  486. package/dist/tools/fixAllLintErrors.js +10 -5
  487. package/dist/tools/fixAllLintErrors.js.map +1 -1
  488. package/dist/tools/foldingRanges.d.ts +1 -0
  489. package/dist/tools/formatDocument.d.ts +1 -0
  490. package/dist/tools/formatDocument.js +10 -5
  491. package/dist/tools/formatDocument.js.map +1 -1
  492. package/dist/tools/generateTests.d.ts +1 -0
  493. package/dist/tools/getAIComments.d.ts +1 -0
  494. package/dist/tools/getAnalyticsReport.js +5 -1
  495. package/dist/tools/getAnalyticsReport.js.map +1 -1
  496. package/dist/tools/getBufferContent.d.ts +1 -0
  497. package/dist/tools/getChangeImpact.d.ts +1 -0
  498. package/dist/tools/getChangeImpact.js +23 -14
  499. package/dist/tools/getChangeImpact.js.map +1 -1
  500. package/dist/tools/getClaudeTaskStatus.d.ts +1 -0
  501. package/dist/tools/getCodeCoverage.d.ts +1 -0
  502. package/dist/tools/getCodeCoverage.js +32 -14
  503. package/dist/tools/getCodeCoverage.js.map +1 -1
  504. package/dist/tools/getCommitsForIssue.d.ts +1 -0
  505. package/dist/tools/getDebugState.d.ts +1 -0
  506. package/dist/tools/getDiagnostics.js +32 -29
  507. package/dist/tools/getDiagnostics.js.map +1 -1
  508. package/dist/tools/getDiffFromHandoff.js +8 -2
  509. package/dist/tools/getDiffFromHandoff.js.map +1 -1
  510. package/dist/tools/getDocumentSymbols.d.ts +1 -0
  511. package/dist/tools/getGitHotspots.d.ts +1 -0
  512. package/dist/tools/getImportedSignatures.d.ts +1 -0
  513. package/dist/tools/getImportedSignatures.js +18 -14
  514. package/dist/tools/getImportedSignatures.js.map +1 -1
  515. package/dist/tools/getPRTemplate.d.ts +1 -0
  516. package/dist/tools/getProjectContext.js +23 -10
  517. package/dist/tools/getProjectContext.js.map +1 -1
  518. package/dist/tools/getSymbolHistory.d.ts +1 -0
  519. package/dist/tools/getToolCapabilities.d.ts +10 -5
  520. package/dist/tools/getToolCapabilities.js +79 -202
  521. package/dist/tools/getToolCapabilities.js.map +1 -1
  522. package/dist/tools/getTypeSignature.d.ts +1 -0
  523. package/dist/tools/getWorkspaceSettings.d.ts +1 -0
  524. package/dist/tools/gitWrite.d.ts +11 -0
  525. package/dist/tools/github/actions.d.ts +2 -0
  526. package/dist/tools/github/composite.d.ts +3 -0
  527. package/dist/tools/github/issues.d.ts +4 -0
  528. package/dist/tools/github/pr.d.ts +7 -0
  529. package/dist/tools/handoffNote.d.ts +1 -0
  530. package/dist/tools/handoffNote.js +2 -1
  531. package/dist/tools/handoffNote.js.map +1 -1
  532. package/dist/tools/headless/lspClient.js +3 -0
  533. package/dist/tools/headless/lspClient.js.map +1 -1
  534. package/dist/tools/hoverAtCursor.d.ts +1 -0
  535. package/dist/tools/httpClient.d.ts +2 -0
  536. package/dist/tools/httpClient.js +38 -71
  537. package/dist/tools/httpClient.js.map +1 -1
  538. package/dist/tools/inlayHints.d.ts +1 -0
  539. package/dist/tools/launchQuickTask.d.ts +1 -0
  540. package/dist/tools/listClaudeTasks.d.ts +1 -0
  541. package/dist/tools/listClaudeTasks.js +10 -8
  542. package/dist/tools/listClaudeTasks.js.map +1 -1
  543. package/dist/tools/listTerminals.d.ts +1 -0
  544. package/dist/tools/lsp.d.ts +15 -0
  545. package/dist/tools/lsp.js +17 -0
  546. package/dist/tools/lsp.js.map +1 -1
  547. package/dist/tools/navigateToSymbolByName.d.ts +1 -0
  548. package/dist/tools/openDiff.d.ts +1 -0
  549. package/dist/tools/openDiff.js +4 -1
  550. package/dist/tools/openDiff.js.map +1 -1
  551. package/dist/tools/openFile.d.ts +1 -0
  552. package/dist/tools/openFile.js +4 -1
  553. package/dist/tools/openFile.js.map +1 -1
  554. package/dist/tools/openInBrowser.js +6 -1
  555. package/dist/tools/openInBrowser.js.map +1 -1
  556. package/dist/tools/organizeImports.d.ts +1 -0
  557. package/dist/tools/organizeImports.js +5 -3
  558. package/dist/tools/organizeImports.js.map +1 -1
  559. package/dist/tools/performanceReport.js +5 -3
  560. package/dist/tools/performanceReport.js.map +1 -1
  561. package/dist/tools/planPersistence.d.ts +3 -0
  562. package/dist/tools/planPersistence.js +4 -1
  563. package/dist/tools/planPersistence.js.map +1 -1
  564. package/dist/tools/previewEdit.d.ts +1 -0
  565. package/dist/tools/previewEdit.js +15 -4
  566. package/dist/tools/previewEdit.js.map +1 -1
  567. package/dist/tools/recentTracesDigest.js +54 -11
  568. package/dist/tools/recentTracesDigest.js.map +1 -1
  569. package/dist/tools/refactorAnalyze.d.ts +1 -0
  570. package/dist/tools/refactorExtractFunction.js +4 -1
  571. package/dist/tools/refactorExtractFunction.js.map +1 -1
  572. package/dist/tools/refactorPreview.d.ts +1 -0
  573. package/dist/tools/refactorPreview.js +10 -2
  574. package/dist/tools/refactorPreview.js.map +1 -1
  575. package/dist/tools/replaceBlock.d.ts +1 -0
  576. package/dist/tools/replaceBlock.js +2 -1
  577. package/dist/tools/replaceBlock.js.map +1 -1
  578. package/dist/tools/resumeClaudeTask.d.ts +1 -0
  579. package/dist/tools/runClaudeTask.d.ts +1 -0
  580. package/dist/tools/runTests.js +15 -4
  581. package/dist/tools/runTests.js.map +1 -1
  582. package/dist/tools/screenshot.d.ts +1 -0
  583. package/dist/tools/screenshotAndAnnotate.js +6 -2
  584. package/dist/tools/screenshotAndAnnotate.js.map +1 -1
  585. package/dist/tools/searchAndReplace.d.ts +1 -0
  586. package/dist/tools/searchAndReplace.js +17 -7
  587. package/dist/tools/searchAndReplace.js.map +1 -1
  588. package/dist/tools/searchTools.js +20 -19
  589. package/dist/tools/searchTools.js.map +1 -1
  590. package/dist/tools/searchWorkspace.d.ts +1 -0
  591. package/dist/tools/selectionRanges.d.ts +1 -0
  592. package/dist/tools/semanticTokens.d.ts +1 -0
  593. package/dist/tools/signatureHelp.d.ts +1 -0
  594. package/dist/tools/spawnWorkspace.js +15 -7
  595. package/dist/tools/spawnWorkspace.js.map +1 -1
  596. package/dist/tools/terminal.d.ts +6 -0
  597. package/dist/tools/testRunners/pytest.js +6 -2
  598. package/dist/tools/testRunners/pytest.js.map +1 -1
  599. package/dist/tools/testRunners/vitestJest.js +3 -1
  600. package/dist/tools/testRunners/vitestJest.js.map +1 -1
  601. package/dist/tools/testTraceToSource.d.ts +1 -0
  602. package/dist/tools/transaction.d.ts +4 -0
  603. package/dist/tools/transaction.js +4 -1
  604. package/dist/tools/transaction.js.map +1 -1
  605. package/dist/tools/typeHierarchy.d.ts +1 -0
  606. package/dist/tools/utils.d.ts +18 -0
  607. package/dist/tools/utils.js +103 -18
  608. package/dist/tools/utils.js.map +1 -1
  609. package/dist/tools/vscodeCommands.d.ts +2 -0
  610. package/dist/tools/vscodeTasks.d.ts +2 -0
  611. package/dist/tools/workspaceSettings.d.ts +1 -0
  612. package/dist/transport.d.ts +3 -1
  613. package/dist/transport.js +103 -52
  614. package/dist/transport.js.map +1 -1
  615. package/dist/winShim.d.ts +34 -0
  616. package/dist/winShim.js +94 -0
  617. package/dist/winShim.js.map +1 -0
  618. package/dist/wireHaltPushDispatch.d.ts +38 -0
  619. package/dist/wireHaltPushDispatch.js +71 -0
  620. package/dist/wireHaltPushDispatch.js.map +1 -0
  621. package/dist/writeFileAtomic.d.ts +23 -0
  622. package/dist/writeFileAtomic.js +121 -0
  623. package/dist/writeFileAtomic.js.map +1 -0
  624. package/package.json +23 -7
  625. package/scripts/postinstall.mjs +42 -2
  626. package/scripts/smoke/run-all.mjs +213 -0
  627. package/scripts/start-all.mjs +572 -0
  628. package/scripts/start-all.ps1 +209 -0
  629. package/scripts/start-all.sh +73 -17
  630. package/scripts/start-orchestrator.ps1 +158 -0
  631. package/scripts/start-remote.mjs +122 -0
  632. package/templates/automation-policies/recipe-authoring.json +1 -1
  633. package/templates/automation-policies/security-first.json +1 -1
  634. package/templates/automation-policies/strict-lint.json +1 -1
  635. package/templates/automation-policies/test-driven.json +1 -1
  636. package/templates/automation-policy.example.json +1 -1
  637. package/templates/co.patchwork-os.bridge.plist +2 -2
  638. package/templates/recipes/approval-queue-ui-test.yaml +1 -1
  639. package/templates/recipes/ctx-loop-test.yaml +1 -1
  640. package/templates/recipes/fix-errors-on-save.yaml +71 -0
  641. package/templates/recipes/morning-brief.yaml +5 -2
  642. package/templates/recipes/project-health-check.yaml +4 -1
  643. package/templates/recipes/sentry-to-linear.yaml +72 -38
  644. package/templates/recipes/webhook/apple-watch-health-log.yaml +145 -0
  645. package/templates/recipes/webhook/customer-escalation.yaml +8 -9
  646. package/templates/recipes/webhook/meeting-prep.yaml +11 -5
  647. package/dist/commands/marketplace.d.ts +0 -16
  648. package/dist/commands/marketplace.js +0 -32
  649. package/dist/commands/marketplace.js.map +0 -1
  650. package/dist/recipes/legacyRecipeCompat.d.ts +0 -10
  651. package/dist/recipes/legacyRecipeCompat.js +0 -131
  652. package/dist/recipes/legacyRecipeCompat.js.map +0 -1
@@ -0,0 +1,206 @@
1
+ /**
2
+ * Parses + allowlists the `github:<owner>/<repo>/(recipes|bundles)/<name>`
3
+ * source format used by `POST /recipes/install`.
4
+ *
5
+ * Before this module existed, the install handler hard-coded
6
+ * `github:patchworkos/recipes/...` everywhere — every URL, every
7
+ * prefix match. Third-party orgs / forks / private mirrors could not
8
+ * host recipe catalogs even though the rest of the install pipeline
9
+ * (SSRF guard, parser, scheduler) is org-agnostic.
10
+ *
11
+ * Allowlist policy:
12
+ * - Always includes `patchworkos/recipes` (backward compat).
13
+ * - Operator opts in additional `<owner>/<repo>` entries via the
14
+ * `PATCHWORK_RECIPE_REPO_ALLOWLIST` env var (comma-separated).
15
+ * - Allowlist matching is case-insensitive (GitHub itself is).
16
+ * - Both owner and repo segments must match the strict regex
17
+ * `[a-z0-9_.-]{1,100}` AFTER lowercasing — guards against
18
+ * traversal segments smuggled into the source string.
19
+ *
20
+ * The default-only behaviour matches the audit recommendation: real
21
+ * multi-org support is opt-in, so existing single-org deployments
22
+ * don't see a behaviour change.
23
+ */
24
+ const DEFAULT_ALLOWLIST = ["patchworkos/recipes"];
25
+ export const SEGMENT_RE = /^(?!.*\.\.)[a-z0-9_.-]{1,100}$/;
26
+ /**
27
+ * Read the runtime allowlist. Combines the always-on default with
28
+ * whatever the operator has set in PATCHWORK_RECIPE_REPO_ALLOWLIST.
29
+ * Entries are lowercased + de-duplicated; trailing whitespace, empty
30
+ * fragments, and shapes that don't look like `owner/repo` are
31
+ * silently dropped (logging here is the install handler's job, not
32
+ * this pure helper's).
33
+ */
34
+ export function loadAllowlist(env = process.env) {
35
+ const fromEnv = (env.PATCHWORK_RECIPE_REPO_ALLOWLIST ?? "")
36
+ .split(",")
37
+ .map((s) => s.trim().toLowerCase())
38
+ .filter((s) => s.length > 0 && s.includes("/"));
39
+ return Array.from(new Set([...DEFAULT_ALLOWLIST, ...fromEnv]));
40
+ }
41
+ /**
42
+ * Parse a `github:owner/repo/(recipes|bundles)/name` source string
43
+ * against the active allowlist. Pure — does NOT fetch anything; the
44
+ * install handler is responsible for the network leg and the SSRF
45
+ * guard. Returns a discriminated union the caller can map to a 400
46
+ * (bad_shape / bad_segment) or 403 (not_allowlisted) response.
47
+ */
48
+ export function parseGithubInstallSource(source, allowlist = loadAllowlist()) {
49
+ if (!source.startsWith("github:")) {
50
+ return {
51
+ ok: false,
52
+ code: "bad_shape",
53
+ error: "source must start with 'github:'",
54
+ };
55
+ }
56
+ // After the `github:` prefix we expect <owner>/<repo>/<kind>/<name>.
57
+ // We split into exactly 4 segments — extra trailing slashes or
58
+ // missing components are rejected with `bad_shape` so the response
59
+ // is actionable.
60
+ const tail = source.slice("github:".length);
61
+ const segments = tail.split("/");
62
+ if (segments.length !== 4) {
63
+ return {
64
+ ok: false,
65
+ code: "bad_shape",
66
+ error: "source must match 'github:<owner>/<repo>/(recipes|bundles)/<name>'",
67
+ };
68
+ }
69
+ const [ownerRaw, repoRaw, kindRaw, nameRaw] = segments;
70
+ const owner = ownerRaw.toLowerCase();
71
+ const repo = repoRaw.toLowerCase();
72
+ if (!SEGMENT_RE.test(owner) || !SEGMENT_RE.test(repo)) {
73
+ return {
74
+ ok: false,
75
+ code: "bad_segment",
76
+ error: "owner and repo must match [a-z0-9_.-]{1,100}",
77
+ };
78
+ }
79
+ if (kindRaw !== "recipes" && kindRaw !== "bundles") {
80
+ return {
81
+ ok: false,
82
+ code: "bad_shape",
83
+ error: "third path segment must be 'recipes' or 'bundles'",
84
+ };
85
+ }
86
+ // Reuse the strict basename predicate inline rather than importing
87
+ // recipeInstall.ts here (circular deps), but match its rules:
88
+ // single segment, no `..`, no slashes, conservative charset, ≤100.
89
+ if (!SEGMENT_RE.test(nameRaw.toLowerCase())) {
90
+ return {
91
+ ok: false,
92
+ code: "bad_segment",
93
+ error: "name must match [a-z0-9_.-]{1,100}",
94
+ };
95
+ }
96
+ const allowSet = new Set(allowlist.map((s) => s.toLowerCase()));
97
+ if (!allowSet.has(`${owner}/${repo}`)) {
98
+ return {
99
+ ok: false,
100
+ code: "not_allowlisted",
101
+ error: `'${owner}/${repo}' is not in the recipe-repo allowlist. Set PATCHWORK_RECIPE_REPO_ALLOWLIST=${owner}/${repo} to opt in.`,
102
+ };
103
+ }
104
+ return {
105
+ ok: true,
106
+ parsed: {
107
+ kind: kindRaw === "recipes" ? "recipe" : "bundle",
108
+ owner,
109
+ repo,
110
+ name: nameRaw,
111
+ },
112
+ };
113
+ }
114
+ /**
115
+ * The repo-relative path of the file for a parsed install source.
116
+ * `recipes/<name>/<name>.yaml` or `bundles/<name>/patchwork-bundle.json`.
117
+ */
118
+ function repoRelativePath(parsed) {
119
+ if (parsed.kind === "recipe") {
120
+ return `recipes/${parsed.name}/${parsed.name}.yaml`;
121
+ }
122
+ return `bundles/${parsed.name}/patchwork-bundle.json`;
123
+ }
124
+ /**
125
+ * Build the raw.githubusercontent URL for a parsed install source.
126
+ * Always pulls `main` branch HEAD — version pinning is on the
127
+ * deferred audit backlog.
128
+ */
129
+ export function buildGithubRawUrl(parsed) {
130
+ return `https://raw.githubusercontent.com/${parsed.owner}/${parsed.repo}/main/${repoRelativePath(parsed)}`;
131
+ }
132
+ /**
133
+ * Build the `api.github.com` Contents-API URL for a parsed install
134
+ * source. Used as a FALLBACK when `raw.githubusercontent.com` is
135
+ * unreachable — many corporate / proxied networks block the raw host
136
+ * even when `api.github.com` is allowed. Combined with the
137
+ * `Accept: application/vnd.github.raw` request header (see
138
+ * `fetchGithubInstallFile`), this endpoint returns the raw file bytes
139
+ * directly — no base64 decode needed. Public repos work unauthenticated.
140
+ */
141
+ export function buildGithubApiUrl(parsed) {
142
+ return `https://api.github.com/repos/${parsed.owner}/${parsed.repo}/contents/${repoRelativePath(parsed)}?ref=main`;
143
+ }
144
+ export async function fetchGithubInstallFile(parsed, init = {}) {
145
+ const rawUrl = buildGithubRawUrl(parsed);
146
+ let rawResponse = null;
147
+ let rawNetworkError = null;
148
+ try {
149
+ rawResponse = await fetch(rawUrl, {
150
+ signal: init.signal,
151
+ redirect: "follow",
152
+ });
153
+ }
154
+ catch (err) {
155
+ rawNetworkError = err;
156
+ }
157
+ // Fast path: raw host returned a usable response.
158
+ if (rawResponse?.ok) {
159
+ return { ok: true, response: rawResponse };
160
+ }
161
+ // Raw host either threw OR returned non-ok → try the API fallback.
162
+ const apiUrl = buildGithubApiUrl(parsed);
163
+ let apiResponse = null;
164
+ let apiNetworkError = null;
165
+ try {
166
+ apiResponse = await fetch(apiUrl, {
167
+ signal: init.signal,
168
+ redirect: "follow",
169
+ headers: { Accept: "application/vnd.github.raw" },
170
+ });
171
+ }
172
+ catch (err) {
173
+ apiNetworkError = err;
174
+ }
175
+ if (apiResponse?.ok) {
176
+ return { ok: true, response: apiResponse };
177
+ }
178
+ // Neither host yielded an ok body. Decide which failure to surface.
179
+ //
180
+ // A non-404 HTTP failure (5xx / 403 rate-limit) is the most
181
+ // actionable signal — prefer it over a 404 from the other host, so a
182
+ // transient upstream problem isn't misreported as "recipe missing".
183
+ // The API response is the more authoritative of the two here (raw is
184
+ // a CDN; the API gives proper status codes), so check it first.
185
+ if (apiResponse && apiResponse.status !== 404) {
186
+ return { ok: false, kind: "upstream_error", response: apiResponse };
187
+ }
188
+ if (rawResponse && rawResponse.status !== 404) {
189
+ return { ok: false, kind: "upstream_error", response: rawResponse };
190
+ }
191
+ // Whatever is left is a genuine 404 from one or both hosts → keep
192
+ // the not-found distinction so the caller surfaces a 404, not a 502.
193
+ if (apiResponse && apiResponse.status === 404) {
194
+ return { ok: false, kind: "not_found", response: apiResponse };
195
+ }
196
+ if (rawResponse && rawResponse.status === 404) {
197
+ return { ok: false, kind: "not_found", response: rawResponse };
198
+ }
199
+ // Both hosts threw network errors.
200
+ return {
201
+ ok: false,
202
+ kind: "network_error",
203
+ error: apiNetworkError ?? rawNetworkError,
204
+ };
205
+ }
206
+ //# sourceMappingURL=githubInstallSource.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"githubInstallSource.js","sourceRoot":"","sources":["../../src/recipes/githubInstallSource.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAoBH,MAAM,iBAAiB,GAA0B,CAAC,qBAAqB,CAAC,CAAC;AACzE,MAAM,CAAC,MAAM,UAAU,GAAG,gCAAgC,CAAC;AAE3D;;;;;;;GAOG;AACH,MAAM,UAAU,aAAa,CAAC,MAAyB,OAAO,CAAC,GAAG;IAChE,MAAM,OAAO,GAAG,CAAC,GAAG,CAAC,+BAA+B,IAAI,EAAE,CAAC;SACxD,KAAK,CAAC,GAAG,CAAC;SACV,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;SAClC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;IAClD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,iBAAiB,EAAE,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AACjE,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OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC;IAC7C,CAAC;IAED,oEAAoE;IACpE,EAAE;IACF,4DAA4D;IAC5D,qEAAqE;IACrE,oEAAoE;IACpE,qEAAqE;IACrE,gEAAgE;IAChE,IAAI,WAAW,IAAI,WAAW,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;QAC9C,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,gBAAgB,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC;IACtE,CAAC;IACD,IAAI,WAAW,IAAI,WAAW,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;QAC9C,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,gBAAgB,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC;IACtE,CAAC;IACD,kEAAkE;IAClE,qEAAqE;IACrE,IAAI,WAAW,IAAI,WAAW,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;QAC9C,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC;IACjE,CAAC;IACD,IAAI,WAAW,IAAI,WAAW,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;QAC9C,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC;IACjE,CAAC;IACD,mCAAmC;IACnC,OAAO;QACL,EAAE,EAAE,KAAK;QACT,IAAI,EAAE,eAAe;QACrB,KAAK,EAAE,eAAe,IAAI,eAAe;KAC1C,CAAC;AACJ,CAAC"}
@@ -0,0 +1,119 @@
1
+ /**
2
+ * Halt-category derivation.
3
+ *
4
+ * PR1c of the Val-inspired plan. PR1 attached a `haltReason` sentence to
5
+ * every error-status StepResult; this module categorises those sentences
6
+ * into a small bounded enum so the dashboard / metrics layer can count
7
+ * them over time. Foundation for "is the haltReason work actually
8
+ * surfacing useful signal, or is everything landing in `unknown`?"
9
+ *
10
+ * The mapping is intentionally pattern-based against the 5 phrases
11
+ * emitted by yamlRunner.ts. Keep this file and those phrases in sync.
12
+ * When a new error site is added, add a category here AND a test.
13
+ */
14
+ export type HaltCategory = "agent_silent_fail" | "agent_narration_only" | "agent_threw" | "tool_threw" | "tool_error"
15
+ /** Write blocked by the global kill-switch (#422). Distinct from a real tool failure. */
16
+ | "kill_switch"
17
+ /** Recipe's `tokensMax` budget breached (PR2b). */
18
+ | "budget_exceeded"
19
+ /** Per-step `expect` assertion failed (slice 2). */
20
+ | "expect_failed"
21
+ /** Per-step wall-clock `timeout_ms` exceeded (sandbox-alternative slice). */
22
+ | "step_timeout"
23
+ /**
24
+ * Connector returned 401/403 — token expired or scopes insufficient.
25
+ * Actionable: user should reconnect from /connections.
26
+ */
27
+ | "auth_failure"
28
+ /**
29
+ * External service returned 429 / rate limit. Actionable: retry later
30
+ * or back off the cron cadence.
31
+ */
32
+ | "rate_limited"
33
+ /**
34
+ * Transport failed before the request reached the service
35
+ * (ECONNREFUSED, ENOTFOUND, fetch failed). Distinct from a 4xx/5xx
36
+ * from the service itself — usually a local network / DNS issue.
37
+ */
38
+ | "network_error"
39
+ /**
40
+ * Tool needed a connector that isn't configured for this workspace.
41
+ * Actionable: install/connect from /connections.
42
+ */
43
+ | "missing_connector"
44
+ /** Whole-recipe failure (e.g. circular dependencies) — has no step row. */
45
+ | "run_level" | "unknown";
46
+ /**
47
+ * Human-readable label per category. Shared by the `halts` CLI, the
48
+ * `recipe doctor` command, and (mirrored) the dashboard, so the wording
49
+ * stays consistent across surfaces.
50
+ */
51
+ export declare const HALT_CATEGORY_LABELS: Record<HaltCategory, string>;
52
+ /**
53
+ * Actionable one-liner per category — "what to do about it". Shared by
54
+ * the `halts` CLI and `recipe doctor` so SSH / mobile users get the fix
55
+ * hint without opening the dashboard.
56
+ */
57
+ export declare const HALT_CATEGORY_HINTS: Record<HaltCategory, string>;
58
+ export declare function categoriseHaltReason(reason: string | undefined): HaltCategory;
59
+ export interface HaltSummary {
60
+ /** Total error-status step results scanned. */
61
+ total: number;
62
+ /** Per-category counts; categories with zero hits are omitted. */
63
+ byCategory: Partial<Record<HaltCategory, number>>;
64
+ /** Most recent 5 halt reasons (verbatim) for surfacing in the UI. */
65
+ recent: Array<{
66
+ reason: string;
67
+ category: HaltCategory;
68
+ runSeq: number;
69
+ }>;
70
+ }
71
+ interface HaltSummaryInputRun {
72
+ seq: number;
73
+ /** Top-level run status — `run_level` halts are runs with status === "error" but no error stepResults (e.g. circular-dep failure before any step ran). */
74
+ status?: "running" | "done" | "error" | "cancelled" | "interrupted";
75
+ /** Top-level errorMessage — surfaced as a `run_level` halt when no per-step halts cover it. */
76
+ errorMessage?: string;
77
+ stepResults?: Array<{
78
+ status: "ok" | "skipped" | "error";
79
+ haltReason?: string;
80
+ /** Pre-tagged category from yamlRunner throw site — avoids regex re-derivation when present. */
81
+ haltCategory?: HaltCategory;
82
+ }>;
83
+ }
84
+ /**
85
+ * Aggregate halt categories across a set of runs. Runs are expected to be
86
+ * sorted newest-first so `recent` reflects the most recent halts.
87
+ *
88
+ * A run contributes:
89
+ * - one entry per error-status stepResult that has a `haltReason`
90
+ * - plus one `run_level` entry if `status === "error"` and there were no
91
+ * per-step halts that already explained it (avoids double-counting).
92
+ */
93
+ export declare function summariseHalts(runs: HaltSummaryInputRun[]): HaltSummary;
94
+ /**
95
+ * Format a `HaltSummary` as Prometheus text-exposition lines for the
96
+ * `bridge_recipe_halts{category="..."} N` gauge. Returns an empty array
97
+ * when the summary is empty (no HELP/TYPE block emitted in that case so
98
+ * Prom scrapers don't see an orphan declaration).
99
+ *
100
+ * Surfaced via `/metrics` so users with their own observability stack
101
+ * can dashboard halts without using Patchwork's UI.
102
+ */
103
+ export declare function haltSummaryToPrometheus(summary: HaltSummary): string[];
104
+ /**
105
+ * Derive a one-sentence haltReason from a step's error-status + raw error
106
+ * string. Used by `chainedRunner` to mirror the convention emitted by
107
+ * `yamlRunner`. Returns `undefined` for non-error rows or missing error.
108
+ *
109
+ * Pattern-matches the same phrases `categoriseHaltReason` knows about,
110
+ * so chained-run haltReasons categorise into the same buckets.
111
+ */
112
+ export declare function deriveHaltReasonFromError(opts: {
113
+ stepId: string;
114
+ toolName?: string;
115
+ isAgent?: boolean;
116
+ status: "ok" | "skipped" | "error";
117
+ error?: string;
118
+ }): string | undefined;
119
+ export {};
@@ -0,0 +1,188 @@
1
+ /**
2
+ * Halt-category derivation.
3
+ *
4
+ * PR1c of the Val-inspired plan. PR1 attached a `haltReason` sentence to
5
+ * every error-status StepResult; this module categorises those sentences
6
+ * into a small bounded enum so the dashboard / metrics layer can count
7
+ * them over time. Foundation for "is the haltReason work actually
8
+ * surfacing useful signal, or is everything landing in `unknown`?"
9
+ *
10
+ * The mapping is intentionally pattern-based against the 5 phrases
11
+ * emitted by yamlRunner.ts. Keep this file and those phrases in sync.
12
+ * When a new error site is added, add a category here AND a test.
13
+ */
14
+ /**
15
+ * Human-readable label per category. Shared by the `halts` CLI, the
16
+ * `recipe doctor` command, and (mirrored) the dashboard, so the wording
17
+ * stays consistent across surfaces.
18
+ */
19
+ export const HALT_CATEGORY_LABELS = {
20
+ agent_silent_fail: "agent silent-fail",
21
+ agent_narration_only: "agent narration-only",
22
+ agent_threw: "agent threw",
23
+ tool_threw: "tool threw",
24
+ tool_error: "tool error",
25
+ kill_switch: "kill-switch blocked",
26
+ budget_exceeded: "budget exceeded",
27
+ expect_failed: "expect failed",
28
+ step_timeout: "step timeout",
29
+ auth_failure: "auth failure",
30
+ rate_limited: "rate limited",
31
+ network_error: "network error",
32
+ missing_connector: "missing connector",
33
+ run_level: "run-level halt",
34
+ unknown: "uncategorised",
35
+ };
36
+ /**
37
+ * Actionable one-liner per category — "what to do about it". Shared by
38
+ * the `halts` CLI and `recipe doctor` so SSH / mobile users get the fix
39
+ * hint without opening the dashboard.
40
+ */
41
+ export const HALT_CATEGORY_HINTS = {
42
+ agent_silent_fail: "inspect prompt + check trace",
43
+ agent_narration_only: "tighten prompt or add `into:` target",
44
+ agent_threw: "open run trace",
45
+ tool_threw: "check inner error in trace",
46
+ tool_error: "check inner error in trace",
47
+ kill_switch: "run `patchwork kill-switch release`",
48
+ budget_exceeded: "raise tokensMax or shrink prompts",
49
+ expect_failed: "inspect assertion vs actual output",
50
+ step_timeout: "bump timeout_ms or speed up step",
51
+ auth_failure: "reconnect from /connections",
52
+ rate_limited: "back off cron cadence or wait",
53
+ network_error: "check connectivity to upstream",
54
+ missing_connector: "install/connect from /connections",
55
+ run_level: "check recipe for circular deps / parse errors",
56
+ unknown: "open run trace for raw error",
57
+ };
58
+ export function categoriseHaltReason(reason) {
59
+ if (!reason)
60
+ return "unknown";
61
+ // Order matters: more specific phrases (silent-fail, narration, kill
62
+ // switch) must match before the general "Agent step ... threw" /
63
+ // "Tool ... threw" patterns. The phrases below mirror
64
+ // yamlRunner.ts:558-606,677-684,693-708 and
65
+ // featureFlags.ts:assertWriteAllowed.
66
+ if (/silent-fail/i.test(reason))
67
+ return "agent_silent_fail";
68
+ if (/narration|whitespace|no content/i.test(reason))
69
+ return "agent_narration_only";
70
+ if (/kill[- _]?switch/i.test(reason))
71
+ return "kill_switch";
72
+ if (/budget[_ ]?exceeded|exceeded its token budget/i.test(reason))
73
+ return "budget_exceeded";
74
+ if (/^expect_failed/i.test(reason))
75
+ return "expect_failed";
76
+ // Must precede the `^Tool ... threw` matcher: timeouts surface wrapped
77
+ // inside the tool-threw envelope (`Tool "x" in step "y" threw: step_timeout: ...`).
78
+ if (/step_timeout/i.test(reason))
79
+ return "step_timeout";
80
+ // Sub-categories that peek inside the wrapped `Tool "x" threw: <inner>` /
81
+ // `Tool "x" reported an error: <inner>` envelope. Must precede the
82
+ // generic `tool_threw` / `tool_error` matchers below. Patterns are
83
+ // deliberately narrow — e.g. "unreachable" alone stays in `tool_error`
84
+ // because too many tools use it as a generic phrase.
85
+ if (/\b(401|403)\b|unauthori[sz]ed|forbidden|invalid[_ -]?token|token[_ -]?expired|authentication[_ -]?failed/i.test(reason))
86
+ return "auth_failure";
87
+ if (/\b429\b|rate[_ -]?limit|too many requests/i.test(reason))
88
+ return "rate_limited";
89
+ if (/ECONNREFUSED|ENOTFOUND|ECONNRESET|ETIMEDOUT|EAI_AGAIN|fetch failed|network[_ -]?error|getaddrinfo/i.test(reason))
90
+ return "network_error";
91
+ if (/connector[_ -]?not[_ -]?configured|no[_ -]?(connector[_ -]?)?token|not[_ -]?connected|missing[_ -]?connector/i.test(reason))
92
+ return "missing_connector";
93
+ if (/^Agent step .* threw/i.test(reason))
94
+ return "agent_threw";
95
+ if (/^Tool .* threw/i.test(reason))
96
+ return "tool_threw";
97
+ if (/^Tool .* reported an error/i.test(reason))
98
+ return "tool_error";
99
+ return "unknown";
100
+ }
101
+ /**
102
+ * Aggregate halt categories across a set of runs. Runs are expected to be
103
+ * sorted newest-first so `recent` reflects the most recent halts.
104
+ *
105
+ * A run contributes:
106
+ * - one entry per error-status stepResult that has a `haltReason`
107
+ * - plus one `run_level` entry if `status === "error"` and there were no
108
+ * per-step halts that already explained it (avoids double-counting).
109
+ */
110
+ export function summariseHalts(runs) {
111
+ const byCategory = {};
112
+ const recent = [];
113
+ let total = 0;
114
+ for (const run of runs) {
115
+ let stepHaltsForRun = 0;
116
+ for (const step of run.stepResults ?? []) {
117
+ if (step.status !== "error" || !step.haltReason)
118
+ continue;
119
+ stepHaltsForRun++;
120
+ total++;
121
+ const cat = step.haltCategory ?? categoriseHaltReason(step.haltReason);
122
+ byCategory[cat] = (byCategory[cat] ?? 0) + 1;
123
+ if (recent.length < 5) {
124
+ recent.push({
125
+ reason: step.haltReason,
126
+ category: cat,
127
+ runSeq: run.seq,
128
+ });
129
+ }
130
+ }
131
+ if (stepHaltsForRun === 0 && run.status === "error" && run.errorMessage) {
132
+ total++;
133
+ byCategory.run_level = (byCategory.run_level ?? 0) + 1;
134
+ if (recent.length < 5) {
135
+ recent.push({
136
+ reason: run.errorMessage,
137
+ category: "run_level",
138
+ runSeq: run.seq,
139
+ });
140
+ }
141
+ }
142
+ }
143
+ return { total, byCategory, recent };
144
+ }
145
+ /**
146
+ * Format a `HaltSummary` as Prometheus text-exposition lines for the
147
+ * `bridge_recipe_halts{category="..."} N` gauge. Returns an empty array
148
+ * when the summary is empty (no HELP/TYPE block emitted in that case so
149
+ * Prom scrapers don't see an orphan declaration).
150
+ *
151
+ * Surfaced via `/metrics` so users with their own observability stack
152
+ * can dashboard halts without using Patchwork's UI.
153
+ */
154
+ export function haltSummaryToPrometheus(summary) {
155
+ if (summary.total === 0)
156
+ return [];
157
+ const lines = [
158
+ "# HELP bridge_recipe_halts Recipe halts in the in-memory run-log window, by category",
159
+ "# TYPE bridge_recipe_halts gauge",
160
+ ];
161
+ for (const [category, count] of Object.entries(summary.byCategory)) {
162
+ lines.push(`bridge_recipe_halts{category="${category}"} ${count}`);
163
+ }
164
+ return lines;
165
+ }
166
+ /**
167
+ * Derive a one-sentence haltReason from a step's error-status + raw error
168
+ * string. Used by `chainedRunner` to mirror the convention emitted by
169
+ * `yamlRunner`. Returns `undefined` for non-error rows or missing error.
170
+ *
171
+ * Pattern-matches the same phrases `categoriseHaltReason` knows about,
172
+ * so chained-run haltReasons categorise into the same buckets.
173
+ */
174
+ export function deriveHaltReasonFromError(opts) {
175
+ if (opts.status !== "error" || !opts.error)
176
+ return undefined;
177
+ if (/silent-fail/i.test(opts.error)) {
178
+ return `Step "${opts.stepId}" returned no usable output (silent-fail).`;
179
+ }
180
+ if (/narration|whitespace|no content/i.test(opts.error)) {
181
+ return `Step "${opts.stepId}" returned only narration or whitespace — no content.`;
182
+ }
183
+ if (opts.isAgent) {
184
+ return `Agent step "${opts.stepId}" threw before completing: ${opts.error}`;
185
+ }
186
+ return `Tool "${opts.toolName ?? "?"}" in step "${opts.stepId}" reported an error: ${opts.error}`;
187
+ }
188
+ //# sourceMappingURL=haltCategory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"halt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
7
+ *
8
+ * `deriveIdempotencyKey(toolId, params)`
9
+ * A stable, deterministic hash over `(toolId, canonicalised params)`.
10
+ * Canonicalisation = JSON.stringify with sorted keys, recursive — so
11
+ * `{ a: 1, b: 2 }` and `{ b: 2, a: 1 }` hash identically. Returns a
12
+ * hex SHA-256 prefix (first 16 chars; collisions vanishingly small
13
+ * within a single run scope).
14
+ *
15
+ * `WriteEffectLedger`
16
+ * Per-run in-memory map of key → cached output. The runner constructs
17
+ * one per recipe run and threads it through `StepDeps` / `ToolContext`.
18
+ * `toolRegistry.executeTool` checks the ledger before invoking write
19
+ * tools; if the key is present, returns the cached output instead of
20
+ * re-executing — preventing duplicate side effects when two parallel
21
+ * branches of a chained recipe both call the same write tool with the
22
+ * same params.
23
+ *
24
+ * Scope of this PR (deliberately narrow):
25
+ * - In-run dedup only (Map lives for one recipe run, discarded after).
26
+ * - Records only on successful execution; errors don't pollute the
27
+ * ledger, so retry-after-failure still re-executes (correct: if the
28
+ * tool errored, we can't assume the side effect happened).
29
+ * - No cross-run persistence — that's PR5b (disk-backed effect ledger).
30
+ * - No retry-time idempotency on partial-failure cases (Slack posted
31
+ * but HTTP timed out); that needs tool-side support and is a future
32
+ * PR.
33
+ *
34
+ * The protection this DOES provide today: a `parallel:` block (or a
35
+ * recipe that calls a write tool from two different chained steps with
36
+ * identical params) cannot duplicate the side effect. Concretely, this
37
+ * was a footgun that pre-dated PR5a: `chainedRunner.ts` schedules steps
38
+ * with dependency-graph parallelism; if two branches happen to call
39
+ * `slack.postMessage` with the same payload, the message went twice.
40
+ */
41
+ import type { Logger } from "../logger.js";
42
+ /**
43
+ * Derive a stable idempotency key for a write-tool invocation. 16 hex
44
+ * chars is 64 bits of entropy — far more than enough for in-run dedup
45
+ * (a single recipe with even 10⁵ steps has ~5×10⁻¹⁰ collision risk).
46
+ */
47
+ export declare function deriveIdempotencyKey(toolId: string, params: Record<string, unknown>): string;
48
+ /**
49
+ * Compose a collision-safe scope key from `(recipeName, manualRunId)`.
50
+ *
51
+ * Naive `${recipeName}:${manualRunId}` is ambiguous: recipe `a:b` +
52
+ * attempt `c` and recipe `a` + attempt `b:c` both produce `a:b:c` and
53
+ * would share a ledger scope, letting one attempt read another's
54
+ * cached write-tool outputs. We hash both fields separately as a JSON
55
+ * array so the encoding is unambiguous regardless of either field's
56
+ * contents.
57
+ *
58
+ * Returned as a 32-hex-char SHA-256 prefix — long enough that
59
+ * collisions across a realistic ledger are effectively impossible
60
+ * (~2^128 birthday bound), short enough to scan in a JSONL row.
61
+ */
62
+ export declare function deriveScopeKey(recipeName: string, manualRunId: string): string;
63
+ export declare function assertValidManualRunId(id: string): string;
64
+ /**
65
+ * In-memory per-run ledger of executed write-tool calls. Maps idempotency
66
+ * keys to the cached output the tool returned, so a duplicate call can
67
+ * be short-circuited to the same result the first call produced.
68
+ *
69
+ * The ledger is single-threaded by design — runners are single-process
70
+ * and a per-run ledger has no cross-thread access. Concurrency safety
71
+ * within a run is provided by the dependency graph (parallel-only steps
72
+ * with no shared params hash by construction); the ledger catches
73
+ * accidental same-params calls.
74
+ */
75
+ /**
76
+ * Optional disk-backed persistence for the ledger.
77
+ *
78
+ * PR5b — extends in-memory dedup so a *retry* of the same logical
79
+ * `(recipeName, manualRunId)` attempt won't replay side effects. The
80
+ * ledger stays per-attempt; cron/webhook runs and recipes without a
81
+ * manualRunId stay purely in memory (no scope key = nothing to write).
82
+ *
83
+ * File layout: a single JSONL at `${dir}/effect_ledger.jsonl`. Each row
84
+ * is `{scopeKey, idemKey, output, recordedAt}`. On construction, the
85
+ * ledger streams the file and rehydrates entries whose `scopeKey`
86
+ * matches the configured scope; everything else is left alone for the
87
+ * other attempts' ledgers to pick up.
88
+ *
89
+ * Failure mode: any IO error falls back to in-memory operation and logs
90
+ * a warning. A partially-replayed attempt with an unreadable ledger
91
+ * degrades to "re-execute side effects" — louder than "silently dedup
92
+ * something we can't audit".
93
+ */
94
+ export interface DiskLedgerOptions {
95
+ /** Directory holding `effect_ledger.jsonl`. Created if missing. */
96
+ dir: string;
97
+ /** `${recipeName}:${manualRunId}` — composed by the caller. */
98
+ scopeKey: string;
99
+ logger?: Logger;
100
+ }
101
+ export declare class WriteEffectLedger {
102
+ private readonly cache;
103
+ private readonly inFlight;
104
+ private readonly disk;
105
+ private readonly file;
106
+ constructor(disk?: DiskLedgerOptions);
107
+ has(key: string): boolean;
108
+ /**
109
+ * Return the previously-cached output for `key`, or `undefined` if not
110
+ * recorded. `null` is a legitimate cached value (= the tool returned
111
+ * `null` originally), so callers must use `has()` to distinguish "not
112
+ * present" from "present and null".
113
+ */
114
+ get(key: string): string | null | undefined;
115
+ record(key: string, output: string | null): void;
116
+ /**
117
+ * Atomically check cache + in-flight map, then execute `fn` at most once
118
+ * per key. Concurrent callers with the same key share a single Promise —
119
+ * fixing the TOCTOU window that existed between `has()` and `record()`.
120
+ * Failures are not cached so retry-after-failure still re-executes.
121
+ */
122
+ getOrExecute(key: string, fn: () => Promise<string | null>): Promise<string | null>;
123
+ /** Test-only inspection of the current key set. */
124
+ keys(): string[];
125
+ size(): number;
126
+ private loadExisting;
127
+ private append;
128
+ /**
129
+ * Trim `effect_ledger.jsonl` to the most recent MAX_PERSIST_LINES.
130
+ * Best-effort — failure logs and the next append proceeds against the
131
+ * un-rotated file. Same pattern as RecipeRunLog / DecisionTraceLog.
132
+ */
133
+ private rotate;
134
+ }