* feat(mobile): add commit failure recovery panel with AI fix action - Surfaces a "Commit failed" panel with a one-tap AI fix button when a git commit fails in the source control view or PR creation flow - Detects commit failures specifically during the committing progress step and captures staged entries and commit message for context - Extracts commit failure summary and prompt logic into `src/shared/source-control-commit-failure.ts` and PR checks prompt into `src/shared/pr-checks-fix-prompt.ts` so both desktop and mobile share the same implementations - Adds auto-find of an available Metro port starting from 8081 and extracts expo CLI bootstrap into `mobile-expo-cli.mjs` shared by `start-emulator` and a new `start-expo.mjs` wrapper * Share source-control AI prompts and simplify mobile PR actions - Extract conflict, check-fixing, and commit-failure prompt builders to shared modules for reuse by both desktop and mobile. - Configure Metro in the mobile package to watch and bundle modules from the repository-root shared directory. - Remove the desktop-style merge method picker from the mobile PR actions panel, opting to use repository defaults automatically. - Refactor mobile hosted review creation and git preparation logic into dedicated helper files.
132 lines
4.2 KiB
TypeScript
132 lines
4.2 KiB
TypeScript
import { useCallback, type MutableRefObject } from 'react'
|
|
import type { RpcClient } from '../transport/rpc-client'
|
|
import { triggerError } from '../platform/haptics'
|
|
import type { MobileGitStatusResult } from './mobile-git-status'
|
|
import type { LoadStatusOptions } from './mobile-source-control-screen-state'
|
|
import {
|
|
getMobileCommitFailureStagedEntries,
|
|
type MobileCommitFailureRecovery,
|
|
type RecordMobileCommitFailure
|
|
} from './mobile-commit-failure-recovery'
|
|
import {
|
|
mobileHostedReviewCreateIntentProgressMessage,
|
|
type MobileHostedReviewCreateIntentProgress
|
|
} from './mobile-hosted-review-create-intent'
|
|
import {
|
|
isMobileHostedReviewCommitFailure,
|
|
runMobileHostedReviewCreateIntent,
|
|
type MobileHostedReviewCreateIntentRunOutcome
|
|
} from './mobile-hosted-review-create-intent-runner'
|
|
|
|
type RunGitWorkflow = (actionId: string, runner: () => Promise<void>) => Promise<boolean>
|
|
type LoadStatus = (options?: LoadStatusOptions) => Promise<boolean>
|
|
|
|
type Params = {
|
|
client: RpcClient | null
|
|
worktreeId: string
|
|
status: MobileGitStatusResult | null
|
|
branchLabel: string
|
|
commitMessage: string
|
|
stagedEntries: MobileCommitFailureRecovery['stagedEntries']
|
|
mountedRef: MutableRefObject<boolean>
|
|
runGitWorkflow: RunGitWorkflow
|
|
loadStatus: LoadStatus
|
|
setActionError: (next: string | null) => void
|
|
setCommitMessage: (next: string) => void
|
|
setShowActionSheet: (next: boolean) => void
|
|
setCreatedPrUrl: (next: string | null) => void
|
|
setCreatedPrWarning: (next: string | null) => void
|
|
recordCommitFailure: RecordMobileCommitFailure
|
|
}
|
|
|
|
export function useMobileCreatePrRunner({
|
|
client,
|
|
worktreeId,
|
|
status,
|
|
branchLabel,
|
|
commitMessage,
|
|
stagedEntries,
|
|
mountedRef,
|
|
runGitWorkflow,
|
|
loadStatus,
|
|
setActionError,
|
|
setCommitMessage,
|
|
setShowActionSheet,
|
|
setCreatedPrUrl,
|
|
setCreatedPrWarning,
|
|
recordCommitFailure
|
|
}: Params) {
|
|
return useCallback(
|
|
async (pushFirst: boolean) => {
|
|
setShowActionSheet(false)
|
|
const branch = status?.branch
|
|
if (!client || !branch) {
|
|
triggerError()
|
|
setActionError('Check out a branch before creating a pull request.')
|
|
return
|
|
}
|
|
const created: { current: MobileHostedReviewCreateIntentRunOutcome | null } = {
|
|
current: null
|
|
}
|
|
let progress: MobileHostedReviewCreateIntentProgress | null = null
|
|
const ran = await runGitWorkflow(pushFirst ? 'push-create-pr' : 'create-pr', async () => {
|
|
created.current = await runMobileHostedReviewCreateIntent(client, worktreeId, {
|
|
branch,
|
|
title: branchLabel,
|
|
status,
|
|
commitMessage,
|
|
onProgress: (nextProgress: MobileHostedReviewCreateIntentProgress) => {
|
|
progress = nextProgress
|
|
setActionError(mobileHostedReviewCreateIntentProgressMessage(nextProgress))
|
|
}
|
|
})
|
|
if (!created.current.ok) {
|
|
throw new Error(created.current.error)
|
|
}
|
|
})
|
|
const outcome = created.current
|
|
if (outcome?.committed && mountedRef.current) {
|
|
setCommitMessage('')
|
|
}
|
|
if (!ran && outcome?.status !== undefined && mountedRef.current) {
|
|
await loadStatus({
|
|
preserveReadyOnFailure: true,
|
|
clearActionErrorOnSuccess: false,
|
|
force: true
|
|
})
|
|
}
|
|
if (!ran || !mountedRef.current || !outcome || !outcome.ok) {
|
|
if (!ran && outcome && isMobileHostedReviewCommitFailure(outcome, progress)) {
|
|
const outcomeStagedEntries = getMobileCommitFailureStagedEntries(outcome.status?.entries)
|
|
recordCommitFailure({
|
|
error: outcome.error,
|
|
commitMessage: outcome.commitMessage ?? commitMessage.trim(),
|
|
stagedEntries: outcomeStagedEntries.length > 0 ? outcomeStagedEntries : stagedEntries
|
|
})
|
|
}
|
|
return
|
|
}
|
|
setActionError(null)
|
|
setCreatedPrUrl(outcome.url)
|
|
setCreatedPrWarning(outcome.warning ?? null)
|
|
},
|
|
[
|
|
branchLabel,
|
|
client,
|
|
commitMessage,
|
|
loadStatus,
|
|
mountedRef,
|
|
recordCommitFailure,
|
|
runGitWorkflow,
|
|
setActionError,
|
|
setCommitMessage,
|
|
setCreatedPrUrl,
|
|
setCreatedPrWarning,
|
|
setShowActionSheet,
|
|
stagedEntries,
|
|
status,
|
|
worktreeId
|
|
]
|
|
)
|
|
}
|