Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions .github/workflows/mobile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,30 @@ on:
- 'config/tsconfig.node.json'
- 'src/types/build-constants.d.ts'
- 'src/main/native-chat/agent-session-wire/**'
# Recorded phone transcripts exercise these host decoders and their runtime dependencies.
- 'src/main/native-chat/*transcript*.ts'
- 'src/main/native-chat/subagent-entry-id-bounds.ts'
- 'src/main/native-chat/agent-session-journal/journal-payload-bounds.ts'
- 'src/main/native-chat/agent-session-journal/journal-reasoning-row.ts'
- 'src/main/claude/claude-internal-message-content.ts'
- 'src/main/claude/claude-stop-hook-feedback.ts'
- 'src/main/claude/structured/journal/**'
- 'src/main/claude/__fixtures__/claude-adapter-capture-fold.jsonl'
- 'src/main/codex/app-server/codex-item-field-readers.ts'
- 'src/main/codex/structured/items/**'
- 'src/main/codex/structured/background-work/codex-subagent-activity.ts'
- 'src/main/codex/structured/journal/codex-goal-journal-rows.ts'
- 'src/main/codex/__fixtures__/codex-hook-outcomes.jsonl'
- 'src/main/ai-vault/session-scanner-*.ts'
- 'src/main/ai-vault/ai-vault-scan-cancellation.ts'
- 'src/main/ai-vault/scan-service/session-scanner-service-env.ts'
- 'src/main/ai-vault/scanners/grok/session-scanner-grok-user-text.ts'
- 'src/main/provider-process/provider-json-record.ts'
- 'src/main/providers/ssh-host-not-served-error.ts'
- 'src/main/wsl/discovery/**'
- 'src/main/wsl/execution/wsl-exe-process.ts'
- 'src/main/wsl/execution/wsl-interop-spawn-directory.ts'
- 'src/main/wsl/filesystem/wsl-unc-access-gate.ts'
- 'src/main/runtime/structured-attention-original-delivery.test-fixture.ts'
# Rerun the only Fastfile-loading checks for release-workflow/Fastfile edits.
- '.github/workflows/mobile.yml'
Expand Down Expand Up @@ -103,6 +127,30 @@ on:
- 'config/tsconfig.node.json'
- 'src/types/build-constants.d.ts'
- 'src/main/native-chat/agent-session-wire/**'
# Recorded phone transcripts exercise these host decoders and their runtime dependencies.
- 'src/main/native-chat/*transcript*.ts'
- 'src/main/native-chat/subagent-entry-id-bounds.ts'
- 'src/main/native-chat/agent-session-journal/journal-payload-bounds.ts'
- 'src/main/native-chat/agent-session-journal/journal-reasoning-row.ts'
- 'src/main/claude/claude-internal-message-content.ts'
- 'src/main/claude/claude-stop-hook-feedback.ts'
- 'src/main/claude/structured/journal/**'
- 'src/main/claude/__fixtures__/claude-adapter-capture-fold.jsonl'
- 'src/main/codex/app-server/codex-item-field-readers.ts'
- 'src/main/codex/structured/items/**'
- 'src/main/codex/structured/background-work/codex-subagent-activity.ts'
- 'src/main/codex/structured/journal/codex-goal-journal-rows.ts'
- 'src/main/codex/__fixtures__/codex-hook-outcomes.jsonl'
- 'src/main/ai-vault/session-scanner-*.ts'
- 'src/main/ai-vault/ai-vault-scan-cancellation.ts'
- 'src/main/ai-vault/scan-service/session-scanner-service-env.ts'
- 'src/main/ai-vault/scanners/grok/session-scanner-grok-user-text.ts'
- 'src/main/provider-process/provider-json-record.ts'
- 'src/main/providers/ssh-host-not-served-error.ts'
- 'src/main/wsl/discovery/**'
- 'src/main/wsl/execution/wsl-exe-process.ts'
- 'src/main/wsl/execution/wsl-interop-spawn-directory.ts'
- 'src/main/wsl/filesystem/wsl-unc-access-gate.ts'
- 'src/main/runtime/structured-attention-original-delivery.test-fixture.ts'
- '.github/workflows/mobile.yml'
- 'config/mobile-ci.vitest.config.mjs'
Expand Down
5 changes: 4 additions & 1 deletion config/tsconfig.test.mobile-host-declarations.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
"../src/main/runtime/rpc/dispatcher-request-parsing.ts",
"../src/main/github/issue-field-options.ts",
"../src/main/runtime/workspaces/process-listing/runtime-worktree-ps-summaries.ts",
"../src/types/build-constants.d.ts"
"../src/types/build-constants.d.ts",
"../src/main/native-chat/transcript-line-decoders-claude.ts",
"../src/main/codex/structured/items/codex-thread-item-identity.ts",
"../src/main/codex/structured/items/codex-structured-item-translation.ts"
],
"include": ["../src/shared/**/*.ts", "../src/shared/**/*.tsx"],
"exclude": [
Expand Down
4 changes: 4 additions & 0 deletions mobile/scripts/check-tests-typecheck-ratchet.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ const ERROR_LINE = /^(\S.*?)\(\d+,\d+\): error TS\d+:/
// Tests outside the RN program. Checked transfers are the roots of tsconfig.test.node.json and must pass
// that strict program; the rest are legacy runtime-only allowances whose bodies nothing typechecks.
export const TESTS_OUTSIDE_PROGRAM = new Map([
[
'src/session/native-chat/transcript/mobile-native-chat-recorded-projection.test.ts',
'Checked transfer: strict Node program over emitted phone/host declarations (tsconfig.test.node.json)'
],
[
'src/components/WorktreeAgentList.runtime-lineage.test.tsx',
'Legacy runtime-only: the test body is not typechecked anywhere; it imports the desktop SQLite assignment projection, which does not check against RN libs, and its implementation sources keep their normal checks'
Expand Down
12 changes: 7 additions & 5 deletions mobile/src/session/native-chat/MobileNativeChatOverlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { MobileQueuedMessageComposerContext } from '../mobile-queued-message-com
import { useCallback, useLayoutEffect, useMemo, useRef } from 'react'
import { StyleSheet, View } from 'react-native'
import { MobileNativeChatView, type MobileNativeChatInputLockReason } from './MobileNativeChatView'
import { foldMobileNativeChatMessages } from './mobile-native-chat-render-data'
import { useMobileNativeChatProjection } from './transcript/use-mobile-native-chat-projection'
import { nativeChatDockedTaskList } from '../../../../src/shared/native-chat/input/native-chat-task-list-state'
import type { MobileNativeChatImageAttachments } from './composer/use-mobile-native-chat-image-attachments'
import type { MobileNativeChatController } from './mobile-native-chat-controller-contract'
Expand Down Expand Up @@ -99,10 +99,12 @@ export function MobileNativeChatOverlay({
session.messages,
controller.nativeChatItemSource
)
const folded = useMemo(
() => foldMobileNativeChatMessages(fullContent.messages, agent),
[fullContent.messages, agent]
)
const folded = useMobileNativeChatProjection(fullContent.messages, agent, [
sendSurfaceId,
sessionId,
controller.nativeChatItemSource?.client,
controller.nativeChatItemSource?.sessionId
])
const taskList = useMemo(() => nativeChatDockedTaskList(folded), [folded])
const streaming = controller.nativeChatStreamingText ?? null
const queued = controller.nativeChatQueued
Expand Down
14 changes: 4 additions & 10 deletions mobile/src/session/native-chat/MobileNativeChatView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ import { MobileNativeChatEmptyStateView } from '../MobileNativeChatEmptyStateVie
import { mobileNativeChatListFooter } from './mobile-native-chat-list-footer'
import { mobileNativeChatListHeader } from './mobile-native-chat-list-header'
import {
buildMobileNativeChatTransientData,
mobileNativeChatEmptyState,
type MobileNativeChatPendingItem
} from './mobile-native-chat-render-data'
import { useMobileNativeChatTransientData } from './transcript/use-mobile-native-chat-transient-data'
import { useMobileNativeChatRowKeys } from './transcript/mobile-native-chat-row-keys'
import { useMobileNativeChatPinchGesture } from './transcript/use-mobile-native-chat-pinch-gesture'
import { useMobileNativeChatTailFollow } from './transcript/use-mobile-native-chat-tail-follow'
Expand Down Expand Up @@ -217,15 +217,9 @@ export function MobileNativeChatView({
const bottomPad = keyboardInset > 0 ? keyboardInset + insets.bottom : insets.bottom
const { fontScale, pinchGesture } = useMobileNativeChatPinchGesture()

const { data } = useMemo(
() =>
buildMobileNativeChatTransientData({
folded,
streaming,
pending,
imagePreviewsByMessageId
}),
[folded, streaming, pending, imagePreviewsByMessageId]
const data = useMobileNativeChatTransientData(
{ folded, streaming, pending, imagePreviewsByMessageId },
sendSurfaceId
)
const tail = useMobileNativeChatTailFollow({ hasItems: data.length > 0, scopeKey: sendSurfaceId })
const { jumpToTail, recordScrollMetrics, scrollMayLoadEarlier } = tail
Expand Down
49 changes: 32 additions & 17 deletions mobile/src/session/native-chat/mobile-native-chat-render-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
type NativeChatMessage
} from '../../../../src/shared/native-chat/native-chat-types'
import type { AgentType } from '../../../../src/shared/agent-status/contracts/agent-status-types'
import type { MobileNativeChatStatus } from './use-mobile-native-chat-session'
import type { MobileNativeChatStatus } from './mobile-native-chat-session-status'
import { orderNativeChatDisplayMessages } from '../../../../src/shared/native-chat/transcript/native-chat-message-order'
import { translate } from '../../i18n/mobile-i18n'

Expand Down Expand Up @@ -99,22 +99,37 @@ export function foldMobileNativeChatMessages(
messages: readonly NativeChatMessage[],
agent: AgentType
): NativeChatMessage[] {
// Filter child/noise rows before folding so they cannot split tool runs; project plan updates afterward so they cannot consume another call’s result.
return projectNativeChatTaskListFrames(
stripNoiseMessages(
foldToolMessages(
foldSubagentItems(
prepareNativeChatMessages(
messages.filter(
(message) =>
isRootAgentJournalItem(message) && !isUndrawnProviderFrameMessage(message)
),
agent
)
)
)
)
).filter((message) => !isWordlessProviderFrameMessage(message))
return finishMobileNativeChatMessages(
foldToolMessages(foldSubagentItems(prepareMobileNativeChatMessages(messages, agent)))
)
}

export function isMobileNativeChatSource(message: NativeChatMessage): boolean {
return isRootAgentJournalItem(message) && !isUndrawnProviderFrameMessage(message)
}

export function prepareMobileNativeChatMessages(
messages: readonly NativeChatMessage[],
agent: AgentType,
recordSource?: (message: NativeChatMessage, visible: boolean) => void
): NativeChatMessage[] {
return prepareNativeChatMessages(
messages.filter((message) => {
const visible = isMobileNativeChatSource(message)
recordSource?.(message, visible)
return visible
}),
agent
)
}

export function finishMobileNativeChatMessages(
messages: readonly NativeChatMessage[]
): NativeChatMessage[] {
// Plan frames must not consume another call's result.
return projectNativeChatTaskListFrames(stripNoiseMessages(messages)).filter(
(message) => !isWordlessProviderFrameMessage(message)
)
}

export function buildMobileNativeChatTransientData({
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export type MobileNativeChatStatus =
| 'idle'
| 'loading'
| 'waiting-session'
// No transcript file yet: render the empty chat while keeping its read unsettled.
| 'awaiting-transcript'
| 'ready'
| 'error'
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import type { NativeChatMessage } from '../../../../../src/shared/native-chat/native-chat-types'
import {
foldToolMessages,
type NativeChatToolFoldKind
} from '../../../../../src/shared/native-chat/tools/native-chat-tool-fold'
import {
orphanRowId,
type NativeChatOrphanOrigin
} from '../../../../../src/shared/native-chat/tools/native-chat-folded-tool-results'
import { finishMobileNativeChatMessages } from '../mobile-native-chat-render-data'

export type Unit = {
sources: readonly NativeChatMessage[]
rows: NativeChatMessage[]
orphans: readonly NativeChatOrphanOrigin[]
}

export function buildMobileNativeChatUnits(
grouped: readonly NativeChatMessage[],
kinds: ReadonlyMap<NativeChatMessage, NativeChatToolFoldKind>,
previous?: { units: readonly Unit[] }
): Unit[] {
const members: NativeChatMessage[][] = []
let active = false
for (const source of grouped) {
const kind = kinds.get(source)!
if (active && (kind === 'tool' || kind === 'sidecar' || kind === 'pass')) {
members.at(-1)!.push(source)
} else {
members.push([source])
active = source.role === 'assistant' && kind !== 'orphan'
}
}
const ids = new Set(grouped.map((row) => row.id))
const oldUnits = new Map(previous?.units.map((unit) => [unit.sources[0]!.id, unit]))
const units = members.map((sources): Unit => {
const before = oldUnits.get(sources[0]!.id)
if (
before &&
before.sources.length === sources.length &&
before.sources.every((source, index) => source === sources[index])
) {
return before
}
const substituted = before && substituteProse(before, sources, kinds)
const orphans: NativeChatOrphanOrigin[] = []
const rows =
substituted ??
finishMobileNativeChatMessages(
foldToolMessages(sources, ids, kinds, (origin) => orphans.push(origin))
)
return { sources, rows, orphans: substituted ? before!.orphans : orphans }
})
const allocated = new Set(ids)
const occurrences = new Map<string, number>()
return units.map((unit) => {
const renamed = new Map<NativeChatMessage, NativeChatMessage>()
const orphans = unit.orphans.map((origin) => {
const id = orphanRowId(origin.sourceId, allocated, occurrences)
allocated.add(id)
if (id === origin.row.id) {
return origin
}
const row = { ...origin.row, id }
renamed.set(origin.row, row)
return { ...origin, row }
})
return renamed.size === 0
? unit
: {
...unit,
orphans,
rows: unit.rows.map((row) => renamed.get(row) ?? row)
}
})
}

function substituteProse(
before: Unit,
sources: readonly NativeChatMessage[],
kinds: ReadonlyMap<NativeChatMessage, NativeChatToolFoldKind>
): NativeChatMessage[] | null {
if (before.sources.length !== sources.length) {
return null
}
const changed = sources.flatMap((source, index) =>
source === before.sources[index] ? [] : [index]
)
if (changed.length !== 1 || changed[0] !== 0) {
return null
}
const old = before.sources[0]!,
next = sources[0]!
if (
old.role !== next.role ||
(next.role !== 'assistant' && next.role !== 'reasoning') ||
old.unpairedToolResults ||
next.unpairedToolResults ||
!old.blocks.every((block) => block.type === 'text' && !block.providerFrame) ||
!next.blocks.every((block) => block.type === 'text' && !block.providerFrame)
) {
return null
}
const target = before.rows.find((row) => row.id === old.id && row.role === old.role)
if (!target || !old.blocks.every((block, index) => block === target.blocks[index])) {
return null
}
const contribution = sources
.slice(1)
.findLast(
(source) =>
source.journalPosition && (kinds.get(source) === 'tool' || kinds.get(source) === 'sidecar')
)
const replacement: NativeChatMessage = {
...next,
blocks: [...next.blocks, ...target.blocks.slice(old.blocks.length)],
...(contribution ? { foldedJournalPosition: contribution.journalPosition } : {})
}
return before.rows.map((row) => (row === target ? replacement : row))
}
Loading
Loading