+6
-6
main.ts
+6
-6
main.ts
···
8
import { checkBluesky } from "./tasks/checkBluesky.ts";
9
import { checkNotifications } from "./tasks/checkNotifications.ts";
10
11
-
setTimeout(logStats, msRandomOffset(msFrom.minutes(1), msFrom.minutes(5)));
12
13
setTimeout(
14
logTasks,
15
-
msRandomOffset(msFrom.minutes(30), msFrom.minutes(60)),
16
);
17
setTimeout(
18
sendSleepMessage,
19
-
msUntilDailyWindow(agentContext.sleepTime, 0, msFrom.minutes(20)),
20
);
21
setTimeout(
22
sendWakeMessage,
23
-
msUntilDailyWindow(agentContext.wakeTime, 0, msFrom.minutes(80)),
24
);
25
setTimeout(
26
runReflection,
27
-
msRandomOffset(msFrom.minutes(180), msFrom.minutes(240)),
28
);
29
setTimeout(
30
checkBluesky,
31
-
msRandomOffset(msFrom.minutes(10), msFrom.minutes(90)),
32
);
33
await checkNotifications();
···
8
import { checkBluesky } from "./tasks/checkBluesky.ts";
9
import { checkNotifications } from "./tasks/checkNotifications.ts";
10
11
+
setTimeout(logStats, msFrom.minutes(30));
12
13
setTimeout(
14
logTasks,
15
+
msFrom.minutes(100),
16
);
17
setTimeout(
18
sendSleepMessage,
19
+
msUntilDailyWindow(agentContext.sleepTime, 0, msFrom.minutes(30)),
20
);
21
setTimeout(
22
sendWakeMessage,
23
+
msUntilDailyWindow(agentContext.wakeTime, 0, msFrom.minutes(30)),
24
);
25
setTimeout(
26
runReflection,
27
+
msRandomOffset(msFrom.minutes(120), msFrom.minutes(240)),
28
);
29
setTimeout(
30
checkBluesky,
31
+
msRandomOffset(msFrom.minutes(45), msFrom.minutes(90)),
32
);
33
await checkNotifications();
+2
-2
tasks/checkBluesky.ts
+2
-2
tasks/checkBluesky.ts
···
13
14
export const checkBluesky = async () => {
15
if (!claimTaskThread()) {
16
-
const newDelay = msRandomOffset(msFrom.minutes(5), msFrom.minutes(10));
17
18
console.log(
19
`🔹 ${agentContext.agentBskyName} is busy, will try checking bluesky again in ${
20
newDelay * 60 * 1000
21
} minutes…`,
22
);
23
-
// agentContext is busy, try to check notifications in 5~10 minutes.
24
setTimeout(checkBluesky, newDelay);
25
return;
26
}
···
13
14
export const checkBluesky = async () => {
15
if (!claimTaskThread()) {
16
+
const newDelay = msFrom.minutes(2);
17
18
console.log(
19
`🔹 ${agentContext.agentBskyName} is busy, will try checking bluesky again in ${
20
newDelay * 60 * 1000
21
} minutes…`,
22
);
23
+
// agentContext is busy, try to check notifications in 2 minutes.
24
setTimeout(checkBluesky, newDelay);
25
return;
26
}
+4
-4
tasks/checkNotifications.ts
+4
-4
tasks/checkNotifications.ts
···
13
14
export const checkNotifications = async () => {
15
if (!claimTaskThread()) {
16
-
const newDelay = msRandomOffset(msFrom.minutes(5), msFrom.minutes(10));
17
console.log(
18
`🔹 ${agentContext.agentBskyName} is busy, checking for notifications again in ${
19
(newDelay * 1000) * 60
20
} minutes…`,
21
);
22
-
// agentContext is busy, try to check notifications in 5~10 minutes.
23
setTimeout(checkNotifications, newDelay);
24
return;
25
}
26
27
const delay = msUntilNextWakeWindow(
28
-
0,
29
-
msFrom.minutes(90),
30
);
31
32
if (delay !== 0) {
···
13
14
export const checkNotifications = async () => {
15
if (!claimTaskThread()) {
16
+
const newDelay = msFrom.minutes(2);
17
console.log(
18
`🔹 ${agentContext.agentBskyName} is busy, checking for notifications again in ${
19
(newDelay * 1000) * 60
20
} minutes…`,
21
);
22
+
// agentContext is busy, try to check notifications in 2 minutes.
23
setTimeout(checkNotifications, newDelay);
24
return;
25
}
26
27
const delay = msUntilNextWakeWindow(
28
+
msFrom.minutes(30),
29
+
msFrom.minutes(45),
30
);
31
32
if (delay !== 0) {
+1
-4
tasks/logStats.ts
+1
-4
tasks/logStats.ts
+1
-4
tasks/logTasks.ts
+1
-4
tasks/logTasks.ts
···
50
const uptime = Date.now() - serverStartTime;
51
const uptimeFormatted = formatUptime(uptime);
52
53
-
const nextCheckDelay = msRandomOffset(
54
-
msFrom.minutes(30),
55
-
msFrom.hours(1),
56
-
);
57
const nextCheckMinutes = ((nextCheckDelay / 1000) / 60).toFixed(1);
58
59
if (totalActivity <= 0) {
+4
-4
tasks/runReflection.ts
+4
-4
tasks/runReflection.ts
···
14
15
export const runReflection = async () => {
16
if (!claimTaskThread()) {
17
-
const newDelay = msRandomOffset(msFrom.minutes(5), msFrom.minutes(10));
18
19
console.log(
20
`🔹 ${agentContext.agentBskyName} is busy, will try reflecting again in ${
21
(newDelay / 1000) / 60
22
} minutes…`,
23
);
24
-
// session is busy, try to start reflection in 5~10 minutes.
25
setTimeout(runReflection, newDelay);
26
return;
27
}
···
34
return;
35
}
36
37
-
// adds 1-2 hours to wake time
38
// only applies if sleep is enabled
39
const delay = msUntilNextWakeWindow(
40
-
msFrom.hours(1),
41
msFrom.hours(2),
42
);
43
44
if (delay !== 0) {
···
14
15
export const runReflection = async () => {
16
if (!claimTaskThread()) {
17
+
const newDelay = msFrom.minutes(2);
18
19
console.log(
20
`🔹 ${agentContext.agentBskyName} is busy, will try reflecting again in ${
21
(newDelay / 1000) / 60
22
} minutes…`,
23
);
24
+
// session is busy, try to start reflection in 2 minutes.
25
setTimeout(runReflection, newDelay);
26
return;
27
}
···
34
return;
35
}
36
37
+
// adds 2-4 hours to wake time
38
// only applies if sleep is enabled
39
const delay = msUntilNextWakeWindow(
40
msFrom.hours(2),
41
+
msFrom.hours(4),
42
);
43
44
if (delay !== 0) {
+4
-4
tasks/sendSleepMessage.ts
+4
-4
tasks/sendSleepMessage.ts
···
14
15
export const sendSleepMessage = async () => {
16
if (!claimTaskThread()) {
17
-
const newDelay = msRandomOffset(msFrom.minutes(5), msFrom.minutes(10));
18
console.log(
19
`🔹 ${agentContext.agentBskyName} is busy, sending sleep message again in ${
20
(newDelay / 1000) / 60
21
} minutes…`,
22
);
23
-
// session is busy, try to check notifications in 5~10 minutes.
24
setTimeout(sendSleepMessage, newDelay);
25
return;
26
}
···
41
const delay = msUntilDailyWindow(
42
agentContext.sleepTime,
43
0,
44
-
msFrom.minutes(20),
45
);
46
setTimeout(sendSleepMessage, delay);
47
console.log(
···
61
console.log("🔹 wind down attempt processed, scheduling next wind down…");
62
setTimeout(
63
sendSleepMessage,
64
-
msUntilDailyWindow(agentContext.sleepTime, 0, msFrom.minutes(20)),
65
);
66
console.log("exiting wind down process");
67
releaseTaskThread();
···
14
15
export const sendSleepMessage = async () => {
16
if (!claimTaskThread()) {
17
+
const newDelay = msFrom.minutes(2);
18
console.log(
19
`🔹 ${agentContext.agentBskyName} is busy, sending sleep message again in ${
20
(newDelay / 1000) / 60
21
} minutes…`,
22
);
23
+
// session is busy, try to check notifications in 2 minutes.
24
setTimeout(sendSleepMessage, newDelay);
25
return;
26
}
···
41
const delay = msUntilDailyWindow(
42
agentContext.sleepTime,
43
0,
44
+
msFrom.minutes(30),
45
);
46
setTimeout(sendSleepMessage, delay);
47
console.log(
···
61
console.log("🔹 wind down attempt processed, scheduling next wind down…");
62
setTimeout(
63
sendSleepMessage,
64
+
msUntilDailyWindow(agentContext.sleepTime, 0, msFrom.minutes(30)),
65
);
66
console.log("exiting wind down process");
67
releaseTaskThread();
+4
-4
tasks/sendWakeMessage.ts
+4
-4
tasks/sendWakeMessage.ts
···
10
11
export const sendWakeMessage = async () => {
12
if (!claimTaskThread()) {
13
-
const newDelay = msRandomOffset(msFrom.minutes(5), msFrom.minutes(10));
14
console.log(
15
`🔹 ${agentContext.agentBskyName} is busy, sending wake message again in ${
16
(newDelay / 1000) / 60
17
} minutes…`,
18
);
19
-
// session is busy, try to check notifications in 5~10 minutes.
20
setTimeout(sendWakeMessage, newDelay);
21
return;
22
}
···
37
const delay = msUntilDailyWindow(
38
agentContext.wakeTime,
39
0,
40
-
msFrom.minutes(80),
41
);
42
setTimeout(sendWakeMessage, delay);
43
console.log(
···
57
console.log("🔹 wake attempt processed, scheduling next wake prompt…");
58
setTimeout(
59
sendWakeMessage,
60
-
msUntilDailyWindow(agentContext.wakeTime, 0, msFrom.minutes(80)),
61
);
62
console.log("🔹 exiting wake process");
63
releaseTaskThread();
···
10
11
export const sendWakeMessage = async () => {
12
if (!claimTaskThread()) {
13
+
const newDelay = msFrom.minutes(2);
14
console.log(
15
`🔹 ${agentContext.agentBskyName} is busy, sending wake message again in ${
16
(newDelay / 1000) / 60
17
} minutes…`,
18
);
19
+
// session is busy, try to check notifications in 2 minutes.
20
setTimeout(sendWakeMessage, newDelay);
21
return;
22
}
···
37
const delay = msUntilDailyWindow(
38
agentContext.wakeTime,
39
0,
40
+
msFrom.minutes(30),
41
);
42
setTimeout(sendWakeMessage, delay);
43
console.log(
···
57
console.log("🔹 wake attempt processed, scheduling next wake prompt…");
58
setTimeout(
59
sendWakeMessage,
60
+
msUntilDailyWindow(agentContext.wakeTime, 0, msFrom.minutes(30)),
61
);
62
console.log("🔹 exiting wake process");
63
releaseTaskThread();