Skip to content

feat(pi): default Emacs MCP to codemode and add compose/followup controls - #612

Open
tninja wants to merge 3 commits into
mainfrom
kang_feat_11
Open

tninja wants to merge 3 commits into
mainfrom
kang_feat_11

Conversation

@tninja

@tninja tninja commented Nov 23, 2026

Copy link
Copy Markdown
Owner

Summary

Improve the out-of-the-box Pi (ai-code-pi.el + ai-code-mcp-agent.el) experience—especially tool-calling accuracy and parallel batching on Gemini models, plus Pilish-inspired Emacs compose and follow-up ergonomics—while keeping startup 100% model-, credential-, and trust-neutral by default:

  • Default Pi Emacs MCP to codemode with minimal direct anchors (ai-code-mcp-agent.el):
    • Change ai-code-mcp-agent-pi-exposure default from "direct" to "codemode" so Pi automatically enables its built-in codemode script runner for parallel tool batching and keeps ~85% of Emacs MCP JSON schemas out of every turn (preventing strict-schema overload on Gemini 3+ and preserving prompt cache).
    • Keep the 3 harness-referenced anchor tools (diagnostics_baseline, get_diagnostics, get_org_heading_context) directly declared via ai-code-mcp-agent-pi-tool-exposure, with fail-closed validation and full customization back to "direct".
  • Emacs compose viewport, follow-up queueing & slash commands (ai-code-pi.el, ai-code-backends-infra.el):
    • M-x ai-code-pi-compose: send Ctrl+G (\x07) to open Pi's external editor in ai-code-editor-viewport without Emacs C-g (keyboard-quit) interception, refreshing MCP source context when invoked from a project buffer.
    • M-<return> in Pi session buffers, M-x ai-code-pi-send-follow-up, and ai-code-pi-send-while-busy (steer default vs followup): submit via Alt+Enter (\e[13;3u), which sends immediately when Pi is idle and queues a follow-up when streaming or compacting (using unhyphenated followup so bare follow-up is never interned into obarray for ai-code-session-link).
    • M-x ai-code-pi-slash-command: completion and normalization for Pi slash commands (/model, /thinking, /tree, /compact, etc.), always submitted with standard Return.
    • ai-code-pi-project-trust: optional approve / no-approve startup flag (default nil, honoring explicit CLI switches).
  • Documentation (README.org): document Pi's MCP codemode defaults, compose/follow-up workflows, and a recommended manual Gemini setup (GEMINI_API_KEY / Vertex AI + gemini-3.1-pro-preview-customtools & Pro/Flash cycling).

Test Plan

  • Focused ERT suite (test_ai-code-pi.el + test_ai-code-mcp-agent.el Pi tests): 20/20 passed.
  • Full ERT suite (test/test_*.el): 2018 run, 0 new failures versus baseline.
  • Batch byte-compilation (emacs -Q --batch) & checkdoc-file: 0 new warnings across all touched files.
  • Runtime verification: generated Pi extension dynamically imported under Node ESM to verify registerMcpServer headers, exposure, and toolExposure; 5/5 scripted manual mutations killed.

…rols

- Switch Pi's generated Emacs MCP extension default exposure from direct to codemode with direct toolExposure anchors (diagnostics_baseline, get_diagnostics, get_org_heading_context) and fail-closed validation, keeping ~85% of MCP tool schemas out of every turn while enabling parallel codemode calls.
- Add ai-code-pi-compose (Ctrl+G external editor viewport trigger), ai-code-pi-send-follow-up / M-<return> / ai-code-pi-send-while-busy (Alt+Enter follow-up queueing without interning bare follow-up in obarray), ai-code-pi-slash-command, and optional ai-code-pi-project-trust.
- Support optional :post-start-fn composition and dynamic submit-return hook in ai-code-backends-infra to avoid duplicating prompt submission logic.
- Document Pi compose/queue workflows and recommended manual Gemini setup in README.org, with ERT coverage.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-23T22:21:18.478960Z f9278ef PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Kang Tu and others added 2 commits November 23, 2026 20:14
Pi binds app.message.followUp to ctrl+q when it uses Windows keybindings
(win32, or Linux with WSL_DISTRO_NAME/WSL_INTEROP) and to alt+enter
elsewhere. The fixed Alt+Enter default typed text into Pi's editor without
submitting or queueing it on those platforms.

- Derive ai-code-pi-follow-up-sequence's default from the platform.
- Document the platform difference and keybinding override in the docstring.
- Add ERT coverage for macOS, Linux, Windows, and both WSL variables.
Resolve conflict in `ai-code-backends-infra--start-cli-session' by
forwarding `(plist-get options :post-start-fn)' into the deferred
launch preparation path so `:prepare-launch' and option post-start
hooks compose in order.  Update `test_ai-code-pi.el' for deferred
launch preparation and add a composition order unit test in
`test_ai-code-backends-infra.el'.
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