@agent-smith/cli 0.0.99 → 0.0.101
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/mcp.d.ts +2 -1
- package/dist/cmd/lib/mcp.js +11 -1
- package/dist/cmd/lib/tasks/cmd.d.ts +1 -1
- package/dist/cmd/lib/tasks/cmd.js +3 -3
- package/dist/cmd/lib/tasks/read.js +29 -6
- package/dist/cmd/lib/tools.d.ts +3 -1
- package/dist/cmd/lib/tools.js +12 -1
- package/dist/cmd/lib/workflows/cmd.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 +2 -0
- package/dist/utils/perf.d.ts +3 -1
- package/dist/utils/perf.js +30 -5
- package/package.json +4 -4
- /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, };
|
package/dist/cmd/lib/mcp.d.ts
CHANGED
|
@@ -6,8 +6,9 @@ declare class McpClient {
|
|
|
6
6
|
transport: StdioClientTransport;
|
|
7
7
|
client: Client;
|
|
8
8
|
authorizedTools: Array<string> | null;
|
|
9
|
+
askUserTools: Array<string> | null;
|
|
9
10
|
tools: Record<string, ToolSpec>;
|
|
10
|
-
constructor(servername: string, command: string, args: Array<string>, authorizedTools?: Array<string> | null);
|
|
11
|
+
constructor(servername: string, command: string, args: Array<string>, authorizedTools?: Array<string> | null, askUserTools?: Array<string> | null);
|
|
11
12
|
start(): Promise<void>;
|
|
12
13
|
stop(): Promise<void>;
|
|
13
14
|
extractTools(): Promise<Array<ToolSpec>>;
|
package/dist/cmd/lib/mcp.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
2
2
|
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
|
|
3
|
+
import { confirmToolUsage } from "./tools.js";
|
|
3
4
|
class McpClient {
|
|
4
5
|
name;
|
|
5
6
|
transport;
|
|
6
7
|
client;
|
|
7
8
|
authorizedTools = null;
|
|
9
|
+
askUserTools = null;
|
|
8
10
|
tools = {};
|
|
9
|
-
constructor(servername, command, args, authorizedTools = null) {
|
|
11
|
+
constructor(servername, command, args, authorizedTools = null, askUserTools = null) {
|
|
10
12
|
this.name = servername;
|
|
11
13
|
const okargs = new Array();
|
|
12
14
|
for (const arg of args) {
|
|
@@ -29,6 +31,9 @@ class McpClient {
|
|
|
29
31
|
if (authorizedTools) {
|
|
30
32
|
this.authorizedTools = authorizedTools;
|
|
31
33
|
}
|
|
34
|
+
if (askUserTools) {
|
|
35
|
+
this.askUserTools = askUserTools;
|
|
36
|
+
}
|
|
32
37
|
}
|
|
33
38
|
async start() {
|
|
34
39
|
await this.client.connect(this.transport);
|
|
@@ -66,6 +71,11 @@ class McpClient {
|
|
|
66
71
|
arguments: args,
|
|
67
72
|
execute: exec
|
|
68
73
|
};
|
|
74
|
+
if (this.askUserTools) {
|
|
75
|
+
if (this.askUserTools.includes(tool.name)) {
|
|
76
|
+
t.canRun = confirmToolUsage;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
69
79
|
this.tools[tool.name] = t;
|
|
70
80
|
toolSpecs.push(t);
|
|
71
81
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { TaskOutput } from "@agent-smith/task";
|
|
2
|
-
declare function executeTask(name: string, payload: Record<string, any>, options: Record<string, any
|
|
2
|
+
declare function executeTask(name: string, payload: Record<string, any>, options: Record<string, any>): Promise<TaskOutput>;
|
|
3
3
|
declare function executeTaskCmd(name: string, targs?: Array<any>): Promise<TaskOutput>;
|
|
4
4
|
export { executeTask, executeTaskCmd };
|
|
@@ -13,7 +13,7 @@ import { runtimeDataError, runtimeError, runtimeWarning } from "../user_msgs.js"
|
|
|
13
13
|
import { formatStats, processOutput } from "../utils.js";
|
|
14
14
|
import { readTask } from "./read.js";
|
|
15
15
|
import { getTaskPrompt } from "./utils.js";
|
|
16
|
-
async function executeTask(name, payload, options
|
|
16
|
+
async function executeTask(name, payload, options) {
|
|
17
17
|
if (!isTaskSettingsInitialized.value) {
|
|
18
18
|
initTaskSettings();
|
|
19
19
|
}
|
|
@@ -167,7 +167,7 @@ async function executeTask(name, payload, options, quiet) {
|
|
|
167
167
|
}
|
|
168
168
|
++i;
|
|
169
169
|
};
|
|
170
|
-
const spinnerInit = (name) => ora(`Executing ${name} tool
|
|
170
|
+
const spinnerInit = (name) => ora(`Executing ${name} tool ...\n`);
|
|
171
171
|
let tcspinner;
|
|
172
172
|
const onToolCall = (tc) => {
|
|
173
173
|
console.log("⚒️ ", color.bold(name), "=>", `${color.yellowBright(tc.name)}`, tc.arguments);
|
|
@@ -228,7 +228,7 @@ async function executeTask(name, payload, options, quiet) {
|
|
|
228
228
|
}
|
|
229
229
|
mcpServers.forEach(async (s) => await s.stop());
|
|
230
230
|
await processOutput(out);
|
|
231
|
-
if (isChatMode.value) {
|
|
231
|
+
if (!options?.isToolCall && isChatMode.value) {
|
|
232
232
|
if (tpl) {
|
|
233
233
|
setChatTemplate(tpl);
|
|
234
234
|
}
|
|
@@ -8,6 +8,7 @@ import { executeWorkflow } from "../workflows/cmd.js";
|
|
|
8
8
|
import { executeTask } from "./cmd.js";
|
|
9
9
|
import { configureTaskModel, mergeInferParams } from "./conf.js";
|
|
10
10
|
import { openTaskSpec } from "./utils.js";
|
|
11
|
+
import { confirmToolUsage } from "../tools.js";
|
|
11
12
|
async function readTask(name, payload, options, agent) {
|
|
12
13
|
if (options?.debug) {
|
|
13
14
|
console.log("Task", name);
|
|
@@ -54,7 +55,19 @@ async function readTask(name, payload, options, agent) {
|
|
|
54
55
|
}
|
|
55
56
|
if (taskFileSpec?.mcp) {
|
|
56
57
|
for (const [servername, tool] of Object.entries(taskFileSpec.mcp)) {
|
|
57
|
-
const
|
|
58
|
+
const authorizedTools = new Array();
|
|
59
|
+
const askUserTools = new Array();
|
|
60
|
+
if (tool?.tools) {
|
|
61
|
+
tool.tools.forEach(t => {
|
|
62
|
+
let tn = t;
|
|
63
|
+
if (t.endsWith("?")) {
|
|
64
|
+
tn = t.slice(0, -1);
|
|
65
|
+
askUserTools.push(tn);
|
|
66
|
+
}
|
|
67
|
+
authorizedTools.push(tn);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
const mcp = new McpClient(servername, tool.command, tool.arguments, authorizedTools.length > 0 ? authorizedTools : null, askUserTools.length > 0 ? askUserTools : null);
|
|
58
71
|
mcpServers.push(mcp);
|
|
59
72
|
await mcp.start();
|
|
60
73
|
const tools = await mcp.extractTools();
|
|
@@ -62,21 +75,29 @@ async function readTask(name, payload, options, agent) {
|
|
|
62
75
|
}
|
|
63
76
|
}
|
|
64
77
|
if (taskSpec.toolsList) {
|
|
65
|
-
for (const
|
|
78
|
+
for (const rawToolName of taskSpec.toolsList) {
|
|
79
|
+
let toolName = rawToolName;
|
|
80
|
+
let autoRunTool = true;
|
|
81
|
+
if (rawToolName.endsWith("?")) {
|
|
82
|
+
autoRunTool = false;
|
|
83
|
+
toolName = rawToolName.slice(0, -1);
|
|
84
|
+
}
|
|
66
85
|
const { found, tool, type } = readTool(toolName);
|
|
67
86
|
if (!found) {
|
|
68
87
|
throw new Error(`tool ${toolName} not found for task ${taskSpec.name}`);
|
|
69
88
|
}
|
|
89
|
+
const quiet = !options?.debug;
|
|
70
90
|
const lmTool = {
|
|
71
91
|
...tool,
|
|
72
92
|
execute: async (params) => {
|
|
73
93
|
switch (type) {
|
|
74
94
|
case "action":
|
|
75
|
-
const res = await executeAction(toolName, params, options,
|
|
95
|
+
const res = await executeAction(toolName, params, options, quiet);
|
|
76
96
|
return res;
|
|
77
97
|
case "task":
|
|
78
|
-
|
|
79
|
-
const tres = await executeTask(
|
|
98
|
+
options.isToolCall = true;
|
|
99
|
+
const tres = await executeTask(toolName, params, options);
|
|
100
|
+
options.isToolCall = false;
|
|
80
101
|
return tres.answer.text;
|
|
81
102
|
case "workflow":
|
|
82
103
|
const wres = await executeWorkflow(toolName, params, options);
|
|
@@ -86,13 +107,15 @@ async function readTask(name, payload, options, agent) {
|
|
|
86
107
|
}
|
|
87
108
|
}
|
|
88
109
|
};
|
|
110
|
+
if (!autoRunTool) {
|
|
111
|
+
lmTool.canRun = confirmToolUsage;
|
|
112
|
+
}
|
|
89
113
|
taskSpec.tools.push(lmTool);
|
|
90
114
|
}
|
|
91
115
|
delete taskSpec.toolsList;
|
|
92
116
|
}
|
|
93
117
|
;
|
|
94
118
|
const task = new Task(agent, taskSpec);
|
|
95
|
-
task.addTools(taskSpec.tools);
|
|
96
119
|
if (model?.inferParams?.tsGrammar) {
|
|
97
120
|
model.inferParams.grammar = serializeGrammar(await compile(model.inferParams.tsGrammar, "Grammar"));
|
|
98
121
|
delete model.inferParams.tsGrammar;
|
package/dist/cmd/lib/tools.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { FeatureExtension } from '../../interfaces.js';
|
|
2
|
+
import { type ToolCallSpec } from '@locallm/types';
|
|
3
|
+
declare function confirmToolUsage(toolCall: ToolCallSpec): Promise<boolean>;
|
|
2
4
|
declare function extractTaskToolDocAndVariables(name: string, ext: FeatureExtension, dirPath: string): {
|
|
3
5
|
toolDoc: string;
|
|
4
6
|
variables: {
|
|
@@ -10,4 +12,4 @@ declare function extractToolDoc(name: string, ext: FeatureExtension, dirPath: st
|
|
|
10
12
|
found: boolean;
|
|
11
13
|
toolDoc: string;
|
|
12
14
|
};
|
|
13
|
-
export { extractToolDoc, extractTaskToolDocAndVariables, };
|
|
15
|
+
export { extractToolDoc, extractTaskToolDocAndVariables, confirmToolUsage, };
|
package/dist/cmd/lib/tools.js
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
import YAML from 'yaml';
|
|
2
2
|
import * as fs from 'fs';
|
|
3
3
|
import { readYmlFile } from '../sys/read_yml_file.js';
|
|
4
|
+
import { confirm } from '@inquirer/prompts';
|
|
5
|
+
async function confirmToolUsage(toolCall) {
|
|
6
|
+
let args;
|
|
7
|
+
if (toolCall?.arguments) {
|
|
8
|
+
args = `with arguments ${JSON.stringify(toolCall.arguments)}`;
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
args = "with no arguments";
|
|
12
|
+
}
|
|
13
|
+
return await confirm({ message: `Execute tool ${toolCall.name} ${args}?` });
|
|
14
|
+
}
|
|
4
15
|
function _extractToolDoc(filePath, startComment, endComment) {
|
|
5
16
|
try {
|
|
6
17
|
const fileContent = fs.readFileSync(filePath, 'utf-8');
|
|
@@ -127,4 +138,4 @@ function extractToolDoc(name, ext, dirPath) {
|
|
|
127
138
|
}
|
|
128
139
|
return { found: true, toolDoc: spec };
|
|
129
140
|
}
|
|
130
|
-
export { extractToolDoc, extractTaskToolDocAndVariables, };
|
|
141
|
+
export { extractToolDoc, extractTaskToolDocAndVariables, confirmToolUsage, };
|
|
@@ -46,7 +46,7 @@ async function executeWorkflow(wname, args, options = {}) {
|
|
|
46
46
|
if (!pr) {
|
|
47
47
|
throw new Error(`Workflow ${wname} step ${i + 1}: provide a prompt for the task ${step.name}`);
|
|
48
48
|
}
|
|
49
|
-
const tr = await executeTask(step.name, { prompt: pr }, options
|
|
49
|
+
const tr = await executeTask(step.name, { prompt: pr }, options);
|
|
50
50
|
taskRes = { ...tr, ...taskRes };
|
|
51
51
|
}
|
|
52
52
|
catch (e) {
|
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[];
|
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.101",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"buildrl": "rm -rf dist/* && rollup -c",
|
|
8
8
|
"build": "rm -rf dist/* && tsc",
|
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
"watch": "tsc --noCheck -p . -w"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@agent-smith/agent": "^0.
|
|
14
|
-
"@agent-smith/task": "^0.
|
|
13
|
+
"@agent-smith/agent": "^0.2.0",
|
|
14
|
+
"@agent-smith/task": "^0.2.0",
|
|
15
15
|
"@agent-smith/tfm": "^0.2.0",
|
|
16
16
|
"@inquirer/prompts": "^8.1.0",
|
|
17
17
|
"@intrinsicai/gbnfgen": "0.12.0",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"@agent-smith/tmem-jobs": "^0.0.4",
|
|
32
32
|
"@cfworker/json-schema": "^4.1.1",
|
|
33
33
|
"@commander-js/extra-typings": "^14.0.0",
|
|
34
|
-
"@locallm/types": "^0.6.
|
|
34
|
+
"@locallm/types": "^0.6.7",
|
|
35
35
|
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
36
36
|
"@rollup/plugin-typescript": "^12.3.0",
|
|
37
37
|
"@types/better-sqlite3": "^7.6.13",
|
|
File without changes
|