diff options
| -rw-r--r-- | CHANGELOG.md | 22 | ||||
| -rw-r--r-- | Cargo.lock | 2 | ||||
| -rw-r--r-- | Cargo.toml | 2 | ||||
| -rw-r--r-- | README.md | 28 | ||||
| -rwxr-xr-x | comp.sh | 248 | ||||
| -rw-r--r-- | src/session.rs | 1 | ||||
| -rw-r--r-- | tests/sessions.rs | 3 |
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. | |||
| 7 | file, and the tool schemas the model sees. Anything a script or a resumed session | 7 | file, and the tool schemas the model sees. Anything a script or a resumed session |
| 8 | could depend on counts as API. | 8 | could 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 | |||
| 20 | Verified on this machine: the native x86_64 build requires `GLIBC_2.34`, the | ||
| 21 | static musl build is 4.1 MiB, runs on Debian 10 (glibc 2.28), and reaches the | ||
| 22 | live 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 |
| @@ -10,7 +10,7 @@ checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" | |||
| 10 | 10 | ||
| 11 | [[package]] | 11 | [[package]] |
| 12 | name = "agent686" | 12 | name = "agent686" |
| 13 | version = "0.7.1" | 13 | version = "0.8.0" |
| 14 | dependencies = [ | 14 | dependencies = [ |
| 15 | "crossterm", | 15 | "crossterm", |
| 16 | "libc", | 16 | "libc", |
| @@ -1,6 +1,6 @@ | |||
| 1 | [package] | 1 | [package] |
| 2 | name = "agent686" | 2 | name = "agent686" |
| 3 | version = "0.7.1" | 3 | version = "0.8.0" |
| 4 | edition = "2021" | 4 | edition = "2021" |
| 5 | description = "A small coding agent for a 32-bit Debian box" | 5 | description = "A small coding agent for a 32-bit Debian box" |
| 6 | publish = false | 6 | publish = false |
| @@ -1,24 +1,33 @@ | |||
| 1 | # agent686 | 1 | # agent686 |
| 2 | 2 | ||
| 3 | A small coding agent for a 32-bit Debian box: one binary, six tools, line mode. | 3 | A small coding agent for Debian-class Linux: one binary, six tools, line mode. |
| 4 | 4 | ||
| 5 | Built because the existing harnesses are TypeScript bundles that need a modern | 5 | Built because the existing harnesses are TypeScript bundles that either need a |
| 6 | CPU, and the target here is a Debian 12 i386 machine with 2 cores and 4 GB. | 6 | modern CPU or a Node runtime. This one is pure Rust with no runtime dependency, |
| 7 | and it builds for whatever machine you are on. | ||
| 7 | 8 | ||
| 8 | ``` | 9 | ``` |
| 9 | 3.5 MiB ELF 32-bit LSB pie, Intel i386 | 10 | 4.0 MiB x86_64 glibc build, GLIBC_2.34 required |
| 10 | GLIBC_2.34 required (target has 2.36) | 11 | 4.1 MiB x86_64 static musl build, no libc dependency |
| 11 | startup ~0.8 ms | 12 | ~1 ms startup |
| 12 | ``` | 13 | ``` |
| 13 | 14 | ||
| 14 | ## Build | 15 | ## Build |
| 15 | 16 | ||
| 16 | ```sh | 17 | ```sh |
| 17 | cargo 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 | ||
| 21 | The 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 |
| 25 | target triple, and the `cfg` values the code will see. A native glibc build | ||
| 26 | inherits this machine's glibc floor, which is why the portable paths are printed | ||
| 27 | next to it: static musl removes the floor entirely, and building inside an older | ||
| 28 | Debian image lowers it. | ||
| 29 | |||
| 30 | The gate matters: the dev host's glibc is newer than the target's, so a | ||
| 22 | dependency can silently raise the required symbol version. | 31 | dependency 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 |
| @@ -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. | ||
| 11 | set -euo pipefail | ||
| 12 | |||
| 13 | here=$(cd "$(dirname "$0")" && pwd) | ||
| 14 | run=0 | ||
| 15 | plan=native | ||
| 16 | |||
| 17 | for 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 | ||
| 31 | done | ||
| 32 | |||
| 33 | say() { printf '%s\n' "$*"; } | ||
| 34 | section() { printf '\n\033[1m== %s\033[0m\n' "$*"; } | ||
| 35 | note() { printf ' %s\n' "$*"; } | ||
| 36 | |||
| 37 | # ---------------------------------------------------------------- detection | ||
| 38 | |||
| 39 | arch=$(uname -m) | ||
| 40 | kernel=$(uname -r) | ||
| 41 | |||
| 42 | distro=unknown | ||
| 43 | if [ -r /etc/os-release ]; then | ||
| 44 | # shellcheck disable=SC1091 | ||
| 45 | . /etc/os-release | ||
| 46 | distro=${PRETTY_NAME:-${ID:-unknown}} | ||
| 47 | fi | ||
| 48 | |||
| 49 | libc=unknown | ||
| 50 | libc_version= | ||
| 51 | if getconf GNU_LIBC_VERSION >/dev/null 2>&1; then | ||
| 52 | libc=glibc | ||
| 53 | libc_version=$(getconf GNU_LIBC_VERSION | awk '{print $2}') | ||
| 54 | elif 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) | ||
| 57 | elif ls /lib/ld-musl-*.so.1 >/dev/null 2>&1; then | ||
| 58 | libc=musl | ||
| 59 | fi | ||
| 60 | |||
| 61 | cpu_model=$(grep -m1 'model name' /proc/cpuinfo 2>/dev/null | cut -d: -f2- | sed 's/^ *//' || true) | ||
| 62 | cpu_flags=$(grep -m1 '^flags' /proc/cpuinfo 2>/dev/null | cut -d: -f2- || true) | ||
| 63 | |||
| 64 | rustc_version=$(rustc -V 2>/dev/null || echo "not installed") | ||
| 65 | cargo_version=$(cargo -V 2>/dev/null | awk '{print $2}' || echo "not installed") | ||
| 66 | |||
| 67 | # ---------------------------------------------------------------- triple map | ||
| 68 | |||
| 69 | triple_gnu=unknown-unknown-linux-gnu | ||
| 70 | triple_musl=unknown-unknown-linux-musl | ||
| 71 | baseline_flag= | ||
| 72 | |||
| 73 | case "$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 | ;; | ||
| 111 | esac | ||
| 112 | |||
| 113 | native_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. | ||
| 118 | defsym_flag= | ||
| 119 | if [ "$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" | ||
| 121 | fi | ||
| 122 | |||
| 123 | # ---------------------------------------------------------------- report | ||
| 124 | |||
| 125 | section "machine" | ||
| 126 | note "distro $distro" | ||
| 127 | note "arch $arch ($(getconf LONG_BIT 2>/dev/null || echo '?')-bit)" | ||
| 128 | note "kernel $kernel" | ||
| 129 | note "libc ${libc}${libc_version:+ $libc_version}" | ||
| 130 | note "cpu ${cpu_model:-unknown}" | ||
| 131 | note "rust $rustc_version" | ||
| 132 | note "cargo $cargo_version" | ||
| 133 | if [ -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 | ||
| 139 | fi | ||
| 140 | |||
| 141 | section "target" | ||
| 142 | case "$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 | ;; | ||
| 152 | esac | ||
| 153 | |||
| 154 | if [ "$baseline_flag" = "-C target-cpu=x86-64" ]; then | ||
| 155 | note "baseline x86-64 (SSE2): runs on any 64-bit x86 CPU" | ||
| 156 | fi | ||
| 157 | |||
| 158 | case "$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 | ;; | ||
| 167 | esac | ||
| 168 | |||
| 169 | section "commands" | ||
| 170 | |||
| 171 | case "$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 | ;; | ||
| 211 | esac | ||
| 212 | |||
| 213 | section "cfg the code will see" | ||
| 214 | if 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 | ||
| 221 | else | ||
| 222 | note "rustc not found; no cfg to show" | ||
| 223 | fi | ||
| 224 | |||
| 225 | if [ "$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 | ||
| 248 | fi | ||
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] |
| 69 | fn cli_lists_sessions_without_a_key() { | 69 | fn 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) |
