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
17 changes: 5 additions & 12 deletions .agents/skills/formencoder-harness/references/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

Generated from the formencoder engine by `./formencoder agents sync`; do not edit by hand.

96 commands in 24 namespaces. Every menu item and button in formencoder is one of these. Run one over MCP with its own tool (the `MCP` name on each line, in the full profile) or `execute {command, params}` (every profile), several as one undo step with `batch`, or from a shell as `./formencoder ID --name value` (`--help` after the id lists the flags). `describe_command ID` returns the JSON Schema. In the summaries `?` marks an optional parameter and `a|b` lists the accepted values. `refs` takes output ids, item ids, `#n` (the nth queue item), `selected` or `all`. Unknown parameters are refused with the schema in the message.
94 commands in 23 namespaces. Every menu item and button in formencoder is one of these. Run one over MCP with its own tool (the `MCP` name on each line, in the full profile) or `execute {command, params}` (every profile), several as one undo step with `batch`, or from a shell as `./formencoder ID --name value` (`--help` after the id lists the flags). `describe_command ID` returns the JSON Schema. In the summaries `?` marks an optional parameter and `a|b` lists the accepted values. `refs` takes output ids, item ids, `#n` (the nth queue item), `selected` or `all`. Unknown parameters are refused with the schema in the message.

## Contents

`queue` (26) `encode` (5) `preset` (11) `format` (3) `watch` (9) `ingest` (1) `proxy` (1) `analyze` (1) `media` (3) `captions` (4) `lut` (2) `family` (2) `publish` (1) `log` (2) `prefs` (5) `edit` (2) `history` (1) `ui` (4) `app` (2) `settings` (1) `metadata` (3) `plugin` (3) `shortcuts` (3) `tools` (1)
`queue` (26) `encode` (5) `preset` (11) `format` (3) `watch` (9) `ingest` (1) `proxy` (1) `analyze` (1) `media` (3) `captions` (4) `lut` (2) `family` (1) `log` (2) `prefs` (5) `edit` (2) `history` (1) `ui` (4) `app` (2) `settings` (1) `metadata` (3) `plugin` (3) `shortcuts` (3) `tools` (1)

## queue

Expand Down Expand Up @@ -68,8 +68,9 @@ Generated from the formencoder engine by `./formencoder agents sync`; do not edi
Joins clips, in the order given, into one source with one output; sizes and rates follow the first clip.
- `queue.select` Select · Edit · query · MCP `queue_select`
`{items?: array, outputs?: array}`
- `queue.save` Save Queue · File · Cmd+S · query · MCP `queue_save`
`{path?: string}`
- `queue.save` Save Queue · File · Cmd+S · MCP `queue_save`
`{path?: string, overwrite?: boolean}`
Saves the queue, to path when given. An existing file at path is replaced only with overwrite: true.
- `queue.open` Open Queue · File · undoable, destructive · MCP `queue_open`
`{path: string, append?: boolean}`

Expand Down Expand Up @@ -195,14 +196,6 @@ Generated from the formencoder engine by `./formencoder agents sync`; do not edi
- `family.queue` Queue Family Source · File · undoable · MCP `family_queue`
`{spec: object, preset?: string, format?: h264|hevc|av1|webm|quicktime|prores|prores_mxf|dnxhr_mxf|mxf_op1a|jpeg2000_mxf|as10|as11|..., settings?: object, folder?: string, outputs?: array, start?: boolean}`
Queues a source described by the family bridge (family.add finds it in the app and calls this).
- `family.resolved` Family Media Ready · File · query · MCP `family_resolved`
`{output: string, media?: object, error?: string}`
The service hands a waiting output the media the family app produced.

## publish

- `publish.result` Publish Result · Publish · MCP `publish_result`
`{output: string, results: array}`

## log

Expand Down
2 changes: 1 addition & 1 deletion .agents/skills/formencoder-harness/references/tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ How to encode with formencoder through these tools.

### queue

