Skip to content

fix: WS chat binary resolution + Buffer handling + error detail - #19

Merged
dahai80 merged 2 commits into
mainfrom
fix/ws-chat-stream-json-verbose
Jul 30, 2026
Merged

dahai80 merged 2 commits into
mainfrom
fix/ws-chat-stream-json-verbose

Conversation

@dahai80

@dahai80 dahai80 commented Jul 30, 2026

Copy link
Copy Markdown
Owner

Problem

The WebSocket /ws/chat endpoint spawns fusion-code -p "..." --output-format=stream-json but the CLI requires --verbose when using --output-format=stream-json with -p. Without it, the CLI exits immediately with:

Error: When using --print, --output-format=stream-json requires --verbose

This causes /ws/chat to return chat_done immediately with zero chat_event tokens.

Fix

Add --verbose to the spawn args in handleChatStream().

Testing

Before fix: WebSocket /ws/chat returns only chat_done with no content.
After fix: (needs verification with MLX backend)

Fixes #17

🤖 Generated with Claude Code

dahai80 added 2 commits July 31, 2026 00:09
Without --verbose, fusion-code -p --output-format=stream-json exits
with error: 'When using --print, --output-format=stream-json requires --verbose'

This caused /ws/chat to return chat_done immediately with zero tokens.

Fixes #17

🤖 Generated with [Claude Code](https://claude.com/claude-code)
- findFusionCodeBinary: add process.execPath + cwd candidates
  (compiled binary can't resolve via import.meta.dir)
- WS message handler: handle Buffer messages via TextDecoder
- WS error: expose actual parse error instead of generic 'Invalid JSON'
- Test: update assertion for new error message format

🤖 Generated with [Claude Code](https://claude.com/claude-code)
@dahai80 dahai80 changed the title fix: add --verbose to stream-json subprocess in WS chat handler fix: WS chat binary resolution + Buffer handling + error detail Jul 30, 2026
@dahai80
dahai80 merged commit caae6a6 into main Jul 30, 2026
1 check passed
@dahai80
dahai80 deleted the fix/ws-chat-stream-json-verbose branch July 30, 2026 23:08
dahai80 added a commit that referenced this pull request Aug 28, 2026
…ate helper (audit §1.1.1 slice #19) (#189)

Extract the 37-LOC onCompactProgress switch (REPL getToolUseContext,
5 CompactProgressEvent cases routing 3 spinner setters) into a pure
routing helper src/utils/compactProgressState.ts. No React hooks, no
JSX, no async; only side effect = call 3 spinner setters, matching the
original useCallback body verbatim (including \u2026 ellipsis escapes
and COMPACT_STALL_HINT_MS threshold gate).

REPL keeps a thin onCompactProgress wrapper passing the closure-captured
spinner setters + COMPACT_STALL_HINT_MS; the getToolUseContext useCallback
deps array is unchanged (spinner setters + const are stable refs/values,
not in deps). Downstream reads the same ProcessUserInputContext.onCompactProgress
field = byte-identical.

formatDuration import dropped from REPL (now only used by the helper);
CompactProgressEvent type added to the Tool.ts import.

- REPL 6415 -> 6386 (-29 net; 10 insertions / 39 deletions)
- New helper: src/utils/compactProgressState.ts (applyOnCompactProgress)
- New test: src/__tests__/utils/compactProgressState.test.ts (9 tests,
  19 assertions: all 5 event types, stall threshold boundary, configurable
  hint, compact_end null-clears)
- Gates: typecheck 0 / 896 tests pass / biome clean / build:dev ok

Co-authored-by: Claude Fable 5 <[email protected]>
dahai80 added a commit that referenced this pull request Aug 29, 2026
…ice #25) (#195)

从 REPL.tsx onQueryImpl apiMetrics capture 子块 (L3300-3337, 38 LOC) 抽出到
src/utils/apiMetricsCapture.ts 的 captureApiMetrics() helper。

PURE-ROUTING SUB-BLOCK class (像 slice #19 onCompactProgress):
- 行为等价,无 React hooks/JSX/await。
- helper 直接 import 9 module symbols (6 getTurn* timing fn / median /
  isInternalBuild / createApiMetricsMessage / getGlobalConfigWriteCount);
  ctx 携带 3 REPL 闭包依赖 (apiMetricsRef + loadingStartTimeRef + setMessages)。
- guard 移入 helper (isInternalBuild() && length>0),REPL 保留薄调用。

REPL 清理 8 个 sole-user import (6 getTurn* + getGlobalConfigWriteCount +
createApiMetricsMessage),isInternalBuild(18 用)/median(6 用) 保留。

LOC: REPL 6215→6172 (−43),cumulative −881→−924。
4 gates: typecheck 0 / 914 pass / biome clean(new) / build:dev 3781 mods。

Co-authored-by: Claude Fable 5 <[email protected]>
dahai80 added a commit that referenced this pull request Aug 29, 2026
….1.1 slice #30) (#201)

Extract REPL onQueryEvent → handleMessageFromStream first callback
(L2954-3016, 62-LOC message-dispatch sub-block) into
src/utils/streamMessageDispatch.ts as createStreamMessageDispatch(ctx)
factory returning the (newMessage) => void callback.

Routes incoming streamed message to the right setMessages mutation:
- compact-boundary → replace (or append in fullscreen) + bump conversationId
- ephemeral tool-progress tick → replace last same-tool tick (no array blowup)
- otherwise → append
Plus proactive context-block toggle on API errors / success.

Pure-routing sub-block extraction class (proven via slices #19/#25-#29):
reads only setters + module helpers, no React hooks, no closures over REPL
state beyond the explicitly-passed ctx. ~9 deps via ctx object vs the parent
onQueryEvent's 15+ — manageable, avoids the getToolUseContext factory
ctx-reconstruct risk (lesson #18).

REPL 6034 → 5976 (-58 net). Byte-identical behavior: factory passes the same
setMessages/setConversationId/proactiveModule the inline closure captured.
Removed now-unused isEphemeralToolProgress import (import-cleanup lesson #22);
isCompactBoundaryMessage kept (still used at L3073).

Gates: typecheck 0 / 921 tests pass / biome exit 0 / build:dev pass.

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.

Bug: projectApiServer WebSocket handler spawns CLI without --verbose, breaking stream-json output

1 participant