Commit Graph
100 Commits
Author SHA1 Message Date
abel533andCopilot bd375e6b15 fix+test: code quality improvements + 87 unit tests
Fixes:
- Resource leaks: process cleanup in BashTool, GrepTool, NotificationService
- Input validation: null/blank checks in BashTool, FileEditTool, GrepTool
- Path traversal: FileEditTool blocks ../ escape from workDir
- Thread safety: AgentLoop messageHistory now synchronizedList
- Error handling: log instead of silently swallow exceptions
- Bounds validation: RateLimiter constructor validates all params

Tests (87 total):
- TokenEstimationServiceTest: 14 tests (estimation, cost, formatting)
- RateLimiterTest: 12 tests (limits, cooldown, reset, concurrent)
- InternalLoggerTest: 12 tests (levels, structured, file output, export)
- NotificationServiceTest: 6 tests (config, disabled mode)
- FileEditToolTest: 8 tests (validation, traversal, core edit)
- BashToolTest: 9 tests (validation, dangerous commands, metadata)
- GrepToolTest: 5 tests (validation, metadata)
- Phase4CommandsTest: 21 tests (all Phase 4B+4D command metadata)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-05 11:48:00 +08:00
abel533andCopilot dd47566cb8 feat: Phase 4C infrastructure services + 4D debug commands
4C Services:
- RateLimiter: sliding window rate limiting, concurrent semaphore, cooldowns
- TokenEstimationService: approximate token counting, cost estimation
- NotificationService: cross-platform desktop notifications
- InternalLogger: structured session logging with export

4D Debug Commands:
- /debug: toggle debug mode, view internal logs
- /heapdump: JVM heap dump and memory pool info (Java advantage)
- /trace: request/response tracing
- /ctx-viz: context window token distribution visualization
- /reset-limits: reset rate limits and cooldowns
- /sandbox: sandbox mode toggle (strict/permissive/none)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-05 11:36:35 +08:00
abel533andCopilot d09809e924 feat: 12 UX commands - brief, vim, theme, usage, tips, env, perf, etc (Phase 4B)
New commands:
- /brief: toggle concise output mode
- /vim: toggle vi-mode editing
- /theme: switch color theme (dark/light/auto)
- /usage: detailed token/cost breakdown with visual bar
- /tips: usage tips (random or /tips all)
- /output-style: output format (markdown/plain/json)
- /env: environment variables, config paths, system info
- /performance (/perf): memory, threads, GC, session metrics
- /privacy: telemetry/logging/memory opt-out settings
- /feedback: save feedback to ~/.claude-code-java/feedback/
- /release-notes (/changelog): version history
- /keybindings (/keys): keyboard shortcuts reference

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-05 11:31:22 +08:00
abel533andCopilot d65d63038f feat: LSPTool, BriefTool, NotificationTool (Phase 4A)
- LSPTool: goto_definition, find_references, hover, diagnostics, document_symbols
  Wraps LSPServerManager.sendRequest() with JsonNode response formatting
- BriefTool: enable/disable/toggle/status for brief output mode via ToolContext
- NotificationTool: cross-platform notifications (Windows toast, macOS osascript,
  Linux notify-send) with terminal bell fallback
- Registered all 3 in AppConfig (total: 31 tools)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-05 11:27:30 +08:00
abel533andCopilot 12557f23f0 feat: Plugin marketplace - manifest, installer, auto-update, marketplace (Phase 3E)
- PluginManifest: manifest.json record with validation, DeclaredTool/Command/Hook, MarketplaceEntry
- PluginInstaller: HTTP download, JAR install/uninstall, version management, update checking
- MarketplaceManager: remote catalog fetch with 24h cache, search/filter/popular queries
- PluginAutoUpdate: scheduled update checks, parallel check, auto-install option, notification callback
- Enhanced /plugin command: install/remove/update/search subcommands (was: load/unload/reload/info)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-05 10:36:10 +08:00
abel533andCopilot 76191f5035 feat: Basic telemetry - feature flags, metrics, feature gates (Phase 3D)
- FeatureFlagService: local JSON config with env override, hot reload, typed accessors
- MetricsCollector: session metrics (tools, commands, tokens, errors), daily JSON persistence
- FeatureGate: connects flags to tool/feature enable checks with status reporting
- Default flags for all major features (server, worktree, LSP, coordinator, etc.)
- Metrics flushed to ~/.claude-code/metrics/{date}.json

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-05 10:32:30 +08:00
abel533andCopilot 293dd5657c feat: LSP integration - client, server manager, diagnostic registry (Phase 3C)
- LSPClient: JSON-RPC over stdio with Content-Length framing
- LSPServerInstance: single server lifecycle with lazy startup and crash recovery
- LSPServerManager: multi-server routing by file extension, file sync (didOpen/didChange/didSave/didClose)
- LSPDiagnosticRegistry: batch+cross-turn dedup, per-file/total limits, severity sorting
- LSPServerConfig: server config record with extension-to-language mapping
- Features: exponential backoff for content-modified errors, LRU cache for delivered diagnostics,
  handler registration before connection ready, formatForContext() for agent injection

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-05 10:30:25 +08:00
abel533andCopilot dcba6c86ae feat: Git Worktree isolation tools (Phase 3B)
- WorktreeManager: full lifecycle with slug validation, symlinks, stale GC
- EnterWorktreeTool: create/resume worktree with auto-slug generation
- ExitWorktreeTool: keep or remove with uncommitted change safety
- Slug validation: max 64 chars, [a-zA-Z0-9._-] only, path traversal prevention
- Symlink support for large directories (node_modules, dist, etc.)
- Stale agent worktree cleanup with ephemeral pattern matching
- Fast resume via direct .git pointer file read (no subprocess)
- Registered both tools in AppConfig (total: 28 tools)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-05 10:23:37 +08:00
abel533andCopilot b98675f643 feat: Server Mode with WebSocket direct connect (Phase 3A)
- DirectConnectServer: lifecycle management, auth token, port config
- DirectConnectWebSocketHandler: WebSocket handler with session management
- ServerSession: per-connection AgentLoop with permission forwarding
- ServerMessage: 7-type JSON protocol (user/assistant/result/control/interrupt/keep_alive/error)
- ServerModeAutoConfiguration: conditional Spring config with @EnableWebSocket
- WebSocketServerConfig: endpoint registration and container settings
- ClaudeCodeApplication: --server flag detection, web-application-type override
- ClaudeCodeRunner: skip TUI in server mode, block on shutdown signal
- pom.xml: added spring-boot-starter-websocket dependency

