@heylemon/lemonade 0.0.1 → 0.0.2
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.
|
@@ -349,6 +349,10 @@ export function buildAgentSystemPrompt(params) {
|
|
|
349
349
|
"- If files must be written, use `mktemp -d` and clean up after (`rm -rf $TMPDIR`).",
|
|
350
350
|
"- Skill-provided scripts (docx, xlsx, etc.) are fine to use as-is.",
|
|
351
351
|
"",
|
|
352
|
+
"## Cron / Reminders",
|
|
353
|
+
"ALWAYS use the `cron` tool (action: add/update/remove/list/run/status) for managing cron jobs and reminders.",
|
|
354
|
+
"NEVER use `exec` or shell commands to read/write cron files (e.g. ~/.lemonade/cron/jobs.json) directly — the gateway cron service will not detect the change.",
|
|
355
|
+
"",
|
|
352
356
|
"## Lemonade CLI Quick Reference",
|
|
353
357
|
"Lemonade is controlled via subcommands. Do not invent commands.",
|
|
354
358
|
"To manage the Gateway daemon service (start/stop/restart):",
|
package/dist/build-info.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
c77230f007691fa7cb97f258b75674d6a4a6be4b9afdfd0bc34c2edcf7e36e7b
|
package/dist/cron/service/ops.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { applyJobPatch, computeJobNextRunAtMs, createJob, findJobOrThrow, isJobDue, nextWakeAtMs, recomputeNextRuns, } from "./jobs.js";
|
|
2
2
|
import { locked } from "./locked.js";
|
|
3
|
-
import { ensureLoaded, persist, warnIfDisabled } from "./store.js";
|
|
3
|
+
import { ensureLoaded, forceReload, persist, startFileWatcher, stopFileWatcher, warnIfDisabled } from "./store.js";
|
|
4
4
|
import { armTimer, emit, executeJob, stopTimer, wake } from "./timer.js";
|
|
5
5
|
export async function start(state) {
|
|
6
6
|
await locked(state, async () => {
|
|
@@ -12,6 +12,18 @@ export async function start(state) {
|
|
|
12
12
|
recomputeNextRuns(state);
|
|
13
13
|
await persist(state);
|
|
14
14
|
armTimer(state);
|
|
15
|
+
startFileWatcher(state, () => {
|
|
16
|
+
state.deps.log.info({}, "cron: external file change detected, reloading");
|
|
17
|
+
void locked(state, async () => {
|
|
18
|
+
await forceReload(state);
|
|
19
|
+
recomputeNextRuns(state);
|
|
20
|
+
await persist(state);
|
|
21
|
+
armTimer(state);
|
|
22
|
+
state.deps.log.info({ jobs: state.store?.jobs.length ?? 0, nextWakeAtMs: nextWakeAtMs(state) ?? null }, "cron: reloaded from disk");
|
|
23
|
+
}).catch((err) => {
|
|
24
|
+
state.deps.log.error({ err: String(err) }, "cron: reload after file change failed");
|
|
25
|
+
});
|
|
26
|
+
});
|
|
15
27
|
state.deps.log.info({
|
|
16
28
|
enabled: true,
|
|
17
29
|
jobs: state.store?.jobs.length ?? 0,
|
|
@@ -21,6 +33,7 @@ export async function start(state) {
|
|
|
21
33
|
}
|
|
22
34
|
export function stop(state) {
|
|
23
35
|
stopTimer(state);
|
|
36
|
+
stopFileWatcher(state);
|
|
24
37
|
}
|
|
25
38
|
export async function status(state) {
|
|
26
39
|
return await locked(state, async () => {
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
1
3
|
import { migrateLegacyCronPayload } from "../payload-migration.js";
|
|
2
4
|
import { loadCronStore, saveCronStore } from "../store.js";
|
|
3
5
|
import { inferLegacyName, normalizeOptionalText } from "./normalize.js";
|
|
@@ -53,5 +55,44 @@ export function warnIfDisabled(state, action) {
|
|
|
53
55
|
export async function persist(state) {
|
|
54
56
|
if (!state.store)
|
|
55
57
|
return;
|
|
58
|
+
state.lastPersistTs = Date.now();
|
|
56
59
|
await saveCronStore(state.deps.storePath, state.store);
|
|
57
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* Force-reload the cron store from disk, discarding the in-memory cache.
|
|
63
|
+
* Used when the file is modified externally (e.g. by `exec`).
|
|
64
|
+
*/
|
|
65
|
+
export async function forceReload(state) {
|
|
66
|
+
storeCache.delete(state.deps.storePath);
|
|
67
|
+
state.store = null;
|
|
68
|
+
await ensureLoaded(state);
|
|
69
|
+
}
|
|
70
|
+
const EXTERNAL_CHANGE_GRACE_MS = 2000;
|
|
71
|
+
export function startFileWatcher(state, onExternalChange) {
|
|
72
|
+
stopFileWatcher(state);
|
|
73
|
+
const dir = path.dirname(state.deps.storePath);
|
|
74
|
+
const basename = path.basename(state.deps.storePath);
|
|
75
|
+
try {
|
|
76
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
77
|
+
const watcher = fs.watch(dir, (eventType, filename) => {
|
|
78
|
+
if (filename !== basename)
|
|
79
|
+
return;
|
|
80
|
+
if (Date.now() - state.lastPersistTs < EXTERNAL_CHANGE_GRACE_MS)
|
|
81
|
+
return;
|
|
82
|
+
onExternalChange();
|
|
83
|
+
});
|
|
84
|
+
watcher.on("error", () => {
|
|
85
|
+
// Non-fatal; the watcher may fail on some file systems
|
|
86
|
+
});
|
|
87
|
+
state.fileWatcher = watcher;
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
// Watching is best-effort
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
export function stopFileWatcher(state) {
|
|
94
|
+
if (state.fileWatcher) {
|
|
95
|
+
state.fileWatcher.close();
|
|
96
|
+
state.fileWatcher = null;
|
|
97
|
+
}
|
|
98
|
+
}
|