Files
orca/mobile/src/session/QuickCommandsList.tsx
T
Neil 77f23b013f refactor(shared): drop the shared/types barrel and import from the real modules (#14447)
#14397 split `shared/types.ts` into 46 per-domain modules but kept the path as
a re-export barrel so the import sites did not have to change. This removes
the barrel: every consumer now imports from the module that actually declares
the type, and `src/shared/types.ts` is deleted.

Barrels hide where a type lives, make every consumer look like it depends on
the whole domain, and let an unrelated edit invalidate a module that ~2,000
files transitively import.

2,323 import declarations across 2,321 files. Rewritten mechanically: each
specifier was resolved to an absolute path via the TypeScript AST and
recomputed, rather than string-substituted, so alias forms (`@/../../shared/
types`) and per-specifier `type` modifiers survive.

Four cases the mechanical pass had to handle, each found by a gate rather than
by reading the diff:

- Modules inside `src/shared` import the barrel as `./types`, not
  `shared/types`. A pre-filter on the latter string skipped 176 of them and
  left imports dangling at a deleted file, which surfaced as confusing
  `Property 'x' is optional in type 'Repo' but required in Pick<Repo, ...>`
  errors rather than "module not found".
- The barrel RENAMED one type on the way through
  (`WorkspaceSource as WorkspaceCreateTelemetrySource`), so the original name
  in the owning module has to be re-aliased at each consumer.
- Three test files put `;(globalThis as ...)` on the line after the import.
  TypeScript parses that `;` as the import statement's terminator, so
  replacing through `statement.getEnd()` deletes it and breaks ASI. The
  rewrite now stops at the module specifier.
- A file that already imported directly from a module got a SECOND import
  from it, because the barrel re-exported those same names — which trips
  `import/no-duplicates` under `--deny-warnings`. A post-pass merges
  declarations sharing a specifier and type-only-ness; the `import type` plus
  `import` pair from one module is left alone, since that form is allowed.

Splitting one barrel import into several genuinely adds lines, which pushed
`terminal-layout-pty-ownership.ts` to 301 counted lines: its 107-character
import must wrap, and neither local type collapses onto one line (101 and 116
characters). Rather than contort a type declaration to fit a line budget,
`collectLeafIds` and `pruneLeaves` move to `terminal-pane-layout-tree.ts` —
they are pure structural operations on the layout tree and independent of PTY
ownership. `visible-worktrees.ts` similarly loses its own mini-barrel
re-export of `isDefaultBranchWorkspace`, with the four real consumers
repointed at the declaring module. No `max-lines` bypass added.

Verified: cold `tsc --noEmit` green on node, cli, and web (buildinfo deleted
first — these projects are `composite: true` and reuse stale caches); the full
`pnpm lint` green, not just bare oxlint — the narrower local check is what let
the duplicate imports reach CI; max-lines ratchet OK at 344.
2026-08-13 22:48:24 -07:00

256 lines
7.4 KiB
TypeScript

import { View, Text, Pressable, TextInput, StyleSheet, ActivityIndicator } from 'react-native'
import { Check, Plus, Search } from 'lucide-react-native'
import { colors, spacing } from '../theme/mobile-theme'
import { MobileAgentIcon } from '../components/MobileAgentIcon'
import { MOBILE_AGENT_CATALOG } from '../tasks/mobile-agent-catalog'
import type { TerminalQuickCommand } from '../../../src/shared/terminal-quick-command-types'
import type { TuiAgent } from '../../../src/shared/tui-agent'
import { supportsTerminalAgentQuickCommand } from '../terminal/quick-commands'
import { QuickCommandRow } from './QuickCommandRow'
export const QUICK_COMMAND_SUPPORTED_AGENTS = MOBILE_AGENT_CATALOG.filter((entry) =>
supportsTerminalAgentQuickCommand(entry.id)
)
export const QUICK_COMMAND_SEARCH_QUERY_MAX_LENGTH = 2048
type ListProps = {
repoCommands: TerminalQuickCommand[]
globalCommands: TerminalQuickCommand[]
totalCount: number
query: string
loading: boolean
disabled: boolean
canAdd: boolean
error: string | null
onQueryChange: (value: string) => void
onLaunch: (command: TerminalQuickCommand) => void
onEdit: (command: TerminalQuickCommand) => void
onDelete: (command: TerminalQuickCommand) => void
onAdd: () => void
}
export function QuickCommandsList({
repoCommands,
globalCommands,
totalCount,
query,
loading,
disabled,
canAdd,
error,
onQueryChange,
onLaunch,
onEdit,
onDelete,
onAdd
}: ListProps) {
const hasVisible = repoCommands.length + globalCommands.length > 0
const addDisabled = disabled || !canAdd
// Why: keep an active filter clearable if a delete or paired desktop edit
// leaves only one command while the sheet is open.
const showSearch = totalCount > 1 || query.length > 0
return (
<View style={styles.listBody}>
{showSearch ? (
<View style={styles.search}>
<Search size={16} color={colors.textMuted} />
<TextInput
style={styles.searchInput}
value={query}
onChangeText={onQueryChange}
placeholder="Search quick commands..."
placeholderTextColor={colors.textMuted}
autoCapitalize="none"
autoCorrect={false}
// Why: bound pasted text before it reaches the per-keystroke JS
// search path; useful queries are far smaller than this budget.
maxLength={QUICK_COMMAND_SEARCH_QUERY_MAX_LENGTH}
/>
</View>
) : null}
{error ? <Text style={styles.error}>{error}</Text> : null}
{loading && !hasVisible ? (
<ActivityIndicator style={styles.loading} color={colors.textSecondary} />
) : null}
{!loading && totalCount === 0 ? (
<Text style={styles.empty}>No quick commands yet.</Text>
) : null}
{!loading && totalCount > 0 && !hasVisible ? (
<Text style={styles.empty}>No matching quick commands.</Text>
) : null}
{repoCommands.length > 0 ? (
<QuickCommandGroup
label="This project"
commands={repoCommands}
onLaunch={onLaunch}
onEdit={onEdit}
onDelete={onDelete}
disabled={disabled}
/>
) : null}
{globalCommands.length > 0 ? (
<QuickCommandGroup
label="Global"
commands={globalCommands}
onLaunch={onLaunch}
onEdit={onEdit}
onDelete={onDelete}
disabled={disabled}
/>
) : null}
<Pressable
style={({ pressed }) => [
styles.addRow,
addDisabled && styles.disabled,
pressed && !addDisabled && styles.pressed
]}
disabled={addDisabled}
onPress={onAdd}
accessibilityRole="button"
>
<Plus size={18} color={colors.textSecondary} />
<Text style={styles.addText}>
{canAdd ? 'New quick command' : 'Quick command limit reached'}
</Text>
</Pressable>
</View>
)
}
function QuickCommandGroup({
label,
commands,
onLaunch,
onEdit,
onDelete,
disabled
}: {
label: string
commands: TerminalQuickCommand[]
onLaunch: (command: TerminalQuickCommand) => void
onEdit: (command: TerminalQuickCommand) => void
onDelete: (command: TerminalQuickCommand) => void
disabled: boolean
}) {
return (
<View>
<Text style={styles.groupLabel}>{label}</Text>
<View style={styles.group}>
{commands.map((command, index) => (
<QuickCommandRow
key={command.id}
command={command}
first={index === 0}
onLaunch={onLaunch}
onEdit={onEdit}
onDelete={onDelete}
disabled={disabled}
/>
))}
</View>
</View>
)
}
export function QuickCommandAgentPicker({
selected,
onSelect
}: {
selected: TuiAgent | null
onSelect: (agent: TuiAgent) => void
}) {
return (
<View style={styles.group}>
{QUICK_COMMAND_SUPPORTED_AGENTS.map((agent, index) => (
<Pressable
key={agent.id}
style={({ pressed }) => [
styles.row,
index > 0 && styles.rowBorder,
pressed && styles.pressed
]}
onPress={() => onSelect(agent.id)}
accessibilityRole="button"
accessibilityState={{ selected: selected === agent.id }}
>
<View style={styles.rowIcon}>
<MobileAgentIcon agentId={agent.id} size={16} />
</View>
<Text style={styles.agentLabel}>{agent.label}</Text>
{selected === agent.id ? <Check size={16} color={colors.textPrimary} /> : null}
</Pressable>
))}
</View>
)
}
const styles = StyleSheet.create({
pressed: { backgroundColor: colors.bgRaised },
disabled: { opacity: 0.45 },
listBody: { gap: spacing.sm, paddingBottom: spacing.sm },
search: {
flexDirection: 'row',
alignItems: 'center',
gap: spacing.sm,
backgroundColor: colors.bgPanel,
borderRadius: 8,
borderWidth: 1,
borderColor: colors.borderSubtle,
paddingHorizontal: spacing.md,
paddingVertical: spacing.sm
},
searchInput: { flex: 1, color: colors.textPrimary, fontSize: 14, padding: 0 },
error: { color: colors.statusRed, fontSize: 13, paddingHorizontal: spacing.xs },
loading: { paddingVertical: spacing.lg },
empty: {
color: colors.textMuted,
fontSize: 14,
textAlign: 'center',
paddingVertical: spacing.lg
},
groupLabel: {
fontSize: 11,
fontWeight: '600',
color: colors.textMuted,
textTransform: 'uppercase',
letterSpacing: 0.6,
paddingHorizontal: spacing.xs,
paddingTop: spacing.xs,
paddingBottom: spacing.xs
},
group: { backgroundColor: colors.bgPanel, borderRadius: 12, overflow: 'hidden' },
row: { flexDirection: 'row', alignItems: 'center' },
rowBorder: { borderTopWidth: StyleSheet.hairlineWidth, borderTopColor: colors.borderSubtle },
rowIcon: {
width: 26,
height: 26,
borderRadius: 6,
backgroundColor: colors.bgRaised,
alignItems: 'center',
justifyContent: 'center'
},
agentLabel: { flex: 1, fontSize: 14, color: colors.textPrimary },
addRow: {
flexDirection: 'row',
alignItems: 'center',
gap: spacing.sm,
backgroundColor: colors.bgPanel,
borderRadius: 12,
borderWidth: 1,
borderStyle: 'dashed',
borderColor: colors.borderSubtle,
paddingVertical: spacing.md,
paddingHorizontal: spacing.md,
marginTop: spacing.xs
},
addText: { fontSize: 14, fontWeight: '600', color: colors.textPrimary }
})