|
| 1 | +# Remote Tool Interactions Plan |
| 2 | + |
| 3 | +## Summary |
| 4 | + |
| 5 | +Implement a structured remote interaction loop for Telegram and Feishu so remote endpoints can resolve paused permission and question interactions without falling back to a generic desktop-only notice. The feature stays inside Electron main and reuses the existing `RemoteConversationRunner`, `RemoteCommandRouter`, `FeishuCommandRouter`, and `newAgentPresenter.respondToolInteraction(...)` flow. |
| 6 | + |
| 7 | +## Goals |
| 8 | + |
| 9 | +- Expose `RemoteConversationSnapshot.pendingInteraction` as the canonical paused-interaction state for remote delivery. |
| 10 | +- Preserve the current detached-session and bound-endpoint model without adding renderer IPC. |
| 11 | +- Let Telegram resolve interactions with inline buttons plus text fallback. |
| 12 | +- Let Feishu render interaction cards and fall back to complete plain-text prompts when card delivery fails. |
| 13 | +- Keep command/session state safe while an interaction is unresolved. |
| 14 | + |
| 15 | +## Readiness |
| 16 | + |
| 17 | +- No open clarification items remain. |
| 18 | +- The feature is ready for implementation and regression verification. |
| 19 | + |
| 20 | +## Rollout Steps |
| 21 | + |
| 22 | +1. Extend remote snapshot and runner contracts to surface `pendingInteraction`. |
| 23 | +2. Parse assistant `tool_call_permission` and `question_request` blocks into a shared `RemotePendingInteraction` model. |
| 24 | +3. Gate remote command routing around pending interactions and add `/pending`. |
| 25 | +4. Add Telegram-specific rendering, callback token state, callback refresh, and text fallback. |
| 26 | +5. Add Feishu-specific card rendering, text fallback, and inbound text parsing. |
| 27 | +6. Add regression coverage for runner extraction, callback refresh, prompt resend, and channel-specific prompt delivery. |
| 28 | +7. Update spec artifacts so acceptance, rollout, and compatibility are reviewable without tracing code. |
| 29 | + |
| 30 | +## Dependencies |
| 31 | + |
| 32 | +- `RemoteConversationSnapshot.pendingInteraction` in `RemoteConversationRunner` |
| 33 | +- `newAgentPresenter.respondToolInteraction(...)` |
| 34 | +- Existing Telegram outbound edit/send flows in `TelegramPoller` |
| 35 | +- Existing Feishu outbound text flow extended with card sending in `FeishuRuntime` |
| 36 | +- In-memory callback/token state in `RemoteBindingStore` |
| 37 | + |
| 38 | +## Data And API Changes |
| 39 | + |
| 40 | +- `RemoteConversationSnapshot` |
| 41 | + - Add `pendingInteraction: RemotePendingInteraction | null` |
| 42 | + - Preserve `text` and `completed` semantics so remote delivery can send visible text plus a follow-up interaction prompt |
| 43 | +- `RemoteRunnerStatus` |
| 44 | + - Add `pendingInteraction` |
| 45 | + - Suppress `isGenerating` while the assistant is explicitly waiting on user action |
| 46 | +- `RemotePendingInteraction` |
| 47 | + - Include `messageId`, `toolCallId`, `toolName`, `toolArgs` |
| 48 | + - Include permission metadata for `tool_call_permission` |
| 49 | + - Include question metadata for `question_request` |
| 50 | +- `RemoteCommandRouteResult` / `FeishuCommandRouteResult` |
| 51 | + - Allow outbound interaction prompt actions in addition to normal replies/conversation execution |
| 52 | + |
| 53 | +## Telegram Rendering Behavior |
| 54 | + |
| 55 | +- Permission interactions render a dedicated prompt with inline `Allow` / `Deny` buttons. |
| 56 | +- Single-choice questions render inline option buttons and `Other` when custom text is allowed. |
| 57 | +- `question.multiple === true` does not render fake multi-select buttons and instead instructs the user to reply in plain text. |
| 58 | +- Text fallback accepts: |
| 59 | + - `ALLOW` / `DENY` for permissions |
| 60 | + - Exact numeric replies for question options |
| 61 | + - Exact option labels for question options |
| 62 | + - Custom text when allowed |
| 63 | +- Expired callback tokens do not hard-fail if the interaction still exists; the router re-reads the current pending interaction and refreshes the prompt. |
| 64 | +- After a button press, Telegram edits the original prompt into a resolved state immediately, then continues any deferred execution in the background. |
| 65 | + |
| 66 | +## Feishu Rendering Behavior |
| 67 | + |
| 68 | +- Pending interactions render as interactive-card style outbound messages when the card API succeeds. |
| 69 | +- Card fallback uses the full plain-text prompt, not only a short reply hint, so the user still sees permission/question details. |
| 70 | +- Feishu remains text-response only on the inbound side: |
| 71 | + - `ALLOW` / `DENY` for permissions |
| 72 | + - Exact numeric replies for question options |
| 73 | + - Exact option labels for question options |
| 74 | + - Custom text when allowed |
| 75 | +- `question.multiple === true` always uses plain-text answers. |
| 76 | + |
| 77 | +## Command Gating While Waiting |
| 78 | + |
| 79 | +- Blocked commands while a pending interaction exists: |
| 80 | + - `/new` |
| 81 | + - `/use` |
| 82 | + - `/model` |
| 83 | + - Unrelated plain-text new-turn input |
| 84 | +- Allowed commands while a pending interaction exists: |
| 85 | + - `/help` |
| 86 | + - `/status` |
| 87 | + - `/open` |
| 88 | + - `/pending` |
| 89 | +- `/pending` re-sends the current prompt for the endpoint-bound session. |
| 90 | + |
| 91 | +## Migration And Compatibility |
| 92 | + |
| 93 | +- `RemoteConversationSnapshot.pendingInteraction` is additive and does not require a persisted config migration. |
| 94 | +- Existing Telegram and Feishu bindings remain valid. |
| 95 | +- Existing remote sessions continue to use detached session creation and the same runner/session binding path. |
| 96 | +- Telegram keeps inline-button interaction handling; Feishu does not introduce public callback endpoints. |
| 97 | +- The former generic "Desktop confirmation is required" message becomes a fallback path only, not the primary remote behavior. |
| 98 | + |
| 99 | +## Risks And Mitigations |
| 100 | + |
| 101 | +- Stale callback tokens |
| 102 | + - Mitigation: rebind tokens to `endpointKey + messageId + toolCallId` and refresh prompts when the current interaction still matches. |
| 103 | +- Session drift while waiting |
| 104 | + - Mitigation: block `/new`, `/use`, `/model`, and unrelated plain-text turns until the interaction is resolved. |
| 105 | +- Feishu card delivery failures |
| 106 | + - Mitigation: fall back to the full plain-text prompt and keep inbound parsing text-only. |
| 107 | +- Telegram callback latency |
| 108 | + - Mitigation: edit the prompt immediately and run continuation work off the poll loop. |
| 109 | + |
| 110 | +## Test Strategy |
| 111 | + |
| 112 | +- Runner tests |
| 113 | + - Extract `pendingInteraction` from assistant action blocks |
| 114 | + - Resume after tool interaction response |
| 115 | + - Handle chained interactions on the same assistant message |
| 116 | +- Telegram tests |
| 117 | + - Button callbacks and text fallback |
| 118 | + - Expired callback token refresh |
| 119 | + - `/pending` prompt resend |
| 120 | + - Prompt edit timing and non-blocking deferred continuation |
| 121 | +- Feishu tests |
| 122 | + - Card prompt generation |
| 123 | + - Plain-text fallback content |
| 124 | + - Text parsing for permission/question answers |
| 125 | + - Pending command gating and `/pending` |
0 commit comments