Skip to content

feat: group implicit projects by git repository - #5204

Merged
Grapedge merged 13 commits into
mainfrom
feat/worktree-project-grouping
Nov 25, 2026
Merged

Grapedge merged 13 commits into
mainfrom
feat/worktree-project-grouping

Conversation

@Grapedge

@Grapedge Grapedge commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

Requirement or Bug

CLI 会为启动 kimi 的每个目录自动建一个隐式项目(桌面端里手动建的叫手动项目)。用户用 git worktree add 给同一个仓库另开一个工作文件夹,在里面运行 kimi 时会遇到三个问题。已经信任过的仓库又问一次信任。桌面端侧边栏里同一个仓库出现好几个项目。桌面端还能改隐式项目的主目录,改完以后在终端里打开原来的目录,kimi 却在改过的目录里运行。

这个 PR 让隐式项目按 git 仓库归组。worktree 和子目录里新开的会话归到仓库的项目,沿用它的信任,同时留在自己启动的目录里工作。隐式项目的主目录改为只读。

Bug Reproduction Steps

  1. 在仓库 ~/app 里运行 kimi,选择信任。
  2. 运行 git worktree add ../app-fix,再 cd ../app-fix && kimi,又弹出信任提示。
  3. 打开桌面端,侧边栏里有 app 和 app-fix 两个项目。
  4. 在桌面端把 app-fix 项目的主目录改成别的目录,回到终端 cd ../app-fix && kimi,初始工作目录是改过的目录,不是 app-fix。

Root Cause

隐式项目的 id 是启动目录的哈希。CLI 从不看目录属于哪个仓库,所以每个 worktree、每个子目录都成了独立的项目,各自要信任。会话也不记自己的工作目录,而是跟着项目主目录走,所以桌面端一改主目录,CLI 的会话也跟着挪走。这是根本修复。项目归属改由一个解析器按仓库决定,会话在主目录以外启动时记下自己的目录。

Code Changes

核心思路。 所有创建隐式项目的入口都走同一个解析器,包括 TUI、kimi -p、SDK、只传 workspace_root 的 KAP 请求、ACP 和会话导入。启动目录自己已经有带会话的隐式项目,就继续用它,老数据原样保留。否则从磁盘认出目录所在仓库的主检出(仓库最初所在、放着 .git 目录的文件夹),复用或创建它的项目。不在仓库里,就和以前一样按目录建项目。会话在主目录以外启动时,把起始目录记进 state.json 里已有的 environmentCwd。项目受信任,当且仅当它的主目录有信任记录。

flowchart TD
  D[启动目录 D] --> R1{D 自己的隐式项目里有会话}
  R1 -- 有 --> P1[用 D 自己的项目]
  R1 -- 没有 --> L{认出 D 所在仓库的主检出 M}
  L -- 是,且 M 不是 home 或其上级 --> P2[复用或创建 M 的项目]
  L -- 否 --> P3[复用或创建 D 自己的项目]
Loading

第一条规则保住已经有会话的老项目,不迁移任何数据,只有新目录才归组。认主检出只读磁盘上的 .git 文件,不调用 git。worktree 的指针文件要和 git 写下的反向指针对得上才归组,伪造的或读不懂的 .git 让目录自成项目。

内容跟谁走。 会随分支变的内容跟工作目录,不会变的跟项目。

内容 跟谁 在 worktree ~/app-fix 里的会话
信任、项目名、附加目录 项目 用 ~/app 项目的
AGENTS.md、skills、agents、local.toml 工作目录 读 ~/app-fix 的
项目级 MCP 会话所在的检出 读 ~/app-fix 的配置,服务在 ~/app-fix 启动

项目级 MCP 每个检出一套,配置从项目主目录在这个检出里的对应位置读。子目录自己的 .kimi-code/mcp.json 不再读。信任现在覆盖整个仓库,而 node_modules 或解压进来的目录里也可能带着这个文件,不能不经确认就运行里面的命令。

隐式项目的主目录只读。 改它会把 CLI 的会话带到别处。核心报 workspace.primary_immutable,KAP 返回新错误码 40941,桌面端不再显示「设为主目录」。手动项目不受影响。

KAP。 POST /sessions 同时给 workspace_id 和 workspace_root 时,隐式和手动项目用同一条规则。workspace_root 和主目录在同一个 git 仓库里就放行,否则必须等于主目录,和以前一样返回 40001。附加目录不算。会话在哪个目录启动就在哪里运行,不在主目录的会话在响应的 environment_cwd 里报告这个目录。会话里的 agent 按 kap.md 再开会话时,要带上自己的 environment_id 和 environment_cwd,否则新会话会跑到主目录。

