@agent-smith/cli 0.0.103 → 0.0.104
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/clicmds/cache.js +2 -2
- package/dist/cmd/clicmds/cmds.js +3 -8
- package/dist/cmd/lib/tasks/cmd.js +1 -1
- package/dist/cmd/lib/workflows/cmd.js +55 -4
- package/dist/cmd/lib/workflows/read.js +5 -92
- package/dist/interfaces.d.ts +0 -1
- package/dist/state/auto/usercmds.d.ts +4 -1
- package/dist/state/auto/usercmds.js +3 -9
- package/package.json +1 -1
|
@@ -15,8 +15,8 @@ function createCacheFileContent(cmdFeats) {
|
|
|
15
15
|
++i;
|
|
16
16
|
});
|
|
17
17
|
const finalImports = imports.join("\n");
|
|
18
|
-
const cmds = `const cmds = [ ${cmdNames.join(", ")} ]
|
|
19
|
-
const end = "export { cmds }";
|
|
18
|
+
const cmds = `const cmds = [ ${cmdNames.join(", ")} ];\nconst isCacheReady = true;`;
|
|
19
|
+
const end = "export { isCacheReady, cmds }";
|
|
20
20
|
return `${finalImports}\n\n${cmds}\n\n${end}`;
|
|
21
21
|
}
|
|
22
22
|
function ensureUserCmdsCacheFileExists(cacheFilePath) {
|
package/dist/cmd/clicmds/cmds.js
CHANGED
|
@@ -1,29 +1,24 @@
|
|
|
1
1
|
import colors from "ansi-colors";
|
|
2
2
|
import path from "path";
|
|
3
|
-
import { pathToFileURL } from 'url';
|
|
4
3
|
import YAML from 'yaml';
|
|
5
4
|
import { cacheFilePath, dbPath } from "../../conf.js";
|
|
6
5
|
import { readFeaturePaths, readFeaturesType, readTaskSetting } from "../../db/read.js";
|
|
7
6
|
import { cleanupFeaturePaths, deleteTaskSetting, updateAliases, updateFeatures, upsertTaskSettings } from "../../db/write.js";
|
|
7
|
+
import { isCacheReady, cmds } from "../../state/auto/usercmds.js";
|
|
8
8
|
import { getFeatureSpec, readFeaturesDirs } from "../../state/features.js";
|
|
9
9
|
import { readPluginsPaths } from "../../state/plugins.js";
|
|
10
10
|
import { runMode } from "../../state/state.js";
|
|
11
11
|
import { initTaskSettings, isTaskSettingsInitialized, tasksSettings } from '../../state/tasks.js';
|
|
12
|
-
import { cmds } from "../../state/auto/usercmds.js";
|
|
13
12
|
import { deleteFileIfExists } from "../sys/delete_file.js";
|
|
14
13
|
import { readCmd } from "../sys/read_cmds.js";
|
|
15
14
|
import { readTask } from "../sys/read_task.js";
|
|
16
15
|
import { updateUserCmdsCache } from './cache.js';
|
|
17
16
|
async function initUserCmds(cmdFeats) {
|
|
18
17
|
const features = Object.values(cmdFeats);
|
|
19
|
-
if (features.length == 0) {
|
|
20
|
-
return [];
|
|
21
|
-
}
|
|
22
18
|
let endCmds = cmds;
|
|
23
|
-
if (
|
|
19
|
+
if (!isCacheReady) {
|
|
24
20
|
updateUserCmdsCache(cacheFilePath, features);
|
|
25
|
-
const
|
|
26
|
-
const usrCmds = new Array();
|
|
21
|
+
const usrCmds = [];
|
|
27
22
|
for (const feat of features) {
|
|
28
23
|
const cmdPath = path.join(feat.path, feat.name + "." + feat.ext);
|
|
29
24
|
const c = await readCmd(feat.name, cmdPath);
|
|
@@ -5,6 +5,9 @@ import { executeTask } from "../tasks/cmd.js";
|
|
|
5
5
|
import { getTaskPrompt } from "../tasks/utils.js";
|
|
6
6
|
import { readWorkflow } from "./read.js";
|
|
7
7
|
import colors from "ansi-colors";
|
|
8
|
+
import { getFeatureSpec } from "../../../state/features.js";
|
|
9
|
+
import { pathToFileURL } from "node:url";
|
|
10
|
+
import { runtimeError } from "../user_msgs.js";
|
|
8
11
|
async function executeWorkflow(wname, args, options = {}) {
|
|
9
12
|
const { workflow, found } = await readWorkflow(wname);
|
|
10
13
|
if (!found) {
|
|
@@ -27,7 +30,7 @@ async function executeWorkflow(wname, args, options = {}) {
|
|
|
27
30
|
switch (step.type) {
|
|
28
31
|
case "task":
|
|
29
32
|
try {
|
|
30
|
-
let tdata =
|
|
33
|
+
let tdata = taskRes;
|
|
31
34
|
if (i == 0) {
|
|
32
35
|
tdata.prompt = await getTaskPrompt(step.name, taskRes.cmdArgs, options);
|
|
33
36
|
}
|
|
@@ -37,7 +40,6 @@ async function executeWorkflow(wname, args, options = {}) {
|
|
|
37
40
|
tdata.prompt = taskRes.answer.text;
|
|
38
41
|
}
|
|
39
42
|
}
|
|
40
|
-
tdata = taskRes;
|
|
41
43
|
}
|
|
42
44
|
if (!tdata?.prompt) {
|
|
43
45
|
throw new Error(`Workflow ${wname} step ${i + 1}: provide a prompt for the task ${step.name}`);
|
|
@@ -49,6 +51,31 @@ async function executeWorkflow(wname, args, options = {}) {
|
|
|
49
51
|
throw new Error(`workflow task ${i + 1}: ${e}`);
|
|
50
52
|
}
|
|
51
53
|
break;
|
|
54
|
+
case "agent":
|
|
55
|
+
try {
|
|
56
|
+
let tdata = taskRes;
|
|
57
|
+
if (i == 0) {
|
|
58
|
+
tdata.prompt = await getTaskPrompt(step.name, taskRes.cmdArgs, options);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
if (prevStepType) {
|
|
62
|
+
if (prevStepType == "task") {
|
|
63
|
+
tdata.prompt = taskRes.answer.text;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if (!tdata?.prompt) {
|
|
68
|
+
throw new Error(`Workflow ${wname} step ${i + 1}: provide a prompt for the task ${step.name}`);
|
|
69
|
+
}
|
|
70
|
+
options.isAgent = true;
|
|
71
|
+
const tr = await executeTask(step.name, tdata, options);
|
|
72
|
+
options.isAgent = false;
|
|
73
|
+
taskRes = { ...tr, ...taskRes };
|
|
74
|
+
}
|
|
75
|
+
catch (e) {
|
|
76
|
+
throw new Error(`workflow task ${i + 1}: ${e}`);
|
|
77
|
+
}
|
|
78
|
+
break;
|
|
52
79
|
case "action":
|
|
53
80
|
try {
|
|
54
81
|
const actArgs = i == 0 ? taskRes.cmdArgs : taskRes;
|
|
@@ -75,7 +102,7 @@ async function executeWorkflow(wname, args, options = {}) {
|
|
|
75
102
|
taskRes.args = adres;
|
|
76
103
|
}
|
|
77
104
|
else {
|
|
78
|
-
taskRes = { ...adres
|
|
105
|
+
taskRes = { ...adres };
|
|
79
106
|
}
|
|
80
107
|
if (i == finalTaskIndex) {
|
|
81
108
|
console.log(taskRes);
|
|
@@ -85,8 +112,32 @@ async function executeWorkflow(wname, args, options = {}) {
|
|
|
85
112
|
throw new Error(`workflow adaptater ${i + 1}: ${e}`);
|
|
86
113
|
}
|
|
87
114
|
break;
|
|
115
|
+
case "cmd":
|
|
116
|
+
try {
|
|
117
|
+
const { found, path } = getFeatureSpec(step.name, "cmd");
|
|
118
|
+
if (!found) {
|
|
119
|
+
throw new Error(`Command ${step.name} not found`);
|
|
120
|
+
}
|
|
121
|
+
const url = pathToFileURL(path).href;
|
|
122
|
+
const jsa = await import(url);
|
|
123
|
+
if (!jsa?.runCmd) {
|
|
124
|
+
runtimeError(`workflow ${wname}: can not import the runCmd function from step ${i} for command ${step.name}: please add a runCmd function export`);
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
const cres = await jsa.runCmd(args, options);
|
|
128
|
+
if (typeof cres == "string" || Array.isArray(cres)) {
|
|
129
|
+
taskRes.args = cres;
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
taskRes = { ...cres, ...taskRes };
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
catch (e) {
|
|
136
|
+
throw new Error(`workflow command ${i + 1}: ${e}`);
|
|
137
|
+
}
|
|
138
|
+
break;
|
|
88
139
|
default:
|
|
89
|
-
throw new Error(`unknown
|
|
140
|
+
throw new Error(`unknown workflow step type ${step.type} in workflow ${wname}`);
|
|
90
141
|
}
|
|
91
142
|
prevStepType = step.type;
|
|
92
143
|
++i;
|
|
@@ -1,104 +1,17 @@
|
|
|
1
|
-
import { Agent } from '@agent-smith/agent';
|
|
2
|
-
import { Task } from '@agent-smith/task';
|
|
3
1
|
import { default as fs } from "fs";
|
|
4
2
|
import YAML from 'yaml';
|
|
5
|
-
import { backend } from '../../../state/backends.js';
|
|
6
3
|
import { getFeatureSpec } from '../../../state/features.js';
|
|
7
|
-
import { readTask } from "../../sys/read_task.js";
|
|
8
|
-
import { pythonAction, systemAction } from '../actions/cmd.js';
|
|
9
|
-
import { createJsAction } from '../actions/read.js';
|
|
10
|
-
import { pathToFileURL } from 'url';
|
|
11
4
|
async function _createWorkflowFromSpec(spec) {
|
|
12
5
|
const steps = [];
|
|
13
|
-
let i = 1;
|
|
14
6
|
for (const step of spec.steps) {
|
|
15
7
|
const type = Object.keys(step)[0];
|
|
16
8
|
const sval = step[type];
|
|
17
9
|
const name = sval;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
switch (ext) {
|
|
24
|
-
case "js":
|
|
25
|
-
const url = pathToFileURL(path).href;
|
|
26
|
-
const { action } = await import(url);
|
|
27
|
-
const at = action;
|
|
28
|
-
const wf = {
|
|
29
|
-
name: name,
|
|
30
|
-
type: "action",
|
|
31
|
-
run: at,
|
|
32
|
-
};
|
|
33
|
-
steps.push(wf);
|
|
34
|
-
break;
|
|
35
|
-
case "mjs":
|
|
36
|
-
const url2 = pathToFileURL(path).href;
|
|
37
|
-
const mjsa = await import(url2);
|
|
38
|
-
const act = createJsAction(mjsa.action);
|
|
39
|
-
const wf2 = {
|
|
40
|
-
name: name,
|
|
41
|
-
type: "action",
|
|
42
|
-
run: act,
|
|
43
|
-
};
|
|
44
|
-
steps.push(wf2);
|
|
45
|
-
break;
|
|
46
|
-
case "yml":
|
|
47
|
-
const _t1 = systemAction(path);
|
|
48
|
-
const wf3 = {
|
|
49
|
-
name: name,
|
|
50
|
-
type: "action",
|
|
51
|
-
run: _t1,
|
|
52
|
-
};
|
|
53
|
-
steps.push(wf3);
|
|
54
|
-
break;
|
|
55
|
-
case "py":
|
|
56
|
-
const _t = pythonAction(path);
|
|
57
|
-
const wf4 = {
|
|
58
|
-
name: name,
|
|
59
|
-
type: "action",
|
|
60
|
-
run: _t,
|
|
61
|
-
};
|
|
62
|
-
steps.push(wf4);
|
|
63
|
-
break;
|
|
64
|
-
default:
|
|
65
|
-
throw new Error(`Unknown feature extension ${ext}`);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
else if (type == "adaptater") {
|
|
69
|
-
const { found, path } = getFeatureSpec(name, "adaptater");
|
|
70
|
-
if (!found) {
|
|
71
|
-
throw new Error(`Adaptater ${name} not found`);
|
|
72
|
-
}
|
|
73
|
-
const url = pathToFileURL(path).href;
|
|
74
|
-
const jsa = await import(url);
|
|
75
|
-
const act = createJsAction(jsa.action);
|
|
76
|
-
const wf = {
|
|
77
|
-
name: name,
|
|
78
|
-
type: "adaptater",
|
|
79
|
-
run: act,
|
|
80
|
-
};
|
|
81
|
-
steps.push(wf);
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
const { found, path } = getFeatureSpec(name, "task");
|
|
85
|
-
if (!found) {
|
|
86
|
-
throw new Error(`Task ${name} not found`);
|
|
87
|
-
}
|
|
88
|
-
const res = readTask(path);
|
|
89
|
-
if (!res.found) {
|
|
90
|
-
throw new Error(`Unable to read task ${name} ${path}`);
|
|
91
|
-
}
|
|
92
|
-
const agent = new Agent(backend.value);
|
|
93
|
-
const tsk = Task.fromYaml(agent, res.ymlTask);
|
|
94
|
-
const wf = {
|
|
95
|
-
name: name,
|
|
96
|
-
type: "task",
|
|
97
|
-
run: tsk.run,
|
|
98
|
-
};
|
|
99
|
-
steps.push(wf);
|
|
100
|
-
}
|
|
101
|
-
++i;
|
|
10
|
+
const wf = {
|
|
11
|
+
name: name,
|
|
12
|
+
type: type == "command" ? "cmd" : type,
|
|
13
|
+
};
|
|
14
|
+
steps.push(wf);
|
|
102
15
|
}
|
|
103
16
|
return steps;
|
|
104
17
|
}
|
package/dist/interfaces.d.ts
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import { cmd as c4 } from "file:///home/ggg/dev/js/snowind-astro/features/cmds/design-component.js";
|
|
5
|
-
import { cmd as c5 } from "file:///home/ggg/dev/js/docdundee/package/features/dist/cmds/tsdoccmd.js";
|
|
6
|
-
|
|
7
|
-
const cmds = [ c1, c2, c3, c4, c5 ]
|
|
8
|
-
|
|
9
|
-
export { cmds }
|
|
1
|
+
const cmds = new Array();
|
|
2
|
+
const isCacheReady = false;
|
|
3
|
+
export { cmds, isCacheReady, };
|
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.104",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"buildrl": "rm -rf dist/* && rollup -c",
|
|
8
8
|
"build": "rm -rf dist/* && tsc",
|