awe docs

Skills and automation

Scripts and background jobs

A script is a shell command you register with awe under a name. Once registered, awe can run it when you ask, from the console, on a schedule, or as part of an automation. Long commands run as background jobs that you can check on, read the output of, and cancel. This page is for developers.

Scripts are run by awe-script-executor, one of the servers that comes with awe.

How a script runs

Each registered script runs in one of two ways:

Mode When What you get back
Foreground The default awe waits for the command and returns its output. A non-zero exit is an error that includes the output
Background job The script is marked for background, or its estimated duration is more than 300 seconds A job id straight away. The command keeps running on its own

Only background runs create a job. A foreground run leaves no job record: its output is the whole result.

On macOS and Linux the command runs with sh -c. On Windows it runs in cmd.exe.

Register a script

From the awe folder:

./awe-core script register my-project backup --command "./scripts/backup.sh" \
  --dir /home/you/my-project --description "Nightly backup" --background --estimated-secs 600
Option Meaning
<group> A group name of your choice. A script is always addressed as group plus name
<name> The script’s name. The pair must be unique. Both names use only letters, digits, - and _, so a skill can call the script with {{invoke_script:group::name}}
--command The shell command to run, on one line
--dir Where to run it. A full path, or a path read from the awe folder. The folder must exist. Default: the awe folder
--description Shown in the console
--background Always run it as a background job
--params The parameters it takes, as a JSON array: [{"name":"who","type":"string","optional":true}]. A name uses letters, digits and _. Types: string, number, integer, boolean. See “Parameters” below
--keywords Phrases that run the script when someone types them, comma separated: "back up my notes,run the backup". A phrase that already runs something else is refused unless you add --replace
--estimated-secs Seconds. Above 300, the script runs as a background job even without --background
--replace Change a script already registered under this group and name. Without it, a name already taken is refused
--json Print the result as JSON
./awe-core script list                      # every registered script
./awe-core script list --server my-project  # one group
./awe-core script show my-project backup
./awe-core script remove my-project backup         # shows what would be removed
./awe-core script remove my-project backup --yes   # removes it

Removing a script also removes its keywords (see “Run a script by asking”) and its job records. The job output files in logs/scripts/ stay. A scheduled task that still runs the script is named in a warning and left alone; it fails until you register the script again or remove the task.

Every registered script can run. There is no on/off switch per script.

The same three actions are open to the chat, as the tools vc_scripts_register, vc_scripts_list and vc_scripts_remove on the awe-core server, and to the console API: POST /api/scripts and DELETE /api/scripts/<group>/<name>, which need the console’s admin token. All three check a script the same way.

Who can register a script. A registered command runs later, when a skill, a schedule or a keyword calls it, without asking again. Anyone at a shell on this computer can register one with awe-core script register. The chat can, through vc_scripts_register: the stricter permission profiles count that as bash, so workspace asks you first and read-only refuses it (see managed-chat-tools.md). Under the default full profile it runs without asking. The console API needs the admin token.

A new install has one script registered: system-test in the group awe, a foreground script that checks the install.

Run a script

From the awe folder:

./awe-core call awe-script-executor execute_script '{"server_name":"awe","script_name":"system-test"}'

A foreground script prints its output. A background script answers with a job:

{
  "jobId": "job_Ab3dE5fG7hJ9",
  "status": "running",
  "message": "Background job started: job_Ab3dE5fG7hJ9"
}

Parameters

Pass values in "params": { ... }. Each parameter the script declared reaches its command as an environment variable named AWE_PARAM_<name>:

./awe-core script register my-tools greet --command 'echo "hello $AWE_PARAM_who"' \
  --params '[{"name":"who","type":"string"}]'
./awe-core call awe-script-executor execute_script \
  '{"server_name":"my-tools","script_name":"greet","params":{"who":"Sam"}}'

A value is never pasted into the command or run: {"who":"$(rm -rf ~)"} prints that text. Quote the variable in your command ("$AWE_PARAM_who"), as with any shell variable. Before the script starts, awe refuses a name the script did not declare, a missing parameter that is not optional, a value of the wrong type, and text over 8192 characters. A script that declares no parameters takes any params, as before.

Every script, foreground or background, also gets all params as JSON in the PARAMS_JSON environment variable.

