@hyperwindmill/caretaker-cli 0.22.0 → 0.24.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/memory_extract.d.ts +55 -0
- package/dist/cli/web/scheduler/memory_extract.d.ts.map +1 -0
- package/dist/cli/web/scheduler/memory_extract.js +112 -0
- package/dist/cli/web/scheduler/memory_sweep.d.ts +68 -0
- package/dist/cli/web/scheduler/memory_sweep.d.ts.map +1 -0
- package/dist/cli/web/scheduler/memory_sweep.js +329 -0
- package/dist/cli/web/scheduler/task_review.d.ts +3 -0
- package/dist/cli/web/scheduler/task_review.d.ts.map +1 -1
- package/dist/cli/web/scheduler/task_review.js +1 -0
- package/dist/cli/web/scheduler/task_roles.js +1 -1
- package/dist/cli/web/scheduler/task_strategy.d.ts.map +1 -1
- package/dist/cli/web/scheduler/task_strategy.js +8 -4
- package/dist/cli/web/scheduler.d.ts.map +1 -1
- package/dist/cli/web/scheduler.js +5 -0
- package/dist/cli/web/server.d.ts.map +1 -1
- package/dist/cli/web/server.js +67 -27
- package/dist/harness/claude_code_runner.d.ts.map +1 -1
- package/dist/harness/claude_code_runner.js +5 -0
- package/dist/harness/loop.d.ts +9 -0
- package/dist/harness/loop.d.ts.map +1 -1
- package/dist/harness/loop.js +10 -0
- package/dist/harness/memory_recall.d.ts +23 -0
- package/dist/harness/memory_recall.d.ts.map +1 -0
- package/dist/harness/memory_recall.js +70 -0
- package/dist/harness/tools/builtin/index.d.ts +2 -1
- package/dist/harness/tools/builtin/index.d.ts.map +1 -1
- package/dist/harness/tools/builtin/index.js +4 -1
- package/dist/harness/tools/builtin/memory_tools.d.ts +3 -0
- package/dist/harness/tools/builtin/memory_tools.d.ts.map +1 -0
- package/dist/harness/tools/builtin/memory_tools.js +60 -0
- package/dist/harness/tools/builtin/task_tools.js +37 -37
- package/dist/harness/tools/resolve.d.ts.map +1 -1
- package/dist/harness/tools/resolve.js +15 -0
- package/dist/harness/tools/types.d.ts +6 -0
- package/dist/harness/tools/types.d.ts.map +1 -1
- 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/project_resolve.d.ts +5 -0
- package/dist/lib/project_resolve.d.ts.map +1 -0
- package/dist/lib/project_resolve.js +23 -0
- 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/mcp/builtin_server.d.ts +1 -0
- package/dist/mcp/builtin_server.d.ts.map +1 -1
- package/dist/mcp/builtin_server.js +6 -5
- package/dist/store/db.d.ts +78 -7
- package/dist/store/db.d.ts.map +1 -1
- package/dist/store/db.js +127 -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/tui/agents.js +5 -2
- package/dist/webview/standalone.js +602 -434
- package/dist/webview/standalone.js.map +4 -4
- package/package.json +3 -3
|
@@ -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
|
|
@@ -403,6 +403,9 @@ export async function runTaskHeartbeatTick(now) {
|
|
|
403
403
|
prompt: effectivePrompt,
|
|
404
404
|
history: historyRecords,
|
|
405
405
|
workingDir,
|
|
406
|
+
// The worktree never prefix-matches the project's workingDir, so
|
|
407
|
+
// the recall block gets the project scope explicitly.
|
|
408
|
+
memoryProjectId: task.projectId,
|
|
406
409
|
claudeCode,
|
|
407
410
|
dockerContainer,
|
|
408
411
|
signal,
|
|
@@ -584,7 +587,7 @@ async function runReviewCycle(opts) {
|
|
|
584
587
|
// Finalize the agent's last work so the branch is complete before review.
|
|
585
588
|
await commitWip(task.worktreePath, task.title);
|
|
586
589
|
// 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;
|
|
590
|
+
const priorReviews = (await runQuery(`SELECT * FROM task_messages WHERE taskId = '${task.id}'`)).filter((m) => m.messageType === 'review').length;
|
|
588
591
|
const round = priorReviews + 1;
|
|
589
592
|
let verdict = 'pass';
|
|
590
593
|
let reviewText = '';
|
|
@@ -596,6 +599,7 @@ async function runReviewCycle(opts) {
|
|
|
596
599
|
objective: task.objective,
|
|
597
600
|
branch: task.branch || '(unknown)',
|
|
598
601
|
workingDir,
|
|
602
|
+
projectId: task.projectId,
|
|
599
603
|
round,
|
|
600
604
|
signal,
|
|
601
605
|
maxRunSeconds,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scheduler.d.ts","sourceRoot":"","sources":["../../../src/cli/web/scheduler.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"scheduler.d.ts","sourceRoot":"","sources":["../../../src/cli/web/scheduler.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,sBAAsB,EACtB,YAAY,EACZ,WAAW,GACZ,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAOpD;;GAEG;AACH,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC,CA4BtD;AAKD;;GAEG;AACH,wBAAgB,wBAAwB,IAAI,IAAI,CAQ/C;AAED;;GAEG;AACH,wBAAgB,uBAAuB,IAAI,IAAI,CAM9C"}
|
|
@@ -2,6 +2,7 @@ import { loadConfig } from '../../store/json.js';
|
|
|
2
2
|
import { HeartbeatStrategy } from './scheduler/heartbeat.js';
|
|
3
3
|
import { TelegramStrategy } from './scheduler/telegram.js';
|
|
4
4
|
import { runTaskHeartbeatTick } from './scheduler/task_strategy.js';
|
|
5
|
+
import { runMemorySweepTick } from './scheduler/memory_sweep.js';
|
|
5
6
|
// Re-exported for backwards compatibility with existing consumers (server.ts, tests).
|
|
6
7
|
export { schedulerLogsDir, schedulerLogPath, ensureSchedulerLogsDir, loadTaskRuns, saveTaskRun, } from './scheduler/logs.js';
|
|
7
8
|
export { runningTasks } from './scheduler/locks.js';
|
|
@@ -30,6 +31,10 @@ export async function runSchedulerTick() {
|
|
|
30
31
|
await runTaskHeartbeatTick(now).catch((err) => {
|
|
31
32
|
console.error('[scheduler] Autonomous Task Heartbeat Tick failed:', err);
|
|
32
33
|
});
|
|
34
|
+
// Memory sweep (session digests) — self-gated to at most one run per sweepMinutes.
|
|
35
|
+
await runMemorySweepTick(now).catch((err) => {
|
|
36
|
+
console.error('[scheduler] Memory sweep tick failed:', err);
|
|
37
|
+
});
|
|
33
38
|
}
|
|
34
39
|
catch (err) {
|
|
35
40
|
console.error('[scheduler] Error evaluating scheduler tasks tick:', err);
|
|
@@ -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,CAgoC3E"}
|
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;
|
|
@@ -848,7 +864,12 @@ export async function startServer(port, host) {
|
|
|
848
864
|
// Collapse every builtin `mcp__<ns>__` namespace (task, email, …) into a
|
|
849
865
|
// single wildcard entry: the picker offers the namespace, so a namespace
|
|
850
866
|
// gaining a tool needs no config change. resolveAgentTools expands it.
|
|
851
|
-
|
|
867
|
+
// Hidden tools (memory_read) are harness infrastructure, auto-included
|
|
868
|
+
// by resolveAgentTools behind their own gate — never a picker choice.
|
|
869
|
+
const toolNames = harness.tools
|
|
870
|
+
.list()
|
|
871
|
+
.filter((t) => !t.hidden)
|
|
872
|
+
.map((t) => t.name);
|
|
852
873
|
const namespaces = [
|
|
853
874
|
...new Set(toolNames.map((name) => /^mcp__[a-z]+__/.exec(name)?.[0]).filter((p) => !!p)),
|
|
854
875
|
];
|
|
@@ -1010,6 +1031,25 @@ export async function startServer(port, host) {
|
|
|
1010
1031
|
return;
|
|
1011
1032
|
case 'saveConfig':
|
|
1012
1033
|
try {
|
|
1034
|
+
const idError = validateProjectIds(msg.config.projects || []);
|
|
1035
|
+
if (idError) {
|
|
1036
|
+
post({ type: 'error', message: idError });
|
|
1037
|
+
return;
|
|
1038
|
+
}
|
|
1039
|
+
// A project that still has tasks must be deleted through DELETE /api/projects/:id
|
|
1040
|
+
// (which removes tasks, worktrees and the managed clone) — not silently dropped
|
|
1041
|
+
// from a config save. Also blocks id "renames", which arrive as drop+add.
|
|
1042
|
+
const prev = await loadConfig();
|
|
1043
|
+
const incomingIds = new Set((msg.config.projects || []).map((p) => p.id));
|
|
1044
|
+
for (const old of prev.projects || []) {
|
|
1045
|
+
if (incomingIds.has(old.id))
|
|
1046
|
+
continue;
|
|
1047
|
+
const remaining = (await runQuery(`SELECT * FROM tasks WHERE projectId = '${old.id}'`));
|
|
1048
|
+
if (remaining.length > 0) {
|
|
1049
|
+
post({ type: 'error', message: `Project "${old.name}" still has ${remaining.length} task(s) — delete it from the Projects panel instead.` });
|
|
1050
|
+
return;
|
|
1051
|
+
}
|
|
1052
|
+
}
|
|
1013
1053
|
// The settings form saves the whole config through here, so this
|
|
1014
1054
|
// — not POST /api/projects — is the write path that actually
|
|
1015
1055
|
// needs to enforce the repository-URL rules.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"claude_code_runner.d.ts","sourceRoot":"","sources":["../../src/harness/claude_code_runner.ts"],"names":[],"mappings":"AAMA,OAAO,EAAsB,KAAK,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAM3E,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"claude_code_runner.d.ts","sourceRoot":"","sources":["../../src/harness/claude_code_runner.ts"],"names":[],"mappings":"AAMA,OAAO,EAAsB,KAAK,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAM3E,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAkBrE,MAAM,MAAM,mBAAmB,GAAG;IAChC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,e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AAC,EAAE,MAAM,CAAC;IAC5B,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;kFAC8E;IAC9E,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,cAAc,EAAE,OAAO,CAAC;CACzB;AAED,wBAAgB,eAAe,CAAC,CAAC,EAAE,eAAe,GAAG,MAAM,EAAE,CAe5D;AAED,uEAAuE;AACvE,wBAAgB,oBAAoB,CAAC,CAAC,EAAE;IACtC,QAAQ,EAAE,OAAO,CAAC;IAClB,GAAG,EAAE,OAAO,CAAC;IACb,MAAM,CAAC,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;CACzC,GAAG,mBAAmB,CAwBtB;AAsMD,wBAAsB,aAAa,CAAC,IAAI,EAAE,UAAU,EAAE,EAAE,GAAE,YAAiB,GAAG,OAAO,CAAC,SAAS,CAAC,CA2I/F"}
|
|
@@ -11,6 +11,7 @@ import os from 'node:os';
|
|
|
11
11
|
import path from 'node:path';
|
|
12
12
|
import { parseClaudeStreamLine } from './claude_code_stream.js';
|
|
13
13
|
import { loadContextFiles, formatContextBlock, resolveFileReferences } from './context_files.js';
|
|
14
|
+
import { buildMemoriesBlock } from './memory_recall.js';
|
|
14
15
|
import { VOICE_CONVERSATION_PRELUDE } from './prelude.js';
|
|
15
16
|
import { readSession, updateClaudeSessionId, assistantMessage, toolMessage, } from '../session/store.js';
|
|
16
17
|
import { loadMcpServers } from '../store/json.js';
|
|
@@ -271,9 +272,13 @@ export async function runClaudeCode(opts, cb = {}) {
|
|
|
271
272
|
// ~/.caretaker/AGENTS.md it does not — verified on CLI 2.1.207).
|
|
272
273
|
const sys = await resolveFileReferences(agent.systemPrompt ?? '', workingDir);
|
|
273
274
|
const ctxEntries = (await loadContextFiles(workingDir)).filter((e) => path.basename(e.path) !== 'CLAUDE.md');
|
|
275
|
+
const memoriesBlock = opts.skipMemoryRecall
|
|
276
|
+
? ''
|
|
277
|
+
: await buildMemoriesBlock(opts.prompt, workingDir, opts.memoryProjectId);
|
|
274
278
|
const appendSystemPrompt = [
|
|
275
279
|
sys,
|
|
276
280
|
ctxEntries.length ? formatContextBlock(ctxEntries) : '',
|
|
281
|
+
memoriesBlock,
|
|
277
282
|
opts.voiceConversation ? VOICE_CONVERSATION_PRELUDE : '',
|
|
278
283
|
]
|
|
279
284
|
.filter(Boolean)
|
package/dist/harness/loop.d.ts
CHANGED
|
@@ -62,6 +62,15 @@ export interface RunOptions {
|
|
|
62
62
|
/** The turn came from voice conversation mode; append the spoken-reply
|
|
63
63
|
* block to the system prompt so the agent writes speakable prose. */
|
|
64
64
|
voiceConversation?: boolean;
|
|
65
|
+
/** Skip the per-turn <memories> recall block. Set by the memory sweep's
|
|
66
|
+
* own summarize runs: injecting recalled memories into the call that
|
|
67
|
+
* extracts memories would pollute its carefully-shaped prompt. */
|
|
68
|
+
skipMemoryRecall?: boolean;
|
|
69
|
+
/** Explicit project scope for the recall block. Set by autonomous task
|
|
70
|
+
* runs, whose workingDir is a worktree (or managed repo dir) that never
|
|
71
|
+
* prefix-matches the project's workingDir — the task record already
|
|
72
|
+
* knows the project. Host-side, never the model's choice. */
|
|
73
|
+
memoryProjectId?: string;
|
|
65
74
|
}
|
|
66
75
|
export interface RunResult {
|
|
67
76
|
/** Concatenated assistant text across all turns. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loop.d.ts","sourceRoot":"","sources":["../../src/harness/loop.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE/D,OAAO,KAAK,EAAiB,aAAa,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC9F,OA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AS,CAAC;CACxC;AAED,wBAAsB,GAAG,CAAC,IAAI,EAAE,UAAU,EAAE,EAAE,GAAE,YAAiB,GAAG,OAAO,CAAC,SAAS,CAAC,CA+VrF"}
|
package/dist/harness/loop.js
CHANGED
|
@@ -17,6 +17,7 @@ import { buildRequestBody, readStream } from './provider.js';
|
|
|
17
17
|
import { mapMessagesToChat } from './history.js';
|
|
18
18
|
import { toOpenAiTool, } from './tools/index.js';
|
|
19
19
|
import { withHarnessPrelude, VOICE_CONVERSATION_PRELUDE } from './prelude.js';
|
|
20
|
+
import { buildMemoriesBlock } from './memory_recall.js';
|
|
20
21
|
import { formatRuntimeInfoBlock } from './runtime_info.js';
|
|
21
22
|
import { loadContextFiles, formatContextBlock, resolveFileReferences } from './context_files.js';
|
|
22
23
|
let fetchImpl = globalThis.fetch.bind(globalThis);
|
|
@@ -78,6 +79,15 @@ export async function run(opts, cb = {}) {
|
|
|
78
79
|
workingDir: toolCtx.workingDir,
|
|
79
80
|
});
|
|
80
81
|
effectiveSystemPrompt = `${effectiveSystemPrompt}\n\n${runtimeBlock}`.trim();
|
|
82
|
+
// Memory recall (read path): per-turn <memories> block — titles matched
|
|
83
|
+
// host-side against the user prompt, zero model calls. '' when memory is
|
|
84
|
+
// unconfigured or nothing matches.
|
|
85
|
+
if (!opts.skipMemoryRecall) {
|
|
86
|
+
const memoriesBlock = await buildMemoriesBlock(prompt, toolCtx.workingDir, opts.memoryProjectId);
|
|
87
|
+
if (memoriesBlock) {
|
|
88
|
+
effectiveSystemPrompt = `${effectiveSystemPrompt}\n\n${memoriesBlock}`.trim();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
81
91
|
// Voice-conversation block is appended last (strongest recency) and only
|
|
82
92
|
// on voice turns — the same session mixes typed and spoken turns.
|
|
83
93
|
if (opts.voiceConversation) {
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Memory } from '../store/db.js';
|
|
2
|
+
export declare const RECALL_TOP_K = 5;
|
|
3
|
+
export declare const MIN_KEYWORD_LENGTH = 3;
|
|
4
|
+
/** Inverted lexical match — no query tokenization: a stored keyword matches
|
|
5
|
+
* when the lowercased prompt contains it (multi-word keywords work free).
|
|
6
|
+
* score = matched × importanceWeight × (1 + log2(1 + recallCount)):
|
|
7
|
+
* acquired strength weighs in — much-recalled memories surface more easily.
|
|
8
|
+
* Ties: lastRecalledAt desc, then createdAt desc. Top-K, score > 0 only. */
|
|
9
|
+
export declare function matchMemories(prompt: string, memories: Memory[]): Memory[];
|
|
10
|
+
/** The prelude block. Titles only, never bodies: the explicit memory_read
|
|
11
|
+
* IS the recall event that feeds acquired strength — a system that always
|
|
12
|
+
* injects bodies never learns what mattered. '' when no matches. */
|
|
13
|
+
export declare function formatMemoriesBlock(matches: Memory[]): string;
|
|
14
|
+
/** One-stop per-turn recall: gate on MemoryConfig (present = read path on,
|
|
15
|
+
* same gate as the sweep), resolve the project from the run's workingDir,
|
|
16
|
+
* match global + project memories, format. Never throws — recall must
|
|
17
|
+
* never break a chat turn.
|
|
18
|
+
* `explicitProjectId` overrides dir resolution: task cycles run in a
|
|
19
|
+
* worktree (or managed repo dir) that never prefix-matches the project's
|
|
20
|
+
* workingDir, but the caller knows the project from the task record —
|
|
21
|
+
* still host-side, never the model's choice. */
|
|
22
|
+
export declare function buildMemoriesBlock(prompt: string, workingDir: string, explicitProjectId?: string): Promise<string>;
|
|
23
|
+
//# sourceMappingURL=memory_recall.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory_recall.d.ts","sourceRoot":"","sources":["../../src/harness/memory_recall.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAK7C,eAAO,MAAM,YAAY,IAAI,CAAC;AAC9B,eAAO,MAAM,kBAAkB,IAAI,CAAC;AAOpC;;;;6EAI6E;AAC7E,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAqB1E;AAED;;qEAEqE;AACrE,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,CAS7D;AAED;;;;;;;iDAOiD;AACjD,wBAAsB,kBAAkB,CACtC,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,EAClB,iBAAiB,CAAC,EAAE,MAAM,GACzB,OAAO,CAAC,MAAM,CAAC,CAajB"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { listMemories } from '../store/db.js';
|
|
2
|
+
import { loadConfig } from '../store/json.js';
|
|
3
|
+
import { resolveProjectIdForDir } from '../lib/project_resolve.js';
|
|
4
|
+
export const RECALL_TOP_K = 5;
|
|
5
|
+
export const MIN_KEYWORD_LENGTH = 3;
|
|
6
|
+
const IMPORTANCE_WEIGHT = {
|
|
7
|
+
low: 0.5,
|
|
8
|
+
normal: 1,
|
|
9
|
+
high: 2,
|
|
10
|
+
};
|
|
11
|
+
/** Inverted lexical match — no query tokenization: a stored keyword matches
|
|
12
|
+
* when the lowercased prompt contains it (multi-word keywords work free).
|
|
13
|
+
* score = matched × importanceWeight × (1 + log2(1 + recallCount)):
|
|
14
|
+
* acquired strength weighs in — much-recalled memories surface more easily.
|
|
15
|
+
* Ties: lastRecalledAt desc, then createdAt desc. Top-K, score > 0 only. */
|
|
16
|
+
export function matchMemories(prompt, memories) {
|
|
17
|
+
const text = prompt.toLowerCase();
|
|
18
|
+
const scored = [];
|
|
19
|
+
for (const m of memories) {
|
|
20
|
+
let matched = 0;
|
|
21
|
+
for (const k of m.keywords) {
|
|
22
|
+
const kw = k.trim().toLowerCase();
|
|
23
|
+
if (kw.length >= MIN_KEYWORD_LENGTH && text.includes(kw))
|
|
24
|
+
matched++;
|
|
25
|
+
}
|
|
26
|
+
if (matched === 0)
|
|
27
|
+
continue;
|
|
28
|
+
const score = matched * IMPORTANCE_WEIGHT[m.importance] * (1 + Math.log2(1 + (m.recallCount ?? 0)));
|
|
29
|
+
scored.push({ m, score });
|
|
30
|
+
}
|
|
31
|
+
scored.sort((a, b) => b.score - a.score ||
|
|
32
|
+
(b.m.lastRecalledAt ?? '').localeCompare(a.m.lastRecalledAt ?? '') ||
|
|
33
|
+
b.m.createdAt.localeCompare(a.m.createdAt));
|
|
34
|
+
return scored.slice(0, RECALL_TOP_K).map((s) => s.m);
|
|
35
|
+
}
|
|
36
|
+
/** The prelude block. Titles only, never bodies: the explicit memory_read
|
|
37
|
+
* IS the recall event that feeds acquired strength — a system that always
|
|
38
|
+
* injects bodies never learns what mattered. '' when no matches. */
|
|
39
|
+
export function formatMemoriesBlock(matches) {
|
|
40
|
+
if (matches.length === 0)
|
|
41
|
+
return '';
|
|
42
|
+
return [
|
|
43
|
+
'<memories>',
|
|
44
|
+
'Stored memories that may be relevant to the current message:',
|
|
45
|
+
...matches.map((m) => `- ${m.id} — ${m.title} (${m.kind}, ${m.importance})`),
|
|
46
|
+
'To read their full content, call the memory_read tool with the ids (when available).',
|
|
47
|
+
'</memories>',
|
|
48
|
+
].join('\n');
|
|
49
|
+
}
|
|
50
|
+
/** One-stop per-turn recall: gate on MemoryConfig (present = read path on,
|
|
51
|
+
* same gate as the sweep), resolve the project from the run's workingDir,
|
|
52
|
+
* match global + project memories, format. Never throws — recall must
|
|
53
|
+
* never break a chat turn.
|
|
54
|
+
* `explicitProjectId` overrides dir resolution: task cycles run in a
|
|
55
|
+
* worktree (or managed repo dir) that never prefix-matches the project's
|
|
56
|
+
* workingDir, but the caller knows the project from the task record —
|
|
57
|
+
* still host-side, never the model's choice. */
|
|
58
|
+
export async function buildMemoriesBlock(prompt, workingDir, explicitProjectId) {
|
|
59
|
+
try {
|
|
60
|
+
const config = await loadConfig();
|
|
61
|
+
if (!config.memory)
|
|
62
|
+
return '';
|
|
63
|
+
const projectId = explicitProjectId ?? resolveProjectIdForDir(workingDir, config.projects ?? []);
|
|
64
|
+
const candidates = (await listMemories()).filter((m) => m.projectId === '' || m.projectId === projectId);
|
|
65
|
+
return formatMemoriesBlock(matchMemories(prompt, candidates));
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
return '';
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -18,7 +18,8 @@ import { listCommandsTool } from './list_commands.js';
|
|
|
18
18
|
import { invokeCommandTool } from './invoke_command.js';
|
|
19
19
|
import { getAgentContextTool } from './get_agent_context.js';
|
|
20
20
|
import { emailListAccountsTool, emailSendTool, emailFetchTool } from './email_tools.js';
|
|
21
|
+
import { memoryReadTool } from './memory_tools.js';
|
|
21
22
|
import { getTaskStateTool, updateChecklistItemTool, updateChecklistTool, addMessageTool, completeTaskTool, blockTaskTool, yieldTaskTool, projectListTool, taskCreateTool, taskSearchTool, taskUnblockTool, taskActivateTool, taskUnpauseTool, taskDiscardWorktreeTool, taskArchiveTool, taskUnarchiveTool, taskDeleteTool, taskSetAgentTool, submitPlanTool, taskUpdateDetailsTool } from './task_tools.js';
|
|
22
23
|
export declare function registerBuiltins(registry: ToolRegistry): void;
|
|
23
|
-
export { readFileTool, readDocumentTool, readImageTool, readAttachmentTool, writeTool, editTool, multieditTool, globTool, grepTool, fetchTool, bashTool, listSkillsTool, readSkillTool, listAgentsTool, invokeAgentTool, listCommandsTool, invokeCommandTool, getAgentContextTool, getTaskStateTool, updateChecklistItemTool, updateChecklistTool, addMessageTool, completeTaskTool, blockTaskTool, yieldTaskTool, projectListTool, taskCreateTool, taskSearchTool, taskUnblockTool, taskActivateTool, taskUnpauseTool, taskDiscardWorktreeTool, taskArchiveTool, taskUnarchiveTool, taskDeleteTool, taskSetAgentTool, submitPlanTool, taskUpdateDetailsTool, emailListAccountsTool, emailSendTool, emailFetchTool, };
|
|
24
|
+
export { readFileTool, readDocumentTool, readImageTool, readAttachmentTool, writeTool, editTool, multieditTool, globTool, grepTool, fetchTool, bashTool, listSkillsTool, readSkillTool, listAgentsTool, invokeAgentTool, listCommandsTool, invokeCommandTool, getAgentContextTool, getTaskStateTool, updateChecklistItemTool, updateChecklistTool, addMessageTool, completeTaskTool, blockTaskTool, yieldTaskTool, projectListTool, taskCreateTool, taskSearchTool, taskUnblockTool, taskActivateTool, taskUnpauseTool, taskDiscardWorktreeTool, taskArchiveTool, taskUnarchiveTool, taskDeleteTool, taskSetAgentTool, submitPlanTool, taskUpdateDetailsTool, emailListAccountsTool, emailSendTool, emailFetchTool, memoryReadTool, };
|
|
24
25
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/harness/tools/builtin/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAA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BAAgB,EAChB,eAAe,EACf,uBAAuB,EACvB,eAAe,EACf,iBAAiB,EACjB,cAAc,EACd,gBAAgB,EAChB,cAAc,EACd,qBAAqB,EACrB,qBAAqB,EACrB,aAAa,EACb,cAAc,EACd,cAAc,GACf,CAAC"}
|
|
@@ -20,6 +20,7 @@ import { listCommandsTool } from './list_commands.js';
|
|
|
20
20
|
import { invokeCommandTool } from './invoke_command.js';
|
|
21
21
|
import { getAgentContextTool } from './get_agent_context.js';
|
|
22
22
|
import { emailListAccountsTool, emailSendTool, emailFetchTool } from './email_tools.js';
|
|
23
|
+
import { memoryReadTool } from './memory_tools.js';
|
|
23
24
|
import { getTaskStateTool, updateChecklistItemTool, updateChecklistTool, addMessageTool, completeTaskTool, blockTaskTool, yieldTaskTool, projectListTool, taskCreateTool, taskSearchTool, taskUnblockTool, taskActivateTool, taskUnpauseTool, taskDiscardWorktreeTool, taskArchiveTool, taskUnarchiveTool, taskDeleteTool, taskSetAgentTool, submitPlanTool, taskUpdateDetailsTool, } from './task_tools.js';
|
|
24
25
|
export function registerBuiltins(registry) {
|
|
25
26
|
// Filesystem (sandboxed to ctx.workingDir).
|
|
@@ -77,5 +78,7 @@ export function registerBuiltins(registry) {
|
|
|
77
78
|
registry.register(emailListAccountsTool);
|
|
78
79
|
registry.register(emailSendTool);
|
|
79
80
|
registry.register(emailFetchTool);
|
|
81
|
+
// Memory subsystem read path (recall accounting lives in the tool).
|
|
82
|
+
registry.register(memoryReadTool);
|
|
80
83
|
}
|
|
81
|
-
export { readFileTool, readDocumentTool, readImageTool, readAttachmentTool, writeTool, editTool, multieditTool, globTool, grepTool, fetchTool, bashTool, listSkillsTool, readSkillTool, listAgentsTool, invokeAgentTool, listCommandsTool, invokeCommandTool, getAgentContextTool, getTaskStateTool, updateChecklistItemTool, updateChecklistTool, addMessageTool, completeTaskTool, blockTaskTool, yieldTaskTool, projectListTool, taskCreateTool, taskSearchTool, taskUnblockTool, taskActivateTool, taskUnpauseTool, taskDiscardWorktreeTool, taskArchiveTool, taskUnarchiveTool, taskDeleteTool, taskSetAgentTool, submitPlanTool, taskUpdateDetailsTool, emailListAccountsTool, emailSendTool, emailFetchTool, };
|
|
84
|
+
export { readFileTool, readDocumentTool, readImageTool, readAttachmentTool, writeTool, editTool, multieditTool, globTool, grepTool, fetchTool, bashTool, listSkillsTool, readSkillTool, listAgentsTool, invokeAgentTool, listCommandsTool, invokeCommandTool, getAgentContextTool, getTaskStateTool, updateChecklistItemTool, updateChecklistTool, addMessageTool, completeTaskTool, blockTaskTool, yieldTaskTool, projectListTool, taskCreateTool, taskSearchTool, taskUnblockTool, taskActivateTool, taskUnpauseTool, taskDiscardWorktreeTool, taskArchiveTool, taskUnarchiveTool, taskDeleteTool, taskSetAgentTool, submitPlanTool, taskUpdateDetailsTool, emailListAccountsTool, emailSendTool, emailFetchTool, memoryReadTool, };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory_tools.d.ts","sourceRoot":"","sources":["../../../../src/harness/tools/builtin/memory_tools.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,IAAI,EAAc,MAAM,aAAa,CAAC;AAGpD,eAAO,MAAM,cAAc,EAAE,IAgD5B,CAAC"}
|