feat: emit permission_asked events in --format json mode for headless integrations - #39447
feat: emit permission_asked events in --format json mode for headless integrations#39447baizhu945 wants to merge 1 commit into
Conversation
… integrations Enables OpenCode in --format json headless mode to emit permission_asked NDJSON events to stdout and accept permission replies via stdin, instead of automatically auto-rejecting all permission requests. This allows external tools (e.g. cc-connect) to relay permission verification cards to messaging platforms and return user decisions back to OpenCode. Changes: - Keep stdin open in --format json mode for permission reply channel (prompt is passed as positional argument instead of piped via stdin) - Emit permission_asked JSON event with full permission details - Add readPermissionReply() helper using node:readline, with 120s timeout defaulting to reject See: chenhg5/cc-connect#1420
|
This PR doesn't fully meet our contributing guidelines and PR template. What needs to be fixed:
Please edit this PR description to address the above within 2 hours, or it will be automatically closed. If you believe this was flagged incorrectly, please let a maintainer know. |
|
The following comment was made by an LLM, it may be inaccurate: The search found one potentially related PR: Related PR:
The search results primarily show PR #39447 itself, suggesting there are no exact duplicates currently open. The #37902 PR is related to permission handling but addresses a different scope (child/subagent sessions vs. headless integrations). |
|
This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window. Feel free to open a new pull request that follows our guidelines. |
Problem
When OpenCode runs in
--format jsonnon-interactive mode (as used by external tools like cc-connect), all permission requests are automatically rejected internally. Thepermission.askedevent is never emitted to stdout, so external tools cannot relay permission verification cards to users on messaging platforms (Telegram, Feishu, etc.).See: chenhg5/cc-connect#1420
Solution
In
--format jsonmode:permission_askedJSON events to stdout with full permission details (id, permission name, patterns, metadata, tool info)readPermissionReply()helper usingnode:readline, with a 120-second timeout defaulting to"reject"Data Flow
Changes
packages/opencode/src/cli/cmd/run.ts: Modified stdin handling,permission.askedevent handler, addedreadPermissionReply()helperTesting
Tested end-to-end with cc-connect + Telegram bot. Non-JSON-format mode behavior is unchanged.