@tyvm/knowhow 0.0.82 → 0.0.84

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.
Files changed (210) hide show
  1. package/package.json +4 -2
  2. package/src/agents/base/base.ts +72 -62
  3. package/src/agents/index.ts +30 -14
  4. package/src/agents/tools/startAgentTask.ts +3 -1
  5. package/src/chat/CliChatService.ts +20 -4
  6. package/src/chat/modules/AgentModule.ts +399 -357
  7. package/src/chat/modules/CustomCommandsModule.ts +0 -1
  8. package/src/chat/modules/InternalChatModule.ts +18 -2
  9. package/src/chat/modules/RendererModule.ts +109 -0
  10. package/src/chat/modules/SessionsModule.ts +854 -0
  11. package/src/chat/modules/SetupModule.ts +6 -8
  12. package/src/chat/modules/index.ts +1 -0
  13. package/src/chat/renderer/CompactRenderer.ts +209 -0
  14. package/src/chat/renderer/ConsoleRenderer.ts +141 -0
  15. package/src/chat/renderer/FancyRenderer.ts +421 -0
  16. package/src/chat/renderer/index.ts +5 -0
  17. package/src/chat/renderer/loadRenderer.ts +314 -0
  18. package/src/chat/renderer/messagesToRenderEvents.ts +96 -0
  19. package/src/chat/renderer/types.ts +88 -0
  20. package/src/chat/types.ts +5 -0
  21. package/src/chat.ts +69 -5
  22. package/src/cli.ts +24 -5
  23. package/src/config.ts +15 -0
  24. package/src/plugins/AgentsMdPlugin.ts +1 -1
  25. package/src/plugins/GitPlugin.ts +20 -20
  26. package/src/plugins/PluginBase.ts +11 -0
  27. package/src/plugins/SkillsPlugin.ts +150 -0
  28. package/src/plugins/asana.ts +4 -4
  29. package/src/plugins/embedding.ts +3 -5
  30. package/src/plugins/exec.ts +3 -3
  31. package/src/plugins/figma.ts +3 -7
  32. package/src/plugins/github.ts +18 -29
  33. package/src/plugins/jira.ts +2 -2
  34. package/src/plugins/language.ts +4 -4
  35. package/src/plugins/linear.ts +4 -4
  36. package/src/plugins/notion.ts +6 -8
  37. package/src/plugins/plugins.ts +30 -4
  38. package/src/plugins/url.ts +2 -2
  39. package/src/plugins/vim.ts +4 -3
  40. package/src/services/AgentService.ts +17 -0
  41. package/src/services/AgentSyncFs.ts +3 -0
  42. package/src/services/EventService.ts +168 -27
  43. package/src/services/KnowhowClient.ts +1 -0
  44. package/src/services/SessionManager.ts +51 -1
  45. package/src/services/SyncedAgentWatcher.ts +397 -0
  46. package/src/services/SyncerService.ts +147 -0
  47. package/src/services/index.ts +2 -0
  48. package/src/services/modules/index.ts +14 -3
  49. package/src/types.ts +25 -0
  50. package/src/worker.ts +80 -2
  51. package/src/workers/auth/PasskeySetup.ts +185 -0
  52. package/src/workers/auth/WorkerPasskeyAuth.ts +190 -0
  53. package/src/workers/auth/types.ts +58 -0
  54. package/src/workers/tools/getChallenge.ts +33 -0
  55. package/src/workers/tools/index.ts +8 -0
  56. package/src/workers/tools/lock.ts +31 -0
  57. package/src/workers/tools/unlock.ts +116 -0
  58. package/tests/unit/modules/moduleLoading.test.ts +226 -0
  59. package/tests/unit/plugins/pluginLoading.test.ts +151 -0
  60. package/ts_build/package.json +4 -2
  61. package/ts_build/src/agents/base/base.d.ts +4 -3
  62. package/ts_build/src/agents/base/base.js +54 -30
  63. package/ts_build/src/agents/base/base.js.map +1 -1
  64. package/ts_build/src/agents/index.d.ts +3 -0
  65. package/ts_build/src/agents/index.js +21 -11
  66. package/ts_build/src/agents/index.js.map +1 -1
  67. package/ts_build/src/agents/tools/startAgentTask.js +2 -1
  68. package/ts_build/src/agents/tools/startAgentTask.js.map +1 -1
  69. package/ts_build/src/chat/CliChatService.js +16 -5
  70. package/ts_build/src/chat/CliChatService.js.map +1 -1
  71. package/ts_build/src/chat/modules/AgentModule.d.ts +34 -17
  72. package/ts_build/src/chat/modules/AgentModule.js +248 -258
  73. package/ts_build/src/chat/modules/AgentModule.js.map +1 -1
  74. package/ts_build/src/chat/modules/CustomCommandsModule.js.map +1 -1
  75. package/ts_build/src/chat/modules/InternalChatModule.d.ts +3 -0
  76. package/ts_build/src/chat/modules/InternalChatModule.js +16 -1
  77. package/ts_build/src/chat/modules/InternalChatModule.js.map +1 -1
  78. package/ts_build/src/chat/modules/RendererModule.d.ts +16 -0
  79. package/ts_build/src/chat/modules/RendererModule.js +76 -0
  80. package/ts_build/src/chat/modules/RendererModule.js.map +1 -0
  81. package/ts_build/src/chat/modules/SessionsModule.d.ts +33 -0
  82. package/ts_build/src/chat/modules/SessionsModule.js +582 -0
  83. package/ts_build/src/chat/modules/SessionsModule.js.map +1 -0
  84. package/ts_build/src/chat/modules/SetupModule.d.ts +3 -3
  85. package/ts_build/src/chat/modules/SetupModule.js +4 -6
  86. package/ts_build/src/chat/modules/SetupModule.js.map +1 -1
  87. package/ts_build/src/chat/modules/index.d.ts +1 -0
  88. package/ts_build/src/chat/modules/index.js +3 -1
  89. package/ts_build/src/chat/modules/index.js.map +1 -1
  90. package/ts_build/src/chat/renderer/CompactRenderer.d.ts +23 -0
  91. package/ts_build/src/chat/renderer/CompactRenderer.js +167 -0
  92. package/ts_build/src/chat/renderer/CompactRenderer.js.map +1 -0
  93. package/ts_build/src/chat/renderer/ConsoleRenderer.d.ts +22 -0
  94. package/ts_build/src/chat/renderer/ConsoleRenderer.js +110 -0
  95. package/ts_build/src/chat/renderer/ConsoleRenderer.js.map +1 -0
  96. package/ts_build/src/chat/renderer/FancyRenderer.d.ts +23 -0
  97. package/ts_build/src/chat/renderer/FancyRenderer.js +328 -0
  98. package/ts_build/src/chat/renderer/FancyRenderer.js.map +1 -0
  99. package/ts_build/src/chat/renderer/index.d.ts +5 -0
  100. package/ts_build/src/chat/renderer/index.js +29 -0
  101. package/ts_build/src/chat/renderer/index.js.map +1 -0
  102. package/ts_build/src/chat/renderer/loadRenderer.d.ts +4 -0
  103. package/ts_build/src/chat/renderer/loadRenderer.js +246 -0
  104. package/ts_build/src/chat/renderer/loadRenderer.js.map +1 -0
  105. package/ts_build/src/chat/renderer/messagesToRenderEvents.d.ts +15 -0
  106. package/ts_build/src/chat/renderer/messagesToRenderEvents.js +72 -0
  107. package/ts_build/src/chat/renderer/messagesToRenderEvents.js.map +1 -0
  108. package/ts_build/src/chat/renderer/types.d.ts +75 -0
  109. package/ts_build/src/chat/renderer/types.js +3 -0
  110. package/ts_build/src/chat/renderer/types.js.map +1 -0
  111. package/ts_build/src/chat/types.d.ts +5 -0
  112. package/ts_build/src/chat.js +46 -4
  113. package/ts_build/src/chat.js.map +1 -1
  114. package/ts_build/src/cli.js +18 -5
  115. package/ts_build/src/cli.js.map +1 -1
  116. package/ts_build/src/config.d.ts +1 -0
  117. package/ts_build/src/config.js +17 -1
  118. package/ts_build/src/config.js.map +1 -1
  119. package/ts_build/src/plugins/AgentsMdPlugin.js +1 -1
  120. package/ts_build/src/plugins/AgentsMdPlugin.js.map +1 -1
  121. package/ts_build/src/plugins/GitPlugin.js +20 -20
  122. package/ts_build/src/plugins/GitPlugin.js.map +1 -1
  123. package/ts_build/src/plugins/PluginBase.d.ts +1 -0
  124. package/ts_build/src/plugins/PluginBase.js +13 -0
  125. package/ts_build/src/plugins/PluginBase.js.map +1 -1
  126. package/ts_build/src/plugins/SkillsPlugin.d.ts +13 -0
  127. package/ts_build/src/plugins/SkillsPlugin.js +149 -0
  128. package/ts_build/src/plugins/SkillsPlugin.js.map +1 -0
  129. package/ts_build/src/plugins/asana.js +4 -4
  130. package/ts_build/src/plugins/asana.js.map +1 -1
  131. package/ts_build/src/plugins/embedding.js +3 -3
  132. package/ts_build/src/plugins/embedding.js.map +1 -1
  133. package/ts_build/src/plugins/exec.js +3 -3
  134. package/ts_build/src/plugins/exec.js.map +1 -1
  135. package/ts_build/src/plugins/figma.js +3 -3
  136. package/ts_build/src/plugins/figma.js.map +1 -1
  137. package/ts_build/src/plugins/github.js +18 -18
  138. package/ts_build/src/plugins/github.js.map +1 -1
  139. package/ts_build/src/plugins/jira.js +2 -2
  140. package/ts_build/src/plugins/jira.js.map +1 -1
  141. package/ts_build/src/plugins/language.js +4 -4
  142. package/ts_build/src/plugins/language.js.map +1 -1
  143. package/ts_build/src/plugins/linear.js +4 -4
  144. package/ts_build/src/plugins/linear.js.map +1 -1
  145. package/ts_build/src/plugins/notion.js +6 -6
  146. package/ts_build/src/plugins/notion.js.map +1 -1
  147. package/ts_build/src/plugins/plugins.d.ts +3 -0
  148. package/ts_build/src/plugins/plugins.js +19 -4
  149. package/ts_build/src/plugins/plugins.js.map +1 -1
  150. package/ts_build/src/plugins/url.js +2 -2
  151. package/ts_build/src/plugins/url.js.map +1 -1
  152. package/ts_build/src/plugins/vim.js +2 -2
  153. package/ts_build/src/plugins/vim.js.map +1 -1
  154. package/ts_build/src/services/AgentService.d.ts +3 -0
  155. package/ts_build/src/services/AgentService.js +7 -0
  156. package/ts_build/src/services/AgentService.js.map +1 -1
  157. package/ts_build/src/services/AgentSyncFs.d.ts +1 -0
  158. package/ts_build/src/services/AgentSyncFs.js +2 -0
  159. package/ts_build/src/services/AgentSyncFs.js.map +1 -1
  160. package/ts_build/src/services/EventService.d.ts +25 -2
  161. package/ts_build/src/services/EventService.js +92 -14
  162. package/ts_build/src/services/EventService.js.map +1 -1
  163. package/ts_build/src/services/KnowhowClient.d.ts +1 -0
  164. package/ts_build/src/services/KnowhowClient.js.map +1 -1
  165. package/ts_build/src/services/SessionManager.d.ts +6 -0
  166. package/ts_build/src/services/SessionManager.js +39 -1
  167. package/ts_build/src/services/SessionManager.js.map +1 -1
  168. package/ts_build/src/services/SyncedAgentWatcher.d.ts +101 -0
  169. package/ts_build/src/services/SyncedAgentWatcher.js +312 -0
  170. package/ts_build/src/services/SyncedAgentWatcher.js.map +1 -0
  171. package/ts_build/src/services/SyncerService.d.ts +30 -0
  172. package/ts_build/src/services/SyncerService.js +72 -0
  173. package/ts_build/src/services/SyncerService.js.map +1 -0
  174. package/ts_build/src/services/index.d.ts +2 -0
  175. package/ts_build/src/services/index.js +2 -0
  176. package/ts_build/src/services/index.js.map +1 -1
  177. package/ts_build/src/services/modules/index.js +10 -2
  178. package/ts_build/src/services/modules/index.js.map +1 -1
  179. package/ts_build/src/types.d.ts +19 -0
  180. package/ts_build/src/types.js.map +1 -1
  181. package/ts_build/src/worker.d.ts +2 -0
  182. package/ts_build/src/worker.js +59 -4
  183. package/ts_build/src/worker.js.map +1 -1
  184. package/ts_build/src/workers/auth/PasskeySetup.d.ts +10 -0
  185. package/ts_build/src/workers/auth/PasskeySetup.js +131 -0
  186. package/ts_build/src/workers/auth/PasskeySetup.js.map +1 -0
  187. package/ts_build/src/workers/auth/WorkerPasskeyAuth.d.ts +35 -0
  188. package/ts_build/src/workers/auth/WorkerPasskeyAuth.js +129 -0
  189. package/ts_build/src/workers/auth/WorkerPasskeyAuth.js.map +1 -0
  190. package/ts_build/src/workers/auth/types.d.ts +36 -0
  191. package/ts_build/src/workers/auth/types.js +3 -0
  192. package/ts_build/src/workers/auth/types.js.map +1 -0
  193. package/ts_build/src/workers/tools/getChallenge.d.ts +9 -0
  194. package/ts_build/src/workers/tools/getChallenge.js +27 -0
  195. package/ts_build/src/workers/tools/getChallenge.js.map +1 -0
  196. package/ts_build/src/workers/tools/index.d.ts +6 -0
  197. package/ts_build/src/workers/tools/index.js +10 -0
  198. package/ts_build/src/workers/tools/index.js.map +1 -1
  199. package/ts_build/src/workers/tools/lock.d.ts +9 -0
  200. package/ts_build/src/workers/tools/lock.js +27 -0
  201. package/ts_build/src/workers/tools/lock.js.map +1 -0
  202. package/ts_build/src/workers/tools/unlock.d.ts +18 -0
  203. package/ts_build/src/workers/tools/unlock.js +78 -0
  204. package/ts_build/src/workers/tools/unlock.js.map +1 -0
  205. package/ts_build/tests/unit/modules/moduleLoading.test.d.ts +1 -0
  206. package/ts_build/tests/unit/modules/moduleLoading.test.js +187 -0
  207. package/ts_build/tests/unit/modules/moduleLoading.test.js.map +1 -0
  208. package/ts_build/tests/unit/plugins/pluginLoading.test.d.ts +1 -0
  209. package/ts_build/tests/unit/plugins/pluginLoading.test.js +123 -0
  210. package/ts_build/tests/unit/plugins/pluginLoading.test.js.map +1 -0
