Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions extension/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 9 additions & 5 deletions extension/src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ type AutomationSession = {
};

const automationSessions = new Map<string, AutomationSession>();
const WINDOW_IDLE_TIMEOUT = 30000; // 30s — quick cleanup after command finishes
const DEFAULT_WINDOW_IDLE_TIMEOUT = 600_000;
let windowIdleTimeout = DEFAULT_WINDOW_IDLE_TIMEOUT;
let windowFocused = false; // set per-command from daemon's OPENCLI_WINDOW_FOCUSED

function getWorkspaceKey(workspace?: string): string {
Expand All @@ -140,7 +141,7 @@ function resetWindowIdleTimer(workspace: string): void {
const session = automationSessions.get(workspace);
if (!session) return;
if (session.idleTimer) clearTimeout(session.idleTimer);
session.idleDeadlineAt = Date.now() + WINDOW_IDLE_TIMEOUT;
session.idleDeadlineAt = Date.now() + windowIdleTimeout;
session.idleTimer = setTimeout(async () => {
const current = automationSessions.get(workspace);
if (!current) return;
Expand All @@ -156,7 +157,7 @@ function resetWindowIdleTimer(workspace: string): void {
// Already gone
}
automationSessions.delete(workspace);
}, WINDOW_IDLE_TIMEOUT);
}, windowIdleTimeout);
}

/** Get or create the dedicated automation window.
Expand Down Expand Up @@ -191,7 +192,7 @@ async function getAutomationWindow(workspace: string, initialUrl?: string): Prom
const session: AutomationSession = {
windowId: win.id!,
idleTimer: null,
idleDeadlineAt: Date.now() + WINDOW_IDLE_TIMEOUT,
idleDeadlineAt: Date.now() + windowIdleTimeout,
owned: true,
preferredTabId: null,
};
Expand Down Expand Up @@ -280,6 +281,9 @@ chrome.runtime.onMessage.addListener((msg, _sender, sendResponse) => {
async function handleCommand(cmd: Command): Promise<Result> {
const workspace = getWorkspaceKey(cmd.workspace);
windowFocused = cmd.windowFocused === true;
if (cmd.windowIdleTimeout && cmd.windowIdleTimeout > 0) {
windowIdleTimeout = cmd.windowIdleTimeout;
}
// Reset idle timer on every command (window stays alive while active)
resetWindowIdleTimer(workspace);
try {
Expand Down Expand Up @@ -387,7 +391,7 @@ function setWorkspaceSession(workspace: string, session: Omit<AutomationSession,
automationSessions.set(workspace, {
...session,
idleTimer: null,
idleDeadlineAt: Date.now() + WINDOW_IDLE_TIMEOUT,
idleDeadlineAt: Date.now() + windowIdleTimeout,
});
}

Expand Down
2 changes: 2 additions & 0 deletions extension/src/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ export interface Command {
cdpParams?: Record<string, unknown>;
/** When true, automation windows are created in the foreground (focused) */
windowFocused?: boolean;
/** Override the automation window idle timeout (milliseconds). Sent by the daemon per-command. */
windowIdleTimeout?: number;
}

export interface Result {
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion src/browser/daemon-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export interface DaemonCommand {
cdpParams?: Record<string, unknown>;
/** When true, automation windows are created in the foreground */
windowFocused?: boolean;
windowIdleTimeout?: number;
}

export interface DaemonResult {
Expand Down Expand Up @@ -142,7 +143,9 @@ async function sendCommandRaw(
const id = generateId();
const wf = process.env.OPENCLI_WINDOW_FOCUSED;
const windowFocused = (wf === '1' || wf === 'true') ? true : undefined;
const command: DaemonCommand = { id, action, ...params, ...(windowFocused && { windowFocused }) };
const wit = process.env.OPENCLI_WINDOW_IDLE_TIMEOUT;
const windowIdleTimeout = wit ? Math.max(parseInt(wit, 10), 5) * 1000 : undefined;
const command: DaemonCommand = { id, action, ...params, ...(windowFocused && { windowFocused }), ...(windowIdleTimeout && { windowIdleTimeout }) };
try {
const res = await requestDaemon('/command', {
method: 'POST',
Expand Down