@danieltmn/tamnora 0.13.0 → 0.14.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 +31 -0
- package/harness/packages/core/src/index.js +1 -0
- package/harness/packages/core/src/schedule/cron.js +124 -0
- package/harness/packages/core/src/storage/sqlite.js +96 -1
- package/harness/packages/core/test/cron.test.js +46 -0
- package/harness/packages/server/public/app.js +187 -3
- package/harness/packages/server/public/index.html +67 -1
- 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/agentRun.js +21 -0
- package/harness/packages/server/src/lib/checkpoints.js +106 -0
- package/harness/packages/server/src/lib/scheduler.js +183 -0
- package/harness/packages/server/src/routes/chat.js +8 -2
- 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 +8 -0
- package/harness/packages/server/test/server.test.js +144 -5
- package/package.json +1 -1
|
@@ -728,11 +728,15 @@ test('approving clears the permission instead of bringing it back', async () =>
|
|
|
728
728
|
body: JSON.stringify({ allow: true }),
|
|
729
729
|
});
|
|
730
730
|
assert.equal(decision.status, 200);
|
|
731
|
-
approved.push(ask.askId);
|
|
732
|
-
// Inmediatamente despues de resolver, no queda pendiente: si
|
|
733
|
-
// el cliente lo re-pintaria en bucle.
|
|
734
|
-
|
|
735
|
-
|
|
731
|
+
approved.push(ask.askId);
|
|
732
|
+
// Inmediatamente despues de resolver, ese permiso no queda pendiente: si
|
|
733
|
+
// volviera, el cliente lo re-pintaria en bucle. (Puede haber otro askId
|
|
734
|
+
// nuevo del siguiente paso, pero el resuelto no puede reaparecer.)
|
|
735
|
+
const after = await (await fetch(`${base}/api/state`)).json();
|
|
736
|
+
assert.ok(
|
|
737
|
+
!after.permissions.some((p) => p.askId === ask.askId),
|
|
738
|
+
'el permiso resuelto no debe reaparecer'
|
|
739
|
+
);
|
|
736
740
|
}
|
|
737
741
|
}
|
|
738
742
|
// Tres peticiones del agente -> tres askId distintos, ninguno revivido.
|
|
@@ -1217,6 +1221,141 @@ test('rules by path are injected (transiently) when a tool touches a matching fi
|
|
|
1217
1221
|
}
|
|
1218
1222
|
});
|
|
1219
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
|
+
|
|
1220
1359
|
test('skills: modo eager inyecta el body en el system prompt', async () => {
|
|
1221
1360
|
let captured = '';
|
|
1222
1361
|
const captureProvider = {
|
package/package.json
CHANGED