Skip to content

Commit fe6a6c3

Browse files
committed
feat(mcp): setEditorSettings and a settings block in getCurrentDocument
One tool writes the project's look through applySettingsPatch: background, frame, format (Original shapes included), camera layout, cursor, autoFocusAll and audioGainDb, with the pane's own side effects. Bounds come from SETTING_BOUNDS and wallpapers from parseStylePresetWallpaper. getCurrentDocument reads it back in the same shape, with the options on offer and why each hidden setting is inert. setAspectRatio becomes an alias. Part of #1180
1 parent e896d77 commit fe6a6c3

10 files changed

Lines changed: 719 additions & 13 deletions

File tree

‎electron/ai-edition/agent-tools.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ describe("the mutating-tool table", () => {
203203
"setAudio",
204204
"setCameraFullscreen",
205205
"setClipRange",
206+
"setEditorSettings",
206207
"setSpeed",
207208
"setTrim",
208209
"setWordText",

‎electron/ai-edition/agent-tools.ts‎

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ import {
4848
figureDataSchema,
4949
} from "../../src/lib/ai-edition/schema";
5050
import { getEditorSettings } from "../../src/lib/ai-edition/store/editorSettings";
51-
import { applySettingsPatch } from "../../src/lib/ai-edition/store/settingsPatch";
5251
import { hasAnyClipWithCamera } from "../../src/lib/ai-edition/timeline/camera";
5352
import { isGeneratedAssetId } from "../../src/lib/ai-edition/timeline/clip-parts";
5453
import {
@@ -79,8 +78,10 @@ import {
7978
zoomTransitions,
8079
} from "../../src/lib/ai-edition/timeline/zoom-transitions";
8180
import { SETTING_BOUNDS } from "../../src/lib/projectDefaults";
81+
import type { SegmentationSupport } from "../../src/native/contracts";
8282
import { annotationFootageRect, zoomScaleLimit } from "../../src/native/sceneDescription";
8383
import { ASPECT_RATIO_PRESETS } from "../../src/utils/aspectRatioUtils";
84+
import { editorSettingsSnapshot, executeSetEditorSettings } from "./editor-settings-tool";
8485
import { measureTextInShippedFonts } from "./text-measure";
8586

8687
export interface AgentToolExecution {
@@ -670,7 +671,11 @@ export const setClipRangeArgs = z.object({
670671
});
671672

672673
export const setAspectRatioArgs = z.object({
673-
aspectRatio: z.enum(["auto", ...ASPECT_RATIO_PRESETS]),
674+
aspectRatio: z
675+
.string()
676+
.describe(
677+
`"auto", one of ${ASPECT_RATIO_PRESETS.join(", ")}, or a token from getCurrentDocument's settingsContext.originalAspectRatios.`,
678+
),
674679
});
675680

676681
export const replaceTimelineArgs = z.object({
@@ -1027,6 +1032,7 @@ export const OPENSCREEN_TOOL_NAMES = [
10271032
"removeModifier",
10281033
"removeClip",
10291034
"setAspectRatio",
1035+
"setEditorSettings",
10301036
] as const;
10311037

10321038
/**
@@ -1100,6 +1106,7 @@ export const MUTATING_TOOL_NAMES: ReadonlySet<string> = new Set([
11001106
"removeModifier",
11011107
"removeClip",
11021108
"setAspectRatio",
1109+
"setEditorSettings",
11031110
]);
11041111

11051112
export function isMutatingTool(name: string): boolean {
@@ -1512,6 +1519,9 @@ export interface AgentToolOptions {
15121519
* Absent means the runtime has no telemetry reader wired at all, which the
15131520
* executor reports as "could not look", never as "there is none". */
15141521
cursorTelemetry?: CursorTelemetryContext;
1522+
/** Whether this machine can cut out the camera background, asked only by the two tools that
1523+
* report it. Absent where nothing can ask the compositor: reported as not checked. */
1524+
cameraSegmentation?: () => SegmentationSupport;
15151525
}
15161526

15171527
/**
@@ -1724,28 +1734,33 @@ export function executeAgentTool(
17241734

17251735
switch (name) {
17261736
case "setAspectRatio": {
1737+
// The format alone, kept for clients that know it: setEditorSettings does the work.
17271738
const parsed = setAspectRatioArgs.safeParse(args);
17281739
if (!parsed.success) return failure(parsed.error.message);
17291740
const previous = getEditorSettings(document).aspectRatio;
1730-
// The editor's own write: the frame-placed annotations keep their centre, and a text is
1731-
// refitted to its words in the new frame, measured in the shipped fonts.
1732-
const next = applySettingsPatch(
1741+
const execution = executeSetEditorSettings(
17331742
document,
17341743
{ aspectRatio: parsed.data.aspectRatio },
1735-
measureTextInShippedFonts,
1744+
options?.cameraSegmentation?.() ?? null,
17361745
);
1746+
if (!execution.ok) return execution;
17371747
return {
1738-
ok: true,
1739-
document: next,
1748+
...execution,
17401749
resultJson: JSON.stringify({ aspectRatio: parsed.data.aspectRatio, previous }),
17411750
summary: `set the format to ${parsed.data.aspectRatio}`,
17421751
};
17431752
}
17441753

1754+
case "setEditorSettings":
1755+
return executeSetEditorSettings(document, args, options?.cameraSegmentation?.() ?? null);
1756+
17451757
case "getCurrentDocument": {
17461758
return {
17471759
ok: true,
1748-
resultJson: JSON.stringify(documentSnapshotForModel(document, options?.cursorTelemetry)),
1760+
resultJson: JSON.stringify({
1761+
...documentSnapshotForModel(document, options?.cursorTelemetry),
1762+
...editorSettingsSnapshot(document, options?.cameraSegmentation?.() ?? null),
1763+
}),
17491764
};
17501765
}
17511766

‎electron/ai-edition/chat-service.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import type {
2020
AiEditionChatMessage,
2121
AiEditionChatResult,
2222
AiEditionToolCallSummary,
23+
SegmentationSupport,
2324
} from "../../src/native/contracts";
2425
import {
2526
applyCompaction,
@@ -319,6 +320,8 @@ export interface ChatRunEnv {
319320
/** Reads recorded cursor telemetry for an asset. Built in `electron/ipc/
320321
* handlers.ts`, where the path allow-list lives. */
321322
cursor?: CursorTelemetryReader;
323+
/** Whether this machine can cut out the camera background, asked of the compositor. */
324+
cameraSegmentation?: () => SegmentationSupport;
322325
/** Runtime-only model retry override used by bounded measurement harnesses. */
323326
maxRetries?: number;
324327
}
@@ -464,6 +467,7 @@ export async function runChat(
464467
sink: agentSink,
465468
editsAllowed,
466469
cursor: env.cursor,
470+
cameraSegmentation: env.cameraSegmentation,
467471
});
468472

469473
// The project was deleted while the agent ran: its sessions are gone, so a

‎electron/ai-edition/deep-agent/service.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ const ARGS: Record<string, unknown> = {
8585
removeModifier: { id: "nope" },
8686
removeClip: { clipId: "clip_1" },
8787
setAspectRatio: { aspectRatio: "16:9" },
88+
setEditorSettings: { padding: 30 },
8889
};
8990

9091
/** ponytail: the fixture starts from a FIXED instant. `createEmptyDocument` reads

‎electron/ai-edition/deep-agent/service.ts‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
ZOOM_DEPTH_LEGEND,
3232
} from "../../../src/lib/ai-edition/timeline/zoom-scale";
3333
import { ZOOM_TRANSITION_LEGEND } from "../../../src/lib/ai-edition/timeline/zoom-transitions";
34+
import type { SegmentationSupport } from "../../../src/native/contracts";
3435
import {
3536
AGENT_EDITS_SETTING,
3637
type AgentToolExecution,
@@ -65,6 +66,7 @@ import {
6566
setWordTextArgs,
6667
setZoomArgs,
6768
} from "../agent-tools";
69+
import { setEditorSettingsArgs } from "../editor-settings-tool";
6870
import {
6971
createOpenScreenChatModel,
7072
messageContentToText,
@@ -132,7 +134,7 @@ const BASE_SYSTEM_PROMPT = [
132134
"- Cutting specific spoken words (fillers, a repeated or flubbed phrase, a false start, a duplicate take) is removeWords: read getTranscriptWords, choose the occurrences from their surrounding speech, then pass that assetId and ONLY those word IDs. Word IDs restart for each asset, so keep the read's assetId. Consecutive words become one cut. Do not cut every occurrence of a word just because its text matches one you were asked to remove.",
133135
"- Changing where a clip starts or ends within its source is setClipRange — the clip's in/out, distinct from a trim.",
134136
`- addZoom takes a virtual-timeline span (depth is an ordinal 1–6 selecting from a fixed table — ${ZOOM_DEPTH_LEGEND} — never a multiplier; focus in 0–1 frame fractions). addSpeed changes pacing over a span. addAnnotation puts text, an arrow or a privacy blur on screen: a blur is how an email address, a token or any private detail the recording shows is hidden. addCameraFullscreen enlarges the webcam, and only does something where assets[].hasCameraTrack is true.`,
135-
"- setAspectRatio picks the shape of the whole video, for where it will be shown; auto follows the recording.",
137+
"- setEditorSettings sets the look of the whole video: the background (wallpaper, its motion and blur), padding, rounded corners, shadow, a device frame, motion blur, depth of field, the shape of the video (aspectRatio: auto follows the recording) and how a recording of another shape fills it, the camera's layout (picture-in-picture, side by side, stacked, its shape, size, position, framing and background cutout), the cursor, and the master volume. getCurrentDocument returns all of them under settings, in the shape this tool takes, and settingsContext.inactive names each one the editor hides in the current state and why: setting one of those changes nothing, so say so instead of reporting the look as changed. setAspectRatio is the same write for the shape alone.",
136138
"- A zoom animates in just before its span and out just after it (zoomInFromSec, zoomOutUntilSec in getCurrentDocument). Leave those windows untrimmed, or the export jumps at the cut.",
137139
"- addAudio lays an imported voiceover or music file over a span. It plays an asset the project already has (kind 'audio'); importing or recording one is the editor's job, not a tool you have — so when the project has none, say so rather than naming an id that does not exist.",
138140
"- moveClip changes the order of placed clips, one call per clip that moves, preserving ids, source ranges, trims and anchored effects. replaceTimeline rebuilds the timeline from kept intervals and sorts them, so it cannot reorder anything.",
@@ -181,7 +183,7 @@ const CUT_TRANSITIONS_RESULT = `When the result cuts a zoom's move in or out, it
181183

182184
export const TOOL_DESCRIPTIONS: Record<string, string> = {
183185
getCurrentDocument:
184-
"Read a compact snapshot of the current project: assets (with durations), timeline clips and trim ranges (source-time), and the zoom / speed / annotation / camera-fullscreen / audio regions (virtual, edited-timeline time), each with the settings its writes take: a zoom's level, focus mode and hidden cursor, an annotation's type, box, look and arrow or blur data, an audio track's level and fades. Call this before editing if the snapshot in the system prompt may be stale. The AxcutDocument is the single source of truth — your edits should preserve the user's placed clips and any timeline state they have already set up.",
186+
"Read a compact snapshot of the current project: assets (with durations), timeline clips and trim ranges (source-time), and the zoom / speed / annotation / camera-fullscreen / audio regions (virtual, edited-timeline time), each with the settings its writes take: a zoom's level, focus mode and hidden cursor, an annotation's type, box, look and arrow or blur data, an audio track's level and fades. It also gives the project's look under `settings`, in the shape setEditorSettings takes, with `settingsContext`: the formats, wallpapers and cursor themes on offer, and under `inactive` each setting the editor hides in the current state and why. Call this before editing if the snapshot in the system prompt may be stale. The AxcutDocument is the single source of truth — your edits should preserve the user's placed clips and any timeline state they have already set up.",
185187
getTranscript:
186188
"Read the transcript segments (speech and silence, with start/end seconds and text) for an asset. Omit assetId to read the primary asset's transcript.",
187189
getCursorTrack:
@@ -214,7 +216,9 @@ export const TOOL_DESCRIPTIONS: Record<string, string> = {
214216
setAnnotation:
215217
"Change an existing annotation by id: its span (virtual-timeline seconds), its type, its centre (x/y, percent of its box), its size (width/height, arrow and blur only), its text and look (text only: fontSize, color, background, bold, animation), or its figureData / blurData, of which only the keys you pass change. Only the fields you pass are changed. A type change converts it as the editor's type switch does: it stays where it is on screen, a text turned into an arrow or a blur takes the default box, and the text is kept to come back to. A text box is refitted to its text around its centre. Arguments that belong to another kind (width on a text, blurData on an arrow) are refused. A new span that would run into another annotation is refused, naming it.",
216218
setAspectRatio:
217-
"Set the shape of the exported video: 16:9 for X, YouTube or a slide, 9:16 for a vertical story or short, 1:1 or 4:5 for a square feed, auto to follow the recording. Annotations on the frame keep their place and shape.",
219+
"Set the shape of the exported video: 16:9 for X, YouTube or a slide, 9:16 for a vertical story or short, 1:1 or 4:5 for a square feed, auto to follow the recording, or one of the clips' own shapes (getCurrentDocument's settingsContext.originalAspectRatios). Annotations on the frame keep their place and shape. The same as setEditorSettings with aspectRatio alone.",
220+
setEditorSettings:
221+
'Change the project\'s look: pass only the settings to change, named as getCurrentDocument returns them under `settings`. Background: wallpaper (a bundled path from settingsContext.bundledWallpapers, a CSS colour or gradient, or a base64 PNG/JPEG data URL; never a file path or web URL; an embedded image reads back as a marker, leave the key out to keep it), wallpaperMotion (moves a gradient or image only), backgroundBlur 0–1. Frame: aspectRatio ("auto", a preset, or an originalAspectRatios token; a fixed format picked for the first time fills the frame with a window that follows the cursor, which formatFollowCursor turns off when settingsContext.formatFill is "available"), padding 0–100 %, borderRadius 0–64 px, shadowIntensity 0–1, frame (none, window, laptop, phone, monitor) and frameTheme (light, dark), motionBlurAmount 0–1, depthOfField (blurs 3D-tilted zooms only). Camera: webcamLayoutPreset, webcamMirrored, webcamReactiveZoom (shrinks on zoom), webcamMaskShape (square or rectangle, the camera\'s own proportions; an untouched roundness follows it), webcamRoundness 0–1, webcamSizePreset 15–60, webcamAnchor (a corner or an edge middle), webcamCropRegion (the framing: a square share of the picture, width = height ≥ 1/3) and webcamCropPan (where that window sits, 0–1 per axis, 0.5 centred), webcamBackgroundMode (none, transparent, blur, custom: needs settingsContext.cameraSegmentation ready), webcamBlurIntensity 0–1, webcamWallpaper (as wallpaper). Cursor, under `cursor`: show, autoHide, theme (settingsContext.cursorThemes), asArrow (the recorded cursor kinds drawn as the arrow instead), size 1.5–6, smoothing 0–1, motionBlur 0–1, clickBounce 0–2, clickImpact, clickSound (only heard when the take recorded clicks) and clickSoundGainDb −24–0, model3d. Also autoFocusAll (every zoom follows the cursor) and audioGainDb −12–12 dB, the master volume. A value out of range or a key not listed is refused with the reason, and nothing changes. The result lists what was applied, including what the editor changes with it, and `inactive` for any of those the current state leaves without effect.',
218222
addCameraFullscreen:
219223
"Add a camera-fullscreen region over a span of the edited timeline (virtual seconds): the webcam fills the frame for that span. This only does something when the footage under that span comes from an asset with a linked webcam — check assets[].hasCameraTrack (or hasAnyCamera) in getCurrentDocument first. On footage with no camera the call is refused rather than storing a region that would render nothing; say so instead of retrying.",
220224
setCameraFullscreen:
@@ -259,6 +263,8 @@ export interface CursorTelemetryReader {
259263
export interface ToolRuntime {
260264
cursor?: CursorTelemetryReader;
261265
availableByAssetId?: Record<string, boolean>;
266+
/** Asks the compositor whether this machine can cut out the camera background. */
267+
cameraSegmentation?: () => SegmentationSupport;
262268
}
263269

264270
/**
@@ -339,6 +345,7 @@ export async function runDocumentTool(
339345
return executeAgentTool(document, name, JSON.stringify(args ?? {}), {
340346
editsAllowed,
341347
cursorTelemetry: { availableByAssetId: runtime.availableByAssetId, load },
348+
cameraSegmentation: runtime.cameraSegmentation,
342349
});
343350
}
344351

@@ -423,6 +430,7 @@ export const TOOL_ARG_SCHEMAS: ReadonlyArray<readonly [string, z.ZodObject]> = [
423430
["removeModifier", removeModifierArgs],
424431
["removeClip", removeClipArgs],
425432
["setAspectRatio", setAspectRatioArgs],
433+
["setEditorSettings", setEditorSettingsArgs],
426434
];
427435

428436
/**
@@ -460,6 +468,8 @@ export interface InvokeArgs {
460468
/** Injected by `chat-service` from the Electron layer. Absent in tests and in
461469
* the workbench unless one is supplied on purpose. */
462470
cursor?: CursorTelemetryReader;
471+
/** Injected the same way: whether this machine can cut out the camera background. */
472+
cameraSegmentation?: () => SegmentationSupport;
463473
}
464474

465475
/** One cheap probe per asset, run before the tools are built so the very first
@@ -534,6 +544,7 @@ export async function invokeOpenScreenAgent(args: InvokeArgs): Promise<InvokeRes
534544
const tools = buildTools(holder, sink, editsAllowed, {
535545
cursor: args.cursor,
536546
availableByAssetId,
547+
cameraSegmentation: args.cameraSegmentation,
537548
});
538549
const agent = createAgent({
539550
model: chatModel,

0 commit comments

Comments
 (0)