patchwork-os 0.2.0-alpha.3 → 0.2.0-alpha.31

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 (301) hide show
  1. package/README.bridge.md +6 -0
  2. package/README.md +40 -15
  3. package/deploy/bootstrap-vps.sh +184 -0
  4. package/deploy/deploy-dashboard.sh +174 -0
  5. package/deploy/deploy-landing.sh +79 -0
  6. package/dist/activationMetrics.d.ts +67 -0
  7. package/dist/activationMetrics.js +255 -0
  8. package/dist/activationMetrics.js.map +1 -0
  9. package/dist/approvalHttp.d.ts +24 -2
  10. package/dist/approvalHttp.js +150 -10
  11. package/dist/approvalHttp.js.map +1 -1
  12. package/dist/approvalQueue.d.ts +16 -1
  13. package/dist/approvalQueue.js +44 -3
  14. package/dist/approvalQueue.js.map +1 -1
  15. package/dist/automation.d.ts +20 -0
  16. package/dist/automation.js +54 -1
  17. package/dist/automation.js.map +1 -1
  18. package/dist/bridge.d.ts +2 -0
  19. package/dist/bridge.js +55 -130
  20. package/dist/bridge.js.map +1 -1
  21. package/dist/bridgeToken.js +57 -19
  22. package/dist/bridgeToken.js.map +1 -1
  23. package/dist/ccPermissions.js +6 -4
  24. package/dist/ccPermissions.js.map +1 -1
  25. package/dist/claudeOrchestrator.d.ts +1 -1
  26. package/dist/claudeOrchestrator.js +14 -8
  27. package/dist/claudeOrchestrator.js.map +1 -1
  28. package/dist/commands/launchd.d.ts +2 -0
  29. package/dist/commands/launchd.js +94 -0
  30. package/dist/commands/launchd.js.map +1 -0
  31. package/dist/commands/recipe.d.ts +258 -0
  32. package/dist/commands/recipe.js +1130 -0
  33. package/dist/commands/recipe.js.map +1 -0
  34. package/dist/commands/recipeInstall.d.ts +72 -0
  35. package/dist/commands/recipeInstall.js +339 -0
  36. package/dist/commands/recipeInstall.js.map +1 -0
  37. package/dist/config.d.ts +14 -1
  38. package/dist/config.js +99 -8
  39. package/dist/config.js.map +1 -1
  40. package/dist/connectors/baseConnector.d.ts +117 -0
  41. package/dist/connectors/baseConnector.js +213 -0
  42. package/dist/connectors/baseConnector.js.map +1 -0
  43. package/dist/connectors/confluence.d.ts +111 -0
  44. package/dist/connectors/confluence.js +406 -0
  45. package/dist/connectors/confluence.js.map +1 -0
  46. package/dist/connectors/datadog.d.ts +116 -0
  47. package/dist/connectors/datadog.js +385 -0
  48. package/dist/connectors/datadog.js.map +1 -0
  49. package/dist/connectors/fixtureLibrary.d.ts +21 -0
  50. package/dist/connectors/fixtureLibrary.js +70 -0
  51. package/dist/connectors/fixtureLibrary.js.map +1 -0
  52. package/dist/connectors/fixtureRecorder.d.ts +1 -0
  53. package/dist/connectors/fixtureRecorder.js +35 -0
  54. package/dist/connectors/fixtureRecorder.js.map +1 -0
  55. package/dist/connectors/github.d.ts +58 -8
  56. package/dist/connectors/github.js +312 -84
  57. package/dist/connectors/github.js.map +1 -1
  58. package/dist/connectors/gmail.d.ts +4 -1
  59. package/dist/connectors/gmail.js +79 -16
  60. package/dist/connectors/gmail.js.map +1 -1
  61. package/dist/connectors/googleCalendar.d.ts +60 -0
  62. package/dist/connectors/googleCalendar.js +345 -0
  63. package/dist/connectors/googleCalendar.js.map +1 -0
  64. package/dist/connectors/hubspot.d.ts +112 -0
  65. package/dist/connectors/hubspot.js +408 -0
  66. package/dist/connectors/hubspot.js.map +1 -0
  67. package/dist/connectors/intercom.d.ts +102 -0
  68. package/dist/connectors/intercom.js +402 -0
  69. package/dist/connectors/intercom.js.map +1 -0
  70. package/dist/connectors/jira.d.ts +98 -0
  71. package/dist/connectors/jira.js +379 -0
  72. package/dist/connectors/jira.js.map +1 -0
  73. package/dist/connectors/linear.d.ts +69 -19
  74. package/dist/connectors/linear.js +170 -129
  75. package/dist/connectors/linear.js.map +1 -1
  76. package/dist/connectors/mcpClient.d.ts +56 -0
  77. package/dist/connectors/mcpClient.js +189 -0
  78. package/dist/connectors/mcpClient.js.map +1 -0
  79. package/dist/connectors/mcpOAuth.d.ts +84 -0
  80. package/dist/connectors/mcpOAuth.js +389 -0
  81. package/dist/connectors/mcpOAuth.js.map +1 -0
  82. package/dist/connectors/mockConnector.d.ts +28 -0
  83. package/dist/connectors/mockConnector.js +81 -0
  84. package/dist/connectors/mockConnector.js.map +1 -0
  85. package/dist/connectors/notion.d.ts +143 -0
  86. package/dist/connectors/notion.js +424 -0
  87. package/dist/connectors/notion.js.map +1 -0
  88. package/dist/connectors/sentry.d.ts +17 -21
  89. package/dist/connectors/sentry.js +115 -131
  90. package/dist/connectors/sentry.js.map +1 -1
  91. package/dist/connectors/slack.d.ts +50 -0
  92. package/dist/connectors/slack.js +324 -0
  93. package/dist/connectors/slack.js.map +1 -0
  94. package/dist/connectors/stripe.d.ts +116 -0
  95. package/dist/connectors/stripe.js +379 -0
  96. package/dist/connectors/stripe.js.map +1 -0
  97. package/dist/connectors/tokenStorage.d.ts +35 -0
  98. package/dist/connectors/tokenStorage.js +459 -0
  99. package/dist/connectors/tokenStorage.js.map +1 -0
  100. package/dist/connectors/zendesk.d.ts +104 -0
  101. package/dist/connectors/zendesk.js +424 -0
  102. package/dist/connectors/zendesk.js.map +1 -0
  103. package/dist/drivers/gemini/index.d.ts +5 -1
  104. package/dist/drivers/gemini/index.js +39 -5
  105. package/dist/drivers/gemini/index.js.map +1 -1
  106. package/dist/drivers/index.d.ts +5 -0
  107. package/dist/drivers/index.js +1 -1
  108. package/dist/drivers/index.js.map +1 -1
  109. package/dist/featureFlags.d.ts +73 -0
  110. package/dist/featureFlags.js +203 -0
  111. package/dist/featureFlags.js.map +1 -0
  112. package/dist/fp/automationInterpreter.js +1 -0
  113. package/dist/fp/automationInterpreter.js.map +1 -1
  114. package/dist/fp/automationProgram.d.ts +1 -1
  115. package/dist/fp/automationProgram.js.map +1 -1
  116. package/dist/fp/policyParser.js +17 -0
  117. package/dist/fp/policyParser.js.map +1 -1
  118. package/dist/index.js +621 -61
  119. package/dist/index.js.map +1 -1
  120. package/dist/installGuard.d.ts +25 -0
  121. package/dist/installGuard.js +48 -0
  122. package/dist/installGuard.js.map +1 -0
  123. package/dist/oauth.d.ts +4 -1
  124. package/dist/oauth.js +50 -14
  125. package/dist/oauth.js.map +1 -1
  126. package/dist/patchworkConfig.d.ts +9 -0
  127. package/dist/patchworkConfig.js.map +1 -1
  128. package/dist/recipeOrchestration.d.ts +53 -0
  129. package/dist/recipeOrchestration.js +272 -0
  130. package/dist/recipeOrchestration.js.map +1 -0
  131. package/dist/recipes/RecipeOrchestrator.d.ts +40 -0
  132. package/dist/recipes/RecipeOrchestrator.js +51 -0
  133. package/dist/recipes/RecipeOrchestrator.js.map +1 -0
  134. package/dist/recipes/agentExecutor.d.ts +28 -0
  135. package/dist/recipes/agentExecutor.js +42 -0
  136. package/dist/recipes/agentExecutor.js.map +1 -0
  137. package/dist/recipes/chainedRunner.d.ts +140 -0
  138. package/dist/recipes/chainedRunner.js +539 -0
  139. package/dist/recipes/chainedRunner.js.map +1 -0
  140. package/dist/recipes/dependencyGraph.d.ts +39 -0
  141. package/dist/recipes/dependencyGraph.js +199 -0
  142. package/dist/recipes/dependencyGraph.js.map +1 -0
  143. package/dist/recipes/legacyRecipeCompat.d.ts +2 -0
  144. package/dist/recipes/legacyRecipeCompat.js +112 -0
  145. package/dist/recipes/legacyRecipeCompat.js.map +1 -0
  146. package/dist/recipes/manifest.d.ts +47 -0
  147. package/dist/recipes/manifest.js +141 -0
  148. package/dist/recipes/manifest.js.map +1 -0
  149. package/dist/recipes/nestedRecipeStep.d.ts +58 -0
  150. package/dist/recipes/nestedRecipeStep.js +95 -0
  151. package/dist/recipes/nestedRecipeStep.js.map +1 -0
  152. package/dist/recipes/outputRegistry.d.ts +28 -0
  153. package/dist/recipes/outputRegistry.js +52 -0
  154. package/dist/recipes/outputRegistry.js.map +1 -0
  155. package/dist/recipes/scheduler.d.ts +23 -7
  156. package/dist/recipes/scheduler.js +131 -41
  157. package/dist/recipes/scheduler.js.map +1 -1
  158. package/dist/recipes/schema.d.ts +17 -2
  159. package/dist/recipes/schemaGenerator.d.ts +28 -0
  160. package/dist/recipes/schemaGenerator.js +565 -0
  161. package/dist/recipes/schemaGenerator.js.map +1 -0
  162. package/dist/recipes/templateEngine.d.ts +62 -0
  163. package/dist/recipes/templateEngine.js +182 -0
  164. package/dist/recipes/templateEngine.js.map +1 -0
  165. package/dist/recipes/toolRegistry.d.ts +181 -0
  166. package/dist/recipes/toolRegistry.js +300 -0
  167. package/dist/recipes/toolRegistry.js.map +1 -0
  168. package/dist/recipes/tools/calendar.d.ts +6 -0
  169. package/dist/recipes/tools/calendar.js +61 -0
  170. package/dist/recipes/tools/calendar.js.map +1 -0
  171. package/dist/recipes/tools/confluence.d.ts +6 -0
  172. package/dist/recipes/tools/confluence.js +254 -0
  173. package/dist/recipes/tools/confluence.js.map +1 -0
  174. package/dist/recipes/tools/datadog.d.ts +6 -0
  175. package/dist/recipes/tools/datadog.js +239 -0
  176. package/dist/recipes/tools/datadog.js.map +1 -0
  177. package/dist/recipes/tools/diagnostics.d.ts +6 -0
  178. package/dist/recipes/tools/diagnostics.js +36 -0
  179. package/dist/recipes/tools/diagnostics.js.map +1 -0
  180. package/dist/recipes/tools/file.d.ts +6 -0
  181. package/dist/recipes/tools/file.js +170 -0
  182. package/dist/recipes/tools/file.js.map +1 -0
  183. package/dist/recipes/tools/git.d.ts +6 -0
  184. package/dist/recipes/tools/git.js +63 -0
  185. package/dist/recipes/tools/git.js.map +1 -0
  186. package/dist/recipes/tools/github.d.ts +6 -0
  187. package/dist/recipes/tools/github.js +91 -0
  188. package/dist/recipes/tools/github.js.map +1 -0
  189. package/dist/recipes/tools/gmail.d.ts +6 -0
  190. package/dist/recipes/tools/gmail.js +210 -0
  191. package/dist/recipes/tools/gmail.js.map +1 -0
  192. package/dist/recipes/tools/hubspot.d.ts +6 -0
  193. package/dist/recipes/tools/hubspot.js +232 -0
  194. package/dist/recipes/tools/hubspot.js.map +1 -0
  195. package/dist/recipes/tools/index.d.ts +22 -0
  196. package/dist/recipes/tools/index.js +25 -0
  197. package/dist/recipes/tools/index.js.map +1 -0
  198. package/dist/recipes/tools/intercom.d.ts +6 -0
  199. package/dist/recipes/tools/intercom.js +226 -0
  200. package/dist/recipes/tools/intercom.js.map +1 -0
  201. package/dist/recipes/tools/linear.d.ts +6 -0
  202. package/dist/recipes/tools/linear.js +83 -0
  203. package/dist/recipes/tools/linear.js.map +1 -0
  204. package/dist/recipes/tools/notion.d.ts +6 -0
  205. package/dist/recipes/tools/notion.js +278 -0
  206. package/dist/recipes/tools/notion.js.map +1 -0
  207. package/dist/recipes/tools/slack.d.ts +6 -0
  208. package/dist/recipes/tools/slack.js +72 -0
  209. package/dist/recipes/tools/slack.js.map +1 -0
  210. package/dist/recipes/tools/stripe.d.ts +6 -0
  211. package/dist/recipes/tools/stripe.js +265 -0
  212. package/dist/recipes/tools/stripe.js.map +1 -0
  213. package/dist/recipes/tools/zendesk.d.ts +6 -0
  214. package/dist/recipes/tools/zendesk.js +245 -0
  215. package/dist/recipes/tools/zendesk.js.map +1 -0
  216. package/dist/recipes/validation.d.ts +13 -0
  217. package/dist/recipes/validation.js +433 -0
  218. package/dist/recipes/validation.js.map +1 -0
  219. package/dist/recipes/yamlRunner.d.ts +87 -0
  220. package/dist/recipes/yamlRunner.js +693 -409
  221. package/dist/recipes/yamlRunner.js.map +1 -1
  222. package/dist/recipesHttp.d.ts +34 -6
  223. package/dist/recipesHttp.js +285 -15
  224. package/dist/recipesHttp.js.map +1 -1
  225. package/dist/riskTier.js +1 -0
  226. package/dist/riskTier.js.map +1 -1
  227. package/dist/runLog.d.ts +23 -0
  228. package/dist/runLog.js +56 -1
  229. package/dist/runLog.js.map +1 -1
  230. package/dist/schemas/dry-run-plan.v1.json +139 -0
  231. package/dist/schemas/recipe.v1.json +684 -0
  232. package/dist/server.d.ts +32 -1
  233. package/dist/server.js +980 -97
  234. package/dist/server.js.map +1 -1
  235. package/dist/streamableHttp.js +2 -0
  236. package/dist/streamableHttp.js.map +1 -1
  237. package/dist/tools/addLinearComment.d.ts +55 -0
  238. package/dist/tools/addLinearComment.js +72 -0
  239. package/dist/tools/addLinearComment.js.map +1 -0
  240. package/dist/tools/bridgeDoctor.js +2 -2
  241. package/dist/tools/bridgeDoctor.js.map +1 -1
  242. package/dist/tools/createLinearIssue.d.ts +84 -0
  243. package/dist/tools/createLinearIssue.js +146 -0
  244. package/dist/tools/createLinearIssue.js.map +1 -0
  245. package/dist/tools/fetchCalendarEvents.d.ts +94 -0
  246. package/dist/tools/fetchCalendarEvents.js +97 -0
  247. package/dist/tools/fetchCalendarEvents.js.map +1 -0
  248. package/dist/tools/fetchGithubIssue.d.ts +80 -0
  249. package/dist/tools/fetchGithubIssue.js +84 -0
  250. package/dist/tools/fetchGithubIssue.js.map +1 -0
  251. package/dist/tools/fetchGithubPR.d.ts +89 -0
  252. package/dist/tools/fetchGithubPR.js +96 -0
  253. package/dist/tools/fetchGithubPR.js.map +1 -0
  254. package/dist/tools/fetchSlackProfile.d.ts +43 -0
  255. package/dist/tools/fetchSlackProfile.js +46 -0
  256. package/dist/tools/fetchSlackProfile.js.map +1 -0
  257. package/dist/tools/getConnectorStatus.d.ts +58 -0
  258. package/dist/tools/getConnectorStatus.js +56 -0
  259. package/dist/tools/getConnectorStatus.js.map +1 -0
  260. package/dist/tools/github/actions.js +4 -2
  261. package/dist/tools/github/actions.js.map +1 -1
  262. package/dist/tools/github/composite.d.ts +339 -0
  263. package/dist/tools/github/composite.js +343 -0
  264. package/dist/tools/github/composite.js.map +1 -0
  265. package/dist/tools/github/index.d.ts +2 -1
  266. package/dist/tools/github/index.js +2 -1
  267. package/dist/tools/github/index.js.map +1 -1
  268. package/dist/tools/github/issues.js +8 -4
  269. package/dist/tools/github/issues.js.map +1 -1
  270. package/dist/tools/github/pr.d.ts +122 -0
  271. package/dist/tools/github/pr.js +195 -5
  272. package/dist/tools/github/pr.js.map +1 -1
  273. package/dist/tools/index.js +32 -1
  274. package/dist/tools/index.js.map +1 -1
  275. package/dist/tools/searchTools.js +1 -1
  276. package/dist/tools/searchTools.js.map +1 -1
  277. package/dist/tools/slackListChannels.d.ts +65 -0
  278. package/dist/tools/slackListChannels.js +70 -0
  279. package/dist/tools/slackListChannels.js.map +1 -0
  280. package/dist/tools/slackPostMessage.d.ts +57 -0
  281. package/dist/tools/slackPostMessage.js +77 -0
  282. package/dist/tools/slackPostMessage.js.map +1 -0
  283. package/dist/tools/testTraceToSource.js +2 -2
  284. package/dist/tools/testTraceToSource.js.map +1 -1
  285. package/dist/tools/updateLinearIssue.d.ts +89 -0
  286. package/dist/tools/updateLinearIssue.js +117 -0
  287. package/dist/tools/updateLinearIssue.js.map +1 -0
  288. package/dist/transport.d.ts +7 -1
  289. package/dist/transport.js +85 -11
  290. package/dist/transport.js.map +1 -1
  291. package/package.json +5 -2
  292. package/scripts/start-all.sh +56 -19
  293. package/templates/automation-policies/recipe-authoring.json +25 -0
  294. package/templates/automation-policy.example.json +6 -0
  295. package/templates/co.patchwork-os.bridge.plist +34 -0
  296. package/templates/recipes/ctx-loop-test.yaml +75 -0
  297. package/templates/recipes/lint-on-save.yaml +1 -2
  298. package/templates/recipes/morning-brief-slack.yaml +57 -0
  299. package/templates/recipes/morning-brief.yaml +14 -6
  300. package/templates/recipes/project-health-check.yaml +50 -0
  301. package/templates/recipes/sentry-to-linear.yaml +77 -0
