opencode-discord-notify 0.1.0 → 0.1.1

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-JP.md CHANGED
@@ -20,24 +20,6 @@ OpenCode のイベントを Discord Webhook に通知するプラグインです
20
20
  Discord の Forum チャンネル webhook を前提に、セッション開始時(または最初の通知タイミング)にスレッド(投稿)を作成して、その後の更新を同スレッドに流します。
21
21
  通常のテキストチャンネル webhook でも利用できます(その場合はスレッドが作れないため、チャンネルへ直投稿します)。
22
22
 
23
- ## 使い方
24
-
25
- `opencode.json` / `opencode.jsonc` にプラグインを追加します。
26
-
27
- ```jsonc
28
- {
29
- "plugin": ["opencode-discord-notify@latest"],
30
- }
31
- ```
32
-
33
- バージョン固定したい場合:
34
-
35
- ```jsonc
36
- {
37
- "plugin": ["opencode-discord-notify@0.1.0"],
38
- }
39
- ```
40
-
41
23
  ## できること
42
24
 
43
25
  - `session.created`: セッション開始 → 開始通知をキュー(スレッド作成/送信は後続イベントで条件が揃ったタイミングで実行されることがある)
@@ -50,29 +32,24 @@ Discord の Forum チャンネル webhook を前提に、セッション開始
50
32
 
51
33
  ## セットアップ
52
34
 
53
- ### 1) 依存のインストール
54
-
55
- グローバルにインストールします。
56
-
57
- - `npm i -g @opencode-ai/plugin`
58
-
59
- ### 2) プラグイン配置
60
-
61
- プロジェクト直下に以下のファイルを置きます。
35
+ ### 1) プラグイン配置
62
36
 
63
- - `.opencode/plugin/discord-notification.ts`
37
+ `opencode.json` / `opencode.jsonc` にプラグインを追加します。
64
38
 
65
- (グローバルに使いたい場合は `~/.config/opencode/plugin/` 配下でもOKです)
39
+ OpenCode を再起動してください。
66
40
 
67
- > [!WARNING]
68
- > グローバル(`~/.config/opencode/plugin/`)とプロジェクト(`.opencode/plugin/`)の両方に配置すると、プラグインが二重に読み込まれて通知が重複します。どちらか一方にしてください。
41
+ ```jsonc
42
+ {
43
+ "plugin": ["opencode-discord-notify@latest"],
44
+ }
45
+ ```
69
46
 
70
- ### 3) Discord 側の準備
47
+ ### 2) Discord 側の準備
71
48
 
72
49
  - Discord の Forum チャンネルで Webhook を作成してください。
73
50
  - テキストチャンネル webhook でも動きますが、スレッド作成(`thread_name`)は Forum 向けの挙動が前提です。
74
51
 
75
- ### 4) 環境変数
52
+ ### 3) 環境変数
76
53
 
77
54
  必須:
78
55
 
@@ -118,7 +95,7 @@ Discord の Forum チャンネル webhook を前提に、セッション開始
118
95
 
119
96
  - 依存のインストール: `npm i`
120
97
  - フォーマット: `npx prettier . --write`
121
- - プラグイン本体: `.opencode/plugin/discord-notification.ts`
98
+ - プラグイン本体: `src/index.ts`
122
99
 
123
100
  ## 今後の展望(予定)
124
101
 
package/README.md CHANGED
@@ -21,24 +21,6 @@ A plugin that posts OpenCode events to a Discord webhook.
21
21
  It is optimized for Discord Forum channel webhooks: it creates one thread per session (via `thread_name`) and posts subsequent updates to the same thread.
22
22
  It also works with regular text channel webhooks (in that case, it falls back to posting directly to the channel because threads cannot be created).
23
23
 
24
- ## Usage
25
-
26
- Add this plugin to your `opencode.json` / `opencode.jsonc`:
27
-
28
- ```jsonc
29
- {
30
- "plugin": ["opencode-discord-notify@latest"],
31
- }
32
- ```
33
-
34
- If you want to pin a version:
35
-
36
- ```jsonc
37
- {
38
- "plugin": ["opencode-discord-notify@0.1.0"],
39
- }
40
- ```
41
-
42
24
  ## What it does
43
25
 
44
26
  - `session.created`: session started → queues a start notification (thread creation / sending may happen later when required info is available)
