Skip to content

feat(chat): refresh workspace repository context on demand - #1096

Merged
crispinhu27 merged 3 commits into
mainfrom
feature/workspace-repository-context
Nov 19, 2026
Merged

crispinhu27 merged 3 commits into
mainfrom
feature/workspace-repository-context

Conversation

@crispinhu27

@crispinhu27 crispinhu27 commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

What changed

Follow-up to #947. A conversation workspace gives its native CLI the current project's repository catalog, including repository IDs, names, credential-free clone URLs, and default branches.

  • Send the full catalog on the first launch in a workspace, when rebuilding a native session, or when the catalog changes. Normal follow-up turns reuse the catalog already in native history.
  • The CLI checks existing checkouts first and preserves local edits. It clones the repositories it needs. If a task requires existing source and the target repository is still unclear, it clones the remaining catalog entries with a clone URL.
  • Small catalogs are sent inline. Large catalogs are staged as a JSONL session attachment so CLIs that take the prompt in a single argument can start. Repository network URLs omit credentials, query strings, and fragments. Git filesystem paths preserve literal # and ?.

Scope

  • Platform core / API / runner
  • Shared behavior contract

Compatibility

The catalog fingerprint is stored in the local native-session metadata after the CLI phase completes successfully. Existing sessions establish it the first time they receive the catalog after upgrade.

Validation

  • go test -count=1 -timeout=5m ./internal/httpapi passed with a process-local Git configuration for the bare-repository test fixture. Focused workspace and native-session regression tests passed again after rebasing onto main.
  • python3 scripts/check-public.py and git diff --check passed.
  • Real CodeBuddy 2.185.0 with HY4, a macOS native sandbox, disposable Docker MySQL, and local fixture repositories. Inspected actual CLI input and the resulting Git checkouts.
    • First entry received the full catalog and cloned only the requested repository.
    • A follow-up reused the same native session with zero new catalog blocks. It read an uncommitted file from the existing checkout and cloned the next requested repository using native history.
    • Registering another repository sent the updated full catalog to the same native session. The CLI cloned only the newly requested repository.
    • A missing native journal triggered a new session and a full catalog resend. The recovery run cloned both remaining repositories and read the expected source value. The four-turn run reached its seven-minute limit before the final reply. A focused real CLI run separately completed the missing-journal recovery and returned the requested terminal output with an empty checkout set.
  • Review follow-up verified the actual Cursor, Pi, and Antigravity command arguments on Linux with a 1,000-repository catalog. A real CodeBuddy run read a staged 1,001-entry catalog and cloned only the requested repository. In a separate two-turn run, CodeBuddy cloned the exact registered billing#core.git path on first entry and read the expected Git commit from the existing checkout in the same native session on resume.

Safety

  • Repository fixtures and verification data are synthetic.
  • The commit is scoped to the workspace and assistant changes and their tests.

@Robert0622 Robert0622 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

用本提交生成的仓库清单和同一真实 CodeBuddy iOA 会话跑了三轮 DeepSeek V4.1 Flash。首次读取、续接时从历史读取、更新后读取新分支均通过,三次输入中的清单块数分别为 1、0、1。另用本地测试项目验证了大清单的 CLI 启动路径,发现以下问题。

Comment thread internal/httpapi/assistant.go Outdated
// The journal's catalogue is uncertain until the phase completes.
workspaceRepositoryHash = ""
}
prompt = assistantWorkspaceSystemPrompt + "\n审批模式:" + approvalMode + "。\n" + repositoryPrompt + prompt

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[P2] 完整清单拼进 prompt 后,仍用单个 argv 参数传递提示词的 CLI 会在 Linux 上启动失败。本地用 1,000 个普通仓库记录生成了 187,071 字节的清单,即使用户只问当前分支,Cursor、Pi、Antigravity 的实际命令构造器都产生了约 190 KB 的单参数。把可执行文件换成 /usr/bin/true 验证,三个调用都在进入 CLI 之前返回 E2BIG。建议按 CLI 能力使用标准输入,或让 CLI 从工作区内的清单文件读取完整内容,并覆盖刷新和重建路径。

for _, r := range repositories {
r = domain.PublicRepository(r)
hint := workspaceRepositoryHint{
ID: r.ID, Name: r.Name, CloneURL: r.CloneURL, DefaultBranch: strings.TrimSpace(r.DefaultBranch),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[P1] 请给模型清单中的仓库 URL 单独做脱敏。PublicRepository 清理的是 URL 的 userinfo,历史记录的签名查询参数仍可能随 CloneURL 进入原生会话历史,备用 WebURL 也经过同一路径。建议生成仅含必要组成部分的仓库地址,并覆盖这两个字段的脱敏测试。

@Robert0622 Robert0622 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

上一轮的大清单和签名 URL 问题已修复。用 1000 个仓库构造 Cursor、Pi、agy 的实际命令参数,再以 /usr/bin/true 代替模型进程执行,三者均能启动,最长单个参数为 7609 字节。对同步后的 168000 字节 JSONL,用 CodeBuddy iOA 的 DeepSeek V4.1 Flash 在同一会话实测了首次进入、续聊、更新分支,三次均调用 Read 并答对目标分支。另有一处合法本地 Git 路径会在清单中被截断,见行内评论。

// may have signed query strings or fragments in addition to URL userinfo.
func workspaceRepositoryURL(raw string) string {
base := strings.TrimSpace(raw)
if i := strings.IndexAny(base, "?#"); i >= 0 {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[P3] 保留本地 Git 路径中的字面 #

这里在判断地址类型前就截断 ? 和 #,会改写管理员可以登记的本地 Git 路径。我建了一个名为 billing#core.git 的裸仓库,通过 /api/repositories 登记返回 200,对登记的完整路径执行 git ls-remote 也成功。工作区清单给出的路径却只到 billing,同一条 Git 命令退出 128。建议只对有 URL 查询串或片段语义的地址清理这些部分,普通文件系统路径保留原样,并补一个带 # 的本地路径用例。

@Robert0622 Robert0622 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

复审通过。使用管理员身份通过仓库 API 登记了三个真实的本地 Git 裸仓库,分别覆盖路径中的 #、? 和同时含两者的 file:// 地址。工作区清单保留了原地址,使用清单里的值执行 git ls-remote 均成功。网络 URL 清理和共享会话恢复的回归测试也通过。

用最新提交生成并同步 1000 项仓库清单后,又在同一个 CodeBuddy iOA 会话中实测了首次读取、续聊和更新分支。三次都只使用 DeepSeek V4.1 Flash,都实际调用 Read 并返回了目标仓库的正确分支。

@crispinhu27
crispinhu27 merged commit 4175c96 into main Nov 19, 2026
16 checks passed
@crispinhu27
crispinhu27 deleted the feature/workspace-repository-context branch November 19, 2026 13:06
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