Skip to content

Make videos on the computer you already own. FreeVideo runs MiniMax H3 in as little as 8 GB of VRAM and 16 GB of RAM, and adapts its acceleration path to your hardware.

Fix agent launch quoting, Mac entry points and UTF-8 I/O

Bowen Xue80a4db74a8d7
diff --git a/freevideo_engine/agent/cli.py b/freevideo_engine/agent/cli.py
index ed1b81e..ca0eadb 100644
--- a/freevideo_engine/agent/cli.py
+++ b/freevideo_engine/agent/cli.py
@@ -4,6 +4,11 @@
./freevideo agent submit shot.json --wait
./freevideo agent batch storyboard.json --wait
./freevideo agent job j0123456789ab
+
+Linux x86_64 uses ./freevideo; Windows uses freevideo.cmd. On macOS and other
+Unix platforms, use the installed interpreter and source folder:
+ env FREEVIDEO_AGENT=1 PYTHONPATH=/path/to/FreeVideo/engine-source \
+ /path/to/installed/python -X utf8 -m freevideo_engine.agent.cli --root /path/to/FreeVideo status
"""
import argparse
import json
@@ -137,6 +142,9 @@ def build_parser():
def main(argv=None):
+ for stream in (sys.stdin, sys.stdout):
+ if hasattr(stream, 'reconfigure'):
+ stream.reconfigure(encoding='utf-8')
parser = build_parser()
args = parser.parse_args(argv)
values = vars(args)
diff --git a/freevideo_engine/agent/mcp.py b/freevideo_engine/agent/mcp.py
index 3ecb5db..4855fb1 100644
--- a/freevideo_engine/agent/mcp.py
+++ b/freevideo_engine/agent/mcp.py
@@ -1,8 +1,12 @@
"""FreeVideo as an MCP server (stdio, JSON-RPC 2.0), for Claude Code, Claude Desktop, Cursor and other agents.
- ./freevideo mcp # Linux / macOS
+ ./freevideo mcp # Linux x86_64
freevideo.cmd mcp # Windows
- ./freevideo mcp --print-config # ready-to-paste client configuration
+ ./freevideo mcp --print-config # Linux client configuration
+ # macOS / other Unix platforms: use the installed Python and source folder.
+ env FREEVIDEO_AGENT=1 PYTHONPATH=/path/to/FreeVideo/engine-source \
+ /path/to/installed/python -X utf8 -m freevideo_engine.agent.mcp --root /path/to/FreeVideo
+ # Add --print-config to print client configuration.
Standard library only; it talks to the running ComfyUI through the agent API.
"""
@@ -406,6 +410,29 @@ class Server:
return [dict(type='image', data=base64.b64encode(data).decode(), mimeType='image/jpeg')]
+def shell_quote(value, *, windows=None):
+ """Quote display arguments for cmd.exe or a POSIX shell, not C argv parsing."""
+ windows = sys.platform == 'win32' if windows is None else windows
+ if windows:
+ return '"' + value + '"' if not value or any(c.isspace() or c in '&()^%!|<>;,=' for c in value) else value
+ import shlex
+ return shlex.quote(value)
+
+
+def linux_wrapper_supported():
+ import platform
+ return sys.platform.startswith('linux') and platform.machine() == 'x86_64'
+
+
+def python_shell_command(config, module):
+ """Direct Unix entry using this installation's interpreter, source and root."""
+ command = list(config['command'])
+ command[command.index('-m') + 1] = module
+ command[1:1] = ['-X', 'utf8']
+ env = ['FREEVIDEO_AGENT=1'] + [key + '=' + value for key, value in config['env'].items()]
+ return 'env ' + ' '.join(shell_quote(value) for value in env + command)
+
+
def client_config(root):
"""How MCP clients start this server for this installation."""
root = Path(root).resolve()
@@ -416,14 +443,17 @@ def client_config(root):
python = sys.executable
command = [python, '-B', '-m', 'freevideo_engine.agent.mcp', '--root', str(root)]
env = {'PYTHONPATH': str(Path(__file__).resolve().parents[2])}
- import shlex
- import subprocess
- quote = lambda p: subprocess.list2cmdline([p]) if sys.platform == 'win32' else shlex.quote(p)
- return dict(command=command, env=env, codex='codex mcp add freevideo --env PYTHONPATH=%s -- %s' % (
- quote(env['PYTHONPATH']), ' '.join(quote(p) for p in command)), mcp_json={'mcpServers': {'freevideo': {
+ shell_command = list(command)
+ if sys.platform != 'win32' and not linux_wrapper_supported():
+ shell_command[1:1] = ['-X', 'utf8']
+ # Keep JSON argv untouched. Windows command text targets Command Prompt.
+ assignment = shell_quote('PYTHONPATH=' + env['PYTHONPATH']) if sys.platform == 'win32' else \
+ 'PYTHONPATH=' + shell_quote(env['PYTHONPATH'])
+ return dict(command=command, env=env, codex='codex mcp add freevideo --env %s -- %s' % (
+ assignment, ' '.join(shell_quote(p) for p in shell_command)), mcp_json={'mcpServers': {'freevideo': {
'command': command[0], 'args': command[1:], 'env': env}}},
- claude_code='claude mcp add freevideo --env PYTHONPATH=%s -- %s' % (
- quote(env['PYTHONPATH']), ' '.join(quote(p) for p in command)))
+ claude_code='claude mcp add freevideo --env %s -- %s' % (
+ assignment, ' '.join(shell_quote(p) for p in shell_command)))
def print_config(root):
diff --git a/freevideo_engine/agent/routes.py b/freevideo_engine/agent/routes.py
index a66f868..fdb976e 100644
--- a/freevideo_engine/agent/routes.py
+++ b/freevideo_engine/agent/routes.py
@@ -679,7 +679,7 @@ def register():
# For Settings: how to connect an agent on this computer. The token itself stays in its file.
from ..comfy_bridge import installation_root, source_root
from .guide import page_language
- from .mcp import client_config
+ from .mcp import client_config, linux_wrapper_supported, python_shell_command, shell_quote
page_language(request[query_key].get('lang'))
try:
root = installation_root()
@@ -687,16 +687,19 @@ def register():
except (OSError, ValueError) as error:
return problem('not_ready', str(error), 503)
config = await asyncio.to_thread(client_config, root)
- script = next((folder / name for folder in (root, source_root())
- for name in (('freevideo.cmd',) if os.name == 'nt' else ('freevideo',))
- if (folder / name).is_file()), None)
+ if os.name != 'nt' and not linux_wrapper_supported():
+ cli = python_shell_command(config, 'freevideo_engine.agent.cli') + ' status'
+ else:
+ script = next((folder / name for folder in (root, source_root())
+ for name in (('freevideo.cmd',) if os.name == 'nt' else ('freevideo',))
+ if (folder / name).is_file()), None)
+ cli = shell_quote(str(script), windows=os.name == 'nt') + ' agent status' if script else None
seen = {}
for row in jobs.rows():
if row.get('client'):
seen[row['client']] = max(seen.get(row['client'], 0), row['created_at'])
return reply(dict(address=local_address(request), api=PREFIX, token_file=str(token_path(root)), claude_code=config['claude_code'],
- mcp_json=config['mcp_json'], cli=('"%s"' % script if ' ' in str(script) else str(script))
- + ' agent status' if script else None,
+ mcp_json=config['mcp_json'], cli=cli,
token_from_environment=False,
agents=[dict(client=name, last_seen=time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime(stamp)))
for name, stamp in sorted(seen.items(), key=lambda item: -item[1])[:5]]))