@esquadrao/cli 1.7.1 → 1.9.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/README.md +33 -7
- package/assets/broll-catalog.json +11905 -0
- package/assets/studio-ui/index.html +512 -0
- package/bin/cli.js +10 -1
- package/package.json +4 -3
- package/scripts/cutout.py +83 -15
- package/scripts/dag_validator.js +38 -3
- package/scripts/lint.js +47 -7
- package/scripts/merkle_verify.js +6 -1
- package/skill-media-producer/SKILL.md +32 -0
- package/skill-media-producer/references/composicoes-especiais.md +1 -1
- package/skill-media-producer/references/configuracao-inicial.md +4 -10
- package/skill-media-producer/references/llm-agent-guide.md +31 -8
- package/src/binaries.js +74 -0
- package/src/commands/onboard.js +11 -16
- package/src/commands/setup.js +22 -20
- package/src/commands/studio.js +48 -1
- package/src/studio/jobTelemetry.js +239 -0
- package/src/studio/planSummary.js +76 -0
- package/src/studio/previewCache.js +90 -0
- package/src/studio/server.js +457 -0
- package/src/studio/stateDir.js +132 -0
|
@@ -0,0 +1,512 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="pt-BR">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
|
+
<title>Esquadrão Studio — Companion local</title>
|
|
7
|
+
<style>
|
|
8
|
+
:root {
|
|
9
|
+
color-scheme: dark;
|
|
10
|
+
--bg: #0a0b0d;
|
|
11
|
+
--panel: #121418;
|
|
12
|
+
--panel-2: #171a1f;
|
|
13
|
+
--line: #262a31;
|
|
14
|
+
--fg: #e9ecf1;
|
|
15
|
+
--muted: #9aa3af;
|
|
16
|
+
--accent: #ffe600;
|
|
17
|
+
--accent-ink: #12130a;
|
|
18
|
+
--ok: #3ddc97;
|
|
19
|
+
--warn: #ffb020;
|
|
20
|
+
--err: #ff5c6c;
|
|
21
|
+
--radius: 14px;
|
|
22
|
+
}
|
|
23
|
+
* { box-sizing: border-box; }
|
|
24
|
+
html, body { margin: 0; background: var(--bg); color: var(--fg); }
|
|
25
|
+
body { font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif; }
|
|
26
|
+
a { color: var(--accent); }
|
|
27
|
+
header {
|
|
28
|
+
position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 8px;
|
|
29
|
+
padding: 14px 22px; border-bottom: 1px solid var(--line); background: rgba(10, 11, 13, .92);
|
|
30
|
+
backdrop-filter: blur(6px);
|
|
31
|
+
}
|
|
32
|
+
.brand { font-weight: 700; letter-spacing: -.01em; margin-right: 10px; }
|
|
33
|
+
.brand span { color: var(--accent); }
|
|
34
|
+
nav { display: flex; gap: 6px; flex-wrap: wrap; }
|
|
35
|
+
nav button {
|
|
36
|
+
appearance: none; border: 1px solid transparent; background: transparent; color: var(--muted);
|
|
37
|
+
padding: 8px 14px; border-radius: 999px; cursor: pointer; font: inherit; font-weight: 600;
|
|
38
|
+
}
|
|
39
|
+
nav button:hover { color: var(--fg); background: var(--panel-2); }
|
|
40
|
+
nav button[aria-selected="true"] { background: var(--accent); color: var(--accent-ink); }
|
|
41
|
+
main { max-width: 1180px; margin: 0 auto; padding: 26px 22px 80px; }
|
|
42
|
+
section[hidden] { display: none; }
|
|
43
|
+
h1 { font-size: 26px; letter-spacing: -.02em; margin: 4px 0 6px; }
|
|
44
|
+
h2 { font-size: 18px; margin: 0 0 12px; letter-spacing: -.01em; }
|
|
45
|
+
p.lead { color: var(--muted); margin: 0 0 22px; max-width: 72ch; }
|
|
46
|
+
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
|
|
47
|
+
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
|
|
48
|
+
.card h3 { margin: 0 0 2px; font-size: 14.5px; }
|
|
49
|
+
.card .meta { color: var(--muted); font-size: 12px; font-family: ui-monospace, Menlo, Consolas, monospace; }
|
|
50
|
+
.card video { width: 100%; aspect-ratio: 9/16; border-radius: 10px; background: #000; margin: 10px 0; object-fit: cover; }
|
|
51
|
+
.pack { display: flex; justify-content: space-between; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 13.5px; }
|
|
52
|
+
.pack:last-child { border-bottom: 0; }
|
|
53
|
+
.pack small { color: var(--muted); display: block; }
|
|
54
|
+
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
|
|
55
|
+
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
|
|
56
|
+
label { display: block; font-size: 12px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin: 0 0 6px; font-weight: 700; }
|
|
57
|
+
select, input, textarea {
|
|
58
|
+
width: 100%; background: var(--panel-2); color: var(--fg); border: 1px solid var(--line);
|
|
59
|
+
border-radius: 10px; padding: 10px 12px; font: inherit;
|
|
60
|
+
}
|
|
61
|
+
textarea { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; min-height: 64px; resize: vertical; }
|
|
62
|
+
.actions { display: flex; gap: 10px; align-items: center; margin-top: 16px; flex-wrap: wrap; }
|
|
63
|
+
button.primary {
|
|
64
|
+
background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 10px;
|
|
65
|
+
padding: 11px 18px; font: inherit; font-weight: 700; cursor: pointer;
|
|
66
|
+
}
|
|
67
|
+
button.primary:disabled { opacity: .45; cursor: not-allowed; }
|
|
68
|
+
button.ghost {
|
|
69
|
+
background: transparent; color: var(--fg); border: 1px solid var(--line); border-radius: 10px;
|
|
70
|
+
padding: 10px 16px; font: inherit; font-weight: 600; cursor: pointer;
|
|
71
|
+
}
|
|
72
|
+
button.danger { color: var(--err); border-color: rgba(255, 92, 108, .4); }
|
|
73
|
+
.hint { color: var(--muted); font-size: 12.5px; }
|
|
74
|
+
.stages { display: flex; flex-wrap: wrap; gap: 6px; margin: 14px 0 6px; }
|
|
75
|
+
.stage {
|
|
76
|
+
font-size: 12px; padding: 5px 10px; border-radius: 999px; border: 1px solid var(--line);
|
|
77
|
+
color: var(--muted); font-family: ui-monospace, Menlo, Consolas, monospace;
|
|
78
|
+
}
|
|
79
|
+
.stage.active { border-color: var(--accent); color: var(--accent); }
|
|
80
|
+
.stage.done { border-color: rgba(61, 220, 151, .45); color: var(--ok); }
|
|
81
|
+
.stage.failed, .stage.canceled { border-color: rgba(255, 92, 108, .5); color: var(--err); }
|
|
82
|
+
.summary { margin: 12px 0 0; padding: 11px 14px; border: 1px solid rgba(255, 230, 0, .35); border-left: 3px solid var(--accent); border-radius: 8px; background: rgba(255, 230, 0, .06); font-size: 13.5px; }
|
|
83
|
+
pre.log {
|
|
84
|
+
background: #07080a; border: 1px solid var(--line); border-radius: 10px; padding: 12px;
|
|
85
|
+
height: 260px; overflow: auto; font: 12.5px/1.5 ui-monospace, Menlo, Consolas, monospace;
|
|
86
|
+
white-space: pre-wrap; margin: 12px 0 0;
|
|
87
|
+
}
|
|
88
|
+
.pill { display: inline-block; font-size: 11.5px; padding: 3px 9px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
|
|
89
|
+
.pill.ok { color: var(--ok); border-color: rgba(61, 220, 151, .4); }
|
|
90
|
+
.pill.err { color: var(--err); border-color: rgba(255, 92, 108, .4); }
|
|
91
|
+
.job { border-bottom: 1px solid var(--line); padding: 12px 0; }
|
|
92
|
+
.job:last-child { border-bottom: 0; }
|
|
93
|
+
.job-head { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; flex-wrap: wrap; }
|
|
94
|
+
.job video { width: 100%; max-height: 420px; border-radius: 10px; background: #000; margin-top: 10px; }
|
|
95
|
+
.empty { color: var(--muted); padding: 24px; text-align: center; border: 1px dashed var(--line); border-radius: var(--radius); }
|
|
96
|
+
.toast { position: fixed; right: 18px; bottom: 18px; background: #1b1f26; border: 1px solid var(--line); padding: 12px 16px; border-radius: 10px; max-width: 380px; }
|
|
97
|
+
.toast.err { border-color: rgba(255, 92, 108, .5); color: var(--err); }
|
|
98
|
+
@media (max-width: 720px) { .row { grid-template-columns: 1fr; } main { padding: 18px 14px 60px; } }
|
|
99
|
+
</style>
|
|
100
|
+
</head>
|
|
101
|
+
<body>
|
|
102
|
+
<header>
|
|
103
|
+
<div class="brand">Esquadrão <span>Studio</span></div>
|
|
104
|
+
<nav role="tablist" aria-label="Telas">
|
|
105
|
+
<button role="tab" data-screen="catalog" aria-selected="true">Catálogo Visual</button>
|
|
106
|
+
<button role="tab" data-screen="run" aria-selected="false">Execução Ao Vivo</button>
|
|
107
|
+
<button role="tab" data-screen="result" aria-selected="false">Resultado & QA</button>
|
|
108
|
+
</nav>
|
|
109
|
+
</header>
|
|
110
|
+
|
|
111
|
+
<main>
|
|
112
|
+
<section id="screen-catalog">
|
|
113
|
+
<h1>Catálogo Visual</h1>
|
|
114
|
+
<p class="lead">Nove templates de legenda com preview de 5 s gerado localmente, e os packs descritos no catálogo semântico do workspace. Tudo lido da sua máquina.</p>
|
|
115
|
+
<h2>Templates de legenda</h2>
|
|
116
|
+
<div id="templates" class="grid"><div class="empty">Carregando templates…</div></div>
|
|
117
|
+
<h2 style="margin-top:30px">Packs locais</h2>
|
|
118
|
+
<div class="panel" id="packs"><div class="empty">Nenhum pack carregado.</div></div>
|
|
119
|
+
</section>
|
|
120
|
+
|
|
121
|
+
<section id="screen-run" hidden>
|
|
122
|
+
<h1>Execução Ao Vivo</h1>
|
|
123
|
+
<p class="lead">Dispare um job no workspace autorizado e acompanhe os estágios. A fila da interface aceita um job por vez; execuções feitas pela LLM no terminal aparecem apenas como observação.</p>
|
|
124
|
+
<div class="panel">
|
|
125
|
+
<div class="row">
|
|
126
|
+
<div>
|
|
127
|
+
<label for="workspace">Workspace</label>
|
|
128
|
+
<select id="workspace"></select>
|
|
129
|
+
</div>
|
|
130
|
+
<div>
|
|
131
|
+
<label for="command">Comando</label>
|
|
132
|
+
<select id="command">
|
|
133
|
+
<option value="render">studio render <editplan.json></option>
|
|
134
|
+
<option value="auto-clip">studio auto-clip <video></option>
|
|
135
|
+
<option value="batch">studio batch <dir></option>
|
|
136
|
+
<option value="cutout">studio cutout <video> --background <pack></option>
|
|
137
|
+
<option value="onboard">onboard</option>
|
|
138
|
+
</select>
|
|
139
|
+
</div>
|
|
140
|
+
</div>
|
|
141
|
+
<div style="margin-top:14px">
|
|
142
|
+
<label for="args">Argumentos (separados por espaço)</label>
|
|
143
|
+
<textarea id="args" placeholder="packages/editplan.json --caption-template mrbeast-yellow"></textarea>
|
|
144
|
+
<p class="hint">Sem <code>--openai</code>: a UI nunca lê ou repassa <code>OPENAI_API_KEY</code>. Para transcrição remota, rode no terminal.</p>
|
|
145
|
+
</div>
|
|
146
|
+
<div class="actions">
|
|
147
|
+
<button class="primary" id="start">Iniciar job</button>
|
|
148
|
+
<button class="ghost danger" id="cancel" disabled>Cancelar job</button>
|
|
149
|
+
<button class="ghost" id="goto-result" hidden>Ver resultado & QA</button>
|
|
150
|
+
<span class="hint" id="run-status">Nenhum job em execução.</span>
|
|
151
|
+
</div>
|
|
152
|
+
</div>
|
|
153
|
+
<div class="panel" style="margin-top:16px">
|
|
154
|
+
<h2>Estágios</h2>
|
|
155
|
+
<div class="stages" id="stages"></div>
|
|
156
|
+
<div class="summary" id="summary" hidden></div>
|
|
157
|
+
<pre class="log" id="log" aria-live="polite"></pre>
|
|
158
|
+
</div>
|
|
159
|
+
</section>
|
|
160
|
+
|
|
161
|
+
<section id="screen-result" hidden>
|
|
162
|
+
<h1>Resultado & QA</h1>
|
|
163
|
+
<p class="lead">Histórico local de jobs. Quando o QA aprova, o MP4 final aparece aqui para revisão antes de publicar.</p>
|
|
164
|
+
<div class="panel" id="jobs"><div class="empty">Nenhum job registrado.</div></div>
|
|
165
|
+
</section>
|
|
166
|
+
</main>
|
|
167
|
+
|
|
168
|
+
<script>
|
|
169
|
+
(() => {
|
|
170
|
+
'use strict';
|
|
171
|
+
const STAGES = ['queued','importing','detecting_silence','transcribing','planning','rendering','qa','done','failed','canceled'];
|
|
172
|
+
const LABELS = {
|
|
173
|
+
queued: 'na fila', importing: 'importando', detecting_silence: 'detectando silêncio',
|
|
174
|
+
transcribing: 'transcrevendo', planning: 'planejando', rendering: 'renderizando',
|
|
175
|
+
qa: 'verificando QA', done: 'concluído', failed: 'falhou', canceled: 'cancelado'
|
|
176
|
+
};
|
|
177
|
+
const hash = new URLSearchParams(location.hash.replace(/^#/, ''));
|
|
178
|
+
let token = hash.get('t') || sessionStorage.getItem('esq.token') || '';
|
|
179
|
+
if (token) sessionStorage.setItem('esq.token', token);
|
|
180
|
+
let activeJob = null;
|
|
181
|
+
let streamAbort = null;
|
|
182
|
+
let observedJobId = null;
|
|
183
|
+
let blobs = [];
|
|
184
|
+
|
|
185
|
+
const el = (id) => document.getElementById(id);
|
|
186
|
+
|
|
187
|
+
function toast(message, isError = false) {
|
|
188
|
+
const node = document.createElement('div');
|
|
189
|
+
node.className = 'toast' + (isError ? ' err' : '');
|
|
190
|
+
node.textContent = message;
|
|
191
|
+
document.body.appendChild(node);
|
|
192
|
+
setTimeout(() => node.remove(), 6000);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
async function api(path, options = {}) {
|
|
196
|
+
if (!token) throw new Error('Token ausente: abra a URL impressa pelo comando serve (com #t=...).');
|
|
197
|
+
const res = await fetch(path, {
|
|
198
|
+
...options,
|
|
199
|
+
headers: { 'X-Esquadrao-Token': token, ...(options.body ? { 'Content-Type': 'application/json' } : {}), ...(options.headers || {}) },
|
|
200
|
+
});
|
|
201
|
+
if (!res.ok) {
|
|
202
|
+
let detail = {};
|
|
203
|
+
try { detail = await res.json(); } catch {}
|
|
204
|
+
throw new Error(detail.error || ('HTTP ' + res.status));
|
|
205
|
+
}
|
|
206
|
+
return res;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function show(screen) {
|
|
210
|
+
for (const button of document.querySelectorAll('nav button')) {
|
|
211
|
+
button.setAttribute('aria-selected', String(button.dataset.screen === screen));
|
|
212
|
+
}
|
|
213
|
+
for (const section of document.querySelectorAll('main section')) {
|
|
214
|
+
section.hidden = section.id !== 'screen-' + screen;
|
|
215
|
+
}
|
|
216
|
+
if (screen === 'result') loadJobs();
|
|
217
|
+
if (screen === 'run') loadWorkspaces();
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
async function loadTemplates() {
|
|
221
|
+
const box = el('templates');
|
|
222
|
+
try {
|
|
223
|
+
const data = await (await api('/api/catalog')).json();
|
|
224
|
+
if (!data.templates.length) { box.innerHTML = '<div class="empty">Nenhum template disponível.</div>'; return; }
|
|
225
|
+
box.innerHTML = '';
|
|
226
|
+
for (const template of data.templates) {
|
|
227
|
+
const card = document.createElement('article');
|
|
228
|
+
card.className = 'card';
|
|
229
|
+
const title = document.createElement('h3');
|
|
230
|
+
title.textContent = template.name;
|
|
231
|
+
const meta = document.createElement('div');
|
|
232
|
+
meta.className = 'meta';
|
|
233
|
+
meta.textContent = template.id + ' · ' + template.font + ' · ' + template.font_size + 'px';
|
|
234
|
+
const video = document.createElement('video');
|
|
235
|
+
video.muted = true; video.loop = true; video.playsInline = true; video.autoplay = true;
|
|
236
|
+
video.setAttribute('aria-label', 'Preview do template ' + template.name);
|
|
237
|
+
card.append(title, meta, video);
|
|
238
|
+
box.appendChild(card);
|
|
239
|
+
api('/api/previews/' + encodeURIComponent(template.id) + '.mp4')
|
|
240
|
+
.then((res) => res.blob())
|
|
241
|
+
.then((blob) => { const url = URL.createObjectURL(blob); blobs.push(url); video.src = url; })
|
|
242
|
+
.catch(() => { meta.textContent += ' · preview indisponível'; });
|
|
243
|
+
}
|
|
244
|
+
const packs = el('packs');
|
|
245
|
+
if (!data.items.length) {
|
|
246
|
+
packs.innerHTML = '<div class="empty">Nenhum pack em .esquadrao/broll-catalog.json neste workspace.</div>';
|
|
247
|
+
} else {
|
|
248
|
+
packs.innerHTML = '';
|
|
249
|
+
for (const item of data.items.slice(0, 200)) {
|
|
250
|
+
const row = document.createElement('div');
|
|
251
|
+
row.className = 'pack';
|
|
252
|
+
const left = document.createElement('div');
|
|
253
|
+
const name = document.createElement('div');
|
|
254
|
+
name.textContent = item.filename || item.id;
|
|
255
|
+
const desc = document.createElement('small');
|
|
256
|
+
desc.textContent = [item.pack, item.description, (item.tags || []).join(', ')].filter(Boolean).join(' · ');
|
|
257
|
+
left.append(name, desc);
|
|
258
|
+
const dur = document.createElement('span');
|
|
259
|
+
dur.className = 'pill';
|
|
260
|
+
dur.textContent = item.duration_ms ? (item.duration_ms / 1000).toFixed(1) + ' s' : (item.pack || 'pack');
|
|
261
|
+
row.append(left, dur);
|
|
262
|
+
packs.appendChild(row);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
} catch (err) {
|
|
266
|
+
box.innerHTML = '<div class="empty">' + err.message + '</div>';
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
async function loadWorkspaces() {
|
|
271
|
+
const select = el('workspace');
|
|
272
|
+
try {
|
|
273
|
+
const data = await (await api('/api/workspaces')).json();
|
|
274
|
+
select.innerHTML = '';
|
|
275
|
+
for (const workspace of data.workspaces) {
|
|
276
|
+
const option = document.createElement('option');
|
|
277
|
+
option.value = workspace.path;
|
|
278
|
+
option.textContent = workspace.name + ' — ' + workspace.path;
|
|
279
|
+
option.selected = workspace.path === data.active;
|
|
280
|
+
select.appendChild(option);
|
|
281
|
+
}
|
|
282
|
+
if (!data.workspaces.length) {
|
|
283
|
+
const option = document.createElement('option');
|
|
284
|
+
option.textContent = 'Nenhum workspace autorizado';
|
|
285
|
+
select.appendChild(option);
|
|
286
|
+
}
|
|
287
|
+
} catch (err) {
|
|
288
|
+
select.innerHTML = '<option>' + err.message + '</option>';
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
function splitArgs(text) {
|
|
293
|
+
const source = String(text || '').trim();
|
|
294
|
+
if (!source) return [];
|
|
295
|
+
const args = [];
|
|
296
|
+
const pattern = /"([^"]*)"|'([^']*)'|(\S+)/g;
|
|
297
|
+
let match;
|
|
298
|
+
while ((match = pattern.exec(source))) {
|
|
299
|
+
args.push(match[1] !== undefined ? match[1] : (match[2] !== undefined ? match[2] : match[3]));
|
|
300
|
+
}
|
|
301
|
+
return args;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
function renderStages(current, terminal) {
|
|
305
|
+
const box = el('stages');
|
|
306
|
+
box.innerHTML = '';
|
|
307
|
+
const currentIndex = STAGES.indexOf(current);
|
|
308
|
+
for (const stage of STAGES) {
|
|
309
|
+
const chip = document.createElement('span');
|
|
310
|
+
chip.className = 'stage';
|
|
311
|
+
chip.textContent = LABELS[stage] || stage;
|
|
312
|
+
if (stage === current || (terminal && stage === current)) chip.classList.add(stage === 'failed' || stage === 'canceled' ? stage : 'active');
|
|
313
|
+
else if (!terminal && currentIndex > -1 && STAGES.indexOf(stage) < currentIndex && !['done','failed','canceled'].includes(stage)) chip.classList.add('done');
|
|
314
|
+
box.appendChild(chip);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
function appendLog(line) {
|
|
319
|
+
const log = el('log');
|
|
320
|
+
log.textContent += line + '\n';
|
|
321
|
+
log.scrollTop = log.scrollHeight;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
async function follow(jobId, options = {}) {
|
|
325
|
+
if (streamAbort) streamAbort.abort();
|
|
326
|
+
const controller = new AbortController();
|
|
327
|
+
streamAbort = controller;
|
|
328
|
+
el('log').textContent = '';
|
|
329
|
+
el('summary').hidden = true;
|
|
330
|
+
el('summary').textContent = '';
|
|
331
|
+
el('goto-result').hidden = true;
|
|
332
|
+
activeJob = jobId;
|
|
333
|
+
el('cancel').disabled = false;
|
|
334
|
+
el('start').disabled = false;
|
|
335
|
+
el('run-status').textContent = options.external
|
|
336
|
+
? 'Observando execução externa (' + (options.command || jobId) + ')'
|
|
337
|
+
: 'Job ' + jobId + ' em execução.';
|
|
338
|
+
try {
|
|
339
|
+
const res = await fetch('/api/jobs/' + encodeURIComponent(jobId) + '/events', {
|
|
340
|
+
headers: { 'X-Esquadrao-Token': token }, signal: controller.signal,
|
|
341
|
+
});
|
|
342
|
+
if (!res.ok || !res.body) throw new Error('SSE indisponível (HTTP ' + res.status + ')');
|
|
343
|
+
const reader = res.body.getReader();
|
|
344
|
+
const decoder = new TextDecoder();
|
|
345
|
+
let buffer = '';
|
|
346
|
+
for (;;) {
|
|
347
|
+
const { value, done } = await reader.read();
|
|
348
|
+
if (done) break;
|
|
349
|
+
buffer += decoder.decode(value, { stream: true });
|
|
350
|
+
const frames = buffer.split('\n\n');
|
|
351
|
+
buffer = frames.pop() || '';
|
|
352
|
+
for (const frame of frames) {
|
|
353
|
+
const dataLine = frame.split('\n').find((l) => l.startsWith('data: '));
|
|
354
|
+
if (!dataLine) continue;
|
|
355
|
+
let event;
|
|
356
|
+
try { event = JSON.parse(dataLine.slice(6)); } catch { continue; }
|
|
357
|
+
if (event.type === 'stage') {
|
|
358
|
+
renderStages(event.stage, ['done','failed','canceled'].includes(event.stage));
|
|
359
|
+
appendLog('[' + event.stage + '] ' + (LABELS[event.stage] || ''));
|
|
360
|
+
if (['done','failed','canceled'].includes(event.stage)) {
|
|
361
|
+
el('cancel').disabled = true;
|
|
362
|
+
el('start').disabled = false;
|
|
363
|
+
el('run-status').textContent = options.external
|
|
364
|
+
? 'Execução externa (' + (options.command || jobId) + '): ' + (LABELS[event.stage] || event.stage) + '.'
|
|
365
|
+
: 'Job ' + jobId + ': ' + (LABELS[event.stage] || event.stage) + '.';
|
|
366
|
+
if (event.stage === 'done') el('goto-result').hidden = false;
|
|
367
|
+
controller.abort();
|
|
368
|
+
return;
|
|
369
|
+
}
|
|
370
|
+
} else if (event.type === 'log') {
|
|
371
|
+
appendLog(String(event.payload && event.payload.line || ''));
|
|
372
|
+
} else if (event.type === 'plan_summary') {
|
|
373
|
+
const text = String(event.payload && event.payload.text || '');
|
|
374
|
+
const box = el('summary');
|
|
375
|
+
box.textContent = text;
|
|
376
|
+
box.hidden = !text;
|
|
377
|
+
appendLog('Resumo: ' + text);
|
|
378
|
+
} else if (event.type === 'artifact') {
|
|
379
|
+
appendLog('Artefato: ' + (event.payload && event.payload.path || ''));
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
} catch (err) {
|
|
384
|
+
if (err.name !== 'AbortError') {
|
|
385
|
+
appendLog('Erro no stream: ' + err.message);
|
|
386
|
+
toast(err.message, true);
|
|
387
|
+
}
|
|
388
|
+
} finally {
|
|
389
|
+
if (streamAbort === controller) {
|
|
390
|
+
streamAbort = null;
|
|
391
|
+
activeJob = null;
|
|
392
|
+
el('start').disabled = false;
|
|
393
|
+
el('cancel').disabled = true;
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
async function pollExternal() {
|
|
399
|
+
if (!token || activeJob) return;
|
|
400
|
+
try {
|
|
401
|
+
const data = await (await api('/api/jobs')).json();
|
|
402
|
+
const job = data.jobs.find((j) => (j.status === 'running' || j.status === 'queued') && j.id !== observedJobId);
|
|
403
|
+
if (!job) return;
|
|
404
|
+
observedJobId = job.id;
|
|
405
|
+
show('run');
|
|
406
|
+
el('run-status').textContent = 'Observando execução externa (' + job.command + ')';
|
|
407
|
+
await follow(job.id, { external: true, command: job.command });
|
|
408
|
+
} catch {}
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
async function startJob() {
|
|
412
|
+
const workspace = el('workspace').value;
|
|
413
|
+
const command = el('command').value;
|
|
414
|
+
const args = splitArgs(el('args').value);
|
|
415
|
+
el('start').disabled = true;
|
|
416
|
+
activeJob = 'pending';
|
|
417
|
+
try {
|
|
418
|
+
const res = await api('/api/jobs', { method: 'POST', body: JSON.stringify({ command, workspace, args }) });
|
|
419
|
+
const data = await res.json();
|
|
420
|
+
renderStages('queued', false);
|
|
421
|
+
await follow(data.job_id);
|
|
422
|
+
} catch (err) {
|
|
423
|
+
activeJob = null;
|
|
424
|
+
toast(err.message, true);
|
|
425
|
+
el('start').disabled = false;
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
async function cancelJob() {
|
|
430
|
+
if (!activeJob) return;
|
|
431
|
+
try {
|
|
432
|
+
await api('/api/jobs/' + encodeURIComponent(activeJob) + '/cancel', { method: 'POST' });
|
|
433
|
+
toast('Cancelamento enviado (SIGINT).');
|
|
434
|
+
} catch (err) {
|
|
435
|
+
toast(err.message, true);
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
async function loadJobs() {
|
|
440
|
+
const box = el('jobs');
|
|
441
|
+
try {
|
|
442
|
+
const data = await (await api('/api/jobs')).json();
|
|
443
|
+
if (!data.jobs.length) { box.innerHTML = '<div class="empty">Nenhum job registrado.</div>'; return; }
|
|
444
|
+
box.innerHTML = '';
|
|
445
|
+
for (const job of data.jobs.slice(0, 30)) {
|
|
446
|
+
const row = document.createElement('div');
|
|
447
|
+
row.className = 'job';
|
|
448
|
+
const head = document.createElement('div');
|
|
449
|
+
head.className = 'job-head';
|
|
450
|
+
const left = document.createElement('div');
|
|
451
|
+
const title = document.createElement('div');
|
|
452
|
+
title.textContent = job.command + ' · ' + job.id;
|
|
453
|
+
const meta = document.createElement('div');
|
|
454
|
+
meta.className = 'meta';
|
|
455
|
+
meta.textContent = (job.workspace || '—') + ' · ' + (job.created_at || '');
|
|
456
|
+
left.append(title, meta);
|
|
457
|
+
const pill = document.createElement('span');
|
|
458
|
+
const status = job.status || 'unknown';
|
|
459
|
+
pill.className = 'pill ' + (status === 'done' ? 'ok' : (status === 'failed' || status === 'canceled' ? 'err' : ''));
|
|
460
|
+
pill.textContent = LABELS[status] || status;
|
|
461
|
+
head.append(left, pill);
|
|
462
|
+
row.appendChild(head);
|
|
463
|
+
if (job.artifact && job.artifact.id) {
|
|
464
|
+
const video = document.createElement('video');
|
|
465
|
+
video.controls = true; video.playsInline = true;
|
|
466
|
+
video.setAttribute('aria-label', 'Vídeo do job ' + job.id);
|
|
467
|
+
row.appendChild(video);
|
|
468
|
+
api('/api/artifacts/' + encodeURIComponent(job.artifact.id))
|
|
469
|
+
.then((res) => res.blob())
|
|
470
|
+
.then((blob) => { const url = URL.createObjectURL(blob); blobs.push(url); video.src = url; })
|
|
471
|
+
.catch(() => {});
|
|
472
|
+
}
|
|
473
|
+
box.appendChild(row);
|
|
474
|
+
}
|
|
475
|
+
} catch (err) {
|
|
476
|
+
box.innerHTML = '<div class="empty">' + err.message + '</div>';
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
for (const button of document.querySelectorAll('nav button')) {
|
|
481
|
+
button.addEventListener('click', () => show(button.dataset.screen));
|
|
482
|
+
}
|
|
483
|
+
el('start').addEventListener('click', startJob);
|
|
484
|
+
el('cancel').addEventListener('click', cancelJob);
|
|
485
|
+
el('goto-result').addEventListener('click', () => show('result'));
|
|
486
|
+
el('command').addEventListener('change', () => {
|
|
487
|
+
const value = el('command').value;
|
|
488
|
+
const hint = {
|
|
489
|
+
render: 'packages/editplan.json --caption-template mrbeast-yellow',
|
|
490
|
+
'auto-clip': 'assets/AST-xxxxxxxx.mp4 --no-captions --format 9:16',
|
|
491
|
+
batch: 'packages --stop-on-error',
|
|
492
|
+
cutout: 'assets/AST-xxxxxxxx.mp4 --background packs/pack.mp4',
|
|
493
|
+
onboard: '--mode dark --dest .',
|
|
494
|
+
}[value] || '';
|
|
495
|
+
el('args').value = hint;
|
|
496
|
+
});
|
|
497
|
+
window.addEventListener('beforeunload', () => { for (const url of blobs) URL.revokeObjectURL(url); });
|
|
498
|
+
|
|
499
|
+
if (!token) {
|
|
500
|
+
const input = prompt('Token da sessão (aparece no fragmento #t= da URL impressa pelo serve):');
|
|
501
|
+
if (input) { token = input.trim(); sessionStorage.setItem('esq.token', token); }
|
|
502
|
+
}
|
|
503
|
+
if (token) {
|
|
504
|
+
loadTemplates();
|
|
505
|
+
renderStages('queued', false);
|
|
506
|
+
pollExternal();
|
|
507
|
+
setInterval(pollExternal, 1500);
|
|
508
|
+
}
|
|
509
|
+
})();
|
|
510
|
+
</script>
|
|
511
|
+
</body>
|
|
512
|
+
</html>
|
package/bin/cli.js
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
import { parseArgs } from 'node:util';
|
|
3
3
|
import { existsSync, readFileSync } from 'node:fs';
|
|
4
4
|
import process from 'node:process';
|
|
5
|
+
import { ensureBundledPath } from '../src/binaries.js';
|
|
6
|
+
|
|
7
|
+
// FFmpeg/ffprobe embutidos: injeta no PATH antes de qualquer comando.
|
|
8
|
+
ensureBundledPath();
|
|
5
9
|
|
|
6
10
|
if (typeof process.loadEnvFile === 'function' && existsSync('.env')) {
|
|
7
11
|
try { process.loadEnvFile(); } catch {}
|
|
@@ -9,6 +13,7 @@ if (typeof process.loadEnvFile === 'function' && existsSync('.env')) {
|
|
|
9
13
|
|
|
10
14
|
const pkg = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
|
|
11
15
|
|
|
16
|
+
|
|
12
17
|
const { values: flags, positionals } = parseArgs({
|
|
13
18
|
args: process.argv.slice(2),
|
|
14
19
|
options: {
|
|
@@ -40,6 +45,8 @@ const { values: flags, positionals } = parseArgs({
|
|
|
40
45
|
'min-dur': { type: 'string' },
|
|
41
46
|
'max-dur': { type: 'string' },
|
|
42
47
|
'stop-on-error': { type: 'boolean' },
|
|
48
|
+
port: { type: 'string' },
|
|
49
|
+
'no-open': { type: 'boolean' },
|
|
43
50
|
},
|
|
44
51
|
allowPositionals: true,
|
|
45
52
|
strict: false,
|
|
@@ -63,7 +70,7 @@ Usage:
|
|
|
63
70
|
Commands:
|
|
64
71
|
setup Instala os skills nos ambientes de agentes (.agents, .claude, .codex, .cursor)
|
|
65
72
|
role Lista, inspeciona e executa papéis canônicos da esteira
|
|
66
|
-
studio Estúdio local de vídeo: init, import, render, qa, batch, auto-clip, cutout, caption-templates
|
|
73
|
+
studio Estúdio local de vídeo: init, import, render, qa, batch, auto-clip, cutout, serve, caption-templates
|
|
67
74
|
onboard Guia interativo: da mídia bruta ao primeiro corte renderizado
|
|
68
75
|
version Exibe a versão do CLI
|
|
69
76
|
help Exibe mensagens de ajuda
|
|
@@ -72,6 +79,8 @@ Options:
|
|
|
72
79
|
-h, --help Show help
|
|
73
80
|
-v, --version Show version
|
|
74
81
|
--json Output results in JSON format
|
|
82
|
+
--port <n> Porta do companion visual (padrão: 4310)
|
|
83
|
+
--no-open Não abrir o navegador ao iniciar o studio serve
|
|
75
84
|
--dest <path> Custom destination directory for skills or workspace
|
|
76
85
|
--mode <mode> Video mode for onboarding (edit_only, dark, podcast_clip)
|
|
77
86
|
--file <path> Source media file for onboarding (can be repeated)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@esquadrao/cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.0",
|
|
4
4
|
"description": "Esquadrão CLI and autonomous skill orchestration framework for AI agents",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -52,8 +52,9 @@
|
|
|
52
52
|
"cli"
|
|
53
53
|
],
|
|
54
54
|
"license": "MIT",
|
|
55
|
-
"dependencies": {},
|
|
56
55
|
"optionalDependencies": {
|
|
57
|
-
"@xenova/transformers": "^2.17.2"
|
|
56
|
+
"@xenova/transformers": "^2.17.2",
|
|
57
|
+
"ffmpeg-static": "5.2.0",
|
|
58
|
+
"ffprobe-static": "^3.1.0"
|
|
58
59
|
}
|
|
59
60
|
}
|