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
7 changes: 5 additions & 2 deletions .agents/skills/formvfx-harness/references/tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ Note: read-only.

## execute

Runs one formvfx command by id with its parameters (see describe_command) and returns its result. Undoable commands are one step in the person's History.
Runs one formvfx command by id with its parameters (see describe_command) and returns its result. Undoable commands are one step in the person's History. Commands that replace the open project (file.newProject, file.open, file.closeProject, file.openRecent, file.openDemoProject, templates.create) refuse while it has unsaved changes unless discard is true.

- `command`: string; required
- `params`: object; The command's parameters.
- `discard`: boolean; default false; replace an open project that has unsaved changes

## batch

Expand All @@ -49,6 +50,7 @@ Runs several commands as one undo step. Each step is {command, params}; a string
- `steps`: array; required
- `label`: string
- `atomic`: boolean; default true
- `discard`: boolean; default false; replace an open project that has unsaved changes

## get_comp

Expand Down Expand Up @@ -217,10 +219,11 @@ Live Link: another app (formcut, an editor, a script) uses a composition as a li

## project

Project files: new, open (path), save (path for the first save), saveAs (path), close. formvfx projects are .fvxproj JSON; projects saved as .ecproj by earlier formvfx releases open as imports.
Project files: new, open (path), save (path for the first save), saveAs (path), close. formvfx projects are .fvxproj JSON; projects saved as .ecproj by earlier formvfx releases open as imports. new, open, close and demo replace the open project and clear its undo history, so they refuse while it has unsaved changes: save first, or pass discard: true only when the person agreed to lose them.

- `action`: string (new | open | save | saveAs | close | demo); required
- `path`: string
- `discard`: boolean; default false; replace an open project that has unsaved changes

Note: replaces or removes.

Expand Down
7 changes: 5 additions & 2 deletions .claude/skills/formvfx-harness/references/tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ Note: read-only.

## execute

Runs one formvfx command by id with its parameters (see describe_command) and returns its result. Undoable commands are one step in the person's History.
Runs one formvfx command by id with its parameters (see describe_command) and returns its result. Undoable commands are one step in the person's History. Commands that replace the open project (file.newProject, file.open, file.closeProject, file.openRecent, file.openDemoProject, templates.create) refuse while it has unsaved changes unless discard is true.

- `command`: string; required
- `params`: object; The command's parameters.
- `discard`: boolean; default false; replace an open project that has unsaved changes

## batch

Expand All @@ -49,6 +50,7 @@ Runs several commands as one undo step. Each step is {command, params}; a string
- `steps`: array; required
- `label`: string
- `atomic`: boolean; default true
- `discard`: boolean; default false; replace an open project that has unsaved changes

## get_comp

Expand Down Expand Up @@ -217,10 +219,11 @@ Live Link: another app (formcut, an editor, a script) uses a composition as a li

## project

Project files: new, open (path), save (path for the first save), saveAs (path), close. formvfx projects are .fvxproj JSON; projects saved as .ecproj by earlier formvfx releases open as imports.
Project files: new, open (path), save (path for the first save), saveAs (path), close. formvfx projects are .fvxproj JSON; projects saved as .ecproj by earlier formvfx releases open as imports. new, open, close and demo replace the open project and clear its undo history, so they refuse while it has unsaved changes: save first, or pass discard: true only when the person agreed to lose them.

- `action`: string (new | open | save | saveAs | close | demo); required
- `path`: string
- `discard`: boolean; default false; replace an open project that has unsaved changes

Note: replaces or removes.

Expand Down
83 changes: 79 additions & 4 deletions backend/app/agent/agent_lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
import threading
import time
from dataclasses import dataclass, field
from pathlib import Path
from pathlib import Path, PureWindowsPath

VERSION = "1.0.1"
VERSION = "1.0.2"
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 @@ -359,13 +359,88 @@ def _quote(word: str, fish: bool) -> str:
return "'" + word.replace("'", "'\"'\"'") + "'"


class UnsafeArgument(ValueError):
"""A word that the Windows command interpreter would read as something other than one plain argument."""


