@mohak34/opencode-notifier 0.1.30-beta.2 → 0.1.30-beta.3

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 (2) hide show
  1. package/dist/index.js +30 -14
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -3728,6 +3728,7 @@ var require_node_notifier = __commonJS((exports, module) => {
3728
3728
 
3729
3729
  // src/index.ts
3730
3730
  import { basename } from "path";
3731
+ import { readFileSync as readFileSync3, writeFileSync as writeFileSync2 } from "fs";
3731
3732
 
3732
3733
  // src/config.ts
3733
3734
  import { readFileSync, existsSync } from "fs";
@@ -3798,6 +3799,10 @@ function getConfigPath() {
3798
3799
  }
3799
3800
  return join(homedir(), ".config", "opencode", "opencode-notifier.json");
3800
3801
  }
3802
+ function getStatePath() {
3803
+ const configPath = getConfigPath();
3804
+ return join(dirname(configPath), "opencode-notifier-state.json");
3805
+ }
3801
3806
  function parseEventConfig(userEvent, defaultConfig) {
3802
3807
  if (userEvent === undefined) {
3803
3808
  return defaultConfig;
@@ -4466,7 +4471,30 @@ var pendingIdleTimers = new Map;
4466
4471
  var sessionIdleSequence = new Map;
4467
4472
  var sessionErrorSuppressionAt = new Map;
4468
4473
  var sessionLastBusyAt = new Map;
4469
- var sessionTurnCount = new Map;
4474
+ var globalTurnCount = null;
4475
+ function loadTurnCount() {
4476
+ try {
4477
+ const content = readFileSync3(getStatePath(), "utf-8");
4478
+ const state = JSON.parse(content);
4479
+ if (typeof state.turn === "number" && Number.isFinite(state.turn) && state.turn >= 0) {
4480
+ return state.turn;
4481
+ }
4482
+ } catch {}
4483
+ return 0;
4484
+ }
4485
+ function saveTurnCount(count) {
4486
+ try {
4487
+ writeFileSync2(getStatePath(), JSON.stringify({ turn: count }));
4488
+ } catch {}
4489
+ }
4490
+ function incrementTurnCount() {
4491
+ if (globalTurnCount === null) {
4492
+ globalTurnCount = loadTurnCount();
4493
+ }
4494
+ globalTurnCount++;
4495
+ saveTurnCount(globalTurnCount);
4496
+ return globalTurnCount;
4497
+ }
4470
4498
  setInterval(() => {
4471
4499
  const cutoff = Date.now() - 5 * 60 * 1000;
4472
4500
  for (const [sessionID] of sessionIdleSequence) {
@@ -4484,11 +4512,6 @@ setInterval(() => {
4484
4512
  sessionLastBusyAt.delete(sessionID);
4485
4513
  }
4486
4514
  }
4487
- for (const [sessionID] of sessionTurnCount) {
4488
- if (!pendingIdleTimers.has(sessionID) && !sessionLastBusyAt.has(sessionID)) {
4489
- sessionTurnCount.delete(sessionID);
4490
- }
4491
- }
4492
4515
  }, 5 * 60 * 1000);
4493
4516
  function getNotificationTitle(config, projectName) {
4494
4517
  if (config.showProjectName && projectName) {
@@ -4503,20 +4526,13 @@ function formatTimestamp() {
4503
4526
  const s = String(now.getSeconds()).padStart(2, "0");
4504
4527
  return `${h}:${m}:${s}`;
4505
4528
  }
4506
- function incrementSessionTurn(sessionID) {
4507
- if (!sessionID)
4508
- return 1;
4509
- const next = (sessionTurnCount.get(sessionID) ?? 0) + 1;
4510
- sessionTurnCount.set(sessionID, next);
4511
- return next;
4512
- }
4513
4529
  async function handleEvent(config, eventType, projectName, elapsedSeconds, sessionTitle, sessionID) {
4514
4530
  if (config.suppressWhenFocused && isTerminalFocused()) {
4515
4531
  return;
4516
4532
  }
4517
4533
  const promises = [];
4518
4534
  const timestamp = formatTimestamp();
4519
- const turn = incrementSessionTurn(sessionID ?? null);
4535
+ const turn = incrementTurnCount();
4520
4536
  const rawMessage = getMessage(config, eventType);
4521
4537
  const message = interpolateMessage(rawMessage, {
4522
4538
  sessionTitle: config.showSessionTitle ? sessionTitle : null,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mohak34/opencode-notifier",
3
- "version": "0.1.30-beta.2",
3
+ "version": "0.1.30-beta.3",
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",