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
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ The rest is written by hand.
| media.py | /api/media | 26 |
| media_check.py | /api/media/health | 1 |
| model_manager.py | /api/models | 8 |
| notices_api.py | /api/notices | 1 |
| orchestration.py | /api/orchestration | 4 |
| planar_api.py | /api/planar | 19 |
| presets.py | /api/presets | 9 |
Expand Down
2 changes: 2 additions & 0 deletions .docs/wiki/Licences.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

Ledger per dev-rules and the tauri pack's sidecar-tier policy. Distribution axis: the desktop bundle is distributed; the engine ships inside it, external binaries do not.

The full licence text of everything that ships (the Python runtime and packages, the PyInstaller bootloader, the npm packages built into the window, the Rust crates of the shell and the native kernels, and the FFmpeg and OpenH264 binaries) is in `THIRD-PARTY-NOTICES.txt` at the root of the repository, written by `setup/notices.py` and held by `setup/notices.py --check` in CI. It ships beside `NOTICE` in every installer and inside the frozen engine, and Settings, About shows it.

## Runtime dependencies (ship in the bundle)

| Component | License | Role | Decision |
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ jobs:
run: choco install ffmpeg -y --no-progress
- name: tests
run: python -m pytest tests -q
# THIRD-PARTY-NOTICES.txt must list every Python package, npm package in the window, crate and binary that
# ships, with its licence text; setup/notices.py regenerates it.
- name: third-party notices cover what ships
run: python setup/notices.py --check

- name: golden frames, and preview against export
if: matrix.os == 'ubuntu-latest'
Expand Down
3 changes: 2 additions & 1 deletion NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ backend/app/device_library (from 3d-mock-models) are original designs, modelled
from scratch in code, under CC0-1.0; their keyboard legends were drawn with the
Inter font (SIL Open Font License 1.1). They are provided as is and used at
each person's own risk, as USE_POLICY.md sets out. Every component and its obligations are
listed in .docs/wiki/Licences.md.
listed in .docs/wiki/Licences.md, and the full licence text of every third-party software component
that ships is in THIRD-PARTY-NOTICES.txt (Settings, About, Third-party notices).

Use of formcut is set out in USE_POLICY.md. As the Apache License, Version 2.0 provides (sections 7 and 8), formcut
is provided "as is", without warranties or conditions of any kind, and its contributors are not liable for its use
Expand Down
32,112 changes: 32,112 additions & 0 deletions THIRD-PARTY-NOTICES.txt

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions backend/HASHOUT_LOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@

Reasoning behind engine changes, newest first.

## Unreleased · THIRD-PARTY-NOTICES.txt holds the full licence text of everything that ships (`setup/notices.py`, `app/notices_api.py`)

- **What was missing.** NOTICE and `.docs/wiki/Licences.md` named the components and their licences, but only some of the licence texts travelled with the app (the FFmpeg sidecar's, OpenCV's, a few in copied package metadata). MIT, BSD and Apache terms ask for the text with the binaries.
- **How it is written.** `setup/notices.py`, after FormDAM's and formcraft's, walks `backend/requirements.txt` with every requested extra and every marker that holds on macOS (Apple silicon and Intel), Linux or Windows, leaving out pytest, maturin and PyYAML, which never reach the frozen engine. Packages that ship on another platform only (colorama, pyreadline3, pywin32, pywin32-ctypes on Windows; jeepney and secretstorage on Linux) are read from their published wheels with `--wheels`, then kept from the previous file. npm packages are walked from the window's dependencies through the lock file, skipping `onnxruntime-node` and `sharp`, which `@huggingface/transformers`' web build never imports; onnxruntime-web and onnxruntime-common carry no licence file, so the same project's text from the onnxruntime Python distribution is used. Crates come from both `src-tauri` and `backend/native` (the kernels inside the frozen engine). The binaries are the FFmpeg sidecar release named in `ffmpeg-licence.json` (its own THIRD-PARTY-NOTICES.txt and LGPL-2.1 text in full), FFmpeg's libraries beside PyAV (version from `setup/build_lgpl_av`) and Cisco's OpenH264 (its licence from `app/openh264.py`, by reference as a download).
- **The check.** `--check` fails when a pinned or transitive Python package, an npm package, a crate or a binary that ships has no section, when a section no longer ships, or when a section has no licence text because its source was not available. It reads only the lock files and installed metadata, so it runs on all three CI runners after the tests.
- **Served.** `GET /api/notices` reads the file beside the frozen engine or at the root of a clone, at most 16 MB, `no-store`; a build without it answers 404.

