fi.gy

Agent IDE control — replacing shell-outs with a live editor session

2026-11-23

Status: Phases 1, 2 and 2.5a are implemented. The 24 November UX/safety pass (Phase 2.5b) is now local: three resizable panel sections, exact-target lease rows, a user-centric approval dialog, no approval timeout, exact file scopes, deterministic Authorization lines and Herdr mod checks inside setHerdr. The current release candidates are 2026.11.24.4; they are not published yet.

Goal: give a swamp-driven agent the same hands and eyes in a running editor that a human pair programmer has — search, read, edit, create, run, debug, annotate, and later point — without spawning a shell process per action.

Note: This is another in my experiments into MyUserExperiences - I havn't documented most of them, but they included a browser UI, a GUI app that heads towards a Smalltalk browser-like UI, a series of workflow specific micro-GUIs, and .. lately, an 'nn'-based information/workflow/behaiviour/news/todo UI. Somewhere on this list is going to be voice but .. so many thing to try.


UX and safety pass — 24 November 2026

The latest work has been less about adding methods and more about making the live IDE safe and legible. The earlier sections below remain the design record; this is what the current local build feels like.

The right-hand panel is three sections, not tabs

The Swamp IDE panel is now three vertically stacked, independently resizable sections: Activity, Command histogram and Leases. The whole column is horizontally resizable too. Selecting one no longer hides the others.

  • Activity keeps the routed/bypass/error filters.
  • The histogram lists programs and counts only. Hover or click a program to expand its ten most common command invocations; the old side-by-side programs-and-commands bars are gone.
  • The Leases section is a first-class part of the panel, not a hidden debug tab.

Leases are human-only targets

A lease row now carries a purpose and a risk, and the row label wraps instead of truncating the purpose. Expanding a lease shows its exact targets, expiry, purpose and risk in a capped detail area with its own always-visible scrollbar. Raw scopes are labelled by target, not just by file-edit or protected:.

Clicking a lease toggles it. The expanded row offers +5m, +30m, +1h and a two-click revoke; an until-revoked lease offers only revoke. Extending a feature extends every scope in it. Approved requests become named features, so the list says what the lease is for rather than only which scope it carries.

The approval dialog explains the grant

The dialog now starts with You are granting, then an explicit Target: the exact file, exact command, swamp method, or a loud NO specific file warning for a broad method grant. It then shows:

  • what the agent may do;
  • what it may not do;
  • a HIGH/MEDIUM risk rating with concrete reasons;
  • how to undo or revoke it;
  • the agent's reason and goal, followed by the technical action and command.

The approval request no longer expires. You can walk away and come back; the dialog waits for Approve, Deny, Explain, Copy, closing, or cancellation of the tool call.

Commands and files are constrained

Non-protected edits now use an exact file:<absolute path> scope. Broad file-edit and broad protected grants are rejected: a lease names the file, not "any file". The dialog and lease rows show that path.

Mutating calls must include a reason and a goal. Shell wrappers (sh -c, bash -c, etc.) are rejected before approval because they hide the real command; the request must show the complete exact argv or a committed script whose contents were shown. Every swamp_ide result now begins with a deterministic Authorization: line generated by the addin, and the same structured fields go to the activity log and OTLP span. The addin prompt tells the assistant to quote that line rather than invent an explanation.

setHerdr now runs herdr-app check against the activity, panel and approval mods before switching layout, and fails without switching if any check fails. There is no separate "Herdr check" approval loop.

Current release state

The local release candidates are 2026.11.24.4 for both @svendowideit/swamp-ide and @svendowideit/swamp-ide-pi-plugin. Tests pass (17), the Deno-checkable modules pass, formatting and both workflows pass, the meta-factory scores are 94/100, and both dry-runs are clean with adversarial reviews recorded. Nothing has been pushed to the registry yet.


What changed since this plan was written

This started as a design document. It is now partly built, running locally, and observable. The plan below is kept as the design record; this section is the progress report.

Structure

@svendowideit/swamp-ide is now the single front door. It pulls in herdr-core and vim-controller and exposes one enable/disable pair: swamp workflow run @svendowideit/swamp-ide-enable (or ...-disable). The pi addin lives in @svendowideit/swamp-ide-pi-plugin; the OpenObserve dashboard lives in @svendowideit/swamp-ide-openobserve and is only used when OpenObserve is installed and healthy. The old @svendowideit/vim is now @svendowideit/vim-controller; the plan text below keeps the old name for history.

