Commit 0076e3d9 authored by 李恩泽's avatar 李恩泽

chore(knip): include plugins in unused-code checks

- add plugins/* as knip workspaces and scan the root workspace - remove unused @modelcontextprotocol/server and dotenv from plugin manifests - delete unreferenced exports and update AGENTS.md
parent 4ec9da67
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
- ESM(`"type": "module"`)。 - ESM(`"type": "module"`)。
- 脚本一律用 `bun run scripts/*.ts` 执行,不要假定 `tsx` 可用。 - 脚本一律用 `bun run scripts/*.ts` 执行,不要假定 `tsx` 可用。
- pnpm workspace 成员只有 `packages/*` 与 `dsh-plugins`;`plugins/*` **不是** workspace 成员,它们的依赖由根 `package.json` 提供、构建时由 Vite 打进 `dist/index.mjs`。 - pnpm workspace 成员只有 `packages/*` 与 `dsh-plugins`;`plugins/*` **不是** workspace 成员,它们的依赖由根 `package.json` 提供、构建时由 Vite 打进 `dist/index.mjs`。
- 新增插件运行时依赖时,必须同时加到**根** `package.json`(构建解析)和插件自己的 `package.json`(分发元数据)。 - 新增插件**直接 import** 的运行时依赖时,必须同时加到**根** `package.json`(构建解析)和插件自己的 `package.json`(分发元数据);仅由共享包转依赖的包只留在共享包清单里。
## 仓库结构 ## 仓库结构
...@@ -57,7 +57,7 @@ ...@@ -57,7 +57,7 @@
| `pnpm run test:run` / `test` | Vitest 单次 / watch | | `pnpm run test:run` / `test` | Vitest 单次 / watch |
| `pnpm run typecheck` | 根 tsconfig(plugins/packages/scripts)+ `dsh-plugins` | | `pnpm run typecheck` | 根 tsconfig(plugins/packages/scripts)+ `dsh-plugins` |
| `pnpm run lint` / `lint:fix` | oxlint | | `pnpm run lint` / `lint:fix` | oxlint |
| `pnpm run knip` | 未使用文件/依赖/导出(仅 workspace 成员) | | `pnpm run knip` | 未使用文件/依赖/导出(含 `plugins/*`) |
| `pnpm run fmt` / `fmt:check` | oxfmt | | `pnpm run fmt` / `fmt:check` | oxfmt |
| `pnpm run index:frontend -- --root <path>` | 批量构建前端索引 | | `pnpm run index:frontend -- --root <path>` | 批量构建前端索引 |
| `pnpm run index:jenkins` | 重建三份 `jenkins-repo-map.json` | | `pnpm run index:jenkins` | 重建三份 `jenkins-repo-map.json` |
...@@ -91,7 +91,7 @@ pnpm run test:run ...@@ -91,7 +91,7 @@ pnpm run test:run
- **工具**:通过 `@auto-browser/mcp-server-kit` 的 `startWorkflowMcpServer` 注册;工具名是 `mcp__<serverName>__<tool>`。 - **工具**:通过 `@auto-browser/mcp-server-kit` 的 `startWorkflowMcpServer` 注册;工具名是 `mcp__<serverName>__<tool>`。
- **技能**:只放 `plugins/<name>/skills/<skill>/SKILL.md`;适配层不会读 `agents/` 或其它路径。 - **技能**:只放 `plugins/<name>/skills/<skill>/SKILL.md`;适配层不会读 `agents/` 或其它路径。
- **凭证**:机密只走 DSH credentials 或进程环境变量;不要写进描述符、`.env.example`、README 示例或测试。`.env` 仅本地调试。 - **凭证**:机密只走 DSH credentials 或进程环境变量;不要写进描述符、`.env.example`、README 示例或测试。`.env` 仅本地调试。
- **共享包**:保持四个子路径导出;新增导出前确认有调用方,`knip` 会检查 workspace 成员。 - **共享包**:保持四个子路径导出;新增导出前确认有调用方,`knip` 会检查 workspace 成员与 `plugins/*`。
- **适配层**:没有 runtime `dependencies`;宿主注入 `loader`/`webServer`/`credentials`/`skills`。不要直接 import 宿主内部包。 - **适配层**:没有 runtime `dependencies`;宿主注入 `loader`/`webServer`/`credentials`/`skills`。不要直接 import 宿主内部包。
- **Jenkins 索引**:默认可移植模式,路径写成 `${JENKINS_WORK_ROOT}`;三个消费方(frontend-explorer、gitlab-api、jenkins-api)会运行时还原。改生成器必须同步这三处与 `tests/repoMapPortability.test.ts`。 - **Jenkins 索引**:默认可移植模式,路径写成 `${JENKINS_WORK_ROOT}`;三个消费方(frontend-explorer、gitlab-api、jenkins-api)会运行时还原。改生成器必须同步这三处与 `tests/repoMapPortability.test.ts`。
- **前端索引**:`index:frontend` 需要显式 `--root`,不要写死本机路径。 - **前端索引**:`index:frontend` 需要显式 `--root`,不要写死本机路径。
...@@ -106,7 +106,7 @@ pnpm run test:run ...@@ -106,7 +106,7 @@ pnpm run test:run
## 已知限制与陷阱 ## 已知限制与陷阱
- `knip` 只扫 workspace 成员(`packages/*`、`dsh-plugins`);`plugins/*` 不在扫描范围,不能据此判断插件内部无死代码。 - `knip` 通过 `knip.json` 的 `plugins/*` 额外 workspace 覆盖插件(它们不是 pnpm workspace 成员);根 workspace 也纳入扫描,才能统计 `scripts/`、`tests/` 对插件导出的引用。根 `package.json` 中仅供插件构建解析的依赖列入 `ignoreDependencies`;插件 workspace 开启 `ignoreExportsUsedInFile`(仅同文件内使用的导出不算死代码),`.agents/` 被忽略。
- 根 tsconfig 的 `include` 不含 `tests/`;测试由 Vitest 执行,不参与 `tsc`。 - 根 tsconfig 的 `include` 不含 `tests/`;测试由 Vitest 执行,不参与 `tsc`。
- DSH 以 `link:` 方式安装 bundle:目录被移动/删除会断链;安装验证要在固定路径。 - DSH 以 `link:` 方式安装 bundle:目录被移动/删除会断链;安装验证要在固定路径。
- DSH 不读插件 `.env`;`.env.example` 只服务本地直接运行 MCP 产物。 - DSH 不读插件 `.env`;`.env.example` 只服务本地直接运行 MCP 产物。
......
{ {
"$schema": "https://unpkg.com/knip@6/schema.json", "$schema": "https://unpkg.com/knip@6/schema.json",
"ignoreWorkspaces": ["."], "ignore": [".agents/**"],
"workspaces": { "workspaces": {
".": {
"ignoreDependencies": [
"@gitbeaker/rest",
"@modelcontextprotocol/server",
"@vue/compiler-sfc",
"axios",
"jsonrepair",
"zod"
]
},
"packages/mcp-server-kit": { "packages/mcp-server-kit": {
"entry": ["tests/**/*.test.ts"] "entry": ["tests/**/*.test.ts"]
}, },
...@@ -10,6 +20,10 @@ ...@@ -10,6 +20,10 @@
}, },
"dsh-plugins": { "dsh-plugins": {
"entry": ["src/client/index.tsx"] "entry": ["src/client/index.tsx"]
},
"plugins/*": {
"entry": ["src/index.ts", "src/manifest.ts"],
"ignoreExportsUsedInFile": true
} }
} }
} }
...@@ -7,8 +7,6 @@ ...@@ -7,8 +7,6 @@
"start": "node ./dist/index.mjs" "start": "node ./dist/index.mjs"
}, },
"dependencies": { "dependencies": {
"@modelcontextprotocol/server": "^2.0.0",
"dotenv": "^17.4.2",
"zod": "^4.4.3" "zod": "^4.4.3"
} }
} }
...@@ -7,9 +7,7 @@ ...@@ -7,9 +7,7 @@
"start": "node ./dist/index.mjs" "start": "node ./dist/index.mjs"
}, },
"dependencies": { "dependencies": {
"@modelcontextprotocol/server": "^2.0.0",
"@vue/compiler-sfc": "^3.5.41", "@vue/compiler-sfc": "^3.5.41",
"dotenv": "^17.4.2",
"typescript": "^6.0.3", "typescript": "^6.0.3",
"zod": "^4.4.3" "zod": "^4.4.3"
} }
......
...@@ -229,8 +229,3 @@ export function pruneWorkspaceIndexCache(params: { ...@@ -229,8 +229,3 @@ export function pruneWorkspaceIndexCache(params: {
export function hasMaintenanceEffect(result: IndexMaintenanceResult): boolean { export function hasMaintenanceEffect(result: IndexMaintenanceResult): boolean {
return result.removedProjectDirs > 0 || result.removedSnapshots > 0; return result.removedProjectDirs > 0 || result.removedSnapshots > 0;
} }
/** 便于排障:返回本次清理的摘要文案。 */
export function describeMaintenance(result: IndexMaintenanceResult): string {
return `清理失效索引目录 ${result.removedProjectDirs} 个、历史快照 ${result.removedSnapshots} 个,回收 ${(result.removedBytes / 1048576).toFixed(1)}MB`;
}
...@@ -8,8 +8,6 @@ ...@@ -8,8 +8,6 @@
}, },
"dependencies": { "dependencies": {
"@gitbeaker/rest": "^43.8.0", "@gitbeaker/rest": "^43.8.0",
"@modelcontextprotocol/server": "^2.0.0",
"dotenv": "^17.4.2",
"zod": "^4.4.3" "zod": "^4.4.3"
} }
} }
...@@ -2,12 +2,6 @@ import { Gitlab } from "@gitbeaker/rest"; ...@@ -2,12 +2,6 @@ import { Gitlab } from "@gitbeaker/rest";
import type { BlobSchema, RepositoryFileExpandedSchema } from "@gitbeaker/rest"; import type { BlobSchema, RepositoryFileExpandedSchema } from "@gitbeaker/rest";
import { resolveGitlabHost, resolveGitlabPersonalAccessToken } from "../runtimePaths.js"; import { resolveGitlabHost, resolveGitlabPersonalAccessToken } from "../runtimePaths.js";
export {
DEFAULT_GITLAB_HOST,
resolveGitlabHost,
resolveGitlabPersonalAccessToken,
} from "../runtimePaths.js";
type SearchProjectResult = { type SearchProjectResult = {
id?: number; id?: number;
name?: string; name?: string;
......
...@@ -7,8 +7,6 @@ ...@@ -7,8 +7,6 @@
"start": "node ./dist/index.mjs" "start": "node ./dist/index.mjs"
}, },
"dependencies": { "dependencies": {
"@modelcontextprotocol/server": "^2.0.0",
"dotenv": "^17.4.2",
"zod": "^4.4.3" "zod": "^4.4.3"
} }
} }
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
* - `fixedEnv`:固定常量,写入描述符,不可由用户配置。 * - `fixedEnv`:固定常量,写入描述符,不可由用户配置。
*/ */
export type PluginEnvFieldType = "string" | "url" | "secret" | "number" | "boolean" | "path"; type PluginEnvFieldType = "string" | "url" | "secret" | "number" | "boolean" | "path";
export interface PluginManifestField { export interface PluginManifestField {
/** 环境变量名,必须是大写 POSIX 标识符;同一插件内唯一。 */ /** 环境变量名,必须是大写 POSIX 标识符;同一插件内唯一。 */
......
...@@ -7,9 +7,7 @@ ...@@ -7,9 +7,7 @@
"start": "node ./dist/index.mjs" "start": "node ./dist/index.mjs"
}, },
"dependencies": { "dependencies": {
"@modelcontextprotocol/server": "^2.0.0",
"axios": "^1.20.0", "axios": "^1.20.0",
"dotenv": "^17.4.2",
"jsonrepair": "^3.15.0", "jsonrepair": "^3.15.0",
"zod": "^4.4.3" "zod": "^4.4.3"
} }
......
...@@ -592,39 +592,6 @@ function compareOperationMatchCandidates( ...@@ -592,39 +592,6 @@ function compareOperationMatchCandidates(
); );
} }
export function resolveCatalogOperation(params: {
operations: IndexedApiOperationDoc[];
apiId?: string;
path?: string;
method?: string;
service: ServiceDefinition;
}): IndexedApiOperationDoc | null {
if (params.apiId?.trim()) {
return (
params.operations.find(
(operation) => operation.apiId === params.apiId?.trim().toLowerCase(),
) ?? null
);
}
if (!params.path || !params.method) {
return null;
}
const query = buildQueryIdentity({
serviceName: params.service.serviceName,
url: params.path,
method: params.method,
pathPrefixes: params.service.pathPrefixes,
});
if (!query) {
return null;
}
const match = matchApiOperation(buildApiDocIndex(params.operations), query);
return match.operation ?? null;
}
type BundleMatchInput = { type BundleMatchInput = {
query: ApiIdentity; query: ApiIdentity;
operations: IndexedApiOperationDoc[]; operations: IndexedApiOperationDoc[];
......
import { readFile } from "node:fs/promises";
import path from "node:path";
import { writeFileAtomic } from "../utils/atomicFile.js"; import { writeFileAtomic } from "../utils/atomicFile.js";
interface ApiField { interface ApiField {
...@@ -369,24 +367,3 @@ export async function generateOpenApiGlossaryFromFlatDocs( ...@@ -369,24 +367,3 @@ export async function generateOpenApiGlossaryFromFlatDocs(
glossaryItems, glossaryItems,
}; };
} }
export async function generateOpenApiGlossaryWarningFromFlatFile(params: {
inputFile: string;
outputFile: string;
}): Promise<{
inputFile: string;
warningOutputFile: string;
warningCount: number;
}> {
const inputFile = path.resolve(params.inputFile);
const warningOutputFile = path.resolve(params.outputFile);
const raw = await readFile(inputFile, "utf8");
const flatDocs = JSON.parse(raw) as FlatApiOperationDoc[];
const result = await generateOpenApiGlossaryFromFlatDocs(flatDocs, warningOutputFile);
return {
inputFile,
warningOutputFile,
warningCount: result.warningCount,
};
}
...@@ -7,9 +7,7 @@ ...@@ -7,9 +7,7 @@
"start": "node ./dist/index.mjs" "start": "node ./dist/index.mjs"
}, },
"dependencies": { "dependencies": {
"@modelcontextprotocol/server": "^2.0.0",
"axios": "^1.20.0", "axios": "^1.20.0",
"dotenv": "^17.4.2",
"zod": "^4.4.3" "zod": "^4.4.3"
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment