@agent-smith/cli 0.0.100 → 0.0.102

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.
@@ -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>>;
@@ -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>, quiet?: boolean): Promise<TaskOutput>;
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, quiet) {
16
+ async function executeTask(name, payload, options) {
17
17
  if (!isTaskSettingsInitialized.value) {
18
18
  initTaskSettings();
19
19
  }
@@ -37,7 +37,7 @@ async function executeTask(name, payload, options, quiet) {
37
37
  if (options?.debug || options?.backend) {
38
38
  console.log("Agent:", colors.bold(agent.lm.name), "( " + agent.lm.providerType + " backend type)");
39
39
  }
40
- const { task, model, conf, vars, mcpServers } = await readTask(name, payload, options, agent);
40
+ const { task, model, conf, vars, mcpServers, taskDir } = await readTask(name, payload, options, agent);
41
41
  if (hasSettings) {
42
42
  if (!model?.inferParams) {
43
43
  model.inferParams = {};
@@ -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);
@@ -191,6 +191,7 @@ async function executeTask(name, payload, options, quiet) {
191
191
  delete conf.model;
192
192
  }
193
193
  const tconf = {
194
+ baseDir: taskDir,
194
195
  model: model,
195
196
  onToolCall: onToolCall,
196
197
  onToolCallEnd: onToolCallEnd,
@@ -228,7 +229,7 @@ async function executeTask(name, payload, options, quiet) {
228
229
  }
229
230
  mcpServers.forEach(async (s) => await s.stop());
230
231
  await processOutput(out);
231
- if (isChatMode.value) {
232
+ if (!options?.isToolCall && isChatMode.value) {
232
233
  if (tpl) {
233
234
  setChatTemplate(tpl);
234
235
  }
@@ -1,11 +1,14 @@
1
1
  import { Agent } from "@agent-smith/agent";
2
- import { ModelSpec, Task, TaskConf } from "@agent-smith/task";
2
+ import { ModelSpec } from "@agent-smith/task";
3
+ import { NodeTask } from "@agent-smith/nodetask";
3
4
  import { McpClient } from "../mcp.js";
5
+ import type { LmTaskConfig } from "../../../interfaces.js";
4
6
  declare function readTask(name: string, payload: Record<string, any>, options: Record<string, any>, agent: Agent): Promise<{
5
- task: Task;
7
+ task: NodeTask;
6
8
  model: ModelSpec;
7
- conf: TaskConf;
9
+ conf: LmTaskConfig;
8
10
  vars: Record<string, any>;
9
11
  mcpServers: Array<McpClient>;
12
+ taskDir: string;
10
13
  }>;
11
14
  export { readTask };
@@ -1,4 +1,5 @@
1
- import { Task } from "@agent-smith/task";
1
+ import path from "path";
2
+ import { NodeTask } from "@agent-smith/nodetask";
2
3
  import { compile, serializeGrammar } from "@intrinsicai/gbnfgen";
3
4
  import { readTool } from "../../../db/read.js";
4
5
  import { executeAction } from "../actions/cmd.js";
@@ -8,13 +9,15 @@ import { executeWorkflow } from "../workflows/cmd.js";
8
9
  import { executeTask } from "./cmd.js";
9
10
  import { configureTaskModel, mergeInferParams } from "./conf.js";
10
11
  import { openTaskSpec } from "./utils.js";
12
+ import { confirmToolUsage } from "../tools.js";
11
13
  async function readTask(name, payload, options, agent) {
12
14
  if (options?.debug) {
13
15
  console.log("Task", name);
14
16
  console.log("Payload:", payload);
15
17
  console.log("Task options:", options);
16
18
  }
17
- const taskFileSpec = openTaskSpec(name);
19
+ const { taskFileSpec, taskPath } = openTaskSpec(name);
20
+ const taskDir = path.dirname(taskPath);
18
21
  const opts = payload?.inferParams ? { ...options, ...payload.inferParams } : options;
19
22
  const conf = parseTaskConfigOptions(opts);
20
23
  if (options?.debug) {
@@ -54,7 +57,19 @@ async function readTask(name, payload, options, agent) {
54
57
  }
55
58
  if (taskFileSpec?.mcp) {
56
59
  for (const [servername, tool] of Object.entries(taskFileSpec.mcp)) {
57
- const mcp = new McpClient(servername, tool.command, tool.arguments, tool?.tools ?? null);
60
+ const authorizedTools = new Array();
61
+ const askUserTools = new Array();
62
+ if (tool?.tools) {
63
+ tool.tools.forEach(t => {
64
+ let tn = t;
65
+ if (t.endsWith("?")) {
66
+ tn = t.slice(0, -1);
67
+ askUserTools.push(tn);
68
+ }
69
+ authorizedTools.push(tn);
70
+ });
71
+ }
72
+ const mcp = new McpClient(servername, tool.command, tool.arguments, authorizedTools.length > 0 ? authorizedTools : null, askUserTools.length > 0 ? askUserTools : null);
58
73
  mcpServers.push(mcp);
59
74
  await mcp.start();
60
75
  const tools = await mcp.extractTools();
@@ -62,21 +77,29 @@ async function readTask(name, payload, options, agent) {
62
77
  }
63
78
  }
64
79
  if (taskSpec.toolsList) {
65
- for (const toolName of taskSpec.toolsList) {
80
+ for (const rawToolName of taskSpec.toolsList) {
81
+ let toolName = rawToolName;
82
+ let autoRunTool = true;
83
+ if (rawToolName.endsWith("?")) {
84
+ autoRunTool = false;
85
+ toolName = rawToolName.slice(0, -1);
86
+ }
66
87
  const { found, tool, type } = readTool(toolName);
67
88
  if (!found) {
68
89
  throw new Error(`tool ${toolName} not found for task ${taskSpec.name}`);
69
90
  }
91
+ const quiet = !options?.debug;
70
92
  const lmTool = {
71
93
  ...tool,
72
94
  execute: async (params) => {
73
95
  switch (type) {
74
96
  case "action":
75
- const res = await executeAction(toolName, params, options, true);
97
+ const res = await executeAction(toolName, params, options, quiet);
76
98
  return res;
77
99
  case "task":
78
- conf.quiet = !options?.debug;
79
- const tres = await executeTask(name, params, options, true);
100
+ options.isToolCall = true;
101
+ const tres = await executeTask(toolName, params, options);
102
+ options.isToolCall = false;
80
103
  return tres.answer.text;
81
104
  case "workflow":
82
105
  const wres = await executeWorkflow(toolName, params, options);
@@ -86,17 +109,19 @@ async function readTask(name, payload, options, agent) {
86
109
  }
87
110
  }
88
111
  };
112
+ if (!autoRunTool) {
113
+ lmTool.canRun = confirmToolUsage;
114
+ }
89
115
  taskSpec.tools.push(lmTool);
90
116
  }
91
117
  delete taskSpec.toolsList;
92
118
  }
93
119
  ;
94
- const task = new Task(agent, taskSpec);
95
- task.addTools(taskSpec.tools);
120
+ const task = new NodeTask(agent, taskSpec);
96
121
  if (model?.inferParams?.tsGrammar) {
97
122
  model.inferParams.grammar = serializeGrammar(await compile(model.inferParams.tsGrammar, "Grammar"));
98
123
  delete model.inferParams.tsGrammar;
99
124
  }
100
- return { task, model, conf, vars, mcpServers };
125
+ return { task, model, conf, vars, mcpServers, taskDir };
101
126
  }
102
127
  export { readTask };
@@ -1,4 +1,7 @@
1
1
  import { LmTaskFileSpec } from "../../../interfaces.js";
2
- declare function openTaskSpec(name: string): LmTaskFileSpec;
2
+ declare function openTaskSpec(name: string): {
3
+ taskFileSpec: LmTaskFileSpec;
4
+ taskPath: string;
5
+ };
3
6
  declare function getTaskPrompt(name: string, args: Array<string>, options: Record<string, any>): Promise<string>;
4
- export { openTaskSpec, getTaskPrompt, };
7
+ export { getTaskPrompt, openTaskSpec };
@@ -1,9 +1,9 @@
1
1
  import YAML from 'yaml';
2
+ import { readClipboard } from '../../../cmd/sys/clipboard.js';
2
3
  import { readTask } from "../../../cmd/sys/read_task.js";
3
4
  import { getFeatureSpec } from "../../../state/features.js";
4
- import { readClipboard } from '../../../cmd/sys/clipboard.js';
5
- import { readPromptFile } from '../utils.js';
6
5
  import { runtimeDataError } from '../user_msgs.js';
6
+ import { readPromptFile } from '../utils.js';
7
7
  function openTaskSpec(name) {
8
8
  const { found, path } = getFeatureSpec(name, "task");
9
9
  if (!found) {
@@ -15,7 +15,7 @@ function openTaskSpec(name) {
15
15
  }
16
16
  const taskFileSpec = YAML.parse(res.ymlTask);
17
17
  taskFileSpec.name = name;
18
- return taskFileSpec;
18
+ return { taskFileSpec: taskFileSpec, taskPath: path };
19
19
  }
20
20
  async function getTaskPrompt(name, args, options) {
21
21
  let pr;
@@ -36,4 +36,4 @@ async function getTaskPrompt(name, args, options) {
36
36
  }
37
37
  return pr;
38
38
  }
39
- export { openTaskSpec, getTaskPrompt, };
39
+ export { getTaskPrompt, openTaskSpec };
@@ -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, };
@@ -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');
@@ -55,7 +66,7 @@ function _parseToolDoc(rawTxt, name) {
55
66
  return res;
56
67
  }
57
68
  catch (e) {
58
- throw new Error(`Error parsing tool ${name}: data:\n${rawTxt}\n`);
69
+ throw new Error(`Error parsing tool ${name}: ${e} \nData:\n${rawTxt}\n`);
59
70
  }
60
71
  }
61
72
  function _parseTaskVariables(data) {
@@ -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, true);
49
+ const tr = await executeTask(step.name, { prompt: pr }, options);
50
50
  taskRes = { ...tr, ...taskRes };
51
51
  }
52
52
  catch (e) {
@@ -1,9 +1,2 @@
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
+ const cmds = new Array();
2
+ export { cmds };
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.100",
5
+ "version": "0.0.102",
6
6
  "scripts": {
7
7
  "buildrl": "rm -rf dist/* && rollup -c",
8
8
  "build": "rm -rf dist/* && tsc",
@@ -10,8 +10,9 @@
10
10
  "watch": "tsc --noCheck -p . -w"
11
11
  },
12
12
  "dependencies": {
13
- "@agent-smith/agent": "^0.1.8",
14
- "@agent-smith/task": "^0.1.9",
13
+ "@agent-smith/agent": "^0.2.0",
14
+ "@agent-smith/task": "^0.2.1",
15
+ "@agent-smith/nodetask": "^0.1.0",
15
16
  "@agent-smith/tfm": "^0.2.0",
16
17
  "@inquirer/prompts": "^8.1.0",
17
18
  "@intrinsicai/gbnfgen": "0.12.0",
@@ -31,7 +32,7 @@
31
32
  "@agent-smith/tmem-jobs": "^0.0.4",
32
33
  "@cfworker/json-schema": "^4.1.1",
33
34
  "@commander-js/extra-typings": "^14.0.0",
34
- "@locallm/types": "^0.6.5",
35
+ "@locallm/types": "^0.6.7",
35
36
  "@rollup/plugin-node-resolve": "^16.0.3",
36
37
  "@rollup/plugin-typescript": "^12.3.0",
37
38
  "@types/better-sqlite3": "^7.6.13",