@@ -24,30 +24,38 @@ var __importStar = (this && this.__importStar) || function (mod) {
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.AgentModule = void 0;
27
+ const renderer_1 = require("../renderer");
27
28
  const index_1 = require("../../services/index");
28
29
  const fs = __importStar(require("fs"));
29
30
  const fsPromises = __importStar(require("fs/promises"));
30
31
  const path = __importStar(require("path"));
31
32
  const BaseChatModule_1 = require("./BaseChatModule");
32
- const index_2 = require("../../utils/index");
33
+ const index_2 = require("../../services/index");
34
+ const index_3 = require("../../utils/index");
33
35
  const TokenCompressor_1 = require("../../processors/TokenCompressor");
34
36
  const ToolResponseCache_1 = require("../../processors/ToolResponseCache");
35
- const index_3 = require("../../processors/index");
37
+ const index_4 = require("../../processors/index");
36
38
  const agents_1 = require("../../agents");
37
39
  const KnowhowClient_1 = require("../../services/KnowhowClient");
38
40
  class AgentModule extends BaseChatModule_1.BaseChatModule {
39
41
  name = "agent";
40
42
  description = "Agent interaction functionality";
43
+ attachedAgent;
41
44
  taskRegistry;
42
45
  sessionManager;
43
- webSync;
44
- fsSync;
46
+ syncer;
47
+ processStartTime = Date.now();
48
+ activeAgentTaskId;
49
+ activeSyncedWatcher;
50
+ _wireAgentEvents;
51
+ _wireTaskId;
52
+ _wireAgentName;
53
+ _wireEventTypes;
45
54
  constructor() {
46
55
  super();
47
56
  this.taskRegistry = new index_1.TaskRegistry();
48
57
  this.sessionManager = new index_1.SessionManager();
49
- this.webSync = new index_1.AgentSyncKnowhowWeb();
50
- this.fsSync = new index_1.AgentSyncFs();
58
+ this.syncer = new index_1.SyncerService();
51
59
  }
52
60
  getCommands() {
53
61
  return [
@@ -62,28 +70,113 @@ class AgentModule extends BaseChatModule_1.BaseChatModule {
62
70
  handler: this.handleAgentsCommand.bind(this),
63
71
  },
64
72
  {
65
- name: "attach",
66
- description: "Attach to a running session or resume an old session",
67
- handler: this.handleAttachCommand.bind(this),
73
+ name: "pause",
74
+ description: "Pause the currently attached agent",
75
+ modes: ["agent:attached"],
76
+ handler: async (_args) => {
77
+ if (this.attachedAgent) {
78
+ await this.attachedAgent.pause();
79
+ console.log("Agent paused.");
80
+ }
81
+ },
82
+ },
83
+ {
84
+ name: "unpause",
85
+ description: "Unpause the currently attached agent",
86
+ modes: ["agent:attached"],
87
+ handler: async (_args) => {
88
+ if (this.attachedAgent) {
89
+ await this.attachedAgent.unpause();
90
+ console.log("Agent unpaused.");
91
+ }
92
+ },
68
93
  },
69
94
  {
70
- name: "sessions",
71
- description: "List active tasks and saved sessions",
72
- handler: this.handleSessionsCommand.bind(this),
95
+ name: "kill",
96
+ description: "Kill the currently attached agent",
97
+ modes: ["agent:attached"],
98
+ handler: async (_args) => {
99
+ if (this.attachedAgent) {
100
+ await this.attachedAgent.kill();
101
+ console.log("Agent terminated.");
102
+ this.detachFromAgent();
103
+ }
104
+ },
105
+ },
106
+ {
107
+ name: "detach",
108
+ description: "Detach from the currently attached agent",
109
+ modes: ["agent:attached"],
110
+ handler: async (_args) => {
111
+ console.log("Detached from agent");
112
+ this.detachFromAgent();
113
+ },
114
+ },
115
+ {
116
+ name: "done",
117
+ description: "Exit the current agent interaction",
118
+ modes: ["agent:attached"],
119
+ handler: async (_args) => {
120
+ this.detachFromAgent();
121
+ },
73
122
  },
74
123
  ];
75
124
  }
125
+ detachFromAgent() {
126
+ this.attachedAgent = undefined;
127
+ this.unwireAgentRendering();
128
+ if (this.chatService) {
129
+ this.chatService.setMode("default");
130
+ }
131
+ if (this.activeSyncedWatcher) {
132
+ this.activeSyncedWatcher.stopWatching();
133
+ this.activeSyncedWatcher = undefined;
134
+ }
135
+ const context = this.chatService?.getContext();
136
+ if (context)
137
+ context.activeAgentTaskId = undefined;
138
+ }
76
139
  getModes() {
77
140
  return [
78
141
  {
79
142
  name: "agent",
80
143
  description: "Agent interaction mode",
81
144
  active: true,
145
+ promptText: () => {
146
+ const ctx = this.chatService?.getContext();
147
+ return ctx?.currentAgent
148
+ ? `\nAsk knowhow ${ctx.currentAgent}: `
149
+ : `\nAsk knowhow: `;
150
+ },
151
+ },
152
+ {
153
+ name: "agent:attached",
154
+ description: "Attached to a running agent",
155
+ active: false,
156
+ promptText: () => this.attachedAgent
157
+ ? `Enter command or message for ${this.attachedAgent.name}: `
158
+ : `Enter command or message for agent: `,
82
159
  },
83
160
  ];
84
161
  }
162
+ get renderer() {
163
+ return (this.chatService?.getContext()?.renderer ??
164
+ new renderer_1.ConsoleRenderer());
165
+ }
85
166
  async initialize(service) {
86
167
  await super.initialize(service);
168
+ const Events = (0, index_2.services)().Events;
169
+ Events.setListener({ key: "agentModule:pluginLog", event: Events.eventTypes.pluginLog }, (logEvent) => {
170
+ const activeTasks = this.taskRegistry.getAll();
171
+ this.renderer.render({
172
+ type: "log",
173
+ taskId: this.activeAgentTaskId,
174
+ agentName: logEvent.source,
175
+ message: logEvent.message,
176
+ level: logEvent.level || "info",
177
+ timestamp: logEvent.timestamp || new Date().toISOString(),
178
+ });
179
+ });
87
180
  await this.handleAgentCommand(["Patcher"]);
88
181
  }
89
182
  async handleAgentCommand(args) {
@@ -127,32 +220,76 @@ class AgentModule extends BaseChatModule_1.BaseChatModule {
127
220
  console.error(`Error selecting agent ${agentName}:`, error);
128
221
  }
129
222
  }
130
- async handleAttachCommand(args) {
131
- if (args.length === 0) {
132
- const runningTasks = this.taskRegistry.getAll();
133
- const savedSessions = this.sessionManager.listAvailableSessions();
134
- if (runningTasks.length === 0 && savedSessions.length === 0) {
135
- console.log("No active tasks or saved sessions found to attach to.");
136
- return;
137
- }
138
- await this.sessionManager.logRunningTasks(runningTasks, savedSessions);
139
- const allIds = [
140
- ...savedSessions.map((s) => s.sessionId),
141
- ...runningTasks.map((t) => t.taskId),
142
- ];
143
- const selectedId = await this.chatService?.getInput("Select a session/task to attach to (or press Enter to skip): ", allIds);
144
- if (selectedId &&
145
- selectedId.trim() &&
146
- allIds.includes(selectedId.trim())) {
147
- await this.handleAttachById(selectedId.trim());
148
- }
149
- return;
223
+ getTaskRegistry() {
224
+ return this.taskRegistry;
225
+ }
226
+ getSessionManager() {
227
+ return this.sessionManager;
228
+ }
229
+ getRenderer() {
230
+ return this.renderer;
231
+ }
232
+ getActiveSyncedWatcher() {
233
+ return this.activeSyncedWatcher;
234
+ }
235
+ setActiveSyncedWatcher(w) {
236
+ this.activeSyncedWatcher = w;
237
+ }
238
+ getActiveAgentTaskId() {
239
+ return this.activeAgentTaskId;
240
+ }
241
+ setActiveAgentTaskId(id) {
242
+ this.activeAgentTaskId = id;
243
+ }
244
+ wireAgentRendering(taskId, agentEvents, eventTypes, agentName) {
245
+ if (eventTypes.toolCall) {
246
+ agentEvents.setListener({ key: "agentModule:render:toolCall", event: eventTypes.toolCall }, (data) => this.renderer.render({
247
+ type: "toolCall",
248
+ taskId,
249
+ agentName,
250
+ toolCall: data.toolCall,
251
+ }));
150
252
  }
151
- const taskId = args[0];
152
- await this.handleAttachById(taskId);
253
+ if (eventTypes.toolUsed) {
254
+ agentEvents.setListener({ key: "agentModule:render:toolUsed", event: eventTypes.toolUsed }, (data) => this.renderer.render({
255
+ type: "toolResult",
256
+ taskId,
257
+ agentName,
258
+ toolCall: data.toolCall,
259
+ result: data.functionResp,
260
+ }));
261
+ }
262
+ if (eventTypes.agentSay) {
263
+ agentEvents.setListener({ key: "agentModule:render:agentSay", event: eventTypes.agentSay }, (data) => this.renderer.render({
264
+ type: "agentMessage",
265
+ taskId,
266
+ agentName,
267
+ message: data.message,
268
+ role: "assistant",
269
+ }));
270
+ }
271
+ this.activeAgentTaskId = taskId;
272
+ this.renderer.setActiveTaskId(taskId);
273
+ this._wireAgentEvents = agentEvents;
274
+ this._wireAgentName = agentName;
275
+ this._wireEventTypes = eventTypes;
276
+ this._wireTaskId = taskId;
153
277
  }
154
- displaySingleTask(task) {
155
- this.taskRegistry.displaySingleTask(task);
278
+ unwireAgentRendering() {
279
+ if (this._wireAgentEvents) {
280
+ this._wireAgentEvents.removeManagedListenersByPrefix("agentModule:render:");
281
+ this._wireAgentEvents = undefined;
282
+ }
283
+ this.activeAgentTaskId = undefined;
284
+ this.renderer.setActiveTaskId(undefined);
285
+ }
286
+ rewireAgentRendering() {
287
+ if (!this._wireAgentEvents ||
288
+ !this._wireTaskId ||
289
+ !this._wireEventTypes ||
290
+ !this._wireAgentName)
291
+ return;
292
+ this.wireAgentRendering(this._wireTaskId, this._wireAgentEvents, this._wireEventTypes, this._wireAgentName);
156
293
  }
157
294
  async handleAgentsCommand(args) {
158
295
  try {
@@ -183,99 +320,8 @@ class AgentModule extends BaseChatModule_1.BaseChatModule {
183
320
  console.log("Could not load agents list.");
184
321
  }
185
322
  }
186
- async logSessionTable() {
187
- const runningTasks = this.taskRegistry.getAll();
188
- const savedSessions = this.sessionManager.listAvailableSessions();
189
- this.sessionManager.logSessionTable(runningTasks, savedSessions);
190
- }
191
- async handleSessionsCommand(args) {
192
- try {
193
- const runningTasks = this.taskRegistry.getAll();
194
- const savedSessions = this.sessionManager.listAvailableSessions();
195
- if (runningTasks.length === 0 && savedSessions.length === 0) {
196
- console.log("No active tasks or saved sessions found.");
197
- return;
198
- }
199
- await this.logSessionTable();
200
- const allIds = [
201
- ...savedSessions.map((s) => s.sessionId),
202
- ...runningTasks.map((t) => t.taskId),
203
- ];
204
- if (allIds.length > 0) {
205
- const selectedId = await this.chatService?.getInput("Select a session/task to attach to (or press Enter to skip): ", allIds);
206
- if (selectedId &&
207
- selectedId.trim() &&
208
- allIds.includes(selectedId.trim())) {
209
- await this.handleAttachById(selectedId.trim());
210
- }
211
- }
212
- }
213
- catch (error) {
214
- console.error("Error listing sessions and tasks:", error);
215
- }
216
- }
217
- async handleAttachById(id) {
218
- if (this.taskRegistry.has(id)) {
219
- const taskInfo = this.taskRegistry.get(id);
220
- if (taskInfo) {
221
- const context = this.chatService?.getContext();
222
- const allAgents = (0, agents_1.agents)();
223
- const selectedAgent = allAgents[taskInfo.agentName];
224
- if (context && selectedAgent) {
225
- context.selectedAgent = selectedAgent;
226
- context.agentMode = true;
227
- context.currentAgent = taskInfo.agentName;
228
- context.currentModel = selectedAgent.getModel();
229
- context.currentProvider = selectedAgent.getProvider();
230
- console.log(`🔄 Switched to agent mode with ${taskInfo.agentName}`);
231
- console.log(`📋 Attached to running task: ${id}`);
232
- console.log(`Task: ${taskInfo.initialInput}`);
233
- console.log(`Status: ${taskInfo.status}`);
234
- return;
235
- }
236
- }
237
- console.log(index_2.Marked.parse(`**Attached to running task: ${id}**`));
238
- return;
239
- }
240
- try {
241
- const session = this.sessionManager.loadSession(id);
242
- if (session) {
243
- console.log(index_2.Marked.parse(`**Resuming saved session: ${id}**`));
244
- const context = this.chatService?.getContext();
245
- const allAgents = (0, agents_1.agents)();
246
- const selectedAgent = allAgents[session.agentName];
247
- if (context && selectedAgent) {
248
- context.selectedAgent = selectedAgent;
249
- context.agentMode = true;
250
- context.currentModel = selectedAgent.getModel();
251
- context.currentProvider = selectedAgent.getProvider();
252
- console.log(`🔄 Switched to agent mode with ${session.agentName}`);
253
- console.log(`📋 Resuming saved session: ${id}`);
254
- console.log(`Original task: ${session.initialInput}`);
255
- console.log(`Status: ${session.status}`);
256
- const addedContext = await this.chatService.getInput("Add any additional context for resuming this session (or press Enter to skip): ");
257
- await this.resumeSession(id);
258
- return;
259
- }
260
- }
261
- }
262
- catch (error) {
263
- }
264
- console.log(index_2.Marked.parse(`**Session/Task ${id} not found.**`));
265
- }
266
- async listAvailableSessions() {
267
- return this.sessionManager.listAvailableSessions();
268
- }
269
- async listSessionsAndTasks() {
270
- const runningTasks = this.taskRegistry.getAll();
271
- const savedSessions = this.sessionManager.listAvailableSessions();
272
- return {
273
- runningTasks,
274
- savedSessions,
275
- };
276
- }
277
- getTaskRegistry() {
278
- return this.taskRegistry;
323
+ getProcessStartTime() {
324
+ return this.processStartTime;
279
325
  }
280
326
  async resumeSession(sessionId, resumeReason) {
281
327
  try {
@@ -327,6 +373,13 @@ Please continue from where you left off and complete the original request.
327
373
  }
328
374
  async handleInput(input, context) {
329
375
  if (context.agentMode && context.selectedAgent) {
376
+ if (this.attachedAgent) {
377
+ this.attachedAgent.addPendingUserMessage({
378
+ role: "user",
379
+ content: input,
380
+ });
381
+ return true;
382
+ }
330
383
  const initialInteraction = {
331
384
  input,
332
385
  output: "",
@@ -343,12 +396,12 @@ Please continue from where you left off and complete the original request.
343
396
  return false;
344
397
  }
345
398
  async setupAgent(options) {
346
- const allAgents = (0, agents_1.agents)();
347
- if (!allAgents[options.agentName]) {
348
- throw new Error(`Agent "${options.agentName}" not found. Available agents: ${Object.keys(allAgents).join(", ")}`);
399
+ if (!agents_1.agentConstructors[options.agentName]) {
400
+ throw new Error(`Agent "${options.agentName}" not found. Available agents: ${Object.keys(agents_1.agentConstructors).join(", ")}`);
349
401
  }
350
402
  const { input, chatHistory = [], agentName } = options;
351
- const agent = allAgents[options.agentName];
403
+ const agentContext = (0, index_2.services)().Agents.getAgentContext();
404
+ const agent = (0, agents_1.createAgent)(options.agentName, agentContext);
352
405
  let done = false;
353
406
  let output = "Done";
354
407
  const taskId = options.taskId || this.sessionManager.generateTaskId(input);
@@ -371,38 +424,27 @@ Please continue from where you left off and complete the original request.
371
424
  };
372
425
  this.taskRegistry.register(taskId, taskInfo);
373
426
  this.saveSession(taskId, taskInfo, []);
374
- this.webSync.reset();
375
- this.fsSync.reset();
376
- if (options.messageId &&
377
- !options.existingKnowhowTaskId &&
378
- !options.syncFs) {
379
- knowhowTaskId = await this.webSync.createChatTask({
380
- messageId: options.messageId,
381
- prompt: input,
382
- });
383
- if (knowhowTaskId) {
384
- taskInfo.knowhowTaskId = knowhowTaskId;
385
- this.taskRegistry.register(taskId, taskInfo);
386
- await this.webSync.setupAgentSync(agent, knowhowTaskId);
387
- }
388
- }
389
- else if (!options.messageId || options.syncFs) {
390
- console.log(`📁 Using filesystem-based synchronization for task: ${taskId}`);
391
- const fsTaskId = await this.fsSync.createTask({
392
- taskId,
393
- prompt: input,
394
- });
395
- taskInfo.knowhowTaskId = fsTaskId;
396
- this.taskRegistry.register(taskId, taskInfo);
397
- await this.fsSync.setupAgentSync(agent, fsTaskId);
398
- }
427
+ this.syncer.reset();
428
+ const syncTaskId = await this.syncer.createTask({
429
+ taskId,
430
+ prompt: input,
431
+ messageId: options.messageId,
432
+ syncFs: options.syncFs,
433
+ existingKnowhowTaskId: options.existingKnowhowTaskId,
434
+ agentName,
435
+ });
436
+ const webTaskId = this.syncer.getCreatedWebTaskId();
437
+ knowhowTaskId = webTaskId;
438
+ taskInfo.knowhowTaskId = webTaskId || syncTaskId;
439
+ this.taskRegistry.register(taskId, taskInfo);
440
+ await this.syncer.setupAgentSync(agent, syncTaskId);
399
441
  const threadUpdateHandler = async (threadState) => {
400
442
  this.updateSession(taskId, threadState);
401
443
  taskInfo.totalCost = agent.getTotalCostUsd();
402
444
  };
403
445
  agent.agentEvents.on(agent.eventTypes.threadUpdate, threadUpdateHandler);
404
- console.log(index_2.Marked.parse(`**Starting ${agent.name} with task ID: ${taskId}...**`));
405
- console.log(index_2.Marked.parse(`**Task:** ${input}`));
446
+ console.log(index_3.Marked.parse(`**Starting ${agent.name} with task ID: ${taskId}...**`));
447
+ console.log(index_3.Marked.parse(`**Task:** ${input}`));
406
448
  await agent.newTask(taskId);
407
449
  if (options.model) {
408
450
  console.log("Setting model:", options.model);
@@ -418,7 +460,7 @@ Please continue from where you left off and complete the original request.
418
460
  throw new Error("ChatService not available in tools context");
419
461
  }
420
462
  console.log("AI has asked: ");
421
- console.log(index_2.Marked.parse(question), "\n");
463
+ console.log(index_3.Marked.parse(question), "\n");
422
464
  return await chatService.getInput("response: ");
423
465
  }, 10);
424
466
  const caching = [
@@ -426,53 +468,57 @@ Please continue from where you left off and complete the original request.
426
468
  new TokenCompressor_1.TokenCompressor(agent.tools).createProcessor((msg) => Boolean(msg.role === "tool" && msg.tool_call_id)),
427
469
  ];
428
470
  agent.messageProcessor.setProcessors("pre_call", [
429
- new index_3.Base64ImageProcessor(agent.tools).createProcessor(),
471
+ new index_4.Base64ImageProcessor(agent.tools).createProcessor(),
430
472
  ...caching,
431
- new index_3.CustomVariables(agent.tools).createProcessor(),
473
+ new index_4.CustomVariables(agent.tools).createProcessor(),
432
474
  ]);
433
475
  agent.messageProcessor.setProcessors("post_call", [
434
- new index_3.XmlToolCallProcessor().createProcessor(),
435
- new index_3.HarmonyToolProcessor().createProcessor(),
476
+ new index_4.XmlToolCallProcessor().createProcessor(),
477
+ new index_4.HarmonyToolProcessor().createProcessor(),
436
478
  ]);
437
479
  agent.messageProcessor.setProcessors("post_tools", [
438
- new index_3.Base64ImageProcessor(agent.tools).createProcessor(),
480
+ new index_4.Base64ImageProcessor(agent.tools).createProcessor(),
439
481
  ...caching,
440
482
  ]);
441
- if (!agent.agentEvents.listenerCount(agent.eventTypes.toolCall)) {
442
- agent.agentEvents.on(agent.eventTypes.toolCall, (responseMsg) => {
443
- console.time(JSON.stringify(responseMsg.toolCall.function.name));
444
- console.log(` 🔨 Tool: ${responseMsg.toolCall.function.name}\n Args: ${responseMsg.toolCall.function.arguments}\n`);
483
+ const agentLogHandler = (logData) => {
484
+ this.renderer.render({
485
+ type: "log",
486
+ taskId,
487
+ agentName: logData.agentName,
488
+ message: logData.message,
489
+ level: logData.level,
490
+ timestamp: logData.timestamp,
445
491
  });
446
- }
447
- if (!agent.agentEvents.listenerCount(agent.eventTypes.toolUsed)) {
448
- agent.agentEvents.on(agent.eventTypes.toolUsed, (responseMsg) => {
449
- console.timeEnd(JSON.stringify(responseMsg.toolCall.function.name));
450
- console.log(` 🔨 Tool Response:
451
- ${JSON.stringify(responseMsg.functionResp, null, 2)}`);
492
+ };
493
+ const agentStatusHandler = (statusData) => {
494
+ this.renderer.render({
495
+ type: "agentStatus",
496
+ taskId,
497
+ agentName: statusData.agentName,
498
+ statusMessage: statusData.statusMessage,
499
+ details: statusData.details,
500
+ timestamp: statusData.timestamp,
452
501
  });
453
- }
502
+ };
503
+ agent.agentEvents.on(agent.eventTypes.agentLog, agentLogHandler);
504
+ agent.agentEvents.on(agent.eventTypes.agentStatus, agentStatusHandler);
454
505
  const taskCompleted = new Promise((resolve) => {
455
506
  agent.agentEvents.once(agent.eventTypes.done, async (doneMsg) => {
456
507
  console.log("🎯 [AgentModule] Task Completed");
457
508
  done = true;
458
509
  output = doneMsg || "No response from the AI";
459
510
  agent.agentEvents.removeListener(agent.eventTypes.threadUpdate, threadUpdateHandler);
511
+ agent.agentEvents.removeListener(agent.eventTypes.agentLog, agentLogHandler);
512
+ agent.agentEvents.removeListener(agent.eventTypes.agentStatus, agentStatusHandler);
460
513
  taskInfo = this.taskRegistry.get(taskId);
461
- if (knowhowTaskId) {
462
- console.log("🎯 [AgentModule] Waiting for web sync finalization...");
463
- await this.webSync.waitForFinalization();
464
- console.log("🎯 [AgentModule] Web sync finalization complete");
465
- }
466
- console.log("🎯 [AgentModule] Waiting for fs sync finalization...");
467
- await this.fsSync.waitForFinalization();
468
- console.log("🎯 [AgentModule] Fs sync finalization complete");
514
+ await this.syncer.waitForFinalization();
469
515
  if (taskInfo) {
470
516
  taskInfo.status = "completed";
471
517
  taskInfo.totalCost = agent.getTotalCostUsd();
472
518
  this.updateSession(taskId, agent.getThreads());
473
519
  taskInfo.endTime = Date.now();
474
520
  }
475
- console.log(index_2.Marked.parse(output));
521
+ console.log(index_3.Marked.parse(output));
476
522
  console.log("🎯 [AgentModule] Task Complete");
477
523
  resolve(doneMsg);
478
524
  });
@@ -589,10 +635,10 @@ Please continue from where you left off and complete the original request.
589
635
  }
590
636
  attachToTask(taskId) {
591
637
  if (this.taskRegistry.has(taskId)) {
592
- console.log(index_2.Marked.parse(`**Attached to agent task: ${taskId}**`));
638
+ console.log(index_3.Marked.parse(`**Attached to agent task: ${taskId}**`));
593
639
  return true;
594
640
  }
595
- console.log(index_2.Marked.parse(`**Task ${taskId} not found or already completed.**`));
641
+ console.log(index_3.Marked.parse(`**Task ${taskId} not found or already completed.**`));
596
642
  return false;
597
643
  }
598
644
  saveSession(taskId, taskInfo, threads) {
@@ -620,91 +666,35 @@ Please continue from where you left off and complete the original request.
620
666
  }
621
667
  async attachedAgentChatLoop(taskId, agent, initialInput) {
622
668
  try {
623
- let done = false;
624
- let output = "Done";
625
669
  let agentFinalOutput;
626
670
  if (this.chatService) {
627
671
  this.chatService.setMode("agent:attached");
628
672
  }
629
- const modeCommands = this.chatService
630
- ?.getCommandsForMode("agent:attached")
631
- .map((cmd) => `/${cmd.name}`) || [];
632
- const commands = [
633
- ...modeCommands,
634
- "/pause",
635
- "/unpause",
636
- "/kill",
637
- "/detach",
638
- "/done",
639
- ];
640
- const history = [];
641
- let finished = false;
673
+ this.wireAgentRendering(taskId, agent.agentEvents, agent.eventTypes, agent.name);
674
+ const context = this.chatService?.getContext();
675
+ if (context)
676
+ context.activeAgentTaskId = taskId;
677
+ this.attachedAgent = agent;
642
678
  const donePromise = new Promise((resolve) => {
643
679
  agent.agentEvents.once(agent.eventTypes.done, (doneMsg) => {
644
680
  agentFinalOutput = doneMsg || "No response from the AI";
645
681
  console.log("Finished", taskId, `$${agent.getTotalCostUsd()}`);
646
- finished = true;
682
+ const finalTaskInfo = this.taskRegistry.get(taskId);
683
+ if (finalTaskInfo) {
684
+ if (finalTaskInfo.status === "running") {
685
+ finalTaskInfo.status = "completed";
686
+ finalTaskInfo.totalCost = agent.getTotalCostUsd();
687
+ finalTaskInfo.endTime = Date.now();
688
+ }
689
+ }
647
690
  resolve("done");
691
+ this.detachFromAgent();
648
692
  });
649
693
  });
650
694
  if (initialInput) {
651
695
  const taskInfo = this.taskRegistry.get(taskId);
652
696
  agent.call(taskInfo?.formattedPrompt || taskInfo?.initialInput || initialInput);
653
697
  }
654
- let input = (await this.chatService?.getInput(`Enter command or message for ${agent.name}: `, commands)) || "";
655
- history.push(input);
656
- while (!done) {
657
- switch (input) {
658
- case "":
659
- if (finished) {
660
- output = "Agent has completed the task.";
661
- done = true;
662
- }
663
- break;
664
- case "/done":
665
- output = "Exited agent interaction.";
666
- done = true;
667
- break;
668
- case "/pause":
669
- await agent.pause();
670
- console.log("Agent paused.");
671
- break;
672
- case "/unpause":
673
- await agent.unpause();
674
- console.log("Agent unpaused.");
675
- break;
676
- case "/kill":
677
- await agent.kill();
678
- console.log("Agent terminated.");
679
- done = true;
680
- break;
681
- case "/detach":
682
- console.log("Detached from agent");
683
- if (this.chatService) {
684
- this.chatService.setMode("default");
685
- }
686
- return { result: true, finalOutput: agentFinalOutput };
687
- default:
688
- agent.addPendingUserMessage({
689
- role: "user",
690
- content: input,
691
- });
692
- }
693
- if (!done) {
694
- input = await this.chatService?.getInput(`Enter command or message for ${agent.name}: `, commands);
695
- }
696
- }
697
- if (this.chatService) {
698
- this.chatService.setMode("default");
699
- }
700
- const finalTaskInfo = this.taskRegistry.get(taskId);
701
- if (finalTaskInfo) {
702
- if (finalTaskInfo.status === "running") {
703
- finalTaskInfo.status = "completed";
704
- finalTaskInfo.totalCost = agent.getTotalCostUsd();
705
- finalTaskInfo.endTime = Date.now();
706
- }
707
- }
708
698
  return { result: true, finalOutput: agentFinalOutput };
709
699
  }
710
700
  catch (error) {