Skip to content

feat(kap-server): take turn_number in the file-history queries - #4788

Merged
wbxl2000 merged 2 commits into
mainfrom
refactor/file-history-turn-number
Nov 10, 2026
Merged

wbxl2000 merged 2 commits into
mainfrom
refactor/file-history-turn-number

Conversation

@wbxl2000

Copy link
Copy Markdown
Collaborator

Requirement or Bug

文件历史接口(GET /sessions/{id}/file-history/changes、/content)用查询参数 turn_id 传一个整数,也就是这一轮的 turn_number。但在对话接口里,turn_id 是轮的字符串 id(如 t_ab12…),同一个名字有两种含义。客户端迁到新的对话结构时,很容易把字符串 turn_id 或 ordinal 传进来,而 ordinal 从 0 开始、包含 system 轮、撤销后还会复用。传错不会报错,只会悄悄读到别的轮的文件变更。

这个 PR 把参数名改成和对话里 Turn.turn_number 一致的 turn_number,旧名字 turn_id 暂时继续接受。

Bug Reproduction Steps

N/A

Root Cause

N/A

Code Changes

 fileHistoryChangesQuerySchema / fileHistoryContentQuerySchema
-  turn_id: integer (required)
+  turn_number?: integer
+  turn_id?: integer        # deprecated alias of turn_number
+  → transform: turn_number = turn_number ?? turn_id; neither given → 40001 "turn_number is required"

 file-history routes
-  history.changes(req.query.turn_id)
+  history.changes(req.query.turn_number)
  • 输入侧仍是普通对象,OpenAPI 里能看到两个参数,turn_id 标注为 deprecated alias。路由代码只认 turn_number。
  • 不能直接删掉旧名字:CLI 自带的 web dist 和 desktop 当前的客户端都还在传 turn_id,直接改名会让文件历史在客户端更新之前失效。客户端会在 code-app bump 子模块时切到 turn_number,之后再单独删掉别名。

Behavior Changes and Affected Users

Behavior Before After Who relies on the old behavior Escape hatch
?turn_number=N 当作未知参数忽略,缺少必填的 turn_id 返回 40001 读取第 N 轮 — —
?turn_id=N 读取第 N 轮 不变,作为别名继续接受 desktop / web 当前的客户端 不需要
两个都传 — 以 turn_number 为准 — —
两个都不传 40001 40001,提示 turn_number is required — —

受影响模块:packages/kap-server 的文件历史协议与路由。apiSurface 快照只记录路径,没有变化。

测试(test/fileHistory.test.ts):

  • 原有用例改用 turn_number。
  • 新增两个用例:旧名字 turn_id 在两个接口上仍可用;两个都不传时返回 40001。

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue (external PRs: issue must have a maintainer's /approve).
  • I have added tests that prove my feature works.
  • The behavior-change table above is complete, and every removed behavior or flipped default is named in the changeset and either has an escape hatch or was explicitly approved by a maintainer in this PR.
  • Ran gen-changesets skill, or this PR needs no changeset. 不写:用户看不到变化,旧参数照常可用。
  • Ran gen-docs skill, or this PR needs no doc update. 文档里本来就写的是 turn_number。

@changeset-bot

changeset-bot Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: fd54a0e

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-10T08:36:22.998579Z fd54a0e Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@pkg-pr-new

pkg-pr-new Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@fd54a0e
npx https://pkg.pr.new/@moonshot-ai/kimi-code@fd54a0e

commit: fd54a0e

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6e6f97515a

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@wbxl2000

Copy link
Copy Markdown
Collaborator Author

@codex review
评审约定:

  1. 只审本 PR 相对 base 的 diff;base 存量问题请单列为 note,不作阻塞意见。
  2. 同类问题请一次性列出 diff 内全部位置,不逐轮分批提出。
  3. 纯风格/个人偏好意见不发;每条意见标注严重度(P0 阻断 / P1 应修 / P2 建议)。
  4. 已 resolve 的主题代表我们的判断取舍与当前代码现状,请勿重复提出。

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: fd54a0e4cd

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@wbxl2000
wbxl2000 merged commit 961b90f into main Nov 10, 2026
16 checks passed
@wbxl2000
wbxl2000 deleted the refactor/file-history-turn-number branch November 10, 2026 10:05
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.

2 participants