From ada047e90ebaccce9fa33a95709899e1100805ef Mon Sep 17 00:00:00 2001 From: liruifengv Date: Wed, 15 Jul 2026 13:31:48 +0800 Subject: [PATCH] chore(scripts): require KIMI_CODE_REPO in sync:web, drop dead copy-web-dist - sync-web-to-kimi-code.mjs: KIMI_CODE_REPO is now required (no more ../kimi-code-2 default), the target is validated as a kimi-code checkout, errors are in Chinese, and a reminder to open a PR in the kimi-code repo prints after a successful sync - Remove apps/desktop/scripts/copy-web-dist.mjs and the web-dist .gitignore entry: the desktop renderer builds from src/renderer into desktop-dist, so the web-dist copy flow is dead - README.md / AGENTS.md updated to match --- .gitignore | 1 - AGENTS.md | 2 +- README.md | 2 +- apps/desktop/scripts/copy-web-dist.mjs | 27 ------------------- scripts/sync-web-to-kimi-code.mjs | 36 +++++++++++++++++++++----- 5 files changed, 31 insertions(+), 37 deletions(-) delete mode 100644 apps/desktop/scripts/copy-web-dist.mjs diff --git a/.gitignore b/.gitignore index 982e4be16..a39b9ec50 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,6 @@ dist out dist-app resources-stage -web-dist .DS_Store *.log coverage diff --git a/AGENTS.md b/AGENTS.md index 46cfc90b7..0a6939e4d 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -23,7 +23,7 @@ - `apps/web`:浏览器 Web UI(`@moonshot-ai/kimi-web`,Vue 3 + Vite + vue-i18n)。dev 时 Vite 把 `/api/v1`(REST + WS)代理到 `KIMI_SERVER_URL`(默认 `http://127.0.0.1:58627`)。 - `packages/*`:`@moonshot-ai/{web-core,web-i18n,web-markdown,web-ui}` + `vite-preset`(exports→src,被 apps/web 与 desktop renderer 复用)。 - `kimi-code/`:git submodule(核心仓)。`kimi-code/packages/*` 提供 `kap-server`、`agent-core-v2`、`kimi-code-sdk` 等源码。 -- `scripts/sync-web-to-kimi-code.mjs`:`apps/web/dist` → `/apps/kimi-code/dist-web`(`KIMI_CODE_REPO` 指定目标,默认 `../kimi-code-2`)。 +- `scripts/sync-web-to-kimi-code.mjs`:`apps/web/dist` → `/apps/kimi-code/dist-web`(`KIMI_CODE_REPO` 必传,指定目标 checkout)。 ## 常用命令 diff --git a/README.md b/README.md index 9c33c0a6a..9edebe4f2 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Kimi Code 客户端仓库:桌面端(`apps/desktop`)+ Web UI(`apps/web` - **本仓库是 Web UI 和桌面端源码的主仓库**。这两个应用此前住在 kimi-code 仓库(`apps/kimi-web` / `apps/kimi-desktop`),今后 web/desktop 的开发都在本仓库进行。 - **kimi-code 是 CLI / server / agent 的主仓库**,以 submodule 钉在本仓库根目录,其 `packages/*` 通过 pnpm workspace 直接以源码链接进来——desktop 的 Electron 主进程会把其中的 server(`kap-server`、`agent-core-v2` 等)打包为内嵌 server。 -- **web 产物分发**:`pnpm sync:web`(`scripts/sync-web-to-kimi-code.mjs`)把 `apps/web/dist` 拷贝到一个 kimi-code checkout 的 `apps/kimi-code/dist-web`,用 `KIMI_CODE_REPO` 指定目标 checkout(默认 `../kimi-code-2`)。 +- **web 产物分发**:`pnpm sync:web`(`scripts/sync-web-to-kimi-code.mjs`)把 `apps/web/dist` 拷贝到一个 kimi-code checkout 的 `apps/kimi-code/dist-web`,用 `KIMI_CODE_REPO` 指定目标 checkout(必传)。 ## 快速开始 diff --git a/apps/desktop/scripts/copy-web-dist.mjs b/apps/desktop/scripts/copy-web-dist.mjs deleted file mode 100644 index 4dfdbd912..000000000 --- a/apps/desktop/scripts/copy-web-dist.mjs +++ /dev/null @@ -1,27 +0,0 @@ -import { cp, rm, stat } from 'node:fs/promises'; -import { dirname, resolve } from 'node:path'; -import { fileURLToPath } from 'node:url'; - -const desktopRoot = resolve(dirname(fileURLToPath(import.meta.url)), '..'); -const repoRoot = resolve(desktopRoot, '../..'); -const source = resolve(repoRoot, 'apps/web/dist'); -const target = resolve(desktopRoot, 'web-dist'); - -async function assertBuiltWeb() { - try { - const info = await stat(resolve(source, 'index.html')); - if (!info.isFile()) { - throw new Error('index.html is not a file'); - } - } catch { - throw new Error( - `Web build output was not found at ${source}. Run \`pnpm --filter @moonshot-ai/kimi-web run build\` first.`, - ); - } -} - -await assertBuiltWeb(); -await rm(target, { recursive: true, force: true }); -await cp(source, target, { recursive: true }); - -console.log(`Copied web assets to ${target}`); diff --git a/scripts/sync-web-to-kimi-code.mjs b/scripts/sync-web-to-kimi-code.mjs index 581ef3aa8..f3fa66d5e 100644 --- a/scripts/sync-web-to-kimi-code.mjs +++ b/scripts/sync-web-to-kimi-code.mjs @@ -4,12 +4,20 @@ import { fileURLToPath } from 'node:url'; const repoRoot = resolve(dirname(fileURLToPath(import.meta.url)), '..'); const source = resolve(repoRoot, 'apps/web/dist'); -// Dev default: sibling checkout `../kimi-code-2` (the kimi-code repo where the -// split branch lives). Override with KIMI_CODE_REPO to point at any checkout. +// Target kimi-code checkout is REQUIRED via KIMI_CODE_REPO — there is no +// default, so a sync never lands in the wrong clone. const kimiCodeRepo = process.env.KIMI_CODE_REPO ? resolve(process.env.KIMI_CODE_REPO) - : resolve(repoRoot, '..', 'kimi-code-2'); -const target = resolve(kimiCodeRepo, 'apps/kimi-code/dist-web'); + : undefined; + +if (kimiCodeRepo === undefined) { + throw new Error( + '请设置 KIMI_CODE_REPO 指向你的 kimi-code 仓 checkout,例如:KIMI_CODE_REPO=~/code/kimi-code-5 pnpm sync:web', + ); +} + +const appRoot = resolve(kimiCodeRepo, 'apps/kimi-code'); +const target = resolve(appRoot, 'dist-web'); async function assertBuiltWeb() { try { @@ -19,14 +27,28 @@ async function assertBuiltWeb() { } } catch { throw new Error( - `Web build output was not found at ${source}. Run \`pnpm --filter @moonshot-ai/kimi-web run build\` first.`, + `未找到 web 构建产物 ${source}/index.html,请先运行 \`pnpm --filter @moonshot-ai/kimi-web run build\`。`, + ); + } +} + +async function assertKimiCodeRepo() { + try { + const info = await stat(appRoot); + if (!info.isDirectory()) { + throw new Error('apps/kimi-code is not a directory'); + } + } catch { + throw new Error( + `KIMI_CODE_REPO 不像一个 kimi-code 仓 checkout:未找到 ${appRoot}。`, ); } } await assertBuiltWeb(); +await assertKimiCodeRepo(); await rm(target, { recursive: true, force: true }); await cp(source, target, { recursive: true }); -console.log(`Synced web assets to kimi-code SEA bundle: ${target}`); -console.log('Next: commit the dist-web snapshot inside the kimi-code repo and open a PR.'); +console.log(`已同步 web 产物到:${target}`); +console.log('提醒:完成后在 kimi-code 仓提交 dist-web 变更并创建 PR(该仓 gitignore dist-web,需 `git add -f`)。');