mirror of
https://github.com/harivansh-afk/clanker-agent.git
synced 2026-04-15 05:02:07 +00:00
ubuntu
This commit is contained in:
parent
cf2bb61383
commit
dd0c89d8aa
2 changed files with 55 additions and 0 deletions
|
|
@ -187,6 +187,7 @@ export interface BrowserToolOptions {
|
||||||
profileDir?: string;
|
profileDir?: string;
|
||||||
stateDir?: string;
|
stateDir?: string;
|
||||||
agentDir?: string;
|
agentDir?: string;
|
||||||
|
headed?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface BrowserCommandContext {
|
interface BrowserCommandContext {
|
||||||
|
|
@ -262,6 +263,30 @@ function ensureBrowserDirs(profilePath: string, stateDir: string): void {
|
||||||
mkdirSync(stateDir, { recursive: true });
|
mkdirSync(stateDir, { recursive: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isTruthyEnv(value: string | undefined): boolean {
|
||||||
|
if (!value) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (value.trim().toLowerCase()) {
|
||||||
|
case "":
|
||||||
|
case "0":
|
||||||
|
case "false":
|
||||||
|
case "no":
|
||||||
|
case "off":
|
||||||
|
return false;
|
||||||
|
default:
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function shouldLaunchHeaded(options?: BrowserToolOptions): boolean {
|
||||||
|
if (options?.headed !== undefined) {
|
||||||
|
return options.headed;
|
||||||
|
}
|
||||||
|
return isTruthyEnv(process.env.COMPANION_AGENT_BROWSER_HEADED);
|
||||||
|
}
|
||||||
|
|
||||||
function createBrowserCommandContext(
|
function createBrowserCommandContext(
|
||||||
profilePath: string,
|
profilePath: string,
|
||||||
stateDir: string,
|
stateDir: string,
|
||||||
|
|
@ -328,6 +353,9 @@ function buildBrowserCommand(
|
||||||
const profilePath = getBrowserProfilePath(cwd, options);
|
const profilePath = getBrowserProfilePath(cwd, options);
|
||||||
const stateDir = getBrowserStateDir(cwd, options);
|
const stateDir = getBrowserStateDir(cwd, options);
|
||||||
const baseArgs = ["--profile", profilePath];
|
const baseArgs = ["--profile", profilePath];
|
||||||
|
if (shouldLaunchHeaded(options)) {
|
||||||
|
baseArgs.push("--headed");
|
||||||
|
}
|
||||||
|
|
||||||
switch (input.action) {
|
switch (input.action) {
|
||||||
case "open": {
|
case "open": {
|
||||||
|
|
|
||||||
|
|
@ -117,6 +117,33 @@ describe("browser tool", () => {
|
||||||
expect(details?.profilePath).toBe(profileDir);
|
expect(details?.profilePath).toBe(profileDir);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("can force agent-browser into headed mode for desktop sandboxes", async () => {
|
||||||
|
const cwd = createTempDir("coding-agent-browser-headed-");
|
||||||
|
const profileDir = join(cwd, "profile");
|
||||||
|
const stateDir = join(cwd, "states");
|
||||||
|
const { calls, operations } = createMockBrowserOperations();
|
||||||
|
|
||||||
|
const browserTool = createBrowserTool(cwd, {
|
||||||
|
operations,
|
||||||
|
profileDir,
|
||||||
|
stateDir,
|
||||||
|
headed: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
await browserTool.execute("browser-open-headed", {
|
||||||
|
action: "open",
|
||||||
|
url: "https://example.com",
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(calls[0]?.args).toEqual([
|
||||||
|
"--profile",
|
||||||
|
profileDir,
|
||||||
|
"--headed",
|
||||||
|
"open",
|
||||||
|
"https://example.com",
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
it("uses interactive snapshots by default and returns snapshot text", async () => {
|
it("uses interactive snapshots by default and returns snapshot text", async () => {
|
||||||
const cwd = createTempDir("coding-agent-browser-snapshot-");
|
const cwd = createTempDir("coding-agent-browser-snapshot-");
|
||||||
const profileDir = join(cwd, "profile");
|
const profileDir = join(cwd, "profile");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue