opencode-work-context 0.4.1 → 0.4.2
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.md +10 -0
- package/package.json +1 -1
- package/plugin/attention.js +12 -4
- package/plugin/tui-focus.js +18 -0
package/README.md
CHANGED
|
@@ -248,6 +248,16 @@ delivery errors are ignored so they cannot interrupt TUI startup or event
|
|
|
248
248
|
processing. Notifications are not replayed after restart, and clicking one does
|
|
249
249
|
not navigate to its session in this release.
|
|
250
250
|
|
|
251
|
+
Background includes a linked native session that is not selected and a current
|
|
252
|
+
session in an OpenCode process whose terminal has emitted a standard blur event.
|
|
253
|
+
The latter allows notifications when switching between independent OpenCode
|
|
254
|
+
processes in different terminal windows, tabs, or focus-aware multiplexer panes.
|
|
255
|
+
Focus is tracked through OpenTUI's public renderer events rather than by querying
|
|
256
|
+
the operating system or a specific terminal multiplexer. Until the terminal
|
|
257
|
+
reports focus or blur, the process is conservatively treated as focused. A
|
|
258
|
+
terminal or multiplexer that does not forward focus events retains session-only
|
|
259
|
+
background detection.
|
|
260
|
+
|
|
251
261
|
To verify an installed project manually, install the distribution package that
|
|
252
262
|
provides `notify-send` (commonly `libnotify-bin`), ensure `notify-send "Test"`
|
|
253
263
|
appears in the current desktop session, restart OpenCode, start work in a linked
|
package/package.json
CHANGED
package/plugin/attention.js
CHANGED
|
@@ -2,6 +2,7 @@ import { createHash } from "node:crypto";
|
|
|
2
2
|
import { loadConfig } from "../src/storage.js";
|
|
3
3
|
import { readWorkContextSnapshot } from "../src/work-context-snapshot.js";
|
|
4
4
|
import { createDesktopNotifier } from "./notifier.js";
|
|
5
|
+
import { createTuiFocusTracker } from "./tui-focus.js";
|
|
5
6
|
import { readTuiState, updateTuiState } from "./tui-state.js";
|
|
6
7
|
|
|
7
8
|
const ATTENTION_TTL_MS = 30 * 24 * 60 * 60 * 1000;
|
|
@@ -245,7 +246,7 @@ export const desktopNotificationsEnabled = (projectRoot) => {
|
|
|
245
246
|
try { return loadConfig(projectRoot).notifications?.desktop !== false; } catch { return false; }
|
|
246
247
|
};
|
|
247
248
|
|
|
248
|
-
export const createAttentionTuiController = ({ api, projectRoot, read = readWorkContextSnapshot, onAttention, now } = {}) => {
|
|
249
|
+
export const createAttentionTuiController = ({ api, projectRoot, read = readWorkContextSnapshot, onAttention, isFocused = () => true, now } = {}) => {
|
|
249
250
|
const persisted = readTuiState(projectRoot).attention;
|
|
250
251
|
const engine = createAttentionEngine({
|
|
251
252
|
persisted,
|
|
@@ -263,7 +264,7 @@ export const createAttentionTuiController = ({ api, projectRoot, read = readWork
|
|
|
263
264
|
linked = linkedSessionIds(result);
|
|
264
265
|
snapshot = result.data;
|
|
265
266
|
const current = currentSessionId(api);
|
|
266
|
-
if (current && linked.has(current)) engine.acknowledge(current);
|
|
267
|
+
if (isFocused() !== false && current && linked.has(current)) engine.acknowledge(current);
|
|
267
268
|
}
|
|
268
269
|
} catch {}
|
|
269
270
|
return linked;
|
|
@@ -274,7 +275,7 @@ export const createAttentionTuiController = ({ api, projectRoot, read = readWork
|
|
|
274
275
|
if (!sessionId) return { changed: false, ignored: true };
|
|
275
276
|
await refresh();
|
|
276
277
|
if (!linked.has(sessionId)) return { changed: false, unlinked: true };
|
|
277
|
-
const foreground = currentSessionId(api);
|
|
278
|
+
const foreground = isFocused() !== false ? currentSessionId(api) : undefined;
|
|
278
279
|
if (foreground === sessionId) engine.acknowledge(sessionId);
|
|
279
280
|
const result = engine.apply(event, { foreground });
|
|
280
281
|
if (result.changed) onAttention?.({
|
|
@@ -325,10 +326,16 @@ export const tui = async (api, options = {}) => {
|
|
|
325
326
|
const projectRoot = api.state?.path?.worktree || api.state?.path?.directory;
|
|
326
327
|
if (!projectRoot) return;
|
|
327
328
|
const desktopNotifier = options.desktopNotifier || createDesktopNotifier({ enabled: desktopNotificationsEnabled(projectRoot), ...options.notifierOptions });
|
|
328
|
-
|
|
329
|
+
let controller;
|
|
330
|
+
const focus = options.tuiFocus || createTuiFocusTracker({
|
|
331
|
+
renderer: api.renderer,
|
|
332
|
+
onFocus: () => { void controller?.refresh(); },
|
|
333
|
+
});
|
|
334
|
+
controller = createAttentionTuiController({
|
|
329
335
|
api,
|
|
330
336
|
projectRoot,
|
|
331
337
|
read: api.attentionSnapshotProvider || readWorkContextSnapshot,
|
|
338
|
+
isFocused: options.isTuiFocused || (() => focus.isFocused()),
|
|
332
339
|
onAttention: (change) => {
|
|
333
340
|
try { options.onAttention?.(change); } catch {}
|
|
334
341
|
const context = change.contexts?.[0];
|
|
@@ -349,6 +356,7 @@ export const tui = async (api, options = {}) => {
|
|
|
349
356
|
if (cleaned) return;
|
|
350
357
|
cleaned = true;
|
|
351
358
|
controller.dispose();
|
|
359
|
+
focus.dispose?.();
|
|
352
360
|
for (const registration of registrations) disposeRegistration(registration);
|
|
353
361
|
if (activeControllers.get(api) === cleanup) activeControllers.delete(api);
|
|
354
362
|
if (api[ACTIVE_ATTENTION_KEY] === cleanup) delete api[ACTIVE_ATTENTION_KEY];
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export const createTuiFocusTracker = ({ renderer, onFocus } = {}) => {
|
|
2
|
+
let state = "unknown";
|
|
3
|
+
const handleFocus = () => {
|
|
4
|
+
state = "focused";
|
|
5
|
+
try { onFocus?.(); } catch {}
|
|
6
|
+
};
|
|
7
|
+
const handleBlur = () => { state = "blurred"; };
|
|
8
|
+
renderer?.on?.("focus", handleFocus);
|
|
9
|
+
renderer?.on?.("blur", handleBlur);
|
|
10
|
+
return {
|
|
11
|
+
state: () => state,
|
|
12
|
+
isFocused: () => state !== "blurred",
|
|
13
|
+
dispose: () => {
|
|
14
|
+
renderer?.off?.("focus", handleFocus);
|
|
15
|
+
renderer?.off?.("blur", handleBlur);
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
};
|