Skip to content

upstream 取り込み PR #4: terminal 系 / 3 commits + dedupe fix#400

Merged
MocA-Love merged 4 commits intomainfrom
upstream/batch-4-terminal
Apr 23, 2026
Merged

upstream 取り込み PR #4: terminal 系 / 3 commits + dedupe fix#400
MocA-Love merged 4 commits intomainfrom
upstream/batch-4-terminal

Conversation

@MocA-Love
Copy link
Copy Markdown
Owner

@MocA-Love MocA-Love commented Apr 23, 2026

Summary

upstream 取り込みバッチ 4: terminal 系 3 commits + dedupe fix。Codex 事前調査を経て、対象 11 commits のうち大部分が fork で既に同等実装を持つ領域と判明し、残る 3 commits を取り込み。

取り込み内容(3 commits + 1 dedupe fix)

除外した 8 commits(理由別)

fork 既取り込み相当(cherry-pick で empty commit 判定 = 実質変化ゼロ)

PR #4 scope 外へ移動

Fork 側のコンフリクト解決

Fork 固有機能ヘルスチェック

作業前 baseline (/tmp/pr4-baseline/fork-features.txt) と作業後を grep で照合。全 14 項目変化なし:

  • 19 tRPC プロシージャ全数
  • ansi_up, @vscode/ripgrep, @xyflow/react 依存
  • TERMINAL_OPTIONS (5 ファイル)
  • SUPERSET_WORKSPACE_NAME (24 箇所)
  • moonshot-ai.kimi-code, MainWindowEffects, INCEPTION_AUTH_PROVIDER_ID
  • listBranches sortOrder/pinDefault
  • port-scanner.ts Windows 分岐 (3 箇所)
  • BROWSER_RELOAD, dmg.size="4g"

Codex 事前調査レポート

/tmp/pr4-codex-preanalysis.md 参照。PR #388 で既に大半の terminal fixes が取り込まれていたため、今回の取り込み実質差分は 3 commits に留まる。

Test plan

  • bun install 正常完了
  • bun run typecheck グリーン (27/27 task)
  • bun run lint グリーン (4058 files checked)
  • fork 固有機能 regression ゼロ
  • terminal agent presets の default が新しいほうに
  • 既存ユーザー (canary) の permissions が backfill される
  • TUI (vim, neovim 等) で Shift+Enter が CSI-u として解釈される

次の PR

Summary by CodeRabbit

リリースノート

  • バグ修正

    • ターミナルエージェントの CLI フラグを更新しました(Claude、Codex、Gemini、Copilot)
    • ターミナル環境変数の報告を修正しました
  • ドキュメント

    • ターミナルプリセットのデフォルトコマンド設定を更新しました
    • 権限および承認モードの説明を改善しました

saddlepaddle and others added 4 commits April 24, 2026 06:48
…erset-sh#3546)

* feat(desktop): safer defaults for builtin terminal agent presets

Swap permission-bypass flags for each CLI's intended safe-but-useful
mode (claude acceptEdits, codex --full-auto, gemini auto_edit, copilot
--allow-all-tools). Drop mastracode/opencode/pi from the default seed
since they are YOLO-by-default at the CLI level; they remain available
via Quick-Add. Remove cursor-agent's --yolo suffix (silent no-op on the
real binary). Existing users are preserved — the v1
terminalPresetsInitialized guard and v2 migration marker ensure stored
commands are never rewritten.

* test(desktop): update agent-launch-request fixture for new codex default

buildPromptAgentLaunchRequest's terminal-command fixture hard-coded the
old --dangerously-bypass-approvals-and-sandbox flag. Update it to the
new --full-auto default so the test reflects the current builtin.

* fix(desktop): address reviewer feedback on safe-default flag choices

- gemini promptCommand: add --approval-mode=auto_edit so prompt/task
  launches use the same safety mode as terminal launches (flagged by
  cubic, greptile, and CodeRabbit)
