Repository navigation
feat: mention other sessions from the @ menu - #5068
Conversation
🦋 Changeset detectedLatest commit: a073486 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 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: aeaf63b549
ℹ️ 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".
| activity: repeatedParam(sessionActivitySchema), | ||
| updated_after: isoDateTimeSchema.optional(), | ||
| updated_before: isoDateTimeSchema.optional(), | ||
| query: z.string().optional(), |
There was a problem hiding this comment.
Advertise query support before clients rely on it
For external KAP clients, or hosts=include when a remote daemon is still on the previous release, the older listSessionsQuerySchema silently strips this unknown parameter and returns an unfiltered successful response. Because this change adds neither a /meta capability nor a host API-level gate, callers cannot distinguish that response from a filtered one and may present or reference unrelated sessions. Advertise a runtime capability and gate use of query, or enforce the filter while aggregating older hosts.
AGENTS.md reference: packages/kap-server/AGENTS.md:L7-L10
Useful? React with 👍 / 👎.
GET /api/v1/sessions accepts an optional query parameter. A session matches when its title or last prompt contains the trimmed text (case-insensitive), or when its id equals the text. A blank query is ignored, and the text is bound into the page_token fingerprint. The filter runs over the session index summaries the route already scans in memory, so it works without the global search index. With hosts=include the parameter reaches every host through the existing query forwarding.
GET /api/v1/meta now includes home_dir, the absolute path of the Kimi Code data directory the server runs on (KIMI_CODE_HOME or the default ~/.kimi-code). Clients that point the model at files under it, such as a referenced session's agents/main/wire.jsonl, no longer have to guess where the server keeps its data.
The package tsconfig sets types to an empty list, so oxlint's type-aware pass saw every `~icons/*?raw` import as an error type and flagged each entry of the icon map as an unsafe assignment. Declare the raw icon module as a string in the package and drop the 16 frozen findings from the ratchet baseline.
Typing @ offers a Sessions entry that opens a submenu of local, unarchived sessions (current workspace first, newest first). The text after @ filters the loaded sessions and, after a short pause, also queries GET /api/v1/sessions?query= on this machine, so sessions outside the loaded sidebar pages can be found by title, last prompt, or exact session id. Picking one inserts a session pill serialized as [title](kimi-code://session/<workspaceId>/<sessionId>). On submit the client appends a <referenced_sessions> block that lists each referenced session's id, title and the absolute path of its main agent wire.jsonl, built from home_dir reported by GET /api/v1/meta and the session layout documented under data locations. The composer snapshot, user bubble, session title and last prompt keep showing only the pill.
00084d8 to
bda5900
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: bda5900323
ℹ️ 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".
| serverVersion: data.server_version, | ||
| serverId: data.server_id, | ||
| startedAt: data.started_at, | ||
| homeDir: data.home_dir, |
There was a problem hiding this comment.
Handle missing home_dir from older servers
When Desktop or Web connects to an older KAP daemon, /meta legitimately has no newly added home_dir, so this returns undefined despite the declared string type and configStore stores that value. After the user selects any session mention, sending the prompt calls sessionLogPath(), which invokes undefined.replaceAll(...) and rejects the send; map a missing field to '' and keep the wire field optional so session references degrade gracefully.
AGENTS.md reference: AGENTS.md:L188-L190
Useful? React with 👍 / 👎.
| export function sessionLogPath(home: string, ref: SessionMentionRef): string { | ||
| const root = home.replaceAll('\\', '/').replace(/\/+$/, ''); | ||
| return `${root}/sessions/${ref.workspaceId}/${ref.sessionId}/agents/main/wire.jsonl`; |
There was a problem hiding this comment.
Route session logs through the host filesystem
When the active session is bound to an SSH, Docker, or custom remote environment, its ordinary Read and Bash operations run in that environment, while home_dir identifies the daemon host's data directory. This host-local absolute path is therefore inaccessible to the model in remote-environment sessions, so every inserted session reference points to a log it cannot read; expose the log through a daemon-backed file reference or another host-filesystem access path instead of embedding the raw host path.
Useful? React with 👍 / 👎.
| @@ -0,0 +1,5 @@ | |||
| --- | |||
| "@moonshot-ai/kimi-code": patch | |||
There was a problem hiding this comment.
Attribute changesets to the changed packages
This changeset is attributed only to the CLI package, but the diff changes the public kap-server API and adds a user-visible Desktop/Web session-mention feature. Without separate @moonshot-ai/kap-server and kimi-code-app entries, release tooling will omit the library version/changelog entry and the Desktop update notes will not announce the feature; add the required package-specific changesets while retaining the CLI entry if its bundled server is also affected.
AGENTS.md reference: AGENTS.md:L166-L167
Useful? React with 👍 / 👎.
The Sessions entry in the @ menu is now off by default. Settings > Lab > Session mentions turns it on; while it is off the menu offers no sessions and the composer sends no session search requests. The switch is a local preference stored in the renderer, like the sidebar tabs switch: server experimental flags only cover the core and TUI surfaces, and this feature lives entirely in the composer.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 17965090a8
ℹ️ 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".
|
|
||
| export function sessionLogPath(home: string, ref: SessionMentionRef): string { | ||
| const root = home.replaceAll('\\', '/').replace(/\/+$/, ''); | ||
| return `${root}/sessions/${ref.workspaceId}/${ref.sessionId}/agents/main/wire.jsonl`; |
There was a problem hiding this comment.
Include the legacy root journal in session references
When a mention targets an older .kimi-code session whose history lives in <session>/wire.jsonl, or a resumed session containing both root and per-agent journals, this hard-coded path is either nonexistent or omits all pre-migration history. Search and export deliberately support the root journal, so these sessions remain selectable, but the model silently receives none or only part of the referenced conversation; resolve the actual journal set server-side or include the legacy root journal.
AGENTS.md reference: AGENTS.md:L109-L110
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a073486531
ℹ️ 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".
| query.includeGit, | ||
| query.pageSize, | ||
| query.projection, | ||
| query.text ?? null, |
There was a problem hiding this comment.
Preserve queryless page-token fingerprints
When a client resumes an ordinary, unfiltered /sessions listing with a page_token issued before this upgrade, appending null to every fingerprint changes the hash even though the request semantics are unchanged, so decodePageToken rejects the token with 40922. This breaks pagination for existing KAP clients across an upgrade; include the new fingerprint component only when query is present, or retain compatibility with the previous queryless fingerprint.
AGENTS.md reference: packages/kap-server/AGENTS.md:L7-L10
Useful? React with 👍 / 👎.
| const sessionMentions = ref<boolean>(safeGetString(STORAGE_KEYS.sessionMentions) === '1'); | ||
|
|
||
| function setSessionMentions(on: boolean): void { | ||
| sessionMentions.value = on; | ||
| safeSetString(STORAGE_KEYS.sessionMentions, on ? '1' : '0'); |
There was a problem hiding this comment.
Use the standard experimental flag mechanism
When operators enable experimental features through KIMI_CODE_EXPERIMENTAL_FLAG, the individual environment variable, or [experimental], session mentions remain disabled because this state is sourced exclusively from browser localStorage; it also bypasses the repository's required flag-precedence model. Back the Lab switch with an environment-driven registered experimental flag instead of a standalone local preference.
AGENTS.md reference: AGENTS.md:L119-L122
Useful? React with 👍 / 👎.
Mark MoonshotAI#5048, MoonshotAI#5068, MoonshotAI#5203 and MoonshotAI#5260 ported with executable grep probes and evidence from the fork commits that carried them.
Requirement or Bug
在一个会话里经常需要参考另一个会话做过的事,比如「接着那个会话的结论往下做」。现在只能手动复制内容或描述那个会话,agent 也不知道去哪里找它的记录。
本 PR 之后,在 desktop 或
kimi web的输入框输入@,可以从「会话」子菜单搜索并引用其他会话。发送时 prompt 里会带上被引用会话主 agentwire.jsonl的绝对路径,agent 用自己的工具去读。这是实验功能,默认关闭,在「设置 > 实验室 > 引用会话」打开。Bug Reproduction Steps
N/A
Root Cause
N/A
Code Changes
核心思路:
@根菜单多一个「会话」入口,进入后列出本机未归档的其他会话,当前工作区优先,按更新时间倒序。@后输入的文字先过滤客户端已加载的会话,停顿 150ms 后再用新增的GET /api/v1/sessions?query=查本机服务端,所以侧边栏没加载到的会话也能找到。选中后插入一个会话 pill,序列化为[标题](kimi-code://session/<workspaceId>/<sessionId>)。发送时,客户端在提交副本末尾追加<referenced_sessions>块,每个被引用的会话一行id、title、log。log由GET /api/v1/meta新返回的home_dir,加上用户文档「数据路径」里写明的布局sessions/<workspaceId>/<sessionId>/agents/main/wire.jsonl拼成。服务端不解析正文里的会话链接;输入框快照、用户气泡、会话标题和 last prompt 里都只显示 pill。整个入口受实验室开关控制:开关关闭,或者当前工作区在远程 SSH 设备上时,菜单里没有会话入口,也不发搜索请求。session,path为<workspaceId>/<sessionId><referenced_sessions>块id、title、loghome_dirGET /api/v1/meta的新字段queryGET /api/v1/sessions的新参数:标题或最后一条消息包含该文本(不区分大小写),或会话 ID 完全相同flowchart LR subgraph Renderer["desktop / kimi web 渲染端"] Pool[(已加载的会话)] Menu[会话入口与二级菜单<br/>本地排序 + 服务端搜索] Doc[输入框文档<br/>session pill] Submit[发送<br/>追加 referenced_sessions] end subgraph Server[kap-server] List["GET /sessions?query="] Meta["GET /meta:home_dir"] end Agent[agent<br/>读取 wire.jsonl] Pool --> Menu Menu -- 防抖查询,只查本机 --> List Menu -- 插入 --> Doc Doc --> Submit Meta -- 启动时读取 --> Submit Submit -- prompt --> Agent菜单只负责找到会话并插入 pill,日志路径到发送时才拼出来。因此草稿、快照和历史消息里只保存会话身份,不保存某台机器上的绝对路径。服务端只补两项事实(按文本过滤会话、报告数据目录),不理解客户端的标记。
wire.jsonl的绝对路径,不附读取说明,模型用自己的文件工具读home_dir加文档里的目录布局拼skills);目录布局已经写在用户文档「数据路径」里GET /api/v1/meta的home_dirKIMI_CODE_HOME,web 猜<home>/.kimi-codeKIMI_CODE_HOME时,只有服务端知道GET /api/v1/sessions?query=POST /api/v1/searchwire.jsonl建索引,结果按消息命中且不能按 ID 查hosts=include)session_开头,子串匹配会让一两个字符的输入命中所有会话;界面里「复制会话 ID」拿到的就是完整 IDHOST_API_LEVEL/meta,会话搜索也只查本机,不依赖远程设备支持新字段kimi-web.session-mentions),和「多标签页的会话列表」一样在「设置 > 实验室」切换registerFlagDefinition,环境变量加[experimental])surface只有 core 和 TUI,这个功能完全在输入框里;服务端新增的query和home_dir对现有调用方没有可见影响,不需要开关提交顺序:
kap-server的两个接口改动、app-composer的类型声明修正、客户端功能、实验室开关。类型声明那个提交是为了加新图标:packages/app-composer/tsconfig.json设了"types": [],类型感知 lint 把每个~icons/*?raw导入都当成 error 类型,图标表里每一项都报 unsafe assignment,原有 16 处冻结在 ratchet 基线里,新加一个图标就会变成 17 处。补上~icons/*?raw的模块声明后这 16 处一起消失,基线相应下调。建议阅读顺序:
packages/app-client/src/composables/useMentionMenu.ts:会话入口和二级菜单的状态、本地排序,以及服务端搜索的防抖、取消与合并。packages/app-client/src/lib/sessionReferences.ts:候选会话的筛选排序,发送时<referenced_sessions>块和日志路径的生成。useKimiWebClient.ts里的sessionMentionsAvailable是唯一的可用性判断(开关已打开,且当前工作区不在远程 SSH 设备上),候选列表和服务端搜索都经过它。packages/kap-server/src/routes/sessionList.ts、packages/kap-server/src/routes/meta.ts:query过滤和home_dir。packages/app-composer/src/model/wireCodec.ts、inlineLinks.ts:session mention 的序列化与解析规则,packages/app-composer/docs/wire-format.md已同步。packages/app-client/src/lib/browserReferenceSubmission.ts、useModelProviderState.ts:追加引用块的接入点(普通发送、steer、side chat、技能参数)。可以略读:
MentionMenu.vue的模板和样式、ComposerText.vue/Markdown.vue/ tooltip 里对sessionkind 的分支(会话 pill 不可点击,不做文件存在性探测)、useSessionMentions.ts和SettingsDialog.vue里的开关行、track-events.ts新增的session-mentions设置键、i18n 词条、测试、kap.md、契约摘要和 ratchet 基线。发送时提交给服务端的文本,也就是模型看到的内容(示例里的 ID 和路径是占位值):
正文里的会话链接原样保留,引用块追加在最后。同一个会话引用多次只列一行,属性值做 XML 转义,
home_dir里的反斜杠统一成/。服务端没有返回home_dir时不追加引用块,消息照常发送。会话菜单的细节:候选、排序与搜索
GET /api/v1/sessions?query=…&page_size=50&has_prompt=true,只查本机,结果和本地结果合并去重。新的输入会取消还没返回的旧请求,搜索进行中显示加载状态。目前的边界:
wire.jsonl,不包括子 agent 的日志。kimi web要各自打开,KIMI_CODE_EXPERIMENTAL_FLAG=1也打不开它(原因见上表「实验开关放在哪」)。Screenshots / Recordings
「设置 > 实验室」新增「引用会话」开关,默认关闭:
打开开关后,输入
@进入「会话」,二级菜单列出本机的其他会话,右侧是所属工作区和更新时间:输入关键词后,子菜单找到了不在已加载列表里的目标会话(测试数据共 58 个会话)。上方是之前发送的消息:用户气泡只显示会话 pill,模型读取了被引用会话的
wire.jsonl:Behavior Changes and Affected Users
query的GET /api/v1/sessionsquery的GET /api/v1/sessionsquery作为未知参数被忽略,返回未过滤的列表queryquerypage_tokenhosts=include且带queryquery转发给每台设备;旧版本设备会忽略它,返回该设备未过滤的会话hosts=include只查本机GET /api/v1/meta的响应home_dirhome_dir(服务端数据目录的绝对路径)@菜单kimi web用户<referenced_sessions>块,随消息存进会话记录;TUI 和GET /turns会看到这段 XML,desktop 与 web 的气泡按快照渲染,只显示 pill契约文件的消费者:desktop 与
kimi web(本 PR 消费query和home_dir)、外部 KAP agent(kap.md由运行中的服务端直接下发,写了这两项就意味着这个服务端支持)。上一版本的客户端不发送query、不读取home_dir,行为不变。受影响模块与测试覆盖:
kap-server会话列表:sessionList.test.ts新增「按标题、最后一条消息不区分大小写的子串或完整 ID 过滤」(覆盖 ID 片段不命中、空白参数不过滤、分组视图)和「query计入page_token指纹」;hostAggregation.test.ts新增「query转发给本机列表和每台设备」。kap-servermeta:meta.test.ts新增「home_dir等于服务端的数据目录」;apiSurface.snapshot.test.ts契约摘要更新,apiLevel保持 1。app-core:daemon-client.test.ts(只查本机的搜索请求不带hosts=include)、configClient.test.ts(映射home_dir)。app-composer:composer-model.test.ts、snapshot.test.ts(session 链接的分类、round-trip、畸形链接保持纯文本、快照接受sessionkind)。app-markdown:MarkdownFilePathLinks.test.ts(助手消息里的会话链接渲染为不可点击的 pill)。app-client:useMentionMenu.test.ts(入口位置、二级菜单进出、过滤与插入、lastPrompt和完整 ID 匹配、服务端搜索的防抖、过期请求被忽略、加载状态、关闭后清空结果)、session-references.test.ts(候选筛选排序、引用块转义与去重、home_dir未返回时不追加;实验室开关关闭时没有候选、不请求服务端搜索,打开后两者恢复,开关状态写入本地存储)。验证记录
pnpm lint:通过(注释检查、oxlint、import 边界、guards、ratchet、说明文件检查)。pnpm --filter kimi-code-app run typecheck、pnpm --filter @moonshot-ai/kap-server run typecheck:通过。pnpm exec vitest run --reporter=agent覆盖上述 4 个 kap-server 测试文件、全部packages/app-*和apps/desktop/tests:651 个文件、10043 个用例通过。加上实验室开关之后,全部packages/app-*和apps/desktop/tests重跑:647 个文件、9962 个用例通过(kap-server 之后没有改动)。packages/kap-server全量 1421 个用例通过;apps/kimi-code/test/cli/web/web.test.ts76 个用例通过。KIMI_CODE_HOME和一个兼容 OpenAI 的假模型。GET /meta返回的home_dir是这个自定义目录;造 58 个会话,让目标会话不在已加载的列表里,按关键词和完整 ID 都能在子菜单里找到它;请求为GET /api/v1/sessions?page_size=50&has_prompt=true&query=…,不带hosts=include;模型收到的引用块里log指向自定义目录下的wire.jsonl,模型调用Read后读到了被引用会话里的标记文字。@,菜单里没有「会话」入口(测试工作区没有文件,显示「无匹配」);在「设置 > 实验室」打开后,@菜单出现「会话」入口,二级菜单列出会话。home_dir里的反斜杠会被统一成/,这一点有单元测试覆盖。Checklist
/approve).gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.