Refs: an output id (o...), an item id (i...), '#n' for the nth item (its outputs), 'selected' or 'all'. queue.addSource {paths, preset|format|settings|outputs, folder, stitch, frameRate (image sequence), start}. queue.addOutput {item, preset} adds another output to a source. queue.duplicate, queue.remove, queue.clearDone, queue.reorder {item, to}, queue.skip {refs, skip}, queue.resetStatus {refs} (encode again). queue.setRange {refs, mode: entire|inout|custom, in, out} in source seconds. queue.interpret {item, frameRate, pixelAspect, fieldOrder, alpha, rotation}. queue.stitch {paths} joins clips into one output. queue.save {path} and queue.open {path} keep a queue as .fequeue. Status values: ready, preparing, encoding, paused, done, failed, stopped, skipped.
Refs: an output id (o...), an item id (i...), '#n' for the nth item (its outputs), 'selected' or 'all'. queue.addSource {paths, preset|format|settings|outputs, folder, stitch, frameRate (image sequence), start}. queue.addOutput {item, preset} adds another output to a source. queue.duplicate, queue.remove, queue.clearDone, queue.reorder {item, to}, queue.skip {refs, skip}, queue.resetStatus {refs} (encode again). queue.setRange {refs, mode: entire|inout|custom, in, out} in source seconds. queue.interpret {item, frameRate, pixelAspect, fieldOrder, alpha, rotation}. queue.stitch {paths} joins clips into one output. queue.save {path, overwrite} and queue.open {path} keep a queue as .fequeue (an existing file is replaced only with overwrite: true). Status values: ready, preparing, encoding, paused, done, failed, stopped, skipped.

