Skip to content

feat(compose): unify resource source configuration#335

Open
fuchencong wants to merge 2 commits into
mainfrom
feat/issue-332-unified-resource-sources
Open

feat(compose): unify resource source configuration#335
fuchencong wants to merge 2 commits into
mainfrom
feat/issue-332-unified-resource-sources

Conversation

@fuchencong

Copy link
Copy Markdown
Contributor

Summary

  • unify Skill, Workspace, and Scheduler script source configuration around the flat provider, url, ref, path, format, and authentication fields
  • treat ZIP as a content format (format: zip) instead of a provider, replace Workspace branch/commit with ref, and separate Workspace source path from destination target
  • add a shared pkg/sources model and Git client used by Skills, Workspaces, and Git-backed Scheduler scripts, including ref resolution, authentication, validation, and credential redaction
  • preserve the existing resolution lifecycle for each consumer and update Proto, examples, README files, and the English/Chinese YAML manuals

Closes #332

Testing

  • task generate:proto
  • GOFLAGS=-buildvcs=false task lint GO_BUILD_CACHE_DIR="$GOCACHE" GOLANGCI_LINT_CACHE_DIR="$GOLANGCI_LINT_CACHE"
  • GOFLAGS=-buildvcs=false task build GO_BUILD_CACHE_DIR="$GOCACHE"
  • task test GO_BUILD_CACHE_DIR="$GOCACHE"
    • Unit: 74.37%
    • Integration: 61.88%
    • E2E: 61.23%
    • Combined: 78.20%
  • task docs:build

The full test task was run in a subprocess with inherited daemon/product configuration variables cleared as documented in DEVELOPMENT_WORKFLOW.md. The build reused runtime artifacts whose source fingerprints matched the current branch.

Checklist

  • Documentation updated when behavior or configuration changed.
  • Tests added or updated for user-visible behavior.
  • No secrets, private endpoints, internal certificates, or local runtime state included.

@monkeyscan

monkeyscan Bot commented Jul 17, 2026

Copy link
Copy Markdown

PR Title: feat(compose): unify resource source configuration

Commit: 1d84a7f

本次 PR 将 workspace、skill 和 script source 的配置统一为新的 Source 结构,核心变更包括:

  1. 新增 pkg/sources 包,定义了 Source 结构体和 GitClient(负责 git clone/checkout 和 ref resolve)。
  2. ref 替代了原来的 branch/commit,用 target 替代了 path(workspace clone 目标路径)。
  3. local provider 重命名为 file provider,统一了 provider 命名。
  4. SkillSpec 和 WorkspaceSpec 中新增/调整了字段,移除了旧字段,并在 API 和存储层进行了相应映射。
  5. GitClient 通过 GIT_CONFIG_VALUE_0 注入 HTTP Authorization header 实现凭据传递,避免在 URL 中明文携带密码。
  6. 多处 JSON/YAML 序列化结构、proto、以及测试进行了同步更新。

发现一处高严重性问题:旧版 git workspace ConfigJSON(包含 branch/commit/path 字段)在新的 GitWorkspaceConfig 结构下反序列化时会静默丢失数据,导致运行时无法检出指定分支/提交,且 clone 目标路径也会丢失。legacy_workspace_migration.go 中的迁移逻辑同样受影响。建议增加旧字段兼容映射并补充相关测试。

@fuchencong
fuchencong force-pushed the feat/issue-332-unified-resource-sources branch from 1d84a7f to ce2e98c Compare July 17, 2026 13:19
@monkeyscan

monkeyscan Bot commented Jul 17, 2026

Copy link
Copy Markdown

PR Title: feat(compose): unify resource source configuration

Commit: ce2e98c