桌面端。 侧边栏只按项目 id 分组会话。选中会话时,文件树、diff、终端、Open In、会话信息和 @ 补全以会话的工作目录为根,草稿页用项目主目录。「已归档」页按项目分组。

关键决策
决策 选择 没选 理由
怎么认出主检出 只读磁盘上的 .git、gitdir、commondir、core.bare、core.worktree 调用 git rev-parse、git worktree list 实测快一个数量级(0.08 到 0.53 ms,git 进程约 5.5 ms);不依赖 PATH 和 GIT_* 环境变量;能识破伪造的 core.worktree
已经有会话的老项目 原样保留 迁到主检出的项目 不改写落盘数据,老会话照常可见、可续
主检出是 home 或其上级 不归组 照常归组 把 home 做成 dotfiles 仓库的用户,home 下所有目录会并成一个项目
信任判定 只看主目录的记录 目录集里任一目录有记录就算 信任要有唯一的归属
什么时候记会话的工作目录 只在起始目录不是主目录时 每个会话都记 在主目录启动的会话和以前一样跟着主目录走
项目级 MCP 读哪里 每个检出一套,从主目录的对应位置读 从会话自己的目录读 信任覆盖整个仓库之后,子目录里的配置会不经确认运行命令
隐式项目改主目录 拒绝 允许 允许就会让 CLI 跑到别的目录,正是问题 3
kimi -c 续哪个会话 隐式项目里工作目录恰好是当前目录的最新会话 前缀匹配,或者也看手动项目 主检出和 worktree 的会话互不串
拆成更多 PR 不拆 解析器、会话目录、桌面端各开一个 解析器单独合入时,worktree 的会话会跑在主检出里;另外两部分单独合入没有使用方
旧路径和新位置
旧位置 做的事 新位置
各入口各自 acquire({ cwd })、createOrTouch 按目录哈希找或建项目 IWorkspaceService.resolveImplicit,只读查询用 peekImplicit
信任的 forRoots 目录集里任一目录有记录就受信任 forProject 只看主目录,改主目录时把记录带过去
SDK 的 workspaceIdsFor 隐式项目及别名,加上目录集包含它的手动项目 只看隐式项目,工作目录恰好相等
TUI -r 的 listSessions({ sessionId, workDir }) 只在目录视图里找 按 id 在所有项目里找,再比较工作目录
KAP POST /sessions 的目录校验 给了 workspace_id 时必须等于主目录 同仓库规则
KAP 按路径读文件 为路径找或建项目 路径正好是已有隐式项目的主目录时用它,否则直接读,不登记项目
唯一的项目根视图 AGENTS.md、skills、agents、local.toml 从主目录读 每个工作目录一个视图,根视图只在有人用到主目录时才打开
一个项目一套 MCP 从主目录读 每个检出一套
桌面端面板和 @ 补全 以项目主目录为根 以会话的工作目录为根
阅读指南
  1. packages/agent-core-v2/src/app/git/workTree.ts 讲各种 .git 布局怎么认。
  2. packages/agent-core-v2/src/app/workspace/implicitProject.ts 是三条规则的纯函数。
  3. packages/agent-core-v2/src/app/workspace/workspaceService.ts 实现 resolveImplicit、主目录只读和复活已删除的项目。
  4. packages/agent-core-v2/src/app/workspace/projectWorkDir.ts 判断一个目录能不能在项目里当工作目录,以及它在哪个检出里对应主目录。
  5. packages/agent-core-v2/src/session/workspaceContext/workspaceRoots.ts 决定什么时候记会话的工作目录。
  6. packages/agent-core-v2/src/program/programWorkdirs.ts 和 programMcpSets.ts 给每个工作目录一个视图、每个检出一套 MCP。
  7. packages/kap-server/src/routes/sessions.ts 是 KAP 的放置规则。
  8. packages/node-sdk/src/sdk-rpc-client-v2.ts 决定目录查询用哪个视图、怎么列目录的会话。
  9. packages/app-core/src/lib/panelRoots.ts 决定桌面端面板的根。

信任、权限规则和 MCP 注册表的改动,是改成读项目主目录或会话所在的检出。CLI 改的是数据来源和文案。这些可以略读。

Behavior Changes and Affected Users

