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 @@ -76,7 +76,7 @@ To turn a shot into media, use `command_run` with the scene's generate-from-came

## Projects

`projects_list` and `projects_get` read; `projects_create` and `projects_update` write; `projects_export` writes a `.fcrft` file; `projects_import` reads one; `projects_delete` asks. A project open in the window reloads when changed under it.
`projects_list` and `projects_get` read; `projects_create` and `projects_update` write, and replacing a project's document asks every time (that answer is never remembered); `projects_export` writes a `.fcrft` file; `projects_import` reads one; `projects_delete` asks. `folders_delete`, `tags_delete` and `characters_delete` ask too. A project open in the window reloads when changed under it.

## Catalogue of commands

Expand Down
8 changes: 4 additions & 4 deletions .agents/skills/formcraft-harness/references/tool-map.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,18 @@ These run in the engine and work with the window closed. Code: `backend/app/serv
| `folders_list` | R | `GET /api/folders` | |
| `folders_create` | W | `POST /api/folders` | |
| `folders_update` | W | `PATCH /api/folders/{id}` | |
| `folders_delete` | D | `DELETE /api/folders/{id}` | |
| `folders_delete` | D | `DELETE /api/folders/{id}` | asks |
| `folders_add_items` | W | `POST /api/folders/{id}/items` | |
| `tags_list` | R | `GET /api/tags` | |
| `tags_apply` | W | `POST /api/tags/apply` | |
| `tags_rename` | W | `PATCH /api/tags/{name}` | |
| `tags_delete` | D | `DELETE /api/tags/{name}` | |
| `tags_delete` | D | `DELETE /api/tags/{name}` | asks |
| `characters_list`, `characters_get` | R | `GET /api/characters`, `/{id}` | |
| `characters_create`, `characters_update` | W | `POST`, `PATCH /api/characters` | |
| `characters_delete` | D | `DELETE /api/characters/{id}` | |
| `characters_delete` | D | `DELETE /api/characters/{id}` | asks |
| `prompt_history` | R | `GET /api/prompts` | |
| `projects_list`, `projects_get` | R | `GET /api/projects`, `/{id}` | kinds storyboard, scene, canvas, board, edit |
| `projects_create`, `projects_update` | W | `POST`, `PUT`, `PATCH /api/projects` | a project open in the window reloads through its changed-under-it path |
| `projects_create`, `projects_update` | W | `POST`, `PUT`, `PATCH /api/projects` | a project open in the window reloads through its changed-under-it path; replacing the document asks |
| `projects_export` | W | `POST /api/projects/{id}/export` | overwriting a file asks |
| `projects_import` | W | `POST /api/projects/import` | |
| `projects_delete` | D | `DELETE /api/projects/{id}` | asks |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ To turn a shot into media, use `command_run` with the scene's generate-from-came

## Projects

`projects_list` and `projects_get` read; `projects_create` and `projects_update` write; `projects_export` writes a `.fcrft` file; `projects_import` reads one; `projects_delete` asks. A project open in the window reloads when changed under it.
`projects_list` and `projects_get` read; `projects_create` and `projects_update` write, and replacing a project's document asks every time (that answer is never remembered); `projects_export` writes a `.fcrft` file; `projects_import` reads one; `projects_delete` asks. `folders_delete`, `tags_delete` and `characters_delete` ask too. A project open in the window reloads when changed under it.

## Catalogue of commands

Expand Down
8 changes: 4 additions & 4 deletions .claude/skills/formcraft-harness/references/tool-map.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,18 @@ These run in the engine and work with the window closed. Code: `backend/app/serv
| `folders_list` | R | `GET /api/folders` | |
| `folders_create` | W | `POST /api/folders` | |
| `folders_update` | W | `PATCH /api/folders/{id}` | |
| `folders_delete` | D | `DELETE /api/folders/{id}` | |
| `folders_delete` | D | `DELETE /api/folders/{id}` | asks |
| `folders_add_items` | W | `POST /api/folders/{id}/items` | |
| `tags_list` | R | `GET /api/tags` | |
| `tags_apply` | W | `POST /api/tags/apply` | |
| `tags_rename` | W | `PATCH /api/tags/{name}` | |
| `tags_delete` | D | `DELETE /api/tags/{name}` | |
| `tags_delete` | D | `DELETE /api/tags/{name}` | asks |
| `characters_list`, `characters_get` | R | `GET /api/characters`, `/{id}` | |
| `characters_create`, `characters_update` | W | `POST`, `PATCH /api/characters` | |
| `characters_delete` | D | `DELETE /api/characters/{id}` | |
| `characters_delete` | D | `DELETE /api/characters/{id}` | asks |
| `prompt_history` | R | `GET /api/prompts` | |
| `projects_list`, `projects_get` | R | `GET /api/projects`, `/{id}` | kinds storyboard, scene, canvas, board, edit |
| `projects_create`, `projects_update` | W | `POST`, `PUT`, `PATCH /api/projects` | a project open in the window reloads through its changed-under-it path |
| `projects_create`, `projects_update` | W | `POST`, `PUT`, `PATCH /api/projects` | a project open in the window reloads through its changed-under-it path; replacing the document asks |
| `projects_export` | W | `POST /api/projects/{id}/export` | overwriting a file asks |
| `projects_import` | W | `POST /api/projects/import` | |
| `projects_delete` | D | `DELETE /api/projects/{id}` | asks |
Expand Down
4 changes: 4 additions & 0 deletions agents/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@
"library_import",
"library_save_copy",
"library_delete",
"folders_delete",
"tags_delete",
"characters_delete",
"projects_update",
"projects_export",
"projects_delete",
"starter_pack_install",
Expand Down
19 changes: 19 additions & 0 deletions backend/HASHOUT_LOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2247,6 +2247,17 @@ From VERIFY_v0.8.0_E2E.md. A closed page's long poll could take a queued call: t
- **CI.** The `install` job runs `./formcraft install` and the self-check. `install-desktop`, the freeze and the desktop build still run in no job.
- Removed code: none.

