mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
feat: add multi-run fusion and session change walkthroughs
Fuse two to five completed multi-run entries into one synthesized session, and explain a session's diff as ordered walkthrough stops cached by diff hash. - Multi-run fusion service, persistence, routes and FuseRunDialog - Change walkthrough service, persistence, routes and ChangesWalkthroughDialog - Shared unified-diff parser plus bounded text generation, json-extract, text-truncate and service-error helpers
This commit is contained in:
1 parent
90c6ccf236
commit
b36d412ca2
66 files changed
+6228
-468
No files matched your search
@@ -0,0 +1,58 @@
|
||||
import { z } from "zod";
|
||||
|
||||
export const WALKTHROUGH_DIFF_MAX_CHARS = 60000;
|
||||
export const WALKTHROUGH_HUNK_MAX_CHARS = 8000;
|
||||
export const WALKTHROUGH_MAX_STOPS = 20;
|
||||
export const WALKTHROUGH_TEXT_MAX_CHARS = 2000;
|
||||
|
||||
export const WalkthroughHunkSchema = z.object({
|
||||
id: z.string(),
|
||||
file: z.string(),
|
||||
status: z.enum(["added", "deleted", "modified"]),
|
||||
header: z.string(),
|
||||
text: z.string(),
|
||||
truncated: z.boolean(),
|
||||
});
|
||||
|
||||
export type WalkthroughHunk = z.infer<typeof WalkthroughHunkSchema>;
|
||||
|
||||
export const WalkthroughStopSchema = z.object({
|
||||
title: z.string(),
|
||||
explanation: z.string(),
|
||||
hunkIds: z.array(z.string()),
|
||||
});
|
||||
|
||||
export type WalkthroughStop = z.infer<typeof WalkthroughStopSchema>;
|
||||
|
||||
export const WalkthroughOmittedFileSchema = z.object({
|
||||
file: z.string(),
|
||||
reason: z.enum(["binary", "budget"]),
|
||||
});
|
||||
|
||||
export type WalkthroughOmittedFile = z.infer<typeof WalkthroughOmittedFileSchema>;
|
||||
|
||||
export const ChangeWalkthroughSchema = z.object({
|
||||
sessionId: z.string(),
|
||||
diffHash: z.string(),
|
||||
summary: z.string(),
|
||||
stops: z.array(WalkthroughStopSchema),
|
||||
hunks: z.array(WalkthroughHunkSchema),
|
||||
omittedFiles: z.array(WalkthroughOmittedFileSchema),
|
||||
createdAt: z.number(),
|
||||
});
|
||||
|
||||
export type ChangeWalkthrough = z.infer<typeof ChangeWalkthroughSchema>;
|
||||
|
||||
export const ChangeWalkthroughStateSchema = z.object({
|
||||
walkthrough: ChangeWalkthroughSchema.nullable(),
|
||||
currentDiffHash: z.string().nullable(),
|
||||
stale: z.boolean(),
|
||||
});
|
||||
|
||||
export type ChangeWalkthroughState = z.infer<typeof ChangeWalkthroughStateSchema>;
|
||||
|
||||
export const GenerateChangeWalkthroughRequestSchema = z.object({
|
||||
regenerate: z.boolean().optional(),
|
||||
});
|
||||
|
||||
export type GenerateChangeWalkthroughRequest = z.infer<typeof GenerateChangeWalkthroughRequestSchema>;
|
||||
@@ -21,3 +21,4 @@ export * from './logs'
|
||||
export * from './terminal'
|
||||
export * from './project-config'
|
||||
export * from './preview'
|
||||
export * from './change-walkthroughs'
|
||||
@@ -1,3 +1,5 @@
|
||||
export const SESSION_PROMPT_MAX_LENGTH = 20000;
|
||||
export const FUSION_PROMPT_MAX_LENGTH = 60000;
|
||||
export const FUSION_INSTRUCTIONS_MAX_LENGTH = 4000;
|
||||
export const GOAL_MAX_CONTINUATIONS_MIN = 1;
|
||||
export const GOAL_MAX_CONTINUATIONS_MAX = 200;
|
||||
@@ -1,7 +1,8 @@
|
||||
import { z } from "zod";
|
||||
import { SESSION_PROMPT_MAX_LENGTH } from "./limits";
|
||||
import { FUSION_INSTRUCTIONS_MAX_LENGTH, SESSION_PROMPT_MAX_LENGTH } from "./limits";
|
||||
|
||||
export const MULTI_RUN_MAX_MODELS = 5;
|
||||
export const MULTI_RUN_FUSION_MIN_SOURCES = 2;
|
||||
|
||||
export const MultiRunEntryStatusSchema = z.enum(["starting", "started", "failed", "discarded"]);
|
||||
|
||||
@@ -21,6 +22,37 @@ export const MultiRunEntrySchema = z.object({
|
||||
|
||||
export type MultiRunEntry = z.infer<typeof MultiRunEntrySchema>;
|
||||
|
||||
export const MultiRunFusionStatusSchema = z.enum(["starting", "started", "failed"]);
|
||||
|
||||
export type MultiRunFusionStatus = z.infer<typeof MultiRunFusionStatusSchema>;
|
||||
|
||||
export const MultiRunFusionSourceSchema = z.object({
|
||||
entryId: z.number().int(),
|
||||
sessionId: z.string(),
|
||||
model: z.string(),
|
||||
truncated: z.boolean(),
|
||||
});
|
||||
|
||||
export type MultiRunFusionSource = z.infer<typeof MultiRunFusionSourceSchema>;
|
||||
|
||||
export const MultiRunFusionSchema = z.object({
|
||||
id: z.number().int(),
|
||||
requestId: z.string(),
|
||||
model: z.string(),
|
||||
instructions: z.string().nullable(),
|
||||
isolated: z.boolean(),
|
||||
baseRef: z.string().nullable(),
|
||||
status: MultiRunFusionStatusSchema,
|
||||
sessionId: z.string().nullable(),
|
||||
directory: z.string().nullable(),
|
||||
error: z.string().nullable(),
|
||||
sources: z.array(MultiRunFusionSourceSchema),
|
||||
createdAt: z.number(),
|
||||
updatedAt: z.number(),
|
||||
});
|
||||
|
||||
export type MultiRunFusion = z.infer<typeof MultiRunFusionSchema>;
|
||||
|
||||
export const MultiRunSchema = z.object({
|
||||
id: z.number().int(),
|
||||
repoId: z.number().int(),
|
||||
@@ -30,6 +62,7 @@ export const MultiRunSchema = z.object({
|
||||
baseRef: z.string().nullable(),
|
||||
createdAt: z.number(),
|
||||
entries: z.array(MultiRunEntrySchema),
|
||||
fusions: z.array(MultiRunFusionSchema),
|
||||
});
|
||||
|
||||
export type MultiRun = z.infer<typeof MultiRunSchema>;
|
||||
@@ -49,3 +82,45 @@ export const LaunchMultiRunRequestSchema = z.object({
|
||||
});
|
||||
|
||||
export type LaunchMultiRunRequest = z.infer<typeof LaunchMultiRunRequestSchema>;
|
||||
|
||||
export const FuseMultiRunRequestSchema = z.object({
|
||||
requestId: z.string().uuid(),
|
||||
entryIds: z
|
||||
.array(z.number().int())
|
||||
.min(MULTI_RUN_FUSION_MIN_SOURCES)
|
||||
.max(MULTI_RUN_MAX_MODELS)
|
||||
.refine((entryIds) => new Set(entryIds).size === entryIds.length, { message: "Entry ids must be unique" }),
|
||||
model: z.string().min(3),
|
||||
instructions: z.string().trim().max(FUSION_INSTRUCTIONS_MAX_LENGTH).optional(),
|
||||
isolate: z.boolean(),
|
||||
baseRef: z.string().trim().min(1).optional(),
|
||||
agent: z.string().optional(),
|
||||
});
|
||||
|
||||
export type FuseMultiRunRequest = z.infer<typeof FuseMultiRunRequestSchema>;
|
||||
|
||||
export const FusionUnavailableReasonSchema = z.enum([
|
||||
"not-started",
|
||||
"running",
|
||||
"incomplete",
|
||||
"failed",
|
||||
"missing",
|
||||
"unavailable",
|
||||
]);
|
||||
|
||||
export type FusionUnavailableReason = z.infer<typeof FusionUnavailableReasonSchema>;
|
||||
|
||||
export const FusionUnavailableSourceSchema = z.object({
|
||||
entryId: z.number().int(),
|
||||
model: z.string(),
|
||||
reason: FusionUnavailableReasonSchema,
|
||||
message: z.string(),
|
||||
});
|
||||
|
||||
export type FusionUnavailableSource = z.infer<typeof FusionUnavailableSourceSchema>;
|
||||
|
||||
export const FusionUnavailableDetailsSchema = z.object({
|
||||
unavailableSources: z.array(FusionUnavailableSourceSchema),
|
||||
});
|
||||
|
||||
export type FusionUnavailableDetails = z.infer<typeof FusionUnavailableDetailsSchema>;
|
||||
@@ -3,3 +3,4 @@ export * from './repo'
|
||||
export * from './sandbox-command'
|
||||
export * from './semver'
|
||||
export * from './terminal-title'
|
||||
export * from './unified-diff'
|
||||
@@ -0,0 +1,117 @@
|
||||
export interface DiffLine {
|
||||
type: "add" | "remove" | "context" | "header" | "hunk";
|
||||
content: string;
|
||||
oldLineNumber?: number;
|
||||
newLineNumber?: number;
|
||||
}
|
||||
|
||||
export interface DiffHunk {
|
||||
header: string;
|
||||
text: string;
|
||||
}
|
||||
|
||||
export function parseDiffLines(diff: string): DiffLine[] {
|
||||
const lines = diff.split("\n");
|
||||
const result: DiffLine[] = [];
|
||||
let oldLine = 0;
|
||||
let newLine = 0;
|
||||
let oldRemaining = 0;
|
||||
let newRemaining = 0;
|
||||
let inHunk = false;
|
||||
|
||||
for (const line of lines) {
|
||||
if (
|
||||
line.startsWith("diff --git") ||
|
||||
line.startsWith("index ") ||
|
||||
line.startsWith("Index:") ||
|
||||
line.startsWith("===")
|
||||
) {
|
||||
inHunk = false;
|
||||
if (line.startsWith("diff --git") || line.startsWith("index ")) {
|
||||
result.push({ type: "header", content: line });
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (line.startsWith("@@")) {
|
||||
const match = line.match(/@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/);
|
||||
if (match) {
|
||||
oldLine = parseInt(match[1]!, 10);
|
||||
newLine = parseInt(match[3]!, 10);
|
||||
oldRemaining = match[2] === undefined ? 1 : parseInt(match[2], 10);
|
||||
newRemaining = match[4] === undefined ? 1 : parseInt(match[4], 10);
|
||||
}
|
||||
inHunk = true;
|
||||
result.push({ type: "hunk", content: line });
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!inHunk && (line.startsWith("---") || line.startsWith("+++"))) {
|
||||
result.push({ type: "header", content: line });
|
||||
continue;
|
||||
}
|
||||
|
||||
if (line.startsWith("+")) {
|
||||
result.push({
|
||||
type: "add",
|
||||
content: line.substring(1),
|
||||
newLineNumber: newLine,
|
||||
});
|
||||
newLine++;
|
||||
newRemaining--;
|
||||
} else if (line.startsWith("-")) {
|
||||
result.push({
|
||||
type: "remove",
|
||||
content: line.substring(1),
|
||||
oldLineNumber: oldLine,
|
||||
});
|
||||
oldLine++;
|
||||
oldRemaining--;
|
||||
} else if (line.startsWith(" ") || line === "") {
|
||||
result.push({
|
||||
type: "context",
|
||||
content: line.substring(1) || "",
|
||||
oldLineNumber: oldLine,
|
||||
newLineNumber: newLine,
|
||||
});
|
||||
oldLine++;
|
||||
newLine++;
|
||||
oldRemaining--;
|
||||
newRemaining--;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (inHunk && oldRemaining <= 0 && newRemaining <= 0) {
|
||||
inHunk = false;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
export function splitDiffHunks(patch: string): DiffHunk[] {
|
||||
const hunks: DiffHunk[] = [];
|
||||
let current: string[] | null = null;
|
||||
|
||||
for (const line of patch.split("\n")) {
|
||||
if (line.startsWith("@@")) {
|
||||
if (current) {
|
||||
hunks.push(toHunk(current));
|
||||
}
|
||||
current = [line];
|
||||
} else if (current) {
|
||||
current.push(line);
|
||||
}
|
||||
}
|
||||
|
||||
if (current) {
|
||||
hunks.push(toHunk(current));
|
||||
}
|
||||
|
||||
return hunks;
|
||||
}
|
||||
|
||||
function toHunk(lines: string[]): DiffHunk {
|
||||
return { header: lines[0]!, text: lines.join("\n") };
|
||||
}
|
||||
Reference in new issue
Block a user