@agent-smith/cli 0.0.32 → 0.0.35
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/execute_action.js +5 -1
- package/dist/cmd/lib/execute_job.js +67 -9
- package/dist/cmd/lib/utils.d.ts +5 -2
- package/dist/cmd/lib/utils.js +16 -5
- package/dist/cmd/sys/read_features.js +1 -1
- package/dist/db/schemas.js +1 -1
- package/dist/interfaces.d.ts +1 -1
- package/package.json +10 -10
|
@@ -4,7 +4,7 @@ import { readYmlAction } from "../sys/read_yml_action.js";
|
|
|
4
4
|
import { execute } from "../sys/execute.js";
|
|
5
5
|
import { runPyScript } from "../sys/run_python.js";
|
|
6
6
|
import { pyShell } from "../../state/state.js";
|
|
7
|
-
import { parseInputOptions, processOutput } from "./utils.js";
|
|
7
|
+
import { createJsAction, parseInputOptions, processOutput } from "./utils.js";
|
|
8
8
|
function systemAction(path) {
|
|
9
9
|
const action = useAgentTask({
|
|
10
10
|
id: "system_action",
|
|
@@ -43,6 +43,10 @@ async function executeActionCmd(args = [], options = {}, quiet = false) {
|
|
|
43
43
|
const { action } = await import(path);
|
|
44
44
|
act = action;
|
|
45
45
|
break;
|
|
46
|
+
case "mjs":
|
|
47
|
+
const mjsa = await import(path);
|
|
48
|
+
act = createJsAction(mjsa.action);
|
|
49
|
+
break;
|
|
46
50
|
case "yml":
|
|
47
51
|
act = systemAction(path);
|
|
48
52
|
break;
|
|
@@ -4,7 +4,7 @@ import { useAgentJob } from "@agent-smith/jobs";
|
|
|
4
4
|
import { brain, marked, taskBuilder } from '../../agent.js';
|
|
5
5
|
import { getFeatureSpec } from '../../state/features.js';
|
|
6
6
|
import { formatMode, isDebug, isVerbose } from '../../state/state.js';
|
|
7
|
-
import { initTaskConf, initTaskParams, initTaskVars, readTask } from './utils.js';
|
|
7
|
+
import { createJsAction, initTaskConf, initTaskParams, initTaskVars, parseInputOptions, readTask } from './utils.js';
|
|
8
8
|
import { pythonAction, systemAction } from './execute_action.js';
|
|
9
9
|
async function executeJobCmd(name, args = [], options = {}) {
|
|
10
10
|
const { job, found } = await _dispatchReadJob(name);
|
|
@@ -23,6 +23,7 @@ async function executeJobCmd(name, args = [], options = {}) {
|
|
|
23
23
|
const finalTaskIndex = Object.keys(job.tasks).length - 1;
|
|
24
24
|
for (const [name, task] of Object.entries(job.tasks)) {
|
|
25
25
|
if (task.type == "task") {
|
|
26
|
+
const chain = task.properties?.chain;
|
|
26
27
|
const { found, path } = getFeatureSpec(name, "task");
|
|
27
28
|
if (!found) {
|
|
28
29
|
return { ok: false, data: {}, error: `Task ${name} not found` };
|
|
@@ -32,22 +33,48 @@ async function executeJobCmd(name, args = [], options = {}) {
|
|
|
32
33
|
throw new Error(`Task ${name}, ${path} not found`);
|
|
33
34
|
}
|
|
34
35
|
const taskSpec = taskBuilder.readFromYaml(tres.ymlTask);
|
|
36
|
+
if (params.data?.history?.length > 0) {
|
|
37
|
+
const taskShots = taskSpec?.shots ?? [];
|
|
38
|
+
taskSpec.shots = [...taskShots, ...params.data.history];
|
|
39
|
+
}
|
|
35
40
|
let conf = {};
|
|
36
41
|
let vars = {};
|
|
37
42
|
if (i == 0) {
|
|
38
43
|
const vs = initTaskVars(args, taskSpec?.inferParams ? taskSpec.inferParams : {});
|
|
39
44
|
conf = vs.conf;
|
|
40
45
|
vars = vs.vars;
|
|
46
|
+
const _pr = await parseInputOptions(options);
|
|
47
|
+
if (_pr) {
|
|
48
|
+
vars.prompt = _pr;
|
|
49
|
+
}
|
|
41
50
|
}
|
|
42
51
|
else {
|
|
52
|
+
if (!params?.prompt) {
|
|
53
|
+
if (params?.text) {
|
|
54
|
+
params.prompt = params.text;
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
throw new Error(`No prompt provided for task ${name}.\Params: ${params}`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
43
60
|
const vs = initTaskParams(params, taskSpec?.inferParams ? taskSpec.inferParams : {});
|
|
44
61
|
conf = vs.conf;
|
|
45
62
|
vars = vs.vars;
|
|
46
63
|
}
|
|
64
|
+
const nextParams = {};
|
|
65
|
+
for (const [k, v] of Object.entries(vars)) {
|
|
66
|
+
if (taskSpec.variables?.required?.includes(k) || taskSpec.variables?.optional?.includes(k) || k == "prompt") {
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
;
|
|
70
|
+
nextParams[k] = v;
|
|
71
|
+
delete vars[k];
|
|
72
|
+
}
|
|
47
73
|
conf = initTaskConf(conf, taskSpec);
|
|
48
74
|
if (isDebug.value) {
|
|
49
75
|
console.log("Task conf:", conf);
|
|
50
76
|
console.log("Task vars:", vars);
|
|
77
|
+
console.log("Next params:", nextParams);
|
|
51
78
|
}
|
|
52
79
|
if (isVerbose.value || isDebug.value) {
|
|
53
80
|
conf.verbose = true;
|
|
@@ -66,7 +93,30 @@ async function executeJobCmd(name, args = [], options = {}) {
|
|
|
66
93
|
console.log(i + 1, "Running task", name);
|
|
67
94
|
}
|
|
68
95
|
try {
|
|
69
|
-
|
|
96
|
+
const invars = { ...params, ...vars };
|
|
97
|
+
try {
|
|
98
|
+
res = await job.runTask(name, invars, conf);
|
|
99
|
+
}
|
|
100
|
+
catch (e) {
|
|
101
|
+
throw new Error(`Error running task ${name}: ${e}`);
|
|
102
|
+
}
|
|
103
|
+
if (chain) {
|
|
104
|
+
const turn = {
|
|
105
|
+
user: vars["prompt"],
|
|
106
|
+
assistant: res.text
|
|
107
|
+
};
|
|
108
|
+
if (res.data?.history) {
|
|
109
|
+
res.data.history.push(turn);
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
res.data.history = [turn];
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
if (res.data?.history) {
|
|
117
|
+
res.data.history = [];
|
|
118
|
+
}
|
|
119
|
+
}
|
|
70
120
|
}
|
|
71
121
|
catch (e) {
|
|
72
122
|
throw new Error(`Error running job task ${e}`);
|
|
@@ -80,7 +130,7 @@ async function executeJobCmd(name, args = [], options = {}) {
|
|
|
80
130
|
console.log(marked.parse(res.text).trim());
|
|
81
131
|
}
|
|
82
132
|
}
|
|
83
|
-
params = res;
|
|
133
|
+
params = { ...res, ...nextParams };
|
|
84
134
|
}
|
|
85
135
|
catch (err) {
|
|
86
136
|
return { error: `Error executing job task ${name}: ${err}` };
|
|
@@ -88,21 +138,21 @@ async function executeJobCmd(name, args = [], options = {}) {
|
|
|
88
138
|
}
|
|
89
139
|
else {
|
|
90
140
|
try {
|
|
141
|
+
const _p = i == 0 ? args : params;
|
|
91
142
|
if (isDebug.value) {
|
|
92
|
-
console.log(i + 1, "Running action", name,
|
|
143
|
+
console.log(i + 1, "Running action", name, _p);
|
|
93
144
|
}
|
|
94
145
|
else if (isVerbose.value) {
|
|
95
146
|
console.log(i + 1, "Running action", name);
|
|
96
147
|
}
|
|
97
|
-
const _p = i == 0 ? args : params;
|
|
98
148
|
try {
|
|
99
149
|
res = await job.runTask(name, _p, options);
|
|
100
150
|
}
|
|
101
151
|
catch (e) {
|
|
102
152
|
throw new Error(`Error executing job action ${e}`);
|
|
103
153
|
}
|
|
104
|
-
if (res
|
|
105
|
-
return { ok: false, data: "", conf: {}, error: `Error executing action ${name}: ${res
|
|
154
|
+
if (!res.ok) {
|
|
155
|
+
return { ok: false, data: "", conf: {}, error: `Error executing action ${name}: ${res?.error}` };
|
|
106
156
|
}
|
|
107
157
|
if (i == finalTaskIndex) {
|
|
108
158
|
console.log(res.data);
|
|
@@ -161,6 +211,12 @@ async function _createJobFromSpec(spec) {
|
|
|
161
211
|
at.type = "action";
|
|
162
212
|
tasks[t.name] = at;
|
|
163
213
|
}
|
|
214
|
+
else if (ext == "mjs") {
|
|
215
|
+
const mjsa = await import(path);
|
|
216
|
+
const act = createJsAction(mjsa.action);
|
|
217
|
+
act.type = "action";
|
|
218
|
+
tasks[t.name] = act;
|
|
219
|
+
}
|
|
164
220
|
else if (ext == "yml") {
|
|
165
221
|
const _t = systemAction(path);
|
|
166
222
|
_t.type = "action";
|
|
@@ -181,8 +237,10 @@ async function _createJobFromSpec(spec) {
|
|
|
181
237
|
if (!res.found) {
|
|
182
238
|
throw new Error(`Task ${t.name}, ${path} not found`);
|
|
183
239
|
}
|
|
184
|
-
const at = taskBuilder.fromYaml(res.ymlTask);
|
|
185
|
-
|
|
240
|
+
const at = taskBuilder.fromYaml(res.ymlTask, "task");
|
|
241
|
+
if (t?.chain) {
|
|
242
|
+
at.properties = { "chain": true };
|
|
243
|
+
}
|
|
186
244
|
tasks[t.name] = at;
|
|
187
245
|
}
|
|
188
246
|
}
|
package/dist/cmd/lib/utils.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AgentTask } from "@agent-smith/jobs/dist/jobsinterfaces.js";
|
|
2
|
+
import { LmTask } from "@agent-smith/lmtask";
|
|
3
|
+
import { FeatureType } from "../../interfaces.js";
|
|
2
4
|
declare function setOptions(args: Array<string> | undefined, options: Record<string, any>): Promise<Array<string>>;
|
|
3
5
|
declare function readPromptFile(): string;
|
|
4
6
|
declare function processOutput(res: any): Promise<void>;
|
|
@@ -17,4 +19,5 @@ declare function initTaskVars(args: Array<any>, inferParams: Record<string, any>
|
|
|
17
19
|
vars: Record<string, any>;
|
|
18
20
|
};
|
|
19
21
|
declare function parseInputOptions(options: any): Promise<string | null>;
|
|
20
|
-
|
|
22
|
+
declare function createJsAction(action: CallableFunction): AgentTask<FeatureType>;
|
|
23
|
+
export { createJsAction, initTaskConf, initTaskParams, initTaskVars, parseInputOptions, processOutput, readPromptFile, readTask, readTasksDir, setOptions };
|
package/dist/cmd/lib/utils.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import { useAgentTask } from "@agent-smith/jobs";
|
|
2
|
+
import { useTemplateForModel } from "@agent-smith/tfm";
|
|
1
3
|
import { default as fs } from "fs";
|
|
2
4
|
import { default as path } from "path";
|
|
3
|
-
import { outputMode, promptfile } from "../../state/state.js";
|
|
4
|
-
import { inputMode } from "../../state/state.js";
|
|
5
|
-
import { readClipboard, writeToClipboard } from "../sys/clipboard.js";
|
|
5
|
+
import { inputMode, outputMode, promptfile } from "../../state/state.js";
|
|
6
6
|
import { modes } from "../clicmds/modes.js";
|
|
7
|
-
import {
|
|
7
|
+
import { readClipboard, writeToClipboard } from "../sys/clipboard.js";
|
|
8
8
|
const tfm = useTemplateForModel();
|
|
9
9
|
async function setOptions(args = [], options) {
|
|
10
10
|
for (const k of Object.keys(options)) {
|
|
@@ -184,4 +184,15 @@ async function parseInputOptions(options) {
|
|
|
184
184
|
}
|
|
185
185
|
return out;
|
|
186
186
|
}
|
|
187
|
-
|
|
187
|
+
function createJsAction(action) {
|
|
188
|
+
const task = useAgentTask({
|
|
189
|
+
id: "",
|
|
190
|
+
title: "",
|
|
191
|
+
run: async (args) => {
|
|
192
|
+
const res = await action(args);
|
|
193
|
+
return { ok: true, data: res };
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
return task;
|
|
197
|
+
}
|
|
198
|
+
export { createJsAction, initTaskConf, initTaskParams, initTaskVars, parseInputOptions, processOutput, readPromptFile, readTask, readTasksDir, setOptions };
|
|
@@ -52,7 +52,7 @@ function readFeaturesDir(dir) {
|
|
|
52
52
|
}
|
|
53
53
|
dirpath = path.join(dir, "actions");
|
|
54
54
|
if (fs.existsSync(dirpath)) {
|
|
55
|
-
const data = _readDir(dirpath, ["yml", ".js", ".py"]);
|
|
55
|
+
const data = _readDir(dirpath, ["yml", ".js", "mjs", ".py"]);
|
|
56
56
|
data.forEach((filename) => {
|
|
57
57
|
const parts = filename.split(".");
|
|
58
58
|
const ext = parts.pop();
|
package/dist/db/schemas.js
CHANGED
|
@@ -28,7 +28,7 @@ const actions = `CREATE TABLE IF NOT EXISTS action (
|
|
|
28
28
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
29
29
|
name TEXT UNIQUE NOT NULL,
|
|
30
30
|
path TEXT NOT NULL,
|
|
31
|
-
ext TEXT NOT NULL CHECK ( ext IN ('yml', 'js', 'py') )
|
|
31
|
+
ext TEXT NOT NULL CHECK ( ext IN ('yml', 'js', 'py', 'mjs') )
|
|
32
32
|
);`;
|
|
33
33
|
const cmds = `CREATE TABLE IF NOT EXISTS cmd (
|
|
34
34
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
package/dist/interfaces.d.ts
CHANGED
|
@@ -41,7 +41,7 @@ type OutputMode = "txt" | "clipboard";
|
|
|
41
41
|
type RunMode = "cli" | "cmd";
|
|
42
42
|
type FormatMode = "text" | "markdown";
|
|
43
43
|
type FeatureType = "task" | "job" | "action" | "cmd";
|
|
44
|
-
type ActionExtension = "js" | "py" | "yml";
|
|
44
|
+
type ActionExtension = "js" | "mjs" | "py" | "yml";
|
|
45
45
|
type TaskExtension = "yml";
|
|
46
46
|
type JobExtension = "yml";
|
|
47
47
|
type CmdExtension = "js";
|
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.35",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"buildrl": "rm -rf dist/* && rollup -c",
|
|
8
8
|
"build": "rm -rf dist/* && tsc --noCheck",
|
|
@@ -10,18 +10,18 @@
|
|
|
10
10
|
"watch": "tsc --noCheck -p . -w"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@agent-smith/brain": "^0.0.
|
|
14
|
-
"@agent-smith/jobs": "^0.0.
|
|
15
|
-
"@agent-smith/lmtask": "^0.0.
|
|
13
|
+
"@agent-smith/brain": "^0.0.38",
|
|
14
|
+
"@agent-smith/jobs": "^0.0.12",
|
|
15
|
+
"@agent-smith/lmtask": "^0.0.30",
|
|
16
16
|
"@agent-smith/tfm": "^0.1.1",
|
|
17
|
-
"@inquirer/prompts": "^7.3.
|
|
18
|
-
"@inquirer/select": "^4.0.
|
|
17
|
+
"@inquirer/prompts": "^7.3.3",
|
|
18
|
+
"@inquirer/select": "^4.0.10",
|
|
19
19
|
"@vue/reactivity": "^3.5.13",
|
|
20
20
|
"better-sqlite3": "^11.8.1",
|
|
21
21
|
"clipboardy": "^4.0.0",
|
|
22
22
|
"commander": "^13.1.0",
|
|
23
23
|
"marked-terminal": "^7.3.0",
|
|
24
|
-
"modprompt": "^0.
|
|
24
|
+
"modprompt": "^0.10.3",
|
|
25
25
|
"python-shell": "^5.0.0",
|
|
26
26
|
"yaml": "^2.7.0"
|
|
27
27
|
},
|
|
@@ -33,12 +33,12 @@
|
|
|
33
33
|
"@rollup/plugin-typescript": "^12.1.2",
|
|
34
34
|
"@types/better-sqlite3": "^7.6.12",
|
|
35
35
|
"@types/marked-terminal": "^6.1.1",
|
|
36
|
-
"@types/node": "^22.13.
|
|
36
|
+
"@types/node": "^22.13.10",
|
|
37
37
|
"restmix": "^0.5.0",
|
|
38
|
-
"rollup": "^4.
|
|
38
|
+
"rollup": "^4.35.0",
|
|
39
39
|
"ts-node": "^10.9.2",
|
|
40
40
|
"tslib": "2.8.1",
|
|
41
|
-
"typescript": "^5.
|
|
41
|
+
"typescript": "^5.8.2"
|
|
42
42
|
},
|
|
43
43
|
"type": "module",
|
|
44
44
|
"preferGlobal": true,
|