Commit Graph
256 Commits
Author SHA1 Message Date
weishu 41d8844c00 fix: implement permission handler callbacks and add CodexPermission UI support
Adds onRequest and onComplete callbacks to CodexPermissionHandler to track
permission request/response lifecycle. Includes helper functions to normalize
command and cwd inputs, and displays permission requests in the web UI.
2026-01-13 11:06:50 +08:00
weishu 9f2da5f8ae fix: suppress git stderr when running in non-git directory 2026-01-12 17:59:52 +08:00
weishu c659446fc1 fix: enable shell option for Windows process spawning in ACP transport
close #49
2026-01-10 21:53:53 +08:00
weishu 1665c63d95 fix: add retry logic to daemon machine registration for transient connection errors
Add exponential backoff retry mechanism to handle ECONNREFUSED errors when the
server isn't ready yet during daemon startup. This includes:

- New errorUtils module with error classification helpers
- withRetry function in time.ts supporting configurable exponential backoff
- Machine registration retry with sensible defaults (60 attempts, 1-30s delays)
- Error refactoring to consolidate extractErrorInfo utility

close #35
2026-01-08 11:37:29 +08:00
zrq8andGitHub 2646df346e fix: start codex on Windows by using shell; keep mcp args parseable (#40)
Windows global installs expose codex as codex.cmd; spawning 'codex' without shell hits ENOENT.

Enable shell to align with Claude's Windows behavior and resolve PATH lookup.

Shell spawn makes cmd.exe strip TOML double quotes in -c arrays, so args become a string.

Switch mcp args to TOML literal (single-quoted) arrays to preserve types; update tests.
2026-01-08 10:44:01 +08:00
weishu 9dc69d1e80 feat: add serverUrl configuration support with settings.json fallback
Implement serverUrl initialization following the cliApiToken design pattern:
- Environment variable HAPI_SERVER_URL (highest priority, allows temporary override)
- settings.json serverUrl field (user persistent configuration)
- Default value 'http://localhost:3006' (fallback)

Changes:
- Add serverUrl field to Settings interface (persistence.ts)
- Convert serverUrl to private property with getter/setter (configuration.ts)
- Create initializeServerUrl module to load from settings (serverUrlInit.ts)
- Integrate serverUrl initialization in tokenInit flow (tokenInit.ts)
- Skip auto-start when serverUrl is configured in settings (autoStartServer.ts)
2026-01-08 10:37:37 +08:00
weishu a627b085c8 feat: add --host and --port CLI arguments to hapi server command. fix #37
Add configurable host binding for the Mini App HTTP server through:
- New `webappHost` configuration (defaults to 127.0.0.1 for security)
- CLI arguments `--host` and `--port` with flexible parsing (--host=value or --host value)
- Priority order: CLI args > env vars > settings.json > defaults
- Updated Bun.serve() to bind to the configured hostname

Modified:
- server/src/config/settings.ts
- server/src/config/serverSettings.ts
- server/src/configuration.ts
- server/src/web/server.ts
- server/src/index.ts
- cli/src/commands/server.ts
2026-01-07 14:39:54 +08:00
weishu 605d44f3ac chore(codex): log MCP wrapper event types 2026-01-06 18:38:22 +08:00
weishu 9a28e6e0a1 refactor: unify MCP bridge setup and system prompt delivery
Extract duplicate MCP bridge initialization code from codexLocalLauncher and
codexRemoteLauncher into a new buildHapiMcpBridge utility. This ensures both
modes use identical server setup logic and provides a single source of truth
for MCP configuration.

Update codexStartConfig to deliver system prompt via developer_instructions
instead of appending to the user message. This ensures consistent behavior
between local and remote modes and properly separates system guidance from
user intent.
2026-01-05 18:38:58 +08:00
weishu c50621e85a feat: add MCP config and system prompt support for Codex local mode
Implements MCP server configuration and developer instructions support in
Codex local mode, bringing it to parity with remote mode.

Key additions:
- buildMcpServerConfigArgs() and buildDeveloperInstructionsArg() utilities
  to construct -c config arguments for passing MCP servers and instructions
  to the Codex CLI at runtime
- TITLE_INSTRUCTION for Codex to call hapi__change_title to update chat
  session titles dynamically
- Codex local mode now starts hapi MCP bridge server and passes both MCP
  configuration and developer instructions to Claude, enabling full feature
  parity with remote mode

Files changed:
- New: codexMcpConfig.ts (utilities), systemPrompt.ts (prompt definition),
  codexMcpConfig.test.ts (comprehensive tests)
- Updated: codexLocal.ts (accepts mcpServers, builds config args),
  codexLocalLauncher.ts (starts hapi server, passes config),
  codexStartConfig.ts (imports TITLE_INSTRUCTION)
2026-01-05 18:38:58 +08:00
weishu 908d2f694a refactor: extract permission handler base class for code reuse 2026-01-05 18:04:51 +08:00
weishu e8252c601f refactor: extract remote launcher base class for code reuse 2026-01-05 16:50:22 +08:00
weishu 0e360f0a48 refactor: extract session scanner base class for code reuse
Create BaseSessionScanner abstract class to consolidate common session
scanning logic shared between Claude and Codex session scanners. Both
scanners now inherit from this base, reducing duplication and providing
consistent patterns for file watching, event processing, and state
management.
2026-01-05 15:53:30 +08:00
weishu d388c92114 refactor: remove CLI dead code
Remove unused daemon installation/uninstallation logic and unnecessary re-exports:
- Delete cli/src/daemon/mac/ directory (macOS LaunchDaemon install/uninstall not used)
- Delete cli/src/daemon/install.ts and uninstall.ts wrappers
- Remove daemon install/uninstall subcommands from cli/src/commands/daemon.ts
- Delete cli/src/api/encryption.ts (misleading name, just base64 encoding)
- Inline base64 encoding directly in cli/src/persistence.ts
- Delete cli/src/modules/common/gitHandlers.ts (unnecessary re-export)
- Update cli/src/modules/common/registerCommonHandlers.ts to import directly from handlers/git

Part of refactoring plan item #1 "删除 CLI 死代码".
2026-01-05 13:00:48 +08:00
weishu f82728e9b3 refactor: remove deprecated logout command and legacy sidechain logic 2026-01-05 10:49:23 +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
weishu c8325b921a refactor: extract session lifecycle management and mode switching to shared module
Consolidates duplicate cleanup, signal handling, and state management logic from
runClaude and runCodex into a reusable createRunnerLifecycle factory function.
Extracts mode switching handler and controlled user state updates into utilities.
Adds runLocalRemoteSession wrapper to handle session ready callbacks in loop base.
2026-01-04 20:50:33 +08:00
weishu 34cfe49f87 refactor: extract chat normalization and reducer logic, cleanup legacy credentials
- Split normalize.ts into focused modules: normalizeAgent, normalizeUser, normalizeUtils
- Extract reducer.ts into specialized modules: reducerCliOutput, reducerEvents, reducerTimeline, reducerTools
- Remove legacy credentials support (zod schema, readCredentials, writeCredentialsLegacy)
- Refactor NewSession component from monolithic file into modular subcomponents
- Improves code organization and maintainability across chat and authentication layers
2026-01-03 23:39:10 +08:00
weishu f2f46e9383 refactor(api): extract versioned update handling to shared utility
Extract duplicate version acknowledgment logic from apiMachine and
apiSession into a reusable applyVersionedAck utility. This handles
success, version-mismatch, and error responses consistently with
customizable parsing and error handling via options object.
2026-01-03 22:23:29 +08:00
weishu aa0c3f2f0d refactor(cli): split command routing and modularize RPC handlers
Restructure CLI entry point and RPC handler registration to improve maintainability:

- Introduce command registry pattern with CommandDefinition interface for consistent command structure
- Extract individual command modules (claude, codex, daemon, doctor, gemini, auth, connect, etc.)
- Move RPC handlers into separate feature modules (bash, files, git, directories, ripgrep, difftastic, slashCommands)
- Create shared RPC types and response helpers (rpcTypes.ts, rpcResponses.ts)
- Move SpawnSessionOptions and SpawnSessionResult to rpcTypes for proper type organization
- Simplify index.ts to minimal entrypoint using command registry
- Update imports in apiMachine.ts and daemon/run.ts to use rpcTypes module

This enables:
- Better code organization by feature/command
- Easier testing of individual commands
- Safer RPC handler registration without side effects
- Clearer separation of concerns between routing and business logic
2026-01-03 17:29:05 +08:00
weishu 89b6fc34f7 refactor(cli): unify session bootstrap 2026-01-03 15:34:49 +08:00
weishu e2028b6914 Unify protocol types and modes 2026-01-03 14:43:59 +08:00
weishu bc602ff5ea fix: archive session 2026-01-03 10:31:54 +08:00
weishu 2de3a3d635 fix: expand codex custom prompt 2026-01-02 21:45:29 +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 a0b1bb1524 refactor: remove unused onboardingCompleted field from Settings 2025-12-31 17:24:13 +08:00
weishu d61cfc90c2 refactor: replace specific character regex with comprehensive non-alphanumeric pattern
Update the regex in getProjectPath to replace all non-alphanumeric characters
with dashes instead of only specific ones. This provides more robust handling
of edge cases in working directory paths.
2025-12-31 12:18:34 +08:00
weishu 705ce24e17 refactor: remove unnecessary getCleanEnv() function
Simplify environment handling by removing the getCleanEnv() function that was
filtering out local node_modules/.bin paths. Running from home directory is
sufficient to avoid local cwd side effects.
2025-12-31 11:16:45 +08:00
weishu b7dce6bf3f refactor: use undefined instead of null for optional return type 2025-12-30 17:39:24 +08:00
weishu 754d9dc0e8 feat: auto-detect git worktree context from git commands
When HAPI_WORKTREE_* environment variables are not set, fall back to
probing git to detect if running inside a worktree. This enables
worktree features to work automatically without explicit env vars.
2025-12-30 16:44:18 +08:00
weishu ce6234da3f fix: prevent race condition in MessageQueue2 wait logic 2025-12-30 13:26:33 +08:00
weishu b160888101 feat: implement message backfill to prevent message loss on reconnection 2025-12-30 13:22:27 +08:00
weishu 90e6879552 feat: add local session soft resume support for remote codex sessions 2025-12-30 11:59:34 +08:00
weishu 7845708123 fix git commit prompt 2025-12-29 14:36:24 +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 2dc09a80db fix: pass through all permission modes in claudeRemote 2025-12-28 20:51:18 +08:00
weishu 05deb6fff8 feat: add directory autocomplete with validation for new session form 2025-12-28 16:31:53 +08:00
weishu ce40de900f fix: update slash command descriptions for claude, codex, and gemini.
close #20
2025-12-28 15:19:08 +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 2004d22afe fix: capture process PID in local variable for TypeScript control flow 2025-12-28 14:01:12 +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
weishu 50d5c4fd35 fix: resolve TypeScript type inference issue in claudeLocal.ts
Remove unnecessary Promise wrapper and move args building outside try block
so cleanupMcpConfig becomes const with proper type inference instead of never
2025-12-28 13:12:15 +08:00
Evan7198andweishu 62f0cf4c41 fix: improve cross-platform compatibility for path and file operations
Use basename() instead of split('/').pop() and 'wx' flag instead of
fs constants for better Windows compatibility.
2025-12-28 12:16:51 +08:00
weishu 2ef7e0ec5f refactor: extract MCP config handling to use temp files on Windows 2025-12-28 11:36:56 +08:00
weishu 007721bdc8 fix: codex session selection 2025-12-27 22:24:18 +08:00
weishu 3bdcc14ed0 refactor: simplify yolo mode implementation by removing env vars
Remove HAPPY_GEMINI_ARGS and HAPPY_GEMINI_COMMAND environment variables.
Refactor gemini.ts to export registerGeminiAgent(yolo) function that
directly configures args instead of reading from environment.
2025-12-27 21:24:16 +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 f03c7f2cc8 feat: add intelligent session matching based on cwd and timestamp 2025-12-26 21:11:43 +08:00