@slatesvideo/cli 0.5.13 → 0.5.14
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/README.md +8 -4
- package/dist/commands/completion.d.ts +2 -0
- package/dist/commands/completion.js +84 -0
- package/dist/commands/doctor.d.ts +2 -0
- package/dist/commands/doctor.js +165 -0
- package/dist/commands/login.js +2 -1
- package/dist/commands/op.d.ts +11 -0
- package/dist/commands/op.js +302 -50
- package/dist/commands/use.d.ts +2 -0
- package/dist/commands/use.js +50 -0
- package/dist/exit-codes.d.ts +21 -0
- package/dist/exit-codes.js +45 -0
- package/dist/index.js +74 -8
- package/package.json +58 -58
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @slatesvideo/cli
|
|
2
2
|
|
|
3
|
-
The `slates` command for the [Slates](https://slates.video) AI video studio. Drive Slates from your terminal, or let Claude Code shell out to it instead of loading
|
|
3
|
+
The `slates` command for the [Slates](https://slates.video) AI video studio. Drive Slates from your terminal, or let Claude Code shell out to it instead of loading <!-- gen:tool-count -->91<!-- /gen:tool-count --> tool schemas into context.
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
@@ -19,11 +19,15 @@ Requires Node.js 18+ and the Slates desktop app ([slates.video](https://slates.v
|
|
|
19
19
|
| `slates status` | Show connection state, account, and credit balance |
|
|
20
20
|
| `slates mcp` | Detect installed MCP clients and print the exact config for each; `--write` merges it into Claude Desktop / Cursor configs (with a `.bak` backup) |
|
|
21
21
|
| `slates install-skills` | Install the bundled agent skills into `.claude/skills/<name>/SKILL.md`; `--global` targets `~/.claude/skills` |
|
|
22
|
-
| `slates run <op>` | Invoke any Slates operation by id; `--list` shows all
|
|
22
|
+
| `slates run <op>` | Invoke any Slates operation by id; `--list` shows all <!-- gen:tool-count -->91<!-- /gen:tool-count -->, `<op> --help` shows one op's flags |
|
|
23
|
+
| `slates run <op> --input '<json>'` | Pass a NESTED object (Shot `params`/`refs`, batch updates) — flags cannot express those |
|
|
24
|
+
| `slates use <project>` | Set the default project, by id or name, so ops stop needing `--projectId` |
|
|
25
|
+
| `slates doctor` | Check every setup precondition and print the fix for each failure |
|
|
26
|
+
| `slates completion bash\|zsh\|pwsh` | Shell completion for the operation ids |
|
|
23
27
|
|
|
24
28
|
## Skills
|
|
25
29
|
|
|
26
|
-
|
|
30
|
+
<!-- gen:skill-count -->34<!-- /gen:skill-count --> agent skills ship embedded in `@slatesvideo/shared`: <!-- gen:workflow-skill-count -->18<!-- /gen:workflow-skill-count --> workflow recipes (<!-- gen:workflow-skills -->blocking-to-prompt, camera-language, character-identity, content-policy, cost-discipline, dialogue-blocking, direct-response-ad, edit-and-iterate, model-selection, one-prompt-film, previs-blocking, project-organization, restyle-from-blocking, shot-variety, storyboard-from-script, style-prompting, ugc-influencer-ad, vision-feedback-loop<!-- /gen:workflow-skills -->) and <!-- gen:per-model-skill-count -->16<!-- /gen:per-model-skill-count --> per-model prompting guides covering <!-- gen:video-roster -->kling-v3.0-std, kling-v3.0-pro, kling-v3.0-omni, veo-3.1-fast, veo-3.1-standard, Seedance 2.0, Seedance 2.5, Gemini Omni Flash, MiniMax H3, MiniMax H3 Max, LTX-2.5, LTX-2.5 Pro<!-- /gen:video-roster -->, <!-- gen:image-roster -->Nano Banana 2 (Gemini 3.1 Flash Image), Nano Banana 2 Lite, Nano Banana Pro, GPT Image 2, FLUX.2 Max, Seedream 5 Lite<!-- /gen:image-roster --> and <!-- gen:audio-roster -->Seed Audio 1.0, ElevenLabs Sound Effects v2, Inworld Realtime TTS-2<!-- /gen:audio-roster -->.
|
|
27
31
|
|
|
28
32
|
`slates install-skills` writes each one to `.claude/skills/<skill-name>/SKILL.md` in your current project, which is the layout Claude Code's skill discovery requires. Use `--global` to install for every project. Restart Claude Code afterward, then ask: "what slates skills do you have?" to verify.
|
|
29
33
|
|
|
@@ -60,7 +64,7 @@ Notes for agent use:
|
|
|
60
64
|
|
|
61
65
|
- Repeated flags or comma lists become arrays: `--ids a,b,c`.
|
|
62
66
|
- `--json` emits `{text, data, images}`. Image entries carry `mimeType` and byte count only, not the binary. Use the MCP server (`@slatesvideo/mcp-server`) when the agent needs to see generated images inline.
|
|
63
|
-
- Generation ops gate on missing `aspectRatio`/`resolution` and on cost over
|
|
67
|
+
- Generation ops gate on missing `aspectRatio`/`resolution` and on cost over <!-- gen:confirm-credits -->17<!-- /gen:confirm-credits --> credits (`confirm=true` required), so a scripted run cannot silently overspend. The exit code says which: **0** done, **1** error, **3** confirm required, **4** clarification required, **5** desktop unreachable, **6** not signed in.
|
|
64
68
|
|
|
65
69
|
## First-time setup
|
|
66
70
|
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { ALL_OPERATIONS } from '@slatesvideo/shared';
|
|
2
|
+
// `slates completion bash|zsh|pwsh` — op ids are long, there are 91 of them,
|
|
3
|
+
// and every one starts with the same eleven characters. Tab completion is the
|
|
4
|
+
// difference between typing an id and remembering one.
|
|
5
|
+
//
|
|
6
|
+
// Generated from ALL_OPERATIONS at print time, so a new op completes the day it
|
|
7
|
+
// ships rather than the day someone remembers this file exists.
|
|
8
|
+
const COMMANDS = [
|
|
9
|
+
'login',
|
|
10
|
+
'logout',
|
|
11
|
+
'status',
|
|
12
|
+
'doctor',
|
|
13
|
+
'setup',
|
|
14
|
+
'mcp',
|
|
15
|
+
'install-skills',
|
|
16
|
+
'use',
|
|
17
|
+
'run',
|
|
18
|
+
'completion',
|
|
19
|
+
];
|
|
20
|
+
export function runCompletion(shell) {
|
|
21
|
+
const ops = ALL_OPERATIONS.map((o) => o.id);
|
|
22
|
+
const target = (shell ?? '').toLowerCase();
|
|
23
|
+
if (target === 'bash') {
|
|
24
|
+
console.log(`# slates bash completion — add to ~/.bashrc:
|
|
25
|
+
# source <(slates completion bash)
|
|
26
|
+
_slates_completion() {
|
|
27
|
+
local cur prev
|
|
28
|
+
cur="\${COMP_WORDS[COMP_CWORD]}"
|
|
29
|
+
prev="\${COMP_WORDS[COMP_CWORD-1]}"
|
|
30
|
+
if [ "$prev" = "run" ]; then
|
|
31
|
+
COMPREPLY=( $(compgen -W "${ops.join(' ')}" -- "$cur") )
|
|
32
|
+
elif [ "$prev" = "completion" ]; then
|
|
33
|
+
COMPREPLY=( $(compgen -W "bash zsh pwsh" -- "$cur") )
|
|
34
|
+
elif [ "$COMP_CWORD" -eq 1 ]; then
|
|
35
|
+
COMPREPLY=( $(compgen -W "${COMMANDS.join(' ')}" -- "$cur") )
|
|
36
|
+
fi
|
|
37
|
+
}
|
|
38
|
+
complete -F _slates_completion slates`);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
if (target === 'zsh') {
|
|
42
|
+
console.log(`# slates zsh completion — add to ~/.zshrc:
|
|
43
|
+
# source <(slates completion zsh)
|
|
44
|
+
_slates() {
|
|
45
|
+
local -a cmds ops
|
|
46
|
+
cmds=(${COMMANDS.join(' ')})
|
|
47
|
+
ops=(${ops.join(' ')})
|
|
48
|
+
if (( CURRENT == 2 )); then
|
|
49
|
+
compadd -- $cmds
|
|
50
|
+
elif [[ \${words[2]} == run ]]; then
|
|
51
|
+
compadd -- $ops
|
|
52
|
+
elif [[ \${words[2]} == completion ]]; then
|
|
53
|
+
compadd -- bash zsh pwsh
|
|
54
|
+
fi
|
|
55
|
+
}
|
|
56
|
+
compdef _slates slates`);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
if (target === 'pwsh' || target === 'powershell') {
|
|
60
|
+
console.log(`# slates PowerShell completion — add to $PROFILE:
|
|
61
|
+
# slates completion pwsh | Out-String | Invoke-Expression
|
|
62
|
+
Register-ArgumentCompleter -Native -CommandName slates -ScriptBlock {
|
|
63
|
+
param($wordToComplete, $commandAst, $cursorPosition)
|
|
64
|
+
$tokens = $commandAst.ToString() -split '\\s+'
|
|
65
|
+
$candidates = if ($tokens.Length -ge 2 -and $tokens[1] -eq 'run') {
|
|
66
|
+
@(${ops.map((o) => `'${o}'`).join(',')})
|
|
67
|
+
} elseif ($tokens.Length -ge 2 -and $tokens[1] -eq 'completion') {
|
|
68
|
+
@('bash','zsh','pwsh')
|
|
69
|
+
} else {
|
|
70
|
+
@(${COMMANDS.map((c) => `'${c}'`).join(',')})
|
|
71
|
+
}
|
|
72
|
+
$candidates | Where-Object { $_ -like "$wordToComplete*" } | ForEach-Object {
|
|
73
|
+
[System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
|
|
74
|
+
}
|
|
75
|
+
}`);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
console.error('Usage: slates completion bash|zsh|pwsh');
|
|
79
|
+
console.error(' bash: source <(slates completion bash) in ~/.bashrc');
|
|
80
|
+
console.error(' zsh: source <(slates completion zsh) in ~/.zshrc');
|
|
81
|
+
console.error(' pwsh: slates completion pwsh | Out-String | Invoke-Expression in $PROFILE');
|
|
82
|
+
process.exit(1);
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=completion.js.map
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { readFileSync, existsSync, readdirSync } from 'node:fs';
|
|
2
|
+
import { join, dirname } from 'node:path';
|
|
3
|
+
import { homedir } from 'node:os';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import { readConnection, CONNECTION_FILE, SlatesCloudClient, SlatesDesktopClient, SKILLS, } from '@slatesvideo/shared';
|
|
6
|
+
import { EXIT } from '../exit-codes.js';
|
|
7
|
+
function frontmatterName(markdown, fallback) {
|
|
8
|
+
if (!markdown.startsWith('---'))
|
|
9
|
+
return fallback;
|
|
10
|
+
const end = markdown.indexOf('\n---', 3);
|
|
11
|
+
if (end === -1)
|
|
12
|
+
return fallback;
|
|
13
|
+
const m = markdown.slice(3, end).match(/^name:\s*(.+?)\s*$/m);
|
|
14
|
+
return m ? m[1].trim() : fallback;
|
|
15
|
+
}
|
|
16
|
+
/** Every op that needs a desktop capability, and the capability it needs. Kept
|
|
17
|
+
* in step with `requireCapability` call sites in the ops registry. */
|
|
18
|
+
const REQUIRED_CAPABILITIES = [
|
|
19
|
+
['shots', 'Shots — the whole shot-list surface'],
|
|
20
|
+
['background-generation', 'background: true on any generate op'],
|
|
21
|
+
['image-references', 'reference images on image generation'],
|
|
22
|
+
['image-models-v2', 'gpt-image-2 / nano-banana-pro / nano-banana-2-lite'],
|
|
23
|
+
];
|
|
24
|
+
export async function runDoctor() {
|
|
25
|
+
const checks = [];
|
|
26
|
+
const conn = readConnection();
|
|
27
|
+
// 1. The connection file.
|
|
28
|
+
checks.push({
|
|
29
|
+
name: 'Connection file',
|
|
30
|
+
ok: existsSync(CONNECTION_FILE),
|
|
31
|
+
detail: existsSync(CONNECTION_FILE) ? CONNECTION_FILE : `not found at ${CONNECTION_FILE}`,
|
|
32
|
+
fix: 'Run `slates login`, or open Slates → Settings → Agent Control → Send link.',
|
|
33
|
+
});
|
|
34
|
+
// 2. The cloud token, verified against the API rather than merely present.
|
|
35
|
+
if (!conn.cloud.token) {
|
|
36
|
+
checks.push({
|
|
37
|
+
name: 'Cloud account',
|
|
38
|
+
ok: false,
|
|
39
|
+
detail: 'no token',
|
|
40
|
+
fix: 'Run `slates login` (or connect from Slates → Settings → Agent Control).',
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
try {
|
|
45
|
+
const me = await new SlatesCloudClient().get('/api/agent/me');
|
|
46
|
+
const balance = me.user.credit_balance ?? me.user.credit_balance_cents ?? 0;
|
|
47
|
+
checks.push({
|
|
48
|
+
name: 'Cloud account',
|
|
49
|
+
ok: true,
|
|
50
|
+
detail: `${me.user.email} · ${me.user.tier} · ${balance.toLocaleString('en-US')} credits`,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
catch (err) {
|
|
54
|
+
checks.push({
|
|
55
|
+
name: 'Cloud account',
|
|
56
|
+
ok: false,
|
|
57
|
+
detail: err instanceof Error ? err.message : String(err),
|
|
58
|
+
fix: 'The token is expired or was revoked — run `slates login` again.',
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
// 3. The desktop server: enabled, on a port, and actually answering.
|
|
63
|
+
let health = null;
|
|
64
|
+
if (!conn.desktop.enabled || !conn.desktop.port || !conn.desktop.token) {
|
|
65
|
+
checks.push({
|
|
66
|
+
name: 'Desktop server',
|
|
67
|
+
ok: false,
|
|
68
|
+
detail: 'not enabled in the connection file',
|
|
69
|
+
fix: 'Open Slates → Settings → Agent Control → toggle on. Every workspace op needs this.',
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
try {
|
|
74
|
+
health = await new SlatesDesktopClient().healthz();
|
|
75
|
+
checks.push({
|
|
76
|
+
name: 'Desktop server',
|
|
77
|
+
ok: true,
|
|
78
|
+
detail: `127.0.0.1:${conn.desktop.port} · v${health.version ?? '?'} · agent API v${health.agentApiVersion ?? 1}`,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
catch (err) {
|
|
82
|
+
checks.push({
|
|
83
|
+
name: 'Desktop server',
|
|
84
|
+
ok: false,
|
|
85
|
+
detail: err instanceof Error ? err.message : String(err),
|
|
86
|
+
fix: 'Open the Slates app. If it IS open, the stored port is stale — toggle Agent Control off and on.',
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
// 4. Desktop capabilities vs the ops that need them.
|
|
91
|
+
if (health) {
|
|
92
|
+
const have = new Set(health.capabilities ?? []);
|
|
93
|
+
const missing = REQUIRED_CAPABILITIES.filter(([cap]) => !have.has(cap));
|
|
94
|
+
checks.push({
|
|
95
|
+
name: 'Desktop capabilities',
|
|
96
|
+
ok: missing.length === 0,
|
|
97
|
+
detail: missing.length === 0
|
|
98
|
+
? `${have.size} capabilities, all the ops need present`
|
|
99
|
+
: `missing: ${missing.map(([cap, what]) => `${cap} (${what})`).join(', ')}`,
|
|
100
|
+
fix: 'Update Slates (Settings → Check for Updates). The ops that need these will refuse until you do.',
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
// 5. Installed skills vs what this CLI ships.
|
|
104
|
+
const bundled = new Set(Object.entries(SKILLS).map(([k, v]) => frontmatterName(v, k)));
|
|
105
|
+
const roots = [join(process.cwd(), '.claude', 'skills'), join(homedir(), '.claude', 'skills')];
|
|
106
|
+
const installedRoot = roots.find((r) => existsSync(r));
|
|
107
|
+
if (!installedRoot) {
|
|
108
|
+
checks.push({
|
|
109
|
+
name: 'Agent skills',
|
|
110
|
+
ok: false,
|
|
111
|
+
detail: 'none installed',
|
|
112
|
+
fix: 'Run `slates install-skills` (add --global for ~/.claude/skills), then restart Claude Code.',
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
const installed = new Set(readdirSync(installedRoot).filter((d) => existsSync(join(installedRoot, d, 'SKILL.md'))));
|
|
117
|
+
const missing = [...bundled].filter((s) => !installed.has(s));
|
|
118
|
+
checks.push({
|
|
119
|
+
name: 'Agent skills',
|
|
120
|
+
ok: missing.length === 0,
|
|
121
|
+
detail: missing.length === 0
|
|
122
|
+
? `${bundled.size} of ${bundled.size} installed in ${installedRoot}`
|
|
123
|
+
: `${bundled.size - missing.length} of ${bundled.size} installed — missing ${missing.length}`,
|
|
124
|
+
fix: 'Run `slates install-skills` to bring them up to this CLI version, then restart Claude Code.',
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
// 6. MCP client configs — present is enough; `slates mcp` owns the detail.
|
|
128
|
+
const mcpConfigs = [
|
|
129
|
+
join(homedir(), '.claude.json'),
|
|
130
|
+
join(homedir(), 'AppData', 'Roaming', 'Claude', 'claude_desktop_config.json'),
|
|
131
|
+
join(homedir(), 'Library', 'Application Support', 'Claude', 'claude_desktop_config.json'),
|
|
132
|
+
join(homedir(), '.cursor', 'mcp.json'),
|
|
133
|
+
].filter((p) => existsSync(p));
|
|
134
|
+
const wired = mcpConfigs.filter((p) => {
|
|
135
|
+
try {
|
|
136
|
+
return readFileSync(p, 'utf8').includes('slates');
|
|
137
|
+
}
|
|
138
|
+
catch {
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
checks.push({
|
|
143
|
+
name: 'MCP client config',
|
|
144
|
+
ok: wired.length > 0,
|
|
145
|
+
detail: wired.length > 0
|
|
146
|
+
? `slates entry found in ${wired.length} of ${mcpConfigs.length} detected config(s)`
|
|
147
|
+
: `${mcpConfigs.length} client config(s) detected, none mentions slates`,
|
|
148
|
+
fix: 'Run `slates mcp --write` (or `slates setup`), then restart the client.',
|
|
149
|
+
});
|
|
150
|
+
// ── Report ──
|
|
151
|
+
const version = JSON.parse(readFileSync(join(dirname(fileURLToPath(import.meta.url)), '..', '..', 'package.json'), 'utf8'));
|
|
152
|
+
console.log(`slates doctor — CLI v${version.version}\n`);
|
|
153
|
+
for (const c of checks) {
|
|
154
|
+
console.log(`${c.ok ? ' ok ' : ' ✗ '}${c.name}: ${c.detail}`);
|
|
155
|
+
if (!c.ok && c.fix)
|
|
156
|
+
console.log(` → ${c.fix}`);
|
|
157
|
+
}
|
|
158
|
+
const failed = checks.filter((c) => !c.ok);
|
|
159
|
+
console.log(failed.length === 0
|
|
160
|
+
? `\nAll ${checks.length} checks passed.`
|
|
161
|
+
: `\n${failed.length} of ${checks.length} checks failed. Fix them top-down — a later one often depends on an earlier one.`);
|
|
162
|
+
if (failed.length > 0)
|
|
163
|
+
process.exit(EXIT.ERROR);
|
|
164
|
+
}
|
|
165
|
+
//# sourceMappingURL=doctor.js.map
|
package/dist/commands/login.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { setCloudToken } from '@slatesvideo/shared';
|
|
2
2
|
import { promptInput } from '../util/prompt.js';
|
|
3
|
-
|
|
3
|
+
import { SLATES_API_URL } from '@slatesvideo/shared';
|
|
4
|
+
const CLOUD_BASE_URL = process.env.SLATES_CLOUD_BASE_URL ?? SLATES_API_URL;
|
|
4
5
|
export async function runLogin(opts) {
|
|
5
6
|
// Manual paste path — power users who minted a key on the web UI
|
|
6
7
|
// (or want to bypass email entirely for CI).
|
package/dist/commands/op.d.ts
CHANGED
|
@@ -1,8 +1,19 @@
|
|
|
1
|
+
import { type Operation } from '@slatesvideo/shared';
|
|
1
2
|
interface RunOpOptions {
|
|
2
3
|
opId: string;
|
|
3
4
|
rawArgs: string[];
|
|
4
5
|
json: boolean;
|
|
6
|
+
saveImages?: string;
|
|
5
7
|
}
|
|
8
|
+
/**
|
|
9
|
+
* `slates run <op> --help`.
|
|
10
|
+
*
|
|
11
|
+
* The only way to learn an op's parameters used to be `slates run --list`,
|
|
12
|
+
* which printed all 91 descriptions — 29 KB, including the generated capability
|
|
13
|
+
* tables — and not one parameter NAME. An agent shelling out had to guess the
|
|
14
|
+
* flags or go and read a skill.
|
|
15
|
+
*/
|
|
16
|
+
export declare function printOpHelp(op: Operation<unknown>): void;
|
|
6
17
|
export declare function runOp(opts: RunOpOptions): Promise<void>;
|
|
7
18
|
export {};
|
|
8
19
|
//# sourceMappingURL=op.d.ts.map
|
package/dist/commands/op.js
CHANGED
|
@@ -1,23 +1,45 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { readFileSync, writeFileSync, mkdirSync } from 'node:fs';
|
|
3
|
+
import { join, extname } from 'node:path';
|
|
4
|
+
import { ALL_OPERATIONS, defaultContext, readDefaultProjectId, } from '@slatesvideo/shared';
|
|
5
|
+
import { EXIT, exitFor } from '../exit-codes.js';
|
|
2
6
|
// Run-command flags that are CLI-side controls, not operation inputs.
|
|
3
7
|
// They get filtered out of rawArgs so they don't fail strict schemas
|
|
4
8
|
// like z.object({}).strict() on operations that take no input.
|
|
5
|
-
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
//
|
|
10
|
+
// The value-taking ones are listed separately: `--save-images ./out` must eat
|
|
11
|
+
// its value, or `./out` is parsed as a bare positional and silently ignored.
|
|
12
|
+
const RUN_COMMAND_FLAGS = new Set(['--json', '--list', '--full', '--help', '-h']);
|
|
13
|
+
const RUN_COMMAND_VALUE_FLAGS = new Set(['--save-images', '--input', '--input-file']);
|
|
14
|
+
/**
|
|
15
|
+
* Parse `--key value` pairs into an object. Repeated `--key` becomes an
|
|
16
|
+
* array. Booleans accept `--flag` (true) and `--flag=false`. Numbers
|
|
17
|
+
* auto-coerce when the Zod schema expects one — done at parse time
|
|
18
|
+
* against the operation input shape.
|
|
19
|
+
*
|
|
20
|
+
* 🚨 FLAGS CANNOT EXPRESS A NESTED OBJECT, AND THAT IS WHY `--input` EXISTS.
|
|
21
|
+
* Every op with an object-shaped param was UNCALLABLE from the CLI: all eight
|
|
22
|
+
* Shot ops (`params`, `refs`, the script fields), `slates_batch_update_frames`,
|
|
23
|
+
* `slates_update_timeline_settings`. The README tells a Claude Code user to
|
|
24
|
+
* shell out to the CLI instead of loading the tool schemas — and then they
|
|
25
|
+
* could not create a Shot. `--input '<json>'` and `--input-file <path>` carry
|
|
26
|
+
* the whole object; explicit flags still win, so `--input ... --prompt x`
|
|
27
|
+
* overrides the JSON's prompt.
|
|
28
|
+
*/
|
|
10
29
|
function parseArgs(rawArgs) {
|
|
11
30
|
const out = {};
|
|
12
31
|
for (let i = 0; i < rawArgs.length; i++) {
|
|
13
32
|
const arg = rawArgs[i];
|
|
14
33
|
if (!arg.startsWith('--'))
|
|
15
34
|
continue;
|
|
16
|
-
|
|
35
|
+
const bare = arg.split('=')[0];
|
|
36
|
+
if (RUN_COMMAND_FLAGS.has(bare) || RUN_COMMAND_VALUE_FLAGS.has(bare)) {
|
|
17
37
|
// Skip the value too if it doesn't start with --
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
38
|
+
if (!arg.includes('=')) {
|
|
39
|
+
const next = rawArgs[i + 1];
|
|
40
|
+
if (next != null && !next.startsWith('--'))
|
|
41
|
+
i++;
|
|
42
|
+
}
|
|
21
43
|
continue;
|
|
22
44
|
}
|
|
23
45
|
const eqIdx = arg.indexOf('=');
|
|
@@ -40,6 +62,51 @@ function parseArgs(rawArgs) {
|
|
|
40
62
|
}
|
|
41
63
|
return out;
|
|
42
64
|
}
|
|
65
|
+
/** The `--input` / `--input-file` payload, merged UNDER the explicit flags. */
|
|
66
|
+
function readInputObject(rawArgs) {
|
|
67
|
+
const valueOf = (flag) => {
|
|
68
|
+
for (let i = 0; i < rawArgs.length; i++) {
|
|
69
|
+
const a = rawArgs[i];
|
|
70
|
+
if (a === flag)
|
|
71
|
+
return rawArgs[i + 1];
|
|
72
|
+
if (a.startsWith(`${flag}=`))
|
|
73
|
+
return a.slice(flag.length + 1);
|
|
74
|
+
}
|
|
75
|
+
return undefined;
|
|
76
|
+
};
|
|
77
|
+
const inline = valueOf('--input');
|
|
78
|
+
const file = valueOf('--input-file');
|
|
79
|
+
const sources = [];
|
|
80
|
+
if (file) {
|
|
81
|
+
try {
|
|
82
|
+
sources.push(readFileSync(file, 'utf8'));
|
|
83
|
+
}
|
|
84
|
+
catch (err) {
|
|
85
|
+
console.error(`--input-file ${file}: ${err instanceof Error ? err.message : String(err)}`);
|
|
86
|
+
process.exit(EXIT.ERROR);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (inline)
|
|
90
|
+
sources.push(inline);
|
|
91
|
+
const merged = {};
|
|
92
|
+
for (const src of sources) {
|
|
93
|
+
let parsed;
|
|
94
|
+
try {
|
|
95
|
+
parsed = JSON.parse(src);
|
|
96
|
+
}
|
|
97
|
+
catch (err) {
|
|
98
|
+
console.error(`--input is not valid JSON: ${err instanceof Error ? err.message : String(err)}`);
|
|
99
|
+
console.error('Tip: on PowerShell, single quotes do not escape inner double quotes — use --input-file.');
|
|
100
|
+
process.exit(EXIT.ERROR);
|
|
101
|
+
}
|
|
102
|
+
if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {
|
|
103
|
+
console.error('--input must be a JSON OBJECT, e.g. \'{"projectId":"…","params":{"duration":8}}\'');
|
|
104
|
+
process.exit(EXIT.ERROR);
|
|
105
|
+
}
|
|
106
|
+
Object.assign(merged, parsed);
|
|
107
|
+
}
|
|
108
|
+
return merged;
|
|
109
|
+
}
|
|
43
110
|
function assign(obj, key, value) {
|
|
44
111
|
const existing = obj[key];
|
|
45
112
|
if (existing == null) {
|
|
@@ -52,26 +119,211 @@ function assign(obj, key, value) {
|
|
|
52
119
|
}
|
|
53
120
|
obj[key] = [existing, value];
|
|
54
121
|
}
|
|
122
|
+
const WRAPPERS = new Set([
|
|
123
|
+
'ZodOptional',
|
|
124
|
+
'ZodDefault',
|
|
125
|
+
'ZodNullable',
|
|
126
|
+
'ZodReadonly',
|
|
127
|
+
'ZodEffects',
|
|
128
|
+
'ZodCatch',
|
|
129
|
+
'ZodBranded',
|
|
130
|
+
]);
|
|
131
|
+
function unwrap(t) {
|
|
132
|
+
let cur = t;
|
|
133
|
+
let depth = 0;
|
|
134
|
+
while (cur?._def?.typeName && WRAPPERS.has(cur._def.typeName) && depth < 8) {
|
|
135
|
+
cur = cur._def.innerType ?? cur._def.schema;
|
|
136
|
+
depth++;
|
|
137
|
+
}
|
|
138
|
+
return cur;
|
|
139
|
+
}
|
|
140
|
+
function isOptional(t) {
|
|
141
|
+
let cur = t;
|
|
142
|
+
let depth = 0;
|
|
143
|
+
while (cur?._def?.typeName && depth < 8) {
|
|
144
|
+
if (cur._def.typeName === 'ZodOptional' || cur._def.typeName === 'ZodDefault')
|
|
145
|
+
return true;
|
|
146
|
+
if (!WRAPPERS.has(cur._def.typeName))
|
|
147
|
+
return false;
|
|
148
|
+
cur = cur._def.innerType ?? cur._def.schema;
|
|
149
|
+
depth++;
|
|
150
|
+
}
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
function describeOf(t) {
|
|
154
|
+
let cur = t;
|
|
155
|
+
let depth = 0;
|
|
156
|
+
while (cur?._def && depth < 8) {
|
|
157
|
+
if (cur._def.description)
|
|
158
|
+
return cur._def.description;
|
|
159
|
+
cur = cur._def.innerType ?? cur._def.schema;
|
|
160
|
+
depth++;
|
|
161
|
+
if (!cur)
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
return '';
|
|
165
|
+
}
|
|
166
|
+
function objectShape(schema) {
|
|
167
|
+
const z = schema;
|
|
168
|
+
if (z?._def?.typeName !== 'ZodObject')
|
|
169
|
+
return {};
|
|
170
|
+
return typeof z._def.shape === 'function' ? z._def.shape() : (z.shape ?? {});
|
|
171
|
+
}
|
|
172
|
+
/** A human type name plus, for an enum, its legal values. */
|
|
173
|
+
function typeLabel(t) {
|
|
174
|
+
const leaf = unwrap(t);
|
|
175
|
+
const name = leaf?._def?.typeName ?? '';
|
|
176
|
+
switch (name) {
|
|
177
|
+
case 'ZodString':
|
|
178
|
+
return 'string';
|
|
179
|
+
case 'ZodNumber':
|
|
180
|
+
return 'number';
|
|
181
|
+
case 'ZodBoolean':
|
|
182
|
+
return 'boolean';
|
|
183
|
+
case 'ZodEnum':
|
|
184
|
+
return `enum(${(leaf?._def?.values ?? []).join('|')})`;
|
|
185
|
+
case 'ZodNativeEnum':
|
|
186
|
+
return 'enum';
|
|
187
|
+
case 'ZodArray':
|
|
188
|
+
return `${typeLabel(leaf?._def?.type)}[]`;
|
|
189
|
+
case 'ZodObject':
|
|
190
|
+
return 'object';
|
|
191
|
+
case 'ZodUnion':
|
|
192
|
+
return 'union';
|
|
193
|
+
default:
|
|
194
|
+
return name.replace(/^Zod/, '').toLowerCase() || 'value';
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Zod's default error is a JSON blob of issue objects. Flatten to one readable
|
|
199
|
+
* line per problem, with the legal set printed whenever an enum was what
|
|
200
|
+
* failed — the same treatment the MCP server gives it, because both surfaces
|
|
201
|
+
* are read by an agent that pays a turn for every unclear error.
|
|
202
|
+
*/
|
|
203
|
+
function flattenZodError(err) {
|
|
204
|
+
return err.issues
|
|
205
|
+
.map((issue) => {
|
|
206
|
+
const path = issue.path.length > 0 ? issue.path.join('.') : '(root)';
|
|
207
|
+
if (issue.code === 'invalid_enum_value') {
|
|
208
|
+
const legal = issue.options ?? [];
|
|
209
|
+
return ` ${path}: ${issue.message}. Legal values: ${legal.join(', ')}`;
|
|
210
|
+
}
|
|
211
|
+
if (issue.code === 'unrecognized_keys') {
|
|
212
|
+
const keys = issue.keys ?? [];
|
|
213
|
+
return ` ${path}: unknown parameter(s) ${keys.join(', ')}`;
|
|
214
|
+
}
|
|
215
|
+
return ` ${path}: ${issue.message}`;
|
|
216
|
+
})
|
|
217
|
+
.join('\n');
|
|
218
|
+
}
|
|
219
|
+
function firstSentence(text) {
|
|
220
|
+
const s = text.split(/(?<=[.!?])\s/)[0].trim();
|
|
221
|
+
return s.length > 200 ? `${s.slice(0, 197)}…` : s;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* `slates run <op> --help`.
|
|
225
|
+
*
|
|
226
|
+
* The only way to learn an op's parameters used to be `slates run --list`,
|
|
227
|
+
* which printed all 91 descriptions — 29 KB, including the generated capability
|
|
228
|
+
* tables — and not one parameter NAME. An agent shelling out had to guess the
|
|
229
|
+
* flags or go and read a skill.
|
|
230
|
+
*/
|
|
231
|
+
export function printOpHelp(op) {
|
|
232
|
+
console.log(`${op.id}\n`);
|
|
233
|
+
console.log(`${op.description}\n`);
|
|
234
|
+
const shape = objectShape(op.input);
|
|
235
|
+
const keys = Object.keys(shape);
|
|
236
|
+
if (keys.length === 0) {
|
|
237
|
+
console.log('Takes no parameters.');
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
console.log('Parameters:');
|
|
241
|
+
const objectFields = [];
|
|
242
|
+
for (const key of keys) {
|
|
243
|
+
const node = shape[key];
|
|
244
|
+
const leaf = unwrap(node);
|
|
245
|
+
const required = !isOptional(node);
|
|
246
|
+
const label = typeLabel(node);
|
|
247
|
+
if (leaf?._def?.typeName === 'ZodObject')
|
|
248
|
+
objectFields.push(key);
|
|
249
|
+
const desc = describeOf(node);
|
|
250
|
+
console.log(` --${key}${' '.repeat(Math.max(1, 26 - key.length))}${label}${required ? ' (required)' : ''}`);
|
|
251
|
+
if (desc)
|
|
252
|
+
console.log(` ${firstSentence(desc)}`);
|
|
253
|
+
}
|
|
254
|
+
if (objectFields.length > 0) {
|
|
255
|
+
console.log(`\nNested object field(s): ${objectFields.join(', ')}. Flags cannot express these — ` +
|
|
256
|
+
`pass them with --input '<json>' or --input-file <path>.`);
|
|
257
|
+
console.log(` e.g. slates run ${op.id} --input '{"${objectFields[0]}":{}}'`);
|
|
258
|
+
}
|
|
259
|
+
console.log('\nExit codes: 0 done · 1 error · 3 confirm required · 4 clarification required · 5 desktop unreachable · 6 not signed in');
|
|
260
|
+
}
|
|
55
261
|
export async function runOp(opts) {
|
|
56
262
|
const ops = ALL_OPERATIONS;
|
|
57
263
|
const op = ops.find((o) => o.id === opts.opId);
|
|
58
264
|
if (!op) {
|
|
59
265
|
console.error(`Unknown operation: ${opts.opId}`);
|
|
60
266
|
console.error('Run `slates run --list` to see all operations.');
|
|
61
|
-
process.exit(
|
|
267
|
+
process.exit(EXIT.ERROR);
|
|
268
|
+
}
|
|
269
|
+
if (opts.rawArgs.some((a) => a === '--help' || a === '-h')) {
|
|
270
|
+
printOpHelp(op);
|
|
271
|
+
return;
|
|
62
272
|
}
|
|
63
|
-
const raw = parseArgs(opts.rawArgs);
|
|
273
|
+
const raw = { ...readInputObject(opts.rawArgs), ...parseArgs(opts.rawArgs) };
|
|
64
274
|
const coerced = coerceForSchema(op.input, raw);
|
|
275
|
+
// `slates use <project>` writes a default. Filled ONLY when the op declares a
|
|
276
|
+
// projectId and the caller left it out — never overriding an explicit value.
|
|
277
|
+
const shape = objectShape(op.input);
|
|
278
|
+
if (coerced.projectId === undefined && 'projectId' in shape) {
|
|
279
|
+
const fallback = readDefaultProjectId();
|
|
280
|
+
if (fallback)
|
|
281
|
+
coerced.projectId = fallback;
|
|
282
|
+
}
|
|
65
283
|
let parsed;
|
|
66
284
|
try {
|
|
67
285
|
parsed = op.input.parse(coerced);
|
|
68
286
|
}
|
|
69
287
|
catch (err) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
288
|
+
// 🚨 ONE LINE PER PROBLEM, not Zod's issue JSON. The raw error is an array
|
|
289
|
+
// of objects the caller has to read past to find the field name — and this
|
|
290
|
+
// is the surface a Claude Code session shells out to, so an unreadable
|
|
291
|
+
// error costs a turn every time. Same flattening the MCP server does.
|
|
292
|
+
console.error(`Invalid arguments for ${op.id}:`);
|
|
293
|
+
console.error(err instanceof z.ZodError ? flattenZodError(err) : String(err));
|
|
294
|
+
// An OBJECT field is the failure the flag parser structurally cannot fix,
|
|
295
|
+
// so name the one thing that does fix it rather than leaving the caller to
|
|
296
|
+
// guess why `--params.duration 8` did nothing.
|
|
297
|
+
const objectFields = Object.keys(shape).filter((k) => unwrap(shape[k])?._def?.typeName === 'ZodObject');
|
|
298
|
+
if (objectFields.length > 0) {
|
|
299
|
+
console.error(`\nNote: ${objectFields.join(', ')} ${objectFields.length === 1 ? 'is an OBJECT' : 'are OBJECTS'} — ` +
|
|
300
|
+
`flags cannot express nested values. Pass them with --input '<json>' or --input-file <path>. ` +
|
|
301
|
+
`\`slates run ${op.id} --help\` lists every flag.`);
|
|
302
|
+
}
|
|
303
|
+
process.exit(EXIT.ERROR);
|
|
304
|
+
}
|
|
305
|
+
let result;
|
|
306
|
+
try {
|
|
307
|
+
result = await op.run(parsed, defaultContext());
|
|
308
|
+
}
|
|
309
|
+
catch (err) {
|
|
310
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
311
|
+
console.error(message);
|
|
312
|
+
// 5 / 6 rather than a blanket 1: a script that shells out needs to tell
|
|
313
|
+
// "the app is closed" from "the call was wrong", and retrying the second is
|
|
314
|
+
// how an agent burns a loop.
|
|
315
|
+
process.exit(exitFor(err));
|
|
316
|
+
}
|
|
317
|
+
const data = result.data;
|
|
318
|
+
// The banned-token warning is in the RESULT, where a model reads it. A human
|
|
319
|
+
// running the CLI would never see it in --json, and would scroll past it in
|
|
320
|
+
// the prose — so it also goes to stderr, in yellow.
|
|
321
|
+
const warning = typeof data?.prompt_warning === 'string' ? data.prompt_warning : '';
|
|
322
|
+
if (warning)
|
|
323
|
+
process.stderr.write(`[33m${warning}[0m\n`);
|
|
324
|
+
if (opts.saveImages && result.images?.length) {
|
|
325
|
+
saveImages(result.images, opts.saveImages);
|
|
73
326
|
}
|
|
74
|
-
const result = await op.run(parsed, defaultContext());
|
|
75
327
|
if (opts.json) {
|
|
76
328
|
process.stdout.write(JSON.stringify({
|
|
77
329
|
text: result.text,
|
|
@@ -82,42 +334,42 @@ export async function runOp(opts) {
|
|
|
82
334
|
})),
|
|
83
335
|
}, null, 2));
|
|
84
336
|
process.stdout.write('\n');
|
|
85
|
-
return;
|
|
86
337
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
338
|
+
else {
|
|
339
|
+
console.log(result.text);
|
|
340
|
+
if (result.images && result.images.length > 0 && !opts.saveImages) {
|
|
341
|
+
console.log(`\nReturned ${result.images.length} inline image(s).`);
|
|
342
|
+
console.log('(--save-images <dir> writes them to disk; --json reports metadata only)');
|
|
343
|
+
}
|
|
91
344
|
}
|
|
345
|
+
// 🚨 A COMPLETED OP IS NOT NECESSARILY A DONE OP. `requires_confirm` and
|
|
346
|
+
// `requires_clarification` both used to exit 0, so a script or an agent
|
|
347
|
+
// reading the exit code could not tell "done" from "I asked you something" —
|
|
348
|
+
// and the natural reaction to a 0 is to move on.
|
|
349
|
+
if (data?.requires_confirm === true)
|
|
350
|
+
process.exit(EXIT.CONFIRM_REQUIRED);
|
|
351
|
+
if (data?.requires_clarification === true)
|
|
352
|
+
process.exit(EXIT.CLARIFICATION_REQUIRED);
|
|
353
|
+
}
|
|
354
|
+
/** Write returned images to disk and print the paths. */
|
|
355
|
+
function saveImages(images, dir) {
|
|
356
|
+
mkdirSync(dir, { recursive: true });
|
|
357
|
+
const stamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
358
|
+
images.forEach((img, i) => {
|
|
359
|
+
const ext = extname(`x.${img.mimeType.split('/')[1] ?? 'png'}`) || '.png';
|
|
360
|
+
const path = join(dir, `slates-${stamp}-${i + 1}${ext}`);
|
|
361
|
+
writeFileSync(path, Buffer.from(img.data, 'base64'));
|
|
362
|
+
console.log(path);
|
|
363
|
+
});
|
|
92
364
|
}
|
|
93
365
|
function coerceForSchema(schema, raw) {
|
|
94
|
-
|
|
95
|
-
|
|
366
|
+
// Best-effort coercion for the strings produced by parseArgs.
|
|
367
|
+
// Zod's parse will reject unknown inputs anyway; this just improves
|
|
368
|
+
// the experience for the common cases (numbers, booleans).
|
|
369
|
+
// Values that arrived through --input are already typed, so they pass through.
|
|
370
|
+
const shape = objectShape(schema);
|
|
371
|
+
if (Object.keys(shape).length === 0)
|
|
96
372
|
return raw;
|
|
97
|
-
const shape = typeof zodObj._def.shape === 'function'
|
|
98
|
-
? zodObj._def.shape()
|
|
99
|
-
: zodObj.shape ?? {};
|
|
100
|
-
// Unwrap ZodOptional / ZodDefault / ZodNullable / ZodEffects / ZodReadonly
|
|
101
|
-
// to find the leaf type. `z.number().optional()` reports typeName
|
|
102
|
-
// 'ZodOptional' with `_def.innerType` pointing at the ZodNumber.
|
|
103
|
-
const wrappers = new Set([
|
|
104
|
-
'ZodOptional',
|
|
105
|
-
'ZodDefault',
|
|
106
|
-
'ZodNullable',
|
|
107
|
-
'ZodReadonly',
|
|
108
|
-
'ZodEffects',
|
|
109
|
-
'ZodCatch',
|
|
110
|
-
'ZodBranded',
|
|
111
|
-
]);
|
|
112
|
-
const unwrap = (t) => {
|
|
113
|
-
let cur = t;
|
|
114
|
-
let depth = 0;
|
|
115
|
-
while (cur?._def?.typeName && wrappers.has(cur._def.typeName) && depth < 8) {
|
|
116
|
-
cur = cur._def.innerType ?? cur._def.schema;
|
|
117
|
-
depth++;
|
|
118
|
-
}
|
|
119
|
-
return cur;
|
|
120
|
-
};
|
|
121
373
|
// Does the declared type allow null anywhere in its wrapper chain?
|
|
122
374
|
// (e.g. z.string().uuid().nullable() — so `--folderId null` → null.)
|
|
123
375
|
const isNullable = (t) => {
|
|
@@ -126,7 +378,7 @@ function coerceForSchema(schema, raw) {
|
|
|
126
378
|
while (cur?._def?.typeName && depth < 8) {
|
|
127
379
|
if (cur._def.typeName === 'ZodNullable')
|
|
128
380
|
return true;
|
|
129
|
-
if (
|
|
381
|
+
if (WRAPPERS.has(cur._def.typeName)) {
|
|
130
382
|
cur = cur._def.innerType ?? cur._def.schema;
|
|
131
383
|
depth++;
|
|
132
384
|
continue;
|
|
@@ -159,8 +411,8 @@ function coerceForSchema(schema, raw) {
|
|
|
159
411
|
// Array fields: a single `--ids X` produced a bare string; repeated
|
|
160
412
|
// `--ids X --ids Y` produced an array. Accept either, plus comma-split
|
|
161
413
|
// (`--ids a,b,c`). Coerce each element to the array's element type.
|
|
162
|
-
if (fieldType === 'ZodArray') {
|
|
163
|
-
const elemType = (leaf?._def?.type?._def?.typeName ?? '');
|
|
414
|
+
if (fieldType === 'ZodArray' && typeof value !== 'object') {
|
|
415
|
+
const elemType = (unwrap(leaf?._def?.type)?._def?.typeName ?? '');
|
|
164
416
|
const arr = Array.isArray(value)
|
|
165
417
|
? value
|
|
166
418
|
: typeof value === 'string'
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { SlatesDesktopClient, setDefaultProjectId, readDefaultProjectId, } from '@slatesvideo/shared';
|
|
2
|
+
import { EXIT, exitFor } from '../exit-codes.js';
|
|
3
|
+
export async function runUse(target) {
|
|
4
|
+
if (!target) {
|
|
5
|
+
const current = readDefaultProjectId();
|
|
6
|
+
console.log(current ? `Default project: ${current}` : 'No default project set.');
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
if (target === '--clear' || target === 'none') {
|
|
10
|
+
setDefaultProjectId(null);
|
|
11
|
+
console.log('Default project cleared.');
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
let projects = [];
|
|
15
|
+
try {
|
|
16
|
+
const r = await new SlatesDesktopClient().get('/agent/projects');
|
|
17
|
+
projects = r.projects ?? [];
|
|
18
|
+
}
|
|
19
|
+
catch (err) {
|
|
20
|
+
console.error(err instanceof Error ? err.message : String(err));
|
|
21
|
+
process.exit(exitFor(err));
|
|
22
|
+
}
|
|
23
|
+
const byId = projects.find((p) => p.id === target);
|
|
24
|
+
if (byId) {
|
|
25
|
+
setDefaultProjectId(byId.id);
|
|
26
|
+
console.log(`Default project: ${byId.name} (${byId.id})`);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
// Name match: exact first, then case-insensitive substring. An ambiguous
|
|
30
|
+
// substring REFUSES rather than picking one — the wrong project is where a
|
|
31
|
+
// generation lands on someone else's storyboard.
|
|
32
|
+
const q = target.toLowerCase();
|
|
33
|
+
const exact = projects.filter((p) => p.name.toLowerCase() === q);
|
|
34
|
+
const partial = exact.length > 0 ? exact : projects.filter((p) => p.name.toLowerCase().includes(q));
|
|
35
|
+
if (partial.length === 1) {
|
|
36
|
+
setDefaultProjectId(partial[0].id);
|
|
37
|
+
console.log(`Default project: ${partial[0].name} (${partial[0].id})`);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
if (partial.length === 0) {
|
|
41
|
+
console.error(`No project matches "${target}".`);
|
|
42
|
+
console.error(`Known projects: ${projects.map((p) => p.name).join(', ') || '(none)'}`);
|
|
43
|
+
process.exit(EXIT.ERROR);
|
|
44
|
+
}
|
|
45
|
+
console.error(`"${target}" matches ${partial.length} projects — be more specific or pass the id:`);
|
|
46
|
+
for (const p of partial)
|
|
47
|
+
console.error(` ${p.id} ${p.name}`);
|
|
48
|
+
process.exit(EXIT.ERROR);
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=use.js.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare const EXIT: {
|
|
2
|
+
/** The op ran and finished. */
|
|
3
|
+
readonly OK: 0;
|
|
4
|
+
/** Anything went wrong: bad arguments, a provider error, an unexpected throw. */
|
|
5
|
+
readonly ERROR: 1;
|
|
6
|
+
/** The op returned `requires_confirm` — a human has to OK the spend, then
|
|
7
|
+
* re-call with `--confirm true`. Nothing was charged. */
|
|
8
|
+
readonly CONFIRM_REQUIRED: 3;
|
|
9
|
+
/** The op returned `requires_clarification` — a required choice is missing
|
|
10
|
+
* (aspect ratio, resolution, duration). Its `message` names the field. */
|
|
11
|
+
readonly CLARIFICATION_REQUIRED: 4;
|
|
12
|
+
/** The Slates desktop app is not running with Agent Control on. */
|
|
13
|
+
readonly DESKTOP_UNREACHABLE: 5;
|
|
14
|
+
/** No cloud token, or it was revoked. Run `slates login`. */
|
|
15
|
+
readonly NOT_SIGNED_IN: 6;
|
|
16
|
+
};
|
|
17
|
+
/** Map a thrown error to its exit code. Retrying a 5 or a 6 is pointless until
|
|
18
|
+
* the user does something; retrying a 1 might work. That distinction is the
|
|
19
|
+
* whole reason these exist. */
|
|
20
|
+
export declare function exitFor(err: unknown): number;
|
|
21
|
+
//# sourceMappingURL=exit-codes.d.ts.map
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// ============================================================
|
|
2
|
+
// CLI EXIT CODES — a CONTRACT, not a convenience.
|
|
3
|
+
//
|
|
4
|
+
// Every completed op used to exit 0, including `requires_confirm` and
|
|
5
|
+
// `requires_clarification`. A script or an agent reading the exit code could
|
|
6
|
+
// not tell "done" from "I asked you something", and the natural reaction to a 0
|
|
7
|
+
// is to move on — so the question went unanswered and the work silently did not
|
|
8
|
+
// happen.
|
|
9
|
+
//
|
|
10
|
+
// 🚨 THESE NUMBERS ARE PUBLIC. Scripts and agent skills will branch on them.
|
|
11
|
+
// Add codes; never renumber one.
|
|
12
|
+
// ============================================================
|
|
13
|
+
export const EXIT = {
|
|
14
|
+
/** The op ran and finished. */
|
|
15
|
+
OK: 0,
|
|
16
|
+
/** Anything went wrong: bad arguments, a provider error, an unexpected throw. */
|
|
17
|
+
ERROR: 1,
|
|
18
|
+
/** The op returned `requires_confirm` — a human has to OK the spend, then
|
|
19
|
+
* re-call with `--confirm true`. Nothing was charged. */
|
|
20
|
+
CONFIRM_REQUIRED: 3,
|
|
21
|
+
/** The op returned `requires_clarification` — a required choice is missing
|
|
22
|
+
* (aspect ratio, resolution, duration). Its `message` names the field. */
|
|
23
|
+
CLARIFICATION_REQUIRED: 4,
|
|
24
|
+
/** The Slates desktop app is not running with Agent Control on. */
|
|
25
|
+
DESKTOP_UNREACHABLE: 5,
|
|
26
|
+
/** No cloud token, or it was revoked. Run `slates login`. */
|
|
27
|
+
NOT_SIGNED_IN: 6,
|
|
28
|
+
};
|
|
29
|
+
/** Map a thrown error to its exit code. Retrying a 5 or a 6 is pointless until
|
|
30
|
+
* the user does something; retrying a 1 might work. That distinction is the
|
|
31
|
+
* whole reason these exist. */
|
|
32
|
+
export function exitFor(err) {
|
|
33
|
+
const code = err?.code;
|
|
34
|
+
if (code === 'DESKTOP_SERVER_MISSING')
|
|
35
|
+
return EXIT.DESKTOP_UNREACHABLE;
|
|
36
|
+
if (code === 'CLOUD_TOKEN_MISSING')
|
|
37
|
+
return EXIT.NOT_SIGNED_IN;
|
|
38
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
39
|
+
if (/not reachable|Agent Control|is not running/i.test(message))
|
|
40
|
+
return EXIT.DESKTOP_UNREACHABLE;
|
|
41
|
+
if (/rejected the auth token|slates login|401/i.test(message))
|
|
42
|
+
return EXIT.NOT_SIGNED_IN;
|
|
43
|
+
return EXIT.ERROR;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=exit-codes.js.map
|
package/dist/index.js
CHANGED
|
@@ -11,6 +11,11 @@ import { runOp } from './commands/op.js';
|
|
|
11
11
|
import { runInstallSkills } from './commands/install-skills.js';
|
|
12
12
|
import { runMcp } from './commands/mcp.js';
|
|
13
13
|
import { runSetup } from './commands/setup.js';
|
|
14
|
+
import { runDoctor } from './commands/doctor.js';
|
|
15
|
+
import { runUse } from './commands/use.js';
|
|
16
|
+
import { runCompletion } from './commands/completion.js';
|
|
17
|
+
import { printOpHelp } from './commands/op.js';
|
|
18
|
+
import { EXIT } from './exit-codes.js';
|
|
14
19
|
import { ALL_OPERATIONS } from '@slatesvideo/shared';
|
|
15
20
|
// Slates CLI. The CLI mirrors the MCP tool surface as commands so Claude
|
|
16
21
|
// Code can shell out to them instead of loading every tool schema into
|
|
@@ -70,11 +75,29 @@ program
|
|
|
70
75
|
.description('Install the bundled skills into .claude/skills/<name>/SKILL.md (Claude Code layout).')
|
|
71
76
|
.option('--global', 'Install into ~/.claude/skills instead of the current project', false)
|
|
72
77
|
.action((opts) => runInstallSkills(opts));
|
|
78
|
+
program
|
|
79
|
+
.command('doctor')
|
|
80
|
+
.description('Check every setup precondition at once — connection file, cloud token, desktop server and its capabilities, installed skills, MCP configs — and print the fix for each failure.')
|
|
81
|
+
.action(() => runDoctor());
|
|
82
|
+
program
|
|
83
|
+
.command('use')
|
|
84
|
+
.description('Set the default project for this machine, by id or name. Ops that take projectId fill it when you omit one; an explicit --projectId always wins. No argument prints the current default; `slates use --clear` removes it.')
|
|
85
|
+
.argument('[project]', 'Project id or name')
|
|
86
|
+
.action((project) => runUse(project));
|
|
87
|
+
program
|
|
88
|
+
.command('completion')
|
|
89
|
+
.description('Print a shell completion script for the 91 operation ids.')
|
|
90
|
+
.argument('[shell]', 'bash | zsh | pwsh')
|
|
91
|
+
.action((shell) => runCompletion(shell));
|
|
73
92
|
program
|
|
74
93
|
.command('run')
|
|
75
|
-
.description('Invoke a Slates operation by id
|
|
76
|
-
.option('--list', 'List
|
|
77
|
-
.option('--
|
|
94
|
+
.description('Invoke a Slates operation by id. `slates run --list` lists them; `slates run <op> --help` prints that op\'s flags.')
|
|
95
|
+
.option('--list', 'List operation ids with a one-line summary', false)
|
|
96
|
+
.option('--full', 'With --list: print each op\'s complete description (large — 29 KB)', false)
|
|
97
|
+
.option('--json', 'Emit structured JSON ({text, data, images: [{mimeType, bytes}]}). Image binary is omitted — use --save-images to write the files.', false)
|
|
98
|
+
.option('--save-images <dir>', 'Write returned images into <dir> and print the paths')
|
|
99
|
+
.option('--input <json>', 'JSON object of inputs — the only way to pass a NESTED object (Shot params/refs, batch updates). Merged under explicit flags.')
|
|
100
|
+
.option('--input-file <path>', 'Same as --input, read from a file. Use this when your shell mangles quotes.')
|
|
78
101
|
.allowUnknownOption()
|
|
79
102
|
.passThroughOptions()
|
|
80
103
|
.argument('[opId]', 'Operation id, e.g. slates_create_project')
|
|
@@ -82,16 +105,59 @@ program
|
|
|
82
105
|
.action(async (opId, args, options) => {
|
|
83
106
|
// With passThroughOptions enabled, --json/--list AFTER the opId end
|
|
84
107
|
// up in `args` instead of `options`. Detect both positions.
|
|
85
|
-
const
|
|
86
|
-
const
|
|
108
|
+
const flag = (name) => args.some((a) => a === `--${name}` || a.startsWith(`--${name}=`));
|
|
109
|
+
const jsonFlag = !!options.json || flag('json');
|
|
110
|
+
const listFlag = !!options.list || flag('list');
|
|
111
|
+
const fullFlag = !!options.full || flag('full');
|
|
112
|
+
const valueOf = (name) => {
|
|
113
|
+
const opt = options[name];
|
|
114
|
+
if (opt)
|
|
115
|
+
return opt;
|
|
116
|
+
const i = args.findIndex((a) => a === `--${name}`);
|
|
117
|
+
if (i !== -1)
|
|
118
|
+
return args[i + 1];
|
|
119
|
+
const eq = args.find((a) => a.startsWith(`--${name}=`));
|
|
120
|
+
return eq ? eq.slice(name.length + 3) : undefined;
|
|
121
|
+
};
|
|
122
|
+
const ops = ALL_OPERATIONS;
|
|
87
123
|
if (listFlag || !opId) {
|
|
88
|
-
|
|
124
|
+
// 🚨 IDS AND ONE SENTENCE, NOT 29 KB. `--list` printed every description
|
|
125
|
+
// in full — including the generated capability tables — and not one
|
|
126
|
+
// parameter name, so the one command that was supposed to teach the
|
|
127
|
+
// surface was unreadable and taught nothing. `--full` keeps the old
|
|
128
|
+
// output for anyone who wants it; `<op> --help` is what you actually want.
|
|
89
129
|
for (const op of ops) {
|
|
90
|
-
|
|
130
|
+
if (fullFlag) {
|
|
131
|
+
console.log(`${op.id}\n ${op.description}\n`);
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
console.log(`${op.id} — ${op.description.split(/(?<=\.)\s/)[0]}`);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (!fullFlag) {
|
|
138
|
+
console.log(`\n${ops.length} operations. \`slates run <op> --help\` for one op's flags; --full for every description.`);
|
|
139
|
+
}
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
if (args.some((a) => a === '--help' || a === '-h')) {
|
|
143
|
+
const op = ops.find((o) => o.id === opId);
|
|
144
|
+
if (!op) {
|
|
145
|
+
console.error(`Unknown operation: ${opId}`);
|
|
146
|
+
process.exit(EXIT.ERROR);
|
|
91
147
|
}
|
|
148
|
+
printOpHelp(op);
|
|
92
149
|
return;
|
|
93
150
|
}
|
|
94
|
-
await runOp({
|
|
151
|
+
await runOp({
|
|
152
|
+
opId,
|
|
153
|
+
rawArgs: [
|
|
154
|
+
...args,
|
|
155
|
+
...(options.input ? ['--input', options.input] : []),
|
|
156
|
+
...(options.inputFile ? ['--input-file', options.inputFile] : []),
|
|
157
|
+
],
|
|
158
|
+
json: jsonFlag,
|
|
159
|
+
saveImages: valueOf('save-images') ?? options.saveImages,
|
|
160
|
+
});
|
|
95
161
|
});
|
|
96
162
|
// Hidden helper for skills that just need the cloud token.
|
|
97
163
|
program
|
package/package.json
CHANGED
|
@@ -1,58 +1,58 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@slatesvideo/cli",
|
|
3
|
-
"version": "0.5.
|
|
4
|
-
"description": "Slates CLI: drive the Slates AI video studio from your terminal or let Claude Code shell out to it. Includes the bundled agent skills and an MCP client configurator.",
|
|
5
|
-
"license": "MIT",
|
|
6
|
-
"type": "module",
|
|
7
|
-
"bin": {
|
|
8
|
-
"slates": "dist/index.js"
|
|
9
|
-
},
|
|
10
|
-
"main": "./dist/index.js",
|
|
11
|
-
"files": [
|
|
12
|
-
"dist",
|
|
13
|
-
"!dist/**/*.map",
|
|
14
|
-
"README.md"
|
|
15
|
-
],
|
|
16
|
-
"scripts": {
|
|
17
|
-
"build": "tsc",
|
|
18
|
-
"start": "node dist/index.js",
|
|
19
|
-
"typecheck": "tsc --noEmit",
|
|
20
|
-
"prepublishOnly": "npm run build"
|
|
21
|
-
},
|
|
22
|
-
"repository": {
|
|
23
|
-
"type": "git",
|
|
24
|
-
"url": "git+https://github.com/EricDisero/slates-mcp.git",
|
|
25
|
-
"directory": "packages/cli"
|
|
26
|
-
},
|
|
27
|
-
"homepage": "https://slates.video",
|
|
28
|
-
"bugs": {
|
|
29
|
-
"url": "https://github.com/EricDisero/slates-mcp/issues"
|
|
30
|
-
},
|
|
31
|
-
"keywords": [
|
|
32
|
-
"slates",
|
|
33
|
-
"cli",
|
|
34
|
-
"mcp",
|
|
35
|
-
"model-context-protocol",
|
|
36
|
-
"ai-video",
|
|
37
|
-
"video-generation",
|
|
38
|
-
"image-generation",
|
|
39
|
-
"claude",
|
|
40
|
-
"claude-code",
|
|
41
|
-
"agent-skills",
|
|
42
|
-
"veo",
|
|
43
|
-
"kling",
|
|
44
|
-
"seedance"
|
|
45
|
-
],
|
|
46
|
-
"engines": {
|
|
47
|
-
"node": ">=18"
|
|
48
|
-
},
|
|
49
|
-
"dependencies": {
|
|
50
|
-
"@slatesvideo/shared": "^0.6.
|
|
51
|
-
"commander": "^12.1.0",
|
|
52
|
-
"zod": "^3.23.0"
|
|
53
|
-
},
|
|
54
|
-
"devDependencies": {
|
|
55
|
-
"@types/node": "^20.0.0",
|
|
56
|
-
"typescript": "^5.7.0"
|
|
57
|
-
}
|
|
58
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@slatesvideo/cli",
|
|
3
|
+
"version": "0.5.14",
|
|
4
|
+
"description": "Slates CLI: drive the Slates AI video studio from your terminal or let Claude Code shell out to it. Includes the bundled agent skills and an MCP client configurator.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"bin": {
|
|
8
|
+
"slates": "dist/index.js"
|
|
9
|
+
},
|
|
10
|
+
"main": "./dist/index.js",
|
|
11
|
+
"files": [
|
|
12
|
+
"dist",
|
|
13
|
+
"!dist/**/*.map",
|
|
14
|
+
"README.md"
|
|
15
|
+
],
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "tsc",
|
|
18
|
+
"start": "node dist/index.js",
|
|
19
|
+
"typecheck": "tsc --noEmit",
|
|
20
|
+
"prepublishOnly": "npm run build"
|
|
21
|
+
},
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "git+https://github.com/EricDisero/slates-mcp.git",
|
|
25
|
+
"directory": "packages/cli"
|
|
26
|
+
},
|
|
27
|
+
"homepage": "https://slates.video",
|
|
28
|
+
"bugs": {
|
|
29
|
+
"url": "https://github.com/EricDisero/slates-mcp/issues"
|
|
30
|
+
},
|
|
31
|
+
"keywords": [
|
|
32
|
+
"slates",
|
|
33
|
+
"cli",
|
|
34
|
+
"mcp",
|
|
35
|
+
"model-context-protocol",
|
|
36
|
+
"ai-video",
|
|
37
|
+
"video-generation",
|
|
38
|
+
"image-generation",
|
|
39
|
+
"claude",
|
|
40
|
+
"claude-code",
|
|
41
|
+
"agent-skills",
|
|
42
|
+
"veo",
|
|
43
|
+
"kling",
|
|
44
|
+
"seedance"
|
|
45
|
+
],
|
|
46
|
+
"engines": {
|
|
47
|
+
"node": ">=18"
|
|
48
|
+
},
|
|
49
|
+
"dependencies": {
|
|
50
|
+
"@slatesvideo/shared": "^0.6.4",
|
|
51
|
+
"commander": "^12.1.0",
|
|
52
|
+
"zod": "^3.23.0"
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"@types/node": "^20.0.0",
|
|
56
|
+
"typescript": "^5.7.0"
|
|
57
|
+
}
|
|
58
|
+
}
|