Two params are also handed to a background script as arguments, on macOS and Linux: path, then maxFiles if path is there too. Each reaches the script as one argument and is never run as part of the command. path must be a plain file path inside the script’s working folder, the awe folder or your home folder: no .., no leading dash, and none of ; | & $ < > " \ * ? ! { } or a backtick. maxFiles must be a whole number. A value that breaks these rules is refused and no job starts.

A script’s environment includes the settings in the awe folder’s .env, and no other .env.

Other ways to run a script:

  • In the console. Open Skills & Tools → Scripts (http://127.0.0.1:8765/#/capabilities?tab=scripts) and press Run on a row. The console waits up to two minutes for a foreground script.
  • By asking. See “Run a script by asking” below.
  • On a schedule. ./awe-core schedule add <name> <schedule> "<group> <script>" --type script, or a scheduled task of kind script through the API. See awe-scheduler.md.

Check, read and cancel a job

# Where is it?
./awe-core call awe-script-executor script_status '{"job_id":"job_Ab3dE5fG7hJ9"}'

# The last 50 lines of output
./awe-core call awe-script-executor script_output '{"job_id":"job_Ab3dE5fG7hJ9","tail_lines":50}'

# End it
./awe-core call awe-script-executor cancel_script '{"job_id":"job_Ab3dE5fG7hJ9"}'
Tool Arguments Returns
list_scripts optional server_name Every registered script: group, name, description, parameters, whether it runs in the background, and its phrases
execute_script server_name, script_name, optional params The output, or a job. Its description lists the first 30 registered scripts
script_status job_id status, exitCode, startedAt, completedAt, elapsed, pid, and the script’s names
script_output job_id, optional tail_lines (default 100) The end of the job’s standard output, then its standard error if there is any
cancel_script job_id status, stopped, forced and a message

A job’s status is one of:

Status Meaning
running Still going
completed Finished with exit code 0
failed Finished with any other exit code, or could not start
cancelled You cancelled it

What cancel does. awe asks the job and everything it started to end, waits up to three seconds, then forces whatever is left. It reports cancelled only once nothing is still running. forced: true means the job did not end when asked. If awe cannot end the job, it says so and the job stays running. Cancelling a job that already finished changes nothing.

Where output goes. Each job writes two files in the awe folder: logs/scripts/<job id>.out and logs/scripts/<job id>.err. Each starts with a line saying when the job started and ends with one giving the exit code. Clear old files out yourself when you no longer need them.

The Scripts page in the console lists recent jobs with their status, exit code, start time and duration.

Run a script by asking

awe can route a request by keyword. Give a script its phrases when you register it:

./awe-core script register my-project backup --command "./scripts/backup.sh" --keywords "run nightly backup"

Each phrase becomes a keyword route to execute_script carrying the script’s group and name. After that, the phrase runs the script from the console chat or the launcher:

./do "run nightly backup"

Choose a phrase that is specific. A keyword that also turns up in ordinary sentences will match when you did not mean it. To see what a phrase would route to without running anything:

./awe-core intent-signal "run nightly backup"

A phrase typed on its own runs the script. Inside a longer sentence it runs only when the sentence reads as a request; otherwise the chat is told the script matches and decides. To change a script’s phrases, register it again with --replace and the new --keywords. Removing the script removes its phrases. The console lists every route under Skills & Tools → Routing rules.

Scripts in schedules and automations

  • A scheduled task of kind script runs a script at a set time. The payload is "<group> <script>", or {"server_name":"...","script_name":"...","params":{}}.
  • A scheduled task or an automation can also call execute_script like any other tool, with the server awe-script-executor.
  • A background script returns a job id, not its results. If an automation should react to what a script produced, have the script write its results to a JSON file and trigger the automation on that file with feed_json_file. See awe-automations.md.

Scripts or tools?

Script Tool on a connected server
What it is Any shell command A typed function a server offers
Arguments A fixed command line Checked against a schema
Long-running work Yes, as a background job Not suited: a call is expected to answer
Best for Builds, backups, test runs, data jobs Reading and changing things in your apps

Troubleshooting

“Script not found: group::name”. The pair does not match a registered script. List what is registered:

./awe-core script list

A job shows failed at once. Read its error file: logs/scripts/<job id>.err. The usual causes are a working directory that does not exist or a command that is not on the path.

No output yet. script_output reads the job’s files. A command that buffers its output shows nothing until it flushes or exits.

A keyword runs the wrong thing. Check what it routes to with ./awe-core intent-signal. A longer, more specific keyword fixes most cases.