@leitwerk-dev/coding 0.3.1 → 0.4.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 (123) hide show
  1. package/README.md +154 -13
  2. package/dist/chunk-3WJRJ3Q7.js +220 -0
  3. package/dist/chunk-3WJRJ3Q7.js.map +1 -0
  4. package/dist/chunk-ABQH2WZT.js +36 -0
  5. package/dist/chunk-ABQH2WZT.js.map +1 -0
  6. package/dist/chunk-B3PE6DPF.js +820 -0
  7. package/dist/chunk-B3PE6DPF.js.map +1 -0
  8. package/dist/chunk-DNG7D77K.js +65 -0
  9. package/dist/chunk-DNG7D77K.js.map +1 -0
  10. package/dist/chunk-E3DB4TIZ.js +49 -0
  11. package/dist/chunk-E3DB4TIZ.js.map +1 -0
  12. package/dist/chunk-L2TFD72B.js +16320 -0
  13. package/dist/chunk-L2TFD72B.js.map +1 -0
  14. package/dist/chunk-M2VTUPFO.js +265 -0
  15. package/dist/chunk-M2VTUPFO.js.map +1 -0
  16. package/dist/{chunk-YSC5GEQJ.js → chunk-QD6FI4HR.js} +7 -3
  17. package/dist/chunk-QD6FI4HR.js.map +1 -0
  18. package/dist/chunk-SKGB4CZS.js +14 -0
  19. package/dist/chunk-SKGB4CZS.js.map +1 -0
  20. package/dist/chunk-SZ4WOGV2.js +120 -0
  21. package/dist/chunk-SZ4WOGV2.js.map +1 -0
  22. package/dist/finalization-git-internal.d.ts +9 -0
  23. package/dist/finalization-git-internal.d.ts.map +1 -1
  24. package/dist/finalization-git.d.ts +1 -1
  25. package/dist/finalization-git.d.ts.map +1 -1
  26. package/dist/finalization-git.js +6 -3
  27. package/dist/index.d.ts +1 -0
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/index.js +18 -591
  30. package/dist/index.js.map +1 -1
  31. package/dist/pull-request-publication-internal.d.ts +34 -24
  32. package/dist/pull-request-publication-internal.d.ts.map +1 -1
  33. package/dist/repository-change-launch-internal-BudnAfL7.d.ts +88 -0
  34. package/dist/repository-change-launch-internal.d.ts +32 -11
  35. package/dist/repository-change-launch-internal.d.ts.map +1 -1
  36. package/dist/repository-change-launch.d.ts +4 -3
  37. package/dist/repository-change-launch.d.ts.map +1 -1
  38. package/dist/repository-change-launch.js +162 -34
  39. package/dist/repository-change-launch.js.map +1 -1
  40. package/dist/repository-change-process-DlgF04fU.d.ts +69 -0
  41. package/dist/repository-change-process.d.ts +30 -25
  42. package/dist/repository-change-process.d.ts.map +1 -1
  43. package/dist/repository-change-publication.d.ts +76 -7
  44. package/dist/repository-change-publication.d.ts.map +1 -1
  45. package/dist/repository-change-publication.js +624 -136
  46. package/dist/repository-change-publication.js.map +1 -1
  47. package/dist/repository-change-state-internal.d.ts +18 -4
  48. package/dist/repository-change-state-internal.d.ts.map +1 -1
  49. package/dist/repository-change-ui-launcher-internal.d.ts +34 -22
  50. package/dist/repository-change-ui-launcher-internal.d.ts.map +1 -1
  51. package/dist/repository-publication-receipt.d.ts +23 -0
  52. package/dist/repository-publication-receipt.d.ts.map +1 -0
  53. package/dist/repository-rebase/git.d.ts +8 -0
  54. package/dist/repository-rebase/git.d.ts.map +1 -1
  55. package/dist/repository-reconciliation.d.ts +47 -0
  56. package/dist/repository-reconciliation.d.ts.map +1 -0
  57. package/dist/repository-record.d.ts +6 -0
  58. package/dist/repository-record.d.ts.map +1 -0
  59. package/dist/settings.d.ts +15 -0
  60. package/dist/settings.d.ts.map +1 -0
  61. package/dist/turns/commit-message-evidence.d.ts +35 -0
  62. package/dist/turns/commit-message-evidence.d.ts.map +1 -0
  63. package/dist/turns/commit-message-evidence.js +9 -0
  64. package/dist/turns/generate-commit-message.d.ts +4 -1
  65. package/dist/turns/generate-commit-message.d.ts.map +1 -1
  66. package/dist/turns/generate-commit-message.js +7 -5
  67. package/dist/turns/generate-plan.d.ts.map +1 -1
  68. package/dist/turns/generate-plan.js +1 -1
  69. package/dist/turns/git-inspection-profile.d.ts +25 -0
  70. package/dist/turns/git-inspection-profile.d.ts.map +1 -0
  71. package/dist/turns/git-inspection-profile.js +8 -0
  72. package/dist/turns/implement.d.ts +1 -1
  73. package/dist/turns/implement.d.ts.map +1 -1
  74. package/dist/turns/implement.js +1 -1
  75. package/dist/turns/simplify-implementation.d.ts +1 -1
  76. package/dist/turns/simplify-implementation.d.ts.map +1 -1
  77. package/dist/turns/simplify-implementation.js +3 -3
  78. package/package.json +5 -9
  79. package/src/finalization-git-internal.ts +186 -114
  80. package/src/finalization-git.ts +1 -1
  81. package/src/index.ts +4 -1
  82. package/src/pull-request-publication-internal.ts +158 -79
  83. package/src/repository-change-launch-internal.ts +119 -12
  84. package/src/repository-change-launch.ts +8 -4
  85. package/src/repository-change-process.ts +252 -524
  86. package/src/repository-change-publication.ts +702 -121
  87. package/src/repository-change-state-internal.ts +34 -20
  88. package/src/repository-change-ui-launcher-internal.ts +139 -56
  89. package/src/repository-publication-receipt.ts +71 -0
  90. package/src/repository-rebase/git.ts +108 -29
  91. package/src/repository-reconciliation.ts +600 -0
  92. package/src/repository-record.ts +14 -0
  93. package/src/settings.ts +79 -0
  94. package/src/turns/commit-message-evidence.ts +241 -0
  95. package/src/turns/generate-commit-message.ts +53 -23
  96. package/src/turns/generate-plan.ts +26 -12
  97. package/src/turns/git-inspection-profile.ts +134 -0
  98. package/src/turns/implement.ts +13 -3
  99. package/src/turns/simplify-implementation.ts +10 -6
  100. package/dist/chunk-34B3Q75M.js +0 -25
  101. package/dist/chunk-34B3Q75M.js.map +0 -1
  102. package/dist/chunk-F6CEEAFE.js +0 -13
  103. package/dist/chunk-F6CEEAFE.js.map +0 -1
  104. package/dist/chunk-GO44KCUS.js +0 -154
  105. package/dist/chunk-GO44KCUS.js.map +0 -1
  106. package/dist/chunk-R3UCUGY6.js +0 -31
  107. package/dist/chunk-R3UCUGY6.js.map +0 -1
  108. package/dist/chunk-W7VJT6AN.js +0 -25
  109. package/dist/chunk-W7VJT6AN.js.map +0 -1
  110. package/dist/chunk-WKHVLLKE.js +0 -45
  111. package/dist/chunk-WKHVLLKE.js.map +0 -1
  112. package/dist/chunk-YSC5GEQJ.js.map +0 -1
  113. package/dist/repository-change-launch-internal-Dd-AONUs.d.ts +0 -67
  114. package/dist/turns/review-implementation.d.ts +0 -4
  115. package/dist/turns/review-implementation.d.ts.map +0 -1
  116. package/dist/turns/review-implementation.js +0 -8
  117. package/dist/turns/review-plan.d.ts +0 -4
  118. package/dist/turns/review-plan.d.ts.map +0 -1
  119. package/dist/turns/review-plan.js +0 -8
  120. package/src/turns/review-implementation.ts +0 -30
  121. package/src/turns/review-plan.ts +0 -24
  122. /package/dist/turns/{review-implementation.js.map → commit-message-evidence.js.map} +0 -0
  123. /package/dist/turns/{review-plan.js.map → git-inspection-profile.js.map} +0 -0