## Unreleased · the shared finder is 1.1.0, one Windows starter for npm, pnpm and bun shims (`app/agent_lookup.py`)

- **The copy.** `app/agent_lookup.py` is FormVis's 1.1.0 byte for byte (SHA-256 `313fcd40541199c920314516026a0b225aeb4915e9a5dc26bf51d1ba05f1da8e`, recorded in `setup/agents.py` `LOOKUP_HASHES`). The 1.0.2 here was formcut's own step on the way and is replaced, not merged: its `cmd_words` is now the family's `cmd_safe`, raising `CommandLineRefused` (an `OSError`, so `check` still reports such a program as not starting and the dock tab still refuses to open it).
- **What changes.** npm, pnpm and bun `.cmd` shims, in any letter case and with trailing dots, spaces or a `::$DATA` name, start their node or bun script or their `.exe` directly as an argument list. A shim that sets anything of its own other than `NODE_PATH`, or whose lines disagree on the runner, is not followed. Any other batch file goes through `cmd.exe /c` only when no word holds `& | < > ^ ( ) ! % "` or a control character, and a program path with a space is not followed by a word that needs quotes.
- **No wrapper to remove.** `dock_tabs.py` and `agent_connect.py` already called `start_argv` and `run` without hardening of their own, so nothing else changes.
- **Checked.** `tests/test_windows_start.py` runs the new rules with `platform="win32"` on any system, and checks the copy against its recorded hash.

## Unreleased · a job keeps its pass, and a pass for the agent's session (`app/agent_access.py`, `app/jobs.py`, `app/security.py`, `app/agent_mcp.py`)

- **The owner's choice.** Keep the fifteen-minute pass, but a tool call started under a pass that runs longer (a render) keeps it until the job ends. And the person can allow an agent for its session: until the agent disconnects or formcut quits.
Expand All @@ -15,6 +29,7 @@ Reasoning behind engine changes, newest first.
- **Not done.** The window cannot give the answer yet: the shared dock's dialog (module 2.2.1, never edited here) knows `deny`, `once` and `always` only, and the adapter keeps to those. The button needs a dock module change in FormVis, copied to the family.
- **Not run.** The Linux and Windows lookups have run here only on recorded tables and a stand-in `/proc`; the live connection test ran on macOS.
- **Tests.** `tests/test_agent_passes.py`, `tests/test_peer_process.py`.

## Unreleased · the suite's data folder on Windows is checked against the person's data folder (`tests/test_stand_in_home.py`)

- **What was there.** `test_the_data_folder_read_at_import_is_the_suites_own_and_not_under_the_persons_home` asserted that the suite's data folder is not anywhere under the person's home. On Windows the system temporary folder is `%LOCALAPPDATA%\Temp`, inside the home, so the folder `tempfile.mkdtemp` makes there always failed it (CI: `C:\Users\runneradmin\AppData\Local\Temp\formcut-tests-...`).
Expand Down
126 changes: 91 additions & 35 deletions backend/app/agent_lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

from __future__ import annotations

import errno
import os
import re
import shutil
Expand All @@ -27,7 +26,7 @@
from dataclasses import dataclass, field
from pathlib import Path

