diff --git a/.vite-hooks/pre-commit b/.vite-hooks/pre-commit index c036247c..86cfbf94 100755 --- a/.vite-hooks/pre-commit +++ b/.vite-hooks/pre-commit @@ -21,6 +21,7 @@ git add \ skills/bailian-memory/reference \ skills/bailian-knowledge/SKILL.md \ skills/bailian-knowledge/reference \ - skills/bailian-web-search/SKILL.md + skills/bailian-web-search/SKILL.md \ + skills/bailian-opd/SKILL.md vp staged diff --git a/AGENTS.md b/AGENTS.md index 61f6b651..d7a07c2e 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -58,29 +58,30 @@ Skill / 命令手册随 `skills/bailian-*/` 经 `bl skill init` 安装(装齐 按当前任务从下表挑一条进入对应文档: -| 场景 | 何时进入 | 详见 | -| ----------------- | --------------------------------------------------------------------- | ---------------------------------------------------------------------------- | -| 命令增删改 | 增加 / 删除 / 重命名 `bl xxx` 或入口命令路径 | [docs/agents/command-add-remove.md](docs/agents/command-add-remove.md) | -| 测试维护与性能 | 新增/修改任意单测、输出契约测试或 E2E;选择 runner、fixture、计时方式 | [docs/agents/cli-e2e-tests.md](docs/agents/cli-e2e-tests.md) | -| 测试隔离 | 单测/E2E 受本地 HOME、语言、系统目录干扰;统一隔离基建 | [docs/agents/test-isolation.md](docs/agents/test-isolation.md) | -| 输出契约 | 新增输出、quiet/verbose、JSON 错误或流式输出 | [docs/agents/output-contract.md](docs/agents/output-contract.md) | -| 批量压测 | 改/跑多能力并发压测、`test:stress`、fixtures | [docs/agents/stress-batch-tests.md](docs/agents/stress-batch-tests.md) | -| 选项变更 | 给已有命令加 `--flag` 或改默认值 | [docs/agents/command-flag-change.md](docs/agents/command-flag-change.md) | -| 模型上下架 | 增加新模型 / 改默认模型 / 废弃旧模型 | [docs/agents/model-add-remove.md](docs/agents/model-add-remove.md) | -| Skill 文案 / 路由 | 改 SKILL 路由、安装约定、hand-off、hub/领域边界 | [docs/agents/skill-change.md](docs/agents/skill-change.md) | -| 错误文案变更 | 改 `BailianError` 的 message 或 hint | [docs/agents/error-hint-change.md](docs/agents/error-hint-change.md) | -| URL / 渠道变更 | 控制台域名 / 文档站 / 追踪参数 | [docs/agents/url-change.md](docs/agents/url-change.md) | -| 埋点变更 | 改 AEM 命令事件、后端渠道 header、User-Agent | [docs/agents/telemetry-change.md](docs/agents/telemetry-change.md) | -| 鉴权扩展 | 加 OAuth / SSO / 换 token 来源 | [docs/agents/auth-change.md](docs/agents/auth-change.md) | -| 配置项扩展 | 新 env var 或 `~/.bailian/config.json` 字段 | [docs/agents/config-add.md](docs/agents/config-add.md) | -| Profile / 激活 | 改命名 Profile、预设或 `active_config` | [docs/agents/config-profile-change.md](docs/agents/config-profile-change.md) | -| 安装文档 | 改安装、鉴权、验证流程或线上 install 页面 | [docs/agents/install-doc-change.md](docs/agents/install-doc-change.md) | -| 发布 | channel / stable 发布到 npm(CI 驱动) | [docs/agents/publish.md](docs/agents/publish.md) | -| Change Log | 发版说明 / 历史版本说明 | [docs/agents/changelog-write.md](docs/agents/changelog-write.md) | -| 公开内容检查 | 公开前检查凭证、真实资源、内部文档及 Git 历史 | [docs/agents/public-content-review.md](docs/agents/public-content-review.md) | -| 工具链调整 | lint 规则 / 构建配置 / 依赖升级 | [docs/agents/lint-toolchain.md](docs/agents/lint-toolchain.md) | -| Command Pack | 扩展包 / 白名单 / plugin 管理命令 | [docs/agents/command-pack.md](docs/agents/command-pack.md) | -| dsh 插件 | 改 `packages/bailian-kb-dsh` / `bailian-memo-dsh`、dsh 依赖、插件发布 | [docs/agents/dsh-plugin.md](docs/agents/dsh-plugin.md) | +| 场景 | 何时进入 | 详见 | +| ----------------- | ------------------------------------------------------------------------- | ---------------------------------------------------------------------------- | +| 命令增删改 | 增加 / 删除 / 重命名 `bl xxx` 或入口命令路径 | [docs/agents/command-add-remove.md](docs/agents/command-add-remove.md) | +| 测试维护与性能 | 新增/修改任意单测、输出契约测试或 E2E;选择 runner、fixture、计时方式 | [docs/agents/cli-e2e-tests.md](docs/agents/cli-e2e-tests.md) | +| 测试隔离 | 单测/E2E 受本地 HOME、语言、系统目录干扰;统一隔离基建 | [docs/agents/test-isolation.md](docs/agents/test-isolation.md) | +| 输出契约 | 新增输出、quiet/verbose、JSON 错误或流式输出 | [docs/agents/output-contract.md](docs/agents/output-contract.md) | +| 批量压测 | 改/跑多能力并发压测、`test:stress`、fixtures | [docs/agents/stress-batch-tests.md](docs/agents/stress-batch-tests.md) | +| 选项变更 | 给已有命令加 `--flag` 或改默认值 | [docs/agents/command-flag-change.md](docs/agents/command-flag-change.md) | +| 模型上下架 | 增加新模型 / 改默认模型 / 废弃旧模型 | [docs/agents/model-add-remove.md](docs/agents/model-add-remove.md) | +| Skill 文案 / 路由 | 改 SKILL 路由、安装约定、hand-off、hub/领域边界 | [docs/agents/skill-change.md](docs/agents/skill-change.md) | +| 错误文案变更 | 改 `BailianError` 的 message 或 hint | [docs/agents/error-hint-change.md](docs/agents/error-hint-change.md) | +| URL / 渠道变更 | 控制台域名 / 文档站 / 追踪参数 | [docs/agents/url-change.md](docs/agents/url-change.md) | +| 埋点变更 | 改 AEM 命令事件、后端渠道 header、User-Agent | [docs/agents/telemetry-change.md](docs/agents/telemetry-change.md) | +| 鉴权扩展 | 加 OAuth / SSO / 换 token 来源 | [docs/agents/auth-change.md](docs/agents/auth-change.md) | +| 配置项扩展 | 新 env var 或 `~/.bailian/config.json` 字段 | [docs/agents/config-add.md](docs/agents/config-add.md) | +| Profile / 激活 | 改命名 Profile、预设或 `active_config` | [docs/agents/config-profile-change.md](docs/agents/config-profile-change.md) | +| 安装文档 | 改安装、鉴权、验证流程或线上 install 页面 | [docs/agents/install-doc-change.md](docs/agents/install-doc-change.md) | +| 发布 | channel / stable 发布到 npm(CI 驱动) | [docs/agents/publish.md](docs/agents/publish.md) | +| Change Log | 发版说明 / 历史版本说明 | [docs/agents/changelog-write.md](docs/agents/changelog-write.md) | +| 公开内容检查 | 公开前检查凭证、真实资源、内部文档及 Git 历史 | [docs/agents/public-content-review.md](docs/agents/public-content-review.md) | +| 工具链调整 | lint 规则 / 构建配置 / 依赖升级 | [docs/agents/lint-toolchain.md](docs/agents/lint-toolchain.md) | +| Command Pack | 扩展包 / 白名单 / plugin 管理命令 | [docs/agents/command-pack.md](docs/agents/command-pack.md) | +| dsh 插件 | 改 `packages/bailian-kb-dsh` / `bailian-memo-dsh`、dsh 依赖、插件发布 | [docs/agents/dsh-plugin.md](docs/agents/dsh-plugin.md) | +| RL / OPD 沙箱 | 改 `bl finetune rl` / `opd` / `runtime`、执行隔离、托管运行时、授权状态机 | [docs/agents/rl-sandbox.md](docs/agents/rl-sandbox.md) | 如果当前任务无法对应任何场景,先按经验完成,然后**回来评估这是不是一类新场景** —— 是就新增 `docs/agents/.md`,把清单沉淀下来。 diff --git a/README.md b/README.md index f6f7beaa..f8258629 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ _Built for AI Agents. Every command works as a structured tool call._ - **Asset understanding** — Parse and ask questions about images, documents, audio, and long videos - **App orchestration** — Call Managed Agents, agents, and workflows published on Aliyun Model Studio, wired to knowledge bases, memory, web search, and MCP tools; create, update, publish, copy, and delete agents/workflows, and edit workflow canvases from the CLI - **Native MCP setup** — Register Bailian MCP servers in Codex, Claude Code, Cursor, Qoder, Qoder Work, QwenWork (千问办公), Qwen Code, Gemini CLI, or Pi -- **Training & deployment** — Validate and upload datasets, fine-tune models, deploy dedicated models as endpoints +- **Training & deployment** — Validate and upload datasets, fine-tune models (SFT/DPO/CPT), run reinforcement-learning jobs in an isolated sandbox (macOS/Linux), submit OPD distillation jobs via OpenAPI, deploy dedicated models as endpoints - **Batch inference** — Prepare CSV/JSONL, create and follow asynchronous Chat/Embedding tasks, download original results/errors with optional CSV, or send one synchronous Batch Chat request - **Account operations** — Login, UI-based configuration, model marketplace, usage and quota, rate-limit increases, team seat management - **Plan onboarding** — Connect subscription plans such as Token Plan to the CLI and common coding agents in one step diff --git a/README.zh.md b/README.zh.md index 252d0b51..eb959b96 100644 --- a/README.zh.md +++ b/README.zh.md @@ -26,7 +26,7 @@ _专为 AI Agent 打造,每个命令均可作为结构化工具调用。_ - **素材理解** — 图像、文档、音频、长视频的解析与问答 - **应用编排** — 调用百炼已发布的 Managed Agent、智能体和工作流,接入知识库、记忆库、联网搜索与 MCP 工具;并可在命令行创建/更新/发布/复制/删除智能体与工作流、编辑工作流画布 - **原生 MCP 接入** — 将百炼 MCP 服务注册到 Codex、Claude Code、Cursor、Qoder、Qoder Work、千问办公(QwenWork)、Qwen Code、Gemini CLI 或 Pi -- **模型训推** — 数据集校验上传、模型精调、专属模型部署上线 +- **模型训推** — 数据集校验上传、模型精调(SFT/DPO/CPT)、在隔离沙箱内执行强化学习(RL)训练(macOS/Linux)、通过 OpenAPI 提交 OPD 蒸馏训练、专属模型部署上线 - **批量推理** — CSV/JSONL 构造、异步 Chat/Embedding 任务创建与跟踪、原始结果/错误下载及可选 CSV,或同步单请求 Batch Chat - **账号运维** — 授权登录、界面化配置、模型市场、用量与额度、限流提额、团队席位管理 - **套餐接入** — 支持 Token Plan 等订阅计划一键接到 CLI 和常见 Coding Agent diff --git a/docs/agents/rl-sandbox.md b/docs/agents/rl-sandbox.md new file mode 100644 index 00000000..83346147 --- /dev/null +++ b/docs/agents/rl-sandbox.md @@ -0,0 +1,120 @@ +# RL / OPD 沙箱训练子系统 + +## 触发条件 + +- 增删改 `bl finetune rl *` / `bl finetune opd *` / `bl finetune runtime *` 命令 +- 改执行隔离(凭据禁读、home 重定向、白名单代理、快照/暂存)或 OS 适配 +- 改托管 Python 运行时(manifest / 安装生命周期 / doctor 自检 / 开发态 override) +- 改沙箱产物生命周期(任务目录销毁 / 孤儿 TTL 回收 / 旧版本运行时清理 / runtime clean) +- 改 RL / OPD 授权状态机或控制台网关授权接口 + +命令增删改的通用登记流程仍走 [command-add-remove.md](command-add-remove.md);本文只沉淀本子系统特有的约束。 + +## 分层与关键文件 + +``` +core(纯逻辑,不依赖 runtime/commands,不 process.exit) + finetune/rl/config.ts resolveTrainingSpec / buildTaskYaml:参数+YAML 深度合并,剥离 bailian 段 + finetune/rl/auth.ts runRlAuthorization:可审计授权状态机(TS 侧调控制台网关) + finetune/rl/types.ts RlRunParams / RlJobSpec / IResolvedTrainingSpec + isolation/ 两层隔离:app-layer(环境闭环 + 调用结束销毁 taskDir)+ os-isolation(OS 强制)+ proxy + snapshot + paths + cleanup(产物回收) + rl-runtime/manifest.ts 清单 schema v2 解析 / 平台选择 / SHA256 完整性 / bundledRuntimeManifest + rl-runtime/manifest-data.ts 随包受审查清单常量(由仓库根 runtime-manifest.json 生成,勿手改) + rl-runtime/locks.ts 随包 universal 依赖锁文件(uv pip compile --generate-hashes 生成,勿手改) + rl-runtime/manager.ts resolveRuntime / installRuntime:独占锁→多源下载 CPython 校验→tar 解压→pip 装锁文件→自检→原子 READY + rl-runtime/sandbox.ts executeInSandbox:黑盒唯一执行入口(清单驱动初始化 + confinement + 结果归一化) + rl-runtime/doctor.ts runRuntimeDoctor / assertDoctorPassed:逐项自检 + 退出码归一化 + +commands(命令库,不决定产品路径) + commands/finetune/rl-shared.ts RL/OPD 命令组共享:executeRl / runRlJob / runRlAuthorize / RL_RUN_FLAGS / probeRlJob / followRlJob(后两者支持可选 workspaceId) + commands/finetune/rl-job-commands.ts 任务管理命令工厂:get/watch/logs/cancel/delete 按 domain(rl|opd)参数化;opd 走宿主 fine-tunes OpenAPI,rl 走沙箱 SDK;list 仅 RL(opd list 已删,与 finetune list 冗余同源) + commands/finetune/dataset-input.ts create / opd run 共享的数据集解析+延迟上传管线(从 create.ts 提取) + commands/finetune/rl-*.ts rl run/authorize + 工厂薄包装(domain=rl) + commands/finetune/opd-run.ts OPD 提交:宿主 OpenAPI,create 风格 flag,零网络 dry-run,超参不填默认(charge_type 例外,见下) + commands/finetune/opd-params.ts OPD 参数查询(training_type=pg_opd,hyper/resource 分组) + commands/finetune/opd-*.ts opd authorize + 工厂薄包装(domain=opd) + commands/finetune/runtime-*.ts runtime prepare / doctor / clean(仅 RL 需要) + +cli(产品入口) + src/commands.ts "finetune rl *" / "finetune opd *" / "finetune runtime *" 路径 map +``` + +`rl-shared.ts` 与 `rl-job-commands.ts` 是命令组内部共享,**不注册为命令**(不在 index.ts / commands.ts 出现)。RL 与 OPD 是两种训练类型,命令面对称独立(`finetune rl *` / `finetune opd *`),但**后端不同**:RL 的 run/get/list/logs/cancel 走沙箱 SDK(受审查基线 dashscope 1.25.23 的 CLI 面是 `rl run/get/list/logs/cancel`,**无 `jobs` 子组、无 delete、无顶层 --output**,JSON 输出是叶子级 `--output-format/-o json`,cancel 无 -o 且成功消息走 stderr);**OPD 全组在宿主直连 fine-tunes OpenAPI**(run 提交 `training_type=pg_opd` + `teacher_model`,get/logs/cancel/delete/watch 走 core 的 fine-tunes wrapper;**无 opd list**——2026-11-18 删除,与 `finetune list` 冗余同源,OPD 任务直接用通用 list 查),不经沙箱、不需要托管运行时。任务管理命令仍由 `rl-job-commands.ts` 的 domain 参数化工厂生成,domain=opd 时切宿主后端并追加可选 `--workspace-id`,logs flag 为 `--page/--page-size`(RL 保持 `--offset/--lines`)。OPD 超参按用户提供值原样发送(JSON 文件 + `--hp` 覆盖),**不填参数接口 recommend_value**(它不是所选教师的有效默认值),未指定字段交服务端/教师解析;显式覆盖值按 hyper+resource 两组 schema 校验(`save_strategy` 即使 schema 未列出也放行,服务端校验器允许)。唯一本地默认是 `resource_config.charge_type`:服务端对 pg_opd 只接受 MTU 计费(缺失时按通用默认计费拒绝,400 "only support mtu charge type"),故缺省填 `mtu_postpaid`、显式传其他值本地报 USAGE。`mtu_spec_code`/`mtu_capacity` 为**本地必填**(文件或 flag 任一来源):实测缺失时服务端落库后回 500、任务执行期 FAILED(2026-11-18,request_id 1d066588),故在上传/创建前报 USAGE 拦截;取值随师生组合变化,不填默认。本地前置校验套件(dry-run 同样生效):唯一硬校验是 `opd_teacher_infer_tp == opd_teacher_n_gpus_per_node`(教师 Worker 模板约束,离线渲染取证);其余均 warning 不拦——组合不在公开矩阵(`opd-model-matrix.ts`,官方文档"模型与训练单元"2026-11-18 快照,18 对邀测,URL 在 runtime/urls.ts `OPD_MODEL_MATRIX_DOC`;快照会过期故只提醒)、学生布局四字段不全(提示官方推荐 MTU4×24 与当前容量;容量等式检查服务端在执行期做,本地无模式合同算不了)、显式学生长度超过显式教师 max_model_len。**batch-fit 闸(2026-11-18 增,官方文档定义 + DLC 日志取证)**:`batch_size` 即官方"每步样本数",总步数 = floor(本地训练集条数 × n_epochs / batch_size);为 0 时执行期必炸 `lr_decay_steps > 0` 断言(ft-…e439:12 条 × 1 epoch / 64 = 0 步,创建返回 200 后 FAILED),故本地条数已知且 batch_size/n_epochs 显式时在上传/创建前报 USAGE——本地条数是预处理后的上界,"本地不够"是闭合硬拦,"本地够"不保证(预处理会过滤)。`ppo_mini_batch_size > batch_size × n_rollouts` 全显式时 USAGE(官方参数关系)。总步数可算时:显式 `lr_warmup_steps` ≥ 0 超总步数 → `OPD_WARMUP_EXCEEDS_STEPS`(文档建议小数据冒烟设 0);`eval_steps`/`save_steps`(steps 策略)超总步数 → `OPD_INTERVAL_EXCEEDS_STEPS`(评估/保存不会触发);batch_size/n_epochs 显式但条数未知(file-id)→ `OPD_BATCH_FIT_UNKNOWN`。纯函数在 `opd-batch-fit.ts`;skill `bailian-opd` 的 `lib.mjs` computeBatchFit/miniBatchLimit 同口径,preflight 有 batch-fit 阶段(用 dataset validate 的 totalRecords)。通用 finetune get 对带描述符的任务抑制空的 training_files/validation_files 旧字段(防"数据没传上"误导)。`opd params` 以 `training_type=pg_opd` 查参数接口;兼容教师发现服务端尚无合同,不做笛卡尔积;公开文档矩阵仅用于 warning 级提示,不用于硬拦截。watch/probe/delete 两域同走宿主。kscli 不暴露 RL/OPD。 + +## 必查清单 + +### A. 保留 flag 守卫 + +- [ ] 命令自有 flag 不得与全局/确认/凭证保留 flag 同名(`registry.ts` register 会抛 `redeclares reserved flag`)。本子系统已踩过的坑: + - 轮询超时用 `pollTimeout`(`--poll-timeout`,rl watch)/ `waitTimeout`(`--wait-timeout`,rl run),**不能**用 `timeout`(全局保留);监控在 TS 宿主轮询 fine-tunes 端点(`getFineTune`),不再经沙箱 SDK wait + - YAML 输入用 `configFile`(`--config-file`),**不能**用 `config`(profile 全局 flag) + - `--yes` 由 runtime 注入,命令不得自声明 +- [ ] 共享 helper 取 `ctx` 必须用泛型 `(ctx: CommandContext)`;`CommandContext<具体Flags>` 不能赋给 `CommandContext`(不变性) + +### B. 执行隔离(安全底线,fail-closed) + +- [ ] 环境闭环是硬性要求:`python -I` isolated 模式 + 全新最小环境 + home 重定向 + 凭据 deny 路径。OS 强制层(macOS SBPL / Linux bwrap)不可用时 fail-closed,不降级放行 +- [ ] Windows AppContainer 当前为占位:全平台注册命令,运行时返回 `Not supported on Windows yet.`(中文 `Windows 暂不支持。`)。文案保持简单,不堆技术术语 +- [ ] 负向测试不可删:沙箱内直接读真实 `~/.dashscope` 必须失败;`expanduser('~')` 必须等于任务 home。doctor 的 `credential-deny-negative` / `home-redirect` 是必过项 +- [ ] 白名单代理拒无关域名 / 私网 / metadata IP,只允许 CONNECT 443;doctor 用回环真实断言,不依赖外网 +- [ ] 用户业务 requirements 只被读取/上传,**绝不**进入 SDK 执行器安装步骤 +- [ ] 任务目录生命周期绑定**调用**,不绑定 job 结果:`executeIsolatedRun` 的 finally 无条件 `rmSync(taskDir)`(成功/失败/超时同策,不保留)。SDK 不可断点续跑、taskDir 内全部产物可再生(spec 经 dry-run 重生成、start.sh 由 SDK 版本确定性生成、错误已经 stderr 脱敏输出),保留零收益。best-effort:清理失败不得掩盖执行结果;崩溃路径(SIGKILL/断电)孤儿由 TTL 兜底 +- [ ] layout 随单次 `executeIsolatedRun` 调用消费:多次执行的调用方(如 doctor 多探针)**每次调用各自 `createTaskDir()`**,不得跨调用共享 layout——第二次执行的 `adapter.prepare` 会向已销毁目录写文件(darwin profile.sb)而 ENOENT。doctor 机制探测用实际执行的 `adapter.detect()`(与执行一致,注入 fake adapter 可确定性测试);回归守卫见 `rl-runtime-doctor.test.ts` 多探针用例(prepare 写 marker 模拟 profile.sb) + +### C. 托管运行时(黑盒清单驱动 · 首次下载+缓存 · 仅 RL;OPD 全组不经沙箱) + +- [ ] 沙箱是工程内本地 TS 黑盒(`sandbox.ts` `executeInSandbox`):命令层只传 SDK 参数+凭证+prepare,黑盒内部按受审查清单首次下载/缓存运行时并 confinement 执行;外围 `executeRl` 保持最薄,不再分别编排 resolveRuntime / executeIsolatedRun +- [ ] 清单默认取随包受审查产物(`bundledRuntimeManifest`,schema v2):每平台 CPython(python-build-standalone install_only)+ 全平台共用 dashscope wheel(PyPI);固定 CPython 3.11.9 + dashscope 1.25.23(端到端真实训练验证过的组合),求稳不耦合发版。改清单改仓库根 `runtime-manifest.json` 后重生成 `manifest-data.ts`(有同步测试守卫) +- [ ] 真实下载源:CPython 哈希取自 python-build-standalone 20240415 官方 SHA256SUMS;dashscope wheel SHA `7cb2cc48…` 取自 PyPI(等于基线 `RL_DASHSCOPE_WHEEL_SHA256`)。SHA 只能真实计算/取自官方,绝不臆造 +- [ ] FC_PYPI_LIB 注入链(用户零感知):`sandbox.ts` 从 `runtime.dashscopeVersion` 派生 `FC_PYPI_LIB=dashscope==`,经 `IIsolatedRunInput.sdkEnv` → `IIsolationSpec.sdkEnv` → `buildSandboxEnv` 受控注入(绝不从宿主继承)。机理:start.sh 的 SERVER_CLASSPATH 默认模块路径由**提交端 SDK 版本**决定,FC_PYPI_LIB 只决定 FC 内 pip 装哪个 dashscope,两者锁步才不会启动即崩。override 运行时版本经 `importlib.metadata` 实测(不谎报基线常量);doctor `fc-pypi-lib-injected` 是必过项 +- [ ] 安装生命周期:多源下载 CPython→逐源校验 SHA256→系统 tar 解压→ensurepip→`pip install --require-hashes -r` 随包 universal 锁文件→版本/import 自检→原子 READY。中断不生成 READY;run 用解释器绝对路径,不 source activate、不改全局 PATH +- [ ] 沙箱 cwd 契约:SDK `create_deployment_files` 相对**进程 cwd** 写 `start.sh`(open+chmod)再按 `zipdir` 打包,原 demo 流程 cwd==zipdir。故 `executeInSandbox` 传 `cwd: layout.deployCopyDir`(可写且与 zipdir 一致);默认 taskDir 不在写允许集会 EPERM([2052] Registration failed),且落在包外会使上传 zip 缺启动脚本。doctor 等无代码包场景仍用默认 taskDir +- [ ] 下载韧性:CPython 走多源候选(`pythonDownloadCandidates`:`BAILIAN_RL_PYTHON_MIRROR` 自定义镜像优先 → GitHub canonical → 内置 npmmirror 回退),单次下载带超时(停滞快速失败转镜像,不无限挂起);逐源校验同一 SHA256,换源不换哈希,任一源网络失败或哈希不符转下一源,全部失败才报错。npmmirror(阿里 CNPM)与 GitHub release 路径 1:1、已核验字节级一致(SHA 命中官方)。pip 索引可经 `BAILIAN_RL_PIP_INDEX_URL` 指向稳定 PyPI 镜像(清华 `pypi.tuna.tsinghua.edu.cn/simple` / 阿里 `mirrors.aliyun.com/pypi/simple`,自托管 wheel 可绕开受限地区卡住的 files.pythonhosted.org CDN 路由),默认 PyPI 不变;`--require-hashes` 仍逐包校验哈希。注意镜像同步滞后于 PyPI:锁文件钉精确传递依赖版本(如 regex),镜像缺该版本时 pip fail-closed 报 `No matching distribution found for X==ver`,换更新更快的镜像或回默认 PyPI(已 live 验证:阿里 lag 缺 regex 新版失败、tuna 齐全成功 READY)。镜像只换来源,绝不跳过 hash +- [ ] 依赖锁文件随包(`locks.ts`,universal 全平台 wheel 哈希),升级固定 dashscope 版本时重生成;1.25.23 未声明 pyyaml/tenacity(缺则 AgenticRL import 崩,且 CLI 懒注册会静默吞掉 rl 子命令),重生成时输入须显式带上它们及 fastapi/uvicorn/opentelemetry/tiktoken;绝不安装用户业务 requirements +- [ ] 开发态 `BAILIAN_RL_RUNTIME` 指向本机 dashscope Python 目录跳过发行校验联调;不支持平台返回 RUNTIME_UNAVAILABLE +- [ ] doctor 运行时缺失时相关项标 `skip`(不当通过),整体 `ok=false`;增强项(内核网络/进程树/内存)不可用降级提示,不阻断 +- [ ] 产物回收(`isolation/cleanup.ts` `cleanupSandboxArtifacts`,计划式:先对每个目录产出 remove/keep 再执行,dry-run 零删除):runs 按目录 mtime 超 TTL(默认 24h)回收孤儿;runtimes/rl 只保留 `currentManagedRuntimeId()`(随包清单派生)基线,旧版本目录回收;缺基线 id 时跳过运行时回收(fail-safe)。`runtime prepare` 顺手 prune runs(`pruneRuntimes: false`,best-effort 不阻断主流程,输出 `pruned_runs`);`runtime clean`(auth none、risk destructive、`--ttl-hours`)做完整回收。下载缓存 `cache/rl`(按 SHA 内容寻址、跨版本复用)与 `BAILIAN_RL_RUNTIME` override 目录绝不触碰 + +### D. 授权状态机 + +- [ ] `auth.ts` 的控制台 API 名与响应形状是 **UNVERIFIED CONTRACT**(取自产品设计,未对线上网关核验)。`extractEnabledFlag` 防御性解析,无识别形状降级 `UNKNOWN`,不臆断开通/未开通 +- [ ] 只读 probe 不做任何 mutation;`authorize: true` 才开通业务,且**只开请求目标**(RL 不自动开 OPD,反之亦然);服务关联角色永不自动创建,缺失报 `REQUIRES_USER_ACTION` 并附手动授权文档(URL 经 `manualAuthDocUrl` 由命令层注入,core 不硬编码) +- [ ] 查询失败一律 `UNKNOWN`(绝不 READY/MISSING);缺准入白名单/角色都是 `REQUIRES_USER_ACTION`,CLI 不创建角色 +- [ ] authorize 命令 `auth: "console"`,用 `defineConsoleReadCommand` 包装做 workspace 绑定;risk high,CI 须显式 `--authorize --yes`,单独 `--yes` 不扩大权限 +- [ ] 核验线上契约后:更新 `RL_AUTH_API` 与响应解析,并补真实网关集成测试 + +### E. 风险闸门与文案 + +- [ ] `rl run` / `opd run` 声明 `risk.reason: "billing"`;`rl cancel` / `delete` / `runtime clean` 声明 destructive;静态 risk 命令在远端请求/本地写入前处理 `settings.dryRun` +- [ ] 用户可见文案中英双语;服务端错误原样透传(不翻译,见 [error-hint-change.md](error-hint-change.md)) +- [ ] `exportApiCredential` 受 lint 限定,仅 `rl-shared.ts` 执行器有窄范围 override(`vite.config.ts`);不要扩散到整个 finetune 族 + +### F. 注册与文档 + +- [ ] 四步登记:实现文件 → `commands/src/index.ts` re-export → `cli/src/commands.ts` map → `commands/tests/e2e/topic-routes.ts`(FINETUNE_ROUTES) +- [ ] reference 按一级命令组生成:RL/OPD/runtime 均属 `finetune` 组,自动并入 `skills/bailian-finetune/reference/finetune.md`,`GROUP_OWNER_SKILL` 无需改;跑 `pnpm run sync:skill-assets`,勿手改生成物 +- [ ] 拥有方 `skills/bailian-finetune/SKILL.md` 路由表补意图;hub `bailian-cli` 不抄领域明细 +- [ ] README.md / README.zh.md 与 packages/cli 两份保持一致(release 强校验) + +## 测试 + +- core 单测:`packages/core/tests/rl-config.test.ts` / `rl-auth.test.ts` / `rl-isolation-*.test.ts` / `isolation-cleanup.test.ts` / `isolation-app-layer.test.ts`(fake adapter + 真实 node 子进程验 finally 销毁)/ `rl-runtime-*.test.ts`,从 `../src/index.ts` 导入,fs/env 用 `helpers/isolation.ts`,mock 网络用 `vi.spyOn(httpTransport, "fetch")` +- commands E2E:`packages/commands/tests/e2e/`(需注册后才能跑 `runCommandInProcess` / `runCommandHelp`),真实集成 gated(需 API key / console token / 已准备运行时) +- 全量注册守卫:`packages/cli/tests/e2e/registry.smoke.e2e.test.ts` 构建完整产品 map,捕获保留 flag 冲突 +- 定向执行 + 记录耗时,见 [cli-e2e-tests.md](cli-e2e-tests.md);全仓 `vp test` 本机可能静默 exit 1,须定向跑 + +## 常见漏点 + +- ✗ 用 `timeout` / `config` 作命令自有 flag → 注册时抛 reserved flag +- ✗ 共享 helper 用非泛型 `CommandContext` → TS2345 不变性报错 +- ✗ 删负向测试或放宽 doctor 必过项来"提速" → 破坏安全底线 +- ✗ 把授权查询失败当作未开通去 enable → 撒谎;应记 UNKNOWN(角色缺失只引导手动授权,不创建) +- ✗ authorize 跨开另一种训练模式(RL 开了 OPD)→ 违反只开请求目标 +- ✗ 手改 `skills/*/reference/*.md` → 下次 generate 覆盖 +- ✗ 在注释/文档引用仓外私有设计文档的章节号/文件名 → 开源读者无上下文,注释须自解释 +- ✗ 把运行时初始化摊回外围(在 `executeRl` 里直接 resolveRuntime + 组装命令)→ 违背黑盒边界,初始化须在 `sandbox.ts` 内部 +- ✗ 臆造下载 URL/SHA256,或把稳定运行时构建塞进发版流水线 → 求稳解耦,下载源与哈希取自官方、一次下载长期缓存 +- ✗ 用参数接口 recommend_value 批量填充 OPD 超参 → 覆盖所选教师的真实默认(如 Flash/Max 教师长度 16385 ≠ 通用 34816);未指定字段留空交服务端解析 +- ✗ 失败/超时保留 taskDir 供“重试复用/排查” → SDK 不可断点续跑,网络步骤每次重做,产物全部可再生,保留零收益只泄漏磁盘与代码;生命周期绑定调用,结果连保留策略都不影响 +- ✗ 多次 `executeIsolatedRun` 共享一个 layout(doctor 旧实现)→ 首次调用 finally 销毁 taskDir 后,下次 prepare 写 profile.sb ENOENT;每次调用各自 createTaskDir,不引入 keep opt-out +- ✗ 自动回收触碰当前基线运行时 / override 开发目录 / 下载缓存 → 复用边界是“不可变层按版本寻址”,回收只动孤儿 runs 与被取代的旧版本目录 diff --git a/packages/bailian-kb-dsh/package.json b/packages/bailian-kb-dsh/package.json index f93b6e73..52c0fc96 100644 --- a/packages/bailian-kb-dsh/package.json +++ b/packages/bailian-kb-dsh/package.json @@ -1,6 +1,6 @@ { "name": "bailian-kb-dsh", - "version": "2.10.3", + "version": "2.10.4", "description": "Bailian knowledge-base tools for DeepSeek Harness: kb_search and kb_chat over the DashScope RAG API, plus the bl CLI management skill.", "keywords": [ "alibaba-cloud", diff --git a/packages/bailian-memo-dsh/package.json b/packages/bailian-memo-dsh/package.json index 27718ae5..a0fdae44 100644 --- a/packages/bailian-memo-dsh/package.json +++ b/packages/bailian-memo-dsh/package.json @@ -1,6 +1,6 @@ { "name": "bailian-memo-dsh", - "version": "2.10.3", + "version": "2.10.4", "description": "Bailian personal memory for DeepSeek Harness: automatic recall, silent curation, and user-controlled remember/forget.", "keywords": [ "alibaba-cloud", diff --git a/packages/cli/README.md b/packages/cli/README.md index f6f7beaa..f8258629 100644 --- a/packages/cli/README.md +++ b/packages/cli/README.md @@ -27,7 +27,7 @@ _Built for AI Agents. Every command works as a structured tool call._ - **Asset understanding** — Parse and ask questions about images, documents, audio, and long videos - **App orchestration** — Call Managed Agents, agents, and workflows published on Aliyun Model Studio, wired to knowledge bases, memory, web search, and MCP tools; create, update, publish, copy, and delete agents/workflows, and edit workflow canvases from the CLI - **Native MCP setup** — Register Bailian MCP servers in Codex, Claude Code, Cursor, Qoder, Qoder Work, QwenWork (千问办公), Qwen Code, Gemini CLI, or Pi -- **Training & deployment** — Validate and upload datasets, fine-tune models, deploy dedicated models as endpoints +- **Training & deployment** — Validate and upload datasets, fine-tune models (SFT/DPO/CPT), run reinforcement-learning jobs in an isolated sandbox (macOS/Linux), submit OPD distillation jobs via OpenAPI, deploy dedicated models as endpoints - **Batch inference** — Prepare CSV/JSONL, create and follow asynchronous Chat/Embedding tasks, download original results/errors with optional CSV, or send one synchronous Batch Chat request - **Account operations** — Login, UI-based configuration, model marketplace, usage and quota, rate-limit increases, team seat management - **Plan onboarding** — Connect subscription plans such as Token Plan to the CLI and common coding agents in one step diff --git a/packages/cli/README.zh.md b/packages/cli/README.zh.md index 252d0b51..eb959b96 100644 --- a/packages/cli/README.zh.md +++ b/packages/cli/README.zh.md @@ -26,7 +26,7 @@ _专为 AI Agent 打造,每个命令均可作为结构化工具调用。_ - **素材理解** — 图像、文档、音频、长视频的解析与问答 - **应用编排** — 调用百炼已发布的 Managed Agent、智能体和工作流,接入知识库、记忆库、联网搜索与 MCP 工具;并可在命令行创建/更新/发布/复制/删除智能体与工作流、编辑工作流画布 - **原生 MCP 接入** — 将百炼 MCP 服务注册到 Codex、Claude Code、Cursor、Qoder、Qoder Work、千问办公(QwenWork)、Qwen Code、Gemini CLI 或 Pi -- **模型训推** — 数据集校验上传、模型精调、专属模型部署上线 +- **模型训推** — 数据集校验上传、模型精调(SFT/DPO/CPT)、在隔离沙箱内执行强化学习(RL)训练(macOS/Linux)、通过 OpenAPI 提交 OPD 蒸馏训练、专属模型部署上线 - **批量推理** — CSV/JSONL 构造、异步 Chat/Embedding 任务创建与跟踪、原始结果/错误下载及可选 CSV,或同步单请求 Batch Chat - **账号运维** — 授权登录、界面化配置、模型市场、用量与额度、限流提额、团队席位管理 - **套餐接入** — 支持 Token Plan 等订阅计划一键接到 CLI 和常见 Coding Agent diff --git a/packages/cli/package.json b/packages/cli/package.json index 841f467b..9c1ac9f5 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -1,6 +1,6 @@ { "name": "bailian-cli", - "version": "2.10.3", + "version": "2.10.4", "description": "CLI for Aliyun Model Studio (DashScope) AI Platform.", "keywords": [ "agent", diff --git a/packages/cli/src/commands.ts b/packages/cli/src/commands.ts index 717f45a8..91214219 100644 --- a/packages/cli/src/commands.ts +++ b/packages/cli/src/commands.ts @@ -204,6 +204,25 @@ import { finetuneCompressLogs, finetuneCompressCancel, finetuneCompressDelete, + finetuneRlAuthorize, + finetuneRlRun, + finetuneRlGet, + finetuneRlList, + finetuneRlWatch, + finetuneRlLogs, + finetuneRlCancel, + finetuneRlDelete, + finetuneOpdAuthorize, + finetuneOpdRun, + finetuneOpdParams, + finetuneOpdGet, + finetuneOpdWatch, + finetuneOpdLogs, + finetuneOpdCancel, + finetuneOpdDelete, + finetuneRuntimePrepare, + finetuneRuntimeDoctor, + finetuneRuntimeClean, deployTextCreate, deployAudioCreate, deployImageCreate, @@ -564,6 +583,25 @@ export const commands: Record = { "finetune compress logs": finetuneCompressLogs, "finetune compress cancel": finetuneCompressCancel, "finetune compress delete": finetuneCompressDelete, + "finetune rl authorize": finetuneRlAuthorize, + "finetune rl run": finetuneRlRun, + "finetune rl get": finetuneRlGet, + "finetune rl list": finetuneRlList, + "finetune rl watch": finetuneRlWatch, + "finetune rl logs": finetuneRlLogs, + "finetune rl cancel": finetuneRlCancel, + "finetune rl delete": finetuneRlDelete, + "finetune opd authorize": finetuneOpdAuthorize, + "finetune opd run": finetuneOpdRun, + "finetune opd params": finetuneOpdParams, + "finetune opd get": finetuneOpdGet, + "finetune opd watch": finetuneOpdWatch, + "finetune opd logs": finetuneOpdLogs, + "finetune opd cancel": finetuneOpdCancel, + "finetune opd delete": finetuneOpdDelete, + "finetune runtime prepare": finetuneRuntimePrepare, + "finetune runtime doctor": finetuneRuntimeDoctor, + "finetune runtime clean": finetuneRuntimeClean, "deploy text create": deployTextCreate, "deploy audio create": deployAudioCreate, "deploy image create": deployImageCreate, diff --git a/packages/cli/tests/fixtures/opd-fake-bl.mjs b/packages/cli/tests/fixtures/opd-fake-bl.mjs new file mode 100644 index 00000000..42f4e8f8 --- /dev/null +++ b/packages/cli/tests/fixtures/opd-fake-bl.mjs @@ -0,0 +1,22 @@ +#!/usr/bin/env node +// Fake bl entry for the bailian-opd runBl contract test. Emits the same output +// shapes as the real CLI: pretty-printed JSON documents, single-line JSON with +// stderr warnings, and plain text followed by a JSON line. +const args = process.argv.slice(2); +if (args.includes("pretty")) { + process.stdout.write( + `${JSON.stringify({ output: { job_id: "job-1", status: "PENDING" } }, null, 2)}\n`, + ); +} else if (args.includes("warn")) { + process.stderr.write( + `${JSON.stringify({ warning: { code: "OPD_PAIR_NOT_PUBLISHED", message: "pair not published" } })}\n`, + ); + process.stdout.write(`${JSON.stringify({ ok: true })}\n`); +} else if (args.includes("mixed")) { + process.stdout.write(`Uploading file...\n${JSON.stringify({ file_id: "file-1" })}\n`); +} else if (args.includes("error")) { + process.stderr.write(`${JSON.stringify({ error: { code: 1, message: "boom" } }, null, 2)}\n`); + process.exit(1); +} else { + process.stdout.write(`${JSON.stringify({ ok: true })}\n`); +} diff --git a/packages/cli/tests/skill-opd-reference.test.ts b/packages/cli/tests/skill-opd-reference.test.ts new file mode 100644 index 00000000..dab951c5 --- /dev/null +++ b/packages/cli/tests/skill-opd-reference.test.ts @@ -0,0 +1,261 @@ +import { spawnSync } from "node:child_process"; +import { existsSync, readFileSync, readdirSync } from "node:fs"; +import { dirname, join } from "node:path"; +import { fileURLToPath, pathToFileURL } from "node:url"; +import { validateSkillDir } from "bailian-cli-core"; +import { expect, test } from "vite-plus/test"; +import { parse } from "yaml"; + +const repositoryRoot = join(dirname(fileURLToPath(import.meta.url)), "../../.."); +const opdSkillDirectory = join(repositoryRoot, "skills/bailian-opd"); +const scriptsDirectory = join(opdSkillDirectory, "scripts"); +const assetsDirectory = join(opdSkillDirectory, "assets"); + +function readAsset(name: string): Record { + return JSON.parse(readFileSync(join(assetsDirectory, name), "utf8")) as Record; +} + +test("OPD is a valid standalone skill aligned with the CLI version", () => { + const metadata = validateSkillDir(opdSkillDirectory, "bailian-opd"); + expect(metadata.name).toBe("bailian-opd"); + + const skillMarkdown = readFileSync(join(opdSkillDirectory, "SKILL.md"), "utf8"); + const frontmatter = parse(skillMarkdown.split(/^---\s*$/m)[1]) as { + metadata: { version: string; requires?: { bins?: string[] } }; + }; + const cliPackage = JSON.parse( + readFileSync(join(repositoryRoot, "packages/cli/package.json"), "utf8"), + ) as { version: string }; + expect(frontmatter.metadata.version).toBe(cliPackage.version); + expect(frontmatter.metadata.requires?.bins).toEqual(["bl", "node"]); + + for (const document of ["SKILL.md", "README.md", "README.zh.md"]) { + const text = readFileSync(join(opdSkillDirectory, document), "utf8"); + for (const link of text.matchAll(/\]\(([^)]+)\)/g)) { + const target = link[1].split("#")[0]; + if (/^https?:/.test(target)) continue; + expect(existsSync(join(opdSkillDirectory, target)), `${document} → ${target}`).toBe(true); + } + } +}); + +// Syntax check of the shipped .mjs assets runs in a child process because +// `node --check` is the only parser that validates them as Node ESM without +// executing their top-level gates. +test("OPD scripts pass node --check", () => { + const scripts = readdirSync(scriptsDirectory).filter((name) => name.endsWith(".mjs")); + expect(scripts.sort()).toEqual([ + "lib.mjs", + "opd-preflight.mjs", + "opd-submit.mjs", + "opd-wait.mjs", + ]); + for (const script of scripts) { + const result = spawnSync(process.execPath, ["--check", join(scriptsDirectory, script)], { + encoding: "utf8", + }); + expect(result.status, `${script}: ${result.stderr}`).toBe(0); + } +}); + +test("OPD baselines match the verified request snapshots", () => { + const flashHyper = readAsset("baseline-9b-from-flash.hyper_parameters.json"); + const fixtureHyper = JSON.parse( + readFileSync( + join(repositoryRoot, "packages/commands/tests/e2e/fixtures/opd-hyper-parameters.json"), + "utf8", + ), + ) as Record; + expect(Object.keys(flashHyper).sort()).toEqual(Object.keys(fixtureHyper).sort()); + for (const key of Object.keys(fixtureHyper)) { + const expected = fixtureHyper[key]; + const actual = flashHyper[key]; + const bothNumeric = + expected !== "" && + actual !== "" && + Number.isFinite(Number(expected)) && + Number.isFinite(Number(actual)); + if (bothNumeric) { + expect(Number(actual), key).toBe(Number(expected)); + } else { + expect(actual, key).toEqual(expected); + } + } + + const explicitHyper = readAsset("baseline-9b-from-397b.hyper_parameters.json"); + expect(Object.keys(explicitHyper)).toHaveLength(29); + const teacherKeys = Object.keys(explicitHyper).filter((key) => key.startsWith("opd_teacher_")); + expect(teacherKeys.sort()).toEqual( + [ + "opd_teacher_gpu_memory_utilization", + "opd_teacher_infer_tp", + "opd_teacher_max_model_len", + "opd_teacher_max_num_batched_tokens", + "opd_teacher_max_num_seqs", + "opd_teacher_n_gpus_per_node", + "opd_teacher_nnodes", + "opd_teacher_num_replicas", + ].sort(), + ); + expect(explicitHyper.opd_teacher_infer_tp).toBe(explicitHyper.opd_teacher_n_gpus_per_node); + + for (const [name, capacity] of [ + ["baseline-9b-from-flash.resource_config.json", 16], + ["baseline-9b-from-397b.resource_config.json", 24], + ] as const) { + const resource = readAsset(name); + expect(resource).toEqual({ + charge_type: "mtu_postpaid", + mtu_spec_code: "MTU4", + mtu_capacity: capacity, + }); + } +}); + +test("OPD capacity formulas reproduce the baseline sizing", async () => { + const lib = (await import(pathToFileURL(join(scriptsDirectory, "lib.mjs")).href)) as { + computeCapacity: (hyperParameters: Record) => { + complete: boolean; + studentExternal?: number; + studentInternal?: number; + teacherGpus?: number; + totalExternal?: number; + totalInternal?: number; + }; + }; + + // Flash baseline: external teacher, teacher fields omitted (server defaults). + // Student external = (1 + 1) * 4 = 8; Flash teacher occupies 8 GPUs → 16. + const flash = lib.computeCapacity(readAsset("baseline-9b-from-flash.hyper_parameters.json")); + expect(flash.studentExternal).toBe(8); + expect(flash.studentInternal).toBe(6); + expect(flash.complete).toBe(false); + const flashResource = readAsset("baseline-9b-from-flash.resource_config.json"); + expect((flash.studentExternal as number) + 8).toBe(flashResource.mtu_capacity); + + // 397B baseline: all teacher fields explicit → fully computable. + // Internal student = 1*8 + 1*8 = 16; teacher = 1*1*8 = 8 → 24. + const explicit = lib.computeCapacity(readAsset("baseline-9b-from-397b.hyper_parameters.json")); + expect(explicit.complete).toBe(true); + expect(explicit.studentInternal).toBe(16); + expect(explicit.teacherGpus).toBe(8); + expect(explicit.totalInternal).toBe(24); + const explicitResource = readAsset("baseline-9b-from-397b.resource_config.json"); + expect(explicit.totalInternal).toBe(explicitResource.mtu_capacity); +}); + +test("OPD batch-fit helpers mirror the CLI zero-step gate", async () => { + const lib = (await import(pathToFileURL(join(scriptsDirectory, "lib.mjs")).href)) as { + computeBatchFit: ( + hyperParameters: Record, + recordCount?: number, + ) => { steps?: number; requiredSamples?: number }; + miniBatchLimit: ( + hyperParameters: Record, + ) => { miniBatchSize: number; limit: number } | undefined; + }; + expect(lib.computeBatchFit({ batch_size: 64, n_epochs: 1 }, 12)).toMatchObject({ + steps: 0, + requiredSamples: 64, + }); + expect(lib.computeBatchFit({ batch_size: 64, n_epochs: 1 }, 96).steps).toBe(1); + expect(lib.computeBatchFit({ batch_size: 64, n_epochs: 3 }, 22)).toMatchObject({ + steps: 1, + requiredSamples: 22, + }); + expect(lib.computeBatchFit({ batch_size: 64 }, 96).steps).toBeUndefined(); + expect(lib.computeBatchFit({ batch_size: 64, n_epochs: 1 }).steps).toBeUndefined(); + expect(lib.miniBatchLimit({ ppo_mini_batch_size: 16, batch_size: 64, n_rollouts: 4 })).toEqual({ + miniBatchSize: 16, + limit: 256, + }); + expect(lib.miniBatchLimit({ ppo_mini_batch_size: 16 })).toBeUndefined(); + + const preflightSource = readFileSync(join(scriptsDirectory, "opd-preflight.mjs"), "utf8"); + expect(preflightSource).toContain('addStage("batch-fit"'); +}); + +test("OPD skill ships no real IDs, credentials, or internal references", () => { + const files = [ + "SKILL.md", + "README.md", + "README.zh.md", + ...readdirSync(scriptsDirectory).map((name) => join("scripts", name)), + ...readdirSync(assetsDirectory).map((name) => join("assets", name)), + ]; + const forbidden = [ + /\b(?:file|ft|ws)-[0-9a-f]{10,}/i, + /sk-[A-Za-z0-9]{16,}/, + /model-opd-bl-cli-handoff|opd-handoff|Desktop\//, + /alibaba-inc\.com|aliyun-inc\.com/, + ]; + for (const file of files) { + const text = readFileSync(join(opdSkillDirectory, file), "utf8"); + for (const pattern of forbidden) { + expect(pattern.test(text), `${file} matches ${pattern}`).toBe(false); + } + } +}); + +test("OPD consent and read-only gates are enforced in the shipped sources", () => { + const skillMarkdown = readFileSync(join(opdSkillDirectory, "SKILL.md"), "utf8"); + expect(skillMarkdown).toContain("../bailian-protocol/SKILL.md"); + expect(skillMarkdown).toContain("Never add `--yes` or `--confirmed` automatically."); + + const submitSource = readFileSync(join(scriptsDirectory, "opd-submit.mjs"), "utf8"); + const consentGate = submitSource.indexOf("if (!flags.confirmed)"); + const firstSpawn = submitSource.indexOf("runBl("); + expect(consentGate).toBeGreaterThan(-1); + expect(firstSpawn).toBeGreaterThan(consentGate); + expect(submitSource).toContain("usageError("); + + const preflightSource = readFileSync(join(scriptsDirectory, "opd-preflight.mjs"), "utf8"); + expect(preflightSource).toContain('"authorize", "--yes"'); + expect(preflightSource).not.toMatch(/runBl\(\s*\[[^\]]*--authorize/); + + const waitSource = readFileSync(join(scriptsDirectory, "opd-wait.mjs"), "utf8"); + expect(waitSource).toContain("export function waitForJob"); + expect(waitSource).not.toContain('"--follow"'); + expect(waitSource).toContain("realpathSync(process.argv[1])"); +}); + +// runBl spawns a real child process: the fake bl entry exercises the spawn / +// env / stdout-parse boundary that unit-level JSON parsing cannot cover. +test("OPD runBl parses pretty-printed and line-based bl JSON contracts", async () => { + const lib = (await import(pathToFileURL(join(scriptsDirectory, "lib.mjs")).href)) as { + runBl: ( + args: string[], + options?: { callerName?: string }, + ) => { + exitCode: number; + json?: Record; + warnings: { code: string }[]; + error?: { message: string }; + }; + }; + const previousEntry = process.env.BAILIAN_BL_ENTRY; + process.env.BAILIAN_BL_ENTRY = join( + repositoryRoot, + "packages/cli/tests/fixtures/opd-fake-bl.mjs", + ); + try { + const pretty = lib.runBl(["pretty"], { callerName: "test" }); + expect(pretty.exitCode).toBe(0); + expect(pretty.json).toEqual({ output: { job_id: "job-1", status: "PENDING" } }); + + const warned = lib.runBl(["warn"], { callerName: "test" }); + expect(warned.exitCode).toBe(0); + expect(warned.json).toEqual({ ok: true }); + expect(warned.warnings.map((warning) => warning.code)).toEqual(["OPD_PAIR_NOT_PUBLISHED"]); + + const mixed = lib.runBl(["mixed"], { callerName: "test" }); + expect(mixed.json).toEqual({ file_id: "file-1" }); + + const failed = lib.runBl(["error"], { callerName: "test" }); + expect(failed.exitCode).toBe(1); + expect(failed.error?.message).toBe("boom"); + } finally { + if (previousEntry === undefined) delete process.env.BAILIAN_BL_ENTRY; + else process.env.BAILIAN_BL_ENTRY = previousEntry; + } +}); diff --git a/packages/commands/package.json b/packages/commands/package.json index 1e2a46fa..f5ff5306 100644 --- a/packages/commands/package.json +++ b/packages/commands/package.json @@ -1,6 +1,6 @@ { "name": "bailian-cli-commands", - "version": "2.10.3", + "version": "2.10.4", "description": "Command library for bailian-cli products (knowledge, memory, media, …). See https://www.npmjs.com/package/bailian-cli for usage.", "homepage": "https://bailian.console.aliyun.com/cli", "bugs": { diff --git a/packages/commands/src/commands/finetune/capability.ts b/packages/commands/src/commands/finetune/capability.ts index 6c725aa4..1899066f 100644 --- a/packages/commands/src/commands/finetune/capability.ts +++ b/packages/commands/src/commands/finetune/capability.ts @@ -7,6 +7,7 @@ import { isTrainingTypeCli, trainingTypeMethodVariant, TRAINING_TYPES_CLI, + FINETUNE_CATALOG_SUPPORTS, anonymousConsoleCall, UsageError, type HttpDeps, @@ -16,16 +17,20 @@ import { } from "bailian-cli-core"; /** - * Page through every foundation-model page (listFoundationModels, public — no - * console login needed, so the gateway is called anonymously). Returns raw - * records so capability fields (`supports` / `trainingTypes`) are preserved - * for filtering. + * Page through the trainable foundation-model catalog (listFoundationModels + * scoped by `fineTune`, public — no console login needed, so the gateway is + * called anonymously). The default inference-scoped catalog omits training-only + * base models and their snapshots; scoping matches the console training selector. + * Returns raw records so capability fields (`supports` / `trainingTypes`) are + * preserved for filtering. */ async function fetchAllFoundationModels( settings: Settings, diagnostics: Pick, ): Promise { - const all = await fetchModelListAll(anonymousConsoleCall(settings, diagnostics)); + const all = await fetchModelListAll(anonymousConsoleCall(settings, diagnostics), { + supports: FINETUNE_CATALOG_SUPPORTS, + }); return all as ModelCapability[]; } diff --git a/packages/commands/src/commands/finetune/create.ts b/packages/commands/src/commands/finetune/create.ts index 38795c08..1a0cb960 100644 --- a/packages/commands/src/commands/finetune/create.ts +++ b/packages/commands/src/commands/finetune/create.ts @@ -1,9 +1,7 @@ import { - formatCommand, defineCommand, createFineTune, getFineTuneParams, - uploadDataset, detectModality, getProfile, fetchModelCapability, @@ -14,7 +12,6 @@ import { isTrainingTypeCli, TRAINING_TYPES_CLI, DEFAULT_TRAINING_TYPE, - formatIssue, BailianError, ExitCode, type HttpDeps, @@ -22,189 +19,10 @@ import { type CreateFineTuneRequest, type FineTuneHyperParameters, type FineTuneHyperParameterIssue, - type DatasetFile, - type TrainingProfile, type DataModality, type FlagsDef, } from "bailian-cli-core"; -import { existsSync, statSync } from "fs"; -import { basename } from "path"; - -/** - * A `--datasets` / `--validations` token is treated as a local file to upload - * when it resolves to an existing file on disk; otherwise it is forwarded - * verbatim as a previously-uploaded file-id (the `file-xxx` shape returned by - * `dataset upload`). This lets users skip the manual upload step: - * `--datasets ./train.jsonl` uploads then trains in one shot. - */ -function isLocalPath(token: string): boolean { - return existsSync(token) && statSync(token).isFile(); -} - -interface ResolvedDataset { - /** - * Tokens in input order. Local paths are kept as-is here (a placeholder - * until `uploadResolvedLocal` swaps them for real file-ids); bare file-ids - * pass through untouched. In dry-run the paths stay (the previewed body - * reflects exactly what the user typed). - */ - fileIds: string[]; - /** Local paths in input order, for the deferred upload step. */ - localPaths: string[]; - /** In-hand size for the first local token, if known (local statSync). */ - firstSize?: number; - /** - * Total training-sample count across local tokens, when known. Sourced from - * `validateDataset`'s `stats.totalRecords` (summed per token). Undefined when - * any token is a bare file-id (no local file to count) or in dry-run — the - * pre-submit batch-size gate only fires when this is known, so file-id flows - * fall through to the platform rather than risk a false positive. - */ - recordCount?: number; -} - -/** - * Analyze a comma-separated `--datasets` / `--validations` value WITHOUT - * uploading: bare file-ids pass through; local paths are validated through the - * same pipeline as `dataset upload` (so structural errors surface here), - * their sample count and size are captured for the pre-submit gate, and the - * path itself is recorded in `localPaths` for a later, deferred upload. - * - * Splitting analysis from upload lets the batch-size gate fire before any - * network call — a doomed job (too few samples) is rejected without burning an - * upload, and is offline-testable. In dry-run mode local paths are not - * validated (the preview never touches the network or the disk beyond stat). - */ -async function analyzeDatasetTokens( - context: Pick, - raw: string, - label: string, - profile: TrainingProfile, - modality: DataModality, - model: string, - /** Pre-detected modality for a known path (avoids re-opening the file). */ - knownModality?: { path: string; modality: DataModality }, -): Promise { - const { settings } = context; - const tokens = raw - .split(",") - .map((token) => token.trim()) - .filter(Boolean); - if (tokens.length === 0) { - throw new BailianError(`--${label} must contain at least one entry.`, ExitCode.USAGE); - } - - const fileIds: string[] = []; - const localPaths: string[] = []; - let firstSize: number | undefined; - let recordCount: number | undefined; - // A file-id token has no local file to count, so the total sample count is - // only knowable when every token is a local path. Once any file-id is seen, - // flip to unknown and stop accumulating to avoid an undercount that could - // trip the batch-size gate falsely. - let recordCountKnown = true; - - for (const token of tokens) { - if (!isLocalPath(token)) { - fileIds.push(token); - recordCountKnown = false; - continue; - } - - fileIds.push(token); - localPaths.push(token); - - if (settings.dryRun) continue; - - // The command's modality is authoritative; each local file is validated - // under that modality's schema. Reuse the caller's pre-detected modality - // when available to avoid opening the same file twice (matters for large - // ZIPs). - const tokenModality = - knownModality && knownModality.path === token ? knownModality.modality : modality; - - // Local path → validate through the profile. The profile internally routes - // to the correct validator based on modality. Upload is deferred to - // `uploadResolvedLocal` so the gate can run first. `model` is forwarded for - // schema-agnostic cross-checks. - const result = await profile.validate(token, tokenModality, { model }); - if (!result.valid) { - const lines = [ - `Dataset validation failed for ${token}`, - ...result.errors.slice(0, 10).map(formatIssue), - ]; - if (result.errors.length > 10) { - lines.push(` … and ${result.errors.length - 10} more error(s).`); - } - lines.push( - "", - `Hint: re-run \`${formatCommand(context.identity, "dataset validate --file ")}\` for the full report,`, - ` or upload manually with \`${formatCommand(context.identity, "dataset upload --no-validate")}\` and`, - " pass the resulting file-id here.", - ); - throw new BailianError(lines.join("\n"), ExitCode.GENERAL); - } - if (result.warnings.length > 0) { - context.output.warning({ - code: "DATASET_VALIDATION_WARNINGS", - message: { - "en-US": `Dataset validation passed with ${result.warnings.length} warning(s) for ${token}.`, - "zh-CN": `${token} 数据集校验通过,共 ${result.warnings.length} 条警告。`, - }, - details: { file: token, warnings: result.warnings }, - }); - } - - // Accumulate the sample count so the caller can pre-flight the batch-size - // gate before submitting. `totalRecords` is set by the jsonl validator as - // (non-blank lines); undefined stats fall back to "unknown" (no gate). - const tokenRecords = result.stats.totalRecords; - if (typeof tokenRecords === "number") { - recordCount = (recordCount ?? 0) + tokenRecords; - } - if (firstSize === undefined) firstSize = statSync(token).size; - } - - return { - fileIds, - localPaths, - firstSize, - recordCount: recordCountKnown ? recordCount : undefined, - }; -} - -/** - * Upload each local path recorded in `resolved.localPaths`, swapping the - * placeholder path entries in `resolved.fileIds` for the returned file-ids. - * Returns the uploaded file records. No-op in dry-run. Validation already - * happened in `analyzeDatasetTokens`, so this is pure upload. - */ -async function uploadResolvedLocal( - context: Pick, - resolved: ResolvedDataset, - purpose: string, - label: string, -): Promise { - const { client } = context; - const uploaded: DatasetFile[] = []; - for (const [index, token] of resolved.fileIds.entries()) { - if (!isLocalPath(token)) continue; - const file: DatasetFile = await uploadDataset(client, { filePath: token, purpose }); - if (!file.file_id) { - throw new BailianError( - `Upload of ${token} succeeded but no file_id was returned.`, - ExitCode.GENERAL, - ); - } - uploaded.push(file); - resolved.fileIds[index] = file.file_id; - context.output.info({ - "en-US": `Uploaded ${basename(token)} → ${file.file_id} (auto from --${label})`, - "zh-CN": `已上传 ${basename(token)} → ${file.file_id}(来自 --${label})`, - }); - } - return uploaded; -} +import { analyzeDatasetTokens, isLocalPath, uploadResolvedLocal } from "./dataset-input.ts"; /** The modality a `finetune create` subcommand is bound to. */ type CommandModality = "text" | "audio" | "image" | "video"; @@ -250,7 +68,7 @@ function explicitHyperParameterOverrides( return overrides; } -function formatHyperParameterIssue( +export function formatHyperParameterIssue( context: Pick, issue: FineTuneHyperParameterIssue, ): string { diff --git a/packages/commands/src/commands/finetune/dataset-input.ts b/packages/commands/src/commands/finetune/dataset-input.ts new file mode 100644 index 00000000..89a4fdb1 --- /dev/null +++ b/packages/commands/src/commands/finetune/dataset-input.ts @@ -0,0 +1,200 @@ +/** + * Shared dataset-input pipeline for `finetune create` and + * `finetune opd run`: resolve comma-separated file-id / local-path tokens, + * validate local files through the training profile, and defer upload until + * pre-flight checks pass. + */ +import { existsSync, statSync } from "fs"; +import { basename } from "path"; +import { + BailianError, + ExitCode, + formatCommand, + formatIssue, + uploadDataset, + type CommandContext, + type DataModality, + type DatasetFile, + type TrainingProfile, +} from "bailian-cli-core"; + +/** + * A `--datasets` / `--validations` token is treated as a local file to upload + * when it resolves to an existing file on disk; otherwise it is forwarded + * verbatim as a previously-uploaded file-id (the `file-xxx` shape returned by + * `dataset upload`). This lets users skip the manual upload step: + * `--datasets ./train.jsonl` uploads then trains in one shot. + */ +export function isLocalPath(token: string): boolean { + return existsSync(token) && statSync(token).isFile(); +} + +export interface ResolvedDataset { + /** + * Tokens in input order. Local paths are kept as-is here (a placeholder + * until `uploadResolvedLocal` swaps them for real file-ids); bare file-ids + * pass through untouched. In dry-run the paths stay (the previewed body + * reflects exactly what the user typed). + */ + fileIds: string[]; + /** Local paths in input order, for the deferred upload step. */ + localPaths: string[]; + /** In-hand size for the first local token, if known (local statSync). */ + firstSize?: number; + /** + * Total training-sample count across local tokens, when known. Sourced from + * `validateDataset`'s `stats.totalRecords` (summed per token). Undefined when + * any token is a bare file-id (no local file to count) or in dry-run — the + * pre-submit batch-size gate only fires when this is known, so file-id flows + * fall through to the platform rather than risk a false positive. + */ + recordCount?: number; +} + +/** + * Analyze a comma-separated `--datasets` / `--validations` value WITHOUT + * uploading: bare file-ids pass through; local paths are validated through the + * same pipeline as `dataset upload` (so structural errors surface here), + * their sample count and size are captured for the pre-submit gate, and the + * path itself is recorded in `localPaths` for a later, deferred upload. + * + * Splitting analysis from upload lets the batch-size gate fire before any + * network call — a doomed job (too few samples) is rejected without burning an + * upload, and is offline-testable. In dry-run mode local paths are not + * validated (the preview never touches the network or the disk beyond stat). + */ +export async function analyzeDatasetTokens( + context: Pick, + raw: string, + label: string, + profile: TrainingProfile, + modality: DataModality, + model: string, + /** Pre-detected modality for a known path (avoids re-opening the file). */ + knownModality?: { path: string; modality: DataModality }, +): Promise { + const { settings } = context; + const tokens = raw + .split(",") + .map((token) => token.trim()) + .filter(Boolean); + if (tokens.length === 0) { + throw new BailianError(`--${label} must contain at least one entry.`, ExitCode.USAGE); + } + + const fileIds: string[] = []; + const localPaths: string[] = []; + let firstSize: number | undefined; + let recordCount: number | undefined; + // A file-id token has no local file to count, so the total sample count is + // only knowable when every token is a local path. Once any file-id is seen, + // flip to unknown and stop accumulating to avoid an undercount that could + // trip the batch-size gate falsely. + let recordCountKnown = true; + + for (const token of tokens) { + if (!isLocalPath(token)) { + fileIds.push(token); + recordCountKnown = false; + continue; + } + + fileIds.push(token); + localPaths.push(token); + + if (settings.dryRun) continue; + + // The command's modality is authoritative; each local file is validated + // under that modality's schema. Reuse the caller's pre-detected modality + // when available to avoid opening the same file twice (matters for large + // ZIPs). + const tokenModality = + knownModality && knownModality.path === token ? knownModality.modality : modality; + + // Local path → validate through the profile. The profile internally routes + // to the correct validator based on modality. Upload is deferred to + // `uploadResolvedLocal` so the gate can run first. `model` is forwarded for + // schema-agnostic cross-checks. + const result = await profile.validate(token, tokenModality, { model }); + if (!result.valid) { + const lines = [ + `Dataset validation failed for ${token}`, + ...result.errors.slice(0, 10).map(formatIssue), + ]; + if (result.errors.length > 10) { + lines.push(` … and ${result.errors.length - 10} more error(s).`); + } + lines.push( + "", + `Hint: re-run \`${formatCommand(context.identity, "dataset validate --file ")}\` for the full report,`, + ` or upload manually with \`${formatCommand(context.identity, "dataset upload --no-validate")}\` and`, + " pass the resulting file-id here.", + ); + throw new BailianError(lines.join("\n"), ExitCode.GENERAL); + } + if (result.warnings.length > 0) { + context.output.warning({ + code: "DATASET_VALIDATION_WARNINGS", + message: { + "en-US": `Dataset validation passed with ${result.warnings.length} warning(s) for ${token}.`, + "zh-CN": `${token} 数据集校验通过,共 ${result.warnings.length} 条警告。`, + }, + details: { file: token, warnings: result.warnings }, + }); + } + + // Accumulate the sample count so the caller can pre-flight the batch-size + // gate before submitting. `totalRecords` is set by the jsonl validator as + // (non-blank lines); undefined stats fall back to "unknown" (no gate). + const tokenRecords = result.stats.totalRecords; + if (typeof tokenRecords === "number") { + recordCount = (recordCount ?? 0) + tokenRecords; + } + if (firstSize === undefined) firstSize = statSync(token).size; + } + + return { + fileIds, + localPaths, + firstSize, + recordCount: recordCountKnown ? recordCount : undefined, + }; +} + +/** + * Upload each local path recorded in `resolved.localPaths`, swapping the + * placeholder path entries in `resolved.fileIds` for the returned file-ids. + * Returns the uploaded file records. No-op in dry-run. Validation already + * happened in `analyzeDatasetTokens`, so this is pure upload. + */ +export async function uploadResolvedLocal( + context: Pick, + resolved: ResolvedDataset, + purpose: string, + label: string, + workspaceId?: string, +): Promise { + const { client } = context; + const uploaded: DatasetFile[] = []; + for (const [index, token] of resolved.fileIds.entries()) { + if (!isLocalPath(token)) continue; + const file: DatasetFile = await uploadDataset(client, { + filePath: token, + purpose, + workspaceId, + }); + if (!file.file_id) { + throw new BailianError( + `Upload of ${token} succeeded but no file_id was returned.`, + ExitCode.GENERAL, + ); + } + uploaded.push(file); + resolved.fileIds[index] = file.file_id; + context.output.info({ + "en-US": `Uploaded ${basename(token)} → ${file.file_id} (auto from --${label})`, + "zh-CN": `已上传 ${basename(token)} → ${file.file_id}(来自 --${label})`, + }); + } + return uploaded; +} diff --git a/packages/commands/src/commands/finetune/get.ts b/packages/commands/src/commands/finetune/get.ts index e18ff6b5..da1b9d2c 100644 --- a/packages/commands/src/commands/finetune/get.ts +++ b/packages/commands/src/commands/finetune/get.ts @@ -77,6 +77,22 @@ export default defineCommand({ charge_type: typeof job.charge_type === "string" ? job.charge_type : "", }; + // OPD (pg_opd) readback fields — additive: only present on OPD jobs, so + // sft/dpo output is unchanged. + if (job.teacher_model !== undefined) item.teacher_model = job.teacher_model; + if (job.training_datasets !== undefined) item.training_datasets = job.training_datasets; + if (job.validation_datasets !== undefined) item.validation_datasets = job.validation_datasets; + if (job.mtu_spec_code !== undefined) item.mtu_spec_code = job.mtu_spec_code; + if (job.mtu_capacity !== undefined) item.mtu_capacity = job.mtu_capacity; + // Descriptor-carrying jobs show data in training_datasets/validation_datasets; + // the empty legacy id lists there mislead users into thinking upload failed. + if (job.training_datasets !== undefined && (job.training_file_ids ?? []).length === 0) { + delete item.training_files; + } + if (job.validation_datasets !== undefined && (job.validation_file_ids ?? []).length === 0) { + delete item.validation_files; + } + // Actual fee: only when the platform reports a concrete token count // (SUCCEEDED / CANCELED). Best-effort — silently omitted on lookup failure. if (usageTokens !== undefined && usageTokens > 0 && job.model) { diff --git a/packages/commands/src/commands/finetune/opd-authorize.ts b/packages/commands/src/commands/finetune/opd-authorize.ts new file mode 100644 index 00000000..3ebb7b71 --- /dev/null +++ b/packages/commands/src/commands/finetune/opd-authorize.ts @@ -0,0 +1,61 @@ +import { type FlagsDef } from "bailian-cli-core"; +import { OPD_TRAINING_DOC } from "bailian-cli-runtime"; +import { defineConsoleReadCommand } from "../shared/console-read.ts"; +import { runRlAuthorize } from "./rl-shared.ts"; + +const AUTHORIZE_FLAGS = { + authorize: { + type: "switch", + description: { + "en-US": + "Permit enabling OPD once the service roles are manually authorized (read-only probe without it)", + "zh-CN": "允许在角色已手动授权后开通 OPD(不传则仅只读检查)", + }, + }, +} satisfies FlagsDef; + +export default defineConsoleReadCommand({ + defaultOutput: "json", + description: { + "en-US": "Check and authorize OPD distillation access (whitelist, service roles, enablement)", + "zh-CN": "检查并授权 OPD 蒸馏访问能力(准入白名单、服务角色、业务开通)", + }, + auth: "console", + risk: { + level: "high", + reason: "destructive", + message: { + "en-US": + "With --authorize this enables the OPD training mode for your account. The CLI never creates service-linked roles.", + "zh-CN": "传入 --authorize 时会为账号开通 OPD 训练模式。CLI 不会创建服务关联角色。", + }, + }, + usageArgs: "[--authorize]", + flags: AUTHORIZE_FLAGS, + exampleArgs: ["", "--authorize --yes", "--dry-run"], + notes: [ + { + "en-US": `Service-linked roles must be authorized manually first (${OPD_TRAINING_DOC}); missing roles report REQUIRES_USER_ACTION and block enablement.`, + "zh-CN": `服务关联角色须先手动授权(${OPD_TRAINING_DOC});角色缺失时报告 REQUIRES_USER_ACTION 并阻止开通。`, + }, + { + "en-US": + "Without --authorize this is a read-only probe. Each capability reports READY / MISSING / UNKNOWN / REQUIRES_USER_ACTION / FAILED; a failed query is UNKNOWN, never assumed enabled.", + "zh-CN": + "不传 --authorize 时仅只读检查。每项能力返回 READY / MISSING / UNKNOWN / REQUIRES_USER_ACTION / FAILED;查询失败记为 UNKNOWN,绝不臆断为已开通。", + }, + { + "en-US": + "Only OPD is enabled; RL is never auto-enabled. In CI pass --authorize --yes to permit changes; --yes alone does not expand permissions.", + "zh-CN": + "只开通 OPD,不会自动开通 RL。CI 中须显式 --authorize --yes 才允许变更;单独 --yes 不扩大权限。", + }, + ], + async run(ctx) { + await runRlAuthorize(ctx, { + target: "opd", + action: "finetune.opd.authorize", + authorize: ctx.flags.authorize === true, + }); + }, +}); diff --git a/packages/commands/src/commands/finetune/opd-batch-fit.ts b/packages/commands/src/commands/finetune/opd-batch-fit.ts new file mode 100644 index 00000000..6479565c --- /dev/null +++ b/packages/commands/src/commands/finetune/opd-batch-fit.ts @@ -0,0 +1,58 @@ +import type { FineTuneHyperParameters } from "bailian-cli-core"; + +function numericField(hyperParameters: FineTuneHyperParameters, key: string): number | undefined { + const raw = hyperParameters[key]; + if (raw === undefined) return undefined; + const value = Number(raw); + return Number.isFinite(value) ? value : undefined; +} + +export interface OpdBatchFit { + batchSize?: number; + nEpochs?: number; + recordCount?: number; + /** floor(recordCount * nEpochs / batchSize); undefined when not computable. */ + steps?: number; + /** Minimum raw samples for at least one step: ceil(batchSize / nEpochs). */ + requiredSamples?: number; +} + +/** + * OPD consumes batch_size prompts per training step (the published docs define + * batch_size as "每步样本数"; server logs show ppo_mini_batch_size × + * require_batches = batch_size). total_training_steps = floor(samples × + * n_epochs / batch_size); zero steps trips the DLC assertion lr_decay_steps > 0 + * AFTER the job is created and billed. The raw local count is an upper bound on + * the post-preprocessing count, so "locally too few" is a sound hard reject. + */ +export function computeOpdBatchFit( + hyperParameters: FineTuneHyperParameters, + recordCount?: number, +): OpdBatchFit { + const batchSize = numericField(hyperParameters, "batch_size"); + const nEpochs = numericField(hyperParameters, "n_epochs"); + const fit: OpdBatchFit = { batchSize, nEpochs, recordCount }; + if (batchSize !== undefined && batchSize > 0 && nEpochs !== undefined && nEpochs >= 1) { + fit.requiredSamples = Math.ceil(batchSize / nEpochs); + if (recordCount !== undefined) { + fit.steps = Math.floor((recordCount * nEpochs) / batchSize); + } + } + return fit; +} + +/** + * Published constraint: ppo_mini_batch_size ≤ batch_size × n_rollouts. + * Returns the values only when all three fields are explicit. + */ +export function opdMiniBatchLimit( + hyperParameters: FineTuneHyperParameters, +): { miniBatchSize: number; limit: number } | undefined { + const miniBatchSize = numericField(hyperParameters, "ppo_mini_batch_size"); + const batchSize = numericField(hyperParameters, "batch_size"); + const nRollouts = numericField(hyperParameters, "n_rollouts"); + if (miniBatchSize === undefined || batchSize === undefined || nRollouts === undefined) { + return undefined; + } + return { miniBatchSize, limit: batchSize * nRollouts }; +} diff --git a/packages/commands/src/commands/finetune/opd-cancel.ts b/packages/commands/src/commands/finetune/opd-cancel.ts new file mode 100644 index 00000000..55ac0384 --- /dev/null +++ b/packages/commands/src/commands/finetune/opd-cancel.ts @@ -0,0 +1,3 @@ +import { defineJobCancelCommand } from "./rl-job-commands.ts"; + +export default defineJobCancelCommand("opd"); diff --git a/packages/commands/src/commands/finetune/opd-delete.ts b/packages/commands/src/commands/finetune/opd-delete.ts new file mode 100644 index 00000000..117935fa --- /dev/null +++ b/packages/commands/src/commands/finetune/opd-delete.ts @@ -0,0 +1,3 @@ +import { defineJobDeleteCommand } from "./rl-job-commands.ts"; + +export default defineJobDeleteCommand("opd"); diff --git a/packages/commands/src/commands/finetune/opd-get.ts b/packages/commands/src/commands/finetune/opd-get.ts new file mode 100644 index 00000000..89a5c832 --- /dev/null +++ b/packages/commands/src/commands/finetune/opd-get.ts @@ -0,0 +1,3 @@ +import { defineJobGetCommand } from "./rl-job-commands.ts"; + +export default defineJobGetCommand("opd"); diff --git a/packages/commands/src/commands/finetune/opd-logs.ts b/packages/commands/src/commands/finetune/opd-logs.ts new file mode 100644 index 00000000..36144413 --- /dev/null +++ b/packages/commands/src/commands/finetune/opd-logs.ts @@ -0,0 +1,3 @@ +import { defineJobLogsCommand } from "./rl-job-commands.ts"; + +export default defineJobLogsCommand("opd"); diff --git a/packages/commands/src/commands/finetune/opd-model-matrix.ts b/packages/commands/src/commands/finetune/opd-model-matrix.ts new file mode 100644 index 00000000..f799f0fa --- /dev/null +++ b/packages/commands/src/commands/finetune/opd-model-matrix.ts @@ -0,0 +1,38 @@ +import { OPD_MODEL_MATRIX_DOC } from "bailian-cli-runtime"; + +// Published pure-Model-OPD student/teacher pairs, CN North-2 (Beijing), from +// the official docs "模型与训练单元" section (OPD_MODEL_MATRIX_DOC), checked +// 2026-11-18. All pairs are invite-only; Singapore publishes none. This is a +// point-in-time snapshot of a published doc, not a live API contract: server +// config may move ahead of it, so mismatches only warn, never block. +const PUBLISHED_OPD_PAIRS = new Set([ + "qwen3.5-2b|qwen3.5-27b", + "qwen3.5-2b|qwen3.5-35b-a3b", + "qwen3.5-2b|qwen3.5-122b-a10b", + "qwen3.5-2b|qwen3.5-397b-a17b", + "qwen3.5-4b|qwen3.5-27b", + "qwen3.5-4b|qwen3.5-35b-a3b", + "qwen3.5-4b|qwen3.5-122b-a10b", + "qwen3.5-4b|qwen3.5-397b-a17b", + "qwen3.5-9b|qwen3.5-27b", + "qwen3.5-9b|qwen3.5-35b-a3b", + "qwen3.5-9b|qwen3.5-122b-a10b", + "qwen3.5-9b|qwen3.5-397b-a17b", + "qwen3.5-9b|qwen3.8-flash", + "qwen3.5-9b|qwen3.8-max", + "qwen3.5-27b|qwen3.5-122b-a10b", + "qwen3.5-27b|qwen3.5-397b-a17b", + "qwen3.5-35b-a3b|qwen3.5-122b-a10b", + "qwen3.5-35b-a3b|qwen3.5-397b-a17b", +]); + +export function isPublishedOpdPair(studentModel: string, teacherModel: string): boolean { + return PUBLISHED_OPD_PAIRS.has(`${studentModel}|${teacherModel}`); +} + +// The doc recommends MTU4 × 24 for every published pair. It is a sizing +// recommendation for the default layout, not an equality constraint: custom +// student layouts have succeeded with less (e.g. 9B←Flash at 16). +export const OPD_RECOMMENDED_MTU_CAPACITY = 24; + +export { OPD_MODEL_MATRIX_DOC }; diff --git a/packages/commands/src/commands/finetune/opd-params.ts b/packages/commands/src/commands/finetune/opd-params.ts new file mode 100644 index 00000000..aac6f664 --- /dev/null +++ b/packages/commands/src/commands/finetune/opd-params.ts @@ -0,0 +1,110 @@ +import { defineCommand, getFineTuneParams, type FlagsDef } from "bailian-cli-core"; + +const OPD_PARAMS_FLAGS = { + baseModel: { + type: "string", + valueHint: "", + description: { + "en-US": "Student base model to query OPD parameters for (e.g. qwen3.5-9b)", + "zh-CN": "要查询 OPD 参数的学生基座模型(例如 qwen3.5-9b)", + }, + required: true, + }, + paramType: { + type: "string", + valueHint: "", + description: { + "en-US": + "Parameter group: hyper (training) | resource (GPUs / teacher). Omit to return all groups.", + "zh-CN": "参数类别:hyper(训练)| resource(GPU / 教师资源)。不传返回全部分类。", + }, + choices: ["hyper", "resource"] as const, + }, + mtuSpecCode: { + type: "string", + valueHint: "", + description: { + "en-US": "MTU spec code for resource-group queries (e.g. MTU4)", + "zh-CN": "查询资源类参数时的 MTU 规格编码(例如 MTU4)", + }, + }, + workspaceId: { + type: "string", + valueHint: "", + description: { + "en-US": + "Workspace ID sent as X-DashScope-WorkSpace; omit when your API key is already workspace-bound.", + "zh-CN": "以 X-DashScope-WorkSpace 头发送的业务空间 ID;API Key 已绑定空间时可省略。", + }, + }, +} satisfies FlagsDef; + +export default defineCommand({ + defaultOutput: "json", + description: { + "en-US": "Query OPD (pg_opd) training / resource parameter configuration for a student model", + "zh-CN": "查询学生模型的 OPD(pg_opd)训练 / 资源参数配置", + }, + auth: "apiKey", + usageArgs: + "--base-model [--param-type ] [--mtu-spec-code ] [--workspace-id ]", + flags: OPD_PARAMS_FLAGS, + exampleArgs: [ + "--base-model qwen3.5-9b", + "--base-model qwen3.5-9b --param-type hyper", + "--base-model qwen3.5-9b --param-type resource --mtu-spec-code MTU4", + "--base-model qwen3.5-9b --dry-run", + ], + notes: [ + { + "en-US": + "Queries GET /api/v1/fine-tunes/fine-tunes-params with training_type=pg_opd. Entries keep server field names verbatim (recommend_value, defaultValue, data_range, ...).", + "zh-CN": + "以 training_type=pg_opd 调用 GET /api/v1/fine-tunes/fine-tunes-params。每条参数原样保留服务端字段名(recommend_value、defaultValue、data_range 等)。", + }, + { + "en-US": + "recommend_value is NOT the selected teacher's effective default: external teachers (e.g. Flash/Max) carry their own default resources resolved server-side at submit time. Use this output for ranges/enums, not as a recipe to fill into requests.", + "zh-CN": + "recommend_value 不是所选教师的有效默认值:外接教师(如 Flash/Max)有各自的默认资源,由服务端在提交时解析。本输出用于查看范围/枚举,不要当作配方填入请求。", + }, + { + "en-US": + "Compatible-teacher discovery is not exposed by the parameter API yet; teacher/student compatibility is validated server-side when submitting via finetune opd run.", + "zh-CN": + "参数接口尚未提供兼容教师发现;教师/学生兼容性在通过 finetune opd run 提交时由服务端校验。", + }, + ], + async run(ctx) { + const { settings, flags } = ctx; + const workspaceId = flags.workspaceId ?? settings.workspaceId; + + if (settings.dryRun) { + const preview = { + action: "finetune.opd.params", + base_model: flags.baseModel, + training_type: "pg_opd", + ...(flags.paramType ? { param_type: flags.paramType } : {}), + ...(flags.mtuSpecCode ? { mtu_spec_code: flags.mtuSpecCode } : {}), + ...(workspaceId ? { workspace_id: workspaceId } : {}), + }; + ctx.output.result( + preview, + settings.output === "text" ? { text: JSON.stringify(preview, null, 2) } : undefined, + ); + return; + } + + const response = await getFineTuneParams(ctx.client, { + inputModel: flags.baseModel, + trainingType: "pg_opd", + paramType: flags.paramType || undefined, + mtuSpecCode: flags.mtuSpecCode || undefined, + workspaceId, + }); + ctx.output.result( + response, + settings.output === "text" ? { text: JSON.stringify(response, null, 2) } : undefined, + ); + }, +}); diff --git a/packages/commands/src/commands/finetune/opd-run.ts b/packages/commands/src/commands/finetune/opd-run.ts new file mode 100644 index 00000000..1b073b47 --- /dev/null +++ b/packages/commands/src/commands/finetune/opd-run.ts @@ -0,0 +1,575 @@ +import { readFileSync } from "node:fs"; +import { + BailianError, + ExitCode, + createFineTune, + defineCommand, + getFineTuneParams, + getProfile, + parseAssignment, + parseTypedValue, + validateFineTuneHyperParameterOverrides, + type CreateFineTuneRequest, + type FineTuneDatasetDescriptor, + type FineTuneHyperParameters, + type FineTuneParamHyperParam, + type FineTuneResourceConfig, + type FlagsDef, +} from "bailian-cli-core"; +import { analyzeDatasetTokens, uploadResolvedLocal } from "./dataset-input.ts"; +import { formatHyperParameterIssue } from "./create.ts"; +import { computeOpdBatchFit, opdMiniBatchLimit } from "./opd-batch-fit.ts"; +import { + isPublishedOpdPair, + OPD_MODEL_MATRIX_DOC, + OPD_RECOMMENDED_MTU_CAPACITY, +} from "./opd-model-matrix.ts"; +import { emitRlDryRun, emitRlResult, followRlJob } from "./rl-shared.ts"; + +const OPD_RUN_FLAGS = { + baseModel: { + type: "string", + valueHint: "", + description: { + "en-US": "Student base model ID (e.g. qwen3.5-9b)", + "zh-CN": "学生基座模型 ID(例如 qwen3.5-9b)", + }, + required: true, + }, + teacherModel: { + type: "string", + valueHint: "", + description: { + "en-US": "Platform-registered teacher model ID (required; no arbitrary URLs or keys)", + "zh-CN": "平台登记的教师模型 ID(必填;不接受任意 URL 或密钥)", + }, + required: true, + }, + datasets: { + type: "string", + valueHint: "", + description: { + "en-US": + "Comma-separated dataset file IDs or local .jsonl paths. Local paths are validated and uploaded first.", + "zh-CN": "数据集文件 ID 或本地 .jsonl 路径,以逗号分隔。本地路径会先校验并上传。", + }, + required: true, + }, + validations: { + type: "string", + valueHint: "", + description: { + "en-US": + "Comma-separated validation file IDs or local paths (auto-uploaded like --datasets).", + "zh-CN": "验证集文件 ID 或本地路径,以逗号分隔(与 --datasets 一样自动上传)。", + }, + }, + jobName: { + type: "string", + valueHint: "", + description: { + "en-US": "Training job display name (job_name)", + "zh-CN": "训练任务显示名称(job_name)", + }, + }, + hyperParametersFile: { + type: "string", + valueHint: "", + description: { + "en-US": + "JSON file of training + resource hyper-parameters (keys map 1:1 to hyper_parameters). --hp overrides it.", + "zh-CN": "训练与资源超参 JSON 文件(键与 hyper_parameters 一一对应)。--hp 优先级更高。", + }, + }, + resourceConfigFile: { + type: "string", + valueHint: "", + description: { + "en-US": + "JSON file of resource_config (charge_type / mtu_spec_code / mtu_capacity). Resource flags override it.", + "zh-CN": + "resource_config JSON 文件(charge_type / mtu_spec_code / mtu_capacity)。资源 flag 优先级更高。", + }, + }, + hp: { + type: "array", + valueHint: "", + description: { + "en-US": "Hyper-parameter override (repeatable, parsed by type); beats the JSON file", + "zh-CN": "超参数覆盖(可重复,按类型解析);优先于 JSON 文件", + }, + }, + chargeType: { + type: "string", + valueHint: "", + description: { + "en-US": "resource_config.charge_type; pg_opd only supports mtu_postpaid (default)", + "zh-CN": "resource_config.charge_type;pg_opd 仅支持 mtu_postpaid(默认值)", + }, + }, + mtuSpec: { + type: "string", + valueHint: "", + description: { + "en-US": + "resource_config.mtu_spec_code (e.g. MTU4); required, via this flag or the resource file", + "zh-CN": "resource_config.mtu_spec_code(例如 MTU4);必填,本 flag 或资源文件提供均可", + }, + }, + mtuCount: { + type: "number", + valueHint: "", + description: { + "en-US": + "resource_config.mtu_capacity (student GPUs + teacher GPUs); required, via this flag or the resource file", + "zh-CN": + "resource_config.mtu_capacity(学生 GPU 数 + 教师 GPU 数);必填,本 flag 或资源文件提供均可", + }, + }, + workspaceId: { + type: "string", + valueHint: "", + description: { + "en-US": + "Workspace for upload, parameter query, creation and reads (X-DashScope-WorkSpace). Omit when the API key is workspace-bound.", + "zh-CN": + "上传、参数查询、创建与读取使用的业务空间(X-DashScope-WorkSpace)。API Key 已绑定空间时可省略。", + }, + }, + watch: { + type: "switch", + description: { + "en-US": "Wait for the job to reach a terminal state", + "zh-CN": "提交后等待任务进入终态", + }, + }, + waitTimeout: { + type: "number", + valueHint: "", + description: { + "en-US": + "Maximum seconds to poll with --watch (default: no limit; does not cancel the cloud job)", + "zh-CN": "--watch 的最长轮询秒数(默认无限制;超时不取消云端任务)", + }, + }, +} satisfies FlagsDef; + +/** Read a JSON object file with errno-specific I/O hints and a shape check. */ +function readOpdJsonObject(filePath: string, flagName: string): Record { + let text: string; + try { + text = readFileSync(filePath, "utf8"); + } catch (error) { + const errno = (error as NodeJS.ErrnoException).code; + const hint = + errno === "ENOENT" + ? `File not found: ${filePath}` + : errno === "EACCES" || errno === "EPERM" + ? `Permission denied reading file: ${filePath}` + : errno === "EISDIR" + ? `Path is a directory: ${filePath}` + : `Cannot read file: ${filePath} (${errno ?? String(error)})`; + throw new BailianError(`Cannot read ${flagName} file: ${filePath}`, ExitCode.GENERAL, hint); + } + let parsed: unknown; + try { + parsed = JSON.parse(text); + } catch { + throw new BailianError(`${flagName} file is not valid JSON: ${filePath}`, ExitCode.USAGE); + } + if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) { + throw new BailianError( + `${flagName} file must contain a JSON object: ${filePath}`, + ExitCode.USAGE, + ); + } + return parsed as Record; +} + +function toDatasetDescriptors( + fileIds: string[], + type: FineTuneDatasetDescriptor["type"], +): FineTuneDatasetDescriptor[] { + return fileIds.map((fileId) => ({ type, data_source_type: "file_id", file_id: fileId })); +} + +export default defineCommand({ + defaultOutput: "json", + description: { + "en-US": "Submit a pure Model OPD distillation job (pg_opd) via the fine-tunes OpenAPI", + "zh-CN": "通过 fine-tunes OpenAPI 提交纯 Model OPD 蒸馏任务(pg_opd)", + }, + auth: "apiKey", + risk: { + level: "high", + reason: "billing", + message: { + "en-US": "This creates a billed OPD training job that consumes compute resources.", + "zh-CN": "该操作会创建计费的 OPD 训练任务,消耗算力资源。", + }, + }, + usageArgs: "--base-model --teacher-model --datasets [flags]", + flags: OPD_RUN_FLAGS, + exampleArgs: [ + "--base-model qwen3.5-9b --teacher-model qwen3.8-flash --datasets file-xxx --validations file-yyy --hyper-parameters-file ./hp.json --resource-config-file ./resource.json --dry-run", + "--base-model qwen3.5-9b --teacher-model qwen3.5-397b-a17b --datasets ./train.jsonl --hp n_epochs=1 --hp batch_size=64 --charge-type mtu_postpaid --mtu-spec MTU4 --mtu-count 24 --watch", + "--base-model qwen3.5-9b --teacher-model qwen3.8-flash --datasets file-xxx --workspace-id ws-xxx", + ], + notes: [ + { + "en-US": + "Forces training_type=pg_opd. Pure Model OPD needs no rollout / reward functions and creates no function-compute resources.", + "zh-CN": + "强制 training_type=pg_opd。纯 Model OPD 无需 rollout / reward 函数,不创建函数计算资源。", + }, + { + "en-US": + "Submits directly from the host via the fine-tunes OpenAPI (no sandbox runtime). Query commands: finetune opd get/watch/logs/cancel/delete; list/checkpoints/export/metrics use the shared finetune commands.", + "zh-CN": + "在宿主直接经 fine-tunes OpenAPI 提交(无需沙箱运行时)。查询命令:finetune opd get/watch/logs/cancel/delete;list/checkpoints/export/metrics 使用通用 finetune 命令。", + }, + { + "en-US": + "Hyper-parameters are sent exactly as provided (JSON file, then --hp overrides). Omitted fields are resolved by the server and the selected teacher's defaults — the CLI never fills parameter-API recommend_value, which is not the teacher's effective default.", + "zh-CN": + "超参按提供值原样发送(JSON 文件,--hp 覆盖)。未指定字段由服务端与所选教师默认值补齐——CLI 不填充参数接口的 recommend_value,它不是教师的有效默认值。", + }, + { + "en-US": + "The teacher must be a platform-registered model ID compatible with the student; compatibility and resource capacity are validated server-side and errors are surfaced as-is.", + "zh-CN": "教师须为与学生兼容的平台登记模型 ID;兼容性与资源容量由服务端校验,错误原样透传。", + }, + { + "en-US": `mtu_capacity must equal student GPUs + teacher GPUs. The published docs recommend MTU4 x ${OPD_RECOMMENDED_MTU_CAPACITY} for the default layout; custom layouts must be computed yourself (the server checks capacity after job creation). Supported pairs and sizing: ${OPD_MODEL_MATRIX_DOC}.`, + "zh-CN": `mtu_capacity 必须等于学生 GPU 数 + 教师 GPU 数。官方文档对默认布局推荐 MTU4 x ${OPD_RECOMMENDED_MTU_CAPACITY};自定义布局需自行核算(服务端容量检查在任务创建后执行)。支持组合与规格见 ${OPD_MODEL_MATRIX_DOC}。`, + }, + { + "en-US": + "batch_size is the samples-per-step: floor(training samples × n_epochs / batch_size) must be ≥ 1, otherwise the job fails at execution time after billing starts (lr_decay_steps > 0). With local datasets the CLI rejects zero-step configurations before upload; ppo_mini_batch_size must not exceed batch_size × n_rollouts.", + "zh-CN": + "batch_size 即每步样本数:floor(训练样本数 × n_epochs / batch_size) 必须 ≥ 1,否则任务在计费开始后的执行期失败(lr_decay_steps > 0 断言)。本地数据集时 CLI 在上传前拒绝 0 步配置;ppo_mini_batch_size 不得超过 batch_size × n_rollouts。", + }, + { + "en-US": "Timing out with --watch stops waiting only; it does not cancel the cloud job.", + "zh-CN": "--watch 超时仅停止等待,不会取消云端任务。", + }, + ], + async run(ctx) { + const { settings, flags } = ctx; + const model = flags.baseModel; + const workspaceId = flags.workspaceId ?? settings.workspaceId; + + // Explicit inputs only: file values first, CLI overrides on top. Omitted + // hyper keys stay omitted for server/teacher resolution; charge_type is the + // one fixed constraint (pg_opd is MTU-only) and defaults to mtu_postpaid. + const hyperParameters: FineTuneHyperParameters = flags.hyperParametersFile + ? (readOpdJsonObject( + flags.hyperParametersFile, + "--hyper-parameters-file", + ) as FineTuneHyperParameters) + : {}; + for (const entry of flags.hp ?? []) { + const { key, value } = parseAssignment(entry, "--hp", "--hp "); + hyperParameters[key] = parseTypedValue(value); + } + // Learning rate travels as a string to avoid JSON-number precision loss. + if (typeof hyperParameters.learning_rate === "number") { + hyperParameters.learning_rate = String(hyperParameters.learning_rate); + } + + const resourceConfig: FineTuneResourceConfig = flags.resourceConfigFile + ? (readOpdJsonObject( + flags.resourceConfigFile, + "--resource-config-file", + ) as FineTuneResourceConfig) + : {}; + if (flags.chargeType !== undefined) resourceConfig.charge_type = flags.chargeType; + if (flags.mtuSpec !== undefined) resourceConfig.mtu_spec_code = flags.mtuSpec; + if (flags.mtuCount !== undefined) resourceConfig.mtu_capacity = flags.mtuCount; + if (resourceConfig.charge_type === undefined) { + resourceConfig.charge_type = "mtu_postpaid"; + } else if (resourceConfig.charge_type !== "mtu_postpaid") { + throw new BailianError( + ctx.localize({ + "en-US": `pg_opd only supports charge_type "mtu_postpaid" (got "${resourceConfig.charge_type}").`, + "zh-CN": `pg_opd 仅支持 charge_type 为 "mtu_postpaid"(当前为 "${resourceConfig.charge_type}")。`, + }), + ExitCode.USAGE, + ); + } + // Without the MTU fields the server persists the job, returns 500, and the + // job fails at execution time — reject locally before upload/creation. + const missingResourceFields: string[] = []; + if (!resourceConfig.mtu_spec_code) missingResourceFields.push("mtu_spec_code (--mtu-spec)"); + if (typeof resourceConfig.mtu_capacity !== "number") { + missingResourceFields.push("mtu_capacity (--mtu-count)"); + } + if (missingResourceFields.length > 0) { + throw new BailianError( + ctx.localize({ + "en-US": `pg_opd requires resource_config.${missingResourceFields.join(" and resource_config.")}; provide them via --resource-config-file or the resource flags.`, + "zh-CN": `pg_opd 要求 resource_config.${missingResourceFields.join(" 和 resource_config.")};请通过 --resource-config-file 或资源 flag 提供。`, + }), + ExitCode.USAGE, + ); + } + + // Local pre-flight. The only hard check is the teacher-Worker template + // constraint (TP must equal GPUs per node); everything else warns, because + // the published matrix/capacity are point-in-time doc snapshots and the + // server config may move ahead of them. + const teacherTp = Number(hyperParameters.opd_teacher_infer_tp); + const teacherGpusPerNode = Number(hyperParameters.opd_teacher_n_gpus_per_node); + if ( + hyperParameters.opd_teacher_infer_tp !== undefined && + hyperParameters.opd_teacher_n_gpus_per_node !== undefined && + Number.isFinite(teacherTp) && + Number.isFinite(teacherGpusPerNode) && + teacherTp !== teacherGpusPerNode + ) { + throw new BailianError( + ctx.localize({ + "en-US": `opd_teacher_infer_tp (${teacherTp}) must equal opd_teacher_n_gpus_per_node (${teacherGpusPerNode}); the teacher Worker template rejects mismatches.`, + "zh-CN": `opd_teacher_infer_tp(${teacherTp})必须等于 opd_teacher_n_gpus_per_node(${teacherGpusPerNode});教师 Worker 模板会拒绝不匹配的配置。`, + }), + ExitCode.USAGE, + ); + } + if (!isPublishedOpdPair(model, flags.teacherModel)) { + ctx.output.warning({ + code: "OPD_PAIR_NOT_PUBLISHED", + message: { + "en-US": `Student/teacher pair "${model}" <- "${flags.teacherModel}" is not in the published OPD support list (invite-only, region-specific); the server may reject it. See ${OPD_MODEL_MATRIX_DOC}.`, + "zh-CN": `学生/教师组合"${model}" <- "${flags.teacherModel}"不在官方公布的 OPD 支持列表中(邀测、分地域),服务端可能拒绝。见 ${OPD_MODEL_MATRIX_DOC}。`, + }, + }); + } + const studentLayoutKeys = [ + "nnodes_training", + "nnodes_rollout", + "n_gpus_training", + "n_gpus_rollout", + ] as const; + if (studentLayoutKeys.some((key) => hyperParameters[key] === undefined)) { + ctx.output.warning({ + code: "OPD_DEFAULT_LAYOUT_CAPACITY", + message: { + "en-US": `Student GPU layout is not fully specified; the server applies its default layout. The published recommendation is MTU4 x ${OPD_RECOMMENDED_MTU_CAPACITY}, and you set mtu_capacity=${resourceConfig.mtu_capacity}. Verify the capacity covers student + teacher GPUs (the capacity check currently runs after job creation).`, + "zh-CN": `学生 GPU 布局未完全指定,服务端将按默认布局分配。官方推荐容量为 MTU4 x ${OPD_RECOMMENDED_MTU_CAPACITY},当前 mtu_capacity=${resourceConfig.mtu_capacity}。请确认容量覆盖学生 + 教师 GPU(容量检查目前在任务创建后才执行)。`, + }, + }); + } + const teacherMaxModelLen = Number(hyperParameters.opd_teacher_max_model_len); + if ( + hyperParameters.opd_teacher_max_model_len !== undefined && + Number.isFinite(teacherMaxModelLen) + ) { + const overLengthKeys = (["max_length", "max_prompt_length"] as const).filter((key) => { + const value = Number(hyperParameters[key]); + return ( + hyperParameters[key] !== undefined && Number.isFinite(value) && value > teacherMaxModelLen + ); + }); + if (overLengthKeys.length > 0) { + ctx.output.warning({ + code: "OPD_LENGTH_EXCEEDS_TEACHER", + message: { + "en-US": `${overLengthKeys.join(" / ")} exceeds the explicit opd_teacher_max_model_len (${teacherMaxModelLen}); training may fail at execution time. When teacher fields are omitted the server fills teacher defaults — keep student lengths compatible with the selected teacher.`, + "zh-CN": `${overLengthKeys.join(" / ")} 超过显式指定的 opd_teacher_max_model_len(${teacherMaxModelLen}),训练可能在执行期失败。教师字段省略时由服务端补教师默认值——请保持学生长度与所选教师兼容。`, + }, + }); + } + } + + const miniBatch = opdMiniBatchLimit(hyperParameters); + if (miniBatch && miniBatch.miniBatchSize > miniBatch.limit) { + throw new BailianError( + ctx.localize({ + "en-US": `ppo_mini_batch_size (${miniBatch.miniBatchSize}) must not exceed batch_size × n_rollouts (${miniBatch.limit}); the published OPD parameter relationship rejects larger mini-batches.`, + "zh-CN": `ppo_mini_batch_size(${miniBatch.miniBatchSize})不得超过 batch_size × n_rollouts(${miniBatch.limit});官方 OPD 参数关系约束更大的 mini-batch 无效。`, + }), + ExitCode.USAGE, + ); + } + + const profile = getProfile("pg-opd"); + const training = await analyzeDatasetTokens( + ctx, + flags.datasets, + "datasets", + profile, + "text", + model, + ); + const validation = flags.validations + ? await analyzeDatasetTokens(ctx, flags.validations, "validations", profile, "text", model) + : undefined; + + // Batch-fit pre-flight. batch_size is the published "samples per step"; + // floor(samples × n_epochs / batch_size) = 0 trips the DLC assertion + // lr_decay_steps > 0 after the job is created and billed. The raw local + // count upper-bounds the post-preprocessing count, so a local shortfall is + // a sound hard reject; a surplus is not a guarantee (preprocessing filters). + const batchFit = computeOpdBatchFit(hyperParameters, training.recordCount); + if ( + batchFit.requiredSamples !== undefined && + training.recordCount === undefined && + (!settings.dryRun || training.localPaths.length === 0) + ) { + ctx.output.warning({ + code: "OPD_BATCH_FIT_UNKNOWN", + message: { + "en-US": `Dataset sample count is unknown (file-id datasets). With batch_size=${batchFit.batchSize} and n_epochs=${batchFit.nEpochs}, training needs at least ${batchFit.requiredSamples} effective samples for one step; fewer fails at execution time after billing starts.`, + "zh-CN": `数据集样本数未知(file-id 数据集)。batch_size=${batchFit.batchSize}、n_epochs=${batchFit.nEpochs} 时,训练至少需要 ${batchFit.requiredSamples} 条有效样本才能走出 1 步;不足会在计费开始后的执行期失败。`, + }, + }); + } + if (!settings.dryRun && batchFit.steps !== undefined) { + const totalSteps = batchFit.steps; + if (totalSteps === 0) { + throw new BailianError( + ctx.localize({ + "en-US": `Training dataset has ${batchFit.recordCount} sample(s); with n_epochs=${batchFit.nEpochs} and batch_size=${batchFit.batchSize} (samples per step) the job would run 0 training steps and fail at execution time (lr_decay_steps > 0).`, + "zh-CN": `训练集共 ${batchFit.recordCount} 条样本;n_epochs=${batchFit.nEpochs}、batch_size=${batchFit.batchSize}(每步样本数)时总训练步数为 0,任务会在执行期失败(lr_decay_steps > 0 断言)。`, + }), + ExitCode.USAGE, + ctx.localize({ + "en-US": `Provide at least ${batchFit.requiredSamples} samples (preprocessing may filter some, so leave headroom), or lower batch_size / raise n_epochs. Nothing was uploaded or created.`, + "zh-CN": `请至少提供 ${batchFit.requiredSamples} 条样本(预处理可能过滤部分样本,建议留余量),或调小 batch_size / 调大 n_epochs。未上传、未创建任何资源。`, + }), + ); + } + const warmupSteps = Number(hyperParameters.lr_warmup_steps); + if ( + hyperParameters.lr_warmup_steps !== undefined && + Number.isFinite(warmupSteps) && + warmupSteps >= 0 && + warmupSteps > totalSteps + ) { + ctx.output.warning({ + code: "OPD_WARMUP_EXCEEDS_STEPS", + message: { + "en-US": `lr_warmup_steps (${warmupSteps}) exceeds the estimated total training steps (${totalSteps}); the docs recommend 0 for small-data smoke runs so warmup does not outrun the schedule.`, + "zh-CN": `lr_warmup_steps(${warmupSteps})超过估算总训练步数(${totalSteps});官方文档建议小数据冒烟设 0,避免预热步数超过总步数。`, + }, + }); + } + const intervalKeys = (["eval_steps", "save_steps"] as const).filter((key) => { + if (key === "save_steps" && hyperParameters.save_strategy === "epoch") return false; + const value = Number(hyperParameters[key]); + return hyperParameters[key] !== undefined && Number.isFinite(value) && value > totalSteps; + }); + if (intervalKeys.length > 0) { + ctx.output.warning({ + code: "OPD_INTERVAL_EXCEEDS_STEPS", + message: { + "en-US": `${intervalKeys.join(" / ")} exceeds the estimated total training steps (${totalSteps}); evaluation / checkpoint saving would never trigger. The docs suggest eval_steps ≈ total steps / 10~20 and save_steps ≈ eval_steps × 2~3.`, + "zh-CN": `${intervalKeys.join(" / ")} 超过估算总训练步数(${totalSteps}),评估 / 保存 checkpoint 一次都不会触发。官方建议 eval_steps ≈ 总步数 / 10~20、save_steps ≈ eval_steps × 2~3。`, + }, + }); + } + } + + const buildBody = (): CreateFineTuneRequest => { + const body: CreateFineTuneRequest = { + model, + training_type: "pg_opd", + teacher_model: flags.teacherModel, + training_datasets: toDatasetDescriptors(training.fileIds, "training"), + }; + if (validation && validation.fileIds.length > 0) { + body.validation_datasets = toDatasetDescriptors(validation.fileIds, "validation"); + } + if (Object.keys(hyperParameters).length > 0) body.hyper_parameters = hyperParameters; + body.resource_config = resourceConfig; + if (flags.jobName !== undefined) body.job_name = flags.jobName; + return body; + }; + + if (settings.dryRun) { + const pending = [ + ...training.localPaths.map((path) => ({ field: "datasets", path })), + ...(validation?.localPaths ?? []).map((path) => ({ field: "validations", path })), + ]; + emitRlDryRun(ctx, "finetune.opd.run", { + body: buildBody(), + ...(pending.length > 0 ? { pending_uploads: pending } : {}), + watch: flags.watch === true, + wait_timeout: flags.waitTimeout, + ...(workspaceId ? { workspace_id: workspaceId } : {}), + }); + return; + } + + // Authoritative parameter schema (hyper + resource groups). Explicit + // overrides must satisfy it; empty ranges/enums are skipped by the + // validator, which matters for students whose schema omits ranges. + const [hyperResponse, resourceResponse] = await Promise.all([ + getFineTuneParams(ctx.client, { + inputModel: model, + trainingType: "pg_opd", + paramType: "hyper", + workspaceId, + }), + getFineTuneParams(ctx.client, { + inputModel: model, + trainingType: "pg_opd", + paramType: "resource", + mtuSpecCode: + typeof resourceConfig.mtu_spec_code === "string" + ? resourceConfig.mtu_spec_code + : undefined, + workspaceId, + }), + ]); + const schema: FineTuneParamHyperParam[] = [ + ...(hyperResponse.output?.hyper_params ?? []), + ...(resourceResponse.output?.hyper_params ?? []), + ]; + if (schema.length === 0) { + throw new BailianError( + ctx.localize({ + "en-US": `No authoritative training parameter schema was returned for model "${model}" and training type "pg_opd".`, + "zh-CN": `模型“${model}”和训练类型“pg_opd”未返回权威训练参数配置。`, + }), + ExitCode.GENERAL, + ctx.localize({ + "en-US": "The dataset was not uploaded and the training job was not submitted.", + "zh-CN": "数据集未上传,训练任务未提交。", + }), + ); + } + const issues = validateFineTuneHyperParameterOverrides(schema, hyperParameters).filter( + // save_strategy is accepted by the server's hyper-parameter checker even + // when the parameter API does not list it; do not reject it locally. + (issue) => !(issue.parameter === "save_strategy" && issue.code === "unsupported"), + ); + if (issues.length > 0) { + throw new BailianError( + ctx.localize({ + "en-US": "One or more training hyper-parameter overrides are invalid.", + "zh-CN": "一个或多个训练超参数覆盖值无效。", + }), + ExitCode.USAGE, + issues.map((issue) => formatHyperParameterIssue(ctx, issue)).join("\n"), + ); + } + + await uploadResolvedLocal(ctx, training, "fine-tune", "datasets", workspaceId); + if (validation) { + await uploadResolvedLocal(ctx, validation, "fine-tune", "validations", workspaceId); + } + + const response = await createFineTune(ctx.client, buildBody(), undefined, workspaceId); + emitRlResult(ctx, response); + + if (flags.watch !== true) return; + const jobId = (response.output ?? response.data)?.job_id; + if (!jobId) return; + await followRlJob(ctx, jobId, { + pollTimeoutSec: flags.waitTimeout, + jobLabel: "OPD job", + workspaceId, + }); + }, +}); diff --git a/packages/commands/src/commands/finetune/opd-watch.ts b/packages/commands/src/commands/finetune/opd-watch.ts new file mode 100644 index 00000000..4d81f4fe --- /dev/null +++ b/packages/commands/src/commands/finetune/opd-watch.ts @@ -0,0 +1,3 @@ +import { defineJobWatchCommand } from "./rl-job-commands.ts"; + +export default defineJobWatchCommand("opd"); diff --git a/packages/commands/src/commands/finetune/rl-authorize.ts b/packages/commands/src/commands/finetune/rl-authorize.ts new file mode 100644 index 00000000..55dcbb9b --- /dev/null +++ b/packages/commands/src/commands/finetune/rl-authorize.ts @@ -0,0 +1,62 @@ +import { type FlagsDef } from "bailian-cli-core"; +import { RL_TRAINING_DOC } from "bailian-cli-runtime"; +import { defineConsoleReadCommand } from "../shared/console-read.ts"; +import { runRlAuthorize } from "./rl-shared.ts"; + +const AUTHORIZE_FLAGS = { + authorize: { + type: "switch", + description: { + "en-US": + "Permit enabling RL once the service roles are manually authorized (read-only probe without it)", + "zh-CN": "允许在角色已手动授权后开通 RL(不传则仅只读检查)", + }, + }, +} satisfies FlagsDef; + +export default defineConsoleReadCommand({ + defaultOutput: "json", + description: { + "en-US": + "Check and authorize reinforcement-learning access (whitelist, service roles, enablement)", + "zh-CN": "检查并授权强化学习访问能力(准入白名单、服务角色、业务开通)", + }, + auth: "console", + risk: { + level: "high", + reason: "destructive", + message: { + "en-US": + "With --authorize this enables the RL training mode for your account. The CLI never creates service-linked roles.", + "zh-CN": "传入 --authorize 时会为账号开通 RL 训练模式。CLI 不会创建服务关联角色。", + }, + }, + usageArgs: "[--authorize]", + flags: AUTHORIZE_FLAGS, + exampleArgs: ["", "--authorize --yes", "--dry-run"], + notes: [ + { + "en-US": `Service-linked roles must be authorized manually first (${RL_TRAINING_DOC}); missing roles report REQUIRES_USER_ACTION and block enablement.`, + "zh-CN": `服务关联角色须先手动授权(${RL_TRAINING_DOC});角色缺失时报告 REQUIRES_USER_ACTION 并阻止开通。`, + }, + { + "en-US": + "Without --authorize this is a read-only probe. Each capability reports READY / MISSING / UNKNOWN / REQUIRES_USER_ACTION / FAILED; a failed query is UNKNOWN, never assumed enabled.", + "zh-CN": + "不传 --authorize 时仅只读检查。每项能力返回 READY / MISSING / UNKNOWN / REQUIRES_USER_ACTION / FAILED;查询失败记为 UNKNOWN,绝不臆断为已开通。", + }, + { + "en-US": + "Only RL is enabled; OPD is never auto-enabled. In CI pass --authorize --yes to permit changes; --yes alone does not expand permissions.", + "zh-CN": + "只开通 RL,不会自动开通 OPD。CI 中须显式 --authorize --yes 才允许变更;单独 --yes 不扩大权限。", + }, + ], + async run(ctx) { + await runRlAuthorize(ctx, { + target: "rl", + action: "finetune.rl.authorize", + authorize: ctx.flags.authorize === true, + }); + }, +}); diff --git a/packages/commands/src/commands/finetune/rl-cancel.ts b/packages/commands/src/commands/finetune/rl-cancel.ts new file mode 100644 index 00000000..2473d827 --- /dev/null +++ b/packages/commands/src/commands/finetune/rl-cancel.ts @@ -0,0 +1,3 @@ +import { defineJobCancelCommand } from "./rl-job-commands.ts"; + +export default defineJobCancelCommand("rl"); diff --git a/packages/commands/src/commands/finetune/rl-delete.ts b/packages/commands/src/commands/finetune/rl-delete.ts new file mode 100644 index 00000000..f1e1426b --- /dev/null +++ b/packages/commands/src/commands/finetune/rl-delete.ts @@ -0,0 +1,3 @@ +import { defineJobDeleteCommand } from "./rl-job-commands.ts"; + +export default defineJobDeleteCommand("rl"); diff --git a/packages/commands/src/commands/finetune/rl-get.ts b/packages/commands/src/commands/finetune/rl-get.ts new file mode 100644 index 00000000..c0693b5d --- /dev/null +++ b/packages/commands/src/commands/finetune/rl-get.ts @@ -0,0 +1,3 @@ +import { defineJobGetCommand } from "./rl-job-commands.ts"; + +export default defineJobGetCommand("rl"); diff --git a/packages/commands/src/commands/finetune/rl-job-commands.ts b/packages/commands/src/commands/finetune/rl-job-commands.ts new file mode 100644 index 00000000..0adce6f4 --- /dev/null +++ b/packages/commands/src/commands/finetune/rl-job-commands.ts @@ -0,0 +1,453 @@ +import { + cancelFineTune, + defineCommand, + deleteFineTune, + getFineTune, + getFineTuneLogs, + type FlagDef, + type FlagsDef, +} from "bailian-cli-core"; + +import { + RL_TIMEOUT_MS, + RL_WATCH_DEFAULT_INTERVAL_SEC, + RL_WATCH_MIN_INTERVAL_SEC, + emitRlDryRun, + emitRlResult, + executeRl, + followRlJob, + probeRlJob, +} from "./rl-shared.ts"; + +/** + * Training domains that share the same fine-tunes job backend. RL and OPD are + * distinct training types with symmetric command surfaces (`finetune rl *` / + * `finetune opd *`). Backends differ: RL job queries run through the sandbox + * SDK (the reviewed dashscope CLI surface), while OPD queries call the + * fine-tunes OpenAPI directly in the host — OPD submission is OpenAPI-only, + * so its whole command group stays sandbox-free. + */ +export type RlJobDomain = "rl" | "opd"; + +const DOMAIN_LABELS: Record = { rl: "RL", opd: "OPD" }; + +/** Placeholder job ID used in help examples (OPD jobs use the ft- prefix). */ +function sampleJobId(domain: RlJobDomain): string { + return domain === "rl" ? "rl-xxx" : "ft-xxx"; +} + +/** OPD commands accept an optional workspace; RL flags stay unchanged. */ +function workspaceFlag() { + return { + type: "string", + valueHint: "", + description: { + "en-US": + "Workspace ID sent as X-DashScope-WorkSpace; omit when your API key is already workspace-bound.", + "zh-CN": "以 X-DashScope-WorkSpace 头发送的业务空间 ID;API Key 已绑定空间时可省略。", + }, + } satisfies FlagDef; +} + +function jobIdFlag(label: string) { + return { + type: "string", + valueHint: "", + description: { + "en-US": `${label} job ID (required)`, + "zh-CN": `${label} 任务 ID(必填)`, + }, + required: true, + } satisfies FlagDef; +} + +function jobIdFlags(domain: RlJobDomain) { + const canonical = { + jobId: jobIdFlag("OPD"), + workspaceId: workspaceFlag(), + } satisfies FlagsDef; + if (domain === "opd") return canonical; + // RL has no workspace flag at runtime; the shared canonical type keeps + // ParsedFlags precise (a union would widen defineCommand's generic). + return { jobId: jobIdFlag("RL") } as typeof canonical; +} + +function pageFlag() { + return { + type: "number", + valueHint: "", + description: { "en-US": "Page number", "zh-CN": "页码" }, + } satisfies FlagDef; +} + +function sizeFlag(description: { "en-US": string; "zh-CN": string }) { + return { type: "number", valueHint: "", description } satisfies FlagDef; +} + +/** Domain-conditional flags widen the parsed type; read extras defensively. */ +function extraString(flags: Record, name: string): string | undefined { + return typeof flags[name] === "string" ? flags[name] : undefined; +} + +function extraNumber(flags: Record, name: string): number | undefined { + return typeof flags[name] === "number" ? flags[name] : undefined; +} + +export function defineJobGetCommand(domain: RlJobDomain) { + const label = DOMAIN_LABELS[domain]; + return defineCommand({ + defaultOutput: "json", + description: { + "en-US": `Get an ${label} job`, + "zh-CN": `查询 ${label} 任务详情`, + }, + auth: "apiKey", + usageArgs: "--job-id ", + flags: jobIdFlags(domain), + exampleArgs: [`--job-id ${sampleJobId(domain)}`], + notes: + domain === "opd" + ? [ + { + "en-US": + "Returns the raw fine-tunes OpenAPI response (teacher_model, training/validation datasets, MTU spec and capacity included). No sandbox runtime needed.", + "zh-CN": + "原样返回 fine-tunes OpenAPI 响应(含 teacher_model、训练/验证数据集、MTU 规格与容量)。无需沙箱运行时。", + }, + ] + : undefined, + async run(ctx) { + const jobId = ctx.flags.jobId; + const workspaceId = extraString(ctx.flags, "workspaceId"); + if (ctx.settings.dryRun) { + emitRlDryRun(ctx, `finetune.${domain}.get`, { + job_id: jobId, + ...(workspaceId ? { workspace_id: workspaceId } : {}), + }); + return; + } + if (domain === "opd") { + emitRlResult(ctx, await getFineTune(ctx.client, jobId, undefined, workspaceId)); + return; + } + emitRlResult( + ctx, + await executeRl(ctx, ["rl", "get", jobId, "--output-format", "json"], { + timeoutMs: RL_TIMEOUT_MS.query, + }), + ); + }, + }); +} + +export function defineJobListCommand() { + const LIST_FLAGS = { + page: pageFlag(), + size: sizeFlag({ "en-US": "Page size", "zh-CN": "每页数量" }), + } satisfies FlagsDef; + + return defineCommand({ + defaultOutput: "json", + description: { "en-US": "List RL jobs", "zh-CN": "列出 RL 任务" }, + auth: "apiKey", + usageArgs: "[--page ] [--size ]", + flags: LIST_FLAGS, + exampleArgs: ["--page 1 --size 20"], + notes: [ + { + "en-US": + "RL and OPD jobs share the same job backend; this lists the same job records as `finetune list` (including OPD jobs).", + "zh-CN": + "RL 与 OPD 任务共用同一任务后端;此处列出的任务记录与 `finetune list` 同源(含 OPD 任务)。", + }, + ], + async run(ctx) { + if (ctx.settings.dryRun) { + emitRlDryRun(ctx, "finetune.rl.list", { + page: ctx.flags.page, + size: ctx.flags.size, + }); + return; + } + const args = ["rl", "list", "--output-format", "json"]; + if (ctx.flags.page !== undefined) args.push("--page", String(ctx.flags.page)); + if (ctx.flags.size !== undefined) args.push("--size", String(ctx.flags.size)); + emitRlResult(ctx, await executeRl(ctx, args, { timeoutMs: RL_TIMEOUT_MS.query })); + }, + }); +} + +export function defineJobWatchCommand(domain: RlJobDomain) { + const label = DOMAIN_LABELS[domain]; + const WATCH_FLAGS = { + ...jobIdFlags(domain), + follow: { + type: "switch", + description: { + "en-US": + "Block and poll until a terminal state. Without it, a single status probe is performed and the command returns immediately.", + "zh-CN": "阻塞并轮询至终态。不使用时仅查询一次状态并立即返回。", + }, + }, + interval: { + type: "number", + valueHint: "", + description: { + "en-US": `Seconds between polls with --follow (default: ${RL_WATCH_DEFAULT_INTERVAL_SEC}, min: ${RL_WATCH_MIN_INTERVAL_SEC}). Ignored without --follow.`, + "zh-CN": `使用 --follow 时的轮询间隔秒数(默认:${RL_WATCH_DEFAULT_INTERVAL_SEC},最小:${RL_WATCH_MIN_INTERVAL_SEC})。未使用 --follow 时忽略。`, + }, + }, + pollTimeout: { + type: "number", + valueHint: "", + description: { + "en-US": + "With --follow, stop polling after this many seconds (default: no limit). Ignored without --follow.", + "zh-CN": "使用 --follow 时,在指定秒数后停止轮询(默认:无限制)。未使用 --follow 时忽略。", + }, + }, + } satisfies FlagsDef; + + return defineCommand({ + defaultOutput: "json", + description: { + "en-US": `Probe an ${label} job's status (default: single non-blocking fetch). Pass --follow to poll until terminal.`, + "zh-CN": `查询 ${label} 任务状态(默认:单次非阻塞获取)。使用 --follow 持续轮询至终态。`, + }, + auth: "apiKey", + usageArgs: "--job-id [--follow] [--interval ] [--poll-timeout ]", + flags: WATCH_FLAGS, + exampleArgs: [ + "--job-id ft-xxx", + "--job-id ft-xxx --output json", + "--job-id ft-xxx --follow", + "--job-id ft-xxx --follow --interval 5", + "--job-id ft-xxx --follow --poll-timeout 3600", + ], + notes: [ + { + "en-US": + "Default (no --follow) is a NON-BLOCKING single status probe: one fetch, then return immediately. The caller owns the polling cadence, so the CLI never holds the terminal.", + "zh-CN": + "默认不使用 --follow,执行非阻塞的单次状态查询:获取一次后立即返回。由调用方控制轮询节奏,CLI 不会持续占用终端。", + }, + { + "en-US": + "A terminal FAILED/CANCELED status raises a normal CLI error (non-zero exit); SUCCEEDED or still-running returns 0. With --follow, exceeding --poll-timeout raises a timeout error but does not cancel the cloud job.", + "zh-CN": + "终态 FAILED/CANCELED 会触发普通 CLI 错误(非零退出码);SUCCEEDED 或仍在运行时返回 0。使用 --follow 时超过 --poll-timeout 会触发超时错误,但不会取消云端任务。", + }, + { + "en-US": `Queries the fine-tunes endpoint directly in the host (no sandbox runtime needed). For per-step training output use \`finetune ${domain} logs\`.`, + "zh-CN": `直接在宿主查询 fine-tunes 端点(无需沙箱运行时)。查看逐步骤训练输出请用 \`finetune ${domain} logs\`。`, + }, + ], + async run(ctx) { + const jobId = ctx.flags.jobId; + const follow = ctx.flags.follow; + const intervalSec = Math.max( + RL_WATCH_MIN_INTERVAL_SEC, + ctx.flags.interval ?? RL_WATCH_DEFAULT_INTERVAL_SEC, + ); + const pollTimeoutSec = ctx.flags.pollTimeout; + const jobLabel = `${label} job`; + const workspaceId = extraString(ctx.flags, "workspaceId"); + + if (ctx.settings.dryRun) { + emitRlDryRun(ctx, `finetune.${domain}.watch`, { + job_id: jobId, + follow: follow === true, + interval: intervalSec, + timeout: pollTimeoutSec, + ...(workspaceId ? { workspace_id: workspaceId } : {}), + }); + return; + } + + if (!follow) { + await probeRlJob(ctx, jobId, jobLabel, workspaceId); + return; + } + await followRlJob(ctx, jobId, { intervalSec, pollTimeoutSec, jobLabel, workspaceId }); + }, + }); +} + +export function defineJobLogsCommand(domain: RlJobDomain) { + const label = DOMAIN_LABELS[domain]; + // OPD reads logs via the fine-tunes OpenAPI (page_no/page_size); RL keeps + // the sandbox SDK's offset/lines surface. + const canonicalLogsFlags = { + ...jobIdFlags("opd"), + page: pageFlag(), + pageSize: sizeFlag({ "en-US": "Lines per page", "zh-CN": "每页行数" }), + } satisfies FlagsDef; + const LOGS_FLAGS: typeof canonicalLogsFlags = + domain === "opd" + ? canonicalLogsFlags + : ({ + ...jobIdFlags(domain), + offset: { + type: "number", + valueHint: "", + description: { "en-US": "Log offset", "zh-CN": "日志偏移量" }, + }, + lines: { + type: "number", + valueHint: "", + description: { "en-US": "Number of log lines", "zh-CN": "日志行数" }, + }, + } satisfies FlagsDef as unknown as typeof canonicalLogsFlags); + + return defineCommand({ + defaultOutput: "json", + description: { + "en-US": `Fetch ${label} job logs`, + "zh-CN": `获取 ${label} 任务日志`, + }, + auth: "apiKey", + usageArgs: + domain === "opd" + ? "--job-id [--page ] [--page-size ]" + : "--job-id [--offset ] [--lines ]", + flags: LOGS_FLAGS, + exampleArgs: + domain === "opd" + ? [ + `--job-id ${sampleJobId(domain)}`, + `--job-id ${sampleJobId(domain)} --page 1 --page-size 100`, + ] + : [ + `--job-id ${sampleJobId(domain)}`, + `--job-id ${sampleJobId(domain)} --offset 0 --lines 100`, + ], + async run(ctx) { + const jobId = ctx.flags.jobId; + const flags = ctx.flags as Record; + const workspaceId = extraString(flags, "workspaceId"); + if (ctx.settings.dryRun) { + emitRlDryRun(ctx, `finetune.${domain}.logs`, { + job_id: jobId, + ...(domain === "opd" + ? { page: extraNumber(flags, "page"), page_size: extraNumber(flags, "pageSize") } + : { offset: extraNumber(flags, "offset"), lines: extraNumber(flags, "lines") }), + ...(workspaceId ? { workspace_id: workspaceId } : {}), + }); + return; + } + if (domain === "opd") { + emitRlResult( + ctx, + await getFineTuneLogs(ctx.client, jobId, { + pageNo: extraNumber(flags, "page"), + pageSize: extraNumber(flags, "pageSize"), + workspaceId, + }), + ); + return; + } + const args = ["rl", "logs", jobId, "--output-format", "json"]; + const offset = extraNumber(flags, "offset"); + const lines = extraNumber(flags, "lines"); + if (offset !== undefined) args.push("--offset", String(offset)); + if (lines !== undefined) args.push("--lines", String(lines)); + emitRlResult(ctx, await executeRl(ctx, args, { timeoutMs: RL_TIMEOUT_MS.query })); + }, + }); +} + +export function defineJobCancelCommand(domain: RlJobDomain) { + const label = DOMAIN_LABELS[domain]; + return defineCommand({ + defaultOutput: "json", + description: { + "en-US": `Cancel a running ${label} job`, + "zh-CN": `取消运行中的 ${label} 任务`, + }, + auth: "apiKey", + risk: { + level: "high", + reason: "destructive", + message: { + "en-US": `This cancels the running ${label} job; progress may be lost.`, + "zh-CN": `该操作会取消运行中的 ${label} 任务,进度可能丢失。`, + }, + }, + usageArgs: "--job-id ", + flags: jobIdFlags(domain), + exampleArgs: [ + `--job-id ${sampleJobId(domain)}`, + `--job-id ${sampleJobId(domain)} --dry-run`, + `--job-id ${sampleJobId(domain)} --yes`, + ], + async run(ctx) { + const jobId = ctx.flags.jobId; + const workspaceId = extraString(ctx.flags, "workspaceId"); + if (ctx.settings.dryRun) { + emitRlDryRun(ctx, `finetune.${domain}.cancel`, { + job_id: jobId, + ...(workspaceId ? { workspace_id: workspaceId } : {}), + }); + return; + } + if (domain === "opd") { + emitRlResult(ctx, await cancelFineTune(ctx.client, jobId, undefined, workspaceId)); + return; + } + // 1.25.23's rl cancel has no --yes/-o: the confirmation gate is handled by the CLI risk mechanism; the success message + // goes to stderr with empty stdout, exit 0 means cancellation succeeded, and the TS side synthesizes a structured result. + // On failure executeRl passes the server error through (non-zero exit). + await executeRl(ctx, ["rl", "cancel", jobId], { timeoutMs: RL_TIMEOUT_MS.query }); + emitRlResult(ctx, { job_id: jobId, canceled: true }); + }, + }); +} + +export function defineJobDeleteCommand(domain: RlJobDomain) { + const label = DOMAIN_LABELS[domain]; + return defineCommand({ + defaultOutput: "json", + description: { + "en-US": `Delete an ${label} job record`, + "zh-CN": `删除 ${label} 任务记录`, + }, + auth: "apiKey", + risk: { + level: "high", + reason: "destructive", + message: { + "en-US": `This permanently deletes the ${label} job record and cannot be undone.`, + "zh-CN": `该操作会永久删除 ${label} 任务记录,且无法撤销。`, + }, + }, + usageArgs: "--job-id ", + flags: jobIdFlags(domain), + exampleArgs: [ + `--job-id ${sampleJobId(domain)}`, + `--job-id ${sampleJobId(domain)} --dry-run`, + `--job-id ${sampleJobId(domain)} --yes`, + ], + notes: [ + { + "en-US": + "Deletes the job record via the fine-tunes endpoint directly in the host (no sandbox runtime needed); RL and OPD jobs share this backend.", + "zh-CN": + "直接在宿主经 fine-tunes 端点删除任务记录(无需沙箱运行时);RL 与 OPD 任务共用该后端。", + }, + ], + async run(ctx) { + const jobId = ctx.flags.jobId; + const workspaceId = extraString(ctx.flags, "workspaceId"); + if (ctx.settings.dryRun) { + emitRlDryRun(ctx, `finetune.${domain}.delete`, { + job_id: jobId, + ...(workspaceId ? { workspace_id: workspaceId } : {}), + }); + return; + } + // RL/OPD jobs share the fine-tunes backend; deletion goes through the host-side deleteFineTune (same path as watch/probe), + // not through the sandbox. + emitRlResult(ctx, await deleteFineTune(ctx.client, jobId, undefined, workspaceId)); + }, + }); +} diff --git a/packages/commands/src/commands/finetune/rl-list.ts b/packages/commands/src/commands/finetune/rl-list.ts new file mode 100644 index 00000000..9fd0ab00 --- /dev/null +++ b/packages/commands/src/commands/finetune/rl-list.ts @@ -0,0 +1,3 @@ +import { defineJobListCommand } from "./rl-job-commands.ts"; + +export default defineJobListCommand(); diff --git a/packages/commands/src/commands/finetune/rl-logs.ts b/packages/commands/src/commands/finetune/rl-logs.ts new file mode 100644 index 00000000..18828ba3 --- /dev/null +++ b/packages/commands/src/commands/finetune/rl-logs.ts @@ -0,0 +1,3 @@ +import { defineJobLogsCommand } from "./rl-job-commands.ts"; + +export default defineJobLogsCommand("rl"); diff --git a/packages/commands/src/commands/finetune/rl-run.ts b/packages/commands/src/commands/finetune/rl-run.ts new file mode 100644 index 00000000..c7cb2241 --- /dev/null +++ b/packages/commands/src/commands/finetune/rl-run.ts @@ -0,0 +1,49 @@ +import { defineCommand } from "bailian-cli-core"; + +import { RL_RUN_FLAGS, buildRlRunParams, readRlConfigFile, runRlJob } from "./rl-shared.ts"; + +export default defineCommand({ + defaultOutput: "json", + description: { + "en-US": "Submit a reinforcement-learning training job", + "zh-CN": "提交强化学习训练任务", + }, + auth: "apiKey", + risk: { + level: "high", + reason: "billing", + message: { + "en-US": "This creates a billed RL training job that consumes compute resources.", + "zh-CN": "该操作会创建计费的 RL 训练任务,消耗算力资源。", + }, + }, + usageArgs: "--model [flags]", + flags: RL_RUN_FLAGS, + exampleArgs: [ + "--model qwen3.5-9b --train-file ./data/train.jsonl --code-dir . --rollout functions.rollout.MyRollout --charge-type mtu_postpaid --mtu-spec MTU4 --mtu-count 24 --watch", + "--config-file job.yaml --watch", + "--model qwen3.5-9b --train-file ./data/train.jsonl --dry-run", + ], + notes: [ + { + "en-US": + "Runs inside an isolated sandbox. Prepare the runtime first with `finetune runtime prepare`, or pass --install-runtime.", + "zh-CN": + "在隔离沙箱内执行。请先用 `finetune runtime prepare` 准备运行时,或传入 --install-runtime。", + }, + { + "en-US": "Timing out with --watch stops waiting only; it does not cancel the cloud job.", + "zh-CN": "--watch 超时仅停止等待,不会取消云端任务。", + }, + ], + async run(ctx) { + const params = buildRlRunParams(ctx.flags); + const yamlText = ctx.flags.configFile ? readRlConfigFile(ctx.flags.configFile) : undefined; + await runRlJob(ctx, params, yamlText, { + action: "finetune.rl.run", + watch: ctx.flags.watch, + waitTimeoutSeconds: ctx.flags.waitTimeout, + allowInstall: ctx.flags.installRuntime, + }); + }, +}); diff --git a/packages/commands/src/commands/finetune/rl-shared.ts b/packages/commands/src/commands/finetune/rl-shared.ts new file mode 100644 index 00000000..a45212d1 --- /dev/null +++ b/packages/commands/src/commands/finetune/rl-shared.ts @@ -0,0 +1,618 @@ +import { readFileSync } from "node:fs"; +import { + BailianError, + ExitCode, + RL_DASHSCOPE_VERSION, + buildTaskYaml, + createSnapshot, + executeInSandbox, + getFineTune, + resolveTrainingSpec, + runRlAuthorization, + stageDataFiles, + type CommandContext, + type FlagsDef, + type ITaskDirLayout, + type ParsedFlags, + type RlAuthTarget, + type RlJobSpec, + type RlRunParams, +} from "bailian-cli-core"; +import { OPD_TRAINING_DOC, RL_TRAINING_DOC } from "bailian-cli-runtime"; +import { consoleReadTargetPreview } from "../shared/console-read.ts"; + +/** Wall-clock budgets per command class (milliseconds). */ +export const RL_TIMEOUT_MS = { + query: 60_000, + run: 1_800_000, +} as const; + +const RL_MAX_OUTPUT_BYTES = 16 * 1024 * 1024; + +export interface IRlExecuteOptions { + timeoutMs?: number; + /** Allow first-time runtime preparation (interactive run only). */ + allowInstall?: boolean; + signal?: AbortSignal; + /** + * Stage task-local inputs before spawning. Return a YAML string to also write + * a task config passed via `--config`. + */ + prepare?: (layout: ITaskDirLayout) => string | void; +} + +/** Emit a normal result, rendering JSON as text when the user asked for text. */ +export function emitRlResult(ctx: CommandContext, data: unknown): void { + ctx.output.result( + data, + ctx.settings.output === "text" ? { text: JSON.stringify(data, null, 2) } : undefined, + ); +} + +/** Emit a dry-run preview (zero network, zero local writes). */ +export function emitRlDryRun( + ctx: CommandContext, + action: string, + preview: unknown, +): void { + emitRlResult(ctx, { action, ...(preview as Record) }); +} + +/** + * Thin periphery: hand the SDK args + credential to the sandbox black box, which + * internally resolves the runtime (manifest-driven first download / cache) and + * runs `python -I -m dashscope.cli ` under two-layer isolation. JSON + * output is a leaf-level `--output-format json` carried in sdkArgs (the reviewed + * dashscope 1.25.23 CLI has no top-level --output option). + */ +export async function executeRl( + ctx: CommandContext, + sdkArgs: string[] | ((layout: ITaskDirLayout) => string[]), + options: IRlExecuteOptions = {}, +): Promise { + const credential = ctx.client.exportApiCredential(); + if (!credential) { + throw new BailianError( + "No API key found for the RL command. / RL 命令未找到 API Key。", + ExitCode.AUTH, + "Configure an API key first (see the auth command).", + ); + } + return executeInSandbox({ + sdkArgs, + // The RL SDK carries its own management-plane gateway routing: explicitly injecting base_url (the inference workspace gateway, even + // dashscope itself) breaks RL routing with 404; pass only the token and let the SDK use its default RL gateway (matches the demo cli.sh setting only the API Key). + credential: { token: credential.token }, + prepare: options.prepare, + timeoutMs: options.timeoutMs ?? RL_TIMEOUT_MS.query, + maxOutputBytes: RL_MAX_OUTPUT_BYTES, + signal: options.signal, + allowInstall: options.allowInstall, + }); +} + +/** + * Business + execution flags shared by `rl run` and `opd run`. The watch budget + * uses `--wait-timeout` because `--timeout` is a reserved global flag. + */ +export const RL_RUN_FLAGS = { + configFile: { + type: "string", + valueHint: "", + description: { + "en-US": "Optional job YAML file; explicit CLI flags override it", + "zh-CN": "可选的任务 YAML 文件;显式 CLI 参数优先级更高", + }, + }, + name: { + type: "string", + valueHint: "", + description: { "en-US": "Job name", "zh-CN": "任务名称" }, + }, + model: { + type: "string", + valueHint: "", + description: { "en-US": "Base model ID", "zh-CN": "基座模型 ID" }, + }, + trainFile: { + type: "array", + valueHint: "", + description: { "en-US": "Local training file (repeatable)", "zh-CN": "本地训练文件(可重复)" }, + }, + trainFileId: { + type: "array", + valueHint: "", + description: { + "en-US": "Uploaded training file ID (repeatable)", + "zh-CN": "已上传训练文件 ID(可重复)", + }, + }, + validationFile: { + type: "array", + valueHint: "", + description: { + "en-US": "Local validation file (repeatable)", + "zh-CN": "本地验证文件(可重复)", + }, + }, + validationFileId: { + type: "array", + valueHint: "", + description: { + "en-US": "Uploaded validation file ID (repeatable)", + "zh-CN": "已上传验证文件 ID(可重复)", + }, + }, + codeDir: { + type: "string", + valueHint: "", + description: { "en-US": "Function package source directory", "zh-CN": "函数代码包源目录" }, + }, + requirements: { + type: "string", + valueHint: "", + description: { + "en-US": "Requirements path relative to the code dir", + "zh-CN": "相对代码目录的 requirements 路径", + }, + }, + include: { + type: "array", + valueHint: "", + description: { + "en-US": "Package include glob (repeatable)", + "zh-CN": "打包纳入 glob(可重复)", + }, + }, + exclude: { + type: "array", + valueHint: "", + description: { + "en-US": "Package exclude glob (repeatable)", + "zh-CN": "打包排除 glob(可重复)", + }, + }, + rollout: { + type: "string", + valueHint: "", + description: { "en-US": "Rollout function classpath", "zh-CN": "rollout 函数 classpath" }, + }, + reward: { + type: "array", + valueHint: "", + description: { "en-US": "Reward function (repeatable)", "zh-CN": "reward 函数(可重复)" }, + }, + clearFunctions: { + type: "switch", + description: { + "en-US": "Clear functions defined in the YAML", + "zh-CN": "清空 YAML 中定义的函数", + }, + }, + functionTimeout: { + type: "array", + valueHint: "", + description: { + "en-US": "Function timeout in seconds (repeatable)", + "zh-CN": "函数超时秒数(可重复)", + }, + }, + functionRuntime: { + type: "array", + valueHint: "", + description: { + "en-US": "Function runtime field (repeatable)", + "zh-CN": "函数 runtime 字段(可重复)", + }, + }, + rewardWeight: { + type: "array", + valueHint: "", + description: { "en-US": "Reward weight (repeatable)", "zh-CN": "reward 权重(可重复)" }, + }, + rewardMetric: { + type: "array", + valueHint: "", + description: { + "en-US": "Reward metric weight (repeatable)", + "zh-CN": "reward 指标权重(可重复)", + }, + }, + functionEnv: { + type: "array", + valueHint: "", + description: { + "en-US": "Function environment variable (repeatable)", + "zh-CN": "函数环境变量(可重复)", + }, + }, + hp: { + type: "array", + valueHint: "", + description: { + "en-US": "Hyper-parameter (repeatable, parsed by type)", + "zh-CN": "超参数(可重复,按类型解析)", + }, + }, + chargeType: { + type: "string", + valueHint: "", + description: { "en-US": "Resource charge type", "zh-CN": "资源计费类型" }, + }, + mtuSpec: { + type: "string", + valueHint: "", + description: { "en-US": "MTU spec code", "zh-CN": "MTU 规格代码" }, + }, + mtuCount: { + type: "number", + valueHint: "", + description: { "en-US": "MTU capacity", "zh-CN": "MTU 数量" }, + }, + instanceId: { + type: "string", + valueHint: "", + description: { "en-US": "Prepaid resource instance ID", "zh-CN": "预付费资源实例 ID" }, + }, + set: { + type: "array", + valueHint: "", + description: { + "en-US": "Top-level spec override (repeatable, JSON value)", + "zh-CN": "顶层 spec 覆盖(可重复,值按 JSON 解析)", + }, + }, + watch: { + type: "switch", + description: { + "en-US": "Wait for the job to reach a terminal state", + "zh-CN": "提交后等待任务进入终态", + }, + }, + waitTimeout: { + type: "number", + valueHint: "", + description: { + "en-US": + "Maximum seconds to poll with --watch (default: no limit; does not cancel the cloud job)", + "zh-CN": "--watch 的最长轮询秒数(默认无限制;超时不取消云端任务)", + }, + }, + installRuntime: { + type: "switch", + description: { + "en-US": "Allow first-time managed runtime preparation", + "zh-CN": "允许首次准备托管运行时", + }, + }, +} satisfies FlagsDef; + +/** Map parsed run flags into the core business-param shape. */ +export function buildRlRunParams(flags: ParsedFlags): RlRunParams { + return { + name: flags.name, + model: flags.model, + trainFiles: flags.trainFile, + trainFileIds: flags.trainFileId, + validationFiles: flags.validationFile, + validationFileIds: flags.validationFileId, + codeDir: flags.codeDir, + requirements: flags.requirements, + include: flags.include, + exclude: flags.exclude, + rollout: flags.rollout, + rewards: flags.reward, + clearFunctions: flags.clearFunctions, + functionTimeouts: flags.functionTimeout, + functionRuntime: flags.functionRuntime, + rewardWeights: flags.rewardWeight, + rewardMetrics: flags.rewardMetric, + functionEnv: flags.functionEnv, + hp: flags.hp, + chargeType: flags.chargeType, + mtuSpec: flags.mtuSpec, + mtuCount: flags.mtuCount, + instanceId: flags.instanceId, + set: flags.set, + }; +} + +/** Read the optional job YAML, keeping an errno-specific hint on I/O failure. */ +export function readRlConfigFile(filePath: string): string { + try { + return readFileSync(filePath, "utf8"); + } catch (error) { + const errno = (error as NodeJS.ErrnoException).code; + const hint = + errno === "ENOENT" + ? `Config file not found: ${filePath}` + : errno === "EACCES" || errno === "EPERM" + ? `Permission denied reading config file: ${filePath}` + : errno === "EISDIR" + ? `Config file path is a directory: ${filePath}` + : `Cannot read config file: ${filePath} (${errno ?? String(error)})`; + throw new BailianError(`Cannot read config file: ${filePath}`, ExitCode.GENERAL, hint); + } +} + +/** Snapshot the code package and stage local data files into the task layout. */ +function stageJobInputs(spec: RlJobSpec, layout: ITaskDirLayout): void { + const codeDir = + spec.bailian?.code_dir ?? spec.functions?.find((fn) => fn.fcmodel?.zipdir)?.fcmodel?.zipdir; + if (codeDir) { + createSnapshot({ + sourceDir: codeDir, + snapshotDir: layout.snapshotDir, + deployCopyDir: layout.deployCopyDir, + include: spec.bailian?.package?.include, + exclude: spec.bailian?.package?.exclude, + }); + } + const localFiles = (spec.datasets ?? []) + .map((dataset) => dataset.file_name) + .filter((file): file is string => typeof file === "string" && file.length > 0); + if (localFiles.length > 0) stageDataFiles(localFiles, layout.dataDir); +} + +export interface IRlRunControls { + /** Dry-run action label, e.g. `finetune.rl.run`. */ + action: string; + watch?: boolean; + waitTimeoutSeconds?: number; + allowInstall?: boolean; +} + +/** + * Assemble the spec, then submit `rl run` inside the sandbox (the reviewed + * dashscope 1.25.23 CLI surface: run/get/list/logs/cancel, no `jobs` subgroup). + * Shared by `rl run` and `opd run`; the caller supplies the merged business + * params and the optional YAML text. Dry-run returns the assembled spec with + * zero writes. + */ +export async function runRlJob( + ctx: CommandContext, + params: RlRunParams, + yamlText: string | undefined, + controls: IRlRunControls, +): Promise { + const resolved = resolveTrainingSpec(params, yamlText); + const watch = controls.watch === true; + const waitTimeoutSeconds = controls.waitTimeoutSeconds; + + if (ctx.settings.dryRun) { + emitRlDryRun(ctx, controls.action, { + model: resolved.spec.model?.name, + training_type: resolved.spec.training?.type, + has_functions: resolved.hasFunctions, + is_opd: resolved.isOpd, + watch, + wait_timeout: waitTimeoutSeconds, + spec: resolved.spec, + }); + return; + } + + // The reviewed runtime baseline (dashscope 1.25.23) does not include the pg_opd training type: real OPD submissions + // fail fast (dry-run can still preview the spec) without introducing a second runtime. get/list/logs/watch/ + // cancel/delete share the fine-tunes backend and are unaffected. + if (resolved.isOpd) { + throw new BailianError( + `OPD (pg_opd) submission is not supported by the reviewed dashscope runtime ${RL_DASHSCOPE_VERSION}. / 受审查的 dashscope 运行时 ${RL_DASHSCOPE_VERSION} 不支持 OPD(pg_opd)提交。`, + ExitCode.USAGE, + "Use finetune rl run for reinforcement training; OPD requires a newer reviewed SDK baseline. No cloud resources were created.", + ); + } + + // Submit only: the SDK registers/uploads/submits and returns the job envelope + // without blocking. `--watch` then polls in the TS host like `finetune watch + // --follow`, sharing its no-default-timeout semantics (no sandbox wait ceiling). + const data = await executeRl(ctx, ["rl", "run", "--output-format", "json"], { + timeoutMs: RL_TIMEOUT_MS.run, + allowInstall: controls.allowInstall, + prepare: (layout) => { + stageJobInputs(resolved.spec, layout); + return buildTaskYaml(resolved.spec, { + deployCopyDir: layout.deployCopyDir, + dataDir: layout.dataDir, + }); + }, + }); + + if (!watch) { + emitRlResult(ctx, data); + return; + } + + const jobId = (data as { job_id?: string } | null)?.job_id; + if (!jobId) { + // Submit returned no job id to follow; surface the raw submit result. + emitRlResult(ctx, data); + return; + } + await followRlJob(ctx, jobId, { + pollTimeoutSec: waitTimeoutSeconds, + jobLabel: params.opd ? "OPD job" : "RL job", + }); +} + +export interface IRlAuthorizeOptions { + target: RlAuthTarget; + /** Dry-run action label, e.g. `finetune.rl.authorize`. */ + action: string; + /** Permit role creation / enablement; read-only probe when false. */ + authorize: boolean; +} + +/** + * Run the console-side authorization state machine for one target. Authorization + * runs in the TS host (no Python sandbox); dry-run previews the console target + * and whether mutations are permitted, with zero network calls. + */ +export async function runRlAuthorize( + ctx: CommandContext, + options: IRlAuthorizeOptions, +): Promise { + if (ctx.settings.dryRun) { + emitRlDryRun(ctx, options.action, { + target: options.target, + authorize: options.authorize, + ...consoleReadTargetPreview(ctx.settings), + }); + return; + } + const report = await runRlAuthorization({ + target: options.target, + console: (api, data) => ctx.client.console(api, data), + workspaceId: ctx.settings.workspaceId, + authorize: options.authorize, + localize: ctx.localize, + manualAuthDocUrl: options.target === "opd" ? OPD_TRAINING_DOC : RL_TRAINING_DOC, + }); + emitRlResult(ctx, report); +} + +/** Default polling interval for `rl watch --follow` (seconds). */ +export const RL_WATCH_DEFAULT_INTERVAL_SEC = 10; +/** Minimum polling interval for `rl watch --follow` (seconds). */ +export const RL_WATCH_MIN_INTERVAL_SEC = 1; +const RL_TERMINAL_STATUSES = new Set(["SUCCEEDED", "FAILED", "CANCELED"]); + +function rlWatchStamp(): string { + const date = new Date(); + const pad = (value: number) => String(value).padStart(2, "0"); + return `${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`; +} + +function formatRlElapsed(milliseconds: number): string { + const totalSeconds = Math.floor(milliseconds / 1000); + const minutes = Math.floor(totalSeconds / 60); + const seconds = totalSeconds % 60; + if (minutes === 0) return `${seconds}s`; + return `${minutes}m ${seconds}s`; +} + +/** Resolve after `milliseconds`, rejecting early on abort (Ctrl-C). */ +function rlWatchSleep(milliseconds: number, signal: AbortSignal): Promise { + return new Promise((resolve, reject) => { + if (signal.aborted) { + reject(new Error("aborted")); + return; + } + const onAbort = () => { + clearTimeout(timer); + reject(new Error("aborted")); + }; + const timer = setTimeout(() => { + signal.removeEventListener("abort", onAbort); + resolve(); + }, milliseconds); + signal.addEventListener("abort", onAbort, { once: true }); + }); +} + +/** + * Single non-blocking status probe, mirroring `finetune watch` default. RL jobs + * share the fine-tunes backend, so this queries the same HTTP endpoint in the TS + * host (no sandbox). A terminal FAILED/CANCELED status raises a normal error. + */ +export async function probeRlJob( + ctx: CommandContext, + jobId: string, + jobLabel = "RL job", + workspaceId?: string, +): Promise { + const response = await getFineTune(ctx.client, jobId, undefined, workspaceId); + const job = response.output ?? response.data; + const status = String(job?.status ?? "").toUpperCase(); + const terminal = RL_TERMINAL_STATUSES.has(status); + emitRlResult(ctx, { + job_id: jobId, + status: status || "UNKNOWN", + terminal, + request_id: response.request_id, + }); + if (terminal && status !== "SUCCEEDED") { + throw new BailianError(`${jobLabel} ${jobId} ended in status ${status}.`, ExitCode.GENERAL); + } +} + +export interface IRlFollowOptions { + intervalSec?: number; + /** Stop polling after this many seconds; undefined means no limit. */ + pollTimeoutSec?: number; + /** Domain wording for terminal/timeout errors, e.g. "OPD job". */ + jobLabel?: string; + /** Sent as X-DashScope-WorkSpace on each poll; omit for the key-bound space. */ + workspaceId?: string; +} + +/** + * Blocking poll loop, mirroring `finetune watch --follow`. Polls the fine-tunes + * endpoint in the TS host until a terminal state; Ctrl-C aborts gracefully and + * `pollTimeoutSec` (default: no limit) bounds the wait without cancelling the job. + */ +export async function followRlJob( + ctx: CommandContext, + jobId: string, + options: IRlFollowOptions = {}, +): Promise { + const intervalSec = Math.max( + RL_WATCH_MIN_INTERVAL_SEC, + options.intervalSec ?? RL_WATCH_DEFAULT_INTERVAL_SEC, + ); + const pollTimeoutSec = options.pollTimeoutSec; + const jobLabel = options.jobLabel ?? "RL job"; + const controller = new AbortController(); + const onSigint = () => controller.abort(); + process.on("SIGINT", onSigint); + + try { + let lastStatus = ""; + const startedAt = Date.now(); + + // eslint-disable-next-line no-constant-condition + while (true) { + const response = await getFineTune(ctx.client, jobId, controller.signal, options.workspaceId); + const job = response.output ?? response.data; + const status = String(job?.status ?? "").toUpperCase(); + + if (status !== lastStatus) { + ctx.output.progress({ + "en-US": `${rlWatchStamp()} ${jobId} ${status || "UNKNOWN"}`, + "zh-CN": `${rlWatchStamp()} ${jobId} ${status || "UNKNOWN"}`, + }); + lastStatus = status; + } + + if (RL_TERMINAL_STATUSES.has(status)) { + const elapsed = Date.now() - startedAt; + emitRlResult(ctx, response); + if (status !== "SUCCEEDED") { + throw new BailianError( + `${jobLabel} ${jobId} ended in status ${status} (elapsed ${formatRlElapsed(elapsed)}).`, + ExitCode.GENERAL, + ); + } + return; + } + + if (pollTimeoutSec !== undefined && (Date.now() - startedAt) / 1000 >= pollTimeoutSec) { + throw new BailianError( + `Watching ${jobLabel} ${jobId} timed out after ` + + `${formatRlElapsed(Date.now() - startedAt)} (last status: ${status || "UNKNOWN"}).`, + ExitCode.TIMEOUT, + ); + } + + await rlWatchSleep(intervalSec * 1000, controller.signal); + } + } catch (error) { + if (controller.signal.aborted) { + ctx.output.info({ "en-US": "Interrupted.", "zh-CN": "已中断。" }); + return; + } + throw error; + } finally { + process.off("SIGINT", onSigint); + } +} diff --git a/packages/commands/src/commands/finetune/rl-watch.ts b/packages/commands/src/commands/finetune/rl-watch.ts new file mode 100644 index 00000000..bf84edc3 --- /dev/null +++ b/packages/commands/src/commands/finetune/rl-watch.ts @@ -0,0 +1,3 @@ +import { defineJobWatchCommand } from "./rl-job-commands.ts"; + +export default defineJobWatchCommand("rl"); diff --git a/packages/commands/src/commands/finetune/runtime-clean.ts b/packages/commands/src/commands/finetune/runtime-clean.ts new file mode 100644 index 00000000..56d8fed5 --- /dev/null +++ b/packages/commands/src/commands/finetune/runtime-clean.ts @@ -0,0 +1,90 @@ +import { + cleanupSandboxArtifacts, + currentManagedRuntimeId, + DEFAULT_RUNS_TTL_MS, + defineCommand, + type FlagsDef, +} from "bailian-cli-core"; + +import { emitRlDryRun, emitRlResult } from "./rl-shared.ts"; + +const MS_PER_HOUR = 3_600_000; + +const CLEAN_FLAGS = { + ttlHours: { + type: "number", + valueHint: "", + description: { + "en-US": "Age threshold for orphaned run directories (default 24)", + "zh-CN": "孤儿任务目录的年龄阈值(默认 24 小时)", + }, + }, +} satisfies FlagsDef; + +export default defineCommand({ + defaultOutput: "json", + description: { + "en-US": "Reclaim orphaned sandbox run directories and superseded runtime versions", + "zh-CN": "回收孤儿沙箱任务目录与旧版本运行时", + }, + auth: "none", + risk: { + level: "high", + reason: "destructive", + message: { + "en-US": + "This permanently deletes orphaned run directories and superseded runtime versions; it cannot be undone.", + "zh-CN": "该操作会永久删除孤儿任务目录与旧版本运行时,且无法撤销。", + }, + }, + usageArgs: "[--ttl-hours ] [--dry-run]", + flags: CLEAN_FLAGS, + exampleArgs: ["--dry-run", "--ttl-hours 48", ""], + notes: [ + { + "en-US": + "Normal runs are disposed automatically when the invocation ends; only crash leftovers (older than the TTL) remain under runs/. Superseded runtime versions under runtimes/rl/ are reclaimed, keeping only the current reviewed baseline.", + "zh-CN": + "正常调用的任务目录在结束时自动销毁,runs/ 下只剩崩溃残留(超过 TTL 才回收);runtimes/rl/ 下仅保留当前受审查基线,旧版本目录被回收。", + }, + { + "en-US": + "Never touches the current baseline runtime, BAILIAN_RL_RUNTIME development directories, or the content-addressed download cache. Local only: no credentials, no cloud resources.", + "zh-CN": + "绝不触碰当前基线运行时、BAILIAN_RL_RUNTIME 开发目录与按内容寻址的下载缓存。纯本地操作:无需凭证,不创建任何云资源。", + }, + { + "en-US": + "Deletion is irreversible; preview the remove/keep plan with --dry-run first. Runtime reclamation requires a bundled manifest entry for this platform; otherwise only runs are pruned.", + "zh-CN": + "删除不可撤销,请先用 --dry-run 预览 remove/keep 计划。运行时回收需要本平台在随包清单中有条目,否则只清理 runs。", + }, + ], + validate: (flags) => { + const ttlHours = flags.ttlHours as number | undefined; + if (ttlHours !== undefined && !(ttlHours > 0)) { + return "--ttl-hours must be a positive number. / --ttl-hours 必须为正数。"; + } + return undefined; + }, + async run(ctx) { + const ttlHours = + (ctx.flags.ttlHours as number | undefined) ?? DEFAULT_RUNS_TTL_MS / MS_PER_HOUR; + const currentRuntimeId = currentManagedRuntimeId(); + const options = { + runsTtlMs: ttlHours * MS_PER_HOUR, + pruneRuns: true, + pruneRuntimes: currentRuntimeId !== undefined, + currentRuntimeId, + }; + if (ctx.settings.dryRun) { + emitRlDryRun( + ctx, + "finetune.runtime.clean", + cleanupSandboxArtifacts({ ...options, dryRun: true }), + ); + return; + } + emitRlResult(ctx, cleanupSandboxArtifacts(options)); + }, +}); diff --git a/packages/commands/src/commands/finetune/runtime-doctor.ts b/packages/commands/src/commands/finetune/runtime-doctor.ts new file mode 100644 index 00000000..d5d3ad82 --- /dev/null +++ b/packages/commands/src/commands/finetune/runtime-doctor.ts @@ -0,0 +1,65 @@ +import { homedir } from "node:os"; +import { join } from "node:path"; +import { + assertDoctorPassed, + defineCommand, + resolveRuntime, + runRuntimeDoctor, + type IResolvedRuntime, +} from "bailian-cli-core"; + +import { emitRlDryRun, emitRlResult } from "./rl-shared.ts"; + +export default defineCommand({ + defaultOutput: "json", + description: { + "en-US": + "Check the RL runtime and sandbox isolation (credential deny, home redirect, SDK import)", + "zh-CN": "检查 RL 运行时与沙箱隔离(凭据禁读、home 重定向、SDK 导入)", + }, + auth: "none", + usageArgs: "", + flags: {}, + exampleArgs: ["", "--dry-run", "--output json"], + notes: [ + { + "en-US": + "Read-only self-check; it creates no cloud resources. Required checks must pass; when the runtime is missing they are skipped (not treated as passed) and the command exits non-zero.", + "zh-CN": + "只读自检,不创建任何云资源。必过项必须通过;运行时缺失时相关项记为 skip(不当作通过),命令以非零码退出。", + }, + { + "en-US": + "Enhanced hardening (kernel network enforcement, process tree, memory) degrades with a notice when unavailable and does not fail the overall check.", + "zh-CN": "增强项(内核网络强制、进程树、内存)不可用时降级提示,不判定整体失败。", + }, + { + "en-US": + "Host network reachability (API / runtime download / PyPI hosts) is probed as an advisory check: blocked hosts degrade with guidance (agent sandboxes often block outbound network) and do not fail the overall check.", + "zh-CN": + "宿主网络可达性(API / 运行时下载 / PyPI 主机)为增强项:被阻断时降级并给出指引(agent 沙箱常默认阻断出站网络),不判定整体失败。", + }, + ], + async run(ctx) { + if (ctx.settings.dryRun) { + emitRlDryRun(ctx, "finetune.runtime.doctor", { + credential_deny_paths: [join(homedir(), ".dashscope")], + }); + return; + } + // A missing runtime is reported as skipped checks, not a hard resolve error. + let runtime: IResolvedRuntime | undefined; + try { + runtime = await resolveRuntime({ allowInstall: false }); + } catch { + runtime = undefined; + } + const report = await runRuntimeDoctor({ + runtime, + credentialDenyPaths: [join(homedir(), ".dashscope")], + checkHostNetwork: true, + }); + emitRlResult(ctx, report); + assertDoctorPassed(report); + }, +}); diff --git a/packages/commands/src/commands/finetune/runtime-prepare.ts b/packages/commands/src/commands/finetune/runtime-prepare.ts new file mode 100644 index 00000000..5f3e7940 --- /dev/null +++ b/packages/commands/src/commands/finetune/runtime-prepare.ts @@ -0,0 +1,92 @@ +import { + cleanupSandboxArtifacts, + defineCommand, + resolveRuntime, + RUNTIME_OVERRIDE_ENV, + type FlagsDef, +} from "bailian-cli-core"; + +import { emitRlDryRun, emitRlResult } from "./rl-shared.ts"; + +const PREPARE_FLAGS = { + manifest: { + type: "string", + valueHint: "", + description: { + "en-US": "Optional runtime manifest file (defaults to the bundled reviewed manifest)", + "zh-CN": "可选的运行时清单文件(默认使用随包受审查清单)", + }, + }, +} satisfies FlagsDef; + +export default defineCommand({ + defaultOutput: "json", + description: { + "en-US": "Prepare the managed Python/SDK runtime used by RL and OPD jobs", + "zh-CN": "准备 RL / OPD 任务使用的托管 Python/SDK 运行时", + }, + auth: "none", + usageArgs: "[--manifest ]", + flags: PREPARE_FLAGS, + exampleArgs: ["", "--manifest ./runtime-manifest.json", "--dry-run"], + notes: [ + { + "en-US": + "Downloads and verifies the runtime locally; it never creates a training job. Set BAILIAN_RL_RUNTIME to a local dashscope Python directory to reuse a development runtime instead.", + "zh-CN": + "仅在本地下载并校验运行时,不会创建训练任务。可将 BAILIAN_RL_RUNTIME 指向本机 dashscope Python 目录以复用开发态运行时。", + }, + { + "en-US": + "On an unsupported platform this reports RUNTIME_UNAVAILABLE; no cloud resources are created.", + "zh-CN": "在不支持的平台返回 RUNTIME_UNAVAILABLE;不会创建任何云资源。", + }, + { + "en-US": + "CPython downloads fall back to a built-in npmmirror mirror when GitHub is unreachable; set BAILIAN_RL_PYTHON_MIRROR to a custom mirror prefix. Integrity is always verified against the reviewed SHA256 regardless of source.", + "zh-CN": + "GitHub 不可达时 CPython 下载回退到内置 npmmirror 镜像;可用 BAILIAN_RL_PYTHON_MIRROR 指定自定义镜像前缀。无论哪个源,完整性始终按受审查 SHA256 校验。", + }, + { + "en-US": + "In regions where the PyPI CDN stalls, set BAILIAN_RL_PIP_INDEX_URL to a stable PyPI mirror (e.g. https://pypi.tuna.tsinghua.edu.cn/simple/ or https://mirrors.aliyun.com/pypi/simple/); pip still verifies every package hash via --require-hashes. Mirrors lag PyPI: if a mirror lacks a pinned version, pip reports 'No matching distribution found for X==ver' — use a fresher mirror or the default PyPI.", + "zh-CN": + "PyPI CDN 受限地区可设 BAILIAN_RL_PIP_INDEX_URL 指向稳定 PyPI 镜像(如 https://pypi.tuna.tsinghua.edu.cn/simple/ 或 https://mirrors.aliyun.com/pypi/simple/);pip 仍以 --require-hashes 逐包校验哈希。镜像同步滞后于 PyPI:若镜像缺锁文件钉的版本,pip 报 No matching distribution found for X==ver,换更新更快的镜像或回默认 PyPI。", + }, + { + "en-US": + "Prepare also reclaims orphaned run directories older than 24 hours (crash leftovers); normal runs are disposed automatically when the invocation ends. Use runtime clean to preview or reclaim superseded runtime versions.", + "zh-CN": + "prepare 会顺手回收超过 24 小时的孤儿任务目录(崩溃残留);正常调用的任务目录在结束时自动销毁。预览或回收旧版本运行时请用 runtime clean。", + }, + ], + async run(ctx) { + if (ctx.settings.dryRun) { + emitRlDryRun(ctx, "finetune.runtime.prepare", { + manifest: ctx.flags.manifest, + override_env: RUNTIME_OVERRIDE_ENV, + allow_install: true, + prune_orphan_runs: true, + }); + return; + } + // Opportunistically reclaim crash-orphaned runs (TTL safety net); best-effort, never blocks the main prepare flow. + let prunedRuns = 0; + try { + prunedRuns = cleanupSandboxArtifacts({ pruneRuntimes: false }).removedCount; + } catch { + // Leave cleanup failures to runtime clean + } + const runtime = await resolveRuntime({ + allowInstall: true, + manifestPath: ctx.flags.manifest, + }); + emitRlResult(ctx, { + runtime_root: runtime.runtimeRoot, + python_path: runtime.pythonPath, + dashscope_version: runtime.dashscopeVersion, + source: runtime.source, + pruned_runs: prunedRuns, + }); + }, +}); diff --git a/packages/commands/src/index.ts b/packages/commands/src/index.ts index 732502bf..90d12cf7 100644 --- a/packages/commands/src/index.ts +++ b/packages/commands/src/index.ts @@ -206,6 +206,25 @@ export { default as finetuneCompressWatch } from "./commands/finetune/compress-w export { default as finetuneCompressLogs } from "./commands/finetune/compress-logs.ts"; export { default as finetuneCompressCancel } from "./commands/finetune/compress-cancel.ts"; export { default as finetuneCompressDelete } from "./commands/finetune/compress-delete.ts"; +export { default as finetuneRlAuthorize } from "./commands/finetune/rl-authorize.ts"; +export { default as finetuneRlRun } from "./commands/finetune/rl-run.ts"; +export { default as finetuneRlGet } from "./commands/finetune/rl-get.ts"; +export { default as finetuneRlList } from "./commands/finetune/rl-list.ts"; +export { default as finetuneRlWatch } from "./commands/finetune/rl-watch.ts"; +export { default as finetuneRlLogs } from "./commands/finetune/rl-logs.ts"; +export { default as finetuneRlCancel } from "./commands/finetune/rl-cancel.ts"; +export { default as finetuneRlDelete } from "./commands/finetune/rl-delete.ts"; +export { default as finetuneOpdAuthorize } from "./commands/finetune/opd-authorize.ts"; +export { default as finetuneOpdRun } from "./commands/finetune/opd-run.ts"; +export { default as finetuneOpdParams } from "./commands/finetune/opd-params.ts"; +export { default as finetuneOpdGet } from "./commands/finetune/opd-get.ts"; +export { default as finetuneOpdWatch } from "./commands/finetune/opd-watch.ts"; +export { default as finetuneOpdLogs } from "./commands/finetune/opd-logs.ts"; +export { default as finetuneOpdCancel } from "./commands/finetune/opd-cancel.ts"; +export { default as finetuneOpdDelete } from "./commands/finetune/opd-delete.ts"; +export { default as finetuneRuntimePrepare } from "./commands/finetune/runtime-prepare.ts"; +export { default as finetuneRuntimeDoctor } from "./commands/finetune/runtime-doctor.ts"; +export { default as finetuneRuntimeClean } from "./commands/finetune/runtime-clean.ts"; export { deployTextCreate, deployAudioCreate, diff --git a/packages/commands/tests/e2e/finetune-rl.e2e.test.ts b/packages/commands/tests/e2e/finetune-rl.e2e.test.ts new file mode 100644 index 00000000..c7c19b47 --- /dev/null +++ b/packages/commands/tests/e2e/finetune-rl.e2e.test.ts @@ -0,0 +1,1431 @@ +import { describe, expect, test } from "vite-plus/test"; +import { existsSync, mkdirSync, mkdtempSync, rmSync, utimesSync, writeFileSync } from "node:fs"; +import { tmpdir } from "node:os"; +import { join } from "node:path"; +import { fileURLToPath } from "node:url"; +import { + isConsoleE2EReady, + isDashScopeE2EReady, + parseStdoutJson, + runCommandHelp, + runCommandInProcess, +} from "./helpers.ts"; +import { FINETUNE_ROUTES } from "./topic-routes.ts"; + +// A dummy key keeps the offline cases hermetic; the confirmation gate runs +// before auth, and dry-run swallows credential resolution for these commands. +const DUMMY_KEY = ["--api-key", "e2e-dummy-key"]; + +describe("e2e: finetune rl/opd/runtime help", () => { + test("rl group lists the job subcommands", async () => { + const { stderr, exitCode } = await runCommandHelp(FINETUNE_ROUTES, [ + "finetune", + "rl", + "--help", + ]); + expect(exitCode, stderr).toBe(0); + expect(stderr).toMatch(/run|get|list|watch|logs|cancel|delete|authorize/); + }); + + test("rl run help exposes the confirmation gate and execution flags", async () => { + const { stderr, exitCode } = await runCommandHelp(FINETUNE_ROUTES, [ + "finetune", + "rl", + "run", + "--help", + ]); + expect(exitCode, stderr).toBe(0); + expect(stderr).toMatch(/--yes/); + expect(stderr).toMatch(/--model/); + expect(stderr).toMatch(/--watch/); + expect(stderr).toMatch(/--wait-timeout/); + expect(stderr).toMatch(/--config-file/); + expect(stderr).toMatch(/--install-runtime/); + }); + + test("opd run help exposes the OpenAPI contract, not the RL sandbox flags", async () => { + const { stderr, exitCode } = await runCommandHelp(FINETUNE_ROUTES, [ + "finetune", + "opd", + "run", + "--help", + ]); + expect(exitCode, stderr).toBe(0); + expect(stderr).toMatch(/--teacher-model/); + expect(stderr).toMatch(/--base-model/); + expect(stderr).toMatch(/--datasets/); + expect(stderr).toMatch(/--hyper-parameters-file/); + expect(stderr).toMatch(/--resource-config-file/); + expect(stderr).toMatch(/--hp/); + expect(stderr).toMatch(/--workspace-id/); + expect(stderr).toMatch(/--yes/); + expect(stderr).not.toMatch(/--rollout|--code-dir|--install-runtime|--config-file/); + }); + + test("opd group lists the job subcommands", async () => { + const { stderr, exitCode } = await runCommandHelp(FINETUNE_ROUTES, [ + "finetune", + "opd", + "--help", + ]); + expect(exitCode, stderr).toBe(0); + expect(stderr).toMatch(/run|params|get|watch|logs|cancel|delete|authorize/); + // Listing is shared with finetune list; opd has no list subcommand. + expect(stderr).not.toMatch(/^\s*list\b/m); + }); + + test("opd params help exposes the parameter-group flags", async () => { + const { stderr, exitCode } = await runCommandHelp(FINETUNE_ROUTES, [ + "finetune", + "opd", + "params", + "--help", + ]); + expect(exitCode, stderr).toBe(0); + expect(stderr).toMatch(/--base-model/); + expect(stderr).toMatch(/--param-type/); + expect(stderr).toMatch(/--mtu-spec-code/); + }); + + test("opd watch help exposes follow/interval/poll-timeout", async () => { + const { stderr, exitCode } = await runCommandHelp(FINETUNE_ROUTES, [ + "finetune", + "opd", + "watch", + "--help", + ]); + expect(exitCode, stderr).toBe(0); + expect(stderr).toMatch(/--follow/); + expect(stderr).toMatch(/--interval/); + expect(stderr).toMatch(/--poll-timeout/); + }); + + test("rl authorize help exposes --authorize and the injected --yes", async () => { + const { stderr, exitCode } = await runCommandHelp(FINETUNE_ROUTES, [ + "finetune", + "rl", + "authorize", + "--help", + ]); + expect(exitCode, stderr).toBe(0); + expect(stderr).toMatch(/--authorize/); + expect(stderr).toMatch(/--yes/); + }); + + test("opd authorize help exposes --authorize and the injected --yes", async () => { + const { stderr, exitCode } = await runCommandHelp(FINETUNE_ROUTES, [ + "finetune", + "opd", + "authorize", + "--help", + ]); + expect(exitCode, stderr).toBe(0); + expect(stderr).toMatch(/--authorize/); + expect(stderr).toMatch(/--yes/); + }); + + test("rl watch help exposes follow/interval/poll-timeout", async () => { + const { stderr, exitCode } = await runCommandHelp(FINETUNE_ROUTES, [ + "finetune", + "rl", + "watch", + "--help", + ]); + expect(exitCode, stderr).toBe(0); + expect(stderr).toMatch(/--follow/); + expect(stderr).toMatch(/--interval/); + expect(stderr).toMatch(/--poll-timeout/); + }); + + test("runtime prepare help exits cleanly and shows --manifest", async () => { + const { stderr, exitCode } = await runCommandHelp(FINETUNE_ROUTES, [ + "finetune", + "runtime", + "prepare", + "--help", + ]); + expect(exitCode, stderr).toBe(0); + expect(stderr).toMatch(/--manifest/); + }); + + test("runtime doctor help exits cleanly", async () => { + const { stderr, exitCode } = await runCommandHelp(FINETUNE_ROUTES, [ + "finetune", + "runtime", + "doctor", + "--help", + ]); + expect(exitCode, stderr).toBe(0); + }); +}); + +describe("e2e: finetune rl/opd offline contracts", () => { + test("rl run without --yes requires confirmation (7)", async () => { + const { stderr, exitCode } = await runCommandInProcess(FINETUNE_ROUTES, [ + "finetune", + "rl", + "run", + "--model", + "qwen3.5-9b", + ...DUMMY_KEY, + "--output", + "json", + ]); + expect(exitCode).toBe(7); + expect(JSON.parse(stderr)).toMatchObject({ + error: { code: 7, type: "requires_confirmation" }, + }); + }); + + test("rl run dry-run without a base model is a usage error (2)", async () => { + const { stderr, exitCode } = await runCommandInProcess(FINETUNE_ROUTES, [ + "finetune", + "rl", + "run", + "--dry-run", + ...DUMMY_KEY, + "--output", + "json", + ]); + expect(exitCode).toBe(2); + expect(stderr).toMatch(/model/i); + }); + + test("rl run dry-run previews a reinforcement spec with no writes", async () => { + const { stdout, stderr, exitCode } = await runCommandInProcess(FINETUNE_ROUTES, [ + "finetune", + "rl", + "run", + "--model", + "qwen3.5-9b", + "--dry-run", + ...DUMMY_KEY, + "--output", + "json", + ]); + expect(exitCode, stderr).toBe(0); + const data = parseStdoutJson<{ + action: string; + model: string; + training_type: string; + is_opd: boolean; + has_functions: boolean; + watch: boolean; + }>(stdout); + expect(data.action).toBe("finetune.rl.run"); + expect(data.model).toBe("qwen3.5-9b"); + expect(data.training_type).toBe("reinforcement"); + expect(data.is_opd).toBe(false); + expect(data.has_functions).toBe(false); + expect(data.watch).toBe(false); + }); + + test("opd run without --yes requires confirmation (7)", async () => { + const { stderr, exitCode } = await runCommandInProcess(FINETUNE_ROUTES, [ + "finetune", + "opd", + "run", + "--base-model", + "qwen3.5-9b", + "--teacher-model", + "qwen3.5-397b-a17b", + "--datasets", + "file-train", + ...DUMMY_KEY, + "--output", + "json", + ]); + expect(exitCode).toBe(7); + expect(JSON.parse(stderr)).toMatchObject({ + error: { code: 7, type: "requires_confirmation" }, + }); + }); + + test("opd run dry-run without --teacher-model is a usage error (2)", async () => { + const { stderr, exitCode } = await runCommandInProcess(FINETUNE_ROUTES, [ + "finetune", + "opd", + "run", + "--base-model", + "qwen3.5-9b", + "--datasets", + "file-train", + "--dry-run", + ...DUMMY_KEY, + "--output", + "json", + ]); + expect(exitCode).toBe(2); + expect(stderr).toMatch(/teacher-model/i); + }); + + test("opd run dry-run without --datasets is a usage error (2)", async () => { + const { stderr, exitCode } = await runCommandInProcess(FINETUNE_ROUTES, [ + "finetune", + "opd", + "run", + "--base-model", + "qwen3.5-9b", + "--teacher-model", + "qwen3.5-397b-a17b", + "--dry-run", + ...DUMMY_KEY, + "--output", + "json", + ]); + expect(exitCode).toBe(2); + expect(stderr).toMatch(/datasets/i); + }); + + test("opd run dry-run builds the pg_opd OpenAPI body with dataset descriptors", async () => { + const { stdout, stderr, exitCode } = await runCommandInProcess(FINETUNE_ROUTES, [ + "finetune", + "opd", + "run", + "--base-model", + "qwen3.5-9b", + "--teacher-model", + "qwen3.5-397b-a17b", + "--datasets", + "file-train", + "--validations", + "file-val", + "--mtu-spec", + "MTU4", + "--mtu-count", + "16", + "--dry-run", + ...DUMMY_KEY, + "--output", + "json", + ]); + expect(exitCode, stderr).toBe(0); + const data = parseStdoutJson<{ + action: string; + watch: boolean; + body: { + model: string; + training_type: string; + teacher_model: string; + training_datasets: Array<{ type: string; data_source_type: string; file_id: string }>; + validation_datasets: Array<{ type: string; data_source_type: string; file_id: string }>; + resource_config: Record; + }; + }>(stdout); + expect(data.action).toBe("finetune.opd.run"); + expect(data.watch).toBe(false); + expect(data.body.model).toBe("qwen3.5-9b"); + expect(data.body.training_type).toBe("pg_opd"); + expect(data.body.teacher_model).toBe("qwen3.5-397b-a17b"); + expect(data.body.training_datasets).toEqual([ + { type: "training", data_source_type: "file_id", file_id: "file-train" }, + ]); + expect(data.body.validation_datasets).toEqual([ + { type: "validation", data_source_type: "file_id", file_id: "file-val" }, + ]); + // charge_type defaults locally; MTU fields come from the flags. + expect(data.body.resource_config).toEqual({ + charge_type: "mtu_postpaid", + mtu_spec_code: "MTU4", + mtu_capacity: 16, + }); + // No student layout fields -> default-layout capacity advisory. + expect(stderr).toMatch(/OPD_DEFAULT_LAYOUT_CAPACITY/); + }); + + test("opd run dry-run reproduces the historical baseline body from JSON files", async () => { + const hyperFile = fileURLToPath( + new URL("./fixtures/opd-hyper-parameters.json", import.meta.url), + ); + const resourceFile = fileURLToPath( + new URL("./fixtures/opd-resource-config.json", import.meta.url), + ); + const { stdout, stderr, exitCode } = await runCommandInProcess(FINETUNE_ROUTES, [ + "finetune", + "opd", + "run", + "--base-model", + "qwen3.5-9b", + "--teacher-model", + "qwen3.8-flash", + "--datasets", + "file-train-placeholder", + "--validations", + "file-val-placeholder", + "--hyper-parameters-file", + hyperFile, + "--resource-config-file", + resourceFile, + "--job-name", + "e2e-opd-baseline", + "--dry-run", + ...DUMMY_KEY, + "--output", + "json", + ]); + expect(exitCode, stderr).toBe(0); + const data = parseStdoutJson<{ body: Record }>(stdout); + // Historical 9B←Flash success baseline (placeholder file IDs; job_name is + // the only intentionally different field). + expect(data.body).toEqual({ + model: "qwen3.5-9b", + training_type: "pg_opd", + teacher_model: "qwen3.8-flash", + training_datasets: [ + { type: "training", data_source_type: "file_id", file_id: "file-train-placeholder" }, + ], + validation_datasets: [ + { type: "validation", data_source_type: "file_id", file_id: "file-val-placeholder" }, + ], + hyper_parameters: { + n_epochs: 1, + n_rollouts: 4, + learning_rate: "1e-6", + eval_steps: 50, + ppo_mini_batch_size: 16, + kl_loss_coef: 0, + lr_scheduler_type: "cosine", + algorithm: "gspo", + batch_size: 64, + max_prompt_length: 15360, + max_length: 16384, + nnodes_training: 1, + nnodes_rollout: 1, + n_gpus_training: 4, + n_gpus_rollout: 2, + save_strategy: "steps", + save_steps: 50, + save_total_limit: 1, + lr_warmup_steps: -1, + tensor_model_parallel_size: 4, + inference_tensor_parallel_size: 2, + }, + resource_config: { charge_type: "mtu_postpaid", mtu_spec_code: "MTU4", mtu_capacity: 16 }, + job_name: "e2e-opd-baseline", + }); + }); + + test("opd run dry-run: --hp and resource flags override the JSON files", async () => { + const hyperFile = fileURLToPath( + new URL("./fixtures/opd-hyper-parameters.json", import.meta.url), + ); + const resourceFile = fileURLToPath( + new URL("./fixtures/opd-resource-config.json", import.meta.url), + ); + const { stdout, stderr, exitCode } = await runCommandInProcess(FINETUNE_ROUTES, [ + "finetune", + "opd", + "run", + "--base-model", + "qwen3.5-9b", + "--teacher-model", + "qwen3.8-flash", + "--datasets", + "file-train", + "--hyper-parameters-file", + hyperFile, + "--resource-config-file", + resourceFile, + "--hp", + "batch_size=128", + "--hp", + "opd_teacher_num_replicas=2", + "--mtu-count", + "24", + "--dry-run", + ...DUMMY_KEY, + "--output", + "json", + ]); + expect(exitCode, stderr).toBe(0); + const data = parseStdoutJson<{ + body: { + hyper_parameters: Record; + resource_config: Record; + }; + }>(stdout); + expect(data.body.hyper_parameters.batch_size).toBe(128); + expect(data.body.hyper_parameters.opd_teacher_num_replicas).toBe(2); + // Untouched file values survive the merge. + expect(data.body.hyper_parameters.max_length).toBe(16384); + expect(data.body.resource_config).toEqual({ + charge_type: "mtu_postpaid", + mtu_spec_code: "MTU4", + mtu_capacity: 24, + }); + }); + + test("opd run rejects a non-mtu charge_type flag with a usage error (2)", async () => { + const { stderr, exitCode } = await runCommandInProcess(FINETUNE_ROUTES, [ + "finetune", + "opd", + "run", + "--base-model", + "qwen3.5-9b", + "--teacher-model", + "qwen3.8-flash", + "--datasets", + "file-train", + "--charge-type", + "postpaid", + "--dry-run", + ...DUMMY_KEY, + "--output", + "json", + ]); + expect(exitCode).toBe(2); + expect(stderr).toMatch(/mtu_postpaid/); + }); + + test("opd run rejects a non-mtu charge_type from the resource file with a usage error (2)", async () => { + const root = mkdtempSync(join(tmpdir(), "bl-opd-charge-e2e-")); + const resourceFile = join(root, "resource.json"); + writeFileSync(resourceFile, JSON.stringify({ charge_type: "prepaid", mtu_capacity: 16 })); + try { + const { stderr, exitCode } = await runCommandInProcess(FINETUNE_ROUTES, [ + "finetune", + "opd", + "run", + "--base-model", + "qwen3.5-9b", + "--teacher-model", + "qwen3.8-flash", + "--datasets", + "file-train", + "--resource-config-file", + resourceFile, + "--dry-run", + ...DUMMY_KEY, + "--output", + "json", + ]); + expect(exitCode).toBe(2); + expect(stderr).toMatch(/mtu_postpaid/); + } finally { + rmSync(root, { recursive: true, force: true }); + } + }); + + test("opd run without MTU fields is a usage error before upload (2)", async () => { + const { stderr, exitCode } = await runCommandInProcess(FINETUNE_ROUTES, [ + "finetune", + "opd", + "run", + "--base-model", + "qwen3.5-9b", + "--teacher-model", + "qwen3.8-flash", + "--datasets", + "file-train", + "--dry-run", + ...DUMMY_KEY, + "--output", + "json", + ]); + expect(exitCode).toBe(2); + expect(stderr).toMatch(/mtu_spec_code/); + expect(stderr).toMatch(/mtu_capacity/); + }); + + test("opd run with --mtu-spec but no capacity is a usage error (2)", async () => { + const { stderr, exitCode } = await runCommandInProcess(FINETUNE_ROUTES, [ + "finetune", + "opd", + "run", + "--base-model", + "qwen3.5-9b", + "--teacher-model", + "qwen3.8-flash", + "--datasets", + "file-train", + "--mtu-spec", + "MTU4", + "--dry-run", + ...DUMMY_KEY, + "--output", + "json", + ]); + expect(exitCode).toBe(2); + expect(stderr).toMatch(/mtu_capacity/); + expect(stderr).not.toMatch(/mtu_spec_code/); + }); + + test("opd run rejects mismatched teacher TP and GPUs per node (2)", async () => { + const { stderr, exitCode } = await runCommandInProcess(FINETUNE_ROUTES, [ + "finetune", + "opd", + "run", + "--base-model", + "qwen3.5-9b", + "--teacher-model", + "qwen3.8-flash", + "--datasets", + "file-train", + "--mtu-spec", + "MTU4", + "--mtu-count", + "24", + "--hp", + "opd_teacher_infer_tp=4", + "--hp", + "opd_teacher_n_gpus_per_node=8", + "--dry-run", + ...DUMMY_KEY, + "--output", + "json", + ]); + expect(exitCode).toBe(2); + expect(stderr).toMatch(/opd_teacher_infer_tp/); + }); + + test("opd run accepts equal teacher TP and GPUs per node", async () => { + const { stdout, stderr, exitCode } = await runCommandInProcess(FINETUNE_ROUTES, [ + "finetune", + "opd", + "run", + "--base-model", + "qwen3.5-9b", + "--teacher-model", + "qwen3.8-flash", + "--datasets", + "file-train", + "--mtu-spec", + "MTU4", + "--mtu-count", + "24", + "--hp", + "opd_teacher_infer_tp=8", + "--hp", + "opd_teacher_n_gpus_per_node=8", + "--dry-run", + ...DUMMY_KEY, + "--output", + "json", + ]); + expect(exitCode, stderr).toBe(0); + expect(parseStdoutJson(stdout)).toMatchObject({ action: "finetune.opd.run" }); + }); + + test("opd run warns when student lengths exceed the explicit teacher limit", async () => { + const { stderr, exitCode } = await runCommandInProcess(FINETUNE_ROUTES, [ + "finetune", + "opd", + "run", + "--base-model", + "qwen3.5-9b", + "--teacher-model", + "qwen3.8-flash", + "--datasets", + "file-train", + "--mtu-spec", + "MTU4", + "--mtu-count", + "24", + "--hp", + "opd_teacher_max_model_len=16385", + "--hp", + "max_length=33792", + "--dry-run", + ...DUMMY_KEY, + "--output", + "json", + ]); + expect(exitCode).toBe(0); + expect(stderr).toMatch(/OPD_LENGTH_EXCEEDS_TEACHER/); + }); + + test("opd run warns when the student/teacher pair is not published", async () => { + const { stderr, exitCode } = await runCommandInProcess(FINETUNE_ROUTES, [ + "finetune", + "opd", + "run", + "--base-model", + "qwen3.5-9b", + "--teacher-model", + "qwen3.5-2b", + "--datasets", + "file-train", + "--mtu-spec", + "MTU4", + "--mtu-count", + "24", + "--dry-run", + ...DUMMY_KEY, + "--output", + "json", + ]); + expect(exitCode).toBe(0); + expect(stderr).toMatch(/OPD_PAIR_NOT_PUBLISHED/); + }); + + test("opd run rejects a zero-step configuration before upload (2)", async () => { + const trainFile = fileURLToPath(new URL("./fixtures/opd-train-12.jsonl", import.meta.url)); + const { stderr, exitCode } = await runCommandInProcess(FINETUNE_ROUTES, [ + "finetune", + "opd", + "run", + "--base-model", + "qwen3.5-9b", + "--teacher-model", + "qwen3.5-397b-a17b", + "--datasets", + trainFile, + "--mtu-spec", + "MTU4", + "--mtu-count", + "24", + "--hp", + "batch_size=64", + "--hp", + "n_epochs=1", + "--yes", + ...DUMMY_KEY, + "--output", + "json", + ]); + expect(exitCode).toBe(2); + expect(stderr).toMatch(/training steps/i); + expect(stderr).toMatch(/lr_decay_steps/); + expect(stderr).not.toMatch(/Uploaded/); + }); + + test("opd run rejects ppo_mini_batch_size above batch_size × n_rollouts (2)", async () => { + const { stderr, exitCode } = await runCommandInProcess(FINETUNE_ROUTES, [ + "finetune", + "opd", + "run", + "--base-model", + "qwen3.5-9b", + "--teacher-model", + "qwen3.5-397b-a17b", + "--datasets", + "file-train", + "--mtu-spec", + "MTU4", + "--mtu-count", + "24", + "--hp", + "batch_size=64", + "--hp", + "n_rollouts=4", + "--hp", + "ppo_mini_batch_size=300", + "--dry-run", + ...DUMMY_KEY, + "--output", + "json", + ]); + expect(exitCode).toBe(2); + expect(stderr).toMatch(/ppo_mini_batch_size/); + }); + + test("opd run warns when the sample count is unknown (file-id datasets)", async () => { + const { stderr, exitCode } = await runCommandInProcess(FINETUNE_ROUTES, [ + "finetune", + "opd", + "run", + "--base-model", + "qwen3.5-9b", + "--teacher-model", + "qwen3.5-397b-a17b", + "--datasets", + "file-train", + "--mtu-spec", + "MTU4", + "--mtu-count", + "24", + "--hp", + "batch_size=64", + "--hp", + "n_epochs=1", + "--dry-run", + ...DUMMY_KEY, + "--output", + "json", + ]); + expect(exitCode).toBe(0); + expect(stderr).toMatch(/OPD_BATCH_FIT_UNKNOWN/); + }); + + test("opd batch-fit helpers compute steps, minimum samples, and the mini-batch limit", async () => { + const { computeOpdBatchFit, opdMiniBatchLimit } = + await import("../../src/commands/finetune/opd-batch-fit.ts"); + expect(computeOpdBatchFit({ batch_size: 64, n_epochs: 1 }, 12)).toMatchObject({ + steps: 0, + requiredSamples: 64, + }); + expect(computeOpdBatchFit({ batch_size: 64, n_epochs: 1 }, 96)).toMatchObject({ + steps: 1, + requiredSamples: 64, + }); + expect(computeOpdBatchFit({ batch_size: 64, n_epochs: 3 }, 22)).toMatchObject({ + steps: 1, + requiredSamples: 22, + }); + expect( + computeOpdBatchFit( + { batch_size: "64", n_epochs: "1" } as unknown as Parameters[0], + 12, + ).steps, + ).toBe(0); + expect(computeOpdBatchFit({ batch_size: 64 }, 96).steps).toBeUndefined(); + expect(computeOpdBatchFit({ batch_size: 64 }, 96).requiredSamples).toBeUndefined(); + expect(computeOpdBatchFit({ batch_size: 64, n_epochs: 1 }).steps).toBeUndefined(); + expect(opdMiniBatchLimit({ ppo_mini_batch_size: 16, batch_size: 64, n_rollouts: 4 })).toEqual({ + miniBatchSize: 16, + limit: 256, + }); + expect(opdMiniBatchLimit({ ppo_mini_batch_size: 16, batch_size: 64 })).toBeUndefined(); + }); + + test("opd run emits warmup/interval warnings before the upload attempt", async () => { + // Loopback schema server: the batch-fit warnings must surface before any + // upload; the upload itself hits the mock 404 and fails (no real network). + const { createServer } = await import("node:http"); + const schemaRows = [ + "batch_size", + "n_epochs", + "eval_steps", + "save_steps", + "lr_warmup_steps", + ].map((name) => ({ + name, + type: "intInputNumber", + data_range: ["-1", "1000000"], + editable: true, + })); + const server = createServer((request, response) => { + const url = new URL(request.url ?? "/", "http://127.0.0.1"); + response.setHeader("content-type", "application/json"); + if (url.pathname === "/api/v1/fine-tunes/fine-tunes-params") { + response.end(JSON.stringify({ output: { hyper_params: schemaRows } })); + return; + } + response.statusCode = 404; + response.end('{"message":"unexpected path"}'); + }); + await new Promise((resolve, reject) => { + server.once("error", reject); + server.listen(0, "127.0.0.1", resolve); + }); + const address = server.address(); + if (!address || typeof address === "string") throw new Error("Expected a local TCP server."); + try { + const trainFile = fileURLToPath(new URL("./fixtures/opd-train-12.jsonl", import.meta.url)); + const { stderr, exitCode } = await runCommandInProcess( + FINETUNE_ROUTES, + [ + "finetune", + "opd", + "run", + "--base-model", + "qwen3.5-9b", + "--teacher-model", + "qwen3.5-397b-a17b", + "--datasets", + trainFile, + "--mtu-spec", + "MTU4", + "--mtu-count", + "24", + "--hp", + "batch_size=8", + "--hp", + "n_epochs=1", + "--hp", + "lr_warmup_steps=5", + "--hp", + "eval_steps=50", + "--hp", + "save_steps=50", + "--yes", + ...DUMMY_KEY, + "--output", + "json", + ], + { + DASHSCOPE_API_KEY: "offline-test-only", + DASHSCOPE_BASE_URL: `http://127.0.0.1:${address.port}`, + BAILIAN_WORKSPACE_ID: "", + NODE_OPTIONS: "", + HTTP_PROXY: "", + HTTPS_PROXY: "", + ALL_PROXY: "", + NO_PROXY: "", + http_proxy: "", + https_proxy: "", + all_proxy: "", + no_proxy: "", + NODE_USE_ENV_PROXY: "", + }, + ); + expect(exitCode).not.toBe(0); + expect(stderr).toMatch(/OPD_WARMUP_EXCEEDS_STEPS/); + expect(stderr).toMatch(/OPD_INTERVAL_EXCEEDS_STEPS/); + expect(stderr).not.toMatch(/Uploaded/); + } finally { + server.closeAllConnections(); + await new Promise((resolve) => server.close(() => resolve())); + } + }); + + test("opd params without --base-model is a usage error (2)", async () => { + const { stderr, exitCode } = await runCommandInProcess(FINETUNE_ROUTES, [ + "finetune", + "opd", + "params", + ...DUMMY_KEY, + "--output", + "json", + ]); + expect(exitCode).toBe(2); + expect(stderr).toMatch(/base-model/i); + }); + + test("opd params dry-run previews the pg_opd query without network", async () => { + const { stdout, stderr, exitCode } = await runCommandInProcess(FINETUNE_ROUTES, [ + "finetune", + "opd", + "params", + "--base-model", + "qwen3.5-9b", + "--param-type", + "resource", + "--mtu-spec-code", + "MTU4", + "--workspace-id", + "ws-e2e", + "--dry-run", + ...DUMMY_KEY, + "--output", + "json", + ]); + expect(exitCode, stderr).toBe(0); + expect(parseStdoutJson(stdout)).toMatchObject({ + action: "finetune.opd.params", + base_model: "qwen3.5-9b", + training_type: "pg_opd", + param_type: "resource", + mtu_spec_code: "MTU4", + workspace_id: "ws-e2e", + }); + }); + + test("opd get without --job-id is a usage error (2)", async () => { + const { stderr, exitCode } = await runCommandInProcess(FINETUNE_ROUTES, [ + "finetune", + "opd", + "get", + ...DUMMY_KEY, + "--output", + "json", + ]); + expect(exitCode).toBe(2); + expect(stderr).toMatch(/--job-id/); + }); + + test("opd get dry-run previews the job id under the opd action", async () => { + const { stdout, stderr, exitCode } = await runCommandInProcess(FINETUNE_ROUTES, [ + "finetune", + "opd", + "get", + "--job-id", + "ft-xxx", + "--dry-run", + ...DUMMY_KEY, + "--output", + "json", + ]); + expect(exitCode, stderr).toBe(0); + expect(parseStdoutJson(stdout)).toMatchObject({ + action: "finetune.opd.get", + job_id: "ft-xxx", + }); + }); + + test("opd get dry-run previews the workspace when provided", async () => { + const { stdout, stderr, exitCode } = await runCommandInProcess(FINETUNE_ROUTES, [ + "finetune", + "opd", + "get", + "--job-id", + "ft-xxx", + "--workspace-id", + "ws-e2e", + "--dry-run", + ...DUMMY_KEY, + "--output", + "json", + ]); + expect(exitCode, stderr).toBe(0); + expect(parseStdoutJson(stdout)).toMatchObject({ + action: "finetune.opd.get", + job_id: "ft-xxx", + workspace_id: "ws-e2e", + }); + }); + + test("opd watch dry-run defaults to a non-blocking probe", async () => { + const { stdout, stderr, exitCode } = await runCommandInProcess(FINETUNE_ROUTES, [ + "finetune", + "opd", + "watch", + "--job-id", + "ft-xxx", + "--dry-run", + ...DUMMY_KEY, + "--output", + "json", + ]); + expect(exitCode, stderr).toBe(0); + expect(parseStdoutJson(stdout)).toMatchObject({ + action: "finetune.opd.watch", + job_id: "ft-xxx", + follow: false, + interval: 10, + }); + }); + + test("opd logs dry-run previews page and page_size", async () => { + const { stdout, stderr, exitCode } = await runCommandInProcess(FINETUNE_ROUTES, [ + "finetune", + "opd", + "logs", + "--job-id", + "ft-xxx", + "--page", + "1", + "--page-size", + "100", + "--dry-run", + ...DUMMY_KEY, + "--output", + "json", + ]); + expect(exitCode, stderr).toBe(0); + expect(parseStdoutJson(stdout)).toMatchObject({ + action: "finetune.opd.logs", + job_id: "ft-xxx", + page: 1, + page_size: 100, + }); + }); + + test("opd cancel without --yes requires confirmation (7)", async () => { + const { stderr, exitCode } = await runCommandInProcess(FINETUNE_ROUTES, [ + "finetune", + "opd", + "cancel", + "--job-id", + "ft-xxx", + ...DUMMY_KEY, + "--output", + "json", + ]); + expect(exitCode).toBe(7); + expect(JSON.parse(stderr)).toMatchObject({ + error: { code: 7, type: "requires_confirmation" }, + }); + }); + + test("opd cancel dry-run previews the job id without confirmation", async () => { + const { stdout, stderr, exitCode } = await runCommandInProcess(FINETUNE_ROUTES, [ + "finetune", + "opd", + "cancel", + "--job-id", + "ft-xxx", + "--dry-run", + ...DUMMY_KEY, + "--output", + "json", + ]); + expect(exitCode, stderr).toBe(0); + expect(parseStdoutJson(stdout)).toMatchObject({ + action: "finetune.opd.cancel", + job_id: "ft-xxx", + }); + }); + + test("opd delete without --yes requires confirmation (7)", async () => { + const { stderr, exitCode } = await runCommandInProcess(FINETUNE_ROUTES, [ + "finetune", + "opd", + "delete", + "--job-id", + "ft-xxx", + ...DUMMY_KEY, + "--output", + "json", + ]); + expect(exitCode).toBe(7); + expect(JSON.parse(stderr)).toMatchObject({ + error: { code: 7, type: "requires_confirmation" }, + }); + }); + + test("opd delete dry-run previews the job id without confirmation", async () => { + const { stdout, stderr, exitCode } = await runCommandInProcess(FINETUNE_ROUTES, [ + "finetune", + "opd", + "delete", + "--job-id", + "ft-xxx", + "--dry-run", + ...DUMMY_KEY, + "--output", + "json", + ]); + expect(exitCode, stderr).toBe(0); + expect(parseStdoutJson(stdout)).toMatchObject({ + action: "finetune.opd.delete", + job_id: "ft-xxx", + }); + }); + + test("rl cancel without --yes requires confirmation (7)", async () => { + const { stderr, exitCode } = await runCommandInProcess(FINETUNE_ROUTES, [ + "finetune", + "rl", + "cancel", + "--job-id", + "rl-xxx", + ...DUMMY_KEY, + "--output", + "json", + ]); + expect(exitCode).toBe(7); + expect(JSON.parse(stderr)).toMatchObject({ + error: { code: 7, type: "requires_confirmation" }, + }); + }); + + test("rl cancel dry-run previews the job id without confirmation", async () => { + const { stdout, stderr, exitCode } = await runCommandInProcess(FINETUNE_ROUTES, [ + "finetune", + "rl", + "cancel", + "--job-id", + "rl-xxx", + "--dry-run", + ...DUMMY_KEY, + "--output", + "json", + ]); + expect(exitCode, stderr).toBe(0); + expect(parseStdoutJson(stdout)).toMatchObject({ + action: "finetune.rl.cancel", + job_id: "rl-xxx", + }); + }); + + test("rl watch dry-run defaults to a non-blocking probe", async () => { + const { stdout, stderr, exitCode } = await runCommandInProcess(FINETUNE_ROUTES, [ + "finetune", + "rl", + "watch", + "--job-id", + "ft-xxx", + "--dry-run", + ...DUMMY_KEY, + "--output", + "json", + ]); + expect(exitCode, stderr).toBe(0); + expect(parseStdoutJson(stdout)).toMatchObject({ + action: "finetune.rl.watch", + job_id: "ft-xxx", + follow: false, + interval: 10, + }); + }); + + test("rl watch dry-run previews follow polling without a default timeout", async () => { + const { stdout, stderr, exitCode } = await runCommandInProcess(FINETUNE_ROUTES, [ + "finetune", + "rl", + "watch", + "--job-id", + "ft-xxx", + "--follow", + "--interval", + "5", + "--dry-run", + ...DUMMY_KEY, + "--output", + "json", + ]); + expect(exitCode, stderr).toBe(0); + expect(parseStdoutJson(stdout)).toMatchObject({ + action: "finetune.rl.watch", + job_id: "ft-xxx", + follow: true, + interval: 5, + }); + }); + + test("rl list dry-run previews pagination", async () => { + const { stdout, stderr, exitCode } = await runCommandInProcess(FINETUNE_ROUTES, [ + "finetune", + "rl", + "list", + "--page", + "1", + "--size", + "20", + "--dry-run", + ...DUMMY_KEY, + "--output", + "json", + ]); + expect(exitCode, stderr).toBe(0); + expect(parseStdoutJson(stdout)).toMatchObject({ + action: "finetune.rl.list", + page: 1, + size: 20, + }); + }); + + test("rl authorize without --yes requires confirmation (7)", async () => { + const { stderr, exitCode } = await runCommandInProcess(FINETUNE_ROUTES, [ + "finetune", + "rl", + "authorize", + "--output", + "json", + ]); + expect(exitCode).toBe(7); + expect(JSON.parse(stderr)).toMatchObject({ + error: { code: 7, type: "requires_confirmation" }, + }); + }); + + test("rl authorize dry-run previews a read-only probe", async () => { + const { stdout, stderr, exitCode } = await runCommandInProcess(FINETUNE_ROUTES, [ + "finetune", + "rl", + "authorize", + "--dry-run", + "--output", + "json", + ]); + expect(exitCode, stderr).toBe(0); + expect(parseStdoutJson(stdout)).toMatchObject({ + action: "finetune.rl.authorize", + target: "rl", + authorize: false, + }); + }); + + test("opd authorize dry-run targets opd and stays read-only", async () => { + const { stdout, stderr, exitCode } = await runCommandInProcess(FINETUNE_ROUTES, [ + "finetune", + "opd", + "authorize", + "--dry-run", + "--output", + "json", + ]); + expect(exitCode, stderr).toBe(0); + expect(parseStdoutJson(stdout)).toMatchObject({ + action: "finetune.opd.authorize", + target: "opd", + authorize: false, + }); + }); + + test("runtime prepare dry-run previews the managed install plan", async () => { + const { stdout, stderr, exitCode } = await runCommandInProcess(FINETUNE_ROUTES, [ + "finetune", + "runtime", + "prepare", + "--dry-run", + "--output", + "json", + ]); + expect(exitCode, stderr).toBe(0); + expect(parseStdoutJson(stdout)).toMatchObject({ + action: "finetune.runtime.prepare", + override_env: "BAILIAN_RL_RUNTIME", + allow_install: true, + }); + }); + + test("runtime doctor dry-run previews the credential deny path", async () => { + const { stdout, stderr, exitCode } = await runCommandInProcess(FINETUNE_ROUTES, [ + "finetune", + "runtime", + "doctor", + "--dry-run", + "--output", + "json", + ]); + expect(exitCode, stderr).toBe(0); + const data = parseStdoutJson<{ + action: string; + credential_deny_paths: string[]; + }>(stdout); + expect(data.action).toBe("finetune.runtime.doctor"); + expect(data.credential_deny_paths.some((path) => path.endsWith(".dashscope"))).toBe(true); + }); +}); + +describe("e2e: finetune runtime clean (offline)", () => { + /** Exclusive temp config dir (the explicit BAILIAN_CONFIG_DIR is reused by the isolation infra); cleaned up in finally. */ + function seedCleanFixture() { + const root = mkdtempSync(join(tmpdir(), "bl-clean-e2e-")); + const configDir = join(root, "config"); + const oldRun = join(configDir, "runs", "old-run"); + const youngRun = join(configDir, "runs", "young-run"); + mkdirSync(oldRun, { recursive: true }); + mkdirSync(youngRun, { recursive: true }); + const aged = new Date(Date.now() - 25 * 3_600_000); + utimesSync(oldRun, aged, aged); + return { + configDir, + oldRun, + youngRun, + dispose: () => rmSync(root, { recursive: true, force: true }), + }; + } + + test("runtime clean help exposes --ttl-hours and the injected --yes", async () => { + const { stderr, exitCode } = await runCommandHelp(FINETUNE_ROUTES, [ + "finetune", + "runtime", + "clean", + "--help", + ]); + expect(exitCode, stderr).toBe(0); + expect(stderr).toMatch(/--ttl-hours/); + expect(stderr).toMatch(/--yes/); + expect(stderr).toMatch(/--dry-run/); + }); + + test("runtime clean without --yes requires confirmation (7)", async () => { + const { stderr, exitCode } = await runCommandInProcess(FINETUNE_ROUTES, [ + "finetune", + "runtime", + "clean", + "--output", + "json", + ]); + expect(exitCode).toBe(7); + expect(JSON.parse(stderr)).toMatchObject({ + error: { code: 7, type: "requires_confirmation" }, + }); + }); + + test("runtime clean rejects a non-positive --ttl-hours (2)", async () => { + const { stderr, exitCode } = await runCommandInProcess(FINETUNE_ROUTES, [ + "finetune", + "runtime", + "clean", + "--ttl-hours", + "0", + "--dry-run", + "--output", + "json", + ]); + expect(exitCode).toBe(2); + expect(stderr).toMatch(/ttl-hours/); + }); + + test("runtime clean dry-run previews the plan without deleting", async () => { + const fixture = seedCleanFixture(); + try { + const { stdout, stderr, exitCode } = await runCommandInProcess( + FINETUNE_ROUTES, + ["finetune", "runtime", "clean", "--dry-run", "--output", "json"], + { BAILIAN_CONFIG_DIR: fixture.configDir }, + ); + expect(exitCode, stderr).toBe(0); + expect(parseStdoutJson(stdout)).toMatchObject({ + action: "finetune.runtime.clean", + dryRun: true, + removedCount: 1, + }); + expect(existsSync(fixture.oldRun)).toBe(true); + expect(existsSync(fixture.youngRun)).toBe(true); + } finally { + fixture.dispose(); + } + }); + + test("runtime clean --yes enters run and removes only expired runs", async () => { + const fixture = seedCleanFixture(); + try { + const { stdout, stderr, exitCode } = await runCommandInProcess( + FINETUNE_ROUTES, + ["finetune", "runtime", "clean", "--yes", "--output", "json"], + { BAILIAN_CONFIG_DIR: fixture.configDir }, + ); + expect(exitCode, stderr).toBe(0); + const data = parseStdoutJson<{ + dryRun: boolean; + removedCount: number; + entries: { kind: string; action: string }[]; + }>(stdout); + expect(data.dryRun).toBe(false); + expect(data.removedCount).toBe(1); + expect(data.entries.every((entry) => entry.kind === "run")).toBe(true); + expect(existsSync(fixture.oldRun)).toBe(false); + expect(existsSync(fixture.youngRun)).toBe(true); + } finally { + fixture.dispose(); + } + }); +}); + +// Live RL/OPD execution needs a prepared sandbox runtime (BAILIAN_RL_RUNTIME or a +// reviewed manifest), an API key, a console token and an account whitelist. CI +// ships no bundled runtime, so these stay opt-in via BAILIAN_E2E_RL=1 and never +// create billed jobs by default. The read-only authorize probe below is the +// representative live integration; run/watch/list live cases additionally +// require BAILIAN_RL_RUNTIME to point at a local dashscope Python directory. +const rlLiveReady = + isDashScopeE2EReady() && isConsoleE2EReady() && process.env.BAILIAN_E2E_RL === "1"; + +describe.skipIf(!rlLiveReady)("e2e: finetune rl (live, opt-in)", () => { + test("rl authorize read-only probe reports capability states", async () => { + const { stdout, stderr, exitCode } = await runCommandInProcess(FINETUNE_ROUTES, [ + "finetune", + "rl", + "authorize", + "--yes", + "--output", + "json", + ]); + expect(exitCode, stderr).toBe(0); + const data = parseStdoutJson<{ target?: string }>(stdout); + expect(data.target).toBe("rl"); + }); +}); + +// OPD submission creates billed jobs and stays manual-acceptance only; the +// read-only parameter query is the representative live integration here. +describe.skipIf(!isDashScopeE2EReady())("e2e: finetune opd params (live, read-only)", () => { + test("opd params returns the pg_opd hyper schema for qwen3.5-9b", async () => { + const { stdout, stderr, exitCode } = await runCommandInProcess( + FINETUNE_ROUTES, + [ + "finetune", + "opd", + "params", + "--base-model", + "qwen3.5-9b", + "--param-type", + "hyper", + "--output", + "json", + ], + // The shared .env workspace may belong to a different primary account + // than the key; query the key's own workspace instead. + { BAILIAN_WORKSPACE_ID: "" }, + ); + expect(exitCode, stderr).toBe(0); + const data = parseStdoutJson<{ output?: { hyper_params?: Array<{ name?: string }> } }>(stdout); + expect(Array.isArray(data.output?.hyper_params)).toBe(true); + expect(data.output?.hyper_params?.length ?? 0).toBeGreaterThan(0); + }); +}); diff --git a/packages/commands/tests/e2e/fixtures/opd-hyper-parameters.json b/packages/commands/tests/e2e/fixtures/opd-hyper-parameters.json new file mode 100644 index 00000000..2bb06a8e --- /dev/null +++ b/packages/commands/tests/e2e/fixtures/opd-hyper-parameters.json @@ -0,0 +1,23 @@ +{ + "n_epochs": 1, + "n_rollouts": 4, + "learning_rate": "1e-6", + "eval_steps": 50, + "ppo_mini_batch_size": 16, + "kl_loss_coef": 0.0, + "lr_scheduler_type": "cosine", + "algorithm": "gspo", + "batch_size": 64, + "max_prompt_length": 15360, + "max_length": 16384, + "nnodes_training": 1, + "nnodes_rollout": 1, + "n_gpus_training": 4, + "n_gpus_rollout": 2, + "save_strategy": "steps", + "save_steps": 50, + "save_total_limit": 1, + "lr_warmup_steps": -1, + "tensor_model_parallel_size": 4, + "inference_tensor_parallel_size": 2 +} diff --git a/packages/commands/tests/e2e/fixtures/opd-resource-config.json b/packages/commands/tests/e2e/fixtures/opd-resource-config.json new file mode 100644 index 00000000..c0fa7911 --- /dev/null +++ b/packages/commands/tests/e2e/fixtures/opd-resource-config.json @@ -0,0 +1,5 @@ +{ + "charge_type": "mtu_postpaid", + "mtu_spec_code": "MTU4", + "mtu_capacity": 16 +} diff --git a/packages/commands/tests/e2e/fixtures/opd-train-12.jsonl b/packages/commands/tests/e2e/fixtures/opd-train-12.jsonl new file mode 100644 index 00000000..217723df --- /dev/null +++ b/packages/commands/tests/e2e/fixtures/opd-train-12.jsonl @@ -0,0 +1,12 @@ +{"messages":[{"role":"system","content":"你是一个意图分类器。请判断用户输入属于以下哪个意图,只输出意图标签本身,不要输出其他内容。可选标签:查询天气、播放音乐、设置闹钟、闲聊。"},{"role":"user","content":"明天上海会下雨吗?"}],"rollout_extra":{"solution":"查询天气"}} +{"messages":[{"role":"system","content":"你是一个意图分类器。请判断用户输入属于以下哪个意图,只输出意图标签本身,不要输出其他内容。可选标签:查询天气、播放音乐、设置闹钟、闲聊。"},{"role":"user","content":"帮我放一首周杰伦的歌。"}],"rollout_extra":{"solution":"播放音乐"}} +{"messages":[{"role":"system","content":"你是一个意图分类器。请判断用户输入属于以下哪个意图,只输出意图标签本身,不要输出其他内容。可选标签:查询天气、播放音乐、设置闹钟、闲聊。"},{"role":"user","content":"早上七点半叫我起床。"}],"rollout_extra":{"solution":"设置闹钟"}} +{"messages":[{"role":"system","content":"你是一个意图分类器。请判断用户输入属于以下哪个意图,只输出意图标签本身,不要输出其他内容。可选标签:查询天气、播放音乐、设置闹钟、闲聊。"},{"role":"user","content":"今天心情不太好,想找人聊聊天。"}],"rollout_extra":{"solution":"闲聊"}} +{"messages":[{"role":"system","content":"你是一个意图分类器。请判断用户输入属于以下哪个意图,只输出意图标签本身,不要输出其他内容。可选标签:查询天气、播放音乐、设置闹钟、闲聊。"},{"role":"user","content":"北京这周末气温多少度?"}],"rollout_extra":{"solution":"查询天气"}} +{"messages":[{"role":"system","content":"你是一个意图分类器。请判断用户输入属于以下哪个意图,只输出意图标签本身,不要输出其他内容。可选标签:查询天气、播放音乐、设置闹钟、闲聊。"},{"role":"user","content":"来点轻音乐,我想放松一下。"}],"rollout_extra":{"solution":"播放音乐"}} +{"messages":[{"role":"system","content":"你是一个意图分类器。请判断用户输入属于以下哪个意图,只输出意图标签本身,不要输出其他内容。可选标签:查询天气、播放音乐、设置闹钟、闲聊。"},{"role":"user","content":"提醒我二十分钟后关火。"}],"rollout_extra":{"solution":"设置闹钟"}} +{"messages":[{"role":"system","content":"你是一个意图分类器。请判断用户输入属于以下哪个意图,只输出意图标签本身,不要输出其他内容。可选标签:查询天气、播放音乐、设置闹钟、闲聊。"},{"role":"user","content":"你觉得人生的意义是什么?"}],"rollout_extra":{"solution":"闲聊"}} +{"messages":[{"role":"system","content":"你是一个意图分类器。请判断用户输入属于以下哪个意图,只输出意图标签本身,不要输出其他内容。可选标签:查询天气、播放音乐、设置闹钟、闲聊。"},{"role":"user","content":"杭州现在外面冷不冷,要不要带外套?"}],"rollout_extra":{"solution":"查询天气"}} +{"messages":[{"role":"system","content":"你是一个意图分类器。请判断用户输入属于以下哪个意图,只输出意图标签本身,不要输出其他内容。可选标签:查询天气、播放音乐、设置闹钟、闲聊。"},{"role":"user","content":"把刚才那首歌再循环播放一遍。"}],"rollout_extra":{"solution":"播放音乐"}} +{"messages":[{"role":"system","content":"你是一个意图分类器。请判断用户输入属于以下哪个意图,只输出意图标签本身,不要输出其他内容。可选标签:查询天气、播放音乐、设置闹钟、闲聊。"},{"role":"user","content":"每天晚上十一点提醒我睡觉。"}],"rollout_extra":{"solution":"设置闹钟"}} +{"messages":[{"role":"system","content":"你是一个意图分类器。请判断用户输入属于以下哪个意图,只输出意图标签本身,不要输出其他内容。可选标签:查询天气、播放音乐、设置闹钟、闲聊。"},{"role":"user","content":"给我讲个笑话吧。"}],"rollout_extra":{"solution":"闲聊"}} \ No newline at end of file diff --git a/packages/commands/tests/e2e/topic-routes.ts b/packages/commands/tests/e2e/topic-routes.ts index 94bc55fc..d7ce3a3e 100644 --- a/packages/commands/tests/e2e/topic-routes.ts +++ b/packages/commands/tests/e2e/topic-routes.ts @@ -339,6 +339,25 @@ export const FINETUNE_ROUTES: E2eRouteExports = { "finetune compress logs": "finetuneCompressLogs", "finetune compress cancel": "finetuneCompressCancel", "finetune compress delete": "finetuneCompressDelete", + "finetune rl authorize": "finetuneRlAuthorize", + "finetune rl run": "finetuneRlRun", + "finetune rl get": "finetuneRlGet", + "finetune rl list": "finetuneRlList", + "finetune rl watch": "finetuneRlWatch", + "finetune rl logs": "finetuneRlLogs", + "finetune rl cancel": "finetuneRlCancel", + "finetune rl delete": "finetuneRlDelete", + "finetune opd authorize": "finetuneOpdAuthorize", + "finetune opd run": "finetuneOpdRun", + "finetune opd params": "finetuneOpdParams", + "finetune opd get": "finetuneOpdGet", + "finetune opd watch": "finetuneOpdWatch", + "finetune opd logs": "finetuneOpdLogs", + "finetune opd cancel": "finetuneOpdCancel", + "finetune opd delete": "finetuneOpdDelete", + "finetune runtime prepare": "finetuneRuntimePrepare", + "finetune runtime doctor": "finetuneRuntimeDoctor", + "finetune runtime clean": "finetuneRuntimeClean", }; export const CONSOLE_FLAGS_DRY_RUN_ROUTES: E2eRouteExports = { diff --git a/packages/commands/tests/output/finetune-capability-output.test.ts b/packages/commands/tests/output/finetune-capability-output.test.ts new file mode 100644 index 00000000..5b3b512b --- /dev/null +++ b/packages/commands/tests/output/finetune-capability-output.test.ts @@ -0,0 +1,152 @@ +import { afterEach, beforeEach, expect, test, vi } from "vite-plus/test"; +import { buildSettings, Client, httpTransport, type LocalizedText } from "bailian-cli-core"; +import { createOutputReporter } from "bailian-cli-runtime"; +import * as commands from "../../src/index.ts"; + +const identity = { binName: "bl", version: "test", clientName: "test", npmPackage: "test" }; + +// Training-only base model: absent from the inference catalog, present when scoped. +const trainingOnly = { + model: "qwen3-8b", + name: "Qwen3 8B", + supports: { sft: true, fineTune: true, inference: false }, + trainingTypes: { sft: ["full", "lora"] }, +}; +// LoRA-only image model: trainable, but not full-parameter SFT. +const loraOnly = { + model: "qwen-image-2.0", + name: "Qwen Image 2.0", + supports: { sft: true, fineTune: true, inference: true }, + trainingTypes: { sft: ["lora"] }, +}; +// Inference flagship: not trainable, only in the default inference catalog. +const inferenceOnly = { + model: "qwen3.8-max", + name: "Qwen3.8 Max", + supports: { inference: true, fineTune: false }, +}; +const trainableCatalog = [trainingOnly, loraOnly]; +const inferenceCatalog = [loraOnly, inferenceOnly]; + +let inputs: Record[]; +beforeEach(() => { + inputs = []; + vi.stubEnv("NO_COLOR", "1"); + vi.spyOn(httpTransport, "fetch").mockImplementation(async (_input, init) => { + const raw = typeof init?.body === "string" ? init.body : ""; + const encoded = new URLSearchParams(raw).get("params"); + const params = JSON.parse(encoded ?? "{}") as { + Api: string; + Data: { input: Record }; + }; + const input = params.Data.input; + inputs.push(input); + // Simulate the server-side capability scope: fineTune returns the trainable + // universe; the default (unscoped) query returns the inference catalog. + const supports = input.supports as Record | undefined; + const list = supports?.fineTune ? trainableCatalog : inferenceCatalog; + return Response.json({ data: { total: list.length, list } }); + }); +}); +afterEach(() => { + vi.restoreAllMocks(); + vi.unstubAllEnvs(); +}); + +async function invoke(flags: Record) { + let stdout = "", + stderr = "", + strayOut = "", + strayErr = ""; + const outSpy = vi.spyOn(process.stdout, "write").mockImplementation((chunk) => { + strayOut += String(chunk); + return true; + }); + const errSpy = vi.spyOn(process.stderr, "write").mockImplementation((chunk) => { + strayErr += String(chunk); + return true; + }); + const settings = buildSettings({ + flags: { output: "json", quiet: true }, + file: { language: "en-US" }, + env: {}, + configPath: "/tmp/finetune-capability-no-config/config.json", + }); + const localize = (text: LocalizedText) => (typeof text === "string" ? text : text["en-US"]); + const reporter = createOutputReporter({ + settings, + localize, + stdout: { write: (chunk) => (stdout += chunk) }, + stderr: { write: (chunk) => (stderr += chunk) }, + }); + const client = new Client({ + identity, + settings, + baseUrl: "https://fixture.invalid", + apiCred: { token: "fixture-api-token", source: "flag", baseUrl: "https://fixture.invalid" }, + }); + let exitCode = 0; + try { + try { + await commands.finetuneCapability.run({ + identity, + flags, + settings, + client, + localize, + output: reporter.output, + } as never); + } catch (error) { + exitCode = reporter.error(error); + } + return { stdout, stderr, strayOut, strayErr, exitCode }; + } finally { + outSpy.mockRestore(); + errSpy.mockRestore(); + } +} + +test("--training-type sft queries the trainable catalog and keeps full-parameter semantics", async () => { + const result = await invoke({ trainingType: "sft" }); + expect(result.exitCode, result.stderr).toBe(0); + expect(result.strayOut + result.strayErr).toBe(""); + // The fix: capability queries scope the catalog by fineTune. + expect(inputs.length).toBeGreaterThan(0); + for (const input of inputs) expect(input.supports).toEqual({ fineTune: true }); + const data = JSON.parse(result.stdout) as { + training_type: string; + count: number; + models: { model: string }[]; + }; + expect(data.training_type).toBe("sft"); + // qwen3-8b (training-only) now appears; qwen-image-2.0 stays excluded (lora-only). + expect(data.models.map((model) => model.model)).toEqual(["qwen3-8b"]); + expect(data.count).toBe(1); +}); + +test("--training-type sft-lora includes lora-only models", async () => { + const result = await invoke({ trainingType: "sft-lora" }); + expect(result.exitCode, result.stderr).toBe(0); + for (const input of inputs) expect(input.supports).toEqual({ fineTune: true }); + const data = JSON.parse(result.stdout) as { models: { model: string }[] }; + expect(data.models.map((model) => model.model)).toEqual(["qwen-image-2.0", "qwen3-8b"]); +}); + +test("--base-model finds a training-only base model in the trainable catalog", async () => { + const result = await invoke({ baseModel: "qwen3-8b" }); + expect(result.exitCode, result.stderr).toBe(0); + expect(inputs[0]?.supports).toEqual({ fineTune: true }); + expect(inputs[0]?.name).toBe("qwen3-8b"); + const data = JSON.parse(result.stdout) as { model: string; supported: string[] }; + expect(data.model).toBe("qwen3-8b"); + expect(data.supported).toEqual(["sft", "sft-lora"]); +}); + +test("--base-model reports not-found for a non-trainable inference model", async () => { + const result = await invoke({ baseModel: "qwen3.8-max" }); + expect(result.exitCode, result.stderr).toBe(0); + expect(inputs[0]?.supports).toEqual({ fineTune: true }); + const data = JSON.parse(result.stdout) as { model: string; error?: string }; + expect(data.model).toBe("qwen3.8-max"); + expect(data.error).toContain("No foundation model found"); +}); diff --git a/packages/commands/tests/output/fixtures/training-deployment.json b/packages/commands/tests/output/fixtures/training-deployment.json index 855f08d4..6e70eb3d 100644 --- a/packages/commands/tests/output/fixtures/training-deployment.json +++ b/packages/commands/tests/output/fixtures/training-deployment.json @@ -853,5 +853,93 @@ "body": null } ] + }, + "finetune opd get": { + "data": { + "request_id": "request-fixture", + "output": { + "job_id": "ft-opd-fixture", + "job_name": "opd-fixture", + "model": "qwen3.5-9b", + "status": "SUCCEEDED", + "training_type": "pg_opd", + "teacher_model": "qwen3.8-flash", + "training_datasets": [ + { + "type": "training", + "data_source_type": "file_id", + "file_id": "file-train" + } + ], + "validation_datasets": [ + { + "type": "validation", + "data_source_type": "file_id", + "file_id": "file-val" + } + ], + "mtu_spec_code": "MTU4", + "mtu_capacity": 16, + "hyper_parameters": { + "n_epochs": 1 + }, + "usage": 0 + } + }, + "requests": [ + { + "url": "https://fixture.invalid/api/v1/fine-tunes/ft-opd-fixture", + "method": "GET", + "body": null + } + ], + "stdout": "{\n \"request_id\": \"request-fixture\",\n \"output\": {\n \"job_id\": \"ft-opd-fixture\",\n \"job_name\": \"opd-fixture\",\n \"model\": \"qwen3.5-9b\",\n \"status\": \"SUCCEEDED\",\n \"training_type\": \"pg_opd\",\n \"teacher_model\": \"qwen3.8-flash\",\n \"training_datasets\": [\n {\n \"type\": \"training\",\n \"data_source_type\": \"file_id\",\n \"file_id\": \"file-train\"\n }\n ],\n \"validation_datasets\": [\n {\n \"type\": \"validation\",\n \"data_source_type\": \"file_id\",\n \"file_id\": \"file-val\"\n }\n ],\n \"mtu_spec_code\": \"MTU4\",\n \"mtu_capacity\": 16,\n \"hyper_parameters\": {\n \"n_epochs\": 1\n },\n \"usage\": 0\n }\n}\n" + }, + "finetune get opd projection": { + "data": { + "job_id": "ft-opd-fixture", + "job_name": "opd-fixture", + "priority": "", + "hyper_parameters": { + "n_epochs": 1 + }, + "max_output_cnt": null, + "base_model": "qwen3.5-9b", + "status": "SUCCEEDED", + "training_type": "pg_opd", + "hyper_params": "n_epochs=1", + "output_model": "", + "model_name": "", + "created_at": "", + "updated_at": "", + "usage_tokens": 0, + "charge_type": "", + "teacher_model": "qwen3.8-flash", + "training_datasets": [ + { + "type": "training", + "data_source_type": "file_id", + "file_id": "file-train" + } + ], + "validation_datasets": [ + { + "type": "validation", + "data_source_type": "file_id", + "file_id": "file-val" + } + ], + "mtu_spec_code": "MTU4", + "mtu_capacity": 16, + "request_id": "request-fixture" + }, + "requests": [ + { + "url": "https://fixture.invalid/api/v1/fine-tunes/ft-opd-fixture", + "method": "GET", + "body": null + } + ], + "stdout": "{\n \"job_id\": \"ft-opd-fixture\",\n \"job_name\": \"opd-fixture\",\n \"priority\": \"\",\n \"hyper_parameters\": {\n \"n_epochs\": 1\n },\n \"max_output_cnt\": null,\n \"base_model\": \"qwen3.5-9b\",\n \"status\": \"SUCCEEDED\",\n \"training_type\": \"pg_opd\",\n \"hyper_params\": \"n_epochs=1\",\n \"output_model\": \"\",\n \"model_name\": \"\",\n \"created_at\": \"\",\n \"updated_at\": \"\",\n \"usage_tokens\": 0,\n \"charge_type\": \"\",\n \"teacher_model\": \"qwen3.8-flash\",\n \"training_datasets\": [\n {\n \"type\": \"training\",\n \"data_source_type\": \"file_id\",\n \"file_id\": \"file-train\"\n }\n ],\n \"validation_datasets\": [\n {\n \"type\": \"validation\",\n \"data_source_type\": \"file_id\",\n \"file_id\": \"file-val\"\n }\n ],\n \"mtu_spec_code\": \"MTU4\",\n \"mtu_capacity\": 16,\n \"request_id\": \"request-fixture\"\n}\n" } } diff --git a/packages/commands/tests/output/training-deployment-output.test.ts b/packages/commands/tests/output/training-deployment-output.test.ts index 1e5d096b..484406b1 100644 --- a/packages/commands/tests/output/training-deployment-output.test.ts +++ b/packages/commands/tests/output/training-deployment-output.test.ts @@ -45,6 +45,20 @@ const job = { output_model: "trained-fixture", ...retained, }; +const opdJob = { + job_id: "ft-opd-fixture", + job_name: "opd-fixture", + model: "qwen3.5-9b", + status: "SUCCEEDED", + training_type: "pg_opd", + teacher_model: "qwen3.8-flash", + training_datasets: [{ type: "training", data_source_type: "file_id", file_id: "file-train" }], + validation_datasets: [{ type: "validation", data_source_type: "file_id", file_id: "file-val" }], + mtu_spec_code: "MTU4", + mtu_capacity: 16, + hyper_parameters: { n_epochs: 1 }, + usage: 0, +}; const deployment = { deployed_model: "deploy-fixture", status: "RUNNING", @@ -408,6 +422,18 @@ const scenarios: Scenario[] = [ response: trainingParameters, dryRun: true, }, + { + name: "finetune opd get", + command: commands.finetuneOpdGet, + flags: { jobId: "ft-opd-fixture" }, + response: { request_id: "request-fixture", output: opdJob }, + }, + { + name: "finetune get opd projection", + command: commands.finetuneGet, + flags: { jobId: "ft-opd-fixture" }, + response: { request_id: "request-fixture", output: opdJob }, + }, ]; const displays = ["json", "text"].flatMap((format) => [false, true].flatMap((quiet) => diff --git a/packages/core/package.json b/packages/core/package.json index c89420ad..b95e45fe 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "bailian-cli-core", - "version": "2.10.3", + "version": "2.10.4", "description": "Core SDK for bailian-cli. See https://www.npmjs.com/package/bailian-cli for usage.", "homepage": "https://bailian.console.aliyun.com/cli", "bugs": { diff --git a/packages/core/src/client/console-session.ts b/packages/core/src/client/console-session.ts index 1ab6e85e..10d525b5 100644 --- a/packages/core/src/client/console-session.ts +++ b/packages/core/src/client/console-session.ts @@ -54,46 +54,42 @@ export class ConsoleSession { } async request(api: string, data: Record): Promise { + return this.dispatch( + (credential) => + callConsoleGateway( + credential, + this.deps.settings.timeout, + { api, data }, + { debug: this.deps.debug, recoveryHint: this.deps.consoleRecoveryHint }, + ) as Promise, + ); + } + + /** Shared credential lifecycle: lazy issuance and expired-session refresh. */ + private async dispatch(invoke: (credential: ConsoleCredential) => Promise): Promise { const credential = this.deps.consoleCred; if (!credential) { const failure = new BailianError("This command needs a console access token.", ExitCode.AUTH); if (!this.deps.resolveConsoleOpenApiCredential) throw failure; - return this.refreshConsole(api, data, failure); + return this.refreshConsole(invoke, failure); } try { - return await this.requestConsole(credential, api, data); + return await invoke(credential); } catch (error) { if (!(error instanceof CredentialError) || error.reason !== "expired-console-session") throw error; - return this.refreshConsole(api, data, error, credential); + return this.refreshConsole(invoke, error, credential); } } - private async requestConsole( - credential: ConsoleCredential, - api: string, - data: Record, - ): Promise { - return (await callConsoleGateway( - credential, - this.deps.settings.timeout, - { api, data }, - { - debug: this.deps.debug, - recoveryHint: this.deps.consoleRecoveryHint, - }, - )) as T; - } - /** Share issuance only; every caller retries and validates its own business request. */ private async refreshConsole( - api: string, - data: Record, + invoke: (credential: ConsoleCredential) => Promise, failure: BailianError, previous?: ConsoleCredential, ): Promise { if (this.deps.consoleCred && this.deps.consoleCred !== previous) - return this.requestConsole(this.deps.consoleCred, api, data); + return invoke(this.deps.consoleCred); let refresh = this.consoleRefresh; if (!refresh || refresh.previous !== previous) { @@ -108,7 +104,7 @@ export class ConsoleSession { throw error; }); if (!exchange) throw failure; - const result = await this.requestConsole(exchange.credential, api, data); + const result = await invoke(exchange.credential); refresh.commit ??= (async () => { if (this.deps.consoleCred !== previous) return; if (exchange.persist) diff --git a/packages/core/src/client/index.ts b/packages/core/src/client/index.ts index 035d9e76..b6f46602 100644 --- a/packages/core/src/client/index.ts +++ b/packages/core/src/client/index.ts @@ -151,3 +151,9 @@ export { export type { ServerSentEvent } from "./stream.ts"; export { parseSSE } from "./stream.ts"; export { httpTransport } from "./transport.ts"; +export { + networkCauseCode, + isSandboxNetworkDenialCode, + probeTcpHost, + SANDBOX_NETWORK_HINT, +} from "./network-diagnostics.ts"; diff --git a/packages/core/src/client/network-diagnostics.ts b/packages/core/src/client/network-diagnostics.ts new file mode 100644 index 00000000..8fb0463e --- /dev/null +++ b/packages/core/src/client/network-diagnostics.ts @@ -0,0 +1,50 @@ +/** + * Network failure diagnostics: extract errno from the fetch cause chain and recognize sandbox network-denial signatures. + * + * When an agent host sandbox (e.g. Codex's default workspace-write) disables outbound network, connect fails immediately + * with EPERM/EACCES/ENETUNREACH/EHOSTUNREACH — this is not a regional network issue and mirrors cannot fix it; + * the hint must guide toward enabling network or using an egress proxy, never mislead the user into switching sources. + */ + +import { connect as netConnect } from "node:net"; + +/** Typical errno of sandbox-blocked outbound network (connect fails immediately, not a timeout/reset). */ +const SANDBOX_DENIAL_CODES = new Set(["EPERM", "EACCES", "ENETUNREACH", "EHOSTUNREACH"]); + +/** Take the first string errno along the cause chain (undici wraps connect errors inside TypeError.cause). */ +export function networkCauseCode(error: unknown): string | undefined { + let current: unknown = error; + for (let depth = 0; depth < 5 && current != null; depth += 1) { + const code = (current as NodeJS.ErrnoException).code; + if (typeof code === "string" && code.length > 0) return code; + current = (current as { cause?: unknown }).cause; + } + return undefined; +} + +/** Whether the code is a sandbox network-denial signature (EPERM/EACCES/ENETUNREACH/EHOSTUNREACH). */ +export function isSandboxNetworkDenialCode(code: string | undefined): boolean { + return code !== undefined && SANDBOX_DENIAL_CODES.has(code); +} + +/** Core-layer sandbox-block guidance (abstract actions; no product command names or URLs). */ +export const SANDBOX_NETWORK_HINT = + "The execution environment (for example an AI agent sandbox) may be blocking outbound network. Enable network access for this process in the agent settings, or run the command in a regular terminal. If an egress proxy is required, set HTTPS_PROXY."; + +/** TCP reachability probe: undefined on success, errno on failure (used by the doctor host network preflight). */ +export function probeTcpHost( + host: string, + port: number, + timeoutMs: number, +): Promise { + return new Promise((resolve) => { + const socket = netConnect({ host, port }); + const finish = (code?: string) => { + socket.destroy(); + resolve(code); + }; + socket.setTimeout(timeoutMs, () => finish("ETIMEDOUT")); + socket.once("connect", () => finish(undefined)); + socket.once("error", (error: NodeJS.ErrnoException) => finish(error.code ?? "UNKNOWN")); + }); +} diff --git a/packages/core/src/console/gateway.ts b/packages/core/src/console/gateway.ts index 7ffbe5bc..6f46b779 100644 --- a/packages/core/src/console/gateway.ts +++ b/packages/core/src/console/gateway.ts @@ -88,6 +88,23 @@ export function anonymousConsoleCall( ); } +function buildCornerstoneParam( + data: Record, + switchAgent?: number, +): Record { + return { + protocol: "V2", + console: "ONE_CONSOLE", + productCode: "p_efm", + switchUserType: 3, + consoleSite: "BAILIAN_ALIYUN", + ...(switchAgent != null ? { switchAgent } : {}), + ...(typeof data.cornerstoneParam === "object" && data.cornerstoneParam !== null + ? (data.cornerstoneParam as Record) + : {}), + }; +} + function buildGatewayParams( api: string, data: Record, @@ -98,17 +115,7 @@ function buildGatewayParams( V: "1.0", Data: { ...data, - cornerstoneParam: { - protocol: "V2", - console: "ONE_CONSOLE", - productCode: "p_efm", - switchUserType: 3, - consoleSite: "BAILIAN_ALIYUN", - ...(switchAgent != null ? { switchAgent } : {}), - ...(typeof data.cornerstoneParam === "object" && data.cornerstoneParam !== null - ? (data.cornerstoneParam as Record) - : {}), - }, + cornerstoneParam: buildCornerstoneParam(data, switchAgent), }, }); } @@ -156,7 +163,14 @@ export async function callConsoleGateway( }); debugResponse(options, res); + return interpretGatewayResponse(res, options); +} +/** Shared HTTP + business-error interpretation for the console gateway. */ +async function interpretGatewayResponse( + res: Response, + options: Pick & { recoveryHint?: string }, +): Promise { if (!res.ok) { const t = await res.text().catch(() => ""); throw new BailianError( diff --git a/packages/core/src/console/models.ts b/packages/core/src/console/models.ts index 8610413b..0a1c78c0 100644 --- a/packages/core/src/console/models.ts +++ b/packages/core/src/console/models.ts @@ -32,6 +32,12 @@ export interface ModelListParams { name?: string; providers?: string[]; capabilities?: string[]; + /** + * Server-side capability scope, e.g. `{ fineTune: true }` for the trainable + * catalog. Omitted by default, which returns the inference-scoped catalog; + * training-only base models and their snapshots only appear when scoped. + */ + supports?: Record; } export interface ModelListResult { @@ -44,21 +50,29 @@ export async function fetchModelList( call: ConsoleCall, params: ModelListParams = {}, ): Promise { - const { pageNo = 1, pageSize = 50, name = "", providers = [], capabilities = [] } = params; + const { + pageNo = 1, + pageSize = 50, + name = "", + providers = [], + capabilities = [], + supports, + } = params; - const result = (await call(MODEL_LIST_API, { - input: { - pageNo, - pageSize, - name, - providers, - inferenceProviders: [], - features: [], - group: true, - capabilities, - contextWindows: [], - }, - })) as Record; + const input: Record = { + pageNo, + pageSize, + name, + providers, + inferenceProviders: [], + features: [], + group: true, + capabilities, + contextWindows: [], + }; + if (supports) input.supports = supports; + + const result = (await call(MODEL_LIST_API, { input })) as Record; const responseData = unwrapResponse(result); const total = (responseData.total as number) ?? 0; @@ -102,8 +116,9 @@ export async function fetchModelListAll( export async function findModelByName( call: ConsoleCall, modelName: string, + supports?: Record, ): Promise | null> { - const result = await fetchModelList(call, { name: modelName, pageSize: 50 }); + const result = await fetchModelList(call, { name: modelName, pageSize: 50, supports }); return result.models.find((item) => item.model === modelName) ?? null; } diff --git a/packages/core/src/dataset/api.ts b/packages/core/src/dataset/api.ts index df21054d..8dc4de1b 100644 --- a/packages/core/src/dataset/api.ts +++ b/packages/core/src/dataset/api.ts @@ -32,6 +32,8 @@ export interface DatasetUploadParams { purpose?: string; /** 已由调用方校验的不可变字节;提供时不再读取 filePath。 */ fileBlob?: Blob; + /** Sent as X-DashScope-WorkSpace; omit when the API key is workspace-bound. */ + workspaceId?: string; signal?: AbortSignal; } @@ -62,6 +64,7 @@ export async function uploadDataset( path: datasetUploadPath(), method: "POST", body: form, + headers: params.workspaceId ? { "X-DashScope-WorkSpace": params.workspaceId } : undefined, signal, }); diff --git a/packages/core/src/finetune/api.ts b/packages/core/src/finetune/api.ts index 0de254fe..32bb6090 100644 --- a/packages/core/src/finetune/api.ts +++ b/packages/core/src/finetune/api.ts @@ -29,16 +29,23 @@ import type { ListBasicMetricsResponse, } from "./types.ts"; +/** Optional workspace header; undefined means the API key's bound workspace. */ +function workspaceHeaders(workspaceId?: string): Record | undefined { + return workspaceId ? { "X-DashScope-WorkSpace": workspaceId } : undefined; +} + /** POST /api/v1/fine-tunes */ export async function createFineTune( client: Client, body: CreateFineTuneRequest, signal?: AbortSignal, + workspaceId?: string, ): Promise { return client.requestJson({ path: finetuneJobsPath(), method: "POST", body, + headers: workspaceHeaders(workspaceId), signal, }); } @@ -49,6 +56,8 @@ export interface ListFineTunesParams { status?: string; /** Filter by base model ID (server-side). */ model?: string; + /** Sent as X-DashScope-WorkSpace; use the job's owning workspace. */ + workspaceId?: string; signal?: AbortSignal; } @@ -67,6 +76,7 @@ export async function listFineTunes( return client.requestJson({ path, method: "GET", + headers: workspaceHeaders(params.workspaceId), signal: params.signal, }); } @@ -76,10 +86,12 @@ export async function getFineTune( client: Client, jobId: string, signal?: AbortSignal, + workspaceId?: string, ): Promise { return client.requestJson({ path: finetuneJobPath(jobId), method: "GET", + headers: workspaceHeaders(workspaceId), signal, }); } @@ -89,10 +101,12 @@ export async function cancelFineTune( client: Client, jobId: string, signal?: AbortSignal, + workspaceId?: string, ): Promise { return client.requestJson({ path: finetuneCancelPath(jobId), method: "POST", + headers: workspaceHeaders(workspaceId), signal, }); } @@ -102,10 +116,12 @@ export async function deleteFineTune( client: Client, jobId: string, signal?: AbortSignal, + workspaceId?: string, ): Promise { return client.requestJson({ path: finetuneJobPath(jobId), method: "DELETE", + headers: workspaceHeaders(workspaceId), signal, }); } @@ -113,6 +129,8 @@ export async function deleteFineTune( export interface GetFineTuneLogsParams { pageNo?: number; pageSize?: number; + /** Sent as X-DashScope-WorkSpace; use the job's owning workspace. */ + workspaceId?: string; signal?: AbortSignal; } @@ -130,6 +148,7 @@ export async function getFineTuneLogs( return client.requestJson({ path, method: "GET", + headers: workspaceHeaders(params.workspaceId), signal: params.signal, }); } @@ -218,10 +237,12 @@ export async function listCheckpoints( client: Client, jobId: string, signal?: AbortSignal, + workspaceId?: string, ): Promise { return client.requestJson({ path: finetuneCheckpointsPath(jobId), method: "GET", + headers: workspaceHeaders(workspaceId), signal, }); } @@ -239,12 +260,14 @@ export async function exportCheckpoint( checkpoint: string, modelName: string, signal?: AbortSignal, + workspaceId?: string, ): Promise { const qs = new URLSearchParams(); qs.set("model_name", modelName); return client.requestJson({ path: `${finetuneExportPath(jobId, checkpoint)}?${qs.toString()}`, method: "GET", + headers: workspaceHeaders(workspaceId), signal, }); } diff --git a/packages/core/src/finetune/capability.ts b/packages/core/src/finetune/capability.ts index 3d5bfc95..817a8d41 100644 --- a/packages/core/src/finetune/capability.ts +++ b/packages/core/src/finetune/capability.ts @@ -34,6 +34,14 @@ export const TRAINING_TYPES_CLI: readonly TrainingTypeCli[] = Object.keys( /** Default training type when `--training-type` is omitted. */ export const DEFAULT_TRAINING_TYPE: TrainingTypeCli = "sft-lora"; +/** + * Catalog scope for training-capability queries. The default `listFoundationModels` + * catalog is inference-scoped and omits training-only base models (and their dated + * snapshots); scoping by `fineTune` returns the trainable universe the console + * training selector shows. Shared by both capability query directions. + */ +export const FINETUNE_CATALOG_SUPPORTS: Record = { fineTune: true }; + /** Subset of `supports` relevant to training capability. */ interface ModelSupports { sft?: boolean; @@ -113,6 +121,11 @@ export async function fetchModelCapability( diagnostics: Pick = {}, ): Promise { // Public model catalog — anonymous gateway call, no console token needed. - const match = await findModelByName(anonymousConsoleCall(settings, diagnostics), modelName); + // Scoped to the trainable catalog so training-only base models are found too. + const match = await findModelByName( + anonymousConsoleCall(settings, diagnostics), + modelName, + FINETUNE_CATALOG_SUPPORTS, + ); return match as ModelCapability | null; } diff --git a/packages/core/src/finetune/index.ts b/packages/core/src/finetune/index.ts index 4b3f261d..19297eff 100644 --- a/packages/core/src/finetune/index.ts +++ b/packages/core/src/finetune/index.ts @@ -5,3 +5,4 @@ export * from "./capability.ts"; export * from "./preflight.ts"; export * from "./profiles/index.ts"; export * from "./price.ts"; +export * from "./rl/index.ts"; diff --git a/packages/core/src/finetune/profiles/pg-opd.ts b/packages/core/src/finetune/profiles/pg-opd.ts new file mode 100644 index 00000000..0ae5fe1c --- /dev/null +++ b/packages/core/src/finetune/profiles/pg-opd.ts @@ -0,0 +1,28 @@ +/** + * `pg-opd` profile — pure Model OPD distillation (server `pg_opd`). + * ChatML record schema (prompt-only messages are accepted). + * + * Deliberately NOT registered in TRAINING_TYPE_MAP: OPD owns its command + * surface (`finetune opd run`) and must stay unreachable from + * `finetune text create --training-type`. + * + * Hyper-parameters come from the user's JSON file / --hp overrides, never + * from flag-based defaults: the parameter API's recommend_value is not the + * selected teacher's effective default, so the CLI fills nothing and leaves + * omitted fields to the server's teacher resolution. + */ +import { textProfile } from "./common.ts"; +import type { TrainingProfile } from "./types.ts"; + +const base = textProfile("pg-opd", "pg_opd", "chatml"); + +export const pgOpdProfile: TrainingProfile = { + ...base, + resolveHyperParameters: () => ({}), + // OPD batch_size is a training-batch knob, not the per-device semantics the + // samples>batch_size gate was built for; the gate's premise is unverified. + shouldSkipGate: () => true, + // The foundation catalog's capability shape for pg_opd is unverified; + // teacher/student compatibility is decided by the server at submit time. + shouldSkipCapabilityCheck: () => true, +}; diff --git a/packages/core/src/finetune/profiles/registry.ts b/packages/core/src/finetune/profiles/registry.ts index 8d4531cc..0dc1ebff 100644 --- a/packages/core/src/finetune/profiles/registry.ts +++ b/packages/core/src/finetune/profiles/registry.ts @@ -18,6 +18,7 @@ import { sftLoraProfile } from "./sft-lora.ts"; import { dpoProfile } from "./dpo.ts"; import { dpoLoraProfile } from "./dpo-lora.ts"; import { cptProfile } from "./cpt.ts"; +import { pgOpdProfile } from "./pg-opd.ts"; const PROFILES: TrainingProfile[] = [ sftProfile, @@ -25,6 +26,7 @@ const PROFILES: TrainingProfile[] = [ dpoProfile, dpoLoraProfile, cptProfile, + pgOpdProfile, ]; /** Look up a profile by its CLI training-type name. Throws USAGE if unknown. */ diff --git a/packages/core/src/finetune/rl/auth.ts b/packages/core/src/finetune/rl/auth.ts new file mode 100644 index 00000000..e9b8d844 --- /dev/null +++ b/packages/core/src/finetune/rl/auth.ts @@ -0,0 +1,304 @@ +/** + * RL / OPD authorization state machine. + * + * Auditable flow: check -> plan -> (confirm) -> enable the requested target -> + * final recheck. Every capability resolves to one of READY / MISSING / UNKNOWN / + * REQUIRES_USER_ACTION / FAILED; a failed query is UNKNOWN (never silently + * treated as enabled or disabled). Service-linked roles are account-level + * grants the CLI never creates: a missing role reports REQUIRES_USER_ACTION + * with manual-authorization guidance and blocks enablement. Business + * enablement only runs when the caller passes `authorize: true`, and only the + * requested target is enabled — RL never auto-enables OPD and vice versa. + * + * The zelda API names and request bodies below mirror the model-training + * console (customFetcherIo wraps payloads in `{input}` and appends `.m_efm`; + * fetcherIo payloads use `{reqDTO}`). Response parsing stays defensive: the + * console host may wrap a scalar flag in `{result}` or `{openStatus}`, so an + * unrecognized shape degrades to UNKNOWN rather than guessing a state. The SLS + * step is a static manual advisory: SLS activation is a separate console action + * (the console's own one-click authorization only creates the service roles), + * and the SLS OpenAPI needs SLS4-HMAC-SHA256 signing that neither the CLI zelda + * gateway nor its ACS3 signer provides, so the CLI never probes or opens it. + */ + +import { unwrapConsoleResponse } from "../../console/response.ts"; +import type { LocalizedText } from "../../types/command.ts"; + +/** Authorization target: plain reinforcement learning or OPD distillation. */ +export type RlAuthTarget = "rl" | "opd"; + +export type RlAuthStatus = "READY" | "MISSING" | "UNKNOWN" | "REQUIRES_USER_ACTION" | "FAILED"; + +export interface IRlAuthCheck { + name: string; + /** Required checks must be READY for the report to pass; advisory ones may degrade. */ + required: boolean; + status: RlAuthStatus; + detail?: string; +} + +export interface IRlAuthReport { + target: RlAuthTarget; + checks: IRlAuthCheck[]; + /** True when every required check is READY. */ + ok: boolean; + /** Audit trail of mutations actually attempted (name, or name:failed). */ + actions: string[]; +} + +/** Console gateway seam: `(api, data) => client.console(api, data)`. */ +export type RlConsoleCaller = (api: string, data: Record) => Promise; + +export interface IRlAuthOptions { + target: RlAuthTarget; + console: RlConsoleCaller; + workspaceId?: string; + /** Permit business enablement. Read-only probe when false (default). */ + authorize?: boolean; + /** Locale selector for user-facing guidance; defaults to en-US when omitted. */ + localize?: (text: LocalizedText) => string; + /** Console doc URL guiding manual SLR authorization; injected by the command layer. */ + manualAuthDocUrl: string; +} + +/** + * Console zelda API names, aligned with the model-training console. The + * `.m_efm` suffix and `{input}` wrapper belong to the customFetcherIo family; + * the telemetry and finetune HTTP APIs use `{reqDTO}` instead. + */ +export const RL_AUTH_API = { + checkUserWhitelist: + "zeldaHttp.dashscopeFinetune./zelda/api/v1/finetune/common/checkUserWhitelist", + queryReinforcementEnabled: + "zeldaHttp.dashscopeFinetune./zelda/api/v1/finetune/reinforcement/query_reinforcement_enabled", + queryOpdEnabled: "zeldaHttp.dashscopeFinetune./zelda/api/v1/finetune/opd/query_opd_enabled", + checkFineTuningSlrAuth: "zeldaEasy.broadscope-platform.modelInstance.checkSlrAuth.m_efm", + getTelemetrySlrStatus: "zeldaEasy.bailian-telemetry.activate.getTelemetrySlrStatus", + getTelemetryServiceStatus: "zeldaEasy.bailian-telemetry.activate.getTelemetryServiceStatus", + enableReinforcement: + "zeldaHttp.dashscopeFinetune./zelda/api/v1/finetune/reinforcement/enable_reinforcement", + enableOpd: "zeldaHttp.dashscopeFinetune./zelda/api/v1/finetune/opd/enable_opd", +} as const; + +/** + * SLS log service activation is a manual console step, not a CLI mutation. The + * SLS OpenAPI (GetSlsService / OpenSlsService) requires SLS4-HMAC-SHA256 signing + * that the CLI zelda gateway and ACS3 signer do not provide, and the console's + * own one-click authorization only creates the service roles (the fine-tuning + * SLR already covers SLS). The check therefore stays a static advisory. + */ +const RL_SLS_GUIDANCE: LocalizedText = { + "en-US": + "SLS (Simple Log Service) activation must be completed manually in the Alibaba Cloud console; the CLI cannot open it. Its service-linked role is already covered by the fine-tuning SLR above.", + "zh-CN": + "SLS(日志服务)开通需在阿里云控制台手动完成,CLI 无法代为开通;其服务关联角色已由上方 fine-tuning SLR 覆盖。", +}; + +const WHITELIST_PRODUCT: Record = { + rl: "agentic_rl", + opd: "pg_opd", +}; + +/** + * Manual SLR authorization guidance. Creating a service-linked role grants + * cross-service permissions on the user's account, so the CLI only checks the + * role status and points at the console doc instead of creating it. + */ +function slrManualGuidance(docUrl: string): LocalizedText { + return { + "en-US": `The CLI does not create service-linked roles. Follow ${docUrl} to authorize the required roles in the console, then re-run to continue.`, + "zh-CN": `CLI 不会自动创建服务关联角色。请参照 ${docUrl} 在控制台完成角色授权后重新执行。`, + }; +} + +interface IProbeResult { + status: RlAuthStatus; + detail?: string; +} + +function errorMessage(error: unknown): string { + return error instanceof Error ? error.message : String(error); +} + +/** Compact a raw payload for diagnostics so an UNKNOWN check explains itself. */ +function rawSnippet(value: unknown): string { + let text: string; + try { + text = typeof value === "string" ? value : (JSON.stringify(value) ?? String(value)); + } catch { + text = String(value); + } + return text.length > 300 ? `${text.slice(0, 300)}…` : text; +} + +/** + * Extract a boolean state from a gateway business payload. The console host + * exposes the flag under different keys depending on the API: a bare boolean + * (origin responses), `{result}` (wrapped scalars), `{openStatus}` (telemetry + * service) or `{enabled}` (SLS). Returns undefined when no recognizable flag is + * present so the caller reports UNKNOWN. + */ +export function extractEnabledFlag(response: unknown): boolean | undefined { + if (typeof response === "boolean") return response; + if (response === null || typeof response !== "object") return undefined; + const record = response as Record; + const data = + record.data !== null && typeof record.data === "object" + ? (record.data as Record) + : record; + for (const key of [ + "enabled", + "authorized", + "whitelisted", + "created", + "opened", + "available", + "result", + "openStatus", + ]) { + const value = data[key]; + if (typeof value === "boolean") return value; + } + return undefined; +} + +/** Query one capability; a thrown error or unrecognized shape becomes UNKNOWN. */ +async function probe(label: string, run: () => Promise): Promise { + let payload: unknown; + try { + payload = unwrapConsoleResponse(await run()); + } catch (error) { + const raw = (error as { rawResponse?: unknown }).rawResponse; + const suffix = raw !== undefined ? ` | raw=${rawSnippet(raw)}` : ""; + return { status: "UNKNOWN", detail: `${label}: ${errorMessage(error)}${suffix}` }; + } + const enabled = extractEnabledFlag(payload); + if (enabled === undefined) + return { + status: "UNKNOWN", + detail: `${label}: unrecognized response | raw=${rawSnippet(payload)}`, + }; + return { status: enabled ? "READY" : "MISSING" }; +} + +/** Attempt a mutation, recording the outcome in the audit trail. */ +async function mutate( + label: string, + run: () => Promise, + actions: string[], +): Promise { + try { + unwrapConsoleResponse(await run()); + actions.push(label); + return true; + } catch (error) { + actions.push(`${label}:failed (${errorMessage(error)})`); + return false; + } +} + +/** + * Run the authorization state machine for one target. Read-only by default; + * pass `authorize: true` to enable the target once its prerequisites (manual + * role authorization included) are ready. Roles are never created by the CLI; + * SLS activation is always a manual console step (static advisory). + */ +export async function runRlAuthorization(options: IRlAuthOptions): Promise { + const { target, console: call, authorize = false, workspaceId, manualAuthDocUrl } = options; + const localize = + options.localize ?? + ((text: LocalizedText) => (typeof text === "string" ? text : text["en-US"])); + const checks: IRlAuthCheck[] = []; + const actions: string[] = []; + const telemetryScope: Record = workspaceId ? { workspaceId } : {}; + + // 1. Admission whitelist (bare boolean). Missing admission is a user action, + // not a role gap. + const whitelist = await probe(RL_AUTH_API.checkUserWhitelist, () => + call(RL_AUTH_API.checkUserWhitelist, { reqDTO: { type: WHITELIST_PRODUCT[target] } }), + ); + checks.push({ + name: "whitelist", + required: true, + status: whitelist.status === "MISSING" ? "REQUIRES_USER_ACTION" : whitelist.status, + detail: whitelist.detail, + }); + + // 2. Fine-tuning service-linked role (shared by FC and SLS); `{input:{role}}`. + // A missing role is a manual user action, never a CLI mutation. + const slrCheckData = { input: { role: "fine-tuning" } }; + let slr = await probe(RL_AUTH_API.checkFineTuningSlrAuth, () => + call(RL_AUTH_API.checkFineTuningSlrAuth, slrCheckData), + ); + if (slr.status === "MISSING") { + slr = { status: "REQUIRES_USER_ACTION", detail: localize(slrManualGuidance(manualAuthDocUrl)) }; + } + checks.push({ name: "finetune-slr", required: true, status: slr.status, detail: slr.detail }); + + // 3. Telemetry role (advisory; Xtrace SLR); `{reqDTO:{workspaceId,slrType}}`. + const telemetrySlrData = { reqDTO: { ...telemetryScope, slrType: "Xtrace" } }; + let telemetrySlr = await probe(RL_AUTH_API.getTelemetrySlrStatus, () => + call(RL_AUTH_API.getTelemetrySlrStatus, telemetrySlrData), + ); + if (telemetrySlr.status === "MISSING") { + telemetrySlr = { + status: "REQUIRES_USER_ACTION", + detail: localize(slrManualGuidance(manualAuthDocUrl)), + }; + } + checks.push({ + name: "telemetry-slr", + required: false, + status: telemetrySlr.status, + detail: telemetrySlr.detail, + }); + + // 4. AppTrace service activation (advisory). The console opens it via a + // purchase page, so a non-ready state always requires a manual user action. + const appTrace = await probe(RL_AUTH_API.getTelemetryServiceStatus, () => + call(RL_AUTH_API.getTelemetryServiceStatus, { + reqDTO: { ...telemetryScope, serviceType: "AppTrace" }, + }), + ); + checks.push({ + name: "apptrace-service", + required: false, + status: appTrace.status === "READY" ? "READY" : "REQUIRES_USER_ACTION", + detail: appTrace.detail, + }); + + // 5. SLS log service (advisory). Activation is a manual console step the CLI + // cannot perform, so this is a static user-action reminder, never a probe. + checks.push({ + name: "sls-service", + required: false, + status: "REQUIRES_USER_ACTION", + detail: localize(RL_SLS_GUIDANCE), + }); + + // 6. Business enablement state for the requested target only; `{reqDTO:{}}`. + const enabledApi = + target === "opd" ? RL_AUTH_API.queryOpdEnabled : RL_AUTH_API.queryReinforcementEnabled; + let enabled = await probe(enabledApi, () => call(enabledApi, { reqDTO: {} })); + + // 7. Enable only the requested target, only when authorized and prerequisites + // are ready (roles must already be authorized manually in the console). + // Never cross-enable the other training mode. + const prerequisitesReady = whitelist.status === "READY" && slr.status === "READY"; + if (authorize && prerequisitesReady && enabled.status === "MISSING") { + const enableApi = target === "opd" ? RL_AUTH_API.enableOpd : RL_AUTH_API.enableReinforcement; + const done = await mutate(enableApi, () => call(enableApi, { reqDTO: {} }), actions); + enabled = done + ? await probe(enabledApi, () => call(enabledApi, { reqDTO: {} })) + : { status: "FAILED" }; + } + checks.push({ + name: "business-enabled", + required: true, + status: enabled.status, + detail: enabled.detail, + }); + + const ok = checks.every((check) => !check.required || check.status === "READY"); + return { target, checks, ok, actions }; +} diff --git a/packages/core/src/finetune/rl/config.ts b/packages/core/src/finetune/rl/config.ts new file mode 100644 index 00000000..35b89e0b --- /dev/null +++ b/packages/core/src/finetune/rl/config.ts @@ -0,0 +1,326 @@ +/** + * RL / OPD config assembly: merge CLI params + optional YAML into one SDK spec, + * then serialize a task-local YAML with all filesystem paths rewritten. + * + * Merge priority: + * accepted defaults < YAML < explicit CLI params. + * `--set` is applied last as a top-level shallow override (SDK `init(**kwargs)`). + */ + +import { basename, join } from "node:path"; +import { parse, stringify } from "yaml"; +import { UsageError } from "../../errors/base.ts"; +import { + parseAssignment, + parseDottedAssignment, + parseJsonValue, + parseNumericValue, + parseTypedValue, +} from "./params.ts"; +import type { + IResolvedTrainingSpec, + RlDataset, + RlFunction, + RlJobSpec, + RlRunParams, + RlTaskPaths, +} from "./types.ts"; + +const DEFAULT_ROLLOUT_NAME = "rollout-1"; + +function isPlainObject(value: unknown): value is Record { + return typeof value === "object" && value !== null && !Array.isArray(value); +} + +/** Recursive plain-object merge; arrays and scalars are replaced, not joined. */ +function deepMerge( + target: Record, + source: Record, +): Record { + const result: Record = { ...target }; + for (const [key, sourceValue] of Object.entries(source)) { + const targetValue = result[key]; + result[key] = + isPlainObject(targetValue) && isPlainObject(sourceValue) + ? deepMerge(targetValue, sourceValue) + : sourceValue; + } + return result; +} + +/** Parse the optional `--config` YAML document into a spec (empty when absent). */ +export function parseJobYaml(yamlText: string): RlJobSpec { + let parsed: unknown; + try { + parsed = parse(yamlText); + } catch (error) { + throw new UsageError( + "Invalid --config YAML.", + error instanceof Error ? error.message : undefined, + ); + } + if (parsed === null || parsed === undefined) return {}; + if (!isPlainObject(parsed)) { + throw new UsageError("Invalid --config YAML.", "Expected a mapping at the document root."); + } + return parsed as RlJobSpec; +} + +function functionList(spec: RlJobSpec): RlFunction[] { + spec.functions ??= []; + return spec.functions; +} + +/** Find a function by name, or create it with the given type. */ +function upsertFunction(spec: RlJobSpec, name: string, type: string): RlFunction { + const functions = functionList(spec); + let found = functions.find((existing) => existing.name === name); + if (!found) { + found = { type, name }; + functions.push(found); + } + return found; +} + +/** Find an existing function by name; modifiers require it to be defined. */ +function requireFunction(spec: RlJobSpec, name: string, flag: string): RlFunction { + const found = functionList(spec).find((existing) => existing.name === name); + if (!found) { + throw new UsageError( + `Unknown function name "${name}" in ${flag}.`, + "Define the function first via --rollout / --reward or in --config.", + ); + } + return found; +} + +/** Replace one dataset sublist (training/validation) independently. */ +function replaceDatasets(spec: RlJobSpec, type: string, entries: RlDataset[]): void { + const kept = (spec.datasets ?? []).filter((dataset) => dataset.type !== type); + spec.datasets = [...kept, ...entries]; +} + +function buildDatasetEntries( + type: string, + files: string[] | undefined, + fileIds: string[] | undefined, +): RlDataset[] { + const entries: RlDataset[] = []; + for (const file of files ?? []) { + entries.push({ type, data_source_type: "file_id", file_name: file }); + } + for (const fileId of fileIds ?? []) { + entries.push({ type, data_source_type: "file_id", file_id: fileId }); + } + return entries; +} + +/** + * Merge CLI params over an optional YAML document into a single SDK spec. + * Enforces model presence and the RL/OPD type constraints. + */ +export function resolveTrainingSpec(params: RlRunParams, yamlText?: string): IResolvedTrainingSpec { + const spec: RlJobSpec = yamlText ? parseJobYaml(yamlText) : {}; + + // --- functions: clear, then create rollout/rewards, then apply modifiers --- + if (params.clearFunctions) spec.functions = []; + + if (params.rollout) { + const functions = functionList(spec); + const rollout = + functions.find((existing) => existing.type === "rollout") ?? + upsertFunction(spec, DEFAULT_ROLLOUT_NAME, "rollout"); + rollout.type = "rollout"; + rollout.fcmodel = { ...rollout.fcmodel, classpath: params.rollout }; + } + + for (const entry of params.rewards ?? []) { + const { key, value } = parseAssignment(entry, "--reward", "--reward "); + const reward = upsertFunction(spec, key, "reward"); + reward.type = "reward"; + reward.fcmodel = { ...reward.fcmodel, classpath: value }; + } + + // code-dir / requirements apply to every function package. + if (params.codeDir !== undefined || params.requirements !== undefined) { + for (const fn of functionList(spec)) { + fn.fcmodel ??= {}; + if (params.codeDir !== undefined) fn.fcmodel.zipdir = params.codeDir; + if (params.requirements !== undefined) fn.fcmodel.requirements_path = params.requirements; + } + } + + for (const entry of params.functionTimeouts ?? []) { + const { key, value } = parseAssignment( + entry, + "--function-timeout", + "--function-timeout ", + ); + requireFunction(spec, key, "--function-timeout").timeout = parseNumericValue( + value, + "--function-timeout", + ); + } + + for (const entry of params.rewardWeights ?? []) { + const { key, value } = parseAssignment(entry, "--reward-weight", "--reward-weight "); + requireFunction(spec, key, "--reward-weight").weight = parseNumericValue( + value, + "--reward-weight", + ); + } + + for (const entry of params.rewardMetrics ?? []) { + const { name, field, value } = parseDottedAssignment( + entry, + "--reward-metric", + "--reward-metric ", + ); + const fn = requireFunction(spec, name, "--reward-metric"); + fn.reward_metric_weight ??= {}; + fn.reward_metric_weight[field] = parseNumericValue(value, "--reward-metric"); + } + + for (const entry of params.functionRuntime ?? []) { + const { name, field, value } = parseDottedAssignment( + entry, + "--function-runtime", + "--function-runtime ", + ); + const fn = requireFunction(spec, name, "--function-runtime"); + fn.runtime = deepMerge(fn.runtime ?? {}, { [field]: parseTypedValue(value) }); + } + + for (const entry of params.functionEnv ?? []) { + const { name, field, value } = parseDottedAssignment( + entry, + "--function-env", + "--function-env ", + ); + const fn = requireFunction(spec, name, "--function-env"); + fn.runtime ??= {}; + fn.runtime.env ??= {}; + fn.runtime.env[field] = value; + } + + // --- datasets: training and validation replaced independently --- + const trainingEntries = buildDatasetEntries("training", params.trainFiles, params.trainFileIds); + if (trainingEntries.length > 0) replaceDatasets(spec, "training", trainingEntries); + const validationEntries = buildDatasetEntries( + "validation", + params.validationFiles, + params.validationFileIds, + ); + if (validationEntries.length > 0) replaceDatasets(spec, "validation", validationEntries); + + // --- scalar fields --- + if (params.model !== undefined) spec.model = { ...spec.model, name: params.model }; + if (params.name !== undefined) spec.name = params.name; + if (params.teacherModel !== undefined) spec.teacher_model = params.teacherModel; + + // --- training.hyper_parameters: deep merge, never whole-block replace --- + if (params.hp && params.hp.length > 0) { + const hyperParameters: Record = {}; + for (const entry of params.hp) { + const { key, value } = parseAssignment(entry, "--hp", "--hp "); + hyperParameters[key] = parseTypedValue(value); + } + spec.training ??= {}; + spec.training.hyper_parameters = deepMerge( + spec.training.hyper_parameters ?? {}, + hyperParameters, + ); + } + + // --- training.resources --- + if ( + params.chargeType !== undefined || + params.mtuSpec !== undefined || + params.mtuCount !== undefined || + params.instanceId !== undefined + ) { + spec.training ??= {}; + const resources = { ...spec.training.resources }; + if (params.chargeType !== undefined) resources.charge_type = params.chargeType; + if (params.mtuSpec !== undefined) resources.mtu_spec_code = params.mtuSpec; + if (params.mtuCount !== undefined) resources.mtu_capacity = params.mtuCount; + if (params.instanceId !== undefined) resources.instance_id = params.instanceId; + spec.training.resources = resources; + } + + // --- bailian metadata: packaging rules consumed by the snapshot layer --- + if ( + params.codeDir !== undefined || + params.requirements !== undefined || + params.include !== undefined || + params.exclude !== undefined + ) { + const bailian = spec.bailian ?? {}; + if (params.codeDir !== undefined) bailian.code_dir = params.codeDir; + if (params.requirements !== undefined) bailian.requirements = params.requirements; + if (params.include !== undefined || params.exclude !== undefined) { + bailian.package = { + ...bailian.package, + ...(params.include !== undefined ? { include: params.include } : {}), + ...(params.exclude !== undefined ? { exclude: params.exclude } : {}), + }; + } + spec.bailian = bailian; + } + + // --- --set: top-level shallow override, applied last (highest priority) --- + for (const entry of params.set ?? []) { + const { key, value } = parseAssignment(entry, "--set", "--set "); + spec[key] = parseJsonValue(value); + } + + // --- type constraints + required fields --- + const isOpd = params.opd === true; + spec.training ??= {}; + if (isOpd) { + spec.training.type = "pg_opd"; + if (!spec.teacher_model) { + throw new UsageError("OPD requires a teacher model.", "Pass --teacher-model ."); + } + } else { + if (spec.teacher_model) { + throw new UsageError( + "teacher_model is only valid for OPD jobs.", + "Remove --teacher-model, or use the OPD run command.", + ); + } + if (!spec.training.type) spec.training.type = "reinforcement"; + } + + if (!spec.model?.name) { + throw new UsageError( + "A base model is required.", + "Pass --model or set model.name in --config.", + ); + } + + return { + spec, + hasFunctions: (spec.functions?.length ?? 0) > 0, + isOpd, + }; +} + +/** + * Serialize the task-local YAML handed to the SDK: strip the `bailian` namespace + * and rewrite every filesystem reference into the task directory. `classpath` + * and `requirements_path` stay relative to the package root and are untouched. + */ +export function buildTaskYaml(spec: RlJobSpec, paths: RlTaskPaths): string { + const clone = structuredClone(spec); + delete clone.bailian; + + for (const fn of clone.functions ?? []) { + if (fn.fcmodel) fn.fcmodel.zipdir = paths.deployCopyDir; + } + for (const dataset of clone.datasets ?? []) { + if (dataset.file_name) dataset.file_name = join(paths.dataDir, basename(dataset.file_name)); + } + + return stringify(clone); +} diff --git a/packages/core/src/finetune/rl/index.ts b/packages/core/src/finetune/rl/index.ts new file mode 100644 index 00000000..d8d43349 --- /dev/null +++ b/packages/core/src/finetune/rl/index.ts @@ -0,0 +1,4 @@ +export * from "./types.ts"; +export * from "./params.ts"; +export * from "./config.ts"; +export * from "./auth.ts"; diff --git a/packages/core/src/finetune/rl/params.ts b/packages/core/src/finetune/rl/params.ts new file mode 100644 index 00000000..ba2c105d --- /dev/null +++ b/packages/core/src/finetune/rl/params.ts @@ -0,0 +1,98 @@ +/** + * Parsers for the repeatable `KEY=VALUE` style RL flags. + * + * Core stays free of runtime flag parsing: the command layer hands raw entry + * strings here and these helpers turn them into structured assignments. + * All errors are {@link UsageError} (exit 2) — they describe user input, not + * server-side failures. + */ + +import { UsageError } from "../../errors/base.ts"; + +/** + * Parse a scalar by type: boolean / null / JSON object-or-array / number, + * falling back to the original string. Used for `--hp key=value`. + */ +export function parseTypedValue(raw: string): unknown { + const trimmed = raw.trim(); + if (trimmed === "true") return true; + if (trimmed === "false") return false; + if (trimmed === "null") return null; + if (trimmed.startsWith("{") || trimmed.startsWith("[") || trimmed.startsWith('"')) { + try { + return JSON.parse(trimmed); + } catch { + return raw; + } + } + if (trimmed !== "" && !Number.isNaN(Number(trimmed))) return Number(trimmed); + return raw; +} + +/** + * Parse a value as JSON, falling back to the original string. Used for + * `--set key=value` (matches the SDK `init(**kwargs)` top-level override). + */ +export function parseJsonValue(raw: string): unknown { + try { + return JSON.parse(raw); + } catch { + return raw; + } +} + +/** A `key=value` assignment split on the first `=`. */ +export interface KeyValueAssignment { + key: string; + value: string; +} + +/** + * Split `key=value` on the first `=`. Both sides must be non-empty. + * `formatHint` describes the expected syntax for the error message. + */ +export function parseAssignment( + entry: string, + flag: string, + formatHint: string, +): KeyValueAssignment { + const separatorIndex = entry.indexOf("="); + if (separatorIndex <= 0 || separatorIndex === entry.length - 1) { + throw new UsageError(`Invalid ${flag} value "${entry}".`, `Expected ${formatHint}.`); + } + return { key: entry.slice(0, separatorIndex), value: entry.slice(separatorIndex + 1) }; +} + +/** A `name.field=value` assignment (name and field split on the first `.`). */ +export interface DottedAssignment { + name: string; + field: string; + value: string; +} + +/** + * Split `name.field=value` into its three parts. Used for `--function-runtime`, + * `--function-env` and `--reward-metric`. The value may itself contain `.` or + * `=`; only the first `=` and the first `.` of the left side are separators. + */ +export function parseDottedAssignment( + entry: string, + flag: string, + formatHint: string, +): DottedAssignment { + const { key, value } = parseAssignment(entry, flag, formatHint); + const dotIndex = key.indexOf("."); + if (dotIndex <= 0 || dotIndex === key.length - 1) { + throw new UsageError(`Invalid ${flag} value "${entry}".`, `Expected ${formatHint}.`); + } + return { name: key.slice(0, dotIndex), field: key.slice(dotIndex + 1), value }; +} + +/** Parse a numeric flag value, rejecting non-finite input. */ +export function parseNumericValue(raw: string, flag: string): number { + const parsed = Number(raw); + if (raw.trim() === "" || Number.isNaN(parsed) || !Number.isFinite(parsed)) { + throw new UsageError(`Invalid ${flag} value "${raw}".`, "Expected a finite number."); + } + return parsed; +} diff --git a/packages/core/src/finetune/rl/types.ts b/packages/core/src/finetune/rl/types.ts new file mode 100644 index 00000000..d6346417 --- /dev/null +++ b/packages/core/src/finetune/rl/types.ts @@ -0,0 +1,166 @@ +/** + * RL / OPD training spec types. + * + * Mirrors the DashScope SDK `job.yaml` shape (snake_case preserved verbatim — + * the SDK owns these field names). CLI-only metadata lives under the `bailian` + * namespace and is stripped before the spec is handed to the SDK. + */ + +/** FC runtime sizing + env for a single function component. */ +export interface RlFunctionRuntime { + cpu?: number; + memory_size?: number; + disk_size?: number; + concurrency?: number; + capacity?: number; + min_capacity?: number; + max_capacity?: number; + memory_scale_threshold?: number; + concurrency_scale_threshold?: number; + env?: Record; + [key: string]: unknown; +} + +/** Upload package descriptor for a function component. */ +export interface RlFcModel { + /** Source root uploaded as the function package; rewritten to deploy-copy. */ + zipdir?: string; + /** Python entry class, relative to zipdir; never rewritten. */ + classpath?: string; + /** Requirements path relative to the package root; kept as-is. */ + requirements_path?: string; + [key: string]: unknown; +} + +/** A rollout / reward function component. */ +export interface RlFunction { + type?: string; + name?: string; + timeout?: number; + weight?: number; + reward_metric_weight?: Record; + fcmodel?: RlFcModel; + runtime?: RlFunctionRuntime; + [key: string]: unknown; +} + +/** A training / validation dataset entry. */ +export interface RlDataset { + type?: string; + data_source_type?: string; + /** Local file path; rewritten into the task data dir before submission. */ + file_name?: string; + /** Reuse an already-uploaded file; mutually exclusive with a local upload. */ + file_id?: string; + [key: string]: unknown; +} + +export interface RlModel { + name?: string; + [key: string]: unknown; +} + +export interface RlResources { + charge_type?: string; + mtu_spec_code?: string; + mtu_capacity?: number; + instance_id?: string; + [key: string]: unknown; +} + +export interface RlTraining { + type?: string; + hyper_parameters?: Record; + resources?: RlResources; + [key: string]: unknown; +} + +/** CLI-only metadata; stripped before handing the spec to the SDK. */ +export interface RlBailianMeta { + schema_version?: number; + profile?: string; + code_dir?: string; + requirements?: string; + package?: { include?: string[]; exclude?: string[] }; + execution?: { watch?: boolean; timeout?: number }; + /** Secret references only (env var names); never plaintext credentials. */ + function_secret_env?: Record; + [key: string]: unknown; +} + +/** The full job.yaml document (SDK fields + bailian namespace). */ +export interface RlJobSpec { + name?: string; + model?: RlModel; + /** OPD teacher model; forbidden for plain RL. */ + teacher_model?: string; + functions?: RlFunction[]; + datasets?: RlDataset[]; + training?: RlTraining; + observability?: Record; + bailian?: RlBailianMeta; + [key: string]: unknown; +} + +/** + * Parsed CLI business params fed into {@link resolveTrainingSpec}. + * + * The command layer maps raw flags into this shape; core stays free of any + * runtime flag-parsing dependency. Repeatable flags arrive as string arrays + * in the original `KEY=VALUE` / `name.field=value` syntax. + */ +export interface RlRunParams { + name?: string; + model?: string; + teacherModel?: string; + trainFiles?: string[]; + trainFileIds?: string[]; + validationFiles?: string[]; + validationFileIds?: string[]; + codeDir?: string; + requirements?: string; + include?: string[]; + exclude?: string[]; + /** Single rollout classpath. */ + rollout?: string; + /** Repeatable `name=classpath`. */ + rewards?: string[]; + clearFunctions?: boolean; + /** Repeatable `name=sec`. */ + functionTimeouts?: string[]; + /** Repeatable `name.field=value`. */ + functionRuntime?: string[]; + /** Repeatable `name=num`. */ + rewardWeights?: string[]; + /** Repeatable `name.metric=num`. */ + rewardMetrics?: string[]; + /** Repeatable `name.KEY=value`. */ + functionEnv?: string[]; + /** Repeatable `key=value`, parsed by type. */ + hp?: string[]; + chargeType?: string; + mtuSpec?: string; + mtuCount?: number; + instanceId?: string; + /** Repeatable `key=value`, top-level shallow override (SDK init(**kwargs)). */ + set?: string[]; + /** Force OPD mode: training.type=pg_opd + teacher_model required. */ + opd?: boolean; +} + +/** Task-directory paths needed to rewrite filesystem references in the YAML. */ +export interface RlTaskPaths { + /** Writable source copy the SDK packages (zipdir target). */ + deployCopyDir: string; + /** Staged training/validation data (file_name target). */ + dataDir: string; +} + +/** Result of {@link resolveTrainingSpec}: merged spec + assembly diagnostics. */ +export interface IResolvedTrainingSpec { + spec: RlJobSpec; + /** Whether any function component (rollout/reward) is present. */ + hasFunctions: boolean; + /** Whether this is an OPD job (pg_opd + teacher_model). */ + isOpd: boolean; +} diff --git a/packages/core/src/finetune/types.ts b/packages/core/src/finetune/types.ts index b0a81601..72738a3c 100644 --- a/packages/core/src/finetune/types.ts +++ b/packages/core/src/finetune/types.ts @@ -20,13 +20,33 @@ export interface FineTuneHyperParameters { [k: string]: unknown; } +/** + * Dataset descriptor used by OPD (pg_opd) jobs. The server also accepts the + * flat `training_file_ids` form, but OPD submissions and readbacks use these + * descriptors, so the CLI sends the same shape. + */ +export interface FineTuneDatasetDescriptor { + type: "training" | "validation"; + data_source_type: "file_id"; + file_id: string; +} + +/** MTU resource configuration for OPD jobs (kept separate from hyper_parameters). */ +export interface FineTuneResourceConfig { + charge_type?: string; + mtu_spec_code?: string; + mtu_capacity?: number; + [k: string]: unknown; +} + /** POST /api/v1/fine-tunes request body. */ export interface CreateFineTuneRequest { /** Base model ID, or a previously fine-tuned model ID for continued training. */ model: string; - training_file_ids: string[]; + /** Flat file-id form (sft/dpo/cpt). OPD uses training_datasets instead. */ + training_file_ids?: string[]; /** - * Server-supported values: `cpt | sft | efficient_sft | dpo_full | dpo_lora`. + * Server-supported values: `cpt | sft | efficient_sft | dpo_full | dpo_lora | pg_opd`. * * NOTE — current bailian-cli scope: `sft` (default) and `efficient_sft`. * Other values are rejected by the CLI at parse time so users get an @@ -45,6 +65,14 @@ export interface CreateFineTuneRequest { model_name?: string; /** Suffix appended by the platform; field is `finetuned_output_suffix` (NOT `suffix`). */ finetuned_output_suffix?: string; + /** OPD (pg_opd): platform-registered teacher model ID. */ + teacher_model?: string; + /** OPD (pg_opd): training dataset descriptors. */ + training_datasets?: FineTuneDatasetDescriptor[]; + /** OPD (pg_opd): validation dataset descriptors. */ + validation_datasets?: FineTuneDatasetDescriptor[]; + /** OPD (pg_opd): MTU charge type / spec / capacity. */ + resource_config?: FineTuneResourceConfig; } /** GET /api/v1/fine-tunes/{id}/logs response. */ @@ -158,6 +186,12 @@ export interface FineTuneJob { training_file_ids?: string[]; validation_file_ids?: string[]; hyper_parameters?: FineTuneHyperParameters; + /** OPD (pg_opd) readback fields. */ + teacher_model?: string; + training_datasets?: FineTuneDatasetDescriptor[]; + validation_datasets?: FineTuneDatasetDescriptor[]; + mtu_spec_code?: string; + mtu_capacity?: number; /** Server-side timestamps (DashScope uses snake_case `create_time` / `end_time`). */ create_time?: string; end_time?: string; diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index fbe04780..afe68199 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -16,6 +16,8 @@ export * from "./batch/index.ts"; export * from "./decision/index.ts"; export * from "./parsex/index.ts"; export * from "./finetune/index.ts"; +export * from "./isolation/index.ts"; +export * from "./rl-runtime/index.ts"; export * from "./deploy/index.ts"; export * from "./model-import/index.ts"; export * from "./speech/index.ts"; diff --git a/packages/core/src/isolation/app-layer.ts b/packages/core/src/isolation/app-layer.ts new file mode 100644 index 00000000..56e72a69 --- /dev/null +++ b/packages/core/src/isolation/app-layer.ts @@ -0,0 +1,145 @@ +/** + * 确定性应用层编排。 + * + * detect → fail-closed 闸门 → OS prepare → 白名单代理 → 最小环境 → home 预生成 + * → 受控进程 → 脱敏 → 关代理。环境闭环(凭据禁读)不可用时在创建任何云资源前 + * fail-closed;快照/临时 YAML 由命令层组装后经 layout 传入,本模块保持通用。 + */ + +import { rmSync } from "node:fs"; +import { BailianError } from "../errors/base.ts"; +import { ExitCode } from "../errors/codes.ts"; +import { buildSandboxEnv, prepareTaskHome } from "./env.ts"; +import type { ITaskDirLayout } from "./paths.ts"; +import { DEFAULT_PROXY_POLICY, startWhitelistProxy, withEndpointDomain } from "./proxy.ts"; +import { runSandboxedProcess } from "./process.ts"; +import type { IIsolationAdapter, IIsolationResult, IIsolationSpec, IProxyPolicy } from "./types.ts"; + +/** 一次隔离执行的输入(任务目录与命令由命令层组装)。 */ +export interface IIsolatedRunInput { + layout: ITaskDirLayout; + runtimeRoot: string; + /** 完整 argv,含解释器,如 [python, -I, -m, dashscope, ...]。 */ + command: string[]; + apiKey: string; + baseUrl?: string; + credentialDenyPaths: string[]; + network?: IProxyPolicy; + timeoutMs: number; + maxOutputBytes: number; + logLevel?: string; + /** 受控 SDK 环境变量(如 FC_PYPI_LIB),由黑盒显式注入,绝不从宿主继承。 */ + sdkEnv?: Record; + /** 沙箱进程 cwd,默认 taskDir。SDK 会相对 cwd 写部署文件(如 start.sh), + * 带代码包的命令须传 deployCopyDir,使相对写入落在可写的代码包内。 */ + cwd?: string; + signal?: AbortSignal; +} + +/** 日志脱敏:OSS 签名参数与 API Key。 */ +export function sanitizeSecrets(text: string): string { + return text + .replace(/OSSAccessKeyId=[^&\s"']+/g, "OSSAccessKeyId=***") + .replace(/Signature=[^&\s"']+/g, "Signature=***") + .replace(/sk-[A-Za-z0-9]+/g, "sk-***"); +} + +function buildSpec(input: IIsolatedRunInput): IIsolationSpec { + const { layout } = input; + return { + runId: layout.runId, + runtimeRoot: input.runtimeRoot, + taskDir: layout.taskDir, + snapshotDir: layout.snapshotDir, + deployCopyDir: layout.deployCopyDir, + dataDir: layout.dataDir, + homeDir: layout.homeDir, + tmpDir: layout.tmpDir, + cacheDir: layout.cacheDir, + configPath: layout.configPath, + command: input.command, + apiKey: input.apiKey, + baseUrl: input.baseUrl, + credentialDenyPaths: input.credentialDenyPaths, + network: input.network ?? DEFAULT_PROXY_POLICY, + timeoutMs: input.timeoutMs, + maxOutputBytes: input.maxOutputBytes, + logLevel: input.logLevel, + sdkEnv: input.sdkEnv, + }; +} + +/** + * 在两层隔离下执行命令。环境闭环不可用时 fail-closed(不创建任何云资源)。 + */ +export async function executeIsolatedRun( + input: IIsolatedRunInput, + adapter: IIsolationAdapter, +): Promise { + const capability = await adapter.detect(); + if (!capability.credentialDenyRead.available) { + const reason = capability.credentialDenyRead.reason ?? "Credential isolation is unavailable."; + throw new BailianError( + reason, + ExitCode.GENERAL, + "No cloud resources were created. See the runtime doctor command for diagnostics.", + ); + } + + const spec = buildSpec(input); + // 白名单须包含用户配置的服务端点 host(workspace 网关等),否则 SDK 经代理访问被 403。 + const proxy = await startWhitelistProxy({ + policy: withEndpointDomain(spec.network, spec.baseUrl), + }); + spec.proxyPort = proxy.port; + + try { + await adapter.prepare(spec); + const env = buildSandboxEnv({ + homeDir: spec.homeDir, + tmpDir: spec.tmpDir, + cacheDir: spec.cacheDir, + runtimeRoot: spec.runtimeRoot, + apiKey: spec.apiKey, + baseUrl: spec.baseUrl, + proxyPort: proxy.port, + logLevel: spec.logLevel, + sdkEnv: spec.sdkEnv, + }); + prepareTaskHome(spec.homeDir, spec.baseUrl); + + const result = await runSandboxedProcess({ + command: spec.command, + env, + cwd: input.cwd ?? spec.taskDir, + timeoutMs: spec.timeoutMs, + maxOutputBytes: spec.maxOutputBytes, + wrapCommand: (command) => adapter.wrapCommand(spec, command), + signal: input.signal, + }); + + return { + exitCode: result.exitCode, + signal: result.signal, + stdout: sanitizeSecrets(result.stdout), + stderr: sanitizeSecrets(result.stderr), + timedOut: result.timedOut, + credentialDenyEnforced: capability.credentialDenyRead.available, + hardening: capability.hardening, + }; + } finally { + try { + await proxy.close(); + await adapter.dispose(); + } finally { + // 生命周期绑定调用:结束即销毁任务目录(成功/失败/超时同策,不保留)。 + // 崩溃路径(SIGKILL/断电)finally 未执行的孤儿由 runtime clean / prepare + // 按 TTL 兜底回收。best-effort:清理失败不得掩盖执行结果。 + try { + rmSync(spec.taskDir, { recursive: true, force: true }); + } catch { + // 留给 TTL 兜底 + } + } + } +} diff --git a/packages/core/src/isolation/cleanup.ts b/packages/core/src/isolation/cleanup.ts new file mode 100644 index 00000000..9530e1bf --- /dev/null +++ b/packages/core/src/isolation/cleanup.ts @@ -0,0 +1,118 @@ +/** + * 沙箱产物生命周期清理(计划式,支持 dry-run 预览)。 + * + * 两类产物、两种策略: + * - runs//:正常路径在调用结束时立即销毁(见 app-layer 的 finally), + * 留到这里的都是崩溃路径孤儿(SIGKILL/断电致 finally 未执行),按 TTL 回收。 + * - runtimes/rl//:不可变运行时按版本跨调用复用;基线升级后旧版本 + * 目录成为死重,按「只保留当前基线」回收。 + * 下载缓存(cache/rl,按 SHA 内容寻址、跨版本复用)与 override 开发目录绝不触碰。 + */ + +import { existsSync, readdirSync, rmSync, statSync } from "node:fs"; +import { join } from "node:path"; +import { managedRuntimesRoot, runsRoot } from "./paths.ts"; + +/** runs 孤儿默认年龄阈值:24 小时(正常调用分钟级结束,阈值极宽裕)。 */ +export const DEFAULT_RUNS_TTL_MS = 24 * 60 * 60 * 1000; + +export interface ICleanupOptions { + /** 基准时间(ms epoch),默认 Date.now()。 */ + now?: number; + /** runs 孤儿年龄阈值(毫秒),默认 24h。 */ + runsTtlMs?: number; + /** 回收 runs 孤儿,默认 true。 */ + pruneRuns?: boolean; + /** 回收旧版本运行时,默认 false(prepare 顺手清理只动 runs)。 */ + pruneRuntimes?: boolean; + /** 当前基线 runtime-id;pruneRuntimes 时缺省则跳过运行时回收(fail-safe)。 */ + currentRuntimeId?: string; + /** 只产出计划,不删除。 */ + dryRun?: boolean; + /** 目录覆盖(测试用);缺省取隔离布局的标准路径。 */ + runsDir?: string; + runtimesDir?: string; +} + +/** 单个产物的处置决定(keep 也列出,保证预览透明)。 */ +export interface ICleanupEntry { + path: string; + kind: "run" | "runtime"; + action: "remove" | "keep"; + reason: string; +} + +export interface ICleanupResult { + dryRun: boolean; + entries: ICleanupEntry[]; + /** 实际删除数(dryRun 时为计划删除数)。 */ + removedCount: number; +} + +function listSubdirs(dir: string): string[] { + if (!existsSync(dir)) return []; + return readdirSync(dir, { withFileTypes: true }) + .filter((dirent) => dirent.isDirectory()) + .map((dirent) => join(dir, dirent.name)); +} + +/** + * 清理沙箱产物:先对每个目录产出 remove/keep 计划,再统一执行删除。 + * 单目录删除失败降级为 keep(不抛错、不中断其余清理);stat 竞态直接跳过。 + */ +export function cleanupSandboxArtifacts(options: ICleanupOptions = {}): ICleanupResult { + const now = options.now ?? Date.now(); + const ttlMs = options.runsTtlMs ?? DEFAULT_RUNS_TTL_MS; + const dryRun = options.dryRun === true; + const entries: ICleanupEntry[] = []; + + if (options.pruneRuns !== false) { + for (const path of listSubdirs(options.runsDir ?? runsRoot())) { + let mtimeMs: number; + try { + mtimeMs = statSync(path).mtimeMs; + } catch { + continue; // 与并发清理竞态:目录已消失 + } + const expired = now - mtimeMs > ttlMs; + entries.push({ + path, + kind: "run", + action: expired ? "remove" : "keep", + reason: expired ? "orphaned run older than TTL" : "within TTL", + }); + } + } + + if (options.pruneRuntimes === true && options.currentRuntimeId !== undefined) { + const runtimesDir = options.runtimesDir ?? managedRuntimesRoot(); + const currentPath = join(runtimesDir, options.currentRuntimeId); + for (const path of listSubdirs(runtimesDir)) { + const isCurrent = path === currentPath; + entries.push({ + path, + kind: "runtime", + action: isCurrent ? "keep" : "remove", + reason: isCurrent ? "current baseline runtime" : "superseded runtime version", + }); + } + } + + let removedCount = 0; + for (const entry of entries) { + if (entry.action !== "remove") continue; + if (dryRun) { + removedCount += 1; + continue; + } + try { + rmSync(entry.path, { recursive: true, force: true }); + removedCount += 1; + } catch (error) { + entry.action = "keep"; + entry.reason = `delete failed: ${error instanceof Error ? error.message : String(error)}`; + } + } + + return { dryRun, entries, removedCount }; +} diff --git a/packages/core/src/isolation/env.ts b/packages/core/src/isolation/env.ts new file mode 100644 index 00000000..1af0bc94 --- /dev/null +++ b/packages/core/src/isolation/env.ts @@ -0,0 +1,99 @@ +/** + * 环境变量清洗 + home 重定向。 + * + * 核心:不是"在用户环境上追加",而是构造一个全新的最小环境对象。凭据/代理/ + * Python 劫持变量一律不继承;home 变量重定向到任务目录,使 SDK 的 + * expanduser("~/.dashscope/...") 解析到任务 home 而非真实 home。 + */ + +import { mkdirSync, writeFileSync } from "node:fs"; +import { join, win32 } from "node:path"; + +/** 构造最小环境所需的输入。 */ +export interface ISandboxEnvInput { + homeDir: string; + tmpDir: string; + cacheDir: string; + runtimeRoot: string; + apiKey: string; + baseUrl?: string; + proxyPort: number; + logLevel?: string; + /** 受控 SDK 环境变量(如 FC_PYPI_LIB),由黑盒显式注入,绝不从宿主继承。 */ + sdkEnv?: Record; + /** 目标平台,默认当前进程平台(便于跨平台单测)。 */ + platform?: NodeJS.Platform; + /** 宿主环境,仅用于挑选必要系统变量(SystemRoot/locale),默认 process.env。 */ + hostEnv?: Record; +} + +/** + * 构造全新最小环境。只包含注入项 + 必要系统变量;其余(DASHSCOPE_CONFIG、 + * DASHSCOPE_API_KEY_FILE_PATH、PYTHONPATH/PYTHONHOME、SSH_AUTH_SOCK、用户代理、 + * AWS / ALIBABA_CLOUD / AZURE 系列凭据变量等)因全新构造而天然不存在。 + */ +export function buildSandboxEnv(input: ISandboxEnvInput): Record { + const platform = input.platform ?? process.platform; + const hostEnv = input.hostEnv ?? process.env; + const proxyUrl = `http://127.0.0.1:${input.proxyPort}`; + const env: Record = {}; + + // 凭据:API Key 优先级最高,SDK 不回退读 api_key 文件。 + env.DASHSCOPE_API_KEY = input.apiKey; + if (input.baseUrl) env.DASHSCOPE_HTTP_BASE_URL = input.baseUrl; + + env.LOG_LEVEL = input.logLevel ?? "info"; + env.PYTHONDONTWRITEBYTECODE = "1"; + env.XDG_CACHE_HOME = input.cacheDir; + + // 受控 SDK 变量(如 FC_PYPI_LIB 钉住 FC 内安装的 dashscope 版本,与提交端锁步)。 + if (input.sdkEnv) Object.assign(env, input.sdkEnv); + + // 强制全部流量走本地白名单代理;NO_PROXY 为空不让任何域名绕过。 + env.HTTP_PROXY = proxyUrl; + env.HTTPS_PROXY = proxyUrl; + env.NO_PROXY = ""; + + const runtimeBin = join(input.runtimeRoot, "bin"); + if (platform === "win32") { + env.TEMP = input.tmpDir; + env.TMP = input.tmpDir; + // Windows 必须三变量一致指向任务 home,否则 expanduser 仍可能解析到真实 home。 + env.USERPROFILE = input.homeDir; + const root = win32.parse(input.homeDir).root; + const drive = /^[A-Za-z]:/.test(root) ? root.slice(0, 2) : ""; + env.HOMEDRIVE = drive; + env.HOMEPATH = drive ? input.homeDir.slice(drive.length) : input.homeDir; + const systemRoot = hostEnv.SystemRoot ?? hostEnv.windir ?? "C:\\Windows"; + env.SystemRoot = systemRoot; + env.windir = systemRoot; + env.PATH = `${input.runtimeRoot};${runtimeBin};${join(systemRoot, "System32")};${systemRoot}`; + } else { + env.TMPDIR = input.tmpDir; + env.HOME = input.homeDir; + env.PATH = `${runtimeBin}:/usr/bin:/bin`; + // 保留必要 locale,避免 SDK 编码异常。 + for (const localeKey of ["LANG", "LC_ALL"]) { + const localeValue = hostEnv[localeKey]; + if (localeValue) env[localeKey] = localeValue; + } + } + + return env; +} + +/** + * 预生成任务 home 下的 .dashscope/config.toml。 + * + * API Key 经环境变量注入(优先级最高),刻意不落盘以减少持久化秘密;此处仅 + * 写入非秘密设置(如企业 base_url),确保 SDK 读到受控配置而非回退真实 home。 + */ +export function prepareTaskHome(homeDir: string, baseUrl?: string): string { + const dashscopeDir = join(homeDir, ".dashscope"); + mkdirSync(dashscopeDir, { recursive: true }); + const configPath = join(dashscopeDir, "config.toml"); + const lines = ["# Managed by bailian CLI; credentials are injected via environment."]; + if (baseUrl) lines.push(`base_url = ${JSON.stringify(baseUrl)}`); + writeFileSync(configPath, `${lines.join("\n")}\n`, "utf8"); + return configPath; +} diff --git a/packages/core/src/isolation/index.ts b/packages/core/src/isolation/index.ts new file mode 100644 index 00000000..96d0919c --- /dev/null +++ b/packages/core/src/isolation/index.ts @@ -0,0 +1,12 @@ +export * from "./types.ts"; +export * from "./paths.ts"; +export * from "./env.ts"; +export * from "./snapshot.ts"; +export * from "./proxy.ts"; +export * from "./process.ts"; +export * from "./app-layer.ts"; +export * from "./cleanup.ts"; +export * from "./os-isolation/detect.ts"; +export * from "./os-isolation/darwin.ts"; +export * from "./os-isolation/linux.ts"; +export * from "./os-isolation/windows.ts"; diff --git a/packages/core/src/isolation/os-isolation/darwin.ts b/packages/core/src/isolation/os-isolation/darwin.ts new file mode 100644 index 00000000..a98533b7 --- /dev/null +++ b/packages/core/src/isolation/os-isolation/darwin.ts @@ -0,0 +1,120 @@ +/** + * macOS:sandbox-exec + SBPL deny-default。 + * + * 凭据禁读机制:(deny default) 默认拒绝一切读,只显式 allow 运行时与任务目录; + * 真实用户 home(含 ~/.dashscope)不在 allow 列表 → 子进程读它返回 EPERM。 + * 嵌套沙箱导致 sandbox-exec 不可用时凭据禁读无法强制 → fail-closed。 + */ + +import { spawnSync } from "node:child_process"; +import { existsSync, unlinkSync, writeFileSync } from "node:fs"; +import { join } from "node:path"; +import type { IIsolationAdapter, IIsolationCapability, IIsolationSpec } from "../types.ts"; + +const SANDBOX_EXEC = "/usr/bin/sandbox-exec"; + +/** SBPL 字符串字面量转义。 */ +function sbplQuote(path: string): string { + return `"${path.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"`; +} + +/** 生成 deny-default + 显式 allow 的 SBPL profile。 */ +export function buildSbplProfile(spec: IIsolationSpec): string { + const proxyPort = spec.proxyPort ?? 0; + const readPaths = [ + spec.runtimeRoot, + // cwd 由调用方指定(默认 taskDir,带代码包的命令为 deploy-copy),getcwd() 需读 cwd 目录本身; + // 两者都在读允许集,仅允许子目录会让 rich 等库的 os.getcwd() 报 EPERM。 + spec.taskDir, + spec.snapshotDir, + spec.dataDir, + spec.deployCopyDir, + spec.tmpDir, + spec.homeDir, + "/usr/lib", + "/System/Library", + "/private/var/db/dyld", + // 系统 CA 证书(ssl 默认 /private/etc/ssl/cert.pem):放行才能做 TLS 证书校验, + // 否则 SDK 上传/注册函数报 CERTIFICATE_VERIFY_FAILED。与 linux 绑定 /etc/ssl/certs 对齐。 + "/private/etc/ssl", + ]; + const writePaths = [spec.deployCopyDir, spec.tmpDir, spec.homeDir]; + + const readRules = readPaths.map((path) => ` (subpath ${sbplQuote(path)})`).join("\n"); + const writeRules = writePaths.map((path) => ` (subpath ${sbplQuote(path)})`).join("\n"); + + return `(version 1) +(deny default) +(allow file-read* +${readRules} + (literal ${sbplQuote(spec.configPath)}) + (literal "/dev/urandom") + (literal "/dev/null") + ; 根目录读权限:dyld 启动解析绝对路径需读根 inode,缺失则解释器 SIGABRT(exit 134)且无输出。 + ; 仅放开根目录自身(readdir/stat),不放开任意文件,真实 home/凭据仍被 deny-default 禁读。 + (literal "/")) +(allow file-write* +${writeRules}) +(allow network-outbound (remote tcp "localhost:${proxyPort}")) +(allow process-exec (subpath ${sbplQuote(spec.runtimeRoot)})) +(allow process-fork) +(allow sysctl-read) +(allow mach-lookup) +`; +} + +/** 探测 sandbox-exec 是否可用(非嵌套沙箱)。 */ +export function probeSandboxExec(): IIsolationCapability { + const hardening = { networkEnforce: true, processTree: true, memoryLimit: false }; + if (!existsSync(SANDBOX_EXEC)) { + return { + credentialDenyRead: { + available: false, + mechanism: "sbpl", + reason: "sandbox-exec not found.", + }, + hardening: { networkEnforce: false, processTree: false, memoryLimit: false }, + }; + } + const probe = spawnSync(SANDBOX_EXEC, ["-p", "(version 1)(allow default)", "/usr/bin/true"], { + shell: false, + timeout: 10_000, + }); + if (probe.status === 0) { + return { credentialDenyRead: { available: true, mechanism: "sbpl" }, hardening }; + } + return { + credentialDenyRead: { + available: false, + mechanism: "sbpl", + reason: "sandbox-exec is unavailable (nested sandbox or restricted host).", + }, + hardening: { networkEnforce: false, processTree: false, memoryLimit: false }, + }; +} + +/** 创建 macOS 适配器。 */ +export function createDarwinAdapter(): IIsolationAdapter { + let profilePath: string | undefined; + return { + detect: async () => probeSandboxExec(), + prepare: async (spec) => { + profilePath = join(spec.taskDir, "profile.sb"); + writeFileSync(profilePath, buildSbplProfile(spec), "utf8"); + }, + wrapCommand: (spec, command) => { + const profile = profilePath ?? join(spec.taskDir, "profile.sb"); + return [SANDBOX_EXEC, "-f", profile, ...command]; + }, + dispose: async () => { + if (profilePath && existsSync(profilePath)) { + try { + unlinkSync(profilePath); + } catch { + // 清理失败不影响结果 + } + } + profilePath = undefined; + }, + }; +} diff --git a/packages/core/src/isolation/os-isolation/detect.ts b/packages/core/src/isolation/os-isolation/detect.ts new file mode 100644 index 00000000..b823addc --- /dev/null +++ b/packages/core/src/isolation/os-isolation/detect.ts @@ -0,0 +1,50 @@ +/** + * 平台探测分派。 + * + * 按 process.platform 选择 OS 适配器;硬性凭据禁读与增强能力由各适配器分开判定。 + * 平台差异收敛在此分派与各适配层内部,上层逻辑无平台分支。 + */ + +import type { IIsolationAdapter, IIsolationCapability } from "../types.ts"; +import { createDarwinAdapter } from "./darwin.ts"; +import { createLinuxAdapter } from "./linux.ts"; +import { createWindowsAdapter } from "./windows.ts"; + +function createUnsupportedAdapter(platform: string): IIsolationAdapter { + return { + detect: async () => ({ + credentialDenyRead: { + available: false, + mechanism: "none", + reason: `Not supported on ${platform} yet.`, + }, + hardening: { networkEnforce: false, processTree: false, memoryLimit: false }, + }), + prepare: async () => {}, + wrapCommand: (_spec, command) => command, + dispose: async () => {}, + }; +} + +/** 按平台创建 OS 隔离适配器。 */ +export function createIsolationAdapter( + platform: NodeJS.Platform = process.platform, +): IIsolationAdapter { + switch (platform) { + case "darwin": + return createDarwinAdapter(); + case "linux": + return createLinuxAdapter(); + case "win32": + return createWindowsAdapter(); + default: + return createUnsupportedAdapter(platform); + } +} + +/** 探测当前(或指定)平台的隔离能力。 */ +export async function detectIsolation( + platform: NodeJS.Platform = process.platform, +): Promise { + return createIsolationAdapter(platform).detect(); +} diff --git a/packages/core/src/isolation/os-isolation/linux.ts b/packages/core/src/isolation/os-isolation/linux.ts new file mode 100644 index 00000000..7fdf111a --- /dev/null +++ b/packages/core/src/isolation/os-isolation/linux.ts @@ -0,0 +1,81 @@ +/** + * Linux:bwrap 不挂载真实 home。 + * + * 凭据禁读机制:bwrap 只挂载运行时与任务目录(按真实路径绑定,避免 YAML 路径 + * 重写),真实用户 home(含 ~/.dashscope)根本不进入挂载命名空间 → 子进程读不到。 + * 用户命名空间被禁用时凭据禁读无法强制 → fail-closed。 + * + * 网络:首版走应用层白名单代理(networkEnforce 降级为 false);--unshare-net + + * socat/Unix socket 的内核级断网是延后增强(随运行时捆绑 socat 后启用)。 + */ + +import { spawnSync } from "node:child_process"; +import { existsSync } from "node:fs"; +import type { IIsolationAdapter, IIsolationCapability, IIsolationSpec } from "../types.ts"; + +/** 需要只读绑定的系统目录(存在才绑定)。 */ +const SYSTEM_RO_DIRS = ["/usr", "/lib", "/lib64", "/etc/ssl/certs"]; + +/** 生成 bwrap 参数:只绑定运行时与任务目录,绝不绑定真实 home。 */ +export function buildBwrapArgs(spec: IIsolationSpec, command: string[]): string[] { + const args: string[] = ["--unshare-pid", "--die-with-parent"]; + + for (const sysDir of SYSTEM_RO_DIRS) { + if (existsSync(sysDir)) args.push("--ro-bind", sysDir, sysDir); + } + + // 运行时只读;任务目录按真实路径绑定(snapshot/data 只读,deploy-copy/tmp/home 可写)。 + args.push("--ro-bind", spec.runtimeRoot, spec.runtimeRoot); + args.push("--ro-bind", spec.snapshotDir, spec.snapshotDir); + args.push("--ro-bind", spec.dataDir, spec.dataDir); + args.push("--bind", spec.deployCopyDir, spec.deployCopyDir); + args.push("--bind", spec.tmpDir, spec.tmpDir); + args.push("--bind", spec.homeDir, spec.homeDir); + args.push("--ro-bind", spec.configPath, spec.configPath); + args.push("--proc", "/proc", "--dev", "/dev"); + + args.push("--", ...command); + return args; +} + +/** 探测 bwrap 存在且用户命名空间可用。 */ +export function probeBwrap(): IIsolationCapability { + const hardening = { networkEnforce: false, processTree: true, memoryLimit: false }; + const probe = spawnSync("bwrap", ["--ro-bind", "/", "/", "--", "/bin/true"], { + shell: false, + timeout: 10_000, + }); + if (probe.error && (probe.error as NodeJS.ErrnoException).code === "ENOENT") { + return { + credentialDenyRead: { + available: false, + mechanism: "bwrap-nobind", + reason: "bwrap is not installed.", + }, + hardening: { networkEnforce: false, processTree: false, memoryLimit: false }, + }; + } + if (probe.status === 0) { + return { credentialDenyRead: { available: true, mechanism: "bwrap-nobind" }, hardening }; + } + return { + credentialDenyRead: { + available: false, + mechanism: "bwrap-nobind", + reason: "bwrap cannot create a user namespace (disabled or restricted host).", + }, + hardening: { networkEnforce: false, processTree: false, memoryLimit: false }, + }; +} + +/** 创建 Linux 适配器。 */ +export function createLinuxAdapter(): IIsolationAdapter { + return { + detect: async () => probeBwrap(), + prepare: async () => { + // bwrap 参数在 wrapCommand 内即时生成,无需预写资源。 + }, + wrapCommand: (spec, command) => ["bwrap", ...buildBwrapArgs(spec, command)], + dispose: async () => {}, + }; +} diff --git a/packages/core/src/isolation/os-isolation/windows.ts b/packages/core/src/isolation/os-isolation/windows.ts new file mode 100644 index 00000000..a89e95cd --- /dev/null +++ b/packages/core/src/isolation/os-isolation/windows.ts @@ -0,0 +1,30 @@ +/** + * Windows:AppContainer fail-closed 占位。 + * + * 凭据禁读须用 AppContainer(不是 Job Object——后者只管进程/资源,不管文件路径), + * 需 N-API 原生模块(CreateAppContainerProfile / SetSecurityInfo / CreateProcess + + * SECURITY_CAPABILITIES)。原生模块与 Python DLL/代理/三库兼容性实测列为延后项。 + * 当前 win32 上 detect 返回不可用 → app-layer fail-closed, + * 不创建任何云资源。接口预留,待原生模块落地后替换实现。 + */ + +import type { IIsolationAdapter } from "../types.ts"; + +/** 创建 Windows 适配器(当前 fail-closed 占位)。 */ +export function createWindowsAdapter(): IIsolationAdapter { + return { + detect: async () => ({ + credentialDenyRead: { + available: false, + mechanism: "appcontainer", + reason: "Not supported on Windows yet.", + }, + hardening: { networkEnforce: false, processTree: false, memoryLimit: false }, + }), + prepare: async () => { + // 占位:原生模块落地后在此创建 AppContainer profile 并授权自建目录 SID。 + }, + wrapCommand: (_spec, command) => command, + dispose: async () => {}, + }; +} diff --git a/packages/core/src/isolation/paths.ts b/packages/core/src/isolation/paths.ts new file mode 100644 index 00000000..192e41ed --- /dev/null +++ b/packages/core/src/isolation/paths.ts @@ -0,0 +1,80 @@ +/** + * 任务目录与运行时目录布局。 + * + * 数据目录统一经 getConfigDir() 派生(仓库约定,全平台一致,不做平台分支): + * runs// 随调用结束立即销毁(app-layer finally);崩溃路径孤儿由 + * runtime clean / prepare 按 TTL 兜底回收(见 cleanup.ts)。 + */ + +import { randomBytes } from "node:crypto"; +import { mkdirSync } from "node:fs"; +import { join } from "node:path"; +import { getConfigDir } from "../config/paths.ts"; + +/** 一次任务的目录布局。 */ +export interface ITaskDirLayout { + runId: string; + taskDir: string; + snapshotDir: string; + dataDir: string; + deployCopyDir: string; + tmpDir: string; + homeDir: string; + dashscopeDir: string; + cacheDir: string; + configPath: string; + resultPath: string; +} + +/** 生成随机 run-id(不依赖时间戳,避免可预测)。 */ +export function newRunId(): string { + return randomBytes(8).toString("hex"); +} + +export function runsRoot(): string { + return join(getConfigDir(), "runs"); +} + +/** 创建任务目录骨架(含 home/.dashscope),返回布局。 */ +export function createTaskDir(runId: string = newRunId()): ITaskDirLayout { + const taskDir = join(runsRoot(), runId); + const layout: ITaskDirLayout = { + runId, + taskDir, + snapshotDir: join(taskDir, "snapshot"), + dataDir: join(taskDir, "data"), + deployCopyDir: join(taskDir, "deploy-copy"), + tmpDir: join(taskDir, "tmp"), + homeDir: join(taskDir, "home"), + dashscopeDir: join(taskDir, "home", ".dashscope"), + cacheDir: join(taskDir, "cache"), + configPath: join(taskDir, "config.yaml"), + resultPath: join(taskDir, "result.json"), + }; + for (const dir of [ + layout.snapshotDir, + layout.dataDir, + layout.deployCopyDir, + layout.tmpDir, + layout.dashscopeDir, + layout.cacheDir, + ]) { + mkdirSync(dir, { recursive: true }); + } + return layout; +} + +/** 托管运行时安装目录:/runtimes/rl//。 */ +export function runtimeRoot(runtimeId: string): string { + return join(managedRuntimesRoot(), runtimeId); +} + +/** 托管运行时版本目录的根:/runtimes/rl/(旧版本回收的扫描范围)。 */ +export function managedRuntimesRoot(): string { + return join(getConfigDir(), "runtimes", "rl"); +} + +/** 运行时下载缓存目录。 */ +export function runtimeCacheRoot(): string { + return join(getConfigDir(), "cache", "rl"); +} diff --git a/packages/core/src/isolation/process.ts b/packages/core/src/isolation/process.ts new file mode 100644 index 00000000..7e7bf5ad --- /dev/null +++ b/packages/core/src/isolation/process.ts @@ -0,0 +1,131 @@ +/** + * 进程启动 / 超时 / 输出限额 / 进程树管理。 + * + * 参数数组 + shell:false(绝不经过 shell);POSIX 用 detached 进程组以便整组 + * kill;墙钟超时与输出超限均杀进程;支持 AbortSignal 中断(命令层接 SIGINT)。 + * OS 强制由 wrapCommand 钩子注入(darwin sandbox-exec / linux bwrap)。 + */ + +import { spawn } from "node:child_process"; +import { BailianError } from "../errors/base.ts"; +import { ExitCode } from "../errors/codes.ts"; + +export interface IProcessOptions { + /** 完整 argv,含解释器,如 [python, -I, -m, dashscope, ...]。 */ + command: string[]; + env: Record; + cwd: string; + timeoutMs: number; + maxOutputBytes: number; + /** OS 包装:把原始 argv 转成沙箱 argv;缺省直接执行。 */ + wrapCommand?: (command: string[]) => string[]; + signal?: AbortSignal; + onStdout?: (chunk: string) => void; + onStderr?: (chunk: string) => void; +} + +export interface IProcessResult { + exitCode: number | null; + signal: string | null; + stdout: string; + stderr: string; + timedOut: boolean; +} + +/** 杀进程树:POSIX 杀进程组,Windows 用 taskkill /T /F 兜底。 */ +function killProcessTree(pid: number | undefined, platform: NodeJS.Platform): void { + if (pid === undefined) return; + if (platform === "win32") { + spawn("taskkill", ["/pid", String(pid), "/T", "/F"], { shell: false, windowsHide: true }); + return; + } + try { + process.kill(-pid, "SIGKILL"); + } catch { + try { + process.kill(pid, "SIGKILL"); + } catch { + // 进程已退出 + } + } +} + +/** 启动受控子进程,收集 stdout/stderr,按超时/输出限额/中断杀进程。 */ +export function runSandboxedProcess(options: IProcessOptions): Promise { + const argv = options.wrapCommand ? options.wrapCommand(options.command) : options.command; + const [executable, ...args] = argv; + const platform = process.platform; + + return new Promise((resolve, reject) => { + const child = spawn(executable, args, { + env: options.env, + cwd: options.cwd, + shell: false, + windowsHide: true, + stdio: ["pipe", "pipe", "pipe"], + detached: platform !== "win32", + }); + + let stdout = ""; + let stderr = ""; + let stdoutBytes = 0; + let stderrBytes = 0; + let timedOut = false; + let settled = false; + + const timer = setTimeout(() => { + timedOut = true; + killProcessTree(child.pid, platform); + }, options.timeoutMs); + + const onAbort = (): void => killProcessTree(child.pid, platform); + options.signal?.addEventListener("abort", onAbort, { once: true }); + + const cleanup = (): void => { + clearTimeout(timer); + options.signal?.removeEventListener("abort", onAbort); + }; + + child.stdout?.on("data", (chunk: Buffer) => { + stdoutBytes += chunk.length; + if (stdoutBytes <= options.maxOutputBytes) { + const text = chunk.toString("utf8"); + stdout += text; + options.onStdout?.(text); + } else { + killProcessTree(child.pid, platform); + } + }); + child.stderr?.on("data", (chunk: Buffer) => { + stderrBytes += chunk.length; + if (stderrBytes <= options.maxOutputBytes) { + const text = chunk.toString("utf8"); + stderr += text; + options.onStderr?.(text); + } else { + killProcessTree(child.pid, platform); + } + }); + + child.on("error", (error) => { + if (settled) return; + settled = true; + cleanup(); + reject( + new BailianError( + `Failed to start sandboxed process: ${error.message}`, + ExitCode.GENERAL, + "Check the managed runtime via the runtime doctor command.", + { cause: error }, + ), + ); + }); + + child.on("close", (code, signal) => { + if (settled) return; + settled = true; + cleanup(); + resolve({ exitCode: code, signal, stdout, stderr, timedOut }); + }); + }); +} diff --git a/packages/core/src/isolation/proxy.ts b/packages/core/src/isolation/proxy.ts new file mode 100644 index 00000000..723c77e9 --- /dev/null +++ b/packages/core/src/isolation/proxy.ts @@ -0,0 +1,183 @@ +/** + * 本地白名单代理。 + * + * SDK 三库(aiohttp/requests/httpx)均 trust_env=True,设 HTTP_PROXY/HTTPS_PROXY + * 即可接管全部流量。代理只监听 127.0.0.1,仅放行 CONNECT 443 到管理面精确域名 + * 与 OSS 后缀白名单;DNS 解析后拒绝私网/loopback/link-local/metadata IP(防 + * rebinding);拒绝明文 HTTP;日志只记 host:port,不记路径/body(避免泄露签名)。 + */ + +import { lookup } from "node:dns/promises"; +import { createServer, type Server } from "node:http"; +import { connect as netConnect, isIP } from "node:net"; +import type { Duplex } from "node:stream"; +import type { IProxyPolicy } from "./types.ts"; + +/** 默认策略:管理面精确域名 + 全区域 OSS 后缀 + 仅 443。 */ +export const DEFAULT_PROXY_POLICY: IProxyPolicy = { + managementDomains: ["dashscope.aliyuncs.com"], + ossSuffixes: [".oss-*.aliyuncs.com", ".oss.aliyuncs.com"], + allowedPorts: [443], +}; + +export interface IProxyEvent { + type: "allow" | "deny"; + host: string; + port: number; +} + +export interface IWhitelistProxy { + port: number; + close(): Promise; +} + +export interface IProxyOptions { + policy?: IProxyPolicy; + /** 仅 host:port 级别事件,供诊断/测试;默认无操作。 */ + onEvent?: (event: IProxyEvent) => void; +} + +/** 判断 IP 是否属于禁止目标(私网/loopback/link-local/metadata/保留)。 */ +export function isDeniedIp(ip: string): boolean { + const version = isIP(ip); + if (version === 4) { + const [first, second] = ip.split(".").map(Number); + if (first === 0 || first === 10 || first === 127) return true; + if (first === 169 && second === 254) return true; // link-local + metadata + if (first === 172 && second >= 16 && second <= 31) return true; + if (first === 192 && second === 168) return true; + if (first >= 224) return true; // multicast / reserved + return false; + } + if (version === 6) { + const lower = ip.toLowerCase(); + if (lower === "::1" || lower === "::") return true; + if (lower.startsWith("::ffff:")) return isDeniedIp(lower.slice(7)); + if (lower.startsWith("fe80")) return true; // link-local + if (lower.startsWith("fc") || lower.startsWith("fd")) return true; // unique-local + return false; + } + return true; // 无法识别一律拒绝 +} + +function matchesManagement(host: string, domains: string[]): boolean { + return domains.some((domain) => host === domain.toLowerCase()); +} + +/** + * 将用户配置的服务端点 host 并入管理面白名单(返回新策略,不改原对象)。 + * 默认白名单只含legacy dashscope.aliyuncs.com;workspace 网关(ws-*..maas.aliyuncs.com) + * 等自定义 base_url 不在其中,SDK 经代理访问会被 403。仅放行精确 host,不放开后缀。 + */ +export function withEndpointDomain(policy: IProxyPolicy, baseUrl?: string): IProxyPolicy { + if (!baseUrl) return policy; + let host: string; + try { + host = new URL(baseUrl).hostname.toLowerCase(); + } catch { + return policy; + } + if (!host || policy.managementDomains.includes(host)) return policy; + return { ...policy, managementDomains: [...policy.managementDomains, host] }; +} + +function matchesOssSuffix(host: string, suffixes: string[]): boolean { + return suffixes.some((suffix) => { + if (suffix.includes("*")) { + const escaped = suffix.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, "[a-z0-9-]+"); + return new RegExp(`${escaped}$`).test(host); + } + return host.endsWith(suffix); + }); +} + +function isAllowedHost(host: string, policy: IProxyPolicy): boolean { + const normalized = host.toLowerCase(); + return ( + matchesManagement(normalized, policy.managementDomains) || + matchesOssSuffix(normalized, policy.ossSuffixes) + ); +} + +function splitHostPort(target: string): { host: string; port: number } { + const lastColon = target.lastIndexOf(":"); + if (lastColon <= 0) return { host: target, port: NaN }; + return { host: target.slice(0, lastColon), port: Number(target.slice(lastColon + 1)) }; +} + +/** 解析并校验目标 IP;任一地址被禁则拒绝,返回首个可用地址。 */ +async function resolveAllowedAddress(host: string): Promise { + if (isIP(host)) { + if (isDeniedIp(host)) throw new Error("denied ip"); + return host; + } + const addresses = await lookup(host, { all: true, verbatim: true }); + if (addresses.length === 0) throw new Error("no address"); + if (addresses.some((entry) => isDeniedIp(entry.address))) throw new Error("denied ip"); + return addresses[0].address; +} + +/** 启动白名单代理,监听 127.0.0.1 随机端口。 */ +export function startWhitelistProxy(options: IProxyOptions = {}): Promise { + const policy = options.policy ?? DEFAULT_PROXY_POLICY; + const emit = options.onEvent ?? (() => {}); + const sockets = new Set(); + + const track = (socket: Duplex): void => { + sockets.add(socket); + socket.on("close", () => sockets.delete(socket)); + socket.on("error", () => socket.destroy()); + }; + + const server: Server = createServer(); + server.on("connect", (req, clientSocket, head) => { + track(clientSocket); + const { host, port } = splitHostPort(req.url ?? ""); + if (!host || !policy.allowedPorts.includes(port) || !isAllowedHost(host, policy)) { + emit({ type: "deny", host, port }); + clientSocket.write("HTTP/1.1 403 Forbidden\r\n\r\n"); + clientSocket.destroy(); + return; + } + resolveAllowedAddress(host) + .then((address) => { + const upstream = netConnect({ host: address, port }, () => { + emit({ type: "allow", host, port }); + clientSocket.write("HTTP/1.1 200 Connection Established\r\n\r\n"); + if (head.length > 0) upstream.write(head); + upstream.pipe(clientSocket); + clientSocket.pipe(upstream); + }); + track(upstream); + upstream.on("error", () => clientSocket.destroy()); + }) + .catch(() => { + emit({ type: "deny", host, port }); + clientSocket.write("HTTP/1.1 403 Forbidden\r\n\r\n"); + clientSocket.destroy(); + }); + }); + + // 明文 HTTP 一律拒绝(SDK 全走 HTTPS)。 + server.on("request", (_req, res) => { + res.writeHead(403, { "Content-Type": "text/plain" }); + res.end("Forbidden"); + }); + + return new Promise((resolve, reject) => { + server.once("error", reject); + server.listen(0, "127.0.0.1", () => { + const address = server.address(); + const port = typeof address === "object" && address ? address.port : 0; + resolve({ + port, + close: () => + new Promise((resolveClose) => { + for (const socket of sockets) socket.destroy(); + sockets.clear(); + server.close(() => resolveClose()); + }), + }); + }); + }); +} diff --git a/packages/core/src/isolation/snapshot.ts b/packages/core/src/isolation/snapshot.ts new file mode 100644 index 00000000..b9ac404a --- /dev/null +++ b/packages/core/src/isolation/snapshot.ts @@ -0,0 +1,158 @@ +/** + * 文件快照 + deploy-copy + 数据暂存。 + * + * SDK 的 zip_dir() 会递归读取整个 zipdir 并写 start.sh,因此不能直接指向用户 + * 原工程:先按 include/exclude 复制到只读 snapshot/,再复制出可写 deploy-copy/ + * 供 SDK 落 start.sh;数据单独复制到 data/。内置安全排除 + 拒绝符号链接。 + */ + +import { copyFileSync, cpSync, lstatSync, mkdirSync, readdirSync, statSync } from "node:fs"; +import { basename, join, relative, sep } from "node:path"; +import { BailianError } from "../errors/base.ts"; +import { ExitCode } from "../errors/codes.ts"; + +/** 目录级安全排除(任意路径段命中即排除)。 */ +const SAFETY_EXCLUDE_DIRS = new Set([".git", ".venv", "node_modules", "__pycache__"]); +/** 文件级安全排除(basename 命中即排除)。 */ +const SAFETY_EXCLUDE_FILE_PATTERNS = [/^\.env/, /\.pem$/, /\.key$/]; +/** 默认包大小上限(字节)。 */ +const DEFAULT_MAX_PACKAGE_BYTES = 200 * 1024 * 1024; + +export interface ISnapshotOptions { + sourceDir: string; + snapshotDir: string; + deployCopyDir: string; + include?: string[]; + exclude?: string[]; + maxPackageBytes?: number; +} + +export interface ISnapshotResult { + fileCount: number; + totalBytes: number; + /** 相对 sourceDir 的 posix 路径列表(上传摘要)。 */ + files: string[]; +} + +/** 最小 glob 匹配器:支持 ** / * / ?,路径按 posix 分隔符匹配。 */ +function globToRegExp(glob: string): RegExp { + const normalized = glob.replace(/\\/g, "/"); + let pattern = ""; + for (let index = 0; index < normalized.length; index++) { + const char = normalized[index]; + if (char === "*") { + if (normalized[index + 1] === "*") { + pattern += ".*"; + index++; + if (normalized[index + 1] === "/") index++; + } else { + pattern += "[^/]*"; + } + } else if (char === "?") { + pattern += "[^/]"; + } else { + pattern += char.replace(/[.+^${}()|[\]\\]/g, "\\$&"); + } + } + return new RegExp(`^${pattern}$`); +} + +function matchesAny(relativePath: string, globs: string[] | undefined): boolean { + if (!globs || globs.length === 0) return false; + return globs.some((glob) => globToRegExp(glob).test(relativePath)); +} + +function isSafetyExcluded(relativePath: string, isDir: boolean): boolean { + const segments = relativePath.split("/"); + if (segments.some((segment) => SAFETY_EXCLUDE_DIRS.has(segment))) return true; + if (!isDir) { + const name = segments[segments.length - 1]; + if (SAFETY_EXCLUDE_FILE_PATTERNS.some((pattern) => pattern.test(name))) return true; + } + return false; +} + +function toPosix(path: string): string { + return sep === "/" ? path : path.split(sep).join("/"); +} + +/** 拒绝符号链接(Windows 下 junction 同样被 lstat 识别为符号链接)。 */ +function assertNotSymlink(entryPath: string): void { + const stat = lstatSync(entryPath); + if (stat.isSymbolicLink()) { + throw new BailianError( + `Refusing to snapshot symlink: ${entryPath}`, + ExitCode.USAGE, + "Remove symlinks from the source directory; they may escape the upload scope.", + ); + } +} + +/** + * 复制源码到 snapshot/ 并生成可写 deploy-copy/。返回上传摘要。 + */ +export function createSnapshot(options: ISnapshotOptions): ISnapshotResult { + const { sourceDir, snapshotDir, deployCopyDir } = options; + const maxBytes = options.maxPackageBytes ?? DEFAULT_MAX_PACKAGE_BYTES; + const files: string[] = []; + let totalBytes = 0; + + mkdirSync(snapshotDir, { recursive: true }); + + const walk = (dir: string): void => { + for (const entry of readdirSync(dir)) { + const entryPath = join(dir, entry); + assertNotSymlink(entryPath); + const stat = lstatSync(entryPath); + const relativePath = toPosix(relative(sourceDir, entryPath)); + const isDir = stat.isDirectory(); + + if (isSafetyExcluded(relativePath, isDir)) continue; + if (matchesAny(relativePath, options.exclude)) continue; + // include 为空表示全部纳入;否则仅纳入命中项(目录始终遍历以深入匹配)。 + if (!isDir && options.include && options.include.length > 0) { + if (!matchesAny(relativePath, options.include)) continue; + } + + if (isDir) { + walk(entryPath); + } else { + const size = statSync(entryPath).size; + totalBytes += size; + if (totalBytes > maxBytes) { + throw new BailianError( + `Source package exceeds the ${maxBytes} byte limit.`, + ExitCode.USAGE, + "Narrow --include or add --exclude to reduce the upload size.", + ); + } + const destPath = join(snapshotDir, relativePath); + mkdirSync(join(destPath, ".."), { recursive: true }); + copyFileSync(entryPath, destPath); + files.push(relativePath); + } + } + }; + + walk(sourceDir); + + // deploy-copy 是 snapshot 的可写副本,SDK 的 zipdir 指向它(start.sh 落此)。 + cpSync(snapshotDir, deployCopyDir, { recursive: true }); + + return { fileCount: files.length, totalBytes, files }; +} + +/** + * 将数据文件单独复制到 data/(不混进代码包)。返回暂存后的绝对路径。 + */ +export function stageDataFiles(files: string[], dataDir: string): string[] { + mkdirSync(dataDir, { recursive: true }); + const staged: string[] = []; + for (const file of files) { + assertNotSymlink(file); + const destPath = join(dataDir, basename(file)); + copyFileSync(file, destPath); + staged.push(destPath); + } + return staged; +} diff --git a/packages/core/src/isolation/types.ts b/packages/core/src/isolation/types.ts new file mode 100644 index 00000000..28e55489 --- /dev/null +++ b/packages/core/src/isolation/types.ts @@ -0,0 +1,89 @@ +/** + * 隔离层类型契约。 + * + * 两层隔离:确定性应用层(全平台必选)+ OS 强制(环境闭环硬性 fail-closed, + * 其余增强可降级)。平台差异收敛在 os-isolation/ 适配层,上层逻辑无平台分支。 + */ + +/** 本地白名单代理策略。 */ +export interface IProxyPolicy { + /** 管理面精确域名,如 dashscope.aliyuncs.com。 */ + managementDomains: string[]; + /** OSS 域名后缀白名单,如 .oss-cn-beijing.aliyuncs.com。 */ + ossSuffixes: string[]; + /** 允许的 CONNECT 端口,首版仅 443。 */ + allowedPorts: number[]; +} + +/** 一次隔离执行的完整输入。 */ +export interface IIsolationSpec { + runId: string; + /** 托管 Python + SDK 目录。 */ + runtimeRoot: string; + /** /runs/。 */ + taskDir: string; + snapshotDir: string; + deployCopyDir: string; + dataDir: string; + /** 重定向的 HOME/USERPROFILE。 */ + homeDir: string; + tmpDir: string; + cacheDir: string; + configPath: string; + /** [python, -I, -m, dashscope, ...]。 */ + command: string[]; + /** 注入用,绝不进日志。 */ + apiKey: string; + /** 企业 profile 指定时才注入 DASHSCOPE_HTTP_BASE_URL。 */ + baseUrl?: string; + /** 真实凭据路径,OS 禁读目标(如真实 ~/.dashscope)。 */ + credentialDenyPaths: string[]; + network: IProxyPolicy; + /** 本地代理端口(app-layer 启动代理后回填,供 OS 网络放行)。 */ + proxyPort?: number; + timeoutMs: number; + maxOutputBytes: number; + logLevel?: string; + /** 受控 SDK 环境变量(如 FC_PYPI_LIB),由黑盒显式注入,绝不从宿主继承。 */ + sdkEnv?: Record; +} + +/** 增强能力实际启用情况(可降级,不阻断)。 */ +export interface IIsolationHardening { + networkEnforce: boolean; + processTree: boolean; + memoryLimit: boolean; +} + +/** 平台探测结果:硬性凭据禁读与增强分开判定。 */ +export interface IIsolationCapability { + credentialDenyRead: { + available: boolean; + mechanism: "sbpl" | "bwrap-nobind" | "appcontainer" | "none"; + reason?: string; + }; + hardening: IIsolationHardening; +} + +/** 一次隔离执行的结果。 */ +export interface IIsolationResult { + exitCode: number | null; + signal: string | null; + stdout: string; + stderr: string; + timedOut: boolean; + /** 凭据禁读是否由 OS 强制(硬性,必须 true 才执行)。 */ + credentialDenyEnforced: boolean; + hardening: IIsolationHardening; +} + +/** OS 适配层统一接口。app-layer 负责编排,OS 层只注入强制 argv 与资源准备。 */ +export interface IIsolationAdapter { + /** 探测凭据禁读能力;不可用则 run 前 fail-closed。 */ + detect(): Promise; + /** OS 资源准备(如写 SBPL profile、授权 SID)。 */ + prepare(spec: IIsolationSpec): Promise; + /** 把原始 argv 包装成 OS 强制 argv(sandbox-exec / bwrap);无包装原样返回。 */ + wrapCommand(spec: IIsolationSpec, command: string[]): string[]; + dispose(): Promise; +} diff --git a/packages/core/src/rl-runtime/doctor.ts b/packages/core/src/rl-runtime/doctor.ts new file mode 100644 index 00000000..559502fa --- /dev/null +++ b/packages/core/src/rl-runtime/doctor.ts @@ -0,0 +1,319 @@ +/** + * Runtime and sandbox self-check. + * + * Required checks (security baseline): credential-isolation mechanism probe, managed Python boot, SDK import, home + * redirect in effect, closed-loop negative test (reading real credentials inside the sandbox must fail), proxy denies unrelated domains. Enhanced checks + * (kernel network enforcement / process tree / memory / host network reachability) degrade with a notice when unavailable and never fail the report. When the runtime is missing, + * related checks are marked skip (not treated as passed) and overall ok=false. + */ + +import { connect as netConnect } from "node:net"; +import { probeTcpHost } from "../client/network-diagnostics.ts"; +import { BailianError } from "../errors/base.ts"; +import { ExitCode } from "../errors/codes.ts"; +import { executeIsolatedRun } from "../isolation/app-layer.ts"; +import { createTaskDir } from "../isolation/paths.ts"; +import { startWhitelistProxy } from "../isolation/proxy.ts"; +import { createIsolationAdapter } from "../isolation/os-isolation/detect.ts"; +import type { IIsolationAdapter } from "../isolation/types.ts"; +import type { IResolvedRuntime } from "./manager.ts"; + +/** Single check result. */ +export interface IDoctorCheck { + name: string; + /** Required fail/skip fails the report; enhanced degradation does not block. */ + required: boolean; + status: "pass" | "fail" | "degraded" | "skip"; + detail?: string; +} + +export interface IDoctorReport { + checks: IDoctorCheck[]; + /** True only when every required check passes. */ + ok: boolean; +} + +export interface IDoctorOptions { + /** Resolved runtime; when missing, runtime-related checks are skipped. */ + runtime?: IResolvedRuntime; + /** Real credential paths (targets of the closed-loop negative test), e.g. the real ~/.dashscope. */ + credentialDenyPaths?: string[]; + adapter?: IIsolationAdapter; + platform?: NodeJS.Platform; + /** Per-self-check timeout (ms). */ + timeoutMs?: number; + /** Whether to probe host outbound network reachability (enhanced; off by default so doctor stays usable offline). */ + checkHostNetwork?: boolean; + /** Host network probe targets (defaults to the API / CPython download / PyPI host trio). */ + hostNetworkTargets?: { host: string; port: number }[]; + /** Probe injection seam (unit tests inject results, no real outbound); returns an errno, or undefined for success. */ + hostNetworkProbe?: (host: string, port: number) => Promise; +} + +const SELF_CHECK_TIMEOUT_MS = 30_000; +const SELF_CHECK_MAX_OUTPUT = 1024 * 1024; + +/** Default host network preflight targets: the submit / download / pip outbound dependencies. */ +const HOST_NETWORK_TARGETS = [ + { host: "dashscope.aliyuncs.com", port: 443 }, + { host: "github.com", port: 443 }, + { host: "pypi.org", port: 443 }, +]; +const HOST_NETWORK_TIMEOUT_MS = 5_000; + +/** CONNECT to the target through the proxy; returns whether it was denied with 403 (real loopback assertion). */ +async function proxyDenies(port: number, target: string): Promise { + return new Promise((resolve, reject) => { + const socket = netConnect({ host: "127.0.0.1", port }, () => { + socket.write(`CONNECT ${target} HTTP/1.1\r\nHost: ${target}\r\n\r\n`); + }); + let buffer = ""; + socket.on("data", (chunk: Buffer) => { + buffer += chunk.toString("utf8"); + if (buffer.includes("\r\n\r\n")) { + socket.destroy(); + resolve(buffer.includes("403")); + } + }); + socket.on("error", reject); + socket.setTimeout(5_000, () => { + socket.destroy(); + resolve(false); + }); + }); +} + +/** Run doctor and return the per-check report. */ +export async function runRuntimeDoctor(options: IDoctorOptions = {}): Promise { + const platform = options.platform ?? process.platform; + const adapter = options.adapter ?? createIsolationAdapter(platform); + const timeoutMs = options.timeoutMs ?? SELF_CHECK_TIMEOUT_MS; + const checks: IDoctorCheck[] = []; + + // 1. Credential-isolation mechanism probe (hard requirement). Probe with the adapter actually used for execution, + // so the mechanism verdict matches later sandbox runs (including injected custom adapters). + const capability = await adapter.detect(); + const mechanismAvailable = capability.credentialDenyRead.available; + checks.push({ + name: "credential-isolation-mechanism", + required: true, + status: mechanismAvailable ? "pass" : "fail", + detail: mechanismAvailable + ? capability.credentialDenyRead.mechanism + : capability.credentialDenyRead.reason, + }); + + // Enhanced checks: degrade with a notice when unavailable; never block. + checks.push({ + name: "network-kernel-enforce", + required: false, + status: capability.hardening.networkEnforce ? "pass" : "degraded", + detail: capability.hardening.networkEnforce + ? undefined + : "Falling back to the whitelist proxy.", + }); + checks.push({ + name: "process-tree-limit", + required: false, + status: capability.hardening.processTree ? "pass" : "degraded", + }); + checks.push({ + name: "memory-limit", + required: false, + status: capability.hardening.memoryLimit ? "pass" : "degraded", + detail: capability.hardening.memoryLimit ? undefined : "Not enforced in this release.", + }); + + // 2. Proxy denies unrelated domains (hard requirement, real loopback assertion, no external network). + const proxy = await startWhitelistProxy(); + try { + const denied = await proxyDenies(proxy.port, "example.com:443"); + checks.push({ + name: "proxy-denies-unrelated-domain", + required: true, + status: denied ? "pass" : "fail", + detail: denied ? undefined : "Whitelist proxy did not reject example.com.", + }); + } finally { + await proxy.close(); + } + + // 2.5 Host outbound network reachability (enhanced): when an agent host sandbox (e.g. Codex's default + // workspace-write) disables network, prepare/submission fail mid-flight; surface a degraded signal + // with guidance here without failing the report (doctor stays usable offline). + if (options.checkHostNetwork) { + const targets = options.hostNetworkTargets ?? HOST_NETWORK_TARGETS; + const probe = + options.hostNetworkProbe ?? + ((host: string, port: number) => probeTcpHost(host, port, HOST_NETWORK_TIMEOUT_MS)); + const results = await Promise.all( + targets.map(async (target) => ({ target, code: await probe(target.host, target.port) })), + ); + const blocked = results.filter((result) => result.code !== undefined); + checks.push({ + name: "host-network-reachability", + required: false, + status: blocked.length === 0 ? "pass" : "degraded", + detail: + blocked.length === 0 + ? undefined + : `${blocked + .map((result) => `${result.target.host}:${result.target.port} (${result.code})`) + .join( + ", ", + )}. Agent host sandboxes (e.g. Codex workspace-write) block outbound network by default: enable network access for the agent, or run runtime prepare / job submission in a regular terminal. HTTPS_PROXY is honored when set.`, + }); + } + + // 3. Runtime-related checks: skip when the runtime is missing or the mechanism is unavailable (not treated as passed). + const runtime = options.runtime; + const canRunSandbox = mechanismAvailable && runtime !== undefined; + const denyPaths = options.credentialDenyPaths ?? []; + + if (!canRunSandbox) { + const reason = + runtime === undefined ? "runtime not resolved" : "credential isolation unavailable"; + for (const name of [ + "python-version", + "sdk-import", + "fc-pypi-lib-injected", + "home-redirect", + "credential-deny-negative", + ]) { + checks.push({ name, required: true, status: "skip", detail: reason }); + } + return finalize(checks); + } + + // taskDir is consumed by a single executeIsolatedRun call (destroyed unconditionally in finally), + // so every probe must create its own layout; sharing would make the next probe's prepare write + // into an already-destroyed directory (e.g. darwin profile.sb) and hit ENOENT. + const runPython = async ( + code: string, + extraArgs: string[] = [], + sdkEnv?: Record, + ) => { + const layout = createTaskDir(); + const result = await executeIsolatedRun( + { + layout, + runtimeRoot: runtime.runtimeRoot, + command: [runtime.pythonPath, "-I", "-c", code, ...extraArgs], + apiKey: "doctor-self-check", + credentialDenyPaths: denyPaths, + timeoutMs, + maxOutputBytes: SELF_CHECK_MAX_OUTPUT, + sdkEnv, + }, + adapter, + ); + return { result, layout }; + }; + + try { + const version = await runPython("import sys; print(sys.version.split()[0])"); + checks.push({ + name: "python-version", + required: true, + status: version.result.exitCode === 0 ? "pass" : "fail", + detail: + version.result.exitCode === 0 ? version.result.stdout.trim() : version.result.stderr.trim(), + }); + + // The 1.25.23 package root has no __version__ attribute; read the version via importlib.metadata, + // while import dashscope itself still verifies importability. + const sdkImport = await runPython( + 'import dashscope, importlib.metadata; print(importlib.metadata.version("dashscope"))', + ); + checks.push({ + name: "sdk-import", + required: true, + status: sdkImport.result.exitCode === 0 ? "pass" : "fail", + detail: + sdkImport.result.exitCode === 0 + ? sdkImport.result.stdout.trim() + : sdkImport.result.stderr.trim(), + }); + + // Real assertion of the FC_PYPI_LIB injection chain: inside the sandbox it must read the version locked + // to the submit-side runtime (zero user involvement; no manual env registration). + const expectedFcPypiLib = `dashscope==${runtime.dashscopeVersion}`; + const fcEnv = await runPython("import os; print(os.environ.get('FC_PYPI_LIB', ''))", [], { + FC_PYPI_LIB: expectedFcPypiLib, + }); + const fcOk = fcEnv.result.exitCode === 0 && fcEnv.result.stdout.trim() === expectedFcPypiLib; + checks.push({ + name: "fc-pypi-lib-injected", + required: true, + status: fcOk ? "pass" : "fail", + detail: fcOk + ? expectedFcPypiLib + : `expected ${expectedFcPypiLib}, got ${fcEnv.result.stdout.trim() || fcEnv.result.stderr.trim()}`, + }); + + const home = await runPython("import os; print(os.path.expanduser('~'))"); + const homeOk = home.result.exitCode === 0 && home.result.stdout.trim() === home.layout.homeDir; + checks.push({ + name: "home-redirect", + required: true, + status: homeOk ? "pass" : "fail", + detail: homeOk + ? home.layout.homeDir + : `expected ${home.layout.homeDir}, got ${home.result.stdout.trim()}`, + }); + + // Closed-loop negative test: reading the real credential path inside the sandbox must fail (exit!=0 counts as pass). + if (denyPaths.length === 0) { + checks.push({ + name: "credential-deny-negative", + required: true, + status: "skip", + detail: "no real credential path provided", + }); + } else { + const negative = await runPython( + "import sys\ntry:\n open(sys.argv[1]).close()\nexcept OSError:\n sys.exit(3)\nsys.exit(0)\n", + [denyPaths[0]], + ); + checks.push({ + name: "credential-deny-negative", + required: true, + status: negative.result.exitCode !== 0 ? "pass" : "fail", + detail: + negative.result.exitCode !== 0 + ? "real credential path is blocked inside the sandbox" + : "real credential path was readable inside the sandbox", + }); + } + } catch (error) { + const message = error instanceof BailianError ? error.message : String(error); + checks.push({ + name: "sandbox-self-check", + required: true, + status: "fail", + detail: message, + }); + } + + return finalize(checks); +} + +function finalize(checks: IDoctorCheck[]): IDoctorReport { + const ok = checks.every((check) => !check.required || check.status === "pass"); + return { checks, ok }; +} + +/** Throw when doctor fails overall (for the command layer to normalize the exit code). */ +export function assertDoctorPassed(report: IDoctorReport): void { + if (!report.ok) { + const failed = report.checks + .filter((check) => check.required && check.status !== "pass") + .map((check) => `${check.name}: ${check.status}${check.detail ? ` (${check.detail})` : ""}`) + .join("; "); + throw new BailianError( + `Runtime doctor failed: ${failed}`, + ExitCode.GENERAL, + "Fix the required checks above before running RL tasks. No cloud resources were created.", + ); + } +} diff --git a/packages/core/src/rl-runtime/index.ts b/packages/core/src/rl-runtime/index.ts new file mode 100644 index 00000000..d8afc4ae --- /dev/null +++ b/packages/core/src/rl-runtime/index.ts @@ -0,0 +1,5 @@ +export * from "./manifest.ts"; +export * from "./manager.ts"; +export * from "./sandbox.ts"; +export * from "./doctor.ts"; +export { RL_DEPENDENCY_LOCK } from "./locks.ts"; diff --git a/packages/core/src/rl-runtime/locks.ts b/packages/core/src/rl-runtime/locks.ts new file mode 100644 index 00000000..5b3213f5 --- /dev/null +++ b/packages/core/src/rl-runtime/locks.ts @@ -0,0 +1,1646 @@ +/** + * Bundled dependency lockfile (universal, wheel hashes for all platforms). + * + * Generated by uv pip compile --universal --generate-hashes --python-version 3.11 against + * dashscope==1.25.23 (explicitly adding runtime deps the SDK does not declare — pyyaml/tenacity — + * plus fastapi/uvicorn/opentelemetry/tiktoken used by the RL function chain); written to disk on first black-box init + * and installed via pip install --require-hashes, making transitive deps reproducible and guarding against supply-chain tampering. + * Regenerate when upgrading the pinned dashscope version; do not edit by hand. + */ + +const LOCK_LINES: string[] = [ + "aiohappyeyeballs==2.7.1 \\", + " --hash=sha256:065665c041c42a5938ed220bdcd7230f22527fbec085e1853d2402c8a3615d9d \\", + " --hash=sha256:9243213661e29250eb41368e5daa826fc017156c3b8a11440826b2e3ed376472", + " # via aiohttp", + "aiohttp==3.14.5 \\", + " --hash=sha256:0133c3c3b54a0bf1e71fa5c1ad95c93f07fd54e24ef1fe182f5122e1573d2bf1 \\", + " --hash=sha256:038c2c7e8caa26b6c8423779b5eaf1893904048a512c19b32fe841ffa5592b50 \\", + " --hash=sha256:0684952aeae1f5dbfe02d46039338513b94009baecd15d8e4098a357c4c4a2a6 \\", + " --hash=sha256:0790ec66fa4013e83c53b9025a45d454723da1a2fce28b3208c9b32d08af162f \\", + " --hash=sha256:083673c7a94c3ea035caaa5ca04288bdb44887abfe1f5ba23294e6a4b03efd2d \\", + " --hash=sha256:09e0eb18c7e0c8777e2f9149de63799195b9b3ca1b5c81ba6f32f2c6b8628210 \\", + " --hash=sha256:09ec102b4b8c9a920275733bbc11fdbb615efe6f9231a06007c0218d336fb77a \\", + " --hash=sha256:0a8ea271867e360ac985ae607f4a23ad9a38414b9aca1d49ec98839ae660e49f \\", + " --hash=sha256:0e6f16f5e49c4b8267988c05ab07760d7064cea57d077c3d068d04b0fbb992cb \\", + " --hash=sha256:1061b364556e8172e8d46b0b183adeeb73e8c42d30ebc745591e1bd89acad52e \\", + " --hash=sha256:1220353657ad49493551f089ce02f1a348fd57ffd585bfec77f2f3c4fe3a7346 \\", + " --hash=sha256:137351bf20bbed9a65e839f4a4452ac377389bdb2f2857d2acffef38f5e9f2d1 \\", + " --hash=sha256:149fb56caf7acb67073126f675d0958d9c4b3125fcd3f6d4877df98aa8a97ce9 \\", + " --hash=sha256:14f04769cfefe4734016a856a83af36133cd17779cef9ae817f812b8ba9d6d51 \\", + " --hash=sha256:15a310d3c71398e3d7bfc93a1a73fbe664315cd9e9016b8efc1cff85eeab7155 \\", + " --hash=sha256:1612fa5857b37bf32e5c1eaeefb96e3b01e9c70679eec81f0934e8a600080863 \\", + " --hash=sha256:16c8abd5bca220a47efe667d26f8460124c81810787e79ee87b242677563d9dd \\", + " --hash=sha256:19e2ba471507c34f8252402ab50f5ab512398b9ea8c8f1cb26beb3f75793ba30 \\", + " --hash=sha256:1aead151c3abbac6b32942e452020cb66d7efc099d253cc6c20f748e926c858b \\", + " --hash=sha256:1b438b73c38111818d0c9d6a5c2bfed8584c8e503a49ef085d70e874ec846738 \\", + " --hash=sha256:1b5416552740edf07234cc9437d0706f2acb67b93c198670b1a68e1b2b587dec \\", + " --hash=sha256:1d2d981b53dd09a319e3570ef8cc3bbc3ef86f5a7abef0f6b2bff3867db3a9e7 \\", + " --hash=sha256:1eb8167961ec4dfcc8cb9dd50bd0ee72519f7ef496be95203e49e27b01618382 \\", + " --hash=sha256:1ffa3a523a36d8628f98c06492ae16a31a23d14c0b4ec721757b477319f656d6 \\", + " --hash=sha256:20064a177a070d789ee64a50b01a9161d3468e989baacfc6c714aa685c4b332f \\", + " --hash=sha256:20726f9782d5c2744c1c66255842d1d163bb3edcf768b8de25216bf47f7b6ccf \\", + " --hash=sha256:20f085697d7e911f1f73c43ed03fafbed1e7121797e2eb5428efa80398060584 \\", + " --hash=sha256:225c579c23b68b343cccea27a7e06e3bd8ec23a09c30b427eb3f1e4ca6239b20 \\", + " --hash=sha256:24409db442e2fb6e766bc7f3943851a8381dec3098140e43bb2e843b79e31b12 \\", + " --hash=sha256:248d779ad720b49d4fb355720e60c9e5f444f95887bc16974fea48fc56c41789 \\", + " --hash=sha256:2528cb4c6b92008c76ac9ac6298624069bb2db91ff4929905512d1d84485f658 \\", + " --hash=sha256:276a4fc00b1d9ae492b802763a789c5b86328b989c5ea169f2faa447d6a11c7c \\", + " --hash=sha256:27c2322e03f66101acb09869ce1cf1efc04994ee95e1735b69827bf8c8b9d781 \\", + " --hash=sha256:293d3ae7c6a0ed176a42e59a1b5fde825ead65c835360f734148e96729f928d2 \\", + " --hash=sha256:2cc38a4f2b516bef1714e690df87a0e043faf1a7693c82d860091684453d5111 \\", + " --hash=sha256:3093b72c215bda16ce961a6d073f6e71d46e022962a9d5d457c5d4d421c78b57 \\", + " --hash=sha256:32e8fa6644e541fcd7e02430588c7fc93b602c1778ea0bc345505db76b61cfb4 \\", + " --hash=sha256:330900acd0dc4cb8b27f9c127fbaad770964845338493e7906ae3822e82dbf8d \\", + " --hash=sha256:33f706574e32c6e694f352a856e05caf18f7f2c871b3e87b41c55ea452b409ab \\", + " --hash=sha256:3ae800a20947e2c2e53088047d021e6bf7d51560cc49f6a0737a1f79d2e3a13c \\", + " --hash=sha256:3be7dd397d64ca3e1869626fa9318aaebb54b7bf93bc72d7a205448d83e4f748 \\", + " --hash=sha256:3e0eb43bed3c6801a6cee315195377789e90b2a72c2277a475b578535312488d \\", + " --hash=sha256:3e51a27980c3788e6e6b3325d694fdd4898087fa8a86b2763af77b39353da41e \\", + " --hash=sha256:3edbece0379b8b4aaa67619b8aa2399bb66fce372cd5911098a434ea77220aa0 \\", + " --hash=sha256:3f2dcc00191fd563e9075181a14ec31d7dd63223ced7582cc70a15a499de0c79 \\", + " --hash=sha256:42b5e616946dbaf505e2bff18c9af2cd4ef9e7ef300ee58a6e951a5b7cf147ae \\", + " --hash=sha256:42f320d4a5b00b9af0bddcfec5407dc6f2d9816f006b2f79ebbaa31f16895df3 \\", + " --hash=sha256:43351bdb5e4c3cb7d1772368e988534e869a74db7778079a83782c11c69535c7 \\", + " --hash=sha256:43e1b7994a8b038125f722bff07492ef501110722c2727c408995d9fb864c421 \\", + " --hash=sha256:4887d130a7bbfed3a85493bb5a25e5b5b558d40c1d986dd16970d2bb26d63793 \\", + " --hash=sha256:4f07fe3ac408d8b3f768be471dc3f56d43843c47d97c66120534467a15ead197 \\", + " --hash=sha256:50343c1757b4b6f6708eeaf24534b32f19dfb99fb1b762c00420867a62fc81e0 \\", + " --hash=sha256:50983e3be33d8c0942ab88cec3905b10602f64c469b20153c48c5d4e558dd016 \\", + " --hash=sha256:50a195903119008fe9cc68710535eb37f556ffffd6a7759afe70a2c145587045 \\", + " --hash=sha256:5558a7f5a05af9ecf744af91e5baefc436f93c9333e656c27ec253f9a6bbe178 \\", + " --hash=sha256:56572c42e3ecd636de8d2c3dd54cf5fc939cb5c32eb56297f176a0d366fac622 \\", + " --hash=sha256:56d9828f204331a5ca8850fcfe2bcce95a149f1f223f60cc7216e5524978e480 \\", + " --hash=sha256:579f97d5120f2971876d2ddca2968135f6944d00c44c3a6590ad7d86ca9b403f \\", + " --hash=sha256:5af42135fdfebdadbc2bcd9c0842a48ccf0d62794c36a260b21dc4b94d1e0119 \\", + " --hash=sha256:5ba14a839fbe87cf7c12a6b5661c05f324a296eb8363141edb3944ba63d4c9d3 \\", + " --hash=sha256:5c76f1802bab718a68ac3cce447160605c734551f95c67ae90fa1132b215cb29 \\", + " --hash=sha256:5e8f97c0488ffda3082766ac0f2c8150a9a58c4d05788330e479cfd449b37939 \\", + " --hash=sha256:5f3e96071686755d9cd3600c3880183eb94b012178e92746d68101800f0ed8a3 \\", + " --hash=sha256:5fb6a6e919bfb703227bc1ce6579281b84b1a2ba57deb9794dfdbec7dcd1e40c \\", + " --hash=sha256:602c1e9b718a3275c580149f947e7fac65044c0a20e599553fb12e9700da9eca \\", + " --hash=sha256:657291433bf4dd3142f3abac495764cd47d0c7c92087751e6666c6447e65fcef \\", + " --hash=sha256:6774814fd5c338e72ee0da5cbb9432816df450e69c019f72b5d29bdec2a1792d \\", + " --hash=sha256:6da32b5ff3fd78d244e37300463434c7145162bfd2b6e9e915ab164da37f7343 \\", + " --hash=sha256:6e1d8637cf73eebc92eba2e11d4cfff98a3b562f2505bd75bba766d908926e8d \\", + " --hash=sha256:6e4251c0ba4624a68a2c11471a1ac54c3306876c21f0ae86de085cc9241c8905 \\", + " --hash=sha256:6f275c11d1aa6d4c458e05a68be084efe3c55a113d99e3f46a318098e52948fc \\", + " --hash=sha256:6f967dde489ca6a8c02d093ab245d2cbf50ccb5c36adf0188b17b0ca39d24b67 \\", + " --hash=sha256:6fdcd6af7e2e51d1ba1b4bea16e97b074bcb7b5dd0246a9d8201341bb28085a0 \\", + " --hash=sha256:70cb4008ac2ed1e0ca9e824deb4b53d3aa0d939109698ebf1e723a84337bd794 \\", + " --hash=sha256:7457580535e019e1247ea35d6a02bf081ad30c26d0cbc210c93f6c3ab67a0835 \\", + " --hash=sha256:74b0a9c8270f9b0a11410e124ff8d4f18bfc1f1837440ec84da5ae7b50927b5d \\", + " --hash=sha256:74efb69332b85675b1eabd760a8cfc2e2cf42c60607c66f88014c1bdfb40942d \\", + " --hash=sha256:755933b107ea7a6a9ac916f635a70595a5b1a32fac10a8ff0b9f2ab88555550c \\", + " --hash=sha256:7779cd97e61ebe583ec2f1c5616cdd038aa08a4453b1848c67842176d054948e \\", + " --hash=sha256:788ecaa9c10533b786ce5ba70c4f2df78ad41819fd00a6c99d92b66f9a32e1da \\", + " --hash=sha256:7bd8ac754ebd6733a3e2a0dd1674c4d8ab086196803fd8dcd776f07b4e2607d9 \\", + " --hash=sha256:81c2b3dfd56c62bee6108e4852d5970b4cf9086390b6983f52b666e878c1f115 \\", + " --hash=sha256:823c910f046f23f4c713b8d99a2242dc65f591cb45ee86418fa11762a3c2963c \\", + " --hash=sha256:82c7583cd3dfdc7dcc927835b4f6c7faae7ecc1ba3ca5879321621ae2e6f8e84 \\", + " --hash=sha256:8966ecac808dd5f473c9c4cefd10cd3ffda71c18a4d3493b7c7d2ae1803bf2cc \\", + " --hash=sha256:8df7d481654ac96fe1ba9a02a9f67770fdd367823e0d5ef01b922725c4bd2cfa \\", + " --hash=sha256:8e317e0fb6b16212c881d2205a7d87414c29acd69320b3aa6dce9d9c7b86fe4f \\", + " --hash=sha256:932ce7e694bbc29b2bf6f64f2343c27d148d4997c771d01bdade4639b6749ff4 \\", + " --hash=sha256:939042d5cda21d41a6f512e7cc8b8e33a2aebff863352251da495fbd91b673b5 \\", + " --hash=sha256:94684b879ac1d71e4238850c99b62dc1b28d9086b156a2555f082010b85a865c \\", + " --hash=sha256:96a2e584f0b9ed8f1fa33211397dcf67bb7069866402cb405d191c2f0defb9a3 \\", + " --hash=sha256:9ad7e6aa38c20da1be697874349c4c273c8a03b7887169665081706398d0439a \\", + " --hash=sha256:9b42db919715e91eb76acf3bc492a9a7ccd8bd9adc6745c1412b689735269f14 \\", + " --hash=sha256:9bab2045550c4fe0f7baf89574db1b455c195750702ba96fef1f16972b146617 \\", + " --hash=sha256:9bf1d5dcc15204d9ec8b8ea4c18fd66e6b80e5de1f4ecbafb3a2f2740f8039d4 \\", + " --hash=sha256:9c061aa954daaf57d2a4b8374f9fca621ef0e1b603584431c220c22458c59b6d \\", + " --hash=sha256:9c428eb2bd8817588d16a0ab898aa4eb5d141f896aa2b394cc79a4cf61d9a8e2 \\", + " --hash=sha256:9cc882cf8619109583c906b4d4a85d6a111a98afa34b7a450d1e08118d016820 \\", + " --hash=sha256:9ce66feae6ac65327379460380549bf1b8df8e17c4e25df2a2bcf168272e3bed \\", + " --hash=sha256:a23fe35d776bc03cb495938b9594450d047e3bc08c5255315a82323e9cb7d2dd \\", + " --hash=sha256:a2c473a355f9239efcb72c92d5abfd8fcdb0cc78c8e9af607e72ca12dbb36593 \\", + " --hash=sha256:a63afd1f757de949028387e65a7127b61ad0f775432dbb0e62816ae619fe69ac \\", + " --hash=sha256:a6d02b4c38de03d9c7617813433e6a0fb6b522797974177d69d9dad431900833 \\", + " --hash=sha256:a7d470cf7b206e6359fc77b1b860632fde400d5a2ed59cd0181b93a686bc81ee \\", + " --hash=sha256:a95529a92a446db351675f4aab518feaf5e99842f63f5dd17160c2b74f382db3 \\", + " --hash=sha256:a9918e58faf62ba2c7147927d06057aec78f42475aff5048047ec47e7265a600 \\", + " --hash=sha256:a9d3983bd6ab7aa1cfd573544ae98df9b6cb6912a5185a198263e024a636861d \\", + " --hash=sha256:ab52d8f1fc1b64821c1fbad64a647ed6203627004059a6d1ed4f0858a1499703 \\", + " --hash=sha256:abfda5cb094a829f7bc25216a32f7db2e85cc65bd59910f8e7b40b3d9b224764 \\", + " --hash=sha256:adbeee7d6fd4cf5fe0aece2fb3edc4243615d3180430ba8149d01a90670cac99 \\", + " --hash=sha256:ae53924aa853a7a2ca20ed4142c7c6b56338e4d4cd999e2980075b9efc2e257a \\", + " --hash=sha256:b032a0023eb41d768ce77d83210ab2a3c389bc0b09313273c7e1eca48c10a755 \\", + " --hash=sha256:b1b8ece1e71132d2afba4dbc0c3d62c766e25165990b25db1196c04969eb3d84 \\", + " --hash=sha256:b2966998927d7bed9db12c0a4647b0c7b179755878fc9c357fe1ffd3e3b0c1a5 \\", + " --hash=sha256:b3cc509327c7b27f6f4727a8830f4004f6df7766e179f2f4b8e54e65c0bec5d3 \\", + " --hash=sha256:b7806e804889231b0e06469fd4a5c06313d1c0a3377322b6d9237fa5e0fe4167 \\", + " --hash=sha256:bea559ad70218d230663e4210875735076a9bfea5994cef34a55a25faeaf2544 \\", + " --hash=sha256:bf163cc701f3d4ac43ba7d97771bf5fd955220ef5500ef3ee847bc0ecfbf4ec1 \\", + " --hash=sha256:c147451b4a58e7050f7f7394e6c467867c84161560001f9ad4fb2d1446743946 \\", + " --hash=sha256:c172db893e516e1358e65a95ee20b7ce7173963eefe318b6ab2a2220688b999e \\", + " --hash=sha256:c1d60eafd9c7e8e74abd03a5b00df44e7febfe6d9b89b559c0a6551eef0699d4 \\", + " --hash=sha256:c2c30484dd1417ef98b51021ffa2cc0d7f3c78918adaaaab7e70817335ab3e02 \\", + " --hash=sha256:c32e26310cc10e547f53cd13d39a369034f69dcb7d749d5cb0e5f67bc196b6ba \\", + " --hash=sha256:c5ed596aedb9c42afd3fe0aae3117725378ac73d2cc5ddc735056fbdb96c5d02 \\", + " --hash=sha256:c8859a013ae0de1074660992139a1a440df3e6b219b86cf0d3f11c2692bb4fe3 \\", + " --hash=sha256:c8c4478bef6d57fcfda15dae461ea3c9f06aa7b257c58df3f2300174ccbb185a \\", + " --hash=sha256:cb11a971a3aea10f9b8373be628f1df932964fc6c6b174516d318a48c3ac4412 \\", + " --hash=sha256:cb131d775a1573c1aee66656bd78b023577bbdb6cb8349a07773bd4f73e68a6e \\", + " --hash=sha256:cd88b01f3d37b7a2a34f91d98f14720206f1ea3d540843fab2d649dd5fb91fec \\", + " --hash=sha256:d05e94cdfe0d15d0206f970722d2554780ce562787b21b218b275447f8751319 \\", + " --hash=sha256:d079c0a0135c36e7beb6f1c88087c8f108dc5891cdd0b5eafa778421bda70ed2 \\", + " --hash=sha256:d3112585250b199296c26ca6e0131640b6a8d01bab8b232d2eb3763ed469de11 \\", + " --hash=sha256:d418ce2af40c6bb685b3f663e9e8de27cb0a22431d8e88a167348d7f01878073 \\", + " --hash=sha256:d51db97c96384fbfcaf8f4c65922183a68b94f891c3c10c862ef5f6df2adbb1f \\", + " --hash=sha256:d94e44be379e569758fee8a9a58431cfc3c2598c708b92b1cfe96c66b4c94aef \\", + " --hash=sha256:dab9ac5a67c8d1f070c00fa8fccb7cbd1b8dcc1a8d6b42f37540df9b3d4cc603 \\", + " --hash=sha256:dbf53ae2601b7fd5a93c3944deea3a78d40f495226d582c35ef7a433425ce2b2 \\", + " --hash=sha256:dca3fa8d8a0a26679862eccb0b1a9151b2b9f1cd2c212e7a6335778faaff5833 \\", + " --hash=sha256:df37b620684e19b5e25724412518ccafc3b1a49cdac706fdbd2f983fad943450 \\", + " --hash=sha256:e1cc2bfaee8c214f06080a7c7d5772419b8a1108e8e5349236189811823fb02a \\", + " --hash=sha256:e29347c142cf6e99e0dff5e2995ead1d50fa3b51bf37a7c726a7ccfe5419745a \\", + " --hash=sha256:e4f5cf4dc72a71c4cfa9751b4950be22f733626670230d46e7d606592aa22d59 \\", + " --hash=sha256:e724a7b6091f0b1ac064f9d1b15ff9ec52e6033a86cdae649e5f086e32a3c0db \\", + " --hash=sha256:e87046c8ff77a8decdb6a41d8ab25824b47531b2da933aeab0c1e21c7acff329 \\", + " --hash=sha256:e95c8def4b81c5d68d5cf1f54c07acd7c0d2577af244e5b6da802120825737c6 \\", + " --hash=sha256:eb324e2009fb54db30a071dad7caf6998ee2879c4704007efb244514dad1fec1 \\", + " --hash=sha256:ef60869969180ec2464f1349aff07138ae35ca2200f0946cb3552e49e8f301a8 \\", + " --hash=sha256:ef692a24087a699c0a4a26af45e746e0c1eae2116f6d8a5ff91d8aae2b867b45 \\", + " --hash=sha256:efc21a454892828368b11c2c780de0ff8bc991f73f6b99c6b66e56205470929b \\", + " --hash=sha256:f001b571ead90ca1770f1e616db255351a1703317f20374c361ef22f12c06d09 \\", + " --hash=sha256:f2a7966bda23dd85051f1661ce0ace38d6890e05ec6c357ecae9d2479cba377e \\", + " --hash=sha256:f2ebb54b3f932210503072f09974b4fb574d823e497a944adfdcd140a6a00255 \\", + " --hash=sha256:f2ed8b64dc0c651c0f5a9c926777719770021251b8f336d97c4b80b660836ce1 \\", + " --hash=sha256:f375db73a39f5cf83696d500e21a67f418dc9a988955756f254be8f03b7b3651 \\", + " --hash=sha256:f59c7673465908cbe506117176156c127f29f917677afceada34957179221d91 \\", + " --hash=sha256:f8d40ce41991e9d56fab4f5dc4a51fe59bc3b5c77c27f4b148963064d00232e8 \\", + " --hash=sha256:f9033b43f511f27547c557dcaba0177649e10a3725336ccd2cce0fdc1dc4850d \\", + " --hash=sha256:fba47bc2c3d7303c3d027c6cf4d07626c37b1314ac81f5820c31032e0ca1f677 \\", + " --hash=sha256:fbdc5ec49f9ca3cd24955cf3520b10a4d4c901ba2572094c84274e9e7eb30534 \\", + " --hash=sha256:fce9523df31cea6284f3e2c479876750d7687cf671d7b25d32b19effc0e86441 \\", + " --hash=sha256:ff75a7537413a86e7cafe98e0e1d6e3dc4b15c6349896e7d5c6b881bfdb6d550", + " # via dashscope", + "aiosignal==1.4.0 \\", + " --hash=sha256:053243f8b92b990551949e63930a839ff0cf0b0ebbe0597b0f3fb19e1a0fe82e \\", + " --hash=sha256:f47eecd9468083c2029cc99945502cb7708b082c232f9aca65da147157b251c7", + " # via aiohttp", + "annotated-doc==0.0.6 \\", + " --hash=sha256:361ca0950cc7082f53fa69e9328409f40a62c61e57e0a47e1825a08078a58a53 \\", + " --hash=sha256:7969bb69912085b2285849c0dcac0b4b374fd180c13cf10a87f284ffcf347bbf", + " # via", + " # fastapi", + " # typer", + "annotated-types==0.8.0 \\", + " --hash=sha256:13b2beaad985e05e2d6407ee4c4f35590b11f8d693a258a561055cac8f64cab7 \\", + " --hash=sha256:f072f4d804ea359e4eaf198b1af7a8b0943881a87f31bb764f8bf219bb9419e0", + " # via pydantic", + "anyio==4.16.0 \\", + " --hash=sha256:59bb03251907983d1603d27c3087ddb1e93299ea2163adcdba37899a4fb12ffb \\", + " --hash=sha256:c66ae634e0b8228396b801741beb3294326d4b6102f7bba4041c0dfb58c29026", + " # via", + " # fastapi", + " # starlette", + "attrs==26.1.0 \\", + " --hash=sha256:c647aa4a12dfbad9333ca4e71fe62ddc36f4e63b2d260a37a8b83d2f043ac309 \\", + " --hash=sha256:d03ceb89cb322a8fd706d4fb91940737b6642aa36998fe130a9bc96c985eff32", + " # via aiohttp", + "certifi==2026.10.23 \\", + " --hash=sha256:a9895e6e2758b371e0545e321a3a8fd1fcfd9829ada8824a936dfb16aaaf36cd \\", + " --hash=sha256:e9b54de76e530bb6cf0ccd036787103acb58fd42ba930ea8bf948ddbaa2f61d1", + " # via", + " # dashscope", + " # requests", + "cffi==2.1.1 ; platform_python_implementation != 'PyPy' \\", + " --hash=sha256:046bfc24911b37851ee1b51aab8bffe713d89c68c6a057b09484ce9fd5f69b4e \\", + " --hash=sha256:06c72bb76605a4b0cd0aad6930b69d4baf7dd5d806cfc409b824191099700e66 \\", + " --hash=sha256:0beceaabe56af686895136a2de78db54ecd8e4046b236b8fd6d6cb61389e9bf2 \\", + " --hash=sha256:154852545011f779917b11c78db2358d095da62a9a172b78ad0a583ee5adc0d0 \\", + " --hash=sha256:194cffa889098ced9976c3fc6340305e43f6303657d298da55366907c05c22d6 \\", + " --hash=sha256:19ee6127ee34de7d83ce3d371ebc5ed91addbdcc39f9ab15ce4eb35a4e534971 \\", + " --hash=sha256:1a18a57b58cfb21fc28d72e876acf10eaed67a1ed96226f92af4df681d571c4c \\", + " --hash=sha256:1aa5645c30469b09530c4ebca77ebf8f17618293c58f8549cb1a543a50236e7d \\", + " --hash=sha256:1dea0e4d7d4f11f619fe8c1d76caf49e24405b4b5743c0e3be16a500ecd930c9 \\", + " --hash=sha256:208f941bb9d18e768138677f0a6d2ce01f590df56043dda1df1535ac57c88517 \\", + " --hash=sha256:210019b6c7cf07f081b4c54635c8cf744377001350e29cc0f81c4377b4797735 \\", + " --hash=sha256:246fa40ce8645a614ff682e0b70f37134e460eaf93a775e0cbe3cca585a67a80 \\", + " --hash=sha256:25792eac27877609e7bb06d42ff88278a6624fff2ba9bbb523c09616b117e80f \\", + " --hash=sha256:27350daa11d4f10c540e6e89dada4c54feb7256ad03e9a4dc075ebad7ba360d1 \\", + " --hash=sha256:28907ab9bfb6aa13184cfc17c6b8e1023c5ab6fd7076d8c20a35e59fe04f8f29 \\", + " --hash=sha256:2ae64be792b8966f2c69538199728b290e34726562896df1e5dc8ffd8d8188e8 \\", + " --hash=sha256:31348097ff5bbe827ccc41795d4dd099d9f0625e7def00ee653c137a490c2a6c \\", + " --hash=sha256:3143d81e29e1e20a9ce10901ec369012947876596f75a222235965f2b7ae832e \\", + " --hash=sha256:3222ba5d678f80a030e6afbcc33dc1ae5cb45facabb61cee2c7016b8432fde48 \\", + " --hash=sha256:3311ed60d36f83378794e1009ac6258bafbf81f7888b4caa7b35a521e3f95813 \\", + " --hash=sha256:334644fbac4eff73d985a17a91226df55d0f394160c4cfb880e084c8f7161cac \\", + " --hash=sha256:34e261f78cb6ceaaa36f42f2613f4380d94d9c759a9c73c769ee6e0247364632 \\", + " --hash=sha256:363e05fa78e15116c3c32c210ee36884fd6b9afa6d440e47112c3bd511d64cb6 \\", + " --hash=sha256:398aff33cee2767e3e781d2554c54bd0dff386bb437581e0d8011fde1a942ec1 \\", + " --hash=sha256:3d22a20b1fb1632cc72c22f95f7b0d2961c3e1c235f245ba4c606c4771035659 \\", + " --hash=sha256:42a494cee34437f05546455144f2b5d9ac09b1face62bcfce597d2e521066688 \\", + " --hash=sha256:42e2f76b9455f5a9a844f770bf3e200ed3da0e15f5df3db9c31fe80b04b3d004 \\", + " --hash=sha256:42f6930c31dc7f50732c9ae793c2786c7b6b044195967bbdde40bb9be81c4cc0 \\", + " --hash=sha256:456a61fa52d579ebf9df2e9552ead5129855dbaff6c1e5a9b1bc408809bdc062 \\", + " --hash=sha256:471cee653ae88de62096552e6d24ccb4a5adb8c8c9f10b5054d0122c15bf2779 \\", + " --hash=sha256:49cbc70e6542d4ccccb936558d1064a8012541e78f821f955cff24e357776c94 \\", + " --hash=sha256:4a7c934f7360e8cd64fe9efadcbd10c7c6364f531e432b9a4bf5ccbc9e0e8b50 \\", + " --hash=sha256:4be96343e422f2dfcd12ab5c9f5aebe03f82f737c6bffeca6830b3875cb44aab \\", + " --hash=sha256:4f42141fc14250de6dde5ee7ea4432be017252d91f19c5ad043c084cea629cac \\", + " --hash=sha256:507a24c282e0f42f8ed737cf048572cbf580468da5555764a8331735e9c736b6 \\", + " --hash=sha256:51b31d1c98274844cfd7838ce00bfc27c7423a4dc00fc0772fc3331c2cc90676 \\", + " --hash=sha256:58acb8ab8e295e6c5ea12f888cbb13cf21511ef2a3303a23f4325c29d17fe5c1 \\", + " --hash=sha256:5a59cc1c4442bc3d5c703bf720b51138d0bfc173618807c9ee2490a7541dd3d9 \\", + " --hash=sha256:5bb4e7ea95dcd6a014a6fef62e62467d67d8e582326443f3d68e71d6320a9fcf \\", + " --hash=sha256:5c58fe613dc5e5336357eff555824a314d8e43282600435c8d1cb6a7a2fedd13 \\", + " --hash=sha256:5e7cecbaadb83884793e05828cee59b210b24583b9c7425d0ba6a754fe22eb4e \\", + " --hash=sha256:616f097f2fe415bc92a247f02e11f634e1f9e9a83d327e3c915c15089c87869e \\", + " --hash=sha256:63bbfd5ded17c4840ac07cd8f1c21ba9d9708141f840b324f422f41b207e3973 \\", + " --hash=sha256:64faea20f4e2613363a1a9b9c7dd73058f3ecd00133a511e72ad7c511658f527 \\", + " --hash=sha256:661c298b4821edebead0c91edd2b00374d67ad7c5a1f7a91d4442633b79d6a72 \\", + " --hash=sha256:68e62fe11f30d5ca8289242866f0a5291402d8529ca2178ab8afc5c9694ae890 \\", + " --hash=sha256:6a8dddef476fab96d066d578fc88526767b836ab5ab21754e1d5bf3879c31c7c \\", + " --hash=sha256:6e192623c49c94421616a5778fba35cf0d5a8d000650c1967ef4448ee5cdd990 \\", + " --hash=sha256:7225e4514edb64eb6740324353e0da0711954fd8d7da4576755b1c6e09b697cd \\", + " --hash=sha256:75f80557d1389eddbd0de2681f6a390a0c5338c31ddaa821381c203fc3fd50d9 \\", + " --hash=sha256:770de9db11e84213beec501cfcaa013b019820ca881e03344dea5844f7876d94 \\", + " --hash=sha256:7750c6449dff7864bb9bb27ddfb0267756189201a3afc911d82b3caacd70dfc3 \\", + " --hash=sha256:7bde5e4cc5c10140859842b9d383af292b22639a4dffb725314baf45968cef80 \\", + " --hash=sha256:7ce713ace7c0e4520535b42b77eaa742c16dab813978064913e5a3cf82973b41 \\", + " --hash=sha256:7da0c5eff80f0197f3b3d1232ec5a682a9325f4ae9016a78f5f5ca35f9ced1f5 \\", + " --hash=sha256:7dbb61fe3a7699468030f71bbe5f8a0e326a151daa91beb11a6fc1f980c55e1c \\", + " --hash=sha256:811bd1e21d32de12efca32393a0ab3f5133b54fce9bd44b8bd77ab07da14bf6a \\", + " --hash=sha256:8ef53b2de9bcb9197d31854256575d59dbac0cba72ac627bb291ef5eceb74be4 \\", + " --hash=sha256:937c0052c05a31ca1daf18de3158eed4dbfcb9cc107adbea227728d647be701e \\", + " --hash=sha256:9d2055050ea716bd38b7f7f1579c275386646b4894c155a3e2f3cd62ed41b7c6 \\", + " --hash=sha256:9f8d177621de5cb38ee3e731eda45d421db093ec0739f46a5594babda7987a98 \\", + " --hash=sha256:a2d7755bef5a12ed488f4ef1f1b69ee9191d7396083b755a5d2295f6edb4768b \\", + " --hash=sha256:a48d62ab9d6f4f98c983223a547af44be6ca3691074c31cecced6facd3ba2dc1 \\", + " --hash=sha256:a4f00aa42f75d6e4595e8866e748cc1705adc0cddfeb2ca86d0d03993d63ba03 \\", + " --hash=sha256:a6e721d4b0e45d5b65e87534470e67b18dcd092c83f68fba09f152b9cbc061af \\", + " --hash=sha256:a730a083190634c65cca36ba5f489531576ebd79bcd5c8e172130f6453127231 \\", + " --hash=sha256:a931079504ecc49efed7744c476a5c343a92fabf66dec2db95edb1b2fdc770e2 \\", + " --hash=sha256:aa9511c62d14da7aacc9b4bf51f3f697a621e83b2d6919008243c3aad168eea3 \\", + " --hash=sha256:ab36d55f9ed2d067327667c2fea18dda018eb628dd6347aa01dda6cf1f5d3836 \\", + " --hash=sha256:ad2c86c495b899d862ea0f4b42891b8713a3bd45dd4105c7fd51c2a72f39f3a5 \\", + " --hash=sha256:aeae0e330c9f6acd681f647d46cefd30c29f93e3392882e792e82080c9691399 \\", + " --hash=sha256:b0431303acaea1089ad4b3e9ce4e6518193def1118d4073ca848635ee4ea2e96 \\", + " --hash=sha256:b5bdfd1c873d4e093aabc0ca84c4ca6dbc4f752afb5c86f146d9742580c9da2e \\", + " --hash=sha256:baed1e86cc735622097354b9d1281406caf42ff42a886d29faa8e8d1630333be \\", + " --hash=sha256:c1453022f490d2459a11819d83ad1d586e9ff65a12ac3e705ffebd46d3685dcf \\", + " --hash=sha256:c26608d2222fb1e94487e4a387d85f13eb55d5ed725cb25a0c589ac4ee60e7bc \\", + " --hash=sha256:c7659f22557c5a0bc4855cd635f55edec690cc008a40768527762cb9fb263455 \\", + " --hash=sha256:c8c69575568085ba0b1b10c0249d779a214aea6f6522e949a0fc9fb0fcb449d0 \\", + " --hash=sha256:c8d2c9fd1f2d16f780d15127abb050d13d1a76c03a4bd87d7e4980e45e511e12 \\", + " --hash=sha256:ca82be1a1d406ecfe1d25dc16cb33488e5a16bf4438c9fb590484ea29d92478b \\", + " --hash=sha256:cc572dace3f60ef98d7b12ff411d20f5362feb31a0439eab0085bbfd349982d7 \\", + " --hash=sha256:d18e5ac0f2f03f4f518d3e23db0f0cad7faa1da8620e9c09461d443bbf6e6692 \\", + " --hash=sha256:d28630f5854ab07ab1fd4aba756de52326c82e6be15d414b12793f1975048b54 \\", + " --hash=sha256:d9c275eaacd24aa73f94ffd6de08fc3f932424d8b6c376f4bed7cde376fe7bc3 \\", + " --hash=sha256:da0e573f9f97159390c89d9f1a9e41908b66d408cc5b58d08cf3847d844c531b \\", + " --hash=sha256:dd31f52ea1086513bb9df30f8fcee9b8918323ae067a3d5b78bc826a000712be \\", + " --hash=sha256:dddad92b554513a31f272570678ba307fb9f618f05e3d4a5eacafff9eae03e1d \\", + " --hash=sha256:df423d40ee8654634421812bc3b196da3f9bd7d32929da813f8394c4348a5358 \\", + " --hash=sha256:df913725b79db7bcf03448f36b7bf8815363417d5b58deecf9305e3e30f0f21a \\", + " --hash=sha256:e0bcb7e0f677f543555d2adff3bf19c05f66cdb4796e5ff602442ab2fe3c4ef7 \\", + " --hash=sha256:e2d65b31f36619cda3999b78b2aa9632e76b78448e7a56fc4240824200e7c4fc \\", + " --hash=sha256:e6e8cff14d6fb0be70a09c0bdc58096f501952d04624ebf867e0e56da2df8960 \\", + " --hash=sha256:f16c709686a78c727bbbf059f92b0bf41c6fc60deec706d2dc19f529175a6125 \\", + " --hash=sha256:f24fb43132a4c6b4cb4eb029492919b2db645be6808d738f244fd146c03c32cb \\", + " --hash=sha256:f53e442b08449d42821fa4a4fba000095af9f62742a500f978a9f557ec44339a \\", + " --hash=sha256:f5cfbc5fe74540d335175b656c725d74d90e3730c626d92575eea35029d9afaa \\", + " --hash=sha256:f81b3b8f3d4e343550fa4baa0e479bba9f2d29ce9c2e9b51d1ce1718d7442fcf \\", + " --hash=sha256:f8ec5e643a9a937f64e1999eb9f75d072263751912dc5cd06d3c85f8f44be7c3 \\", + " --hash=sha256:fb92203a88b3d3053034db775110081c49d28be6551923805e039924093761e4 \\", + " --hash=sha256:fcd22650c908d7b7da162bbfaab594a1227a15d1643a98c68b122ac642fa2264", + " # via cryptography", + "charset-normalizer==3.5.2 \\", + " --hash=sha256:01077390b03f7988f11d700a2194e69b119741a86b1a638b1db88891e3eced8e \\", + " --hash=sha256:01b0c0d2262a9e28e8484a278c7e1b5d650e3ac8cf2683d2967e25899f208bdf \\", + " --hash=sha256:04851f73ae72b8413dddadb16a49dfee95263553741fd42d546f7d66907e6be5 \\", + " --hash=sha256:0521c5665880b33d603717defa76c094048900010897909952397feb3039da56 \\", + " --hash=sha256:0774bf9bf620249fee3e0b8b9fd3065de213be30f3aa94ce2494b3b638949e26 \\", + " --hash=sha256:0891b9d3903c5571c03771ca669a4b0ec5618ca722a5c957d3d29cd4e5062848 \\", + " --hash=sha256:0c951d5e6dd9c2ff60609476752bee49da4206adde960ebc247766937f72e718 \\", + " --hash=sha256:0fed1d06615f022ee3b13caf5e8b180cfea32bb2c5aded8a9d44277afc040f93 \\", + " --hash=sha256:114e4d0c92d618409ed82a99e22b5c5e768fe995f2973f78265f4524f49d4640 \\", + " --hash=sha256:11912e4bb14baae7c5d8791aa55ba0a3a03ec6729073307b0f57270abaa713d3 \\", + " --hash=sha256:11a4d68a6ecda3292cb1e50239e111543ba5d709bb62a6b4ea1afcfa729d8875 \\", + " --hash=sha256:124fbf1a8ff966d87ae05bb8bd45a71f966055ed8bba320d0c7cf450bc5f4d0e \\", + " --hash=sha256:1461ac396c4fdb983a675f20aa555624f0ee18ac83d832b9244ffff3d8055275 \\", + " --hash=sha256:1503bccbeb36d5527790c3930327704c39af22de3112f1b1666a9f3ce15ee204 \\", + " --hash=sha256:15bb4005af6320d259dc7593ca84a38d7fe06a421dbcf7b910ae23979101e787 \\", + " --hash=sha256:15c44f7edfd477b06f517a5cc317fc1707edb9de2c865f43d4b6513907473234 \\", + " --hash=sha256:16fa0eccf81304b79c5cd87f9271c3b85dd9dd99245e4422ae9c0dd45e0f99d3 \\", + " --hash=sha256:183b88127acdb4fabe59d951ab424faf1af7b63cdbb5f776186c1ea2ffcaed98 \\", + " --hash=sha256:195c26fb65950f8fce54e26349852b7bdd7c5f120aeefbcc440b8a20faaed4a3 \\", + " --hash=sha256:1afb975bd5d68d5ce9f6b6d44fdf2f7e34b895a35e95708a7a91b20a3b51d187 \\", + " --hash=sha256:1b4cbc7c3491ccb4aa17fcd8165649d01cf39f76de1696da8631b5f71b85401d \\", + " --hash=sha256:1bc0baf5ef96b6ede57d47f4b8fe4d9d84019c3bfcbeb20a41edc6a6ee341f1f \\", + " --hash=sha256:1c50fe28bbc2ced33386f298650d91218076c05420e6cbd790b913adc41659e7 \\", + " --hash=sha256:1db38f4c5496827c1a501846d64d14c3b80c7e6714e406cd7dc36a9899fa1011 \\", + " --hash=sha256:211d5a3eb6af8f513b8d4ca19a8c1b7accab1b5f0d3175f9826b03c1a920dc1f \\", + " --hash=sha256:23851fb4e1b85ed3f6c2a27b777cdfe2e19fb5b38429a8faf38c7542b7665869 \\", + " --hash=sha256:254eb48b9fa5ee9898a3c445825a1f340fe53712a098904b39b0bddba8ea3cb1 \\", + " --hash=sha256:2625388c6c754520c37abaf3b41eb34d1cc4a373f457898f08606c8e362b891d \\", + " --hash=sha256:281cb91036248400f4cc957495cccd44c275c2e0c5854f7e45ac5cf7dc193847 \\", + " --hash=sha256:28a15fdad492a99b6eccfaaed66ef3f74050680545ea61ec8b2f4c538f1f1320 \\", + " --hash=sha256:28b4f0d66fb834ff90f28209ac7bce77868c45d8c93e26f906709d9b7c2e1af9 \\", + " --hash=sha256:2a925889534b3748302dae5dead07cc13480de1dac3aea80a941b729b471ef93 \\", + " --hash=sha256:2b7b3bbfb4fe8ef40600792d762fbaa9057559f9d3fad209525b7a22b99e91fd \\", + " --hash=sha256:2c9ad19a6cfcd5ea5c0d41161d22f9df1dcc277e9bef2751391334546a314c00 \\", + " --hash=sha256:2cc961b171b3f3440f410489ab3573e86aea8736134ebbb40ea1338b7f0831bc \\", + " --hash=sha256:2ce45c6627b22c47e390bc91a41c3d13032192e699fa0bea96e9671b373d69b0 \\", + " --hash=sha256:2e06a3a98f916dd41d27f3105e02e7a40181c98c94b9158733d03a6f80506c09 \\", + " --hash=sha256:304d5463e65a35d7bb0850550e0780395395f6fcf452f04db7d5ca7cecc425ac \\", + " --hash=sha256:304d8e4d493af723536393eee0c689eb7813f4a474c8b479dee63f1fdd98f621 \\", + " --hash=sha256:30fcd120b732aa79317f08dee04d7de0847822e4cf7ee0e9f445bb958832252c \\", + " --hash=sha256:31f3930700408d211f13378ccbe1c40845d8da54bd0681fac3a9b5aae81c7aa8 \\", + " --hash=sha256:34276fd796040bf0993ab33a369aa572e6979c7aab225a88893667ad8eac8f7a \\", + " --hash=sha256:355ad8011081dec5412240c087a9a0c9d4d5039f3ed11a3f13e18c2b29b56c51 \\", + " --hash=sha256:38a873987f3be698494da8b2e3085e29da02da7b633dce73e79c699a113d7bf0 \\", + " --hash=sha256:39de2a259fc954455c57274dc94c79d5842774e1247a016aff30bc0efed0f4ef \\", + " --hash=sha256:3d14b50de6bf4d0edf857a9386836846f982b8f524e188e2e68b96d702bcf4aa \\", + " --hash=sha256:3d21b8b13c7592db2ac5e544a6d83187b995257472b0c9e8351b6d507ae37ed6 \\", + " --hash=sha256:3d31298449090ab8d47b7b1b2a555ff73cac7ed438a08b7ac160980c7ebed649 \\", + " --hash=sha256:3ddacd27458c45bdacd6bd6db644bfb730efbf9e830310186e3045c9c5be8fb2 \\", + " --hash=sha256:3df041de8887954562c9b261cba85ca0e9ded74048daf125f45edcfaa4832229 \\", + " --hash=sha256:40ab6bffa02ae10a0581e6c198be7d2d8ca5c2a0c64e4ed3465d766df457573e \\", + " --hash=sha256:4275811936e2f06feff5e598fb42a1b7ae852da8e39605211892b56b81a34efd \\", + " --hash=sha256:443eae2bf318abeaf6f15d785138f71fd6de770e99a92158b8b814265e079115 \\", + " --hash=sha256:447441e76ec720b15e64418d32e092297340387053047c7c694f579efb0ee1d9 \\", + " --hash=sha256:4495c5002a7b28557e7e222e77e0b661183e432b7d6d2e788101e3f240e05b8c \\", + " --hash=sha256:44bd4fbb29dfbeba60e7d2bd000c59e4b21ddb3cc53912b14048d37092706d7c \\", + " --hash=sha256:4685902cf26edf013ed7a3da0f426ebba7a00ebb9541386d835afbf002c11cab \\", + " --hash=sha256:498dc3188ca05a68231ac3fdbfc7f57eb67e1343c30e0fea17f8218c1599b253 \\", + " --hash=sha256:4c2b5031f63e331e3839b40aed2dd6f191e9c07edbde303e7876846ea1946995 \\", + " --hash=sha256:4d48f2d08b9de5864e2c8744d4461b862fb149a18274abc8b698c45975573438 \\", + " --hash=sha256:4f87960d57feabfb618e4e0af6e7371645fa26a277860739d6e5d6e0012c92f0 \\", + " --hash=sha256:50e3adfb96fc189eb27b1cf62d3b598b89b4bb0420d93a3d3e42e137409011be \\", + " --hash=sha256:51cf45226a9b588d0d2b4880c62d686934b63ab0bd79ca23ab0e9762eb27441b \\", + " --hash=sha256:52aa6992700996af31f375de0c6bacd402b0097fe40b53c426b9f51a90ebabc7 \\", + " --hash=sha256:55ea99acb17b9325618de155a0cd6a2e8f5d10be008113e1d433bbb58db543b2 \\", + " --hash=sha256:56bc200a365efb37383b7852e4cc5898d3b2da5987289b543956cf8cad71018a \\", + " --hash=sha256:588461c2e8384d309bd63e5826019b6977bc66d629b99ac8737bb795d7b2cb5a \\", + " --hash=sha256:58ca3755ee7ff7f59b57789ec9833c9de9ea275405cdd240eda1f193112e398a \\", + " --hash=sha256:58f361dcbab699cf8f42db3f47c8e7fd1036f138c23a5d08de9fde5f425a730c \\", + " --hash=sha256:598a11a2c7ebaa5334bf698bf29568c9c390abac6a154d8170fedecd1cea38c5 \\", + " --hash=sha256:59f63901b0031c3136cf64704dcb21de0bbae62ce2c9529bc39d27665463de37 \\", + " --hash=sha256:5cde776b7cc66e4f6c99612cea4aa7269aa65863f7a15841b2c264f103822f4e \\", + " --hash=sha256:5e2b6b57e9733d39f0c9fd3185efa6b8e29652c4cd8fe94180272cf6ed9a78c4 \\", + " --hash=sha256:5fb29fb8cd1a46c27a1bf9613ad5ec2599310d46b4025d9556404a6b6a292800 \\", + " --hash=sha256:6045373d5a89a5ec71afde535db987ca28e76dfa276c2d4c818265b375d4b055 \\", + " --hash=sha256:619799369eeef6366ed3e8755a5670f4f2f0fb6b30a0fd7264dc0fdc2357058e \\", + " --hash=sha256:62588a277bfb59def052abd940703fa35107152bf479781a878617d60faf8fb5 \\", + " --hash=sha256:62603db9a7caa0802eaa28c1c46fecd7b3a263a774069c24c3c28c302448721c \\", + " --hash=sha256:65cd72beeeca9d3aaea1201e5923859f308f952f9c71de93f06063c79f0f7a3b \\", + " --hash=sha256:68eb192d85ab8e5f6ec69c2bc6ac0179fbf04a5ac1569d12fbef74883fe102d0 \\", + " --hash=sha256:6bd128f206a7752ae1f2ab6c61bf8a24ba28913a10df8b14c2637b973ff97a80 \\", + " --hash=sha256:6be488a102b8cf28d0391d8c4ba7748938ae28b78ad901f8585520fca33ead1a \\", + " --hash=sha256:7218e8f32b0956cfcd048fd42d9d5779809745ca1d86113ca56f66e7ae1549c4 \\", + " --hash=sha256:7441d755b7ab94f8d4eb3e43ec05482d760842fd263d003a99102d742cd835e2 \\", + " --hash=sha256:749e97e1b32313717a565abbe321bc2190bc8b35f1a67e4cdbc7c56c8d8ffe58 \\", + " --hash=sha256:75a3ceed0724d625d64b86ca20aba182e4df462e04c2414fc941c0f523f06aac \\", + " --hash=sha256:780fbe7cab297b81dad9fb8dc5eb003c0468ffb0d9e5f65068c53a34661a96bc \\", + " --hash=sha256:78456a747de8dc58360ffa581f30a002baf5aa28cb262536545e91f113ed7639 \\", + " --hash=sha256:7967d08cf06dee78443b874f98c98036f624f3a4e73e11f9f64f5be4d25393cf \\", + " --hash=sha256:7a881931aa470808df94a8c380eed2bbbc76cd9dc622310f99665658c821eb6d \\", + " --hash=sha256:7dcd882da75ef9adf94903b1e3b9419e8aa8fb4c7396822b834b9ef7fb96954f \\", + " --hash=sha256:7e841fb9010836c992c9f12fcbd43a831de93a5f726fc1ccd8ca1d0268c5014c \\", + " --hash=sha256:7fdde2c9fd9e3eca40631e024664cf2584272cc8f96308cbe5fdfc930f51d8bc \\", + " --hash=sha256:8024d00c3faf3fc0c16e07a69f4405e8eac7cc0ab15f65fe6cf43827c4cf72b4 \\", + " --hash=sha256:80d02b6f04e92601a081dd97b23d3128033098bff5d35d392ddcc0476ea11253 \\", + " --hash=sha256:838dcc90063569a0448120554591a1d6c4a4ffe11babf048908793154ab86ade \\", + " --hash=sha256:849df64e889b2e17230d58410a03dba311a65b163508fd33679b2b737d4b7858 \\", + " --hash=sha256:87475fabc8d9996fd9c27debb395e642e8c838d78a00b6e932227a0e06b81e26 \\", + " --hash=sha256:87e50a3e7cb90af586b6c5faf23e302a970415ac73bd7bd90a515a04b427ef96 \\", + " --hash=sha256:89b53f3cda69831909888e0494f4fa0bcd3537e3e138dabeb620bd6ad946bae8 \\", + " --hash=sha256:8a893cc101149f80a653f82062ebc95b34525a2614382e1da5458fe7c6997249 \\", + " --hash=sha256:8b2bfab86aa71ae13aa41a6a26aab338e0db2b8bc75434b05aea89e011ff35a4 \\", + " --hash=sha256:8d86d6fc60743dc916eb79e2eb1ec4818e21e427731543af40a3021851174a13 \\", + " --hash=sha256:915563965d418f986e7e145accc592eae9e1a1be3566ff98a05d7a9ec42a76e1 \\", + " --hash=sha256:92888bb3187c5ba50500b00b3b310c9f2c651709d28036077680cb5255450a03 \\", + " --hash=sha256:93223adc95033dd47133a46ccfc316a0139176fd79085762e27202ec56018f03 \\", + " --hash=sha256:9373ad13ef0d2c0fb761e04e55bfdee5a08b52cef2c882c8fbe9935b1517152e \\", + " --hash=sha256:9409a8bf35cf78353942504b24a57de3d75b708997a1e4bd8db71ac8633ce364 \\", + " --hash=sha256:9b7f416ff0978e2f2249330527f0ad6fa02f4932e6199692d3b52da2048c19e4 \\", + " --hash=sha256:9bde855991b7e362c146535e3136a50bfaffc0487d38b33ca7e5edefc6e23849 \\", + " --hash=sha256:9cae88599c7219005d879f98e5ed53341e9a122af585e1091200358a3003d2a0 \\", + " --hash=sha256:9cf9b1a857e25c4baceeb3624e92a56df3668f398c4acba74e174d81fb4d1d3a \\", + " --hash=sha256:9f56f72050826f63dcee7a7f55b0a77168cb3bfc553fd405e7f8f9ece75a4036 \\", + " --hash=sha256:a090bb2c68df85450502e3e20d665e3a5af9c65a84d6508ed477badd49166fd3 \\", + " --hash=sha256:a192e2c40070d92c3ccf777e3a5c4ff515573cd2bb7ed0c537fdadbbec5bbf21 \\", + " --hash=sha256:a19a731138fc27d5682277d3b9df22855cea1239bce7fcec5f78f42ef2d1f3c3 \\", + " --hash=sha256:a66c3bc5ab1f0ff2164fc9965ddd611ff0802173f4b9d24554c563f6ab7e1d6e \\", + " --hash=sha256:a815775b6c38d4e0ff7bcffbeba67feded90202bb6a226b8dd35f1c855217413 \\", + " --hash=sha256:a89012d6d5476ee112d20d998570ed58df2260a852afb1758809cd6900411d21 \\", + " --hash=sha256:ae4f5fea5b8b8ccff88238cc8569303e5ee95efae67fa62922a311397a71f346 \\", + " --hash=sha256:b6856554c4f44d79fc2307d5768854310a8f0096e501c75637542c82292b0429 \\", + " --hash=sha256:b6b751274acb69d77b3323d6b7dbaa3c7fdfc1eb829b7eb61d262f32e1af9685 \\", + " --hash=sha256:b736353c0a625bbd5fcec108576e2385db3496f4f771f785ff32e108d3c3bc45 \\", + " --hash=sha256:b7fd005a73d9e657273b7a10dc71a9e03c8fb9ee6999798d6918ce095b81ac7f \\", + " --hash=sha256:b91363207bd9dc966a691e959bb47f64b30f7ac4b072be9968b366982f7db77c \\", + " --hash=sha256:ba0b1d2620edf869789c3879223f52bf2afc5d31b3cb47cc57b3a12c05e2aa9d \\", + " --hash=sha256:bbbfc8e28816f19d7c0f1816664980c0a9875d01b27cdf8eedddb639d9e108ad \\", + " --hash=sha256:bd16aabe4a02a297c23417aa17ac6299dbd8c49f673bcd645b4929b11f5a4400 \\", + " --hash=sha256:c0afc6800ba57ccc350374c5bd6150419915d95ce93cdbab2d783d75eaf30ecb \\", + " --hash=sha256:c6708715abcf3c73b99508253e961a9967f02fe536532834149574eda6de0d1c \\", + " --hash=sha256:c7c9ab723cde841fefb34efbad91e87f00a674b1fe1cd0784fde742bf2c154dc \\", + " --hash=sha256:c8f3d67aeaf55f017982b73683f0e7342ba2f6635a78f69ce89ebb26aa411e5c \\", + " --hash=sha256:c9790464842f85f437dbbb54417eda1e0e6bfc52dd8d22d6fd1c994b73b2dc74 \\", + " --hash=sha256:ca403d7e4798f525fdfc78e258820419cbbd0f0ecbab9de7840e3c017cf6b8cf \\", + " --hash=sha256:d008d90a7f2471519aef0c90dfbe73b3e6e4d5e66ac48e19154c17e89e98b604 \\", + " --hash=sha256:d19fbd981a488e22cd04883659ca6b08f50b5974f9fd7c95655ef6a043e5893f \\", + " --hash=sha256:d1befeed746d247c81127bb14de9dc3d30edb6e5976d34f83f86ed262b1d9105 \\", + " --hash=sha256:d2374b62878abb00cd8309b32af6c0b715cd02dec0ca74ef12e5069bdc64144a \\", + " --hash=sha256:d376bbd28b3a8999db1a103b3b388aee6f1ddeb3e51bc2172993efdcd86e064d \\", + " --hash=sha256:d4a7319f304a774bed22115bc891618e45f85065ab44ea6acd07d274e750519a \\", + " --hash=sha256:d6734d2ef8a50fbf8445c139477da401f50d62a0606bf00e20ec6d87773fefb1 \\", + " --hash=sha256:d760fe2a4d7c3b226cb9026d6a842868d52a7901bd98420e1baf14e80da85cf5 \\", + " --hash=sha256:d913de495d90407cd859d263bee2e5d1a4ed3eb6573c04e70d9ec619a7cbed7f \\", + " --hash=sha256:db19d07e2e0129e974a0e65d0064fc222a446cd5122c2fd4184d2af9fc734a9e \\", + " --hash=sha256:dca9ab98072a5a54ebacebdc45f53e645336b320c667410b061be1ca588ae709 \\", + " --hash=sha256:ddc7dacc8ece3a182e7f15cb862d1fd616b46d076cb1ae9dd232b2c38b655874 \\", + " --hash=sha256:ddf19c062bea7a0cc80f519243d2c01dd091be0cf952a0750d4ad576709559f5 \\", + " --hash=sha256:def79fa35ef0cef8d2accec024f4fdc7ead3012ff02f5215c783f39f03ef8cfc \\", + " --hash=sha256:df29a0a7107f7011e77f4eebdddec4c7331e24d787a0b21a46d63bdf7445da95 \\", + " --hash=sha256:e09a3942ecbdee5cce73ea9d42da82b81b72ac1bf031ce069b93b5adf4eac8cd \\", + " --hash=sha256:e242bb1c5e76e97dfa9e7f209a71e93a01d7f19ffdd5cfbb2e2d55b4f08f8ab0 \\", + " --hash=sha256:e243bd13217235fc7290c621941c3f5cc8b66e4872495be821d7436ba2fb838d \\", + " --hash=sha256:e2af3aad578aa6bd1384bcf4750fc285e5a9de53f40b7d41e5a0bf748edeb2b3 \\", + " --hash=sha256:e4e81e09c1578b8df602e3db08b0b3ea0a6947ad612f52bf8dc5ea8d47691f0c \\", + " --hash=sha256:e54da4baf05720032d527874d40b65fa4d7e5c6c6a43d0c3adbeffcaf275a2b3 \\", + " --hash=sha256:e80e6c2f55656b4824d72065abb4ddd6a525c74bd78a0aab5d9fc2cf4fb5af50 \\", + " --hash=sha256:ed2a239c0ea213acc1908150a3037257083c7c083128f1a4cec2ec4b97dca491 \\", + " --hash=sha256:ed905975ab14056a2e5eb1c376cb2e1ebc5396baf84163939c518556fccde9f5 \\", + " --hash=sha256:ee21e28f0430bd6dc9086c6e525d5e818a44a5ad19720c8a0ef766792f3eb5e5 \\", + " --hash=sha256:ee43c17b173d46a3212baa6ead3ae258eeabdae48c263a01ccf0218c366dd655 \\", + " --hash=sha256:ef4fcbf3327382cd4c9f540babd61248208af7b93eec4de397b4d5f58a09e288 \\", + " --hash=sha256:eff0ac9dbe711a4aee69bf04a83896aa9b85f19641264053a9f6d48573abb7dd \\", + " --hash=sha256:f0aa869112ef88429ae17820d99c3dd9504c9e9c671d3c246f3d7442cb051084 \\", + " --hash=sha256:f3c96f633825733f735c5a9cf21d21a257d8e1edf0b1cee0a064b9c424ca0f7d \\", + " --hash=sha256:f5833ad231be5eb6553de524a70f48d71b2c8563101750531e0b80184e175cd4 \\", + " --hash=sha256:f5ec61164adcec446f8969a3358ec3f9b26bbda3b9213e5586d219afa8df2915 \\", + " --hash=sha256:f7d486c83842422badd511868fd8a9a20e9407ace71564b6af47ce7e60a336c1 \\", + " --hash=sha256:fb9e68df06293761f9fe66ade60a9bc6d0f5e42b8acf2939a9158af86ab0e5bd \\", + " --hash=sha256:fc14a032f813bf5fe624d991960ea83e9715adc27e4c1830a2361eb1d02ac341 \\", + " --hash=sha256:fcff63213e8e6e47770541a4607175404f47cbb3ebea7b6058cc82d524a0e424 \\", + " --hash=sha256:fd1fbe0f116b6e55da77aca2c6ddcddcfac2186cbf78bdebf40fc156efca389d \\", + " --hash=sha256:fe9753dfee015c570d73df76f899f18444d41388bffcde097deba51c4fadbb9f", + " # via requests", + "click==8.5.1 \\", + " --hash=sha256:8bb5376d2006950386f8c6427613334a2acadc5f559cb80e638d00b4df957e37 \\", + " --hash=sha256:9bbfada76703fd1d784b83eea012e3e8c6a001a876543ef104fa56aaaeb072b4", + " # via uvicorn", + "colorama==0.4.6 ; sys_platform == 'win32' \\", + " --hash=sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44 \\", + " --hash=sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6", + " # via typer", + "cryptography==50.0.2 \\", + " --hash=sha256:0ddc924c04591c2811ca024d62ecad4f7f6f08af8939c211438f48a16bd23602 \\", + " --hash=sha256:0ec5f09541743261e66e291b4a0cbf0fb2997aeaab6d9e9c740b9dba1b58d1c2 \\", + " --hash=sha256:0ecbc5652bdb6fc9eaf89a7d196e20941adfe812f43bc4ca05d9150496821047 \\", + " --hash=sha256:1981f1db4630889b9ef7803fadef12b056f428cb6b85c27ba57b774793b6093c \\", + " --hash=sha256:1ba34f04897fcdaa73f74145c25f3ec146fbd56593853e88adc2e811303c5f42 \\", + " --hash=sha256:241449bf940a5d27309bd317e6f9a2af6932113818bb2b8f5c59ddc7ef16da18 \\", + " --hash=sha256:25784ce8b9621c90c643efb9e1e2162ab3b0224cae446ad5e70e7fcb1ce18b51 \\", + " --hash=sha256:3dc4fd8058cea1644971207d530e1a03a184a805ffc8ebdddf0599d78a331b81 \\", + " --hash=sha256:4061c0079120205fb760c58acab6443e217307dcf05e3702cf970e0689972856 \\", + " --hash=sha256:4a20ce1e5cb4284a86692fdcba7cb8754185c6b2e5c56fcef3751cf451d3cdc2 \\", + " --hash=sha256:4e81d95e5bafc2d6e34e4bed780e53e4d5b9a2f928573428aa4d35fbec1eb0de \\", + " --hash=sha256:58a0c478eeca76fe5e07993c5a0703def34a6dc6a0cda4f5564639b33112ffe7 \\", + " --hash=sha256:58ddb5a8e3179d12f19e4ea34d2d32e9d63a4baa142c875c1eb59f41b7243acd \\", + " --hash=sha256:630ebfea3bf689d075f82316324ff7433dc447fe6bc1bfc76524b74b4a9567d2 \\", + " --hash=sha256:6f8700550aa1474a91e5dc07049c46f98b423b5b1ddd0483e0b51362eeeaf5be \\", + " --hash=sha256:78198641e5be9521beea5aa782bb551a58068d10e6eb04c9c680c1b69f2e7d45 \\", + " --hash=sha256:79def8d059362e7831389ed3be0ecdf58a89386e1271e35dd9f5af84e81bffd0 \\", + " --hash=sha256:7a8701d6b584d76e909e3d305b7d126b41439876a5aaf76cddc67fc230eafa2e \\", + " --hash=sha256:7afa5a6602a9f29af1f3a2965f831bae7c9d5d597b7cbb716d41ab3b7d89879c \\", + " --hash=sha256:7b46165bb56eb4704e2eaaf86f3c940d19154535d9b0ca7d6d590b04060e00d5 \\", + " --hash=sha256:7b75de3c8b3be1cdb1052747c929440c3eea46c1bc2cb8a6e3a48388e9b7b452 \\", + " --hash=sha256:7c6d0330c472d96f6a6afe24d80dfdf15176c33096f0a4397ae4c60f3dd3be48 \\", + " --hash=sha256:828d49b0ff5a0e3975865571c5d91dbbdd0d38d8289b249a163e9425413a5e05 \\", + " --hash=sha256:84f964e537f916e2cc85199e5a88742e964939b575ac8598b3f9d6cc416cdaf1 \\", + " --hash=sha256:85d0d9a31b9098e98534226d5686b47264b95e62ce459dc2e62fdfc809f9fe93 \\", + " --hash=sha256:87e9ce85beb6b328ba370cc6e6aea483c92617b4c95b1d33a49297eb662bfb04 \\", + " --hash=sha256:8c71ba2cd31fc93748c38e1b613200ff1c2665cbfd5341fe3a61cfde35a1430e \\", + " --hash=sha256:92e665960f25fcdc73725b9cec7a3824f279ba97a98653afe9ffac2e43668f67 \\", + " --hash=sha256:94e5e9f108ee10471288214d3d233fbfbb492840a8457eb85178d643ddeb32c7 \\", + " --hash=sha256:9c8402a82ea0dc4ceeab793db05f0fafa8ca139ca34fcde5df0f596103c74107 \\", + " --hash=sha256:9dab55f57c74c3cad24c323bacbbd04be4705ba6eb0d92e920b1fc4837ed5079 \\", + " --hash=sha256:a582ab2ae1d34f67112cadc86702774c9ea4374df6bca6afe672817203c99134 \\", + " --hash=sha256:a6557e5f38e065ca9fbdaf7cfc7435ecb1d113aa81a022d1b51921ee7432e227 \\", + " --hash=sha256:a9f7355e6fab51f6c369b86fb7571cffa05edee2c2121e0380a37fb9ac1cd5c1 \\", + " --hash=sha256:ab50ee449bf968271e820086f10a33d101dd060370abc10bcd22279be2656539 \\", + " --hash=sha256:ac9ed99d81760c62fe89d5f0815cdfa1ba9a35141cf30f1c2d044f04b4803d2e \\", + " --hash=sha256:b13478603dcd0a2479ff8e87e2c19a7d525734686fe3c49542472293a204212d \\", + " --hash=sha256:c423ab384a46c4dff7217b2ea5ba2e11cffdeab6441acd04cf65a369caf0366c \\", + " --hash=sha256:c5e67125c7dca78d199ec4e116aa93dbb83494808ecbb8211a2cb09b1bf41dbd \\", + " --hash=sha256:c71be1cbfa5cd9a41ee452acf1eccd82b2c05950358b106ec8ceb83411d1a020 \\", + " --hash=sha256:cbc8738fd8526d80f35cb3a40d41f41a2e7030bb3b18b09a6778ef63d291c2fd \\", + " --hash=sha256:ce47f66801c20ec6c6632453bb5960fe38939e9306970b48b3a5a26de7745d94 \\", + " --hash=sha256:d370b8d1dfcdf7130178137f6fbee6140774a1acc6cacefc4b42643ec11d0a3a \\", + " --hash=sha256:d38cdff612d06fa6a32840d5e1b1f7a27cee4a349aa9085d94a67789d6bfd408 \\", + " --hash=sha256:d8947001be83df1394050758ce0e745dd74fb134eef0a4b5124208dfc3a68c37 \\", + " --hash=sha256:deb9fde5c60e437ee4821bc9bc39ff31b42135c27e1dc61ef0a629389c1de62e \\", + " --hash=sha256:dfe9763530994147d9af1def057a5b9658b00e8f8fe8743d144d1e0911c2e454 \\", + " --hash=sha256:e105ab60406787da31fccc883fc0f733af1efd78f0136a4599692c4083a73d0c \\", + " --hash=sha256:e275096ea1e60cc595cda2836fd4a6c725d1125108b868be17f53684d164e2cc \\", + " --hash=sha256:edc3342adf8f697fc5f59c887a304356f147b397809440ed64e2fa6af2f50f37 \\", + " --hash=sha256:ee247f5c245c9a2fe7c8e2214e295918838e44e00a45a6718451e4004219e767 \\", + " --hash=sha256:eef4c2f3423810b3070ab391f85436d2f8bbfcb286ac15cbc73190b3563b1f1a \\", + " --hash=sha256:f21e8a22c8605750c7af886bab299a363721264061b4ac0a30efb73cfd58efc5 \\", + " --hash=sha256:f265528741e048bce55c3463ed721fb0aa45a5888d8add8cfeccb3035451bbdc \\", + " --hash=sha256:f2f9bd7f90c64fe89253f0a2c05e3c4856072660429ce8831b4235bf29403a67 \\", + " --hash=sha256:f785f6161f202ab04d8ca194158968798e480ca058943907972da5f12e2881e8 \\", + " --hash=sha256:f9f6143a8c75945eb960d9eb98905a441394abfa24afaae239d514ffb2586480 \\", + " --hash=sha256:fa8f5efb344d6908a1ce62f4a24e2e5780f825d6f53f5f50ec5ffacac72936cb \\", + " --hash=sha256:fdd28f912fccfec1846a94e2e1e8f9b0012f557f0c46fe4f3eb0d7a87afcf90b", + " # via dashscope", + "dashscope==1.25.23 \\", + " --hash=sha256:7cb2cc48fd82536202e3100e93730e92c952435bb8cbe16d45de9700e1546bcc", + " # via -r rl-lock-input.in", + "fastapi==0.163.1 \\", + " --hash=sha256:3d364b02a68b67292e833ff2dfed3b8dc3aeadf73e271c15316c6c166668792f \\", + " --hash=sha256:68f2d8050f5c3583121c0d203046cc7def5c16a7d6c43a0e7707a8ea610fe2d3", + " # via -r rl-lock-input.in", + "frozenlist==1.8.0 \\", + " --hash=sha256:0325024fe97f94c41c08872db482cf8ac4800d80e79222c6b0b7b162d5b13686 \\", + " --hash=sha256:032efa2674356903cd0261c4317a561a6850f3ac864a63fc1583147fb05a79b0 \\", + " --hash=sha256:03ae967b4e297f58f8c774c7eabcce57fe3c2434817d4385c50661845a058121 \\", + " --hash=sha256:06be8f67f39c8b1dc671f5d83aaefd3358ae5cdcf8314552c57e7ed3e6475bdd \\", + " --hash=sha256:073f8bf8becba60aa931eb3bc420b217bb7d5b8f4750e6f8b3be7f3da85d38b7 \\", + " --hash=sha256:07cdca25a91a4386d2e76ad992916a85038a9b97561bf7a3fd12d5d9ce31870c \\", + " --hash=sha256:09474e9831bc2b2199fad6da3c14c7b0fbdd377cce9d3d77131be28906cb7d84 \\", + " --hash=sha256:0c18a16eab41e82c295618a77502e17b195883241c563b00f0aa5106fc4eaa0d \\", + " --hash=sha256:0f96534f8bfebc1a394209427d0f8a63d343c9779cda6fc25e8e121b5fd8555b \\", + " --hash=sha256:102e6314ca4da683dca92e3b1355490fed5f313b768500084fbe6371fddfdb79 \\", + " --hash=sha256:11847b53d722050808926e785df837353bd4d75f1d494377e59b23594d834967 \\", + " --hash=sha256:119fb2a1bd47307e899c2fac7f28e85b9a543864df47aa7ec9d3c1b4545f096f \\", + " --hash=sha256:13d23a45c4cebade99340c4165bd90eeb4a56c6d8a9d8aa49568cac19a6d0dc4 \\", + " --hash=sha256:154e55ec0655291b5dd1b8731c637ecdb50975a2ae70c606d100750a540082f7 \\", + " --hash=sha256:168c0969a329b416119507ba30b9ea13688fafffac1b7822802537569a1cb0ef \\", + " --hash=sha256:17c883ab0ab67200b5f964d2b9ed6b00971917d5d8a92df149dc2c9779208ee9 \\", + " --hash=sha256:1a7607e17ad33361677adcd1443edf6f5da0ce5e5377b798fba20fae194825f3 \\", + " --hash=sha256:1a7fa382a4a223773ed64242dbe1c9c326ec09457e6b8428efb4118c685c3dfd \\", + " --hash=sha256:1aa77cb5697069af47472e39612976ed05343ff2e84a3dcf15437b232cbfd087 \\", + " --hash=sha256:1b9290cf81e95e93fdf90548ce9d3c1211cf574b8e3f4b3b7cb0537cf2227068 \\", + " --hash=sha256:20e63c9493d33ee48536600d1a5c95eefc870cd71e7ab037763d1fbb89cc51e7 \\", + " --hash=sha256:21900c48ae04d13d416f0e1e0c4d81f7931f73a9dfa0b7a8746fb2fe7dd970ed \\", + " --hash=sha256:229bf37d2e4acdaf808fd3f06e854a4a7a3661e871b10dc1f8f1896a3b05f18b \\", + " --hash=sha256:2552f44204b744fba866e573be4c1f9048d6a324dfe14475103fd51613eb1d1f \\", + " --hash=sha256:27c6e8077956cf73eadd514be8fb04d77fc946a7fe9f7fe167648b0b9085cc25 \\", + " --hash=sha256:28bd570e8e189d7f7b001966435f9dac6718324b5be2990ac496cf1ea9ddb7fe \\", + " --hash=sha256:294e487f9ec720bd8ffcebc99d575f7eff3568a08a253d1ee1a0378754b74143 \\", + " --hash=sha256:29548f9b5b5e3460ce7378144c3010363d8035cea44bc0bf02d57f5a685e084e \\", + " --hash=sha256:2c5dcbbc55383e5883246d11fd179782a9d07a986c40f49abe89ddf865913930 \\", + " --hash=sha256:2dc43a022e555de94c3b68a4ef0b11c4f747d12c024a520c7101709a2144fb37 \\", + " --hash=sha256:2f05983daecab868a31e1da44462873306d3cbfd76d1f0b5b69c473d21dbb128 \\", + " --hash=sha256:33139dc858c580ea50e7e60a1b0ea003efa1fd42e6ec7fdbad78fff65fad2fd2 \\", + " --hash=sha256:332db6b2563333c5671fecacd085141b5800cb866be16d5e3eb15a2086476675 \\", + " --hash=sha256:33f48f51a446114bc5d251fb2954ab0164d5be02ad3382abcbfe07e2531d650f \\", + " --hash=sha256:34187385b08f866104f0c0617404c8eb08165ab1272e884abc89c112e9c00746 \\", + " --hash=sha256:342c97bf697ac5480c0a7ec73cd700ecfa5a8a40ac923bd035484616efecc2df \\", + " --hash=sha256:3462dd9475af2025c31cc61be6652dfa25cbfb56cbbf52f4ccfe029f38decaf8 \\", + " --hash=sha256:39ecbc32f1390387d2aa4f5a995e465e9e2f79ba3adcac92d68e3e0afae6657c \\", + " --hash=sha256:3e0761f4d1a44f1d1a47996511752cf3dcec5bbdd9cc2b4fe595caf97754b7a0 \\", + " --hash=sha256:3ede829ed8d842f6cd48fc7081d7a41001a56f1f38603f9d49bf3020d59a31ad \\", + " --hash=sha256:3ef2d026f16a2b1866e1d86fc4e1291e1ed8a387b2c333809419a2f8b3a77b82 \\", + " --hash=sha256:405e8fe955c2280ce66428b3ca55e12b3c4e9c336fb2103a4937e891c69a4a29 \\", + " --hash=sha256:42145cd2748ca39f32801dad54aeea10039da6f86e303659db90db1c4b614c8c \\", + " --hash=sha256:4314debad13beb564b708b4a496020e5306c7333fa9a3ab90374169a20ffab30 \\", + " --hash=sha256:433403ae80709741ce34038da08511d4a77062aa924baf411ef73d1146e74faf \\", + " --hash=sha256:44389d135b3ff43ba8cc89ff7f51f5a0bb6b63d829c8300f79a2fe4fe61bcc62 \\", + " --hash=sha256:48e6d3f4ec5c7273dfe83ff27c91083c6c9065af655dc2684d2c200c94308bb5 \\", + " --hash=sha256:494a5952b1c597ba44e0e78113a7266e656b9794eec897b19ead706bd7074383 \\", + " --hash=sha256:4970ece02dbc8c3a92fcc5228e36a3e933a01a999f7094ff7c23fbd2beeaa67c \\", + " --hash=sha256:4e0c11f2cc6717e0a741f84a527c52616140741cd812a50422f83dc31749fb52 \\", + " --hash=sha256:50066c3997d0091c411a66e710f4e11752251e6d2d73d70d8d5d4c76442a199d \\", + " --hash=sha256:517279f58009d0b1f2e7c1b130b377a349405da3f7621ed6bfae50b10adf20c1 \\", + " --hash=sha256:54b2077180eb7f83dd52c40b2750d0a9f175e06a42e3213ce047219de902717a \\", + " --hash=sha256:5500ef82073f599ac84d888e3a8c1f77ac831183244bfd7f11eaa0289fb30714 \\", + " --hash=sha256:581ef5194c48035a7de2aefc72ac6539823bb71508189e5de01d60c9dcd5fa65 \\", + " --hash=sha256:59a6a5876ca59d1b63af8cd5e7ffffb024c3dc1e9cf9301b21a2e76286505c95 \\", + " --hash=sha256:5a3a935c3a4e89c733303a2d5a7c257ea44af3a56c8202df486b7f5de40f37e1 \\", + " --hash=sha256:5c1c8e78426e59b3f8005e9b19f6ff46e5845895adbde20ece9218319eca6506 \\", + " --hash=sha256:5d63a068f978fc69421fb0e6eb91a9603187527c86b7cd3f534a5b77a592b888 \\", + " --hash=sha256:667c3777ca571e5dbeb76f331562ff98b957431df140b54c85fd4d52eea8d8f6 \\", + " --hash=sha256:6da155091429aeba16851ecb10a9104a108bcd32f6c1642867eadaee401c1c41 \\", + " --hash=sha256:6dc4126390929823e2d2d9dc79ab4046ed74680360fc5f38b585c12c66cdf459 \\", + " --hash=sha256:7398c222d1d405e796970320036b1b563892b65809d9e5261487bb2c7f7b5c6a \\", + " --hash=sha256:74c51543498289c0c43656701be6b077f4b265868fa7f8a8859c197006efb608 \\", + " --hash=sha256:776f352e8329135506a1d6bf16ac3f87bc25b28e765949282dcc627af36123aa \\", + " --hash=sha256:778a11b15673f6f1df23d9586f83c4846c471a8af693a22e066508b77d201ec8 \\", + " --hash=sha256:78f7b9e5d6f2fdb88cdde9440dc147259b62b9d3b019924def9f6478be254ac1 \\", + " --hash=sha256:799345ab092bee59f01a915620b5d014698547afd011e691a208637312db9186 \\", + " --hash=sha256:7bf6cdf8e07c8151fba6fe85735441240ec7f619f935a5205953d58009aef8c6 \\", + " --hash=sha256:8009897cdef112072f93a0efdce29cd819e717fd2f649ee3016efd3cd885a7ed \\", + " --hash=sha256:80f85f0a7cc86e7a54c46d99c9e1318ff01f4687c172ede30fd52d19d1da1c8e \\", + " --hash=sha256:8585e3bb2cdea02fc88ffa245069c36555557ad3609e83be0ec71f54fd4abb52 \\", + " --hash=sha256:878be833caa6a3821caf85eb39c5ba92d28e85df26d57afb06b35b2efd937231 \\", + " --hash=sha256:8a76ea0f0b9dfa06f254ee06053d93a600865b3274358ca48a352ce4f0798450 \\", + " --hash=sha256:8b7b94a067d1c504ee0b16def57ad5738701e4ba10cec90529f13fa03c833496 \\", + " --hash=sha256:8d92f1a84bb12d9e56f818b3a746f3efba93c1b63c8387a73dde655e1e42282a \\", + " --hash=sha256:908bd3f6439f2fef9e85031b59fd4f1297af54415fb60e4254a95f75b3cab3f3 \\", + " --hash=sha256:92db2bf818d5cc8d9c1f1fc56b897662e24ea5adb36ad1f1d82875bd64e03c24 \\", + " --hash=sha256:940d4a017dbfed9daf46a3b086e1d2167e7012ee297fef9e1c545c4d022f5178 \\", + " --hash=sha256:957e7c38f250991e48a9a73e6423db1bb9dd14e722a10f6b8bb8e16a0f55f695 \\", + " --hash=sha256:96153e77a591c8adc2ee805756c61f59fef4cf4073a9275ee86fe8cba41241f7 \\", + " --hash=sha256:96f423a119f4777a4a056b66ce11527366a8bb92f54e541ade21f2374433f6d4 \\", + " --hash=sha256:97260ff46b207a82a7567b581ab4190bd4dfa09f4db8a8b49d1a958f6aa4940e \\", + " --hash=sha256:974b28cf63cc99dfb2188d8d222bc6843656188164848c4f679e63dae4b0708e \\", + " --hash=sha256:9ff15928d62a0b80bb875655c39bf517938c7d589554cbd2669be42d97c2cb61 \\", + " --hash=sha256:a6483e309ca809f1efd154b4d37dc6d9f61037d6c6a81c2dc7a15cb22c8c5dca \\", + " --hash=sha256:a88f062f072d1589b7b46e951698950e7da00442fc1cacbe17e19e025dc327ad \\", + " --hash=sha256:ac913f8403b36a2c8610bbfd25b8013488533e71e62b4b4adce9c86c8cea905b \\", + " --hash=sha256:adbeebaebae3526afc3c96fad434367cafbfd1b25d72369a9e5858453b1bb71a \\", + " --hash=sha256:b2a095d45c5d46e5e79ba1e5b9cb787f541a8dee0433836cea4b96a2c439dcd8 \\", + " --hash=sha256:b3210649ee28062ea6099cfda39e147fa1bc039583c8ee4481cb7811e2448c51 \\", + " --hash=sha256:b37f6d31b3dcea7deb5e9696e529a6aa4a898adc33db82da12e4c60a7c4d2011 \\", + " --hash=sha256:b4dec9482a65c54a5044486847b8a66bf10c9cb4926d42927ec4e8fd5db7fed8 \\", + " --hash=sha256:b4f3b365f31c6cd4af24545ca0a244a53688cad8834e32f56831c4923b50a103 \\", + " --hash=sha256:b6db2185db9be0a04fecf2f241c70b63b1a242e2805be291855078f2b404dd6b \\", + " --hash=sha256:b9be22a69a014bc47e78072d0ecae716f5eb56c15238acca0f43d6eb8e4a5bda \\", + " --hash=sha256:bac9c42ba2ac65ddc115d930c78d24ab8d4f465fd3fc473cdedfccadb9429806 \\", + " --hash=sha256:bf0a7e10b077bf5fb9380ad3ae8ce20ef919a6ad93b4552896419ac7e1d8e042 \\", + " --hash=sha256:c23c3ff005322a6e16f71bf8692fcf4d5a304aaafe1e262c98c6d4adc7be863e \\", + " --hash=sha256:c4c800524c9cd9bac5166cd6f55285957fcfc907db323e193f2afcd4d9abd69b \\", + " --hash=sha256:c7366fe1418a6133d5aa824ee53d406550110984de7637d65a178010f759c6ef \\", + " --hash=sha256:c8d1634419f39ea6f5c427ea2f90ca85126b54b50837f31497f3bf38266e853d \\", + " --hash=sha256:c9a63152fe95756b85f31186bddf42e4c02c6321207fd6601a1c89ebac4fe567 \\", + " --hash=sha256:cb89a7f2de3602cfed448095bab3f178399646ab7c61454315089787df07733a \\", + " --hash=sha256:cba69cb73723c3f329622e34bdbf5ce1f80c21c290ff04256cff1cd3c2036ed2 \\", + " --hash=sha256:cee686f1f4cadeb2136007ddedd0aaf928ab95216e7691c63e50a8ec066336d0 \\", + " --hash=sha256:cf253e0e1c3ceb4aaff6df637ce033ff6535fb8c70a764a8f46aafd3d6ab798e \\", + " --hash=sha256:d1eaff1d00c7751b7c6662e9c5ba6eb2c17a2306ba5e2a37f24ddf3cc953402b \\", + " --hash=sha256:d3bb933317c52d7ea5004a1c442eef86f426886fba134ef8cf4226ea6ee1821d \\", + " --hash=sha256:d4d3214a0f8394edfa3e303136d0575eece0745ff2b47bd2cb2e66dd92d4351a \\", + " --hash=sha256:d6a5df73acd3399d893dafc71663ad22534b5aa4f94e8a2fabfe856c3c1b6a52 \\", + " --hash=sha256:d8b7138e5cd0647e4523d6685b0eac5d4be9a184ae9634492f25c6eb38c12a47 \\", + " --hash=sha256:db1e72ede2d0d7ccb213f218df6a078a9c09a7de257c2fe8fcef16d5925230b1 \\", + " --hash=sha256:e25ac20a2ef37e91c1b39938b591457666a0fa835c7783c3a8f33ea42870db94 \\", + " --hash=sha256:e2de870d16a7a53901e41b64ffdf26f2fbb8917b3e6ebf398098d72c5b20bd7f \\", + " --hash=sha256:e4a3408834f65da56c83528fb52ce7911484f0d1eaf7b761fc66001db1646eff \\", + " --hash=sha256:eaa352d7047a31d87dafcacbabe89df0aa506abb5b1b85a2fb91bc3faa02d822 \\", + " --hash=sha256:eab8145831a0d56ec9c4139b6c3e594c7a83c2c8be25d5bcf2d86136a532287a \\", + " --hash=sha256:ec3cc8c5d4084591b4237c0a272cc4f50a5b03396a47d9caaf76f5d7b38a4f11 \\", + " --hash=sha256:edee74874ce20a373d62dc28b0b18b93f645633c2943fd90ee9d898550770581 \\", + " --hash=sha256:eefdba20de0d938cec6a89bd4d70f346a03108a19b9df4248d3cf0d88f1b0f51 \\", + " --hash=sha256:ef2b7b394f208233e471abc541cc6991f907ffd47dc72584acee3147899d6565 \\", + " --hash=sha256:f21f00a91358803399890ab167098c131ec2ddd5f8f5fd5fe9c9f2c6fcd91e40 \\", + " --hash=sha256:f4be2e3d8bc8aabd566f8d5b8ba7ecc09249d74ba3c9ed52e54dc23a293f0b92 \\", + " --hash=sha256:f57fb59d9f385710aa7060e89410aeb5058b99e62f4d16b08b91986b9a2140c2 \\", + " --hash=sha256:f6292f1de555ffcc675941d65fffffb0a5bcd992905015f85d0592201793e0e5 \\", + " --hash=sha256:f833670942247a14eafbb675458b4e61c82e002a148f49e68257b79296e865c4 \\", + " --hash=sha256:fa47e444b8ba08fffd1c18e8cdb9a75db1b6a27f17507522834ad13ed5922b93 \\", + " --hash=sha256:fb30f9626572a76dfe4293c7194a09fb1fe93ba94c7d4f720dfae3b646b45027 \\", + " --hash=sha256:fe3c58d2f5db5fbd18c2987cba06d51b0529f52bc3a6cdc33d3f4eab725104bd", + " # via", + " # aiohttp", + " # aiosignal", + "h11==0.16.0 \\", + " --hash=sha256:4e35b956cf45792e4caa5885e69fba00bdbc6ffafbfa020300e549b208ee5ff1 \\", + " --hash=sha256:63cf8bbe7522de3bf65932fda1d9c2772064ffb3dae62d55932da54b31cb6c86", + " # via uvicorn", + "idna==3.20 \\", + " --hash=sha256:a7db850025b95ded1eae8a46181a1a6c56c92c96f0e2b005d9ff8dc0210cab44 \\", + " --hash=sha256:ab7ae7122974553370f0bdb919e1a960b2cd1bc1ef0276416d896db81c14582c", + " # via", + " # anyio", + " # requests", + " # yarl", + "markdown-it-py==4.3.0 \\", + " --hash=sha256:7aa1511a46c39138de78d9eba92ce47e63124d8003fc98b3a351909e04239efa \\", + " --hash=sha256:91a58fa5b72c71a40cf7177250fd767480d7a2bb3ac426ccfb76fb90305fdaaa", + " # via rich", + "mdurl==0.1.2 \\", + " --hash=sha256:84008a41e51615a49fc9966191ff91509e3c40b939176e643fd50a5c2196b8f8 \\", + " --hash=sha256:bb413d29f5eea38f31dd4754dd7377d4465116fb207585f97bf925588687c1ba", + " # via markdown-it-py", + "multidict==7.2.1 \\", + " --hash=sha256:02009b402129a73e1f3da68f48eb999afbacd29f25aef0d5052b84ff5c2786a2 \\", + " --hash=sha256:02d9c04d395a36eeebe89e45f2269614a4675b8e83fddcba15bba2be903971e5 \\", + " --hash=sha256:03846be88267369908fcd9a91159358a3b142d740991c96e4f696d362fce516c \\", + " --hash=sha256:08ea94663d9e7c25d14d78222f7aee906c472d4837766bec62477c38f6e419dc \\", + " --hash=sha256:0c454b677214fa604e9c4a38952c685dc88a62c96f5576a7ce550f213d1dc318 \\", + " --hash=sha256:0c52fdd8cb8194fcb6969a417149aa1d09d6e48b69fb1b34ee1b1e4cb51ec183 \\", + " --hash=sha256:0c7b4d8cc9e6ae7070b8129bdb840215552d4e2689ca765d37eb208a24919209 \\", + " --hash=sha256:0d852d3d9638f852158d7de7200dd77f7ff8d77fc8f3d396032f3d847883f631 \\", + " --hash=sha256:0eb7fa012ab47b13e96bffc1369642f520adcc4e3d3e170d7f1a2b39fb953bce \\", + " --hash=sha256:0ec95a02f9f08246cc7f1d85ac425e4d5c233fd3f098f5be1b2cca16aa690186 \\", + " --hash=sha256:0f30d6eaf3cb309b6c21096c6c2b4cf3800f195a78b1babae85f481ce851bdc2 \\", + " --hash=sha256:12bbab225ce7f69df75409ab8005b11b4e9309fae863821e019e81b32e53a2a8 \\", + " --hash=sha256:13268013a3db11a214ccb6920f778d175b765f69a40509610b92e43602272718 \\", + " --hash=sha256:15da10cf11fd8d8716720c95b93180e94c8317405d89d08524c579ef360128ac \\", + " --hash=sha256:1d369ed297e79b417766327ece16bb7e89306c588df63c364a85d90d4aeac843 \\", + " --hash=sha256:1fb8c1a3480c130c3a6422d5f16f3cad6552bf08c2089dd288ba7134649183b5 \\", + " --hash=sha256:2022bd3194968a027f64ed16f9779e62e71a823a9df3971a7328c1d45dfeb9ab \\", + " --hash=sha256:21d86f2aa58aa428fb9909d6b8587b75eea827287e3515b8506dca86b55e2c7d \\", + " --hash=sha256:223427392fdf993e198644ec40c404fd93f1cd2a61328d18842ecbf154d02c82 \\", + " --hash=sha256:2529873a3bf68c372532a9f8058bcf4199e78387e92cd6a01b73334bfe6a7e3f \\", + " --hash=sha256:2592fb6c335d67f1912bf72788c02fd5dab305fc3c8c7eab078a5bec1aaa0f88 \\", + " --hash=sha256:25ebc4208d9098f77caeb16df895a0e56eb6c3b22870ac4e3ec43e0a9d6a33b6 \\", + " --hash=sha256:27166b6ec73eac37696d66b2c6efbd44b6d04b597d655070959df54dc7c71c0b \\", + " --hash=sha256:27cc258247b13008742f0e239933ad01dec5ed4e6dfc63849e30e04e1aa5bc82 \\", + " --hash=sha256:295a15ccb8cfde9351dd6062b80af4e839460636b3c46813b4aa443905ded86a \\", + " --hash=sha256:2b4d0c4e13d329ffee73d46128e32dd3b4aeb2f9c6ac9c8a89eb28d3b82dcea8 \\", + " --hash=sha256:2bac371da2c3554a99ba126f545e79ab8e8d9426a3e41df81d00ad725c1e2cbf \\", + " --hash=sha256:2c4e6a97f79699f33e6dc13bddb5631781ee79a4a94c1822116d100e7d5c136c \\", + " --hash=sha256:2d4cfbbb1023f0f6795b5395c400752fb23a5a09ba756aa9003886bbc47b3e12 \\", + " --hash=sha256:2e279ad5a6e9347bc9e043fdbee180a0480c8fd52618c3258e983dd93d98ed49 \\", + " --hash=sha256:2f3cf710144b1859f4128051cc27ea86eee83caac5648cf2ca0c1b835261cbbe \\", + " --hash=sha256:30572b61c7932e4d3c2ad1e580de7db1f35b7a35d36db38f89397ce3f2e69096 \\", + " --hash=sha256:335f715f8c111654f29e4bf19086bdf0245579d2b4f4f59ca8dd9b3003b859c1 \\", + " --hash=sha256:363e5db93fc3f65f3218a79fe108d217b9d264181a4e993c77552bfe275d0393 \\", + " --hash=sha256:36b868758fb11cfa748c788b793994e73660abec90f83c780a678539c2c468bf \\", + " --hash=sha256:37b161535e92776788957a165fcf38a80b33c1efde7b18cab287db4e4574df78 \\", + " --hash=sha256:3b7542fad2706595c1b1853b46f2c3c4ae5cc5a6252b7225f294d607a29e1bdf \\", + " --hash=sha256:3ca4e2e9102d0788b94894a30a5e3561fd4818a0605d8748d8fe780f890aa069 \\", + " --hash=sha256:3ca60708f0ca9d994f46790c5a5c774771e2f1dcb75b12c70a5582f915d0e721 \\", + " --hash=sha256:3d22ebb716ac79bf32c2a1d15250f017faef719114af4376e8dd814d6633cf0a \\", + " --hash=sha256:3d6fce7cc4ef63d9a7633cbae43e737798412805a4c3ba876cdf472dc6ff9c51 \\", + " --hash=sha256:4b338b45dc26ca4bac702e1278754f78613d4d0081e14e94e44fe8e261bf1750 \\", + " --hash=sha256:4bebc9587cc29359e3b045518a7a09264fa882a7d165b0d143fdac8eeb7ea948 \\", + " --hash=sha256:4d61be3725016ef5db3543c95f1f062d7d150ba776582d959a982af88e75fa55 \\", + " --hash=sha256:4eb2650aa240b62ab0c6d87238bee5d14aa4d411c0d69ad61be53e026e0785ba \\", + " --hash=sha256:4f31ddf9c00e0e7db848b0236c717acbe8a51954d0d31b4d908c538ab3f0f5bc \\", + " --hash=sha256:522f7d2351743804cdf5c5a304bc45f9d55e935dd87706fae2dbeafe0fed0b49 \\", + " --hash=sha256:5324411117bdb67cfaeb3d1d28fb783710fcca3d88b855696af99044d7219e4b \\", + " --hash=sha256:554ee1d2e71fb5b4059c0c4ee35d8cbc8af2a3147036d65a454c53fea07ff4eb \\", + " --hash=sha256:57ac987ec5d26d89bbc48c03e486f659e1367d425c465552ac2e4c4af8219def \\", + " --hash=sha256:57b5d0df4c60ab8b1159687610a1c3ae069ad2380d390a79dedff5c82318e714 \\", + " --hash=sha256:584ebfa26c9dcf3e465637a5a9afa2647bebb3022b50b1ff384834ba8e0380d1 \\", + " --hash=sha256:5a7df927c7999d1d3196176a8d4139d3a0e1765936f5de8c768097275b2d617a \\", + " --hash=sha256:5b944091cfa7da4f7a9bd2587569cd90c94b89ec4721f8e87fe62504f2432b67 \\", + " --hash=sha256:5deadf03fb4a7842696d551f9f9a06dd4445bb43ca06b5f9736e4e1885561333 \\", + " --hash=sha256:5efddcdbcb73f5485dca2b6624edc8ee063604b77bd3a3eb772826063965819f \\", + " --hash=sha256:65e4448dadc7c94a8643bb41361e45f3a73d46e36a008a9bc03e9b525f4d7c80 \\", + " --hash=sha256:66af55b07e4593790157e85f897f06983ded8a8692cb2fb048f3049c1d3fa172 \\", + " --hash=sha256:678ac791b5820d9346eb13c8515fe0c9383659335e5cfc544bf6f54714ca1939 \\", + " --hash=sha256:68b97b721d95b77d75e718d1b62a227fa4b3e647bd2a9fb39552d1a79ffb67c0 \\", + " --hash=sha256:6966806cf917cbbeb9a8b5c581db52e19c9af0ef5fe009db54c1f5799a6e003f \\", + " --hash=sha256:69befda4b1ef57027ea95dc6ed733568642f330fb3203a3e5c5ef107d41e0a1f \\", + " --hash=sha256:6e22756c6e2d4f57ead0d2e6be179d8a16d661bee424b81de0c6c0c1305ec39f \\", + " --hash=sha256:6efdeed2723431999cf3bcbc84c72dbe0f65d16bb1f84e15a657f5b60ff18ca6 \\", + " --hash=sha256:714fe5f3eabd153b1b6911d0b5d31cfc2b808ae6b9e59a32fab17a4e6cdad5a6 \\", + " --hash=sha256:7238f7135481926d52a94c18a8cca633a9e72c1cbfccd5796548298a479b0656 \\", + " --hash=sha256:74d3e015c28b43b6c1a108eec324ea2efb185c359c459216cabd4cb98f7f02f6 \\", + " --hash=sha256:76a4f5132b8dc29eb3c768ee9b47e132a1d24fbc2e9259854c01af9beaff1d49 \\", + " --hash=sha256:7726c53b1d59eb57b009a9e8759d4f71049ebdacf30642a198a197f80cea451c \\", + " --hash=sha256:781ca5dfc2f1d58e47f52216a0c1c7e1ba91ce8aa235459e20de2d402af77fb3 \\", + " --hash=sha256:785ef2f3e372dabc131f228a275f97eca92ad17cfab1ab138790e330d99abe3e \\", + " --hash=sha256:7cb1a6bb70edcc06ea65cb9a35654f268ee39d9fc3a52240e6ba074db4d9c99e \\", + " --hash=sha256:7fb3bc8d58e1b7c1d9fa1d995e30a4ce9dbe49f4c63c755a1ffdecdfbd026ccb \\", + " --hash=sha256:8148c2aaaf4b85d7872f024c8bb0c9b9797cc76b10588e3594a69cb01057472a \\", + " --hash=sha256:81a5f84a76401c4330e6db4e170dddd58860b30c4e8a44a181e5c2809c7f9c9d \\", + " --hash=sha256:81c6fc88ac9bf6920a0cdf22d3c383964167f12d35eb630463fc6d5ac89e460d \\", + " --hash=sha256:822a7fcd33f6922b650e1b26594f09d53c5d011fe655fea7ded27b2728ce2a1b \\", + " --hash=sha256:83fbd7cfaca614975efdbdcd9e2df45f3e987e819216468fb73e1db6f0365b98 \\", + " --hash=sha256:846b17193f1c373d6f05ada894fadf56bce2473067caea0aab51828849894b31 \\", + " --hash=sha256:8648dd5dc4d5db32b5936dc5e85e9a4d79db1135513d40d1f54ca15503750324 \\", + " --hash=sha256:873d35366cc115be02a1c858f9b22a1a9f6182b99aab2171ee5276af02a153e3 \\", + " --hash=sha256:8c3ff4f5c376df7126695a52af61e6084b69c9e52dcb9f4713e71ce9819e1bfd \\", + " --hash=sha256:90efd90a0f9b7ae3844a4fb3ae614321832d364ae19567b7cd312315fac4ec39 \\", + " --hash=sha256:9306e0c5595f91874e685be0a9eb743d48ba069c888eea051bec3c67c08b5b8d \\", + " --hash=sha256:987f65f6c9321402bc7012f6c6d09ba501b88ddb1640f5b0b4a19f2caafe24a5 \\", + " --hash=sha256:9a53776adc1ba923c9e345fdea7b61553c44c17a9af5eba8d8def8c5dcac4dec \\", + " --hash=sha256:9c44bd978adddf39df5834c6a1efd7d075c84769a7a084168d035a2a276d9008 \\", + " --hash=sha256:9c9f285f788acf2448a57c9b93d31103ac69bd03f92907e2ffbb23c4e2b42eb6 \\", + " --hash=sha256:9df532dd12c59a7a4d381646fc1bf5ccb4bcdbd01c0887d07ec769fae965ea9a \\", + " --hash=sha256:a0f999155c22c8929cc492949c08c6fe7ec8079a5e1bfdeb34b9a3e4991959d0 \\", + " --hash=sha256:a2a322c8a6ca82a5a67ae6542e9c6a13ded9045cfd171dcccc5c213ac4fe0eab \\", + " --hash=sha256:a3d28ac22fe658ad7486d1532b3a9084fbf65b428db31f47212c5b0b6da826f1 \\", + " --hash=sha256:a3d9a59bcdf8531d46b56bcd512017533510c25e955c2c546efd0743bd840940 \\", + " --hash=sha256:a789e3d27fc5665cc0477f10a35a89383313e4c9cf8b5e6af7ea71f039cdcc0e \\", + " --hash=sha256:a7d120bdde5b213e67ed7dc80ea3adf4f014453fbc20195d619ba2ceb34084f3 \\", + " --hash=sha256:a878fef2797a7c082aa47559af68299372edebc7367bd5128dff2d36e6d820e1 \\", + " --hash=sha256:a92e3080d8889b0f7a80ea0c4a72181b4d4d5d3918a03136b4a459f51f5f59da \\", + " --hash=sha256:a9cc121b5ee2c8b4bd4b6b526d5a26bb782f4d620463f73707691b2004b8c349 \\", + " --hash=sha256:b4821bd30b38144d8ab75df56af0b07e9d71327c9cf94c0c7a1965f865bb9615 \\", + " --hash=sha256:b5fb6b048931ea925b484f0c7c01b007981415a00a6c62ee74bbf8d229d39c08 \\", + " --hash=sha256:b63acdf4df5a78a15223bbb510bb3e0f8234dfa807610ccb8796d0842db2c801 \\", + " --hash=sha256:b81ff0f2d375988152614eaea4d5023c98ecb08f77df4bb1d96762504bb86fca \\", + " --hash=sha256:b97bffa5772b7e853303de094829fcd3a9bd49fddd70534651ee4933691f6587 \\", + " --hash=sha256:ba5e8d9310a794b853fb0e327d46a827b5b015576341219a591f88ed9d799c27 \\", + " --hash=sha256:bc9decb36abd00ed5d123db9df70eb9a0da45d6376d86d64f4a94bfd5a1b83fe \\", + " --hash=sha256:c10ac5e3e76837180656079008f71add8339b00c3c26314092bcd1e8e449049f \\", + " --hash=sha256:c753b820738cddc097892fee95e7cd716fbdfc9640414c5e9ce9463ad125321b \\", + " --hash=sha256:c85a0a54a19429a17ef449e967baffe7b5089cb4f6ef2894c9168a69fa024d05 \\", + " --hash=sha256:cadd02ca804d6ebe799a7af19197d9730094fe2cc74b70eb4f374f4b8c1886c1 \\", + " --hash=sha256:cb43bb34346155d479acdc5423afccdff79ce1fc66adfcc9de995cbec8a13acf \\", + " --hash=sha256:cb7fc8820b206932ec6d8f8985aeba6edfd2932e13b6c4bf2434d6bcbbeef3e1 \\", + " --hash=sha256:cba29f12cd717f1cbbe220edf005666f8df0453347217748331a0c2f7522eca4 \\", + " --hash=sha256:cd69c99affd1b4debc1f9a53058ea6e3a9b34f2e733840bb45891666cd8ede0a \\", + " --hash=sha256:ce0f884408938fbd72e764031d0e23a8f5e438a7bf73641089c7a6465cb84456 \\", + " --hash=sha256:cecb2c778f00a65c6ca01410dd194d0e797a9eebb7c6dea0db87718719f293c7 \\", + " --hash=sha256:cff7657e79224dea46f2f2e58eb99186656ca63ebe356212210c5c00e9beb814 \\", + " --hash=sha256:d0381074dc21225951278d7e4a7a2241f7fb86a4d8b94154dfee1411f49cf851 \\", + " --hash=sha256:d094951489bb7836342c005e790bd005e60b669aaf5c936b96dd5d68cbd2e23b \\", + " --hash=sha256:d10e49b940e70e2a4e91f44098007dda0bacb78c3f8e31ba7a37ee2ce52269e6 \\", + " --hash=sha256:d37773029ba034a2cc970b6eeb67dad3bff9d894393c51f6bb1c6b4f563a032c \\", + " --hash=sha256:d4af0d863e72f3ea48e85d3aa1d1b426fd81e9544fd7976fc6d6753584a25b03 \\", + " --hash=sha256:d5738cd929f2af8651ebb284467acb58b1ec0f2f4d42489cd0597172bc82e15b \\", + " --hash=sha256:d615377a8e7bfc4f1983ede3f411c2ac2b0f7c3053f262d0437b7d8bcc4485e3 \\", + " --hash=sha256:dbda2baafe08f8431fd3333be02c261023fd454607e3bde5e7dc00565f7bebcb \\", + " --hash=sha256:dc6f3dcb08c4b41e64f2d6cf272b5686d9144db585b2e138a8b1664376ab3921 \\", + " --hash=sha256:e0f2b33a6ae233f4da38c77ea32f90aab2cb82ba819d7b6c4f1b68cd33d871b6 \\", + " --hash=sha256:e47d058c2db95010f5d2e1f6037acebdfb0e2fa4507650e1041437985c91db38 \\", + " --hash=sha256:e64b86d16158954825d12799271979c6944c1fd1d03575b2f22e869c3f7d00dc \\", + " --hash=sha256:e8af3e6f1bdbc31fd762b094133b478b89988eaebc63cbe82b1d9e3bbd15cede \\", + " --hash=sha256:eb5c4a5b1281985271b6c29be53f2c1a9decf11e30a0e2733439c4d9d61b9ebb \\", + " --hash=sha256:ec4ee5d2d624088775e61cada87bbe7629bfd936bfbd57f122a106970d8ab1ee \\", + " --hash=sha256:ed6c107642a9acaa7ede32dcd428a6c87e302c5d555ecd3ec132ffa8c6155b4b \\", + " --hash=sha256:edffdb3950d3a8b769ddaec3a0962fb7b76b3c96f317f6b88500455a537dded2 \\", + " --hash=sha256:efe695cc2081633b02fcb95bc1b13070f6647c9ad52d42a8beeb3c2a7ea062dc \\", + " --hash=sha256:f07f06db2e333b68dd52560b8b0b12b6f8bf6053cedebf9af4aecfecd2dc1b32 \\", + " --hash=sha256:f15205c67d4c45250fcff5da077f0ae54102b5bc39e9ee8bab90d99e09a728c5 \\", + " --hash=sha256:f2087ee23a18d1d618a135eedcafba7dfc40c6be4e8e52d7f29a1c8a2344cfcc \\", + " --hash=sha256:f278f118f9fdb5faba5a6792be397fbda094d1568efa4dfe8c3595ce4ce89eea \\", + " --hash=sha256:f29885fef157a602d1816439e5da964c70ebcdbbcd4bb9d2d21b7e8bb5636604 \\", + " --hash=sha256:f2cc27ec6a53b1d39bab44d2b9dd21cc31e796d01b5e18a76d569721282bb264 \\", + " --hash=sha256:f332b16911ffc668baec6aaf8f08a09e1af34a8ee87ccac26bd722589e264645 \\", + " --hash=sha256:f5812cfcf7daf3ace5fedf6e2ef8d4b342c92fb8ea3a87c1aed2b50453271093 \\", + " --hash=sha256:f62172cf387e92f4928b60e5936b02c06e3c8449ed7fb440978d6c9bcbfc85df \\", + " --hash=sha256:f9c118e866164ce05498d9106a4bd01e745321403cd6f0b77a0b2587768f8c06 \\", + " --hash=sha256:f9e78d98a29e969a001e953eb09167a48bbc71249e804dae5db987ee7e6531c9 \\", + " --hash=sha256:fa0ecd064b0ae18d235283abb5adbc4e07304dba8f2aa7c0d61f28bebcc70d4c \\", + " --hash=sha256:fa949c81e3865c10f981dea72fd8d418b59edd13a047a0aee89ae64790113d53 \\", + " --hash=sha256:fba33e264cdd2ec43b762b9960d1648478eecfc1ce6e8159e7573510f0412c0a \\", + " --hash=sha256:fc45ff19520bc5321dcd9c6dd7df6f35ddd894eed35e5be65d1828a9c3f5e7fb \\", + " --hash=sha256:fcfebcb537f419e415b6e2bfc77ddbd33abe3c036f0105410a25a14741df9c31 \\", + " --hash=sha256:fd24c4425fdb8e822601335602375c6d0cb020f7a368e1d5842eb7925a9c8748", + " # via", + " # aiohttp", + " # yarl", + "opentelemetry-api==1.45.2 \\", + " --hash=sha256:2cbd737377e710ee740d261c94e93fa0f08e6d037c18f17513cc0a2d94479a34 \\", + " --hash=sha256:d7b0008e21e5fd61cbe7a7f34ca3b6905a78ab677d9bc395e299359c75cda6b4", + " # via", + " # -r rl-lock-input.in", + " # fastapi", + " # opentelemetry-sdk", + " # opentelemetry-semantic-conventions", + "opentelemetry-sdk==1.45.2 \\", + " --hash=sha256:7eec4de13dd21ff3a1670dcb0e02079e692736f94d733dfdce5af461d884248d \\", + " --hash=sha256:ff974ea70ee4f1d51e2ec152db37c2b626c7bf82bb3f7d86114fd8704e7199c6", + " # via -r rl-lock-input.in", + "opentelemetry-semantic-conventions==0.66b2 \\", + " --hash=sha256:4cbe61e5f9275d57ab31708446e7938ef4291ebbe6a7fca6f7a629c5acae87d8 \\", + " --hash=sha256:7da5f1a5dc4383eb66711d4d3d3e71824d9403ac1559fea021cc103c1a4c4976", + " # via", + " # -r rl-lock-input.in", + " # opentelemetry-sdk", + "propcache==0.5.4 \\", + " --hash=sha256:004e685b315646c410771836e72a44f143bbe624f29653a42687815069a303d5 \\", + " --hash=sha256:02c0a34f16889cf800f10f0247a564d8ce6eeab6ffcd7c87198f769067eb8432 \\", + " --hash=sha256:03969626faf0783a592dfa17e28eac06018bd0b44dafae6943d53b92421a7f72 \\", + " --hash=sha256:03b229037d25b801e7af53fd52b9fc49d9439b036fca1e087e02780631adfa97 \\", + " --hash=sha256:0951315a6b3142ee2167404d707743f0157c110091342b1aa0accac5cf0e4acf \\", + " --hash=sha256:0a095db8e15a6020db149ecbed6461939fe74f6acaa3ae8b702a1fe8c38cd983 \\", + " --hash=sha256:0c889f6fa84957bc7e8b4eab71fd16a0455068d5045e3aa40c733071d2b2fd77 \\", + " --hash=sha256:0d21d0d2c82bbfeb1677a9711f38df968f9837576102bb4add1bd449d28d88f1 \\", + " --hash=sha256:10ef33a68a61ce317e095fd2e202a592ea92392b90944a78c993f0d9a73ab06c \\", + " --hash=sha256:12682126712ddc19b70ff819debbd279e58adf1f0c8f8f8138c18ade2044b284 \\", + " --hash=sha256:135036c5cfc93864affb0f9af9a27e5d7a71cb7bd745e7b6dbfc2d56cc30e827 \\", + " --hash=sha256:13e52b6e0bde97dee98ab66552dbff2931649c96f1ac432eac299fe689ec373b \\", + " --hash=sha256:141fdbd73748db0cf7636035030aaac383d2efde8f34e7bc24594cc776d225b8 \\", + " --hash=sha256:146f48a9e4812611a7581003b1a39de56c34967046310c4171a68ef908c9a745 \\", + " --hash=sha256:174507f82d3594622acb1dd2dafecf2d899d6d506335494e7107767bf05f3aae \\", + " --hash=sha256:1783582065a1f07f9d9ee1e992e13f15d7dc8fb1eb3a7476d43eb3f2e69d26bb \\", + " --hash=sha256:17a7400cec0256f0a71ae71f9da398f9894c956ff6668a1c9d317b3367316320 \\", + " --hash=sha256:1b2f3bec4261a94019575481c726c29850f72e27907773c75b1de421e20e9f9d \\", + " --hash=sha256:1d759d05634f1b038fb625a66662a8c85e5a8fec912da381b5149ddac107482b \\", + " --hash=sha256:1df8d8561b21465c5dd56110a01caf897e026d065b4b84e98a488209094272ec \\", + " --hash=sha256:213bb68d9ced5cf2bf717b1071bf2b09b4b04c426256f9fe6d054c60318424c4 \\", + " --hash=sha256:23278f808cd81d5ada7184a76606b925fb3389c60e1077b2cd7da7b1fcf0553c \\", + " --hash=sha256:251c63dd46a0659bb875cb254dc4c1e79ee91a847c737cd62373295afc2235dc \\", + " --hash=sha256:279655a16973f1ee2bd2fe79973137681642fd9ae0d89215bba263726eb0dc3a \\", + " --hash=sha256:2814ecd8e818f487bee4b0f921bc4d1c176cc5fc71ac0f072d0fa67eda4ac14b \\", + " --hash=sha256:286867fb156488c251a3721766e380ac4495e4fd6b51aaa1403d89ce7f4359d9 \\", + " --hash=sha256:2dba2f02d2d5c09ef8a0e6c1a42aeaa451f4be9898cb00b04fe98717da2eb23b \\", + " --hash=sha256:30cc1cebaf9aef49db06357a50398323ae04d70460c0491837d026ab7d6452ea \\", + " --hash=sha256:31eb43ba2edc704ab2ec27815315dd8a19def0fb16215be4cfe8d32fe78ffd51 \\", + " --hash=sha256:350b272b2279f4135a64fc0c304a5d08e28a137c9573442c606152446638a831 \\", + " --hash=sha256:36c0d9db44b523ef93d03341b1c42d69ff01d673c053d1b1c6c3a363bcaa39ba \\", + " --hash=sha256:3af0c8642b2da4815d86e631232ac8286e17644fad907c19508aa8e7cb4ba8ad \\", + " --hash=sha256:3cd3a7edb6b95b9b33998135ebfa18d709da82290fb8f27c858970b5a12c8b56 \\", + " --hash=sha256:3d605bb239b796e82a81c6709548b2bd460ab73b4590cb0c83de8a2dd9694d0f \\", + " --hash=sha256:3e413d7a4a9b4866b7a761d6060d434b64d23cd35122eda3b026a0bbe8196b25 \\", + " --hash=sha256:3eb2e820e8e2101407da93f17c57cbb7d225461955fc60105daaba14cd421ee2 \\", + " --hash=sha256:3fa15757fea1dfcd5b7745cad9f4638929605531bd4018ab2adff7955f1a403d \\", + " --hash=sha256:3fc24f209c1b7f7f688b66b98293954f5504279760999b58920ee12dd8471c1d \\", + " --hash=sha256:4054acf80d40456a0537f2913b349718649d8d6458a14ab7f48d0ce28c30869d \\", + " --hash=sha256:40e94adb1e7d39ff28a8bd8d8b8fbd1df6b9f40976dbe379134f1ce058e532dd \\", + " --hash=sha256:420162a77f94eb1cf5ef7893f500016dabd548e73de956785a1dd899cc73006a \\", + " --hash=sha256:425f8cc86ab5018b4b8d4a23bc8e74d964bd3d757c3702e301aa79be76c53f6c \\", + " --hash=sha256:44149f46500a0a41b95b4d99c2e586a77319539730607b9892974a092788b111 \\", + " --hash=sha256:445ee3bfb46e85838387fb3c536a73cc0b994dc192b004e40e170adc54aa2a7e \\", + " --hash=sha256:45488d1a5f9ab5bd90aaa1ca20f50fe1922b8ffad71a2009d2adf41355897aac \\", + " --hash=sha256:45bebbe252550fec975ba3b62bc6f931643cfd3b5464ef47619cf3fef154e01c \\", + " --hash=sha256:45bf2e730ab8905d0527fe05a86500f406e64305c34cc81ebe64b4617cab9760 \\", + " --hash=sha256:48cb48c5346a97de792254af77715aa2529c2a1ebc5f586aa0aae44a02f1fe57 \\", + " --hash=sha256:4a1f4f5ffa55dce6307631f3cb2948e117e665966ea512e0d502b16c24f567e7 \\", + " --hash=sha256:4cfe0a92ae30151869e67a4b5f5e105e4e03ad30b3f38e5211b5bf77d0881993 \\", + " --hash=sha256:4d86476a935c88963d9b8e1a9a0d38188790e9622169bfbafa173046846709d3 \\", + " --hash=sha256:4e985382be6d15da8d0c2710a6fa7b9070fc9ecdeefb7f580e88373984ec8be3 \\", + " --hash=sha256:4f2d880ff60f45898f4acfa152aac8d04e3ee627d90ff4003491bf92239d5757 \\", + " --hash=sha256:4fbc1a15dc8cd1689508758d626b372b1f09d28d9577667feaf9e6bfcd8efcbc \\", + " --hash=sha256:50e337653721d20ead710da33bf44487fbe8a0db8782714b60306481e9f95b51 \\", + " --hash=sha256:53eaa697c4d0422ff4cb714d00231b43352064d97b944033b30c1d57cc506ec0 \\", + " --hash=sha256:56fc3f7599528db40b1efa0889a620116e2704144495273d66066e8164e45838 \\", + " --hash=sha256:58134228927cee6c047d626c08e60a81be604a20578a12ce752cc5c9a84d4826 \\", + " --hash=sha256:594eb4c6ec35e7179b058481f4e9f02521b56de16fa577c4b85c76fb1bf8a9f8 \\", + " --hash=sha256:5cacf3c9efd09df409dc33654dd077e1c245ba8fb747b0f0236ef41b7c49b589 \\", + " --hash=sha256:60a64cbccaa11b7760ce705a14ada17ba459e7ca9f23ba587eb013821032d7ef \\", + " --hash=sha256:62530ca89187827e4a4fe733f971abe81a7542eeea48ff61995f19b64d7199c8 \\", + " --hash=sha256:62c60aec739ed00124573cce1178138fd690c7676352d67a37328c1cf51d7468 \\", + " --hash=sha256:69fc35c0779522da366c563e5faf203ffc1f8ff0021d5b1337fa4efa5be73177 \\", + " --hash=sha256:6af4693716bfb03f1752ef1b30faa593db2c01d5272e9b8564a1549452a979ab \\", + " --hash=sha256:6c7599df2b57ebeea8de011b5f2f7b85de95e76037d43d34b95e328430275487 \\", + " --hash=sha256:6e9368e87a3efc285e559131092c5db643eb8e56de4ee42064d5baec22ef2bb5 \\", + " --hash=sha256:6f0093ac3e9daada202c2082439d414a625c57184727a46e112a3fb2a81cb788 \\", + " --hash=sha256:7177c43eddf10a0893c4fec52ebb408fdcd7f7d63962caace9180d8f81b14ece \\", + " --hash=sha256:720cf832eb2d0b0dfee129cb3335a26f6ce3cc45ee1187e8f0731758caa16792 \\", + " --hash=sha256:770e8209d018175fc0063936fa9583b6d27e88c5ad31543f3383d66080efdd62 \\", + " --hash=sha256:7a8d5ff04eb1f85698a78d20c62a14676e7b960dcafde09a388d60ad377d355d \\", + " --hash=sha256:7b9100a93b372418d8688f3f2a3e5b45c64d70ca4d6176e121aca1e3bfc1e32f \\", + " --hash=sha256:7cc528e760a8af06f2b13e9b9f362cd90c7c718ea61228a96dbd31ba16ed7f47 \\", + " --hash=sha256:7ffafcbfc7b549ab940047e505c831eabac5e67de53e1bc174adbc5285c55944 \\", + " --hash=sha256:87a3caecf8095e48dc72f84bfa42e23a848cf410cc9cc13031fba4869b706a21 \\", + " --hash=sha256:886b59c4d28ca97dd23b025fdfc50a0356be934efbbbca89ad26230067f86fe5 \\", + " --hash=sha256:8876b39961e33d912afe3c1bee18ee564fdad0206f873cc15d522756b7f50737 \\", + " --hash=sha256:897d1ddf6716e8f47200f7aad9a0efa6cc7586df66c6defa572f9eab379c078e \\", + " --hash=sha256:8a1fc236528c457cd739c88abe823da851b7ab645d72792f88658114cc340c12 \\", + " --hash=sha256:8a235f73d6e020855dc29dff012d920c02ee0feab8d73a24185a7569f4be1161 \\", + " --hash=sha256:8f911c395cef73c510bac566da9507bb6a43e7763d0c79138dc60ee53f11207e \\", + " --hash=sha256:96f7c5c15656040ddcbc51e56dc59b58aa25999d743c126abd425b9766ab43e9 \\", + " --hash=sha256:978f28401afbc76cdc3df9e1717b4229a06b626a1dcc75db4e1f2beb3884c3e9 \\", + " --hash=sha256:98914de2c4d7f0f9f4a8c6ea4bf05841f4175796941e3ef7d47eb718f22311fb \\", + " --hash=sha256:9a2a8a50a93dee0268a860a07fa3b4bd968f8ce4dbd794957da772f395368526 \\", + " --hash=sha256:9cbfff4423eef4cc6cafc021469641a2b835f610b2647a6c5281903e21b8670d \\", + " --hash=sha256:9e9ab13760aa8b6d0881ae7cb04fd891d8d490cd2554ea8e79bb278399169bcc \\", + " --hash=sha256:9f3551b8a35c1df3e7ea4d2d86edee15f0dde1bddd434a71744048683544d0ef \\", + " --hash=sha256:9f86f7259efe2c951f43e57d471c9b41daa5bfc7db9f67189059cf1ae6d77fd9 \\", + " --hash=sha256:9fb0a5be8d9aa213150e8d8148a42aca4984b285bcad1e69587dc4298edd929b \\", + " --hash=sha256:a219f0ac59817a9114dd2aa57c13180f993e819ba658c7ddab4b66ed1ee0d370 \\", + " --hash=sha256:a419ee85e654927baabda3929c03c0cc1112bf472ff0dfd6142f4e3a81ca4162 \\", + " --hash=sha256:a4d7a54719b67338a305dca2ce6aafe366817df94ddfd4b5514374356f5ca546 \\", + " --hash=sha256:a5793c7698a53f56f4a1889a4737c7eeb1b7ad0842fa6b1abca22913ff79c8c1 \\", + " --hash=sha256:a5e8ef588c109725dc713ba69aadcac00a1ef90c2ce9c0a8c7075128f569f47f \\", + " --hash=sha256:a74bfa37147cc08fb29df10bd9c16f40fa7f860cd3a6d2fff853323a94f6e17f \\", + " --hash=sha256:ada748108a43d29b7c328ba7db3755327cd94f028bcc1a7ee3f0addcfacd9c38 \\", + " --hash=sha256:ae58f361bd5dae942717c65d3413b478c70aea9c462599e7b9adad3731db3894 \\", + " --hash=sha256:b28f41fa3b8c6900457f858ec5b03998f3a6d535fbc1bb2edec5961ea05ec429 \\", + " --hash=sha256:b3083bfe87f95c756e610bd8025f26cbd1cd4aaa03a422f2d65efb7a97cd53d8 \\", + " --hash=sha256:b61805357d966680acf68b3b6d49772631ed9df44ebece10ff1460e117a7da8a \\", + " --hash=sha256:b77c313314524ca9c38fbd70f73515d04597ac58c40c939bc0e71eeb4abff680 \\", + " --hash=sha256:bee7d3aed13d56f54e681df38c3a23031bc9e3863f687d9d598825c9146acd7d \\", + " --hash=sha256:c02c0e570c5c7e077b0181a9f3cdb7d4c3617d1cda6b5c95bd5d34022923d82c \\", + " --hash=sha256:c174bfd1c48a1b51a3078e95586dde718374bac79719ab3541ec9e74aec40574 \\", + " --hash=sha256:c2ba30a89035b57b73e00475de948521602f543d79ce01db10b04b36c4c76fc8 \\", + " --hash=sha256:c3e98c55bde2bcf7db3c70d1aed7ae9aa8aebbf19a250c66645cde44cdb8b867 \\", + " --hash=sha256:c3ef2818d63bc86071e9d2989ae75a1bc32b8f7059cfd9f5abbbee70c32e2ed6 \\", + " --hash=sha256:c83acbce9f2b5e3f5f5eda9e53d2001fed22fcdfef81274a9e02d8fd53b70a30 \\", + " --hash=sha256:c9281e922c072158c91974d4589f1dbe0fee6d467f284c28e463f9f5a4d933f4 \\", + " --hash=sha256:cc07876cfb079b6f6f36d21ce75784ad6c2c6b563eeac0ed26c2fa2669b85df9 \\", + " --hash=sha256:ccf4f7a79e26bb7efb06ecd50c177833b71df05cbc748701372325e6bcc17f6f \\", + " --hash=sha256:cdee8205a44d0be91bbac4c41b95d86641b72dfc7aef1279400e4fda3f26a937 \\", + " --hash=sha256:ceb3e879afac028f93d272c957814695dc5569e4904262dbee92f6c41bd5e4a3 \\", + " --hash=sha256:d1f5a500bfcbb2c0ab85e98a0dcd70f5899d34efe365a0187700369a79603031 \\", + " --hash=sha256:d42a9a856a4a6e2f6c10f1318c07e7daa498d6593abe745c71dae4521a26ca39 \\", + " --hash=sha256:d83b12902eb8bce151259c86c03ba746600b2d994543de46e370cecf96c452f2 \\", + " --hash=sha256:d8e017eeb7482bed34cdb0d61cf2bcfc88d104bbab296a17cd16a6af8aabc70e \\", + " --hash=sha256:db3ae52ccc150dbc84704e9d642743897f3e1c54742ff34cacb661e52e3818a9 \\", + " --hash=sha256:dbab5f5ff6897c81f355d079010cdae85b02e5a0b518b5251523b8ad8ae9ac3c \\", + " --hash=sha256:dc4242ca653c9b30ab51c5f8193323e7bc0928f897ee9103201e59a43abcb72e \\", + " --hash=sha256:dcbf346a318a5e30063f547630b02bb787ce2f45b6368d5da143660b6a3835d8 \\", + " --hash=sha256:dd2ac8f5b643454c2cc6b6118b13da16e88f4a6434fc3ba61aca384029f04f36 \\", + " --hash=sha256:e1d52a05dc417279f7e5c7618c5dfbbc29923aaf9bc0a5c1802ddcebf54c61a0 \\", + " --hash=sha256:e6720ba44ad7e72174314d0e1fb0172494cff5c73a3a8a2159c3d2402ff15565 \\", + " --hash=sha256:e738ab81179510ce79b2eac9a6ecf47feffd9e76d1c72e403005dddb6e36c06c \\", + " --hash=sha256:e904d4d01f36bd6e197590be1533c44e06058771e0746dd073a8ebb3ef880858 \\", + " --hash=sha256:e9f165403b81fea7e89c932d89046a1e3d9a3a60e8d7ef2f249dccdcb0982bf5 \\", + " --hash=sha256:ec6a85f424afa8d23e0d9a094e5dbb6eda01da91c92b9183cd433768247ffc97 \\", + " --hash=sha256:ee19113bce2f3acd46432050688b70f61acd6857d75abb9ec96341b7e9ced123 \\", + " --hash=sha256:ef3b928d9c984322b5c44e6964d8dbc653da87d2d8ee1647fa6da43072e650a9 \\", + " --hash=sha256:f273dcf7149a50527c4fd1f55cfe9eac0f60753f5af544b4c9352578e20c0874 \\", + " --hash=sha256:f5470694918830da62fac9e69133b53d23b736d7070e587b27a4a2be37e08e68 \\", + " --hash=sha256:f574e460d1c8a08384a016fdb09ccf3543433263ed6b2f97104f979e64ea57c2 \\", + " --hash=sha256:f85915e00dcb1cd9f2f890ead064ed40a27df06f0db65be427b29482ae357572 \\", + " --hash=sha256:fc2461ecc45f17893f8207e73b46ea8ba93e33630e51cf4af3fbc21d47462b1a \\", + " --hash=sha256:ff6b113f50bc066a698db5d944d2c6dc7507168dd3341e255a8892fd0715a558", + " # via", + " # aiohttp", + " # yarl", + "pycparser==3.12 ; implementation_name != 'PyPy' and platform_python_implementation != 'PyPy' \\", + " --hash=sha256:a076f3f489b39b43ed13563a1dafe42447445bec2e294154ec5c57fcdda4c85e \\", + " --hash=sha256:f03387877eab82ce01bbdfd0ba7252ee55a90b1c708d5129e2ce915475cf1db6", + " # via cffi", + "pydantic==2.14.3 \\", + " --hash=sha256:1054f237f4d4733e5a30e1e2333bd33a2004ab9ab1510bd053a9a31bb48e232d \\", + " --hash=sha256:3f7b347782ab7e4cf4c798496ae3a82787d9f21ec12676a9c564355eeef8daa8", + " # via", + " # fastapi", + " # typer", + "pydantic-core==2.50.4 \\", + " --hash=sha256:0001d6920e3a5d92758cda460d6dc9f918a78ad6d5d092f1c8b5395e6b775356 \\", + " --hash=sha256:0574866e05f6adeecc520d87e87dd06210c0a51706341f6ef8421572f5a64444 \\", + " --hash=sha256:09450778e3ab58d3f565899fcfbf6c82926e31af29e28e799d1d50941316e0cb \\", + " --hash=sha256:0af56dbf8822ba9f4efcbbfdc15478f8b6fb08f1609860cb50aa2cc8476b3c34 \\", + " --hash=sha256:0b059a7968b1911be5a2d9a8234827ab0bef9d1e465d4b42da525894143550e8 \\", + " --hash=sha256:0ec20aca2b067369913716847f7dfe5f4dddf16a46965b7a70bbad5defaaba86 \\", + " --hash=sha256:0f87ae9db5ba8d8de40dcb93982cf8dd544e6552a80d3345af51941cc2146b80 \\", + " --hash=sha256:1239daaf063e62213ca1f34d96663900bd7510c42a786e843fd328af70e46445 \\", + " --hash=sha256:13b6dd62b5279f5b9d72f3bf918a35443ee8bd549241d9dc52d79a2c3b6d7016 \\", + " --hash=sha256:15bece43a02ad543c621c8305e67dedb5f27d378c5ba741e5a2c36523f8ef37f \\", + " --hash=sha256:16902a147b3da4840612164a5e67947104d63e978f7a57c395877a5e26690b9c \\", + " --hash=sha256:1afefe44ec042fbabfb4483ea258c04cf75ff4ff328d754f09b321fdaa232aca \\", + " --hash=sha256:1de7be9a66fc8536770481ab64a05aae5067c725f2b29a09543af00e6a417b97 \\", + " --hash=sha256:1e20cbde2b6deb33a51d08cd168454dd9044ec7d4474056f4d98d63f51578783 \\", + " --hash=sha256:2039e323acee9abfec1fb5f661776e8965fe5928f3b7f8431900a774cba5c317 \\", + " --hash=sha256:219114f8dcdcbe4720d82ef016b1287ce5a0a67d7c69ca61524eb72e82aac344 \\", + " --hash=sha256:22e874666bdbd96d6bf629d32cd8ab376fedf1fd62585b52a42b9fa9fa6c20b6 \\", + " --hash=sha256:23a9ba564b2db709ff16eca990992ba95a19069972b34bff87c81d4b473cd755 \\", + " --hash=sha256:25e7e1080f9f7ce7cd9d114b31470ce912771bd02f38c824721d3c35d312abff \\", + " --hash=sha256:26cb012c4b8ca9f847bd0ac15978bd3d0f55b050bfbe6c47355edfc7e945029b \\", + " --hash=sha256:29358a8ca74e7d81158d14e2b10c904bd18773293ae3788716c0626fe0342347 \\", + " --hash=sha256:2980a701be88f9128a7470189fa3bcda5387f76c298a6f8e000fc29eb2a6f4e7 \\", + " --hash=sha256:2a60ec2a57ac3ef3767e526e9bf706ec75aa3d79c4ea134d9d4fcf7c62a297a7 \\", + " --hash=sha256:2f42584e5785385f681163a42506cab0d51295e17599a648396c52a7046c1372 \\", + " --hash=sha256:2f5cc5bcb94063fbbdfd285a2b302da34af07491337c10bb35de1d5220fa1583 \\", + " --hash=sha256:2f6767122b37c780bb756a720a4eef2bc6a050a0a1143428834b3cbc89448bd2 \\", + " --hash=sha256:300753f71c73302e218124baf995f00058e085cd01869bd9610bcbd0bd4500c1 \\", + " --hash=sha256:30d4dc35bc0eea52202a90b3820445ee0072c820241bfa710a623a078c9b267b \\", + " --hash=sha256:32a991aebd165f227b7c7c60bb9d66c2c7de9c24308552da264c9938fde0f8d6 \\", + " --hash=sha256:32d6dda86383645ec428ea64dfc277036f5cbc60a72238eab28b91a3fdb9a113 \\", + " --hash=sha256:33b21f69540a12c2053cd1d95766d8bd9667a3897f7c712a642de8aa37eb0865 \\", + " --hash=sha256:39f489ce31272073e6e146f6781690f9c1ee8c126836e6403361ef91154d89fe \\", + " --hash=sha256:3a48a5254d15a0ad050318bfc7a9566d4ec740118187e8f303e47a6840287eb7 \\", + " --hash=sha256:3b8ee2589a082739c522c1fe4be227412fcf108b903abb6672ae2f5570558882 \\", + " --hash=sha256:3de6c2a4df2af0ac9ab4dc1488746fe8b1a90e27955d870d9edda3187d20092b \\", + " --hash=sha256:3e0b395648c6cb871bceb2906907f255dc876ec425f2d5b024e129985cea8519 \\", + " --hash=sha256:3e547ceec1da7382f01f9e13963023e53367a71802c88778b21b9645a077cbdf \\", + " --hash=sha256:41b2cd8b29dbb5a4c9828a70f50d1abfc92011115c813213d3a91205c6f731b3 \\", + " --hash=sha256:41f4f8ae714e4fea1d635880f8a1af715ecf080eed4d13c5b04a0f3210f9c61a \\", + " --hash=sha256:474f7e598c7902165662a5d5160d3fce31037890a2975a9871ebf7c05862300b \\", + " --hash=sha256:477af785d1846e4e96bf56983b92ea7553aaeccdeb8acdaa55c7cee9eda0ae32 \\", + " --hash=sha256:49eb1241a969a5994db6880c18c012b6cbe2340343d8f529721571806583e500 \\", + " --hash=sha256:4c29b8f2d6417069bb1f257e6b9113f5d64dc2f554cc200ea90b4fe2c5cdb733 \\", + " --hash=sha256:4eb15be588407148ef5937dc8d9256a71f6b115e6cddadb7aa20b6ee384680dc \\", + " --hash=sha256:4eda7e3fdef382b7d4492745988a5baaf6953923a337f8b9dde5f76fa8afde20 \\", + " --hash=sha256:523466eba8ee10f7480f3c2057563145978011c583130d2cc01fb1e7af808e25 \\", + " --hash=sha256:57fa0a9490785139f1a4e4f43891830d55dfe4408845c0c9cb5eff4aeaf75f69 \\", + " --hash=sha256:5b26e5f1793b96cdc60242bf38da86ff24a27a708aa396214cac9b534bf571c7 \\", + " --hash=sha256:5bc1811ef2b4d4ba63e8e452f6e332b6374bd1d2cbbfdf66826c8cb1f71dd10d \\", + " --hash=sha256:5c074454dc6d4f6f4ba6561a56bf33a14db7651d882a5a5321ba3ae8868e082d \\", + " --hash=sha256:5c1013647be741647895c102831dcf79c34209662dbb683df9efb864417ed7d5 \\", + " --hash=sha256:601fce6cea9ddeaa85329e12e7f351def38d233075f42a3012b9c48071b02941 \\", + " --hash=sha256:6118e5a5550e36582e19bac1a403711a748f9f18251b054c326d3db02aaa7a18 \\", + " --hash=sha256:629eae995185540406e3635df5d5cf1d44f19ea240840b835d3f44541ff694d8 \\", + " --hash=sha256:6348ad12fa741bcc9c2f173e99fbf27cbc038826d8c31a4a7d836eca27878ba2 \\", + " --hash=sha256:65376dbe1ab4dbc768ca2b72b7c13993562c035f5925fd3bc7ff9c8c585c515d \\", + " --hash=sha256:6619d49a89a15cd04334f76fec530c155923bfc60da74ff5d815a52629e1aa6c \\", + " --hash=sha256:664e74848c2f5fc27db8505fe24e1ecd3ac669412913bf73d176916f86cc08e2 \\", + " --hash=sha256:67f7cc397e1d5556a801d1cba74de0d27d827eb242e6c036c0ca273c745414f1 \\", + " --hash=sha256:696613a0c0e7b2b35356e389ba4195ce20cfe7a2fc2e992c87d974d973eabec7 \\", + " --hash=sha256:6c5687b59b6ba0f663c4f2f15470f68507d6b45ccd3a19ee6d224f95cbee70d8 \\", + " --hash=sha256:6c7d7b0b596319e9ce79ef96ce57a14054a2eac629c0588a0539187a218be799 \\", + " --hash=sha256:70dbc9f83c41f37a4faa62dae5203853847223a891da446f48ef2efcfd5df806 \\", + " --hash=sha256:71395a43da5584bb70556f380387e15f845c0dcf76373c1afbfa0025737576ac \\", + " --hash=sha256:71ade6d2e445839350d589ff99bbddfde16f3f32db28da5c894a09f99c8b2a03 \\", + " --hash=sha256:71e03d2ea1a221d020cfc5b6cc8bbbedef23a06704c70fcf4d0afb42965b22d1 \\", + " --hash=sha256:7210398a1607ad607dc73196e575b3148b00a333cbb602ddbe1b60ba54554f43 \\", + " --hash=sha256:7472c39480ccc11dda69a196d1b7c7a6b48eb6594b77f05d945599d3e47f731c \\", + " --hash=sha256:7646353a5a7c553c04167aca628e2550b538f492765b03ccf34321a560acc43c \\", + " --hash=sha256:76e0065998159244ff4c097a6c05ff08019c6fbb6e597a85846e73044f0215b3 \\", + " --hash=sha256:789a6453e5ffd18a7ab6b8c3a0dd8403053829197ec258ecb90c604c21ffcc99 \\", + " --hash=sha256:789f88dea57841cdebef392b5d6e90444d767117e9ff2e0d9172df5c9de6690c \\", + " --hash=sha256:7ac2769a7ddd661e07e26c12220adc31b17014c48234b2a5a88993b8d4109e09 \\", + " --hash=sha256:817953730e4a73a09008b010c4a42396cefe799616a22df2ac21d3927b3080cf \\", + " --hash=sha256:83d2beac85b757bfc404c5c0612df51c4ef33bbb7be65cf4a96b4da7cbc4ff4f \\", + " --hash=sha256:86c7c4615634b5c57a79770f5b738354e45ae219a89949aeae84f19169a05283 \\", + " --hash=sha256:8923fcd49f875e8a0448d7223d1fdf1a9973ae2d1f20d4158753ceb8909facd2 \\", + " --hash=sha256:8cceae48ae7f94990c2f4e36291e9ec9868735e8b0f19e4489a17b0422338466 \\", + " --hash=sha256:92f8f63df729061bb14558ed740e7a222f6e2aa6c2e6a5bcfb4e706676562049 \\", + " --hash=sha256:930ad463d3fb7a340d323bcc496ec32dae469ec9974c29ff569f19806b6b03b4 \\", + " --hash=sha256:94733cb447c37b0ce6f71b39ca1288d5f966a084023a5617b4cc35a852586859 \\", + " --hash=sha256:9be1cfe715ecaa060ffd5d599ef410b94ef2697a0eed4cee562f788a2aa2175b \\", + " --hash=sha256:a0c5210d038418a115e7cf8706bfa611bd14add2f5787274dba45aadca3155e0 \\", + " --hash=sha256:a2f8716344bbbd10443391be0b1f2003b34949e3c4e6883005c2bc498ab6b64b \\", + " --hash=sha256:a4bb174bd65f795c39ad6642d9d5bdc43351b306b7d0a654ab0d0abb38be245f \\", + " --hash=sha256:a70d5effebd81ebd8e15a8aabdc7980832367b2b00c36543bac378977004cc80 \\", + " --hash=sha256:a9ee990bf2cfbd81574c5d4f9f6c9d480a14b5b43d2c4f2ca13f4c6f48089394 \\", + " --hash=sha256:ab2822bcdcefb54d1e8ca29f5e3ec3afe160fb794bb3a3a73b09d11ed2671104 \\", + " --hash=sha256:ad92d255a165cde5f9882ff69699eaf5495e0a1f32e97566bbbb80f11e46781f \\", + " --hash=sha256:aead3b74b68396bf0feab5d57e050b730ded7df55853c1e048a87e00aaf033c6 \\", + " --hash=sha256:aeb2e123cbf978a905e9f55155c1b8316fbbfa7cf64d04521fe174bab302d100 \\", + " --hash=sha256:aec3c2d741a8e3ee993de7f95f37afb51e31b169c95dbd29da4cf6688f340914 \\", + " --hash=sha256:b0cdb655fbd1562c2dfc9986f9103a106f7058cd0915afc6e656d4b1d73f3387 \\", + " --hash=sha256:b26f39a5be3cd91a2035818be3d0ffdf5282c3e1f5f53d3b80b7024021acee52 \\", + " --hash=sha256:b2f2d13239487cecaae98c9f4d5904ad0737643cdf8873c88ec6a78b12214f20 \\", + " --hash=sha256:b300a30304c4c6aeab03ed06809819d9eceacdd58441d3c7dffe41edfd006091 \\", + " --hash=sha256:b42f64825f5d750228f08318a9bf4d723b7ecb4c472aedcb3013c3ec2dc1f949 \\", + " --hash=sha256:b67d38e8bb0ade7e6e84575e4bb153fab35b122458077273aeb08fdf12be9d2c \\", + " --hash=sha256:b867f9fd183d76977f810c626d539265183c25b2284762893a31e8d6cacc81c0 \\", + " --hash=sha256:b99bed995ed7c41515c11fe2beb86f8a6cc298e5537cae2f736de2f982f74ef0 \\", + " --hash=sha256:bd46bcc28ed85d3cf71581b42d90b4ebd1f2062f81879519fed209f8a4d1cfc6 \\", + " --hash=sha256:bee28aab5a580eec673f7b68dfa8dece3dd37bd207ef8d22fafe23a8e9837296 \\", + " --hash=sha256:c04e9d920e2674f54651fd260a15c5d2843526c73d5242ee4311325ddc9573b3 \\", + " --hash=sha256:c4c5a1770ecfe8bdb6c6f09f8d81ea4de04f7efb012fac1efa4ad315dccc1fd1 \\", + " --hash=sha256:c733087ecf7dde06b1d071679bfd5f3ba03266ba77814c1c7253bc48c9adedd9 \\", + " --hash=sha256:c813ada7a651193acda85b6bc1cf12abd4b37cd25c7c6a75d7183512cc374969 \\", + " --hash=sha256:c81d98e27d9d9261909dcccab1ba5d6ea1c98b0bb9470e368604614fd1d36ddd \\", + " --hash=sha256:c81e35862aced259177a537ce1a6264c3a97bae1ced184ca9dc10ea754563688 \\", + " --hash=sha256:c856e439a9d54d514e81a7131229ba151cdf81df7c408e0f6c89340e5003dfe2 \\", + " --hash=sha256:c9e70012926e97069cdd09221861aff412aa94e4cac2e019055cdb79485b150c \\", + " --hash=sha256:ca83a32b2b41653d89f09a3d22b770bca96da72273bef8f7a68136bdd1e8b823 \\", + " --hash=sha256:cbf0777d54672990b10cb8ca9b0523499e182d7e2ea39f86b138519a902aa601 \\", + " --hash=sha256:d49127f137f871cde3c5650af33bbbdcee02679dae76e020902fa106f522b8ae \\", + " --hash=sha256:d690121e80ab16e623415351ab24713534d4e500b3cadff216409cb6826063d4 \\", + " --hash=sha256:d6a166978f22f10cb91413f70519861605219346decf65bc79008f9257c94afe \\", + " --hash=sha256:d6e3485a5e5c01fb5339c1ee3d4b9e21e2135a2a9d44caafb71acd994487ee7c \\", + " --hash=sha256:d7d406709ae924cf0b08b8282ca2f0e1c90526911d93bc040557cbc83b74c55f \\", + " --hash=sha256:d8201c9f9035520cdcc7dcad383b039ec8123969b87e01cf27c3dd883c02313b \\", + " --hash=sha256:da779ae50b46f3f7d1e1b5f362fdc0ad376a49fd55f6f3122dc2b6149936cdf7 \\", + " --hash=sha256:dcf2c7eaaa4cafe8e49b017e5bb49e76e084ab6f0cd712ee4019c812b5cf68b8 \\", + " --hash=sha256:dd8bed00731a21e3106e5dd6bbffb6c775a2c0bbc7c0c9face534d830057bdc9 \\", + " --hash=sha256:df1c174796cd63eb6b139f7daf783affe1f3ed659605850e843b24764c21bfc5 \\", + " --hash=sha256:dfcf6e51000b34f7026322cd9ea9bc340d745637e27e0bbc22f504b4f6b967ee \\", + " --hash=sha256:e498900bfbf7ddddd862f810440c09e9b81674739e8a11d619b40906dccd4a9a \\", + " --hash=sha256:e512c75ec5cf4475c1aa50ad975ecdf253f4963b06e152e1a11edd6de4010753 \\", + " --hash=sha256:e5bd109d095aaae989a0463d5ef0fcc43e9ddd5de125e656d3c119a79e466380 \\", + " --hash=sha256:e6b4b08d09054310a4dc389fa61ee22a7a5a292cb23ab8a985136ca8828bf924 \\", + " --hash=sha256:e6da138a1ecc1341c8b788a5ee822670b03788e1f5decf7af9d461de6e508b8e \\", + " --hash=sha256:ea2f61b0bc12f3592288503961b764579dea0658852d96a0b3d823614d808821 \\", + " --hash=sha256:ed9c0b6f236648dbf30d57e9f57e1f74878caafa04833a19f529b5ba5164b7a8 \\", + " --hash=sha256:edbca8789fd10f0de534b660a6b4c71f1fd18039679c918dad392ab044bb37e4 \\", + " --hash=sha256:edc17549ab592e33cfcaf285f047bb75fcd98f608aa9309af1187fd736ce9641 \\", + " --hash=sha256:ef8a9ddb2e2a4eae4abb72dc0710eca6c2726779b0664bd10c3ce9fcfaed8c4e \\", + " --hash=sha256:f08ee8248aad2d054e5bc4c73554d4505464698f6d754f16198dbc5764e9821d \\", + " --hash=sha256:f1d62fb172db35c6478c9323da34ff37d1f3d37d7d44337a9d94ba8c583e5730 \\", + " --hash=sha256:f8fd23653a252cefabea11cd041efd7b80bdf403e43a36dea53f9cb0aaa21f0f \\", + " --hash=sha256:faa4e96385c820ce9d7f7a623486e23d4134ae3c9ba2071e44e0ab5a5a5002c4 \\", + " --hash=sha256:fb2bb5b557080da398b866408117d98fe9731a12334afd0cdff221b458cdc5dc \\", + " --hash=sha256:fc04affef30be98c1f36f0c422a4061ef618fdc1dde79f5ad5458dd496fecffa \\", + " --hash=sha256:ffb616d8d55965839670301dc3bae3abacff560a7e137a89056058a8a9da4d96", + " # via pydantic", + "pygments==2.21.0 \\", + " --hash=sha256:2363c69b61c4a97c838da3b130dcd6468f4848992b21a82f2a63ec34377137d9 \\", + " --hash=sha256:610ca751c9bc2492b38eb9a38a7fbc93edbbb2d7182edaf34e66ae493dee5c8c", + " # via rich", + "pyyaml==6.0.3 \\", + " --hash=sha256:00c4bdeba853cc34e7dd471f16b4114f4162dc03e6b7afcc2128711f0eca823c \\", + " --hash=sha256:0150219816b6a1fa26fb4699fb7daa9caf09eb1999f3b70fb6e786805e80375a \\", + " --hash=sha256:02893d100e99e03eda1c8fd5c441d8c60103fd175728e23e431db1b589cf5ab3 \\", + " --hash=sha256:02ea2dfa234451bbb8772601d7b8e426c2bfa197136796224e50e35a78777956 \\", + " --hash=sha256:0f29edc409a6392443abf94b9cf89ce99889a1dd5376d94316ae5145dfedd5d6 \\", + " --hash=sha256:10892704fc220243f5305762e276552a0395f7beb4dbf9b14ec8fd43b57f126c \\", + " --hash=sha256:16249ee61e95f858e83976573de0f5b2893b3677ba71c9dd36b9cf8be9ac6d65 \\", + " --hash=sha256:1d37d57ad971609cf3c53ba6a7e365e40660e3be0e5175fa9f2365a379d6095a \\", + " --hash=sha256:1ebe39cb5fc479422b83de611d14e2c0d3bb2a18bbcb01f229ab3cfbd8fee7a0 \\", + " --hash=sha256:214ed4befebe12df36bcc8bc2b64b396ca31be9304b8f59e25c11cf94a4c033b \\", + " --hash=sha256:2283a07e2c21a2aa78d9c4442724ec1eb15f5e42a723b99cb3d822d48f5f7ad1 \\", + " --hash=sha256:22ba7cfcad58ef3ecddc7ed1db3409af68d023b7f940da23c6c2a1890976eda6 \\", + " --hash=sha256:27c0abcb4a5dac13684a37f76e701e054692a9b2d3064b70f5e4eb54810553d7 \\", + " --hash=sha256:28c8d926f98f432f88adc23edf2e6d4921ac26fb084b028c733d01868d19007e \\", + " --hash=sha256:2e71d11abed7344e42a8849600193d15b6def118602c4c176f748e4583246007 \\", + " --hash=sha256:34d5fcd24b8445fadc33f9cf348c1047101756fd760b4dacb5c3e99755703310 \\", + " --hash=sha256:37503bfbfc9d2c40b344d06b2199cf0e96e97957ab1c1b546fd4f87e53e5d3e4 \\", + " --hash=sha256:3c5677e12444c15717b902a5798264fa7909e41153cdf9ef7ad571b704a63dd9 \\", + " --hash=sha256:3ff07ec89bae51176c0549bc4c63aa6202991da2d9a6129d7aef7f1407d3f295 \\", + " --hash=sha256:41715c910c881bc081f1e8872880d3c650acf13dfa8214bad49ed4cede7c34ea \\", + " --hash=sha256:418cf3f2111bc80e0933b2cd8cd04f286338bb88bdc7bc8e6dd775ebde60b5e0 \\", + " --hash=sha256:44edc647873928551a01e7a563d7452ccdebee747728c1080d881d68af7b997e \\", + " --hash=sha256:4a2e8cebe2ff6ab7d1050ecd59c25d4c8bd7e6f400f5f82b96557ac0abafd0ac \\", + " --hash=sha256:4ad1906908f2f5ae4e5a8ddfce73c320c2a1429ec52eafd27138b7f1cbe341c9 \\", + " --hash=sha256:501a031947e3a9025ed4405a168e6ef5ae3126c59f90ce0cd6f2bfc477be31b7 \\", + " --hash=sha256:5190d403f121660ce8d1d2c1bb2ef1bd05b5f68533fc5c2ea899bd15f4399b35 \\", + " --hash=sha256:5498cd1645aa724a7c71c8f378eb29ebe23da2fc0d7a08071d89469bf1d2defb \\", + " --hash=sha256:5cf4e27da7e3fbed4d6c3d8e797387aaad68102272f8f9752883bc32d61cb87b \\", + " --hash=sha256:5e0b74767e5f8c593e8c9b5912019159ed0533c70051e9cce3e8b6aa699fcd69 \\", + " --hash=sha256:5ed875a24292240029e4483f9d4a4b8a1ae08843b9c54f43fcc11e404532a8a5 \\", + " --hash=sha256:5fcd34e47f6e0b794d17de1b4ff496c00986e1c83f7ab2fb8fcfe9616ff7477b \\", + " --hash=sha256:5fdec68f91a0c6739b380c83b951e2c72ac0197ace422360e6d5a959d8d97b2c \\", + " --hash=sha256:6344df0d5755a2c9a276d4473ae6b90647e216ab4757f8426893b5dd2ac3f369 \\", + " --hash=sha256:64386e5e707d03a7e172c0701abfb7e10f0fb753ee1d773128192742712a98fd \\", + " --hash=sha256:652cb6edd41e718550aad172851962662ff2681490a8a711af6a4d288dd96824 \\", + " --hash=sha256:66291b10affd76d76f54fad28e22e51719ef9ba22b29e1d7d03d6777a9174198 \\", + " --hash=sha256:66e1674c3ef6f541c35191caae2d429b967b99e02040f5ba928632d9a7f0f065 \\", + " --hash=sha256:6adc77889b628398debc7b65c073bcb99c4a0237b248cacaf3fe8a557563ef6c \\", + " --hash=sha256:79005a0d97d5ddabfeeea4cf676af11e647e41d81c9a7722a193022accdb6b7c \\", + " --hash=sha256:7c6610def4f163542a622a73fb39f534f8c101d690126992300bf3207eab9764 \\", + " --hash=sha256:7f047e29dcae44602496db43be01ad42fc6f1cc0d8cd6c83d342306c32270196 \\", + " --hash=sha256:8098f252adfa6c80ab48096053f512f2321f0b998f98150cea9bd23d83e1467b \\", + " --hash=sha256:850774a7879607d3a6f50d36d04f00ee69e7fc816450e5f7e58d7f17f1ae5c00 \\", + " --hash=sha256:8d1fab6bb153a416f9aeb4b8763bc0f22a5586065f86f7664fc23339fc1c1fac \\", + " --hash=sha256:8da9669d359f02c0b91ccc01cac4a67f16afec0dac22c2ad09f46bee0697eba8 \\", + " --hash=sha256:8dc52c23056b9ddd46818a57b78404882310fb473d63f17b07d5c40421e47f8e \\", + " --hash=sha256:9149cad251584d5fb4981be1ecde53a1ca46c891a79788c0df828d2f166bda28 \\", + " --hash=sha256:93dda82c9c22deb0a405ea4dc5f2d0cda384168e466364dec6255b293923b2f3 \\", + " --hash=sha256:96b533f0e99f6579b3d4d4995707cf36df9100d67e0c8303a0c55b27b5f99bc5 \\", + " --hash=sha256:9c57bb8c96f6d1808c030b1687b9b5fb476abaa47f0db9c0101f5e9f394e97f4 \\", + " --hash=sha256:9c7708761fccb9397fe64bbc0395abcae8c4bf7b0eac081e12b809bf47700d0b \\", + " --hash=sha256:9f3bfb4965eb874431221a3ff3fdcddc7e74e3b07799e0e84ca4a0f867d449bf \\", + " --hash=sha256:a33284e20b78bd4a18c8c2282d549d10bc8408a2a7ff57653c0cf0b9be0afce5 \\", + " --hash=sha256:a80cb027f6b349846a3bf6d73b5e95e782175e52f22108cfa17876aaeff93702 \\", + " --hash=sha256:b30236e45cf30d2b8e7b3e85881719e98507abed1011bf463a8fa23e9c3e98a8 \\", + " --hash=sha256:b3bc83488de33889877a0f2543ade9f70c67d66d9ebb4ac959502e12de895788 \\", + " --hash=sha256:b865addae83924361678b652338317d1bd7e79b1f4596f96b96c77a5a34b34da \\", + " --hash=sha256:b8bb0864c5a28024fac8a632c443c87c5aa6f215c0b126c449ae1a150412f31d \\", + " --hash=sha256:ba1cc08a7ccde2d2ec775841541641e4548226580ab850948cbfda66a1befcdc \\", + " --hash=sha256:bdb2c67c6c1390b63c6ff89f210c8fd09d9a1217a465701eac7316313c915e4c \\", + " --hash=sha256:c1ff362665ae507275af2853520967820d9124984e0f7466736aea23d8611fba \\", + " --hash=sha256:c2514fceb77bc5e7a2f7adfaa1feb2fb311607c9cb518dbc378688ec73d8292f \\", + " --hash=sha256:c3355370a2c156cffb25e876646f149d5d68f5e0a3ce86a5084dd0b64a994917 \\", + " --hash=sha256:c458b6d084f9b935061bc36216e8a69a7e293a2f1e68bf956dcd9e6cbcd143f5 \\", + " --hash=sha256:d0eae10f8159e8fdad514efdc92d74fd8d682c933a6dd088030f3834bc8e6b26 \\", + " --hash=sha256:d76623373421df22fb4cf8817020cbb7ef15c725b9d5e45f17e189bfc384190f \\", + " --hash=sha256:ebc55a14a21cb14062aa4162f906cd962b28e2e9ea38f9b4391244cd8de4ae0b \\", + " --hash=sha256:eda16858a3cab07b80edaf74336ece1f986ba330fdb8ee0d6c0d68fe82bc96be \\", + " --hash=sha256:ee2922902c45ae8ccada2c5b501ab86c36525b883eff4255313a253a3160861c \\", + " --hash=sha256:efd7b85f94a6f21e4932043973a7ba2613b059c4a000551892ac9f1d11f5baf3 \\", + " --hash=sha256:f7057c9a337546edc7973c0d3ba84ddcdf0daa14533c2065749c9075001090e6 \\", + " --hash=sha256:fa160448684b4e94d80416c0fa4aac48967a969efe22931448d853ada8baf926 \\", + " --hash=sha256:fc09d0aa354569bc501d4e787133afc08552722d3ab34836a80547331bb5d4a0", + " # via -r rl-lock-input.in", + "regex==2026.11.15 \\", + " --hash=sha256:03e3e31271f40e17f038e2810014a15b3e9b0950c8dac5ca910a3375ffc7b112 \\", + " --hash=sha256:058e6aa045d02985490d6622b986cb7db25929890384faf642233539439b804c \\", + " --hash=sha256:0a24a03358c429457365e600ad639ca6111b61a6275dd2756b4e02a792ec8477 \\", + " --hash=sha256:0e1cd15586d8afa75a925f1837ad347e61e3d32d9bbe0b0e63edb194b4d718c5 \\", + " --hash=sha256:0fa62f316890f582ec536aa4e993b8e3679d493b45d87de77b59e9df2325ad28 \\", + " --hash=sha256:119909bbaae76605210572042196de125e261037f915dec273af3b13fae65c06 \\", + " --hash=sha256:14feb390805c099e16bf7d37e5f574068eeac59c55336a76d0c1c6f7388b2510 \\", + " --hash=sha256:150f52dbcaf759d94c73a61dc31ccc60eb8a552acafa43e99e3ed76405173170 \\", + " --hash=sha256:19989877c737d3f648a6addd2cba45b2698b895cd15ac37388eb4af48b6af819 \\", + " --hash=sha256:1b34d1f63493a14845e70b72a53eb6b1542f63c44cb615ecf2fd68ec470ed489 \\", + " --hash=sha256:1bdcc15a5e10be63a05f6660ac28679f7ab50cd48d8a53c9328b030d2bc36060 \\", + " --hash=sha256:1c3c89fbbb08d2f75e36179d27154e867836656a9ab57616aaf8042c089c0d20 \\", + " --hash=sha256:1f05e0ea23b59b4a69e08498c6d2b58eb94719dd1966e97b73e4c1df1604db38 \\", + " --hash=sha256:20a86cd29d0323feab48ddb630cd7a48e66355504e6f4661329f11a931ed58f2 \\", + " --hash=sha256:20fb02e33c0e3c0a265d1b767c359c92d0df9292292c280ff67ace49e3e05467 \\", + " --hash=sha256:2388100a73abc2205b22b37f292661bfd1b221be0fde996e5e4f1ad272335471 \\", + " --hash=sha256:259abe2f6d24a87928715f758f55ad8bad58f02c950447cad42f46752cd96c66 \\", + " --hash=sha256:2ade9b8a36259183539c2eb82cc163ebaac1c38d14b4a30da9433295a4610dc0 \\", + " --hash=sha256:3232156a2b62a063f21aa155154e9cc943ca05eeae1d1a00dca7910c7cc1976c \\", + " --hash=sha256:34fd5add8dedc9b1de724049951e3835afddc21cc43e2741cdce6e1c92b88b81 \\", + " --hash=sha256:37f839f3a65368314d232376c754eee726ce4a34030c18247c76d238ef0ff249 \\", + " --hash=sha256:3a16f20dcfb68ad67bcc326757facad9b3e922693409c1c8c0deea3869e70669 \\", + " --hash=sha256:3b896ba13443de0048e7adc18632ea04a163641a77e977a010cc178f45b2352c \\", + " --hash=sha256:415ae840ea09b36e40fe602d65a84c2fec12a5bff845d932a6cc863c94a60b96 \\", + " --hash=sha256:42f9f6d0f3698f8b32cfe45b03cbd1830a7c203c9930fe15a1516ab9dda19c36 \\", + " --hash=sha256:481626b285706374a83f7ce569f2d1a0c640700a569d5ca54dba1d2668e03a04 \\", + " --hash=sha256:49ca893a13a1fb68fcec24ddf19e8c8dfb13fef697c1ed9d65711b5881d03180 \\", + " --hash=sha256:55db42bd5d8de089e2ab3e5ef48a83c013fa6eb81cc69e3e124556762b61cff3 \\", + " --hash=sha256:5607a1d49b4ef9d4a61de1a84902a09e4bd6619be71712d7c32381292ece5063 \\", + " --hash=sha256:5de7aeead82b6f40ec8524555bcbfdf21824ac97fd8e219598008befba56fc91 \\", + " --hash=sha256:66a49a7a63c0d77d0abe20edcc2d9466c8bb7b6a78d77c61871c768d6894f72f \\", + " --hash=sha256:681e92c0de78a5124e5a2e53788538c7acba4c8086d90623fc8101840583d40b \\", + " --hash=sha256:6dace895669eb1a4e4c02ffa6595fc4f02873de53f88fc21e70d41c4451220a7 \\", + " --hash=sha256:7011045ea36d3d642ae5207f2f80f0486f3495f6107326bc1d9a9c68b2ba9f72 \\", + " --hash=sha256:702089e41de56efc2cf4a690dcdc6c16e80833bb336eeee70b61c147bbb608f4 \\", + " --hash=sha256:7288fae326a15b1ea57c6b07225a1b6e0b68def5dbe7670651a35e4af61f785b \\", + " --hash=sha256:74e0b34c79b7c27e47d5929e565ab703a2149e89c5d50d99e06e33410ff29394 \\", + " --hash=sha256:76d4a6f241bd25e915ee292722cd06610d417689d11f9b1080fcb3693952fe6c \\", + " --hash=sha256:7848463f856954ca7991c076cad16734329596417e8ed266b1753ac09dc51097 \\", + " --hash=sha256:7912578bc32a25cde9648f35ef00e064464792980f43fa0a690501277e33042e \\", + " --hash=sha256:7ad141cdbb94ee48a9128b7118bf82b4df2b80f3b3caa22c36045da49e765481 \\", + " --hash=sha256:7ddabafb036132a20a8868637bfade62a98e5edefc574a52a91ce73961bc4e47 \\", + " --hash=sha256:7e0562f26fbe338b614691a3ab7040392b17c5ed1cb26e04032c9c1a874b0040 \\", + " --hash=sha256:808be73b8fcb4bc9f1996ce0dead2e49aaeee0cd11db0691f7b63eea7c0f8448 \\", + " --hash=sha256:81130194b54191230abe0bc57f15f70f18147d1c1c7c237f85e6a2425c1c0445 \\", + " --hash=sha256:81a0a8a2cecab76abc0fbb4d50f849d004a6128accb32d77109b92e8324d4272 \\", + " --hash=sha256:82abe7618741745c83a8cf3f0decc4605c3bb5a2b6e1bc5e7412be01ed10eabb \\", + " --hash=sha256:8721e5331ed77ddc52e86e2f3111840e58e3182bb049195fb632c441e8ed853b \\", + " --hash=sha256:88da86058c8ee083aa4ecb8c73bcbb46e388a34a4d548b73c834e77409a445a1 \\", + " --hash=sha256:8965eafcd408db9f44d7ae9debf052dfbad3748972510bc1c7e2d6241645a3bf \\", + " --hash=sha256:8a194defd67c120d7dfbd8459b9d98057bdcd03a8466b977d4d237a526c053a7 \\", + " --hash=sha256:8a3cb0651bc61270f3db6f733a277a9c1bea006ab9e0bf17d5a1ae36ea55def6 \\", + " --hash=sha256:8ba7541b08666615b6a5348fb9b2553dcdb7b6543089f318b77135667c3a7d43 \\", + " --hash=sha256:8f1c6871464b8da493f1f6828f1073725a0e9cbaacb1181a3334e65422c062ef \\", + " --hash=sha256:930c3244a9128d9546c50f9b03c01c22b3674bf006fd8830f2581e74bb5f1105 \\", + " --hash=sha256:958661f35e8f260fea889a9a4b42db0e2756f85971c8f7371d9059cfd1997f70 \\", + " --hash=sha256:95cf02fb529fdda5f9414303e3a9c0e1807bc4a00ae5b0ac214e66812fa175aa \\", + " --hash=sha256:99e61a4f575b3439de59de524bed94d144b22a11877407c81c702ce98fb4e1d3 \\", + " --hash=sha256:9a7d15f046e1ea4be447749462ad588effe5fe4c6e26271649385d89767d6e9b \\", + " --hash=sha256:9d304418a1de575974d85c1d3b4ca04b8371d18cbe55c9f953fbaebcb61741c6 \\", + " --hash=sha256:9dee9001be6426e1ca58411e5b77dbf297d89cfe4f1d3abe78595ecd912adba7 \\", + " --hash=sha256:9f94950edcaee1925e1e9ab11d1b458029d525f42b32eb8014c93ead19a22fdb \\", + " --hash=sha256:9fc28a3e2f8a1d6930dcdbefb31a80a82caa86619980f147d5bfeca30eae76b3 \\", + " --hash=sha256:a489fde13c1f49325ff8b3f4ac2138631edd093c02dfbfa31921cd8a478e8aff \\", + " --hash=sha256:a99aa9a355ebe33cc7a68e6651c20712f338fa57a8e8cebd782e4208543c3b46 \\", + " --hash=sha256:aafeb64c8569d69edfbf772feba49d2a001d3dca0f43e6a71e3735587ecb8222 \\", + " --hash=sha256:ac637b5ad26f868091fd939426dc5aa4b75237c2cc72196cab756a861abd107e \\", + " --hash=sha256:b22436339fe2fbf5e932f4b187dd1244663f05fe96d255c11c0cb1adaaa13576 \\", + " --hash=sha256:b2bc7e596c7fd46f303a42ce40b4e9c08fdd37f431695052acbee2e7ac7db6ae \\", + " --hash=sha256:b55f41770984827e083808892b25022b618a74e228887bdfc51574621dcf96e9 \\", + " --hash=sha256:b569ef5adf7dc957c24602b243cc3af6f4e8fc80d688d528ec478b4164f3f1b8 \\", + " --hash=sha256:b90e34261f0cc8ab174602a86bfc0b9b89825ba7fa05b996a1c97a1426730267 \\", + " --hash=sha256:b9aff8d89f72818646f192632c8249f3848a23d2c9527360de356d6025c5bcee \\", + " --hash=sha256:bbe5efba8a008a2a684173286be44b85b2cfc3427107662440903ccce6ec00d5 \\", + " --hash=sha256:befb860301d5c4736e0cdfabbbe2ea5887a7a643594f5e32c59d9a28f94a5f75 \\", + " --hash=sha256:c2873cc9abe12d0ad55e4ff5b616856c2e1b764f39d58e931038c06b37e5a7f4 \\", + " --hash=sha256:c487f7832327bbaf68d66b47e8848586e2d07ceb0028ba71a42cd5ec10585bd3 \\", + " --hash=sha256:c56b4d165feb65211571007f4b016d142b52fffb91b30bb4b38175cf3acd3917 \\", + " --hash=sha256:c58f6a5c1f080384010dfa8b33378fdc554b4ad96299d3dcbe362a7aaa50857d \\", + " --hash=sha256:c5d722af534ac05fea28db7876d45aaae1f8b6c504cf82a5ab27cd80e543e9fe \\", + " --hash=sha256:c6c868a2b8a2ca126930d2699b1a9ea7bd2134fe32107f8b5608d352783adce3 \\", + " --hash=sha256:c91d5a2a0b8fbf1e9deddbc2c59df93eb0de5c2314d9384969866cfaff6096c2 \\", + " --hash=sha256:c9d594f5785a4b0b7ad6a949ce8c799c67ee8105a6ffc8b4d5f4fd39f53bb9cb \\", + " --hash=sha256:ca38887219a8b77e56a8ded792a4ca6b0e78138c0ea0817de44022b0f73da3a7 \\", + " --hash=sha256:caeba590c348e1960ef9ce99589af4ab53b481f68b35ebd7f536abec2b072d54 \\", + " --hash=sha256:cb35195054f5eb044a9022a9d1c1799e0524adaa3f9ba936d2f134f3c7fa1d01 \\", + " --hash=sha256:cde33ba347b399d6b4f4c4ad03679a2570f945222596a56f9ca335e8ceea9340 \\", + " --hash=sha256:ce6afc332face9c5978dccf74c9bbee095d43b9794bc256f5acec1565c3e3fde \\", + " --hash=sha256:cfaf14e2080f5ced2699ebfbd5fd6cede980d331e14b2dc25235480bbd3de61d \\", + " --hash=sha256:d55cb1bb1f4309e7462324d70491d99b8cfe7af62c41a0e5bf42835f164fa2bc \\", + " --hash=sha256:d6ec7e29e62ebf93ab2a593d1137022b6025497d8610e5cb666d52f9ee5bb0ce \\", + " --hash=sha256:d7882799ee96f80e07cc0cc049e609ed3ccacf08fec81e47fdbbb06c0b8ea2c1 \\", + " --hash=sha256:d8d8f0dcd2583c0095e1764d591f35d9b974b6d98afec20b33512cc7778f389a \\", + " --hash=sha256:d96b2621622b040e5fec358cd9f45341845ab8517fd4d06d28088ea4a2fb2d5b \\", + " --hash=sha256:d9ab084d9c09cb95cce2e93bb59e19d55b98347e01649beeadf595d129111475 \\", + " --hash=sha256:da8dcbb501d6b3bc2c47db82fd1f3c78b7e980941db820e98562955e59c4a562 \\", + " --hash=sha256:dcb2f4ce63699ba4606d928ccf1e9f81557ba8b2ff263c52610253324856e199 \\", + " --hash=sha256:e3b0bac7b125515fee40b4df7069b2c3a89b4f722e159ccaaf78d44fe4fec261 \\", + " --hash=sha256:e4e69107963c47c35ca2d5f3c400e4dfe7eab5b107ab02830f712058e34e9846 \\", + " --hash=sha256:e53de052944732050022a81ea14f6dea25fbcfddc1c0c38def00e2ea3da1257a \\", + " --hash=sha256:e64ed603efac109f0ca26bb7e69ddcb5735aac463ca7dd15f7ca1eb7cf212f02 \\", + " --hash=sha256:e6cd01d3cefde448faacee38fcb1372e8e8687dd05a23d767e684b5081bcd0b4 \\", + " --hash=sha256:e7d10c6ac4e4a7cc65cc12ad61daa188c7fd16b32ba1919913b5da054ec6fd35 \\", + " --hash=sha256:e809decf3539660a2080b806d48a9b716b58b011a43f62f4272d256ec9cdf0c6 \\", + " --hash=sha256:e933aa169c3ec81518ce52b4db533eb3c7bfe5e55426a3e7f57742300263c4c0 \\", + " --hash=sha256:ece2f6ae38a8cd3eae07c8ca723af420351385294f989a76235a2b5bd465045a \\", + " --hash=sha256:f07145c751729bc78aa1a231018e4c98316c1e516514c09e926fbcb0d3b14ec8 \\", + " --hash=sha256:f11f0d4110a071aa6d8da35c199fdcc607271cb8c23babbf00aadc2d02b85b00 \\", + " --hash=sha256:f3758c3b1689ab778f3e1ae0f9aa4d22b8e4efc362e2e4cfdbbc5a208fed0bc1 \\", + " --hash=sha256:f48429378adb4a3e2c93ef4b551265350d712cb7cc5071538b7841a66da17014 \\", + " --hash=sha256:f5749d2d16ebd65e60ae1e1a2661c80ac1717e5cb2db50fb47cbeb0073108b5e \\", + " --hash=sha256:f8b2e49c18439db0a77533429d3ed7330671a262b8e82bdb6e9cf03b4ea91adc \\", + " --hash=sha256:fd90d5f29b349833fd692860ecdea1a9e6fd24127582b96234bfae15c1ae18ae \\", + " --hash=sha256:ff36007d31a0ba241f7bb09fd179febe221f52b3bf11798ab1b48e8b20a43220", + " # via tiktoken", + "requests==2.34.2 \\", + " --hash=sha256:2a0d60c172f83ac6ab31e4554906c0f3b3588d37b5cb939b1c061f4907e278e0 \\", + " --hash=sha256:f288924cae4e29463698d6d60bc6a4da69c89185ad1e0bcc4104f584e960b9ed", + " # via", + " # dashscope", + " # tiktoken", + "rich==15.0.0 \\", + " --hash=sha256:33bd4ef74232fb73fe9279a257718407f169c09b78a87ad3d296f548e27de0bb \\", + " --hash=sha256:edd07a4824c6b40189fb7ac9bc4c52536e9780fbbfbddf6f1e2502c31b068c36", + " # via", + " # dashscope", + " # typer", + "shellingham==1.5.4 \\", + " --hash=sha256:7ecfff8f2fd72616f7481040475a65b2bf8af90a56c89140852d1120324e8686 \\", + " --hash=sha256:8dbca0739d487e5bd35ab3ca4b36e11c4078f3a234bfce294b0a0291363404de", + " # via typer", + "starlette==1.10.0 \\", + " --hash=sha256:478c0ab3b4ced6e82719849c118fa406f0278a3499c1a898cd15cd31bdc38ce4 \\", + " --hash=sha256:b8399098d4c1e3522734f7235dc79b1fc967f96cf139c81e0fa30479e0685f9b", + " # via fastapi", + "tenacity==9.2.1 \\", + " --hash=sha256:9e56f17539296baab7beabb08b92f6ee3d7be92d8be72d763360677c2ad6580e \\", + " --hash=sha256:a606b5c808d0cded4a359d5b9932d867ff2a6a6b64d37350260fd01bbdf83839", + " # via -r rl-lock-input.in", + "tiktoken==0.14.0 \\", + " --hash=sha256:087538c080e5ff421abd3a0785ed63c5111d06af98e6cd0d374dbe5969147ca3 \\", + " --hash=sha256:10f31e63e40313f2e518d87f7086cfa44e45f64cc14d8ae14103b41220c30a14 \\", + " --hash=sha256:11d8211b290855d2721334ff17dd9b3a17bfb26872be01f25d73612ef7ece890 \\", + " --hash=sha256:144a3fc369f92b7d548995217c5d6e84038d3572157a0f6f34080d65291d0f78 \\", + " --hash=sha256:149d97453c4c98c04b081d64a85e635921269b532710d6faf81e9e82b790e7d3 \\", + " --hash=sha256:14b47e3674f2624803a8acc8fb367b7e24fc53055f9df3296482fe9a3a34a232 \\", + " --hash=sha256:151d37a150c8f3dfc5f4345597b10e101876bd1bd13494e0185af6b508758d2e \\", + " --hash=sha256:18a1b651c4b032004bf7b4f1713391a54b2a341a52c6e8a2b59acae9d16e13c7 \\", + " --hash=sha256:19d643d701fdaa70e5b9c7f8f96abcaffe77ca5e482a3a1a7dde46feb4284695 \\", + " --hash=sha256:1b6e4adcfd285c44502aed51df98aaaca4f0fea028165dbf8a9e857b9f98d8ea \\", + " --hash=sha256:1f83081065ee5833d35b49e9180f3d8d15622a603dd1c435da0da6cc12b3662f \\", + " --hash=sha256:2157f52e4b4d7ac5ecc7457b3716834706e7ef9a46f5144029bfeb7cf71f4e06 \\", + " --hash=sha256:231dec90efcdccf1b565a1416107736f1e09b1a08fe736ef9d6363e626d03874 \\", + " --hash=sha256:26cc4b4840fa0e9f4b72ed489883e12f57e00d1021ca794720e3c29a12f0edef \\", + " --hash=sha256:26e60f6a956ee171ab728b37b8439905d7ea1db435c30f9822f291e9861c861d \\", + " --hash=sha256:2cc19ac87b41c9493c9778ff5847f0c8bbcf5bd0ec6b87ce06c1c802adc8a771 \\", + " --hash=sha256:2ea70afba6b9eddbf22c165142e5f0a2ad7aa36a452873c48b57bb2aeb8492ae \\", + " --hash=sha256:2ec16eb585332c55d022d86354e209ddf27326b1ea3477585ab248e7776d3b1f \\", + " --hash=sha256:2fc834fbe3f6a0736905c36ab709537e6840dbd63b982dc9e0216ae7d305ba1a \\", + " --hash=sha256:380873f330b741c4435574f37edb20813d04603ace2d53e0a63560e1fec83010 \\", + " --hash=sha256:3b12e54f8bec91433e41aff65d8d1f209a4f678081163747079806e5361f6c91 \\", + " --hash=sha256:3c5349c9f916283bba32bec8af69b763e4faa304dc004d0eaaea66a3cf004c1f \\", + " --hash=sha256:3de75343041a1c57333b1e707ac8a9769738241d7d6a55d39e12cf84548337c6 \\", + " --hash=sha256:3fd7c14b1cb45b486c39fc9b3443bb341f3e2fc7e6f31247f3435a5836651632 \\", + " --hash=sha256:447ada49af4898b5e992f0b5799d2f3af385921102c211947ce3fe960dd919da \\", + " --hash=sha256:4d8d91d68353bd167fdf26467e5ff9e56aaa5f87d6410c0238608629e4dc0d33 \\", + " --hash=sha256:50a7e5646cbac2a8f7c3e8c0934ffda1a4357ee9c44b652434b23c3ed54d0900 \\", + " --hash=sha256:561e7580f84a79859af1ef6f676968e9030fcc3fe195700b15235bca64f009c9 \\", + " --hash=sha256:60c47ca69ddda0dea8256fffd12e1b86f4b59734a20e4a70c61f63cc5f021df4 \\", + " --hash=sha256:6eb94895c45f26bb8f5546e5fd8a069efcf6e3f108ea9d5cbe3bf6f7f3983438 \\", + " --hash=sha256:728303a072163130c5b477b1f20d6211895569c1d5302c24ffc93a3009160871 \\", + " --hash=sha256:78571efc311c30b73f31eb949a921d6dac39a5d9dc42d1cfa8f8db157b3447b1 \\", + " --hash=sha256:7896eea257fe497a2b7134474d909156c6744ce8da35bce88011a960e008aa0d \\", + " --hash=sha256:7aab286a020660a039097912a088236b985d18a3090d73f136c4413d29d37ca0 \\", + " --hash=sha256:7b7acbb7a4b8383707bce22ad3c162006478c27b56368acd3e1fcb1658a80425 \\", + " --hash=sha256:7db45b98e94adf4173a5cd7422b150999a7ee11ff847783a14f6e1b80cc38cb6 \\", + " --hash=sha256:86951a971c53979ec857bd8c4a32dc227ab0fd33f6c12a3bd62d3fbf5f0bfcaa \\", + " --hash=sha256:86f66c85e796f5d05d5c4a60ec1d40cbfebc47a32464053528c797163fa9ab89 \\", + " --hash=sha256:8e947aefe98ef74cce94923f90e48c98fe34eb1ec0a6bfdfadfc5a96359bfc36 \\", + " --hash=sha256:90a762670c7f968184723769a06ed51f5cf5ce5dcd1e30164f25c72d85c2d1f1 \\", + " --hash=sha256:94f77b60a8ab23580db19ae822744c9716c1720020d2179ca5605112d12326f1 \\", + " --hash=sha256:979c1524f753b662b0f3cd261b135afe6659cce33caaa7a5ea00dd1756b3055c \\", + " --hash=sha256:a140e83317fef02faeeb78d9a8efac623887f2feaf0055c55dcdb2b17f0226ad \\", + " --hash=sha256:aa428a559d5fd02ae619aacaace86c7474a1f2702d2c01fc828908dd60f20f7a \\", + " --hash=sha256:b950248272f1b303dc32986396e2dccfa10cf6d1e83ec8f0bba1776660305482 \\", + " --hash=sha256:c2edf09b381fafbc014ae8e018ed25087abb9a3dafa8465a0ea63c6558c47a79 \\", + " --hash=sha256:c3093001ddce822b4587e6e94bf6de36a5f97b3f31de1c9fc8d4fda144c59ff4 \\", + " --hash=sha256:c6cb9896a82b9ee44e15ba0b5c8044072f2e4d48acaa704c8d3feeef5ad9487c \\", + " --hash=sha256:c77d4a3e1deb2707819df92046b89aad1ac81d27e07616b797cbff3f62c037da \\", + " --hash=sha256:ca4db6ff5c5bf600f9b7761a0070ed44dfe5797a76bd432fb978bc480ef40c58 \\", + " --hash=sha256:cbe2cc3bba939bcdaf103e03df9d5039d33887080b315624be28ec69059e5f94 \\", + " --hash=sha256:cd8ca1305c1c902fe42c486165f2e4808d9997625c98ffb05b9e0366d99d3948 \\", + " --hash=sha256:d0781223705199b289faa59601bb9c2441712d4c600dd13c43d8fd6a33d22cd5 \\", + " --hash=sha256:d6cebe67765569df3dafac8474e4eccf5c19d24140492567a5e58a11445732a4 \\", + " --hash=sha256:e067f4cbcc5d036e8aff7fe7a6b530a8f4de2e4616ad9005a24a1879e24e6450 \\", + " --hash=sha256:e2eca764c53490f8930dbce329e0769f11108d87d908282a80c5c130e26e7037 \\", + " --hash=sha256:e3442bbb2f0c588cec876061e37ae67b455b9df9978b003c8fe30e45f2ef5b42 \\", + " --hash=sha256:e4ddf863b59347deaa92302dcd90e5eb003cdc9be06ec2b692c38d1bdd9efd49 \\", + " --hash=sha256:e9c5fe393aab56469f04e432ff851216d3def3436cf5f07e442a240164bf500f \\", + " --hash=sha256:eceeff0c62419bc78d4b6e70a4762a4d25df3ae8f2d5946e3853ce93e7a57098 \\", + " --hash=sha256:f2af4a336ea56d6c14f27741a0e1d8294a35dd0b038bcf990d232ebb54eb994b \\", + " --hash=sha256:f3d6cf93fbe2e7117eb7bedca684216fbe328a41f0843ce34245451d8eb2df1c \\", + " --hash=sha256:f5e7665f6624e052e5e7f6a36919ab69279decdc976d7b16b4fa15e1897d0513 \\", + " --hash=sha256:f702e0aeeb6506e57687e881c59e844ebe8f0a6a097ddafe20e3ab25f387be4e", + " # via -r rl-lock-input.in", + "typer==0.29.1 \\", + " --hash=sha256:00dbc549c13428bec1be55fe1f4d0fb8c6637a310e4f178ef14abe9534ee7b58 \\", + " --hash=sha256:ab6eb3880bf67ce96147734717f9ec333c06f66e361f3ea947d0be43da39f242", + " # via dashscope", + "typing-extensions==4.16.0 \\", + " --hash=sha256:481caa481374e813c1b176ada14e97f1f67a4539ce9cfeb3f350d78d6370c2e8 \\", + " --hash=sha256:dc983d19a509c94dba722ee6abd33940f7c05a89e243c47e907eb4db6f1a43e5", + " # via", + " # aiohttp", + " # aiosignal", + " # anyio", + " # fastapi", + " # opentelemetry-api", + " # opentelemetry-sdk", + " # opentelemetry-semantic-conventions", + " # pydantic", + " # pydantic-core", + " # starlette", + " # typing-inspection", + "typing-inspection==0.4.5 \\", + " --hash=sha256:7f16c411e7930dc79596d42ab44672a3fe5f60eb34b781a1647e7872363120c7 \\", + " --hash=sha256:bc210535442b39e1bf2805e0c7a17dfd6a4ace760c84c7f7d16245d23a6b1c39", + " # via", + " # fastapi", + " # pydantic", + "urllib3==2.8.0 \\", + " --hash=sha256:0cf3cae568d36aa9576b28dfb35f11328f1cb974ca7647d9475ebb86c75ac6e3 \\", + " --hash=sha256:63bf2ead4c879426ebf22ef2a781eeb4aa3b4ae798a0435506f8687fd5bb9b63", + " # via requests", + "uvicorn==0.54.0 \\", + " --hash=sha256:505bdb0f318731d45f1f712071fc781a8981f6847a31c902c9f5e652d4f67faf \\", + " --hash=sha256:a2e33cbfaa0306f8e6b0c13e0cb89d7d7a2da3e62b90c66e18c33d9807b28620", + " # via -r rl-lock-input.in", + "websocket-client==1.9.2 \\", + " --hash=sha256:0fcb57545848be86992e128218fd96dd87a6769ffdb1a968dff79632b85604d0 \\", + " --hash=sha256:e1a673830a9c7bfa47b1cd3d5e4178f4c9651d80a4eab02c9c23a1c3ec6250ce", + " # via dashscope", + "yarl==1.25.1 \\", + " --hash=sha256:0136d640dfa9b0523853e411430a99f8a91eca85774c6420285a33b755bc6de3 \\", + " --hash=sha256:03dd38de09bc213e9a8b29761eec33ee1d5318dac0e49d8af36e4d27830e23a7 \\", + " --hash=sha256:0a191bfdb30a79b98e5d175d75285f9fcb78bf0e46ba5efda042e1c72071a0de \\", + " --hash=sha256:0a66db89ea473abeac4b70523cafd94db3772380e565f9d28af7a179b7af71fa \\", + " --hash=sha256:0ae12ff2b805fa02c4dab838005caef735e39986322698c48588d3beacb65c62 \\", + " --hash=sha256:0f12afda4eea8c8994a76d4df1875c765194f5fbe8a9d197929ea303caee29ec \\", + " --hash=sha256:10b2fd95332f0d716d5eee3c9fb2ce8eada19082de7fee83d32e37992fd75c26 \\", + " --hash=sha256:126a2533570c554719ca40a1288fdee1700b6bc82e7131aa69fa85252d92e651 \\", + " --hash=sha256:12b6bc4906e11f5e1a1cdcb12296e7afbd366c783cc8073403cd2fb74334e453 \\", + " --hash=sha256:142c06c4d6a35ee3ec5da08499805e879cb3ca7c1fbfbecb0140fe72403818d6 \\", + " --hash=sha256:14b79a30a93a3ce2e8832603fd0ab780ada281b0ba5110b519a634f2d7d7d1fc \\", + " --hash=sha256:17c9877a89fb6e2bca6f9087eb24cd7fb434653946ef5075e470d23d49b52287 \\", + " --hash=sha256:192a866877a49993949ef1975864ad8728bea28ee810f6abe1a0729c2b500426 \\", + " --hash=sha256:1ab7618921a93767387a4b83776f751588f5b5ae9bb5bc96620e2e2e00bca868 \\", + " --hash=sha256:1e80dcf1446e1b080b1932b0d103c464a04112f5bc31f0f983ad418172063cde \\", + " --hash=sha256:1f51020b2eb8a003c84925638ec63c21a750a4bddd3a22ec8eac6a742dadf1b9 \\", + " --hash=sha256:1fb2a01ba8cd9c5d2c5dc1ec35e0fc951d04b4f037541d4ac090c993ce58b3d7 \\", + " --hash=sha256:2239a02249d9326655419e0168a28ca9008938eaab31dc29fc875c217927a6c0 \\", + " --hash=sha256:23bf5b403c879a54964e0feac7285688e04bb220074878d737d331522da0a5bf \\", + " --hash=sha256:24ce942011a61953e7d313438038f4d32ff21387b775f58a957f7a07dd55ef95 \\", + " --hash=sha256:25868beca8b6765f8f7d0e11fe6dd7c66dd4b0793b9500286d20cc92352126a5 \\", + " --hash=sha256:287e99ff5aa4dc1c7630bfc683ded6f106d756c99dec432a2d7f197a784f51c6 \\", + " --hash=sha256:29273edf1530e397bd07cb784db1fbe0d2590b77569f2e24679a9c0a2d763b94 \\", + " --hash=sha256:2b49375d22299b0a834c2bca72f39aaecc270d96fb24c30424899676f487b22a \\", + " --hash=sha256:30eec96e8a91bd588ce897c9543f6d5d8d34b28fbcba28a4dedf20ebeae9fe57 \\", + " --hash=sha256:319e070a01db9920fb63761843f96a104c8e2b9427266731810dc1e22595b17c \\", + " --hash=sha256:35dcbea443fafb3eece757ad4e514560ddeb6c34cfae1582c620d7b293d7feee \\", + " --hash=sha256:3f4d48a6112712973e676bd792121fee470e432d749177162d9949d5c9460a1b \\", + " --hash=sha256:3feb99222553a8cbedfa52c2f59dd84c3f50d5b582c728d522caf8d72769a54b \\", + " --hash=sha256:419f392a1da624877975709e3864dfe833af6cc7671b39318086d456e288380c \\", + " --hash=sha256:42a66563d8cc056ee32e6191e05097a7b2b3bc302e0bc3133daf8710eb18bd26 \\", + " --hash=sha256:48796ea00a303961507dc6c8437c4b325a6fc3f95f7c36c71b91ea9a8150963c \\", + " --hash=sha256:4bd6340d20ae2c7ca719b87b426e808e90743b676d05d4c26c4fb5ca71f41184 \\", + " --hash=sha256:4ca89e4e21854ed27ec753297dde84b16c9f8e53b14a4866fb44457d643c19f8 \\", + " --hash=sha256:4d781294bb815ecb5ea57ff6bbf8038e0a31a95fdf3e1788f66e0dc100d64b58 \\", + " --hash=sha256:4f1c91f5a5980a937ff8e238e98e6897e1ad74a4b1e2c0d68c73b5ffbb3f5c0b \\", + " --hash=sha256:564fdc7085d2245ab84f88882fdb1d6ac0723124bff6ded35bfb1c00f812630d \\", + " --hash=sha256:59ba3a6e1aa8cfe5adf4bd270fd965db21955401b7ca6f1696010c55ed4daec2 \\", + " --hash=sha256:5df89f769cc8ff94c3d7e7603386fba309d25ce5240132d26c15baa8d0e96c4c \\", + " --hash=sha256:632da579b2d879f6bad20f2cfa35ded1efe2f4f77f8abb26a6234a5b236acd2f \\", + " --hash=sha256:65b5b2066651b7432d389e9799d979c703bcc6ef44266bb8153ef54e91e4aab3 \\", + " --hash=sha256:664ec6a520b74a1df2810666eb67695fcb77fa663e6ea0a25aaf2e529cb24dfa \\", + " --hash=sha256:681c758b0490f9e96b78e5fa8e8dc6e648e9185bb6eaebe73183c33ea0c445f3 \\", + " --hash=sha256:683e362b8ba453080f7489c66f4ea794e751c35b72e7eab3575ef784c2fbc7fb \\", + " --hash=sha256:68782fdb4027b8d1eee25ec35e9a6db05e863b899eb0310b3a33b6c3fef55707 \\", + " --hash=sha256:6efaf45df6a849cef613a03a94c845647456662f85438c886bb67a9c027c8c2c \\", + " --hash=sha256:71f42c5b9a948c113bbdebfa544598321431d064ff959d32e99b1feb61d68345 \\", + " --hash=sha256:72849d892954be4d09e569b8b831ac39ce58417fedc767d4308a0fe542018a40 \\", + " --hash=sha256:72c34ac7ad4314c19362d5ce27626dcc8429bd30bbf8c179f4234078851f9492 \\", + " --hash=sha256:734f6e5400352ac4254456003d462866c684703570929cff7a7bde015d0cb371 \\", + " --hash=sha256:75baa6cf9b6d1c52f3e111a130e202fd8cf0a5b3a066c3f73d615e885092e4ec \\", + " --hash=sha256:77716e245c90f058466a05e6a465bb8600f767a8f4b18b4d40f3aff958e5f73c \\", + " --hash=sha256:77e5099b99b37f3cf79c246998ca9f7313a78054cd1809ec46bc1afad47e1c4c \\", + " --hash=sha256:783dd1467083f4d3f7722ad6a313f24c173e7571372738fcb7a6e6d1ba48df25 \\", + " --hash=sha256:7a5c3115595995779ee21f2567035793911c3802a43c74f3fbb0314929ec67ac \\", + " --hash=sha256:7c88edaec8c349ad4c5ad4c486a3defcc4b80ceb2f074436ffa0a87caf5e76a6 \\", + " --hash=sha256:7cb414a73e21a7ab58254926073f2930cb22f5b4314ea4260a687e2b3fd4dce3 \\", + " --hash=sha256:7d42e7e3ca399555578b4d617e3a6ecf13371b3743a115995fa010c7bf341459 \\", + " --hash=sha256:7d575b54cb3863ef9bc290ea4b009999d55dc237326131e4853cf33e888fee03 \\", + " --hash=sha256:7e4de3ac4adbad3d0bc7c6f4360a7dbff5de2f15e3b723be3198074e17fd9c40 \\", + " --hash=sha256:7efc9f082dfed77c316edffa9deb52888e1bc6789171887cc1f68e06d65465c8 \\", + " --hash=sha256:80a063f8297fc796296f00f100be520f209b23dc98f93ce8eba6ee7122598209 \\", + " --hash=sha256:80e47012e730da131c9f059c80936783f9659aae22dc31c03c0595590d11ed54 \\", + " --hash=sha256:83d4a37e4b95da4d8bda930d6d35b75b4cdadbacbb4980cae290ea3100b5d51d \\", + " --hash=sha256:83e9f4a25085bd4b7214701a0794ff1f50fc633ffb8bdfebf07abdd81c2db126 \\", + " --hash=sha256:85a18376073f8a39aa07be34f9fc77e2869aa72c55c441efdd2cf79a0407504d \\", + " --hash=sha256:87796fedc3ba97ec14fab55acb48584276e6c1e4c1e89c422bda62c838e754a9 \\", + " --hash=sha256:882569ff613758cac762a457a5d72d6e211b28d4bcfea89d1d71ea942b02eac0 \\", + " --hash=sha256:8ce4d6ccafb33d39bd78444612d14938ead674c25702ded2ee9c54a47735d225 \\", + " --hash=sha256:8e7d98cdbb6d71e726f7d525952867096053d1f290dd4e3c50d7d313a136f414 \\", + " --hash=sha256:8ee202350cf57abf0e9502a41601841019c25d3db7ff52d980aaf31446254059 \\", + " --hash=sha256:8fb0eb4955adf0579001581f2f71a126e8781ba61bcd120f127b0401163c6c2d \\", + " --hash=sha256:90c30ed53546da833c700115c0064c22120d1b1560f474699fd31f22dd668233 \\", + " --hash=sha256:9489e6abf47ba37f332075a91444c7cfedb03e6ce99fbb2f116bfe1ce810da3b \\", + " --hash=sha256:94d7aa6debf92a1dd14cb5280b083a764169a13cfb23a452111160274ed989f4 \\", + " --hash=sha256:98d370568f393215d605304cdb77b3d5539bd192c75b623c7304c42c8d6d8273 \\", + " --hash=sha256:9b1bdaae98bc016825dd3c9d8ee1832f829b3341f9cc6ebd1a1b0a7fef7367cc \\", + " --hash=sha256:9d693bf4bf534e9ba3ae2780cfd577f5135629f7b5ac653490859d0b77864865 \\", + " --hash=sha256:9d6ed3d17bccce4c05343e1ca8da13bc5c02c812a4e7282ddd05e8769322d3fc \\", + " --hash=sha256:9e23c82b63cd7652fc24d33ed6cc17099d607aa3b4fc4ddc75e95062f3d82df4 \\", + " --hash=sha256:a1daf47cd95a7c3a63456336bc5aaa8c86dd3a47d07ed3d0e76132ae4666a5a1 \\", + " --hash=sha256:a1e32763e641a1566507d90a8d3b19bfc3cc04a9d4e5ae3e32189874ed4b58a3 \\", + " --hash=sha256:a2059a2d891bd156bc5184e7ab7a56e78a84dfcfdeac8c501b552533ad1c36ee \\", + " --hash=sha256:a2ed0ba415ccdf08f14bf544cb78346d0f76086707ffee24921a2c84dbf1305a \\", + " --hash=sha256:a3faadac7d812ddac258feb57b9846b60c1b437c4f4b9ad42595c6f6fe4390df \\", + " --hash=sha256:a5877f2255aab518ebe528289037699201d5dc5f045f2396cb30aa02db22f57f \\", + " --hash=sha256:a78b50b4f7918a3de71105d5c0b93bbc57bb8339a4d03a9dfd449f9068e76f3d \\", + " --hash=sha256:a8c2b841478068440d8b733005d13a5ef535b9928cbc05f17182d410f32ba449 \\", + " --hash=sha256:a9ca696eb02e5c02a8afd872ada510eba9b7fe6e68b9572c2e9a9b1941e31e2e \\", + " --hash=sha256:aa4ed3dd308548f9e707d9caaf005d2d7f8c1e7868f858dfeb47fe76e16b391d \\", + " --hash=sha256:ab2054c5531af2a9ba7b69b8ec91e4f884420e83a8c5e579b013084cb57e5e5d \\", + " --hash=sha256:abb1384477f5901d436b5d2e5465954de46ea6098f59163d243660b5c4461d35 \\", + " --hash=sha256:acae6b45d1ace09b6ba3876da43b88366ef368f73b988c7f57e14231753d4420 \\", + " --hash=sha256:acfa7e22aa6c6e7a5996a41d275bfa01efa7ea56ab890590280e9063e2cf5c1b \\", + " --hash=sha256:af4ea5b37403ef4e30f3927eaed540db942bde01d8d3ff083527c0704d1c9c68 \\", + " --hash=sha256:b10dd0557ba422715b5206b3743192135a6022acca8baec51aa127d0a75db8fe \\", + " --hash=sha256:b13b88747769537f3d32e89e3a735da10c0a9e35d7322928c701b5f93d3afffd \\", + " --hash=sha256:b51c159a9794633f5e0db7ecec7b2b6e3734eca1f5d17dc989ff3552a43ff78b \\", + " --hash=sha256:b5402a340723fa7da00b5cff987ddab61276be6d11251ea71ae02bcac54890d8 \\", + " --hash=sha256:b7abffdf37af1cec6a2ad69b827aa84320db5894791bc8ed932dc93fb274b7e9 \\", + " --hash=sha256:b8075fe90bc08e40b8b8a1874fab42ee4c7b56af05c5886e9cc841397f916908 \\", + " --hash=sha256:bc3ac7bf569f6b64dad04dd7808c7872dae8a97df657856eac05e9b7e3614a85 \\", + " --hash=sha256:bd0912757081f89b107d6c00b2ff8a194401b0b87eadcf4481de2b865a8fd44f \\", + " --hash=sha256:bdc8d8b8c22e9e43ac68316b5e6cf083dec537f4ec213cb4aa967b583bc3fa64 \\", + " --hash=sha256:be80550d9bfe83d9b62398a37081a90434e6df2d978ec345c3d2820de6beddab \\", + " --hash=sha256:c6f117789d22dce188e5754e8bc65b7e6ebf8cb73963b9fa761f672a5883769d \\", + " --hash=sha256:ca32926d7d77bcc8838425c4c95e040a3ace1cb7dfdae599013458dcda2607ca \\", + " --hash=sha256:cce0727fd5ac04d372fa9bbfde9febc2bcf209aadfcf0468e45dec72719895d1 \\", + " --hash=sha256:d0f1489233a254bb3643d2f05de7d59019254d81daeca6b9162fe9edef57e0c7 \\", + " --hash=sha256:d1c557dfd5e3db046053a0bdc72261ade790ebe8e2c7a41b36b0ca1f14cb95f3 \\", + " --hash=sha256:d21f0fa80a02d05299207eeaafef345d812ace96d5306e4ef265e1d419a615fa \\", + " --hash=sha256:d45673badd08456d0340e9364eddafe1c53a9d2896424294de4d7dd71ad3ee57 \\", + " --hash=sha256:d5add7b4ca7afeea91d52e4d4e4db3b1fe9885b71f07054560d8c4296b7441a2 \\", + " --hash=sha256:d5f90e44653c4e0f78501ed9bb7d3fce835a8d62b7c6ed0cb16557534087e743 \\", + " --hash=sha256:d7306dee25b8a0e737363f347362b875094b4dc4e367311470656ae420fdbf8e \\", + " --hash=sha256:dbcef5a9119ef653653132cccaf999b30a0af6f33bb0a4ba80bec30056868487 \\", + " --hash=sha256:def538065f9e4d4cf1ae164bd59aba00dfa84f03923e0de4c3788f252d6bcd17 \\", + " --hash=sha256:df23df54b5114a17c2d0ef192433e2e5a9f0c5178c32375e90b7cfc965f349d0 \\", + " --hash=sha256:dfbf531053a0935f2e871bcd4753f90313688772ff8c017f5ea402e315a78c1f \\", + " --hash=sha256:e029648f9c951db30e98a7d7ec90835db88ec4b32820efe2a9bdc2287e032eb6 \\", + " --hash=sha256:e07595c7d6f4db270ceede356a1bd1c07a34f1c26f958d1ed0cd7b48e0d2bba3 \\", + " --hash=sha256:e12c538e00e7c1b286a07061046b90e8124e6a9793efae2c70db6a4aad07faad \\", + " --hash=sha256:e546fe1d4a93ebc2910f0d768baff19faa09843ab3f2036a67ed6e69fae4419d \\", + " --hash=sha256:e5637ca8d0bd7fb72648a6c7934af4baaccb697657f7438c9d264fc2abb8b0b1 \\", + " --hash=sha256:e636b64d24fd9c38053c5e389a1174c66361fa49dcfd220f4dd35b4abde7cb89 \\", + " --hash=sha256:e7011b8fb8c4054bf0c12e5edc6cd83778b0028e99ce59b18586ed036f92cfdc \\", + " --hash=sha256:e80f557716fd765439577131e526b8942ffc2c07bdbc5e39fa62f660ba1e963f \\", + " --hash=sha256:e92b6bcc741b86d67606c40d3cb9c7cc8e6c737f81e31f4a94efc204456c92e3 \\", + " --hash=sha256:eb96ed1ae6c7d072d60840c0434aef07a2df611812810807fbc54263a6053e9a \\", + " --hash=sha256:eda19ea5ee88742f47a2340816e6f2d40b53bed3ab5b69794769f36af9f35bb4 \\", + " --hash=sha256:ef74070ac553c59eb4f04258722066d6c6135b7baa03b2e9f2da65c096e96d98 \\", + " --hash=sha256:efb01a106f971cb3752856bca2318bbdf7f01bd8823779c461586cbe5ffd5258 \\", + " --hash=sha256:f074e8d4aa0a5798920ddb6de3d08b228c614ff3724c3e8bd7577f4bafea867b \\", + " --hash=sha256:f38a70074041d3b7e138e452799f5174198bae5bd5ab2000917badf403908c5f \\", + " --hash=sha256:f41753a76f4f63927d03a0d8ba8f5ce0f2083bec29a8cfaccc55371b1564b96b \\", + " --hash=sha256:f53dcd26694f148f738edc052b5a69234833e739f10f4c3287bdfd8ec0f7b326 \\", + " --hash=sha256:f61964f235a43738bfac50da46fc4254943a7eea3051aeb0b6fc7c992c29fadc \\", + " --hash=sha256:fe01645169a2112aa1d4ebc3e4c5f029c5c8f97adfc32e5d37c993b39a994d75", + " # via aiohttp", +]; + +/** Full lockfile text (directly consumable by pip --require-hashes). */ +export const RL_DEPENDENCY_LOCK = LOCK_LINES.join("\n") + "\n"; diff --git a/packages/core/src/rl-runtime/manager.ts b/packages/core/src/rl-runtime/manager.ts new file mode 100644 index 00000000..2ad31b2b --- /dev/null +++ b/packages/core/src/rl-runtime/manager.ts @@ -0,0 +1,385 @@ +/** + * Managed runtime manager (black-box internal initialization). + * + * Install lifecycle: exclusive lock → multi-source CPython download per manifest (python-build-standalone install_only, + * canonical → mirror fallback, each attempt timed) → per-source SHA256 verification → system tar extract into the version dir → ensurepip → + * pip install --require-hashes of dashscope and transitive deps from the bundled universal lockfile → version/import self-check in a controlled env + * → atomic READY marker + pointer write. First download is cached and reused long-term via READY; later runs use the interpreter absolute path + * (no source activate, no global PATH changes). Dev override: BAILIAN_RL_RUNTIME pointing at a local Python dir with dashscope installed + * reuses it directly, skipping release verification. + * + * The manifest defaults to the bundled reviewed artifact (bundledRuntimeManifest): pinned versions for stability, decoupled from CLI releases. + */ + +import { spawn } from "node:child_process"; +import { + closeSync, + existsSync, + mkdirSync, + openSync, + readFileSync, + unlinkSync, + writeFileSync, +} from "node:fs"; +import { join } from "node:path"; +import { BailianError } from "../errors/base.ts"; +import { ExitCode } from "../errors/codes.ts"; +import { httpTransport } from "../client/transport.ts"; +import { + isSandboxNetworkDenialCode, + networkCauseCode, + SANDBOX_NETWORK_HINT, +} from "../client/network-diagnostics.ts"; +import { runtimeCacheRoot, runtimeRoot as runtimeRootDir } from "../isolation/paths.ts"; +import { RL_DEPENDENCY_LOCK } from "./locks.ts"; +import { + RL_DASHSCOPE_VERSION, + RL_PIP_INDEX_ENV, + RL_PYTHON_VERSION, + assertArtifactIntegrity, + bundledRuntimeManifest, + parseRuntimeManifest, + pythonDownloadCandidates, + selectManifestEntry, + type IRuntimeManifest, + type IRuntimeManifestEntry, +} from "./manifest.ts"; + +/** Dev override env var: points at a local Python dir with dashscope (the reviewed baseline version) installed. */ +export const RUNTIME_OVERRIDE_ENV = "BAILIAN_RL_RUNTIME"; + +/** Per-download timeout (ms): fail fast on stalls and fall back to mirrors instead of hanging forever. */ +const RL_DOWNLOAD_TIMEOUT_MS = 120_000; + +/** Resolved runtime (runs use the interpreter absolute path). */ +export interface IResolvedRuntime { + runtimeRoot: string; + pythonPath: string; + dashscopeVersion: string; + source: "override" | "managed"; +} + +/** Controlled command execution result (tar / python / pip self-checks). */ +export interface IRuntimeCommandResult { + exitCode: number | null; + stdout: string; + stderr: string; +} + +/** Dependency-injection seam for the install lifecycle (defaults to real fetch/spawn; mockable in unit tests). */ +export interface IRuntimeDeps { + download(url: string): Promise; + run(command: string, args: string[], options?: { cwd?: string }): Promise; +} + +export interface IResolveRuntimeOptions { + /** Manifest passed directly (takes precedence over manifestPath and the bundled manifest). */ + manifest?: IRuntimeManifest; + /** Manifest file path (overrides the bundled manifest; for review / integration debugging). */ + manifestPath?: string; + /** Whether first-time runtime preparation is allowed (defaults to false for non-interactive use). */ + allowInstall?: boolean; + env?: Record; + platform?: NodeJS.Platform; + arch?: string; + deps?: IRuntimeDeps; +} + +/** Download failure wrapper: message carries the errno; sandbox-denial codes append network-enable/proxy guidance (mirrors cannot help). */ +export function runtimeDownloadFailure(url: string, error: unknown): BailianError { + const code = networkCauseCode(error); + const sandboxHint = isSandboxNetworkDenialCode(code) ? ` ${SANDBOX_NETWORK_HINT}` : ""; + return new BailianError( + `Failed to download runtime artifact from ${url}${code ? ` (${code})` : ""}.`, + ExitCode.NETWORK, + `Check network connectivity, or set BAILIAN_RL_PYTHON_MIRROR to a reachable mirror, then retry runtime prepare.${sandboxHint}`, + { cause: error }, + ); +} + +const defaultDeps: IRuntimeDeps = { + async download(url) { + const controller = new AbortController(); + const timer = setTimeout(() => controller.abort(), RL_DOWNLOAD_TIMEOUT_MS); + try { + const response = await httpTransport.fetch(url, { signal: controller.signal }); + if (!response.ok) { + throw new BailianError( + `Failed to download runtime artifact (HTTP ${response.status}).`, + ExitCode.NETWORK, + ); + } + return Buffer.from(await response.arrayBuffer()); + } catch (error) { + if (error instanceof BailianError) throw error; + throw runtimeDownloadFailure(url, error); + } finally { + clearTimeout(timer); + } + }, + run(command, args, options) { + return new Promise((resolve, reject) => { + const child = spawn(command, args, { cwd: options?.cwd, shell: false, windowsHide: true }); + let stdout = ""; + let stderr = ""; + child.stdout?.on("data", (chunk: Buffer) => (stdout += chunk.toString("utf8"))); + child.stderr?.on("data", (chunk: Buffer) => (stderr += chunk.toString("utf8"))); + child.on("error", reject); + child.on("close", (exitCode) => resolve({ exitCode, stdout, stderr })); + }); + }, +}; + +/** Absolute path of the extracted CPython interpreter (install_only tarball top level is python/). */ +export function managedPythonPath(root: string, platform: NodeJS.Platform): string { + if (platform === "win32") return join(root, "python", "python.exe"); + const minor = RL_PYTHON_VERSION.split(".").slice(0, 2).join("."); + return join(root, "python", "bin", `python${minor}`); +} + +/** Runtime version directory name: platform-arch-Python version-baseline SDK version (immutable addressing key). */ +function runtimeIdFor(entry: IRuntimeManifestEntry, manifest: IRuntimeManifest): string { + return `${entry.os}-${entry.arch}-${entry.pythonVersion}-${manifest.dashscopeVersion}`; +} + +/** Managed runtime-id for the current baseline (bundled reviewed manifest); undefined when this platform has no entry. */ +export function currentManagedRuntimeId( + platform: NodeJS.Platform = process.platform, + arch: string = process.arch, +): string | undefined { + const manifest = bundledRuntimeManifest(); + const entry = selectManifestEntry(manifest, platform, arch); + if (!entry) return undefined; + return runtimeIdFor(entry, manifest); +} + +/** Interpreter candidates under the override dir (first existing one wins). */ +function overridePythonPath(dir: string, platform: NodeJS.Platform): string | undefined { + const candidates = + platform === "win32" + ? [join(dir, "python.exe"), join(dir, "Scripts", "python.exe")] + : [join(dir, "bin", "python"), join(dir, "python")]; + return candidates.find((candidate) => existsSync(candidate)); +} + +function runtimeUnavailable(detail: string): BailianError { + return new BailianError( + `RUNTIME_UNAVAILABLE: ${detail}`, + ExitCode.GENERAL, + `Prepare the managed runtime first (runtime prepare), or set BAILIAN_RL_RUNTIME to a local dashscope ${RL_DASHSCOPE_VERSION} Python directory for development. No cloud resources were created.`, + ); +} + +function loadManifest(manifestPath?: string): IRuntimeManifest | undefined { + if (!manifestPath || !existsSync(manifestPath)) return undefined; + return parseRuntimeManifest(readFileSync(manifestPath, "utf8")); +} + +/** Resolve the runtime: dev override first, then managed READY, then first-time download + install if allowed. */ +export async function resolveRuntime( + options: IResolveRuntimeOptions = {}, +): Promise { + const env = options.env ?? process.env; + const platform = options.platform ?? process.platform; + const arch = options.arch ?? process.arch; + + const override = env[RUNTIME_OVERRIDE_ENV]; + if (override) { + const pythonPath = overridePythonPath(override, platform); + if (!pythonPath) { + throw new BailianError( + `BAILIAN_RL_RUNTIME is set but no Python interpreter was found under "${override}".`, + ExitCode.GENERAL, + `Point BAILIAN_RL_RUNTIME at a directory containing a dashscope ${RL_DASHSCOPE_VERSION} Python interpreter.`, + ); + } + // Measure the override env's dashscope version for real (never report the baseline constant blindly): FC_PYPI_LIB is + // derived from it, keeping the submit side and the FC install in lockstep; fail closed if missing or not importable. + const deps = options.deps ?? defaultDeps; + let measured = ""; + try { + const probe = await deps.run(pythonPath, [ + "-I", + "-c", + 'import importlib.metadata; print(importlib.metadata.version("dashscope"))', + ]); + if (probe.exitCode === 0) measured = probe.stdout.trim(); + } catch { + // Non-executable interpreter and similar cases all fall through to the fail-closed path below + } + if (!measured) { + throw new BailianError( + `BAILIAN_RL_RUNTIME points at "${override}" but dashscope is not importable there.`, + ExitCode.GENERAL, + `Install dashscope==${RL_DASHSCOPE_VERSION} (the reviewed baseline) into that Python environment, then retry.`, + ); + } + return { + runtimeRoot: override, + pythonPath, + dashscopeVersion: measured, + source: "override", + }; + } + + const manifest = + options.manifest ?? loadManifest(options.manifestPath) ?? bundledRuntimeManifest(); + const entry = selectManifestEntry(manifest, platform, arch); + if (!entry) { + throw runtimeUnavailable(`no validated runtime for ${platform}/${arch}.`); + } + + const runtimeId = runtimeIdFor(entry, manifest); + const root = runtimeRootDir(runtimeId); + const pythonPath = managedPythonPath(root, platform); + if (existsSync(join(root, "READY")) && existsSync(pythonPath)) { + return { + runtimeRoot: root, + pythonPath, + dashscopeVersion: manifest.dashscopeVersion, + source: "managed", + }; + } + if (!options.allowInstall) { + throw runtimeUnavailable("the managed runtime is not prepared yet."); + } + await installRuntime(entry, manifest, root, options.deps ?? defaultDeps, platform, env); + return { + runtimeRoot: root, + pythonPath, + dashscopeVersion: manifest.dashscopeVersion, + source: "managed", + }; +} + +/** Acquire the exclusive runtime-dir lock (atomic O_EXCL creation); returns the release function. */ +function acquireRuntimeLock(root: string): () => void { + mkdirSync(root, { recursive: true }); + const lockPath = join(root, ".lock"); + let fd: number; + try { + fd = openSync(lockPath, "wx"); + } catch { + throw new BailianError( + "Another runtime prepare is in progress for this runtime.", + ExitCode.GENERAL, + "Wait for it to finish, or remove the stale .lock if no prepare is running.", + ); + } + writeFileSync(fd, String(process.pid)); + closeSync(fd); + return () => { + try { + unlinkSync(lockPath); + } catch { + // Cleanup failure does not affect the result + } + }; +} + +/** Download and verify SHA256 per source; network failure or hash mismatch moves to the next source; if all fail, throw the last error. */ +async function downloadVerifiedArtifact( + candidates: string[], + expectedSha256: string, + deps: IRuntimeDeps, +): Promise { + let lastError: unknown; + for (const url of candidates) { + try { + const data = await deps.download(url); + assertArtifactIntegrity(data, expectedSha256); + return data; + } catch (error) { + lastError = error; + } + } + if (lastError instanceof Error) throw lastError; + throw new BailianError( + "Failed to download CPython from all candidate sources.", + ExitCode.NETWORK, + ); +} + +/** Full install lifecycle; an interruption never writes READY, so the next attempt rebuilds in a fresh directory. */ +export async function installRuntime( + entry: IRuntimeManifestEntry, + manifest: IRuntimeManifest, + root: string, + deps: IRuntimeDeps, + platform: NodeJS.Platform, + env: Record = process.env, +): Promise { + const releaseLock = acquireRuntimeLock(root); + try { + // 1. Multi-source CPython download with integrity verification (canonical → mirror fallback; switching sources never changes the SHA). + const cacheDir = runtimeCacheRoot(); + mkdirSync(cacheDir, { recursive: true }); + const candidates = pythonDownloadCandidates(entry.pythonUrl, env); + const tarball = await downloadVerifiedArtifact(candidates, entry.pythonSha256, deps); + const tarPath = join(cacheDir, `${entry.pythonSha256}.tar.gz`); + writeFileSync(tarPath, tarball); + + // 2. System tar extract into the version dir (install_only top level python/, containing the interpreter and stdlib). + mkdirSync(root, { recursive: true }); + const extracted = await deps.run("tar", ["-xzf", tarPath, "-C", root]); + if (extracted.exitCode !== 0) { + throw new BailianError( + `Failed to extract CPython ${entry.pythonVersion}: ${extracted.stderr}`, + ExitCode.GENERAL, + ); + } + const pythonPath = managedPythonPath(root, platform); + if (!existsSync(pythonPath)) { + throw new BailianError( + `CPython interpreter missing after extract: ${pythonPath}`, + ExitCode.GENERAL, + "Retry runtime prepare; the incomplete runtime was not marked READY.", + ); + } + + // 3. Ensure pip is available (install_only usually ships it; ensurepip as fallback, failures surface in the next step). + await deps.run(pythonPath, ["-m", "ensurepip", "--upgrade"]); + + // 4. Install locked wheel deps from the bundled universal lockfile (never install user business requirements). + // --require-hashes forces a hash per package; the dashscope wheel must match the reviewed baseline SHA256. + const lockfilePath = join(root, "requirements.lock"); + writeFileSync(lockfilePath, RL_DEPENDENCY_LOCK, "utf8"); + const pipArgs = ["-m", "pip", "install", "--require-hashes", "--no-warn-script-location"]; + // Restricted regions can point BAILIAN_RL_PIP_INDEX_URL at a stable PyPI mirror; --require-hashes still verifies every package. + const pipIndex = env[RL_PIP_INDEX_ENV]; + if (pipIndex) pipArgs.push("--index-url", pipIndex); + pipArgs.push("-r", lockfilePath); + const install = await deps.run(pythonPath, pipArgs); + if (install.exitCode !== 0) { + throw new BailianError( + `pip failed to install locked dependencies: ${install.stderr}`, + ExitCode.GENERAL, + ); + } + + // 5. Version/import self-check in a controlled environment. + const version = await deps.run(pythonPath, ["-I", "--version"]); + const importCheck = await deps.run(pythonPath, ["-I", "-c", "import dashscope"]); + if (version.exitCode !== 0 || importCheck.exitCode !== 0) { + throw new BailianError( + "Runtime self-check failed (python --version / import dashscope).", + ExitCode.GENERAL, + "Retry runtime prepare; the incomplete runtime was not marked READY.", + ); + } + + // 6. Atomically write the READY marker + runtime pointer (only then visible to runs). + writeFileSync( + join(root, "READY"), + `${JSON.stringify({ dashscopeVersion: manifest.dashscopeVersion, pythonVersion: entry.pythonVersion }, null, 2)}\n`, + "utf8", + ); + writeFileSync( + join(root, "runtime.json"), + `${JSON.stringify({ pythonPath }, null, 2)}\n`, + "utf8", + ); + } finally { + releaseLock(); + } +} diff --git a/packages/core/src/rl-runtime/manifest-data.ts b/packages/core/src/rl-runtime/manifest-data.ts new file mode 100644 index 00000000..cc3d405e --- /dev/null +++ b/packages/core/src/rl-runtime/manifest-data.ts @@ -0,0 +1,10 @@ +/** + * Bundled reviewed runtime manifest (schema v2, real download sources + official SHA256). + * + * Generated from the repo-root runtime-manifest.json; do not edit by hand — change the json and regenerate. + * CPython hashes come from the python-build-standalone 20240415 official SHA256SUMS; + * the dashscope wheel hash comes from the official PyPI JSON (equals the code baseline RL_DASHSCOPE_WHEEL_SHA256). + */ + +export const BUNDLED_RUNTIME_MANIFEST_JSON = + '{\n "schemaVersion": 2,\n "dashscopeVersion": "1.25.23",\n "dashscopeUrl": "https://files.pythonhosted.org/packages/9e/47/556e3a5d9e9e0f2d7c45f8598c7b9a9569ec7e5340e8e2a21288b58e4cfc/dashscope-1.25.23-py3-none-any.whl",\n "dashscopeSha256": "7cb2cc48fd82536202e3100e93730e92c952435bb8cbe16d45de9700e1546bcc",\n "entries": [\n {\n "os": "darwin",\n "arch": "arm64",\n "triple": "aarch64-apple-darwin",\n "pythonVersion": "3.11.9",\n "pythonUrl": "https://github.com/astral-sh/python-build-standalone/releases/download/20240415/cpython-3.11.9+20240415-aarch64-apple-darwin-install_only.tar.gz",\n "pythonSha256": "7af7058f7c268b4d87ed7e08c2c7844ef8460863b3e679db3afdce8bb1eedfae"\n },\n {\n "os": "darwin",\n "arch": "x64",\n "triple": "x86_64-apple-darwin",\n "pythonVersion": "3.11.9",\n "pythonUrl": "https://github.com/astral-sh/python-build-standalone/releases/download/20240415/cpython-3.11.9+20240415-x86_64-apple-darwin-install_only.tar.gz",\n "pythonSha256": "9afd734f63a23783cf0257bef25c9231ffc80e7747486dc54cf72f325213fd15"\n },\n {\n "os": "linux",\n "arch": "x64",\n "triple": "x86_64-unknown-linux-gnu",\n "pythonVersion": "3.11.9",\n "pythonUrl": "https://github.com/astral-sh/python-build-standalone/releases/download/20240415/cpython-3.11.9+20240415-x86_64-unknown-linux-gnu-install_only.tar.gz",\n "pythonSha256": "78b1c16a9fd032997ba92a60f46a64f795cd18ff335659dfdf6096df277b24d5"\n },\n {\n "os": "linux",\n "arch": "arm64",\n "triple": "aarch64-unknown-linux-gnu",\n "pythonVersion": "3.11.9",\n "pythonUrl": "https://github.com/astral-sh/python-build-standalone/releases/download/20240415/cpython-3.11.9+20240415-aarch64-unknown-linux-gnu-install_only.tar.gz",\n "pythonSha256": "b3a7199ac2615d75fb906e5ba556432efcf24baf8651fc70370d9f052d4069ee"\n }\n ]\n}'; diff --git a/packages/core/src/rl-runtime/manifest.ts b/packages/core/src/rl-runtime/manifest.ts new file mode 100644 index 00000000..0347fcfd --- /dev/null +++ b/packages/core/src/rl-runtime/manifest.ts @@ -0,0 +1,189 @@ +/** + * Runtime manifest schema and integrity verification (schema v2, real multi-source). + * + * The manifest describes real download sources for a pinned runtime: one CPython per platform (python-build-standalone + * install_only tar.gz) + a single dashscope wheel shared across platforms (PyPI, py3-none-any). On first init the black box + * downloads and verifies CPython per manifest, then pip --require-hashes installs dashscope and transitive deps from the bundled lockfile. + * The manifest is a reviewed artifact shipped as a TS constant (manifest-data.ts, generated from the repo-root + * runtime-manifest.json); SHA256 values come from official SHA256SUMS / PyPI, never invented. + */ + +import { createHash, timingSafeEqual } from "node:crypto"; +import { BailianError, UsageError } from "../errors/base.ts"; +import { ExitCode } from "../errors/codes.ts"; +import { BUNDLED_RUNTIME_MANIFEST_JSON } from "./manifest-data.ts"; + +/** Reviewed pinned dashscope version (upgrades require re-review + lockfile regeneration). */ +export const RL_DASHSCOPE_VERSION = "1.25.23"; + +/** SHA256 of the dashscope==1.25.23 wheel (official PyPI value, verified). */ +export const RL_DASHSCOPE_WHEEL_SHA256 = + "7cb2cc48fd82536202e3100e93730e92c952435bb8cbe16d45de9700e1546bcc"; + +/** Reviewed pinned CPython version. */ +export const RL_PYTHON_VERSION = "3.11.9"; + +/** Custom CPython mirror env var: replaces the GitHub release download prefix (1:1 path mapping, SHA unchanged). */ +export const RL_PYTHON_MIRROR_ENV = "BAILIAN_RL_PYTHON_MIRROR"; + +/** Custom pip index env var: restricted regions can point at a stable PyPI mirror (Tsinghua tuna / Aliyun); a mirror lagging PyPI fails closed on missing pinned versions. */ +export const RL_PIP_INDEX_ENV = "BAILIAN_RL_PIP_INDEX_URL"; + +/** python-build-standalone GitHub release download prefix (canonical reviewed source). */ +const GITHUB_RELEASE_BASE = + "https://github.com/astral-sh/python-build-standalone/releases/download/"; + +/** Built-in fallback mirror: Aliyun CNPM npmmirror, 1:1 with GitHub release paths, verified byte-identical. */ +export const DEFAULT_PYTHON_MIRRORS = [ + "https://registry.npmmirror.com/-/binary/python-build-standalone/", +]; + +/** Per-platform CPython download entry. */ +export interface IRuntimeManifestEntry { + os: "darwin" | "linux"; + arch: string; + /** python-build-standalone target triple (matches os/arch). */ + triple: string; + pythonVersion: string; + pythonUrl: string; + pythonSha256: string; +} + +/** Runtime manifest (schema v2). The dashscope wheel is shared across platforms and lives at the top level. */ +export interface IRuntimeManifest { + schemaVersion: 2; + dashscopeVersion: string; + dashscopeUrl: string; + dashscopeSha256: string; + entries: IRuntimeManifestEntry[]; +} + +const SHA256_HEX = /^[0-9a-f]{64}$/; + +function requireString(record: Record, key: string, where: string): string { + const value = record[key]; + if (typeof value !== "string" || value.length === 0) { + throw new UsageError(`Invalid runtime manifest: ${where}.${key} must be a non-empty string.`); + } + return value; +} + +function requireSha256(record: Record, key: string, where: string): string { + const value = requireString(record, key, where); + if (!SHA256_HEX.test(value)) { + throw new UsageError(`Invalid runtime manifest: ${where}.${key} must be a 64-char hex SHA256.`); + } + return value; +} + +/** Parse and validate manifest text; any malformed shape/hash is rejected (fail-closed). */ +export function parseRuntimeManifest(text: string): IRuntimeManifest { + let raw: unknown; + try { + raw = JSON.parse(text); + } catch (error) { + throw new UsageError("Invalid runtime manifest: not valid JSON.", String(error)); + } + if (typeof raw !== "object" || raw === null || Array.isArray(raw)) { + throw new UsageError("Invalid runtime manifest: root must be an object."); + } + const root = raw as Record; + if (root.schemaVersion !== 2) { + throw new UsageError("Invalid runtime manifest: schemaVersion must be 2."); + } + const dashscopeVersion = requireString(root, "dashscopeVersion", "root"); + const dashscopeUrl = requireString(root, "dashscopeUrl", "root"); + const dashscopeSha256 = requireSha256(root, "dashscopeSha256", "root"); + if (!Array.isArray(root.entries) || root.entries.length === 0) { + throw new UsageError("Invalid runtime manifest: entries must be a non-empty array."); + } + const entries: IRuntimeManifestEntry[] = root.entries.map((item, index) => { + const where = `entries[${index}]`; + if (typeof item !== "object" || item === null || Array.isArray(item)) { + throw new UsageError(`Invalid runtime manifest: ${where} must be an object.`); + } + const record = item as Record; + const os = requireString(record, "os", where); + if (os !== "darwin" && os !== "linux") { + throw new UsageError(`Invalid runtime manifest: ${where}.os must be darwin or linux.`); + } + return { + os, + arch: requireString(record, "arch", where), + triple: requireString(record, "triple", where), + pythonVersion: requireString(record, "pythonVersion", where), + pythonUrl: requireString(record, "pythonUrl", where), + pythonSha256: requireSha256(record, "pythonSha256", where), + }; + }); + return { schemaVersion: 2, dashscopeVersion, dashscopeUrl, dashscopeSha256, entries }; +} + +/** Bundled reviewed manifest (parsed from manifest-data.ts). */ +export function bundledRuntimeManifest(): IRuntimeManifest { + return parseRuntimeManifest(BUNDLED_RUNTIME_MANIFEST_JSON); +} + +/** Select the platform entry by os/arch; undefined when nothing matches (caller fails closed). */ +export function selectManifestEntry( + manifest: IRuntimeManifest, + platform: NodeJS.Platform, + arch: string, +): IRuntimeManifestEntry | undefined { + const os = platform === "darwin" ? "darwin" : platform === "linux" ? "linux" : undefined; + if (!os) return undefined; + return manifest.entries.find((entry) => entry.os === os && entry.arch === arch); +} + +/** Compute the byte SHA256 (hex). */ +export function sha256Hex(data: Buffer | string): string { + return createHash("sha256").update(data).digest("hex"); +} + +/** Rewrite a GitHub release download URL to a mirror prefix (prefix only; the / suffix is unchanged). */ +function rewriteToMirror(pythonUrl: string, mirrorBase: string): string | undefined { + if (!pythonUrl.startsWith(GITHUB_RELEASE_BASE)) return undefined; + const suffix = pythonUrl.slice(GITHUB_RELEASE_BASE.length); + const base = mirrorBase.endsWith("/") ? mirrorBase : `${mirrorBase}/`; + return base + suffix; +} + +/** + * Build CPython download candidates (ordered, deduplicated): custom mirror (if set) → canonical → built-in fallback mirror. + * Switching sources changes only the origin, never the SHA256; the caller verifies integrity per source and moves on after any failure. Custom manifest URLs + * that are not GitHub canonical are never mirror-rewritten; they download as-is. + */ +export function pythonDownloadCandidates( + pythonUrl: string, + env: Record = process.env, +): string[] { + const candidates: string[] = []; + const customMirror = env[RL_PYTHON_MIRROR_ENV]; + if (customMirror) { + const rewritten = rewriteToMirror(pythonUrl, customMirror); + if (rewritten) candidates.push(rewritten); + } + candidates.push(pythonUrl); + for (const mirror of DEFAULT_PYTHON_MIRRORS) { + const rewritten = rewriteToMirror(pythonUrl, mirror); + if (rewritten) candidates.push(rewritten); + } + return [...new Set(candidates)]; +} + +/** Verify downloaded artifact integrity; reject immediately on mismatch (timing-safe comparison). */ +export function assertArtifactIntegrity(data: Buffer, expectedSha256: string): void { + const actual = sha256Hex(data); + const expectedBuffer = Buffer.from(expectedSha256, "utf8"); + const actualBuffer = Buffer.from(actual, "utf8"); + if ( + expectedBuffer.length !== actualBuffer.length || + !timingSafeEqual(expectedBuffer, actualBuffer) + ) { + throw new BailianError( + "Runtime artifact integrity check failed (SHA256 mismatch).", + ExitCode.GENERAL, + "The downloaded artifact does not match the reviewed manifest. Refusing to install. No cloud resources were created.", + ); + } +} diff --git a/packages/core/src/rl-runtime/sandbox.ts b/packages/core/src/rl-runtime/sandbox.ts new file mode 100644 index 00000000..12a9c9a6 --- /dev/null +++ b/packages/core/src/rl-runtime/sandbox.ts @@ -0,0 +1,136 @@ +/** + * RL/OPD sandbox black-box entry (manifest-driven · first-time download + cache · thinnest possible shell). + * + * The command layer passes only "SDK args to execute + credential + optional prepare"; inside the black box the reviewed manifest + * drives first-time download/caching of the runtime (resolveRuntime), task-dir creation, assembly of the python -I -m dashscope.cli + * command, execution through the two-layer isolation confinement (executeIsolatedRun), and result normalization or error pass-through. + * The shell no longer orchestrates runtime resolution and isolated execution separately — initialization is the black box's business. + */ + +import { homedir } from "node:os"; +import { join } from "node:path"; +import { writeFileSync } from "node:fs"; +import { BailianError } from "../errors/base.ts"; +import { ExitCode } from "../errors/codes.ts"; +import { executeIsolatedRun } from "../isolation/app-layer.ts"; +import { createIsolationAdapter } from "../isolation/os-isolation/detect.ts"; +import { createTaskDir, type ITaskDirLayout } from "../isolation/paths.ts"; +import type { IIsolationAdapter, IIsolationResult } from "../isolation/types.ts"; +import { resolveRuntime, type IResolveRuntimeOptions } from "./manager.ts"; + +const DEFAULT_TIMEOUT_MS = 60_000; +const DEFAULT_MAX_OUTPUT_BYTES = 16 * 1024 * 1024; + +/** API credential injected into the sandbox (structurally compatible with client.exportApiCredential()). */ +export interface ISandboxCredential { + token: string; + baseUrl?: string; +} + +export interface ISandboxRunInput { + /** dashscope SDK args (without the interpreter and -I -m dashscope prefix, injected by the black box). */ + sdkArgs: string[] | ((layout: ITaskDirLayout) => string[]); + credential: ISandboxCredential; + /** Staging input after the task dir is ready and before spawn; returning a YAML string writes --config. */ + prepare?: (layout: ITaskDirLayout) => string | void; + timeoutMs?: number; + maxOutputBytes?: number; + signal?: AbortSignal; + /** Allow first-time runtime download/preparation (interactive run). */ + allowInstall?: boolean; + /** Real credential paths the OS must deny reads for; defaults to denying the real ~/.dashscope. */ + credentialDenyPaths?: string[]; + /** Runtime resolution overrides (manifest/deps/platform) for tests and management commands. */ + runtimeOptions?: IResolveRuntimeOptions; + adapter?: IIsolationAdapter; +} + +/** Normalize the in-sandbox SDK result: timeout/non-zero exit passes through as an error; success returns parsed JSON. */ +export function normalizeSandboxResult(result: IIsolationResult): unknown { + if (result.timedOut) { + throw new BailianError( + "The RL task timed out; its remote result is unknown. / RL 任务超时,远端结果未知。", + ExitCode.TIMEOUT, + "Check the job status with finetune rl get; the cloud job was not canceled.", + ); + } + let parsed: unknown; + const stdout = result.stdout.trim(); + if (stdout) { + try { + parsed = JSON.parse(stdout); + } catch { + parsed = undefined; + } + } + if (result.exitCode !== 0) { + // Server errors pass through verbatim; never re-classify. + const fromJson = + parsed && typeof parsed === "object" + ? ((parsed as Record).message ?? (parsed as Record).error) + : undefined; + const message = + (typeof fromJson === "string" && fromJson) || + result.stderr.trim() || + stdout || + `dashscope exited with code ${result.exitCode}. / dashscope 以退出码 ${result.exitCode} 结束。`; + throw new BailianError(message, ExitCode.GENERAL); + } + return parsed ?? { raw: stdout }; +} + +/** The black box's sole execution entry: manifest in → internal init + confinement execution → normalized result out. */ +export async function executeInSandbox(input: ISandboxRunInput): Promise { + const runtime = await resolveRuntime({ + allowInstall: input.allowInstall, + ...input.runtimeOptions, + }); + const layout = createTaskDir(); + + let hasConfig = false; + if (input.prepare) { + const yaml = input.prepare(layout); + if (typeof yaml === "string") { + writeFileSync(layout.configPath, yaml, "utf8"); + hasConfig = true; + } + } + + const resolvedArgs = typeof input.sdkArgs === "function" ? input.sdkArgs(layout) : input.sdkArgs; + const command = [ + runtime.pythonPath, + "-I", + "-m", + // The CLI entry is dashscope.cli (has __main__.py, same origin as the console_script); + // the package root dashscope has no __main__.py, so -m dashscope reports "cannot be directly executed". + "dashscope.cli", + // 1.25.23 has no top-level --output option; JSON output is the leaf-level --output-format/-o json, + // carried by the command layer in sdkArgs (except commands like cancel that lack the option). + ...resolvedArgs, + ...(hasConfig ? ["--config", layout.configPath] : []), + ]; + + const result = await executeIsolatedRun( + { + layout, + runtimeRoot: runtime.runtimeRoot, + command, + apiKey: input.credential.token, + baseUrl: input.credential.baseUrl, + credentialDenyPaths: input.credentialDenyPaths ?? [join(homedir(), ".dashscope")], + timeoutMs: input.timeoutMs ?? DEFAULT_TIMEOUT_MS, + maxOutputBytes: input.maxOutputBytes ?? DEFAULT_MAX_OUTPUT_BYTES, + // The dashscope version installed inside FC stays locked to the submit-side runtime (start.sh module paths are determined + // by the submit-side SDK version; FC_PYPI_LIB only controls what FC installs; a mismatch crashes at startup). + // Zero user involvement: no environment variable needs manual registration. + sdkEnv: { FC_PYPI_LIB: `dashscope==${runtime.dashscopeVersion}` }, + // The SDK writes start.sh relative to the process cwd, then packages via zipdir (the original demo flow had cwd==zipdir). + // cwd must be the writable deploy-copy: taskDir is outside the write allowlist (EPERM), and landing outside the package + // would leave the uploaded zip without the startup script. + cwd: layout.deployCopyDir, + signal: input.signal, + }, + input.adapter ?? createIsolationAdapter(), + ); + return normalizeSandboxResult(result); +} diff --git a/packages/core/tests/finetune-capability-catalog.test.ts b/packages/core/tests/finetune-capability-catalog.test.ts new file mode 100644 index 00000000..e5e1aeb1 --- /dev/null +++ b/packages/core/tests/finetune-capability-catalog.test.ts @@ -0,0 +1,127 @@ +import { afterEach, expect, test, vi } from "vite-plus/test"; +import { httpTransport } from "../src/client/transport.ts"; +import { + FINETUNE_CATALOG_SUPPORTS, + fetchModelCapability, + fetchModelList, + fetchModelListAll, + findModelByName, + listSupportedTrainingTypes, + modelSupportsTrainingType, + type ConsoleCall, + type ModelCapability, + type Settings, +} from "../src/index.ts"; + +afterEach(() => { + vi.restoreAllMocks(); +}); + +/** A recording ConsoleCall that returns a fixed catalog envelope (no HTTP). */ +function recordingCall(response: { total: number; list: unknown[] }): { + call: ConsoleCall; + inputs: Record[]; +} { + const inputs: Record[] = []; + const call: ConsoleCall = async (_api, data) => { + inputs.push(data.input as Record); + return { data: response }; + }; + return { call, inputs }; +} + +test("FINETUNE_CATALOG_SUPPORTS scopes the catalog to trainable models", () => { + expect(FINETUNE_CATALOG_SUPPORTS).toEqual({ fineTune: true }); +}); + +test("fetchModelList omits supports by default (inference catalog, backward compatible)", async () => { + const { call, inputs } = recordingCall({ total: 0, list: [] }); + await fetchModelList(call); + expect(inputs[0]).not.toHaveProperty("supports"); + expect(inputs[0]?.group).toBe(true); +}); + +test("fetchModelList forwards an explicit supports scope into the gateway input", async () => { + const { call, inputs } = recordingCall({ total: 0, list: [] }); + await fetchModelList(call, { supports: { fineTune: true } }); + expect(inputs[0]?.supports).toEqual({ fineTune: true }); +}); + +test("findModelByName forwards supports and still requires an exact model match", async () => { + const { call, inputs } = recordingCall({ + total: 2, + list: [{ model: "qwen3-8b-v2" }, { model: "qwen3-8b" }], + }); + const match = await findModelByName(call, "qwen3-8b", { fineTune: true }); + expect(match?.model).toBe("qwen3-8b"); + expect(inputs[0]?.name).toBe("qwen3-8b"); + expect(inputs[0]?.supports).toEqual({ fineTune: true }); +}); + +test("findModelByName without supports keeps the default inference scope", async () => { + const { call, inputs } = recordingCall({ total: 1, list: [{ model: "qwen-plus" }] }); + await findModelByName(call, "qwen-plus"); + expect(inputs[0]).not.toHaveProperty("supports"); +}); + +test("fetchModelListAll carries the supports scope across every page", async () => { + const inputs: Record[] = []; + const call: ConsoleCall = async (_api, data) => { + const input = data.input as Record; + inputs.push(input); + const list = input.pageNo === 1 ? [{ model: "a" }, { model: "b" }] : [{ model: "c" }]; + return { data: { total: 3, list } }; + }; + const all = await fetchModelListAll(call, { supports: { fineTune: true }, pageSize: 2 }); + expect(all.map((model) => model.model)).toEqual(["a", "b", "c"]); + expect(inputs).toHaveLength(2); + for (const input of inputs) expect(input.supports).toEqual({ fineTune: true }); +}); + +test("fetchModelCapability queries the trainable catalog and resolves training types", async () => { + let capturedInput: Record | undefined; + vi.spyOn(httpTransport, "fetch").mockImplementation(async (_input, init) => { + const params = new URLSearchParams(init?.body as string).get("params"); + capturedInput = (JSON.parse(params ?? "{}") as { Data: { input: Record } }) + .Data.input; + return new Response( + JSON.stringify({ + data: { + total: 1, + list: [ + { + model: "qwen3-8b", + supports: { sft: true, fineTune: true, inference: false }, + trainingTypes: { sft: ["full", "lora"] }, + }, + ], + }, + }), + { status: 200, headers: { "Content-Type": "application/json" } }, + ); + }); + + const capability = await fetchModelCapability({ timeout: 30 } as Settings, "qwen3-8b"); + expect(capturedInput?.supports).toEqual({ fineTune: true }); + expect(capability?.model).toBe("qwen3-8b"); + expect(listSupportedTrainingTypes(capability)).toEqual(["sft", "sft-lora"]); +}); + +test("sft stays full-parameter only; lora-only models resolve to sft-lora (semantics preserved)", () => { + const loraOnly: ModelCapability = { + model: "qwen-image-2.0", + supports: { sft: true, fineTune: true }, + trainingTypes: { sft: ["lora"] }, + }; + expect(modelSupportsTrainingType(loraOnly, "sft")).toBe(false); + expect(modelSupportsTrainingType(loraOnly, "sft-lora")).toBe(true); + expect(listSupportedTrainingTypes(loraOnly)).toEqual(["sft-lora"]); + + const full: ModelCapability = { + model: "qwen3-8b", + supports: { sft: true, fineTune: true }, + trainingTypes: { sft: ["full", "lora"] }, + }; + expect(modelSupportsTrainingType(full, "sft")).toBe(true); + expect(listSupportedTrainingTypes(full)).toEqual(["sft", "sft-lora"]); +}); diff --git a/packages/core/tests/finetune-opd-api.test.ts b/packages/core/tests/finetune-opd-api.test.ts new file mode 100644 index 00000000..84ef2fac --- /dev/null +++ b/packages/core/tests/finetune-opd-api.test.ts @@ -0,0 +1,142 @@ +import { describe, expect, test, vi } from "vite-plus/test"; +import { + cancelFineTune, + createFineTune, + deleteFineTune, + exportCheckpoint, + getFineTune, + getFineTuneLogs, + getProfile, + isTrainingTypeCli, + listCheckpoints, + listFineTunes, + type Client, + type CreateFineTuneRequest, +} from "../src/index.ts"; + +function mockClient(response: unknown = {}) { + const requestJson = vi.fn().mockResolvedValue(response); + return { client: { requestJson } as unknown as Client, requestJson }; +} + +const OPD_BODY: CreateFineTuneRequest = { + model: "qwen3.5-9b", + training_type: "pg_opd", + teacher_model: "qwen3.8-flash", + training_datasets: [{ type: "training", data_source_type: "file_id", file_id: "file-train" }], + validation_datasets: [{ type: "validation", data_source_type: "file_id", file_id: "file-val" }], + hyper_parameters: { n_epochs: 1, learning_rate: "1e-6" }, + resource_config: { charge_type: "mtu_postpaid", mtu_spec_code: "MTU4", mtu_capacity: 16 }, +}; + +describe("fine-tune OPD API shapes", () => { + test("createFineTune forwards the OPD body verbatim (descriptors, teacher, resource_config)", async () => { + const { client, requestJson } = mockClient(); + await createFineTune(client, OPD_BODY); + expect(requestJson).toHaveBeenCalledWith({ + path: "/api/v1/fine-tunes", + method: "POST", + body: OPD_BODY, + headers: undefined, + signal: undefined, + }); + }); + + test("createFineTune sends the workspace header only when provided", async () => { + const withWorkspace = mockClient(); + await createFineTune(withWorkspace.client, OPD_BODY, undefined, "ws-123"); + expect(withWorkspace.requestJson.mock.calls[0]?.[0].headers).toEqual({ + "X-DashScope-WorkSpace": "ws-123", + }); + + const withoutWorkspace = mockClient(); + await createFineTune(withoutWorkspace.client, OPD_BODY); + expect(withoutWorkspace.requestJson.mock.calls[0]?.[0].headers).toBeUndefined(); + }); + + test("job read/action wrappers send the workspace header only when provided", async () => { + const calls: Array<{ + invoke: (client: Client, workspaceId?: string) => Promise; + path: string; + method: string; + }> = [ + { + invoke: (client, workspaceId) => getFineTune(client, "ft-xxx", undefined, workspaceId), + path: "/api/v1/fine-tunes/ft-xxx", + method: "GET", + }, + { + invoke: (client, workspaceId) => cancelFineTune(client, "ft-xxx", undefined, workspaceId), + path: "/api/v1/fine-tunes/ft-xxx/cancel", + method: "POST", + }, + { + invoke: (client, workspaceId) => deleteFineTune(client, "ft-xxx", undefined, workspaceId), + path: "/api/v1/fine-tunes/ft-xxx", + method: "DELETE", + }, + { + invoke: (client, workspaceId) => listCheckpoints(client, "ft-xxx", undefined, workspaceId), + path: "/api/v1/fine-tunes/ft-xxx/checkpoints", + method: "GET", + }, + { + invoke: (client, workspaceId) => + exportCheckpoint(client, "ft-xxx", "ckpt-1", "my-model", undefined, workspaceId), + path: "/api/v1/fine-tunes/ft-xxx/export/ckpt-1?model_name=my-model", + method: "GET", + }, + ]; + for (const { invoke, path, method } of calls) { + const withWorkspace = mockClient(); + await invoke(withWorkspace.client, "ws-123"); + expect(withWorkspace.requestJson.mock.calls[0]?.[0]).toMatchObject({ + path, + method, + headers: { "X-DashScope-WorkSpace": "ws-123" }, + }); + + const withoutWorkspace = mockClient(); + await invoke(withoutWorkspace.client); + expect(withoutWorkspace.requestJson.mock.calls[0]?.[0].headers).toBeUndefined(); + } + }); + + test("listFineTunes / getFineTuneLogs forward pagination and workspace", async () => { + const list = mockClient(); + await listFineTunes(list.client, { pageNo: 2, pageSize: 20, workspaceId: "ws-123" }); + expect(list.requestJson.mock.calls[0]?.[0]).toMatchObject({ + path: "/api/v1/fine-tunes?page_no=2&page_size=20", + method: "GET", + headers: { "X-DashScope-WorkSpace": "ws-123" }, + }); + + const logs = mockClient(); + await getFineTuneLogs(logs.client, "ft-xxx", { pageNo: 1, pageSize: 100 }); + expect(logs.requestJson.mock.calls[0]?.[0]).toMatchObject({ + path: "/api/v1/fine-tunes/ft-xxx/logs?page_no=1&page_size=100", + method: "GET", + headers: undefined, + }); + }); +}); + +describe("pg-opd profile", () => { + test("resolves with server type pg_opd and chatml validation", () => { + const profile = getProfile("pg-opd"); + expect(profile.serverTrainingType).toBe("pg_opd"); + expect(profile.acceptedExtensions).toEqual([".jsonl"]); + }); + + test("fills no hyper-parameter defaults and skips sft-only gates", () => { + const profile = getProfile("pg-opd"); + expect(profile.resolveHyperParameters("text", { nEpochs: 4, batchSize: 64 })).toEqual({}); + expect(profile.shouldSkipGate("batch_size", "text")).toBe(true); + expect(profile.shouldSkipCapabilityCheck("text")).toBe(true); + }); + + test("stays unreachable from the text-create training-type whitelist", () => { + expect(isTrainingTypeCli("pg-opd")).toBe(false); + expect(isTrainingTypeCli("pg_opd")).toBe(false); + }); +}); diff --git a/packages/core/tests/isolation-app-layer.test.ts b/packages/core/tests/isolation-app-layer.test.ts new file mode 100644 index 00000000..fbd97681 --- /dev/null +++ b/packages/core/tests/isolation-app-layer.test.ts @@ -0,0 +1,87 @@ +import { describe, expect, test } from "vite-plus/test"; +import { existsSync } from "node:fs"; +import { executeIsolatedRun, type IIsolatedRunInput } from "../src/isolation/app-layer.ts"; +import { createTaskDir, type ITaskDirLayout } from "../src/isolation/paths.ts"; +import type { IIsolationAdapter } from "../src/isolation/types.ts"; +import { withIsolatedHome } from "./helpers/isolation.ts"; + +// 生命周期断言用 fake adapter(不施加 OS 强制)+ 真实 node 子进程: +// 覆盖 app-layer 的 finally 销毁路径,避免依赖平台沙箱可用性。 +const fakeAdapter: IIsolationAdapter = { + detect: async () => ({ + credentialDenyRead: { available: true, mechanism: "none" }, + hardening: { networkEnforce: false, processTree: false, memoryLimit: false }, + }), + prepare: async () => {}, + wrapCommand: (_spec, command) => command, + dispose: async () => {}, +}; + +function baseInput(layout: ITaskDirLayout, command: string[]): IIsolatedRunInput { + return { + layout, + runtimeRoot: process.execPath, + command, + apiKey: "sk-lifecycle-test", + credentialDenyPaths: [], + timeoutMs: 10_000, + maxOutputBytes: 1_048_576, + }; +} + +describe("executeIsolatedRun task-dir lifecycle", () => { + test("disposes the task dir after a successful run", async () => { + await withIsolatedHome(async () => { + const layout = createTaskDir(); + const result = await executeIsolatedRun( + baseInput(layout, [process.execPath, "-e", "process.stdout.write('ok')"]), + fakeAdapter, + ); + expect(result.exitCode).toBe(0); + expect(result.stdout).toBe("ok"); + expect(existsSync(layout.taskDir)).toBe(false); + }); + }); + + test("disposes the task dir after a failed run (no failure retention)", async () => { + await withIsolatedHome(async () => { + const layout = createTaskDir(); + const result = await executeIsolatedRun( + baseInput(layout, [process.execPath, "-e", "process.exit(3)"]), + fakeAdapter, + ); + expect(result.exitCode).toBe(3); + expect(existsSync(layout.taskDir)).toBe(false); + }); + }); + + test("disposes the task dir after a timeout kill", async () => { + await withIsolatedHome(async () => { + const layout = createTaskDir(); + const input = baseInput(layout, [process.execPath, "-e", "setTimeout(() => {}, 5000)"]); + input.timeoutMs = 300; + const result = await executeIsolatedRun(input, fakeAdapter); + expect(result.timedOut).toBe(true); + expect(existsSync(layout.taskDir)).toBe(false); + }); + }); + + test("fail-closed gate rejects before execution when credential deny is unavailable", async () => { + await withIsolatedHome(async () => { + const layout = createTaskDir(); + const unavailableAdapter: IIsolationAdapter = { + ...fakeAdapter, + detect: async () => ({ + credentialDenyRead: { available: false, mechanism: "none", reason: "not supported" }, + hardening: { networkEnforce: false, processTree: false, memoryLimit: false }, + }), + }; + await expect( + executeIsolatedRun( + baseInput(layout, [process.execPath, "-e", "process.stdout.write('ok')"]), + unavailableAdapter, + ), + ).rejects.toThrow(/not supported/); + }); + }); +}); diff --git a/packages/core/tests/isolation-cleanup.test.ts b/packages/core/tests/isolation-cleanup.test.ts new file mode 100644 index 00000000..836d52a8 --- /dev/null +++ b/packages/core/tests/isolation-cleanup.test.ts @@ -0,0 +1,130 @@ +import { describe, expect, test } from "vite-plus/test"; +import { existsSync, mkdirSync, utimesSync, writeFileSync } from "node:fs"; +import { join } from "node:path"; +import { cleanupSandboxArtifacts, DEFAULT_RUNS_TTL_MS } from "../src/isolation/cleanup.ts"; +import { managedRuntimesRoot, runsRoot } from "../src/isolation/paths.ts"; +import { withIsolatedHome } from "./helpers/isolation.ts"; + +const HOUR_MS = 3_600_000; +const CURRENT_ID = "darwin-arm64-3.11.9-1.25.23"; +const OLD_ID = "darwin-arm64-3.11.9-2.0.4"; + +/** 建目录并把 mtime 拨到 ageHours 小时前(先放内容再拨时间,避免被子项更新)。 */ +function seedAgedDir(path: string, ageHours: number): void { + mkdirSync(path, { recursive: true }); + writeFileSync(join(path, "marker.txt"), "x", "utf8"); + const when = new Date(Date.now() - ageHours * HOUR_MS); + utimesSync(path, when, when); +} + +describe("cleanupSandboxArtifacts", () => { + test("dry-run plans removals without deleting anything", async () => { + await withIsolatedHome(async () => { + seedAgedDir(join(runsRoot(), "old-run"), 25); + seedAgedDir(join(runsRoot(), "young-run"), 1); + seedAgedDir(join(managedRuntimesRoot(), OLD_ID), 100); + seedAgedDir(join(managedRuntimesRoot(), CURRENT_ID), 100); + + const result = cleanupSandboxArtifacts({ + dryRun: true, + pruneRuntimes: true, + currentRuntimeId: CURRENT_ID, + }); + + expect(result.dryRun).toBe(true); + expect(result.removedCount).toBe(2); + expect(result.entries).toHaveLength(4); + expect(result.entries.filter((entry) => entry.action === "remove")).toHaveLength(2); + // 计划式预览:零删除 + expect(existsSync(join(runsRoot(), "old-run"))).toBe(true); + expect(existsSync(join(managedRuntimesRoot(), OLD_ID))).toBe(true); + }); + }); + + test("removes expired runs and superseded runtimes, keeps young and current", async () => { + await withIsolatedHome(async () => { + seedAgedDir(join(runsRoot(), "old-run"), 25); + seedAgedDir(join(runsRoot(), "young-run"), 1); + seedAgedDir(join(managedRuntimesRoot(), OLD_ID), 100); + seedAgedDir(join(managedRuntimesRoot(), CURRENT_ID), 100); + + const result = cleanupSandboxArtifacts({ + pruneRuntimes: true, + currentRuntimeId: CURRENT_ID, + }); + + expect(result.dryRun).toBe(false); + expect(result.removedCount).toBe(2); + expect(existsSync(join(runsRoot(), "old-run"))).toBe(false); + expect(existsSync(join(managedRuntimesRoot(), OLD_ID))).toBe(false); + expect(existsSync(join(runsRoot(), "young-run"))).toBe(true); + expect(existsSync(join(managedRuntimesRoot(), CURRENT_ID))).toBe(true); + const kept = result.entries.filter((entry) => entry.action === "keep"); + expect(kept.map((entry) => entry.reason)).toEqual( + expect.arrayContaining(["within TTL", "current baseline runtime"]), + ); + }); + }); + + test("prepare mode (pruneRuntimes false) never touches runtimes", async () => { + await withIsolatedHome(async () => { + seedAgedDir(join(runsRoot(), "old-run"), 25); + seedAgedDir(join(managedRuntimesRoot(), OLD_ID), 100); + + const result = cleanupSandboxArtifacts({ pruneRuntimes: false }); + + expect(result.removedCount).toBe(1); + expect(result.entries.every((entry) => entry.kind === "run")).toBe(true); + expect(existsSync(join(managedRuntimesRoot(), OLD_ID))).toBe(true); + }); + }); + + test("skips runtime reclamation without currentRuntimeId (fail-safe)", async () => { + await withIsolatedHome(async () => { + seedAgedDir(join(managedRuntimesRoot(), OLD_ID), 100); + + const result = cleanupSandboxArtifacts({ pruneRuntimes: true }); + + expect(result.entries.every((entry) => entry.kind === "run")).toBe(true); + expect(existsSync(join(managedRuntimesRoot(), OLD_ID))).toBe(true); + }); + }); + + test("honors a custom TTL", async () => { + await withIsolatedHome(async () => { + seedAgedDir(join(runsRoot(), "three-hours"), 3); + seedAgedDir(join(runsRoot(), "one-hour"), 1); + + const result = cleanupSandboxArtifacts({ runsTtlMs: 2 * HOUR_MS }); + + expect(result.removedCount).toBe(1); + expect(existsSync(join(runsRoot(), "three-hours"))).toBe(false); + expect(existsSync(join(runsRoot(), "one-hour"))).toBe(true); + }); + }); + + test("default TTL is 24 hours", () => { + expect(DEFAULT_RUNS_TTL_MS).toBe(24 * HOUR_MS); + }); + + test("ignores stray files and tolerates missing roots", async () => { + await withIsolatedHome(async () => { + // 根目录尚不存在 + const empty = cleanupSandboxArtifacts({ pruneRuntimes: true, currentRuntimeId: CURRENT_ID }); + expect(empty.entries).toHaveLength(0); + expect(empty.removedCount).toBe(0); + + // 只有散落文件,无子目录 + mkdirSync(runsRoot(), { recursive: true }); + writeFileSync(join(runsRoot(), "stray.txt"), "x", "utf8"); + mkdirSync(managedRuntimesRoot(), { recursive: true }); + writeFileSync(join(managedRuntimesRoot(), "stray.txt"), "x", "utf8"); + const filesOnly = cleanupSandboxArtifacts({ + pruneRuntimes: true, + currentRuntimeId: CURRENT_ID, + }); + expect(filesOnly.entries).toHaveLength(0); + expect(existsSync(join(runsRoot(), "stray.txt"))).toBe(true); + }); + }); +}); diff --git a/packages/core/tests/network-diagnostics.test.ts b/packages/core/tests/network-diagnostics.test.ts new file mode 100644 index 00000000..db956318 --- /dev/null +++ b/packages/core/tests/network-diagnostics.test.ts @@ -0,0 +1,95 @@ +import { createServer, type Server } from "node:net"; +import { afterEach, describe, expect, test } from "vite-plus/test"; +import { + isSandboxNetworkDenialCode, + networkCauseCode, + probeTcpHost, + runtimeDownloadFailure, + BailianError, + ExitCode, +} from "../src/index.ts"; + +describe("networkCauseCode", () => { + test("取直接 errno", () => { + expect(networkCauseCode(Object.assign(new Error("x"), { code: "EPERM" }))).toBe("EPERM"); + }); + + test("沿 cause 链取 undici 包装下的 errno", () => { + const cause = Object.assign(new Error("connect EPERM 1.2.3.4:443"), { code: "EPERM" }); + const wrapped = new TypeError("fetch failed", { cause }); + expect(networkCauseCode(wrapped)).toBe("EPERM"); + }); + + test("无 code 或非错误对象返回 undefined", () => { + expect(networkCauseCode(new Error("plain"))).toBeUndefined(); + expect(networkCauseCode(undefined)).toBeUndefined(); + expect(networkCauseCode("string error")).toBeUndefined(); + }); +}); + +describe("isSandboxNetworkDenialCode", () => { + test("沙箱拒绝特征码为 true", () => { + for (const code of ["EPERM", "EACCES", "ENETUNREACH", "EHOSTUNREACH"]) { + expect(isSandboxNetworkDenialCode(code)).toBe(true); + } + }); + + test("普通网络错误与 undefined 为 false(不误报沙箱)", () => { + for (const code of ["ENOTFOUND", "ECONNREFUSED", "ECONNRESET", "ETIMEDOUT", undefined]) { + expect(isSandboxNetworkDenialCode(code)).toBe(false); + } + }); +}); + +describe("runtimeDownloadFailure", () => { + const url = "https://example.invalid/python.tar.gz"; + + test("沙箱拒绝:message 带 errno,hint 追加放行网络/代理指引", () => { + const cause = Object.assign(new Error("connect EPERM"), { code: "EPERM" }); + const error = runtimeDownloadFailure(url, new TypeError("fetch failed", { cause })); + expect(error).toBeInstanceOf(BailianError); + expect(error.exitCode).toBe(ExitCode.NETWORK); + expect(error.message).toContain("(EPERM)"); + expect(error.hint).toContain("BAILIAN_RL_PYTHON_MIRROR"); + expect(error.hint).toContain("agent sandbox"); + expect(error.hint).toContain("HTTPS_PROXY"); + }); + + test("普通网络失败:保留镜像指引,不追加沙箱指引", () => { + const cause = Object.assign(new Error("getaddrinfo ENOTFOUND"), { code: "ENOTFOUND" }); + const error = runtimeDownloadFailure(url, new TypeError("fetch failed", { cause })); + expect(error.message).toContain("(ENOTFOUND)"); + expect(error.hint).toContain("BAILIAN_RL_PYTHON_MIRROR"); + expect(error.hint).not.toContain("agent sandbox"); + }); + + test("无 errno 时 message 不携带空括号", () => { + const error = runtimeDownloadFailure(url, new Error("boom")); + expect(error.message).toBe(`Failed to download runtime artifact from ${url}.`); + }); +}); + +describe("probeTcpHost(回环,不真实出站)", () => { + let server: Server | undefined; + + afterEach(async () => { + if (server) { + await new Promise((resolve) => server!.close(() => resolve())); + server = undefined; + } + }); + + test("可达端口返回 undefined,关闭后的端口返回 ECONNREFUSED", async () => { + server = createServer(); + await new Promise((resolve) => server!.listen(0, "127.0.0.1", resolve)); + const address = server!.address(); + const port = typeof address === "object" && address !== null ? address.port : 0; + expect(port).toBeGreaterThan(0); + + expect(await probeTcpHost("127.0.0.1", port, 2_000)).toBeUndefined(); + + await new Promise((resolve) => server!.close(() => resolve())); + server = undefined; + expect(await probeTcpHost("127.0.0.1", port, 2_000)).toBe("ECONNREFUSED"); + }); +}); diff --git a/packages/core/tests/rl-auth.test.ts b/packages/core/tests/rl-auth.test.ts new file mode 100644 index 00000000..cbca386f --- /dev/null +++ b/packages/core/tests/rl-auth.test.ts @@ -0,0 +1,271 @@ +import { describe, expect, test, vi } from "vite-plus/test"; +import { RL_AUTH_API, extractEnabledFlag, runRlAuthorization } from "../src/index.ts"; + +const READY = { data: { enabled: true } }; +const MISSING = { data: { enabled: false } }; +const MANUAL_DOC = "https://docs.example.com/rl-training-overview#env-prep"; + +const MUTATION_APIS: string[] = [RL_AUTH_API.enableReinforcement, RL_AUTH_API.enableOpd]; + +function consoleMock( + overrides: Record = {}, + failures: Record = {}, +) { + const calls: { api: string; data: Record }[] = []; + const caller = vi.fn(async (api: string, data: Record) => { + calls.push({ api, data }); + if (failures[api]) throw failures[api]; + if (api in overrides) return overrides[api]; + return READY; + }); + return { caller, calls }; +} + +function apis(calls: { api: string }[]): string[] { + return calls.map((call) => call.api); +} + +function reqDTO(data: Record | undefined): Record { + return (data?.reqDTO ?? {}) as Record; +} + +describe("rl authorization state machine", () => { + test("read-only probe performs no mutations", async () => { + const { caller, calls } = consoleMock(); + const report = await runRlAuthorization({ + target: "rl", + console: caller, + manualAuthDocUrl: MANUAL_DOC, + }); + expect(report.ok).toBe(true); + expect(apis(calls).filter((api) => MUTATION_APIS.includes(api))).toHaveLength(0); + }); + + test("a failed query is UNKNOWN, never READY or MISSING", async () => { + const { caller } = consoleMock( + {}, + { [RL_AUTH_API.queryReinforcementEnabled]: new Error("gateway down") }, + ); + const report = await runRlAuthorization({ + target: "rl", + console: caller, + manualAuthDocUrl: MANUAL_DOC, + }); + const enabled = report.checks.find((check) => check.name === "business-enabled"); + expect(enabled?.status).toBe("UNKNOWN"); + expect(report.ok).toBe(false); + }); + + test("authorize enables RL only, never OPD", async () => { + const { caller, calls } = consoleMock({ [RL_AUTH_API.queryReinforcementEnabled]: MISSING }); + await runRlAuthorization({ + target: "rl", + console: caller, + authorize: true, + manualAuthDocUrl: MANUAL_DOC, + }); + expect(apis(calls)).toContain(RL_AUTH_API.enableReinforcement); + expect(apis(calls)).not.toContain(RL_AUTH_API.enableOpd); + }); + + test("authorize enables OPD only, never RL", async () => { + const { caller, calls } = consoleMock({ [RL_AUTH_API.queryOpdEnabled]: MISSING }); + await runRlAuthorization({ + target: "opd", + console: caller, + authorize: true, + manualAuthDocUrl: MANUAL_DOC, + }); + expect(apis(calls)).toContain(RL_AUTH_API.enableOpd); + expect(apis(calls)).not.toContain(RL_AUTH_API.enableReinforcement); + }); + + test("missing whitelist requires user action and blocks enablement", async () => { + const { caller, calls } = consoleMock({ + [RL_AUTH_API.checkUserWhitelist]: MISSING, + [RL_AUTH_API.queryReinforcementEnabled]: MISSING, + }); + const report = await runRlAuthorization({ + target: "rl", + console: caller, + authorize: true, + manualAuthDocUrl: MANUAL_DOC, + }); + const whitelist = report.checks.find((check) => check.name === "whitelist"); + expect(whitelist?.status).toBe("REQUIRES_USER_ACTION"); + expect(apis(calls)).not.toContain(RL_AUTH_API.enableReinforcement); + expect(report.ok).toBe(false); + }); + + test("missing fine-tuning SLR requires manual authorization and blocks enablement", async () => { + const { caller, calls } = consoleMock({ + [RL_AUTH_API.checkFineTuningSlrAuth]: MISSING, + [RL_AUTH_API.queryReinforcementEnabled]: MISSING, + }); + const report = await runRlAuthorization({ + target: "rl", + console: caller, + authorize: true, + manualAuthDocUrl: MANUAL_DOC, + }); + const slr = report.checks.find((check) => check.name === "finetune-slr"); + expect(slr?.status).toBe("REQUIRES_USER_ACTION"); + expect(slr?.detail).toContain(MANUAL_DOC); + expect( + apis(calls).some((api) => api.includes("createSLR") || api.includes("createTelemetrySlr")), + ).toBe(false); + expect(apis(calls)).not.toContain(RL_AUTH_API.enableReinforcement); + expect(report.ok).toBe(false); + }); + + test("AppTrace without a service interface requires user action (advisory)", async () => { + const { caller } = consoleMock({ [RL_AUTH_API.getTelemetryServiceStatus]: MISSING }); + const report = await runRlAuthorization({ + target: "rl", + console: caller, + manualAuthDocUrl: MANUAL_DOC, + }); + const appTrace = report.checks.find((check) => check.name === "apptrace-service"); + expect(appTrace?.status).toBe("REQUIRES_USER_ACTION"); + expect(report.ok).toBe(true); + }); + + test("workspace id is forwarded to the telemetry reqDTO", async () => { + const { caller, calls } = consoleMock(); + await runRlAuthorization({ + target: "rl", + console: caller, + workspaceId: "ws-123", + manualAuthDocUrl: MANUAL_DOC, + }); + const scoped = calls.find((call) => call.api === RL_AUTH_API.getTelemetrySlrStatus); + expect(reqDTO(scoped?.data).workspaceId).toBe("ws-123"); + }); + + test("request bodies match the console gateway contract", async () => { + const { caller, calls } = consoleMock(); + await runRlAuthorization({ + target: "rl", + console: caller, + workspaceId: "ws-1", + manualAuthDocUrl: MANUAL_DOC, + }); + const bodyOf = (api: string) => calls.find((call) => call.api === api)?.data; + expect(bodyOf(RL_AUTH_API.checkUserWhitelist)).toEqual({ reqDTO: { type: "agentic_rl" } }); + expect(bodyOf(RL_AUTH_API.checkFineTuningSlrAuth)).toEqual({ input: { role: "fine-tuning" } }); + expect(bodyOf(RL_AUTH_API.getTelemetrySlrStatus)).toEqual({ + reqDTO: { workspaceId: "ws-1", slrType: "Xtrace" }, + }); + expect(bodyOf(RL_AUTH_API.getTelemetryServiceStatus)).toEqual({ + reqDTO: { workspaceId: "ws-1", serviceType: "AppTrace" }, + }); + expect(bodyOf(RL_AUTH_API.queryReinforcementEnabled)).toEqual({ reqDTO: {} }); + }); + + test("missing telemetry SLR reports manual guidance without blocking (advisory)", async () => { + const { caller, calls } = consoleMock({ [RL_AUTH_API.getTelemetrySlrStatus]: MISSING }); + const report = await runRlAuthorization({ + target: "rl", + console: caller, + authorize: true, + manualAuthDocUrl: MANUAL_DOC, + }); + const telemetry = report.checks.find((check) => check.name === "telemetry-slr"); + expect(telemetry?.status).toBe("REQUIRES_USER_ACTION"); + expect(telemetry?.required).toBe(false); + expect(telemetry?.detail).toContain(MANUAL_DOC); + expect(apis(calls).some((api) => api.includes("createTelemetrySlr"))).toBe(false); + expect(report.ok).toBe(true); + }); + + test("SLR guidance honors the localize seam (zh-CN)", async () => { + const { caller } = consoleMock({ [RL_AUTH_API.checkFineTuningSlrAuth]: MISSING }); + const report = await runRlAuthorization({ + target: "rl", + console: caller, + manualAuthDocUrl: MANUAL_DOC, + localize: (text) => (typeof text === "string" ? text : text["zh-CN"]), + }); + const slr = report.checks.find((check) => check.name === "finetune-slr"); + expect(slr?.detail).toContain("服务关联角色"); + expect(slr?.detail).toContain(MANUAL_DOC); + }); + + test("telemetry result flag and AppTrace openStatus are parsed", async () => { + const { caller } = consoleMock({ + [RL_AUTH_API.getTelemetrySlrStatus]: { data: { result: true } }, + [RL_AUTH_API.getTelemetryServiceStatus]: { + data: { openStatus: true, instanceStatus: "Running" }, + }, + }); + const report = await runRlAuthorization({ + target: "rl", + console: caller, + manualAuthDocUrl: MANUAL_DOC, + }); + expect(report.checks.find((check) => check.name === "telemetry-slr")?.status).toBe("READY"); + expect(report.checks.find((check) => check.name === "apptrace-service")?.status).toBe("READY"); + }); +}); + +describe("rl authorization SLS step", () => { + test("SLS is a static manual advisory, never probed or opened", async () => { + const { caller, calls } = consoleMock(); + const report = await runRlAuthorization({ + target: "rl", + console: caller, + authorize: true, + manualAuthDocUrl: MANUAL_DOC, + }); + const sls = report.checks.find((check) => check.name === "sls-service"); + expect(sls?.status).toBe("REQUIRES_USER_ACTION"); + expect(sls?.required).toBe(false); + expect(sls?.detail).toContain("SLS"); + // No SLS gateway call and no SLS mutation is ever attempted. + expect(apis(calls).some((api) => api.toLowerCase().includes("sls"))).toBe(false); + expect(report.actions.some((action) => action.toLowerCase().includes("sls"))).toBe(false); + expect(report.ok).toBe(true); + }); + + test("SLS guidance defaults to en-US without a localize seam", async () => { + const { caller } = consoleMock(); + const report = await runRlAuthorization({ + target: "rl", + console: caller, + manualAuthDocUrl: MANUAL_DOC, + }); + const sls = report.checks.find((check) => check.name === "sls-service"); + expect(sls?.detail).toContain("manually"); + }); + + test("SLS guidance honors the localize seam (zh-CN)", async () => { + const { caller } = consoleMock(); + const report = await runRlAuthorization({ + target: "rl", + console: caller, + manualAuthDocUrl: MANUAL_DOC, + localize: (text) => (typeof text === "string" ? text : text["zh-CN"]), + }); + const sls = report.checks.find((check) => check.name === "sls-service"); + expect(sls?.detail).toContain("日志服务"); + expect(sls?.detail).toContain("控制台"); + }); +}); + +describe("extractEnabledFlag", () => { + test("reads common boolean flags under data or root", () => { + expect(extractEnabledFlag({ data: { enabled: true } })).toBe(true); + expect(extractEnabledFlag({ data: { authorized: false } })).toBe(false); + expect(extractEnabledFlag({ whitelisted: true })).toBe(true); + expect(extractEnabledFlag(true)).toBe(true); + expect(extractEnabledFlag({ result: true })).toBe(true); + expect(extractEnabledFlag({ openStatus: false })).toBe(false); + expect(extractEnabledFlag({ data: { enabled: false, status: "NotExist" } })).toBe(false); + }); + + test("unrecognized shapes degrade to undefined", () => { + expect(extractEnabledFlag({ data: { foo: 1 } })).toBeUndefined(); + expect(extractEnabledFlag(null)).toBeUndefined(); + expect(extractEnabledFlag("ready")).toBeUndefined(); + }); +}); diff --git a/packages/core/tests/rl-config.test.ts b/packages/core/tests/rl-config.test.ts new file mode 100644 index 00000000..998d6294 --- /dev/null +++ b/packages/core/tests/rl-config.test.ts @@ -0,0 +1,274 @@ +import { describe, expect, test } from "vite-plus/test"; +import { parse } from "yaml"; +import { + buildTaskYaml, + parseAssignment, + parseDottedAssignment, + parseJsonValue, + parseTypedValue, + resolveTrainingSpec, + type RlJobSpec, + type RlRunParams, + type RlTaskPaths, +} from "../src/index.ts"; + +const TASK_PATHS: RlTaskPaths = { + deployCopyDir: "/task/deploy-copy", + dataDir: "/task/data", +}; + +/** Effective SDK config (bailian stripped, paths rewritten), order-insensitive. */ +function effectiveConfig(params: RlRunParams, yamlText?: string): unknown { + const resolved = resolveTrainingSpec(params, yamlText); + return parse(buildTaskYaml(resolved.spec, TASK_PATHS)); +} + +describe("RL param parsers", () => { + test("parseTypedValue resolves number / boolean / JSON, falls back to string", () => { + expect(parseTypedValue("64")).toBe(64); + expect(parseTypedValue("0.000002")).toBe(0.000002); + expect(parseTypedValue("true")).toBe(true); + expect(parseTypedValue("false")).toBe(false); + expect(parseTypedValue("epoch")).toBe("epoch"); + expect(parseTypedValue("functions.rollout.CalcX")).toBe("functions.rollout.CalcX"); + expect(parseTypedValue('{"a":1}')).toEqual({ a: 1 }); + }); + + test("parseJsonValue parses JSON, falls back to string", () => { + expect(parseJsonValue("calc-rl")).toBe("calc-rl"); + expect(parseJsonValue("64")).toBe(64); + expect(parseJsonValue('{"type":"reinforcement"}')).toEqual({ type: "reinforcement" }); + }); + + test("parseAssignment rejects malformed entries", () => { + expect(parseAssignment("name=classpath", "--reward", "--reward ")).toEqual({ + key: "name", + value: "classpath", + }); + expect(() => parseAssignment("noequals", "--hp", "--hp ")).toThrow(/Invalid --hp/); + expect(() => parseAssignment("=value", "--hp", "--hp ")).toThrow(/Invalid --hp/); + expect(() => parseAssignment("key=", "--hp", "--hp ")).toThrow(/Invalid --hp/); + }); + + test("parseDottedAssignment splits name.field=value", () => { + expect( + parseDottedAssignment( + "rollout-1.cpu=2", + "--function-runtime", + "--function-runtime ", + ), + ).toEqual({ name: "rollout-1", field: "cpu", value: "2" }); + expect(() => + parseDottedAssignment( + "rollout-1=2", + "--function-runtime", + "--function-runtime ", + ), + ).toThrow(/Invalid --function-runtime/); + }); +}); + +describe("resolveTrainingSpec merge rules", () => { + test("pure params and equivalent YAML produce the same effective config", () => { + const params: RlRunParams = { + name: "calc-rl", + model: "qwen3.5-9b", + trainFiles: ["./data/train.jsonl"], + codeDir: ".", + requirements: "requirements.txt", + rollout: "functions.rollout.CalcX", + rewards: ["reward-1=functions.reward.Demo"], + hp: ["algorithm=gspo", "batch_size=64"], + chargeType: "mtu_postpaid", + mtuSpec: "MTU4", + mtuCount: 24, + }; + const yamlText = ` +name: calc-rl +model: + name: qwen3.5-9b +functions: + - type: rollout + name: rollout-1 + fcmodel: + zipdir: . + classpath: functions.rollout.CalcX + requirements_path: requirements.txt + - type: reward + name: reward-1 + fcmodel: + zipdir: . + classpath: functions.reward.Demo + requirements_path: requirements.txt +datasets: + - type: training + data_source_type: file_id + file_name: ./data/train.jsonl +training: + type: reinforcement + hyper_parameters: + algorithm: gspo + batch_size: 64 + resources: + charge_type: mtu_postpaid + mtu_spec_code: MTU4 + mtu_capacity: 24 +`; + expect(effectiveConfig(params)).toEqual(effectiveConfig({ model: "qwen3.5-9b" }, yamlText)); + }); + + test("--hp deep merges into YAML hyper_parameters without whole-block replace", () => { + const yamlText = ` +model: + name: qwen3.5-9b +training: + hyper_parameters: + algorithm: gspo + batch_size: 64 +`; + const resolved = resolveTrainingSpec({ hp: ["n_epochs=3", "batch_size=128"] }, yamlText); + expect(resolved.spec.training?.hyper_parameters).toEqual({ + algorithm: "gspo", + batch_size: 128, + n_epochs: 3, + }); + }); + + test("--function-runtime deep merges into the named function runtime", () => { + const resolved = resolveTrainingSpec({ + model: "m", + rollout: "pkg.Rollout", + functionRuntime: ["rollout-1.cpu=2", "rollout-1.memory_size=4096"], + }); + const rollout = resolved.spec.functions?.find((fn) => fn.type === "rollout"); + expect(rollout?.runtime).toEqual({ cpu: 2, memory_size: 4096 }); + }); + + test("training and validation dataset lists are replaced independently", () => { + const yamlText = ` +model: + name: m +datasets: + - type: training + data_source_type: file_id + file_name: ./old-train.jsonl + - type: validation + data_source_type: file_id + file_name: ./old-val.jsonl +`; + const resolved = resolveTrainingSpec({ trainFiles: ["./new-train.jsonl"] }, yamlText); + expect(resolved.spec.datasets).toEqual([ + { type: "validation", data_source_type: "file_id", file_name: "./old-val.jsonl" }, + { type: "training", data_source_type: "file_id", file_name: "./new-train.jsonl" }, + ]); + }); + + test("functions merge by name and --clear-functions empties the list first", () => { + const yamlText = ` +model: + name: m +functions: + - type: reward + name: reward-1 + fcmodel: + classpath: old.Reward +`; + const merged = resolveTrainingSpec({ rewards: ["reward-1=new.Reward"] }, yamlText); + expect(merged.spec.functions).toHaveLength(1); + expect(merged.spec.functions?.[0].fcmodel?.classpath).toBe("new.Reward"); + + const cleared = resolveTrainingSpec({ clearFunctions: true, rollout: "pkg.Rollout" }, yamlText); + expect(cleared.spec.functions).toHaveLength(1); + expect(cleared.spec.functions?.[0].type).toBe("rollout"); + }); + + test("reward modifiers target the named function", () => { + const resolved = resolveTrainingSpec({ + model: "m", + rewards: ["reward-1=pkg.Reward"], + rewardWeights: ["reward-1=0.8"], + rewardMetrics: ["reward-1.test1=0.5", "reward-1.test2=0.5"], + functionTimeouts: ["reward-1=120"], + functionEnv: ["reward-1.API_BASE=https://example.com"], + }); + const reward = resolved.spec.functions?.find((fn) => fn.name === "reward-1"); + expect(reward?.weight).toBe(0.8); + expect(reward?.timeout).toBe(120); + expect(reward?.reward_metric_weight).toEqual({ test1: 0.5, test2: 0.5 }); + expect(reward?.runtime?.env).toEqual({ API_BASE: "https://example.com" }); + }); + + test("modifiers on an undefined function name fail with USAGE", () => { + expect(() => resolveTrainingSpec({ model: "m", rewardWeights: ["ghost=1"] })).toThrow( + /Unknown function name "ghost"/, + ); + }); + + test("--set overrides top-level keys last (shallow)", () => { + const resolved = resolveTrainingSpec({ + model: "m", + name: "from-params", + set: ["name=from-set", 'training={"type":"reinforcement","hyper_parameters":{"n_epochs":9}}'], + }); + expect(resolved.spec.name).toBe("from-set"); + expect(resolved.spec.training?.hyper_parameters).toEqual({ n_epochs: 9 }); + }); +}); + +describe("resolveTrainingSpec type constraints", () => { + test("OPD forces pg_opd and requires teacher_model", () => { + const resolved = resolveTrainingSpec({ model: "m", teacherModel: "teacher", opd: true }); + expect(resolved.isOpd).toBe(true); + expect(resolved.spec.training?.type).toBe("pg_opd"); + expect(resolved.spec.teacher_model).toBe("teacher"); + expect(() => resolveTrainingSpec({ model: "m", opd: true })).toThrow(/teacher model/); + }); + + test("plain RL defaults to reinforcement and forbids teacher_model", () => { + const resolved = resolveTrainingSpec({ model: "m" }); + expect(resolved.spec.training?.type).toBe("reinforcement"); + expect(() => resolveTrainingSpec({ model: "m", teacherModel: "teacher" })).toThrow( + /only valid for OPD/, + ); + }); + + test("base model is required", () => { + expect(() => resolveTrainingSpec({})).toThrow(/base model is required/); + }); +}); + +describe("buildTaskYaml path rewriting", () => { + test("strips bailian, rewrites zipdir and file_name, keeps classpath/requirements", () => { + const resolved = resolveTrainingSpec({ + model: "m", + codeDir: ".", + requirements: "requirements.txt", + rollout: "functions.rollout.CalcX", + trainFiles: ["./data/train.jsonl"], + include: ["functions/**"], + }); + expect(resolved.spec.bailian?.package?.include).toEqual(["functions/**"]); + + const document = parse(buildTaskYaml(resolved.spec, TASK_PATHS)) as RlJobSpec; + expect(document.bailian).toBeUndefined(); + + const functions = document.functions ?? []; + expect(functions[0].fcmodel?.zipdir).toBe("/task/deploy-copy"); + expect(functions[0].fcmodel?.classpath).toBe("functions.rollout.CalcX"); + expect(functions[0].fcmodel?.requirements_path).toBe("requirements.txt"); + + const datasets = document.datasets ?? []; + expect(datasets[0].file_name).toBe("/task/data/train.jsonl"); + }); + + test("file_id datasets are left untouched", () => { + const resolved = resolveTrainingSpec({ model: "m", trainFileIds: ["file-abc"] }); + const document = parse(buildTaskYaml(resolved.spec, TASK_PATHS)) as RlJobSpec; + const datasets = document.datasets ?? []; + expect(datasets[0]).toEqual({ + type: "training", + data_source_type: "file_id", + file_id: "file-abc", + }); + }); +}); diff --git a/packages/core/tests/rl-isolation-env.test.ts b/packages/core/tests/rl-isolation-env.test.ts new file mode 100644 index 00000000..40298f96 --- /dev/null +++ b/packages/core/tests/rl-isolation-env.test.ts @@ -0,0 +1,123 @@ +import { describe, expect, test } from "vite-plus/test"; +import { readFileSync } from "node:fs"; +import { join } from "node:path"; +import { buildSandboxEnv, prepareTaskHome } from "../src/index.ts"; +import { withIsolatedHome } from "./helpers/isolation.ts"; + +const POSIX_INPUT = { + homeDir: "/task/home", + tmpDir: "/task/tmp", + cacheDir: "/task/cache", + runtimeRoot: "/runtime/rl/abc", + apiKey: "sk-test-key", + proxyPort: 8080, + platform: "linux" as NodeJS.Platform, + hostEnv: {} as Record, +}; + +describe("buildSandboxEnv", () => { + test("injects credential, proxy and python hardening variables", () => { + const env = buildSandboxEnv({ ...POSIX_INPUT, baseUrl: "https://example.com" }); + expect(env.DASHSCOPE_API_KEY).toBe("sk-test-key"); + expect(env.DASHSCOPE_HTTP_BASE_URL).toBe("https://example.com"); + expect(env.HTTP_PROXY).toBe("http://127.0.0.1:8080"); + expect(env.HTTPS_PROXY).toBe("http://127.0.0.1:8080"); + expect(env.NO_PROXY).toBe(""); + expect(env.PYTHONDONTWRITEBYTECODE).toBe("1"); + expect(env.XDG_CACHE_HOME).toBe("/task/cache"); + expect(env.LOG_LEVEL).toBe("info"); + }); + + test("omits base url when not provided", () => { + const env = buildSandboxEnv(POSIX_INPUT); + expect(env.DASHSCOPE_HTTP_BASE_URL).toBeUndefined(); + }); + + test("does not inherit credential / hijack variables from host env", () => { + const env = buildSandboxEnv({ + ...POSIX_INPUT, + hostEnv: { + DASHSCOPE_CONFIG: "/real/home/.dashscope", + DASHSCOPE_API_KEY_FILE_PATH: "/real/key", + PYTHONPATH: "/evil", + PYTHONHOME: "/evil", + SSH_AUTH_SOCK: "/tmp/sock", + AWS_SECRET_ACCESS_KEY: "secret", + ALIBABA_CLOUD_ACCESS_KEY_SECRET: "secret", + HTTPS_PROXY: "http://user-proxy:1080", + }, + }); + for (const key of [ + "DASHSCOPE_CONFIG", + "DASHSCOPE_API_KEY_FILE_PATH", + "PYTHONPATH", + "PYTHONHOME", + "SSH_AUTH_SOCK", + "AWS_SECRET_ACCESS_KEY", + "ALIBABA_CLOUD_ACCESS_KEY_SECRET", + ]) { + expect(env[key]).toBeUndefined(); + } + // 代理被强制重写为本地白名单代理,而非继承用户代理。 + expect(env.HTTPS_PROXY).toBe("http://127.0.0.1:8080"); + }); + + test("injects controlled sdkEnv (FC_PYPI_LIB) without inheriting it from host", () => { + const env = buildSandboxEnv({ + ...POSIX_INPUT, + sdkEnv: { FC_PYPI_LIB: "dashscope==1.25.23" }, + hostEnv: { FC_PYPI_LIB: "dashscope==9.9.9" }, + }); + // 受控注入优先,宿主同名变量绝不继承。 + expect(env.FC_PYPI_LIB).toBe("dashscope==1.25.23"); + }); + + test("omits FC_PYPI_LIB when sdkEnv is not provided", () => { + const env = buildSandboxEnv({ + ...POSIX_INPUT, + hostEnv: { FC_PYPI_LIB: "dashscope==9.9.9" }, + }); + expect(env.FC_PYPI_LIB).toBeUndefined(); + }); + + test("POSIX redirects HOME / TMPDIR and builds a minimal PATH", () => { + const env = buildSandboxEnv({ ...POSIX_INPUT, hostEnv: { LANG: "en_US.UTF-8" } }); + expect(env.HOME).toBe("/task/home"); + expect(env.TMPDIR).toBe("/task/tmp"); + expect(env.PATH).toBe("/runtime/rl/abc/bin:/usr/bin:/bin"); + expect(env.LANG).toBe("en_US.UTF-8"); + expect(env.USERPROFILE).toBeUndefined(); + }); + + test("win32 redirects the three home variables consistently", () => { + const env = buildSandboxEnv({ + ...POSIX_INPUT, + homeDir: "C:\\task\\home", + tmpDir: "C:\\task\\tmp", + runtimeRoot: "C:\\runtime\\rl\\abc", + platform: "win32", + hostEnv: { SystemRoot: "C:\\Windows" }, + }); + expect(env.USERPROFILE).toBe("C:\\task\\home"); + expect(env.HOMEDRIVE).toBe("C:"); + expect(env.HOMEPATH).toBe("\\task\\home"); + expect(env.TEMP).toBe("C:\\task\\tmp"); + expect(env.TMP).toBe("C:\\task\\tmp"); + expect(env.SystemRoot).toBe("C:\\Windows"); + expect(env.HOME).toBeUndefined(); + }); +}); + +describe("prepareTaskHome", () => { + test("writes a controlled config.toml without persisting the API key", async () => { + await withIsolatedHome(async (home) => { + const taskHome = join(home, "task-home"); + const configPath = prepareTaskHome(taskHome, "https://example.com"); + const content = readFileSync(configPath, "utf8"); + expect(configPath).toBe(join(taskHome, ".dashscope", "config.toml")); + expect(content).toContain('base_url = "https://example.com"'); + expect(content).not.toContain("sk-"); + expect(content).not.toContain("api_key"); + }); + }); +}); diff --git a/packages/core/tests/rl-isolation-os.test.ts b/packages/core/tests/rl-isolation-os.test.ts new file mode 100644 index 00000000..bb4924cd --- /dev/null +++ b/packages/core/tests/rl-isolation-os.test.ts @@ -0,0 +1,116 @@ +import { describe, expect, test } from "vite-plus/test"; +import { + buildBwrapArgs, + buildSbplProfile, + createIsolationAdapter, + detectIsolation, + type IIsolationSpec, +} from "../src/index.ts"; + +const REAL_HOME = "/Users/real/.dashscope"; + +const SPEC: IIsolationSpec = { + runId: "run-1", + runtimeRoot: "/data/runtimes/rl/abc", + taskDir: "/data/runs/run-1", + snapshotDir: "/data/runs/run-1/snapshot", + deployCopyDir: "/data/runs/run-1/deploy-copy", + dataDir: "/data/runs/run-1/data", + homeDir: "/data/runs/run-1/home", + tmpDir: "/data/runs/run-1/tmp", + cacheDir: "/data/runs/run-1/cache", + configPath: "/data/runs/run-1/config.yaml", + command: ["/data/runtimes/rl/abc/bin/python", "-I", "-m", "dashscope"], + apiKey: "sk-secret", + credentialDenyPaths: [REAL_HOME], + network: { managementDomains: ["dashscope.aliyuncs.com"], ossSuffixes: [], allowedPorts: [443] }, + proxyPort: 9090, + timeoutMs: 1000, + maxOutputBytes: 1024, +}; + +describe("platform dispatch", () => { + test("win32 is fail-closed with a plain not-supported reason", async () => { + const capability = await createIsolationAdapter("win32").detect(); + expect(capability.credentialDenyRead.available).toBe(false); + expect(capability.credentialDenyRead.mechanism).toBe("appcontainer"); + expect(capability.credentialDenyRead.reason).toBe("Not supported on Windows yet."); + expect(capability.hardening).toEqual({ + networkEnforce: false, + processTree: false, + memoryLimit: false, + }); + }); + + test("unknown platforms are fail-closed", async () => { + const capability = await detectIsolation("freebsd" as NodeJS.Platform); + expect(capability.credentialDenyRead.available).toBe(false); + expect(capability.credentialDenyRead.mechanism).toBe("none"); + expect(capability.credentialDenyRead.reason).toBe("Not supported on freebsd yet."); + }); + + test("windows adapter leaves the command unwrapped", () => { + const adapter = createIsolationAdapter("win32"); + expect(adapter.wrapCommand(SPEC, SPEC.command)).toEqual(SPEC.command); + }); +}); + +describe("darwin SBPL profile", () => { + test("is deny-default and only allows runtime / task paths", () => { + const profile = buildSbplProfile(SPEC); + expect(profile).toContain("(deny default)"); + expect(profile).toContain("(allow file-read*"); + expect(profile).toContain(SPEC.runtimeRoot); + expect(profile).toContain(SPEC.snapshotDir); + expect(profile).toContain(SPEC.deployCopyDir); + expect(profile).toContain(`(allow network-outbound (remote tcp "localhost:9090"))`); + }); + + test("never references the real credential home", () => { + const profile = buildSbplProfile(SPEC); + expect(profile).not.toContain(REAL_HOME); + expect(profile).not.toContain("/Users/real"); + }); + + test("allows root inode read and the task cwd for interpreter startup", () => { + const profile = buildSbplProfile(SPEC); + // dyld 启动解析绝对路径需读根目录本身,缺失则解释器 SIGABRT(exit 134)且无输出。 + expect(profile).toContain('(literal "/")'); + // cwd=taskDir,getcwd() 需读 cwd 目录本身;仅允许子目录会让 rich 的 os.getcwd() 报 EPERM。 + expect(profile).toContain(`(subpath "${SPEC.taskDir}")`); + }); + + test("allows the system CA bundle for TLS certificate verification", () => { + const profile = buildSbplProfile(SPEC); + expect(profile).toContain('(subpath "/private/etc/ssl")'); + }); +}); + +describe("linux bwrap args", () => { + test("binds runtime and task dirs by real path with pid isolation", () => { + const args = buildBwrapArgs(SPEC, SPEC.command); + expect(args).toContain("--unshare-pid"); + expect(args).toContain("--die-with-parent"); + expect(args).toContain("--ro-bind"); + // 运行时与 snapshot/data 只读,deploy-copy/tmp/home 可写,均按真实路径绑定。 + expect(args).toContain(SPEC.runtimeRoot); + expect(args).toContain(SPEC.deployCopyDir); + expect(args).toContain(SPEC.homeDir); + // 命令位于 -- 之后。 + const separator = args.indexOf("--"); + expect(args.slice(separator + 1)).toEqual(SPEC.command); + }); + + test("never binds the real credential home", () => { + const args = buildBwrapArgs(SPEC, SPEC.command); + expect(args).not.toContain(REAL_HOME); + expect(args.some((arg) => arg.startsWith("/Users/real"))).toBe(false); + }); + + test("linux adapter wraps the command with bwrap", () => { + const adapter = createIsolationAdapter("linux"); + const wrapped = adapter.wrapCommand(SPEC, SPEC.command); + expect(wrapped[0]).toBe("bwrap"); + expect(wrapped).toContain("--unshare-pid"); + }); +}); diff --git a/packages/core/tests/rl-isolation-proxy.test.ts b/packages/core/tests/rl-isolation-proxy.test.ts new file mode 100644 index 00000000..d1c2f360 --- /dev/null +++ b/packages/core/tests/rl-isolation-proxy.test.ts @@ -0,0 +1,203 @@ +import { afterEach, describe, expect, test, vi } from "vite-plus/test"; +import { createServer, connect as netConnect, type Socket } from "node:net"; +import { + isDeniedIp, + startWhitelistProxy, + withEndpointDomain, + DEFAULT_PROXY_POLICY, + type IWhitelistProxy, +} from "../src/index.ts"; + +// DNS 解析 mock:白名单放行用例返回公网 IP(避免真实网络);拒绝用例在解析前已被拦截。 +vi.mock("node:dns/promises", () => ({ + lookup: vi.fn(async () => [{ address: "93.184.216.34", family: 4 }]), +})); + +// 保留真实 connect 供测试客户端使用;代理上游 connect 默认走真实实现,放行用例再改写。 +vi.mock("node:net", async (importOriginal) => { + const actual = await importOriginal(); + return { ...actual, connect: vi.fn(actual.connect) }; +}); + +const { connect: realConnect } = await vi.importActual("node:net"); + +const openProxies: IWhitelistProxy[] = []; +const openSockets: Socket[] = []; +const openServers: ReturnType[] = []; + +afterEach(async () => { + for (const socket of openSockets.splice(0)) socket.destroy(); + for (const proxy of openProxies.splice(0)) await proxy.close(); + for (const server of openServers.splice(0)) { + await new Promise((resolve) => server.close(() => resolve())); + } + vi.mocked(netConnect).mockImplementation(realConnect); +}); + +async function startProxy( + policy?: Parameters[0], +): Promise { + const proxy = await startWhitelistProxy(policy); + openProxies.push(proxy); + return proxy; +} + +function clientSocket(port: number): Socket { + const socket = realConnect({ host: "127.0.0.1", port }); + openSockets.push(socket); + return socket; +} + +/** 发送原始请求并读到首个响应头结束(\r\n\r\n)。 */ +function readHead(socket: Socket, raw: string): Promise { + return new Promise((resolve, reject) => { + let buffer = ""; + const onData = (chunk: Buffer): void => { + buffer += chunk.toString("utf8"); + if (buffer.includes("\r\n\r\n")) { + socket.off("data", onData); + resolve(buffer); + } + }; + socket.on("data", onData); + socket.on("error", reject); + socket.write(raw); + }); +} + +describe("isDeniedIp", () => { + test("denies loopback / private / link-local / metadata / reserved ranges", () => { + for (const ip of [ + "127.0.0.1", + "10.1.2.3", + "192.168.0.1", + "172.16.0.1", + "172.31.255.255", + "169.254.169.254", + "0.0.0.0", + "224.0.0.1", + "::1", + "::", + "fe80::1", + "fd00::1", + "::ffff:127.0.0.1", + ]) { + expect(isDeniedIp(ip)).toBe(true); + } + }); + + test("allows public addresses", () => { + expect(isDeniedIp("93.184.216.34")).toBe(false); + expect(isDeniedIp("8.8.8.8")).toBe(false); + expect(isDeniedIp("2606:2800:220:1:248:1893:25c8:1946")).toBe(false); + }); + + test("denies unrecognized input", () => { + expect(isDeniedIp("not-an-ip")).toBe(true); + }); +}); + +describe("whitelist proxy (real loopback)", () => { + test("denies an unrelated domain with 403", async () => { + const proxy = await startProxy(); + const socket = clientSocket(proxy.port); + const head = await readHead( + socket, + "CONNECT evil.example.com:443 HTTP/1.1\r\nHost: evil.example.com:443\r\n\r\n", + ); + expect(head).toContain("403"); + }); + + test("denies non-443 ports even for an allowed domain", async () => { + const proxy = await startProxy(); + const socket = clientSocket(proxy.port); + const head = await readHead( + socket, + "CONNECT dashscope.aliyuncs.com:80 HTTP/1.1\r\nHost: dashscope.aliyuncs.com:80\r\n\r\n", + ); + expect(head).toContain("403"); + }); + + test("denies plain HTTP requests with 403", async () => { + const proxy = await startProxy(); + const socket = clientSocket(proxy.port); + const head = await readHead( + socket, + "GET http://dashscope.aliyuncs.com/ HTTP/1.1\r\nHost: dashscope.aliyuncs.com\r\n\r\n", + ); + expect(head).toContain("403"); + }); + + test("denies a private IP literal even when host policy would allow it", async () => { + const proxy = await startProxy({ + policy: { managementDomains: ["127.0.0.1"], ossSuffixes: [], allowedPorts: [443] }, + }); + const socket = clientSocket(proxy.port); + const head = await readHead( + socket, + "CONNECT 127.0.0.1:443 HTTP/1.1\r\nHost: 127.0.0.1:443\r\n\r\n", + ); + expect(head).toContain("403"); + }); + + test("allows an approved management host on 443 and tunnels bytes", async () => { + // 真实回环 echo 上游;代理上游 connect 改写到它(DNS 已 mock 成公网 IP 通过 IP 校验)。 + const echo = createServer((socket) => socket.pipe(socket)); + openServers.push(echo); + await new Promise((resolve) => echo.listen(0, "127.0.0.1", () => resolve())); + const echoPort = (echo.address() as { port: number }).port; + vi.mocked(netConnect).mockImplementation(((_options: unknown, callback?: () => void) => + realConnect({ host: "127.0.0.1", port: echoPort }, callback)) as typeof netConnect); + + const events: string[] = []; + const proxy = await startProxy({ + onEvent: (event) => events.push(`${event.type}:${event.host}:${event.port}`), + }); + const socket = clientSocket(proxy.port); + const head = await readHead( + socket, + "CONNECT dashscope.aliyuncs.com:443 HTTP/1.1\r\nHost: dashscope.aliyuncs.com:443\r\n\r\n", + ); + expect(head).toContain("200"); + + const echoed = await new Promise((resolve, reject) => { + socket.once("data", (chunk: Buffer) => resolve(chunk.toString("utf8"))); + socket.once("error", reject); + socket.write("ping"); + }); + expect(echoed).toBe("ping"); + expect(events).toContain("allow:dashscope.aliyuncs.com:443"); + }); +}); + +describe("withEndpointDomain", () => { + test("adds the configured workspace gateway host to the management whitelist", () => { + const policy = withEndpointDomain( + DEFAULT_PROXY_POLICY, + "https://ws-abc.cn-beijing.maas.aliyuncs.com", + ); + expect(policy.managementDomains).toContain("ws-abc.cn-beijing.maas.aliyuncs.com"); + expect(policy.managementDomains).toContain("dashscope.aliyuncs.com"); + }); + + test("does not mutate the original policy", () => { + const before = [...DEFAULT_PROXY_POLICY.managementDomains]; + withEndpointDomain(DEFAULT_PROXY_POLICY, "https://ws-abc.cn-beijing.maas.aliyuncs.com"); + expect(DEFAULT_PROXY_POLICY.managementDomains).toEqual(before); + }); + + test("extracts hostname ignoring path and stays idempotent for known hosts", () => { + const policy = withEndpointDomain( + DEFAULT_PROXY_POLICY, + "https://dashscope.aliyuncs.com/api/v1", + ); + expect( + policy.managementDomains.filter((domain) => domain === "dashscope.aliyuncs.com"), + ).toHaveLength(1); + }); + + test("returns the policy unchanged for missing or invalid base_url", () => { + expect(withEndpointDomain(DEFAULT_PROXY_POLICY)).toBe(DEFAULT_PROXY_POLICY); + expect(withEndpointDomain(DEFAULT_PROXY_POLICY, "not a url")).toBe(DEFAULT_PROXY_POLICY); + }); +}); diff --git a/packages/core/tests/rl-isolation-snapshot.test.ts b/packages/core/tests/rl-isolation-snapshot.test.ts new file mode 100644 index 00000000..9c368cf5 --- /dev/null +++ b/packages/core/tests/rl-isolation-snapshot.test.ts @@ -0,0 +1,145 @@ +import { afterEach, describe, expect, test } from "vite-plus/test"; +import { + existsSync, + mkdirSync, + mkdtempSync, + readFileSync, + rmSync, + symlinkSync, + writeFileSync, +} from "node:fs"; +import { tmpdir } from "node:os"; +import { join } from "node:path"; +import { BailianError, createSnapshot, stageDataFiles } from "../src/index.ts"; + +const tempRoots: string[] = []; + +function makeTempRoot(): string { + const root = mkdtempSync(join(tmpdir(), "bl-rl-snap-")); + tempRoots.push(root); + return root; +} + +afterEach(() => { + for (const root of tempRoots.splice(0)) { + rmSync(root, { recursive: true, force: true }); + } +}); + +/** Build a source tree with a mix of safe / sensitive / excluded entries. */ +function seedSource(sourceDir: string): void { + mkdirSync(sourceDir, { recursive: true }); + writeFileSync(join(sourceDir, "main.py"), "print('hi')\n"); + writeFileSync(join(sourceDir, "reward.py"), "x = 1\n"); + mkdirSync(join(sourceDir, ".git"), { recursive: true }); + writeFileSync(join(sourceDir, ".git", "config"), "secret"); + mkdirSync(join(sourceDir, "node_modules"), { recursive: true }); + writeFileSync(join(sourceDir, "node_modules", "pkg.js"), "x"); + mkdirSync(join(sourceDir, "__pycache__"), { recursive: true }); + writeFileSync(join(sourceDir, "__pycache__", "main.pyc"), "x"); + writeFileSync(join(sourceDir, ".env"), "API_KEY=secret"); + writeFileSync(join(sourceDir, "cert.pem"), "secret"); + writeFileSync(join(sourceDir, "private.key"), "secret"); +} + +describe("createSnapshot", () => { + test("applies built-in safety exclusions for dirs and secret files", () => { + const root = makeTempRoot(); + const sourceDir = join(root, "src"); + seedSource(sourceDir); + const result = createSnapshot({ + sourceDir, + snapshotDir: join(root, "snapshot"), + deployCopyDir: join(root, "deploy-copy"), + }); + expect(result.files.sort()).toEqual(["main.py", "reward.py"]); + expect(result.fileCount).toBe(2); + expect(existsSync(join(root, "snapshot", ".git"))).toBe(false); + expect(existsSync(join(root, "snapshot", ".env"))).toBe(false); + expect(existsSync(join(root, "snapshot", "cert.pem"))).toBe(false); + }); + + test("produces a writable deploy-copy mirroring the snapshot", () => { + const root = makeTempRoot(); + const sourceDir = join(root, "src"); + seedSource(sourceDir); + const deployCopyDir = join(root, "deploy-copy"); + createSnapshot({ + sourceDir, + snapshotDir: join(root, "snapshot"), + deployCopyDir, + }); + expect(readFileSync(join(deployCopyDir, "main.py"), "utf8")).toBe("print('hi')\n"); + // deploy-copy 可写:SDK 的 start.sh 落此。 + writeFileSync(join(deployCopyDir, "start.sh"), "#!/bin/sh\n"); + expect(existsSync(join(deployCopyDir, "start.sh"))).toBe(true); + }); + + test("honors include / exclude globs", () => { + const root = makeTempRoot(); + const sourceDir = join(root, "src"); + mkdirSync(join(sourceDir, "pkg"), { recursive: true }); + writeFileSync(join(sourceDir, "pkg", "a.py"), "a"); + writeFileSync(join(sourceDir, "pkg", "b.txt"), "b"); + writeFileSync(join(sourceDir, "top.py"), "t"); + const result = createSnapshot({ + sourceDir, + snapshotDir: join(root, "snapshot"), + deployCopyDir: join(root, "deploy-copy"), + include: ["**/*.py"], + exclude: ["pkg/a.py"], + }); + expect(result.files.sort()).toEqual(["top.py"]); + }); + + test("rejects symlinks in the source tree", () => { + const root = makeTempRoot(); + const sourceDir = join(root, "src"); + mkdirSync(sourceDir, { recursive: true }); + writeFileSync(join(sourceDir, "main.py"), "x"); + symlinkSync(join(root, "outside"), join(sourceDir, "link.py")); + expect(() => + createSnapshot({ + sourceDir, + snapshotDir: join(root, "snapshot"), + deployCopyDir: join(root, "deploy-copy"), + }), + ).toThrow(BailianError); + }); + + test("enforces the package size limit", () => { + const root = makeTempRoot(); + const sourceDir = join(root, "src"); + mkdirSync(sourceDir, { recursive: true }); + writeFileSync(join(sourceDir, "big.bin"), "x".repeat(100)); + expect(() => + createSnapshot({ + sourceDir, + snapshotDir: join(root, "snapshot"), + deployCopyDir: join(root, "deploy-copy"), + maxPackageBytes: 10, + }), + ).toThrow(/byte limit/); + }); +}); + +describe("stageDataFiles", () => { + test("copies data files into data/ by basename", () => { + const root = makeTempRoot(); + const dataFile = join(root, "train.jsonl"); + writeFileSync(dataFile, '{"a":1}\n'); + const dataDir = join(root, "data"); + const staged = stageDataFiles([dataFile], dataDir); + expect(staged).toEqual([join(dataDir, "train.jsonl")]); + expect(readFileSync(staged[0], "utf8")).toBe('{"a":1}\n'); + }); + + test("rejects symlinked data files", () => { + const root = makeTempRoot(); + const target = join(root, "real.jsonl"); + writeFileSync(target, "x"); + const link = join(root, "link.jsonl"); + symlinkSync(target, link); + expect(() => stageDataFiles([link], join(root, "data"))).toThrow(BailianError); + }); +}); diff --git a/packages/core/tests/rl-runtime-doctor.test.ts b/packages/core/tests/rl-runtime-doctor.test.ts new file mode 100644 index 00000000..2ad2e043 --- /dev/null +++ b/packages/core/tests/rl-runtime-doctor.test.ts @@ -0,0 +1,154 @@ +import { describe, expect, test } from "vite-plus/test"; +import { + assertDoctorPassed, + BailianError, + createWindowsAdapter, + runRuntimeDoctor, + type IDoctorCheck, + type IDoctorReport, +} from "../src/index.ts"; +import { existsSync, writeFileSync } from "node:fs"; +import { join } from "node:path"; +import type { IIsolationAdapter } from "../src/isolation/types.ts"; +import { withIsolatedHome } from "./helpers/isolation.ts"; + +function report(checks: IDoctorCheck[]): IDoctorReport { + return { checks, ok: checks.every((check) => !check.required || check.status === "pass") }; +} + +describe("assertDoctorPassed", () => { + test("passes when every required check passes", () => { + const ok = report([ + { name: "mechanism", required: true, status: "pass" }, + { name: "memory", required: false, status: "degraded" }, + ]); + expect(() => assertDoctorPassed(ok)).not.toThrow(); + }); + + test("fails on a required fail or skip, ignoring degraded enhancements", () => { + expect(() => + assertDoctorPassed(report([{ name: "mechanism", required: true, status: "fail" }])), + ).toThrow(BailianError); + expect(() => + assertDoctorPassed(report([{ name: "python", required: true, status: "skip" }])), + ).toThrow(BailianError); + }); +}); + +describe("runRuntimeDoctor (win32 fail-closed)", () => { + test("reports mechanism failure and skips runtime checks without a runtime", async () => { + const result = await runRuntimeDoctor({ + platform: "win32", + adapter: createWindowsAdapter(), + }); + expect(result.ok).toBe(false); + const mechanism = result.checks.find( + (check) => check.name === "credential-isolation-mechanism", + ); + expect(mechanism?.status).toBe("fail"); + expect(mechanism?.detail).toBe("Not supported on Windows yet."); + // Proxy denying unrelated domains is a real loopback assertion, verifiable offline. + const proxyDeny = result.checks.find((check) => check.name === "proxy-denies-unrelated-domain"); + expect(proxyDeny?.status).toBe("pass"); + // No runtime: runtime-related required checks are skipped (not treated as passed). + const python = result.checks.find((check) => check.name === "python-version"); + expect(python?.status).toBe("skip"); + const fcPypiLib = result.checks.find((check) => check.name === "fc-pypi-lib-injected"); + expect(fcPypiLib?.required).toBe(true); + expect(fcPypiLib?.status).toBe("skip"); + // Host network preflight is off by default (doctor stays usable offline). + expect( + result.checks.find((check) => check.name === "host-network-reachability"), + ).toBeUndefined(); + }); +}); + +describe("runRuntimeDoctor host-network-reachability(注入探针,不真实出站)", () => { + test("全部可达:增强项 pass,不阻断整体", async () => { + const result = await runRuntimeDoctor({ + platform: "win32", + adapter: createWindowsAdapter(), + checkHostNetwork: true, + hostNetworkTargets: [{ host: "api.example.test", port: 443 }], + hostNetworkProbe: async () => undefined, + }); + const check = result.checks.find((item) => item.name === "host-network-reachability"); + expect(check?.required).toBe(false); + expect(check?.status).toBe("pass"); + expect(check?.detail).toBeUndefined(); + }); + + test("部分被阻断:degraded 并列出主机与 errno 及沙箱指引,不计入必过项", async () => { + const result = await runRuntimeDoctor({ + platform: "win32", + adapter: createWindowsAdapter(), + checkHostNetwork: true, + hostNetworkTargets: [ + { host: "api.example.test", port: 443 }, + { host: "download.example.test", port: 443 }, + ], + hostNetworkProbe: async (host) => (host === "download.example.test" ? "EPERM" : undefined), + }); + const check = result.checks.find((item) => item.name === "host-network-reachability"); + expect(check?.required).toBe(false); + expect(check?.status).toBe("degraded"); + expect(check?.detail).toContain("download.example.test:443 (EPERM)"); + expect(check?.detail).not.toContain("api.example.test"); + expect(check?.detail).toContain("sandbox"); + expect(check?.detail).toContain("HTTPS_PROXY"); + // Enhanced degradation does not change the required-check verdict. + expect(() => assertDoctorPassed({ checks: [check!], ok: true })).not.toThrow(); + }); +}); + +// Regression: taskDir is consumed by a single executeIsolatedRun call (destroyed unconditionally in finally), +// so doctor's multiple probes must each create their own layout. The old implementation shared one layout, and the second probe's +// prepare wrote profile.sb into the destroyed directory, hitting ENOENT. Here a fake adapter whose prepare writes a marker +// simulates darwin writing profile.sb; pythonPath uses a node stand-in (probe semantics are covered by the real-runtime doctor, +// this case only asserts multi-probe lifecycle orchestration). +describe("runRuntimeDoctor multi-probe task-dir consumption", () => { + test("each probe prepares into a fresh task dir and all dirs are disposed", async () => { + await withIsolatedHome(async (home) => { + const preparedTaskDirs: string[] = []; + const markerAdapter: IIsolationAdapter = { + detect: async () => ({ + credentialDenyRead: { available: true, mechanism: "none" }, + hardening: { networkEnforce: false, processTree: false, memoryLimit: false }, + }), + prepare: async (spec) => { + writeFileSync(join(spec.taskDir, "marker.sb"), "(version 1)"); + preparedTaskDirs.push(spec.taskDir); + }, + wrapCommand: (_spec, command) => command, + dispose: async () => {}, + }; + const result = await runRuntimeDoctor({ + adapter: markerAdapter, + runtime: { + runtimeRoot: process.execPath, + pythonPath: process.execPath, + dashscopeVersion: "1.25.23", + source: "override", + }, + credentialDenyPaths: [join(home, "real-credential")], + }); + // Each of the 5 probes prepares once into distinct directories; with a shared layout the second prepare + // hits ENOENT, falls into sandbox-self-check fail, and loses the remaining probes. + expect(preparedTaskDirs.length).toBe(5); + expect(new Set(preparedTaskDirs).size).toBe(5); + expect(result.checks.find((check) => check.name === "sandbox-self-check")).toBeUndefined(); + for (const name of [ + "python-version", + "sdk-import", + "fc-pypi-lib-injected", + "home-redirect", + "credential-deny-negative", + ]) { + expect(result.checks.some((check) => check.name === name)).toBe(true); + } + for (const taskDir of preparedTaskDirs) { + expect(existsSync(taskDir)).toBe(false); + } + }); + }); +}); diff --git a/packages/core/tests/rl-runtime-manifest.test.ts b/packages/core/tests/rl-runtime-manifest.test.ts new file mode 100644 index 00000000..1846952e --- /dev/null +++ b/packages/core/tests/rl-runtime-manifest.test.ts @@ -0,0 +1,261 @@ +import { describe, expect, test } from "vite-plus/test"; +import { mkdirSync, readFileSync, writeFileSync } from "node:fs"; +import { join } from "node:path"; +import { fileURLToPath } from "node:url"; +import { + assertArtifactIntegrity, + BailianError, + bundledRuntimeManifest, + DEFAULT_PYTHON_MIRRORS, + parseRuntimeManifest, + pythonDownloadCandidates, + resolveRuntime, + RL_DASHSCOPE_VERSION, + RL_DASHSCOPE_WHEEL_SHA256, + RL_DEPENDENCY_LOCK, + RL_PYTHON_MIRROR_ENV, + runtimeRoot, + RUNTIME_OVERRIDE_ENV, + selectManifestEntry, + sha256Hex, + UsageError, + type IRuntimeManifest, +} from "../src/index.ts"; +import { withIsolatedHome } from "./helpers/isolation.ts"; + +const PYTHON_SHA = sha256Hex("cpython-bytes"); + +function manifestFixture(): IRuntimeManifest { + return { + schemaVersion: 2, + dashscopeVersion: RL_DASHSCOPE_VERSION, + dashscopeUrl: "https://files.pythonhosted.org/packages/dashscope-1.25.23-py3-none-any.whl", + dashscopeSha256: RL_DASHSCOPE_WHEEL_SHA256, + entries: [ + { + os: "linux", + arch: "x64", + triple: "x86_64-unknown-linux-gnu", + pythonVersion: "3.11.9", + pythonUrl: "https://example.com/cpython-3.11.9-install_only.tar.gz", + pythonSha256: PYTHON_SHA, + }, + ], + }; +} + +describe("parseRuntimeManifest (schema v2)", () => { + test("parses a valid manifest", () => { + const manifest = parseRuntimeManifest(JSON.stringify(manifestFixture())); + expect(manifest.schemaVersion).toBe(2); + expect(manifest.entries).toHaveLength(1); + expect(manifest.entries[0].os).toBe("linux"); + expect(manifest.dashscopeSha256).toBe(RL_DASHSCOPE_WHEEL_SHA256); + }); + + test("rejects invalid JSON, missing fields and legacy schemaVersion", () => { + expect(() => parseRuntimeManifest("{broken")).toThrow(UsageError); + expect(() => parseRuntimeManifest(JSON.stringify({ schemaVersion: 2 }))).toThrow(UsageError); + expect(() => parseRuntimeManifest(JSON.stringify({ schemaVersion: 1 }))).toThrow(UsageError); + expect(() => + parseRuntimeManifest( + JSON.stringify({ + schemaVersion: 2, + dashscopeVersion: "1.25.23", + dashscopeUrl: "https://example.com/wheel.whl", + dashscopeSha256: RL_DASHSCOPE_WHEEL_SHA256, + entries: [{}], + }), + ), + ).toThrow(UsageError); + }); + + test("rejects malformed SHA256 on both python and dashscope", () => { + const badPython = manifestFixture(); + badPython.entries[0].pythonSha256 = "not-a-hash"; + expect(() => parseRuntimeManifest(JSON.stringify(badPython))).toThrow(UsageError); + const badDashscope = manifestFixture(); + badDashscope.dashscopeSha256 = "not-a-hash"; + expect(() => parseRuntimeManifest(JSON.stringify(badDashscope))).toThrow(UsageError); + }); +}); + +describe("selectManifestEntry", () => { + test("matches os/arch and rejects unsupported combinations", () => { + const manifest = manifestFixture(); + expect(selectManifestEntry(manifest, "linux", "x64")?.pythonVersion).toBe("3.11.9"); + expect(selectManifestEntry(manifest, "win32", "x64")).toBeUndefined(); + expect(selectManifestEntry(manifest, "linux", "arm64")).toBeUndefined(); + }); +}); + +describe("artifact integrity", () => { + test("accepts matching SHA256 and rejects mismatch", () => { + const data = Buffer.from("cpython-bytes"); + expect(() => assertArtifactIntegrity(data, PYTHON_SHA)).not.toThrow(); + expect(() => assertArtifactIntegrity(data, sha256Hex("tampered"))).toThrow(BailianError); + }); +}); + +describe("bundled reviewed manifest", () => { + test("covers four platforms with the reviewed dashscope baseline", () => { + const manifest = bundledRuntimeManifest(); + expect(manifest.dashscopeVersion).toBe(RL_DASHSCOPE_VERSION); + expect(manifest.dashscopeSha256).toBe(RL_DASHSCOPE_WHEEL_SHA256); + expect(manifest.entries).toHaveLength(4); + for (const entry of manifest.entries) { + expect(entry.pythonSha256).toMatch(/^[0-9a-f]{64}$/); + expect(entry.pythonUrl).toContain("python-build-standalone"); + } + }); + + test("stays in sync with the repo-root runtime-manifest.json source of truth", () => { + const jsonPath = fileURLToPath(new URL("../../../runtime-manifest.json", import.meta.url)); + const fromDisk = JSON.parse(readFileSync(jsonPath, "utf8")); + expect(bundledRuntimeManifest()).toEqual(fromDisk); + }); +}); + +describe("dependency lockfile", () => { + test("pins the reviewed dashscope wheel hash for --require-hashes", () => { + expect(RL_DEPENDENCY_LOCK).toContain(`dashscope==${RL_DASHSCOPE_VERSION}`); + expect(RL_DEPENDENCY_LOCK).toContain(RL_DASHSCOPE_WHEEL_SHA256); + expect(RL_DEPENDENCY_LOCK).toContain("--hash=sha256:"); + }); +}); + +describe("pythonDownloadCandidates (multi-source fallback)", () => { + const githubUrl = + "https://github.com/astral-sh/python-build-standalone/releases/download/20240415/cpython-3.11.9+20240415-x86_64-unknown-linux-gnu-install_only.tar.gz"; + const suffix = "20240415/cpython-3.11.9+20240415-x86_64-unknown-linux-gnu-install_only.tar.gz"; + + test("orders canonical GitHub first then the built-in npmmirror fallback", () => { + const candidates = pythonDownloadCandidates(githubUrl, {}); + expect(candidates).toEqual([githubUrl, `${DEFAULT_PYTHON_MIRRORS[0]}${suffix}`]); + }); + + test("prepends a custom mirror (normalized trailing slash) when env is set", () => { + const candidates = pythonDownloadCandidates(githubUrl, { + [RL_PYTHON_MIRROR_ENV]: "https://mirror.internal/python-build-standalone", + }); + expect(candidates[0]).toBe(`https://mirror.internal/python-build-standalone/${suffix}`); + expect(candidates[1]).toBe(githubUrl); + expect(candidates[2]).toBe(`${DEFAULT_PYTHON_MIRRORS[0]}${suffix}`); + }); + + test("dedupes when the custom mirror equals the built-in fallback", () => { + const candidates = pythonDownloadCandidates(githubUrl, { + [RL_PYTHON_MIRROR_ENV]: DEFAULT_PYTHON_MIRRORS[0], + }); + expect(candidates).toEqual([`${DEFAULT_PYTHON_MIRRORS[0]}${suffix}`, githubUrl]); + }); + + test("does not rewrite a non-GitHub canonical URL", () => { + const custom = "https://example.com/cpython-3.11.9-install_only.tar.gz"; + expect(pythonDownloadCandidates(custom, {})).toEqual([custom]); + }); +}); + +describe("resolveRuntime", () => { + /** Override version-probe deps: simulates the measured importlib.metadata result. */ + function probeDeps(stdout: string, exitCode = 0) { + return { + async download() { + return Buffer.from(""); + }, + async run() { + return { exitCode, stdout, stderr: "" }; + }, + }; + } + + test("reuses a dev override and reports the measured dashscope version", async () => { + await withIsolatedHome(async (home) => { + const overrideDir = join(home, "dev-runtime"); + mkdirSync(join(overrideDir, "bin"), { recursive: true }); + writeFileSync(join(overrideDir, "bin", "python"), ""); + const resolved = await resolveRuntime({ + env: { [RUNTIME_OVERRIDE_ENV]: overrideDir }, + platform: "linux", + deps: probeDeps(`${RL_DASHSCOPE_VERSION}\n`), + }); + expect(resolved.source).toBe("override"); + expect(resolved.pythonPath).toBe(join(overrideDir, "bin", "python")); + expect(resolved.dashscopeVersion).toBe(RL_DASHSCOPE_VERSION); + }); + }); + + test("override reports a non-baseline version honestly (no constant lie)", async () => { + await withIsolatedHome(async (home) => { + const overrideDir = join(home, "dev-runtime"); + mkdirSync(join(overrideDir, "bin"), { recursive: true }); + writeFileSync(join(overrideDir, "bin", "python"), ""); + const resolved = await resolveRuntime({ + env: { [RUNTIME_OVERRIDE_ENV]: overrideDir }, + platform: "linux", + deps: probeDeps("9.9.9\n"), + }); + expect(resolved.dashscopeVersion).toBe("9.9.9"); + }); + }); + + test("override without an importable dashscope fails closed", async () => { + await withIsolatedHome(async (home) => { + const overrideDir = join(home, "dev-runtime"); + mkdirSync(join(overrideDir, "bin"), { recursive: true }); + writeFileSync(join(overrideDir, "bin", "python"), ""); + await expect( + resolveRuntime({ + env: { [RUNTIME_OVERRIDE_ENV]: overrideDir }, + platform: "linux", + deps: probeDeps("", 1), + }), + ).rejects.toThrow(BailianError); + }); + }); + + test("fails when the override has no interpreter", async () => { + await withIsolatedHome(async (home) => { + await expect( + resolveRuntime({ env: { [RUNTIME_OVERRIDE_ENV]: join(home, "empty") }, platform: "linux" }), + ).rejects.toThrow(BailianError); + }); + }); + + test("returns RUNTIME_UNAVAILABLE for an unsupported platform", async () => { + await withIsolatedHome(async () => { + await expect( + resolveRuntime({ env: {}, platform: "win32", arch: "x64" }), + ).rejects.toMatchObject({ message: expect.stringContaining("RUNTIME_UNAVAILABLE") }); + }); + }); + + test("selects the bundled manifest and reports not-prepared when install disallowed", async () => { + await withIsolatedHome(async () => { + await expect( + resolveRuntime({ env: {}, platform: "linux", arch: "x64", allowInstall: false }), + ).rejects.toMatchObject({ + message: expect.stringContaining("RUNTIME_UNAVAILABLE"), + exitCode: 1, + }); + }); + }); + + test("reuses a prepared managed runtime marked READY", async () => { + await withIsolatedHome(async () => { + const runtimeId = `linux-x64-3.11.9-${RL_DASHSCOPE_VERSION}`; + const root = runtimeRoot(runtimeId); + mkdirSync(join(root, "python", "bin"), { recursive: true }); + writeFileSync(join(root, "python", "bin", "python3.11"), ""); + writeFileSync(join(root, "READY"), "{}\n"); + const resolved = await resolveRuntime({ + env: {}, + manifest: manifestFixture(), + platform: "linux", + arch: "x64", + }); + expect(resolved.source).toBe("managed"); + expect(resolved.pythonPath).toBe(join(root, "python", "bin", "python3.11")); + }); + }); +}); diff --git a/packages/core/tests/rl-runtime-sandbox.test.ts b/packages/core/tests/rl-runtime-sandbox.test.ts new file mode 100644 index 00000000..4e700904 --- /dev/null +++ b/packages/core/tests/rl-runtime-sandbox.test.ts @@ -0,0 +1,393 @@ +import { beforeEach, describe, expect, test, vi } from "vite-plus/test"; +import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs"; +import { homedir } from "node:os"; +import { join } from "node:path"; +import type { IIsolationResult } from "../src/isolation/types.ts"; + +// Black-box orchestration tests mock isolated execution to avoid real spawns; keep the rest of app-layer's exports. +const mocks = vi.hoisted(() => ({ + isolatedRun: vi.fn(), +})); +vi.mock("../src/isolation/app-layer.ts", async (importOriginal) => { + const actual = await importOriginal(); + return { ...actual, executeIsolatedRun: mocks.isolatedRun }; +}); + +import { + BailianError, + executeInSandbox, + installRuntime, + normalizeSandboxResult, + RL_DASHSCOPE_VERSION, + RL_DASHSCOPE_WHEEL_SHA256, + RL_DEPENDENCY_LOCK, + RL_PIP_INDEX_ENV, + RL_PYTHON_MIRROR_ENV, + runtimeRoot, + RUNTIME_OVERRIDE_ENV, + sha256Hex, + type IRuntimeDeps, + type IRuntimeManifest, +} from "../src/index.ts"; +import { withIsolatedHome } from "./helpers/isolation.ts"; + +const PYTHON_SHA = sha256Hex("cpython-bytes"); + +function manifestFixture(): IRuntimeManifest { + return { + schemaVersion: 2, + dashscopeVersion: RL_DASHSCOPE_VERSION, + dashscopeUrl: "https://files.pythonhosted.org/packages/dashscope-1.25.23-py3-none-any.whl", + dashscopeSha256: RL_DASHSCOPE_WHEEL_SHA256, + entries: [ + { + os: "linux", + arch: "x64", + triple: "x86_64-unknown-linux-gnu", + pythonVersion: "3.11.9", + pythonUrl: "https://example.com/cpython-3.11.9-install_only.tar.gz", + pythonSha256: PYTHON_SHA, + }, + ], + }; +} + +function okResult(stdout: string): IIsolationResult { + return { + exitCode: 0, + signal: null, + stdout, + stderr: "", + timedOut: false, + credentialDenyEnforced: true, + hardening: { networkEnforce: false, processTree: false, memoryLimit: false }, + }; +} + +describe("normalizeSandboxResult", () => { + test("returns parsed JSON on success and raw fallback for non-JSON", () => { + expect(normalizeSandboxResult(okResult('{"job_id":"j1"}'))).toEqual({ job_id: "j1" }); + expect(normalizeSandboxResult(okResult("plain text"))).toEqual({ raw: "plain text" }); + }); + + test("maps timeout to TIMEOUT without canceling the cloud job", () => { + const timedOut = { ...okResult(""), timedOut: true }; + expect(() => normalizeSandboxResult(timedOut)).toThrow(BailianError); + try { + normalizeSandboxResult(timedOut); + } catch (error) { + expect((error as BailianError).exitCode).toBe(5); + } + }); + + test("passes server-side failures through verbatim", () => { + const failed = { ...okResult('{"message":"boom"}'), exitCode: 1 }; + expect(() => normalizeSandboxResult(failed)).toThrow("boom"); + const stderrFailed = { ...okResult(""), exitCode: 1, stderr: "stderr detail" }; + expect(() => normalizeSandboxResult(stderrFailed)).toThrow("stderr detail"); + }); +}); + +describe("executeInSandbox (black-box orchestration)", () => { + beforeEach(() => { + mocks.isolatedRun.mockReset(); + mocks.isolatedRun.mockResolvedValue(okResult('{"job_id":"j1"}')); + }); + + /** Override version-probe deps: returns the reviewed baseline version (no real spawn). */ + function probeDeps(version: string = RL_DASHSCOPE_VERSION): IRuntimeDeps { + return { + async download() { + return Buffer.from(""); + }, + async run() { + return { exitCode: 0, stdout: `${version}\n`, stderr: "" }; + }, + }; + } + + test("injects interpreter prefix, credential, config, FC_PYPI_LIB and default deny path", async () => { + await withIsolatedHome(async (home) => { + const overrideDir = join(home, "dev-runtime"); + mkdirSync(join(overrideDir, "bin"), { recursive: true }); + writeFileSync(join(overrideDir, "bin", "python"), ""); + + const data = await executeInSandbox({ + sdkArgs: ["rl", "get", "j1", "--output-format", "json"], + credential: { token: "sk-test", baseUrl: "https://example.com" }, + runtimeOptions: { + env: { [RUNTIME_OVERRIDE_ENV]: overrideDir }, + platform: "linux", + deps: probeDeps(), + }, + prepare: (layout) => { + writeFileSync(join(layout.dataDir, "train.jsonl"), "{}\n"); + return "name: test\n"; + }, + }); + expect(data).toEqual({ job_id: "j1" }); + + const input = mocks.isolatedRun.mock.calls[0][0]; + expect(input.runtimeRoot).toBe(overrideDir); + expect(input.apiKey).toBe("sk-test"); + expect(input.baseUrl).toBe("https://example.com"); + expect(input.credentialDenyPaths).toEqual([join(homedir(), ".dashscope")]); + // 1.25.23 has no top-level --output; JSON output is carried by the command layer's leaf-level --output-format. + expect(input.command).toEqual([ + join(overrideDir, "bin", "python"), + "-I", + "-m", + "dashscope.cli", + "rl", + "get", + "j1", + "--output-format", + "json", + "--config", + input.layout.configPath, + ]); + // FC_PYPI_LIB stays locked to the submit-side runtime version; zero user involvement. + expect(input.sdkEnv).toEqual({ FC_PYPI_LIB: `dashscope==${RL_DASHSCOPE_VERSION}` }); + // The SDK writes start.sh relative to cwd: cwd must be the writable deploy-copy (same as zipdir). + expect(input.cwd).toBe(input.layout.deployCopyDir); + expect(readFileSync(input.layout.configPath, "utf8")).toBe("name: test\n"); + }); + }); + + test("FC_PYPI_LIB follows the measured override version (no baseline lie)", async () => { + await withIsolatedHome(async (home) => { + const overrideDir = join(home, "dev-runtime"); + mkdirSync(join(overrideDir, "bin"), { recursive: true }); + writeFileSync(join(overrideDir, "bin", "python"), ""); + await executeInSandbox({ + sdkArgs: ["rl", "list", "--output-format", "json"], + credential: { token: "sk-test" }, + runtimeOptions: { + env: { [RUNTIME_OVERRIDE_ENV]: overrideDir }, + platform: "linux", + deps: probeDeps("9.9.9"), + }, + }); + const input = mocks.isolatedRun.mock.calls[0][0]; + expect(input.sdkEnv).toEqual({ FC_PYPI_LIB: "dashscope==9.9.9" }); + }); + }); + + test("omits --config when prepare returns nothing", async () => { + await withIsolatedHome(async (home) => { + const overrideDir = join(home, "dev-runtime"); + mkdirSync(join(overrideDir, "bin"), { recursive: true }); + writeFileSync(join(overrideDir, "bin", "python"), ""); + await executeInSandbox({ + sdkArgs: ["rl", "list", "--output-format", "json"], + credential: { token: "sk-test" }, + runtimeOptions: { + env: { [RUNTIME_OVERRIDE_ENV]: overrideDir }, + platform: "linux", + deps: probeDeps(), + }, + }); + const input = mocks.isolatedRun.mock.calls[0][0]; + expect(input.command).not.toContain("--config"); + expect(input.command).toContain("list"); + }); + }); +}); + +/** Mock deps: records calls and simulates tar extracting an interpreter; optionally injects pip/import failures. */ +function makeDeps( + root: string, + opts: { bytes?: Buffer; failPip?: boolean; failImport?: boolean } = {}, +): { deps: IRuntimeDeps; calls: Array<{ command: string; args: string[] }> } { + const calls: Array<{ command: string; args: string[] }> = []; + const deps: IRuntimeDeps = { + async download() { + return opts.bytes ?? Buffer.from("cpython-bytes"); + }, + async run(command, args) { + calls.push({ command, args }); + if (command === "tar") { + mkdirSync(join(root, "python", "bin"), { recursive: true }); + writeFileSync(join(root, "python", "bin", "python3.11"), ""); + return { exitCode: 0, stdout: "", stderr: "" }; + } + if (opts.failPip && args.includes("pip")) { + return { exitCode: 1, stdout: "", stderr: "pip boom" }; + } + if (opts.failImport && args.includes("import dashscope")) { + return { exitCode: 1, stdout: "", stderr: "import boom" }; + } + return { exitCode: 0, stdout: "", stderr: "" }; + }, + }; + return { deps, calls }; +} + +describe("installRuntime (manifest-driven first download + cache)", () => { + test("downloads CPython, verifies hash, installs locked deps, self-checks, marks READY", async () => { + await withIsolatedHome(async () => { + const manifest = manifestFixture(); + const root = runtimeRoot(`linux-x64-3.11.9-${RL_DASHSCOPE_VERSION}`); + const { deps, calls } = makeDeps(root); + await installRuntime(manifest.entries[0], manifest, root, deps, "linux"); + + expect(existsSync(join(root, "READY"))).toBe(true); + expect(existsSync(join(root, "runtime.json"))).toBe(true); + expect(readFileSync(join(root, "requirements.lock"), "utf8")).toBe(RL_DEPENDENCY_LOCK); + + const tarCall = calls.find((call) => call.command === "tar"); + expect(tarCall?.args).toContain("-xzf"); + const pipCall = calls.find((call) => call.args.includes("pip")); + expect(pipCall?.args).toContain("--require-hashes"); + expect(calls.some((call) => call.args.includes("import dashscope"))).toBe(true); + }); + }); + + test("passes a custom pip index when BAILIAN_RL_PIP_INDEX_URL is set", async () => { + await withIsolatedHome(async () => { + const manifest = manifestFixture(); + const root = runtimeRoot(`linux-x64-3.11.9-${RL_DASHSCOPE_VERSION}`); + const { deps, calls } = makeDeps(root); + await installRuntime(manifest.entries[0], manifest, root, deps, "linux", { + [RL_PIP_INDEX_ENV]: "https://mirrors.aliyun.com/pypi/simple/", + }); + const pipCall = calls.find((call) => call.args.includes("pip")); + expect(pipCall?.args).toContain("--index-url"); + expect(pipCall?.args).toContain("https://mirrors.aliyun.com/pypi/simple/"); + expect(pipCall?.args).toContain("--require-hashes"); + }); + }); + + test("refuses a tampered CPython artifact and never marks READY", async () => { + await withIsolatedHome(async () => { + const manifest = manifestFixture(); + const root = runtimeRoot(`linux-x64-3.11.9-${RL_DASHSCOPE_VERSION}`); + const { deps } = makeDeps(root, { bytes: Buffer.from("tampered") }); + await expect( + installRuntime(manifest.entries[0], manifest, root, deps, "linux"), + ).rejects.toThrow(BailianError); + expect(existsSync(join(root, "READY"))).toBe(false); + }); + }); + + test("a failed dependency install leaves no READY marker", async () => { + await withIsolatedHome(async () => { + const manifest = manifestFixture(); + const root = runtimeRoot(`linux-x64-3.11.9-${RL_DASHSCOPE_VERSION}`); + const { deps } = makeDeps(root, { failPip: true }); + await expect( + installRuntime(manifest.entries[0], manifest, root, deps, "linux"), + ).rejects.toThrow(BailianError); + expect(existsSync(join(root, "READY"))).toBe(false); + }); + }); + + test("a failed import self-check leaves no READY marker", async () => { + await withIsolatedHome(async () => { + const manifest = manifestFixture(); + const root = runtimeRoot(`linux-x64-3.11.9-${RL_DASHSCOPE_VERSION}`); + const { deps } = makeDeps(root, { failImport: true }); + await expect( + installRuntime(manifest.entries[0], manifest, root, deps, "linux"), + ).rejects.toThrow(BailianError); + expect(existsSync(join(root, "READY"))).toBe(false); + }); + }); +}); + +/** GitHub canonical manifest (triggers mirror fallback candidates). */ +function githubManifestFixture(): IRuntimeManifest { + return { + schemaVersion: 2, + dashscopeVersion: RL_DASHSCOPE_VERSION, + dashscopeUrl: "https://files.pythonhosted.org/packages/dashscope-1.25.23-py3-none-any.whl", + dashscopeSha256: RL_DASHSCOPE_WHEEL_SHA256, + entries: [ + { + os: "linux", + arch: "x64", + triple: "x86_64-unknown-linux-gnu", + pythonVersion: "3.11.9", + pythonUrl: + "https://github.com/astral-sh/python-build-standalone/releases/download/20240415/cpython-3.11.9+20240415-x86_64-unknown-linux-gnu-install_only.tar.gz", + pythonSha256: PYTHON_SHA, + }, + ], + }; +} + +/** URL-aware download mock: the GitHub source can inject network failure/tampering; mirror sources return valid bytes by default. */ +function makeFallbackDeps( + root: string, + opts: { github?: "ok" | "network" | "tamper"; mirror?: "ok" | "network" } = {}, +): { deps: IRuntimeDeps; urls: string[] } { + const urls: string[] = []; + const deps: IRuntimeDeps = { + async download(url) { + urls.push(url); + const mode = url.includes("github.com") ? (opts.github ?? "ok") : (opts.mirror ?? "ok"); + if (mode === "network") throw new Error("network stall"); + if (mode === "tamper") return Buffer.from("tampered"); + return Buffer.from("cpython-bytes"); + }, + async run(command) { + if (command === "tar") { + mkdirSync(join(root, "python", "bin"), { recursive: true }); + writeFileSync(join(root, "python", "bin", "python3.11"), ""); + } + return { exitCode: 0, stdout: "", stderr: "" }; + }, + }; + return { deps, urls }; +} + +describe("installRuntime (multi-source download fallback)", () => { + test("falls back to npmmirror when the GitHub download stalls", async () => { + await withIsolatedHome(async () => { + const manifest = githubManifestFixture(); + const root = runtimeRoot(`linux-x64-3.11.9-${RL_DASHSCOPE_VERSION}`); + const { deps, urls } = makeFallbackDeps(root, { github: "network" }); + await installRuntime(manifest.entries[0], manifest, root, deps, "linux", {}); + expect(existsSync(join(root, "READY"))).toBe(true); + expect(readFileSync(join(root, "requirements.lock"), "utf8")).toBe(RL_DEPENDENCY_LOCK); + expect(urls[0]).toContain("github.com"); + expect(urls[1]).toContain("npmmirror.com"); + }); + }); + + test("falls back when GitHub serves a tampered artifact (SHA mismatch)", async () => { + await withIsolatedHome(async () => { + const manifest = githubManifestFixture(); + const root = runtimeRoot(`linux-x64-3.11.9-${RL_DASHSCOPE_VERSION}`); + const { deps, urls } = makeFallbackDeps(root, { github: "tamper" }); + await installRuntime(manifest.entries[0], manifest, root, deps, "linux", {}); + expect(existsSync(join(root, "READY"))).toBe(true); + expect(urls.some((url) => url.includes("npmmirror.com"))).toBe(true); + }); + }); + + test("never marks READY when every candidate source fails", async () => { + await withIsolatedHome(async () => { + const manifest = githubManifestFixture(); + const root = runtimeRoot(`linux-x64-3.11.9-${RL_DASHSCOPE_VERSION}`); + const { deps } = makeFallbackDeps(root, { github: "network", mirror: "network" }); + await expect( + installRuntime(manifest.entries[0], manifest, root, deps, "linux", {}), + ).rejects.toThrow(); + expect(existsSync(join(root, "READY"))).toBe(false); + }); + }); + + test("tries a custom mirror first when BAILIAN_RL_PYTHON_MIRROR is set", async () => { + await withIsolatedHome(async () => { + const manifest = githubManifestFixture(); + const root = runtimeRoot(`linux-x64-3.11.9-${RL_DASHSCOPE_VERSION}`); + const { deps, urls } = makeFallbackDeps(root); + await installRuntime(manifest.entries[0], manifest, root, deps, "linux", { + [RL_PYTHON_MIRROR_ENV]: "https://mirror.internal/python-build-standalone", + }); + expect(existsSync(join(root, "READY"))).toBe(true); + expect(urls[0]).toContain("mirror.internal"); + }); + }); +}); diff --git a/packages/kscli/package.json b/packages/kscli/package.json index aa62459b..ae682ca1 100644 --- a/packages/kscli/package.json +++ b/packages/kscli/package.json @@ -1,6 +1,6 @@ { "name": "knowledge-studio-cli", - "version": "2.10.3", + "version": "2.10.4", "description": "Lightweight RAG CLI for Aliyun Model Studio — focused on knowledge-base retrieval.", "keywords": [ "alibaba-cloud", diff --git a/packages/runtime/package.json b/packages/runtime/package.json index 774645da..6e35ce37 100644 --- a/packages/runtime/package.json +++ b/packages/runtime/package.json @@ -1,6 +1,6 @@ { "name": "bailian-cli-runtime", - "version": "2.10.3", + "version": "2.10.4", "description": "Runtime framework for bailian-cli (createCli, registry, args, output, pipeline). See https://www.npmjs.com/package/bailian-cli for usage.", "homepage": "https://bailian.console.aliyun.com/cli", "bugs": { diff --git a/packages/runtime/src/error-handler.ts b/packages/runtime/src/error-handler.ts index 6b93fe11..29281704 100644 --- a/packages/runtime/src/error-handler.ts +++ b/packages/runtime/src/error-handler.ts @@ -1,6 +1,11 @@ import { CredentialError } from "bailian-cli-core"; import { formatCommand } from "bailian-cli-core"; -import { BailianError, ExitCode, type LocalizedText } from "bailian-cli-core"; +import { + BailianError, + ExitCode, + isSandboxNetworkDenialCode, + type LocalizedText, +} from "bailian-cli-core"; import type { OutputReporter } from "./output/reporter.ts"; import { sanitizeDiagnosticDetails } from "./output/diagnostics.ts"; import { API_KEY_PAGE } from "./urls.ts"; @@ -237,6 +242,14 @@ function networkHint( baseUrlHint: string, localize: Localize, ): string { + // Sandbox network denial (connect fails immediately with EPERM/EACCES/ENETUNREACH/EHOSTUNREACH): + // mirrors and retries cannot help; guide toward enabling network in the agent settings or running in a regular terminal. + if (isSandboxNetworkDenialCode(code)) { + return localize({ + "en-US": `Outbound network appears to be blocked by the execution environment (e.g. an AI agent sandbox). Enable network access for this process in the agent settings, or run ${commandPrefix} in a regular terminal. If an egress proxy is required, set HTTPS_PROXY.`, + "zh-CN": `出站网络似乎被执行环境(如 AI agent 沙箱)阻断。请在 agent 设置中为本进程放行网络,或在普通终端中运行 ${commandPrefix}。如需经代理出站,请设置 HTTPS_PROXY。`, + }); + } switch (code) { case "ENOTFOUND": case "EAI_AGAIN": diff --git a/packages/runtime/src/index.ts b/packages/runtime/src/index.ts index f10e5413..3c581b29 100644 --- a/packages/runtime/src/index.ts +++ b/packages/runtime/src/index.ts @@ -41,6 +41,9 @@ export { mcpMarketplaceDetailPage, VOICE_TTS_PAGE, MODEL_TELEMETRY_DOC, + RL_TRAINING_DOC, + OPD_TRAINING_DOC, + OPD_MODEL_MATRIX_DOC, refundConsolePage, } from "./urls.ts"; diff --git a/packages/runtime/src/proxy.ts b/packages/runtime/src/proxy.ts index 4c21ef58..0dc72e74 100644 --- a/packages/runtime/src/proxy.ts +++ b/packages/runtime/src/proxy.ts @@ -8,7 +8,8 @@ export interface ProxyEnv { } function pick(env: NodeJS.ProcessEnv, key: string): string | undefined { - const value = env[key]?.trim(); + // 大写优先,小写兜底(macOS/Linux 习惯设 https_proxy 等小写变量)。 + const value = (env[key] ?? env[key.toLowerCase()])?.trim(); return value || undefined; } diff --git a/packages/runtime/src/urls.ts b/packages/runtime/src/urls.ts index 927599e1..6ed66415 100644 --- a/packages/runtime/src/urls.ts +++ b/packages/runtime/src/urls.ts @@ -44,6 +44,19 @@ export const VOICE_TTS_PAGE = "https://help.aliyun.com/zh/model-studio/cosyvoice export const MODEL_TELEMETRY_DOC = "https://docs.bailian.console.aliyun.com/zh/model-studio/model-telemetry"; +/** + * RL / OPD training docs (environment-preparation section) — guide users to + * manually authorize the service-linked roles required by RL / OPD training. + * The CLI only checks role status and never creates roles on the user's behalf. + */ +export const RL_TRAINING_DOC = + "https://docs.bailian.console.aliyun.com/zh/model-studio/rl-training-overview#%E7%8E%AF%E5%A2%83%E5%87%86%E5%A4%87"; +export const OPD_TRAINING_DOC = + "https://docs.bailian.console.aliyun.com/zh/model-studio/opd-training-overview#%E7%8E%AF%E5%A2%83%E5%87%86%E5%A4%87"; +/** OPD docs "模型与训练单元" section: published student/teacher pairs and the recommended MTU capacity. */ +export const OPD_MODEL_MATRIX_DOC = + "https://docs.bailian.console.aliyun.com/zh/model-studio/opd-training-overview#%E6%A8%A1%E5%9E%8B%E4%B8%8E%E8%AE%AD%E7%BB%83%E5%8D%95%E5%85%83"; + /** * Aliyun billing console refund (unsubscribe) page for one prepaid instance. * Unsubscribing a prepaid PTU capacity instance is a billing action that has diff --git a/packages/runtime/tests/error-handler.test.ts b/packages/runtime/tests/error-handler.test.ts index b40a6e59..b34625b3 100644 --- a/packages/runtime/tests/error-handler.test.ts +++ b/packages/runtime/tests/error-handler.test.ts @@ -1,6 +1,6 @@ import { BailianError, ExitCode, mapApiError, resolveRecoveryConfigName } from "bailian-cli-core"; import { expect, test, vi } from "vite-plus/test"; -import { errorHint, handleError } from "../src/error-handler.ts"; +import { errorHint, handleError, normalizeError } from "../src/error-handler.ts"; import { createOutputReporter } from "../src/output/reporter.ts"; import { ConfirmationRequiredError } from "../src/confirm.ts"; @@ -66,6 +66,25 @@ test("handleError: fetch without nested cause still maps to NETWORK", () => { expect(payload.cause).toEqual({ message: "fetch failed" }); }); +test("handleError: 沙箱拒绝 errno(EPERM)hint 引导放行网络而非换镜像", () => { + const cause = Object.assign(new Error("connect EPERM 1.2.3.4:443"), { code: "EPERM" }); + const payload = JSON.parse(render(new TypeError("fetch failed", { cause }))).error; + expect(payload.code).toBe(ExitCode.NETWORK); + expect(payload.message).toContain("EPERM"); + expect(payload.hint).toContain("agent sandbox"); + expect(payload.hint).toContain("HTTPS_PROXY"); +}); + +test("normalizeError: 沙箱拒绝 hint 中文本地化", () => { + const cause = Object.assign(new Error("connect ENETUNREACH"), { code: "ENETUNREACH" }); + const normalized = normalizeError(new TypeError("fetch failed", { cause }), "bl", (text) => + typeof text === "string" ? text : text["zh-CN"], + ); + expect(normalized.exitCode).toBe(ExitCode.NETWORK); + expect(normalized.hint).toContain("沙箱"); + expect(normalized.hint).toContain("HTTPS_PROXY"); +}); + test("handleError: confirmation preserves its structured subtype and guidance", () => { const confirmation = new ConfirmationRequiredError({ message: "Permanent deletion.", diff --git a/packages/runtime/tests/proxy.test.ts b/packages/runtime/tests/proxy.test.ts index aae11a20..3615e507 100644 --- a/packages/runtime/tests/proxy.test.ts +++ b/packages/runtime/tests/proxy.test.ts @@ -31,8 +31,30 @@ test("readProxyEnv: 读取代理变量", () => { }); test("readProxyEnv: NO_PROXY 独立读取", () => { - const r = readProxyEnv({ NO_PROXY: "*.aliyuncs.com" }); - expect(r.noProxy).toBe("*.aliyuncs.com"); - expect(r.httpProxy).toBeUndefined(); - expect(r.httpsProxy).toBeUndefined(); + const result = readProxyEnv({ NO_PROXY: "*.aliyuncs.com" }); + expect(result.noProxy).toBe("*.aliyuncs.com"); + expect(result.httpProxy).toBeUndefined(); + expect(result.httpsProxy).toBeUndefined(); +}); + +test("readProxyEnv: 小写变量兜底(macOS/Linux 习惯)", () => { + expect( + readProxyEnv({ + https_proxy: "http://127.0.0.1:7890", + http_proxy: "http://127.0.0.1:7891", + no_proxy: "localhost", + }), + ).toEqual({ + httpProxy: "http://127.0.0.1:7891", + httpsProxy: "http://127.0.0.1:7890", + noProxy: "localhost", + }); +}); + +test("readProxyEnv: 大写优先于小写", () => { + const result = readProxyEnv({ + HTTPS_PROXY: "http://upper.example.com:8080", + https_proxy: "http://lower.example.com:8080", + }); + expect(result.httpsProxy).toBe("http://upper.example.com:8080"); }); diff --git a/runtime-manifest.json b/runtime-manifest.json new file mode 100644 index 00000000..0fb1cdc5 --- /dev/null +++ b/runtime-manifest.json @@ -0,0 +1,40 @@ +{ + "schemaVersion": 2, + "dashscopeVersion": "1.25.23", + "dashscopeUrl": "https://files.pythonhosted.org/packages/9e/47/556e3a5d9e9e0f2d7c45f8598c7b9a9569ec7e5340e8e2a21288b58e4cfc/dashscope-1.25.23-py3-none-any.whl", + "dashscopeSha256": "7cb2cc48fd82536202e3100e93730e92c952435bb8cbe16d45de9700e1546bcc", + "entries": [ + { + "os": "darwin", + "arch": "arm64", + "triple": "aarch64-apple-darwin", + "pythonVersion": "3.11.9", + "pythonUrl": "https://github.com/astral-sh/python-build-standalone/releases/download/20240415/cpython-3.11.9+20240415-aarch64-apple-darwin-install_only.tar.gz", + "pythonSha256": "7af7058f7c268b4d87ed7e08c2c7844ef8460863b3e679db3afdce8bb1eedfae" + }, + { + "os": "darwin", + "arch": "x64", + "triple": "x86_64-apple-darwin", + "pythonVersion": "3.11.9", + "pythonUrl": "https://github.com/astral-sh/python-build-standalone/releases/download/20240415/cpython-3.11.9+20240415-x86_64-apple-darwin-install_only.tar.gz", + "pythonSha256": "9afd734f63a23783cf0257bef25c9231ffc80e7747486dc54cf72f325213fd15" + }, + { + "os": "linux", + "arch": "x64", + "triple": "x86_64-unknown-linux-gnu", + "pythonVersion": "3.11.9", + "pythonUrl": "https://github.com/astral-sh/python-build-standalone/releases/download/20240415/cpython-3.11.9+20240415-x86_64-unknown-linux-gnu-install_only.tar.gz", + "pythonSha256": "78b1c16a9fd032997ba92a60f46a64f795cd18ff335659dfdf6096df277b24d5" + }, + { + "os": "linux", + "arch": "arm64", + "triple": "aarch64-unknown-linux-gnu", + "pythonVersion": "3.11.9", + "pythonUrl": "https://github.com/astral-sh/python-build-standalone/releases/download/20240415/cpython-3.11.9+20240415-aarch64-unknown-linux-gnu-install_only.tar.gz", + "pythonSha256": "b3a7199ac2615d75fb906e5ba556432efcf24baf8651fc70370d9f052d4069ee" + } + ] +} diff --git a/skills/bailian-cli/SKILL.md b/skills/bailian-cli/SKILL.md index 40e6bc4f..d8629466 100644 --- a/skills/bailian-cli/SKILL.md +++ b/skills/bailian-cli/SKILL.md @@ -1,7 +1,7 @@ --- name: bailian-cli metadata: - version: "2.10.3" + version: "2.10.4" requires: bins: ["bl"] description: >- @@ -31,7 +31,7 @@ BAILIAN_CALLER_TYPE=agent BAILIAN_CALLER_NAME=codex BAILIAN_SKILL_NAME=bailian-c > **Family hub** — This skill owns Bailian resource commands and the hub `reference/` (apps, usage, auth, config, …). > Shared protocol → [`../bailian-protocol/SKILL.md`](../bailian-protocol/SKILL.md) (install the full family with `bl skill init`). -> Soft hand-offs by skill name (Read if installed; else `bl … --help` / prompt `bl skill init`): `bailian-gen` (media) · `bailian-finetune` (training) · `bailian-managed-agent` (agents.yaml IaC) · `bailian-sandbox` (Sandbox lifecycle) · `bailian-web-search` (web search routing) · `bailian-knowledge` (personal documents in everyday tasks and knowledge workflows). +> Soft hand-offs by skill name (Read if installed; else `bl … --help` / prompt `bl skill init`): `bailian-gen` (media) · `bailian-finetune` (training) · `bailian-opd` (guided end-to-end OPD distillation workflow) · `bailian-managed-agent` (agents.yaml IaC) · `bailian-sandbox` (Sandbox lifecycle) · `bailian-web-search` (web search routing) · `bailian-knowledge` (personal documents in everyday tasks and knowledge workflows). > Tasks that need the user’s own historical documents belong to `bailian-knowledge`; ordinary writing does not itself select a cloud provider. > Do not invoke it for ordinary reasoning, coding, writing, translation, summarization, generic research, or image understanding the host agent can complete directly. > @@ -102,6 +102,7 @@ Use this table only after the decision table in [`bailian-protocol`](../bailian- | Switch CLI Help / Quick Start language | `bl config set --key language --value zh-CN` | Use `en-US` to switch back; follows the active config profile | | Image / video / speech / omni / vision | → skill `bailian-gen` | Fallback: `bl image\|video\|speech\|omni\|vision --help` | | Training dataset / fine-tune / deploy | → skill `bailian-finetune` | Fallback: `bl dataset\|finetune\|deploy --help` | +| Guided end-to-end OPD distillation workflow | → skill `bailian-opd` | Authorize → validate → preflight → consent → submit → wait; fallback: `bl finetune opd --help` | | agents.yaml IaC / managed-agent sessions | → skill `bailian-managed-agent` | Fallback: `bl managed-agent --help`; `apply`/`destroy` need `--yes` after `plan` | | Bailian Sandbox instance / template lifecycle | → skill `bailian-sandbox` | Fallback: `bl sandbox --help` | | Web search (mode-aware routing) | → skill `bailian-web-search` | Default model mode vs explicit `--mode mcp` + fallback; fallback: `bl search web --help` | diff --git a/skills/bailian-finetune/SKILL.md b/skills/bailian-finetune/SKILL.md index 71dfcea7..47cde633 100644 --- a/skills/bailian-finetune/SKILL.md +++ b/skills/bailian-finetune/SKILL.md @@ -1,7 +1,7 @@ --- name: bailian-finetune metadata: - version: "2.10.3" + version: "2.10.4" requires: bins: ["bl"] description: >- @@ -10,6 +10,9 @@ description: >- 把专属模型部署成服务时使用 `bl dataset` / `bl finetune` / `bl deploy`。链路是 validate 校验数据 → upload 拿 file-id → finetune create 建任务 → watch 看进度 → export 导出 → 可选 compress 量化压缩 → deploy 上线,需要 API key; Console 版本状态与独立部署服务查询使用 Console 鉴权。 + 强化学习(RL)训练走 `bl finetune rl`,在隔离沙箱内执行,需先 `bl finetune runtime prepare` 准备运行时(沙箱仅支持 macOS / Linux); + OPD 蒸馏训练走 `bl finetune opd`,宿主直连 fine-tunes OpenAPI,无需沙箱运行时; + 授权检查与开通走 `bl finetune rl authorize` / `bl finetune opd authorize`(Console 鉴权)。 写操作先用 `--dry-run` 预览。反触发:用户点名火山方舟/ark 的精调不走本 skill;只是要选哪个模型走 bailian-model-recommend;用现成模型生图生视频走 bailian-gen;百炼其他资源管理走 bailian-cli。 官方安装:`bl skill init`(与共享协议 bailian-protocol 同装)。 @@ -47,28 +50,33 @@ BAILIAN_CALLER_TYPE=agent BAILIAN_CALLER_NAME=codex BAILIAN_SKILL_NAME=bailian-f ## When to use which command -| Intent | Command | -| ------------------------------------------------------ | ------------------------------------------------------------------------------------------------------ | -| Validate / upload training data | `bl dataset validate` / `upload` (`.jsonl` or `.zip`) | -| Dataset list / detail / delete | `bl dataset list` / `get` / `delete` | -| Console dataset groups / discover version and file IDs | `bl dataset groups` → `bl dataset version --dataset-group-id ` (Console auth) | -| Console version detail / import and release state | `bl dataset version --dataset-id ` (Console auth; optional `--include-status`) | -| Console independent deployment services | `bl deploy instances` (Console auth; not capacity instances or replicas) | -| Create a fine-tuning job | `bl finetune text\|audio\|image create` | -| Job list / detail / follow | `bl finetune list` / `get` / `watch` / `logs` | -| Artifacts and export | `bl finetune checkpoints` / `export` | -| Quantize / compress a full model | `bl finetune compress templates` / `create` / `watch` / `get` / `logs` / `list` | -| Cancel / delete a compression job | `bl finetune compress cancel` / `delete` | -| Cancel / delete a fine-tuning job | `bl finetune cancel` / `delete` | -| Import an external OSS LoRA model | Hand-off: `bl cmodel import *` — hub-owned commands; see `bailian-cli` reference or `bl cmodel --help` | -| Trainable capability lookup | `bl finetune capability` | -| Deploy / lifecycle | `bl deploy text\|audio\|image create`, `list` / `get` / `update` / `scale` / `delete` / `models` | -| Query throughput reservations | `bl deploy list --plan ptu` / `bl deploy get` | -| Query capacity instances | `bl deploy capacity list` / `get` | -| Query / wait for a capacity operation | `bl deploy operation get` / `wait` | -| Buy / scale / renew / release capacity | `bl deploy capacity create` / `scale` / `renew` / `delete` | -| Unsubscribe a prepaid instance | `bl deploy capacity unsubscribe` (builds the billing console refund link) | -| Configure ModelCode overflow strategy | `bl deploy overflow` | +| Intent | Command | +| ------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------ | +| Validate / upload training data | `bl dataset validate` / `upload` (`.jsonl` or `.zip`) | +| Dataset list / detail / delete | `bl dataset list` / `get` / `delete` | +| Console dataset groups / discover version and file IDs | `bl dataset groups` → `bl dataset version --dataset-group-id ` (Console auth) | +| Console version detail / import and release state | `bl dataset version --dataset-id ` (Console auth; optional `--include-status`) | +| Console independent deployment services | `bl deploy instances` (Console auth; not capacity instances or replicas) | +| Create a fine-tuning job | `bl finetune text\|audio\|image create` | +| Job list / detail / follow | `bl finetune list` / `get` / `watch` / `logs` | +| Artifacts and export | `bl finetune checkpoints` / `export` | +| Quantize / compress a full model | `bl finetune compress templates` / `create` / `watch` / `get` / `logs` / `list` | +| Cancel / delete a compression job | `bl finetune compress cancel` / `delete` | +| Cancel / delete a fine-tuning job | `bl finetune cancel` / `delete` | +| Reinforcement-learning (RL) training | `bl finetune rl run` / `get` / `list` / `watch` / `logs` / `cancel` / `delete` (sandbox) | +| RL / OPD authorization check and enablement | `bl finetune rl authorize` / `bl finetune opd authorize` (Console auth; `--authorize` to mutate) | +| OPD distillation training | `bl finetune opd run --teacher-model ` / `get` / `watch` / `logs` / `cancel` / `delete` (OpenAPI; forces `pg_opd`; list via `finetune list`) | +| OPD training / resource parameter query | `bl finetune opd params --base-model [--param-type hyper\|resource]` | +| Prepare / check / clean the RL sandbox runtime | `bl finetune runtime prepare` / `doctor` / `clean` | +| Import an external OSS LoRA model | Hand-off: `bl cmodel import *` — hub-owned commands; see `bailian-cli` reference or `bl cmodel --help` | +| Trainable capability lookup | `bl finetune capability` | +| Deploy / lifecycle | `bl deploy text\|audio\|image create`, `list` / `get` / `update` / `scale` / `delete` / `models` | +| Query throughput reservations | `bl deploy list --plan ptu` / `bl deploy get` | +| Query capacity instances | `bl deploy capacity list` / `get` | +| Query / wait for a capacity operation | `bl deploy operation get` / `wait` | +| Buy / scale / renew / release capacity | `bl deploy capacity create` / `scale` / `renew` / `delete` | +| Unsubscribe a prepaid instance | `bl deploy capacity unsubscribe` (builds the billing console refund link) | +| Configure ModelCode overflow strategy | `bl deploy overflow` | The `capacity list` / `get`, `operation get` / `wait` and `deploy list` / `get` queries are read-only. Capacity values are kTPM; effective, configured and target capacities are distinct. `deploy list --status` filters only the fetched page locally, with the server total left unfiltered. `operation get` reports status as data; `operation wait` exits non-zero on failure or timeout and refreshes capacity after success. Use IDs returned by the API; waiting never retries a write. @@ -78,6 +86,45 @@ Console reads are separate from API-key file/deployment queries; the API Key / ` Flags, usage, and examples: see [`reference/`](reference/index.md) or `bl --help` — do not guess flags. +## RL sandbox / OPD distillation training + +`bl finetune rl` submits reinforcement-learning jobs with the DashScope SDK inside an isolated sandbox (credential deny-read, home redirect, whitelist proxy), so the host Python environment is never used. The sandbox is a local black box: on first run it downloads and verifies a fixed CPython + dashscope runtime from a bundled reviewed manifest, caches it, and reuses the cache afterwards. + +``` +1. Authorize bl finetune rl authorize # read-only probe (Console auth) + bl finetune rl authorize --authorize --yes # enable RL (roles must be authorized manually first) +2. Prepare runtime bl finetune runtime prepare # trigger first-run download / verify cache; or set BAILIAN_RL_RUNTIME for dev +3. Check sandbox bl finetune runtime doctor # isolation self-check, exits non-zero on failure +4. Submit job bl finetune rl run --model --train-file --code-dir . --rollout --watch +5. Manage job bl finetune rl get|list|watch|logs|cancel|delete +``` + +`bl finetune opd` submits pure Model OPD distillation jobs (`training_type=pg_opd`) directly from the host via the fine-tunes OpenAPI — no sandbox, no runtime prepare, no rollout/reward functions or function-compute resources. + +For a guided end-to-end OPD workflow (authorize → dataset validation → preflight → billing consent → submit → monitor to terminal state), hand off to skill `bailian-opd` (script-gated preflight and submit; Read its `SKILL.md` if installed, else `bl finetune opd --help` or prompt `bl skill init`). Use the raw commands below when the user asks for a specific step or manages existing jobs. + +``` +1. Authorize bl finetune opd authorize # read-only probe (Console auth) + bl finetune opd authorize --authorize --yes # enable OPD +2. Query params bl finetune opd params --base-model qwen3.5-9b --param-type resource --mtu-spec-code MTU4 +3. Submit job bl finetune opd run --base-model qwen3.5-9b --teacher-model qwen3.8-flash \ + --datasets ./train.jsonl --hyper-parameters-file ./hp.json --resource-config-file ./resource.json --watch +4. Manage job bl finetune opd get|watch|logs|cancel|delete --job-id ft-xxx # list via bl finetune list +5. Artifacts bl finetune checkpoints / export / metrics --job-id ft-xxx # shared finetune commands +``` + +- OPD hyper-parameters are sent exactly as provided (`--hyper-parameters-file` JSON, then `--hp key=value` overrides; `--charge-type` / `--mtu-spec` / `--mtu-count` override `--resource-config-file`). Omitted fields are resolved by the server and the selected teacher's defaults — never fill the parameter API's `recommend_value` into requests: it is not the teacher's effective default (e.g. Flash/Max teacher max length 16385 vs the generic 33792). Exception: `resource_config.charge_type` defaults to `mtu_postpaid` (pg_opd is MTU-only; any other explicit value is a usage error), and `mtu_spec_code` / `mtu_capacity` are required locally (via `--resource-config-file` or `--mtu-spec` / `--mtu-count`) — without them the server persists the job, returns 500, and the job fails at execution time. Their values depend on the student + teacher GPU layout; no defaults are filled. +- The teacher must be a platform-registered model ID compatible with the student; compatibility and MTU capacity (student GPUs + teacher GPUs) are validated server-side and errors surface as-is. Compatible-teacher discovery is not exposed by the parameter API yet. +- OPD local pre-flight (also in `--dry-run`): `opd_teacher_infer_tp` must equal `opd_teacher_n_gpus_per_node` when both are explicit (usage error — teacher Worker template constraint). Warnings never block: student/teacher pair outside the published support matrix (official docs "模型与训练单元", invite-only, region-specific); student GPU layout not fully specified (docs recommend MTU4 × 24 for the default layout — `mtu_capacity` must equal student + teacher GPUs, and the server checks this only after job creation); explicit `max_length` / `max_prompt_length` above an explicit `opd_teacher_max_model_len`. `finetune get` hides the empty legacy `training_files` / `validation_files` for jobs carrying dataset descriptors. +- OPD batch-fit (real submit with local datasets): `batch_size` is the samples-per-step — `floor(samples × n_epochs / batch_size) = 0` is a usage error before upload (the job would fail at execution time on `lr_decay_steps > 0`, after billing starts); provide at least `ceil(batch_size / n_epochs)` samples with headroom. `ppo_mini_batch_size` above `batch_size × n_rollouts` is a usage error when all three are explicit (also in `--dry-run`). When steps are computable, explicit `lr_warmup_steps` / `eval_steps` / `save_steps` above the total step count warn (`OPD_WARMUP_EXCEEDS_STEPS` / `OPD_INTERVAL_EXCEEDS_STEPS`); file-id datasets with explicit batch_size/n_epochs warn `OPD_BATCH_FIT_UNKNOWN`. +- `rl run` / `opd run` are billed (`risk: high`, reason billing); `rl` / `opd` `cancel` / `delete` are destructive. Preview with `--dry-run` (zero network for both), then confirm with the runtime-injected `--yes`; never add `--yes` automatically. +- `authorize` only enables the requested target (RL never auto-enables OPD and vice versa) and never creates service-linked roles — missing roles report `REQUIRES_USER_ACTION` with manual-authorization docs (RL: https://docs.bailian.console.aliyun.com/zh/model-studio/rl-training-overview#%E7%8E%AF%E5%A2%83%E5%87%86%E5%A4%87, OPD: https://docs.bailian.console.aliyun.com/zh/model-studio/opd-training-overview#%E7%8E%AF%E5%A2%83%E5%87%86%E5%A4%87) and block enablement. A failed query reports `UNKNOWN`, never assumed enabled. In CI, permission changes require explicit `--authorize --yes`. +- `rl|opd run --watch` / `rl|opd watch --follow` poll to a terminal state; `--wait-timeout` / `--poll-timeout` only stop waiting (default: no limit), never cancel the cloud job. `watch` without `--follow` is a single non-blocking probe. The RL sandbox is macOS / Linux only — on Windows it fails closed with "Not supported on Windows yet." OPD has no platform restriction. +- OPD job commands accept `--workspace-id` (upload, parameter query, creation and reads use the same workspace). There is no `opd list` — OPD jobs appear in `finetune list` (same records, including non-OPD jobs). +- Runtime downloads fall back to a built-in npmmirror mirror when GitHub is unreachable; set `BAILIAN_RL_PYTHON_MIRROR` to a custom mirror prefix. Where the PyPI CDN stalls, set `BAILIAN_RL_PIP_INDEX_URL` to a stable PyPI mirror (e.g. `https://pypi.tuna.tsinghua.edu.cn/simple/` or `https://mirrors.aliyun.com/pypi/simple/`). Mirrors lag PyPI — if a mirror lacks a pinned version, pip fails closed with `No matching distribution found for X==ver`; use a fresher mirror or the default PyPI. Integrity is always verified against the reviewed SHA256 / per-package hashes regardless of source. +- Sandbox artifact lifecycle: each invocation's task directory is disposed when the invocation ends (success / failure / timeout alike — nothing is retained for retries). Crash orphans older than 24h and superseded runtime versions are reclaimed by `bl finetune runtime clean` (local only, no auth; destructive — preview the remove/keep plan with `--dry-run`, then confirm with `--yes`; `--ttl-hours` tunes the orphan threshold). `runtime prepare` also prunes orphaned runs as a side effect. The current baseline runtime, `BAILIAN_RL_RUNTIME` dev directories and the content-addressed download cache are never touched. +- Flags, usage, and examples: see [`reference/finetune.md`](reference/finetune.md) or `bl finetune rl --help` / `bl finetune opd --help` — do not guess flags. + ## Quick examples ```bash @@ -91,6 +138,11 @@ bl finetune compress templates --model my-qwen-sft bl finetune compress create --model my-qwen-sft --template-id quant-xxx --suffix int4 bl finetune compress watch --job-id quant-xxx --follow bl deploy text create --model-name --display-name my-svc +# RL sandbox training (macOS / Linux) +bl finetune runtime prepare +bl finetune rl run --model qwen3.5-9b --train-file ./data/train.jsonl --code-dir . --rollout functions.rollout.MyRollout --charge-type mtu_postpaid --mtu-spec MTU4 --mtu-count 24 --watch +# OPD distillation (host OpenAPI, no sandbox) +bl finetune opd run --base-model qwen3.5-9b --teacher-model qwen3.5-397b-a17b --datasets ./data/train.jsonl --charge-type mtu_postpaid --mtu-spec MTU4 --mtu-count 24 --watch ``` ## Common hand-offs diff --git a/skills/bailian-finetune/reference/finetune.md b/skills/bailian-finetune/reference/finetune.md index afef8bcd..5ded1589 100644 --- a/skills/bailian-finetune/reference/finetune.md +++ b/skills/bailian-finetune/reference/finetune.md @@ -28,8 +28,27 @@ Index: [index.md](index.md) | `bl finetune list` | API Key | List fine-tune jobs | | `bl finetune logs` | API Key | Fetch training logs for a fine-tune job | | `bl finetune metrics` | API Key | Query the training metrics of a fine-tune job | +| `bl finetune opd authorize` | Console | Check and authorize OPD distillation access (whitelist, service roles, enablement) | +| `bl finetune opd cancel` | API Key | Cancel a running OPD job | +| `bl finetune opd delete` | API Key | Delete an OPD job record | +| `bl finetune opd get` | API Key | Get an OPD job | +| `bl finetune opd logs` | API Key | Fetch OPD job logs | +| `bl finetune opd params` | API Key | Query OPD (pg_opd) training / resource parameter configuration for a student model | +| `bl finetune opd run` | API Key | Submit a pure Model OPD distillation job (pg_opd) via the fine-tunes OpenAPI | +| `bl finetune opd watch` | API Key | Probe an OPD job's status (default: single non-blocking fetch). Pass --follow to poll until terminal. | | `bl finetune params` | API Key | Query the training hyper-parameter configuration for a base model | | `bl finetune price` | Console | Estimate the training cost for a fine-tune job (token billing) | +| `bl finetune rl authorize` | Console | Check and authorize reinforcement-learning access (whitelist, service roles, enablement) | +| `bl finetune rl cancel` | API Key | Cancel a running RL job | +| `bl finetune rl delete` | API Key | Delete an RL job record | +| `bl finetune rl get` | API Key | Get an RL job | +| `bl finetune rl list` | API Key | List RL jobs | +| `bl finetune rl logs` | API Key | Fetch RL job logs | +| `bl finetune rl run` | API Key | Submit a reinforcement-learning training job | +| `bl finetune rl watch` | API Key | Probe an RL job's status (default: single non-blocking fetch). Pass --follow to poll until terminal. | +| `bl finetune runtime clean` | No Auth | Reclaim orphaned sandbox run directories and superseded runtime versions | +| `bl finetune runtime doctor` | No Auth | Check the RL runtime and sandbox isolation (credential deny, home redirect, SDK import) | +| `bl finetune runtime prepare` | No Auth | Prepare the managed Python/SDK runtime used by RL and OPD jobs | | `bl finetune text create` | API Key | Create a text model fine-tune job (sft \| sft-lora \| dpo \| dpo-lora \| cpt) | | `bl finetune video create` | API Key | Create a video generation model fine-tune job (Wan i2v/kf2v, efficient_sft) | | `bl finetune watch` | API Key | Probe a fine-tune job's status (default: single non-blocking fetch). Pass --follow to poll until terminal. | @@ -757,6 +776,342 @@ bl finetune metrics --job-id ft-xxx --output json bl finetune metrics --job-id ft-xxx --dry-run ``` +### `bl finetune opd authorize` + +| Field | Value | +| ------------------ | ----------------------------------------------------------------------------------------------------------------- | +| **Name** | `finetune opd authorize` | +| **Description** | Check and authorize OPD distillation access (whitelist, service roles, enablement) | +| **Authentication** | Console | +| **Usage** | `bl finetune opd authorize [--authorize]` | +| **Risk** | `high` | +| **Risk message** | With --authorize this enables the OPD training mode for your account. The CLI never creates service-linked roles. | + +> **Agent safety:** Never add `--yes` automatically. On `type="requires_confirmation"`, stop and ask for explicit user confirmation of the same action and scope. + +#### Flags + +| Flag | Type | Required | Description | +| ------------------------------ | ------ | -------- | ----------------------------------------------------------------------------------------------- | +| `--authorize` | switch | no | Permit enabling OPD once the service roles are manually authorized (read-only probe without it) | +| `--yes` | switch | no | Confirm this high-risk operation | +| `--console-region ` | string | no | Console gateway region (e.g. cn-beijing, ap-southeast-1) | +| `--console-site ` | string | no | Console site: domestic, international | +| `--console-switch-agent ` | number | no | Switch agent UID for delegated access | +| `--workspace-id ` | string | no | Workspace ID (env: BAILIAN_WORKSPACE_ID) | + +#### Notes + +- Service-linked roles must be authorized manually first (https://docs.bailian.console.aliyun.com/zh/model-studio/opd-training-overview#%E7%8E%AF%E5%A2%83%E5%87%86%E5%A4%87); missing roles report REQUIRES_USER_ACTION and block enablement. +- Without --authorize this is a read-only probe. Each capability reports READY / MISSING / UNKNOWN / REQUIRES_USER_ACTION / FAILED; a failed query is UNKNOWN, never assumed enabled. +- Only OPD is enabled; RL is never auto-enabled. In CI pass --authorize --yes to permit changes; --yes alone does not expand permissions. +- A selected workspace is resolved to its Console identity before business requests, overriding --console-switch-agent for this invocation only. Resolution failure stops the query; dry-run only previews this step. + +#### Examples + +```bash +bl finetune opd authorize +``` + +```bash +# Only after explicit user confirmation: +bl finetune opd authorize --authorize --yes +``` + +```bash +bl finetune opd authorize --dry-run +``` + +### `bl finetune opd cancel` + +| Field | Value | +| ------------------ | ------------------------------------------------------- | +| **Name** | `finetune opd cancel` | +| **Description** | Cancel a running OPD job | +| **Authentication** | API Key | +| **Usage** | `bl finetune opd cancel --job-id ` | +| **Risk** | `high` | +| **Risk message** | This cancels the running OPD job; progress may be lost. | + +> **Agent safety:** Never add `--yes` automatically. On `type="requires_confirmation"`, stop and ask for explicit user confirmation of the same action and scope. + +#### Flags + +| Flag | Type | Required | Description | +| --------------------- | ------ | -------- | ---------------------------------------------------------------------------------------------- | +| `--job-id ` | string | yes | OPD job ID (required) | +| `--workspace-id ` | string | no | Workspace ID sent as X-DashScope-WorkSpace; omit when your API key is already workspace-bound. | +| `--yes` | switch | no | Confirm this high-risk operation | +| `--api-key ` | string | no | API key | +| `--base-url ` | string | no | API base URL | + +#### Examples + +```bash +bl finetune opd cancel --job-id ft-xxx +``` + +```bash +bl finetune opd cancel --job-id ft-xxx --dry-run +``` + +```bash +# Only after explicit user confirmation: +bl finetune opd cancel --job-id ft-xxx --yes +``` + +### `bl finetune opd delete` + +| Field | Value | +| ------------------ | ----------------------------------------------------------------- | +| **Name** | `finetune opd delete` | +| **Description** | Delete an OPD job record | +| **Authentication** | API Key | +| **Usage** | `bl finetune opd delete --job-id ` | +| **Risk** | `high` | +| **Risk message** | This permanently deletes the OPD job record and cannot be undone. | + +> **Agent safety:** Never add `--yes` automatically. On `type="requires_confirmation"`, stop and ask for explicit user confirmation of the same action and scope. + +#### Flags + +| Flag | Type | Required | Description | +| --------------------- | ------ | -------- | ---------------------------------------------------------------------------------------------- | +| `--job-id ` | string | yes | OPD job ID (required) | +| `--workspace-id ` | string | no | Workspace ID sent as X-DashScope-WorkSpace; omit when your API key is already workspace-bound. | +| `--yes` | switch | no | Confirm this high-risk operation | +| `--api-key ` | string | no | API key | +| `--base-url ` | string | no | API base URL | + +#### Notes + +- Deletes the job record via the fine-tunes endpoint directly in the host (no sandbox runtime needed); RL and OPD jobs share this backend. + +#### Examples + +```bash +bl finetune opd delete --job-id ft-xxx +``` + +```bash +bl finetune opd delete --job-id ft-xxx --dry-run +``` + +```bash +# Only after explicit user confirmation: +bl finetune opd delete --job-id ft-xxx --yes +``` + +### `bl finetune opd get` + +| Field | Value | +| ------------------ | ----------------------------------- | +| **Name** | `finetune opd get` | +| **Description** | Get an OPD job | +| **Authentication** | API Key | +| **Usage** | `bl finetune opd get --job-id ` | + +#### Flags + +| Flag | Type | Required | Description | +| --------------------- | ------ | -------- | ---------------------------------------------------------------------------------------------- | +| `--job-id ` | string | yes | OPD job ID (required) | +| `--workspace-id ` | string | no | Workspace ID sent as X-DashScope-WorkSpace; omit when your API key is already workspace-bound. | +| `--api-key ` | string | no | API key | +| `--base-url ` | string | no | API base URL | + +#### Notes + +- Returns the raw fine-tunes OpenAPI response (teacher_model, training/validation datasets, MTU spec and capacity included). No sandbox runtime needed. + +#### Examples + +```bash +bl finetune opd get --job-id ft-xxx +``` + +### `bl finetune opd logs` + +| Field | Value | +| ------------------ | ------------------------------------------------------------------- | +| **Name** | `finetune opd logs` | +| **Description** | Fetch OPD job logs | +| **Authentication** | API Key | +| **Usage** | `bl finetune opd logs --job-id [--page ] [--page-size ]` | + +#### Flags + +| Flag | Type | Required | Description | +| --------------------- | ------ | -------- | ---------------------------------------------------------------------------------------------- | +| `--job-id ` | string | yes | OPD job ID (required) | +| `--workspace-id ` | string | no | Workspace ID sent as X-DashScope-WorkSpace; omit when your API key is already workspace-bound. | +| `--page ` | number | no | Page number | +| `--page-size ` | number | no | Lines per page | +| `--api-key ` | string | no | API key | +| `--base-url ` | string | no | API base URL | + +#### Examples + +```bash +bl finetune opd logs --job-id ft-xxx +``` + +```bash +bl finetune opd logs --job-id ft-xxx --page 1 --page-size 100 +``` + +### `bl finetune opd params` + +| Field | Value | +| ------------------ | ----------------------------------------------------------------------------------------------------------------------------- | +| **Name** | `finetune opd params` | +| **Description** | Query OPD (pg_opd) training / resource parameter configuration for a student model | +| **Authentication** | API Key | +| **Usage** | `bl finetune opd params --base-model [--param-type ] [--mtu-spec-code ] [--workspace-id ]` | + +#### Flags + +| Flag | Type | Required | Description | +| -------------------------------- | ------ | -------- | ---------------------------------------------------------------------------------------------- | +| `--base-model ` | string | yes | Student base model to query OPD parameters for (e.g. qwen3.5-9b) | +| `--param-type ` | string | no | Parameter group: hyper (training) \| resource (GPUs / teacher). Omit to return all groups. | +| `--mtu-spec-code ` | string | no | MTU spec code for resource-group queries (e.g. MTU4) | +| `--workspace-id ` | string | no | Workspace ID sent as X-DashScope-WorkSpace; omit when your API key is already workspace-bound. | +| `--api-key ` | string | no | API key | +| `--base-url ` | string | no | API base URL | + +#### Notes + +- Queries GET /api/v1/fine-tunes/fine-tunes-params with training_type=pg_opd. Entries keep server field names verbatim (recommend_value, defaultValue, data_range, ...). +- recommend_value is NOT the selected teacher's effective default: external teachers (e.g. Flash/Max) carry their own default resources resolved server-side at submit time. Use this output for ranges/enums, not as a recipe to fill into requests. +- Compatible-teacher discovery is not exposed by the parameter API yet; teacher/student compatibility is validated server-side when submitting via finetune opd run. + +#### Examples + +```bash +bl finetune opd params --base-model qwen3.5-9b +``` + +```bash +bl finetune opd params --base-model qwen3.5-9b --param-type hyper +``` + +```bash +bl finetune opd params --base-model qwen3.5-9b --param-type resource --mtu-spec-code MTU4 +``` + +```bash +bl finetune opd params --base-model qwen3.5-9b --dry-run +``` + +### `bl finetune opd run` + +| Field | Value | +| ------------------ | -------------------------------------------------------------------------------------------- | +| **Name** | `finetune opd run` | +| **Description** | Submit a pure Model OPD distillation job (pg_opd) via the fine-tunes OpenAPI | +| **Authentication** | API Key | +| **Usage** | `bl finetune opd run --base-model --teacher-model --datasets [flags]` | +| **Risk** | `high` | +| **Risk message** | This creates a billed OPD training job that consumes compute resources. | + +> **Agent safety:** Never add `--yes` automatically. On `type="requires_confirmation"`, stop and ask for explicit user confirmation of the same action and scope. + +#### Flags + +| Flag | Type | Required | Description | +| -------------------------------- | ------ | -------- | ---------------------------------------------------------------------------------------------------------------------------- | +| `--base-model ` | string | yes | Student base model ID (e.g. qwen3.5-9b) | +| `--teacher-model ` | string | yes | Platform-registered teacher model ID (required; no arbitrary URLs or keys) | +| `--datasets ` | string | yes | Comma-separated dataset file IDs or local .jsonl paths. Local paths are validated and uploaded first. | +| `--validations ` | string | no | Comma-separated validation file IDs or local paths (auto-uploaded like --datasets). | +| `--job-name ` | string | no | Training job display name (job_name) | +| `--hyper-parameters-file ` | string | no | JSON file of training + resource hyper-parameters (keys map 1:1 to hyper_parameters). --hp overrides it. | +| `--resource-config-file ` | string | no | JSON file of resource_config (charge_type / mtu_spec_code / mtu_capacity). Resource flags override it. | +| `--hp ` | array | no | Hyper-parameter override (repeatable, parsed by type); beats the JSON file | +| `--charge-type ` | string | no | resource_config.charge_type; pg_opd only supports mtu_postpaid (default) | +| `--mtu-spec ` | string | no | resource_config.mtu_spec_code (e.g. MTU4); required, via this flag or the resource file | +| `--mtu-count ` | number | no | resource_config.mtu_capacity (student GPUs + teacher GPUs); required, via this flag or the resource file | +| `--workspace-id ` | string | no | Workspace for upload, parameter query, creation and reads (X-DashScope-WorkSpace). Omit when the API key is workspace-bound. | +| `--watch` | switch | no | Wait for the job to reach a terminal state | +| `--wait-timeout ` | number | no | Maximum seconds to poll with --watch (default: no limit; does not cancel the cloud job) | +| `--yes` | switch | no | Confirm this high-risk operation | +| `--api-key ` | string | no | API key | +| `--base-url ` | string | no | API base URL | + +#### Notes + +- Forces training_type=pg_opd. Pure Model OPD needs no rollout / reward functions and creates no function-compute resources. +- Submits directly from the host via the fine-tunes OpenAPI (no sandbox runtime). Query commands: finetune opd get/watch/logs/cancel/delete; list/checkpoints/export/metrics use the shared finetune commands. +- Hyper-parameters are sent exactly as provided (JSON file, then --hp overrides). Omitted fields are resolved by the server and the selected teacher's defaults — the CLI never fills parameter-API recommend_value, which is not the teacher's effective default. +- The teacher must be a platform-registered model ID compatible with the student; compatibility and resource capacity are validated server-side and errors are surfaced as-is. +- mtu_capacity must equal student GPUs + teacher GPUs. The published docs recommend MTU4 x 24 for the default layout; custom layouts must be computed yourself (the server checks capacity after job creation). Supported pairs and sizing: https://docs.bailian.console.aliyun.com/zh/model-studio/opd-training-overview#%E6%A8%A1%E5%9E%8B%E4%B8%8E%E8%AE%AD%E7%BB%83%E5%8D%95%E5%85%83. +- batch_size is the samples-per-step: floor(training samples × n_epochs / batch_size) must be ≥ 1, otherwise the job fails at execution time after billing starts (lr_decay_steps > 0). With local datasets the CLI rejects zero-step configurations before upload; ppo_mini_batch_size must not exceed batch_size × n_rollouts. +- Timing out with --watch stops waiting only; it does not cancel the cloud job. + +#### Examples + +```bash +bl finetune opd run --base-model qwen3.5-9b --teacher-model qwen3.8-flash --datasets file-xxx --validations file-yyy --hyper-parameters-file ./hp.json --resource-config-file ./resource.json --dry-run +``` + +```bash +bl finetune opd run --base-model qwen3.5-9b --teacher-model qwen3.5-397b-a17b --datasets ./train.jsonl --hp n_epochs=1 --hp batch_size=64 --charge-type mtu_postpaid --mtu-spec MTU4 --mtu-count 24 --watch +``` + +```bash +bl finetune opd run --base-model qwen3.5-9b --teacher-model qwen3.8-flash --datasets file-xxx --workspace-id ws-xxx +``` + +### `bl finetune opd watch` + +| Field | Value | +| ------------------ | ----------------------------------------------------------------------------------------------------- | +| **Name** | `finetune opd watch` | +| **Description** | Probe an OPD job's status (default: single non-blocking fetch). Pass --follow to poll until terminal. | +| **Authentication** | API Key | +| **Usage** | `bl finetune opd watch --job-id [--follow] [--interval ] [--poll-timeout ]` | + +#### Flags + +| Flag | Type | Required | Description | +| ---------------------- | ------ | -------- | -------------------------------------------------------------------------------------------------------------------------- | +| `--job-id ` | string | yes | OPD job ID (required) | +| `--workspace-id ` | string | no | Workspace ID sent as X-DashScope-WorkSpace; omit when your API key is already workspace-bound. | +| `--follow` | switch | no | Block and poll until a terminal state. Without it, a single status probe is performed and the command returns immediately. | +| `--interval ` | number | no | Seconds between polls with --follow (default: 10, min: 1). Ignored without --follow. | +| `--poll-timeout ` | number | no | With --follow, stop polling after this many seconds (default: no limit). Ignored without --follow. | +| `--api-key ` | string | no | API key | +| `--base-url ` | string | no | API base URL | + +#### Notes + +- Default (no --follow) is a NON-BLOCKING single status probe: one fetch, then return immediately. The caller owns the polling cadence, so the CLI never holds the terminal. +- A terminal FAILED/CANCELED status raises a normal CLI error (non-zero exit); SUCCEEDED or still-running returns 0. With --follow, exceeding --poll-timeout raises a timeout error but does not cancel the cloud job. +- Queries the fine-tunes endpoint directly in the host (no sandbox runtime needed). For per-step training output use `finetune opd logs`. + +#### Examples + +```bash +bl finetune opd watch --job-id ft-xxx +``` + +```bash +bl finetune opd watch --job-id ft-xxx --output json +``` + +```bash +bl finetune opd watch --job-id ft-xxx --follow +``` + +```bash +bl finetune opd watch --job-id ft-xxx --follow --interval 5 +``` + +```bash +bl finetune opd watch --job-id ft-xxx --follow --poll-timeout 3600 +``` + ### `bl finetune params` | Field | Value | @@ -859,6 +1214,436 @@ bl finetune price --base-model qwen3-8b --datasets file-ft-xxx,file-ft-yyy --n-e bl finetune price --base-model qwen3-8b --datasets file-ft-xxx --training-type cpt ``` +### `bl finetune rl authorize` + +| Field | Value | +| ------------------ | ---------------------------------------------------------------------------------------------------------------- | +| **Name** | `finetune rl authorize` | +| **Description** | Check and authorize reinforcement-learning access (whitelist, service roles, enablement) | +| **Authentication** | Console | +| **Usage** | `bl finetune rl authorize [--authorize]` | +| **Risk** | `high` | +| **Risk message** | With --authorize this enables the RL training mode for your account. The CLI never creates service-linked roles. | + +> **Agent safety:** Never add `--yes` automatically. On `type="requires_confirmation"`, stop and ask for explicit user confirmation of the same action and scope. + +#### Flags + +| Flag | Type | Required | Description | +| ------------------------------ | ------ | -------- | ---------------------------------------------------------------------------------------------- | +| `--authorize` | switch | no | Permit enabling RL once the service roles are manually authorized (read-only probe without it) | +| `--yes` | switch | no | Confirm this high-risk operation | +| `--console-region ` | string | no | Console gateway region (e.g. cn-beijing, ap-southeast-1) | +| `--console-site ` | string | no | Console site: domestic, international | +| `--console-switch-agent ` | number | no | Switch agent UID for delegated access | +| `--workspace-id ` | string | no | Workspace ID (env: BAILIAN_WORKSPACE_ID) | + +#### Notes + +- Service-linked roles must be authorized manually first (https://docs.bailian.console.aliyun.com/zh/model-studio/rl-training-overview#%E7%8E%AF%E5%A2%83%E5%87%86%E5%A4%87); missing roles report REQUIRES_USER_ACTION and block enablement. +- Without --authorize this is a read-only probe. Each capability reports READY / MISSING / UNKNOWN / REQUIRES_USER_ACTION / FAILED; a failed query is UNKNOWN, never assumed enabled. +- Only RL is enabled; OPD is never auto-enabled. In CI pass --authorize --yes to permit changes; --yes alone does not expand permissions. +- A selected workspace is resolved to its Console identity before business requests, overriding --console-switch-agent for this invocation only. Resolution failure stops the query; dry-run only previews this step. + +#### Examples + +```bash +bl finetune rl authorize +``` + +```bash +# Only after explicit user confirmation: +bl finetune rl authorize --authorize --yes +``` + +```bash +bl finetune rl authorize --dry-run +``` + +### `bl finetune rl cancel` + +| Field | Value | +| ------------------ | ------------------------------------------------------ | +| **Name** | `finetune rl cancel` | +| **Description** | Cancel a running RL job | +| **Authentication** | API Key | +| **Usage** | `bl finetune rl cancel --job-id ` | +| **Risk** | `high` | +| **Risk message** | This cancels the running RL job; progress may be lost. | + +> **Agent safety:** Never add `--yes` automatically. On `type="requires_confirmation"`, stop and ask for explicit user confirmation of the same action and scope. + +#### Flags + +| Flag | Type | Required | Description | +| ------------------ | ------ | -------- | -------------------------------- | +| `--job-id ` | string | yes | RL job ID (required) | +| `--yes` | switch | no | Confirm this high-risk operation | +| `--api-key ` | string | no | API key | +| `--base-url ` | string | no | API base URL | + +#### Examples + +```bash +bl finetune rl cancel --job-id rl-xxx +``` + +```bash +bl finetune rl cancel --job-id rl-xxx --dry-run +``` + +```bash +# Only after explicit user confirmation: +bl finetune rl cancel --job-id rl-xxx --yes +``` + +### `bl finetune rl delete` + +| Field | Value | +| ------------------ | ---------------------------------------------------------------- | +| **Name** | `finetune rl delete` | +| **Description** | Delete an RL job record | +| **Authentication** | API Key | +| **Usage** | `bl finetune rl delete --job-id ` | +| **Risk** | `high` | +| **Risk message** | This permanently deletes the RL job record and cannot be undone. | + +> **Agent safety:** Never add `--yes` automatically. On `type="requires_confirmation"`, stop and ask for explicit user confirmation of the same action and scope. + +#### Flags + +| Flag | Type | Required | Description | +| ------------------ | ------ | -------- | -------------------------------- | +| `--job-id ` | string | yes | RL job ID (required) | +| `--yes` | switch | no | Confirm this high-risk operation | +| `--api-key ` | string | no | API key | +| `--base-url ` | string | no | API base URL | + +#### Notes + +- Deletes the job record via the fine-tunes endpoint directly in the host (no sandbox runtime needed); RL and OPD jobs share this backend. + +#### Examples + +```bash +bl finetune rl delete --job-id rl-xxx +``` + +```bash +bl finetune rl delete --job-id rl-xxx --dry-run +``` + +```bash +# Only after explicit user confirmation: +bl finetune rl delete --job-id rl-xxx --yes +``` + +### `bl finetune rl get` + +| Field | Value | +| ------------------ | ---------------------------------- | +| **Name** | `finetune rl get` | +| **Description** | Get an RL job | +| **Authentication** | API Key | +| **Usage** | `bl finetune rl get --job-id ` | + +#### Flags + +| Flag | Type | Required | Description | +| ------------------ | ------ | -------- | -------------------- | +| `--job-id ` | string | yes | RL job ID (required) | +| `--api-key ` | string | no | API key | +| `--base-url ` | string | no | API base URL | + +#### Examples + +```bash +bl finetune rl get --job-id rl-xxx +``` + +### `bl finetune rl list` + +| Field | Value | +| ------------------ | ----------------------------------------------- | +| **Name** | `finetune rl list` | +| **Description** | List RL jobs | +| **Authentication** | API Key | +| **Usage** | `bl finetune rl list [--page ] [--size ]` | + +#### Flags + +| Flag | Type | Required | Description | +| ------------------ | ------ | -------- | ------------ | +| `--page ` | number | no | Page number | +| `--size ` | number | no | Page size | +| `--api-key ` | string | no | API key | +| `--base-url ` | string | no | API base URL | + +#### Notes + +- RL and OPD jobs share the same job backend; this lists the same job records as `finetune list` (including OPD jobs). + +#### Examples + +```bash +bl finetune rl list --page 1 --size 20 +``` + +### `bl finetune rl logs` + +| Field | Value | +| ------------------ | ---------------------------------------------------------------- | +| **Name** | `finetune rl logs` | +| **Description** | Fetch RL job logs | +| **Authentication** | API Key | +| **Usage** | `bl finetune rl logs --job-id [--offset ] [--lines ]` | + +#### Flags + +| Flag | Type | Required | Description | +| ------------------ | ------ | -------- | -------------------- | +| `--job-id ` | string | yes | RL job ID (required) | +| `--offset ` | number | no | Log offset | +| `--lines ` | number | no | Number of log lines | +| `--api-key ` | string | no | API key | +| `--base-url ` | string | no | API base URL | + +#### Examples + +```bash +bl finetune rl logs --job-id rl-xxx +``` + +```bash +bl finetune rl logs --job-id rl-xxx --offset 0 --lines 100 +``` + +### `bl finetune rl run` + +| Field | Value | +| ------------------ | ---------------------------------------------------------------------- | +| **Name** | `finetune rl run` | +| **Description** | Submit a reinforcement-learning training job | +| **Authentication** | API Key | +| **Usage** | `bl finetune rl run --model [flags]` | +| **Risk** | `high` | +| **Risk message** | This creates a billed RL training job that consumes compute resources. | + +> **Agent safety:** Never add `--yes` automatically. On `type="requires_confirmation"`, stop and ask for explicit user confirmation of the same action and scope. + +#### Flags + +| Flag | Type | Required | Description | +| --------------------------------------- | ------ | -------- | --------------------------------------------------------------------------------------- | +| `--config-file ` | string | no | Optional job YAML file; explicit CLI flags override it | +| `--name ` | string | no | Job name | +| `--model ` | string | no | Base model ID | +| `--train-file ` | array | no | Local training file (repeatable) | +| `--train-file-id ` | array | no | Uploaded training file ID (repeatable) | +| `--validation-file ` | array | no | Local validation file (repeatable) | +| `--validation-file-id ` | array | no | Uploaded validation file ID (repeatable) | +| `--code-dir ` | string | no | Function package source directory | +| `--requirements ` | string | no | Requirements path relative to the code dir | +| `--include ` | array | no | Package include glob (repeatable) | +| `--exclude ` | array | no | Package exclude glob (repeatable) | +| `--rollout ` | string | no | Rollout function classpath | +| `--reward ` | array | no | Reward function (repeatable) | +| `--clear-functions` | switch | no | Clear functions defined in the YAML | +| `--function-timeout ` | array | no | Function timeout in seconds (repeatable) | +| `--function-runtime ` | array | no | Function runtime field (repeatable) | +| `--reward-weight ` | array | no | Reward weight (repeatable) | +| `--reward-metric ` | array | no | Reward metric weight (repeatable) | +| `--function-env ` | array | no | Function environment variable (repeatable) | +| `--hp ` | array | no | Hyper-parameter (repeatable, parsed by type) | +| `--charge-type ` | string | no | Resource charge type | +| `--mtu-spec ` | string | no | MTU spec code | +| `--mtu-count ` | number | no | MTU capacity | +| `--instance-id ` | string | no | Prepaid resource instance ID | +| `--set ` | array | no | Top-level spec override (repeatable, JSON value) | +| `--watch` | switch | no | Wait for the job to reach a terminal state | +| `--wait-timeout ` | number | no | Maximum seconds to poll with --watch (default: no limit; does not cancel the cloud job) | +| `--install-runtime` | switch | no | Allow first-time managed runtime preparation | +| `--yes` | switch | no | Confirm this high-risk operation | +| `--api-key ` | string | no | API key | +| `--base-url ` | string | no | API base URL | + +#### Notes + +- Runs inside an isolated sandbox. Prepare the runtime first with `finetune runtime prepare`, or pass --install-runtime. +- Timing out with --watch stops waiting only; it does not cancel the cloud job. + +#### Examples + +```bash +bl finetune rl run --model qwen3.5-9b --train-file ./data/train.jsonl --code-dir . --rollout functions.rollout.MyRollout --charge-type mtu_postpaid --mtu-spec MTU4 --mtu-count 24 --watch +``` + +```bash +bl finetune rl run --config-file job.yaml --watch +``` + +```bash +bl finetune rl run --model qwen3.5-9b --train-file ./data/train.jsonl --dry-run +``` + +### `bl finetune rl watch` + +| Field | Value | +| ------------------ | ---------------------------------------------------------------------------------------------------- | +| **Name** | `finetune rl watch` | +| **Description** | Probe an RL job's status (default: single non-blocking fetch). Pass --follow to poll until terminal. | +| **Authentication** | API Key | +| **Usage** | `bl finetune rl watch --job-id [--follow] [--interval ] [--poll-timeout ]` | + +#### Flags + +| Flag | Type | Required | Description | +| ---------------------- | ------ | -------- | -------------------------------------------------------------------------------------------------------------------------- | +| `--job-id ` | string | yes | RL job ID (required) | +| `--follow` | switch | no | Block and poll until a terminal state. Without it, a single status probe is performed and the command returns immediately. | +| `--interval ` | number | no | Seconds between polls with --follow (default: 10, min: 1). Ignored without --follow. | +| `--poll-timeout ` | number | no | With --follow, stop polling after this many seconds (default: no limit). Ignored without --follow. | +| `--api-key ` | string | no | API key | +| `--base-url ` | string | no | API base URL | + +#### Notes + +- Default (no --follow) is a NON-BLOCKING single status probe: one fetch, then return immediately. The caller owns the polling cadence, so the CLI never holds the terminal. +- A terminal FAILED/CANCELED status raises a normal CLI error (non-zero exit); SUCCEEDED or still-running returns 0. With --follow, exceeding --poll-timeout raises a timeout error but does not cancel the cloud job. +- Queries the fine-tunes endpoint directly in the host (no sandbox runtime needed). For per-step training output use `finetune rl logs`. + +#### Examples + +```bash +bl finetune rl watch --job-id ft-xxx +``` + +```bash +bl finetune rl watch --job-id ft-xxx --output json +``` + +```bash +bl finetune rl watch --job-id ft-xxx --follow +``` + +```bash +bl finetune rl watch --job-id ft-xxx --follow --interval 5 +``` + +```bash +bl finetune rl watch --job-id ft-xxx --follow --poll-timeout 3600 +``` + +### `bl finetune runtime clean` + +| Field | Value | +| ------------------ | ------------------------------------------------------------------------------------------------------- | +| **Name** | `finetune runtime clean` | +| **Description** | Reclaim orphaned sandbox run directories and superseded runtime versions | +| **Authentication** | No Auth | +| **Usage** | `bl finetune runtime clean [--ttl-hours ] [--dry-run]` | +| **Risk** | `high` | +| **Risk message** | This permanently deletes orphaned run directories and superseded runtime versions; it cannot be undone. | + +> **Agent safety:** Never add `--yes` automatically. On `type="requires_confirmation"`, stop and ask for explicit user confirmation of the same action and scope. + +#### Flags + +| Flag | Type | Required | Description | +| --------------------- | ------ | -------- | ------------------------------------------------------- | +| `--ttl-hours ` | number | no | Age threshold for orphaned run directories (default 24) | +| `--yes` | switch | no | Confirm this high-risk operation | + +#### Notes + +- Normal runs are disposed automatically when the invocation ends; only crash leftovers (older than the TTL) remain under runs/. Superseded runtime versions under runtimes/rl/ are reclaimed, keeping only the current reviewed baseline. +- Never touches the current baseline runtime, BAILIAN_RL_RUNTIME development directories, or the content-addressed download cache. Local only: no credentials, no cloud resources. +- Deletion is irreversible; preview the remove/keep plan with --dry-run first. Runtime reclamation requires a bundled manifest entry for this platform; otherwise only runs are pruned. + +#### Examples + +```bash +bl finetune runtime clean --dry-run +``` + +```bash +bl finetune runtime clean --ttl-hours 48 +``` + +```bash +bl finetune runtime clean +``` + +### `bl finetune runtime doctor` + +| Field | Value | +| ------------------ | --------------------------------------------------------------------------------------- | +| **Name** | `finetune runtime doctor` | +| **Description** | Check the RL runtime and sandbox isolation (credential deny, home redirect, SDK import) | +| **Authentication** | No Auth | +| **Usage** | `bl finetune runtime doctor` | + +#### Flags + +_No command-specific flags._ + +#### Notes + +- Read-only self-check; it creates no cloud resources. Required checks must pass; when the runtime is missing they are skipped (not treated as passed) and the command exits non-zero. +- Enhanced hardening (kernel network enforcement, process tree, memory) degrades with a notice when unavailable and does not fail the overall check. +- Host network reachability (API / runtime download / PyPI hosts) is probed as an advisory check: blocked hosts degrade with guidance (agent sandboxes often block outbound network) and do not fail the overall check. + +#### Examples + +```bash +bl finetune runtime doctor +``` + +```bash +bl finetune runtime doctor --dry-run +``` + +```bash +bl finetune runtime doctor --output json +``` + +### `bl finetune runtime prepare` + +| Field | Value | +| ------------------ | -------------------------------------------------------------- | +| **Name** | `finetune runtime prepare` | +| **Description** | Prepare the managed Python/SDK runtime used by RL and OPD jobs | +| **Authentication** | No Auth | +| **Usage** | `bl finetune runtime prepare [--manifest ]` | + +#### Flags + +| Flag | Type | Required | Description | +| ------------------- | ------ | -------- | -------------------------------------------------------------------------- | +| `--manifest ` | string | no | Optional runtime manifest file (defaults to the bundled reviewed manifest) | + +#### Notes + +- Downloads and verifies the runtime locally; it never creates a training job. Set BAILIAN_RL_RUNTIME to a local dashscope Python directory to reuse a development runtime instead. +- On an unsupported platform this reports RUNTIME_UNAVAILABLE; no cloud resources are created. +- CPython downloads fall back to a built-in npmmirror mirror when GitHub is unreachable; set BAILIAN_RL_PYTHON_MIRROR to a custom mirror prefix. Integrity is always verified against the reviewed SHA256 regardless of source. +- In regions where the PyPI CDN stalls, set BAILIAN_RL_PIP_INDEX_URL to a stable PyPI mirror (e.g. https://pypi.tuna.tsinghua.edu.cn/simple/ or https://mirrors.aliyun.com/pypi/simple/); pip still verifies every package hash via --require-hashes. Mirrors lag PyPI: if a mirror lacks a pinned version, pip reports 'No matching distribution found for X==ver' — use a fresher mirror or the default PyPI. +- Prepare also reclaims orphaned run directories older than 24 hours (crash leftovers); normal runs are disposed automatically when the invocation ends. Use runtime clean to preview or reclaim superseded runtime versions. + +#### Examples + +```bash +bl finetune runtime prepare +``` + +```bash +bl finetune runtime prepare --manifest ./runtime-manifest.json +``` + +```bash +bl finetune runtime prepare --dry-run +``` + ### `bl finetune text create` | Field | Value | diff --git a/skills/bailian-finetune/reference/index.md b/skills/bailian-finetune/reference/index.md index 0e94c76d..0d4351ed 100644 --- a/skills/bailian-finetune/reference/index.md +++ b/skills/bailian-finetune/reference/index.md @@ -59,19 +59,38 @@ Use this index for the skill-scoped quick index and global flags. | `bl finetune list` | API Key | List fine-tune jobs | [finetune.md](finetune.md) | | `bl finetune logs` | API Key | Fetch training logs for a fine-tune job | [finetune.md](finetune.md) | | `bl finetune metrics` | API Key | Query the training metrics of a fine-tune job | [finetune.md](finetune.md) | +| `bl finetune opd authorize` | Console | Check and authorize OPD distillation access (whitelist, service roles, enablement) | [finetune.md](finetune.md) | +| `bl finetune opd cancel` | API Key | Cancel a running OPD job | [finetune.md](finetune.md) | +| `bl finetune opd delete` | API Key | Delete an OPD job record | [finetune.md](finetune.md) | +| `bl finetune opd get` | API Key | Get an OPD job | [finetune.md](finetune.md) | +| `bl finetune opd logs` | API Key | Fetch OPD job logs | [finetune.md](finetune.md) | +| `bl finetune opd params` | API Key | Query OPD (pg_opd) training / resource parameter configuration for a student model | [finetune.md](finetune.md) | +| `bl finetune opd run` | API Key | Submit a pure Model OPD distillation job (pg_opd) via the fine-tunes OpenAPI | [finetune.md](finetune.md) | +| `bl finetune opd watch` | API Key | Probe an OPD job's status (default: single non-blocking fetch). Pass --follow to poll until terminal. | [finetune.md](finetune.md) | | `bl finetune params` | API Key | Query the training hyper-parameter configuration for a base model | [finetune.md](finetune.md) | | `bl finetune price` | Console | Estimate the training cost for a fine-tune job (token billing) | [finetune.md](finetune.md) | +| `bl finetune rl authorize` | Console | Check and authorize reinforcement-learning access (whitelist, service roles, enablement) | [finetune.md](finetune.md) | +| `bl finetune rl cancel` | API Key | Cancel a running RL job | [finetune.md](finetune.md) | +| `bl finetune rl delete` | API Key | Delete an RL job record | [finetune.md](finetune.md) | +| `bl finetune rl get` | API Key | Get an RL job | [finetune.md](finetune.md) | +| `bl finetune rl list` | API Key | List RL jobs | [finetune.md](finetune.md) | +| `bl finetune rl logs` | API Key | Fetch RL job logs | [finetune.md](finetune.md) | +| `bl finetune rl run` | API Key | Submit a reinforcement-learning training job | [finetune.md](finetune.md) | +| `bl finetune rl watch` | API Key | Probe an RL job's status (default: single non-blocking fetch). Pass --follow to poll until terminal. | [finetune.md](finetune.md) | +| `bl finetune runtime clean` | No Auth | Reclaim orphaned sandbox run directories and superseded runtime versions | [finetune.md](finetune.md) | +| `bl finetune runtime doctor` | No Auth | Check the RL runtime and sandbox isolation (credential deny, home redirect, SDK import) | [finetune.md](finetune.md) | +| `bl finetune runtime prepare` | No Auth | Prepare the managed Python/SDK runtime used by RL and OPD jobs | [finetune.md](finetune.md) | | `bl finetune text create` | API Key | Create a text model fine-tune job (sft \| sft-lora \| dpo \| dpo-lora \| cpt) | [finetune.md](finetune.md) | | `bl finetune video create` | API Key | Create a video generation model fine-tune job (Wan i2v/kf2v, efficient_sft) | [finetune.md](finetune.md) | | `bl finetune watch` | API Key | Probe a fine-tune job's status (default: single non-blocking fetch). Pass --follow to poll until terminal. | [finetune.md](finetune.md) | ## By group -| Group | Commands | Reference | -| ---------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------- | -| `dataset` | `delete`, `get`, `groups`, `list`, `upload`, `validate`, `version` | [dataset.md](dataset.md) | -| `deploy` | `audio create`, `capacity create`, `capacity delete`, `capacity get`, `capacity list`, `capacity renew`, `capacity scale`, `capacity unsubscribe`, `delete`, `get`, `image create`, `instances`, `list`, `models`, `operation get`, `operation wait`, `overflow`, `pause`, `resume`, `scale`, `text create`, `update` | [deploy.md](deploy.md) | -| `finetune` | `audio create`, `cancel`, `capability`, `checkpoints`, `compress cancel`, `compress create`, `compress delete`, `compress get`, `compress list`, `compress logs`, `compress templates`, `compress watch`, `delete`, `export`, `get`, `image create`, `list`, `logs`, `metrics`, `params`, `price`, `text create`, `video create`, `watch` | [finetune.md](finetune.md) | +| Group | Commands | Reference | +| ---------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------- | +| `dataset` | `delete`, `get`, `groups`, `list`, `upload`, `validate`, `version` | [dataset.md](dataset.md) | +| `deploy` | `audio create`, `capacity create`, `capacity delete`, `capacity get`, `capacity list`, `capacity renew`, `capacity scale`, `capacity unsubscribe`, `delete`, `get`, `image create`, `instances`, `list`, `models`, `operation get`, `operation wait`, `overflow`, `pause`, `resume`, `scale`, `text create`, `update` | [deploy.md](deploy.md) | +| `finetune` | `audio create`, `cancel`, `capability`, `checkpoints`, `compress cancel`, `compress create`, `compress delete`, `compress get`, `compress list`, `compress logs`, `compress templates`, `compress watch`, `delete`, `export`, `get`, `image create`, `list`, `logs`, `metrics`, `opd authorize`, `opd cancel`, `opd delete`, `opd get`, `opd logs`, `opd params`, `opd run`, `opd watch`, `params`, `price`, `rl authorize`, `rl cancel`, `rl delete`, `rl get`, `rl list`, `rl logs`, `rl run`, `rl watch`, `runtime clean`, `runtime doctor`, `runtime prepare`, `text create`, `video create`, `watch` | [finetune.md](finetune.md) | ## Global flags diff --git a/skills/bailian-gen/SKILL.md b/skills/bailian-gen/SKILL.md index 7ae20cae..f431e81b 100644 --- a/skills/bailian-gen/SKILL.md +++ b/skills/bailian-gen/SKILL.md @@ -1,7 +1,7 @@ --- name: bailian-gen metadata: - version: "2.10.3" + version: "2.10.4" requires: bins: ["bl"] description: >- diff --git a/skills/bailian-knowledge/SKILL.md b/skills/bailian-knowledge/SKILL.md index 9357d826..295a023f 100644 --- a/skills/bailian-knowledge/SKILL.md +++ b/skills/bailian-knowledge/SKILL.md @@ -1,7 +1,7 @@ --- name: bailian-knowledge metadata: - version: "2.10.3" + version: "2.10.4" requires: bins: ["bl"] description: >- diff --git a/skills/bailian-managed-agent/SKILL.md b/skills/bailian-managed-agent/SKILL.md index 28353d69..6da883e8 100644 --- a/skills/bailian-managed-agent/SKILL.md +++ b/skills/bailian-managed-agent/SKILL.md @@ -1,7 +1,7 @@ --- name: bailian-managed-agent metadata: - version: "2.10.3" + version: "2.10.4" requires: bins: ["bl"] description: >- diff --git a/skills/bailian-memory/SKILL.md b/skills/bailian-memory/SKILL.md index 0dc9f051..8ac2fb8d 100644 --- a/skills/bailian-memory/SKILL.md +++ b/skills/bailian-memory/SKILL.md @@ -1,7 +1,7 @@ --- name: bailian-memory metadata: - version: "2.10.3" + version: "2.10.4" requires: bins: ["bl"] description: >- diff --git a/skills/bailian-opd/README.md b/skills/bailian-opd/README.md new file mode 100644 index 00000000..e887bdfe --- /dev/null +++ b/skills/bailian-opd/README.md @@ -0,0 +1,101 @@ +# bailian-opd + +Guided end-to-end workflow for **pure Model OPD distillation** (`pg_opd`) on +Alibaba Cloud Bailian: train a student model from a teacher model through the +`bl` CLI, with deterministic scripts enforcing every gate. + +[中文版](README.zh.md) · Agent instructions: [SKILL.md](SKILL.md) + +## What it does + +Runs the full creation chain in the safe order: + +1. **Authorize** — probe the account's OPD feature gate (whitelist, service + roles, enablement); enablement only after your explicit confirmation. +2. **Validate data** — local ChatML validation of your JSONL (prompt-only + `messages` + `rollout_extra` are valid for pure distillation). +3. **Probe parameters** — confirm the student is registered for `pg_opd` and + the workspace matches the API key. +4. **Dry-run + consent** — assemble the exact request body, surface every + warning (unpublished pair, default-layout capacity, teacher length), and + require your explicit confirmation of the body and billing scope. +5. **Confirmed submit** — create the job; on failure/timeout a duplicate-creation + guard checks whether the server persisted a job anyway (it can return 500 + after persisting). Never blind-retries. +6. **Verified success** — poll to a terminal state; `SUCCEEDED` plus listed + checkpoints counts as success. Execution-phase failures (e.g. MTU capacity + mismatch) are extracted with a triage hint. + +## When to use + +You want OPD / online distillation with a `teacher_model`. Not for RL / agentic +rollout training, SFT/DPO/CPT fine-tuning, or deployment — those belong to the +`bailian-finetune` skill. + +## Prerequisites + +- `bl` (bailian-cli) installed and up to date; `node` >= 18. +- Two logins: `bl auth login --api-key` (data/params/create) and + `bl auth login --console` (OPD feature probe). +- OPD is invite-only; supported student/teacher pairs are published in the + official OPD docs ("模型与训练单元" section). + +## Quickstart + +```bash +# 1. Read-only preflight (aggregates all gates into one JSON report) +node scripts/opd-preflight.mjs \ + --base-model qwen3.5-9b --teacher-model qwen3.5-397b-a17b \ + --datasets ./train.jsonl --validations ./valid.jsonl \ + --hyper-parameters-file assets/baseline-9b-from-397b.hyper_parameters.json \ + --resource-config-file assets/baseline-9b-from-397b.resource_config.json \ + --caller-name my-agent + +# 2. Review the report, then submit ONLY after explicit confirmation +node scripts/opd-submit.mjs --confirmed --caller-name my-agent + +# 3. Monitor to a verified terminal state +node scripts/opd-wait.mjs --job-id ft-xxx --caller-name my-agent +``` + +## Baselines and capacity + +Bundled `assets/` baselines are dated snapshots of historically successful +requests (public model names and parameters only). Default to the all-explicit +9B←397B baseline for a first run; 9B←Flash is the second choice. + +| Layout | mtu_capacity | +| ------------------------------------------ | ---------------------------- | +| Default student layout, 9B + Flash teacher | 24 (official recommendation) | +| Flash baseline custom layout | 16 | +| 397B baseline all-explicit | 24 | + +`mtu_capacity` must equal student GPUs + teacher GPUs. The server checks this +**after** job creation, so the preflight computes both layout interpretations +and warns on mismatch — treat the advice as advisory (teacher mode has no public +query API). + +## Billing warning + +OPD jobs are **MTU postpaid**: `mtu_spec_code × mtu_capacity`, charged while the +job runs. The consent gate exists to make that scope explicit before anything +is created. A poll timeout does not cancel the job. + +## Troubleshooting (summary) + +- Exit 2: local guard (missing MTU fields, wrong charge type, teacher TP ≠ GPUs + per node, 0 training steps, mini-batch too large, schema violation) — nothing + was created. +- Exit 3: log in (`--api-key` / `--console`). +- Create 500/timeout: trust the script's `duplicate_check`; attach to a possibly + created job instead of resubmitting. +- FAILED "OPD requires N student GPUs + M teacher GPUs…": set capacity to N+M or + change the layout, re-preflight, re-confirm, submit as a new job. +- batch-fit blocked ("0 training steps"): `batch_size` is the samples-per-step; + add data to at least `ceil(batch_size / n_epochs)` samples with headroom, or + lower `batch_size` / raise `n_epochs`. Zero-step jobs fail at execution time, + after billing starts. +- Never fill the parameter API's `recommend_value` into requests — it is not the + teacher's effective default. + +Full triage table and hard rules: [SKILL.md](SKILL.md). diff --git a/skills/bailian-opd/README.zh.md b/skills/bailian-opd/README.zh.md new file mode 100644 index 00000000..985c38d4 --- /dev/null +++ b/skills/bailian-opd/README.zh.md @@ -0,0 +1,89 @@ +# bailian-opd + +阿里云百炼**纯 Model OPD 蒸馏**(`pg_opd`)端到端引导工作流:通过 `bl` CLI +用教师模型训练学生模型,每个门禁都由确定性脚本强制执行。 + +[English](README.md) · Agent 执行说明:[SKILL.md](SKILL.md) + +## 做什么 + +按安全顺序跑完创建全链路: + +1. **授权**——探测账号 OPD 功能闸(邀测白名单、服务关联角色、开通状态); + 开通只在你明确确认后执行。 +2. **数据校验**——本地 ChatML 校验 JSONL(纯蒸馏允许 prompt-only 的 + `messages` + `rollout_extra`)。 +3. **参数探测**——确认学生已登记 `pg_opd`、workspace 与 API Key 匹配。 +4. **dry-run + 确认**——组装精确请求体,原样呈现所有告警(未公布组合、 + 默认布局容量、教师长度),要求你对请求体和计费范围明确确认。 +5. **确认后提交**——创建任务;失败/超时时执行重复创建守卫(服务端可能 + 落库后仍回 500),绝不盲目重试。 +6. **验证成功**——轮询到终态;`SUCCEEDED` 且查到 checkpoints 才算成功。 + 执行期失败(如 MTU 容量不匹配)会提取失败原因并给处置建议。 + +## 何时使用 + +你要做 OPD / 在线蒸馏(带 `teacher_model`)。RL / agentic rollout 训练、 +SFT/DPO/CPT 精调、部署不属于本 skill,归 `bailian-finetune`。 + +## 前置条件 + +- 已安装并更新 `bl`(bailian-cli);`node` >= 18。 +- 双登录:`bl auth login --api-key`(数据/参数/创建)与 + `bl auth login --console`(OPD 功能探测)。 +- OPD 为邀测功能;支持的师生组合见官方 OPD 文档"模型与训练单元"章节。 + +## 快速开始 + +```bash +# 1. 只读预检(所有门禁聚合为一份 JSON 报告) +node scripts/opd-preflight.mjs \ + --base-model qwen3.5-9b --teacher-model qwen3.5-397b-a17b \ + --datasets ./train.jsonl --validations ./valid.jsonl \ + --hyper-parameters-file assets/baseline-9b-from-397b.hyper_parameters.json \ + --resource-config-file assets/baseline-9b-from-397b.resource_config.json \ + --caller-name my-agent + +# 2. 审阅报告,明确确认后才提交 +node scripts/opd-submit.mjs <相同参数> --confirmed --caller-name my-agent + +# 3. 监控到验证过的终态 +node scripts/opd-wait.mjs --job-id ft-xxx --caller-name my-agent +``` + +## 基线与容量 + +`assets/` 内置基线是历史成功请求的时点快照(仅公开模型名与参数)。首跑默认 +用教师字段全显式的 9B←397B 基线;9B←Flash 为第二选择。 + +| 布局 | mtu_capacity | +| ----------------------------- | -------------- | +| 默认学生布局,9B + Flash 教师 | 24(官方推荐) | +| Flash 基线自定义布局 | 16 | +| 397B 基线全显式 | 24 | + +`mtu_capacity` 必须等于学生 GPU 数 + 教师 GPU 数。服务端在任务创建**之后** +才检查容量,因此预检会按两种布局口径计算并在不匹配时告警——建议仅供参考 +(教师内接/外接模式无公开查询接口)。 + +## 计费警示 + +OPD 任务为 **MTU 后付费**:`mtu_spec_code × mtu_capacity`,任务运行期间计费。 +确认门禁的存在就是为了在创建任何东西之前把计费范围讲清楚。轮询超时不会 +取消任务。 + +## 故障摘要 + +- exit 2:本地闸(缺 MTU 字段、charge type 错误、教师 TP ≠ 每节点 GPU、 + 0 训练步数、mini-batch 过大、schema 违规)——未创建任何东西。 +- exit 3:登录(`--api-key` / `--console`)。 +- 创建 500/超时:相信脚本的 `duplicate_check`;挂到可能已创建的任务上, + 不要重新提交。 +- FAILED "OPD requires N student GPUs + M teacher GPUs…":容量改为 N+M + 或调整布局,重新预检、重新确认、作为新任务提交。 +- batch-fit 被拦("0 训练步数"):`batch_size` 即每步样本数;数据补到至少 + `ceil(batch_size / n_epochs)` 条并留余量,或调小 `batch_size` / 调大 + `n_epochs`。0 步任务会在计费开始后的执行期失败。 +- 绝不把参数接口的 `recommend_value` 填进请求——它不是教师的有效默认值。 + +完整分诊表与硬性规则见 [SKILL.md](SKILL.md)。 diff --git a/skills/bailian-opd/SKILL.md b/skills/bailian-opd/SKILL.md new file mode 100644 index 00000000..ecf6264a --- /dev/null +++ b/skills/bailian-opd/SKILL.md @@ -0,0 +1,204 @@ +--- +name: bailian-opd +metadata: + version: "2.10.4" + requires: + bins: ["bl", "node"] +description: >- + Guided end-to-end pure Model OPD distillation (pg_opd) on Alibaba Cloud Bailian: + authorize → dataset validate → parameter probes → dry-run consent gate → + confirmed submit → verified terminal state, driven by deterministic scripts. + Use when the user wants to distill a student model from a teacher model + (teacher_model / OPD / 蒸馏 / 在线蒸馏) and run the whole creation chain safely. + Not for RL / agentic rollout training, SFT/DPO/CPT fine-tuning, or deployment + (those go to bailian-finetune); not for model selection advice + (bailian-model-recommend). +--- + +# Bailian OPD Distillation Workflow + +Create a pure Model OPD training job (`training_type=pg_opd`, top-level +`teacher_model`, no rollout/reward functions, no Function Compute) with the +highest possible first-run success rate. Gate logic lives in deterministic +scripts under `scripts/`; the agent orchestrates, presents findings, and obtains +consent — it does not re-implement gates or guess flags. + +> **CRITICAL — shared protocol first.** Before executing anything, Read +> `../bailian-protocol/SKILL.md` and follow it: mandatory version pre-flight +> before the first `bl` call, consent classes, attribution, error reporting, +> output conventions. If the protocol skill is missing, stop and prompt +> `bl skill init`. Business context for OPD flags lives in skill +> `bailian-finetune` (its `reference/finetune.md`) or `bl finetune opd --help` — +> never guess flags. + +## Attribution + +Bundled scripts already carry the protocol `script` attribution +(`BAILIAN_CALLER_TYPE=script`, `BAILIAN_CALLER_NAME` from `--caller-name`). +For inline `bl` commands the agent runs itself, use the protocol `agent` +template, e.g.: + +```bash +BAILIAN_CALLER_TYPE=agent BAILIAN_CALLER_NAME=codex BAILIAN_SKILL_NAME=bailian-opd BAILIAN_SKILL_VERSION=2.10.2 bl finetune opd authorize --authorize --yes +``` + +## Prerequisites + +- `bl` installed and up to date (protocol version pre-flight); `node` >= 18 on PATH. +- **Two logins**: API key (`bl auth login --api-key`) for data/params/create, and + Console (`bl auth login --console`) for the OPD feature authorize probe. +- OPD is invite-only (邀测): the account whitelist must be enabled. Published + student/teacher pairs and sizing: the official OPD docs "模型与训练单元" + section (the CLI warns on unpublished pairs). + +## Workflow (steps 0–7) + +### 0. Protocol pre-flight + +Run the protocol version pre-flight; check `node --version` (>= 18) and +`bl auth status`. Missing Console login blocks only the authorize stage — the +preflight report still surfaces everything else. + +### 1. Chain-start authorization + +Disclose before any probe: OPD training is **MTU postpaid billing** +(`mtu_spec_code × mtu_capacity`, charged while the job runs). Obtain the user's +consent to start the read-only preflight. This consent covers the authorize +probe's `--yes` (the runtime risk gate requires it even for the read-only +probe; the probe never enables anything). + +### 2. Choose a baseline (do not improvise hyper-parameters) + +Default to the **all-explicit 9B←397B baseline** for a first run — every teacher +resource field is explicit, so nothing depends on server defaults and capacity +is fully computable: + +```bash +node scripts/opd-preflight.mjs \ + --base-model qwen3.5-9b --teacher-model qwen3.5-397b-a17b \ + --datasets --validations \ + --hyper-parameters-file assets/baseline-9b-from-397b.hyper_parameters.json \ + --resource-config-file assets/baseline-9b-from-397b.resource_config.json \ + --caller-name +``` + +Second choice: `assets/baseline-9b-from-flash.*` (9B←qwen3.8-flash, teacher +fields omitted → server fills Flash defaults). Capacity guide: + +| Layout | mtu_capacity | +| ------------------------------------------------------------------ | ---------------------------------------------------------------------------- | +| Default student layout (layout fields omitted), 9B + Flash teacher | 24 (official recommendation; observed default = 16 student + 8 teacher GPUs) | +| Flash baseline custom layout (4/2 GPUs) | 16 | +| 397B baseline all-explicit (8/8 GPUs + 8 teacher) | 24 | + +Baselines are dated snapshots of historically successful requests — never +"improve" them; apply overrides only when the user explicitly asks. Data format: +JSONL, `messages` with system (task) + user (input); prompt-only is valid for +pure distillation; `rollout_extra.solution` passes through untouched. Data size: +`batch_size` is the samples-per-step, so the training set needs at least +`ceil(batch_size / n_epochs)` effective samples for one step — the preflight +`batch-fit` stage computes the step count and blocks zero-step configurations +(they fail at execution time, after billing starts). + +### 3. Preflight report and remediation + +Run `opd-preflight.mjs` (read-only; aggregates all stages in one pass). Present +the report. Blocked stages → follow their `remediation`: + +- Console login missing → `bl auth login --console`. +- Service roles `REQUIRES_USER_ACTION` → surface the manual authorization links + verbatim; the CLI never creates roles. +- `business-enabled: MISSING` → **only after explicit user confirmation**, run + inline: `bl finetune opd authorize --authorize --yes`. The scripts never enable. +- Empty parameter schema → the student is not registered for pg_opd; pick a + published student. +- Workspace 400/403 → the workspace does not match the API key; fix + `--workspace-id` / config. +- `batch-fit` blocked (0 training steps) → add data to at least + `ceil(batch_size / n_epochs)` samples with headroom, or lower `batch_size` / + raise `n_epochs`; re-run preflight. + +Re-run preflight after remediation until no stage is blocked. + +### 4. Consent gate (mandatory, verbatim) + +Present to the user, verbatim from the report: + +- `body_preview` (the exact request body), +- every warning (`OPD_PAIR_NOT_PUBLISHED`, `OPD_DEFAULT_LAYOUT_CAPACITY`, + `OPD_LENGTH_EXCEEDS_TEACHER`, `OPD_BATCH_FIT_UNKNOWN`, + `OPD_WARMUP_EXCEEDS_STEPS`, `OPD_INTERVAL_EXCEEDS_STEPS`, capacity advice, + dataset warnings), +- `pending_uploads` (local files that will be uploaded), +- billing scope: `mtu_spec_code × mtu_capacity`, MTU postpaid, charged until the + job reaches a terminal state. + +Obtain explicit confirmation. **Any scope change (model, teacher, data, +capacity, hyper-parameters) requires re-running preflight and re-confirming.** +Never add `--yes` or `--confirmed` automatically. + +### 5. Confirmed submit + +```bash +node scripts/opd-submit.mjs --confirmed --caller-name +``` + +The script passes `--yes` to `bl finetune opd run` only because `--confirmed` +was given after step 4. Local paths are validated and uploaded inside this run. +On create failure/timeout the script **never retries**; it runs a +duplicate-creation guard (the server can persist a job and still return 500) and +reports `duplicate_check`. `possibly_created` → attach to that job, do not +resubmit. `unknown` → stop and report the uncertainty. + +### 6. Monitor to a verified terminal state + +```bash +node scripts/opd-wait.mjs --job-id [--interval 30] [--poll-timeout 3600] --caller-name +``` + +(or `opd-submit.mjs … --confirmed --wait`). Creation returning a job id is NOT +success: capacity mismatches fail at execution time, after billing starts. +Poll timeout (exit 5) ≠ failure — the job was not canceled; resume with the +printed command, never resubmit. + +### 7. Verified success and hand-off + +Success = terminal `SUCCEEDED` **and** checkpoints listed (the wait script +includes them). Give the protocol one-line summary. Export / deployment / +metrics → soft hand-off to skill `bailian-finetune` (`bl finetune checkpoints / +export / metrics`, then `bl deploy`). Listing jobs: `bl finetune list` (there is +no `opd list`). + +## Failure triage + +| Signal | Meaning | Action | +| ---------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------- | +| exit 2 | usage / local guard (missing MTU fields, bad charge_type, TP ≠ GPUs/node, 0 training steps, mini-batch too large, schema violation) | fix inputs; nothing was uploaded or created | +| exit 3 | auth missing | `bl auth login --api-key` / `--console` | +| exit 5 | poll timeout | job still alive; resume waiting | +| exit 6 | network | retry the read-only step; never blind-retry create | +| exit 7 | `requires_confirmation` | normal control flow — obtain consent, then `--yes`/`--confirmed` | +| create 500 / timeout | job may exist anyway | trust `duplicate_check`; attach or stop-and-report | +| FAILED message "OPD requires N student GPUs + M teacher GPUs, but the MTU capacity is K" | execution-phase capacity mismatch | set capacity N+M (or change layout), re-preflight, re-confirm, submit as a NEW job | +| batch-fit blocked / exit 2 "0 training steps" | samples × n_epochs < batch_size (samples per step) | add data to ≥ ceil(batch_size / n_epochs) with headroom, or lower batch_size / raise n_epochs; re-preflight, re-confirm | +| FAILED length errors | student lengths exceed teacher limit | keep `max_length`/`max_prompt_length` ≤ teacher `max_model_len` (Flash/Max default 16385); re-confirm | + +## Anti-patterns (hard rules) + +- Never fill the parameter API's `recommend_value` into requests — it is not the + selected teacher's effective default (Flash/Max teacher max length 16385 vs + the generic 33792/34816). +- Never hardcode teacher defaults into requests; omitted teacher fields are + resolved by the server. +- Never pass `--yes` to `opd run` or `--confirmed` to the submit script without + explicit user confirmation of the exact scope. +- Never blind-retry a create; a timeout is not a rejection. +- `opd authorize` exit 0 does NOT mean enabled — parse `ok` / `checks`. +- Treat capacity advice as advisory: teacher mode (internal/external) has no + public query API, so the scripts compute both interpretations and warn. + +## References + +- Shared execution protocol: `../bailian-protocol/SKILL.md` +- OPD command flags and domain rules: skill `bailian-finetune`, `bl finetune opd --help` +- User-facing intro: `README.md` / `README.zh.md` diff --git a/skills/bailian-opd/assets/baseline-9b-from-397b.hyper_parameters.json b/skills/bailian-opd/assets/baseline-9b-from-397b.hyper_parameters.json new file mode 100644 index 00000000..f312d9e6 --- /dev/null +++ b/skills/bailian-opd/assets/baseline-9b-from-397b.hyper_parameters.json @@ -0,0 +1,31 @@ +{ + "n_epochs": 1, + "n_rollouts": 4, + "learning_rate": 1e-6, + "eval_steps": 50, + "ppo_mini_batch_size": 16, + "kl_loss_coef": 0.0, + "lr_scheduler_type": "cosine", + "algorithm": "gspo", + "batch_size": 64, + "max_prompt_length": 15360, + "max_length": 16384, + "nnodes_training": 1, + "nnodes_rollout": 1, + "n_gpus_training": 8, + "n_gpus_rollout": 8, + "save_strategy": "steps", + "save_steps": 50, + "save_total_limit": 1, + "lr_warmup_steps": -1, + "opd_teacher_nnodes": 1, + "opd_teacher_n_gpus_per_node": 8, + "opd_teacher_infer_tp": 8, + "opd_teacher_gpu_memory_utilization": 0.75, + "opd_teacher_max_model_len": 16385, + "opd_teacher_max_num_batched_tokens": 4096, + "opd_teacher_max_num_seqs": 2, + "opd_teacher_num_replicas": 1, + "tensor_model_parallel_size": 4, + "inference_tensor_parallel_size": 2 +} diff --git a/skills/bailian-opd/assets/baseline-9b-from-397b.resource_config.json b/skills/bailian-opd/assets/baseline-9b-from-397b.resource_config.json new file mode 100644 index 00000000..46141ea2 --- /dev/null +++ b/skills/bailian-opd/assets/baseline-9b-from-397b.resource_config.json @@ -0,0 +1,5 @@ +{ + "charge_type": "mtu_postpaid", + "mtu_spec_code": "MTU4", + "mtu_capacity": 24 +} diff --git a/skills/bailian-opd/assets/baseline-9b-from-flash.hyper_parameters.json b/skills/bailian-opd/assets/baseline-9b-from-flash.hyper_parameters.json new file mode 100644 index 00000000..9a16bea8 --- /dev/null +++ b/skills/bailian-opd/assets/baseline-9b-from-flash.hyper_parameters.json @@ -0,0 +1,23 @@ +{ + "n_epochs": 1, + "n_rollouts": 4, + "learning_rate": 1e-6, + "eval_steps": 50, + "ppo_mini_batch_size": 16, + "kl_loss_coef": 0.0, + "lr_scheduler_type": "cosine", + "algorithm": "gspo", + "batch_size": 64, + "max_prompt_length": 15360, + "max_length": 16384, + "nnodes_training": 1, + "nnodes_rollout": 1, + "n_gpus_training": 4, + "n_gpus_rollout": 2, + "save_strategy": "steps", + "save_steps": 50, + "save_total_limit": 1, + "lr_warmup_steps": -1, + "tensor_model_parallel_size": 4, + "inference_tensor_parallel_size": 2 +} diff --git a/skills/bailian-opd/assets/baseline-9b-from-flash.resource_config.json b/skills/bailian-opd/assets/baseline-9b-from-flash.resource_config.json new file mode 100644 index 00000000..c0fa7911 --- /dev/null +++ b/skills/bailian-opd/assets/baseline-9b-from-flash.resource_config.json @@ -0,0 +1,5 @@ +{ + "charge_type": "mtu_postpaid", + "mtu_spec_code": "MTU4", + "mtu_capacity": 16 +} diff --git a/skills/bailian-opd/scripts/lib.mjs b/skills/bailian-opd/scripts/lib.mjs new file mode 100644 index 00000000..0f3159e9 --- /dev/null +++ b/skills/bailian-opd/scripts/lib.mjs @@ -0,0 +1,282 @@ +// Shared utilities for the bailian-opd skill scripts. +// Bare Node (>=18.17), no dependencies: shells out to the installed `bl` CLI +// and parses its JSON contract. Attribution follows the bailian-protocol +// `script` template (caller type/name only; skill variables are omitted for +// script invocations per protocol). + +import { spawnSync } from "node:child_process"; +import { existsSync, readFileSync } from "node:fs"; +import { dirname, join } from "node:path"; +import { fileURLToPath } from "node:url"; + +export const EXIT = { ok: 0, blocked: 1, usage: 2, auth: 3, timeout: 5, network: 6 }; + +const SCRIPT_DIR = dirname(fileURLToPath(import.meta.url)); + +export function skillVersion() { + try { + const text = readFileSync(join(SCRIPT_DIR, "..", "SKILL.md"), "utf8"); + const match = text.match(/version:\s*"([^"]+)"/); + return match ? match[1] : "unknown"; + } catch { + return "unknown"; + } +} + +export function usageError(message) { + process.stderr.write(`${JSON.stringify({ error: { code: EXIT.usage, message } })}\n`); + // Exit code 2 is the machine contract: usage errors must terminate the + // standalone script before any network call. + // eslint-disable-next-line unicorn/no-process-exit + process.exit(EXIT.usage); +} + +// Minimal flag parser: value flags consume the next token, switches are boolean, +// `repeatable` flags collect an array. Unknown flags are usage errors. +export function parseFlags(argv, spec) { + const flags = {}; + for (let index = 0; index < argv.length; index += 1) { + const token = argv[index]; + if (!token.startsWith("--")) usageError(`Unexpected argument: ${token}`); + const name = token.slice(2); + const rule = spec[name]; + if (!rule) usageError(`Unknown flag: --${name}`); + if (rule.switch) { + flags[name] = true; + continue; + } + const value = argv[index + 1]; + if (value === undefined || value.startsWith("--")) usageError(`--${name} requires a value`); + index += 1; + if (rule.repeatable) { + (flags[name] ??= []).push(value); + } else { + flags[name] = value; + } + } + for (const [name, rule] of Object.entries(spec)) { + if (rule.required && flags[name] === undefined) usageError(`--${name} is required`); + } + return flags; +} + +// Resolve how to spawn bl. On Windows, Node >=18.20/20.12 refuses to spawn +// .cmd shims without a shell; resolve the real JS entry and spawn it with the +// current node executable instead (never shell:true with user-provided paths). +function resolveBlCommand() { + const override = process.env.BAILIAN_BL_ENTRY; + if (override) return { command: process.execPath, prefix: [override] }; + if (process.platform !== "win32") return { command: "bl", prefix: [] }; + const where = spawnSync("where", ["bl"], { encoding: "utf8" }); + const candidates = (where.stdout ?? "") + .split(/\r?\n/) + .map((line) => line.trim()) + .filter(Boolean); + for (const candidate of candidates) { + const entry = join(dirname(candidate), "node_modules", "bailian-cli", "dist", "bailian.mjs"); + if (existsSync(entry)) return { command: process.execPath, prefix: [entry] }; + } + usageError( + "Cannot resolve the bl JS entry on Windows. Set BAILIAN_BL_ENTRY to /node_modules/bailian-cli/dist/bailian.mjs and retry.", + ); +} + +// Parse one JSON object document; undefined for empty / non-object / invalid. +function tryParseJson(text) { + const trimmed = text.trim(); + if (!trimmed.startsWith("{")) return undefined; + try { + const parsed = JSON.parse(trimmed); + return typeof parsed === "object" && parsed !== null && !Array.isArray(parsed) + ? parsed + : undefined; + } catch { + return undefined; + } +} + +// Run bl and parse its JSON contract: results on stdout (whole document first, +// else last JSON line), warnings/errors as JSON documents on stderr. +export function runBl(args, { callerName = "unknown", timeoutMs = 120_000 } = {}) { + const { command, prefix } = resolveBlCommand(); + const result = spawnSync(command, [...prefix, ...args], { + encoding: "utf8", + timeout: timeoutMs, + maxBuffer: 64 * 1024 * 1024, + shell: false, + env: { + ...process.env, + NO_COLOR: "1", + BAILIAN_CALLER_TYPE: "script", + BAILIAN_CALLER_NAME: callerName, + }, + }); + const stdout = result.stdout ?? ""; + const stderr = result.stderr ?? ""; + // bl --output json may emit one pretty-printed document (multi-line) or + // JSON lines; try the whole stream first, then the last JSON line. + let json = tryParseJson(stdout); + if (json === undefined) { + for (const line of stdout.split(/\r?\n/)) { + const parsed = tryParseJson(line); + if (parsed !== undefined) json = parsed; + } + } + const warnings = []; + let error; + const stderrDocuments = []; + const wholeStderr = tryParseJson(stderr); + if (wholeStderr !== undefined) { + stderrDocuments.push(wholeStderr); + } else { + for (const line of stderr.split(/\r?\n/)) { + const parsed = tryParseJson(line); + if (parsed !== undefined) stderrDocuments.push(parsed); + } + } + for (const doc of stderrDocuments) { + if (doc.warning) warnings.push(doc.warning); + if (doc.error) error = doc.error; + } + const timedOut = result.error?.code === "ETIMEDOUT"; + return { + exitCode: timedOut ? EXIT.timeout : (result.status ?? EXIT.network), + timedOut, + spawnError: result.error?.message, + stdout, + stderr, + json, + warnings, + error, + }; +} + +export function parseJsonObjectFile(filePath, label) { + let text; + try { + text = readFileSync(filePath, "utf8"); + } catch (error) { + usageError(`Cannot read ${label} file: ${filePath} (${error.code ?? error.message})`); + } + let parsed; + try { + parsed = JSON.parse(text); + } catch { + usageError(`${label} file is not valid JSON: ${filePath}`); + } + if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) { + usageError(`${label} file must contain a JSON object: ${filePath}`); + } + return parsed; +} + +// Parse --hp key=value overrides with scalar type inference (numbers stay +// numbers; everything else stays a string — same convention as bl --hp). +export function parseHpOverrides(entries) { + const overrides = {}; + for (const entry of entries ?? []) { + const eq = entry.indexOf("="); + if (eq <= 0) usageError(`--hp expects key=value, got: ${entry}`); + const key = entry.slice(0, eq); + const raw = entry.slice(eq + 1); + const numeric = Number(raw); + overrides[key] = raw !== "" && Number.isFinite(numeric) ? numeric : raw; + } + return overrides; +} + +function numericField(source, key) { + const value = Number(source[key]); + return source[key] !== undefined && Number.isFinite(value) ? value : undefined; +} + +// Dual capacity formulas (research-verified, mode-dependent): +// external teacher Worker: student = (nnodes_training + nnodes_rollout) * n_gpus_training +// internal teacher: student = nnodes_training * n_gpus_training + nnodes_rollout * n_gpus_rollout +// teacher GPUs = opd_teacher_nnodes * opd_teacher_num_replicas * opd_teacher_n_gpus_per_node +// Teacher mode has no public query API, so results are advisory only. +export function computeCapacity(hyperParameters) { + const nnodesTraining = numericField(hyperParameters, "nnodes_training"); + const nnodesRollout = numericField(hyperParameters, "nnodes_rollout"); + const gpusTraining = numericField(hyperParameters, "n_gpus_training"); + const gpusRollout = numericField(hyperParameters, "n_gpus_rollout"); + const teacherNnodes = numericField(hyperParameters, "opd_teacher_nnodes"); + const teacherReplicas = numericField(hyperParameters, "opd_teacher_num_replicas"); + const teacherGpusPerNode = numericField(hyperParameters, "opd_teacher_n_gpus_per_node"); + const studentComplete = + nnodesTraining !== undefined && + nnodesRollout !== undefined && + gpusTraining !== undefined && + gpusRollout !== undefined; + const teacherComplete = + teacherNnodes !== undefined && + teacherReplicas !== undefined && + teacherGpusPerNode !== undefined; + const studentExternal = studentComplete + ? (nnodesTraining + nnodesRollout) * gpusTraining + : undefined; + const studentInternal = studentComplete + ? nnodesTraining * gpusTraining + nnodesRollout * gpusRollout + : undefined; + const teacherGpus = teacherComplete + ? teacherNnodes * teacherReplicas * teacherGpusPerNode + : undefined; + return { + complete: studentComplete && teacherComplete, + studentComplete, + teacherComplete, + studentExternal, + studentInternal, + teacherGpus, + totalExternal: + studentExternal !== undefined && teacherGpus !== undefined + ? studentExternal + teacherGpus + : undefined, + totalInternal: + studentInternal !== undefined && teacherGpus !== undefined + ? studentInternal + teacherGpus + : undefined, + }; +} + +// Batch-fit (mirrors the CLI gate): batch_size is the published samples-per-step; +// floor(samples × n_epochs / batch_size) = 0 trips the DLC assertion +// lr_decay_steps > 0 after the job is created and billed. The raw local count +// upper-bounds the post-preprocessing count, so a local shortfall is a sound +// hard reject; a surplus is not a guarantee (preprocessing filters). +export function computeBatchFit(hyperParameters, recordCount) { + const batchSize = numericField(hyperParameters, "batch_size"); + const nEpochs = numericField(hyperParameters, "n_epochs"); + const fit = { batchSize, nEpochs, recordCount }; + if (batchSize !== undefined && batchSize > 0 && nEpochs !== undefined && nEpochs >= 1) { + fit.requiredSamples = Math.ceil(batchSize / nEpochs); + if (recordCount !== undefined) { + fit.steps = Math.floor((recordCount * nEpochs) / batchSize); + } + } + return fit; +} + +// Published constraint: ppo_mini_batch_size ≤ batch_size × n_rollouts. +export function miniBatchLimit(hyperParameters) { + const miniBatchSize = numericField(hyperParameters, "ppo_mini_batch_size"); + const batchSize = numericField(hyperParameters, "batch_size"); + const nRollouts = numericField(hyperParameters, "n_rollouts"); + if (miniBatchSize === undefined || batchSize === undefined || nRollouts === undefined) { + return undefined; + } + return { miniBatchSize, limit: batchSize * nRollouts }; +} + +// Synchronous cross-platform sleep (no busy loop, no child process). +export function sleepSync(ms) { + Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms); +} + +export function emitJson(document) { + process.stdout.write(`${JSON.stringify(document)}\n`); +} + +export function logLine(message) { + process.stderr.write(`${message}\n`); +} diff --git a/skills/bailian-opd/scripts/opd-preflight.mjs b/skills/bailian-opd/scripts/opd-preflight.mjs new file mode 100644 index 00000000..52f521f5 --- /dev/null +++ b/skills/bailian-opd/scripts/opd-preflight.mjs @@ -0,0 +1,405 @@ +#!/usr/bin/env node +// bailian-opd preflight: read-only gate battery for an OPD distillation job. +// Aggregates ALL findings in one pass (does not abort on the first block) and +// emits a single JSON report. Nothing here mutates cloud state: the authorize +// call is a probe (never --authorize), params/dry-run are read-only, dataset +// validation is local. Uploads and creation happen only in opd-submit.mjs +// after explicit operator consent. +// +// Exit: 0 = all stages pass (warnings allowed) / 1 = any stage blocked / 2 = usage. + +import { existsSync } from "node:fs"; +import { + EXIT, + computeBatchFit, + computeCapacity, + emitJson, + miniBatchLimit, + parseFlags, + parseHpOverrides, + parseJsonObjectFile, + runBl, +} from "./lib.mjs"; + +const flags = parseFlags(process.argv.slice(2), { + "base-model": { required: true }, + "teacher-model": { required: true }, + datasets: { required: true }, + validations: {}, + "hyper-parameters-file": {}, + "resource-config-file": {}, + hp: { repeatable: true }, + "mtu-spec": {}, + "mtu-count": {}, + "charge-type": {}, + "workspace-id": {}, + "caller-name": {}, + "skip-authorize": { switch: true }, +}); + +const callerName = flags["caller-name"] ?? "unknown"; +const stages = []; +const warnings = []; +const recommendations = []; + +function addStage(name, status, detail, remediation) { + stages.push({ name, status, detail, ...(remediation ? { remediation } : {}) }); +} + +// Assembly flags shared by the dry-run stage (mirrors bl finetune opd run). +const runArgs = [ + "finetune", + "opd", + "run", + "--base-model", + flags["base-model"], + "--teacher-model", + flags["teacher-model"], + "--datasets", + flags.datasets, +]; +if (flags.validations) runArgs.push("--validations", flags.validations); +if (flags["hyper-parameters-file"]) + runArgs.push("--hyper-parameters-file", flags["hyper-parameters-file"]); +if (flags["resource-config-file"]) + runArgs.push("--resource-config-file", flags["resource-config-file"]); +for (const entry of flags.hp ?? []) runArgs.push("--hp", entry); +if (flags["mtu-spec"]) runArgs.push("--mtu-spec", flags["mtu-spec"]); +if (flags["mtu-count"]) runArgs.push("--mtu-count", flags["mtu-count"]); +if (flags["charge-type"]) runArgs.push("--charge-type", flags["charge-type"]); +if (flags["workspace-id"]) runArgs.push("--workspace-id", flags["workspace-id"]); + +// Stage 1: local inputs. +const hyperParameters = flags["hyper-parameters-file"] + ? parseJsonObjectFile(flags["hyper-parameters-file"], "--hyper-parameters-file") + : {}; +Object.assign(hyperParameters, parseHpOverrides(flags.hp)); +const resourceConfig = flags["resource-config-file"] + ? parseJsonObjectFile(flags["resource-config-file"], "--resource-config-file") + : {}; +if (flags["mtu-count"] !== undefined) resourceConfig.mtu_capacity = Number(flags["mtu-count"]); +if (flags["mtu-spec"] !== undefined) resourceConfig.mtu_spec_code = flags["mtu-spec"]; +addStage("inputs", "pass", "Local files and overrides parsed."); + +// Stage 2: dataset validation (local, no auth). +const datasetEntries = [ + ...flags.datasets.split(",").map((entry) => ({ field: "datasets", value: entry.trim() })), + ...(flags.validations ?? "") + .split(",") + .filter(Boolean) + .map((entry) => ({ field: "validations", value: entry.trim() })), +]; +let datasetBlocked = false; +const datasetDetails = []; +let trainingRecordCount = 0; +let trainingCountKnown = true; +for (const { field, value } of datasetEntries) { + if (!existsSync(value)) { + if (field === "datasets") trainingCountKnown = false; + datasetDetails.push( + `${field}: ${value} treated as a file id (not a local path); skipped local validation`, + ); + continue; + } + const result = runBl( + [ + "dataset", + "validate", + "--file", + value, + "--schema", + "chatml", + "--full-validate", + "--output", + "json", + ], + { callerName }, + ); + const report = result.json; + if (result.exitCode === EXIT.ok && report?.valid) { + datasetDetails.push(`${field}: ${value} valid (${report.stats?.totalRecords ?? "?"} records)`); + if (field === "datasets") { + if (typeof report.stats?.totalRecords === "number") { + trainingRecordCount += report.stats.totalRecords; + } else { + trainingCountKnown = false; + } + } + for (const issue of report.warnings ?? []) { + warnings.push({ + code: issue.code ?? "DATASET_WARNING", + message: issue.message, + source: "dataset-validate", + }); + } + } else { + datasetBlocked = true; + const issues = (report?.errors ?? []) + .map((issue) => `line ${issue.line ?? "?"}: ${issue.message}`) + .join("; "); + datasetDetails.push(`${field}: ${value} INVALID${issues ? ` — ${issues}` : ""}`); + } +} +addStage( + "dataset-validate", + datasetBlocked ? "blocked" : "pass", + datasetDetails.join(" | "), + datasetBlocked + ? "Fix the dataset errors (chatml: messages[] with system/user content; rollout_extra passes through) and re-run preflight." + : undefined, +); + +// Stage 3: OPD authorize probe (Console auth; read-only, never enables). +if (flags["skip-authorize"]) { + addStage( + "authorize-probe", + "skipped", + "--skip-authorize was passed; OPD enablement was not verified.", + ); + warnings.push({ + code: "AUTHORIZE_SKIPPED", + message: "OPD enablement not verified; creation may be rejected by the account feature gate.", + source: "preflight", + }); +} else { + const result = runBl(["finetune", "opd", "authorize", "--yes", "--output", "json"], { + callerName, + }); + const report = result.json; + if (result.exitCode === EXIT.auth) { + addStage( + "authorize-probe", + "blocked", + "Console login required for the OPD feature probe.", + "Run: bl auth login --console", + ); + } else if (!report || typeof report.ok !== "boolean") { + addStage( + "authorize-probe", + "blocked", + result.error?.message ?? result.stderr.trim() ?? "No authorize report returned.", + ); + } else if (report.ok) { + addStage( + "authorize-probe", + "pass", + "All required OPD checks READY (whitelist, service role, business enablement).", + ); + } else { + const problems = (report.checks ?? []) + .filter((check) => check.required && check.status !== "READY") + .map((check) => `${check.name}: ${check.status}${check.detail ? ` (${check.detail})` : ""}`); + const advisory = (report.checks ?? []) + .filter((check) => !check.required && check.status === "REQUIRES_USER_ACTION") + .map((check) => `${check.name}: ${check.detail ?? check.status}`); + addStage( + "authorize-probe", + "blocked", + problems.join("; ") || "OPD checks not ready.", + "Complete the manual actions reported by bl finetune opd authorize (service roles are never auto-created).", + ); + for (const line of advisory) { + warnings.push({ code: "AUTHORIZE_ADVISORY", message: line, source: "authorize" }); + } + const business = (report.checks ?? []).find((check) => check.name === "business-enabled"); + if (business?.status === "MISSING") { + recommendations.push( + "After explicit user confirmation, enable OPD inline: bl finetune opd authorize --authorize --yes (the preflight script never enables it).", + ); + } + } +} + +// Stage 4: parameter schema probe (also surfaces workspace mismatch early). +const paramsBase = [ + "finetune", + "opd", + "params", + "--base-model", + flags["base-model"], + "--output", + "json", +]; +if (flags["workspace-id"]) paramsBase.push("--workspace-id", flags["workspace-id"]); +// The resource schema query requires an MTU spec (empty array without one). +const effectiveMtuSpec = flags["mtu-spec"] ?? resourceConfig.mtu_spec_code; +let paramsBlocked = false; +const paramsDetails = []; +for (const paramType of ["hyper", "resource"]) { + const args = [...paramsBase, "--param-type", paramType]; + if (paramType === "resource" && effectiveMtuSpec !== undefined) + args.push("--mtu-spec-code", String(effectiveMtuSpec)); + const result = runBl(args, { callerName }); + const rows = result.json?.output?.hyper_params; + if (result.exitCode !== EXIT.ok) { + paramsBlocked = true; + paramsDetails.push( + `${paramType}: query failed — ${result.error?.message ?? result.stderr.trim()}`, + ); + } else if (!Array.isArray(rows) || rows.length === 0) { + paramsBlocked = true; + paramsDetails.push( + paramType === "resource" && effectiveMtuSpec === undefined + ? "resource: empty schema — no MTU spec available (set --mtu-spec or resource_config.mtu_spec_code)" + : `${paramType}: empty schema — student "${flags["base-model"]}" is not registered for pg_opd`, + ); + } else { + paramsDetails.push(`${paramType}: ${rows.length} parameter rows`); + } +} +addStage( + "params-probe", + paramsBlocked ? "blocked" : "pass", + paramsDetails.join(" | "), + paramsBlocked + ? "Verify the student model supports pg_opd and the workspace matches the API key (400/403 = mismatch). Never copy recommend_value into requests — it is not the teacher's effective default." + : undefined, +); + +// Stage 5: capacity advice (local, advisory only — teacher mode has no public API). +const capacity = computeCapacity(hyperParameters); +const declaredCapacity = Number(resourceConfig.mtu_capacity); +const capacityDetail = { + ...capacity, + declared: Number.isFinite(declaredCapacity) ? declaredCapacity : null, +}; +if (!Number.isFinite(declaredCapacity)) { + addStage("capacity-advice", "warn", "mtu_capacity not set; the CLI requires it before creation."); +} else if (capacity.complete) { + const matches = []; + if (capacity.totalExternal === declaredCapacity) + matches.push( + `external-teacher formula (${capacity.studentExternal} student + ${capacity.teacherGpus} teacher)`, + ); + if (capacity.totalInternal === declaredCapacity) + matches.push( + `internal-teacher formula (${capacity.studentInternal} student + ${capacity.teacherGpus} teacher)`, + ); + if (matches.length === 0) { + addStage( + "capacity-advice", + "warn", + `mtu_capacity=${declaredCapacity} matches neither layout interpretation: external needs ${capacity.totalExternal}, internal needs ${capacity.totalInternal}. The server checks capacity AFTER job creation — a mismatch wastes a billed job.`, + ); + recommendations.push( + `Set --mtu-count to ${capacity.totalExternal} (external teacher) or ${capacity.totalInternal} (internal teacher), or adjust the GPU layout, then re-run preflight and re-confirm.`, + ); + } else { + addStage( + "capacity-advice", + "pass", + `mtu_capacity=${declaredCapacity} matches the ${matches.join(" / ")}.`, + ); + } +} else { + addStage( + "capacity-advice", + "warn", + "Student layout and/or teacher resource fields are omitted; the server applies defaults. Published docs recommend MTU4 x 24 for the default layout (observed qwen3.5-9b default = 16 student GPUs; Flash teacher = 8, Max = 64). Verify mtu_capacity covers student + teacher GPUs.", + ); +} + +// Stage 6: batch-fit (local; mirrors the CLI zero-step gate). batch_size is the +// published samples-per-step; 0 steps fails at execution time after billing. +const batchFit = computeBatchFit( + hyperParameters, + trainingCountKnown ? trainingRecordCount : undefined, +); +const miniBatch = miniBatchLimit(hyperParameters); +const batchFindings = []; +let batchStatus = "pass"; +let batchRemediation; +if (miniBatch && miniBatch.miniBatchSize > miniBatch.limit) { + batchStatus = "blocked"; + batchFindings.push( + `ppo_mini_batch_size (${miniBatch.miniBatchSize}) exceeds batch_size × n_rollouts (${miniBatch.limit}).`, + ); + batchRemediation = + "Lower ppo_mini_batch_size to at most batch_size × n_rollouts, then re-run preflight."; +} +if (batchFit.requiredSamples === undefined) { + batchFindings.push( + "batch_size / n_epochs not both explicit; per-step sample count is resolved by the server.", + ); +} else if (batchFit.recordCount === undefined) { + if (batchStatus !== "blocked") batchStatus = "warn"; + batchFindings.push( + `Sample count unknown (file-id datasets); with batch_size=${batchFit.batchSize} and n_epochs=${batchFit.nEpochs}, training needs at least ${batchFit.requiredSamples} effective samples for one step.`, + ); + warnings.push({ + code: "OPD_BATCH_FIT_UNKNOWN", + message: `Dataset sample count is unknown; verify at least ${batchFit.requiredSamples} effective samples (batch_size=${batchFit.batchSize}, n_epochs=${batchFit.nEpochs}).`, + source: "preflight", + }); +} else if (batchFit.steps === 0) { + batchStatus = "blocked"; + batchFindings.push( + `${batchFit.recordCount} samples with n_epochs=${batchFit.nEpochs} and batch_size=${batchFit.batchSize} (samples per step) yield 0 training steps; the job would fail at execution time (lr_decay_steps > 0) after billing starts.`, + ); + batchRemediation = `Provide at least ${batchFit.requiredSamples} samples (preprocessing may filter some, so leave headroom), or lower batch_size / raise n_epochs, then re-run preflight and re-confirm.`; +} else { + batchFindings.push( + `${batchFit.recordCount} samples → ${batchFit.steps} training step(s) (batch_size=${batchFit.batchSize}, n_epochs=${batchFit.nEpochs}).`, + ); + const warmupSteps = Number(hyperParameters.lr_warmup_steps); + if ( + hyperParameters.lr_warmup_steps !== undefined && + Number.isFinite(warmupSteps) && + warmupSteps >= 0 && + warmupSteps > batchFit.steps + ) { + if (batchStatus !== "blocked") batchStatus = "warn"; + warnings.push({ + code: "OPD_WARMUP_EXCEEDS_STEPS", + message: `lr_warmup_steps (${warmupSteps}) exceeds the estimated total training steps (${batchFit.steps}); the docs recommend 0 for small-data smoke runs.`, + source: "preflight", + }); + } + const intervalKeys = ["eval_steps", "save_steps"].filter((key) => { + if (key === "save_steps" && hyperParameters.save_strategy === "epoch") return false; + const value = Number(hyperParameters[key]); + return hyperParameters[key] !== undefined && Number.isFinite(value) && value > batchFit.steps; + }); + if (intervalKeys.length > 0) { + if (batchStatus !== "blocked") batchStatus = "warn"; + warnings.push({ + code: "OPD_INTERVAL_EXCEEDS_STEPS", + message: `${intervalKeys.join(" / ")} exceeds the estimated total training steps (${batchFit.steps}); evaluation / checkpoint saving would never trigger. Docs suggest eval_steps ≈ total steps / 10~20, save_steps ≈ eval_steps × 2~3.`, + source: "preflight", + }); + } +} +addStage("batch-fit", batchStatus, batchFindings.join(" "), batchRemediation); + +// Stage 7: integrated dry-run (zero network) — the consent artifact. +let bodyPreview; +let pendingUploads; +const dryRun = runBl([...runArgs, "--dry-run", "--output", "json"], { callerName }); +for (const warning of dryRun.warnings) { + warnings.push({ ...warning, source: "cli" }); +} +if (dryRun.exitCode === EXIT.ok && dryRun.json?.body) { + bodyPreview = dryRun.json.body; + pendingUploads = dryRun.json.pending_uploads; + addStage("run-dry-run", "pass", "Request body assembled; CLI local guards passed."); +} else { + addStage( + "run-dry-run", + "blocked", + dryRun.error?.message ?? dryRun.stderr.trim() ?? "Dry-run failed.", + "Fix the reported usage/guard error and re-run preflight.", + ); +} + +const ok = !stages.some((stage) => stage.status === "blocked"); +emitJson({ + ok, + stages, + warnings, + capacity: capacityDetail, + batch_fit: batchFit, + ...(bodyPreview ? { body_preview: bodyPreview } : {}), + ...(pendingUploads ? { pending_uploads: pendingUploads } : {}), + recommendations, +}); +process.exit(ok ? EXIT.ok : EXIT.blocked); diff --git a/skills/bailian-opd/scripts/opd-submit.mjs b/skills/bailian-opd/scripts/opd-submit.mjs new file mode 100644 index 00000000..12461c2b --- /dev/null +++ b/skills/bailian-opd/scripts/opd-submit.mjs @@ -0,0 +1,152 @@ +#!/usr/bin/env node +// bailian-opd submit: create an OPD job ONLY after explicit operator consent +// (--confirmed). Never retries a failed/timed-out create — a timeout does not +// mean the server rejected the job (it may have persisted it and returned 500), +// so on failure it runs a duplicate-creation guard against the shared job list +// and reports possibly-created jobs instead of resubmitting. +// +// Exit: 0 created (or SUCCEEDED with --wait) / 1 failed or unknown / 2 usage or +// missing consent (checked before any network call). + +import { EXIT, emitJson, parseFlags, runBl, usageError } from "./lib.mjs"; +import { waitForJob } from "./opd-wait.mjs"; + +const flags = parseFlags(process.argv.slice(2), { + "base-model": { required: true }, + "teacher-model": { required: true }, + datasets: { required: true }, + validations: {}, + "hyper-parameters-file": {}, + "resource-config-file": {}, + hp: { repeatable: true }, + "mtu-spec": {}, + "mtu-count": {}, + "charge-type": {}, + "job-name": {}, + "workspace-id": {}, + "caller-name": {}, + confirmed: { switch: true }, + wait: { switch: true }, + "poll-timeout": {}, +}); + +// Consent gate: before any spawn. The calling agent must have presented the +// preflight body_preview, all warnings, and the billing scope, and obtained +// explicit user confirmation. Never pass --confirmed automatically. +if (!flags.confirmed) { + usageError( + "Operator consent required: run opd-preflight.mjs, present the report (body, warnings, billing scope) to the user, and re-run with --confirmed only after explicit confirmation.", + ); +} + +const callerName = flags["caller-name"] ?? "unknown"; +const runArgs = [ + "finetune", + "opd", + "run", + "--base-model", + flags["base-model"], + "--teacher-model", + flags["teacher-model"], + "--datasets", + flags.datasets, +]; +if (flags.validations) runArgs.push("--validations", flags.validations); +if (flags["hyper-parameters-file"]) + runArgs.push("--hyper-parameters-file", flags["hyper-parameters-file"]); +if (flags["resource-config-file"]) + runArgs.push("--resource-config-file", flags["resource-config-file"]); +for (const entry of flags.hp ?? []) runArgs.push("--hp", entry); +if (flags["mtu-spec"]) runArgs.push("--mtu-spec", flags["mtu-spec"]); +if (flags["mtu-count"]) runArgs.push("--mtu-count", flags["mtu-count"]); +if (flags["charge-type"]) runArgs.push("--charge-type", flags["charge-type"]); +if (flags["job-name"]) runArgs.push("--job-name", flags["job-name"]); +if (flags["workspace-id"]) runArgs.push("--workspace-id", flags["workspace-id"]); + +// Uploads of local paths happen inside this confirmed run. No --watch here: +// monitoring is delegated to waitForJob so stdout stays a single JSON document. +const created = runBl([...runArgs, "--yes", "--output", "json"], { + callerName, + timeoutMs: 300_000, +}); +const jobId = created.json?.output?.job_id ?? created.json?.data?.job_id; + +if (created.exitCode === EXIT.ok && jobId) { + const result = { + ok: true, + job_id: jobId, + status: created.json?.output?.status ?? created.json?.data?.status ?? "PENDING", + }; + if (flags.wait) { + const pollTimeoutSec = + flags["poll-timeout"] !== undefined ? Number(flags["poll-timeout"]) : 3600; + const waited = waitForJob({ + jobId, + workspaceId: flags["workspace-id"], + callerName, + pollTimeoutSec: Number.isFinite(pollTimeoutSec) ? pollTimeoutSec : 3600, + }); + emitJson({ ...result, monitor: waited }); + process.exit( + waited.exitCode === EXIT.timeout ? EXIT.timeout : waited.ok ? EXIT.ok : EXIT.blocked, + ); + } + result.next = `node scripts/opd-wait.mjs --job-id ${jobId}${flags["workspace-id"] ? ` --workspace-id ${flags["workspace-id"]}` : ""}`; + emitJson(result); + process.exit(EXIT.ok); +} + +// Create failed or timed out. NEVER retry the create. Check whether the server +// persisted a job anyway (500-after-persist / timeout). The shared list is +// newest-first; match pg_opd records for this student, then compare teachers. +const failureMessage = + created.error?.message ?? + (created.timedOut ? "Create request timed out." : created.stderr.trim() || "Create failed."); +const duplicateCheck = { performed: false, candidates: [], conclusion: "unknown" }; +const list = runBl(["finetune", "list", "--page-size", "20", "--output", "json"], { callerName }); +if (list.exitCode === EXIT.ok && Array.isArray(list.json?.items)) { + duplicateCheck.performed = true; + const recent = list.json.items.filter( + (item) => item.training_type === "pg_opd" && item.base_model === flags["base-model"], + ); + for (const item of recent) { + const detail = runBl( + [ + "finetune", + "opd", + "get", + "--job-id", + item.job_id, + "--output", + "json", + ...(flags["workspace-id"] ? ["--workspace-id", flags["workspace-id"]] : []), + ], + { callerName }, + ); + const teacher = detail.json?.output?.teacher_model ?? detail.json?.data?.teacher_model; + if (teacher === flags["teacher-model"]) { + duplicateCheck.candidates.push({ + job_id: item.job_id, + status: item.status, + created_at: item.created_at, + teacher_model: teacher, + }); + } + } + duplicateCheck.conclusion = + duplicateCheck.candidates.length > 0 ? "possibly_created" : "not_found"; +} + +const result = { + ok: false, + error: failureMessage, + duplicate_check: duplicateCheck, + next: + duplicateCheck.conclusion === "possibly_created" + ? `A matching job may already exist — attach to it instead of resubmitting: node scripts/opd-wait.mjs --job-id ${duplicateCheck.candidates[0].job_id}` + : duplicateCheck.conclusion === "not_found" + ? "No matching job found in the recent list. Fix the reported error, re-run preflight, re-confirm with the user, then submit again." + : "Could not verify whether a job was created (list query failed). STOP and report the uncertainty to the user; check bl finetune list manually before any resubmission.", +}; +emitJson(result); +process.exit(EXIT.blocked); diff --git a/skills/bailian-opd/scripts/opd-wait.mjs b/skills/bailian-opd/scripts/opd-wait.mjs new file mode 100644 index 00000000..5f5e193b --- /dev/null +++ b/skills/bailian-opd/scripts/opd-wait.mjs @@ -0,0 +1,130 @@ +#!/usr/bin/env node +// bailian-opd wait: poll an OPD job to a terminal state with single probes +// (bl finetune opd watch, no --follow — stdout stays one final JSON document; +// status changes go to stderr). On SUCCEEDED it lists checkpoints; on +// FAILED/CANCELED it extracts the server failure message and a triage hint. +// +// Exit: 0 SUCCEEDED / 1 FAILED or CANCELED / 5 poll timeout (job NOT canceled) +// / 3 auth / 6 network (read-only polling is safe to re-run). + +import { realpathSync } from "node:fs"; +import { pathToFileURL } from "node:url"; +import { EXIT, emitJson, logLine, parseFlags, runBl, sleepSync } from "./lib.mjs"; + +const TERMINAL = ["SUCCEEDED", "FAILED", "CANCELED"]; +const CAPACITY_PATTERN = + /requires\s+(\d+)\s+student GPUs\s*\+\s*(\d+)\s+teacher GPUs.*?capacity is\s+(\d+)/i; + +export function waitForJob({ + jobId, + workspaceId, + callerName = "unknown", + intervalSec = 30, + pollTimeoutSec = 3600, +}) { + const workspaceArgs = workspaceId ? ["--workspace-id", workspaceId] : []; + const deadline = Date.now() + pollTimeoutSec * 1000; + let lastStatus; + for (;;) { + const probe = runBl( + ["finetune", "opd", "watch", "--job-id", jobId, "--output", "json", ...workspaceArgs], + { callerName }, + ); + if (probe.exitCode === EXIT.auth || probe.exitCode === EXIT.network) { + return { + ok: false, + exitCode: probe.exitCode, + job_id: jobId, + error: probe.error?.message ?? probe.stderr.trim(), + }; + } + const status = probe.json?.status; + if (!status) { + return { + ok: false, + exitCode: EXIT.blocked, + job_id: jobId, + error: probe.error?.message ?? "No job status returned.", + }; + } + if (status !== lastStatus) { + logLine(`[opd-wait] ${jobId}: ${status}`); + lastStatus = status; + } + if (probe.json?.terminal === true || TERMINAL.includes(status)) { + if (status === "SUCCEEDED") { + const checkpoints = runBl( + ["finetune", "checkpoints", "--job-id", jobId, "--output", "json"], + { callerName }, + ); + return { + ok: true, + exitCode: EXIT.ok, + job_id: jobId, + status, + artifacts: checkpoints.json ?? null, + }; + } + const detail = runBl( + ["finetune", "opd", "get", "--job-id", jobId, "--output", "json", ...workspaceArgs], + { callerName }, + ); + const failureMessage = detail.json?.output?.message ?? detail.json?.data?.message ?? null; + let triageHint; + const capacityMatch = + typeof failureMessage === "string" ? failureMessage.match(CAPACITY_PATTERN) : null; + if (capacityMatch) { + const needed = Number(capacityMatch[1]) + Number(capacityMatch[2]); + triageHint = `Capacity mismatch: the server needs ${capacityMatch[1]} student + ${capacityMatch[2]} teacher = ${needed} GPUs, but mtu_capacity was ${capacityMatch[3]}. Adjust --mtu-count or the GPU layout, re-run preflight, re-confirm with the user, and submit as a NEW job (never blind-retry).`; + } + return { + ok: false, + exitCode: EXIT.blocked, + job_id: jobId, + status, + failure_message: failureMessage, + ...(triageHint ? { triage_hint: triageHint } : {}), + }; + } + if (Date.now() >= deadline) { + return { + ok: false, + exitCode: EXIT.timeout, + job_id: jobId, + status, + note: "Poll timeout — the cloud job was NOT canceled and may still succeed.", + resume_command: `node scripts/opd-wait.mjs --job-id ${jobId}${workspaceId ? ` --workspace-id ${workspaceId}` : ""}`, + }; + } + sleepSync(intervalSec * 1000); + } +} + +// CLI entry (skipped when imported by opd-submit.mjs). argv[1] is normalized +// with realpathSync: skill installs are symlinks, and Node's ESM loader resolves +// import.meta.url to the real path — comparing the raw argv path would silently +// skip the entry under a symlinked invocation. +if (process.argv[1] && import.meta.url === pathToFileURL(realpathSync(process.argv[1])).href) { + const flags = parseFlags(process.argv.slice(2), { + "job-id": { required: true }, + interval: {}, + "poll-timeout": {}, + "workspace-id": {}, + "caller-name": {}, + }); + const intervalSec = flags.interval !== undefined ? Number(flags.interval) : 30; + const pollTimeoutSec = flags["poll-timeout"] !== undefined ? Number(flags["poll-timeout"]) : 3600; + if (!Number.isFinite(intervalSec) || intervalSec < 1) { + emitJson({ ok: false, error: "--interval must be a number >= 1 second" }); + process.exit(EXIT.usage); + } + const result = waitForJob({ + jobId: flags["job-id"], + workspaceId: flags["workspace-id"], + callerName: flags["caller-name"] ?? "unknown", + intervalSec, + pollTimeoutSec: Number.isFinite(pollTimeoutSec) ? pollTimeoutSec : 3600, + }); + emitJson(result); + process.exit(result.exitCode); +} diff --git a/skills/bailian-protocol/SKILL.md b/skills/bailian-protocol/SKILL.md index 9ecb847c..58b521c6 100644 --- a/skills/bailian-protocol/SKILL.md +++ b/skills/bailian-protocol/SKILL.md @@ -1,13 +1,13 @@ --- name: bailian-protocol metadata: - version: "2.10.3" + version: "2.10.4" requires: bins: ["bl"] description: >- 阿里云百炼 `bl` 家族共享执行协议(consent 确认、版本预检、鉴权/安装、错误上报、本地文件与输出约定)。 不是面向用户意图的业务入口;当任一 bailian-* 业务 skill(bailian-cli / bailian-gen / - bailian-finetune / bailian-managed-agent / bailian-sandbox / bailian-memory / bailian-knowledge / bailian-web-search)执行前需要公共上下文,或用户首次安装/鉴权/`bl` 报错需上报时读取本 skill。 + bailian-finetune / bailian-opd / bailian-managed-agent / bailian-sandbox / bailian-memory / bailian-knowledge / bailian-web-search)执行前需要公共上下文,或用户首次安装/鉴权/`bl` 报错需上报时读取本 skill。 官方安装为整包:`bl skill init`(与业务 skill 同装)。 --- @@ -68,6 +68,7 @@ Commands declaring `preparation: "read-only"` may authenticate and read remote r | ---------------------------------------------------------- | ----------------------- | ---------------------------------------------- | | 生图 / 生视频 / 语音 / 图片理解 / 视频理解 / omni / vision | `bailian-gen` | `bl image\|video\|speech\|omni\|vision --help` | | 精调 / 训练数据集 / 部署 | `bailian-finetune` | `bl dataset\|finetune\|deploy --help` | +| OPD 蒸馏端到端工作流(授权→校验→确认→提交→监控) | `bailian-opd` | `bl finetune opd --help` | | agents.yaml IaC | `bailian-managed-agent` | `bl managed-agent --help` | | 百炼 Sandbox 实例 / 模版生命周期 | `bailian-sandbox` | `bl sandbox --help` | | 联网搜索 / web search(模型路由 + 兜底) | `bailian-web-search` | `bl search web --help` | diff --git a/skills/bailian-sandbox/SKILL.md b/skills/bailian-sandbox/SKILL.md index f23b542a..a08c6373 100644 --- a/skills/bailian-sandbox/SKILL.md +++ b/skills/bailian-sandbox/SKILL.md @@ -1,7 +1,7 @@ --- name: bailian-sandbox metadata: - version: "2.10.3" + version: "2.10.4" requires: bins: ["bl"] description: >- diff --git a/skills/bailian-web-search/SKILL.md b/skills/bailian-web-search/SKILL.md index 3698c54f..b5a461fb 100644 --- a/skills/bailian-web-search/SKILL.md +++ b/skills/bailian-web-search/SKILL.md @@ -1,7 +1,7 @@ --- name: bailian-web-search metadata: - version: "2.10.3" + version: "2.10.4" requires: bins: ["bl"] description: >- diff --git a/tools/release/check.mjs b/tools/release/check.mjs index 42a2ee8b..a4c6c529 100644 --- a/tools/release/check.mjs +++ b/tools/release/check.mjs @@ -70,6 +70,7 @@ export async function runCheck(options = {}) { "skills/bailian-memory/SKILL.md", "skills/bailian-knowledge/SKILL.md", "skills/bailian-web-search/SKILL.md", + "skills/bailian-opd/SKILL.md", ]), "skills/bailian-cli/reference/", "skills/bailian-gen/reference/", diff --git a/vite.config.ts b/vite.config.ts index 0a50965a..399e6358 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -100,6 +100,15 @@ export default defineConfig({ "no-restricted-properties": restrictCommandCapabilities("exportApiCredential"), }, }, + { + // RL/OPD 沙箱执行器把 API 凭证委托给隔离沙箱内嵌的 dashscope SDK(不经过 + // core 的 request/requestJson 通道),与 managed-agent/_engine、advisor 的 + // 嵌入式 SDK 委托同属受控例外;仅限执行器本身,不波及整个 finetune 命令族。 + files: ["packages/commands/src/commands/finetune/rl-shared.ts"], + rules: { + "no-restricted-properties": restrictCommandCapabilities("exportApiCredential"), + }, + }, { // dsh 插件(下游宿主适配层)的 `_` 前缀是“有意不用”的声明:被忽略的 catch // 绑定用 `_原因` 命名解释为何可以忽略,测试 mock 的 `_path` 类参数则是为了