@leitwerk-dev/coding 0.2.0 → 0.3.0
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.
- package/README.md +28 -10
- package/dist/actions.d.ts +12 -3
- package/dist/actions.d.ts.map +1 -1
- package/dist/auto-work-branch-internal.d.ts +4 -0
- package/dist/auto-work-branch-internal.d.ts.map +1 -0
- package/dist/auto-work-branch.d.ts +1 -12
- package/dist/auto-work-branch.d.ts.map +1 -1
- package/dist/auto-work-branch.js +18 -97
- package/dist/auto-work-branch.js.map +1 -1
- package/dist/{chunk-EP3ZC37F.js → chunk-34B3Q75M.js} +1 -1
- package/dist/chunk-34B3Q75M.js.map +1 -0
- package/dist/{chunk-OFDNIT5X.js → chunk-F6CEEAFE.js} +1 -1
- package/dist/chunk-F6CEEAFE.js.map +1 -0
- package/dist/chunk-GO44KCUS.js +154 -0
- package/dist/chunk-GO44KCUS.js.map +1 -0
- package/dist/{chunk-WQEPA35Z.js → chunk-R3UCUGY6.js} +1 -1
- package/dist/chunk-R3UCUGY6.js.map +1 -0
- package/dist/{chunk-67YKGZLM.js → chunk-W7VJT6AN.js} +1 -1
- package/dist/chunk-W7VJT6AN.js.map +1 -0
- package/dist/{chunk-NIJCT4VK.js → chunk-WKHVLLKE.js} +1 -1
- package/dist/chunk-WKHVLLKE.js.map +1 -0
- package/dist/{chunk-UBVLJV3V.js → chunk-YSC5GEQJ.js} +1 -1
- package/dist/chunk-YSC5GEQJ.js.map +1 -0
- package/dist/finalization-git-internal.d.ts +33 -0
- package/dist/finalization-git-internal.d.ts.map +1 -0
- package/dist/finalization-git.d.ts +2 -47
- package/dist/finalization-git.d.ts.map +1 -1
- package/dist/finalization-git.js +3 -9
- package/dist/index.d.ts +3 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +73 -112
- package/dist/index.js.map +1 -1
- package/dist/repository-change-launch-internal.d.ts +35 -0
- package/dist/repository-change-launch-internal.d.ts.map +1 -0
- package/dist/repository-change-launch.d.ts +2 -64
- package/dist/repository-change-launch.d.ts.map +1 -1
- package/dist/repository-change-launch.js +22 -11
- package/dist/repository-change-launch.js.map +1 -1
- package/dist/repository-change-process.d.ts +31 -13
- package/dist/repository-change-process.d.ts.map +1 -1
- package/dist/repository-change-publication.d.ts +229 -0
- package/dist/repository-change-publication.d.ts.map +1 -0
- package/dist/repository-change-publication.js +368 -0
- package/dist/repository-change-publication.js.map +1 -0
- package/dist/repository-change-state-internal.d.ts +21 -0
- package/dist/repository-change-state-internal.d.ts.map +1 -0
- package/dist/repository-change-state.d.ts +1 -17
- package/dist/repository-change-state.d.ts.map +1 -1
- package/dist/repository-change-state.js +0 -13
- package/dist/turns/generate-commit-message.d.ts +2 -0
- package/dist/turns/generate-commit-message.d.ts.map +1 -1
- package/dist/turns/generate-commit-message.js +1 -1
- package/dist/turns/generate-plan.d.ts +1 -0
- package/dist/turns/generate-plan.d.ts.map +1 -1
- package/dist/turns/generate-plan.js +1 -1
- package/dist/turns/implement.d.ts +1 -0
- package/dist/turns/implement.d.ts.map +1 -1
- package/dist/turns/implement.js +1 -1
- package/dist/turns/review-implementation.d.ts +1 -0
- package/dist/turns/review-implementation.d.ts.map +1 -1
- package/dist/turns/review-implementation.js +1 -1
- package/dist/turns/review-plan.d.ts +1 -0
- package/dist/turns/review-plan.d.ts.map +1 -1
- package/dist/turns/review-plan.js +1 -1
- package/dist/turns/simplify-implementation.d.ts +1 -0
- package/dist/turns/simplify-implementation.d.ts.map +1 -1
- package/dist/turns/simplify-implementation.js +1 -1
- package/package.json +24 -8
- package/src/actions.ts +12 -9
- package/src/auto-work-branch-internal.ts +41 -0
- package/src/auto-work-branch.ts +1 -140
- package/src/finalization-git-internal.ts +218 -0
- package/src/finalization-git.ts +2 -828
- package/src/index.ts +15 -4
- package/src/repository-change-launch-internal.ts +64 -0
- package/src/repository-change-launch.ts +10 -264
- package/src/repository-change-process.ts +33 -123
- package/src/repository-change-publication.ts +689 -0
- package/src/repository-change-state-internal.ts +60 -0
- package/src/repository-change-state.ts +1 -78
- package/src/turns/generate-commit-message.ts +2 -0
- package/src/turns/generate-plan.ts +1 -0
- package/src/turns/implement.ts +1 -0
- package/src/turns/review-implementation.ts +1 -0
- package/src/turns/review-plan.ts +1 -0
- package/src/turns/simplify-implementation.ts +1 -0
- package/dist/chunk-5LVPKVI2.js +0 -27
- package/dist/chunk-5LVPKVI2.js.map +0 -1
- package/dist/chunk-67YKGZLM.js.map +0 -1
- package/dist/chunk-73LKROYK.js +0 -616
- package/dist/chunk-73LKROYK.js.map +0 -1
- package/dist/chunk-EP3ZC37F.js.map +0 -1
- package/dist/chunk-NIJCT4VK.js.map +0 -1
- package/dist/chunk-OFDNIT5X.js.map +0 -1
- package/dist/chunk-UBVLJV3V.js.map +0 -1
- package/dist/chunk-WQEPA35Z.js.map +0 -1
- package/dist/chunk-Y2S6JFVO.js +0 -185
- package/dist/chunk-Y2S6JFVO.js.map +0 -1
- package/dist/chunk-YIP4MP64.js +0 -61
- package/dist/chunk-YIP4MP64.js.map +0 -1
- package/dist/turns/resolve-merge-conflict.d.ts +0 -3
- package/dist/turns/resolve-merge-conflict.d.ts.map +0 -1
- package/dist/turns/resolve-merge-conflict.js +0 -8
- package/dist/turns/resolve-merge-conflict.js.map +0 -1
- package/src/turns/resolve-merge-conflict.ts +0 -25
package/src/index.ts
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
import type { LeitwerkExtensionModule } from "@leitwerk-dev/process-sdk";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
/** @internal */
|
|
4
|
+
const manifest = {
|
|
5
|
+
/** @internal */
|
|
6
|
+
id: "coding",
|
|
7
|
+
/** @internal */
|
|
8
|
+
version: "0.1.0",
|
|
9
|
+
} as const;
|
|
10
|
+
/** @public */
|
|
4
11
|
const extension: LeitwerkExtensionModule = { manifest };
|
|
5
12
|
export default extension;
|
|
6
13
|
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
|
|
14
|
+
export {
|
|
15
|
+
acceptReviewForm,
|
|
16
|
+
codingActionIds,
|
|
17
|
+
requestReviewChangesForm,
|
|
18
|
+
requestRevisionForm,
|
|
19
|
+
} from "./actions.js";
|
|
20
|
+
export { createRepositoryChangeProcess } from "./repository-change-process.js";
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { parseRepoLocator, trimString } from "@leitwerk-dev/domain";
|
|
2
|
+
import type { Codec } from "@leitwerk-dev/process-sdk";
|
|
3
|
+
|
|
4
|
+
/** @public */
|
|
5
|
+
export interface RepositoryChangeParamsBase {
|
|
6
|
+
/** @public */
|
|
7
|
+
repoLocator: string;
|
|
8
|
+
/** @public */
|
|
9
|
+
baseBranch: string;
|
|
10
|
+
/** @public */
|
|
11
|
+
workBranch: string;
|
|
12
|
+
/** @public */
|
|
13
|
+
prompt: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** @public */
|
|
17
|
+
export type RepositoryChangeLaunchParams<TExtra extends object = Record<never, never>> = TExtra &
|
|
18
|
+
RepositoryChangeParamsBase;
|
|
19
|
+
|
|
20
|
+
/** @public */
|
|
21
|
+
export interface NormalizedRepositoryChangeParamsInput {
|
|
22
|
+
/** @internal */
|
|
23
|
+
repoLocator: string;
|
|
24
|
+
/** @internal */
|
|
25
|
+
baseBranch: string;
|
|
26
|
+
/** @internal */
|
|
27
|
+
workBranch: string;
|
|
28
|
+
/** @internal */
|
|
29
|
+
prompt: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** @public */
|
|
33
|
+
export function repositoryChangeParamsRecord(
|
|
34
|
+
value: unknown,
|
|
35
|
+
displayName: string,
|
|
36
|
+
): Record<string, unknown> {
|
|
37
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
38
|
+
throw new Error(`${displayName} params must be an object`);
|
|
39
|
+
}
|
|
40
|
+
return value as Record<string, unknown>;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** @public */
|
|
44
|
+
export function normalizeRepositoryChangeParamsInput(
|
|
45
|
+
value: unknown,
|
|
46
|
+
displayName: string,
|
|
47
|
+
): NormalizedRepositoryChangeParamsInput {
|
|
48
|
+
const record = repositoryChangeParamsRecord(value, displayName);
|
|
49
|
+
const rawRepoLocator = trimString(record.repoLocator);
|
|
50
|
+
return {
|
|
51
|
+
repoLocator: parseRepoLocator(rawRepoLocator)?.value ?? rawRepoLocator,
|
|
52
|
+
baseBranch: trimString(record.baseBranch) || "main",
|
|
53
|
+
workBranch: trimString(record.workBranch),
|
|
54
|
+
prompt: trimString(record.prompt),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** @public */
|
|
59
|
+
export function createRepositoryChangeParamsCodec<T extends RepositoryChangeParamsBase>(input: {
|
|
60
|
+
/** @public */
|
|
61
|
+
normalize(value: unknown): T;
|
|
62
|
+
}): Codec<T> {
|
|
63
|
+
return { parse: input.normalize, serialize: (value) => value };
|
|
64
|
+
}
|
|
@@ -1,264 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
export interface RepositoryChangeParamsBase {
|
|
13
|
-
repoLocator: string;
|
|
14
|
-
baseBranch: string;
|
|
15
|
-
workBranch: string;
|
|
16
|
-
prompt: string;
|
|
17
|
-
launchKind: RepositoryChangeLaunchKind;
|
|
18
|
-
importedPlanMarkdown?: string;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export type RepositoryChangeLaunchParams<TExtra extends object = Record<never, never>> = TExtra &
|
|
22
|
-
Omit<RepositoryChangeParamsBase, "launchKind" | "importedPlanMarkdown"> &
|
|
23
|
-
(
|
|
24
|
-
| { launchKind: "requested_change" }
|
|
25
|
-
| { launchKind: "imported_plan"; importedPlanMarkdown: string }
|
|
26
|
-
);
|
|
27
|
-
|
|
28
|
-
export interface NormalizedRepositoryChangeParamsInput {
|
|
29
|
-
launchKind: string;
|
|
30
|
-
repoLocator: string;
|
|
31
|
-
baseBranch: string;
|
|
32
|
-
workBranch: string;
|
|
33
|
-
prompt: string;
|
|
34
|
-
importedPlanMarkdown: string;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export function repositoryChangeParamsRecord(
|
|
38
|
-
value: unknown,
|
|
39
|
-
displayName: string,
|
|
40
|
-
): Record<string, unknown> {
|
|
41
|
-
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
42
|
-
throw new Error(`${displayName} params must be an object`);
|
|
43
|
-
}
|
|
44
|
-
return value as Record<string, unknown>;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export function normalizeRepositoryChangeParamsInput(
|
|
48
|
-
value: unknown,
|
|
49
|
-
displayName: string,
|
|
50
|
-
): NormalizedRepositoryChangeParamsInput {
|
|
51
|
-
const record = repositoryChangeParamsRecord(value, displayName);
|
|
52
|
-
const rawRepoLocator = trimString(record.repoLocator);
|
|
53
|
-
return {
|
|
54
|
-
launchKind: trimString(record.launchKind),
|
|
55
|
-
repoLocator: parseRepoLocator(rawRepoLocator)?.value ?? rawRepoLocator,
|
|
56
|
-
baseBranch: trimString(record.baseBranch) || "main",
|
|
57
|
-
workBranch: trimString(record.workBranch),
|
|
58
|
-
prompt: trimString(record.prompt),
|
|
59
|
-
importedPlanMarkdown: trimString(record.importedPlanMarkdown),
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export function createRepositoryChangeParamsCodec<T extends RepositoryChangeParamsBase>(input: {
|
|
64
|
-
displayName: string;
|
|
65
|
-
normalize(
|
|
66
|
-
value: unknown,
|
|
67
|
-
): NormalizedRepositoryChangeParamsInput & Omit<T, keyof RepositoryChangeParamsBase>;
|
|
68
|
-
}): Codec<T> {
|
|
69
|
-
return {
|
|
70
|
-
parse(value) {
|
|
71
|
-
const { importedPlanMarkdown, ...shared } = input.normalize(value);
|
|
72
|
-
if (shared.launchKind === "requested_change") return shared as T;
|
|
73
|
-
if (shared.launchKind === "imported_plan") {
|
|
74
|
-
return { ...shared, launchKind: shared.launchKind, importedPlanMarkdown } as T;
|
|
75
|
-
}
|
|
76
|
-
throw new Error(`${input.displayName} params require a valid launchKind`);
|
|
77
|
-
},
|
|
78
|
-
serialize: (value) => value,
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export interface RepositoryChangeLaunchPlannerInput {
|
|
83
|
-
input: Record<string, unknown>;
|
|
84
|
-
metadata?: Record<string, unknown> | null;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export type RepositoryChangeLaunchResolution<T extends RepositoryChangeParamsBase> =
|
|
88
|
-
| { ok: true; launchConfig: ProcessLaunchConfig<T> }
|
|
89
|
-
| { ok: false; errors: readonly LauncherValidationError[] };
|
|
90
|
-
|
|
91
|
-
export interface RepositoryChangeLaunchPlanner<T extends RepositoryChangeParamsBase> {
|
|
92
|
-
plan(input: RepositoryChangeLaunchPlannerInput): RepositoryChangeLaunchResolution<T>;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
export function formatRepositoryChangeLaunchErrors(
|
|
96
|
-
errors: readonly LauncherValidationError[],
|
|
97
|
-
): string {
|
|
98
|
-
return errors.map((error) => `${error.fieldId ?? "launch"}: ${error.message}`).join("; ");
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
export function createRepositoryChangeLaunchPlanner<T extends RepositoryChangeParamsBase>(config: {
|
|
102
|
-
processId: string;
|
|
103
|
-
normalize(input: Record<string, unknown>): T & { importedPlanMarkdown?: string };
|
|
104
|
-
validateRepoLocator(repoLocator: string): string | null;
|
|
105
|
-
validate?(input: Record<string, unknown>, params: T): readonly LauncherValidationError[];
|
|
106
|
-
prepare?(params: T): T;
|
|
107
|
-
deferWithoutWorkBranch?: boolean;
|
|
108
|
-
}): RepositoryChangeLaunchPlanner<T> {
|
|
109
|
-
return {
|
|
110
|
-
plan({ input, metadata }) {
|
|
111
|
-
const params = config.normalize(input);
|
|
112
|
-
const errors: LauncherValidationError[] = [];
|
|
113
|
-
if (params.launchKind !== "requested_change" && params.launchKind !== "imported_plan") {
|
|
114
|
-
errors.push({
|
|
115
|
-
code: "custom_rule",
|
|
116
|
-
fieldId: "launchKind",
|
|
117
|
-
message: "launchKind must be requested_change or imported_plan",
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
const locatorError = config.validateRepoLocator(params.repoLocator);
|
|
121
|
-
if (locatorError) {
|
|
122
|
-
errors.push({
|
|
123
|
-
code: "invalid_repo_locator",
|
|
124
|
-
fieldId: "repoLocator",
|
|
125
|
-
message: locatorError,
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
if (params.workBranch && params.workBranch === params.baseBranch) {
|
|
129
|
-
errors.push({
|
|
130
|
-
code: "custom_rule",
|
|
131
|
-
fieldId: "workBranch",
|
|
132
|
-
message: "workBranch cannot match baseBranch",
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
if (!params.prompt) {
|
|
136
|
-
errors.push({ code: "required", fieldId: "prompt", message: "prompt is required" });
|
|
137
|
-
}
|
|
138
|
-
if (params.launchKind === "imported_plan" && !params.importedPlanMarkdown) {
|
|
139
|
-
errors.push({
|
|
140
|
-
code: "required",
|
|
141
|
-
fieldId: "importedPlanMarkdown",
|
|
142
|
-
message: "importedPlanMarkdown is required for imported_plan launches",
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
if (params.launchKind === "requested_change" && "importedPlanMarkdown" in input) {
|
|
146
|
-
errors.push({
|
|
147
|
-
code: "custom_rule",
|
|
148
|
-
fieldId: "importedPlanMarkdown",
|
|
149
|
-
message: "importedPlanMarkdown is not allowed for requested_change launches",
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
errors.push(...(config.validate?.(input, params) ?? []));
|
|
153
|
-
if (errors.length > 0) return { ok: false, errors };
|
|
154
|
-
|
|
155
|
-
const prepared = config.prepare?.(params) ?? params;
|
|
156
|
-
const hasWorkBranch = prepared.workBranch !== "";
|
|
157
|
-
return {
|
|
158
|
-
ok: true,
|
|
159
|
-
launchConfig: {
|
|
160
|
-
processId: config.processId,
|
|
161
|
-
params: prepared,
|
|
162
|
-
startTurnId:
|
|
163
|
-
config.deferWithoutWorkBranch && !hasWorkBranch
|
|
164
|
-
? null
|
|
165
|
-
: prepared.launchKind === "imported_plan"
|
|
166
|
-
? "import_plan"
|
|
167
|
-
: "generate_plan",
|
|
168
|
-
titleSourceFields: [{ label: "Requested change", value: prepared.prompt }],
|
|
169
|
-
metadata: metadata ?? null,
|
|
170
|
-
projects: [
|
|
171
|
-
{
|
|
172
|
-
key: "repo",
|
|
173
|
-
repoLocator: prepared.repoLocator,
|
|
174
|
-
baseBranch: prepared.baseBranch,
|
|
175
|
-
workBranch: hasWorkBranch ? prepared.workBranch : null,
|
|
176
|
-
},
|
|
177
|
-
],
|
|
178
|
-
},
|
|
179
|
-
};
|
|
180
|
-
},
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
export function createRepositoryChangeUiLauncher<T extends RepositoryChangeParamsBase>(config: {
|
|
185
|
-
id: string;
|
|
186
|
-
formId: string;
|
|
187
|
-
title: string;
|
|
188
|
-
workBranchDescription: string;
|
|
189
|
-
sshCredentials?: boolean;
|
|
190
|
-
resolveRelaunchInput?: UiLauncherDefinition<T>["resolveRelaunchInput"];
|
|
191
|
-
resolveLaunchConfig: UiLauncherDefinition<T>["resolveLaunchConfig"];
|
|
192
|
-
}): ProcessLauncherDefinition<T> {
|
|
193
|
-
return {
|
|
194
|
-
id: config.id,
|
|
195
|
-
label: config.title,
|
|
196
|
-
description: "Plan, implement, review, and finalize a change in a single git repository",
|
|
197
|
-
visibility: "ui",
|
|
198
|
-
ui: {
|
|
199
|
-
card: {
|
|
200
|
-
title: config.title,
|
|
201
|
-
description:
|
|
202
|
-
"Run a plan → implement → review → finalize loop against any local or remote git repository.",
|
|
203
|
-
},
|
|
204
|
-
launchConfigSchema: {
|
|
205
|
-
id: config.formId,
|
|
206
|
-
title: config.title,
|
|
207
|
-
fields: [
|
|
208
|
-
{
|
|
209
|
-
id: "repoLocator",
|
|
210
|
-
label: "Repository path or URL",
|
|
211
|
-
kind: "text",
|
|
212
|
-
required: true,
|
|
213
|
-
placeholder: "/path/to/repo or https://git.example.com/team/repo.git",
|
|
214
|
-
description: "Use a local checkout path or a remote Git URL.",
|
|
215
|
-
rememberRecentValues: true,
|
|
216
|
-
},
|
|
217
|
-
...(config.sshCredentials
|
|
218
|
-
? [
|
|
219
|
-
{
|
|
220
|
-
id: "sshCredentialRef",
|
|
221
|
-
label: "SSH credential profile",
|
|
222
|
-
kind: "text" as const,
|
|
223
|
-
required: true,
|
|
224
|
-
placeholder: "default",
|
|
225
|
-
description: "Profile from extensions.git-ssh.credentials.",
|
|
226
|
-
},
|
|
227
|
-
]
|
|
228
|
-
: []),
|
|
229
|
-
{
|
|
230
|
-
id: "baseBranch",
|
|
231
|
-
label: "Base branch",
|
|
232
|
-
kind: "text",
|
|
233
|
-
placeholder: "main",
|
|
234
|
-
description: "Leave this as main unless the change should merge somewhere else.",
|
|
235
|
-
},
|
|
236
|
-
{
|
|
237
|
-
id: "workBranch",
|
|
238
|
-
label: "Work branch",
|
|
239
|
-
kind: "text",
|
|
240
|
-
placeholder: "feature/my-change",
|
|
241
|
-
description: config.workBranchDescription,
|
|
242
|
-
},
|
|
243
|
-
{
|
|
244
|
-
id: "prompt",
|
|
245
|
-
label: "Requested change",
|
|
246
|
-
kind: "textarea",
|
|
247
|
-
required: true,
|
|
248
|
-
placeholder: "Describe the change this process should plan, implement, and review.",
|
|
249
|
-
},
|
|
250
|
-
],
|
|
251
|
-
submitLabel: "Start change",
|
|
252
|
-
},
|
|
253
|
-
resolveDefaults: () => ({
|
|
254
|
-
repoLocator: "",
|
|
255
|
-
...(config.sshCredentials ? { sshCredentialRef: "default" } : {}),
|
|
256
|
-
baseBranch: "main",
|
|
257
|
-
workBranch: "",
|
|
258
|
-
prompt: "",
|
|
259
|
-
}),
|
|
260
|
-
resolveRelaunchInput: config.resolveRelaunchInput,
|
|
261
|
-
resolveLaunchConfig: config.resolveLaunchConfig,
|
|
262
|
-
},
|
|
263
|
-
};
|
|
264
|
-
}
|
|
1
|
+
export type {
|
|
2
|
+
NormalizedRepositoryChangeParamsInput,
|
|
3
|
+
RepositoryChangeLaunchParams,
|
|
4
|
+
RepositoryChangeParamsBase,
|
|
5
|
+
} from "./repository-change-launch-internal.js";
|
|
6
|
+
export {
|
|
7
|
+
createRepositoryChangeParamsCodec,
|
|
8
|
+
normalizeRepositoryChangeParamsInput,
|
|
9
|
+
repositoryChangeParamsRecord,
|
|
10
|
+
} from "./repository-change-launch-internal.js";
|
|
@@ -19,54 +19,62 @@ import {
|
|
|
19
19
|
requestReviewChangesForm,
|
|
20
20
|
requestRevisionForm,
|
|
21
21
|
} from "./actions.js";
|
|
22
|
-
import { runDeterministicFinalization } from "./finalization-git.js";
|
|
23
22
|
import {
|
|
24
23
|
clearReviewRefs,
|
|
25
24
|
createEmptyRepositoryChangeFinalizationState,
|
|
26
25
|
type RepositoryChangeState,
|
|
27
26
|
repositoryChangeStateCodec,
|
|
28
|
-
|
|
29
|
-
} from "./repository-change-state.js";
|
|
27
|
+
} from "./repository-change-state-internal.js";
|
|
30
28
|
import {
|
|
31
29
|
buildGenerateCommitMessagePrompt,
|
|
32
30
|
normalizeGeneratedCommitMessage,
|
|
33
31
|
} from "./turns/generate-commit-message.js";
|
|
34
32
|
import { buildGeneratePlanPrompt } from "./turns/generate-plan.js";
|
|
35
33
|
import { buildImplementPrompt } from "./turns/implement.js";
|
|
36
|
-
import { buildResolveMergeConflictPrompt } from "./turns/resolve-merge-conflict.js";
|
|
37
34
|
import { buildReviewImplementationPrompt } from "./turns/review-implementation.js";
|
|
38
35
|
import { buildReviewPlanPrompt } from "./turns/review-plan.js";
|
|
39
36
|
import { buildSimplifyImplementationPrompt } from "./turns/simplify-implementation.js";
|
|
40
37
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
importedPlanMarkdown?: string;
|
|
44
|
-
};
|
|
38
|
+
/** @public */
|
|
39
|
+
export type RepositoryChangeParams = object;
|
|
45
40
|
|
|
41
|
+
/** @public */
|
|
46
42
|
export interface RepositoryChangeProcessConfig<TParams extends RepositoryChangeParams> {
|
|
43
|
+
/** @public */
|
|
47
44
|
processId: string;
|
|
45
|
+
/** @public */
|
|
48
46
|
displayName: string;
|
|
47
|
+
/** @public */
|
|
49
48
|
paramsCodec: Codec<TParams>;
|
|
49
|
+
/** @public */
|
|
50
50
|
launcher?: ProcessLauncherDefinition<TParams>;
|
|
51
|
+
/** @public */
|
|
51
52
|
finalizeLabel: string;
|
|
53
|
+
/** @public */
|
|
52
54
|
finalizeForm: FormDefinition;
|
|
53
|
-
|
|
55
|
+
/** @public */
|
|
54
56
|
repositoryCredentials?(input: {
|
|
57
|
+
/** @public */
|
|
55
58
|
params: TParams;
|
|
59
|
+
/** @internal */
|
|
56
60
|
projects: readonly RepositoryCredentialProject[];
|
|
57
61
|
}): readonly RepositoryCredentialRequirement[];
|
|
58
|
-
|
|
62
|
+
/** @public */
|
|
63
|
+
publication: {
|
|
64
|
+
/** @public */
|
|
59
65
|
entryTurnId: string;
|
|
66
|
+
/** @public */
|
|
60
67
|
fragment: FlowFragmentBuilder<TParams, RepositoryChangeState>;
|
|
68
|
+
/** @public */
|
|
61
69
|
happyPath?: readonly string[];
|
|
62
70
|
};
|
|
63
71
|
}
|
|
64
72
|
|
|
73
|
+
/** @public */
|
|
65
74
|
export function createRepositoryChangeProcess<TParams extends RepositoryChangeParams>(
|
|
66
75
|
config: RepositoryChangeProcessConfig<TParams>,
|
|
67
76
|
) {
|
|
68
77
|
const turnIds = {
|
|
69
|
-
importPlan: "import_plan",
|
|
70
78
|
generatePlan: "generate_plan",
|
|
71
79
|
planDecision: "plan_decision",
|
|
72
80
|
reviewPlan: "review_plan",
|
|
@@ -78,8 +86,6 @@ export function createRepositoryChangeProcess<TParams extends RepositoryChangePa
|
|
|
78
86
|
simplifyImplementation: "simplify_implementation",
|
|
79
87
|
simplificationDecision: "simplification_decision",
|
|
80
88
|
generateCommitMessage: "generate_commit_message",
|
|
81
|
-
commitAndMerge: "commit_and_merge",
|
|
82
|
-
resolveMergeConflict: "resolve_merge_conflict",
|
|
83
89
|
} as const;
|
|
84
90
|
|
|
85
91
|
const products = {
|
|
@@ -87,22 +93,11 @@ export function createRepositoryChangeProcess<TParams extends RepositoryChangePa
|
|
|
87
93
|
review: "review",
|
|
88
94
|
simplificationPlan: "simplification-plan",
|
|
89
95
|
implementationSummary: "implementation-summary",
|
|
90
|
-
mergeResolutionSummary: "merge-resolution-summary",
|
|
91
96
|
commitMessage: "commit-message",
|
|
92
97
|
} as const;
|
|
93
98
|
|
|
94
99
|
const implementationTurnAvailableTools = ["read", "bash", "edit", "write"] as const;
|
|
95
100
|
|
|
96
|
-
function resetFinalizationAfterMessage(
|
|
97
|
-
state: RepositoryChangeState,
|
|
98
|
-
overrides: Partial<RepositoryChangeState["finalization"]> = {},
|
|
99
|
-
) {
|
|
100
|
-
return resetRepositoryChangeFinalizationState({
|
|
101
|
-
generatedCommitMessage: state.finalization.generatedCommitMessage,
|
|
102
|
-
...overrides,
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
|
|
106
101
|
function hasResolvedTurnRecordRef(
|
|
107
102
|
ref: RepositoryChangeState["semanticEntryRefs"][keyof RepositoryChangeState["semanticEntryRefs"]],
|
|
108
103
|
): ref is { entryId: string; turnRecordId: string } {
|
|
@@ -318,7 +313,7 @@ export function createRepositoryChangeProcess<TParams extends RepositoryChangePa
|
|
|
318
313
|
},
|
|
319
314
|
],
|
|
320
315
|
commentary:
|
|
321
|
-
"
|
|
316
|
+
"Publish this implementation, request another pass, simplify it, or run an automated review.",
|
|
322
317
|
actions: {
|
|
323
318
|
[codingActionIds.finalizeChange]: {
|
|
324
319
|
label: config.finalizeLabel,
|
|
@@ -470,34 +465,6 @@ export function createRepositoryChangeProcess<TParams extends RepositoryChangePa
|
|
|
470
465
|
},
|
|
471
466
|
});
|
|
472
467
|
|
|
473
|
-
const importPlanTurn = flow
|
|
474
|
-
.automatic<TParams, RepositoryChangeState>(turnIds.importPlan)
|
|
475
|
-
.description("Import handoff plan")
|
|
476
|
-
.run((ctx) => {
|
|
477
|
-
const planMarkdown =
|
|
478
|
-
ctx.params.launchKind === "imported_plan"
|
|
479
|
-
? normalizeOptionalMarkdown(ctx.params.importedPlanMarkdown)
|
|
480
|
-
: null;
|
|
481
|
-
if (!planMarkdown) {
|
|
482
|
-
throw new Error("No importedPlanMarkdown is available to import");
|
|
483
|
-
}
|
|
484
|
-
return {
|
|
485
|
-
outcome: "imported",
|
|
486
|
-
params: { plan: planMarkdown },
|
|
487
|
-
markdown: planMarkdown,
|
|
488
|
-
};
|
|
489
|
-
})
|
|
490
|
-
.outcome("imported", (outcome) =>
|
|
491
|
-
outcome
|
|
492
|
-
.description("Imported a handoff plan and skipped replanning")
|
|
493
|
-
.markdown("plan", { description: "Imported handoff plan", publish: true })
|
|
494
|
-
.to(turnIds.implement)
|
|
495
|
-
.effect(({ ctx }) => ({
|
|
496
|
-
processPatch: { planRevision: ctx.process.planRevision + 1 },
|
|
497
|
-
state: clearReviewState(ctx.state),
|
|
498
|
-
})),
|
|
499
|
-
);
|
|
500
|
-
|
|
501
468
|
const generatePlanTurn = flow
|
|
502
469
|
.llm<TParams, RepositoryChangeState>(turnIds.generatePlan)
|
|
503
470
|
.description("Plan")
|
|
@@ -637,7 +604,7 @@ export function createRepositoryChangeProcess<TParams extends RepositoryChangePa
|
|
|
637
604
|
.consume(products.plan)
|
|
638
605
|
.buildPrompt(buildGenerateCommitMessagePrompt)
|
|
639
606
|
.publish(products.commitMessage)
|
|
640
|
-
.to(config.publication
|
|
607
|
+
.to(config.publication.entryTurnId)
|
|
641
608
|
.state(({ ctx }) =>
|
|
642
609
|
patchRepositoryChangeState(ctx.state, {
|
|
643
610
|
finalization: {
|
|
@@ -647,70 +614,8 @@ export function createRepositoryChangeProcess<TParams extends RepositoryChangePa
|
|
|
647
614
|
}),
|
|
648
615
|
);
|
|
649
616
|
|
|
650
|
-
const commitAndMergeTurn = flow
|
|
651
|
-
.automatic<TParams, RepositoryChangeState>(turnIds.commitAndMerge)
|
|
652
|
-
.description(config.finalizationDescription)
|
|
653
|
-
.run(runDeterministicFinalization)
|
|
654
|
-
.outcome("merge_conflict", (outcome) =>
|
|
655
|
-
outcome
|
|
656
|
-
.description("Deterministic merge hit conflicts and needs conflict resolution")
|
|
657
|
-
.requiredString("headSha", "The current HEAD sha while the merge conflict is active")
|
|
658
|
-
.stringArray("conflictedFiles", "Conflicted files that need resolution")
|
|
659
|
-
.string("fetchedBaseSha", "The fetched origin/<baseBranch> sha when available")
|
|
660
|
-
.to(turnIds.resolveMergeConflict)
|
|
661
|
-
.state(({ ctx }) =>
|
|
662
|
-
patchRepositoryChangeState(ctx.state, {
|
|
663
|
-
finalization: resetFinalizationAfterMessage(ctx.state),
|
|
664
|
-
}),
|
|
665
|
-
),
|
|
666
|
-
)
|
|
667
|
-
.outcome("finalized", (outcome) =>
|
|
668
|
-
outcome
|
|
669
|
-
.description("Deterministic finalization succeeded")
|
|
670
|
-
.requiredString("headSha", "The final HEAD sha")
|
|
671
|
-
.requiredString("mergeMode", "How origin/<baseBranch> was integrated")
|
|
672
|
-
.requiredString("pushTarget", "The final base-branch publish target")
|
|
673
|
-
.requiredBoolean("usedConflictResolution", "Whether the merge required conflict resolution")
|
|
674
|
-
.complete()
|
|
675
|
-
.state(({ ctx, event }) =>
|
|
676
|
-
patchRepositoryChangeState(ctx.state, {
|
|
677
|
-
finalization: resetFinalizationAfterMessage(ctx.state, {
|
|
678
|
-
usedConflictResolution:
|
|
679
|
-
event.params.usedConflictResolution === true ||
|
|
680
|
-
ctx.state.finalization.usedConflictResolution,
|
|
681
|
-
finalizationSummaryMarkdown: normalizeOptionalMarkdown(ctx.output?.content),
|
|
682
|
-
finalizedHeadSha: normalizeMessage(event.params.headSha),
|
|
683
|
-
}),
|
|
684
|
-
}),
|
|
685
|
-
),
|
|
686
|
-
);
|
|
687
|
-
|
|
688
|
-
const resolveMergeConflictTurn = flow
|
|
689
|
-
.llm<TParams, RepositoryChangeState>(turnIds.resolveMergeConflict)
|
|
690
|
-
.description("Resolve merge conflict")
|
|
691
|
-
.tools("read", "bash", "edit", "write")
|
|
692
|
-
.fullPrimary()
|
|
693
|
-
.startFromRoot()
|
|
694
|
-
.buildPrompt(buildResolveMergeConflictPrompt)
|
|
695
|
-
.outcomeTool("clean", (tool) =>
|
|
696
|
-
tool
|
|
697
|
-
.description("The merge conflict was resolved and the repository is clean")
|
|
698
|
-
.requiredString("headSha", "The post-resolution HEAD sha")
|
|
699
|
-
.to(turnIds.commitAndMerge)
|
|
700
|
-
.state(({ ctx, event }) =>
|
|
701
|
-
patchRepositoryChangeState(ctx.state, {
|
|
702
|
-
finalization: resetFinalizationAfterMessage(ctx.state, {
|
|
703
|
-
expectedPostConflictHeadSha: normalizeMessage(event.params.headSha),
|
|
704
|
-
usedConflictResolution: true,
|
|
705
|
-
}),
|
|
706
|
-
}),
|
|
707
|
-
),
|
|
708
|
-
)
|
|
709
|
-
.publish(products.mergeResolutionSummary);
|
|
710
|
-
|
|
711
617
|
const planFlow = flow
|
|
712
618
|
.fragment<TParams, RepositoryChangeState>("plan")
|
|
713
|
-
.turn(importPlanTurn)
|
|
714
619
|
.turn(generatePlanTurn)
|
|
715
620
|
.turn({ id: turnIds.planDecision, definition: planDecisionSpec })
|
|
716
621
|
.turn(reviewPlanTurn)
|
|
@@ -731,20 +636,16 @@ export function createRepositoryChangeProcess<TParams extends RepositoryChangePa
|
|
|
731
636
|
const finalizationFlow = flow
|
|
732
637
|
.fragment<TParams, RepositoryChangeState>("finalization")
|
|
733
638
|
.turn(generateCommitMessageTurn);
|
|
734
|
-
if (!config.publication) {
|
|
735
|
-
finalizationFlow.turn(commitAndMergeTurn).turn(resolveMergeConflictTurn);
|
|
736
|
-
}
|
|
737
639
|
|
|
738
640
|
const builder = flow
|
|
739
641
|
.process<TParams, RepositoryChangeState>(config.processId)
|
|
740
642
|
.displayName(config.displayName)
|
|
741
643
|
.entry(turnIds.generatePlan)
|
|
742
|
-
.alternateEntry(turnIds.importPlan)
|
|
743
644
|
.happyPath(
|
|
744
645
|
turnIds.generatePlan,
|
|
745
646
|
turnIds.implement,
|
|
746
647
|
turnIds.generateCommitMessage,
|
|
747
|
-
...(config.publication
|
|
648
|
+
...(config.publication.happyPath ?? [config.publication.entryTurnId]),
|
|
748
649
|
)
|
|
749
650
|
.piConfig({ sessionCwdTemplate: "{{{projectKey}}}" })
|
|
750
651
|
.codecs({
|
|
@@ -759,21 +660,30 @@ export function createRepositoryChangeProcess<TParams extends RepositoryChangePa
|
|
|
759
660
|
.use(planFlow)
|
|
760
661
|
.use(implementationFlow)
|
|
761
662
|
.use(finalizationFlow);
|
|
762
|
-
|
|
663
|
+
builder.use(config.publication.fragment);
|
|
763
664
|
if (config.repositoryCredentials) builder.repositoryCredentials(config.repositoryCredentials);
|
|
764
665
|
if (config.launcher) builder.launcher(config.launcher);
|
|
765
666
|
const process = builder.define();
|
|
766
667
|
const decision = (id: string) =>
|
|
767
668
|
({
|
|
669
|
+
/** @public */
|
|
768
670
|
id,
|
|
769
671
|
...(process.turns.get(id)?.definition as HumanTurnDefinition),
|
|
770
|
-
}) as HumanTurnDefinition & {
|
|
672
|
+
}) as HumanTurnDefinition & {
|
|
673
|
+
/** @public */ id: string;
|
|
674
|
+
};
|
|
771
675
|
return {
|
|
676
|
+
/** @public */
|
|
772
677
|
process,
|
|
678
|
+
/** @internal */
|
|
773
679
|
planDecision: decision(turnIds.planDecision),
|
|
680
|
+
/** @internal */
|
|
774
681
|
planReviewFeedback: decision(turnIds.planReviewFeedback),
|
|
682
|
+
/** @internal */
|
|
775
683
|
implementationDecision: decision(turnIds.implementationDecision),
|
|
684
|
+
/** @internal */
|
|
776
685
|
implementationReviewFeedback: decision(turnIds.implementationReviewFeedback),
|
|
686
|
+
/** @internal */
|
|
777
687
|
simplificationDecision: decision(turnIds.simplificationDecision),
|
|
778
688
|
};
|
|
779
689
|
}
|