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: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ credentials.json
browser/.venv/
target/
.claude.md
CLAUDE.md
.mcp.json
.playwright-mcp/
x-post-*.png
Expand Down
34 changes: 28 additions & 6 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,11 @@ stdout and diagnostics go to stderr.

## Layout

- `src/` holds the Rust crate. `src/main.rs` defines the clap CLI. Handlers live in
`src/commands/` and the domain modules beside it (`ax_send.rs`, `safety/`, `context/`,
`local_db.rs`, `geeknews/`, `loco/`).
The codemap, process topology and invariants are in `ARCHITECTURE.md`.

- `scripts/` holds the Python auto-reply runtime: worker, service, supervisor, db-watch,
session-monitor and menubar. Production runs a baked, frozen copy of these files, not
the checkout.
- `tests/` holds Rust integration tests (`*.rs`) and Python `unittest` modules (`test_*.py`).
- `desktop/` is the Tauri desktop app (Vite + TypeScript front end, `src-tauri/` bridge).
- `macos/AutoReplyMenu/` is the legacy Swift menu extra, still built in CI.

## Checks

Expand Down Expand Up @@ -123,3 +119,29 @@ openkakao-cli auto-reply --chat 'bind:417780809780519:부자멘토멘티' --chec
- Conventional Commits (`feat:`, `fix:`, `refactor:`, `test:`, `docs:`, `chore:`).
- `rust-toolchain.toml` pins Rust. Keep new dependencies to a minimum.
- Record point-in-time verification in `docs/engineering-status.md`, not here.
- Releases follow the release steps in `CONTRIBUTING.md`. Never force-move a release tag
(the cause of the v1.1.0 incident). Fix, bump the version, and tag again.

## Docs map

- `STATUS.md`: current state, next steps, blockers. Read first.
- `ARCHITECTURE.md`: codemap, process topology and invariants. Read before cross-module
changes.
- `desktop/DESIGN.md`: Jarvis desktop visual and motion contract. Read before UI changes.
- `CHANGELOG.md`: user-visible changes. Recent entries are written in Korean.
- `CONTRIBUTING.md`: full push checklist (desktop fmt and clippy included) and release steps.
- `docs/engineering-status.md`: dated verification history.
- `docs/auto-reply-launchd-supervision.md`: session monitor, bake and LaunchAgent runbook,
with the current, legacy and non-current status of each runtime script.
- `docs/architecture/`: Archify diagrams (`*.html`) and their JSON sources.

## Session protocol

- Start: read `STATUS.md`, then `git log --oneline -10`. On a feature branch, also read its PR description (`gh pr view`).
- End of any session that changed files:
1. On a feature branch, record progress (done, next, blockers, last verified command) in the PR description with `gh pr edit --body-file`. Do not edit `STATUS.md` there; parallel branches would conflict on it.
2. On the default branch (after a merge), overwrite `STATUS.md` with the current state.
3. Add user-visible changes under `## [Unreleased]` in `CHANGELOG.md`.
4. Update `ARCHITECTURE.md` only when a module, boundary, or invariant changed.
5. Add a rule here only when a future agent would otherwise repeat a mistake. Keep this file under 200 lines.
- Check docs: `python3 ~/.agents/skills/project-onboard/scripts/check_docs.py .`
103 changes: 103 additions & 0 deletions ARCHITECTURE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# ARCHITECTURE

<!-- matklad format: https://matklad.github.io/2021/02/06/ARCHITECTURE.md.html. Only things unlikely to change often. Name files and symbols so they can be searched; avoid deep links. -->

## Bird's-eye view

Alden is a single-user macOS assistant built around the owner's KakaoTalk account.

- `openkakao-cli` is the Rust core. It reads the local KakaoTalk SQLCipher database, sends through macOS Accessibility (AX), and supervises the Python auto-reply runtime.
- The Python runtime under `scripts/` turns incoming rows into reply turns and composes replies with local MLX models by default. A remote runner needs `model.privacy_mode = "remote_explicit"` in `config.toml`.
- Jarvis is the Tauri menu-bar app. It draws the runtime as an animated core and hosts settings, voice, and the GraphRAG conversation map.

