feat(shellEnv): 注册并导出 Bailian 工作空间 ID 环境变量

- 新增 ShellEnvRegistration 接口定义,避免对主包依赖
- 为上下文添加 shellEnv 注册功能支持
- 在注入阶段注册 Bailian 工作空间 ID 环境变量
- 使管理 CLI 命令可访问解析后的工作空间 ID
- 确保子进程环境变量继承设置服务解析结果
This commit is contained in:
zeyu.fz
2026-08-17 19:30:09 +08:00
parent 0ef7c829de
commit f36e044119
+28
View File
@@ -19,11 +19,20 @@ interface WebRoute {
path: string
handler: (req: IncomingMessage, res: ServerResponse) => void | Promise<void>
}
/** Shell-environment registration shape (declared inline to avoid a host-package dependency). */
interface ShellEnvRegistration {
name: string
variables: Record<string, { description: string }>
resolve: () => Record<string, string | undefined>
}
declare module '@deepseek-ai/cordis' {
interface Context {
webServer: {
register(route: WebRoute): () => void
}
shellEnv: {
register(registration: ShellEnvRegistration): void
}
}
}
@@ -184,6 +193,25 @@ export function apply(ctx: Context, config: Config): void {
}
registerSkill(ctx)
// Export the resolved workspace id as a shell environment variable so
// management CLI commands (`bl knowledge list`, `kscli kb list`, etc.)
// running in bash can see the value the settings service resolved.
// Without this, the settings.yaml value is invisible to child processes.
ctx.inject(['shellEnv'], (envCtx) => {
envCtx.shellEnv.register({
name: 'bailian-kb',
variables: {
BAILIAN_WORKSPACE_ID: {
description: 'Bailian workspace id resolved from settings (Settings → 百炼知识库) or credentials.',
},
},
resolve: () => {
const wsId = current().workspaceId
return wsId ? { BAILIAN_WORKSPACE_ID: wsId } : {}
},
})
})
// Bridge routes let the browser settings page read and write the resolved
// section without riding the settings wire (which requires an apiproxy
// allowlist entry the composition does not grant out-of-tree namespaces).