Skip to content

feat(agent-core-v2): add Git worktree service, session presence, and SDK APIs - #5292

Merged
Grapedge merged 17 commits into
mainfrom
feat/worktree-core
Nov 25, 2026
Merged

Grapedge merged 17 commits into
mainfrom
feat/worktree-core

Conversation

@Grapedge

@Grapedge Grapedge commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Requirement or Bug

在同一个 Git 仓库中并行推进多个任务时,单工作目录会导致分支切换与未提交改动互相干扰。本 PR 作为 Git worktree 能力的底层 PR(基于已合入的 #5204 与 #5206),在引擎与 SDK 中提供完整的 Git worktree 生命周期、活跃会话占用检测、按项目列出跨 worktree 会话,以及缺失工作目录的回合提醒;CLI 与 TUI 交互层放在后续堆叠 PR 中实现。

Bug Reproduction Steps

N/A

Root Cause

N/A

Code Changes

核心思路

所有 worktree 能力完全建立在 stack/5225 的项目模型之上:同一 Git 仓库的主目录、子目录和所有 linked worktree 天然归属同一个 Project,单个会话仍使用单一 workDir 指向实际工作目录,不再引入额外的目录映射层。核心服务拆分为独立的 IWorktreeService、ISessionPresenceService 与 IProjectSessions.listForProject,通过 @moonshot-ai/kimi-code-sdk 暴露给上层宿主,并由默认关闭的实验开关 experimental.worktree 控制。

概念

概念 回答什么问题 本 PR 之后
WorktreeCheckout 当前目录位于哪种 Git 布局下 复用与 locateCheckout 一致的 git rev-parse 定位;普通仓库、bare 仓库派生的 linked worktree、submodule 与分离 git 目录均可工作,bare 仓库根目录返回未处于工作树
Managed worktree Kimi 创建并管理的隔离工作区放哪里 统一放在 <kimiHome>/worktrees/<projectId>/<name>,默认以 detached HEAD 检出,不污染源仓库分支列表;list/inspectRemoval/remove 覆盖同一仓库的全部 linked worktree(按 managed 区分排序,主仓库禁止删除)
SessionPresence 删除 worktree 前,该目录下是否有其他进程正在运行会话 基于会话数据目录的轻量 PID 记录,查询时通过进程存活探测过滤僵尸记录,并在 fork 与会话导出时自动排除
Missing-workdir reminder 会话对应的 worktree 被删除后继续对话,模型如何知道目录已不存在 回合开始前检测到绑定的本地 cwd 不存在时,向当轮上下文注入一条客观事实提醒,不改动任何 .md 系统提示词

结构图

flowchart LR
    SDK["@moonshot-ai/kimi-code-sdk\n(worktree APIs / scope: project / projectWorkDir)"]
    WT["IWorktreeService\n(locate / create / include / setup / status / remove)"]
    PRES["ISessionPresenceService\n(PID-backed occupancy)"]
    PSESS["IProjectSessions\n(listForWorkdir / listForProject)"]
    ENV["environmentBinding\n(missing-workdir turn reminder)"]
    TUI["@moonshot-ai/pi-tui\n(Editor.clearHistory)"]

    SDK --> WT
    SDK --> PSESS
    WT --> PRES
    WT -.共享项目归属.-> PSESS
    ENV -.每轮检查 cwd.-> PSESS
Loading

上述模块按职责分层,上层 CLI/TUI 只通过 SDK 契约访问 worktree 生命周期和项目级会话列表,不直接拼装 git 命令或读取持久化内部文件。

关键决策

决策 选择 没选 理由
新建 worktree 默认检出方式 默认 detached HEAD,可选指定 base(分支 / tag / commit) 自动创建本地分支 避免大量临时任务产生残留本地分支,需要保留时由用户按需切分支
Git 仓库布局支持 跟随 stack/5225 的 locateCheckout,支持普通仓库、bare 派生 linked worktree、submodule、分离 git 目录;bare 仓库根目录拒绝 仅支持普通仓库根目录,或强行在 bare 根目录执行 .worktreeinclude / setup 与项目分组心智模型一致,避免在无工作树的 bare 根目录误跑文件复制和脚本
目录缺失时的模型提示 仅在回合开始前注入一条客观事实提醒(目录已不存在),不修改 system.md 修改系统提示词或将缺失目录会话锁定为只读 仅告知客观事实即可让模型自行判断后续动作,不干扰未涉及该场景的会话,也保留在原会话中继续对话的能力
删除前占用保护 基于 PID 文件的轻量 presence 跟踪 仅依赖当前进程内存态 防止在另一个终端仍打开该 worktree 会话时误删目录;进程异常退出后靠 PID 存活探测自动忽略失效记录

阅读指南

建议按以下顺序阅读:

  1. packages/agent-core-v2/src/app/worktree/ — 看 worktreeService.ts、worktreePorcelain.ts、worktreeCheckout.ts 和 worktreeInclude.ts,了解定位、detached HEAD 创建、.worktreeinclude 复制、setup 脚本流式执行、脏状态统计与删除保护。
  2. packages/agent-core-v2/src/app/sessionPresence/sessionPresenceService.ts 与 packages/agent-core-v2/src/persistence/backends/node-fs/processLiveness.ts — 了解 PID 占用登记与僵尸记录过滤。
  3. packages/agent-core-v2/src/app/projectSessions/projectSessionsService.ts — 了解 listForProject 如何汇总同一项目下所有 worktree/子目录的会话。
  4. packages/agent-core-v2/src/agent/environmentBinding/ — 了解缺失目录回合提醒的注入条件与文本。
  5. packages/node-sdk/src/worktree.ts 与 packages/node-sdk/src/index.ts — 了解对外公开的 SDK 契约与错误码。
  6. packages/pi-tui/src/components/editor.ts 与 packages/pi-tui/UPSTREAM.md — 了解新增的 Editor.clearHistory() 及上游分叉登记。

其余文件为 DI 注册、错误码导出、参数透传、changesets 与单元测试,可略读。

Behavior Changes and Affected Users

行为 改动前 改动后 依赖旧行为的人群 退路
experimental.worktree 开关 不存在 注册实验开关,默认关闭;可通过 KIMI_CODE_EXPERIMENTAL_WORKTREE=1 或 [experimental] worktree = true 开启 所有客户端(CLI/TUI、Desktop/Web、VS Code、ACP、SDK)默认关闭无影响 默认关闭
会话绑定目录已删除时的回合上下文 回合开始前不提示,工具调用报错后模型才知道目录不存在 本地绑定 cwd 不存在时,每轮注入单条客观提醒 The working directory `<cwd>` no longer exists.;不改动任何 .md 系统提示词文件 使用 agent-core-v2 恢复已被删除目录会话的客户端(CLI/TUI、Desktop/Web、VS Code、ACP、SDK) 无(仅补充客观环境事实,不改变工具或权限约束)
listSessions 与 SessionSummary 仅支持按当前目录或全部列出;摘要不含 projectWorkDir 新增可选参数 scope: 'project' 与可选字段 projectWorkDir;未传 scope 时行为不变 既有 SDK 调用方、CLI、Desktop/Web、VS Code 向后兼容扩展,不传 scope 保持原行为
新增 SDK worktree 接口与错误码 无 在 KimiHarness / SDKRpcClientV2 暴露 worktree 增删查与 setup 脚本接口及 worktree.* 错误码 既有 SDK 调用方 纯增量公开 API
Editor.clearHistory()(@moonshot-ai/pi-tui) 无清空输入历史接口 新增 clearHistory() 方法 直接使用 @moonshot-ai/pi-tui 的终端客户端 纯增量方法,未调用无变化

受影响模块与验证结论:

  • 契约文件核对:packages/node-sdk/src/index.ts 仅新增导出类型、方法与错误码,无破坏性签名变更;config-manifest.toml、wire-manifest.d.ts、state-manifest.d.ts 与 kap-server 契约未改动;历史版本写入的会话与旧客户端均保持兼容。
  • 平台核对:在 macOS 上通过单元测试验证了路径规范化、子进程 git 执行、.worktreeinclude 拷贝、setup 脚本流式输出与信号中止、PID 存活检测。Linux / Windows 路径与子进程行为依赖 CI 矩阵进一步验证。
验证命令与测试覆盖详情
  • 变基至最新 main(c6dec96ae1)后验证:
  • pnpm lint:通过(5436 文件无注释违规、5567 文件 oxlint 0 warnings / 0 errors、import boundaries、guards、ratchet、test-doubles、legacy-e2e、quarantine、instructions、e2e-boundary 全部通过)
  • pnpm run check:duplication origin/main:通过(0 new clones)
  • pnpm exec tsc -p packages/pi-tui/tsconfig.json --noEmit && pnpm exec tsc -p packages/agent-core-v2/tsconfig.json --noEmit && pnpm exec tsc -p packages/node-sdk/tsconfig.json --noEmit && pnpm exec tsc -p apps/kimi-code/tsconfig.json --noEmit:全部通过
  • packages/agent-core-v2:configManifest.test.ts、test/app/worktree/、test/app/projectSessions/、test/agent/environmentBinding/、test/app/sessionExport/sessionExport.test.ts、test/project/sessionLifecycle/sessionLifecycleService.test.ts 共 6 文件 156/156 通过
  • packages/node-sdk:test/list-sessions.test.ts 全部通过、test/sdk-rpc-client-v2.test.ts -t "worktree" 27/27 通过
  • packages/pi-tui:pnpm --filter @moonshot-ai/pi-tui test 1153 通过、0 失败、1 跳过(含 clearHistory() 回归测试)
  • apps/kimi-code:test/tui/commands/experiments.test.ts 8/8 通过

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 23, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: dacf7c5

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

This PR includes changesets to release 10 packages
Name Type
@moonshot-ai/pi-tui Patch
@moonshot-ai/agent-core-v2 Minor
@moonshot-ai/kimi-code-sdk Minor
@moonshot-ai/acp-server Patch
@moonshot-ai/kap-server Patch
@moonshot-ai/klient Patch
@moonshot-ai/migration-legacy Patch
@moonshot-ai/kimi-code-product Patch
@moonshot-ai/remote-control Patch
kimi-code 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 23, 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-25T11:53:52.444745Z dacf7c5 Draft marked ready
ℹ️ 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 23, 2026 •

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

commit: d53c325

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

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

@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: 4ebab1dc2d

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

@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: 6dc9591717

ℹ️ 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/node-sdk/src/types.ts Resolved

@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: 34178354d1

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

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

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

@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: 42747e46ba

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

@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: 3b0f3a2f4f

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

@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: 6d5f1a2208

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

@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: 2fd5147285

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

@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: 42bbafbf6a

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

@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: 4b5d7ec324

ℹ️ 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/node-sdk/src/rpc.ts Resolved

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

ℹ️ 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/node-sdk/src/types.ts Resolved
@Grapedge
Grapedge marked this pull request as ready for review November 25, 2026 11:46

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

ℹ️ 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 merged commit 8286e8f into main Nov 25, 2026
20 checks passed
@Grapedge
Grapedge deleted the feat/worktree-core branch November 25, 2026 14: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
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 26, 2026
MoonshotAI#5292)

Port the engine half: worktree discovery, creation, listing and removal,
session presence records, projectRoot session-index revivals, lock
liveness/testing hooks, and the environment/session lifecycle wiring.
The node-sdk client and the pi-tui history patch remain for follow-ups.

Verified: agent-core-v2 typecheck clean; worktree, sessionLock,
sessionLifecycle, environmentBinding and sessionExport suites 142 pass /
16 skip; check:no-comments OK.
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
…shotAI#5292)

A cwd-based instance ref now goes through resolveImplicit instead of
createOrTouch, so in-process sessions join the grouped repository project
and their projectWorkDir is the repository root. The manager fake follows.
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
…licit (MoonshotAI#5292)

When a cwd-based ref names a workspace id that has no record yet, fall back
to resolveImplicit(root) instead of createOrTouch, so the instance joins
the grouped repository project. The instance-manager fake follows.
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
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
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
…rimary differs (MoonshotAI#5292)

The session context cwd now comes from the requested workDir while the
project workdir (dirs/MCP) still resolves through the project primary, so
a worktree session keeps its own working directory. Session lifecycle,
workspace-context and project-dirs suites 45 pass.
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 26, 2026
Complete the SDK side of MoonshotAI#5292. The harness and RPC client expose
resolveWorkLocation, listWorktrees, createWorktree, runWorktreeSetupScript,
inspectWorktreeRemoval and removeWorktree; the SDK carries the engine's
worktree error codes and restates its Error2 payloads as KimiError. Session
listing accepts scope "project" and reports projectWorkDir, and the engine
writes environmentCwd when the requested cwd differs from the project
primary, so an index-mirror line no longer collapses the session cwd to the
project root.

The sync-throw overrides keep their non-async shape for require-await but
route through asPromise, so a missing live session still rejects instead of
throwing synchronously; cancelPromptPrediction also returns its boolean as a
promise.

Verified: node-sdk typecheck clean; sdk-rpc-client-v2 100 pass / 11 skip /
0 fail; list-sessions 15 pass; agent-core-v2 typecheck clean; environment
binding, project sessions, session export, worktree and session lifecycle
suites 140 pass / 15 skip / 0 fail. Pre-existing and unrelated: six
create-session-transport telemetry cases still expect the removed
tool_select experimental flag.
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 26, 2026
Port the pi-tui half of upstream 8286e8f. clearHistory() drops the stored
prompt history, restores an in-progress draft and resets the recall index,
so a host that switches working directories can swap in the new directory's
history. navigateHistory shares the extracted restoreHistoryDraft().

Verified: pi-tui typecheck clean; editor and editor-history-keybindings
235 pass / 0 fail.
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