Commit Graph
68 Commits
Author SHA1 Message Date
歸藏 487c0a5cb7 fix: prevent path traversal in file APIs (#16)
fix: prevent path traversal in file tree and preview APIs
2026-02-09 16:08:11 +08:00
歸藏 8dcc19d077 fix: add graceful database shutdown (#20)
fix: add graceful database shutdown to prevent WAL file leaks
2026-02-09 16:08:07 +08:00
歸藏 c2c53e9591 feat: import and resume Claude Code CLI sessions (#28)
feat: import and resume Claude Code CLI sessions (closes #10)
2026-02-09 16:08:02 +08:00
歸藏 336897cded fix: 支持读取 ~/.claude/skills/ 目录下的已安装技能 (#36)
fix: 支持读取 ~/.claude/skills/ 目录下的已安装技能
2026-02-09 16:07:58 +08:00
歸藏 c558b40eb8 fix: 修复加载大消息会话时卡死的问题 (#38)
fix: 修复加载大消息会话时卡死的问题
2026-02-09 16:07:54 +08:00
llg-linwei f437024a96 fix: 修复加载大消息会话时卡死的问题 2026-02-09 14:29:58 +08:00
gy212andClaude Opus 4.6 61e3720ded fix: 支持读取 ~/.claude/skills/ 目录下的已安装技能 (#35)
问题:CodePilot 只扫描 ~/.agents/skills/,缺失了 ~/.claude/skills/ 路径,
导致用户通过 CLI 安装到该目录的技能无法在 CodePilot 中显示和使用。

修改内容:

后端:
- 列表接口 (GET /api/skills) 同时扫描 ~/.agents/skills/ 和 ~/.claude/skills/
- 通过 SHA1 内容哈希去重:同名同内容只保留一条,同名不同内容保留两条
- 详情接口 (GET/PUT/DELETE /api/skills/:name) 新增 ?source= 参数精确定位来源
- 详情接口使用 YAML front matter 的 name 字段匹配,修复列表能看到但点开 404 的问题
- 同名不同内容时返回 409,要求前端传 source 消歧

前端:
- SkillItem 类型新增 installedSource 字段
- Badge 显示 installed:claude 或 installed:agents 明确来源
- 保存/删除时携带 ?source= 防止误操作同名技能
- 聊天补全项描述追加来源提示
- 技能展开时精准请求对应来源

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-09 11:10:08 +08:00
7418andClaude Opus 4.6 5b69a63c06 fix: show env vars as overridden when a provider is active
When a manually configured provider is active, environment variables
are now shown with "Overridden" badge, strikethrough text, and muted
colors instead of both appearing as active simultaneously.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-09 10:32:37 +08:00
7418andClaude Opus 4.6 8002131692 docs: add release notes format spec to CLAUDE.md
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-09 10:26:09 +08:00
7418andClaude Opus 4.6 a42c0e312d fix: resolve session switching stuck on loading spinner
Race condition when quickly switching chat sessions caused the UI to get
stuck on loading. Added cancellation flags and key-based remounting.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-09 10:19:25 +08:00
7418andClaude Opus 4.6 e17482e652 chore: bump version to 0.5.0
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-08 22:26:52 +08:00
7418andClaude Opus 4.6 37cfaacaf0 fix: file upload bugs and UI adjustment
- Include base64 data in file metadata for chat display (fixes broken images)
- Use file-to-disk + Read tool approach instead of SDK multimodal
  messages (fixes slow response caused by invalid prompt format)
- Move attach button before folder picker in input toolbar

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-08 22:26:42 +08:00
liuxiaopai-ai 187cc23127 feat: import and resume Claude Code CLI sessions (closes #10)
Add ability to browse and import conversation history from Claude Code CLI
into CodePilot, with full resume support via SDK session ID.

Features:
- JSONL parser for Claude Code session files (~/.claude/projects/)
- REST API: GET /api/claude-sessions (list) + POST /api/claude-sessions/import
- Import dialog UI accessible from sidebar 'Import CLI Session' button
- Imported sessions bind sdk_session_id for seamless resume in CodePilot
- Duplicate import protection (409 with redirect to existing session)
- File size guard (50MB max) to prevent memory issues

Files changed:
- src/lib/claude-session-parser.ts — JSONL parser core
- src/app/api/claude-sessions/route.ts — list API
- src/app/api/claude-sessions/import/route.ts — import API with dedup
- src/components/layout/ImportSessionDialog.tsx — browse & import UI
- src/components/layout/ChatListPanel.tsx — sidebar integration
- src/__tests__/unit/claude-session-parser.test.ts — 17 unit tests
2026-02-08 22:04:12 +08:00
liuxiaopai-ai 746cea1eb7 fix: add graceful database shutdown to prevent WAL file leaks
The SQLite database connection was never explicitly closed when the
process exits. In WAL mode, this can leave behind -wal and -shm files
and risk data loss if the WAL hasn't been checkpointed.

Changes:
- Add closeDb() export for explicit database closure
- Register process shutdown handlers (exit, SIGTERM, SIGINT, SIGHUP)
  that call closeDb() before the process terminates
- Idempotent: multiple calls to closeDb() are safe
- After closeDb(), getDb() transparently re-opens the database
- Add 6 unit tests covering close, idempotency, reopen, data
  persistence, and WAL cleanup (all passing)
2026-02-08 21:37:35 +08:00
liuxiaopai-ai 0f05e4fd0f fix: address code review - fallback to homedir, validate baseDir, use afterAll
Address all 3 points from @op7418's review:

1. No baseDir fallback (severe): Both /api/files and /api/files/preview
   now fall back to os.homedir() when no baseDir is provided, preventing
   access to arbitrary system directories/files.

2. baseDir bypass via baseDir=/ (medium): Both APIs now validate that
   baseDir itself is within the user's home directory. Setting baseDir=/
   will be rejected with 403.

3. Test cleanup (minor): Replaced 'it(cleanup...)' with proper after()
   hook. Added 6 new tests for baseDir validation (18 total, all pass).
2026-02-08 21:36:56 +08:00
7418andClaude Opus 4.6 164f730da1 feat: add file upload and preview support (images and documents)
- Support image (JPEG/PNG/GIF/WebP, max 5MB) and document uploads
- Images sent as multimodal content blocks to Claude SDK
- Documents saved to temp dir for Claude's Read tool
- Emerald capsule badges in input for attached files
- Drag-and-drop, paste, and file picker support via PromptInput
- Chat display: image thumbnails with lightbox, file cards
- Lightbox uses Radix Dialog with prev/next navigation
- File metadata embedded in message content as HTML comments
- Compatible with existing slash command badge system

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-08 21:35:45 +08:00
liuxiaopai-ai 84de2d1de8 fix: prevent path traversal in file tree and preview APIs
The file tree API (/api/files) and file preview API (/api/files/preview)
had ineffective path safety checks that could allow reading arbitrary
files on the host system.

Issues fixed:
- /api/files: isPathSafe(resolvedDir, resolvedDir) always returns true
  since it compares the directory against itself
- /api/files/preview: isPathSafe(dirname, filePath) always returns true
  since a file is always inside its own parent directory

Changes:
- Add baseDir parameter to both APIs so the frontend can pass the
  session's working directory as a trust boundary
- When baseDir is provided, validate that the requested path is within it
- For /api/files/preview without baseDir, fall back to restricting access
  to the user's home directory (prevents /etc/passwd etc.)
- Add comprehensive unit tests covering path traversal, prefix attacks,
  symlink escapes, and edge cases (13 tests, all passing)

Security: This is a defense-in-depth measure. CodePilot runs locally so
the attack surface is limited, but proper validation prevents accidental
exposure when the dev server is bound to non-localhost interfaces.
2026-02-08 21:35:34 +08:00
7418andClaude Opus 4.6 4ac1f8cea3 chore: bump version to 0.4.1
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-08 21:02:48 +08:00
7418andClaude Opus 4.6 e956753a38 feat: add version display, cache clearing on upgrade, exclude data dir
- Show app version (v0.4.0) in sidebar bottom
- Clear Electron web cache when version changes to prevent stale JS
- Exclude data/ directory from packaged app

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-08 21:02:39 +08:00
7418andClaude Opus 4.6 de7b211876 fix: use utilityProcess.fork() to prevent macOS Dock bouncing icon
Replace child_process.spawn with Electron's utilityProcess.fork() for
the Next.js server subprocess. utilityProcess runs as a Chromium
service process which doesn't register as a GUI app, eliminating the
extra Dock icon bounce on macOS.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-08 21:02:33 +08:00
7418andClaude Opus 4.6 e688b29210 fix: add scrollbar to skills list on extensions page (closes #3)
Add flex flex-col min-h-0 to the skills container so overflow-y-auto
in SkillsManager can properly trigger scrolling.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-08 20:54:15 +08:00
7418andClaude Opus 4.6 4617c71f34 fix: detect and display env var API config fallback (closes #22, closes #4)
Providers API now detects ANTHROPIC_API_KEY, ANTHROPIC_AUTH_TOKEN, and
ANTHROPIC_BASE_URL from environment. ProviderManager shows a banner
when env vars are detected, informing users they're used automatically
when no provider is active.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-08 20:54:10 +08:00
7418andClaude Opus 4.6 81125a233b fix: auto-detect git-bash path on Windows (closes #23)
Add findGitBash() to platform.ts that checks env var, common install
paths, and derives path from `where git`. Used in claude-client.ts
to set CLAUDE_CODE_GIT_BASH_PATH when not already configured.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-08 20:54:03 +08:00
7418andClaude Opus 4.6 f2e7731766 chore: bump version to 0.4.0 and fix Linux desktop entry format
- Bump version to 0.4.0 for new release
- Fix electron-builder linux.desktop config to use entry sub-object
  (required by electron-builder 26.7.0)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-08 20:30:52 +08:00
7418andClaude Opus 4.6 e2ef642b67 fix: add missing popoverFilter to handleKeyDown useCallback deps
Fixes stale closure bug where keyboard navigation in the slash command
popover could reference an outdated filteredItems list when the filter
text changed.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-08 20:29:04 +08:00
歸藏 8b8a427754 Merge pull request #19 from liuxiaopai-ai/feat/linux-build-support
Code review approved: clean Linux build support, correct platform handling.
2026-02-08 20:27:30 +08:00
歸藏 5d62e8ce5d Merge pull request #18 from liuxiaopai-ai/fix/persist-structured-messages
Code review approved: high quality bug fix, backward compatible design, comprehensive tests (10 cases).
2026-02-08 20:27:27 +08:00
歸藏 7d52a508a4 Merge pull request #17 from liuxiaopai-ai/fix/mcp-sse-http-transport
Code review approved: correct SDK type usage, backward compatible, comprehensive tests (11 cases).
2026-02-08 20:27:23 +08:00
7418andClaude Opus 4.6 4e81eaa60b feat: fix slash commands, add badge UI, multi-provider management
Slash commands:
- Fix skills not appearing (removed non-existent `enabled` filter)
- Add badge/capsule UI for prompt-type commands (/compact, /review, etc.)
- SDK-native commands sent directly; CLI-only commands expanded to prompts
- /clear now resets SDK session and clears database messages
- /cost shows actual aggregated token usage statistics
- Keyboard: Backspace/Escape to remove badge, arrow keys auto-scroll popover
- Add /memory command for editing CLAUDE.md

Multi-provider management:
- CRUD API for API providers with SQLite storage
- ProviderManager UI with quick presets (GLM, Kimi, MiniMax, etc.)
- Dynamic model labels based on active provider
- Environment variable injection with conflict resolution

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-08 20:03:18 +08:00
liuxiaopai-ai afeaa6a120 feat: add Linux build support (AppImage, deb, rpm)
Add Linux as a supported platform with AppImage, deb, and rpm targets
for both x64 and arm64 architectures.

Changes:
- electron-builder.yml: add linux section with AppImage/deb/rpm targets,
  icon, category, and desktop entry configuration
- package.json: add electron:pack:linux script
- electron/main.ts: fix getIconPath() to return .png on Linux instead
  of .icns (macOS format); enable loadUserShellEnv() on Linux since GUI
  apps launched from desktop also have limited env
- README.md + README_CN.md: update supported platforms section

The README previously stated 'Linux builds are planned. Contributions
welcome.' — this delivers on that.
2026-02-08 16:01:33 +08:00
liuxiaopai-ai 960d5906b8 fix: persist structured tool_use/tool_result blocks in messages
The collectStreamResponse() function only collected text events,
discarding tool_use and tool_result events. When a conversation was
resumed, all tool call context was lost — the user only saw the
text portions of Claude's responses.

Changes:
- Collect tool_use and tool_result SSE events as MessageContentBlock
  entries alongside text blocks
- Flush accumulated text into a text block before each tool_use to
  preserve the interleaved ordering (text → tool_use → tool_result →
  text → ...)
- Store messages with tool calls as JSON arrays of MessageContentBlock,
  using the existing type definitions in types/index.ts
- Text-only messages remain as plain strings for backward compatibility
  with existing message rendering (parseMessageContent handles both)
- Add 10 unit tests covering parsing, serialization, round-tripping,
  edge cases, and backward compatibility (all passing)

This enables future improvements like:
- Rendering tool call history in resumed conversations
- Showing which files were read/written in previous turns
- Exporting full conversation logs with tool context
2026-02-08 15:59:59 +08:00
liuxiaopai-ai 7c8240fff0 fix: support SSE and HTTP transport types for MCP servers
The toSdkMcpConfig() function only handled stdio transport, discarding
the type, url, and headers fields. This meant SSE and HTTP MCP servers
configured through the Extensions page were silently converted to
broken stdio configs.

Changes:
- Import McpSSEServerConfig, McpHttpServerConfig, McpServerConfig types
  from the Claude Agent SDK
- Rewrite toSdkMcpConfig() to dispatch on config.type (stdio/sse/http)
- SSE configs: pass type, url, and optional headers to the SDK
- HTTP configs: pass type, url, and optional headers to the SDK
- stdio configs: pass command, args, env (unchanged behavior)
- Skip servers with missing required fields (url for SSE/HTTP, command
  for stdio) with a console warning instead of passing broken configs
- Do not include empty headers objects
- Add 11 unit tests covering all transport types, mixed configs,
  missing fields, and edge cases (all passing)

This aligns the implementation with the README which states:
'Supports stdio, sse, and http transport types.'
2026-02-08 15:58:15 +08:00
7418andClaude Opus 4.6 21226fc010 fix: replace Radix ScrollArea with native overflow-y-auto for Skills list (closes #8)
Radix ScrollArea doesn't reliably get constrained height in flex
layouts, preventing mouse wheel scrolling. Replace with a simple
div using overflow-y-auto and min-h-0 which works correctly.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-07 22:58:06 +08:00
7418andClaude Opus 4.6 f19053f1b2 docs: beautify README with badges, emojis, and updated content
- Enable GitHub release, platform, and license badges
- Add emojis to feature list for better visual hierarchy
- Update download section with macOS (arm64 + x64) and Windows support
- Correct database path to ~/.codepilot/codepilot.db
- Unify badge style between English and Chinese versions

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-07 22:51:59 +08:00
7418andClaude Opus 4.6 d80477cfac chore: add arch to macOS DMG filename
Use artifactName template to always include architecture in DMG
filename (e.g. CodePilot-0.2.3-x64.dmg) for clarity.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-07 22:33:53 +08:00
7418andClaude Opus 4.6 d554735dca chore: bump version to 0.2.3, add CLAUDE.md
Add CLAUDE.md with release checklist and build notes.
Bump version for new release with ABI fix, Windows path fix,
x64 macOS support, and Extensions scroll fix.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-07 22:22:08 +08:00
7418andClaude Opus 4.6 0b1ae6c02f fix: Windows Claude CLI path discovery and Extensions scroll
- Fix Windows Claude CLI not found when installed as .exe or without
  extension in .local\bin (closes #6). Now searches all extensions
  (.cmd, .exe, .bat, and bare) for every candidate directory.
- Fix Extensions/Skills list not scrollable when many items exist.
  Change content container to overflow-hidden so internal ScrollArea
  works correctly. Add overflow-auto to McpManager for its own scroll.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-07 22:20:03 +08:00
歸藏 f870b5d9c1 feat: support x64/arm64 macOS builds and fix build script errors (#7)
feat: support x64/arm64 macOS builds and fix build script errors
2026-02-07 22:15:34 +08:00
tianshuang b9d68d5051 feat: support x64/arm64 macOS builds and fix build script errors 2026-02-07 21:34:40 +08:00
7418andClaude Opus 4.6 b42d3d2ad8 fix: explicitly rebuild better-sqlite3 for Electron ABI in afterPack
Root cause: electron-builder's @electron/rebuild only rebuilds native
modules found in the `files` config. Since better-sqlite3 enters the
app through extraResources (via .next/standalone/), it was skipped.
The afterPack hook was copying the system Node.js ABI (127) instead
of the required Electron ABI (143).

Fix:
- afterPack now explicitly calls `npx electron-rebuild` targeting the
  exact Electron version and architecture from the build context
- Falls back to @electron/rebuild programmatic API if CLI fails
- Fails the build if rebuild cannot complete (no silent failures)
- Adds file size logging for verification
- Excludes `release/` from extraResources to prevent recursive nesting
- Adds startup ABI compatibility check in Electron main process with
  friendly error dialog instead of cryptic crash

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-07 16:23:37 +08:00
7418andClaude Opus 4.6 0bf97a3795 fix: support Windows/Linux paths in afterPack hook
The afterPack script only searched macOS-specific paths
(CodePilot.app/Contents/Resources) for better_sqlite3.node replacement.
Add Windows/Linux path (resources/standalone/) so the native module
ABI fix works on all platforms.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-07 14:28:38 +08:00
7418 b819eb7601 Merge branch 'main' into feat/windows-drive-switcher
Resolve conflict in electron-builder.yml: keep both icon resources
(from PR) and afterPack hook (from main).
2026-02-07 14:20:17 +08:00
xuxu777xuandClaude Opus 4.6 0234240066 feat: full Windows platform adaptation
- Add src/lib/platform.ts: cross-platform Claude CLI discovery
  (candidate paths, .cmd/.bat shell handling, where/which fallback)
- Refactor claude-status route and claude-client to use shared platform utils
- Electron main: Windows process spawning (windowsHide), PATH construction
  with AppData/npm dirs, titleBarOverlay, .ico icon support
- electron-builder.yml: add win/nsis build targets
- package.json: add electron:pack:win script
- FolderPicker: drive switcher dropdown for navigating between drives
- SkillsManager: fix duplicate key warning with filePath fallback

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-07 13:35:04 +08:00
7418andClaude Opus 4.6 2506e7f1e8 chore: bump version to 0.2.2
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-07 13:32:08 +08:00
7418andClaude Opus 4.6 ac0546c0b0 fix: ensure better-sqlite3 in standalone uses Electron ABI
Add afterPack hook that copies the @electron/rebuild-compiled
better_sqlite3.node into the standalone resources directory.
Previously the standalone copy retained the system Node ABI from
next build, causing MODULE_VERSION mismatch at runtime.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-07 13:31:54 +08:00
xuxu777xuandClaude Opus 4.6 3ae44a7277 feat: add Windows drive switcher dropdown in FolderPicker
When navigating to a drive root on Windows (e.g. C:\), path.dirname
returns itself, disabling the "go up" button and trapping the user on
that drive. This adds a compact dropdown next to the up button that
lists all available drives (auto-detected via fs.accessSync), allowing
quick switching between drives. macOS/Linux are unaffected (empty array,
dropdown not rendered).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-07 13:29:59 +08:00
7418andClaude Opus 4.6 262b295f63 fix: use stable ~/.codepilot/ data directory to persist across updates
Previously the database path depended on app.getPath('userData') which
varies with app name changes (CodePilot vs codepilot vs Claude GUI).
Now uses a fixed ~/.codepilot/ directory for both dev and production.

Includes automatic migration: on first launch, if the DB doesn't exist
at the new path, it checks old locations (Application Support variants
and the old dev-mode data/ folder) and copies the database over.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-07 13:07:08 +08:00
7418andClaude Opus 4.6 d2a926b353 docs: add CodePilot icon to README titles
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-07 11:35:51 +08:00
7418andClaude Opus 4.6 1ef7616991 chore: bump version to 0.2.1
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-07 11:13:42 +08:00
7418andClaude Opus 4.6 bd818afeee feat: add copy button on hover for user and assistant messages
Shows a copy icon at the bottom of each message on hover. Clicking
copies the text content to clipboard with a brief checkmark confirmation.
User messages show the button right-aligned; assistant messages show it
alongside the existing timestamp and token usage.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-07 11:09:50 +08:00