@agent-smith/cli 0.0.61 → 0.0.63

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,8 +1,8 @@
1
1
  import YAML from 'yaml';
2
2
  import { dataDirPath, isChatMode, isDebug, promptfilePath, runMode } from "../../state/state.js";
3
3
  import { getFeatureSpec, readFeaturesDirs } from "../../state/features.js";
4
- import { readAliases, readFeaturePaths, readFeatures } from "../../db/read.js";
5
- import { cleanupFeaturePaths, updateAliases, updateDataDirPath, updateFeatures, updatePromptfilePath } from "../../db/write.js";
4
+ import { readAliases, readFeaturePaths, readFeatures, readFilePath } from "../../db/read.js";
5
+ import { cleanupFeaturePaths, updateAliases, updateDataDirPath, updateFeatures, upsertFilePath, updatePromptfilePath } from "../../db/write.js";
6
6
  import { processConfPath } from "../../conf.js";
7
7
  import { executeActionCmd } from "../lib/actions/cmd.js";
8
8
  import { initAgent, taskBuilder } from "../../agent.js";
@@ -12,8 +12,9 @@ import { executeWorkflowCmd } from "../lib/workflows/cmd.js";
12
12
  import { readTask } from "../sys/read_task.js";
13
13
  import { deleteFileIfExists } from "../sys/delete_file.js";
14
14
  import { dbPath, initDb } from "../../db/db.js";
15
- import { showModelsCmd, updateModels } from '../lib/models.js';
15
+ import { showModelsCmd, updateAllModels } from '../lib/models.js';
16
16
  import { readPluginsPaths } from '../../state/plugins.js';
