Skip to content

统一 Gen Code 草稿的类型化解码 - #66

Merged
tiye merged 3 commits into
mainfrom
refine/gen-code-draft-decoder
Nov 14, 2026
Merged

tiye merged 3 commits into
mainfrom
refine/gen-code-draft-decoder

Conversation

@tiye

@tiye tiye commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

用户影响

插件打开草稿和启动时恢复中断请求,都沿用原先接受的 Map 与 Struct 格式。缺少草稿时仍使用初始状态。

改动与验证

将两个入口重复的草稿校验合为 read-draft,返回 GenCodeState。原始值在解码入口收敛,渲染和恢复逻辑共用同一个类型合同。

Calcit 0.42.1 的 248 个定义、完整 strict、7 项原生测试、离线流式回归和 Node 24 构建均通过。

Summary by CodeRabbit

  • New Features
    • Added a state reset option that emits a typed operation with the drafter cursor and initial state.
  • Bug Fixes
    • Improved handling of streamed responses that contain chunks without text, helping prevent interruptions during code generation.
  • Refactor
    • Updated draft-state handling for more consistent state decoding.
  • Documentation
    • Updated the plugin contract to describe the state reset option and its event emitter.

类型化重置

类型化宿主可用 (.reset-state-with plugin emit!) 接收具名 GenCodeOp,旧宿主继续用原有重置方法。Calcit 0.42.1 全定义 248/248、8 项原生测试和完整 strict 已通过。

流式响应

没有文本字段的流片段仍会跳过,后续文本继续累积。文本读取现在使用受检的 JS 宿主转换,并在现有离线用例覆盖缺失字段场景。全定义检查、完整 strict、8 项原生测试以及离线流式回归通过。

@coderabbitai

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The change adds reset-state-with, which emits a typed state-reset operation. It adds read-draft for draft decoding in two functions and updates stream chunk handling when a chunk has no text property.

Changes

Typed reset operation

Layer / File(s) Summary
Typed reset operation
calcit.cirru, README.md
GenCodeActions and its implementation add reset-state-with. The method emits a :states operation for the plugin cursor and initial state. Tests check the emitted operation, and the README documents the method and emitter.

Draft state decoding

Layer / File(s) Summary
Shared draft decoder
calcit.cirru
read-draft converts struct inputs to maps and decodes the result as GenCodeState. use-gen-code-with-dispatch and clear-interrupted-loading now use this helper.

Stream chunk handling

Layer / File(s) Summary
Chunks without text
calcit.cirru, tests/stream-contract.mjs
read-genai-chunk checks for a text property and uses an object with text: undefined when it is absent. The stream fixture now yields an empty object before its offline response.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Refactor

Merge Risk: Minimal · up to 8e871

This change unifies draft decoding, adds a typed reset operation while keeping the old one, and tolerates stream chunks with no text. No actionable merge-blocking risk is evident.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "统一 Gen Code 草稿的类型化解码" (Unify typed decoding of Gen Code drafts) matches the main change. The PR adds read-draft, which unifies the draft decoding used when opening drafts and when restoring…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Full details: Title check

Explanation

The title "统一 Gen Code 草稿的类型化解码" (Unify typed decoding of Gen Code drafts) matches the main change. The PR adds read-draft, which unifies the draft decoding used when opening drafts and when restoring interrupted requests, and returns GenCodeState. The title does not mention the secondary reset-state-with addition, which is acceptable because the title need not cover every detail.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 98678572-b8f7-4409-9ae9-ea327f92d022
Commits

Reviewing files that changed from the base of the PR and between 4275bf4 and 8e871db.

Files selected for processing: 2

  • calcit.cirru
  • tests/stream-contract.mjs

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@tiye
tiye merged commit e5900e9 into main Nov 14, 2026
1 check passed
@tiye
tiye deleted the refine/gen-code-draft-decoder branch November 14, 2026 04:13
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