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
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ jobs:
backend/requirements-test.txt
- name: Engine and test dependencies
run: pip install -r backend/requirements.txt -r backend/requirements-test.txt
- name: Licence texts cover what ships
run: python setup/collect_licenses.py --check
- name: Engine tests, family layers included (no network, model tests skip)
working-directory: backend
run: python -m pytest -q -rs -p no:cacheprovider tests
Expand Down
2 changes: 1 addition & 1 deletion NOTICE.md
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,7 @@ The Linux AppImage that `tauri build` makes (`"targets": "all"`) bundles the sys

## Keeping this file current

The licence texts themselves are in `licenses/` at the repository root, bundled into every installer through `bundle.resources` in `src-tauri/tauri.conf.json`; `setup/collect_licenses.py` regenerates them (see `licenses/README.md`). flatbuffers, antlr4-python3-runtime and cuda-toolkit ship no licence file in their wheels, so their texts are not in that folder yet.
The licence texts themselves are in `licenses/` at the repository root, bundled into every installer through `bundle.resources` in `src-tauri/tauri.conf.json`; `setup/collect_licenses.py` regenerates them and `setup/collect_licenses.py --check` (run in CI) fails when one is missing (see `licenses/README.md`). The Rust crates are in `licenses/rust-crates.txt` with each crate's own licence files; the Python interpreter's licence is `licenses/python-runtime/LICENSE.txt`, and `licenses/ffmpeg.txt` points to the downloaded FFmpeg build's own notices and LGPL text. The 69 crates and the flatbuffers wheel that ship no licence file carry the texts kept in `setup/licence_texts/`, from their upstream repositories or, where upstream has none, the SPDX text, each with its source named; antlr4-python3-runtime and cuda-toolkit (ML extras) ship none either and have no texts kept yet.

After any dependency change, regenerate the tables above:

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

Living log for the engine service side, _v0.1.0. Read the map and the TOC first; entries are anchored by file and symbol, and removed code is quoted in full.

## The 69 crates and flatbuffers that ship no licence file now carry their upstream texts · after 2.8.4, unreleased (setup/licenses_vendored.py new; setup/licenses_rust.py KEPT, describe, kept, bare; setup/collect_licenses.py copy_kept, copy_dist, check; setup/licence_texts/ new; tests/test_licence_texts.py; licenses/rust-crates.txt; licenses/python/flatbuffers/)

- Kind: fix · logged 2026-11-29.
- Why: the 69 crates and the flatbuffers wheel that carry no licence file were listed with their SPDX licence and repository only, so the texts their licences ask to travel with the binaries were not in the installer.
- Now: `setup/licence_texts/<crate|python|npm>/<name>-<version>/` keeps each one's licence files, taken from its upstream repository at the published commit or tag (66 crates and flatbuffers), or the SPDX standard text with the holders its Cargo.toml names where upstream has none (dispatch 0.2.0, selectors 0.36.1, sigchld 0.2.5), each with a SOURCE.txt. `describe` falls back to `kept`, which prints the texts and SOURCE.txt under a Note naming the upstream files and ref or the SPDX text; `copy_dist` falls back to `copy_kept`, which copies them into the package's folder. `--check` fails when a crate or a NO-LICENCE-FILE.txt is bare while texts are kept for it. Tests: 7.
- Regenerated here: rust (42 crates for other systems from their crates.io archives; 0 crates left without texts) and python.

## licenses/ covers every crate, the Python runtime and the downloaded FFmpeg, and CI checks it · after 2.8.4, unreleased (setup/collect_licenses.py HAND_KEPT, RUST_FILE, FFMPEG_FILE, FFMPEG_NOTE, NO_FILE, dist_licence, dist_source, copy_dist, do_python, do_npm, do_rust, do_runtime, check, main; setup/licenses_rust.py new; tests/test_licence_texts.py new; licenses/; NOTICE.md; .github/workflows/ci.yml test job)

