Save Qt editor and documentation updates
ober
9532781c339ae690690a0d6063ecf6055195b94a
deleted file mode 100644 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,53 +0,0 @@ -name: CI - -on: - push: - branches: [main, master] - pull_request: - workflow_dispatch: - -permissions: - contents: read - -env: - JERBOA_VERSION: v0.2.8 - JERBUILD_TOOL: ${{ github.workspace }}/.jerboa/bin/jerbuild - -jobs: - build-test-audit: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 - - - name: Security gate - run: make security - - - name: Install system tools - run: | - set -eu - sudo apt-get update - sudo apt-get install -y --no-install-recommends \ - build-essential \ - ca-certificates \ - curl \ - file \ - git \ - libpcre2-dev \ - libvterm-dev \ - pkg-config \ - python3 \ - qt6-base-dev \ - xauth \ - xvfb - - - name: Install Jerboa toolchain - run: sh support/ensure-jerboa.sh "$JERBOA_VERSION" .jerboa/bin - - - name: Build generated libraries - run: make build - - - name: Full test suite - run: make test - - - name: Native dependency audit - run: make audit deleted file mode 100644 --- a/.github/workflows/security-baseline.yml +++ /dev/null @@ -1,38 +0,0 @@ -name: Security Baseline - -on: - push: - branches: [main, master] - pull_request: - workflow_dispatch: - -permissions: - contents: read - -jobs: - baseline: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 - - - name: Required release files - run: | - set -eu - test -f LICENSE - test -f SECURITY.md - test -f .gitignore - find . -maxdepth 1 -iname "README*" -type f | grep -q . - - - name: Project security gate - run: make security - - - name: High-confidence secret scan - run: | - set -eu - pattern="(BEGIN (RSA|OPENSSH|EC|DSA|PRIVATE) KEY|ghp_[A-Za-z0-9_]{20,}|github_pat_[A-Za-z0-9_]{20,}|sk-(ant-api03|proj|svcacct)-[A-Za-z0-9_-]{30,}|AKIA[0-9A-Z]{16})" - matches="$(git grep -n -I -E "$pattern" -- . ":!*.png" ":!*.jpg" ":!*.jpeg" ":!*.gif" ":!*.so" ":!*.dylib" ":!*.o" ":!*.a" ":!*.boot" ":!*.tar.gz" || true)" - if [ -n "$matches" ]; then - echo "$matches" - echo "High-confidence secret pattern found." - exit 1 - fi new file mode 100644 --- /dev/null +++ b/ANCHORED_SUMMARY.md @@ -0,0 +1,51 @@ +## Objective +- Implement P1.6 (real frames — C-x 5 2) by creating a second QMainWindow that shares the buffer table, replacing the current virtual-frame system. + +## Important Details +- `app-state-frame` slot (`core.ss:1356`) used pervasively in both TUI and Qt backends — cannot change struct. +- `app-state-frame-set!` exported (`editor.ss:7`) but never used — available for reassigning the current frame. +- `*frame-list*` / `*current-frame-idx*` (`core.ss:1437–1438`) are shared globals for virtual frames; TUI also uses them — must remain unchanged. +- `qt-frame` struct (`window.ss:123–129`) has `splitter`, `root`, `windows`, `current-idx`, `main-win` fields. +- Startup (`app.ss:1005–1024`) creates one QMainWindow, tab bar, splitter, echo label, then calls `qt-frame-init!`. +- `qt-make-real-frame!` in `window.ss` replicates the full window layout: QMainWindow, central widget, tab bar, splitter, echo label, editor via `qt-frame-init!`. +- `qt-widget-show!`, `qt-widget-close!`, `qt-widget-set-focus!` are available via `:jerboa-qt/qt` import in `app.ss`. +- `qt-ensure-drop-filter!` is in `app.ss:2584–2590` — not called by `qt-make-real-frame!` to avoid circular dependency; drop support for new frames is a known limitation. +- Key handlers are installed via `(app-state-key-handler app)` stored in `app-state` at startup (`app.ss:1717–1722`). `cmd-make-frame` now calls this on the new frame's editor. +- New frames still lack minibuffer and tab-bar integration (deferred to P1.7+). + +## Work State +### Completed +- Added `*qt-real-frames*` (list of `qt-frame` structs) and `*qt-app-pointer*` globals in `window.ss`. +- Added `qt-make-real-frame!` function in `window.ss` that creates a complete QMainWindow with tab bar, splitter, echo label, and editor, then registers the frame in `*qt-real-frames*`. +- Added `qt-set-app-pointer!` export in `window.ss` for storing the Qt application pointer. +- Updated `app.ss` startup (`app.ss:1024` area) to register the initial frame in `*qt-real-frames*` and store the app pointer. +- Rewrote `cmd-make-frame` in `commands-shell.ss:958` to call `qt-make-real-frame!` and set `app-state-frame` to the new frame. +- Rewrote `cmd-other-frame` in `commands-shell.ss:991` to cycle focus through `*qt-real-frames*` using `qt-widget-set-focus!`. +- Rewrote `cmd-delete-frame` in `commands-shell.ss:1018` to close the current frame's `main-win` and remove it from `*qt-real-frames*`. +- Removed `list-index` from `window.ss` exports and definition; added `:std/srfi/1` import to `window.ss`, `commands-shell.ss`, and `helm-qt.ss` to resolve the duplicate-definition build error. + +### Active +- Build succeeds with no errors. +- Code is complete and ready for runtime testing (requires launching jemacs). + +### Recent Improvements +- `cmd-make-frame` installs key handlers on new frames' editors via `(app-state-key-handler app)`. +- `cmd-make-frame` attaches the current buffer to the new frame's editor (matches Emacs behavior). +- `cmd-other-frame` focuses the terminal view (not just editor) when the switched-to frame has a visible terminal buffer. +- New frames get a descriptive title ("jemacs - Frame N"). + +## Next Move +1. Test the real-frame commands (C-x 5 2, C-x 5 o, C-x 5 0) at runtime. + +## Relevant Files +- `src/jerboa-emacs/qt/window.ss`: `*qt-real-frames*`, `*qt-app-pointer*`, `qt-make-real-frame!`, `list-remove-idx` — core real-frame infrastructure; `:std/srfi/1` import added, `list-index` removed from exports/def. +- `src/jerboa-emacs/qt/app.ss:1005–1024`: startup window layout — template for `qt-make-real-frame!`; now registers initial frame in `*qt-real-frames*`. +- `src/jerboa-emacs/qt/commands-shell.ss:958–989`: rewritten `cmd-make-frame`. +- `src/jerboa-emacs/qt/commands-shell.ss:991–1016`: rewritten `cmd-other-frame`. +- `src/jerboa-emacs/qt/commands-shell.ss:1018–1032`: rewritten `cmd-delete-frame`. +- `src/jerboa-emacs/core.ss:1355–1383`: `app-state` struct with `frame` slot. +- `src/jerboa-emacs/core.ss:1435–1442`: `*frame-list*`, `*current-frame-idx*`, `frame-count` (shared with TUI, unchanged). +- `src/jerboa-emacs/qt/sci-shim.ss:75–83`: exported Qt window primitives. +- `src/jerboa-emacs/qt/app.ss:2584–2590`: `qt-ensure-drop-filter!` — not used in new frames yet. +- `lib/jerboa-emacs/qt/echo.sls`: generated file where the `list-index` duplicate-definition error occurred. +- `vendor/jerboa/lib/std/srfi/srfi-1.ss:118`: defines `list-index` (pred-based, variadic). --- a/README.md +++ b/README.md @@ -5,10 +5,10 @@ A Chez Scheme port of the jerboa-based Emacs-like text editor, featuring a TUI ( ## Overview jerboa-emacs is an Emacs-inspired editor built on top of: -- **[jerboa](https://github.com/jerboa-scheme)** — Chez Scheme runtime with Gerbil-compatible stdlib -- **[jerboa-scintilla](https://github.com/jafourni/jerboa-scintilla)** — Scintilla editor component FFI bindings -- **[jerboa-shell (jsh)](https://github.com/jafourni/jerboa-shell)** — POSIX shell interpreter -- **[jerboa-qt](https://github.com/jafourni/jerboa-qt)** — Qt 5/6 GUI bindings (Qt backend only) +- **[jerboa](https://git.jerboa.sh/ober/jerboa)** — Chez Scheme runtime with Gerbil-compatible stdlib +- **[jerboa-scintilla](https://git.jerboa.sh/ober/jerboa-scintilla)** — Scintilla editor component FFI bindings +- **[jerboa-shell (jsh)](https://git.jerboa.sh/ober/jerboa-shell)** — POSIX shell interpreter +- **[jerboa-qt](https://git.jerboa.sh/ober/jerboa-qt)** — Qt 5/6 GUI bindings (Qt backend only) The TUI backend runs in a terminal using Scintilla's text model. The Qt backend provides a full graphical interface. new file mode 100644 --- /dev/null +++ b/codex-session-019fb044.md @@ -0,0 +1,68058 @@ +# Codex Session 019fb044-c388-7dc0-b034-71ca95635625 + +- **Date**: 2026-07-29T23:45:24.453Z +- **CWD**: /Users/user/mine/jerboa-emacs +- **Model**: openai +- **CLI**: 0.146.0 + +--- + + +## Turn 1 + +### User + +# AGENTS.md instructions for /Users/user/mine/jerboa-emacs + +<INSTRUCTIONS> +## STOP: Editing `.ss`/`.sls` Files — Mandatory Rules + +These rules exist because local-model sessions have lost **hours** fighting +parenthesis imbalances that these rules would have prevented in seconds. +They override every habit from other editors and languages. + +1. **NEVER use `edit`, `write`, `sed`, `python`, `perl`, or `awk` to modify + `*.ss` or `*.sls` files.** Use the jerboa-mcp tools instead: + - Add a top-level form → `jerboa_balanced_insert` (anchor = one unique + complete form, e.g. the `def` above the insertion point). + - Replace exact text → `jerboa_balanced_replace`. It is **dry-run by + default** — pass `dry_run: false` to actually write. + - Create a whole new file → `jerboa_write_file` (use `verify: true` to + reject unbalanced content before it lands). +2. **After EVERY `.ss` change, run `jerboa_check_balance` before building.** + The balanced tools check automatically; if you bypassed them, check now. +3. **If a file ever becomes unbalanced, STOP.** Do NOT count parens by hand, + do NOT write paren-counting scripts, do NOT poke one character at a time. + Recovery is exactly one of: + - `git checkout -- <file>` and redo the edit with `jerboa_balanced_insert` + (preferred — one command, seconds), or + - `jerboa_repair_balance` (dry-run shows the plan; `apply: true` writes). +4. **Keep closer-runs short.** Never hand-write code that ends in more than + ~4 consecutive closers (`))))]` runs). Flatten deep nesting with helper + `def`s, `let*`, or cond `=>` clauses so no edit ever depends on counting + a long `)` run. +5. **`(def ...)` after an expression in a body is invalid.** Internal defines + must come first in a body, or use `let`/`let*`. The build error + "invalid context for definition" means you violated this — or a missing + paren above glued two top-level forms together (check balance first). + +## The Jerboa Language — Quick Reference + +Jerboa is a Scheme dialect built on Chez Scheme. It is Gerbil-inspired but its own language. **All user-facing code is `.ss` files. Never write `.sls` files for the user** — those are internal implementation files. + +### File Structure + +Every Jerboa file looks like this: + +```scheme +(import (jerboa prelude)) ;; ONE import gives you the ENTIRE language +;; Optional extra imports for modules NOT in the prelude: +;; (import (std net request)) + +(def (my-function x y) + (+ x y)) + +(displayln (my-function 1 2)) +``` + +Run with: `~/.local/bin/jerboa run file.ss` (or `jerboa run file.ss` if `~/.local/bin` is on your PATH). + +**NEVER** write `(library ...)` forms — that's `.sls` internal syntax. + +### Reader Syntax Extensions + +``` +[...] → plain parentheses — same as Gerbil and Chez Scheme +{method obj args} → (~ obj 'method args) — method dispatch +name: → keyword #:name +:std/sort → (std sort) — Gerbil-style module path +#<<END ... END → heredoc string +``` + +Square brackets `[...]` are interchangeable with `(...)`, exactly like Gerbil and stock Chez Scheme. You can freely use them in bindings, match clauses, and anywhere you'd use parentheses: +```scheme +;; All of these are correct: +(let ([x 1] [y 2]) (+ x y)) +(for/collect ([x (in-range 5)]) (* x x)) +(match val ([list a b] (+ a b))) +(cond [(> x 0) "positive"] [else "non-positive"]) +``` + +### CRITICAL: Things That DO NOT EXIST in Jerboa/Chez + +Claude frequently hallucinates these from Gerbil, Gambit, Racket, or R7RS training data. +**NONE of them are real in Jerboa/Chez. STOP and use the correct form.** + +#### AI Compatibility Aliases (these now work in the prelude) +The following names from other Scheme dialects are aliased in `(jerboa prelude)`: +- `hash-has-key?` → `hash-key?` (Racket) +- `hash-table-set!` → `hash-put!` (Racket) +- `directory-exists?` → `file-directory?` (Gambit) +- `eql?` → `eqv?` (Common Lisp) +- `random-integer` → `random` (Gambit) +- `read-line` → `get-line` wrapper (Gambit) — works with or without port arg +- `force-output` → `flush-output-port` wrapper (Gambit) — works with or without port arg +- `string-map` → char-level map (Racket/R7RS) — `(string-map f str)` + +#### Hallucinated Functions (still do NOT exist) +- `symbol<?` — use `(lambda (a b) (string<? (symbol->string a) (symbol->string b)))` +- `string-contains?` — use `(string-contains str sub)` (returns index or #f, NOT boolean) +- `define-struct` — use `(defstruct name (fields ...))` +- `raise` with a string — use `(error 'who "message" irritants ...)` +- `environment-bound?` — Gerbil-only. No direct Chez equivalent + +#### Gerbil/Gambit-isms (from training data — wrong in Jerboa) +- `time->seconds` — use `(time-second (current-time))` for epoch seconds +- `thread-sleep!` — Gambit. Use `(sleep (make-time 'time-duration 0 seconds))` +- `thread-yield` — no Chez equivalent. Use `(sleep (make-time 'time-duration 0 0))` as workaround +- `path-expand` with 2 args — Gerbil takes `(path-expand rel base)`. Jerboa takes 1 arg. Use `(path-join base rel)` for 2-arg version +- `process-status` — Gerbil. Use `(std misc process)` API in Jerboa +- `user-info-home` — Gerbil. Use `(getenv "HOME")` +- `the-environment` — Gerbil. Use `(interaction-environment)` in Chez +- `condition/report-string` — Gerbil. Use `(with-output-to-string (lambda () (display-condition c)))` +- `make-class-type` — Gerbil. Use `(defstruct ...)` or `(defclass ...)` in Jerboa +- `string-subst` — Gerbil. Not in prelude. Use `(string-replace str old new)` or implement manually +- `open-fd-pair` — Gambit. Does not exist in Chez; requires different API + +#### R6RS/Racket-isms (wrong variant) +- `make-equal-hashtable` — R6RS. Use `(make-hash-table)` from Jerboa prelude +- `arithmetic-shift` — Racket. Use `(bitwise-arithmetic-shift n k)` or `(ash n k)` in Chez +- `pregexp-match` — Racket. Use `(std text regex)` or `(std pregexp)` API in Jerboa + +### CRITICAL: Common Arity Mistakes + +- `(list-of? pred)` → returns a PREDICATE. It takes 1 arg. Use: `((list-of? number?) lst)` +- `(maybe pred)` → returns a PREDICATE. It takes 1 arg. Use: `((maybe string?) val)` +- `(in-range end)` or `(in-range start end)` or `(in-range start end step)` — NOT `(in-range start step end)` +- `(hash-ref ht key)` or `(hash-ref ht key default)` — NOT `(hash-ref key ht)` +- `(string-split str delimiter)` where delimiter is a CHAR: `(string-split "a,b" #\,)` +- `(make-rwlock)` — takes **0 args**, NOT `(make-rwlock 'name)` (Gerbil takes a name; Jerboa does not) +- `(path-expand path)` — takes **1 arg**, NOT `(path-expand rel base)` (Gerbil takes 2; use `path-join` for 2-arg) +- `(sort list predicate)` — Jerboa `(std sort)`/prelude order. Raw Chez `sort` is predicate-first, but Jerboa-facing code should use list first. + +### Core Forms (all from `(import (jerboa prelude))`) + +#### Definitions +```scheme +(def x 42) ;; variable +(def (f x y) (+ x y)) ;; function +(def (f x (y 10)) body) ;; optional param with default +(def (f x . rest) body) ;; rest args +(def* f ((x) ...) ((x y) ...)) ;; multi-arity +(defrule (name pat) template) ;; macro +``` + +#### Data Structures +```scheme +(defstruct point (x y)) ;; → make-point, point?, point-x, point-y, point-x-set! +(defstruct (circle shape) (radius)) ;; inheritance (single only) +(defmethod (area (self circle)) body) ;; method on type +(~ obj 'method arg ...) ;; dispatch (or {method obj arg ...}) +(defrecord person (name age)) ;; struct + pretty-print + ->alist +(define-enum color (red green blue)) ;; → color-red, color?, color->name +``` + +#### Pattern Matching +```scheme +(match value + (42 "exact") ;; literal + ((list a b c) (+ a b c)) ;; list destructure + ((cons h t) h) ;; pair + ((? number?) "num") ;; predicate + ((? string? s) (string-upcase s)) ;; predicate + bind + ((and (? number?) (? positive?)) "positive number") + ((or "yes" "y") #t) + ((=> string->number n) n) ;; view pattern + (n (where (> n 0)) "positive") ;; guard + (_ "default")) ;; wildcard +``` + +#### Error Handling +```scheme +(try expr (catch (e) handler) (finally cleanup)) +(try expr (catch (error? e) handler)) +(unwind-protect body cleanup) +(with-resource (var init cleanup) body) +``` + +#### Result Type (Rust-inspired ok/err) +```scheme +(ok 42) (err "bad") (ok? r) (err? r) +(unwrap (ok 42)) ;; → 42 (raises on err) +(unwrap-or (err "x") 0) ;; → 0 +(map-ok f result) (map-err f result) +(and-then result f) ;; monadic bind +(try-result expr) ;; exceptions → (err condition) +(try-result* expr) ;; exceptions → (err "message string") +(sequence-results list-of-results) ;; → (ok list) or first (err) +(->? (ok 10) (+ 5) (* 2)) ;; → (ok 30), short-circuits on err +``` + +#### Iterators +```scheme +(for ((x (in-range 5))) (displayln x)) +(for/collect ((x (in-range 5))) (* x x)) ;; → (0 1 4 9 16) +(for/fold ((sum 0)) ((x (in-range 10))) (+ sum x)) ;; → 45 +(for/or ((x lst)) (and (pred? x) x)) ;; first truthy +(for/and ((x lst)) (pred? x)) ;; all truthy + +;; Iterators: in-list, in-vector, in-string, in-range, in-hash-keys, +;; in-hash-values, in-hash-pairs, in-naturals, in-indexed, +;; in-port, in-lines, in-chars, in-bytes, in-producer +``` + +#### Threading Macros +```scheme +(-> x (f a) (g b)) ;; thread first: (g (f x a) b) +(->> x (f a) (g b)) ;; thread last: (g b (f a x)) +(as-> x v (f v) (g v)) ;; named +(some-> x (f) (g)) ;; short-circuit on #f +(cond-> x test (f) t2 (g)) ;; conditional steps +(->? (ok x) (f) (g)) ;; result-aware thread first +``` + +#### Ergo Typing +```scheme +(: expr pred?) ;; checked cast +(using (p (make-point 1 2) : point?) + (+ p.x p.y)) ;; dot-access → (point-x p) etc. +((list-of? number?) '(1 2 3)) ;; predicate factory → #t +((maybe string?) #f) ;; accepts #f or string → #t +``` + +#### Hash Tables +```scheme +(def ht (make-hash-table)) +(hash-put! ht "key" "val") +(hash-ref ht "key") ;; error if missing +(hash-ref ht "key" "default") ;; with default +(hash-get ht "key") ;; → val or #f +(hash-key? ht "key") ;; → #t/#f +(hash-remove! ht "key") +(hash->list ht) (hash-keys ht) (hash-values ht) +(hash-for-each (lambda (k v) ...) ht) +(list->hash-table '(("a" . 1) ("b" . 2))) +``` + +#### Strings +```scheme +(string-split "a,b,c" #\,) ;; → ("a" "b" "c") NOTE: char delimiter +(string-join '("a" "b") ",") ;; → "a,b" +(string-trim " hi ") ;; → "hi" +(string-prefix? "he" "hello") ;; → #t +(string-suffix? "lo" "hello") ;; → #t +(string-contains "hello" "ell") ;; → 1 (index, not boolean!) +(string-empty? "") ;; → #t +(str "age: " 42 "!") ;; → "age: 42!" (auto-coerce) +``` + +#### Lists +```scheme +(flatten '(1 (2 (3)))) ;; → (1 2 3) +(unique '(1 2 2 3)) ;; → (1 2 3) +(take lst n) (drop lst n) (take-last lst n) (drop-last lst n) +(every pred lst) (any pred lst) (filter-map f lst) +(group-by f lst) (zip lst1 lst2) (frequencies lst) +(partition pred lst) (interleave l1 l2) (mapcat f lst) +(distinct lst) (keep f lst) (split-at lst n) +(append-map f lst) (snoc lst elem) +``` + +#### Functional Combinators +```scheme +(compose f g) (comp f g) ;; (f (g x)) +(partial f arg ...) ;; partial application +(complement pred) (negate pred) ;; logical not +(identity x) (constantly v) ;; basic combinators +(curry f arg) (flip f) ;; currying, arg swap +(conjoin p1 p2) (disjoin p1 p2) ;; predicate AND/OR +(juxt f g) ;; → (lambda (x) (list (f x) (g x))) +(cut f <> y) ;; SRFI-26 partial: (lambda (x) (f x y)) +``` + +#### JSON +```scheme +(string->json-object "{\"key\":\"val\"}") ;; → hash table +(json-object->string ht) ;; → JSON string +(read-json port) (write-json obj port) +``` + +#### CSV +```scheme +(csv->alists "name,age\nAlice,30") ;; → (((name . "Alice") (age . "30"))) +(read-csv-file "data.csv") ;; → list of row lists +(write-csv-file "out.csv" rows) +``` + +#### DateTime +```scheme +(datetime-now) (datetime-utc-now) +(make-datetime 2026 3 27 12 0 0) +(parse-datetime "2026-03-27T12:00:00Z") +(datetime->iso8601 dt) (datetime->epoch dt) +(datetime-add dt duration) (datetime-diff dt1 dt2) +(datetime<? dt1 dt2) (day-of-week dt) (leap-year? 2024) +``` + +#### Paths +```scheme +(path-join "/home" "user" "f.txt") ;; → "/home/user/f.txt" +(path-directory "/a/b/f.txt") ;; → "/a/b" +(path-extension "file.txt") ;; → "txt" +(path-absolute? "/home") ;; → #t +``` + +#### File I/O +```scheme +(read-file-string "f.txt") ;; → entire file +(read-file-lines "f.txt") ;; → list of lines +(write-file-string "f.txt" "data") +``` + +#### Pretty Printing +```scheme +(pp expr) (pp-to-string expr) (pprint expr) +``` + +#### Formatting +```scheme +(format "~a is ~a" "Alice" 30) ;; → "Alice is 30" +(printf "x = ~a\n" 42) +(displayln "hello" " " "world") +``` + +#### Anaphoric / Conditional Binding +```scheme +(awhen (find x) (use it)) ;; binds result to `it` +(aif (find x) (use it) (default)) +(when-let (x (find y)) (use x)) +(if-let (x (find y)) (use x) (default)) +``` + +#### Loops +```scheme +(while test body ...) +(until test body ...) +(dotimes (i 10) body ...) ;; 0..9 +``` + +#### Misc Sugar +```scheme +(assert! (> x 0)) (assert! (> x 0) "message") +(alist (name "Alice") (age 30)) ;; → ((name . "Alice") (age . 30)) +(let-alist data (name age) body) +``` + +### What's NOT in the Prelude (requires separate import) + +```scheme +(import (std net request)) ;; HTTP client +(import (std net httpd)) ;; HTTP server +(import (std db sqlite)) ;; SQLite +(import (std actor)) ;; Actor system +(import (std async)) ;; Async/await +(import (std crypto digest)) ;; SHA, MD5 +(import (std text regex)) ;; Regex +(import (std text xml)) ;; XML +(import (std text yaml)) ;; YAML +(import (std os env)) ;; Environment variables +(import (std os signal)) ;; Signal handling +(import (std security sandbox)) ;; Sandboxing +``` + +### Chez Scheme Conflicts (handled by prelude) + +The prelude shadows these Chez builtins with Jerboa versions: +`make-hash-table`, `hash-table?`, `sort`, `sort!`, `printf`, `fprintf`, +`path-extension`, `path-absolute?`, `with-input-from-string`, +`with-output-to-string`, `iota`, `1+`, `1-`, `partition`, +`make-date`, `make-time` + +All standard Chez Scheme is still available — the prelude just re-exports +improved versions of the above. + +--- + +## Repository Boundaries + +When working in a Jerboa project, **ONLY modify files in the current repo** unless the user explicitly names another path. + +Common sibling repos that exist but must NOT be touched without explicit instruction: +- `~/mine/jerboa-emacs` — **NEVER touch**. Another model owns it. +- `~/mine/jerboa-mcp` — Legacy node MCP, superseded. The active MCP server now lives in THIS repo at `mcp/` + `data/`. Don't modify the legacy repo unless told. +- `~/mine/jerboa-shell` — Only modify when user explicitly says to work there. +- `~/mine/gerbil-mcp` — **NEVER touch**. Deprecated. +- `~/mine/gerbil-orig` — Read-only reference for upstream Gerbil. Never modify. + +If a user instruction mentions a file path, use EXACTLY that path. Do not substitute a similar-looking path from another repo. + +### Never Reference Sibling Checkouts in Build Files + +Build files (Makefile, shell scripts, CI config) must **never** resolve a +dependency via a relative sibling path (`../jerboa-foo`) or an absolute +`~/mine/jerboa-foo` path. That layout is specific to this one machine — +other users and CI do not have it. Always vendor instead: fetch/clone the +dependency into `vendor/` (or this repo's equivalent) at build time, or use +a pinned-release fetch script, so the build is reproducible without +assuming any sibling checkout exists. + +A sibling-path fallback is not just a portability bug: it can silently +substitute a full alternate source tree (build config, embedded data, +secrets) for the vendored one, with no equivalent safety default, changing +what actually gets built without any indication. If you find one +(`grep -rn '\.\./jerboa\|~/mine/jerboa'` over Makefiles/scripts), remove it +and vendor properly instead. + +--- + +## Build & Verification + +After modifying any `.ss` or `.sls` (Jerboa Scheme) source files, always run the build command and fix any errors before moving on. Common issues include: missing imports, wrong function names, and duplicate definitions. + +### Stale Artifacts + +If edits seem to have no effect after `make build`, delete stale compiled files: +```bash +find lib -name "*.so" -delete && find lib -name "*.wpo" -delete && make build +``` +Run `jerboa_stale_static` to detect stale `.so` files before debugging "why doesn't my edit work?". + +## Pre-commit Requirements + +**ALWAYS** run a clean build **before** committing any code to this repository. Pick the right target for the *current* platform: + +- **Linux**: run `make docker-build` — the Docker image must build cleanly against the full musl-static release pipeline. +- **macOS / FreeBSD / other**: run `make binary` — the native local build must succeed. Do **not** run `make docker-build` here; Docker on non-Linux hosts is slow and not the canonical pipeline for those platforms. + +Do not commit if the build fails. + +## Act First, Read Less + +When making changes, read only what you need to make the edit, then make it. +Do not read more than 3 files before acting. Do not re-read files you already +read. Do not verify things you already know. If you have enough context to make +a change, make it. The user will interrupt you if you are wrong. + +## Jerboa MCP Tools — MANDATORY Usage + +Jerboa is a niche Scheme dialect with limited training data. **Never guess — always verify** with MCP tools. Tool descriptions are available at runtime via the MCP server; this section covers **when** and **why** to use each tool. + +### MANDATORY Workflow Order (for writing new code) + +1. **`jerboa_howto`** — BEFORE writing code, search cookbook for verified patterns +2. **`jerboa_module_exports`** / **`jerboa_function_signature`** — confirm APIs exist and check arities +3. Write the code +4. **`jerboa_verify`** — combined syntax + compile + lint + arity + duplicate check (use instead of individual tools) +5. **`jerboa_security_scan`** — for code involving FFI, shell commands, or file I/O + +### Essential Tools (use proactively) + +| When | Tool | +|---|---| +| Before writing ANY Jerboa code | `jerboa_howto` — cookbook has verified patterns with correct imports | +| Check what a module exports | `jerboa_module_exports` — never guess function names | +| Check function arity/args | `jerboa_function_signature` — prevents wrong-arg-count errors | +| Validate your code | `jerboa_verify` — one-stop syntax+compile+lint+arity check | +| Test expressions interactively | `jerboa_eval` — use `imports` param for modules, `env` for FFI paths | +| Persistent interactive testing | `jerboa_repl_session` — maintains state across evaluations | +| Debug an error message | `jerboa_explain_error` + `jerboa_error_fix_lookup` | +| Understand unfamiliar code | `jerboa_file_summary` + `jerboa_document_symbols` | +| Find where something is defined | `jerboa_find_definition` — source file, module, kind, arity | +| Search for symbol by substring | `jerboa_apropos` or `jerboa_smart_complete` | +| Build the project | `jerboa_build_and_report` or `jerboa_make` — prefer over bash `make` | +| Run tests | `jerboa_run_tests` — prefer over ad hoc shell test invocations | +| Check for stale .so artifacts | `jerboa_stale_static` — common cause of "edit has no effect" | +| Macro expansion | `jerboa_expand_macro` / `jerboa_trace_macro` | +| Inspect struct/class types | `jerboa_class_info` — fields, inheritance, constructor signature | +| FFI work | `jerboa_ffi_scaffold` / `jerboa_ffi_type_check` / `jerboa_ffi_null_safety` | +| Port Gerbil code | `jerboa_migration_check` + `jerboa_translate_scheme` | +| Detect paren imbalance | `jerboa_check_balance` — use BEFORE `make build` after deep edits | +| Edit a `.ss` file | `jerboa_balanced_insert` / `jerboa_balanced_replace` — NEVER raw `edit`/`sed`/`python` (see top of file) | +| Create a `.ss` file | `jerboa_write_file` — whole-file atomic write, `verify: true` rejects unbalanced content | +| File already unbalanced | `jerboa_repair_balance` — dry-run repair plan; or `git checkout -- <file>` and redo with `balanced_insert` | +| Full project audit | `jerboa_project_health_check` — balance, exports, cycles, duplicates | +| Security audit | `jerboa_security_audit` + `jerboa_import_policy_check` | +| Static build audit | `jerboa_static_symbol_audit` + `jerboa_boot_library_audit` | +| Explore a module | `jerboa_module_catalog` (replaces multiple `jerboa_doc` calls) | +| Look up any symbol | `jerboa_doc` — type, arity, qualified name, related symbols | +| Read stdlib source | `jerboa_stdlib_source` — see internal implementations | + +### Cookbook & Knowledge Management + +- **`jerboa_howto`** / **`jerboa_howto_get`**: Search and retrieve verified recipes +- **`jerboa_howto_add`**: Save new patterns to cookbook (MANDATORY when you discover something non-trivial) +- **`jerboa_howto_run`** / **`jerboa_howto_verify`**: Validate recipes still work +- **`jerboa_error_fix_add`**: Save error→fix mappings for common mistakes +- **`jerboa_anti_pattern_lookup`**: Search reusable local-model mistakes and failed strategies + +**The knowledge base is `data/*.sexp` in THIS repo**, embedded into `jmcp` at build time. The write tools above edit it live — the server reads `data/` from disk first, with the embedded copy as fallback (`JERBOA_MCP_REPO` points every client at this repo). When you add a stdlib/language feature, also update `data/` (a cookbook recipe + `api-signatures.sexp` + `changelog.sexp`) and **commit it**. Run `make jmcp` (or `make jmcp-portable`) only to refresh the embedded copy shipped in portable binaries. + +### Code Generation & Refactoring + +`jerboa_rename_symbol`, `jerboa_balanced_replace`, `jerboa_balanced_insert`, `jerboa_write_file`, `jerboa_repair_balance`, `jerboa_wrap_form`, `jerboa_splice_form`, `jerboa_scaffold_test`, `jerboa_generate_module`, `jerboa_translate_scheme`, `jerboa_project_template`, `jerboa_httpd_handler_scaffold`, `jerboa_db_pattern_scaffold`, `jerboa_actor_ensemble_scaffold` + +### Feature Suggestions + +- **`jerboa_list_features`** / **`jerboa_suggest_feature`** / **`jerboa_vote_feature`**: Track and submit tooling improvement ideas + +--- + +## MANDATORY: Save What You Learn + +Jerboa is niche — every non-trivial pattern you discover prevents future sessions from re-discovering it. + +### Save to cookbook (`jerboa_howto_add`) whenever you: +- Discover a working pattern through `jerboa_eval` or trial-and-error +- Figure out correct imports, arities, or calling conventions that weren't obvious +- Find a workaround for a Jerboa quirk or undocumented behavior + +**Before saving**: check `jerboa_howto` to avoid duplicates. **Do NOT save**: trivial one-liners, project-specific logic, or existing recipes. + +**Recipe format**: `id` (kebab-case), `tags` (4-6 search keywords incl. module name), `imports` (all required), `code` (complete working example), `notes` (gotchas/alternatives). + +### Save anti-patterns (`data/anti-patterns.sexp`) whenever you: +- See a plausible local-model strategy that failed verification +- Find a weak verifier pattern that allowed false success +- See a repeated repair loop, such as broad-reading after a concrete error +- Find a generic runtime mistake, such as missing lower-bound checks before vector access + +**Before saving**: check `jerboa_anti_pattern_lookup` to avoid duplicates. If none exists, call `jerboa_anti_pattern_add`; only edit `data/anti-patterns.sexp` directly if the writer tool is unavailable. Save the normalized reusable mistake, not the whole trace or benchmark name. + +**Anti-pattern format**: `id`, `title`, `kinds`, `severity`, `tags`, `pattern`, `avoid`, `advice`, `tools`. + +### Save error fixes (`jerboa_error_fix_add`) whenever you: +- See exact compiler/runtime/verifier text with a repeatable repair +- Hit an error that `jerboa_failure_advisor` should classify better next time +- Debug a local-model generated-code failure where a short diagnosis prevents another failed iteration + +**Before saving**: check `jerboa_error_fix_lookup` with the exact error text. **Do NOT save**: one-off project business-logic mistakes. + +**Error-fix format**: `id`, `pattern`, `fix`; optional `type`, `explanation`, `code_example`. + +### Suggest tooling improvements (`jerboa_suggest_feature`) whenever you: +- Make multiple sequential tool calls that could be one tool +- Fall back to bash because an MCP tool is missing or insufficient + +**Before suggesting**: check `jerboa_list_features`; vote with `jerboa_vote_feature` if it already exists. + +### Save Discoveries Mechanisms +- **`/save-discoveries` skill**: invoke anytime to review session and save recipes, anti-patterns, error fixes, feature suggestions, and security patterns +- **PreCompact hook**: add `PreCompact` hook with `type: "prompt"` in `.claude/settings.json` to auto-save before context compaction + +--- + +## Common Workflows + +- **Write new code**: `jerboa_howto` -> `jerboa_module_exports` -> write code -> `jerboa_verify` -> `jerboa_security_scan` +- **Debug an error**: `jerboa_explain_error` -> follow suggested tools -> `jerboa_howto` for fix patterns +- **Understand unfamiliar code**: `jerboa_file_summary` -> `jerboa_document_symbols` -> `jerboa_module_deps` +- **Refactor a module**: `jerboa_check_exports` -> `jerboa_find_callers` -> `jerboa_rename_symbol` -> `jerboa_check_import_conflicts` +- **Build project**: `jerboa_build_conflict_check` -> `jerboa_make` -> `jerboa_build_and_report` +- **Port from Gerbil**: `jerboa_migration_check` -> `jerboa_translate_scheme` -> `jerboa_verify` -> `jerboa_check_syntax` +- **Audit project quality**: `jerboa_verify` -> `jerboa_lint` -> `jerboa_dead_code` -> `jerboa_dependency_cycles` +- **Debug a crash**: `jerboa_stale_static` -> `jerboa_bisect_crash` -> `jerboa_ffi_type_check` +- **Learn a module**: `jerboa_stdlib_source` -> `jerboa_module_catalog` -> `jerboa_module_quickstart` +- **Security audit**: `jerboa_security_audit` -> `jerboa_import_policy_check` -> `jerboa_unsafe_import_lint` +- **Static build audit**: `jerboa_static_symbol_audit` -> `jerboa_boot_library_audit` -> `jerboa_rust_musl_build` +- **Safe-by-default check**: `jerboa_safe_prelude_check` -> `jerboa_resource_leak_check` -> `jerboa_safe_prelude_generate` +- **Debug editor command**: `jerboa_command_trace` with `project_path` and `buffer_type` + +## Workflow Conventions + +When implementing new features, always complete the documentation update in the same session. Document non-trivial solutions as howto recipes in the cookbook system. + +</INSTRUCTIONS> +<environment_context> + <cwd>/Users/user/mine/jerboa-emacs</cwd> + <shell>bash</shell> + <current_date>2026-07-29</current_date> + <timezone>America/Boise</timezone> + <filesystem><workspace_roots><root>/Users/user/mine/jerboa-emacs</root></workspace_roots><permission_profile type="disabled"><file_system type="unrestricted" /></permission_profile></filesystem> +</environment_context> + +### User + +Please convert this repo to use podman! instead of docker. see other ~/mine/jerboa* maybe jerboa-code? I forget. + +### Assistant + +I’ll inspect the repo’s Docker references first, then look at sibling repos only as read-only examples since this change belongs in `jerboa-emacs`. After that I’ll patch the current repo and run the relevant checks I can find. + +> **Tool**: exec_command — `{"cmd": "rg -n \"docker|Docker|DOCKER|container\" .", "workdir": "/Users/user/mine/jerboa-emacs", "yield_time_ms": 10000, "max_output_tokens": 20000}` + +> **Tool**: exec_command — `{"cmd": "rg --files .", "workdir": "/Users/user/mine/jerboa-emacs", "yield_time_ms": 10000, "max_output_tokens": 12000}` + +> **Tool**: exec_command — `{"cmd": "find /Users/user/mine -maxdepth 1 -type d -name 'jerboa*' -print", "workdir": "/Users/user/mine/jerboa-emacs", "yield_time_ms": 10000, "max_output_tokens": 12000}` + +<details><summary>output</summary> + +``` +Chunk ID: c09de4 +Wall time: 0.0000 seconds +Process exited with code 0 +Original token count: 14524 +Output: +Warning: truncated output (original token count: 14524) +Total output lines: 584 + +./src/jerboa-emacs/editor-extra-editing.ss:1478:;;; Docker Compose integration +./src/jerboa-emacs/editor-extra-editing.ss:1481:(def (cmd-docker-compose app) +./src/jerboa-emacs/editor-extra-editing.ss:1482: "Run docker compose command interactively." +./src/jerboa-emacs/editor-extra-editing.ss:1484: (args +... (truncated) +``` +</details> + +<details><summary>output</summary> + +``` +Chunk ID: 653df8 +Wall time: 0.0000 seconds +Process exited with code 0 +Original token count: 2068 +Output: +./src/jerboa/repl-socket.ss +./src/jerboa-emacs/editor-extra-media2.ss +./src/jerboa-emacs/core.ss +./src/jerboa-emacs/org-highlight.ss +./src/jerboa-emacs/editor-extra-final.ss +./src/jerboa-emacs/editor-extra-media.ss +./src/jerboa-emacs/eshell.ss +./src/jerboa-emacs/keymap.ss +./src/jerboa-emacs/editor-extra-editing.ss +./src/jerboa-emacs/ipc.ss +./src/jerboa-emacs/persist.ss +./src/jerboa-emacs/repl +... (truncated) +``` +</details> + +<details><summary>output</summary> + +``` +Chunk ID: a6d598 +Wall time: 0.0000 seconds +Process exited with code 0 +Original token count: 553 +Output: +/Users/user/mine/jerboa-virus +/Users/user/mine/jerboa-code +/Users/user/mine/jerboa-scintilla +/Users/user/mine/jerboa-tetris +/Users/user/mine/jerboa-llm-search +/Users/user/mine/jerboa-asm +/Users/user/mine/jerboa-ssd-recognizer +/Users/user/mine/jerboa-edge +/Users/user/mine/jerboa-websearch +/Users/user/mine/jerboa-sshd +/Users/user/mine/jerboa-sqlite +/Users/user/mine/jerboa-mail +/Users/user/mine/j +... (truncated) +``` +</details> + +### Assistant + +The matches are mostly Jerboa `.ss` command implementations plus Dockerfile build recipes and docs. Since `.ss` edits are involved, I need to use the repository’s balanced Jerboa tooling instead of raw file writes for those files. + +### Assistant + +I found existing Podman command names documented as scaffolded, but the implemented container UI still shells out to `docker`. I’m checking the nearby code and one sibling example for naming conventions, then I’ll make the smallest consistent conversion. + +> **Tool**: exec_command — `{"cmd": "nl -ba src/jerboa-emacs/editor-extra-modes.ss | sed -n '430,505p'", "workdir": "/Users/user/mine/jerboa-emacs", "yield_time_ms": 10000, "max_output_tokens": 12000}` + +> **Tool**: exec_command — `{"cmd": "nl -ba src/jerboa-emacs/editor-extra-editing.ss | sed -n '1468,1542p'", "workdir": "/Users/user/mine/jerboa-emacs", "yield_time_ms": 10000, "max_output_tokens": 12000}` + +> **Tool**: exec_command — `{"cmd": "rg -n \"podman|Podman|docker|Docker\" /Users/user/mine/jerboa-code /Users/user/mine/jerboa -g '!*vendor*'", "workdir": "/Users/user/mine/jerboa-emacs", "yield_time_ms": 10000, "max_output_tok` + +<details><summary>output</summary> + +``` +Chunk ID: eeb881 +Wall time: 0.0000 seconds +Process exited with code 0 +Original token count: 1013 +Output: + 430 (echo-message! (app-state-echo app) (string-append "'" word "': no suggestions")))))))))) + 431 + 432 ;; Bibliography / citar + 433 (def (cmd-citar-insert-citation app) + 434 "Insert citation — prompts for citation key." + 435 (let ((key (app-read-string app "Citation key: "))) + 436 (when (and key (not (string-empty? key))) + 437 (let* ((fr (app-st +... (truncated) +``` +</details> + +<details><summary>output</summary> + +``` +Chunk ID: 7e6fd7 +Wall time: 0.0000 seconds +Process exited with code 0 +Original token count: 1008 +Output: + 1468 arguments: '("plan" "-no-color") + 1469 directory: dir + 1470 stderr-redirection: #t)))) + 1471 (let ((result (read-line p #f))) + 1472 (close-port p) + 1473 (or result "No output"))))))) + 1474 +... (truncated) +``` +</details> + +<details><summary>output</summary> + +``` +Chunk ID: 16da2b +Wall time: 0.0000 seconds +Process exited with code 0 +Original token count: 6652 +Output: +/Users/user/mine/jerboa/README.md:245:make docker-build +/Users/user/mine/jerboa/AGENTS.md.example:67:cross-build setup. Never use Docker or Podman for building, testing, smoke +/Users/user/mine/jerboa/AGENTS.md.example:91:- Do not add Dockerfiles, container scripts, Podman invocations, or container-based verification paths. +/Users/user/mine/jerboa/Makefile:296:.PHONY: help chez static-supporte +... (truncated) +``` +</details> + +### Assistant + +The sibling example confirms `podman run --rm --platform ...` style for smoke tests. I’m also going to preserve compatibility where command names are part of the editor surface by adding Podman-facing aliases rather than deleting all old names blindly. + +> **Tool**: jerboa_howto — `{"query": "open-process command shell command process arguments string-split editor command integration", "max_results": 3, "compact": true}` + +<details><summary>output</summary> + +``` +Wall time: 0.3430 seconds +Output: +[{"type":"text","text":"Found 3 recipe(s) for \"open-process command shell command process arguments string-split editor command integration\":\n\n json-command-surface-for-editor-frontends - Expose a machine-readable JSON command surface for editor frontends\n tags: json, emacs, frontend, cli, hash-table, command-protocol\n\n intercept-exit-in-subcommand - Intercept (exit n) in a subcommand without terminating the host process\n tags: exit, handler, gua +... (truncated) +``` +</details> + +### Assistant + +I didn’t find a cookbook recipe specifically for Podman integration; the existing subprocess pattern is already local and uses `open-process`/`open-input-process`. I’m checking the build targets now, since those are likely the user-visible Docker-to-Podman conversion points outside the editor commands. + +> **Tool**: exec_command — `{"cmd": "nl -ba Makefile | sed -n '1,220p'", "workdir": "/Users/user/mine/jerboa-emacs", "yield_time_ms": 10000, "max_output_tokens": 16000}` + +> **Tool**: exec_command — `{"cmd": "nl -ba Makefile | sed -n '220,520p'", "workdir": "/Users/user/mine/jerboa-emacs", "yield_time_ms": 10000, "max_output_tokens": 20000}` + +> **Tool**: exec_command — `{"cmd": "nl -ba README.md | sed -n '1,220p'", "workdir": "/Users/user/mine/jerboa-emacs", "yield_time_ms": 10000, "max_output_tokens": 20000}` + +<details><summary>output</summary> + +``` +Chunk ID: 7a7d6e +Wall time: 0.0000 seconds +Process exited with code 0 +Original token count: 3336 +Output: + 1 VENDOR ?= $(CURDIR)/vendor + 2 BIN_DIR ?= $(HOME)/.local/bin + 3 DIST_DIR ?= dist + 4 SBOM_DIR ?= $(DIST_DIR)/sbom + 5 REPRO_DIR ?= $(DIST_DIR)/reproducibility + 6 EDITOR_FLOW_EVIDENCE_DIR ?= $(DIST_DIR)/editor-flow-evidence + 7 RELEASE_EVIDENCE_DIR ?= $(DIST_DIR)/release-evidence + 8 + 9 # Standalone jerbuild toolchain. This mirrors the bootstrap path u +... (truncated) +``` +</details> + +<details><summary>output</summary> + +``` +Chunk ID: 519ea4 +Wall time: 0.0000 seconds +Process exited with code 0 +Original token count: 4354 +Output: + 220 @echo " clean Remove build artifacts" + 221 @echo " JEMACS_FEATURES=aws make <target> Enable optional AWS EC2 SSH support" + 222 + 223 vendor-deps: + 224 @echo "=== Vendoring dependencies into $(VENDOR) ===" + 225 @mkdir -p $(VENDOR) + 226 @for repo in $(VENDOR_REPOS); do \ + 227 case "$$repo" in \ + 228 jerboa) url="$(JERBOA_REPO)"; rev="$(JERBOA_REV) +... (truncated) +``` +</details> + +<details><summary>output</summary> + +``` +Chunk ID: 33f2f1 +Wall time: 0.0000 seconds +Process exited with code 0 +Original token count: 2214 +Output: + 1 # jerboa-emacs + 2 + 3 A Chez Scheme port of the jerboa-based Emacs-like text editor, featuring a TUI (terminal) backend and a Qt graphical frontend. + 4 + 5 ## Overview + 6 + 7 jerboa-emacs is an Emacs-inspired editor built on top of: + 8 - **[jerboa](https://github.com/jerboa-scheme)** — Chez Scheme runtime with Gerbil-compatible stdlib + 9 - **[jerboa-scin +... (truncated) +``` +</details> + +### Assistant + +The Makefile already has Podman target names, but they currently route through Docker or are disabled. I’m going to flip those to real Podman commands and keep `docker-static-qt` as a compatibility alias to the new Podman-backed target. + +> **Tool**: exec_command — `{"cmd": "nl -ba Makefile | sed -n '520,880p'", "workdir": "/Users/user/mine/jerboa-emacs", "yield_time_ms": 10000, "max_output_tokens": 22000}` + +> **Tool**: exec_command — `{"cmd": "nl -ba Dockerfile.qt | sed -n '1,25p'", "workdir": "/Users/user/mine/jerboa-emacs", "yield_time_ms": 10000, "max_output_tokens": 8000}` + +> **Tool**: exec_command — `{"cmd": "nl -ba Dockerfile.tui | sed -n '1,25p'", "workdir": "/Users/user/mine/jerboa-emacs", "yield_time_ms": 10000, "max_output_tokens": 8000}` + +<details><summary>output</summary>