Skip to main content

Module tools_script

Module tools_script 

Source
Expand description

The script tool: workflows the agent writes once and then calls by name.

A script is an executable file in the scripts directory (<config dir>/scripts/, or the profile’s own under a profile). The agent works something out, writes it there, and the next run — or the next minute — it is a command: script runs it, and shell finds it on PATH. This module is the one place that decides what a script is: list_scripts says what is in the directory, resolve turns a name into a file that is safe to run or a sentence saying why not, and command builds the process. The tool and eclipse scripts run both go through those three, so the CLI cannot run something the tool would refuse.

What a name may be is deliberately narrow. Scripts are flat — no /, no \, no .. — and the file is canonicalised before it runs: a symlink that leads out of the directory is refused rather than followed, because the directory is writable by the agent and a link in it would otherwise be a way to run anything. The directory itself is the user’s own config directory, which is why write_file may write there at all.

The process limits are shell’s, by sharing its code: [tools] shell_timeout_secs, a process-group kill so a background child cannot outlive the run, and output capped at [tools] max_output_bytes.

Nothing reads more of a file than it needs. A listing takes the first few kilobytes of each script for its description and no more, so a directory holding a large file costs what a small one does.

Structs§

Listing
What list_scripts found.
ScriptInfo
One file in the scripts directory.
ScriptTool
script: list the scripts, or run one.

Constants§

ENV_SCRIPTS_DIR
The environment variable that carries the scripts directory to everything Eclipse starts: scripts, shell commands and plugin tool processes.

Functions§

apply_env
The environment a run gets: the scripts directory by name, and on PATH after the real commands. Shared so execute_code — which builds its own command over the same directory — cannot drift from what script gives one (#550).
command
The process for script (already resolved by resolve) with args: run from the scripts directory, with that directory first on PATH and in ENV_SCRIPTS_DIR. Stdio is left for the caller — the tool pipes it, eclipse scripts run inherits it.
first_comment
The description a script gives itself: its first comment line.
list_scripts
The scripts in dir, sorted by name.
locate_file
As resolve, without the executable check: the file name names, for reading it (eclipse scripts cat) rather than running it.
path_with
dir placed on the PATH this process has, so a script is a command — last.
resolve
Turn name into the file to run, or a sentence saying why it will not be.
start_error
Why a script could not be started, for the one failure that has a fix the agent can make.