Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Changelog

## v0.12.0 · 2026-11-20

The app's side of starting and stopping cleanly, and two fixes to agent tabs and to start-up on macOS.

- On Windows the engine is tied to the app through the system: an app ended in Task Manager, or any other way, takes its engine with it at once.
- When the app cannot start its engine, the message now says what went wrong, shows the engine's last lines and its exit code, and gives the full path of the engine's log. A copy that is already open is still named as the likely cause when that is the reason.
- The app waits at most 90 seconds for its engine to be ready, then says so instead of waiting without end.
- On Windows the engine is built with no console window beside the app. `FORMENCODER_ENGINE_WINDOWED=0` at build time keeps the console.
- Fixed: two Antigravity tabs open at once each keep their own connection to the app, and closing one no longer cuts off the other. Each tab works in a folder of its own.
- Fixed, on macOS: an engine left over from an earlier start that had ended but was not yet cleaned up by the system kept the next start waiting and then refused it. It now counts as gone.
- The Agents panel's guide now says that Codex, Cursor and Antigravity each get a button of their own when they are on this computer.
- Not run for this release: Windows, macOS, the desktop app (its Windows code was type-checked here, not built or run) and a packaged engine. The checks ran on Linux from source, with stand-ins for the agent programs.
- The version string inside the three browser demo bundles was not changed in this release; they still say 0.11.0.

## v0.11.0 · 2026-11-20

Starting and stopping cleanly, on Windows too: the engine's side. One engine of the app per data folder, an engine that leaves when its app is gone, a log file, and a start failure that is said before the app closes. The app's side of the same work (below, under "Not in this release") is still to come.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</p>

<p align="center">
<img alt="version 0.11.0" src="https://img.shields.io/badge/version-0.11.0-eef0f4?style=flat-square">
<img alt="version 0.12.0" src="https://img.shields.io/badge/version-0.12.0-eef0f4?style=flat-square">
<img alt="Rust" src="https://img.shields.io/badge/Rust-engine-b7410e?style=flat-square&logo=rust&logoColor=white">
<img alt="TypeScript" src="https://img.shields.io/badge/TypeScript-interface-3178c6?style=flat-square">
<img alt="macOS, Windows, Linux" src="https://img.shields.io/badge/macOS%20%C2%B7%20Windows%20%C2%B7%20Linux-native-2f7bf5?style=flat-square">
Expand Down Expand Up @@ -102,7 +102,7 @@ FormEncoder loads extensions made to the Form Extension Contract (API 1): FormPo

## Under the hood

Version 0.11.0 · Apache-2.0 · Rust encoding engine, Python service, TypeScript interface, Tauri 2 shell
Version 0.12.0 · Apache-2.0 · Rust encoding engine, Python service, TypeScript interface, Tauri 2 shell

- **Engine:** seven `fencoder` Rust crates in `native/`, loaded by the Python service as the `fe_core` extension.
- **FFmpeg:** a pinned LGPL build, run as a separate program and never linked.
Expand Down
29 changes: 29 additions & 0 deletions backend/HASHOUT_LOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -396,3 +396,32 @@ Refers to `backend/app/routers/terminal.py` (`pump`) · kind: fix · logged: unr
- In `pump`, a hand-over of output that raises `RuntimeError` ends the read loop, and the hand-over of the end notice ignores the same error. The wait for the child stays where it was, so the child is still reaped.
- Seen: the whole backend suite with this change, 279 passed, and its output held no `Event loop is closed` line. Whether the line shows on this machine without the change was not looked at.


## An engine that has ended but was not yet collected counts as gone where there is no /proc (unreleased, after 0.11.0)

Refers to `backend/app/core/startup.py` (`finished`, `gone_by`), `backend/tests/test_startup.py` · kind: fix · logged: unreleased · 2026-11-20

