@curie-agent/daemon 0.2.5
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/LICENSE +179 -0
- package/dist/src/approval-tracker.d.ts +42 -0
- package/dist/src/approval-tracker.d.ts.map +1 -0
- package/dist/src/approval-tracker.js +78 -0
- package/dist/src/approval-tracker.js.map +1 -0
- package/dist/src/auth.d.ts +17 -0
- package/dist/src/auth.d.ts.map +1 -0
- package/dist/src/auth.js +94 -0
- package/dist/src/auth.js.map +1 -0
- package/dist/src/channel-manager.d.ts +50 -0
- package/dist/src/channel-manager.d.ts.map +1 -0
- package/dist/src/channel-manager.js +184 -0
- package/dist/src/channel-manager.js.map +1 -0
- package/dist/src/daemon-app.d.ts +88 -0
- package/dist/src/daemon-app.d.ts.map +1 -0
- package/dist/src/daemon-app.js +496 -0
- package/dist/src/daemon-app.js.map +1 -0
- package/dist/src/index.d.ts +19 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +26 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/jsonrpc-handler.d.ts +47 -0
- package/dist/src/jsonrpc-handler.d.ts.map +1 -0
- package/dist/src/jsonrpc-handler.js +2205 -0
- package/dist/src/jsonrpc-handler.js.map +1 -0
- package/dist/src/server.d.ts +49 -0
- package/dist/src/server.d.ts.map +1 -0
- package/dist/src/server.js +204 -0
- package/dist/src/server.js.map +1 -0
- package/dist/src/slash-cd.d.ts +38 -0
- package/dist/src/slash-cd.d.ts.map +1 -0
- package/dist/src/slash-cd.js +93 -0
- package/dist/src/slash-cd.js.map +1 -0
- package/dist/src/static-files.d.ts +7 -0
- package/dist/src/static-files.d.ts.map +1 -0
- package/dist/src/static-files.js +73 -0
- package/dist/src/static-files.js.map +1 -0
- package/dist/src/ws-handler.d.ts +21 -0
- package/dist/src/ws-handler.d.ts.map +1 -0
- package/dist/src/ws-handler.js +119 -0
- package/dist/src/ws-handler.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +37 -0
|
@@ -0,0 +1,496 @@
|
|
|
1
|
+
import { homedir } from 'node:os';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { readFileSync, existsSync } from 'node:fs';
|
|
4
|
+
import { TaskManager, TelegramGateway, HeartbeatExecutor, HeartbeatDelivery, SubagentExecutor, computeNextFire, migrateTasks } from '@curie-agent/core';
|
|
5
|
+
import { ApprovalTracker } from './approval-tracker.js';
|
|
6
|
+
import { ChannelManager } from './channel-manager.js';
|
|
7
|
+
/**
|
|
8
|
+
* Central orchestrator for the daemon. Wires together:
|
|
9
|
+
* - ChannelManager (per-channel TurnLoop)
|
|
10
|
+
* - ApprovalTracker (cross-client approval resolution)
|
|
11
|
+
* - TaskManager (heartbeats, reminders, scheduled tasks)
|
|
12
|
+
* - TelegramGateway (Telegram bot)
|
|
13
|
+
* - MCP tool management
|
|
14
|
+
*/
|
|
15
|
+
export class DaemonApp {
|
|
16
|
+
eventBus;
|
|
17
|
+
sessionStore;
|
|
18
|
+
settingsManager;
|
|
19
|
+
createProvider;
|
|
20
|
+
tools;
|
|
21
|
+
mcpServers;
|
|
22
|
+
sendMessage;
|
|
23
|
+
systemPrompt;
|
|
24
|
+
channelManager;
|
|
25
|
+
approvalTracker;
|
|
26
|
+
/** Unified task manager — primary store for all tasks (manual, auto, notify). */
|
|
27
|
+
taskManager;
|
|
28
|
+
subagentExecutor;
|
|
29
|
+
telegramGateway = null;
|
|
30
|
+
mcpStatus = [];
|
|
31
|
+
checkerTimer = null;
|
|
32
|
+
unsubscribes = [];
|
|
33
|
+
/** Maps task ID → subagent agentId for auto-mode tasks. */
|
|
34
|
+
taskIdAgentMap = new Map();
|
|
35
|
+
/** Reverse map: subagent agentId → task ID. */
|
|
36
|
+
agentIdTaskMap = new Map();
|
|
37
|
+
constructor(eventBus, sessionStore, settingsManager, createProvider, tools = [], mcpServers, sendMessage, systemPrompt) {
|
|
38
|
+
this.eventBus = eventBus;
|
|
39
|
+
this.sessionStore = sessionStore;
|
|
40
|
+
this.settingsManager = settingsManager;
|
|
41
|
+
this.createProvider = createProvider;
|
|
42
|
+
this.tools = tools;
|
|
43
|
+
this.mcpServers = mcpServers;
|
|
44
|
+
this.sendMessage = sendMessage;
|
|
45
|
+
this.systemPrompt = systemPrompt;
|
|
46
|
+
this.approvalTracker = new ApprovalTracker(eventBus);
|
|
47
|
+
this.channelManager = new ChannelManager(eventBus, sessionStore, settingsManager, createProvider, tools, this.approvalTracker, this.systemPrompt);
|
|
48
|
+
this.taskManager = new TaskManager();
|
|
49
|
+
this.subagentExecutor = new SubagentExecutor(eventBus, sessionStore);
|
|
50
|
+
}
|
|
51
|
+
/** Start all subsystems. */
|
|
52
|
+
async start() {
|
|
53
|
+
const settings = this.settingsManager.get();
|
|
54
|
+
// Start Telegram gateway if configured
|
|
55
|
+
if (settings.channels?.bot_token && settings.channels?.user_id) {
|
|
56
|
+
this.telegramGateway = new TelegramGateway({
|
|
57
|
+
botToken: settings.channels.bot_token,
|
|
58
|
+
allowedUserId: settings.channels.user_id,
|
|
59
|
+
onUserMessage: (ctx) => this.handleTelegramMessage(ctx),
|
|
60
|
+
onApprovalDecision: (toolCallId, approved) => {
|
|
61
|
+
this.approvalTracker.decide(toolCallId, approved ? 'allow' : 'deny');
|
|
62
|
+
},
|
|
63
|
+
onError: (err) => {
|
|
64
|
+
console.error('[telegram] Error:', err.message);
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
this.telegramGateway.start();
|
|
68
|
+
}
|
|
69
|
+
// Run migration: merge legacy todo.json + cron.json → tasks.json (runs once)
|
|
70
|
+
try {
|
|
71
|
+
migrateTasks();
|
|
72
|
+
}
|
|
73
|
+
catch (err) {
|
|
74
|
+
console.error('[daemon] Migration error:', err);
|
|
75
|
+
}
|
|
76
|
+
// Ensure heartbeat is correctly scheduled if enabled
|
|
77
|
+
this.taskManager.load();
|
|
78
|
+
if (settings.heartbeat?.schedule === 'on') {
|
|
79
|
+
const hb = settings.heartbeat;
|
|
80
|
+
this.taskManager.rescheduleFromSettings({
|
|
81
|
+
HEARTBEAT_INTRADAY: hb.intraday,
|
|
82
|
+
HEARTBEAT_DAILY: hb.daily,
|
|
83
|
+
HEARTBEAT_WEEKLY: hb.weekly,
|
|
84
|
+
HEARTBEAT_MONTHLY: hb.monthly,
|
|
85
|
+
HEARTBEAT_DREAMING: hb.dreaming,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
// Subscribe to configuration changes to auto-reschedule cron
|
|
89
|
+
this.unsubscribes.push(this.eventBus.subscribe('config-changed', () => {
|
|
90
|
+
this.taskManager.load();
|
|
91
|
+
const freshSettings = this.settingsManager.get();
|
|
92
|
+
if (freshSettings.heartbeat?.schedule === 'on') {
|
|
93
|
+
const hb = freshSettings.heartbeat;
|
|
94
|
+
this.taskManager.rescheduleFromSettings({
|
|
95
|
+
HEARTBEAT_INTRADAY: hb.intraday,
|
|
96
|
+
HEARTBEAT_DAILY: hb.daily,
|
|
97
|
+
HEARTBEAT_WEEKLY: hb.weekly,
|
|
98
|
+
HEARTBEAT_MONTHLY: hb.monthly,
|
|
99
|
+
HEARTBEAT_DREAMING: hb.dreaming,
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
// Cancel all pending heartbeat tasks
|
|
104
|
+
this.taskManager.cancelAllHeartbeats();
|
|
105
|
+
}
|
|
106
|
+
}));
|
|
107
|
+
// Start cron checker
|
|
108
|
+
this.startCronChecker();
|
|
109
|
+
// Subscribe to subagent lifecycle events for auto-mode task status updates
|
|
110
|
+
this.unsubscribes.push(this.eventBus.subscribe('agent-done', (event) => {
|
|
111
|
+
const meta = event.metadata;
|
|
112
|
+
if (meta?.taskId && meta?.taskType === 'auto') {
|
|
113
|
+
const taskId = meta.taskId;
|
|
114
|
+
this.taskManager.load();
|
|
115
|
+
const task = this.taskManager.findTask(taskId);
|
|
116
|
+
if (task) {
|
|
117
|
+
// Clear the map entries
|
|
118
|
+
this.taskIdAgentMap.delete(taskId);
|
|
119
|
+
const agentId = this.agentIdTaskMap.get(taskId);
|
|
120
|
+
if (agentId)
|
|
121
|
+
this.agentIdTaskMap.delete(agentId);
|
|
122
|
+
// Update task status; store result text if available
|
|
123
|
+
const text = event.text;
|
|
124
|
+
this.taskManager.updateTaskStatus(taskId, 'completed');
|
|
125
|
+
if (task.metadata) {
|
|
126
|
+
task.metadata.resultText = text;
|
|
127
|
+
this.taskManager.save();
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}));
|
|
132
|
+
this.unsubscribes.push(this.eventBus.subscribe('agent-error', (event) => {
|
|
133
|
+
const meta = event.metadata;
|
|
134
|
+
if (meta?.taskId && meta?.taskType === 'auto') {
|
|
135
|
+
const taskId = meta.taskId;
|
|
136
|
+
this.taskManager.load();
|
|
137
|
+
this.taskManager.updateTaskStatus(taskId, 'failed');
|
|
138
|
+
this.taskIdAgentMap.delete(taskId);
|
|
139
|
+
const agentId = this.agentIdTaskMap.get(taskId);
|
|
140
|
+
if (agentId)
|
|
141
|
+
this.agentIdTaskMap.delete(agentId);
|
|
142
|
+
}
|
|
143
|
+
}));
|
|
144
|
+
// Emit daemon-ready event
|
|
145
|
+
this.eventBus.emit({
|
|
146
|
+
type: 'daemon-ready',
|
|
147
|
+
id: crypto.randomUUID(),
|
|
148
|
+
version: '0.2.4',
|
|
149
|
+
timestamp: Date.now(),
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
/** Stop all subsystems. */
|
|
153
|
+
async stop() {
|
|
154
|
+
this.stopCronChecker();
|
|
155
|
+
for (const unsub of this.unsubscribes) {
|
|
156
|
+
unsub();
|
|
157
|
+
}
|
|
158
|
+
this.unsubscribes = [];
|
|
159
|
+
this.telegramGateway?.stop();
|
|
160
|
+
this.channelManager.cleanup();
|
|
161
|
+
this.approvalTracker.clear();
|
|
162
|
+
this.subagentExecutor.shutdown();
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Handle incoming Telegram message. Routes to the appropriate
|
|
166
|
+
* channel, then calls back to the sender.
|
|
167
|
+
*/
|
|
168
|
+
handleTelegramMessage(ctx) {
|
|
169
|
+
const route = this.channelManager.routeTelegramMessage({
|
|
170
|
+
chatId: ctx.chatId,
|
|
171
|
+
userId: ctx.userId,
|
|
172
|
+
isGroup: ctx.isGroup,
|
|
173
|
+
chatTitle: ctx.chatTitle,
|
|
174
|
+
});
|
|
175
|
+
if (!route) {
|
|
176
|
+
console.log('[telegram] Message rejected (group not allowed)');
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
// Emit the message as a user-prompt event so clients can see it
|
|
180
|
+
this.eventBus.emit({
|
|
181
|
+
type: 'user-prompt',
|
|
182
|
+
id: crypto.randomUUID(),
|
|
183
|
+
text: ctx.text,
|
|
184
|
+
cwd: join(homedir(), '.curie-agent'),
|
|
185
|
+
timestamp: Date.now(),
|
|
186
|
+
});
|
|
187
|
+
// Process the message asynchronously — response will be sent
|
|
188
|
+
// back via TelegramGateway when the turn completes
|
|
189
|
+
this.processTelegramTurn(route.channelId, route.sessionId, ctx.text, ctx.chatId);
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Process a Telegram turn. Sends the message to the TurnLoop,
|
|
193
|
+
* collects the response, and delivers it back via Telegram.
|
|
194
|
+
*/
|
|
195
|
+
async processTelegramTurn(channelId, sessionId, text, chatId) {
|
|
196
|
+
try {
|
|
197
|
+
if (!this.createProvider) {
|
|
198
|
+
await this.sendTelegram(chatId, 'Error: no provider configured');
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
const settings = this.settingsManager.get();
|
|
202
|
+
const provider = this.createProvider(settings);
|
|
203
|
+
// Collect assistant text
|
|
204
|
+
let assistantText = '';
|
|
205
|
+
const { TurnLoop } = await import('@curie-agent/core');
|
|
206
|
+
const loop = new TurnLoop({
|
|
207
|
+
provider,
|
|
208
|
+
model: settings.model_override || settings.model,
|
|
209
|
+
tools: this.tools,
|
|
210
|
+
cwd: join(homedir(), '.curie-agent'),
|
|
211
|
+
settings,
|
|
212
|
+
approvalMode: settings.mode || 'auto',
|
|
213
|
+
effort: settings.effort,
|
|
214
|
+
sessionId,
|
|
215
|
+
resume: !!sessionId,
|
|
216
|
+
system: this.systemPrompt,
|
|
217
|
+
onApprovalAsk: async (req) => {
|
|
218
|
+
const toolCallId = req.toolCallId || crypto.randomUUID();
|
|
219
|
+
// Send approval request to Telegram
|
|
220
|
+
if (this.telegramGateway) {
|
|
221
|
+
this.telegramGateway.sendApprovalRequest(chatId, toolCallId, req.name, JSON.stringify(req.input).slice(0, 200));
|
|
222
|
+
}
|
|
223
|
+
return this.approvalTracker.register({
|
|
224
|
+
toolCallId, name: req.name, input: req.input,
|
|
225
|
+
sessionId, channelId,
|
|
226
|
+
});
|
|
227
|
+
},
|
|
228
|
+
type: 'telegram',
|
|
229
|
+
}, this.sessionStore);
|
|
230
|
+
// Bridge events to shared bus
|
|
231
|
+
const eventTypes = [
|
|
232
|
+
'assistant-delta', 'tool-call', 'tool-result',
|
|
233
|
+
'error', 'session-start', 'session-stop',
|
|
234
|
+
];
|
|
235
|
+
const unsubs = eventTypes.map(type => loop.eventBus.subscribe(type, (event) => this.eventBus.emit(event)));
|
|
236
|
+
// Also collect assistant text for Telegram delivery
|
|
237
|
+
unsubs.push(loop.eventBus.subscribe('assistant-delta', (e) => {
|
|
238
|
+
if (e.type === 'assistant-delta')
|
|
239
|
+
assistantText += e.text;
|
|
240
|
+
}));
|
|
241
|
+
try {
|
|
242
|
+
await loop.run(text);
|
|
243
|
+
}
|
|
244
|
+
finally {
|
|
245
|
+
unsubs.forEach(u => u());
|
|
246
|
+
}
|
|
247
|
+
// Send response back (truncate to Telegram limit)
|
|
248
|
+
const response = assistantText.slice(0, 4096);
|
|
249
|
+
if (response) {
|
|
250
|
+
await this.sendTelegram(chatId, response);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
catch (err) {
|
|
254
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
255
|
+
await this.sendTelegram(chatId, `Error: ${msg}`);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
/** Send a message to Telegram chat. */
|
|
259
|
+
async sendTelegram(chatId, text) {
|
|
260
|
+
if (this.telegramGateway) {
|
|
261
|
+
await this.telegramGateway.sendMessage(chatId, text);
|
|
262
|
+
}
|
|
263
|
+
else if (this.sendMessage) {
|
|
264
|
+
await this.sendMessage(chatId, text);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
/** Start the cron checker (heartbeat + scheduled tasks + reminders). */
|
|
268
|
+
startCronChecker(intervalMs = 60_000) {
|
|
269
|
+
this.checkerTimer = setInterval(async () => {
|
|
270
|
+
this.taskManager.load();
|
|
271
|
+
const now = Date.now();
|
|
272
|
+
const pendingTasks = this.taskManager.list({ status: 'pending' });
|
|
273
|
+
for (const task of pendingTasks) {
|
|
274
|
+
if (!task.scheduled_at || task.scheduled_at > now)
|
|
275
|
+
continue;
|
|
276
|
+
if (this.taskManager.isHeartbeat(task)) {
|
|
277
|
+
// Recurring heartbeat — update scheduled_at before firing
|
|
278
|
+
const oldScheduledAt = task.scheduled_at;
|
|
279
|
+
if (task.frequency) {
|
|
280
|
+
task.scheduled_at = computeNextFire({ type: task.frequency.type, value: task.frequency.value }, now);
|
|
281
|
+
this.taskManager.save();
|
|
282
|
+
}
|
|
283
|
+
await this.executeHeartbeatUnified(task, oldScheduledAt).catch(err => {
|
|
284
|
+
console.error('[DaemonApp] heartbeat run error:', err);
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
else if (task.mode === 'auto') {
|
|
288
|
+
// One-shot scheduled task (LLM executes)
|
|
289
|
+
await this.executeTaskUnified(task);
|
|
290
|
+
}
|
|
291
|
+
else if (task.mode === 'notify') {
|
|
292
|
+
// Reminder notification — mark done and emit event
|
|
293
|
+
this.taskManager.updateTaskStatus(task.id, 'done');
|
|
294
|
+
const event = {
|
|
295
|
+
type: 'cron-task-fired',
|
|
296
|
+
id: crypto.randomUUID(),
|
|
297
|
+
taskId: task.id,
|
|
298
|
+
taskType: 'notify',
|
|
299
|
+
message: task.title,
|
|
300
|
+
timestamp: Date.now(),
|
|
301
|
+
};
|
|
302
|
+
this.eventBus.emit(event);
|
|
303
|
+
// 1. Notify Web UI
|
|
304
|
+
const targetSessionId = this.sessionStore.list().sort((a, b) => b.updatedAt - a.updatedAt)[0]?.id;
|
|
305
|
+
if (targetSessionId) {
|
|
306
|
+
try {
|
|
307
|
+
this.sessionStore.appendEvent(targetSessionId, { ...event, sessionId: targetSessionId });
|
|
308
|
+
}
|
|
309
|
+
catch { /* ignore */ }
|
|
310
|
+
}
|
|
311
|
+
// 2. Notify Telegram
|
|
312
|
+
const settings = this.settingsManager.get();
|
|
313
|
+
if (settings.channels?.user_id) {
|
|
314
|
+
this.sendTelegram(settings.channels.user_id, `🔔 **Reminder:** ${task.title}`).catch(err => {
|
|
315
|
+
console.error('[DaemonApp] failed to send reminder to telegram:', err);
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}, intervalMs);
|
|
321
|
+
}
|
|
322
|
+
/** Stop the cron checker. */
|
|
323
|
+
stopCronChecker() {
|
|
324
|
+
if (this.checkerTimer) {
|
|
325
|
+
clearInterval(this.checkerTimer);
|
|
326
|
+
this.checkerTimer = null;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
/** Execute a scheduled task from unified TaskManager (auto mode). */
|
|
330
|
+
async executeTaskUnified(task) {
|
|
331
|
+
if (!this.createProvider)
|
|
332
|
+
return;
|
|
333
|
+
try {
|
|
334
|
+
const settings = this.settingsManager.get();
|
|
335
|
+
const provider = this.createProvider(settings);
|
|
336
|
+
const autoSystem = this.buildAutoSystemPrompt(task.title);
|
|
337
|
+
const fullSystem = this.systemPrompt
|
|
338
|
+
? `${this.systemPrompt}\n\n${autoSystem}`
|
|
339
|
+
: autoSystem;
|
|
340
|
+
const userPrompt = this.buildAutoUserPrompt(task.title);
|
|
341
|
+
this.taskManager.updateTaskStatus(task.id, 'executing');
|
|
342
|
+
const metadata = { taskId: task.id, taskType: 'auto' };
|
|
343
|
+
// Parse optional spawn overrides from task metadata (set via WebUI schedule form)
|
|
344
|
+
const spawnOverrides = task.metadata;
|
|
345
|
+
const effectiveModel = spawnOverrides?.model || settings.model_override || settings.model;
|
|
346
|
+
const effectiveEffort = spawnOverrides?.effort || settings.effort;
|
|
347
|
+
const handle = await this.subagentExecutor.spawn({
|
|
348
|
+
provider,
|
|
349
|
+
model: effectiveModel,
|
|
350
|
+
tools: this.tools,
|
|
351
|
+
cwd: join(homedir(), '.curie-agent'),
|
|
352
|
+
settings,
|
|
353
|
+
prompt: userPrompt,
|
|
354
|
+
system: fullSystem,
|
|
355
|
+
mode: 'auto',
|
|
356
|
+
effort: effectiveEffort,
|
|
357
|
+
type: 'subagent',
|
|
358
|
+
metadata,
|
|
359
|
+
});
|
|
360
|
+
// Track linkage for completion/cancel sync
|
|
361
|
+
this.taskIdAgentMap.set(task.id, handle.agentId);
|
|
362
|
+
this.agentIdTaskMap.set(handle.agentId, task.id);
|
|
363
|
+
}
|
|
364
|
+
catch (err) {
|
|
365
|
+
this.taskManager.updateTaskStatus(task.id, 'canceled');
|
|
366
|
+
console.error('[auto task] spawn failed:', err);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
/** Build system prompt for an auto-mode subagent — persistent identity + operational context. */
|
|
370
|
+
buildAutoSystemPrompt(taskTitle) {
|
|
371
|
+
const curieDir = join(homedir(), '.curie-agent');
|
|
372
|
+
// Read active tasks from unified format or legacy todo.json
|
|
373
|
+
let tasksSection = '';
|
|
374
|
+
const taskPath = join(curieDir, 'tasks.json');
|
|
375
|
+
if (existsSync(taskPath)) {
|
|
376
|
+
const raw = readFileSync(taskPath, 'utf-8');
|
|
377
|
+
try {
|
|
378
|
+
const parsed = JSON.parse(raw);
|
|
379
|
+
if (parsed.tasks?.length) {
|
|
380
|
+
tasksSection = `\n=== ACTIVE TASKS ===\n` + parsed.tasks.filter(t => t.status !== 'done').map(t => ` [${t.status}] ${t.title}`).join('\n');
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
catch { /* skip */ }
|
|
384
|
+
}
|
|
385
|
+
else {
|
|
386
|
+
const todoPath = join(curieDir, 'todo.json');
|
|
387
|
+
if (existsSync(todoPath)) {
|
|
388
|
+
const raw = readFileSync(todoPath, 'utf-8');
|
|
389
|
+
try {
|
|
390
|
+
const parsed = JSON.parse(raw);
|
|
391
|
+
if (parsed.tasks?.length) {
|
|
392
|
+
tasksSection = `\n=== ACTIVE TASKS ===\n` + parsed.tasks.filter(t => t.status !== 'done').map(t => ` [${t.status}] ${t.title}`).join('\n');
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
catch { /* skip */ }
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
const sections = [];
|
|
399
|
+
// Persistent user profile
|
|
400
|
+
const userMd = join(curieDir, 'USER.md');
|
|
401
|
+
if (existsSync(userMd)) {
|
|
402
|
+
sections.push(`=== USER PROFILE ===\n${readFileSync(userMd, 'utf-8')}`);
|
|
403
|
+
}
|
|
404
|
+
// Persistent agent memory
|
|
405
|
+
const memoryMd = join(curieDir, 'MEMORY.md');
|
|
406
|
+
if (existsSync(memoryMd)) {
|
|
407
|
+
sections.push(`=== AGENT MEMORY ===\n${readFileSync(memoryMd, 'utf-8')}`);
|
|
408
|
+
}
|
|
409
|
+
// Active tasks
|
|
410
|
+
if (tasksSection) {
|
|
411
|
+
sections.push(tasksSection.trimStart());
|
|
412
|
+
}
|
|
413
|
+
// Available tools listing
|
|
414
|
+
if (this.tools.length > 0) {
|
|
415
|
+
const toolList = this.tools.map(t => `- ${t.definition.name}: ${t.definition.description}`).join('\n');
|
|
416
|
+
sections.push(`=== AVAILABLE TOOLS ===\n${toolList}`);
|
|
417
|
+
}
|
|
418
|
+
// Subagent communication protocol
|
|
419
|
+
sections.push('=== COMMUNICATION PROTOCOL ===\nWhen you need a tool, call it through the tool-use interface.\nWhen done, respond with a clear summary of your results.');
|
|
420
|
+
return sections.join('\n\n');
|
|
421
|
+
}
|
|
422
|
+
/** Build user message for an auto-mode subagent — task instruction only. */
|
|
423
|
+
buildAutoUserPrompt(taskTitle) {
|
|
424
|
+
return `${taskTitle}\n\nExecute this task using available tools. Deliver a clear summary of your results.`;
|
|
425
|
+
}
|
|
426
|
+
/** Execute a heartbeat from unified TaskManager (auto mode + frequency). */
|
|
427
|
+
async executeHeartbeatUnified(task, oldScheduledAt) {
|
|
428
|
+
if (!this.createProvider)
|
|
429
|
+
return;
|
|
430
|
+
try {
|
|
431
|
+
const settings = this.settingsManager.get();
|
|
432
|
+
const provider = this.createProvider(settings);
|
|
433
|
+
const scheduleType = task.frequency?.type;
|
|
434
|
+
const executor = new HeartbeatExecutor({
|
|
435
|
+
provider,
|
|
436
|
+
model: settings.model_override || settings.model,
|
|
437
|
+
tools: this.tools,
|
|
438
|
+
cwd: join(homedir(), '.curie-agent'),
|
|
439
|
+
settings,
|
|
440
|
+
scheduleType,
|
|
441
|
+
system: this.systemPrompt,
|
|
442
|
+
});
|
|
443
|
+
const result = await executor.execute();
|
|
444
|
+
const formatted = HeartbeatDelivery.formatBrief(result);
|
|
445
|
+
this.eventBus.emit({
|
|
446
|
+
type: 'heartbeat-brief',
|
|
447
|
+
id: crypto.randomUUID(),
|
|
448
|
+
scheduleType: scheduleType || 'daily',
|
|
449
|
+
formattedText: formatted,
|
|
450
|
+
toolCalls: result.toolCalls,
|
|
451
|
+
maxTurns: result.maxTurns,
|
|
452
|
+
reason: result.reason,
|
|
453
|
+
errors: result.errors,
|
|
454
|
+
timestamp: Date.now(),
|
|
455
|
+
});
|
|
456
|
+
if (this.telegramGateway && settings.channels?.chat_id) {
|
|
457
|
+
await this.telegramGateway.sendMessage(settings.channels.chat_id, formatted);
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
catch (err) {
|
|
461
|
+
console.error('[unified heartbeat] Execution failed:', err);
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
/** Run an immediate heartbeat (triggered via RPC). */
|
|
465
|
+
async runHeartbeat(scheduleType) {
|
|
466
|
+
if (!this.createProvider) {
|
|
467
|
+
throw new Error('no provider configured');
|
|
468
|
+
}
|
|
469
|
+
const settings = this.settingsManager.get();
|
|
470
|
+
const provider = this.createProvider(settings);
|
|
471
|
+
const executor = new HeartbeatExecutor({
|
|
472
|
+
provider,
|
|
473
|
+
model: settings.model_override || settings.model,
|
|
474
|
+
tools: this.tools,
|
|
475
|
+
cwd: join(homedir(), '.curie-agent'),
|
|
476
|
+
settings,
|
|
477
|
+
scheduleType,
|
|
478
|
+
system: this.systemPrompt,
|
|
479
|
+
});
|
|
480
|
+
const result = await executor.execute();
|
|
481
|
+
const formatted = HeartbeatDelivery.formatBrief(result);
|
|
482
|
+
this.eventBus.emit({
|
|
483
|
+
type: 'heartbeat-brief',
|
|
484
|
+
id: crypto.randomUUID(),
|
|
485
|
+
scheduleType: scheduleType || 'daily',
|
|
486
|
+
formattedText: formatted,
|
|
487
|
+
toolCalls: result.toolCalls,
|
|
488
|
+
maxTurns: result.maxTurns,
|
|
489
|
+
reason: result.reason,
|
|
490
|
+
errors: result.errors,
|
|
491
|
+
timestamp: Date.now(),
|
|
492
|
+
});
|
|
493
|
+
return { text: formatted, toolCalls: result.toolCalls, maxTurns: result.maxTurns, reason: result.reason, errors: result.errors };
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
//# sourceMappingURL=daemon-app.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"daemon-app.js","sourceRoot":"","sources":["../../src/daemon-app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAKnD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C;YACjB,IAAI,EAAE,iBAAiB;YACvB,EAAE,EAAE,MAAM,CAAC,UAAU,EAAE;YACvB,YAAY,EAAE,YAAY,IAAI,OAAO;YACrC,aAAa,EAAE,SAAS;YACxB,SAAS,EAAE,MAAM,CAAC,SAAS;YAC3B,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;SACF,CAAC,CAAC;QAEvB,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,CAAC,SAAS,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC;IACnI,CAAC;CACF"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { DaemonServer, type DaemonConfig } from './server.js';
|
|
2
|
+
export { DaemonServer } from './server.js';
|
|
3
|
+
export type { DaemonConfig, ProviderFactory } from './server.js';
|
|
4
|
+
export { generateToken, loadToken, saveToken, ensureToken } from './auth.js';
|
|
5
|
+
export { JsonRpcHandler } from './jsonrpc-handler.js';
|
|
6
|
+
export type { JsonRpcRequest, JsonRpcResponse, JsonRpcError } from './jsonrpc-handler.js';
|
|
7
|
+
export { WsHandler } from './ws-handler.js';
|
|
8
|
+
export type { WsClientInfo } from './ws-handler.js';
|
|
9
|
+
export { DaemonApp } from './daemon-app.js';
|
|
10
|
+
export type { McpServerConfig, McpConnectionStatus, SendMessageFn } from './daemon-app.js';
|
|
11
|
+
export { ApprovalTracker } from './approval-tracker.js';
|
|
12
|
+
export { ChannelManager } from './channel-manager.js';
|
|
13
|
+
/** Get or create a daemon server instance. */
|
|
14
|
+
export declare function getOrCreateDaemonServer(config: DaemonConfig): DaemonServer;
|
|
15
|
+
/** Get the current daemon instance or null. */
|
|
16
|
+
export declare function getDaemonInstance(): DaemonServer | null;
|
|
17
|
+
/** Reset the singleton (for testing). */
|
|
18
|
+
export declare function resetDaemonInstance(): void;
|
|
19
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,KAAK,YAAY,EAAE,MAAM,aAAa,CAAC;AAG9D,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,YAAY,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAC7E,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,YAAY,EAAE,cAAc,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAC1F,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,YAAY,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,YAAY,EAAE,eAAe,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC3F,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAKtD,8CAA8C;AAC9C,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,YAAY,GAAG,YAAY,CAK1E;AAED,+CAA+C;AAC/C,wBAAgB,iBAAiB,IAAI,YAAY,GAAG,IAAI,CAEvD;AAED,yCAAyC;AACzC,wBAAgB,mBAAmB,IAAI,IAAI,CAE1C"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { DaemonServer } from './server.js';
|
|
2
|
+
export { DaemonServer } from './server.js';
|
|
3
|
+
export { generateToken, loadToken, saveToken, ensureToken } from './auth.js';
|
|
4
|
+
export { JsonRpcHandler } from './jsonrpc-handler.js';
|
|
5
|
+
export { WsHandler } from './ws-handler.js';
|
|
6
|
+
export { DaemonApp } from './daemon-app.js';
|
|
7
|
+
export { ApprovalTracker } from './approval-tracker.js';
|
|
8
|
+
export { ChannelManager } from './channel-manager.js';
|
|
9
|
+
// Singleton instance
|
|
10
|
+
let instance = null;
|
|
11
|
+
/** Get or create a daemon server instance. */
|
|
12
|
+
export function getOrCreateDaemonServer(config) {
|
|
13
|
+
if (!instance) {
|
|
14
|
+
instance = new DaemonServer(config);
|
|
15
|
+
}
|
|
16
|
+
return instance;
|
|
17
|
+
}
|
|
18
|
+
/** Get the current daemon instance or null. */
|
|
19
|
+
export function getDaemonInstance() {
|
|
20
|
+
return instance;
|
|
21
|
+
}
|
|
22
|
+
/** Reset the singleton (for testing). */
|
|
23
|
+
export function resetDaemonInstance() {
|
|
24
|
+
instance = null;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAqB,MAAM,aAAa,CAAC;AAG9D,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAC7E,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,qBAAqB;AACrB,IAAI,QAAQ,GAAwB,IAAI,CAAC;AAEzC,8CAA8C;AAC9C,MAAM,UAAU,uBAAuB,CAAC,MAAoB;IAC1D,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,QAAQ,GAAG,IAAI,YAAY,CAAC,MAAM,CAAC,CAAC;IACtC,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,+CAA+C;AAC/C,MAAM,UAAU,iBAAiB;IAC/B,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,yCAAyC;AACzC,MAAM,UAAU,mBAAmB;IACjC,QAAQ,GAAG,IAAI,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { EventBus } from '@curie-agent/core';
|
|
2
|
+
import type { SessionStore, SettingsManager, Tool } from '@curie-agent/core';
|
|
3
|
+
import type { ProviderFactory } from './server.js';
|
|
4
|
+
import type { DaemonApp } from './daemon-app.js';
|
|
5
|
+
export interface JsonRpcRequest {
|
|
6
|
+
jsonrpc: '2.0';
|
|
7
|
+
id: string | number;
|
|
8
|
+
method: string;
|
|
9
|
+
params?: Record<string, unknown>;
|
|
10
|
+
}
|
|
11
|
+
export interface JsonRpcResponse {
|
|
12
|
+
jsonrpc: '2.0';
|
|
13
|
+
id: string | number;
|
|
14
|
+
result: unknown;
|
|
15
|
+
}
|
|
16
|
+
export interface JsonRpcError {
|
|
17
|
+
jsonrpc: '2.0';
|
|
18
|
+
id: string | number;
|
|
19
|
+
error: {
|
|
20
|
+
code: number;
|
|
21
|
+
message: string;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export declare class JsonRpcHandler {
|
|
25
|
+
private sessionStore;
|
|
26
|
+
private settingsManager;
|
|
27
|
+
private sharedEventBus?;
|
|
28
|
+
private createProvider?;
|
|
29
|
+
private tools;
|
|
30
|
+
private daemonApp?;
|
|
31
|
+
private systemPrompt?;
|
|
32
|
+
private turnLoops;
|
|
33
|
+
constructor(sessionStore: SessionStore, settingsManager: SettingsManager, sharedEventBus?: EventBus | undefined, createProvider?: ProviderFactory | undefined, tools?: Tool[], daemonApp?: DaemonApp | undefined, systemPrompt?: string | undefined);
|
|
34
|
+
handle(request: JsonRpcRequest): Promise<JsonRpcResponse | JsonRpcError>;
|
|
35
|
+
private handleSend;
|
|
36
|
+
private getStringParam;
|
|
37
|
+
private paramError;
|
|
38
|
+
/** Get a nested value from an object using dot notation (e.g. "providers.anthropic.model"). */
|
|
39
|
+
private getNestedValue;
|
|
40
|
+
/** Get the current working directory from session metadata, falling back to process.cwd(). */
|
|
41
|
+
private getSessionCwd;
|
|
42
|
+
private executeSlashCommand;
|
|
43
|
+
private validatePricingString;
|
|
44
|
+
private runAutomaticCompaction;
|
|
45
|
+
private checkContextThresholds;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=jsonrpc-handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsonrpc-handler.d.ts","sourceRoot":"","sources":["../../src/jsonrpc-handler.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAyB,IAAI,EAAiB,MAAM,mBAAmB,CAAC;AAGnH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEjD,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,KAAK,CAAC;IACf,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,KAAK,CAAC;IACf,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;IACpB,MAAM,EAAE,OAAO,CAAC;CACjB;AAED,MA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