Behavior Before After Who relies on the old behavior Escape hatch
在 git 仓库的 worktree 或子目录启动(TUI、kimi -p、VS Code、ACP、只传 workspace_root 的 KAP 请求、会话导入) 每个目录一个隐式项目,各自问信任 归到主检出的项目,沿用它的信任;有会话的老项目、主检出是 home 或其上级、主目录被旧版本改过的隐式项目不归组 想让每个 worktree 单独信任的用户 在桌面端为这个目录建手动项目
信任判定 目录集里任一目录有记录就受信任 只看主目录的记录;改手动项目的主目录时带走信任 只靠附加目录、local.toml 目录或 --add-dir 目录的记录才受信任的项目;早先改过主目录的手动项目 再信任一次
TUI 信任提示(所有用户) Trust this folder?,显示启动目录 Trust this project?,显示项目主目录 解析 TUI 文本的脚本 无
TUI 读不出项目或它的信任记录 照常提示信任,带 Could not inspect project settings. 报错退出,说明信任设置存在哪里;只有要披露的内容读不出时才照常提示 无 修好后重新运行
kimi -p 未信任警告(所有用户) this folder is not trusted,让用户选不存在的 Trust this folder this project is not trusted,选项名改成真实存在的 Trust and continue;不再列出 enabled: false 的服务 解析 stderr 的脚本 无
kimi -c、kimi -p -c、会话选择器、kimi session list、kimi fork、kimi export 的默认会话 当前目录的隐式项目,加上目录集包含当前目录的手动项目 所属隐式项目里工作目录恰好是当前目录的会话 在手动项目的目录里用这些命令找桌面端会话的用户;解析 kimi session list --json 的脚本 kimi session list --all、kimi -r <id>
kimi -r <id> 只在当前目录的会话里找 在所有项目里按 id 找;会话不在当前目录时提示 cd,目录已删时说明;信任按会话所属的项目问 解析 stderr 的脚本 无
新会话的工作目录 跟随项目主目录 在主目录启动的仍跟随;在别处启动的留在起始目录 无(以前 CLI 的起始目录总是主目录) 无
AGENTS.md、skills、agents、local.toml 从项目主目录读 从会话的工作目录读 无(以前 CLI 的工作目录就是主目录) 无
worktree、子目录会话的附加目录 各自项目的附加目录 仓库项目的附加目录;/add-dir 选「记住」写到仓库项目 无 无
/add-dir 自己的工作目录并选「记住」 工作目录不是主目录时,写进项目的附加目录 不登记 无 无
登记成附加目录的 worktree 里的会话 拿到项目主目录作附加目录,主检出的技能和 @ 候选也会出现 只拿项目的其他附加目录 用 environment_cwd 把会话钉在登记目录、又要访问主目录的 KAP 客户端 用 --add-dir 或 /add-dir 加上主目录
隐式项目吸收手动项目的附加目录 吸收 不吸收 在桌面端给手动项目加附加目录、又在同一目录用 CLI 的用户 CLI 里 /add-dir
项目级 MCP,子目录会话 读子目录的 .kimi-code/mcp.json(先问信任) 读所在检出根的文件;有会话的老子目录项目照旧 在子目录放 .kimi-code/mcp.json 的用户 把文件移到检出根
项目级 MCP,worktree 会话 worktree 自成项目,读 worktree 的 同一个项目,仍读 worktree 的,在 worktree 里启动 无 无
内置技能 mcp-config、import-from-cc-codex 的提示词(逐句见下) 项目级 Kimi MCP 写到 <cwd>/.kimi-code/mcp.json 写到 <project root>/.kimi-code/mcp.json;<cwd> 在子目录时先向用户说明 用这两个技能配置 MCP 的会话 让模型写到别处
文件历史的保留窗口 每个项目最近 30 个会话 在主目录以外运行的本地会话,按项目加工作目录各算 30 个 无 无
隐式项目的 setPrimary 成功 核心报错,KAP 返回 40941,桌面端不显示入口 桌面端用户;调这个接口的 KAP 客户端;老版本在界面建的、落盘为隐式的项目 改用手动项目
KAP POST /sessions 只传 workspace_root 或它的别名 进这个目录自己的隐式项目 在 git 仓库里时进主检出的项目,会话在这个目录运行 用 workspace_root 推算项目 id 的 KAP 客户端 从响应里取 workspace_id
KAP POST /sessions 同时给 workspace_id 和 workspace_root workspace_root 必须等于主目录 同仓库规则;按真实路径比较,指向仓库外的符号链接和不存在的目录返回 40001 依赖这个校验报错的 KAP 客户端 无
KAP 会话响应 只有显式钉住目录的会话带 environment_cwd 在主目录以外启动的会话都带 environment_cwd,值是它运行的目录 无 无
KAP 按路径读文件 为路径登记一个项目 不登记 无 无
SDK 的目录查询(技能、附加目录、suggestFiles、项目级 MCP、信任信息) 按目录所属项目的主目录回答 按在这个目录新建的会话会看到的回答;不存在的目录报错 在 worktree 或子目录调用这些接口的 SDK 用户 无
SDK listSessions({ workDir }) 隐式和手动项目里的会话 只有隐式项目里工作目录恰好相等的会话 SDK 用户;VS Code 扩展的欢迎语对只有桌面端会话的文件夹显示「第一次使用」 listSessions() 列全部
SDK 报告的会话 cwd 写索引时的目录;主目录被改过的隐式项目里,老会话报原来的目录 会话实际运行的目录 无 无
工作目录已删除的会话 CLI 提示 cd 到不存在的目录 能打开、看历史、改名、归档、删除;继续对话报目录不存在 解析 kimi -r stderr 的脚本 无
主检出的 .kimi-code/local.toml 写坏 进程退出并打印堆栈 worktree 会话不受影响;主检出里报出 TOML 错误后退出 无 无
kimi export 的 manifest workspaceDir 是项目主目录 会话的工作目录 解析导出文件的脚本 无
桌面端面板和 @ 补全 以项目主目录为根 以会话的工作目录为根,草稿页用主目录 无 无
桌面端侧边栏 不在项目列表里的项目,用会话目录兜底匹配 只按项目 id 分组;遇到没见过的 id 时重拉项目列表 无 无
在 worktree 或子目录里运行 kimi app 复用这个目录自己的隐式项目 桌面端为它新建手动项目,要信任一次;CLI 的会话在仓库的项目下 在 worktree 里用 kimi app 的用户 在仓库的项目里继续 CLI 的会话
设置里「已归档」页 按会话目录分组 按项目分组,组名是项目名 无 无

