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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</p>

<p align="center">
<img alt="version 0.58.0" src="https://img.shields.io/badge/version-0.58.0-eef0f4?style=flat-square">
<img alt="version 0.59.0" src="https://img.shields.io/badge/version-0.59.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-Vite-3178c6?style=flat-square&logo=typescript&logoColor=white">
<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 @@ FormVFX loads Form extensions (API 1): FormPortal installs them, form.ext makes

## Under the hood

Version 0.58.0 · Apache-2.0 · compositing engine: FormVFX's own, in Rust (`native/fvx-core`)
Version 0.59.0 · Apache-2.0 · compositing engine: FormVFX's own, in Rust (`native/fvx-core`)

- **Engine:** `native/fvx-core` is the compositing engine, Rust with PyO3, loaded by the engine service as the `fvx_core` extension.
- **Service:** a FastAPI engine service in `backend`, with the MCP server and the embedded terminal.
Expand Down
32 changes: 32 additions & 0 deletions backend/HASHOUT_LOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -361,3 +361,35 @@ Living context for the engine service. Code carries almost no comments; the reas
- No other shell change was needed for the engine side: the shell already gives the engine its process id in `FORMVFX_PARENT_PID`, the variable the engine watches.
- Not compiled and not run on any system: the desktop shell cannot be built on the machine this was written on.
- Held, for the next pass: the Windows job object (`win_job.rs`), `engine_start.rs` with the engine's last lines and exit code in the failure text, a limit on the wait for the address, and a sentence when the main window fails to build (that arm still only closes the loading window).

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

