Skip to content

Let each adapter decide which actions m4code takes with its agent - #153

Merged
m4rocks merged 2 commits into
mainfrom
adapter-capabilities
Nov 28, 2026
Merged

m4rocks merged 2 commits into
mainfrom
adapter-capabilities

Conversation

@m4rocks

@m4rocks m4rocks commented Nov 27, 2026 •

Copy link
Copy Markdown
Owner

Part of #152. Before m4code can follow Google's Antigravity terms, it needs one place where an adapter says which actions m4code may take with its agent. Rules for one harness were scattered through src/app, src/panels and src/thread as match harness branches.

This PR moves them into the adapters and changes no behavior: every adapter still allows everything. The Antigravity rules from #152 come in a follow-up PR as declarations in its adapter.

Capabilities

src/harness/capabilities.rs adds Capabilities to Adapter. Each field is one action: rewind, fork, continue in a fresh session, m4code's compaction fallback, text generation, handoff in and out, running as a subagent, and starting subagents. A refusal carries the reason the user sees.

The core asks before each of those actions:

  • A refused button stays visible but disabled, with the reason as its tooltip. This covers rewind, fork (both the message action and the review footer), "Continue in fresh session" and the Settings "Allow subagent delegation" switch.
  • A refused model in the composer, retry, review, text generation and auto-handoff pickers is greyed out with the reason and can't be picked.
  • The same check runs where the work starts, so a tool call, a palette command or an automatic step can't get around it: dynamic_handoff, rewind_session, fork_thread, compact_session, continue_in_fresh_session, set_model, best_fallback_model, spawn_subagent, the review subagent, thread_start for a resumed subagent, the Claude plugin's agent types and the --acp runner.
  • Rewind checks before it restores any files.
  • A harness that refuses to start subagents gets no subagent tools.

Handoff has Any and Never for now. Initiator already tells the user from the agent, so the follow-up can add a rule that allows only switches the user starts without changing the call sites.

Moved into the adapters

  • SignIn: the sign-in command and the signed-out hints. This replaces acp::login_hint, the table in github_pane.rs, the Claude branch in runner.rs and Provider.sign_in.
  • UsageSource and LiveUsage: where limits come from, how often m4code asks, whether a turn's end asks again, and Codex's log watcher. They replace Provider.limits and the Claude and Codex branches in ingest.rs and the sidebar. The Antigravity reader stays off, now commented in its adapter.
  • text_generation_launch: each adapter's tool-free launch for text generation, which was a match in text_generation.rs.
  • probe_session_meta, copies_skills, and the worktree followed hook, which was a Claude branch in switch.rs.
  • Each agent's subagent Provider now lives in its adapter module. The opencode module is always compiled, as codex and antigravity already were.
  • antigravity_full_access is now launched_full_access in code. It is saved under the old key, so state files stay compatible both ways.

Claude Code's own records

The second commit moves the Claude Code code that was still in the core:

  • NativeSessions: an agent's own record of its sessions. The busy, idle and waiting statuses the activity poll and pending worktree switches read, the session names m4code writes, and the transcript check for resuming. Claude Code's registry cache now lives in its adapter.
  • reports: the figures sessions report outside ACP. Claude Code's mod snapshots are now SessionReports, and ingest.rs applies any adapter's reports.
  • tidy: each adapter's start-up cleanup of its old files in m4code's data folder.
  • claude_exe is now executables, each adapter's discovered executable. An adapter with custom_path (Claude Code's) is found at once, as before. The others are found in the background, because looking can start a login shell. Each adapter's probes now get its own executable instead of Claude Code's.
  • The store keeps the keys older versions read, but only its accessors know which one is Claude Code's: Settings::executable_path, Data::usage_pools and Data::merge_usage_pools.
  • The Windows priority raise is named for every agent, which it already covered.

Two small behavior changes. A harness whose CLI is on the PATH now counts as available for auto-handoff without a cached model list. Startup no longer looks for the other agents' executables on the UI thread.

Still in the core: the Claude Code pages of the setup window and Settings (its path field, output limits, costly-settings findings, advisor and background-compaction switches) and the sidebar's Claude usage row. They are Claude Code features with their own UI, not rules about actions.

Verification

  • cargo clippy --locked --all-targets -- -D warnings is clean.
  • cargo test: 605 unit tests passed on the final commit, including new ones for the handoff rules.
  • Headless tests (cargo test -- --ignored --test-threads=1) on the final commit: 41 passed, 5 failed. Four start the real Claude Code, Codex and OpenCode CLIs, and each stops with "The adapter did not discover m4code's MCP tools before the startup deadline." Under cargo test, current_exe() is the test binary, which has no --mcp-title entry point, so the agent can't reach m4code's MCP server. The fifth, github::e2e, hit a GitHub GraphQL server error while creating a pull request; it passed on the first commit. I didn't rerun these on main.
  • No screenshots: nothing is refused yet, so no view looks different. The follow-up screenshots the refused states.

Risk

Low. Every real adapter declares Capabilities::ALL, so every new check passes. The most likely place for a regression is the usage-limit move in ingest.rs. Reading, merging and storing now go through stored_pools and store_pools, which keep Claude's usage in claude_usage and every other agent's under its key, as before.

Adds Capabilities to Adapter and checks it before rewind, fork, fresh
sessions, compaction fallback, text generation, handoffs and subagents.
Moves sign-in, usage sources, text-generation launches and other
per-harness branches out of the core into the adapters. Every adapter
still allows everything, so behavior is unchanged.

Part of #152.
@vercel

vercel Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
claudiu Ready Ready Preview Nov 28, 2026 1:23am UTC

Adds NativeSessions (statuses, name writes, transcripts), SessionReport
readers and a tidy hook to Adapter, and replaces claude_exe with each
adapter's discovered executable. The store reads usage per harness
through one accessor, keeping the keys older versions read.
@m4rocks
m4rocks merged commit c1cf16a into main Nov 28, 2026
5 checks passed
@m4rocks
m4rocks deleted the adapter-capabilities branch November 28, 2026 02:24

This branch was successfully deployed

1 active deployment
Preview — 2de956e3 Deployed Nov 28, 2026 by vercel[bot]
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