mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +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
@@ -20,6 +20,7 @@ export const BUILTIN_COMMAND_ACTIONS = [
|
||||
'showSkills',
|
||||
'showSettings',
|
||||
'connectProvider',
|
||||
'showWalkthrough',
|
||||
] as const
|
||||
|
||||
type BuiltinCommandAction = (typeof BUILTIN_COMMAND_ACTIONS)[number]
|
||||
@@ -58,6 +59,7 @@ export const BUILTIN_COMMANDS: readonly BuiltinCommand[] = [
|
||||
{ name: 'details', description: 'Toggle tool execution details', action: 'toggleDetails' },
|
||||
{ name: 'mcp', description: 'Manage MCP servers', action: 'showMcp' },
|
||||
{ name: 'skills', description: 'Load a skill', action: 'showSkills' },
|
||||
{ name: 'walkthrough', description: 'Walk through the session changes, explained step by step', action: 'showWalkthrough' },
|
||||
{ name: 'settings', description: 'Open settings', action: 'showSettings' },
|
||||
{ name: 'connect', description: 'Connect a provider', action: 'connectProvider' },
|
||||
]
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
import { Clock, Star, type LucideIcon } from 'lucide-react'
|
||||
import {
|
||||
formatModelName,
|
||||
formatProviderName,
|
||||
providerModelRef,
|
||||
type ModelSelection,
|
||||
type OpenCodeModelState,
|
||||
type ProviderWithModels,
|
||||
} from '@/api/providers'
|
||||
|
||||
export interface ModelOption {
|
||||
value: string
|
||||
label: string
|
||||
providerName: string
|
||||
searchText: string
|
||||
}
|
||||
|
||||
export interface ModelSection {
|
||||
key: string
|
||||
title: string
|
||||
icon?: LucideIcon
|
||||
pinned: boolean
|
||||
options: ModelOption[]
|
||||
}
|
||||
|
||||
export function buildModelSections(providers: ProviderWithModels[], modelState: OpenCodeModelState | undefined): ModelSection[] {
|
||||
const optionsByValue = new Map<string, ModelOption>()
|
||||
const providerSections = providers.map((provider): ModelSection => {
|
||||
const providerName = formatProviderName(provider)
|
||||
const options = provider.models.map((model) => {
|
||||
const label = formatModelName(model)
|
||||
const value = providerModelRef(provider, model)
|
||||
const option = { value, label, providerName, searchText: `${label} ${value} ${providerName}`.toLowerCase() }
|
||||
optionsByValue.set(value, option)
|
||||
return option
|
||||
})
|
||||
return { key: `provider:${provider.id}`, title: providerName, pinned: false, options }
|
||||
})
|
||||
|
||||
const pinnedValues = new Set<string>()
|
||||
const pinOptions = (selections: ModelSelection[] = []) =>
|
||||
selections.flatMap((selection) => {
|
||||
const option = optionsByValue.get(providerModelRef({ id: selection.providerID }, { id: selection.modelID }))
|
||||
if (!option || pinnedValues.has(option.value)) return []
|
||||
pinnedValues.add(option.value)
|
||||
return [option]
|
||||
})
|
||||
|
||||
const favoriteOptions = pinOptions(modelState?.favorite)
|
||||
const recentOptions = pinOptions(modelState?.recent)
|
||||
const sections: ModelSection[] = [
|
||||
{ key: 'favorites', title: 'Favorites', icon: Star, pinned: true, options: favoriteOptions },
|
||||
{ key: 'recent', title: 'Recent', icon: Clock, pinned: true, options: recentOptions },
|
||||
...providerSections.map((section) => ({
|
||||
...section,
|
||||
options: section.options.filter((option) => !pinnedValues.has(option.value)),
|
||||
})),
|
||||
]
|
||||
return sections.filter((section) => section.options.length > 0)
|
||||
}
|
||||
|
||||
export function filterModelSections(sections: ModelSection[], query: string): ModelSection[] {
|
||||
const terms = query.toLowerCase().split(/\s+/).filter(Boolean)
|
||||
if (terms.length === 0) return sections
|
||||
|
||||
return sections
|
||||
.map((section) => ({
|
||||
...section,
|
||||
options: section.options.filter((option) => terms.every((term) => option.searchText.includes(term))),
|
||||
}))
|
||||
.filter((section) => section.options.length > 0)
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { parseDiffLines, splitDiffHunks } from '@opencode-manager/shared/utils';
|
||||
|
||||
const DIFF = [
|
||||
'diff --git a/src/app.ts b/src/app.ts',
|
||||
'index 1111111..2222222 100644',
|
||||
'--- a/src/app.ts',
|
||||
'+++ b/src/app.ts',
|
||||
'@@ -1,3 +1,4 @@',
|
||||
' const a = 1;',
|
||||
'-const b = 2;',
|
||||
'+const b = 3;',
|
||||
'+const c = 4;',
|
||||
'@@ -10,2 +11,2 @@',
|
||||
' const d = 5;',
|
||||
'-const e = 6;',
|
||||
'+const e = 7;',
|
||||
].join('\n');
|
||||
|
||||
describe('parseDiffLines', () => {
|
||||
it('classifies headers, hunks, additions, removals and context', () => {
|
||||
const lines = parseDiffLines(DIFF);
|
||||
|
||||
expect(lines.map((line) => line.type)).toEqual([
|
||||
'header',
|
||||
'header',
|
||||
'header',
|
||||
'header',
|
||||
'hunk',
|
||||
'context',
|
||||
'remove',
|
||||
'add',
|
||||
'add',
|
||||
'hunk',
|
||||
'context',
|
||||
'remove',
|
||||
'add',
|
||||
]);
|
||||
expect(lines[0]).toEqual({ type: 'header', content: 'diff --git a/src/app.ts b/src/app.ts' });
|
||||
});
|
||||
|
||||
it('tracks old and new line numbers across hunks', () => {
|
||||
const lines = parseDiffLines(DIFF);
|
||||
|
||||
expect(lines[5]).toMatchObject({ type: 'context', content: 'const a = 1;', oldLineNumber: 1, newLineNumber: 1 });
|
||||
expect(lines[6]).toMatchObject({ type: 'remove', content: 'const b = 2;', oldLineNumber: 2 });
|
||||
expect(lines[7]).toMatchObject({ type: 'add', content: 'const b = 3;', newLineNumber: 2 });
|
||||
expect(lines[10]).toMatchObject({ type: 'context', content: 'const d = 5;', oldLineNumber: 10, newLineNumber: 11 });
|
||||
});
|
||||
|
||||
it('returns an empty list for an empty diff', () => {
|
||||
expect(parseDiffLines('')).toEqual([{ type: 'context', content: '', oldLineNumber: 0, newLineNumber: 0 }]);
|
||||
});
|
||||
|
||||
it('treats ++/-- lines inside a hunk as additions and removals', () => {
|
||||
const lines = parseDiffLines('@@ -1,2 +1,2 @@\n---counter;\n+++counter;\n next();');
|
||||
|
||||
expect(lines.map((line) => line.type)).toEqual(['hunk', 'remove', 'add', 'context']);
|
||||
expect(lines[1]).toMatchObject({ type: 'remove', content: '--counter;', oldLineNumber: 1 });
|
||||
expect(lines[2]).toMatchObject({ type: 'add', content: '++counter;', newLineNumber: 1 });
|
||||
expect(lines[3]).toMatchObject({ type: 'context', content: 'next();', oldLineNumber: 2, newLineNumber: 2 });
|
||||
});
|
||||
|
||||
it('treats removed Markdown delimiter lines as removals', () => {
|
||||
const lines = parseDiffLines('@@ -1,3 +1,2 @@\n----\n title: x\n body');
|
||||
|
||||
expect(lines.map((line) => line.type)).toEqual(['hunk', 'remove', 'context', 'context']);
|
||||
expect(lines[1]).toMatchObject({ type: 'remove', content: '---', oldLineNumber: 1 });
|
||||
});
|
||||
|
||||
it('still recognizes real file headers before a hunk', () => {
|
||||
const patch = [
|
||||
'Index: docs/a.md',
|
||||
'===================================================================',
|
||||
'--- docs/a.md',
|
||||
'+++ docs/a.md',
|
||||
'@@ -1,1 +1,1 @@',
|
||||
'-a',
|
||||
'+b',
|
||||
].join('\n');
|
||||
const lines = parseDiffLines(patch);
|
||||
|
||||
expect(lines.map((line) => line.type)).toEqual(['header', 'header', 'hunk', 'remove', 'add']);
|
||||
expect(lines[0]).toMatchObject({ type: 'header', content: '--- docs/a.md' });
|
||||
expect(lines[1]).toMatchObject({ type: 'header', content: '+++ docs/a.md' });
|
||||
expect(lines[3]).toMatchObject({ type: 'remove', content: 'a', oldLineNumber: 1 });
|
||||
expect(lines[4]).toMatchObject({ type: 'add', content: 'b', newLineNumber: 1 });
|
||||
});
|
||||
});
|
||||
|
||||
describe('splitDiffHunks', () => {
|
||||
it('returns one entry per hunk with the header line and body', () => {
|
||||
const hunks = splitDiffHunks(DIFF);
|
||||
|
||||
expect(hunks).toHaveLength(2);
|
||||
expect(hunks[0].header).toBe('@@ -1,3 +1,4 @@');
|
||||
expect(hunks[0].text).toBe(
|
||||
['@@ -1,3 +1,4 @@', ' const a = 1;', '-const b = 2;', '+const b = 3;', '+const c = 4;'].join('\n'),
|
||||
);
|
||||
expect(hunks[1].header).toBe('@@ -10,2 +11,2 @@');
|
||||
expect(hunks[1].text).toContain('-const e = 6;');
|
||||
});
|
||||
|
||||
it('excludes lines before the first hunk', () => {
|
||||
const [first] = splitDiffHunks(DIFF);
|
||||
|
||||
expect(first.text.startsWith('@@')).toBe(true);
|
||||
expect(first.text).not.toContain('diff --git');
|
||||
expect(first.text).not.toContain('--- a/src/app.ts');
|
||||
});
|
||||
|
||||
it('returns an empty list for a binary patch with no hunk', () => {
|
||||
expect(splitDiffHunks('diff --git a/img.png b/img.png\nBinary files a/img.png and b/img.png differ')).toEqual([]);
|
||||
});
|
||||
|
||||
it('returns an empty list for an empty patch', () => {
|
||||
expect(splitDiffHunks('')).toEqual([]);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user