- copilot: switch from --allow-all-tools to --allow-tool=write. Per
  GitHub's own docs, --allow-all-tools "allows all tools to run
  automatically without confirmation" including shell, which
  contradicts the safe-by-default claim. --allow-tool=write auto-
  approves file edits only (analog of claude's acceptEdits).
- docs: update copilot line; clarify mastracode/opencode/pi opt-in
  parentheticals so users understand why they're not auto-seeded.
…uperset-sh#3546 (superset-sh#3615)

PR superset-sh#3546 swapped builtin terminal agent defaults to safer modes (claude
acceptEdits, codex --full-auto, gemini auto_edit, copilot --allow-tool=write,
cursor-agent without --yolo suffix). The v1 `terminalPresetsInitialized`
guard and v2 migration marker preserved users' stored terminal-preset
command strings, but the **agent-preset** resolution path (resolveAgentConfigs
in packages/shared/src/agent-settings.ts) layers user overrides on top of the
*current* builtin defaults — so any existing canary user who never
customized claude/codex/gemini/copilot/cursor-agent silently had their
resolved launch command swapped.

Fix: one-shot backfill into agentPresetOverrides. New
`agentPresetPermissionsMigratedAt` column in settings gates the migration to
run exactly once per user. On first read of agent-preset overrides, if the
user's stored `terminalPresets` row contains any of the 4 pre-superset-sh#3546 exact
default command strings (meaning their seed happened on a pre-superset-sh#3546 build),
we inject overrides for `command`/`promptCommand`/`promptCommandSuffix`
carrying the legacy YOLO values, skipping any field the user has already
customized. Fresh post-superset-sh#3546 installs have no legacy fingerprint, so the
migration only stamps the timestamp and moves on.
superset-sh#3667)

* fix(desktop): adopt Ghostty keyboard model in v2 terminal

v2's terminal runtime only filtered app hotkeys. With kitty keyboard
protocol enabled (needed for Shift+Enter disambiguation in claude-code,
modifier reporting in neovim/helix), every Mac Cmd chord xterm saw got
CSI-u encoded and leaked into TUIs as a literal char — and line-edit
niceties like Cmd+Left/Right/Backspace and Option+Left/Right that v1
handles never worked at all.

Mirror Ghostty's approach (src/input/key_encode.zig:534-545: "on macOS,
command+keys do not encode text"): bubble every Mac Cmd chord out to
the host before xterm's kitty encoder runs, then port v1's line-edit
chord translators so shell navigation works the same in both renderers.

Changes:
- Broaden shouldBubbleClipboardShortcut's Mac branch to bubble all Cmd
  chords (not just Cmd+C/V with selection gating). v1 benefits too.
- Port v1's line-edit translators into v2's custom key handler:
  Cmd+Left/Right/Backspace, Option+Left/Right, Windows Ctrl+Left/Right.
  Duplicates v1 for now; a follow-up can share the handler properly.
- Wire shouldSelectAllShortcut into v2 so Cmd+A selects terminal buffer.
- Use xterm.input(data, true) to inject translated sequences into the
  PTY (fires onData, forwarded by terminal-ws-transport).
- Restructure tests around the new Mac rule.

* fix(desktop): track kitty flags to gate Shift+Enter CSI-u injection

When claude-code or codex pushes kitty progressive-enhancement flags
(CSI > N u), the running program expects modified keys as CSI-u. xterm.js
v6.1-beta tracks this internally but doesn't expose the active flags, so
we mirror them via our own CSI handlers registered alongside xterm's
built-ins (registering with return-false passes through to xterm too).

With the disambiguate bit active, Shift+Enter now emits the canonical
\x1b[13;2u that both claude-code and codex recognise — matching Ghostty
/ kitty / wezterm, which all gate CSI-u on program-initiated kitty mode
(ghostty/src/input/key_encode.zig:88, kitty/key_encoding.c:153). Without
kitty flags, Shift+Enter falls through to xterm.js's legacy encoding
(plain \r), so bash / zsh still behave normally.

Replaces the previous alt-screen heuristic, which incorrectly missed
Ink-based TUIs like claude-code that render inline rather than in the
alternate buffer.

* chore(desktop): instrument v2 terminal keyboard path for diagnosis

Add three toggleable diagnostic taps, all gated on localStorage flag
`__kbdDebug=1`:

- Every keydown that reaches the custom key handler: key / code / mods /
  current kitty flags.
- Every kitty CSI push/set/pop with resulting flag state.
- Every onData byte written to the PTY, shown as hex (non-printable
  escaped, printable verbatim) plus length and kitty flags.

Second flag `__kbdDebugSkipOverride=1` temporarily disables our
Shift+Enter CSI-u override so we can observe xterm.js's raw encoding.

To use: in DevTools console, `localStorage.setItem('__kbdDebug', '1')`
(optionally also `__kbdDebugSkipOverride`), reload the terminal pane,
reproduce the bug, copy `[kbd:*]` logs.

* fix(desktop): match Shift+Enter CSI-u form to active kitty flags

Diagnostic trace showed xterm.js emits event-type-suffixed kitty
sequences when the running program activates the report-events flag
(0x02) — e.g. Escape release came through as \x1b[27;1:3u. Our override
was hardcoded to \x1b[13;2u which is the right form only when disambiguate
(0x01) is the sole flag; claude-code (which requests flags = 0x07) was
rejecting the suffix-less form and submitting instead of newline.

Inspect the flags at inject time: emit \x1b[13;2:1u (explicit press event
type) when 0x02 is active, \x1b[13;2u otherwise. Also make kbdLog
stringify its payload so DevTools shows the bytes inline instead of
collapsing to "Object".

* chore(desktop): log keyup too, in addition to keydown

* chore(desktop): disable Shift+Enter override to capture xterm raw output

* fix(host-service): claim TERM_PROGRAM=kitty so TUIs parse our CSI-u

Diagnostic trace of v2 terminal Shift+Enter proved xterm.js v6 with
kittyKeyboard is emitting the correct kitty-protocol bytes (\x1b[13;2u
press + \x1b[13;2:3u release, same as Ghostty). Yet Shift+Enter still
submits in claude-code — strings-dumped the claude-code binary and
found the actual gate:

    Ix_ = {
      ghostty: "Ghostty", kitty: "Kitty", "iTerm.app": "iTerm2",
      WezTerm: "WezTerm", WarpTerminal: "Warp"
    }

Its CSI-u parser keys off TERM_PROGRAM being in that allowlist. With
our previous "Superset" value it ignored the bytes entirely and fell
through to Node readline's legacy keypress handling, where Shift+Enter
looks like plain Enter and submits.

Claim "kitty" — the protocol origin. Fewer downstream version-gated
branches than "ghostty" (which claude-code version-checks against 1.2.0)
and safer than "iTerm.app" (color-depth gated on version <3.x).
TERM_PROGRAM_VERSION stays as our host-service version; programs that
care about real kitty version will hit our version string and probably
fall back to conservative behaviour.

* chore(desktop): remove diagnostic instrumentation and abandoned override code

Root cause for claude-code Shift+Enter landed in host-service env.ts
(TERM_PROGRAM=kitty). The renderer-side machinery we added while
diagnosing is no longer needed:

- kbdLog / kbdHex / kbdDebugSkipOverride console tap
- createKittyFlagTracker (watched CSI > u pushes to gate the override)
- KITTY_FLAG_DISAMBIGUATE / KITTY_FLAG_REPORT_EVENTS constants
- shiftEnterCsiU helper
- terminal.onData logging tap

v2 terminal-runtime.ts is back to a simple createKeyEventHandler
calling resolveHotkeyFromEvent → line-edit translators → select-all →
clipboard bubble → xterm default. Shift+Enter now goes through xterm's
native kitty encoder and claude-code parses it correctly because
TERM_PROGRAM is in its allowlist.

Net -142 LOC from renderer.

* experiment(desktop): narrow Mac Cmd bubble back to VS Code-style

Hypothesis: with TERM_PROGRAM=kitty claiming kitty in the claude-code /
codex allowlist, kitty-aware TUIs parse CSI-u Cmd+chords correctly and
don't show literal char garbage. The broader Ghostty-style "bubble every
Mac Cmd chord" may have been overkill — needed only for TUIs that don't
speak CSI-u.

Revert the Mac branch of shouldBubbleClipboardShortcut to the original
narrow rule (Cmd+V + Cmd+C-with-selection) to test. If kitty-aware TUIs
stay clean AND non-kitty-aware ones (vim base, less, htop, tmux-without-
kitty) are tolerable, we can ship simpler.

Line-edit translators and Cmd+A select-all stay — those aren't
kitty-specific, they're Mac-convention handling the shell expects
regardless of kitty.

* experiment(desktop): revert all renderer changes, keep only TERM_PROGRAM=kitty

Aggressive minimum — strip terminal-runtime.ts and clipboardShortcuts.ts
back to main. The only net change from main becomes:

    env.TERM_PROGRAM = "kitty"   (was "Superset")

If claude-code's CSI-u parsing handles Cmd+C/V/Left/Right correctly with
TERM_PROGRAM now in the allowlist, and shell fallback is acceptable for
the rest, this is the true minimum fix.

Things that may regress and be worth checking:
- Cmd+Left / Cmd+Right / Cmd+Backspace in shell (no translator → xterm
  sends CSI-u → bash readline ignores → no cursor navigation)
- Option+Left / Option+Right (same, word navigation won't work in shell)
- Cmd+A in shell (no select-all handler → CSI-u to PTY)
- Cmd+C in vim / less / htop (no broad bubble → CSI-u reaches PTY; if
  those TUIs don't speak kitty they'll show garbage)

If any of those bite, we restore the specific piece(s).

* chore(host-service): trim TERM_PROGRAM comment to essentials
upstream superset-sh#3615 backfill cherry-pick の際に packages/shared/package.json に
既存と重複する export entry が追加された。duplicate key 警告を解消。
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 23, 2026

📝 Walkthrough

ウォークスルー

複数のターミナルエージェント設定と関連テストを更新し、CLIフラグを変更しました。Codexは--dangerously-bypass-approvals-and-sandboxを削除して--full-autoを追加、Claudeは--dangerously-skip-permissions--permission-mode acceptEditsに変更、Geminiは--yolo--approval-mode=auto_editに変更、Copilotは--allow-all --yolo--allow-tool=writeに変更しました。また、TERM_PROGRAMを"Superset"から"kitty"に更新しました。

変更内容

Cohort / File(s) Summary
Codex エージェント CLI フラグ更新
apps/desktop/src/shared/utils/agent-launch-request.test.ts, packages/shared/src/agent-command.test.ts
Codex エージェントのテスト期待値を更新:--dangerously-bypass-approvals-and-sandbox フラグを削除し、--full-auto フラグを追加。既存の推論オプションは変更なし。
ターミナルエージェント CLI フラグ設定
packages/shared/src/builtin-terminal-agents.ts
複数エージェントのビルトイン設定を更新:Claude は --permission-mode acceptEdits に、Codex は --full-auto に、Gemini は --approval-mode=auto_edit に、Copilot は --allow-tool=write に変更。デフォルトから mastracode、opencode、pi を削除。
ターミナル環境設定
packages/host-service/src/terminal/env.ts, packages/host-service/src/terminal/env.test.ts
TERM_PROGRAM 環境変数を "Superset" から "kitty" に変更。kitty互換のCSI-u シーケンス解釈用のコメントを追加。
ターミナルプリセット ドキュメント
apps/docs/content/docs/terminal-presets.mdx
クイック追加テンプレートセクションを更新:各プリセットのCLIコマンドを新しいフラグに対応させ、デフォルトで安全な動作とパーミッションモード/承認モードフラグの説明を追加。

予想コード レビュー工数

🎯 2 (Simple) | ⏱️ ~12 minutes

関連する可能性のあるPR

🐰✨ Codex は full-auto で走り出し、
Claude は permission mode で礼儀正しく、
Kitty の環境で CSI-u を踊り、
すべてのエージェントが調和して動く。
安全さと自動化のバランス、完璧! 🎪

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed タイトルは PR の主な変更内容を正確に反映しており、upstream の terminal 系 3 commits と dedupe fix の取り込みを明確に示している。
Description check ✅ Passed PR の説明は詳細で、取り込み内容・除外理由・コンフリクト解決・テストプランが包括的に記載されており、テンプレートの主要セクションをカバーしている。
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch upstream/batch-4-terminal

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 23, 2026

🧹 Preview Cleanup Complete

The following preview resources have been cleaned up:

  • ⚠️ Neon database branch
  • ⚠️ Electric Fly.io app

Thank you for your contribution! 🎉

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/shared/src/builtin-terminal-agents.ts (1)

118-127: ⚠️ Potential issue | 🟡 Minor

kimi の --yolo が残存し default preset に含まれる点は意図どおりですか?

本 PR のテーマは "safer defaults" で、codex の --dangerously-bypass-approvals-and-sandbox や gemini の --yolo、copilot の --allow-all はすべて置き換えられています。一方で kimi は command: "kimi --yolo" + promptCommandSuffix: "--yolo" のまま includeInDefaultTerminalPresets: true が維持されており、apps/docs/content/docs/terminal-presets.mdx の Quick-Add 一覧からも(安全デフォルト群と対比させるかたちでは)省かれています。

  • upstream #3546 側で kimi のフラグ変更が無かった、という事実上の現状維持であれば問題なし。
  • もし単に漏れているだけなら、--yolo を外すか、mastracode/opencode/pi と同様に default preset から外す(includeInDefaultTerminalPresets を落とす)方が PR 全体のメッセージと整合します。

意図的な温存かどうかだけご確認ください。

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/shared/src/builtin-terminal-agents.ts` around lines 118 - 127, The
preset for the builtin terminal agent with id "kimi" still includes the unsafe
flag "--yolo" in command and promptCommandSuffix while also being included in
default presets via includeInDefaultTerminalPresets: true; either remove the
"--yolo" occurrences from command and promptCommandSuffix or set
includeInDefaultTerminalPresets to false to align with the "safer defaults"
changes (update the createBuiltinTerminalAgent call for id "kimi" to reflect the
chosen fix).
🧹 Nitpick comments (2)
apps/docs/content/docs/terminal-presets.mdx (1)

48-48: nit: codex ... --full-auto の省略記号は他行と不統一

他のエージェント(claude / gemini / copilot など)は Quick-Add コマンドを完全な形で示していますが、codex 行だけ ... で省略されています。読者が "... はそのまま打つのか、何かが省略されているのか" で迷う可能性があるので、完全形にするか、"(-c model_reasoning_effort="high" 等の reasoning 設定は省略)" のような注記を足すと親切です。

💡 表現案
-- **codex** - `codex ... --full-auto` (workspace-sandboxed)
++ **codex** - `codex -c model_reasoning_effort="high" -c model_reasoning_summary="detailed" -c model_supports_reasoning_summaries=true --full-auto` (workspace-sandboxed)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/docs/content/docs/terminal-presets.mdx` at line 48,
行の省略記号が他のエージェント行と不統一で読者が混乱するため、"codex - `codex ... --full-auto`"
を修正してください。具体的には、該当行(codex の Quick-Add
表記)を他行と同様に完全なコマンド表記に置き換えるか、もしくは省略しているオプション(例: `-c model_reasoning_effort="high"`
等の reasoning 設定)を括弧注記で明示して、読者に「実際に入力するのは省略されている部分を含む」ことが分かるようにしてください。
packages/shared/src/agent-command.test.ts (1)

15-30: LGTM — claude / codex の新フラグに追従

codex の --full-auto -- 挿入位置、claude の --permission-mode acceptEdits プレフィックスとも、builtin-terminal-agents.ts 側の定義変更と一致しています。

補足(任意): 本 PR では gemini / copilot も commandpromptCommand を変更していますが、対応する buildAgentPromptCommand のテストは追加されていません。回帰検知を強化したければ、gemini(--approval-mode=auto_edit)および copilot(-i --allow-tool=write)の prompt 構築についても同様のケースを足しておくと安心です(本 PR 必須ではありません)。

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/shared/src/agent-command.test.ts` around lines 15 - 30, Add tests
for gemini and copilot in the buildAgentPromptCommand spec similar to the
existing codex/claude cases: verify buildAgentPromptCommand({agent: "gemini",
...}) produces the new gemini prefix/flag (--approval-mode=auto_edit) and the
heredoc marker with the randomId, and verify buildAgentPromptCommand({agent:
"copilot", ...}) produces the new copilot flags (-i --allow-tool=write) and the
correct heredoc marker; refer to the buildAgentPromptCommand function and the
agent definitions in builtin-terminal-agents.ts to match exact expected strings
and ensure the tests assert the command contains both the agent-specific flags
and the prompt delimiter.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@packages/shared/src/builtin-terminal-agents.ts`:
- Around line 118-127: The preset for the builtin terminal agent with id "kimi"
still includes the unsafe flag "--yolo" in command and promptCommandSuffix while
also being included in default presets via includeInDefaultTerminalPresets:
true; either remove the "--yolo" occurrences from command and
promptCommandSuffix or set includeInDefaultTerminalPresets to false to align
with the "safer defaults" changes (update the createBuiltinTerminalAgent call
for id "kimi" to reflect the chosen fix).

---

Nitpick comments:
In `@apps/docs/content/docs/terminal-presets.mdx`:
- Line 48: 行の省略記号が他のエージェント行と不統一で読者が混乱するため、"codex - `codex ... --full-auto`"
を修正してください。具体的には、該当行(codex の Quick-Add
表記)を他行と同様に完全なコマンド表記に置き換えるか、もしくは省略しているオプション(例: `-c model_reasoning_effort="high"`
等の reasoning 設定)を括弧注記で明示して、読者に「実際に入力するのは省略されている部分を含む」ことが分かるようにしてください。

In `@packages/shared/src/agent-command.test.ts`:
- Around line 15-30: Add tests for gemini and copilot in the
buildAgentPromptCommand spec similar to the existing codex/claude cases: verify
buildAgentPromptCommand({agent: "gemini", ...}) produces the new gemini
prefix/flag (--approval-mode=auto_edit) and the heredoc marker with the
randomId, and verify buildAgentPromptCommand({agent: "copilot", ...}) produces
the new copilot flags (-i --allow-tool=write) and the correct heredoc marker;
refer to the buildAgentPromptCommand function and the agent definitions in
builtin-terminal-agents.ts to match exact expected strings and ensure the tests
assert the command contains both the agent-specific flags and the prompt
delimiter.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3d33f3c5-948b-477d-9078-43f2d8ccf672

📥 Commits

Reviewing files that changed from the base of the PR and between ac645b2 and 4f8c948.

⛔ Files ignored due to path filters (1)
  • bun.lock is excluded by !**/*.lock
📒 Files selected for processing (6)
  • apps/desktop/src/shared/utils/agent-launch-request.test.ts
  • apps/docs/content/docs/terminal-presets.mdx
  • packages/host-service/src/terminal/env.test.ts
  • packages/host-service/src/terminal/env.ts
  • packages/shared/src/agent-command.test.ts
  • packages/shared/src/builtin-terminal-agents.ts

@MocA-Love MocA-Love merged commit bc614eb into main Apr 23, 2026
12 of 13 checks passed
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.

3 participants