17
+ import { runtimeDataError, runtimeInfo } from '../lib/user_msgs.js';
17
18
  let cmds = {
18
19
  exit: {
19
20
  cmd: async () => process.exit(0),
@@ -94,19 +95,31 @@ async function _updateFeatures(args = [], options) {
94
95
  const feats = readFeaturesDirs(paths);
95
96
  updateFeatures(feats);
96
97
  updateAliases(feats);
97
- updateModels();
98
98
  const deleted = cleanupFeaturePaths(paths);
99
99
  for (const el of deleted) {
100
100
  console.log("- [feature path]", el);
101
101
  }
102
102
  }
103
103
  async function updateConfCmd(args = [], options) {
104
- if (args.length == 0) {
105
- console.warn("Provide a config.yml file path");
106
- return;
107
- }
108
104
  initDb(isDebug.value, true);
109
- const { paths, pf, dd } = await processConfPath(args[0]);
105
+ const { found, path } = readFilePath("conf");
106
+ const userProvidedConfPath = (args[0] != "conf") ? args[0] : null;
107
+ if (!found && !userProvidedConfPath) {
108
+ runtimeDataError("conf file path not found in db: please provide a conf path parameter to the command");
109
+ }
110
+ let confPath;
111
+ if (userProvidedConfPath) {
112
+ confPath = userProvidedConfPath;
113
+ const isu = upsertFilePath("conf", confPath);
114
+ if (isu) {
115
+ runtimeInfo("Config path", confPath, "updated");
116
+ }
117
+ }
118
+ else {
119
+ confPath = path;
120
+ }
121
+ console.log("Using", confPath, "to update features");
122
+ const { paths, pf, dd } = await processConfPath(confPath);
110
123
  if (pf.length > 0) {
111
124
  updatePromptfilePath(pf);
112
125
  promptfilePath.value = pf;
@@ -118,7 +131,7 @@ async function updateConfCmd(args = [], options) {
118
131
  const feats = readFeaturesDirs(paths);
119
132
  updateFeatures(feats);
120
133
  updateAliases(feats);
121
- updateModels();
134
+ updateAllModels();
122
135
  const deleted = cleanupFeaturePaths(paths);
123
136
  for (const el of deleted) {
124
137
  console.log("- [feature path]", el);
@@ -5,6 +5,7 @@ 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 { createJsAction } from "./read.js";
8
+ import { runtimeError } from "../../../utils/user_msgs.js";
8
9
  function systemAction(path) {
9
10
  const action = useAgentTask({
10
11
  id: "system_action",
@@ -23,6 +24,10 @@ function systemAction(path) {
23
24
  runArgs = args;
24
25
  }
25
26
  const actionSpec = readYmlFile(path);
27
+ if (!actionSpec.found) {
28
+ runtimeError("System action yml file", path, "not found");
29
+ }
30
+ console.log("Yml action", JSON.stringify(actionSpec.data, null, " "));
26
31
  if (!actionSpec.data?.args) {
27
32
  actionSpec.data.args = [];
28
33
  }
@@ -93,7 +98,7 @@ async function executeActionCmd(args = [], options = {}, quiet = false) {
93
98
  const res = await act.run(args, options);
94
99
  if (!quiet) {
95
100
  if (res) {
96
- console.log("ARES", res);
101
+ console.log(res);
97
102
  }
98
103
  }
99
104
  return res;
@@ -1,3 +1,3 @@
1
1
  declare function showModelsCmd(args: Array<string>, options: any): Promise<void>;
2
- declare function updateModels(): void;
3
- export { updateModels, showModelsCmd, };
2
+ declare function updateAllModels(): void;
3
+ export { updateAllModels, showModelsCmd, };
@@ -1,7 +1,7 @@
1
1
  import path from "path";
2
2
  import { readModelfiles, readModels } from "../../db/read.js";
3
3
  import { readModelsFile } from "../sys/read_modelfile.js";
4
- import { upsertModels } from "../../db/write.js";
4
+ import { updateModels as dbUpdateModels } from "../../db/write.js";
5
5
  import color from "ansi-colors";
6
6
  async function showModelsCmd(args, options) {
7
7
  let models = readModels();
@@ -23,9 +23,8 @@ async function showModelsCmd(args, options) {
23
23
  console.log(m);
24
24
  });
25
25
  }
26
- function updateModels() {
26
+ function updateAllModels() {
27
27
  const mfs = readModelfiles();
28
- const modelNames = new Array();
29
28
  const modelDefs = new Array();
30
29
  mfs.forEach((mf) => {
31
30
  const filePath = path.join(mf.path + "/" + mf.name + "." + mf.ext);
@@ -34,10 +33,6 @@ function updateModels() {
34
33
  throw new Error(`model file ${filePath} not found`);
35
34
  }
36
35
  for (const [name, m] of (Object.entries(models))) {
37
- if (modelNames.includes(m.name)) {
38
- console.log("🔴 [models] error: duplicate model name", m.name, "found in", filePath);
39
- continue;
40
- }
41
36
  if (!m?.ctx) {
42
37
  m.ctx = ctx;
43
38
  }
@@ -50,7 +45,7 @@ function updateModels() {
50
45
  const md = { name: m.name, shortname: name, data: m };
51
46
  modelDefs.push(md);
52
47
  }
53
- upsertModels(modelDefs);
54
48
  });
49
+ dbUpdateModels(modelDefs);
55
50
  }
56
- export { updateModels, showModelsCmd, };
51
+ export { updateAllModels, showModelsCmd, };
@@ -0,0 +1,5 @@
1
+ declare function runtimeError(...msg: string[]): void;
2
+ declare function runtimeWarning(...msg: string[]): void;
3
+ declare function runtimeDataError(...msg: string[]): void;
4
+ declare function runtimeInfo(...msg: string[]): void;
5
+ export { runtimeError, runtimeWarning, runtimeDataError, runtimeInfo, };
@@ -0,0 +1,17 @@
1
+ import { exit } from "process";
2
+ import chalk from 'chalk';
3
+ function runtimeError(...msg) {
4
+ console.warn("💥", chalk.dim("Runtime error:"), ...msg);
5
+ exit(1);
6
+ }
7
+ function runtimeWarning(...msg) {
8
+ console.warn("⚠️", chalk.dim("Runtime warning:"), ...msg);
9
+ }
10
+ function runtimeDataError(...msg) {
11
+ console.warn("❌", chalk.dim("Runtime data error:"), ...msg);
12
+ exit(1);
13
+ }
14
+ function runtimeInfo(...msg) {
15
+ console.log("📫", chalk.dim("Info:"), ...msg);
16
+ }
17
+ export { runtimeError, runtimeWarning, runtimeDataError, runtimeInfo, };
package/dist/conf.js CHANGED
@@ -2,12 +2,13 @@ import path from "path";
2
2
  import { readConf } from "./cmd/sys/read_conf.js";
3
3
  import { insertFeaturesPathIfNotExists, insertPluginIfNotExists } from "./db/write.js";
4
4
  import { buildPluginsPaths } from "./state/plugins.js";
5
+ import { runtimeError } from "./cmd/lib/user_msgs.js";
5
6
  const confDir = path.join(process.env.HOME, ".config/agent-smith/cli");
6
7
  const dbPath = path.join(confDir, "config.db");
7
8
  async function processConfPath(confPath) {
8
9
  const { found, data } = readConf(confPath);
9
10
  if (!found) {
10
- console.warn(`Config file ${confPath} not found`);
11
+ runtimeError(`Config file ${confPath} not found`);
11
12
  }
12
13
  const allPaths = new Array();
13
14
  if (data?.features) {
package/dist/db/read.d.ts CHANGED
@@ -20,10 +20,14 @@ declare function readFilePaths(): Array<{
20
20
  name: string;
21
21
  path: string;
22
22
  }>;
23
+ declare function readFilePath(name: string): {
24
+ found: boolean;
25
+ path: string;
26
+ };
23
27
  declare function readModelfiles(): Array<Record<string, string>>;
24
28
  declare function readModels(): Array<DbModelDef>;
25
29
  declare function readModel(shortname: string): {
26
30
  found: boolean;
27
31
  modelData: Record<string, any>;
28
32
  };
29
- export { readFeatures, readFeaturePaths, readFeature, readPlugins, readAliases, readFilePaths, readTool, readModels, readModelfiles, readModel, };
33
+ export { readFeatures, readFeaturePaths, readFeature, readPlugins, readAliases, readFilePath, readFilePaths, readTool, readModels, readModelfiles, readModel, };
package/dist/db/read.js CHANGED
@@ -86,6 +86,15 @@ function readFilePaths() {
86
86
  });
87
87
  return f;
88
88
  }
89
+ function readFilePath(name) {
90
+ const q = `SELECT id, path FROM filepath WHERE name= ?`;
91
+ const stmt = db.prepare(q);
92
+ const result = stmt.get(name);
93
+ if (result?.id) {
94
+ return { found: true, path: result.path };
95
+ }
96
+ return { found: false, path: "" };
97
+ }
89
98
  function readModelfiles() {
90
99
  const stmt = db.prepare("SELECT name, path, ext FROM modelfile");
91
100
  const data = stmt.all();
@@ -120,4 +129,4 @@ function readModel(shortname) {
120
129
  }
121
130
  return { found: false, modelData: {} };
122
131
  }
123
- export { readFeatures, readFeaturePaths, readFeature, readPlugins, readAliases, readFilePaths, readTool, readModels, readModelfiles, readModel, };
132
+ export { readFeatures, readFeaturePaths, readFeature, readPlugins, readAliases, readFilePath, readFilePaths, readTool, readModels, readModelfiles, readModel, };
@@ -5,6 +5,7 @@ declare function insertFeaturesPathIfNotExists(path: string): boolean;
5
5
  declare function insertPluginIfNotExists(n: string, p: string): boolean;
6
6
  declare function cleanupFeaturePaths(paths: Array<string>): Array<string>;
7
7
  declare function updateAliases(feats: Features): void;
8
- declare function upsertModels(models: Array<DbModelDef>): void;
8
+ declare function updateModels(models: Array<DbModelDef>): void;
9
9
  declare function updateFeatures(feats: Features): void;
10
- export { updatePromptfilePath, updateDataDirPath, insertFeaturesPathIfNotExists, insertPluginIfNotExists, updateFeatures, updateAliases, cleanupFeaturePaths, upsertModels, };
10
+ declare function upsertFilePath(name: string, newPath: string): boolean;
11
+ export { updatePromptfilePath, updateDataDirPath, insertFeaturesPathIfNotExists, insertPluginIfNotExists, updateFeatures, updateAliases, cleanupFeaturePaths, updateModels, upsertFilePath, };
package/dist/db/write.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { extractToolDoc } from "../cmd/lib/tools.js";
2
2
  import { db } from "./db.js";
3
+ import { readModels } from "./read.js";
3
4
  function updatePromptfilePath(pf) {
4
5
  const deleteStmt = db.prepare("DELETE FROM filepath WHERE name = ?");
5
6
  deleteStmt.run("promptfile");
@@ -110,26 +111,28 @@ function upsertTool(name, type, toolDoc) {
110
111
  stmt.run(name, toolDoc, type);
111
112
  console.log("+", "[tool] from", type, ":", name);
112
113
  }
113
- function upsertModels(models) {
114
- const stmt1 = db.prepare("SELECT shortname FROM model");
115
- const rows = stmt1.all();
116
- const existingModelShortNames = rows.map(row => row.shortname);
117
- const stmt = db.prepare(`INSERT INTO model (name, shortname, data) VALUES (?,?,?)`);
118
- existingModelShortNames.forEach((name) => {
119
- if (!existingModelShortNames.includes(name)) {
120
- const deleteStmt = db.prepare("DELETE FROM model WHERE name = ?");
121
- deleteStmt.run(name);
122
- console.log("-", "[model]", name);
123
- }
124
- });
114
+ function updateModels(models) {
115
+ const allDbModels = readModels();
116
+ const existingModelShortNames = allDbModels.map(row => row.shortname);
117
+ const newModelShortNames = models.filter(m => !existingModelShortNames.includes(m.shortname)).map(m => m.shortname);
118
+ const mm = models.map(m => m.shortname);
119
+ const modelsToDelete = existingModelShortNames.filter(name => !mm.includes(name));
125
120
  db.transaction(() => {
126
121
  for (const model of models) {
127
- const stmt1 = db.prepare("SELECT * FROM model WHERE shortname = ?");
128
- const result = stmt1.get(model.shortname);
129
- if (result?.id) {
130
- continue;
122
+ if (!existingModelShortNames.includes(model.shortname)) {
123
+ const insertStmt = db.prepare("INSERT INTO model (name, shortname, data) VALUES (?, ?, ?)");
124
+ insertStmt.run(model.name, model.shortname, JSON.stringify(model.data));
125
+ console.log("+", "[model]", model.name);
126
+ }
127
+ else {
128
+ const updateStmt = db.prepare("UPDATE model SET name = ?, data = ? WHERE shortname = ?");
129
+ updateStmt.run(model.name, JSON.stringify(model.data), model.shortname);
131
130
  }
132
- stmt.run(model.name, model.shortname, JSON.stringify(model.data));
131
+ }
132
+ for (const name of modelsToDelete) {
133
+ const deleteStmt = db.prepare("DELETE FROM model WHERE shortname = ?");
134
+ deleteStmt.run(name);
135
+ console.log("-", "[model]", name);
133
136
  }
134
137
  })();
135
138
  }
@@ -159,4 +162,19 @@ function updateFeatures(feats) {
159
162
  upsertAndCleanFeatures(feats.cmd, "cmd");
160
163
  upsertAndCleanFeatures(feats.modelfile, "modelfile");
161
164
  }
162
- export { updatePromptfilePath, updateDataDirPath, insertFeaturesPathIfNotExists, insertPluginIfNotExists, updateFeatures, updateAliases, cleanupFeaturePaths, upsertModels, };
165
+ function upsertFilePath(name, newPath) {
166
+ const selectStmt = db.prepare("SELECT * FROM filepath WHERE name = ?");
167
+ const result = selectStmt.get(name);
168
+ if (result?.id) {
169
+ const q = `UPDATE filepath SET path = ? WHERE name = ?`;
170
+ const stmt = db.prepare(q);
171
+ const updateResult = stmt.run(newPath, name);
172
+ return updateResult.changes > 0;
173
+ }
174
+ else {
175
+ const insertStmt = db.prepare("INSERT INTO filepath (name, path) VALUES (?, ?)");
176
+ insertStmt.run(name, newPath);
177
+ return true;
178
+ }
179
+ }
180
+ export { updatePromptfilePath, updateDataDirPath, insertFeaturesPathIfNotExists, insertPluginIfNotExists, updateFeatures, updateAliases, cleanupFeaturePaths, updateModels, upsertFilePath, };
@@ -0,0 +1,5 @@
1
+ declare function runtimeError(...msg: string[]): void;
2
+ declare function runtimeWarning(...msg: string[]): void;
3
+ declare function runtimeDataError(...msg: string[]): void;
4
+ declare function runtimeInfo(...msg: string[]): void;
5
+ export { runtimeError, runtimeWarning, runtimeDataError, runtimeInfo, };
@@ -0,0 +1,17 @@
1
+ import { exit } from "process";
2
+ import chalk from 'chalk';
3
+ function runtimeError(...msg) {
4
+ console.warn("💥", chalk.dim("Runtime error:"), ...msg);
5
+ exit(1);
6
+ }
7
+ function runtimeWarning(...msg) {
8
+ console.warn("⚠️", chalk.dim("Runtime warning:"), ...msg);
9
+ }
10
+ function runtimeDataError(...msg) {
11
+ console.warn("❌", chalk.dim("Runtime data error:"), ...msg);
12
+ exit(1);
13
+ }
14
+ function runtimeInfo(...msg) {
15
+ console.log("📫", chalk.dim("Info:"), ...msg);
16
+ }
17
+ export { runtimeError, runtimeWarning, runtimeDataError, runtimeInfo, };
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.61",
5
+ "version": "0.0.63",
6
6
  "scripts": {
7
7
  "buildrl": "rm -rf dist/* && rollup -c",
8
8
  "build": "rm -rf dist/* && tsc",
@@ -20,13 +20,14 @@
20
20
  "@wllama/wllama": "^2.3.1",
21
21
  "ansi-colors": "^4.1.3",
22
22
  "better-sqlite3": "^11.10.0",
23
+ "chalk": "^5.4.1",
23
24
  "clipboardy": "^4.0.0",
24
25
  "commander": "^13.1.0",
25
26
  "marked-terminal": "^7.3.0",
26
- "modprompt": "^0.11.6",
27
+ "modprompt": "^0.11.7",
28
+ "ora": "^8.2.0",
27
29
  "python-shell": "^5.0.0",
28
- "yaml": "^2.7.1",
29
- "ora": "^8.2.0"
30
+ "yaml": "^2.7.1"
30
31
  },
31
32
  "devDependencies": {
32
33
  "@agent-smith/tmem-jobs": "^0.0.4",