From dbeb422aeb6216db1c335fc3f3999f8b2c986da3 Mon Sep 17 00:00:00 2001 From: yunyingk Date: Thu, 27 Aug 2026 11:09:18 +0800 Subject: [PATCH] =?UTF-8?q?chore(release):=20=E6=9B=B4=E6=96=B0=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E4=B8=8E=20CLI=20=E5=90=8D=E7=A7=B0=E4=B8=BA=20hose-u?= =?UTF-8?q?se=EF=BC=8C=E5=8D=87=E7=BA=A7=E5=88=B0=20v0.2.0=EF=BC=8C?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=8C=E8=BF=9B=E5=88=B6=E6=9E=84=E5=BB=BA?= =?UTF-8?q?=E4=B8=8E=20GitHub=20Actions=20Release=20=E5=B7=A5=E4=BD=9C?= =?UTF-8?q?=E6=B5=81=EF=BC=8C=E9=9B=86=E6=88=90=20Agent=20Skill?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/release.yml | 56 +++++++++++ AGENTS.md | 5 +- README.md | 56 +++++++---- package.json | 9 +- scripts/build-binary.mjs | 70 ++++++++++++++ scripts/install.sh | 169 ++++++++++++++++++++++++++++++++++ skills/hose-use/SKILL.md | 105 +++++++++++++++++++++ src/cli/commands/skill.ts | 122 ++++++++++++++++++++++++ src/cli/printer.ts | 26 ++++-- src/cli/runner.ts | 6 +- src/core/embedded-skill.ts | 50 ++++++++++ src/declarations.d.ts | 14 +++ src/version.ts | 2 +- 13 files changed, 653 insertions(+), 37 deletions(-) create mode 100644 .github/workflows/release.yml create mode 100644 scripts/build-binary.mjs create mode 100755 scripts/install.sh create mode 100644 skills/hose-use/SKILL.md create mode 100644 src/cli/commands/skill.ts create mode 100644 src/core/embedded-skill.ts create mode 100644 src/declarations.d.ts diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..7331e7a --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,56 @@ +name: 🚀 Release + +on: + push: + tags: + - "v*" + workflow_dispatch: + +permissions: + contents: write + +jobs: + build-and-publish: + name: 🚀 Build & Publish Multi-Platform Binaries + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Bun + uses: oven-sh/setup-bun@v2 + with: + bun-version: latest + + - name: Install dependencies + run: bun install --frozen-lockfile + + - name: Type-check + run: bun run check + + - name: Compile multi-target binaries + run: | + mkdir -p dist/bin + node scripts/build-binary.mjs --all + + - name: Package release archives + run: | + sudo apt-get update && sudo apt-get install -y zip + cd dist/bin + tar -czf hose-use-linux-x64.tar.gz hose-use-linux-x64 + tar -czf hose-use-linux-arm64.tar.gz hose-use-linux-arm64 + tar -czf hose-use-darwin-x64.tar.gz hose-use-darwin-x64 + tar -czf hose-use-darwin-arm64.tar.gz hose-use-darwin-arm64 + zip -q hose-use-windows-x64.zip hose-use-windows-x64.exe + + - name: Publish GitHub Release + env: + GH_TOKEN: ${{ github.token }} + run: | + TAG_MSG=$(git tag -l --format='%(contents)' "${GITHUB_REF_NAME}" | sed '/^$/d') + if [ -n "$TAG_MSG" ]; then + gh release view "${GITHUB_REF_NAME}" --repo "${GITHUB_REPOSITORY}" >/dev/null 2>&1 || gh release create "${GITHUB_REF_NAME}" --repo "${GITHUB_REPOSITORY}" --title "${GITHUB_REF_NAME}" --notes "$TAG_MSG" --generate-notes + else + gh release view "${GITHUB_REF_NAME}" --repo "${GITHUB_REPOSITORY}" >/dev/null 2>&1 || gh release create "${GITHUB_REF_NAME}" --repo "${GITHUB_REPOSITORY}" --title "${GITHUB_REF_NAME}" --generate-notes + fi + gh release upload "${GITHUB_REF_NAME}" dist/bin/hose-use-* --repo "${GITHUB_REPOSITORY}" --clobber diff --git a/AGENTS.md b/AGENTS.md index 1d526b9..6225031 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -1,4 +1,4 @@ -# hose-serve-tool 项目上下文(AGENTS.md) +# hose-use 项目上下文(AGENTS.md) 本文件是根目录总纲,面向 AI 智能体说明项目目标、分层规则和文档索引。 @@ -6,9 +6,10 @@ 合思/易快报(ekuaibao)企业费控与平台自建应用的高性能 CLI 命令行工具与底层 SDK(兼具轻量 MCP 适配能力): -- **CLI 工具 (`hose`)**:面向运维/实施/开发者的高性能交互与自动化命令行 +- **CLI 工具 (`hose-use` / `hose`)**:面向运维/实施/开发者的高性能交互与自动化命令行 - **底层 SDK (`src/domains/` & `src/core/`)**:纯函数式、零 UI 绑定的业务 API 与换票能力 - **MCP Server (`src/server.ts`)**:精简核心适配器(保留核心切换与扫描能力) +- **Agent Skill (`skills/hose-use`)**:内嵌 AI 智能体技能标准定义(支持 `hose-use skill install` 一键分发) ## 架构总览 diff --git a/README.md b/README.md index 49f4843..101baa3 100644 --- a/README.md +++ b/README.md @@ -1,36 +1,52 @@ -# hose-serve-tool +# hose-use (v0.2.0) -合思/易快报(ekuaibao)企业费控与平台自建应用的高性能 CLI 命令行工具与底层 SDK。 +合思/易快报(ekuaibao)企业级 CLI 命令行工具与底层 SDK。 ## 安装与快速开始 +### 方式一:一键脚本安装独立二进制(推荐) + ```bash -bun install +curl -fsSL https://raw.githubusercontent.com/yunyingk/hose-serve-tool/main/scripts/install.sh | bash ``` -### CLI 命令行工具 (`hose`) +### 方式二:本地 Bun 源码开发 ```bash -# 1. 认证与登录 (支持账密、短信、F12抓包导入、浏览器同步) -bun run cli auth login --phone=17718556446 --password=... -bun run cli auth status # 查看当前登录状态与有效性 -bun run cli auth refresh # 批量刷新账号名下全部企业 Token +bun install +bun run cli +``` + +--- + +### CLI 常用命令速查 (`hose-use`) + +```bash +# 1. 认证与登录 (支持账密、短信、F12抓包导入、浏览器同步,支持 401 自动无感续杯) +hose-use auth login --phone=17718556446 --password=... +hose-use auth status # 查看当前登录状态与有效性 +hose-use auth refresh # 批量刷新账号名下全部企业 30 天 Token # 2. 多企业租户管理 -bun run cli corps list # 列出名下所有已配置企业 -bun run cli corps switch # 切换工作企业 -bun run cli corps current # 查看当前激活企业 +hose-use corps list # 列出名下所有已配置企业 +hose-use corps switch # 切换工作企业 +hose-use corps current # 查看当前激活企业 -# 3. 平台与工作流管理 (跨应用聚合) -bun run cli workflow list # 汇总查看全部工作流列表 -bun run cli workflow get # 获取工作流详情与节点结构 -bun run cli workflow find --task=code-js2 # 搜索包含特定节点类型的工作流 -bun run cli workflow toggle --state=1 # 启用/停用工作流 -bun run cli platform list # 查看企业下所有启用的自建应用 +# 3. 运行模式管理 (有状态 vs 无状态) +hose-use config show # 查看当前运行模式 +hose-use config mode stateless # 切换为无状态模式 (防止 Agent 误操作) +hose-use config mode stateful # 切换为有状态模式 (记忆默认企业) -# 4. 连通性诊断与 MCP Server -bun run probe # 诊断当前企业鉴权与接口连通性 -bun run start # 启动精简版 MCP Server (stdio) +# 4. 平台与工作流管理 (跨自建应用聚合) +hose-use workflow list # 汇总查看全部工作流列表 +hose-use workflow get # 获取工作流详情与节点结构 +hose-use workflow find --task=code-js2 # 搜索包含特定节点类型的工作流 +hose-use workflow toggle --state=1 # 启用/停用工作流 +hose-use platform list # 查看企业下所有启用的自建应用 + +# 5. Agent Skill 与连通性诊断 +hose-use skill install # 一键将 Agent Skill 安装到 ~/.agents/skills/ +hose-use probe # 诊断当前企业主站 Session、EASO 握手与接口连通性 ``` ## 架构 diff --git a/package.json b/package.json index c0dc10c..c21475f 100644 --- a/package.json +++ b/package.json @@ -1,17 +1,20 @@ { - "name": "hose-serve-tool", - "version": "0.1.0", + "name": "hose-use", + "version": "0.2.0", "module": "src/server.ts", "type": "module", "bin": { + "hose-use": "src/cli.ts", "hose": "src/cli.ts" }, "scripts": { "cli": "bun run src/cli.ts", "probe": "bun run src/cli.ts probe", + "check": "tsc --noEmit", + "typecheck": "tsc --noEmit", + "build:binary": "node scripts/build-binary.mjs", "dev": "bun run --watch src/server.ts", "start": "bun run src/server.ts", - "typecheck": "tsc --noEmit", "export:workflow-schema": "bun run scripts/export-workflow-schema.ts" }, "dependencies": { diff --git a/scripts/build-binary.mjs b/scripts/build-binary.mjs new file mode 100644 index 0000000..ffe2703 --- /dev/null +++ b/scripts/build-binary.mjs @@ -0,0 +1,70 @@ +import { mkdirSync } from "node:fs"; +import { spawnSync } from "node:child_process"; +import { dirname, resolve } from "node:path"; +import { fileURLToPath } from "node:url"; + +const root = resolve(dirname(fileURLToPath(import.meta.url)), ".."); +const bun = process.env.BUN_BIN || "bun"; + +const TARGET_MAP = { + "darwin-arm64": { bunTarget: "bun-darwin-arm64", outfile: "dist/bin/hose-use-darwin-arm64" }, + "darwin-x64": { bunTarget: "bun-darwin-x64", outfile: "dist/bin/hose-use-darwin-x64" }, + "linux-x64": { bunTarget: "bun-linux-x64", outfile: "dist/bin/hose-use-linux-x64" }, + "linux-arm64": { bunTarget: "bun-linux-arm64", outfile: "dist/bin/hose-use-linux-arm64" }, + "windows-x64": { bunTarget: "bun-windows-x64", outfile: "dist/bin/hose-use-windows-x64.exe" } +}; + +const args = process.argv.slice(2); +const isAll = args.includes("--all") || args.includes("--matrix"); +const targetArg = args.find((arg) => arg.startsWith("--target="))?.replace("--target=", ""); + +if (isAll) { + for (const [name, config] of Object.entries(TARGET_MAP)) { + buildTarget(name, config.bunTarget, resolve(root, config.outfile)); + } +} else if (targetArg) { + const config = TARGET_MAP[targetArg]; + if (!config) { + throw new Error(`Unknown target: ${targetArg}. Available targets: ${Object.keys(TARGET_MAP).join(", ")}`); + } + buildTarget(targetArg, config.bunTarget, resolve(root, config.outfile)); +} else { + const output = resolve(root, "dist/bin/hose-use"); + buildTarget("host", null, output); +} + +function buildTarget(name, bunTarget, output) { + mkdirSync(dirname(output), { recursive: true }); + const buildArgs = ["build", "--compile"]; + if (bunTarget) { + buildArgs.push(`--target=${bunTarget}`); + } + buildArgs.push("--outfile", output, "src/cli.ts"); + + console.log(`[build:binary] compiling target: ${name} -> ${output}`); + run(bun, buildArgs); + + if (process.platform === "darwin" && (name.startsWith("darwin") || name === "host")) { + try { + run("/usr/bin/codesign", ["--remove-signature", output], { quiet: true }); + } catch { + // ignore + } + try { + run("/usr/bin/codesign", ["--force", "--sign", "-", output], { quiet: true }); + } catch { + // ignore + } + } +} + +function run(command, args, options = {}) { + const result = spawnSync(command, args, { + cwd: root, + stdio: options.quiet ? ["ignore", "ignore", "ignore"] : "inherit" + }); + if (result.error) throw result.error; + if (result.status !== 0) { + throw new Error(`${command} ${args.join(" ")} failed with status ${result.status}`); + } +} diff --git a/scripts/install.sh b/scripts/install.sh new file mode 100755 index 0000000..aa67647 --- /dev/null +++ b/scripts/install.sh @@ -0,0 +1,169 @@ +#!/usr/bin/env bash +set -e + +REPO="yunyingk/hose-serve-tool" + +echo "==> Detecting platform and architecture..." +OS="$(uname -s | tr '[:upper:]' '[:lower:]')" +ARCH="$(uname -m)" + +case "$OS" in + darwin) + PLATFORM="darwin" + ;; + linux) + PLATFORM="linux" + ;; + *) + echo "Unsupported operating system: $OS" >&2 + exit 1 + ;; +esac + +case "$ARCH" in + x86_64|amd64) + ARCH_NAME="x64" + ;; + arm64|aarch64) + ARCH_NAME="arm64" + ;; + *) + echo "Unsupported architecture: $ARCH" >&2 + exit 1 + ;; +esac + +# Resolve best writable bin directory without requiring sudo +TARGET_DIR="" +for candidate in "/opt/homebrew/bin" "/usr/local/bin" "$HOME/.local/bin" "$HOME/bin"; do + if [ -d "$candidate" ] && [ -w "$candidate" ]; then + TARGET_DIR="$candidate" + break + fi +done + +if [ -z "$TARGET_DIR" ]; then + mkdir -p "$HOME/.local/bin" + TARGET_DIR="$HOME/.local/bin" +fi + +ASSET_NAME="hose-use-${PLATFORM}-${ARCH_NAME}" +TARGET_PATH="${TARGET_DIR}/hose-use" + +get_file_size() { + local file="$1" + if [ ! -f "$file" ]; then + echo "0" + return + fi + local sz + sz=$(stat -f%z "$file" 2>/dev/null || stat -c%s "$file" 2>/dev/null || wc -c < "$file" | tr -d ' ') + echo "$sz" +} + +format_bytes() { + local bytes="$1" + if [ -z "$bytes" ] || [ "$bytes" -le 0 ]; then + echo "0 B" + return + fi + if [ "$bytes" -ge 1048576 ]; then + awk "BEGIN {printf \"%.2f MB (%'d bytes)\", $bytes / 1048576, $bytes}" 2>/dev/null || awk "BEGIN {printf \"%.2f MB (%d bytes)\", $bytes / 1048576, $bytes}" + elif [ "$bytes" -ge 1024 ]; then + awk "BEGIN {printf \"%.2f KB (%d bytes)\", $bytes / 1024, $bytes}" + else + echo "${bytes} bytes" + fi +} + +extract_host() { + local url="$1" + echo "$url" | sed -e 's|^[^/]*//||' -e 's|/.*$||' +} + +download_candidate() { + local url="$1" + local dest="$2" + local label="$3" + local host + host="$(extract_host "$url")" + + echo "==> Downloading from ${label}" + echo " Source Host: ${host}" + echo " Source URL: ${url}" + + # Test connectivity & headers first + if ! curl -fIs --connect-timeout 4 "$url" >/dev/null 2>&1; then + echo " ↳ Source unreachable or asset not ready (404), falling back to next mirror..." + return 1 + fi + + # Download with progress bar + if curl -fL --progress-bar "$url" -o "$dest"; then + local size_bytes + size_bytes="$(get_file_size "$dest")" + if [ "$size_bytes" -gt 1000000 ]; then + echo "✓ Download complete! Total size: $(format_bytes "$size_bytes")" + echo "✓ Successfully fetched from host: ${host}" + return 0 + fi + fi + + rm -f "$dest" + return 1 +} + +echo "==> Target install location: ${TARGET_PATH}" +TMP_FILE="$(mktemp)" +DOWNLOAD_SUCCESS=false + +# Candidate mirrors +GITHUB_URL="https://github.com/${REPO}/releases/latest/download/${ASSET_NAME}" +GHPROXY_URL="https://ghfast.top/https://github.com/${REPO}/releases/latest/download/${ASSET_NAME}" + +# 1. Try direct GitHub Releases +if download_candidate "$GITHUB_URL" "$TMP_FILE" "GitHub Releases (Direct)"; then + DOWNLOAD_SUCCESS=true +fi + +# 2. Try Fast CDN Proxy Fallback +if [ "$DOWNLOAD_SUCCESS" = "false" ]; then + if download_candidate "$GHPROXY_URL" "$TMP_FILE" "Fast CDN Mirror (Fallback)"; then + DOWNLOAD_SUCCESS=true + fi +fi + +if [ "$DOWNLOAD_SUCCESS" = "false" ]; then + echo "Error: Failed to download ${ASSET_NAME} from all candidate mirrors." >&2 + rm -f "$TMP_FILE" + exit 1 +fi + +chmod +x "$TMP_FILE" +mv "$TMP_FILE" "$TARGET_PATH" + +# Also create 'hose' symlink if possible +if [ -w "$TARGET_DIR" ]; then + ln -sf "$TARGET_PATH" "${TARGET_DIR}/hose" 2>/dev/null || true +fi + +# Ad-hoc sign on macOS +if [ "$PLATFORM" = "darwin" ] && command -v codesign >/dev/null 2>&1; then + echo "==> Applying macOS code signature..." + codesign --force --sign - "$TARGET_PATH" 2>/dev/null || true +fi + +echo "==> Initializing agent skill to ~/.agents/skills/hose-use..." +"$TARGET_PATH" skill install >/dev/null 2>&1 || true +echo "✓ Agent skill installed to ~/.agents/skills/hose-use" + +echo "" +echo "✨ hose-use successfully installed to ${TARGET_PATH}!" +"$TARGET_PATH" version +echo "" +echo "Quick start:" +echo " 1. Login: hose-use auth login --phone=177... --password=..." +echo " 2. List corps: hose-use corps list" +echo " 3. List workflows: hose-use workflow list" +echo " 4. Switch mode: hose-use config mode stateless" +echo "" diff --git a/skills/hose-use/SKILL.md b/skills/hose-use/SKILL.md new file mode 100644 index 0000000..0585d66 --- /dev/null +++ b/skills/hose-use/SKILL.md @@ -0,0 +1,105 @@ +--- +name: hose-use +description: 合思/易快报 (ekuaibao) 企业 SaaS CLI 命令行工具与底层 SDK。支持多账号纯 API 登录、30天 Token 自动无感续杯、多企业租户管理、有状态/无状态模式切换、自建应用扫描与跨应用工作流聚合检索。 +--- + +# hose-use (合思/易快报企业级 CLI 与底层 SDK) + +`hose-use` 是面向合思/易快报 SaaS、开发者与 AI 智能体的高性能交互工具。 + +## 核心架构原则 + +- **纯 API 认证**:内置 RSA PKCS#1 密码加密与统一认证中心握手,无需浏览器滑块即可登录。 +- **全自动无感续杯**:内置 401 拦截与预检换票机制,Token 到期自动刷新并重试,零人工介入。 +- **多账号与多身份分层**:支持一个手机号管理 13+ 家企业;支持同一企业下多身份(`corpId@accountId`)共存。 +- **有状态 / 无状态双模式**: + - **有状态 (Stateful)**:自动记忆默认企业,命令无需反复加 `--corp`。 + - **无状态 (Stateless)**:严格要求 `--corp `,防止多租户或 Agent 误操作。 + +--- + +## 常用命令速查 + +### 1. 认证管理 (`hose-use auth`) + +```bash +# 纯 API 账密全自动登录(自动获取 RSA 公钥加密并拉取旗下所有企业) +hose-use auth login --phone=17718556446 --password=... + +# 导入 F12 抓包复制的 cURL 或 Request Headers +hose-use auth import --raw="curl ..." + +# 查看当前登录状态与活跃账号 +hose-use auth status + +# 一键批量刷新名下所有企业的最新 30 天 AccessToken +hose-use auth refresh + +# 查看已保存的全部主账号 +hose-use auth accounts +``` + +### 2. 多企业租户管理 (`hose-use corps`) + +```bash +# 列出名下所有已授权企业 +hose-use corps list + +# 切换当前工作企业 (有状态模式下自动持久化) +hose-use corps switch uzU7pcWfScck00 + +# 查看当前激活企业信息 +hose-use corps current +``` + +### 3. 全局运行模式 (`hose-use config`) + +```bash +# 查看全局运行模式与配置文件路径 +hose-use config show + +# 切换为无状态模式 (Stateless) +hose-use config mode stateless + +# 切换为有状态模式 (Stateful) +hose-use config mode stateful +``` + +### 4. 平台与工作流管理 (`hose-use workflow` / `hose-use platform`) + +```bash +# 汇总查看企业下所有工作流 (跨自建应用聚合) +hose-use workflow list + +# 查看指定工作流详情与节点结构 +hose-use workflow get 829729467412037634 + +# 搜索包含指定节点类型的工作流 (如 code-js2, http 等) +hose-use workflow find --task=code-js2 + +# 启用 / 停用工作流 (1: 启用, 0: 停用) +hose-use workflow toggle --state=1 + +# 查看企业下所有启用的自建应用 +hose-use platform list +``` + +### 5. 诊断与 MCP 服务 (`hose-use probe` / `hose-use mcp`) + +```bash +# 连通性与 EASO 平台鉴权诊断 +hose-use probe +hose-use probe --corp=uzU7pcWfScck00 + +# 启动极简 MCP stdio 服务 +hose-use mcp serve +``` + +--- + +## 全局选项 + +- `--corp=`:临时指定操作的企业/身份 ID +- `--json`, `-j`:输出 JSON 结构化格式(适合脚本解析) +- `--stateless`:单次命令强制以无状态模式执行 +- `--stateful`:单次命令强制以有状态模式执行 diff --git a/src/cli/commands/skill.ts b/src/cli/commands/skill.ts new file mode 100644 index 0000000..5888631 --- /dev/null +++ b/src/cli/commands/skill.ts @@ -0,0 +1,122 @@ +import { existsSync } from "node:fs"; +import { join } from "node:path"; +import { + getDefaultGlobalSkillDir, + getAgentSkillCandidates, + getSkillContent, + installSkillFiles, +} from "../../core/embedded-skill.js"; +import { booleanOption, stringOption } from "../parser.js"; +import { printJson, printKeyValue } from "../printer.js"; +import type { CliParsedArgs, CliResult, CliRuntime } from "../types.js"; + +export async function handleSkillCommand( + parsed: CliParsedArgs, + runtime: CliRuntime +): Promise { + const action = parsed.action || "status"; + + switch (action) { + case "dump": + case "cat": + case "show": + return { + stdout: `${getSkillContent()}\n`, + stderr: "", + exitCode: 0, + }; + + case "install": + case "init": + case "sync": { + const isLocal = + booleanOption(parsed.options, ["local"]) || + booleanOption(parsed.options, ["workspace"]); + const customDir = + stringOption(parsed.options, ["dir", "target"]) || parsed.args[0]; + + const targetDir = customDir + ? customDir + : isLocal + ? join(process.cwd(), ".agents", "skills", "hose-use") + : getDefaultGlobalSkillDir(); + + const result = installSkillFiles(targetDir); + + // 也同时尝试安装到其它检测到的候选目录 + const candidates = getAgentSkillCandidates(); + for (const dir of candidates) { + if (dir !== targetDir) { + try { + installSkillFiles(dir); + } catch { + // ignore + } + } + } + + if (runtime.jsonMode) { + return { + stdout: printJson({ + installed: true, + targetDir: result.targetDir, + fileCount: result.files.length, + files: result.files, + }), + stderr: "", + exitCode: 0, + }; + } + + return { + stdout: `[SUCCESS] hose-use 技能已成功安装至: ${result.targetDir}\n包含文件: ${result.files.join(", ")}\n`, + stderr: "", + exitCode: 0, + }; + } + + case "status": + case "get": { + const globalDir = getDefaultGlobalSkillDir(); + const localDir = join(process.cwd(), ".agents", "skills", "hose-use"); + const candidates = getAgentSkillCandidates(); + + const statusObj = { + global: { + dir: globalDir, + installed: existsSync(join(globalDir, "SKILL.md")), + }, + local: { + dir: localDir, + installed: existsSync(join(localDir, "SKILL.md")), + }, + candidates: candidates.map((dir) => ({ + dir, + installed: existsSync(join(dir, "SKILL.md")), + })), + }; + + if (runtime.jsonMode) { + return { stdout: printJson(statusObj), stderr: "", exitCode: 0 }; + } + + const output = printKeyValue({ + "全局 Skill 目录": `${globalDir} [${statusObj.global.installed ? "已安装 ✅" : "未安装 ❌"}]`, + "本地 Skill 目录": `${localDir} [${statusObj.local.installed ? "已安装 ✅" : "未安装 ❌"}]`, + }); + + return { + stdout: `====== Agent Skill 状态 ======\n${output}\n\n提示: 运行 hose-use skill install 进行全局安装\n`, + stderr: "", + exitCode: 0, + }; + } + + default: + return { + stdout: "", + stderr: `未知 skill 子命令: ${action}。支持: install, status, dump\n`, + exitCode: 1, + }; + } +} diff --git a/src/cli/printer.ts b/src/cli/printer.ts index 611c420..a3dec02 100644 --- a/src/cli/printer.ts +++ b/src/cli/printer.ts @@ -38,32 +38,38 @@ export function printTable( export function printHelp(): string { return ` -合思/易快报企业级 CLI 工具 (hose) v${VERSION} +合思/易快报企业级 CLI 工具 (hose-use) v${VERSION} 用法: - hose <命令域> <子命令> [参数] [选项] + hose-use <命令域> <子命令> [参数] [选项] 核心命令域: auth 认证与凭证管理 (login, status, refresh, import, accounts) corps 多企业租户管理 (list, switch, current) + config 全局运行模式 (show, mode , set) workflow 工作流管理 (list, get, find, toggle) platform 自建应用管理 (list) + skill Agent Skill 管理 (install, status, dump) probe 连通性诊断 (probe [corpId]) mcp MCP Server 运行 (serve) version 查看版本信息 全局选项: - --corp= 临时指定操作的企业 ID (覆盖当前激活企业) + --corp= 临时指定操作的企业/身份 ID (覆盖默认企业) --json, -j 以 JSON 结构化输出结果 (适合脚本/流水线集成) + --stateless 单次强制以无状态模式执行 + --stateful 单次强制以有状态模式执行 --help, -h 查看帮助信息 常用示例: - hose auth login --phone=177... --password=... # 纯 API 账密自动登录 - hose auth status # 查看当前登录状态与活跃企业 - hose corps list # 列出名下所有企业 - hose corps switch uzU7pcWfScck00 # 切换工作企业 - hose workflow list # 汇总查看全部工作流 - hose workflow find --task=code-js2 # 搜索包含自定义脚本的工作流 - hose probe # 诊断当前企业鉴权连通性 + hose-use auth login --phone=177... --password=... # 纯 API 账密自动登录 + hose-use auth status # 查看当前登录状态与活跃企业 + hose-use config mode stateless # 切换为无状态模式 (防止 Agent 误操作) + hose-use corps list # 列出名下所有企业 + hose-use corps switch uzU7pcWfScck00 # 切换工作企业 + hose-use workflow list # 汇总查看全部工作流 + hose-use workflow find --task=code-js2 # 搜索包含自定义脚本的工作流 + hose-use probe # 诊断当前企业鉴权连通性 + hose-use skill install # 安装 Agent 技能到用户目录 `.trim(); } diff --git a/src/cli/runner.ts b/src/cli/runner.ts index 5db29bd..c2bb1d8 100644 --- a/src/cli/runner.ts +++ b/src/cli/runner.ts @@ -7,6 +7,7 @@ import { handleCorpsCommand } from "./commands/corps.js"; import { handleConfigCommand } from "./commands/config.js"; import { handleWorkflowCommand } from "./commands/workflow.js"; import { handlePlatformCommand } from "./commands/platform.js"; +import { handleSkillCommand } from "./commands/skill.js"; import { handleProbeCommand } from "./commands/probe.js"; import { handleMcpCommand } from "./commands/mcp.js"; import type { CliResult, CliRunOptions } from "./types.js"; @@ -22,7 +23,7 @@ export async function runCli( } if (booleanOption(parsed.options, ["version", "v"]) || parsed.area === "version") { - return { stdout: `hose v${VERSION}\n`, stderr: "", exitCode: 0 }; + return { stdout: `hose-use v${VERSION}\n`, stderr: "", exitCode: 0 }; } const jsonMode = booleanOption(parsed.options, ["json", "j"]); @@ -57,6 +58,9 @@ export async function runCli( case "app": case "apps": return await handlePlatformCommand(parsed, runtime); + case "skill": + case "skills": + return await handleSkillCommand(parsed, runtime); case "probe": case "check": case "diagnose": diff --git a/src/core/embedded-skill.ts b/src/core/embedded-skill.ts new file mode 100644 index 0000000..ec72dbb --- /dev/null +++ b/src/core/embedded-skill.ts @@ -0,0 +1,50 @@ +import { existsSync, mkdirSync, writeFileSync, readFileSync } from "node:fs"; +import { homedir } from "node:os"; +import { dirname, join } from "node:path"; +import skillMain from "../../skills/hose-use/SKILL.md" with { type: "text" }; + +export const EMBEDDED_SKILL_FILES: Record = { + "SKILL.md": skillMain, +}; + +export function getSkillContent(): string { + return EMBEDDED_SKILL_FILES["SKILL.md"] || ""; +} + +export function getDefaultGlobalSkillDir(): string { + return join(homedir(), ".agents", "skills", "hose-use"); +} + +export function getAgentSkillCandidates(): string[] { + return [ + join(homedir(), ".agents", "skills", "hose-use"), + join(homedir(), ".gemini", "antigravity", "skills", "hose-use"), + join(homedir(), ".codex", "skills", "hose-use"), + ]; +} + +export function installSkillFiles(targetDir: string = getDefaultGlobalSkillDir()): { + targetDir: string; + files: string[]; +} { + mkdirSync(targetDir, { recursive: true }); + const installed: string[] = []; + + for (const [relPath, content] of Object.entries(EMBEDDED_SKILL_FILES)) { + const fullPath = join(targetDir, relPath); + mkdirSync(dirname(fullPath), { recursive: true }); + writeFileSync(fullPath, content, "utf8"); + installed.push(relPath); + } + + return { + targetDir, + files: installed, + }; +} + +export function syncGlobalSkillIfPresent(): { synced: boolean; targetDir?: string } { + const globalDir = getDefaultGlobalSkillDir(); + installSkillFiles(globalDir); + return { synced: true, targetDir: globalDir }; +} diff --git a/src/declarations.d.ts b/src/declarations.d.ts new file mode 100644 index 0000000..495d98f --- /dev/null +++ b/src/declarations.d.ts @@ -0,0 +1,14 @@ +declare module "*.md" { + const content: string; + export default content; +} + +declare module "*.yaml" { + const content: string; + export default content; +} + +declare module "*.yml" { + const content: string; + export default content; +} diff --git a/src/version.ts b/src/version.ts index 52c905c..edbab61 100644 --- a/src/version.ts +++ b/src/version.ts @@ -1 +1 @@ -export const VERSION = "0.1.0"; +export const VERSION = "0.2.0";