chore(cli): save screenshots to tmp dir when no path provided (#247)
* fix(cli): save screenshots to tmp dir when no path provided Instead of outputting base64 to stdout (which is not useful for most CLI use cases), screenshots without a path now save to ~/.agent-browser/tmp/screenshots/ with a generated filename and return the path. This makes the behavior more ergonomic for AI agents and CLI users alike. * cleanup * cleanup * just revert the cargo.lock version for now * refactor: extract getAppDir() from getSocketDir() * docs: improve screenshot help text consistency
This commit is contained in:
+12
-9
@@ -51,27 +51,30 @@ function getPortForSession(session: string): number {
|
||||
* Get the base directory for socket/pid files.
|
||||
* Priority: AGENT_BROWSER_SOCKET_DIR > XDG_RUNTIME_DIR > ~/.agent-browser > tmpdir
|
||||
*/
|
||||
export function getSocketDir(): string {
|
||||
// 1. Explicit override
|
||||
if (process.env.AGENT_BROWSER_SOCKET_DIR) {
|
||||
return process.env.AGENT_BROWSER_SOCKET_DIR;
|
||||
}
|
||||
|
||||
// 2. XDG_RUNTIME_DIR (Linux standard)
|
||||
export function getAppDir(): string {
|
||||
// 1. XDG_RUNTIME_DIR (Linux standard)
|
||||
if (process.env.XDG_RUNTIME_DIR) {
|
||||
return path.join(process.env.XDG_RUNTIME_DIR, 'agent-browser');
|
||||
}
|
||||
|
||||
// 3. Home directory fallback (like Docker Desktop's ~/.docker/run/)
|
||||
// 2. Home directory fallback (like Docker Desktop's ~/.docker/run/)
|
||||
const homeDir = os.homedir();
|
||||
if (homeDir) {
|
||||
return path.join(homeDir, '.agent-browser');
|
||||
}
|
||||
|
||||
// 4. Last resort: temp dir
|
||||
// 3. Last resort: temp dir
|
||||
return path.join(os.tmpdir(), 'agent-browser');
|
||||
}
|
||||
|
||||
export function getSocketDir(): string {
|
||||
// Allow explicit override for socket directory
|
||||
if (process.env.AGENT_BROWSER_SOCKET_DIR) {
|
||||
return process.env.AGENT_BROWSER_SOCKET_DIR;
|
||||
}
|
||||
return getAppDir();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the socket path for the current session (Unix) or port (Windows)
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user