Skip to content

Add plugin cli-agent-bridge - #7

Open
Hylouis233 wants to merge 49 commits into
MiniMax-AI:mainfrom
Hylouis233:plugin/cli-agent-bridge
Open

Add plugin cli-agent-bridge#7
Hylouis233 wants to merge 49 commits into
MiniMax-AI:mainfrom
Hylouis233:plugin/cli-agent-bridge

Conversation

@Hylouis233

@Hylouis233 Hylouis233 commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Migrated from hetaoBackend/MiniMax-Code-Plugins#16; the earlier review history remains there. Current head: 902b194.


What changes

Adds the hosted Plugin plugins/Hylouis233/cli-agent-bridge: a dependency-free stdio MCP server
and same-name Skill that let MiniMax Code delegate bounded coding tasks to locally installed
Claude Code, Codex CLI, Kimi Code, ZCode, or DSH processes inside a Git repository, then review
the resulting workspace and commit changes.

The server exposes three tools:

  • list_backends reports configured CLIs, availability, versions, and experimental notes.
  • workspace_status returns a bounded Git snapshot: status, staged/unstaged diff stats, changed
    files (including untracked paths), HEAD and symbolic HEAD, and refs.
  • delegate_task runs one backend and returns bounded output, before/after Git snapshots, moved
    refs, and an attributed commits block. Dirty worktrees are rejected unless allowDirty=true;
    unsupported resume requests fail instead of silently starting a fresh session.

Safety and concurrency behavior

  • Calls targeting the same Git common directory serialize across subdirectory aliases, symlinks,
    linked worktrees, independent MCP clients, and bridge processes. Independent clones can run in
    parallel.
  • Coordination state lives in a private bare lock store under the Git common directory and never
    enters the target repository. Lease acquisition and recovery use compare-and-swap owner records;
    uncertain worker termination fails closed behind a shared quarantine marker.
  • Cancellation and the overall deadline cover discovery, lock waits, snapshots, the backend, and
    post-run attribution. The supported Windows path uses a kill-on-close Job Object and confirms
    tree termination before releasing the repository lease.
  • Git attribution handles unborn HEADs, symbolic-HEAD changes, force-moved and non-commit refs,
    fetched history, more than 256 baseline tips, linked worktrees, submodules, unusual path bytes,
    and staged/untracked changes without presenting truncated evidence as complete.
  • Trace2 worktree resolution is interruption-aware, yields during large session sets, caches
    repeated identities, and fails commit attribution closed when a POSIX realpath cannot be proven.
  • The server makes no network calls and stores no credentials or session logs. The selected backend
    CLI uses the user's own authentication and may send task/workspace data to its provider.

Requirements and platform disclosure

  • Node.js 20 or newer and Git on PATH; the target workspace must be a Git repository.
  • Production delegation and workspace inspection are supported on Windows. Linux, macOS, and BSD
    fail closed before backend configuration, workspace access, Git resolution, or executable
    probing because this dependency-free server cannot prove containment after an arbitrary local
    worker asks a host service to launch outside its original process tree.
  • Backend CLIs must already be installed, authenticated, and configured by the user. Claude,
    Codex, and Kimi templates are non-experimental; ZCode and DSH remain explicitly experimental.
  • No credentials, installers, native binaries, private endpoints, or telemetry are bundled.

Latest review follow-ups

Current head also closes the review gaps left after the earlier Copilot follow-up:

  • workspace-lock deadline and cancellation failures return structured MCP results;
  • Trace2 session resolution continues observing cancellation/deadlines and does not leave a late
    rejected realpath promise unhandled;
  • repeated worktree identities are cached, while unresolved POSIX identities fail attribution
    closed;
  • the Trace2 capability probe reads raw emitted events instead of invoking the parser under test;
  • environment-gated tests return immediately after context.skip();
  • the Windows workflow invokes the four explicit test files, and both CI checkout pins use the
    canonical 40-character actions/checkout@v7.0.1 commit SHA.

Verification

Verified locally on current head 902b194:

  • npm run validate: all 9 hosted Plugins and both examples validated.
  • Explicit cli-agent-bridge suite: 219 tests, 199 passed, 20 platform-specific skips, 0 failed.
    The skips are Windows-only or other OS-specific fixtures on the macOS verification host.
  • Four focused Trace2 regressions all executed and passed: bounded/interrupted provenance,
    unresolved-identity fail-closed behavior, successive fetch detection, and partial-fetch
    uncertainty.
  • node --check passes for the server and integration test file.
  • actionlint reports zero diagnostics for .github/workflows/ci.yml.
  • git diff --check is clean.

The upstream PR currently has no GitHub-hosted Windows run for this head. The workflow is present
and statically validated, but no hosted runner result is currently available. No skipped
[code]smith check is being presented as test evidence.

Submission checklist

  • Plugin path, manifest name, license, examples, requirements, platforms, accounts, network/data
    behavior, and experimental backends are disclosed.
  • No scaffold TODOs, credentials, symlinks, installers, or native binaries are included.
  • Repository validation and the local current-head plugin suite pass.
  • GitHub-hosted Windows job passes on the current head.