Built

  • @svendowideit/herdr-core — 21 methods: status, terminals, read, run, send, keys, interrupt, kill, rm, put, wait, exec, file-read, file-write, file-edit, file-edit-lines, search, machines, machine-add, machine-remove, otel-status. It fans out internally, edits files exact-once or by known line range, runs commands locally or on a herdr-core machine, and writes typed swamp data. Tests and meta-factory 96/100 (A) pass.
  • @svendowideit/vim-controller — 17 methods: servers, open, status, read, edit, write, cursor, annotate, select, diff, command, expr, keys, diagnostics, undo, close, otel-status. It bundles a small Vimscript runtime, opens Vim in a herdr-core terminal, applies exact-text or line-range edits in one call, and returns the undo sequence and a unified diff. annotate draws a line-level virtual label plus a column highlight. Tests and meta-factory 91/100 (A) pass.
  • The swamp-ide front door — @svendowideit/swamp-ide installs the Herdr activity panel/layout, and @svendowideit/swamp-ide-enable / -disable call the pi plugin and the optional OpenObserve page. One command enables or disables the whole system.
  • The pi addin plugin — @svendowideit/swamp-ide-pi-plugin owns the installed .pi/extensions/swamp-ide.ts and the per-session gate; it refuses to overwrite or remove a file it did not mark as managed. The addin itself is the swamp_ide tool described in the next bullet.
  • The OpenObserve page — @svendowideit/swamp-ide-openobserve owns the Swarm Agent IDE dashboard; @svendowideit/openobserve remains the general SQL/streams client.
  • A pi addin (.pi/extensions/swamp-ide.ts) — exposes one swamp_ide tool, adds prompt rules that prefer it over bash/read/write/edit, and can block bypass tools in enforce mode. It records every finalized tool call as an OTLP span, including the ones that did not go through the system.
  • The serve fast path — the addin now opens one swamp serve WebSocket per pi session and sends model.method.run directly. A status call returned in 164 ms through serve (via: serve) in the runtime harness. The CLI is a fallback only when the connection cannot be established; a request that was already sent is never retried through the CLI. OTEL settings are read with data.get over the same socket.
  • The shell-out histogram — every bash tool call is split into shell segments and its executable is appended to ~/.local/state/swamp-agent-ide/shellouts.jsonl, with program, subcommand, bypass/other category, outcome, session and cwd. /swamp-ide shows the top five; /swamp-ide histogram shows the top twenty. The OTLP span also carries swamp.agent.shell.program, .subcommand and .category, so the dashboard can group the same data.
  • The observability loop — both extensions default to @svendowideit/otel-settings for the OTLP endpoint, mesh and bearer token, then fall back to the standard OTEL environment. otel-status reports why tracing is on or off; otel-status test=true posts one test span. A test span returned HTTP 200 against the current https://otlp.fi.gy gateway.
  • An OpenObserve dashboard — Swamp Agent IDE at https://obs.otel.fi.gy/web/dashboards/view?org_identifier=default&dashboard=7530524594227118080&folder=default. Panels: routed vs bypassed, operations by route, recent bypassed calls, recent routed calls, recent errors. At the time of writing it showed 41 routed spans, one deliberate bypass demo, one older "other" span, and eight routed errors.
  • Reports and line edits — @svendowideit/terminal-session and @svendowideit/edit-session render the method data (run, commands, files, search, diff, undo sequence) as review artefacts. herdr-core file-edit-lines replaces known line ranges with expectedLines/expectedHash checks, so an edit follows a search/read rather than guessing exact text. Vim gained select and diff.
  • A live Herdr activity panel — the swamp-activity mod in the swamp-ide layout reads the shared JSONL event log and lists every agent tool call and extension method, newest first: green for routed herdr-core/vim, red for bypassed built-ins, with filters for routed, bypass and errors. The current session is gated by a per-session marker, so other pi sessions stay unaffected.

What the implementation changed about the plan

  • Vim was enough locally. Vim 9.1 with +clientserver already supports read/edit/annotate/diagnostics through --remote-expr; switching to Neovim is not required for the local case. Neovim is now a fleet/remote option, not a prerequisite.
  • Editing uses --remote-expr, not keystrokes. hc keys cannot express punctuation such as :, so typing into Vim would be the wrong primitive. The Vim adapter plans the edit in TypeScript, then applies it with one SwampVimSetLines call. That also gives exact-once checks and a diff.
  • open uses herdr-core to host Vim. Vim needs a terminal to stay watchable; the extension starts it with hc run --bg and a stable --servername. vim --serverlist returns upper-case names, while --servername is case-insensitive; the adapter compares case-insensitively.
  • Vim annotations need col=0. prop_add rejects text_align on a non-zero column. The runtime now draws the virtual label at column 0 and a separate highlight mark at the requested column. The runtime has a version (SwampVimRuntime()), so a running server is re-sourced when it changes.
  • OpenObserve exposes a fixed trace schema. Arbitrary span attributes such as swamp.route are not columns there. The addin therefore encodes the route in the span name: swamp_ide.herdr-core.<method>, swamp_ide.vim.<method>, bypass.<tool>, and tool.<tool>. The dashboard groups on service_name, operation_name and swamp_outcome, all real OpenObserve columns.
  • Session scoping is a pi concern. The swamp extensions are repo-local and available to swamp runs in this repo. The pi addin is gated by a marker file per PI_SESSION_ID, so it can be enabled for one session and remain inert in every other and new session.
  • Herdr mods and layouts are client-side. Installing the activity panel into x1yoga's ~/.config/herdr-app did not make it appear in a herdr-app running on p1gen4. The mod and layout files belong to the machine running the app; the space/tab/pane state belongs to the core. A remote install must target the app's host as a swamp step (or a worker), not copy files into the orchestrator's home. That p1gen4 install is deferred for now; the local x1yoga app has the panel.

Release state

The five extensions were published to the swamp registry on 2026-11-23:

Extension Version Tests Meta-factory Content hash
@svendowideit/herdr-core 2026.11.23.2 passing 96/100 (A) 19eae9…
@svendowideit/vim-controller 2026.11.23.2 passing 91/100 (A) ca5883…
@svendowideit/swamp-ide 2026.11.23.1 passing 95/100 (A) 02df71…
@svendowideit/swamp-ide-pi-plugin 2026.11.23.1 passing 94/100 (A) fce27f…
@svendowideit/swamp-ide-openobserve 2026.11.23.1 passing 92/100 (A) ffe8ca…

The OpenObserve dashboard now lives in swamp-ide-openobserve; @svendowideit/openobserve is the unchanged general SQL/streams client. The old @svendowideit/vim name is retained only in the historical plan text.

