Commit Graph
111 Commits
Author SHA1 Message Date
weishu a2bdc73236 refactor(web): unify max-width constraints with tailwind content class
Adds maxWidth.content: '720px' to tailwind.config.ts for centralized width management across the web app. Replaces all hardcoded max-w-[720px] references with the new max-w-content class. Adds missing max-width constraints to file.tsx, files.tsx, and SessionList.tsx. Moves border-b dividers from outer full-width divs to inner max-w-content divs for consistent visual hierarchy.
2025-12-23 18:40:51 +08:00
weishu 2bff252e6a refactor: migrate unpack-tools script from CommonJS to TypeScript 2025-12-23 18:09:12 +08:00
weishu 92996667d5 refactor: remove CommonJS ripgrep launcher and spawn binary directly
Replace the ripgrep_launcher.cjs intermediary with direct binary execution.
This simplifies the ripgrep module by spawning the binary directly instead
of going through a Node.js subprocess wrapper. Add platform-specific binary
path resolution to handle both Unix and Windows environments.
2025-12-23 18:09:12 +08:00
weishu eafd4d12a9 feat: add session cleanup script with flexible filtering options
Add cleanup-sessions.ts script that enables deletion of sessions from the database with support for multiple filtering strategies:
- Message count filtering (delete sessions with fewer than N messages)
- Path pattern matching with glob support
- Orphaned session detection (sessions whose path no longer exists)
- Optional confirmation prompt with --force flag to skip

Includes 'clean-session' npm script for convenient invocation.
2025-12-23 17:45:15 +08:00
weishu 7f9145b6de feat: add token-based authentication to session hooks
Implement hook token validation to secure session start requests.
Each hook server generates a unique token that must be provided
in the x-hapi-hook-token header. Updates hook-forwarder command
to support both positional and named arguments for port and token.
2025-12-23 16:02:04 +08:00
weishu 61d3a1bed1 feat: implement session tracking via Claude hooks
Adds a dedicated hook server infrastructure to receive Claude SessionStart
notifications. This allows the CLI to track session ID changes (new sessions,
resume, compact, fork, etc.) without relying on file watchers.

Changes:
- Add SessionFound callback system to AgentSessionBase for session tracking
- Create hook server that listens for POST requests from Claude's hooks
- Generate temporary settings files with hook command configuration
- Implement session hook forwarder CLI command to relay hook data
- Integrate hook server into runClaude with proper cleanup
- Pass hookSettingsPath through local and remote execution paths
- Update SDK query builder to support --settings flag
2025-12-23 16:02:04 +08:00
weishu e637f2bb27 refactor(web): simplify NewSession component layout with divided sections
Replace Card wrapper with a flex column layout using dividers for better visual separation and simpler structure.
2025-12-23 15:53:42 +08:00
weishu 422018299c refactor(web): redesign SessionList component with enhanced session metadata
Replace Card-based layout with semantic button elements for better accessibility and keyboard navigation. Add session metadata fields (flavor, activeAt, modelMode) and implement helper functions to format session information including agent flavor, model mode, and relative last-seen timestamps. Update hover styles and add focus-visible indicators.
2025-12-23 14:17:15 +08:00
weishu f81e585eef refactor(daemon): use mtime-based version detection instead of string comparison
Replace CLI version string comparison with file modification time (mtime) based detection. This provides a more reliable way to detect when the CLI binary has been updated, especially for bun-compiled executables where package.json may not be accessible.

Changes:
- Add getInstalledCliMtimeMs() utility to check CLI binary or package.json mtime
- Store startedWithCliMtimeMs in daemon state on startup
- Use mtime comparison in version check loop for daemon auto-restart
- Move version flag handling to early CLI startup before daemon initialization
- Fix machine active state merging to prefer newer activeAt timestamp

This improves daemon restart behavior when CLI is updated via package managers.
2025-12-23 13:14:15 +08:00
weishu c8f7a23f2f feat(web): add continue hint in HappyComposer when switching to remote mode
When switching from local mode to remote mode, the placeholder text now
suggests users can type "continue" to resume interrupted tasks. This helps
users understand they can continue where they left off after experiencing
permission prompts that were stuck in the terminal during local mode.
2025-12-23 11:13:37 +08:00
weishu 88cce9c28d refactor: remove CommonJS launchers and use claude command directly
Remove local Claude launcher scripts and refactor to invoke the global
claude command from PATH. This simplifies the launcher logic and removes
the need to maintain separate CommonJS entry points.

Changes:
- Delete cli/scripts/claude_local_launcher.cjs, claude_remote_launcher.cjs,
  and claude_version_utils.cjs
- Update claudeLocal to spawn 'claude' command directly instead of using
  a launcher script
