@derushly/mcp 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/NOTICE +15 -0
- package/README.md +17 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/main.d.ts +2 -0
- package/dist/main.js +47 -0
- package/dist/outputs.d.ts +6 -0
- package/dist/outputs.js +56 -0
- package/dist/server.d.ts +44 -0
- package/dist/server.js +821 -0
- package/package.json +48 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
Derushly
|
|
2
|
+
Copyright 2026 Auxilh
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (see LICENSE).
|
|
5
|
+
|
|
6
|
+
packages/core/docker/Dockerfile derives from the Dockerfile of HyperFrames
|
|
7
|
+
(https://github.com/heygen-com/hyperframes, Apache-2.0, Copyright 2026 HeyGen, Inc.).
|
|
8
|
+
|
|
9
|
+
The plugin bundle (plugin/server/) and the editor page include third-party
|
|
10
|
+
software; their licenses are in server/THIRD_PARTY_NOTICES.md (plugin) and
|
|
11
|
+
ui-dist/THIRD_PARTY_NOTICES.md (@derushly/editor).
|
|
12
|
+
|
|
13
|
+
The render image is built on the user's machine from the Dockerfile: it
|
|
14
|
+
downloads Debian packages, Chromium and an FFmpeg build under their own
|
|
15
|
+
licenses (FFmpeg: GPL). Derushly does not distribute them.
|
package/README.md
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @derushly/mcp
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Le serveur MCP de Derushly (`derushly-mcp`, stdio) : il donne à un agent (Claude Code, Codex, tout client MCP) les outils pour créer, modifier, contrôler et rendre une vidéo [HyperFrames](https://hyperframes.heygen.com).
|
|
4
|
+
|
|
5
|
+
Le plus simple est d'installer le plugin, qui apporte ce serveur et un skill :
|
|
6
|
+
|
|
7
|
+
```text
|
|
8
|
+
/plugin marketplace add Auxilh/derushly
|
|
9
|
+
/plugin install derushly@derushly
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Sans plugin :
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
claude mcp add derushly -- npx -y -p @derushly/mcp derushly-mcp --root ~/videos
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Le serveur ne touche qu'aux dossiers autorisés (`--root`), et demande l'accord de l'utilisateur avant un rendu final ou une suppression. Outils, confirmations et options : [docs/MCP.md](https://github.com/Auxilh/derushly/blob/main/docs/MCP.md). Présentation : [Derushly](https://github.com/Auxilh/derushly#readme). Licence Apache 2.0.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createServer, VERSION, type ServerOptions, type Engine } from "./server.js";
|
package/dist/index.js
ADDED
package/dist/main.d.ts
ADDED
package/dist/main.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// derushly-mcp: the Derushly MCP server on stdio (no port: only the agent that started it can call it).
|
|
3
|
+
// derushly-mcp [--root <folder>]... [--docker | --local] [--confirm dialog|conversation] [--no-browser]
|
|
4
|
+
// Folders: --root, else DERUSHLY_ROOTS (separated by the path delimiter), else the client's roots,
|
|
5
|
+
// else the folder the server starts in.
|
|
6
|
+
import { delimiter } from "node:path";
|
|
7
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
8
|
+
import { createServer } from "./server.js";
|
|
9
|
+
const argv = process.argv.slice(2);
|
|
10
|
+
const roots = [];
|
|
11
|
+
let mode;
|
|
12
|
+
let openBrowser = process.env.DERUSHLY_NO_BROWSER !== "1";
|
|
13
|
+
let confirm = process.env.DERUSHLY_CONFIRM || "dialog";
|
|
14
|
+
for (let i = 0; i < argv.length; i++) {
|
|
15
|
+
if (argv[i] === "--root" && argv[i + 1])
|
|
16
|
+
roots.push(argv[++i]);
|
|
17
|
+
else if (argv[i] === "--docker")
|
|
18
|
+
mode = "docker";
|
|
19
|
+
else if (argv[i] === "--local")
|
|
20
|
+
mode = "local";
|
|
21
|
+
else if (argv[i] === "--no-browser")
|
|
22
|
+
openBrowser = false;
|
|
23
|
+
else if (argv[i] === "--confirm" && argv[i + 1])
|
|
24
|
+
confirm = argv[++i];
|
|
25
|
+
else if (argv[i] === "--version") {
|
|
26
|
+
console.log("derushly-mcp 0.1.0");
|
|
27
|
+
process.exit(0);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (!roots.length && process.env.DERUSHLY_ROOTS)
|
|
31
|
+
roots.push(...process.env.DERUSHLY_ROOTS.split(delimiter).filter(Boolean));
|
|
32
|
+
// The engine reads these too (runner.ts sets them for each run); set here for anything else.
|
|
33
|
+
process.env.HYPERFRAMES_NO_TELEMETRY = "1";
|
|
34
|
+
process.env.DO_NOT_TRACK = "1";
|
|
35
|
+
if (confirm !== "dialog" && confirm !== "conversation") {
|
|
36
|
+
console.error(`derushly-mcp: --confirm / DERUSHLY_CONFIRM is "dialog" or "conversation", not "${confirm}"`);
|
|
37
|
+
process.exit(2);
|
|
38
|
+
}
|
|
39
|
+
const server = createServer({ roots, confirm, openBrowser, ...(mode ? { mode } : {}) });
|
|
40
|
+
await server.connect(new StdioServerTransport());
|
|
41
|
+
// The client closes stdin to stop the server (Claude Code waits 300 ms on Windows): exit cleanly.
|
|
42
|
+
const stop = () => {
|
|
43
|
+
void server.close().finally(() => process.exit(0));
|
|
44
|
+
};
|
|
45
|
+
process.stdin.on("end", stop);
|
|
46
|
+
process.stdin.on("close", stop);
|
|
47
|
+
//# sourceMappingURL=main.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const OUTPUTS: Record<string, z.ZodRawShape>;
|
|
3
|
+
/** The output schema of a tool; snapshot and export_frames answer with images and have none. */
|
|
4
|
+
export declare const outputSchema: (name: string) => z.ZodObject<{
|
|
5
|
+
ok: z.ZodBoolean;
|
|
6
|
+
}, z.core.$loose> | undefined;
|
package/dist/outputs.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// What each tool answers, published as its output schema. Every successful answer is a JSON object
|
|
2
|
+
// with `ok`; the main fields are listed here and others may come with them. Errors (isError) are
|
|
3
|
+
// { ok: false, code, error, errors?, drift? }.
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
const n = (d) => (d ? z.number().describe(d) : z.number()).optional();
|
|
6
|
+
const s = (d) => (d ? z.string().describe(d) : z.string()).optional();
|
|
7
|
+
const list = (d) => z.array(z.unknown()).optional().describe(d);
|
|
8
|
+
const any = (d) => z.unknown().optional().describe(d);
|
|
9
|
+
const version = { version: n("Project version after the change (history_undo goes back one)") };
|
|
10
|
+
const job = {
|
|
11
|
+
state: s("running, done, failed or none"),
|
|
12
|
+
progress: n("Percent, while running"),
|
|
13
|
+
output: s("Rendered file, relative to the project"),
|
|
14
|
+
path: s("Rendered file, absolute"),
|
|
15
|
+
url: s("file:// link of the rendered file"),
|
|
16
|
+
mismatches: list("Differences between the file and the project (size, duration, audio)"),
|
|
17
|
+
file: any("Size, duration, resolution and audio of the file"),
|
|
18
|
+
status: any("State of a render still running or ended"),
|
|
19
|
+
next: s("What to do next"),
|
|
20
|
+
};
|
|
21
|
+
export const OUTPUTS = {
|
|
22
|
+
project_create: { project: s("Project folder"), scenes: list("Scenes"), variables: any("Editable texts, or their number") },
|
|
23
|
+
project_get: { ...version, composition: any("Size, duration, frame rate"), scenes: list("Scenes and clips"), audio: list("Audio clips"), variables: list("Editable texts by scene"), formats: list("Main format and variants"), brands: any("Brand kits"), openNotes: list("Open correction notes"), render: any("Last render, or null") },
|
|
24
|
+
project_sync: { ...version, changes: list("Edits taken into the project") },
|
|
25
|
+
history_undo: { ...version },
|
|
26
|
+
history_redo: { ...version },
|
|
27
|
+
project_archive: { ...version, output: s("Archive, relative to the project"), bytes: n(), files: n() },
|
|
28
|
+
media_list: { files: list("Media files with type, size, duration, errors and warnings"), remote: list("Files loaded from the internet"), errors: n() },
|
|
29
|
+
media_analyze: { path: s(), bytes: n(), type: s("Type read from the bytes"), probe: any("Duration, resolution, frame rate, audio") },
|
|
30
|
+
media_import: { ...version, imported: list("Files copied into the project") },
|
|
31
|
+
library_list: { components: list("Built-in components"), templates: list("Templates"), transitions: any("Transitions"), motions: any("Clip motions") },
|
|
32
|
+
template_save: { template: any("The saved template") },
|
|
33
|
+
variables_set: { ...version, built: any("Files regenerated") },
|
|
34
|
+
scene_create: { ...version },
|
|
35
|
+
scene_update: { ...version },
|
|
36
|
+
clip_edit: { ...version, parts: list("split: the two parts") },
|
|
37
|
+
scene_delete: { ...version },
|
|
38
|
+
timeline_update: { ...version, changes: list("What changed, in order") },
|
|
39
|
+
brand_update: { ...version, removed: any("Removed kit") },
|
|
40
|
+
adapters_list: { adapters: list("Adapters and whether they are ready here") },
|
|
41
|
+
voice_generate: { ...version, path: s("Audio file, relative to the project"), duration: n(), adapter: s(), license: s("Licence of the audio") },
|
|
42
|
+
captions_transcribe: { ...version, adapter: s(), added: list("New captions"), removed: list("Ids of replaced captions") },
|
|
43
|
+
notes_list: { notes: list("Correction notes with time range, region and covered items") },
|
|
44
|
+
note_add: { ...version, note: any("The note") },
|
|
45
|
+
note_resolve: { ...version, note: any("The note") },
|
|
46
|
+
check: { format: s(), errors: n(), warnings: n(), runner: s("docker or local"), findings: list("Problems: severity, code, message, fix"), blocked: list("Network accesses refused") },
|
|
47
|
+
preview_generate: job,
|
|
48
|
+
render_start: job,
|
|
49
|
+
render_status: job,
|
|
50
|
+
export_get: { exports: list("Renders, newest first") },
|
|
51
|
+
editor_open: { url: s("One-time link to give to the user"), note: s() },
|
|
52
|
+
doctor: { engine: s("Engine version"), runners: list("Runners ready: docker, local"), checks: list("Each requirement: ok, detail, fix"), fixed: list("What was installed") },
|
|
53
|
+
};
|
|
54
|
+
/** The output schema of a tool; snapshot and export_frames answer with images and have none. */
|
|
55
|
+
export const outputSchema = (name) => (OUTPUTS[name] ? z.looseObject({ ok: z.boolean(), ...OUTPUTS[name] }) : undefined);
|
|
56
|
+
//# sourceMappingURL=outputs.js.map
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import * as core from "@derushly/core";
|
|
2
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
+
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
|
|
4
|
+
export declare const VERSION = "0.1.0";
|
|
5
|
+
export interface ServerOptions {
|
|
6
|
+
/**
|
|
7
|
+
* Folders the tools may read and write. Empty: the client's roots (MCP roots), else the
|
|
8
|
+
* folder the server was started in.
|
|
9
|
+
*/
|
|
10
|
+
roots?: string[];
|
|
11
|
+
/** Seconds render_start and preview_generate wait before answering "still running". */
|
|
12
|
+
waitSeconds?: number;
|
|
13
|
+
/** Runner for check, snapshot and renders (default: Docker if ready, else local). */
|
|
14
|
+
mode?: core.RunnerMode;
|
|
15
|
+
/**
|
|
16
|
+
* How costly or destructive tools get the user's agreement. "dialog" (default): the client's
|
|
17
|
+
* confirmation dialog when it has one, else `confirmed: true` after asking in the conversation.
|
|
18
|
+
* "conversation": always `confirmed: true`, for runs where no one can answer a dialog
|
|
19
|
+
* (`codex exec`, CI), which decline every dialog.
|
|
20
|
+
*/
|
|
21
|
+
confirm?: "dialog" | "conversation";
|
|
22
|
+
/** What to tell the user when the client declined a dialog without showing it (default: start the server with --confirm conversation). */
|
|
23
|
+
declinedHint?: string;
|
|
24
|
+
/** editor_open also opens the link in the default browser (default true). */
|
|
25
|
+
openBrowser?: boolean;
|
|
26
|
+
/** Runs check, snapshot and renders somewhere else (the hosted version's workers). Default: here. */
|
|
27
|
+
engine?: Engine;
|
|
28
|
+
/** Link given for a rendered file (default: file://). */
|
|
29
|
+
fileUrl?: (path: string) => string;
|
|
30
|
+
/** Tools not offered (the hosted version has no local editor and no machine to check). */
|
|
31
|
+
disable?: string[];
|
|
32
|
+
/**
|
|
33
|
+
* Runs around every tool call (the hosted version checks quotas, sets who acts, stores the
|
|
34
|
+
* change afterwards). An error it throws is the tool's answer.
|
|
35
|
+
*/
|
|
36
|
+
around?: (tool: string, readOnly: boolean, run: () => Promise<CallToolResult>) => Promise<CallToolResult>;
|
|
37
|
+
}
|
|
38
|
+
/** Where the engine runs: by default the core functions, on this machine. */
|
|
39
|
+
export interface Engine {
|
|
40
|
+
check: typeof core.check;
|
|
41
|
+
snapshot: typeof core.snapshot;
|
|
42
|
+
render: typeof core.render;
|
|
43
|
+
}
|
|
44
|
+
export declare function createServer(opts?: ServerOptions): McpServer;
|
package/dist/server.js
ADDED
|
@@ -0,0 +1,821 @@
|
|
|
1
|
+
// Derushly MCP server: the operations of @derushly/core as MCP tools, for coding agents.
|
|
2
|
+
// Rules (spec of the tool): stdio only; tools never reach outside the allowed folders; costly or
|
|
3
|
+
// destructive tools need a human confirmation; every change is journaled with the client's name.
|
|
4
|
+
import { spawn, spawnSync } from "node:child_process";
|
|
5
|
+
import { existsSync, readdirSync, readFileSync, realpathSync, statSync } from "node:fs";
|
|
6
|
+
import { dirname, isAbsolute, join, relative, resolve } from "node:path";
|
|
7
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
8
|
+
import * as core from "@derushly/core";
|
|
9
|
+
import { DerushlyError } from "@derushly/core";
|
|
10
|
+
import { startEditor } from "@derushly/editor";
|
|
11
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
12
|
+
import { z } from "zod";
|
|
13
|
+
import { outputSchema } from "./outputs.js";
|
|
14
|
+
export const VERSION = "0.1.0";
|
|
15
|
+
/** Opens an address in the default browser; the link is in the answer anyway. */
|
|
16
|
+
function openInBrowser(url) {
|
|
17
|
+
const [cmd, args] = process.platform === "win32" ? ["cmd", ["/c", "start", '""', url.replaceAll("&", "^&")]]
|
|
18
|
+
: process.platform === "darwin" ? ["open", [url]] : ["xdg-open", [url]];
|
|
19
|
+
try {
|
|
20
|
+
const child = spawn(cmd, args, { detached: true, stdio: "ignore", windowsHide: true });
|
|
21
|
+
child.on("error", () => { });
|
|
22
|
+
child.unref();
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
// no browser here
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/** The answer as text, and as structured content matching the tool's output schema. */
|
|
29
|
+
const ok = (value) => {
|
|
30
|
+
const body = { ok: true, ...JSON.parse(JSON.stringify(value)) };
|
|
31
|
+
return { content: [{ type: "text", text: JSON.stringify(body, null, 1) }], structuredContent: body };
|
|
32
|
+
};
|
|
33
|
+
function errorBody(e) {
|
|
34
|
+
const err = e instanceof DerushlyError ? e : null;
|
|
35
|
+
const body = { ok: false, code: err?.code ?? "internal", error: e.message };
|
|
36
|
+
if (err?.errors)
|
|
37
|
+
body.errors = err.errors;
|
|
38
|
+
if (err?.drift)
|
|
39
|
+
body.drift = err.drift;
|
|
40
|
+
return body;
|
|
41
|
+
}
|
|
42
|
+
const fail = (e) => ({ isError: true, content: [{ type: "text", text: JSON.stringify(errorBody(e), null, 1) }] });
|
|
43
|
+
// Limits on what an agent may send (spec: size limits).
|
|
44
|
+
const text = (max = 2000) => z.string().max(max);
|
|
45
|
+
const seconds = z.number().min(0).max(24 * 3600);
|
|
46
|
+
const formatArg = { format: z.string().max(40).optional().describe("Format: a variant id from project_get formats (1x1, 16x9...); default: the main format") };
|
|
47
|
+
const projectArg = { project: text(1000).describe("Project folder (absolute, or relative to the workspace root)") };
|
|
48
|
+
const transition = z.object({
|
|
49
|
+
type: z.enum(core.TRANSITION_TYPES),
|
|
50
|
+
duration: z.number().min(0.05).max(10).optional().describe("Seconds (default 0.4)"),
|
|
51
|
+
});
|
|
52
|
+
const mediaClip = z.object({
|
|
53
|
+
src: text(1000).describe("Video or image of the project (assets/...); media_import brings files in"),
|
|
54
|
+
mediaStart: seconds.optional().describe("Video: where in the file the clip starts"),
|
|
55
|
+
fit: z.enum(["cover", "contain"]).optional(),
|
|
56
|
+
volume: z.number().min(0).max(4).optional().describe("Video: plays its sound at this gain (default silent)"),
|
|
57
|
+
muted: z.boolean().optional(),
|
|
58
|
+
motion: z.enum(["zoom-in", "zoom-out"]).optional().describe("Slow zoom over the clip"),
|
|
59
|
+
});
|
|
60
|
+
const mediaPatch = z.object({
|
|
61
|
+
src: text(1000).optional(), mediaStart: seconds.nullable().optional(), fit: z.enum(["cover", "contain"]).nullable().optional(),
|
|
62
|
+
volume: z.number().min(0).max(4).nullable().optional(), muted: z.boolean().nullable().optional(), motion: z.enum(["zoom-in", "zoom-out"]).nullable().optional(),
|
|
63
|
+
});
|
|
64
|
+
const transform = z.object({
|
|
65
|
+
x: z.number().min(-200).max(200).nullable().optional().describe("Centre moved right, % of the frame's width"),
|
|
66
|
+
y: z.number().min(-200).max(200).nullable().optional().describe("Centre moved down, % of the frame's height"),
|
|
67
|
+
scale: z.number().min(0.05).max(10).nullable().optional().describe("1 = full frame; 0.35 makes a picture-in-picture"),
|
|
68
|
+
rotation: z.number().min(-360).max(360).nullable().optional().describe("Degrees, clockwise"),
|
|
69
|
+
opacity: z.number().min(0).max(1).nullable().optional(),
|
|
70
|
+
});
|
|
71
|
+
const name40 = z.string().regex(/^[a-z][a-z0-9-]{0,31}$/);
|
|
72
|
+
/** The object without its undefined fields (null stays: it removes). */
|
|
73
|
+
const clean = (o) => Object.fromEntries(Object.entries(o).filter(([, v]) => v !== undefined));
|
|
74
|
+
export function createServer(opts = {}) {
|
|
75
|
+
const server = new McpServer({ name: "derushly", version: VERSION }, {
|
|
76
|
+
instructions: "Derushly edits HyperFrames videos through a project folder. Read the derushly skill first. " +
|
|
77
|
+
"Usual order: project_create (a template with media files, or an import) or project_get, then brand_update, " +
|
|
78
|
+
"scene_create / variables_set / scene_update / timeline_update, voice_generate and captions_transcribe, " +
|
|
79
|
+
"check, snapshot to look, then render_start (asks the user) and render_status until done, export_get, export_frames to look at the rendered file.",
|
|
80
|
+
});
|
|
81
|
+
const waitMs = (opts.waitSeconds ?? 40) * 1000;
|
|
82
|
+
const engine = opts.engine ?? { check: core.check, snapshot: core.snapshot, render: core.render };
|
|
83
|
+
const fileUrl = opts.fileUrl ?? ((p) => pathToFileURL(p).href);
|
|
84
|
+
const disabled = new Set(opts.disable ?? []);
|
|
85
|
+
let busy = null;
|
|
86
|
+
let waiting = 0;
|
|
87
|
+
let queue = Promise.resolve();
|
|
88
|
+
const jobs = new Map();
|
|
89
|
+
server.server.oninitialized = () => {
|
|
90
|
+
const client = server.server.getClientVersion()?.name ?? "client";
|
|
91
|
+
core.setActor(`mcp:${client}`);
|
|
92
|
+
};
|
|
93
|
+
// ---- folders -------------------------------------------------------------------------------
|
|
94
|
+
async function roots() {
|
|
95
|
+
if (opts.roots?.length)
|
|
96
|
+
return opts.roots.map((r) => resolve(r));
|
|
97
|
+
if (server.server.getClientCapabilities()?.roots) {
|
|
98
|
+
try {
|
|
99
|
+
const r = await server.server.listRoots();
|
|
100
|
+
const dirs = r.roots.filter((x) => x.uri.startsWith("file:")).map((x) => fileURLToPath(x.uri));
|
|
101
|
+
if (dirs.length)
|
|
102
|
+
return dirs;
|
|
103
|
+
}
|
|
104
|
+
catch {
|
|
105
|
+
// client said it has roots but did not answer: fall back to the start folder
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return [process.cwd()];
|
|
109
|
+
}
|
|
110
|
+
const real = (p) => {
|
|
111
|
+
// A folder that does not exist yet (import target): check its nearest existing parent.
|
|
112
|
+
let cur = p;
|
|
113
|
+
const rest = [];
|
|
114
|
+
while (!existsSync(cur) && dirname(cur) !== cur) {
|
|
115
|
+
rest.unshift(cur.slice(dirname(cur).length + 1));
|
|
116
|
+
cur = dirname(cur);
|
|
117
|
+
}
|
|
118
|
+
return join(realpathSync(cur), ...rest);
|
|
119
|
+
};
|
|
120
|
+
async function folder(input, mustExist = true) {
|
|
121
|
+
const allowed = await roots();
|
|
122
|
+
const abs = isAbsolute(input) ? resolve(input) : resolve(allowed[0], input);
|
|
123
|
+
const target = real(abs);
|
|
124
|
+
const inside = allowed.some((r) => {
|
|
125
|
+
const rel = relative(real(r), target);
|
|
126
|
+
return rel === "" || (!rel.startsWith("..") && !isAbsolute(rel));
|
|
127
|
+
});
|
|
128
|
+
if (!inside)
|
|
129
|
+
throw new DerushlyError("invalid", `${input} is outside the folders this server may use (${allowed.join(", ")})`);
|
|
130
|
+
if (mustExist && !existsSync(target))
|
|
131
|
+
throw new DerushlyError("not_found", `${input} does not exist`);
|
|
132
|
+
return target;
|
|
133
|
+
}
|
|
134
|
+
async function project(input) {
|
|
135
|
+
const dir = await folder(input);
|
|
136
|
+
if (!existsSync(join(dir, "project.json")))
|
|
137
|
+
throw new DerushlyError("not_found", `${input} is not a Derushly project (no project.json): import it with project_create`);
|
|
138
|
+
return dir;
|
|
139
|
+
}
|
|
140
|
+
// ---- confirmation (spec: costly or destructive actions) -------------------------------------
|
|
141
|
+
async function confirm(question, confirmed) {
|
|
142
|
+
if (opts.confirm !== "conversation" && server.server.getClientCapabilities()?.elicitation) {
|
|
143
|
+
const r = await server.server.elicitInput({
|
|
144
|
+
message: question,
|
|
145
|
+
requestedSchema: { type: "object", properties: { confirm: { type: "boolean", title: "Confirmer", description: question } }, required: ["confirm"] },
|
|
146
|
+
});
|
|
147
|
+
if (r.action === "accept" && r.content?.confirm === true)
|
|
148
|
+
return;
|
|
149
|
+
throw new DerushlyError("usage", `the user did not confirm in the dialog (${r.action}): nothing was done. ` +
|
|
150
|
+
"Do not retry on your own. If the user did not see a dialog, the client may decline them automatically (non-interactive runs such as codex exec): " +
|
|
151
|
+
`tell the user; ${opts.declinedHint ?? "the server can be started with DERUSHLY_CONFIRM=conversation (or --confirm conversation) to accept confirmed: true instead."}`);
|
|
152
|
+
}
|
|
153
|
+
// No dialog in this client: the agent must have asked the user in the conversation.
|
|
154
|
+
if (confirmed !== true) {
|
|
155
|
+
throw new DerushlyError("usage", `${question} This needs the user's confirmation: ask them in the conversation, then call again with confirmed: true.`);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
const confirmedArg = { confirmed: z.boolean().optional().describe("Only for clients without confirmation dialogs: true once the user agreed in the conversation") };
|
|
159
|
+
function tool(name, config, run, raw = false) {
|
|
160
|
+
if (disabled.has(name))
|
|
161
|
+
return;
|
|
162
|
+
server.registerTool(name, {
|
|
163
|
+
title: config.title,
|
|
164
|
+
description: config.description,
|
|
165
|
+
inputSchema: config.input,
|
|
166
|
+
...(outputSchema(name) ? { outputSchema: outputSchema(name) } : {}),
|
|
167
|
+
annotations: { title: config.title, readOnlyHint: !!config.readOnly, destructiveHint: !!config.destructive, idempotentHint: !!config.readOnly, openWorldHint: !!config.openWorld },
|
|
168
|
+
}, (async (args, extra) => {
|
|
169
|
+
const call = async () => {
|
|
170
|
+
try {
|
|
171
|
+
const out = await run(args, extra);
|
|
172
|
+
return raw ? out : ok(out);
|
|
173
|
+
}
|
|
174
|
+
catch (e) {
|
|
175
|
+
return fail(e);
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
if (!opts.around)
|
|
179
|
+
return call();
|
|
180
|
+
try {
|
|
181
|
+
return await opts.around(name, !!config.readOnly, call);
|
|
182
|
+
}
|
|
183
|
+
catch (e) {
|
|
184
|
+
return fail(e);
|
|
185
|
+
}
|
|
186
|
+
}));
|
|
187
|
+
}
|
|
188
|
+
const rendering = () => busy === "render" || busy === "preview";
|
|
189
|
+
const engineBusy = () => new DerushlyError("exists", `the engine is busy (${busy ?? "checks are queued"}): wait for it (render_status), then try again`);
|
|
190
|
+
function exclusive(what, fn) {
|
|
191
|
+
if (rendering())
|
|
192
|
+
return Promise.reject(engineBusy());
|
|
193
|
+
waiting++;
|
|
194
|
+
const next = queue.then(async () => {
|
|
195
|
+
busy = what;
|
|
196
|
+
try {
|
|
197
|
+
return await fn();
|
|
198
|
+
}
|
|
199
|
+
finally {
|
|
200
|
+
busy = null;
|
|
201
|
+
waiting--;
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
queue = next.catch(() => { });
|
|
205
|
+
return next;
|
|
206
|
+
}
|
|
207
|
+
// ---- project -------------------------------------------------------------------------------
|
|
208
|
+
tool("project_create", {
|
|
209
|
+
title: "Create a project",
|
|
210
|
+
description: "Creates a Derushly project in a new folder: from a template (library_list: blank, ad, or one saved with template_save) in a format (9x16, 16x9, 1x1, 4x5), with media files checked and copied into assets/ (the ad template places them as clips under a hook, then three points, a key figure and an end card); or by importing a HyperFrames project folder (source; the source is not changed). .env files are never copied. Returns the scenes and their editable texts.",
|
|
211
|
+
input: {
|
|
212
|
+
project: text(1000).describe("New project folder (must not exist, or be empty)"),
|
|
213
|
+
source: text(1000).optional().describe("HyperFrames project folder to import, instead of a template"),
|
|
214
|
+
template: text(100).optional().describe("Template id (default blank)"),
|
|
215
|
+
format: z.enum(["9x16", "16x9", "1x1", "4x5"]).optional().describe("Format of a built-in template (default 9x16)"),
|
|
216
|
+
name: text(200).optional(),
|
|
217
|
+
fps: z.number().int().min(1).max(120).optional(),
|
|
218
|
+
media: z.array(text(1000)).max(50).optional().describe("Video, image, sound or font files to bring in (inside the allowed folders)"),
|
|
219
|
+
license: text(500).optional().describe("Licence or origin of those files, recorded with them"),
|
|
220
|
+
},
|
|
221
|
+
}, async ({ source, project: dest, template, format, name, fps, media, license }) => {
|
|
222
|
+
const dir = await folder(dest, false);
|
|
223
|
+
if (!source) {
|
|
224
|
+
const files = await Promise.all((media ?? []).map((m) => folder(m)));
|
|
225
|
+
const r = core.createProject(dir, clean({ template, format, name, fps, license, media: files.length ? files : undefined }));
|
|
226
|
+
return { ok: true, ...r, scenes: core.describe(dir).scenes, variables: core.listVariables(dir) };
|
|
227
|
+
}
|
|
228
|
+
if (template || format || media?.length)
|
|
229
|
+
throw new DerushlyError("usage", "give source (import) or a template with media, not both");
|
|
230
|
+
const src = await folder(source);
|
|
231
|
+
const { report } = core.importProject(src, dir);
|
|
232
|
+
const built = core.build(dir);
|
|
233
|
+
core.openProject(dir);
|
|
234
|
+
const view = core.describe(dir);
|
|
235
|
+
return { ok: true, project: dir, built, variables: core.listVariables(dir).reduce((n, s) => n + s.variables.length, 0), skipped: report.skipped, warnings: report.warnings, scenes: view.scenes };
|
|
236
|
+
});
|
|
237
|
+
tool("project_get", {
|
|
238
|
+
title: "Read a project",
|
|
239
|
+
description: "Reads a project: composition, scenes (with their editable variables and current values), audio clips, captions, formats (main format and variants), open notes and the current version. Call it before editing.",
|
|
240
|
+
input: { ...projectArg, include: z.array(z.enum(["variables", "captions", "history", "journal"])).max(4).optional().describe("Extra parts; default: variables") },
|
|
241
|
+
readOnly: true,
|
|
242
|
+
}, async ({ project: p, include }) => {
|
|
243
|
+
const dir = await project(p);
|
|
244
|
+
const parts = new Set(include ?? ["variables"]);
|
|
245
|
+
const view = core.describe(dir);
|
|
246
|
+
return {
|
|
247
|
+
ok: true, project: dir, ...view,
|
|
248
|
+
...(parts.has("variables") ? { variables: core.listVariables(dir) } : {}),
|
|
249
|
+
...(parts.has("history") ? { history: core.history(dir) } : {}),
|
|
250
|
+
...(parts.has("journal") ? { journal: core.journalEntries(dir, 30) } : {}),
|
|
251
|
+
formats: core.listFormats(dir),
|
|
252
|
+
brands: core.listBrands(dir),
|
|
253
|
+
openNotes: core.listNotes(dir, { status: "open" }),
|
|
254
|
+
render: core.renderStatus(dir),
|
|
255
|
+
};
|
|
256
|
+
});
|
|
257
|
+
tool("project_sync", {
|
|
258
|
+
title: "Take or discard outside edits",
|
|
259
|
+
description: "When a tool answers code \"drift\" (generated files were edited in the HyperFrames Studio or by hand): keep: true takes those edits into the project; keep: false discards them and regenerates the files (asks the user first).",
|
|
260
|
+
input: { ...projectArg, keep: z.boolean().describe("true: take the outside edits; false: discard them"), ...confirmedArg },
|
|
261
|
+
}, async ({ project: p, keep, confirmed }) => {
|
|
262
|
+
const dir = await project(p);
|
|
263
|
+
if (keep)
|
|
264
|
+
return { ok: true, ...core.sync(dir) };
|
|
265
|
+
await confirm(`Discard the edits made outside Derushly in ${dir}?`, confirmed);
|
|
266
|
+
return { ok: true, ...core.rebuild(dir, { force: true }) };
|
|
267
|
+
});
|
|
268
|
+
tool("history_undo", {
|
|
269
|
+
title: "Undo the last change",
|
|
270
|
+
description: "Goes back one version of the project (any edit made by a tool). history_redo goes forward again.",
|
|
271
|
+
input: projectArg,
|
|
272
|
+
}, async ({ project: p }) => ({ ok: true, ...core.undo(await project(p)) }));
|
|
273
|
+
tool("history_redo", {
|
|
274
|
+
title: "Redo a change",
|
|
275
|
+
description: "Goes forward one version after history_undo.",
|
|
276
|
+
input: projectArg,
|
|
277
|
+
}, async ({ project: p }) => ({ ok: true, ...core.redo(await project(p)) }));
|
|
278
|
+
tool("project_archive", {
|
|
279
|
+
title: "Archive the project",
|
|
280
|
+
description: "Packs the project into exports/archives/<id>-v<version>.tar.gz, without its history, renders or .env files. Never overwrites an archive.",
|
|
281
|
+
input: projectArg,
|
|
282
|
+
}, async ({ project: p }) => core.archiveProject(await project(p)));
|
|
283
|
+
// ---- media ---------------------------------------------------------------------------------
|
|
284
|
+
tool("media_list", {
|
|
285
|
+
title: "List the media",
|
|
286
|
+
description: "Lists the project's media files with their real type, size, duration, resolution and audio, and flags missing files, files loaded from the internet and files too large or too long.",
|
|
287
|
+
input: projectArg,
|
|
288
|
+
readOnly: true,
|
|
289
|
+
}, async ({ project: p }) => {
|
|
290
|
+
const r = core.analyzeMedia(await project(p));
|
|
291
|
+
return { ok: r.errors === 0, ...r };
|
|
292
|
+
});
|
|
293
|
+
tool("media_analyze", {
|
|
294
|
+
title: "Analyze one media file",
|
|
295
|
+
description: "Reads one media file of the project: real type (from its bytes), duration, resolution, frame rate, audio.",
|
|
296
|
+
input: { ...projectArg, path: text(1000).describe("File path, relative to the project folder") },
|
|
297
|
+
readOnly: true,
|
|
298
|
+
}, async ({ project: p, path }) => {
|
|
299
|
+
const dir = await project(p);
|
|
300
|
+
const file = core.inside(dir, path);
|
|
301
|
+
if (!existsSync(file))
|
|
302
|
+
throw new DerushlyError("not_found", `${path} does not exist in the project`);
|
|
303
|
+
return { ok: true, path, bytes: statSync(file).size, type: core.sniff(file) ?? "unknown", probe: core.probe(file) ?? null };
|
|
304
|
+
});
|
|
305
|
+
tool("media_import", {
|
|
306
|
+
title: "Bring media files in",
|
|
307
|
+
description: "Checks files (real type from their bytes, size, duration, picture, sound; SVG without scripts) and copies them into the project's assets/ (video/, images/, audio/, fonts/, or folder), recording where each came from and its licence. All or nothing. Then place them with scene_create (media) or timeline_update (audio with src).",
|
|
308
|
+
input: {
|
|
309
|
+
...projectArg,
|
|
310
|
+
files: z.array(text(1000)).min(1).max(50).describe("Files inside the allowed folders"),
|
|
311
|
+
license: text(500).optional(),
|
|
312
|
+
folder: text(200).optional().describe("Target folder in the project, e.g. assets/vo"),
|
|
313
|
+
},
|
|
314
|
+
}, async ({ project: p, files, license, folder: sub }) => {
|
|
315
|
+
const dir = await project(p);
|
|
316
|
+
const paths = await Promise.all(files.map((f) => folder(f)));
|
|
317
|
+
const r = core.importMedia(dir, paths, clean({ license, folder: sub }));
|
|
318
|
+
return { ok: true, imported: r.result, version: r.version };
|
|
319
|
+
});
|
|
320
|
+
tool("library_list", {
|
|
321
|
+
title: "List components and templates",
|
|
322
|
+
description: "What Derushly offers to build a video: built-in components (add one with scene_create, component \"library:<id>\"; their variables and defaults), templates (project_create), transitions and clip motions.",
|
|
323
|
+
input: {},
|
|
324
|
+
readOnly: true,
|
|
325
|
+
}, async () => ({ ok: true, ...core.listLibrary() }));
|
|
326
|
+
tool("template_save", {
|
|
327
|
+
title: "Save as a template",
|
|
328
|
+
description: "Saves the project (scenes, components, brand kits, captions style, media) as a template for project_create, without its history, notes, renders or .env.",
|
|
329
|
+
input: { ...projectArg, name: z.string().regex(/^[a-z0-9][a-z0-9-]{0,39}$/), description: text(500).optional(), overwrite: z.boolean().optional() },
|
|
330
|
+
}, async ({ project: p, name, description, overwrite }) => ({ ok: true, template: core.saveTemplate(await project(p), name, clean({ description, overwrite })) }));
|
|
331
|
+
// ---- scenes and texts ----------------------------------------------------------------------
|
|
332
|
+
tool("variables_set", {
|
|
333
|
+
title: "Change scene texts",
|
|
334
|
+
description: "Changes the editable texts (variables) of scenes, all in one version. A list variable takes an array with exactly as many strings as it has items, or one item with index (1-based). *word* marks an accented word where the variable allows it. Unknown names are refused with the list of valid ones.",
|
|
335
|
+
input: {
|
|
336
|
+
...projectArg,
|
|
337
|
+
values: z.array(z.object({
|
|
338
|
+
scene: text(200),
|
|
339
|
+
variable: text(200).describe("Variable id, or an element id inside a list"),
|
|
340
|
+
index: z.number().int().min(1).max(500).optional().describe("For a list: the item to change (1-based)"),
|
|
341
|
+
value: z.union([text(5000), z.array(text(5000)).max(500)]),
|
|
342
|
+
})).min(1).max(200),
|
|
343
|
+
},
|
|
344
|
+
}, async ({ project: p, values }) => {
|
|
345
|
+
const dir = await project(p);
|
|
346
|
+
const r = core.setVariables(dir, values.map((v) => ({ scene: v.scene, target: v.index ? `${v.variable}[${v.index}]` : v.variable, value: v.value })));
|
|
347
|
+
return { ok: true, version: r.version, built: r.built };
|
|
348
|
+
});
|
|
349
|
+
tool("scene_create", {
|
|
350
|
+
title: "Add a scene",
|
|
351
|
+
description: "Adds a scene: a video or image clip of the project (media), a built-in component (component \"library:title\", see library_list), or a component already in the project (copy of scene `from`, or its file), with its own texts and transitions. In projects with track layering (those Derushly creates) a higher track is painted over a lower one; a clip without duration lasts as long as its video (3 s for an image). ripple: true makes room (what starts later moves later); extend: true lengthens the video when the scene ends after it.",
|
|
352
|
+
input: {
|
|
353
|
+
...projectArg,
|
|
354
|
+
id: text(100).describe("New scene id: letters, digits, dashes"),
|
|
355
|
+
from: text(100).optional().describe("Id of a scene whose component is reused"),
|
|
356
|
+
component: text(500).optional().describe("Or a component: library:<id>, or a file such as compositions/card.html"),
|
|
357
|
+
media: mediaClip.optional().describe("Or a video / image clip"),
|
|
358
|
+
start: seconds,
|
|
359
|
+
duration: seconds.positive().optional().describe("Seconds (required for a project component)"),
|
|
360
|
+
track: z.number().int().min(0).max(100).optional(),
|
|
361
|
+
params: z.record(text(200), z.union([text(5000), z.array(text(5000)).max(500)])).optional().describe("Texts and colours of the new scene: { variable: value }; a colour takes CSS or brand.<name>"),
|
|
362
|
+
transitionIn: transition.optional(), transitionOut: transition.optional(),
|
|
363
|
+
transform: transform.optional().describe("Free placement: picture-in-picture, tilt, transparency"),
|
|
364
|
+
ripple: z.boolean().optional(), extend: z.boolean().optional(),
|
|
365
|
+
},
|
|
366
|
+
}, async ({ project: p, ripple, ...input }) => {
|
|
367
|
+
const r = core.addScene(await project(p), clean(input), { ripple: !!ripple });
|
|
368
|
+
return { ok: true, ...r.result, version: r.version };
|
|
369
|
+
});
|
|
370
|
+
tool("scene_update", {
|
|
371
|
+
title: "Change a scene's timing, transitions or clip",
|
|
372
|
+
description: "Changes a scene's start, duration (or shorten / lengthen by some seconds), track, transitions (null removes one) or, for a clip, its media fields (src, mediaStart, fit, volume, muted, motion; null removes one); or moves it before / after another scene. ripple: true moves what follows (scenes, voice, effects, captions) and changes the video's length; music follows. extend: true lengthens the video when the scene ends after it.",
|
|
373
|
+
input: {
|
|
374
|
+
...projectArg,
|
|
375
|
+
id: text(100),
|
|
376
|
+
start: seconds.optional(), duration: seconds.positive().optional(),
|
|
377
|
+
shorten: seconds.positive().optional(), lengthen: seconds.positive().optional(),
|
|
378
|
+
track: z.number().int().min(0).max(100).optional(),
|
|
379
|
+
before: text(100).optional(), after: text(100).optional(),
|
|
380
|
+
transitionIn: transition.nullable().optional(), transitionOut: transition.nullable().optional(),
|
|
381
|
+
media: mediaPatch.optional(),
|
|
382
|
+
transform: transform.nullable().optional().describe("Free placement (scene or clip): given fields change, a null field or transform: null resets"),
|
|
383
|
+
ripple: z.boolean().optional(), extend: z.boolean().optional(),
|
|
384
|
+
},
|
|
385
|
+
}, async ({ project: p, id, before, after, shorten, lengthen, ripple, transitionIn, transitionOut, media, transform: place, extend, ...patch }) => {
|
|
386
|
+
const dir = await project(p);
|
|
387
|
+
if (before || after) {
|
|
388
|
+
const r = core.moveScene(dir, id, { ...(before ? { before } : {}), ...(after ? { after } : {}) });
|
|
389
|
+
return { ok: true, ...r.result, version: r.version };
|
|
390
|
+
}
|
|
391
|
+
if ([patch.duration, shorten, lengthen].filter((x) => x !== undefined).length > 1)
|
|
392
|
+
throw new DerushlyError("usage", "use only one of duration, shorten, lengthen");
|
|
393
|
+
const scene = core.openProject(dir).project.scenes.find((s) => s.id === id);
|
|
394
|
+
if (!scene)
|
|
395
|
+
throw new DerushlyError("not_found", `Unknown scene "${id}"`);
|
|
396
|
+
const duration = patch.duration ?? (shorten ? scene.duration - shorten : lengthen ? scene.duration + lengthen : undefined);
|
|
397
|
+
const change = clean({
|
|
398
|
+
start: patch.start, track: patch.track, duration: duration === undefined ? undefined : Math.round(duration * 1000) / 1000,
|
|
399
|
+
transitionIn, transitionOut, media: media ? clean(media) : undefined, transform: place && clean(place), extend,
|
|
400
|
+
});
|
|
401
|
+
if (!Object.keys(change).filter((k) => k !== "extend").length)
|
|
402
|
+
throw new DerushlyError("usage", "nothing to change: give start, duration, shorten, lengthen, track, transitions, media, transform, before or after");
|
|
403
|
+
const r = core.updateScene(dir, id, change, { ripple: !!ripple });
|
|
404
|
+
return { ok: true, ...r.result, version: r.version };
|
|
405
|
+
});
|
|
406
|
+
tool("clip_edit", {
|
|
407
|
+
title: "Cut, trim, duplicate or cross-fade",
|
|
408
|
+
description: "Edits like on an editing timeline. split: cuts a media clip or an audio clip in two at `at` (a component scene cannot be cut). trim: new in and/or out points (times of the video) for a scene or audio clip; ripple: true leaves no hole (what follows moves). duplicate: copies it, right after or at `at`, on `track`. crossfade: fades a scene into the next one on the same track over `duration` s. layering: track order decides what is on top (tracks) or not (default). Check captions after cutting or moving voice.",
|
|
409
|
+
input: {
|
|
410
|
+
...projectArg,
|
|
411
|
+
action: z.enum(["split", "trim", "duplicate", "crossfade", "layering"]),
|
|
412
|
+
id: text(100).optional().describe("Scene or audio clip id (all actions but layering)"),
|
|
413
|
+
at: seconds.optional().describe("split: where to cut; duplicate: where the copy starts"),
|
|
414
|
+
in: seconds.optional(), out: seconds.optional(),
|
|
415
|
+
duration: seconds.positive().optional().describe("crossfade: seconds (default 0.5)"),
|
|
416
|
+
track: z.number().int().min(0).max(100).optional().describe("duplicate: track of the copy"),
|
|
417
|
+
layering: z.enum(["tracks", "default"]).optional(),
|
|
418
|
+
ripple: z.boolean().optional(), extend: z.boolean().optional(),
|
|
419
|
+
},
|
|
420
|
+
}, async ({ project: p, action, id, at, in: from, out, duration, track, layering, ripple, extend }) => {
|
|
421
|
+
const dir = await project(p);
|
|
422
|
+
if (action === "layering") {
|
|
423
|
+
if (!layering)
|
|
424
|
+
throw new DerushlyError("usage", "layering needs layering: tracks or default");
|
|
425
|
+
const r = core.setLayering(dir, layering);
|
|
426
|
+
return { ok: true, layering: r.result, version: r.version };
|
|
427
|
+
}
|
|
428
|
+
if (!id)
|
|
429
|
+
throw new DerushlyError("usage", `${action} needs id`);
|
|
430
|
+
if (action === "split" && at === undefined)
|
|
431
|
+
throw new DerushlyError("usage", "split needs at");
|
|
432
|
+
const r = action === "split" ? core.splitClip(dir, id, at)
|
|
433
|
+
: action === "trim" ? core.trimClip(dir, id, clean({ in: from, out }), { ripple: !!ripple })
|
|
434
|
+
: action === "duplicate" ? core.duplicateClip(dir, id, clean({ at, track, extend }))
|
|
435
|
+
: core.crossfade(dir, id, duration);
|
|
436
|
+
return { ok: true, ...r.result, version: r.version };
|
|
437
|
+
});
|
|
438
|
+
tool("scene_delete", {
|
|
439
|
+
title: "Delete a scene",
|
|
440
|
+
description: "Removes a scene (asks the user first; history_undo brings it back). ripple: true also removes the voice, effects and captions lying entirely inside it and closes the gap.",
|
|
441
|
+
input: { ...projectArg, id: text(100), ripple: z.boolean().optional(), ...confirmedArg },
|
|
442
|
+
destructive: true,
|
|
443
|
+
}, async ({ project: p, id, ripple, confirmed }) => {
|
|
444
|
+
const dir = await project(p);
|
|
445
|
+
await confirm(`Delete scene "${id}"${ripple ? " and close the gap" : ""}?`, confirmed);
|
|
446
|
+
const r = core.removeScene(dir, id, { ripple: !!ripple });
|
|
447
|
+
return { ok: true, ...r.result, version: r.version };
|
|
448
|
+
});
|
|
449
|
+
// ---- audio and captions --------------------------------------------------------------------
|
|
450
|
+
const audioChange = z.object({
|
|
451
|
+
src: text(1000).optional().describe("Add a clip: an audio file of the project (assets/...), with start"),
|
|
452
|
+
extend: z.boolean().optional().describe("New clip: lengthen the video when it ends after it"),
|
|
453
|
+
id: text(100).optional(), role: z.enum(["music", "voice", "sfx", "audio"]).optional().describe("Change: all clips of this role, instead of one id. New clip: its role (music is trimmed to the end of the video)"),
|
|
454
|
+
volume: z.union([z.number().min(0).max(4), text(20)]).optional().describe("Gain (0.5) or change in decibels (\"-6dB\")"),
|
|
455
|
+
start: seconds.optional(), duration: seconds.positive().optional(), mediaStart: seconds.optional(),
|
|
456
|
+
fadeIn: seconds.optional(), fadeOut: seconds.optional(), track: z.number().int().min(0).max(100).optional(),
|
|
457
|
+
remove: z.boolean().optional().describe("Remove this clip"),
|
|
458
|
+
});
|
|
459
|
+
const captionChange = z.object({
|
|
460
|
+
id: text(100).optional().describe("Caption to change or remove; omit to add one"),
|
|
461
|
+
text: text(1000).optional().describe("Words separated by spaces; *word* = accented"),
|
|
462
|
+
start: seconds.optional(), duration: seconds.positive().optional(),
|
|
463
|
+
remove: z.boolean().optional(),
|
|
464
|
+
});
|
|
465
|
+
const variantChange = z.object({
|
|
466
|
+
id: z.string().regex(/^[a-z0-9][a-z0-9-]{0,31}$/).describe("Format id: a preset (16x9, 9x16, 1x1, 4x5), or a name with width and height"),
|
|
467
|
+
preset: z.enum(["16x9", "9x16", "1x1", "4x5"]).optional(),
|
|
468
|
+
width: z.number().int().min(16).max(7680).optional(), height: z.number().int().min(16).max(7680).optional(),
|
|
469
|
+
fit: z.enum(["contain", "cover"]).optional().describe("contain: whole scenes, bands around; cover: fills the frame, crops the edges"),
|
|
470
|
+
background: z.union([text(30), z.null()]).optional().describe("Colour of the bands (contain); null: the video's own background"),
|
|
471
|
+
safeZone: z.union([z.enum(["tiktok", "reels", "shorts", "standard", "off"]), z.null()]).optional().describe("Safe zone the check applies to this format; null: default"),
|
|
472
|
+
remove: z.boolean().optional().describe("Remove this variant"),
|
|
473
|
+
});
|
|
474
|
+
tool("timeline_update", {
|
|
475
|
+
title: "Change audio clips, captions and formats",
|
|
476
|
+
description: "Changes the video's length (duration), audio clips (add one with src and start: a voice line, a music bed, a sound effect; volume in gain or dB, timing, fades; by id or by role, e.g. role music), captions (text, timing; add when no id; remove) and format variants (the same video in another frame: 16x9, 9x16, 1x1, 4x5; add, change, remove). Each change is one version (history_undo goes back).",
|
|
477
|
+
input: {
|
|
478
|
+
...projectArg,
|
|
479
|
+
duration: seconds.positive().optional().describe("New length of the video in seconds (not shorter than its scenes)"),
|
|
480
|
+
audio: z.array(audioChange).max(100).optional(), captions: z.array(captionChange).max(200).optional(), variants: z.array(variantChange).max(10).optional(),
|
|
481
|
+
},
|
|
482
|
+
}, async ({ project: p, duration, audio, captions, variants }) => {
|
|
483
|
+
const dir = await project(p);
|
|
484
|
+
if (duration === undefined && !audio?.length && !captions?.length && !variants?.length)
|
|
485
|
+
throw new DerushlyError("usage", "nothing to change: give duration, audio, captions and/or variants");
|
|
486
|
+
const done = [];
|
|
487
|
+
// All or nothing: a failing change undoes the ones this call already made.
|
|
488
|
+
const v0 = core.currentVersion(dir);
|
|
489
|
+
try {
|
|
490
|
+
if (duration !== undefined)
|
|
491
|
+
done.push({ duration: core.setDuration(dir, duration).result });
|
|
492
|
+
for (const a of audio ?? []) {
|
|
493
|
+
if (a.src) {
|
|
494
|
+
const { src, start, volume, remove, ...rest } = a;
|
|
495
|
+
if (start === undefined || remove)
|
|
496
|
+
throw new DerushlyError("usage", "a new audio clip needs src and start");
|
|
497
|
+
if (typeof volume === "string")
|
|
498
|
+
throw new DerushlyError("usage", "a new clip takes volume as a gain (0.5), not in dB");
|
|
499
|
+
done.push({ added: core.addAudio(dir, { src, start, ...clean(rest), ...(volume !== undefined ? { volume } : {}) }).result });
|
|
500
|
+
continue;
|
|
501
|
+
}
|
|
502
|
+
if (!a.id && !a.role)
|
|
503
|
+
throw new DerushlyError("usage", "each audio change needs an id or a role");
|
|
504
|
+
if (a.remove) {
|
|
505
|
+
if (!a.id)
|
|
506
|
+
throw new DerushlyError("usage", "remove takes one clip id");
|
|
507
|
+
done.push({ removed: core.removeAudio(dir, a.id).result });
|
|
508
|
+
continue;
|
|
509
|
+
}
|
|
510
|
+
const { id, role, volume, remove: _r, extend: _e, src: _s, ...rest } = a;
|
|
511
|
+
const patch = Object.fromEntries(Object.entries(rest).filter(([, v]) => v !== undefined));
|
|
512
|
+
const r = core.updateAudio(dir, { ...(id ? { id } : {}), ...(role ? { role } : {}) }, { ...patch, ...(typeof volume === "number" ? { volume } : {}), ...(typeof volume === "string" ? { volumeChange: volume } : {}) });
|
|
513
|
+
done.push({ audio: r.result });
|
|
514
|
+
}
|
|
515
|
+
for (const c of captions ?? []) {
|
|
516
|
+
if (c.remove) {
|
|
517
|
+
if (!c.id)
|
|
518
|
+
throw new DerushlyError("usage", "remove takes a caption id");
|
|
519
|
+
done.push({ removed: core.removeCaption(dir, c.id).result });
|
|
520
|
+
}
|
|
521
|
+
else if (c.id) {
|
|
522
|
+
const { id, remove: _r, ...rest } = c;
|
|
523
|
+
done.push({ caption: core.updateCaption(dir, id, Object.fromEntries(Object.entries(rest).filter(([, v]) => v !== undefined))).result });
|
|
524
|
+
}
|
|
525
|
+
else {
|
|
526
|
+
if (c.text === undefined || c.start === undefined || c.duration === undefined)
|
|
527
|
+
throw new DerushlyError("usage", "a new caption needs text, start and duration");
|
|
528
|
+
done.push({ added: core.addCaption(dir, { text: c.text, start: c.start, duration: c.duration }).result });
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
for (const v of variants ?? []) {
|
|
532
|
+
if (v.remove) {
|
|
533
|
+
done.push({ removedFormat: core.removeVariant(dir, v.id).result });
|
|
534
|
+
continue;
|
|
535
|
+
}
|
|
536
|
+
const { remove: _r, ...rest } = v;
|
|
537
|
+
done.push({ format: core.setVariant(dir, Object.fromEntries(Object.entries(rest).filter(([, x]) => x !== undefined))).result });
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
catch (e) {
|
|
541
|
+
for (let i = 0; i <= done.length && core.currentVersion(dir) !== v0; i++)
|
|
542
|
+
core.undo(dir);
|
|
543
|
+
if (done.length && e instanceof DerushlyError)
|
|
544
|
+
throw new DerushlyError(e.code, `${e.message}\n(the ${done.length} earlier change(s) of this call were undone: nothing changed)`, { errors: e.errors });
|
|
545
|
+
throw e;
|
|
546
|
+
}
|
|
547
|
+
return { ok: true, changes: done, version: core.currentVersion(dir) };
|
|
548
|
+
});
|
|
549
|
+
// ---- brand kits ----------------------------------------------------------------------------
|
|
550
|
+
tool("brand_update", {
|
|
551
|
+
title: "Create, change or apply a brand kit",
|
|
552
|
+
description: "Creates or changes a brand kit (colours, font files, logos, caption style) kept in the project's brands/<id>/, and applies it (apply: true). Applied, its colours become CSS variables (--brand-<name>) the components use (colour variables take brand.<name>), its fonts and logos load in the video, and the caption style applies. Font and logo files are checked and copied into the kit. null removes an entry; remove: true removes the kit (asks first). project_get lists the kits.",
|
|
553
|
+
input: {
|
|
554
|
+
...projectArg,
|
|
555
|
+
id: z.string().regex(/^[a-z0-9][a-z0-9-]{0,39}$/),
|
|
556
|
+
name: text(200).optional(),
|
|
557
|
+
colors: z.record(name40, z.union([text(80), z.null()])).optional().describe("{ primary: \"#ff5a1f\", background, text, accent... }"),
|
|
558
|
+
fonts: z.record(name40, z.union([z.object({ file: text(1000), family: text(100).optional(), weight: text(20).optional(), style: z.enum(["normal", "italic"]).optional() }), z.null()])).optional()
|
|
559
|
+
.describe("{ display: { file, family }, body: ... }: .woff2, .woff, .ttf or .otf"),
|
|
560
|
+
logos: z.record(name40, z.union([text(1000), z.null()])).optional().describe("{ main: file }: the end card shows main"),
|
|
561
|
+
captions: z.union([z.object({
|
|
562
|
+
color: text(80).optional(), highlight: text(80).optional(), background: text(80).optional(),
|
|
563
|
+
font: text(40).optional().describe("A font role of the kit"),
|
|
564
|
+
size: z.number().min(2).max(20).optional().describe("Text height in % of the frame's shorter side (2 to 20; about 4 for a vertical video)"), position: z.enum(["bottom", "middle", "top"]).optional(), uppercase: z.boolean().optional(),
|
|
565
|
+
}), z.null()]).optional(),
|
|
566
|
+
apply: z.boolean().optional().describe("true: apply this kit; false: stop applying it"),
|
|
567
|
+
remove: z.boolean().optional(),
|
|
568
|
+
...confirmedArg,
|
|
569
|
+
},
|
|
570
|
+
}, async ({ project: p, remove, confirmed, ...input }) => {
|
|
571
|
+
const dir = await project(p);
|
|
572
|
+
if (remove) {
|
|
573
|
+
await confirm(`Remove brand kit "${input.id}" from the project?`, confirmed);
|
|
574
|
+
return { ok: true, removed: core.removeBrand(dir, input.id).result };
|
|
575
|
+
}
|
|
576
|
+
// Files outside the project must be inside the allowed folders.
|
|
577
|
+
const own = async (f) => (isAbsolute(f) ? folder(f) : f);
|
|
578
|
+
const fonts = input.fonts
|
|
579
|
+
? Object.fromEntries(await Promise.all(Object.entries(input.fonts).map(async ([k, v]) => [k, v ? { ...clean(v), file: await own(v.file) } : null])))
|
|
580
|
+
: undefined;
|
|
581
|
+
const logos = input.logos ? Object.fromEntries(await Promise.all(Object.entries(input.logos).map(async ([k, v]) => [k, v ? await own(v) : null]))) : undefined;
|
|
582
|
+
const captions = input.captions === null ? null : input.captions ? clean(input.captions) : undefined;
|
|
583
|
+
const r = core.setBrand(dir, clean({ ...input, fonts, logos, captions }));
|
|
584
|
+
return { ok: true, ...r.result, version: r.version };
|
|
585
|
+
});
|
|
586
|
+
// ---- voice and captions ---------------------------------------------------------------------
|
|
587
|
+
tool("adapters_list", {
|
|
588
|
+
title: "List speech and transcription adapters",
|
|
589
|
+
description: "Speech synthesis and transcription adapters: where they run (local, or a remote service), cost, what they need, settings, limits, licence of what they make, and whether they are ready here (with what to do if not). Account adapters stay off until the user lists them in DERUSHLY_ADAPTERS; keys stay in the environment or the project's .env and are never shown.",
|
|
590
|
+
input: { project: text(1000).optional().describe("Project folder, to read its .env") },
|
|
591
|
+
readOnly: true,
|
|
592
|
+
}, async ({ project: p }) => ({ ok: true, adapters: core.listAdapters(p ? await project(p) : undefined) }));
|
|
593
|
+
tool("voice_generate", {
|
|
594
|
+
title: "Generate a voice line",
|
|
595
|
+
description: "Synthesises a voice line from a text with a speech adapter (adapters_list) into assets/vo/<id>.wav, records its provenance (adapter, model, voice, text, licence) and places it on the timeline when start is given. A remote adapter sends the text to the service and may cost: the user confirms first.",
|
|
596
|
+
input: {
|
|
597
|
+
...projectArg, text: text(4000), adapter: text(40).optional().describe("Default: DERUSHLY_TTS"),
|
|
598
|
+
voice: text(80).optional(), language: text(20).optional(), speed: z.number().min(0.25).max(4).optional(),
|
|
599
|
+
id: z.string().regex(/^[a-z][a-z0-9-]{0,39}$/i).optional(), start: seconds.optional(), volume: z.number().min(0).max(4).optional(), extend: z.boolean().optional(),
|
|
600
|
+
...confirmedArg,
|
|
601
|
+
},
|
|
602
|
+
}, async ({ project: p, confirmed, ...input }) => {
|
|
603
|
+
const dir = await project(p);
|
|
604
|
+
const adapter = core.adapterFor(dir, "tts", input.adapter);
|
|
605
|
+
if (core.isRemote(adapter))
|
|
606
|
+
await confirm(`Generate a voice line (${input.text.length} characters) with ${adapter.name}? The text is sent to the service (${adapter.cost}).`, confirmed);
|
|
607
|
+
const r = await core.generateVoice(dir, { ...clean(input), adapter: adapter.id });
|
|
608
|
+
return { ok: true, ...r.result, license: adapter.license, version: r.version };
|
|
609
|
+
});
|
|
610
|
+
tool("captions_transcribe", {
|
|
611
|
+
title: "Make captions from the voice",
|
|
612
|
+
description: "Makes captions from voice clips (default: every voice clip), placed at their time and grouped into short lines; replaces the captions lying in those clips' time. With the script (text: one per clip, in order) the free local pause detection times it; otherwise a transcription adapter (adapters_list). A remote adapter sends the audio to the service: the user confirms first.",
|
|
613
|
+
input: {
|
|
614
|
+
...projectArg, clips: z.array(text(100)).max(100).optional(), adapter: text(40).optional(), language: text(20).optional(),
|
|
615
|
+
text: z.union([text(8000), z.array(text(8000)).max(100)]).optional().describe("What is said: one text, or one per clip"),
|
|
616
|
+
replace: z.boolean().optional().describe("false: refuse when captions already cover a clip"),
|
|
617
|
+
...confirmedArg,
|
|
618
|
+
},
|
|
619
|
+
}, async ({ project: p, confirmed, ...input }) => {
|
|
620
|
+
const dir = await project(p);
|
|
621
|
+
const adapter = core.adapterFor(dir, "transcribe", input.adapter, input.text !== undefined);
|
|
622
|
+
if (core.isRemote(adapter))
|
|
623
|
+
await confirm(`Transcribe the voice clips with ${adapter.name}? The audio is sent to the service (${adapter.cost}).`, confirmed);
|
|
624
|
+
const r = await core.transcribeCaptions(dir, { ...clean(input), adapter: adapter.id });
|
|
625
|
+
return { ok: true, ...r.result, version: r.version };
|
|
626
|
+
});
|
|
627
|
+
// ---- notes ---------------------------------------------------------------------------------
|
|
628
|
+
tool("notes_list", {
|
|
629
|
+
title: "List correction notes",
|
|
630
|
+
description: "Lists the correction notes the user placed on the video (default: open ones), with their time range, frame region, and the scenes, captions and clips they cover. Treat each open note as a request: fix it, then note_resolve.",
|
|
631
|
+
input: { ...projectArg, status: z.enum(["open", "done", "validated"]).optional() },
|
|
632
|
+
readOnly: true,
|
|
633
|
+
}, async ({ project: p, status }) => ({ ok: true, notes: core.listNotes(await project(p), { status: status ?? "open" }) }));
|
|
634
|
+
tool("note_add", {
|
|
635
|
+
title: "Add a correction note",
|
|
636
|
+
description: "Places a correction note on a stretch of the video (from, to in seconds), optionally on a region of the frame.",
|
|
637
|
+
input: {
|
|
638
|
+
...projectArg, from: seconds, to: seconds, text: text(2000),
|
|
639
|
+
region: z.object({ x: z.number(), y: z.number(), w: z.number().positive(), h: z.number().positive() }).optional(),
|
|
640
|
+
},
|
|
641
|
+
}, async ({ project: p, ...note }) => {
|
|
642
|
+
const r = core.addNote(await project(p), note);
|
|
643
|
+
return { ok: true, note: r.result, version: r.version };
|
|
644
|
+
});
|
|
645
|
+
tool("note_resolve", {
|
|
646
|
+
title: "Mark a note done",
|
|
647
|
+
description: "Marks an open note done, with what was changed (the user then validates or reopens it). Attach the path of a snapshot showing the fix when you have one.",
|
|
648
|
+
input: { ...projectArg, id: text(100), resolution: text(2000), snapshot: text(1000).optional().describe("Snapshot path, relative to the project") },
|
|
649
|
+
}, async ({ project: p, id, resolution, snapshot }) => {
|
|
650
|
+
const r = core.resolveNote(await project(p), id, resolution, snapshot);
|
|
651
|
+
return { ok: true, note: r.result, version: r.version };
|
|
652
|
+
});
|
|
653
|
+
// ---- check, look, render -------------------------------------------------------------------
|
|
654
|
+
tool("check", {
|
|
655
|
+
title: "Check before rendering",
|
|
656
|
+
description: "Checks the project: validity, media, network and non-deterministic code, then the engine's own checks (runtime errors, layout, TikTok/Reels/Shorts safe zones, contrast, text size). Errors block a render; read the warnings too. Can take a minute.",
|
|
657
|
+
input: { ...projectArg, ...formatArg, at: z.array(seconds).max(20).optional().describe("Extra times to inspect"), static: z.boolean().optional().describe("Only the checks that need no browser (fast)") },
|
|
658
|
+
readOnly: true,
|
|
659
|
+
}, async ({ project: p, at, static: staticOnly, format }) => {
|
|
660
|
+
const dir = await project(p);
|
|
661
|
+
const variant = format ? { variant: format } : {};
|
|
662
|
+
if (staticOnly)
|
|
663
|
+
return core.check(dir, { staticOnly: true, ...variant });
|
|
664
|
+
return exclusive("check", () => engine.check(dir, { ...variant, ...(at ? { at } : {}), ...(opts.mode ? { mode: opts.mode } : {}) }));
|
|
665
|
+
});
|
|
666
|
+
tool("snapshot", {
|
|
667
|
+
title: "Look at frames",
|
|
668
|
+
description: "Renders still frames at the given times and returns them as images (plus their paths in exports/snapshots/), to check a change visually. Takes 10 to 60 seconds.",
|
|
669
|
+
input: { ...projectArg, ...formatArg, at: z.array(seconds).min(1).max(8) },
|
|
670
|
+
readOnly: true,
|
|
671
|
+
}, async ({ project: p, at, format }) => {
|
|
672
|
+
const dir = await project(p);
|
|
673
|
+
const r = await exclusive("snapshot", () => engine.snapshot(dir, at, { ...(opts.mode ? { mode: opts.mode } : {}), ...(format ? { variant: format } : {}) }));
|
|
674
|
+
const images = r.files.map((f) => image(join(dir, f.path)));
|
|
675
|
+
return {
|
|
676
|
+
content: [
|
|
677
|
+
{ type: "text", text: JSON.stringify({ ok: true, ...r }, null, 1) },
|
|
678
|
+
...images.filter((x) => !!x).map((x) => ({ type: "image", ...x })),
|
|
679
|
+
],
|
|
680
|
+
};
|
|
681
|
+
}, true);
|
|
682
|
+
function startJob(dir, kind, ro) {
|
|
683
|
+
if (busy || waiting)
|
|
684
|
+
throw engineBusy();
|
|
685
|
+
busy = kind;
|
|
686
|
+
const job = { kind, project: dir, started: Date.now(), promise: Promise.resolve() };
|
|
687
|
+
job.promise = engine.render(dir, { ...ro, ...(opts.mode ? { mode: opts.mode } : {}) })
|
|
688
|
+
.then((r) => { job.done = r; })
|
|
689
|
+
.catch((e) => { job.error = errorBody(e); })
|
|
690
|
+
.finally(() => { busy = null; });
|
|
691
|
+
jobs.set(dir, job);
|
|
692
|
+
return job;
|
|
693
|
+
}
|
|
694
|
+
async function jobAnswer(dir, job) {
|
|
695
|
+
if (job && !job.done && !job.error)
|
|
696
|
+
await Promise.race([job.promise, new Promise((r) => setTimeout(r, waitMs))]);
|
|
697
|
+
const status = core.renderStatus(dir);
|
|
698
|
+
if (job?.error)
|
|
699
|
+
return { ok: false, state: "failed", ...job.error };
|
|
700
|
+
if (job?.done) {
|
|
701
|
+
const r = job.done;
|
|
702
|
+
return { ok: r.mismatches.length === 0, state: "done", ...r, path: join(dir, r.output), url: fileUrl(join(dir, r.output)) };
|
|
703
|
+
}
|
|
704
|
+
return { ok: true, state: status?.state ?? "none", progress: status?.progress ?? 0, ...(status ? { status } : {}), next: status?.state === "running" ? "call render_status again in about 30 seconds" : undefined };
|
|
705
|
+
}
|
|
706
|
+
tool("preview_generate", {
|
|
707
|
+
title: "Quick low-quality render",
|
|
708
|
+
description: "Renders a draft-quality MP4 of the whole video or of a part (start, end), to watch a change quickly. Runs in the background: if it is not done within ~40 s, follow it with render_status.",
|
|
709
|
+
input: { ...projectArg, ...formatArg, start: seconds.optional(), end: seconds.optional() },
|
|
710
|
+
}, async ({ project: p, start, end, format }) => {
|
|
711
|
+
const dir = await project(p);
|
|
712
|
+
const job = startJob(dir, "preview", { quality: "draft", ...(format ? { variant: format } : {}), ...(start !== undefined ? { start } : {}), ...(end !== undefined ? { end } : {}) });
|
|
713
|
+
return jobAnswer(dir, job);
|
|
714
|
+
});
|
|
715
|
+
tool("render_start", {
|
|
716
|
+
title: "Render the video",
|
|
717
|
+
description: "Renders the final MP4 into exports/ without network access, after the user confirms (it takes minutes and a lot of CPU). Run check first. Runs in the background: follow it with render_status until state is done, then report the file.",
|
|
718
|
+
input: { ...projectArg, ...formatArg, quality: z.enum(["draft", "standard", "high"]).optional(), ...confirmedArg },
|
|
719
|
+
openWorld: false,
|
|
720
|
+
}, async ({ project: p, quality, confirmed, format }) => {
|
|
721
|
+
const dir = await project(p);
|
|
722
|
+
const v = core.describe(dir);
|
|
723
|
+
const formats = core.listFormats(dir);
|
|
724
|
+
const f = formats.find((x) => (format ? x.id === format : x.main));
|
|
725
|
+
if (!f)
|
|
726
|
+
throw new DerushlyError("not_found", `unknown format "${format}" (formats: ${formats.map((x) => x.id).join(", ")})`);
|
|
727
|
+
await confirm(`Render "${v.name}" (${f.ratio}, ${f.width}x${f.height}, ${v.composition.duration}s, quality ${quality ?? "standard"})? It takes a few minutes.`, confirmed);
|
|
728
|
+
const job = startJob(dir, "render", { quality: quality ?? "standard", ...(format ? { variant: format } : {}) });
|
|
729
|
+
return jobAnswer(dir, job);
|
|
730
|
+
});
|
|
731
|
+
tool("render_status", {
|
|
732
|
+
title: "Follow a render",
|
|
733
|
+
description: "State of the project's current or last render or preview: running with its progress, done with the file and its check (size, duration, audio), or failed with the engine's error. Waits up to ~40 s for a running render to finish.",
|
|
734
|
+
input: projectArg,
|
|
735
|
+
readOnly: true,
|
|
736
|
+
}, async ({ project: p }) => {
|
|
737
|
+
const dir = await project(p);
|
|
738
|
+
return jobAnswer(dir, jobs.get(dir));
|
|
739
|
+
});
|
|
740
|
+
tool("export_get", {
|
|
741
|
+
title: "Get the rendered files",
|
|
742
|
+
description: "Lists the finished renders and previews in exports/, newest first, with their path, file:// link, size, duration, resolution and audio.",
|
|
743
|
+
input: { ...projectArg, limit: z.number().int().min(1).max(50).optional() },
|
|
744
|
+
readOnly: true,
|
|
745
|
+
}, async ({ project: p, limit }) => {
|
|
746
|
+
const dir = await project(p);
|
|
747
|
+
const ex = join(dir, core.EXPORTS_DIR);
|
|
748
|
+
const files = existsSync(ex) ? readdirSync(ex).filter((f) => f.toLowerCase().endsWith(".mp4")) : [];
|
|
749
|
+
const list = files.map((f) => ({ f, t: statSync(join(ex, f)).mtimeMs })).sort((a, b) => b.t - a.t).slice(0, limit ?? 10).map(({ f, t }) => {
|
|
750
|
+
const path = join(ex, f);
|
|
751
|
+
return { file: `${core.EXPORTS_DIR}/${f}`, path, url: fileUrl(path), bytes: statSync(path).size, modified: new Date(t).toISOString(), ...(core.probe(path) ?? {}) };
|
|
752
|
+
});
|
|
753
|
+
return { ok: true, exports: list };
|
|
754
|
+
});
|
|
755
|
+
tool("export_frames", {
|
|
756
|
+
title: "Look at a rendered video",
|
|
757
|
+
description: "Extracts still frames from a rendered MP4 of exports/ (file as export_get gives it) at the given times and returns them as images, to check the final file itself after render_status says done. Takes a few seconds; snapshot looks at the project instead.",
|
|
758
|
+
input: { ...projectArg, file: text(500).describe("Rendered file, relative to the project, such as exports/x.mp4"), at: z.array(seconds).min(1).max(8) },
|
|
759
|
+
readOnly: true,
|
|
760
|
+
}, async ({ project: p, file, at }) => {
|
|
761
|
+
const dir = await project(p);
|
|
762
|
+
const r = core.exportFrames(dir, file, at);
|
|
763
|
+
const images = r.files.map((f) => image(join(dir, f.path)));
|
|
764
|
+
return {
|
|
765
|
+
content: [
|
|
766
|
+
{ type: "text", text: JSON.stringify({ ok: true, ...r }, null, 1) },
|
|
767
|
+
...images.filter((x) => !!x).map((x) => ({ type: "image", ...x })),
|
|
768
|
+
],
|
|
769
|
+
};
|
|
770
|
+
}, true);
|
|
771
|
+
// ---- editor --------------------------------------------------------------------------------
|
|
772
|
+
const editors = new Map();
|
|
773
|
+
tool("editor_open", {
|
|
774
|
+
title: "Open the local editor",
|
|
775
|
+
description: "Opens the project in Derushly's local editor (a page on 127.0.0.1: preview in each format with safe zones, timeline, texts, captions, audio, notes, renders) and returns a one-time link. Give the link to the user. The editor and the tools change the same folder: the page follows your changes, and notes the user places there appear in notes_list.",
|
|
776
|
+
input: { ...projectArg, open: z.boolean().optional().describe("Also open it in the default browser (default true)") },
|
|
777
|
+
}, async ({ project: p, open }) => {
|
|
778
|
+
const dir = await project(p);
|
|
779
|
+
let ed = editors.get(dir);
|
|
780
|
+
let url;
|
|
781
|
+
if (ed)
|
|
782
|
+
url = ed.newLink();
|
|
783
|
+
else {
|
|
784
|
+
ed = await startEditor({ project: dir, ...(opts.mode ? { mode: opts.mode } : {}) });
|
|
785
|
+
editors.set(dir, ed);
|
|
786
|
+
url = ed.url;
|
|
787
|
+
}
|
|
788
|
+
if (open !== false && opts.openBrowser !== false)
|
|
789
|
+
openInBrowser(url);
|
|
790
|
+
return { ok: true, url, note: "One-time link: call editor_open again for a new one. The editor stops with this server." };
|
|
791
|
+
});
|
|
792
|
+
const closed = server.server.onclose;
|
|
793
|
+
server.server.onclose = () => {
|
|
794
|
+
for (const ed of editors.values())
|
|
795
|
+
void ed.close();
|
|
796
|
+
editors.clear();
|
|
797
|
+
closed?.();
|
|
798
|
+
};
|
|
799
|
+
tool("doctor", {
|
|
800
|
+
title: "Check the machine",
|
|
801
|
+
description: "Checks what this machine has for rendering (Node, FFmpeg, the pinned HyperFrames engine and its browser, Docker and the isolated render image) and says how to fix what is missing. fix: \"local\" installs the engine, fix: \"docker\" builds the image; both download files once and ask the user first.",
|
|
802
|
+
input: { fix: z.enum(["local", "docker"]).optional(), ...confirmedArg },
|
|
803
|
+
openWorld: true,
|
|
804
|
+
}, async ({ fix, confirmed }) => {
|
|
805
|
+
if (fix)
|
|
806
|
+
await confirm(fix === "docker" ? "Build the Derushly render image with Docker (downloads about 1 GB once)?" : "Install the HyperFrames render engine and its browser (downloads about 300 MB once)?", confirmed);
|
|
807
|
+
return exclusive("doctor", async () => core.doctor({ ...(fix ? { fix: true, docker: fix === "docker" } : {}) }));
|
|
808
|
+
});
|
|
809
|
+
return server;
|
|
810
|
+
}
|
|
811
|
+
/** A frame for the agent to look at: scaled to 540 px wide as JPEG when FFmpeg is there. */
|
|
812
|
+
function image(path) {
|
|
813
|
+
if (!existsSync(path))
|
|
814
|
+
return null;
|
|
815
|
+
const ffmpeg = process.env.DERUSHLY_FFMPEG || "ffmpeg";
|
|
816
|
+
const r = spawnSync(ffmpeg, ["-v", "error", "-i", path, "-vf", "scale=540:-2", "-q:v", "4", "-f", "image2pipe", "-vcodec", "mjpeg", "-"], { windowsHide: true, maxBuffer: 16 * 1024 * 1024, timeout: 20_000 });
|
|
817
|
+
if (r.status === 0 && r.stdout.length)
|
|
818
|
+
return { data: r.stdout.toString("base64"), mimeType: "image/jpeg" };
|
|
819
|
+
return { data: readFileSync(path).toString("base64"), mimeType: "image/png" };
|
|
820
|
+
}
|
|
821
|
+
//# sourceMappingURL=server.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,50 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@derushly/mcp",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Derushly MCP server (stdio)",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"mcp",
|
|
7
|
+
"model-context-protocol",
|
|
8
|
+
"hyperframes",
|
|
9
|
+
"video",
|
|
10
|
+
"agent"
|
|
11
|
+
],
|
|
12
|
+
"license": "Apache-2.0",
|
|
13
|
+
"author": "Auxilh",
|
|
14
|
+
"homepage": "https://github.com/Auxilh/derushly#readme",
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/Auxilh/derushly/issues"
|
|
17
|
+
},
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/Auxilh/derushly.git",
|
|
21
|
+
"directory": "packages/mcp"
|
|
22
|
+
},
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=22"
|
|
25
|
+
},
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public"
|
|
28
|
+
},
|
|
29
|
+
"type": "module",
|
|
30
|
+
"main": "./dist/index.js",
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"bin": {
|
|
33
|
+
"derushly-mcp": "./dist/main.js"
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"dist",
|
|
37
|
+
"!dist/**/*.map",
|
|
38
|
+
"NOTICE",
|
|
39
|
+
"README.md"
|
|
40
|
+
],
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@derushly/core": "0.1.0",
|
|
43
|
+
"@modelcontextprotocol/sdk": "1.32.2",
|
|
44
|
+
"zod": "4.6.7",
|
|
45
|
+
"@derushly/editor": "0.1.0"
|
|
46
|
+
},
|
|
47
|
+
"scripts": {
|
|
48
|
+
"prepack": "node ../../scripts/prepack.mjs"
|
|
49
|
+
}
|
|
50
|
+
}
|