code
Execute one sandboxed JavaScript program to drive shell, filesystem, HTTP, and MCP tools, replacing chains of separate calls and returning a small summary instead of raw JSON.
Instructions
Execute one JavaScript program that achieves the whole goal. This replaces chains of separate tool calls: one call here does the work of N, and intermediate data never enters your context.
Available: type ShellInput = { cmd: string; cwd?: string; timeout_ms?: number; } type ShellOutput = unknown type FsReadInput = { path: string; } type FsReadOutput = unknown type FsWriteInput = { path: string; content: string; } type FsWriteOutput = unknown type FsAppendInput = { path: string; content: string; } type FsAppendOutput = unknown type FsExistsInput = { path: string; } type FsExistsOutput = unknown type FsStatInput = { path: string; } type FsStatOutput = unknown type FsListInput = { dir?: string; } type FsListOutput = unknown type FsGlobInput = { pattern: string; cwd?: string; limit?: number; } type FsGlobOutput = unknown type FsGrepInput = { pattern: string; cwd?: string; include?: string; limit?: number; ignore_case?: boolean; } type FsGrepOutput = unknown type FsRemoveInput = { path: string; } type FsRemoveOutput = unknown type FsMkdirInput = { path: string; } type FsMkdirOutput = unknown type HttpInput = { url: string; method?: string; headers?: { [key: string]: string; }; body?: string; timeout_ms?: number; } type HttpOutput = unknown type HttpJsonInput = { url: string; method?: string; headers?: { [key: string]: string; }; body?: string; timeout_ms?: number; } type HttpJsonOutput = unknown
declare const codemode: { /** * Run a PowerShell (Windows) or POSIX shell command. Returns {code,stdout,stderr,ms}. */ shell: (input: ShellInput) => Promise;
/**
* Read a UTF-8 text file. Relative paths resolve under the sandbox ROOT.
*/
fs_read: (input: FsReadInput) => Promise<FsReadOutput>;
/**
* Write a file (creates parent dirs).
*/
fs_write: (input: FsWriteInput) => Promise<FsWriteOutput>;
/**
* Append to a file.
*/
fs_append: (input: FsAppendInput) => Promise<FsAppendOutput>;
/**
* True if the path exists.
*/
fs_exists: (input: FsExistsInput) => Promise<FsExistsOutput>;
/**
* Size / dir / mtime.
*/
fs_stat: (input: FsStatInput) => Promise<FsStatOutput>;
/**
* List a directory.
*/
fs_list: (input: FsListInput) => Promise<FsListOutput>;
/**
* Glob files under cwd (forward slashes, *, ?). Skips node_modules/.git/dist.
*/
fs_glob: (input: FsGlobInput) => Promise<FsGlobOutput>;
/**
* Regex search under cwd. Returns ["file:line: text"].
*/
fs_grep: (input: FsGrepInput) => Promise<FsGrepOutput>;
/**
* Delete a file or directory tree.
*/
fs_remove: (input: FsRemoveInput) => Promise<FsRemoveOutput>;
/**
* Create a directory tree.
*/
fs_mkdir: (input: FsMkdirInput) => Promise<FsMkdirOutput>;
/**
* HTTP request. Returns {status, ok, headers, text, ms}.
*/
http: (input: HttpInput) => Promise<HttpOutput>;
/**
* HTTP request parsed as JSON. Returns {status, ok, json}.
*/
http_json: (input: HttpJsonInput) => Promise<HttpJsonOutput>;
}
Rules:
Write an async arrow function that returns the final value. Do NOT use TypeScript syntax.
Use forward slashes in paths. A backslash inside a JS string is an escape ("\p" becomes "p") and silently corrupts the path.
Return a small JSON-able summary. Anything you do not return is discarded, which is the point: filter and aggregate inside the code, not in the conversation.
console.log output is captured host-side but is NOT returned — collect progress in an array and return it.
Loop freely: many files, many URLs, many tool calls per execution.
Default timeout 120s (CODEMODE_TIMEOUT_MS). Errors throw; catch them inside the code if you want to continue.
Example: async () => { const r = await codemode.shell({ cmd: "...", cwd: "...", timeout_ms: 0 }); return r; }
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | JavaScript async arrow function to execute |