auth-yes/forum/poc-g2/sys_exec.ts
Tyler Gillispie e47df08b75
chore: Purge Node artifacts and execute Gen 2 tools via native Deno.Command (#70)
- Purges any existing Node artifacts (package.json, node_modules) ensuring a pristine Deno + Rust environment.
- Refactors Gen 2 Proof of Concepts (cfg, code_intelligence, protobuf, tool_sandbox) to execute external tools (tree-sitter, semgrep, protoc) as native system commands using Deno.Command.
- Introduces `sys_exec.ts` to handle pre-flight dependency checks, ensuring scripts fail gracefully rather than breaking when a required host tool is missing.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Co-authored-by: mrteye <1945243+mrteye@users.noreply.github.com>
2026-08-29 11:09:59 -07:00

67 lines
1.7 KiB
TypeScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

export async function checkToolExists(toolName: string): Promise<boolean> {
try {
const command = new Deno.Command("which", {
args: [toolName],
stdout: "piped",
stderr: "piped",
});
const { code } = await command.output();
return code === 0;
} catch {
return false;
}
}
export async function requireTool(
toolName: string,
installationInstructions: string,
): Promise<boolean> {
const exists = await checkToolExists(toolName);
if (!exists) {
console.warn(`\n⚠ [Pre-flight Check] Tool '${toolName}' is missing.`);
console.warn(` Please install it: ${installationInstructions}`);
console.warn(` Skipping execution that depends on this tool.\n`);
return false;
}
return true;
}
export async function execTool(
toolName: string,
args: string[],
options?: { stdin?: string },
): Promise<{ code: number; stdout: string; stderr: string }> {
const commandOpts: Deno.CommandOptions = {
args,
stdout: "piped",
stderr: "piped",
};
if (options?.stdin) {
commandOpts.stdin = "piped";
}
const command = new Deno.Command(toolName, commandOpts);
if (options?.stdin) {
const process = command.spawn();
const writer = process.stdin.getWriter();
await writer.write(new TextEncoder().encode(options.stdin));
await writer.close();
const { code, stdout, stderr } = await process.output();
return {
code,
stdout: new TextDecoder().decode(stdout),
stderr: new TextDecoder().decode(stderr),
};
}
const { code, stdout, stderr } = await command.output();
return {
code,
stdout: new TextDecoder().decode(stdout),
stderr: new TextDecoder().decode(stderr),
};
}