@tyvm/knowhow 0.0.56 ā 0.0.59
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/package.json +3 -3
- package/src/agents/base/base.ts +87 -43
- package/src/agents/tools/execCommand.ts +17 -14
- package/src/agents/tools/googleSearch.ts +1 -0
- package/src/agents/tools/index.ts +1 -0
- package/src/agents/tools/lazy/definitions.ts +63 -0
- package/src/agents/tools/lazy/disableTools.ts +16 -0
- package/src/agents/tools/lazy/enableTools.ts +16 -0
- package/src/agents/tools/lazy/index.ts +3 -0
- package/src/agents/tools/lazy/listAvailableTools.ts +14 -0
- package/src/agents/tools/list.ts +2 -0
- package/src/agents/tools/mcp/connectMcpServer.ts +40 -0
- package/src/agents/tools/mcp/definitions.ts +67 -0
- package/src/agents/tools/mcp/disconnectMcpServer.ts +40 -0
- package/src/agents/tools/mcp/index.ts +3 -0
- package/src/agents/tools/mcp/listAvailableMcpServers.ts +28 -0
- package/src/agents/tools/writeFile.ts +4 -1
- package/src/chat/CliChatService.ts +8 -3
- package/src/chat/modules/AgentModule.ts +74 -296
- package/src/cli.ts +33 -10
- package/src/plugins/GitPlugin.ts +30 -24
- package/src/plugins/language.ts +95 -18
- package/src/processors/ToolResponseCache.ts +98 -79
- package/src/processors/tools/grepToolResponse.ts +99 -0
- package/src/processors/tools/index.ts +21 -0
- package/src/processors/tools/jqToolResponse.ts +124 -0
- package/src/processors/tools/listStoredToolResponses.ts +83 -0
- package/src/processors/tools/tailToolResponse.ts +75 -0
- package/src/services/AgentService.ts +1 -1
- package/src/services/AgentSynchronization.ts +291 -0
- package/src/services/DockerService.ts +37 -1
- package/src/services/EventService.ts +8 -2
- package/src/services/KnowhowClient.ts +141 -1
- package/src/services/LazyToolsService.ts +146 -0
- package/src/services/Mcp.ts +171 -4
- package/src/services/SessionManager.ts +287 -0
- package/src/services/TaskRegistry.ts +108 -0
- package/src/services/Tools.ts +2 -0
- package/src/services/index.ts +7 -0
- package/src/services/script-execution/ScriptExecutor.ts +7 -5
- package/src/types.ts +1 -0
- package/src/utils/InputQueueManager.ts +91 -57
- package/src/utils/errors.ts +0 -0
- package/src/utils/index.ts +11 -0
- package/src/worker.ts +12 -0
- package/tests/compressor/bigstring.test.ts +100 -0
- package/tests/compressor/bigstring.txt +1 -0
- package/tests/plugins/language/languagePlugin-content-triggers.test.ts +13 -5
- package/tests/plugins/language/languagePlugin-integration.test.ts +22 -7
- package/tests/plugins/language/languagePlugin.test.ts +11 -4
- package/tests/processors/ToolResponseCache.test.ts +128 -0
- package/tests/unit/InputQueueManager.test.ts +174 -0
- package/ts_build/package.json +3 -3
- package/ts_build/src/agents/base/base.d.ts +10 -0
- package/ts_build/src/agents/base/base.js +66 -34
- package/ts_build/src/agents/base/base.js.map +1 -1
- package/ts_build/src/agents/tools/execCommand.js +1 -9
- package/ts_build/src/agents/tools/execCommand.js.map +1 -1
- package/ts_build/src/agents/tools/github/index.d.ts +1 -1
- package/ts_build/src/agents/tools/googleSearch.d.ts +1 -0
- package/ts_build/src/agents/tools/googleSearch.js +1 -0
- package/ts_build/src/agents/tools/googleSearch.js.map +1 -1
- package/ts_build/src/agents/tools/index.d.ts +1 -0
- package/ts_build/src/agents/tools/index.js +1 -0
- package/ts_build/src/agents/tools/index.js.map +1 -1
- package/ts_build/src/agents/tools/lazy/definitions.d.ts +5 -0
- package/ts_build/src/agents/tools/lazy/definitions.js +58 -0
- package/ts_build/src/agents/tools/lazy/definitions.js.map +1 -0
- package/ts_build/src/agents/tools/lazy/disableTools.d.ts +9 -0
- package/ts_build/src/agents/tools/lazy/disableTools.js +15 -0
- package/ts_build/src/agents/tools/lazy/disableTools.js.map +1 -0
- package/ts_build/src/agents/tools/lazy/enableTools.d.ts +9 -0
- package/ts_build/src/agents/tools/lazy/enableTools.js +15 -0
- package/ts_build/src/agents/tools/lazy/enableTools.js.map +1 -0
- package/ts_build/src/agents/tools/lazy/index.d.ts +3 -0
- package/ts_build/src/agents/tools/lazy/index.js +20 -0
- package/ts_build/src/agents/tools/lazy/index.js.map +1 -0
- package/ts_build/src/agents/tools/lazy/listAvailableTools.d.ts +11 -0
- package/ts_build/src/agents/tools/lazy/listAvailableTools.js +15 -0
- package/ts_build/src/agents/tools/lazy/listAvailableTools.js.map +1 -0
- package/ts_build/src/agents/tools/list.js +2 -0
- package/ts_build/src/agents/tools/list.js.map +1 -1
- package/ts_build/src/agents/tools/mcp/connectMcpServer.d.ts +5 -0
- package/ts_build/src/agents/tools/mcp/connectMcpServer.js +31 -0
- package/ts_build/src/agents/tools/mcp/connectMcpServer.js.map +1 -0
- package/ts_build/src/agents/tools/mcp/definitions.d.ts +2 -0
- package/ts_build/src/agents/tools/mcp/definitions.js +62 -0
- package/ts_build/src/agents/tools/mcp/definitions.js.map +1 -0
- package/ts_build/src/agents/tools/mcp/disconnectMcpServer.d.ts +5 -0
- package/ts_build/src/agents/tools/mcp/disconnectMcpServer.js +31 -0
- package/ts_build/src/agents/tools/mcp/disconnectMcpServer.js.map +1 -0
- package/ts_build/src/agents/tools/mcp/index.d.ts +3 -0
- package/ts_build/src/agents/tools/mcp/index.js +10 -0
- package/ts_build/src/agents/tools/mcp/index.js.map +1 -0
- package/ts_build/src/agents/tools/mcp/listAvailableMcpServers.d.ts +14 -0
- package/ts_build/src/agents/tools/mcp/listAvailableMcpServers.js +23 -0
- package/ts_build/src/agents/tools/mcp/listAvailableMcpServers.js.map +1 -0
- package/ts_build/src/agents/tools/writeFile.js +4 -1
- package/ts_build/src/agents/tools/writeFile.js.map +1 -1
- package/ts_build/src/chat/CliChatService.js +3 -1
- package/ts_build/src/chat/CliChatService.js.map +1 -1
- package/ts_build/src/chat/modules/AgentModule.d.ts +4 -3
- package/ts_build/src/chat/modules/AgentModule.js +71 -265
- package/ts_build/src/chat/modules/AgentModule.js.map +1 -1
- package/ts_build/src/cli.d.ts +1 -1
- package/ts_build/src/cli.js +17 -4
- package/ts_build/src/cli.js.map +1 -1
- package/ts_build/src/plugins/GitPlugin.d.ts +1 -0
- package/ts_build/src/plugins/GitPlugin.js +26 -19
- package/ts_build/src/plugins/GitPlugin.js.map +1 -1
- package/ts_build/src/plugins/language.d.ts +3 -0
- package/ts_build/src/plugins/language.js +55 -13
- package/ts_build/src/plugins/language.js.map +1 -1
- package/ts_build/src/processors/ToolResponseCache.d.ts +7 -4
- package/ts_build/src/processors/ToolResponseCache.js +47 -88
- package/ts_build/src/processors/ToolResponseCache.js.map +1 -1
- package/ts_build/src/processors/tools/grepToolResponse.d.ts +10 -0
- package/ts_build/src/processors/tools/grepToolResponse.js +71 -0
- package/ts_build/src/processors/tools/grepToolResponse.js.map +1 -0
- package/ts_build/src/processors/tools/index.d.ts +4 -0
- package/ts_build/src/processors/tools/index.js +16 -0
- package/ts_build/src/processors/tools/index.js.map +1 -0
- package/ts_build/src/processors/tools/jqToolResponse.d.ts +3 -0
- package/ts_build/src/processors/tools/jqToolResponse.js +115 -0
- package/ts_build/src/processors/tools/jqToolResponse.js.map +1 -0
- package/ts_build/src/processors/tools/listStoredToolResponses.d.ts +21 -0
- package/ts_build/src/processors/tools/listStoredToolResponses.js +51 -0
- package/ts_build/src/processors/tools/listStoredToolResponses.js.map +1 -0
- package/ts_build/src/processors/tools/tailToolResponse.d.ts +6 -0
- package/ts_build/src/processors/tools/tailToolResponse.js +55 -0
- package/ts_build/src/processors/tools/tailToolResponse.js.map +1 -0
- package/ts_build/src/services/AgentService.d.ts +1 -1
- package/ts_build/src/services/AgentSynchronization.d.ts +27 -0
- package/ts_build/src/services/AgentSynchronization.js +168 -0
- package/ts_build/src/services/AgentSynchronization.js.map +1 -0
- package/ts_build/src/services/DockerService.d.ts +2 -0
- package/ts_build/src/services/DockerService.js +21 -1
- package/ts_build/src/services/DockerService.js.map +1 -1
- package/ts_build/src/services/EventService.d.ts +5 -0
- package/ts_build/src/services/EventService.js +7 -2
- package/ts_build/src/services/EventService.js.map +1 -1
- package/ts_build/src/services/KnowhowClient.d.ts +41 -1
- package/ts_build/src/services/KnowhowClient.js +42 -0
- package/ts_build/src/services/KnowhowClient.js.map +1 -1
- package/ts_build/src/services/LazyToolsService.d.ts +29 -0
- package/ts_build/src/services/LazyToolsService.js +96 -0
- package/ts_build/src/services/LazyToolsService.js.map +1 -0
- package/ts_build/src/services/Mcp.d.ts +18 -1
- package/ts_build/src/services/Mcp.js +119 -4
- package/ts_build/src/services/Mcp.js.map +1 -1
- package/ts_build/src/services/SessionManager.d.ts +15 -0
- package/ts_build/src/services/SessionManager.js +220 -0
- package/ts_build/src/services/SessionManager.js.map +1 -0
- package/ts_build/src/services/TaskRegistry.d.ts +15 -0
- package/ts_build/src/services/TaskRegistry.js +58 -0
- package/ts_build/src/services/TaskRegistry.js.map +1 -0
- package/ts_build/src/services/Tools.d.ts +2 -0
- package/ts_build/src/services/Tools.js.map +1 -1
- package/ts_build/src/services/index.d.ts +4 -0
- package/ts_build/src/services/index.js +4 -0
- package/ts_build/src/services/index.js.map +1 -1
- package/ts_build/src/services/script-execution/ScriptExecutor.js +7 -5
- package/ts_build/src/services/script-execution/ScriptExecutor.js.map +1 -1
- package/ts_build/src/types.d.ts +1 -0
- package/ts_build/src/types.js.map +1 -1
- package/ts_build/src/utils/InputQueueManager.d.ts +9 -2
- package/ts_build/src/utils/InputQueueManager.js +54 -40
- package/ts_build/src/utils/InputQueueManager.js.map +1 -1
- package/ts_build/src/utils/errors.d.ts +0 -0
- package/ts_build/src/utils/errors.js +1 -0
- package/ts_build/src/utils/errors.js.map +1 -0
- package/ts_build/src/utils/index.d.ts +1 -0
- package/ts_build/src/utils/index.js +5 -1
- package/ts_build/src/utils/index.js.map +1 -1
- package/ts_build/src/worker.js +8 -0
- package/ts_build/src/worker.js.map +1 -1
- package/ts_build/tests/compressor/bigstring.test.d.ts +1 -0
- package/ts_build/tests/compressor/bigstring.test.js +66 -0
- package/ts_build/tests/compressor/bigstring.test.js.map +1 -0
- package/ts_build/tests/plugins/language/languagePlugin-content-triggers.test.js +6 -5
- package/ts_build/tests/plugins/language/languagePlugin-content-triggers.test.js.map +1 -1
- package/ts_build/tests/plugins/language/languagePlugin-integration.test.js +9 -7
- package/ts_build/tests/plugins/language/languagePlugin-integration.test.js.map +1 -1
- package/ts_build/tests/plugins/language/languagePlugin.test.js +7 -4
- package/ts_build/tests/plugins/language/languagePlugin.test.js.map +1 -1
- package/ts_build/tests/processors/ToolResponseCache.test.js +107 -0
- package/ts_build/tests/processors/ToolResponseCache.test.js.map +1 -1
- package/ts_build/tests/unit/InputQueueManager.test.d.ts +1 -0
- package/ts_build/tests/unit/InputQueueManager.test.js +104 -0
- package/ts_build/tests/unit/InputQueueManager.test.js.map +1 -0
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session Manager Service - Handles agent session persistence and restoration
|
|
3
|
+
*/
|
|
4
|
+
import * as fs from "fs";
|
|
5
|
+
import * as path from "path";
|
|
6
|
+
import { TaskInfo, ChatSession } from "../chat/types";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* SessionManager handles saving, loading, and managing agent sessions
|
|
10
|
+
*/
|
|
11
|
+
export class SessionManager {
|
|
12
|
+
private sessionsDir: string;
|
|
13
|
+
|
|
14
|
+
constructor(sessionsDir: string = "./.knowhow/chats/sessions") {
|
|
15
|
+
this.sessionsDir = sessionsDir;
|
|
16
|
+
this.ensureSessionsDirectoryExists();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Ensure the sessions directory exists
|
|
21
|
+
*/
|
|
22
|
+
private ensureSessionsDirectoryExists(): void {
|
|
23
|
+
if (!fs.existsSync(this.sessionsDir)) {
|
|
24
|
+
fs.mkdirSync(this.sessionsDir, { recursive: true });
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Generate human-readable task ID from initial input
|
|
30
|
+
*/
|
|
31
|
+
generateTaskId(initialInput: string): string {
|
|
32
|
+
const words = initialInput
|
|
33
|
+
.toLowerCase()
|
|
34
|
+
.replace(/[^\w\s]/g, "")
|
|
35
|
+
.split(/\s+/)
|
|
36
|
+
.filter((word) => word.length > 2)
|
|
37
|
+
.slice(0, 9);
|
|
38
|
+
|
|
39
|
+
const wordPart = words.join("-") || "task";
|
|
40
|
+
const epochSeconds = Math.floor(Date.now() / 1000);
|
|
41
|
+
return `${epochSeconds}-${wordPart}`;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Save session to file
|
|
46
|
+
*/
|
|
47
|
+
saveSession(taskId: string, taskInfo: TaskInfo, threads: any[]): void {
|
|
48
|
+
try {
|
|
49
|
+
const sessionPath = path.join(this.sessionsDir, `${taskId}.json`);
|
|
50
|
+
const session: ChatSession = {
|
|
51
|
+
sessionId: taskId,
|
|
52
|
+
knowhowMessageId: taskInfo.knowhowMessageId,
|
|
53
|
+
knowhowTaskId: taskInfo.knowhowTaskId,
|
|
54
|
+
taskId,
|
|
55
|
+
agentName: taskInfo.agentName,
|
|
56
|
+
initialInput: taskInfo.initialInput,
|
|
57
|
+
status: taskInfo.status,
|
|
58
|
+
startTime: taskInfo.startTime,
|
|
59
|
+
endTime: taskInfo.endTime,
|
|
60
|
+
totalCost: taskInfo.totalCost,
|
|
61
|
+
threads,
|
|
62
|
+
currentThread: 0,
|
|
63
|
+
lastUpdated: Date.now(),
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
fs.writeFileSync(sessionPath, JSON.stringify(session, null, 2));
|
|
67
|
+
} catch (error) {
|
|
68
|
+
console.error(`Error saving session ${taskId}:`, error);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Update existing session with new thread state
|
|
74
|
+
*/
|
|
75
|
+
updateSession(
|
|
76
|
+
taskId: string,
|
|
77
|
+
taskInfo: TaskInfo | undefined,
|
|
78
|
+
threads: any[]
|
|
79
|
+
): void {
|
|
80
|
+
try {
|
|
81
|
+
const sessionPath = path.join(this.sessionsDir, `${taskId}.json`);
|
|
82
|
+
if (fs.existsSync(sessionPath)) {
|
|
83
|
+
const session: ChatSession = JSON.parse(
|
|
84
|
+
fs.readFileSync(sessionPath, "utf8")
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
// Update session with current state
|
|
88
|
+
session.threads = threads;
|
|
89
|
+
session.lastUpdated = Date.now();
|
|
90
|
+
|
|
91
|
+
if (taskInfo) {
|
|
92
|
+
session.status = taskInfo.status;
|
|
93
|
+
session.endTime = taskInfo.endTime;
|
|
94
|
+
session.totalCost = taskInfo.totalCost;
|
|
95
|
+
|
|
96
|
+
// Update Knowhow task fields if they exist in TaskInfo
|
|
97
|
+
session.knowhowMessageId = taskInfo.knowhowMessageId;
|
|
98
|
+
session.knowhowTaskId = taskInfo.knowhowTaskId;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
fs.writeFileSync(sessionPath, JSON.stringify(session, null, 2));
|
|
102
|
+
}
|
|
103
|
+
} catch (error) {
|
|
104
|
+
console.error(`Error updating session ${taskId}:`, error);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Load a session by ID
|
|
110
|
+
*/
|
|
111
|
+
loadSession(sessionId: string): ChatSession | null {
|
|
112
|
+
try {
|
|
113
|
+
const sessionPath = path.join(this.sessionsDir, `${sessionId}.json`);
|
|
114
|
+
if (fs.existsSync(sessionPath)) {
|
|
115
|
+
const content = fs.readFileSync(sessionPath, "utf-8");
|
|
116
|
+
return JSON.parse(content) as ChatSession;
|
|
117
|
+
}
|
|
118
|
+
} catch (error) {
|
|
119
|
+
console.error(`Failed to load session ${sessionId}:`, error);
|
|
120
|
+
}
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* List available session files
|
|
126
|
+
*/
|
|
127
|
+
listAvailableSessions(): ChatSession[] {
|
|
128
|
+
try {
|
|
129
|
+
const files = fs.readdirSync(this.sessionsDir);
|
|
130
|
+
const sessionFiles = files.filter((f) => f.endsWith(".json"));
|
|
131
|
+
|
|
132
|
+
const sessions: ChatSession[] = [];
|
|
133
|
+
const thresholdTime = 15 * 60 * 1000; // 15 minutes
|
|
134
|
+
|
|
135
|
+
for (const file of sessionFiles) {
|
|
136
|
+
const filePath = path.join(this.sessionsDir, file);
|
|
137
|
+
try {
|
|
138
|
+
const content = fs.readFileSync(filePath, "utf8");
|
|
139
|
+
const session = JSON.parse(content) as ChatSession;
|
|
140
|
+
|
|
141
|
+
// Cleanup check: mark stale running sessions as failed
|
|
142
|
+
const isStale = Date.now() - session.lastUpdated > thresholdTime;
|
|
143
|
+
const isRunning = session.status === "running";
|
|
144
|
+
|
|
145
|
+
if (isRunning && isStale) {
|
|
146
|
+
console.log(
|
|
147
|
+
`š§¹ Marking stale session ${
|
|
148
|
+
session.sessionId
|
|
149
|
+
} as failed (last updated: ${new Date(
|
|
150
|
+
session.lastUpdated
|
|
151
|
+
).toLocaleString()})`
|
|
152
|
+
);
|
|
153
|
+
session.status = "failed";
|
|
154
|
+
session.lastUpdated = Date.now();
|
|
155
|
+
// Update the session file with failed status
|
|
156
|
+
fs.writeFileSync(filePath, JSON.stringify(session, null, 2));
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
sessions.push(session);
|
|
160
|
+
} catch (error) {
|
|
161
|
+
console.warn(
|
|
162
|
+
`Failed to read session file ${file}:`,
|
|
163
|
+
(error as Error).message
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
return sessions.sort((a, b) => b.lastUpdated - a.lastUpdated);
|
|
169
|
+
} catch (error) {
|
|
170
|
+
console.warn("Failed to list sessions:", (error as Error).message);
|
|
171
|
+
return [];
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Check if a session exists
|
|
177
|
+
*/
|
|
178
|
+
sessionExists(sessionId: string): boolean {
|
|
179
|
+
const sessionPath = path.join(this.sessionsDir, `${sessionId}.json`);
|
|
180
|
+
return fs.existsSync(sessionPath);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Delete a session
|
|
185
|
+
*/
|
|
186
|
+
deleteSession(sessionId: string): boolean {
|
|
187
|
+
try {
|
|
188
|
+
const sessionPath = path.join(this.sessionsDir, `${sessionId}.json`);
|
|
189
|
+
if (fs.existsSync(sessionPath)) {
|
|
190
|
+
fs.unlinkSync(sessionPath);
|
|
191
|
+
return true;
|
|
192
|
+
}
|
|
193
|
+
} catch (error) {
|
|
194
|
+
console.error(`Failed to delete session ${sessionId}:`, error);
|
|
195
|
+
}
|
|
196
|
+
return false;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
async logSessionTable(
|
|
200
|
+
runningTasks: TaskInfo[],
|
|
201
|
+
savedSessions: ChatSession[]
|
|
202
|
+
) {
|
|
203
|
+
// Display unified table
|
|
204
|
+
console.log("\nš Sessions & Tasks:");
|
|
205
|
+
|
|
206
|
+
const data = [];
|
|
207
|
+
// Display saved sessions first (historical)
|
|
208
|
+
savedSessions.forEach((session) => {
|
|
209
|
+
const lastUpdated = new Date(session.lastUpdated).toLocaleString();
|
|
210
|
+
const inputPreview =
|
|
211
|
+
session.initialInput && session.initialInput.length > 30
|
|
212
|
+
? session.initialInput.substring(0, 27) + "..."
|
|
213
|
+
: session.initialInput || "[No input]";
|
|
214
|
+
const cost = session.totalCost
|
|
215
|
+
? `$${session.totalCost.toFixed(3)}`
|
|
216
|
+
: "$0.000";
|
|
217
|
+
|
|
218
|
+
data.push({
|
|
219
|
+
ID: session.sessionId,
|
|
220
|
+
Agent: session.agentName,
|
|
221
|
+
Status: session.status,
|
|
222
|
+
Type: "saved",
|
|
223
|
+
Time: lastUpdated,
|
|
224
|
+
Cost: cost,
|
|
225
|
+
"Initial Input": inputPreview,
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
// Display running tasks at the bottom
|
|
230
|
+
runningTasks.forEach((task) => {
|
|
231
|
+
const elapsed = task.endTime
|
|
232
|
+
? `${Math.round((task.endTime - task.startTime) / 1000)}s`
|
|
233
|
+
: `${Math.round((Date.now() - task.startTime) / 1000)}s`;
|
|
234
|
+
const cost = `$${task.totalCost.toFixed(3)}`;
|
|
235
|
+
const inputPreview =
|
|
236
|
+
task.initialInput.length > 30
|
|
237
|
+
? task.initialInput.substring(0, 27) + "..."
|
|
238
|
+
: task.initialInput;
|
|
239
|
+
data.push({
|
|
240
|
+
ID: task.taskId,
|
|
241
|
+
Agent: task.agentName,
|
|
242
|
+
Status: task.status,
|
|
243
|
+
Type: "running",
|
|
244
|
+
Time: elapsed,
|
|
245
|
+
Cost: cost,
|
|
246
|
+
"Initial Input": inputPreview,
|
|
247
|
+
});
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
console.table(data);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
async logRunningTasks(
|
|
254
|
+
runningTasks: TaskInfo[],
|
|
255
|
+
savedSessions: ChatSession[]
|
|
256
|
+
) {
|
|
257
|
+
// Show available options for selection
|
|
258
|
+
console.log("\nš Available Sessions & Tasks:");
|
|
259
|
+
console.log("ā".repeat(80));
|
|
260
|
+
console.log(
|
|
261
|
+
"ID".padEnd(25) + "Agent".padEnd(15) + "Status".padEnd(12) + "Type"
|
|
262
|
+
);
|
|
263
|
+
console.log("ā".repeat(80));
|
|
264
|
+
|
|
265
|
+
// Show saved sessions
|
|
266
|
+
savedSessions.forEach((session) => {
|
|
267
|
+
console.log(
|
|
268
|
+
session.sessionId.padEnd(25) +
|
|
269
|
+
session.agentName.padEnd(15) +
|
|
270
|
+
session.status.padEnd(12) +
|
|
271
|
+
"saved"
|
|
272
|
+
);
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
// Show running tasks
|
|
276
|
+
runningTasks.forEach((task) => {
|
|
277
|
+
console.log(
|
|
278
|
+
task.taskId.padEnd(25) +
|
|
279
|
+
task.agentName.padEnd(15) +
|
|
280
|
+
task.status.padEnd(12) +
|
|
281
|
+
"running"
|
|
282
|
+
);
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
console.log("ā".repeat(80));
|
|
286
|
+
}
|
|
287
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Task Registry Service - Manages active agent tasks
|
|
3
|
+
*/
|
|
4
|
+
import { TaskInfo } from "../chat/types";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* TaskRegistry manages the in-memory registry of active agent tasks
|
|
8
|
+
*/
|
|
9
|
+
export class TaskRegistry {
|
|
10
|
+
private tasks = new Map<string, TaskInfo>();
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Register a new task
|
|
14
|
+
*/
|
|
15
|
+
register(taskId: string, taskInfo: TaskInfo): void {
|
|
16
|
+
this.tasks.set(taskId, taskInfo);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Get a task by ID
|
|
21
|
+
*/
|
|
22
|
+
get(taskId: string): TaskInfo | undefined {
|
|
23
|
+
return this.tasks.get(taskId);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Update a task's information
|
|
28
|
+
*/
|
|
29
|
+
update(taskId: string, updates: Partial<TaskInfo>): void {
|
|
30
|
+
const task = this.tasks.get(taskId);
|
|
31
|
+
if (task) {
|
|
32
|
+
Object.assign(task, updates);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Remove a task from the registry
|
|
38
|
+
*/
|
|
39
|
+
delete(taskId: string): boolean {
|
|
40
|
+
return this.tasks.delete(taskId);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Check if a task exists
|
|
45
|
+
*/
|
|
46
|
+
has(taskId: string): boolean {
|
|
47
|
+
return this.tasks.has(taskId);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Get all tasks as an array
|
|
52
|
+
*/
|
|
53
|
+
getAll(): TaskInfo[] {
|
|
54
|
+
return Array.from(this.tasks.values());
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Get all task entries
|
|
59
|
+
*/
|
|
60
|
+
getEntries(): [string, TaskInfo][] {
|
|
61
|
+
return Array.from(this.tasks.entries());
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Get the underlying Map (for compatibility)
|
|
66
|
+
*/
|
|
67
|
+
getMap(): Map<string, TaskInfo> {
|
|
68
|
+
return this.tasks;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Clear all tasks
|
|
73
|
+
*/
|
|
74
|
+
clear(): void {
|
|
75
|
+
this.tasks.clear();
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Get count of active tasks
|
|
80
|
+
*/
|
|
81
|
+
count(): number {
|
|
82
|
+
return this.tasks.size;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Display single task details
|
|
87
|
+
*/
|
|
88
|
+
displaySingleTask(task: TaskInfo): void {
|
|
89
|
+
console.log(`\nš Task Details: ${task.taskId}`);
|
|
90
|
+
console.log("ā".repeat(50));
|
|
91
|
+
console.log(`Agent: ${task.agentName}`);
|
|
92
|
+
console.log(`Status: ${task.status}`);
|
|
93
|
+
console.log(`Initial Input: ${task.initialInput}`);
|
|
94
|
+
console.log(`Start Time: ${new Date(task.startTime).toLocaleString()}`);
|
|
95
|
+
if (task.endTime) {
|
|
96
|
+
console.log(`End Time: ${new Date(task.endTime).toLocaleString()}`);
|
|
97
|
+
console.log(
|
|
98
|
+
`Duration: ${Math.round((task.endTime - task.startTime) / 1000)}s`
|
|
99
|
+
);
|
|
100
|
+
} else {
|
|
101
|
+
console.log(
|
|
102
|
+
`Running for: ${Math.round((Date.now() - task.startTime) / 1000)}s`
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
console.log(`Total Cost: $${task.totalCost.toFixed(3)}`);
|
|
106
|
+
console.log("ā".repeat(50));
|
|
107
|
+
}
|
|
108
|
+
}
|
package/src/services/Tools.ts
CHANGED
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
createPatternMatcher,
|
|
14
14
|
} from "./types";
|
|
15
15
|
import { PluginService } from "../plugins/plugins";
|
|
16
|
+
import { McpService } from "./Mcp";
|
|
16
17
|
|
|
17
18
|
export interface ToolContext {
|
|
18
19
|
Agents?: AgentService;
|
|
@@ -20,6 +21,7 @@ export interface ToolContext {
|
|
|
20
21
|
Clients?: AIClient;
|
|
21
22
|
Tools?: ToolsService;
|
|
22
23
|
Plugins?: PluginService;
|
|
24
|
+
Mcp?: McpService;
|
|
23
25
|
metadata?: { [key: string]: any };
|
|
24
26
|
}
|
|
25
27
|
|
package/src/services/index.ts
CHANGED
|
@@ -10,6 +10,9 @@ import { S3Service } from "./S3";
|
|
|
10
10
|
import { ToolsService } from "./Tools";
|
|
11
11
|
import { PluginService } from "../plugins/plugins";
|
|
12
12
|
import { DockerService } from "./DockerService";
|
|
13
|
+
import { AgentSynchronization } from "./AgentSynchronization";
|
|
14
|
+
import { SessionManager } from "./SessionManager";
|
|
15
|
+
import { TaskRegistry } from "./TaskRegistry";
|
|
13
16
|
|
|
14
17
|
export * from "./AgentService";
|
|
15
18
|
export * from "./EventService";
|
|
@@ -17,9 +20,13 @@ export * from "./flags";
|
|
|
17
20
|
export * from "./GitHub";
|
|
18
21
|
export * from "./S3";
|
|
19
22
|
export * from "./Tools";
|
|
23
|
+
export * from "./LazyToolsService";
|
|
20
24
|
export * as MCP from "./Mcp";
|
|
21
25
|
export * from "./EmbeddingService";
|
|
22
26
|
export * from "./DockerService";
|
|
27
|
+
export * from "./AgentSynchronization";
|
|
28
|
+
export * from "./SessionManager";
|
|
29
|
+
export * from "./TaskRegistry";
|
|
23
30
|
export { Clients } from "../clients";
|
|
24
31
|
|
|
25
32
|
let Singletons = {} as {
|
|
@@ -55,16 +55,18 @@ export class ScriptExecutor {
|
|
|
55
55
|
|
|
56
56
|
if (!hasNoNodeSnapshot) {
|
|
57
57
|
const errorMessage = [
|
|
58
|
-
`Node.js ${nodeVersion} detected. The --no-node-snapshot flag
|
|
58
|
+
`Node.js ${nodeVersion} detected. The executeScript tool requires the --no-node-snapshot flag for isolated-vm compatibility.`,
|
|
59
59
|
'',
|
|
60
|
-
'
|
|
61
|
-
'
|
|
62
|
-
'
|
|
60
|
+
'This flag is automatically included when running knowhow commands via the CLI (e.g., `knowhow agent`, `knowhow chat`).',
|
|
61
|
+
'',
|
|
62
|
+
'If you are programmatically using knowhow or running custom scripts:',
|
|
63
|
+
'1. Start your application with: node --no-node-snapshot your-app.js',
|
|
64
|
+
'2. Or update your package.json scripts to include the flag:',
|
|
63
65
|
' "scripts": {',
|
|
64
66
|
' "start": "node --no-node-snapshot dist/index.js"',
|
|
65
67
|
' }',
|
|
66
68
|
'',
|
|
67
|
-
'This flag is
|
|
69
|
+
'Note: This flag is required for Node.js 20+ to ensure isolated-vm works correctly.'
|
|
68
70
|
].join('\n');
|
|
69
71
|
|
|
70
72
|
throw new Error(errorMessage);
|
package/src/types.ts
CHANGED