@@ -46,37 +28,30 @@ If you want to pin a version:
46
28
  - `session.idle`: session finished → posts a notification
47
29
  - `session.error`: error → posts a notification (skips if `sessionID` is not present)
48
30
  - `todo.updated`: todo updates → posts a checklist (keeps received order; excludes `cancelled`)
49
- - `message.updated`: does not notify (tracked for role inference; may emit previously-held text later)
50
- - `message.part.updated`:
51
- - `text`: user text is posted immediately; assistant text is posted only when finalized (`time.end`)
31
+ - `message.updated`: does not notify (tracked for role inference; may emit previously-held `text` later)
32
+ - `message.part.updated`: message content/tool results updates →
33
+ - `text`: user text is posted immediately; assistant text is posted only when finalized (when `time.end` exists)
52
34
  - `tool`: not posted
53
35
  - `reasoning`: not posted
54
36
 
55
37
  ## Setup
56
38
 
57
- ### 1) Install dependencies
58
-
59
- Install the OpenCode plugin runner globally.
60
-
61
- - `npm i -g @opencode-ai/plugin`
62
-
63
- ### 2) Place the plugin file
39
+ ### 1) Add the plugin
64
40
 
65
- Put the plugin file in your project:
41
+ Add this plugin to your `opencode.json` / `opencode.jsonc` and restart OpenCode.
66
42
 
67
- - `.opencode/plugin/discord-notification.ts`
68
-
69
- (If you want to use it globally, place it under `~/.config/opencode/plugin/` instead.)
70
-
71
- > [!WARNING]
72
- > If you place the plugin in both the global directory (`~/.config/opencode/plugin/`) and the project directory (`.opencode/plugin/`), it may be loaded twice and send duplicate notifications. Choose either global or project placement, not both.
43
+ ```jsonc
44
+ {
45
+ "plugin": ["opencode-discord-notify@latest"],
46
+ }
47
+ ```
73
48
 
74
- ### 3) Create a Discord webhook
49
+ ### 2) Create a Discord webhook
75
50
 
76
51
  - Recommended: create a webhook in a Discord Forum channel.
77
52
  - A webhook in a regular text channel also works, but thread creation using `thread_name` is a Forum-oriented behavior.
78
53
 
79
- ### 4) Environment variables
54
+ ### 3) Environment variables
80
55
 
81
56
  Required:
82
57
 
@@ -88,7 +63,7 @@ Optional:
88
63
  - `DISCORD_WEBHOOK_AVATAR_URL`: avatar URL for webhook posts
89
64
  - `DISCORD_WEBHOOK_COMPLETE_MENTION`: mention to put in `session.idle` / `session.error` messages (only `@everyone` or `@here` supported; Forum webhooks may not actually ping due to Discord behavior)
90
65
  - `DISCORD_WEBHOOK_PERMISSION_MENTION`: mention to put in `permission.updated` messages (no fallback to `DISCORD_WEBHOOK_COMPLETE_MENTION`; only `@everyone` or `@here` supported; Forum webhooks may not actually ping due to Discord behavior)
91
- - `DISCORD_WEBHOOK_EXCLUDE_INPUT_CONTEXT`: when set to `1`, exclude "input context" (user text parts that start with `<file>`) from notifications (default: `1`; set to `0` to disable)
66
+ - `DISCORD_WEBHOOK_EXCLUDE_INPUT_CONTEXT`: when set to `1`, exclude "input context" (user `text` parts that start with `<file>`) from notifications (default: `1`; set to `0` to disable)
92
67
 
93
68
  ## Notes / behavior
94
69
 
@@ -102,9 +77,9 @@ Optional:
102
77
  - If thread creation fails (e.g. on non-Forum webhooks), it falls back to posting directly to the channel.
103
78
  - `permission.updated` / `session.idle` may be queued until the thread name becomes available.
104
79
  - `session.error` is skipped when `sessionID` is missing in the upstream payload.