- What was seen: in FormCut's macOS check, ending a leftover engine waited until the wait ran out and the start was refused with "could not stop an engine that was left running". `gone_by` asks `alive`, and `_alive_posix` asks `kill(pid, 0)`, which still answers for a process that has ended and whose parent has not collected it. Only a read of `/proc` tells such a process apart, and macOS has none. This start-up file is the same file, so it has the same fault.
- What changed (`app/core/startup.py` :: `finished`, `gone_by`): `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 watch on the app's shell starts no program.
- Seen here, on Linux, with `PROC` pointed at a folder that does not exist: without the change `claim` raised `Busy` with the sentence above for a holder that had been ended; with it the holder is replaced. `tests/test_startup.py::test_a_holder_that_has_ended_but_was_not_collected_counts_as_gone_where_there_is_no_proc` holds that. Not run on macOS.

## Each Antigravity tab has a folder of its own (0.59.0)

- Why: every Antigravity tab started in the agent workspace and wrote its entry `formvfx_tab` into that one folder's `.agents/mcp_config.json`. A second tab wrote over the first one's entry, so the first tab's program was left holding the second tab's access, and the first tab to close left the other with an entry it could not find again.
- What changed (`app/agent/terminals.py` :: `tab_folder`, `drop_tab_folder`, `open_agent`): an Antigravity tab gets `[data folder]/agent-tabs/antigravity/[twelve hex digits]`, made for it, with its entry in `.agents/mcp_config.json` there and a copy of the workspace's `AGENTS.md` beside it, and `agy` is started in that folder. The workspace's own file is no longer written. At close the entry is taken out only while it still carries the tab's token, the file is removed when it then holds no server, the guide is removed when it is still the copy, and the two folders are removed only when they are empty: anything a person or the program put there stays, and so does the folder.
- The guide is copied because the tab no longer starts in the workspace, where the program found it before. The workspace's skills folder is not copied; `FORMVFX_WORKSPACE` and the `formvfx` command on `PATH` still point there.
- `_tab_servers` now answers with its sentence for a file that is not JSON, where it let the parser's own error through.
- Seen with a stand-in `agy` through `POST /api/terminal/launch`: two tabs open at once had two folders, two tokens, each its own entry (mode 0600), and each stand-in reported its own folder as where it was started; closing the first removed its folder and its token and left the second's entry and token as they were; the workspace's file, seeded with another entry, was byte for byte the same at the end. A tab folder that held a file of the person's kept that file and only that. Two tests in `tests/test_window_key.py`, the first replacing the test of the shared entry. No real Antigravity was run.

## The Windows shell side: the engine ends with the app, and a failed start says why (0.59.0)

- Kind: fix. Logged: 2026-11-20. Refers to `src-tauri/src/main.rs`, the new `src-tauri/src/win_job.rs` and `src-tauri/src/engine_start.rs`, `src-tauri/Cargo.toml` and one line of `src-tauri/Cargo.lock`. `src-tauri` has no log of its own, so this is kept here. Finishes what the entry of 0.58.0 above held.
- Way taken: FormVis's. The shell still starts its engine through tauri-plugin-shell, so the job takes the engine by its process id (`win_job::hold_pid`) right after the start; nothing moved to another mechanism. `kill_backend` ends the job first on Windows, then the child as before.
- `engine_start.rs`: the sentence for each way a start fails (program missing, not started, stopped with its code, with the engine's own codes 2 for a held data folder and 5 for a data folder it cannot use, a wait that ran out, the window that could not be built), the engine's last twelve lines (never the window-key line, control characters taken out, 300 characters a line at most), and the log's path, worked out the way `app/core/config.py` and `app/core/runtime.py` do (`FORMVFX_DATA_DIR`, a leading `~`, else `~/Formvfx`, then `Logs/formvfx-engine.log`).
- The wait for the address now has a limit: 90 seconds (the owner's D1; there was none). The wait for the window key after the address stays at 10 seconds. A stopped engine is given one second for its last lines before the dialog. The dialog is shown before the loading window closes, then the engine is ended and the app exits 1.
- The window that cannot be built used to close the loading window and leave the app with no window; it now shows "FormVFX could not open its window." the same way.
- `windows-sys` 0.61.2 (the version most of the lock already uses), Windows only, the four features. The hand line in `Cargo.lock` was proved: the old lock with this `Cargo.toml` and stub sources, `cargo update --workspace --offline`, gave a lock identical to the one committed. `cargo metadata --locked --offline` resolves.
- Seen here: the two files in a scratch crate passed `cargo check --target x86_64-pc-windows-msvc` with no error and no warning (rustc 1.97.0) and its 6 unit tests. The shell itself was not compiled and nothing ran on Windows or macOS.

## The Windows engine is frozen with no console window (0.59.0)

- Kind: change. Logged: 2026-11-20. Refers to `setup/freeze_backend` and `setup/freeze_backend.bat`.
- Why: the owner's D3, the family's rule: a Windows engine is packaged with no console window, as FormWeb's is. Before, the Windows build of this engine opened a console window beside the app.
- What changed: on Windows both scripts give PyInstaller `--noconsole` unless `FORMVFX_ENGINE_WINDOWED=0`, the opt-out for a person who wants to see the engine's console. The other systems are untouched.
- Why this is safe here: `formvfx_engine.py` already replaces a missing standard input, output and error with the null device before anything else runs, so `--selfcheck`, `--gpu-probe` and the refusal sentences still run when there is no console; the shell reads the address and the window key through the pipes tauri-plugin-shell gives the engine, which a program with no console still has.
- Checked: `bash -n setup/freeze_backend`, and the `.bat` by reading. No Windows build has shown it.
2 changes: 1 addition & 1 deletion backend/app/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.58.0"
__version__ = "0.59.0"
42 changes: 36 additions & 6 deletions backend/app/agent/terminals.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from collections import deque
from pathlib import Path

from ..core import config
from ..engine.host import host
from . import claude_code, consent, workspace

Expand All @@ -24,6 +25,8 @@
AGENTS = {"claude": "claude", "codex": "codex", "cursor": "cursor-agent", "antigravity": "agy"}
TITLES = {"claude": "Claude Code", "codex": "Codex", "cursor": "Cursor", "antigravity": "Antigravity"}
TAB_FILE = (".agents", "mcp_config.json")
TAB_ROOT = ("agent-tabs", "antigravity")
TAB_GUIDE = "AGENTS.md"
TAB_HEADER = "x-formvfx-agent-token"


Expand Down Expand Up @@ -403,8 +406,33 @@ def find_agent(binary: str) -> str | None:
return claude_code.located(kind).path if kind else None


def tab_folder(guide: Path) -> Path:
folder = config.data_dir().joinpath(*TAB_ROOT, os.urandom(6).hex())
folder.mkdir(parents=True)
with contextlib.suppress(OSError):
(folder / TAB_GUIDE).write_bytes(guide.read_bytes())
return folder


def drop_tab_folder(folder: Path, token: str, guide: Path) -> None:
remove_tab_entry(folder, token)
path = folder.joinpath(*TAB_FILE)
with contextlib.suppress(OSError, ValueError):
if _tab_servers(path) == {"mcpServers": {}}:
path.unlink()
with contextlib.suppress(OSError):
if (folder / TAB_GUIDE).read_bytes() == guide.read_bytes():
(folder / TAB_GUIDE).unlink()
for emptied in (path.parent, folder):
with contextlib.suppress(OSError):
emptied.rmdir()


def _tab_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 formvfx can read, so it was left alone")
return data
Expand Down Expand Up @@ -451,19 +479,21 @@ def open_agent(kind: str, base_url: str, cols: int, rows: int) -> Session:
agent = consent.issue()
env = claude_code.child_env(environment(base_url), path)
env["FORMVFX_AGENT_TOKEN"] = agent
folder = workspace.ensure() if kind == "antigravity" else None
guide = workspace.root() / TAB_GUIDE
folder = None
try:
if folder is not None:
if kind == "antigravity":
folder = tab_folder(guide)
write_tab_entry(folder, base_url, agent)
session = open_session(kind, argv, env, cols, rows)
session = open_session(kind, argv, env, cols, rows, cwd=str(folder) if folder else None)
except BaseException:
consent.revoke(agent)
if folder is not None:
remove_tab_entry(folder, agent)
drop_tab_folder(folder, agent, guide)
raise
session.on_close.append(lambda: consent.revoke(agent))
if folder is not None:
session.on_close.append(lambda: remove_tab_entry(folder, agent))
session.on_close.append(lambda: drop_tab_folder(folder, agent, guide))
return session


Expand Down
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
2 changes: 1 addition & 1 deletion backend/tests/test_dock_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def _imports(path):

def test_the_shared_dock_files_match_their_manifest():
kept = json.loads((DOCK / "MANIFEST.json").read_text(encoding="utf-8"))
assert kept["module"] == "dock" and kept["version"] == "2.2.0"
assert kept["module"] == "dock" and kept["version"] == "2.2.1"
now = {p.name: hashlib.sha256(p.read_bytes()).hexdigest() for p in DOCK.iterdir() if p.is_file() and p.name != "MANIFEST.json"}
assert kept["files"] == now
assert f"Module version {kept['version']}." in (DOCK / "CONTRACT.md").read_text(encoding="utf-8")
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 @@ -132,6 +132,23 @@ def test_the_two_ways_of_reading_a_start_time_agree(monkeypatch):
assert startup.created(4_000_000) == 0.0


def test_a_holder_that_has_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_engine_serves_and_logs_with_its_three_streams_closed(tmp_path):
proc = subprocess.Popen(["sh", "-c", 'exec "$0" formvfx_engine.py <&- >&- 2>&-', sys.executable], cwd=BACKEND, env=engine_env(tmp_path))
log = tmp_path / "Logs" / "formvfx-engine.log"
Expand Down
71 changes: 56 additions & 15 deletions backend/tests/test_window_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,28 +239,69 @@ def test_a_codex_or_cursor_tab_gets_its_own_token_in_its_environment_until_the_t


@pytest.mark.skipif(os.name == "nt", reason="the stand-ins are shell scripts")
def test_an_antigravity_tab_gets_its_entry_in_the_workspace_file_until_the_tab_closes(client, keyed, tmp_path, monkeypatch):
def test_each_antigravity_tab_gets_a_folder_of_its_own_with_its_entry_until_the_tab_closes(client, keyed, tmp_path, monkeypatch):
from pathlib import Path

from app.agent import consent, terminals, workspace

_stand_in(tmp_path, "agy", 'pwd > "$FORMVFX_WORKSPACE/../agy-$$.cwd"\nsleep 30')
monkeypatch.setenv("PATH", f"{tmp_path}{os.pathsep}{os.environ.get('PATH', '')}")
shared = workspace.ensure() / ".agents" / "mcp_config.json"
shared.parent.mkdir(parents=True, exist_ok=True)
seed = json.dumps({"mcpServers": {"other": {"command": "/bin/true"}}, "theme": "kept"})
shared.write_text(seed, encoding="utf-8")
tabs = []
for _ in range(2):
made = client.post("/api/terminal/launch", headers=keyed, json={"agent": "antigravity", "cols": 80, "rows": 24})
assert made.status_code == 200 and made.json()["kind"] == "antigravity" and made.json()["title"].startswith("Antigravity")
tabs.append(terminals.get(made.json()["id"]))
first, second = tabs
folders = [Path(tab.cwd) for tab in tabs]
tokens = [tab.env["FORMVFX_AGENT_TOKEN"] for tab in tabs]
assert folders[0] != folders[1] and tokens[0] != tokens[1]
assert all(folder.parent == workspace.root().parent / "agent-tabs" / "antigravity" for folder in folders)
for folder, token in zip(folders, tokens):
held = folder / ".agents" / "mcp_config.json"
entry = json.loads(held.read_text(encoding="utf-8"))["mcpServers"]["formvfx_tab"]
assert entry["serverUrl"].endswith("/mcp") and entry["headers"]["x-formvfx-agent-token"] == token
assert stat.S_IMODE(os.stat(held).st_mode) == 0o600 and consent.in_app(token)
assert (folder / "AGENTS.md").read_bytes() == (workspace.root() / "AGENTS.md").read_bytes()
started = set()
for _ in range(100):
started = {note.read_text().strip() for note in workspace.root().parent.glob("agy-*.cwd")}
if len(started) == 2:
break
time.sleep(0.1)
assert started == {str(folder.resolve()) for folder in folders}
assert client.post("/api/terminal/close", headers=keyed, json={"id": first.id}).status_code == 200
assert not folders[0].exists() and not consent.in_app(tokens[0])
kept = json.loads((folders[1] / ".agents" / "mcp_config.json").read_text(encoding="utf-8"))
assert kept["mcpServers"]["formvfx_tab"]["headers"]["x-formvfx-agent-token"] == tokens[1] and consent.in_app(tokens[1])
assert client.post("/api/terminal/close", headers=keyed, json={"id": second.id}).status_code == 200
assert not folders[1].exists() and not consent.in_app(tokens[1])
assert shared.read_text(encoding="utf-8") == seed
shared.unlink()
for note in workspace.root().parent.glob("agy-*.cwd"):
note.unlink()


@pytest.mark.skipif(os.name == "nt", reason="the stand-ins are shell scripts")
def test_an_antigravity_tab_folder_that_holds_something_else_is_kept_when_the_tab_closes(client, keyed, tmp_path, monkeypatch):
from pathlib import Path

from app.agent import terminals

_stand_in(tmp_path, "agy", "sleep 30")
monkeypatch.setenv("PATH", f"{tmp_path}{os.pathsep}{os.environ.get('PATH', '')}")
kept = workspace.ensure() / ".agents" / "mcp_config.json"
kept.parent.mkdir(parents=True, exist_ok=True)
seed = {"mcpServers": {"other": {"command": "/bin/true"}}, "theme": "kept"}
kept.write_text(json.dumps(seed), encoding="utf-8")
made = client.post("/api/terminal/launch", headers=keyed, json={"agent": "antigravity", "cols": 80, "rows": 24})
assert made.status_code == 200 and made.json()["kind"] == "antigravity" and made.json()["title"].startswith("Antigravity")
assert made.status_code == 200
session = terminals.get(made.json()["id"])
token = session.env["FORMVFX_AGENT_TOKEN"]
now = json.loads(kept.read_text(encoding="utf-8"))
assert now["theme"] == "kept" and now["mcpServers"]["other"] == seed["mcpServers"]["other"]
entry = now["mcpServers"]["formvfx_tab"]
assert entry["serverUrl"].endswith("/mcp") and entry["headers"]["x-formvfx-agent-token"] == token
assert stat.S_IMODE(os.stat(kept).st_mode) == 0o600 and consent.in_app(token)
folder = Path(session.cwd)
(folder / "notes.txt").write_text("mine", encoding="utf-8")
assert client.post("/api/terminal/close", headers=keyed, json={"id": session.id}).status_code == 200
assert json.loads(kept.read_text(encoding="utf-8")) == seed
assert not consent.in_app(token)
kept.unlink()
assert sorted(item.name for item in folder.iterdir()) == ["notes.txt"]
(folder / "notes.txt").unlink()
folder.rmdir()


@pytest.mark.skipif(os.name == "nt", reason="the stand-ins are shell scripts")
Expand Down
Loading
Loading