- Why: FormCut's macOS job failed three start-up tests with "could not stop an engine that was left running". `end` had ended the holder, but `gone_by` kept seeing it: `_alive_posix` asks `kill(pid, 0)`, which still answers for a process that has ended and that its parent has not collected, and it tells such a process apart only by reading `/proc`, which macOS does not have. This file is the same one, so the same wait would run out here.
- `finished(pid)` asks `ps -o stat= -p <pid>` where there is no `/proc` (never on Windows, never on Linux) and answers true for a state that starts with `Z`. `gone_by` stops waiting when the process is not alive or is finished. `alive` is unchanged, so the two second watch on the app starts no program.
- Seen on Linux with `PROC` pointed at a folder that does not exist: with `finished` answering false, `claim` on a holder whose shell is gone is refused with that sentence; with the change it replaces the holder. One new test, `test_startup.py` 16 passed. Not run on macOS.

## Each Antigravity tab has a folder of its own (unreleased, after 0.11.0)

Refers to `backend/app/services/agent_programs.py` (`TAB_FOLDERS`, `TAB_GUIDE`, `tab_folder`, `_servers`, `write_tab_entry`, `clear_tab_folder`), `backend/app/routers/terminal.py` (`Hub.open`, `Term._start`, `Term._forget`), `backend/tests/test_dock_engine.py` · kind: fix · logged: unreleased · 2026-11-20