相对的 --agent-file 仍按启动目录解析,相对的 --skills-dir、extra_skill_dirs、extra_agent_dirs 仍按工作目录所在检出的根解析,和改动前一样。

内置技能的提示词改动(packages/agent-core-v2/src/features/skill/catalog/builtin/),逐句列出:

位置 原句 新句
mcp-config.md,Project-root 一条 <project root>/.mcp.json, where project root is found by walking up from <cwd> to the nearest .git. 补上 or is <cwd> when there is none,和读取逻辑一致
mcp-config.md,Project-local 一条 Project-local: <cwd>/.kimi-code/mcp.json. Use for Kimi-specific overrides in the current working directory. Project-local: <project root>/.kimi-code/mcp.json. Use for Kimi-specific overrides; Kimi does not read this file from subdirectories. When <cwd> is not the project root, say in the announcement before the write that Kimi loads this file for sessions anywhere in this git checkout, while a project opened directly at <cwd> (for example one created for this folder in the desktop app) reads <cwd>/.kimi-code/mcp.json instead.
import-from-cc-codex.md,目标位置清单 Project-local MCP: <cwd>/.kimi-code/mcp.json, because Kimi reads the current working directory's Kimi-specific MCP file, not every project-root .kimi-code/mcp.json from subdirectories. Project-local MCP: <project root>/.kimi-code/mcp.json, because Kimi reads the Kimi-specific MCP file at the project root, not .kimi-code/mcp.json files in its subdirectories.
import-from-cc-codex.md,disabledMcpjsonServers 的建议 Suggest a complete server entry with "enabled": false in <cwd>/.kimi-code/mcp.json 位置换成 <project root>/.kimi-code/mcp.json,其余不变
import-from-cc-codex.md,选目标作用域 … project-local Kimi MCP target (<cwd>/.kimi-code/mcp.json). If <cwd> is not the project root, call this out in the preview so the user understands when Kimi will load it. … project-local Kimi MCP target (<project root>/.kimi-code/mcp.json). If <cwd> is not the project root, say in the preview that Kimi loads it for sessions anywhere in this git checkout, while a project opened directly at <cwd> … reads <cwd>/.kimi-code/mcp.json instead.

这些句子只发给激活了这两个内置技能的会话,也就是用户运行 /mcp-config 或导入技能,或者模型自己调用它们的时候。原句让模型把项目级 Kimi MCP 写进当前目录。这个 PR 之后,子目录里的这个文件不再被读,照原句写会静默失效。新句改成写到检出根,也就是 Kimi 实际读取的位置。只有桌面端为子目录建的项目还读子目录里的文件,模型分不清这种情况,所以要求它写入前向用户说明。

契约。 改动的契约文件是 packages/kap-server/docs/kap.md、packages/kap-server/schema/contract.txt、packages/node-sdk/src/index.ts 和 apps/kimi-code/src/cli/。contract.txt 只多了 POST /workspaces/{id}/primary 返回 40941 的形状,HOST_API_LEVEL 不变。kap.md 写了新的放置规则和 40941。SDK 只做加法,新增 sameDir、resolveSessionPlacement、信任信息里的 projectRoot 和信任查询的 sessionId;listSessions({ workDir }) 的语义变化见上表。使用方是本仓库的桌面端和 Web 端、会话里按 kap.md 调 KAP 的 agent、VS Code 扩展(经 SDK)、Zed 等 ACP 客户端和 SDK 用户。旧版本写的数据都能继续读。projects.json 的 schema_version 仍是 2,没有新字段。会话索引每行只多一个可选的 projectRoot,旧版本读索引时忽略它。老会话没有 environmentCwd,按跟随主目录处理。