### settings

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ A source added without a preset gets the `defaultPreset` preference (Match Sourc
- `queue {action: resetStatus, refs}` returns done, failed or stopped outputs to ready, to encode again after a fix.
- `queue {action: reorder, item, to}` moves an item (1-based). `clearDone` removes finished items; `remove {refs}` removes outputs, or whole items when an item id is named.
- The `parallel` and `maxParallel` preferences decide how many outputs of one source encode at once.
- `execute queue.save {path}` writes the queue as `.fequeue`; `execute queue.open {path, append}` brings one back.
- `execute queue.save {path, overwrite}` writes the queue as `.fequeue` (an existing file is replaced only with `overwrite: true`, which asks the person); `execute queue.open {path, append}` brings one back.

## Presets

Expand Down
17 changes: 5 additions & 12 deletions .claude/skills/formencoder-harness/references/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

Generated from the formencoder engine by `./formencoder agents sync`; do not edit by hand.

96 commands in 24 namespaces. Every menu item and button in formencoder is one of these. Run one over MCP with its own tool (the `MCP` name on each line, in the full profile) or `execute {command, params}` (every profile), several as one undo step with `batch`, or from a shell as `./formencoder ID --name value` (`--help` after the id lists the flags). `describe_command ID` returns the JSON Schema. In the summaries `?` marks an optional parameter and `a|b` lists the accepted values. `refs` takes output ids, item ids, `#n` (the nth queue item), `selected` or `all`. Unknown parameters are refused with the schema in the message.
94 commands in 23 namespaces. Every menu item and button in formencoder is one of these. Run one over MCP with its own tool (the `MCP` name on each line, in the full profile) or `execute {command, params}` (every profile), several as one undo step with `batch`, or from a shell as `./formencoder ID --name value` (`--help` after the id lists the flags). `describe_command ID` returns the JSON Schema. In the summaries `?` marks an optional parameter and `a|b` lists the accepted values. `refs` takes output ids, item ids, `#n` (the nth queue item), `selected` or `all`. Unknown parameters are refused with the schema in the message.

## Contents

`queue` (26) `encode` (5) `preset` (11) `format` (3) `watch` (9) `ingest` (1) `proxy` (1) `analyze` (1) `media` (3) `captions` (4) `lut` (2) `family` (2) `publish` (1) `log` (2) `prefs` (5) `edit` (2) `history` (1) `ui` (4) `app` (2) `settings` (1) `metadata` (3) `plugin` (3) `shortcuts` (3) `tools` (1)
`queue` (26) `encode` (5) `preset` (11) `format` (3) `watch` (9) `ingest` (1) `proxy` (1) `analyze` (1) `media` (3) `captions` (4) `lut` (2) `family` (1) `log` (2) `prefs` (5) `edit` (2) `history` (1) `ui` (4) `app` (2) `settings` (1) `metadata` (3) `plugin` (3) `shortcuts` (3) `tools` (1)

## queue

Expand Down Expand Up @@ -68,8 +68,9 @@ Generated from the formencoder engine by `./formencoder agents sync`; do not edi
Joins clips, in the order given, into one source with one output; sizes and rates follow the first clip.
- `queue.select` Select · Edit · query · MCP `queue_select`
`{items?: array, outputs?: array}`
- `queue.save` Save Queue · File · Cmd+S · query · MCP `queue_save`
`{path?: string}`
- `queue.save` Save Queue · File · Cmd+S · MCP `queue_save`
`{path?: string, overwrite?: boolean}`
Saves the queue, to path when given. An existing file at path is replaced only with overwrite: true.
- `queue.open` Open Queue · File · undoable, destructive · MCP `queue_open`
`{path: string, append?: boolean}`

Expand Down Expand Up @@ -195,14 +196,6 @@ Generated from the formencoder engine by `./formencoder agents sync`; do not edi
- `family.queue` Queue Family Source · File · undoable · MCP `family_queue`
`{spec: object, preset?: string, format?: h264|hevc|av1|webm|quicktime|prores|prores_mxf|dnxhr_mxf|mxf_op1a|jpeg2000_mxf|as10|as11|..., settings?: object, folder?: string, outputs?: array, start?: boolean}`
Queues a source described by the family bridge (family.add finds it in the app and calls this).
- `family.resolved` Family Media Ready · File · query · MCP `family_resolved`
`{output: string, media?: object, error?: string}`
The service hands a waiting output the media the family app produced.

## publish

- `publish.result` Publish Result · Publish · MCP `publish_result`
`{output: string, results: array}`

## log

Expand Down
2 changes: 1 addition & 1 deletion .claude/skills/formencoder-harness/references/tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ How to encode with formencoder through these tools.

### queue

Refs: an output id (o...), an item id (i...), '#n' for the nth item (its outputs), 'selected' or 'all'. queue.addSource {paths, preset|format|settings|outputs, folder, stitch, frameRate (image sequence), start}. queue.addOutput {item, preset} adds another output to a source. queue.duplicate, queue.remove, queue.clearDone, queue.reorder {item, to}, queue.skip {refs, skip}, queue.resetStatus {refs} (encode again). queue.setRange {refs, mode: entire|inout|custom, in, out} in source seconds. queue.interpret {item, frameRate, pixelAspect, fieldOrder, alpha, rotation}. queue.stitch {paths} joins clips into one output. queue.save {path} and queue.open {path} keep a queue as .fequeue. Status values: ready, preparing, encoding, paused, done, failed, stopped, skipped.
Refs: an output id (o...), an item id (i...), '#n' for the nth item (its outputs), 'selected' or 'all'. queue.addSource {paths, preset|format|settings|outputs, folder, stitch, frameRate (image sequence), start}. queue.addOutput {item, preset} adds another output to a source. queue.duplicate, queue.remove, queue.clearDone, queue.reorder {item, to}, queue.skip {refs, skip}, queue.resetStatus {refs} (encode again). queue.setRange {refs, mode: entire|inout|custom, in, out} in source seconds. queue.interpret {item, frameRate, pixelAspect, fieldOrder, alpha, rotation}. queue.stitch {paths} joins clips into one output. queue.save {path, overwrite} and queue.open {path} keep a queue as .fequeue (an existing file is replaced only with overwrite: true). Status values: ready, preparing, encoding, paused, done, failed, stopped, skipped.

### settings

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ A source added without a preset gets the `defaultPreset` preference (Match Sourc
- `queue {action: resetStatus, refs}` returns done, failed or stopped outputs to ready, to encode again after a fix.
- `queue {action: reorder, item, to}` moves an item (1-based). `clearDone` removes finished items; `remove {refs}` removes outputs, or whole items when an item id is named.
- The `parallel` and `maxParallel` preferences decide how many outputs of one source encode at once.
- `execute queue.save {path}` writes the queue as `.fequeue`; `execute queue.open {path, append}` brings one back.
- `execute queue.save {path, overwrite}` writes the queue as `.fequeue` (an existing file is replaced only with `overwrite: true`, which asks the person); `execute queue.open {path, append}` brings one back.

## Presets

Expand Down
6 changes: 1 addition & 5 deletions agents/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,6 @@
"tools_list",
"prefs_clean_cache",
"family_queue",
"family_resolved",
"publish_result",
"edit_undo",
"edit_redo",
"history_list",
Expand Down Expand Up @@ -150,7 +148,6 @@
"queue_get_settings",
"settings_apply",
"queue_select",
"queue_save",
"encode_status",
"encode_report",
"encode_estimate",
Expand All @@ -177,7 +174,6 @@
"plugin_result",
"shortcuts_list",
"tools_list",
"family_resolved",
"history_list",
"ui_panel",
"ui_workspace",
Expand Down Expand Up @@ -222,6 +218,7 @@
"queue_stop_current",
"queue_auto_encode_watch",
"queue_stitch",
"queue_save",
"queue_open",
"preset_create",
"preset_update",
Expand Down Expand Up @@ -255,7 +252,6 @@
"shortcuts_reset",
"prefs_clean_cache",
"family_queue",
"publish_result",
"edit_undo",
"edit_redo"
],
Expand Down
95 changes: 87 additions & 8 deletions backend/app/agent/approvals.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import itertools
import json
import os
import re
import time
from collections import deque
from pathlib import Path
Expand All @@ -16,6 +17,8 @@
WAIT = 120.0
_ids = itertools.count(1)
_destructive: dict[str, str] = {}
_queries: set[str] = set()
PRESET_MAKERS = ("preset.create", "preset.update", "preset.duplicate", "preset.alias", "preset.import")
pending: dict[int, tuple[dict, Callable[[], Awaitable[Any]], asyncio.Future]] = {}
decided: deque = deque(maxlen=200)
activity: deque = deque(maxlen=300)
Expand Down Expand Up @@ -85,6 +88,8 @@ async def _load_registry() -> None:
for r in rows:
if (r.get("annotations") or {}).get("destructiveHint"):
_destructive[r["id"]] = r.get("label") or r["id"]
if r.get("query"):
_queries.add(r["id"])


def _settings_in(params: dict) -> list[dict]:
Expand All @@ -98,6 +103,56 @@ def _settings_in(params: dict) -> list[dict]:
return found


def _unread(what: str, exc: Any = None) -> str:
detail = f" ({_shown(exc)[:160]})" if exc else ""
return f"{what} could not be read{detail}, so it may publish"


async def _engine_query(command: str, params: dict) -> Any:
return json.loads(await host.call(lambda e: e.execute(command, json.dumps(params), "engine")))


async def _preset_settings(params: dict) -> tuple[list[dict], list[str]]:
"""The settings of every preset the params name. A preset that cannot be read is a reason to ask (fail closed)."""
names = [params.get("preset")] + [o.get("preset") for o in params.get("outputs") or [] if isinstance(o, dict)]
found: list[dict] = []
why: list[str] = []
for name in sorted({n for n in names if isinstance(n, str) and n}):
try:
row = await _engine_query("preset.get", {"preset": name})
except Exception as exc:
why.append(_unread(f"the preset {_shown(name)}", exc))
continue
if isinstance(row, dict) and isinstance(row.get("settings"), dict):
found.append(row["settings"])
else:
why.append(_unread(f"the preset {_shown(name)}"))
return found, why


async def _resolved_reasons(command: str, params: dict) -> list[str]:
"""Whether the preset a preset command leaves publishes, as the engine works it out (preset.resolve, run only by the engine
service): an import reads the file the way preset.import reads it, an update applies its patch, a create from an output takes
that output's settings. The engine answers with a publish summary only, never the settings or the file."""
try:
row = await _engine_query("preset.resolve", {"command": command, "params": params})
except Exception as exc:
return [_unread("the preset settings", exc)]
if not isinstance(row, dict) or not isinstance(row.get("publishes"), bool) or not isinstance(row.get("destinations"), list):
return [_unread("the preset settings")]
kinds = {str(k) for k in row["destinations"]}
out = [f"it sends the encoded file to {k}" for k in sorted(kinds & UPLOADS)]
if "folder" in kinds:
out.append("it copies the encoded file into a folder")
if row.get("deletesLocal") is not False:
out.append("it deletes the local file after publishing")
return out


def _shown(value: Any) -> str:
return re.sub(r"[\x00-\x1f\x7f]", "?", str(value))


def _publish_reasons(settings: dict) -> list[str]:
out = []
dests = settings.get("publish")
Expand All @@ -109,6 +164,8 @@ def _publish_reasons(settings: dict) -> list[str]:
kind = str(d.get("type") or "")
if kind in UPLOADS:
out.append(f"it sends the encoded file to {kind}")
if kind == "folder":
out.append(f"it copies the encoded file into {_shown(d.get('path') or 'a folder')}")
if d.get("deleteLocal"):
out.append("it deletes the local file after publishing")
return out
Expand All @@ -119,30 +176,52 @@ async def reasons(command: str, params: dict) -> list[str]:
why: list[str] = []
if command in _destructive:
why.append(f"{_destructive[command].rstrip('.')} deletes, clears or replaces something")
for s in _settings_in(params):
why += _publish_reasons(s)
if command not in _queries:
named, unread = await _preset_settings(params)
found = _settings_in(params) + named
why += unread
if command in PRESET_MAKERS:
why += await _resolved_reasons(command, params)
for s in found:
why += _publish_reasons(s)
if command == "queue.setOutput" and isinstance(params.get("path"), str) and params["path"]:
target = Path(os.path.expanduser(params["path"]))
if target.exists():
why.append(f"it would overwrite {target}")
why.append(f"it would overwrite {_shown(target)}")
if command == "queue.save" and params.get("overwrite") is True:
why.append(f"it may overwrite {_shown(params.get('path') or 'a saved queue')}")
if command in ("watch.setOutput", "watch.addOutput") and params.get("folder") not in (None, ""):
why.append("it changes where a watch folder writes its files")
if command == "watch.chain":
why.append("it changes where a watch folder's outputs go")
return sorted(set(why))


async def guard(client: str, label: str, why: list[str], params: Any, run: Callable[[], Awaitable[Any]]) -> Any:
if not why:
return await run()
if full_faith():
return await run()
def _register(client: str, label: str, why: list[str], params: Any, run: Callable[[], Awaitable[Any]]) -> tuple[dict, asyncio.Future]:
rid = next(_ids)
request = {"id": rid, "client": client, "action": label, "params": _short(params, 600), "why": why, "created": time.time(), "status": "pending",
"summary": f"{client} asks to run {label}: {'; '.join(why)}"}
fut: asyncio.Future = asyncio.get_running_loop().create_future()
pending[rid] = (request, run, fut)
_changed()
return request, fut


async def ask_later(client: str, label: str, why: list[str], params: Any, run: Callable[[], Awaitable[Any]]) -> dict:
"""For a caller that cannot wait (a webhook): run now when nothing needs asking or full faith is on, otherwise leave the
request in the Agent Connect panel, where approving it runs it, and answer at once with its id."""
if not why or full_faith():
return {"result": await run()}
request, _fut = _register(client, label, why, params, run)
return {"pendingApproval": request["id"], "why": why, "summary": request["summary"]}


async def guard(client: str, label: str, why: list[str], params: Any, run: Callable[[], Awaitable[Any]]) -> Any:
if not why:
return await run()
if full_faith():
return await run()
request, fut = _register(client, label, why, params, run)
if not host.bus.windows():
raise Pending(request)
try:
Expand Down
Loading
Loading