Rob Lourens a9a3df670e
launch: simple file dialog, monaco-paste helper, parallel session pattern (#318488)
* launch: simple file dialog, monaco-paste helper, parallel session pattern

Surfaced while running a bug bash over the Agents window terminal tool —
the launch skill needed three improvements before subagents could drive
multiple Code OSS instances cleanly.

1. launch.sh now forces `files.simpleDialog.enable: true` in the launched
   profile. Native macOS file dialogs cannot be driven via @playwright/cli
   over CDP/SSH; the simple (quick-input style) dialog can. Without this,
   the new-session workspace picker's `Select...` button is a dead end
   for automation on a fresh slim-copied UDD.

2. New scripts/monaco-paste.sh helper inserts text into the focused
   Code OSS chat-input Monaco editor by dispatching a synthetic
   ClipboardEvent('paste') with a DataTransfer payload. Avoids pbcopy's
   system-wide NSPasteboard collision (which fights any other process
   touching the clipboard), supports unicode/emoji/backticks/quotes/
   newlines, and waits two requestAnimationFrames before read-back
   because Monaco updates its view-line DOM asynchronously after paste.
   Honors `--session NAME` arg or `$PW_SESSION` env. Verified across
   20+ pastes including all the awkward characters and parallel
   multi-instance runs.

3. SKILL.md updated to:
   - document the new simpleDialog default
   - recommend monaco-paste.sh as the primary typing path; keeps per-key
     `press` and `pbcopy` as fallbacks with the pasteboard-collision
     caveat called out explicitly
   - make `-s=$PW_SESSION` the default convention on every
     @playwright/cli example so the skill's per-instance isolation
     extends to the Playwright-driving layer. Without `-s=`, parallel
     shells share the implicit "default" session daemon and the most-
     recently-attached CDP wins for every subsequent command
   - add a "Parallel multi-instance pattern" subsection showing the
     full attach/paste/cleanup loop with per-session names
   - note that PLAYWRIGHT_CLI_SESSION env var works for `open`-style
     workflows but interacts poorly with `attach --cdp=` due to a
     playwright-core bug (cli-client/session.ts:142-143) — explicit
     `-s=` works in all modes

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Address PR review feedback

Five inline comments from the Copilot reviewer on #318488, all addressed:

- launch.sh: replace the regex-strip-then-JSON.parse settings overlay
  with a data-preserving text-based insert. The previous version could
  silently drop user settings on parse failure and would incorrectly
  strip `//` inside string values (e.g. URLs). The new version:
    * detects when the key is already present (any value) and updates
      its value via a targeted regex on the value slot only;
    * otherwise inserts the key before the last `}`, preserving all
      comments and formatting;
    * fails loudly (non-zero exit) if the file is structurally bad
      rather than silently overwriting with `{}`;
    * is idempotent (T6: byte-identical when key is already `true`).
  Verified across 7 scenarios incl. JSONC comments + URLs containing
  `//` + malformed input.

- monaco-paste.sh: detect platform and pick `Meta+a` (macOS) or
  `Control+a` (Linux/Windows) for the clear-before-paste select-all,
  so the default (non-`--append`) path actually clears the editor on
  non-mac.

- monaco-paste.sh: validate node + jq up-front in addition to npx, so
  missing tools fail with a clear actionable message and exit 2 rather
  than crashing later.

- monaco-paste.sh: header docs now correctly list the three exit codes
  (0 success, 1 paste/eval failure, 2 argument/tooling error) and the
  required tools on PATH.

- monaco-paste.sh: fix `set -u` unbound-variable error when no
  PW_SESSION/--session is set — `"${PW_ARGS[@]}"` on an empty array
  trips set -u, so use the `${PW_ARGS[@]+"${PW_ARGS[@]}"}` idiom at
  every call site.

- SKILL.md: fix "Macros-Mach-ports" → "macOS Mach-ports" typo.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-27 03:31:05 +00:00
..