From 2865728885dd9ab98a986e56babc414a686b7d1e Mon Sep 17 00:00:00 2001 From: yunyingk Date: Sat, 5 Sep 2026 22:32:39 +0800 Subject: [PATCH] feat(cli): enhance update sources, normalize repo, upgrade to MCP 2.0, and bump to v0.6.2 --- .zcode-plugin/plugin.json | 2 +- README.md | 4 +- bun.lock | 168 ++-------------------------- dist/openapi.json | 2 +- openapi/openapi.yaml | 2 +- package.json | 6 +- skills/hose-use/SKILL.md | 2 +- src/cli/commands/config.ts | 40 +++++-- src/cli/commands/update.test.ts | 33 +++++- src/cli/commands/update.ts | 187 +++++++++++++++++++++++++------- src/cli/printer.ts | 3 +- src/core/config/loader.ts | 6 +- src/core/config/types.ts | 3 + src/server.test.ts | 4 +- src/server.ts | 12 +- src/version.ts | 2 +- 16 files changed, 241 insertions(+), 235 deletions(-) diff --git a/.zcode-plugin/plugin.json b/.zcode-plugin/plugin.json index 4484c39..9a2d623 100644 --- a/.zcode-plugin/plugin.json +++ b/.zcode-plugin/plugin.json @@ -1,6 +1,6 @@ { "name": "hose-use", - "version": "0.6.1", + "version": "0.6.2", "description": "合思/易快报 (ekuaibao) 企业级 SaaS CLI 与底层 SDK:多账号登录、企业租户切换、单据明细检索、工作流管理、内置 HTTP 服务与常驻守护进程。", "author": { "name": "yingqing" diff --git a/README.md b/README.md index a350395..3d903a8 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# hose-use (v0.6.1) +# hose-use (v0.6.2) 合思/易快报(ekuaibao)企业级 CLI 命令行工具与底层 SDK。 @@ -138,7 +138,7 @@ src/ - **Runtime**: Bun - **HTTP Client**: ky - **Schema**: Zod -- **MCP SDK**: @modelcontextprotocol/sdk +- **MCP Protocol**: @modelcontextprotocol/server & @modelcontextprotocol/core (v2.0+) ## 面向 AI 智能体 diff --git a/bun.lock b/bun.lock index 7570cb5..a58d39b 100644 --- a/bun.lock +++ b/bun.lock @@ -5,214 +5,60 @@ "": { "name": "ekb-mcp", "dependencies": { - "@modelcontextprotocol/sdk": "^1.29.0", + "@modelcontextprotocol/core": "^2.0.0", + "@modelcontextprotocol/server": "^2.0.0", "ky": "^2.0.2", "yaml": "^2.9.0", "zod": "^4.4.3", }, "devDependencies": { + "@modelcontextprotocol/client": "^2.0.0", "@types/bun": "^1.3.14", "typescript": "^5.9.3", }, }, }, "packages": { - "@hono/node-server": ["@hono/node-server@1.19.14", "", { "peerDependencies": { "hono": "^4" } }, "sha512-GwtvgtXxnWsucXvbQXkRgqksiH2Qed37H9xHZocE5sA3N8O8O8/8FA3uclQXxXVzc9XBZuEOMK7+r02FmSpHtw=="], + "@modelcontextprotocol/client": ["@modelcontextprotocol/client@2.0.0", "", { "dependencies": { "@modelcontextprotocol/core": "2.0.0", "cross-spawn": "^7.0.5", "eventsource": "^3.0.2", "eventsource-parser": "^3.0.0", "jose": "^6.1.3", "pkce-challenge": "^5.0.0", "zod": "^4.2.0" } }, "sha512-8f1OghQ2rjzIOfqgUCP+8GiUWqRs89njoWLNqAe8kWmDePv3s1fZXseej+QXemssEuuOvLLmLO/kqM3IQHtISw=="], - "@modelcontextprotocol/sdk": ["@modelcontextprotocol/sdk@1.29.0", "", { "dependencies": { "@hono/node-server": "^1.19.9", "ajv": "^8.17.1", "ajv-formats": "^3.0.1", "content-type": "^1.0.5", "cors": "^2.8.5", "cross-spawn": "^7.0.5", "eventsource": "^3.0.2", "eventsource-parser": "^3.0.0", "express": "^5.2.1", "express-rate-limit": "^8.2.1", "hono": "^4.11.4", "jose": "^6.1.3", "json-schema-typed": "^8.0.2", "pkce-challenge": "^5.0.0", "raw-body": "^3.0.0", "zod": "^3.25 || ^4.0", "zod-to-json-schema": "^3.25.1" }, "peerDependencies": { "@cfworker/json-schema": "^4.1.1" }, "optionalPeers": ["@cfworker/json-schema"] }, "sha512-zo37mZA9hJWpULgkRpowewez1y6ML5GsXJPY8FI0tBBCd77HEvza4jDqRKOXgHNn867PVGCyTdzqpz0izu5ZjQ=="], + "@modelcontextprotocol/core": ["@modelcontextprotocol/core@2.0.0", "", { "dependencies": { "zod": "^4.2.0" } }, "sha512-pJCEwGG7Lfr/+PQp9ZTwKXNeO5wzbfKL7H3MYpCorM4oFBoQrdjnBgEoqG+RjhsvS1FKrDbKux+M1HhlnGWqcA=="], + + "@modelcontextprotocol/server": ["@modelcontextprotocol/server@2.0.0", "", { "dependencies": { "@modelcontextprotocol/core": "2.0.0", "zod": "^4.2.0" } }, "sha512-YhHWdHfpFMQfd0prsEnxKeS3Qz3ytIGmsS0sth4KDjnacIT7hxk6hXHkJ9KysxlkvTM+WZAtQbbcUhdoP4Hvtw=="], "@types/bun": ["@types/bun@1.3.14", "", { "dependencies": { "bun-types": "1.3.14" } }, "sha512-h1hFqFVcvAvD9j9K7ZW7vd82aSA+rTdznZa+5bwvCwqSB1jmmfLcbIWhOLx1/+boy/xmjgCs/OMUL8hRJSmnPw=="], "@types/node": ["@types/node@25.8.0", "", { "dependencies": { "undici-types": ">=7.24.0 <7.24.7" } }, "sha512-TCFSk8IZh+iLX1xtksoBVtdmgL+1IX0fC9BeU4QqFSuNdN/K+HUlhqOzEmSYYpZUVsLYcPqc9KX+60iDuninSQ=="], - "accepts": ["accepts@2.0.0", "", { "dependencies": { "mime-types": "^3.0.0", "negotiator": "^1.0.0" } }, "sha512-5cvg6CtKwfgdmVqY1WIiXKc3Q1bkRqGLi+2W/6ao+6Y7gu/RCwRuAhGEzh5B4KlszSuTLgZYuqFqo5bImjNKng=="], - - "ajv": ["ajv@8.20.0", "", { "dependencies": { "fast-deep-equal": "^3.1.3", "fast-uri": "^3.0.1", "json-schema-traverse": "^1.0.0", "require-from-string": "^2.0.2" } }, "sha512-Thbli+OlOj+iMPYFBVBfJ3OmCAnaSyNn4M1vz9T6Gka5Jt9ba/HIR56joy65tY6kx/FCF5VXNB819Y7/GUrBGA=="], - - "ajv-formats": ["ajv-formats@3.0.1", "", { "dependencies": { "ajv": "^8.0.0" } }, "sha512-8iUql50EUR+uUcdRQ3HDqa6EVyo3docL8g5WJ3FNcWmu62IbkGUue/pEyLBW8VGKKucTPgqeks4fIU1DA4yowQ=="], - - "body-parser": ["body-parser@2.2.2", "", { "dependencies": { "bytes": "^3.1.2", "content-type": "^1.0.5", "debug": "^4.4.3", "http-errors": "^2.0.0", "iconv-lite": "^0.7.0", "on-finished": "^2.4.1", "qs": "^6.14.1", "raw-body": "^3.0.1", "type-is": "^2.0.1" } }, "sha512-oP5VkATKlNwcgvxi0vM0p/D3n2C3EReYVX+DNYs5TjZFn/oQt2j+4sVJtSMr18pdRr8wjTcBl6LoV+FUwzPmNA=="], - "bun-types": ["bun-types@1.3.14", "", { "dependencies": { "@types/node": "*" } }, "sha512-4N0ig0fEomHt5R0KCFWjovxow98rIoRwKolrYdCcknNwMekCXRnWEUvgu5soYV8QXtVsrUD8B95MBOZGPvr6KQ=="], - "bytes": ["bytes@3.1.2", "", {}, "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg=="], - - "call-bind-apply-helpers": ["call-bind-apply-helpers@1.0.2", "", { "dependencies": { "es-errors": "^1.3.0", "function-bind": "^1.1.2" } }, "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ=="], - - "call-bound": ["call-bound@1.0.4", "", { "dependencies": { "call-bind-apply-helpers": "^1.0.2", "get-intrinsic": "^1.3.0" } }, "sha512-+ys997U96po4Kx/ABpBCqhA9EuxJaQWDQg7295H4hBphv3IZg0boBKuwYpt4YXp6MZ5AmZQnU/tyMTlRpaSejg=="], - - "content-disposition": ["content-disposition@1.1.0", "", {}, "sha512-5jRCH9Z/+DRP7rkvY83B+yGIGX96OYdJmzngqnw2SBSxqCFPd0w2km3s5iawpGX8krnwSGmF0FW5Nhr0Hfai3g=="], - - "content-type": ["content-type@1.0.5", "", {}, "sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA=="], - - "cookie": ["cookie@0.7.2", "", {}, "sha512-yki5XnKuf750l50uGTllt6kKILY4nQ1eNIQatoXEByZ5dWgnKqbnqmTrBE5B4N7lrMJKQ2ytWMiTO2o0v6Ew/w=="], - - "cookie-signature": ["cookie-signature@1.2.2", "", {}, "sha512-D76uU73ulSXrD1UXF4KE2TMxVVwhsnCgfAyTg9k8P6KGZjlXKrOLe4dJQKI3Bxi5wjesZoFXJWElNWBjPZMbhg=="], - - "cors": ["cors@2.8.6", "", { "dependencies": { "object-assign": "^4", "vary": "^1" } }, "sha512-tJtZBBHA6vjIAaF6EnIaq6laBBP9aq/Y3ouVJjEfoHbRBcHBAHYcMh/w8LDrk2PvIMMq8gmopa5D4V8RmbrxGw=="], - "cross-spawn": ["cross-spawn@7.0.6", "", { "dependencies": { "path-key": "^3.1.0", "shebang-command": "^2.0.0", "which": "^2.0.1" } }, "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA=="], - "debug": ["debug@4.4.3", "", { "dependencies": { "ms": "^2.1.3" } }, "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA=="], - - "depd": ["depd@2.0.0", "", {}, "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw=="], - - "dunder-proto": ["dunder-proto@1.0.1", "", { "dependencies": { "call-bind-apply-helpers": "^1.0.1", "es-errors": "^1.3.0", "gopd": "^1.2.0" } }, "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A=="], - - "ee-first": ["ee-first@1.1.1", "", {}, "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow=="], - - "encodeurl": ["encodeurl@2.0.0", "", {}, "sha512-Q0n9HRi4m6JuGIV1eFlmvJB7ZEVxu93IrMyiMsGC0lrMJMWzRgx6WGquyfQgZVb31vhGgXnfmPNNXmxnOkRBrg=="], - - "es-define-property": ["es-define-property@1.0.1", "", {}, "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g=="], - - "es-errors": ["es-errors@1.3.0", "", {}, "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw=="], - - "es-object-atoms": ["es-object-atoms@1.1.1", "", { "dependencies": { "es-errors": "^1.3.0" } }, "sha512-FGgH2h8zKNim9ljj7dankFPcICIK9Cp5bm+c2gQSYePhpaG5+esrLODihIorn+Pe6FGJzWhXQotPv73jTaldXA=="], - - "escape-html": ["escape-html@1.0.3", "", {}, "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow=="], - - "etag": ["etag@1.8.1", "", {}, "sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg=="], - "eventsource": ["eventsource@3.0.7", "", { "dependencies": { "eventsource-parser": "^3.0.1" } }, "sha512-CRT1WTyuQoD771GW56XEZFQ/ZoSfWid1alKGDYMmkt2yl8UXrVR4pspqWNEcqKvVIzg6PAltWjxcSSPrboA4iA=="], "eventsource-parser": ["eventsource-parser@3.0.8", "", {}, "sha512-70QWGkr4snxr0OXLRWsFLeRBIRPuQOvt4s8QYjmUlmlkyTZkRqS7EDVRZtzU3TiyDbXSzaOeF0XUKy8PchzukQ=="], - "express": ["express@5.2.1", "", { "dependencies": { "accepts": "^2.0.0", "body-parser": "^2.2.1", "content-disposition": "^1.0.0", "content-type": "^1.0.5", "cookie": "^0.7.1", "cookie-signature": "^1.2.1", "debug": "^4.4.0", "depd": "^2.0.0", "encodeurl": "^2.0.0", "escape-html": "^1.0.3", "etag": "^1.8.1", "finalhandler": "^2.1.0", "fresh": "^2.0.0", "http-errors": "^2.0.0", "merge-descriptors": "^2.0.0", "mime-types": "^3.0.0", "on-finished": "^2.4.1", "once": "^1.4.0", "parseurl": "^1.3.3", "proxy-addr": "^2.0.7", "qs": "^6.14.0", "range-parser": "^1.2.1", "router": "^2.2.0", "send": "^1.1.0", "serve-static": "^2.2.0", "statuses": "^2.0.1", "type-is": "^2.0.1", "vary": "^1.1.2" } }, "sha512-hIS4idWWai69NezIdRt2xFVofaF4j+6INOpJlVOLDO8zXGpUVEVzIYk12UUi2JzjEzWL3IOAxcTubgz9Po0yXw=="], - - "express-rate-limit": ["express-rate-limit@8.5.2", "", { "dependencies": { "ip-address": "^10.2.0" }, "peerDependencies": { "express": ">= 4.11" } }, "sha512-5Kb34ipNX694DH48vN9irak1Qx30nb0PLYHXfJgw4YEjiC3ZEmZJhwOp+VfiCYwFzvFTdB9QkArYS5kXa2cx2A=="], - - "fast-deep-equal": ["fast-deep-equal@3.1.3", "", {}, "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q=="], - - "fast-uri": ["fast-uri@3.1.2", "", {}, "sha512-rVjf7ArG3LTk+FS6Yw81V1DLuZl1bRbNrev6Tmd/9RaroeeRRJhAt7jg/6YFxbvAQXUCavSoZhPPj6oOx+5KjQ=="], - - "finalhandler": ["finalhandler@2.1.1", "", { "dependencies": { "debug": "^4.4.0", "encodeurl": "^2.0.0", "escape-html": "^1.0.3", "on-finished": "^2.4.1", "parseurl": "^1.3.3", "statuses": "^2.0.1" } }, "sha512-S8KoZgRZN+a5rNwqTxlZZePjT/4cnm0ROV70LedRHZ0p8u9fRID0hJUZQpkKLzro8LfmC8sx23bY6tVNxv8pQA=="], - - "forwarded": ["forwarded@0.2.0", "", {}, "sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow=="], - - "fresh": ["fresh@2.0.0", "", {}, "sha512-Rx/WycZ60HOaqLKAi6cHRKKI7zxWbJ31MhntmtwMoaTeF7XFH9hhBp8vITaMidfljRQ6eYWCKkaTK+ykVJHP2A=="], - - "function-bind": ["function-bind@1.1.2", "", {}, "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA=="], - - "get-intrinsic": ["get-intrinsic@1.3.0", "", { "dependencies": { "call-bind-apply-helpers": "^1.0.2", "es-define-property": "^1.0.1", "es-errors": "^1.3.0", "es-object-atoms": "^1.1.1", "function-bind": "^1.1.2", "get-proto": "^1.0.1", "gopd": "^1.2.0", "has-symbols": "^1.1.0", "hasown": "^2.0.2", "math-intrinsics": "^1.1.0" } }, "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ=="], - - "get-proto": ["get-proto@1.0.1", "", { "dependencies": { "dunder-proto": "^1.0.1", "es-object-atoms": "^1.0.0" } }, "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g=="], - - "gopd": ["gopd@1.2.0", "", {}, "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg=="], - - "has-symbols": ["has-symbols@1.1.0", "", {}, "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ=="], - - "hasown": ["hasown@2.0.3", "", { "dependencies": { "function-bind": "^1.1.2" } }, "sha512-ej4AhfhfL2Q2zpMmLo7U1Uv9+PyhIZpgQLGT1F9miIGmiCJIoCgSmczFdrc97mWT4kVY72KA+WnnhJ5pghSvSg=="], - - "hono": ["hono@4.12.19", "", {}, "sha512-xa3eYXYXx68XTT4hZ7dRzsXBhaq85ToSrlUJNoR0gwz/1Ap/CNwX47wfvV7pc/xWhjKVVkLT7zBJy8chhNguqQ=="], - - "http-errors": ["http-errors@2.0.1", "", { "dependencies": { "depd": "~2.0.0", "inherits": "~2.0.4", "setprototypeof": "~1.2.0", "statuses": "~2.0.2", "toidentifier": "~1.0.1" } }, "sha512-4FbRdAX+bSdmo4AUFuS0WNiPz8NgFt+r8ThgNWmlrjQjt1Q7ZR9+zTlce2859x4KSXrwIsaeTqDoKQmtP8pLmQ=="], - - "iconv-lite": ["iconv-lite@0.7.2", "", { "dependencies": { "safer-buffer": ">= 2.1.2 < 3.0.0" } }, "sha512-im9DjEDQ55s9fL4EYzOAv0yMqmMBSZp6G0VvFyTMPKWxiSBHUj9NW/qqLmXUwXrrM7AvqSlTCfvqRb0cM8yYqw=="], - - "inherits": ["inherits@2.0.4", "", {}, "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ=="], - - "ip-address": ["ip-address@10.2.0", "", {}, "sha512-/+S6j4E9AHvW9SWMSEY9Xfy66O5PWvVEJ08O0y5JGyEKQpojb0K0GKpz/v5HJ/G0vi3D2sjGK78119oXZeE0qA=="], - - "ipaddr.js": ["ipaddr.js@1.9.1", "", {}, "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g=="], - - "is-promise": ["is-promise@4.0.0", "", {}, "sha512-hvpoI6korhJMnej285dSg6nu1+e6uxs7zG3BYAm5byqDsgJNWwxzM6z6iZiAgQR4TJ30JmBTOwqZUw3WlyH3AQ=="], - "isexe": ["isexe@2.0.0", "", {}, "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw=="], "jose": ["jose@6.2.3", "", {}, "sha512-YYVDInQKFJfR/xa3ojUTl8c2KoTwiL1R5Wg9YCydwH0x0B9grbzlg5HC7mMjCtUJjbQ/YnGEZIhI5tCgfTb4Hw=="], - "json-schema-traverse": ["json-schema-traverse@1.0.0", "", {}, "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug=="], - - "json-schema-typed": ["json-schema-typed@8.0.2", "", {}, "sha512-fQhoXdcvc3V28x7C7BMs4P5+kNlgUURe2jmUT1T//oBRMDrqy1QPelJimwZGo7Hg9VPV3EQV5Bnq4hbFy2vetA=="], - "ky": ["ky@2.0.2", "", {}, "sha512-/GmXpo9F9W+f8n4Ivr2iH+7h7wL7jLbLKWkMlpflcCRb6kGjBfTlASEXaZ9qUgNTn4VgS0P2pwxxzQ4EM6Ulgg=="], - "math-intrinsics": ["math-intrinsics@1.1.0", "", {}, "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g=="], - - "media-typer": ["media-typer@1.1.0", "", {}, "sha512-aisnrDP4GNe06UcKFnV5bfMNPBUw4jsLGaWwWfnH3v02GnBuXX2MCVn5RbrWo0j3pczUilYblq7fQ7Nw2t5XKw=="], - - "merge-descriptors": ["merge-descriptors@2.0.0", "", {}, "sha512-Snk314V5ayFLhp3fkUREub6WtjBfPdCPY1Ln8/8munuLuiYhsABgBVWsozAG+MWMbVEvcdcpbi9R7ww22l9Q3g=="], - - "mime-db": ["mime-db@1.54.0", "", {}, "sha512-aU5EJuIN2WDemCcAp2vFBfp/m4EAhWJnUNSSw0ixs7/kXbd6Pg64EmwJkNdFhB8aWt1sH2CTXrLxo/iAGV3oPQ=="], - - "mime-types": ["mime-types@3.0.2", "", { "dependencies": { "mime-db": "^1.54.0" } }, "sha512-Lbgzdk0h4juoQ9fCKXW4by0UJqj+nOOrI9MJ1sSj4nI8aI2eo1qmvQEie4VD1glsS250n15LsWsYtCugiStS5A=="], - - "ms": ["ms@2.1.3", "", {}, "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA=="], - - "negotiator": ["negotiator@1.0.0", "", {}, "sha512-8Ofs/AUQh8MaEcrlq5xOX0CQ9ypTF5dl78mjlMNfOK08fzpgTHQRQPBxcPlEtIw0yRpws+Zo/3r+5WRby7u3Gg=="], - - "object-assign": ["object-assign@4.1.1", "", {}, "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg=="], - - "object-inspect": ["object-inspect@1.13.4", "", {}, "sha512-W67iLl4J2EXEGTbfeHCffrjDfitvLANg0UlX3wFUUSTx92KXRFegMHUVgSqE+wvhAbi4WqjGg9czysTV2Epbew=="], - - "on-finished": ["on-finished@2.4.1", "", { "dependencies": { "ee-first": "1.1.1" } }, "sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg=="], - - "once": ["once@1.4.0", "", { "dependencies": { "wrappy": "1" } }, "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w=="], - - "parseurl": ["parseurl@1.3.3", "", {}, "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ=="], - "path-key": ["path-key@3.1.1", "", {}, "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q=="], - "path-to-regexp": ["path-to-regexp@8.4.2", "", {}, "sha512-qRcuIdP69NPm4qbACK+aDogI5CBDMi1jKe0ry5rSQJz8JVLsC7jV8XpiJjGRLLol3N+R5ihGYcrPLTno6pAdBA=="], - "pkce-challenge": ["pkce-challenge@5.0.1", "", {}, "sha512-wQ0b/W4Fr01qtpHlqSqspcj3EhBvimsdh0KlHhH8HRZnMsEa0ea2fTULOXOS9ccQr3om+GcGRk4e+isrZWV8qQ=="], - "proxy-addr": ["proxy-addr@2.0.7", "", { "dependencies": { "forwarded": "0.2.0", "ipaddr.js": "1.9.1" } }, "sha512-llQsMLSUDUPT44jdrU/O37qlnifitDP+ZwrmmZcoSKyLKvtZxpyV0n2/bD/N4tBAAZ/gJEdZU7KMraoK1+XYAg=="], - - "qs": ["qs@6.15.2", "", { "dependencies": { "side-channel": "^1.1.0" } }, "sha512-Rzq0KEyX/w/tEybncDgdkZrJgVUsUMk3xjh3t5bv3S1HTAtg+uOYt72+ZfwiQwKdysThkTBdL/rTi6HDmX9Ddw=="], - - "range-parser": ["range-parser@1.2.1", "", {}, "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg=="], - - "raw-body": ["raw-body@3.0.2", "", { "dependencies": { "bytes": "~3.1.2", "http-errors": "~2.0.1", "iconv-lite": "~0.7.0", "unpipe": "~1.0.0" } }, "sha512-K5zQjDllxWkf7Z5xJdV0/B0WTNqx6vxG70zJE4N0kBs4LovmEYWJzQGxC9bS9RAKu3bgM40lrd5zoLJ12MQ5BA=="], - - "require-from-string": ["require-from-string@2.0.2", "", {}, "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw=="], - - "router": ["router@2.2.0", "", { "dependencies": { "debug": "^4.4.0", "depd": "^2.0.0", "is-promise": "^4.0.0", "parseurl": "^1.3.3", "path-to-regexp": "^8.0.0" } }, "sha512-nLTrUKm2UyiL7rlhapu/Zl45FwNgkZGaCpZbIHajDYgwlJCOzLSk+cIPAnsEqV955GjILJnKbdQC1nVPz+gAYQ=="], - - "safer-buffer": ["safer-buffer@2.1.2", "", {}, "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg=="], - - "send": ["send@1.2.1", "", { "dependencies": { "debug": "^4.4.3", "encodeurl": "^2.0.0", "escape-html": "^1.0.3", "etag": "^1.8.1", "fresh": "^2.0.0", "http-errors": "^2.0.1", "mime-types": "^3.0.2", "ms": "^2.1.3", "on-finished": "^2.4.1", "range-parser": "^1.2.1", "statuses": "^2.0.2" } }, "sha512-1gnZf7DFcoIcajTjTwjwuDjzuz4PPcY2StKPlsGAQ1+YH20IRVrBaXSWmdjowTJ6u8Rc01PoYOGHXfP1mYcZNQ=="], - - "serve-static": ["serve-static@2.2.1", "", { "dependencies": { "encodeurl": "^2.0.0", "escape-html": "^1.0.3", "parseurl": "^1.3.3", "send": "^1.2.0" } }, "sha512-xRXBn0pPqQTVQiC8wyQrKs2MOlX24zQ0POGaj0kultvoOCstBQM5yvOhAVSUwOMjQtTvsPWoNCHfPGwaaQJhTw=="], - - "setprototypeof": ["setprototypeof@1.2.0", "", {}, "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw=="], - "shebang-command": ["shebang-command@2.0.0", "", { "dependencies": { "shebang-regex": "^3.0.0" } }, "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA=="], "shebang-regex": ["shebang-regex@3.0.0", "", {}, "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A=="], - "side-channel": ["side-channel@1.1.0", "", { "dependencies": { "es-errors": "^1.3.0", "object-inspect": "^1.13.3", "side-channel-list": "^1.0.0", "side-channel-map": "^1.0.1", "side-channel-weakmap": "^1.0.2" } }, "sha512-ZX99e6tRweoUXqR+VBrslhda51Nh5MTQwou5tnUDgbtyM0dBgmhEDtWGP/xbKn6hqfPRHujUNwz5fy/wbbhnpw=="], - - "side-channel-list": ["side-channel-list@1.0.1", "", { "dependencies": { "es-errors": "^1.3.0", "object-inspect": "^1.13.4" } }, "sha512-mjn/0bi/oUURjc5Xl7IaWi/OJJJumuoJFQJfDDyO46+hBWsfaVM65TBHq2eoZBhzl9EchxOijpkbRC8SVBQU0w=="], - - "side-channel-map": ["side-channel-map@1.0.1", "", { "dependencies": { "call-bound": "^1.0.2", "es-errors": "^1.3.0", "get-intrinsic": "^1.2.5", "object-inspect": "^1.13.3" } }, "sha512-VCjCNfgMsby3tTdo02nbjtM/ewra6jPHmpThenkTYh8pG9ucZ/1P8So4u4FGBek/BjpOVsDCMoLA/iuBKIFXRA=="], - - "side-channel-weakmap": ["side-channel-weakmap@1.0.2", "", { "dependencies": { "call-bound": "^1.0.2", "es-errors": "^1.3.0", "get-intrinsic": "^1.2.5", "object-inspect": "^1.13.3", "side-channel-map": "^1.0.1" } }, "sha512-WPS/HvHQTYnHisLo9McqBHOJk2FkHO/tlpvldyrnem4aeQp4hai3gythswg6p01oSoTl58rcpiFAjF2br2Ak2A=="], - - "statuses": ["statuses@2.0.2", "", {}, "sha512-DvEy55V3DB7uknRo+4iOGT5fP1slR8wQohVdknigZPMpMstaKJQWhwiYBACJE3Ul2pTnATihhBYnRhZQHGBiRw=="], - - "toidentifier": ["toidentifier@1.0.1", "", {}, "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA=="], - - "type-is": ["type-is@2.1.0", "", { "dependencies": { "content-type": "^2.0.0", "media-typer": "^1.1.0", "mime-types": "^3.0.0" } }, "sha512-faYHw0anBbc/kWF3zFTEnxSFOAGUX9GFbOBthvDdLsIlEoWOFOtS0zgCiQYwIskL9iGXZL3kAXD8OoZ4GmMATA=="], - "typescript": ["typescript@5.9.3", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw=="], "undici-types": ["undici-types@7.24.6", "", {}, "sha512-WRNW+sJgj5OBN4/0JpHFqtqzhpbnV0GuB+OozA9gCL7a993SmU+1JBZCzLNxYsbMfIeDL+lTsphD5jN5N+n0zg=="], - "unpipe": ["unpipe@1.0.0", "", {}, "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ=="], - - "vary": ["vary@1.1.2", "", {}, "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg=="], - "which": ["which@2.0.2", "", { "dependencies": { "isexe": "^2.0.0" }, "bin": { "node-which": "./bin/node-which" } }, "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA=="], - "wrappy": ["wrappy@1.0.2", "", {}, "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ=="], - "yaml": ["yaml@2.9.0", "", { "bin": { "yaml": "bin.mjs" } }, "sha512-2AvhNX3mb8zd6Zy7INTtSpl1F15HW6Wnqj0srWlkKLcpYl/gMIMJiyuGq2KeI2YFxUPjdlB+3Lc10seMLtL4cA=="], "zod": ["zod@4.4.3", "", {}, "sha512-ytENFjIJFl2UwYglde2jchW2Hwm4GJFLDiSXWdTrJQBIN9Fcyp7n4DhxJEiWNAJMV1/BqWfW/kkg71UDcHJyTQ=="], - - "zod-to-json-schema": ["zod-to-json-schema@3.25.2", "", { "peerDependencies": { "zod": "^3.25.28 || ^4" } }, "sha512-O/PgfnpT1xKSDeQYSCfRI5Gy3hPf91mKVDuYLUHZJMiDFptvP41MSnWofm8dnCm0256ZNfZIM7DSzuSMAFnjHA=="], - - "type-is/content-type": ["content-type@2.0.0", "", {}, "sha512-j/O/d7GcZCyNl7/hwZAb606rzqkyvaDctLmckbxLzHvFBzTJHuGEdodATcP3yIRoDrLHkIATJuvzbFlp/ki2cQ=="], } } diff --git a/dist/openapi.json b/dist/openapi.json index d164045..5e9065a 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.6.1", + "version": "0.6.2", "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 72e3ec5..0c0cc28 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.6.1 + version: 0.6.2 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 980386a..eca03b2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hose-use", - "version": "0.6.1", + "version": "0.6.2", "module": "src/server.ts", "type": "module", "bin": { @@ -23,12 +23,14 @@ "export:workflow-schema": "bun run scripts/export-workflow-schema.ts" }, "dependencies": { - "@modelcontextprotocol/sdk": "^1.29.0", + "@modelcontextprotocol/core": "^2.0.0", + "@modelcontextprotocol/server": "^2.0.0", "ky": "^2.0.2", "yaml": "^2.9.0", "zod": "^4.4.3" }, "devDependencies": { + "@modelcontextprotocol/client": "^2.0.0", "@types/bun": "^1.3.14", "typescript": "^5.9.3" } diff --git a/skills/hose-use/SKILL.md b/skills/hose-use/SKILL.md index 2144aee..5c9bbd5 100644 --- a/skills/hose-use/SKILL.md +++ b/skills/hose-use/SKILL.md @@ -6,7 +6,7 @@ metadata: short-description: 合思/易快报企业级 CLI 工具与底层 SDK (v0.6.0) --- -# hose-use (v0.6.1) +# hose-use (v0.6.2) 在具备 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 fe79252..bba1bd1 100644 --- a/src/cli/commands/config.ts +++ b/src/cli/commands/config.ts @@ -48,6 +48,8 @@ async function handleShow(parsed: CliParsedArgs, runtime: CliRuntime): Promise\n 指定企业: hose corps switch \n`, + stdout: `====== 全局运行配置 ======\n${output}\n\n提示:\n 切换模式: hose config mode \n 指定企业: hose corps switch \n 更新源设置: hose config set updateSource \n`, stderr: "", exitCode: 0, }; @@ -95,10 +99,10 @@ async function handleMode(parsed: CliParsedArgs, runtime: CliRuntime): Promise { - const key = parsed.args[0]; + const rawKey = parsed.args[0]; const val = parsed.args[1]; - if (!key || val === undefined) { + if (!rawKey || val === undefined) { return { stdout: "", stderr: "用法: hose config set (如 hose config set defaultCorpId uzU7pcWfScck00)\n", @@ -106,17 +110,37 @@ async function handleSet(parsed: CliParsedArgs, runtime: CliRuntime): Promise = {}; - if (key === "stateful") { + let resolvedKey = rawKey; + + if (keyLower === "stateful") { + resolvedKey = "stateful"; partial.stateful = val === "true" || val === "1"; - } else if (key === "defaultCorpId") { + } else if (keyLower === "defaultcorpid") { + resolvedKey = "defaultCorpId"; partial.defaultCorpId = val; - } else if (key === "defaultAccountId") { + } else if (keyLower === "defaultaccountid") { + resolvedKey = "defaultAccountId"; partial.defaultAccountId = val; + } else if (keyLower === "updaterepo") { + resolvedKey = "updateRepo"; + partial.updateRepo = val; + } else if (keyLower === "updatesource") { + resolvedKey = "updateSource"; + const srcLower = val.toLowerCase(); + if (srcLower !== "auto" && srcLower !== "github" && srcLower !== "gitea") { + return { + stdout: "", + stderr: `不支持的 updateSource 值: ${val}。可选: auto, github, gitea\n`, + exitCode: 1, + }; + } + partial.updateSource = srcLower; } else { return { stdout: "", - stderr: `不支持配置键: ${key}。支持: stateful, defaultCorpId, defaultAccountId\n`, + stderr: `不支持配置键: ${rawKey}。支持: stateful, defaultCorpId, defaultAccountId, updateRepo, updateSource\n`, exitCode: 1, }; } @@ -127,7 +151,7 @@ async function handleSet(parsed: CliParsedArgs, runtime: CliRuntime): Promise { test("correctly identifies newer semantic versions", () => { @@ -20,6 +27,29 @@ describe("update version comparator", () => { }); }); +describe("normalizeRepo and isValidRepo", () => { + test("normalizeRepo trims and cleans various GitHub URL formats", () => { + expect(normalizeRepo("yunyingk/hose-use")).toBe("yunyingk/hose-use"); + expect(normalizeRepo("https://github.com/yunyingk/hose-use")).toBe("yunyingk/hose-use"); + expect(normalizeRepo("https://github.com/yunyingk/hose-use.git")).toBe("yunyingk/hose-use"); + expect(normalizeRepo("http://www.github.com/my-org/my-fork/")).toBe("my-org/my-fork"); + expect(normalizeRepo(" custom/project.git ")).toBe("custom/project"); + expect(normalizeRepo("github.com/test-org/repo")).toBe("test-org/repo"); + }); + + test("isValidRepo validates owner/repo format and rejects illegal inputs", () => { + expect(isValidRepo("yunyingk/hose-use")).toBe(true); + expect(isValidRepo("my-org/hose-use-fork")).toBe(true); + expect(isValidRepo("user.name/repo_name.v2")).toBe(true); + + expect(isValidRepo("")).toBe(false); + expect(isValidRepo("single-word")).toBe(false); + expect(isValidRepo("too/many/parts/here")).toBe(false); + expect(isValidRepo("../path/traversal")).toBe(false); + expect(isValidRepo("invalid character/repo")).toBe(false); + }); +}); + describe("matchAssetForPlatform", () => { const assets: GitHubAsset[] = [ { name: "hose-use-darwin-arm64", downloadUrl: "https://example.com/darwin-arm64", size: 100 }, @@ -49,3 +79,4 @@ describe("matchAssetForPlatform", () => { expect(matched?.name).toBe("hose-use-windows-x64.zip"); }); }); + diff --git a/src/cli/commands/update.ts b/src/cli/commands/update.ts index 2748029..058f30f 100644 --- a/src/cli/commands/update.ts +++ b/src/cli/commands/update.ts @@ -3,6 +3,7 @@ import { dirname, join } from "node:path"; import { spawnSync } from "node:child_process"; import { isCompiledBinary, resolveAppRoot } from "../../core/runtime.js"; import { syncGlobalSkillIfPresent } from "../../core/embedded-skill.js"; +import { loadGlobalConfig } from "../../core/config/loader.js"; import { VERSION } from "../../version.js"; import { booleanOption, numberOption, stringOption } from "../parser.js"; import { printJson, printKeyValue } from "../printer.js"; @@ -11,15 +12,29 @@ import type { CliParsedArgs, CliResult, CliRunOptions, CliRuntime } from "../typ const DEFAULT_GITHUB_REPO = "yunyingk/hose-use"; const GITHUB_REPO_ENV = "HOSE_USE_GITHUB_REPO"; +export type UpdateSourcePreference = "auto" | "github" | "gitea"; + export type UpdateOptions = { checkOnly?: boolean; changelogOnly?: boolean; limit?: number; force?: boolean; targetVersion?: string; - repo?: string; + repo: string; + sourcePreference: UpdateSourcePreference; }; +export function normalizeRepo(raw: string): string { + let repo = raw.trim(); + repo = repo.replace(/^(https?:\/\/)?(www\.)?github\.com\//i, ""); + repo = repo.replace(/\.git$/i, "").replace(/\/+$/, ""); + return repo; +} + +export function isValidRepo(repo: string): boolean { + return /^[a-zA-Z0-9_.-]+\/[a-zA-Z0-9_.-]+$/.test(repo); +} + export async function handleUpdateCommand( parsed: CliParsedArgs, runtime: CliRuntime, @@ -47,11 +62,44 @@ export async function handleUpdateCommand( ? targetVersionRaw.replace(/^v/, "") : undefined; - const repo = + const isGitHub = booleanOption(parsed.options, ["github", "gh"]); + const isGitea = booleanOption(parsed.options, ["gitea", "yingqing", "mirror"]); + const globalConfig = loadGlobalConfig(); + const configuredSource = globalConfig.updateSource || "auto"; + + let sourcePreference: UpdateSourcePreference = "auto"; + if (isGitHub) { + sourcePreference = "github"; + } else if (isGitea) { + sourcePreference = "gitea"; + } else if (configuredSource === "github" || configuredSource === "gitea") { + sourcePreference = configuredSource; + } + + const rawRepo = stringOption(parsed.options, ["repo"]) || process.env[GITHUB_REPO_ENV]?.trim() || + globalConfig.updateRepo?.trim() || DEFAULT_GITHUB_REPO; + const repo = normalizeRepo(rawRepo); + + if (!isValidRepo(repo)) { + const errorMsg = `非法 GitHub 仓库标识: '${rawRepo}'。应为 'owner/repo' 格式(如 'yunyingk/hose-use')。`; + if (runtime.jsonMode) { + return { + stdout: printJson({ updated: false, error: true, message: errorMsg }), + stderr: "", + exitCode: 1, + }; + } + return { + stdout: "", + stderr: `[ERROR] ${errorMsg}\n`, + exitCode: 1, + }; + } + const options: UpdateOptions = { checkOnly: isCheck, changelogOnly: isChangelog, @@ -59,6 +107,7 @@ export async function handleUpdateCommand( force: booleanOption(parsed.options, ["force", "f"]), targetVersion, repo, + sourcePreference, }; const appRoot = runOptions.appRoot || resolveAppRoot(runOptions.entryFile); @@ -112,11 +161,13 @@ export async function handleUpdateCommand( // 1. Changelog / Release History query if (options.changelogOnly) { - const releases = await fetchGitHubReleases(repo, options.limit ?? 10); + const releases = await fetchGitHubReleases(repo, options.limit ?? 10, options.sourcePreference); if (runtime.jsonMode) { return { stdout: printJson({ currentVersion: VERSION, + repo, + sourcePreference: options.sourcePreference, totalQueried: releases.length, releases: releases.map((r) => ({ version: r.version, @@ -157,7 +208,7 @@ export async function handleUpdateCommand( // 2. Source development mode (running via bun/node) if (!isCompiledBinary()) { if (options.checkOnly) { - const releases = await fetchGitHubReleases(repo, 30); + const releases = await fetchGitHubReleases(repo, 30, options.sourcePreference); const latestRelease = releases[0]; const latestVersion = latestRelease?.version ?? VERSION; const currentRelease = releases.find((r) => r.version === VERSION); @@ -174,6 +225,8 @@ export async function handleUpdateCommand( latestVersion, latestVersionPublishedAt: latestRelease?.publishedAt, behindCount: pendingReleases.length, + repo, + sourcePreference: options.sourcePreference, pendingReleases: pendingReleases.map((r) => ({ version: r.version, tagName: r.tagName, @@ -197,6 +250,8 @@ export async function handleUpdateCommand( "当前版本": `v${VERSION}`, "最新版本": `v${latestVersion} ${isUpgrade ? "(可升级 ✨)" : "(已是最新 ✅)"}`, "待更新版本数": pendingReleases.length, + "发布仓库": repo, + "通道偏好": options.sourcePreference, "源码路径": appRoot, }); @@ -241,11 +296,11 @@ export async function handleUpdateCommand( const platform = detectPlatform(); const arch = detectArch(); - const releases = await fetchGitHubReleases(repo, 30); + const releases = await fetchGitHubReleases(repo, 30, options.sourcePreference); const release = targetVersion ? (releases.find((r) => r.version === targetVersion || r.tagName === targetVersion || r.tagName === `v${targetVersion}`) ?? - await fetchGitHubRelease(repo, targetVersion)) - : (releases[0] ?? await fetchGitHubRelease(repo)); + await fetchGitHubRelease(repo, targetVersion, options.sourcePreference)) + : (releases[0] ?? await fetchGitHubRelease(repo, undefined, options.sourcePreference)); if (!release) { const errorMsg = `无法从 GitHub 仓库 '${repo}' 获取 Release 列表`; @@ -254,6 +309,8 @@ export async function handleUpdateCommand( stdout: printJson({ updated: false, currentVersion: VERSION, + repo, + sourcePreference: options.sourcePreference, mode: "binary", message: errorMsg, }), @@ -285,6 +342,8 @@ export async function handleUpdateCommand( latestVersion, latestVersionPublishedAt: release.publishedAt, behindCount: pendingReleases.length, + repo, + sourcePreference: options.sourcePreference, pendingReleases: pendingReleases.map((r) => ({ version: r.version, tagName: r.tagName, @@ -308,6 +367,8 @@ export async function handleUpdateCommand( "最新版本": `v${latestVersion} ${isUpgrade ? "(可升级 ✨)" : "(已是最新 ✅)"}`, "发布时间": release.publishedAt ? release.publishedAt.slice(0, 10) : "未知", "平台架构": `${platform}-${arch}`, + "发布仓库": repo, + "通道偏好": options.sourcePreference, }); return { @@ -326,6 +387,8 @@ export async function handleUpdateCommand( currentVersionPublishedAt: currentRelease?.publishedAt, latestVersion, latestVersionPublishedAt: release.publishedAt, + repo, + sourcePreference: options.sourcePreference, mode: "binary", message: `hose-use 当前已是最新版本 (v${VERSION})`, }), @@ -365,7 +428,7 @@ export async function handleUpdateCommand( try { const downloadedFile = join(tmpDir, asset.name); - await downloadFile(asset.downloadUrl, downloadedFile, release.tagName, asset.name); + await downloadFile(asset.downloadUrl, downloadedFile, release.tagName, asset.name, repo, options.sourcePreference); let newBinaryPath = downloadedFile; if (asset.name.endsWith(".tar.gz") || asset.name.endsWith(".tgz")) { @@ -456,7 +519,11 @@ export type GitHubRelease = { assets: GitHubAsset[]; }; -export async function fetchGitHubReleases(repo: string, limit = 20): Promise { +export async function fetchGitHubReleases( + repo: string, + limit = 20, + sourcePreference: UpdateSourcePreference = "auto" +): Promise { const token = process.env.GITHUB_TOKEN || process.env.GH_TOKEN; const headers: Record = { "User-Agent": `hose-use/${VERSION}`, @@ -464,10 +531,23 @@ export async function fetchGitHubReleases(repo: string, limit = 20): Promise { const tag = targetVersion ? (targetVersion.startsWith("v") ? targetVersion : `v${targetVersion}`) : undefined; const token = process.env.GITHUB_TOKEN || process.env.GH_TOKEN; @@ -536,15 +617,26 @@ export async function fetchGitHubRelease( ...(token ? { Authorization: `Bearer ${token}` } : {}), }; - const urls = tag - ? [ - `https://git.ying-qing.cn/api/v1/repos/gitea/hose-use/releases/tags/${tag}`, - `https://api.github.com/repos/${repo}/releases/tags/${tag}`, - ] - : [ - `https://git.ying-qing.cn/api/v1/repos/gitea/hose-use/releases/latest`, - `https://api.github.com/repos/${repo}/releases/latest`, - ]; + const isDefaultRepo = repo.toLowerCase() === DEFAULT_GITHUB_REPO.toLowerCase(); + const allowGitea = isDefaultRepo && sourcePreference !== "github"; + + const urls: string[] = []; + const giteaTagUrl = tag + ? `https://git.ying-qing.cn/api/v1/repos/gitea/hose-use/releases/tags/${tag}` + : `https://git.ying-qing.cn/api/v1/repos/gitea/hose-use/releases/latest`; + const githubTagUrl = tag + ? `https://api.github.com/repos/${repo}/releases/tags/${tag}` + : `https://api.github.com/repos/${repo}/releases/latest`; + + if (sourcePreference === "github") { + urls.push(githubTagUrl); + } else if (sourcePreference === "gitea") { + if (allowGitea) urls.push(giteaTagUrl); + urls.push(githubTagUrl); + } else { + if (allowGitea) urls.push(giteaTagUrl); + urls.push(githubTagUrl); + } let fallbackRelease: GitHubRelease | undefined; @@ -651,32 +743,47 @@ function logProgress(msg: string) { } } -async function downloadFile(url: string, destPath: string, tagName?: string, assetName?: string) { +export async function downloadFile( + url: string, + destPath: string, + tagName?: string, + assetName?: string, + repo: string = DEFAULT_GITHUB_REPO, + sourcePreference: UpdateSourcePreference = "auto" +) { const candidates: string[] = []; const tag = tagName ? (tagName.startsWith("v") ? tagName : `v${tagName}`) : undefined; const fileName = assetName || url.split("/").pop() || ""; + const isDefaultRepo = repo.toLowerCase() === DEFAULT_GITHUB_REPO.toLowerCase(); + const allowGitea = isDefaultRepo && sourcePreference !== "github"; - // 1. High-speed Gitea direct mirror first - if (tag && fileName) { - candidates.push(`https://git.ying-qing.cn/gitea/hose-use/releases/download/${tag}/${fileName}`); - } - if (url.startsWith("https://git.ying-qing.cn")) { - candidates.push(url); + // 1. High-speed Gitea direct mirror first (only for default official repo) + if (allowGitea) { + if (tag && fileName) { + candidates.push(`https://git.ying-qing.cn/gitea/hose-use/releases/download/${tag}/${fileName}`); + } + if (url.startsWith("https://git.ying-qing.cn")) { + candidates.push(url); + } } - // 2. Fast GitHub CDN proxies and direct GitHub fallback + // 2. Fast GitHub CDN proxies and direct GitHub fallback (dynamic repo) if (tag && fileName) { - const ghDirectUrl = `https://github.com/${DEFAULT_GITHUB_REPO}/releases/download/${tag}/${fileName}`; - candidates.push(`https://ghfast.top/${ghDirectUrl}`); - candidates.push(`https://ghproxy.net/${ghDirectUrl}`); - candidates.push(`https://gh.ddlc.top/${ghDirectUrl}`); - candidates.push(`https://mirror.ghproxy.com/${ghDirectUrl}`); + const ghDirectUrl = `https://github.com/${repo}/releases/download/${tag}/${fileName}`; + if (sourcePreference !== "gitea") { + candidates.push(`https://ghfast.top/${ghDirectUrl}`); + candidates.push(`https://ghproxy.net/${ghDirectUrl}`); + candidates.push(`https://gh.ddlc.top/${ghDirectUrl}`); + candidates.push(`https://mirror.ghproxy.com/${ghDirectUrl}`); + } candidates.push(ghDirectUrl); } else if (url.includes("github.com")) { - candidates.push(`https://ghfast.top/${url}`); - candidates.push(`https://ghproxy.net/${url}`); - candidates.push(`https://gh.ddlc.top/${url}`); - candidates.push(`https://mirror.ghproxy.com/${url}`); + if (sourcePreference !== "gitea") { + candidates.push(`https://ghfast.top/${url}`); + candidates.push(`https://ghproxy.net/${url}`); + candidates.push(`https://gh.ddlc.top/${url}`); + candidates.push(`https://mirror.ghproxy.com/${url}`); + } candidates.push(url); } else { candidates.push(url); diff --git a/src/cli/printer.ts b/src/cli/printer.ts index 726638a..40ed9ca 100644 --- a/src/cli/printer.ts +++ b/src/cli/printer.ts @@ -129,7 +129,7 @@ export function printHelp(): string { permission 权限模型快照 (get) skill Agent Skill 管理 (install, status, dump) probe 连通性诊断 (probe [corpId]) - update 版本自更新与发布记录 (update, update check, update --changelog) + update 版本自更新与发布记录 (update, update check, update --changelog, --github, --gitea, --repo=) openapi OpenAPI 3.1.0 规范导出 (openapi, openapi --raw, openapi paths, openapi info) http 启动轻量 HTTP Server 与交互式文档 (http [--port=8888] [--host=127.0.0.1]) service 常驻守护进程管理 (service start|stop|restart|status|logs|poll) @@ -194,6 +194,7 @@ export function printHelp(): string { hose-use probe # 诊断当前企业鉴权连通性 hose-use skill install # 安装 Agent 技能到用户目录 hose-use update # 自动检查并升级到最新版本 + hose-use update --github # 强制走官方 GitHub 源升级 hose-use update --changelog # 查看版本发布历史 hose-use openapi paths # 查看所有 API 路径与概要一览 hose-use openapi --raw # 导出原生下游全量 OpenAPI 规范 diff --git a/src/core/config/loader.ts b/src/core/config/loader.ts index bb9fecf..e189ad2 100644 --- a/src/core/config/loader.ts +++ b/src/core/config/loader.ts @@ -86,11 +86,7 @@ export function loadGlobalConfig(): GlobalConfig { // 容错返回默认 } - return { - stateful: true, - defaultCorpId: undefined, - defaultAccountId: undefined, - }; + return GlobalConfigSchema.parse({}); } export function saveGlobalConfig(config: Partial): GlobalConfig { diff --git a/src/core/config/types.ts b/src/core/config/types.ts index 627e2c9..9b3f57b 100644 --- a/src/core/config/types.ts +++ b/src/core/config/types.ts @@ -65,6 +65,9 @@ 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("默认主账号"), + updateRepo: z.string().optional().describe("默认自更新的 GitHub 仓库 (owner/repo)"), + updateSource: z.enum(["auto", "github", "gitea"]).optional().default("auto").describe("默认自更新源通道偏好 (auto/github/gitea)"), }); export type GlobalConfig = z.infer; + diff --git a/src/server.test.ts b/src/server.test.ts index e78b375..2047b9c 100644 --- a/src/server.test.ts +++ b/src/server.test.ts @@ -1,6 +1,6 @@ import { describe, expect, test } from "bun:test"; -import { Client } from "@modelcontextprotocol/sdk/client/index.js"; -import { InMemoryTransport } from "@modelcontextprotocol/sdk/inMemory.js"; +import { Client } from "@modelcontextprotocol/client"; +import { InMemoryTransport } from "@modelcontextprotocol/server"; import { createServer, resolveMcpMode, diff --git a/src/server.ts b/src/server.ts index 1d363da..921b169 100644 --- a/src/server.ts +++ b/src/server.ts @@ -1,9 +1,5 @@ -import { Server } from "@modelcontextprotocol/sdk/server/index.js"; -import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"; -import { - CallToolRequestSchema, - ListToolsRequestSchema, -} from "@modelcontextprotocol/sdk/types.js"; +import { Server } from "@modelcontextprotocol/server"; +import { StdioServerTransport } from "@modelcontextprotocol/server/stdio"; import { z } from "zod"; import { dirname, resolve } from "node:path"; import { fileURLToPath } from "node:url"; @@ -192,7 +188,7 @@ export function createServer(options: { mode?: HoseMcpMode; enabled?: boolean } const fineGrainedTools = [...authTools, ...platformTools, ...billTools]; // 注册工具列表 - server.setRequestHandler(ListToolsRequestSchema, async () => { + server.setRequestHandler("tools/list", async () => { if (!enabled) { return { tools: [] }; } @@ -234,7 +230,7 @@ export function createServer(options: { mode?: HoseMcpMode; enabled?: boolean } }); // 处理工具调用 - server.setRequestHandler(CallToolRequestSchema, async (request) => { + server.setRequestHandler("tools/call", async (request: any) => { if (!enabled) { return cliResult({ stdout: "", diff --git a/src/version.ts b/src/version.ts index 72a3111..402ed8e 100644 --- a/src/version.ts +++ b/src/version.ts @@ -1 +1 @@ -export const VERSION = "0.6.1"; +export const VERSION = "0.6.2";