From 1cbb3a5e6fe58cd4bd8127834edc8e0064eba9fb Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Thu, 9 Jul 2026 16:58:28 -0500 Subject: [PATCH] refac --- README.md | 2 +- .../src/lib/components/FileBrowser.svelte | 9 +- .../src/lib/components/FileEditor.svelte | 52 +++- .../frontend/src/lib/components/GitBar.svelte | 74 +++--- .../src/lib/components/GitView.svelte | 78 ++---- cptr/frontend/src/lib/components/Icon.svelte | 243 ++++++++++++++++++ .../src/lib/components/SearchModal.svelte | 2 +- .../src/lib/components/SidebarNav.svelte | 4 +- .../automations/AutomationsPanel.svelte | 6 +- cptr/frontend/src/lib/i18n/locales/de.json | 4 +- cptr/frontend/src/lib/i18n/locales/en.json | 24 +- cptr/frontend/src/lib/i18n/locales/es.json | 4 +- cptr/frontend/src/lib/i18n/locales/fr.json | 4 +- cptr/frontend/src/lib/i18n/locales/ja.json | 4 +- cptr/frontend/src/lib/i18n/locales/ko.json | 4 +- cptr/frontend/src/lib/i18n/locales/pt-BR.json | 4 +- cptr/frontend/src/lib/i18n/locales/ru.json | 4 +- cptr/frontend/src/lib/i18n/locales/zh-CN.json | 4 +- cptr/frontend/src/lib/i18n/locales/zh-TW.json | 4 +- .../src/lib/stores/gitStatus.svelte.ts | 2 + cptr/frontend/src/lib/utils/diff.ts | 15 ++ cptr/frontend/src/lib/utils/fileIcon.ts | 129 +++++++++- .../src/routes/scheduled/+page.svelte | 10 + .../src/routes/scheduled/[id]/+page.svelte | 13 + cptr/utils/git.py | 34 +++ 25 files changed, 594 insertions(+), 139 deletions(-) create mode 100644 cptr/frontend/src/routes/scheduled/+page.svelte create mode 100644 cptr/frontend/src/routes/scheduled/[id]/+page.svelte diff --git a/README.md b/README.md index b1d43ee..d4ea90a 100644 --- a/README.md +++ b/README.md @@ -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. | diff --git a/cptr/frontend/src/lib/components/FileBrowser.svelte b/cptr/frontend/src/lib/components/FileBrowser.svelte index 2b2aaf5..50d0c97 100644 --- a/cptr/frontend/src/lib/components/FileBrowser.svelte +++ b/cptr/frontend/src/lib/components/FileBrowser.svelte @@ -1228,9 +1228,14 @@ {/if} {#if fileGitStatus && entryGitDecoration} {entryGitDecoration.char} + +{fileGitStatus.additions ?? 0} + -{fileGitStatus.deletions ?? 0} + {/if} {#if entry.type !== 'directory' && entry.size !== null} f.path === relPath); } + let currentFileStatus = $derived(fileData ? gitFileStatus(fileData.path) : undefined); + function applyGitLineChanges() { gitLineChanges = normalizeGitLineChanges(gitLineChanges); view?.dispatch({ effects: setGitLineChangesEffect.of(gitLineChanges) }); @@ -1030,7 +1032,15 @@
- {fileData.name} + + {fileData.name} + {#if currentFileStatus} + + +{currentFileStatus.additions ?? 0} + -{currentFileStatus.deletions ?? 0} + + {/if} + {formatSize(fileData.size)}
@@ -1268,10 +1278,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; @@ -1288,6 +1308,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; diff --git a/cptr/frontend/src/lib/components/GitBar.svelte b/cptr/frontend/src/lib/components/GitBar.svelte index af5227e..dc703d0 100644 --- a/cptr/frontend/src/lib/components/GitBar.svelte +++ b/cptr/frontend/src/lib/components/GitBar.svelte @@ -34,7 +34,7 @@ import { t } from '$lib/i18n'; import Spinner from '$lib/components/common/Spinner.svelte'; import DiffSettingsMenu from './DiffSettingsMenu.svelte'; - import type { DiffFile } from '$lib/utils/diff'; + import { countDiffStats, type DiffFile } from '$lib/utils/diff'; import DiffHunkRows from './DiffHunkRows.svelte'; type GitFile = { @@ -44,6 +44,8 @@ unstaged?: boolean; staged_status?: string; unstaged_status?: string; + additions?: number; + deletions?: number; }; type Commit = { hash: string; short_hash: string; author: string; date: string; message: string }; type BranchItem = { @@ -116,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); @@ -664,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) @@ -762,7 +752,7 @@
{ expanded = !expanded; if (expanded) { @@ -774,11 +764,12 @@ {#if gitStatus.ahead > 0}↑{gitStatus.ahead}{/if} {#if gitStatus.behind > 0}↓{gitStatus.behind}{/if} {#if totalChanges > 0}{$t('git.changedCount', { count: totalChanges })}+{totalAdditions}-{totalDeletions}{/if} {#if actionMsg}{actionMsg}{/if} @@ -817,7 +813,7 @@ @@ -1240,7 +1236,6 @@
{#each gitStatus?.files ?? [] as file (file.path)} {@const fp = fPath(file.path)} - {@const sc = statusChar(file.status)}
diff --git a/cptr/frontend/src/lib/components/GitView.svelte b/cptr/frontend/src/lib/components/GitView.svelte index 99b7ca1..15ee85b 100644 --- a/cptr/frontend/src/lib/components/GitView.svelte +++ b/cptr/frontend/src/lib/components/GitView.svelte @@ -6,7 +6,7 @@ import { tooltip } from '$lib/tooltip'; import { t } from '$lib/i18n'; - import type { DiffFile } from '$lib/utils/diff'; + 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'; @@ -34,6 +34,8 @@ 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 @@ -89,7 +91,7 @@ diffFiles = []; } - const counts = countDiff(diffFiles); + const counts = countDiffStats(diffFiles); const key = fileKey(file); return { key, @@ -126,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 @@ -162,27 +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' }; - } - }
{$t('git.changedCount', { count: totalChanges })} + +{totalAdditions} + -{totalDeletions} {/if}
@@ -279,6 +252,12 @@ {$t('git.change', { count: totalChanges })} + +{totalAdditions} + -{totalDeletions}
{/if} @@ -304,7 +283,6 @@
{#each reviewFiles as file (file.key)} {@const parts = pathParts(file.path)} - {@const meta = statusMeta(file.status)}
diff --git a/cptr/frontend/src/lib/i18n/locales/de.json b/cptr/frontend/src/lib/i18n/locales/de.json index 95d9834..3d0fdf1 100644 --- a/cptr/frontend/src/lib/i18n/locales/de.json +++ b/cptr/frontend/src/lib/i18n/locales/de.json @@ -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", diff --git a/cptr/frontend/src/lib/i18n/locales/en.json b/cptr/frontend/src/lib/i18n/locales/en.json index eaa89b4..6592c35 100644 --- a/cptr/frontend/src/lib/i18n/locales/en.json +++ b/cptr/frontend/src/lib/i18n/locales/en.json @@ -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", diff --git a/cptr/frontend/src/lib/i18n/locales/es.json b/cptr/frontend/src/lib/i18n/locales/es.json index 12ec210..7303275 100644 --- a/cptr/frontend/src/lib/i18n/locales/es.json +++ b/cptr/frontend/src/lib/i18n/locales/es.json @@ -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", diff --git a/cptr/frontend/src/lib/i18n/locales/fr.json b/cptr/frontend/src/lib/i18n/locales/fr.json index b278ec6..1075c62 100644 --- a/cptr/frontend/src/lib/i18n/locales/fr.json +++ b/cptr/frontend/src/lib/i18n/locales/fr.json @@ -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", diff --git a/cptr/frontend/src/lib/i18n/locales/ja.json b/cptr/frontend/src/lib/i18n/locales/ja.json index 6f14825..2770d19 100644 --- a/cptr/frontend/src/lib/i18n/locales/ja.json +++ b/cptr/frontend/src/lib/i18n/locales/ja.json @@ -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": "画像を生成または編集します", diff --git a/cptr/frontend/src/lib/i18n/locales/ko.json b/cptr/frontend/src/lib/i18n/locales/ko.json index 74b1aa0..59aa16b 100644 --- a/cptr/frontend/src/lib/i18n/locales/ko.json +++ b/cptr/frontend/src/lib/i18n/locales/ko.json @@ -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": "이미지를 생성하거나 편집합니다", diff --git a/cptr/frontend/src/lib/i18n/locales/pt-BR.json b/cptr/frontend/src/lib/i18n/locales/pt-BR.json index decc4a3..9927ad8 100644 --- a/cptr/frontend/src/lib/i18n/locales/pt-BR.json +++ b/cptr/frontend/src/lib/i18n/locales/pt-BR.json @@ -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", diff --git a/cptr/frontend/src/lib/i18n/locales/ru.json b/cptr/frontend/src/lib/i18n/locales/ru.json index dce4659..d25e8fd 100644 --- a/cptr/frontend/src/lib/i18n/locales/ru.json +++ b/cptr/frontend/src/lib/i18n/locales/ru.json @@ -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": "Создание или редактирование изображений", diff --git a/cptr/frontend/src/lib/i18n/locales/zh-CN.json b/cptr/frontend/src/lib/i18n/locales/zh-CN.json index 2618560..33c94bd 100644 --- a/cptr/frontend/src/lib/i18n/locales/zh-CN.json +++ b/cptr/frontend/src/lib/i18n/locales/zh-CN.json @@ -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": "生成或编辑图片", diff --git a/cptr/frontend/src/lib/i18n/locales/zh-TW.json b/cptr/frontend/src/lib/i18n/locales/zh-TW.json index 658f201..8467992 100644 --- a/cptr/frontend/src/lib/i18n/locales/zh-TW.json +++ b/cptr/frontend/src/lib/i18n/locales/zh-TW.json @@ -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": "生成或編輯圖片", diff --git a/cptr/frontend/src/lib/stores/gitStatus.svelte.ts b/cptr/frontend/src/lib/stores/gitStatus.svelte.ts index 7b1c7d9..6858b40 100644 --- a/cptr/frontend/src/lib/stores/gitStatus.svelte.ts +++ b/cptr/frontend/src/lib/stores/gitStatus.svelte.ts @@ -17,6 +17,8 @@ export interface GitFile { unstaged?: boolean; staged_status?: string; unstaged_status?: string; + additions?: number; + deletions?: number; } export interface GitStatus { diff --git a/cptr/frontend/src/lib/utils/diff.ts b/cptr/frontend/src/lib/utils/diff.ts index ecdd4c1..7737b05 100644 --- a/cptr/frontend/src/lib/utils/diff.ts +++ b/cptr/frontend/src/lib/utils/diff.ts @@ -7,6 +7,21 @@ export type InlineDiffSegment = { text: string; changed: boolean }; export type InlineDiffLine = NumberedDiffLine & { segments: InlineDiffSegment[] }; export type DiffLineGroup = { 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(); diff --git a/cptr/frontend/src/lib/utils/fileIcon.ts b/cptr/frontend/src/lib/utils/fileIcon.ts index 6f71ac1..b7c1239 100644 --- a/cptr/frontend/src/lib/utils/fileIcon.ts +++ b/cptr/frontend/src/lib/utils/fileIcon.ts @@ -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'; } diff --git a/cptr/frontend/src/routes/scheduled/+page.svelte b/cptr/frontend/src/routes/scheduled/+page.svelte new file mode 100644 index 0000000..6790d01 --- /dev/null +++ b/cptr/frontend/src/routes/scheduled/+page.svelte @@ -0,0 +1,10 @@ + + + + {$t('automations.title')} / Computer + + + diff --git a/cptr/frontend/src/routes/scheduled/[id]/+page.svelte b/cptr/frontend/src/routes/scheduled/[id]/+page.svelte new file mode 100644 index 0000000..47414b0 --- /dev/null +++ b/cptr/frontend/src/routes/scheduled/[id]/+page.svelte @@ -0,0 +1,13 @@ + + + + {$t('automations.automation')} / Computer + + + diff --git a/cptr/utils/git.py b/cptr/utils/git.py index 416663a..f8a5f01 100644 --- a/cptr/utils/git.py +++ b/cptr/utils/git.py @@ -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,6 +184,19 @@ 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,