Commit Graph
74 Commits
Author SHA1 Message Date
weishu 23887ce040 refactor: remove unused/deprecated code and legacy socket events 2026-01-05 13:00:48 +08:00
weishu 21a64dfb49 refactor: extract session summary utilities to shared module 2026-01-05 13:00:48 +08:00
weishu b665e34d3c refactor: modularize store implementation into domain-specific modules 2026-01-05 11:51:49 +08:00
weishu 7a487269ea refactor: replace hardcoded permission/model modes with centralized schema validation
Extract permission and model mode validation into reusable functions utilizing
@hapi/protocol schemas. Use isPermissionModeAllowedForFlavor and
isModelModeAllowedForFlavor to validate modes based on session flavor (claude/codex).
Replace inline type definitions with shared types from @hapi/protocol.
2026-01-04 22:07:03 +08:00
Ruihang XiaandGitHub d1c532301e feat: sync thinking state to session list view (#32)
Signed-off-by: Ruihang Xia <waynestxia@gmail.com>
2026-01-04 20:48:21 +08:00
weishu 37c6bc83d7 chore: migrate to AGPL-3.0-only 2026-01-04 20:45:15 +08:00
weishu 920ef29ab4 fix: docker build 2026-01-03 22:52:04 +08:00
weishu 4d18789d50 refactor: extract permission mode utilities and consolidate styling logic
Extract permission mode display logic into shared utilities for better reusability and maintainability. Add PermissionModeTone type and related helpers to centralize mode-based styling rules across components. Update components to use new PermissionModeOption type for consistent permission mode presentation.
2026-01-03 22:49:40 +08:00
weishu 705933e17b refactor: extract message utilities to shared module
Consolidate RoleWrappedRecord type and message envelope utilities into
a new shared module to reduce duplication across server and web packages.
2026-01-03 22:23:29 +08:00
weishu 680a37071e refactor(sync): split SyncEngine into modular services
Extracted five focused modules from SyncEngine to improve maintainability
and separation of concerns:
- EventPublisher: handles event broadcasting and listener management
- SessionCache: manages session state and lifecycle
- MachineCache: manages machine state and lifecycle
- MessageService: handles message storage and retrieval
- RpcGateway: handles RPC communication with sessions and machines
- aliveTime: utility for clamping and validating alive timestamps

Removed unused members (sessionMessages cache, fetchMessages,
getSessionMessages, setPermissionMode, setModelMode) that added
complexity without clear value.

SyncEngine now orchestrates these services as a lightweight facade,
improving code organization and testability.
2026-01-03 16:27:35 +08:00
weishu 41e5ce8eca fix(store): handle version 0 with existing tables gracefully
Instead of throwing a schema mismatch error when version is 0 but tables already exist, set the version and return. This allows the database to properly initialize without erroring.
2026-01-03 16:10:29 +08:00
weishu 365728aed7 refactor(store): introduce schema versioning and remove compatibility migrations
Replace legacy migration logic (ALTER TABLE, missing column checks) with explicit
schema version tracking. This prevents silent schema mismatches and simplifies the
database lifecycle—users must rebuild or offline-migrate on version mismatch.

Changes:
- Add SCHEMA_VERSION and REQUIRED_TABLES constants
- Refactor initSchema() to check version and table presence
- Extract createSchema() and helper methods (getUserVersion, setUserVersion, etc)
- Add compound indexes for better query performance (tag+namespace, platform+namespace)
- Store dbPath for better error messages
2026-01-03 15:52:29 +08:00
weishu 8ce568ea70 Fix sync event typing 2026-01-03 14:57:00 +08:00
weishu e2028b6914 Unify protocol types and modes 2026-01-03 14:43:59 +08:00
weishu 4fe20b74c7 fix: use relative path for PWA push notification URL 2026-01-03 12:55:09 +08:00
weishu 8e03cadcf8 refactor: restructure notification system with NotificationHub abstraction
Extract notification logic from PushNotifier into a modular architecture
with NotificationHub as the central coordinator and NotificationChannel
interface for different notification providers (push, telegram). This
enables better separation of concerns and easier addition of new
notification channels in the future.

- Create NotificationHub to coordinate multiple notification channels
- Create NotificationChannel interface for channel implementations
- Move push notification logic to PushNotificationChannel
- Update HappyBot to implement NotificationChannel
- Simplify HappyBot by removing sync event handling (delegated to hub)
- Add notification helper utilities (sessionInfo, eventParsing)
- Update index.ts to use new notification architecture
2026-01-03 12:36:44 +08:00
weishu 83fa0157b4 feat: make session metadata updated_at timestamp optional
Allow updateSessionMetadata to conditionally update the updated_at timestamp
by adding an optional touchUpdatedAt flag. When set to false, the timestamp is
not modified, enabling metadata updates without changing the last modified time.
2026-01-03 10:31:58 +08:00
weishu bc602ff5ea fix: archive session 2026-01-03 10:31:54 +08:00
weishu d87250aff2 fix: docker build 2026-01-03 08:59:22 +08:00
weishu 43519621f3 feat: add web push notifications support
Implement push notification system with VAPID keys, client service worker integration, and push subscription management. Includes server-side PushService for sending notifications and PushNotifier for reactive event handling, plus client-side usePushNotifications hook and service worker support.
2026-01-02 19:19:40 +08:00
weishu 41fd1abd53 feat: add session management (rename, archive, delete)
Implements comprehensive session lifecycle management with user-friendly interactions:

Rename: Update session metadata.name via PATCH endpoint with conflict detection
Archive: Abort active sessions via DELETE endpoint with validation
Delete: Permanently remove inactive sessions with cascade cleanup

Backend:
- Store.deleteSession() removes session and cascade-deletes messages
- SyncEngine.renameSession() with concurrency error handling
- SyncEngine.deleteSession() with active session validation
- PATCH /sessions/:id for rename, DELETE /sessions/:id for delete

Frontend Components:
- RenameSessionDialog: Text input with auto-focus and error display
- SessionActionMenu: Modal with rename, archive, delete buttons
- ConfirmDialog: Reusable confirmation with error feedback
- SessionHeader: Menu button (⋮) triggering action menu
- SessionList: Long-press detection triggering item actions

Interactions:
- Long-press on session list items (500ms threshold) opens action menu
- Menu button in session header (non-Telegram environments only)
- Confirmation dialogs with descriptive warnings for destructive actions
- Real-time error display in dialogs on operation failure
- Haptic feedback on long-press via usePlatform hook

Accessibility:
- Keyboard support (Enter/Space) for long-press handler
- Focus management in RenameSessionDialog
- Proper ARIA labels and semantic HTML
2026-01-02 19:15:01 +08:00
weishu 94823b7a8b feat: add auto-start server feature for CLI
- Added /health endpoint to server for readiness checks (no auth required)
- Created autoStartServer module that auto-starts server when:
  - HAPI_SERVER_URL not set (using default localhost:3006)
  - cliApiToken exists in settings (server previously used)
  - Port 3006 is not currently listening
- Server runs as child process (not daemon) and exits when CLI exits
- Integrated maybeAutoStartServer() into hapi, codex, and gemini commands
2026-01-02 16:21:14 +08:00
weishu 7ae7158127 fix: improve namespace-based multi-user 2025-12-31 23:28:29 +08:00
weishu e821458af8 feat: add namespace-based multi-user isolation
Implement namespace support across sessions, machines, and users for multi-user server deployments. Add access control with specific error reasons (namespace-missing, access-denied, not-found) and database schema updates with namespace columns and indexes.
2025-12-31 21:56:01 +08:00
weishu 8f7dcf848b refactor: Add Telegram binding storage and auth 2025-12-31 17:43:57 +08:00
weishu a0b1bb1524 refactor: remove unused onboardingCompleted field from Settings 2025-12-31 17:24:13 +08:00
weishu 4efc263d9b chore: add LGPL-3.0-or-later license and update package.json licenses
- Add LICENSE file to root and cli/ directories with LGPL-3.0-or-later text
- Create cli/NOTICE file with MIT attribution for happy-cli derived code
- Update license field in cli/, server/, and web/ package.json to "LGPL-3.0-or-later"
- Add NOTICE to cli/package.json files array for npm publishing
2025-12-31 13:08:02 +08:00
weishu b160888101 feat: implement message backfill to prevent message loss on reconnection 2025-12-30 13:22:27 +08:00
weishu 334cebc2da feat: add real-time permission and model mode synchronization close #21
Implements bidirectional sync of permission/model modes between CLI sessions and web app. Adds Codex-specific permission modes (read-only, safe-yolo, yolo) alongside Claude's modes. Web can now control CLI session state via RPC set-session-config handler, while CLI broadcasts state changes through keep-alive payloads. UI controls are flavor-aware, showing appropriate modes for Claude vs Codex vs Gemini. Type centralization in api/types eliminates circular dependencies.
2025-12-28 20:51:18 +08:00
weishu 1ef7bee01d feat: add listSlashCommands method to SyncEngine 2025-12-28 17:00:47 +08:00
weishu 05deb6fff8 feat: add directory autocomplete with validation for new session form 2025-12-28 16:31:53 +08:00
weishu fbc0d601f8 feat: add slash command autocomplete to HappyComposer
Implements full-stack slash command autocomplete with agent-specific built-in commands and user-defined command discovery. Includes React Strict Mode fix for suggestion handling.
2025-12-28 15:19:08 +08:00
weishu c35a5ce827 feat: add git worktree session support with improved UI
Implement comprehensive worktree session support allowing users to spawn sessions in temporary git worktrees. Includes backend worktree management, full-stack integration, and refined UI for session type selection.

Backend:
- Add worktree creation/removal utilities with branch management
- Track worktree metadata (basePath, branch, name, path) in session metadata
- Automatic cleanup of worktrees when sessions fail or exit
- Enhanced error handling with stderr tail logging

UI improvements:
- Redesign session type toggle with improved alignment and spacing
- Move worktree description inline with label for cleaner layout
- Add branch name input field that appears when worktree mode selected
- Auto-focus on worktree input when switching modes
- Reduce gap between radio options from gap-3 to gap-1.5
- Update descriptive text and placeholders for clarity

Integration:
- Thread worktree parameters through API client, RPC handlers, and daemon
- Add worktreeEnv utility to read worktree info from environment
- Update session spawning to support both simple and worktree modes
2025-12-28 13:17:58 +08:00
58e61b3db9 feat: create new session with yolo mode (#13)
* feat: create new session with yolo mode

Signed-off-by: Ruihang Xia <waynestxia@gmail.com>

* fix: harden sequence typecheck

* feat: add unified --yolo flag across all agents

---------

Signed-off-by: Ruihang Xia <waynestxia@gmail.com>
Co-authored-by: weishu <twsxtd@gmail.com>
2025-12-27 21:03:34 +08:00
weishu 126c5e483c fix: we need bun 1.3.5 becuase of the Terminal feature. close #15 2025-12-27 17:10:30 +08:00
NickGitHubfactory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
09faf443ce feat(server): add Dockerfile + CI docker build/push (#10)
* feat: add server Docker image build (Dockerfile + GH Actions)

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
2025-12-26 20:56:08 +08:00
aababe6a57 fix: use timing-safe comparison for CLI API token validation (#9)
* fix: use timing-safe comparison for CLI API token validation

Replace direct string comparison (===) with constant-time comparison
using crypto.timingSafeEqual to prevent timing attacks that could
leak information about the token character by character.

Affected locations:
- server/src/web/routes/auth.ts (accessToken validation)
- server/src/web/routes/cli.ts (bearer token middleware)
- server/src/socket/server.ts (socket.io /cli namespace auth)

* Update server/src/utils/crypto.ts

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-12-26 17:22:04 +08:00
weishu 5d5023883e refactor: safely access Bun.main with optional chaining 2025-12-26 12:40:44 +08:00
weishu 76b84a0b52 refactor: unify bun compiled detection with windows support
- Add shared isBunCompiled() function for consistent runtime detection
- Support Windows virtual filesystem paths (/~BUN/) alongside Linux/macOS (/$bunfs/)
- Use Bun.main for reliable detection instead of process.argv[1]
- Remove redundant $bunfs checks from cli/src/index.ts
- Update cli/src/utils/bunRuntime.ts to use shared detection function
- Create server/src/utils/bunCompiled.ts for server-side compilation check
2025-12-26 11:29:12 +08:00
weishu abec6d958d refactor: update dependencies including zod, vitest, and type packages 2025-12-25 23:18:13 +08:00
weishu 3765cc539b refactor: update dependencies and fix TypeScript instantiation depth issues
Updates ModelContextProtocol SDK and multiple dependent libraries to latest versions. Refactors TypeScript schemas to avoid instantiation depth issues by widening Zod types and using explicit type parameters.
2025-12-25 22:56:08 +08:00
weishu 18e6310451 feat: implement web terminal feature with xterm.js and Socket.IO proxy
- Add CLI-side terminal management via Bun.Terminal with TerminalManager
- Implement server-side Socket.IO proxy for terminal I/O between web and CLI
- Create web terminal UI component with xterm.js and support for resize/reconnect
- Add terminal route and navigation button in session chat
- Include comprehensive terminal implementation plan and architecture docs
2025-12-25 21:57:18 +08:00
weishu 0be023b23b feat: add configurable server URL for standalone web hosting
Adds support for hosting the web UI separately from the hapi server on static hosts (GitHub Pages, Cloudflare Pages). Users can now set a custom server origin via a dialog on the login screen, with the ability to return to same-origin behavior.

Changes include:
- New useServerUrl hook for managing server URL configuration and storage
- Updated API client to support baseUrl parameter for all requests
- Enhanced login UI with server picker dialog (top-right button)
- Auth system now keys tokens per baseUrl to support multiple servers
- SSE connection updated to use configured baseUrl
- Documentation updates for standalone hosting setup
2025-12-25 17:42:30 +08:00
weishu fa63529d04 fix: persist CLI_API_TOKEN from env var to settings when not already saved
When CLI_API_TOKEN is provided via environment variable, persist it to settings.json
if not already saved. This prevents token regeneration if the env var fails to load
on subsequent startups, ensuring token consistency across server restarts.
2025-12-25 15:48:45 +08:00
abe215d5d5 fix: use Bun.main to detect compiled binary instead of Bun.isCompiled (#4)
Bun.isCompiled does not exist and always returns undefined, causing
embeddedAssetMap to be null. This makes the server fall back to looking
for web/dist directory, which doesn't exist when running the compiled
binary from a different location.

The correct way to detect a compiled Bun binary is to check if Bun.main
starts with '/$bunfs' (the virtual filesystem path used by compiled binaries).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-25 15:15:04 +08:00
weishu 8353d34dfb refactor: move web asset module declarations to dedicated types file 2025-12-25 12:48:41 +08:00
weishu e5f9d8cbe8 feat: implement server configuration persistence to ~/.hapi/settings.json
Configuration now loads with priority: environment variable > settings.json > default value.
When values are read from environment variables and not present in settings.json, they are automatically saved for future use. This eliminates the need to repeatedly set environment variables.

- New serverSettings.ts module handles loading/saving with persistence logic
- Async createConfiguration() factory for proper initialization ordering
- Configuration sources tracked and displayed in startup logs
- Exported Settings interface and read/write functions from cliApiToken.ts
- Updated index.ts to display configuration sources in log output
2025-12-25 12:27:14 +08:00
weishu 92d9546a9d chore: add module declaration for web asset imports 2025-12-24 18:17:06 +08:00
weishu eee4489b0f docs: update all README files with comprehensive documentation
Update documentation across the project to reflect current state of codebase:
- cli/README.md: Add all commands (codex, gemini, daemon subcommands, doctor, mcp),
  configuration options, storage locations, and source structure references
- server/README.md: Add complete HTTP API reference, Socket.IO events, Telegram bot
  features, core logic descriptions, and source structure
- web/README.md: Add all routes, feature descriptions, authentication flow, data
  fetching, real-time updates, and source structure
- README.md: Improve feature list clarity, add HTTPS exposure instructions in
  quickstart, add multi-agent support section
2025-12-24 17:56:07 +08:00
weishu 852c7f4c4e Licenses 2025-12-24 17:35:19 +08:00