VERSION = "1.0.2"
VERSION = "1.1.0"
PROGRAMS: dict = {
"claude": {"title": "Claude Code", "names": ("claude",), "setting": "claudeBin",
"install": "curl -fsSL https://claude.ai/install.sh | bash", "install_windows": "irm https://claude.ai/install.ps1 | iex",
Expand Down Expand Up @@ -360,57 +359,114 @@ def _quote(word: str, fish: bool) -> str:
return "'" + word.replace("'", "'\"'\"'") + "'"


_SHIM_TARGET = re.compile(r'"%~?dp0%?\\?([^"%]+)"\s+%\*')
_CMD_NEVER = re.compile(r'[\x00-\x1f\x7f&|<>^()!%"]')
class CommandLineRefused(OSError):
"""A word the Windows command interpreter would not pass through to the program as it is."""


def shim_target(shim: str | os.PathLike, env: dict | None = None) -> list[str] | None:
"""What a package manager's .cmd shim runs (the program, or node and its script), read from the shim, so it can be
started directly instead of through the command interpreter; None when the shim says nothing this can follow."""
shim = Path(shim)
BATCH_ENDINGS = (".cmd", ".bat")
RUNNERS = ("node", "bun")
_STREAM = re.compile(r"(?:::\$data)?[ .]*$", re.I)
_DP0 = r'"%(?:~dp0|dp0%)\\?([^"%\r\n]+?\.{ext})"'
_RUNNER = r'(?:"%_prog%"|(node|bun)(?:\.exe)?|"%(?:~dp0|dp0%)\\?(node|bun)\.exe")'
_SHIM_SCRIPT = re.compile(r'(?:^|&)[ \t]*@?' + _RUNNER + r'[ \t]+' + _DP0.format(ext="(?:js|cjs|mjs)") + r'[ \t]+%\*[ \t\r]*$', re.I | re.M)
_SHIM_EXE = re.compile(r'(?:^|&)[ \t]*@?' + _DP0.format(ext="exe") + r'[ \t]+%\*[ \t\r]*$', re.I | re.M)
_SHIM_SETS = re.compile(r'\bset[ \t]+"?([A-Za-z_]\w*)=', re.I)
_SHIM_PROG = re.compile(r'\bset[ \t]+"?_prog=([^"\r\n]*)', re.I)
_PROG_VALUE = re.compile(r'(?:%(?:~dp0|dp0%)\\?)?(node|bun)(?:\.exe)?', re.I)
_SHIM_OWN_VARS = frozenset({"dp0", "_prog", "pathext", "node_path"})
_CMD_REFUSED = re.compile(r'[&|<>^()!%"\x00-\x1f\x7f]')
_CMD_QUOTED = re.compile(r'[ \t]')
REFUSAL = ("Windows starts this program through the command interpreter (cmd.exe), which would change or act on the text, so it "
"was not started. Pass long or special text through standard input or a file if the program supports it, or point "
"the setting at the program's .exe or node script so it starts without the command interpreter.")


def plain_name(path: str | os.PathLike) -> str:
"""The file name as Windows opens it: lower case, without trailing dots or spaces or a ::$DATA stream name."""
return _STREAM.sub("", Path(str(path)).name).lower()


def batch_file(path: str | os.PathLike) -> bool:
"""Whether Windows would start this file through the command interpreter (.cmd or .bat in any letter case)."""
return plain_name(path).endswith(BATCH_ENDINGS)


def _beside(folder: Path, rel: str) -> Path:
return folder.joinpath(*[part for part in rel.replace("\\", "/").split("/") if part])


def _runner(text: str, named: list[str]) -> str | None:
"""The one runner (node or bun) every script line of a shim uses, or None when they disagree or one is unknown."""
progs = _SHIM_PROG.findall(text)
stems = {word.lower() for word in named if word}
if any(not word for word in named):
for value in progs:
match = _PROG_VALUE.fullmatch(value.strip())
if not match:
return None
stems.add(match.group(1).lower())
return stems.pop() if len(stems) == 1 else None


def shim_target(shim: str, env: dict | None = None) -> list[str] | None:
"""The program an npm, pnpm or bun .cmd shim runs (its script with node or bun, or its .exe), so it can be started
without the command interpreter; None when the file is not such a shim (it sets anything of its own other than
NODE_PATH, or hands %* to anything else) or its target is missing. pnpm's NODE_PATH is not carried over: node finds a
package's own dependencies from the script's folder."""
env = os.environ if env is None else env
folder = Path(shim).parent
try:
text = shim.read_text(encoding="utf-8", errors="replace")
text = Path(shim).read_text(encoding="utf-8", errors="replace")[:65536]
except OSError:
return None
found = _SHIM_TARGET.findall(text)
if not found:
return None
target = shim.parent / found[-1].strip().replace("\\", os.sep).lstrip(os.sep)
kind = target.suffix.lower()
if not target.is_file() or kind not in (".exe", ".js", ".cjs", ".mjs"):
if any(name.lower() not in _SHIM_OWN_VARS for name in _SHIM_SETS.findall(text)):
return None
if kind == ".exe":
return [str(target)]
beside = shim.parent / "node.exe"
node = str(beside) if beside.is_file() else shutil.which("node", path=(env or os.environ).get("PATH"))
return [node, str(target)] if node else None
lines = _SHIM_SCRIPT.findall(text)
scripts = [_beside(folder, rel) for _bare, _dp0, rel in lines]
exes = [_beside(folder, rel) for rel in _SHIM_EXE.findall(text)]
if scripts and not exes and len(set(scripts)) == 1 and scripts[0].is_file():
runner = _runner(text, [bare or dp0 for bare, dp0, _rel in lines])
if runner is None:
return None
beside = folder / f"{runner}.exe"
found = str(beside) if beside.is_file() else shutil.which(runner, path=env.get("PATH", ""))
return [found, str(scripts[0])] if found else None
if exes and not scripts and len(set(exes)) == 1 and plain_name(exes[0]) not in ("node.exe", "bun.exe") and exes[0].is_file():
return [str(exes[0])]
return None


def cmd_words(words: list[str]) -> list[str]:
"""Words for the command interpreter's /c line. A .cmd file reads its arguments again through %*, and the interpreter
acts on & | < > ^ ( ) ! % and quotes even inside quotes, so any word holding one of them, or a control character, is
refused whether or not it has spaces. Long or free text belongs on the program's standard input or in a file."""
for word in words:
if _CMD_NEVER.search(word):
raise OSError(errno.EINVAL, "an argument holds a character the Windows command interpreter would act on "
"(& | < > ^ ( ) ! % \" or a control character), so it cannot be passed on the command line; "
"pass long text through standard input or a file if the program supports it")
return words
def cmd_safe(words: list[str]) -> None:
"""Raises CommandLineRefused unless cmd.exe /c would pass every word, the program's path included, unchanged. No word
may hold & | < > ^ ( ) ! % " or a control character: quotes do not protect a word there, so no word is let through
because it is quoted or has no spaces. A program path that needs quotes (a space or tab) keeps them only when it is
the line's one quoted word and holds no @, so such a path may not be followed by a word that needs quotes."""
words = [str(word) for word in words]
for index, word in enumerate(words):
if _CMD_REFUSED.search(word):
what = "The path of this program" if index == 0 else "A word for this program"
raise CommandLineRefused(f"{what} has one of & | < > ^ ( ) ! % \" or a control character. {REFUSAL}")
program, rest = words[0], words[1:]
if _CMD_QUOTED.search(program) and ("@" in program or any(word == "" or _CMD_QUOTED.search(word) for word in rest)):
raise CommandLineRefused("The path of this program has a space, and the command interpreter would drop its quotes when an "
f"@ is in it or another word has a space or is empty. {REFUSAL}")


def start_argv(cmd: list, env: dict | None = None, platform: str | None = None) -> list[str]:
"""How a program is started, the same for a tab, Chat and a check: through the person's login shell on macOS and Linux
(exec, so the process is the program), directly on Windows; a .cmd or .bat runs what it points at directly when it is
a package manager's shim, else through the command interpreter with only words it passes on as text."""
(exec, so the process is the program), directly on Windows. An npm, pnpm or bun .cmd shim is started as the node or bun
script or the program it names, with the words as an argv list; any other .cmd or .bat (any letter case, trailing dots
or spaces) goes through the command interpreter, only with words it passes through unchanged."""
words = [str(c) for c in cmd]
env = os.environ if env is None else env
if windows(platform):
if not words[0].lower().rstrip(". ").endswith((".cmd", ".bat")):
if not batch_file(words[0]):
return words
direct = shim_target(words[0], env)
if direct:
if direct and not batch_file(direct[0]):
return [*direct, *words[1:]]
return [env.get("COMSPEC") or "cmd.exe", "/c", *cmd_words(words)]
cmd_safe(words)
return [env.get("COMSPEC") or "cmd.exe", "/c", *words]
shell = login_shell(env, platform)
fish = Path(shell).name == "fish"
return [shell, "-l", "-c", "exec " + " ".join(_quote(w, fish) for w in words)]
Expand Down
2 changes: 2 additions & 0 deletions backend/app/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from .jobs import router as jobs
from .local_speech import router as speech
from .model_manager import router as models
from .notices_api import router as notices
from .orchestration import router as orchestration
from .project_tracking import router as project_tracking
from .providers import router as providers_router
Expand Down Expand Up @@ -41,5 +42,6 @@
orchestration,
recovery,
extensions,
notices,
):
router.include_router(module)
36 changes: 36 additions & 0 deletions backend/app/notices_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""Settings, About: THIRD-PARTY-NOTICES.txt, the licence text of every third-party component formcut ships.

setup/notices.py writes the file at the root of a clone; backend/freeze.py puts it beside the frozen engine.
"""

from __future__ import annotations

import sys
from pathlib import Path

from fastapi import APIRouter, HTTPException
from fastapi.responses import PlainTextResponse

NAME = "THIRD-PARTY-NOTICES.txt"
CAP = 16 * 1024 * 1024

router = APIRouter(prefix="/api/notices", tags=["notices"])


def notices_path() -> Path:
"""The notices file inside the frozen engine, or at the root of a clone."""
if getattr(sys, "frozen", False):
return Path(getattr(sys, "_MEIPASS", "")) / NAME
return Path(__file__).resolve().parents[2] / NAME


@router.get("", response_class=PlainTextResponse)
def notices() -> PlainTextResponse:
try:
with notices_path().open(encoding="utf-8") as handle:
text = handle.read(CAP + 1)
except OSError:
raise HTTPException(404, "The third-party notices are not in this build.") from None
if len(text) > CAP:
raise HTTPException(500, "The third-party notices file is larger than expected.")
return PlainTextResponse(text, headers={"Cache-Control": "no-store"})
1 change: 1 addition & 0 deletions backend/freeze.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
'--onefile' if args.onefile else '--onedir',
'--add-data', str(root.parent / 'frontend' / 'dist') + os.pathsep + 'frontend_dist',
'--add-data', str(root.parent / 'src-tauri' / 'binaries' / 'ffmpeg-licence.json') + os.pathsep + '.',
'--add-data', str(root.parent / 'THIRD-PARTY-NOTICES.txt') + os.pathsep + '.',
'--add-data', str(root / 'app' / 'effect_library') + os.pathsep + 'app/effect_library',
'--add-data', str(root / 'app' / 'bundled_models') + os.pathsep + 'app/bundled_models',
'--add-data', str(root / 'app' / 'device_library') + os.pathsep + 'app/device_library',
Expand Down
Loading
Loading