@agent-smith/cli 0.0.87 → 0.0.89
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.
- package/dist/cmd/lib/actions/cmd.d.ts +1 -1
- package/dist/cmd/lib/actions/cmd.js +31 -14
- package/dist/cmd/lib/adaptaters/cmd.js +0 -3
- package/dist/cmd/lib/options_parsers.d.ts +1 -1
- package/dist/cmd/lib/tasks/read.js +4 -0
- package/dist/cmd/lib/workflows/cmd.d.ts +1 -1
- package/dist/cmd/lib/workflows/cmd.js +11 -12
- package/dist/cmd/sys/clipboard.js +1 -10
- package/dist/cmd/sys/execute.js +5 -2
- package/dist/conf.js +2 -0
- package/package.json +3 -3
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FeatureExecutor } from "../../../interfaces.js";
|
|
2
|
-
declare function executeAction(name: string, payload:
|
|
2
|
+
declare function executeAction(name: string, payload: any, options: Record<string, any>, quiet?: boolean): Promise<any>;
|
|
3
3
|
declare function executeActionCmd(name: string, aargs: Array<any>, quiet?: boolean): Promise<any>;
|
|
4
4
|
declare function systemAction(path: string): FeatureExecutor<Array<string>, any>;
|
|
5
5
|
declare function pythonAction(path: string): FeatureExecutor<Array<string>>;
|
|
@@ -28,11 +28,7 @@ async function executeAction(name, payload, options, quiet = false) {
|
|
|
28
28
|
default:
|
|
29
29
|
throw new Error(`Action ext ${ext} not implemented`);
|
|
30
30
|
}
|
|
31
|
-
|
|
32
|
-
if (payload?.args) {
|
|
33
|
-
_pl = payload.args;
|
|
34
|
-
}
|
|
35
|
-
const res = await run(_pl, options);
|
|
31
|
+
const res = await run(payload, options);
|
|
36
32
|
if (!quiet) {
|
|
37
33
|
if (res) {
|
|
38
34
|
console.log(res);
|
|
@@ -43,12 +39,12 @@ async function executeAction(name, payload, options, quiet = false) {
|
|
|
43
39
|
}
|
|
44
40
|
async function executeActionCmd(name, aargs, quiet = false) {
|
|
45
41
|
const { args, options } = parseCommandArgs(aargs);
|
|
46
|
-
const params =
|
|
42
|
+
const params = args;
|
|
47
43
|
if (options?.clipBoardInput) {
|
|
48
|
-
params.
|
|
44
|
+
params.push(await readClipboard());
|
|
49
45
|
}
|
|
50
46
|
else if (options?.inputFile) {
|
|
51
|
-
params.
|
|
47
|
+
params.push(readPromptFile());
|
|
52
48
|
}
|
|
53
49
|
if (options?.debug) {
|
|
54
50
|
console.log("Action", name, "params", params);
|
|
@@ -57,7 +53,23 @@ async function executeActionCmd(name, aargs, quiet = false) {
|
|
|
57
53
|
}
|
|
58
54
|
function systemAction(path) {
|
|
59
55
|
const run = async (params) => {
|
|
60
|
-
let runArgs =
|
|
56
|
+
let runArgs = new Array();
|
|
57
|
+
if (!Array.isArray(params)) {
|
|
58
|
+
try {
|
|
59
|
+
if (typeof params == "string") {
|
|
60
|
+
runArgs.push(params);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
runArgs = Object.values(params);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
catch (e) {
|
|
67
|
+
throw new Error(`wrong python action args: ${e}`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
runArgs = params;
|
|
72
|
+
}
|
|
61
73
|
const actionSpec = readYmlFile(path);
|
|
62
74
|
if (!actionSpec.found) {
|
|
63
75
|
runtimeError("System action yml file", path, "not found");
|
|
@@ -73,17 +85,22 @@ function systemAction(path) {
|
|
|
73
85
|
function pythonAction(path) {
|
|
74
86
|
const run = async (params) => {
|
|
75
87
|
let runArgs = new Array();
|
|
76
|
-
if (params
|
|
77
|
-
runArgs = params.args;
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
88
|
+
if (!Array.isArray(params)) {
|
|
80
89
|
try {
|
|
81
|
-
|
|
90
|
+
if (typeof params == "string") {
|
|
91
|
+
runArgs.push(params);
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
runArgs = Object.values(params);
|
|
95
|
+
}
|
|
82
96
|
}
|
|
83
97
|
catch (e) {
|
|
84
98
|
throw new Error(`wrong python action args: ${e}`);
|
|
85
99
|
}
|
|
86
100
|
}
|
|
101
|
+
else {
|
|
102
|
+
runArgs = params;
|
|
103
|
+
}
|
|
87
104
|
const { data, error } = await runPyScript(pyShell, "python3", path, runArgs);
|
|
88
105
|
if (error) {
|
|
89
106
|
throw new Error(`python error: ${error}`);
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { getFeatureSpec } from "../../../state/features.js";
|
|
2
2
|
import { createJsAction } from "../actions/read.js";
|
|
3
3
|
async function executeAdaptater(name, params, options) {
|
|
4
|
-
if (params?.args) {
|
|
5
|
-
params = params.args;
|
|
6
|
-
}
|
|
7
4
|
const { found, path } = getFeatureSpec(name, "adaptater");
|
|
8
5
|
if (!found) {
|
|
9
6
|
throw new Error(`adaptater ${name} not found`);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { LmTaskConfig } from "../../interfaces.js";
|
|
2
2
|
declare function parseCommandArgs(args: Array<any>): {
|
|
3
|
-
args: Array<
|
|
3
|
+
args: Array<string>;
|
|
4
4
|
options: Record<string, any>;
|
|
5
5
|
};
|
|
6
6
|
declare function parseTaskConfigOptions(options: Record<string, any>): LmTaskConfig;
|
|
@@ -10,12 +10,16 @@ import { configureTaskModel, mergeInferParams } from "./conf.js";
|
|
|
10
10
|
import { openTaskSpec } from "./utils.js";
|
|
11
11
|
async function readTask(name, payload, options, agent) {
|
|
12
12
|
if (options?.debug) {
|
|
13
|
+
console.log("Task", name);
|
|
13
14
|
console.log("Payload:", payload);
|
|
14
15
|
console.log("Task options:", options);
|
|
15
16
|
}
|
|
16
17
|
const taskFileSpec = openTaskSpec(name);
|
|
17
18
|
const opts = payload?.inferParams ? { ...options, ...payload.inferParams } : options;
|
|
18
19
|
const conf = parseTaskConfigOptions(opts);
|
|
20
|
+
if (!conf?.model) {
|
|
21
|
+
throw new Error(`No model found: either specify a model in the task or use the -m flag`);
|
|
22
|
+
}
|
|
19
23
|
if (options?.debug) {
|
|
20
24
|
console.log("conf:", conf);
|
|
21
25
|
conf.debug = true;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
declare function executeWorkflow(name: string,
|
|
1
|
+
declare function executeWorkflow(name: string, args: any, options?: Record<string, any>): Promise<any>;
|
|
2
2
|
declare function executeWorkflowCmd(name: string, wargs: Array<any>): Promise<any>;
|
|
3
3
|
export { executeWorkflow, executeWorkflowCmd, };
|
|
@@ -4,7 +4,7 @@ import { parseCommandArgs } from "../options_parsers.js";
|
|
|
4
4
|
import { executeTask } from "../tasks/cmd.js";
|
|
5
5
|
import { readWorkflow } from "./read.js";
|
|
6
6
|
import colors from "ansi-colors";
|
|
7
|
-
async function executeWorkflow(name,
|
|
7
|
+
async function executeWorkflow(name, args, options = {}) {
|
|
8
8
|
const { workflow, found } = await readWorkflow(name);
|
|
9
9
|
if (!found) {
|
|
10
10
|
throw new Error(`Workflow ${name} not found`);
|
|
@@ -17,7 +17,7 @@ async function executeWorkflow(name, params, options) {
|
|
|
17
17
|
}
|
|
18
18
|
let i = 0;
|
|
19
19
|
const finalTaskIndex = stepNames.length - 1;
|
|
20
|
-
let taskRes =
|
|
20
|
+
let taskRes = { cmdArgs: args };
|
|
21
21
|
for (const [name, step] of Object.entries(workflow)) {
|
|
22
22
|
if (isDebug || isVerbose) {
|
|
23
23
|
console.log(i + 1, name, colors.dim(step.type));
|
|
@@ -26,7 +26,7 @@ async function executeWorkflow(name, params, options) {
|
|
|
26
26
|
case "task":
|
|
27
27
|
try {
|
|
28
28
|
const tr = await executeTask(name, taskRes, options, true);
|
|
29
|
-
taskRes = { ...tr, ...
|
|
29
|
+
taskRes = { ...tr, ...taskRes };
|
|
30
30
|
}
|
|
31
31
|
catch (e) {
|
|
32
32
|
throw new Error(`workflow task ${i + 1}: ${e}`);
|
|
@@ -35,11 +35,11 @@ async function executeWorkflow(name, params, options) {
|
|
|
35
35
|
case "action":
|
|
36
36
|
try {
|
|
37
37
|
const ares = await executeAction(name, taskRes, options, true);
|
|
38
|
-
if (typeof ares == "string") {
|
|
39
|
-
taskRes =
|
|
38
|
+
if (typeof ares == "string" || Array.isArray(ares)) {
|
|
39
|
+
taskRes.args = ares;
|
|
40
40
|
}
|
|
41
41
|
else {
|
|
42
|
-
taskRes = { ...ares, ...
|
|
42
|
+
taskRes = { ...ares, ...taskRes };
|
|
43
43
|
}
|
|
44
44
|
if (i == finalTaskIndex) {
|
|
45
45
|
console.log(taskRes);
|
|
@@ -51,12 +51,12 @@ async function executeWorkflow(name, params, options) {
|
|
|
51
51
|
break;
|
|
52
52
|
case "adaptater":
|
|
53
53
|
try {
|
|
54
|
-
const
|
|
55
|
-
if (typeof
|
|
56
|
-
taskRes =
|
|
54
|
+
const adres = await executeAdaptater(name, taskRes, options);
|
|
55
|
+
if (typeof adres == "string" || Array.isArray(adres)) {
|
|
56
|
+
taskRes.args = adres;
|
|
57
57
|
}
|
|
58
58
|
else {
|
|
59
|
-
taskRes = { ...
|
|
59
|
+
taskRes = { ...adres, ...taskRes };
|
|
60
60
|
}
|
|
61
61
|
if (i == finalTaskIndex) {
|
|
62
62
|
console.log(taskRes);
|
|
@@ -69,13 +69,12 @@ async function executeWorkflow(name, params, options) {
|
|
|
69
69
|
default:
|
|
70
70
|
throw new Error(`unknown task type ${step.type} in workflow ${name}`);
|
|
71
71
|
}
|
|
72
|
-
params = taskRes;
|
|
73
72
|
++i;
|
|
74
73
|
}
|
|
75
74
|
return taskRes;
|
|
76
75
|
}
|
|
77
76
|
async function executeWorkflowCmd(name, wargs) {
|
|
78
77
|
const { args, options } = parseCommandArgs(wargs);
|
|
79
|
-
return await executeWorkflow(name,
|
|
78
|
+
return await executeWorkflow(name, args, options);
|
|
80
79
|
}
|
|
81
80
|
export { executeWorkflow, executeWorkflowCmd, };
|
|
@@ -1,15 +1,6 @@
|
|
|
1
1
|
import clipboard from 'clipboardy';
|
|
2
|
-
import { execute } from "./execute.js";
|
|
3
|
-
const { platform } = process;
|
|
4
2
|
async function readClipboard() {
|
|
5
|
-
|
|
6
|
-
if (platform == "linux") {
|
|
7
|
-
res = await execute("xclip", ["-o", "-selection", "primary"]);
|
|
8
|
-
}
|
|
9
|
-
else {
|
|
10
|
-
res = await clipboard.read();
|
|
11
|
-
}
|
|
12
|
-
return res;
|
|
3
|
+
return await clipboard.read();
|
|
13
4
|
}
|
|
14
5
|
async function writeToClipboard(data) {
|
|
15
6
|
await clipboard.write(data);
|
package/dist/cmd/sys/execute.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { spawn } from "child_process";
|
|
2
|
+
import { platform } from "os";
|
|
2
3
|
async function execute(command, args = [], { onStdout = (data) => { }, onStderr = (data) => { }, onError = (data) => { }, stream = false, } = {
|
|
3
4
|
onStderr: (data) => console.log("stderr:", data),
|
|
4
5
|
onError: (err) => { if (err)
|
|
5
6
|
throw err; },
|
|
6
7
|
}) {
|
|
7
8
|
let buffer = new Array();
|
|
8
|
-
const
|
|
9
|
+
const useShell = platform() === 'win32';
|
|
10
|
+
const child = spawn(command, args, { shell: useShell });
|
|
9
11
|
child.stdout.setEncoding('utf8');
|
|
10
12
|
child.stdout.on('data', (data) => {
|
|
11
13
|
buffer.push(data);
|
|
@@ -32,7 +34,8 @@ function run(command, args = [], { onStdout = (data) => { }, onStderr = (data) =
|
|
|
32
34
|
throw err; },
|
|
33
35
|
onFinished: () => { },
|
|
34
36
|
}) {
|
|
35
|
-
|
|
37
|
+
const useShell = platform() === 'win32';
|
|
38
|
+
var child = spawn(command, args, { shell: useShell });
|
|
36
39
|
child.stdout.setEncoding('utf8');
|
|
37
40
|
child.stdout.on('data', (data) => onStdout(data));
|
|
38
41
|
child.stderr.setEncoding('utf8');
|
package/dist/conf.js
CHANGED
|
@@ -5,6 +5,7 @@ import { runtimeError } from "./cmd/lib/user_msgs.js";
|
|
|
5
5
|
import { localBackends } from "./const.js";
|
|
6
6
|
import { homedir } from 'os';
|
|
7
7
|
import { join } from 'path';
|
|
8
|
+
import { createDirectoryIfNotExists } from "./cmd/sys/dirs.js";
|
|
8
9
|
function getConfigPath(appName, filename) {
|
|
9
10
|
let confDir;
|
|
10
11
|
let dbPath;
|
|
@@ -24,6 +25,7 @@ function getConfigPath(appName, filename) {
|
|
|
24
25
|
}
|
|
25
26
|
const { confDir, dbPath } = getConfigPath("agent-smith", "config.db");
|
|
26
27
|
async function processConfPath(confPath) {
|
|
28
|
+
createDirectoryIfNotExists(confDir);
|
|
27
29
|
const { found, data } = readConf(confPath);
|
|
28
30
|
if (!found) {
|
|
29
31
|
runtimeError(`Config file ${confPath} not found`);
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@agent-smith/cli",
|
|
3
3
|
"description": "Agent Smith: terminal client for language model agents",
|
|
4
4
|
"repository": "https://github.com/synw/agent-smith",
|
|
5
|
-
"version": "0.0.
|
|
5
|
+
"version": "0.0.89",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"buildrl": "rm -rf dist/* && rollup -c",
|
|
8
8
|
"build": "rm -rf dist/* && tsc",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"@vue/reactivity": "^3.5.24",
|
|
21
21
|
"ansi-colors": "^4.1.3",
|
|
22
22
|
"better-sqlite3": "^12.4.1",
|
|
23
|
-
"clipboardy": "^5.0.
|
|
23
|
+
"clipboardy": "^5.0.1",
|
|
24
24
|
"commander": "^14.0.2",
|
|
25
25
|
"marked-terminal": "^7.3.0",
|
|
26
26
|
"modprompt": "^0.12.5",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"@types/marked-terminal": "^6.1.1",
|
|
40
40
|
"@types/node": "^24.10.1",
|
|
41
41
|
"restmix": "^0.5.0",
|
|
42
|
-
"rollup": "^4.53.
|
|
42
|
+
"rollup": "^4.53.3",
|
|
43
43
|
"ts-node": "^10.9.2",
|
|
44
44
|
"tslib": "2.8.1",
|
|
45
45
|
"typescript": "^5.9.3"
|