Skip to content

feat(assets): add project asset bundle import and export - #1494

Open
Robert0622 wants to merge 5 commits into
Tencent:mainfrom
Robert0622:codex/project-asset-bundles
Open

Robert0622 wants to merge 5 commits into
Tencent:mainfrom
Robert0622:codex/project-asset-bundles

Conversation

@Robert0622

Copy link
Copy Markdown
Collaborator

What changed

Add an Asset bundles entry to the LOOP library. Project owners and maintainers can export a single Skill, MCP server, role or LOOP, or select several assets for one download. The bundle includes project-owned dependencies and preserves Skill and MCP attachment bytes and executable modes.

The destination project previews the bundle and its connection setup before importing. Import creates project-owned copies in one transaction and rewrites their references. Imported LOOPs are drafts, and destination credential bindings are configured separately.

Compatibility

The versioned JSON format uses the existing catalog tables and supports automatic sandbox selection, inherited role executors and inline Docker sandbox definitions.

Validation

  • Focused Go tests for bundle round trips, authorization, rollback, automatic execution settings and OpenAPI.
  • go vet -p=2 ./....
  • Chatbot build and 547 tests, plus 395 web tests.
  • Local Chromium smoke test for single and bulk downloads, preview retry and confirmed destination.
  • Public content check and Gitleaks scan of the exact candidate commit.

The full Go run hit the 180-second package timeout in the engine and HTTP suites. The runner cancellation test also timed out when run individually, while the focused bundle and API tests passed.

Robert0622 and others added 3 commits November 27, 2026 16:28
…-list.css

asset-bundle.css only styles the .asset-bundle-* dialog and builds on the
shared --hui-* tokens, like the other assets-page sheets the harness
already allows after issues-list.css. Without it core failed in
TestIssuesListStylesheetLoadsLast.

Co-Authored-By: Claude Code <noreply@anthropic.com>

@crispinhu27 crispinhu27 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.

初审 head e2787a7f(base main 5c406d25)。

审查范围:资产包导出 / 预览 / 导入的 HTTP 处理、internal/repo/asset_bundle_export.go / asset_bundle_import.go 的依赖收集、ID 重写与事务保存,前端 asset-bundle.js 和 index.html 改动,以及 OpenAPI 文档。

验证(隔离工作区,不带任何凭据;web/native-chat 用占位页代替):

  • go build ./...、对改动包 go vet 通过;go test ./internal/repo ./internal/domain 通过;./internal/httpapi 里本 PR 的 4 个 AssetBundle 测试和 OpenAPI 测试通过。
  • 6aed7446 上 TestIssuesListStylesheetLoadsLast 失败(CI core 当时的红灯),base 上通过。新提交 e2787a7f 把 asset-bundle.css 加进了页面级样式白名单,该测试已通过;asset-bundle.css 的选择器都在 .asset-bundle-* 下,不会覆盖 issues-list 的样式,所以这一项没有单独提评论。./web 里剩下的 TestNativeChatLazyImportsAreEmbedded 失败只是占位页导致的,base 上也一样失败。

阻塞问题(1 条,见行内评论):[P2] 别的项目绑到本项目共享 LOOP 上的全局规则,会让本项目导出这个 LOOP 时直接返回 400。

提交本 Review 时,新 head 的 CI(core / browser / first-run)还在跑。

Comment thread internal/repo/asset_bundle_export.go Resolved
@Robert0622

Copy link
Copy Markdown
Collaborator Author

CR + 部署实测:#1494 资产包导入导出(head e2787a7f)

结论:暂不建议合入。 我在部署环境复现了 crispinhu27 提的 [P2]:别的项目绑在本项目共享 LOOP 上的全局规则,会让本项目导不出这个 LOOP。修好之前不能合。除此之外,导出、预览、单事务导入、引用重写、权限、凭据剥离、路径和大小校验,以及导入后真实派发运行,都实测通过。另有 3 条 P3 建议,不阻塞合入。

e2787a7f 相对 6aed7446 只改了 web/issues_list_harness_test.go 的一行白名单,运行时代码没变,没有夹带别的改动。

