diff --git a/CHANGELOG.md b/CHANGELOG.md index bc9fd9b..f96db97 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,13 @@ 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.7] - 2026-07-09 + +### Fixed + +- 🗂️ **Clearer Git status.** File changes now show a clear status instead of misleading line totals for images and other non-text files. +- 🤖 **More reliable Claude Code chats.** Image attachments and separate thinking sections now appear and finish more reliably. + ## [0.8.6] - 2026-07-09 ### Added diff --git a/cptr/frontend/src/lib/components/FileBrowser.svelte b/cptr/frontend/src/lib/components/FileBrowser.svelte index 50d0c97..04277e7 100644 --- a/cptr/frontend/src/lib/components/FileBrowser.svelte +++ b/cptr/frontend/src/lib/components/FileBrowser.svelte @@ -1231,10 +1231,15 @@ class="flex shrink-0 items-center gap-1 text-[0.625rem] font-mono font-medium" use:tooltip={gitStatusTooltip(fileGitStatus, entry)} > - +{fileGitStatus.additions ?? 0} - -{fileGitStatus.deletions ?? 0} + {#if fileGitStatus.binary} + {entryGitDecoration.char} + {:else} + +{fileGitStatus.additions ?? 0} + -{fileGitStatus.deletions ?? 0} + {/if} {/if} {#if entry.type !== 'directory' && entry.size !== null} diff --git a/cptr/frontend/src/lib/components/FileEditor.svelte b/cptr/frontend/src/lib/components/FileEditor.svelte index eddc75d..87935da 100644 --- a/cptr/frontend/src/lib/components/FileEditor.svelte +++ b/cptr/frontend/src/lib/components/FileEditor.svelte @@ -1026,6 +1026,17 @@ return `${(bytes / 1048576).toFixed(1)} MB`; } + function gitStatusChar(status: string): string { + const chars: Record = { + added: 'A', + untracked: 'U', + modified: 'M', + deleted: 'D', + renamed: 'R' + }; + return chars[status] ?? '?'; + } + onDestroy(() => { destroyEditor(); revokeBinaryUrl(); @@ -1041,8 +1052,12 @@ {fileData.name} {#if currentFileStatus} - +{currentFileStatus.additions ?? 0} - -{currentFileStatus.deletions ?? 0} + {#if currentFileStatus.binary} + {gitStatusChar(currentFileStatus.status)} + {:else} + +{currentFileStatus.additions ?? 0} + -{currentFileStatus.deletions ?? 0} + {/if} {/if} @@ -1325,6 +1340,10 @@ color: #ef4444; } + .file-git-status { + color: var(--color-gray-500); + } + :global(.dark) .file-git-additions { color: #4ade80; } diff --git a/cptr/frontend/src/lib/components/GitBar.svelte b/cptr/frontend/src/lib/components/GitBar.svelte index 94cf2a0..0299588 100644 --- a/cptr/frontend/src/lib/components/GitBar.svelte +++ b/cptr/frontend/src/lib/components/GitBar.svelte @@ -44,6 +44,7 @@ unstaged?: boolean; staged_status?: string; unstaged_status?: string; + binary?: boolean; additions?: number; deletions?: number; }; @@ -673,6 +674,25 @@ return `${Math.floor(s / 86400)}d`; } + function statusChar(status: string): { char: string; color: string } { + switch (status) { + 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) @@ -788,25 +808,38 @@ - {#if gitStatus.ahead > 0} 0} + ↑{gitStatus.ahead}{/if} - {#if gitStatus.behind > 0}↓{gitStatus.behind}{/if} - {#if totalChanges > 0} + ↑{gitStatus.ahead} + + {/if} + {#if gitStatus.behind > 0} + + ↓{gitStatus.behind} + + {/if} + {#if totalChanges > 0} + {$t('git.changedCount', { count: totalChanges })}+{totalAdditions} - -{totalDeletions}{/if} - {#if actionMsg} + {$t('git.changedCount', { count: totalChanges })} + + {#if totalAdditions || totalDeletions} + + +{totalAdditions} + -{totalDeletions} + + {/if} + {/if} + {#if actionMsg} + {actionMsg}{/if} + > + {actionMsg} + + {/if}
@@ -1235,6 +1268,7 @@
{#each gitStatus?.files ?? [] as file (file.path)} {@const fp = fPath(file.path)} + {@const sc = statusChar(file.status)}
{/if} @@ -312,14 +329,21 @@ > {/if} - +{file.additions} - -{file.deletions} + {#if file.binary} + {statusChar(file.status)} + {:else} + +{file.additions} + -{file.deletions} + {/if} str: return "\n\n".join(parts) -def _claude_query_input(prompt: str, attachments: PreparedAgentAttachments) -> Any: +def _claude_query_input( + prompt: str, attachments: PreparedAgentAttachments +) -> str | AsyncIterator[dict[str, Any]]: if not attachments.images: return prompt content: list[dict[str, Any]] = [] @@ -52,7 +54,15 @@ def _claude_query_input(prompt: str, attachments: PreparedAgentAttachments) -> A }, } ) - return content + + async def messages() -> AsyncIterator[dict[str, Any]]: + yield { + "type": "user", + "message": {"role": "user", "content": content}, + "parent_tool_use_id": None, + } + + return messages() def _chat_approval_mode(chat_params: dict[str, Any]) -> str: diff --git a/cptr/utils/chat_task.py b/cptr/utils/chat_task.py index 9672e9e..bba5aa7 100644 --- a/cptr/utils/chat_task.py +++ b/cptr/utils/chat_task.py @@ -1521,21 +1521,22 @@ async def run_chat_task( runner = runners.get(agent_target.agent) if runner is None: raise RuntimeError(f"Unsupported agent type: {agent_target.agent}") - reasoning_buffer = "" - reasoning_item_id = f"reasoning-{message_id}" + + def _active_reasoning_item(): + return next( + ( + item + for item in reversed(output_items) + if item.get("type") == "reasoning" and item.get("status") == "in_progress" + ), + None, + ) async def _finish_reasoning_item(): - existing = next( - (item for item in output_items if item.get("id") == reasoning_item_id), None - ) - if not existing or existing.get("status") == "completed": + existing = _active_reasoning_item() + if not existing: return - item = { - "type": "reasoning", - "id": reasoning_item_id, - "status": "completed", - "content": [{"type": "reasoning_text", "text": reasoning_buffer}], - } + item = {**existing, "status": "completed"} _upsert_output_item(output_items, item) await emit(output=item) _sync_state() @@ -1557,13 +1558,29 @@ async def run_chat_task( await emit(delta=event.text) _sync_state() elif isinstance(event, AgentReasoningDelta): - reasoning_buffer += event.text - item = { - "type": "reasoning", - "id": reasoning_item_id, - "status": "in_progress", - "content": [{"type": "reasoning_text", "text": reasoning_buffer}], - } + existing = _active_reasoning_item() + if existing: + blocks = existing.get("content") or [] + text = next( + ( + block.get("text", "") + for block in blocks + if isinstance(block, dict) and block.get("type") == "reasoning_text" + ), + "", + ) + item = { + **existing, + "content": [{"type": "reasoning_text", "text": f"{text}{event.text}"}], + } + else: + section = sum(item.get("type") == "reasoning" for item in output_items) + 1 + item = { + "type": "reasoning", + "id": f"reasoning-{message_id}-{section}", + "status": "in_progress", + "content": [{"type": "reasoning_text", "text": event.text}], + } _upsert_output_item(output_items, item) await emit(output=item) _sync_state() diff --git a/cptr/utils/git.py b/cptr/utils/git.py index f8a5f01..ad9e2de 100644 --- a/cptr/utils/git.py +++ b/cptr/utils/git.py @@ -105,7 +105,10 @@ async def status(root: str) -> dict[str, Any]: continue added, deleted, path = parts[0], parts[1], parts[2] entry = files_by_path.get(path) - if not entry or added == "-" or deleted == "-": + if not entry: + continue + if added == "-" or deleted == "-": + entry["binary"] = True continue entry["additions"] = entry.get("additions", 0) + int(added) entry["deletions"] = entry.get("deletions", 0) + int(deleted) @@ -142,8 +145,12 @@ async def status(root: str) -> dict[str, Any]: 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 + line_count = _count_text_lines(os.path.join(root, path)) + if line_count is None: + entry["binary"] = True + else: + entry["additions"] = line_count + entry["deletions"] = 0 elif line.startswith("u "): # Unmerged parts = line.split(" ", 10) @@ -184,14 +191,14 @@ def _status_char(c: str) -> str: }.get(c, c) -def _count_text_lines(path: str) -> int: +def _count_text_lines(path: str) -> int | None: try: with open(path, "rb") as f: data = f.read() except OSError: - return 0 + return None if b"\0" in data: - return 0 + return None if not data: return 0 return data.count(b"\n") + (0 if data.endswith(b"\n") else 1) diff --git a/pyproject.toml b/pyproject.toml index e882fcc..2e18835 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "cptr" -version = "0.8.6" +version = "0.8.7" description = "Your computer, from anywhere. Code, manage, and control your machine from the web." license = {file = "LICENSE"} readme = "README.md" diff --git a/uv.lock b/uv.lock index 6c2ced7..8b650d6 100644 --- a/uv.lock +++ b/uv.lock @@ -284,7 +284,7 @@ wheels = [ [[package]] name = "cptr" -version = "0.8.6" +version = "0.8.7" source = { editable = "." } dependencies = [ { name = "aiosqlite" },