上表多数行没有开关形式的逃生口,行为在设计阶段定下,请维护者在这个 PR 里确认。

已知限制。

  • 旧版本的 CLI 或 VS Code 扩展在 worktree 里建过会话的,那个 worktree 自成项目,在桌面端删掉那个项目后才归组。
  • 主检出整个被移走,或者 git worktree move 之后,kimi -c 按会话记下的目录找,找不到搬走前的会话。
  • 会话开着时手动项目改了主目录,worktree 会话用哪套 MCP 要到重新打开才变。
  • separate-git-dir 仓库的 worktree 不归组。
  • 主目录被旧版本改过的隐式项目,在原目录启动的会话跑在原目录,项目级 MCP 和信任仍按改过的目录算。
  • KAP 客户端用符号链接写法传主检出的路径时,它的 worktree 不会归到同一个项目。
受影响模块与测试覆盖
  • 主检出定位器的用例在 packages/agent-core-v2/test/app/git/gitService.test.ts,覆盖各种 .git 布局、伪造的指针、裸仓库、config.worktree、CRLF 和 Windows 写法,布局夹具在 checkoutLayouts.ts。
  • 解析器的三条规则和 home 保护在 implicitProject.test.ts。两个进程同时解析只产生一个项目、清空 projects.json 后重建、删掉老项目后归组、复活已删除的项目、主目录只读、改主目录后带走信任,在 workspaceService.test.ts。
  • 一个目录能不能当工作目录、它在各个检出里对应的位置,在 projectWorkDir.test.ts。
  • 会话的工作目录、每个工作目录一个视图、坏掉的 local.toml 只影响用它的会话,在 workspaceRoots.test.ts、program.test.ts、workspaceDirsService.test.ts、workspaceSessionsService.test.ts。
  • MCP 每个检出一套(主检出、worktree、子目录、裸仓库、目录已删、符号链接、远端会话),在 programMcpSets.test.ts 和 mcpRegistry.test.ts,真实的 kimi -p 在 apps/kimi-code/test/cli/print-mcp.test.ts。
  • 信任在 workspaceTrust.test.ts,SDK 里另有「已信任的目录被仓库的 local.toml 列出,项目照样问信任」和「读不出要披露的内容时仍给出准确的主目录」两条。
  • 文件历史的保留窗口在 fileHistory.test.ts,KAP 的 fork 和删除也各有用例。
  • KAP 的用例走真实入口。sessions.test.ts 覆盖只传 workspace_root 归组、同仓库规则、范围外 40001、符号链接、fork、environment_cwd 的报告和目录删除后仍能打开。workspaces.test.ts 覆盖 40941,fs.test.ts 覆盖按路径读文件不登记项目,skills.test.ts 覆盖登记成附加目录的 worktree 用自己的技能。
  • 跨进程恢复在 tests/scenarios/cold-recovery.test.ts。
  • SDK 和 ACP 在 sdk-rpc-client-v2.test.ts、list-sessions.test.ts、acp-server/test/lifecycle.test.ts。
  • CLI 在 kimi-tui-startup.test.ts、v2-run-print.test.ts、import-sessions.test.ts 和 tests/e2e/scenarios/workspace/(tests/e2e/surfaces/tui.ts 已同步更新为等待 Trust this project?)。
  • 桌面端在 packages/app-core/test/panelRoots.test.ts、packages/app-client/test/workspaces-store.test.ts、files-store.test.ts、session-list-store.test.ts、apps/desktop/tests/renderer/sessionPanelRoots.test.ts 和已归档页的组件测试。

改动过的已有测试。 旧断言固定的是这次有意改掉的几种行为,包括隐式项目吸收手动项目的目录、目录集里任一目录有记录就信任、读子目录的 .kimi-code/mcp.json、-c 和 -r 和 listSessions 的目录视图,以及会话一律跟随主目录。删掉了四条原有单测:两条是桌面端 panelAdapters 里和 sessionPanelRoots 重复的用例,一条是 filesPanel.test.ts 里只断言替身的用例,还有一条是 print 模式的「跟随项目的会话从当前项目根恢复」(由索引测试 projects the current primary without changing explicit environment cwd or historical metadata 覆盖)。KAP 的固定端口用例由「只有 worktree 会话时只启动一个进程」的断言覆盖。另因 main 在 #5385 冻结了已停跑的 apps/kimi-code/test/e2e/tui/,移除了本 PR 此前在该目录新增的 project-trust.test.ts 与 working-directory.test.ts;对应行为继续由 packages/node-sdk/test/sdk-rpc-client-v2.test.ts、apps/kimi-code/test/tui/kimi-tui-startup.test.ts 与 tests/e2e/scenarios/workspace/ 覆盖(仅少了一组停跑目录内的独立 PTY worktree 信任串联用例,原本在 CI 中也不运行)。