Input is the local KakaoTalk database. Output is text typed into the KakaoTalk composer through AX, plus private local indexes such as `context.sqlite3` and `knowledge-graph.sqlite3`.

One auto-reply turn:

```text
KakaoTalk local DB (read-only)
-> scripts/auto-reply-db-watch.py durable, versioned queue envelopes
-> scripts/auto-reply-worker.py reply turn, context, local MLX gateway
-> openkakao-cli local-send AX send, gated by the safety.* config checks
-> confirm_worker_local_delivery the outgoing row is read back from the DB
```

`openkakao-cli auto-reply` (`src/commands/auto_reply/`) runs that loop. It resolves exact rooms and runs one `scripts/auto-reply-supervisor.py` per room until `Ctrl-C`. The supervisor runs db-watch and the worker behind one readiness fence.

Unattended runs wrap that same foreground command:

```text
LaunchAgent com.openkakao.auto-reply.session-monitor
-> openkakao-cli auto-reply-host --tick Kakao-blind; checks the manifest, digest and owner locks
-> /bin/sh <pinned .command> baked by scripts/prepare-auto-reply-session-runtime.py
-> scripts/auto-reply-service.py --mode session watchdog, then guardian
-> caffeinate openkakao-cli auto-reply
```

`src/commands/auto_reply_host.rs` holds `auto-reply-host` (`--status`, `--bake`, `--disable`, `--tick`). The lock chain is `session-monitor.lock`, then `session-watchdog.owner.lock`, then `supervisor.owner.lock`. `docs/auto-reply-launchd-supervision.md` still describes an `open -g -b com.apple.Terminal` launch. The tick code uses `/bin/sh`.

Diagrams for these flows are in `docs/architecture/`. `jarvis-system.html` is the end-to-end map.

## Codemap

Rust crate (`Cargo.toml`, package `openkakao-cli`):

- `src/main.rs`: the clap CLI and dispatch. Handlers live in `src/commands/`, one file or folder per command family.
- `src/lib.rs`: the `openkakao_cli` library shared by the CLI, `tests/*.rs`, and the legacy health binary `src/bin/openkakao-auto-reply-health.rs`.
- `src/auto_reply_runtime.rs`: host helpers that use bin crate types. They stay out of the lib crate.
- `src/local_db.rs`: the KakaoTalk SQLCipher reader. `src/context_sync_replica.rs` makes the APFS clone used for consistent snapshots.
- `src/ax_send.rs`: AX send, delete and read against the KakaoTalk UI.
- `src/safety/`: the automatic-reply send decision (`SafetyGate::evaluate`) and `SendGuard::authorize`, which mints the `SendTicket` (`src/safety/guard.rs`) that `SendPort` sends require.
- `src/commands/local_send.rs`: interactive and worker AX sends. `require_ax_send` and `require_allowed_send_chat` check the `safety.*` config gates. `src/room_catalog.rs` and `src/reply_policy.rs` hold the room catalog guard and outbound reply rules.
- `src/ports/`: traits for every external boundary. `src/fakes/`: seeded, deterministic fakes for them.
- `src/config.rs`: the `~/.config/openkakao/config.toml` model, including the `safety.*` gates.
- `src/context/`: the private SQLite index of chat history, owner style, response timing and reply decisions.
- `src/commands/auto_reply/`: the foreground host and the reply job queue (`queue.rs`).
- `src/geeknews/`: GeekNews posting rules. `src/forward/`: link forwarding and the shared image-acquisition ladder. `src/relay/`: the Telegram desktop to KakaoTalk relay. `src/collector/`: the two-path link collector.
- `src/breaker/`: the emergency breaker. `src/logging/`: the redacted transition journal. `src/reply_receipt.rs`: turn receipts. `src/auto_reply_service.rs`: shared status, log and hook helpers and the legacy LaunchAgent labels. `src/state.rs`: `state.json` with a sibling lock file. `src/message_db.rs`: the local message cache for offline search.
- `src/loco/`, `src/loco_helpers.rs`, `src/rest.rs`, `src/auth.rs`, `src/auth_flow.rs`, `src/credentials.rs`: the LOCO protocol client, the Kakao REST API, and credentials.
- Verification, learning and settings support: `src/durability/`, `src/coverage/`, `src/experiment/`, `src/dataset/`, `src/improve/`, `src/live_sample/`, `src/rag_eval/`, `src/memory/`, `src/model_config/`, `src/profile/`, `src/doctor/`, `src/packaging/`, `src/ui_shell/`.