- Remove runtimePath dependency and launcher existence checks
- Add DISABLE_AUTOUPDATER environment variable for local mode
- Improve error messages when claude command is not found
- Add shell option for Windows compatibility in process spawning
- Remove unused imports from claudeLocal and index files
2025-12-23 10:21:50 +08:00
weishu f132a7dc79 feat(codex): implement CLI argument passthrough for codex
Collect unknown CLI arguments from index.ts and pass them through the execution chain (runCodex → loop → CodexSession → codexLocalLauncher → codexLocal), similar to how claude already works. This enables users to pass CLI arguments like --model and --sandbox to the underlying codex process.

Filter out the 'resume' subcommand which is managed internally by hapi, while allowing other CLI arguments to pass through. Add warning log in remote mode when CLI args are ignored since remote mode uses message-based configuration instead. Include unit tests for the resume filtering logic.
2025-12-23 09:06:08 +08:00
weishu 0128792495 refactor: remove thinking state tracking from local launcher 2025-12-23 08:25:44 +08:00
weishu 93810689ad refactor(ui): extract switch controls logic into reusable hook and terminal restoration utility
Extracts duplicated exit/switch confirmation handling from CodexDisplay and RemoteModeDisplay into a custom useSwitchControls hook. Centralizes terminal state restoration (raw mode, keyboard protocol cleanup) into a restoreTerminalState utility function used across codex modules. Improves code reusability and maintainability.
2025-12-22 23:12:24 +08:00
weishu 360e3a9919 refactor: extract session and loop logic into reusable agent base classes 2025-12-22 23:12:24 +08:00
weishu aef3ed367b refactor(web): move message loading header into HappyThread with infinite scroll
Move the message loading header UI and infinite scroll logic from SessionChat into HappyThread component. This improves component isolation and adds IntersectionObserver-based automatic loading with proper scroll position preservation and error handling.
2025-12-22 21:45:34 +08:00
weishu 999ee64852 refactor(web): unify session creation into single page with path history 2025-12-22 21:45:11 +08:00
weishu 4290f539bd refactor(codex): extract session management and launcher logic into separate modules
Reorganized runCodex.ts to improve maintainability by extracting:
- CodexSession class for session lifecycle management
- CodexLocalLauncher and CodexRemoteLauncher for mode-specific initialization
- CodexEventConverter for MCP message handling and UI buffer updates
- CodexSessionScanner for resume file discovery
- emitReadyIfIdle utility for ready event emission