验证
  • 变基到 main 的 f85f504b8f 后,本机(macOS)通过了完整的 pnpm lint、受影响包与桌面端类型检查(agent-core-v2、kap-server、node-sdk、kimi-code、acp-server、tests/e2e、apps/desktop)、tests/e2e/scenarios/workspace/ 的 2 条 TUI 信任场景,以及与 main 重叠模块的 Vitest 用例(apiSurface、openapi、sessions、acp-server/lifecycle、sessionPanelRoots、session-header-menu-context、panelRoots、kimi-tui-startup、trust-prompt、workspaceDirsService 与 sdk-rpc-client-v2 信任分组)。
  • 更早一次变基到 main 的 2679368ca 后,完整 CI 在 aa513a5c50 上全部通过(跳过项为 main 上暂停的 L0 受保护测试门禁 ci: temporarily pause previous e2e gates #5309、关闭的 Windows 任务和按标签触发的变异测试),本机也通过了 pnpm run check:duplication、agent-core-v2/kap-server/app-core/klient 全套(11,225 条)与 CLI/桌面端渲染层测试(6,466 条;个别超时或需本机 zstd 的用例在 main 上同样失败或单跑通过)。
  • 最近几次评审修复都很小,每个都补了修复前失败的测试,并在 main 和本 PR 上用真实入口并排跑过。修完都重跑了 lint、类型检查和相关测试。
    • 上级目录被换成普通文件的会话会启动主检出的 MCP 服务,main 上不会。改了 programMcpSets.ts 两行,经 KAP 跑了目录被删、上级被换成文件、上级没有权限三种情况,结果和 main 一致。
    • 托管项目改主目录时,如果文件树请求还没返回,面板会停在旧目录的文件上。改了 files.ts,挂载真实的文件面板验证。
    • 显式传了等于主目录的 environment_cwd 的会话会单独占一份文件历史保留列表,同一目录最多保留 60 个会话。改回和项目共用一份,经 KAP 各建 31 个会话验证,保留数和 main 一样是 30。
    • 已归档会话页面里,两个目录名相同的项目显示一样的名字。现在项目名旁边显示路径,和项目选择器一致,挂载真实的设置对话框验证。
    • 工作目录已不存在的会话,读 MCP 配置时会从这个路径往上找 git 根。路径落在另一个仓库下面时,会读到那个仓库的 .mcp.json,并按本项目的信任启动它的服务。现在这类会话只读用户级配置。经 KAP 复现并验证,删掉另一个仓库下的工作目录再恢复会话,那个仓库的命令不再执行。
    • 更早一次只改了一条 KAP 测试、kap.md 的一句话和 changeset。
  • 变基到 main 的 48cdb62be 之后、这些评审修复之前,整条栈上 TUI、ACP、桌面端、Web 四套跨端用例各 65 条全部通过。桌面端 E2E 87 条通过,失败的 1 条 terminal-panel.spec.ts 在 main 上同样失败。
  • 变基前,在 main 和本 PR 上用真实入口并排跑过 53 条旅程,其中 CLI 21 条,桌面端和 kimi web 18 条,升级、仓库布局、并发、远端、VS Code、ACP、会话导入、文件历史和重启恢复 14 条。桌面端和 kimi web 原本列了 19 条,内置浏览器那条没跑。回归中发现的问题都已修掉并补了测试,和 main 不同的地方都写在上面的表和已知限制里。
  • real-llm-smoke 要连真实模型,没有跑。worktree 会话里的内置浏览器没有验证。Windows 路径由单元测试覆盖,没有在 Windows 和真实 SSH 主机上实测。

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.

@changeset-bot

changeset-bot Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 301742a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 11 packages
Name Type
@moonshot-ai/kimi-code Patch
@moonshot-ai/agent-core-v2 Minor
kimi-code-app Patch
@moonshot-ai/kap-server Minor
@moonshot-ai/klient Minor
@moonshot-ai/migration-legacy Patch
@moonshot-ai/kimi-code-sdk Minor
kimi-code Patch
@moonshot-ai/acp-server Patch
@moonshot-ai/kimi-code-product Patch
@moonshot-ai/remote-control Patch

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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 21, 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-25T10:04:23.695556Z 301742a New commits
ℹ️ 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 21, 2026 •

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

commit: 301742a

@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: 270d2cbca9

ℹ️ 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".

Comment thread apps/kimi-code/src/tui/kimi-tui.ts Resolved
@Grapedge
Grapedge added this pull request to stack #5225 November 22, 2026 15:17
@Grapedge
Grapedge force-pushed the feat/worktree-project-grouping branch from e9e75f5 to c4ba5f3 Compare November 23, 2026 04:36
@Grapedge Grapedge changed the title feat: group implicit projects by repository and pin sessions to their working directory feat: group implicit projects by git repository Nov 23, 2026

@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: c4ba5f347f

ℹ️ 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".

@Grapedge
Grapedge force-pushed the feat/worktree-project-grouping branch from c4ba5f3 to 5726a5d Compare November 23, 2026 05:02

@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: 5726a5d870

ℹ️ 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".

Comment thread apps/kimi-code/src/cli/launch-paths.ts Resolved
@Grapedge
Grapedge force-pushed the feat/worktree-project-grouping branch from 5726a5d to 1a526f1 Compare November 23, 2026 05:31

@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: 1a526f15a8

ℹ️ 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".

Comment thread packages/app-client/src/stores/files.ts Resolved
@Grapedge
Grapedge force-pushed the feat/worktree-project-grouping branch from 1a526f1 to 35a522d Compare November 23, 2026 06:05
@Grapedge
Grapedge force-pushed the feat/worktree-project-grouping branch 2 times, most recently from b4b12c3 to 395aa7a Compare November 23, 2026 06:36
@Grapedge
Grapedge force-pushed the feat/worktree-project-grouping branch from 395aa7a to 2395d32 Compare November 23, 2026 06:51

@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: 2395d32c21

ℹ️ 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".

@Grapedge
Grapedge force-pushed the feat/worktree-project-grouping branch from 2395d32 to 8de5b76 Compare November 23, 2026 07:45

@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: 8de5b7638d

ℹ️ 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".

Comment thread .changeset/session-directory-cli.md Resolved
@Grapedge
Grapedge force-pushed the feat/worktree-project-grouping branch from 8de5b76 to 26c6604 Compare November 23, 2026 08:30

@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: 26c66047fc

ℹ️ 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".

…irectory

A session created with only workspace_root, or one of its aliases, joins
the implicit workspace of its repository, and workspace_id with a
workspace_root elsewhere in the root's repository starts the session
there. Sessions report the directory they run in, changing the primary
directory of an implicit workspace returns 40941, and file requests by
path no longer register a workspace.
… them

Skills, additional directories, file suggestions, MCP servers and trust
info for a directory now come from the view a new session in that
directory would use, and listing the sessions of a directory returns those
of its implicit project that run there. Imported and migrated sessions are
placed by the same rule as new ones.
…irectories

Starting in a linked worktree or subdirectory of a trusted repository no
longer asks for trust again, and the prompt names the project and its
primary directory. kimi -c and the session lists use the sessions that ran
in the current directory, and resuming a session whose directory was
deleted says so.
Sessions are grouped with their project by id only, and the file tree,
diff picker, terminals, Open In, session info and @ suggestions open at
the directory a session runs in. Archived sessions in Settings are grouped
by project as well. The primary directory of a CLI project can no longer
be changed, and a removed project shows up again once the server lists it.
…ectory as missing for MCP

When a component of a session's working directory has been replaced by a
file, realpath fails with ENOTDIR. The MCP fallback treated only ENOENT as
a missing directory, so such a session was served by the main checkout's
set and started its servers, while main gives it no project servers.
…s file tree loads

When a session's directory changed while the listing of its old directory
was still in flight, the refresh was skipped because the path was marked as
loading, and the old response then filled the tree. The file panel showed
the former directory's files until a manual refresh.
…the project's file-history list

A session created with an explicit local environment directory equal to the
project's primary directory got its own retention list, so one directory
could keep file history for twice the usual number of sessions. Such
sessions now share the project's list again, as they do on main.
Archived sessions are grouped and filtered by project, labelled with the
project name. A new project is named after the last segment of its
directory, so two projects such as /a/app and /b/app showed the same label
in both the filter and the group headings. Each project now also shows its
path, as the project picker does.
…y that no longer exists

A session whose working directory had been removed got a set of MCP
servers of its own, and loading its config searched upward from the
missing path for a git root. When the path sat under another repository,
that repository's .mcp.json was read and its servers started under the
session project's trust. Such a set now never counts as trusted, so it
reads the user's config only, and it is cached apart from the checkout
sets so that a directory that comes back is served by the checkout rules.
Update the TUI driver in tests/e2e to match the renamed 'Trust this project?' prompt, and remove the paused legacy apps/kimi-code/test/e2e/tui additions blocked by legacy-e2e.mjs on main (the behaviors remain covered by node-sdk, kimi-tui-startup, and tests/e2e/scenarios/workspace).
@Grapedge
Grapedge force-pushed the feat/worktree-project-grouping branch from aa513a5 to 301742a Compare November 25, 2026 10:00
@Grapedge
Grapedge merged commit e6b16c4 into main Nov 25, 2026
25 checks passed
@Grapedge
Grapedge deleted the feat/worktree-project-grouping branch November 25, 2026 10:14
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 25, 2026
MoonshotAI#5204 needs the layered project port, MoonshotAI#5206 is the Workspace -> Project
rename, and MoonshotAI#5292 imports the projectSessions paths both create. Keep them
in dependency order rather than applying 189/320-file patches wholesale.
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 25, 2026
…equivalent

Register the deliberate naming deviation in PLAYBOOK and close the rename
row as equivalent. MoonshotAI#5204/MoonshotAI#5292 are adapted to workspace semantics instead
of importing upstream's project paths.
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 26, 2026
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 26, 2026
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 26, 2026
…5204)

