Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8c28499bd6 | |||
| 94941f59a9 | |||
| d243b37d74 | |||
| 1c942e6cb7 | |||
| d1c3230642 | |||
| bc2198103a |
Binary file not shown.
|
After Width: | Height: | Size: 366 KiB |
+33
-9
@@ -7,7 +7,12 @@ import path from 'node:path';
|
|||||||
const execFileP = promisify(execFile);
|
const execFileP = promisify(execFile);
|
||||||
|
|
||||||
// Each entry defines how to invoke the agent in non-interactive "one-shot" mode.
|
// Each entry defines how to invoke the agent in non-interactive "one-shot" mode.
|
||||||
// `buildArgs(prompt, imagePaths)` returns argv for the child process.
|
// `buildArgs(prompt, imagePaths, extraAllowedDirs)` returns argv for the child
|
||||||
|
// process. `extraAllowedDirs` is a list of absolute directories the agent must
|
||||||
|
// be permitted to read files from (skill seeds, design-system specs) that live
|
||||||
|
// outside the project cwd. Currently only Claude Code wires this through
|
||||||
|
// (`--add-dir`); other agents either inherit broader access or run with cwd
|
||||||
|
// boundaries we can't widen via flags.
|
||||||
// `streamFormat` hints to the daemon how to interpret stdout:
|
// `streamFormat` hints to the daemon how to interpret stdout:
|
||||||
// - 'claude-stream-json' : line-delimited JSON emitted by Claude Code's
|
// - 'claude-stream-json' : line-delimited JSON emitted by Claude Code's
|
||||||
// `--output-format stream-json`. Daemon parses it into typed events
|
// `--output-format stream-json`. Daemon parses it into typed events
|
||||||
@@ -19,14 +24,23 @@ export const AGENT_DEFS = [
|
|||||||
name: 'Claude Code',
|
name: 'Claude Code',
|
||||||
bin: 'claude',
|
bin: 'claude',
|
||||||
versionArgs: ['--version'],
|
versionArgs: ['--version'],
|
||||||
buildArgs: (prompt) => [
|
buildArgs: (prompt, _imagePaths, extraAllowedDirs = []) => {
|
||||||
'-p',
|
const args = [
|
||||||
prompt,
|
'-p',
|
||||||
'--output-format',
|
prompt,
|
||||||
'stream-json',
|
'--output-format',
|
||||||
'--verbose',
|
'stream-json',
|
||||||
'--include-partial-messages',
|
'--verbose',
|
||||||
],
|
'--include-partial-messages',
|
||||||
|
];
|
||||||
|
const dirs = (extraAllowedDirs || []).filter(
|
||||||
|
(d) => typeof d === 'string' && d.length > 0,
|
||||||
|
);
|
||||||
|
if (dirs.length > 0) {
|
||||||
|
args.push('--add-dir', ...dirs);
|
||||||
|
}
|
||||||
|
return args;
|
||||||
|
},
|
||||||
streamFormat: 'claude-stream-json',
|
streamFormat: 'claude-stream-json',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -111,3 +125,13 @@ export async function detectAgents() {
|
|||||||
export function getAgentDef(id) {
|
export function getAgentDef(id) {
|
||||||
return AGENT_DEFS.find((a) => a.id === id) || null;
|
return AGENT_DEFS.find((a) => a.id === id) || null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Resolve the absolute path of an agent's binary on the current PATH.
|
||||||
|
// Used by the chat handler so spawn() gets the same executable that
|
||||||
|
// detection reported as available — fixes Windows ENOENT when the bare
|
||||||
|
// bin name isn't on the child process's PATH (issue #10).
|
||||||
|
export function resolveAgentBin(id) {
|
||||||
|
const def = getAgentDef(id);
|
||||||
|
if (!def?.bin) return null;
|
||||||
|
return resolveOnPath(def.bin);
|
||||||
|
}
|
||||||
|
|||||||
+26
-4
@@ -6,7 +6,7 @@ import { fileURLToPath } from 'node:url';
|
|||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
import fs from 'node:fs';
|
import fs from 'node:fs';
|
||||||
import os from 'node:os';
|
import os from 'node:os';
|
||||||
import { detectAgents, getAgentDef } from './agents.js';
|
import { detectAgents, getAgentDef, resolveAgentBin } from './agents.js';
|
||||||
import { listSkills } from './skills.js';
|
import { listSkills } from './skills.js';
|
||||||
import { listDesignSystems, readDesignSystem } from './design-systems.js';
|
import { listDesignSystems, readDesignSystem } from './design-systems.js';
|
||||||
import { createClaudeStreamHandler } from './claude-stream.js';
|
import { createClaudeStreamHandler } from './claude-stream.js';
|
||||||
@@ -769,7 +769,17 @@ export async function startServer({ port = 7456 } = {}) {
|
|||||||
safeImages.length ? `\n\n${safeImages.map((p) => `@${p}`).join(' ')}` : '',
|
safeImages.length ? `\n\n${safeImages.map((p) => `@${p}`).join(' ')}` : '',
|
||||||
].join('');
|
].join('');
|
||||||
|
|
||||||
const args = def.buildArgs(composed, safeImages);
|
// Skill seeds (`skills/<id>/assets/template.html`) and design-system
|
||||||
|
// specs (`design-systems/<id>/DESIGN.md`) live outside the project cwd.
|
||||||
|
// The composed system prompt asks the agent to Read them via absolute
|
||||||
|
// paths in the skill-root preamble — without an explicit allowlist,
|
||||||
|
// Claude Code blocks those reads (issue #6: "no permission to read
|
||||||
|
// skills template"). We surface both roots so any agent that honours
|
||||||
|
// `--add-dir` can resolve those side files.
|
||||||
|
const extraAllowedDirs = [SKILLS_DIR, DESIGN_SYSTEMS_DIR].filter(
|
||||||
|
(d) => fs.existsSync(d),
|
||||||
|
);
|
||||||
|
const args = def.buildArgs(composed, safeImages, extraAllowedDirs);
|
||||||
|
|
||||||
res.setHeader('Content-Type', 'text/event-stream');
|
res.setHeader('Content-Type', 'text/event-stream');
|
||||||
res.setHeader('Cache-Control', 'no-cache, no-transform');
|
res.setHeader('Cache-Control', 'no-cache, no-transform');
|
||||||
@@ -782,9 +792,20 @@ export async function startServer({ port = 7456 } = {}) {
|
|||||||
res.write(`data: ${JSON.stringify(data)}\n\n`);
|
res.write(`data: ${JSON.stringify(data)}\n\n`);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Resolve the agent's bin to its absolute path. Detection (`/api/agents`)
|
||||||
|
// already locates the executable via PATH, but spawning the bare name here
|
||||||
|
// fails on Windows (ENOENT) when the child process's PATH doesn't contain
|
||||||
|
// the user's npm-global / shim directory — see issue #10.
|
||||||
|
const resolvedBin = resolveAgentBin(agentId) || def.bin;
|
||||||
|
// npm shims on Windows are .cmd/.bat files; Node ≥21 refuses to spawn
|
||||||
|
// those without `shell: true` (CVE-2024-27980). When `shell: true` is set
|
||||||
|
// on Windows, Node escapes args automatically for the cmd.exe shell.
|
||||||
|
const useShell =
|
||||||
|
process.platform === 'win32' && /\.(cmd|bat)$/i.test(resolvedBin);
|
||||||
|
|
||||||
send('start', {
|
send('start', {
|
||||||
agentId,
|
agentId,
|
||||||
bin: def.bin,
|
bin: resolvedBin,
|
||||||
streamFormat: def.streamFormat ?? 'plain',
|
streamFormat: def.streamFormat ?? 'plain',
|
||||||
projectId: typeof projectId === 'string' ? projectId : null,
|
projectId: typeof projectId === 'string' ? projectId : null,
|
||||||
cwd,
|
cwd,
|
||||||
@@ -792,10 +813,11 @@ export async function startServer({ port = 7456 } = {}) {
|
|||||||
|
|
||||||
let child;
|
let child;
|
||||||
try {
|
try {
|
||||||
child = spawn(def.bin, args, {
|
child = spawn(resolvedBin, args, {
|
||||||
env: { ...process.env },
|
env: { ...process.env },
|
||||||
stdio: ['ignore', 'pipe', 'pipe'],
|
stdio: ['ignore', 'pipe', 'pipe'],
|
||||||
cwd: cwd || undefined,
|
cwd: cwd || undefined,
|
||||||
|
shell: useShell,
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
send('error', { message: `spawn failed: ${err.message}` });
|
send('error', { message: `spawn failed: ${err.message}` });
|
||||||
|
|||||||
@@ -116,6 +116,7 @@ export function App() {
|
|||||||
const withOnboarding: AppConfig = { ...next, onboardingCompleted: true };
|
const withOnboarding: AppConfig = { ...next, onboardingCompleted: true };
|
||||||
saveConfig(withOnboarding);
|
saveConfig(withOnboarding);
|
||||||
setConfig(withOnboarding);
|
setConfig(withOnboarding);
|
||||||
|
setSettingsOpen(false);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const handleModeChange = useCallback(
|
const handleModeChange = useCallback(
|
||||||
|
|||||||
@@ -276,10 +276,7 @@ export function SettingsDialog({
|
|||||||
type="button"
|
type="button"
|
||||||
className="primary"
|
className="primary"
|
||||||
disabled={!canSave}
|
disabled={!canSave}
|
||||||
onClick={() => {
|
onClick={() => onSave(cfg)}
|
||||||
onSave(cfg);
|
|
||||||
onClose();
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
{welcome ? t('settings.getStarted') : t('common.save')}
|
{welcome ? t('settings.getStarted') : t('common.save')}
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
Reference in New Issue
Block a user