@vibeframe/cli 0.27.0 → 0.30.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.
Files changed (118) hide show
  1. package/LICENSE +21 -0
  2. package/dist/agent/adapters/index.d.ts +1 -0
  3. package/dist/agent/adapters/index.d.ts.map +1 -1
  4. package/dist/agent/adapters/index.js +5 -0
  5. package/dist/agent/adapters/index.js.map +1 -1
  6. package/dist/agent/adapters/openrouter.d.ts +16 -0
  7. package/dist/agent/adapters/openrouter.d.ts.map +1 -0
  8. package/dist/agent/adapters/openrouter.js +100 -0
  9. package/dist/agent/adapters/openrouter.js.map +1 -0
  10. package/dist/agent/types.d.ts +1 -1
  11. package/dist/agent/types.d.ts.map +1 -1
  12. package/dist/commands/agent.d.ts.map +1 -1
  13. package/dist/commands/agent.js +3 -1
  14. package/dist/commands/agent.js.map +1 -1
  15. package/dist/commands/ai-edit-cli.d.ts.map +1 -1
  16. package/dist/commands/ai-edit-cli.js +18 -0
  17. package/dist/commands/ai-edit-cli.js.map +1 -1
  18. package/dist/commands/generate.js +14 -0
  19. package/dist/commands/generate.js.map +1 -1
  20. package/dist/commands/schema.d.ts +1 -0
  21. package/dist/commands/schema.d.ts.map +1 -1
  22. package/dist/commands/schema.js +122 -21
  23. package/dist/commands/schema.js.map +1 -1
  24. package/dist/commands/setup.js +5 -2
  25. package/dist/commands/setup.js.map +1 -1
  26. package/dist/config/schema.d.ts +2 -1
  27. package/dist/config/schema.d.ts.map +1 -1
  28. package/dist/config/schema.js +2 -0
  29. package/dist/config/schema.js.map +1 -1
  30. package/dist/index.js +0 -0
  31. package/package.json +16 -12
  32. package/.turbo/turbo-build.log +0 -4
  33. package/.turbo/turbo-lint.log +0 -21
  34. package/.turbo/turbo-test.log +0 -689
  35. package/src/agent/adapters/claude.ts +0 -143
  36. package/src/agent/adapters/gemini.ts +0 -159
  37. package/src/agent/adapters/index.ts +0 -61
  38. package/src/agent/adapters/ollama.ts +0 -231
  39. package/src/agent/adapters/openai.ts +0 -116
  40. package/src/agent/adapters/xai.ts +0 -119
  41. package/src/agent/index.ts +0 -251
  42. package/src/agent/memory/index.ts +0 -151
  43. package/src/agent/prompts/system.ts +0 -106
  44. package/src/agent/tools/ai-editing.ts +0 -845
  45. package/src/agent/tools/ai-generation.ts +0 -1073
  46. package/src/agent/tools/ai-pipeline.ts +0 -1055
  47. package/src/agent/tools/ai.ts +0 -21
  48. package/src/agent/tools/batch.ts +0 -429
  49. package/src/agent/tools/e2e.test.ts +0 -545
  50. package/src/agent/tools/export.ts +0 -184
  51. package/src/agent/tools/filesystem.ts +0 -237
  52. package/src/agent/tools/index.ts +0 -150
  53. package/src/agent/tools/integration.test.ts +0 -775
  54. package/src/agent/tools/media.ts +0 -697
  55. package/src/agent/tools/project.ts +0 -313
  56. package/src/agent/tools/timeline.ts +0 -951
  57. package/src/agent/types.ts +0 -68
  58. package/src/commands/agent.ts +0 -340
  59. package/src/commands/ai-analyze.ts +0 -429
  60. package/src/commands/ai-animated-caption.ts +0 -390
  61. package/src/commands/ai-audio.ts +0 -941
  62. package/src/commands/ai-broll.ts +0 -490
  63. package/src/commands/ai-edit-cli.ts +0 -658
  64. package/src/commands/ai-edit.ts +0 -1542
  65. package/src/commands/ai-fill-gaps.ts +0 -566
  66. package/src/commands/ai-helpers.ts +0 -65
  67. package/src/commands/ai-highlights.ts +0 -1303
  68. package/src/commands/ai-image.ts +0 -761
  69. package/src/commands/ai-motion.ts +0 -347
  70. package/src/commands/ai-narrate.ts +0 -451
  71. package/src/commands/ai-review.ts +0 -309
  72. package/src/commands/ai-script-pipeline-cli.ts +0 -1710
  73. package/src/commands/ai-script-pipeline.ts +0 -1365
  74. package/src/commands/ai-suggest-edit.ts +0 -264
  75. package/src/commands/ai-video-fx.ts +0 -445
  76. package/src/commands/ai-video.ts +0 -915
  77. package/src/commands/ai-viral.ts +0 -595
  78. package/src/commands/ai-visual-fx.ts +0 -601
  79. package/src/commands/ai.test.ts +0 -627
  80. package/src/commands/ai.ts +0 -307
  81. package/src/commands/analyze.ts +0 -282
  82. package/src/commands/audio.ts +0 -644
  83. package/src/commands/batch.test.ts +0 -279
  84. package/src/commands/batch.ts +0 -440
  85. package/src/commands/detect.ts +0 -329
  86. package/src/commands/doctor.ts +0 -237
  87. package/src/commands/edit-cmd.ts +0 -1014
  88. package/src/commands/export.ts +0 -918
  89. package/src/commands/generate.ts +0 -2146
  90. package/src/commands/media.ts +0 -177
  91. package/src/commands/output.ts +0 -142
  92. package/src/commands/pipeline.ts +0 -398
  93. package/src/commands/project.test.ts +0 -127
  94. package/src/commands/project.ts +0 -149
  95. package/src/commands/sanitize.ts +0 -60
  96. package/src/commands/schema.ts +0 -130
  97. package/src/commands/setup.ts +0 -509
  98. package/src/commands/timeline.test.ts +0 -499
  99. package/src/commands/timeline.ts +0 -529
  100. package/src/commands/validate.ts +0 -77
  101. package/src/config/config.test.ts +0 -197
  102. package/src/config/index.ts +0 -125
  103. package/src/config/schema.ts +0 -82
  104. package/src/engine/index.ts +0 -2
  105. package/src/engine/project.test.ts +0 -702
  106. package/src/engine/project.ts +0 -439
  107. package/src/index.ts +0 -146
  108. package/src/utils/api-key.test.ts +0 -41
  109. package/src/utils/api-key.ts +0 -247
  110. package/src/utils/audio.ts +0 -83
  111. package/src/utils/exec-safe.ts +0 -75
  112. package/src/utils/first-run.ts +0 -52
  113. package/src/utils/provider-resolver.ts +0 -56
  114. package/src/utils/remotion.ts +0 -951
  115. package/src/utils/subtitle.test.ts +0 -227
  116. package/src/utils/subtitle.ts +0 -169
  117. package/src/utils/tty.ts +0 -196
  118. package/tsconfig.json +0 -20
