@agent-smith/cli 0.0.31 → 0.0.32

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.
@@ -1,4 +1,4 @@
1
- import { formatMode, inputMode, isChatMode, isDebug, outputMode, runMode } from "../../state/state.js";
1
+ import { formatMode, inputMode, isChatMode, isDebug, isVerbose, outputMode, runMode } from "../../state/state.js";
2
2
  const modes = {
3
3
  "-d": {
4
4
  cmd: async () => {
@@ -9,6 +9,15 @@ const modes = {
9
9
  },
10
10
  description: "use debug mode",
11
11
  },
12
+ "-v": {
13
+ cmd: async () => {
14
+ isVerbose.value = true;
15
+ if (runMode.value == "cli") {
16
+ console.log("Verbose mode is on");
17
+ }
18
+ },
19
+ description: "use verbose mode",
20
+ },
12
21
  "-c": {
13
22
  cmd: async () => {
14
23
  isChatMode.value = true;
@@ -1,2 +1,6 @@
1
+ import { AgentTask } from "@agent-smith/jobs";
2
+ import { FeatureType } from "../../interfaces.js";
3
+ declare function systemAction(path: string): AgentTask<FeatureType>;
4
+ declare function pythonAction(path: string): AgentTask<FeatureType>;
1
5
  declare function executeActionCmd(args?: Array<string>, options?: any, quiet?: boolean): Promise<any>;
2
- export { executeActionCmd };
6
+ export { executeActionCmd, systemAction, pythonAction };
@@ -5,25 +5,28 @@ import { execute } from "../sys/execute.js";
5
5
  import { runPyScript } from "../sys/run_python.js";
6
6
  import { pyShell } from "../../state/state.js";
7
7
  import { parseInputOptions, processOutput } from "./utils.js";
8
- function _systemAction(path) {
8
+ function systemAction(path) {
9
9
  const action = useAgentTask({
10
10
  id: "system_action",
11
11
  title: "",
12
12
  run: async (args) => {
13
13
  const actionSpec = readYmlAction(path);
14
+ if (!actionSpec.data?.args) {
15
+ actionSpec.data.args = [];
16
+ }
14
17
  const out = await execute(actionSpec.data.cmd, [...actionSpec.data.args, ...args]);
15
- return { data: out, error: "", ok: true };
18
+ return { data: out.trim(), error: "", ok: true };
16
19
  }
17
20
  });
18
21
  return action;
19
22
  }
20
- function _pythonAction(path) {
23
+ function pythonAction(path) {
21
24
  const action = useAgentTask({
22
25
  id: "python_action",
23
26
  title: "",
24
27
  run: async (args) => {
25
28
  const out = await runPyScript(pyShell, "python3", path, args);
26
- return { data: out[0], error: "", ok: true };
29
+ return { data: out.join("\n"), error: "", ok: true };
27
30
  }
28
31
  });
29
32
  return action;
@@ -41,10 +44,10 @@ async function executeActionCmd(args = [], options = {}, quiet = false) {
41
44
  act = action;
42
45
  break;
43
46
  case "yml":
44
- act = _systemAction(path);
47
+ act = systemAction(path);
45
48
  break;
46
49
  case "py":
47
- act = _pythonAction(path);
50
+ act = pythonAction(path);
48
51
  break;
49
52
  default:
50
53
  throw new Error(`Action ext ${ext} not implemented`);
@@ -60,4 +63,4 @@ async function executeActionCmd(args = [], options = {}, quiet = false) {
60
63
  await processOutput(res);
61
64
  return { ok: true, data: res.data, error: "" };
62
65
  }
63
- export { executeActionCmd };
66
+ export { executeActionCmd, systemAction, pythonAction };
@@ -3,10 +3,14 @@ import { default as fs } from "fs";
3
3
  import { useAgentJob } from "@agent-smith/jobs";
4
4
  import { brain, marked, taskBuilder } from '../../agent.js';
5
5
  import { getFeatureSpec } from '../../state/features.js';
6
- import { formatMode, isDebug } from '../../state/state.js';
7
- import { initTaskConf, initTaskVars, readTask } from './utils.js';
6
+ import { formatMode, isDebug, isVerbose } from '../../state/state.js';
7
+ import { initTaskConf, initTaskParams, initTaskVars, readTask } from './utils.js';
8
+ import { pythonAction, systemAction } from './execute_action.js';
8
9
  async function executeJobCmd(name, args = [], options = {}) {
9
10
  const { job, found } = await _dispatchReadJob(name);
11
+ if (isDebug.value || isVerbose.value) {
12
+ console.log("Running job", name, Object.keys(job.tasks).length, "tasks");
13
+ }
10
14
  if (!found) {
11
15
  console.log(`Job ${name} not found`);
12
16
  return { error: `Job ${name} not found` };
@@ -16,6 +20,7 @@ async function executeJobCmd(name, args = [], options = {}) {
16
20
  let params = {};
17
21
  brain.backendsForModelsInfo();
18
22
  let i = 0;
23
+ const finalTaskIndex = Object.keys(job.tasks).length - 1;
19
24
  for (const [name, task] of Object.entries(job.tasks)) {
20
25
  if (task.type == "task") {
21
26
  const { found, path } = getFeatureSpec(name, "task");
@@ -27,12 +32,26 @@ async function executeJobCmd(name, args = [], options = {}) {
27
32
  throw new Error(`Task ${name}, ${path} not found`);
28
33
  }
29
34
  const taskSpec = taskBuilder.readFromYaml(tres.ymlTask);
30
- let { conf, vars } = initTaskVars(args, taskSpec?.inferParams ? taskSpec.inferParams : {});
35
+ let conf = {};
36
+ let vars = {};
37
+ if (i == 0) {
38
+ const vs = initTaskVars(args, taskSpec?.inferParams ? taskSpec.inferParams : {});
39
+ conf = vs.conf;
40
+ vars = vs.vars;
41
+ }
42
+ else {
43
+ const vs = initTaskParams(params, taskSpec?.inferParams ? taskSpec.inferParams : {});
44
+ conf = vs.conf;
45
+ vars = vs.vars;
46
+ }
31
47
  conf = initTaskConf(conf, taskSpec);
32
48
  if (isDebug.value) {
33
49
  console.log("Task conf:", conf);
34
50
  console.log("Task vars:", vars);
35
51
  }
52
+ if (isVerbose.value || isDebug.value) {
53
+ conf.verbose = true;
54
+ }
36
55
  const ex = brain.getOrCreateExpertForModel(conf.model.name, conf.model.template);
37
56
  if (!ex) {
38
57
  throw new Error("No expert found for model " + conf.model.name);
@@ -43,10 +62,18 @@ async function executeJobCmd(name, args = [], options = {}) {
43
62
  });
44
63
  conf["expert"] = ex;
45
64
  try {
46
- if (isDebug) {
47
- console.log("Running", name);
65
+ if (isDebug.value || isVerbose.value) {
66
+ console.log(i + 1, "Running task", name);
67
+ }
68
+ try {
69
+ res = await job.runTask(name, { ...params, ...vars }, conf);
70
+ }
71
+ catch (e) {
72
+ throw new Error(`Error running job task ${e}`);
73
+ }
74
+ if (res?.error) {
75
+ return { ok: false, data: "", conf: conf, error: `Error executing job task ${name}: ${res.error}` };
48
76
  }
49
- res = await job.runTask(name, { ...params, ...vars }, conf);
50
77
  if ("text" in res) {
51
78
  if (formatMode.value == "markdown") {
52
79
  console.log("\n\n------------------\n");
@@ -56,16 +83,32 @@ async function executeJobCmd(name, args = [], options = {}) {
56
83
  params = res;
57
84
  }
58
85
  catch (err) {
59
- return { error: `Error executing (${task.type}) task ${name}: ${err}` };
86
+ return { error: `Error executing job task ${name}: ${err}` };
60
87
  }
61
88
  }
62
89
  else {
63
90
  try {
64
- if (i == 0) {
65
- res = await job.runTask(name, args, options);
91
+ if (isDebug.value) {
92
+ console.log(i + 1, "Running action", name, args);
93
+ }
94
+ else if (isVerbose.value) {
95
+ console.log(i + 1, "Running action", name);
96
+ }
97
+ const _p = i == 0 ? args : params;
98
+ try {
99
+ res = await job.runTask(name, _p, options);
100
+ }
101
+ catch (e) {
102
+ throw new Error(`Error executing job action ${e}`);
103
+ }
104
+ if (res?.error) {
105
+ return { ok: false, data: "", conf: {}, error: `Error executing action ${name}: ${res.error}` };
106
+ }
107
+ if (i == finalTaskIndex) {
108
+ console.log(res.data);
66
109
  }
67
110
  else {
68
- res = await job.runTask(name, params, options);
111
+ params = res.data;
69
112
  }
70
113
  params = res.data;
71
114
  }
@@ -108,14 +151,26 @@ async function _createJobFromSpec(spec) {
108
151
  const tasks = {};
109
152
  for (const t of spec.tasks) {
110
153
  if (t.type == "action") {
111
- const { found, path } = getFeatureSpec(t.name, "action");
154
+ const { found, path, ext } = getFeatureSpec(t.name, "action");
112
155
  if (!found) {
113
156
  return { found: false, job: {} };
114
157
  }
115
- const { action } = await import(path);
116
- const at = action;
117
- at.type = "action";
118
- tasks[t.name] = at;
158
+ if (ext == "js") {
159
+ const { action } = await import(path);
160
+ const at = action;
161
+ at.type = "action";
162
+ tasks[t.name] = at;
163
+ }
164
+ else if (ext == "yml") {
165
+ const _t = systemAction(path);
166
+ _t.type = "action";
167
+ tasks[t.name] = _t;
168
+ }
169
+ else if (ext == "py") {
170
+ const _t = pythonAction(path);
171
+ _t.type = "action";
172
+ tasks[t.name] = _t;
173
+ }
119
174
  }
120
175
  else {
121
176
  const { found, path } = getFeatureSpec(t.name, "task");
@@ -1,2 +1,2 @@
1
- declare function executeTaskCmd(args?: Array<string>, options?: any): Promise<any>;
1
+ declare function executeTaskCmd(args?: Array<string> | Record<string, any>, options?: any): Promise<any>;
2
2
  export { executeTaskCmd };
@@ -1,24 +1,43 @@
1
1
  import { brain, initAgent, taskBuilder } from "../../agent.js";
2
2
  import { getFeatureSpec } from "../../state/features.js";
3
3
  import { isChatMode, isDebug } from "../../state/state.js";
4
- import { initTaskConf, initTaskVars, parseInputOptions, readTask } from "./utils.js";
4
+ import { initTaskConf, initTaskParams, initTaskVars, parseInputOptions, readTask } from "./utils.js";
5
5
  async function executeTaskCmd(args = [], options = {}) {
6
6
  await initAgent();
7
7
  if (isDebug.value) {
8
8
  console.log("Task args:", args);
9
9
  console.log("Task options:", options);
10
10
  }
11
- const name = args.shift();
12
- const params = args.filter((x) => x.length > 0);
13
- let pr = await parseInputOptions(options);
14
- if (!pr) {
15
- const p = params.shift();
16
- if (p) {
17
- pr = p;
11
+ const isJob = !Array.isArray(args);
12
+ let name;
13
+ let pr;
14
+ if (!isJob) {
15
+ name = args.shift();
16
+ const _pr = await parseInputOptions(options);
17
+ if (!_pr) {
18
+ const p = args.shift();
19
+ if (p) {
20
+ pr = p;
21
+ }
22
+ else {
23
+ throw new Error("Please provide a prompt");
24
+ }
25
+ }
26
+ else {
27
+ pr = _pr;
18
28
  }
19
29
  }
20
- if (!pr) {
21
- throw new Error("Please provide a prompt");
30
+ else {
31
+ if (!args.name) {
32
+ throw new Error("Provide a task name param");
33
+ }
34
+ if (!args.prompt) {
35
+ throw new Error("Provide a task prompt param");
36
+ }
37
+ name = args.name;
38
+ delete args.name;
39
+ pr = args.prompt;
40
+ delete args.prompt;
22
41
  }
23
42
  const { found, path } = getFeatureSpec(name, "task");
24
43
  if (!found) {
@@ -30,7 +49,18 @@ async function executeTaskCmd(args = [], options = {}) {
30
49
  }
31
50
  const taskSpec = taskBuilder.readFromYaml(res.ymlTask);
32
51
  const task = taskBuilder.fromYaml(res.ymlTask);
33
- let { conf, vars } = initTaskVars(args, taskSpec?.inferParams ? taskSpec.inferParams : {});
52
+ let conf = {};
53
+ let vars = {};
54
+ if (!isJob) {
55
+ const tv = initTaskVars(args, taskSpec?.inferParams ? taskSpec.inferParams : {});
56
+ conf = tv.conf;
57
+ vars = tv.vars;
58
+ }
59
+ else {
60
+ const tv = initTaskParams(args, taskSpec?.inferParams ? taskSpec.inferParams : {});
61
+ conf = tv.conf;
62
+ vars = tv.vars;
63
+ }
34
64
  conf = initTaskConf(conf, taskSpec);
35
65
  if (isDebug.value) {
36
66
  console.log("Task conf:", conf);
@@ -57,7 +87,7 @@ async function executeTaskCmd(args = [], options = {}) {
57
87
  }
58
88
  const data = await task.run({ prompt: pr, ...vars }, conf);
59
89
  if (data?.error) {
60
- return { ok: false, data: "", conf: conf, error: `Error executing task: ${data.error}` };
90
+ return { ok: false, data: "", conf: conf, error: `Error executing task: ${name} ${data.error}` };
61
91
  }
62
92
  conf.prompt = pr;
63
93
  if (isChatMode.value) {
@@ -8,9 +8,13 @@ declare function readTask(taskpath: string): {
8
8
  };
9
9
  declare function readTasksDir(dir: string): Array<string>;
10
10
  declare function initTaskConf(conf: Record<string, any>, taskSpec: LmTask): Record<string, any>;
11
+ declare function initTaskParams(params: Record<string, any>, inferParams: Record<string, any>): {
12
+ conf: Record<string, any>;
13
+ vars: Record<string, any>;
14
+ };
11
15
  declare function initTaskVars(args: Array<any>, inferParams: Record<string, any>): {
12
16
  conf: Record<string, any>;
13
17
  vars: Record<string, any>;
14
18
  };
15
19
  declare function parseInputOptions(options: any): Promise<string | null>;
16
- export { readPromptFile, processOutput, setOptions, readTask, readTasksDir, initTaskVars, initTaskConf, parseInputOptions, };
20
+ export { readPromptFile, processOutput, setOptions, readTask, readTasksDir, initTaskVars, initTaskConf, initTaskParams, parseInputOptions, };
@@ -44,6 +44,7 @@ async function processOutput(res) {
44
44
  let hasOutput = false;
45
45
  if (res?.data) {
46
46
  data = res.data;
47
+ 0;
47
48
  hasOutput = true;
48
49
  }
49
50
  if (res?.text) {
@@ -58,6 +59,9 @@ async function processOutput(res) {
58
59
  data = res;
59
60
  }
60
61
  if (outputMode.value == "clipboard") {
62
+ if (typeof data == "object") {
63
+ data = JSON.stringify(data);
64
+ }
61
65
  await writeToClipboard(data);
62
66
  }
63
67
  }
@@ -122,6 +126,18 @@ function initTaskConf(conf, taskSpec) {
122
126
  }
123
127
  return _conf;
124
128
  }
129
+ function initTaskParams(params, inferParams) {
130
+ const conf = { inferParams: inferParams };
131
+ if (!params?.prompt) {
132
+ throw new Error(`Error initializing task variable: provide a prompt`);
133
+ }
134
+ if (params?.images) {
135
+ conf.inferParams.images = params.images;
136
+ delete params.images;
137
+ }
138
+ const res = { conf: conf, vars: params };
139
+ return res;
140
+ }
125
141
  function initTaskVars(args, inferParams) {
126
142
  const conf = { inferParams: inferParams };
127
143
  const vars = {};
@@ -130,27 +146,29 @@ function initTaskVars(args, inferParams) {
130
146
  const t = a.split("=");
131
147
  const k = t[0];
132
148
  const v = t[1];
133
- if (k == "m") {
134
- if (v.includes("/")) {
135
- const _s = v.split("/");
136
- conf.model = _s[0];
137
- conf.template = _s[1];
138
- }
139
- else {
140
- conf.model = v;
141
- }
142
- }
143
- else if (k == "ip") {
144
- v.split(",").forEach((p) => {
145
- const s = p.split(":");
146
- conf["inferParams"][s[0]] = parseFloat(s[1]);
147
- });
148
- }
149
- else if (k == "s") {
150
- conf.size = v;
151
- }
152
- else {
153
- vars[k] = v;
149
+ switch (k) {
150
+ case "m":
151
+ if (v.includes("/")) {
152
+ const _s = v.split("/");
153
+ conf.model = _s[0];
154
+ conf.template = _s[1];
155
+ }
156
+ else {
157
+ conf.model = v;
158
+ }
159
+ break;
160
+ case "ip":
161
+ v.split(",").forEach((p) => {
162
+ const s = p.split(":");
163
+ conf["inferParams"][s[0]] = parseFloat(s[1]);
164
+ });
165
+ break;
166
+ case "s":
167
+ conf.size = v;
168
+ break;
169
+ default:
170
+ vars[k] = v;
171
+ break;
154
172
  }
155
173
  }
156
174
  });
@@ -166,4 +184,4 @@ async function parseInputOptions(options) {
166
184
  }
167
185
  return out;
168
186
  }
169
- export { readPromptFile, processOutput, setOptions, readTask, readTasksDir, initTaskVars, initTaskConf, parseInputOptions, };
187
+ export { readPromptFile, processOutput, setOptions, readTask, readTasksDir, initTaskVars, initTaskConf, initTaskParams, parseInputOptions, };
@@ -7,6 +7,7 @@ declare const runMode: import("@vue/reactivity").Ref<RunMode, RunMode>;
7
7
  declare const formatMode: import("@vue/reactivity").Ref<FormatMode, FormatMode>;
8
8
  declare const isChatMode: import("@vue/reactivity").Ref<boolean, boolean>;
9
9
  declare const isDebug: import("@vue/reactivity").Ref<boolean, boolean>;
10
+ declare const isVerbose: import("@vue/reactivity").Ref<boolean, boolean>;
10
11
  declare const promptfile: import("@vue/reactivity").Ref<string, string>;
11
12
  declare const lastCmd: {
12
13
  name: string;
@@ -14,4 +15,4 @@ declare const lastCmd: {
14
15
  };
15
16
  declare function initFeatures(): Promise<void>;
16
17
  declare function initState(): Promise<void>;
17
- export { inputMode, outputMode, isChatMode, runMode, formatMode, lastCmd, isDebug, promptfile, initState, initFeatures, pyShell, };
18
+ export { inputMode, outputMode, isChatMode, runMode, formatMode, lastCmd, isDebug, isVerbose, promptfile, initState, initFeatures, pyShell, };
@@ -12,6 +12,7 @@ const runMode = ref("cmd");
12
12
  const formatMode = ref("text");
13
13
  const isChatMode = ref(false);
14
14
  const isDebug = ref(false);
15
+ const isVerbose = ref(false);
15
16
  const promptfile = ref("");
16
17
  const lastCmd = reactive({
17
18
  name: "",
@@ -37,4 +38,4 @@ async function initState() {
37
38
  initConf();
38
39
  await initFeatures();
39
40
  }
40
- export { inputMode, outputMode, isChatMode, runMode, formatMode, lastCmd, isDebug, promptfile, initState, initFeatures, pyShell, };
41
+ export { inputMode, outputMode, isChatMode, runMode, formatMode, lastCmd, isDebug, isVerbose, promptfile, initState, initFeatures, pyShell, };
package/package.json CHANGED
@@ -2,17 +2,17 @@
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.31",
5
+ "version": "0.0.32",
6
6
  "scripts": {
7
7
  "buildrl": "rm -rf dist/* && rollup -c",
8
- "build": "rm -rf dist/* && tsc",
8
+ "build": "rm -rf dist/* && tsc --noCheck",
9
9
  "cli": "node --loader ts-node/esm bin/index.ts",
10
- "watch": "tsc -p . -w"
10
+ "watch": "tsc --noCheck -p . -w"
11
11
  },
12
12
  "dependencies": {
13
- "@agent-smith/brain": "^0.0.35",
13
+ "@agent-smith/brain": "^0.0.36",
14
14
  "@agent-smith/jobs": "^0.0.11",
15
- "@agent-smith/lmtask": "^0.0.28",
15
+ "@agent-smith/lmtask": "^0.0.29",
16
16
  "@agent-smith/tfm": "^0.1.1",
17
17
  "@inquirer/prompts": "^7.3.2",
18
18
  "@inquirer/select": "^4.0.9",
@@ -33,7 +33,7 @@
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.4",
36
+ "@types/node": "^22.13.5",
37
37
  "restmix": "^0.5.0",
38
38
  "rollup": "^4.34.8",
39
39
  "ts-node": "^10.9.2",