mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-27 03:14:11 +00:00
* feat(runner): replace server-side bash sandbox with remote runner * fix(runner): address review findings for output bounds, key rotation, defaults, and generated uploads * chore(docker): remove sandbox privileges and env vars from remaining compose files * feat(cli): add runner start with bundled SRT sandboxing (#535) * refactor(agent): expose runner bash without skill gating * feat(cli): add runner start with optional SRT sandboxing * refactor(cli): remove runner Python dependency * feat(cli): bundle SRT and use platform-native runner shells * refactor(cli): delegate runner processes to Execa * chore(cli): upgrade @anthropic-ai/sandbox-runtime to 0.0.83 * feat(cli): discover Bash for Windows runners Use Pi-style Bash discovery and launch behavior, exercise the packaged CLI shell, and wait for pending ZIP metadata reads before closing cancelled downloads. * fix(runner): enforce ownership and safe reconnects Gate dispatch on reconciliation, retain cancellations across disconnects, and stop replaced clients. Guard the single-server runner topology with a database lease. Restage missing generated inputs, report signal exits, and bound generated-file cleanup. * feat(webui): add Korean translations for agent runners * feat(cli): add runner event logging and --verbose flag (#536) * feat(cli): add runner event logging and --verbose flag * fix(cli): log runner capacity rejections accurately and use monotonic duration
85 lines
2.8 KiB
TypeScript
85 lines
2.8 KiB
TypeScript
import { realpath, stat } from 'node:fs/promises'
|
|
import path from 'node:path'
|
|
import { CliError } from '../operations/errors'
|
|
|
|
export interface RunnerOptions {
|
|
url?: string
|
|
key?: string
|
|
cwd?: string
|
|
srt?: string
|
|
verbose?: boolean
|
|
}
|
|
|
|
export interface RunnerConfig {
|
|
url: URL
|
|
key: string
|
|
cwd: string
|
|
srt?: string
|
|
verbose?: boolean
|
|
}
|
|
|
|
export async function resolveRunnerConfig(options: RunnerOptions): Promise<RunnerConfig> {
|
|
const address = options.url ?? process.env.SHUMAI_API_SERVER
|
|
const key = options.key ?? process.env.SHUMAI_RUNNER_KEY
|
|
if (!address) throw new CliError('Set SHUMAI_API_SERVER or pass --url.')
|
|
if (!key?.trim()) throw new CliError('Set SHUMAI_RUNNER_KEY or pass --key with a runner key.')
|
|
let url: URL
|
|
try {
|
|
url = new URL(address)
|
|
} catch {
|
|
throw new CliError('Invalid Shumai server URL.')
|
|
}
|
|
if (
|
|
url.username ||
|
|
url.password ||
|
|
url.search ||
|
|
url.hash ||
|
|
!['http:', 'https:'].includes(url.protocol)
|
|
) {
|
|
throw new CliError(
|
|
'Use an http:// or https:// server URL without credentials, query, or fragment.',
|
|
)
|
|
}
|
|
const localHosts = ['localhost', '127.0.0.1', '[::1]', 'host.docker.internal']
|
|
if (url.protocol === 'http:' && !localHosts.includes(url.hostname)) {
|
|
throw new CliError(
|
|
'Remote runners require HTTPS. HTTP is only supported for local development.',
|
|
)
|
|
}
|
|
url.protocol = url.protocol === 'https:' ? 'wss:' : 'ws:'
|
|
url.pathname = `${url.pathname.replace(/\/+$/, '')}/api/runners/ws`
|
|
const cwd = await realpath(path.resolve(options.cwd ?? process.cwd()))
|
|
if (!(await stat(cwd)).isDirectory()) throw new CliError('Runner workspace must be a directory.')
|
|
return {
|
|
url,
|
|
key: key.trim(),
|
|
cwd,
|
|
srt: options.srt ? path.resolve(options.srt) : undefined,
|
|
verbose: Boolean(options.verbose),
|
|
}
|
|
}
|
|
|
|
/** Commands inherit baseline OS settings and explicitly supplied skill variables, never CLI credentials. */
|
|
export function commandEnv(extra: Record<string, string> = {}, inherit = true): NodeJS.ProcessEnv {
|
|
const env: NodeJS.ProcessEnv = {}
|
|
for (const [key, value] of Object.entries(inherit ? process.env : {})) {
|
|
if (
|
|
/^(PATH|PATHEXT|HOME|USER|LOGNAME|LANG|TERM|TMPDIR|TEMP|TMP|SYSTEMROOT|SYSTEMDRIVE|COMSPEC|USERPROFILE|USERNAME|APPDATA|LOCALAPPDATA|PROGRAMDATA|PROGRAMFILES|PROGRAMFILES\(X86\)|LC_.*)$/i.test(
|
|
key,
|
|
)
|
|
)
|
|
env[key] = value
|
|
}
|
|
for (const [key, value] of Object.entries(extra)) {
|
|
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(key))
|
|
throw new Error('Invalid skill environment variable name.')
|
|
if (['SHUMAI_RUNNER_KEY', 'SHUMAI_API_KEY'].includes(key.toUpperCase())) continue
|
|
// Windows treats environment names as case-insensitive.
|
|
for (const existing of Object.keys(env)) {
|
|
if (existing.toUpperCase() === key.toUpperCase()) delete env[existing]
|
|
}
|
|
env[key] = value
|
|
}
|
|
return env
|
|
}
|