marfrit d4c20f09df docs/PHASE7: review fold-in — 3 BLOCKERs + 6 CONCERNs + 5 NITs
Sonnet-reviewed (per the reviews-use-sonnet feedback memory).

BLOCKERs (RESOLVED in-place):

R1. M.chat would silently return (text, nil) for ALL non-streaming
    callers — 4 of 5 categories (summarize/delegate/memory_summarize/
    probe) flow through broker.chat, NOT chat_stream. §4 now shows
    the explicit M.chat update that captures kind=="usage" alongside
    "text" and returns (text, usage).

R2. call_broker fallback retry would credit usage to the wrong model
    name. Fix: broker emits payload.model = model_cfg.model (which IS
    the fallback's name when called with fb_cfg — chat_stream's
    upvar). Wrapper keys by payload.model, NOT outer model_name. §4
    + §13 commit 3 reflect.

R3. build_request has TWO internal callers inside broker.lua itself,
    not just the public surface. Plan §13 commit 1 risk row now
    spells this out explicitly so the implementer doesn't read "every
    caller already passes opts" as "external-only".

CONCERNs (FOLDED):

R4. Single cost_warn_fired flag covers two thresholds — first-to-fire
    suppresses the other. Split into ctx.cost_warn_state = { dollars
    = false, tokens = false }; :cost reset clears both. §7 + §13.

R5. Warn-check centralization — single _record_usage helper in
    repl.lua wraps ctx:add_usage AND does threshold check. safety.lua
    routes via helpers.on_usage / opts.on_usage callbacks. context.lua
    stays decoupled from renderer.

R6. Preserve nil-vs-0 cost distinction. Accumulator slot gains
    `is_local = true` (sticky) when ANY recorded usage had cost==nil.
    `:cost detail` annotation comes from is_local flag, not a
    fragile cost==0 heuristic.

R7. :cost detail sort needs 3-level deterministic key:
    (cost desc, model asc, category asc) — table.sort is unstable.

R8. call_broker fallback passes opts.include_usage unchanged.
    Documented as known assumption (B1 confirms both backends
    accept; future-broken fallback can pass include_usage=false).

R9. :resume does NOT restore historical usage_totals. Per-turn usage
    IS in session JSONL for scripting; cross-session aggregation is
    Q-C2 deferred. Documented in §8.

R10. $%.4f loses sub-cent precision (cloud cost 0.000028 -> $0.0000).
     Widened to $%.6f in §6 + §7 warn message format.

NITs (APPLIED):

N1. §4 pseudocode comment notes `if doc.usage` branch is independent
    of choice branch (handles both B2 emission shapes).
N2. §2 stale "B7" reference corrected to B3.
N3. §13 commit 3 row gains explicit dependency note on commit 1's R1.
N4. §13 commit 4 spells out llm_probe -> llm_second_opinion ->
    M.is_destructive signature chain widening.
N5. §3 + §13 commit 6 — PHASE0 §11 amendment already in tree
    (3bad07b); commit 6 must NOT re-apply.

PHASE7.md now 803 lines (was 528 after plan). +275/-57. Ready for
implementation phase pending user gate.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-16 22:55:59 +00:00

aish

aish — AI-augmented conversational shell.

A single REPL that interleaves shell command execution and language-model conversation, backed by a llama.cpp HTTP broker. Implementation is LuaJIT 2.x with FFI bindings to libcurl, GNU readline, and libc — no C extensions, no build step, one source tree.

Why

Three flows that currently live in three windows fold into one:

  1. "Run this command and show me the output" — fast feedback loop, no copy-paste between terminal and chat.
  2. "Explain or write code based on the output we just looked at" — exec output is automatically injected into the model's context.
  3. "Plan and execute a multi-step task with confirmation gates" — landing in Phase 3 as Chuck Norris autonomous mode.

aish is not a wrapper around bash. It's a first-class interactive environment where the shell is one of several execution channels.

Status

Component State
Repository skeleton in this commit
Phase 0 manifest docs/PHASE0.md — locked
Phase 0 implementation 🔜 next session
Phase 1+ 📋 enumerated in PHASE0.md §11

Every module file currently raises not implemented (Phase 0 pending) when called. luajit main.lua fails loudly at the first un-implemented function, never silently.

Quick orientation

Read this If you want to know
docs/PHASE0.md §12 What aish is and what Phase 0 ships
docs/PHASE0.md §3 Technology decisions (LuaJIT, FFI, readline, libcurl, llama.cpp)
docs/PHASE0.md §4 Directory layout — these file names are stable across all phases
docs/PHASE0.md §5 How input is dispatched (meta / shell / AI)
docs/PHASE0.md §6 Broker contract: /v1/chat/completions, CMD: extraction
docs/PHASE0.md §10 Config schema and resolution order
docs/PHASE0.md §11 Phase sequence (what lands when)
docs/PHASE0.md §13 Open questions, tracked per phase
CLAUDE.md Project conventions for AI-assisted contributors

Directory layout

aish/
├── main.lua              # entry point
├── repl.lua              # readline loop, dispatch, prompt
├── broker.lua            # llama.cpp HTTP client
├── router.lua            # input classifier (meta/shell/AI)
├── executor.lua          # command exec + CMD: extraction
├── context.lua           # in-memory turn history
├── history.lua           # disk persistence (Phase 1+)
├── safety.lua            # destructive-op gate (Phase 3+)
├── renderer.lua          # output formatting
├── config.lua            # default model registry + preferences
├── ffi/
│   ├── curl.lua          # libcurl easy interface
│   ├── readline.lua      # GNU readline
│   ├── pty.lua           # forkpty (Phase 1+)
│   └── libc.lua          # chdir, errno, strerror
└── docs/
    └── PHASE0.md         # locked substrate

Build / runtime dependencies

System packages (Debian / ALARM / Arch names):

  • luajit (>= 2.0)
  • libcurl4 / libcurl-openssl-3 runtime
  • libreadline8 runtime
  • libc6 runtime (always present)

No compilation, no luarocks, no make. Just luajit main.lua.

Running

Once Phase 0 ships:

luajit main.lua                          # uses ~/.config/aish/config.lua
luajit main.lua --config ./config.lua    # explicit config path
AISH_CONFIG=/path/to/config.lua luajit main.lua

Config resolution order is documented in docs/PHASE0.md §10.

Configuration

config.lua is a Lua file returning a single table. The committed config.lua in this repo is both the canonical example and the development-fallback config (lowest precedence). Copy it to ~/.config/aish/config.lua and edit endpoints to your local llama.cpp servers, or point AISH_CONFIG at your own.

The default endpoints assume mfritsche's home network:

  • fastdirac.fritz.box:8081 (Qwen2.5-Coder-7B q4 8k ctx)
  • deepdirac.fritz.box:8080 (Qwen2.5-Coder-7B q4 32k ctx)
  • cloudhossenfelder.fritz.box:8082 (forwards to OpenRouter)

Replace these with your own llama.cpp endpoints if you're not on that LAN.

License

Not yet selected. Default-private until decided.

Project conventions

See CLAUDE.md for contribution conventions, commit style, and the phase-loop discipline this project follows.

S
Description
AI-augmented conversational shell — LuaJIT REPL with llama.cpp broker, shell executor, and routed AI inference.
Readme MIT 2.2 MiB
Languages
Lua 99.8%
Shell 0.2%