Repository navigation
feat: share session rating rules across CLI and server - #4272
Conversation
Move the session rating product logic out of the TUI into @moonshot-ai/kimi-code-product so the CLI and kap-server share one engine: survey_popup parsing and the effective config, the product gates, the Appearance state machine, event properties, the kfc check, the global cooldown file, and the named cloud config client. The TUI survey controller becomes an adapter. It translates SDK events into engine facts, reads its environment from appState, applies the terminal-only UI vetoes before asking the engine to evaluate, and keeps digit debounce, the 600ms entrance guard, draft detection, Esc, arrow keys and rendering. The cloud config client now takes its region, base URL override and cache directory from the host. Behavior notes: the engine rereads the shared cooldown file before each evaluation instead of once per mount, and a vetoed evaluation no longer draws the session sample early.
Add the top-level disable_feedback_survey key to config.toml so the CLI and the desktop app share one opt-out. The SDK config schema and TOML writer, the kap-server config route and the config docs learn the key. The CLI /settings toggle now writes config.toml. On startup the CLI moves a legacy tui.toml value into config.toml and drops it from tui.toml; when config.toml cannot be written it keeps honoring the legacy value, warns, and retries on the next start. The engine reads the key before every evaluation, so a change from either client applies without a restart.
Add a replayable userTurnTally state that counts main-agent prompts the shared user turn classification accepts. It folds over the full journal, so undo, context clears, and compaction never lower the count, and a fork counts only the turns it copied. A prompt that cannot be classified, or a user message recorded before the first prompt, turns the count unknown. The restore pass that already replays every record builds the state, so hosts read the session user turn count without a second read of the log.
The server host now feeds the engine everything the CLI reports: the managed model route for the kfc check, busy state from the loop and compaction, the session user turn count from core, resumed subagents from session metadata, and tool call, subagent, and compaction facts from the main agent. The consent gate reuses the server telemetry rule and is read before every evaluation. survey_popup comes from the cloud through the product client config client with region, token, and cache directory taken from core; the first evaluation request starts the fetch. Preview mode now needs debug endpoints, so production builds ignore it. Server shutdown still ends every rating silently.
Evaluate rating offers synchronously for a target turn and retain reporting snapshots independently of session lifetime. Settle selection and undo locally in each client and acknowledge actual display separately. Preserve existing preferences when migrating the survey opt-out.
🦋 Changeset detectedLatest commit: c91d0ac The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
commit: |
Separate common rating configuration from Node-backed feeds and migrate CLI and server imports. Derive build entries from package exports and add entry-boundary checks.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1cefbef44d
ℹ️ 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".
Share survey origin classification and historical counting across SDK replay and the session rating host. Move survey event definitions into product and retain generic telemetry dispatch in core. Attach counters before normal restore and serialize late replay with history restoration to preserve counts and queued events.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 18237a0e7f
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: de1437a845
ℹ️ 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".
Drops the tui.toml migration-history sentence added earlier on this branch; public docs describe what the key does now, not its move.
Ported from MoonshotAI/kimi-code 2.3.0 (ce0834a). Introduces `packages/product` — the shared product layer (`client-configs/node`, `session-rating`, `session-rating/node`) — and moves the session-rating engine, survey gates, cooldown store and client-config cache into it so the CLI and kap-server evaluate the same rules. The TUI survey controller and the server's `POST /sessions/{id}/rating` route both drive that engine. Fork adaptation of the new package: - `packages/product` ships as a Bun workspace member: `test` runs `scripts/run-package-tests.mjs`, `vitest.config.ts` is gone, the nine test files are `bun:test`, and `tsconfig.json` maps `#/*` to `./src/*.ts` (the one thing Bun needs and vitest resolved through its own config). - `bun install` links it; `flake.nix` and both `package.json` dependency lists keep the fork's `@moonshot-ai/kimi-i18n` alongside the new package. Conflicts resolved: - `klient/contract/global/events.ts`: the fork's root import for `ConfigChangedEvent` resolved to the bus-event type of the same name, so `config.sectionChanged` carried the wrong payload and the new `SDKRpcClientV2.onConfigSectionChanged` override stopped compiling. It now imports the section payload from `app/config/config` (as upstream does) and uses `ConfigSectionChangedEvent` for the section channel. - `sessionLifecycleService.ts`: kept the fork's compact formatting and added upstream's `onDidCreateScope` seed plus `scopeCreated.fire(handle)`. - `eventDispatcherService.ts`: added upstream's `replayFailure` rethrow. - `kimi-tui.ts`: kept the fork file — it carries ~40 fork-only members (token statistics, transcript mounting, the status-surface focus fix), which taking upstream's rewrite would delete — and hand-ported its six survey deltas: the `Unsubscribe` import, `migrateLegacySurveySetting`, `removeLegacySurveySetting`, the `surveySettingSubscription` field/teardown, the `disableFeedbackSurvey` config-section listener (guarded with a `typeof` check because several TUI test doubles omit it) and `notifyTurnStarted(event.origin)`. - `survey-panel.ts`, `survey-controller.ts`, `survey-policy.ts`, `client-configs.ts`: took upstream, then restored the fork's localisation (`surveyQuestion()`/`surveyOptionLabels()`, `t('tui.messages.surveyThanks')`). - survey tests: `survey-controller.test.ts`, `survey-policy.test.ts` and `survey-preferences.test.ts` were rewritten upstream against the new engine and taken over with the `bun:test` conversion; `config.test.ts` likewise, plus the fork's `locale`/`disableFeedbackSurvey` fields in its expected objects. `kimi-tui-survey.test.ts` and `kimi-tui-message-flow.test.ts` waited on the controller's old `cooldownReady` flag, which the product mount resolves synchronously; those waits became a single macrotask yield. - `rest-session-rating.ts`: the fork's `defineRoute` rejects non-strict request bodies, so the rating body became `z.strictObject` per union member. - `rest-config.ts`: added `disable_feedback_survey` and kept the fork's `.strict()`. Fixes surfaced by the port: - `renderTuiConfig` wrote `locale = "undefined"` when the caller omitted the fork-only `locale` field, and the strict parser then rejected the file; it now falls back to `DEFAULT_TUI_CONFIG.locale`. - `fullCompaction` pre-existing failure untouched (fails identically before). Verification: - bun run typecheck: exit 0, zero errors across every package and app - packages/product: 272 pass / 0 fail - apps/kimi-code: 4712 pass / 0 fail / 0 errors, 22 skip - packages/kap-server: 1367 pass / 0 fail, 9 skip - packages/node-sdk: 296 pass / 6 fail; the six are pre-existing in auth-facade.test.ts (the fixture omits `limit.context`, which packages/oauth already requires on the parent commit) and the file is untouched here - packages/agent-core-v2: 7884 pass / 1 fail / 0 errors; the one failure is the fullCompaction pre-shrink case that fails identically on the parent commit - check:no-comments, no-hardcoded-prose, t-coverage, locale-keys, catalog-versions, nix-workspace all OK
Requirement or Bug
让 CLI 和桌面端共用会话评分规则、云控和统计,同时由各客户端决定选择、撤销和结算,避免远程请求乱序改变用户答案。
Bug Reproduction Steps
N/A
Root Cause
N/A
Code Changes
新回合、会话卸载和后续评估不会清掉旧回答快照。重复报告不重复结算,未显示的 offer 不产生 appeared。账本不跨进程重启保存,也不承诺报告持久送达。
Behavior Changes and Affected Users
tui.toml,只供 CLI 使用config.toml,CLI 和桌面共用tui.toml含旧评分键的用户POST /sessions/{id}/rating的四种操作disable_feedback_survey = true关闭提示;现有其他接口不变/settings关闭评分旧路径的功能归属如下。
survey_popup、长上下文优先级、模型门禁、抽样、全局冷却和事件属性移入packages/product。KIMI_CODE_BASE_URL。缓存提示、推荐思考强度和横幅改用共享实现。服务端新增接口供配套桌面端使用,没有新增评分 WebSocket 事件或视图恢复接口。旧客户端不调用该接口,不需要降级分支。未修改模型提示词、provider 协议或其他客户端的 UI。
已运行产品包全量测试、服务端评分/API 快照/配置测试、CLI 全量测试,以及相关 typecheck 和 lint。CLI 的两项 native artifact 测试因环境缺少
zstd失败,对应脚本未改。测试覆盖迟到、重复、跨回合、卸载后报告、历史计数、遥测关闭和配置迁移失败后的重试。配置与 API 文档已核对中英两版;文档流程所需的 changelog 同步脚本当前缺失,未执行该步骤。Checklist
/approve). 无关联 GitHub issue。gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update. 已核对双语文档;同步步骤因缺少脚本停止。