@biunow/agent-biutalk 2.0.1 → 2.0.2

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.
@@ -0,0 +1,66 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * 输出收敛器:跑一条命令,只把"错误 + 结尾 20 行"还给模型,完整日志落盘。
4
+ *
5
+ * node run-quiet.mjs -- npx tsc -p . --noUnusedLocals
6
+ * node run-quiet.mjs --lines 12 -- explainroo render . --draft
7
+ *
8
+ * 为什么:渲染/编译工具的日志动辄几百上千行,全塞进上下文等于白烧 token;
9
+ * 但这些日志 99% 是进度条和重复警告,真正有用的是错误行和最后十几行。
10
+ *
11
+ * 输出格式(固定 3 段,总行数 ≤ lines+3):
12
+ * [quiet] exit=0 ok log=<path> 全输出 <n> 字节
13
+ * [quiet] 关键行: …(最多 lines 行)
14
+ */
15
+ import fs from 'node:fs';
16
+ import path from 'node:path';
17
+ import { spawn } from 'node:child_process';
18
+
19
+ const argv = process.argv.slice(2);
20
+ let lines = 20;
21
+ const sep = argv.indexOf('--');
22
+ const head = sep >= 0 ? argv.slice(0, sep) : [];
23
+ const cmd = sep >= 0 ? argv.slice(sep + 1) : argv;
24
+ for (let i = 0; i < head.length; i += 1) {
25
+ if (head[i] === '--lines') lines = Math.max(3, Number(head[i + 1]) || 20);
26
+ }
27
+ if (!cmd.length) {
28
+ console.error('usage: node run-quiet.mjs [--lines N] -- <command> [args...]');
29
+ process.exit(2);
30
+ }
31
+
32
+ const logDir = path.join(process.cwd(), '.logs');
33
+ fs.mkdirSync(logDir, { recursive: true });
34
+ const stamp = new Date().toISOString().replace(/[:.]/g, '-');
35
+ const logFile = path.join(logDir, `${stamp}.log`);
36
+
37
+ const child = spawn(cmd[0], cmd.slice(1), { stdio: ['ignore', 'pipe', 'pipe'], windowsHide: true });
38
+ let out = '';
39
+ let err = '';
40
+ child.stdout.on('data', (chunk) => { out += chunk.toString(); });
41
+ child.stderr.on('data', (chunk) => { err += chunk.toString(); });
42
+
43
+ const started = Date.now();
44
+ child.once('error', (error) => {
45
+ console.log(`[quiet] exit=127 fail log=- 启动失败:${error.message}`);
46
+ process.exit(127);
47
+ });
48
+
49
+ child.once('close', (code) => {
50
+ const seconds = ((Date.now() - started) / 1000).toFixed(1);
51
+ const all = `${out}${err}`;
52
+ fs.writeFileSync(logFile, all, 'utf8');
53
+ const bytes = Buffer.byteLength(all);
54
+ const keep = all
55
+ .split(/\r?\n/)
56
+ .map((line) => line.trimEnd())
57
+ .filter((line) => line.length > 0)
58
+ .slice(-lines);
59
+ const status = code === 0 ? 'ok' : 'fail';
60
+ console.log(`[quiet] exit=${code} ${status} ${seconds}s log=${path.relative(process.cwd(), logFile)} 全输出 ${bytes} 字节`);
61
+ if (keep.length) {
62
+ console.log('[quiet] 关键行:');
63
+ for (const line of keep) console.log(` ${line.slice(0, 400)}`);
64
+ }
65
+ process.exit(code === null ? 1 : code);
66
+ });
@@ -0,0 +1,105 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * 一步到底的闸门聚合器:把 EXEC 里"要连着敲 3–6 条命令"的阶段压成一条。
4
+ *
5
+ * node stage.mjs pre --project . --engine "$ENGINE" [--ep <EP>]
6
+ * node stage.mjs post --project . --video out/final.mp4 [--ep <EP>] [--job job.json]
7
+ *
8
+ * 为什么:每次工具调用都会把整段上下文重发一遍,模型侧的 token 大致按「轮数²」涨。
9
+ * 把 5 条命令并成 1 条,等于把这一阶段的轮数从 5 降到 1;子命令输出也只回摘要。
10
+ *
11
+ * 配置在同目录 stages.json;`{engine}` `{project}` `{ep}` `{video}` `{job}` 会被替换。
12
+ * 输出固定 ≤8 行:一条总判定 + 每个失败项一行 `code hint`。
13
+ */
14
+ import fs from 'node:fs';
15
+ import path from 'node:path';
16
+ import { spawn } from 'node:child_process';
17
+ import { fileURLToPath } from 'node:url';
18
+
19
+ const here = path.dirname(fileURLToPath(import.meta.url));
20
+ const argv = process.argv.slice(2);
21
+ const stageName = argv.find((a) => !a.startsWith('--')) || '';
22
+ const opt = (name, fallback = '') => {
23
+ const i = argv.indexOf(name);
24
+ return i >= 0 && argv[i + 1] && !argv[i + 1].startsWith('--') ? argv[i + 1] : fallback;
25
+ };
26
+
27
+ const project = path.resolve(opt('--project', process.cwd()));
28
+ const engine = opt('--engine', process.env.ENGINE_ROOT || '');
29
+ const ep = opt('--ep', '');
30
+ const video = opt('--video', '');
31
+ const job = opt('--job', '');
32
+
33
+ if (!stageName) {
34
+ console.error('usage: node stage.mjs <stage> [--project .] [--engine DIR] [--ep ID] [--video FILE] [--job FILE]');
35
+ process.exit(2);
36
+ }
37
+
38
+ const cfgFile = path.join(here, 'stages.json');
39
+ if (!fs.existsSync(cfgFile)) {
40
+ console.error(`missing ${cfgFile}`);
41
+ process.exit(2);
42
+ }
43
+ const cfg = JSON.parse(fs.readFileSync(cfgFile, 'utf8').replace(/^\uFEFF/, ''));
44
+ const steps = cfg.stages?.[stageName];
45
+ if (!Array.isArray(steps) || !steps.length) {
46
+ console.error(`unknown stage "${stageName}"; have: ${Object.keys(cfg.stages || {}).join(', ')}`);
47
+ process.exit(2);
48
+ }
49
+
50
+ const vars = { engine, project, ep, video, job, skill: here };
51
+ const fill = (value) => String(value).replace(/\{(\w+)\}/g, (m, key) => (vars[key] ?? m));
52
+
53
+ function run(step) {
54
+ const [label, cmd, ...rest] = step;
55
+ const args = rest.map(fill);
56
+ return new Promise((resolve) => {
57
+ const child = spawn(cmd, args, { cwd: project, stdio: ['ignore', 'pipe', 'pipe'], windowsHide: true });
58
+ let out = '';
59
+ let err = '';
60
+ child.stdout.on('data', (c) => { out += c.toString(); });
61
+ child.stderr.on('data', (c) => { err += c.toString(); });
62
+ child.once('error', (e) => resolve({ label, code: 127, out: '', err: e.message }));
63
+ child.once('close', (code) => resolve({ label, code: code ?? 1, out, err }));
64
+ });
65
+ }
66
+
67
+ /** 从任意子命令输出里抠失败提示:优先 hint/detail 字段,退化到错误行。 */
68
+ function digest(text) {
69
+ const hints = [];
70
+ for (const m of text.matchAll(/"(?:hint|detail)"\s*:\s*"((?:[^"\\]|\\.)*)"/g)) {
71
+ const value = m[1].replace(/\\"/g, '"').replace(/\\\\/g, '\\');
72
+ if (value && value.length < 300) hints.push(value);
73
+ if (hints.length >= 5) break;
74
+ }
75
+ const okFlag = /"ok"\s*:\s*true/.test(text);
76
+ return { ok: okFlag, hints };
77
+ }
78
+
79
+ const started = Date.now();
80
+ const lines = [];
81
+ let failed = false;
82
+
83
+ for (const step of steps) {
84
+ if (failed) break;
85
+ const result = await run(step);
86
+ const combined = `${result.out}${result.err}`;
87
+ const info = digest(result.out) || digest(combined);
88
+ const ok = info.ok && result.code === 0;
89
+ if (!ok) {
90
+ failed = true;
91
+ if (info.hints.length) {
92
+ for (const hint of info.hints.slice(0, 4)) lines.push(`${result.label}: ${hint}`);
93
+ } else {
94
+ const tail = combined.split(/\r?\n/).filter(Boolean).slice(-3);
95
+ lines.push(`${result.label} exit=${result.code}`);
96
+ for (const t of tail) lines.push(` ${t.slice(0, 200)}`);
97
+ }
98
+ }
99
+ }
100
+
101
+ const seconds = ((Date.now() - started) / 1000).toFixed(1);
102
+ const head = failed ? `[stage] ${stageName} FAIL ${seconds}s` : `[stage] ${stageName} ok ${seconds}s (${steps.length} 步)`;
103
+ console.log(head);
104
+ for (const line of lines) console.log(` ${line}`);
105
+ process.exit(failed ? 1 : 0);
@@ -0,0 +1,31 @@
1
+ {
2
+ "agent": "biutalk",
3
+ "stages": {
4
+ "pre": [
5
+ [
6
+ "doctor",
7
+ "node",
8
+ "{skill}/doctor.mjs",
9
+ "--project",
10
+ ".",
11
+ "--engine",
12
+ "{engine}",
13
+ "--json"
14
+ ]
15
+ ],
16
+ "post": [
17
+ [
18
+ "qc",
19
+ "node",
20
+ "{skill}/qc.mjs",
21
+ "--project",
22
+ ".",
23
+ "--engine",
24
+ "{engine}",
25
+ "--video",
26
+ "{video}",
27
+ "--json"
28
+ ]
29
+ ]
30
+ }
31
+ }
package/studio/app.js CHANGED
@@ -7,7 +7,38 @@
7
7
  el.textContent = value;