@@ -1,529 +0,0 @@
1
- import { Command } from "commander";
2
- import { readFile, writeFile } from "node:fs/promises";
3
- import { resolve, basename, extname } from "node:path";
4
- import chalk from "chalk";
5
- import ora from "ora";
6
- import { Project, type ProjectFile } from "../engine/index.js";
7
- import type { MediaType } from "@vibeframe/core/timeline";
8
- import { validateResourceId } from "./validate.js";
9
-
10
- export const timelineCommand = new Command("timeline")
11
- .description("Timeline editing commands");
12
-
13
- timelineCommand
14
- .command("add-source")
15
- .description("Add a media source to the project")
16
- .argument("<project>", "Project file path")
17
- .argument("<media>", "Media file path")
18
- .option("-n, --name <name>", "Source name (defaults to filename)")
19
- .option("-t, --type <type>", "Media type (video, audio, image)")
20
- .option("-d, --duration <seconds>", "Duration in seconds (required for images)")
21
- .action(async (projectPath: string, mediaPath: string, options) => {
22
- const spinner = ora("Adding source...").start();
23
-
24
- try {
25
- const filePath = resolve(process.cwd(), projectPath);
26
- const content = await readFile(filePath, "utf-8");
27
- const data: ProjectFile = JSON.parse(content);
28
- const project = Project.fromJSON(data);
29
-
30
- const absMediaPath = resolve(process.cwd(), mediaPath);
31
- const mediaName = options.name || basename(mediaPath);
32
- const mediaType = options.type || detectMediaType(mediaPath);
33
- const duration = parseFloat(options.duration) || 5; // Default 5s for images
34
-
35
- const source = project.addSource({
36
- name: mediaName,
37
- type: mediaType,
38
- url: absMediaPath,
39
- duration,
40
- });
41
-
42
- await writeFile(filePath, JSON.stringify(project.toJSON(), null, 2), "utf-8");
43
-
44
- spinner.succeed(chalk.green(`Source added: ${source.id}`));
45
- console.log();
46
- console.log(chalk.dim(" Name:"), mediaName);
47
- console.log(chalk.dim(" Type:"), mediaType);
48
- console.log(chalk.dim(" Path:"), absMediaPath);
49
- console.log(chalk.dim(" Duration:"), duration, "s");
50
- } catch (error) {
51
- spinner.fail(chalk.red("Failed to add source"));
52
- console.error(error);
53
- process.exit(1);
54
- }
55
- });
56
-
57
- timelineCommand
58
- .command("add-clip")
59
- .description("Add a clip to the timeline")
60
- .argument("<project>", "Project file path")
61
- .argument("<source-id>", "Source ID to use")
62
- .option("-t, --track <id>", "Track ID (defaults to first matching track)")
63
- .option("-s, --start <seconds>", "Start time in timeline", "0")
64
- .option("-d, --duration <seconds>", "Clip duration (defaults to source duration)")
65
- .option("--offset <seconds>", "Source start offset", "0")
66
- .action(async (projectPath: string, sourceId: string, options) => {
67
- const spinner = ora("Adding clip...").start();
68
-
69
- try {
70
- validateResourceId(sourceId);
71
- if (options.track) validateResourceId(options.track);
72
-
73
- const filePath = resolve(process.cwd(), projectPath);
74
- const content = await readFile(filePath, "utf-8");
75
- const data: ProjectFile = JSON.parse(content);
76
- const project = Project.fromJSON(data);
77
-
78
- const source = project.getSource(sourceId);
79
- if (!source) {
80
- spinner.fail(chalk.red(`Source not found: ${sourceId}`));
81
- process.exit(1);
82
- }
83
-
84
- // Find track (images use video track, like REPL does)
85
- let trackId = options.track;
86
- if (!trackId) {
87
- const trackType = source.type === "audio" ? "audio" : "video";
88
- const tracks = project.getTracksByType(trackType);
89
- if (tracks.length === 0) {
90
- spinner.fail(chalk.red(`No ${trackType} track found. Create one first.`));
91
- process.exit(1);
92
- }
93
- trackId = tracks[0].id;
94
- }
95
-
96
- const startTime = parseFloat(options.start);
97
- const sourceOffset = parseFloat(options.offset);
98
- const duration = options.duration ? parseFloat(options.duration) : source.duration;
99
-
100
- const clip = project.addClip({
101
- sourceId,
102
- trackId,
103
- startTime,
104
- duration,
105
- sourceStartOffset: sourceOffset,
106
- sourceEndOffset: sourceOffset + duration,
107
- });
108
-
109
- await writeFile(filePath, JSON.stringify(project.toJSON(), null, 2), "utf-8");
110
-
111
- spinner.succeed(chalk.green(`Clip added: ${clip.id}`));
112
- console.log();
113
- console.log(chalk.dim(" Source:"), source.name);
114
- console.log(chalk.dim(" Track:"), trackId);
115
- console.log(chalk.dim(" Start:"), startTime, "s");
116
- console.log(chalk.dim(" Duration:"), duration, "s");
117
- } catch (error) {
118
- spinner.fail(chalk.red("Failed to add clip"));
119
- console.error(error);
120
- process.exit(1);
121
- }
122
- });
123
-
124
- timelineCommand
125
- .command("add-track")
126
- .description("Add a new track")
127
- .argument("<project>", "Project file path")
128
- .argument("<type>", "Track type (video, audio)")
129
- .option("-n, --name <name>", "Track name")
130
- .action(async (projectPath: string, type: string, options) => {
131
- const spinner = ora("Adding track...").start();
132
-
133
- try {
134
- const filePath = resolve(process.cwd(), projectPath);
135
- const content = await readFile(filePath, "utf-8");
136
- const data: ProjectFile = JSON.parse(content);
137
- const project = Project.fromJSON(data);
138
-
139
- const existingTracks = project.getTracksByType(type as MediaType);
140
- const trackName = options.name || `${type.charAt(0).toUpperCase() + type.slice(1)} ${existingTracks.length + 1}`;
141
- const order = project.getTracks().length;
142
-
143
- const track = project.addTrack({
144
- name: trackName,
145
- type: type as MediaType,
146
- order,
147
- isMuted: false,
148
- isLocked: false,
149
- isVisible: true,
150
- });
151
-
152
- await writeFile(filePath, JSON.stringify(project.toJSON(), null, 2), "utf-8");
153
-
154
- spinner.succeed(chalk.green(`Track added: ${track.id}`));
155
- console.log();
156
- console.log(chalk.dim(" Name:"), track.name);
157
- console.log(chalk.dim(" Type:"), track.type);
158
- } catch (error) {
159
- spinner.fail(chalk.red("Failed to add track"));
160
- console.error(error);
161
- process.exit(1);
162
- }
163
- });
164
-
165
- timelineCommand
166
- .command("add-effect")
167
- .description("Add an effect to a clip")
168
- .argument("<project>", "Project file path")
169
- .argument("<clip-id>", "Clip ID")
170
- .argument("<effect-type>", "Effect type (fadeIn, fadeOut, blur, brightness, contrast, saturation, speed, volume)")
171
- .option("-s, --start <seconds>", "Effect start time (relative to clip)", "0")
172
- .option("-d, --duration <seconds>", "Effect duration (defaults to clip duration)")
173
- .option("-p, --params <json>", "Effect parameters as JSON", "{}")
174
- .action(async (projectPath: string, clipId: string, effectType: string, options) => {
175
- const spinner = ora("Adding effect...").start();
176
-
177
- try {
178
- validateResourceId(clipId);
179
-
180
- const filePath = resolve(process.cwd(), projectPath);
181
- const content = await readFile(filePath, "utf-8");
182
- const data: ProjectFile = JSON.parse(content);
183
- const project = Project.fromJSON(data);
184
-
185
- const clip = project.getClip(clipId);
186
- if (!clip) {
187
- spinner.fail(chalk.red(`Clip not found: ${clipId}`));
188
- process.exit(1);
189
- }
190
-
191
- const startTime = parseFloat(options.start);
192
- const duration = options.duration ? parseFloat(options.duration) : clip.duration;
193
- const params = JSON.parse(options.params);
194
-
195
- const effect = project.addEffect(clipId, {
196
- type: effectType as any,
197
- startTime,
198
- duration,
199
- params,
200
- });
201
-
202
- if (!effect) {
203
- spinner.fail(chalk.red("Failed to add effect"));
204
- process.exit(1);
205
- }
206
-
207
- await writeFile(filePath, JSON.stringify(project.toJSON(), null, 2), "utf-8");
208
-
209
- spinner.succeed(chalk.green(`Effect added: ${effect.id}`));
210
- console.log();
211
- console.log(chalk.dim(" Type:"), effectType);
212
- console.log(chalk.dim(" Start:"), startTime, "s");
213
- console.log(chalk.dim(" Duration:"), duration, "s");
214
- } catch (error) {
215
- spinner.fail(chalk.red("Failed to add effect"));
216
- console.error(error);
217
- process.exit(1);
218
- }
219
- });
220
-
221
- timelineCommand
222
- .command("trim")
223
- .description("Trim a clip")
224
- .argument("<project>", "Project file path")
225
- .argument("<clip-id>", "Clip ID")
226
- .option("--start <seconds>", "New start time")
227
- .option("--duration <seconds>", "New duration")
228
- .action(async (projectPath: string, clipId: string, options) => {
229
- const spinner = ora("Trimming clip...").start();
230
-
231
- try {
232
- validateResourceId(clipId);
233
-
234
- const filePath = resolve(process.cwd(), projectPath);
235
- const content = await readFile(filePath, "utf-8");
236
- const data: ProjectFile = JSON.parse(content);
237
- const project = Project.fromJSON(data);
238
-
239
- const clip = project.getClip(clipId);
240
- if (!clip) {
241
- spinner.fail(chalk.red(`Clip not found: ${clipId}`));
242
- process.exit(1);
243
- }
244
-
245
- if (options.start !== undefined) {
246
- project.trimClipStart(clipId, parseFloat(options.start));
247
- }
248
- if (options.duration !== undefined) {
249
- project.trimClipEnd(clipId, parseFloat(options.duration));
250
- }
251
-
252
- await writeFile(filePath, JSON.stringify(project.toJSON(), null, 2), "utf-8");
253
-
254
- const updatedClip = project.getClip(clipId)!;
255
- spinner.succeed(chalk.green("Clip trimmed"));
256
- console.log();
257
- console.log(chalk.dim(" Start:"), updatedClip.startTime, "s");
258
- console.log(chalk.dim(" Duration:"), updatedClip.duration, "s");
259
- } catch (error) {
260
- spinner.fail(chalk.red("Failed to trim clip"));
261
- console.error(error);
262
- process.exit(1);
263
- }
264
- });
265
-
266
- timelineCommand
267
- .command("list")
268
- .description("List timeline contents")
269
- .argument("<project>", "Project file path")
270
- .option("--sources", "List sources only")
271
- .option("--tracks", "List tracks only")
272
- .option("--clips", "List clips only")
273
- .action(async (projectPath: string, options) => {
274
- try {
275
- const filePath = resolve(process.cwd(), projectPath);
276
- const content = await readFile(filePath, "utf-8");
277
- const data: ProjectFile = JSON.parse(content);
278
- const project = Project.fromJSON(data);
279
-
280
- const showAll = !options.sources && !options.tracks && !options.clips;
281
-
282
- if (showAll || options.sources) {
283
- console.log();
284
- console.log(chalk.bold.cyan("Sources"));
285
- console.log(chalk.dim("─".repeat(60)));
286
- const sources = project.getSources();
287
- if (sources.length === 0) {
288
- console.log(chalk.dim(" (none)"));
289
- } else {
290
- for (const source of sources) {
291
- console.log(` ${chalk.yellow(source.id)}`);
292
- console.log(` ${source.name} (${source.type}, ${source.duration}s)`);
293
- }
294
- }
295
- }
296
-
297
- if (showAll || options.tracks) {
298
- console.log();
299
- console.log(chalk.bold.cyan("Tracks"));
300
- console.log(chalk.dim("─".repeat(60)));
301
- const tracks = project.getTracks();
302
- for (const track of tracks) {
303
- const status = [
304
- track.isMuted ? "muted" : null,
305
- track.isLocked ? "locked" : null,
306
- !track.isVisible ? "hidden" : null,
307
- ].filter(Boolean).join(", ");
308
- console.log(` ${chalk.yellow(track.id)}`);
309
- console.log(` ${track.name} (${track.type})${status ? ` [${status}]` : ""}`);
310
- }
311
- }
312
-
313
- if (showAll || options.clips) {
314
- console.log();
315
- console.log(chalk.bold.cyan("Clips"));
316
- console.log(chalk.dim("─".repeat(60)));
317
- const clips = project.getClips();
318
- if (clips.length === 0) {
319
- console.log(chalk.dim(" (none)"));
320
- } else {
321
- for (const clip of clips) {
322
- const source = project.getSource(clip.sourceId);
323
- console.log(` ${chalk.yellow(clip.id)}`);
324
- console.log(` ${source?.name || "unknown"} @ ${clip.startTime}s (${clip.duration}s)`);
325
- if (clip.effects.length > 0) {
326
- console.log(` Effects: ${clip.effects.map((e) => e.type).join(", ")}`);
327
- }
328
- }
329
- }
330
- }
331
-
332
- console.log();
333
- } catch (error) {
334
- console.error(chalk.red("Failed to list timeline"));
335
- console.error(error);
336
- process.exit(1);
337
- }
338
- });
339
-
340
- timelineCommand
341
- .command("split")
342
- .description("Split a clip at a specific time")
343
- .argument("<project>", "Project file path")
344
- .argument("<clip-id>", "Clip ID to split")
345
- .option("-t, --time <seconds>", "Split time relative to clip start", "0")
346
- .action(async (projectPath: string, clipId: string, options) => {
347
- const spinner = ora("Splitting clip...").start();
348
-
349
- try {
350
- validateResourceId(clipId);
351
-
352
- const filePath = resolve(process.cwd(), projectPath);
353
- const content = await readFile(filePath, "utf-8");
354
- const data: ProjectFile = JSON.parse(content);
355
- const project = Project.fromJSON(data);
356
-
357
- const clip = project.getClip(clipId);
358
- if (!clip) {
359
- spinner.fail(chalk.red(`Clip not found: ${clipId}`));
360
- process.exit(1);
361
- }
362
-
363
- const splitTime = parseFloat(options.time);
364
- if (splitTime <= 0 || splitTime >= clip.duration) {
365
- spinner.fail(chalk.red(`Invalid split time. Must be between 0 and ${clip.duration}s`));
366
- process.exit(1);
367
- }
368
-
369
- const result = project.splitClip(clipId, splitTime);
370
- if (!result) {
371
- spinner.fail(chalk.red("Failed to split clip"));
372
- process.exit(1);
373
- }
374
-
375
- await writeFile(filePath, JSON.stringify(project.toJSON(), null, 2), "utf-8");
376
-
377
- const [first, second] = result;
378
- spinner.succeed(chalk.green("Clip split successfully"));
379
- console.log();
380
- console.log(chalk.dim(" First clip:"), first.id, `(${first.duration.toFixed(2)}s)`);
381
- console.log(chalk.dim(" Second clip:"), second.id, `(${second.duration.toFixed(2)}s)`);
382
- } catch (error) {
383
- spinner.fail(chalk.red("Failed to split clip"));
384
- console.error(error);
385
- process.exit(1);
386
- }
387
- });
388
-
389
- timelineCommand
390
- .command("duplicate")
391
- .description("Duplicate a clip")
392
- .argument("<project>", "Project file path")
393
- .argument("<clip-id>", "Clip ID to duplicate")
394
- .option("-t, --time <seconds>", "Start time for duplicate (default: after original)")
395
- .action(async (projectPath: string, clipId: string, options) => {
396
- const spinner = ora("Duplicating clip...").start();
397
-
398
- try {
399
- validateResourceId(clipId);
400
-
401
- const filePath = resolve(process.cwd(), projectPath);
402
- const content = await readFile(filePath, "utf-8");
403
- const data: ProjectFile = JSON.parse(content);
404
- const project = Project.fromJSON(data);
405
-
406
- const clip = project.getClip(clipId);
407
- if (!clip) {
408
- spinner.fail(chalk.red(`Clip not found: ${clipId}`));
409
- process.exit(1);
410
- }
411
-
412
- const offsetTime = options.time ? parseFloat(options.time) : undefined;
413
- const duplicated = project.duplicateClip(clipId, offsetTime);
414
-
415
- if (!duplicated) {
416
- spinner.fail(chalk.red("Failed to duplicate clip"));
417
- process.exit(1);
418
- }
419
-
420
- await writeFile(filePath, JSON.stringify(project.toJSON(), null, 2), "utf-8");
421
-
422
- spinner.succeed(chalk.green(`Clip duplicated: ${duplicated.id}`));
423
- console.log();
424
- console.log(chalk.dim(" Start:"), duplicated.startTime, "s");
425
- console.log(chalk.dim(" Duration:"), duplicated.duration, "s");
426
- } catch (error) {
427
- spinner.fail(chalk.red("Failed to duplicate clip"));
428
- console.error(error);
429
- process.exit(1);
430
- }
431
- });
432
-
433
- timelineCommand
434
- .command("delete")
435
- .description("Delete a clip from the timeline")
436
- .argument("<project>", "Project file path")
437
- .argument("<clip-id>", "Clip ID to delete")
438
- .action(async (projectPath: string, clipId: string) => {
439
- const spinner = ora("Deleting clip...").start();
440
-
441
- try {
442
- validateResourceId(clipId);
443
-
444
- const filePath = resolve(process.cwd(), projectPath);
445
- const content = await readFile(filePath, "utf-8");
446
- const data: ProjectFile = JSON.parse(content);
447
- const project = Project.fromJSON(data);
448
-
449
- const clip = project.getClip(clipId);
450
- if (!clip) {
451
- spinner.fail(chalk.red(`Clip not found: ${clipId}`));
452
- process.exit(1);
453
- }
454
-
455
- const removed = project.removeClip(clipId);
456
- if (!removed) {
457
- spinner.fail(chalk.red("Failed to delete clip"));
458
- process.exit(1);
459
- }
460
-
461
- await writeFile(filePath, JSON.stringify(project.toJSON(), null, 2), "utf-8");
462
-
463
- spinner.succeed(chalk.green("Clip deleted"));
464
- } catch (error) {
465
- spinner.fail(chalk.red("Failed to delete clip"));
466
- console.error(error);
467
- process.exit(1);
468
- }
469
- });
470
-
471
- timelineCommand
472
- .command("move")
473
- .description("Move a clip to a new position")
474
- .argument("<project>", "Project file path")
475
- .argument("<clip-id>", "Clip ID to move")
476
- .option("-t, --time <seconds>", "New start time")
477
- .option("--track <track-id>", "Move to different track")
478
- .action(async (projectPath: string, clipId: string, options) => {
479
- const spinner = ora("Moving clip...").start();
480
-
481
- try {
482
- validateResourceId(clipId);
483
- if (options.track) validateResourceId(options.track);
484
-
485
- const filePath = resolve(process.cwd(), projectPath);
486
- const content = await readFile(filePath, "utf-8");
487
- const data: ProjectFile = JSON.parse(content);
488
- const project = Project.fromJSON(data);
489
-
490
- const clip = project.getClip(clipId);
491
- if (!clip) {
492
- spinner.fail(chalk.red(`Clip not found: ${clipId}`));
493
- process.exit(1);
494
- }
495
-
496
- const newTime = options.time !== undefined ? parseFloat(options.time) : clip.startTime;
497
- const newTrack = options.track || clip.trackId;
498
-
499
- const moved = project.moveClip(clipId, newTrack, newTime);
500
- if (!moved) {
501
- spinner.fail(chalk.red("Failed to move clip"));
502
- process.exit(1);
503
- }
504
-
505
- await writeFile(filePath, JSON.stringify(project.toJSON(), null, 2), "utf-8");
506
-
507
- const updated = project.getClip(clipId)!;
508
- spinner.succeed(chalk.green("Clip moved"));
509
- console.log();
510
- console.log(chalk.dim(" Track:"), updated.trackId);
511
- console.log(chalk.dim(" Start:"), updated.startTime, "s");
512
- } catch (error) {
513
- spinner.fail(chalk.red("Failed to move clip"));
514
- console.error(error);
515
- process.exit(1);
516
- }
517
- });
518
-
519
- function detectMediaType(path: string): MediaType {
520
- const ext = extname(path).toLowerCase();
521
- const videoExts = [".mp4", ".mov", ".webm", ".avi", ".mkv"];
522
- const audioExts = [".mp3", ".wav", ".ogg", ".m4a", ".aac"];
523
- const imageExts = [".jpg", ".jpeg", ".png", ".gif", ".webp"];
524
-
525
- if (videoExts.includes(ext)) return "video";
526
- if (audioExts.includes(ext)) return "audio";
527
- if (imageExts.includes(ext)) return "image";
528
- return "video"; // Default
529
- }
@@ -1,77 +0,0 @@
1
- /**
2
- * @module validate
3
- * @description Input validation layer for CLI commands.
4
- * Guards against path traversal, control characters, and invalid resource IDs.
5
- */
6
-
7
- import { resolve, relative, isAbsolute } from "node:path";
8
-
9
- /**
10
- * Validate and resolve an output path, ensuring it stays within the working directory.
11
- * Prevents path traversal attacks (e.g., --output ../../etc/passwd).
12
- */
13
- export function validateOutputPath(path: string, cwd = process.cwd()): string {
14
- rejectControlChars(path);
15
- const resolved = resolve(cwd, path);
16
- const rel = relative(cwd, resolved);
17
- if (rel.startsWith("..") || isAbsolute(rel)) {
18
- throw new Error(
19
- `Output path "${path}" escapes the working directory. Use a path within "${cwd}".`
20
- );
21
- }
22
- return resolved;
23
- }
24
-
25
- /**
26
- * Validate a resource ID (source-*, clip-*, track-*, effect-*).
27
- * Only allows alphanumeric characters, hyphens, and underscores.
28
- */
29
- export function validateResourceId(id: string): string {
30
- rejectControlChars(id);
31
- if (!/^[a-zA-Z0-9_-]+$/.test(id)) {
32
- throw new Error(
33
- `Invalid resource ID "${id}". Only alphanumeric characters, hyphens, and underscores are allowed.`
34
- );
35
- }
36
- if (id.length > 128) {
37
- throw new Error(`Resource ID too long (max 128 characters).`);
38
- }
39
- return id;
40
- }
41
-
42
- /**
43
- * Reject strings containing control characters (U+0000–U+001F, U+007F–U+009F).
44
- * Prevents terminal injection and other control-char exploits.
45
- */
46
- export function rejectControlChars(input: string): string {
47
- // eslint-disable-next-line no-control-regex
48
- if (/[\x00-\x1f\x7f-\x9f]/.test(input)) {
49
- throw new Error("Input contains invalid control characters.");
50
- }
51
- return input;
52
- }
53
-
54
- /**
55
- * Validate a media file path and check its extension against an allowlist.
56
- */
57
- export function validateMediaFile(
58
- path: string,
59
- allowedExts: string[]
60
- ): string {
61
- rejectControlChars(path);
62
- const ext = path.toLowerCase().split(".").pop();
63
- if (!ext || !allowedExts.includes(`.${ext}`)) {
64
- throw new Error(
65
- `Unsupported file type ".${ext}". Allowed: ${allowedExts.join(", ")}`
66
- );
67
- }
68
- return path;
69
- }
70
-
71
- /** Common media file extensions */
72
- export const MEDIA_EXTS = {
73
- video: [".mp4", ".mov", ".avi", ".mkv", ".webm", ".m4v", ".flv"],
74
- audio: [".mp3", ".wav", ".aac", ".ogg", ".m4a", ".flac", ".wma"],
75
- image: [".png", ".jpg", ".jpeg", ".gif", ".webp", ".bmp", ".tiff", ".svg"],
76
- subtitle: [".srt", ".vtt", ".ass", ".ssa"],
77
- };