Skip to content

Commit 7bc1c49

Browse files
committed
feat(release): 给 publish.yml 加 bailian-kb-dsh 通道
复用同一个 Publish workflow 入口(package 下拉多一项 bailian-kb-dsh),路由到 独立的 publish-kb-dsh.mjs 处理: - 版本读自身 package.json(不广播全套 bl 版本) - stable 打 bailian-kb-dsh-v<version> tag(与 bl 的 v<version> 错开命名空间) - channel 临时 bump 到 0.0.0-beta-<sha>-<stamp>(形态与 bl channel 一致), finally 还原 package.json - 走自身的 tsc + tsdown build,无 binary,无 OSS CDN - 复用 lib/git.mjs / lib/npm.mjs / lib/proc.mjs 三个薄工具 - 复用 workflow 入口 UI 与 setup 步骤(checkout / pnpm / node 24 / gitleaks / install),stable 走 environment: production Required Reviewers gate 不复用 publish-stable.mjs / publish-channel.mjs:它们的 loadAndValidatePackages 会广播 core 版本给全套锁步包并强校验一致性,把 kb-dsh 塞进去第一步就 throw。 故意分开是为了保住这个隔离。 本地 --dry-run 端到端跑通:build → 幂等性查重 → pack + publint + gitleaks → pnpm publish --tag latest|<channel> --provenance --dry-run;channel 模式的 finally 还原后 git diff 干净。 文档:dsh-plugin.md 补发布小节 + 已知待办(publint 那条 web bundle CJS/ESM warning);publish.md 加 bailian-kb-dsh 定位;packages.mjs 与 AGENTS.md 的 注释同步指向新的 job 与 script 名。
1 parent a393bdc commit 7bc1c49

11 files changed

Lines changed: 309 additions & 69 deletions

File tree

.github/workflows/publish.yml

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ on:
1010
options:
1111
- bailian-cli
1212
- knowledge-studio-cli
13+
- bailian-kb-dsh
1314
mode:
1415
description: "Publish mode"
1516
required: true
@@ -18,7 +19,7 @@ on:
1819
- channel
1920
- stable
2021
channel:
21-
description: "Required when mode=channel. npm dist-tag only (lowercase, digits, dashes), e.g. mcp / plugin / sync-release. bailian-cli binary CDN always overwrites sync-release.json; knowledge-studio-cli is npm-only."
22+
description: "Required when mode=channel. npm dist-tag only (lowercase, digits, dashes), e.g. mcp / plugin / sync-release. bailian-cli binary CDN always overwrites sync-release.json; knowledge-studio-cli and bailian-kb-dsh are npm-only."
2223
required: false
2324
type: string
2425

@@ -28,7 +29,7 @@ concurrency:
2829

2930
jobs:
3031
publish-stable:
31-
if: inputs.mode == 'stable'
32+
if: inputs.mode == 'stable' && inputs.package != 'bailian-kb-dsh'
3233
name: publish stable (${{ inputs.package }}) to npm + binary + tag
3334
runs-on: ubuntu-latest
3435
environment: production # Required Reviewers gate
@@ -83,7 +84,7 @@ jobs:
8384
run: node tools/release/publish-stable.mjs ${{ inputs.package == 'knowledge-studio-cli' && '--knowledge' || '' }}
8485

