mirror of
https://github.com/wu736139669/hapi.git
synced 2026-08-05 06:24:37 +00:00
* feat(cli,web,hub): migrate Cursor remote sessions to ACP with model/effort pickers Move stream-json remote launcher to legacy path and add ACP launcher with set_config_option model/mode sync, optimistic keepalive on config changes, and shared catalog caching. Web gets dual base/effort Cursor pickers for session and new-session flows; hide composer status bar when Cursor sends no usage_update. Co-authored-by: Cursor <cursoragent@cursor.com> * fix(cli,web,shared): Cursor model picker — ACP wires + CLI sku variants Enrich the web/mobile picker with agent --list-models SKUs grouped under ACP wire bases, fix session-open base highlight, and keep catalog discovery safe while the ACP transport holds the CLI lock. Co-authored-by: Cursor <cursoragent@cursor.com> * fix(cursor-acp): apply ACP default model when web resets to Default Web sends model: null for Default; push session/set_config_option with the ACP default[] wire so Cursor backend matches hub state. Regression tests for setModel(null) and applyModelConfig(null). Co-authored-by: Cursor <cursoragent@cursor.com> * fix(acp): clear stale agent-acp lock when owning process is gone Check lock pid with signal 0; remove orphaned lock dirs after SIGKILL or crash so listCursorModels can run cold probes again. Regression tests for guard and catalog discovery. Co-authored-by: Cursor <cursoragent@cursor.com> * test(cursor): use live pid for ACP lock handler tests Stale-lock cleanup clears dead pids; handler tests must simulate an active lock with the current process pid to avoid cold probes/timeouts. Co-authored-by: Cursor <cursoragent@cursor.com> * fix(acp): scope agent CLI lock guard to Cursor agent command only Gemini/OpenCode/Kimi ACP sessions must not register agent-acp-active; that blocked listCursorModels while unrelated backends were running. Co-authored-by: Cursor <cursoragent@cursor.com> * fix(hub,web): reject Cursor model changes for local sessions Hub returns 409 when controlledByUser is set, matching Codex. Web hides model and variant pickers for local Cursor sessions so users do not hit a dead RPC path. Document pre-push-review in AGENTS.md. Verified: bun typecheck; bun run test (919 cli + 243 hub + 768 web + 46 shared). Co-authored-by: Cursor <cursoragent@cursor.com> * fix(web): send stable ids for Cursor ask_question replies Parse and submit question.id and option.id so ACP receives keys like { approach: ['a'] } instead of index/label. Verified: bun typecheck && bun run test. Co-authored-by: Cursor <cursoragent@cursor.com> --------- Co-authored-by: Cursor <cursoragent@cursor.com>
6.3 KiB
6.3 KiB
AGENTS.md
Work style: telegraph; noun-phrases ok; drop grammar;
Short guide for AI agents in this repo. Prefer progressive loading: start with the root README, then package READMEs as needed.
What is HAPI?
Local-first platform for running AI coding agents (Claude Code, Codex, Gemini) with remote control via web/phone. CLI wraps agents and connects to hub; hub serves web app and handles real-time sync.
Repo layout
cli/ - CLI binary, agent wrappers, runner daemon
hub/ - HTTP API + Socket.IO + SSE + Telegram bot
web/ - React PWA for remote control
shared/ - Common types, schemas, utilities
docs/ - VitePress documentation site
website/ - Marketing site
Bun workspaces; shared consumed by cli, hub, web.
Architecture overview
┌─────────┐ Socket.IO ┌─────────┐ SSE/REST ┌─────────┐
│ CLI │ ──────────── │ Hub │ ──────────── │ Web │
│ (agent) │ │ (server)│ │ (PWA) │
└─────────┘ └─────────┘ └─────────┘
│ │ │
├─ Wraps Claude/Codex ├─ SQLite persistence ├─ TanStack Query
├─ Socket.IO client ├─ Session cache ├─ SSE for updates
└─ RPC handlers ├─ RPC gateway └─ assistant-ui
└─ Telegram bot
Data flow:
- CLI spawns agent (claude/codex/gemini), connects to hub via Socket.IO
- Agent events → CLI → hub (socket
messageevent) → DB + SSE broadcast - Web subscribes to SSE
/api/events, receives live updates - User actions → Web → hub REST API → RPC to CLI → agent
Reference docs
README.md- User overview, quick startcli/README.md- CLI commands, config, runnerhub/README.md- Hub config, HTTP API, Socket.IO eventsweb/README.md- Routes, components, hooksdocs/guide/- User guides (installation, how-it-works, FAQ)
Shared rules
- No backward compatibility: breaking old formats freely
- Prioritize Pragmatism, and Avoid Overengineering.
- Write necessary tests ONLY.
- TypeScript strict; no untyped code
- Bun workspaces; run
buncommands from repo root - Path alias
@/*maps to./src/*per package - Prefer 4-space indentation
- Zod for runtime validation (schemas in
shared/src/schemas.ts)
Common commands (repo root)
bun typecheck # All packages
bun run test # cli + hub tests
bun run dev # hub + web concurrently
bun run build:single-exe # All-in-one binary
Key source dirs
CLI (cli/src/)
api/- Hub connection (Socket.IO client, auth)claude/- Claude Code integration (wrapper, hooks)codex/- Codex mode integrationagent/- Multi-agent support (Gemini via ACP)runner/- Background daemon for remote spawncommands/- CLI subcommands (auth, runner, doctor)modules/- Tool implementations (ripgrep, difftastic, git)ui/- Terminal UI (Ink components)
Hub (hub/src/)
web/routes/- REST API endpointssocket/- Socket.IO setupsocket/handlers/cli/- CLI event handlers (session, terminal, machine, RPC)sync/- Core logic (sessionCache, messageService, rpcGateway)store/- SQLite persistence (better-sqlite3)sse/- Server-Sent Events managertelegram/- Bot commands, callbacksnotifications/- Push (VAPID) and Telegram notificationsconfig/- Settings loading, token generationvisibility/- Client visibility tracking
Web (web/src/)
routes/- TanStack Router pagesroutes/sessions/- Session views (chat, files, terminal)components/- Reusable UI (SessionList, SessionChat, NewSession/)hooks/queries/- TanStack Query hookshooks/mutations/- Mutation hookshooks/useSSE.ts- SSE subscriptionapi/client.ts- API client wrapper
Shared (shared/src/)
types.ts- Core types (Session, Message, Machine)schemas.ts- Zod schemas for validationsocket.ts- Socket.IO event typesmessages.ts- Message parsing utilitiesmodes.ts- Permission/model mode definitions
Pre-push self-review (agents)
Before commit/push/PR: use the pre-push-review skill (~/.cursor/skills/pre-push-review/).
- Mechanical:
bun typecheck && bun run test(matches.github/workflows/test.yml) - Logic: skim
git diff origin/main...HEAD; apply.github/prompts/codex-pr-review.mdas a local Major checklist (no Codex required) - Style: optional
Testing
- Test framework: Vitest (via
bun run test) - Test files:
*.test.tsnext to source - Run:
bun run test(from root) orbun run test(from package) - Hub tests:
hub/src/**/*.test.ts - CLI tests:
cli/src/**/*.test.ts - No web tests currently
Common tasks
| Task | Key files |
|---|---|
| Add CLI command | cli/src/commands/, cli/src/index.ts |
| Add API endpoint | hub/src/web/routes/, register in hub/src/web/index.ts |
| Add Socket.IO event | hub/src/socket/handlers/cli/, shared/src/socket.ts |
| Add web route | web/src/routes/, web/src/router.tsx |
| Add web component | web/src/components/ |
| Modify session logic | hub/src/sync/sessionCache.ts, hub/src/sync/syncEngine.ts |
| Modify message handling | hub/src/sync/messageService.ts |
| Add notification type | hub/src/notifications/ |
| Add shared type | shared/src/types.ts, shared/src/schemas.ts |
Important patterns
- RPC: CLI registers handlers (
rpc-register), hub routes requests viarpcGateway.ts - Versioned updates: CLI sends
update-metadata/update-statewith version; hub rejects stale - Session modes:
local(terminal) vsremote(web-controlled); switchable mid-session - Permission modes:
default,acceptEdits,bypassPermissions,plan - Namespaces: Multi-user isolation via
CLI_API_TOKEN:<namespace>suffix
Critical Thinking
- Fix root cause (not band-aid).
- Unsure: read more code; if still stuck, ask w/ short options.
- Conflicts: call out; pick safer path.
- Unrecognized changes: assume other agent; keep going; focus your changes. If it causes issues, stop + ask user.