Server mode: --server [--server-port=12321] [--server-token=xxx]
Env vars: CLAUDE_CODE_SERVER_MODE, CLAUDE_CODE_SERVER_PORT, CLAUDE_CODE_SERVER_TOKEN

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-05 10:18:57 +08:00
abel533andCopilot a926b31e34 feat: /doctor, /session, /agent, /rename commands (Phase 2F)
- /doctor: environment diagnostics (Java, Git, API keys, disk, memory)
- /session: session info, save/load/export functionality
- /agent: list/detail/stop sub-agents and workers
- /rename: session naming with clear/reset support
- Registered all 4 commands in AppConfig

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-05 09:56:49 +08:00
abel533andCopilot 5a6798540a feat: MCP enhancements - HTTP+SSE transport, resource tools, env vars (Phase 2E)
- HttpSseTransport: HTTP POST + SSE streaming for modern MCP servers
- ListMcpResourcesTool: browse MCP server resources by server/URI
- ReadMcpResourceTool: read MCP resource content with auto-routing
- McpManager: environment variable expansion (\) in config
- McpManager: HTTP server support via 'url' field in mcp.json
- Registered both resource tools in AppConfig (total: 26 tools)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-05 09:53:07 +08:00
abel533andCopilot 758d0d2980 feat: Coordinator Mode with SendMessageTool (Phase 2D)
- CoordinatorMode: env-var activation, system prompt, tool filtering
- SendMessageTool: direct message, broadcast, message queuing
- Coordinator allowed tools: Agent, SendMessage, TaskStop, TaskGet, TaskList, TaskOutput
- Worker allowed tools: Read, Write, Edit, Bash, Grep, Glob, etc.
- AppConfig: coordinator mode detection, specialized system prompt
- Registered SendMessageTool in ToolRegistry

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-05 09:50:09 +08:00
abel533andCopilot 6e49c4fdc7 feat: SessionMemory service with post-sampling hook integration
- SessionMemoryService: threshold-based memory extraction (50K init, 20K update)
- Async extraction via virtual threads with forked agent
- Post-sampling hook in AgentLoop after each model response
- System prompt injection of existing session memory
- /memory session sub-command to view session memory
- AppConfig wiring: bean registration, agent factory, AgentLoop hook

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-05 09:44:28 +08:00
abel533andCopilot 6088678c4f feat: Skills execution system (Phase 2B)
- SkillTool: execute skills by name via forked sub-agent
- BundledSkills: 4 built-in skills (verify, debug, review, commit)
- SkillLoader: bundled skills auto-loaded + budget-aware prompt listing
- /skills command: detail view with /skills <name>
- Budget management: 8K char budget, 250 char per-entry cap

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-05 09:39:29 +08:00
abel533andCopilot cb76b267f1 feat: Plan Mode implementation (Phase 2A)
- EnterPlanModeTool: switch to read-only mode with plan file path management
- ExitPlanModeTool: restore permissions and validate plan content
- PermissionRuleEngine: plan file edit exception in PLAN mode
- SystemPromptBuilder: 5-phase plan workflow instructions injection
- /plan command: toggle plan mode from command line
- Plan file stored at ~/.claude/projects/[path]/PLAN.md

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-05 09:35:44 +08:00
abel533andCopilot bd98dea6b3 feat: console rendering enhancements (Phase 1B.4)
- MarkdownRenderer: table parsing and box-drawing character rendering
- ToolStatusRenderer: permission dialog beautification, progress bar, duration tracking
- SpinnerAnimation: multiple animation styles, elapsed time display, stopAndGetElapsed()

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-05 09:24:04 +08:00
abel533andCopilot 95b45940fd feat: command layer enhancements (Phase 1B.3)
- /help: keyword search + command detail view
- /compact: --stats for token statistics, --aggressive for deeper compaction
- /commit: --push to push after commit, --pr to create PR via gh CLI
- /files: directory tree with depth control, file pattern search
- /permissions: view current permission mode and rules
- /tasks: list background tasks with status, age, result preview

Total commands: 28 → 31

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-05 09:20:44 +08:00
abel533andCopilot 05e6e019b2 feat: BashTool sandbox, ConfigTool persistence, ToolSearchTool
- BashTool: command blacklist (fork bombs, rm -rf /, etc) + risky
  command warning log. Blocked commands return clear error message.
- ConfigTool: JSON file persistence (~/.claude-code/config.json),
  new 'list' action, loads from file on first access.
- ToolSearchTool: search ToolRegistry by name/description keywords,
  returns matching tools with descriptions (total: 23 tools).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-05 09:16:12 +08:00
abel533andCopilot f5da3499a4 feat: FileReadTool image support + FileEditTool unified diff output
- FileReadTool: detect image files (png/jpg/gif/webp/svg/bmp/ico),
  read as Base64 with MIME type, 20MB size limit
- FileEditTool: generate unified diff after edits with 3-line context,
  showing removed (-) and added (+) lines in standard diff format

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-05 09:12:31 +08:00
abel533andCopilot d9b8c795b6 feat: add TaskStopTool, TaskOutputTool, and SleepTool
- TaskStopTool: cancel running tasks via TaskManager.cancelTask()
- TaskOutputTool: retrieve task results with status-aware formatting
- SleepTool: Thread.sleep() with 5-minute max and interrupt support
- Registered all 3 tools in AppConfig (total: 22 tools)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-05 09:09:18 +08:00
abel533andCopilot 08ebc72416 feat: enhance GrepTool with output_mode, case_insensitive, multiline, context lines
Add 7 new parameters to match TS GrepTool capabilities:
- output_mode: content/files_with_matches/count (3 modes like TS)
- case_insensitive: -i flag support
- multiline: cross-line pattern matching (ripgrep only)
- context_before/context_after: -B/-A context lines
- type: file type filter (e.g., 'java', 'py') for ripgrep
- head_limit: configurable result limit (was hardcoded 100)

All parameters correctly wired to rg, grep, and findstr backends.
Description updated with output mode documentation and escaping notes.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-05 09:07:23 +08:00
abel533andCopilot c5440a2b4c feat: enhance system prompt and tool descriptions to match TS version
Phase 1A implementation:

SystemPromptBuilder.java (142 lines -> ~290 lines):
- Add CyberRisk security boundary instruction
- Add System section (permission modes, prompt injection defense)
- Add Doing Tasks section (coding style, security, collaboration)
- Add Actions section (operation risk management, dangerous ops protection)
- Add Tone & Style section (emoji control, concise output, code references)
- Add Output Efficiency section (direct communication)
- Add Language preference support
- Restructure into modular section builder methods matching TS architecture