@@ -1,11 +1,16 @@
1
1
  import type {
2
2
  defineExternalActionSource,
3
+ ProcessWatcherDefinition,
3
4
  RepositoryFeedbackSourceConfig,
4
5
  RepositoryIssueCancelledSourceConfig,
5
6
  RepositoryPullRequestSourceConfig,
6
7
  } from "@leitwerk-dev/process-sdk";
7
8
  import type { GitIdentity } from "./finalization-git.js";
8
9
  import type { RepositoryIssueOriginParams } from "./repository-change-launch-internal.js";
10
+ import {
11
+ createRepositoryChangeProcess,
12
+ type RepositoryChangeProcessConfig,
13
+ } from "./repository-change-process.js";
9
14
  import type {
10
15
  PublicationContext,
11
16
  PublicationEvidence,
@@ -13,16 +18,75 @@ import type {
13
18
  PublicationRequest,
14
19
  PublicationSource,
15
20
  PublicationState,
21
+ PublicationReconciliationContext as RemoteContext,
16
22
  RepositoryChangePublicationAdapter,
17
23
  } from "./repository-change-publication.js";
18
24
  import {
25
+ createRepositoryChangePublication,
19
26
  publicationObject as object,
20
27
  readPublicationState,
21
28
  } from "./repository-change-publication.js";
22
29
  import type { RepositoryChangeState } from "./repository-change-state.js";
23
30
 
31
+ /** Shared process defaults for SSH-backed pull-request publication. @internal */
32
+ export function createPullRequestChangeProcess<
33
+ P extends PublicationParams & {
34
+ /** @internal */
35
+ sshCredentialRef: string;
36
+ },
37
+ E,
38
+ C,
39
+ >(
40
+ provider: string,
41
+ label: string,
42
+ docker: boolean,
43
+ config: Pick<RepositoryChangeProcessConfig<P>, "paramsCodec" | "launcher" | "workflow"> & {
44
+ /** @internal */ publication: RepositoryChangePublicationAdapter<P>;
45
+ /** @internal */ watcher: Omit<
46
+ ProcessWatcherDefinition<P, E, C>,
47
+ "id" | "label" | "description"
48
+ >;
49
+ },
50
+ ) {
51
+ const { watcher, publication: adapter, ...definition } = config;
52
+ const publication = createRepositoryChangePublication(adapter);
53
+ publication.fragment.watcher({
54
+ ...watcher,
55
+ id: "use_leitwerk",
56
+ label: `${label} use-leitwerk issues`,
57
+ description: `Launch a remote repository change for ${label} issues carrying the trigger label`,
58
+ });
59
+ const { process } = createRepositoryChangeProcess({
60
+ ...definition,
61
+ publication,
62
+ processId: `${provider}_repo_change_process`,
63
+ displayName: `${label} Repo Change`,
64
+ repositoryCredentials: ({ params }) => [
65
+ { projectKey: "repo", kind: "git_ssh", credentialRef: params.sshCredentialRef },
66
+ ],
67
+ });
68
+ process.runtime = { ...process.runtime, docker };
69
+ return process;
70
+ }
71
+
72
+ /** Tools implementing the shared pull-request publication protocol. @internal */
73
+ function pullRequestDeliveryTools(provider: string): string[] {
74
+ return [
75
+ "get_pull_request",
76
+ "add_pull_request_comment",
77
+ "resolve_git_identity",
78
+ "ensure_pull_request",
79
+ "add_issue_comment",
80
+ "add_pull_request_feedback_reaction",
81
+ "reply_to_pull_request_feedback",
82
+ "get_issue",
83
+ "ensure_label",
84
+ "update_issue",
85
+ ].map((name) => `${provider}_${name}`);
86
+ }
87
+
24
88
  const callFor =
25
- <P>(ctx: PublicationContext<P>, provider: string) =>
89
+ (ctx: Pick<PublicationContext<unknown>, "callIntegrationTool">, provider: string) =>
26
90
  <T>(name: string, args: Record<string, unknown>) =>
27
91
  ctx.callIntegrationTool(`${provider}_${name}`, { projectKey: "repo", ...args }) as Promise<T>;
28
92
 
@@ -31,22 +95,24 @@ export async function resolvePullRequestGitIdentity<P>(
31
95
  ctx: PublicationContext<P>,
32
96
  provider: string,
33
97
  profile: string,
98
+ allowLookup = true,
34
99
  ): Promise<GitIdentity> {
35
- const project = ctx.projects.find((candidate) => candidate.key === "repo");
36
- const identity = object(object(project?.metadata)["leitwerk.gitIdentity"]);
100
+ const project = ctx.repo.get("repo");
101
+ const metadata = ctx.projects.find((candidate) => candidate.key === project.key)?.metadata;
102
+ const identity = object(metadata?.["leitwerk.gitIdentity"]);
37
103
  if (
38
104
  identity.provider === provider &&
39
105
  identity.profile === profile &&
40
- [identity.login, identity.name, identity.email].every(
41
- (value) => typeof value === "string" && value.trim(),
42
- )
106
+ (!allowLookup || (typeof identity.login === "string" && identity.login.trim())) &&
107
+ [identity.name, identity.email].every((value) => typeof value === "string" && value.trim())
43
108
  )
44
109
  return identity as unknown as GitIdentity;
110
+ if (!allowLookup) throw new Error(`Pinned ${provider} Git identity is unavailable`);
45
111
  return callFor(ctx, provider)<GitIdentity>("resolve_git_identity", {});
46
112
  }
47
113
 
48
114
  /** @internal */
49
- export function readPullRequestFeedback(
115
+ function readPullRequestFeedback(
50
116
  current: PublicationState,
51
117
  event: unknown,
52
118
  ): Extract<PublicationEvidence, { kind: "feedback" }> {
@@ -61,57 +127,11 @@ export function readPullRequestFeedback(
61
127
  };
62
128
  }
63
129
 
64
- /** @internal */
65
- export function reconcilePullRequestSourceIssue<P extends PublicationParams>(
66
- provider: string,
67
- labelKey: "id" | "name",
68
- issueOrigin: (params: P) =>
69
- | {
70
- /** @internal */
71
- issueNumber: number;
72
- /** @internal */
73
- triggerLabel: string;
74
- /** @internal */
75
- doneLabel: string;
76
- }
77
- | undefined,
78
- ): RepositoryChangePublicationAdapter<P>["reconcileTerminal"] {
79
- return async (ctx, _current, pr) => {
80
- const params = issueOrigin(ctx.params);
81
- if (!params) return;
82
- const call = callFor(ctx, provider);
83
- const issue = await call<{ labels: Array<{ id: number; name: string }> }>("get_issue", {
84
- issueNumber: params.issueNumber,
85
- });
86
- let labels = issue.labels
87
- .filter((label) => label.name !== params.triggerLabel)
88
- .map((label) => label[labelKey]);
89
- if (pr.merged) {
90
- const done = await call<{ id: number; name: string }>("ensure_label", {
91
- name: params.doneLabel,
92
- });
93
- labels = [...new Set([...labels, done[labelKey]])];
94
- }
95
- await call("update_issue", {
96
- issueNumber: params.issueNumber,
97
- patch: { labels, ...(pr.merged ? { state: "closed" } : {}) },
98
- writeKey: `${provider}:${ctx.process.id}:${pr.merged ? "complete-source-issue" : "remove-source-trigger"}`,
99
- });
100
- await call("add_issue_comment", {
101
- issueNumber: params.issueNumber,
102
- body: pr.merged
103
- ? `Merged ${pr.html_url}${pr.merge_commit_sha ? ` at ${pr.merge_commit_sha}` : ""}.`
104
- : `Leitwerk stopped because ${pr.html_url} was closed without merge.`,
105
- writeKey: `${provider}:${ctx.process.id}:${pr.merged ? "merged" : "closed"}-pr-comment`,
106
- });
107
- };
108
- }
109
-
110
130
  /** @internal */
111
131
  type SourceFactory<C> = ReturnType<typeof defineExternalActionSource<C>>;
112
132
 
113
133
  /** Shared wiring for providers implementing the pull-request source protocol. @internal */
114
- export function pullRequestPublicationSources<P extends PublicationParams>(
134
+ export function pullRequestPublicationDefaults<P extends PublicationParams>(
115
135
  provider: string,
116
136
  label: string,
117
137
  external: {
@@ -126,6 +146,13 @@ export function pullRequestPublicationSources<P extends PublicationParams>(
126
146
  },
127
147
  profile: (params: P) => string,
128
148
  issueOrigin: (params: P) => RepositoryIssueOriginParams | undefined,
149
+ labelKey: "id" | "name",
150
+ ci: {
151
+ /** @internal */ id: string;
152
+ /** @internal */ label: string;
153
+ /** @internal */ tools: readonly string[];
154
+ /** @internal */ prompt(current: PublicationState): string;
155
+ },
129
156
  ) {
130
157
  const remote = (state: RepositoryChangeState) =>
131
158
  readPublicationState(state, `${provider}RepoChange`);
@@ -196,32 +223,65 @@ export function pullRequestPublicationSources<P extends PublicationParams>(
196
223
  }),
197
224
  read: () => ({ kind: "cancelled" }),
198
225
  };
199
- return {
200
- /** @internal */ requirePr,
201
- /** @internal */ feedback,
202
- /** @internal */ terminal,
203
- /** @internal */ cancelled,
204
- };
205
- }
206
-
207
- /** Callbacks for providers implementing the shared pull-request tool protocol. @internal */
208
- export function pullRequestPublicationCallbacks<P extends PublicationParams>(
209
- provider: string,
210
- label: string,
211
- issueOrigin: (params: P) =>
212
- | {
213
- /** @internal */
214
- issueNumber: number;
215
- /** @internal */
216
- issueUrl: string;
217
- }
218
- | undefined,
219
- ): Pick<
220
- RepositoryChangePublicationAdapter<P>,
221
- "ensureRequest" | "linkIssue" | "reply" | "acknowledge" | "head" | "afterRebase"
222
- > {
226
+ async function finalizeIssue(ctx: RemoteContext<P>, pr: PublicationRequest | null) {
227
+ const params = issueOrigin(ctx.params);
228
+ if (!params) return;
229
+ const call = callFor(ctx, provider);
230
+ const issue = await call<{ labels: Array<{ id: number; name: string }> }>("get_issue", {
231
+ issueNumber: params.issueNumber,
232
+ });
233
+ let labels = issue.labels
234
+ .filter((label) => label.name !== params.triggerLabel)
235
+ .map((label) => label[labelKey]);
236
+ if (pr?.merged) {
237
+ const done = await call<{ id: number; name: string }>("ensure_label", {
238
+ name: params.doneLabel,
239
+ });
240
+ labels = [...new Set([...labels, done[labelKey]])];
241
+ }
242
+ await call("update_issue", {
243
+ issueNumber: params.issueNumber,
244
+ patch: { labels, ...(pr?.merged ? { state: "closed" } : {}) },
245
+ writeKey: `${provider}:${ctx.process.id}:${pr?.merged ? "complete-source-issue" : pr ? "remove-source-trigger" : "no-changes-trigger"}`,
246
+ });
247
+ await call("add_issue_comment", {
248
+ issueNumber: params.issueNumber,
249
+ body: !pr
250
+ ? "No repository changes were needed. No pull request was opened."
251
+ : pr.merged
252
+ ? `Merged ${pr.html_url}${pr.merge_commit_sha ? ` at ${pr.merge_commit_sha}` : ""}.`
253
+ : `Leitwerk stopped because ${pr.html_url} was closed without merge.`,
254
+ writeKey: `${provider}:${ctx.process.id}:${pr ? `${pr.merged ? "merged" : "closed"}-pr-comment` : "no-changes-comment"}`,
255
+ });
256
+ }
223
257
  const call = (ctx: PublicationContext<P>) => callFor(ctx, provider);
224
- return {
258
+ const adapter: Omit<RepositoryChangePublicationAdapter<P>, "sources"> = {
259
+ /** @internal */ namespace: `${provider}RepoChange`,
260
+ /** @internal */ label: `${label} PR`,
261
+ /** @internal */ ids: {
262
+ /** @internal */ deliver: "deliver_change",
263
+ /** @internal */ feedback: "revise_from_pull_request_feedback",
264
+ /** @internal */ ciRepair: ci.id,
265
+ /** @internal */ operator: "ci_operator_action",
266
+ },
267
+ /** @internal */ tools: {
268
+ /** @internal */ delivery: pullRequestDeliveryTools(provider),
269
+ /** @internal */ feedback: [
270
+ `${provider}_get_pull_request`,
271
+ `${provider}_list_pull_request_feedback`,
272
+ ],
273
+ /** @internal */ ci: ci.tools,
274
+ },
275
+ /** @internal */ commitMessage: (kind: "feedback" | "ci") =>
276
+ kind === "feedback" ? `fix: address ${label} review feedback` : `fix: repair ${ci.label}`,
277
+ /** @internal */ prompt: (kind: "feedback" | "ci", current: PublicationState) =>
278
+ kind === "feedback"
279
+ ? `Address the unseen ${label} pull-request feedback batch for PR #${current.prNumber}. Feedback identifiers: ${JSON.stringify(current.feedbackIds)}. Inspect the current checkout and use ${label} tools to read the full feedback. Do not rely on an earlier plan or conversation. Make only justified repository changes. Call changes_ready if files need publishing, no_changes after an explicit diagnosis that no repository change is needed, or cannot_repair when operator action is required.`
280
+ : ci.prompt(current),
281
+ /** @internal */ identity: (ctx: PublicationContext<P>) =>
282
+ resolvePullRequestGitIdentity(ctx, provider, profile(ctx.params)),
283
+ /** @internal */ reconcileTerminal: (ctx, _current, pr) => finalizeIssue(ctx, pr),
284
+ /** @internal */ unchanged: (ctx) => finalizeIssue(ctx, null),
225
285
  async ensureRequest(ctx) {
226
286
  const project = ctx.repo.get("repo");
227
287
  const issue = issueOrigin(ctx.params);
@@ -283,4 +343,23 @@ export function pullRequestPublicationCallbacks<P extends PublicationParams>(
283
343
  });
284
344
  },
285
345
  };
346
+ return {
347
+ /** @internal */ adapter,
348
+ /** @internal */ conflict(source: PublicationSource<P>["source"]): PublicationSource<P> {
349
+ return {
350
+ id: `${provider}_merge_conflict`,
351
+ kind: "conflict",
352
+ label: "Rebase conflicting pull request",
353
+ source,
354
+ read: ({ event }) => ({
355
+ kind: "conflict",
356
+ conflict: object(event).conflict as NonNullable<PublicationState["conflict"]>,
357
+ }),
358
+ };
359
+ },
360
+ /** @internal */ requirePr,
361
+ /** @internal */ feedback,
362
+ /** @internal */ terminal,
363
+ /** @internal */ cancelled,
364
+ };
286
365
  }
@@ -1,8 +1,66 @@
1
1
  import { parseRepoLocator, trimString } from "@leitwerk-dev/domain";
2
- import type { Codec } from "@leitwerk-dev/process-sdk";
2
+ import type { Codec, FormDefinition, ProcessLaunchConfig } from "@leitwerk-dev/process-sdk";
3
+ import type { RepositoryChangeWorkflow } from "./repository-change-process.js";
3
4
 
4
5
  /** @public */
5
- export interface RepositoryChangeParamsBase {
6
+ export interface RepositoryChangeOptions {
7
+ /** @public */
8
+ skipPlanDecision?: boolean;
9
+ /** @public */
10
+ skipSimplification?: boolean;
11
+ }
12
+
13
+ /** @internal */
14
+ export const repositoryChangeOptionFields: FormDefinition["fields"] = [
15
+ {
16
+ id: "skipPlanDecision",
17
+ label: "Skip plan approval",
18
+ kind: "boolean",
19
+ description: "Generate a plan, then implement and publish automatically.",
20
+ },
21
+ {
22
+ id: "skipSimplification",
23
+ label: "Skip simplification",
24
+ kind: "boolean",
25
+ description: "Publish after implementation without the simplification pass.",
26
+ },
27
+ ];
28
+
29
+ /** @internal */
30
+ export function repositoryChangeOptions(input: RepositoryChangeOptions): RepositoryChangeOptions {
31
+ return {
32
+ skipPlanDecision: input.skipPlanDecision === true,
33
+ skipSimplification: input.skipSimplification === true,
34
+ };
35
+ }
36
+
37
+ /** Provider label reads happen only at the implementation route boundary. @internal */
38
+ export function repositoryChangeWorkflow<
39
+ P extends RepositoryChangeOptions & {
40
+ /** @internal */
41
+ origin: string;
42
+ },
43
+ >(readLabels: (params: P) => Promise<readonly string[]>): RepositoryChangeWorkflow<P> {
44
+ return {
45
+ async planDecision(params) {
46
+ return {
47
+ skip: params.origin === "ui" && params.skipPlanDecision === true,
48
+ reason: "Launcher option",
49
+ };
50
+ },
51
+ async simplification(params) {
52
+ return params.origin === "ui"
53
+ ? { skip: params.skipSimplification === true, reason: "Launcher option" }
54
+ : {
55
+ skip: (await readLabels(params)).includes("leitwerk-skip-simplification"),
56
+ reason: "Source labels",
57
+ };
58
+ },
59
+ };
60
+ }
61
+
62
+ /** @public */
63
+ export interface RepositoryChangeParamsBase extends RepositoryChangeOptions {
6
64
  /** @public */
7
65
  repoLocator: string;
8
66
  /** @public */
@@ -45,6 +103,63 @@ export interface RepositoryUiOriginParams {
45
103
  doneLabel: null;
46
104
  }
47
105
 
106
+ /** Input shared by SSH-backed pull-request launchers. @public */
107
+ export interface PullRequestChangeLaunchInput
108
+ extends Pick<RepositoryChangeParamsBase, "prompt" | "workBranch"> {
109
+ /** @public */ profile: string;
110
+ /** @public */ sshCredentialRef: string;
111
+ }
112
+
113
+ /** Shared launch envelope; providers retain ownership of project metadata. @internal */
114
+ export function repositoryIssueChangeLaunchConfig<
115
+ P extends RepositoryChangeParamsBase & (RepositoryIssueOriginParams | RepositoryUiOriginParams),
116
+ >(
117
+ provider: string,
118
+ params: P,
119
+ title: string,
120
+ repository: string,
121
+ metadata: Record<string, unknown>,
122
+ source?: {
123
+ /** @internal */ id?: number;
124
+ /** @internal */ html_url: string;
125
+ /** @internal */ ssh_url: string;
126
+ /** @internal */ clone_url?: string;
127
+ },
128
+ ): ProcessLaunchConfig<P> {
129
+ const issue = params.origin === "issue";
130
+ const settingsRepository =
131
+ source?.id !== undefined
132
+ ? {
133
+ origin: new URL(source.html_url).origin,
134
+ repositoryId: source.id,
135
+ aliases: [source.ssh_url, ...(source.clone_url ? [source.clone_url] : [])],
136
+ }
137
+ : undefined;
138
+ return {
139
+ processId: `${provider}_repo_change_process`,
140
+ params,
141
+ title,
142
+ startTurnId: "generate_plan",
143
+ ...(issue
144
+ ? {
145
+ externalId: `${provider}:${repository}#${params.issueNumber}`,
146
+ externalUrl: params.issueUrl,
147
+ }
148
+ : {}),
149
+ projects: [
150
+ {
151
+ key: "repo",
152
+ repoLocator: params.repoLocator,
153
+ ...(settingsRepository ? { settingsRepository } : {}),
154
+ baseBranch: params.baseBranch,
155
+ workBranch: params.workBranch,
156
+ ...(issue ? { externalId: String(params.issueNumber), externalUrl: params.issueUrl } : {}),
157
+ metadata,
158
+ },
159
+ ],
160
+ };
161
+ }
162
+
48
163
  /** GitHub/Forgejo legacy origins default to issue; other providers may be stricter. @internal */
49
164
  export function normalizeRepositoryIssueOrigin(
50
165
  record: Record<string, unknown>,
@@ -72,16 +187,7 @@ export function normalizeRepositoryIssueOrigin(
72
187
  }
73
188
 
74
189
  /** @public */
75
- export interface NormalizedRepositoryChangeParamsInput {
76
- /** @internal */
77
- repoLocator: string;
78
- /** @internal */
79
- baseBranch: string;
80
- /** @internal */
81
- workBranch: string;
82
- /** @internal */
83
- prompt: string;
84
- }
190
+ export interface NormalizedRepositoryChangeParamsInput extends RepositoryChangeParamsBase {}
85
191
 
86
192
  /** @public */
87
193
  export function repositoryChangeParamsRecord(
@@ -102,6 +208,7 @@ export function normalizeRepositoryChangeParamsInput(
102
208
  const record = repositoryChangeParamsRecord(value, displayName);
103
209
  const rawRepoLocator = trimString(record.repoLocator);
104
210
  return {
211
+ ...repositoryChangeOptions(record),
105
212
  repoLocator: parseRepoLocator(rawRepoLocator)?.value ?? rawRepoLocator,
106
213
  baseBranch: trimString(record.baseBranch) || "main",
107
214
  workBranch: trimString(record.workBranch),
@@ -1,7 +1,9 @@
1
1
  export { parseRepositoryProfileBindings } from "./profile-bindings-internal.js";
2
2
  export type {
3
3
  NormalizedRepositoryChangeParamsInput,
4
+ PullRequestChangeLaunchInput,
4
5
  RepositoryChangeLaunchParams,
6
+ RepositoryChangeOptions,
5
7
  RepositoryChangeParamsBase,
6
8
  RepositoryIssueOriginParams,
7
9
  RepositoryUiOriginParams,
@@ -11,9 +13,11 @@ export {
11
13
  normalizeRepositoryChangeParamsInput,
12
14
  normalizeRepositoryIssueChangeParams,
13
15
  normalizeRepositoryIssueOrigin,
16
+ repositoryChangeOptionFields,
17
+ repositoryChangeOptions,
14
18
  repositoryChangeParamsRecord,
19
+ repositoryChangeWorkflow,
20
+ repositoryIssueChangeLaunchConfig,
15
21
  } from "./repository-change-launch-internal.js";
16
- export {
17
- createRepositoryChangeUiLauncher,
18
- repositoryVisibilityCheck,
19
- } from "./repository-change-ui-launcher-internal.js";
22
+ export type { RepositoryChangeWorkflow } from "./repository-change-process.js";
23
+ export { createRepositoryChangeLauncher } from "./repository-change-ui-launcher-internal.js";