Skip to content

Commit c19818d

Browse files
authored
Merge pull request #15 from awwaiid/clean-up
Clean up code, add formatter and clippy check
2 parents d95a242 + ff60dda commit c19818d

17 files changed

Lines changed: 427 additions & 313 deletions

.github/workflows/quality.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Code Quality
2+
3+
on:
4+
push:
5+
branches: [ main, clean-up ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
format:
11+
name: Check Formatting
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
- uses: dtolnay/rust-toolchain@stable
16+
with:
17+
components: rustfmt
18+
- name: Check formatting
19+
run: cargo fmt -- --check
20+
21+
lint:
22+
name: Clippy Linting
23+
runs-on: ubuntu-latest
24+
steps:
25+
- uses: actions/checkout@v4
26+
- uses: dtolnay/rust-toolchain@stable
27+
with:
28+
components: clippy
29+
- name: Run clippy
30+
run: cargo clippy -- -D warnings
31+
32+
check:
33+
name: Check Compilation
34+
runs-on: ubuntu-latest
35+
steps:
36+
- uses: actions/checkout@v4
37+
- uses: dtolnay/rust-toolchain@stable
38+
- name: Check code compiles
39+
run: cargo check --all-targets --all-features

.rustfmt.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
max_width = 160
2+
hard_tabs = false
3+
tab_spaces = 4
4+
newline_style = "Unix"
5+
use_small_heuristics = "Default"
6+
reorder_imports = true
7+
reorder_modules = true
8+
remove_nested_parens = true
9+
fn_params_layout = "Tall"
10+
merge_derives = true
11+
use_try_shorthand = false
12+
use_field_init_shorthand = false
13+
force_explicit_abi = true
14+
edition = "2021"

AGENTS.md

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
# AGENTS.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) and other similar tools when working with code in this repository.
4+
5+
## Project Overview
6+
7+
Ghostwriter is a Vision-LLM agent for the reMarkable tablet that watches handwritten input and responds by drawing or typing back to the screen. It takes screenshots, sends them to LLM APIs (OpenAI, Anthropic, Google), and uses the responses to interact with the device through simulated pen and keyboard input.
8+
9+
## Core Architecture
10+
11+
- **main.rs**: Main application entry point with CLI argument parsing and orchestration
12+
- **LLM Engine Layer** (`src/llm_engine/`): Pluggable backends for different AI providers
13+
- `openai.rs`: OpenAI API integration (GPT models)
14+
- `anthropic.rs`: Anthropic API integration (Claude models)
15+
- `google.rs`: Google API integration (Gemini models)
16+
- `mod.rs`: Common LLM engine trait and interface
17+
- **Device Interaction** (`src/`):
18+
- `screenshot.rs`: Screen capture functionality for both reMarkable2 and Paper Pro
19+
- `pen.rs`: SVG drawing and bitmap rendering to screen
20+
- `keyboard.rs`: Virtual keyboard input via uinput
21+
- `touch.rs`: Touch event detection and gesture recognition
22+
- **Image Processing**:
23+
- `segmenter.rs`: Image segmentation to provide spatial context to LLMs
24+
- `util.rs`: SVG to bitmap conversion and other utilities
25+
- **Configuration**:
26+
- `prompts/`: JSON-based prompt templates and tool definitions
27+
- `embedded_assets.rs`: Bundled configuration files
28+
29+
## Common Development Commands
30+
31+
### Building
32+
```bash
33+
# Local development build
34+
cargo build --release
35+
# or
36+
./build.sh local
37+
38+
# Cross-compile for reMarkable2 (armv7)
39+
cross build --release --target=armv7-unknown-linux-gnueabihf
40+
# or
41+
./build.sh
42+
43+
# Cross-compile for reMarkable Paper Pro (aarch64)
44+
cross build --release --target=aarch64-unknown-linux-gnu
45+
# or
46+
./build.sh rmpp
47+
```
48+
49+
### Code Quality and Formatting
50+
```bash
51+
# Format code with rustfmt
52+
cargo fmt
53+
54+
# Check formatting without applying changes
55+
cargo fmt -- --check
56+
57+
# Run clippy linting
58+
cargo clippy
59+
60+
# Run clippy with stricter warnings
61+
cargo clippy -- -D warnings
62+
63+
# Check code compiles
64+
cargo check --all-targets --all-features
65+
```
66+
67+
### Testing and Evaluation
68+
```bash
69+
# Run evaluation suite across multiple models and configurations
70+
./run_eval.sh
71+
72+
# Test with local input file (no device required)
73+
./target/release/ghostwriter \
74+
--input-png evaluations/test_case/input.png \
75+
--output-file tmp/result.out \
76+
--save-bitmap tmp/result.png \
77+
--no-draw --no-loop --no-trigger
78+
79+
# Run with specific model and options
80+
./ghostwriter --model gpt-4o-mini --apply-segmentation --thinking
81+
```
82+
83+
### Deployment
84+
```bash
85+
# Deploy to reMarkable (replace IP address)
86+
scp target/armv7-unknown-linux-gnueabihf/release/ghostwriter root@192.168.1.117:
87+
# or for Paper Pro
88+
scp target/aarch64-unknown-linux-gnu/release/ghostwriter root@192.168.1.117:
89+
```
90+
91+
## Key Development Notes
92+
93+
### Cross-compilation Setup Required
94+
- Install `cross`: `cargo install cross --git https://github.com/cross-rs/cross`
95+
- Add targets: `rustup target add armv7-unknown-linux-gnueabihf aarch64-unknown-linux-gnu`
96+
- Docker required for cross-compilation
97+
98+
### Device-Specific Considerations
99+
- reMarkable2 uses armv7 architecture, Paper Pro uses aarch64
100+
- Paper Pro requires uinput kernel module to be loaded (handled automatically)
101+
- Screen resolutions and input handling differ between devices
102+
- Virtual display size is normalized to 768x1024 pixels
103+
104+
### Environment Variables
105+
Set API keys for different LLM providers:
106+
```bash
107+
export OPENAI_API_KEY=your-key-here
108+
export ANTHROPIC_API_KEY=your-key-here
109+
export GOOGLE_API_KEY=your-key-here
110+
```
111+
112+
### Prompt System
113+
- Prompts are defined in `prompts/` directory as JSON files
114+
- Tools (draw_text, draw_svg) are defined separately and referenced by prompts
115+
- Runtime prompt overrides supported by copying files to device
116+
- Default prompt is `general.json`
117+
118+
### Testing and Evaluation Framework
119+
- `evaluations/` contains test scenarios with input images
120+
- `run_eval.sh` runs systematic evaluations across models and configurations
121+
- Results include merged images showing original input + AI output in red
122+
- Supports segmentation analysis for improved spatial awareness
123+
124+
### reMarkable Integration
125+
- Touch trigger in upper-right corner activates the assistant
126+
- Progress indication through keyboard text and screen taps
127+
- Supports both SVG drawing (via pen simulation) and text output (via virtual keyboard)
128+
- Background execution supported with `nohup ./ghostwriter &`

CLAUDE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
AGENTS.md

0 commit comments

Comments
 (0)