Honest gaps

  • exec --on xeon is wired but was only exercised locally in the final pass.
  • The pi addin defaults to advise; enforce (blocking bypass tools) is opt-in.
  • The serve fast path is implemented and installed; the CLI remains the fallback when no serve is reachable.
  • The shell-out histogram is built. Its first records are from a test harness, so the first real prioritisation pass should wait for a day of normal use.
  • The p1gen4 Herdr app has no activity panel yet; its mod/layout install needs a swamp step placed on that host, not a local x1yoga install.
  • Phase 2.5b (git mv hygiene and the release rename check) is still open.
  • The VS Code bridge, Neovim adapter, DAP client, and literal second pointer are still plan items.

1. Why: the request

Shelling out is how the agent reaches the machine today, and it is the part of the loop that feels least effective. It is not that the commands are wrong. It is that every action is a fresh process that knows nothing about the last one, returns text that has to be re-parsed, and leaves no shared state with me or with the editor. The agent spends its effort reconstructing a world instead of changing it.

Six specific costs:

  1. A process per thought. rg, cat, sed, apply_patch, npm test, gdb — each is a process start, a cwd, an environment, and a text pipe. Swamp's own datastore lock serialises concurrent invocations (30 s TTL, 1 s retry, 60 s max wait), so a chatty agent turns into a queue. The swamp-ui.md measurement — ~0.4 s for a no-op swamp model search --json on a warm machine — is the floor before any work happens.
  2. Text is a lossy interface. rg gives lines, not a stable buffer identity. cat loses the cursor, selection, folds, and diagnostics. sed has no undo group. apply_patch has no line numbers, no selection, no conflict detection against what I typed a second ago.
  3. Neither side knows what the other did. The editor does not know the agent edited a buffer; the agent does not know I am mid-edit. The result is races, stale reads, lost undo, and the familiar "it worked when I ran it" gap.
  4. I cannot watch it work. The request explicitly includes "I often watch the thinking/working." A shell-out is invisible until it prints. A live session should show the agent's cursor, selection, annotations, and edits as they happen, while still producing a diff and an audit record afterwards.
  5. Debugging by print is guesswork. Shell-based debugging is printf, rerun, squint. There are no breakpoints, no stack, no scopes, no variables, no conditional breakpoints, no watch expressions. A debug adapter is a structured protocol for exactly this, and no swamp extension exposes one.
  6. The fleet makes it worse. An ssh host '...' command is a distributed system disguised as a pipe: quoting, per-host tool versions, no shared session, no way to see what happened on the other side. The fleet (macmini, xeon, eieio) is already connected through herdr-core; shelling out over SSH ignores that.

There is also a safety and review cost. A shell edit is not atomic, not exact-once, not undoable as a group, and not attributable. A live editor API can offer all four.

What I want is not a better shell wrapper. It is a session: an editor that stays running, an agent that can ask it structured questions and make structured changes, a human who can watch or review a diff later, and data that records what happened. The terminal runtime for that session already exists — herdr-core — and the missing piece is the swamp extension that exposes it, plus an adapter for the editor I actually use.

This document records what was checked, the options, the recommended split of ownership, and a phased plan with verification.


2. Ground truth checked

2.1 herdr-core is the persistent session layer

herdr-core 0.1.21 (hc) is already a background server that owns terminals, their processes, their scrollback, and a fleet of other machines. Its API is JSON-RPC over a Unix socket; the CLI is a thin client. The parts that matter here, from hc --help and hc schema:

Need Primitive
run a program in a persistent terminal terminal.run / hc run (--bg, --cwd, --label, --on, --keep)
see it terminal.read (screen, lines of history), terminal.wait, terminal.wait --output
type into it terminal.send (paste + Enter), terminal.keys (named keys), terminal.attach (raw DATA stream)
files file.read, file.write (atomic), file.edit (exact-once, all-or-none per file)
processes without a terminal machine.exec (argv as given, timeout, exit code, base64 stdout/stderr)
other machines machine.add/list/connect/rename/rm, --on <machine> on exec/file
shared sessions the server owns the pty; clients attach; multiple clients are documented for Herdr
pairing etiquette terminal.send waits for a human's unfinished draft (up to 60 s), otherwise ~3 s quiet

The current fleet is connected and usable:

$ herdr-core machine ls
macmini   connected  0.1.18
xeon      connected  0.1.18
eieio     connected  0.1.18

Local is 0.1.21. That skew is a design input, not a footnote: every method must negotiate capabilities from hello / rpc.discover and fail clearly when the remote lacks one.

