@leitwerk-dev/process-analysis 0.1.9 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -5
- package/dist/actions.d.ts +15 -13
- package/dist/actions.d.ts.map +1 -1
- package/dist/index.d.ts +1 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +464 -33
- package/dist/index.js.map +1 -1
- package/dist/params.d.ts +11 -2
- package/dist/params.d.ts.map +1 -1
- package/dist/process-definition.d.ts +8 -5
- package/dist/process-definition.d.ts.map +1 -1
- package/dist/process-ref.d.ts +7 -0
- package/dist/process-ref.d.ts.map +1 -1
- package/dist/server-runtime.d.ts +6 -8
- package/dist/server-runtime.d.ts.map +1 -1
- package/dist/snapshot-downloader.d.ts +16 -0
- package/dist/snapshot-downloader.d.ts.map +1 -1
- package/dist/snapshot-markdown.d.ts +6 -0
- package/dist/snapshot-markdown.d.ts.map +1 -1
- package/dist/state.d.ts +11 -1
- package/dist/state.d.ts.map +1 -1
- package/dist/tools.d.ts +6 -0
- package/dist/tools.d.ts.map +1 -0
- package/package.json +4 -5
- package/src/actions.ts +15 -16
- package/src/index.ts +15 -22
- package/src/params.ts +20 -7
- package/src/process-definition.ts +79 -195
- package/src/process-ref.ts +7 -0
- package/src/server-runtime.ts +6 -46
- package/src/snapshot-downloader.ts +25 -9
- package/src/snapshot-markdown.ts +6 -0
- package/src/state.ts +14 -7
- package/src/tools.ts +37 -0
- package/dist/actions.js +0 -36
- package/dist/actions.js.map +0 -1
- package/dist/params.js +0 -25
- package/dist/params.js.map +0 -1
- package/dist/process-definition.js +0 -266
- package/dist/process-definition.js.map +0 -1
- package/dist/process-ref.js +0 -37
- package/dist/process-ref.js.map +0 -1
- package/dist/server-runtime.js +0 -52
- package/dist/server-runtime.js.map +0 -1
- package/dist/snapshot-downloader.js +0 -61
- package/dist/snapshot-downloader.js.map +0 -1
- package/dist/snapshot-markdown.js +0 -34
- package/dist/snapshot-markdown.js.map +0 -1
- package/dist/state.js +0 -31
- package/dist/state.js.map +0 -1
|
@@ -1,44 +1,39 @@
|
|
|
1
1
|
import { rm } from "node:fs/promises";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
formatLocalRepoChangeLaunchErrors,
|
|
5
|
-
type LocalRepoChangeLaunchPlanner,
|
|
6
|
-
localRepoChangeImportedPlanLauncherId,
|
|
7
|
-
} from "@leitwerk-dev/local-repo-change";
|
|
2
|
+
import type { ExtensionProcessDefinition } from "@leitwerk-dev/process-sdk";
|
|
8
3
|
import {
|
|
9
4
|
createEmptyStructuralProcessState,
|
|
10
5
|
flow,
|
|
11
6
|
humanTurn,
|
|
12
7
|
revisionAction,
|
|
13
8
|
} from "@leitwerk-dev/process-sdk";
|
|
14
|
-
import { followupForm,
|
|
9
|
+
import { followupForm, processAnalysisActionIds } from "./actions.js";
|
|
15
10
|
import {
|
|
16
11
|
type ProcessAnalysisParams,
|
|
17
12
|
processAnalysisParamsCodec,
|
|
18
13
|
validateProcessAnalysisLaunchInput,
|
|
19
14
|
} from "./params.js";
|
|
15
|
+
import { getProcessAnalysisRuntime } from "./server-runtime.js";
|
|
16
|
+
import { resolveProcessSnapshotDirectory } from "./snapshot-downloader.js";
|
|
20
17
|
import {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
} from "./
|
|
25
|
-
import {
|
|
26
|
-
import { type ProcessAnalysisState, processAnalysisStateCodec } from "./state.js";
|
|
18
|
+
type ProcessAnalysisState,
|
|
19
|
+
parseProcessAnalysisSnapshotState,
|
|
20
|
+
processAnalysisStateCodec,
|
|
21
|
+
} from "./state.js";
|
|
22
|
+
import { processAnalysisDownloadSnapshotTool } from "./tools.js";
|
|
27
23
|
|
|
28
24
|
const turnIds = {
|
|
29
|
-
|
|
25
|
+
/** @internal */
|
|
30
26
|
analyzeProcess: "analyze_process",
|
|
27
|
+
/** @internal */
|
|
31
28
|
analysisDecision: "analysis_decision",
|
|
32
|
-
handoff: "handoff_local_repo_change",
|
|
33
29
|
} as const;
|
|
34
30
|
const products = { analysis: "analysis" } as const;
|
|
35
31
|
|
|
36
32
|
function analysisPrompt(ctx: {
|
|
37
33
|
params: ProcessAnalysisParams;
|
|
38
|
-
|
|
34
|
+
prepared: NonNullable<ProcessAnalysisState["snapshot"]>;
|
|
39
35
|
}): string {
|
|
40
|
-
const snapshot = ctx.
|
|
41
|
-
if (!snapshot) throw new Error("No process snapshot is available for analysis");
|
|
36
|
+
const snapshot = ctx.prepared;
|
|
42
37
|
return [
|
|
43
38
|
"Analyze the referenced leitwerk process for the operator.",
|
|
44
39
|
"You are in read-only analysis mode. Use only read and bash inspection commands. Do not modify files.",
|
|
@@ -49,207 +44,94 @@ function analysisPrompt(ctx: {
|
|
|
49
44
|
].join("\n\n");
|
|
50
45
|
}
|
|
51
46
|
|
|
52
|
-
async function runHandoff(
|
|
53
|
-
launchPlanner: LocalRepoChangeLaunchPlanner,
|
|
54
|
-
ctx: {
|
|
55
|
-
process: { id: string };
|
|
56
|
-
params: ProcessAnalysisParams;
|
|
57
|
-
state: ProcessAnalysisState;
|
|
58
|
-
},
|
|
59
|
-
input: Record<string, unknown> = {},
|
|
60
|
-
) {
|
|
61
|
-
const runtime = getProcessAnalysisRuntime();
|
|
62
|
-
if (!runtime.processLaunches) throw new Error("process launch service is not configured");
|
|
63
|
-
const snapshot = ctx.state.snapshot;
|
|
64
|
-
if (!snapshot) throw new Error("No process snapshot is available for handoff");
|
|
65
|
-
if (!(await isProcessAnalysisRuntimeGitRepo())) {
|
|
66
|
-
throw new Error(
|
|
67
|
-
`Cannot start Local Repo Change handoff: server launch directory is not a git repository (${runtime.analysisCwd})`,
|
|
68
|
-
);
|
|
69
|
-
}
|
|
70
|
-
const runtimeRepo = await resolveProcessAnalysisRuntimeRepoConfig();
|
|
71
|
-
const note = trimString(input.note);
|
|
72
|
-
const analysis = trimString(input.analysisMarkdown);
|
|
73
|
-
const prompt = [
|
|
74
|
-
"Implement the fix identified by a process analysis handoff.",
|
|
75
|
-
note ? `Operator handoff note:\n${note}` : null,
|
|
76
|
-
`Original analysis instruction:\n${ctx.params.instruction}`,
|
|
77
|
-
]
|
|
78
|
-
.filter(Boolean)
|
|
79
|
-
.join("\n\n");
|
|
80
|
-
const importedPlanMarkdown = [
|
|
81
|
-
"# Imported process-analysis plan",
|
|
82
|
-
`- Source process: ${snapshot.sourceProcessId}`,
|
|
83
|
-
`- Source URL: ${snapshot.apiUrl}`,
|
|
84
|
-
`- Analysis process: ${ctx.process.id}`,
|
|
85
|
-
`- Snapshot directory: ${snapshot.snapshotDir}`,
|
|
86
|
-
"",
|
|
87
|
-
"## Operator instruction",
|
|
88
|
-
ctx.params.instruction,
|
|
89
|
-
note ? `\n## Handoff note\n${note}` : "",
|
|
90
|
-
"\n## Analysis",
|
|
91
|
-
analysis || "No analysis markdown was available.",
|
|
92
|
-
].join("\n");
|
|
93
|
-
const metadata = {
|
|
94
|
-
processAnalysisHandoff: {
|
|
95
|
-
sourceAnalysisProcessId: ctx.process.id,
|
|
96
|
-
sourceProcessId: snapshot.sourceProcessId,
|
|
97
|
-
sourceProcessUrl: snapshot.apiUrl,
|
|
98
|
-
},
|
|
99
|
-
};
|
|
100
|
-
const planned = launchPlanner.plan({
|
|
101
|
-
input: {
|
|
102
|
-
launchKind: "imported_plan",
|
|
103
|
-
repoLocator: runtimeRepo.repoLocator,
|
|
104
|
-
baseBranch: runtimeRepo.baseBranch,
|
|
105
|
-
workBranch: "",
|
|
106
|
-
prompt,
|
|
107
|
-
importedPlanMarkdown,
|
|
108
|
-
},
|
|
109
|
-
metadata,
|
|
110
|
-
});
|
|
111
|
-
if (!planned.ok) {
|
|
112
|
-
throw new Error(
|
|
113
|
-
`Invalid local repo change handoff input: ${formatLocalRepoChangeLaunchErrors(planned.errors)}`,
|
|
114
|
-
);
|
|
115
|
-
}
|
|
116
|
-
const handoffDedupKey = `process-analysis:${ctx.process.id}:local-repo-change`;
|
|
117
|
-
const result = await runtime.processLaunches.createProcessFromLaunchConfig({
|
|
118
|
-
launcherId: localRepoChangeImportedPlanLauncherId,
|
|
119
|
-
launchConfig: planned.launchConfig,
|
|
120
|
-
handoffDedupKey,
|
|
121
|
-
});
|
|
122
|
-
if (!result.ok) {
|
|
123
|
-
throw new Error(`Failed to launch local repo change: ${JSON.stringify(result.body)}`);
|
|
124
|
-
}
|
|
125
|
-
return { linkedId: result.process.id, reused: result.reused };
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
const downloadTurn = flow
|
|
129
|
-
.serverAutomatic<ProcessAnalysisParams, ProcessAnalysisState>(turnIds.downloadProcess)
|
|
130
|
-
.description("Download process snapshot")
|
|
131
|
-
.run(async (ctx) => {
|
|
132
|
-
const snapshot = await downloadProcessSnapshot({
|
|
133
|
-
analysisProcessId: ctx.process.id,
|
|
134
|
-
processRef: ctx.params.processRef,
|
|
135
|
-
});
|
|
136
|
-
return {
|
|
137
|
-
outcome: "downloaded",
|
|
138
|
-
params: {},
|
|
139
|
-
markdown: `Downloaded process snapshot to ${snapshot.snapshotDir}.`,
|
|
140
|
-
state: { ...ctx.state, snapshot },
|
|
141
|
-
};
|
|
142
|
-
})
|
|
143
|
-
.outcome("downloaded", (outcome) =>
|
|
144
|
-
outcome.description("Snapshot downloaded").to(turnIds.analyzeProcess),
|
|
145
|
-
);
|
|
146
|
-
|
|
147
47
|
const analyzeTurn = flow
|
|
148
48
|
.llm<ProcessAnalysisParams, ProcessAnalysisState>(turnIds.analyzeProcess)
|
|
149
49
|
.description("Analyze process")
|
|
50
|
+
.integrationTools(processAnalysisDownloadSnapshotTool)
|
|
51
|
+
.prepare(async (ctx) => {
|
|
52
|
+
ctx.reportProgress({
|
|
53
|
+
title: "Analysis preparation",
|
|
54
|
+
steps: [
|
|
55
|
+
{ id: "download_snapshot", label: "Download process snapshot", status: "in_progress" },
|
|
56
|
+
],
|
|
57
|
+
});
|
|
58
|
+
const result = await ctx.callIntegrationTool(processAnalysisDownloadSnapshotTool, {
|
|
59
|
+
processRef: ctx.params.processRef,
|
|
60
|
+
});
|
|
61
|
+
const snapshot = parseProcessAnalysisSnapshotState(result);
|
|
62
|
+
if (!snapshot) throw new Error("Snapshot tool returned an invalid process snapshot");
|
|
63
|
+
ctx.reportProgress({
|
|
64
|
+
title: "Analysis preparation",
|
|
65
|
+
steps: [{ id: "download_snapshot", label: "Download process snapshot", status: "completed" }],
|
|
66
|
+
});
|
|
67
|
+
return snapshot;
|
|
68
|
+
})
|
|
150
69
|
.tools("read", "bash")
|
|
151
70
|
.freshPrimary()
|
|
152
71
|
.buildPrompt(analysisPrompt)
|
|
153
72
|
.publish(products.analysis)
|
|
154
73
|
.to(turnIds.analysisDecision);
|
|
155
74
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
75
|
+
const reviseAnalysis = (label: string) =>
|
|
76
|
+
revisionAction<ProcessAnalysisParams, ProcessAnalysisState>({
|
|
77
|
+
label,
|
|
78
|
+
acceptanceState: "neutral",
|
|
79
|
+
form: followupForm,
|
|
80
|
+
to: turnIds.analyzeProcess,
|
|
81
|
+
queueTarget: { productName: products.analysis },
|
|
82
|
+
schedulable: true,
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
const decisionTurn = humanTurn<ProcessAnalysisParams, ProcessAnalysisState>({
|
|
86
|
+
description: "Review process analysis",
|
|
87
|
+
reviewProduct: products.analysis,
|
|
88
|
+
commentary: "Ask follow-up questions, refine the analysis, or refresh the snapshot.",
|
|
89
|
+
actions: {
|
|
90
|
+
[processAnalysisActionIds.completeAnalysis]: {
|
|
91
|
+
label: "Complete analysis",
|
|
92
|
+
acceptanceState: "accepted",
|
|
93
|
+
complete: true,
|
|
94
|
+
},
|
|
95
|
+
[processAnalysisActionIds.askFollowup]: reviseAnalysis("Ask follow-up"),
|
|
96
|
+
[processAnalysisActionIds.refineAnalysis]: reviseAnalysis("Refine analysis"),
|
|
97
|
+
[processAnalysisActionIds.refreshSnapshot]: {
|
|
98
|
+
label: "Refresh snapshot",
|
|
160
99
|
acceptanceState: "neutral",
|
|
161
|
-
form: followupForm,
|
|
162
100
|
to: turnIds.analyzeProcess,
|
|
163
|
-
queueTarget: { productName: products.analysis },
|
|
164
|
-
schedulable: true,
|
|
165
|
-
});
|
|
166
|
-
return humanTurn<ProcessAnalysisParams, ProcessAnalysisState>({
|
|
167
|
-
description: "Review process analysis",
|
|
168
|
-
reviewProduct: products.analysis,
|
|
169
|
-
commentary: handoffAvailable
|
|
170
|
-
? "Ask follow-up questions, refresh the snapshot, or hand the analysis to a Local Repo Change process."
|
|
171
|
-
: "Ask follow-up questions, refine the analysis, or refresh the snapshot.",
|
|
172
|
-
actions: {
|
|
173
|
-
[processAnalysisActionIds.completeAnalysis]: {
|
|
174
|
-
label: "Complete analysis",
|
|
175
|
-
acceptanceState: "accepted",
|
|
176
|
-
complete: true,
|
|
177
|
-
},
|
|
178
|
-
[processAnalysisActionIds.askFollowup]: reviseAnalysis("Ask follow-up"),
|
|
179
|
-
[processAnalysisActionIds.refineAnalysis]: reviseAnalysis("Refine analysis"),
|
|
180
|
-
[processAnalysisActionIds.refreshSnapshot]: {
|
|
181
|
-
label: "Refresh snapshot",
|
|
182
|
-
acceptanceState: "neutral",
|
|
183
|
-
to: turnIds.downloadProcess,
|
|
184
|
-
},
|
|
185
|
-
...(handoffAvailable
|
|
186
|
-
? {
|
|
187
|
-
[processAnalysisActionIds.startLocalRepoChange]: {
|
|
188
|
-
label: "Start Local Repo Change",
|
|
189
|
-
acceptanceState: "accepted" as const,
|
|
190
|
-
form: handoffForm,
|
|
191
|
-
to: turnIds.handoff,
|
|
192
|
-
effect: ({ ctx, input }) => ({
|
|
193
|
-
state: {
|
|
194
|
-
...ctx.state,
|
|
195
|
-
pendingHandoffInput: {
|
|
196
|
-
...input,
|
|
197
|
-
analysisMarkdown: ctx.readProductTurnResultMarkdown(products.analysis) ?? "",
|
|
198
|
-
},
|
|
199
|
-
},
|
|
200
|
-
}),
|
|
201
|
-
},
|
|
202
|
-
}
|
|
203
|
-
: {}),
|
|
204
101
|
},
|
|
205
|
-
}
|
|
206
|
-
}
|
|
102
|
+
},
|
|
103
|
+
});
|
|
207
104
|
|
|
208
|
-
|
|
105
|
+
/** @internal */
|
|
106
|
+
export function createProcessAnalysisProcess(): ExtensionProcessDefinition<
|
|
107
|
+
ProcessAnalysisParams,
|
|
108
|
+
ProcessAnalysisState
|
|
109
|
+
> {
|
|
209
110
|
return flow
|
|
210
|
-
.serverAutomatic<ProcessAnalysisParams, ProcessAnalysisState>(turnIds.handoff)
|
|
211
|
-
.description("Start Local Repo Change handoff")
|
|
212
|
-
.run(async (ctx) => {
|
|
213
|
-
const result = await runHandoff(launchPlanner, ctx, ctx.state.pendingHandoffInput ?? {});
|
|
214
|
-
return {
|
|
215
|
-
outcome: "launched",
|
|
216
|
-
params: { linkedProcessId: result.linkedId, reused: result.reused },
|
|
217
|
-
markdown: `${result.reused ? "Reused" : "Created"} Local Repo Change process ${result.linkedId}.`,
|
|
218
|
-
state: { ...ctx.state, pendingHandoffInput: null },
|
|
219
|
-
};
|
|
220
|
-
})
|
|
221
|
-
.outcome("launched", (outcome) =>
|
|
222
|
-
outcome
|
|
223
|
-
.description("Local Repo Change process linked")
|
|
224
|
-
.requiredString("linkedProcessId", "Linked process id")
|
|
225
|
-
.boolean("reused", "Whether an existing handoff was reused")
|
|
226
|
-
.complete(),
|
|
227
|
-
);
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
export function createProcessAnalysisProcess(launchPlanner?: LocalRepoChangeLaunchPlanner) {
|
|
231
|
-
let processBuilder = flow
|
|
232
111
|
.process<ProcessAnalysisParams, ProcessAnalysisState>("process_analysis_process")
|
|
233
112
|
.displayName("Process Analysis")
|
|
234
|
-
.entry(turnIds.
|
|
113
|
+
.entry(turnIds.analyzeProcess)
|
|
235
114
|
.codecs({ params: processAnalysisParamsCodec, state: processAnalysisStateCodec })
|
|
236
115
|
.piConfig({ sessionCwdTemplate: "{{{analysisCwd}}}" })
|
|
237
116
|
.initialState(() => ({
|
|
238
117
|
...createEmptyStructuralProcessState(),
|
|
239
118
|
snapshot: null,
|
|
240
|
-
pendingHandoffInput: null,
|
|
241
119
|
}))
|
|
242
|
-
.turn(downloadTurn)
|
|
243
120
|
.turn(analyzeTurn)
|
|
244
|
-
.turn({ id: turnIds.analysisDecision, definition:
|
|
245
|
-
if (launchPlanner) {
|
|
246
|
-
processBuilder = processBuilder.turn(buildHandoffTurn(launchPlanner));
|
|
247
|
-
}
|
|
248
|
-
return processBuilder
|
|
121
|
+
.turn({ id: turnIds.analysisDecision, definition: decisionTurn })
|
|
249
122
|
.server((api) => {
|
|
250
123
|
api.onCleanup(async (ctx) => {
|
|
251
|
-
|
|
252
|
-
if (!snapshotDir)
|
|
124
|
+
let snapshotDir = ctx.state.snapshot?.snapshotDir ?? null;
|
|
125
|
+
if (!snapshotDir) {
|
|
126
|
+
try {
|
|
127
|
+
snapshotDir = resolveProcessSnapshotDirectory({
|
|
128
|
+
analysisProcessId: ctx.process.id,
|
|
129
|
+
processRef: ctx.params.processRef,
|
|
130
|
+
}).baseDir;
|
|
131
|
+
} catch {
|
|
132
|
+
return { state: { ...ctx.state, snapshot: null } };
|
|
133
|
+
}
|
|
134
|
+
}
|
|
253
135
|
await rm(snapshotDir, { recursive: true, force: true });
|
|
254
136
|
return { state: { ...ctx.state, snapshot: null } };
|
|
255
137
|
});
|
|
@@ -289,7 +171,7 @@ export function createProcessAnalysisProcess(launchPlanner?: LocalRepoChangeLaun
|
|
|
289
171
|
launchConfig: {
|
|
290
172
|
processId: "process_analysis_process",
|
|
291
173
|
params: { ...validated.value, analysisCwd: runtime.analysisCwd },
|
|
292
|
-
startTurnId: turnIds.
|
|
174
|
+
startTurnId: turnIds.analyzeProcess,
|
|
293
175
|
titleSourceFields: [
|
|
294
176
|
{ label: "Analysis instruction", value: validated.value.instruction },
|
|
295
177
|
],
|
|
@@ -302,6 +184,8 @@ export function createProcessAnalysisProcess(launchPlanner?: LocalRepoChangeLaun
|
|
|
302
184
|
.define();
|
|
303
185
|
}
|
|
304
186
|
|
|
187
|
+
/** @internal */
|
|
305
188
|
export const processAnalysisProcess = createProcessAnalysisProcess();
|
|
306
189
|
|
|
190
|
+
/** @internal */
|
|
307
191
|
export const processAnalysisTurnIds = turnIds;
|
package/src/process-ref.ts
CHANGED
|
@@ -1,13 +1,20 @@
|
|
|
1
|
+
/** @internal */
|
|
1
2
|
export interface ResolvedProcessRef {
|
|
3
|
+
/** @internal */
|
|
2
4
|
id: string;
|
|
5
|
+
/** @internal */
|
|
3
6
|
origin: string;
|
|
7
|
+
/** @internal */
|
|
4
8
|
apiUrl: string;
|
|
5
9
|
}
|
|
6
10
|
|
|
7
11
|
const ID_RE = /^[A-Za-z0-9][A-Za-z0-9._:-]*$/;
|
|
8
12
|
|
|
13
|
+
/** @internal */
|
|
9
14
|
export function resolveProcessRef(input: {
|
|
15
|
+
/** @internal */
|
|
10
16
|
processRef: string;
|
|
17
|
+
/** @internal */
|
|
11
18
|
serverBaseUrl: string;
|
|
12
19
|
}): ResolvedProcessRef {
|
|
13
20
|
const raw = input.processRef.trim();
|
package/src/server-runtime.ts
CHANGED
|
@@ -1,71 +1,31 @@
|
|
|
1
|
-
import { execFile as execFileCb } from "node:child_process";
|
|
2
1
|
import path from "node:path";
|
|
3
|
-
import { promisify } from "node:util";
|
|
4
|
-
import { resolveGitBinary } from "@leitwerk-dev/process-sdk/git-binary";
|
|
5
|
-
|
|
6
|
-
const execFile = promisify(execFileCb);
|
|
7
|
-
|
|
8
|
-
import type { ProcessLaunchExecutorLike } from "@leitwerk-dev/process-sdk";
|
|
9
2
|
|
|
3
|
+
/** @internal */
|
|
10
4
|
export interface ProcessAnalysisRuntime {
|
|
5
|
+
/** @internal */
|
|
11
6
|
analysisCwd: string;
|
|
7
|
+
/** @internal */
|
|
12
8
|
serverBaseUrl: string;
|
|
9
|
+
/** @internal */
|
|
13
10
|
processWorkspacesDir: string | null;
|
|
14
|
-
processLaunches: ProcessLaunchExecutorLike | null;
|
|
15
11
|
}
|
|
16
12
|
|
|
17
13
|
const runtime: ProcessAnalysisRuntime = {
|
|
18
14
|
analysisCwd: path.resolve(process.cwd()),
|
|
19
15
|
serverBaseUrl: "http://localhost",
|
|
20
16
|
processWorkspacesDir: null,
|
|
21
|
-
processLaunches: null,
|
|
22
17
|
};
|
|
23
18
|
|
|
19
|
+
/** @internal */
|
|
24
20
|
export function configureProcessAnalysisRuntime(overrides: Partial<ProcessAnalysisRuntime>): void {
|
|
25
21
|
runtime.analysisCwd = overrides.analysisCwd
|
|
26
22
|
? path.resolve(overrides.analysisCwd)
|
|
27
23
|
: runtime.analysisCwd;
|
|
28
24
|
runtime.serverBaseUrl = overrides.serverBaseUrl ?? runtime.serverBaseUrl;
|
|
29
25
|
runtime.processWorkspacesDir = overrides.processWorkspacesDir ?? null;
|
|
30
|
-
runtime.processLaunches = overrides.processLaunches ?? null;
|
|
31
26
|
}
|
|
32
27
|
|
|
28
|
+
/** @internal */
|
|
33
29
|
export function getProcessAnalysisRuntime(): ProcessAnalysisRuntime {
|
|
34
30
|
return runtime;
|
|
35
31
|
}
|
|
36
|
-
|
|
37
|
-
export interface ProcessAnalysisRuntimeRepoConfig {
|
|
38
|
-
repoLocator: string;
|
|
39
|
-
baseBranch: string;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
async function runGit(args: readonly string[]): Promise<string | null> {
|
|
43
|
-
try {
|
|
44
|
-
const { stdout } = await execFile(resolveGitBinary(), ["-C", runtime.analysisCwd, ...args], {
|
|
45
|
-
encoding: "utf8",
|
|
46
|
-
});
|
|
47
|
-
return stdout.trim();
|
|
48
|
-
} catch {
|
|
49
|
-
return null;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export async function isProcessAnalysisRuntimeGitRepo(): Promise<boolean> {
|
|
54
|
-
return (await runGit(["rev-parse", "--is-inside-work-tree"])) === "true";
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export async function resolveProcessAnalysisRuntimeRepoConfig(): Promise<ProcessAnalysisRuntimeRepoConfig> {
|
|
58
|
-
const originHead = await runGit([
|
|
59
|
-
"symbolic-ref",
|
|
60
|
-
"--quiet",
|
|
61
|
-
"--short",
|
|
62
|
-
"refs/remotes/origin/HEAD",
|
|
63
|
-
]);
|
|
64
|
-
const baseBranch = originHead?.startsWith("origin/")
|
|
65
|
-
? originHead.slice("origin/".length)
|
|
66
|
-
: "main";
|
|
67
|
-
return {
|
|
68
|
-
repoLocator: runtime.analysisCwd,
|
|
69
|
-
baseBranch,
|
|
70
|
-
};
|
|
71
|
-
}
|
|
@@ -32,25 +32,41 @@ async function writeJson(file: string, value: unknown): Promise<void> {
|
|
|
32
32
|
await writeFile(file, `${JSON.stringify(value, null, 2)}\n`, "utf8");
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
/** @internal */
|
|
36
|
+
export function resolveProcessSnapshotDirectory(input: {
|
|
37
|
+
/** @internal */
|
|
36
38
|
analysisProcessId: string;
|
|
39
|
+
/** @internal */
|
|
37
40
|
processRef: string;
|
|
38
|
-
}):
|
|
41
|
+
}): {
|
|
42
|
+
/** @internal */
|
|
43
|
+
baseDir: string;
|
|
44
|
+
/** @internal */
|
|
45
|
+
ref: ReturnType<typeof resolveProcessRef>;
|
|
46
|
+
} {
|
|
39
47
|
const runtime = getProcessAnalysisRuntime();
|
|
40
48
|
if (!runtime.processWorkspacesDir) throw new Error("processWorkspacesDir is not configured");
|
|
41
49
|
const ref = resolveProcessRef({
|
|
42
50
|
processRef: input.processRef,
|
|
43
51
|
serverBaseUrl: runtime.serverBaseUrl,
|
|
44
52
|
});
|
|
53
|
+
const sourceWorkspace = path.join(runtime.processWorkspacesDir, ref.id);
|
|
54
|
+
return {
|
|
55
|
+
ref,
|
|
56
|
+
baseDir: path.join(sourceWorkspace, ".leitwerk", "process-analysis", input.analysisProcessId),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** @internal */
|
|
61
|
+
export async function downloadProcessSnapshot(input: {
|
|
62
|
+
/** @internal */
|
|
63
|
+
analysisProcessId: string;
|
|
64
|
+
/** @internal */
|
|
65
|
+
processRef: string;
|
|
66
|
+
}): Promise<ProcessAnalysisSnapshotState> {
|
|
67
|
+
const { baseDir, ref } = resolveProcessSnapshotDirectory(input);
|
|
45
68
|
const detail = await fetchJson(ref.apiUrl);
|
|
46
69
|
const primaryPath = await fetchJson(`${ref.apiUrl}/primary-path`);
|
|
47
|
-
const sourceWorkspace = path.join(runtime.processWorkspacesDir, ref.id);
|
|
48
|
-
const baseDir = path.join(
|
|
49
|
-
sourceWorkspace,
|
|
50
|
-
".leitwerk",
|
|
51
|
-
"process-analysis",
|
|
52
|
-
input.analysisProcessId,
|
|
53
|
-
);
|
|
54
70
|
await mkdir(baseDir, { recursive: true });
|
|
55
71
|
await writeJson(path.join(baseDir, "process-detail.json"), detail);
|
|
56
72
|
await writeJson(path.join(baseDir, "primary-path.json"), primaryPath);
|
package/src/snapshot-markdown.ts
CHANGED
|
@@ -4,13 +4,18 @@ function fence(value: string, language = "json"): string {
|
|
|
4
4
|
return `${marker}${language}\n${value.endsWith("\n") ? value : `${value}\n`}${marker}`;
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
+
/** @internal */
|
|
7
8
|
export function jsonMarkdown(title: string, value: unknown): string {
|
|
8
9
|
return `# ${title}\n\n${fence(JSON.stringify(value, null, 2))}\n`;
|
|
9
10
|
}
|
|
10
11
|
|
|
12
|
+
/** @internal */
|
|
11
13
|
export function buildSummaryMarkdown(input: {
|
|
14
|
+
/** @internal */
|
|
12
15
|
detail: unknown;
|
|
16
|
+
/** @internal */
|
|
13
17
|
primaryPath: unknown;
|
|
18
|
+
/** @internal */
|
|
14
19
|
sourceUrl: string;
|
|
15
20
|
}): string {
|
|
16
21
|
const detail = input.detail as Record<string, unknown>;
|
|
@@ -28,6 +33,7 @@ export function buildSummaryMarkdown(input: {
|
|
|
28
33
|
].join("\n");
|
|
29
34
|
}
|
|
30
35
|
|
|
36
|
+
/** @internal */
|
|
31
37
|
export function buildRecordsMarkdown(title: string, value: unknown): string {
|
|
32
38
|
if (Array.isArray(value))
|
|
33
39
|
return [
|
package/src/state.ts
CHANGED
|
@@ -1,20 +1,30 @@
|
|
|
1
1
|
import type { Codec, StructuralProcessState } from "@leitwerk-dev/process-sdk";
|
|
2
2
|
import { parseStructuralProcessState } from "@leitwerk-dev/process-sdk";
|
|
3
3
|
|
|
4
|
+
/** @internal */
|
|
4
5
|
export interface ProcessAnalysisSnapshotState {
|
|
6
|
+
/** @internal */
|
|
5
7
|
sourceProcessId: string;
|
|
8
|
+
/** @internal */
|
|
6
9
|
apiUrl: string;
|
|
10
|
+
/** @internal */
|
|
7
11
|
snapshotDir: string;
|
|
12
|
+
/** @internal */
|
|
8
13
|
primaryPath?: unknown;
|
|
14
|
+
/** @internal */
|
|
9
15
|
downloadedAt: string;
|
|
10
16
|
}
|
|
11
17
|
|
|
18
|
+
/** @internal */
|
|
12
19
|
export interface ProcessAnalysisState extends StructuralProcessState {
|
|
20
|
+
/** @internal */
|
|
13
21
|
snapshot: ProcessAnalysisSnapshotState | null;
|
|
14
|
-
pendingHandoffInput: Record<string, unknown> | null;
|
|
15
22
|
}
|
|
16
23
|
|
|
17
|
-
|
|
24
|
+
/** @internal */
|
|
25
|
+
export function parseProcessAnalysisSnapshotState(
|
|
26
|
+
value: unknown,
|
|
27
|
+
): ProcessAnalysisSnapshotState | null {
|
|
18
28
|
if (typeof value !== "object" || value === null || Array.isArray(value)) return null;
|
|
19
29
|
const r = value as Record<string, unknown>;
|
|
20
30
|
if (typeof r.sourceProcessId !== "string" || typeof r.snapshotDir !== "string") return null;
|
|
@@ -27,16 +37,13 @@ function parseSnapshot(value: unknown): ProcessAnalysisSnapshotState | null {
|
|
|
27
37
|
};
|
|
28
38
|
}
|
|
29
39
|
|
|
40
|
+
/** @internal */
|
|
30
41
|
export const processAnalysisStateCodec: Codec<ProcessAnalysisState> = {
|
|
31
42
|
parse(value) {
|
|
32
43
|
const r = (typeof value === "object" && value !== null ? value : {}) as Record<string, unknown>;
|
|
33
44
|
return {
|
|
34
45
|
...parseStructuralProcessState(r),
|
|
35
|
-
snapshot:
|
|
36
|
-
pendingHandoffInput:
|
|
37
|
-
r.pendingHandoffInput && typeof r.pendingHandoffInput === "object"
|
|
38
|
-
? (r.pendingHandoffInput as Record<string, unknown>)
|
|
39
|
-
: null,
|
|
46
|
+
snapshot: parseProcessAnalysisSnapshotState(r.snapshot),
|
|
40
47
|
};
|
|
41
48
|
},
|
|
42
49
|
serialize(value) {
|
package/src/tools.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { ServerExtensionAPI } from "@leitwerk-dev/process-sdk";
|
|
2
|
+
import { downloadProcessSnapshot } from "./snapshot-downloader.js";
|
|
3
|
+
|
|
4
|
+
/** @internal */
|
|
5
|
+
export const processAnalysisDownloadSnapshotTool = "process_analysis_download_snapshot";
|
|
6
|
+
|
|
7
|
+
function parseArgs(value: unknown): { processRef: string } {
|
|
8
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
9
|
+
throw new Error("Tool arguments must be an object");
|
|
10
|
+
}
|
|
11
|
+
const processRef = (value as Record<string, unknown>).processRef;
|
|
12
|
+
if (typeof processRef !== "string" || !processRef.trim()) {
|
|
13
|
+
throw new Error("'processRef' must be a non-empty string");
|
|
14
|
+
}
|
|
15
|
+
return { processRef: processRef.trim() };
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** @internal */
|
|
19
|
+
export function registerProcessAnalysisTools(api: ServerExtensionAPI): void {
|
|
20
|
+
api.tool({
|
|
21
|
+
name: processAnalysisDownloadSnapshotTool,
|
|
22
|
+
description: "Download a durable snapshot of a process for read-only analysis",
|
|
23
|
+
parameters: {
|
|
24
|
+
type: "object",
|
|
25
|
+
properties: { processRef: { type: "string" } },
|
|
26
|
+
required: ["processRef"],
|
|
27
|
+
additionalProperties: false,
|
|
28
|
+
},
|
|
29
|
+
parse: parseArgs,
|
|
30
|
+
execute(ctx, args) {
|
|
31
|
+
return downloadProcessSnapshot({
|
|
32
|
+
analysisProcessId: ctx.process.id,
|
|
33
|
+
processRef: args.processRef,
|
|
34
|
+
});
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
}
|
package/dist/actions.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
export const processAnalysisActionIds = {
|
|
2
|
-
completeAnalysis: "complete_analysis",
|
|
3
|
-
askFollowup: "ask_followup",
|
|
4
|
-
refineAnalysis: "refine_analysis",
|
|
5
|
-
refreshSnapshot: "refresh_snapshot",
|
|
6
|
-
startLocalRepoChange: "start_local_repo_change",
|
|
7
|
-
};
|
|
8
|
-
export const followupForm = {
|
|
9
|
-
id: "process_analysis_followup",
|
|
10
|
-
title: "Follow up",
|
|
11
|
-
fields: [
|
|
12
|
-
{
|
|
13
|
-
id: "message",
|
|
14
|
-
label: "Question or refinement",
|
|
15
|
-
kind: "textarea",
|
|
16
|
-
primaryPrompt: true,
|
|
17
|
-
required: true,
|
|
18
|
-
},
|
|
19
|
-
],
|
|
20
|
-
submitLabel: "Send",
|
|
21
|
-
};
|
|
22
|
-
export const handoffForm = {
|
|
23
|
-
id: "process_analysis_handoff",
|
|
24
|
-
title: "Start Local Repo Change",
|
|
25
|
-
fields: [
|
|
26
|
-
{
|
|
27
|
-
id: "note",
|
|
28
|
-
label: "Handoff note",
|
|
29
|
-
kind: "textarea",
|
|
30
|
-
primaryPrompt: true,
|
|
31
|
-
description: "Optional implementation direction to prepend to the analysis.",
|
|
32
|
-
},
|
|
33
|
-
],
|
|
34
|
-
submitLabel: "Start change",
|
|
35
|
-
};
|
|
36
|
-
//# sourceMappingURL=actions.js.map
|
package/dist/actions.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"actions.js","sourceRoot":"","sources":["../src/actions.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,wBAAwB,GAAG;IACvC,gBAAgB,EAAE,mBAAmB;IACrC,WAAW,EAAE,cAAc;IAC3B,cAAc,EAAE,iBAAiB;IACjC,eAAe,EAAE,kBAAkB;IACnC,oBAAoB,EAAE,yBAAyB;CACtC,CAAC;AAEX,MAAM,CAAC,MAAM,YAAY,GAAG;IAC3B,EAAE,EAAE,2BAA2B;IAC/B,KAAK,EAAE,WAAW;IAClB,MAAM,EAAE;QACP;YACC,EAAE,EAAE,SAAS;YACb,KAAK,EAAE,wBAAwB;YAC/B,IAAI,EAAE,UAAmB;YACzB,aAAa,EAAE,IAAa;YAC5B,QAAQ,EAAE,IAAI;SACd;KACD;IACD,WAAW,EAAE,MAAM;CACnB,CAAC;AAEF,MAAM,CAAC,MAAM,WAAW,GAAG;IAC1B,EAAE,EAAE,0BAA0B;IAC9B,KAAK,EAAE,yBAAyB;IAChC,MAAM,EAAE;QACP;YACC,EAAE,EAAE,MAAM;YACV,KAAK,EAAE,cAAc;YACrB,IAAI,EAAE,UAAmB;YACzB,aAAa,EAAE,IAAa;YAC5B,WAAW,EAAE,+DAA+D;SAC5E;KACD;IACD,WAAW,EAAE,cAAc;CAC3B,CAAC"}
|
package/dist/params.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { trimString } from "@leitwerk-dev/domain";
|
|
2
|
-
export const processAnalysisParamsCodec = {
|
|
3
|
-
parse(value) {
|
|
4
|
-
const record = typeof value === "object" && value !== null ? value : {};
|
|
5
|
-
return {
|
|
6
|
-
processRef: trimString(record.processRef),
|
|
7
|
-
instruction: trimString(record.instruction),
|
|
8
|
-
analysisCwd: trimString(record.analysisCwd),
|
|
9
|
-
};
|
|
10
|
-
},
|
|
11
|
-
serialize(value) {
|
|
12
|
-
return value;
|
|
13
|
-
},
|
|
14
|
-
};
|
|
15
|
-
export function validateProcessAnalysisLaunchInput(input) {
|
|
16
|
-
const processRef = trimString(input.processRef);
|
|
17
|
-
const instruction = trimString(input.instruction);
|
|
18
|
-
const errors = [];
|
|
19
|
-
if (!processRef)
|
|
20
|
-
errors.push({ code: "required", fieldId: "processRef", message: "processRef is required" });
|
|
21
|
-
if (!instruction)
|
|
22
|
-
errors.push({ code: "required", fieldId: "instruction", message: "instruction is required" });
|
|
23
|
-
return errors.length ? { ok: false, errors } : { ok: true, value: { processRef, instruction } };
|
|
24
|
-
}
|
|
25
|
-
//# sourceMappingURL=params.js.map
|
package/dist/params.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"params.js","sourceRoot":"","sources":["../src/params.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAUlD,MAAM,CAAC,MAAM,0BAA0B,GAAiC;IACvE,KAAK,CAAC,KAAK;QACV,MAAM,MAAM,GAAG,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;QACxE,OAAO;YACN,UAAU,EAAE,UAAU,CAAE,MAAmC,CAAC,UAAU,CAAC;YACvE,WAAW,EAAE,UAAU,CAAE,MAAoC,CAAC,WAAW,CAAC;YAC1E,WAAW,EAAE,UAAU,CAAE,MAAoC,CAAC,WAAW,CAAC;SAC1E,CAAC;IACH,CAAC;IACD,SAAS,CAAC,KAAK;QACd,OAAO,KAAK,CAAC;IACd,CAAC;CACD,CAAC;AAKF,MAAM,UAAU,kCAAkC,CACjD,KAA8B;IAI9B,MAAM,UAAU,GAAG,UAAU,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IAChD,MAAM,WAAW,GAAG,UAAU,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;IAClD,MAAM,MAAM,GAA8B,EAAE,CAAC;IAC7C,IAAI,CAAC,UAAU;QACd,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,wBAAwB,EAAE,CAAC,CAAC;IAC7F,IAAI,CAAC,WAAW;QACf,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,yBAAyB,EAAE,CAAC,CAAC;IAC/F,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,UAAU,EAAE,WAAW,EAAE,EAAE,CAAC;AACjG,CAAC"}
|