@leitwerk-dev/coding 0.3.1 → 0.4.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 +86 -1
- package/dist/chunk-ABQH2WZT.js +36 -0
- package/dist/chunk-ABQH2WZT.js.map +1 -0
- package/dist/{chunk-YSC5GEQJ.js → chunk-BI45R2FH.js} +7 -3
- package/dist/chunk-BI45R2FH.js.map +1 -0
- package/dist/chunk-DNG7D77K.js +65 -0
- package/dist/chunk-DNG7D77K.js.map +1 -0
- package/dist/chunk-L2TFD72B.js +16320 -0
- package/dist/chunk-L2TFD72B.js.map +1 -0
- package/dist/chunk-M2VTUPFO.js +265 -0
- package/dist/chunk-M2VTUPFO.js.map +1 -0
- package/dist/chunk-OM2AMDTJ.js +347 -0
- package/dist/chunk-OM2AMDTJ.js.map +1 -0
- package/dist/chunk-Q24RPXOA.js +159 -0
- package/dist/chunk-Q24RPXOA.js.map +1 -0
- package/dist/chunk-SKGB4CZS.js +14 -0
- package/dist/chunk-SKGB4CZS.js.map +1 -0
- package/dist/chunk-SZ4WOGV2.js +120 -0
- package/dist/chunk-SZ4WOGV2.js.map +1 -0
- package/dist/finalization-git-internal.d.ts +3 -0
- package/dist/finalization-git-internal.d.ts.map +1 -1
- package/dist/finalization-git.d.ts +1 -1
- package/dist/finalization-git.d.ts.map +1 -1
- package/dist/finalization-git.js +5 -3
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -591
- package/dist/index.js.map +1 -1
- package/dist/pull-request-publication-internal.d.ts +26 -24
- package/dist/pull-request-publication-internal.d.ts.map +1 -1
- package/dist/repository-change-launch-internal-BudnAfL7.d.ts +88 -0
- package/dist/repository-change-launch-internal.d.ts +32 -11
- package/dist/repository-change-launch-internal.d.ts.map +1 -1
- package/dist/repository-change-launch.d.ts +4 -3
- package/dist/repository-change-launch.d.ts.map +1 -1
- package/dist/repository-change-launch.js +162 -34
- package/dist/repository-change-launch.js.map +1 -1
- package/dist/repository-change-process-DlgF04fU.d.ts +69 -0
- package/dist/repository-change-process.d.ts +30 -25
- package/dist/repository-change-process.d.ts.map +1 -1
- package/dist/repository-change-publication.d.ts +62 -6
- package/dist/repository-change-publication.d.ts.map +1 -1
- package/dist/repository-change-publication.js +364 -90
- package/dist/repository-change-publication.js.map +1 -1
- package/dist/repository-change-state-internal.d.ts +18 -4
- package/dist/repository-change-state-internal.d.ts.map +1 -1
- package/dist/repository-change-ui-launcher-internal.d.ts +34 -22
- package/dist/repository-change-ui-launcher-internal.d.ts.map +1 -1
- package/dist/settings.d.ts +15 -0
- package/dist/settings.d.ts.map +1 -0
- package/dist/turns/commit-message-evidence.d.ts +35 -0
- package/dist/turns/commit-message-evidence.d.ts.map +1 -0
- package/dist/turns/commit-message-evidence.js +9 -0
- package/dist/turns/generate-commit-message.d.ts +4 -1
- package/dist/turns/generate-commit-message.d.ts.map +1 -1
- package/dist/turns/generate-commit-message.js +7 -5
- package/dist/turns/generate-plan.d.ts.map +1 -1
- package/dist/turns/generate-plan.js +1 -1
- package/dist/turns/git-inspection-profile.d.ts +25 -0
- package/dist/turns/git-inspection-profile.d.ts.map +1 -0
- package/dist/turns/git-inspection-profile.js +8 -0
- package/dist/turns/implement.d.ts.map +1 -1
- package/dist/turns/implement.js +1 -1
- package/dist/turns/simplify-implementation.d.ts +1 -1
- package/dist/turns/simplify-implementation.d.ts.map +1 -1
- package/dist/turns/simplify-implementation.js +3 -3
- package/package.json +5 -9
- package/src/finalization-git-internal.ts +117 -114
- package/src/finalization-git.ts +1 -1
- package/src/index.ts +4 -1
- package/src/pull-request-publication-internal.ts +156 -78
- package/src/repository-change-launch-internal.ts +119 -12
- package/src/repository-change-launch.ts +8 -4
- package/src/repository-change-process.ts +234 -523
- package/src/repository-change-publication.ts +516 -121
- package/src/repository-change-state-internal.ts +34 -20
- package/src/repository-change-ui-launcher-internal.ts +139 -56
- package/src/settings.ts +79 -0
- package/src/turns/commit-message-evidence.ts +241 -0
- package/src/turns/generate-commit-message.ts +53 -23
- package/src/turns/generate-plan.ts +26 -12
- package/src/turns/git-inspection-profile.ts +134 -0
- package/src/turns/implement.ts +9 -2
- package/src/turns/simplify-implementation.ts +10 -6
- package/dist/chunk-34B3Q75M.js +0 -25
- package/dist/chunk-34B3Q75M.js.map +0 -1
- package/dist/chunk-F6CEEAFE.js +0 -13
- package/dist/chunk-F6CEEAFE.js.map +0 -1
- package/dist/chunk-GO44KCUS.js +0 -154
- package/dist/chunk-GO44KCUS.js.map +0 -1
- package/dist/chunk-R3UCUGY6.js +0 -31
- package/dist/chunk-R3UCUGY6.js.map +0 -1
- package/dist/chunk-W7VJT6AN.js +0 -25
- package/dist/chunk-W7VJT6AN.js.map +0 -1
- package/dist/chunk-WKHVLLKE.js +0 -45
- package/dist/chunk-WKHVLLKE.js.map +0 -1
- package/dist/chunk-YSC5GEQJ.js.map +0 -1
- package/dist/repository-change-launch-internal-Dd-AONUs.d.ts +0 -67
- package/dist/turns/review-implementation.d.ts +0 -4
- package/dist/turns/review-implementation.d.ts.map +0 -1
- package/dist/turns/review-implementation.js +0 -8
- package/dist/turns/review-plan.d.ts +0 -4
- package/dist/turns/review-plan.d.ts.map +0 -1
- package/dist/turns/review-plan.js +0 -8
- package/src/turns/review-implementation.ts +0 -30
- package/src/turns/review-plan.ts +0 -24
- /package/dist/turns/{review-implementation.js.map → commit-message-evidence.js.map} +0 -0
- /package/dist/turns/{review-plan.js.map → git-inspection-profile.js.map} +0 -0
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
import {
|
|
2
|
+
GitTrace2Collector
|
|
3
|
+
} from "./chunk-SZ4WOGV2.js";
|
|
4
|
+
|
|
5
|
+
// src/turns/commit-message-evidence.ts
|
|
6
|
+
import { spawn } from "child_process";
|
|
7
|
+
import { chmod, copyFile, mkdtemp, rm, stat, utimes } from "fs/promises";
|
|
8
|
+
import { tmpdir } from "os";
|
|
9
|
+
import path from "path";
|
|
10
|
+
import {
|
|
11
|
+
repositoryGitArgs,
|
|
12
|
+
sanitizeWorkerSubprocessEnv
|
|
13
|
+
} from "@leitwerk-dev/process-sdk";
|
|
14
|
+
import { resolveGitBinary } from "@leitwerk-dev/process-sdk/git-binary";
|
|
15
|
+
|
|
16
|
+
// src/settings.ts
|
|
17
|
+
var codingPurposes = {
|
|
18
|
+
/** @public */
|
|
19
|
+
planning: "coding.planning",
|
|
20
|
+
/** @public */
|
|
21
|
+
implementation: "coding.implementation",
|
|
22
|
+
/** @public */
|
|
23
|
+
review: "coding.review"
|
|
24
|
+
};
|
|
25
|
+
var commitMessageGitTimeout = {
|
|
26
|
+
key: "coding.commit_message_git_timeout_ms",
|
|
27
|
+
schemaVersion: 1,
|
|
28
|
+
scopes: ["instance", "repository"],
|
|
29
|
+
merge: "replace",
|
|
30
|
+
defaultValue: 6e4,
|
|
31
|
+
schema: {
|
|
32
|
+
parse(value) {
|
|
33
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value) || value <= 0 || value > 2147483647) {
|
|
34
|
+
throw new Error(
|
|
35
|
+
"Git timeout must be a positive integer of at most 2147483647 milliseconds"
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
return value;
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
form: {
|
|
42
|
+
label: "Commit-message Git timeout (milliseconds)",
|
|
43
|
+
group: "Implementation",
|
|
44
|
+
control: "number",
|
|
45
|
+
description: "Deadline per Git inspection command. Defaults to 60000 ms (60 seconds)."
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
function model(key, label, group) {
|
|
49
|
+
return {
|
|
50
|
+
key,
|
|
51
|
+
schemaVersion: 1,
|
|
52
|
+
scopes: ["instance", "repository"],
|
|
53
|
+
merge: "replace",
|
|
54
|
+
defaultValue: null,
|
|
55
|
+
schema: {
|
|
56
|
+
parse(value) {
|
|
57
|
+
if (value === null || typeof value === "string" && value.length > 0) return value;
|
|
58
|
+
throw new Error("Choose a model profile or inherit the runtime default");
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
form: {
|
|
62
|
+
label,
|
|
63
|
+
group,
|
|
64
|
+
control: "model",
|
|
65
|
+
description: "Used by future steps unless the process has an explicit model choice."
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
var codingSettings = {
|
|
70
|
+
settings: [
|
|
71
|
+
model("coding.planning_model", "Planning model", "Planning"),
|
|
72
|
+
model("coding.implementation_model", "Implementation model", "Implementation"),
|
|
73
|
+
model("coding.review_model", "Review model", "Review"),
|
|
74
|
+
commitMessageGitTimeout
|
|
75
|
+
],
|
|
76
|
+
purposes: Object.entries(codingPurposes).map(([name, id]) => ({
|
|
77
|
+
id,
|
|
78
|
+
label: name,
|
|
79
|
+
modelSettingKey: `coding.${name}_model`,
|
|
80
|
+
...name === "implementation" ? { settingKeys: [commitMessageGitTimeout.key] } : {}
|
|
81
|
+
}))
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
// src/turns/commit-message-evidence.ts
|
|
85
|
+
var MAX_SNAPSHOT_BYTES = 60 * 1024;
|
|
86
|
+
function inspectionEnv(indexFile) {
|
|
87
|
+
const env = sanitizeWorkerSubprocessEnv(process.env);
|
|
88
|
+
for (const key of Object.keys(env)) {
|
|
89
|
+
if (key.startsWith("GIT_TRACE") || key === "GIT_INDEX_FILE") delete env[key];
|
|
90
|
+
}
|
|
91
|
+
return {
|
|
92
|
+
...env,
|
|
93
|
+
...indexFile ? { GIT_INDEX_FILE: indexFile } : {},
|
|
94
|
+
GIT_OPTIONAL_LOCKS: indexFile ? "1" : "0",
|
|
95
|
+
GIT_TERMINAL_PROMPT: "0",
|
|
96
|
+
GIT_TRACE2: "0",
|
|
97
|
+
GIT_TRACE2_PERF: "0",
|
|
98
|
+
GIT_TRACE2_EVENT: "3"
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
async function readGit(ctx, command, args) {
|
|
102
|
+
const started = performance.now();
|
|
103
|
+
const trace = new GitTrace2Collector();
|
|
104
|
+
let exitCode = null;
|
|
105
|
+
let exitSignal = null;
|
|
106
|
+
let timedOut = false;
|
|
107
|
+
let succeeded = false;
|
|
108
|
+
let outputBytes = 0;
|
|
109
|
+
try {
|
|
110
|
+
const output = await new Promise((resolve, reject) => {
|
|
111
|
+
const child = spawn(
|
|
112
|
+
resolveGitBinary(),
|
|
113
|
+
repositoryGitArgs([
|
|
114
|
+
...ctx.indexFile ? ["-c", "core.splitIndex=false", "-c", "splitIndex.sharedIndexExpire=never"] : ["--no-optional-locks"],
|
|
115
|
+
"-c",
|
|
116
|
+
"core.fsmonitor=false",
|
|
117
|
+
...args
|
|
118
|
+
]),
|
|
119
|
+
{
|
|
120
|
+
cwd: ctx.cwd,
|
|
121
|
+
env: inspectionEnv(ctx.indexFile),
|
|
122
|
+
stdio: ["ignore", "pipe", "ignore", "pipe"],
|
|
123
|
+
timeout: ctx.timeoutMs
|
|
124
|
+
}
|
|
125
|
+
);
|
|
126
|
+
child.stdio[3]?.on("data", (chunk) => trace.write(chunk));
|
|
127
|
+
const chunks = [];
|
|
128
|
+
let bytes = 0;
|
|
129
|
+
let truncated = false;
|
|
130
|
+
child.stdout?.on("data", (chunk) => {
|
|
131
|
+
outputBytes += chunk.length;
|
|
132
|
+
const remaining = MAX_SNAPSHOT_BYTES - bytes;
|
|
133
|
+
if (chunk.length > remaining) truncated = true;
|
|
134
|
+
const retained = chunk.subarray(0, remaining);
|
|
135
|
+
if (retained.length) chunks.push(retained);
|
|
136
|
+
bytes += retained.length;
|
|
137
|
+
});
|
|
138
|
+
child.once("error", reject);
|
|
139
|
+
child.once("close", (code, signal) => {
|
|
140
|
+
exitCode = code;
|
|
141
|
+
exitSignal = signal;
|
|
142
|
+
timedOut = child.killed;
|
|
143
|
+
if (code !== 0) {
|
|
144
|
+
if (timedOut) {
|
|
145
|
+
reject(
|
|
146
|
+
new Error(
|
|
147
|
+
`Cannot inspect '${ctx.key}': git ${args[0]} timed out after ${ctx.timeoutMs}ms`
|
|
148
|
+
)
|
|
149
|
+
);
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
reject(
|
|
153
|
+
new Error(`Cannot inspect '${ctx.key}': git ${args[0]} failed (${signal ?? code})`)
|
|
154
|
+
);
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
resolve({ text: Buffer.concat(chunks).toString("utf8"), truncated });
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
succeeded = true;
|
|
161
|
+
return output;
|
|
162
|
+
} finally {
|
|
163
|
+
const report = {
|
|
164
|
+
level: succeeded ? "info" : "warn",
|
|
165
|
+
code: "coding.git_inspection",
|
|
166
|
+
message: "Commit-message Git inspection command completed",
|
|
167
|
+
details: {
|
|
168
|
+
repository: ctx.key,
|
|
169
|
+
command,
|
|
170
|
+
durationMs: Math.round((performance.now() - started) * 1e3) / 1e3,
|
|
171
|
+
timeoutMs: ctx.timeoutMs,
|
|
172
|
+
outcome: succeeded ? "succeeded" : timedOut ? "timed_out" : "failed",
|
|
173
|
+
exitCode,
|
|
174
|
+
signal: exitSignal,
|
|
175
|
+
outputBytes,
|
|
176
|
+
trace2: trace.finish()
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
try {
|
|
180
|
+
ctx.reportDiagnostic?.(report);
|
|
181
|
+
} catch {
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
async function prepareRepositoryCommitMessageEvidence(ctx) {
|
|
186
|
+
const capturedTimeout = ctx.scopedSettings?.values.find(
|
|
187
|
+
({ key }) => key === commitMessageGitTimeout.key
|
|
188
|
+
);
|
|
189
|
+
const timeoutMs = commitMessageGitTimeout.schema.parse(
|
|
190
|
+
capturedTimeout ? capturedTimeout.value : commitMessageGitTimeout.defaultValue
|
|
191
|
+
);
|
|
192
|
+
const repositories = [];
|
|
193
|
+
for (const project of ctx.projects) {
|
|
194
|
+
const cwd = ctx.repo.get(project.key).fsPath;
|
|
195
|
+
const inspection = { key: project.key, cwd, timeoutMs, reportDiagnostic: ctx.reportDiagnostic };
|
|
196
|
+
const head = await readGit(inspection, "rev-parse.head", ["rev-parse", "HEAD"]);
|
|
197
|
+
const indexPath = await readGit(inspection, "rev-parse.index", [
|
|
198
|
+
"rev-parse",
|
|
199
|
+
"--path-format=absolute",
|
|
200
|
+
"--git-path",
|
|
201
|
+
"index"
|
|
202
|
+
]);
|
|
203
|
+
if (indexPath.truncated)
|
|
204
|
+
throw new Error(`Cannot inspect '${project.key}': Git index path too long`);
|
|
205
|
+
const scratch = await mkdtemp(path.join(tmpdir(), "leitwerk-git-inspection-"));
|
|
206
|
+
try {
|
|
207
|
+
const indexFile = path.join(scratch, "index");
|
|
208
|
+
try {
|
|
209
|
+
const originalIndex = indexPath.text.replace(/\n$/, "");
|
|
210
|
+
const metadata = await stat(originalIndex);
|
|
211
|
+
await copyFile(originalIndex, indexFile);
|
|
212
|
+
await chmod(indexFile, 384);
|
|
213
|
+
await utimes(indexFile, metadata.atime, metadata.mtime);
|
|
214
|
+
} catch (error) {
|
|
215
|
+
if (error.code !== "ENOENT") throw error;
|
|
216
|
+
}
|
|
217
|
+
const git = (command, args) => readGit({ ...inspection, indexFile }, command, args);
|
|
218
|
+
const status = await git("status", ["status", "--porcelain=v1", "--untracked-files=all"]);
|
|
219
|
+
const diffOptions = ["--no-ext-diff", "--no-textconv", "--no-color"];
|
|
220
|
+
const stagedDiff = await git("diff.staged", ["diff", "--cached", ...diffOptions]);
|
|
221
|
+
const unstagedDiff = await git("diff.unstaged", ["diff", ...diffOptions]);
|
|
222
|
+
const untrackedFiles = await git("ls-files.untracked", [
|
|
223
|
+
"ls-files",
|
|
224
|
+
"--others",
|
|
225
|
+
"--exclude-standard"
|
|
226
|
+
]);
|
|
227
|
+
repositories.push({
|
|
228
|
+
key: project.key,
|
|
229
|
+
path: cwd,
|
|
230
|
+
head: head.text.trim(),
|
|
231
|
+
status,
|
|
232
|
+
stagedDiff,
|
|
233
|
+
unstagedDiff,
|
|
234
|
+
untrackedFiles
|
|
235
|
+
});
|
|
236
|
+
} finally {
|
|
237
|
+
await rm(scratch, { recursive: true, force: true });
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
const prepared = { repositories };
|
|
241
|
+
const outputs = repositories.flatMap((repo) => [
|
|
242
|
+
repo.status,
|
|
243
|
+
repo.stagedDiff,
|
|
244
|
+
repo.unstagedDiff,
|
|
245
|
+
repo.untrackedFiles
|
|
246
|
+
]);
|
|
247
|
+
while (Buffer.byteLength(JSON.stringify(prepared), "utf8") > MAX_SNAPSHOT_BYTES) {
|
|
248
|
+
const largest = outputs.reduce(
|
|
249
|
+
(current, output) => !current || output.text.length > current.text.length ? output : current,
|
|
250
|
+
void 0
|
|
251
|
+
);
|
|
252
|
+
if (!largest?.text.length) throw new Error("Repository identities exceed the evidence limit");
|
|
253
|
+
largest.text = largest.text.slice(0, Math.floor(largest.text.length / 2));
|
|
254
|
+
largest.truncated = true;
|
|
255
|
+
}
|
|
256
|
+
return prepared;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
export {
|
|
260
|
+
codingPurposes,
|
|
261
|
+
commitMessageGitTimeout,
|
|
262
|
+
codingSettings,
|
|
263
|
+
prepareRepositoryCommitMessageEvidence
|
|
264
|
+
};
|
|
265
|
+
//# sourceMappingURL=chunk-M2VTUPFO.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/turns/commit-message-evidence.ts","../src/settings.ts"],"sourcesContent":["import { spawn } from \"node:child_process\";\nimport { chmod, copyFile, mkdtemp, rm, stat, utimes } from \"node:fs/promises\";\nimport { tmpdir } from \"node:os\";\nimport path from \"node:path\";\nimport type { ScopedSettingsSnapshot } from \"@leitwerk-dev/domain\";\nimport {\n\trepositoryGitArgs,\n\tsanitizeWorkerSubprocessEnv,\n\ttype TurnDiagnosticReport,\n} from \"@leitwerk-dev/process-sdk\";\nimport { resolveGitBinary } from \"@leitwerk-dev/process-sdk/git-binary\";\nimport { commitMessageGitTimeout } from \"../settings.js\";\nimport { GitTrace2Collector } from \"./git-inspection-profile.js\";\n\ninterface GitOutput {\n\ttext: string;\n\ttruncated: boolean;\n}\n\ninterface RepositoryChanges {\n\tkey: string;\n\tpath: string;\n\thead: string;\n\tstatus: GitOutput;\n\tstagedDiff: GitOutput;\n\tunstagedDiff: GitOutput;\n\tuntrackedFiles: GitOutput;\n}\n\n/** @internal */\nexport interface RepositoryCommitMessagePreparation {\n\t/** @internal */\n\trepositories: RepositoryChanges[];\n}\n\n// Preparation checkpoints have a 64 KiB limit. Leave room for checkpoint metadata.\nconst MAX_SNAPSHOT_BYTES = 60 * 1024;\n\ninterface GitInspectionContext {\n\tkey: string;\n\tcwd: string;\n\ttimeoutMs: number;\n\tindexFile?: string;\n\treportDiagnostic?: (report: TurnDiagnosticReport) => void;\n}\n\nfunction inspectionEnv(indexFile: string | undefined): NodeJS.ProcessEnv {\n\tconst env = sanitizeWorkerSubprocessEnv(process.env);\n\t// Ambient index selection and trace destinations must not change this inspection\n\t// or persist raw Trace2 events. Only fd 3 receives our temporary trace stream.\n\tfor (const key of Object.keys(env)) {\n\t\tif (key.startsWith(\"GIT_TRACE\") || key === \"GIT_INDEX_FILE\") delete env[key];\n\t}\n\treturn {\n\t\t...env,\n\t\t...(indexFile ? { GIT_INDEX_FILE: indexFile } : {}),\n\t\tGIT_OPTIONAL_LOCKS: indexFile ? \"1\" : \"0\",\n\t\tGIT_TERMINAL_PROMPT: \"0\",\n\t\tGIT_TRACE2: \"0\",\n\t\tGIT_TRACE2_PERF: \"0\",\n\t\tGIT_TRACE2_EVENT: \"3\",\n\t};\n}\n\nasync function readGit(\n\tctx: GitInspectionContext,\n\tcommand: string,\n\targs: string[],\n): Promise<GitOutput> {\n\tconst started = performance.now();\n\tconst trace = new GitTrace2Collector();\n\tlet exitCode: number | null = null;\n\tlet exitSignal: NodeJS.Signals | null = null;\n\tlet timedOut = false;\n\tlet succeeded = false;\n\tlet outputBytes = 0;\n\ttry {\n\t\tconst output = await new Promise<GitOutput>((resolve, reject) => {\n\t\t\tconst child = spawn(\n\t\t\t\tresolveGitBinary(),\n\t\t\t\trepositoryGitArgs([\n\t\t\t\t\t...(ctx.indexFile\n\t\t\t\t\t\t? [\"-c\", \"core.splitIndex=false\", \"-c\", \"splitIndex.sharedIndexExpire=never\"]\n\t\t\t\t\t\t: [\"--no-optional-locks\"]),\n\t\t\t\t\t\"-c\",\n\t\t\t\t\t\"core.fsmonitor=false\",\n\t\t\t\t\t...args,\n\t\t\t\t]),\n\t\t\t\t{\n\t\t\t\t\tcwd: ctx.cwd,\n\t\t\t\t\tenv: inspectionEnv(ctx.indexFile),\n\t\t\t\t\tstdio: [\"ignore\", \"pipe\", \"ignore\", \"pipe\"],\n\t\t\t\t\ttimeout: ctx.timeoutMs,\n\t\t\t\t},\n\t\t\t);\n\t\t\tchild.stdio[3]?.on(\"data\", (chunk: Buffer) => trace.write(chunk));\n\t\t\tconst chunks: Buffer[] = [];\n\t\t\tlet bytes = 0;\n\t\t\tlet truncated = false;\n\t\t\tchild.stdout?.on(\"data\", (chunk: Buffer) => {\n\t\t\t\toutputBytes += chunk.length;\n\t\t\t\tconst remaining = MAX_SNAPSHOT_BYTES - bytes;\n\t\t\t\tif (chunk.length > remaining) truncated = true;\n\t\t\t\tconst retained = chunk.subarray(0, remaining);\n\t\t\t\tif (retained.length) chunks.push(retained);\n\t\t\t\tbytes += retained.length;\n\t\t\t});\n\t\t\tchild.once(\"error\", reject);\n\t\t\tchild.once(\"close\", (code, signal) => {\n\t\t\t\texitCode = code;\n\t\t\t\texitSignal = signal;\n\t\t\t\ttimedOut = child.killed;\n\t\t\t\tif (code !== 0) {\n\t\t\t\t\tif (timedOut) {\n\t\t\t\t\t\treject(\n\t\t\t\t\t\t\tnew Error(\n\t\t\t\t\t\t\t\t`Cannot inspect '${ctx.key}': git ${args[0]} timed out after ${ctx.timeoutMs}ms`,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\treject(\n\t\t\t\t\t\tnew Error(`Cannot inspect '${ctx.key}': git ${args[0]} failed (${signal ?? code})`),\n\t\t\t\t\t);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tresolve({ text: Buffer.concat(chunks).toString(\"utf8\"), truncated });\n\t\t\t});\n\t\t});\n\t\tsucceeded = true;\n\t\treturn output;\n\t} finally {\n\t\tconst report: TurnDiagnosticReport = {\n\t\t\tlevel: succeeded ? \"info\" : \"warn\",\n\t\t\tcode: \"coding.git_inspection\",\n\t\t\tmessage: \"Commit-message Git inspection command completed\",\n\t\t\tdetails: {\n\t\t\t\trepository: ctx.key,\n\t\t\t\tcommand,\n\t\t\t\tdurationMs: Math.round((performance.now() - started) * 1_000) / 1_000,\n\t\t\t\ttimeoutMs: ctx.timeoutMs,\n\t\t\t\toutcome: succeeded ? \"succeeded\" : timedOut ? \"timed_out\" : \"failed\",\n\t\t\t\texitCode,\n\t\t\t\tsignal: exitSignal,\n\t\t\t\toutputBytes,\n\t\t\t\ttrace2: trace.finish(),\n\t\t\t},\n\t\t};\n\t\t// Diagnostics are best-effort and must not replace a Git result or failure.\n\t\ttry {\n\t\t\tctx.reportDiagnostic?.(report);\n\t\t} catch {}\n\t}\n}\n\n/** @internal */\nexport async function prepareRepositoryCommitMessageEvidence(ctx: {\n\tprojects: readonly { key: string }[];\n\trepo: { get(key: string): { fsPath: string } };\n\tscopedSettings?: ScopedSettingsSnapshot;\n\treportDiagnostic?: (report: TurnDiagnosticReport) => void;\n}): Promise<RepositoryCommitMessagePreparation> {\n\tconst capturedTimeout = ctx.scopedSettings?.values.find(\n\t\t({ key }) => key === commitMessageGitTimeout.key,\n\t);\n\tconst timeoutMs = commitMessageGitTimeout.schema.parse(\n\t\tcapturedTimeout ? capturedTimeout.value : commitMessageGitTimeout.defaultValue,\n\t);\n\tconst repositories: RepositoryChanges[] = [];\n\tfor (const project of ctx.projects) {\n\t\tconst cwd = ctx.repo.get(project.key).fsPath;\n\t\tconst inspection = { key: project.key, cwd, timeoutMs, reportDiagnostic: ctx.reportDiagnostic };\n\t\tconst head = await readGit(inspection, \"rev-parse.head\", [\"rev-parse\", \"HEAD\"]);\n\t\tconst indexPath = await readGit(inspection, \"rev-parse.index\", [\n\t\t\t\"rev-parse\",\n\t\t\t\"--path-format=absolute\",\n\t\t\t\"--git-path\",\n\t\t\t\"index\",\n\t\t]);\n\t\tif (indexPath.truncated)\n\t\t\tthrow new Error(`Cannot inspect '${project.key}': Git index path too long`);\n\t\tconst scratch = await mkdtemp(path.join(tmpdir(), \"leitwerk-git-inspection-\"));\n\t\ttry {\n\t\t\tconst indexFile = path.join(scratch, \"index\");\n\t\t\ttry {\n\t\t\t\tconst originalIndex = indexPath.text.replace(/\\n$/, \"\");\n\t\t\t\tconst metadata = await stat(originalIndex);\n\t\t\t\tawait copyFile(originalIndex, indexFile);\n\t\t\t\tawait chmod(indexFile, 0o600);\n\t\t\t\t// A newer copy timestamp could hide racy-clean entries. Millisecond\n\t\t\t\t// rounding moves this timestamp earlier, conservatively retaining scans.\n\t\t\t\tawait utimes(indexFile, metadata.atime, metadata.mtime);\n\t\t\t} catch (error) {\n\t\t\t\t// An absent index is a valid checkout state. Git may create only the scratch copy.\n\t\t\t\tif ((error as NodeJS.ErrnoException).code !== \"ENOENT\") throw error;\n\t\t\t}\n\t\t\t// Status can persist refreshed stat data here. Later diffs reuse it without\n\t\t\t// rehashing clean files or updating the checkout's staging state.\n\t\t\tconst git = (command: string, args: string[]) =>\n\t\t\t\treadGit({ ...inspection, indexFile }, command, args);\n\t\t\tconst status = await git(\"status\", [\"status\", \"--porcelain=v1\", \"--untracked-files=all\"]);\n\t\t\tconst diffOptions = [\"--no-ext-diff\", \"--no-textconv\", \"--no-color\"];\n\t\t\tconst stagedDiff = await git(\"diff.staged\", [\"diff\", \"--cached\", ...diffOptions]);\n\t\t\tconst unstagedDiff = await git(\"diff.unstaged\", [\"diff\", ...diffOptions]);\n\t\t\tconst untrackedFiles = await git(\"ls-files.untracked\", [\n\t\t\t\t\"ls-files\",\n\t\t\t\t\"--others\",\n\t\t\t\t\"--exclude-standard\",\n\t\t\t]);\n\t\t\trepositories.push({\n\t\t\t\tkey: project.key,\n\t\t\t\tpath: cwd,\n\t\t\t\thead: head.text.trim(),\n\t\t\t\tstatus,\n\t\t\t\tstagedDiff,\n\t\t\t\tunstagedDiff,\n\t\t\t\tuntrackedFiles,\n\t\t\t});\n\t\t} finally {\n\t\t\tawait rm(scratch, { recursive: true, force: true });\n\t\t}\n\t}\n\tconst prepared = { repositories };\n\tconst outputs = repositories.flatMap((repo) => [\n\t\trepo.status,\n\t\trepo.stagedDiff,\n\t\trepo.unstagedDiff,\n\t\trepo.untrackedFiles,\n\t]);\n\twhile (Buffer.byteLength(JSON.stringify(prepared), \"utf8\") > MAX_SNAPSHOT_BYTES) {\n\t\tconst largest = outputs.reduce<GitOutput | undefined>(\n\t\t\t(current, output) =>\n\t\t\t\t!current || output.text.length > current.text.length ? output : current,\n\t\t\tundefined,\n\t\t);\n\t\tif (!largest?.text.length) throw new Error(\"Repository identities exceed the evidence limit\");\n\t\tlargest.text = largest.text.slice(0, Math.floor(largest.text.length / 2));\n\t\tlargest.truncated = true;\n\t}\n\treturn prepared;\n}\n","import type { ScopedSettingsDeclaration, SettingDefinition } from \"@leitwerk-dev/process-sdk\";\n\n/** @public */\nexport const codingPurposes = {\n\t/** @public */\n\tplanning: \"coding.planning\",\n\t/** @public */\n\timplementation: \"coding.implementation\",\n\t/** @public */\n\treview: \"coding.review\",\n} as const;\n\n/** @internal */\nexport const commitMessageGitTimeout: SettingDefinition<number> = {\n\tkey: \"coding.commit_message_git_timeout_ms\",\n\tschemaVersion: 1,\n\tscopes: [\"instance\", \"repository\"],\n\tmerge: \"replace\",\n\tdefaultValue: 60_000,\n\tschema: {\n\t\tparse(value) {\n\t\t\tif (\n\t\t\t\ttypeof value !== \"number\" ||\n\t\t\t\t!Number.isSafeInteger(value) ||\n\t\t\t\tvalue <= 0 ||\n\t\t\t\tvalue > 2_147_483_647\n\t\t\t) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"Git timeout must be a positive integer of at most 2147483647 milliseconds\",\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn value;\n\t\t},\n\t},\n\tform: {\n\t\tlabel: \"Commit-message Git timeout (milliseconds)\",\n\t\tgroup: \"Implementation\",\n\t\tcontrol: \"number\",\n\t\tdescription: \"Deadline per Git inspection command. Defaults to 60000 ms (60 seconds).\",\n\t},\n};\n\nfunction model(key: string, label: string, group: string): SettingDefinition<string | null> {\n\treturn {\n\t\tkey,\n\t\tschemaVersion: 1,\n\t\tscopes: [\"instance\", \"repository\"],\n\t\tmerge: \"replace\",\n\t\tdefaultValue: null,\n\t\tschema: {\n\t\t\tparse(value) {\n\t\t\t\tif (value === null || (typeof value === \"string\" && value.length > 0)) return value;\n\t\t\t\tthrow new Error(\"Choose a model profile or inherit the runtime default\");\n\t\t\t},\n\t\t},\n\t\tform: {\n\t\t\tlabel,\n\t\t\tgroup,\n\t\t\tcontrol: \"model\",\n\t\t\tdescription: \"Used by future steps unless the process has an explicit model choice.\",\n\t\t},\n\t};\n}\n\n/** @public */\nexport const codingSettings: ScopedSettingsDeclaration = {\n\tsettings: [\n\t\tmodel(\"coding.planning_model\", \"Planning model\", \"Planning\"),\n\t\tmodel(\"coding.implementation_model\", \"Implementation model\", \"Implementation\"),\n\t\tmodel(\"coding.review_model\", \"Review model\", \"Review\"),\n\t\tcommitMessageGitTimeout,\n\t],\n\tpurposes: Object.entries(codingPurposes).map(([name, id]) => ({\n\t\tid,\n\t\tlabel: name,\n\t\tmodelSettingKey: `coding.${name}_model`,\n\t\t...(name === \"implementation\" ? { settingKeys: [commitMessageGitTimeout.key] } : {}),\n\t})),\n};\n"],"mappings":";;;;;AAAA,SAAS,aAAa;AACtB,SAAS,OAAO,UAAU,SAAS,IAAI,MAAM,cAAc;AAC3D,SAAS,cAAc;AACvB,OAAO,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,KAAK,MAAM,QAAQ,KAAK,SAAS,CAAC,CAAC;AACxE,YAAQ,YAAY;AAAA,EACrB;AACA,SAAO;AACR;","names":[]}
|
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
import {
|
|
2
|
+
buildRepositoryCommitMessagesPrompt,
|
|
3
|
+
parseRepositoryCommitMessages
|
|
4
|
+
} from "./chunk-DNG7D77K.js";
|
|
5
|
+
import {
|
|
6
|
+
buildGeneratePlanPrompt
|
|
7
|
+
} from "./chunk-ABQH2WZT.js";
|
|
8
|
+
import {
|
|
9
|
+
buildImplementPrompt
|
|
10
|
+
} from "./chunk-BI45R2FH.js";
|
|
11
|
+
import {
|
|
12
|
+
buildStreamlinedSimplificationPrompt
|
|
13
|
+
} from "./chunk-SKGB4CZS.js";
|
|
14
|
+
import {
|
|
15
|
+
codingPurposes,
|
|
16
|
+
prepareRepositoryCommitMessageEvidence
|
|
17
|
+
} from "./chunk-M2VTUPFO.js";
|
|
18
|
+
|
|
19
|
+
// src/actions.ts
|
|
20
|
+
var codingActionIds = {
|
|
21
|
+
/** @public */
|
|
22
|
+
approvePlan: "approve_plan",
|
|
23
|
+
/** @internal */
|
|
24
|
+
requestRevision: "request_revision",
|
|
25
|
+
/** @internal */
|
|
26
|
+
runReview: "run_review",
|
|
27
|
+
/** @internal */
|
|
28
|
+
simplify: "simplify",
|
|
29
|
+
/** @internal */
|
|
30
|
+
acceptReview: "accept_review",
|
|
31
|
+
/** @internal */
|
|
32
|
+
requestReviewChanges: "request_review_changes",
|
|
33
|
+
/** @internal */
|
|
34
|
+
dismissReview: "dismiss_review",
|
|
35
|
+
/** @public */
|
|
36
|
+
finalizeChange: "finalize_change"
|
|
37
|
+
};
|
|
38
|
+
function notesForm(id, title, label, description) {
|
|
39
|
+
return {
|
|
40
|
+
id,
|
|
41
|
+
title,
|
|
42
|
+
fields: [
|
|
43
|
+
{ id: "message", label, kind: "textarea", primaryPrompt: true, required: true, description }
|
|
44
|
+
],
|
|
45
|
+
submitLabel: title
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
var requestRevisionForm = notesForm(
|
|
49
|
+
codingActionIds.requestRevision,
|
|
50
|
+
"Request revision",
|
|
51
|
+
"Revision notes",
|
|
52
|
+
"Instructions for the next implementation pass."
|
|
53
|
+
);
|
|
54
|
+
var requestReviewChangesForm = notesForm(
|
|
55
|
+
codingActionIds.requestReviewChanges,
|
|
56
|
+
"Request review changes",
|
|
57
|
+
"Review notes",
|
|
58
|
+
"Instructions for the next review pass."
|
|
59
|
+
);
|
|
60
|
+
var acceptReviewForm = {
|
|
61
|
+
id: codingActionIds.acceptReview,
|
|
62
|
+
title: "Accept review",
|
|
63
|
+
fields: [
|
|
64
|
+
{
|
|
65
|
+
id: "message",
|
|
66
|
+
label: "Review adjustment",
|
|
67
|
+
kind: "textarea",
|
|
68
|
+
primaryPrompt: true,
|
|
69
|
+
description: "Optional instructions to apply with the accepted review, such as dropping one finding."
|
|
70
|
+
}
|
|
71
|
+
],
|
|
72
|
+
submitLabel: "Accept review"
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
// src/repository-change-process.ts
|
|
76
|
+
import { trimString as normalizeMessage } from "@leitwerk-dev/domain";
|
|
77
|
+
import {
|
|
78
|
+
flow,
|
|
79
|
+
humanTurn,
|
|
80
|
+
revisionAction
|
|
81
|
+
} from "@leitwerk-dev/process-sdk";
|
|
82
|
+
|
|
83
|
+
// src/repository-change-state-internal.ts
|
|
84
|
+
import { parseStructuralProcessState } from "@leitwerk-dev/process-sdk";
|
|
85
|
+
function toRecord(value) {
|
|
86
|
+
return typeof value === "object" && value !== null ? value : {};
|
|
87
|
+
}
|
|
88
|
+
function parseFinalizationState(value) {
|
|
89
|
+
const record = toRecord(value);
|
|
90
|
+
return {
|
|
91
|
+
generatedCommitMessage: typeof record.generatedCommitMessage === "string" ? record.generatedCommitMessage : null,
|
|
92
|
+
...record.commitMessages ? {
|
|
93
|
+
commitMessages: Object.fromEntries(
|
|
94
|
+
Object.entries(toRecord(record.commitMessages)).filter(
|
|
95
|
+
(entry) => typeof entry[1] === "string"
|
|
96
|
+
)
|
|
97
|
+
)
|
|
98
|
+
} : {}
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
var repositoryChangeStateCodec = {
|
|
102
|
+
parse(value) {
|
|
103
|
+
const record = toRecord(value);
|
|
104
|
+
return {
|
|
105
|
+
...parseStructuralProcessState(record),
|
|
106
|
+
finalization: parseFinalizationState(record.finalization),
|
|
107
|
+
extensionState: toRecord(record.extensionState),
|
|
108
|
+
routing: toRecord(record.routing)
|
|
109
|
+
};
|
|
110
|
+
},
|
|
111
|
+
serialize(value) {
|
|
112
|
+
return value;
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
// src/repository-change-process.ts
|
|
117
|
+
function createRepositoryChangeProcess(config) {
|
|
118
|
+
const tools = ["read", "bash", "edit", "write"];
|
|
119
|
+
const planDecision = humanTurn({
|
|
120
|
+
description: "Review Plan",
|
|
121
|
+
reviewSemanticRef: "plan",
|
|
122
|
+
notesFields: [
|
|
123
|
+
{
|
|
124
|
+
id: "message",
|
|
125
|
+
label: "Revision notes",
|
|
126
|
+
placeholder: "Describe what the next plan revision should improve",
|
|
127
|
+
required: true
|
|
128
|
+
}
|
|
129
|
+
],
|
|
130
|
+
commentary: "Approve this plan or request a revision with comments.",
|
|
131
|
+
actions: {
|
|
132
|
+
[codingActionIds.approvePlan]: {
|
|
133
|
+
label: "Approve plan",
|
|
134
|
+
description: "Accept the current plan and continue into implementation.",
|
|
135
|
+
acceptanceState: "accepted",
|
|
136
|
+
to: "implement",
|
|
137
|
+
effect: ({ ctx }) => {
|
|
138
|
+
if (!ctx.state.semanticEntryRefs.plan?.turnRecordId?.trim())
|
|
139
|
+
throw new Error("No plan is available for approval");
|
|
140
|
+
return {
|
|
141
|
+
emit: [
|
|
142
|
+
{
|
|
143
|
+
type: "plan_approved",
|
|
144
|
+
data: {
|
|
145
|
+
externalId: ctx.process.externalId,
|
|
146
|
+
planRevision: ctx.process.planRevision
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
]
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
},
|
|
153
|
+
[codingActionIds.requestRevision]: revisionAction({
|
|
154
|
+
label: "Request revision",
|
|
155
|
+
description: "Send the plan back for another draft revision.",
|
|
156
|
+
acceptanceState: "requires_changes",
|
|
157
|
+
form: requestRevisionForm,
|
|
158
|
+
schedulable: true,
|
|
159
|
+
to: "generate_plan",
|
|
160
|
+
queueTarget: { semanticRef: "currentPrimaryPathLeaf" },
|
|
161
|
+
effect: ({ input }) => ({
|
|
162
|
+
emit: [
|
|
163
|
+
{ type: "plan_revision_requested", data: { message: normalizeMessage(input.message) } }
|
|
164
|
+
]
|
|
165
|
+
})
|
|
166
|
+
})
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
if (config.workflow?.planBypassSource)
|
|
170
|
+
planDecision.externalActions = {
|
|
171
|
+
bypass_plan: {
|
|
172
|
+
id: "bypass_plan",
|
|
173
|
+
label: "Skip plan approval",
|
|
174
|
+
source: config.workflow.planBypassSource,
|
|
175
|
+
to: "implement",
|
|
176
|
+
effect: ({ state, process, event }) => {
|
|
177
|
+
if (event.planRevision !== process.planRevision)
|
|
178
|
+
throw new Error("Stale plan bypass event");
|
|
179
|
+
return {
|
|
180
|
+
state: {
|
|
181
|
+
...state,
|
|
182
|
+
routing: {
|
|
183
|
+
...state.routing,
|
|
184
|
+
plan: { planRevision: process.planRevision, skip: true, reason: "Jira label" }
|
|
185
|
+
}
|
|
186
|
+
},
|
|
187
|
+
emit: [
|
|
188
|
+
{
|
|
189
|
+
type: "plan_approved",
|
|
190
|
+
data: {
|
|
191
|
+
planRevision: process.planRevision,
|
|
192
|
+
actor: "system",
|
|
193
|
+
bypassed: true,
|
|
194
|
+
reason: "Jira label"
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
]
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
const generatePlan = flow.llm("generate_plan").description("Plan").executionPurpose(codingPurposes.planning).tools("read", "bash").askQuestions().freshPrimary().buildPrompt(buildGeneratePlanPrompt).outcomeTool(
|
|
203
|
+
"plan_saved",
|
|
204
|
+
(tool) => tool.description(
|
|
205
|
+
"Save a finished, implementable plan after resolving design-critical questions. Required investigation and access must be complete. If blocked, use abort_turn. Use ask_questions for operator decisions when available; otherwise decide within the requested scope and document assumptions."
|
|
206
|
+
).requiredString("summary", "One concise sentence summarizing the proposed plan").requiredStringArray(
|
|
207
|
+
"acceptanceCriteria",
|
|
208
|
+
"Requested outcomes for the repository change, without expanding scope"
|
|
209
|
+
).routeByState(
|
|
210
|
+
{
|
|
211
|
+
approval: {
|
|
212
|
+
to: "plan_decision",
|
|
213
|
+
label: "Approval required",
|
|
214
|
+
description: "When the process policy requires an operator to approve the saved plan."
|
|
215
|
+
},
|
|
216
|
+
bypass: {
|
|
217
|
+
to: "implement",
|
|
218
|
+
label: "Skip plan approval",
|
|
219
|
+
description: "When the process policy skips plan approval, for example through the Skip plan approval launcher option."
|
|
220
|
+
}
|
|
221
|
+
},
|
|
222
|
+
({ ctx }) => ctx.state.routing?.plan?.skip ? "bypass" : "approval"
|
|
223
|
+
).effect(async ({ ctx, event }) => {
|
|
224
|
+
const planRevision = ctx.process.planRevision + 1;
|
|
225
|
+
const policy = await config.workflow?.planDecision?.(ctx.params).catch(() => ({ skip: false, reason: "Source unavailable; approval required" })) ?? {
|
|
226
|
+
skip: false,
|
|
227
|
+
reason: "Human approval required"
|
|
228
|
+
};
|
|
229
|
+
const summary = normalizeMessage(event.params.summary);
|
|
230
|
+
const acceptanceCriteria = Array.isArray(event.params.acceptanceCriteria) ? event.params.acceptanceCriteria.filter(
|
|
231
|
+
(entry) => typeof entry === "string" && entry.trim() !== ""
|
|
232
|
+
) : [];
|
|
233
|
+
return {
|
|
234
|
+
state: {
|
|
235
|
+
...ctx.state,
|
|
236
|
+
routing: { ...ctx.state.routing, plan: { ...policy, planRevision } }
|
|
237
|
+
},
|
|
238
|
+
processPatch: { planRevision },
|
|
239
|
+
broadcasts: [
|
|
240
|
+
{
|
|
241
|
+
type: "plan.updated",
|
|
242
|
+
payload: {
|
|
243
|
+
planRevision,
|
|
244
|
+
reviewState: policy.skip ? "accepted" : "awaiting_approval",
|
|
245
|
+
approved: policy.skip,
|
|
246
|
+
summary
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
],
|
|
250
|
+
emit: [
|
|
251
|
+
...policy.skip ? [
|
|
252
|
+
{
|
|
253
|
+
type: "plan_approved",
|
|
254
|
+
data: {
|
|
255
|
+
planRevision,
|
|
256
|
+
actor: "system",
|
|
257
|
+
bypassed: true,
|
|
258
|
+
reason: policy.reason
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
] : [],
|
|
262
|
+
{
|
|
263
|
+
type: "plan_saved",
|
|
264
|
+
data: {
|
|
265
|
+
planRevision,
|
|
266
|
+
summary,
|
|
267
|
+
planMarkdown: ctx.output?.content ?? "",
|
|
268
|
+
acceptanceCriteria
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
]
|
|
272
|
+
};
|
|
273
|
+
})
|
|
274
|
+
).publish("plan");
|
|
275
|
+
const implement = flow.llm("implement").description("Implement").waitFor(({ state }) => !!state.productRefs.plan).executionPurpose(codingPurposes.implementation).tools(...tools).freshSeededPrimary().startFromRoot().consume("plan").buildPrompt(buildImplementPrompt).outcomeTool(
|
|
276
|
+
"implementation_ready",
|
|
277
|
+
(tool) => tool.description("Implementation and checks are complete; continue to delivery").routeByState(
|
|
278
|
+
{
|
|
279
|
+
simplify: {
|
|
280
|
+
to: "simplify_implementation",
|
|
281
|
+
label: "Simplification enabled",
|
|
282
|
+
description: "When the process policy enables simplification. This is the default unless a launcher option or source policy skips it."
|
|
283
|
+
},
|
|
284
|
+
skip: {
|
|
285
|
+
to: "generate_commit_message",
|
|
286
|
+
label: "Skip simplification",
|
|
287
|
+
description: "When simplification is skipped, for example through the Skip simplification launcher option or the leitwerk-skip-simplification source label."
|
|
288
|
+
}
|
|
289
|
+
},
|
|
290
|
+
({ ctx }) => ctx.state.routing?.simplification?.skip ? "skip" : "simplify"
|
|
291
|
+
).effect(async ({ ctx }) => ({
|
|
292
|
+
state: {
|
|
293
|
+
...ctx.state,
|
|
294
|
+
routing: {
|
|
295
|
+
...ctx.state.routing,
|
|
296
|
+
simplification: ctx.state.routing?.simplification ?? await config.workflow?.simplification?.(ctx.params) ?? {
|
|
297
|
+
skip: false,
|
|
298
|
+
reason: "Simplification enabled by default"
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}))
|
|
303
|
+
).publish("implementation-summary");
|
|
304
|
+
const simplify = flow.llm("simplify_implementation").description("Simplify").executionPurpose(codingPurposes.review).tools("read", "bash").rootBranchReview().startFromProductBranch("simplification-plan").buildPrompt(buildStreamlinedSimplificationPrompt).publish("simplification-plan").to("apply_simplification");
|
|
305
|
+
const applySimplification = flow.llm("apply_simplification").description("Apply simplification").executionPurpose(codingPurposes.implementation).tools(...tools).freshSeededPrimary().consume("plan").consume("simplification-plan").buildPrompt(
|
|
306
|
+
(ctx) => `Apply justified simplifications to each repository, preserving the accepted plan and behavior. Rerun the required checks. Empty findings require no edits. Leave changes uncommitted for delivery.
|
|
307
|
+
|
|
308
|
+
Accepted plan:
|
|
309
|
+
${ctx.input.plan}
|
|
310
|
+
|
|
311
|
+
Findings by repository:
|
|
312
|
+
${ctx.input["simplification-plan"]}`
|
|
313
|
+
).publish("implementation-summary").to("generate_commit_message");
|
|
314
|
+
const generateCommitMessage = flow.llm("generate_commit_message").description("Write Commit Message").executionPurpose(codingPurposes.implementation).tools("read", "grep", "find", "ls").rootBranchReview().startFromRoot().consume("plan").consume("implementation-summary").prepare(prepareRepositoryCommitMessageEvidence).buildPrompt(buildRepositoryCommitMessagesPrompt).publish("commit-message").to(config.publication.entryTurnId).state(({ ctx }) => ({
|
|
315
|
+
...ctx.state,
|
|
316
|
+
finalization: {
|
|
317
|
+
...ctx.state.finalization,
|
|
318
|
+
commitMessages: parseRepositoryCommitMessages(
|
|
319
|
+
ctx.output?.content,
|
|
320
|
+
ctx.projects.map((p) => p.key)
|
|
321
|
+
)
|
|
322
|
+
}
|
|
323
|
+
}));
|
|
324
|
+
const builder = flow.process(config.processId).displayName(config.displayName).entry("generate_plan").happyPath(
|
|
325
|
+
"generate_plan",
|
|
326
|
+
"implement",
|
|
327
|
+
"simplify_implementation",
|
|
328
|
+
"apply_simplification",
|
|
329
|
+
"generate_commit_message",
|
|
330
|
+
...config.publication.happyPath ?? [config.publication.entryTurnId]
|
|
331
|
+
).piConfig(config.workflow?.multiRepository ? {} : { sessionCwdTemplate: "{{{projectKey}}}" }).codecs({ params: config.paramsCodec, state: repositoryChangeStateCodec }).initialState(() => repositoryChangeStateCodec.parse({})).turn(generatePlan).turn({ id: "plan_decision", definition: planDecision }).turn(implement).turn(simplify).turn(applySimplification).turn(generateCommitMessage).use(config.publication.fragment);
|
|
332
|
+
if (config.repositoryCredentials) builder.repositoryCredentials(config.repositoryCredentials);
|
|
333
|
+
if (config.launcher) builder.launcher(config.launcher);
|
|
334
|
+
return {
|
|
335
|
+
/** @public */
|
|
336
|
+
process: builder.define()
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
export {
|
|
341
|
+
codingActionIds,
|
|
342
|
+
requestRevisionForm,
|
|
343
|
+
requestReviewChangesForm,
|
|
344
|
+
acceptReviewForm,
|
|
345
|
+
createRepositoryChangeProcess
|
|
346
|
+
};
|
|
347
|
+
//# sourceMappingURL=chunk-OM2AMDTJ.js.map
|