Skip to content
Website ↗

Observe a Codant swarm with Node.js ​

Read a swarm snapshot with a local script, then subscribe to changes in task state, leases, and pheromones. The script uses Codant's stdio bridge. You can read the initial snapshot and subscribe before configuring a model.

Your own TUI or desktop client can use the same stdio JSON-RPC interface. If a desktop app renders a web frontend, its local host starts and holds the bridge connection and passes view data to the frontend. Download this example from the page and run it in a local terminal. The experimental official VS Code extension uses the IDE bridge. The standalone official GUI is pending release. Choose an integration

Start the observer ​

You need a working Codant installation and Node.js 22 or 24. For a source build, check the supported Node.js versions in the quickstart and build the CLI first. Start the daemon in one terminal.

sh
codant serve

Download codant-observer.mjs. In a second terminal, change to the download directory and run the following command. With the Windows MSI, the script uses the fixed command codant bridge to invoke the installer's codant.cmd.

sh
node codant-observer.mjs

For a source build, give the absolute path to the same CLI entry point in both commands.

sh
node "/path/to/codant/packages/cli/dist/index.js" serve
node codant-observer.mjs node "/path/to/codant/packages/cli/dist/index.js"

Run those commands in separate terminals. You can also run node codant-observer.mjs "<path to the native Codant executable>". On Windows, pass an .exe for that form. If you set CODANT_DATA_DIR, use the same value in both terminals. Press Ctrl+C to stop the script and its bridge. The daemon stays available to other clients. Bridge transport and launcher options

Read snapshots and events ​

The script prints three types of JSONL records. This excerpt comes from a run against a local Codant daemon. The instance and task IDs are placeholders.

jsonl
{"type":"snapshot","instanceId":"example","lastSeq":3,"tasks":1,"signals":1,"agents":0}
{"type":"subscribed","fromSeq":4,"lastSeq":3}
{"type":"event","seq":4,"kind":"task/created","taskId":"example-task"}
  • snapshot shows task, signal, and agent counts from bus/state and the latest bus sequence in that snapshot. Use the task query reference to read individual cards or durable records.
  • subscribed shows the requested starting sequence and the server's latest sequence when it accepted the subscription. Add one to the snapshot's lastSeq to get the inclusive start. The snapshot above ends at 3, so the subscription starts at 4. Track progress using each event's seq.
  • event shows one change, including its kind, sequence, and any task status or pheromone type carried by that event. The script prints selected fields. Task titles and signal notes stay in the daemon's records. Event notification schema

An idle daemon can print snapshot and subscribed and then wait. Once you've configured a model, you can submit a read-only investigation in a third terminal and watch the events it generates. Event counts depend on the actual run. Hunt walkthrough

Check task evidence and the VS Code panel ​

Replace TASK_ID with a real taskId from an event to read execution and acceptance evidence. When calling the same task/evidence method in your own client, check for it in the initialization capabilities first.

sh
codant task evidence TASK_ID

The VS Code swarm panel uses swarm/snapshot and swarm/subscribe. It passes the snapshot's seq directly as fromSeq. The server puts changes strictly after that sequence in the reply's replay field, and replay: null tells the panel to refresh its snapshot. The Node.js observer uses the bus cursor instead. It starts inclusively at lastSeq + 1 from bus/state and receives events as separate notifications. Each sequence belongs to its own data source. See packages/api/src/swarm-hub.ts, packages/api/src/connection.ts, and packages/vscode/src/panel-inspect-controller.ts. Task evidence reference · VS Code task view

Recover with a fresh snapshot ​

The observer reads JSON-RPC one line at a time and handles replies with request IDs separately from server notifications. Each request has a 10-second timeout. Once subscribed, the observer can wait for events indefinitely.

If a sequence skips ahead, the server sends bus/dropped, the cursor leaves the replay window (RPC error -32013), a request times out, or the bridge closes unexpectedly, the script closes the original bridge and retries once after 500 milliseconds. The new connection initializes, reads a fresh snapshot, and subscribes from that snapshot's lastSeq + 1. The fresh snapshot restores the current view. Notifications that fell out of the replay window are unavailable. If the second connection also fails, the script prints the error and exits.

In the source, read packages/api/src/bridge.ts for the stdio relay, busStateResponseSchema and busEventNotificationSchema in packages/api/src/protocol.ts for message shapes, and packages/api/src/bus-subscription-pump.ts for replay and queue overflow. The replay window is managed by replayFrom in packages/core/src/bus/events.ts. Initialization reference · Codant source guide