环境

  • 构建 e2787a7f,数据库 MariaDB 11.8.9 全新库,鉴权开启,native 沙箱(容器不支持 user namespace,用仅供测试的 bwrap 替身)。
  • 真实模型:CodeBuddy CLI 2.187.0,IOA 站,deepseek-v4.1-flash;目标仓库是一次性私有库,不对本仓库跑任务。
  • 用户:src / dst 两个项目的 owner(非平台管理员)、maintainer、member、viewer,外部项目 owner,匿名。

实测结果

① 导出(单个 Skill / MCP / 角色 / LOOP,以及多选)

  • 依赖全部带上:LOOP 会带出角色、Skill、2 个 MCP、全局规则和项目沙箱。
  • Skill 附件的字节和权限位保持不变:scripts/hello.sh 0755、bin/blob.bin 二进制 0644、SKILL.md 0600,sha256 与源一致;MCP 附件也一致。
  • 响应头为 Cache-Control: private, no-store,附带 attachment 文件名。
  • 包里没有任何秘密:项目凭据 ID 和变量、节点 credentialEnv、沙箱 env、MCP env / headers、URL 里的 user:pw@、?token=、#frag 都被剥离,转成了 5 条 bindings 提示。

② 导入到另一个项目

  • 预览只返回清单,不写任何行。
  • 导入返回 201。7 项资产都换成新 ID bundle-<nonce>-N,引用全部改写正确:
    • 角色的 skills / mcp / rules;
    • 节点的 agentId;
    • 全局规则的 workflowIds;
    • LOOP 的 sandboxProfileId,指向导入的 native 沙箱副本;
    • prompt 里的 .agentflow/<role>/skills/<skill> 路径;
    • 脚本里的 CR_SKILL = "…" 常量。
  • LOOP 导入后为 draft、v1、projectId=dst;同一个包再导一次,ID 不重叠。
  • 回滚:角色 hook 不合法时,PutAgent 在 Skill、MCP、规则、沙箱都已写入之后才失败,结果返回 400,8 张表的行数一行没变,没有留下半成品。

③ 权限与跨项目

  • owner 和 maintainer 可以导出、预览、导入;member、viewer、外部项目 owner 都返回 403,匿名返回 401,失败时都不写任何行。
  • 从 src 端点导出别的项目的 Skill 或角色返回 400,对别的项目的端点操作返回 403。
  • 手工篡改的包导入后,凭据 ID、credentialEnv、各类 env / headers / query、projectId=src/other、shared:true、platformMcp、knowledgeBase、published 都被剥离或强制改掉,0 残留。

④ 边界:以下 26 个用例全部返回预期的 400 或 413,且都不写任何行。

  • 空 body、空包、格式版本不对、JSON 损坏、JSON 后面跟多余数据、未知字段;
  • 非法 ID ../x、重复声明同一个 ID;
  • 附件路径 ../../etc/passwd、/etc/passwd、反斜杠、首尾空格、文件和目录同名、NUL 字符,内联文件路径穿越;
  • sha 不一致、单文件超过 10 MiB、附件总计 66.5 MiB(超过 64 MiB)、请求体超过 96 MiB;
  • http MCP 带附件、缺少依赖、子 LOOP 循环依赖、未知执行器;
  • 导出时选择为空、把规则当入口、选了 201 项。

另外:权限位 04777 入库为 0777,setuid 被去掉;同名资产可以再次导入,生成独立副本;59.4 MiB 附件的包能导入,也能再导出。

⑤ 本地用例

  • go vet ./... 通过;4 个 TestProjectAssetBundle* 用例、OpenAPI / registry、internal/domain、internal/repo、internal/engine 图校验、go test ./web 都通过。
  • webtest 395/395 通过。

⑥ 真实运行:导出的 LOOP 导入到 dst 后发布、派发,CodeBuddy deepseek-v4.1-flash 跑了 2 次,两次都 succeeded,各约 32s。

  • 导入的全局规则在运行时生效:回答末尾带了 [cr-rule]。
  • 脚本节点打印的是改写后的 Skill ID。
  • Agent 在工作区里对导入的 scripts/hello.sh 执行 ls -l,结果是 -rwxr-xr-x;直接执行它,输出 hello-from-cr-skill。

需修复

