mirror of
https://github.com/stablyai/orca.git
synced 2026-09-24 00:02:24 +00:00
* docs: design SSH relay PTY backpressure * fix(ssh): bound relay frame decoding * fix(relay): bound PTY output publication * fix(ssh): bound PTY model admission * fix(ssh): settle closed model admissions * feat(ssh): negotiate bounded PTY consumer sessions * fix(ssh): fence exit on renderer settlement * feat(ssh): track PTY source credit end to end * fix(ssh): recover bounded PTY output across reconnect * feat(ssh): complete relay PTY output backpressure * fix(ssh): close final PTY source credit races * docs(ssh): record final backpressure validation * feat(ssh): complete relay PTY source-credit lifecycle * test(ssh): complete provider notification fixture * fix(ssh): preserve terminal source credit across rotation * fix(ssh): fail closed on recovery cancellation * fix(ssh): prioritize mux control writes after drain * fix(ssh): retire canceled relay restore deliveries * fix(ssh): order exit cancellation cleanup * fix(ssh): gate provisional source activation * test(ssh): register mux drain-priority coverage * fix(ssh): type stale owner recovery mismatches * fix(ssh): close projection replacement races * fix(relay): contain streaming edge failures * fix(ssh): secure relay endpoint credentials * docs(ssh): reconcile final backpressure lifecycle * fix(ssh): bound main IPC output lifecycle * fix(ssh): close recovery ownership gaps * docs(ssh): record exact artifact validation * fix(ssh): reject reclaimed snapshot replacements * fix(ssh): fence model admission across reconnect * fix(ssh): contain migration failure per PTY * docs(ssh): record final exact-head validation * test(ssh): align deploy fixtures with credential publication * feat(ssh): add per-target bounded output setting * fix(ssh): close source recovery review gaps * fix(ssh): latch source credit environment override * feat(ssh): make PTY source credit the default * docs(ssh): record always-on relay validation * docs(ssh): bind validation to current main * test(ssh): grant source credit in IPC fixture * test(ssh): grant source credit in fake relay --------- Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
85 lines
1.9 KiB
TypeScript
85 lines
1.9 KiB
TypeScript
export class RelayFrameBuffer {
|
|
private chunks: Buffer[] = []
|
|
private bytes = 0
|
|
|
|
get length(): number {
|
|
return this.bytes
|
|
}
|
|
|
|
append(chunk: Buffer): void {
|
|
this.chunks.push(chunk)
|
|
this.bytes += chunk.length
|
|
}
|
|
|
|
clear(): void {
|
|
this.chunks = []
|
|
this.bytes = 0
|
|
}
|
|
|
|
drain(): Buffer {
|
|
const out = this.chunks.length === 1 ? this.chunks[0] : Buffer.concat(this.chunks, this.bytes)
|
|
this.clear()
|
|
return out
|
|
}
|
|
|
|
peek(count: number): Buffer {
|
|
const first = this.chunks[0]
|
|
if (first.length >= count) {
|
|
return first
|
|
}
|
|
const out = Buffer.allocUnsafe(count)
|
|
let copied = 0
|
|
for (const part of this.chunks) {
|
|
copied += part.copy(out, copied, 0, Math.min(part.length, count - copied))
|
|
if (copied >= count) {
|
|
break
|
|
}
|
|
}
|
|
return out
|
|
}
|
|
|
|
take(count: number): Buffer {
|
|
const first = this.chunks[0]
|
|
if (first.length === count) {
|
|
this.chunks.shift()
|
|
this.bytes -= count
|
|
return first
|
|
}
|
|
if (first.length > count) {
|
|
this.chunks[0] = first.subarray(count)
|
|
this.bytes -= count
|
|
return first.subarray(0, count)
|
|
}
|
|
const out = Buffer.allocUnsafe(count)
|
|
let copied = 0
|
|
while (copied < count) {
|
|
const part = this.chunks[0]
|
|
const take = Math.min(part.length, count - copied)
|
|
part.copy(out, copied, 0, take)
|
|
copied += take
|
|
if (take === part.length) {
|
|
this.chunks.shift()
|
|
} else {
|
|
this.chunks[0] = part.subarray(take)
|
|
}
|
|
}
|
|
this.bytes -= count
|
|
return out
|
|
}
|
|
|
|
discard(count: number): void {
|
|
let remaining = count
|
|
while (remaining > 0) {
|
|
const part = this.chunks[0]
|
|
if (part.length <= remaining) {
|
|
this.chunks.shift()
|
|
remaining -= part.length
|
|
} else {
|
|
this.chunks[0] = part.subarray(remaining)
|
|
remaining = 0
|
|
}
|
|
}
|
|
this.bytes -= count
|
|
}
|
|
}
|