Skip to content

Text to vertical video in 100+ styles: AI codes each scene (HTML/SVG/WebGL), renders a 9:16 MP4 with music and English/Vietnamese voice. MCP, CLI and REST for AI agents.

Sửa: gọi Claude Code cài qua npm trên Windows (ENOENT), cột phải cuộn được

Lumtekdd514c33adb0
diff --git a/generator/audio-job.mjs b/generator/audio-job.mjs
index 1a6b19f..a0a5269 100644
--- a/generator/audio-job.mjs
+++ b/generator/audio-job.mjs
@@ -84,11 +84,11 @@ async function viaApi(prompt) {
return (msg.content || []).filter((b) => b.type === 'text').map((b) => b.text).join('\n');
}
async function viaClaude(prompt) {
- const { findClaude } = await import('./claude.mjs');
+ const { spawnClaude } = await import('./claude.mjs');
const cwd = fs.mkdtempSync(path.join(os.tmpdir(), 'lumreels-voice-'));
const args = ['-p', '--output-format', 'json', '--permission-mode', 'default', '--tools', '', '--setting-sources', 'project', '--strict-mcp-config', '--no-session-persistence', '--max-turns', '2'];
return new Promise((resolve, reject) => {
- const p = spawn(findClaude(), args, { cwd, windowsHide: true, env: { ...process.env } });
+ const p = spawnClaude(args, { cwd, windowsHide: true, env: (({ ANTHROPIC_API_KEY, ...e }) => e)(process.env) });
let out = '';
const timer = setTimeout(() => { p.kill(); reject(new Error('Claude Code quá giờ khi viết lời đọc')); }, AI_TIMEOUT_MS);
p.stdout.on('data', (d) => { out += d; });
diff --git a/generator/claude.mjs b/generator/claude.mjs
index 6cd9a3f..cce3427 100644
--- a/generator/claude.mjs
+++ b/generator/claude.mjs
@@ -8,13 +8,51 @@ import { spawn, spawnSync } from 'node:child_process';
export function findClaude() {
if (process.env.CLAUDE_BIN && fs.existsSync(process.env.CLAUDE_BIN)) return process.env.CLAUDE_BIN;
const which = spawnSync(process.platform === 'win32' ? 'where.exe' : 'which', ['claude'], { encoding: 'utf8' });
- const hit = (which.stdout || '').split(/\r?\n/).map((s) => s.trim()).find(Boolean);
+ const hits = (which.stdout || '').split(/\r?\n/).map((s) => s.trim()).filter(Boolean);
+ // Windows: `where claude` liệt kê cả shim bash không đuôi của npm (spawn ra ENOENT) → ưu tiên .exe, rồi .cmd
+ const hit = hits.find((h) => /\.exe$/i.test(h)) || hits.find((h) => /\.cmd$/i.test(h)) || hits[0];
if (hit) return hit;
const home = os.homedir();
const cands = [path.join(home, '.local', 'bin', 'claude.exe'), path.join(home, '.local', 'bin', 'claude')];
return cands.find((c) => fs.existsSync(c)) || null;
}
+/**
+ * Lệnh thật để chạy Claude Code: { cmd, pre }. Trên Windows, Node không spawn được shim .cmd / shim không đuôi
+ * của npm nếu không qua shell (ENOENT / EINVAL), mà qua shell thì phải tự quote tham số. Nên đọc shim lấy đích thật:
+ * cli.js → chạy bằng chính node đang chạy LumReels; .exe → chạy thẳng.
+ */
+export function claudeCommand() {
+ const bin = findClaude();
+ if (!bin) return null;
+ if (process.platform !== 'win32' || /\.exe$/i.test(bin)) return { cmd: bin, pre: [] };
+ const dir = path.dirname(bin);
+ const asCmd = (t) => (/\.exe$/i.test(t) ? { cmd: t, pre: [] } : { cmd: process.execPath, pre: [t] });
+ const base = bin.replace(/\.(cmd|ps1)$/i, '');
+ for (const shim of [base + '.cmd', base + '.ps1', base]) {
+ let txt = '';
+ try { txt = fs.readFileSync(shim, 'utf8'); } catch { continue; }
+ // npm cmd-shim: "%dp0%\node_modules\...\cli.js" | ps1/sh: "$basedir/node_modules/.../cli.js"
+ const m = txt.match(/(?:%~?dp0%?|\$basedir)[\\/]([^"'\r\n%]+?\.(?:c?js|mjs|exe))/i);
+ if (m) {
+ const t = path.join(dir, ...m[1].split(/[\\/]/));
+ if (fs.existsSync(t)) return asCmd(t);
+ }
+ }
+ for (const rel of [['node_modules', '@anthropic-ai', 'claude-code', 'cli.js'], ['node_modules', '@anthropic-ai', 'claude-code', 'bin', 'claude.exe']]) {
+ const t = path.join(dir, ...rel);
+ if (fs.existsSync(t)) return asCmd(t);
+ }
+ return { cmd: bin, pre: [] };
+}
+
+/** spawn Claude Code với tham số đã cho (qua claudeCommand). */
+export function spawnClaude(args, opts) {
+ const c = claudeCommand();
+ if (!c) throw new Error('Không tìm thấy lệnh claude (cài Claude Code hoặc đặt CLAUDE_BIN)');
+ return spawn(c.cmd, [...c.pre, ...args], opts);
+}
+
export const ALLOWED_TOOLS = [
'Read',
'Write',
@@ -43,7 +81,7 @@ export function runClaude(cwd, prompt, log = console.log, { timeoutMs = 25 * 60
if (!bin) return Promise.resolve({ ok: false, error: 'Không tìm thấy lệnh claude (đặt CLAUDE_BIN hoặc thêm vào PATH)' });
return new Promise((resolve) => {
log(`claude: ${bin} (cwd ${cwd})`);
- const p = spawn(bin, claudeArgs(), { cwd, windowsHide: true, env: (({ ANTHROPIC_API_KEY, ...e }) => e)(process.env) });
+ const p = spawnClaude(claudeArgs(), { cwd, windowsHide: true, env: (({ ANTHROPIC_API_KEY, ...e }) => e)(process.env) });
const raw = fs.createWriteStream(path.join(cwd, 'claude.stream.jsonl'));
let buf = '';
let result = null;
diff --git a/generator/rewrite.mjs b/generator/rewrite.mjs
index 4d48995..a608f8f 100644
--- a/generator/rewrite.mjs
+++ b/generator/rewrite.mjs
@@ -8,7 +8,7 @@ import path from 'node:path';
import { spawn } from 'node:child_process';
import Anthropic from '@anthropic-ai/sdk';
import { config, costOf } from './config.mjs';
-import { findClaude } from './claude.mjs';
+import { findClaude, spawnClaude } from './claude.mjs';
import { loadCatalog, guidancePath, hasGuidance, parseDuration, fmtDuration } from './jobs.mjs';
export const REWRITE_MAX_CHARS = 4000;
@@ -116,7 +116,7 @@ function viaClaude(prompt) {
// Thư mục trống riêng: không đọc CLAUDE.md / cấu hình dự án nào.
const cwd = fs.mkdtempSync(path.join(os.tmpdir(), 'lumreels-rewrite-'));
return new Promise((resolve, reject) => {
- const p = spawn(bin, args, { cwd, windowsHide: true, env: (({ ANTHROPIC_API_KEY, ...e }) => e)(process.env) });
+ const p = spawnClaude(args, { cwd, windowsHide: true, env: (({ ANTHROPIC_API_KEY, ...e }) => e)(process.env) });
let out = ''; let err = '';
const timer = setTimeout(() => { p.kill(); reject(new Error(`Claude Code quá ${REWRITE_TIMEOUT_MS / 1000}s, đã dừng`)); }, REWRITE_TIMEOUT_MS);
p.stdout.on('data', (d) => { out += d; });
diff --git a/server/public/style.css b/server/public/style.css
index 092cc3a..dca3e8d 100644
--- a/server/public/style.css
+++ b/server/public/style.css
@@ -52,7 +52,7 @@ h2 { font: 700 26px/1.2 var(--cond); text-transform: uppercase; letter-spacing:
.tpl.off .play { opacity: 1; }
.empty-grid { color: var(--ink-2); padding: 32px; text-align: center; background: var(--panel); border-radius: var(--r); grid-column: 1 / -1; }
-.sticky { position: sticky; top: 16px; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 20px; }
+.sticky { position: sticky; top: 16px; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 20px; max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px); overflow-y: auto; overscroll-behavior: contain; scrollbar-gutter: stable; scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
.picked { display: flex; gap: 12px; align-items: center; background: var(--panel-2); border-radius: 12px; padding: 10px; margin-bottom: 16px; min-height: 64px; }
.picked.empty { color: var(--ink-3); font-size: 15px; padding: 14px; }
.picked img { width: 44px; height: 78px; object-fit: cover; border-radius: 6px; flex: none; }
@@ -145,7 +145,7 @@ dialog a { color: var(--accent); }
.layout { grid-template-columns: 1fr; grid-template-areas: "pick" "compose" "jobs"; padding: 12px 16px 120px; }
.top { padding: 16px 16px 4px; }
.grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 12px; }
- .sticky { position: static; }
+ .sticky { position: static; max-height: none; overflow: visible; }
.go { position: fixed; left: 16px; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); width: auto; z-index: 5; }
.job { grid-template-columns: 110px minmax(0, 1fr); gap: 12px; }
}