mirror of
https://github.com/stablyai/orca.git
synced 2026-11-19 04:23:57 +00:00
The PR tab and the Checks and Comments screens refresh by themselves while they are open and the app is in the foreground, on desktop's checks-panel cadence (policy moved to src/shared). A failed background read keeps the PR on screen and backs off instead of replacing it with an error. Review threads show the lines they are about: the host forwards the tail of each thread root's diff hunk, and mobile numbers it back from the thread's line. Bot findings get "Ask <agent> to fix", which launches desktop's Resolve comments prompt (moved to src/shared) for that thread. Fix and Ask buttons name the agent that would start.
51 lines
1.7 KiB
TypeScript
51 lines
1.7 KiB
TypeScript
// GitHub ends a review comment's diff hunk on the line the thread is anchored to, so its tail is the code in question.
|
|
|
|
const HUNK_TAIL_LINES = 8
|
|
|
|
/** The hunk's last lines without its @@ header; what the host forwards so phones get the code, not the whole hunk. */
|
|
export function tailDiffHunk(hunk: string | null | undefined): string | undefined {
|
|
if (!hunk) {
|
|
return undefined
|
|
}
|
|
const lines = hunk.split('\n').filter((line) => !line.startsWith('@@'))
|
|
return lines.length > 0 ? lines.slice(-HUNK_TAIL_LINES).join('\n') : undefined
|
|
}
|
|
|
|
export type DiffHunkLine = {
|
|
/** Position in the hunk tail; stable and unique, for list keys. */
|
|
index: number
|
|
number: number | null
|
|
sign: '+' | '-' | ' '
|
|
text: string
|
|
}
|
|
|
|
/**
|
|
* The lines a thread is about (startLine..endLine, or just endLine), numbered back from endLine.
|
|
* Removed lines inside the range show unnumbered; "\ No newline" markers are skipped.
|
|
*/
|
|
export function threadDiffLines(
|
|
hunkTail: string,
|
|
endLine: number,
|
|
startLine?: number
|
|
): DiffHunkLine[] {
|
|
const first = Math.max(startLine ?? endLine, endLine - HUNK_TAIL_LINES + 1)
|
|
const lines = hunkTail.split('\n')
|
|
const out: DiffHunkLine[] = []
|
|
let number = endLine
|
|
for (let index = lines.length - 1; index >= 0 && number >= first; index--) {
|
|
const raw = lines[index]
|
|
if (raw.startsWith('\\')) {
|
|
continue
|
|
}
|
|
const sign = raw.startsWith('+') ? '+' : raw.startsWith('-') ? '-' : ' '
|
|
const text = sign === ' ' && !raw.startsWith(' ') ? raw : raw.slice(1)
|
|
if (sign === '-') {
|
|
out.unshift({ index, number: null, sign, text })
|
|
continue
|
|
}
|
|
out.unshift({ index, number, sign, text })
|
|
number -= 1
|
|
}
|
|
return out
|
|
}
|