Added codexSessionId field to metadata schema for session tracking.
Updated UI components to work with refactored architecture.
2025-12-22 19:14:47 +08:00
weishu 0c16b7b215 feat(web): improve token refresh handling with automatic 401 retry and focus-based refresh 2025-12-22 18:29:32 +08:00
weishu 439778c875 fix(web): enable auto-scroll and add key prop to HappyThread component 2025-12-22 18:11:07 +08:00
weishu 0aab06ca47 fix(cli): resolve path alias with bun link using bunfig.toml configuration
When the cli package is symlinked via `bun link`, tsconfig.json's `rootDir: ".."`
interferes with the `@/*` path alias resolution at runtime. Add bunfig.toml to
explicitly configure path aliases for Bun's runtime to fix the module resolution error.
2025-12-22 16:44:27 +08:00
weishu d057daabfe chore: migrate cli distribution from npm to bun executable
Migrate HAPI CLI from npm-based distribution to Bun single-executable format:
- Remove npm bin wrappers (bin/happy.mjs, bin/happy-mcp.mjs)
- Simplify package.json: remove npm publish config (exports, main, module, types, files, publishConfig)
- Update bin entry to point to TypeScript source (src/index.ts)
- Migrate shebang from Node to Bun (#!/usr/bin/env bun)
- Simplify build scripts: remove npm-specific steps (pkgroll, prepublishOnly, release-it)
- Update spawnHappyCLI to support compiled binaries and development TypeScript mode
- Update daemon/doctor diagnostics for new process detection logic
- Production: use `bun build --compile` for single-executable releases
- Development: run TypeScript directly via `bun src/index.ts` or `tsx src/index.ts`
2025-12-22 16:44:20 +08:00
weishu fd94a684dc fix(cli): improve error message categorization for better UX
- Connection errors (ECONNREFUSED, ETIMEDOUT, ENOTFOUND, "Network Error") show
  a friendly message with the server URL and network troubleshooting hints
- Authentication errors (401, 403, "unauthorized", "forbidden") suggest running
  `hapi auth login` to help users resolve auth issues
- Use case-insensitive matching (toLowerCase) to reliably catch error message
  variants
2025-12-22 12:34:52 +08:00
weishu f16ccb2759 fix(web): handle null values in permissionMode and modelMode using nullish coalescing
The settings popup in HappyComposer did not show any option selected when
permissionMode or modelMode was null, since destructuring defaults only
handle undefined, not null. This fix uses the ?? operator to properly
handle both null and undefined cases, falling back to 'default' in both.
2025-12-22 12:25:01 +08:00
weishu aacab0be51 feat(web): add auto-focus to composer input on desktop devices only
Adds touch device detection via media query (pointer: coarse) to prevent
triggering virtual keyboard on mobile. Input auto-focus is now conditional
on desktop environments where it improves keyboard-based interactions.
2025-12-22 09:46:03 +08:00
weishu dbcbc93ad0 feat: improve codex permission elicitation with parameter extraction and reason support
- Add robust parameter extraction helpers in codexMcpClient
- Implement buildElicitationResult to construct properly formatted MCP responses
- Support dynamic requested schemas with fallback handling
- Add reason/explanation tracking through permission decision flow
- Improve type safety with explicit extraction and validation
2025-12-22 09:27:20 +08:00
weishu 6505c58bf3 feat: make Telegram optional and unify user authentication with owner ID
- Make TELEGRAM_BOT_TOKEN and ALLOWED_CHAT_IDS optional environment variables
- Add telegramEnabled flag to conditionally initialize the bot on startup
- Introduce persistent owner ID for unified user identity across web and Telegram auth
- Update Telegram bot to accept configuration in constructor instead of using global config
- Handle empty allowlist by showing chat ID prompt on /start command
- Use owner ID instead of Telegram user ID for API authentication
- Add conditional Telegram support checks in auth routes with clear error messages
- Update documentation to explain optional Telegram configuration and binding workflow
- Rename telegramUserId to userId in auth middleware for clarity
2025-12-22 08:52:51 +08:00
weishu 7c86f83d5c feat: add switch to remote button for local mode 2025-12-22 00:05:55 +08:00
weishu 8cbe68c47a fix(cli): add stub embedded assets generation to build process 2025-12-22 00:01:34 +08:00
weishu e54c9844e8 feat(web): separate pending permissions from task details in tool messages
Add helper functions to identify and split task children into pending
permission blocks and other details, allowing permission prompts to display
immediately while keeping other task details collapsible.
2025-12-22 00:00:10 +08:00
weishu 16c2e7c7ec fix(web): fix navigation in session creation flow with back buttons
- Add back buttons to MachinesPage and SpawnPage for non-Telegram environments
- Fix navigation after session creation to clear spawn flow from history
- Update useAppGoBack hook to use explicit path navigation for consistent behavior
2025-12-21 23:55:33 +08:00
weishu 04725dda72 fix(web): remove streaming dot indicator from markdown component 2025-12-21 23:13:39 +08:00
weishu ab06426773 feat: add source file execution and fix function name reference
- Add support for running CLI from TypeScript source when using tsx or similar tools
- Fix outdated happy__change_title reference to hapi__change_title in codex prompt
2025-12-21 23:13:14 +08:00
weishu c1fce7a9cf fix(web): handle codex content type in message normalization
Add isCodexContent() helper and check for failed normalization of codex
content to properly skip unsupported codex message types during decryption
2025-12-21 22:02:58 +08:00
weishu 3aa41fcef2 fix: add type safety improvements and fix Bun runtime type issues
- Replace embeddedAssets stub with generated type definitions
- Fix Bun.isCompiled access with proper type assertion to prevent undefined errors
- Improve router search validation with explicit SessionFileSearch type
- Simplify middleware return patterns for better readability
2025-12-21 19:53:44 +08:00
weishu 81852a3176 refactor: unify runtime directories and environment variables to HAPI_HOME
Consolidate CLI and server runtime directories from ~/.config/hapi/ (CLI) and ~/.hapi-server/ (Server) to a single ~/.hapi/ directory. Unify environment variables from HAPI_HOME_DIR (CLI) and HAPI_BOT_DATA_DIR (Server) to a single HAPI_HOME variable across both applications. Update all documentation and configuration references accordingly. Bump bun-types to 1.3.5.
2025-12-21 19:17:07 +08:00
weishu bf72e0dc3b chore: remove unused test fixtures and disable dead test case 2025-12-21 19:16:24 +08:00
weishu a665386f05 fix(web): add safe-area-inset-top padding to prevent statusbar overlap on iOS PWA
This fixes an issue where viewport-fit=cover and black-translucent statusbar
configuration allowed content to extend under the iOS statusbar. Added env(safe-area-inset-top)
CSS handling to all main layout components:
- SessionHeader with pt-[env(safe-area-inset-top)]
- SessionsPage, MachinesPage, SpawnPage with safe-area padding
- FilesPage and FilePage headers with safe-area padding
2025-12-21 18:50:40 +08:00
weishu 4f03f29ac3 docs: rebrand Happy to HAPI and add component documentation
This commit rebrands the project from "Happy" to "HAPI" throughout the codebase, including documentation, comments, logs, and tool references. It also adds comprehensive README files for the server and web components, clarifies the monorepo structure in AGENTS.md and root README.md, and removes the outdated roadmap.md file.

Changes include:
- Rebrand references from Happy to HAPI in CLI, server, and web components
- MCP tool names updated from mcp__happy__ to mcp__hapi__
- Process/service names updated consistently
- New server/README.md with deployment and configuration guide
- New web/README.md with stack and development instructions
- Updated root README.md with quickstart guide
- Updated AGENTS.md with cleaner structure documentation
- Removed cli/roadmap.md (now superseded by documentation)
2025-12-21 18:49:04 +08:00
weishu 56ae2c85a2 feat(cli): add Agent Client Protocol (ACP) integration for external agent support
Implements comprehensive ACP backend enabling integration with ACP-compliant agents like Gemini. Includes stdio transport, message handling, permission flow, and registry for agent management. Adds new 'hapi gemini' command to launch ACP agent sessions.
2025-12-21 18:40:04 +08:00
weishu 76a82c27c5 fix(web): prevent text overflow in user message component by adding min-w-0 constraint 2025-12-21 09:16:46 +08:00
weishu afe0e8b892 feat(web): add CLI output message block support with layout improvements
Implement CLI output message type for displaying command output from user/assistant messages. Adds CliOutputBlock component and type with detection logic based on message metadata and CLI tags. Includes merging of adjacent CLI output blocks for cleaner presentation. Enhance layout throughout components with proper overflow handling and width constraints for improved text wrapping and scrolling behavior.
2025-12-21 09:16:46 +08:00
weishu 1028547a3a feat(cli): add single executable with embedded web assets support
Implement support for bundling web assets into CLI single executable binaries.
When built with --with-web-assets, the executable includes the compiled web
application and serves it directly without file system access. A stub generator
creates empty manifests for normal builds to maintain compatibility.

Key changes:
- Add --with-web-assets flag to build-executable.ts with manifest validation
- Generate embeddedAssets.ts manifest from web/dist during build
- Serve embedded assets in web server with fallback to file system
- Add hapi server subcommand to start API + web server
- Include server sources in CLI tsconfig for compilation scope
- Add workspace-level build:single-exe scripts for production builds
2025-12-21 08:42:00 +08:00
weishu cf04937355 feat(cli): refactor embedded assets with Bun-specific and stub implementations
Split embedded assets loading into runtime-specific variants using package.json imports field. Bun-compiled binaries use the full implementation with file assets, while stub fallback provides clear error for non-Bun runtimes.
2025-12-20 23:46:02 +08:00
weishu be655f9fcf feat(web): enable scroll restoration in TanStack Router
Adds scrollRestoration: true to createRouter configuration to preserve
scroll position when navigating between pages, improving navigation UX
when switching between views like sessions list and session details.
2025-12-20 23:20:30 +08:00
weishu eac7ff239a fix: improve error handling in git operations and queries 2025-12-20 23:09:53 +08:00
weishu 8ebd4f6ab9 feat: add git integration with file browsing and diff viewing
Add comprehensive git support across the stack:
- CLI: register git RPC handlers (status, diff numstat, diff file)
- Server: create git routes with proper session path resolution
- Web: add file browser, diff viewer, and git status visualization
- Add FileIcon component and git parser utilities
- Add TanStack Router routes for /files and /file pages
- Add git-themed CSS variables for light and dark modes
2025-12-20 23:00:26 +08:00
weishu 17eeba10d6 feat(cli): add Bun single executable binary support
Enables building hapi as standalone Bun-compiled executables for macOS,
Linux, and Windows (x64/arm64). Adds build script, bootstrap entry point,
runtime asset management, and automatic deployment of bundled tools
(ripgrep, difftastic). Includes MCP stdio bridge support and proper
environment handling for compiled binaries. Updates documentation with
build and installation instructions for single executable distribution.
2025-12-20 21:41:11 +08:00
weishu bf18224d05 fix(web): suppress focus ring on pointer interactions while preserving keyboard accessibility 2025-12-20 19:52:56 +08:00
weishu ce5bdc8bed feat(web): improve AskUserQuestion tool card UX with better answers visualization
- Show selected answers with green borders and checkmarks in the question view
- Use circles (●/○) for single-select and squares (☑/☐) for multi-select
- Multi-question titles now show "N Questions" with subtitle "(+N more)"
- Remove redundant Single/Multi badges from footer
- Hide empty Result section when answers are shown in the view
- Dialog header updates to "Questions & Answers" when answered
- Handle freeform/fallback answers gracefully in all display modes
2025-12-20 18:04:40 +08:00