@skillbuilder/minitool-cli 0.0.0-beta-20261027053041051

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/README.md +185 -0
  2. package/bin/redminitool.js +176 -0
  3. package/lib/bootstrap.js +69 -0
  4. package/lib/commands/auth/identity.js +98 -0
  5. package/lib/commands/auth/index.js +20 -0
  6. package/lib/commands/auth/login.js +148 -0
  7. package/lib/commands/auth/logout.js +52 -0
  8. package/lib/commands/auth/storage.js +105 -0
  9. package/lib/commands/dev/dev.test.js +108 -0
  10. package/lib/commands/dev.js +119 -0
  11. package/lib/commands/index.js +19 -0
  12. package/lib/commands/minitool/cli.test.js +222 -0
  13. package/lib/commands/minitool/commands.test.js +119 -0
  14. package/lib/commands/minitool/common.js +103 -0
  15. package/lib/commands/minitool/config.js +51 -0
  16. package/lib/commands/minitool/edit.js +55 -0
  17. package/lib/commands/minitool/history.js +56 -0
  18. package/lib/commands/minitool/index.js +24 -0
  19. package/lib/commands/minitool/list.js +65 -0
  20. package/lib/commands/minitool/preview.js +115 -0
  21. package/lib/commands/minitool/status.js +55 -0
  22. package/lib/commands/minitool/submit.js +58 -0
  23. package/lib/commands/minitool/upload.js +80 -0
  24. package/lib/core/base.js +133 -0
  25. package/lib/decorators/auth.js +26 -0
  26. package/lib/decorators/captureError.js +32 -0
  27. package/lib/decorators/constants.js +11 -0
  28. package/lib/decorators/decorators.test.js +94 -0
  29. package/lib/decorators/index.js +21 -0
  30. package/lib/decorators/injectParams.js +30 -0
  31. package/lib/decorators/json-output.js +18 -0
  32. package/lib/decorators/params/common.js +21 -0
  33. package/lib/decorators/params/index.js +24 -0
  34. package/lib/index.js +18 -0
  35. package/lib/main.js +26 -0
  36. package/lib/mcp.js +197 -0
  37. package/lib/output.js +7 -0
  38. package/lib/ui.js +39 -0
  39. package/lib/utils/agent-check.js +157 -0
  40. package/lib/utils/templates.js +75 -0
  41. package/package.json +48 -0
  42. package/types/bootstrap.d.ts +14 -0
  43. package/types/commands/auth/identity.d.ts +9 -0
  44. package/types/commands/auth/index.d.ts +4 -0
  45. package/types/commands/auth/login.d.ts +13 -0
  46. package/types/commands/auth/logout.d.ts +7 -0
  47. package/types/commands/auth/storage.d.ts +14 -0
  48. package/types/commands/dev/dev.test.d.ts +1 -0
  49. package/types/commands/dev.d.ts +8 -0
  50. package/types/commands/index.d.ts +3 -0
  51. package/types/commands/minitool/cli.test.d.ts +1 -0
  52. package/types/commands/minitool/commands.test.d.ts +1 -0
  53. package/types/commands/minitool/common.d.ts +12 -0
  54. package/types/commands/minitool/config.d.ts +5 -0
  55. package/types/commands/minitool/edit.d.ts +20 -0
  56. package/types/commands/minitool/history.d.ts +5 -0
  57. package/types/commands/minitool/index.d.ts +8 -0
  58. package/types/commands/minitool/list.d.ts +5 -0
  59. package/types/commands/minitool/preview.d.ts +23 -0
  60. package/types/commands/minitool/status.d.ts +5 -0
  61. package/types/commands/minitool/submit.d.ts +25 -0
  62. package/types/commands/minitool/upload.d.ts +20 -0
  63. package/types/core/base.d.ts +37 -0
  64. package/types/decorators/auth.d.ts +1 -0
  65. package/types/decorators/captureError.d.ts +1 -0
  66. package/types/decorators/constants.d.ts +7 -0
  67. package/types/decorators/decorators.test.d.ts +1 -0
  68. package/types/decorators/index.d.ts +5 -0
  69. package/types/decorators/injectParams.d.ts +1 -0
  70. package/types/decorators/json-output.d.ts +2 -0
  71. package/types/decorators/params/common.d.ts +10 -0
  72. package/types/decorators/params/index.d.ts +5 -0
  73. package/types/index.d.ts +2 -0
  74. package/types/main.d.ts +5 -0
  75. package/types/mcp.d.ts +9 -0
  76. package/types/output.d.ts +4 -0
  77. package/types/ui.d.ts +4 -0
  78. package/types/utils/agent-check.d.ts +16 -0
  79. package/types/utils/templates.d.ts +17 -0
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
15
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
16
+ return new (P || (P = Promise))(function (resolve, reject) {
17
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
18
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
19
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
20
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
21
+ });
22
+ };
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ const assert_1 = require("assert");
25
+ const _1 = require(".");
26
+ const test = require("node:test");
27
+ function context(status) {
28
+ return {
29
+ options: { page: 2 },
30
+ params: ["sample"],
31
+ services: {
32
+ auth: {
33
+ getAuthState: () => __awaiter(this, void 0, void 0, function* () {
34
+ return status === "authenticated"
35
+ ? {
36
+ status: "authenticated",
37
+ method: "secret",
38
+ source: "local_file",
39
+ identitySnapshot: null,
40
+ expiresAt: "2030-01-01T00:00:00.000Z",
41
+ }
42
+ : status === "unavailable"
43
+ ? { status: "unavailable", reason: "credential_store_error" }
44
+ : { status: "anonymous", reason: "not_logged_in" };
45
+ }),
46
+ },
47
+ },
48
+ };
49
+ }
50
+ test("AuthGuard 使用当前登录态,不执行未登录命令", () => __awaiter(void 0, void 0, void 0, function* () {
51
+ let invoked = false;
52
+ let ProtectedCommand = class ProtectedCommand {
53
+ execute(_ctx) {
54
+ return __awaiter(this, void 0, void 0, function* () {
55
+ invoked = true;
56
+ });
57
+ }
58
+ };
59
+ ProtectedCommand = __decorate([
60
+ (0, _1.AuthGuard)()
61
+ ], ProtectedCommand);
62
+ const command = new ProtectedCommand();
63
+ yield assert_1.strict.rejects(command.execute(context("anonymous")), { code: "AUTHENTICATION_REQUIRED" });
64
+ yield assert_1.strict.rejects(command.execute(context("unavailable")), {
65
+ code: "CREDENTIAL_STORE_UNAVAILABLE",
66
+ });
67
+ assert_1.strict.equal(invoked, false);
68
+ yield command.execute(context("authenticated"));
69
+ assert_1.strict.equal(invoked, true);
70
+ }));
71
+ test("InjectParams 注入命令参数和脱敏会话,不注入原始秘钥", () => __awaiter(void 0, void 0, void 0, function* () {
72
+ class ParamCommand {
73
+ execute(options, params, credential) {
74
+ return __awaiter(this, void 0, void 0, function* () {
75
+ return { options, params, credential };
76
+ });
77
+ }
78
+ }
79
+ __decorate([
80
+ (0, _1.InjectParams)(),
81
+ __param(0, (0, _1.ArgsOptions)()),
82
+ __param(1, (0, _1.ArgsParams)()),
83
+ __param(2, (0, _1.Credential)()),
84
+ __metadata("design:type", Function),
85
+ __metadata("design:paramtypes", [Object, Array, Object]),
86
+ __metadata("design:returntype", Promise)
87
+ ], ParamCommand.prototype, "execute", null);
88
+ const result = yield new ParamCommand().execute(context("authenticated"), [], { status: "anonymous" });
89
+ assert_1.strict.deepEqual(result.options, { page: 2 });
90
+ assert_1.strict.deepEqual(result.params, ["sample"]);
91
+ assert_1.strict.equal(result.credential.status, "authenticated");
92
+ assert_1.strict.equal(JSON.stringify(result).includes("sessionToken"), false);
93
+ assert_1.strict.equal(JSON.stringify(result).includes("secretKey"), false);
94
+ }));
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./auth"), exports);
18
+ __exportStar(require("./captureError"), exports);
19
+ __exportStar(require("./injectParams"), exports);
20
+ __exportStar(require("./json-output"), exports);
21
+ __exportStar(require("./params"), exports);
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.InjectParams = InjectParams;
13
+ const common_1 = require("./params/common");
14
+ function InjectParams() {
15
+ return (_target, _key, descriptor) => {
16
+ const original = descriptor.value;
17
+ if (typeof original !== "function")
18
+ return descriptor;
19
+ const bindings = (0, common_1.getParamBindings)(original);
20
+ descriptor.value = function (context, ...rest) {
21
+ return __awaiter(this, void 0, void 0, function* () {
22
+ const args = [context, ...rest];
23
+ for (const { index, getter } of bindings)
24
+ args[index] = yield getter(context);
25
+ return original.apply(this, args);
26
+ });
27
+ };
28
+ return descriptor;
29
+ };
30
+ }
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.JsonOutput = JsonOutput;
4
+ exports.isJsonOutputEnabled = isJsonOutputEnabled;
5
+ const JSON_OUTPUT_ENABLED = Symbol("redminitool.json-output-enabled");
6
+ function JsonOutput() {
7
+ return (target) => {
8
+ Object.defineProperty(target.prototype, JSON_OUTPUT_ENABLED, {
9
+ configurable: false,
10
+ enumerable: false,
11
+ value: true,
12
+ writable: false,
13
+ });
14
+ };
15
+ }
16
+ function isJsonOutputEnabled(target) {
17
+ return target[JSON_OUTPUT_ENABLED] === true;
18
+ }
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createParamDecorator = createParamDecorator;
4
+ exports.getParamBindings = getParamBindings;
5
+ const bindings = new WeakMap();
6
+ function createParamDecorator(type, getter) {
7
+ return () => (target, key, index) => {
8
+ var _a;
9
+ if (key === undefined)
10
+ throw new Error("CLI 参数装饰器只能用于命令方法");
11
+ const method = target[key];
12
+ if (typeof method !== "function")
13
+ throw new Error("CLI 参数装饰器目标必须是方法");
14
+ const existing = (_a = bindings.get(method)) !== null && _a !== void 0 ? _a : [];
15
+ bindings.set(method, [...existing, { type, index, getter }]);
16
+ };
17
+ }
18
+ function getParamBindings(method) {
19
+ var _a;
20
+ return (_a = bindings.get(method)) !== null && _a !== void 0 ? _a : [];
21
+ }
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.ArgsParams = exports.ArgsOptions = exports.CmdContext = exports.Log = exports.Credential = void 0;
13
+ const minitool_cli_auth_1 = require("@skillbuilder/minitool-cli-auth");
14
+ const minitool_core_1 = require("@skillbuilder/minitool-core");
15
+ const constants_1 = require("../constants");
16
+ const common_1 = require("./common");
17
+ exports.Credential = (0, common_1.createParamDecorator)(constants_1.ParamTypes.Credential, (ctx) => __awaiter(void 0, void 0, void 0, function* () {
18
+ const state = yield ctx.services.auth.getAuthState();
19
+ return (0, minitool_cli_auth_1.requireAuthenticatedAuthState)(state);
20
+ }));
21
+ exports.Log = (0, common_1.createParamDecorator)(constants_1.ParamTypes.Log, () => minitool_core_1.logger);
22
+ exports.CmdContext = (0, common_1.createParamDecorator)(constants_1.ParamTypes.CmdContext, (ctx) => ctx);
23
+ exports.ArgsOptions = (0, common_1.createParamDecorator)(constants_1.ParamTypes.ArgsOptions, (ctx) => ctx.options);
24
+ exports.ArgsParams = (0, common_1.createParamDecorator)(constants_1.ParamTypes.ArgsParams, (ctx) => ctx.params);
package/lib/index.js ADDED
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./main"), exports);
18
+ __exportStar(require("./bootstrap"), exports);
package/lib/main.js ADDED
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.flushCliApm = void 0;
13
+ exports.registerCommands = registerCommands;
14
+ const minitool_core_1 = require("@skillbuilder/minitool-core");
15
+ const commander_1 = require("commander");
16
+ const bootstrap_1 = require("./bootstrap");
17
+ const base_1 = require("./core/base");
18
+ require("./commands");
19
+ function registerCommands() {
20
+ return __awaiter(this, arguments, void 0, function* (services = (0, bootstrap_1.createCliServices)(), root = commander_1.program) {
21
+ (0, minitool_core_1.initCliApm)({ cliVersion: process.CLI_VERSION });
22
+ base_1.registrableCommands.forEach(({ Command }) => new Command(services).init(root));
23
+ });
24
+ }
25
+ var minitool_core_2 = require("@skillbuilder/minitool-core");
26
+ Object.defineProperty(exports, "flushCliApm", { enumerable: true, get: function () { return minitool_core_2.flushCliApm; } });
package/lib/mcp.js ADDED
@@ -0,0 +1,197 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
+ return new (P || (P = Promise))(function (resolve, reject) {
38
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
42
+ });
43
+ };
44
+ var __rest = (this && this.__rest) || function (s, e) {
45
+ var t = {};
46
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
47
+ t[p] = s[p];
48
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
49
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
50
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
51
+ t[p[i]] = s[p[i]];
52
+ }
53
+ return t;
54
+ };
55
+ Object.defineProperty(exports, "__esModule", { value: true });
56
+ exports.createMinitoolMcpServer = createMinitoolMcpServer;
57
+ exports.runMcpCommand = runMcpCommand;
58
+ const fs = __importStar(require("fs"));
59
+ const path = __importStar(require("path"));
60
+ const mcp_js_1 = require("@modelcontextprotocol/sdk/server/mcp.js");
61
+ const stdio_js_1 = require("@modelcontextprotocol/sdk/server/stdio.js");
62
+ const minitool_core_1 = require("@skillbuilder/minitool-core");
63
+ const minitool_e2e_1 = require("@skillbuilder/minitool-e2e");
64
+ const zod_1 = require("zod");
65
+ const bootstrap_1 = require("./bootstrap");
66
+ const asJson = (value) => ({
67
+ content: [{ type: "text", text: JSON.stringify(value !== null && value !== void 0 ? value : null, null, 2) }],
68
+ });
69
+ function disposeServices(services) {
70
+ void services.dispose().catch(() => {
71
+ process.stderr.write("[redminitool] runtime cleanup failed\n");
72
+ });
73
+ }
74
+ function createMinitoolMcpServer(opts = {}) {
75
+ var _a;
76
+ const server = new mcp_js_1.McpServer({
77
+ name: "redminitool",
78
+ version: require("../package.json").version,
79
+ });
80
+ const ownsServices = opts.services === undefined;
81
+ const services = (_a = opts.services) !== null && _a !== void 0 ? _a : (0, bootstrap_1.createCliServices)();
82
+ if (ownsServices) {
83
+ server.server.onclose = () => {
84
+ disposeServices(services);
85
+ };
86
+ }
87
+ server.registerTool("auth_status", {
88
+ title: "Read authentication status",
89
+ description: "Return a redacted authentication snapshot. Never returns tokens, secret ids or secret keys.",
90
+ inputSchema: {},
91
+ }, () => __awaiter(this, void 0, void 0, function* () { return asJson(yield services.auth.getAuthState()); }));
92
+ server.registerTool("creator_whoami", {
93
+ title: "Read current creator identity",
94
+ description: "Return the current Xiaohongshu MiniTool creator identity without exposing credentials.",
95
+ inputSchema: {},
96
+ }, () => __awaiter(this, void 0, void 0, function* () { return asJson(yield services.auth.whoAmI()); }));
97
+ server.registerTool("minitool_list", {
98
+ title: "List my MiniTools",
99
+ description: "List MiniTools belonging to the signed-in creator.",
100
+ inputSchema: {
101
+ source: zod_1.z.string().min(1),
102
+ pageNum: zod_1.z.number().int().min(1).default(1),
103
+ pageSize: zod_1.z.number().int().min(1).max(100).default(20),
104
+ },
105
+ }, (_a) => __awaiter(this, [_a], void 0, function* ({ source, pageNum, pageSize }) { return asJson(yield services.miniTools.list({ source, pageNum, pageSize })); }));
106
+ server.registerTool("minitool_status", {
107
+ title: "Read MiniTool status",
108
+ description: "Read version, review and publish status for a MiniTool owned by the creator.",
109
+ inputSchema: { source: zod_1.z.string().min(1), appId: zod_1.z.string().min(1) },
110
+ }, (_a) => __awaiter(this, [_a], void 0, function* ({ source, appId }) { return asJson(yield services.miniTools.getStatus({ source, appId })); }));
111
+ server.registerTool("minitool_preview", {
112
+ title: "Create a device preview",
113
+ description: "Create a device preview for uploaded package file IDs. This changes server-side preview state and requires explicit confirmation.",
114
+ inputSchema: Object.assign(Object.assign({}, minitool_core_1.miniToolPreviewSchema.shape), { confirm: zod_1.z.boolean() }),
115
+ }, (_a) => __awaiter(this, void 0, void 0, function* () {
116
+ var { confirm } = _a, input = __rest(_a, ["confirm"]);
117
+ if (!confirm)
118
+ throw new Error("生成真机预览需要 confirm=true 明确确认");
119
+ return asJson(yield services.miniTools.createPreview(input));
120
+ }));
121
+ server.registerTool("minitool_config", {
122
+ title: "Read MiniTool configuration",
123
+ description: "Read current category and authorization codes.",
124
+ inputSchema: { source: zod_1.z.string().min(1) },
125
+ }, (input) => __awaiter(this, void 0, void 0, function* () { return asJson(yield services.miniTools.getConfig(input)); }));
126
+ server.registerTool("minitool_history", {
127
+ title: "Read version history",
128
+ description: "Read MiniTool version and audit history.",
129
+ inputSchema: { source: zod_1.z.string().min(1), appId: zod_1.z.string().min(1) },
130
+ }, (input) => __awaiter(this, void 0, void 0, function* () { return asJson(yield services.miniTools.getHistory(input)); }));
131
+ server.registerTool("minitool_submit", {
132
+ title: "Submit a MiniTool for review",
133
+ description: "Submit uploaded file IDs and complete metadata for review. Requires explicit confirmation.",
134
+ inputSchema: Object.assign(Object.assign({}, minitool_core_1.miniToolReviewSchema.shape), { confirm: zod_1.z.boolean() }),
135
+ }, (_a) => __awaiter(this, void 0, void 0, function* () {
136
+ var { confirm } = _a, input = __rest(_a, ["confirm"]);
137
+ if (!confirm)
138
+ throw new Error("提交审核需要 confirm=true 明确确认");
139
+ return asJson(yield services.miniTools.submitReview(input));
140
+ }));
141
+ server.registerTool("minitool_edit", {
142
+ title: "Edit MiniTool metadata",
143
+ description: "Edit name, slogan, icon or cover. Requires explicit confirmation.",
144
+ inputSchema: Object.assign(Object.assign({}, minitool_core_1.miniToolEditSchema.shape), { confirm: zod_1.z.boolean() }),
145
+ }, (_a) => __awaiter(this, void 0, void 0, function* () {
146
+ var { confirm } = _a, input = __rest(_a, ["confirm"]);
147
+ if (!confirm)
148
+ throw new Error("编辑需要 confirm=true 明确确认");
149
+ return asJson(yield services.miniTools.edit(input));
150
+ }));
151
+ if (opts.mcpUploadRoot) {
152
+ server.registerTool("minitool_upload", {
153
+ title: "Upload a MiniTool package",
154
+ description: "Upload a ZIP or image within the user-authorized workspace. Requires explicit confirmation.",
155
+ inputSchema: {
156
+ filePath: zod_1.z.string().min(1),
157
+ type: zod_1.z.enum(["pkg", "image"]).default("pkg"),
158
+ confirm: zod_1.z.boolean(),
159
+ },
160
+ }, (_a) => __awaiter(this, [_a], void 0, function* ({ filePath, type, confirm }) {
161
+ if (!confirm)
162
+ throw new Error("上传需要 confirm=true 明确确认");
163
+ const root = fs.realpathSync(opts.mcpUploadRoot);
164
+ const target = fs.realpathSync(filePath);
165
+ const relative = path.relative(root, target);
166
+ if (!relative ||
167
+ relative === ".." ||
168
+ relative.startsWith(`..${path.sep}`) ||
169
+ path.isAbsolute(relative))
170
+ throw new Error("上传文件必须位于用户授权的工作区目录内");
171
+ return asJson(yield services.miniTools.upload({ filePath: target, type }));
172
+ }));
173
+ }
174
+ (0, minitool_e2e_1.registerMinitoolE2ETools)(server, opts);
175
+ return server;
176
+ }
177
+ function runMcpCommand() {
178
+ return __awaiter(this, arguments, void 0, function* (options = {}) {
179
+ const services = (0, bootstrap_1.createCliServices)(options);
180
+ const server = createMinitoolMcpServer({
181
+ distDir: process.env.MINITOOL_E2E_DIST_DIR,
182
+ services,
183
+ mcpUploadRoot: process.env.REDMINITOOL_MCP_UPLOAD_ROOT,
184
+ });
185
+ server.server.onclose = () => {
186
+ disposeServices(services);
187
+ };
188
+ try {
189
+ yield server.connect(new stdio_js_1.StdioServerTransport());
190
+ }
191
+ catch (error) {
192
+ yield services.dispose();
193
+ throw error;
194
+ }
195
+ process.stderr.write("[redminitool] MCP server ready on stdio\n");
196
+ });
197
+ }
package/lib/output.js ADDED
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.output = void 0;
4
+ const minitool_core_1 = require("@skillbuilder/minitool-core");
5
+ exports.output = {
6
+ helpInfo: minitool_core_1.outputHelpInfo,
7
+ };
package/lib/ui.js ADDED
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.printHeading = printHeading;
7
+ exports.printDetails = printDetails;
8
+ exports.printHint = printHint;
9
+ exports.printTable = printTable;
10
+ const chalk_1 = __importDefault(require("chalk"));
11
+ const cli_table3_1 = __importDefault(require("cli-table3"));
12
+ function printHeading(title, subtitle) {
13
+ console.log();
14
+ console.log(chalk_1.default.cyan.bold(` ✦ ${title}`));
15
+ if (subtitle)
16
+ console.log(chalk_1.default.gray(` ${subtitle}`));
17
+ console.log(chalk_1.default.gray(" ───────────────────────────────────────────────"));
18
+ }
19
+ function printDetails(rows) {
20
+ for (const [label, value] of rows) {
21
+ if (value === undefined)
22
+ continue;
23
+ console.log(` ${chalk_1.default.gray(label.padEnd(12, " "))} ${chalk_1.default.white(value)}`);
24
+ }
25
+ console.log();
26
+ }
27
+ function printHint(message) {
28
+ console.log(chalk_1.default.gray(` ↳ ${message}`));
29
+ }
30
+ function printTable(headers, rows) {
31
+ const table = new cli_table3_1.default({
32
+ head: headers.map((heading) => chalk_1.default.cyan.bold(heading)),
33
+ style: { head: [], border: ["gray"] },
34
+ wordWrap: true,
35
+ });
36
+ for (const row of rows)
37
+ table.push(row);
38
+ console.log(table.toString());
39
+ }
@@ -0,0 +1,157 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.checkAndGuideAgentProject = checkAndGuideAgentProject;
16
+ const fs_1 = __importDefault(require("fs"));
17
+ const path_1 = __importDefault(require("path"));
18
+ const chalk_1 = __importDefault(require("chalk"));
19
+ const inquirer_1 = __importDefault(require("inquirer"));
20
+ const open_1 = __importDefault(require("open"));
21
+ const OPEN_PLATFORM_URL = "https://miniapp.xiaohongshu.com/app-choose";
22
+ function isPlaceholder(value) {
23
+ if (!value || !value.trim())
24
+ return true;
25
+ const v = value.trim();
26
+ return v.startsWith("[") || v.includes("从开放平台获取");
27
+ }
28
+ function readProjectConfig(workDir) {
29
+ const configPath = path_1.default.join(workDir, "project.config.json");
30
+ if (!fs_1.default.existsSync(configPath))
31
+ return null;
32
+ try {
33
+ return JSON.parse(fs_1.default.readFileSync(configPath, "utf-8"));
34
+ }
35
+ catch (_a) {
36
+ return null;
37
+ }
38
+ }
39
+ function writeProjectConfig(workDir, updates) {
40
+ var _a;
41
+ const configPath = path_1.default.join(workDir, "project.config.json");
42
+ const existing = (_a = readProjectConfig(workDir)) !== null && _a !== void 0 ? _a : {};
43
+ const next = Object.assign(Object.assign(Object.assign(Object.assign({}, existing), { agentId: updates.agentId }), (updates.name !== undefined ? { name: updates.name } : {})), (updates.desc !== undefined ? { desc: updates.desc } : {}));
44
+ fs_1.default.writeFileSync(configPath, JSON.stringify(next, null, 2), "utf-8");
45
+ }
46
+ function openUrl(url) {
47
+ return __awaiter(this, void 0, void 0, function* () {
48
+ try {
49
+ yield (0, open_1.default)(url);
50
+ }
51
+ catch (_a) {
52
+ console.log(chalk_1.default.cyan(`请手动访问:${url}`));
53
+ }
54
+ });
55
+ }
56
+ function checkAndGuideAgentProject(workDir, services) {
57
+ return __awaiter(this, void 0, void 0, function* () {
58
+ var _a, _b, _c, _d, _e, _f;
59
+ const config = readProjectConfig(workDir);
60
+ if (!config || !("agentId" in config)) {
61
+ return undefined;
62
+ }
63
+ const rawAgentId = config.agentId;
64
+ if (isPlaceholder(rawAgentId)) {
65
+ console.log(chalk_1.default.yellow("\n⚠️ 检测到 project.config.json 中的 agentId 尚未配置,正在引导您关联智能体..."));
66
+ return yield selectAndBindAgent(workDir, services);
67
+ }
68
+ try {
69
+ const detail = yield services.getAgentInfoById(rawAgentId);
70
+ if (!detail) {
71
+ console.log(chalk_1.default.yellow(`\n⚠️ project.config.json 中的 agentId「${rawAgentId}」在当前账号下未找到,正在引导您重新关联...`));
72
+ return yield selectAndBindAgent(workDir, services);
73
+ }
74
+ const remoteName = (_a = detail.agentName) !== null && _a !== void 0 ? _a : "";
75
+ const remoteDesc = (_b = detail.description) !== null && _b !== void 0 ? _b : "";
76
+ const localName = (_c = config.name) !== null && _c !== void 0 ? _c : "";
77
+ const localDesc = (_d = config.desc) !== null && _d !== void 0 ? _d : "";
78
+ const localAgentId = (_e = config.agentId) !== null && _e !== void 0 ? _e : "";
79
+ const needsUpdate = localAgentId !== detail.agentId || localName !== remoteName || localDesc !== remoteDesc;
80
+ if (needsUpdate) {
81
+ writeProjectConfig(workDir, {
82
+ agentId: detail.agentId,
83
+ name: remoteName,
84
+ desc: remoteDesc,
85
+ });
86
+ console.log(chalk_1.default.green(`✅ 已同步 project.config.json(agentId: ${detail.agentId},name: ${remoteName || "(空)"},desc: ${remoteDesc || "(空)"})`));
87
+ }
88
+ else {
89
+ console.log(chalk_1.default.gray(`ℹ️ project.config.json 与开放平台一致,无需更新(agentId: ${detail.agentId})`));
90
+ }
91
+ return detail.agentId;
92
+ }
93
+ catch (err) {
94
+ console.warn(chalk_1.default.yellow(`\n⚠️ 校验 agentId 时出现错误(${(_f = err === null || err === void 0 ? void 0 : err.message) !== null && _f !== void 0 ? _f : String(err)}),将跳过校验直接启动。`));
95
+ return rawAgentId;
96
+ }
97
+ });
98
+ }
99
+ function selectAndBindAgent(workDir, services) {
100
+ return __awaiter(this, void 0, void 0, function* () {
101
+ var _a, _b, _c, _d;
102
+ let agentList = [];
103
+ try {
104
+ agentList = yield services.getAgentList({ pageNo: 1, pageSize: 50 });
105
+ }
106
+ catch (err) {
107
+ console.warn(chalk_1.default.yellow(`\n⚠️ 获取智能体列表失败(${(_a = err === null || err === void 0 ? void 0 : err.message) !== null && _a !== void 0 ? _a : String(err)}),将跳过关联直接启动。`));
108
+ return undefined;
109
+ }
110
+ if (!agentList || agentList.length === 0) {
111
+ console.log("");
112
+ console.log(chalk_1.default.bold.yellow("你好,您当前的账号下没有智能体,请先去开放平台创建智能体:"));
113
+ console.log(chalk_1.default.cyan(OPEN_PLATFORM_URL));
114
+ console.log("");
115
+ yield openUrl(OPEN_PLATFORM_URL);
116
+ return undefined;
117
+ }
118
+ let selectedId;
119
+ if (agentList.length === 1) {
120
+ const only = agentList[0];
121
+ selectedId = only.agentId;
122
+ console.log(chalk_1.default.green(`\n✅ 检测到您账号下只有一个智能体,已自动关联:${only.agentName}(${only.agentId})`));
123
+ }
124
+ else {
125
+ console.log("");
126
+ const { chosenId } = yield inquirer_1.default.prompt([
127
+ {
128
+ type: "list",
129
+ name: "chosenId",
130
+ message: "检测到您账号下有多个智能体,请选择要开发的智能体:",
131
+ choices: agentList.map((a) => ({
132
+ name: `${a.agentName} ${chalk_1.default.gray(`(${a.agentId})`)}`,
133
+ value: a.agentId,
134
+ })),
135
+ },
136
+ ]);
137
+ selectedId = chosenId;
138
+ }
139
+ try {
140
+ const detail = yield services.getAgentInfoById(selectedId);
141
+ if (detail) {
142
+ writeProjectConfig(workDir, {
143
+ agentId: detail.agentId,
144
+ name: (_b = detail.agentName) !== null && _b !== void 0 ? _b : "",
145
+ desc: (_c = detail.description) !== null && _c !== void 0 ? _c : "",
146
+ });
147
+ console.log(chalk_1.default.green(`✅ project.config.json 已更新(agentId: ${detail.agentId},name: ${detail.agentName || "(空)"},desc: ${detail.description || "(空)"})`));
148
+ return detail.agentId;
149
+ }
150
+ }
151
+ catch (err) {
152
+ console.warn(chalk_1.default.yellow(`\n⚠️ 获取智能体详情失败(${(_d = err === null || err === void 0 ? void 0 : err.message) !== null && _d !== void 0 ? _d : String(err)}),将直接写入 agentId。`));
153
+ }
154
+ writeProjectConfig(workDir, { agentId: selectedId });
155
+ return selectedId;
156
+ });
157
+ }