Files
deepseek-harness/packages/experimental/webworker-runtime/src/shell/programs/index.ts
T
imccyu 4779ec9af9 feat(webworker): model-executed shell over nested worker processes
Buy the grammar, own the execution: @yarnpkg/parsers parses the command
line - aliased at bundle time to its shell entry so the root barrel's
syml/js-yaml closure stays out of the worker - and a VFS-backed evaluator
with a coreutils command table runs it inside the worker host. Each shell
process is a real child WebWorker spawned from the same bundle (the first
frame decides the role), so the TERM-then-KILL ladder is real - TERM
requests, KILL terminates the worker - and the file face stays
asynchronous end to end, since the deployment target serves no COOP/COEP
headers and SharedArrayBuffer never exists there. node:child_process
reports through the ChildProcess surface the subprocess service consumes;
execSync, execFileSync and fork refuse, and node-pty stays stubbed.
2026-08-21 20:35:32 +08:00

46 lines
1.5 KiB
TypeScript

/**
* The command table: every program name this shell can run. A browser worker
* spawns no processes, so this table IS the machine's `/bin` — a name that is
* not here reports `command not found`, exactly as a real shell would for a
* binary that is not installed.
* @module @deepseek-ai/dsh-experimental-webworker-runtime/src/shell/programs
*/
import type { ShellProgram } from '../types.ts'
import { BUILTIN_PROGRAMS } from './builtins.ts'
import { FILE_PROGRAMS } from './files.ts'
import { TEXT_PROGRAMS } from './text.ts'
let table: Map<string, ShellProgram> | undefined
/**
* The standard command table, built once and shared by every command line.
* @returns the program table, keyed by command name.
*/
export function standardPrograms(): ReadonlyMap<string, ShellProgram> {
table ??= new Map<string, ShellProgram>([
...Object.entries(BUILTIN_PROGRAMS),
...Object.entries(FILE_PROGRAMS),
...Object.entries(TEXT_PROGRAMS),
['which', which],
])
return table
}
/** Reports which of the requested names this shell can run. */
const which: ShellProgram = (argv, io) => {
const known = standardPrograms()
let status = 0
for (const name of argv.slice(1)) {
// Every program is built into the shell, so a known name reports itself
// instead of a path that would not exist in the VFS.
if (known.has(name)) {
io.out(`${name}: shell built-in command\n`)
continue
}
io.err(`which: no ${name} in the worker host command table\n`)
status = 1
}
return status
}