- Why: every Antigravity tab ran in the agent workspace and wrote its entry `formencoder_tab` into that folder's `.agents/mcp_config.json`. A second tab replaced the first one's entry, and closing the second removed the entry while the first tab was still open (the "known limit" of the entry above).
- Each tab now runs in `[data folder]/agent-tabs/antigravity/[engine process id]-[tab id]`. The process id is in the name because tab ids start again at `t1` in every engine, and a headless engine may share the data folder with the app's engine. The entry is written there, `agy` is started there, and a `cwd` in the request is still ignored for this kind.
- The agent workspace is still prepared first (the entry's command is the workspace's `formencoder` shim), and its `AGENTS.md` is copied into the tab's folder, so the program finds the same guide it found when it ran in the workspace. Nothing read says whether Antigravity reads `AGENTS.md`; the copy costs nothing if it does not.
- When the program ends or the tab closes: the entry is taken out as before (only while it carries the tab's token); then the MCP file is removed if it holds nothing else, the `.agents` folder if it is empty, the guide if it is still the copy, and the folder if it is empty. A folder that holds anything else is kept. `clear_tab_folder` does nothing for a folder that is not two levels below a folder named `agent-tabs`. A restart writes the entry again and so makes the folder again.
- `_servers` took a file that is not JSON as a `ValueError` that nothing caught (a bare 500, and the tab's token stayed issued). It is now the same `OSError` sentence as a file of the wrong shape, which the tab route answers as "The program could not start: [path] is not an MCP servers file formencoder can read, so it was left alone".
- The workspace's own `.agents/mcp_config.json`, if a person has one, is no longer read or written by a tab.
- Seen with the stand-in `agy` of the test folder: one tab has its entry at mode 0600 and the guide in its own folder, the stand-in prints with the token present, and after close the folder is gone and a seeded file in the workspace is byte for byte the seed; two tabs open at once hold a token each in a file each, closing the second leaves the first one's entry and its token still runs a changing call unasked, closing the first removes its folder. `test_dock_engine.py` and `test_dock_module.py`: 28 passed.
- Not run: a real `agy`, Windows (a folder that is still a running program's working folder cannot be removed there, so an empty folder may stay behind), macOS.

## A Windows engine is packaged with no console window (unreleased, after 0.11.0)

Refers to `setup/freeze_backend`, `setup/freeze_backend.bat` · kind: change · logged: unreleased · 2026-11-20

- Why: the owner's decision for the family (D3): a Windows engine is built with no console window, as FormWeb's is. FormEncoder's freeze scripts had no switch, so the switch is added with its default turned round: on Windows PyInstaller gets `--noconsole` unless `FORMENCODER_ENGINE_WINDOWED=0`. The bash script adds it only where `fe_os` says windows; macOS and Linux builds are unchanged.
- The shell reads the engine's output through pipes, which a program with no console still gets. Where it has none at all, `formencoder_engine.py` already puts `os.devnull` in place of a missing stdin, stdout or stderr before anything else runs.
- Seen: `--selfcheck` run from the source with `sys.stdout`, `sys.stderr` and `sys.stdin` set to None exits 0. `bash -n setup/freeze_backend` clean; the `.bat` was read, not run. Not run: no Windows build has shown the windowed engine.
2 changes: 1 addition & 1 deletion backend/app/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.11.0"
__version__ = "0.12.0"
19 changes: 18 additions & 1 deletion backend/app/core/startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,26 @@ def same(pid: int, born: float) -> bool:
return alive(pid) and (not born or (seen > 0 and abs(seen - born) <= SLACK))


def finished(pid: int) -> bool:
if WINDOWS or os.path.isdir(PROC):
return False
try:
told = subprocess.run(
["ps", "-o", "stat=", "-p", str(pid)],
stdin=subprocess.DEVNULL,
capture_output=True,
text=True,
timeout=END_WAIT,
check=False,
)
except (OSError, subprocess.SubprocessError):
return False
return told.stdout.strip().startswith("Z")


def gone_by(pid: int, seconds: float) -> bool:
until = time.monotonic() + seconds
while alive(pid):
while alive(pid) and not finished(pid):
if time.monotonic() >= until:
return False
time.sleep(STEP)
Expand Down
7 changes: 5 additions & 2 deletions backend/app/routers/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def _start(self, cols: int, rows: int) -> None:
self.token = consent.issue() if self.trusted else None
if self.kind == "antigravity" and self.token:
try:
finder.write_tab_entry(self.cwd, _tab_entry(self.base, self.token))
finder.write_tab_entry(self.cwd, _tab_entry(self.base, self.token), workspace.root() / finder.TAB_GUIDE)
except OSError:
consent.revoke(self.token)
self.token = None
Expand Down Expand Up @@ -292,6 +292,7 @@ def close(self) -> None:
def _forget(self) -> None:
if self.kind == "antigravity":
finder.remove_tab_entry(self.cwd, self.token)
finder.clear_tab_folder(self.cwd, workspace.root() / finder.TAB_GUIDE)

def row(self) -> dict:
return {"id": self.id, "title": self.title, "cwd": self.cwd, "created": self.created, "exited": self.exited, "owned": self.owned, "offset": self.offset, "opener": self.opener,
Expand Down Expand Up @@ -325,7 +326,9 @@ def open(self, title: str | None, cwd: str | None, cols: int, rows: int, base: s
kind: str = "shell", window: bool = False, argv: list[str] | None = None, program: str | None = None) -> Term:
self._n += 1
tid = f"t{self._n}"
place = cwd or str(workspace.ensure())
own = kind == "antigravity"
home = workspace.ensure() if own or not cwd else None
place = str(finder.tab_folder(kind, tid)) if own else cwd or str(home)
term = Term(tid, title or f"Terminal {self._n}", place, cols, rows, base, owned, trusted, kind, window, argv, program)
self.terms[tid] = term
if run:
Expand Down
34 changes: 32 additions & 2 deletions backend/app/services/agent_programs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
from pathlib import Path

from ..core import config
from . import agent_lookup

PROGRAMS = {
Expand All @@ -20,6 +21,8 @@
}
OTHERWISE = ""
TAB_ENTRY = "formencoder_tab"
TAB_FOLDERS = "agent-tabs"
TAB_GUIDE = "AGENTS.md"
TOKEN_VAR = "FORMENCODER_AGENT_TOKEN"


Expand Down Expand Up @@ -54,12 +57,19 @@ def program(kind: str) -> str | None:
return found.path if found.state == "runs" else None


def tab_folder(kind: str, tab: str) -> Path:
return config.data_dir() / TAB_FOLDERS / kind / f"{os.getpid()}-{tab}"


def _mcp_file(folder: str | os.PathLike) -> Path:
return Path(folder) / ".agents" / "mcp_config.json"


def _servers(path: Path) -> dict:
data = json.loads(path.read_text(encoding="utf-8") or "{}") if path.exists() else {}
try:
data = json.loads(path.read_text(encoding="utf-8") or "{}") if path.exists() else {}
except ValueError:
data = None
if not isinstance(data, dict) or not isinstance(data.get("mcpServers", {}), dict):
raise OSError(f"{path} is not an MCP servers file formencoder can read, so it was left alone")
return data
Expand All @@ -73,11 +83,31 @@ def _replace(path: Path, data: dict) -> None:
os.replace(part, path)


def write_tab_entry(folder: str | os.PathLike, entry: dict) -> None:
def write_tab_entry(folder: str | os.PathLike, entry: dict, guide: str | os.PathLike | None = None) -> None:
path = _mcp_file(folder)
data = _servers(path)
data.setdefault("mcpServers", {})[TAB_ENTRY] = entry
_replace(path, data)
if guide and Path(guide).is_file():
(Path(folder) / TAB_GUIDE).write_text(Path(guide).read_text(encoding="utf-8"), encoding="utf-8")


def clear_tab_folder(folder: str | os.PathLike, guide: str | os.PathLike | None = None) -> None:
base = Path(folder)
if base.parent.parent.name != TAB_FOLDERS:
return
path = _mcp_file(base)
try:
if path.exists() and _servers(path) == {"mcpServers": {}}:
path.unlink()
if path.parent.is_dir():
path.parent.rmdir()
copy = base / TAB_GUIDE
if copy.is_file() and guide and Path(guide).is_file() and copy.read_text(encoding="utf-8") == Path(guide).read_text(encoding="utf-8"):
copy.unlink()
base.rmdir()
except (OSError, ValueError):
return


def remove_tab_entry(folder: str | os.PathLike, token: str | None) -> None:
Expand Down
69 changes: 62 additions & 7 deletions backend/tests/test_dock_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,26 +158,81 @@ def test_an_agent_tab_runs_the_program_with_its_own_token_which_dies_with_the_ta


@POSIX_ONLY
def test_an_antigravity_tab_has_its_entry_in_the_workspace_file_until_it_closes(client, stand_ins):
def test_an_antigravity_tab_has_its_entry_in_a_folder_of_its_own_until_it_closes(client, stand_ins):
from pathlib import Path

from app.agent import consent, workspace
from app.core import config
from app.routers.terminal import hub

path = workspace.ensure() / ".agents" / "mcp_config.json"
shared = workspace.ensure() / ".agents" / "mcp_config.json"
seed = json.dumps({"mcpServers": {"other": {"command": "/bin/true", "args": []}}, "theme": "kept"}, indent=2) + "\n"
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(seed, encoding="utf-8")
shared.parent.mkdir(parents=True, exist_ok=True)
shared.write_text(seed, encoding="utf-8")
row = client.post("/api/terminal/tabs", headers=LOCAL, json={"kind": "antigravity", "cwd": "/tmp"}).json()
term = hub.terms[row["id"]]
assert row["kind"] == "antigravity" and term.cwd == str(workspace.root())
folder = Path(term.cwd)
assert row["kind"] == "antigravity" and folder == config.data_dir() / "agent-tabs" / "antigravity" / f"{os.getpid()}-{row['id']}"
path = folder / ".agents" / "mcp_config.json"
held = json.loads(path.read_text(encoding="utf-8"))
assert list(held["mcpServers"]) == ["other", "formencoder_tab"] and held["theme"] == "kept" and held["mcpServers"]["other"] == {"command": "/bin/true", "args": []}
assert list(held["mcpServers"]) == ["formencoder_tab"]
entry = held["mcpServers"]["formencoder_tab"]
assert entry["command"] == workspace.mcp_command()[0] and entry["args"] == ["mcp", "--profile", "core"]
assert entry["env"]["FORMENCODER_AGENT_TOKEN"] == term.token and consent.inapp(term.token)
assert path.stat().st_mode & 0o777 == 0o600
assert (folder / "AGENTS.md").read_text(encoding="utf-8") == (workspace.root() / "AGENTS.md").read_text(encoding="utf-8")
assert "token-present=yes" in printed(client, row["id"], "token-present")
token = term.token
client.delete(f"/api/terminal/sessions/{row['id']}", headers=LOCAL)
assert path.read_text(encoding="utf-8") == seed and not consent.inapp(token)
assert not folder.exists() and not consent.inapp(token)
assert shared.read_text(encoding="utf-8") == seed
shared.unlink()


@POSIX_ONLY
def test_two_antigravity_tabs_keep_an_entry_each_and_closing_one_leaves_the_others(client, stand_ins):
from pathlib import Path

from app.agent import consent
from app.routers.terminal import hub

first = client.post("/api/terminal/tabs", headers=LOCAL, json={"kind": "antigravity"}).json()
second = client.post("/api/terminal/tabs", headers=LOCAL, json={"kind": "antigravity"}).json()
one, two = hub.terms[first["id"]], hub.terms[second["id"]]
files = [Path(term.cwd) / ".agents" / "mcp_config.json" for term in (one, two)]
assert one.cwd != two.cwd and one.token != two.token

def token_in(path):
return json.loads(path.read_text(encoding="utf-8"))["mcpServers"]["formencoder_tab"]["env"]["FORMENCODER_AGENT_TOKEN"]

assert [token_in(path) for path in files] == [one.token, two.token]
kept = one.token
client.delete(f"/api/terminal/sessions/{second['id']}", headers=LOCAL)
assert not Path(two.cwd).exists()
assert token_in(files[0]) == kept and consent.inapp(kept) and not changing_call(client, kept).get("isError")
client.delete(f"/api/terminal/sessions/{first['id']}", headers=LOCAL)
assert not Path(one.cwd).exists() and not consent.inapp(kept)


def test_a_tab_folder_that_holds_something_else_is_kept_and_a_file_that_is_not_json_gives_a_sentence(tmp_path):
from app.services import agent_programs as finder

folder = tmp_path / "agent-tabs" / "antigravity" / "1-t1"
finder.write_tab_entry(folder, {"env": {finder.TOKEN_VAR: "abc"}})
(folder / "notes.txt").write_text("mine")
finder.remove_tab_entry(folder, "abc")
finder.clear_tab_folder(folder)
assert sorted(p.name for p in folder.iterdir()) == ["notes.txt"]
elsewhere = tmp_path / "somewhere" / "else" / "t1"
finder.write_tab_entry(elsewhere, {"env": {finder.TOKEN_VAR: "abc"}})
finder.remove_tab_entry(elsewhere, "abc")
finder.clear_tab_folder(elsewhere)
assert (elsewhere / ".agents" / "mcp_config.json").is_file()
(folder / ".agents").mkdir()
(folder / ".agents" / "mcp_config.json").write_text("{not json")
with pytest.raises(OSError, match="is not an MCP servers file formencoder can read, so it was left alone"):
finder.write_tab_entry(folder, {"env": {}})
assert (folder / ".agents" / "mcp_config.json").read_text() == "{not json"


def test_agents_install_adds_formencoder_to_antigravity_and_leaves_a_foreign_entry_alone(tmp_path):
Expand Down
17 changes: 17 additions & 0 deletions backend/tests/test_startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,23 @@ def test_a_lock_that_names_a_process_which_is_not_the_engine_is_replaced_and_the
stop(other, mine)


def test_a_holder_that_ended_but_was_not_collected_counts_as_gone_where_there_is_no_proc(tmp_path, monkeypatch):
from app.core import startup

engine, shell, mine = stand_in(), stand_in(), stand_in()
try:
(tmp_path / startup.LOCK_NAME).write_text(json.dumps(record(startup, engine, shell)))
stop(shell)
monkeypatch.setattr(startup, "PROC", str(tmp_path / "no-proc"))
assert startup.finished(engine.pid) is False
path, replaced = startup.claim(tmp_path, mine.pid)
assert replaced == engine.pid
assert startup.finished(engine.pid) is True
assert json.loads(path.read_text())["pid"] == os.getpid()
finally:
stop(engine, shell, mine)


def test_the_two_ways_of_reading_a_start_time_agree(monkeypatch):
from app.core import startup

Expand Down
2 changes: 1 addition & 1 deletion form-functions.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"format": "form-functions",
"format_version": 1,
"app": "formencoder",
"app_version": "0.11.0",
"app_version": "0.12.0",
"functions": [
{
"id": "encode",
Expand Down
Loading
Loading