@mcphero/cli 1.1.6

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.
@@ -0,0 +1,18 @@
1
+
2
+ 
3
+ > @mcphero/cli@1.1.6 build /Users/atomic/projects/ai/mcphero/packages/cli
4
+ > tsup
5
+
6
+ CLI Building entry: src/index.ts
7
+ CLI Using tsconfig: tsconfig.json
8
+ CLI tsup v8.5.1
9
+ CLI Using tsup config: /Users/atomic/projects/ai/mcphero/packages/cli/tsup.config.ts
10
+ CLI Target: es2022
11
+ CLI Cleaning output folder
12
+ ESM Build start
13
+ ESM build/index.js 3.18 KB
14
+ ESM build/index.js.map 5.63 KB
15
+ ESM ⚡️ Build success in 8ms
16
+ DTS Build start
17
+ DTS ⚡️ Build success in 473ms
18
+ DTS build/index.d.ts 101.00 B
@@ -0,0 +1,12 @@
1
+
2
+ > @mcphero/cli@1.1.6 check /Users/atomic/projects/ai/mcphero/packages/cli
3
+ > pnpm lint && pnpm typecheck
4
+
5
+
6
+ > @mcphero/cli@1.1.6 lint /Users/atomic/projects/ai/mcphero/packages/cli
7
+ > eslint
8
+
9
+
10
+ > @mcphero/cli@1.1.6 typecheck /Users/atomic/projects/ai/mcphero/packages/cli
11
+ > tsc --noEmit
12
+
@@ -0,0 +1,26 @@
1
+
2
+ 
3
+ > @mcphero/cli@1.1.6 prepack /Users/atomic/projects/ai/mcphero/packages/cli
4
+ > pnpm clean && pnpm build
5
+
6
+
7
+ > @mcphero/cli@1.1.6 clean /Users/atomic/projects/ai/mcphero/packages/cli
8
+ > rimraf build
9
+
10
+
11
+ > @mcphero/cli@1.1.6 build /Users/atomic/projects/ai/mcphero/packages/cli
12
+ > tsup
13
+
14
+ CLI Building entry: src/index.ts
15
+ CLI Using tsconfig: tsconfig.json
16
+ CLI tsup v8.5.1
17
+ CLI Using tsup config: /Users/atomic/projects/ai/mcphero/packages/cli/tsup.config.ts
18
+ CLI Target: es2022
19
+ CLI Cleaning output folder
20
+ ESM Build start
21
+ ESM build/index.js 3.18 KB
22
+ ESM build/index.js.map 5.63 KB
23
+ ESM ⚡️ Build success in 9ms
24
+ DTS Build start
25
+ DTS ⚡️ Build success in 652ms
26
+ DTS build/index.d.ts 101.00 B
@@ -0,0 +1,5 @@
1
+ import { AdapterFactory } from '@mcphero/core';
2
+
3
+ declare const cli: AdapterFactory;
4
+
5
+ export { cli };
package/build/index.js ADDED
@@ -0,0 +1,85 @@
1
+ // src/adapter/cli.ts
2
+ import { intro, log } from "@clack/prompts";
3
+ import { unwrap } from "@mcphero/core";
4
+ import { createCLILogger } from "@mcphero/logger";
5
+ import { camelCase, kebabCase } from "change-case";
6
+ import { Command } from "commander";
7
+ import z from "zod";
8
+ function handleCLIError(error) {
9
+ if (error instanceof z.ZodError) {
10
+ log.error("Validation Error", { withGuide: false });
11
+ for (const issue of error.issues) {
12
+ log.error(`${issue.path}: ${issue.message}`);
13
+ }
14
+ } else if (error instanceof Error) {
15
+ log.error(error.message);
16
+ } else if (typeof error === "string") {
17
+ log.error(error);
18
+ } else {
19
+ log.error(JSON.stringify(error));
20
+ }
21
+ }
22
+ function parseCLIInput(action, args) {
23
+ const tmpArgs = args.slice(0, -1);
24
+ const rawInput = tmpArgs.pop();
25
+ action.args?.forEach((k, index) => {
26
+ rawInput[k] = args[index];
27
+ });
28
+ const { error, data } = action.input.safeParse(rawInput);
29
+ if (error || !data) {
30
+ handleCLIError(error);
31
+ process.exit();
32
+ }
33
+ return data;
34
+ }
35
+ var cli = () => {
36
+ return (options, baseContext) => {
37
+ const context = baseContext.fork({ adapter: "cli" });
38
+ const program = new Command().name(options.name).description(options.description).version(options.version);
39
+ return {
40
+ context,
41
+ start: async (actions) => {
42
+ for (const action of actions) {
43
+ const name = kebabCase(action.name);
44
+ const command = program.command(name).description(action.description);
45
+ const shape = action.input.shape;
46
+ const keys = Object.keys(shape);
47
+ for (const key of keys) {
48
+ const [type, { defaultValue }] = unwrap(shape[key]);
49
+ const description = type.description;
50
+ const isArgument = action.args?.includes(key);
51
+ if (isArgument) {
52
+ command.argument(`[${camelCase(key)}]`, description, defaultValue);
53
+ } else if (type instanceof z.ZodBoolean) {
54
+ command.option(`--${kebabCase(key)}`, description, defaultValue);
55
+ command.option(`--no-${kebabCase(key)}`);
56
+ } else if (type instanceof z.ZodNumber) {
57
+ command.option(`--${kebabCase(key)} <number>`, description, defaultValue);
58
+ } else if (type instanceof z.ZodString || type instanceof z.ZodEnum) {
59
+ command.option(`--${kebabCase(key)} <string>`, description, defaultValue);
60
+ } else if (type instanceof z.ZodObject || type instanceof z.ZodRecord || type instanceof z.ZodArray) {
61
+ command.option(`--${kebabCase(key)} <json>`, description ?? "", JSON.parse, defaultValue);
62
+ } else {
63
+ throw new Error(`Invalid zod type: ${type.def.type}`);
64
+ }
65
+ }
66
+ command.action((...args) => {
67
+ const logger = createCLILogger();
68
+ const input = parseCLIInput(action, args);
69
+ intro(`${options.name} - ${action.name}`);
70
+ action.run(input, context.fork({ logger, command })).then((result) => {
71
+ logger.info(JSON.stringify(result, null, 2));
72
+ }).catch(handleCLIError);
73
+ });
74
+ }
75
+ program.parse();
76
+ },
77
+ stop: async () => {
78
+ }
79
+ };
80
+ };
81
+ };
82
+ export {
83
+ cli
84
+ };
85
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/adapter/cli.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { intro, log } from '@clack/prompts'\nimport { Action, AdapterFactory, unwrap } from '@mcphero/core'\nimport { createCLILogger } from '@mcphero/logger'\nimport { camelCase, kebabCase } from 'change-case'\nimport { Command } from 'commander'\nimport z from 'zod'\n\nfunction handleCLIError(error: unknown) {\n if (error instanceof z.ZodError) {\n log.error('Validation Error', { withGuide: false })\n for (const issue of error.issues) {\n log.error(`${issue.path}: ${issue.message}`)\n }\n } else if (error instanceof Error) {\n log.error(error.message)\n } else if (typeof error === 'string') {\n log.error(error)\n } else {\n log.error(JSON.stringify(error))\n }\n}\n\nfunction parseCLIInput(action: Action, args: any[]) {\n const tmpArgs = args.slice(0, -1)\n const rawInput = tmpArgs.pop()\n action.args?.forEach((k, index) => { rawInput[k] = args[index] })\n const { error, data } = action.input.safeParse(rawInput)\n if (error || !data) {\n handleCLIError(error)\n process.exit()\n }\n\n return data\n}\n\nexport const cli: AdapterFactory = () => {\n return (options, baseContext) => {\n const context = baseContext.fork({ adapter: 'cli' })\n const program = new Command()\n .name(options.name)\n .description(options.description)\n .version(options.version)\n\n return {\n context,\n start: async (actions) => {\n for (const action of actions) {\n const name = kebabCase(action.name)\n const command = program.command(name).description(action.description)\n const shape = action.input.shape\n const keys = Object.keys(shape)\n for (const key of keys) {\n const [type, { defaultValue }] = unwrap(shape[key])\n const description = type.description\n const isArgument = action.args?.includes(key)\n if (isArgument) {\n command.argument(`[${camelCase(key)}]`, description, defaultValue)\n } else if (type instanceof z.ZodBoolean) {\n command.option(`--${kebabCase(key)}`, description, defaultValue)\n command.option(`--no-${kebabCase(key)}`)\n } else if (type instanceof z.ZodNumber) {\n command.option(`--${kebabCase(key)} <number>`, description, defaultValue)\n } else if (type instanceof z.ZodString || type instanceof z.ZodEnum) {\n command.option(`--${kebabCase(key)} <string>`, description, defaultValue)\n } else if (type instanceof z.ZodObject || type instanceof z.ZodRecord || type instanceof z.ZodArray) {\n command.option(`--${kebabCase(key)} <json>`, description ?? '', JSON.parse, defaultValue)\n } else {\n throw new Error(`Invalid zod type: ${type.def.type}`)\n }\n }\n command.action((...args) => {\n const logger = createCLILogger()\n const input = parseCLIInput(action, args)\n intro(`${options.name} - ${action.name}`)\n action.run(input, context.fork({ logger, command })).then((result) => {\n logger.info(JSON.stringify(result, null, 2))\n }).catch(handleCLIError)\n })\n }\n program.parse()\n },\n stop: async () => { }\n }\n }\n}\n"],"mappings":";AACA,SAAS,OAAO,WAAW;AAC3B,SAAiC,cAAc;AAC/C,SAAS,uBAAuB;AAChC,SAAS,WAAW,iBAAiB;AACrC,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AC,CAAC;AAAA,YAC7C,CAAC,EAAE,MAAM,cAAc;AAAA,UACzB,CAAC;AAAA,QACH;AACA,gBAAQ,MAAM;AAAA,MAChB;AAAA,MACA,MAAM,YAAY;AAAA,MAAE;AAAA,IACtB;AAAA,EACF;AACF;","names":[]}
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@mcphero/cli",
3
+ "version": "1.1.6",
4
+ "description": "MCP Hero CLI Adapter",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+ssh://git@github.com/atomicbi/mcphero.git",
8
+ "directory": "packages/cli"
9
+ },
10
+ "type": "module",
11
+ "main": "build/index.js",
12
+ "types": "build/index.d.ts",
13
+ "dependencies": {
14
+ "@clack/prompts": "^1.0.1",
15
+ "change-case": "^5.4.4",
16
+ "commander": "^13.1.0",
17
+ "zod": "^4.3.6",
18
+ "@mcphero/core": "1.1.6",
19
+ "@mcphero/logger": "1.1.6"
20
+ },
21
+ "devDependencies": {
22
+ "@eslint/js": "^10.0.1",
23
+ "@stylistic/eslint-plugin": "^5.10.0",
24
+ "@types/node": "^22.0.0",
25
+ "rimraf": "^6.1.3",
26
+ "tsup": "^8.5.1",
27
+ "tsx": "^4.21.0",
28
+ "typescript": "^5.9.3",
29
+ "typescript-eslint": "^8.56.1"
30
+ },
31
+ "scripts": {
32
+ "clean": "rimraf build",
33
+ "build": "tsup",
34
+ "watch": "tsup --watch",
35
+ "typecheck": "tsc --noEmit",
36
+ "lint": "eslint",
37
+ "check": "pnpm lint && pnpm typecheck"
38
+ }
39
+ }