View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

Hylouis233 and others added 30 commits August 15, 2026 17:03
Delegate coding tasks from MiniMax Code to locally installed coding CLIs (Claude Code, Codex, Kimi Code, ZCode, DSH) through a dependency-free stdio MCP server with git-diff review. See NOTICE for upstream credits.
- claude template gains --permission-mode acceptEdits so headless runs can
  actually edit files (verified end-to-end with Claude Code 2.1.226)
- kimi keeps plain -p prompt mode: --auto/-y are mutually exclusive with -p
  on current Kimi Code versions
- git snapshot now lists untracked files (git ls-files --others) so new files
  created by workers appear in changed files
- README/SKILL document permission defaults and honest backend verification
  status
npm-style .ps1/.cmd shims cannot be spawned directly on Windows, so runCommand retries them through the bundled ps1-runner.ps1 (Windows PowerShell 5.1) with verbatim argument forwarding. README documents the fallback and the custom-wrapper caveat.
- per-workspace serialization of delegate_task
- SIGTERM then SIGKILL force kill after timeout grace
- snapshots include staged, untracked files and committed deltas
- delegate_task marked destructiveHint, isError on failures
- notifications/cancelled kills the worker
- honest protocol version negotiation
- fail closed when git snapshot commands fail
- ring-buffer output capture without repeated large copies
- README discloses supported operating systems
SKILL workflow and README tool description now cover before/after snapshots, committed deltas, same-workspace serialization, isError semantics, force-kill timeouts, and cancellation.
Seven self-contained tests cover protocol negotiation, tool list, snapshots, dirty-tree guard, unknown backends, cancellation, and before/after snapshots. SKILL wording now notes same-workspace serialization.
- workspace lock is now keyed by the canonical realpath of the git worktree
  root (git rev-parse --show-toplevel + fs.realpath), so the same checkout
  reached via a subdirectory, casing, or symlink shares one mutex (P1)
- a delegation cancelled while queued for the lock re-checks the cancel flag
  after acquiring it and returns before spawning the worker (P1)
- timeout and cancellation now terminate the whole process tree: taskkill
  /PID /T /F on Windows, signal to the detached process group on POSIX,
  instead of only killing the top-level child (P1)
- git snapshots tolerate an unborn HEAD (fresh git init) and committedDelta
  reports the first commits when the worker started from no commits (P2)
- codex templates delimit the prompt with -- so option-like tasks are not
  parsed as CLI flags (P2)
- README comparison example now requires two independent git worktrees; the
  queued same-checkout second run is documented as follow-up work (P2)
- SKILL resume guidance no longer implies results carry backend session ids

Tests extended to 11 (protocol, tools, snapshots, dirty guard, unknown
backend, in-flight cancel, before/after, worktree-root lock serialization,
cancel-while-queued, unborn HEAD, codex -- delimiter); 3 consecutive runs
green locally
- gitSnapshot/committedDelta executed their git commands via Promise.all;
  git status and git diff both refresh the index, so concurrent processes
  raced for .git/index.lock and intermittently failed with exit code 128,
  surfacing as random 'git snapshot unreliable' errors (reproduced 1-in-15
  on Windows; the fail-closed guard turned it into a JSON-RPC error)
- commands now run serially per repository; 10/10 Windows runs and a full
  npm run check in a Linux node:22 container pass
- test harness: every server now stops in a finally block (a leaked server
  kept stdin/stdout pipes open and hung node --test when an assertion
  failed - the cause of the stalled CI validate job), in-flight cancel test
  bounds its worker with an explicit timeoutMs
…ribution

- disclose repository concurrency: linked worktrees share refs, so snapshots
  detect other active leases plus completed runs' history records and mark
  attribution as potentially overlapping (repositoryConcurrency)
- attribute only genuinely new commits: ranges exclude all pre-delegation
  refs, so a branch checkout is reported as a HEAD move with no new commits,
  and non-commit refs (blob tags) are reported without failing the run
- verify process identity before signaling: Windows tracks creation times,
  POSIX groups are signaled only while the original leader identity matches,
  and reused PIDs are dropped from the tracked tree
- make lease state updates interruptible by the request cancellation/deadline
  and resync the interrupted release by owner token
- move quarantined leases to a recoverable state: removing the quarantine
  marker authorizes the next delegation to reclaim
- catch process-tree inspection failures in the close handler (fail closed
  instead of an unhandled rejection) and slow the Linux /proc monitor to 250ms
- tests: 55 total (checkout attribution, blob refs, concurrency disclosure,
  lease interruption, quarantined reclaim, PID-reuse identity)
- deduplicate HEAD and branch-ref targets so a commit on the checked-out
  branch is logged, diffed, and counted once with both labels
- diff new refs from their merge-base with the pre-delegation state, so a
  branch forked from a divergent branch never attributes pre-existing
  differences to the worker
- register list_backends in activeRequests and terminate a hanging version
  probe on cancellation, skipping the remaining probes
- signal the process group when enumeration is unavailable (containment wins
  when identity cannot be verified)
