mirror of
https://github.com/modelstudioai/cli.git
synced 2026-09-14 19:49:23 +08:00
d24104f7dc
包名 @ali/bailian-kb-dsh → bailian-kb-dsh(公开 npm):package.json name + cordis.patch.yml insert.name + tsdown PLUGIN_ID 三处同步(漏一处即 dsh 运行时崩)。 产物 lib/ → dist/(本仓 .gitignore 忽略 dist 不忽略 lib),连带 main/types/ exports/files/tsdown outDir 同步;.gitignore 补 *.tsbuildinfo。 依赖接 catalog(yaml/typescript/@types/node/vite-plus);测试导入 vitest → vite-plus/test(全仓统一约定,消掉唯一的 vitest 依赖漂移)。 tsconfig 拆三件套:tsconfig.json 纯类型检查覆盖 src+tests(供 oxlint 自动发现, 含 jsx/DOM),tsconfig.build.json 产出 node 半,tsconfig.web.json 隔离检查 web 半。 补齐 tests 从未被类型检查暴露的一处 partial 输入类型错误。 根 vite.config.ts 新增两条 override:web 半 no-restricted-imports 把 tsdown 构建期 的 bundle purity gate 提前到 lint 期;全包放开 _ 前缀的 no-unused-vars。 文档:新增 docs/agents/dsh-plugin.md,AGENTS.md 项目地图/版本锁步例外/分层边界/ 场景索引同步,packages.mjs 注释说明故意不进发布白名单。 格式化(单引号无分号 → 双引号加分号)由 pre-commit 的 vp check --fix 自动完成, 无法单独成 commit,一并纳入。 全仓 vp check 0 error;插件 13 文件 85 测试全绿;build + typecheck 通过。
121 lines
4.6 KiB
TypeScript
121 lines
4.6 KiB
TypeScript
import { defineConfig } from "vite-plus";
|
||
|
||
const commandCapabilityRestrictions = [
|
||
{
|
||
property: "configStore",
|
||
message: "configStore is only available to commands/config/**.",
|
||
},
|
||
{
|
||
property: "authStore",
|
||
message: "authStore is only available to commands/auth/**.",
|
||
},
|
||
{
|
||
property: "commandPacks",
|
||
message: "commandPacks is only available to commands/plugin/**.",
|
||
},
|
||
{
|
||
property: "exportApiCredential",
|
||
message:
|
||
"exportApiCredential is only available to commands/managed-agent/_engine/** (embedded-SDK credential delegation).",
|
||
},
|
||
] as const;
|
||
|
||
type CommandCapabilityRestriction = (typeof commandCapabilityRestrictions)[number];
|
||
type CommandCapability = CommandCapabilityRestriction["property"];
|
||
|
||
function restrictCommandCapabilities(
|
||
allowed?: CommandCapability,
|
||
): ["error", ...CommandCapabilityRestriction[]] {
|
||
return ["error", ...commandCapabilityRestrictions.filter(({ property }) => property !== allowed)];
|
||
}
|
||
|
||
export default defineConfig({
|
||
test: {
|
||
globalSetup: "./packages/e2e/src/global-setup.ts",
|
||
testTimeout: 60_000,
|
||
hookTimeout: 60_000,
|
||
},
|
||
staged: {
|
||
// 用函数形式返回命令:不把匹配到的文件名插值进 argv,改为跑一次全量检查。
|
||
// 逐文件传参会让 `vp check` 的 node 进程 argv 携带仓库内的文件名,
|
||
// 命中终端安全软件按 argv 子串匹配的进程管控规则时整个进程被 SIGKILL,
|
||
// 导致 pre-commit 无法完成。全量检查覆盖面更广,也不依赖文件名。
|
||
"*.{js,mjs,cjs,ts,mts,cts,jsx,tsx,json,yaml,yml,md}": () => "vp check --fix",
|
||
},
|
||
lint: {
|
||
options: { typeAware: true, typeCheck: true },
|
||
// 命令只许抛错;进程退出统一收口到 runtime 的 handleError。
|
||
rules: { "unicorn/no-process-exit": "error" },
|
||
overrides: [
|
||
{
|
||
// runtime 是统一出口层;tools/ 与测试是独立脚本入口,可直接退出。
|
||
files: ["packages/runtime/src/**", "tools/**", "**/tests/**"],
|
||
rules: { "unicorn/no-process-exit": "off" },
|
||
},
|
||
{
|
||
// finetune watch 的退出码是公开探针契约(0 成功/1 失败/2 超时/3 运行中/130 中断),
|
||
// 非错误语义,不走 handleError。
|
||
files: ["packages/commands/src/commands/finetune/watch.ts"],
|
||
rules: { "unicorn/no-process-exit": "off" },
|
||
},
|
||
{
|
||
// 普通业务命令只依赖 settings/flags/client;持久化和管理能力按命令族开放。
|
||
files: ["packages/commands/src/commands/**/*.ts"],
|
||
rules: { "no-restricted-properties": restrictCommandCapabilities() },
|
||
},
|
||
{
|
||
files: ["packages/commands/src/commands/config/**/*.ts"],
|
||
rules: {
|
||
"no-restricted-properties": restrictCommandCapabilities("configStore"),
|
||
},
|
||
},
|
||
{
|
||
files: ["packages/commands/src/commands/auth/**/*.ts"],
|
||
rules: {
|
||
"no-restricted-properties": restrictCommandCapabilities("authStore"),
|
||
},
|
||
},
|
||
{
|
||
files: ["packages/commands/src/commands/plugin/**/*.ts"],
|
||
rules: {
|
||
"no-restricted-properties": restrictCommandCapabilities("commandPacks"),
|
||
},
|
||
},
|
||
{
|
||
files: ["packages/commands/src/commands/managed-agent/_engine/**/*.ts"],
|
||
rules: {
|
||
"no-restricted-properties": restrictCommandCapabilities("exportApiCredential"),
|
||
},
|
||
},
|
||
{
|
||
// dsh 插件(下游宿主适配层)的 `_` 前缀是“有意不用”的声明:被忽略的 catch
|
||
// 绑定用 `_原因` 命名解释为何可以忽略,测试 mock 的 `_path` 类参数则是为了
|
||
// 钉住被 mock 函数的签名(删了就不再约束调用形状)。
|
||
files: ["packages/bailian-kb-dsh/**/*.{ts,tsx}"],
|
||
rules: {
|
||
"no-unused-vars": ["error", { caughtErrorsIgnorePattern: "^_", argsIgnorePattern: "^_" }],
|
||
},
|
||
},
|
||
{
|
||
// web 半会被 tsdown 打成浏览器 bundle,由 host 的 frozen module table 解析 require:
|
||
// node 内置模块和本仓 CLI 包在那里根本不存在,import 到就是运行时必崩。
|
||
// @deepseek-ai/* 的 platform module 白名单仍由 tsdown 的 dsh-client-bundle-purity
|
||
// 插件在构建期把关(名单即 CLIENT_EXTERNALS,见 tsdown.config.ts)。
|
||
files: ["packages/bailian-kb-dsh/src/web/**/*.{ts,tsx}"],
|
||
rules: {
|
||
"no-restricted-imports": [
|
||
"error",
|
||
{
|
||
paths: ["bailian-cli-core", "bailian-cli-runtime", "bailian-cli-commands"],
|
||
patterns: ["node:*"],
|
||
},
|
||
],
|
||
},
|
||
},
|
||
],
|
||
},
|
||
run: {
|
||
cache: true,
|
||
},
|
||
});
|