@pi-archimedes/notify 2.2.0 → 2.3.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/package.json +4 -2
- package/src/index.ts +16 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-archimedes/notify",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package"
|
|
@@ -14,13 +14,15 @@
|
|
|
14
14
|
".": "./src/index.ts"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@pi-archimedes/core": "2.
|
|
17
|
+
"@pi-archimedes/core": "2.3.0"
|
|
18
18
|
},
|
|
19
19
|
"peerDependencies": {
|
|
20
20
|
"@earendil-works/pi-coding-agent": ">=0.1.0",
|
|
21
21
|
"@earendil-works/pi-tui": ">=0.1.0"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
+
"@earendil-works/pi-coding-agent": "^0.84.2",
|
|
25
|
+
"@earendil-works/pi-tui": "^0.84.2",
|
|
24
26
|
"typescript": "^6.0.0"
|
|
25
27
|
},
|
|
26
28
|
"pi": {
|
package/src/index.ts
CHANGED
|
@@ -4,6 +4,14 @@ import { loadConfig, saveConfig } from "@pi-archimedes/core/settings-io";
|
|
|
4
4
|
import { getBus, Events } from "@pi-archimedes/core/bus";
|
|
5
5
|
import { execFile } from "node:child_process";
|
|
6
6
|
|
|
7
|
+
// ── Trigger constants ────────────────────────────────────────────────────────
|
|
8
|
+
|
|
9
|
+
const TRIGGER = {
|
|
10
|
+
AGENT_END: "agent_end",
|
|
11
|
+
ASK_REQUEST: "ask_request",
|
|
12
|
+
} as const;
|
|
13
|
+
type TriggerType = (typeof TRIGGER)[keyof typeof TRIGGER];
|
|
14
|
+
|
|
7
15
|
// ── Config ──────────────────────────────────────────────────────────────────
|
|
8
16
|
|
|
9
17
|
export interface NotifyConfig {
|
|
@@ -124,7 +132,7 @@ export function notify(title: string, body: string): void {
|
|
|
124
132
|
// ── Circuit breaker state ───────────────────────────────────────────────────
|
|
125
133
|
|
|
126
134
|
let notifyTimer: ReturnType<typeof setTimeout> | null = null;
|
|
127
|
-
let pendingTrigger:
|
|
135
|
+
let pendingTrigger: TriggerType | null = null;
|
|
128
136
|
|
|
129
137
|
// ── Circuit breaker logic ───────────────────────────────────────────────────
|
|
130
138
|
|
|
@@ -138,7 +146,7 @@ export function cancelPending(): void {
|
|
|
138
146
|
}
|
|
139
147
|
|
|
140
148
|
/** Schedule a delayed notification (circuit breaker). */
|
|
141
|
-
export function scheduleNotify(trigger:
|
|
149
|
+
export function scheduleNotify(trigger: TriggerType): void {
|
|
142
150
|
// Cancel any existing timer first
|
|
143
151
|
cancelPending();
|
|
144
152
|
|
|
@@ -149,11 +157,11 @@ export function scheduleNotify(trigger: "agent_end" | "ask_request"): void {
|
|
|
149
157
|
return;
|
|
150
158
|
}
|
|
151
159
|
|
|
152
|
-
if (trigger ===
|
|
160
|
+
if (trigger === TRIGGER.AGENT_END && !config.notifyOnAgentEnd) {
|
|
153
161
|
return;
|
|
154
162
|
}
|
|
155
163
|
|
|
156
|
-
if (trigger ===
|
|
164
|
+
if (trigger === TRIGGER.ASK_REQUEST && !config.notifyOnQuestion) {
|
|
157
165
|
return;
|
|
158
166
|
}
|
|
159
167
|
|
|
@@ -169,8 +177,8 @@ export function scheduleNotify(trigger: "agent_end" | "ask_request"): void {
|
|
|
169
177
|
}
|
|
170
178
|
|
|
171
179
|
/** Fire the actual notification based on the pending trigger. */
|
|
172
|
-
function fireNotification(trigger:
|
|
173
|
-
if (trigger ===
|
|
180
|
+
function fireNotification(trigger: TriggerType | null): void {
|
|
181
|
+
if (trigger === TRIGGER.AGENT_END) {
|
|
174
182
|
notify("Pi", "Task complete — waiting for input");
|
|
175
183
|
} else {
|
|
176
184
|
notify("Pi", "A question needs your answer");
|
|
@@ -181,14 +189,14 @@ function fireNotification(trigger: "agent_end" | "ask_request" | null): void {
|
|
|
181
189
|
|
|
182
190
|
/** Register the notify extension with the Pi agent. */
|
|
183
191
|
export function registerNotify(pi: ExtensionAPI): void {
|
|
184
|
-
pi.on("agent_end", () => scheduleNotify(
|
|
192
|
+
pi.on("agent_end", () => scheduleNotify(TRIGGER.AGENT_END));
|
|
185
193
|
pi.on("input", () => cancelPending());
|
|
186
194
|
pi.on("before_agent_start", () => cancelPending());
|
|
187
195
|
pi.on("agent_start", () => cancelPending());
|
|
188
196
|
|
|
189
197
|
// Listen for ask requests from the bus (ask package emits this)
|
|
190
198
|
const unsubAskRequest = getBus().on(Events.ASK_REQUEST, () =>
|
|
191
|
-
scheduleNotify(
|
|
199
|
+
scheduleNotify(TRIGGER.ASK_REQUEST),
|
|
192
200
|
);
|
|
193
201
|
|
|
194
202
|
// Listen for raw terminal keystrokes — cancel on any key press
|