@akalsey/sapience-goals 0.1.2 → 0.2.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/dist/src/events.js +12 -0
- package/dist/src/service.js +11 -0
- package/dist/src/types.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { appendFile, mkdir } from "fs/promises";
|
|
2
|
+
import { dirname } from "path";
|
|
3
|
+
export async function appendEvent(eventsPath, event) {
|
|
4
|
+
try {
|
|
5
|
+
const full = { ...event, ts: event.ts ?? new Date().toISOString() };
|
|
6
|
+
await mkdir(dirname(eventsPath), { recursive: true });
|
|
7
|
+
await appendFile(eventsPath, JSON.stringify(full) + "\n", "utf-8");
|
|
8
|
+
}
|
|
9
|
+
catch {
|
|
10
|
+
// Observability must never break the host plugin.
|
|
11
|
+
}
|
|
12
|
+
}
|
package/dist/src/service.js
CHANGED
|
@@ -5,6 +5,7 @@ import { resolveDataPath, generateId, isWithinActiveHours, nextWeeklyDate } from
|
|
|
5
5
|
import { loadGoals, saveGoals, addGoal, updateNextDelivery } from "./goal-store.js";
|
|
6
6
|
import { readNewGoals, savePosition } from "./inbox-reader.js";
|
|
7
7
|
import { deliverDecomposition, deliverWeeklyStatus } from "./delivery.js";
|
|
8
|
+
import { appendEvent } from "./events.js";
|
|
8
9
|
function mergeConfig(raw, workspaceDir) {
|
|
9
10
|
return {
|
|
10
11
|
...DEFAULT_CONFIG,
|
|
@@ -14,6 +15,7 @@ function mergeConfig(raw, workspaceDir) {
|
|
|
14
15
|
...DEFAULT_CONFIG.output,
|
|
15
16
|
...(raw.output ?? {}),
|
|
16
17
|
goalsPath: resolveDataPath(raw.output?.goalsPath, workspaceDir, DEFAULT_CONFIG.output.goalsPath),
|
|
18
|
+
eventsPath: resolveDataPath(raw.output?.eventsPath, workspaceDir, DEFAULT_CONFIG.output.eventsPath),
|
|
17
19
|
},
|
|
18
20
|
inboxPath: resolveDataPath(raw.inboxPath, workspaceDir, DEFAULT_CONFIG.inboxPath),
|
|
19
21
|
inboxPositionPath: resolveDataPath(raw.inboxPositionPath, workspaceDir, DEFAULT_CONFIG.inboxPositionPath),
|
|
@@ -58,6 +60,7 @@ export default definePluginEntry({
|
|
|
58
60
|
goals = addGoal(goals, goal);
|
|
59
61
|
await saveGoals(goals, config.output.goalsPath);
|
|
60
62
|
await deliverDecomposition(description, api);
|
|
63
|
+
await appendEvent(config.output.eventsPath, { plugin: "goals", type: "goal_created", goal_id: goal.id });
|
|
61
64
|
return { content: [{ type: "text", text: JSON.stringify({ id: goal.id }) }] };
|
|
62
65
|
}
|
|
63
66
|
catch (err) {
|
|
@@ -72,6 +75,7 @@ export default definePluginEntry({
|
|
|
72
75
|
async execute(_id, _params) {
|
|
73
76
|
try {
|
|
74
77
|
if (!isWithinActiveHours(config)) {
|
|
78
|
+
await appendEvent(config.output.eventsPath, { plugin: "goals", type: "check_skipped", reason: "outside_hours" });
|
|
75
79
|
return { content: [{ type: "text", text: "SILENT_REPLY_TOKEN" }] };
|
|
76
80
|
}
|
|
77
81
|
let goals = await loadGoals(config.output.goalsPath);
|
|
@@ -91,17 +95,24 @@ export default definePluginEntry({
|
|
|
91
95
|
};
|
|
92
96
|
goals = addGoal(goals, goal);
|
|
93
97
|
await deliverDecomposition(description, api);
|
|
98
|
+
await appendEvent(config.output.eventsPath, { plugin: "goals", type: "goal_created", goal_id: goal.id });
|
|
94
99
|
}
|
|
95
100
|
if (newDescriptions.length > 0) {
|
|
96
101
|
await savePosition(newPosition, config.inboxPositionPath);
|
|
97
102
|
}
|
|
103
|
+
let delivered = 0;
|
|
98
104
|
for (const goal of goals) {
|
|
99
105
|
if (isWeeklyCheckInDue(goal)) {
|
|
100
106
|
await deliverWeeklyStatus(goal, api);
|
|
107
|
+
delivered++;
|
|
108
|
+
await appendEvent(config.output.eventsPath, { plugin: "goals", type: "status_delivered", goal_id: goal.id });
|
|
101
109
|
goals = updateNextDelivery(goals, goal.id, nextWeeklyDate(config.weeklyCheckInDay, config.weeklyCheckInTime, config.activeHours.timezone));
|
|
102
110
|
}
|
|
103
111
|
}
|
|
104
112
|
await saveGoals(goals, config.output.goalsPath);
|
|
113
|
+
if (newDescriptions.length === 0 && delivered === 0) {
|
|
114
|
+
await appendEvent(config.output.eventsPath, { plugin: "goals", type: "check_skipped", reason: "nothing_due" });
|
|
115
|
+
}
|
|
105
116
|
return { content: [{ type: "text", text: "SILENT_REPLY_TOKEN" }] };
|
|
106
117
|
}
|
|
107
118
|
catch (err) {
|
package/dist/src/types.js
CHANGED
|
@@ -5,5 +5,5 @@ export const DEFAULT_CONFIG = {
|
|
|
5
5
|
weeklyCheckInTime: "09:00",
|
|
6
6
|
inboxPath: "goals/inbox.md",
|
|
7
7
|
inboxPositionPath: "goals/inbox-position.json",
|
|
8
|
-
output: { goalsPath: "goals/goals.json" },
|
|
8
|
+
output: { goalsPath: "goals/goals.json", eventsPath: "sapience/events.jsonl" },
|
|
9
9
|
};
|