@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.
- package/dist/cmd/clicmds/base.js +1 -1
- package/dist/cmd/clicmds/cache.d.ts +4 -0
- package/dist/cmd/clicmds/cache.js +39 -0
- package/dist/cmd/clicmds/cmds.d.ts +1 -1
- package/dist/cmd/clicmds/cmds.js +25 -14
- package/dist/cmd/clicmds/{update.js → updateconf.js} +3 -1
- package/dist/cmd/lib/tasks/read.js +1 -1
- package/dist/cmd/sys/read.d.ts +2 -1
- package/dist/cmd/sys/read.js +12 -1
- package/dist/cmd/sys/read_cmds.d.ts +2 -2
- package/dist/cmd/sys/read_cmds.js +8 -27
- package/dist/conf.d.ts +2 -1
- package/dist/conf.js +2 -1
- package/dist/index.js +1 -1
- package/dist/state/auto/usercmds.d.ts +1 -0
- package/dist/state/auto/usercmds.js +9 -0
- package/dist/utils/perf.d.ts +3 -1
- package/dist/utils/perf.js +30 -5
- package/package.json +1 -1
- /package/dist/cmd/clicmds/{update.d.ts → updateconf.d.ts} +0 -0
package/dist/cmd/clicmds/base.js
CHANGED
|
@@ -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 "./
|
|
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,
|
|
8
|
+
export { initUserCmds, processTaskCmd, processTasksCmd, resetDbCmd, updateFeaturesCmd };
|
package/dist/cmd/clicmds/cmds.js
CHANGED
|
@@ -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
|
|
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 {
|
|
16
|
+
import { updateUserCmdsCache } from './cache.js';
|
|
13
17
|
async function initUserCmds(cmdFeats) {
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
|
|
21
|
-
cmds.push(...c);
|
|
22
|
-
paths.add(feat.path);
|
|
32
|
+
endCmds = usrCmds;
|
|
23
33
|
}
|
|
24
|
-
return
|
|
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,
|
|
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.
|
|
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();
|
package/dist/cmd/sys/read.d.ts
CHANGED
package/dist/cmd/sys/read.js
CHANGED
|
@@ -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
|
-
|
|
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
|
|
3
|
-
export {
|
|
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
|
|
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
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
9
|
+
cmds.push(cmd);
|
|
10
|
+
return cmd;
|
|
30
11
|
}
|
|
31
|
-
export {
|
|
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/
|
|
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 }
|
package/dist/utils/perf.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
declare const usePerfTimer: (startTimer?: boolean) => {
|
|
2
|
-
start: () =>
|
|
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 };
|
package/dist/utils/perf.js
CHANGED
|
@@ -1,15 +1,38 @@
|
|
|
1
1
|
const usePerfTimer = (startTimer = true) => {
|
|
2
|
-
let
|
|
2
|
+
let startTime;
|
|
3
|
+
const measurements = [];
|
|
4
|
+
let lastTime;
|
|
3
5
|
if (startTimer) {
|
|
4
|
-
|
|
6
|
+
startTime = performance.now();
|
|
7
|
+
lastTime = startTime;
|
|
5
8
|
}
|
|
6
|
-
const
|
|
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 (!
|
|
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 -
|
|
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.
|
|
5
|
+
"version": "0.0.100",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"buildrl": "rm -rf dist/* && rollup -c",
|
|
8
8
|
"build": "rm -rf dist/* && tsc",
|
|
File without changes
|