8
8
  }
9
9
 
10
- const { api, fileToBase64, uploadBlockReason, bindPlusMenu, bindCount, renderJobs, addChip, titleFromPrompt, esc , openVoicePicker} = Composer;
10
+ const { api, fileToBase64, uploadBlockReason, bindPlusMenu, bindCount, bindRoleMenu, pickFilesByRole, roleLabel, renderJobs, addChip, titleFromPrompt, esc , openVoicePicker} = Composer;
11
+
12
+ const ATTACH_ROLES = [
13
+ {
14
+ role: 'media',
15
+ icon: '▣',
16
+ label: '图片 / 视频',
17
+ hint: '截图、logo、B-roll 素材',
18
+ accept: 'image/*,video/*',
19
+ },
20
+ {
21
+ role: 'voice',
22
+ icon: '♪',
23
+ label: '旁白录音',
24
+ hint: '我自己的声音;有录音就不合成',
25
+ accept: 'audio/*',
26
+ },
27
+ {
28
+ role: 'music',
29
+ icon: '♫',
30
+ label: '配乐 / 音效',
31
+ hint: '有授权的音乐或音效',
32
+ accept: 'audio/*',
33
+ },
34
+ {
35
+ role: 'doc',
36
+ icon: '▤',
37
+ label: '文档',
38
+ hint: 'PDF / Word / TXT,只用于核对事实',
39
+ accept: '.pdf,.md,.txt,.doc,.docx',
40
+ },
41
+ ];
11
42
 