Tool description enhancements (8 tools):
- BashTool: add security boundaries, git best practices, no-substitute rule
- FileWriteTool: add must-Read-first rule, prefer-Edit guidance
- GrepTool: add never-use-Bash-grep rule, search guidance
- AgentTool: add when-to-use/not-use guidance, sub-prompt enhanced
- FileEditTool: add indentation preservation, prefer-edit-existing rule
- TodoWriteTool: add proactive usage guidance, state machine rules
- TaskUpdateTool: add status workflow documentation
- ConfigTool: add available settings list

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-05 09:06:04 +08:00
abel533andCopilot 3b47c5e818 feat: cursor movement in input field
- Left/Right arrow keys move cursor within text
- Home/End jump to line start/end
- Insert text at cursor position (not just at end)
- Backspace/Delete work at cursor position
- Paste inserts at cursor position
- History browsing sets cursor to end
- Visual cursor: inverse style on character under cursor
- Hide terminal hardware cursor in normal input (use rendered cursor)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-04 21:43:40 +08:00
abel533andCopilot 8946ca93f2 feat: dynamic terminal title matching official Claude Code behavior
- Title updates on every user message (not just the first)
- Shows current tool name during execution: '⠂ Bash · user topic'
- Animation pauses during permission prompts (matches isWaitingForApproval)
- Clears tool name when tool completes
- Priority: sessionTitle (from user input) > 'Claude Code' (fallback)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-04 21:28:09 +08:00
abel533andCopilot d63a10c221 fix: hide cursor during selection mode and agent execution
- Permission selection: cursor hidden (❯ marker indicates selection)
- AskUser selection: cursor hidden (same reason)
- Agent running: cursor hidden (no text input needed)
- AskUser input mode: cursor still visible at text position
- Normal idle: cursor visible at input position

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-04 21:12:18 +08:00
abel533andCopilot f05732a60c fix: terminal title uses jink writeRaw instead of raw PrintStream
Terminal title now writes OSC 0 through Ink.Instance.writeRaw()
which goes directly to the JLine terminal. This eliminates garbled
characters caused by writing through intercepted System.out/err or
to streams that bypass the terminal's ANSI processing.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-04 20:27:15 +08:00
abel533andCopilot ecb88b25a0 fix: restore header border, defer title init, fix title encoding
- Restore bordered headerBox as single scrollable item in messagesArea
- Defer terminal title init to first render() (after jink ready)
- Title uses ConsolePatcher.getOriginalOut() to bypass interception
- Ctrl+C fix in jink: INT signal handler now respects exitOnCtrlC flag

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-04 20:18:34 +08:00
abel533andCopilot db3de65c3c fix: header scrolls with messages, auto-scroll pauses on scroll-up
- Header/logo moved from fixed layout to messagesArea first items
  (matches official LogoHeader behavior: scrolls with messages, not pinned)
- addMessageInternal preserves scrollOffset when user has scrolled up
  (matches official sticky-scroll: only auto-scrolls when at bottom)
