Skip to content

system

Talk to the host OS: read command-line args and environment variables, find the current directory, show notifications, take screenshots, open URLs, and read from stdin.

ts
import { args, env, notify } from "std::system"

node main() {
  const home = env("HOME")
  notify("Done", "Processed ${args().length} arguments")
}

Effects

std::screenshot

ts
effect std::screenshot {
  filepath: string
}

(source)

std::exit

ts
effect std::exit {
  code: number
}

(source)

std::setEnv

ts
effect std::setEnv {
  name: string;
  value: string
}

(source)

std::openUrl

ts
effect std::openUrl {
  url: string
}

(source)

std::notify

ts
effect std::notify {
  title: string;
  body: string
}

(source)

Functions

notify

ts
notify(title: string, message: string): boolean

Show a native OS notification. Returns true if the notification was sent.

@param title - The notification title @param message - The notification body text

Parameters:

NameTypeDefault
titlestring
messagestring

Returns: boolean

Throws: std::notify

(source)

screenshot

ts
screenshot(filepath: string, x: number, y: number, width: number, height: number, allowedPaths: string[])

Take a screenshot and save it to a file. Pass x, y, width, and height to capture a specific region.

@param filepath - Path to save the screenshot @param x - X coordinate of the capture region; -1 for the full screen @param y - Y coordinate of the capture region; -1 for the full screen @param width - Width of the capture region; -1 for the full screen @param height - Height of the capture region; -1 for the full screen @param allowedPaths - Only allow saving under these path prefixes

Ctrl-C, a race loss, or a time-guard abort interrupts an in-progress screencapture.

Parameters:

NameTypeDefault
filepathstring
xnumber-1
ynumber-1
widthnumber-1
heightnumber-1
allowedPathsstring[][]

Throws: std::screenshot

(source)

exit

ts
exit(code: number)

Terminate the process immediately with the given exit code. Use with caution. This skips any cleanup or pending operations. @param code - Exit code (0 for success, non-zero for failure)

Parameters:

NameTypeDefault
codenumber0

Throws: std::exit

(source)

args

ts
args(): string[]

Return the command-line arguments passed to the Agency program (excluding the node executable and script path).

Returns: string[]

(source)

cwd

ts
cwd(): string

Return the absolute path of the current working directory of the Agency process.

Returns: string

(source)

dirname

ts
dirname(): string

Return the absolute path of the directory containing this Agency module's compiled JavaScript.

  • By convention the compiled-JS directory is the same directory as the source
  • .agency file. Use this to build paths to resources shipped alongside your
  • Agency file (prompts, fixtures, etc.):
  • import { dirname } from "std::system"
  • import { join } from "std::path"
  • const promptDir = join(dirname(), "prompts")
  • const prompt = read("system.md", promptDir)
  • Falls back to the current working directory when called outside any Agency
  • execution frame (e.g. from non-Agency host code).

Returns: string

(source)

env

ts
env(name: string): string | null

Read an environment variable. Returns null if the variable is not set.

Parameters:

NameTypeDefault
namestring

Returns: string | null

(source)

setEnv

ts
setEnv(name: string, value: string): Result

Set an environment variable in the current process. Fails if the name is empty or contains '='. The change is visible to child processes spawned afterward but does not persist outside the current process.

@param name - The environment variable name @param value - The value to set

Parameters:

NameTypeDefault
namestring
valuestring

Returns: Result

Throws: std::setEnv

(source)

isTTY

ts
isTTY(): boolean

Return true if standard input is connected to a terminal. Returns false when stdin is piped or redirected from a file. Use this to detect non-interactive invocations (e.g. echo "hi" | my-agent) and adjust output accordingly.

Returns: boolean

(source)

readStdin

ts
readStdin(): string

Read all of standard input until EOF and return it as a string. Blocks until the input stream closes. Intended for non-interactive invocations where the user pipes input into the program.

Returns: string

(source)

openUrl

ts
openUrl(url: string): Result

Open a URL in the user's default browser.

@param url - The URL to open

macOS-only. Ctrl-C, a race loss, or a time-guard abort kills the in-flight open subprocess.

Parameters:

NameTypeDefault
urlstring

Returns: Result

Throws: std::openUrl

(source)

setTitle

ts
setTitle(title: string): void

Set the process title (as shown in system monitors, ps output, and the terminal window). This can help users identify the process, especially when running multiple agents simultaneously.

@param title - The new process title

Parameters:

NameTypeDefault
titlestring

Returns: void

(source)