[P2] 外部项目的全局规则会卡住本项目的导出(与 crispinhu27 的行内评论是同一个问题,已在部署环境复现)

  • 复现:src 把 cr-loop 设为共享;外部项目 other 的 owner(不是 src 成员)执行 PUT /api/rules {projectId:"other", global:true, workflowIds:["cr-loop"]},返回 200;之后 src owner 导出 cr-loop 返回 400「资产或依赖 rule/other-global-rule 不属于当前项目或已不存在」,界面上的报错相同(截图 9)。
  • 后果:外部项目可以让本项目一直导不出自己的 LOOP,本项目还看不到、也删不了这条规则。
  • 位置:internal/repo/asset_bundle_export.go:153-159。
  • 建议:只收集 rule.ProjectID == x.project 的全局规则,并补一个用例。

建议(P3,不阻塞)

  1. 预览不是完整的试运行。角色 hook 语言不合法,或 artifactOutputs 路径为 ../escape 时,预览返回 200,导入才返回 400(回滚是对的)。建议预览也在事务里跑一遍 save 再回滚,或者把这些校验挪到 prepare。
  2. LOOP 用了别的项目共享的角色时,导出直接 400,但导出列表里照样能勾选这个 LOOP。建议在列表里标注出来,或者在报错里说明需要先复制到本项目。
  3. 绑定清单显示的是源项目 ID(如 cr-mcp、src-native)。导入后资产 ID 变成 bundle-<hex>-N,名字和已有资产相同,导入完成后清单也不再显示,用户不好找到要配置的副本。建议导入结果里按「名称 → 新 ID」列出来,并保留清单。

另外说明一点(不算问题):导入的草稿 LOOP 不发布也能直接派发,这和 main 上「复制 LOOP」得到的草稿行为一致。

截图

导出选择 导出完成 + 绑定提示 导入预览
导入完成 目标项目里的草稿 LOOP 损坏 JSON 被拒
member 被拒 导入 LOOP 真实运行成功 P2:外部全局规则卡住导出

结论:修好这条 P2 就可以合入,其余全部实测通过。token 身份是作者 Robert0622,不能自己 Approve;P2 修复后的新 head 我会再复测一次,合入需要一位非作者 Approve。

Another project may bind its own global rule to a shared LOOP. Export
walked every rule on the platform, so the source project got a 400 for a
rule it can neither see nor remove. Only this project's global rules now
travel with the LOOP; runtime injection already ignores the others.

Also from review:
- Preview runs the full save in a transaction and rolls it back, so role
  hooks and artifact paths that only PutAgent checks fail the preview too.
- A dependency that is another project's shared asset or a platform
  template says it must be copied into the project first. A private asset
  of another project still reads like a missing one.
- Import returns bindings that point at the new copies, and the dialog
  lists each asset as name -> new ID with its follow-up items.

Co-Authored-By: Claude Code <noreply@anthropic.com>
@Robert0622

Copy link
Copy Markdown
Collaborator Author

新 head aaac4551,CI 全绿(16/16),mergeable。相对 e2787a7f 只改了资产包:

  • P2(crispinhu27 的行内评论):导出只收本项目的全局规则,别的项目绑到共享 LOOP 上的规则跳过,不再卡住导出;新用例 TestProjectAssetBundleExportIgnoresOtherProjectsGlobalRules 覆盖,去掉过滤会以 400 失败。
  • P3-1:预览在事务里跑完整 save 再回滚,hook language / artifactOutputs 这类只有 PutAgent 才校验的问题预览即 400,不写任何行。
  • P3-2:依赖是其他项目的共享资产或平台模板时报「请先复制到当前项目再导出」;其他项目私有资产仍报「不属于当前项目或已不存在」,不暴露是否存在。
  • P3-3:导入返回的 bindings[].assetId 指向新副本 ID;对话框按「名称 → 新 ID」列出导入项,并保留「导入后需配置」清单。

