opencode-bark-notify 0.0.0-stage → 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 +21 -0
- package/README.md +86 -2
- package/index.ts +116 -0
- package/package.json +35 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Rohit
|
|
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
CHANGED
|
@@ -1,3 +1,87 @@
|
|
|
1
|
-
#
|
|
1
|
+
# opencode-bark-notify
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Bark push notifications for [OpenCode](https://opencode.ai) sessions: one push when a task finishes, fails, or needs approval, with the session title, a deep link back to it, and no duplicates.
|
|
4
|
+
|
|
5
|
+
## Requirements
|
|
6
|
+
|
|
7
|
+
- [Bark](https://github.com/Finb/Bark) on your iPhone or iPad
|
|
8
|
+
- Your Bark device key from the app
|
|
9
|
+
- OpenCode V2
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
opencode plugin add opencode-bark-notify
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Then configure it in `opencode.json(c)`:
|
|
18
|
+
|
|
19
|
+
```jsonc
|
|
20
|
+
{
|
|
21
|
+
"$schema": "https://opencode.ai/config.json",
|
|
22
|
+
"plugins": [
|
|
23
|
+
{
|
|
24
|
+
"package": "opencode-bark-notify",
|
|
25
|
+
"options": {
|
|
26
|
+
"barkKey": "YOUR_DEVICE_KEY",
|
|
27
|
+
"uiUrl": "https://opencode.example.com",
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Options
|
|
35
|
+
|
|
36
|
+
| Option | Required | Default | Description |
|
|
37
|
+
| --------- | -------- | ------------------------------------------ | ------------------------------------------------------------------------ |
|
|
38
|
+
| `barkKey` | yes | — | Bark device key. Without it the plugin logs a warning and sends nothing. |
|
|
39
|
+
| `barkUrl` | no | `https://api.day.app` | Base URL of a Bark server. Trailing slashes are stripped. |
|
|
40
|
+
| `group` | no | `opencode` | Bark notification group. |
|
|
41
|
+
| `uiUrl` | no | — | Base URL of the OpenCode web UI, used to build per-session deep links. |
|
|
42
|
+
| `icon` | no | `https://opencode.ai/favicon-96x96-v3.png` | Icon URL shown by Bark. Set to `""` to send no icon. |
|
|
43
|
+
| `sound` | no | `tiptoes` | Bark/iOS sound name. Set to `""` to send no sound. |
|
|
44
|
+
|
|
45
|
+
Leave `uiUrl` unset to omit the tap action entirely.
|
|
46
|
+
|
|
47
|
+
## Events
|
|
48
|
+
|
|
49
|
+
| Event | Title | Subtitle | Body |
|
|
50
|
+
| ----------------------------- | ------------- | ------------- | ----------------------------- |
|
|
51
|
+
| `session.execution.succeeded` | session title | Task finished | `A session is ready.` |
|
|
52
|
+
| `session.execution.failed` | session title | Task failed | `A session execution failed.` |
|
|
53
|
+
| `permission.asked` | session title | Question | `action: resource` |
|
|
54
|
+
|
|
55
|
+
The title falls back to `OpenCode` when the session has no title or the lookup fails.
|
|
56
|
+
|
|
57
|
+
Requests go to `POST {barkUrl}/push` with an 8 second timeout.
|
|
58
|
+
|
|
59
|
+
## Duplicate prevention
|
|
60
|
+
|
|
61
|
+
OpenCode loads plugins once per project location while the event stream is server-wide, so a naive subscriber sends one push per open project. This plugin avoids that by:
|
|
62
|
+
|
|
63
|
+
- keeping only events whose session belongs to the plugin instance's own directory;
|
|
64
|
+
- skipping sessions with a `parentID` for completion events, so subagents do not each produce a push (`permission.asked` is exempt);
|
|
65
|
+
- relying on a single explicit config entry, never auto-discovery as well.
|
|
66
|
+
|
|
67
|
+
## Deep links
|
|
68
|
+
|
|
69
|
+
Tapping a notification opens the session in the OpenCode web UI:
|
|
70
|
+
|
|
71
|
+
```text
|
|
72
|
+
https://opencode.example.com/server/<serverKey>/session/<sessionID>
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
`serverKey` is the base64url encoding of the `uiUrl` origin. Pairing the same OpenCode server through a different URL yields a different key, so the deep link only resolves when your client is paired to the same origin as `uiUrl`.
|
|
76
|
+
|
|
77
|
+
## Logging
|
|
78
|
+
|
|
79
|
+
Each send logs one line:
|
|
80
|
+
|
|
81
|
+
```text
|
|
82
|
+
[opencode-bark] sending ses_abc123 from /home/me/projects/app
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## License
|
|
86
|
+
|
|
87
|
+
MIT
|
package/index.ts
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { Plugin } from "@opencode/plugin"
|
|
2
|
+
|
|
3
|
+
type Options = {
|
|
4
|
+
barkKey?: string
|
|
5
|
+
barkUrl?: string
|
|
6
|
+
group?: string
|
|
7
|
+
uiUrl?: string
|
|
8
|
+
icon?: string
|
|
9
|
+
sound?: string
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const encodeKey = (value: string) => {
|
|
13
|
+
const bytes = new TextEncoder().encode(value)
|
|
14
|
+
const binary = Array.from(bytes, (byte) => String.fromCharCode(byte)).join("")
|
|
15
|
+
return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "")
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export default Plugin.define({
|
|
19
|
+
id: "bark-notify",
|
|
20
|
+
async setup(ctx) {
|
|
21
|
+
const options = ctx.options as Options
|
|
22
|
+
const barkKey = options.barkKey
|
|
23
|
+
const barkUrl = (options.barkUrl || "https://api.day.app").replace(/\/+$/, "")
|
|
24
|
+
const group = options.group || "opencode"
|
|
25
|
+
const uiUrl = options.uiUrl
|
|
26
|
+
const icon = options.icon ?? "https://opencode.ai/favicon-96x96-v3.png"
|
|
27
|
+
const sound = options.sound ?? "tiptoes"
|
|
28
|
+
|
|
29
|
+
let uiOrigin: string | undefined
|
|
30
|
+
let serverKey: string | undefined
|
|
31
|
+
if (uiUrl) {
|
|
32
|
+
try {
|
|
33
|
+
uiOrigin = new URL(uiUrl).origin
|
|
34
|
+
serverKey = encodeKey(uiOrigin)
|
|
35
|
+
} catch {
|
|
36
|
+
console.warn(`[opencode-bark] invalid uiUrl: ${uiUrl}`)
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const sessionUrl = (sessionID: string) => {
|
|
41
|
+
if (!uiOrigin || !serverKey) return uiUrl
|
|
42
|
+
return `${uiOrigin}/server/${serverKey}/session/${sessionID}`
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const send = async (title: string, subtitle: string, body: string, sessionID: string) => {
|
|
46
|
+
if (!barkKey) {
|
|
47
|
+
console.warn("[opencode-bark] barkKey is not configured; skipping notification")
|
|
48
|
+
return
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const payload: Record<string, string> = {
|
|
52
|
+
device_key: barkKey,
|
|
53
|
+
title,
|
|
54
|
+
subtitle,
|
|
55
|
+
body,
|
|
56
|
+
group,
|
|
57
|
+
}
|
|
58
|
+
if (icon) payload.icon = icon
|
|
59
|
+
if (sound) payload.sound = sound
|
|
60
|
+
const url = sessionUrl(sessionID)
|
|
61
|
+
if (url) payload.url = url
|
|
62
|
+
console.log(`[opencode-bark] sending ${sessionID} from ${ctx.location.directory}`)
|
|
63
|
+
|
|
64
|
+
const response = await fetch(`${barkUrl}/push`, {
|
|
65
|
+
method: "POST",
|
|
66
|
+
headers: { "Content-Type": "application/json; charset=utf-8" },
|
|
67
|
+
body: JSON.stringify(payload),
|
|
68
|
+
signal: AbortSignal.timeout(8000),
|
|
69
|
+
})
|
|
70
|
+
if (!response.ok) console.warn(`[opencode-bark] Bark returned HTTP ${response.status}`)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const sessionFor = async (sessionID: string) => {
|
|
74
|
+
try {
|
|
75
|
+
return await ctx.session.get({ sessionID })
|
|
76
|
+
} catch {
|
|
77
|
+
return undefined
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const controller = new AbortController()
|
|
82
|
+
void (async () => {
|
|
83
|
+
try {
|
|
84
|
+
for await (const event of ctx.event.subscribe({
|
|
85
|
+
types: ["session.execution.succeeded", "session.execution.failed", "permission.asked"],
|
|
86
|
+
signal: controller.signal,
|
|
87
|
+
})) {
|
|
88
|
+
try {
|
|
89
|
+
if (event.location && event.location.directory !== ctx.location.directory) continue
|
|
90
|
+
|
|
91
|
+
const session = await sessionFor(event.data.sessionID)
|
|
92
|
+
if (!session) continue
|
|
93
|
+
if (session.location.directory !== ctx.location.directory) continue
|
|
94
|
+
if (session.parentID && event.type !== "permission.asked") continue
|
|
95
|
+
const title = session.title || "OpenCode"
|
|
96
|
+
|
|
97
|
+
if (event.type === "session.execution.succeeded") {
|
|
98
|
+
await send(title, "Task finished", "A session is ready.", event.data.sessionID)
|
|
99
|
+
} else if (event.type === "session.execution.failed") {
|
|
100
|
+
await send(title, "Task failed", "A session execution failed.", event.data.sessionID)
|
|
101
|
+
} else if (event.type === "permission.asked") {
|
|
102
|
+
const body = [event.data.action, ...event.data.resources].filter(Boolean).join(": ")
|
|
103
|
+
await send(title, "Question", body || "Permission requested", event.data.sessionID)
|
|
104
|
+
}
|
|
105
|
+
} catch (error) {
|
|
106
|
+
console.warn("[opencode-bark] notification failed", error)
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
} catch (error) {
|
|
110
|
+
if (!controller.signal.aborted) console.warn("[opencode-bark] event subscription failed", error)
|
|
111
|
+
}
|
|
112
|
+
})()
|
|
113
|
+
|
|
114
|
+
return () => controller.abort()
|
|
115
|
+
},
|
|
116
|
+
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,37 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-bark-notify",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Bark push notifications for OpenCode sessions, with session deep links and duplicate-free delivery.",
|
|
5
|
+
"homepage": "https://github.com/rohitagre/opencode-bark-notify#readme",
|
|
6
|
+
"bugs": {
|
|
7
|
+
"url": "https://github.com/rohitagre/opencode-bark-notify/issues"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/rohitagre/opencode-bark-notify.git"
|
|
12
|
+
},
|
|
13
|
+
"type": "module",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": "./index.ts"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"index.ts",
|
|
19
|
+
"README.md"
|
|
20
|
+
],
|
|
21
|
+
"keywords": [
|
|
22
|
+
"opencode",
|
|
23
|
+
"opencode-plugin",
|
|
24
|
+
"bark",
|
|
25
|
+
"notifications",
|
|
26
|
+
"push",
|
|
27
|
+
"ios"
|
|
28
|
+
],
|
|
29
|
+
"author": "Rohit Agre",
|
|
30
|
+
"license": "MIT",
|
|
31
|
+
"publishConfig": {
|
|
32
|
+
"access": "public"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@opencode/plugin": "latest"
|
|
36
|
+
}
|
|
37
|
+
}
|