@leitwerk-dev/process-sdk 0.1.9 → 0.2.1

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 (256) hide show
  1. package/dist/browser-ui-extension.d.ts +20 -0
  2. package/dist/browser-ui-extension.d.ts.map +1 -1
  3. package/dist/capabilities.d.ts +6 -0
  4. package/dist/capabilities.d.ts.map +1 -1
  5. package/dist/{chunk-LIIP7FMU.js → chunk-5R6MVLHC.js} +1 -1
  6. package/dist/chunk-5R6MVLHC.js.map +1 -0
  7. package/dist/chunk-DVXW2ZUV.js +1 -0
  8. package/dist/chunk-DVXW2ZUV.js.map +1 -0
  9. package/dist/{chunk-TRQJ5PRM.js → chunk-I7U6HCLN.js} +1 -11
  10. package/dist/chunk-I7U6HCLN.js.map +1 -0
  11. package/dist/{chunk-5RJZ2E7D.js → chunk-TM2LTSW4.js} +2 -6
  12. package/dist/chunk-TM2LTSW4.js.map +1 -0
  13. package/dist/codecs.d.ts +1 -0
  14. package/dist/codecs.d.ts.map +1 -1
  15. package/dist/commit-message.d.ts +5 -0
  16. package/dist/commit-message.d.ts.map +1 -1
  17. package/dist/core-capabilities.d.ts +396 -44
  18. package/dist/core-capabilities.d.ts.map +1 -1
  19. package/dist/define-process.d.ts +209 -64
  20. package/dist/define-process.d.ts.map +1 -1
  21. package/dist/event-bus.d.ts +1 -0
  22. package/dist/event-bus.d.ts.map +1 -1
  23. package/dist/{extension-api-BBcwktmc.d.ts → extension-api-B4gG5w1K.d.ts} +1111 -153
  24. package/dist/extension-api.d.ts +481 -38
  25. package/dist/extension-api.d.ts.map +1 -1
  26. package/dist/external-action-source.d.ts +9 -0
  27. package/dist/external-action-source.d.ts.map +1 -0
  28. package/dist/external-source-poll.d.ts +22 -0
  29. package/dist/external-source-poll.d.ts.map +1 -0
  30. package/dist/flow.d.ts +380 -107
  31. package/dist/flow.d.ts.map +1 -1
  32. package/dist/form-contract.d.ts +1 -1
  33. package/dist/form-contract.d.ts.map +1 -1
  34. package/dist/fs-utils.d.ts +6 -0
  35. package/dist/fs-utils.d.ts.map +1 -1
  36. package/dist/git-binary.d.ts +2 -1
  37. package/dist/git-binary.d.ts.map +1 -1
  38. package/dist/git-binary.js +25 -33
  39. package/dist/git-binary.js.map +1 -1
  40. package/dist/graph-fragments.d.ts +16 -0
  41. package/dist/graph-fragments.d.ts.map +1 -1
  42. package/dist/host-capabilities.d.ts +9 -3
  43. package/dist/host-capabilities.d.ts.map +1 -1
  44. package/dist/index.d.ts +40 -29
  45. package/dist/index.d.ts.map +1 -1
  46. package/dist/index.js +4876 -29
  47. package/dist/index.js.map +1 -1
  48. package/dist/integration-http.d.ts +32 -0
  49. package/dist/integration-http.d.ts.map +1 -0
  50. package/dist/json-data.d.ts +3 -0
  51. package/dist/json-data.d.ts.map +1 -0
  52. package/dist/leaf-outcome-renderer.d.ts +35 -0
  53. package/dist/leaf-outcome-renderer.d.ts.map +1 -1
  54. package/dist/leaf-outcome-renderer.js +86 -64
  55. package/dist/leaf-outcome-renderer.js.map +1 -1
  56. package/dist/leaf-outcomes.d.ts +3 -0
  57. package/dist/leaf-outcomes.d.ts.map +1 -1
  58. package/dist/model-provider.d.ts +144 -12
  59. package/dist/model-provider.d.ts.map +1 -1
  60. package/dist/pi-config-public.d.ts +2 -0
  61. package/dist/pi-config-public.d.ts.map +1 -0
  62. package/dist/pi-config-public.js +15 -0
  63. package/dist/pi-config-public.js.map +1 -0
  64. package/dist/pi-config.d.ts +41 -5
  65. package/dist/pi-config.d.ts.map +1 -1
  66. package/dist/pi-config.js +20 -180
  67. package/dist/pi-config.js.map +1 -1
  68. package/dist/process-definition-internals.d.ts +4 -0
  69. package/dist/process-definition-internals.d.ts.map +1 -1
  70. package/dist/process-flow-view.d.ts +2 -0
  71. package/dist/process-flow-view.d.ts.map +1 -1
  72. package/dist/process-graph.d.ts +34 -0
  73. package/dist/process-graph.d.ts.map +1 -1
  74. package/dist/process-launcher-builder.d.ts +5 -0
  75. package/dist/process-launcher-builder.d.ts.map +1 -1
  76. package/dist/process-watcher-builder.d.ts +5 -0
  77. package/dist/process-watcher-builder.d.ts.map +1 -1
  78. package/dist/process-watcher-source.d.ts +3 -1
  79. package/dist/process-watcher-source.d.ts.map +1 -1
  80. package/dist/project-binding.d.ts +13 -0
  81. package/dist/project-binding.d.ts.map +1 -0
  82. package/dist/registry-utils.d.ts +6 -0
  83. package/dist/registry-utils.d.ts.map +1 -1
  84. package/dist/repository-feedback.d.ts +47 -0
  85. package/dist/repository-feedback.d.ts.map +1 -0
  86. package/dist/repository-git-env.d.ts +8 -2
  87. package/dist/repository-git-env.d.ts.map +1 -1
  88. package/dist/repository-http.d.ts +31 -0
  89. package/dist/repository-http.d.ts.map +1 -0
  90. package/dist/repository-https.d.ts +3 -0
  91. package/dist/repository-https.d.ts.map +1 -0
  92. package/dist/repository-issue-watcher.d.ts +51 -0
  93. package/dist/repository-issue-watcher.d.ts.map +1 -0
  94. package/dist/repository-reconciliation.d.ts +5 -0
  95. package/dist/repository-reconciliation.d.ts.map +1 -0
  96. package/dist/repository-source-config.d.ts +58 -0
  97. package/dist/repository-source-config.d.ts.map +1 -0
  98. package/dist/repository-types.d.ts +63 -0
  99. package/dist/repository-types.d.ts.map +1 -0
  100. package/dist/review-flow-public.d.ts +2 -0
  101. package/dist/review-flow-public.d.ts.map +1 -0
  102. package/dist/review-flow-public.js +11 -0
  103. package/dist/review-flow-public.js.map +1 -0
  104. package/dist/review-flow.d.ts +6 -0
  105. package/dist/review-flow.d.ts.map +1 -1
  106. package/dist/review-flow.js +12 -43
  107. package/dist/review-flow.js.map +1 -1
  108. package/dist/runtime-internals-public.d.ts +2 -0
  109. package/dist/runtime-internals-public.d.ts.map +1 -0
  110. package/dist/runtime-internals-public.js +16 -0
  111. package/dist/runtime-internals-public.js.map +1 -0
  112. package/dist/runtime-internals.js +19 -2
  113. package/dist/runtime-internals.js.map +1 -1
  114. package/dist/server-events.d.ts +67 -0
  115. package/dist/server-events.d.ts.map +1 -1
  116. package/dist/server-process-builder.d.ts +7 -0
  117. package/dist/server-process-builder.d.ts.map +1 -1
  118. package/dist/state-helpers.d.ts +8 -0
  119. package/dist/state-helpers.d.ts.map +1 -1
  120. package/dist/subprocess-env.d.ts +4 -0
  121. package/dist/subprocess-env.d.ts.map +1 -1
  122. package/dist/tool-arguments.d.ts +9 -0
  123. package/dist/tool-arguments.d.ts.map +1 -0
  124. package/dist/tool-renderers.d.ts +6 -0
  125. package/dist/tool-renderers.d.ts.map +1 -1
  126. package/dist/turn-semantics.d.ts +18 -6
  127. package/dist/turn-semantics.d.ts.map +1 -1
  128. package/dist/types.d.ts +209 -38
  129. package/dist/types.d.ts.map +1 -1
  130. package/dist/ui-process-builder.d.ts +5 -0
  131. package/dist/ui-process-builder.d.ts.map +1 -1
  132. package/dist/worker-process-builder.d.ts +5 -0
  133. package/dist/worker-process-builder.d.ts.map +1 -1
  134. package/package.json +17 -15
  135. package/src/browser-ui-extension.ts +20 -0
  136. package/src/capabilities.ts +9 -1
  137. package/src/codecs.ts +1 -0
  138. package/src/commit-message.ts +5 -0
  139. package/src/core-capabilities.ts +464 -59
  140. package/src/define-process.ts +384 -332
  141. package/src/event-bus.ts +1 -0
  142. package/src/extension-api.ts +521 -41
  143. package/src/external-action-source.ts +17 -0
  144. package/src/external-source-poll.ts +61 -0
  145. package/src/flow.ts +674 -677
  146. package/src/form-contract.ts +0 -4
  147. package/src/fs-utils.ts +21 -2
  148. package/src/git-binary.ts +2 -1
  149. package/src/graph-fragments.ts +16 -0
  150. package/src/host-capabilities.ts +9 -6
  151. package/src/index.ts +51 -206
  152. package/src/integration-http.ts +70 -0
  153. package/src/json-data.ts +25 -0
  154. package/src/leaf-outcome-renderer.ts +35 -0
  155. package/src/leaf-outcomes.ts +4 -9
  156. package/src/model-provider.ts +179 -43
  157. package/src/pi-config-public.ts +7 -0
  158. package/src/pi-config.ts +48 -8
  159. package/src/process-definition-internals.ts +4 -0
  160. package/src/process-flow-view.ts +34 -88
  161. package/src/process-graph.ts +59 -51
  162. package/src/process-launcher-builder.ts +5 -0
  163. package/src/process-watcher-builder.ts +5 -0
  164. package/src/process-watcher-source.ts +9 -10
  165. package/src/project-binding.ts +40 -0
  166. package/src/registry-utils.ts +7 -5
  167. package/src/repository-feedback.ts +85 -0
  168. package/src/repository-git-env.ts +40 -2
  169. package/src/repository-http.ts +88 -0
  170. package/src/repository-https.ts +22 -0
  171. package/src/repository-issue-watcher.ts +122 -0
  172. package/src/repository-reconciliation.ts +30 -0
  173. package/src/repository-source-config.ts +79 -0
  174. package/src/repository-types.ts +63 -0
  175. package/src/review-flow-public.ts +5 -0
  176. package/src/review-flow.ts +6 -0
  177. package/src/runtime-internals-public.ts +7 -0
  178. package/src/server-events.ts +67 -0
  179. package/src/server-process-builder.ts +10 -1
  180. package/src/state-helpers.ts +14 -4
  181. package/src/subprocess-env.ts +9 -0
  182. package/src/tool-arguments.ts +39 -0
  183. package/src/tool-renderers.ts +6 -0
  184. package/src/turn-semantics.ts +45 -76
  185. package/src/types.ts +216 -44
  186. package/src/ui-process-builder.ts +8 -1
  187. package/src/worker-process-builder.ts +8 -1
  188. package/dist/browser-ui-extension.js +0 -2
  189. package/dist/browser-ui-extension.js.map +0 -1
  190. package/dist/capabilities.js +0 -7
  191. package/dist/capabilities.js.map +0 -1
  192. package/dist/chunk-5RJZ2E7D.js.map +0 -1
  193. package/dist/chunk-LIIP7FMU.js.map +0 -1
  194. package/dist/chunk-TRQJ5PRM.js.map +0 -1
  195. package/dist/codecs.js +0 -9
  196. package/dist/codecs.js.map +0 -1
  197. package/dist/commit-message.js +0 -3
  198. package/dist/commit-message.js.map +0 -1
  199. package/dist/core-capabilities.js +0 -6
  200. package/dist/core-capabilities.js.map +0 -1
  201. package/dist/define-process.js +0 -1078
  202. package/dist/define-process.js.map +0 -1
  203. package/dist/event-bus.js +0 -31
  204. package/dist/event-bus.js.map +0 -1
  205. package/dist/extension-api.js +0 -5
  206. package/dist/extension-api.js.map +0 -1
  207. package/dist/flow.js +0 -1645
  208. package/dist/flow.js.map +0 -1
  209. package/dist/form-contract.js +0 -2
  210. package/dist/form-contract.js.map +0 -1
  211. package/dist/fs-utils.js +0 -23
  212. package/dist/fs-utils.js.map +0 -1
  213. package/dist/graph-fragments.js +0 -57
  214. package/dist/graph-fragments.js.map +0 -1
  215. package/dist/host-capabilities.js +0 -42
  216. package/dist/host-capabilities.js.map +0 -1
  217. package/dist/launcher-contract.js +0 -2
  218. package/dist/launcher-contract.js.map +0 -1
  219. package/dist/leaf-outcomes.js +0 -52
  220. package/dist/leaf-outcomes.js.map +0 -1
  221. package/dist/model-provider.js +0 -171
  222. package/dist/model-provider.js.map +0 -1
  223. package/dist/process-definition-internals.js +0 -25
  224. package/dist/process-definition-internals.js.map +0 -1
  225. package/dist/process-flow-view.js +0 -418
  226. package/dist/process-flow-view.js.map +0 -1
  227. package/dist/process-graph.js +0 -212
  228. package/dist/process-graph.js.map +0 -1
  229. package/dist/process-launcher-builder.js +0 -43
  230. package/dist/process-launcher-builder.js.map +0 -1
  231. package/dist/process-watcher-builder.js +0 -40
  232. package/dist/process-watcher-builder.js.map +0 -1
  233. package/dist/process-watcher-source.js +0 -52
  234. package/dist/process-watcher-source.js.map +0 -1
  235. package/dist/registry-utils.js +0 -18
  236. package/dist/registry-utils.js.map +0 -1
  237. package/dist/repository-git-env.js +0 -26
  238. package/dist/repository-git-env.js.map +0 -1
  239. package/dist/server-events.js +0 -2
  240. package/dist/server-events.js.map +0 -1
  241. package/dist/server-process-builder.js +0 -52
  242. package/dist/server-process-builder.js.map +0 -1
  243. package/dist/state-helpers.js +0 -18
  244. package/dist/state-helpers.js.map +0 -1
  245. package/dist/subprocess-env.js +0 -34
  246. package/dist/subprocess-env.js.map +0 -1
  247. package/dist/tool-renderers.js +0 -63
  248. package/dist/tool-renderers.js.map +0 -1
  249. package/dist/turn-semantics.js +0 -365
  250. package/dist/turn-semantics.js.map +0 -1
  251. package/dist/types.js +0 -23
  252. package/dist/types.js.map +0 -1
  253. package/dist/ui-process-builder.js +0 -30
  254. package/dist/ui-process-builder.js.map +0 -1
  255. package/dist/worker-process-builder.js +0 -22
  256. package/dist/worker-process-builder.js.map +0 -1