## 2026-11-28 · agent controls, approvals, the Windows prompt and dev origins {#agents-hardening}

- refers-to: app/routers/agents.py :: WINDOW; app/routers/settings.py :: write_settings; app/services/mcp_tools.py :: folders_delete, tags_delete, characters_delete, projects_update; app/services/claude_code.py :: located, checked_script, through_interpreter, interpreter_safe, direct, launch_words, interpreter_argv, run, tab_argv, open_tab; app/services/command_script.py :: safe, resolve; app/services/agent_programs.py :: open_tab, claude_signed_in; app/services/agents.py :: NEVER_REMEMBERED, rememberable, approval_key, remember, remembered, Bridge.ask; frontend src/automation/approvals.ts; app/core/config.py :: window_origins; app/core/local_guard.py :: LocalGuard.allowed; app/main.py; tests/cb01/test_core_local_guard.py, tests/cb02/test_services_mcp_tools_approval.py, tests/cb03/test_routers_agents_window_key.py, tests/cb03/test_services_claude_code_prompt.py, tests/cb03/test_services_command_script.py, tests/cb02/test_services_agents_replace_doc.py
- **Window key on agent routes.** Every `/api/agents/*` route except `POST /api/agents/bridge/bye` now depends on `window_key.require`, and so does `PUT /api/settings` (it carries `agentsAllowed`). These are the window's controls: the bridge queue, results, approvals, policies, the token, activity and stop. The window's patched `fetch` adds the key to every `/api/` call, so it is unaffected. `bye` stays open because the window sends it with `sendBeacon`, which cannot set a header; it only shortens the connected grace period. `GET /api/settings` stays open.
- **Approvals for changes that cannot be undone.** `folders_delete`, `tags_delete` and `characters_delete` are `risky=True`, and `projects_update` is risky when `doc` is given (the document is replaced and no earlier version is kept). They ask whatever the client policy, like `projects_delete` and `library_delete`. Renames and cover changes still follow the policy. `agents.approval_key` keys a `projects_update` with `doc` as `projects_update:doc` and every other `projects_update` as `projects_update`, so a remembered rename or cover change never covers a document replacement. `projects_update:doc` is in `agents.NEVER_REMEMBERED` with the bare `generate`: `remember` never stores it, `remembered` never honours a stored copy, and the approval item carries `rememberable: false` so the window hides the remember box.
- **Command scripts on Windows.** `claude_code.launch_words` is the one place a Windows `.cmd` or `.bat` start is decided, used by `interpreter_argv` (the Claude Code tab and the other agent tabs), `claude_code.run` (the sign-in check) and `checked_script` (the `--version` check `located` uses for a script instead of `agent_lookup.check`, which would start it through cmd.exe). First `command_script.resolve` reads an npm-style shim (at most 64 KiB): the last line holding `%*`, its last quoted word that starts with `%dp0%` or `%~dp0` and is not `node.exe`, with no other `%` left. The target must be an existing file inside the shim's folder (its parent for a `.bin` folder). A `.js`, `.cjs` or `.mjs` target runs as `[node.exe, script, ...]`, with `node.exe` from the shim's folder or else the child PATH; an `.exe` target runs as itself. Then no cmd.exe is involved, the words are an argv list and the prompt goes on the command line again. When the shim does not resolve, cmd.exe is still used and every word, the program path included, must be text with none of `& | < > ^ ( ) ! % "` and no control character (`\x00` to `\x1f`, `\x7f`), with or without spaces: the `/c` line is read by cmd.exe and again by the shim's `%*`, so quoting protects nothing. Otherwise a `LookupError` with `command_script.REFUSED` (the router's 409 path), which says to pass long text through standard input or a file; the checks report broken or unknown without running anything. The earlier exception for `(` and `)` inside a quoted word is gone. Open: the shim formats are checked against hand-written samples in `tests/cb03/test_services_command_script.py`, not yet on a Windows machine.
- **Windows prompt.** A Claude Code found as a `.cmd` or `.bat` starts as `cmd.exe /c ...`, and cmd.exe reads its command line itself: inner quotes, `& | < > ^` and `%VAR%` are not protected by the MSVC quoting pywinpty applies. `tab_argv` leaves the prompt off that command line (only while the shim does not resolve, see above) and `open_tab` types it into the new tab with a carriage return, as it already did for a running tab. `.exe` and macOS and Linux are unchanged. The check lives in `claude_code.py`, because `agent_lookup.py` is the family's shared finder, held to a recorded hash by `setup/agents.py`.
- **Dev origins.** `config.window_origins()` lists `localhost` and `127.0.0.1` on 5290 and 5291 only when `FORMCRAFT_DEV=1`; otherwise only `tauri://localhost` and `http://tauri.localhost` (the engine's own origin is always admitted by the guard). `LocalGuard` takes the list or a function returning it and evaluates it per request; `main.py` passes the function. Tests that model the Vite page set `FORMCRAFT_DEV=1`.
- **Open.** Client names are still what the client reports (`clientInfo.name` or `X-Formcraft-Client`) and every client shares one bearer token, so remembered approvals and policies are per name, not per credential. New names get `ask`. Binding them to a client would need a token per client.
- Removed code: none.

## 2026-11-29 · v0.10.0 the usability round {#usable-v0100}

- **Binaries (`services/binaries.py`).** One resolver for ffmpeg and ffprobe that follows the formai-binaries record; `ffmpeg_fetch.locate()`, `encoders.selected()` and `encode_sessions.py` go through it. The old formcut-binaries address stays as the fallback, and the shared install folder keeps its name. Adapted from formcut `backend/app/tools.py` and `ffmpeg_fetch.py` and formencoder `backend/app/ffmpeg_fetch.py` (Apache-2.0).
Expand All @@ -2267,3 +2278,11 @@ From VERIFY_v0.8.0_E2E.md. A closed page's long poll could take a queued call: t
- **Starter (`services/starter.py`).** `licence_evidence` may be a string or a list; licences accepted are CC0-1.0 and the public-domain labels; packs carry `material` and `map`, `rigged` and `animations`, `source_page`.
- **Starter sourcing rule.** Files come from the publisher's own website, two licence statements read there, and never from a site or path whose robots.txt closes it to AI agents (OpenGameArt, Free Nature Stock, itch.io download links). The older scene pack in `app/pack` (KayKit pieces from GitHub, 0.6.0) is not covered by this round and is left as it was.
- Removed code: none.

## 2026-11-29 · main 0.11.0 merged into the agents hardening branch {#agents-hardening-merge}

- refers-to: app/routers/agents.py :: WINDOW, bridge_next; app/services/agents.py :: approval_key, remember, remembered, _keepable, Bridge.ask; app/services/mcp_tools.py :: projects_update; frontend src/automation/approvals.ts; frontend src/io/api-agents.ts :: BridgeApproval; tests/cb02/test_services_agents_replace_doc.py
- **Router.** `GET /api/agents/bridge/next` keeps the window key from this branch and takes main's `project` query, which calls `agents.set_window_project`. The `Decision` body keeps main's `scope` and `project`.
- **Approval keys.** Main's risk classes replace this branch's `projects_update:doc` key. A `projects_update` with `doc` is risky through `mcp_tools` (`risky=lambda a: "doc" in a`, from this branch), so `approval_key` gives it `risk:projects_update:`; `_keepable` is false for it, so `remember` never stores it, `remembered` never honours a stored copy, and no session, project or allow grant covers it. A rename or cover change stays a normal key. The approval item says so as main's `keepable: false`, which the window already reads to hide the remember box; the PR's `rememberable` field is gone from the engine, `approvals.ts` and `BridgeApproval`.
- **Test.** The two assertions in `test_services_agents_replace_doc.py` that read the approval item now read `keepable`; nothing else in it changed.
- Removed code: `REPLACE_DOC_KEY = "projects_update:doc"`, `NEVER_REMEMBERED = ("generate", REPLACE_DOC_KEY)`, `def rememberable(key: str) -> bool: return key not in NEVER_REMEMBERED`, in `approval_key` the lines `if tool == "command_run": return f"{tool}:{args.get('id')}"`, `if tool == "projects_update": return REPLACE_DOC_KEY if "doc" in args else tool` and `if callable(mcp_tools.TOOLS.get(tool, {}).get("risky")): return f"{tool}:{args.get('path') or args.get('dir') or ''}"`, and the item field `"rememberable": rememberable(key)`; in `approvals.ts`, `const offered = item.rememberable !== false && (priced || item.tool !== 'generate');`; in `api-agents.ts`, `rememberable?: boolean;`.
5 changes: 4 additions & 1 deletion backend/app/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,7 @@ def cors_origins() -> list[str]:

def window_origins() -> list[str]:
preview = FRONTEND_PORT + 1
return [*cors_origins(), f"http://localhost:{preview}", f"http://127.0.0.1:{preview}", "tauri://localhost", "http://tauri.localhost"]
desktop = ["tauri://localhost", "http://tauri.localhost"]
if not is_dev():
return desktop
return [*cors_origins(), f"http://localhost:{preview}", f"http://127.0.0.1:{preview}", *desktop]
9 changes: 7 additions & 2 deletions backend/app/core/local_guard.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,14 @@ def _loopback_client(client) -> bool:


class LocalGuard:
def __init__(self, app, origins: list[str]) -> None:
def __init__(self, app, origins) -> None:
self.app = app
self.allowed = {key for key in (_origin_key(o) for o in origins) if key is not None}
self.origins = origins

@property
def allowed(self) -> set:
origins = self.origins() if callable(self.origins) else self.origins
return {key for key in (_origin_key(o) for o in origins) if key is not None}

def _permitted(self, scope, headers: dict[str, str]) -> bool:
if not _loopback_client(scope.get("client")):
Expand Down
2 changes: 1 addition & 1 deletion backend/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ async def lifespan(_: FastAPI):
errors.install(app)
if config.is_dev():
app.add_middleware(CORSMiddleware, allow_origins=config.cors_origins(), allow_methods=["*"], allow_headers=["*"])
app.add_middleware(LocalGuard, origins=config.window_origins())
app.add_middleware(LocalGuard, origins=config.window_origins)

for _router in (system.router, settings_router.router, keys.router, jobs_router.router, events_router.router, media_router.router, costs.router, models_router.router, plan.router, generate.router, folders.router, tags.router, characters_router.router, prompts.router, projects.router, scene.router, pack_router.router, edit_router.router):
app.include_router(_router, prefix="/api")
Expand Down
22 changes: 12 additions & 10 deletions backend/app/routers/agents.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
from typing import Literal

from fastapi import APIRouter, Body, Query, Request, Response
from fastapi import APIRouter, Body, Depends, Query, Request, Response
from pydantic import BaseModel, StrictBool

from app.core import window_key
from app.core.errors import ApiError
from app.services import agents, mcp_tools

router = APIRouter()
WINDOW = [Depends(window_key.require)]


class Decision(BaseModel):
Expand All @@ -16,12 +18,12 @@ class Decision(BaseModel):
project: str | None = None


@router.post("/agents/catalogue")
@router.post("/agents/catalogue", dependencies=WINDOW)
def post_catalogue(body: dict = Body(...)):
return agents.catalogue.set(body, mcp_tools.names())


@router.get("/agents/bridge/next")
@router.get("/agents/bridge/next", dependencies=WINDOW)
async def bridge_next(request: Request, wait: float = Query(25, ge=0, le=30), project: str | None = Query(None, max_length=200)):
if project is not None:
agents.set_window_project(project)
Expand All @@ -40,14 +42,14 @@ def bridge_bye():
return Response(status_code=204)


@router.post("/agents/bridge/{item_id}/result")
@router.post("/agents/bridge/{item_id}/result", dependencies=WINDOW)
def bridge_result(item_id: str, body: dict = Body(...)):
if not agents.bridge.result(item_id, body):
raise ApiError(404, "call_not_found", "No pending call with that id.")
return {"ok": True}


@router.post("/agents/approvals/{item_id}")
@router.post("/agents/approvals/{item_id}", dependencies=WINDOW)
def approval(item_id: str, body: Decision):
if body.project is not None:
agents.set_window_project(body.project)
Expand All @@ -56,26 +58,26 @@ def approval(item_id: str, body: Decision):
return {"ok": True}


@router.get("/agents/state")
@router.get("/agents/state", dependencies=WINDOW)
def read_state():
return agents.public_state()


@router.put("/agents/state")
@router.put("/agents/state", dependencies=WINDOW)
def write_state(body: dict = Body(...)):
return agents.put_state(body)


@router.post("/agents/token/rotate")
@router.post("/agents/token/rotate", dependencies=WINDOW)
def rotate_token():
return {"tokenPath": str(agents.rotate_token())}


@router.get("/agents/activity")
@router.get("/agents/activity", dependencies=WINDOW)
def read_activity():
return {"calls": agents.activity.list(), "max": agents.ACTIVITY_MAX}


@router.post("/agents/stop")
@router.post("/agents/stop", dependencies=WINDOW)
def stop():
return {"stopped": agents.bridge.stop()}
5 changes: 3 additions & 2 deletions backend/app/routers/settings.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from fastapi import APIRouter, Body
from fastapi import APIRouter, Body, Depends

from app.core import window_key
from app.services import settings

router = APIRouter()
Expand All @@ -10,6 +11,6 @@ def read_settings():
return settings.get()


@router.put("/settings")
@router.put("/settings", dependencies=[Depends(window_key.require)])
def write_settings(body: dict = Body(...)):
return settings.update(body)
Loading
Loading