Repository navigation
feat(mobile): add context-aware prompt optimization in composer - #2036
Merged
Merged
Conversation
Adds input-side context-aware prompt optimization for mobile (iOS, Android, and H5) using the existing /api/sessions/:id/optimize-prompt endpoint, with inline restore/cancel/error feedback, focus/edit/session-switch cancellation, legacy pre-v0.8.0 safe cancel probing, and a server-side 404 guard for unknown session sub-resources. Closes #2025
PR quality triageChanged areas: area:server CLI core policy: No CLI-core policy block detected. Missing-test policy: No missing-test policy block detected. Coverage baseline policy: No coverage-baseline policy block detected. CLI core files:
Coverage policy files:
Required check plan:
Test coverage signals:
Risk notes:
Hard merge gates come from the deterministic GitHub Actions contract lanes above. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds input-side context-aware prompt optimization to the mobile app (iOS, Android, and H5), bringing parity with the desktop implementation (#1965) and closing #2025:
POST /api/sessions/:id/optimize-prompt(120 s timeout) andDELETE /api/sessions/:id/optimize-prompt/:requestIdendpoints, working on idle, empty, and mid-turn (queueing) sessions without mutating session transcripts.PromptOptimizeButton) inChatComposer(shown only in existing sessions when draft text is non-empty and not a/command) and an inline status/restore/error bar (PromptOptimizeFeedback) with one-click Restore (15 s window) and clear Chinese error feedback.useFocusEffect), host/session switches, and unmounts viauseLayoutEffectand per-runclientcapture.GET /api/sessions/:id/optimize-promptbefore issuing the firstDELETE(only sendingDELETEwhen the v0.8.0+405 Unsupported prompt optimization routesignature is confirmed), and the server adds an explicitif (subResource)404 guard before/api/sessions/:iditem handlers insrc/server/api/sessions.ts.optimize-promptroutes and self-test assertions tomobile/scripts/fixture-server.ts.Closes #2025
Feature Quality Contract
mobile/src/core/promptOptimize.test.ts: unit tests forisOptimizablePrompt, API timeout/encoding, legacy pre-v0.8.0 GET-probe cancel protection, v0.8.0+ probe caching, error/abort mapping, oversized prompt guard, per-run client cancel targeting, edit/session-switch cancellation, and restore flow.mobile/src/core/usePromptOptimize.test.ts: real React (react-reconciler) lifecycle tests covering controlled draft updates, synchronoususeLayoutEffectexternal-edit & blocked guards,useFocusEffectblur cleanup, and context/client/unmount cleanup.mobile/src/ui/ChatComposer.promptOptimize.test.ts: composer wiring tests for button visibility, mid-turn queueing, voice/text edit cancellation, inline status/restore/notice/error states, and disabled states.src/server/__tests__/e2e/prompt-optimize.test.ts: regression assertion confirmingDELETE /api/sessions/:id/unknown-subresource/:uuidreturns404and preserves the session.mobile/scripts/fixture-server.ts: addedGETprobe,POSToptimize, andDELETEcancel assertions to--self-test.bun run check:coveragepassed (5/5 suites passed, 0 failed).bun run check:mobile(typecheck, lint, unit/component/hook tests, H5 export),bun run check:policy,bun run check:server,bun run check:chat-contract,bun run check:agent-flow,bun run check:agent-e2e(34 mock + 21 replay scenarios),bun test src/server/__tests__/e2e/prompt-optimize.test.ts, andbun mobile/scripts/fixture-server.ts --self-test./newscreen creates sessions lazily on send and therefore omitssessionId, so prompt optimization is available inside existing sessions (/chat/[id]).git revertof the squash commit; no persisted storage schema changes or migrations.Verification
bun run check:impact; if I claim PR-ready/full validation, I also ranbun run verify.Risk
allow-cli-core-change.allow-missing-tests.allow-coverage-baseline-change.