Python runtime (`scripts/`):

- Reply path: `auto-reply-service.py`, `auto-reply-supervisor.py`, `auto-reply-db-watch.py`, `auto-reply-worker.py`, `auto_reply_transition_journal.py`, `auto_reply_ax_ui.py`, `auto-reply-rerank.py`.
- Operator surfaces: `auto-reply-menubar.py` (the menu-bar backend the desktop app calls) and `auto-reply-tui.py`.
- Unattended host: `auto-reply-session-monitor.py`, `prepare-auto-reply-session-runtime.py`, `auto-reply-schema.json`.
- Local models: `local_mlx_gateway.py` (client-side endpoint and admission contract), `mlx_serve_lifecycle.py` (launches, attests and stops an app-owned server), `local_mlx_model_readiness.py`, `auto_reply_ondevice.py`.
- Retrieval: `auto_reply_knowledge_graph.py`, `auto_reply_reference_search.py`, `auto_reply_reference_store.py`, `rag_eval.py`.
- Jarvis tools: `jarvis_voice.py`, `jarvis_browser_use.py`, `jarvis_browser_runtime.py`, `jarvis_tool_runtime.py`.
- Build and install: `build-*.sh`, `install-*.sh`, `uninstall-*.sh`, `rebake-and-restart.sh`.
- `docs/auto-reply-launchd-supervision.md` marks each script current, legacy or non-current.

Apps and environments:

- `desktop/`: the Tauri v2 app. `desktop/src/` is the Vite, TypeScript and Three.js front end (`main.ts`, `core/` for the animated core, `knowledge/` for the graph view, `tokens.ts`). `desktop/src-tauri/src/python_bridge.rs` runs the bundled Python bytecode, and `resource_layout.rs` fixes the app payload. Python itself is not bundled. `desktop/README.md` holds the resource contract.
- `voice/`: the Python environment and Korean wake-word model (`voice/models/hey_jarvis_ko_ridge.onnx`) for `scripts/jarvis_voice.py`.
- `browser/`: the Python environment for the Jarvis browser-use runtime.
- `macos/AutoReplyMenu/`: the legacy Swift menu extra, still built in CI.
- `examples/launchd/`, `desktop/launchd/`: LaunchAgent plist examples.

Tests (`tests/`): Rust integration tests (`*.rs`) and Python `unittest` modules (`test_*.py`). `tests/auto_reply_hermetic.py` is the guard that keeps tests off the real `HOME`.

## Invariants

