Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
target/
.claude/
50 changes: 40 additions & 10 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,45 @@ behavior must stay output-compatible with it unless a deliberate difference is d

## Layout

- `src/bin/sidepulse-hook.rs` is the hook entry point. It must always exit 0 and print nothing.
- `src/hook.rs` handles payload formatting, routing and the main flow (`hook.py`).
- `src/origin.rs` detects which app launched the agent (`origin.py`), using native process
This is a Cargo workspace. `crates/sidepulse-core` holds the shared logic, `crates/sidepulse-hook`
the per-event hook binary, and `crates/sidepulse-bar` the AppKit menu-bar app. Keep AppKit out of
core and the hook, so the hook stays small and fast to start.

Core modules (`crates/sidepulse-core/src/`):

- `crates/sidepulse-hook/src/main.rs` is the hook entry point. It must always exit 0 and print nothing.
- `hook.rs` handles payload formatting, routing and the main flow (`hook.py`).
- `origin.rs` detects which app launched the agent (`origin.py`), using native process
ancestry with no subprocesses.
- `src/providers.rs` holds event names, payload normalization and log-path detection (`providers.py`).
- `src/collector.rs` holds the per-event status rules (the matching parts of `collector.py`).
- `src/audit.rs`, `src/logrot.rs` and `src/ipc.rs` port the audit record, rotating JSONL appends
- `providers.rs` holds event names, payload normalization and log-path detection (`providers.py`).
- `collector.rs` holds the per-event status rules (the matching parts of `collector.py`).
- `audit.rs`, `logrot.rs` and `ipc.rs` port the audit record, rotating JSONL appends
and the event-socket client.
- `src/pyjson.rs` reproduces Python's JSON and string semantics so records match byte for byte.
- `scripts/parity.py` is the differential harness against the Python hook.
- `pyjson.rs` reproduces Python's JSON and string semantics so records match byte for byte.
- `monitor.rs` holds the live agent state: ingest, snapshot, aggregate and a bounded `latest.json`.
- `devices.rs`, `battery.rs`, `lid.rs` and `power.rs` handle LED programs and writes, battery and
lid reads, and keep-awake and keepalive, all native with no subprocesses.

Bar modules (`crates/sidepulse-bar/src/`):

- `app.rs` holds the main-thread state and refresh logic.
- `ui.rs` covers the status item and menu.
- `led.rs` is the LED worker thread.
- `server.rs` is the event socket.
- `session.rs` handles session rows and open actions.
- `settings.rs` reads and writes `settings.json` and keeps keys this port doesn't use.

`scripts/parity.py` is the differential harness against the Python hook.

## Efficiency rules

- Don't add polling where a notification or event exists. Every timer needs a reason and a
tolerance.
- Don't spawn subprocesses on hot or periodic paths. Use IOKit, IOPM or libc.
- Keep state bounded, and debounce writes to disk.
- Never do I/O to the SD card on the main thread.
- Measure the RSS/footprint and CPU of a release build before and after any change that claims a
performance gain, and update the README tables.

## Commands

Expand Down Expand Up @@ -47,7 +76,8 @@ All four must pass before a commit. CI (`.github/workflows/ci.yml`) runs them on
the PR.
5. **Privacy.** Hook payloads contain prompts, file paths and tool output. Never commit real hook
logs, corpora, parity output or screenshots of them. Tests use synthetic data only.
6. **Unsafe code** is allowed only for libc system calls. Each block needs a `// SAFETY:` comment
explaining why the call is sound.
6. **Unsafe code** is allowed only for system interfaces: libc, IOKit, CoreFoundation and IOPM FFI
(`crates/sidepulse-core/src/power/iokit.rs`), and objc2/AppKit calls in `sidepulse-bar`. Each
block needs a `// SAFETY:` comment explaining why the call is sound.
7. **Scope.** Keep changes small and focused, and follow the phase plan in the README. Update the
README's tables and commands whenever behavior, performance claims or setup steps change.
201 changes: 199 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 7 additions & 17 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,32 +1,22 @@
[package]
name = "sidepulse"
version = "0.1.0"
[workspace]
resolver = "2"
members = ["crates/sidepulse-core", "crates/sidepulse-hook", "crates/sidepulse-bar"]

[workspace.package]
version = "0.2.0"
edition = "2021"
rust-version = "1.85"
description = "Unofficial native (Rust) port of SidePulse agent-status components, starting with the agent hook."
license = "MIT"
repository = "https://github.com/ckorhonen/sidepulse-rust"
readme = "README.md"
keywords = ["sidepulse", "claude-code", "codex", "hooks", "macos"]
publish = false

[lib]
name = "sidepulse"
path = "src/lib.rs"

[[bin]]
name = "sidepulse-hook"
path = "src/bin/sidepulse-hook.rs"

[dependencies]
[workspace.dependencies]
chrono = { version = "0.4", default-features = false, features = ["clock", "std"] }
libc = "0.2"
regex = "1"
serde_json = { version = "1", features = ["preserve_order"] }
shlex = "1"
socket2 = { version = "0.5", features = ["all"] }

[dev-dependencies]
tempfile = "3"

[profile.release]
Expand Down
Loading
Loading