12
43
  const state = {
13
44
  voice: null,
@@ -54,8 +85,9 @@
54
85
  });
55
86
  state.files.forEach((f, i) => {
56
87
  const el = document.createElement('span');
57
- el.className = 'asset';
58
- el.innerHTML = `${esc(f.name)} <button type="button">×</button>`;
88
+ const role = roleLabel(f.role);
89
+ el.className = 'asset' + (f.role ? ' ' + f.role : '');
90
+ el.innerHTML = `${esc(f.name)}${role ? `<span class="role-tag">${esc(role)}</span>` : ''} <button type="button">×</button>`;
59
91
  el.querySelector('button').onclick = () => {
60
92
  state.files.splice(i, 1);
61
93
  renderAssets();
@@ -121,9 +153,12 @@
121
153
  $('linkAdd').onclick = addLink;
122
154
 
123
155
  const plus = bindPlusMenu($('plusBtn'), $('plusMenu'));
124
- $('uploadBtn').onclick = () => {
125
- plus.close();
126
- $('files').click();
156
+ $('uploadBtn').onclick = (e) => {
157
+ e.stopPropagation();
158
+ bindRoleMenu($('uploadBtn'), ATTACH_ROLES, (item) => {
159
+ plus.close();
160
+ pickFilesByRole($('files'), item.role, item.accept, addPickedFiles);
161
+ });
127
162
  };
128
163
  if ($('voiceBtn')) {
129
164
  $('voiceBtn').onclick = () => {
@@ -145,12 +180,10 @@
145
180
  syncPaceHint();
146
181
  };
147
182
 
148
- $('files').onchange = async (e) => {
149
- const picked = Array.from(e.target.files || []);
150
- e.target.value = '';
183
+ async function addPickedFiles(role, picked) {
151
184
  const notes = [];
152
185
  let used = state.files.reduce((n, f) => n + (f.size || 0), 0);
153
- for (const file of picked) {
186
+ for (const file of picked || []) {
154
187
  const reason = uploadBlockReason(file, used);
155
188
  if (reason) {
156
189
  notes.push(reason);
@@ -159,6 +192,7 @@
159
192
  state.files.push({
160
193
  name: file.name,
161
194
  kind: file.type || 'file',
195
+ role: role || 'media',
162
196
  size: file.size,
163
197
  dataBase64: await fileToBase64(file),
164
198
  });
@@ -170,7 +204,7 @@
170
204
  $('err').textContent = notes.join(';');
171
205
  $('err').scrollIntoView({ block: 'nearest' });
172
206
  }
173
- };
207
+ }
174
208
 
175
209
  bindCount($('prompt'), $('count'), 4000);
176
210
 
@@ -112,26 +112,26 @@ button:disabled { cursor: not-allowed; opacity: .5; }
112
112
  width: 100%; min-height: 190px; border: 0; resize: vertical; outline: 0;
113
113
  padding: 18px 22px 8px; font-size: 15px; line-height: 1.7; background: transparent; color: var(--ink);
114
114
  }
115
- .composer textarea::placeholder { color: #a3a39f; }
116
-
117
- .prompt-stage { position: relative; }
118
- .prompt-stage textarea { padding-bottom: 48px; }
119
- .optimize {
120
- position: absolute; right: 14px; bottom: 12px; z-index: 2;
121
- border: 1px solid var(--line-strong); background: #fff; color: var(--ink);
122
- border-radius: 999px; padding: 6px 12px; font-size: 12px; font-weight: 650;
123
- box-shadow: 0 1px 2px rgb(0 0 0 / 6%);
124
- }
125
- .optimize:hover { background: var(--accent-soft); border-color: var(--accent-deep); }
126
- .optimize.is-locked { opacity: .55; }
127
- .optimize.is-locked:hover { background: #fff; border-color: var(--line-strong); }
128
- .optimize-tip {
129
- position: absolute; right: 14px; bottom: 48px; z-index: 3;
130
- background: #111; color: #fff; border-radius: 10px; padding: 8px 10px;
131
- font-size: 12px; line-height: 1.4; white-space: nowrap;
132
- box-shadow: 0 8px 24px rgb(0 0 0 / 18%);
133
- }
134
- .optimize-tip[hidden] { display: none !important; }
115
+ .composer textarea::placeholder { color: #a3a39f; }
116
+
117
+ .prompt-stage { position: relative; }
118
+ .prompt-stage textarea { padding-bottom: 48px; }
119
+ .optimize {
120
+ position: absolute; right: 14px; bottom: 12px; z-index: 2;
121
+ border: 1px solid var(--line-strong); background: #fff; color: var(--ink);
122
+ border-radius: 999px; padding: 6px 12px; font-size: 12px; font-weight: 650;
123
+ box-shadow: 0 1px 2px rgb(0 0 0 / 6%);
124
+ }
125
+ .optimize:hover { background: var(--accent-soft); border-color: var(--accent-deep); }
126
+ .optimize.is-locked { opacity: .55; }
127
+ .optimize.is-locked:hover { background: #fff; border-color: var(--line-strong); }
128
+ .optimize-tip {
129
+ position: absolute; right: 14px; bottom: 48px; z-index: 3;
130
+ background: #111; color: #fff; border-radius: 10px; padding: 8px 10px;
131
+ font-size: 12px; line-height: 1.4; white-space: nowrap;
132
+ box-shadow: 0 8px 24px rgb(0 0 0 / 18%);
133
+ }
134
+ .optimize-tip[hidden] { display: none !important; }
135
135
 
136
136
  .composer-foot {
137
137
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
@@ -392,6 +392,16 @@ button:disabled { cursor: not-allowed; opacity: .5; }
392
392
  .bd-viewer[hidden] { display: none; }
393
393
  .bd-viewer img { max-width: 100%; max-height: 100%; border-radius: 8px; }
394
394
  .asset.ref { background: var(--accent-soft); border-color: var(--accent-deep); }
395
+ /* 附件角色:+ 弹窗的二级菜单(参考素材 / 口播录音 / 配乐 / 文稿)与素材角色标签 */
396
+ .role-menu { position: fixed; width: 260px; z-index: 40; bottom: auto; }
397
+ .role-menu > button .plus-ico { width: 22px; height: 22px; font-size: 12px; border-radius: 7px; }
398
+ .asset .role-tag {
399
+ font-size: 10px; color: var(--muted-2); border: 1px solid var(--line);
400
+ border-radius: 99px; padding: 0 5px; margin-left: 2px;
401
+ }
402
+ .asset.voice { background: #e8f2ff; }
403
+ .asset.music { background: #f1ecff; }
404
+ .asset.doc { background: #f3f1e8; }
395
405
  button.job-play {
396
406
  appearance: none; border: 0; background: none; font: inherit; color: inherit;
397
407
  cursor: pointer; padding: 0; text-align: left; width: 100%;
@@ -531,29 +541,29 @@ button.job-play {
531
541
  .sm-entry-err { flex: 1 0 100%; margin: 0; font-size: 11px; line-height: 1.3; color: var(--danger); }
532
542
 
533
543
  .file-hidden { position: absolute; width: 0; height: 0; opacity: 0; pointer-events: none; }
534
-
535
- .job-detail-card { width: min(520px, 100%); background: #fff; color: var(--ink); }
536
- .job-detail-card .film-modal-bar { color: var(--ink); border-bottom: 1px solid var(--line); }
537
- .job-detail-card .film-modal-x { color: var(--ink-soft); }
538
- .job-detail-body { padding: 14px 16px 18px; display: grid; gap: 10px; }
539
- .job-detail-body .jd-msg { font-size: 13px; line-height: 1.5; white-space: pre-wrap; }
540
- .job-detail-body .jd-meta { font-size: 11px; white-space: pre-wrap; word-break: break-all; }
541
- .job-detail-body .jd-follow { display: grid; gap: 8px; padding-top: 4px; border-top: 1px dashed var(--line); }
542
- .job-detail-body .jd-follow-hint { margin: 0; font-size: 11.5px; }
543
- .job-detail-body .jd-follow-actions { display: flex; flex-wrap: wrap; gap: 6px; }
544
- .job-detail-body .jd-follow-btn {
545
- border: 1px solid var(--line); background: #fff; border-radius: 8px;
546
- padding: 6px 10px; font: inherit; font-size: 12px; cursor: pointer;
547
- }
548
- .job-detail-body .jd-follow-btn:hover { border-color: var(--ink); }
549
- .job-detail-body .jd-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
550
- .job-detail-body .jd-actions button {
551
- border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 7px 12px; font-size: 12px;
552
- }
553
- .job-detail-body .jd-actions .primary, .voice-picker-modal .primary {
554
- background: var(--ink); color: #fff; border-color: var(--ink);
555
- }
556
- .vp-field { display: grid; gap: 6px; font-size: 12px; }
557
- .vp-field select {
558
- width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; font: inherit; background: #fff;
544
+
545
+ .job-detail-card { width: min(520px, 100%); background: #fff; color: var(--ink); }
546
+ .job-detail-card .film-modal-bar { color: var(--ink); border-bottom: 1px solid var(--line); }
547
+ .job-detail-card .film-modal-x { color: var(--ink-soft); }
548
+ .job-detail-body { padding: 14px 16px 18px; display: grid; gap: 10px; }
549
+ .job-detail-body .jd-msg { font-size: 13px; line-height: 1.5; white-space: pre-wrap; }
550
+ .job-detail-body .jd-meta { font-size: 11px; white-space: pre-wrap; word-break: break-all; }
551
+ .job-detail-body .jd-follow { display: grid; gap: 8px; padding-top: 4px; border-top: 1px dashed var(--line); }
552
+ .job-detail-body .jd-follow-hint { margin: 0; font-size: 11.5px; }
553
+ .job-detail-body .jd-follow-actions { display: flex; flex-wrap: wrap; gap: 6px; }
554
+ .job-detail-body .jd-follow-btn {
555
+ border: 1px solid var(--line); background: #fff; border-radius: 8px;
556
+ padding: 6px 10px; font: inherit; font-size: 12px; cursor: pointer;
557
+ }
558
+ .job-detail-body .jd-follow-btn:hover { border-color: var(--ink); }
559
+ .job-detail-body .jd-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
560
+ .job-detail-body .jd-actions button {
561
+ border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 7px 12px; font-size: 12px;
562
+ }
563
+ .job-detail-body .jd-actions .primary, .voice-picker-modal .primary {
564
+ background: var(--ink); color: #fff; border-color: var(--ink);
565
+ }
566
+ .vp-field { display: grid; gap: 6px; font-size: 12px; }
567
+ .vp-field select {
568
+ width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; font: inherit; background: #fff;
559
569
  }