@agent-smith/cli 0.0.98 → 0.0.100

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.
@@ -2,7 +2,7 @@ import { Option } from "commander";
2
2
  import { listBackends, setBackend } from "../../state/backends.js";
3
3
  import { parseCommandArgs } from "../lib/options_parsers.js";
4
4
  import { processTaskCmd, processTasksCmd, resetDbCmd, updateFeaturesCmd } from "./cmds.js";
5
- import { updateConfCmd } from "./update.js";
5
+ import { updateConfCmd } from "./updateconf.js";
6
6
  import { inferenceOptions } from "../options.js";
7
7
  function initBaseCommands(program) {
8
8
  program.command("exit")
@@ -0,0 +1,4 @@
1
+ import { FeatureSpec } from '../../interfaces.js';
2
+ declare function ensureUserCmdsCacheFileExists(cacheFilePath: string): string;
3
+ declare function updateUserCmdsCache(cacheFilePath: string, cmdFeats: Array<FeatureSpec>): void;
4
+ export { ensureUserCmdsCacheFileExists, updateUserCmdsCache, };
@@ -0,0 +1,39 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import { runtimeError } from '../../utils/user_msgs.js';
4
+ function createCacheFileContent(cmdFeats) {
5
+ const imports = new Array();
6
+ const cmdNames = new Array();
7
+ let i = 1;
8
+ cmdFeats.forEach(feat => {
9
+ const fileName = feat.name + "." + feat.ext;
10
+ const importPath = path.join(feat.path, fileName);
11
+ const cmdId = `c${i}`;
12
+ const line = `import { cmd as ${cmdId} } from "file://${importPath}";`;
13
+ imports.push(line);
14
+ cmdNames.push(cmdId);
15
+ ++i;
16
+ });
17
+ const finalImports = imports.join("\n");
18
+ const cmds = `const cmds = [ ${cmdNames.join(", ")} ]`;
19
+ const end = "export { cmds }";
20
+ return `${finalImports}\n\n${cmds}\n\n${end}`;
21
+ }
22
+ function ensureUserCmdsCacheFileExists(cacheFilePath) {
23
+ const fileExists = fs.existsSync(cacheFilePath);
24
+ if (!fileExists) {
25
+ fs.writeFileSync(cacheFilePath, "const cmds = [];\nexport { cmds }");
26
+ }
27
+ return cacheFilePath;
28
+ }
29
+ function updateUserCmdsCache(cacheFilePath, cmdFeats) {
30
+ const filePath = ensureUserCmdsCacheFileExists(cacheFilePath);
31
+ const cacheFileContent = createCacheFileContent(cmdFeats);
32
+ try {
33
+ fs.writeFileSync(filePath, cacheFileContent);
34
+ }
35
+ catch (err) {
36
+ runtimeError("Error writing to user commands cache file at " + filePath, `${err}`);
37
+ }
38
+ }
39
+ export { ensureUserCmdsCacheFileExists, updateUserCmdsCache, };
@@ -5,4 +5,4 @@ declare function resetDbCmd(): Promise<any>;
5
5
  declare function updateFeaturesCmd(): Promise<any>;
6
6
  declare function processTasksCmd(args: Array<string>, options: Record<string, any>): Promise<void>;
7
7
  declare function processTaskCmd(args: Array<string>, options: Record<string, any>): Promise<any>;
8
- export { initUserCmds, resetDbCmd, updateFeaturesCmd, processTaskCmd, processTasksCmd, };
8
+ export { initUserCmds, processTaskCmd, processTasksCmd, resetDbCmd, updateFeaturesCmd };
@@ -1,27 +1,37 @@
1
- import { readCmds } from "../sys/read_cmds.js";
2
- import YAML from 'yaml';
3
1
  import colors from "ansi-colors";
4
- import { dbPath } from "../../conf.js";
2
+ import path from "path";
3
+ import { pathToFileURL } from 'url';
4
+ import YAML from 'yaml';
5
+ import { cacheFilePath, dbPath } from "../../conf.js";
5
6
  import { readFeaturePaths, readFeaturesType, readTaskSetting } from "../../db/read.js";
6
7
  import { cleanupFeaturePaths, deleteTaskSetting, updateAliases, updateFeatures, upsertTaskSettings } from "../../db/write.js";
7
8
  import { getFeatureSpec, readFeaturesDirs } from "../../state/features.js";
8
9
  import { readPluginsPaths } from "../../state/plugins.js";
9
10
  import { runMode } from "../../state/state.js";
11
+ import { initTaskSettings, isTaskSettingsInitialized, tasksSettings } from '../../state/tasks.js';
12
+ import { cmds } from "../../state/auto/usercmds.js";
10
13
  import { deleteFileIfExists } from "../sys/delete_file.js";
14
+ import { readCmd } from "../sys/read_cmds.js";
11
15
  import { readTask } from "../sys/read_task.js";
12
- import { isTaskSettingsInitialized, initTaskSettings, tasksSettings } from '../../state/tasks.js';
16
+ import { updateUserCmdsCache } from './cache.js';
13
17
  async function initUserCmds(cmdFeats) {
14
- const paths = new Set();
15
- const cmds = new Array();
16
- for (const feat of Object.values(cmdFeats)) {
17
- if (paths.has(feat.path)) {
18
- continue;
18
+ const features = Object.values(cmdFeats);
19
+ if (features.length == 0) {
20
+ return [];
21
+ }
22
+ let endCmds = cmds;
23
+ if (cmds.length == 0) {
24
+ updateUserCmdsCache(cacheFilePath, features);
25
+ const url = pathToFileURL(cacheFilePath).href;
26
+ const usrCmds = new Array();
27
+ for (const feat of features) {
28
+ const cmdPath = path.join(feat.path, feat.name + "." + feat.ext);
29
+ const c = await readCmd(feat.name, cmdPath);
30
+ usrCmds.push(c);
19
31
  }
20
- const c = await readCmds(`${feat.path}`);
21
- cmds.push(...c);
22
- paths.add(feat.path);
32
+ endCmds = usrCmds;
23
33
  }
24
- return cmds;
34
+ return endCmds;
25
35
  }
26
36
  async function resetDbCmd() {
27
37
  if (runMode.value == "cli") {
@@ -42,6 +52,7 @@ async function updateFeaturesCmd() {
42
52
  for (const el of deleted) {
43
53
  console.log("- [feature path]", el);
44
54
  }
55
+ updateUserCmdsCache(cacheFilePath, feats.cmd);
45
56
  }
46
57
  async function processTasksCmd(args, options) {
47
58
  if (options?.conf) {
@@ -92,4 +103,4 @@ async function processTaskCmd(args, options) {
92
103
  console.log(colors.dim("Settings") + ":", display);
93
104
  }
94
105
  }
95
- export { initUserCmds, resetDbCmd, updateFeaturesCmd, processTaskCmd, processTasksCmd, };
106
+ export { initUserCmds, processTaskCmd, processTasksCmd, resetDbCmd, updateFeaturesCmd };
@@ -1,10 +1,11 @@
1
- import { processConfPath } from "../../conf.js";
1
+ import { cacheFilePath, processConfPath } from "../../conf.js";
2
2
  import { initDb } from "../../db/db.js";
3
3
  import { readFilePath } from "../../db/read.js";
4
4
  import { cleanupFeaturePaths, updateAliases, updateDataDirPath, updateFeatures, updatePromptfilePath, upsertFilePath } from "../../db/write.js";
5
5
  import { readFeaturesDirs } from "../../state/features.js";
6
6
  import { dataDirPath, promptfilePath } from "../../state/state.js";
7
7
  import { runtimeDataError, runtimeInfo } from '../lib/user_msgs.js';
8
+ import { updateUserCmdsCache } from "./cache.js";
8
9
  async function updateConfCmd(args) {
9
10
  initDb(false, true);
10
11
  const { found, path } = readFilePath("conf");
@@ -40,5 +41,6 @@ async function updateConfCmd(args) {
40
41
  for (const el of deleted) {
41
42
  console.log("- [feature path]", el);
42
43
  }
44
+ updateUserCmdsCache(cacheFilePath, feats.cmd);
43
45
  }
44
46
  export { updateConfCmd, };
@@ -54,7 +54,7 @@ async function readTask(name, payload, options, agent) {
54
54
  }
55
55
  if (taskFileSpec?.mcp) {
56
56
  for (const [servername, tool] of Object.entries(taskFileSpec.mcp)) {
57
- const mcp = new McpClient(servername, tool.command, tool.args, tool?.tools ?? null);
57
+ const mcp = new McpClient(servername, tool.command, tool.arguments, tool?.tools ?? null);
58
58
  mcpServers.push(mcp);
59
59
  await mcp.start();
60
60
  const tools = await mcp.extractTools();
@@ -1,2 +1,3 @@
1
1
  declare function readFile(fp: string): string;
2
- export { readFile, };
2
+ declare function checkIfFileExists(filePath: string): Promise<boolean>;
3
+ export { readFile, checkIfFileExists, };
@@ -1,4 +1,6 @@
1
1
  import { default as fs } from "fs";
2
+ import { access, constants } from 'fs/promises';
3
+ import { resolve } from 'path';
2
4
  function readFile(fp) {
3
5
  try {
4
6
  return fs.readFileSync(fp, 'utf8');
@@ -7,4 +9,13 @@ function readFile(fp) {
7
9
  throw new Error(`reading file ${e}}`);
8
10
  }
9
11
  }
10
- export { readFile, };
12
+ async function checkIfFileExists(filePath) {
13
+ try {
14
+ await access(resolve(filePath), constants.F_OK);
15
+ return true;
16
+ }
17
+ catch {
18
+ return false;
19
+ }
20
+ }
21
+ export { readFile, checkIfFileExists, };
@@ -1,3 +1,3 @@
1
1
  import { Command } from "commander";
2
- declare function readCmds(dir: string): Promise<Array<Command>>;
3
- export { readCmds };
2
+ declare function readCmd(name: string, cmdPath: string): Promise<Command>;
3
+ export { readCmd };
@@ -1,31 +1,12 @@
1
- import { default as fs } from "fs";
2
- import { default as path } from "path";
3
1
  import { pathToFileURL } from 'url';
4
- function _readCmdsDir(dir) {
5
- const fileNames = new Array;
6
- fs.readdirSync(dir).forEach((filename) => {
7
- const filepath = path.join(dir, filename);
8
- const isDir = fs.statSync(filepath).isDirectory();
9
- if (!isDir) {
10
- if (filename.endsWith(".ts") || filename.endsWith(".js")) {
11
- const name = filename.replace(".js", "").replace(".ts", "");
12
- fileNames.push(name);
13
- }
14
- }
15
- });
16
- return fileNames;
17
- }
18
- async function readCmds(dir) {
2
+ async function readCmd(name, cmdPath) {
19
3
  const cmds = new Array();
20
- const fileNames = _readCmdsDir(dir);
21
- for (const name of fileNames) {
22
- const url = pathToFileURL(path.join(dir, name + ".js")).href;
23
- const { cmd } = await import(url);
24
- if (!cmd) {
25
- throw new Error(`command ${name} not found in ${dir}`);
26
- }
27
- cmds.push(cmd);
4
+ const url = pathToFileURL(cmdPath).href;
5
+ const { cmd } = await import(url);
6
+ if (!cmd) {
7
+ throw new Error(`command ${name} not found at ${cmdPath}`);
28
8
  }
29
- return cmds;
9
+ cmds.push(cmd);
10
+ return cmd;
30
11
  }
31
- export { readCmds };
12
+ export { readCmd };
package/dist/conf.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  declare const confDir: string, dbPath: string;
2
+ declare const cacheFilePath: string;
2
3
  declare function processConfPath(confPath: string): Promise<{
3
4
  paths: Array<string>;
4
5
  pf: string;
5
6
  dd: string;
6
7
  }>;
7
- export { confDir, dbPath, processConfPath, };
8
+ export { confDir, dbPath, cacheFilePath, processConfPath, };
package/dist/conf.js CHANGED
@@ -25,6 +25,7 @@ function getConfigPath(appName, filename) {
25
25
  return { confDir: confDir, dbPath: dbPath };
26
26
  }
27
27
  const { confDir, dbPath } = getConfigPath("agent-smith", "config.db");
28
+ const cacheFilePath = join(import.meta.dirname, "state/auto/usercmds.js");
28
29
  async function processConfPath(confPath) {
29
30
  createDirectoryIfNotExists(confDir);
30
31
  const { found, data } = readConf(confPath);
@@ -114,4 +115,4 @@ async function processConfPath(confPath) {
114
115
  }
115
116
  return { paths: allPaths, pf: pf, dd: dd };
116
117
  }
117
- export { confDir, dbPath, processConfPath, };
118
+ export { confDir, dbPath, cacheFilePath, processConfPath, };
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ import { argv } from 'process';
3
3
  import { query } from "./cli.js";
4
4
  import { buildCmds, parseCmd } from './cmd/cmds.js';
5
5
  import { formatMode, init, inputMode, isChatMode, outputMode, runMode } from './state/state.js';
6
- import { updateConfCmd } from './cmd/clicmds/update.js';
6
+ import { updateConfCmd } from './cmd/clicmds/updateconf.js';
7
7
  async function main() {
8
8
  const nargs = argv.length;
9
9
  if (nargs == 2) {
@@ -0,0 +1 @@
1
+ export const cmds: any[];
@@ -0,0 +1,9 @@
1
+ import { cmd as c1 } from "file:///home/ggg/dev/js/agent-smith-plugins/system/fs/dist/cmds/lsdir.js";
2
+ import { cmd as c2 } from "file:///home/ggg/dev/js/agent-smith-plugins/code/git/dist/cmds/commit.js";
3
+ import { cmd as c3 } from "file:///home/ggg/dev/js/agent-smith-plugins/code/git/dist/cmds/commita.js";
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,7 +1,9 @@
1
1
  declare const usePerfTimer: (startTimer?: boolean) => {
2
- start: () => number;
2
+ start: () => void;
3
3
  time: () => string;
4
4
  timeRaw: () => string | number;
5
5
  printTime: () => void;
6
+ measure: (name: string) => void;
7
+ final: (name?: string) => void;
6
8
  };
7
9
  export { usePerfTimer };
@@ -1,15 +1,38 @@
1
1
  const usePerfTimer = (startTimer = true) => {
2
- let _startTime;
2
+ let startTime;
3
+ const measurements = [];
4
+ let lastTime;
3
5
  if (startTimer) {
4
- _startTime = performance.now();
6
+ startTime = performance.now();
7
+ lastTime = startTime;
5
8
  }
6
- const start = () => _startTime = performance.now();
9
+ const measure = (name) => {
10
+ const currentTime = performance.now();
11
+ const elapsedNs = Number(currentTime - lastTime);
12
+ const elapsedSec = elapsedNs / 1000;
13
+ measurements.push({ name, time: elapsedSec, percentage: 0 });
14
+ lastTime = currentTime;
15
+ console.log(name, elapsedSec);
16
+ };
17
+ const final = (name = "") => {
18
+ const totalTime = Number(performance.now() - startTime) / 1000;
19
+ console.log("\n*** Performance", name.length > 0 ? `for ${name}` : "", " ***");
20
+ measurements.forEach(m => {
21
+ m.percentage = (m.time / totalTime) * 100;
22
+ console.log(` - ${m.name}: ${m.time.toFixed(6)}s (${m.percentage.toFixed(2)}%)`);
23
+ });
24
+ console.log(`Total time: ${totalTime.toFixed(6)}s\n`);
25
+ };
26
+ const start = () => {
27
+ startTime = performance.now();
28
+ lastTime = startTime;
29
+ };
7
30
  const _end = (raw) => {
8
- if (!_startTime) {
31
+ if (!startTime) {
9
32
  throw new Error("the timer has not started, can not end it");
10
33
  }
11
34
  const endTime = performance.now();
12
- const duration = endTime - _startTime;
35
+ const duration = endTime - startTime;
13
36
  if (raw) {
14
37
  return duration;
15
38
  }
@@ -33,6 +56,8 @@ const usePerfTimer = (startTimer = true) => {
33
56
  time,
34
57
  timeRaw,
35
58
  printTime,
59
+ measure,
60
+ final,
36
61
  };
37
62
  };
38
63
  export { usePerfTimer };
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.98",
5
+ "version": "0.0.100",
6
6
  "scripts": {
7
7
  "buildrl": "rm -rf dist/* && rollup -c",
8
8
  "build": "rm -rf dist/* && tsc",