@@ -0,0 +1,85 @@
1
+ import { asUnknownRecord } from "@leitwerk-dev/domain";
2
+
3
+ /** @public */
4
+ export interface RepositoryFeedbackItem {
5
+ /** @public */
6
+ kind: "conversation" | "review" | "inline";
7
+ /** @internal */
8
+ id: number;
9
+ /** @public */
10
+ body: string;
11
+ /** @internal */
12
+ createdAt: string;
13
+ /** @public */
14
+ author: string;
15
+ /** @internal */
16
+ path?: string;
17
+ /** @internal */
18
+ line?: number | null;
19
+ }
20
+
21
+ /** Batch already-authorized, unseen feedback after its quiet period. @internal */
22
+ export function repositoryFeedbackBatch(
23
+ unseen: readonly RepositoryFeedbackItem[],
24
+ config: Record<`${RepositoryFeedbackItem["kind"]}Cursor`, number> & {
25
+ /** @internal */
26
+ quietPeriodMs: number;
27
+ },
28
+ now: number,
29
+ ) {
30
+ if (!unseen.length) return null;
31
+ const latest = Math.max(...unseen.map((item) => Date.parse(item.createdAt) || 0));
32
+ if (now - latest < config.quietPeriodMs) return null;
33
+ const cursors = {
34
+ /** @internal */
35
+ conversationCursor: config.conversationCursor,
36
+ /** @internal */
37
+ reviewCursor: config.reviewCursor,
38
+ /** @internal */
39
+ inlineCursor: config.inlineCursor,
40
+ };
41
+ for (const item of unseen) {
42
+ const key = `${item.kind}Cursor` as const;
43
+ cursors[key] = Math.max(cursors[key], item.id);
44
+ }
45
+ return {
46
+ /** @internal */
47
+ event: {
48
+ /** @internal */
49
+ feedbackIds: unseen.map(({ kind, id }) => ({
50
+ /** @internal */
51
+ kind,
52
+ /** @internal */
53
+ id,
54
+ })),
55
+ /** @internal */
56
+ cursors,
57
+ },
58
+ /** @internal */
59
+ mergeKey: `${cursors.conversationCursor}:${cursors.reviewCursor}:${cursors.inlineCursor}`,
60
+ };
61
+ }
62
+
63
+ /** Normalize common forge feedback fields; reject empty bodies and missing identities. @internal */
64
+ export function normalizeRepositoryFeedback(
65
+ kind: RepositoryFeedbackItem["kind"],
66
+ item: Record<string, unknown>,
67
+ ): RepositoryFeedbackItem | null {
68
+ const body = typeof item.body === "string" ? item.body.trim() : "";
69
+ const user = asUnknownRecord(item.user) ?? {};
70
+ if (!body || typeof item.id !== "number" || typeof user.login !== "string") return null;
71
+ return {
72
+ kind,
73
+ id: item.id,
74
+ body,
75
+ createdAt:
76
+ typeof item.submitted_at === "string"
77
+ ? item.submitted_at
78
+ : typeof item.created_at === "string"
79
+ ? item.created_at
80
+ : new Date(0).toISOString(),
81
+ author: user.login,
82
+ ...(typeof item.path === "string" ? { path: item.path } : {}),
83
+ ...(typeof item.line === "number" ? { line: item.line } : {}),
84
+ };
85
+ }
@@ -1,4 +1,5 @@
1
1
  import {
2
+ INTERNAL_REPOSITORY_GIT_HTTPS_ENV_PREFIX,
2
3
  INTERNAL_REPOSITORY_GIT_SSH_ENV_PREFIX,
3
4
  type SubprocessEnvInput,
4
5
  sanitizeWorkerSubprocessEnv,
@@ -8,18 +9,32 @@ function wrapperKey(projectKey: string): string {
8
9
  return `${INTERNAL_REPOSITORY_GIT_SSH_ENV_PREFIX}${encodeURIComponent(projectKey).replace(/%/g, "_")}`;
9
10
  }
10
11
 
11
- /** Worker-internal registration; the wrapper path is never copied to ordinary subprocesses. */
12
+ /** Worker-internal registration; the wrapper path is never copied to ordinary subprocesses. @internal */
12
13
  export function setRepositoryGitSshWrapper(projectKey: string, wrapperPath: string): void {
13
14
  process.env[wrapperKey(projectKey)] = wrapperPath;
14
15
  }
15
16
 
17
+ /** @internal */
16
18
  export function clearRepositoryGitSshWrappers(): void {
17
19
  for (const key of Object.keys(process.env)) {
18
20
  if (key.startsWith(INTERNAL_REPOSITORY_GIT_SSH_ENV_PREFIX)) delete process.env[key];
19
21
  }
20
22
  }
21
23
 
22
- /** Safe environment for a trusted Git invocation for one process project. */
24
+ /** @internal */
25
+ export function setRepositoryGitHttpsHelper(projectKey: string, helperPath: string): void {
26
+ process.env[`${INTERNAL_REPOSITORY_GIT_HTTPS_ENV_PREFIX}${encodeURIComponent(projectKey)}`] =
27
+ helperPath;
28
+ }
29
+
30
+ /** @internal */
31
+ export function clearRepositoryGitHttpsHelpers(): void {
32
+ for (const key of Object.keys(process.env)) {
33
+ if (key.startsWith(INTERNAL_REPOSITORY_GIT_HTTPS_ENV_PREFIX)) delete process.env[key];
34
+ }
35
+ }
36
+
37
+ /** Safe environment for a trusted Git invocation for one process project. @public */
23
38
  export function repositoryGitSubprocessEnv(
24
39
  projectKey: string,
25
40
  overrides: SubprocessEnvInput = {},
@@ -27,9 +42,32 @@ export function repositoryGitSubprocessEnv(
27
42
  const env = sanitizeWorkerSubprocessEnv(process.env, overrides);
28
43
  const wrapper = process.env[wrapperKey(projectKey)];
29
44
  if (wrapper) env.GIT_SSH = wrapper;
45
+ const helper =
46
+ process.env[`${INTERNAL_REPOSITORY_GIT_HTTPS_ENV_PREFIX}${encodeURIComponent(projectKey)}`];
47
+ if (helper) {
48
+ const config = [
49
+ ["credential.helper", ""],
50
+ ["credential.helper", `!${shellQuote(process.execPath)} ${shellQuote(helper)}`],
51
+ ["credential.useHttpPath", "true"],
52
+ ["http.followRedirects", "false"],
53
+ ["protocol.allow", "never"],
54
+ ["protocol.https.allow", "always"],
55
+ ];
56
+ env.GIT_CONFIG_COUNT = String(config.length);
57
+ config.forEach(([key, value], index) => {
58
+ env[`GIT_CONFIG_KEY_${index}`] = key;
59
+ env[`GIT_CONFIG_VALUE_${index}`] = value;
60
+ });
61
+ env.GIT_TERMINAL_PROMPT = "0";
62
+ }
30
63
  return env;
31
64
  }
32
65
 
66
+ /** @public */
33
67
  export function repositoryGitArgs(args: readonly string[]): string[] {
34
68
  return ["-c", "core.hooksPath=/dev/null", ...args];
35
69
  }
70
+
71
+ function shellQuote(value: string): string {
72
+ return "'" + value.replaceAll("'", "'\"'\"'") + "'";
73
+ }
@@ -0,0 +1,88 @@
1
+ import { IntegrationHttpClient } from "./integration-http.js";
2
+ import type { RepositoryIssue, RepositoryPullRequest } from "./repository-types.js";
3
+
4
+ /** Common forge endpoints; extensions retain authentication and specialized operations. @public */
5
+ export class RepositoryHttpClient<Comment = Record<string, unknown>> extends IntegrationHttpClient {
6
+ /** @internal */
7
+ protected repositoryPath(owner: string, repo: string): string {
8
+ return `/repos/${owner}/${repo}`;
9
+ }
10
+
11
+ /** @internal */
12
+ getIssue(owner: string, repo: string, number: number, signal?: AbortSignal) {
13
+ return this.request<RepositoryIssue>(`${this.repositoryPath(owner, repo)}/issues/${number}`, {
14
+ signal,
15
+ });
16
+ }
17
+
18
+ /** @public */
19
+ listIssueComments(owner: string, repo: string, number: number, signal?: AbortSignal) {
20
+ return this.pages<Comment>(
21
+ `${this.repositoryPath(owner, repo)}/issues/${number}/comments`,
22
+ signal,
23
+ );
24
+ }
25
+
26
+ /** @public */
27
+ addIssueComment(owner: string, repo: string, number: number, body: string, signal?: AbortSignal) {
28
+ return this.writeJson(
29
+ `${this.repositoryPath(owner, repo)}/issues/${number}/comments`,
30
+ "POST",
31
+ { body },
32
+ signal,
33
+ );
34
+ }
35
+
36
+ /** @public */
37
+ createPullRequest(
38
+ owner: string,
39
+ repo: string,
40
+ input: {
41
+ /** @public */
42
+ title: string;
43
+ /** @public */
44
+ body: string;
45
+ /** @public */
46
+ head: string;
47
+ /** @public */
48
+ base: string;
49
+ },
50
+ ) {
51
+ return this.writeJson<RepositoryPullRequest>(
52
+ `${this.repositoryPath(owner, repo)}/pulls`,
53
+ "POST",
54
+ input,
55
+ );
56
+ }
57
+
58
+ /** @public */
59
+ getPullRequest(owner: string, repo: string, number: number, signal?: AbortSignal) {
60
+ return this.request<RepositoryPullRequest>(
61
+ `${this.repositoryPath(owner, repo)}/pulls/${number}`,
62
+ { signal },
63
+ );
64
+ }
65
+
66
+ /** @internal */
67
+ listPullRequests(owner: string, repo: string, state = "open") {
68
+ return this.pages<RepositoryPullRequest>(
69
+ `${this.repositoryPath(owner, repo)}/pulls?state=${encodeURIComponent(state)}`,
70
+ );
71
+ }
72
+
73
+ /** @public */
74
+ updatePullRequest(
75
+ owner: string,
76
+ repo: string,
77
+ number: number,
78
+ patch: Record<string, unknown>,
79
+ signal?: AbortSignal,
80
+ ) {
81
+ return this.writeJson<RepositoryPullRequest>(
82
+ `${this.repositoryPath(owner, repo)}/pulls/${number}`,
83
+ "PATCH",
84
+ patch,
85
+ signal,
86
+ );
87
+ }
88
+ }
@@ -0,0 +1,22 @@
1
+ /** Canonical, credential-free HTTPS repository URL. Reject ambiguous Git credential paths. @internal */
2
+ export function repositoryHttpsUrl(value: string): URL {
3
+ let url: URL;
4
+ try {
5
+ url = new URL(value);
6
+ } catch {
7
+ throw new Error("Repository authentication requires a valid HTTPS URL");
8
+ }
9
+ if (
10
+ url.protocol !== "https:" ||
11
+ url.username ||
12
+ url.password ||
13
+ url.search ||
14
+ url.hash ||
15
+ !url.pathname.slice(1) ||
16
+ /[%\\\s]/.test(url.pathname) ||
17
+ url.pathname.split("/").some((part) => part === "." || part === "..") ||
18
+ url.href !== value
19
+ )
20
+ throw new Error("Repository authentication requires a canonical credential-free HTTPS URL");
21
+ return url;
22
+ }
@@ -0,0 +1,122 @@
1
+ import { parseDurationMs } from "@leitwerk-dev/watcher-utils";
2
+ import { parseProcessWatcherLaunchModelConfig } from "./process-watcher-source.js";
3
+ import { objectArg } from "./tool-arguments.js";
4
+
5
+ /** @public */
6
+ export interface RepositoryIssueWatcherConfig {
7
+ /** @internal */
8
+ profile: string;
9
+ /** @internal */
10
+ pollInterval: string;
11
+ /** @internal */
12
+ repositories: {
13
+ /** @internal */
14
+ include: readonly string[];
15
+ /** @internal */
16
+ exclude: readonly string[];
17
+ };
18
+ /** @internal */
19
+ labels: {
20
+ /** @internal */
21
+ trigger: string;
22
+ /** @internal */
23
+ done: string;
24
+ };
25
+ }
26
+
27
+ /** @internal */
28
+ export function matchesRepository(
29
+ config: Pick<RepositoryIssueWatcherConfig, "repositories">,
30
+ repository: {
31
+ /** @internal */
32
+ full_name: string;
33
+ },
34
+ ): boolean {
35
+ const { include = [], exclude = [] } = config.repositories ?? {};
36
+ return (
37
+ !exclude.includes(repository.full_name) &&
38
+ (include.length === 0 || include.includes(repository.full_name))
39
+ );
40
+ }
41
+
42
+ const record = (value: unknown, subject: string) =>
43
+ objectArg(value, `${subject} must be an object`);
44
+
45
+ function nonEmptyString(value: unknown, path: string): string {
46
+ if (typeof value !== "string" || value.trim() === "")
47
+ throw new Error(`${path} must be a non-empty string`);
48
+ return value.trim();
49
+ }
50
+
51
+ function repositoryNames(value: unknown, path: string): readonly string[] {
52
+ if (value === undefined) return [];
53
+ if (!Array.isArray(value)) throw new Error(`${path} must be an array`);
54
+ return value.map((candidate, index) => {
55
+ const name = nonEmptyString(candidate, `${path}[${index}]`);
56
+ if (!/^[^/\s]+\/[^/\s]+$/.test(name))
57
+ throw new Error(`${path}[${index}] must use owner/name format`);
58
+ return name;
59
+ });
60
+ }
61
+
62
+ /** Parse shared issue watcher fields; extensions choose the legacy type and label policy. @internal */
63
+ export function parseRepositoryIssueWatcherConfig(
64
+ raw: unknown,
65
+ legacyType: string,
66
+ distinctLabels = false,
67
+ ) {
68
+ const config = record(raw, "watcher config");
69
+ if (config.type !== undefined && config.type !== legacyType)
70
+ throw new Error(`type must be '${legacyType}' when specified`);
71
+ if (typeof config.enabled !== "boolean") throw new Error("enabled must be a boolean");
72
+ const pollInterval = nonEmptyString(config.poll_interval, "poll_interval");
73
+ if (parseDurationMs(pollInterval, -1, { allowHours: true }) <= 0)
74
+ throw new Error("poll_interval must be a positive duration");
75
+ const labels = record(config.labels, "labels");
76
+ const repositories =
77
+ config.repositories === undefined ? {} : record(config.repositories, "repositories");
78
+ const parsed: RepositoryIssueWatcherConfig = {
79
+ profile: nonEmptyString(config.profile, "profile"),
80
+ pollInterval,
81
+ repositories: {
82
+ include: repositoryNames(repositories.include, "repositories.include"),
83
+ exclude: repositoryNames(repositories.exclude, "repositories.exclude"),
84
+ },
85
+ labels: {
86
+ trigger: nonEmptyString(labels.trigger, "labels.trigger"),
87
+ done: nonEmptyString(labels.done, "labels.done"),
88
+ },
89
+ };
90
+ if (distinctLabels && parsed.labels.trigger === parsed.labels.done)
91
+ throw new Error("Trigger and done labels must differ");
92
+ return {
93
+ /** @internal */
94
+ config: parsed,
95
+ /** @internal */
96
+ enabled: config.enabled,
97
+ /** @internal */
98
+ launchModelConfig: parseProcessWatcherLaunchModelConfig(config.launch),
99
+ };
100
+ }
101
+
102
+ /** @internal */
103
+ export function presentRepositoryIssueWatcherConfig(config: RepositoryIssueWatcherConfig) {
104
+ return {
105
+ /** @internal */
106
+ targetSummary: `Profile ${config.profile} · trigger ${config.labels.trigger}`,
107
+ /** @internal */
108
+ details: [
109
+ {
110
+ /** @internal */
111
+ label: "Profile",
112
+ /** @internal */
113
+ value: config.profile,
114
+ },
115
+ { label: "Included repositories", value: config.repositories.include.join(", ") || "all" },
116
+ { label: "Excluded repositories", value: config.repositories.exclude.join(", ") || "none" },
117
+ { label: "Trigger label", value: config.labels.trigger },
118
+ { label: "Done label", value: config.labels.done },
119
+ { label: "Poll interval", value: config.pollInterval },
120
+ ],
121
+ };
122
+ }
@@ -0,0 +1,30 @@
1
+ import { IntegrationHttpError } from "./integration-http.js";
2
+
3
+ /** @internal */
4
+ export async function existingObject<T>(read: () => Promise<T>): Promise<T | null> {
5
+ try {
6
+ return await read();
7
+ } catch (error) {
8
+ if (error instanceof IntegrationHttpError && error.status === 404) return null;
9
+ throw error;
10
+ }
11
+ }
12
+
13
+ /** @internal */
14
+ export function matchesPatch(current: object, patch: Record<string, unknown>): boolean {
15
+ const fields = current as Record<string, unknown>;
16
+ return Object.entries(patch).every(([key, expected]) => {
17
+ const labelKey = Array.isArray(expected) && typeof expected[0] === "number" ? "id" : "name";
18
+ const normalize = (value: unknown) =>
19
+ key === "labels" && Array.isArray(value)
20
+ ? [
21
+ ...new Set(
22
+ value.map((label) =>
23
+ typeof label === "object" && label !== null ? label[labelKey] : label,
24
+ ),
25
+ ),
26
+ ].sort()
27
+ : value;
28
+ return JSON.stringify(normalize(fields[key])) === JSON.stringify(normalize(expected));
29
+ });
30
+ }
@@ -0,0 +1,79 @@
1
+ import { asUnknownRecord } from "@leitwerk-dev/domain";
2
+
3
+ /** Parse common forge source fields, preserving polling defaults and permissive string handling. @internal */
4
+ export function parseRepositoryPullRequestConfig(value: unknown) {
5
+ const config = asUnknownRecord(value) ?? {};
6
+ if (
7
+ typeof config.profile !== "string" ||
8
+ typeof config.owner !== "string" ||
9
+ typeof config.repo !== "string" ||
10
+ typeof config.prNumber !== "number"
11
+ )
12
+ return null;
13
+ const terminalOutcome: "merged" | "closed" | undefined =
14
+ config.terminalOutcome === "merged" || config.terminalOutcome === "closed"
15
+ ? config.terminalOutcome
16
+ : undefined;
17
+ return {
18
+ /** @internal */
19
+ profile: config.profile,
20
+ /** @internal */
21
+ owner: config.owner,
22
+ /** @internal */
23
+ repo: config.repo,
24
+ /** @internal */
25
+ prNumber: config.prNumber,
26
+ /** @internal */
27
+ pollInterval: typeof config.pollInterval === "string" ? config.pollInterval : "30s",
28
+ /** @internal */
29
+ terminalOutcome,
30
+ /** @internal */
31
+ disabled: config.disabled === true,
32
+ };
33
+ }
34
+
35
+ /** @internal */
36
+ export function parseRepositoryFeedbackConfig(value: unknown) {
37
+ const base = parseRepositoryPullRequestConfig(value);
38
+ const config = asUnknownRecord(value) ?? {};
39
+ if (!base) return null;
40
+ return {
41
+ ...base,
42
+ /** @internal */
43
+ conversationCursor:
44
+ typeof config.conversationCursor === "number" ? config.conversationCursor : 0,
45
+ /** @internal */
46
+ reviewCursor: typeof config.reviewCursor === "number" ? config.reviewCursor : 0,
47
+ /** @internal */
48
+ inlineCursor: typeof config.inlineCursor === "number" ? config.inlineCursor : 0,
49
+ /** @internal */
50
+ quietPeriodMs: typeof config.quietPeriodMs === "number" ? config.quietPeriodMs : 120_000,
51
+ };
52
+ }
53
+
54
+ /** @internal */
55
+ export function parseRepositoryIssueCancelledConfig(value: unknown) {
56
+ const config = asUnknownRecord(value) ?? {};
57
+ if (
58
+ typeof config.profile !== "string" ||
59
+ typeof config.owner !== "string" ||
60
+ typeof config.repo !== "string" ||
61
+ typeof config.issueNumber !== "number" ||
62
+ typeof config.triggerLabel !== "string"
63
+ )
64
+ return null;
65
+ return {
66
+ /** @internal */
67
+ profile: config.profile,
68
+ /** @internal */
69
+ owner: config.owner,
70
+ /** @internal */
71
+ repo: config.repo,
72
+ /** @internal */
73
+ issueNumber: config.issueNumber,
74
+ /** @internal */
75
+ triggerLabel: config.triggerLabel,
76
+ /** @internal */
77
+ pollInterval: typeof config.pollInterval === "string" ? config.pollInterval : "30s",
78
+ };
79
+ }
@@ -0,0 +1,63 @@
1
+ /** Common issue and pull-request response fields used by repository integrations. @public */
2
+ export interface RepositoryIssue {
3
+ /** @public */
4
+ number: number;
5
+ /** @public */
6
+ title: string;
7
+ /** @public */
8
+ body: string | null;
9
+ /** @public */
10
+ state: string;
11
+ /** @public */
12
+ html_url: string;
13
+ /** @public */
14
+ updated_at: string;
15
+ /** @public */
16
+ user: {
17
+ /** @public */
18
+ login: string;
19
+ };
20
+ /** @public */
21
+ labels: Array<{
22
+ /** @public */
23
+ id: number;
24
+ /** @public */
25
+ name: string;
26
+ }>;
27
+ }
28
+
29
+ /** @public */
30
+ export interface RepositoryPullRequest {
31
+ /** @public */
32
+ number: number;
33
+ /** @internal */
34
+ title: string;
35
+ /** @internal */
36
+ body: string | null;
37
+ /** @internal */
38
+ state: string;
39
+ /** @public */
40
+ merged: boolean;
41
+ /** @internal */
42
+ mergeable?: boolean | null;
43
+ /** @internal */
44
+ mergeable_state?: string | null;
45
+ /** @public */
46
+ merge_commit_sha: string | null;
47
+ /** @public */
48
+ html_url: string;
49
+ /** @public */
50
+ head: {
51
+ /** @internal */
52
+ ref: string;
53
+ /** @public */
54
+ sha: string;
55
+ };
56
+ /** @internal */
57
+ base: {
58
+ /** @internal */
59
+ ref: string;
60
+ /** @internal */
61
+ sha: string;
62
+ };
63
+ }
@@ -0,0 +1,5 @@
1
+ export {
2
+ buildPlanSavedEventPayload,
3
+ buildReviewCompletedEventPayload,
4
+ buildReviewRequestedEventPayload,
5
+ } from "./review-flow.js";
@@ -5,6 +5,7 @@ import type {
5
5
  ReviewRequestedEvent,
6
6
  } from "./server-events.js";
7
7
 
8
+ /** @internal */
8
9
  export function filterStringArray(value: unknown): string[] {
9
10
  return Array.isArray(value)
10
11
  ? value.filter((entry): entry is string => typeof entry === "string")
@@ -26,8 +27,11 @@ function resolveOutcomeMarkdown(
26
27
  return typeof value === "string" ? value : undefined;
27
28
  }
28
29
 
30
+ /** @internal */
29
31
  export function buildPlanSavedEventPayload(input: {
32
+ /** @internal */
30
33
  planRevision: number;
34
+ /** @internal */
31
35
  event: Pick<ProcessTurnOutcomeEvent, "params" | "turnResultMarkdown">;
32
36
  }): Omit<PlanSavedEvent, "instanceId"> {
33
37
  return {
@@ -38,6 +42,7 @@ export function buildPlanSavedEventPayload(input: {
38
42
  };
39
43
  }
40
44
 
45
+ /** @internal */
41
46
  export function buildReviewRequestedEventPayload(
42
47
  event: Pick<ProcessTurnOutcomeEvent, "params">,
43
48
  ): Omit<ReviewRequestedEvent, "instanceId"> {
@@ -46,6 +51,7 @@ export function buildReviewRequestedEventPayload(
46
51
  };
47
52
  }
48
53
 
54
+ /** @internal */
49
55
  export function buildReviewCompletedEventPayload(
50
56
  event: Pick<ProcessTurnOutcomeEvent, "outcome" | "params" | "turnResultMarkdown">,
51
57
  ): Omit<ReviewCompletedEvent, "instanceId"> {
@@ -0,0 +1,7 @@
1
+ export {
2
+ getProcessTurnTransitions,
3
+ isDefinedProcess,
4
+ markDefinedProcess,
5
+ registerUnique,
6
+ setProcessTurnTransitions,
7
+ } from "./runtime-internals.js";