liagent 0.0.0-stage → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/DEVICES.md ADDED
@@ -0,0 +1,169 @@
1
+ # Devices: ask the deck from anything
2
+
3
+ A modded calculator, an Arduino with a 16×2 LCD, an ESP32, a LoRa radio a few km away, an old phone over SMS,
4
+ a smart-home hub: if it can send a line of text, it can get an answer.
5
+
6
+ Set them up with **`/devices`** in the chat. They run while liagent serves: `/web`, `liagent --serve` or
7
+ `liagent --service`.
8
+
9
+ | Link | Good for | Range |
10
+ |---|---|---|
11
+ | **HTTP** `GET /ask` | ESP32 / ESP8266 inside a calculator, anything with Wi-Fi | your Wi-Fi (Tailscale: anywhere) |
12
+ | **Serial** (USB, Pi UART, Bluetooth) | calculator through an Arduino, Arduino + LCD, Meshtastic node | a cable / ~10 m |
13
+ | **LoRa** RYLR998 / RYLR896 | a pocket device far from the deck, no internet | 1–5 km in town, more in line of sight |
14
+ | **SMS** via a GSM modem | any phone, even a push-button one | anywhere with mobile coverage |
15
+ | **TCP** `nc deck 8767` | retro computers, quick tests | your network |
16
+ | **MQTT** | Home Assistant, Node-RED, IoT boards | wherever the broker is |
17
+
18
+ **How answers are fitted to the device**
19
+ - Plain text without markdown.
20
+ - Wrapped to the screen width (`width`).
21
+ - Transliterated to Latin letters when the screen can't show anything else (`ascii`).
22
+ - Cut to a length (`limit`).
23
+
24
+ The model is told that the question comes from a small device, so it answers briefly.
25
+
26
+ **Safety.** Devices get read-only answers by default: questions, status, files. They can't run commands. If you
27
+ turn on *Let devices run actions* in `/devices`, every action still asks first: on the device itself
28
+ (`ALLOW? … (y/a/n)`) over serial and TCP, and in the web UI or Discord for the other links. Each device keeps its
29
+ own short conversation, apart from your chat.
30
+
31
+ ---
32
+
33
+ ## HTTP: ESP32, ESP8266, anything with Wi-Fi
34
+ `/devices` → *Show the device key and examples* prints the key.
35
+
36
+ ```
37
+ GET http://<deck>:8765/ask?k=<key>&q=<question>&w=16&a=1&n=200
38
+ ```
39
+ - `w`: screen width
40
+ - `a=1`: Latin letters only
41
+ - `n`: maximum characters
42
+
43
+ The answer comes back as plain text. You can also `POST` the question as the body, with the key in
44
+ `X-Liagent-Key`.
45
+
46
+ ```cpp
47
+ // ESP32 (Arduino core): ask and print the answer
48
+ #include <WiFi.h>
49
+ #include <HTTPClient.h>
50
+
51
+ String ask(const String& q) {
52
+ HTTPClient http;
53
+ String url = "http://192.168.1.20:8765/ask?k=YOUR_KEY&w=16&a=1&q=";
54
+ for (char c : q) { if (isalnum(c)) url += c; else { char b[4]; sprintf(b, "%%%02X", (uint8_t)c); url += b; } }
55
+ http.begin(url);
56
+ http.setTimeout(120000); // the model may take a while
57
+ String answer = http.GET() == 200 ? http.getString() : "error";
58
+ http.end();
59
+ return answer;
60
+ }
61
+
62
+ void setup() {
63
+ Serial.begin(115200);
64
+ WiFi.begin("ssid", "password");
65
+ while (WiFi.status() != WL_CONNECTED) delay(200);
66
+ Serial.println(ask("2+2*3?"));
67
+ }
68
+ void loop() {}
69
+ ```
70
+
71
+ ## Serial: calculators, Arduino, Bluetooth, Meshtastic
72
+ **Protocol.** Send one question per line. The deck answers in lines and ends with a line holding just `.`
73
+ (set another marker or none in `/devices`). Send `stop` to stop an answer. If actions are allowed, the deck may
74
+ send `ALLOW? <what> (y/a/n)`; answer with one letter.
75
+
76
+ **Wiring to the Pi's UART**
77
+ - Connect GPIO14 (TX, pin 8) to the device's RX, GPIO15 (RX, pin 10) to its TX, and GND to GND.
78
+ - In `sudo raspi-config` → Interface → Serial: turn the login shell off and the hardware port on. The port is
79
+ then `/dev/serial0`.
80
+ - **The Pi is 3.3 V.** A 5 V Arduino's TX needs a voltage divider (1 kΩ + 2 kΩ) before the Pi's RX.
81
+
82
+ A USB cable is simpler: the device shows up as `/dev/ttyUSB0` or `/dev/ttyACM0`.
83
+
84
+ **Calculators.** Most graphing calculators have no plain serial port. The usual mod puts a microcontroller
85
+ between the two: an Arduino on the TI link port, or an ESP32 inside the case. That board talks to the calculator
86
+ on one side and sends text lines to the deck over USB serial (or over HTTP, above) on the other. Set the width
87
+ to the calculator's screen: 16 characters on a TI-83/84, about 21 on a Casio fx-9860.
88
+
89
+ ```cpp
90
+ // Arduino: type on Serial (or read a keypad), show the answer on a 16x2 I2C LCD
91
+ #include <LiquidCrystal_I2C.h>
92
+ LiquidCrystal_I2C lcd(0x27, 16, 2);
93
+
94
+ void setup() { Serial.begin(9600); lcd.init(); lcd.backlight(); }
95
+
96
+ void loop() {
97
+ static String q;
98
+ // your input here: a keypad, buttons, or the calculator link
99
+ if (q.length()) { Serial.println(q); q = ""; lcd.clear(); }
100
+ while (Serial.available()) {
101
+ String line = Serial.readStringUntil('\n'); line.trim();
102
+ if (line == ".") break; // end of the answer
103
+ lcd.clear(); lcd.print(line.substring(0, 16));
104
+ lcd.setCursor(0, 1); lcd.print(line.substring(16, 32));
105
+ delay(1500); // scroll line by line
106
+ }
107
+ }
108
+ ```
109
+ Choose *width 16*, *Latin letters only* and baud 9600 in `/devices`.
110
+
111
+ **Bluetooth (phone or gadget with Bluetooth serial).** Pair the device first, then run
112
+ `sudo rfcomm watch hci0` on the deck. `/dev/rfcomm0` appears; add it in `/devices`. On Android, an app such as
113
+ *Serial Bluetooth Terminal* is enough to chat.
114
+
115
+ **Meshtastic.** On the node, enable the *Serial* module in *TEXTMSG* mode, then connect the node to the deck
116
+ over USB or UART. Add it as a serial device at the baud you set in the module. Messages from the mesh channel
117
+ reach the deck, and the answers go back to the channel. The channel's key (PSK) decides who can ask.
118
+
119
+ ## LoRa: RYLR998 / RYLR896 (km, no internet)
120
+ **On the deck**
121
+ - Wiring: module VDD to 3.3 V, TXD to the Pi's RX, RXD to the Pi's TX, GND to GND.
122
+ - In `/devices`: *LoRa module*, baud **115200**.
123
+ - Set the allowed addresses and a PIN. Radio is open to anyone in range.
124
+
125
+ **On both modules (once, over serial)**
126
+ ```
127
+ AT+NETWORKID=5 same on both
128
+ AT+ADDRESS=1 deck = 1, pocket device = 2
129
+ AT+BAND=868000000 868 MHz in Europe/Russia, 915000000 in the Americas
130
+ ```
131
+
132
+ **Asking from the pocket device**
133
+ ```
134
+ AT+SEND=1,15,1234 how hot?
135
+ ```
136
+ Here `1` is the deck's address, `15` is the message length in bytes, and `1234` is the PIN. The answer arrives
137
+ as `+RCV=1,…,<text>,…`, in parts of up to 200 characters.
138
+
139
+ Range depends on antennas and terrain: roughly 1–5 km between buildings, much more in line of sight.
140
+
141
+ ## SMS: GSM modem (SIM800L, SIM7600, USB LTE stick)
142
+ - **Power.** A SIM800L needs 3.7–4.2 V with 2 A peaks: a LiPo cell or a buck converter. The Pi's 3.3 V pin
143
+ can't supply that.
144
+ - **Wiring.** TX/RX/GND to the Pi's UART (as above), or USB for an LTE stick.
145
+ - **Setup.** In `/devices` choose *GSM modem*, baud 115200 (SIM800 also auto-detects 9600). List the phone
146
+ numbers allowed to ask; other numbers are ignored.
147
+
148
+ Answers are SMS in Latin letters, up to 3 messages. Your operator's SMS prices apply.
149
+
150
+ ## TCP
151
+ ```
152
+ $ nc 192.168.1.20 8767
153
+ liagent: send the device key
154
+ <key>
155
+ ok, ask away
156
+ what's the CPU temperature?
157
+ 48 C, normal.
158
+ .
159
+ ```
160
+
161
+ ## MQTT
162
+ In `/devices` choose *MQTT broker*: `mqtt://user:pass@host:1883`, or `mqtts://…` for TLS. Pick an unguessable
163
+ topic, because anyone who can publish to it can ask.
164
+
165
+ ```
166
+ mosquitto_sub -h host -t 'liagent/ab12cd/answer' &
167
+ mosquitto_pub -h host -t 'liagent/ab12cd/ask' -m 'is the garage door sensor online?'
168
+ mosquitto_pub -h host -t 'liagent/ab12cd/ask' -m '{"q": "temp?", "width": 16, "ascii": true, "reply_to": "lcd/1"}'
169
+ ```
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Kuloka
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,96 @@
1
- # Temporary Holding Version
1
+ <p align="center"><img src="banner.svg" alt="liagent — terminal AI agent for Raspberry Pi cyberdecks" width="100%"></p>
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ # liagent
4
+
5
+ Terminal AI agent for Raspberry Pi cyberdecks. Runs on **every Pi** (Zero … 5, 32/64-bit) with Raspberry Pi OS, Kali or any Debian: one Python file,
6
+ two pure-Python dependencies, ~23 MB installed, ~40 MB RAM. Also runs on Windows for testing.
7
+
8
+ **Does:** shell commands (each one behind a yes / always / no menu) · files with diffs and `/undo` · system
9
+ status · opens apps, files and URLs · GPIO · Wi-Fi · voice in and out · remembers facts about your deck ·
10
+ saves every command it runs into a cheatsheet and quizzes you on it · a web UI for your phone and a Discord bot.
11
+
12
+ **Brain:** any OpenAI-compatible provider: Groq (default, free key), Cerebras, Gemini, OpenRouter, Mistral,
13
+ OpenAI, DeepSeek, a custom URL, or Ollama offline.
14
+
15
+ ## Install
16
+ - **Raspberry Pi:**
17
+ ```bash
18
+ wget https://github.com/Kuloka/liagent/releases/latest/download/liagent_all.deb
19
+ sudo apt install ./liagent_all.deb && liagent --key && liagent
20
+ ```
21
+ Details, Kali notes and troubleshooting: **[PI.md](PI.md)**
22
+ - **Anywhere with Node.js and Python 3.8+:** `npx liagent` (the first run puts its two Python libraries in a private venv)
23
+ - **Windows:** `powershell -ExecutionPolicy Bypass -File install.ps1`, then in a new terminal `liagent --key`, `liagent`
24
+
25
+ ## Commands
26
+ Type `/` for the menu. Ctrl+C stops a reply, Ctrl+D quits.
27
+
28
+ | | |
29
+ |---|---|
30
+ | `/model` `/provider` `/key` | pick a model (folders + search) · switch provider and key |
31
+ | `/talk` (ctrl+space, F2) `/speak` | voice input · read replies aloud (offline) |
32
+ | `/hud` `/status` `/wifi` | live dashboard · status snapshot · scan and connect |
33
+ | `/memory` `/learn` `/undo` | remembered facts · cheatsheet and quiz · undo the last file change *or shell command* |
34
+ | `/reflexes` `/mesh` `/wiring` | if-then rules · your other decks · photo check before GPIO (below) |
35
+ | `/devices` | calculators, Arduino / ESP32, LoRa, SMS, MQTT can ask the deck ([DEVICES.md](DEVICES.md)) |
36
+ | `/theme` `/icons` `/fx` `/rain` | colors · language icons (emoji / Nerd Font / tags) · animations · screensaver |
37
+ | `/web` `/discord` | control the deck from your phone or from Discord (below) |
38
+ | `/clear` `/yolo` `/exit` | new chat · run without asking (careful) · quit |
39
+
40
+ ## What makes it different
41
+ - **Undo for shell commands.** Before a command that changes things (`apt`, `rm`, `mv`, `systemctl`, `>` …) it
42
+ copies the files the command names (up to 50 MB) and notes installed packages and service states. `/undo`
43
+ puts them back: files from the copies, packages with `apt-get`, services with `systemctl`.
44
+ - **Reflexes.** Say "if the CPU goes over 75 °C, tell me on Discord" or "when the button on GPIO27 is pressed,
45
+ say the time". The model turns it into a rule once. After that a small local loop checks it, with no model
46
+ calls and no internet. Triggers: temperature, CPU, battery, disk, a GPIO button, Wi-Fi lost or back, a daily
47
+ time, every N minutes. Actions: notify (terminal, web, Discord DM), speak, shell, GPIO, or a request to the agent.
48
+ - **Your phone is the deck's camera.** "Look at my breadboard": the web UI shows a *take photo* button (or the
49
+ bot asks for a photo in Discord), and the model sees it. A Pi camera works too (`rpicam-still`). You need a
50
+ model that can see images, e.g. `meta-llama/llama-4-scout-17b-16e-instruct` on Groq or any Gemini.
51
+ - **Wiring check before GPIO.** Before it first drives a pin, it asks for a photo of the breadboard and checks the
52
+ LED polarity, the resistor and the GND wire. If the wiring is wrong it won't switch the pin on. `/wiring` turns
53
+ this off.
54
+ - **Ask from anything.** A modded calculator, an Arduino with an LCD, an ESP32, a LoRa radio a few km away, a
55
+ push-button phone over SMS, Home Assistant over MQTT. The answer is fitted to the device's screen: short plain
56
+ text, wrapped, transliterated to Latin if needed. Wiring and sketches: [DEVICES.md](DEVICES.md).
57
+ - **Deck mesh.** Decks with the same key (`/mesh`) find each other on the network, and you can say "ask the
58
+ garage deck how hot it is". A deck answers others with read-only tools only, unless you turn on trust.
59
+
60
+ ## Remote: phone and Discord
61
+ Pure standard library, no extra packages. Same agent, same permission questions, now with buttons.
62
+
63
+ - **Web UI:** `liagent --web` (or `/web`) prints a link like `http://192.168.1.20:8765/?t=…` and a QR code.
64
+ Scan it with a phone on the same Wi-Fi to get a plain monospace chat with a one-line status bar (cpu, temp,
65
+ ram, net). Type `/` for the command menu, use ↑ for history, answer permission questions with `y` / `a` / `n`,
66
+ and press Esc to stop a reply. The `?t=` part is a secret, so don't share the link.
67
+ - **Remote commands** (web and Discord): `/status` `/models` `/model <name>` `/memory` `/learn` `/undo`
68
+ `/yolo` `/reflexes` `/clear`.
69
+ - **Discord bot:** `liagent --discord` (or `/discord`). The first run asks for a bot token
70
+ (discord.com/developers → New Application → Bot → Reset Token) and prints an invite link. Add the bot to your
71
+ server, then DM it the 6-digit pairing code shown on the deck. After that it answers your DMs and your
72
+ @mentions, and ignores everyone else. Say `stop` to stop a reply.
73
+ - **Both, always on:** `liagent --serve` runs both without the terminal chat, and `liagent --service` installs it
74
+ as a systemd user service that starts at boot.
75
+ - Remote users can't type the sudo password. It's only entered on the deck.
76
+
77
+ ## How far away does it work?
78
+ | Way | Range | What you need |
79
+ |---|---|---|
80
+ | Web UI over Wi-Fi | your home network: ~20–50 m indoors, up to ~100 m outside | nothing extra |
81
+ | Discord | anywhere both have internet | the deck online (home Wi-Fi, phone hotspot or a USB LTE modem) |
82
+ | Web UI over [Tailscale](https://tailscale.com) | anywhere both have internet | Tailscale on the deck and the phone (free): `curl -fsSL https://tailscale.com/install.sh \| sh && sudo tailscale up`, then open `http://<deck's 100.x address>:8765/?t=…` |
83
+ | LoRa radio (RYLR998) | 1–5 km in town, more in line of sight, **no internet** | two modules, see [DEVICES.md](DEVICES.md) |
84
+ | SMS via a GSM modem | anywhere with mobile coverage | a SIM800L / LTE stick on the deck |
85
+ | Deck mesh across places | anywhere, over Tailscale | `/mesh` → *Add a deck by address* with the 100.x address (broadcast discovery only works on one network) |
86
+
87
+ A few km from home, take Discord or Tailscale. The deck needs internet where it is: home Wi-Fi if it stays
88
+ home, or your phone's hotspot if you carry it. Don't open the web UI port on your router: it's plain HTTP.
89
+ Tailscale encrypts the connection for you.
90
+
91
+ ## Notes
92
+ - Keys live in `~/.config/deck-agent/config.json` (Pi) or `%APPDATA%\deck-agent\config.json` (Windows), never in git.
93
+ - Voice input: `arecord` + Whisper on Groq (needs a Groq key). Voice output: Piper on 64-bit, `espeak-ng` otherwise.
94
+ No mic? `/talk samples/en_cpu_temp.wav`.
95
+ - GPIO uses BCM numbering (GPIO17 = pin 11), 3.3 V. Use a 220–330 Ω resistor for LEDs.
96
+ - Offline: `curl -fsSL https://ollama.com/install.sh | sh && ollama pull qwen2.5:3b`, then `/provider` → ollama.