@@ -0,0 +1,565 @@
1
+ /**
2
+ * Schema Generator — produces JSON Schema from tool registry.
3
+ *
4
+ * Generates composable schemas for editor autocomplete:
5
+ * - schemas/recipe.v1.json — top-level recipe schema
6
+ * - schemas/tools/<namespace>.json — per-namespace tool param schemas
7
+ */
8
+ import { getNamespaces, listTools } from "./toolRegistry.js";
9
+ /**
10
+ * Generate complete schema set from current registry state.
11
+ */
12
+ export function generateSchemaSet() {
13
+ const namespaces = {};
14
+ for (const ns of getNamespaces()) {
15
+ namespaces[ns] = generateNamespaceSchema(ns);
16
+ }
17
+ return {
18
+ recipe: generateRecipeSchema(namespaces),
19
+ namespaces,
20
+ dryRunPlan: generateDryRunPlanSchema(),
21
+ };
22
+ }
23
+ /**
24
+ * JSON Schema for RecipeDryRunPlan. Consumers (dashboard run timeline, external CI)
25
+ * should pin on `schemaVersion` and validate against this.
26
+ */
27
+ export function generateDryRunPlanSchema() {
28
+ const riskEnum = { type: "string", enum: ["low", "medium", "high"] };
29
+ const planStep = {
30
+ type: "object",
31
+ required: ["id", "type"],
32
+ properties: {
33
+ id: { type: "string" },
34
+ type: { type: "string", enum: ["tool", "agent", "recipe"] },
35
+ tool: { type: "string" },
36
+ namespace: { type: "string" },
37
+ into: { type: "string" },
38
+ optional: { type: "boolean" },
39
+ prompt: { type: "string" },
40
+ params: { type: "object", additionalProperties: true },
41
+ dependencies: { type: "array", items: { type: "string" } },
42
+ condition: { type: "string" },
43
+ risk: riskEnum,
44
+ isWrite: { type: "boolean" },
45
+ isConnector: { type: "boolean" },
46
+ resolved: {
47
+ type: "boolean",
48
+ description: "True if the tool id is known to the registry at plan time",
49
+ },
50
+ },
51
+ };
52
+ return {
53
+ $schema: "http://json-schema.org/draft-07/schema#",
54
+ $id: "https://patchworkos.com/schema/dry-run-plan.v1.json",
55
+ title: "Patchwork Recipe Dry-Run Plan",
56
+ description: "Stable machine-readable output of `patchwork recipe run --dry-run`. Pin consumers on schemaVersion.",
57
+ type: "object",
58
+ required: [
59
+ "schemaVersion",
60
+ "recipe",
61
+ "mode",
62
+ "triggerType",
63
+ "generatedAt",
64
+ "steps",
65
+ ],
66
+ properties: {
67
+ schemaVersion: { type: "number", const: 1 },
68
+ recipe: { type: "string" },
69
+ mode: { type: "string", const: "dry-run" },
70
+ triggerType: { type: "string" },
71
+ generatedAt: {
72
+ type: "string",
73
+ description: "ISO-8601 timestamp when plan was generated",
74
+ },
75
+ stepSelection: {
76
+ type: "object",
77
+ properties: {
78
+ query: { type: "string" },
79
+ matchedBy: { type: "string" },
80
+ matchedValue: { type: "string" },
81
+ },
82
+ },
83
+ steps: { type: "array", items: planStep },
84
+ parallelGroups: {
85
+ type: "array",
86
+ items: { type: "array", items: { type: "string" } },
87
+ },
88
+ maxDepth: { type: "number" },
89
+ connectorNamespaces: { type: "array", items: { type: "string" } },
90
+ hasWriteSteps: { type: "boolean" },
91
+ },
92
+ };
93
+ }
94
+ /**
95
+ * Generate top-level recipe schema that composes namespace tool schemas.
96
+ */
97
+ function generateRecipeSchema(namespaceSchemas) {
98
+ const chainedStepMetadataProperties = {
99
+ id: {
100
+ type: "string",
101
+ description: "Unique chained step identifier used for outputs and dependencies",
102
+ },
103
+ awaits: {
104
+ type: "array",
105
+ description: "Step IDs that must complete before this step runs",
106
+ items: {
107
+ type: "string",
108
+ },
109
+ },
110
+ when: {
111
+ type: "string",
112
+ description: "Template condition that controls whether this step runs",
113
+ },
114
+ optional: {
115
+ type: "boolean",
116
+ description: "Whether step failure should be tolerated",
117
+ },
118
+ risk: {
119
+ type: "string",
120
+ enum: ["low", "medium", "high"],
121
+ description: "Risk level for this step",
122
+ },
123
+ transform: {
124
+ type: "string",
125
+ description: "Template rendered after tool execution. Use $result to reference the tool output. Supports all template expressions.",
126
+ },
127
+ retry: {
128
+ type: "number",
129
+ description: "Number of times to retry this step on failure (overrides recipe-level on_error.retry)",
130
+ },
131
+ retryDelay: {
132
+ type: "number",
133
+ description: "Milliseconds to wait between retries (default 1000)",
134
+ },
135
+ };
136
+ const toolRefs = Object.keys(namespaceSchemas).map((ns) => ({
137
+ allOf: [
138
+ {
139
+ $ref: `./tools/${ns}.json`,
140
+ },
141
+ {
142
+ type: "object",
143
+ properties: {
144
+ ...chainedStepMetadataProperties,
145
+ },
146
+ },
147
+ ],
148
+ }));
149
+ const knownToolIds = listTools()
150
+ .map((tool) => tool.id)
151
+ .sort();
152
+ const chainedRecipeStep = {
153
+ type: "object",
154
+ anyOf: [{ required: ["recipe"] }, { required: ["chain"] }],
155
+ properties: {
156
+ ...chainedStepMetadataProperties,
157
+ recipe: {
158
+ type: "string",
159
+ description: "Nested recipe name or path",
160
+ },
161
+ chain: {
162
+ type: "string",
163
+ description: "Alias for nested recipe name or path",
164
+ },
165
+ vars: {
166
+ type: "object",
167
+ description: "Template variables passed into a nested recipe step",
168
+ additionalProperties: {
169
+ type: "string",
170
+ },
171
+ },
172
+ output: {
173
+ type: "string",
174
+ description: "Output key for the nested recipe result",
175
+ },
176
+ },
177
+ };
178
+ // Leaf step variants reused inside parallel: items (one level, no recursion).
179
+ const leafStepVariants = [
180
+ ...toolRefs,
181
+ {
182
+ type: "object",
183
+ required: ["agent"],
184
+ properties: {
185
+ ...chainedStepMetadataProperties,
186
+ agent: {
187
+ type: "object",
188
+ required: ["prompt"],
189
+ description: "Agent step configuration",
190
+ properties: {
191
+ prompt: { type: "string" },
192
+ model: { type: "string" },
193
+ driver: {
194
+ type: "string",
195
+ enum: [
196
+ "claude",
197
+ "claude-code",
198
+ "api",
199
+ "openai",
200
+ "grok",
201
+ "gemini",
202
+ "anthropic",
203
+ ],
204
+ },
205
+ into: { type: "string" },
206
+ },
207
+ },
208
+ },
209
+ },
210
+ {
211
+ type: "object",
212
+ required: ["tool"],
213
+ properties: {
214
+ ...chainedStepMetadataProperties,
215
+ tool: { type: "string", not: { enum: knownToolIds } },
216
+ into: { type: "string" },
217
+ },
218
+ },
219
+ chainedRecipeStep,
220
+ ];
221
+ const parallelStep = {
222
+ type: "object",
223
+ required: ["parallel"],
224
+ properties: {
225
+ id: {
226
+ type: "string",
227
+ description: "Optional group id — used as awaits target by later steps",
228
+ },
229
+ awaits: {
230
+ type: "array",
231
+ description: "Step IDs that must complete before this group starts",
232
+ items: { type: "string" },
233
+ },
234
+ parallel: {
235
+ type: "array",
236
+ description: "Run these steps concurrently. All must finish before later steps that await this group.",
237
+ items: { oneOf: leafStepVariants },
238
+ },
239
+ },
240
+ };
241
+ return {
242
+ $schema: "http://json-schema.org/draft-07/schema#",
243
+ $id: "https://patchworkos.com/schema/recipe.v1.json",
244
+ title: "Patchwork Recipe",
245
+ description: "YAML recipe schema for Patchwork automation",
246
+ // taplo formatter: auto-associates *.patchwork.yaml files
247
+ "x-taplo": {
248
+ "file-patterns": ["*.patchwork.yaml", "*.patchwork.yml"],
249
+ },
250
+ type: "object",
251
+ required: ["name", "trigger", "steps"],
252
+ properties: {
253
+ name: {
254
+ type: "string",
255
+ description: "Recipe name (kebab-case recommended)",
256
+ pattern: "^[a-z0-9-]+$",
257
+ },
258
+ description: {
259
+ type: "string",
260
+ description: "Human-readable description of what this recipe does",
261
+ },
262
+ maxConcurrency: {
263
+ type: "number",
264
+ description: "Maximum number of chained steps that may execute in parallel",
265
+ },
266
+ maxDepth: {
267
+ type: "number",
268
+ description: "Maximum nested recipe depth for chained recipes",
269
+ },
270
+ version: {
271
+ type: "string",
272
+ description: "Semantic version",
273
+ default: "1.0.0",
274
+ },
275
+ apiVersion: {
276
+ type: "string",
277
+ description: "Patchwork API version",
278
+ enum: ["patchwork.sh/v1"],
279
+ default: "patchwork.sh/v1",
280
+ },
281
+ trigger: {
282
+ type: "object",
283
+ description: "When to run this recipe",
284
+ required: ["type"],
285
+ properties: {
286
+ type: {
287
+ type: "string",
288
+ enum: [
289
+ "manual",
290
+ "cron",
291
+ "webhook",
292
+ "file_watch",
293
+ "git_hook",
294
+ "on_file_save",
295
+ "on_test_run",
296
+ "chained",
297
+ ],
298
+ description: "Trigger type",
299
+ },
300
+ at: {
301
+ type: "string",
302
+ description: "Cron expression (for cron trigger)",
303
+ },
304
+ glob: {
305
+ type: "string",
306
+ description: "File glob pattern (for file_watch trigger)",
307
+ },
308
+ on: {
309
+ type: "string",
310
+ enum: ["post-commit", "pre-push", "post-merge"],
311
+ description: "Git hook event (for git_hook trigger)",
312
+ },
313
+ filter: {
314
+ type: "string",
315
+ description: "File filter pattern (for file_watch trigger)",
316
+ },
317
+ eventSource: {
318
+ type: "string",
319
+ description: "Webhook/event source name after legacy trigger normalization",
320
+ },
321
+ eventFilter: {
322
+ oneOf: [
323
+ {
324
+ type: "string",
325
+ },
326
+ {
327
+ type: "object",
328
+ },
329
+ ],
330
+ description: "Webhook/event filter after legacy trigger normalization",
331
+ },
332
+ eventLeadTimeHours: {
333
+ type: "number",
334
+ description: "Lead time in hours after legacy trigger normalization",
335
+ },
336
+ eventLeadTimeMinutes: {
337
+ type: "number",
338
+ description: "Lead time in minutes after legacy trigger normalization",
339
+ },
340
+ legacyType: {
341
+ type: "string",
342
+ enum: ["event"],
343
+ description: "Original trigger type preserved during legacy normalization",
344
+ },
345
+ },
346
+ },
347
+ context: {
348
+ type: "array",
349
+ description: "Context blocks to load before running steps",
350
+ items: {
351
+ type: "object",
352
+ required: ["type"],
353
+ properties: {
354
+ type: {
355
+ type: "string",
356
+ enum: ["file", "env"],
357
+ },
358
+ path: { type: "string" },
359
+ keys: {
360
+ type: "array",
361
+ items: { type: "string" },
362
+ },
363
+ },
364
+ },
365
+ },
366
+ steps: {
367
+ type: "array",
368
+ description: "Sequence of steps to execute",
369
+ items: {
370
+ oneOf: [
371
+ ...toolRefs,
372
+ {
373
+ type: "object",
374
+ required: ["agent"],
375
+ properties: {
376
+ ...chainedStepMetadataProperties,
377
+ agent: {
378
+ type: "object",
379
+ required: ["prompt"],
380
+ description: "Agent step configuration",
381
+ properties: {
382
+ prompt: {
383
+ type: "string",
384
+ description: "Prompt to send to the AI (supports {{templates}})",
385
+ },
386
+ model: {
387
+ type: "string",
388
+ description: "Model to use for the agent step",
389
+ },
390
+ driver: {
391
+ type: "string",
392
+ enum: [
393
+ "claude",
394
+ "claude-code",
395
+ "api",
396
+ "openai",
397
+ "grok",
398
+ "gemini",
399
+ "anthropic",
400
+ ],
401
+ description: "Driver for agent execution",
402
+ },
403
+ into: {
404
+ type: "string",
405
+ description: "Variable name to store output in context",
406
+ },
407
+ },
408
+ },
409
+ },
410
+ },
411
+ {
412
+ type: "object",
413
+ required: ["tool"],
414
+ properties: {
415
+ ...chainedStepMetadataProperties,
416
+ tool: {
417
+ type: "string",
418
+ not: {
419
+ enum: knownToolIds,
420
+ },
421
+ },
422
+ into: {
423
+ type: "string",
424
+ },
425
+ },
426
+ },
427
+ chainedRecipeStep,
428
+ parallelStep,
429
+ ],
430
+ },
431
+ },
432
+ expect: {
433
+ type: "object",
434
+ description: "Optional assertions for mocked recipe tests",
435
+ properties: {
436
+ stepsRun: {
437
+ type: "number",
438
+ description: "Expected number of executed steps",
439
+ },
440
+ outputs: {
441
+ type: "array",
442
+ description: "Expected output paths or keys recorded by the run",
443
+ items: { type: "string" },
444
+ },
445
+ errorMessage: {
446
+ type: ["string", "null"],
447
+ description: "Expected final error message, or null for a clean run",
448
+ },
449
+ context: {
450
+ type: "object",
451
+ description: "Expected context key/value pairs after the run",
452
+ additionalProperties: { type: "string" },
453
+ },
454
+ },
455
+ },
456
+ output: {
457
+ type: "object",
458
+ description: "Output file configuration",
459
+ properties: {
460
+ path: {
461
+ type: "string",
462
+ description: "Path to write final output",
463
+ },
464
+ },
465
+ },
466
+ on_error: {
467
+ type: "object",
468
+ description: "Error handling policy",
469
+ properties: {
470
+ retry: {
471
+ type: "number",
472
+ description: "Number of retries per failing step (overridden by step.retry)",
473
+ default: 0,
474
+ },
475
+ retryDelay: {
476
+ type: "number",
477
+ description: "Milliseconds between retries (overridden by step.retryDelay)",
478
+ default: 1000,
479
+ },
480
+ fallback: {
481
+ type: "string",
482
+ enum: ["log_only", "abort", "deliver_original"],
483
+ description: "log_only / deliver_original: treat step failure as non-fatal (like optional); fail-open. abort (default): propagate failure.",
484
+ },
485
+ notify: {
486
+ type: "boolean",
487
+ description: "Reserved. yamlRunner currently posts Slack notifications on any step failure when slack is connected; gating on this flag is not yet wired.",
488
+ default: true,
489
+ },
490
+ },
491
+ },
492
+ },
493
+ };
494
+ }
495
+ /**
496
+ * Generate schema for a namespace's tools.
497
+ */
498
+ function generateNamespaceSchema(namespace) {
499
+ const tools = listTools(namespace);
500
+ const definitions = {};
501
+ const anyOf = [];
502
+ for (const tool of tools) {
503
+ const toolSchema = generateToolSchema(tool);
504
+ definitions[tool.id.replace(".", "_")] = toolSchema;
505
+ anyOf.push({ $ref: `#/definitions/${tool.id.replace(".", "_")}` });
506
+ }
507
+ return {
508
+ $schema: "http://json-schema.org/draft-07/schema#",
509
+ $id: `https://patchworkos.com/schema/tools/${namespace}.json`,
510
+ title: `${capitalize(namespace)} Tools`,
511
+ description: `Tool parameters for ${namespace} namespace`,
512
+ definitions,
513
+ anyOf,
514
+ };
515
+ }
516
+ /**
517
+ * Extract properties from tool paramsSchema, merging with base tool property.
518
+ */
519
+ function getToolProperties(tool) {
520
+ const base = {
521
+ tool: {
522
+ type: "string",
523
+ const: tool.id,
524
+ description: `Tool: ${tool.id}`,
525
+ },
526
+ };
527
+ const schema = tool.paramsSchema;
528
+ const extra = schema && typeof schema === "object" && "properties" in schema
529
+ ? schema.properties
530
+ : undefined;
531
+ return extra ? { ...base, ...extra } : base;
532
+ }
533
+ /**
534
+ * Generate schema for a single tool's parameters.
535
+ */
536
+ function generateToolSchema(tool) {
537
+ const schema = tool.paramsSchema;
538
+ const requiredFromParams = schema && typeof schema === "object" && Array.isArray(schema.required)
539
+ ? schema.required.filter((value) => typeof value === "string")
540
+ : [];
541
+ return {
542
+ type: "object",
543
+ title: tool.id,
544
+ description: tool.description,
545
+ properties: getToolProperties(tool),
546
+ required: ["tool", ...requiredFromParams],
547
+ };
548
+ }
549
+ function capitalize(s) {
550
+ return s.charAt(0).toUpperCase() + s.slice(1);
551
+ }
552
+ /**
553
+ * Write schema files to disk.
554
+ */
555
+ export async function writeSchemas(outputDir, schemas, writeFile) {
556
+ // Write main recipe schema
557
+ await writeFile(`${outputDir}/recipe.v1.json`, JSON.stringify(schemas.recipe, null, 2));
558
+ // Write dry-run plan schema
559
+ await writeFile(`${outputDir}/dry-run-plan.v1.json`, JSON.stringify(schemas.dryRunPlan, null, 2));
560
+ // Write per-namespace schemas
561
+ for (const [ns, schema] of Object.entries(schemas.namespaces)) {
562
+ await writeFile(`${outputDir}/tools/${ns}.json`, JSON.stringify(schema, null, 2));
563
+ }
564
+ }
565
+ //# sourceMappingURL=schemaGenerator.js.map
@@ -0,0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AAG,SAAS,UAAU,EAAE,OAAO,EAC/B,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAChC,CAAC;IACJ,CAAC;AACH,CAAC"}
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Template Engine — safe template resolution for recipe step outputs.
3
+ *
4
+ * Replaces the deprecated `vm2` approach with a pure AST-based evaluator.
5
+ * Supports: `{{steps.X.data}}`, `{{steps.X.data.field.subfield}}`, `{{env.Y}}`
6
+ *
7
+ * Security: No eval, no Function constructor, no VM. Just path walking.
8
+ */
9
+ export interface TemplateContext {
10
+ steps: Record<string, StepOutput>;
11
+ env: Record<string, string | undefined>;
12
+ }
13
+ export interface StepOutput {
14
+ status: "success" | "error" | "skipped";
15
+ data: unknown;
16
+ metadata?: {
17
+ startedAt: Date;
18
+ completedAt: Date;
19
+ model?: string;
20
+ tokenUsage?: number;
21
+ };
22
+ }
23
+ export interface TemplateCompileError {
24
+ type: "compile_error";
25
+ template: string;
26
+ message: string;
27
+ }
28
+ export interface TemplateEvalError {
29
+ type: "eval_error";
30
+ template: string;
31
+ path: string;
32
+ message: string;
33
+ }
34
+ export type TemplateError = TemplateCompileError | TemplateEvalError;
35
+ export interface CompiledTemplate {
36
+ readonly source: string;
37
+ readonly hasTemplates: boolean;
38
+ evaluate(context: TemplateContext): {
39
+ value: string;
40
+ } | {
41
+ error: TemplateError;
42
+ };
43
+ }
44
+ /**
45
+ * Compile a template string into an executable form.
46
+ * Parses `{{...}}` expressions once, not per-evaluation.
47
+ */
48
+ export declare function compileTemplate(template: string): CompiledTemplate;
49
+ /**
50
+ * Convenience: compile and evaluate in one call.
51
+ * Prefer pre-compilation for repeated evaluations.
52
+ */
53
+ export declare function evaluateTemplate(template: string, context: TemplateContext): {
54
+ value: string;
55
+ } | {
56
+ error: TemplateError;
57
+ };
58
+ /**
59
+ * Validate all templates in a recipe at load time.
60
+ * Returns array of errors, empty if all valid.
61
+ */
62
+ export declare function validateRecipeTemplates(templates: string[]): TemplateError[];