8586
publish-channel:
86-
if: inputs.mode == 'channel'
87+
if: inputs.mode == 'channel' && inputs.package != 'bailian-kb-dsh'
8788
name: publish channel (${{ inputs.package }}) to npm + binary
8889
runs-on: ubuntu-latest
8990
permissions:
@@ -138,3 +139,49 @@ jobs:
138139
BAILIAN_RELEASE_PREFIX: ${{ secrets.BAILIAN_RELEASE_PREFIX }}
139140
BAILIAN_STATIC_PREFIX: ${{ secrets.BAILIAN_STATIC_PREFIX }}
140141
run: node tools/release/publish-channel.mjs ${{ inputs.package == 'knowledge-studio-cli' && '--knowledge' || '' }} --channel "${{ inputs.channel }}"
142+
143+
# bailian-kb-dsh is the dsh plugin (downstream host adapter): independent version,
144+
# tsc + tsdown build, npm-only. It shares this workflow's entry UI and setup steps
145+
# but NOT publish-stable.mjs / publish-channel.mjs — those broadcast one version
146+
# across the locked bl package set and produce binary artifacts, neither of which
147+
# applies here. See docs/agents/dsh-plugin.md.
148+
publish-kb-dsh:
149+
if: inputs.package == 'bailian-kb-dsh'
150+
name: publish ${{ inputs.mode }} (bailian-kb-dsh) to npm
151+
runs-on: ubuntu-latest
152+
# stable goes through the Required Reviewers gate, same as the bl stable job;
153+
# channel stays ungated so dist-tag drops need no approval.
154+
environment: ${{ inputs.mode == 'stable' && 'production' || '' }}
155+
permissions:
156+
contents: write # push the bailian-kb-dsh-v<version> tag (stable only)
157+
id-token: write # OIDC for npm Trusted Publishing + provenance
158+
steps:
159+
- name: Require channel input
160+
if: ${{ inputs.mode == 'channel' && inputs.channel == '' }}
161+
run: |
162+
echo "::error::mode=channel requires the workflow input \"channel\" (npm dist-tag, e.g. mcp / plugin). Leave mode=stable if you do not need a dist-tag."
163+
exit 1
164+
165+
- uses: actions/checkout@v6
166+
167+
- uses: pnpm/action-setup@v6
168+
169+
- uses: actions/setup-node@v6
170+
with:
171+
node-version: "24"
172+
cache: pnpm
173+
registry-url: "https://registry.npmjs.org/"
174+
175+
- name: Install gitleaks
176+
run: |
177+
set -euo pipefail
178+
GITLEAKS_VERSION=8.21.2
179+
curl -sSfL \
180+
"https://github.com/gitleaks/gitleaks/releases/download/v${GITLEAKS_VERSION}/gitleaks_${GITLEAKS_VERSION}_linux_x64.tar.gz" \
181+
| sudo tar -xz -C /usr/local/bin gitleaks
182+
gitleaks version
183+
184+
- run: pnpm install --frozen-lockfile
185+
186+
- name: publish-kb-dsh
187+
run: node tools/release/publish-kb-dsh.mjs ${{ inputs.mode == 'channel' && format('--channel "{0}"', inputs.channel) || '' }}

