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,182 @@
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
+ /**
10
+ * Compile a template string into an executable form.
11
+ * Parses `{{...}}` expressions once, not per-evaluation.
12
+ */
13
+ export function compileTemplate(template) {
14
+ const parts = [];
15
+ // Match {{expression}} — non-greedy, no nesting
16
+ const regex = /\{\{([^{}]+)\}\}/g;
17
+ let lastIndex = 0;
18
+ let match;
19
+ while ((match = regex.exec(template)) !== null) {
20
+ // Add literal text before this match
21
+ if (match.index > lastIndex) {
22
+ parts.push(template.slice(lastIndex, match.index));
23
+ }
24
+ const expression = match[1]?.trim();
25
+ if (!expression)
26
+ continue;
27
+ const parsed = parseExpression(expression);
28
+ if (!parsed) {
29
+ return {
30
+ source: template,
31
+ hasTemplates: true,
32
+ evaluate: () => ({
33
+ error: {
34
+ type: "compile_error",
35
+ template,
36
+ message: `Invalid expression: ${expression}`,
37
+ },
38
+ }),
39
+ };
40
+ }
41
+ parts.push(parsed);
42
+ lastIndex = regex.lastIndex;
43
+ }
44
+ // Add remaining literal text
45
+ if (lastIndex < template.length) {
46
+ parts.push(template.slice(lastIndex));
47
+ }
48
+ return {
49
+ source: template,
50
+ hasTemplates: parts.some((p) => typeof p !== "string"),
51
+ evaluate: (context) => evaluateCompiled(parts, context),
52
+ };
53
+ }
54
+ /**
55
+ * Parse an expression like "steps.X.data.field" or "env.HOME"
56
+ * Returns null if invalid syntax.
57
+ */
58
+ function parseExpression(expr) {
59
+ const parts = expr.split(".");
60
+ if (parts.length < 2)
61
+ return null;
62
+ const root = parts[0];
63
+ const rest = parts.slice(1);
64
+ if (root === "steps" && rest.length >= 2) {
65
+ // steps.X.data or steps.X.data.field
66
+ return { path: expr, type: "step" };
67
+ }
68
+ if (root === "env" && rest.length === 1) {
69
+ // env.HOME
70
+ return { path: expr, type: "env" };
71
+ }
72
+ return null;
73
+ }
74
+ function evaluateCompiled(parts, context) {
75
+ const values = [];
76
+ for (const part of parts) {
77
+ if (typeof part === "string") {
78
+ values.push(part);
79
+ continue;
80
+ }
81
+ const result = evaluateExpression(part, context);
82
+ if ("error" in result) {
83
+ return result;
84
+ }
85
+ values.push(result.value);
86
+ }
87
+ return { value: values.join("") };
88
+ }
89
+ function evaluateExpression(expr, context) {
90
+ const parts = expr.path.split(".");
91
+ if (expr.type === "env") {
92
+ const key = parts[1];
93
+ if (!key)
94
+ return { value: "" };
95
+ const value = context.env[key];
96
+ return {
97
+ value: value ?? "",
98
+ };
99
+ }
100
+ // steps.X.data.path...
101
+ const stepId = parts[1];
102
+ const dataKey = parts[2];
103
+ const pathRest = parts.slice(3);
104
+ if (!stepId || !dataKey) {
105
+ return { value: "" };
106
+ }
107
+ const step = context.steps[stepId];
108
+ if (!step) {
109
+ return {
110
+ error: {
111
+ type: "eval_error",
112
+ template: `{{${expr.path}}}`,
113
+ path: expr.path,
114
+ message: `Step '${stepId}' not found`,
115
+ },
116
+ };
117
+ }
118
+ if (dataKey !== "data" && dataKey !== "status" && dataKey !== "metadata") {
119
+ return {
120
+ error: {
121
+ type: "eval_error",
122
+ template: `{{${expr.path}}}`,
123
+ path: expr.path,
124
+ message: `Invalid step accessor '${dataKey}', expected 'data', 'status', or 'metadata'`,
125
+ },
126
+ };
127
+ }
128
+ let value = step[dataKey];
129
+ // Walk the rest of the path
130
+ for (const key of pathRest) {
131
+ if (value === null || value === undefined) {
132
+ return { value: "" }; // Missing path resolves to empty string
133
+ }
134
+ if (Array.isArray(value)) {
135
+ const index = parseInt(key, 10);
136
+ if (Number.isNaN(index) || index < 0 || index >= value.length) {
137
+ return { value: "" };
138
+ }
139
+ value = value[index];
140
+ }
141
+ else if (typeof value === "object") {
142
+ value = value[key];
143
+ }
144
+ else {
145
+ return { value: "" };
146
+ }
147
+ }
148
+ // Serialize to string
149
+ if (value === null || value === undefined) {
150
+ return { value: "" };
151
+ }
152
+ if (typeof value === "string") {
153
+ return { value };
154
+ }
155
+ return { value: JSON.stringify(value) };
156
+ }
157
+ /**
158
+ * Convenience: compile and evaluate in one call.
159
+ * Prefer pre-compilation for repeated evaluations.
160
+ */
161
+ export function evaluateTemplate(template, context) {
162
+ return compileTemplate(template).evaluate(context);
163
+ }
164
+ /**
165
+ * Validate all templates in a recipe at load time.
166
+ * Returns array of errors, empty if all valid.
167
+ */
168
+ export function validateRecipeTemplates(templates) {
169
+ const errors = [];
170
+ for (const template of templates) {
171
+ const compiled = compileTemplate(template);
172
+ if (!compiled.hasTemplates)
173
+ continue; // literal — valid
174
+ // Probe with empty context: compile_error surfaces regardless of runtime values
175
+ const result = compiled.evaluate({ steps: {}, env: {} });
176
+ if ("error" in result && result.error.type === "compile_error") {
177
+ errors.push(result.error);
178
+ }
179
+ }
180
+ return errors;
181
+ }
182
+ //# sourceMappingURL=templateEngine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"templateEngine.js","sourceRoot":"","sources":["../../src/recipes/templateEngine.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AA0CH;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,QAAgB;IAC9C,MAAM,KAAK,GAAwD,EAAE,CAAC;IAEtE,gDAAgD;IAChD,MAAM,KAAK,GAAG,mBAAmB,CAAC;IAClC,IAAI,SAAS,GAAG,CAAC,CAAC;IAClB,IAAI,KAA6B,CAAC;IAElC,OAAO,CAAC,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;QAC/C,qCAAqC;QACrC,IAAI,KAAK,CAAC,KAAK,GAAG,SAAS,EAAE,CAAC;YAC5B,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,SAAS,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;QACrD,CAAC;QAED,MAAM,UAAU,GAAG,KAAK,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC;QACpC,IAAI,CAAC,UAAU;YAAE,SAAS;QAC1B,MAAM,MAAM,GAAG,eAAe,CAAC,UAAU,CAAC,CAAC;QAE3C,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,OAAO;gBACL,MAAM,EAAE,QAAQ;gBAChB,YAAY,EAAE,IAAI;gBAClB,QAAQ,EAAE,GAAG,EAAE,CAAC,CAAC;oBACf,KAAK,EAAE;wBACL,IAAI,EAAE,eAAe;wBACrB,QAAQ;wBACR,OAAO,EAAE,uBAAuB,UAAU,EAAE;qBAC7C;iBACF,C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;YAC/D,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC5B,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,181 @@
1
+ /**
2
+ * Tool Registry — central dispatch for recipe step tools.
3
+ *
4
+ * Replaces the switch statement in yamlRunner.ts with a declarative,
5
+ * self-describing registry that supports:
6
+ * - Schema generation for editor autocomplete
7
+ * - Dry-run / mock execution
8
+ * - Risk tier metadata for approval gates
9
+ * - Namespace isolation for connectors
10
+ */
11
+ import type { RunContext, StepDeps } from "./yamlRunner.js";
12
+ export interface ToolMetadata {
13
+ /** Unique tool identifier: "namespace.action" */
14
+ id: string;
15
+ /** Namespace for grouping: "file", "git", "github", "jira", etc. */
16
+ namespace: string;
17
+ /** Human-readable description for hover docs */
18
+ description: string;
19
+ /** JSON Schema for input parameters */
20
+ paramsSchema: unknown;
21
+ /** JSON Schema for output (enables template linting) */
22
+ outputSchema: unknown;
23
+ /** Default risk tier for approval gate decisions */
24
+ riskDefault: "low" | "medium" | "high";
25
+ /** Whether this tool performs a write/mutation (affects mock behavior and approval) */
26
+ isWrite: boolean;
27
+ /**
28
+ * Whether this tool calls an external SaaS connector (vs a local/built-in tool).
29
+ * Drives fixture-backed mocking for `recipe test` and `recipe record`.
30
+ */
31
+ isConnector?: boolean;
32
+ }
33
+ export interface ToolContext {
34
+ /** Rendered step parameters after template substitution */
35
+ params: Record<string, unknown>;
36
+ /** Original step for access to raw fields if needed */
37
+ step: Record<string, unknown>;
38
+ /** Execution context with prior step outputs */
39
+ ctx: RunContext;
40
+ /** Dependencies injected for I/O and connector access */
41
+ deps: StepDeps;
42
+ }
43
+ export type ToolExecute = (context: ToolContext) => Promise<string | null>;
44
+ export interface RegisteredTool extends ToolMetadata {
45
+ execute: ToolExecute;
46
+ }
47
+ /**
48
+ * Register a tool. Duplicate IDs throw.
49
+ */
50
+ export declare function registerTool(tool: RegisteredTool): void;
51
+ /**
52
+ * Get a tool by ID. Returns undefined if not found.
53
+ */
54
+ export declare function getTool(id: string): RegisteredTool | undefined;
55
+ /**
56
+ * Check if a tool exists.
57
+ */
58
+ export declare function hasTool(id: string): boolean;
59
+ /**
60
+ * List all registered tools, optionally filtered by namespace.
61
+ */
62
+ export declare function listTools(namespace?: string): RegisteredTool[];
63
+ /**
64
+ * Get all namespaces that have registered tools.
65
+ */
66
+ export declare function getNamespaces(): string[];
67
+ /**
68
+ * Execute a tool by ID. Throws if tool not found.
69
+ */
70
+ export declare function executeTool(id: string, context: ToolContext): Promise<string | null>;
71
+ /**
72
+ * Clear registry — primarily for testing.
73
+ */
74
+ export declare function clearRegistry(): void;
75
+ /**
76
+ * Register tools from a loaded plugin into the recipe tool registry.
77
+ *
78
+ * Plugin tools use a flat `name` (e.g. "myPrefix_doThing") rather than the
79
+ * "namespace.action" convention used by built-in tools. We derive a namespace
80
+ * from the tool name prefix and wrap the plugin handler so it satisfies
81
+ * ToolExecute.
82
+ *
83
+ * Rules:
84
+ * - If a tool with the same ID is already registered, skip it (built-ins win).
85
+ * - Errors in individual tool registration are swallowed — other tools proceed.
86
+ */
87
+ export declare function registerPluginTools(tools: Array<{
88
+ name: string;
89
+ handler: (...args: unknown[]) => Promise<unknown>;
90
+ schema: unknown;
91
+ }>): number;
92
+ /**
93
+ * Returns true if the given tool id is a registered connector-backed tool.
94
+ * Drives fixture-backed mocking decisions.
95
+ */
96
+ export declare function isConnectorTool(toolId: string): boolean;
97
+ /**
98
+ * Returns true if the given namespace has at least one registered connector tool.
99
+ */
100
+ export declare function isConnectorNamespace(namespace: string): boolean;
101
+ /**
102
+ * List all namespaces that contain at least one connector-backed tool.
103
+ */
104
+ export declare function listConnectorNamespaces(): string[];
105
+ export declare function listToolOutputContextKeys(toolId: string, intoKey: string): string[];
106
+ export declare function seedToolOutputPreviewContext(toolId: string, intoKey: string, stepId: string, ctx: Record<string, string>): void;
107
+ export declare function applyToolOutputContext(toolId: string, intoKey: string, result: string, ctx: Record<string, string>): void;
108
+ /**
109
+ * Built-in parameter schemas for common patterns.
110
+ */
111
+ export declare const CommonSchemas: {
112
+ readonly filePath: {
113
+ readonly type: "string";
114
+ readonly description: "File path (supports ~ for home directory)";
115
+ };
116
+ readonly optional: {
117
+ readonly type: "boolean";
118
+ readonly description: "If true, failure returns empty string instead of throwing";
119
+ readonly default: false;
120
+ };
121
+ readonly when: {
122
+ readonly type: "string";
123
+ readonly description: "Conditional expression evaluated before execution";
124
+ };
125
+ readonly max: {
126
+ readonly type: "number";
127
+ readonly description: "Maximum number of results to return";
128
+ readonly default: 20;
129
+ };
130
+ readonly since: {
131
+ readonly type: "string";
132
+ readonly description: "Time expression like '24h', '7d', '2026-01-01'";
133
+ readonly default: "24h";
134
+ };
135
+ readonly into: {
136
+ readonly type: "string";
137
+ readonly description: "Variable name to capture output into context";
138
+ };
139
+ };
140
+ /**
141
+ * Built-in output schemas for common patterns.
142
+ */
143
+ export declare const CommonOutputSchemas: {
144
+ readonly fileContent: {
145
+ readonly type: "string";
146
+ readonly description: "File content as string";
147
+ };
148
+ readonly fileWriteResult: {
149
+ readonly type: "object";
150
+ readonly properties: {
151
+ readonly path: {
152
+ readonly type: "string";
153
+ };
154
+ readonly bytesWritten: {
155
+ readonly type: "number";
156
+ };
157
+ };
158
+ };
159
+ readonly listResult: {
160
+ readonly type: "object";
161
+ readonly properties: {
162
+ readonly count: {
163
+ readonly type: "number";
164
+ };
165
+ readonly items: {
166
+ readonly type: "array";
167
+ };
168
+ };
169
+ };
170
+ readonly successResult: {
171
+ readonly type: "object";
172
+ readonly properties: {
173
+ readonly ok: {
174
+ readonly type: "boolean";
175
+ };
176
+ readonly error: {
177
+ readonly type: "string";
178
+ };
179
+ };
180
+ };
181
+ };
@@ -0,0 +1,300 @@
1
+ /**
2
+ * Tool Registry — central dispatch for recipe step tools.
3
+ *
4
+ * Replaces the switch statement in yamlRunner.ts with a declarative,
5
+ * self-describing registry that supports:
6
+ * - Schema generation for editor autocomplete
7
+ * - Dry-run / mock execution
8
+ * - Risk tier metadata for approval gates
9
+ * - Namespace isolation for connectors
10
+ */
11
+ /** Internal registry map */
12
+ const registry = new Map();
13
+ /**
14
+ * Register a tool. Duplicate IDs throw.
15
+ */
16
+ export function registerTool(tool) {
17
+ if (registry.has(tool.id)) {
18
+ throw new Error(`Tool "${tool.id}" is already registered`);
19
+ }
20
+ registry.set(tool.id, tool);
21
+ }
22
+ /**
23
+ * Get a tool by ID. Returns undefined if not found.
24
+ */
25
+ export function getTool(id) {
26
+ return registry.get(id);
27
+ }
28
+ /**
29
+ * Check if a tool exists.
30
+ */
31
+ export function hasTool(id) {
32
+ return registry.has(id);
33
+ }
34
+ /**
35
+ * List all registered tools, optionally filtered by namespace.
36
+ */
37
+ export function listTools(namespace) {
38
+ const tools = Array.from(registry.values());
39
+ if (!namespace)
40
+ return tools;
41
+ return tools.filter((t) => t.namespace === namespace);
42
+ }
43
+ /**
44
+ * Get all namespaces that have registered tools.
45
+ */
46
+ export function getNamespaces() {
47
+ const namespaces = new Set();
48
+ for (const tool of registry.values()) {
49
+ namespaces.add(tool.namespace);
50
+ }
51
+ return Array.from(namespaces).sort();
52
+ }
53
+ /**
54
+ * Execute a tool by ID. Throws if tool not found.
55
+ */
56
+ export async function executeTool(id, context) {
57
+ const tool = getTool(id);
58
+ if (!tool) {
59
+ throw new Error(`Unknown tool: "${id}"`);
60
+ }
61
+ return tool.execute(context);
62
+ }
63
+ /**
64
+ * Clear registry — primarily for testing.
65
+ */
66
+ export function clearRegistry() {
67
+ registry.clear();
68
+ }
69
+ /**
70
+ * Register tools from a loaded plugin into the recipe tool registry.
71
+ *
72
+ * Plugin tools use a flat `name` (e.g. "myPrefix_doThing") rather than the
73
+ * "namespace.action" convention used by built-in tools. We derive a namespace
74
+ * from the tool name prefix and wrap the plugin handler so it satisfies
75
+ * ToolExecute.
76
+ *
77
+ * Rules:
78
+ * - If a tool with the same ID is already registered, skip it (built-ins win).
79
+ * - Errors in individual tool registration are swallowed — other tools proceed.
80
+ */
81
+ export function registerPluginTools(tools) {
82
+ let registered = 0;
83
+ for (const t of tools) {
84
+ if (!t.name || hasTool(t.name))
85
+ continue;
86
+ try {
87
+ // Derive namespace from tool name: everything before the first underscore,
88
+ // or the full name if there is no underscore.
89
+ const underscoreIdx = t.name.indexOf("_");
90
+ const namespace = underscoreIdx > 0 ? t.name.slice(0, underscoreIdx) : t.name;
91
+ const execute = async (context) => {
92
+ const result = await t.handler(context.params);
93
+ if (result === null || result === undefined)
94
+ return null;
95
+ return typeof result === "string" ? result : JSON.stringify(result);
96
+ };
97
+ registerTool({
98
+ id: t.name,
99
+ namespace,
100
+ description: t.schema?.description ?? `Plugin tool: ${t.name}`,
101
+ paramsSchema: t.schema?.inputSchema ?? {},
102
+ outputSchema: {},
103
+ riskDefault: "low",
104
+ isWrite: false,
105
+ execute,
106
+ });
107
+ registered++;
108
+ }
109
+ catch {
110
+ // skip — duplicate guard in registerTool already throws, but hasTool above
111
+ // guards against that. Any other unexpected error is non-fatal.
112
+ }
113
+ }
114
+ return registered;
115
+ }
116
+ /**
117
+ * Returns true if the given tool id is a registered connector-backed tool.
118
+ * Drives fixture-backed mocking decisions.
119
+ */
120
+ export function isConnectorTool(toolId) {
121
+ return getTool(toolId)?.isConnector === true;
122
+ }
123
+ /**
124
+ * Returns true if the given namespace has at least one registered connector tool.
125
+ */
126
+ export function isConnectorNamespace(namespace) {
127
+ for (const tool of registry.values()) {
128
+ if (tool.namespace === namespace && tool.isConnector) {
129
+ return true;
130
+ }
131
+ }
132
+ return false;
133
+ }
134
+ /**
135
+ * List all namespaces that contain at least one connector-backed tool.
136
+ */
137
+ export function listConnectorNamespaces() {
138
+ const namespaces = new Set();
139
+ for (const tool of registry.values()) {
140
+ if (tool.isConnector) {
141
+ namespaces.add(tool.namespace);
142
+ }
143
+ }
144
+ return Array.from(namespaces).sort();
145
+ }
146
+ function getOutputSchemaProperties(toolId) {
147
+ const outputSchema = getTool(toolId)?.outputSchema;
148
+ if (!outputSchema ||
149
+ typeof outputSchema !== "object" ||
150
+ !("properties" in outputSchema) ||
151
+ !outputSchema.properties ||
152
+ typeof outputSchema.properties !== "object") {
153
+ return undefined;
154
+ }
155
+ return outputSchema.properties;
156
+ }
157
+ function schemaHasType(schema, expected) {
158
+ if (!schema || typeof schema !== "object" || !("type" in schema)) {
159
+ return false;
160
+ }
161
+ const type = schema.type;
162
+ if (typeof type === "string") {
163
+ return type === expected;
164
+ }
165
+ return Array.isArray(type) && type.includes(expected);
166
+ }
167
+ function getJsonAliasPropertyName(properties) {
168
+ for (const [propertyName, propertySchema] of Object.entries(properties)) {
169
+ if (propertyName === "error") {
170
+ continue;
171
+ }
172
+ if (schemaHasType(propertySchema, "array") ||
173
+ schemaHasType(propertySchema, "object")) {
174
+ return propertyName;
175
+ }
176
+ }
177
+ return undefined;
178
+ }
179
+ export function listToolOutputContextKeys(toolId, intoKey) {
180
+ const properties = getOutputSchemaProperties(toolId);
181
+ if (!properties) {
182
+ return [];
183
+ }
184
+ const keys = [];
185
+ for (const [propertyName, propertySchema] of Object.entries(properties)) {
186
+ if (schemaHasType(propertySchema, "string") ||
187
+ schemaHasType(propertySchema, "number") ||
188
+ schemaHasType(propertySchema, "boolean")) {
189
+ keys.push(`${intoKey}.${propertyName}`);
190
+ }
191
+ }
192
+ if (getJsonAliasPropertyName(properties)) {
193
+ keys.push(`${intoKey}.json`);
194
+ }
195
+ return keys;
196
+ }
197
+ export function seedToolOutputPreviewContext(toolId, intoKey, stepId, ctx) {
198
+ for (const key of listToolOutputContextKeys(toolId, intoKey)) {
199
+ const suffix = key.slice(intoKey.length + 1);
200
+ ctx[key] = `[dry-run:${stepId}.${suffix}]`;
201
+ }
202
+ }
203
+ export function applyToolOutputContext(toolId, intoKey, result, ctx) {
204
+ const properties = getOutputSchemaProperties(toolId);
205
+ if (!properties) {
206
+ return;
207
+ }
208
+ let parsed;
209
+ try {
210
+ const parsedResult = JSON.parse(result);
211
+ if (!parsedResult ||
212
+ typeof parsedResult !== "object" ||
213
+ Array.isArray(parsedResult)) {
214
+ return;
215
+ }
216
+ parsed = parsedResult;
217
+ }
218
+ catch {
219
+ return;
220
+ }
221
+ for (const [propertyName, propertySchema] of Object.entries(properties)) {
222
+ const propertyValue = parsed[propertyName];
223
+ if (propertyValue !== undefined &&
224
+ (schemaHasType(propertySchema, "string") ||
225
+ schemaHasType(propertySchema, "number") ||
226
+ schemaHasType(propertySchema, "boolean")) &&
227
+ (typeof propertyValue === "string" ||
228
+ typeof propertyValue === "number" ||
229
+ typeof propertyValue === "boolean")) {
230
+ ctx[`${intoKey}.${propertyName}`] = String(propertyValue);
231
+ }
232
+ }
233
+ const jsonAliasProperty = getJsonAliasPropertyName(properties);
234
+ if (jsonAliasProperty && parsed[jsonAliasProperty] !== undefined) {
235
+ ctx[`${intoKey}.json`] = JSON.stringify(parsed[jsonAliasProperty]);
236
+ }
237
+ }
238
+ /**
239
+ * Built-in parameter schemas for common patterns.
240
+ */
241
+ export const CommonSchemas = {
242
+ filePath: {
243
+ type: "string",
244
+ description: "File path (supports ~ for home directory)",
245
+ },
246
+ optional: {
247
+ type: "boolean",
248
+ description: "If true, failure returns empty string instead of throwing",
249
+ default: false,
250
+ },
251
+ when: {
252
+ type: "string",
253
+ description: "Conditional expression evaluated before execution",
254
+ },
255
+ max: {
256
+ type: "number",
257
+ description: "Maximum number of results to return",
258
+ default: 20,
259
+ },
260
+ since: {
261
+ type: "string",
262
+ description: "Time expression like '24h', '7d', '2026-01-01'",
263
+ default: "24h",
264
+ },
265
+ into: {
266
+ type: "string",
267
+ description: "Variable name to capture output into context",
268
+ },
269
+ };
270
+ /**
271
+ * Built-in output schemas for common patterns.
272
+ */
273
+ export const CommonOutputSchemas = {
274
+ fileContent: {
275
+ type: "string",
276
+ description: "File content as string",
277
+ },
278
+ fileWriteResult: {
279
+ type: "object",
280
+ properties: {
281
+ path: { type: "string" },
282
+ bytesWritten: { type: "number" },
283
+ },
284
+ },
285
+ listResult: {
286
+ type: "object",
287
+ properties: {
288
+ count: { type: "number" },
289
+ items: { type: "array" },
290
+ },
291
+ },
292
+ successResult: {
293
+ type: "object",
294
+ properties: {
295
+ ok: { type: "boolean" },
296
+ error: { type: "string" },
297
+ },
298
+ },
299
+ };
300
+ //# sourceMappingURL=toolRegistry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toolRegistry.js","sourceRoot":"","sources":["../../src/recipes/toolRegistry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AA2CH,4BAA4B;AAC5B,MAAM,QAAQ,GAAG,IAAI,GAAG,EAA0B,CAAC;AAEnD;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,IAAoB;IAC/C,IAAI,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,SAAS,IAAI,CAAC,EAAE,yBAAyB,CAAC,CAAC;IAC7D,CAAC;IACD,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;AAC9B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,OAAO,CAAC,EAAU;IAChC,OAAO,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;AAC1B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,OAAO,CAAC,EAAU;IAChC,OAAO,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;AAC1B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,SAAS,CAAC,SAAkB;IAC1C,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;IAC5C,IAAI,CAAC,SAAS;QAAE,OAAO,KAAK,CAAC;IAC7B,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC;AACxD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU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