mirror of
https://github.com/open-webui/computer.git
synced 2026-11-23 14:10:45 -05:00
44 files changed
+2251
-1155
No files matched your search
@@ -5,6 +5,25 @@ All notable changes to this project will be documented in this file.
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [0.8.6] - 2026-07-09
|
||||
|
||||
### Added
|
||||
|
||||
- ✨ **Sharper diff reviews.** Review changes in split or unified view, hide whitespace-only edits, and spot changed words inside a line.
|
||||
- 📊 **Git change counts.** Git panels and file lists now show added and removed lines at a glance.
|
||||
|
||||
### Changed
|
||||
|
||||
- 🗂️ **Cleaner file browsing.** Files use more recognizable icons, and folder background menus make common actions easier to reach.
|
||||
- 🧭 **Sidebar chat cleanup.** Recent chats can now be deleted from the sidebar.
|
||||
- 📅 **Clearer scheduled-task naming.** Automations are now labeled Scheduled in the app and README.
|
||||
|
||||
### Fixed
|
||||
|
||||
- 🌐 **More reliable browser control.** Browser sessions recover more gracefully when a page connection closes.
|
||||
- 🧰 **More dependable tool use.** Tool calls and artifact creation are less likely to fail when workspace details are included.
|
||||
- 🧠 **Per-model chat cleanup.** Long chats now use the cleanup setting for the selected model.
|
||||
|
||||
## [0.8.5] - 2026-07-07
|
||||
|
||||
### Added
|
||||
|
||||
@@ -92,7 +92,7 @@ Bring your own API key (OpenAI, Anthropic, Ollama, or any OpenAI-compatible endp
|
||||
| ✏️ **Output editing** | Review and edit AI-generated changes before applying. |
|
||||
| 📎 **File mentions** | Type `@` to give the AI context about specific files. |
|
||||
| 🧩 **Skills** | Reusable instruction sets (SKILL.md files). Type `$` to mention one. |
|
||||
| ⏱️ **Automations** | Schedule recurring AI tasks. "Run tests every morning." "Deploy every Friday." |
|
||||
| ⏱️ **Scheduled** | Schedule recurring AI tasks. "Run tests every morning." "Deploy every Friday." |
|
||||
| 🤖 **Sub-agents** | AI spins up parallel workers for complex tasks. Each gets full tool access. |
|
||||
| 🔌 **Tool servers** | Connect external tools via MCP or OpenAPI. |
|
||||
| 🧠 **Context compaction** | Long conversations are automatically summarised to stay fast. |
|
||||
|
||||
@@ -39,8 +39,10 @@ export const getGitLog = (root: string, limit = 30) =>
|
||||
|
||||
export const getGitDiff = (params: string) => fetchJSON(`/api/git/diff?${params}`);
|
||||
|
||||
export const getGitShow = (root: string, ref: string) =>
|
||||
fetchJSON(`/api/git/show?root=${encodeURIComponent(root)}&ref=${encodeURIComponent(ref)}`);
|
||||
export const getGitShow = (root: string, ref: string, ignoreWhitespace = false) =>
|
||||
fetchJSON(
|
||||
`/api/git/show?root=${encodeURIComponent(root)}&ref=${encodeURIComponent(ref)}&ignore_whitespace=${ignoreWhitespace}`
|
||||
);
|
||||
|
||||
export const getGitBranches = (root: string) =>
|
||||
fetchJSON(`/api/git/branches?root=${encodeURIComponent(root)}`);
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
<script lang="ts">
|
||||
import type { DiffHunk } from '$lib/utils/diff';
|
||||
import DiffHunkRows from './DiffHunkRows.svelte';
|
||||
|
||||
interface Props {
|
||||
hunks: DiffHunk[];
|
||||
path: string;
|
||||
showNumbers?: boolean;
|
||||
}
|
||||
|
||||
let { hunks, path, showNumbers = false }: Props = $props();
|
||||
</script>
|
||||
|
||||
{#each hunks as hunk}
|
||||
{#if showNumbers}
|
||||
<div
|
||||
class="grid w-full grid-cols-[2.75rem_2.75rem_1.25rem_auto] border-b border-gray-100 bg-gray-50 text-gray-400 dark:border-white/4 dark:bg-white/3 dark:text-gray-600"
|
||||
>
|
||||
<span></span>
|
||||
<span></span>
|
||||
<span></span>
|
||||
<code class="whitespace-pre px-2 py-0.5">{hunk.header}</code>
|
||||
</div>
|
||||
{:else}
|
||||
<div
|
||||
class="w-full border-b border-gray-100 bg-gray-50 px-2 py-0.5 text-gray-400 dark:border-white/4 dark:bg-white/3 dark:text-gray-600"
|
||||
>
|
||||
{hunk.header}
|
||||
</div>
|
||||
{/if}
|
||||
<DiffHunkRows {hunk} {path} {showNumbers} />
|
||||
{/each}
|
||||
@@ -0,0 +1,186 @@
|
||||
<script lang="ts">
|
||||
import { diffDisplayMode } from '$lib/stores/gitDiffSettings';
|
||||
import {
|
||||
groupDiffLines,
|
||||
numberDiffLines,
|
||||
splitDiffRows,
|
||||
withInlineDiffSegments,
|
||||
languageForPath,
|
||||
type DiffHunk,
|
||||
type DiffLine,
|
||||
type InlineDiffLine
|
||||
} from '$lib/utils/diff';
|
||||
import SyntaxDiffLine from './SyntaxDiffLine.svelte';
|
||||
|
||||
interface Props {
|
||||
hunk: DiffHunk;
|
||||
path: string;
|
||||
showNumbers?: boolean;
|
||||
}
|
||||
|
||||
let { hunk, path, showNumbers = true }: Props = $props();
|
||||
|
||||
const lines = $derived(withInlineDiffSegments(numberDiffLines(hunk)));
|
||||
const language = $derived(languageForPath(path));
|
||||
|
||||
function blockClass(type: DiffLine['type']): string {
|
||||
if (type === 'added')
|
||||
return 'bg-green-100 border-l-[0.1875rem] border-l-green-500 dark:bg-green-500/15 dark:border-l-green-400';
|
||||
if (type === 'removed') return 'bg-red-100 diff-gutter-removed dark:bg-red-500/15';
|
||||
return '';
|
||||
}
|
||||
|
||||
function textClass(type: DiffLine['type']): string {
|
||||
if (type === 'added') return 'text-green-900 dark:text-green-300';
|
||||
if (type === 'removed') return 'text-red-900 dark:text-red-300';
|
||||
return 'text-gray-600 dark:text-gray-400';
|
||||
}
|
||||
|
||||
function prefixClass(type: DiffLine['type']): string {
|
||||
if (type === 'added') return 'text-green-600 dark:text-green-400';
|
||||
if (type === 'removed') return 'text-red-500 dark:text-red-400';
|
||||
return 'text-gray-400 dark:text-gray-600';
|
||||
}
|
||||
|
||||
function linePrefix(type: DiffLine['type']): string {
|
||||
if (type === 'added') return '+';
|
||||
if (type === 'removed') return '-';
|
||||
return ' ';
|
||||
}
|
||||
|
||||
function blankSegments(): InlineDiffLine['segments'] {
|
||||
return [{ text: ' ', changed: false }];
|
||||
}
|
||||
|
||||
function splitCellClass(line: InlineDiffLine | null): string {
|
||||
if (!line) return '';
|
||||
if (line.type === 'added') return 'bg-green-100 dark:bg-green-500/15';
|
||||
if (line.type === 'removed') return 'bg-red-100 dark:bg-red-500/15';
|
||||
return '';
|
||||
}
|
||||
</script>
|
||||
|
||||
{#if $diffDisplayMode === 'split'}
|
||||
{#each splitDiffRows(lines) as row}
|
||||
<div
|
||||
class="grid w-full {showNumbers
|
||||
? 'grid-cols-[2.75rem_minmax(0,1fr)_2.75rem_minmax(0,1fr)]'
|
||||
: 'grid-cols-[minmax(0,1fr)_minmax(0,1fr)]'}"
|
||||
>
|
||||
{#if showNumbers}
|
||||
<span
|
||||
class="select-none border-r border-black/5 px-2 text-right text-gray-400 dark:border-white/4 dark:text-gray-600 {splitCellClass(
|
||||
row.oldLine
|
||||
)}">{row.oldLine?.oldNumber ?? ''}</span
|
||||
>
|
||||
{/if}
|
||||
<div class="min-w-0 {splitCellClass(row.oldLine)}">
|
||||
{#if row.oldLine}
|
||||
<SyntaxDiffLine
|
||||
type={row.oldLine.type}
|
||||
content={row.oldLine.content || ' '}
|
||||
segments={row.oldLine.segments}
|
||||
{language}
|
||||
wrap
|
||||
class={textClass(row.oldLine.type)}
|
||||
/>
|
||||
{:else}
|
||||
<SyntaxDiffLine
|
||||
type="context"
|
||||
content=" "
|
||||
segments={blankSegments()}
|
||||
language="text"
|
||||
wrap
|
||||
class="text-transparent"
|
||||
/>
|
||||
{/if}
|
||||
</div>
|
||||
{#if showNumbers}
|
||||
<span
|
||||
class="select-none border-l border-r border-black/5 px-2 text-right text-gray-400 dark:border-white/4 dark:text-gray-600 {splitCellClass(
|
||||
row.newLine
|
||||
)}">{row.newLine?.newNumber ?? ''}</span
|
||||
>
|
||||
{/if}
|
||||
<div
|
||||
class="min-w-0 border-l border-black/5 dark:border-white/4 {splitCellClass(row.newLine)}"
|
||||
>
|
||||
{#if row.newLine}
|
||||
<SyntaxDiffLine
|
||||
type={row.newLine.type}
|
||||
content={row.newLine.content || ' '}
|
||||
segments={row.newLine.segments}
|
||||
{language}
|
||||
wrap
|
||||
class={textClass(row.newLine.type)}
|
||||
/>
|
||||
{:else}
|
||||
<SyntaxDiffLine
|
||||
type="context"
|
||||
content=" "
|
||||
segments={blankSegments()}
|
||||
language="text"
|
||||
wrap
|
||||
class="text-transparent"
|
||||
/>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
{:else}
|
||||
{#each groupDiffLines(lines) as group}
|
||||
<div class="w-full {blockClass(group.type)}">
|
||||
{#each group.lines as line}
|
||||
{#if showNumbers}
|
||||
<div class="grid w-full grid-cols-[2.75rem_2.75rem_1.25rem_auto]">
|
||||
<span
|
||||
class="select-none border-r border-black/5 px-2 text-right text-gray-400 dark:border-white/4 dark:text-gray-600"
|
||||
>{line.oldNumber ?? ''}</span
|
||||
>
|
||||
<span
|
||||
class="select-none border-r border-black/5 px-2 text-right text-gray-400 dark:border-white/4 dark:text-gray-600"
|
||||
>{line.newNumber ?? ''}</span
|
||||
>
|
||||
<span class="select-none px-1 text-center {prefixClass(line.type)}"
|
||||
>{linePrefix(line.type)}</span
|
||||
>
|
||||
<SyntaxDiffLine
|
||||
type={line.type}
|
||||
content={line.content || ' '}
|
||||
segments={line.segments}
|
||||
{language}
|
||||
class={textClass(line.type)}
|
||||
/>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="flex min-w-max">
|
||||
<span class="select-none px-2 text-center {prefixClass(line.type)}"
|
||||
>{linePrefix(line.type)}</span
|
||||
>
|
||||
<SyntaxDiffLine
|
||||
type={line.type}
|
||||
content={line.content || ' '}
|
||||
segments={line.segments}
|
||||
{language}
|
||||
class={textClass(line.type)}
|
||||
/>
|
||||
</div>
|
||||
{/if}
|
||||
{/each}
|
||||
</div>
|
||||
{/each}
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
.diff-gutter-removed {
|
||||
border-left: 0.1875rem solid transparent;
|
||||
border-image: repeating-linear-gradient(
|
||||
-45deg,
|
||||
#ef4444 0,
|
||||
#ef4444 1px,
|
||||
transparent 1px,
|
||||
transparent 0.1875rem
|
||||
)
|
||||
3;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,86 @@
|
||||
<script lang="ts">
|
||||
import { diffDisplayMode, hideWhitespaceChanges } from '$lib/stores/gitDiffSettings';
|
||||
import DropdownMenu from './DropdownMenu.svelte';
|
||||
import Icon from './Icon.svelte';
|
||||
|
||||
interface Props {
|
||||
anchor: HTMLElement;
|
||||
onclose: () => void;
|
||||
preferAbove?: boolean;
|
||||
forceAbove?: boolean;
|
||||
}
|
||||
|
||||
let { anchor, onclose, preferAbove = false, forceAbove = false }: Props = $props();
|
||||
|
||||
function toggleWhitespace() {
|
||||
hideWhitespaceChanges.set(!$hideWhitespaceChanges);
|
||||
}
|
||||
</script>
|
||||
|
||||
<DropdownMenu
|
||||
items={[]}
|
||||
{anchor}
|
||||
{onclose}
|
||||
{preferAbove}
|
||||
{forceAbove}
|
||||
align="end"
|
||||
className="w-48"
|
||||
headerDivider={false}
|
||||
footerDivider={false}
|
||||
>
|
||||
<div class="py-0.5 text-xs font-normal">
|
||||
<button
|
||||
type="button"
|
||||
class="app-interactive app-muted flex h-6 w-full items-center gap-2 rounded-xl px-2 text-left text-xs font-normal transition-colors duration-75"
|
||||
onclick={toggleWhitespace}
|
||||
aria-pressed={$hideWhitespaceChanges}
|
||||
>
|
||||
<Icon name="code" size={13} class="app-icon-muted shrink-0" />
|
||||
<span class="min-w-0 flex-1 truncate">Hide whitespace</span>
|
||||
<span
|
||||
class="relative h-3.5 w-6 shrink-0 rounded-full transition-colors duration-150 {$hideWhitespaceChanges
|
||||
? 'bg-gray-900 dark:bg-white'
|
||||
: 'bg-gray-300 dark:bg-gray-700'}"
|
||||
>
|
||||
<span
|
||||
class="absolute top-[0.125rem] h-2.5 w-2.5 rounded-full transition-all duration-150 {$hideWhitespaceChanges
|
||||
? 'left-[0.75rem] bg-white dark:bg-black'
|
||||
: 'left-[0.125rem] bg-white dark:bg-gray-500'}"
|
||||
></span>
|
||||
</span>
|
||||
</button>
|
||||
|
||||
<div class="app-muted px-2 pb-0.5 pt-1 text-[0.625rem] leading-none uppercase">
|
||||
Diff Display
|
||||
</div>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
class="flex h-6 w-full items-center gap-2 rounded-xl px-2 text-left text-xs font-normal transition-colors duration-75 {$diffDisplayMode ===
|
||||
'unified'
|
||||
? 'app-interactive-active'
|
||||
: 'app-interactive app-muted'}"
|
||||
onclick={() => diffDisplayMode.set('unified')}
|
||||
>
|
||||
<Icon name="list" size={13} class="app-icon-muted shrink-0" />
|
||||
<span class="min-w-0 flex-1 truncate text-left">Unified</span>
|
||||
{#if $diffDisplayMode === 'unified'}
|
||||
<Icon name="check" size={11} class="app-icon-muted shrink-0" />
|
||||
{/if}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="flex h-6 w-full items-center gap-2 rounded-xl px-2 text-left text-xs font-normal transition-colors duration-75 {$diffDisplayMode ===
|
||||
'split'
|
||||
? 'app-interactive-active'
|
||||
: 'app-interactive app-muted'}"
|
||||
onclick={() => diffDisplayMode.set('split')}
|
||||
>
|
||||
<Icon name="split-view" size={13} class="app-icon-muted shrink-0" />
|
||||
<span class="min-w-0 flex-1 truncate">Split</span>
|
||||
{#if $diffDisplayMode === 'split'}
|
||||
<Icon name="check" size={11} class="app-icon-muted shrink-0" />
|
||||
{/if}
|
||||
</button>
|
||||
</div>
|
||||
</DropdownMenu>
|
||||
@@ -74,6 +74,7 @@
|
||||
let contextMenu = $state<{ x: number; y: number; entry: TreeEntry; anchor?: HTMLElement } | null>(
|
||||
null
|
||||
);
|
||||
let directoryMenu = $state<{ x: number; y: number } | null>(null);
|
||||
let renamingEntry = $state<string | null>(null);
|
||||
let renameValue = $state('');
|
||||
|
||||
@@ -864,18 +865,37 @@
|
||||
// ── Context menu ───────────────────────────────────────────
|
||||
function onContextMenu(e: MouseEvent, entry: TreeEntry) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
directoryMenu = null;
|
||||
contextMenu = { x: e.clientX, y: e.clientY, entry };
|
||||
}
|
||||
|
||||
function openEntryMenu(e: MouseEvent | KeyboardEvent, entry: TreeEntry) {
|
||||
e.stopPropagation();
|
||||
directoryMenu = null;
|
||||
contextMenu = { x: 0, y: 0, entry, anchor: e.currentTarget as HTMLElement };
|
||||
}
|
||||
|
||||
function onDirectoryContextMenu(e: MouseEvent) {
|
||||
if ((e.target as HTMLElement | null)?.closest('input, textarea, [contenteditable="true"]')) {
|
||||
return;
|
||||
}
|
||||
|
||||
e.preventDefault();
|
||||
contextMenu = null;
|
||||
addMenuOpen = false;
|
||||
sortMenuOpen = false;
|
||||
directoryMenu = { x: e.clientX, y: e.clientY };
|
||||
}
|
||||
|
||||
function closeMenu() {
|
||||
contextMenu = null;
|
||||
}
|
||||
|
||||
function closeDirectoryMenu() {
|
||||
directoryMenu = null;
|
||||
}
|
||||
|
||||
function startRename(entry: TreeEntry) {
|
||||
renamingEntry = entry.path;
|
||||
renameValue = entry.name;
|
||||
@@ -1044,7 +1064,7 @@
|
||||
<!-- Sort bar replaced with dropdown in toolbar -->
|
||||
|
||||
<!-- File list -->
|
||||
<div class="flex-1 overflow-y-auto p-1">
|
||||
<div class="flex-1 overflow-y-auto p-1" oncontextmenu={onDirectoryContextMenu}>
|
||||
<!-- New item input -->
|
||||
{#if showNewInput}
|
||||
<div class="flex items-center gap-2 h-7 px-2">
|
||||
@@ -1208,9 +1228,14 @@
|
||||
{/if}
|
||||
{#if fileGitStatus && entryGitDecoration}
|
||||
<span
|
||||
class="text-[0.625rem] font-mono font-bold shrink-0 {entryGitDecoration.badgeColor}"
|
||||
use:tooltip={gitStatusTooltip(fileGitStatus, entry)}>{entryGitDecoration.char}</span
|
||||
class="flex shrink-0 items-center gap-1 text-[0.625rem] font-mono font-medium"
|
||||
use:tooltip={gitStatusTooltip(fileGitStatus, entry)}
|
||||
>
|
||||
<span class="text-green-600 dark:text-green-400"
|
||||
>+{fileGitStatus.additions ?? 0}</span
|
||||
>
|
||||
<span class="text-red-500 dark:text-red-400">-{fileGitStatus.deletions ?? 0}</span>
|
||||
</span>
|
||||
{/if}
|
||||
{#if entry.type !== 'directory' && entry.size !== null}
|
||||
<span
|
||||
@@ -1325,6 +1350,30 @@
|
||||
/>
|
||||
{/if}
|
||||
|
||||
{#if directoryMenu}
|
||||
<DropdownMenu
|
||||
anchor={{ x: directoryMenu.x, y: directoryMenu.y }}
|
||||
items={[
|
||||
{
|
||||
label: $t('files.refresh'),
|
||||
icon: 'refresh',
|
||||
onclick: () => fetchDirectory(cwd)
|
||||
},
|
||||
{ label: '', divider: true, onclick: () => {} },
|
||||
{ label: $t('files.newFile'), icon: 'plus', onclick: () => startNew('file') },
|
||||
{ label: $t('files.newFolder'), icon: 'folder', onclick: () => startNew('folder') },
|
||||
{ label: $t('files.uploadFile'), icon: 'upload', onclick: () => handleUploadFromMenu() },
|
||||
{ label: '', divider: true, onclick: () => {} },
|
||||
{
|
||||
label: showHidden ? $t('files.hideHidden') : $t('files.showHidden'),
|
||||
icon: 'eye',
|
||||
onclick: () => toggleHidden()
|
||||
}
|
||||
]}
|
||||
onclose={closeDirectoryMenu}
|
||||
/>
|
||||
{/if}
|
||||
|
||||
{#if contextMenu}
|
||||
<DropdownMenu
|
||||
anchor={contextMenu.anchor ?? { x: contextMenu.x, y: contextMenu.y }}
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
<script lang="ts">
|
||||
import { onMount, onDestroy } from 'svelte';
|
||||
import { onMount, onDestroy, tick } from 'svelte';
|
||||
import { clearTabEdit, markTabUnsaved, updateTabFilePath, activeWorkspace } from '$lib/stores';
|
||||
import { get } from 'svelte/store';
|
||||
import { t } from '$lib/i18n';
|
||||
import { tooltip } from '$lib/tooltip';
|
||||
import { readFile, writeFile } from '$lib/apis/files';
|
||||
import { getGitDiff } from '$lib/apis/git';
|
||||
import { diffDisplayMode, hideWhitespaceChanges } from '$lib/stores/gitDiffSettings';
|
||||
import { gitStatusStore, type GitFile } from '$lib/stores/gitStatus.svelte';
|
||||
import Icon from './Icon.svelte';
|
||||
import SaveDialog from './SaveDialog.svelte';
|
||||
@@ -20,6 +21,7 @@
|
||||
import SvgPreview from './preview/SvgPreview.svelte';
|
||||
import OfficePreview from './preview/OfficePreview.svelte';
|
||||
import Spinner from './common/Spinner.svelte';
|
||||
import DiffHunkList from './DiffHunkList.svelte';
|
||||
import {
|
||||
EditorState,
|
||||
StateEffect,
|
||||
@@ -158,11 +160,11 @@
|
||||
type DiffHunk = { header: string; lines: DiffLine[] };
|
||||
type DiffFileEntry = { path: string; hunks: DiffHunk[] };
|
||||
type NumberedLine = DiffLine & { oldNumber: number | null; newNumber: number | null };
|
||||
type LineGroup = { type: DiffLine['type']; lines: NumberedLine[] };
|
||||
type GitLineChange = { line: number; type: 'added' | 'modified' };
|
||||
let diffMode = $state(false);
|
||||
let diffFiles = $state<DiffFileEntry[]>([]);
|
||||
let diffLoading = $state(false);
|
||||
let diffScrollEl: HTMLDivElement | undefined;
|
||||
let hasGitChanges = $state(false);
|
||||
let gitLineChanges: GitLineChange[] = [];
|
||||
let gitBaseContent: string | null = null;
|
||||
@@ -265,16 +267,6 @@
|
||||
});
|
||||
}
|
||||
|
||||
function diffGroupLines(lines: NumberedLine[]): LineGroup[] {
|
||||
const groups: LineGroup[] = [];
|
||||
for (const line of lines) {
|
||||
const last = groups[groups.length - 1];
|
||||
if (last && last.type === line.type) last.lines.push(line);
|
||||
else groups.push({ type: line.type, lines: [line] });
|
||||
}
|
||||
return groups;
|
||||
}
|
||||
|
||||
function splitLines(text: string): string[] {
|
||||
return text.length === 0 ? [] : text.split('\n');
|
||||
}
|
||||
@@ -403,6 +395,8 @@
|
||||
return status.files?.find((f) => f.path === relPath);
|
||||
}
|
||||
|
||||
let currentFileStatus = $derived(fileData ? gitFileStatus(fileData.path) : undefined);
|
||||
|
||||
function applyGitLineChanges() {
|
||||
gitLineChanges = normalizeGitLineChanges(gitLineChanges);
|
||||
view?.dispatch({ effects: setGitLineChangesEffect.of(gitLineChanges) });
|
||||
@@ -535,31 +529,6 @@
|
||||
applyGitLineChanges();
|
||||
}
|
||||
|
||||
function diffBlockClass(type: DiffLine['type']): string {
|
||||
if (type === 'added')
|
||||
return 'bg-green-100 border-l-[0.1875rem] border-l-green-500 dark:bg-green-500/15 dark:border-l-green-400';
|
||||
if (type === 'removed') return 'bg-red-100 diff-gutter-removed dark:bg-red-500/15';
|
||||
return '';
|
||||
}
|
||||
|
||||
function diffTextClass(type: DiffLine['type']): string {
|
||||
if (type === 'added') return 'text-green-900 dark:text-green-300';
|
||||
if (type === 'removed') return 'text-red-900 dark:text-red-300';
|
||||
return 'text-gray-600 dark:text-gray-400';
|
||||
}
|
||||
|
||||
function diffPrefixClass(type: DiffLine['type']): string {
|
||||
if (type === 'added') return 'text-green-600 dark:text-green-400';
|
||||
if (type === 'removed') return 'text-red-500 dark:text-red-400';
|
||||
return 'text-gray-400 dark:text-gray-600';
|
||||
}
|
||||
|
||||
function diffPrefix(type: DiffLine['type']): string {
|
||||
if (type === 'added') return '+';
|
||||
if (type === 'removed') return '-';
|
||||
return ' ';
|
||||
}
|
||||
|
||||
// Editing state: true when the code editor should be active
|
||||
let isEditing = $derived(
|
||||
fileData &&
|
||||
@@ -796,11 +765,13 @@
|
||||
!fileData.binary &&
|
||||
!isBinaryPreview &&
|
||||
!isCsv &&
|
||||
!isMarkdown &&
|
||||
!(isMarkdown && markdownMode !== 'raw') &&
|
||||
!(isHtml || isSvg) &&
|
||||
!(isJson && !jsonParseError)
|
||||
) {
|
||||
requestAnimationFrame(() => initEditor(fileData!.content!, fileData!.language));
|
||||
requestAnimationFrame(() =>
|
||||
initEditor(fileData!.content!, isMarkdown ? 'markdown' : fileData!.language)
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -820,7 +791,8 @@
|
||||
root: ws.path,
|
||||
file: relPath,
|
||||
staged: 'false',
|
||||
untracked: String(fileStatus?.status === 'untracked')
|
||||
untracked: String(fileStatus?.status === 'untracked'),
|
||||
ignore_whitespace: String($hideWhitespaceChanges)
|
||||
});
|
||||
const d = (await getGitDiff(params.toString())) as { files?: DiffFileEntry[] };
|
||||
diffFiles = d.files ?? [];
|
||||
@@ -828,6 +800,8 @@
|
||||
diffFiles = [];
|
||||
} finally {
|
||||
diffLoading = false;
|
||||
await tick();
|
||||
if (diffScrollEl) diffScrollEl.scrollLeft = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1063,7 +1037,15 @@
|
||||
<!-- Universal toolbar (hidden for untitled files with no content yet) -->
|
||||
<div class="toolbar">
|
||||
<div class="toolbar-left">
|
||||
<span class="file-name scrollbar-none">{fileData.name}</span>
|
||||
<span class="file-title">
|
||||
<span class="file-name scrollbar-none">{fileData.name}</span>
|
||||
{#if currentFileStatus}
|
||||
<span class="file-git-stats">
|
||||
<span class="file-git-additions">+{currentFileStatus.additions ?? 0}</span>
|
||||
<span class="file-git-deletions">-{currentFileStatus.deletions ?? 0}</span>
|
||||
</span>
|
||||
{/if}
|
||||
</span>
|
||||
<span class="file-size">{formatSize(fileData.size)}</span>
|
||||
</div>
|
||||
<div class="toolbar-right">
|
||||
@@ -1155,6 +1137,25 @@
|
||||
{:else if error}
|
||||
<div class="state error">{error}</div>
|
||||
|
||||
<!-- Diff view -->
|
||||
{:else if diffMode}
|
||||
{#if diffLoading}
|
||||
<div class="state"><Spinner size={20} /></div>
|
||||
{:else if diffFiles.length === 0}
|
||||
<div class="state">
|
||||
<p class="state-title">{$t('editor.noChanges')}</p>
|
||||
<p class="state-sub">{$t('editor.noUncommittedModifications')}</p>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="diff-scroll" bind:this={diffScrollEl}>
|
||||
<div class="diff-content" class:diff-content-split={$diffDisplayMode === 'split'}>
|
||||
{#each diffFiles as df}
|
||||
<DiffHunkList hunks={df.hunks} path={df.path} />
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<!-- ── Binary previews ─────────────────────────────── -->
|
||||
{:else if isImage && binaryUrl}
|
||||
<ImagePreview src={binaryUrl} alt={fileData?.name ?? ''} />
|
||||
@@ -1214,58 +1215,8 @@
|
||||
<p class="state-title">{$t('editor.binaryFile')}</p>
|
||||
<p class="state-sub">{fileData.name} ({formatSize(fileData.size)})</p>
|
||||
</div>
|
||||
{:else if diffMode}
|
||||
<!-- Diff view -->
|
||||
{#if diffLoading}
|
||||
<div class="state"><Spinner size={20} /></div>
|
||||
{:else if diffFiles.length === 0}
|
||||
<div class="state">
|
||||
<p class="state-title">{$t('editor.noChanges')}</p>
|
||||
<p class="state-sub">{$t('editor.noUncommittedModifications')}</p>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="diff-scroll">
|
||||
{#each diffFiles as df}
|
||||
{#each df.hunks as hunk}
|
||||
<div
|
||||
class="grid w-full grid-cols-[2.75rem_2.75rem_1.25rem_auto] border-b border-gray-100 bg-gray-50 text-gray-400 dark:border-white/4 dark:bg-white/3 dark:text-gray-600 font-mono text-[0.6875rem]"
|
||||
>
|
||||
<span></span>
|
||||
<span></span>
|
||||
<span></span>
|
||||
<code class="whitespace-pre px-2 py-0.5">{hunk.header}</code>
|
||||
</div>
|
||||
{#each diffGroupLines(diffNumberedLines(hunk)) as group}
|
||||
<div class="w-full {diffBlockClass(group.type)}">
|
||||
{#each group.lines as line}
|
||||
<div
|
||||
class="grid w-full grid-cols-[2.75rem_2.75rem_1.25rem_auto] font-mono text-[0.6875rem] leading-[1.125rem]"
|
||||
>
|
||||
<span
|
||||
class="select-none border-r border-black/5 px-2 text-right text-gray-400 dark:border-white/4 dark:text-gray-600"
|
||||
>{line.oldNumber ?? ''}</span
|
||||
>
|
||||
<span
|
||||
class="select-none border-r border-black/5 px-2 text-right text-gray-400 dark:border-white/4 dark:text-gray-600"
|
||||
>{line.newNumber ?? ''}</span
|
||||
>
|
||||
<span class="select-none px-1 text-center {diffPrefixClass(line.type)}"
|
||||
>{diffPrefix(line.type)}</span
|
||||
>
|
||||
<code class="whitespace-pre px-2 {diffTextClass(line.type)}"
|
||||
>{line.content || ' '}</code
|
||||
>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{/each}
|
||||
{/each}
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<!-- ┌ Code editor (default) ───────────────────── -->
|
||||
{:else}
|
||||
<!-- ┌ Code editor (default) ───────────────────── -->
|
||||
<div bind:this={editorEl} class="editor-el"></div>
|
||||
{/if}
|
||||
|
||||
@@ -1324,10 +1275,20 @@
|
||||
gap: 0.125rem;
|
||||
}
|
||||
|
||||
.file-title {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex: 1 1 auto;
|
||||
gap: 0.375rem;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.file-name {
|
||||
display: block;
|
||||
flex: 1 1 auto;
|
||||
flex: 0 1 auto;
|
||||
min-width: 0;
|
||||
max-width: 100%;
|
||||
overflow-x: auto;
|
||||
overflow-y: hidden;
|
||||
white-space: nowrap;
|
||||
@@ -1344,6 +1305,34 @@
|
||||
color: var(--color-gray-300);
|
||||
}
|
||||
|
||||
.file-git-stats {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex: 0 0 auto;
|
||||
gap: 0.25rem;
|
||||
font-family:
|
||||
ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', monospace;
|
||||
font-size: 0.6875rem;
|
||||
font-weight: 500;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.file-git-additions {
|
||||
color: #16a34a;
|
||||
}
|
||||
|
||||
.file-git-deletions {
|
||||
color: #ef4444;
|
||||
}
|
||||
|
||||
:global(.dark) .file-git-additions {
|
||||
color: #4ade80;
|
||||
}
|
||||
|
||||
:global(.dark) .file-git-deletions {
|
||||
color: #f87171;
|
||||
}
|
||||
|
||||
.file-size {
|
||||
flex: 0 0 auto;
|
||||
white-space: nowrap;
|
||||
@@ -1477,92 +1466,16 @@
|
||||
height: 100%;
|
||||
overflow: auto;
|
||||
font-family: 'JetBrains Mono', 'Fira Code', ui-monospace, monospace;
|
||||
font-size: 0.75rem;
|
||||
font-size: 0.6875rem;
|
||||
line-height: 1.125rem;
|
||||
}
|
||||
|
||||
.diff-hunk-header {
|
||||
padding: 0.125rem 0.5rem;
|
||||
color: var(--color-gray-400);
|
||||
background: var(--color-gray-50);
|
||||
.diff-content {
|
||||
width: max-content;
|
||||
min-width: 100%;
|
||||
}
|
||||
|
||||
:global(.dark) .diff-hunk-header {
|
||||
background: rgba(255, 255, 255, 0.03);
|
||||
color: var(--color-gray-600);
|
||||
}
|
||||
|
||||
.diff-line {
|
||||
padding: 0 0.5rem;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.diff-prefix {
|
||||
display: inline-block;
|
||||
width: 1rem;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.diff-added {
|
||||
background: #dcfce7;
|
||||
color: #14532d;
|
||||
}
|
||||
|
||||
:global(.dark) .diff-added {
|
||||
background: rgba(34, 197, 94, 0.12);
|
||||
color: #86efac;
|
||||
}
|
||||
|
||||
.diff-added .diff-prefix {
|
||||
color: #16a34a;
|
||||
}
|
||||
:global(.dark) .diff-added .diff-prefix {
|
||||
color: #4ade80;
|
||||
}
|
||||
|
||||
.diff-removed {
|
||||
background: #fee2e2;
|
||||
color: #7f1d1d;
|
||||
}
|
||||
|
||||
:global(.dark) .diff-removed {
|
||||
background: rgba(239, 68, 68, 0.12);
|
||||
color: #fca5a5;
|
||||
}
|
||||
|
||||
.diff-removed .diff-prefix {
|
||||
color: #ef4444;
|
||||
}
|
||||
:global(.dark) .diff-removed .diff-prefix {
|
||||
color: #f87171;
|
||||
}
|
||||
|
||||
.diff-ctx {
|
||||
color: var(--color-gray-600);
|
||||
}
|
||||
|
||||
:global(.dark) .diff-ctx {
|
||||
color: var(--color-gray-400);
|
||||
}
|
||||
|
||||
.diff-ctx .diff-prefix {
|
||||
color: var(--color-gray-400);
|
||||
}
|
||||
|
||||
:global(.dark) .diff-ctx .diff-prefix {
|
||||
color: var(--color-gray-600);
|
||||
}
|
||||
|
||||
.diff-gutter-removed {
|
||||
border-left: 0.1875rem solid transparent;
|
||||
border-image: repeating-linear-gradient(
|
||||
-45deg,
|
||||
#ef4444 0,
|
||||
#ef4444 1px,
|
||||
transparent 1px,
|
||||
transparent 0.1875rem
|
||||
)
|
||||
3;
|
||||
.diff-content-split {
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
@@ -26,12 +26,16 @@
|
||||
renameGitBranch
|
||||
} from '$lib/apis/git';
|
||||
import { gitStatusStore } from '$lib/stores/gitStatus.svelte';
|
||||
import { diffDisplayMode, hideWhitespaceChanges } from '$lib/stores/gitDiffSettings';
|
||||
import Icon from './Icon.svelte';
|
||||
import DropdownMenu from './DropdownMenu.svelte';
|
||||
import Modal from './Modal.svelte';
|
||||
import { tooltip } from '$lib/tooltip';
|
||||
import { t } from '$lib/i18n';
|
||||
import Spinner from '$lib/components/common/Spinner.svelte';
|
||||
import DiffSettingsMenu from './DiffSettingsMenu.svelte';
|
||||
import { countDiffStats, type DiffFile } from '$lib/utils/diff';
|
||||
import DiffHunkList from './DiffHunkList.svelte';
|
||||
|
||||
type GitFile = {
|
||||
path: string;
|
||||
@@ -40,9 +44,9 @@
|
||||
unstaged?: boolean;
|
||||
staged_status?: string;
|
||||
unstaged_status?: string;
|
||||
additions?: number;
|
||||
deletions?: number;
|
||||
};
|
||||
type DiffHunk = { header: string; lines: { type: string; content: string }[] };
|
||||
type DiffFile = { path: string; hunks: DiffHunk[] };
|
||||
type Commit = { hash: string; short_hash: string; author: string; date: string; message: string };
|
||||
type BranchItem = {
|
||||
name: string;
|
||||
@@ -77,8 +81,10 @@
|
||||
let showDiff = $state(false);
|
||||
let showBranches = $state(false);
|
||||
let showWorktrees = $state(false);
|
||||
let showDiffSettings = $state(false);
|
||||
let branchBtnEl = $state<HTMLButtonElement | undefined>();
|
||||
let worktreeBtnEl = $state<HTMLButtonElement | undefined>();
|
||||
let diffSettingsBtnEl = $state<HTMLButtonElement | undefined>();
|
||||
let branchSearchInputEl = $state<HTMLInputElement | undefined>();
|
||||
let worktreeSearchInputEl = $state<HTMLInputElement | undefined>();
|
||||
let newBranchInputEl = $state<HTMLInputElement | undefined>();
|
||||
@@ -112,6 +118,13 @@
|
||||
const stagedFiles = $derived((gitStatus?.files ?? []).filter((f) => f.staged));
|
||||
const unstagedFiles = $derived((gitStatus?.files ?? []).filter((f) => !f.staged));
|
||||
const totalChanges = $derived((gitStatus?.files ?? []).length);
|
||||
const totalAdditions = $derived(
|
||||
(gitStatus?.files ?? []).reduce((sum, file) => sum + (file.additions ?? 0), 0)
|
||||
);
|
||||
const totalDeletions = $derived(
|
||||
(gitStatus?.files ?? []).reduce((sum, file) => sum + (file.deletions ?? 0), 0)
|
||||
);
|
||||
const selectedDiffStats = $derived(countDiffStats(fileDiff));
|
||||
const allStaged = $derived(totalChanges > 0 && unstagedFiles.length === 0);
|
||||
const someStaged = $derived(stagedFiles.length > 0 && unstagedFiles.length > 0);
|
||||
|
||||
@@ -180,6 +193,15 @@
|
||||
}
|
||||
});
|
||||
|
||||
let _prevHideWhitespace = false;
|
||||
$effect(() => {
|
||||
const hideWhitespace = $hideWhitespaceChanges;
|
||||
if (hideWhitespace === _prevHideWhitespace) return;
|
||||
_prevHideWhitespace = hideWhitespace;
|
||||
if (!expanded || !showDiff) return;
|
||||
reloadSelectedDiff();
|
||||
});
|
||||
|
||||
// Auto-select first file
|
||||
$effect(() => {
|
||||
if (
|
||||
@@ -206,7 +228,8 @@
|
||||
const params = new URLSearchParams({
|
||||
root: workspacePath,
|
||||
file: path,
|
||||
staged: String(staged)
|
||||
staged: String(staged),
|
||||
ignore_whitespace: String($hideWhitespaceChanges)
|
||||
});
|
||||
if (untracked) params.set('untracked', 'true');
|
||||
const d = await getGitDiff(params.toString());
|
||||
@@ -221,7 +244,7 @@
|
||||
selectedFile = null;
|
||||
showDiff = true;
|
||||
try {
|
||||
const d = await getGitShow(workspacePath, c.hash);
|
||||
const d = await getGitShow(workspacePath, c.hash, $hideWhitespaceChanges);
|
||||
fileDiff = d.diff?.files ?? [];
|
||||
} catch {
|
||||
fileDiff = [];
|
||||
@@ -232,6 +255,16 @@
|
||||
showDiff = false;
|
||||
}
|
||||
|
||||
function reloadSelectedDiff() {
|
||||
if (selectedCommit) {
|
||||
selectCommit(selectedCommit);
|
||||
return;
|
||||
}
|
||||
if (!selectedFile) return;
|
||||
const file = (gitStatus?.files ?? []).find((item) => item.path === selectedFile);
|
||||
if (file) selectFile(file.path, file.staged, file.status === 'untracked');
|
||||
}
|
||||
|
||||
async function loadHistory() {
|
||||
try {
|
||||
commits = await getGitLog(workspacePath, 50);
|
||||
@@ -640,25 +673,6 @@
|
||||
return `${Math.floor(s / 86400)}d`;
|
||||
}
|
||||
|
||||
function statusChar(s: string): { char: string; color: string } {
|
||||
switch (s) {
|
||||
case 'added':
|
||||
return { char: 'A', color: 'text-green-500' };
|
||||
case 'untracked':
|
||||
return { char: 'U', color: 'text-green-500' };
|
||||
case 'modified':
|
||||
return { char: 'M', color: 'text-amber-500' };
|
||||
case 'deleted':
|
||||
return { char: 'D', color: 'text-red-400' };
|
||||
case 'renamed':
|
||||
return { char: 'R', color: 'text-blue-400' };
|
||||
case 'conflict':
|
||||
return { char: '!', color: 'text-orange-500' };
|
||||
default:
|
||||
return { char: '?', color: 'text-gray-400' };
|
||||
}
|
||||
}
|
||||
|
||||
const syncAction = $derived.by(() => {
|
||||
if (!gitStatus) return { label: $t('git.fetch'), icon: 'refresh', action: doFetch };
|
||||
if (gitStatus.behind > 0)
|
||||
@@ -710,32 +724,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
type LineGroup = { type: string; lines: { type: string; content: string }[] };
|
||||
|
||||
function groupLines(lines: { type: string; content: string }[]): LineGroup[] {
|
||||
const groups: LineGroup[] = [];
|
||||
for (const line of lines) {
|
||||
const last = groups[groups.length - 1];
|
||||
if (last && last.type === line.type) {
|
||||
last.lines.push(line);
|
||||
} else {
|
||||
groups.push({ type: line.type, lines: [line] });
|
||||
}
|
||||
}
|
||||
return groups;
|
||||
}
|
||||
|
||||
function blockClass(type: string): string {
|
||||
switch (type) {
|
||||
case 'added':
|
||||
return 'bg-green-100 border-l-[0.1875rem] border-l-green-500 dark:bg-green-500/15 dark:border-l-green-400';
|
||||
case 'removed':
|
||||
return 'bg-red-100 diff-gutter-removed dark:bg-red-500/15';
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
$effect(() => {
|
||||
if (!expanded) return;
|
||||
function onKeydown(e: KeyboardEvent) {
|
||||
@@ -764,7 +752,7 @@
|
||||
<!-- Collapsed bar (entire bar is clickable to expand) -->
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
<div
|
||||
class="flex items-center h-7 px-3 cursor-pointer hover:bg-gray-50 dark:hover:bg-white/3 transition-colors duration-75"
|
||||
class="flex min-w-0 items-center h-7 px-3 cursor-pointer hover:bg-gray-50 dark:hover:bg-white/3 transition-colors duration-75"
|
||||
onclick={() => {
|
||||
expanded = !expanded;
|
||||
if (expanded) {
|
||||
@@ -776,11 +764,12 @@
|
||||
<!-- Branch button (opens branch picker, stops expand) -->
|
||||
<button
|
||||
bind:this={branchBtnEl}
|
||||
class="flex items-center gap-1.5 h-6 px-1.5 -ml-1.5 rounded-md hover:bg-gray-100 dark:hover:bg-white/6 transition-colors duration-75"
|
||||
class="flex min-w-0 max-w-32 shrink items-center gap-1.5 h-6 px-1.5 -ml-1.5 rounded-md hover:bg-gray-100 dark:hover:bg-white/6 transition-colors duration-75"
|
||||
onclick={toggleBranches}
|
||||
>
|
||||
<Icon name="git-branch" size={12} class="text-gray-400 dark:text-gray-600 shrink-0" />
|
||||
<span class="text-[0.6875rem] text-gray-600 dark:text-gray-400 font-mono"
|
||||
<span
|
||||
class="min-w-0 truncate whitespace-nowrap text-[0.6875rem] text-gray-600 dark:text-gray-400 font-mono"
|
||||
>{gitStatus.branch}</span
|
||||
>
|
||||
<Icon name="chevron-down" size={9} class="text-gray-400 dark:text-gray-600" />
|
||||
@@ -788,18 +777,19 @@
|
||||
|
||||
<button
|
||||
bind:this={worktreeBtnEl}
|
||||
class="flex items-center gap-1.5 h-6 px-1.5 rounded-md hover:bg-gray-100 dark:hover:bg-white/6 transition-colors duration-75"
|
||||
class="flex min-w-0 max-w-32 shrink items-center gap-1.5 h-6 px-1.5 rounded-md hover:bg-gray-100 dark:hover:bg-white/6 transition-colors duration-75"
|
||||
onclick={toggleWorktrees}
|
||||
>
|
||||
<Icon name="folder" size={12} class="text-gray-400 dark:text-gray-600 shrink-0" />
|
||||
<span class="text-[0.6875rem] text-gray-500 dark:text-gray-500 font-mono"
|
||||
<span
|
||||
class="min-w-0 truncate whitespace-nowrap text-[0.6875rem] text-gray-500 dark:text-gray-500 font-mono"
|
||||
>{pathTail(workspacePath)}</span
|
||||
>
|
||||
<Icon name="chevron-down" size={9} class="text-gray-400 dark:text-gray-600" />
|
||||
</button>
|
||||
|
||||
{#if gitStatus.ahead > 0}<span
|
||||
class="text-[0.625rem] font-mono text-gray-400 dark:text-gray-600 ml-1.5"
|
||||
class="ml-1.5 shrink-0 whitespace-nowrap text-[0.625rem] font-mono text-gray-400 dark:text-gray-600"
|
||||
>↑{gitStatus.ahead}</span
|
||||
>{/if}
|
||||
{#if gitStatus.behind > 0}<span
|
||||
@@ -807,11 +797,14 @@
|
||||
>↓{gitStatus.behind}</span
|
||||
>{/if}
|
||||
{#if totalChanges > 0}<span
|
||||
class="text-[0.625rem] font-mono text-gray-400 dark:text-gray-600 ml-1.5"
|
||||
class="mx-1.5 block min-w-0 max-w-20 shrink truncate whitespace-nowrap text-[0.625rem] font-mono text-gray-400 dark:text-gray-600"
|
||||
>{$t('git.changedCount', { count: totalChanges })}</span
|
||||
><span class="mx-1.5 flex shrink-0 items-center gap-1 text-[0.625rem] font-mono"
|
||||
><span class="text-green-600 dark:text-green-400">+{totalAdditions}</span>
|
||||
<span class="text-red-500 dark:text-red-400">-{totalDeletions}</span></span
|
||||
>{/if}
|
||||
{#if actionMsg}<span
|
||||
class="text-[0.625rem] font-mono text-gray-400 dark:text-gray-600 ml-auto"
|
||||
class="ml-auto min-w-0 max-w-32 truncate whitespace-nowrap text-[0.625rem] font-mono text-gray-400 dark:text-gray-600"
|
||||
>{actionMsg}</span
|
||||
>{/if}
|
||||
|
||||
@@ -819,7 +812,7 @@
|
||||
|
||||
<!-- Sync button (stops expand) -->
|
||||
<button
|
||||
class="flex items-center gap-1 h-6 px-2 rounded-md text-[0.6875rem] text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 hover:bg-gray-100 dark:hover:bg-white/6 transition-colors duration-75"
|
||||
class="flex shrink-0 items-center gap-1 h-6 px-2 rounded-md text-[0.6875rem] text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 hover:bg-gray-100 dark:hover:bg-white/6 transition-colors duration-75"
|
||||
onclick={(e) => {
|
||||
e.stopPropagation();
|
||||
syncAction.action();
|
||||
@@ -827,7 +820,7 @@
|
||||
disabled={loading}
|
||||
>
|
||||
<Icon name={syncAction.icon} size={12} />
|
||||
<span>{syncAction.label}</span>
|
||||
<span class="whitespace-nowrap">{syncAction.label}</span>
|
||||
</button>
|
||||
|
||||
<!-- Chevron indicator -->
|
||||
@@ -1174,6 +1167,16 @@
|
||||
</a>
|
||||
{/if}
|
||||
|
||||
<button
|
||||
bind:this={diffSettingsBtnEl}
|
||||
class="flex items-center justify-center w-6 h-6 rounded-md text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 hover:bg-gray-100 dark:hover:bg-white/6 transition-colors duration-75"
|
||||
onclick={() => (showDiffSettings = true)}
|
||||
use:tooltip={'Diff settings'}
|
||||
aria-label="Diff settings"
|
||||
>
|
||||
<Icon name="settings" size={12} />
|
||||
</button>
|
||||
|
||||
<!-- Maximize toggle -->
|
||||
<button
|
||||
class="flex items-center justify-center w-6 h-6 rounded-md text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 hover:bg-gray-100 dark:hover:bg-white/6 transition-colors duration-75"
|
||||
@@ -1184,18 +1187,26 @@
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{#if showDiffSettings && diffSettingsBtnEl}
|
||||
<DiffSettingsMenu
|
||||
anchor={diffSettingsBtnEl}
|
||||
onclose={() => (showDiffSettings = false)}
|
||||
preferAbove
|
||||
/>
|
||||
{/if}
|
||||
|
||||
<!-- Content -->
|
||||
<div class="flex min-h-36" style="height: {panelHeight}px;">
|
||||
<div class="flex min-h-36 min-w-0" style="height: {panelHeight}px;">
|
||||
<!-- Left pane: file list or commit list -->
|
||||
<div
|
||||
class="w-full md:w-60 lg:w-72 shrink-0 md:border-r md:border-gray-100 md:dark:border-white/4 flex flex-col overflow-hidden
|
||||
class="w-full min-w-0 md:w-60 lg:w-72 shrink-0 md:border-r md:border-gray-100 md:dark:border-white/4 flex flex-col overflow-hidden
|
||||
{showDiff ? 'hidden md:flex' : 'flex'}"
|
||||
>
|
||||
{#if view === 'changes'}
|
||||
<!-- Global checkbox -->
|
||||
{#if totalChanges > 0}
|
||||
<button
|
||||
class="flex items-center gap-1.5 h-7 px-2.5 border-b border-gray-100 dark:border-white/4 hover:bg-gray-50 dark:hover:bg-white/3 transition-colors duration-75 shrink-0"
|
||||
class="flex min-w-0 items-center gap-1.5 h-7 px-2.5 border-b border-gray-100 dark:border-white/4 hover:bg-gray-50 dark:hover:bg-white/3 transition-colors duration-75 shrink-0"
|
||||
onclick={toggleAll}
|
||||
>
|
||||
<span
|
||||
@@ -1214,19 +1225,18 @@
|
||||
/>
|
||||
{/if}
|
||||
</span>
|
||||
<span class="text-[0.6875rem] text-gray-600 dark:text-gray-400"
|
||||
<span class="min-w-0 truncate text-[0.6875rem] text-gray-600 dark:text-gray-400"
|
||||
>{$t('git.changedFile', { count: totalChanges })}</span
|
||||
>
|
||||
</button>
|
||||
{/if}
|
||||
|
||||
<!-- File list -->
|
||||
<div class="flex-1 overflow-y-auto">
|
||||
<div class="min-w-0 flex-1 overflow-x-hidden overflow-y-auto">
|
||||
{#each gitStatus?.files ?? [] as file (file.path)}
|
||||
{@const fp = fPath(file.path)}
|
||||
{@const sc = statusChar(file.status)}
|
||||
<button
|
||||
class="group flex items-center gap-1.5 w-full h-7 px-2.5 text-left transition-colors duration-75
|
||||
class="group flex min-w-0 items-center gap-1.5 w-full h-7 px-2.5 text-left transition-colors duration-75
|
||||
{selectedFile === file.path
|
||||
? 'bg-gray-100 dark:bg-white/8'
|
||||
: 'hover:bg-gray-50 dark:hover:bg-white/3'}"
|
||||
@@ -1247,23 +1257,28 @@
|
||||
<Icon name="check" size={7} class="text-white dark:text-black" />
|
||||
{/if}
|
||||
</span>
|
||||
{#if fp.dir}
|
||||
<span class="flex min-w-0 flex-1 items-baseline gap-1.5">
|
||||
{#if fp.dir}
|
||||
<span
|
||||
class="min-w-0 truncate text-[0.625rem] text-gray-400 dark:text-gray-600"
|
||||
>{fp.dir}</span
|
||||
>
|
||||
{/if}
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
<span
|
||||
class="text-[0.625rem] text-gray-400 dark:text-gray-600 truncate shrink min-w-0"
|
||||
>{fp.dir}</span
|
||||
class="min-w-0 max-w-[55%] shrink-0 truncate text-[0.6875rem] text-gray-800 dark:text-gray-200 hover:underline cursor-pointer"
|
||||
onclick={(e) => {
|
||||
e.stopPropagation();
|
||||
openFileTab(workspacePath.replace(/\/$/, '') + '/' + file.path);
|
||||
}}>{fp.name}</span
|
||||
>
|
||||
{/if}
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
</span>
|
||||
<span
|
||||
class="text-[0.6875rem] text-gray-800 dark:text-gray-200 truncate shrink-0 hover:underline cursor-pointer"
|
||||
onclick={(e) => {
|
||||
e.stopPropagation();
|
||||
openFileTab(workspacePath.replace(/\/$/, '') + '/' + file.path);
|
||||
}}>{fp.name}</span
|
||||
>
|
||||
<span class="ml-auto text-[0.625rem] font-mono font-bold shrink-0 {sc.color}"
|
||||
>{sc.char}</span
|
||||
class="flex shrink-0 items-center gap-1 text-[0.625rem] font-mono font-medium"
|
||||
>
|
||||
<span class="text-green-600 dark:text-green-400">+{file.additions ?? 0}</span>
|
||||
<span class="text-red-500 dark:text-red-400">-{file.deletions ?? 0}</span>
|
||||
</span>
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
<span
|
||||
class="flex items-center justify-center w-5 h-5 rounded shrink-0 text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 hover:bg-gray-200 dark:hover:bg-white/10 transition-all duration-75"
|
||||
@@ -1319,7 +1334,7 @@
|
||||
</div>
|
||||
{:else}
|
||||
<!-- History: commit list -->
|
||||
<div class="flex-1 overflow-y-auto">
|
||||
<div class="min-w-0 flex-1 overflow-x-hidden overflow-y-auto">
|
||||
{#each commits as c, i}
|
||||
{#if i === unpushedCount && unpushedCount > 0}
|
||||
<div
|
||||
@@ -1381,23 +1396,31 @@
|
||||
|
||||
<!-- Right pane: diff viewer -->
|
||||
<div
|
||||
class="flex-1 overflow-hidden font-mono text-[0.6875rem] leading-[1.125rem]
|
||||
class="min-w-0 flex-1 overflow-hidden font-mono text-[0.6875rem] leading-[1.125rem]
|
||||
{showDiff ? 'flex flex-col' : 'hidden md:flex md:flex-col'}"
|
||||
>
|
||||
{#if fileDiff.length}
|
||||
<div
|
||||
class="hidden md:flex items-center h-6 px-2 border-b border-gray-100 dark:border-white/4 shrink-0"
|
||||
>
|
||||
<span class="text-[0.625rem] text-gray-400 dark:text-gray-600 font-mono truncate">
|
||||
<span
|
||||
class="min-w-0 flex-1 text-[0.625rem] text-gray-400 dark:text-gray-600 font-mono truncate"
|
||||
>
|
||||
{#if selectedCommit}
|
||||
{selectedCommit.short_hash} · {selectedCommit.message}
|
||||
{:else}
|
||||
{selectedFile}
|
||||
{/if}
|
||||
</span>
|
||||
<span class="ml-2 text-[0.625rem] font-mono text-green-600 dark:text-green-400"
|
||||
>+{selectedDiffStats.additions}</span
|
||||
>
|
||||
<span class="text-[0.625rem] font-mono text-red-500 dark:text-red-400"
|
||||
>-{selectedDiffStats.deletions}</span
|
||||
>
|
||||
</div>
|
||||
<div class="flex-1 overflow-auto">
|
||||
<div class="diff-content">
|
||||
<div class="diff-content" class:diff-content-split={$diffDisplayMode === 'split'}>
|
||||
{#each fileDiff as df}
|
||||
{#if fileDiff.length > 1}
|
||||
<div
|
||||
@@ -1406,39 +1429,7 @@
|
||||
{df.path}
|
||||
</div>
|
||||
{/if}
|
||||
{#each df.hunks as hunk}
|
||||
<div
|
||||
class="px-2 py-0.5 text-gray-400 dark:text-gray-600 bg-gray-50 dark:bg-white/3 border-b border-gray-100 dark:border-white/4 w-full"
|
||||
>
|
||||
{hunk.header}
|
||||
</div>
|
||||
{#each groupLines(hunk.lines) as group}
|
||||
<div class="w-full {blockClass(group.type)}">
|
||||
{#each group.lines as line}
|
||||
<div class="px-2 whitespace-pre-wrap break-all">
|
||||
<span
|
||||
class={line.type === 'added'
|
||||
? 'text-green-600 dark:text-green-400'
|
||||
: line.type === 'removed'
|
||||
? 'text-red-500 dark:text-red-400'
|
||||
: 'text-gray-400 dark:text-gray-600'}
|
||||
>{line.type === 'added'
|
||||
? '+'
|
||||
: line.type === 'removed'
|
||||
? '-'
|
||||
: ' '}</span
|
||||
><span
|
||||
class={line.type === 'added'
|
||||
? 'text-green-900 dark:text-green-300'
|
||||
: line.type === 'removed'
|
||||
? 'text-red-900 dark:text-red-300'
|
||||
: 'text-gray-600 dark:text-gray-400'}>{line.content}</span
|
||||
>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{/each}
|
||||
{/each}
|
||||
<DiffHunkList hunks={df.hunks} path={df.path} />
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
@@ -1632,16 +1623,8 @@
|
||||
min-width: 100%;
|
||||
}
|
||||
|
||||
.diff-gutter-removed {
|
||||
border-left: 0.1875rem solid transparent;
|
||||
border-image: repeating-linear-gradient(
|
||||
-45deg,
|
||||
#ef4444 0,
|
||||
#ef4444 1px,
|
||||
transparent 1px,
|
||||
transparent 0.1875rem
|
||||
)
|
||||
3;
|
||||
.diff-content-split {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.git-resize-handle {
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
<script lang="ts">
|
||||
import { activeWorkspace, openFileTab, gitReviewOpen } from '$lib/stores';
|
||||
import { getGitDiff } from '$lib/apis/git';
|
||||
import { diffDisplayMode, hideWhitespaceChanges } from '$lib/stores/gitDiffSettings';
|
||||
import { gitStatusStore, type GitStatus, type GitFile } from '$lib/stores/gitStatus.svelte';
|
||||
|
||||
import { tooltip } from '$lib/tooltip';
|
||||
import { t } from '$lib/i18n';
|
||||
import { countDiffStats, type DiffFile } from '$lib/utils/diff';
|
||||
import Icon from './Icon.svelte';
|
||||
import Spinner from '$lib/components/common/Spinner.svelte';
|
||||
import DiffSettingsMenu from './DiffSettingsMenu.svelte';
|
||||
import DiffHunkList from './DiffHunkList.svelte';
|
||||
|
||||
type DiffLine = { type: 'added' | 'removed' | 'context'; content: string };
|
||||
type DiffHunk = { header: string; lines: DiffLine[] };
|
||||
type DiffFile = { path: string; hunks: DiffHunk[] };
|
||||
type ReviewFile = {
|
||||
key: string;
|
||||
path: string;
|
||||
@@ -21,31 +22,37 @@
|
||||
deletions: number;
|
||||
expanded: boolean;
|
||||
};
|
||||
type NumberedLine = DiffLine & { oldNumber: number | null; newNumber: number | null };
|
||||
|
||||
let gitStatus = $derived(gitStatusStore.status);
|
||||
let reviewFiles = $state<ReviewFile[]>([]);
|
||||
let loading = $state(false);
|
||||
let refreshing = $state(false);
|
||||
let error = $state('');
|
||||
let showDiffSettings = $state(false);
|
||||
let diffSettingsButtonEl = $state<HTMLButtonElement | undefined>();
|
||||
let loadSeq = 0;
|
||||
|
||||
const workspacePath = $derived($activeWorkspace?.path ?? '');
|
||||
const totalChanges = $derived(reviewFiles.length);
|
||||
const totalAdditions = $derived(reviewFiles.reduce((sum, file) => sum + file.additions, 0));
|
||||
const totalDeletions = $derived(reviewFiles.reduce((sum, file) => sum + file.deletions, 0));
|
||||
const anyExpanded = $derived(reviewFiles.some((file) => file.expanded));
|
||||
|
||||
// React to git status changes from centralized store
|
||||
let _prevStatusRef: GitStatus | null = null;
|
||||
let _prevHideWhitespace = false;
|
||||
$effect(() => {
|
||||
const status = gitStatus;
|
||||
const hideWhitespace = $hideWhitespaceChanges;
|
||||
if (!workspacePath || !status) {
|
||||
reviewFiles = [];
|
||||
return;
|
||||
}
|
||||
// Only re-fetch diffs when status actually changes
|
||||
if (status !== _prevStatusRef) {
|
||||
if (status !== _prevStatusRef || hideWhitespace !== _prevHideWhitespace) {
|
||||
const isInitial = _prevStatusRef === null;
|
||||
_prevStatusRef = status;
|
||||
_prevHideWhitespace = hideWhitespace;
|
||||
fetchDiffs(status, isInitial);
|
||||
}
|
||||
});
|
||||
@@ -71,7 +78,8 @@
|
||||
const params = new URLSearchParams({
|
||||
root,
|
||||
file: file.path,
|
||||
staged: String(file.staged)
|
||||
staged: String(file.staged),
|
||||
ignore_whitespace: String($hideWhitespaceChanges)
|
||||
});
|
||||
if (file.status === 'untracked') params.set('untracked', 'true');
|
||||
|
||||
@@ -83,7 +91,7 @@
|
||||
diffFiles = [];
|
||||
}
|
||||
|
||||
const counts = countDiff(diffFiles);
|
||||
const counts = countDiffStats(diffFiles);
|
||||
const key = fileKey(file);
|
||||
return {
|
||||
key,
|
||||
@@ -120,20 +128,6 @@
|
||||
return `${file.staged ? 'staged' : 'unstaged'}:${file.status}:${file.path}`;
|
||||
}
|
||||
|
||||
function countDiff(files: DiffFile[]): { additions: number; deletions: number } {
|
||||
let additions = 0;
|
||||
let deletions = 0;
|
||||
for (const file of files) {
|
||||
for (const hunk of file.hunks) {
|
||||
for (const line of hunk.lines) {
|
||||
if (line.type === 'added') additions += 1;
|
||||
if (line.type === 'removed') deletions += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return { additions, deletions };
|
||||
}
|
||||
|
||||
function toggleFile(key: string) {
|
||||
reviewFiles = reviewFiles.map((file) =>
|
||||
file.key === key ? { ...file, expanded: !file.expanded } : file
|
||||
@@ -156,103 +150,6 @@
|
||||
if (slash < 0) return { dir: '', name: path };
|
||||
return { dir: path.slice(0, slash + 1), name: path.slice(slash + 1) };
|
||||
}
|
||||
|
||||
function statusMeta(status: string): { char: string; label: string; className: string } {
|
||||
switch (status) {
|
||||
case 'added':
|
||||
return { char: 'A', label: 'Added', className: 'text-green-600 dark:text-green-400' };
|
||||
case 'untracked':
|
||||
return { char: 'U', label: 'Untracked', className: 'text-green-600 dark:text-green-400' };
|
||||
case 'modified':
|
||||
return { char: 'M', label: 'Modified', className: 'text-amber-500 dark:text-amber-400' };
|
||||
case 'deleted':
|
||||
return { char: 'D', label: 'Deleted', className: 'text-red-500 dark:text-red-400' };
|
||||
case 'renamed':
|
||||
return { char: 'R', label: 'Renamed', className: 'text-blue-500 dark:text-blue-400' };
|
||||
case 'copied':
|
||||
return { char: 'C', label: 'Copied', className: 'text-blue-500 dark:text-blue-400' };
|
||||
case 'conflict':
|
||||
return { char: '!', label: 'Conflict', className: 'text-orange-500 dark:text-orange-400' };
|
||||
default:
|
||||
return { char: '?', label: status, className: 'text-gray-400 dark:text-gray-500' };
|
||||
}
|
||||
}
|
||||
|
||||
function hunkStart(header: string): { oldStart: number; newStart: number } {
|
||||
const match = header.match(/^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@/);
|
||||
return {
|
||||
oldStart: match ? Number(match[1]) : 0,
|
||||
newStart: match ? Number(match[2]) : 0
|
||||
};
|
||||
}
|
||||
|
||||
function numberedLines(hunk: DiffHunk): NumberedLine[] {
|
||||
let { oldStart, newStart } = hunkStart(hunk.header);
|
||||
|
||||
return hunk.lines.map((line) => {
|
||||
if (line.type === 'added') {
|
||||
return { ...line, oldNumber: null, newNumber: newStart++ };
|
||||
}
|
||||
if (line.type === 'removed') {
|
||||
return { ...line, oldNumber: oldStart++, newNumber: null };
|
||||
}
|
||||
return { ...line, oldNumber: oldStart++, newNumber: newStart++ };
|
||||
});
|
||||
}
|
||||
|
||||
function blockClass(type: DiffLine['type']): string {
|
||||
switch (type) {
|
||||
case 'added':
|
||||
return 'bg-green-100 border-l-[0.1875rem] border-l-green-500 dark:bg-green-500/15 dark:border-l-green-400';
|
||||
case 'removed':
|
||||
return 'bg-red-100 diff-gutter-removed dark:bg-red-500/15';
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
function textClass(type: DiffLine['type']): string {
|
||||
switch (type) {
|
||||
case 'added':
|
||||
return 'text-green-900 dark:text-green-300';
|
||||
case 'removed':
|
||||
return 'text-red-900 dark:text-red-300';
|
||||
default:
|
||||
return 'text-gray-600 dark:text-gray-400';
|
||||
}
|
||||
}
|
||||
|
||||
function prefixClass(type: DiffLine['type']): string {
|
||||
switch (type) {
|
||||
case 'added':
|
||||
return 'text-green-600 dark:text-green-400';
|
||||
case 'removed':
|
||||
return 'text-red-500 dark:text-red-400';
|
||||
default:
|
||||
return 'text-gray-400 dark:text-gray-600';
|
||||
}
|
||||
}
|
||||
|
||||
function linePrefix(type: DiffLine['type']): string {
|
||||
if (type === 'added') return '+';
|
||||
if (type === 'removed') return '-';
|
||||
return ' ';
|
||||
}
|
||||
|
||||
type LineGroup = { type: DiffLine['type']; lines: NumberedLine[] };
|
||||
|
||||
function groupLines(lines: NumberedLine[]): LineGroup[] {
|
||||
const groups: LineGroup[] = [];
|
||||
for (const line of lines) {
|
||||
const last = groups[groups.length - 1];
|
||||
if (last && last.type === line.type) {
|
||||
last.lines.push(line);
|
||||
} else {
|
||||
groups.push({ type: line.type, lines: [line] });
|
||||
}
|
||||
}
|
||||
return groups;
|
||||
}
|
||||
</script>
|
||||
|
||||
<div
|
||||
@@ -304,9 +201,25 @@
|
||||
<span class="ml-1 font-mono text-[0.625rem] text-gray-400 dark:text-gray-600"
|
||||
>{$t('git.changedCount', { count: totalChanges })}</span
|
||||
>
|
||||
<span class="ml-2 font-mono text-[0.625rem] text-green-600 dark:text-green-400"
|
||||
>+{totalAdditions}</span
|
||||
>
|
||||
<span class="font-mono text-[0.625rem] text-red-500 dark:text-red-400"
|
||||
>-{totalDeletions}</span
|
||||
>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<button
|
||||
bind:this={diffSettingsButtonEl}
|
||||
class="flex h-6 w-6 items-center justify-center rounded-md text-gray-400 transition-colors hover:bg-gray-100 hover:text-gray-600 dark:hover:bg-white/6 dark:hover:text-gray-300"
|
||||
onclick={() => (showDiffSettings = true)}
|
||||
aria-label="Diff settings"
|
||||
use:tooltip={'Diff settings'}
|
||||
>
|
||||
<Icon name="settings" size={13} />
|
||||
</button>
|
||||
|
||||
<button
|
||||
class="flex h-6 w-6 items-center justify-center rounded-md text-gray-400 transition-colors hover:bg-gray-100 hover:text-gray-600 dark:hover:bg-white/6 dark:hover:text-gray-300"
|
||||
onclick={() => refreshReview(false)}
|
||||
@@ -318,6 +231,10 @@
|
||||
</button>
|
||||
</header>
|
||||
|
||||
{#if showDiffSettings && diffSettingsButtonEl}
|
||||
<DiffSettingsMenu anchor={diffSettingsButtonEl} onclose={() => (showDiffSettings = false)} />
|
||||
{/if}
|
||||
|
||||
{#if totalChanges > 0}
|
||||
<div
|
||||
class="flex h-8 shrink-0 items-center gap-2 border-b border-gray-200 px-3 dark:border-white/6"
|
||||
@@ -335,6 +252,12 @@
|
||||
<span class="ml-auto text-[0.6875rem] text-gray-400 dark:text-gray-600"
|
||||
>{$t('git.change', { count: totalChanges })}</span
|
||||
>
|
||||
<span class="ml-2 font-mono text-[0.6875rem] text-green-600 dark:text-green-400"
|
||||
>+{totalAdditions}</span
|
||||
>
|
||||
<span class="font-mono text-[0.6875rem] text-red-500 dark:text-red-400"
|
||||
>-{totalDeletions}</span
|
||||
>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
@@ -360,7 +283,6 @@
|
||||
<div class="p-1">
|
||||
{#each reviewFiles as file (file.key)}
|
||||
{@const parts = pathParts(file.path)}
|
||||
{@const meta = statusMeta(file.status)}
|
||||
<section class="overflow-hidden rounded-lg">
|
||||
<button
|
||||
class="flex h-8 w-full min-w-0 items-center gap-1.5 rounded-lg px-2 text-left transition-colors hover:bg-gray-100 dark:hover:bg-white/4"
|
||||
@@ -373,10 +295,6 @@
|
||||
? 'rotate-90'
|
||||
: ''}"
|
||||
/>
|
||||
<span
|
||||
class="w-4 shrink-0 text-center font-mono text-[0.6875rem] font-bold {meta.className}"
|
||||
title={meta.label}>{meta.char}</span
|
||||
>
|
||||
<Icon name="git-diff" size={13} class="shrink-0 text-gray-400 dark:text-gray-600" />
|
||||
<div class="flex min-w-0 flex-1 items-baseline gap-2">
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
@@ -394,18 +312,14 @@
|
||||
>
|
||||
{/if}
|
||||
</div>
|
||||
{#if file.additions > 0}
|
||||
<span
|
||||
class="shrink-0 font-mono text-[0.6875rem] font-medium text-green-600 dark:text-green-400"
|
||||
>+{file.additions}</span
|
||||
>
|
||||
{/if}
|
||||
{#if file.deletions > 0}
|
||||
<span
|
||||
class="shrink-0 font-mono text-[0.6875rem] font-medium text-red-500 dark:text-red-400"
|
||||
>-{file.deletions}</span
|
||||
>
|
||||
{/if}
|
||||
<span
|
||||
class="shrink-0 font-mono text-[0.6875rem] font-medium text-green-600 dark:text-green-400"
|
||||
>+{file.additions}</span
|
||||
>
|
||||
<span
|
||||
class="shrink-0 font-mono text-[0.6875rem] font-medium text-red-500 dark:text-red-400"
|
||||
>-{file.deletions}</span
|
||||
>
|
||||
|
||||
<span
|
||||
class="shrink-0 rounded px-1.5 py-0.5 text-[0.625rem] font-medium text-rose-500 bg-rose-50 dark:bg-rose-500/10 dark:text-rose-300"
|
||||
@@ -418,7 +332,7 @@
|
||||
<div
|
||||
class="mb-1 overflow-x-auto border-y border-gray-100 bg-white font-mono text-[0.6875rem] leading-[1.125rem] dark:border-white/4 dark:bg-black"
|
||||
>
|
||||
<div class="diff-content">
|
||||
<div class="diff-content" class:diff-content-split={$diffDisplayMode === 'split'}>
|
||||
{#if file.diffFiles.some((diffFile) => diffFile.hunks.length > 0)}
|
||||
{#each file.diffFiles as diffFile}
|
||||
{#if file.diffFiles.length > 1}
|
||||
@@ -428,39 +342,7 @@
|
||||
{diffFile.path}
|
||||
</div>
|
||||
{/if}
|
||||
{#each diffFile.hunks as hunk}
|
||||
<div
|
||||
class="grid w-full grid-cols-[2.75rem_2.75rem_1.25rem_auto] border-b border-gray-100 bg-gray-50 text-gray-400 dark:border-white/4 dark:bg-white/3 dark:text-gray-600"
|
||||
>
|
||||
<span></span>
|
||||
<span></span>
|
||||
<span></span>
|
||||
<code class="whitespace-pre px-2 py-0.5">{hunk.header}</code>
|
||||
</div>
|
||||
{#each groupLines(numberedLines(hunk)) as group}
|
||||
<div class="w-full {blockClass(group.type)}">
|
||||
{#each group.lines as line}
|
||||
<div class="grid w-full grid-cols-[2.75rem_2.75rem_1.25rem_auto]">
|
||||
<span
|
||||
class="select-none border-r border-black/5 px-2 text-right text-gray-400 dark:border-white/4 dark:text-gray-600"
|
||||
>{line.oldNumber ?? ''}</span
|
||||
>
|
||||
<span
|
||||
class="select-none border-r border-black/5 px-2 text-right text-gray-400 dark:border-white/4 dark:text-gray-600"
|
||||
>{line.newNumber ?? ''}</span
|
||||
>
|
||||
<span
|
||||
class="select-none px-1 text-center {prefixClass(line.type)}"
|
||||
>{linePrefix(line.type)}</span
|
||||
>
|
||||
<code class="whitespace-pre px-2 {textClass(line.type)}"
|
||||
>{line.content || ' '}</code
|
||||
>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{/each}
|
||||
{/each}
|
||||
<DiffHunkList hunks={diffFile.hunks} path={diffFile.path} showNumbers />
|
||||
{/each}
|
||||
{:else}
|
||||
<div
|
||||
@@ -486,15 +368,7 @@
|
||||
min-width: 100%;
|
||||
}
|
||||
|
||||
.diff-gutter-removed {
|
||||
border-left: 0.1875rem solid transparent;
|
||||
border-image: repeating-linear-gradient(
|
||||
-45deg,
|
||||
#ef4444 0,
|
||||
#ef4444 1px,
|
||||
transparent 1px,
|
||||
transparent 0.1875rem
|
||||
)
|
||||
3;
|
||||
.diff-content-split {
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
@@ -136,6 +136,249 @@
|
||||
<path d="M13.5 6L10 18.5" />
|
||||
<path d="M6.5 8.5L3 12L6.5 15.5" />
|
||||
<path d="M17.5 8.5L21 12L17.5 15.5" />
|
||||
{:else if name === 'python'}
|
||||
<path
|
||||
d="M8 10H16C17.1046 10 18 9.10457 18 8V5.5C18 4.11929 16.8807 3 15.5 3H10C8.89543 3 8 3.89543 8 5V10Z"
|
||||
/>
|
||||
<path
|
||||
d="M16 14H8C6.89543 14 6 14.8954 6 16V18.5C6 19.8807 7.11929 21 8.5 21H14C15.1046 21 16 20.1046 16 19V14Z"
|
||||
/>
|
||||
<path d="M8 7H6.5C5.11929 7 4 8.11929 4 9.5V12C4 13.1046 4.89543 14 6 14H8" />
|
||||
<path d="M16 10H18C19.1046 10 20 10.8954 20 12V14.5C20 15.8807 18.8807 17 17.5 17H16" />
|
||||
<circle cx="11" cy="6.5" r="0.8" fill="currentColor" stroke="none" />
|
||||
<circle cx="13" cy="17.5" r="0.8" fill="currentColor" stroke="none" />
|
||||
{:else if name === 'javascript-logo'}
|
||||
<rect x="4" y="4" width="16" height="16" rx="2" />
|
||||
<text
|
||||
x="12"
|
||||
y="15"
|
||||
text-anchor="middle"
|
||||
font-size="7"
|
||||
font-weight="700"
|
||||
fill="currentColor"
|
||||
stroke="none">JS</text
|
||||
>
|
||||
{:else if name === 'typescript-logo'}
|
||||
<rect x="4" y="4" width="16" height="16" rx="2" />
|
||||
<text
|
||||
x="12"
|
||||
y="15"
|
||||
text-anchor="middle"
|
||||
font-size="7"
|
||||
font-weight="700"
|
||||
fill="currentColor"
|
||||
stroke="none">TS</text
|
||||
>
|
||||
{:else if name === 'react'}
|
||||
<ellipse cx="12" cy="12" rx="9" ry="3.5" />
|
||||
<ellipse cx="12" cy="12" rx="9" ry="3.5" transform="rotate(60 12 12)" />
|
||||
<ellipse cx="12" cy="12" rx="9" ry="3.5" transform="rotate(120 12 12)" />
|
||||
<circle cx="12" cy="12" r="1.5" fill="currentColor" stroke="none" />
|
||||
{:else if name === 'rust'}
|
||||
<circle cx="12" cy="12" r="6" />
|
||||
<path
|
||||
d="M12 3V5M12 19V21M3 12H5M19 12H21M5.6 5.6L7 7M17 17L18.4 18.4M18.4 5.6L17 7M7 17L5.6 18.4"
|
||||
/>
|
||||
<text
|
||||
x="12"
|
||||
y="14.4"
|
||||
text-anchor="middle"
|
||||
font-size="7"
|
||||
font-weight="700"
|
||||
fill="currentColor"
|
||||
stroke="none">R</text
|
||||
>
|
||||
{:else if name === 'go-logo'}
|
||||
<path d="M3 9H10" />
|
||||
<path d="M2 12H9" />
|
||||
<path d="M3 15H10" />
|
||||
<text
|
||||
x="15"
|
||||
y="15"
|
||||
text-anchor="middle"
|
||||
font-size="8"
|
||||
font-weight="700"
|
||||
fill="currentColor"
|
||||
stroke="none">GO</text
|
||||
>
|
||||
{:else if name === 'java-logo'}
|
||||
<path d="M9 18H17" />
|
||||
<path d="M8 14H18L17 18C16.6667 19.3333 15.5 20 12.5 20C9.5 20 8.33333 19.3333 8 18L7 14H8Z" />
|
||||
<path d="M11 11C9 9 13 8 11 6" />
|
||||
<path d="M14 11C12 9 16 8 14 5" />
|
||||
<path d="M9 22H17" />
|
||||
{:else if name === 'c-logo'}
|
||||
<path d="M12 3L20 7.5V16.5L12 21L4 16.5V7.5L12 3Z" />
|
||||
<text
|
||||
x="12"
|
||||
y="15"
|
||||
text-anchor="middle"
|
||||
font-size="8"
|
||||
font-weight="700"
|
||||
fill="currentColor"
|
||||
stroke="none">C</text
|
||||
>
|
||||
{:else if name === 'cpp-logo'}
|
||||
<path d="M12 3L20 7.5V16.5L12 21L4 16.5V7.5L12 3Z" />
|
||||
<text
|
||||
x="10"
|
||||
y="15"
|
||||
text-anchor="middle"
|
||||
font-size="8"
|
||||
font-weight="700"
|
||||
fill="currentColor"
|
||||
stroke="none">C</text
|
||||
>
|
||||
<path d="M14.5 10V14M12.5 12H16.5M19 10V14M17 12H21" />
|
||||
{:else if name === 'c-sharp-logo'}
|
||||
<path d="M12 3L20 7.5V16.5L12 21L4 16.5V7.5L12 3Z" />
|
||||
<text
|
||||
x="12"
|
||||
y="15"
|
||||
text-anchor="middle"
|
||||
font-size="7"
|
||||
font-weight="700"
|
||||
fill="currentColor"
|
||||
stroke="none">C#</text
|
||||
>
|
||||
{:else if name === 'ruby-logo'}
|
||||
<path d="M12 3L20 8L17 18L12 21L7 18L4 8L12 3Z" />
|
||||
<path d="M4 8H20L12 21L4 8Z" />
|
||||
<path d="M8 8L12 3L16 8L12 21L8 8Z" />
|
||||
{:else if name === 'php-logo'}
|
||||
<ellipse cx="12" cy="12" rx="9" ry="5.5" />
|
||||
<text
|
||||
x="12"
|
||||
y="14.2"
|
||||
text-anchor="middle"
|
||||
font-size="6"
|
||||
font-weight="700"
|
||||
fill="currentColor"
|
||||
stroke="none">PHP</text
|
||||
>
|
||||
{:else if name === 'kotlin-logo'}
|
||||
<path d="M5 4H19L5 18V4Z" />
|
||||
<path d="M5 20L12 13L19 20H5Z" />
|
||||
<path d="M5 4V20" />
|
||||
{:else if name === 'svelte-logo'}
|
||||
<path
|
||||
d="M15.5 4.5C13.7 3.4 11.4 3.7 9.9 5.2L6.3 8.8C5 10.1 5 12.2 6.3 13.5C7.2 14.4 8.5 14.7 9.7 14.3"
|
||||
/>
|
||||
<path
|
||||
d="M8.5 19.5C10.3 20.6 12.6 20.3 14.1 18.8L17.7 15.2C19 13.9 19 11.8 17.7 10.5C16.8 9.6 15.5 9.3 14.3 9.7"
|
||||
/>
|
||||
<path d="M9 12H15" />
|
||||
{:else if name === 'vue-js'}
|
||||
<path d="M12 20.5L22.5 4H18.5L12 14L5.5 4H1.5L12 20.5Z" />
|
||||
<path d="M18.5 4H14.5L12 7.5L9.5 4H5.5" />
|
||||
{:else if name === 'apple-swift'}
|
||||
<path
|
||||
d="M20.457 14.5892C20.9032 13.1527 21.9081 7.84019 14.5261 3.10086C14.2661 2.9345 13.9248 2.97821 13.7186 3.20043C13.5111 3.42264 13.5024 3.75778 13.6974 3.99092C13.7274 4.02614 16.4472 7.33991 15.4798 11.1248C13.8074 9.97369 7.1565 4.70249 7.1565 4.70249L11 11L3.8617 6.40006C3.8617 6.40006 8.90765 12.5953 11.9962 14.9255C10.5013 15.4622 7.25274 16.0305 2.963 13.364C2.72052 13.2122 2.40179 13.2413 2.1918 13.438C1.98431 13.6311 1.93931 13.9395 2.08555 14.1812C2.2293 14.4192 5.66784 20 12.9387 20C14.9335 20 16.0997 19.4317 17.0372 18.9764C17.6134 18.6971 18.0683 18.4749 18.5646 18.4749C19.8007 18.4749 20.6119 19.7025 20.6194 19.7134C20.7344 19.8919 20.9357 20 21.1507 20C21.1669 20 21.1844 19.9988 21.2019 19.9976C21.4356 19.9794 21.6381 19.8373 21.7281 19.6272C22.6206 17.5544 21.0832 15.359 20.457 14.5892Z"
|
||||
/>
|
||||
{:else if name === 'markdown-logo'}
|
||||
<rect x="3" y="6" width="18" height="12" rx="1.5" />
|
||||
<path d="M6 15V9L9 12L12 9V15" />
|
||||
<path d="M16 9V15M14 13L16 15L18 13" />
|
||||
{:else if name === 'json-logo'}
|
||||
<path
|
||||
d="M9 6H8C6.89543 6 6 6.89543 6 8V10C6 11.1046 5.10457 12 4 12C5.10457 12 6 12.8954 6 14V16C6 17.1046 6.89543 18 8 18H9"
|
||||
/>
|
||||
<path
|
||||
d="M15 6H16C17.1046 6 18 6.89543 18 8V10C18 11.1046 18.8954 12 20 12C18.8954 12 18 12.8954 18 14V16C18 17.1046 17.1046 18 16 18H15"
|
||||
/>
|
||||
<path d="M11 9L13 15" />
|
||||
{:else if name === 'yaml-logo'}
|
||||
<path d="M5 5L9 12V19" />
|
||||
<path d="M13 5L9 12" />
|
||||
<path d="M14 9H20" />
|
||||
<path d="M14 13H19" />
|
||||
<path d="M14 17H18" />
|
||||
{:else if name === 'xml-logo'}
|
||||
<path d="M8 8L4 12L8 16" />
|
||||
<path d="M16 8L20 12L16 16" />
|
||||
<path d="M13.5 6L10.5 18" />
|
||||
{:else if name === 'shell-logo'}
|
||||
<path
|
||||
d="M4 5.6C4 5.26863 4.26863 5 4.6 5H19.4C19.7314 5 20 5.26863 20 5.6V18.4C20 18.7314 19.7314 19 19.4 19H4.6C4.26863 19 4 18.7314 4 18.4V5.6Z"
|
||||
/>
|
||||
<path d="M7 9L10 12L7 15" />
|
||||
<path d="M12 15H17" />
|
||||
{:else if name === 'html5'}
|
||||
<path d="M4 3L5.77778 20.0899L12 22L18.2222 20.0899L20 3H4Z" />
|
||||
<path d="M17 7H7.5L8 11.5H16L15.5 17L12 18L8.5 17L8.25 14.5" />
|
||||
{:else if name === 'css3'}
|
||||
<path d="M4 3L5.77778 20.0899L12 22L18.2222 20.0899L20 3H4Z" />
|
||||
<path d="M7 7H16.5L15.5 17L12 18L8.5 17L8.25 14.5" />
|
||||
<path d="M16 11.5H7.5" />
|
||||
{:else if name === 'svg-format'}
|
||||
<path
|
||||
d="M4.5 15H6.5C7.32843 15 8 14.3284 8 13.5C8 12.6716 7.32843 12 6.5 12H6C5.17157 12 4.5 11.3284 4.5 10.5C4.5 9.67157 5.17157 9 6 9H7.5"
|
||||
/>
|
||||
<path d="M10.5 9L12 15L13.5 9" />
|
||||
<path d="M19.5 9H16.5V15L19.5 15V12.6" />
|
||||
<path d="M4 6V3.6C4 3.26863 4.26863 3 4.6 3H19.4C19.7314 3 20 3.26863 20 3.6V6" />
|
||||
<path d="M4 18V20.4C4 20.7314 4.26863 21 4.6 21H19.4C19.7314 21 20 20.7314 20 20.4V18" />
|
||||
{:else if name === 'database-script'}
|
||||
<path d="M22 14V6C22 4.34315 20.6569 3 19 3H9C7.34315 3 6 4.34315 6 6V13" />
|
||||
<path
|
||||
d="M12 21H6C3.79086 21 2 19.2091 2 17C2 14.7909 3.79086 13 6 13H18C15.7909 13 14 14.7909 14 17C14 19.2091 15.7909 21 18 21C20.2091 21 22 19.2091 22 17V14"
|
||||
/>
|
||||
{:else if name === 'csv-logo'}
|
||||
<path
|
||||
d="M4 5.6C4 5.26863 4.26863 5 4.6 5H19.4C19.7314 5 20 5.26863 20 5.6V18.4C20 18.7314 19.7314 19 19.4 19H4.6C4.26863 19 4 18.7314 4 18.4V5.6Z"
|
||||
/>
|
||||
<path d="M4 10H20M4 14H20M10 5V19M15 5V19" />
|
||||
<text
|
||||
x="12"
|
||||
y="13.5"
|
||||
text-anchor="middle"
|
||||
font-size="5"
|
||||
font-weight="700"
|
||||
fill="currentColor"
|
||||
stroke="none">CSV</text
|
||||
>
|
||||
{:else if name === 'pdf-logo'}
|
||||
<path
|
||||
d="M4 21.4V2.6C4 2.26863 4.26863 2 4.6 2H16.2515C16.4106 2 16.5632 2.06321 16.6757 2.17574L19.8243 5.32426C19.9368 5.43679 20 5.5894 20 5.74853V21.4C20 21.7314 19.7314 22 19.4 22H4.6C4.26863 22 4 21.7314 4 21.4Z"
|
||||
/>
|
||||
<path d="M16 2V5.4C16 5.73137 16.2686 6 16.6 6H20" />
|
||||
<text
|
||||
x="12"
|
||||
y="15.2"
|
||||
text-anchor="middle"
|
||||
font-size="5.5"
|
||||
font-weight="700"
|
||||
fill="currentColor"
|
||||
stroke="none">PDF</text
|
||||
>
|
||||
{:else if name === 'npm'}
|
||||
<path d="M1 8L23 8V15L11 15V17L7.5 17V15L1 15V8Z" />
|
||||
<path d="M7.5 8L7.5 15" />
|
||||
<path d="M13.5 8V15" />
|
||||
<path d="M18 11V15" />
|
||||
<path d="M5 11V15" />
|
||||
<path d="M11 11V12" />
|
||||
<path d="M20.5 11V15" />
|
||||
{:else if name === 'archive'}
|
||||
<path d="M7 6L17 6" />
|
||||
<path d="M7 9L17 9" />
|
||||
<path d="M9 17H15" />
|
||||
<path
|
||||
d="M3 12H2.6C2.26863 12 2 12.2686 2 12.6V21.4C2 21.7314 2.26863 22 2.6 22H21.4C21.7314 22 22 21.7314 22 21.4V12.6C22 12.2686 21.7314 12 21.4 12H21M3 12V2.6C3 2.26863 3.26863 2 3.6 2H20.4C20.7314 2 21 2.26863 21 2.6V12M3 12H21"
|
||||
/>
|
||||
{:else if name === 'package'}
|
||||
<path
|
||||
d="M20 5.99999L20 18C20 19.1046 19.1046 20 18 20H6C4.89543 20 4 19.1046 4 18V6C4 4.89543 4.89543 4 6 4H18C19.1045 4 19.9999 4.89543 20 5.99999Z"
|
||||
/>
|
||||
<path d="M12 9V4" />
|
||||
{:else if name === 'package-lock'}
|
||||
<path
|
||||
d="M14 20H6C4.89543 20 4 19.1046 4 18V6C4 4.89543 4.89543 4 6 4H18C19.1045 4 19.9999 4.89543 20 5.99999L20 12"
|
||||
/>
|
||||
<path d="M12 9V4" />
|
||||
<path
|
||||
d="M21.1667 18.5H21.4C21.7314 18.5 22 18.7686 22 19.1V21.4C22 21.7314 21.7314 22 21.4 22H17.6C17.2686 22 17 21.7314 17 21.4V19.1C17 18.7686 17.2686 18.5 17.6 18.5H17.8333M21.1667 18.5V16.75C21.1667 16.1667 20.8333 15 19.5 15C18.1667 15 17.8333 16.1667 17.8333 16.75V18.5M21.1667 18.5H17.8333"
|
||||
/>
|
||||
{:else if name === 'list'}
|
||||
<path d="M8 6H20" />
|
||||
<path d="M4 6.01L4.01 5.99889" />
|
||||
@@ -143,6 +386,11 @@
|
||||
<path d="M4 18.01L4.01 17.9989" />
|
||||
<path d="M8 12H20" />
|
||||
<path d="M8 18H20" />
|
||||
{:else if name === 'split-view'}
|
||||
<path
|
||||
d="M4 5.6C4 5.26863 4.26863 5 4.6 5H19.4C19.7314 5 20 5.26863 20 5.6V18.4C20 18.7314 19.7314 19 19.4 19H4.6C4.26863 19 4 18.7314 4 18.4V5.6Z"
|
||||
/>
|
||||
<path d="M12 5V19" />
|
||||
{:else if name === 'chevron-right'}
|
||||
<path d="M9 6L15 12L9 18" />
|
||||
{:else if name === 'arrow-left'}
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
let resultsEl: HTMLDivElement | undefined = $state();
|
||||
|
||||
// Determine active workspace from the URL, not the store.
|
||||
// When on /automations or other non-workspace pages, $currentWorkspace
|
||||
// When on /scheduled or other non-workspace pages, $currentWorkspace
|
||||
// retains the last workspace but we should search across all.
|
||||
const urlWorkspacePath = $derived($page.url.searchParams.get('workspace'));
|
||||
const effectiveWorkspace = $derived(urlWorkspacePath ? $currentWorkspace : null);
|
||||
|
||||
@@ -1,148 +1,18 @@
|
||||
<script lang="ts">
|
||||
import { goto } from '$app/navigation';
|
||||
import { page } from '$app/stores';
|
||||
import {
|
||||
workspaceList,
|
||||
currentWorkspace,
|
||||
removeWorkspace,
|
||||
reorderWorkspaces,
|
||||
sidebarOpen,
|
||||
sidebarWidth,
|
||||
appVersion,
|
||||
showChangelog,
|
||||
showSearch
|
||||
} from '$lib/stores';
|
||||
import Sortable from 'sortablejs';
|
||||
import Icon from './Icon.svelte';
|
||||
import KeyPill from './KeyPill.svelte';
|
||||
import { sidebarOpen, sidebarWidth } from '$lib/stores';
|
||||
import DirectoryPicker from './DirectoryPicker.svelte';
|
||||
import DropdownMenu from './DropdownMenu.svelte';
|
||||
import SidebarFooter from './SidebarFooter.svelte';
|
||||
import SidebarHeader from './SidebarHeader.svelte';
|
||||
import SidebarNav from './SidebarNav.svelte';
|
||||
import SidebarWorkspaceList from './SidebarWorkspaceList.svelte';
|
||||
import SettingsModal from './SettingsModal.svelte';
|
||||
import SystemInfoModal from './SystemInfoModal.svelte';
|
||||
|
||||
import { tooltip } from '$lib/tooltip';
|
||||
import { session, clearSession } from '$lib/session';
|
||||
import { getWelcome } from '$lib/apis/state';
|
||||
import { getChats, type ChatInfo } from '$lib/apis/chat';
|
||||
import ChatItem from './common/ChatItem.svelte';
|
||||
import { chatEnabled } from '$lib/stores/chat';
|
||||
import { socketStore } from '$lib/stores/socket.svelte';
|
||||
import { t } from '$lib/i18n';
|
||||
import { keybindings, formatChord } from '$lib/stores/keybindings';
|
||||
|
||||
import { onMount, onDestroy } from 'svelte';
|
||||
|
||||
let showPicker = $state(false);
|
||||
let showMenu = $state(false);
|
||||
let showSettings = $state(false);
|
||||
let showSystemInfo = $state(false);
|
||||
let settingsTab = $state<string>('general');
|
||||
let wsMenuPath = $state<string | null>(null);
|
||||
let wsMenuAnchor = $state<HTMLElement | null>(null);
|
||||
|
||||
let menuButtonEl: HTMLButtonElement | undefined = $state();
|
||||
let wsListEl: HTMLDivElement | undefined = $state();
|
||||
let sortable: Sortable | null = null;
|
||||
let unbindSocketListener: (() => void) | null = null;
|
||||
|
||||
// ── Per-workspace chat history ──────────────────────────────
|
||||
let expandedWorkspaces = $state<Set<string>>(new Set());
|
||||
let wsChatsCache = $state<Map<string, ChatInfo[]>>(new Map());
|
||||
let wsChatsLoading = $state<Set<string>>(new Set());
|
||||
|
||||
// Keybinding shortcut display for search
|
||||
let searchShortcut = $derived(formatChord($keybindings.quickOpen));
|
||||
|
||||
function toggleWorkspaceExpand(path: string) {
|
||||
const next = new Set(expandedWorkspaces);
|
||||
if (next.has(path)) {
|
||||
next.delete(path);
|
||||
} else {
|
||||
next.add(path);
|
||||
// Lazy-fetch chats if not cached
|
||||
if (!wsChatsCache.has(path)) {
|
||||
fetchWorkspaceChats(path);
|
||||
}
|
||||
}
|
||||
expandedWorkspaces = next;
|
||||
}
|
||||
|
||||
async function fetchWorkspaceChats(path: string) {
|
||||
if (wsChatsLoading.has(path)) return;
|
||||
wsChatsLoading = new Set([...wsChatsLoading, path]);
|
||||
try {
|
||||
const data = await getChats(path, 5, 0, 'updated_at', 'desc');
|
||||
wsChatsCache = new Map([...wsChatsCache, [path, data.chats || []]]);
|
||||
} catch {
|
||||
wsChatsCache = new Map([...wsChatsCache, [path, []]]);
|
||||
} finally {
|
||||
const next = new Set(wsChatsLoading);
|
||||
next.delete(path);
|
||||
wsChatsLoading = next;
|
||||
}
|
||||
}
|
||||
|
||||
function relativeTime(ts: number): string {
|
||||
// ts is in milliseconds
|
||||
const now = Date.now();
|
||||
const diffMs = now - ts;
|
||||
const diffSec = Math.floor(diffMs / 1000);
|
||||
if (diffSec < 60) return 'now';
|
||||
const diffMin = Math.floor(diffSec / 60);
|
||||
if (diffMin < 60) return `${diffMin}m`;
|
||||
const diffHr = Math.floor(diffMin / 60);
|
||||
if (diffHr < 24) return `${diffHr}h`;
|
||||
const diffDay = Math.floor(diffHr / 24);
|
||||
if (diffDay < 30) return `${diffDay}d`;
|
||||
const diffMonth = Math.floor(diffDay / 30);
|
||||
return `${diffMonth}mo`;
|
||||
}
|
||||
|
||||
function handleSidebarChatClick(chatId: string, wsPath: string, title: string) {
|
||||
goto(`/?workspace=${encodeURIComponent(wsPath)}&chatId=${encodeURIComponent(chatId)}`);
|
||||
if (typeof window !== 'undefined' && window.innerWidth < 768) {
|
||||
sidebarOpen.set(false);
|
||||
}
|
||||
}
|
||||
|
||||
function handleShowMoreChats(wsPath: string) {
|
||||
goto(`/?workspace=${encodeURIComponent(wsPath)}&chatId`);
|
||||
if (typeof window !== 'undefined' && window.innerWidth < 768) {
|
||||
sidebarOpen.set(false);
|
||||
}
|
||||
}
|
||||
|
||||
function handleNewChat(wsPath: string) {
|
||||
goto(`/?workspace=${encodeURIComponent(wsPath)}&chatId`);
|
||||
if (typeof window !== 'undefined' && window.innerWidth < 768) {
|
||||
sidebarOpen.set(false);
|
||||
}
|
||||
}
|
||||
|
||||
// Socket listener for chat events — invalidate cache when chats update
|
||||
const seenChatIds = new Set<string>();
|
||||
|
||||
function handleChatEvent(data: {
|
||||
chat_id: string;
|
||||
done?: boolean;
|
||||
title?: string;
|
||||
delta?: string;
|
||||
workspace?: string;
|
||||
}) {
|
||||
// Re-fetch on done, title update, or first event of a new chat
|
||||
const isNew = !seenChatIds.has(data.chat_id);
|
||||
seenChatIds.add(data.chat_id);
|
||||
|
||||
if (!data.done && !data.title && !isNew) return;
|
||||
|
||||
// Invalidate cache for ALL workspaces so re-expanding shows fresh data
|
||||
wsChatsCache = new Map();
|
||||
|
||||
// Re-fetch immediately for any currently expanded workspaces
|
||||
for (const path of expandedWorkspaces) {
|
||||
fetchWorkspaceChats(path);
|
||||
}
|
||||
}
|
||||
|
||||
const MIN_WIDTH = 160;
|
||||
const MAX_WIDTH = 400;
|
||||
@@ -176,89 +46,18 @@
|
||||
document.body.style.userSelect = 'none';
|
||||
}
|
||||
|
||||
// Current workspace path from URL
|
||||
const currentPath = $derived($page.url.searchParams.get('workspace'));
|
||||
|
||||
function isTouchDevice(): boolean {
|
||||
return (
|
||||
typeof window !== 'undefined' && ('ontouchstart' in window || navigator.maxTouchPoints > 0)
|
||||
);
|
||||
}
|
||||
|
||||
function handleWorkspaceClick(e: MouseEvent, path: string) {
|
||||
// Let Cmd/Ctrl+click open in new tab naturally (it's an <a>)
|
||||
if (e.metaKey || e.ctrlKey) return;
|
||||
e.preventDefault();
|
||||
goto(`/?workspace=${encodeURIComponent(path)}`);
|
||||
if (typeof window !== 'undefined' && window.innerWidth < 768) {
|
||||
sidebarOpen.set(false);
|
||||
}
|
||||
}
|
||||
|
||||
function openWsMenu(e: MouseEvent, path: string) {
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
wsMenuAnchor = e.currentTarget as HTMLElement;
|
||||
wsMenuPath = path;
|
||||
}
|
||||
|
||||
function closeWsMenu() {
|
||||
wsMenuPath = null;
|
||||
wsMenuAnchor = null;
|
||||
}
|
||||
|
||||
function closeSidebar() {
|
||||
sidebarOpen.set(false);
|
||||
}
|
||||
|
||||
function openSettings() {
|
||||
showMenu = false;
|
||||
function openSettings(tab = 'general') {
|
||||
settingsTab = tab;
|
||||
showSettings = true;
|
||||
}
|
||||
|
||||
function openSystemInfo() {
|
||||
showMenu = false;
|
||||
showSystemInfo = true;
|
||||
}
|
||||
|
||||
function logout() {
|
||||
clearSession();
|
||||
}
|
||||
|
||||
async function handleRemoveWorkspace(path: string) {
|
||||
closeWsMenu();
|
||||
await removeWorkspace(path);
|
||||
// If we removed the workspace we're currently viewing, go home
|
||||
if (currentPath === path) {
|
||||
goto('/');
|
||||
}
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
// Enable drag-reorder on non-touch devices
|
||||
if (wsListEl && !isTouchDevice()) {
|
||||
sortable = Sortable.create(wsListEl, {
|
||||
animation: 150,
|
||||
ghostClass: 'opacity-30',
|
||||
dragClass: 'cursor-grabbing',
|
||||
direction: 'vertical',
|
||||
onEnd: (evt) => {
|
||||
if (evt.oldIndex != null && evt.newIndex != null && evt.oldIndex !== evt.newIndex) {
|
||||
reorderWorkspaces(evt.oldIndex, evt.newIndex);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Bind socket listener for chat cache invalidation
|
||||
unbindSocketListener = socketStore.on('events:chat', handleChatEvent);
|
||||
});
|
||||
|
||||
onDestroy(() => {
|
||||
sortable?.destroy();
|
||||
unbindSocketListener?.();
|
||||
unbindSocketListener = null;
|
||||
});
|
||||
</script>
|
||||
|
||||
{#if $sidebarOpen}
|
||||
@@ -278,269 +77,17 @@
|
||||
onpointerdown={startResize}
|
||||
ondblclick={() => sidebarWidth.set(220)}
|
||||
></div>
|
||||
<!-- Logo header with collapse button -->
|
||||
<div
|
||||
class="flex items-center justify-between h-9 pl-3.5 pr-1.5 shrink-0 border-b border-gray-200 dark:border-white/6"
|
||||
style="border-color: var(--app-border);"
|
||||
>
|
||||
<a
|
||||
href="/"
|
||||
class="flex items-center gap-1.5 text-xs font-semibold tracking-tight text-gray-900 dark:text-white"
|
||||
onclick={(e) => {
|
||||
e.preventDefault();
|
||||
goto('/');
|
||||
if (typeof window !== 'undefined' && window.innerWidth < 768) sidebarOpen.set(false);
|
||||
}}><img src="/favicon.png" alt="Computer logo" class="w-4 h-4" />Computer</a
|
||||
>
|
||||
<button
|
||||
class="flex items-center justify-center w-7 h-7 rounded-lg text-gray-300 hover:text-gray-500 dark:text-gray-600 dark:hover:text-gray-400 transition-colors duration-100"
|
||||
onclick={() => sidebarOpen.set(false)}
|
||||
aria-label={$t('sidebar.collapse')}
|
||||
use:tooltip={$t('sidebar.collapse')}
|
||||
>
|
||||
<Icon name="sidebar-expand" size={14} />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- Search -->
|
||||
<div class="px-1.5 mt-1 shrink-0">
|
||||
<button
|
||||
class="group flex items-center gap-1.5 w-full h-7 px-2 rounded-lg text-xs text-gray-500 hover:text-gray-700 dark:hover:text-gray-300 transition-colors duration-100"
|
||||
onclick={() => showSearch.set(true)}
|
||||
>
|
||||
<Icon name="search" size={14} />
|
||||
<span class="flex-1 text-left overflow-hidden text-ellipsis whitespace-nowrap"
|
||||
>{$t('search.search')}</span
|
||||
>
|
||||
<KeyPill
|
||||
text={searchShortcut}
|
||||
class="ml-auto shrink-0 opacity-0 group-hover:opacity-100 transition-opacity duration-100"
|
||||
/>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- Automations (only when chat/LLM backend is available) -->
|
||||
{#if $chatEnabled}
|
||||
<div class="px-1.5 shrink-0">
|
||||
<a
|
||||
href="/automations"
|
||||
class="flex items-center gap-1.5 w-full h-7 px-2 rounded-lg text-xs text-gray-500 hover:text-gray-700 dark:hover:text-gray-300 transition-colors duration-100 no-underline"
|
||||
onclick={(e) => {
|
||||
e.preventDefault();
|
||||
goto('/automations');
|
||||
if (typeof window !== 'undefined' && window.innerWidth < 768) sidebarOpen.set(false);
|
||||
}}
|
||||
>
|
||||
<Icon name="clock" size={14} />
|
||||
<span class="flex-1 text-left overflow-hidden text-ellipsis whitespace-nowrap"
|
||||
>{$t('automations.title')}</span
|
||||
>
|
||||
</a>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<!-- Workspace section header -->
|
||||
<div class="flex items-center justify-between h-8 pl-3.5 pr-1.5 shrink-0">
|
||||
<span class="text-xs text-gray-400 dark:text-gray-500">{$t('sidebar.workspaces')}</span>
|
||||
<button
|
||||
class="flex items-center justify-center w-7 h-7 rounded-lg text-gray-300 hover:text-gray-500 dark:text-gray-600 dark:hover:text-gray-400 transition-colors duration-100"
|
||||
onclick={() => (showPicker = true)}
|
||||
aria-label={$t('sidebar.addWorkspace')}
|
||||
use:tooltip={$t('sidebar.addWorkspace')}
|
||||
>
|
||||
<Icon name="plus" size={14} />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- Workspace list -->
|
||||
<div bind:this={wsListEl} class="flex-1 overflow-y-auto px-1.5">
|
||||
{#each $workspaceList as ws (ws.path)}
|
||||
{@const isExpanded = expandedWorkspaces.has(ws.path)}
|
||||
{@const chats = wsChatsCache.get(ws.path)}
|
||||
{@const isLoading = wsChatsLoading.has(ws.path)}
|
||||
<div class="ws-item">
|
||||
<div
|
||||
class="group flex items-center gap-1 w-full h-7 px-2 rounded-lg text-xs font-medium transition-colors duration-100
|
||||
{ws.path === currentPath
|
||||
? 'bg-gray-200/50 text-gray-900 dark:bg-white/8 dark:text-white'
|
||||
: 'text-gray-500 hover:text-gray-700 dark:hover:text-gray-300'}"
|
||||
>
|
||||
<a
|
||||
href="/?workspace={encodeURIComponent(ws.path)}"
|
||||
class="flex items-center gap-1.5 flex-1 min-w-0 no-underline text-inherit"
|
||||
onclick={(e) => handleWorkspaceClick(e, ws.path)}
|
||||
>
|
||||
<!-- Icon: folder by default, chevron on hover (when chat enabled) -->
|
||||
{#if $chatEnabled}
|
||||
<span
|
||||
class="ws-icon-toggle shrink-0"
|
||||
role="button"
|
||||
tabindex="-1"
|
||||
onclick={(e) => {
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
toggleWorkspaceExpand(ws.path);
|
||||
}}
|
||||
aria-label={isExpanded ? $t('sidebar.collapse') : $t('sidebar.addWorkspace')}
|
||||
>
|
||||
<span class="ws-icon-folder"><Icon name="folder" size={14} /></span>
|
||||
<span
|
||||
class="ws-icon-chevron"
|
||||
style="transform: rotate({isExpanded ? '90deg' : '0deg'})"
|
||||
>
|
||||
<Icon name="chevron-right" size={11} />
|
||||
</span>
|
||||
</span>
|
||||
{:else}
|
||||
<Icon name="folder" size={14} />
|
||||
{/if}
|
||||
<span class="flex-1 text-left overflow-hidden text-ellipsis whitespace-nowrap"
|
||||
>{ws.name}</span
|
||||
>
|
||||
</a>
|
||||
<span
|
||||
class="flex items-center justify-center w-4 h-4 shrink-0 text-gray-400 opacity-0 group-hover:opacity-100 hover:text-gray-600 dark:hover:text-gray-300 transition-all duration-75"
|
||||
role="button"
|
||||
tabindex="-1"
|
||||
onclick={(e) => openWsMenu(e, ws.path)}
|
||||
aria-label={$t('sidebar.workspaceOptions')}
|
||||
>
|
||||
<Icon name="three-dots" size={11} />
|
||||
</span>
|
||||
{#if $chatEnabled}
|
||||
<span
|
||||
class="flex items-center justify-center w-4 h-4 shrink-0 text-gray-400 opacity-0 group-hover:opacity-100 hover:text-gray-600 dark:hover:text-gray-300 transition-all duration-75"
|
||||
role="button"
|
||||
tabindex="-1"
|
||||
onclick={() => handleNewChat(ws.path)}
|
||||
aria-label={$t('bar.newChat')}
|
||||
use:tooltip={$t('bar.newChat')}
|
||||
>
|
||||
<Icon name="pencil" size={11} />
|
||||
</span>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<!-- Collapsible chat list -->
|
||||
{#if $chatEnabled && isExpanded}
|
||||
<div class="ws-chats">
|
||||
{#if isLoading && !chats}
|
||||
<div class="ws-chat-loading">
|
||||
<span class="ws-chat-loading-dot"></span>
|
||||
<span class="ws-chat-loading-dot"></span>
|
||||
<span class="ws-chat-loading-dot"></span>
|
||||
</div>
|
||||
{:else if chats && chats.length > 0}
|
||||
{#each chats as chat (chat.id)}
|
||||
<ChatItem
|
||||
{chat}
|
||||
onclick={() => handleSidebarChatClick(chat.id, ws.path, chat.title)}
|
||||
/>
|
||||
{/each}
|
||||
<button class="ws-chat-show-more" onclick={() => handleShowMoreChats(ws.path)}>
|
||||
{$t('sidebar.showMore')}
|
||||
</button>
|
||||
{:else if chats}
|
||||
<!-- No chats yet, show nothing -->
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{/each}
|
||||
|
||||
{#if $workspaceList.length === 0}
|
||||
<div class="flex flex-col items-center justify-center py-12">
|
||||
<p class="text-xs text-gray-400 dark:text-gray-600">{$t('sidebar.noWorkspaces')}</p>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<!-- Settings and profile footer pinned to the bottom -->
|
||||
<div class="relative px-1 pb-0.5 shrink-0">
|
||||
<button
|
||||
bind:this={menuButtonEl}
|
||||
class="flex items-center gap-2 w-full h-8 px-2 rounded-lg text-xs font-medium text-gray-500 hover:text-gray-700 dark:hover:text-gray-300 transition-colors duration-100"
|
||||
onclick={() => (showMenu = !showMenu)}
|
||||
>
|
||||
<img
|
||||
src={$session?.profile_image_url || '/user.png'}
|
||||
alt="Avatar"
|
||||
class="w-5 h-5 rounded-full object-cover shrink-0"
|
||||
/>
|
||||
<span class="truncate"
|
||||
>{$session?.display_name || $session?.username || $t('sidebar.settings')}</span
|
||||
>
|
||||
{#if $appVersion}
|
||||
<button
|
||||
onclick={(e) => {
|
||||
e.stopPropagation();
|
||||
showChangelog.set(true);
|
||||
}}
|
||||
class="ml-auto text-[0.625rem] text-gray-400 dark:text-gray-600 hover:text-gray-500 dark:hover:text-gray-400 font-mono hover:underline cursor-pointer"
|
||||
>
|
||||
v{$appVersion}
|
||||
</button>
|
||||
{/if}
|
||||
</button>
|
||||
</div>
|
||||
<SidebarHeader />
|
||||
<SidebarNav />
|
||||
<SidebarWorkspaceList onaddworkspace={() => (showPicker = true)} />
|
||||
<SidebarFooter onsettings={openSettings} onsysteminfo={openSystemInfo} />
|
||||
</aside>
|
||||
{/if}
|
||||
|
||||
{#if showMenu && menuButtonEl}
|
||||
<DropdownMenu
|
||||
anchor={menuButtonEl}
|
||||
matchWidth
|
||||
items={[
|
||||
...($session
|
||||
? [
|
||||
{
|
||||
label: $session.display_name || $session.username,
|
||||
image: $session.profile_image_url || '/user.png',
|
||||
onclick: () => {
|
||||
settingsTab = 'account';
|
||||
showMenu = false;
|
||||
showSettings = true;
|
||||
}
|
||||
}
|
||||
]
|
||||
: []),
|
||||
...($session ? [{ divider: true, label: '', onclick: () => {} }] : []),
|
||||
{
|
||||
label: $t('sidebar.settings'),
|
||||
icon: 'settings',
|
||||
shortcut: formatChord($keybindings.openSettings),
|
||||
onclick: openSettings
|
||||
},
|
||||
{
|
||||
label: $t('system.infoTitle'),
|
||||
icon: 'info',
|
||||
onclick: openSystemInfo
|
||||
},
|
||||
{ divider: true, label: '', onclick: () => {} },
|
||||
{ label: $t('sidebar.logOut'), icon: 'log-out', onclick: logout }
|
||||
]}
|
||||
onclose={() => (showMenu = false)}
|
||||
/>
|
||||
{/if}
|
||||
|
||||
{#if showPicker}
|
||||
<DirectoryPicker onclose={() => (showPicker = false)} />
|
||||
{/if}
|
||||
|
||||
{#if wsMenuPath && wsMenuAnchor}
|
||||
<DropdownMenu
|
||||
anchor={wsMenuAnchor}
|
||||
items={[
|
||||
{
|
||||
label: $t('sidebar.remove'),
|
||||
icon: 'xmark',
|
||||
onclick: () => handleRemoveWorkspace(wsMenuPath!)
|
||||
}
|
||||
]}
|
||||
onclose={closeWsMenu}
|
||||
/>
|
||||
{/if}
|
||||
|
||||
{#if showSettings}
|
||||
<SettingsModal
|
||||
initialTab={settingsTab}
|
||||
@@ -607,122 +154,4 @@
|
||||
background: rgba(150, 150, 150, 0.12);
|
||||
}
|
||||
}
|
||||
|
||||
/* ── Workspace chat items ────────────────────────────── */
|
||||
|
||||
.ws-item {
|
||||
margin-bottom: 0.125rem;
|
||||
}
|
||||
|
||||
.ws-expand-btn {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* Icon toggle: folder by default, chevron on hover */
|
||||
.ws-icon-toggle {
|
||||
position: relative;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 0.875rem;
|
||||
height: 0.875rem;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.ws-icon-folder {
|
||||
display: flex;
|
||||
transition: opacity 0.1s;
|
||||
}
|
||||
|
||||
.ws-icon-chevron {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
opacity: 0;
|
||||
transition:
|
||||
opacity 0.1s,
|
||||
transform 0.1s;
|
||||
color: #9ca3af;
|
||||
}
|
||||
|
||||
:global(.dark) .ws-icon-chevron {
|
||||
color: #6b7280;
|
||||
}
|
||||
|
||||
/* On icon hover only, swap folder → chevron */
|
||||
.ws-icon-toggle:hover .ws-icon-folder {
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
.ws-icon-toggle:hover .ws-icon-chevron {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.ws-chats {
|
||||
margin-top: 0.125rem;
|
||||
padding-bottom: 0.25rem;
|
||||
}
|
||||
|
||||
.ws-chat-show-more {
|
||||
display: block;
|
||||
width: 100%;
|
||||
padding: 0.125rem 0.5rem;
|
||||
border: none;
|
||||
background: none;
|
||||
cursor: pointer;
|
||||
font-size: 0.6875rem;
|
||||
color: #b0b5be;
|
||||
text-align: left;
|
||||
transition: color 0.1s;
|
||||
}
|
||||
|
||||
.ws-chat-show-more:hover {
|
||||
color: #6b7280;
|
||||
}
|
||||
|
||||
:global(.dark) .ws-chat-show-more {
|
||||
color: #6b7280;
|
||||
}
|
||||
|
||||
:global(.dark) .ws-chat-show-more:hover {
|
||||
color: #9ca3af;
|
||||
}
|
||||
|
||||
.ws-chat-loading {
|
||||
display: flex;
|
||||
gap: 0.25rem;
|
||||
padding: 0.375rem 0.5rem;
|
||||
}
|
||||
|
||||
.ws-chat-loading-dot {
|
||||
width: 0.25rem;
|
||||
height: 0.25rem;
|
||||
border-radius: 50%;
|
||||
background: #9ca3af;
|
||||
animation: dotPulse 1s ease-in-out infinite;
|
||||
}
|
||||
|
||||
:global(.dark) .ws-chat-loading-dot {
|
||||
background: #6b7280;
|
||||
}
|
||||
|
||||
.ws-chat-loading-dot:nth-child(2) {
|
||||
animation-delay: 0.15s;
|
||||
}
|
||||
|
||||
.ws-chat-loading-dot:nth-child(3) {
|
||||
animation-delay: 0.3s;
|
||||
}
|
||||
|
||||
@keyframes dotPulse {
|
||||
0%,
|
||||
100% {
|
||||
opacity: 0.3;
|
||||
}
|
||||
50% {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,87 @@
|
||||
<script lang="ts">
|
||||
import { appVersion, showChangelog } from '$lib/stores';
|
||||
import { session, clearSession } from '$lib/session';
|
||||
import { t } from '$lib/i18n';
|
||||
import { keybindings, formatChord } from '$lib/stores/keybindings';
|
||||
import DropdownMenu from './DropdownMenu.svelte';
|
||||
|
||||
interface Props {
|
||||
onsettings: (tab?: string) => void;
|
||||
onsysteminfo: () => void;
|
||||
}
|
||||
|
||||
let { onsettings, onsysteminfo }: Props = $props();
|
||||
let showMenu = $state(false);
|
||||
let menuButtonEl: HTMLButtonElement | undefined = $state();
|
||||
|
||||
function openSettings(tab?: string) {
|
||||
showMenu = false;
|
||||
onsettings(tab);
|
||||
}
|
||||
|
||||
function openSystemInfo() {
|
||||
showMenu = false;
|
||||
onsysteminfo();
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="relative px-1 pb-0.5 shrink-0">
|
||||
<button
|
||||
bind:this={menuButtonEl}
|
||||
class="flex items-center gap-2 w-full h-8 px-2 rounded-lg text-xs font-medium text-gray-500 hover:text-gray-700 dark:hover:text-gray-300 transition-colors duration-100"
|
||||
onclick={() => (showMenu = !showMenu)}
|
||||
>
|
||||
<img
|
||||
src={$session?.profile_image_url || '/user.png'}
|
||||
alt="Avatar"
|
||||
class="w-5 h-5 rounded-full object-cover shrink-0"
|
||||
/>
|
||||
<span class="truncate"
|
||||
>{$session?.display_name || $session?.username || $t('sidebar.settings')}</span
|
||||
>
|
||||
{#if $appVersion}
|
||||
<button
|
||||
onclick={(e) => {
|
||||
e.stopPropagation();
|
||||
showChangelog.set(true);
|
||||
}}
|
||||
class="ml-auto text-[0.625rem] text-gray-400 dark:text-gray-600 hover:text-gray-500 dark:hover:text-gray-400 font-mono hover:underline cursor-pointer"
|
||||
>
|
||||
v{$appVersion}
|
||||
</button>
|
||||
{/if}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{#if showMenu && menuButtonEl}
|
||||
<DropdownMenu
|
||||
anchor={menuButtonEl}
|
||||
matchWidth
|
||||
items={[
|
||||
...($session
|
||||
? [
|
||||
{
|
||||
label: $session.display_name || $session.username,
|
||||
image: $session.profile_image_url || '/user.png',
|
||||
onclick: () => openSettings('account')
|
||||
}
|
||||
]
|
||||
: []),
|
||||
...($session ? [{ divider: true, label: '', onclick: () => {} }] : []),
|
||||
{
|
||||
label: $t('sidebar.settings'),
|
||||
icon: 'settings',
|
||||
shortcut: formatChord($keybindings.openSettings),
|
||||
onclick: () => openSettings()
|
||||
},
|
||||
{
|
||||
label: $t('system.infoTitle'),
|
||||
icon: 'info',
|
||||
onclick: openSystemInfo
|
||||
},
|
||||
{ divider: true, label: '', onclick: () => {} },
|
||||
{ label: $t('sidebar.logOut'), icon: 'log-out', onclick: clearSession }
|
||||
]}
|
||||
onclose={() => (showMenu = false)}
|
||||
/>
|
||||
{/if}
|
||||
@@ -0,0 +1,32 @@
|
||||
<script lang="ts">
|
||||
import { goto } from '$app/navigation';
|
||||
import { sidebarOpen } from '$lib/stores';
|
||||
import { t } from '$lib/i18n';
|
||||
import { tooltip } from '$lib/tooltip';
|
||||
import Icon from './Icon.svelte';
|
||||
|
||||
function goHome(e: MouseEvent) {
|
||||
e.preventDefault();
|
||||
goto('/');
|
||||
if (typeof window !== 'undefined' && window.innerWidth < 768) sidebarOpen.set(false);
|
||||
}
|
||||
</script>
|
||||
|
||||
<div
|
||||
class="flex items-center justify-between h-9 pl-3.5 pr-1.5 shrink-0 border-b border-gray-200 dark:border-white/6"
|
||||
style="border-color: var(--app-border);"
|
||||
>
|
||||
<a
|
||||
href="/"
|
||||
class="flex items-center gap-1.5 text-xs font-semibold tracking-tight text-gray-900 dark:text-white"
|
||||
onclick={goHome}><img src="/favicon.png" alt="Computer logo" class="w-4 h-4" />Computer</a
|
||||
>
|
||||
<button
|
||||
class="flex items-center justify-center w-7 h-7 rounded-lg text-gray-300 hover:text-gray-500 dark:text-gray-600 dark:hover:text-gray-400 transition-colors duration-100"
|
||||
onclick={() => sidebarOpen.set(false)}
|
||||
aria-label={$t('sidebar.collapse')}
|
||||
use:tooltip={$t('sidebar.collapse')}
|
||||
>
|
||||
<Icon name="sidebar-expand" size={14} />
|
||||
</button>
|
||||
</div>
|
||||
@@ -0,0 +1,48 @@
|
||||
<script lang="ts">
|
||||
import { goto } from '$app/navigation';
|
||||
import { sidebarOpen, showSearch } from '$lib/stores';
|
||||
import { chatEnabled } from '$lib/stores/chat';
|
||||
import { keybindings, formatChord } from '$lib/stores/keybindings';
|
||||
import { t } from '$lib/i18n';
|
||||
import Icon from './Icon.svelte';
|
||||
import KeyPill from './KeyPill.svelte';
|
||||
|
||||
let searchShortcut = $derived(formatChord($keybindings.quickOpen));
|
||||
|
||||
function openAutomations(e: MouseEvent) {
|
||||
e.preventDefault();
|
||||
goto('/scheduled');
|
||||
if (typeof window !== 'undefined' && window.innerWidth < 768) sidebarOpen.set(false);
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="px-1.5 mt-1 shrink-0">
|
||||
<button
|
||||
class="group flex items-center gap-1.5 w-full h-7 px-2 rounded-lg text-xs text-gray-500 hover:text-gray-700 dark:hover:text-gray-300 transition-colors duration-100"
|
||||
onclick={() => showSearch.set(true)}
|
||||
>
|
||||
<Icon name="search" size={14} />
|
||||
<span class="flex-1 text-left overflow-hidden text-ellipsis whitespace-nowrap"
|
||||
>{$t('search.search')}</span
|
||||
>
|
||||
<KeyPill
|
||||
text={searchShortcut}
|
||||
class="ml-auto shrink-0 opacity-0 group-hover:opacity-100 transition-opacity duration-100"
|
||||
/>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{#if $chatEnabled}
|
||||
<div class="px-1.5 shrink-0">
|
||||
<a
|
||||
href="/scheduled"
|
||||
class="flex items-center gap-1.5 w-full h-7 px-2 rounded-lg text-xs text-gray-500 hover:text-gray-700 dark:hover:text-gray-300 transition-colors duration-100 no-underline"
|
||||
onclick={openAutomations}
|
||||
>
|
||||
<Icon name="clock" size={14} />
|
||||
<span class="flex-1 text-left overflow-hidden text-ellipsis whitespace-nowrap"
|
||||
>{$t('automations.title')}</span
|
||||
>
|
||||
</a>
|
||||
</div>
|
||||
{/if}
|
||||
@@ -0,0 +1,426 @@
|
||||
<script lang="ts">
|
||||
import { goto } from '$app/navigation';
|
||||
import { page } from '$app/stores';
|
||||
import { workspaceList, removeWorkspace, reorderWorkspaces, sidebarOpen } from '$lib/stores';
|
||||
import { chatEnabled } from '$lib/stores/chat';
|
||||
import { socketStore } from '$lib/stores/socket.svelte';
|
||||
import { deleteChat as apiDeleteChat, getChats, type ChatInfo } from '$lib/apis/chat';
|
||||
import { t } from '$lib/i18n';
|
||||
import { tooltip } from '$lib/tooltip';
|
||||
import Sortable from 'sortablejs';
|
||||
import { onDestroy, onMount } from 'svelte';
|
||||
import ChatItem from './common/ChatItem.svelte';
|
||||
import DropdownMenu from './DropdownMenu.svelte';
|
||||
import Icon from './Icon.svelte';
|
||||
|
||||
interface Props {
|
||||
onaddworkspace: () => void;
|
||||
}
|
||||
|
||||
let { onaddworkspace }: Props = $props();
|
||||
let wsMenuPath = $state<string | null>(null);
|
||||
let wsMenuAnchor = $state<HTMLElement | null>(null);
|
||||
let chatMenu = $state<{ chatId: string; wsPath: string; anchor: HTMLElement } | null>(null);
|
||||
let wsListEl: HTMLDivElement | undefined = $state();
|
||||
let sortable: Sortable | null = null;
|
||||
let unbindSocketListener: (() => void) | null = null;
|
||||
|
||||
let expandedWorkspaces = $state<Set<string>>(new Set());
|
||||
let wsChatsCache = $state<Map<string, ChatInfo[]>>(new Map());
|
||||
let wsChatsLoading = $state<Set<string>>(new Set());
|
||||
let currentPath = $derived($page.url.searchParams.get('workspace'));
|
||||
|
||||
function toggleWorkspaceExpand(path: string) {
|
||||
const next = new Set(expandedWorkspaces);
|
||||
if (next.has(path)) {
|
||||
next.delete(path);
|
||||
} else {
|
||||
next.add(path);
|
||||
if (!wsChatsCache.has(path)) fetchWorkspaceChats(path);
|
||||
}
|
||||
expandedWorkspaces = next;
|
||||
}
|
||||
|
||||
async function fetchWorkspaceChats(path: string) {
|
||||
if (wsChatsLoading.has(path)) return;
|
||||
wsChatsLoading = new Set([...wsChatsLoading, path]);
|
||||
try {
|
||||
const data = await getChats(path, 5, 0, 'updated_at', 'desc');
|
||||
wsChatsCache = new Map([...wsChatsCache, [path, data.chats || []]]);
|
||||
} catch {
|
||||
wsChatsCache = new Map([...wsChatsCache, [path, []]]);
|
||||
} finally {
|
||||
const next = new Set(wsChatsLoading);
|
||||
next.delete(path);
|
||||
wsChatsLoading = next;
|
||||
}
|
||||
}
|
||||
|
||||
function closeMobileSidebar() {
|
||||
if (typeof window !== 'undefined' && window.innerWidth < 768) sidebarOpen.set(false);
|
||||
}
|
||||
|
||||
function openWorkspace(e: MouseEvent, path: string) {
|
||||
if (e.metaKey || e.ctrlKey) return;
|
||||
e.preventDefault();
|
||||
goto(`/?workspace=${encodeURIComponent(path)}`);
|
||||
closeMobileSidebar();
|
||||
}
|
||||
|
||||
function openChat(chatId: string, wsPath: string) {
|
||||
goto(`/?workspace=${encodeURIComponent(wsPath)}&chatId=${encodeURIComponent(chatId)}`);
|
||||
closeMobileSidebar();
|
||||
}
|
||||
|
||||
function showMoreChats(wsPath: string) {
|
||||
goto(`/?workspace=${encodeURIComponent(wsPath)}&chatId`);
|
||||
closeMobileSidebar();
|
||||
}
|
||||
|
||||
function newChat(wsPath: string) {
|
||||
goto(`/?workspace=${encodeURIComponent(wsPath)}&chatId`);
|
||||
closeMobileSidebar();
|
||||
}
|
||||
|
||||
function openWsMenu(e: MouseEvent, path: string) {
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
closeChatMenu();
|
||||
wsMenuAnchor = e.currentTarget as HTMLElement;
|
||||
wsMenuPath = path;
|
||||
}
|
||||
|
||||
function closeWsMenu() {
|
||||
wsMenuPath = null;
|
||||
wsMenuAnchor = null;
|
||||
}
|
||||
|
||||
function openChatMenu(e: MouseEvent, chatId: string, wsPath: string) {
|
||||
e.stopPropagation();
|
||||
closeWsMenu();
|
||||
chatMenu = { chatId, wsPath, anchor: e.currentTarget as HTMLElement };
|
||||
}
|
||||
|
||||
function closeChatMenu() {
|
||||
chatMenu = null;
|
||||
}
|
||||
|
||||
async function handleRemoveWorkspace(path: string) {
|
||||
closeWsMenu();
|
||||
await removeWorkspace(path);
|
||||
if (currentPath === path) goto('/');
|
||||
}
|
||||
|
||||
async function handleDeleteChat() {
|
||||
if (!chatMenu) return;
|
||||
const { chatId, wsPath } = chatMenu;
|
||||
closeChatMenu();
|
||||
await apiDeleteChat(chatId);
|
||||
const chats = wsChatsCache.get(wsPath) ?? [];
|
||||
wsChatsCache = new Map([...wsChatsCache, [wsPath, chats.filter((chat) => chat.id !== chatId)]]);
|
||||
if (currentPath === wsPath && $page.url.searchParams.get('chatId') === chatId) {
|
||||
goto(`/?workspace=${encodeURIComponent(wsPath)}`);
|
||||
}
|
||||
}
|
||||
|
||||
const seenChatIds = new Set<string>();
|
||||
|
||||
function handleChatEvent(data: {
|
||||
chat_id: string;
|
||||
done?: boolean;
|
||||
title?: string;
|
||||
delta?: string;
|
||||
workspace?: string;
|
||||
}) {
|
||||
const isNew = !seenChatIds.has(data.chat_id);
|
||||
seenChatIds.add(data.chat_id);
|
||||
if (!data.done && !data.title && !isNew) return;
|
||||
|
||||
wsChatsCache = new Map();
|
||||
for (const path of expandedWorkspaces) fetchWorkspaceChats(path);
|
||||
}
|
||||
|
||||
function isTouchDevice(): boolean {
|
||||
return (
|
||||
typeof window !== 'undefined' && ('ontouchstart' in window || navigator.maxTouchPoints > 0)
|
||||
);
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
if (wsListEl && !isTouchDevice()) {
|
||||
sortable = Sortable.create(wsListEl, {
|
||||
animation: 150,
|
||||
ghostClass: 'opacity-30',
|
||||
dragClass: 'cursor-grabbing',
|
||||
direction: 'vertical',
|
||||
onEnd: (evt) => {
|
||||
if (evt.oldIndex != null && evt.newIndex != null && evt.oldIndex !== evt.newIndex) {
|
||||
reorderWorkspaces(evt.oldIndex, evt.newIndex);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
unbindSocketListener = socketStore.on('events:chat', handleChatEvent);
|
||||
});
|
||||
|
||||
onDestroy(() => {
|
||||
sortable?.destroy();
|
||||
unbindSocketListener?.();
|
||||
unbindSocketListener = null;
|
||||
});
|
||||
</script>
|
||||
|
||||
<div class="flex items-center justify-between h-8 pl-3.5 pr-1.5 shrink-0">
|
||||
<span class="text-xs text-gray-400 dark:text-gray-500">{$t('sidebar.workspaces')}</span>
|
||||
<button
|
||||
class="flex items-center justify-center w-7 h-7 rounded-lg text-gray-300 hover:text-gray-500 dark:text-gray-600 dark:hover:text-gray-400 transition-colors duration-100"
|
||||
onclick={onaddworkspace}
|
||||
aria-label={$t('sidebar.addWorkspace')}
|
||||
use:tooltip={$t('sidebar.addWorkspace')}
|
||||
>
|
||||
<Icon name="plus" size={14} />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div bind:this={wsListEl} class="flex-1 overflow-y-auto px-1.5">
|
||||
{#each $workspaceList as ws (ws.path)}
|
||||
{@const isExpanded = expandedWorkspaces.has(ws.path)}
|
||||
{@const chats = wsChatsCache.get(ws.path)}
|
||||
{@const isLoading = wsChatsLoading.has(ws.path)}
|
||||
<div class="ws-item">
|
||||
<div
|
||||
class="group flex items-center gap-1 w-full h-7 px-2 rounded-lg text-xs font-medium transition-colors duration-100
|
||||
{ws.path === currentPath
|
||||
? 'bg-gray-200/50 text-gray-900 dark:bg-white/8 dark:text-white'
|
||||
: 'text-gray-500 hover:text-gray-700 dark:hover:text-gray-300'}"
|
||||
>
|
||||
<a
|
||||
href="/?workspace={encodeURIComponent(ws.path)}"
|
||||
class="flex items-center gap-1.5 flex-1 min-w-0 no-underline text-inherit"
|
||||
onclick={(e) => openWorkspace(e, ws.path)}
|
||||
>
|
||||
{#if $chatEnabled}
|
||||
<span
|
||||
class="ws-icon-toggle shrink-0"
|
||||
role="button"
|
||||
tabindex="-1"
|
||||
onclick={(e) => {
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
toggleWorkspaceExpand(ws.path);
|
||||
}}
|
||||
aria-label={isExpanded ? $t('sidebar.collapse') : $t('sidebar.addWorkspace')}
|
||||
>
|
||||
<span class="ws-icon-folder"><Icon name="folder" size={14} /></span>
|
||||
<span
|
||||
class="ws-icon-chevron"
|
||||
style="transform: rotate({isExpanded ? '90deg' : '0deg'})"
|
||||
>
|
||||
<Icon name="chevron-right" size={11} />
|
||||
</span>
|
||||
</span>
|
||||
{:else}
|
||||
<Icon name="folder" size={14} />
|
||||
{/if}
|
||||
<span class="flex-1 text-left overflow-hidden text-ellipsis whitespace-nowrap"
|
||||
>{ws.name}</span
|
||||
>
|
||||
</a>
|
||||
<span
|
||||
class="flex items-center justify-center w-4 h-4 shrink-0 text-gray-400 opacity-0 group-hover:opacity-100 hover:text-gray-600 dark:hover:text-gray-300 transition-all duration-75"
|
||||
role="button"
|
||||
tabindex="-1"
|
||||
onclick={(e) => openWsMenu(e, ws.path)}
|
||||
aria-label={$t('sidebar.workspaceOptions')}
|
||||
>
|
||||
<Icon name="three-dots" size={11} />
|
||||
</span>
|
||||
{#if $chatEnabled}
|
||||
<span
|
||||
class="flex items-center justify-center w-4 h-4 shrink-0 text-gray-400 opacity-0 group-hover:opacity-100 hover:text-gray-600 dark:hover:text-gray-300 transition-all duration-75"
|
||||
role="button"
|
||||
tabindex="-1"
|
||||
onclick={() => newChat(ws.path)}
|
||||
aria-label={$t('bar.newChat')}
|
||||
use:tooltip={$t('bar.newChat')}
|
||||
>
|
||||
<Icon name="pencil" size={11} />
|
||||
</span>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
{#if $chatEnabled && isExpanded}
|
||||
<div class="ws-chats">
|
||||
{#if isLoading && !chats}
|
||||
<div class="ws-chat-loading">
|
||||
<span class="ws-chat-loading-dot"></span>
|
||||
<span class="ws-chat-loading-dot"></span>
|
||||
<span class="ws-chat-loading-dot"></span>
|
||||
</div>
|
||||
{:else if chats && chats.length > 0}
|
||||
{#each chats as chat (chat.id)}
|
||||
<ChatItem
|
||||
{chat}
|
||||
onclick={() => openChat(chat.id, ws.path)}
|
||||
onmenu={(e) => openChatMenu(e, chat.id, ws.path)}
|
||||
/>
|
||||
{/each}
|
||||
<button class="ws-chat-show-more" onclick={() => showMoreChats(ws.path)}>
|
||||
{$t('sidebar.showMore')}
|
||||
</button>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{/each}
|
||||
|
||||
{#if $workspaceList.length === 0}
|
||||
<div class="flex flex-col items-center justify-center py-12">
|
||||
<p class="text-xs text-gray-400 dark:text-gray-600">{$t('sidebar.noWorkspaces')}</p>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
{#if wsMenuPath && wsMenuAnchor}
|
||||
<DropdownMenu
|
||||
anchor={wsMenuAnchor}
|
||||
items={[
|
||||
{
|
||||
label: $t('sidebar.remove'),
|
||||
icon: 'xmark',
|
||||
onclick: () => handleRemoveWorkspace(wsMenuPath!)
|
||||
}
|
||||
]}
|
||||
onclose={closeWsMenu}
|
||||
/>
|
||||
{/if}
|
||||
|
||||
{#if chatMenu}
|
||||
<DropdownMenu
|
||||
anchor={chatMenu.anchor}
|
||||
align="end"
|
||||
items={[
|
||||
{
|
||||
label: $t('chat.history.delete'),
|
||||
icon: 'trash',
|
||||
onclick: handleDeleteChat
|
||||
}
|
||||
]}
|
||||
onclose={closeChatMenu}
|
||||
/>
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
@reference "../../app.css";
|
||||
|
||||
.ws-item {
|
||||
margin-bottom: 0.125rem;
|
||||
}
|
||||
|
||||
.ws-icon-toggle {
|
||||
position: relative;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 0.875rem;
|
||||
height: 0.875rem;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.ws-icon-folder {
|
||||
display: flex;
|
||||
transition: opacity 0.1s;
|
||||
}
|
||||
|
||||
.ws-icon-chevron {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
opacity: 0;
|
||||
transition:
|
||||
opacity 0.1s,
|
||||
transform 0.1s;
|
||||
color: #9ca3af;
|
||||
}
|
||||
|
||||
:global(.dark) .ws-icon-chevron {
|
||||
color: #6b7280;
|
||||
}
|
||||
|
||||
.ws-icon-toggle:hover .ws-icon-folder {
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
.ws-icon-toggle:hover .ws-icon-chevron {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.ws-chats {
|
||||
margin-top: 0.125rem;
|
||||
padding-bottom: 0.25rem;
|
||||
}
|
||||
|
||||
.ws-chat-show-more {
|
||||
display: block;
|
||||
width: 100%;
|
||||
padding: 0.125rem 0.5rem;
|
||||
border: none;
|
||||
background: none;
|
||||
cursor: pointer;
|
||||
font-size: 0.6875rem;
|
||||
color: #b0b5be;
|
||||
text-align: left;
|
||||
transition: color 0.1s;
|
||||
}
|
||||
|
||||
.ws-chat-show-more:hover {
|
||||
color: #6b7280;
|
||||
}
|
||||
|
||||
:global(.dark) .ws-chat-show-more {
|
||||
color: #6b7280;
|
||||
}
|
||||
|
||||
:global(.dark) .ws-chat-show-more:hover {
|
||||
color: #9ca3af;
|
||||
}
|
||||
|
||||
.ws-chat-loading {
|
||||
display: flex;
|
||||
gap: 0.25rem;
|
||||
padding: 0.375rem 0.5rem;
|
||||
}
|
||||
|
||||
.ws-chat-loading-dot {
|
||||
width: 0.25rem;
|
||||
height: 0.25rem;
|
||||
border-radius: 50%;
|
||||
background: #9ca3af;
|
||||
animation: dotPulse 1s ease-in-out infinite;
|
||||
}
|
||||
|
||||
:global(.dark) .ws-chat-loading-dot {
|
||||
background: #6b7280;
|
||||
}
|
||||
|
||||
.ws-chat-loading-dot:nth-child(2) {
|
||||
animation-delay: 0.15s;
|
||||
}
|
||||
|
||||
.ws-chat-loading-dot:nth-child(3) {
|
||||
animation-delay: 0.3s;
|
||||
}
|
||||
|
||||
@keyframes dotPulse {
|
||||
0%,
|
||||
100% {
|
||||
opacity: 0.3;
|
||||
}
|
||||
50% {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,233 @@
|
||||
<script module lang="ts">
|
||||
import type { HighlighterCore } from 'shiki/core';
|
||||
|
||||
type HighlightToken = {
|
||||
content: string;
|
||||
offset: number;
|
||||
variants?: {
|
||||
light?: { color?: string };
|
||||
dark?: { color?: string };
|
||||
};
|
||||
};
|
||||
|
||||
let highlighterPromise: Promise<HighlighterCore> | null = null;
|
||||
const tokenCache = new Map<string, HighlightToken[]>();
|
||||
|
||||
async function getHighlighter(): Promise<HighlighterCore> {
|
||||
if (!highlighterPromise) {
|
||||
highlighterPromise = (async () => {
|
||||
const { createHighlighterCore } = await import('shiki/core');
|
||||
const { createOnigurumaEngine } = await import('shiki/engine/oniguruma');
|
||||
return createHighlighterCore({
|
||||
themes: [import('shiki/themes/github-light.mjs'), import('shiki/themes/github-dark.mjs')],
|
||||
langs: [
|
||||
import('shiki/langs/javascript.mjs'),
|
||||
import('shiki/langs/typescript.mjs'),
|
||||
import('shiki/langs/python.mjs'),
|
||||
import('shiki/langs/bash.mjs'),
|
||||
import('shiki/langs/shell.mjs'),
|
||||
import('shiki/langs/json.mjs'),
|
||||
import('shiki/langs/html.mjs'),
|
||||
import('shiki/langs/css.mjs'),
|
||||
import('shiki/langs/markdown.mjs'),
|
||||
import('shiki/langs/yaml.mjs'),
|
||||
import('shiki/langs/toml.mjs'),
|
||||
import('shiki/langs/rust.mjs'),
|
||||
import('shiki/langs/go.mjs'),
|
||||
import('shiki/langs/c.mjs'),
|
||||
import('shiki/langs/cpp.mjs'),
|
||||
import('shiki/langs/java.mjs'),
|
||||
import('shiki/langs/sql.mjs'),
|
||||
import('shiki/langs/svelte.mjs'),
|
||||
import('shiki/langs/dockerfile.mjs'),
|
||||
import('shiki/langs/xml.mjs'),
|
||||
import('shiki/langs/ruby.mjs'),
|
||||
import('shiki/langs/php.mjs'),
|
||||
import('shiki/langs/swift.mjs'),
|
||||
import('shiki/langs/kotlin.mjs'),
|
||||
import('shiki/langs/lua.mjs'),
|
||||
import('shiki/langs/tsx.mjs'),
|
||||
import('shiki/langs/jsx.mjs'),
|
||||
import('shiki/langs/scss.mjs'),
|
||||
import('shiki/langs/graphql.mjs'),
|
||||
import('shiki/langs/makefile.mjs')
|
||||
],
|
||||
engine: createOnigurumaEngine(import('shiki/wasm'))
|
||||
});
|
||||
})();
|
||||
}
|
||||
return highlighterPromise;
|
||||
}
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
import type { DiffLineType, InlineDiffSegment } from '$lib/utils/diff';
|
||||
|
||||
interface Props {
|
||||
type: DiffLineType;
|
||||
content: string;
|
||||
segments: InlineDiffSegment[];
|
||||
language: string;
|
||||
wrap?: boolean;
|
||||
class?: string;
|
||||
}
|
||||
|
||||
type RenderSegment = InlineDiffSegment & {
|
||||
light?: string;
|
||||
dark?: string;
|
||||
};
|
||||
|
||||
let { type, content, segments, language, wrap = false, class: className = '' }: Props = $props();
|
||||
let renderedSegments = $state<RenderSegment[] | null>(null);
|
||||
|
||||
$effect(() => {
|
||||
const currentContent = content;
|
||||
const currentSegments = segments;
|
||||
const currentLanguage = language;
|
||||
|
||||
(async () => {
|
||||
if (!currentLanguage || currentLanguage === 'text') {
|
||||
renderedSegments = null;
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const key = `${currentLanguage}\0${currentContent}`;
|
||||
let tokens = tokenCache.get(key);
|
||||
if (!tokens) {
|
||||
const highlighter = await getHighlighter();
|
||||
if (!highlighter.getLoadedLanguages().includes(currentLanguage)) {
|
||||
renderedSegments = null;
|
||||
return;
|
||||
}
|
||||
const tokenLines = highlighter.codeToTokensWithThemes(currentContent, {
|
||||
lang: currentLanguage,
|
||||
themes: { light: 'github-light', dark: 'github-dark' }
|
||||
}) as HighlightToken[][];
|
||||
tokens = tokenLines[0] ?? [];
|
||||
tokenCache.set(key, tokens);
|
||||
}
|
||||
if (
|
||||
currentContent !== content ||
|
||||
currentSegments !== segments ||
|
||||
currentLanguage !== language
|
||||
) {
|
||||
return;
|
||||
}
|
||||
renderedSegments = mergeTokensWithSegments(tokens, currentSegments);
|
||||
} catch {
|
||||
renderedSegments = null;
|
||||
}
|
||||
})();
|
||||
});
|
||||
|
||||
function mergeTokensWithSegments(
|
||||
tokens: HighlightToken[],
|
||||
diffSegments: InlineDiffSegment[]
|
||||
): RenderSegment[] {
|
||||
const ranges: Array<{ start: number; end: number; changed: boolean }> = [];
|
||||
let offset = 0;
|
||||
for (const segment of diffSegments) {
|
||||
ranges.push({ start: offset, end: offset + segment.text.length, changed: segment.changed });
|
||||
offset += segment.text.length;
|
||||
}
|
||||
|
||||
const merged: RenderSegment[] = [];
|
||||
for (const token of tokens) {
|
||||
const tokenStart = token.offset;
|
||||
const tokenEnd = token.offset + token.content.length;
|
||||
for (const range of ranges) {
|
||||
const start = Math.max(tokenStart, range.start);
|
||||
const end = Math.min(tokenEnd, range.end);
|
||||
if (start >= end) continue;
|
||||
merged.push({
|
||||
text: token.content.slice(start - tokenStart, end - tokenStart),
|
||||
changed: range.changed,
|
||||
light: token.variants?.light?.color,
|
||||
dark: token.variants?.dark?.color
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return merged.length ? merged : diffSegments;
|
||||
}
|
||||
|
||||
function inlineSegmentClass(type: DiffLineType, changed: boolean): string {
|
||||
if (!changed) return '';
|
||||
if (type === 'added') return 'inline-change inline-added';
|
||||
if (type === 'removed') return 'inline-change inline-removed';
|
||||
return '';
|
||||
}
|
||||
|
||||
function escapeHtml(text: string): string {
|
||||
return text
|
||||
.replaceAll('&', '&')
|
||||
.replaceAll('<', '<')
|
||||
.replaceAll('>', '>')
|
||||
.replaceAll('"', '"');
|
||||
}
|
||||
|
||||
function htmlForSegments(type: DiffLineType, segments: RenderSegment[]): string {
|
||||
return segments
|
||||
.map((segment) => {
|
||||
const classes = inlineSegmentClass(type, segment.changed);
|
||||
const styles = [
|
||||
segment.light ? `--diff-token-light: ${segment.light}` : '',
|
||||
segment.dark ? `--diff-token-dark: ${segment.dark}` : ''
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join('; ');
|
||||
const classAttr = classes ? ` class="${classes}"` : '';
|
||||
const styleAttr = styles ? ` style="${styles}"` : '';
|
||||
return `<span${classAttr}${styleAttr}>${escapeHtml(segment.text)}</span>`;
|
||||
})
|
||||
.join('');
|
||||
}
|
||||
|
||||
const fallbackSegments = $derived(renderedSegments ?? segments);
|
||||
const html = $derived(htmlForSegments(type, fallbackSegments));
|
||||
</script>
|
||||
|
||||
<code
|
||||
class="syntax-diff-line block px-2 {wrap
|
||||
? 'whitespace-pre-wrap break-words'
|
||||
: 'whitespace-pre'} {className}">{@html html}</code
|
||||
>
|
||||
|
||||
<style>
|
||||
.syntax-diff-line :global(span) {
|
||||
color: var(--diff-token-light, inherit);
|
||||
}
|
||||
|
||||
:global(.dark) .syntax-diff-line :global(span) {
|
||||
color: var(--diff-token-dark, inherit);
|
||||
}
|
||||
|
||||
.syntax-diff-line :global(.inline-change) {
|
||||
border-radius: 0.125rem;
|
||||
box-decoration-break: clone;
|
||||
-webkit-box-decoration-break: clone;
|
||||
font-weight: 700;
|
||||
padding: 0.0625rem 0.125rem;
|
||||
}
|
||||
|
||||
.syntax-diff-line :global(.inline-added) {
|
||||
background: rgba(22, 163, 74, 0.38);
|
||||
box-shadow: inset 0 -0.125rem 0 rgba(21, 128, 61, 0.42);
|
||||
}
|
||||
|
||||
.syntax-diff-line :global(.inline-removed) {
|
||||
background: rgba(220, 38, 38, 0.32);
|
||||
box-shadow: inset 0 -0.125rem 0 rgba(185, 28, 28, 0.38);
|
||||
}
|
||||
|
||||
:global(.dark) .syntax-diff-line :global(.inline-added) {
|
||||
background: rgba(34, 197, 94, 0.42);
|
||||
box-shadow: inset 0 -0.125rem 0 rgba(134, 239, 172, 0.5);
|
||||
}
|
||||
|
||||
:global(.dark) .syntax-diff-line :global(.inline-removed) {
|
||||
background: rgba(248, 113, 113, 0.4);
|
||||
box-shadow: inset 0 -0.125rem 0 rgba(252, 165, 165, 0.48);
|
||||
}
|
||||
</style>
|
||||
@@ -97,7 +97,7 @@
|
||||
try {
|
||||
await deleteAutomation(a.id);
|
||||
items = items.filter((i) => i.id !== a.id);
|
||||
if (detail?.id === a.id) goto('/automations');
|
||||
if (detail?.id === a.id) goto('/scheduled');
|
||||
toast.success($t('automations.deleted'));
|
||||
} catch (e: any) {
|
||||
toast.error(e.message || $t('automations.failedToDelete'));
|
||||
@@ -211,7 +211,7 @@
|
||||
{/if}
|
||||
<button
|
||||
class="flex items-center gap-1 text-xs text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 transition-colors duration-75"
|
||||
onclick={() => goto('/automations')}
|
||||
onclick={() => goto('/scheduled')}
|
||||
>
|
||||
<Icon name="chevron-left" size={12} />
|
||||
<span>{$t('automations.title')}</span>
|
||||
@@ -509,7 +509,7 @@
|
||||
></span>
|
||||
<button
|
||||
class="text-xs text-gray-700 dark:text-gray-300 truncate flex-1 text-left hover:underline cursor-pointer transition-colors duration-75"
|
||||
onclick={() => goto(`/automations/${a.id}`)}
|
||||
onclick={() => goto(`/scheduled/${a.id}`)}
|
||||
>
|
||||
{a.name}
|
||||
</button>
|
||||
|
||||
@@ -464,7 +464,7 @@
|
||||
"about.share": "Teilen",
|
||||
"about.copyLink": "Link kopieren",
|
||||
"about.copied": "Kopiert!",
|
||||
"automations.title": "Automatisierungen",
|
||||
"automations.title": "Geplant",
|
||||
"automations.filter": "Filtern...",
|
||||
"automations.noMatches": "Keine Treffer",
|
||||
"automations.noAutomations": "Noch keine Automatisierungen",
|
||||
@@ -922,7 +922,7 @@
|
||||
"models.builtinTools.chatsDesc": "Frühere Chats durchsuchen",
|
||||
"models.builtinTools.skills": "Skills",
|
||||
"models.builtinTools.skillsDesc": "Computer-Skills anzeigen und verwalten",
|
||||
"models.builtinTools.automations": "Automatisierungen",
|
||||
"models.builtinTools.automations": "Geplant",
|
||||
"models.builtinTools.automationsDesc": "Geplante Automatisierungen auflisten und verwalten",
|
||||
"models.builtinTools.images": "Bilder",
|
||||
"models.builtinTools.imagesDesc": "Bilder erstellen oder bearbeiten",
|
||||
|
||||
@@ -466,11 +466,11 @@
|
||||
"about.share": "Share",
|
||||
"about.copyLink": "Copy link",
|
||||
"about.copied": "Copied!",
|
||||
"automations.title": "Automations",
|
||||
"automations.title": "Scheduled",
|
||||
"automations.filter": "Filter...",
|
||||
"automations.noMatches": "No matches",
|
||||
"automations.noAutomations": "No automations yet",
|
||||
"automations.create": "Create automation",
|
||||
"automations.noAutomations": "No scheduled tasks yet",
|
||||
"automations.create": "Create scheduled task",
|
||||
"automations.status": "Status",
|
||||
"automations.active": "Active",
|
||||
"automations.paused": "Paused",
|
||||
@@ -493,8 +493,8 @@
|
||||
"automations.deleted": "Deleted",
|
||||
"automations.webhookEnabled": "Webhook enabled",
|
||||
"automations.webhookDisabled": "Webhook disabled",
|
||||
"automations.failedToLoad": "Failed to load automations",
|
||||
"automations.failedToLoadOne": "Failed to load automation",
|
||||
"automations.failedToLoad": "Failed to load scheduled tasks",
|
||||
"automations.failedToLoadOne": "Failed to load scheduled task",
|
||||
"automations.failedToToggle": "Failed to toggle",
|
||||
"automations.failedToDelete": "Failed to delete",
|
||||
"automations.failedToRun": "Failed to run",
|
||||
@@ -503,9 +503,9 @@
|
||||
"automations.triggered": "\"{{name}}\" triggered",
|
||||
"automations.deleteConfirm": "Delete \"{{name}}\"?",
|
||||
"automations.runNow": "Run now",
|
||||
"automations.newAutomation": "New automation",
|
||||
"automations.newAutomation": "New scheduled task",
|
||||
"automations.toggleSidebar": "Toggle sidebar",
|
||||
"automationModal.titlePlaceholder": "Automation title",
|
||||
"automationModal.titlePlaceholder": "Scheduled task title",
|
||||
"automationModal.instructions": "Instructions",
|
||||
"automationModal.promptPlaceholder": "Enter prompt here...",
|
||||
"automationModal.selectWorkspace": "Select workspace",
|
||||
@@ -513,7 +513,7 @@
|
||||
"automationModal.saving": "Saving...",
|
||||
"automationModal.save": "Save",
|
||||
"automationModal.createBtn": "Create",
|
||||
"automationModal.failedToSave": "Failed to save automation",
|
||||
"automationModal.failedToSave": "Failed to save scheduled task",
|
||||
"connections.failedToUpdate": "Failed to update connection",
|
||||
"admin.gateway.tab": "Gateway",
|
||||
"admin.gateway.title": "API Gateway",
|
||||
@@ -866,7 +866,7 @@
|
||||
"onboarding.connectAi": "Connect AI",
|
||||
"onboarding.provider": "Provider",
|
||||
"onboarding.apiType": "API Type",
|
||||
"onboarding.connectAiDesc": "Add an API key to unlock chat, code editing, and automations.",
|
||||
"onboarding.connectAiDesc": "Add an API key to unlock chat, code editing, and scheduled tasks.",
|
||||
"onboarding.connectAiSkip": "I'll do this later",
|
||||
"onboarding.keyStaysLocal": "Your key stays on this machine.",
|
||||
"onboarding.connected": "{{name}} connected",
|
||||
@@ -936,8 +936,8 @@
|
||||
"models.builtinTools.skillsDesc": "View and manage Computer skills",
|
||||
"models.builtinTools.tasks": "Tasks",
|
||||
"models.builtinTools.tasksDesc": "Show visible task progress in chat",
|
||||
"models.builtinTools.automations": "Automations",
|
||||
"models.builtinTools.automationsDesc": "List and manage scheduled automations",
|
||||
"models.builtinTools.automations": "Scheduled",
|
||||
"models.builtinTools.automationsDesc": "List and manage scheduled tasks",
|
||||
"models.builtinTools.images": "Images",
|
||||
"models.builtinTools.imagesDesc": "Generate or edit images",
|
||||
"models.builtinTools.subagents": "Subagents",
|
||||
@@ -991,7 +991,7 @@
|
||||
"git.deleteBranchConfirm": "Delete branch \"{{name}}\"?",
|
||||
"git.branchDeleted": "Branch deleted",
|
||||
"git.deleteBranchFailed": "Failed to delete branch",
|
||||
"automations.automation": "Automation",
|
||||
"automations.automation": "Scheduled task",
|
||||
"automations.once": "Once",
|
||||
"automations.hourly": "Hourly",
|
||||
"automations.daily": "Daily",
|
||||
|
||||
@@ -464,7 +464,7 @@
|
||||
"about.share": "Compartir",
|
||||
"about.copyLink": "Copiar enlace",
|
||||
"about.copied": "¡Copiado!",
|
||||
"automations.title": "Automatizaciones",
|
||||
"automations.title": "Programadas",
|
||||
"automations.filter": "Filtrar...",
|
||||
"automations.noMatches": "Sin resultados",
|
||||
"automations.noAutomations": "Aún no hay automatizaciones",
|
||||
@@ -922,7 +922,7 @@
|
||||
"models.builtinTools.chatsDesc": "Buscar chats anteriores",
|
||||
"models.builtinTools.skills": "Habilidades",
|
||||
"models.builtinTools.skillsDesc": "Ver y administrar habilidades de Computer",
|
||||
"models.builtinTools.automations": "Automatizaciones",
|
||||
"models.builtinTools.automations": "Programadas",
|
||||
"models.builtinTools.automationsDesc": "Listar y administrar automatizaciones programadas",
|
||||
"models.builtinTools.images": "Imágenes",
|
||||
"models.builtinTools.imagesDesc": "Generar o editar imágenes",
|
||||
|
||||
@@ -464,7 +464,7 @@
|
||||
"about.share": "Partager",
|
||||
"about.copyLink": "Copier le lien",
|
||||
"about.copied": "Copié !",
|
||||
"automations.title": "Automatisations",
|
||||
"automations.title": "Planifiées",
|
||||
"automations.filter": "Filtrer...",
|
||||
"automations.noMatches": "Aucun résultat",
|
||||
"automations.noAutomations": "Aucune automatisation",
|
||||
@@ -922,7 +922,7 @@
|
||||
"models.builtinTools.chatsDesc": "Rechercher dans les chats précédents",
|
||||
"models.builtinTools.skills": "Compétences",
|
||||
"models.builtinTools.skillsDesc": "Afficher et gérer les compétences Computer",
|
||||
"models.builtinTools.automations": "Automatisations",
|
||||
"models.builtinTools.automations": "Planifiées",
|
||||
"models.builtinTools.automationsDesc": "Lister et gérer les automatisations planifiées",
|
||||
"models.builtinTools.images": "Images",
|
||||
"models.builtinTools.imagesDesc": "Générer ou modifier des images",
|
||||
|
||||
@@ -464,7 +464,7 @@
|
||||
"about.share": "共有",
|
||||
"about.copyLink": "リンクをコピー",
|
||||
"about.copied": "コピーしました!",
|
||||
"automations.title": "自動化",
|
||||
"automations.title": "スケジュール済み",
|
||||
"automations.filter": "フィルター...",
|
||||
"automations.noMatches": "一致なし",
|
||||
"automations.noAutomations": "自動化はまだありません",
|
||||
@@ -922,7 +922,7 @@
|
||||
"models.builtinTools.chatsDesc": "過去のチャットを検索します",
|
||||
"models.builtinTools.skills": "スキル",
|
||||
"models.builtinTools.skillsDesc": "Computer のスキルを表示および管理します",
|
||||
"models.builtinTools.automations": "自動化",
|
||||
"models.builtinTools.automations": "スケジュール済み",
|
||||
"models.builtinTools.automationsDesc": "スケジュール済みの自動化を一覧表示して管理します",
|
||||
"models.builtinTools.images": "画像",
|
||||
"models.builtinTools.imagesDesc": "画像を生成または編集します",
|
||||
|
||||
@@ -464,7 +464,7 @@
|
||||
"about.share": "공유",
|
||||
"about.copyLink": "링크 복사",
|
||||
"about.copied": "복사됨!",
|
||||
"automations.title": "자동화",
|
||||
"automations.title": "예약됨",
|
||||
"automations.filter": "필터...",
|
||||
"automations.noMatches": "일치 항목 없음",
|
||||
"automations.noAutomations": "자동화가 아직 없습니다",
|
||||
@@ -922,7 +922,7 @@
|
||||
"models.builtinTools.chatsDesc": "이전 채팅을 검색합니다",
|
||||
"models.builtinTools.skills": "스킬",
|
||||
"models.builtinTools.skillsDesc": "Computer 스킬을 보고 관리합니다",
|
||||
"models.builtinTools.automations": "자동화",
|
||||
"models.builtinTools.automations": "예약됨",
|
||||
"models.builtinTools.automationsDesc": "예약된 자동화를 나열하고 관리합니다",
|
||||
"models.builtinTools.images": "이미지",
|
||||
"models.builtinTools.imagesDesc": "이미지를 생성하거나 편집합니다",
|
||||
|
||||
@@ -464,7 +464,7 @@
|
||||
"about.share": "Compartilhar",
|
||||
"about.copyLink": "Copiar link",
|
||||
"about.copied": "Copiado!",
|
||||
"automations.title": "Automações",
|
||||
"automations.title": "Agendadas",
|
||||
"automations.filter": "Filtrar...",
|
||||
"automations.noMatches": "Sem resultados",
|
||||
"automations.noAutomations": "Nenhuma automação ainda",
|
||||
@@ -922,7 +922,7 @@
|
||||
"models.builtinTools.chatsDesc": "Pesquisar chats anteriores",
|
||||
"models.builtinTools.skills": "Habilidades",
|
||||
"models.builtinTools.skillsDesc": "Ver e gerenciar habilidades do Computer",
|
||||
"models.builtinTools.automations": "Automações",
|
||||
"models.builtinTools.automations": "Agendadas",
|
||||
"models.builtinTools.automationsDesc": "Listar e gerenciar automações agendadas",
|
||||
"models.builtinTools.images": "Imagens",
|
||||
"models.builtinTools.imagesDesc": "Gerar ou editar imagens",
|
||||
|
||||
@@ -464,7 +464,7 @@
|
||||
"about.share": "Поделиться",
|
||||
"about.copyLink": "Копировать ссылку",
|
||||
"about.copied": "Скопировано!",
|
||||
"automations.title": "Автоматизации",
|
||||
"automations.title": "Запланированные",
|
||||
"automations.filter": "Фильтр...",
|
||||
"automations.noMatches": "Нет совпадений",
|
||||
"automations.noAutomations": "Автоматизаций пока нет",
|
||||
@@ -922,7 +922,7 @@
|
||||
"models.builtinTools.chatsDesc": "Поиск по прошлым чатам",
|
||||
"models.builtinTools.skills": "Навыки",
|
||||
"models.builtinTools.skillsDesc": "Просмотр и управление навыками Computer",
|
||||
"models.builtinTools.automations": "Автоматизации",
|
||||
"models.builtinTools.automations": "Запланированные",
|
||||
"models.builtinTools.automationsDesc": "Список и управление запланированными автоматизациями",
|
||||
"models.builtinTools.images": "Изображения",
|
||||
"models.builtinTools.imagesDesc": "Создание или редактирование изображений",
|
||||
|
||||
@@ -464,7 +464,7 @@
|
||||
"about.share": "分享",
|
||||
"about.copyLink": "复制链接",
|
||||
"about.copied": "已复制!",
|
||||
"automations.title": "自动化",
|
||||
"automations.title": "已计划",
|
||||
"automations.filter": "筛选...",
|
||||
"automations.noMatches": "无匹配",
|
||||
"automations.noAutomations": "暂无自动化",
|
||||
@@ -922,7 +922,7 @@
|
||||
"models.builtinTools.chatsDesc": "搜索以前的聊天",
|
||||
"models.builtinTools.skills": "技能",
|
||||
"models.builtinTools.skillsDesc": "查看和管理 Computer 技能",
|
||||
"models.builtinTools.automations": "自动化",
|
||||
"models.builtinTools.automations": "已计划",
|
||||
"models.builtinTools.automationsDesc": "列出并管理计划自动化",
|
||||
"models.builtinTools.images": "图片",
|
||||
"models.builtinTools.imagesDesc": "生成或编辑图片",
|
||||
|
||||
@@ -464,7 +464,7 @@
|
||||
"about.share": "分享",
|
||||
"about.copyLink": "複製連結",
|
||||
"about.copied": "已複製!",
|
||||
"automations.title": "自動化",
|
||||
"automations.title": "已排程",
|
||||
"automations.filter": "篩選...",
|
||||
"automations.noMatches": "無符合項目",
|
||||
"automations.noAutomations": "尚無自動化",
|
||||
@@ -922,7 +922,7 @@
|
||||
"models.builtinTools.chatsDesc": "搜尋過去的聊天",
|
||||
"models.builtinTools.skills": "技能",
|
||||
"models.builtinTools.skillsDesc": "檢視和管理 Computer 技能",
|
||||
"models.builtinTools.automations": "自動化",
|
||||
"models.builtinTools.automations": "已排程",
|
||||
"models.builtinTools.automationsDesc": "列出並管理排程自動化",
|
||||
"models.builtinTools.images": "圖片",
|
||||
"models.builtinTools.imagesDesc": "生成或編輯圖片",
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
import { writable } from 'svelte/store';
|
||||
|
||||
const HIDE_WHITESPACE_KEY = 'gitDiff:hideWhitespace';
|
||||
const DISPLAY_MODE_KEY = 'gitDiff:displayMode';
|
||||
export type DiffDisplayMode = 'unified' | 'split';
|
||||
|
||||
function persistedBoolean(key: string, fallback: boolean) {
|
||||
const initial =
|
||||
typeof localStorage !== 'undefined' ? localStorage.getItem(key) === 'true' : fallback;
|
||||
const store = writable(initial);
|
||||
store.subscribe((value) => {
|
||||
if (typeof localStorage !== 'undefined') localStorage.setItem(key, String(value));
|
||||
});
|
||||
return store;
|
||||
}
|
||||
|
||||
export const hideWhitespaceChanges = persistedBoolean(HIDE_WHITESPACE_KEY, false);
|
||||
|
||||
const initialDisplayMode =
|
||||
typeof localStorage !== 'undefined'
|
||||
? localStorage.getItem(DISPLAY_MODE_KEY) === 'split'
|
||||
? 'split'
|
||||
: 'unified'
|
||||
: 'unified';
|
||||
|
||||
export const diffDisplayMode = writable<DiffDisplayMode>(initialDisplayMode);
|
||||
diffDisplayMode.subscribe((value) => {
|
||||
if (typeof localStorage !== 'undefined') localStorage.setItem(DISPLAY_MODE_KEY, value);
|
||||
});
|
||||
@@ -17,6 +17,8 @@ export interface GitFile {
|
||||
unstaged?: boolean;
|
||||
staged_status?: string;
|
||||
unstaged_status?: string;
|
||||
additions?: number;
|
||||
deletions?: number;
|
||||
}
|
||||
|
||||
export interface GitStatus {
|
||||
|
||||
@@ -0,0 +1,217 @@
|
||||
export type DiffLineType = 'added' | 'removed' | 'context';
|
||||
export type DiffLine = { type: DiffLineType; content: string };
|
||||
export type DiffHunk = { header: string; lines: DiffLine[] };
|
||||
export type DiffFile = { path: string; hunks: DiffHunk[] };
|
||||
export type NumberedDiffLine = DiffLine & { oldNumber: number | null; newNumber: number | null };
|
||||
export type InlineDiffSegment = { text: string; changed: boolean };
|
||||
export type InlineDiffLine = NumberedDiffLine & { segments: InlineDiffSegment[] };
|
||||
export type DiffLineGroup<T extends { type: string }> = { type: T['type']; lines: T[] };
|
||||
export type SplitDiffRow = { oldLine: InlineDiffLine | null; newLine: InlineDiffLine | null };
|
||||
export type DiffStats = { additions: number; deletions: number };
|
||||
|
||||
export function countDiffStats(files: DiffFile[]): DiffStats {
|
||||
let additions = 0;
|
||||
let deletions = 0;
|
||||
for (const file of files) {
|
||||
for (const hunk of file.hunks) {
|
||||
for (const line of hunk.lines) {
|
||||
if (line.type === 'added') additions += 1;
|
||||
if (line.type === 'removed') deletions += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return { additions, deletions };
|
||||
}
|
||||
|
||||
export function languageForPath(path: string): string {
|
||||
const ext = path.slice(path.lastIndexOf('.')).toLowerCase();
|
||||
const byExt: Record<string, string> = {
|
||||
'.py': 'python',
|
||||
'.js': 'javascript',
|
||||
'.ts': 'typescript',
|
||||
'.jsx': 'jsx',
|
||||
'.tsx': 'tsx',
|
||||
'.svelte': 'svelte',
|
||||
'.css': 'css',
|
||||
'.scss': 'scss',
|
||||
'.html': 'html',
|
||||
'.json': 'json',
|
||||
'.xml': 'xml',
|
||||
'.yaml': 'yaml',
|
||||
'.yml': 'yaml',
|
||||
'.toml': 'toml',
|
||||
'.md': 'markdown',
|
||||
'.sh': 'bash',
|
||||
'.bash': 'bash',
|
||||
'.zsh': 'bash',
|
||||
'.rs': 'rust',
|
||||
'.go': 'go',
|
||||
'.java': 'java',
|
||||
'.c': 'c',
|
||||
'.h': 'c',
|
||||
'.cpp': 'cpp',
|
||||
'.hpp': 'cpp',
|
||||
'.rb': 'ruby',
|
||||
'.php': 'php',
|
||||
'.swift': 'swift',
|
||||
'.kt': 'kotlin',
|
||||
'.sql': 'sql',
|
||||
'.lua': 'lua',
|
||||
'.dockerfile': 'dockerfile',
|
||||
'.makefile': 'makefile'
|
||||
};
|
||||
return byExt[ext] ?? 'text';
|
||||
}
|
||||
|
||||
export function numberDiffLines(hunk: DiffHunk): NumberedDiffLine[] {
|
||||
const match = hunk.header.match(/^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@/);
|
||||
let oldNumber = match ? Number(match[1]) : 0;
|
||||
let newNumber = match ? Number(match[2]) : 0;
|
||||
|
||||
return hunk.lines.map((line) => {
|
||||
if (line.type === 'added') return { ...line, oldNumber: null, newNumber: newNumber++ };
|
||||
if (line.type === 'removed') return { ...line, oldNumber: oldNumber++, newNumber: null };
|
||||
return { ...line, oldNumber: oldNumber++, newNumber: newNumber++ };
|
||||
});
|
||||
}
|
||||
|
||||
export function groupDiffLines<T extends { type: string }>(lines: T[]): DiffLineGroup<T>[] {
|
||||
const groups: DiffLineGroup<T>[] = [];
|
||||
for (const line of lines) {
|
||||
const last = groups[groups.length - 1];
|
||||
if (last && last.type === line.type) last.lines.push(line);
|
||||
else groups.push({ type: line.type, lines: [line] });
|
||||
}
|
||||
return groups;
|
||||
}
|
||||
|
||||
export function withInlineDiffSegments(lines: NumberedDiffLine[]): InlineDiffLine[] {
|
||||
const result: InlineDiffLine[] = [];
|
||||
let i = 0;
|
||||
|
||||
while (i < lines.length) {
|
||||
const line = lines[i];
|
||||
if (line.type === 'context') {
|
||||
result.push({ ...line, segments: [{ text: line.content || ' ', changed: false }] });
|
||||
i += 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
const block: NumberedDiffLine[] = [];
|
||||
while (i < lines.length && lines[i].type !== 'context') {
|
||||
block.push(lines[i]);
|
||||
i += 1;
|
||||
}
|
||||
|
||||
const removed = block.filter((item) => item.type === 'removed');
|
||||
const added = block.filter((item) => item.type === 'added');
|
||||
const removedSegments = removed.map((item, index) =>
|
||||
segmentsForPair(item.content, added[index]?.content, 'removed')
|
||||
);
|
||||
const addedSegments = added.map((item, index) =>
|
||||
segmentsForPair(removed[index]?.content, item.content, 'added')
|
||||
);
|
||||
|
||||
for (const item of block) {
|
||||
const index =
|
||||
item.type === 'removed'
|
||||
? removed.indexOf(item)
|
||||
: item.type === 'added'
|
||||
? added.indexOf(item)
|
||||
: -1;
|
||||
const segments =
|
||||
item.type === 'removed'
|
||||
? removedSegments[index]
|
||||
: item.type === 'added'
|
||||
? addedSegments[index]
|
||||
: [{ text: item.content || ' ', changed: false }];
|
||||
result.push({ ...item, segments });
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
export function splitDiffRows(lines: InlineDiffLine[]): SplitDiffRow[] {
|
||||
const rows: SplitDiffRow[] = [];
|
||||
let i = 0;
|
||||
|
||||
while (i < lines.length) {
|
||||
const line = lines[i];
|
||||
if (line.type === 'context') {
|
||||
rows.push({ oldLine: line, newLine: line });
|
||||
i += 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
const block: InlineDiffLine[] = [];
|
||||
while (i < lines.length && lines[i].type !== 'context') {
|
||||
block.push(lines[i]);
|
||||
i += 1;
|
||||
}
|
||||
|
||||
const removed = block.filter((item) => item.type === 'removed');
|
||||
const added = block.filter((item) => item.type === 'added');
|
||||
const count = Math.max(removed.length, added.length);
|
||||
for (let index = 0; index < count; index += 1) {
|
||||
rows.push({ oldLine: removed[index] ?? null, newLine: added[index] ?? null });
|
||||
}
|
||||
}
|
||||
|
||||
return rows;
|
||||
}
|
||||
|
||||
function segmentsForPair(
|
||||
oldText: string | undefined,
|
||||
newText: string | undefined,
|
||||
side: 'removed' | 'added'
|
||||
): InlineDiffSegment[] {
|
||||
const text = side === 'removed' ? oldText : newText;
|
||||
if (text === undefined) return [];
|
||||
if (oldText === undefined || newText === undefined)
|
||||
return [{ text: text || ' ', changed: false }];
|
||||
if (oldText === newText) return [{ text: text || ' ', changed: false }];
|
||||
|
||||
let prefix = 0;
|
||||
const maxPrefix = Math.min(oldText.length, newText.length);
|
||||
while (prefix < maxPrefix && oldText[prefix] === newText[prefix]) prefix += 1;
|
||||
|
||||
let oldSuffix = oldText.length;
|
||||
let newSuffix = newText.length;
|
||||
while (
|
||||
oldSuffix > prefix &&
|
||||
newSuffix > prefix &&
|
||||
oldText[oldSuffix - 1] === newText[newSuffix - 1]
|
||||
) {
|
||||
oldSuffix -= 1;
|
||||
newSuffix -= 1;
|
||||
}
|
||||
|
||||
const oldChangedLength = oldSuffix - prefix;
|
||||
const newChangedLength = newSuffix - prefix;
|
||||
const sharedLength = Math.max(
|
||||
oldText.length - oldChangedLength,
|
||||
newText.length - newChangedLength
|
||||
);
|
||||
const similarity = sharedLength / Math.max(oldText.length, newText.length, 1);
|
||||
const changedLength = side === 'removed' ? oldChangedLength : newChangedLength;
|
||||
if (similarity < 0.55 || changedLength / Math.max(text.length, 1) > 0.45) {
|
||||
return [{ text: text || ' ', changed: false }];
|
||||
}
|
||||
|
||||
const end = side === 'removed' ? oldSuffix : newSuffix;
|
||||
const changed = text.slice(prefix, end);
|
||||
const tokenStart = changed.search(/[A-Za-z0-9_$]/);
|
||||
if (tokenStart < 0) return [{ text: text || ' ', changed: false }];
|
||||
|
||||
const tokenEnd = changed.search(/[A-Za-z0-9_$][^A-Za-z0-9_$]*$/);
|
||||
const highlightStart = tokenStart >= 0 ? prefix + tokenStart : prefix;
|
||||
const highlightEnd = tokenEnd >= 0 ? prefix + tokenEnd + 1 : end;
|
||||
const segments = [
|
||||
{ text: text.slice(0, highlightStart), changed: false },
|
||||
{ text: text.slice(highlightStart, highlightEnd), changed: true },
|
||||
{ text: text.slice(highlightEnd), changed: false }
|
||||
].filter((segment) => segment.text.length > 0);
|
||||
|
||||
return segments.length ? segments : [{ text: ' ', changed: false }];
|
||||
}
|
||||
@@ -5,48 +5,157 @@
|
||||
|
||||
export function fileIconName(name: string, type: string = 'file'): string {
|
||||
if (type === 'directory') return 'folder';
|
||||
const ext = name.split('.').pop()?.toLowerCase() ?? '';
|
||||
if (name === 'Dockerfile') return 'docker';
|
||||
if (name === 'LICENSE' || name === 'LICENSE.md') return 'page-text';
|
||||
if (name.endsWith('.lock')) return 'lock';
|
||||
const base = name.split('/').pop() ?? name;
|
||||
const lower = base.toLowerCase();
|
||||
const ext = base.includes('.') ? (base.split('.').pop()?.toLowerCase() ?? '') : '';
|
||||
|
||||
if (lower === 'dockerfile' || lower === 'containerfile') return 'docker';
|
||||
if (lower === 'license' || lower === 'license.md') return 'page-text';
|
||||
if (lower === 'package.json' || lower === 'npm-shrinkwrap.json' || lower === 'bunfig.toml') {
|
||||
return 'npm';
|
||||
}
|
||||
if (
|
||||
lower.endsWith('.lock') ||
|
||||
lower === 'package-lock.json' ||
|
||||
lower === 'pnpm-lock.yaml' ||
|
||||
lower === 'yarn.lock'
|
||||
) {
|
||||
return 'package-lock';
|
||||
}
|
||||
|
||||
switch (ext) {
|
||||
case 'md':
|
||||
return 'page-text';
|
||||
case 'mdx':
|
||||
case 'markdown':
|
||||
return 'markdown-logo';
|
||||
case 'ts':
|
||||
return 'typescript-logo';
|
||||
case 'tsx':
|
||||
return 'react';
|
||||
case 'js':
|
||||
case 'mjs':
|
||||
case 'cjs':
|
||||
return 'javascript-logo';
|
||||
case 'jsx':
|
||||
return 'react';
|
||||
case 'py':
|
||||
case 'pyw':
|
||||
return 'python';
|
||||
case 'rs':
|
||||
return 'rust';
|
||||
case 'go':
|
||||
return 'go-logo';
|
||||
case 'java':
|
||||
return 'java-logo';
|
||||
case 'c':
|
||||
case 'cpp':
|
||||
case 'h':
|
||||
return 'c-logo';
|
||||
case 'cpp':
|
||||
case 'cc':
|
||||
case 'cxx':
|
||||
case 'hpp':
|
||||
case 'hh':
|
||||
case 'hxx':
|
||||
return 'cpp-logo';
|
||||
case 'cs':
|
||||
return 'c-sharp-logo';
|
||||
case 'rb':
|
||||
return 'ruby-logo';
|
||||
case 'php':
|
||||
return 'php-logo';
|
||||
case 'swift':
|
||||
return 'apple-swift';
|
||||
case 'kt':
|
||||
case 'kts':
|
||||
return 'kotlin-logo';
|
||||
case 'svelte':
|
||||
return 'svelte-logo';
|
||||
case 'vue':
|
||||
return 'code';
|
||||
return 'vue-js';
|
||||
case 'json':
|
||||
case 'jsonc':
|
||||
case 'json5':
|
||||
return 'json-logo';
|
||||
case 'yaml':
|
||||
case 'yml':
|
||||
return 'yaml-logo';
|
||||
case 'toml':
|
||||
case 'ini':
|
||||
case 'cfg':
|
||||
case 'conf':
|
||||
case 'env':
|
||||
return 'settings';
|
||||
case 'sh':
|
||||
case 'bash':
|
||||
case 'zsh':
|
||||
return 'terminal';
|
||||
case 'css':
|
||||
case 'fish':
|
||||
return 'shell-logo';
|
||||
case 'html':
|
||||
case 'htm':
|
||||
return 'html5';
|
||||
case 'css':
|
||||
case 'scss':
|
||||
case 'sass':
|
||||
case 'less':
|
||||
return 'css3';
|
||||
case 'xml':
|
||||
return 'code';
|
||||
return 'xml-logo';
|
||||
case 'svg':
|
||||
return 'svg-format';
|
||||
case 'sql':
|
||||
case 'sqlite':
|
||||
case 'sqlite3':
|
||||
case 'db':
|
||||
case 'db3':
|
||||
return 'database-script';
|
||||
case 'csv':
|
||||
case 'tsv':
|
||||
return 'csv-logo';
|
||||
case 'pdf':
|
||||
return 'pdf-logo';
|
||||
case 'jpg':
|
||||
case 'jpeg':
|
||||
case 'png':
|
||||
case 'gif':
|
||||
case 'webp':
|
||||
case 'bmp':
|
||||
case 'ico':
|
||||
case 'avif':
|
||||
case 'tiff':
|
||||
return 'image';
|
||||
case 'mp4':
|
||||
case 'webm':
|
||||
case 'mov':
|
||||
case 'ogv':
|
||||
case 'avi':
|
||||
case 'mkv':
|
||||
return 'play';
|
||||
case 'mp3':
|
||||
case 'wav':
|
||||
case 'ogg':
|
||||
case 'flac':
|
||||
case 'm4a':
|
||||
case 'aac':
|
||||
case 'opus':
|
||||
case 'wma':
|
||||
return 'speaker';
|
||||
case 'zip':
|
||||
case 'tar':
|
||||
case 'gz':
|
||||
case 'tgz':
|
||||
case 'bz2':
|
||||
case 'xz':
|
||||
case '7z':
|
||||
case 'rar':
|
||||
return 'archive';
|
||||
case 'docx':
|
||||
case 'txt':
|
||||
return 'page-text';
|
||||
case 'xlsx':
|
||||
case 'xls':
|
||||
return 'table';
|
||||
case 'pptx':
|
||||
return 'page';
|
||||
default:
|
||||
return 'empty-page';
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
<script lang="ts">
|
||||
import AutomationsPanel from '$lib/components/automations/AutomationsPanel.svelte';
|
||||
import { t } from '$lib/i18n';
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<title>{$t('automations.title')} / Computer</title>
|
||||
</svelte:head>
|
||||
|
||||
<AutomationsPanel />
|
||||
@@ -0,0 +1,13 @@
|
||||
<script lang="ts">
|
||||
import { page } from '$app/stores';
|
||||
import AutomationsPanel from '$lib/components/automations/AutomationsPanel.svelte';
|
||||
import { t } from '$lib/i18n';
|
||||
|
||||
const automationId = $derived($page.params.id);
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<title>{$t('automations.automation')} / Computer</title>
|
||||
</svelte:head>
|
||||
|
||||
<AutomationsPanel {automationId} />
|
||||
+8
-4
@@ -69,12 +69,16 @@ async def git_status(root: str):
|
||||
|
||||
@router.get("/diff")
|
||||
async def git_diff(
|
||||
root: str, file: Optional[str] = None, staged: bool = False, untracked: bool = False
|
||||
root: str,
|
||||
file: Optional[str] = None,
|
||||
staged: bool = False,
|
||||
untracked: bool = False,
|
||||
ignore_whitespace: bool = False,
|
||||
):
|
||||
"""Get diff for working tree or staged changes."""
|
||||
await _require_repo(root)
|
||||
try:
|
||||
return await diff(root, file, staged, untracked)
|
||||
return await diff(root, file, staged, untracked, ignore_whitespace)
|
||||
except GitError as e:
|
||||
_handle_git_error(e)
|
||||
|
||||
@@ -90,11 +94,11 @@ async def git_log(root: str, limit: int = 50, offset: int = 0):
|
||||
|
||||
|
||||
@router.get("/show")
|
||||
async def git_show(root: str, ref: str):
|
||||
async def git_show(root: str, ref: str, ignore_whitespace: bool = False):
|
||||
"""Show a single commit with its diff."""
|
||||
await _require_repo(root)
|
||||
try:
|
||||
return await show(root, ref)
|
||||
return await show(root, ref, ignore_whitespace)
|
||||
except GitError as e:
|
||||
_handle_git_error(e)
|
||||
|
||||
|
||||
+45
-12
@@ -14,6 +14,7 @@ import logging
|
||||
from typing import Any
|
||||
|
||||
import websockets
|
||||
from websockets.exceptions import ConnectionClosed
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -65,7 +66,11 @@ class CDPClient:
|
||||
ws_url = page_target["webSocketDebuggerUrl"]
|
||||
target_id = page_target["id"]
|
||||
|
||||
ws = await websockets.connect(ws_url, max_size=50 * 1024 * 1024)
|
||||
ws = await websockets.connect(
|
||||
ws_url,
|
||||
max_size=50 * 1024 * 1024,
|
||||
ping_interval=None,
|
||||
)
|
||||
|
||||
client = cls(ws, target_id)
|
||||
|
||||
@@ -87,17 +92,46 @@ class CDPClient:
|
||||
if params:
|
||||
payload["params"] = params
|
||||
|
||||
await self._ws.send(json.dumps(payload))
|
||||
try:
|
||||
await self._ws.send(json.dumps(payload))
|
||||
|
||||
# Wait for matching response (skip events)
|
||||
while True:
|
||||
# Wait for matching response (skip events)
|
||||
while True:
|
||||
data = await self._recv_json()
|
||||
if data.get("id") == msg_id:
|
||||
if "error" in data:
|
||||
raise RuntimeError(
|
||||
f"CDP error: {data['error'].get('message', data['error'])}"
|
||||
)
|
||||
return data.get("result", {})
|
||||
# Ignore events (no "id" field)
|
||||
except ConnectionClosed:
|
||||
self._closed = True
|
||||
raise
|
||||
|
||||
async def _recv_json(self) -> dict:
|
||||
try:
|
||||
raw = await asyncio.wait_for(self._ws.recv(), timeout=30)
|
||||
data = json.loads(raw)
|
||||
if data.get("id") == msg_id:
|
||||
if "error" in data:
|
||||
raise RuntimeError(f"CDP error: {data['error'].get('message', data['error'])}")
|
||||
return data.get("result", {})
|
||||
# Ignore events (no "id" field)
|
||||
except ConnectionClosed:
|
||||
self._closed = True
|
||||
raise
|
||||
return json.loads(raw)
|
||||
|
||||
def is_closed(self) -> bool:
|
||||
"""Return whether this client or its underlying socket is closed."""
|
||||
if self._closed:
|
||||
return True
|
||||
|
||||
if getattr(self._ws, "closed", False):
|
||||
self._closed = True
|
||||
return True
|
||||
|
||||
state_name = getattr(getattr(self._ws, "state", None), "name", None)
|
||||
if state_name in {"CLOSING", "CLOSED"}:
|
||||
self._closed = True
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
# ── Navigation ─────────────────────────────────────────
|
||||
|
||||
@@ -107,8 +141,7 @@ class CDPClient:
|
||||
|
||||
# Wait for load event
|
||||
while True:
|
||||
raw = await asyncio.wait_for(self._ws.recv(), timeout=30)
|
||||
data = json.loads(raw)
|
||||
data = await self._recv_json()
|
||||
if data.get("method") == "Page.loadEventFired":
|
||||
break
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ class BrowserSessionManager:
|
||||
"""Get an existing session for this chat, or create a new one."""
|
||||
if chat_id in self._sessions:
|
||||
client = self._sessions[chat_id]
|
||||
if not client._closed:
|
||||
if not client.is_closed():
|
||||
self._last_used[chat_id] = time.monotonic()
|
||||
return client
|
||||
# Session was closed externally, remove it
|
||||
|
||||
@@ -2166,7 +2166,9 @@ async def run_chat_task(
|
||||
for idx in other_indices:
|
||||
tc, item = call_items[idx]
|
||||
if tc["name"] == "create_artifact":
|
||||
result = await create_artifact(**tc["arguments"], workspace=workspace)
|
||||
args = dict(tc["arguments"])
|
||||
args.pop("workspace", None)
|
||||
result = await create_artifact(**args, workspace=workspace)
|
||||
else:
|
||||
result = await execute_tool(
|
||||
tc["name"],
|
||||
|
||||
@@ -93,14 +93,13 @@ def resolve_compact_token_threshold(
|
||||
model: str | None = None,
|
||||
*,
|
||||
chat_models_config: dict | None = None,
|
||||
global_cap: int | None = None,
|
||||
global_threshold: int | None = None,
|
||||
) -> int:
|
||||
"""Return the effective compaction threshold for a model.
|
||||
|
||||
The existing global threshold is the cap. Model-level values can lower it
|
||||
for smaller context windows, but never raise it.
|
||||
Model-level values override the global default.
|
||||
"""
|
||||
cap = global_cap or _get_threshold()
|
||||
default_threshold = global_threshold or _get_threshold()
|
||||
model_threshold = None
|
||||
|
||||
if chat_models_config:
|
||||
@@ -117,7 +116,7 @@ def resolve_compact_token_threshold(
|
||||
if model_threshold:
|
||||
break
|
||||
|
||||
return min(model_threshold, cap) if model_threshold else cap
|
||||
return model_threshold or default_threshold
|
||||
|
||||
|
||||
async def load_compact_token_threshold(model: str | None = None) -> int:
|
||||
|
||||
+47
-18
@@ -95,6 +95,21 @@ async def status(root: str) -> dict[str, Any]:
|
||||
# Prefer the working-tree status for the row label when both sides exist.
|
||||
entry["status"] = status_text
|
||||
|
||||
async def add_numstat(*args: str) -> None:
|
||||
code, numstat, _ = await _run("diff", "--numstat", *args, cwd=root, check=False)
|
||||
if code != 0:
|
||||
return
|
||||
for line in numstat.splitlines():
|
||||
parts = line.split("\t")
|
||||
if len(parts) < 3:
|
||||
continue
|
||||
added, deleted, path = parts[0], parts[1], parts[2]
|
||||
entry = files_by_path.get(path)
|
||||
if not entry or added == "-" or deleted == "-":
|
||||
continue
|
||||
entry["additions"] = entry.get("additions", 0) + int(added)
|
||||
entry["deletions"] = entry.get("deletions", 0) + int(deleted)
|
||||
|
||||
for line in out.splitlines():
|
||||
if line.startswith("# branch.head "):
|
||||
branch = line.split(" ", 2)[2]
|
||||
@@ -126,6 +141,9 @@ async def status(root: str) -> dict[str, Any]:
|
||||
# Untracked
|
||||
path = line[2:]
|
||||
add_file(path, "untracked", unstaged=True)
|
||||
entry = files_by_path[path]
|
||||
entry["additions"] = _count_text_lines(os.path.join(root, path))
|
||||
entry["deletions"] = 0
|
||||
elif line.startswith("u "):
|
||||
# Unmerged
|
||||
parts = line.split(" ", 10)
|
||||
@@ -137,6 +155,9 @@ async def status(root: str) -> dict[str, Any]:
|
||||
if upstream and not has_ab:
|
||||
upstream = ""
|
||||
|
||||
await add_numstat()
|
||||
await add_numstat("--staged")
|
||||
|
||||
# Get remote URL for "View on GitHub/GitLab" link
|
||||
code, remote_out, _ = await _run("remote", "get-url", "origin", cwd=root, check=False)
|
||||
remote_url = remote_out.strip() if code == 0 else ""
|
||||
@@ -163,29 +184,40 @@ def _status_char(c: str) -> str:
|
||||
}.get(c, c)
|
||||
|
||||
|
||||
def _count_text_lines(path: str) -> int:
|
||||
try:
|
||||
with open(path, "rb") as f:
|
||||
data = f.read()
|
||||
except OSError:
|
||||
return 0
|
||||
if b"\0" in data:
|
||||
return 0
|
||||
if not data:
|
||||
return 0
|
||||
return data.count(b"\n") + (0 if data.endswith(b"\n") else 1)
|
||||
|
||||
|
||||
async def diff(
|
||||
root: str,
|
||||
file: str | None = None,
|
||||
staged: bool = False,
|
||||
untracked: bool = False,
|
||||
ignore_whitespace: bool = False,
|
||||
) -> dict[str, Any]:
|
||||
"""Get diff output as structured data."""
|
||||
if untracked and file:
|
||||
# Untracked files: use --no-index to diff against empty
|
||||
null_device = "NUL" if sys.platform == "win32" else "/dev/null"
|
||||
_, out, _ = await _run(
|
||||
"diff",
|
||||
"--no-index",
|
||||
"--unified=3",
|
||||
"--",
|
||||
null_device,
|
||||
file,
|
||||
cwd=root,
|
||||
check=False,
|
||||
)
|
||||
args = ["diff", "--no-index", "--unified=3"]
|
||||
if ignore_whitespace:
|
||||
args.append("--ignore-all-space")
|
||||
args.extend(["--", null_device, file])
|
||||
_, out, _ = await _run(*args, cwd=root, check=False)
|
||||
return _parse_diff(out)
|
||||
|
||||
args = ["diff", "--unified=3"]
|
||||
if ignore_whitespace:
|
||||
args.append("--ignore-all-space")
|
||||
if staged:
|
||||
args.append("--staged")
|
||||
if file:
|
||||
@@ -365,16 +397,13 @@ async def log(
|
||||
return commits
|
||||
|
||||
|
||||
async def show(root: str, ref: str) -> dict[str, Any]:
|
||||
async def show(root: str, ref: str, ignore_whitespace: bool = False) -> dict[str, Any]:
|
||||
"""Show a commit's diff."""
|
||||
fmt = "%H%x00%h%x00%an%x00%aI%x00%s"
|
||||
_, out, _ = await _run(
|
||||
"show",
|
||||
ref,
|
||||
f"--format={fmt}",
|
||||
"--patch",
|
||||
cwd=root,
|
||||
)
|
||||
args = ["show", ref, f"--format={fmt}", "--patch"]
|
||||
if ignore_whitespace:
|
||||
args.append("--ignore-all-space")
|
||||
_, out, _ = await _run(*args, cwd=root)
|
||||
|
||||
# First line is the formatted header, rest is diff
|
||||
lines = out.split("\n", 1)
|
||||
|
||||
@@ -2923,6 +2923,8 @@ async def execute_tool(name: str, args: dict, __context__: dict) -> str:
|
||||
if not is_builtin_tool_enabled(name, __context__.get("builtin_tools")):
|
||||
return f"Error: tool disabled: {name}"
|
||||
fn = info["fn"]
|
||||
args = dict(args)
|
||||
args.pop("workspace", None)
|
||||
try:
|
||||
sig = inspect.signature(fn)
|
||||
if "__context__" in sig.parameters:
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
[project]
|
||||
name = "cptr"
|
||||
version = "0.8.5"
|
||||
version = "0.8.6"
|
||||
description = "Your computer, from anywhere. Code, manage, and control your machine from the web."
|
||||
license = {file = "LICENSE"}
|
||||
readme = "README.md"
|
||||
|
||||
Reference in new issue
Block a user