- Kind: fix · logged 2026-11-29.
- Why: the crate pages made with cargo-about on 2026-10-19 had fallen behind the lock files (25 crates of the shell and 137 of the renderer's lock file were not on them), fzstd and opentype.js shipped in the window with no folder under licenses/npm, and nothing said so. The Python interpreter's own licence and the FFmpeg build the engine downloads were not in the folder either.
- Now: `do_rust` writes `licenses/rust-crates.txt` (setup/licenses_rust.py): every registry crate reachable from `formvis` and `formvis-render` in their Cargo.lock files, every target, with each crate's licence files from the cargo registry (and folders named in FORMVIS_CRATE_SOURCES), shared texts printed once; a crate with no file, or with no source here, is listed with its SPDX licence and repository and a note. 658 crates, 69 of them carry no licence file. The two HTML pages, `src-tauri/about.toml` and `src-tauri/about.hbs` are removed. `do_runtime` copies the interpreter's LICENSE.txt to `licenses/python-runtime/` and writes `licenses/ffmpeg.txt` for release `RELEASE` of `app/ffmpeg_record.py`.
- `do_python` no longer empties `licenses/python` and `licenses/python-ml` first: each package's folder is replaced on its own, so packages collected on another system or with the ML extras stay; `pillow-heif` (written by hand) is left alone. A package with no licence file gets `NO-LICENCE-FILE.txt` with its licence and source (flatbuffers now); npm does the same.
- `--check` fails on a package installed from backend/requirements.txt, an npm production package of package-lock.json, or a crate of either Cargo.lock that has no texts, on a crate listed that is no longer locked, and on a missing runtime licence or an FFmpeg note for another release. The CI test job runs it before the engine tests. `tests/test_licence_texts.py` (4) runs it and checks that it names what is taken away.
- Regenerated here: python (macOS venv; ml-dtypes, numpy and tifffile texts changed), npm, rust (65 crates for other systems were read from their crates.io archives), runtime. Not regenerated: python-ml (the ML extras are not installed here).

## The shared finder is 1.1.0: one Windows starter for npm, pnpm and bun shims · after 2.8.4, unreleased (services/agent_lookup.py VERSION, BATCH_ENDINGS, RUNNERS, REFUSAL, plain_name, batch_file, _runner, shim_target, cmd_safe, start_argv; setup/agents.py LOOKUP_HASHES; tests/test_agent_lookup_windows.py new; docs/AGENT_LOOKUP.md new)

- Kind: fix · logged 2026-11-29.
- Why: the family's copies of the finder had drifted into several different 1.0.2 files, and some apps kept the Windows hardening in wrappers of their own. 1.1.0 is the one canonical file, with the best of those copies, for every app to take unchanged.
- Now: `batch_file` reads a name as Windows opens it (any letter case, trailing dots or spaces, a `::$DATA` stream name dropped) and `start_argv` uses it for the program and for what a shim names. Before, quoted exactly: ` if not words[0].lower().endswith((".cmd", ".bat")):` and ` if direct and not direct[0].lower().endswith((".cmd", ".bat")):`.
- `shim_target` also follows pnpm shims (they set `NODE_PATH`, which is now allowed and not carried over) and bun shims (`bun` or the shim's own `bun.exe` in front of the script). The runner is read from the script lines and from `_prog`'s values; a shim whose lines name different runners, or whose `_prog` is anything but node or bun, is not followed. Before, `"%_prog%"` was taken as node without reading `_prog`. Removed, quoted exactly: `_SHIM_SCRIPT = re.compile(r'(?:^|&)[ \t]*@?(?:"%_prog%"|node|"%(?:~dp0|dp0%)\\?node\.exe")[ \t]+' + _DP0.format(ext="(?:js|cjs|mjs)") + r'[ \t]+%\*[ \t\r]*$', re.I | re.M)` and `_SHIM_OWN_VARS = frozenset({"dp0", "_prog", "pathext"})`.
- `cmd_safe` keeps its character rule and adds the quoting rule FormWeb had: a program path with a space or tab keeps its quotes under `cmd /c` only when it is the one quoted word and holds no `@`, so such a path followed by a word with a space, a tab or an empty word is refused. The refusal text (`REFUSAL`) says to pass long or special text through standard input or a file.
- `LOOKUP_HASHES` records `1.1.0`: `313fcd40541199c920314516026a0b225aeb4915e9a5dc26bf51d1ba05f1da8e`. `docs/AGENT_LOOKUP.md` says how other apps copy the file; a test holds it to the file's version and hash.
- Seen: tests/test_agent_lookup_windows.py (runs on any system with `platform="win32"` and shims in a temporary folder) and tests/test_agent_lookup.py here on macOS. Not run: Windows itself, or a real pnpm or bun install.

## The command line is known by a key the engine writes, not by its name · _v2.8.5 (core/cli_key.py new; main.py lifespan; routers/mcp.py _from_cli; setup/cli.py ROOT, KEY_FILE, KEY_HEADER, engine_setting, data_folder, cli_key, headers, call, serve_request; tests/test_cli_key.py new; docs/MANUAL.md; .docs/wiki/Agents.md)

- Kind: fix · logged 2026-11-29.
Expand Down
83 changes: 63 additions & 20 deletions backend/app/services/agent_lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,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 @@ -363,22 +363,56 @@ class CommandLineRefused(OSError):
"""A word the Windows command interpreter would not pass through to the program as it is."""


BATCH_ENDINGS = (".cmd", ".bat")
RUNNERS = ("node", "bun")
_STREAM = re.compile(r"(?:::\$data)?[ .]*$", re.I)
_DP0 = r'"%(?:~dp0|dp0%)\\?([^"%\r\n]+?\.{ext})"'
_SHIM_SCRIPT = re.compile(r'(?:^|&)[ \t]*@?(?:"%_prog%"|node|"%(?:~dp0|dp0%)\\?node\.exe")[ \t]+' + _DP0.format(ext="(?:js|cjs|mjs)") + r'[ \t]+%\*[ \t\r]*$', re.I | re.M)
_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_OWN_VARS = frozenset({"dp0", "_prog", "pathext"})
_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 .cmd shim runs (its script with node, 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, or hands %* to anything else) or
its target is missing."""
"""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:
Expand All @@ -387,40 +421,49 @@ def shim_target(shim: str, env: dict | None = None) -> list[str] | None:
return None
if any(name.lower() not in _SHIM_OWN_VARS for name in _SHIM_SETS.findall(text)):
return None
scripts = [_beside(folder, rel) for rel in _SHIM_SCRIPT.findall(text)]
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():
node = folder / "node.exe"
found = str(node) if node.is_file() else shutil.which("node", path=env.get("PATH", ""))
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 exes[0].name.lower() != "node.exe" and exes[0].is_file():
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_safe(words: list[str]) -> None:
"""Raises CommandLineRefused unless every word, the program's path included, is free of the characters cmd.exe /c
or a batch file's %* may act on: & | < > ^ ( ) ! % " and control characters. Quotes do not protect a word there, so
no word is let through because it is quoted or has no spaces."""
"""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, which the Windows command "
"interpreter that starts it could change. Pass long or special text through standard input or a file "
"if the program supports it, or install the program so it starts without the command interpreter.")
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. An npm .cmd shim is started as the node script or program
it names; any other .cmd or .bat goes through the command interpreter, only with words it passes through unchanged."""
(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().endswith((".cmd", ".bat")):
if not batch_file(words[0]):
return words
direct = shim_target(words[0], env)
if direct and not direct[0].lower().endswith((".cmd", ".bat")):
if direct and not batch_file(direct[0]):
return [*direct, *words[1:]]
cmd_safe(words)
return [env.get("COMSPEC") or "cmd.exe", "/c", *words]
Expand Down
Loading
Loading