Work with Coding Agents
A coding agent checks, renders and measures from the shell. A person listens at checkpoints.
Give the agent the reference
Section titled “Give the agent the reference”Read resonon reference before writing code for syntax and musical idioms.
Then use resonon reference search "QUERY" to find manual sections, symbols, modules,
DSP builtins, and kits. Use --kind to filter and --limit to cap results.
Read a result with resonon reference read <ID>. Each entry gives its page ID and URL;
read the page ID for an outline. Search and read use the installed version’s documentation.
resonon reference search "euclidean rhythm"resonon reference search Reverb --kind function --limit 3resonon reference read AudioTrack.sendSearch and read exit 0 on success, 1 when not found, and 2 for invalid arguments. An unknown query or ID can suggest near matches. Copy the displayed ID exactly for read. The website serves the core and the full reference.
resonon new and resonon init write AGENTS.md with this workflow. For Claude Code,
import it from CLAUDE.md:
@AGENTS.mdWrite what is special about your piece (its key, its tempo, the sound you want) in AGENTS.md
too.
Work in a live session
Section titled “Work in a live session”Start a server with resonon server, or use the server the editor already runs. The agent edits
.non files, checks the selection, sends it, then reads back the session. A person listens as the
music plays.
# Check exactly the selection that will run, then execute it.resonon check src/main.non --lines 12-18 --message-format jsonresonon send src/main.non --lines 12-18 --message-format json
# Code can also come from an argument, or from stdin with -.resonon check --code 'print(bpm());'resonon send --code 'print(to_json(session.tracks().map(fn(t) { return t.name(); })));'printf '%s\n' 'print(to_json(session.master.peak));' | resonon send -Both commands accept a file, --lines a-b (inclusive, numbered from 1), --code, or - for stdin. Stdin is read only for -.
File selections keep their original file and line numbers in errors and resolve imports relative
to that file. In a live session, code without a file resolves imports from the server’s working directory,
both when checking and sending. Offline checks use the command’s working directory.
check opens no audio or MIDI device. A whole file or project follows the editor’s mode:
Live Mode while the selected server holds this project’s session, File Mode otherwise. A session
is the project’s when its server runs in the project, or when it has run a file from the project.
Start resonon server in the project root, as the editor does. The human output says which mode
it used and, for File Mode, why. JSON includes mode on the final complete object, and reason
when the mode is file. In Live Mode, a whole
editor document can use its own names and names already in the session. A selection or code
argument is checked as its own unit: names elsewhere in the file do not count until sent.
send executes on the existing server, streams its output and diagnostics, and waits briefly
after completion for asynchronous shader diagnostics. It exits with 0 on success, 1 on an
execution error, and 2 on invalid input or a connection failure. In JSON, invalid input and a
connection failure also write an error and then a failed complete. It executes the selection even
when a preceding check reported errors, just as the editor does. A send that fails partway keeps
the statements before the error: tracks they made and settings they changed stay in the session.
Fix the failing statement and send from there; see
The Error Model.
The default server for send is 127.0.0.1:5555. Use --host and --port when
connecting elsewhere. check follows the local editor’s selected server for the project; its
--host and --port options select a different session explicitly. If that server has no session
of this project, check does not check against anything else. It exits with 2 and says why, and
in JSON it writes an error and then a failed complete. Session snapshots are local to the
server’s machine, so checking a remote session requires running the check there.
Read state through the language, using print(to_json(...)) with send. For example,
bpm(), beats_per_cycle(), is_playing(), and cycle() read the transport; session.tracks() lists the
session’s tracks. Track getters read mixer settings and routing. track.peak.get() and
track.rms.get() read the meter’s current displayed value, and to_json reads meter feeds as
numbers too. scope_values() reads the scope probes, and scope_snap("scope.png") draws them as the
scope window would to a PNG you can open, without showing the window; scope_show() puts the
window in front of the user. signal.get() reads a signal, and
parameter.get() reads a parameter’s current value, parameter.get_norm() reads it as a fraction
of its range, and parameter.text() reads it as the device shows it ("1.20 kHz", "35.0 ms",
"Saw"): a plugin’s value in the plugin’s own text. .parameters() lists all three for each
parameter, with the range and default as text too. parameter.set_text("800 Hz") sets a
parameter from that text, as typed into a parameter box: "1.2k", "35 ms", "-6 dB", "25L".
A plugin reads the text itself. session.modulations() lists every parameter that a signal, an
automation lane or a pattern drives: where it is, the source, the source’s range, and the value and
text now. track.output(), track.sends(), and
effect.inputs() return serializable routing descriptions. Readers return data or sources. For data,
to_json writes a track as its name, a mode such as track.monitor() as its name ("auto"),
a key as its root and scale, a Note as {name, note}, a Scale as
{name, intervals, period}, a Duration as {length, unit} (cycles/beats/seconds),
devices as {name, backend, id} (backend dsp/CLAP/VST3), and plugin_scan() and
.parameters() as their rows. track.velocity() returns a number or a source.
Signal and Pattern sources have no JSON form: read signal.get() for the current value
or notes() for the notes a pattern plays. midi_input_events(limit, port)
returns recent MIDI input without consuming it; the history keeps at most 2000 events and
limit bounds each result. These reads return the latest available value without waiting for a measurement
window. See the standard library reference for each reader’s shape.
Connect the language server
Section titled “Connect the language server”Configure your harness’s language-server client to start resonon-lsp --stdio from the project
root, for .non files. It speaks the Language Server Protocol over standard input and output;
no harness-specific plugin or embedded agent is required. The project root selects the project’s
installed Resonon version. Use the diagnostics alongside check before sending a selection.
For a non-default local server, pass initializationOptions with
{"server":{"host":"127.0.0.1","port":5556}}. Clients that switch servers can send the
resonon/sessionServer notification with {"host":"127.0.0.1","port":5556}. The VS Code
extension sends this when its active server changes. Each server has an independent snapshot,
so a second project cannot overwrite the session being checked.
The loop
Section titled “The loop”| Step | Command | It tells you |
|---|---|---|
| 1. Check | resonon check --message-format json | Syntax, undefined names, arity and types, without running anything |
| 2. List | print(to_json(notes(source, cycles))); | The notes and drum hits a part plays, as text |
| 3. Render | resonon run --no-midi scripts/bounce.non | WAV files of the stems and the mix, in the folder it names |
| 4. Analyze | resonon analyze <folder> --format json | Levels, loudness, clipping, stereo and frequency balance |
| 5. Listen | a person | Everything the numbers cannot say |
check and analyze open no audio or MIDI device. run --no-midi disables MIDI but opens the
configured audio device, as a live session does. A piece containing PLAY can sound alongside
an already playing session; render() writes audio offline. See File Runs
for the device and transport behaviour.
Each command exits with 1 when it finds an error. Repeat the loop after each change. Stop for step 5 when a part is done, before the agent builds on it.
Write a piece the loop can run
Section titled “Write a piece the loop can run”The session is the document; code and UI edit it together. resonon save keeps its
tracks, devices, mixer and arrangement. The entry file has a lifecycle:
- Open and Reset Project (
resonon open) callfn teardown()if defined, reset, restore the saved session, callfn setup()if defined, then run the rest of the top level. - Run File Live (
resonon sendwith no source) evaluates the whole entry file into the running session, without a reset and withoutsetup(). main()has no special meaning.
Put settings that need no variable, such as set_bpm(...), in setup(). The session
owns every track: a track stays until session.delete_track(name) deletes it, also when
no variable holds it. resonon open refuses when the session has changes
since the last save; add --discard-changes to lose them. Evaluations and UI gestures
share undo history; undo restores session state, not source text or variables.
See The entry file’s lifecycle.
use "std/instruments" { Sampler, Kit };
fn setup() { set_project_title("Agent Loop"); session.create_track("drums"); session.create_track("hats");}
let beat = [bd _ sd _];let drums = session.track("drums").set_volume(-6);drums.set_instrument(Sampler(Kit("CR-78")));drums << beat;
let hats = session.track("hats").set_volume(-12);hats.set_instrument(Sampler(Kit("CR-78")));hats << [hh*8];Put listing and rendering in a script, not in the entry file: the top level runs on each
open. resonon run scripts/bounce.non opens the project without a window, then evaluates
the script with the entry file’s names in scope:
// List: the drum hits of one cycleprint(to_json(notes(beat, 1)));
// Render: each track, and the mix, for 8 cyclesrender(#[drums, hats, session.master], 8);- List the parts you want to check.
notes()takes a pattern, a timeline, a MIDI track, an array of MIDI tracks or a section. Its output is in List the Notes a Pattern Plays. For a song made of sections, list the song thatarrange()gives. - Render every track and
session.master. A stem shows which track causes a problem in the mix. - Render enough cycles. Include the longest section. A track that plays a pattern loops until the render stops, so its reverb or delay tail is always cut. To keep a tail, make the piece a song that ends, and render a few cycles past its end: Render a Song.
- Give the piece a title.
set_project_title()names the render folder.
Each render writes a new folder and says where: rendered to <folder>/. Analyze that folder.
resonon run scripts/bounce.non --message-format json prints the output and any error as one JSON object per line,
and the folder of each render as a rendered object
(Machine-readable output).
For send, save, open, check and run, --message-format json selects a message stream.
After valid argument parsing, a startup refusal writes an error and exactly one failed
complete with the same request ID. This includes invalid environment settings, version pins,
missing project files and fatal startup failures. Launcher dispatch refusals use the same shape.
Argument usage errors still go to stderr. See Exit codes.
analyze --format json writes one analysis document, without message-stream objects.
The former analyze --message-format option is no longer accepted.
Read the analysis
Section titled “Read the analysis”resonon analyze measures the folder that the render wrote, master first. Each measurement is
defined in the CLI reference. In JSON, each key
has its unit in its name (true_peak_dbtp), and a level of no signal is null. A stem is the
track’s output; master.wav is the mix after the master’s volume.
Check these first:
| Measurement | Look for |
|---|---|
clipped_samples | 0 on every file |
true_peak_dbtp | Below 0 on every stem. On the master, about -6 to -3 while you mix; -1 or lower on a finished master |
integrated_lufs | Not null: a stem with no level plays nothing. Then compare the stems with each other |
bands | The energy where the part should have it: a bass in sub and low, hats in high |
correlation | Above 0 on the master. Below 0, parts cancel when they play in mono |
dc_offset_percent | Close to 0 |
trailing_silence_s | More than 0 when the piece ends with a reverb or delay, or the render cut the tail |
Loudness targets for a finished master, as integrated loudness:
| Destination | Integrated | True peak |
|---|---|---|
| Spotify, YouTube | -14 LUFS | -1 dBTP |
| Apple Music | -16 LUFS | -1 dBTP |
| Broadcast, EBU R128 | -23 LUFS | -1 dBTP |
| Broadcast, ATSC A/85 (US) | -24 LUFS | -2 dBTP |
Streaming services turn a louder master down to their level, so a louder master is not louder for
the listener; it only has less dynamics. Integrated loudness is measured over the whole file, so
measure the whole song, not one loop. A loop that repeats has a loudness range (loudness_range_lu)
near 0.
To let the agent see a part, add --spectrogram all. It writes a PNG beside each WAV, with the
cycles numbered along the top.
Answer common questions
Section titled “Answer common questions”Read what send prints. In JSON, a print is an output object with the line in text,
and an error is an error object with its text at .error.message:
set -o pipefail # else a failed send exits with jq's 0resonon send --code 'print(to_json(bpm()));' --message-format json | jq -c \ 'if .type == "output" then .text | fromjson elif .type == "error" then .error.message else empty end'Compare levels before and after a change. A meter read is one instant, so reads differ with
nothing changed. Render before and after; compare the stems’ integrated_lufs and
true_peak_dbtp in analyze.
See a value move over time. session.modulations() lists what drives each parameter. A
scope() probe records from when it is sent: send scope(sweep), let the length play, then send
scope_snap("scope/sweep.png", length: cycles(8)) and open the PNG.
Check notes against a key. notes() gives each note’s name ("A1") and MIDI note:
let k = Key(A1, "minor");let outside = notes([a1 c2 e2 f#2 g2], 1).filter(fn(n) { return k.quantize(n["note"]) != n["note"]; });print(to_json(outside.map(fn(n) { return n["name"]; }))); // ["F#2"]Listen at checkpoints
Section titled “Listen at checkpoints”The numbers show whether a mix is clean, not whether it is good. They cannot tell a groove that drags from one that swings, or a good sound from a bad one with the same level. Ask the agent to stop when a part is done, and listen to the render before it continues.
Related
Section titled “Related”- Errors & Warnings — what
resonon checkreports - Render a Project — what
render()writes, and where - Levels & Files — volume ranges, the pan law and what a render contains
- Command Line — every command and its options