Repository navigation
fix(agent-core-v2): keep session titles for skill-opening sessions - #5618
Conversation
🦋 Changeset detectedLatest commit: d075f9b The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
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 Summary: ✅ CompletedThis 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: |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8533bc96c9
ℹ️ 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".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 82489e796b
ℹ️ 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".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b0a9107396
ℹ️ 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".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7e6902e800
ℹ️ 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".
| if (!isUserTitlePrompt(message)) return false; | ||
| if (message.origin?.kind !== 'skill_activation' || continuationIds === undefined) return true; | ||
| return message.id === undefined || !continuationIds.has(message.id); |
There was a problem hiding this comment.
Keep bundled skill steers inside the opening turn
When an SDK or KAP caller invokes promptWithSkills(..., { steerIfActive: true }) during the opening turn, AgentSkillService sends the bundled prompt as a continuation whose origin is kind: 'user' with skillActivations. This condition nevertheless treats it as the next turn regardless of its continuation ID, so if the steer arrives before the first assistant text, firstTurnExcerpt() stops there and title generation again receives no assistant excerpt. Apply the wire continuation classification to bundled skill prompts as well as direct skill_activation messages.
AGENTS.md reference: AGENTS.md:L111-L115
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
经评估本次不修:steerIfActive: true 下 bundled skill 插话早于首个 assistant 文本到达属于 SDK/KAP 主动插话的边界场景,若要覆盖需把续接判定扩展到 origin.kind === "user" 的普通续接 prompt,超出本 PR 修复「以 skill 开头的会话标题为空」的范围,暂不在此处改动。
|
|
||
| private turnContinuationPromptIds(): ReadonlySet<string> | undefined { | ||
| let hasTurnPrompts = false; | ||
| const ids = new Set<string>(); |
There was a problem hiding this comment.
Match continuation state to prompt occurrences
When a caller reuses a completed prompt ID for a later direct skill activation, an earlier in-turn activation leaves that ID in this global set. Prompt IDs are explicitly reusable correlation IDs, so isNextTurnPrompt() also classifies the later new-turn skill with the same ID as a continuation; a delayed, retried, or manually forced first_turn title request then spans into the later turn and selects its assistant reply instead of the opening turn's reply. Track continuation by prompt occurrence or turn segment rather than global ID membership.
AGENTS.md reference: AGENTS.md:L111-L115
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
经评估本次不修:跨回合复用同一个 promptId 属于调用方自定义 correlation ID 的极端场景,按出现次数或 turn 分段跟踪续接状态会增加额外复杂度,本次保持现有的 promptId 集合判定,暂不处理。
| @@ -0,0 +1,5 @@ | |||
| --- | |||
| '@moonshot-ai/agent-core-v2': patch | |||
There was a problem hiding this comment.
Add the SDK and KAP release entries
The changed core paths are part of both public surfaces: @moonshot-ai/kap-server routes delegate skill submission, title generation, and session forks to them, while the published @moonshot-ai/kimi-code-sdk bundles agent-core and exposes the same operations. Because neither package appears in the added changesets, the SDK will not be versioned and published with this fix, and the externally visible KAP behavior change will have no owning-package version or changelog entry. Add patch entries for both packages.
AGENTS.md reference: AGENTS.md:L169-L170
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
本次不补这两个包的 changeset:
packages/kap-server和packages/node-sdk(@moonshot-ai/kimi-code-sdk)均为"private": true,不独立发布到 npm,最终随 CLI(@moonshot-ai/kimi-code)和桌面端(kimi-code-app)打包发布,这两个产品包本 PR 已补充 changeset。packages/kap-server的路由与公开协议契约本次没有改动。.changeset/config.json配置了updateInternalDependencies: "patch",且两者均以workspace:^依赖@moonshot-ai/agent-core-v2,发版时 changesets 会自动联动升级内部依赖版本。
|
Codex Review: Didn't find any major issues. What shall we delve into next? Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
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". |
…rom title excerpts
`bun scripts/upstream-ledger.mjs --refresh` at upstream/main 4eb2919 added 126 rows, so every open upstream commit and every PR it references now has a ledger row: 0/596, down from 125 at 8bf8ba3 and 126 at the fetched tip. The refresh only reads `upstream/main ^ main`, so the three release-2.6.2 commits named by the mission (MoonshotAI#4875/MoonshotAI#4905/MoonshotAI#4922) gained rows with the refresh's row shape. Settled with live probes in this tree: - ported: MoonshotAI#5533 (docs 2.8.1 changelog), MoonshotAI#4875 (registry search_url and feedback_url plus the feedback service), MoonshotAI#4905 (Kimi upload status validation in packages/core), MoonshotAI#4922 (swarm task events in sessionTaskFeed), MoonshotAI#5438 (unload only declared dynamic tools), MoonshotAI#5592 (dynamic tool replacement order), MoonshotAI#5595 (append-log known length), MoonshotAI#5573 (skill roots for every work dir), MoonshotAI#5576 (date reminder cwd comparison), MoonshotAI#5618 (session titles for skill openers), MoonshotAI#5638 (frozen loop tool baseline), MoonshotAI#5626 (legacy turn-input origins) - partial: MoonshotAI#5505 (processLiveness source and consumers present; the upstream unit test file was never carried), MoonshotAI#5571 (program-resume and OSC 7577 present; the upstream test helper was never carried), MoonshotAI#5532 (gitService half present; fsService still leaks the environment lease at fsService.ts:1133 and :1267), MoonshotAI#5557 (app-client icon registry kept; the move to app-ui was never carried) - not-applicable: MoonshotAI#4655 (upstream reverted auto review in MoonshotAI#5649), MoonshotAI#5333 (PLAYBOOK:111 deliberate flat experimental flags) M39's "likely present" list was checked, not trusted: MoonshotAI#5438 is present (upstream test passes), MoonshotAI#5487 is not (nativeStartSettleMs/leg.nativeSettled absent), MoonshotAI#5635 is not (ToolsSettled absent), MoonshotAI#5429 needs a visual probe. The remaining 194 pending rows stay open with their reasons; no feature was ported and no upstream-drift allowlist entry was added. Verification: verify -> 332 closed rows, 332 carry every file of their PR; 317 probes pass, 2 foreign-runner skips, 0 fail; a second verify is byte-identical (ledger sha256 cbf53638...). Probe tests 29 pass; bun run lint and node scripts/checks/ratchet.mjs green.
Requirement or Bug
无关联 issue(内部反馈 bug)。
在 Desktop / Web 中,如果新会话的第一条消息是直接调用 skill(例如
/skill:review、仅选择 skill pill 而没有额外文本,或调用方传入了空的metadata.display_text),左侧会话列表的会话名会是空白;即使初始标题落成了 skill 名字面量,首轮结束后也不会自动生成 AI 标题,手动点击「生成标题」同样提示不可用。对这类会话执行 fork 时,新会话的初始标题和lastPrompt也会为空。本 PR 在核心层(
packages/agent-core-v2,不改前端)修复这两点:当display_text为空或没有额外自然语言文本时,统一回退为/skillName args(多 skill 为/skillA args /skillB),保证新建和 fork 的初始title/lastPrompt不为空;同时把用户主动调用的 skill 纳入标题摘要(不包含展开后的<skill-loaded>指令),使首轮结束后能结合 assistant 回复生成 AI 标题。Bug Reproduction Steps
/skill:review回车;或通过 KAP/SDK 调用activateSkill并传metadata: { display_text: '' },或调用promptWithSkills传仅空白文本)。display_text为空串或 bundled 输入仅为空白时,核心层不会写入title和lastPrompt,Desktop/Web 左侧会话列表该行标题为空白,刷新后甚至会因hasPrompt过滤从列表中消失。no_input)。lastPrompt为undefined,fork 出的新会话初始标题同样为空。Root Cause
这是针对根因的修复,而非前端兜底或绕过。问题出在
packages/agent-core-v2的两条标题链路上:display_text短路。promptMetadataTextFromContentParts在clientMetadata每条都带字符串display_text时,直接返回其清洗结果(这是有意设计,防止<browser_capture>等内部序列化内容进入标题)。当display_text为''或纯空白时,清洗结果为undefined,applyPromptMetadataUpdate收到undefined后直接返回。因此promptMetadataTextFromSkill准备好的/skillName args没有机会生效,promptWithSkills在输入仅空白时也一样。fork 路径forkTurnSlice.promptMetadataFromInput使用了同样的旧写法。AgentTitlePromptSourceService只把origin.kind === 'user'视为用户提示词,而直接/skill产生的消息origin.kind是'skill_activation',被整条跳过;bundled skills 剔除 skill 激活块后,若没有剩余文本或有效display_text,用户侧摘要也是undefined。排除message.content原本是为了避免展开后的<skill-loaded>指令全文进入标题请求,但副作用是纯 skill 会话在first_turn/user_prompts/digest三种模式下全部返回no_input。flowchart TD A[用户主动调用 skill] --> B[首条消息写入 / fork 切片] A --> C[首轮结束后生成 AI 标题] B --> D{display_text 非空?} D -- 是 --> E[使用脱敏后的 display_text] D -- 否 --> F[回退 /skillName args] E --> G[写入非空 title 与 lastPrompt] F --> G C --> H{消息来源} H -- user-slash skill_activation --> I[取 display_text 或 /skillName args] H -- bundled skills 且无剩余文本 --> F H -- model-tool / plugin_command --> J[不纳入标题摘要] I --> K[与该轮 assistant 最终回复配对] F --> K K --> L[请求 chat_title 生成标题]Code Changes
核心思路:在核心层定义唯一的 skill 用户侧文本表示——优先使用非空且脱敏后的
display_text,否则回退到/skillName args(多 skill 按顺序拼接)——并同时用于「首条消息初始元数据写入」「fork 切片元数据推导」和「AI 标题摘要提取」三处。只有用户主动触发(user-slash)的 skill 才进入标题摘要,且不读取展开后的<skill-loaded>指令;前端不做任何改动。promptMetadataTextFromSkill第一步向promptMetadataTextFromContentParts传空数组[],是为了只读取并脱敏display_text:当display_text缺失、为空或纯空白时返回undefined,再显式回退到skillCommandLabel,不会把任何内部序列化 XML 当作标题。fork 路径复用同一组函数,消除了internal/forkTurnSlice.ts中与本 PR 同构的平行实现,同时修掉了 fork 时的空标题问题;plugin_command不属于本次 skill 范畴,继续使用原有的私有slashCommandText。关键决策:
/skillName argstitle和lastPrompt落盘,避免刷新后被hasPrompt过滤,且 REST、SDK、fork 各入口行为一致(已与需求方确认不做前端兜底)skill_activation的摘要来源display_text或skillName+skillArgsmessage.contentmessage.content首段是展开后的<skill-loaded>指令全文,直接送入标题请求既冗长又偏离用户输入promptMetadataTextFromSkill/skillCommandLabelforkTurnSlice私有实现forkTurnSlice存在同构逻辑和相同的空标题 bug,经需求方确认合并到同一实现阅读指南:
packages/agent-core-v2/src/features/skill/prompt.ts:看统一的skillCommandLabel及单/多 skill 的空值回退规则。packages/agent-core-v2/src/session/sessionTitle/agentTitlePromptSourceService.ts:看哪些消息进入标题摘要,以及 skill 开场如何与该轮 assistant 回复配对。packages/agent-core-v2/src/features/skill/skillService.ts与packages/agent-core-v2/src/project/sessionLifecycle/internal/forkTurnSlice.ts:初始写入与 fork 切片的接线,可略读。.changeset/(@moonshot-ai/agent-core-v2、kimi-code-app、@moonshot-ai/kimi-code、kimi-code四条 patch):回归用例与发版条目,可略读(覆盖明细见下文折叠块)。Behavior Changes and Affected Users
activateSkill(/skill直接激活)且display_text为空串/纯空白时的初始title/lastPromptundefined,跳过写入;title为''、lastPrompt为undefined/skillName args,titleKind为replaceablepromptWithSkills仅有空白文本或空display_text时的初始title/lastPrompttitle/lastPrompt/skillA args /skillBfirst_turn)、手动「生成标题」(digest)与 SDK 默认user_promptsskill_activation被排除,纯 skill 会话返回no_input,只保留字面量标题,不生成 AI 标题display_text或/skillName args作为 user 摘要,与该轮 assistant 最终文本一起请求chat_title生成标题autoSessionTitle的 desktop 与 web 用户、TUI 交互用户(tui.toml的auto_session_title)、调用generateSessionTitle的 KAP/SDK 调用方auto_session_title = false(或 TUItui.toml)可关闭自动生成;用户自定义标题(custom)在非force下仍不会被覆盖display_text)在标题摘要中的 user 文本undefined,该轮不进标题请求/skillA args /skillBskill_activation(空display_text)或纯 bundled skills 时的lastPrompt/ 初始标题undefined,fork 出的会话标题为空/skillName args或/skillA args /skillBactivateSkill插入 skill 后的标题摘要skill_activation被忽略:first_turn不在该插话处截断,仍取首轮最终 assistant 回复;该 skill 也不进入user_prompts/digestuser-slashskill 与普通用户消息一样作为边界:若插话前已有 assistant 文本则取该文本,若首轮尚未输出文本则first_turn仅含 user 文本;同时该 skill 进入user_prompts/digest(经评审讨论,不额外引入基于 wire 的同回合插话续接判定)/skill的 desktop/web、TUI、KAP/SDK 用户display_text的初始标题与摘要、模型自主调用Skill工具(model-tool/nested-skill)、plugin_command、自定义标题保护undefined或被跳过的输入;model-tool与plugin_command仍被排除;未改任何.md提示词、配置默认值或 wire/state 格式受影响模块与测试覆盖:
features/skill/prompt.ts、features/skill/skillService.ts——test/features/skill/prompt.test.ts(空/空白display_text回退、非空display_text优先与敏感信息脱敏、bundled 正常文本保留)与test/features/skill/activateSkill.test.ts(使用 testkit 假模型验证真实activate/promptWithSkills落盘的title/lastPrompt/titleKind)。session/sessionTitle/agentTitlePromptSourceService.ts——test/session/sessionTitle/agentTitlePromptSourceService.test.ts(user-slash与 assistant 回复配对、在下一条用户或user-slashskill 消息处截断首轮、display_text优先与空值回退、纯 bundled 回退、model-tool与plugin_command仍返回空)、test/session/sessionTitle/titleExcerpt.integration.test.ts(真实 context memory 下的 skill 开场与纯 skill 块摘要)、test/session/sessionTitle/sessionTitleService.test.ts(自定义标题保护、no_input边界不变)。project/sessionLifecycle/internal/forkTurnSlice.ts——test/project/sessionLifecycle/forkTurnSlice.test.ts(context.append_message与turn.prompt两种记录形态、空display_text回退、非空display_text优先、纯 bundled 回退)。agentTitlePromptSourceService.test.ts中原「仅含斜杠激活时不返回标题提示词」的用例,按本次新契约更新为「user-slashskill 返回/compact且不暴露展开指令,plugin_command与model-tool仍不返回」。该文件不属于根AGENTS.md列出的守护契约文件,且此变化已列入上表行 3。验证命令与结果(含平台说明)
在 macOS(本机)基于最新
origin/main(1f91363eb6)实际运行:pnpm exec vitest run --reporter=agent packages/agent-core-v2/test/features/skill/ packages/agent-core-v2/test/session/sessionTitle/ packages/agent-core-v2/test/agent/prompt/promptMetadataText.test.ts packages/agent-core-v2/test/project/sessionLifecycle/:21 个测试文件通过,272 通过、1 个原有 skip(新增用例在修复前均已验证会因空标题/空摘要失败)。pnpm exec vitest run --reporter=agent packages/kap-server/test/skills.test.ts packages/kap-server/test/prompts.test.ts packages/kap-server/test/sessions.test.ts:3 个文件、271 条全部通过(于82489e796b运行,后续仅移除了agent-core-v2标题摘要内的插话续接判定)。pnpm exec tsc -p packages/agent-core-v2/tsconfig.json --noEmit:通过。pnpm lint:0 退出(本地旧构建目录apps/kimi-code/dist-web因上游将忽略项改名为web-dist而暴露,验证时临时挪开后已原样恢复;提交内容本身注释检查、oxlint、导入边界及全部守卫均通过)。pnpm run check:duplication 1f91363eb6:通过,无新增重复。未验证项:未在 Windows / Linux 本地运行(本次仅涉及纯 TypeScript 字符串格式化与条件过滤,不涉及路径分隔符、子进程、shell 或终端输入);未跑真实界面录屏(未改前端代码)。
Checklist
/approve).gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.