aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsalmonik <salmonik@tuta.io>2026-11-15 18:54:00 +0100
committersalmonik <salmonik@tuta.io>2026-11-15 18:55:21 +0100
commit53c85c99647ded9fab199c97b9383744e2524364 (patch)
tree0c4bad8cad75bd4d00e2eff5374c10a42a31210b
parent0.7.1: drop argument-less tool calls, print each command once (diff)
downloadagent686-53c85c99647ded9fab199c97b9383744e2524364.tar.gz
agent686-53c85c99647ded9fab199c97b9383744e2524364.zip
0.8.0: comp.sh reports how to build for the machine it runs on
Detects distro, arch, libc/glibc, CPU baseline and toolchain, prints the target triple, build command, cfg values, and the portable paths (static musl, older glibc image, cargo-zigbuild). --run builds and checks; --musl and --old-glibc select the other plans. Verified: native gnu build needs GLIBC_2.34; static musl build runs on Debian 10 and reaches the live API.
Diffstat (limited to '')
-rw-r--r--CHANGELOG.md22
-rw-r--r--Cargo.lock2
-rw-r--r--Cargo.toml2
-rw-r--r--README.md28
-rwxr-xr-xcomp.sh248
-rw-r--r--src/session.rs1
-rw-r--r--tests/sessions.rs3
7 files changed, 293 insertions, 13 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b71c654..b19c17b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,28 @@ break the interface, **PATCH** for bug fixes.
7file, and the tool schemas the model sees. Anything a script or a resumed session 7file, and the tool schemas the model sees. Anything a script or a resumed session
8could depend on counts as API. 8could depend on counts as API.
9 9
10## 0.8.0
11
12### Added
13- `comp.sh`: detects distro, architecture, libc and glibc version, CPU baseline
14 and toolchain, then prints the exact build command for this machine, the
15 `cfg` values the code will compile against, and the portable alternatives:
16 static musl, an older-glibc container, and `cargo-zigbuild` with a pinned
17 glibc. `--run` executes the native build and its checks; `--musl` and
18 `--old-glibc` select the other plans.
19
20Verified on this machine: the native x86_64 build requires `GLIBC_2.34`, the
21static musl build is 4.1 MiB, runs on Debian 10 (glibc 2.28), and reaches the
22live API through musl's resolver.
23
24### Fixed
25- The session-lock test was flaky under parallel test execution: a test that
26 spawns a child process briefly inherits the session's file description between
27 fork and exec, keeping the lock alive while another test dropped its handle.
28 The spawning test now serialises with the others. Test-only — the harness never
29 drops a session while a child is starting.
30- Removed a stray `File::open` left behind in the session loader.
31
10## 0.7.1 32## 0.7.1
11 33
12### Fixed 34### Fixed
diff --git a/Cargo.lock b/Cargo.lock
index 9326d1c..ccec677 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -10,7 +10,7 @@ checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa"
10 10
11[[package]] 11[[package]]
12name = "agent686" 12name = "agent686"
13version = "0.7.1" 13version = "0.8.0"
14dependencies = [ 14dependencies = [
15 "crossterm", 15 "crossterm",
16 "libc", 16 "libc",
diff --git a/Cargo.toml b/Cargo.toml
index f96cf58..291c064 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
1[package] 1[package]
2name = "agent686" 2name = "agent686"
3version = "0.7.1" 3version = "0.8.0"
4edition = "2021" 4edition = "2021"
5description = "A small coding agent for a 32-bit Debian box" 5description = "A small coding agent for a 32-bit Debian box"
6publish = false 6publish = false
diff --git a/README.md b/README.md
index f98e661..1b070e5 100644
--- a/README.md
+++ b/README.md
@@ -1,24 +1,33 @@
1# agent686 1# agent686
2 2
3A small coding agent for a 32-bit Debian box: one binary, six tools, line mode. 3A small coding agent for Debian-class Linux: one binary, six tools, line mode.
4 4
5Built because the existing harnesses are TypeScript bundles that need a modern 5Built because the existing harnesses are TypeScript bundles that either need a
6CPU, and the target here is a Debian 12 i386 machine with 2 cores and 4 GB. 6modern CPU or a Node runtime. This one is pure Rust with no runtime dependency,
7and it builds for whatever machine you are on.
7 8
8``` 9```
93.5 MiB ELF 32-bit LSB pie, Intel i386 104.0 MiB x86_64 glibc build, GLIBC_2.34 required
10GLIBC_2.34 required (target has 2.36) 114.1 MiB x86_64 static musl build, no libc dependency
11startup ~0.8 ms 12~1 ms startup
12``` 13```
13 14
14## Build 15## Build
15 16
16```sh 17```sh
17cargo build --release --target i686-unknown-linux-gnu 18./comp.sh # detect this machine, print the exact build plan
18./scripts/check-glibc.sh target/i686-unknown-linux-gnu/release/agent686 19./comp.sh --run # build it, then run the glibc gate
20./comp.sh --musl --run # static build: runs on Debian 10 and anything newer
21./comp.sh --old-glibc # recipe for building against an older glibc
19``` 22```
20 23
21The gate matters: the dev host's 32-bit glibc is newer than the target's, so a 24`comp.sh` reports the distro, libc and glibc version, the CPU baseline, the
25target triple, and the `cfg` values the code will see. A native glibc build
26inherits this machine's glibc floor, which is why the portable paths are printed
27next to it: static musl removes the floor entirely, and building inside an older
28Debian image lowers it.
29
30The gate matters: the dev host's glibc is newer than the target's, so a
22dependency can silently raise the required symbol version. 31dependency can silently raise the required symbol version.
23 32
24## Run 33## Run
@@ -30,7 +39,6 @@ export OPENCODE_API_KEY=... # or write it to ~/.config/agent686/key
30./agent686 -c # continue the most recent session 39./agent686 -c # continue the most recent session
31./agent686 --session <id> # resume it, or create it if the id is new 40./agent686 --session <id> # resume it, or create it if the id is new
32./agent686 --list # id, model, message count, age 41./agent686 --list # id, model, message count, age
33./agent686 -c # continue; prints where you left off
34./agent686 --show [id] # render a transcript 42./agent686 --show [id] # render a transcript
35./agent686 --doctor # key, dirs, provider, model 43./agent686 --doctor # key, dirs, provider, model
36./agent686 --yolo "..." # approve every tool call 44./agent686 --yolo "..." # approve every tool call
diff --git a/comp.sh b/comp.sh
new file mode 100755
index 0000000..6b798c6
--- /dev/null
+++ b/comp.sh
@@ -0,0 +1,248 @@
1#!/usr/bin/env bash
2#
3# comp.sh — work out how to build agent686 for *this* machine.
4#
5# Default is dry: it prints the plan. `--run` executes the native build and its
6# checks. `--musl` selects the static plan; `--old-glibc` prints the container
7# recipe for the oldest glibc we support.
8#
9# The point is to make the target explicit, because "it built" on a modern host
10# says nothing about whether it runs on baseline Debian.
11set -euo pipefail
12
13here=$(cd "$(dirname "$0")" && pwd)
14run=0
15plan=native
16
17for arg in "$@"; do
18 case "$arg" in
19 --run) run=1 ;;
20 --musl) plan=musl ;;
21 --old-glibc) plan=old-glibc ;;
22 -h | --help)
23 sed -n '3,9p' "$0" | sed 's/^# \{0,1\}//'
24 exit 0
25 ;;
26 *)
27 echo "comp.sh: unknown argument: $arg" >&2
28 exit 2
29 ;;
30 esac
31done
32
33say() { printf '%s\n' "$*"; }
34section() { printf '\n\033[1m== %s\033[0m\n' "$*"; }
35note() { printf ' %s\n' "$*"; }
36
37# ---------------------------------------------------------------- detection
38
39arch=$(uname -m)
40kernel=$(uname -r)
41
42distro=unknown
43if [ -r /etc/os-release ]; then
44 # shellcheck disable=SC1091
45 . /etc/os-release
46 distro=${PRETTY_NAME:-${ID:-unknown}}
47fi
48
49libc=unknown
50libc_version=
51if getconf GNU_LIBC_VERSION >/dev/null 2>&1; then
52 libc=glibc
53 libc_version=$(getconf GNU_LIBC_VERSION | awk '{print $2}')
54elif command -v ldd >/dev/null 2>&1 && ldd --version 2>&1 | head -1 | grep -qi musl; then
55 libc=musl
56 libc_version=$(ldd --version 2>&1 | head -1 | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1)
57elif ls /lib/ld-musl-*.so.1 >/dev/null 2>&1; then
58 libc=musl
59fi
60
61cpu_model=$(grep -m1 'model name' /proc/cpuinfo 2>/dev/null | cut -d: -f2- | sed 's/^ *//' || true)
62cpu_flags=$(grep -m1 '^flags' /proc/cpuinfo 2>/dev/null | cut -d: -f2- || true)
63
64rustc_version=$(rustc -V 2>/dev/null || echo "not installed")
65cargo_version=$(cargo -V 2>/dev/null | awk '{print $2}' || echo "not installed")
66
67# ---------------------------------------------------------------- triple map
68
69triple_gnu=unknown-unknown-linux-gnu
70triple_musl=unknown-unknown-linux-musl
71baseline_flag=
72
73case "$arch" in
74 x86_64 | amd64)
75 triple_gnu=x86_64-unknown-linux-gnu
76 triple_musl=x86_64-unknown-linux-musl
77 # x86-64 v1: SSE2 only. Anything higher excludes pre-Nehalem CPUs.
78 baseline_flag="-C target-cpu=x86-64"
79 ;;
80 aarch64 | arm64)
81 triple_gnu=aarch64-unknown-linux-gnu
82 triple_musl=aarch64-unknown-linux-musl
83 ;;
84 armv7l | armv7)
85 triple_gnu=armv7-unknown-linux-gnueabihf
86 triple_musl=armv7-unknown-linux-musleabihf
87 ;;
88 armv6l)
89 triple_gnu=arm-unknown-linux-gnueabihf
90 triple_musl=arm-unknown-linux-musleabihf
91 ;;
92 i686 | i386)
93 triple_gnu=i686-unknown-linux-gnu
94 triple_musl=i686-unknown-linux-musl
95 ;;
96 riscv64)
97 triple_gnu=riscv64gc-unknown-linux-gnu
98 triple_musl=riscv64gc-unknown-linux-musl
99 ;;
100 ppc64le)
101 triple_gnu=powerpc64le-unknown-linux-gnu
102 triple_musl=powerpc64le-unknown-linux-musl
103 ;;
104 s390x)
105 triple_gnu=s390x-unknown-linux-gnu
106 triple_musl=s390x-unknown-linux-musl
107 ;;
108 *)
109 note "unrecognised architecture '$arch'; edit comp.sh's triple map"
110 ;;
111esac
112
113native_triple=$triple_gnu
114[ "$libc" = musl ] && native_triple=$triple_musl
115
116# The i686 gnu target uses linker flags from .cargo/config.toml; setting
117# RUSTFLAGS at all would shadow them, so repeat them when needed.
118defsym_flag=
119if [ "$triple_gnu" = i686-unknown-linux-gnu ]; then
120 defsym_flag="-C link-arg=-Wl,--defsym,pidfd_spawnp=0 -C link-arg=-Wl,--defsym,pidfd_getpid=0"
121fi
122
123# ---------------------------------------------------------------- report
124
125section "machine"
126note "distro $distro"
127note "arch $arch ($(getconf LONG_BIT 2>/dev/null || echo '?')-bit)"
128note "kernel $kernel"
129note "libc ${libc}${libc_version:+ $libc_version}"
130note "cpu ${cpu_model:-unknown}"
131note "rust $rustc_version"
132note "cargo $cargo_version"
133if [ -n "$cpu_flags" ]; then
134 for feature in sse2 sse4_2 avx avx2; do
135 case " $cpu_flags " in
136 *" $feature "*) note "has $feature" ;;
137 esac
138 done
139fi
140
141section "target"
142case "$plan" in
143 native)
144 say " target $native_triple"
145 ;;
146 musl)
147 say " target $triple_musl (static)"
148 ;;
149 old-glibc)
150 say " target $triple_gnu, built inside an older image"
151 ;;
152esac
153
154if [ "$baseline_flag" = "-C target-cpu=x86-64" ]; then
155 note "baseline x86-64 (SSE2): runs on any 64-bit x86 CPU"
156fi
157
158case "$plan" in
159 native)
160 if [ "$libc" = glibc ]; then
161 say ""
162 say " Building here links against this machine's glibc ($libc_version)."
163 say " The binary will refuse to start on any machine with an older one."
164 say " For a portable build, use --musl or --old-glibc."
165 fi
166 ;;
167esac
168
169section "commands"
170
171case "$plan" in
172 native | musl)
173 triple=$native_triple
174 [ "$plan" = musl ] && triple=$triple_musl
175 extra_flags=$baseline_flag
176 [ "$triple" = i686-unknown-linux-gnu ] && extra_flags="$extra_flags $defsym_flag"
177
178 say " rustup target add $triple # if not already installed"
179 if [ "$plan" = musl ] && [ "$triple" != i686-unknown-linux-musl ]; then
180 say " # needs a C toolchain for ring: apt install musl-tools"
181 fi
182 if [ -n "$extra_flags" ]; then
183 say " RUSTFLAGS=\"$extra_flags\" \\"
184 fi
185 say " cargo build --release --target $triple"
186 case "$triple" in
187 *-gnu)
188 say " ./scripts/check-glibc.sh target/$triple/release/agent686"
189 ;;
190 *)
191 say " file target/$triple/release/agent686 # expect: statically linked"
192 ;;
193 esac
194 ;;
195 old-glibc)
196 say " # The floor is the glibc in the image you build in:"
197 say " # debian:12 bookworm -> glibc 2.36"
198 say " # debian:11 bullseye -> glibc 2.31"
199 say " # debian:10 buster -> glibc 2.28"
200 say ""
201 say " docker run --rm -it -v \"\$PWD:/src\" -w /src rust:1-bullseye bash -lc '"
202 say " apt-get update &&"
203 say " apt-get install -y --no-install-recommends build-essential pkg-config &&"
204 say " RUSTFLAGS=\"$baseline_flag\" cargo build --release &&"
205 say " ./scripts/check-glibc.sh target/release/agent686'"
206 say ""
207 say " # Alternative without Docker, pinning glibc with zig:"
208 say " # cargo install cargo-zigbuild"
209 say " # cargo zigbuild --release --target $triple_gnu.2.28"
210 ;;
211esac
212
213section "cfg the code will see"
214if command -v rustc >/dev/null 2>&1; then
215 triple_for_cfg=$native_triple
216 [ "$plan" = musl ] && triple_for_cfg=$triple_musl
217 [ "$plan" = old-glibc ] && triple_for_cfg=$triple_gnu
218 rustc --print cfg --target "$triple_for_cfg" 2>/dev/null \
219 | grep -E '^(target_(arch|env|family|os|pointer_width|vendor)|target_feature=)' \
220 | sed 's/^/ /' | sort
221else
222 note "rustc not found; no cfg to show"
223fi
224
225if [ "$run" -eq 1 ]; then
226 if [ "$plan" = old-glibc ]; then
227 echo "comp.sh: --old-glibc is a recipe; run the docker command above" >&2
228 exit 2
229 fi
230 triple=$native_triple
231 [ "$plan" = musl ] && triple=$triple_musl
232 extra_flags=$baseline_flag
233 [ "$triple" = i686-unknown-linux-gnu ] && extra_flags="$extra_flags $defsym_flag"
234
235 section "building"
236 rustup target add "$triple" >/dev/null 2>&1 || true
237 (
238 cd "$here"
239 RUSTFLAGS="$extra_flags" cargo build --release --target "$triple"
240 )
241 binary="$here/target/$triple/release/agent686"
242 section "result"
243 note "$(file -b "$binary")"
244 case "$triple" in
245 *-gnu) "$here/scripts/check-glibc.sh" "$binary" ;;
246 *) note "static: no glibc floor to check" ;;
247 esac
248fi
diff --git a/src/session.rs b/src/session.rs
index 8e0ef02..a1da28f 100644
--- a/src/session.rs
+++ b/src/session.rs
@@ -131,7 +131,6 @@ impl Session {
131 pub fn open(id: &str) -> Result<(Session, Value, Vec<Value>), String> { 131 pub fn open(id: &str) -> Result<(Session, Value, Vec<Value>), String> {
132 let path = sessions_dir().join(format!("{id}.jsonl")); 132 let path = sessions_dir().join(format!("{id}.jsonl"));
133 let raw = std::fs::read(&path).map_err(|e| format!("{}: {e}", path.display()))?; 133 let raw = std::fs::read(&path).map_err(|e| format!("{}: {e}", path.display()))?;
134 let _ = File::open(&path);
135 134
136 let mut model = String::new(); 135 let mut model = String::new();
137 let mut system = Value::Null; 136 let mut system = Value::Null;
diff --git a/tests/sessions.rs b/tests/sessions.rs
index df2f3b2..748b689 100644
--- a/tests/sessions.rs
+++ b/tests/sessions.rs
@@ -67,6 +67,9 @@ fn sessions_create_list_and_replay() {
67 67
68#[test] 68#[test]
69fn cli_lists_sessions_without_a_key() { 69fn cli_lists_sessions_without_a_key() {
70 // Spawning holds a copy of the process's file descriptions between fork and
71 // exec, which would keep a session lock alive while another test drops it.
72 let _env = ENV_LOCK.lock().unwrap_or_else(|e| e.into_inner());
70 let dir = temp_dir("cli"); 73 let dir = temp_dir("cli");
71 let output = Command::new(env!("CARGO_BIN_EXE_agent686")) 74 let output = Command::new(env!("CARGO_BIN_EXE_agent686"))
72 .env("AGENT686_DATA", &dir) 75 .env("AGENT686_DATA", &dir)