@alejandroroman/agent-kit 0.2.1 → 0.2.2
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/cli/setup-agent/index.js +85 -108
- package/package.json +1 -1
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as readline from "readline";
|
|
2
1
|
import * as p from "@clack/prompts";
|
|
3
2
|
import { runAgentLoop } from "../../agent/loop.js";
|
|
4
3
|
import { ToolRegistry } from "../../tools/registry.js";
|
|
@@ -29,115 +28,93 @@ export async function runSetupAgent(opts) {
|
|
|
29
28
|
}
|
|
30
29
|
}
|
|
31
30
|
async function _runSetupAgent(opts, model) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
31
|
+
let finished = false;
|
|
32
|
+
let summary = "Setup cancelled.";
|
|
33
|
+
const spinner = p.spinner();
|
|
34
|
+
const toolRegistry = new ToolRegistry();
|
|
35
|
+
const tools = createSetupTools({
|
|
36
|
+
configPath: opts.configPath,
|
|
37
|
+
dataDir: opts.dataDir,
|
|
38
|
+
skillsDir: opts.skillsDir,
|
|
39
|
+
basePath: opts.basePath,
|
|
40
|
+
onFinish: (s) => {
|
|
41
|
+
finished = true;
|
|
42
|
+
summary = s;
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
for (const tool of tools) {
|
|
46
|
+
toolRegistry.register(tool);
|
|
47
|
+
}
|
|
48
|
+
const soul = opts.mode === "init" ? SETUP_SOUL : CREATE_SOUL;
|
|
49
|
+
const systemPrompt = [soul, dateContext()].join("\n\n");
|
|
50
|
+
const messages = [];
|
|
51
|
+
const onProgress = (phase, detail) => {
|
|
52
|
+
if (phase === "thinking") {
|
|
53
|
+
spinner.message("Thinking...");
|
|
48
54
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
try {
|
|
64
|
-
const result = await runAgentLoop(loopMessages, {
|
|
65
|
-
model,
|
|
66
|
-
systemPrompt,
|
|
67
|
-
toolRegistry,
|
|
68
|
-
maxIterations,
|
|
69
|
-
source: "cli",
|
|
70
|
-
onProgress,
|
|
71
|
-
});
|
|
72
|
-
spinner.stop("");
|
|
73
|
-
return result;
|
|
74
|
-
}
|
|
75
|
-
catch (err) {
|
|
76
|
-
spinner.stop("Error");
|
|
77
|
-
throw err;
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
const rl = readline.createInterface({
|
|
81
|
-
input: process.stdin,
|
|
82
|
-
output: process.stdout,
|
|
83
|
-
});
|
|
84
|
-
const cleanup = async () => {
|
|
85
|
-
rl.close();
|
|
86
|
-
process.stdin.pause();
|
|
87
|
-
await new Promise((r) => setTimeout(r, 200));
|
|
88
|
-
};
|
|
89
|
-
const ask = (prompt) => {
|
|
90
|
-
if (finished) {
|
|
91
|
-
cleanup();
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
rl.question(prompt ?? "You: ", async (input) => {
|
|
95
|
-
const trimmed = input.trim();
|
|
96
|
-
if (trimmed === "/quit" || trimmed === "/exit") {
|
|
97
|
-
await cleanup();
|
|
98
|
-
resolve("Setup cancelled.");
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
if (!trimmed) {
|
|
102
|
-
ask();
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
messages.push({ role: "user", content: trimmed });
|
|
106
|
-
try {
|
|
107
|
-
const result = await runWithSpinner(messages, 30);
|
|
108
|
-
messages.push(...result.messages.slice(messages.length));
|
|
109
|
-
if (!finished) {
|
|
110
|
-
console.log(`\n${result.text}\n`);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
catch (err) {
|
|
114
|
-
console.error(`\n Error: ${err instanceof Error ? err.message : err}\n`);
|
|
115
|
-
}
|
|
116
|
-
if (!finished) {
|
|
117
|
-
ask();
|
|
118
|
-
}
|
|
119
|
-
else {
|
|
120
|
-
await cleanup();
|
|
121
|
-
}
|
|
55
|
+
else if (phase === "tool_use") {
|
|
56
|
+
spinner.message(TOOL_LABELS[detail ?? ""] ?? "Working...");
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
const runWithSpinner = async (loopMessages, maxIterations) => {
|
|
60
|
+
spinner.start("Thinking...");
|
|
61
|
+
try {
|
|
62
|
+
const result = await runAgentLoop(loopMessages, {
|
|
63
|
+
model,
|
|
64
|
+
systemPrompt,
|
|
65
|
+
toolRegistry,
|
|
66
|
+
maxIterations,
|
|
67
|
+
source: "cli",
|
|
68
|
+
onProgress,
|
|
122
69
|
});
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
70
|
+
spinner.stop("");
|
|
71
|
+
return result;
|
|
72
|
+
}
|
|
73
|
+
catch (err) {
|
|
74
|
+
spinner.stop("Error");
|
|
75
|
+
throw err;
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
// Greeting
|
|
79
|
+
try {
|
|
80
|
+
const greeting = opts.mode === "init"
|
|
81
|
+
? "The user just ran `agent-kit init`. Greet them, then call check_environment to see what's available. After that, ask what kind of agent they'd like to create first."
|
|
82
|
+
: "The user wants to add a new agent to their existing setup. Greet them, call check_environment and list_available_skills to see the current state, then ask what kind of agent they'd like to create.";
|
|
83
|
+
messages.push({ role: "user", content: greeting });
|
|
84
|
+
const result = await runWithSpinner(messages, 10);
|
|
85
|
+
messages.push(...result.messages.slice(messages.length));
|
|
86
|
+
console.log(`\n${result.text}\n`);
|
|
87
|
+
}
|
|
88
|
+
catch (err) {
|
|
89
|
+
console.error(`\n Error starting setup agent: ${err instanceof Error ? err.message : err}\n`);
|
|
90
|
+
return summary;
|
|
91
|
+
}
|
|
92
|
+
// Conversation loop using clack prompts (no readline — avoids stdin conflict with spinner)
|
|
93
|
+
while (!finished) {
|
|
94
|
+
const input = await p.text({
|
|
95
|
+
message: "You",
|
|
96
|
+
placeholder: "Type your response... (/quit to exit)",
|
|
97
|
+
});
|
|
98
|
+
if (p.isCancel(input)) {
|
|
99
|
+
return "Setup cancelled.";
|
|
100
|
+
}
|
|
101
|
+
const trimmed = input.trim();
|
|
102
|
+
if (trimmed === "/quit" || trimmed === "/exit") {
|
|
103
|
+
return "Setup cancelled.";
|
|
104
|
+
}
|
|
105
|
+
if (!trimmed)
|
|
106
|
+
continue;
|
|
107
|
+
messages.push({ role: "user", content: trimmed });
|
|
108
|
+
try {
|
|
109
|
+
const result = await runWithSpinner(messages, 30);
|
|
110
|
+
messages.push(...result.messages.slice(messages.length));
|
|
138
111
|
if (!finished) {
|
|
139
|
-
|
|
112
|
+
console.log(`\n${result.text}\n`);
|
|
140
113
|
}
|
|
141
|
-
}
|
|
142
|
-
|
|
114
|
+
}
|
|
115
|
+
catch (err) {
|
|
116
|
+
console.error(`\n Error: ${err instanceof Error ? err.message : err}\n`);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return summary;
|
|
143
120
|
}
|