部署实测(MariaDB 11.8.9 全新库、鉴权开启、native 沙箱 + 仅供测试的 bwrap 替身、CodeBuddy deepseek-v4.1-flash):

  • 复现步骤:other 的 owner PUT /api/rules {projectId:"other",global:true,workflowIds:["cr-loop"]} 200 → src 导出:e2787a7f 400,aaac4551 200 且包里只有 src 自己的规则;界面导出同样成功。
  • 预览/导入:非法 hook、../ 产物路径预览与导入都 400,目标项目 0 行写入;正常包预览 200、导入 201。
  • 导入后的 LOOP 发布 + 派发实跑:succeeded,回答带 [src-rule],本项目的全局规则随包迁移且运行时生效。
  • 界面:导出后的「需配置」清单、导入后的「名称 → 新 ID」都按预期显示。

本地:go build ./...、go vet、gofmt、go test ./internal/repo ./internal/domain ./internal/httpapi -run AssetBundle|OpenAPI、go test ./web、python3 -I scripts/check-public.py 均通过;./internal/httpapi 全量仅两条 Chromium 浏览器用例失败,e2787a7f 上同样失败(本机环境)。

请复审 aaac4551。

@Robert0622

Copy link
Copy Markdown
Collaborator Author

复核 aaac4551(在 e2787a7f 的同一套部署环境上重跑)

结论:我这边可合入。 之前提的 P2 和 3 条 P3 都已在部署环境复核为已修复,没有发现新的阻塞问题。aaac4551 相对 e2787a7f 只动了资产包相关文件(asset_bundle_export.go、asset_bundle_import.go、httpapi/asset_bundle.go、web/app/asset-bundle.js、docs、测试),没有夹带。

复核沿用原来的库(MariaDB 11.8.9 + native 沙箱 + bwrap 替身 + CodeBuddy deepseek-v4.1-flash),没有重建数据,所以 P2 的触发条件还留在库里。

P2:外部项目的全局规则卡住导出 → 已消

  • 库里的状态没变:src 的 cr-loop 仍是共享 LOOP,规则 other-global-rule(projectId=other,global=true,workflowIds=["cr-loop"],由 other 项目的 owner 建的)仍然绑着。
  • 同一请求:e2787a7f 返回 400「资产或依赖 rule/other-global-rule 不属于当前项目或已不存在」;aaac4551 返回 200,包里只有 cr-rule,other-global-rule 不在包里,导出没有写入任何行。界面上导出也成功(截图 1、2)。

P3-1:预览跑完整 save → 已成立

用例 预览 导入 目标项目行数变化
角色 hook language: ruby 400 agent hook "h1" has invalid language "ruby" 400 0
artifactOutputs 路径 ../escape 400 invalid agent artifact contract "x" 400 0
节点 metricStage 非法 400 workflow node "check" has unsupported metricStage 400 0
正常包 200,7 项资产 201 预览 0

代价可接受:79.2 MiB 的包预览 3.2s、导入 3.4s(都是本机实例,写进去再回滚没有明显额外开销)。

P3-2:外部共享依赖的提示 → 已成立

  • LOOP 节点用别的项目的共享角色:400「资产或依赖 agent/other-shared-role 来自其他项目的共享资产或平台通用模板,请先复制到当前项目再导出」。
  • 直接导出那个共享角色也是同一句。
  • 别的项目的私有 Skill 仍然只报「不属于当前项目或已不存在」,不暴露它存不存在。

P3-3:导入后指向新副本 → 已成立

  • 导入响应里的 5 条 bindings 全部指向新副本 ID(bundle-<nonce>-N),不再指向源项目的 ID。
  • 界面导入后按「名称 → 新 ID」列 7 项,再列「导入后需配置」清单,清单里是 CR MCP (bundle-…-2) 这种带名字和新 ID 的形式(截图 5)。

回归(在同一套环境重跑)

  • 上一轮的边界套件 77 项全部符合预期(路径穿越、NUL、反斜杠、文件和目录同名、sha 不符、单文件 >10 MiB、总附件 >64 MiB、请求体 >96 MiB、缺依赖、子 LOOP 环、未知执行器、ID/入口/数量限制等),失败都不写行。
  • 权限不变:owner/maintainer 放行,member/viewer/外部项目 owner 403,匿名 401。
  • 混合包(第二段 LOOP 校验失败)导入仍 400 且 0 行写入,回滚正常。
  • 导入的 LOOP 仍是 draft,agentId / sandboxProfileId / 脚本里的 Skill 常量都改写正确;发布后真实派发跑了一次,32s succeeded,回答带本项目的 [cr-rule],节点输出里是改写后的 Skill ID。
  • 界面:损坏 JSON 预览报错且「导入」按钮保持禁用;非 maintainer 点「资产包」拿不到对话框。