- The live KakaoTalk database is opened only with `SQLITE_OPEN_READ_ONLY` (`src/local_db.rs`). Replicas and the stopped-clean queue check also set `PRAGMA query_only`. GraphRAG indexing and `context-sync-local` open only a stable snapshot copy of the database and its WAL and SHM sidecars. An unstable or failed copy fails closed and never falls back to the live file.
- AX `local-send` and `local-delete` run only when `safety.allow_ax_send` is set and the room is in `safety.allowed_send_chats`. LOCO writes run only when `safety.allow_loco_write` is set.
- Every send method on `SendPort` (relay, forward, durability) requires a `SendTicket`, and only `SendGuard::authorize` in `src/safety/` can mint one.
- A worker send counts only after `confirm_worker_local_delivery` (`src/commands/local_send.rs`) finds the outgoing row. Interactive `local-send` has no such confirmation.
- `reply_jobs.ax_mutation_authorized` is written by a trigger in the same statement that enters `sending`, and it cannot be cleared. Recovery never re-sends a job that carries it. Only the supervisor migrates the queue from schema v2 to v3.
- Code that touches the outside world depends on the `src/ports/` traits, so tests assemble a fake, network-free world from `src/fakes/` and the Python fakes in `tests/`.
- `src/auto_reply_runtime.rs` stays in the bin crate.
- Production runs a baked, immutable runtime, not the checkout. A source change is live only after a new bake and install.
- The session monitor is Kakao-blind and never owns AX send. The legacy watch and health LaunchAgents are observation only and never reply owners.
- Knowledge graph nodes keep bounded evidence IDs, not message bodies.

## Boundaries

- KakaoTalk app: reads go through the SQLCipher database file. Writes are AX keystrokes into the composer and AX delete. LOCO is a network write path kept for research behind `safety.allow_loco_write`.
- Kakao REST API: token checks and REST reads (`doctor`, `chats`, `read --rest`, `friends`, `me`).
- Local MLX server: `127.0.0.1:11234/v1`, started by `scripts/mlx_serve_lifecycle.py` or by a foreign runtime the app does not manage. `scripts/local_mlx_gateway.py` is the client contract. A reply that names a model ID other than the requested one is rejected. A reply with no model ID is accepted.
- Rust and Python: subprocesses. The worker calls `openkakao-cli local-send ... --json`, first with `--preflight` and then for the real send, and reads JSON from stdout.
- Tauri and Python: `desktop/src-tauri/src/python_bridge.rs` runs a separately provisioned CPython 3.11 from `~/Library/Application Support/openkakao/runtimes/{menubar,voice}/` against the bundled bytecode.
- launchd: the session monitor LaunchAgent and the Jarvis desktop LaunchAgent.
- Owner config and state: `~/.config/openkakao/config.toml` and `~/Library/Application Support/openkakao/`.
1 change: 1 addition & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@AGENTS.md
29 changes: 29 additions & 0 deletions STATUS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# STATUS

<!-- Overwritten at the end of each agent session. Keep under 40 lines. History lives in git and CHANGELOG.md. -->

Updated: 2026-11-23

## Current state

- `main` is at `3ab3109`, the merge of PR #58 (release 1.9.1, merged 2026-11-16 22:19 KST; `CHANGELOG.md` dates it 2026-11-17). CI and the v1.9.1 release workflow passed on it.
- 1.9.1 allows `beamster/Qwen3.8-Flash-Next-Sushi-2bpw`, sends only with the exact requested model, and fixes the guardian `killpg` `EPERM` crash.
- 1.9.0 was the stability bundle: queue schema v3, send-once recovery, tighter AX gates, and the `src/main.rs` and `src/context/` split.
- Whether 1.9.1 is baked and installed on the host is not recorded in the repo. Treat Python changes as source-only until a bake is verified.
- No open issues.
- 22 draft PRs are open (#27 to #48) from `codex/alden-*` branches, last updated 2026-10-10 to 2026-11-01. None has merged. They predate the 1.9.0 stability work.
- PR #59 (`chore/remove-tracked-junk`) removes one unreferenced screenshot. PR #60 (`docs/agent-docs-unify`) adds this doc set.

## Next

- Decide which of the draft PRs #27 to #48 to rebase onto `main` and which to close.
- Confirm whether the host runs a 1.9.x bake, and record the check in `docs/engineering-status.md`.

## Blockers

- None recorded.

## Last verified

- `python3 ~/.agents/skills/project-onboard/scripts/check_docs.py .` → OK (2026-11-23)
- `gh run list --branch main` → CI success on `3ab3109` (2026-11-16)
Loading