@danieltmn/tamnora 0.13.1 → 0.15.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/CHANGELOG.md +38 -0
- package/harness/packages/core/src/config/index.js +2 -0
- package/harness/packages/core/src/hooks/index.js +42 -0
- package/harness/packages/core/src/index.js +3 -0
- package/harness/packages/core/src/plugins/index.js +36 -0
- package/harness/packages/core/src/rules/index.js +9 -63
- package/harness/packages/core/src/schedule/cron.js +124 -0
- package/harness/packages/core/src/storage/sqlite.js +96 -1
- package/harness/packages/core/src/tools/glob.js +64 -2
- package/harness/packages/core/test/cron.test.js +46 -0
- package/harness/packages/core/test/hooks.test.js +29 -0
- package/harness/packages/core/test/plugins.test.js +25 -0
- package/harness/packages/server/public/app.js +193 -3
- package/harness/packages/server/public/index.html +76 -2
- package/harness/packages/server/public/landing/index.html +5 -3
- package/harness/packages/server/public/styles.css +17 -10
- package/harness/packages/server/src/lib/advisor.js +4 -0
- package/harness/packages/server/src/lib/agentRun.js +24 -1
- package/harness/packages/server/src/lib/channels/telegram.js +7 -1
- package/harness/packages/server/src/lib/checkpoints.js +106 -0
- package/harness/packages/server/src/lib/compact.js +4 -0
- package/harness/packages/server/src/lib/hooks.js +45 -0
- package/harness/packages/server/src/lib/plugins.js +76 -0
- package/harness/packages/server/src/lib/scheduler.js +190 -0
- package/harness/packages/server/src/routes/advisor.js +4 -2
- package/harness/packages/server/src/routes/chat.js +32 -7
- package/harness/packages/server/src/routes/schedules.js +124 -0
- package/harness/packages/server/src/routes/sessions.js +18 -2
- package/harness/packages/server/src/server.js +24 -0
- package/harness/packages/server/test/server.test.js +201 -0
- package/harness/tamnora.example.json +2 -0
- package/package.json +1 -1
|
@@ -1221,6 +1221,207 @@ test('rules by path are injected (transiently) when a tool touches a matching fi
|
|
|
1221
1221
|
}
|
|
1222
1222
|
});
|
|
1223
1223
|
|
|
1224
|
+
test('manages scheduled tasks from the console', async () => {
|
|
1225
|
+
const { instance, base } = await startServer();
|
|
1226
|
+
const json = { 'Content-Type': 'application/json' };
|
|
1227
|
+
const create = (body) => fetch(`${base}/api/schedules`, { method: 'POST', headers: json, body: JSON.stringify(body) });
|
|
1228
|
+
try {
|
|
1229
|
+
let res = await create({ id: 'nightly', type: 'agent', spec: 'daily 03:00', prompt: 'hacé el resumen' });
|
|
1230
|
+
assert.equal(res.status, 201);
|
|
1231
|
+
let data = await res.json();
|
|
1232
|
+
assert.equal(data.schedule.id, 'nightly');
|
|
1233
|
+
assert.equal(data.schedule.enabled, true);
|
|
1234
|
+
assert.ok(data.schedule.nextRun);
|
|
1235
|
+
|
|
1236
|
+
res = await create({ id: 'bad', spec: 'nope', prompt: 'x' });
|
|
1237
|
+
assert.equal(res.status, 400);
|
|
1238
|
+
|
|
1239
|
+
res = await create({ id: 'nightly', type: 'agent', spec: 'daily 03:00', prompt: 'otra' });
|
|
1240
|
+
assert.equal(res.status, 409);
|
|
1241
|
+
|
|
1242
|
+
res = await fetch(`${base}/api/schedules/nightly/toggle`, { method: 'POST' });
|
|
1243
|
+
data = await res.json();
|
|
1244
|
+
assert.equal(data.enabled, false);
|
|
1245
|
+
|
|
1246
|
+
data = await (await fetch(`${base}/api/schedules`)).json();
|
|
1247
|
+
assert.equal(data.schedules.length, 1);
|
|
1248
|
+
assert.equal(data.schedules[0].enabled, false);
|
|
1249
|
+
|
|
1250
|
+
res = await fetch(`${base}/api/schedules/nightly`, { method: 'DELETE' });
|
|
1251
|
+
assert.equal(res.status, 200);
|
|
1252
|
+
data = await res.json();
|
|
1253
|
+
assert.equal(data.schedules.length, 0);
|
|
1254
|
+
} finally {
|
|
1255
|
+
await instance.close();
|
|
1256
|
+
}
|
|
1257
|
+
});
|
|
1258
|
+
|
|
1259
|
+
test('runs a scheduled task on demand (shell and agent)', async () => {
|
|
1260
|
+
const cwd = await mkdtemp(path.join(tmpdir(), 'tamnora-sched-'));
|
|
1261
|
+
const provider = {
|
|
1262
|
+
id: 'fake',
|
|
1263
|
+
async streamChat(_config, { onEvent }) {
|
|
1264
|
+
onEvent?.({ type: 'text', delta: 'ok', full: 'ok' });
|
|
1265
|
+
return { content: 'ok', reasoning: '', toolCalls: [] };
|
|
1266
|
+
},
|
|
1267
|
+
};
|
|
1268
|
+
const { instance, base } = await startServer({ cwd, resolveProvider: () => ({ provider, config: {} }) });
|
|
1269
|
+
const json = { 'Content-Type': 'application/json' };
|
|
1270
|
+
const create = (body) => fetch(`${base}/api/schedules`, { method: 'POST', headers: json, body: JSON.stringify(body) });
|
|
1271
|
+
let data;
|
|
1272
|
+
try {
|
|
1273
|
+
await create({ id: 'ver', type: 'shell', spec: 'every 1 h', command: 'node', args: ['--version'] });
|
|
1274
|
+
let res = await fetch(`${base}/api/schedules/ver/run`, { method: 'POST' });
|
|
1275
|
+
assert.equal(res.status, 200);
|
|
1276
|
+
assert.equal((await res.json()).ok, true);
|
|
1277
|
+
|
|
1278
|
+
await create({ id: 'nope', type: 'shell', spec: 'every 1 h', command: 'definitely-not-allowed' });
|
|
1279
|
+
res = await fetch(`${base}/api/schedules/nope/run`, { method: 'POST' });
|
|
1280
|
+
assert.equal(res.status, 500);
|
|
1281
|
+
|
|
1282
|
+
await create({ id: 'job', type: 'agent', spec: 'every 1 h', prompt: 'hacé algo útil', model: 'm' });
|
|
1283
|
+
res = await fetch(`${base}/api/schedules/job/run`, { method: 'POST' });
|
|
1284
|
+
data = await res.json();
|
|
1285
|
+
assert.equal(res.status, 200, JSON.stringify(data));
|
|
1286
|
+
assert.equal(data.ok, true, JSON.stringify(data));
|
|
1287
|
+
assert.ok(data.result.sessionId);
|
|
1288
|
+
|
|
1289
|
+
const sessions = await (await fetch(`${base}/api/sessions`)).json();
|
|
1290
|
+
assert.ok(sessions.sessions.some((s) => s.title === 'Tarea: job'));
|
|
1291
|
+
} finally {
|
|
1292
|
+
await instance.close();
|
|
1293
|
+
}
|
|
1294
|
+
});
|
|
1295
|
+
|
|
1296
|
+
test('rewind restores files and truncates the turn', async () => {
|
|
1297
|
+
const cwd = await mkdtemp(path.join(tmpdir(), 'tamnora-rewind-'));
|
|
1298
|
+
await writeFile(path.join(cwd, 'tamnora.json'), JSON.stringify({ permissions: { write: 'allow' } }));
|
|
1299
|
+
await writeFile(path.join(cwd, 'nota.txt'), 'original');
|
|
1300
|
+
const provider = {
|
|
1301
|
+
id: 'rw',
|
|
1302
|
+
async streamChat(_config, { messages }) {
|
|
1303
|
+
if (messages.some((m) => m.role === 'tool' && m.name === 'write')) {
|
|
1304
|
+
return { content: 'listo', reasoning: '', toolCalls: [] };
|
|
1305
|
+
}
|
|
1306
|
+
return {
|
|
1307
|
+
content: '',
|
|
1308
|
+
reasoning: '',
|
|
1309
|
+
toolCalls: [
|
|
1310
|
+
{
|
|
1311
|
+
id: 'w1',
|
|
1312
|
+
type: 'function',
|
|
1313
|
+
function: { name: 'write', arguments: JSON.stringify({ path: 'nota.txt', content: 'cambiado' }) },
|
|
1314
|
+
},
|
|
1315
|
+
],
|
|
1316
|
+
};
|
|
1317
|
+
},
|
|
1318
|
+
};
|
|
1319
|
+
const { instance, base } = await startServer({ cwd, resolveProvider: () => ({ provider, config: {} }) });
|
|
1320
|
+
const json = { 'Content-Type': 'application/json' };
|
|
1321
|
+
try {
|
|
1322
|
+
const created = await (
|
|
1323
|
+
await fetch(`${base}/api/sessions`, { method: 'POST', headers: json, body: JSON.stringify({ title: 't', model: 'm', cwd }) })
|
|
1324
|
+
).json();
|
|
1325
|
+
const sid = created.session.id;
|
|
1326
|
+
await (
|
|
1327
|
+
await fetch(`${base}/api/chat`, {
|
|
1328
|
+
method: 'POST',
|
|
1329
|
+
headers: json,
|
|
1330
|
+
body: JSON.stringify({ sessionId: sid, model: 'm', input: 'cambiá la nota' }),
|
|
1331
|
+
})
|
|
1332
|
+
).text();
|
|
1333
|
+
assert.equal(await readFile(path.join(cwd, 'nota.txt'), 'utf8'), 'cambiado');
|
|
1334
|
+
|
|
1335
|
+
const detail = await (await fetch(`${base}/api/sessions/${sid}`)).json();
|
|
1336
|
+
const userMsg = detail.messages.find((m) => m.role === 'user');
|
|
1337
|
+
assert.ok(userMsg, 'no se persistió el mensaje del usuario');
|
|
1338
|
+
|
|
1339
|
+
const cps = await (await fetch(`${base}/api/sessions/${sid}/checkpoints`)).json();
|
|
1340
|
+
assert.ok(cps.turns.includes(userMsg.id), 'no se registró el checkpoint del turno');
|
|
1341
|
+
|
|
1342
|
+
const res = await fetch(`${base}/api/sessions/${sid}/rewind`, {
|
|
1343
|
+
method: 'POST',
|
|
1344
|
+
headers: json,
|
|
1345
|
+
body: JSON.stringify({ turn: userMsg.id }),
|
|
1346
|
+
});
|
|
1347
|
+
assert.equal(res.status, 200);
|
|
1348
|
+
const out = await res.json();
|
|
1349
|
+
assert.equal(out.restored, 1);
|
|
1350
|
+
assert.equal(await readFile(path.join(cwd, 'nota.txt'), 'utf8'), 'original');
|
|
1351
|
+
|
|
1352
|
+
const after = await (await fetch(`${base}/api/sessions/${sid}`)).json();
|
|
1353
|
+
assert.equal(after.messages.length, 0);
|
|
1354
|
+
} finally {
|
|
1355
|
+
await instance.close();
|
|
1356
|
+
}
|
|
1357
|
+
});
|
|
1358
|
+
|
|
1359
|
+
test('hooks observe tool events and plugins add custom tools', async () => {
|
|
1360
|
+
const cwd = await mkdtemp(path.join(tmpdir(), 'tamnora-hooks-plugins-'));
|
|
1361
|
+
await mkdir(path.join(cwd, '.tamnora', 'hooks'), { recursive: true });
|
|
1362
|
+
await mkdir(path.join(cwd, '.tamnora', 'plugins'), { recursive: true });
|
|
1363
|
+
await writeFile(
|
|
1364
|
+
path.join(cwd, '.tamnora', 'hooks', 'audit.mjs'),
|
|
1365
|
+
"import { appendFileSync } from 'node:fs';\nimport path from 'node:path';\n" +
|
|
1366
|
+
"export default { name: 'audit', events: { 'tool.after': (event, ctx) => { appendFileSync(path.join(ctx.cwd, 'hook.log'), `${event.type}:${event.name}\\n`); } } };\n"
|
|
1367
|
+
);
|
|
1368
|
+
await writeFile(
|
|
1369
|
+
path.join(cwd, '.tamnora', 'plugins', 'demo.mjs'),
|
|
1370
|
+
"export default { name: 'demo', tools: [{ name: 'saludar', description: 'saluda', parameters: { quien: { type: 'string' } }, handler: (args) => `Hola ${args.quien}` }] };\n"
|
|
1371
|
+
);
|
|
1372
|
+
await writeFile(path.join(cwd, 'tamnora.json'), JSON.stringify({ permissions: { plugin__demo__saludar: 'allow' } }));
|
|
1373
|
+
|
|
1374
|
+
let captured = null;
|
|
1375
|
+
const provider = {
|
|
1376
|
+
id: 'hp',
|
|
1377
|
+
async streamChat(_config, { messages }) {
|
|
1378
|
+
const toolMsg = messages.find((m) => m.role === 'tool' && String(m.name).startsWith('plugin__'));
|
|
1379
|
+
if (toolMsg) {
|
|
1380
|
+
captured = toolMsg.content;
|
|
1381
|
+
return { content: 'ok', reasoning: '', toolCalls: [] };
|
|
1382
|
+
}
|
|
1383
|
+
return {
|
|
1384
|
+
content: '',
|
|
1385
|
+
reasoning: '',
|
|
1386
|
+
toolCalls: [
|
|
1387
|
+
{
|
|
1388
|
+
id: 't1',
|
|
1389
|
+
type: 'function',
|
|
1390
|
+
function: { name: 'plugin__demo__saludar', arguments: JSON.stringify({ quien: 'mundo' }) },
|
|
1391
|
+
},
|
|
1392
|
+
],
|
|
1393
|
+
};
|
|
1394
|
+
},
|
|
1395
|
+
};
|
|
1396
|
+
const { instance, base } = await startServer({ cwd, resolveProvider: () => ({ provider, config: {} }) });
|
|
1397
|
+
const json = { 'Content-Type': 'application/json' };
|
|
1398
|
+
try {
|
|
1399
|
+
const hooks = await (await fetch(`${base}/api/hooks`)).json();
|
|
1400
|
+
assert.ok(hooks.hooks.some((h) => h.id === 'audit'));
|
|
1401
|
+
|
|
1402
|
+
const plugins = await (await fetch(`${base}/api/plugins`)).json();
|
|
1403
|
+
assert.ok(plugins.plugins.some((p) => p.name === 'plugin__demo__saludar'));
|
|
1404
|
+
|
|
1405
|
+
const created = await (
|
|
1406
|
+
await fetch(`${base}/api/sessions`, { method: 'POST', headers: json, body: JSON.stringify({ title: 't', model: 'm', cwd }) })
|
|
1407
|
+
).json();
|
|
1408
|
+
await (
|
|
1409
|
+
await fetch(`${base}/api/chat`, {
|
|
1410
|
+
method: 'POST',
|
|
1411
|
+
headers: json,
|
|
1412
|
+
body: JSON.stringify({ sessionId: created.session.id, model: 'm', input: 'saludá' }),
|
|
1413
|
+
})
|
|
1414
|
+
).text();
|
|
1415
|
+
assert.equal(captured, 'Hola mundo');
|
|
1416
|
+
|
|
1417
|
+
await new Promise((resolve) => setTimeout(resolve, 150));
|
|
1418
|
+
const log = await readFile(path.join(cwd, 'hook.log'), 'utf8').catch(() => '');
|
|
1419
|
+
assert.match(log, /tool\.after:plugin__demo__saludar/);
|
|
1420
|
+
} finally {
|
|
1421
|
+
await instance.close();
|
|
1422
|
+
}
|
|
1423
|
+
});
|
|
1424
|
+
|
|
1224
1425
|
test('skills: modo eager inyecta el body en el system prompt', async () => {
|
|
1225
1426
|
let captured = '';
|
|
1226
1427
|
const captureProvider = {
|
package/package.json
CHANGED