diff --git a/.zcode-plugin/plugin.json b/.zcode-plugin/plugin.json index a2473a3..709f1ca 100644 --- a/.zcode-plugin/plugin.json +++ b/.zcode-plugin/plugin.json @@ -1,6 +1,6 @@ { "name": "hose-use", - "version": "0.7.3", + "version": "0.7.4", "description": "合思/易快报 (ekuaibao) 企业级 SaaS CLI 与底层 SDK:多账号登录、企业租户切换、单据明细检索、工作流管理、内置 HTTP 服务与常驻守护进程。", "author": { "name": "yingqing" diff --git a/README.md b/README.md index b84340a..c68d5d0 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# hose-use (v0.7.3) +# hose-use (v0.7.4) 合思/易快报(ekuaibao)企业级 CLI 命令行工具与底层 SDK。 diff --git a/dist/openapi.json b/dist/openapi.json index 83fc1d7..200c6a2 100644 --- a/dist/openapi.json +++ b/dist/openapi.json @@ -2,7 +2,7 @@ "openapi": "3.1.0", "info": { "title": "hose-use API & MCP Tools Specification", - "version": "0.7.3", + "version": "0.7.4", "description": "Unified Enterprise SaaS API, CLI, and MCP Specification for Ekuaibao (合思/易快报), EASO, and Piper Workflows." }, "servers": [ diff --git a/openapi/openapi.yaml b/openapi/openapi.yaml index 524da02..4c63af2 100644 --- a/openapi/openapi.yaml +++ b/openapi/openapi.yaml @@ -1,7 +1,7 @@ openapi: 3.1.0 info: title: hose-use API & MCP Tools Specification - version: 0.7.3 + version: 0.7.4 description: >- Unified Enterprise SaaS API, CLI, and MCP Specification for Ekuaibao (合思/易快报), EASO, and Piper Workflows. servers: diff --git a/package.json b/package.json index 53586dd..ba7983c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hose-use", - "version": "0.7.3", + "version": "0.7.4", "module": "src/server.ts", "type": "module", "bin": { diff --git a/skills/hose-use/SKILL.md b/skills/hose-use/SKILL.md index f08a158..8270eaf 100644 --- a/skills/hose-use/SKILL.md +++ b/skills/hose-use/SKILL.md @@ -1,12 +1,12 @@ --- name: hose-use -description: "v0.7.3: 合思/易快报 (ekuaibao) 企业级 SaaS CLI 与底层 SDK:多账号 API 登录、租户切换、单据检索与审批动作、工作流跨域扫描、内置 HTTP 交互文档与常驻守护进程。" +description: "v0.7.4: 合思/易快报 (ekuaibao) 企业级 SaaS CLI 与底层 SDK:多账号 API 登录、租户切换、单据检索与审批动作、工作流跨域扫描、内置 HTTP 交互文档与常驻守护进程。" metadata: - version: 0.7.3 - short-description: 合思/易快报企业级 CLI 工具与底层 SDK (v0.7.3) + version: 0.7.4 + short-description: 合思/易快报企业级 CLI 工具与底层 SDK (v0.7.4) --- -# hose-use (v0.7.3) +# hose-use (v0.7.4) 在具备 MCP 的 AI 智能体环境中,**优先使用 `hose_cli` 单工具网关**,传入 `command: string` 执行;在终端或自动化脚本中,直接调用全局 `hose` 或 `hose-use` 命令行。 本 Skill 是智能体的路由分发层:保持主文档简明,遇到复杂业务时深入查阅对应的专属参考文档(`references/*.md`)。 diff --git a/src/cli/commands/config.ts b/src/cli/commands/config.ts index 5fa9b43..540397f 100644 --- a/src/cli/commands/config.ts +++ b/src/cli/commands/config.ts @@ -1,3 +1,4 @@ +import { resolve } from "node:path"; import { loadGlobalConfig, saveGlobalConfig, @@ -6,6 +7,7 @@ import { resolveWritableEnterprisesDir, getEnterprisesDirCandidates, } from "../../core/config/loader.js"; +import { booleanOption } from "../parser.js"; import { printJson, printKeyValue } from "../printer.js"; import type { CliParsedArgs, CliResult, CliRuntime } from "../types.js"; @@ -26,12 +28,15 @@ export async function handleConfigCommand( return handlePaths(parsed, runtime); case "mode": return handleMode(parsed, runtime); + case "test-dir": + case "test-enterprises-dir": + return handleTestDir(parsed, runtime); case "set": return handleSet(parsed, runtime); default: return { stdout: "", - stderr: `未知 config 子命令: ${action}。支持: show, paths, mode , set \n`, + stderr: `未知 config 子命令: ${action}。支持: show, paths, mode , test-dir , set \n`, exitCode: 1, }; } @@ -47,6 +52,7 @@ async function handleShow(parsed: CliParsedArgs, runtime: CliRuntime): Promise\n 指定企业: hose-use corps switch \n 更新源设置: hose-use config set updateSource \n`, + stdout: `====== 全局运行配置 ======\n${output}\n\n提示:\n 切换模式: hose-use config mode \n 指定企业: hose-use corps switch \n 配置测试目录: hose-use config test-dir (或 --clear)\n 更新源设置: hose-use config set updateSource \n`, stderr: "", exitCode: 0, }; @@ -98,6 +105,54 @@ async function handleMode(parsed: CliParsedArgs, runtime: CliRuntime): Promise { + const isClear = booleanOption(parsed.options, ["clear"]) || parsed.args[0] === "--clear" || parsed.args[0] === "clear"; + const globalConfig = loadGlobalConfig(); + + if (isClear) { + const updated = saveGlobalConfig({ testEnterprisesDir: undefined }); + if (runtime.jsonMode) { + return { stdout: printJson(updated), stderr: "", exitCode: 0 }; + } + return { + stdout: "[SUCCESS] 已清除测试企业目录配置,恢复默认全局目录。\n", + stderr: "", + exitCode: 0, + }; + } + + const dirArg = parsed.args[0]; + if (!dirArg) { + const info = { + testEnterprisesDir: globalConfig.testEnterprisesDir || null, + configFile: resolveGlobalConfigFile(), + }; + if (runtime.jsonMode) { + return { stdout: printJson(info), stderr: "", exitCode: 0 }; + } + const output = printKeyValue({ + "当前测试企业目录": globalConfig.testEnterprisesDir || "未配置 (当前只读全局企业目录)", + "全局配置文件路径": resolveGlobalConfigFile(), + }); + return { + stdout: `====== 测试企业目录配置 ======\n${output}\n\n提示:\n 设置测试目录: hose-use config test-dir \n 清除测试目录: hose-use config test-dir --clear\n`, + stderr: "", + exitCode: 0, + }; + } + + const resolved = resolve(dirArg); + const updated = saveGlobalConfig({ testEnterprisesDir: resolved }); + if (runtime.jsonMode) { + return { stdout: printJson(updated), stderr: "", exitCode: 0 }; + } + return { + stdout: `[SUCCESS] 测试企业目录已设置为: ${resolved}\n`, + stderr: "", + exitCode: 0, + }; +} + async function handleSet(parsed: CliParsedArgs, runtime: CliRuntime): Promise { const rawKey = parsed.args[0]; const val = parsed.args[1]; @@ -123,6 +178,13 @@ async function handleSet(parsed: CliParsedArgs, runtime: CliRuntime): Promise = { "企业名称": corp.name, "企业 ID": corp.id, @@ -192,7 +197,7 @@ async function handleAddLink(parsed: CliParsedArgs, runtime: CliRuntime): Promis "凭证来源": formatSourceLabel(corp.source), "服务节点": corp.baseUrl, "过期时间": formatExpiresAt(corp.auth?.expiresAt || corp.session?.expTime), - "保存路径": `enterprises/${corp.id}.json`, + "保存路径": savedPath, }; if (corp.session?.isAssistPlatform) { diff --git a/src/core/config/loader.test.ts b/src/core/config/loader.test.ts index ac8fa6d..2bfd449 100644 --- a/src/core/config/loader.test.ts +++ b/src/core/config/loader.test.ts @@ -7,6 +7,7 @@ import { saveCorpConfig, resolveEnterprisesDirs, resolveWritableEnterprisesDir, + getEnterprisesDirCandidates, loadGlobalConfig, saveGlobalConfig, resolveGlobalConfigFile, @@ -39,6 +40,35 @@ describe("core/config/loader", () => { expect(dirs).toEqual([customDir]); }); + test("resolveEnterprisesDirs does not include relative project enterprises dir", () => { + delete process.env.HOSE_ENTERPRISES_DIR; + delete process.env.HOSE_USER_ENTERPRISES_DIR; + const customConfigFile = join(tempDir, "config.json"); + process.env.HOSE_CONFIG_FILE = customConfigFile; + + const dirs = resolveEnterprisesDirs(); + // Must never contain relative "enterprises" + expect(dirs).not.toContain("enterprises"); + }); + + test("resolveEnterprisesDirs prioritizes testEnterprisesDir from global config", () => { + delete process.env.HOSE_ENTERPRISES_DIR; + delete process.env.HOSE_USER_ENTERPRISES_DIR; + const customConfigFile = join(tempDir, "config.json"); + process.env.HOSE_CONFIG_FILE = customConfigFile; + + const customTestDir = join(tempDir, "my-test-enterprises"); + mkdirSync(customTestDir, { recursive: true }); + + saveGlobalConfig({ testEnterprisesDir: customTestDir }); + const dirs = resolveEnterprisesDirs(); + expect(dirs[0]).toBe(customTestDir); + expect(resolveWritableEnterprisesDir()).toBe(customTestDir); + + const candidates = getEnterprisesDirCandidates(); + expect(candidates).toContain(`testEnterprisesDir: ${customTestDir}`); + }); + test("resolveWritableEnterprisesDir respects HOSE_ENTERPRISES_DIR", () => { const customDir = join(tempDir, "writable-enterprises"); mkdirSync(customDir, { recursive: true }); diff --git a/src/core/config/loader.ts b/src/core/config/loader.ts index e189ad2..7ce969d 100644 --- a/src/core/config/loader.ts +++ b/src/core/config/loader.ts @@ -3,7 +3,6 @@ import { homedir } from "node:os"; import { dirname, join } from "node:path"; import { CorpConfig, CorpConfigSchema, GlobalConfig, GlobalConfigSchema } from "./types.js"; -const ENTERPRISES_DIR = "enterprises"; const CONFIG_ENV = "HOSE_ENTERPRISES_DIR"; const USER_DIR_ENV = "HOSE_USER_ENTERPRISES_DIR"; const GLOBAL_CONFIG_ENV = "HOSE_CONFIG_FILE"; @@ -26,13 +25,16 @@ export function resolveEnterprisesDirs(): string[] { } const configuredUserDir = process.env[USER_DIR_ENV]?.trim(); - if (configuredUserDir) { - return [ENTERPRISES_DIR, configuredUserDir].filter((dir) => existsSync(dir)); - } + const userDirs = configuredUserDir + ? (existsSync(configuredUserDir) ? [configuredUserDir] : []) + : [PRIMARY_USER_ENTERPRISES_DIR, LEGACY_USER_ENTERPRISES_DIR]; - const dirs = [ENTERPRISES_DIR, PRIMARY_USER_ENTERPRISES_DIR, LEGACY_USER_ENTERPRISES_DIR]; + const globalConfig = loadGlobalConfig(); + const testDir = globalConfig.testEnterprisesDir?.trim(); + + const candidates = testDir ? [testDir, ...userDirs] : userDirs; const uniqueExisting: string[] = []; - for (const d of dirs) { + for (const d of candidates) { if (existsSync(d) && !uniqueExisting.includes(d)) { uniqueExisting.push(d); } @@ -41,12 +43,7 @@ export function resolveEnterprisesDirs(): string[] { } export function resolvePrimaryEnterprisesDir(): string | undefined { - const configured = process.env[CONFIG_ENV]?.trim(); - if (configured) return existsSync(configured) ? configured : undefined; - if (existsSync(ENTERPRISES_DIR)) return ENTERPRISES_DIR; - if (existsSync(PRIMARY_USER_ENTERPRISES_DIR)) return PRIMARY_USER_ENTERPRISES_DIR; - if (existsSync(LEGACY_USER_ENTERPRISES_DIR)) return LEGACY_USER_ENTERPRISES_DIR; - return undefined; + return resolveEnterprisesDirs()[0]; } export function resolveWritableEnterprisesDir(): string { @@ -54,14 +51,16 @@ export function resolveWritableEnterprisesDir(): string { if (configured) return configured; const configuredUserDir = process.env[USER_DIR_ENV]?.trim(); if (configuredUserDir) return configuredUserDir; - if (existsSync(ENTERPRISES_DIR)) return ENTERPRISES_DIR; + const testDir = loadGlobalConfig().testEnterprisesDir?.trim(); + if (testDir && existsSync(testDir)) return testDir; return PRIMARY_USER_ENTERPRISES_DIR; } export function getEnterprisesDirCandidates(): string[] { + const testDir = loadGlobalConfig().testEnterprisesDir?.trim(); return [ `${CONFIG_ENV}=`, - ENTERPRISES_DIR, + ...(testDir ? [`testEnterprisesDir: ${testDir}`] : []), PRIMARY_USER_ENTERPRISES_DIR, LEGACY_USER_ENTERPRISES_DIR, ]; diff --git a/src/core/config/types.ts b/src/core/config/types.ts index fd8672d..3bb1f09 100644 --- a/src/core/config/types.ts +++ b/src/core/config/types.ts @@ -67,6 +67,7 @@ export const GlobalConfigSchema = z.object({ stateful: z.boolean().default(true).describe("是否为有状态模式 (true 记忆默认企业,false 无状态需显式传 --corp)"), defaultCorpId: z.string().optional().describe("默认工作企业 ID"), defaultAccountId: z.string().optional().describe("默认主账号"), + testEnterprisesDir: z.string().min(1).optional().describe("测试/自定义企业目录(仅用于开发测试重载,优先于全局用户目录)"), updateRepo: z.string().optional().describe("默认自更新的 GitHub 仓库 (owner/repo)"), updateSource: z.enum(["auto", "github", "gitea"]).optional().default("auto").describe("默认自更新源通道偏好 (auto/github/gitea)"), }); diff --git a/src/version.ts b/src/version.ts index 25085ab..ee51168 100644 --- a/src/version.ts +++ b/src/version.ts @@ -1 +1 @@ -export const VERSION = "0.7.3"; +export const VERSION = "0.7.4";