Files
orca/mobile/src/session/session-panel-host.ts
T
8f6e44ed53 Show agent session history on mobile (#6786)
* Show agent session history on mobile

Bring the desktop "Agent Session History" panel to Orca Mobile as a
per-worktree screen: browse past agent transcript sessions across the
host with scope tabs (Workspace/Project/All), search, grouping, session
cards, and tap-to-read message previews.

The transcript scan previously ran only over Electron IPC, so mobile
could not reach it. Expose it over the runtime RPC protocol mobile
already speaks (aiVault.listSessions) so the scan runs on whichever host
owns the transcripts — correct for local and SSH/remote hosts. Both the
desktop IPC handler and the new RPC method share one cache, so opening
the desktop panel and the mobile screen never double-scan.

The pure filter/group/display logic is lifted into /shared (the renderer
re-exports it) so the standalone mobile package can reuse it. Mobile
narrows scoped tabs client-side by cwd path-prefix because the host scan
treats scope paths as a widening union.

Resume-from-mobile is intentionally a follow-up.

* Fix mobile agent history list rendering and RPC authorization

- Authorize aiVault.listSessions in the mobile RPC allowlist so the
  mobile client's call is not rejected before dispatch (without this the
  screen could never load sessions at runtime).
- Name each SectionList section's rows `data` (the field React Native
  reads) instead of `cards`, fixing a type error and silent empty-section
  rendering.

* Address review feedback on agent session history

- Match quoted repo:/path: search operator values so labels and paths
  with spaces match (e.g. path:"/Users/ada/My Project").
- Hold a scoped tab in loading until the worktree list resolves instead
  of firing an unscoped fetch that briefly shows unrelated host history;
  proceed once loaded even if the worktree is absent (no stuck spinner).
- Clear cached host capabilities on disconnect/host-switch and failed
  status.get so a capability-gated action can't linger for a host that
  doesn't support it.
- Cover the real OrcaRuntimeService codex-home forwarding path and the
  quoted-operator parser with tests.

* Hide redundant mobile current worktree badges

Co-authored-by: Orca <help@stably.ai>

* Resume agent sessions from mobile history (#6969)

Co-authored-by: Orca <help@stably.ai>

* Adapt merged seams to main's lint and reply-sender hardening

Co-authored-by: Orca <help@stably.ai>

* Cap mobile project-scope paths to the aiVault RPC bound

Co-authored-by: Orca <help@stably.ai>

* Share the aiVault scopePaths bound between the RPC schema and mobile

Co-authored-by: Orca <help@stably.ai>

* Guard shared AI Vault inflight cleanup against concurrent key replacement

The extracted cache module's .finally() cleared inflight tracking
unconditionally, dropping the if (inflightKey === key) guard its sibling
outer cache kept: an older scan resolving after a different-key scan
replaced the tracking would null the newer scan's dedup slot, so a
re-request started a duplicate transcript rescan. Mirrors the sibling
guard; the regression test flushes a macrotask so a reverted guard fails
fast on the call count instead of hanging.

Co-authored-by: Orca <help@stably.ai>

* Harden aiVault.listSessions contract and gate mobile header entry on capability

- Clamp scopePaths (64) instead of rejecting, cap limit at 2000, and make
  executionHostId optional so mobile can omit it; restamp per caller.
- Retain successful mobile terminal-create mutation ids for 60s so resume
  retries dedupe after transient socket drops.
- Gate the session-header Agent History action on the aiVault.v1 capability
  (mirrors the host-list action) so old hosts never show a dead-end entry.
- Fix stale contract comments (scopePaths clamp semantics; filters move
  includes quoted repo:/path: operator parsing).

* Add subagent field to session test fixtures after #7423 merge

AiVaultSession.subagent became required on main; the five fixtures added on
this branch predate it. Top-level scanned sessions carry null.

---------

Co-authored-by: Orca <help@stably.ai>
Co-authored-by: Brennan Benson <brennanbenson@Brennans-MacBook-Pro.local>
2026-07-10 13:48:10 -07:00

76 lines
2.8 KiB
TypeScript

// Pure master-detail panel-host logic for the mobile session screen. No React/native
// imports so the dock-vs-push decision and the active-panel state machine are
// unit-testable under node Vitest (KTD3/R8).
export type ActivePanel = 'sourceControl' | 'files' | 'pr' | null
// Toggle/swap reducer for the wide-layout dock: tapping the active panel closes it,
// tapping any other opens/swaps to it. Exactly one panel docks at a time (R2).
export function nextActivePanel(
current: ActivePanel,
tapped: Exclude<ActivePanel, null>
): ActivePanel {
return tapped === current ? null : tapped
}
export type PanelAction =
| { kind: 'dock'; next: ActivePanel }
| { kind: 'push'; panel: Exclude<ActivePanel, null> }
export const SESSION_DOCK_MIN_MAIN_WIDTH = 360
export function shouldShowSessionHeaderChecksAction(args: {
isFolderWorkspaceRoute: boolean
repoContextLoaded: boolean
hostedChecksSupported: boolean
}): boolean {
// Why: the hosted checks panel is provider-gated and the pr-panel guard
// force-closes it for unsupported providers, so offering the action there
// (or before the provider probe resolves) would be a silent no-op.
return !args.isFolderWorkspaceRoute && args.repoContextLoaded && args.hostedChecksSupported
}
export function canDockSessionPanel(args: {
isWideLayout: boolean
availableWidth: number
dockWidth: number
minMainWidth?: number
}): boolean {
return (
args.isWideLayout &&
args.availableWidth >= args.dockWidth + (args.minMainWidth ?? SESSION_DOCK_MIN_MAIN_WIDTH)
)
}
// Wide layouts dock (toggle/swap the sidebar beside the terminal); narrow layouts
// push the panel's full-screen route (R3/R7). The caller maps a push to the concrete
// expo-router path + params via panelRouteDescriptor.
export function resolvePanelAction(args: {
canDock: boolean
tapped: Exclude<ActivePanel, null>
current: ActivePanel
}): PanelAction {
if (args.canDock) {
return { kind: 'dock', next: nextActivePanel(args.current, args.tapped) }
}
return { kind: 'push', panel: args.tapped }
}
// Single source of truth for each panel's expo-router pathname pattern so narrow-push
// and any deep-linking agree; the caller supplies the [hostId]/[worktreeId] params.
// The Pull Request panel is a segment of the source-control hub, so its narrow-push
// targets that route with `tab: 'pr'` rather than the standalone (redirecting) route.
export function panelRouteDescriptor(panel: Exclude<ActivePanel, null>): {
pathname: string
params?: Record<string, string>
} {
switch (panel) {
case 'sourceControl':
return { pathname: '/h/[hostId]/source-control/[worktreeId]' }
case 'files':
return { pathname: '/h/[hostId]/files/[worktreeId]' }
case 'pr':
return { pathname: '/h/[hostId]/source-control/[worktreeId]', params: { tab: 'pr' } }
}
}