_SHIM_TARGET = re.compile(r'"%~?dp0%?\\?([^"%\r\n]+?\.(?:js|cjs|mjs|exe))"', re.I)
_CONTROL = re.compile(r"[\x00-\x1f\x7f]")
_CMD_SPECIAL = frozenset('&|<>^()!')
_CMD_TEXT = _CMD_SPECIAL | frozenset('%"')


def shim_target(shim: str | os.PathLike, env: dict | None = None) -> list[str] | None:
"""The program an npm style .cmd shim starts, as words to run without the command interpreter: the .exe it names, or
node (the one beside the shim, else node on PATH) and the script it names. None when the shim is of another kind."""
env = os.environ if env is None else env
try:
with open(shim, encoding="utf-8", errors="replace") as f:
text = f.read(65536)
except OSError:
return None
found = [f for f in _SHIM_TARGET.findall(text) if PureWindowsPath(f).name.lower() != "node.exe"]
if not found:
return None
folder = Path(shim).parent
target = folder.joinpath(*PureWindowsPath(found[-1]).parts)
if not target.is_file():
return None
if target.suffix.lower() == ".exe":
return [str(target)]
beside = folder / "node.exe"
node = str(beside) if beside.is_file() else shutil.which("node", path=env.get("PATH"))
return [node, str(target)] if node else None


def _quoted(word: str) -> bool:
return word == "" or " " in word or "\t" in word


def _windows_name(program: str) -> str:
return str(program).lower().rstrip(" .").removesuffix("::$data").rstrip(" .")


def is_batch(program: str) -> bool:
"""Whether Windows runs this file through the command interpreter: a .cmd or .bat, in any case, also with the trailing dots,
spaces or ::$DATA stream name that Windows drops from a file name."""
return _windows_name(program).endswith((".cmd", ".bat"))


def cmd_safe(words: list[str]) -> list[str]:
"""Words for `cmd.exe /c`. The batch file reads its arguments again (%*), and the command interpreter acts on
& | < > ^ ( ) ! % and quote marks even inside quotes, so any argument with one of them, or with a control character,
is refused whether or not it has a space. The program path may hold ( ) only when it is quoted (it has a space), and
then no argument may need quotes either, because `cmd /c` drops the first and the last quote mark of such a line."""
program = words[0]
program_quoted = _quoted(program)
allowed = frozenset("()") if program_quoted else frozenset()
if _CONTROL.search(program) or set(program) & (_CMD_SPECIAL - allowed) or "%" in program or '"' in program:
raise UnsafeArgument("This program cannot be started through the Windows command interpreter from its folder (the path "
"has a control character, a quote mark, a percent sign or one of & | < > ^ ( ) !). "
"Install the program's own .exe, or move it to a plain folder.")
for word in words[1:]:
if _CONTROL.search(word) or set(word) & _CMD_TEXT or (program_quoted and _quoted(word)):
raise UnsafeArgument("This text cannot be passed to the program through the Windows command interpreter (it has a "
"line break or other control character, a quote mark, a percent sign or one of & | < > ^ ( ) !, "
"or the program's folder has a space and the text needs quotes). Pass long text through standard "
"input or a file if the program takes it that way, install the program's own .exe, or leave "
"those characters out.")
return words


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 with the command interpreter in front of a .cmd or .bat."""
(exec, so the process is the program), directly on Windows. A .cmd shim is followed to the program it starts; any other
.cmd or .bat goes through the command interpreter, which takes only words it cannot misread."""
words = [str(c) for c in cmd]
env = os.environ if env is None else env
if windows(platform):
return [env.get("COMSPEC") or "cmd.exe", "/c", *words] if words[0].lower().endswith((".cmd", ".bat")) else words
if not is_batch(words[0]):
return words
direct = shim_target(words[0], env) if _windows_name(words[0]).endswith(".cmd") else None
if direct:
return [*direct, *words[1:]]
return [env.get("COMSPEC") or "cmd.exe", "/c", *cmd_safe(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
Loading
Loading