feat: chips travel as span records, not mark embeds
android / debug (push) Successful in 2m19s
android / release (push) Successful in 3m0s
ci / checks (push) Successful in 1m11s
ci / test (push) Successful in 38s
ci / chart (push) Successful in 5s
ci / docker (push) Successful in 1m27s
ci / web (push) Successful in 13s
ci / publish-edge-images (deploy/docker/claw.Dockerfile, rhema-claw) (push) Successful in 1m30s
ci / publish-edge-images (deploy/docker/ui.Dockerfile, rhema-claw-ui) (push) Successful in 14s
ci / publish-edge-chart (push) Successful in 4s
android / debug (push) Successful in 2m19s
android / release (push) Successful in 3m0s
ci / checks (push) Successful in 1m11s
ci / test (push) Successful in 38s
ci / chart (push) Successful in 5s
ci / docker (push) Successful in 1m27s
ci / web (push) Successful in 13s
ci / publish-edge-images (deploy/docker/claw.Dockerfile, rhema-claw) (push) Successful in 1m30s
ci / publish-edge-images (deploy/docker/ui.Dockerfile, rhema-claw-ui) (push) Successful in 14s
ci / publish-edge-chart (push) Successful in 4s
The claw's wire carried chips only as U+FFFC-payload-U+FFFC marks written into the text — the very encoding 0.4.0's fold migrated at the provider seam. Now the record rhema-core defined is the wire's own: a message's pasted payloads ride the POST body's `pastes` array beside the plain draft, the fold composes the plain form and measures each chip's PasteSpan, and the `user_message` echo carries text plus `pastes` — the session annotation's own shape — while the turn's question carries the span note into the checkpoint, shifted by the exact bytes any framing prefix adds. The web client mints and renders the new record: the composer sends draft and payloads separately, the optimistic row composes the same plain text and spans the fold will record (so the echo dedupes), and the render slices the text at the record's byte offsets. Rows recorded before spans arrived still parse the mark form — as does every arrival that still mints it, including every surface the shim or an older client feeds. The phone is one of those: it parses chips by scanning marks, and kotlinx ignores the new field, so it reads spans-less rows exactly as before; adopting span records for its own rows is a follow-up.
This commit is contained in:
1 parent
df260fd9a8
commit
c5bf168eed
12 files changed
+484
-108
No files matched your search
@@ -6,7 +6,7 @@
|
||||
// mirror when the stream reopens and folds what arrives, never the other
|
||||
// way around.
|
||||
import { ref } from 'vue'
|
||||
import type { AttachmentMedia, ConsentKind, OutboundImage, TurnEvent } from './useClaw'
|
||||
import type { AttachmentMedia, ConsentKind, OutboundImage, PasteSpan, TurnEvent } from './useClaw'
|
||||
|
||||
/** One tool call inside a turn: started, then completed by its result. */
|
||||
export interface ToolRow {
|
||||
@@ -89,7 +89,7 @@ export interface StagedImage extends OutboundImage {
|
||||
|
||||
/** A transcript line: a message the local user sent, or one streamed turn. */
|
||||
export type TranscriptItem =
|
||||
| { kind: 'sent'; id: number; text: string; images: SentImage[] }
|
||||
| { kind: 'sent'; id: number; text: string; images: SentImage[]; pastes: PasteSpan[] }
|
||||
| { kind: 'turn'; id: number; turn: TurnBlock }
|
||||
| { kind: 'consent'; id: number; consent: ConsentCard }
|
||||
| { kind: 'attachment'; id: number; attachment: AttachmentCard }
|
||||
@@ -123,20 +123,53 @@ export function lineCount(text: string): number {
|
||||
return lines.length
|
||||
}
|
||||
|
||||
/** A chip's label: `▣1 5L` — the anchor's one-based id and the
|
||||
* payload's line count (the TUI's chip_label). */
|
||||
export function chipLabel(paste: string, index: number): string {
|
||||
return `▣${index + 1} ${lineCount(paste)}L`
|
||||
/** A chip's label from its line count: `▣1 5L` — the chip's
|
||||
* one-based id and the payload's line count (the TUI's chip_label). */
|
||||
export function chipLinesLabel(lines: number, index: number): string {
|
||||
return `▣${index + 1} ${lines}L`
|
||||
}
|
||||
|
||||
/** Appends each paste as one MARK-payload-MARK embed, in order — the
|
||||
* session's record of the prompt (paste::embed; a web draft holds no
|
||||
* anchors, so every payload lands at the end). */
|
||||
export function embedPastes(draft: string, pastes: string[]): string {
|
||||
return (
|
||||
draft +
|
||||
pastes.map((paste) => `${PASTE_MARK}${normalizePaste(paste)}${PASTE_MARK}`).join('')
|
||||
)
|
||||
/** A chip's label from its payload (the TUI's chip_label). */
|
||||
export function chipLabel(paste: string, index: number): string {
|
||||
return chipLinesLabel(lineCount(paste), index)
|
||||
}
|
||||
|
||||
/** The modern record the wire carries: each paste a byte span in the
|
||||
* plain text (the `rhema-code` annotation's own shape), one walk over
|
||||
* the composed text mapping every code-point boundary — a span that
|
||||
* splits a code point maps to none, the render skips it. */
|
||||
export function byteToIndex(text: string): (byte: number) => number {
|
||||
const at = new Map<number, number>([[0, 0]])
|
||||
const bytesOf = new TextEncoder()
|
||||
let bytes = 0
|
||||
let units = 0
|
||||
for (const cp of text) {
|
||||
bytes += bytesOf.encode(cp).length
|
||||
units += cp.length
|
||||
at.set(bytes, units)
|
||||
}
|
||||
return (byte) => at.get(byte) ?? -1
|
||||
}
|
||||
|
||||
/** Composes a send the way the fold composes its record: each paste's
|
||||
* normalized payload appends to the draft, its chip's span measured
|
||||
* over the composed plain text. The same form the `user_message`
|
||||
* echo carries, so the optimistic row and the replay render rows of
|
||||
* one shape and the echo dedupes against what this surface sent. */
|
||||
export function composeChips(
|
||||
draft: string,
|
||||
pastes: string[],
|
||||
): { text: string; pastes: PasteSpan[] } {
|
||||
const bytesOf = new TextEncoder()
|
||||
let text = draft
|
||||
const spans: PasteSpan[] = []
|
||||
for (const paste of pastes) {
|
||||
const payload = normalizePaste(paste)
|
||||
const start = bytesOf.encode(text).length
|
||||
text += payload
|
||||
spans.push({ start, end: bytesOf.encode(text).length, lines: lineCount(payload) })
|
||||
}
|
||||
return { text, pastes: spans }
|
||||
}
|
||||
|
||||
/** One scanned piece of embedded-form text. */
|
||||
@@ -244,6 +277,7 @@ export function useTranscript() {
|
||||
id: nextId++,
|
||||
text: event.text,
|
||||
images: event.images.map((image) => ({ ...image, url: null, name: null })),
|
||||
pastes: event.pastes,
|
||||
})
|
||||
break
|
||||
}
|
||||
@@ -356,10 +390,10 @@ export function useTranscript() {
|
||||
* Its images render from the staged previews — the claw stores them
|
||||
* and the stream's echo dedupes against this row. Returns the row's
|
||||
* id, so a failed POST can retract it. */
|
||||
function addSent(text: string, images: SentImage[] = []): number {
|
||||
function addSent(text: string, images: SentImage[] = [], pastes: PasteSpan[] = []): number {
|
||||
const id = nextId++
|
||||
pendingSent.push({ text, images: images.length, itemId: id })
|
||||
items.value.push({ kind: 'sent', id, text, images })
|
||||
items.value.push({ kind: 'sent', id, text, images, pastes })
|
||||
return id
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user