Skip to content

v477 — One write path: the IDE and the agents share a revision log

Choose a tag to compare

@MBHudson MBHudson released this 15 Nov 23:05
· 41 commits to master since this release

The built-in IDE and the agents wrote files through two different doors. The IDE saved through ide/api.php; an agent wrote through Sandbox::writeFile. Neither knew about the other, so an agent's edit landed on disk while the editor kept its old buffer, and a human's save could land on top of a file an agent had just rewritten — with nothing, anywhere, saying either had happened. That is the whole reason "agents and the user use the IDE together" could not be built on top of it.

SrcWorkspace is now the one writer. Every mutation goes through it — the IDE's save, and the agent's write_file, str_replace, insert and apply_patch — and each one appends {rev, path, op, actor, at, bytes, hash, prev} to storage/ide/revs.jsonl under a single tree-wide counter, keeping both the old and the new text content-addressed in storage/ide/blobs/. ide/api.php?action=revs&since=N returns what happened after a revision, and the IDE polls it every 1.5s while visible. Polling, not a socket: this app runs under php -S too, and that server is single-threaded — a held-open stream would block the request the agent is waiting on, which is the one thing a shared editor cannot do. The log sits in storage/, which every serving mode refuses to serve and Workspace::resolve refuses to reach, so it is readable only through the endpoint. The IDE's answer to a change is decided by a pure function (ide/js/changes.js, tested in tests/js/ideChanges.test.mjs): a clean buffer reloads with its caret intact, a dirty buffer is a conflict and is never touched — the amber strip offers Load theirs · Keep mine, and the human wins until they say otherwise. Unopened files and binary tabs are ignored, and the IDE's own saves are recognised so they do not come back as "changed on disk". The chat's file-writing tool calls carry an Open in IDE chip, which shows the IDE screen and posts ide:open over the same-origin handshake that already carried the token. Code in the chat is numbered line for line: fenced blocks get a sticky gutter outside the highlighted <code> (Prism rewrites that element, so a gutter inside it would be eaten), and the wrapping Arguments/Result boxes get a row per line with the number in the margin. tests/php/workspace.test.php pins the revisions, the snapshots and the path rules; the version pins now cover ide/** and caught <html data-build="143">, which nothing had touched since 143 while every Prism vendor script the app injected was fetched from that cache key. JS 43 files / 1,453 assertions, PHP 38 files / 38 passed (3 skipped), docs 14/14.

An IDE drill is the seventh mode: eight steps that make an agent write through the editor's own door instead of the sandbox tools. ide_write creates training/ide-<agent>-pN.txt, ide_open puts it in the operator's IDE screen, ide_read reads it back through ide/api.php, ide_edit changes it by exact replacement (an empty or ambiguous anchor is refused, so a bare append cannot pass), and a second ide_read proves the change landed. The four tools are new — ide_open, ide_read, ide_write, ide_edit — and ride along only while that drill is armed, the same way the browser tools ride along while the browser is on: in the prompt dialect and as native schemas, because every advertised tool costs prompt tokens on every request. ide/api.php?action=edit is new too, and it replaces through Workspace::write, so an agent's edit is a revision the operator's open tab reloads rather than a second silent write path — the exact failure the write path was built to end. DRILL_CHECKS_IDE grades the marker, the anchored edit and the read-back; each pass keeps its own file family (training/ide-…-pN.txt), so no drill can grade another one's bytes. drillPassFile reads ide_write as well as write_file now: it only recognised the sandbox tool, so an IDE pass was filed under the counter's next file while the report claimed that was the one it wrote. tests/js/training.test.mjs pins the eight steps, the label, the mode selection, the file family, both negatives (wrong content, empty anchor) and the block's rule that names write_file as the wrong tool.

drill-run.mjs drives any drill against a real model from a terminal, and grades it with the app's own code. The runner arms the drill in the app's store, so the prompt block, the task table, the checks and the per-pass file naming all come from ui/js/training.js — there is no second definition of "passed", which is what makes a score in a terminal mean the same thing as a score on the Training screen. --mode takes the dialog's own ids (easy, hard, advanced, frontier, browser, ide, custom), and the tool list is derived from the steps themselves, so an IDE pass offers ide_* while an Advanced pass offers fetch_url, write_file, read_file, show_url, show_file; ide_* still goes through ide/api.php — the shared write path, revisions and all — and every other tool runs through the app's own TOOL_REGISTRY with the same root and scope the chat hands it. --target N chains passes and stops on the app's own clean-pass target, --keep leaves the files, and a run ends with a per-pass table (pass number, the file that pass actually wrote, clean or the step it failed at) plus a transcript under storage/drills/.

Three defects surfaced the moment a second drill type ran headless. A write_file that asks for approval built its dialog out of a DOM that does not exist in Node and threw from a timer, which killed the process mid-pass with a stack trace and no verdict — the runner now sets the app's own auto-approve setting, the same switch an operator has in Config, and an uncaught error in app code is named instead of dumped. Native call arguments reached string-argument tools as objects, so fetch_url did String({url}) and the server answered cannot resolve host object Object; arguments are now flattened by each tool's own arg declaration, one-key JSON templates like show_url's included, while multi-key shapes such as write_file stay objects. And --mode nope silently ran the 17-step Hard drill, because trainingTasksFor answers an unknown difficulty with the default table, so the mode is checked against the dialog's list before anything else and exits 2 naming all seven.

--base is optional: the runner probes /ide/api.php?action=info — Apache under /router on 8080 first, then the php -S ports and the roots — and accepts only a JSON body that names the folder and carries the read/write limits, which is specific enough that another server on the port cannot answer for the app. An explicit --base is checked the same way, because a wrong port used to surface as error: fetch failed inside step 3 of a pass rather than as a sentence up front. --timeout (default 180 s, AbortSignal.timeout) exists for the same reason: fetch has no timeout of its own, and a provider that stopped answering hung a run with nothing to show.


VERSION 475 → 477 · APP_VERSION 474 → 477 · JS 43 files / 1,453 assertions · PHP 38 files / 38 passed (3 skipped) · docs 14/14