Files
orca/mobile/src/source-control/mobile-git-status.ts
T
JinjingandOrca a03a3dd51b Render png on mobile (#9087)
* Add mobile image-diff previews via shared data-URI builder

- Extracts a `buildImageDataUri` helper (src/shared/image-data-uri.ts) shared by
  the desktop ImageViewer and mobile, so both trim whitespace-wrapped base64 and
  skip non-previewable mimes (e.g. application/pdf) the same way.
- Adds mobile-diff-image-preview.ts to render binary git.diff results (add/modify/
  delete) as images instead of falling back to "Binary preview unavailable".
- Extracts resolveMobileFileTabDoc to consolidate the session file-tab loading
  logic (diff/image/html/text) out of the route file for testability.

* Fix stale binary image fallback for empty modified diffs and relay reads

- mobileDiffImageDataUri now distinguishes a true deletion (modified
  side absent) from a modify whose binary bytes arrived empty
  (relay/size-cap cases), returning null instead of the stale
  pre-change image
- readWorkingDiffFile passes the file path to bufferToBlob so relay
  working-tree reads can detect previewable image extensions instead
  of always reporting empty binary content
- add mobile-file-tab-doc.test.ts covering diff/image/binary/text
  resolution paths

* Regenerate skill bundle manifest for 1.4.144-rc.2

Co-authored-by: Orca <help@stably.ai>

* fix(review): trim comments to AGENTS.md's one/two-line why-only rule

Comments in mobile-diff-image-preview.ts and mobile-file-tab-doc.ts ran
3-6 lines and narrated mechanism instead of stating only the non-obvious
reason, per AGENTS.md's "Code Comments: Document the Why, Briefly" rule.

Co-authored-by: Orca <help@stably.ai>

* Distinguish read failures from true deletions in binary diff results

- Working-tree stat/readFile errors and relay reads previously collapsed
  onto the same empty-content signal as a genuine deletion, letting
  previewers fall back to stale original bytes on a failed read.
- Add modifiedDeleted/missing flags through status.ts, git-handler-ops,
  and git-working-file-read so only proven deletions trigger the
  original-bytes fallback; failed reads now return null.
- Tighten buildImageDataUri to accept only image/* mimes instead of
  special-casing application/pdf.

* fix(relay): expect missing:false on index blob maxBuffer overflow

readBlobAtIndex now returns a missing flag so staged deletions are
distinct from size-capped binary reads; update the overflow test.

* Allow opening deleted files to show pre-delete text or image diffs

Deleted files can now be opened to view their pre-delete content via
git.diff (including images via modifiedDeleted). Only unresolved conflicts
remain unopenable. Centralizes the canOpen rule in canOpenMobileGitStatusEntry()
to keep opener guards consistent across the mobile source control UI.

---------

Co-authored-by: Orca <help@stably.ai>
2026-07-16 18:21:08 -07:00

114 lines
3.6 KiB
TypeScript

import type {
GitFileStatus,
GitStagingArea,
GitStatusEntry,
GitStatusResult,
GitUpstreamStatus
} from '../../../src/shared/git-status-types'
export type MobileGitFileStatus = GitFileStatus
export type MobileGitStagingArea = GitStagingArea
export type MobileGitStatusEntry = GitStatusEntry
export type MobileGitUpstreamStatus = GitUpstreamStatus
export type MobileGitStatusResult = GitStatusResult
export type MobileSourceControlSection<TEntry extends MobileGitStatusEntry = MobileGitStatusEntry> =
{
area: MobileGitStagingArea
title: string
data: TEntry[]
}
const AREA_ORDER: MobileGitStagingArea[] = ['unstaged', 'untracked', 'staged']
const AREA_TITLES: Record<MobileGitStagingArea, string> = {
unstaged: 'Changes',
untracked: 'Untracked Files',
staged: 'Staged Changes'
}
export const MOBILE_GIT_STATUS_LABELS: Record<MobileGitFileStatus, string> = {
modified: 'M',
added: 'A',
deleted: 'D',
renamed: 'R',
untracked: 'U',
copied: 'C'
}
function compareGitStatusEntries(a: MobileGitStatusEntry, b: MobileGitStatusEntry): number {
return (
getConflictSortRank(a) - getConflictSortRank(b) ||
a.path.localeCompare(b.path, undefined, { numeric: true })
)
}
function getConflictSortRank(entry: MobileGitStatusEntry): number {
if (entry.conflictStatus === 'unresolved') {
return 0
}
if (entry.conflictStatus === 'resolved_locally') {
return 1
}
return 2
}
export function buildMobileSourceControlSections<TEntry extends MobileGitStatusEntry>(
entries: readonly TEntry[]
): MobileSourceControlSection<TEntry>[] {
return AREA_ORDER.map((area) => ({
area,
title: AREA_TITLES[area],
data: entries.filter((entry) => entry.area === area).sort(compareGitStatusEntries)
})).filter((section) => section.data.length > 0)
}
export function countStagedEntries(entries: readonly MobileGitStatusEntry[]): number {
return entries.filter((entry) => entry.area === 'staged').length
}
export function countUnstagedEntries(entries: readonly MobileGitStatusEntry[]): number {
return entries.filter((entry) => entry.area === 'unstaged' || entry.area === 'untracked').length
}
export function getStageablePaths(entries: readonly MobileGitStatusEntry[]): string[] {
return entries.filter(isMobileGitStageableEntry).map((entry) => entry.path)
}
export function getUnstageablePaths(entries: readonly MobileGitStatusEntry[]): string[] {
return entries.filter((entry) => entry.area === 'staged').map((entry) => entry.path)
}
export function isMobileGitStageableEntry(entry: MobileGitStatusEntry): boolean {
return (
(entry.area === 'unstaged' || entry.area === 'untracked') &&
entry.conflictStatus !== 'unresolved'
)
}
export function isMobileGitDiscardableEntry(entry: MobileGitStatusEntry): boolean {
return entry.conflictStatus !== 'unresolved' && entry.conflictStatus !== 'resolved_locally'
}
// Why: unresolved conflicts are not a stable file to open. Deletions are —
// git.diff still returns the pre-delete side (text or image via modifiedDeleted).
export function canOpenMobileGitStatusEntry(entry: MobileGitStatusEntry): boolean {
return entry.conflictStatus !== 'unresolved'
}
export function isMobileGitUnavailable(code: string | undefined, message: string | undefined) {
return (
code === 'forbidden' ||
code === 'method_not_found' ||
message?.includes('not available to mobile clients') === true
)
}
export function isMobileGitTransientRefreshError(
code: string | undefined,
message: string | undefined
) {
const normalized = message?.trim().toLowerCase()
return code === 'request_aborted' || normalized === 'aborting' || normalized === 'request_aborted'
}