Bring in the core of the implicit-project grouping: GitWorkTree's marker
and checkout location detection, the five workdir-slug helpers the
decision needs, decideImplicitProject, projectDirAt and unlessProjectGone.
The implicitProject suite passes 20; projectDirAt's filesystem/symlink
suite is deferred until it is adapted to this host backend.

The primitives are not wired into project sessions yet; the service and
KAP/session integration follow.
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 26, 2026
…hotAI#5204)

Port the post-rename feature onto the project layer: implicit projects are
grouped by their git repository, project sessions gain listForWorkdir,
ProjectDirsService follows the upstream primary/member/worktree rules, and
trust is carried through the primary directory with the ProjectTrust view.
The session-index parser keeps projectRoot so removed projects can be
revived from the directory their sessions recorded.

Includes the upstream changesets and the reset edge handling and tests.
Verified: agent-core-v2 typecheck clean; project, projectDirs,
projectSessions and implicitProject suites 169 pass / 5 skip;
check:no-comments OK.
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 26, 2026
The fake service now carries resolveImplicit, peekImplicit, reviveImplicit,
projectDirAt and acceptsWorkDir, so the root typecheck stays green after the
project-grouping interface grew.
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 26, 2026
…hotAI#5204)

An absolute fs ref no longer calls createOrTouch: it looks up an existing
implicit project by directory or builds a read-only pick, and a missing or
non-directory path returns undefined. This keeps browsing from minting
project records and follows the upstream grouping rule.
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 26, 2026
…sessions (MoonshotAI#5204)

Session creation and profile cwd moves now call resolveImplicit instead of
createOrTouch, so a session started inside a repository joins its grouped
main-checkout project and a session keeps its own working directory. The
auto-registration path is gone from the KAP session surface.
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 26, 2026
…onshotAI#5204)

The workspaces facade now resolves the implicit project for a directory
through the engine's grouping rule; the contract, facade and round-trip
tests follow. Root and klient typechecks are clean, facade 33 pass.
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 26, 2026
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 26, 2026
…hotAI#5204)

Port the remaining client half of upstream e6b16c4 on top of the landed
core/KAP/klient work: desktop panel roots and archived-project grouping,
app-core panelRoots, app-client activePanelRoots and unseen-project listing,
app-components FilesPanel session roots, CLI launch-path resolution for skill
dirs, TUI session-directory resume hints, SDK resolveSessionPlacement and
WorkspaceTrustInfo.projectRoot, and project-scoped imported sessions.

Fork adaptations:
- the localized trust prompt keeps the fork's workspace wording and the
  standalone session-directory hint; upstream's session-aware project trust
  and its trust-prompt rewrite are not adopted;
- upstream vitest test files are adapted to the fork's bun:test suites, and
  the UI test for MoonshotAI#5351's confirmDiscard stays with that row;
- migration-legacy keeps its own session-index entry writer while writing
  the new project-scoped session layout, and imported sessions keep the
  localized default title;
- the message-flow temp-dir cleanup retries on Windows EBUSY.

Verified: apps/kimi-code and node-sdk typecheck clean; node-sdk
sdk-rpc-client-v2 100 pass / 11 skip; session-import 13, add-dir 9,
run-shell 23, TUI startup 89, message-flow 489 pass / 1 skip,
run-v2-print 27; migration-legacy import/resume 9; desktop renderer 50;
app-client workspaces-store 90, files-store 60, session-info 13;
app-components FilesPanel 7; app-core panelRoots 7. Pre-existing:
app-client workspace-state 212 pass / 13 fail and session-list-store
35 pass / 2 fail (Bun lacks vi.resetModules).
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.

4 participants