botholomew 0.7.7 → 0.7.9
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/README.md +2 -0
- package/package.json +1 -1
- package/src/chat/agent.ts +68 -35
- package/src/chat/session.ts +27 -31
- package/src/commands/context.ts +334 -32
- package/src/commands/daemon.ts +15 -2
- package/src/commands/schedule.ts +10 -1
- package/src/commands/skill.ts +18 -3
- package/src/commands/task.ts +28 -4
- package/src/commands/thread.ts +3 -1
- package/src/commands/tools.ts +2 -0
- package/src/commands/with-db.ts +8 -9
- package/src/context/describer.ts +111 -2
- package/src/context/fetcher.ts +1 -0
- package/src/context/ingest.ts +3 -1
- package/src/daemon/index.ts +6 -5
- package/src/daemon/llm.ts +68 -42
- package/src/daemon/prompt.ts +6 -4
- package/src/daemon/schedules.ts +15 -10
- package/src/daemon/tick.ts +55 -39
- package/src/db/connection.ts +143 -14
- package/src/db/context.ts +33 -0
- package/src/db/schedules.ts +7 -3
- package/src/db/tasks.ts +6 -6
- package/src/db/threads.ts +6 -4
- package/src/tools/file/write.ts +52 -13
- package/src/tools/tool.ts +8 -0
- package/src/tui/App.tsx +16 -11
- package/src/tui/components/ContextPanel.tsx +19 -15
- package/src/tui/components/SchedulePanel.tsx +15 -9
- package/src/tui/components/StatusBar.tsx +8 -6
- package/src/tui/components/TaskPanel.tsx +6 -6
- package/src/tui/components/ThreadPanel.tsx +29 -19
- package/src/utils/title.ts +5 -3
package/README.md
CHANGED
|
@@ -128,6 +128,8 @@ Everything the agent can touch is here. No surprises.
|
|
|
128
128
|
| `botholomew nuke context\|tasks\|schedules\|threads\|all` | Bulk-erase sections of the database |
|
|
129
129
|
| `botholomew upgrade` | Self-update |
|
|
130
130
|
|
|
131
|
+
All `list` subcommands support `-l, --limit <n>` and `-o, --offset <n>` for pagination.
|
|
132
|
+
|
|
131
133
|
---
|
|
132
134
|
|
|
133
135
|
## How it works
|
package/package.json
CHANGED
package/src/chat/agent.ts
CHANGED
|
@@ -4,6 +4,7 @@ import type {
|
|
|
4
4
|
ToolResultBlockParam,
|
|
5
5
|
ToolUseBlock,
|
|
6
6
|
} from "@anthropic-ai/sdk/resources/messages";
|
|
7
|
+
import type { McpxClient } from "@evantahler/mcpx";
|
|
7
8
|
import type { BotholomewConfig } from "../config/schemas.ts";
|
|
8
9
|
import { embedSingle } from "../context/embedder.ts";
|
|
9
10
|
import { fitToContextWindow, getMaxInputTokens } from "../daemon/context.ts";
|
|
@@ -13,7 +14,7 @@ import {
|
|
|
13
14
|
extractKeywords,
|
|
14
15
|
loadPersistentContext,
|
|
15
16
|
} from "../daemon/prompt.ts";
|
|
16
|
-
import
|
|
17
|
+
import { withDb } from "../db/connection.ts";
|
|
17
18
|
import { hybridSearch } from "../db/embeddings.ts";
|
|
18
19
|
import { logInteraction } from "../db/threads.ts";
|
|
19
20
|
import { registerAllTools } from "../tools/registry.ts";
|
|
@@ -60,7 +61,7 @@ export async function buildChatSystemPrompt(
|
|
|
60
61
|
projectDir: string,
|
|
61
62
|
options?: {
|
|
62
63
|
keywordSource?: string;
|
|
63
|
-
|
|
64
|
+
dbPath?: string;
|
|
64
65
|
config?: Required<BotholomewConfig>;
|
|
65
66
|
},
|
|
66
67
|
): Promise<string> {
|
|
@@ -74,12 +75,14 @@ export async function buildChatSystemPrompt(
|
|
|
74
75
|
parts.push(...(await loadPersistentContext(projectDir, taskKeywords)));
|
|
75
76
|
|
|
76
77
|
// Relevant context from embeddings search
|
|
77
|
-
const
|
|
78
|
+
const dbPath = options?.dbPath;
|
|
78
79
|
const config = options?.config;
|
|
79
|
-
if (
|
|
80
|
+
if (dbPath && config?.openai_api_key && keywordSource) {
|
|
80
81
|
try {
|
|
81
82
|
const queryVec = await embedSingle(keywordSource, config);
|
|
82
|
-
const results = await
|
|
83
|
+
const results = await withDb(dbPath, (conn) =>
|
|
84
|
+
hybridSearch(conn, keywordSource, queryVec, 5),
|
|
85
|
+
);
|
|
83
86
|
|
|
84
87
|
if (results.length > 0) {
|
|
85
88
|
parts.push("## Relevant Context");
|
|
@@ -160,13 +163,20 @@ export async function runChatTurn(input: {
|
|
|
160
163
|
messages: MessageParam[];
|
|
161
164
|
projectDir: string;
|
|
162
165
|
config: Required<BotholomewConfig>;
|
|
163
|
-
|
|
166
|
+
dbPath: string;
|
|
164
167
|
threadId: string;
|
|
165
|
-
|
|
168
|
+
mcpxClient: McpxClient | null;
|
|
166
169
|
callbacks: ChatTurnCallbacks;
|
|
167
170
|
}): Promise<void> {
|
|
168
|
-
const {
|
|
169
|
-
|
|
171
|
+
const {
|
|
172
|
+
messages,
|
|
173
|
+
projectDir,
|
|
174
|
+
config,
|
|
175
|
+
dbPath,
|
|
176
|
+
threadId,
|
|
177
|
+
mcpxClient,
|
|
178
|
+
callbacks,
|
|
179
|
+
} = input;
|
|
170
180
|
|
|
171
181
|
const client = new Anthropic({
|
|
172
182
|
apiKey: config.anthropic_api_key || undefined,
|
|
@@ -190,7 +200,7 @@ export async function runChatTurn(input: {
|
|
|
190
200
|
const keywordSource = findLastUserText(messages);
|
|
191
201
|
const systemPrompt = await buildChatSystemPrompt(projectDir, {
|
|
192
202
|
keywordSource,
|
|
193
|
-
|
|
203
|
+
dbPath,
|
|
194
204
|
config,
|
|
195
205
|
});
|
|
196
206
|
|
|
@@ -230,13 +240,15 @@ export async function runChatTurn(input: {
|
|
|
230
240
|
|
|
231
241
|
// Log assistant text
|
|
232
242
|
if (assistantText) {
|
|
233
|
-
await
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
243
|
+
await withDb(dbPath, (conn) =>
|
|
244
|
+
logInteraction(conn, threadId, {
|
|
245
|
+
role: "assistant",
|
|
246
|
+
kind: "message",
|
|
247
|
+
content: assistantText,
|
|
248
|
+
durationMs,
|
|
249
|
+
tokenCount,
|
|
250
|
+
}),
|
|
251
|
+
);
|
|
240
252
|
}
|
|
241
253
|
|
|
242
254
|
// Check for tool calls
|
|
@@ -260,20 +272,29 @@ export async function runChatTurn(input: {
|
|
|
260
272
|
callbacks.onToolStart(toolUse.id, toolUse.name, toolInput);
|
|
261
273
|
}
|
|
262
274
|
|
|
263
|
-
await
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
275
|
+
await withDb(dbPath, (conn) =>
|
|
276
|
+
logInteraction(conn, threadId, {
|
|
277
|
+
role: "assistant",
|
|
278
|
+
kind: "tool_use",
|
|
279
|
+
content: `Calling ${toolUse.name}`,
|
|
280
|
+
toolName: toolUse.name,
|
|
281
|
+
toolInput,
|
|
282
|
+
}),
|
|
283
|
+
);
|
|
270
284
|
}
|
|
271
285
|
|
|
272
|
-
// Execute all tools in parallel
|
|
286
|
+
// Execute all tools in parallel. Each tool call opens its own short-lived
|
|
287
|
+
// connection; parallel calls share the process-local DuckDB instance and
|
|
288
|
+
// release the file lock as soon as the last one finishes.
|
|
273
289
|
const execResults = await Promise.all(
|
|
274
290
|
toolUseBlocks.map(async (toolUse) => {
|
|
275
291
|
const start = Date.now();
|
|
276
|
-
const result = await executeChatToolCall(toolUse,
|
|
292
|
+
const result = await executeChatToolCall(toolUse, {
|
|
293
|
+
dbPath,
|
|
294
|
+
projectDir,
|
|
295
|
+
config,
|
|
296
|
+
mcpxClient,
|
|
297
|
+
});
|
|
277
298
|
const durationMs = Date.now() - start;
|
|
278
299
|
const stored = maybeStoreResult(toolUse.name, result.output);
|
|
279
300
|
const meta: ToolEndMeta | undefined = stored.stored
|
|
@@ -293,13 +314,15 @@ export async function runChatTurn(input: {
|
|
|
293
314
|
// Log results and collect tool_result messages
|
|
294
315
|
const toolResults: ToolResultBlockParam[] = [];
|
|
295
316
|
for (const { toolUse, result, durationMs, stored } of execResults) {
|
|
296
|
-
await
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
317
|
+
await withDb(dbPath, (conn) =>
|
|
318
|
+
logInteraction(conn, threadId, {
|
|
319
|
+
role: "tool",
|
|
320
|
+
kind: "tool_result",
|
|
321
|
+
content: result.output,
|
|
322
|
+
toolName: toolUse.name,
|
|
323
|
+
durationMs,
|
|
324
|
+
}),
|
|
325
|
+
);
|
|
303
326
|
|
|
304
327
|
toolResults.push({
|
|
305
328
|
type: "tool_result",
|
|
@@ -314,9 +337,16 @@ export async function runChatTurn(input: {
|
|
|
314
337
|
}
|
|
315
338
|
}
|
|
316
339
|
|
|
340
|
+
interface ChatToolCallCtx {
|
|
341
|
+
dbPath: string;
|
|
342
|
+
projectDir: string;
|
|
343
|
+
config: Required<BotholomewConfig>;
|
|
344
|
+
mcpxClient: McpxClient | null;
|
|
345
|
+
}
|
|
346
|
+
|
|
317
347
|
async function executeChatToolCall(
|
|
318
348
|
toolUse: ToolUseBlock,
|
|
319
|
-
|
|
349
|
+
baseCtx: ChatToolCallCtx,
|
|
320
350
|
): Promise<{ output: string; isError: boolean }> {
|
|
321
351
|
const tool = getTool(toolUse.name);
|
|
322
352
|
if (!tool) return { output: `Unknown tool: ${toolUse.name}`, isError: true };
|
|
@@ -335,7 +365,10 @@ async function executeChatToolCall(
|
|
|
335
365
|
}
|
|
336
366
|
|
|
337
367
|
try {
|
|
338
|
-
const result = await
|
|
368
|
+
const result = await withDb(baseCtx.dbPath, (conn) => {
|
|
369
|
+
const ctx: ToolContext = { ...baseCtx, conn };
|
|
370
|
+
return tool.execute(parsed.data, ctx);
|
|
371
|
+
});
|
|
339
372
|
const isError =
|
|
340
373
|
typeof result === "object" && result !== null && "is_error" in result
|
|
341
374
|
? (result as { is_error: boolean }).is_error
|
package/src/chat/session.ts
CHANGED
|
@@ -2,8 +2,7 @@ import type { MessageParam } from "@anthropic-ai/sdk/resources/messages";
|
|
|
2
2
|
import { loadConfig } from "../config/loader.ts";
|
|
3
3
|
import type { BotholomewConfig } from "../config/schemas.ts";
|
|
4
4
|
import { getDbPath } from "../constants.ts";
|
|
5
|
-
import
|
|
6
|
-
import { getConnection } from "../db/connection.ts";
|
|
5
|
+
import { withDb } from "../db/connection.ts";
|
|
7
6
|
import { migrate } from "../db/schema.ts";
|
|
8
7
|
import {
|
|
9
8
|
createThread,
|
|
@@ -15,18 +14,18 @@ import {
|
|
|
15
14
|
import { createMcpxClient } from "../mcpx/client.ts";
|
|
16
15
|
import { loadSkills } from "../skills/loader.ts";
|
|
17
16
|
import type { SkillDefinition } from "../skills/parser.ts";
|
|
18
|
-
import type { ToolContext } from "../tools/tool.ts";
|
|
19
17
|
import { generateThreadTitle } from "../utils/title.ts";
|
|
20
18
|
import { type ChatTurnCallbacks, runChatTurn } from "./agent.ts";
|
|
21
19
|
|
|
22
20
|
export interface ChatSession {
|
|
23
|
-
|
|
21
|
+
dbPath: string;
|
|
24
22
|
threadId: string;
|
|
25
23
|
projectDir: string;
|
|
26
24
|
config: Required<BotholomewConfig>;
|
|
27
25
|
messages: MessageParam[];
|
|
28
|
-
toolCtx: ToolContext;
|
|
29
26
|
skills: Map<string, SkillDefinition>;
|
|
27
|
+
// biome-ignore lint/suspicious/noExplicitAny: mcpx client
|
|
28
|
+
mcpxClient: any;
|
|
30
29
|
cleanup: () => Promise<void>;
|
|
31
30
|
}
|
|
32
31
|
|
|
@@ -42,21 +41,22 @@ export async function startChatSession(
|
|
|
42
41
|
);
|
|
43
42
|
}
|
|
44
43
|
|
|
45
|
-
const
|
|
46
|
-
await migrate(conn);
|
|
44
|
+
const dbPath = getDbPath(projectDir);
|
|
45
|
+
await withDb(dbPath, (conn) => migrate(conn));
|
|
47
46
|
|
|
48
47
|
let threadId: string;
|
|
49
48
|
const messages: MessageParam[] = [];
|
|
50
49
|
|
|
51
50
|
if (existingThreadId) {
|
|
52
51
|
// Resume existing thread
|
|
53
|
-
const result = await
|
|
52
|
+
const result = await withDb(dbPath, (conn) =>
|
|
53
|
+
getThread(conn, existingThreadId),
|
|
54
|
+
);
|
|
54
55
|
if (!result) {
|
|
55
|
-
conn.close();
|
|
56
56
|
throw new Error(`Thread not found: ${existingThreadId}`);
|
|
57
57
|
}
|
|
58
58
|
threadId = existingThreadId;
|
|
59
|
-
await reopenThread(conn, threadId);
|
|
59
|
+
await withDb(dbPath, (conn) => reopenThread(conn, threadId));
|
|
60
60
|
|
|
61
61
|
// Rebuild message history from interactions
|
|
62
62
|
let firstUserMessage: string | undefined;
|
|
@@ -72,34 +72,29 @@ export async function startChatSession(
|
|
|
72
72
|
|
|
73
73
|
// Backfill title for threads that still have the default
|
|
74
74
|
if (result.thread.title === "New chat" && firstUserMessage) {
|
|
75
|
-
void generateThreadTitle(config,
|
|
75
|
+
void generateThreadTitle(config, dbPath, threadId, firstUserMessage);
|
|
76
76
|
}
|
|
77
77
|
} else {
|
|
78
|
-
threadId = await
|
|
78
|
+
threadId = await withDb(dbPath, (conn) =>
|
|
79
|
+
createThread(conn, "chat_session", undefined, "New chat"),
|
|
80
|
+
);
|
|
79
81
|
}
|
|
80
82
|
|
|
81
83
|
const mcpxClient = await createMcpxClient(projectDir);
|
|
82
84
|
const skills = await loadSkills(projectDir);
|
|
83
85
|
|
|
84
|
-
const toolCtx: ToolContext = {
|
|
85
|
-
conn,
|
|
86
|
-
projectDir,
|
|
87
|
-
config,
|
|
88
|
-
mcpxClient,
|
|
89
|
-
};
|
|
90
|
-
|
|
91
86
|
const cleanup = async () => {
|
|
92
87
|
await mcpxClient?.close();
|
|
93
88
|
};
|
|
94
89
|
|
|
95
90
|
return {
|
|
96
|
-
|
|
91
|
+
dbPath,
|
|
97
92
|
threadId,
|
|
98
93
|
projectDir,
|
|
99
94
|
config,
|
|
100
95
|
messages,
|
|
101
|
-
toolCtx,
|
|
102
96
|
skills,
|
|
97
|
+
mcpxClient,
|
|
103
98
|
cleanup,
|
|
104
99
|
};
|
|
105
100
|
}
|
|
@@ -110,11 +105,13 @@ export async function sendMessage(
|
|
|
110
105
|
callbacks: ChatTurnCallbacks,
|
|
111
106
|
): Promise<void> {
|
|
112
107
|
// Log and append user message
|
|
113
|
-
await
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
108
|
+
await withDb(session.dbPath, (conn) =>
|
|
109
|
+
logInteraction(conn, session.threadId, {
|
|
110
|
+
role: "user",
|
|
111
|
+
kind: "message",
|
|
112
|
+
content: userMessage,
|
|
113
|
+
}),
|
|
114
|
+
);
|
|
118
115
|
|
|
119
116
|
session.messages.push({ role: "user", content: userMessage });
|
|
120
117
|
|
|
@@ -122,7 +119,7 @@ export async function sendMessage(
|
|
|
122
119
|
if (session.messages.length === 1) {
|
|
123
120
|
void generateThreadTitle(
|
|
124
121
|
session.config,
|
|
125
|
-
session.
|
|
122
|
+
session.dbPath,
|
|
126
123
|
session.threadId,
|
|
127
124
|
userMessage,
|
|
128
125
|
);
|
|
@@ -132,15 +129,14 @@ export async function sendMessage(
|
|
|
132
129
|
messages: session.messages,
|
|
133
130
|
projectDir: session.projectDir,
|
|
134
131
|
config: session.config,
|
|
135
|
-
|
|
132
|
+
dbPath: session.dbPath,
|
|
136
133
|
threadId: session.threadId,
|
|
137
|
-
|
|
134
|
+
mcpxClient: session.mcpxClient,
|
|
138
135
|
callbacks,
|
|
139
136
|
});
|
|
140
137
|
}
|
|
141
138
|
|
|
142
139
|
export async function endChatSession(session: ChatSession): Promise<void> {
|
|
143
|
-
await
|
|
140
|
+
await withDb(session.dbPath, (conn) => endThread(conn, session.threadId));
|
|
144
141
|
await session.cleanup();
|
|
145
|
-
session.conn.close();
|
|
146
142
|
}
|