opencode-ntfy.sh 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Anthony Lannutti
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,127 @@
1
+ # opencode-ntfy.sh
2
+
3
+ An [OpenCode](https://opencode.ai) plugin that sends push notifications via
4
+ [ntfy.sh](https://ntfy.sh) when your AI coding session finishes or encounters
5
+ an error. Start a long-running task, walk away, and get notified on your phone
6
+ or desktop when it needs your attention.
7
+
8
+ ## Notifications
9
+
10
+ The plugin sends notifications for two events:
11
+
12
+ - **Session Idle** -- The AI agent has finished its work and is waiting for
13
+ input. Includes the project name and timestamp.
14
+ - **Session Error** -- The session encountered an error. Includes the project
15
+ name, timestamp, and error message (when available).
16
+
17
+ If `NTFY_TOPIC` is not set, the plugin does nothing.
18
+
19
+ ## Install
20
+
21
+ Add the package name to the `plugin` array in your OpenCode config file.
22
+
23
+ opencode.json:
24
+
25
+ ```json
26
+ {
27
+ "$schema": "https://opencode.ai/config.json",
28
+ "plugin": ["opencode-ntfy.sh"]
29
+ }
30
+ ```
31
+
32
+ ## Configuration
33
+
34
+ Configuration is done through environment variables.
35
+
36
+ | Variable | Required | Default | Description |
37
+ |---|---|---|---|
38
+ | `NTFY_TOPIC` | Yes | -- | The ntfy.sh topic to publish to. |
39
+ | `NTFY_SERVER` | No | `https://ntfy.sh` | The ntfy server URL. Set this to use a self-hosted instance. |
40
+ | `NTFY_TOKEN` | No | -- | Bearer token for authenticated topics. |
41
+ | `NTFY_PRIORITY` | No | `default` | Notification priority. One of: `min`, `low`, `default`, `high`, `max`. |
42
+
43
+ ### Subscribing to notifications
44
+
45
+ To receive notifications, subscribe to your topic using any
46
+ [ntfy client](https://docs.ntfy.sh/subscribe/):
47
+
48
+ - **Phone**: Install the ntfy app
49
+ ([Android](https://play.google.com/store/apps/details?id=io.heckel.ntfy),
50
+ [iOS](https://apps.apple.com/us/app/ntfy/id1625396347)) and subscribe to
51
+ your topic.
52
+ - **Desktop**: Open `https://ntfy.sh/<your-topic>` in a browser.
53
+ - **CLI**: `curl -s ntfy.sh/<your-topic>/json`
54
+
55
+ ### Example
56
+
57
+ ```sh
58
+ export NTFY_TOPIC="my-opencode-notifications"
59
+ opencode
60
+ ```
61
+
62
+ With authentication and a self-hosted server:
63
+
64
+ ```sh
65
+ export NTFY_TOPIC="my-opencode-notifications"
66
+ export NTFY_SERVER="https://ntfy.example.com"
67
+ export NTFY_TOKEN="tk_mytoken"
68
+ export NTFY_PRIORITY="high"
69
+ opencode
70
+ ```
71
+
72
+ ## Development
73
+
74
+ ### Prerequisites
75
+
76
+ - Node.js (v18+ for native `fetch` support)
77
+ - npm
78
+
79
+ ### Setup
80
+
81
+ ```sh
82
+ git clone https://github.com/lannuttia/opencode-ntfy.sh.git
83
+ cd opencode-ntfy.sh
84
+ npm install
85
+ ```
86
+
87
+ ### Build
88
+
89
+ ```sh
90
+ npm run build
91
+ ```
92
+
93
+ This compiles TypeScript from `src/` to `dist/` via `tsc`.
94
+
95
+ ### Test
96
+
97
+ ```sh
98
+ npm test
99
+ ```
100
+
101
+ Or in watch mode:
102
+
103
+ ```sh
104
+ npm run test:watch
105
+ ```
106
+
107
+ ### Using a development build with OpenCode
108
+
109
+ To use a local development build as a plugin, place or symlink the project
110
+ directory into the OpenCode plugins folder:
111
+
112
+ ```sh
113
+ # Build first
114
+ npm run build
115
+
116
+ # Project-level (applies to a single project)
117
+ ln -s /path/to/opencode-ntfy.sh .opencode/plugins/opencode-ntfy.sh
118
+
119
+ # Or global (applies to all projects)
120
+ ln -s /path/to/opencode-ntfy.sh ~/.config/opencode/plugins/opencode-ntfy.sh
121
+ ```
122
+
123
+ Then set the required environment variables and start OpenCode as usual.
124
+
125
+ ## License
126
+
127
+ MIT
@@ -0,0 +1,7 @@
1
+ export interface NtfyConfig {
2
+ topic: string;
3
+ server: string;
4
+ token?: string;
5
+ priority: string;
6
+ }
7
+ export declare function loadConfig(env: Record<string, string | undefined>): NtfyConfig;
package/dist/config.js ADDED
@@ -0,0 +1,17 @@
1
+ const VALID_PRIORITIES = ["min", "low", "default", "high", "max"];
2
+ export function loadConfig(env) {
3
+ const topic = env.NTFY_TOPIC;
4
+ if (!topic) {
5
+ throw new Error("NTFY_TOPIC environment variable is required");
6
+ }
7
+ const priority = env.NTFY_PRIORITY || "default";
8
+ if (!VALID_PRIORITIES.includes(priority)) {
9
+ throw new Error(`NTFY_PRIORITY must be one of: ${VALID_PRIORITIES.join(", ")}`);
10
+ }
11
+ return {
12
+ topic,
13
+ server: env.NTFY_SERVER || "https://ntfy.sh",
14
+ token: env.NTFY_TOKEN,
15
+ priority,
16
+ };
17
+ }
@@ -0,0 +1,3 @@
1
+ import type { Plugin } from "@opencode-ai/plugin";
2
+ export declare const plugin: Plugin;
3
+ export default plugin;
package/dist/index.js ADDED
@@ -0,0 +1,55 @@
1
+ import { loadConfig } from "./config.js";
2
+ import { sendNotification } from "./notify.js";
3
+ function getProjectName(directory) {
4
+ return directory.split("/").pop() || directory;
5
+ }
6
+ export const plugin = async (input) => {
7
+ if (!process.env.NTFY_TOPIC) {
8
+ return {};
9
+ }
10
+ const config = loadConfig(process.env);
11
+ const project = getProjectName(input.directory);
12
+ return {
13
+ event: async ({ event }) => {
14
+ if (event.type === "session.idle") {
15
+ await sendNotification(config, {
16
+ title: `${project} - Session Idle`,
17
+ message: `Event: session.idle\nProject: ${project}\nTime: ${new Date().toISOString()}`,
18
+ tags: "hourglass_done",
19
+ });
20
+ }
21
+ else if (event.type === "session.error") {
22
+ const error = event.properties.error;
23
+ const errorMsg = error && "data" in error && "message" in error.data
24
+ ? `\nError: ${error.data.message}`
25
+ : "";
26
+ await sendNotification(config, {
27
+ title: `${project} - Session Error`,
28
+ message: `Event: session.error\nProject: ${project}\nTime: ${new Date().toISOString()}${errorMsg}`,
29
+ tags: "warning",
30
+ });
31
+ }
32
+ else if (event.type === "permission.asked") {
33
+ const props = event.properties;
34
+ const permission = props.permission || "";
35
+ const patterns = props.patterns?.join(", ") || "";
36
+ const detail = permission
37
+ ? `\nPermission: ${permission}${patterns ? ` (${patterns})` : ""}`
38
+ : "";
39
+ await sendNotification(config, {
40
+ title: `${project} - Permission Requested`,
41
+ message: `Event: permission.asked\nProject: ${project}\nTime: ${new Date().toISOString()}${detail}`,
42
+ tags: "lock",
43
+ });
44
+ }
45
+ },
46
+ "permission.ask": async (permission) => {
47
+ await sendNotification(config, {
48
+ title: `${project} - Permission Requested`,
49
+ message: `Event: permission.asked\nProject: ${project}\nTime: ${new Date().toISOString()}\nPermission: ${permission.title}`,
50
+ tags: "lock",
51
+ });
52
+ },
53
+ };
54
+ };
55
+ export default plugin;
@@ -0,0 +1,7 @@
1
+ import type { NtfyConfig } from "./config.js";
2
+ export interface NotificationPayload {
3
+ title: string;
4
+ message: string;
5
+ tags: string;
6
+ }
7
+ export declare function sendNotification(config: NtfyConfig, payload: NotificationPayload): Promise<void>;
package/dist/notify.js ADDED
@@ -0,0 +1,19 @@
1
+ export async function sendNotification(config, payload) {
2
+ const url = `${config.server}/${config.topic}`;
3
+ const headers = {
4
+ Title: payload.title,
5
+ Priority: config.priority,
6
+ Tags: payload.tags,
7
+ };
8
+ if (config.token) {
9
+ headers.Authorization = `Bearer ${config.token}`;
10
+ }
11
+ const response = await fetch(url, {
12
+ method: "POST",
13
+ headers,
14
+ body: payload.message,
15
+ });
16
+ if (!response.ok) {
17
+ throw new Error(`ntfy request failed: ${response.status} ${response.statusText}`);
18
+ }
19
+ }
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "opencode-ntfy.sh",
3
+ "version": "0.1.0",
4
+ "description": "OpenCode plugin that sends push notifications via ntfy.sh",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.js",
11
+ "types": "./dist/index.d.ts"
12
+ }
13
+ },
14
+ "scripts": {
15
+ "build": "tsc",
16
+ "test": "vitest run",
17
+ "test:watch": "vitest"
18
+ },
19
+ "devDependencies": {
20
+ "@opencode-ai/plugin": "^1.1.63",
21
+ "@types/node": "^25.2.3",
22
+ "msw": "^2.12.10",
23
+ "typescript": "^5.7.0",
24
+ "vitest": "^3.0.0",
25
+ "yaml": "^2.8.2"
26
+ },
27
+ "files": [
28
+ "dist"
29
+ ],
30
+ "license": "MIT"
31
+ }