@midscene/shared 1.5.1 → 1.5.2-beta-20260303083655.0
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.
|
@@ -2,6 +2,7 @@ import { existsSync, writeFileSync } from "node:fs";
|
|
|
2
2
|
import { tmpdir } from "node:os";
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
import dotenv from "dotenv";
|
|
5
|
+
import { getDebug } from "../logger.mjs";
|
|
5
6
|
function _define_property(obj, key, value) {
|
|
6
7
|
if (key in obj) Object.defineProperty(obj, key, {
|
|
7
8
|
value: value,
|
|
@@ -12,6 +13,7 @@ function _define_property(obj, key, value) {
|
|
|
12
13
|
else obj[key] = value;
|
|
13
14
|
return obj;
|
|
14
15
|
}
|
|
16
|
+
const debug = getDebug('cli-runner');
|
|
15
17
|
class CLIError extends Error {
|
|
16
18
|
constructor(message, exitCode = 1){
|
|
17
19
|
super(message), _define_property(this, "exitCode", void 0), this.exitCode = exitCode;
|
|
@@ -84,6 +86,8 @@ function printHelp(scriptName, commands) {
|
|
|
84
86
|
console.log(`\nRun "${scriptName} <command> --help" for more info.`);
|
|
85
87
|
}
|
|
86
88
|
async function runToolsCLI(tools, scriptName, options) {
|
|
89
|
+
const rawArgs = options?.argv ?? process.argv.slice(2);
|
|
90
|
+
debug('CLI invoked: %s %s', scriptName, rawArgs.join(' '));
|
|
87
91
|
const envFile = join(process.cwd(), '.env');
|
|
88
92
|
if (existsSync(envFile)) dotenv.config({
|
|
89
93
|
path: envFile
|
|
@@ -93,17 +97,28 @@ async function runToolsCLI(tools, scriptName, options) {
|
|
|
93
97
|
name: removePrefix(def.name, options?.stripPrefix).toLowerCase(),
|
|
94
98
|
def
|
|
95
99
|
}));
|
|
96
|
-
const [commandName, ...restArgs] =
|
|
97
|
-
if (!commandName || '--help' === commandName || '-h' === commandName)
|
|
100
|
+
const [commandName, ...restArgs] = rawArgs;
|
|
101
|
+
if (!commandName || '--help' === commandName || '-h' === commandName) {
|
|
102
|
+
debug('showing help (no command or --help flag)');
|
|
103
|
+
printHelp(scriptName, commands);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
98
106
|
const match = commands.find((c)=>c.name.toLowerCase() === commandName.toLowerCase());
|
|
99
107
|
if (!match) {
|
|
108
|
+
debug('unknown command: %s', commandName);
|
|
100
109
|
console.error(`Unknown command: ${commandName}`);
|
|
101
110
|
printHelp(scriptName, commands);
|
|
102
111
|
throw new CLIError(`Unknown command: ${commandName}`);
|
|
103
112
|
}
|
|
104
113
|
const parsedArgs = parseCliArgs(restArgs);
|
|
105
|
-
|
|
114
|
+
debug('command: %s, args: %s', match.name, JSON.stringify(parsedArgs));
|
|
115
|
+
if (true === parsedArgs.help) {
|
|
116
|
+
debug('showing command help for: %s', match.name);
|
|
117
|
+
printCommandHelp(scriptName, match);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
106
120
|
const result = await match.def.handler(parsedArgs);
|
|
121
|
+
debug('command %s completed, isError: %s', match.name, result.isError ?? false);
|
|
107
122
|
outputResult(result);
|
|
108
123
|
await tools.destroy();
|
|
109
124
|
if (result.isError) throw new CLIError('Command failed', 1);
|
|
@@ -274,7 +274,7 @@ function generateCommonTools(getAgent) {
|
|
|
274
274
|
const agent = await getAgent();
|
|
275
275
|
if (!agent.aiAction) return createErrorResult('act is not supported by this agent');
|
|
276
276
|
const result = await agent.aiAction(prompt, {
|
|
277
|
-
deepThink:
|
|
277
|
+
deepThink: false
|
|
278
278
|
});
|
|
279
279
|
const screenshotResult = await captureScreenshotResult(agent, 'act');
|
|
280
280
|
if (result) {
|
|
@@ -44,6 +44,7 @@ const external_node_os_namespaceObject = require("node:os");
|
|
|
44
44
|
const external_node_path_namespaceObject = require("node:path");
|
|
45
45
|
const external_dotenv_namespaceObject = require("dotenv");
|
|
46
46
|
var external_dotenv_default = /*#__PURE__*/ __webpack_require__.n(external_dotenv_namespaceObject);
|
|
47
|
+
const external_logger_js_namespaceObject = require("../logger.js");
|
|
47
48
|
function _define_property(obj, key, value) {
|
|
48
49
|
if (key in obj) Object.defineProperty(obj, key, {
|
|
49
50
|
value: value,
|
|
@@ -54,6 +55,7 @@ function _define_property(obj, key, value) {
|
|
|
54
55
|
else obj[key] = value;
|
|
55
56
|
return obj;
|
|
56
57
|
}
|
|
58
|
+
const debug = (0, external_logger_js_namespaceObject.getDebug)('cli-runner');
|
|
57
59
|
class CLIError extends Error {
|
|
58
60
|
constructor(message, exitCode = 1){
|
|
59
61
|
super(message), _define_property(this, "exitCode", void 0), this.exitCode = exitCode;
|
|
@@ -126,6 +128,8 @@ function printHelp(scriptName, commands) {
|
|
|
126
128
|
console.log(`\nRun "${scriptName} <command> --help" for more info.`);
|
|
127
129
|
}
|
|
128
130
|
async function runToolsCLI(tools, scriptName, options) {
|
|
131
|
+
const rawArgs = options?.argv ?? process.argv.slice(2);
|
|
132
|
+
debug('CLI invoked: %s %s', scriptName, rawArgs.join(' '));
|
|
129
133
|
const envFile = (0, external_node_path_namespaceObject.join)(process.cwd(), '.env');
|
|
130
134
|
if ((0, external_node_fs_namespaceObject.existsSync)(envFile)) external_dotenv_default().config({
|
|
131
135
|
path: envFile
|
|
@@ -135,17 +139,28 @@ async function runToolsCLI(tools, scriptName, options) {
|
|
|
135
139
|
name: removePrefix(def.name, options?.stripPrefix).toLowerCase(),
|
|
136
140
|
def
|
|
137
141
|
}));
|
|
138
|
-
const [commandName, ...restArgs] =
|
|
139
|
-
if (!commandName || '--help' === commandName || '-h' === commandName)
|
|
142
|
+
const [commandName, ...restArgs] = rawArgs;
|
|
143
|
+
if (!commandName || '--help' === commandName || '-h' === commandName) {
|
|
144
|
+
debug('showing help (no command or --help flag)');
|
|
145
|
+
printHelp(scriptName, commands);
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
140
148
|
const match = commands.find((c)=>c.name.toLowerCase() === commandName.toLowerCase());
|
|
141
149
|
if (!match) {
|
|
150
|
+
debug('unknown command: %s', commandName);
|
|
142
151
|
console.error(`Unknown command: ${commandName}`);
|
|
143
152
|
printHelp(scriptName, commands);
|
|
144
153
|
throw new CLIError(`Unknown command: ${commandName}`);
|
|
145
154
|
}
|
|
146
155
|
const parsedArgs = parseCliArgs(restArgs);
|
|
147
|
-
|
|
156
|
+
debug('command: %s, args: %s', match.name, JSON.stringify(parsedArgs));
|
|
157
|
+
if (true === parsedArgs.help) {
|
|
158
|
+
debug('showing command help for: %s', match.name);
|
|
159
|
+
printCommandHelp(scriptName, match);
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
148
162
|
const result = await match.def.handler(parsedArgs);
|
|
163
|
+
debug('command %s completed, isError: %s', match.name, result.isError ?? false);
|
|
149
164
|
outputResult(result);
|
|
150
165
|
await tools.destroy();
|
|
151
166
|
if (result.isError) throw new CLIError('Command failed', 1);
|
|
@@ -303,7 +303,7 @@ function generateCommonTools(getAgent) {
|
|
|
303
303
|
const agent = await getAgent();
|
|
304
304
|
if (!agent.aiAction) return createErrorResult('act is not supported by this agent');
|
|
305
305
|
const result = await agent.aiAction(prompt, {
|
|
306
|
-
deepThink:
|
|
306
|
+
deepThink: false
|
|
307
307
|
});
|
|
308
308
|
const screenshotResult = await captureScreenshotResult(agent, 'act');
|
|
309
309
|
if (result) {
|
package/package.json
CHANGED
package/src/cli/cli-runner.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { existsSync, writeFileSync } from 'node:fs';
|
|
|
2
2
|
import { tmpdir } from 'node:os';
|
|
3
3
|
import { join } from 'node:path';
|
|
4
4
|
import dotenv from 'dotenv';
|
|
5
|
+
import { getDebug } from '../logger';
|
|
5
6
|
import type { BaseMidsceneTools } from '../mcp/base-tools';
|
|
6
7
|
import type {
|
|
7
8
|
ToolDefinition,
|
|
@@ -9,6 +10,8 @@ import type {
|
|
|
9
10
|
ToolResultContent,
|
|
10
11
|
} from '../mcp/types';
|
|
11
12
|
|
|
13
|
+
const debug = getDebug('cli-runner');
|
|
14
|
+
|
|
12
15
|
interface CLICommand {
|
|
13
16
|
name: string;
|
|
14
17
|
def: ToolDefinition;
|
|
@@ -137,6 +140,9 @@ export async function runToolsCLI(
|
|
|
137
140
|
scriptName: string,
|
|
138
141
|
options?: CLIRunnerOptions,
|
|
139
142
|
): Promise<void> {
|
|
143
|
+
const rawArgs = options?.argv ?? process.argv.slice(2);
|
|
144
|
+
debug('CLI invoked: %s %s', scriptName, rawArgs.join(' '));
|
|
145
|
+
|
|
140
146
|
// Load .env from cwd before any tool initialization
|
|
141
147
|
const envFile = join(process.cwd(), '.env');
|
|
142
148
|
if (existsSync(envFile)) {
|
|
@@ -150,9 +156,10 @@ export async function runToolsCLI(
|
|
|
150
156
|
def,
|
|
151
157
|
}));
|
|
152
158
|
|
|
153
|
-
const [commandName, ...restArgs] =
|
|
159
|
+
const [commandName, ...restArgs] = rawArgs;
|
|
154
160
|
|
|
155
161
|
if (!commandName || commandName === '--help' || commandName === '-h') {
|
|
162
|
+
debug('showing help (no command or --help flag)');
|
|
156
163
|
printHelp(scriptName, commands);
|
|
157
164
|
return;
|
|
158
165
|
}
|
|
@@ -161,19 +168,27 @@ export async function runToolsCLI(
|
|
|
161
168
|
(c) => c.name.toLowerCase() === commandName.toLowerCase(),
|
|
162
169
|
);
|
|
163
170
|
if (!match) {
|
|
171
|
+
debug('unknown command: %s', commandName);
|
|
164
172
|
console.error(`Unknown command: ${commandName}`);
|
|
165
173
|
printHelp(scriptName, commands);
|
|
166
174
|
throw new CLIError(`Unknown command: ${commandName}`);
|
|
167
175
|
}
|
|
168
176
|
|
|
169
177
|
const parsedArgs = parseCliArgs(restArgs);
|
|
178
|
+
debug('command: %s, args: %s', match.name, JSON.stringify(parsedArgs));
|
|
170
179
|
|
|
171
180
|
if (parsedArgs.help === true) {
|
|
181
|
+
debug('showing command help for: %s', match.name);
|
|
172
182
|
printCommandHelp(scriptName, match);
|
|
173
183
|
return;
|
|
174
184
|
}
|
|
175
185
|
|
|
176
186
|
const result = await match.def.handler(parsedArgs);
|
|
187
|
+
debug(
|
|
188
|
+
'command %s completed, isError: %s',
|
|
189
|
+
match.name,
|
|
190
|
+
result.isError ?? false,
|
|
191
|
+
);
|
|
177
192
|
outputResult(result);
|
|
178
193
|
await tools.destroy();
|
|
179
194
|
if (result.isError) {
|
|
@@ -407,7 +407,7 @@ export function generateCommonTools(
|
|
|
407
407
|
if (!agent.aiAction) {
|
|
408
408
|
return createErrorResult('act is not supported by this agent');
|
|
409
409
|
}
|
|
410
|
-
const result = await agent.aiAction(prompt, { deepThink:
|
|
410
|
+
const result = await agent.aiAction(prompt, { deepThink: false });
|
|
411
411
|
const screenshotResult = await captureScreenshotResult(agent, 'act');
|
|
412
412
|
if (result) {
|
|
413
413
|
const message =
|