本次 PR 将代码库中分散的资源来源配置(workspace、skill、script)统一收敛到新的 pkg/sources 包中。核心变更包括:

  1. 统一 Source 模型:新增 sources.Source 结构体,统一承载 Provider/URL/Ref/Path/Format/Username/Password/Token 字段,取代原先各自为政的字段组合(如 Branch+Commit 被合并为 Ref)。
  2. 提取 Git 客户端:将原本散落在 pkg/skills/resolve.gopkg/workspaces/git_workspace.go 中的 git 命令执行、凭证注入、错误脱敏逻辑抽取到 pkg/sources/git.goGitClient 中。
  3. Provider 重命名local 统一更名为 filezip 从独立 provider 变为 file/httpformat 修饰。
  4. Workspace 字段调整Path 在 git workspace 中改为 TargetBranch/Commit 合并为 Ref;文件型 workspace 新增 Target 支持子目录映射。
  5. 环境变量引用解析:将 ResolveEnvReferenceValidateSecretReference 下沉到 sources 包,供 script resolver、git client、HTTP auth 复用。
  6. 向后兼容:更新了 legacy workspace 迁移、proto 序列化/反序列化、canonical revision workspace 恢复等兼容路径。

整体评估:这是一次结构清晰的重构,消除了多处重复凭证处理和 git 调用逻辑。但 GitClient 中仍存在一些安全性与正确性细节需要关注,如临时目录清理、命令参数校验、以及 sources.Source 在 Normalized 后的副作用行为。

Comment thread pkg/runs/preparation.go
Comment thread pkg/sources/git.go
Comment thread pkg/workspaces/git_workspace.go
"path/filepath"
"strings"

domain "agent-compose/pkg/model"
"agent-compose/pkg/sources"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

旧版 git workspace ConfigJSON 反序列化时静默丢失 branch/commit/clone target

新的 GitWorkspaceConfig 嵌入了 sources.Source 并将旧的 CloneTarget 重命名为 Target(JSON tag 从 path 改为 target)。对于数据库中仍然使用旧格式存储的 git workspace ConfigJSON(包含 branch、commit、path 等字段),反序列化时会静默丢失数据:branch/commit → 新结构没有对应字段,Ref 为空,运行时会 fallback 到 HEAD,导致旧 workspace 无法检出指定分支或 commit;path(旧 CloneTarget)→ 新结构的 sources.Source.Path 接收了该值,但语义从“clone 目标路径”变成了“仓库内子路径”,而 Target 为空导致文件被 clone 到 workspace 根目录而非预期的子目录。legacy_workspace_migration.go 中的 mapLegacyWorkspaceConfig 同样使用新结构反序列化旧数据,但未对 branch/commit/path 做兼容映射。

Problem code:

Changed code at pkg/workspaces/git_workspace.go:12

Recommendation:

  1. 为 GitWorkspaceConfig 增加旧字段的兼容反序列化(custom UnmarshalJSON),将旧字段 branch/commit 映射到 Ref,将旧字段 path(CloneTarget)映射到 Target。2. 或在 mapLegacyWorkspaceConfig 中显式解析旧字段并进行映射。3. 添加覆盖旧格式 ConfigJSON 的单元测试,确保迁移和运行时都能正确读取历史数据。

@monkeyscan

monkeyscan Bot commented Jul 17, 2026

Copy link
Copy Markdown

PR Title: feat(compose): unify resource source configuration

Commit: 5133ece

本次变更在 pkg/compose/script_source.go 中新增了 resolveGitScriptPath 函数,用于在从 Git 源读取脚本时解析并校验目标路径,防止通过符号链接(symlink)或路径遍历逃离仓库目录。核心逻辑是:先使用 filepath.EvalSymlinks 解析 checkout 目录和脚本路径,再通过 filepath.Rel 计算相对路径,并检查其是否以 .. 开头,若是则拒绝访问。同时新增了一个测试用例 TestDefaultScriptSourceResolverRejectsEscapingGitSymlink,验证指向仓库外部的符号链接会被正确拒绝。

实现思路清晰, containment 校验覆盖了绝对路径、相对路径以及符号链接解析后的逃逸场景。测试覆盖了典型的 symlink 逃逸攻击向量。整体评估:改动合理,安全加固有效,未发现引入新的正确性或安全问题。

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.

[Feature]: 统一 YAML 中远程资源来源的配置模型

1 participant