Skip to content

feat: support folder-scoped git status - #4527

Merged
liruifengv merged 13 commits into
mainfrom
feat/session-context-panels
Oct 30, 2026
Merged

liruifengv merged 13 commits into
mainfrom
feat/session-context-panels

Conversation

@liruifengv

@liruifengv liruifengv commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

Requirement or Bug

多目录工作区的客户端需要分别获取每个目录的 Git 状态、改动统计和 PR,而不是复用主目录结果。本 PR 新增目录级单查询与批量查询能力,供 Desktop / Web 的右侧会话信息面板使用。

关联 app 仓 PR:https://github.com/MoonshotAI/kimi-code-app/pull/1049

Bug Reproduction Steps

N/A

Root Cause

N/A

Code Changes

核心思路:保留原有主目录调用方式,在现有 environment 能力模型上增加可选 root 和批量 action;每个目录独立执行、独立返回结果或错误,避免单目录失败拖垮整个面板。

单个请求
├── fs:git_status({ root? })
└── fs:pull_request({ root? })

批量请求
├── fs:git_status:batch({ roots })
└── fs:pull_request:batch({ roots })
    ├── 每次最多 32 个目录
    ├── 服务端最多并发处理 2 个目录
    ├── 校验目录属于当前工作区
    └── 按目录返回 results / errors

Git 与 PR 行为

  • root 缺省时保留原主目录语义和文件过滤方式;显式传入目录时,Git 状态和 numstat 只统计该目录范围。
  • PR 查询与 Git 状态可独立调用;gh pr view 增加 isDraft,草稿 PR 返回 draft 而不是 open。
  • 批量接口按目录隔离错误,调用方可以保留其他目录的有效结果。
  • 服务端在当前 environment 架构中申请 fs / process 能力,不恢复旧 runtime 路径。

关键决策

决策 本 PR 的选择 原因
多目录传输 一次批量请求替代每个目录两次 HTTP 请求 降低多目录面板刷新时的请求数量
批量规模 最多 32 个目录,并发上限 2 限制单次负载,避免同时启动大量 Git / PR 子进程
错误模型 按 root 返回 results 与 errors 非 Git 目录或单目录失败不影响其他目录展示
调用兼容 root 保持可选 现有主目录客户端无需修改

阅读指南

  • packages/kap-server/src/routes/fs.ts:单查询、批量 action、目录校验和错误映射。
  • packages/agent-core-v2/src/workspace/workspaceFs/fsService.ts:目录级 Git 状态与 PR 查询入口。
  • packages/agent-core-v2/src/app/git/gitService.ts:目录范围内的 status、numstat、diff 和 PR 查询。
  • packages/agent-core-v2/src/app/git/gitParsers.ts:Git / PR 输出解析及草稿状态。
  • packages/kap-server/test/fs.test.ts 与对应 core 测试:真实 REST、批量隔离和目录范围验证。

Behavior Changes and Affected Users

行为 改动前 改动后 依赖旧行为的用户 退路或兼容方式
未传 root 的 Git 状态 使用主目录和既有文件过滤 保持不变 现有 daemon 客户端、Changes 面板 原调用与测试保留
传入 root 的 Git 状态 无法可靠获得附加目录的独立状态 按请求目录返回分支、改动和 PR 多目录 Desktop / Web 面板 继续使用单查询或省略 root
目录 numstat 可能混入整个仓库的统计 只统计选定目录 同仓库多目录用户 省略 root 保留原主目录统计
批量查询 每个目录分别发起 Git / PR 请求 支持一次批量查询,单目录错误独立返回 多目录面板刷新 保留单查询接口
草稿 PR 作为 open 返回 作为 draft 返回 PR 状态展示方 其他 PR 状态不变
Changeset 无目录查询条目 仅 agent-core-v2 和 kap-server 使用 patch core / server 包 changelog 不包含 CLI 包

验证

  • pnpm vitest run packages/agent-core-v2/test/app/git/gitService.test.ts packages/agent-core-v2/test/workspace/workspaceFs/fsService.test.ts packages/kap-server/test/fs.test.ts:3 个文件、186 项测试全部通过,包含真实 REST 的附加目录查询。
  • pnpm --filter @moonshot-ai/kap-server run typecheck:通过。
  • pnpm --filter @moonshot-ai/agent-core-v2 run typecheck:仍有 test/program/program.test.ts:617 的参数数量错误;该文件与 origin/main 一致,并非本 PR 修改。
  • 未运行全量 build 或全量 lint。

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue(未提供 issue,已链接配套 app 仓 PR)。
  • I have added tests that prove my feature works.
  • The behavior-change table above is complete; existing callers that omit root keep their previous behavior.
  • Ran gen-changesets skill,仅更新 @moonshot-ai/agent-core-v2 与 @moonshot-ai/kap-server 的 patch changeset,不包含 CLI。
  • Evaluated documentation needs;本次为内部接口能力补充,无额外文档更新。

Copilot AI balanced review requested due to automatic review settings October 29, 2026 12:36

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@changeset-bot

changeset-bot Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 128d4e1

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

This PR includes changesets to release 2 packages
Name Type
@moonshot-ai/agent-core-v2 Patch
@moonshot-ai/kap-server 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

@liruifengv
liruifengv marked this pull request as ready for review October 30, 2026 06:02
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-30T09:02:41.667083Z 128d4e1 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 Oct 30, 2026 •

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

commit: 128d4e1

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

ℹ️ 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/kap-server/src/routes/fs.ts Resolved
@liruifengv

Copy link
Copy Markdown
Collaborator Author

@codex review

@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: 62658a9134