105
- - `DISCORD_WEBHOOK_COMPLETE_MENTION=@everyone` (or `@here`) is included as message content, but Forum webhooks may not actually ping.
106
- - `DISCORD_WEBHOOK_PERMISSION_MENTION=@everyone` (or `@here`) is included as message content for `permission.updated`, but Forum webhooks may not actually ping.
107
- - `todo.updated` posts a checklist in the order received (`in_progress` = `[▶]`, `completed` = `[✓]`, `cancelled` excluded). Long lists may be truncated to fit embed constraints.
80
+ - `DISCORD_WEBHOOK_COMPLETE_MENTION=@everyone` (or `@here`) is included as message content, but Forum webhooks may not actually ping (it may just show as plain text).
81
+ - `DISCORD_WEBHOOK_PERMISSION_MENTION=@everyone` (or `@here`) is included as message content for `permission.updated`, but Forum webhooks may not actually ping (it may just show as plain text).
82
+ - `todo.updated` posts a checklist in the order received (`in_progress` = `[▶]`, `completed` = `[✓]`, `cancelled` excluded). Long lists may be truncated to fit embed constraints (if empty: `(no todos)`; if truncated: adds `...and more`).
108
83
  - `message.updated` is not posted (tracked for role inference; may post a previously-held text part later).
109
84
  - `message.part.updated` policy:
110
85
  - `text`: user is posted immediately; assistant is posted only when finalized (when `part.time.end` exists)
@@ -115,13 +90,22 @@ Optional:
115
90
 
116
91
  1. Start OpenCode → a new thread appears in the Forum channel on the first notification timing
117
92
  2. Trigger a permission request → a notification is posted to the same thread (if the thread isn't created yet, it may be created later)
118
- 3. Finish the session → `session.idle` is posted
119
- 4. Trigger an error → `session.error` is posted (skipped if no `sessionID`)
93
+ 3. Finish the session → `session.idle` is posted (if you set `DISCORD_WEBHOOK_COMPLETE_MENTION`, it may not actually ping in Forum webhooks)
94
+ 4. Trigger an error → `session.error` is posted (skipped if no `sessionID`; if you set `DISCORD_WEBHOOK_COMPLETE_MENTION`, it may not actually ping in Forum webhooks)
120
95
 
121
96
  ## Development
122
97
 
123
98
  - Install deps: `npm i`
124
99
  - Format: `npx prettier . --write`
125
- - Plugin source: `.opencode/plugin/discord-notification.ts`
100
+ - Plugin source: `src/index.ts`
101
+
102
+ ## Roadmap (planned)
103
+
104
+ - Publish as an npm package (to make install/update easier)
105
+ - Support multiple webhooks / multiple channels (route by use case)
106
+ - Allow customizing notifications (events, message templates, mention policy)
107
+ - Consider reading a config file (e.g. `opencode-discord-notify.config.json`) and resolving values from env vars as needed
108
+ - Improve Discord limitations handling (rate-limit retry, split posts, better truncation rules)
109
+ - Improve CI (automate lint/format; add basic tests)
126
110
 
127
111
  PRs and issues are welcome.
package/dist/index.d.ts CHANGED
@@ -2,6 +2,4 @@ import { Plugin } from '@opencode-ai/plugin';
2
2
 
3
3
  declare const plugin: Plugin;
4
4
 
5
- declare const DiscordNotificationPlugin: Plugin;
6
-
7
- export { DiscordNotificationPlugin, plugin as default };
5
+ export { plugin as default };
package/dist/index.js CHANGED
@@ -78,7 +78,16 @@ async function postDiscordWebhook(input) {
78
78
  channel_id: channelId
79
79
  };
80
80
  }
81
+ var GLOBAL_GUARD_KEY = "__opencode_discord_notify_registered__";
81
82
  var plugin = async () => {
83
+ const globalWithGuard = globalThis;
84
+ if (globalWithGuard[GLOBAL_GUARD_KEY]) {
85
+ return {
86
+ event: async () => {
87
+ }
88
+ };
89
+ }
90
+ globalWithGuard[GLOBAL_GUARD_KEY] = true;
82
91
  const webhookUrl = getEnv("DISCORD_WEBHOOK_URL");
83
92
  const username = getEnv("DISCORD_WEBHOOK_USERNAME");
84
93
  const avatarUrl = getEnv("DISCORD_WEBHOOK_AVATAR_URL");
@@ -532,8 +541,6 @@ var plugin = async () => {
532
541
  };
533
542
  };
534
543
  var index_default = plugin;
535
- var DiscordNotificationPlugin = plugin;
536
544
  export {
537
- DiscordNotificationPlugin,
538
545
  index_default as default
539
546
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-discord-notify",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "A plugin that posts OpenCode events to a Discord webhook.",
5
5
  "license": "MIT",
6
6
  "type": "module",