feat(ios): search message content and jump to the matched message

Port the H5 content-search scope to the native session list:

- The search field gains a Sessions/Content scope menu. Content mode
  debounces the hub's POST /sessions/content-search over the sessions
  visible under the current machine/status/unread filters, discards stale
  responses by generation, and surfaces loading, failure, and
  potentially-incomplete result states.
- Result rows keep the two-line contract: the matched snippet (plus a
  truncation mark) replaces the project line, while server relevance
  order is preserved.
- Tapping a hit passes its message id to the chat. A row already in the
  loaded transcript scrolls directly; otherwise the window controller
  loads the hub's bounded message-context page, enters history mode, and
  the chat scrolls/flashes the target. "Back to latest" still resets to
  the live tail because a context window is explicitly not the tail.

Adds content-search wire models, endpoint coverage, context-window
transition tests, and session-list model tests for scoping and rendering.

via [HAPI](https://hapi.run)

Co-Authored-By: HAPI <noreply@hapi.run>
Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
2026-12-01 07:22:36 +08:00
co-authored by HAPI Claude Code
parent 563e52b9a0
commit 4387dc7f4a
14 changed files with 873 additions and 70 deletions
@@ -827,6 +827,65 @@ struct MessageWindowControllerTests {
#expect(state.newestPosition == nil)
#expect(state.oldestPosition == MessagePosition(at: 1000, seq: 1))
}
// MARK: - Search jump
@Test func focusMessageReplacesTheWindowWithContextAndEntersHistoryMode() async {
let provider = GatedMessagesProvider()
let initial = warmRecoveryWindow(id: "s", callStatus: "completed")
let controller = MessageWindowController(
sessionId: "s",
provider: provider,
initialState: initial
)
let page = MessageContextPage(
epoch: 1,
nextBeforeSeq: 4,
nextBeforeAt: 4000,
snapshotHeadSeq: 20,
snapshotHeadAt: 20_000,
hasMore: true
)
await provider.releaseContext(MessageContextResponse(
messages: [agentRow(id: "r-4", seq: 4, at: 4000), agentRow(id: "r-5", seq: 5, at: 5000)],
targetMessageId: "r-5",
page: page
))
let focused = await controller.focusMessage("r-5")
#expect(focused)
let contextRequests = await provider.contextRequests
#expect(contextRequests == ["r-5"])
let state = await controller.state
#expect(state.messages.map(\.id) == ["r-4", "r-5"])
#expect(state.viewMode == .history)
#expect(state.epoch == 1)
#expect(state.hasMore)
#expect(state.oldestPosition == MessagePosition(at: 4000, seq: 4))
#expect(state.newestPosition == MessagePosition(at: 20_000, seq: 20))
#expect(state.historyVersion == initial.historyVersion + 1)
#expect(state.syncGeneration == initial.syncGeneration + 1)
#expect(state.requiresLatestReset)
#expect(!state.isSyncingTail)
}
@Test func focusMessageKeepsTheWindowWhenTheTargetNoLongerResolves() async {
let provider = GatedMessagesProvider()
let initial = warmRecoveryWindow(id: "s", callStatus: "completed")
let controller = MessageWindowController(
sessionId: "s",
provider: provider,
initialState: initial
)
await provider.releaseContext(nil)
let focused = await controller.focusMessage("gone")
#expect(!focused)
let state = await controller.state
#expect(state.messages.map(\.id) == initial.messages.map(\.id))
#expect(state.viewMode == .tail)
}
}
// MARK: - Gated transport