- strip only Git's line terminator from rev-parse --show-toplevel so a
  worktree root ending in whitespace canonicalizes correctly
- tests: 60 total, all green locally
Add cross-process repository locking, fail-closed process containment, safe Git attribution, explicit quarantine recovery, Windows Job Object execution, and regression coverage for reviewed lifecycle and documentable safety boundaries.
Copilot AI lite review requested due to automatic review settings August 19, 2026 09:16

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@hetaoBackend hetaoBackend left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please address the repository-scope regression before merge:

This plugin changes the root package.json test script from node --test to node --test --test-concurrency=1. That changes test execution semantics for every existing plugin and masks concurrency regressions globally. Please move the serialization requirement into the cli-agent-bridge-specific test command/fixtures, or provide a repository-level justification and regression evidence showing why all tests must become serial.

The plugin is Windows-only and that limitation is disclosed; the blocking issue here is the unrelated root-level test behavior change. The current [code]smith check is SKIPPED.

@hetaoBackend hetaoBackend left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

当前 head 18e26e2 的自带 suite 实测为 218 tests:194 pass、4 fail、20 skipped,仍有阻塞:

  • a cross-process lock waiter obeys the delegation deadline 在 tests/server.test.mjs:2458 得到缺失 result,随后 TypeError: Cannot read properties of undefined (reading structuredContent)。
  • provenance reads are bounded and interruptible、successive fetches are detected even after FETCH_HEAD is overwritten、a partially successful nonzero fetch makes provenance uncertain 均实际 sawFetch: false,未达到预期的 fail-closed 证据。
  • 插件声明 production 仅支持 Windows,但跨平台/Trace2 相关测试没有正确 gate;Windows Job Object 路径在当前环境被跳过。需要修复这些测试/实现问题,或提供可靠的目标平台 CI 证据,不能在所有 [code]smith Checks 为 SKIPPED 时放行。

请先解决 deadline/provenance 失败并补足 Windows 运行证据,再重新提交。

Hylouis233 and others added 4 commits August 30, 2026 02:08
…est script.

These tests share git/tmpdir fixtures and deadline-sensitive waits, so they take turns via an exclusive directory lock while the repository-wide `node --test` runner stays file-parallel.
…ck so Node 22 file-parallel runs cannot skip-fail.
Return structured lock-deadline MCP results and realpath-aware Trace2 worktree matching.
@Hylouis233

Hylouis233 commented Aug 30, 2026

Copy link
Copy Markdown
Contributor Author

Head 1a4dfb0 relative to the previous 18e26e2 run:

  • Cross-process lock deadline: withWorkspaceLock / delegateTask / the tools/call handler treat WorkspaceLockDeadlineError and cancellation as structured MCP results. A waiter that reaches the delegation deadline returns { timedOut: true, error: /waiting for the workspace lock/ } instead of an undefined tools/call payload.
  • Trace2 fetch provenance: worktrees are matched by resolved path plus POSIX realpath, so a fetch recorded under a tmpdir symlink sets sawFetch: true. Windows skips realpath so the case-sensitive identity fixture stays fail-closed.
  • Tests: Windows-only skips carry an explicit reason; successive and partial fetch tests pass gitWorktreeRoot into readBackendGitProvenance and skip only if a local Trace2 probe cannot prove a fetch.
  • Root package.json remains "test": "node --test". Plugin suites serialize through tests/plugin-test-lock.mjs instead of changing repository-wide concurrency.

The Windows Job Object path remained platform-gated on this head, and no new Windows CI log was available at that point.

@Hylouis233

Hylouis233 commented Aug 30, 2026

Copy link
Copy Markdown
Contributor Author

Head 9d80ab1 added windows-cli-agent-bridge on windows-latest in .github/workflows/ci.yml.

The job was configured to invoke the cli-agent-bridge test directories. The existing Ubuntu validate job and the root package.json command ("test": "node --test") were unchanged on that head.

@Hylouis233

Copy link
Copy Markdown
Contributor Author

Current head is 902b194 (b1b89e1 production/tests + 902b194 Windows CI command).

This follow-up closes the three review threads left on the merged fork PR:

  • Trace2 session resolution now uses interruptible thunk-started realpath calls, caches repeated identities, yields/re-checks cancellation and deadlines, and fails POSIX identity errors closed.
  • Both environment-gated tests return immediately after context.skip().
  • The capability probe inspects raw Trace2 events independently; setup/Git/I/O/parse errors now fail instead of being cached as “unsupported”.
  • The Windows job runs the four explicit test files rather than passing directories to node --test; both CI checkout pins now use the canonical 40-character v7.0.1 SHA.

Current-head local evidence:

  • npm run validate: 9 hosted Plugins + both examples validated.
  • Explicit cli-agent-bridge suite: 219 total, 199 passed, 20 OS-specific skipped, 0 failed.
  • Four focused Trace2 regressions: 4 passed, 0 skipped/failed.
  • node --check, actionlint, and git diff --check: clean.

The PR body now reflects the actual head and Windows-only production support. It explicitly leaves the GitHub-hosted Windows run unchecked; no skipped [code]smith result is being presented as CI evidence.

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.

4 participants