ℹ️ 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: 9ebedb0e7d

ℹ️ 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 docs/en/reference/server-api.md Resolved
Comment on lines +2 to +6
"@moonshot-ai/agent-core-v2": patch
"@moonshot-ai/kap-server": patch
---

Add batched, folder-scoped Git and pull request queries for multi-root workspace panels.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Add a CLI changeset for the draft-state correction

Existing fs:git_status callers with a draft pull request now receive draft instead of open because this PR adds the isDraft field and changes its parsing, but the changeset only announces the new folder and batch queries and versions internal packages. The user-visible correction therefore will not appear in the CLI changelog; record it as a separate logical changeset for @moonshot-ai/kimi-code.

AGENTS.md reference: AGENTS.md:L108-L109

Useful? React with 👍 / 👎.

@liruifengv

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: dbbf9b38c6

ℹ️ 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: 128d4e1a54

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

@liruifengv
liruifengv merged commit 1853dae into main Oct 30, 2026
15 of 16 checks passed
@liruifengv
liruifengv deleted the feat/session-context-panels branch October 30, 2026 09:04
wbxl2000 added a commit that referenced this pull request Oct 30, 2026
Stops before #4538 so the code-app branch can pin a commit that has both
this change and the server code code-app main runs on, without the
tool-select API change that desktop has not adapted to yet.
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 4, 2026
Port of the local-environment hardening in upstream
MoonshotAI/kimi-code 75f35b0 (MoonshotAI#4649).

GitService spawned bare git and gh with the workspace as cwd. On Windows
a bare name is looked up in the cwd before PATH, so a binary planted in
the workspace could run. Both now resolve through resolveProgramPath,
which refuses any match inside the working directory, and the timeout
default moves from none to 30s so a hung git cannot wedge a status read.

resolveProgramPath compares the PATH candidate against the working
directory case-sensitively, so on Windows a PATH entry spelled with
different casing (c:\repo\bin vs C:\Repo) let a workspace-local
executable through; the containment check now folds case on win32.

The pull request cache is keyed by branch, so a branch switch no longer
serves the previous branch's pull request.

Not ported from the same commit: reading the footer git status through
the session environment, which needs the pull-request API of MoonshotAI#4527 and
the session workdir of MoonshotAI#4062, neither of which this tree has. The
startup "Ready." row it also removes does not exist here.
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 4, 2026
Fifteen rows enter the ledger: the six commits that landed on
upstream/main after the last refresh, and the nine commits that reach
main only through the release/2026-11-04 sync (MoonshotAI#4674), which is where
the 2.5.0 changelog entries come from.

Each 2.5.0 row records what it needs from this tree, so the next batch
starts from the blocker instead of rediscovering it:

- MoonshotAI#4658 and MoonshotAI#4659 are ported (79a4199, 7a531f5) with tests that
  fail on the pre-change tree.
- MoonshotAI#4649 is in_progress: its agent-core-v2 half landed in 2fa7b6b,
  while the footer and welcome half needs the pull-request API of MoonshotAI#4527
  and the session workdir of MoonshotAI#4062.
- MoonshotAI#4653, MoonshotAI#4666 and MoonshotAI#4670 build on the MoonshotAI#4525 plugin marketplace, absent
  here; MoonshotAI#4670 additionally needs isError2.
- MoonshotAI#4664 needs the MoonshotAI#4062 remote environments.
- MoonshotAI#4667 and MoonshotAI#4672 are generated-bundle and release commits; settling
  them as not-applicable needs a signature.

Rows were appended by a one-off writer because --refresh fetches and
that fetch does not complete on this network; the file still parses
under the tool's own column contract, and --verify --batch B5 passes
both new probes.
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 4, 2026
Port of upstream MoonshotAI/kimi-code 1853dae (MoonshotAI#4527).

Multi-root panels need the git state of one folder, not of the whole
worktree: status and diff now accept a `root`, return entry paths
relative to it, and refuse a path that escapes it. A batch pair
(`git_status:batch`, `pull_request:batch`) reads several roots in one
call with at most two in flight, folding a failing root into a per-root
error instead of failing the request.

Pull requests load independently of status, keyed by branch, and a draft
open pull request reports `draft` instead of `open`.

Fork adaptations:
- Local resolveWithin rejects absolute paths outright, and that stays.
  A registered root is resolved through a separate path that reuses the
  workspace and realpath containment checks, so `root: '/'` still needs
  an explicit registration.
- The upstream batch error mapping covers EnvironmentError and
  HandshakeError; only EnvironmentError exists here, since handshake
  failures come with the remote environments of MoonshotAI#4062.
- parsePorcelain now returns a null-prototype entry map so a repository
  path named `__proto__` lands in results instead of the prototype.
- Test stubs gain the new interface members, and the fake fs records `/`
  as an existing directory so a registered filesystem root can resolve.

Not ported: the node-sdk session-workdir door to these actions, which
arrives with MoonshotAI#4062.
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 4, 2026
…AI#4649's blocker

MoonshotAI#4527 lands in 5eedb6f with a probe over the batch case. MoonshotAI#4649's
remaining half no longer waits on the pull-request API it now has; only
the MoonshotAI#4062 session workdir is missing.
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 4, 2026
…obes

Both halves of the cross-folder search are in place: the fuzzy walk
(14ba59e) and the empty-query listing, which now anchors an absolute
path at the nearest registered root (a14144d). Upstream's route-level
test is not ported, and the evidence says so, but the route forwarding it
covers has been in place since MoonshotAI#4527's work.

Ledger: closed 36 -> 37, remaining 62.
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.

3 participants