@hyperwindmill/caretaker-cli 0.21.0 → 0.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/web/scheduler/locks.d.ts +3 -3
- package/dist/cli/web/scheduler/task_roles.js +1 -1
- package/dist/cli/web/scheduler/task_strategy.js +4 -4
- package/dist/cli/web/server.d.ts.map +1 -1
- package/dist/cli/web/server.js +61 -26
- package/dist/harness/tools/builtin/email_tools.d.ts.map +1 -1
- package/dist/harness/tools/builtin/email_tools.js +33 -5
- package/dist/harness/tools/builtin/task_tools.js +37 -37
- package/dist/lib/docker.d.ts +1 -1
- package/dist/lib/docker.d.ts.map +1 -1
- package/dist/lib/docker.js +2 -2
- package/dist/lib/email.d.ts +17 -1
- package/dist/lib/email.d.ts.map +1 -1
- package/dist/lib/email.js +23 -1
- package/dist/lib/project_slug.d.ts +29 -0
- package/dist/lib/project_slug.d.ts.map +1 -0
- package/dist/lib/project_slug.js +41 -0
- package/dist/lib/task_git.d.ts +5 -5
- package/dist/lib/task_git.d.ts.map +1 -1
- package/dist/lib/task_git.js +8 -6
- package/dist/store/db.d.ts +12 -7
- package/dist/store/db.d.ts.map +1 -1
- package/dist/store/db.js +59 -15
- package/dist/store/json.d.ts +1 -0
- package/dist/store/json.d.ts.map +1 -1
- package/dist/store/json.js +6 -1
- package/dist/webview/standalone.js +45 -19
- package/dist/webview/standalone.js.map +2 -2
- package/package.json +4 -3
|
@@ -11,13 +11,13 @@ export declare const runningTasks: Set<string>;
|
|
|
11
11
|
* for the current cycle to burn through its turns — the whole point of Pause
|
|
12
12
|
* when an agent has gone off the rails.
|
|
13
13
|
*/
|
|
14
|
-
export declare const runningTaskControllers: Map<
|
|
14
|
+
export declare const runningTaskControllers: Map<string, AbortController>;
|
|
15
15
|
/** Abort the in-flight run for a task, if one is registered. Returns whether it fired. */
|
|
16
|
-
export declare function abortRunningTask(taskId:
|
|
16
|
+
export declare function abortRunningTask(taskId: string): boolean;
|
|
17
17
|
/**
|
|
18
18
|
* Project ids with a repository sync (clone/pull) in flight — shared between
|
|
19
19
|
* the heartbeat's pre-worktree sync and POST /api/projects/:id/sync so the
|
|
20
20
|
* two can never race a clone. Derived state only; never persisted.
|
|
21
21
|
*/
|
|
22
|
-
export declare const syncingProjects: Set<
|
|
22
|
+
export declare const syncingProjects: Set<string>;
|
|
23
23
|
//# sourceMappingURL=locks.d.ts.map
|
|
@@ -51,7 +51,7 @@ export function resolveSddEnabled(task, project) {
|
|
|
51
51
|
export async function activationStatus(task, project) {
|
|
52
52
|
if (!resolvePlanningEnabled(task, project))
|
|
53
53
|
return 'active';
|
|
54
|
-
const messages = (await runQuery(`SELECT * FROM task_messages WHERE taskId = ${task.id}`));
|
|
54
|
+
const messages = (await runQuery(`SELECT * FROM task_messages WHERE taskId = '${task.id}'`));
|
|
55
55
|
return messages.some((m) => m.messageType === 'plan') ? 'active' : 'planning';
|
|
56
56
|
}
|
|
57
57
|
/** Builtins the planner must not have: everything that mutates the workspace.
|
|
@@ -173,7 +173,7 @@ export async function runTaskHeartbeatTick(now) {
|
|
|
173
173
|
mountRoot = task.worktreePath;
|
|
174
174
|
}
|
|
175
175
|
else if (await isGitRepo(baseWorkingDir)) {
|
|
176
|
-
const wt = await ensureWorktree(baseWorkingDir, task.
|
|
176
|
+
const wt = await ensureWorktree(baseWorkingDir, task.id, task.title, task.branch);
|
|
177
177
|
task.branch = wt.branch;
|
|
178
178
|
task.worktreePath = wt.worktreePath;
|
|
179
179
|
await saveTask(task);
|
|
@@ -190,7 +190,7 @@ export async function runTaskHeartbeatTick(now) {
|
|
|
190
190
|
let dockerContainer;
|
|
191
191
|
let dockerHasGit = true;
|
|
192
192
|
if (dockerImage) {
|
|
193
|
-
const name = containerName(task.
|
|
193
|
+
const name = containerName(task.id);
|
|
194
194
|
// Also mount the git common dir so a linked worktree's gitdir resolves
|
|
195
195
|
// inside the container (identical-path). Only for git-worktree tasks.
|
|
196
196
|
const extraMounts = [];
|
|
@@ -341,7 +341,7 @@ export async function runTaskHeartbeatTick(now) {
|
|
|
341
341
|
}
|
|
342
342
|
};
|
|
343
343
|
// Load full history for replay
|
|
344
|
-
const historyMessages = (await runQuery(`SELECT * FROM task_messages WHERE taskId = ${task.id}`));
|
|
344
|
+
const historyMessages = (await runQuery(`SELECT * FROM task_messages WHERE taskId = '${task.id}'`));
|
|
345
345
|
historyMessages.sort((a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime());
|
|
346
346
|
// Map history to loop-compatible message records
|
|
347
347
|
const historyRecords = historyMessages
|
|
@@ -584,7 +584,7 @@ async function runReviewCycle(opts) {
|
|
|
584
584
|
// Finalize the agent's last work so the branch is complete before review.
|
|
585
585
|
await commitWip(task.worktreePath, task.title);
|
|
586
586
|
// Round is derived from the review-message stream, never a stored counter.
|
|
587
|
-
const priorReviews = (await runQuery(`SELECT * FROM task_messages WHERE taskId = ${task.id}`)).filter((m) => m.messageType === 'review').length;
|
|
587
|
+
const priorReviews = (await runQuery(`SELECT * FROM task_messages WHERE taskId = '${task.id}'`)).filter((m) => m.messageType === 'review').length;
|
|
588
588
|
const round = priorReviews + 1;
|
|
589
589
|
let verdict = 'pass';
|
|
590
590
|
let reviewText = '';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../src/cli/web/server.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,OAAO,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../src/cli/web/server.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,OAAO,MAAM,wBAAwB,CAAC;AA0ClD,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAgC,MAAM,gBAAgB,CAAC;AAChG,OAAO,KAAK,EAAE,eAAe,EAA0B,MAAM,mBAAmB,CAAC;AAgBjF,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAChC,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,UAAU,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;IAC9D,YAAY,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACpD,UAAU,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,KAAK,OAAO,CAAC,eAAe,CAAC,CAAC;IACtF,OAAO,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,gBAAgB,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;CAChD;AAED,qBAAa,oBAAoB;IAQ7B,OAAO,CAAC,QAAQ,CAAC,IAAI;IAPvB,OAAO,CAAC,UAAU,CAAkC;IACpD,OAAO,CAAC,OAAO,CAAuB;IACtC,OAAO,CAAC,QAAQ,CAAgC;IAChD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAc;IACzC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAS;gBAGjB,IAAI,EAAE;QACrB,KAAK,EAAE,WAAW,CAAC;QACnB,QAAQ,EAAE,cAAc,CAAC;QACzB,KAAK,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC;QACtB,UAAU,EAAE,MAAM,CAAC;QACnB,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB;IAMH,IAAI,SAAS,IAAI,OAAO,CAEvB;IAED,eAAe,IAAI,GAAG;IAIhB,KAAK,CACT,MAAM,EAAE,MAAM,EACd,EAAE,EAAE,aAAa,EACjB,cAAc,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC,EACtE,iBAAiB,CAAC,EAAE,OAAO,GAC1B,OAAO,CAAC,IAAI,CAAC;IAgFhB,KAAK,IAAI,IAAI;CAGd;AAED,wBAAsB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CA2nC3E"}
|
package/dist/cli/web/server.js
CHANGED
|
@@ -12,6 +12,7 @@ import { getDb, getTaskById, saveTask, createTask, addTaskMessage, deleteTask, r
|
|
|
12
12
|
import { discardWorktree, syncProjectRepo, projectRepoStatus, managedRepoDir } from '../../lib/task_git.js';
|
|
13
13
|
import { removeContainer } from '../../lib/docker.js';
|
|
14
14
|
import { validateRepositoryUrl } from '../../lib/repo_url.js';
|
|
15
|
+
import { validateProjectSlug, validateProjectIds } from '../../lib/project_slug.js';
|
|
15
16
|
import { runningTasks, abortRunningTask, syncingProjects } from './scheduler/locks.js';
|
|
16
17
|
import { registerTaskBridge, setTaskBridgeUrl } from './mcp_bridge.js';
|
|
17
18
|
import { loadAgents, loadConfig, dataDir, saveAgents, saveConfig, loadPlugins, loadMcpServers, } from '../../store/json.js';
|
|
@@ -235,13 +236,19 @@ export async function startServer(port, host) {
|
|
|
235
236
|
if (repoUrlError) {
|
|
236
237
|
return c.json({ error: repoUrlError }, 400);
|
|
237
238
|
}
|
|
239
|
+
const id = String(body.id || '').trim();
|
|
240
|
+
const slugError = validateProjectSlug(id);
|
|
241
|
+
if (slugError)
|
|
242
|
+
return c.json({ error: slugError }, 400);
|
|
238
243
|
const config = await loadConfig();
|
|
244
|
+
if ((config.projects || []).some((p) => p.id === id)) {
|
|
245
|
+
return c.json({ error: `Project id "${id}" already exists.` }, 400);
|
|
246
|
+
}
|
|
239
247
|
if (!config.projects) {
|
|
240
248
|
config.projects = [];
|
|
241
249
|
}
|
|
242
|
-
const nextId = config.projects.length > 0 ? Math.max(...config.projects.map((p) => p.id)) + 1 : 1;
|
|
243
250
|
const project = {
|
|
244
|
-
id
|
|
251
|
+
id,
|
|
245
252
|
name,
|
|
246
253
|
description: description || '',
|
|
247
254
|
workingDir,
|
|
@@ -272,23 +279,22 @@ export async function startServer(port, host) {
|
|
|
272
279
|
});
|
|
273
280
|
app.delete('/api/projects/:id', async (c) => {
|
|
274
281
|
try {
|
|
275
|
-
const id =
|
|
282
|
+
const id = c.req.param('id');
|
|
283
|
+
if (!/^[a-z0-9][a-z0-9-]*$/.test(id))
|
|
284
|
+
return c.json({ error: 'Invalid id' }, 400);
|
|
276
285
|
const config = await loadConfig();
|
|
277
286
|
const project = (config.projects || []).find((p) => p.id === id);
|
|
278
287
|
if (config.projects) {
|
|
279
288
|
config.projects = config.projects.filter((p) => p.id !== id);
|
|
280
289
|
await saveConfig(config);
|
|
281
290
|
}
|
|
282
|
-
//
|
|
283
|
-
// reuses the id — and with it ~/.caretaker/repos/<id>, which the new
|
|
284
|
-
// project would silently inherit (old code, old origin). Remove the
|
|
285
|
-
// managed clone; a user-chosen workingDir is never touched.
|
|
291
|
+
// Remove the managed clone; a user-chosen workingDir is never touched.
|
|
286
292
|
const managed = project ? managedRepoDir(project) : null;
|
|
287
293
|
if (managed)
|
|
288
294
|
await fs.promises.rm(managed, { recursive: true, force: true });
|
|
289
295
|
// Delete task messages first, then tasks — avoids orphaned message rows.
|
|
290
|
-
await runQuery(`DELETE FROM task_messages WHERE taskId IN (SELECT id FROM tasks WHERE projectId = ${id})`);
|
|
291
|
-
await runQuery(`DELETE FROM tasks WHERE projectId = ${id}`);
|
|
296
|
+
await runQuery(`DELETE FROM task_messages WHERE taskId IN (SELECT id FROM tasks WHERE projectId = '${id}')`);
|
|
297
|
+
await runQuery(`DELETE FROM tasks WHERE projectId = '${id}'`);
|
|
292
298
|
return c.json({ ok: true });
|
|
293
299
|
}
|
|
294
300
|
catch (err) {
|
|
@@ -299,7 +305,9 @@ export async function startServer(port, host) {
|
|
|
299
305
|
// ndjson (voice-backend pattern); failures travel in-band as an `error` line
|
|
300
306
|
// so URL/token problems are diagnosable from the UI.
|
|
301
307
|
app.post('/api/projects/:id/sync', async (c) => {
|
|
302
|
-
const id =
|
|
308
|
+
const id = c.req.param('id');
|
|
309
|
+
if (!/^[a-z0-9][a-z0-9-]*$/.test(id))
|
|
310
|
+
return c.json({ error: 'Invalid id' }, 400);
|
|
303
311
|
const config = await loadConfig();
|
|
304
312
|
const project = (config.projects || []).find((p) => p.id === id);
|
|
305
313
|
if (!project)
|
|
@@ -327,7 +335,9 @@ export async function startServer(port, host) {
|
|
|
327
335
|
});
|
|
328
336
|
// Derived repo state — disk + in-flight set at request time, nothing stored.
|
|
329
337
|
app.get('/api/projects/:id/repo-status', async (c) => {
|
|
330
|
-
const id =
|
|
338
|
+
const id = c.req.param('id');
|
|
339
|
+
if (!/^[a-z0-9][a-z0-9-]*$/.test(id))
|
|
340
|
+
return c.json({ error: 'Invalid id' }, 400);
|
|
331
341
|
const config = await loadConfig();
|
|
332
342
|
const project = (config.projects || []).find((p) => p.id === id);
|
|
333
343
|
if (!project)
|
|
@@ -340,10 +350,12 @@ export async function startServer(port, host) {
|
|
|
340
350
|
});
|
|
341
351
|
// Tasks REST endpoints
|
|
342
352
|
app.get('/api/projects/:id/tasks', async (c) => {
|
|
343
|
-
const id =
|
|
353
|
+
const id = c.req.param('id');
|
|
354
|
+
if (!/^[a-z0-9][a-z0-9-]*$/.test(id))
|
|
355
|
+
return c.json({ error: 'Invalid id' }, 400);
|
|
344
356
|
const includeArchived = c.req.query('archived') === 'true';
|
|
345
357
|
try {
|
|
346
|
-
const rows = (await runQuery(`SELECT * FROM tasks WHERE projectId = ${id}`));
|
|
358
|
+
const rows = (await runQuery(`SELECT * FROM tasks WHERE projectId = '${id}'`));
|
|
347
359
|
const filtered = includeArchived ? rows : rows.filter((t) => !t.archived);
|
|
348
360
|
return c.json(filtered);
|
|
349
361
|
}
|
|
@@ -352,7 +364,9 @@ export async function startServer(port, host) {
|
|
|
352
364
|
}
|
|
353
365
|
});
|
|
354
366
|
app.post('/api/projects/:id/tasks', async (c) => {
|
|
355
|
-
const projectId =
|
|
367
|
+
const projectId = c.req.param('id');
|
|
368
|
+
if (!/^[a-z0-9][a-z0-9-]*$/.test(projectId))
|
|
369
|
+
return c.json({ error: 'Invalid id' }, 400);
|
|
356
370
|
const body = await c.req.json();
|
|
357
371
|
const { title, objective, checklist, startActive, agentId, plannerAgentId, reviewerAgentId, planningEnabled, reviewEnabled, sddEnabled, maxRunSeconds } = body;
|
|
358
372
|
// Validate that the specified agents exist (if provided).
|
|
@@ -398,9 +412,11 @@ export async function startServer(port, host) {
|
|
|
398
412
|
return c.json({ ok: true });
|
|
399
413
|
});
|
|
400
414
|
app.get('/api/tasks/:id/messages', async (c) => {
|
|
401
|
-
const taskId =
|
|
415
|
+
const taskId = c.req.param('id');
|
|
416
|
+
if (!/^[a-z0-9][a-z0-9-]*$/.test(taskId))
|
|
417
|
+
return c.json([], 200);
|
|
402
418
|
try {
|
|
403
|
-
const rows = (await runQuery(`SELECT * FROM task_messages WHERE taskId = ${taskId}`));
|
|
419
|
+
const rows = (await runQuery(`SELECT * FROM task_messages WHERE taskId = '${taskId}'`));
|
|
404
420
|
rows.sort((a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime());
|
|
405
421
|
return c.json(rows);
|
|
406
422
|
}
|
|
@@ -409,7 +425,7 @@ export async function startServer(port, host) {
|
|
|
409
425
|
}
|
|
410
426
|
});
|
|
411
427
|
app.post('/api/tasks/:id/messages', async (c) => {
|
|
412
|
-
const taskId =
|
|
428
|
+
const taskId = c.req.param('id');
|
|
413
429
|
const body = await c.req.json();
|
|
414
430
|
const { content } = body;
|
|
415
431
|
await addTaskMessage({
|
|
@@ -432,7 +448,7 @@ export async function startServer(port, host) {
|
|
|
432
448
|
return c.json({ ok: true });
|
|
433
449
|
});
|
|
434
450
|
app.post('/api/tasks/:id/status', async (c) => {
|
|
435
|
-
const taskId =
|
|
451
|
+
const taskId = c.req.param('id');
|
|
436
452
|
const body = await c.req.json();
|
|
437
453
|
const { status } = body;
|
|
438
454
|
const task = await getTaskById(taskId);
|
|
@@ -456,7 +472,7 @@ export async function startServer(port, host) {
|
|
|
456
472
|
return c.json({ ok: true });
|
|
457
473
|
});
|
|
458
474
|
app.post('/api/tasks/:id/discard-worktree', async (c) => {
|
|
459
|
-
const taskId =
|
|
475
|
+
const taskId = c.req.param('id');
|
|
460
476
|
const task = await getTaskById(taskId);
|
|
461
477
|
if (!task)
|
|
462
478
|
return c.json({ ok: false, error: 'not found' }, 404);
|
|
@@ -492,7 +508,7 @@ export async function startServer(port, host) {
|
|
|
492
508
|
return c.json({ ok: true, branch: task.branch });
|
|
493
509
|
});
|
|
494
510
|
app.post('/api/tasks/:id/archive', async (c) => {
|
|
495
|
-
const taskId =
|
|
511
|
+
const taskId = c.req.param('id');
|
|
496
512
|
const task = await getTaskById(taskId);
|
|
497
513
|
if (!task)
|
|
498
514
|
return c.json({ ok: false, error: 'not found' }, 404);
|
|
@@ -511,7 +527,7 @@ export async function startServer(port, host) {
|
|
|
511
527
|
return c.json({ ok: true });
|
|
512
528
|
});
|
|
513
529
|
app.post('/api/tasks/:id/unarchive', async (c) => {
|
|
514
|
-
const taskId =
|
|
530
|
+
const taskId = c.req.param('id');
|
|
515
531
|
const task = await getTaskById(taskId);
|
|
516
532
|
if (!task)
|
|
517
533
|
return c.json({ ok: false, error: 'not found' }, 404);
|
|
@@ -527,7 +543,7 @@ export async function startServer(port, host) {
|
|
|
527
543
|
return c.json({ ok: true });
|
|
528
544
|
});
|
|
529
545
|
app.delete('/api/tasks/:id', async (c) => {
|
|
530
|
-
const taskId =
|
|
546
|
+
const taskId = c.req.param('id');
|
|
531
547
|
const task = await getTaskById(taskId);
|
|
532
548
|
if (!task)
|
|
533
549
|
return c.json({ ok: false, error: 'not found' }, 404);
|
|
@@ -573,7 +589,7 @@ export async function startServer(port, host) {
|
|
|
573
589
|
return c.json({ ok: true });
|
|
574
590
|
});
|
|
575
591
|
app.post('/api/tasks/:id/checklist-item', async (c) => {
|
|
576
|
-
const taskId =
|
|
592
|
+
const taskId = c.req.param('id');
|
|
577
593
|
const body = await c.req.json();
|
|
578
594
|
const { itemId, status: statusInput } = body;
|
|
579
595
|
const status = tryNormalizeChecklistStatus(statusInput);
|
|
@@ -589,7 +605,7 @@ export async function startServer(port, host) {
|
|
|
589
605
|
return c.json({ ok: true });
|
|
590
606
|
});
|
|
591
607
|
app.patch('/api/tasks/:id/agent', async (c) => {
|
|
592
|
-
const taskId =
|
|
608
|
+
const taskId = c.req.param('id');
|
|
593
609
|
const body = await c.req.json();
|
|
594
610
|
const { agentId, role } = body;
|
|
595
611
|
const task = await getTaskById(taskId);
|
|
@@ -619,7 +635,7 @@ export async function startServer(port, host) {
|
|
|
619
635
|
return c.json({ ok: true, role: targetRole, agentId: agentId || null });
|
|
620
636
|
});
|
|
621
637
|
app.patch('/api/tasks/:id/flags', async (c) => {
|
|
622
|
-
const taskId =
|
|
638
|
+
const taskId = c.req.param('id');
|
|
623
639
|
const body = await c.req.json();
|
|
624
640
|
const task = await getTaskById(taskId);
|
|
625
641
|
if (!task)
|
|
@@ -650,7 +666,7 @@ export async function startServer(port, host) {
|
|
|
650
666
|
// guard (unlike …/agent): the objective is read at the start of each cycle, so
|
|
651
667
|
// an edit simply lands on the next one — no reason to force a pause for a typo.
|
|
652
668
|
app.patch('/api/tasks/:id', async (c) => {
|
|
653
|
-
const taskId =
|
|
669
|
+
const taskId = c.req.param('id');
|
|
654
670
|
const body = await c.req.json();
|
|
655
671
|
const hasTitle = 'title' in body;
|
|
656
672
|
const hasObjective = 'objective' in body;
|
|
@@ -1010,6 +1026,25 @@ export async function startServer(port, host) {
|
|
|
1010
1026
|
return;
|
|
1011
1027
|
case 'saveConfig':
|
|
1012
1028
|
try {
|
|
1029
|
+
const idError = validateProjectIds(msg.config.projects || []);
|
|
1030
|
+
if (idError) {
|
|
1031
|
+
post({ type: 'error', message: idError });
|
|
1032
|
+
return;
|
|
1033
|
+
}
|
|
1034
|
+
// A project that still has tasks must be deleted through DELETE /api/projects/:id
|
|
1035
|
+
// (which removes tasks, worktrees and the managed clone) — not silently dropped
|
|
1036
|
+
// from a config save. Also blocks id "renames", which arrive as drop+add.
|
|
1037
|
+
const prev = await loadConfig();
|
|
1038
|
+
const incomingIds = new Set((msg.config.projects || []).map((p) => p.id));
|
|
1039
|
+
for (const old of prev.projects || []) {
|
|
1040
|
+
if (incomingIds.has(old.id))
|
|
1041
|
+
continue;
|
|
1042
|
+
const remaining = (await runQuery(`SELECT * FROM tasks WHERE projectId = '${old.id}'`));
|
|
1043
|
+
if (remaining.length > 0) {
|
|
1044
|
+
post({ type: 'error', message: `Project "${old.name}" still has ${remaining.length} task(s) — delete it from the Projects panel instead.` });
|
|
1045
|
+
return;
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1013
1048
|
// The settings form saves the whole config through here, so this
|
|
1014
1049
|
// — not POST /api/projects — is the write path that actually
|
|
1015
1050
|
// needs to enforce the repository-URL rules.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"email_tools.d.ts","sourceRoot":"","sources":["../../../../src/harness/tools/builtin/email_tools.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,IAAI,EAAc,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"email_tools.d.ts","sourceRoot":"","sources":["../../../../src/harness/tools/builtin/email_tools.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,IAAI,EAAc,MAAM,aAAa,CAAC;AAmCpD,eAAO,MAAM,qBAAqB,EAAE,IAqBnC,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,IAiE5B,CAAC;AAEF,eAAO,MAAM,aAAa,EAAE,IAwG3B,CAAC"}
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
// ctx.callerAgent — a scoped account is invisible, not refused);
|
|
10
10
|
// - who an account may send to (`allowedRecipients`, checked before connecting);
|
|
11
11
|
// - whose mail it may read (`allowedSenders`, checked on the envelope pass).
|
|
12
|
-
import { listEmailAccounts, findAccount, matchesAllowlist, bareAddress, sendEmail, fetchInbox, canSend, canRead, clampLimit, MAX_FETCH, } from '../../../lib/email.js';
|
|
12
|
+
import { listEmailAccounts, findAccount, matchesAllowlist, bareAddress, sendEmail, fetchInbox, canSend, canRead, clampLimit, markdownToHtml, MAX_FETCH, } from '../../../lib/email.js';
|
|
13
13
|
function err(msg) {
|
|
14
14
|
return { content: JSON.stringify({ error: msg }) };
|
|
15
15
|
}
|
|
@@ -114,7 +114,7 @@ export const emailFetchTool = {
|
|
|
114
114
|
};
|
|
115
115
|
export const emailSendTool = {
|
|
116
116
|
name: 'mcp__email__email_send',
|
|
117
|
-
description: 'Send
|
|
117
|
+
description: 'Send an email through one of the configured accounts. Pick the account by its name from email_list_accounts. `body` is the plain-text version and is always required; for a formatted message write `body` in markdown and set `markdown: true` (converted for you, so you write the content once), or pass your own `html`. No attachments. Recipients outside the account allowlist are refused and nothing is sent.',
|
|
118
118
|
parameters: {
|
|
119
119
|
type: 'object',
|
|
120
120
|
properties: {
|
|
@@ -127,7 +127,18 @@ export const emailSendTool = {
|
|
|
127
127
|
cc: { type: 'array', items: { type: 'string' } },
|
|
128
128
|
bcc: { type: 'array', items: { type: 'string' } },
|
|
129
129
|
subject: { type: 'string' },
|
|
130
|
-
body: {
|
|
130
|
+
body: {
|
|
131
|
+
type: 'string',
|
|
132
|
+
description: 'Plain-text body. Required even when sending HTML — it is the fallback part for clients that do not render HTML, and mail without one is treated as spam by many filters.',
|
|
133
|
+
},
|
|
134
|
+
markdown: {
|
|
135
|
+
type: 'boolean',
|
|
136
|
+
description: 'Default false. Set true when `body` is markdown: it is converted to a formatted HTML part for you and also sent as-is as the text part. Prefer this over writing the message twice. Cannot be combined with `html`.',
|
|
137
|
+
},
|
|
138
|
+
html: {
|
|
139
|
+
type: 'string',
|
|
140
|
+
description: 'Optional HTML body, sent as an alternative part alongside `body` — for full control over the markup. Usually `markdown: true` is enough and costs half as much to write. A full document or a fragment both work; inline the CSS as style attributes, because mail clients drop <style> blocks and never fetch external assets.',
|
|
141
|
+
},
|
|
131
142
|
},
|
|
132
143
|
required: ['account', 'to', 'subject', 'body'],
|
|
133
144
|
},
|
|
@@ -142,6 +153,15 @@ export const emailSendTool = {
|
|
|
142
153
|
return err('subject must be a non-empty string');
|
|
143
154
|
if (typeof args?.body !== 'string')
|
|
144
155
|
return err('body must be a string');
|
|
156
|
+
if (args?.html !== undefined && typeof args.html !== 'string')
|
|
157
|
+
return err('html must be a string');
|
|
158
|
+
if (args?.markdown === true && typeof args?.html === 'string' && args.html.trim())
|
|
159
|
+
return err('pass either html or markdown: true, not both — they set the same message part');
|
|
160
|
+
const html = typeof args?.html === 'string' && args.html.trim()
|
|
161
|
+
? args.html
|
|
162
|
+
: args?.markdown === true && body.trim()
|
|
163
|
+
? markdownToHtml(body)
|
|
164
|
+
: undefined;
|
|
145
165
|
const to = toList(args?.to);
|
|
146
166
|
const cc = toList(args?.cc);
|
|
147
167
|
const bcc = toList(args?.bcc);
|
|
@@ -170,9 +190,17 @@ export const emailSendTool = {
|
|
|
170
190
|
return err(`Recipient(s) not allowed by account "${account.name}": ${refused.join(', ')}. Allowed patterns: ${account.allowedRecipients.join(', ')}`);
|
|
171
191
|
}
|
|
172
192
|
try {
|
|
173
|
-
const messageId = await sendEmail(account, { to, cc, bcc, subject, body }, ctx.signal);
|
|
193
|
+
const messageId = await sendEmail(account, { to, cc, bcc, subject, body, html }, ctx.signal);
|
|
174
194
|
return {
|
|
175
|
-
content: JSON.stringify({
|
|
195
|
+
content: JSON.stringify({
|
|
196
|
+
ok: true,
|
|
197
|
+
messageId,
|
|
198
|
+
from: account.from,
|
|
199
|
+
to,
|
|
200
|
+
cc,
|
|
201
|
+
bcc,
|
|
202
|
+
html: !!html,
|
|
203
|
+
}),
|
|
176
204
|
};
|
|
177
205
|
}
|
|
178
206
|
catch (e) {
|