@mohak34/opencode-notifier 0.1.12 → 0.1.13

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.
Files changed (3) hide show
  1. package/README.md +6 -4
  2. package/dist/index.js +29 -17
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -91,6 +91,7 @@ To customize the plugin, create `~/.config/opencode/opencode-notifier.json`:
91
91
  "sound": true,
92
92
  "notification": true,
93
93
  "timeout": 5,
94
+ "showProjectName": true,
94
95
  "events": {
95
96
  "permission": { "sound": true, "notification": true },
96
97
  "complete": { "sound": true, "notification": true },
@@ -98,10 +99,10 @@ To customize the plugin, create `~/.config/opencode/opencode-notifier.json`:
98
99
  "question": { "sound": true, "notification": true }
99
100
  },
100
101
  "messages": {
101
- "permission": "OpenCode needs permission",
102
- "complete": "OpenCode has finished",
103
- "error": "OpenCode encountered an error",
104
- "question": "OpenCode has a question"
102
+ "permission": "Session needs permission",
103
+ "complete": "Session has finished",
104
+ "error": "Session encountered an error",
105
+ "question": "Session has a question"
105
106
  },
106
107
  "sounds": {
107
108
  "permission": "/path/to/custom/sound.wav",
@@ -119,6 +120,7 @@ To customize the plugin, create `~/.config/opencode/opencode-notifier.json`:
119
120
  | `sound` | boolean | `true` | Global toggle for all sounds |
120
121
  | `notification` | boolean | `true` | Global toggle for all notifications |
121
122
  | `timeout` | number | `5` | Notification duration in seconds (Linux only) |
123
+ | `showProjectName` | boolean | `true` | Show project folder name in notification title |
122
124
 
123
125
  ### Events
124
126
 
package/dist/index.js CHANGED
@@ -3726,6 +3726,9 @@ var require_node_notifier = __commonJS((exports, module) => {
3726
3726
  module.exports.Growl = Growl;
3727
3727
  });
3728
3728
 
3729
+ // src/index.ts
3730
+ import { basename } from "path";
3731
+
3729
3732
  // src/config.ts
3730
3733
  import { readFileSync, existsSync } from "fs";
3731
3734
  import { join } from "path";
@@ -3738,6 +3741,7 @@ var DEFAULT_CONFIG = {
3738
3741
  sound: true,
3739
3742
  notification: true,
3740
3743
  timeout: 5,
3744
+ showProjectName: true,
3741
3745
  events: {
3742
3746
  permission: { ...DEFAULT_EVENT_CONFIG },
3743
3747
  complete: { ...DEFAULT_EVENT_CONFIG },
@@ -3745,10 +3749,10 @@ var DEFAULT_CONFIG = {
3745
3749
  question: { ...DEFAULT_EVENT_CONFIG }
3746
3750
  },
3747
3751
  messages: {
3748
- permission: "OpenCode needs permission",
3749
- complete: "OpenCode has finished",
3750
- error: "OpenCode encountered an error",
3751
- question: "OpenCode has a question"
3752
+ permission: "Session needs permission",
3753
+ complete: "Session has finished",
3754
+ error: "Session encountered an error",
3755
+ question: "Session has a question"
3752
3756
  },
3753
3757
  sounds: {
3754
3758
  permission: null,
@@ -3793,11 +3797,12 @@ function loadConfig() {
3793
3797
  sound: globalSound,
3794
3798
  notification: globalNotification,
3795
3799
  timeout: typeof userConfig.timeout === "number" && userConfig.timeout > 0 ? userConfig.timeout : DEFAULT_CONFIG.timeout,
3800
+ showProjectName: userConfig.showProjectName ?? DEFAULT_CONFIG.showProjectName,
3796
3801
  events: {
3797
3802
  permission: parseEventConfig(userConfig.events?.permission ?? userConfig.permission, defaultWithGlobal),
3798
3803
  complete: parseEventConfig(userConfig.events?.complete ?? userConfig.complete, defaultWithGlobal),
3799
3804
  error: parseEventConfig(userConfig.events?.error ?? userConfig.error, defaultWithGlobal),
3800
- question: parseEventConfig(userConfig.events?.question, defaultWithGlobal)
3805
+ question: parseEventConfig(userConfig.events?.question ?? userConfig.question, defaultWithGlobal)
3801
3806
  },
3802
3807
  messages: {
3803
3808
  permission: userConfig.messages?.permission ?? DEFAULT_CONFIG.messages.permission,
@@ -3833,7 +3838,6 @@ function getSoundPath(config, event) {
3833
3838
  var import_node_notifier = __toESM(require_node_notifier(), 1);
3834
3839
  import os from "os";
3835
3840
  import { exec } from "child_process";
3836
- var NOTIFICATION_TITLE = "OpenCode";
3837
3841
  var DEBOUNCE_MS = 1000;
3838
3842
  var platform = os.type();
3839
3843
  var platformNotifier;
@@ -3847,7 +3851,7 @@ if (platform === "Linux" || platform.match(/BSD$/)) {
3847
3851
  platformNotifier = import_node_notifier.default;
3848
3852
  }
3849
3853
  var lastNotificationTime = {};
3850
- async function sendNotification(message, timeout) {
3854
+ async function sendNotification(title, message, timeout) {
3851
3855
  const now = Date.now();
3852
3856
  if (lastNotificationTime[message] && now - lastNotificationTime[message] < DEBOUNCE_MS) {
3853
3857
  return;
@@ -3856,7 +3860,7 @@ async function sendNotification(message, timeout) {
3856
3860
  if (platform === "Darwin") {
3857
3861
  return new Promise((resolve) => {
3858
3862
  const escapedMessage = message.replace(/"/g, "\\\"");
3859
- const escapedTitle = NOTIFICATION_TITLE.replace(/"/g, "\\\"");
3863
+ const escapedTitle = title.replace(/"/g, "\\\"");
3860
3864
  exec(`osascript -e 'display notification "${escapedMessage}" with title "${escapedTitle}"'`, () => {
3861
3865
  resolve();
3862
3866
  });
@@ -3864,7 +3868,7 @@ async function sendNotification(message, timeout) {
3864
3868
  }
3865
3869
  return new Promise((resolve) => {
3866
3870
  const notificationOptions = {
3867
- title: NOTIFICATION_TITLE,
3871
+ title,
3868
3872
  message,
3869
3873
  timeout,
3870
3874
  icon: undefined
@@ -3977,11 +3981,18 @@ async function playSound(event, customPath) {
3977
3981
  }
3978
3982
 
3979
3983
  // src/index.ts
3980
- async function handleEvent(config, eventType) {
3984
+ function getNotificationTitle(config, projectName) {
3985
+ if (config.showProjectName && projectName) {
3986
+ return `OpenCode (${projectName})`;
3987
+ }
3988
+ return "OpenCode";
3989
+ }
3990
+ async function handleEvent(config, eventType, projectName) {
3981
3991
  const promises = [];
3982
3992
  if (isEventNotificationEnabled(config, eventType)) {
3993
+ const title = getNotificationTitle(config, projectName);
3983
3994
  const message = getMessage(config, eventType);
3984
- promises.push(sendNotification(message, config.timeout));
3995
+ promises.push(sendNotification(title, message, config.timeout));
3985
3996
  }
3986
3997
  if (isEventSoundEnabled(config, eventType)) {
3987
3998
  const customSoundPath = getSoundPath(config, eventType);
@@ -3991,27 +4002,28 @@ async function handleEvent(config, eventType) {
3991
4002
  }
3992
4003
  var NotifierPlugin = async ({ project, client, $, directory, worktree }) => {
3993
4004
  const config = loadConfig();
4005
+ const projectName = directory ? basename(directory) : null;
3994
4006
  return {
3995
4007
  event: async ({ event }) => {
3996
4008
  if (event.type === "permission.updated") {
3997
- await handleEvent(config, "permission");
4009
+ await handleEvent(config, "permission", projectName);
3998
4010
  }
3999
4011
  if (event.type === "permission.asked") {
4000
- await handleEvent(config, "permission");
4012
+ await handleEvent(config, "permission", projectName);
4001
4013
  }
4002
4014
  if (event.type === "session.idle") {
4003
- await handleEvent(config, "complete");
4015
+ await handleEvent(config, "complete", projectName);
4004
4016
  }
4005
4017
  if (event.type === "session.error") {
4006
- await handleEvent(config, "error");
4018
+ await handleEvent(config, "error", projectName);
4007
4019
  }
4008
4020
  },
4009
4021
  "permission.ask": async () => {
4010
- await handleEvent(config, "permission");
4022
+ await handleEvent(config, "permission", projectName);
4011
4023
  },
4012
4024
  "tool.execute.before": async (input, output) => {
4013
4025
  if (input.tool === "question") {
4014
- await handleEvent(config, "question");
4026
+ await handleEvent(config, "question", projectName);
4015
4027
  }
4016
4028
  }
4017
4029
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mohak34/opencode-notifier",
3
- "version": "0.1.12",
3
+ "version": "0.1.13",
4
4
  "description": "OpenCode plugin that sends system notifications and plays sounds when permission is needed, generation completes, or errors occur",
5
5
  "author": "mohak34",
6
6
  "license": "MIT",