本地

go vet ./... 通过;internal/httpapi 的 7 个 AssetBundle 用例(含新增的 TestProjectAssetBundleExportIgnoresOtherProjectsGlobalRules、TestProjectAssetBundleExplainsForeignDependencies、TestProjectAssetBundlePreviewRunsTheSave)、OpenAPI / registry、internal/domain、internal/repo、internal/engine 图校验、go test ./web、webtest 395/395 全部通过;internal/httpapi 全量 只有 2 条浏览器用例失败(TestMainBotBrowserStartsAndDrivesRunBrowser、TestBrowserStreamPushesFramesAndRunsCommands),这两条在 main 的同一环境里同样失败(本机无浏览器,走的是替身),与本次改动无关。

截图

导出选择 导出成功 + 需配置清单 导出提示(带资产名)
导入预览 导入完成(名称 → 新 ID) 目标项目里的草稿 LOOP
损坏 JSON 被拒 member 被拒

CI 16/16、MERGEABLE。当前 reviewDecision 仍是 CHANGES_REQUESTED,是 crispinhu27 在 e2787a7f 上提的那条,需要他复审解除;我这条评论是用作者本人的 token 发的,不能 Approve。

crispinhu27
crispinhu27 previously approved these changes Nov 27, 2026

@crispinhu27 crispinhu27 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.

复审 aaac4551:APPROVE

审查版本:head aaac455193de785dd64c1a6345c6b9a07605fa9b,base main 5c406d25;复审增量 e2787a7f..aaac4551(1 个提交,7 文件 +278/−24),并结合整个 PR diff 看了导出 / 导入 / 预览调用链。CI 16/16 通过。

历史问题

问题 结论 依据
[P2] 别的项目绑到共享 LOOP 上的全局规则让本项目导不出这个 LOOP(discussion_r4717544659) FIXED 真实服务 + MariaDB 按「导出 200 → 他项目绑规则 200 → 再导出」复测:aaac4551 第三步 200 且只含本项目规则;基线 e2787a7f 同脚本仍 400。线程已回复并 resolve

实际执行的验证(隔离用户、无凭据、合成数据)

  • go build ./...、go vet ./internal/repo ./internal/httpapi ./internal/domain 通过
  • go test ./internal/repo ./internal/domain 通过;go test ./internal/httpapi -run 'AssetBundle|OpenAPI'(7 个资产包用例 + OpenAPI)通过;internal/engine 的 TestGlobalRuleInjectsIntoEveryNodeOfBoundWorkflow 通过
  • HTTP 端到端:本项目全局规则随 LOOP 进包,导入后 workflowIds 改写为新 LOOP、global 保留(导入 201、预览 200);规则同时绑一个未导出 LOOP 时导出裁剪 workflowIds,导入不报缺依赖;连续 3 次预览前后各表行数不变
  • go test ./web 仅 TestNativeChatLazyImportsAreEmbedded 失败,缺 native-chat 构建产物,基线同样失败,与本 PR 无关

非阻塞建议(P3)

  • 其他项目设为 shared:true 的全局规则在运行时会注入本项目 LOOP(appendWorkflowGlobalRules 按 ProjectID == 本项目 || Shared 判断),但导出时按 ProjectID == 本项目 被跳过,迁移到新项目后这类规则不会跟过去。这是合理取舍,建议在 bindings 或文档里提示一句「已忽略 N 条来自其他项目的共享全局规则」。
  • Generic LOOP 作为入口时,报错从「无法选择该类型作为资产包入口」变成「来自其他项目的共享资产或平台通用模板,请先复制到当前项目再导出」,同为 400,影响很小。

未做:浏览器端导入导出冒烟测试(以 HTTP 接口端到端替代)。以上结论只针对本次审查范围和执行过的验证。

Resolve conflicts with the latest main; keep both sides' additions
(i18n dictionaries, runner/A2A rows, review-mode run header, user turn
actions) without dropping either branch's behaviour.

Co-Authored-By: Claude Code <noreply@anthropic.com>
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