AGENTS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ Skill / 命令手册随 `skills/bailian-*/` 经 `bl skill init` 安装(装齐
8686

8787
源码包的 `version` 当前保持一致: `packages/core``packages/runtime``packages/commands``packages/cli``packages/kscli`。做版本 bump 时一动多动。release 工具当前强校验 / 发布范围以 `tools/release/lib/packages.mjs` 为准;把新包纳入发布前必须同步该清单和 [publish.md](docs/agents/publish.md)
8888

89-
**例外**: `packages/bailian-kb-dsh` 不参与这个锁步(独立 `0.1.x`,跟随 dsh rc 节奏),也不在 release 白名单里,由独立 workflow 发布
89+
**例外**: `packages/bailian-kb-dsh` 不参与这个锁步(独立 `0.1.x`,跟随 dsh rc 节奏),也不在 release 白名单里;它走 `publish.yml``package=bailian-kb-dsh` 的独立 job(`tools/release/publish-kb-dsh.mjs`)
9090

9191
### 2. 分层边界
9292

docs/agents/dsh-plugin.md

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212

1313
它是**下游宿主适配层**:依赖方向朝外(消费 `bl` CLI 与百炼 API,装进 DeepSeek Harness 运行),不是 `core → runtime → commands → 产品入口` 这条链上的一环。由此带来四条与 `packages/*` 通行约定的**故意偏离**
1414

15-
|| 本包 | 其他包 | 原因 |
16-
| -------- | -------------------------------------- | ------------------------------------ | ------------------------------------------------------------------------------------------------ |
17-
| 版本 | 独立 `0.1.x` | core/runtime/commands/cli/kscli 锁步 | 跟随 dsh 的 rc 节奏,与 `bl` 发版无关;不在 `tools/release/lib/packages.mjs` 白名单里 |
18-
| 构建 | `tsc` + `tsdown` | `vp pack` | 浏览器半需要 `__ModuleLoader__` banner/footer 与 lightningcss CSS Modules 内联,`vp pack` 产不出 |
19-
| 发布 | `.github/workflows/publish-kb-dsh.yml` | `publish.yml` | 不在 `bailian-cli` 依赖闭包内,走独立通道 |
20-
| tsconfig | 三个 | 一个 | 见下 |
15+
|| 本包 | 其他包 | 原因 |
16+
| -------- | ---------------------------------------------------------------------- | --------------------------------------------- | ------------------------------------------------------------------------------------------------ |
17+
| 版本 | 独立 `0.1.x` | core/runtime/commands/cli/kscli 锁步 | 跟随 dsh 的 rc 节奏,与 `bl` 发版无关;不在 `tools/release/lib/packages.mjs` 白名单里 |
18+
| 构建 | `tsc` + `tsdown` | `vp pack` | 浏览器半需要 `__ModuleLoader__` banner/footer 与 lightningcss CSS Modules 内联,`vp pack` 产不出 |
19+
| 发布 | `publish.yml``package=bailian-kb-dsh` job,走 `publish-kb-dsh.mjs` | `publish.yml` `publish-stable/channel.mjs` | 不在 `bailian-cli` 依赖闭包内,版本与构建都不同,不能与 `bl` 共用同一条 script |
20+
| tsconfig | 三个 | 一个 | 见下 |
2121

2222
## tsconfig 三件套(改动前先读)
2323

@@ -78,6 +78,39 @@ dsh plugin --profile dev add <本仓库>/packages/bailian-kb-dsh
7878
dsh --profile dev --dump-config # 应能看到 tool-bailian-kb row
7979
```
8080

81+
## 发布
82+
83+
入口与 `bl` 共用:Actions → **Publish**`package=bailian-kb-dsh` + `mode=stable|channel`。共享的只有 workflow 入口与 checkout/pnpm/node/gitleaks/install 几步 setup;它走自己的 `tools/release/publish-kb-dsh.mjs`****复用 `publish-stable.mjs` / `publish-channel.mjs`
84+
85+
| | stable | channel |
86+
| --------- | ------------------------------------------------------------------- | ------------------------------------------------------- |
87+
| 版本 | `package.json` 当前值(先手动 bump 并提交) | 临时 `0.0.0-beta-<sha>-<stamp>``finally` 还原,不提交 |
88+
| npm tag | `latest` | 你传的 `channel`(dist-tag) |
89+
| preflight | 工作区干净 + 必须在 `main` ||
90+
| git tag | `bailian-kb-dsh-v<version>`(与 `bl``v<version>` 错开命名空间) | 不打 tag |
91+
| 审批 | `environment: production`(Required Reviewers) ||
92+
| 产物 | npm only | npm only |
93+
94+
两种模式都跑:`build`(tsc + web 隔离检查 + tsdown)→ 幂等性查重 → `pnpm pack``publint` + `gitleaks``pnpm publish --provenance`
95+
96+
本地验证(不真发,需本地装 gitleaks):
97+
98+
```sh
99+
node tools/release/publish-kb-dsh.mjs --dry-run
100+
node tools/release/publish-kb-dsh.mjs --dry-run --channel dsh-beta
101+
```
102+
103+
### 首发前的 npm 侧前置(仓外操作,一次性)
104+
105+
1. 占住包名 `bailian-kb-dsh`(OIDC Trusted Publishing 无法给不存在的包首发)
106+
2. 在 npm 包设置里绑 Trusted Publisher:仓库 `modelstudioai/cli`、workflow `publish.yml`;stable 走 environment `production`,channel 无 environment
107+
108+
未完成这两步前触发 workflow 会在 `pnpm publish --provenance` 这一步失败(前面的 build / scan 仍会正常跑完)。
109+
110+
### 已知待办
111+
112+
- `publint` 会报一条 warning:`exports["./client"]` 是 CJS 但包为 `type: module`,建议改 `.cjs` 扩展名。这是迁移前就存在的状态,warning 不阻断发布;真要改得同时动宿主按 `exports["./client"]` 解析 `/plugins/<id>/client.js` 的 URL 契约,需 dsh 侧一起验证,不要单方面改
113+
81114
## 相关文档
82115

83116
- 设计与实现计划归档:[docs/kb-dsh/](../kb-dsh/)

docs/agents/publish.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ publish-stable.mjs / publish-channel.mjs ← 唯一发版入口
2424

2525
`tools/release/lib/binary-release.mjs` 等是实现,一般不要单独当发版入口(调试可用)。
2626

27+
### bailian-kb-dsh(独立版本、npm-only)
28+
29+
同一个 Publish 入口,`package=bailian-kb-dsh`。它走单独的 `tools/release/publish-kb-dsh.mjs`,不复用 `publish-stable.mjs` / `publish-channel.mjs`(版本独立、无 binary、无 OSS CDN)。详见 [dsh-plugin.md](dsh-plugin.md#发布)
30+
2731
两种模式:
2832

2933
| 模式 | 用途 | 触发方式 |

packages/bailian-kb-dsh/src/bl-cli.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
/**
2-
* Host-side bridge to the locally installed `bl` CLI (bailian-cli). The CLI's
3-
* credential file (`~/.bailian/config.json`) is its documented "output": the
4-
* console browser login (`bl auth login --console`) validates the api key the
5-
* console issues and persists it there in plain JSON — no CLI command ever
6-
* echoes the value back (auth status / config show both mask), so reading the
7-
* file is the only way to obtain it programmatically.
2+
* Host-side bridge to the locally installed `bl` CLI (bailian-cli): reads the
3+
* credentials an earlier `bl auth login` already stored, so a user who has
4+
* already set the CLI up does not have to configure this plugin a second time.
85
*
9-
* Starting a login is NOT done through the CLI: it hard-codes
10-
* `needApiKey: !hasApiKey` and so refuses to have a fresh key issued once any
11-
* key is stored. See `console-login.ts`, which speaks the callback protocol
12-
* directly and always asks for one.
6+
* Reading the CLI's credential file (`~/.bailian/config.json`) is the only way
7+
* to obtain the value programmatically — CLI commands mask stored keys on
8+
* output, so there is nothing to parse from stdout.
9+
*
10+
* Starting a login is NOT done through the CLI; see `console-login.ts`.
1311
*/
1412

1513
import { readFileSync } from "node:fs";

packages/bailian-kb-dsh/src/console-login.ts

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
11
/**
2-
* Self-contained Bailian console login: the plugin speaks the console's
3-
* callback protocol itself instead of shelling out to `bl auth login --console`.
2+
* Self-contained Bailian console login: the plugin drives the console's browser
3+
* login itself and persists what comes back, rather than shelling out to the
4+
* `bl` CLI.
45
*
5-
* Why not the CLI: it hard-codes `needApiKey: !hasApiKey`, so once any api key
6-
* is stored it never asks the console to issue a fresh one — you end up pairing
7-
* an old account's key with a new account's workspace id, and nothing warns
8-
* you. Driving the flow here lets us always pass `needapikey=true`, so the key
9-
* and the workspace id both come from the account that just signed in, and the
10-
* values land straight in the dsh stores without transiting the CLI's
11-
* `~/.bailian/config.json`.
6+
* Driving the flow here lets it always request a freshly issued api key, so the
7+
* key and the workspace id both come from the account that just signed in, and
8+
* the values land straight in the dsh stores.
129
*
13-
* Protocol (mirrors the CLI's implementation): bind a loopback-only port, open
14-
* `<console>/console-login?notice=127.0.0.1:<port>?state=<state>&needapikey=true`,
15-
* then accept one callback carrying the credentials as query parameters or a
16-
* JSON / form-encoded body. Note the URL shape: `state` is part of the `notice`
17-
* value (separated by `?`), not a sibling query parameter.
10+
* Shape of the flow: bind a loopback-only port, open the console login page
11+
* pointed at that port, then accept one callback carrying the credentials as
12+
* query parameters or a JSON / form-encoded body.
1813
*/
1914

2015
import { execFile } from "node:child_process";
@@ -30,12 +25,12 @@ const CONSOLE_ORIGINS: Record<string, string> = {
3025
/** How long the loopback listener waits for the browser callback. */
3126
const LOGIN_TIMEOUT_MS = 15 * 60 * 1000;
3227

33-
/** Upper bound on a callback body, matching the CLI's limit. */
28+
/** Upper bound on a callback body. */
3429
const MAX_CALLBACK_BODY = 65536;
3530

3631
/** Credentials the console callback can carry. */
3732
export interface ConsoleLoginCredentials {
38-
/** Freshly issued DashScope api key (`needapikey=true` asks for one). */
33+
/** Freshly issued DashScope api key. */
3934
apiKey?: string;
4035
/** Workspace id of the account that signed in. */
4136
workspaceId?: string;
@@ -95,8 +90,8 @@ function readBody(req: http.IncomingMessage): Promise<string> {
9590

9691
/**
9792
* Parse a callback body as JSON (optionally wrapped in `data`) or as form
98-
* encoding. Content-type is a hint only — the CLI falls back to trying both,
99-
* and so do we, because the console has shipped both shapes.
93+
* encoding. Content-type is a hint only: both shapes occur in practice, so both
94+
* are attempted.
10095
* @param raw - the raw request body.
10196
* @returns the flattened fields; an unparseable body yields no fields.
10297
*/
@@ -278,8 +273,8 @@ export async function startConsoleLogin(opts: {
278273
return { status: "failed", reason };
279274
}
280275

281-
// `state` rides inside the `notice` value, and `needapikey=true` is the whole
282-
// point: it makes the console issue a key for the account signing in.
276+
// Ask for a freshly issued key, so the key and the workspace id cannot end up
277+
// belonging to two different accounts.
283278
const origin =
284279
(opts.site !== undefined ? CONSOLE_ORIGINS[opts.site] : undefined) ?? CONSOLE_ORIGINS.domestic!;
285280
const loginUrl =

packages/bailian-kb-dsh/src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -561,9 +561,9 @@ export function apply(ctx: Context, config: Config): void {
561561
sendJson(res, 200, consoleLoginState());
562562
return;
563563
}
564-
// Drive the console flow ourselves with `needapikey=true`, so the key
565-
// and the workspace id both belong to the account signing in now.
566-
// Persisting here keeps the plain key on the host.
564+
// Drive the console flow ourselves, requesting a freshly issued key,
565+
// so the key and the workspace id both belong to the account signing
566+
// in now. Persisting here keeps the plain key on the host.
567567
const started = await startConsoleLogin({
568568
onComplete: async (credentials) => {
569569
const written: string[] = [];

packages/bailian-kb-dsh/src/services.ts

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,33 @@
22
* Retrieval-service discovery for the plugin's internal cache. Not a model tool:
33
* see `KB_PATHS.serviceList`.
44
*
5-
* Two verified server facts shape this module:
6-
* - `page_size` is capped at 100 regardless of what is requested, so a workspace
7-
* with hundreds of services needs many round trips. Test/CI workspaces reach
8-
* the high hundreds (913 observed), which is pure noise for routing, so this
9-
* module stops after {@link MAX_PAGES} and reports the shortfall instead of
10-
* faithfully paging through it.
11-
* - `agent_status: 'deployed'` is honored and means "deployed or edited". Only
12-
* those are callable by the default agent version, so drafts never reach the
13-
* model.
5+
* Listing is paged, and a workspace can hold far more services than are useful
6+
* for routing, so this module stops after {@link MAX_PAGES} and reports the
7+
* shortfall rather than paging through everything. Only deployed services are
8+
* requested: anything else is not callable by the default service version, so it
9+
* would be noise in the catalog the model reads.
1410
*/
1511

1612
import type { ServiceListResponse, ServiceScene } from "./api-types.js";
1713
import type { KbClient } from "./client.js";
1814
import { KB_PATHS } from "./endpoints.js";
1915

20-
/** Server page-size maximum; larger requests are silently clamped to this. */
16+
/** Page size requested per listing call. */
2117
const PAGE_SIZE = 100;
2218

23-
/** Pages fetched per scene before reporting truncation (200 rows is far past the useful range). */
19+
/** Pages fetched per scene before reporting truncation; well past the useful routing range. */
2420
const MAX_PAGES = 2;
2521

2622
/** One deployed retrieval or Q&A service, reduced to the fields that inform routing. */
2723
export interface ServiceEntry {
2824
agent_id: string;
2925
agent_name: string;
3026
scene: ServiceScene;
31-
/** `deployed` or `edited` — both are callable by the default version. */
27+
/** Deployment status as reported for the service; only callable states are listed. */
3228
status: string;
3329
/** Last modification timestamp; the only signal for "which of these is in use". */
3430
modify_time?: string;
35-
/** Absent until the backend adds a description to the list response. */
31+
/** Service description, when the listing provides one. */
3632
description?: string;
3733
}
3834

0 commit comments

Comments
 (0)