Two honest limits found by probing:

  • hc keys cannot type punctuation. On 0.1.21, h, e, space, backslash, ctrl+c work; :, minus, comma, semicolon, bracketleft are rejected as unknown keys. hc send always appends Enter. So "drive Vim by keystrokes" is not solved by the CLI today. Raw terminal.attach DATA (SGR mouse sequences included) is the escape hatch, but it is a stream, not a request/response method.
  • send/keys are debounced (~3 s quiet, or until the human's draft is clear). That is the right policy for handing a whole command to an agent, and the wrong tool for character-level pairing.

2.2 Vim is already controllable on this host

Local Vim 9.1 has +clientserver, +channel, +terminal, +textprop, +quickfix, +signs, -lua. The session is Wayland (niri) with XWayland: DISPLAY=:0.

A probe started Vim inside a herdr terminal and drove it from outside:

herdr-core run --bg --name zz-probe-vim --cwd /tmp/zz-probe-vim \
  vim --servername zz-probe-vim -n f.txt

vim --serverlist
# ZZ-PROBE-VIM

vim --servername zz-probe-vim --remote-expr 'getline(1,"$")'
# one
# two

vim --servername zz-probe-vim --remote-expr 'setline(2,"TWO")'
# 0

vim --servername zz-probe-vim --remote-expr 'execute("write")'
# "f.txt" 2L, 8B written

The file became one\nTWO. This is the important result: we do not need Neovim for live local editing. Vim's server can read lines, replace lines, append/delete, move the cursor, execute Ex commands, inspect &modified, read the quickfix/location lists, and — because 9.1 has +textprop — draw virtual text, highlights, and signs for the agent's cursor and annotations. A batch of edits can be one --remote-expr call to a Vimscript function, so it is atomic for that buffer and one round trip.

Caveats, all real:

  • A Vim server must be started with --servername. A Vim already running without one cannot be discovered or attached; there is no way to add clientserver to a live process. The adapter can open a Vim session (in a herdr terminal) or the human can restart Vim with a server name.
  • +clientserver is X11-bound on Unix. It works here through XWayland. On a headless host with no DISPLAY it does not.
  • --remote-expr 'execute("qa!")' fails because the server disappears before replying; quit/close needs --remote-send (and no reply), not an expression.
  • --remote-expr is serialised with human input: it runs when Vim is not busy. That is good for pairing (the agent waits for me) and bad for latency if I am typing.

2.3 Vim across the fleet

Checked with herdr-core exec --on:

Host Vim +clientserver +channel +textprop DISPLAY nvim code
local 9.1 + + + :0 (XWayland) no 1.144.0
macmini 9.1 (system) − + + none no none
xeon 9.1 + + + none no none
eieio 9.1 − + + none no none

So the Vim clientserver adapter is local-only. The fleet needs one of:

  • herdr-core file/exec methods (no live editor view, but portable), or
  • a small Vim +channel plugin that listens on a socket and evaluates JSON requests (all four hosts have +channel), or
  • Neovim installed on the fleet and driven over msgpack-RPC (portable, richer, no X11).

Neovim is not installed anywhere today. Installing it is a deliberate step, not a prerequisite for Phase 1 or the local Vim adapter.

2.4 VS Code

VS Code 1.144.0 is installed locally, not on the fleet. Its CLI opens, reuses, diffs, and goes to a line (code -g, code -d, code -r) but has no command execution surface. Driving a running VS Code semantically requires a bridge extension inside VS Code that exposes the public API (vscode.commands, WorkspaceEdit, tasks, terminals, diagnostics, vscode.debug) over a local socket. CDP (--remote-debugging-port) can click the UI, but it is version- fragile and cannot use the editor API; it is a fallback for opening, not the design.

2.5 Existing extensions and prior art

Artifact What it actually covers What it does not
@magistr/herdr the herdr TUI API: workspaces → tabs → panes, snapshot, prompt, send-keys, send-text, run-command, wait-output, create/close not herdr-core's terminal.* API; no file ops; no exec; no machine fan-out
@svendowideit/herdr-app install/update/remove the app and herdr-core not a runtime wrapper
@jpisgeek/rex-herdr Rex terminal installer/status not a swamp runtime
@jpisgeek/herdr-swamp-layout Herdr UI layout not control
@swamp/*, community registry no general editor, LSP, DAP, or code-search type the gap this plan fills

@magistr/herdr is good work and should not be forked; it solves a different API. If its TUI methods need raw text/mouse, that is an upstream issue/PR, not a new local fork.

2.6 Display and input

  • Local: Wayland (niri), XWayland available for X11 clients such as Vim clientserver.
  • Windows and Visual Studio are deferred by the request.
  • Wayland has no portable second pointer. X11 can have one (uinput + XInput2 master pointer). macOS and Windows have one. A literal second cursor is therefore a later, platform-specific feature; the design should not pretend otherwise.

3. Options

Option What it is Best for Cost Main risk Verdict
A. @svendowideit/herdr-core Swamp model over the hc API: terminals, send/keys/read/wait, file read/write/edit, exec, search, machines Replacing ls/cat/sed/rg/npm test shell-outs; fleet fan-out; shared sessions M TUI input limits; no semantic editor state Build first
B. @svendowideit/vim Vim clientserver adapter: buffer read/edit, cursor, annotations, quickfix, undo Live local editing in the editor I already use M X11-bound; requires --servername; local-only Build second (local)
C. Neovim adapter msgpack-RPC over a socket: buffers, extmarks, LSP, nvim-dap, portable Live editing on the fleet/remote; richer annotations M–L Install everywhere; another runtime Only when fleet live editing is needed
D. @svendowideit/vscode + bridge VS Code extension exposing JSON-RPC; swamp model calls it Commands, WorkspaceEdit, tasks, terminals, debug UI, diffs L Maintaining a VS Code extension; workspace trust Build after A+B, when VS Code is the target
E. @svendowideit/dap Standalone Debug Adapter Protocol client; debugpy, dlv dap, lldb-dap, js-debug Real breakpoints/step/variables, headless or CI L Per-language lifecycle When breakpoints matter
F. @svendowideit/desktop-input OS keys/mouse/screen/accessibility; leased pointer; second pointer on X11 Apps with no API; literal pair cursor L Wayland has no second pointer; safety; flakiness Last; deferred
G. @svendowideit/ide front door Capability discovery + routing across A–F One agent-facing surface M God-object; duplicated manifests Not a model; later a report/workflow

Do not build a single "IDE" model with an adapter switch. Each transport has different dependencies, failure modes, and docs. Separate types are easier to test, release, and explain; composition happens through CEL data and a report.


4. Recommendation

Build in this order:

  1. A — @svendowideit/herdr-core. It is the base for everything else: a persistent session, structured file edits, process execution, search, and fleet fan-out, with no editor dependency. It replaces the majority of shell-outs on its own.
  2. B — @svendowideit/vim. This is the "easiest first" editor: Vim is already installed, clientserver already works on this host, and text properties give a visible agent cursor and annotations. No need to switch to Neovim for the local case.
  3. D — VS Code bridge. The other daily driver. Build it when the task is VS Code work, not before.
  4. C — Neovim. Add it when live editing is needed on macmini/xeon/eieio, or when extmarks/LSP/nvim-dap are worth the install.
  5. E — DAP. Add real debugging when print statements stop being enough.
  6. F — desktop input. Only when an app with no API demands it. Design the lease/annotate protocol now; do not ship a second pointer yet.

Your answers map to decisions in §10.


5. Proposed extension shape

The implemented surfaces are listed under "What changed"; the sketches below remain the original design and are slightly broader in places.

5.1 @svendowideit/herdr-core

One model type, fan-out methods. One instance per herdr-core session (local or remote via an existing machine name).

Methods

  • status — core identity/version, holder, machine count, terminal count, capability set.
  • terminals — fan-out list filtered by cwd, label, agent, machine, state; one terminal resource each plus a fleet roll-up.
  • read — screen and history for one or many terminals; bounded bytes; tagged with address, cwd, machine.
  • run — start argv in a new or named terminal (bg, cwd, label, on, keep); return the terminal and, when waiting, the exit code.
  • send — text + Enter, draft-aware; refuse the caller's own terminal.
  • keys — named keys, encoded for the program's current keyboard modes.
  • interrupt, kill, rm, put.
  • wait / wait-output — idle, children, or output match/regex, with timeout.
  • exec — argv without a terminal, cwd/env/timeout, decoded stdout/stderr, exit code; fan-out across machines in one call.
  • file-read / file-write / file-edit — local or --on; exact-once, atomic per file; a multi-file call reports each file and never leaves a half-written file.
  • search — rg --json via exec, parsed into path/line/column/text matches, bounded and with an explicit dependency check. (This is the one place a CLI is wrapped, because herdr-core has no search primitive and no registry extension provides general code search.)
  • machines, machine-add, machine-remove.

Data: fleet, terminal, exec-result, file-result, search-result, machine.

Report: terminal-session — what ran, where, exit codes, files changed, elapsed, and the terminals involved. Reports run on failure too, so a failed fan-out says which target failed.

Notes

  • terminal.attach is a long-lived stream; it does not fit swamp's request/response method model. Use send/keys for normal input, and add a bounded raw method only if a specific TUI needs bytes that keys cannot express. File that gap upstream first.
  • events.subscribe is long-lived too. Expose wait/wait-output instead; a workflow can poll or wait.
  • Fan-out is mandatory. Do not run N swamp behavior run calls against the same model; one call takes the lock once and handles all targets.

5.2 @svendowideit/vim

Methods

  • servers — vim --serverlist, server names and reachability.
  • open — start or reuse a Vim with a stable --servername inside a herdr terminal (or attach to an existing named server); load a file, set cwd.
  • status — server, file, &modified, line count, cursor, mode.
  • read — whole buffer, range, visible range, selection, or a named register; returns lines with numbers and file identity.
  • edit — one --remote-expr call that applies a list of operations (setline, append, deletebufline, setbufline) exact-once inside a Vimscript function, and returns {changed, undo_seq, before_hash, after_hash}. All-or-none.
  • write, save (only after explicit approval where overwrite matters).
  • cursor, select — set cursor/visual range; return the new state.
  • annotate — prop_type_add/prop_add virtual text, matchadd highlights, sign_place gutter marks. This is the agent's visible cursor and intent.
  • command — execute() an Ex command (allowlist by default, full access behind an input flag and approval).
  • expr — eval() a Vimscript expression (read-only by default).
  • keys — feedkeys() for the cases only keys can handle; never the primary edit path.
  • diagnostics — getqflist() / getloclist(); optionally setqflist() to inject findings from rg, LSP, or a build.
  • undo — undo to a recorded sequence; undotree() for state.
  • diff — produce a unified diff from before/after snapshots stored as data.
  • close — --remote-send quit/close; never qa! silently.

Data: vim-server, buffer, edit-result, diagnostics, annotation. Report: edit-session — files, hunks, undo sequence, before/after hashes.

The extension bundles a small Vimscript runtime (an autoload function or plugin) that is sourced when open starts Vim. That runtime owns exact-once checks, undo sequencing, and JSON return values. It is the same runtime that a future +channel transport can use on the fleet.

5.3 Neovim adapter (later)

Only if the fleet or richer UI needs it. nvim --listen <socket> and msgpack-RPC give nvim_buf_get_lines, nvim_buf_set_text, nvim_win_set_cursor, nvim_buf_set_extmark (virtual text, signs), nvim_exec_lua, vim.diagnostic, nvim_open_term, and nvim-dap. It is portable across all four hosts and needs no X11. Methods mirror the Vim adapter; the data and report shapes stay the same, so a workflow can switch adapters without changing its CEL.

5.4 VS Code bridge (later)

Two artifacts:

  1. A VS Code extension (swamp-bridge) that listens on a local socket or named pipe, authenticates with a 0600 token file, and maps JSON-RPC methods to the public API: window.showTextDocument, WorkspaceEdit, commands.executeCommand (allowlisted), tasks.executeTask, terminal.sendText (or terminal.shellIntegration), languages.getDiagnostics, debug.startDebugging, debug.activeDebugSession.customRequest, and window.showDiff-style views.
  2. A swamp model that discovers instances, chooses a workspace, and exposes open, reveal, edit, command, task, terminal-send, diagnostics, debug-*, diff, save, undo, wait.

Security: workspace trust, a command allowlist by default, no arbitrary executeCommand unless the caller opts in and the run is approved. The bridge is opt-in per VS Code window.

5.5 DAP (later)

Methods: start, attach, breakpoints, continue, next, step-in, step-out, stack, scopes, variables, evaluate, output, terminate. Adapters: debugpy (Python), dlv dap (Go), lldb-dap (Rust/C/C++), js-debug (Node/TS). One session per target; data debug-session, breakpoint, stack-frame, variable; report debug-session. Start with one language (the one in the current task), not all four.

5.6 Desktop input (deferred)

Only for an app with no API. Methods: lease, release, pointer, click, type, key, screenshot, uia-tree, invoke.

  • X11: XTEST for the current pointer; uinput + XInput2 master for a true second pointer.
  • Wayland: libei/ydotool/wtype for input; one pointer; no portable second cursor on niri.
  • Windows/Visual Studio: deferred.

Safety: focus check, window allowlist, a kill switch, and "first human keypress yields the lease" before any of it ships.


6. Pairing and the literal second cursor

The request prefers a literal second cursor and keyboard, but treats it as a later goal. That is the right order.

In a terminal, a second keyboard already exists. A terminal has one pty and one cursor. herdr-core owns the pty; herdr-apps are clients. Herdr is designed for multiple attached clients, and herdr-core's attach opens a stream per connection; one Phase 0 probe should confirm two concurrent viewers on one terminal. Any bytes an agent writes go to the same program the human is typing into. terminal.send even waits for the human's unfinished draft (up to 60 s) before delivering, which is a built-in pairing protocol. The "second keyboard" is therefore a transport that already works; what is missing is a swamp wrapper and the UX around it.

A literal second cursor in a terminal does not exist. There is one cursor in the pty. The useful approximation is an annotation cursor: prop_add virtual text and matchadd in Vim, extmarks in Neovim, decorations in VS Code. The human keeps the real cursor; the agent shows where it is looking and what it proposes. This is more useful than a second pointer for code work, and it works on every host.

A literal second pointer in a GUI is platform-specific. X11 can do it with uinput and a second XInput2 master pointer. Wayland (niri) cannot give two independent pointers to normal clients; macOS and Windows have one. A "second mouse" on Wayland would need a nested compositor, a custom overlay with a fake cursor, or a compositor feature — all later, none portable.

Recommendation: design the pairing protocol now (lease, annotate, handoff, audit) and implement the transport later. The lease says who may type; the annotation shows intent; the audit records what was done. When an X11 second pointer or a Wayland overlay becomes worth it, it plugs into the same protocol.


7. Phased plan

Phase 0 — probes and a capability matrix (small)

Progress (2026-11-23): the Vim, fleet and herdr-core API probes are done. The concurrent attach/mouse, Vim latency, nvim RPC, VS Code bridge and DAP probes remain.

Done already: Vim clientserver read/edit/write through a herdr terminal; fleet Vim/nvim/code matrix; herdr-core API and machine versions.

Remaining probes, each a throwaway zz-probe-* with the finding recorded here or in an issue:

  1. Two concurrent attach consumers on one herdr-core terminal, and raw SGR mouse bytes into Vim with mouse=a.
  2. Whether hc keys punctuation is fixed in 0.1.18/0.1.21, or must go upstream.
  3. Vim --remote-expr latency and queueing while a human types.
  4. Neovim RPC from Deno (msgpackr pinned) — only if choosing C.
  5. A minimal VS Code bridge handshake and one WorkspaceEdit — only if choosing D.
  6. One DAP handshake (debugpy or dlv dap) from Deno — only if choosing E.

Done when: each probe has a one-paragraph result and a go/no-go for its phase.

Phase 1 — @svendowideit/herdr-core (the base)

Progress (2026-11-23): built. 20 methods, data, the terminal-session report, line-range edits and tests pass. An explicit --on xeon verification remains.

Deliver the methods in §5.1, data, and the terminal-session report. Start with the local session; add --on fan-out and a two-machine test (local + xeon) in the same phase.

Done when:

  • swamp behavior run @svendowideit/herdr-core terminals --input cwd=$PWD lists live terminals and their agents.
  • file-edit is exact-once per file, with a data record; a multi-file call reports each target and does not leave a half-written file.
  • exec --on xeon returns the same shape as local.
  • run + wait-output returns an exit code and the tail of output.
  • The report renders on success and on a failed target.
  • deno test, deno check, swamp extension fmt --check, and the meta-factory score pass.

Phase 2 — @svendowideit/vim (local live editing)

Progress (2026-11-23): built. 15 methods, the bundled runtime, edit diff/undo, annotation, select, diff and the edit-session report pass.

Deliver §5.2, the bundled Vimscript runtime, and the edit-session report. Open a Vim in a herdr pane and drive it while the human watches.

Done when:

  • open starts a named server; servers finds it.
  • read returns the buffer and visible range with file identity.
  • A multi-edit edit call changes exactly the intended lines, is all-or-none for that buffer, and returns an undo sequence.
  • annotate draws a virtual cursor/annotation in the buffer.
  • diagnostics returns quickfix entries.
  • A failed exact-once match writes a failed data record and raises.
  • A workflow can run edit → annotate → wait → diff → report.

Phase 2.5 — use swamp serve, not a swamp process per call

Progress (2026-11-23): 2.5a built. The addin opens one swamp serve WebSocket per pi session, sends model.method.run and data.get over it, and falls back to the CLI only when the connection cannot be established. A status call took 164 ms through serve in the runtime harness. The shell-out histogram landed with it: each bash program is recorded with its subcommand and bypass/other category, and /swamp-ide histogram is the prioritisation view. 2.5b — git mv hygiene and the release rename check — is still open.

The pi addin originally spawned swamp behavior run for each swamp_ide call. That was a shell-out: a process start, a repository load, a lock, and no streaming handle. The phase added a swamp serve client to the addin: detect a running server (SWAMP_SERVE_URL or the repo's serve configuration), connect once per pi session over the serve protocol, and send method requests directly. The CLI path stays as a fallback for a repo with no reachable server. The result: a swamp_ide call starts no swamp binary, latency and lock contention drop, and the addin can stream progress and keep a run handle.

Also in this phase: use git better. Rename tracked files and directories with git mv (not a plain move, copy-and-delete, or a delete-plus-create pair), keep a rename and its reference updates in one commit, and check git status before and after. Add a release check that flags a renamed file that appears as a delete plus an add and suggests git mv. The agent should prefer git mv when it knows the path is tracked, and use the file-edit tooling for content edits after the move.

Phase 3 — VS Code bridge

Next after the serve client.

Deliver §5.4. Use it for one real task (open a repo, reveal a file, apply an edit, run a task, read diagnostics) before adding debug.

Done when: the bridge survives a VS Code reload, refuses untrusted workspaces, and the swamp model's edit/task/diagnostics work against the same repo.

Phase 4 — Neovim (or Vim +channel) for the fleet

Next when fleet live editing matters.

Choose by need: install Neovim on macmini/xeon/eieio and implement the RPC adapter, or write the Vim +channel plugin for the hosts that already have +channel. Either way, reuse the Phase 2 data and report shapes.

Done when: a remote host can be opened, read, edited, annotated, and closed from swamp, with the same method names as local Vim.

Phase 5 — DAP

Next after the VS Code bridge.

Start with one language and one adapter. Add a workflow step that launches, sets a breakpoint, continues, reads a stack and variables, and terminates.

Done when: a real failing test can be debugged without leaving swamp, and the debug-session report explains where it stopped.

Phase 6 — desktop input / literal second pointer

Deferred.

Only after an app with no API demands it, and only behind approvals. X11 second pointer first; Wayland overlay or leased pointer second; Windows later.


8. What gets replaced

Operation Today With the extension
search rg -n, grep -r herdr-core search → JSON matches, fan-out, bounded
read cat, sed -n file-read, Vim read, VS Code reveal
edit/create sed -i, apply_patch, heredoc file-edit (exact-once, atomic) or Vim edit (undo group)
rename/move mv, perl -pi file-edit / WorkspaceEdit; report the hunks
run tests npm test, pytest, cargo test herdr-core run + wait-output, exit code, terminal to watch
shell one-off command/shell still command/shell — this plan does not replace ad-hoc shell
debug printf, gdb DAP: breakpoints, stack, scopes, variables, evaluate
inspect state re-read files read/buffer snapshot with cursor, selection, diagnostics
remote ssh host '...' exec --on host, file-* --on host, terminal --on host
pair paste into the terminal send draft-aware, Vim annotations, later a leased pointer

The mapping is deliberate: structured APIs where they exist, herdr-core where they do not, OS input only as a last resort. command/shell stays for genuinely ad-hoc commands; it is not the integration layer.


9. Safety, determinism, and the fleet

  • Default read-only. Mutating methods against a human's live editor require an approval gate; write/overwrite is separate from edit.
  • Exact-once per file. file-edit and Vim edit fail that file's call if any match is missing or ambiguous. Multi-file calls report each target and never leave a half-written file. No partial edits without a failed data record.
  • Dry-run diff first. A plan/diff mode returns the hunks without writing; the report keeps them.
  • Undo group. Vim edits record an undo sequence; the report can undo the whole agent session. VS Code edits record the workspace edit identity.
  • Path allowlist and repo root. Refuse paths outside the configured root unless an explicit input grants them.
  • TOCTOU checks. Before typing into a terminal, verify the address still has the same foreground program and cwd; refuse the caller's own terminal.
  • No secret exfiltration. read bounds bytes; exec returns bounded stdout/stderr; vault values never appear in data.
  • Fleet capability negotiation. Every call checks the remote hello methods/features; a 0.1.18 host may lack a 0.1.21 method, and the error must say which host and which capability.
  • One lock, one fan-out. Never loop swamp behavior run across targets; one method call acquires the lock once and returns all results.

10. Decisions and open questions

Progress: D1 and D2 are implemented. D3 is next; D4–D6 remain as written.

Taken from the request and the ground truth:

  • D1. (done) Build @svendowideit/herdr-core first; it is the base and the shared-session/pairing transport.
  • D2. (done) Build the Vim adapter second; do not require switching to Neovim for the local host. Vim 9.1 clientserver + text properties are enough for read/edit/annotate/diagnostics.
  • D3. VS Code next (bridge), because it is the other daily driver. Visual Studio and Windows are deferred.
  • D4. Neovim (or a Vim +channel plugin) when live editing is needed on macmini/xeon/eieio, not before.
  • D5. Wayland first; X11 second pointer is the only literal second pointer and is deferred. Pairing starts as lease + annotations.
  • D6. Support both live watching and later diff review: every edit writes before/after data and a report, even when the human watched it happen.
  • D7. The herdr fleet is a first-class dimension: every method must work --on <machine>, and fan-out is preferred to loops.
  • D8. No generic @svendowideit/ide model. Compose through data and a report; a front door can be added later if the surface is proven.
  • D9. The pi addin is session-gated: it registers nothing unless .pi/swamp-ide/<PI_SESSION_ID>.enabled exists. A repo-wide addin must not change every session.
  • D10. Observe the loop in OpenObserve, not in a bespoke log. The addin encodes route in the span name because OpenObserve's trace schema does not expose arbitrary attributes.
  • D11. (done) In the pi addin, prefer a running swamp serve over spawning the swamp binary; fall back to the CLI only when no server is reachable.

Open:

  1. Vim runtime: an autoload function sourced by --cmd, or a proper plugin installed in the extension? (The plugin is reusable for +channel on the fleet.)
  2. command/expr: unrestricted by default, or an allowlist with an explicit escape hatch? My default is allowlist for command, unrestricted expr only for reads.
  3. Pairing state: store the lease in swamp data, or in herdr-core's doc store so every Herdr client sees it? Swamp data is the audit record; the doc store may be the live lease.
  4. For the fleet: install Neovim everywhere, or write the Vim +channel plugin? Neovim is more capable; the plugin avoids a new runtime.
  5. DAP first language: Python (debugpy), Go (dlv dap), or TypeScript (js-debug)?
  6. VS Code bridge transport on Windows: named pipe or TCP loopback? Deferred, but decide before the bridge ships cross-platform.

11. Non-goals and risks

Non-goals for this plan

  • Replacing the human's editor or taking it over without consent.
  • Global input injection as the primary control path.
  • Visual Studio, Windows, and a Wayland second pointer (deferred).
  • An LSP client for every language; editors already have LSP. DAP is the missing debugger, not another language server.
  • A new command/shell wrapper or a bespoke script per task.

Risks

  • herdr-core API drift and fleet version skew (0.1.18 vs 0.1.21). Mitigation: capability negotiation and a minimum-version check.
  • Vim clientserver is X11-bound and requires --servername; local-only. Mitigation: explicit open, clear errors, Neovim/+channel for the fleet.
  • VS Code bridge maintenance and workspace trust. Mitigation: public API only, allowlist, opt-in per window, and no CDP dependency.
  • Latency: send/keys debounce, Vim --remote-expr queues behind human input. Mitigation: use editor APIs for edits, herdr for whole commands, and never type character-by-character for pairing.
  • Security: arbitrary editor commands and eval are powerful. Mitigation: approvals, allowlist, path root, audit data, and a kill switch.
  • Over-building. Mitigation: Phase 1 alone removes most shell-outs; stop after each phase and measure.
  • Vim text properties: text_align requires col=0; keep the virtual label and the column highlight as separate properties. The runtime is versioned so a live server can be re-sourced.
  • OpenObserve trace schema: only mapped columns are queryable. Keep the route in operation_name and success in swamp_outcome, not in arbitrary attributes.
  • Local extension upgrades: the upgrades chain must end at the current version, and a version bump can leave a broken local bundle until swamp doctor extensions --repair --yes rebuilds it. This happened during the build.
  • Pi session gating: without a marker the addin is inert; to enable a new session, create the marker and /reload.

12. Verification and release

For each extension:

~/.swamp/deno/deno test \
  extensions/models/herdr-core/herdr_core_test.ts \
  extensions/models/herdr-core/herdr_core_otel_test.ts \
  extensions/models/herdr-core/herdr_core_report_test.ts \
  extensions/models/vim-controller/vim_test.ts \
  extensions/models/vim-controller/vim_otel_test.ts \
  extensions/models/vim-controller/vim_report_test.ts \
  extensions/models/swamp-ide/swamp_ide_test.ts \
  extensions/models/swamp-ide-pi-plugin/swamp_ide_pi_plugin_test.ts \
  extensions/models/swamp-ide-openobserve/swamp_ide_openobserve_test.ts \
  extensions/models/openobserve/openobserve_test.ts

swamp extension fmt extensions/models/herdr-core/manifest.yaml --check
swamp extension fmt extensions/models/vim-controller/manifest.yaml --check
swamp extension fmt extensions/models/swamp-ide/manifest.yaml --check
swamp extension fmt extensions/models/swamp-ide-pi-plugin/manifest.yaml --check
swamp extension fmt extensions/models/swamp-ide-openobserve/manifest.yaml --check

swamp workflow run @svendowideit/meta-factory \
  --input manifest=extensions/models/herdr-core/manifest.yaml
swamp workflow run @svendowideit/meta-factory \
  --input manifest=extensions/models/vim-controller/manifest.yaml
swamp workflow run @svendowideit/meta-factory \
  --input manifest=extensions/models/swamp-ide/manifest.yaml
swamp workflow run @svendowideit/meta-factory \
  --input manifest=extensions/models/swamp-ide-pi-plugin/manifest.yaml
swamp workflow run @svendowideit/meta-factory \
  --input manifest=extensions/models/swamp-ide-openobserve/manifest.yaml

# Version bump + the review hash used to record the adversarial review
swamp extension version --manifest extensions/models/herdr-core/manifest.yaml
swamp extension push extensions/models/herdr-core/manifest.yaml --dry-run

Then follow the repo's release hygiene: set both the manifest and model versions to the same nextVersion, add the upgrades: entry, record the adversarial review for the new content hash, and report the exact swamp extension push command without pushing.

Phase 1, 2 and 2.5a are now built and running locally. The next concrete deliverable is Phase 2.5b (git rename hygiene), then the VS Code bridge (Phase 3) and the DAP client (Phase 5). The OpenObserve dashboard already shows the routed-vs-bypassed split, and the shell-out histogram now records which programs are still worth a dedicated method.