@gbrennon/good-news-everyone 0.1.0 → 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/README.md +15 -12
- package/package.json +1 -1
- package/scripts/install.sh +37 -26
- package/src/default_extension/default_extension.ts +29 -5
- package/src/notification_command.ts +340 -0
- package/src/notification_hook_service/notification_hook_service.ts +125 -1
- package/src/notification_settings.ts +219 -0
- package/src/notification_taglines/notification_tagline_selector.ts +5 -0
package/README.md
CHANGED
|
@@ -39,35 +39,38 @@ Shown when the agent fails or is aborted.
|
|
|
39
39
|
|
|
40
40
|
## Installation
|
|
41
41
|
|
|
42
|
-
###
|
|
42
|
+
### From npm
|
|
43
43
|
|
|
44
|
-
Install the package with the
|
|
44
|
+
Install the published package with the host package manager:
|
|
45
45
|
|
|
46
46
|
```bash
|
|
47
47
|
pi install npm:@gbrennon/good-news-everyone@0.1.0
|
|
48
|
+
omp plugin install @gbrennon/good-news-everyone@0.1.0
|
|
48
49
|
```
|
|
49
50
|
|
|
50
|
-
Pi loads `src/index.ts
|
|
51
|
+
Pi loads `src/index.ts`; OMP loads the dedicated `src/omp.ts` entrypoint.
|
|
52
|
+
Restart the host after installing or updating the package.
|
|
51
53
|
|
|
52
|
-
###
|
|
54
|
+
### From this checkout
|
|
53
55
|
|
|
54
|
-
|
|
56
|
+
Use the installer script when installing from a repository checkout:
|
|
55
57
|
|
|
56
58
|
```bash
|
|
57
|
-
|
|
59
|
+
./scripts/install.sh pi
|
|
60
|
+
./scripts/install.sh omp
|
|
58
61
|
```
|
|
59
62
|
|
|
60
|
-
|
|
61
|
-
lifecycle. Restart OMP after installing or updating the plugin.
|
|
62
|
-
|
|
63
|
-
### Manual installation
|
|
64
|
-
|
|
65
|
-
To install both hooks directly into the user extension directories:
|
|
63
|
+
Omit the agent name to install for both hosts:
|
|
66
64
|
|
|
67
65
|
```bash
|
|
68
66
|
./scripts/install.sh
|
|
69
67
|
```
|
|
70
68
|
|
|
69
|
+
The script installs the current checkout path through the Pi or OMP package
|
|
70
|
+
manager, so it uses the entrypoints and command code in this checkout rather
|
|
71
|
+
than a potentially stale published version. It also removes known legacy
|
|
72
|
+
manually copied notification hooks. It requires `pi` and/or `omp` on `PATH`.
|
|
73
|
+
|
|
71
74
|
## Overview
|
|
72
75
|
|
|
73
76
|
- Dispatches notifications on `ui_prompt_start` (input needed) and
|
package/package.json
CHANGED
package/scripts/install.sh
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
set -euo pipefail
|
|
3
3
|
|
|
4
4
|
root_dir="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
5
|
-
|
|
5
|
+
package_name="@gbrennon/good-news-everyone"
|
|
6
6
|
|
|
7
7
|
if [[ "$#" -gt 1 ]]; then
|
|
8
8
|
printf 'usage: %s [pi|omp]\n' "$0" >&2
|
|
@@ -15,24 +15,15 @@ if [[ "$#" == 1 && "$1" != "pi" && "$1" != "omp" ]]; then
|
|
|
15
15
|
exit 2
|
|
16
16
|
fi
|
|
17
17
|
|
|
18
|
-
if ! command -v "$bun_command" >/dev/null 2>&1; then
|
|
19
|
-
printf 'required command not found: %s\n' "$bun_command" >&2
|
|
20
|
-
exit 1
|
|
21
|
-
fi
|
|
22
|
-
|
|
23
18
|
if [[ "$#" == 1 ]]; then
|
|
24
19
|
agents=("$1")
|
|
25
20
|
else
|
|
26
21
|
agents=(pi omp)
|
|
27
22
|
fi
|
|
28
23
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
trap cleanup EXIT
|
|
34
|
-
|
|
35
|
-
for agent in "${agents[@]}"; do
|
|
24
|
+
remove_legacy_hooks() {
|
|
25
|
+
local agent="$1"
|
|
26
|
+
local extension_dir
|
|
36
27
|
case "$agent" in
|
|
37
28
|
pi)
|
|
38
29
|
extension_dir="${HOME}/.pi/agent/extensions"
|
|
@@ -42,20 +33,40 @@ for agent in "${agents[@]}"; do
|
|
|
42
33
|
;;
|
|
43
34
|
esac
|
|
44
35
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
--define "process.env.PI_HOOK_AGENT=\"$agent\"" >/dev/null
|
|
51
|
-
rm -f "$extension_dir/ai-toolkit-notify.ts"
|
|
52
|
-
rm -f "$extension_dir/ai-toolkit-notify-hook.ts"
|
|
53
|
-
rm -f "$extension_dir/gb-agent-notifications-hook.ts"
|
|
36
|
+
rm -f \
|
|
37
|
+
"$extension_dir/ai-toolkit-notify.ts" \
|
|
38
|
+
"$extension_dir/ai-toolkit-notify-hook.ts" \
|
|
39
|
+
"$extension_dir/gb-agent-notifications-hook.ts" \
|
|
40
|
+
"$extension_dir/good-news-everyone-hook.ts"
|
|
54
41
|
if [[ "$agent" == "omp" ]]; then
|
|
55
42
|
rm -f "${HOME}/.omp/agent/hooks/post/ai-toolkit-notify.ts"
|
|
56
43
|
fi
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
install_agent() {
|
|
47
|
+
local agent="$1"
|
|
48
|
+
case "$agent" in
|
|
49
|
+
pi)
|
|
50
|
+
command -v pi >/dev/null 2>&1 || {
|
|
51
|
+
printf 'required command not found: pi\n' >&2
|
|
52
|
+
exit 1
|
|
53
|
+
}
|
|
54
|
+
pi remove "npm:${package_name}" >/dev/null 2>&1 || true
|
|
55
|
+
pi remove "$root_dir" >/dev/null 2>&1 || true
|
|
56
|
+
pi install "$root_dir" --approve
|
|
57
|
+
;;
|
|
58
|
+
omp)
|
|
59
|
+
command -v omp >/dev/null 2>&1 || {
|
|
60
|
+
printf 'required command not found: omp\n' >&2
|
|
61
|
+
exit 1
|
|
62
|
+
}
|
|
63
|
+
omp plugin install "$root_dir" --force
|
|
64
|
+
;;
|
|
65
|
+
esac
|
|
66
|
+
remove_legacy_hooks "$agent"
|
|
67
|
+
printf 'installed checkout for %s through the package manager\n' "$agent"
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
for agent in "${agents[@]}"; do
|
|
71
|
+
install_agent "$agent"
|
|
61
72
|
done
|
|
@@ -3,16 +3,25 @@ import { NotificationHookService } from "../notification_hook_service";
|
|
|
3
3
|
import { NotificationTaglineSelector } from "../notification_taglines";
|
|
4
4
|
import type { AgentLifecycle } from "../notification_hooks_extension";
|
|
5
5
|
import { NotificationHooksExtension } from "../notification_hooks_extension";
|
|
6
|
+
import { NotificationSettingsStore } from "../notification_settings";
|
|
6
7
|
import { ReminderCoordinator } from "../reminder_coordinator";
|
|
7
8
|
import { SystemScheduler } from "../system_scheduler";
|
|
9
|
+
import {
|
|
10
|
+
registerNotificationCommand,
|
|
11
|
+
type NotificationCommandHostApi,
|
|
12
|
+
} from "../notification_command";
|
|
8
13
|
|
|
9
14
|
/**
|
|
10
15
|
* Compose and expose the production notification extension.
|
|
11
16
|
*/
|
|
12
17
|
export class DefaultExtension {
|
|
13
18
|
private readonly extension: NotificationHooksExtension;
|
|
19
|
+
private readonly settingsStore: NotificationSettingsStore;
|
|
20
|
+
private readonly service: NotificationHookService;
|
|
14
21
|
|
|
15
22
|
public constructor(agentName = process.env.PI_HOOK_AGENT ?? "pi") {
|
|
23
|
+
const settingsStore = new NotificationSettingsStore();
|
|
24
|
+
const settings = settingsStore.load();
|
|
16
25
|
const reminders = new ReminderCoordinator(
|
|
17
26
|
new SystemScheduler(),
|
|
18
27
|
DefaultExtension.readPositiveInteger(
|
|
@@ -24,12 +33,17 @@ export class DefaultExtension {
|
|
|
24
33
|
3,
|
|
25
34
|
),
|
|
26
35
|
);
|
|
36
|
+
const service = new NotificationHookService(
|
|
37
|
+
agentName,
|
|
38
|
+
reminders,
|
|
39
|
+
new NotificationTaglineSelector(),
|
|
40
|
+
settings.mode,
|
|
41
|
+
settings.completeKind,
|
|
42
|
+
);
|
|
43
|
+
this.settingsStore = settingsStore;
|
|
44
|
+
this.service = service;
|
|
27
45
|
this.extension = new NotificationHooksExtension(
|
|
28
|
-
|
|
29
|
-
agentName,
|
|
30
|
-
reminders,
|
|
31
|
-
new NotificationTaglineSelector(),
|
|
32
|
-
),
|
|
46
|
+
service,
|
|
33
47
|
DefaultExtension.lifecycleForAgent(agentName),
|
|
34
48
|
);
|
|
35
49
|
}
|
|
@@ -39,6 +53,16 @@ export class DefaultExtension {
|
|
|
39
53
|
*/
|
|
40
54
|
public register(api: HookApi): void {
|
|
41
55
|
this.extension.register(api);
|
|
56
|
+
const agentApi = api as { agent?: { kind?: "main" | "sub" } };
|
|
57
|
+
this.service.setAgentKind(agentApi.agent?.kind);
|
|
58
|
+
if ("registerCommand" in api) {
|
|
59
|
+
const hostApi = api as unknown as NotificationCommandHostApi;
|
|
60
|
+
registerNotificationCommand(
|
|
61
|
+
hostApi,
|
|
62
|
+
this.settingsStore,
|
|
63
|
+
this.service,
|
|
64
|
+
);
|
|
65
|
+
}
|
|
42
66
|
}
|
|
43
67
|
|
|
44
68
|
private static lifecycleForAgent(agent: string): AgentLifecycle {
|
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
import { NotificationSettingsStore } from "./notification_settings";
|
|
2
|
+
export { NotificationSettingsStore };
|
|
3
|
+
|
|
4
|
+
export type NotificationCommand =
|
|
5
|
+
| { kind: "show" }
|
|
6
|
+
| { kind: "menu" }
|
|
7
|
+
| { kind: "set"; key: "mode" | "completeKind"; value: string }
|
|
8
|
+
| { kind: "reset"; key?: "mode" | "completeKind" };
|
|
9
|
+
|
|
10
|
+
export const MENU_ACTIONS: readonly string[] = [
|
|
11
|
+
"Show current settings",
|
|
12
|
+
"Set notification mode",
|
|
13
|
+
"Set plan-complete kind",
|
|
14
|
+
"Reset a setting",
|
|
15
|
+
"Reset all settings",
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
const MODE_KEYS = ["mode", "completeKind"] as const;
|
|
19
|
+
const MODE_VALUES: readonly string[] = [
|
|
20
|
+
"per-subagent",
|
|
21
|
+
"all-complete",
|
|
22
|
+
"parent-only",
|
|
23
|
+
];
|
|
24
|
+
const COMPLETE_KIND_VALUES: readonly string[] = ["complete", "error", "question"];
|
|
25
|
+
|
|
26
|
+
const USAGE = [
|
|
27
|
+
"Usage: /good-news [show|menu|set <key> <value>|reset [<key>]]",
|
|
28
|
+
" show Print current notification settings",
|
|
29
|
+
" menu List available configuration actions",
|
|
30
|
+
' set mode <value> Set notification mode: per-subagent, all-complete, parent-only',
|
|
31
|
+
' set completeKind <value> Set plan-complete kind: complete, error, question',
|
|
32
|
+
" reset [mode|completeKind] Reset a setting to its default",
|
|
33
|
+
" reset Reset all settings to defaults",
|
|
34
|
+
].join("\n");
|
|
35
|
+
|
|
36
|
+
function parseSet(args: string[]): NotificationCommand {
|
|
37
|
+
if (args.length < 2) {
|
|
38
|
+
throw new Error(`Missing key or value.\n${USAGE}`);
|
|
39
|
+
}
|
|
40
|
+
const [key, value] = args;
|
|
41
|
+
if (!MODE_KEYS.includes(key as "mode" | "completeKind")) {
|
|
42
|
+
throw new Error(`Unknown setting key "${key}".\n${USAGE}`);
|
|
43
|
+
}
|
|
44
|
+
if (key === "mode") {
|
|
45
|
+
if (!MODE_VALUES.includes(value)) {
|
|
46
|
+
throw new Error(
|
|
47
|
+
`Invalid mode "${value}". Allowed: ${MODE_VALUES.join(", ")}.\n${USAGE}`,
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
} else {
|
|
51
|
+
if (!COMPLETE_KIND_VALUES.includes(value)) {
|
|
52
|
+
throw new Error(
|
|
53
|
+
`Invalid completeKind "${value}". Allowed: ${COMPLETE_KIND_VALUES.join(
|
|
54
|
+
", ",
|
|
55
|
+
)}.\n${USAGE}`,
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return { kind: "set", key: key as "mode" | "completeKind", value };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function parseReset(args: string[]): NotificationCommand {
|
|
63
|
+
if (args.length === 0) {
|
|
64
|
+
return { kind: "reset" };
|
|
65
|
+
}
|
|
66
|
+
const [key] = args;
|
|
67
|
+
if (!MODE_KEYS.includes(key as "mode" | "completeKind")) {
|
|
68
|
+
throw new Error(`Unknown setting key "${key}".\n${USAGE}`);
|
|
69
|
+
}
|
|
70
|
+
return { kind: "reset", key: key as "mode" | "completeKind" };
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Parse `/good-news` command arguments into a NotificationCommand.
|
|
75
|
+
* Throws a descriptive usage error on unknown key or invalid value.
|
|
76
|
+
*/
|
|
77
|
+
export function parseCommand(args: string): NotificationCommand {
|
|
78
|
+
const tokens = args.trim().split(/\s+/).filter((token) => token.length > 0);
|
|
79
|
+
if (tokens.length === 0) {
|
|
80
|
+
return { kind: "menu" };
|
|
81
|
+
}
|
|
82
|
+
const [head, ...rest] = tokens;
|
|
83
|
+
switch (head) {
|
|
84
|
+
case "show":
|
|
85
|
+
return { kind: "show" };
|
|
86
|
+
case "menu":
|
|
87
|
+
return { kind: "menu" };
|
|
88
|
+
case "set":
|
|
89
|
+
return parseSet(rest);
|
|
90
|
+
case "reset":
|
|
91
|
+
return parseReset(rest);
|
|
92
|
+
default:
|
|
93
|
+
throw new Error(`Unknown command "${head}".\n${USAGE}`);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export interface NotificationCommandContext {
|
|
98
|
+
ui?: {
|
|
99
|
+
notify(message: string, type?: "info" | "error"): void;
|
|
100
|
+
select?(title: string, options: string[]): Promise<string | undefined>;
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export interface NotificationCompletionItem {
|
|
105
|
+
value: string;
|
|
106
|
+
label: string;
|
|
107
|
+
description?: string;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export interface NotificationCommandHostApi {
|
|
111
|
+
registerCommand(
|
|
112
|
+
name: string,
|
|
113
|
+
options: {
|
|
114
|
+
description: string;
|
|
115
|
+
getArgumentCompletions?: (
|
|
116
|
+
prefix: string,
|
|
117
|
+
) => NotificationCompletionItem[] | null;
|
|
118
|
+
handler: (
|
|
119
|
+
args: string,
|
|
120
|
+
context: NotificationCommandContext,
|
|
121
|
+
) => void | Promise<void>;
|
|
122
|
+
},
|
|
123
|
+
): void;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
interface ConfigurableNotificationService {
|
|
127
|
+
configure?: (options: {
|
|
128
|
+
mode?: "per-subagent" | "all-complete" | "parent-only";
|
|
129
|
+
completeKind?: "complete" | "error" | "question";
|
|
130
|
+
}) => void;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const COMMAND_DESCRIPTIONS: Record<string, string> = {
|
|
134
|
+
show: "Show current notification settings",
|
|
135
|
+
menu: "List available configuration actions",
|
|
136
|
+
set: "Set a notification setting",
|
|
137
|
+
reset: "Reset notification settings",
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
function completionItems(
|
|
141
|
+
values: readonly string[],
|
|
142
|
+
prefix: string,
|
|
143
|
+
descriptions: Record<string, string> = {},
|
|
144
|
+
): NotificationCompletionItem[] | null {
|
|
145
|
+
const matches = values.filter((value) => value.startsWith(prefix));
|
|
146
|
+
if (matches.length === 0) {
|
|
147
|
+
return null;
|
|
148
|
+
}
|
|
149
|
+
return matches.map((value) => {
|
|
150
|
+
const description = descriptions[value];
|
|
151
|
+
return description
|
|
152
|
+
? { value, label: value, description }
|
|
153
|
+
: { value, label: value };
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function getArgumentCompletions(
|
|
158
|
+
prefix: string,
|
|
159
|
+
): NotificationCompletionItem[] | null {
|
|
160
|
+
const words = prefix.trim().split(/\s+/).filter(Boolean);
|
|
161
|
+
const hasTrailingSpace = /\s$/.test(prefix);
|
|
162
|
+
const current = hasTrailingSpace ? "" : (words.pop() ?? "");
|
|
163
|
+
|
|
164
|
+
if (words.length === 0) {
|
|
165
|
+
return completionItems(
|
|
166
|
+
["show", "menu", "set", "reset"],
|
|
167
|
+
current,
|
|
168
|
+
COMMAND_DESCRIPTIONS,
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
if (words[0] === "set" && words.length === 1) {
|
|
172
|
+
return completionItems(MODE_KEYS, current);
|
|
173
|
+
}
|
|
174
|
+
if (words[0] === "set" && words.length === 2) {
|
|
175
|
+
if (words[1] === "mode") {
|
|
176
|
+
return completionItems(MODE_VALUES, current);
|
|
177
|
+
}
|
|
178
|
+
if (words[1] === "completeKind") {
|
|
179
|
+
return completionItems(COMPLETE_KIND_VALUES, current);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
if (words[0] === "reset" && words.length === 1) {
|
|
183
|
+
return completionItems(MODE_KEYS, current);
|
|
184
|
+
}
|
|
185
|
+
return null;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function notify(
|
|
189
|
+
context: NotificationCommandContext,
|
|
190
|
+
message: string,
|
|
191
|
+
type: "info" | "error" = "info",
|
|
192
|
+
): void {
|
|
193
|
+
context.ui?.notify?.(message, type);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
async function showSettings(
|
|
197
|
+
context: NotificationCommandContext,
|
|
198
|
+
settingsStore: NotificationSettingsStore,
|
|
199
|
+
status?: string,
|
|
200
|
+
): Promise<void> {
|
|
201
|
+
const settings = settingsStore.load();
|
|
202
|
+
const lines = [
|
|
203
|
+
status,
|
|
204
|
+
`Notification settings (${settingsStore.getConfigPath()}):`,
|
|
205
|
+
` mode = ${settings.mode}`,
|
|
206
|
+
` completeKind = ${settings.completeKind}`,
|
|
207
|
+
].filter((line): line is string => line !== undefined);
|
|
208
|
+
notify(context, lines.join("\n"));
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function configureSetting(
|
|
212
|
+
service: ConfigurableNotificationService | undefined,
|
|
213
|
+
key: "mode" | "completeKind",
|
|
214
|
+
value: string,
|
|
215
|
+
): void {
|
|
216
|
+
if (key === "mode") {
|
|
217
|
+
service?.configure?.({
|
|
218
|
+
mode: value as "per-subagent" | "all-complete" | "parent-only",
|
|
219
|
+
});
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
service?.configure?.({
|
|
223
|
+
completeKind: value as "complete" | "error" | "question",
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
async function setSetting(
|
|
228
|
+
context: NotificationCommandContext,
|
|
229
|
+
settingsStore: NotificationSettingsStore,
|
|
230
|
+
service: ConfigurableNotificationService | undefined,
|
|
231
|
+
key: "mode" | "completeKind",
|
|
232
|
+
value: string,
|
|
233
|
+
): Promise<void> {
|
|
234
|
+
await settingsStore.saveSetting(key, value);
|
|
235
|
+
configureSetting(service, key, value);
|
|
236
|
+
await showSettings(context, settingsStore, `Set ${key}=${value}`);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
async function resetSetting(
|
|
240
|
+
context: NotificationCommandContext,
|
|
241
|
+
settingsStore: NotificationSettingsStore,
|
|
242
|
+
service: ConfigurableNotificationService | undefined,
|
|
243
|
+
key?: "mode" | "completeKind",
|
|
244
|
+
): Promise<void> {
|
|
245
|
+
settingsStore.reset(key);
|
|
246
|
+
if (key) {
|
|
247
|
+
configureSetting(service, key, key === "mode" ? "per-subagent" : "complete");
|
|
248
|
+
} else {
|
|
249
|
+
service?.configure?.({
|
|
250
|
+
mode: "per-subagent",
|
|
251
|
+
completeKind: "complete",
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
await showSettings(
|
|
255
|
+
context,
|
|
256
|
+
settingsStore,
|
|
257
|
+
`Reset${key ? ` ${key}` : " all"} settings`,
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
async function handleMenu(
|
|
262
|
+
context: NotificationCommandContext,
|
|
263
|
+
settingsStore: NotificationSettingsStore,
|
|
264
|
+
service: ConfigurableNotificationService | undefined,
|
|
265
|
+
): Promise<void> {
|
|
266
|
+
const select = context.ui?.select?.bind(context.ui);
|
|
267
|
+
if (!select) {
|
|
268
|
+
await showSettings(context, settingsStore);
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
const action = await select("Good news settings", [...MENU_ACTIONS]);
|
|
272
|
+
if (!action) return;
|
|
273
|
+
if (action === "Show current settings") {
|
|
274
|
+
await showSettings(context, settingsStore);
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
if (action === "Set notification mode") {
|
|
278
|
+
const value = await select("Set notification mode", [...MODE_VALUES]);
|
|
279
|
+
if (value) await setSetting(context, settingsStore, service, "mode", value);
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
if (action === "Set plan-complete kind") {
|
|
283
|
+
const value = await select("Set plan-complete kind", [...COMPLETE_KIND_VALUES]);
|
|
284
|
+
if (value) {
|
|
285
|
+
await setSetting(context, settingsStore, service, "completeKind", value);
|
|
286
|
+
}
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
if (action === "Reset a setting") {
|
|
290
|
+
const key = await select("Reset which setting?", [...MODE_KEYS]);
|
|
291
|
+
if (key === "mode" || key === "completeKind") {
|
|
292
|
+
await resetSetting(context, settingsStore, service, key);
|
|
293
|
+
}
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
if (action === "Reset all settings") {
|
|
297
|
+
await resetSetting(context, settingsStore, service);
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
throw new Error(`Unknown settings menu action: ${action}`);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
async function handleCommand(
|
|
304
|
+
command: NotificationCommand,
|
|
305
|
+
context: NotificationCommandContext,
|
|
306
|
+
settingsStore: NotificationSettingsStore,
|
|
307
|
+
service: ConfigurableNotificationService | undefined,
|
|
308
|
+
): Promise<void> {
|
|
309
|
+
if (command.kind === "show") {
|
|
310
|
+
await showSettings(context, settingsStore);
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
if (command.kind === "menu") {
|
|
314
|
+
await handleMenu(context, settingsStore, service);
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
if (command.kind === "set") {
|
|
318
|
+
await setSetting(context, settingsStore, service, command.key, command.value);
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
await resetSetting(context, settingsStore, service, command.key);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
export function registerNotificationCommand(
|
|
325
|
+
hostApi: NotificationCommandHostApi,
|
|
326
|
+
settingsStore: NotificationSettingsStore,
|
|
327
|
+
service?: ConfigurableNotificationService,
|
|
328
|
+
): void {
|
|
329
|
+
hostApi.registerCommand("good-news", {
|
|
330
|
+
description: "Configure notification granularity and plan-complete kind",
|
|
331
|
+
getArgumentCompletions,
|
|
332
|
+
handler: async (rawArgs: string, context: NotificationCommandContext) => {
|
|
333
|
+
try {
|
|
334
|
+
await handleCommand(parseCommand(rawArgs), context, settingsStore, service);
|
|
335
|
+
} catch (error) {
|
|
336
|
+
notify(context, error instanceof Error ? error.message : String(error), "error");
|
|
337
|
+
}
|
|
338
|
+
},
|
|
339
|
+
});
|
|
340
|
+
}
|
|
@@ -12,6 +12,11 @@ import {
|
|
|
12
12
|
} from "../notification_taglines";
|
|
13
13
|
import type { ReminderCoordinator } from "../reminder_coordinator";
|
|
14
14
|
import type { NotificationTemplate } from "./notification_template";
|
|
15
|
+
import type {
|
|
16
|
+
NotificationCompleteKind,
|
|
17
|
+
NotificationMode,
|
|
18
|
+
} from "../notification_settings";
|
|
19
|
+
|
|
15
20
|
|
|
16
21
|
/**
|
|
17
22
|
* Dispatch desktop lifecycle notifications for the Pi coding agent.
|
|
@@ -37,20 +42,57 @@ export class NotificationHookService {
|
|
|
37
42
|
private readonly outcomesByWorkspace: Record<string, AgentOutcome>;
|
|
38
43
|
private readonly agentEndNotificationByWorkspace: Record<string, boolean>;
|
|
39
44
|
private readonly questionNotificationByWorkspace: Record<string, boolean>;
|
|
45
|
+
private mode: NotificationMode;
|
|
46
|
+
private completeKind: NotificationCompleteKind;
|
|
47
|
+
private agentKind: "main" | "sub" | undefined;
|
|
48
|
+
private pendingOutcomes: Record<string, AgentOutcome>;
|
|
49
|
+
|
|
40
50
|
|
|
41
51
|
public constructor(
|
|
42
52
|
agentName: string,
|
|
43
53
|
reminders: ReminderCoordinator | undefined,
|
|
44
54
|
taglineSelector: NotificationTaglineSelector,
|
|
55
|
+
mode: NotificationMode = "per-subagent",
|
|
56
|
+
completeKind: NotificationCompleteKind = "complete",
|
|
57
|
+
agentKind: "main" | "sub" | undefined = undefined,
|
|
45
58
|
) {
|
|
46
59
|
this.agentName = agentName;
|
|
47
60
|
this.reminders = reminders;
|
|
48
61
|
this.taglineSelector = taglineSelector;
|
|
62
|
+
this.mode = mode;
|
|
63
|
+
this.completeKind = completeKind;
|
|
64
|
+
this.agentKind = agentKind;
|
|
49
65
|
this.outcomesByWorkspace = {};
|
|
50
66
|
this.agentEndNotificationByWorkspace = {};
|
|
51
67
|
this.questionNotificationByWorkspace = {};
|
|
68
|
+
this.pendingOutcomes = {};
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Set the host-reported agent identity kind (main/sub). OMP provides this;
|
|
72
|
+
* Pi leaves it undefined and degrades gracefully.
|
|
73
|
+
*/
|
|
74
|
+
public setAgentKind(kind: "main" | "sub" | undefined): void {
|
|
75
|
+
this.agentKind = kind;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Reconfigure notification mode and plan-complete kind at runtime so that
|
|
79
|
+
* /good-news commands take effect in the running extension without a
|
|
80
|
+
* restart.
|
|
81
|
+
*/
|
|
82
|
+
public configure(options?: {
|
|
83
|
+
mode?: NotificationMode;
|
|
84
|
+
completeKind?: NotificationCompleteKind;
|
|
85
|
+
}): void {
|
|
86
|
+
if (options?.mode !== undefined) {
|
|
87
|
+
this.mode = options.mode;
|
|
88
|
+
}
|
|
89
|
+
if (options?.completeKind !== undefined) {
|
|
90
|
+
this.completeKind = options.completeKind;
|
|
91
|
+
}
|
|
52
92
|
}
|
|
53
93
|
|
|
94
|
+
|
|
95
|
+
|
|
54
96
|
/**
|
|
55
97
|
* Notify the user when Pi starts waiting for interactive input.
|
|
56
98
|
*/
|
|
@@ -73,6 +115,7 @@ export class NotificationHookService {
|
|
|
73
115
|
this.outcomesByWorkspace[ctx.cwd] = "completed";
|
|
74
116
|
this.agentEndNotificationByWorkspace[ctx.cwd] = false;
|
|
75
117
|
this.questionNotificationByWorkspace[ctx.cwd] = false;
|
|
118
|
+
delete this.pendingOutcomes[ctx.cwd];
|
|
76
119
|
}
|
|
77
120
|
|
|
78
121
|
/**
|
|
@@ -80,6 +123,7 @@ export class NotificationHookService {
|
|
|
80
123
|
*/
|
|
81
124
|
public handleSessionShutdown(): void {
|
|
82
125
|
this.reminders?.cancelAll();
|
|
126
|
+
this.pendingOutcomes = {};
|
|
83
127
|
}
|
|
84
128
|
|
|
85
129
|
/**
|
|
@@ -90,6 +134,29 @@ export class NotificationHookService {
|
|
|
90
134
|
event: SettleEvent,
|
|
91
135
|
ctx: HookEventContext,
|
|
92
136
|
): Promise<void> {
|
|
137
|
+
if (this.mode === "all-complete") {
|
|
138
|
+
if (this.agentKind === "main") {
|
|
139
|
+
this.pendingOutcomes[ctx.cwd] = this.resolveOutcome(event, ctx);
|
|
140
|
+
await this.flushSubagentNotification(api, ctx);
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
if (this.agentKind === "sub") {
|
|
144
|
+
this.pendingOutcomes[ctx.cwd] = this.resolveOutcome(event, ctx);
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
// Pi: no sub-agent signal; degrade to per-session completion.
|
|
148
|
+
await this.notifySettlement(api, event, ctx);
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
if (this.mode === "parent-only") {
|
|
152
|
+
if (this.agentKind === "sub") {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
// main or undefined (Pi degrades): notify at parent boundary.
|
|
156
|
+
await this.notifySettlement(api, event, ctx);
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
// per-subagent: current settlement behavior.
|
|
93
160
|
const notification = this.getAgentEndNotification(event);
|
|
94
161
|
if (!notification) {
|
|
95
162
|
return;
|
|
@@ -121,6 +188,31 @@ export class NotificationHookService {
|
|
|
121
188
|
outcomes[ctx.cwd] = event.outcome || "completed";
|
|
122
189
|
}
|
|
123
190
|
|
|
191
|
+
/**
|
|
192
|
+
* Flush the latest pending sub-agent outcome for the workspace as one
|
|
193
|
+
* aggregated notification, used by all-complete mode when the parent
|
|
194
|
+
* agent completes.
|
|
195
|
+
*/
|
|
196
|
+
public async flushSubagentNotification(
|
|
197
|
+
api: HookApi,
|
|
198
|
+
ctx: HookEventContext,
|
|
199
|
+
): Promise<void> {
|
|
200
|
+
const outcome = this.pendingOutcomes[ctx.cwd];
|
|
201
|
+
delete this.pendingOutcomes[ctx.cwd];
|
|
202
|
+
if (!outcome) {
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
const template =
|
|
206
|
+
outcome === "error" || outcome === "aborted"
|
|
207
|
+
? { kind: "error", message: "task failed" }
|
|
208
|
+
: NotificationHookService.NOTIFICATION_BY_OUTCOME[outcome];
|
|
209
|
+
const kind =
|
|
210
|
+
template.kind === "complete" && this.completeKind !== "complete"
|
|
211
|
+
? this.completeKind
|
|
212
|
+
: template.kind;
|
|
213
|
+
await this.sendNotification(api, kind as NotificationEvent, ctx.cwd, template.message, false);
|
|
214
|
+
}
|
|
215
|
+
|
|
124
216
|
/**
|
|
125
217
|
* Emit a completion or error desktop notification when the agent settles.
|
|
126
218
|
*/
|
|
@@ -129,6 +221,9 @@ export class NotificationHookService {
|
|
|
129
221
|
event: SettleEvent,
|
|
130
222
|
ctx: HookEventContext,
|
|
131
223
|
): Promise<void> {
|
|
224
|
+
if (this.mode !== "per-subagent") {
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
132
227
|
if (this.agentEndNotificationByWorkspace[ctx.cwd]) {
|
|
133
228
|
return;
|
|
134
229
|
}
|
|
@@ -146,6 +241,29 @@ export class NotificationHookService {
|
|
|
146
241
|
event: SettleEvent,
|
|
147
242
|
ctx: HookEventContext,
|
|
148
243
|
): Promise<void> {
|
|
244
|
+
if (this.mode === "all-complete") {
|
|
245
|
+
if (this.agentKind === "main") {
|
|
246
|
+
this.pendingOutcomes[ctx.cwd] = this.resolveOutcome(event, ctx);
|
|
247
|
+
await this.flushSubagentNotification(api, ctx);
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
if (this.agentKind === "sub") {
|
|
251
|
+
this.pendingOutcomes[ctx.cwd] = this.resolveOutcome(event, ctx);
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
// Pi: no sub-agent signal; degrade to per-session completion.
|
|
255
|
+
await this.notifySettlement(api, event, ctx);
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
if (this.mode === "parent-only") {
|
|
259
|
+
if (this.agentKind === "sub") {
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
// main or undefined (Pi degrades): notify at parent boundary.
|
|
263
|
+
await this.notifySettlement(api, event, ctx);
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
// per-subagent: current settlement behavior.
|
|
149
267
|
await this.notifySettlement(api, event, ctx);
|
|
150
268
|
}
|
|
151
269
|
|
|
@@ -154,7 +272,13 @@ export class NotificationHookService {
|
|
|
154
272
|
event: SettleEvent,
|
|
155
273
|
ctx: HookEventContext,
|
|
156
274
|
): Promise<void> {
|
|
157
|
-
|
|
275
|
+
let template = this.getSettlementTemplate(event, ctx);
|
|
276
|
+
if (
|
|
277
|
+
template.kind === "complete"
|
|
278
|
+
&& this.completeKind !== "complete"
|
|
279
|
+
) {
|
|
280
|
+
template = { kind: this.completeKind, message: template.message };
|
|
281
|
+
}
|
|
158
282
|
if (
|
|
159
283
|
template.kind === "question"
|
|
160
284
|
&& this.questionNotificationByWorkspace[ctx.cwd]
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { homedir } from "node:os";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { existsSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
4
|
+
|
|
5
|
+
export type NotificationMode = "per-subagent" | "all-complete" | "parent-only";
|
|
6
|
+
|
|
7
|
+
export type NotificationCompleteKind = "complete" | "error" | "question";
|
|
8
|
+
|
|
9
|
+
export interface NotificationSettings {
|
|
10
|
+
mode: NotificationMode;
|
|
11
|
+
completeKind: NotificationCompleteKind;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const DEFAULT_NOTIFICATION_SETTINGS: NotificationSettings = {
|
|
15
|
+
mode: "per-subagent",
|
|
16
|
+
completeKind: "complete",
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const ALLOWED_MODES: readonly NotificationMode[] = [
|
|
20
|
+
"per-subagent",
|
|
21
|
+
"all-complete",
|
|
22
|
+
"parent-only",
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
const ALLOWED_COMPLETE_KINDS: readonly NotificationCompleteKind[] = [
|
|
26
|
+
"complete",
|
|
27
|
+
"error",
|
|
28
|
+
"question",
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
const MODE_KEY = "notifications.mode";
|
|
32
|
+
const COMPLETE_KIND_KEY = "notifications.completeKind";
|
|
33
|
+
|
|
34
|
+
function isNotificationMode(value: string): value is NotificationMode {
|
|
35
|
+
return ALLOWED_MODES.includes(value as NotificationMode);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function isNotificationCompleteKind(
|
|
39
|
+
value: string,
|
|
40
|
+
): value is NotificationCompleteKind {
|
|
41
|
+
return ALLOWED_COMPLETE_KINDS.includes(value as NotificationCompleteKind);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function defaultPath(): string {
|
|
45
|
+
const envPath = process.env.GOOD_NEWS_SETTINGS_PATH;
|
|
46
|
+
if (envPath) {
|
|
47
|
+
return envPath;
|
|
48
|
+
}
|
|
49
|
+
return join(homedir(), ".good-news-everyone.toml");
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function parseLine(line: string): { key: string; value: string } | undefined {
|
|
53
|
+
const trimmed = line.trim();
|
|
54
|
+
if (trimmed.length === 0 || trimmed.startsWith("#")) {
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
const equalsIndex = trimmed.indexOf("=");
|
|
58
|
+
if (equalsIndex === -1) {
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
const key = trimmed.slice(0, equalsIndex).trim();
|
|
62
|
+
const rawValue = trimmed.slice(equalsIndex + 1).trim();
|
|
63
|
+
const value = rawValue.replace(/^"(.*)"$/, "$1");
|
|
64
|
+
return { key, value };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function parseSettings(text: string): NotificationSettings {
|
|
68
|
+
const settings: NotificationSettings = { ...DEFAULT_NOTIFICATION_SETTINGS };
|
|
69
|
+
for (const line of text.split("\n")) {
|
|
70
|
+
const parsed = parseLine(line);
|
|
71
|
+
if (!parsed) {
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
if (parsed.key === MODE_KEY) {
|
|
75
|
+
if (isNotificationMode(parsed.value)) {
|
|
76
|
+
settings.mode = parsed.value;
|
|
77
|
+
}
|
|
78
|
+
} else if (parsed.key === COMPLETE_KIND_KEY) {
|
|
79
|
+
if (isNotificationCompleteKind(parsed.value)) {
|
|
80
|
+
settings.completeKind = parsed.value;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return settings;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function serializeSettings(settings: NotificationSettings): string {
|
|
88
|
+
return [
|
|
89
|
+
`${MODE_KEY} = "${settings.mode}"`,
|
|
90
|
+
`${COMPLETE_KIND_KEY} = "${settings.completeKind}"`,
|
|
91
|
+
].join("\n") + "\n";
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function isMissingFileError(error: unknown): boolean {
|
|
95
|
+
return (
|
|
96
|
+
typeof error === "object"
|
|
97
|
+
&& error !== null
|
|
98
|
+
&& "code" in error
|
|
99
|
+
&& error.code === "ENOENT"
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Flat key = value TOML settings store for notification behavior.
|
|
105
|
+
*
|
|
106
|
+
* Reads/writes `$HOME/.good-news-everyone.toml` (overridable via
|
|
107
|
+
* `GOOD_NEWS_SETTINGS_PATH`). Missing or malformed files fall back to
|
|
108
|
+
* defaults. Writes are atomic via temp file + rename into the same
|
|
109
|
+
* directory. No nested tables are supported.
|
|
110
|
+
*/
|
|
111
|
+
export class NotificationSettingsStore {
|
|
112
|
+
private readonly configPath: string;
|
|
113
|
+
|
|
114
|
+
public constructor(options?: { configPath?: string }) {
|
|
115
|
+
this.configPath = options?.configPath ?? defaultPath();
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Resolved settings file path.
|
|
120
|
+
*/
|
|
121
|
+
public getConfigPath(): string {
|
|
122
|
+
return this.configPath;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Load settings from disk; missing or malformed file returns defaults.
|
|
127
|
+
* Invalid mode/completeKind values fall back to default for that key.
|
|
128
|
+
*/
|
|
129
|
+
public load(): NotificationSettings {
|
|
130
|
+
try {
|
|
131
|
+
if (!existsSync(this.configPath)) {
|
|
132
|
+
return { ...DEFAULT_NOTIFICATION_SETTINGS };
|
|
133
|
+
}
|
|
134
|
+
return parseSettings(readFileSync(this.configPath, "utf8"));
|
|
135
|
+
} catch {
|
|
136
|
+
return { ...DEFAULT_NOTIFICATION_SETTINGS };
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Validate and persist a single setting atomically, then reload.
|
|
142
|
+
* Throws on unknown key or invalid value.
|
|
143
|
+
*/
|
|
144
|
+
public async saveSetting(
|
|
145
|
+
key: "mode" | "completeKind",
|
|
146
|
+
rawValue: string,
|
|
147
|
+
): Promise<NotificationSettings> {
|
|
148
|
+
let validated: NotificationSettings;
|
|
149
|
+
if (key === "mode") {
|
|
150
|
+
if (!isNotificationMode(rawValue)) {
|
|
151
|
+
throw new Error(
|
|
152
|
+
`Invalid notification mode "${rawValue}". Allowed: ${ALLOWED_MODES.join(
|
|
153
|
+
", ",
|
|
154
|
+
)}`,
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
validated = { ...this.load(), mode: rawValue };
|
|
158
|
+
} else {
|
|
159
|
+
if (!isNotificationCompleteKind(rawValue)) {
|
|
160
|
+
throw new Error(
|
|
161
|
+
`Invalid notification completeKind "${rawValue}". Allowed: ${ALLOWED_COMPLETE_KINDS.join(
|
|
162
|
+
", ",
|
|
163
|
+
)}`,
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
validated = { ...this.load(), completeKind: rawValue };
|
|
167
|
+
}
|
|
168
|
+
await this.writeSettings(validated);
|
|
169
|
+
return this.load();
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Delete a single key or the whole file. Missing file is silently ignored.
|
|
174
|
+
*/
|
|
175
|
+
public reset(key?: "mode" | "completeKind"): NotificationSettings {
|
|
176
|
+
if (key) {
|
|
177
|
+
const keyToRemove = key === "mode" ? MODE_KEY : COMPLETE_KIND_KEY;
|
|
178
|
+
let text: string;
|
|
179
|
+
try {
|
|
180
|
+
text = readFileSync(this.configPath, "utf8");
|
|
181
|
+
} catch (error) {
|
|
182
|
+
if (isMissingFileError(error)) {
|
|
183
|
+
return { ...DEFAULT_NOTIFICATION_SETTINGS };
|
|
184
|
+
}
|
|
185
|
+
throw error;
|
|
186
|
+
}
|
|
187
|
+
const kept = text
|
|
188
|
+
.split("\n")
|
|
189
|
+
.filter((line) => {
|
|
190
|
+
const parsed = parseLine(line);
|
|
191
|
+
return parsed === undefined || parsed.key !== keyToRemove;
|
|
192
|
+
})
|
|
193
|
+
.join("\n");
|
|
194
|
+
const dir = this.configPath.split("/").slice(0, -1).join("/") || ".";
|
|
195
|
+
const tempName = `.${process.pid}.${crypto.randomUUID()}.tmp`;
|
|
196
|
+
const tempPath = join(dir, tempName);
|
|
197
|
+
writeFileSync(tempPath, kept.endsWith("\n") ? kept : kept + "\n");
|
|
198
|
+
renameSync(tempPath, this.configPath);
|
|
199
|
+
return this.load();
|
|
200
|
+
}
|
|
201
|
+
try {
|
|
202
|
+
rmSync(this.configPath, { force: true });
|
|
203
|
+
} catch (error) {
|
|
204
|
+
if (!isMissingFileError(error)) {
|
|
205
|
+
throw error;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
return { ...DEFAULT_NOTIFICATION_SETTINGS };
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
private async writeSettings(settings: NotificationSettings): Promise<void> {
|
|
212
|
+
const dir = this.configPath.split("/").slice(0, -1).join("/") || ".";
|
|
213
|
+
const tempName = `.${process.pid}.${crypto.randomUUID()}.tmp`;
|
|
214
|
+
const tempPath = join(dir, tempName);
|
|
215
|
+
writeFileSync(tempPath, serializeSettings(settings));
|
|
216
|
+
renameSync(tempPath, this.configPath);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
}
|
|
@@ -37,6 +37,11 @@ export class NotificationTaglineSelector {
|
|
|
37
37
|
{ title: "Good news, Leela!", body: "I landed the contract to empty the spittoons." },
|
|
38
38
|
{ title: "Good news, everyone!", body: "The customer paid in advance." },
|
|
39
39
|
{ title: "Good news, everyone!", body: "The invention is ready for a completely safe test." },
|
|
40
|
+
{ title: "Good news, everyone!", body: "Your stem cells are cancer-free!" },
|
|
41
|
+
{ title: "Good news, everyone!", body: "The battery is charged and the lawyer is paid." },
|
|
42
|
+
{ title: "Good news, everyone!", body: "We're going to the dump!" },
|
|
43
|
+
{ title: "Good news, everyone!", body: "The bridge is out!" },
|
|
44
|
+
{ title: "Good news, everyone!", body: "There's no such thing as ghosts." },
|
|
40
45
|
],
|
|
41
46
|
error: [
|
|
42
47
|
{
|