agentel 0.3.0 → 0.3.1
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/README.md +17 -1
- package/docs/code-reference.md +44 -0
- package/docs/history-source-handling.md +43 -43
- package/docs/release.md +1 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/src/archive.js +2 -0
- package/src/cli.js +679 -54
- package/src/config.js +37 -1
- package/src/slack-notify.js +732 -0
- package/src/supervisor.js +37 -1
package/src/supervisor.js
CHANGED
|
@@ -43,7 +43,8 @@ function createTickState() {
|
|
|
43
43
|
lastMemoryBackupAt: 0,
|
|
44
44
|
pendingSources: new Set(),
|
|
45
45
|
tickAgain: false,
|
|
46
|
-
watch: null
|
|
46
|
+
watch: null,
|
|
47
|
+
nextNotifyCheckAt: 0
|
|
47
48
|
};
|
|
48
49
|
}
|
|
49
50
|
|
|
@@ -242,6 +243,24 @@ async function tick(env, state = createTickState()) {
|
|
|
242
243
|
}
|
|
243
244
|
}
|
|
244
245
|
|
|
246
|
+
try {
|
|
247
|
+
const cfg = loadConfig(env);
|
|
248
|
+
if (cfg.notify?.slack?.enabled) {
|
|
249
|
+
// New archive writes (queue file present) trigger a pass right away;
|
|
250
|
+
// otherwise re-check when the soonest quiet window can elapse.
|
|
251
|
+
const queueWaiting = fs.existsSync(path.join(paths(env).state, "slack-notify-queue.jsonl"));
|
|
252
|
+
if (queueWaiting || now >= state.nextNotifyCheckAt) {
|
|
253
|
+
const result = await slackNotifyInChild(env);
|
|
254
|
+
const nextCheckMs = Math.max(30 * 1000, Number(result?.nextCheckMs) || 5 * 60 * 1000);
|
|
255
|
+
state.nextNotifyCheckAt = now + nextCheckMs;
|
|
256
|
+
if (result?.posted) log(`slack notify posted ${result.posted} session summar${result.posted === 1 ? "y" : "ies"}`, env);
|
|
257
|
+
for (const message of result?.errors || []) log(`slack notify error: ${message}`, env);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
} catch (error) {
|
|
261
|
+
log(`slack notify skipped: ${error.message}`, env);
|
|
262
|
+
}
|
|
263
|
+
|
|
245
264
|
if (now - state.lastMemoryBackupAt >= MEMORY_BACKUP_INTERVAL_MS) {
|
|
246
265
|
try {
|
|
247
266
|
const summaries = await memoryBackupInChild(env);
|
|
@@ -306,6 +325,22 @@ process.title = ${JSON.stringify(title)};
|
|
|
306
325
|
return runJsonChild(script, env, "memory backup", title);
|
|
307
326
|
}
|
|
308
327
|
|
|
328
|
+
function slackNotifyInChild(env = process.env) {
|
|
329
|
+
const title = childProcessTitle("slack-notify");
|
|
330
|
+
const script = `
|
|
331
|
+
process.title = ${JSON.stringify(title)};
|
|
332
|
+
(async () => {
|
|
333
|
+
const { runSlackNotify } = require(${JSON.stringify(path.join(__dirname, "slack-notify"))});
|
|
334
|
+
const result = await runSlackNotify(process.env);
|
|
335
|
+
process.stdout.write(JSON.stringify(result));
|
|
336
|
+
})().catch((error) => {
|
|
337
|
+
console.error(error && error.message ? error.message : String(error));
|
|
338
|
+
process.exit(1);
|
|
339
|
+
});
|
|
340
|
+
`;
|
|
341
|
+
return runJsonChild(script, env, "slack notify", title);
|
|
342
|
+
}
|
|
343
|
+
|
|
309
344
|
function reindexInChild(env = process.env) {
|
|
310
345
|
const title = childProcessTitle("index");
|
|
311
346
|
const script = `
|
|
@@ -548,6 +583,7 @@ module.exports = {
|
|
|
548
583
|
importSourceInChild,
|
|
549
584
|
memoryBackupInChild,
|
|
550
585
|
reindexInChild,
|
|
586
|
+
slackNotifyInChild,
|
|
551
587
|
runJsonChild,
|
|
552
588
|
syncInChild,
|
|
553
589
|
tick
|