diff --git a/.env.example b/.env.example index 477328c..b4ea507 100644 --- a/.env.example +++ b/.env.example @@ -21,3 +21,19 @@ # MCP Server 总开关(默认关闭) # HOSE_USE_MCP_ENABLED=true + +# Piper / ScriptEngine 集群地址(默认 piper.ekuaibao.com / piper-test.ekuaibao.net) +# 私有化或多集群部署可覆盖;影响工作流引擎客户端、Webhook 触发 URL 与灰度节点开通。 +# HOSE_PIPER_BASE_URL=https://piper.ekuaibao.com +# HOSE_PIPER_TEST_BASE_URL=https://piper-test.ekuaibao.net + +# AI PRO 离线凭证(默认 ~/.config/hose-use/aipro-license.token,0600) +# 仅 hose-aipro 需要凭证;hose-use 是免费功能,不受凭证管辖。 +# HOSE_AIPRO_LICENSE_FILE=~/.config/hose-use/aipro-license.token + +# 签发方专用(只在本机签发凭证时使用,客户端运行不需要) +# HOSE_AIPRO_LICENSE_PRIVATE_KEY= +# HOSE_AIPRO_LICENSE_PRIVATE_FILE=~/.config/hose-use/license/private.pem + +# 灰度节点开通的可选管理员密码(设置后需 --password) +# HOSE_ADMIN_PASSWORD=<管理员密码> diff --git a/.workbuddy/memory/MEMORY.md b/.workbuddy/memory/MEMORY.md index 0b0a3a5..7abb3bb 100644 --- a/.workbuddy/memory/MEMORY.md +++ b/.workbuddy/memory/MEMORY.md @@ -15,6 +15,11 @@ - 已发布流程的改动用 `node add` / `node edit`(PUT 即生效),**不要再 publish**,否则报「流程已发布,建议刷新页面重新加载」。 - 删除流程前必须先 `workflow toggle --state=0` 停用。 +## 功能授权边界(用户 2026-11-05 明确) + +- **`hose-use` 是免费功能**,不需要凭证、不受任何激活门禁管辖。 +- **AI PRO 离线凭证只管 `hose-aipro`**,门禁挂在 `runAiProCli`。不要把「`hose-use` 写命令未受凭证约束」当成安全缺口或待办——这是设计,不是漏实现。需要凭证的是 AI PRO 审批能力,不是企业平台 CLI。 + ## 仓库协作 - 双远端:`origin` = GitHub(主),`home` = Gitea(git.ying-qing.cn)。发布顺序先 `home` 再 `origin`。 diff --git a/README.md b/README.md index 1be68cb..c385921 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,18 @@ hose-use version 凭证有两条约束:当前二进制版本不得高于其 `maxVersion`,当前时间不得晚于其 `exp`。完整流程与失败处理见 [hose-aipro Skill](./skills/hose-aipro/SKILL.md) 的「首次安装与激活」章节——Agent 自行安装时以该文档为准。 +**`hose-use` 是免费功能,不需要凭证、不受任何激活门禁管辖;凭证只作用于 `hose-aipro`。** + +### 环境变量 + +全部可选,完整清单见 [.env.example](./.env.example)。几个与发布相关的: + +| 变量 | 作用 | +|---|---| +| `HOSE_PIPER_BASE_URL` / `HOSE_PIPER_TEST_BASE_URL` | 覆盖标准 / 测试 Piper 集群地址,影响工作流引擎客户端、Webhook 触发 URL 与灰度节点开通 | +| `HOSE_AIPRO_LICENSE_FILE` | AI PRO 凭证文件路径(默认 `~/.config/hose-use/aipro-license.token`,0600) | +| `HOSE_AIPRO_LICENSE_PRIVATE_KEY` / `HOSE_AIPRO_LICENSE_PRIVATE_FILE` | 仅签发方使用,客户端运行不需要 | + --- ### CLI 常用命令速查 (`hose-use`) diff --git a/skills/hose-aipro/SKILL.md b/skills/hose-aipro/SKILL.md index 7fc3c4b..bdcf639 100644 --- a/skills/hose-aipro/SKILL.md +++ b/skills/hose-aipro/SKILL.md @@ -37,6 +37,7 @@ metadata: > [!IMPORTANT] > AI PRO **默认不激活**。装完二进制后,业务命令一律返回 `AIPRO_NOT_ACTIVATED`。 > **客户不碰命令行**:客户只会把凭证粘贴到与 Agent 的对话框里;申请引导、执行激活、验证结果全部由 Agent 完成。 +> **凭证只作用于 `hose-aipro`**;`hose-use` 是免费功能,无需凭证、不受此门禁管辖。 > 凭证**不能由 Agent 自行生成**——客户端只内嵌验签公钥,私钥在服务方手里。 > 不要尝试绕过门禁、不要改系统时间、不要伪造或拼接凭证。 diff --git a/src/core/http/piper-endpoints.test.ts b/src/core/http/piper-endpoints.test.ts new file mode 100644 index 0000000..1344977 --- /dev/null +++ b/src/core/http/piper-endpoints.test.ts @@ -0,0 +1,32 @@ +import { afterEach, describe, expect, test } from "bun:test"; +import { resolvePiperBaseUrl } from "./piper-endpoints.js"; + +const KEYS = ["HOSE_PIPER_BASE_URL", "HOSE_PIPER_TEST_BASE_URL"] as const; + +afterEach(() => { + for (const key of KEYS) delete process.env[key]; +}); + +describe("Piper 集群地址", () => { + test("未设置环境变量时使用默认地址", () => { + expect(resolvePiperBaseUrl()).toBe("https://piper.ekuaibao.com"); + expect(resolvePiperBaseUrl(true)).toBe("https://piper-test.ekuaibao.net"); + }); + + test("HOSE_PIPER_BASE_URL 覆盖标准集群并去掉尾部斜线", () => { + process.env.HOSE_PIPER_BASE_URL = "https://piper.internal.example///"; + expect(resolvePiperBaseUrl()).toBe("https://piper.internal.example"); + expect(resolvePiperBaseUrl(true)).toBe("https://piper-test.ekuaibao.net"); + }); + + test("HOSE_PIPER_TEST_BASE_URL 只覆盖测试集群", () => { + process.env.HOSE_PIPER_TEST_BASE_URL = "https://piper-test.internal.example/"; + expect(resolvePiperBaseUrl(true)).toBe("https://piper-test.internal.example"); + expect(resolvePiperBaseUrl()).toBe("https://piper.ekuaibao.com"); + }); + + test("空白值回退默认", () => { + process.env.HOSE_PIPER_BASE_URL = " "; + expect(resolvePiperBaseUrl()).toBe("https://piper.ekuaibao.com"); + }); +}); diff --git a/src/core/http/piper-endpoints.ts b/src/core/http/piper-endpoints.ts new file mode 100644 index 0000000..6ed2e3d --- /dev/null +++ b/src/core/http/piper-endpoints.ts @@ -0,0 +1,24 @@ +/** + * Piper / ScriptEngine 集群地址收口。 + * + * 保持轻量(不依赖 ky、不触发网络),供 core、domains 各层共用。 + * 旧版 HOSE_GRAY_GATEWAY_URL 逃生口在 e562ae9 移除后一直缺位,这里补齐。 + */ +const DEFAULT_PIPER_BASE_URL = "https://piper.ekuaibao.com"; +const DEFAULT_PIPER_TEST_BASE_URL = "https://piper-test.ekuaibao.net"; + +function envBaseUrl(value: string | undefined, fallback: string): string { + const normalized = value?.trim().replace(/\/+$/, ""); + return normalized || fallback; +} + +/** 运行时解析,每次读取环境变量,便于私有化/多集群部署与测试覆盖。 */ +export function resolvePiperBaseUrl(isTest = false): string { + return isTest + ? envBaseUrl(process.env.HOSE_PIPER_TEST_BASE_URL, DEFAULT_PIPER_TEST_BASE_URL) + : envBaseUrl(process.env.HOSE_PIPER_BASE_URL, DEFAULT_PIPER_BASE_URL); +} + +/** 兼容历史常量导入;值为进程启动时的解析结果。 */ +export const SCRIPT_ENGINE_BASE_URL = resolvePiperBaseUrl(false); +export const SCRIPT_ENGINE_TEST_BASE_URL = resolvePiperBaseUrl(true); diff --git a/src/core/http/script-engine-client.ts b/src/core/http/script-engine-client.ts index ade1367..b449730 100644 --- a/src/core/http/script-engine-client.ts +++ b/src/core/http/script-engine-client.ts @@ -16,10 +16,17 @@ import { setCorpTokens, } from "../auth/token-store.js"; -export const SCRIPT_ENGINE_BASE_URL = "https://piper.ekuaibao.com"; +import { + resolvePiperBaseUrl, + SCRIPT_ENGINE_BASE_URL, + SCRIPT_ENGINE_TEST_BASE_URL, +} from "./piper-endpoints.js"; -/** 测试 Piper 集群,仅供显式 --is-test 的工作流灰度开通使用。 */ -export const SCRIPT_ENGINE_TEST_BASE_URL = "https://piper-test.ekuaibao.net"; +export { + resolvePiperBaseUrl, + SCRIPT_ENGINE_BASE_URL, + SCRIPT_ENGINE_TEST_BASE_URL, +} from "./piper-endpoints.js"; // 兼容历史常量名 export const PIPER_BASE_URL = SCRIPT_ENGINE_BASE_URL; @@ -120,7 +127,7 @@ export async function getScriptEngineClient( const cachedJwt = mem.jwt; const cachedHoseToken = mem.hoseToken; return createAuthClient({ - prefixUrl: SCRIPT_ENGINE_BASE_URL, + prefixUrl: resolvePiperBaseUrl(), getHeaders: () => { const headers: Record = { Authorization: `Bearer ${scriptEngineMemoryCache.get(cacheKey)?.jwt ?? cachedJwt}`, diff --git a/src/domains/platform/workflow/transport/README.transport.md b/src/domains/platform/workflow/transport/README.transport.md index 17c95b0..cef74a9 100644 --- a/src/domains/platform/workflow/transport/README.transport.md +++ b/src/domains/platform/workflow/transport/README.transport.md @@ -21,7 +21,7 @@ | 项目 | 说明 | |---|---| | 换票 | 通过企业 `baseUrl` 的 `/api/engine/realm/$EASO/actions/jwt` 获取 EASO JWT;复用 `fetchEasoJwt`,去除 `baseUrl` 末尾斜线 | -| 开通请求 | 携带 EASO JWT 直接 POST 到 Piper 的 `/api/easo/dsl/corporation`;默认使用 `SCRIPT_ENGINE_BASE_URL`,`isTest: true` 时使用 `https://piper-test.ekuaibao.net`。每个企业的工作流只在其中一个 Piper 环境,不会同时支持两者;请求失败时不自动切换 | +| 开通请求 | 携带 EASO JWT 直接 POST 到 Piper 的 `/api/easo/dsl/corporation`;地址经 `resolvePiperBaseUrl(isTest)` 解析,可用 `HOSE_PIPER_BASE_URL` / `HOSE_PIPER_TEST_BASE_URL` 覆盖,常量收口在 `core/http/piper-endpoints.ts`。每个企业的工作流只在其中一个 Piper 环境,不会同时支持两者;请求失败时不自动切换 | | payload | 由编排层 `catalog/catalog.ts` 显式构造;固定附带 `recalculate-the-approval-flow`、`ui-notification`、`start`,dry-run 与成功输出均会展示 | | 成功判定 | 传输层只做响应与认证校验;业务码 `code === 200`、`saved`/`skipped` 由编排层判定,HTTP 200 本身不作为成功依据 | | 生产拦截 | CLI 层 `handleGrantNodes` 对 `isCorpProd` 企业直接拒绝,无 `--force` 逃生口;`--is-test` 只是 Piper 域名开关,不构成环境授权 | diff --git a/src/domains/platform/workflow/transport/catalog/api.ts b/src/domains/platform/workflow/transport/catalog/api.ts index 1a0d1d8..13741f2 100644 --- a/src/domains/platform/workflow/transport/catalog/api.ts +++ b/src/domains/platform/workflow/transport/catalog/api.ts @@ -1,7 +1,8 @@ import { z } from "zod"; import ky, { type KyInstance } from "ky"; import { EkbApiError, EkbError } from "../../../../../core/errors.js"; -import { fetchEasoJwt, SCRIPT_ENGINE_BASE_URL, SCRIPT_ENGINE_TEST_BASE_URL } from "../../../../../core/http/script-engine-client.js"; +import { fetchEasoJwt, resolvePiperBaseUrl } from "../../../../../core/http/script-engine-client.js"; +import { EKB_BASE_URL } from "../../../../../core/http/unity-client.js"; import { WorkflowDslSchema, WorkflowDslCatalogSchema, StaffSchema, WorkflowEnumItemSchema, type WorkflowEnumItem } from "../../types.js"; import { unwrap, assertNoAuthFailure } from "../response.js"; @@ -81,11 +82,11 @@ const WorkflowNodeGrantResponseSchema = z.object({ }).passthrough().nullable().optional(), }).passthrough(); -// 兼容历史导入路径;常量已收敛到 core/http/script-engine-client.ts -export { SCRIPT_ENGINE_TEST_BASE_URL }; +// 兼容历史导入路径;常量已收敛到 core/http/piper-endpoints.ts +export { SCRIPT_ENGINE_TEST_BASE_URL } from "../../../../../core/http/piper-endpoints.js"; function normalizeEkbBaseUrl(baseUrl?: string): string { - return (baseUrl || "https://app.ekuaibao.com").trim().replace(/\/+$/, ""); + return (baseUrl || EKB_BASE_URL).trim().replace(/\/+$/, ""); } export type WorkflowNodeGrantResponse = z.infer; @@ -123,7 +124,7 @@ export async function grantWorkflowNodesApi(options: { try { // 每个企业的工作流只对应标准或测试 Piper 之一;显式选择,不探测或自动回退。 - const piperBaseUrl = options.isTest ? SCRIPT_ENGINE_TEST_BASE_URL : SCRIPT_ENGINE_BASE_URL; + const piperBaseUrl = resolvePiperBaseUrl(options.isTest); const response = await ky.post(`${piperBaseUrl}/api/easo/dsl/corporation`, { json: options.payload, headers: { Authorization: `Bearer ${easoJwt}` }, diff --git a/src/domains/platform/workflow/triggers/webhook.ts b/src/domains/platform/workflow/triggers/webhook.ts index 9925f07..9762761 100644 --- a/src/domains/platform/workflow/triggers/webhook.ts +++ b/src/domains/platform/workflow/triggers/webhook.ts @@ -1,4 +1,5 @@ import type { WorkflowTask } from "../types.js"; +import { resolvePiperBaseUrl } from "../../../../core/http/piper-endpoints.js"; /** 复制的工作流需要独立的 Webhook 地址和样本。 */ export function resetCopiedWebhookTrigger(task?: WorkflowTask): void { @@ -14,5 +15,7 @@ export function ensureWebhookTriggerPath(task: WorkflowTask): void { export function webhookTriggerUrl(task: WorkflowTask): string | undefined { const rawPath = [task.urlPath, task.url, task.path].find((value) => typeof value === "string" && value); if (typeof rawPath !== "string") return undefined; - return rawPath.startsWith("http") ? rawPath : `https://piper.ekuaibao.com/api/webhook/${rawPath.replace(/^\/+/, "")}`; + return rawPath.startsWith("http") + ? rawPath + : `${resolvePiperBaseUrl()}/api/webhook/${rawPath.replace(/^\/+/, "")}`; }