/**
 * Bash Spawn Hook Example
 *
 * Adjusts command, cwd, and env before execution.
 *
 * Usage:
 *   thread -e ./bash-spawn-hook.ts
 */

import type { ExtensionAPI } from "threadwell";
import { createBashTool } from "threadwell";

export default function (threadwell: ExtensionAPI) {
	const cwd = process.cwd();

	const bashTool = createBashTool(cwd, {
		spawnHook: ({ command, cwd, env }) => ({
			command: `source ~/.profile\n${command}`,
			cwd,
			env: { ...env, THREADWELL_SPAWN_HOOK: "1" },
		}),
	});

	threadwell.registerTool({
		...bashTool,
		execute: async (id, params, signal, onUpdate, _ctx) => {
			return bashTool.execute(id, params, signal, onUpdate);
		},
	});
}
