@agent-smith/cli 0.0.6 → 0.0.8

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.js CHANGED
@@ -1,6 +1,5 @@
1
1
  import { useAgentBrain } from "@agent-smith/brain";
2
2
  import { LmTaskBuilder } from "@agent-smith/lmtask";
3
- ;
4
3
  import { marked } from 'marked';
5
4
  import { markedTerminal } from 'marked-terminal';
6
5
  marked.use(markedTerminal());
@@ -9,8 +8,8 @@ const modelsForExpert = {};
9
8
  const taskBuilder = new LmTaskBuilder(brain);
10
9
  async function initExperts() {
11
10
  brain.experts.forEach((ex) => {
12
- ex.setOnStartEmit(() => console.log(""));
13
- ex.setOnToken((t) => {
11
+ ex.backend.setOnStartEmit(() => console.log(""));
12
+ ex.backend.setOnToken((t) => {
14
13
  process.stdout.write(t);
15
14
  });
16
15
  });
@@ -18,9 +17,8 @@ async function initExperts() {
18
17
  async function initAgent(mode, isVerbose = false) {
19
18
  if (!brain.state.get().isOn) {
20
19
  brain.resetExperts();
21
- await brain.discoverLocal();
20
+ await brain.initLocal();
22
21
  await initExperts();
23
- await brain.expertsForModelsInfo();
24
22
  }
25
23
  const brainUp = brain.state.get().isOn;
26
24
  if (isVerbose) {
@@ -1,5 +1,6 @@
1
1
  import { Cmd } from "../../interfaces.js";
2
2
  declare let cmds: Record<string, Cmd>;
3
+ declare function initAliases(): Record<string, Cmd>;
3
4
  declare function initCmds(): Promise<Record<string, Cmd>>;
4
5
  declare function pingCmd(args: Array<string> | undefined, options: any): Promise<boolean>;
5
- export { cmds, initCmds, pingCmd };
6
+ export { cmds, initCmds, pingCmd, initAliases };
@@ -1,7 +1,7 @@
1
1
  import { formatMode, initFeatures, runMode } from "../../state/state.js";
2
2
  import { getFeatureSpec, readFeaturesDirs } from "../../state/features.js";
3
- import { readFeatures } from "../../db/read.js";
4
- import { updateFeatures } from "../../db/write.js";
3
+ import { readAliases, readFeatures } from "../../db/read.js";
4
+ import { updateAliases, updateFeatures } from "../../db/write.js";
5
5
  import { updateConf } from "../../conf.js";
6
6
  import { executeActionCmd } from "../lib/execute_action.js";
7
7
  import { initAgent, marked, taskBuilder } from "../../agent.js";
@@ -57,6 +57,35 @@ let cmds = {
57
57
  description: "reparse the features dirs and update the list",
58
58
  }
59
59
  };
60
+ function initAliases() {
61
+ const aliases = readAliases();
62
+ const _cmds = {};
63
+ aliases.forEach((alias) => {
64
+ switch (alias.type) {
65
+ case "task":
66
+ _cmds[alias.name] = {
67
+ cmd: (args = [], options) => _executeTaskCmd([alias.name, ...args], options),
68
+ description: "task: " + alias.name,
69
+ args: "arguments: \n-args: prompt and other arguments if any for the task"
70
+ };
71
+ break;
72
+ case "action":
73
+ _cmds[alias.name] = {
74
+ cmd: (args = [], options = {}, quiet = false) => executeActionCmd([alias.name, ...args], options, quiet),
75
+ description: "action: " + alias.name,
76
+ args: "arguments: \n-args: other arguments if any for the action"
77
+ };
78
+ break;
79
+ case "job":
80
+ _cmds[alias.name] = {
81
+ cmd: (args = [], options) => _executeJobCmd([alias.name, ...args], options),
82
+ description: "job: " + alias.name,
83
+ args: "arguments: \n-args: other arguments if any for the job"
84
+ };
85
+ }
86
+ });
87
+ return _cmds;
88
+ }
60
89
  async function initCmds() {
61
90
  for (const dirpath of new Set(Object.values(readFeatures().cmd))) {
62
91
  const c = await readCmds(`${dirpath}`);
@@ -84,6 +113,7 @@ async function _updateConfCmd(args = [], options) {
84
113
  const allPaths = await updateConf(args[0]);
85
114
  const feats = readFeaturesDirs(allPaths);
86
115
  updateFeatures(feats);
116
+ updateAliases(feats);
87
117
  }
88
118
  async function _readJobCmd(args = [], options) {
89
119
  if (args.length == 0) {
@@ -140,4 +170,4 @@ async function _readTaskCmd(args = [], options) {
140
170
  async function _listTasksCmd(args = [], options) {
141
171
  Object.keys(readFeatures().task).forEach((t) => console.log("-", t));
142
172
  }
143
- export { cmds, initCmds, pingCmd };
173
+ export { cmds, initCmds, pingCmd, initAliases };
package/dist/cmd/cmds.js CHANGED
@@ -2,7 +2,7 @@ import { Command } from "commander";
2
2
  import { lastCmd } from "../state/state.js";
3
3
  import { modes } from "./clicmds/modes.js";
4
4
  import { processOutput, setOptions } from "./lib/utils.js";
5
- import { cmds, initCmds } from "./clicmds/cmds.js";
5
+ import { cmds, initAliases, initCmds } from "./clicmds/cmds.js";
6
6
  let cliCmds = {};
7
7
  async function initCliCmds() {
8
8
  cliCmds = await initCmds();
@@ -19,7 +19,8 @@ async function runCmd(cmdName, args = []) {
19
19
  }
20
20
  async function buildCmds() {
21
21
  const program = new Command();
22
- for (const [name, spec] of Object.entries(cmds)) {
22
+ const aliases = initAliases();
23
+ for (const [name, spec] of Object.entries({ ...cmds, ...aliases })) {
23
24
  const cmd = program.command(name);
24
25
  const _cmd = async (args = [], options = {}) => {
25
26
  const _args = await setOptions(options, args);
@@ -14,8 +14,8 @@ async function executeJobCmd(name, args = []) {
14
14
  await job.start();
15
15
  let params = args;
16
16
  let res = {};
17
+ brain.backendsForModelsInfo();
17
18
  for (const name of Object.keys(job.tasks)) {
18
- brain.expertsForModelsInfo();
19
19
  try {
20
20
  res = await job.runTask(name, params);
21
21
  if ("text" in res) {
@@ -1,4 +1,4 @@
1
- import { initAgent, taskBuilder } from "../../agent.js";
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
4
  import { readTask } from "./utils.js";
@@ -13,6 +13,7 @@ async function executeTaskCmd(args = [], options = {}) {
13
13
  if (!res.found) {
14
14
  throw new Error(`Task ${name}, ${path} not found`);
15
15
  }
16
+ const taskSpec = taskBuilder.readFromYaml(res.ymlTask);
16
17
  const task = taskBuilder.fromYaml(res.ymlTask);
17
18
  const pr = args.shift();
18
19
  const vars = {};
@@ -22,6 +23,15 @@ async function executeTaskCmd(args = [], options = {}) {
22
23
  vars[t[0]] = t[1];
23
24
  }
24
25
  });
26
+ const ex = brain.getOrCreateExpertForModel(taskSpec.model.name, taskSpec.template.name);
27
+ if (!ex) {
28
+ throw new Error("No expert found for model " + taskSpec.model.name);
29
+ }
30
+ ex.checkStatus();
31
+ ex.backend.setOnToken((t) => {
32
+ process.stdout.write(t);
33
+ });
34
+ vars["expert"] = ex;
25
35
  console.log("Ingesting prompt ...");
26
36
  const data = await task.run({ prompt: pr, ...vars });
27
37
  if (data?.error) {
@@ -1,3 +1,3 @@
1
- import { Features } from "bin/interfaces";
1
+ import { Features } from "../../interfaces.js";
2
2
  declare function readFeaturesDir(dir: string): Features;
3
3
  export { readFeaturesDir };
package/dist/db/db.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import DatabaseConstructor from "better-sqlite3";
2
2
  import { schemas } from "./schemas.js";
3
3
  import { dbPath } from "../conf.js";
4
- let db;
4
+ let db = new DatabaseConstructor("x", { fileMustExist: false });
5
5
  function initDb(isVerbose = false) {
6
6
  db = new DatabaseConstructor(dbPath);
7
7
  schemas.forEach((s) => {
package/dist/db/read.d.ts CHANGED
@@ -1,9 +1,13 @@
1
- import { FeatureSpec, FeatureType } from "../interfaces.js";
1
+ import { AliasType, FeatureSpec, FeatureType } from "../interfaces.js";
2
2
  declare function readFeaturePaths(): Array<string>;
3
3
  declare function readPlugins(): Array<Record<string, string>>;
4
4
  declare function readFeatures(): Record<FeatureType, Record<string, string>>;
5
+ declare function readAliases(): Array<{
6
+ name: string;
7
+ type: AliasType;
8
+ }>;
5
9
  declare function readFeature(name: string, type: FeatureType): {
6
10
  found: boolean;
7
11
  feature: FeatureSpec;
8
12
  };
9
- export { readFeatures, readFeaturePaths, readFeature, readPlugins };
13
+ export { readFeatures, readFeaturePaths, readFeature, readPlugins, readAliases };
package/dist/db/read.js CHANGED
@@ -34,6 +34,15 @@ function readFeatures() {
34
34
  feats.cmd = readFeaturesType("cmd");
35
35
  return feats;
36
36
  }
37
+ function readAliases() {
38
+ const stmt = db.prepare("SELECT name, type FROM aliases");
39
+ const data = stmt.all();
40
+ let f = new Array();
41
+ data.forEach((row) => {
42
+ f.push({ name: row.name, type: row.type });
43
+ });
44
+ return f;
45
+ }
37
46
  function readFeature(name, type) {
38
47
  const q = `SELECT id, path, ext FROM ${type} WHERE name='${name}'`;
39
48
  const stmt = db.prepare(q);
@@ -50,4 +59,4 @@ function readFeature(name, type) {
50
59
  }
51
60
  return { found: false, feature: {} };
52
61
  }
53
- export { readFeatures, readFeaturePaths, readFeature, readPlugins };
62
+ export { readFeatures, readFeaturePaths, readFeature, readPlugins, readAliases };
@@ -36,7 +36,12 @@ const cmds = `CREATE TABLE IF NOT EXISTS cmd (
36
36
  path TEXT NOT NULL,
37
37
  ext TEXT NOT NULL CHECK ( ext IN ('js') )
38
38
  );`;
39
+ const aliases = `CREATE TABLE IF NOT EXISTS aliases (
40
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
41
+ name TEXT UNIQUE NOT NULL,
42
+ type TEXT NOT NULL CHECK ( type IN ('task', 'action', 'job') )
43
+ );`;
39
44
  const schemas = [
40
- filepaths, featurespaths, tasks, jobs, actions, cmds, plugins
45
+ filepaths, featurespaths, tasks, jobs, actions, cmds, plugins, aliases
41
46
  ];
42
47
  export { schemas };
@@ -2,5 +2,6 @@ import { Features } from "../interfaces.js";
2
2
  declare function insertDefaultFilepaths(): void;
3
3
  declare function insertFeaturesPathIfNotExists(path: string): boolean;
4
4
  declare function insertPluginIfNotExists(n: string, p: string): boolean;
5
+ declare function updateAliases(feats: Features): void;
5
6
  declare function updateFeatures(feats: Features): void;
6
- export { insertDefaultFilepaths, insertFeaturesPathIfNotExists, insertPluginIfNotExists, updateFeatures, };
7
+ export { insertDefaultFilepaths, insertFeaturesPathIfNotExists, insertPluginIfNotExists, updateFeatures, updateAliases, };
package/dist/db/write.js CHANGED
@@ -29,6 +29,31 @@ function insertPluginIfNotExists(n, p) {
29
29
  stmt.run(n, p);
30
30
  return false;
31
31
  }
32
+ function _updateAlias(existingAliases, name, type) {
33
+ if (!existingAliases.includes(name)) {
34
+ const insertStmt = db.prepare("INSERT INTO aliases (name, type) VALUES (?, ?)");
35
+ insertStmt.run(name, type);
36
+ }
37
+ else {
38
+ console.log("Can not create command alias", name, ": duplicate name");
39
+ }
40
+ existingAliases.push(name);
41
+ return existingAliases;
42
+ }
43
+ function updateAliases(feats) {
44
+ const deleteStmt = db.prepare("DELETE FROM aliases");
45
+ deleteStmt.run();
46
+ let existingAliases = new Array();
47
+ feats.task.forEach((feat) => {
48
+ existingAliases = _updateAlias(existingAliases, feat.name, "task");
49
+ });
50
+ feats.action.forEach((feat) => {
51
+ existingAliases = _updateAlias(existingAliases, feat.name, "action");
52
+ });
53
+ feats.job.forEach((feat) => {
54
+ existingAliases = _updateAlias(existingAliases, feat.name, "job");
55
+ });
56
+ }
32
57
  function upsertAndCleanFeatures(feats, type) {
33
58
  const stmt = db.prepare(`SELECT name FROM ${type}`);
34
59
  const rows = stmt.all();
@@ -53,4 +78,4 @@ function updateFeatures(feats) {
53
78
  upsertAndCleanFeatures(feats.action, "action");
54
79
  upsertAndCleanFeatures(feats.cmd, "cmd");
55
80
  }
56
- export { insertDefaultFilepaths, insertFeaturesPathIfNotExists, insertPluginIfNotExists, updateFeatures, };
81
+ export { insertDefaultFilepaths, insertFeaturesPathIfNotExists, insertPluginIfNotExists, updateFeatures, updateAliases, };
package/dist/index.js CHANGED
File without changes
@@ -46,4 +46,5 @@ type TaskExtension = "yml";
46
46
  type JobExtension = "yml";
47
47
  type CmdExtension = "js";
48
48
  type FeatureExtension = TaskExtension | JobExtension | CmdExtension | ActionExtension;
49
- export { Cmd, CmdExecutor, InputMode, OutputMode, RunMode, FormatMode, FeatureType, ActionExtension, TaskExtension, JobExtension, CmdExtension, FeatureSpec, Features, ConfigFile, FeatureExtension, };
49
+ type AliasType = "task" | "action" | "job";
50
+ export { Cmd, CmdExecutor, InputMode, OutputMode, RunMode, FormatMode, FeatureType, ActionExtension, TaskExtension, JobExtension, CmdExtension, FeatureSpec, Features, ConfigFile, FeatureExtension, AliasType, };
@@ -9,7 +9,6 @@ function readFeaturesDirs(featuresPaths) {
9
9
  cmd: [],
10
10
  };
11
11
  featuresPaths.forEach((dir) => {
12
- console.log("Reading feats in", dir);
13
12
  const _f = readFeaturesDir(dir);
14
13
  _f.task.forEach((item) => feats.task.push(item));
15
14
  _f.job.forEach((item) => feats.job.push(item));
@@ -1,11 +1,11 @@
1
1
  import { PythonShell } from 'python-shell';
2
2
  import { InputMode, RunMode, FormatMode, OutputMode } from "../interfaces.js";
3
3
  declare let pyShell: PythonShell;
4
- declare const inputMode: import("@vue/reactivity").Ref<InputMode>;
5
- declare const outputMode: import("@vue/reactivity").Ref<OutputMode>;
6
- declare const runMode: import("@vue/reactivity").Ref<RunMode>;
7
- declare const formatMode: import("@vue/reactivity").Ref<FormatMode>;
8
- declare const promptfile: import("@vue/reactivity").Ref<string>;
4
+ declare const inputMode: import("@vue/reactivity").Ref<InputMode, InputMode>;
5
+ declare const outputMode: import("@vue/reactivity").Ref<OutputMode, OutputMode>;
6
+ declare const runMode: import("@vue/reactivity").Ref<RunMode, RunMode>;
7
+ declare const formatMode: import("@vue/reactivity").Ref<FormatMode, FormatMode>;
8
+ declare const promptfile: import("@vue/reactivity").Ref<string, string>;
9
9
  declare const lastCmd: {
10
10
  name: string;
11
11
  args: Array<string>;
@@ -2,7 +2,7 @@ import { reactive, ref } from "@vue/reactivity";
2
2
  import { createConfDirIfNotExists, confDir } from "../conf.js";
3
3
  import { initDb } from "../db/db.js";
4
4
  import { readFeaturePaths } from "../db/read.js";
5
- import { updateFeatures } from "../db/write.js";
5
+ import { updateAliases, updateFeatures } from "../db/write.js";
6
6
  import { readFeaturesDirs } from "./features.js";
7
7
  import { readPluginsPaths } from "./plugins.js";
8
8
  let pyShell;
@@ -28,8 +28,10 @@ async function initFeatures() {
28
28
  const p = [...fp, ...pp];
29
29
  const feats = readFeaturesDirs(p);
30
30
  updateFeatures(feats);
31
+ updateAliases(feats);
31
32
  }
32
33
  async function initState() {
33
34
  initConf();
35
+ await initFeatures();
34
36
  }
35
37
  export { inputMode, outputMode, runMode, formatMode, lastCmd, promptfile, initState, initFeatures, pyShell, };
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.6",
5
+ "version": "0.0.8",
6
6
  "scripts": {
7
7
  "buildrl": "rm -rf dist/* && rollup -c",
8
8
  "build": "rm -rf dist/* && tsc",
@@ -10,34 +10,35 @@
10
10
  "watch": "tsc -p . -w"
11
11
  },
12
12
  "dependencies": {
13
- "@agent-smith/brain": "^0.0.18",
13
+ "@agent-smith/brain": "^0.0.24",
14
14
  "@agent-smith/jobs": "^0.0.8",
15
- "@agent-smith/lmtask": "^0.0.13",
16
- "@inquirer/prompts": "^5.3.8",
17
- "@inquirer/select": "^2.4.7",
18
- "@vue/reactivity": "^3.4.38",
19
- "better-sqlite3": "^11.2.1",
15
+ "@agent-smith/lmtask": "^0.0.17",
16
+ "@inquirer/prompts": "^6.0.1",
17
+ "@inquirer/select": "^3.0.1",
18
+ "@vue/reactivity": "^3.5.6",
19
+ "better-sqlite3": "^11.3.0",
20
20
  "clipboardy": "^4.0.0",
21
21
  "commander": "^12.1.0",
22
22
  "draftlog": "^1.0.13",
23
23
  "marked-terminal": "^7.1.0",
24
24
  "modprompt": "^0.7.7",
25
25
  "python-shell": "^5.0.0",
26
- "yaml": "^2.5.0"
26
+ "yaml": "^2.5.1"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@agent-smith/tmem-jobs": "^0.0.3",
30
30
  "@commander-js/extra-typings": "^12.1.0",
31
- "@locallm/types": "^0.0.17",
31
+ "@locallm/types": "^0.1.5",
32
32
  "@rollup/plugin-node-resolve": "^15.2.3",
33
33
  "@rollup/plugin-typescript": "^11.1.6",
34
34
  "@types/better-sqlite3": "^7.6.11",
35
35
  "@types/marked-terminal": "^6.1.1",
36
- "@types/node": "^22.5.2",
37
- "rollup": "^4.21.2",
36
+ "@types/node": "^22.5.5",
37
+ "restmix": "^0.5.0",
38
+ "rollup": "^4.21.3",
38
39
  "ts-node": "^10.9.2",
39
40
  "tslib": "2.7.0",
40
- "typescript": "^5.5.4"
41
+ "typescript": "^5.6.2"
41
42
  },
42
43
  "type": "module",
43
44
  "preferGlobal": true,