Skip to content

fix: handle Comet permission prompts and prevent browser resize#13

Closed
OneStepAt4time wants to merge 12 commits into
masterfrom
worktree-fix+comet-permission-prompts-viewport
Closed

fix: handle Comet permission prompts and prevent browser resize#13
OneStepAt4time wants to merge 12 commits into
masterfrom
worktree-fix+comet-permission-prompts-viewport

Conversation

@OneStepAt4time
Copy link
Copy Markdown
Owner

Summary

  • Detect and handle Comet action/permission prompts (awaiting_action status) — previously reported as completed when Comet was waiting for user confirmation
  • Add comet_approve_action tool (14th tool) to click primary or cancel buttons on permission prompts
  • Fix browser window physically resizing during operations by making viewport override opt-in (COMET_OVERRIDE_VIEWPORT env var, default false)
  • Fix multiple race conditions: concurrent ensureConnected() deduplication, concurrent comet_ask mutex
  • Fix comet_mode read-mode navigating away from active conversations
  • Dynamic screenshot viewport via Page.getLayoutMetrics() instead of hardcoded config values

Changes

Permission prompt handling

  • src/ui/action.ts (NEW): Script to click action buttons on Comet permission banners
  • src/ui/status.ts: Detect @container/banner elements, report awaiting_action status with actionPrompt and actionButtons fields
  • src/server.ts: New comet_approve_action tool; comet_wait breaks on awaiting_action state

Browser resize fix

  • src/cdp/client.ts: setDeviceMetricsOverride only when overrideViewport: true; new getViewportClip() uses Page.getLayoutMetrics()
  • src/config.ts: overrideViewport: false default, COMET_OVERRIDE_VIEWPORT env var
  • src/types.ts: overrideViewport field on CometConfig

Race condition & edge case fixes

  • connectPromise guard deduplicates concurrent ensureConnected() calls
  • askInProgress mutex prevents concurrent comet_ask corruption
  • comet_mode read-mode only navigates if not already on home page
  • Prose-filter question threshold lowered from <100 to <20 chars
  • buildSubmitPromptScript focuses input before submit, verifies input cleared
  • Response truncation marker at 8000 chars with guidance to use comet_get_page_content

Test plan

  • All 328 unit/integration tests pass
  • New action.test.ts with 11 tests for action button script
  • New status detection tests for awaiting_action, actionPrompt, actionButtons
  • Updated selector tests for ACTION_BANNER
  • Updated tool count tests (13 → 14)
  • Manual UAT: trigger permission prompt via "open a new issue on GitHub" and verify awaiting_action status
  • Manual UAT: verify browser window no longer resizes on connect
  • Manual UAT: verify comet_approve_action clicks correct button

- Detect Comet action/permission prompts (awaiting_action status) via
  @container/banner CSS selector in status polling
- Add comet_approve_action tool to click primary or cancel buttons on
  permission prompts
- comet_wait now breaks out of polling when awaiting_action is detected,
  reporting the prompt text and available actions
- Fix browser window resize by making Emulation.setDeviceMetricsOverride
  opt-in (overrideViewport config, default false)
- Use dynamic viewport via Page.getLayoutMetrics() for screenshots
  instead of hardcoded config values
- Add connectPromise guard to deduplicate concurrent ensureConnected()
  calls (race condition fix)
- Add askInProgress mutex to prevent concurrent comet_ask corruption
- Fix comet_mode read-mode to only navigate if not already on home page
- Lower prose-filter question threshold from <100 to <20 chars
- Improve buildSubmitPromptScript: focus input before submit, verify
  input was cleared
- Add response truncation marker at 8000 chars with guidance to use
  comet_get_page_content
- Fix .gitignore tools/ pattern to /tools/ (root-level only)
- Add .claude/worktrees/ to .gitignore
- Add ACTION_BANNER selector to selector types, v145, and main selectors
- Add AwaitingAction to AgentState enum
…1.2.0

- tools.md: add comet_approve_action (14th tool), awaiting_action status,
  actionPrompt/actionButtons fields, action approval common pattern
- README.md: update tool count 13→14, add comet_approve_action to session
  tools and agent workflows
- CHANGELOG.md: add [1.2.0] entry with all new features and fixes
- configuration.md: add COMET_OVERRIDE_VIEWPORT env var and config option
…vior

The comet_ask docs still described the pre-v1.1.1 polling loop behavior
(timeout, stall detection, response stabilization). The handler actually
returns immediately after submission. Also:
- Remove stale timeout parameter from docs
- Add concurrency guard documentation
- Fix TOC duplicate numbering (15, 15, 16 → 15, 16, 17)
- Add missing env vars to Connection Lifecycle config table
- Add comet_mode query retry count (5 attempts)
…erns

- Update Common Patterns to reflect ask-then-wait two-call pattern
- Remove timeout parameter from comet_ask examples
- Add awaiting_action to poll completion statuses
- Fix comet_wait description (no longer says "after comet_ask times out")
- Remove stale timeout comparison in comet_wait notes
- Remove unused AgentState enum (Thinking, Searching, Responding, Error
  never produced by status detection; 'working' was missing)
- Remove dead AgentStatus interface (never imported outside its test)
- Promote RawAgentStatus to canonical AgentStatus with AgentStatusValue
  union type: 'idle' | 'working' | 'completed' | 'awaiting_action'
- Remove dead timeout parameter from comet_ask Zod schema (accepted but
  never read by handler — silently did nothing)
- Update types.test.ts with proper AgentStatus, AgentStatusValue, and
  overrideViewport coverage
- parseAgentStatus: validate all fields with defaults instead of raw cast,
  prevents TypeError crashes when status.steps/status.response are undefined
- comet_switch_tab: return clear error when no tabId or title provided
  instead of showing "title containing undefined"
- comet_ask: add z.string().min(1) to reject empty prompts
- comet_wait: guard timeout=0 falling through nullish coalescing
- comet_get_page_content: guard maxLength=0 falling through nullish coalescing
- Add "no criteria provided" response to comet_switch_tab docs
- Document status parsing hardening, empty prompt rejection, boundary
  value guards, and type cleanup in CHANGELOG
- Document removal of dead AgentState/AgentStatus types and timeout param
…aring

Root cause: item.click() silently failed because Comet's typeahead menu
items use React onMouseDown handlers, not onClick. The fix invokes
onMouseDown directly via React fiber props (__reactProps$) with
dispatchEvent(mousedown) as fallback.

Also replaces page reload (which didn't clear Lexical editor state) with
select-all + delete + backspace clearing before typing / to open the
typeahead menu.
Mode read path had two bugs: (1) existing Lexical editor text caused
the / character to append instead of triggering the typeahead, and
(2) no Escape/Backspace between retries left / characters accumulating.
Fixed by adding editor clearing before the loop and Escape+Backspace
between retries.

Also adds integration tests for comet_approve_action (5 tests),
bringing all 14 tools to full coverage (336 tests).
… approach

Update AGENTS.md, architecture.md, contributing.md, and integration.md
to reflect the 14th tool (comet_approve_action). Also update the
architecture mode switching section to document the React onMouseDown
approach and Lexical editor clearing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant