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

import type { ExtensionAPI } from "@kaio/avis-coding-agent";
import { createBashTool } from "@kaio/avis-coding-agent";

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

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

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