computer use tool

This commit is contained in:
Harivansh Rathi 2026-03-11 14:13:03 -04:00
parent 3919bbf708
commit e1bba1c1a5
9 changed files with 911 additions and 17 deletions

View file

@ -4,11 +4,10 @@ import { TmuxAdapter } from "./tmux-adapter";
describe("TmuxAdapter", () => {
let adapter: TmuxAdapter;
let mockExecCommand: ReturnType<typeof vi.spyOn>;
beforeEach(() => {
adapter = new TmuxAdapter();
mockExecCommand = vi.spyOn(terminalAdapter, "execCommand");
vi.spyOn(terminalAdapter, "execCommand");
delete process.env.TMUX;
delete process.env.ZELLIJ;
delete process.env.WEZTERM_PANE;
@ -21,6 +20,7 @@ describe("TmuxAdapter", () => {
});
it("detects tmux in headless runtimes when the binary is available", () => {
const mockExecCommand = vi.mocked(terminalAdapter.execCommand);
mockExecCommand.mockReturnValue({
stdout: "tmux 3.4",
stderr: "",
@ -33,6 +33,7 @@ describe("TmuxAdapter", () => {
it("does not detect tmux in GUI terminals just because the binary exists", () => {
process.env.COLORTERM = "truecolor";
const mockExecCommand = vi.mocked(terminalAdapter.execCommand);
mockExecCommand.mockReturnValue({
stdout: "tmux 3.4",
stderr: "",
@ -44,7 +45,8 @@ describe("TmuxAdapter", () => {
});
it("creates a detached team session when not already inside tmux", () => {
mockExecCommand.mockImplementation((_bin: string, args: string[]) => {
const mockExecCommand = vi.mocked(terminalAdapter.execCommand);
mockExecCommand.mockImplementation((_bin, args) => {
if (args[0] === "has-session") {
return { stdout: "", stderr: "missing", status: 1 };
}
@ -65,12 +67,18 @@ describe("TmuxAdapter", () => {
expect(mockExecCommand).toHaveBeenCalledWith(
"tmux",
expect.arrayContaining(["new-session", "-d", "-s", "companion-teams-demo"]),
expect.arrayContaining([
"new-session",
"-d",
"-s",
"companion-teams-demo",
]),
);
});
it("splits an existing detached session when not already inside tmux", () => {
mockExecCommand.mockImplementation((_bin: string, args: string[]) => {
const mockExecCommand = vi.mocked(terminalAdapter.execCommand);
mockExecCommand.mockImplementation((_bin, args) => {
if (args[0] === "has-session") {
return { stdout: "", stderr: "", status: 0 };
}
@ -96,6 +104,7 @@ describe("TmuxAdapter", () => {
});
it("checks pane liveness by pane id", () => {
const mockExecCommand = vi.mocked(terminalAdapter.execCommand);
mockExecCommand.mockReturnValue({
stdout: "%1\n%7\n",
stderr: "",

View file

@ -8,11 +8,10 @@ import { WezTermAdapter } from "./wezterm-adapter";
describe("WezTermAdapter", () => {
let adapter: WezTermAdapter;
let mockExecCommand: ReturnType<typeof vi.spyOn>;
beforeEach(() => {
adapter = new WezTermAdapter();
mockExecCommand = vi.spyOn(terminalAdapter, "execCommand");
vi.spyOn(terminalAdapter, "execCommand");
delete process.env.WEZTERM_PANE;
delete process.env.TMUX;
delete process.env.ZELLIJ;
@ -31,6 +30,7 @@ describe("WezTermAdapter", () => {
describe("detect", () => {
it("should detect when WEZTERM_PANE is set", () => {
const mockExecCommand = vi.mocked(terminalAdapter.execCommand);
mockExecCommand.mockReturnValue({
stdout: "version 1.0",
stderr: "",
@ -43,7 +43,8 @@ describe("WezTermAdapter", () => {
describe("spawn", () => {
it("should spawn first pane to the right with 50%", () => {
// Mock getPanes finding only current pane
mockExecCommand.mockImplementation((_bin: string, args: string[]) => {
const mockExecCommand = vi.mocked(terminalAdapter.execCommand);
mockExecCommand.mockImplementation((_bin, args) => {
if (args.includes("list")) {
return {
stdout: JSON.stringify([{ pane_id: 0, tab_id: 0 }]),
@ -79,7 +80,8 @@ describe("WezTermAdapter", () => {
it("should spawn subsequent panes by splitting the sidebar", () => {
// Mock getPanes finding current pane (0) and sidebar pane (1)
mockExecCommand.mockImplementation((_bin: string, args: string[]) => {
const mockExecCommand = vi.mocked(terminalAdapter.execCommand);
mockExecCommand.mockImplementation((_bin, args) => {
if (args.includes("list")) {
return {
stdout: JSON.stringify([