- Terminal title uses ConsolePatcher.getOriginalOut() to bypass interception

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-04 20:08:08 +08:00
abel533andCopilot 4523e7e4d3 fix: markdown ####, Ctrl+C exit bug, terminal title
- MarkdownToText: support heading levels 1-6 (was 1-3, causing #### raw display)
- Ctrl+C: agent cancel no longer starts exit window (matching official double-press flow)
- Terminal title: dynamic OSC 0 title with animated spinner during work, static idle prefix
  - Matches official useTerminalTitle hook + AnimatedTerminalTitle component
  - Session title inferred from first user message (simplified vs AI generation)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-04 19:55:20 +08:00
abel533andCopilot 43e62fb8fc feat: 增强系统提示词 — 对齐官方工具使用指南
添加 'Using your tools' 段落(匹配官方 Claude Code):
- 专用工具优先于 Bash(FileRead/FileEdit/Glob/Grep)
- WebSearch/WebFetch 主动使用指令:遇到实时信息需求时
  必须使用 WebSearch,不要说无法获取实时信息
- 并行工具调用指导
- TodoWrite 任务管理指导

解决 AI 不主动使用 WebSearch 工具的问题

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-04 19:41:21 +08:00
abel533andCopilot 54c3cb41a9 feat: 工具执行流式输出预览
- ToolEvent 新增 PROGRESS 阶段,工具可在执行中报告进度
- ToolContext 添加 progressCallback,工具可通过 reportProgress() 报告输出行
- BashTool 在读取每行输出时实时报告进度
- AgentLoop 在工具执行前设置进度回调,执行后清除
- ToolCallMsg 支持 outputLines 字段,保留最后 5 行流式预览
- 运行中的工具在消息区显示实时输出(灰色,截断至 120 字符)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-04 19:22:35 +08:00
abel533andCopilot 012d5dfae6 feat: 添加 Ctrl+R 反向历史搜索
- Ctrl+R 进入搜索模式,输入关键词实时过滤历史记录
- 输入区显示 bash 风格搜索提示: (reverse-i-search)\query': result
- 再按 Ctrl+R 搜索更旧的匹配项
- Enter 选定结果放入输入框,Esc 退出搜索
- 快捷键栏显示搜索模式操作提示

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-04 19:15:45 +08:00
abel533andCopilot 6c5580ccd7 feat: 添加斜杠命令 Tab 自动补全
- 输入 / 开头时,前缀匹配所有已注册命令
- Tab 键补全唯一匹配,多个匹配时循环选择
- 输入区显示 ghost text(灰色补全后缀提示)
- 快捷键栏显示匹配命令列表(最多5个)
- 当前 Tab 选中项高亮显示
- Backspace/Esc/Submit 时同步更新建议列表

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-04 19:13:24 +08:00
abel533andCopilot f995a34d66 feat: 对齐官方快捷键和动画行为
Phase A (快速修复):
- Ctrl+C 双击窗口从 2000ms 改为 800ms(匹配官方)
- 添加 Ctrl+L 强制重绘
- 添加 Ctrl+Home/End 跳到顶部/底部

Phase B (动画改进):
- Thinking 显示持续时间: 'Thinking...' → 'Thinking (5s)...'
  (2秒后开始显示时间,匹配官方行为)
- Processing 显示输出 token 计数
- 底部自动滚动已正确实现(新消息 scrollOffset=0)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-04 19:06:34 +08:00
abel533andCopilot 99a4ccf059 feat: 块光标 + 动画移至消息区 + 权限交互选择
块光标:
- 输入区使用 █ 块光标(匹配原版 Claude Code 风格)
- Agent 运行中输入区只显示 ❯ █

动画效果:
- 思考/处理动画从输入区移至消息区底部
- 使用旋转帧 ◐◓◑◒ + Thinking.../Processing... 文字
- Agent 运行中快捷键栏显示 'esc to interrupt'

权限确认:
- 从 Y/A/N/D 文本输入改为交互选择模式
- 3个选项:Yes / Yes, and don't ask again / No
- 支持 ↑↓ 选择、Enter 确认、Esc 取消、1-3 快捷选择
- Tool use 消息显示蓝色分隔线 + 工具详情
- 新增 requestTextInput() 用于无选项的简单文本输入

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-04 18:51:21 +08:00
abel533andCopilot 5ad2628b1a feat: Ctrl+C 双击退出(匹配原版 Claude Code 行为)
- 第一次 Ctrl+C: Agent 运行中则取消任务,空闲时清空输入
- 第二次 Ctrl+C (2秒内): 退出应用
- 快捷键栏显示 'Press Ctrl-C again to exit' 黄色提示
- 2秒超时后自动清除提示(虚拟线程定时)
- 移除未使用的 cmdCount 字段
- 保留 Esc 中断和 Ctrl+D 退出作为备选

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-04 18:43:17 +08:00
abel533andCopilot a20dffa7a0 fix: 改进滚动 maxOffset 计算
使用 totalItems - visibleLines 替代 totalItems - 1
避免滚动到只剩1行内容的极端情况

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-04 18:35:10 +08:00
abel533andCopilot a30dfa9ad0 fix: 修复滚动限制 + 自动检测Shell类型
滚动修复:
- scroll() 使用实际渲染行数而非消息数计算 maxOffset
- 解决 /help 等多行输出无法滚动到顶部的问题

Shell 检测:
- Windows 自动检测 PowerShell 7+ > Windows PowerShell > cmd.exe
- 动态调整 BashTool 描述,告知AI使用正确的命令语法
- 系统提示词包含详细的 Shell 使用指南(PowerShell cmdlets)
- header 显示检测到的 Shell 类型
- Unix 优先 bash,回退 sh

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-04 18:33:42 +08:00
abel533andCopilot e47a3445df fix: 修复代码审查发现的线程安全和边界问题
- render() 中对 volatile 字段取快照,避免跨线程竞争
- 光标位置 clamp 到 >= 0,防止小终端越界
- spinner 线程使用独立 spinnerLock 保护启停操作
- PrintStream 使用 try-with-resources 避免资源泄漏
- 终端高度 < 20 时隐藏标题框腾出空间

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-04 17:44:32 +08:00
abel533andCopilot d4f9c8104f enhance: 改进取消机制 — 流式token和工具调用中也检查cancelled
- streamIteration 中 token 回调检查 cancelled 标志
- executeToolCalls 中每个工具调用前检查 cancelled
- 被取消的工具调用返回 'Cancelled by user'

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-04 17:40:22 +08:00
abel533andCopilot 1b53357ded feat: Ctrl+C 中断 Agent 运行(而非退出应用)
- 使用 Ink.render(component, false) 禁用默认 Ctrl+C 退出
- Ctrl+C 在 Agent 运行中触发 cancel(),停止当前循环
- Ctrl+C 在空闲时清空输入
- 保留 Ctrl+D 作为退出快捷键

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-04 17:38:14 +08:00
abel533andCopilot ffb94bb2f7 feat: 添加 Escape/Ctrl+C 中断 Agent 运行功能
- AgentLoop 添加 cancel()/resetCancel() 中断机制
- executeLoop 在每次迭代前和API调用后检查取消标志
- Escape 键和 Ctrl+C 在 Agent 运行时触发中断
- 快捷键栏更新提示

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-04 17:34:55 +08:00
abel533andCopilot 91190e180b ui: 改进消息显示,添加空行分隔和更友好的初始提示
- 初始消息改为 Ready 提示(header已包含工具/命令信息)
- 用户消息前添加空行分隔,提升对话可读性
- 保持工具调用和系统消息紧凑展示

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-04 17:32:17 +08:00
abel533andCopilot f28d2328ef refactor: 权限/AskUser回调改为虚拟线程执行,避免锁竞争
- handlePermissionInput 回调在虚拟线程中执行
- confirmAskUser 回调在虚拟线程中执行
- 移除 confirmAskUser 中多余的 synchronized 嵌套

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-04 17:28:57 +08:00
abel533andCopilot 7199b4f2dd fix: 修复消息区溢出布局问题,恢复Spacer弹性空白
- 消息区添加 .height(maxMessageLines) + .overflow(HIDDEN) 防止溢出
- 恢复 Spacer.create() 在消息少时填充空白
- AskUser工具添加调试日志帮助排查结构化回调

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-04 17:25:47 +08:00
abel533andCopilot 65bd5b5d9a feat: interactive AskUser with arrow-key selection
- Add interactive option selection for AskUserQuestion tool
  (arrow keys ↑↓, Enter confirm, 1-9 quick select, Esc cancel)
- Last option with '其他/Other' enters free text input mode
- New ASK_USER_STRUCTURED_CALLBACK in AskUserQuestionTool
  accepts (question, options) BiFunction for structured interaction
- ClaudeCodeComponent renders option list with ❯ indicator
- Cursor position adjusts for variable-height ask area
- Falls back to simple text prompt when no options provided

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-04 16:03:23 +08:00
abel533andCopilot 2f645b9d85 enhance: improve header colors, streaming markdown, scroll preservation
- Header: use colored values (API cyan, model green, dir yellow, etc.)
- Markdown: render progressively during streaming (not just after completion)
  - Streaming cursor appended to last rendered line
- Scroll: preserve user scroll offset during streaming token updates
  - Previously reset to 0 on every token, now keeps user position
- All process info (tool calls, thinking) persists after completion

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-04 15:51:23 +08:00
abel533andCopilot 9a437889b7 enhance: ASCII logo header, thinking animation, markdown rendering
- Restore original ASCII coffee cup logo in header (dual-column layout)
- Fix shortcutBar to single line with height(1) constraint
- Add spinning animation for thinking indicator (◐◓◑◒ cycle at 120ms)
- Create MarkdownToText converter for assistant messages:
  - Headers (# ## ###) with distinct colors and prefixes
  - Bold (**text**) rendering
  - Inline code (\code\) in yellow
  - Code blocks with language label and │ prefix
  - Ordered/unordered lists with bullet points
- Streaming messages show raw text; completed messages use markdown

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-04 15:42:53 +08:00
abel533andCopilot b72fcfea79 fix: add thread safety for concurrent state modifications
- Add stateLock to synchronize all getState/setState read-modify-write
  operations across UI thread and AgentLoop background threads
- Synchronize onInput, onPaste, addMessage, appendToStreamingMessage,
  finishStreamingMessage, completeLastToolCall, setThinking, runAgent
- Extract addMessageInternal() to avoid double-locking
- Harden extractToolSummary with explicit indexOf checks

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-04 15:08:04 +08:00
abel533andCopilot 75ecaeca58 enhance: improve tool call display with smart arg extraction
- Add extractToolSummary() to show human-readable tool arguments
  (command: $ ..., file_path: path, pattern: ..., query: ...)
- Tool running state shows 'running...' suffix
- Tool completed state shows 'done' suffix
- Match original Claude Code tool status rendering style

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-04 15:03:23 +08:00
abel533andCopilot 02ab8c2777 enhance: improve assistant message rendering and console patching
- Split multi-line assistant messages into separate rendered lines
- Add streaming cursor (▌) indicator for in-progress responses
- Add patchConsole() to intercept System.out/err during TUI mode
- Handle empty assistant message edge case

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-04 15:02:04 +08:00
abel533andCopilot 45283c87e4 fix: improve command handling and add paste support
- Add ToolRegistry to ClaudeCodeComponent for proper command context
- Use ByteArrayOutputStream to capture command output in TUI mode
- Add onPaste() override for efficient multi-line paste handling
- Fix constructor to accept toolRegistry parameter

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-04 15:00:29 +08:00
abel533andCopilot 199ad6259b refactor: cleanup unused imports, add conversation summary tracking
- Remove unused MarkdownRenderer import and field from ClaudeCodeComponent
- Add onFirstUserInput callback for conversation summary tracking
- Wire conversation summary in JinkReplSession

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-04 14:57:05 +08:00
abel533andCopilot 601a1c9ea9 feat: add jink TUI framework integration
- Add jink dependency (io.mybatis.jink:jink:0.3.0-SNAPSHOT)
- Create UIMessage sealed interface for TUI message model
- Create ClaudeCodeComponent (main jink Component with full layout)
  - Header box with rounded magenta border
  - Message list with virtual scrolling
  - Separator lines above/below input area
  - Input area with prompt and placeholder
  - Status bar and shortcut key bar
- Create JinkReplSession (jink-based REPL replacing JLine readLine loop)
  - AgentLoop integration via callbacks -> setState
  - Permission confirmation inline in TUI
  - Streaming token display
- Update ClaudeCodeRunner to prefer jink TUI with legacy fallback
- Update AppConfig with JinkReplSession bean

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-04 14:52:55 +08:00
abel533andCopilot f9072534ef feat: jlink打包脚本 - 创建最小JRE发行版(Windows/Linux/macOS)
- packaging/build-dist.ps1: PowerShell跨平台构建脚本
- packaging/build-dist.sh: Bash构建脚本
- BUILD.md: 完整构建安装指南
- 自动jdeps分析 + jlink精简JRE(~49MB)+ fat jar + 启动脚本
- 发行包约120MB,免安装JDK直接运行
- 删除旧run.bat/run.ps1

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-03 00:27:40 +08:00
liuzhandCopilot 2d704cc014 docs: 更新README - 添加三层压缩和多级权限管理功能说明
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-02 23:29:23 +08:00
liuzhandCopilot fa565d8c07 feat: 压缩和权限gap功能增强 - PTL gap解析, 时间感知微压缩, token估算安全系数, PLAN模式, 拒绝追踪
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-02 23:17:29 +08:00
liuzhandCopilot 730551cb3f feat: 多层上下文压缩 + 多级权限管理系统
权限管理:
- PermissionTypes: 权限行为/模式/规则/决策/选择类型系统
- PermissionSettings: 用户级/项目级/会话级权限持久化(settings.json)
- PermissionRuleEngine: 多层规则引擎(deny→allow→readOnly→mode→dangerous→ASK)
- DangerousPatterns: 危险shell命令检测(rm -rf, eval, exec等)
- ReplSession: Y/A/N/D四选项权限确认UI
- ConfigCommand: permission-mode/list/reset子命令
- AgentLoop: 集成规则引擎,PermissionChoice回调

上下文压缩:
- TokenTracker: 上下文窗口监控(93%自动压缩/82%警告/98%阻塞)
- MicroCompact: 微压缩,裁剪旧tool_result(无API调用)
- SessionMemoryCompact: Session Memory压缩,AI摘要旧消息保留近期段
- FullCompact: 全量压缩+PTL重试(按API Round逐步丢弃)
- AutoCompactManager: 压缩编排器(micro→session→full),含熔断机制
- CompactCommand: 改造为委托FullCompact
- StatusLine: token使用百分比+颜色告警(绿→黄→红→闪烁)
- AppConfig: 注册PermissionSettings/RuleEngine/AutoCompactManager Bean

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-02 23:05:37 +08:00
liuzh c989d3b451 docs: 添加仓库分支说明,包含 main/claude/learn 三个分支的介绍和链接 2026-04-02 20:59:13 +08:00
liuzhandCopilot d17beb8a85 fix: 工具调用前刷新流式行缓冲 - 修复AI文本丢失
- lineBuffer/mdState提升为实例字段(工具事件回调可访问)
- 工具START事件先flushStreamLineBuffer()再渲染工具状态
- 修复: AI在工具调用前发送的文本(无\\n结尾)现在正确显示

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-02 01:29:52 +08:00
liuzhandCopilot b2066c0cc7 feat: 流式Markdown渲染 - 行缓冲+ANSI样式输出
- MarkdownRenderer新增StreamState和renderStreamingLine()方法
- 流式输出改为行缓冲模式:累积token到换行再渲染输出
- 支持:粗体/斜体→ANSI样式, 代码块→语法高亮边框,
  列表→●圆点, 标题→彩色, 引用→竖线, 链接→下划线
- 代码块状态跨行追踪(StreamState)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-02 01:20:28 +08:00
liuzhandCopilot 2e8e1eb819 fix: TodoWriteTool标记为readOnly - 内存操作无需权限确认
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-02 01:13:53 +08:00
liuzhandCopilot 86a47282cf fix: CLI交互样式优化 - 参考Claude Code/Copilot CLI效果
- 移除输入框横线(readLine阻塞限制,无法实现上下同时显示)
- ● 前缀移至 onStreamStart 回调(避免被 spinner 覆盖)
- 每段 AI 文本都获得独立的 ● 前缀(工具调用后续文也有)
- 工具 START 事件确保换行后再渲染(避免与AI文本混行)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-02 01:08:29 +08:00
liuzhandCopilot 3c852d4446 fix: 工具调用后续文本缩进 - streamNewLine字段共享状态
- 将 isNewLine 局部变量提升为 streamNewLine 实例字段
- 工具 START/END 事件回调中同步标记换行状态
- 确保工具调用后的 AI 续文也有 4 空格缩进对齐

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-02 00:53:17 +08:00
liuzhandCopilot e3f60a5933 fix: CLI交互优化 - 流式缩进+输入框横线+日志降噪
- 流式输出: ● 标识与文本同行,续行4空格缩进对齐
- 输入框: 上下横线(─)分隔输入区域,宽度自适应终端
- 日志: 工具异常日志降为debug级别,避免终端输出stack trace

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-02 00:44:58 +08:00
liuzhandCopilot 1e35cbe222 docs: 更新文档 - CLI样式升级+i18n+修复重复章节
- 修改记录.md: 新增CLI视觉样式升级+i18n英文统一条目
- 需求文档.md: 工具/命令数量更新为18/28, 新增CLI样式和i18n状态, 删除重复的表格数据

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-02 00:35:37 +08:00
liuzhandCopilot ff734d6b0d i18n: 全部用户可见字符串统一为英文(46个文件)
- 所有Command/Tool/Core/MCP/Plugin中的中文提示改为英文
- Javadoc注释和行内注释保留中文不变
- AI提示词(compact/commit/review等)改为英文
- 编译验证通过

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-02 00:30:47 +08:00
liuzhandCopilot 1172ab6b08 fix: 命令描述统一为英文+修复/history双斜杠bug
- CompactCommand: 中文描述改为英文
- HistoryCommand: 中文描述改为英文 + name()去掉多余的/前缀

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-02 00:04:01 +08:00
liuzhandCopilot 1e84fb79a9 chore: 将TODO.md移出版本控制并加入.gitignore
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-02 00:01:23 +08:00
liuzhandCopilot 831461aff0 fix: /help命令动态展示全部28个已注册命令
- CommandContext增加commandRegistry字段
- HelpCommand从registry动态获取命令列表(不再硬编码6个)
- 自动对齐命令名称,附显示别名

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-02 00:01:11 +08:00
liuzhandCopilot 031a868286 fix: Banner布局微调 - Logo缩1字符+API URL展示+Provider改为Protocol
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-01 23:56:17 +08:00
liuzhandCopilot d8a7171325 fix: Banner边框上下对齐 - 加入ANSI可见宽度计算+右侧闭合│+精确padding
- 顶部边框公式修正: innerWidth - titleVisibleLen
- 每行body加右侧闭合│边框
- visibleLength()去除ANSI转义计算真实宽度
- 右侧信息区域自动pad到固定宽度
- Logo宽度调整为20字符

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-01 23:50:48 +08:00
liuzhandCopilot e7eb5e33b1 fix: Banner Logo改为纯ASCII冒烟咖啡杯,修复emoji导致的边框对齐问题
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-01 23:46:46 +08:00
liuzhandCopilot c52d5313a2 style: CLI视觉样式升级 - 边框Banner+●圆点+⎿结果+耗时显示
- BannerPrinter: 带边框的启动Banner(╭╮╰╯框线+咖啡杯Logo+双列布局)
- ToolStatusRenderer: 彩色●圆点标识+⎿结果前缀(Claude Code风格)
- ThinkingRenderer: <thought>标签块显示(Copilot CLI风格)
- ReplSession: AI回复●前缀+✻耗时显示+智能Banner选择

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-01 23:33:35 +08:00
liuzhandCopilot 1fc7a6a495 docs: 全面更新文档 - README/需求文档/修改记录
README.md:
- 功能特性分 P0/P1/P2 三级展示
- 工具列表更新为 18 个(含 P0/P2 工具)
- 命令列表更新为 28 个(分基础/P0/P1/P2 四组)
- 新增 MCP 服务器配置和使用说明
- 新增插件系统使用说明(JAR 加载、目录结构)
- 新增 Vim 模式和 Hook 系统使用说明
- 架构图更新:含 mcp/、plugin/、core/ 新组件
- 核心流程图更新:含 Hook 和权限确认
- 对应关系表新增 MCP/Plugin/Hook/Task 映射

需求文档.md:
- 5.1 实现清单更新为 18 工具 + 28 命令
- 5.2 P0/P1/P2 标记为全部已实现
- 仅保留 P3 跳过项目

修改记录.md:
- 新增 P0/P1/P2 四条修改记录(倒序排列)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-01 23:04:01 +08:00
liuzhandCopilot 79736cf16f feat: P2全部功能 - MCP协议+插件系统+任务管理+CLI增强
A组 CLI增强:
- DiffRenderer: 彩色diff渲染(行号/stat摘要/unified格式)
- /hooks: 查看已注册Hook列表
- /review: AI代码审查(支持--staged/文件路径)
- /stats: 会话使用统计(tokens/费用/API调用/运行时长)
- /branch: 对话分支管理(save/load/list/delete)
- /rewind: 回退对话历史
- /tag: 对话位置标签
- /security-review: AI安全审查

B组 任务系统:
- TaskManager: 后台任务管理(线程安全/自动执行/手动管理)
- TaskCreate/TaskGet/TaskList/TaskUpdate 4个工具
- ConfigTool: 配置读写工具

C组 MCP协议:
- McpClient: MCP客户端(JSON-RPC 2.0/工具发现/资源读取)
- McpTransport: 传输层接口
- StdioTransport: StdIO传输实现(子进程/异步读写)
- McpManager: 多MCP服务器管理(配置加载/生命周期)
- McpToolBridge: MCP工具桥接为本地Tool
- /mcp: MCP服务器管理命令

D组 插件系统:
- Plugin接口 + PluginContext + PluginManager
- JAR插件加载(ClassLoader隔离/Manifest读取)
- OutputStylePlugin: 内置输出样式插件
- /plugin: 插件管理命令

集成: AppConfig注册全部18工具+28命令

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-01 22:56:35 +08:00
liuzhandCopilot da26f02498 feat: P1完成 - Hook系统+Vim模式+Banner增强
- 新增 HookManager: 支持 PreToolUse/PostToolUse/PrePrompt/PostResponse 4种钩子
- Hook 优先级排序, PreToolUse 可中止工具执行, PostToolUse 可修改结果
- AgentLoop 集成 Hook 系统到工具调用流程
- ReplSession 支持 Vim 编辑模式 (CLAUDE_CODE_VIM=1 启用)
- Banner 显示命令数量和 Vim 模式标识
- 修复重复 isDumb 变量

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-01 22:32:49 +08:00
liuzhandCopilot 749062fba7 feat: P1功能增强 - 3命令+代码高亮+状态行
新增3个命令:
- /resume: 恢复已保存的对话(支持list/序号选择)
- /export: 导出对话为Markdown文件
- /commit: 创建Git commit(支持AI生成commit message)

代码语法高亮(MarkdownRenderer增强):
- 支持Java/JS/TS/Python/Bash/SQL关键字着色
- 字符串字面量黄色、数字紫色、注释灰色斜体
- 注解(@Annotation)亮黄色
- true/false/null 红色
- 新增引用块、有序列表、复选框、链接渲染
- 代码块边框对齐

底部状态行(StatusLine):
- 模型名、Token用量、费用、API调用次数、工作目录
- 非dumb终端自动启用
- 每次Agent循环后刷新显示

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-01 22:25:26 +08:00
liuzhandCopilot 82a28b7aa7 feat: P0功能补全 - 5命令+2工具+权限确认+Thinking显示
新增5个命令:
- /diff: 显示Git未提交变更(支持--staged/--stat)
- /version: 显示版本和环境信息
- /skills: 列出所有可用技能
- /memory: 查看/编辑CLAUDE.md(支持add/edit/user子命令)
- /copy: 复制最近AI回复到剪贴板

新增2个工具:
- WebSearchTool: DuckDuckGo搜索(免费,无需API Key)
- AskUserQuestionTool: AI向用户提问(通过ToolContext回调)

权限确认机制:
- 非只读工具执行前提示用户确认(Y/n/always)
- 支持always一次授权全部后续操作
- 在AgentLoop.executeToolCalls中拦截

Thinking内容显示:
- AgentLoop新增onThinkingContent回调
- 从ChatResponse metadata提取thinking内容
- ThinkingRenderer渲染思考过程(缩进暗色格式)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-01 22:06:57 +08:00
liuzhandCopilot 7dc4d142b3 docs: Phase6 完整README文档 + 修改记录更新
新增 README.md:
- 功能特性概览(11工具、11命令、双API、流式输出等)
- 快速开始指南(环境变量、启动方式)
- 完整使用说明(对话、多行输入、斜杠命令、工具、CLAUDE.md、Skills)
- 架构设计(模块结构图、核心流程、双Provider架构)
- 配置参考(application.yml、环境变量表)
- 开发说明(构建、打包、已知问题)
- TypeScript→Java 对应关系表

更新 修改记录.md:
- 补全 Phase 1~5 所有修改记录
- 每个Phase的详细变更说明和关联需求

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-01 21:45:23 +08:00
liuzhandCopilot 094057f0d2 feat: Phase5C+5D /compact AI摘要压缩 + 多行输入支持
/compact 增强:
- 用AI生成对话历史摘要替代简单清空
- 压缩后保留:原始系统提示 + AI摘要 + 最后一轮对话
- AI摘要保留关键决策、代码变更、文件路径等技术细节
- 摘要生成失败时静默降级(仅保留最近对话)

多行输入:
- 支持反斜杠(\\)续行:行末输入\\后回车继续下一行
- 续行提示符: '  ... '
- JLine SECONDARY_PROMPT_PATTERN 配置

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-01 21:38:01 +08:00
liuzhandCopilot 399cea4478 feat: Phase5B 对话历史持久化
新增 ConversationPersistence:
- 退出REPL时自动保存对话到 ~/.claude-code-java/conversations/
- JSON格式存储:系统消息、用户消息、助手消息(含工具调用)、工具响应
- 支持保存、加载最近对话、列出所有对话
- 文件名格式: yyyyMMdd_HHmmss_摘要.json

新增 /history 命令:
- 列出最近10条保存的对话记录
- 显示时间、摘要、消息数、工作目录

ReplSession 更新:
- 自动记录对话摘要(第一次用户输入前40字)
- JLine模式和Scanner模式退出时都保存对话

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-01 21:35:48 +08:00
liuzhandCopilot fd262bf98d feat: Phase5A 流式输出支持,逐token实时显示
AgentLoop 重构:
- 新增 runStreaming(input, onToken) 流式模式
- 使用 chatModel.stream(Prompt) -> Flux<ChatResponse>
- 统一 executeLoop() 核心循环支持阻塞/流式两种模式
- 流式分片工具调用按ID去重累积
- 流式失败自动降级到阻塞模式
- AssistantMessage 使用 Builder 模式构建(构造器是protected)
- 新增 onStreamStart 回调(第一个token到达时停止spinner)
- 新增 getChatModel() / replaceHistory() 方法(为后续compact准备)

ReplSession 更新:
- handleInput 使用 runStreaming 替代 run
- 逐token直接输出到终端(out.print + flush)
- spinner在第一个token到达时自动停止

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-01 21:31:38 +08:00
liuzhandCopilot de8349079f fix: ProviderInfo读取统一后的AI_MODEL环境变量
修复providerInfo() Bean中OpenAI分支仍读取旧变量名AI_OPENAI_MODEL的问题,
以及Anthropic分支仍读取ANTHROPIC_BASE_URL的问题。
现在两个分支都统一使用AI_BASE_URL和AI_MODEL。

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-01 21:15:11 +08:00
liuzhandCopilot 640822de19 refactor: 统一API环境变量命名,AI_API_KEY/AI_BASE_URL/AI_MODEL通用
两种Provider使用相同的环境变量,切换Provider只需改CLAUDE_CODE_PROVIDER:
- AI_API_KEY: API密钥(两种Provider通用)
- AI_BASE_URL: 基础URL(OpenAI默认api.openai.com,Anthropic默认api.anthropic.com)
- AI_MODEL: 模型名(OpenAI默认gpt-4o,Anthropic默认claude-sonnet-4-20250514)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-01 21:08:37 +08:00
liuzhandCopilot 2adbfa56bc feat: 支持OpenAI/Anthropic双API提供者切换,Banner显示URL和模型
通过 claude-code.provider 配置切换API提供者:
- openai(默认): 使用 OpenAI 兼容 API,支持各种代理服务
- anthropic: 使用 Anthropic 原生 API

配置方式:
- 环境变量: CLAUDE_CODE_PROVIDER=openai|anthropic
- application.yml: claude-code.provider

Banner 增强:
- 启动时显示当前 Provider、Model、API URL
- Scanner降级模式也显示同样信息

启动脚本更新:
- run.ps1/run.bat 添加完整的双provider配置说明

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-01 21:06:09 +08:00
liuzhandCopilot 7a6c2fcc02 feat: Phase4 命令系统与上下文增强
新增基础设施:
- TokenTracker: 真实Token使用量追踪和费用估算(按模型定价)
- SkillLoader: .claude/skills/ 扫描加载,支持YAML frontmatter元数据
- GitContext: Git分支/状态/最近提交收集,注入系统提示词

新增命令 (4个):
- /init: 项目CLAUDE.md初始化向导,自动检测项目类型(Maven/Gradle/Node/Python等)
- /status: 会话状态仪表板(模型、Token、内存、运行时间等)
- /context: 上下文概览(CLAUDE.md、Skills、Git、系统提示词大小)
- /config: 配置查看/设置(支持model快捷切换和API key显示)

增强命令 (3个):
- /cost: 从占位→真实Token统计,显示input/output/cache tokens和费用
- /model: 支持快捷名称切换(sonnet/opus/haiku),显示可用模型列表
- /compact: 增强显示压缩前后消息数和Token使用量

系统提示词增强:
- 集成Skills摘要和Git上下文到系统提示词
- 新增Shell环境信息和更详细的Guidelines

命令总数: 6 → 10, 工具总数: 11

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-01 20:59:22 +08:00
liuzhandCopilot e09c3de91e feat: Phase3 新增5个工具 (ListFiles, WebFetch, TodoWrite, Agent, NotebookEdit)
新增工具:
- ListFilesTool: 目录列表,支持递归深度、隐藏文件过滤、文件大小显示
- WebFetchTool: HTTP内容获取,HTML→文本转换,大小限制100KB,超时30s
- TodoWriteTool: 待办任务管理(add/update/complete/delete/list),内存存储
- AgentTool: 子Agent调用,通过ToolContext工厂方法创建独立AgentLoop
- NotebookEditTool: Jupyter notebook编辑(read/insert/replace/delete/move)

配置更新:
- AppConfig注册11个工具(原6+新5)
- AgentLoop工厂方法注入ToolContext,支持AgentTool创建子Agent

工具总数: 6 → 11

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-01 20:51:30 +08:00
liuzhandCopilot 549cc79dc6 fix: 修复Windows终端UTF-8编码问题,恢复emoji字符
根因: System.out使用平台默认编码(CP936/GBK),emoji无法编码显示为?。
修复方案:
1. JVM参数: -Dstdout.encoding=UTF-8 -Dstderr.encoding=UTF-8 -Dfile.encoding=UTF-8
2. 代码层: PrintStream使用StandardCharsets.UTF_8
3. 启动脚本: run.bat添加chcp 65001, run.ps1设置Console编码

同时revert之前的emoji→ASCII替换,恢复原始emoji符号。

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-01 20:44:23 +08:00
liuzh cc0d3f8b00 Revert "fix: 将所有emoji/Unicode特殊字符替换为ASCII安全字符"
This reverts commit 3cd67ffe451be2cc7a66b5c554966f1d5aa58c7c.
2026-04-01 20:43:31 +08:00
liuzhandCopilot eeceaaaea9 fix: 将所有emoji/Unicode特殊字符替换为ASCII安全字符
Windows cmd/PowerShell默认codepage下emoji显示为?号。
全局替换: 👋->移除, 💭->[Thinking], ⚙->*, ✓->[OK], ✗->[FAIL],
◆->>, ⚠->[!], ->[OK], •->|/-, →->>>, ✏️->[Edit]等。
❯保留(windows-vtp终端下正常显示)。

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-01 20:37:55 +08:00
liuzhandCopilot b7ad7956c0 fix: 启动脚本添加MAVEN_OPTS抑制JDK25兼容性警告
设置--enable-native-access和--sun-misc-unsafe-memory-access
消除Maven自身jansi和guava在JDK25下的WARNING输出

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-01 20:32:45 +08:00
liuzhandCopilot f3ded93fec chore: 添加PowerShell启动脚本run.ps1
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-01 20:31:23 +08:00
liuzhandCopilot 1c74bbdcdb fix: 关闭Spring Boot banner和启动日志,添加run.bat启动脚本
- application.yml: banner-mode=off, 所有日志级别提升到WARN
- 启动时不再显示Spring Boot ASCII art和INFO日志
- 控制台只显示Claude Code自己的输出
- run.bat: 预配置JDK25环境变量的一键启动脚本

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-01 20:29:41 +08:00
liuzhandCopilot 9048cc8b74 fix: 改进终端兼容性 - FFM原生终端支持、dumb终端提示、双重Goodbye修复
- 添加jline-terminal-ffm依赖(JDK22+ FFM API原生终端)
- JVM参数增加--enable-native-access=ALL-UNNAMED
- dumb终端模式下显示黄色警告和建议
- 终端尺寸为0时不显示尺寸信息
- ExitCommand不再输出Goodbye(避免与ReplSession重复)
- TerminalBuilder增加streams(System.in, System.out)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-01 20:25:51 +08:00
liuzhandCopilot b29d61581a feat: Phase2 JLine终端交互增强 - 行编辑、历史、Tab补全、信号处理
JLine 3 集成:
- ReplSession重写: JLine Terminal + LineReader 替代Scanner
- 支持行编辑(光标移动、删除、Home/End等)
- 持久化历史记录(~/.claude-code-java/history)
- 上下箭头浏览输入历史
- Ctrl+C取消当前输入、Ctrl+D退出
- JLine失败时自动降级到Scanner模式

Tab补全:
- ClaudeCodeCompleter: 斜杠命令补全(/后按Tab)
- 支持命令别名补全(如 /q → exit)
- 分组显示(Commands / Aliases)

新增命令:
- /model: 显示当前AI模型信息
- /compact: 压缩对话上下文
- /cost: Token用量显示(占位)

改进:
- HelpCommand清理为统一格式
- Banner增加终端信息显示和快捷键提示
- 彩色提示符使用AttributedStringBuilder

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-01 20:18:59 +08:00
liuzhandCopilot 70c9ebed2b fix: 解决ChatModel多Bean冲突和JVM内存不足问题
- AppConfig中用@Qualifier指定anthropicChatModel
- spring-boot-maven-plugin配置-Xmx512m限制堆内存
- application.yml关闭web-application-type为none

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-01 19:41:40 +08:00
liuzhandCopilot 6d3f24aad6 fix: 升级Spring Boot到4.1.0-M2以兼容Spring AI 2.0.0-M4
Spring AI 2.0.0-M4依赖Spring Framework 7.0(RetryListener类),
需要Spring Boot 4.x作为parent。

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-01 19:34:00 +08:00
liuzhandCopilot d67f41358d feat: Phase1 项目骨架 - Maven项目结构、核心AgentLoop、6个工具、命令系统、控制台渲染、REPL会话
实现内容:
- pom.xml: JDK25 + Spring AI 2.0.0-M4 + JLine3 + Picocli
- core/AgentLoop: 基于ChatModel的显式工具循环(非ChatClient)
- tool/: Tool接口 + ToolRegistry + ToolCallbackAdapter(适配Spring AI)
- tool/impl/: BashTool, FileReadTool, FileWriteTool, FileEditTool, GlobTool, GrepTool
- command/: SlashCommand接口 + CommandRegistry + /help, /clear, /exit
- console/: AnsiStyle, BannerPrinter, ToolStatusRenderer, ThinkingRenderer, SpinnerAnimation, MarkdownRenderer
- context/: SystemPromptBuilder, ClaudeMdLoader(多级CLAUDE.md加载)
- repl/ReplSession: REPL主循环(Scanner降级方案)
- config/AppConfig: Spring Bean装配
- application.yml: Anthropic/OpenAI双模型配置

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-01 19:22:04 +08:00
liuzhandCopilot 2a565d314d docs: 初始化项目需求文档和修改记录
- 创建需求文档.md:完整覆盖 claude-code 全部 38 个模块、2289 个文件
- 按 P0/P1/P2/P3 四级划分实现优先级
- 包含工具系统(40个)、命令系统(79+个)、服务层(20个子模块)的完整映射
- 设计 Java 包结构和类映射关系
- 创建修改记录.md

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-01 19:03:10 +08:00