Skip to content

feat: WebSocket /ws/chat + fusion-studio integration (v0.4.1) - #16

Merged
dahai80 merged 1 commit into
mainfrom
feat/project-api-v0.4.0
Jul 30, 2026
Merged

dahai80 merged 1 commit into
mainfrom
feat/project-api-v0.4.0

Conversation

@dahai80

@dahai80 dahai80 commented Jul 30, 2026

Copy link
Copy Markdown
Owner

Summary

v0.4.1 补丁版本,在 v0.4.0 基础上新增 WebSocket 流式对话端点,完成 fusion-code ↔ fusion-studio 三层集成方案的 fusion-code 侧实现。

变更

  • WebSocket /ws/chat (src/server/projectApiServer.ts)
    • 子进程模式:spawn fusion-code --output-format=stream-json,转发 NDJSON 到 WS 客户端
    • 协议:chat.stream / chat.cancel → chat_event / chat_done(兼容 StreamingBridge)
    • 自动清理:连接断开时 kill 子进程
  • 启动脚本 start.sh — 供 UpstreamServiceManager 调用
  • 测试 15 tests (10 HTTP + 5 WebSocket),全部通过
  • README 新增 WS 端点文档
  • 版本 0.4.0 → 0.4.1

Fusion-Studio 侧跟进

层次 Issue PR
Layer 1: 服务注册 #9 #12
Layer 2: REST API 客户端 #10 #12
Layer 3: WebSocket 流式 #11 待实施

Test Plan

  • bun test tests/server/projectApiServer.test.ts — 15 pass
  • bun test tests/lib/claudemd-parser.test.ts — 7 pass
  • bun run build — 编译成功

🤖 Generated with Claude Code

….4.1)

- Add WebSocket /ws/chat to projectApiServer for streaming chat
  (subprocess mode: fusion-code --output-format=stream-json)
- Protocol: chat.stream/chat.cancel → chat_event/chat_done NDJSON
  (compatible with StreamingBridge)
- Add start.sh for UpstreamServiceManager auto-start
- Update README with WS endpoint docs
- Bump version to 0.4.1

Fusion-Studio issues filed:
- #9 Layer 1: upstream service registration
- #10 Layer 2: FusionCodeAPIClient
- #11 Layer 3: StreamingBridge WS integration
- PR #12: Layer 1+2 implementation

🤖 Generated with [Claude Code](https://claude.com/claude-code)
@dahai80
dahai80 merged commit 2061527 into main Jul 30, 2026
1 check passed
@dahai80
dahai80 deleted the feat/project-api-v0.4.0 branch July 30, 2026 13:12
dahai80 added a commit that referenced this pull request Aug 28, 2026
…186)

Extract the setMessages state-sync wrapper from REPL.tsx into a pure
helper src/utils/messagesSetter.ts (applySetMessages). No React hooks,
no JSX, no await — only side effects are mutating 3 refs
(messagesRef/userInputBaselineRef/userMessagePendingRef) and calling
rawSetMessages, byte-identical to the inlined useCallback body.

The body maintains a ref mirror of the messages array plus two
placeholder-tracking refs: (1) compute next (functional action or direct
value) and sync messagesRef.current; (2) if next shrank
(compact/rewind/clear) clamp baseline to 0 so the placeholder length
check can't go stale; (3) if next grew while userMessagePending, inspect
the added slice — if it contains a human turn, clear pending (user
message landed); otherwise bump baseline to next.length so the
placeholder stays visible for async bridge/hook/scheduled messages
landing ahead of the user message.

REPL keeps a thin useCallback wrapper whose deps array [] is unchanged
verbatim (all deps are refs + rawSetMessages captured in the setters
object, no closures). Downstream reads the same const name.

Tests (src/__tests__/utils/messagesSetter.test.ts, 8 cases) cover:
direct-value vs functional action, shrink clamp, grow-with-human
(clears pending), grow-without-human (bumps baseline), grow-without-
pending (no-op), prepend slice path, and the prev-empty guard. Real
isHumanTurn predicate (type==='user' && !isMeta && toolUseResult===undefined)
exercised via minimal fake messages.

Gates: typecheck 0 / 873 tests / biome clean / build:dev pass.
REPL 6455 -> 6434 (-21). Cumulative across 16 slices: -662.

Co-authored-by: Claude Fable 5 <[email protected]>
dahai80 added a commit that referenced this pull request Aug 28, 2026
#187)

Extract setInputValue useCallback body (27 LOC, 3 deps) to pure-helper
src/utils/inputValueState.ts applySetInputValue(). Same aggregate-input
pattern as slices #15/#16: typed InputValueStateSetters (7 fields),
REPL keeps useCallback thin wrapper, deps array
[setIsPromptInputActive, repinScroll, trySuggestBgPRIntercept] unchanged
verbatim. RECENT_SCROLL_REPIN_WINDOW_MS (REPL-local const 3000) passed as
recentScrollRepinWindowMs field to keep helper pure-agnostic.

Behavior: (1) trySuggestBgPRIntercept(prev,value) hit -> early return;
(2) empty->non-empty + scroll-stale (>= window) -> repinScroll;
(3) sync inputValueRef.current + setInputValueRaw + setIsPromptInputActive(trim>0).

Tests: 8 cases (repin+write+activate, intercept early-return, non-empty
guard, scroll within-window/boundary, empty deactivate, whitespace guard,
ref-sync-before-setters). 881/881 pass, typecheck 0, biome clean, build:dev ok.

REPL 6434 -> 6420 (-14). Cumulative 7096 -> 6420 (-676) across 16 slices.
Zero REPL import churn. Byte-identical behavior (deps + ref reads unchanged).

Co-authored-by: Claude Fable 5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant