@agent-smith/cli 0.0.9 → 0.0.11

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/agent.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { LmTaskBuilder } from "@agent-smith/lmtask";
2
2
  import { marked } from 'marked';
3
- import { RunMode } from "./interfaces.js";
3
+ import { FeatureType, RunMode } from "./interfaces.js";
4
4
  declare let brain: import("@agent-smith/brain").AgentBrain;
5
5
  declare const modelsForExpert: Record<string, string>;
6
- declare const taskBuilder: LmTaskBuilder;
6
+ declare const taskBuilder: LmTaskBuilder<FeatureType>;
7
7
  declare function initAgent(mode: RunMode, isVerbose?: boolean): Promise<boolean>;
8
8
  export { brain, initAgent, marked, modelsForExpert, taskBuilder };
@@ -1,4 +1,4 @@
1
- declare function executeJobCmd(name: string, args?: Array<any>): Promise<"" | Record<string, any>>;
1
+ declare function executeJobCmd(name: string, args?: Array<any>): Promise<Record<string, any>>;
2
2
  declare function readJob(name: string): Promise<{
3
3
  found: boolean;
4
4
  data: Record<string, any>;
@@ -4,32 +4,78 @@ 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 } from '../../state/state.js';
7
- import { readTask } from './utils.js';
7
+ import { initTaskVars, readTask } from './utils.js';
8
8
  async function executeJobCmd(name, args = []) {
9
9
  const { job, found } = await _dispatchReadJob(name);
10
10
  if (!found) {
11
11
  console.log(`Job ${name} not found`);
12
- return "";
12
+ return { error: `Job ${name} not found` };
13
13
  }
14
14
  await job.start();
15
- let params = args;
16
15
  let res = {};
16
+ let params = {};
17
17
  brain.backendsForModelsInfo();
18
- for (const name of Object.keys(job.tasks)) {
19
- try {
20
- res = await job.runTask(name, params);
21
- if ("text" in res) {
22
- if (formatMode.value == "markdown") {
23
- console.log("\n\n------------------\n");
24
- console.log(marked.parse(res.text).trim());
18
+ let i = 0;
19
+ for (const [name, task] of Object.entries(job.tasks)) {
20
+ if (task.type == "task") {
21
+ let conf = {};
22
+ let vars = {};
23
+ if (i == 0) {
24
+ const tv = initTaskVars(args);
25
+ conf = tv.conf;
26
+ vars = tv.vars;
27
+ }
28
+ else {
29
+ conf = {};
30
+ vars = params;
31
+ }
32
+ const { found, path } = getFeatureSpec(name, "task");
33
+ if (!found) {
34
+ return { ok: false, data: {}, error: `Task ${name} not found` };
35
+ }
36
+ const tres = readTask(path);
37
+ if (!tres.found) {
38
+ throw new Error(`Task ${name}, ${path} not found`);
39
+ }
40
+ const taskSpec = taskBuilder.readFromYaml(tres.ymlTask);
41
+ const ex = brain.getOrCreateExpertForModel(taskSpec.model.name, taskSpec.template.name);
42
+ if (!ex) {
43
+ throw new Error("No expert found for model " + taskSpec.model.name);
44
+ }
45
+ ex.checkStatus();
46
+ ex.backend.setOnToken((t) => {
47
+ process.stdout.write(t);
48
+ });
49
+ conf["expert"] = ex;
50
+ try {
51
+ res = await job.runTask(name, vars, conf);
52
+ if ("text" in res) {
53
+ if (formatMode.value == "markdown") {
54
+ console.log("\n\n------------------\n");
55
+ console.log(marked.parse(res.text).trim());
56
+ }
25
57
  }
58
+ params = res;
59
+ }
60
+ catch (err) {
61
+ return { error: `Error executing (${task.type}) task ${name}: ${err}` };
26
62
  }
27
63
  }
28
- catch (err) {
29
- console.log("ERR", err);
30
- throw new Error(`Error executing task ${name}: ${err}`);
64
+ else {
65
+ try {
66
+ if (i == 0) {
67
+ res = await job.runTask(name, args);
68
+ }
69
+ else {
70
+ res = await job.runTask(name, params);
71
+ }
72
+ params = res.data;
73
+ }
74
+ catch (err) {
75
+ return { error: `Error executing (${task.type}) task ${name}: ${err}` };
76
+ }
31
77
  }
32
- params = res.data;
78
+ ++i;
33
79
  }
34
80
  await job.finish(true);
35
81
  return res;
@@ -52,7 +98,6 @@ async function _dispatchReadJob(name) {
52
98
  break;
53
99
  default:
54
100
  throw new Error(`Job extension ${ext} not implemented`);
55
- break;
56
101
  }
57
102
  return { found: true, job: jb };
58
103
  }
@@ -70,7 +115,9 @@ async function _createJobFromSpec(spec) {
70
115
  return { found: false, job: {} };
71
116
  }
72
117
  const { action } = await import(path);
73
- tasks[t.name] = action;
118
+ const at = action;
119
+ at.type = "action";
120
+ tasks[t.name] = at;
74
121
  }
75
122
  else {
76
123
  const { found, path } = getFeatureSpec(t.name, "task");
@@ -82,6 +129,7 @@ async function _createJobFromSpec(spec) {
82
129
  throw new Error(`Task ${t.name}, ${path} not found`);
83
130
  }
84
131
  const at = taskBuilder.fromYaml(res.ymlTask);
132
+ at.type = "task";
85
133
  tasks[t.name] = at;
86
134
  }
87
135
  }
@@ -1,7 +1,7 @@
1
1
  import { brain, initAgent, taskBuilder } from "../../agent.js";
2
2
  import { getFeatureSpec } from "../../state/features.js";
3
3
  import { runMode } from "../../state/state.js";
4
- import { readTask } from "./utils.js";
4
+ import { initTaskVars, readTask } from "./utils.js";
5
5
  async function executeTaskCmd(args = [], options = {}) {
6
6
  await initAgent(runMode.value);
7
7
  const name = args.shift();
@@ -16,13 +16,7 @@ async function executeTaskCmd(args = [], options = {}) {
16
16
  const taskSpec = taskBuilder.readFromYaml(res.ymlTask);
17
17
  const task = taskBuilder.fromYaml(res.ymlTask);
18
18
  const pr = args.shift();
19
- const vars = {};
20
- args.forEach((a) => {
21
- if (a.includes("=")) {
22
- const t = a.split("=");
23
- vars[t[0]] = t[1];
24
- }
25
- });
19
+ const { conf, vars } = initTaskVars(args);
26
20
  const ex = brain.getOrCreateExpertForModel(taskSpec.model.name, taskSpec.template.name);
27
21
  if (!ex) {
28
22
  throw new Error("No expert found for model " + taskSpec.model.name);
@@ -31,9 +25,9 @@ async function executeTaskCmd(args = [], options = {}) {
31
25
  ex.backend.setOnToken((t) => {
32
26
  process.stdout.write(t);
33
27
  });
34
- vars["expert"] = ex;
28
+ conf.expert = ex;
35
29
  console.log("Ingesting prompt ...");
36
- const data = await task.run({ prompt: pr, ...vars });
30
+ const data = await task.run({ prompt: pr, ...vars }, conf);
37
31
  if (data?.error) {
38
32
  return { ok: false, data: {}, error: `Error executing task: ${data.error}` };
39
33
  }
@@ -6,4 +6,8 @@ declare function readTask(taskpath: string): {
6
6
  ymlTask: string;
7
7
  };
8
8
  declare function readTasksDir(dir: string): Array<string>;
9
- export { readPromptFile, processOutput, setOptions, readTask, readTasksDir, };
9
+ declare function initTaskVars(args: Array<any>): {
10
+ conf: Record<string, any>;
11
+ vars: Record<string, any>;
12
+ };
13
+ export { readPromptFile, processOutput, setOptions, readTask, readTasksDir, initTaskVars, };
@@ -70,4 +70,29 @@ function readTasksDir(dir) {
70
70
  });
71
71
  return tasks;
72
72
  }
73
- export { readPromptFile, processOutput, setOptions, readTask, readTasksDir, };
73
+ function initTaskVars(args) {
74
+ const conf = {};
75
+ const vars = {};
76
+ args.forEach((a) => {
77
+ if (a.includes("=")) {
78
+ const t = a.split("=");
79
+ const k = t[0];
80
+ const v = t[1];
81
+ if (k == "m") {
82
+ if (v.includes("/")) {
83
+ const _s = v.split("/");
84
+ conf.model = _s[0];
85
+ conf.template = _s[1];
86
+ }
87
+ else {
88
+ conf.model = v;
89
+ }
90
+ }
91
+ else {
92
+ vars[k] = v;
93
+ }
94
+ }
95
+ });
96
+ return { conf, vars };
97
+ }
98
+ export { readPromptFile, processOutput, setOptions, readTask, readTasksDir, initTaskVars, };
package/dist/db/db.js CHANGED
@@ -1,9 +1,10 @@
1
1
  import DatabaseConstructor from "better-sqlite3";
2
2
  import { schemas } from "./schemas.js";
3
- import { dbPath } from "../conf.js";
4
- let db;
3
+ import path from "path";
4
+ const confDir = path.join(process.env.HOME, ".config/agent-smith/cli");
5
+ const dbPath = path.join(confDir, "config.db");
6
+ let db = new DatabaseConstructor(dbPath, { fileMustExist: false });
5
7
  function initDb(isVerbose = false) {
6
- db = new DatabaseConstructor(dbPath, { fileMustExist: false });
7
8
  schemas.forEach((s) => {
8
9
  db.exec(s);
9
10
  if (isVerbose) {
package/dist/db/read.js CHANGED
@@ -44,7 +44,7 @@ function readAliases() {
44
44
  return f;
45
45
  }
46
46
  function readFeature(name, type) {
47
- const q = `SELECT id, path, ext FROM ${type} WHERE name='${name}'`;
47
+ const q = `SELECT id, name, path, ext FROM ${type} WHERE name='${name}'`;
48
48
  const stmt = db.prepare(q);
49
49
  const result = stmt.get();
50
50
  if (result?.id) {
package/dist/index.js CHANGED
File without changes
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.9",
5
+ "version": "0.0.11",
6
6
  "scripts": {
7
7
  "buildrl": "rm -rf dist/* && rollup -c",
8
8
  "build": "rm -rf dist/* && tsc",
@@ -10,12 +10,12 @@
10
10
  "watch": "tsc -p . -w"
11
11
  },
12
12
  "dependencies": {
13
- "@agent-smith/brain": "^0.0.24",
14
- "@agent-smith/jobs": "^0.0.8",
15
- "@agent-smith/lmtask": "^0.0.17",
13
+ "@agent-smith/brain": "^0.0.26",
14
+ "@agent-smith/jobs": "^0.0.11",
15
+ "@agent-smith/lmtask": "^0.0.20",
16
16
  "@inquirer/prompts": "^6.0.1",
17
17
  "@inquirer/select": "^3.0.1",
18
- "@vue/reactivity": "^3.5.6",
18
+ "@vue/reactivity": "^3.5.7",
19
19
  "better-sqlite3": "^11.3.0",
20
20
  "clipboardy": "^4.0.0",
21
21
  "commander": "^12.1.0",
@@ -26,7 +26,7 @@
26
26
  "yaml": "^2.5.1"
27
27
  },
28
28
  "devDependencies": {
29
- "@agent-smith/tmem-jobs": "^0.0.3",
29
+ "@agent-smith/tmem-jobs": "^0.0.4",
30
30
  "@commander-js/extra-typings": "^12.1.0",
31
31
  "@locallm/types": "^0.1.5",
32
32
  "@rollup/plugin-node-resolve": "^15.2.3",
@@ -35,7 +35,7 @@
35
35
  "@types/marked-terminal": "^6.1.1",
36
36
  "@types/node": "^22.5.5",
37
37
  "restmix": "^0.5.0",
38
- "rollup": "^4.21.3",
38
+ "rollup": "^4.22.2",
39
39
  "ts-node": "^10.9.2",
40
40
  "tslib": "2.7.0",
41
41
  "typescript": "^5.6.2"