@takboo/dsh-coopanion 0.4.16 → 0.4.18

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 CHANGED
@@ -58,7 +58,7 @@
58
58
  打开侧边栏 **插件 → 添加插件**,在「包名或地址」中填入:
59
59
 
60
60
  ```text
61
- @takboo/dsh-coopanion@0.4.16
61
+ @takboo/dsh-coopanion@0.4.18
62
62
  ```
63
63
 
64
64
  点击安装,完成后启用 `dsh-coopanion`,再完全退出并重新打开 Harness。
@@ -70,7 +70,7 @@
70
70
  使用 **Desktop 自带的 `dsh` 命令**。先启动 Desktop 一次完成初始化,完全退出应用后执行:
71
71
 
72
72
  ```bash
73
- dsh plugin --profile desktop add @takboo/dsh-coopanion@0.4.16
73
+ dsh plugin --profile desktop add @takboo/dsh-coopanion@0.4.18
74
74
  ```
75
75
 
76
76
  完成后重新打开 Desktop。其他 profile 的安装方法见[使用指南](docs/usage.md#通过-dsh-命令行安装)。
@@ -0,0 +1,32 @@
1
+ // Windows can lose TOPMOST without a corresponding Electron window event.
2
+ // Check periodically while shown, but only repair a missing flag: repeatedly
3
+ // raising an already-topmost window changes its order among other overlays.
4
+ module.exports.installAlwaysOnTop = (win, { platform = process.platform, isSuspended = () => false } = {}) => {
5
+ win.setAlwaysOnTop(true, platform === 'win32' ? 'screen-saver' : 'floating');
6
+ if (platform !== 'win32') return () => {};
7
+ let disposed = false, timer, pending;
8
+ const pause = () => { clearInterval(timer); timer = undefined; clearImmediate(pending); pending = undefined; };
9
+ const repair = () => {
10
+ if (disposed || win.isDestroyed() || !win.isVisible() || win.isMinimized() || isSuspended()) return;
11
+ if (!win.isAlwaysOnTop()) win.setAlwaysOnTop(true, 'screen-saver');
12
+ };
13
+ const reconcile = () => {
14
+ pending = undefined;
15
+ if (disposed || win.isDestroyed() || !win.isVisible() || win.isMinimized()) { pause(); return; }
16
+ repair();
17
+ timer ??= setInterval(repair, 3000);
18
+ timer.unref?.();
19
+ };
20
+ const schedule = () => { if (!disposed && pending === undefined) pending = setImmediate(reconcile); };
21
+ const events = ['show', 'restore', 'focus', 'blur'];
22
+ const dispose = () => {
23
+ if (disposed) return;
24
+ disposed = true; pause();
25
+ for (const event of events) win.off(event, schedule);
26
+ win.off('hide', pause); win.off('minimize', pause); win.off('closed', dispose);
27
+ };
28
+ for (const event of events) win.on(event, schedule);
29
+ win.on('hide', pause); win.on('minimize', pause); win.once('closed', dispose);
30
+ reconcile();
31
+ return dispose;
32
+ };
package/desktop/main.cjs CHANGED
@@ -14,6 +14,7 @@ const { CharacterStore } = require('../dist/character-store.cjs');
14
14
  const { createPetServer } = require('../dist/figure-server.cjs');
15
15
  const { trayState, trayLocale } = require('./tray-state.cjs');
16
16
  const { createDisplayController } = require('./display-controller.cjs');
17
+ const { installAlwaysOnTop } = require('./always-on-top.cjs');
17
18
  const { petCopy, petLanguage } = require('../web/locale.js');
18
19
  app.setName(petCopy('en').defaultName);
19
20
  if (process.env.DSH_PET_TEST_DATA_DIR) {
@@ -34,7 +35,7 @@ if (process.env.DSH_PET_TEST_DEBUG_PORT) {
34
35
  const displayTest = process.env.DSH_PET_TEST_NO_SANDBOX === '1' && !!process.env.DSH_PET_TEST_DEBUG_PORT;
35
36
  const keyboardActivity = require('./keyboard-activity.cjs').createKeyboardActivity();
36
37
  const { initialLockState } = require('./lifecycle-state.cjs');
37
- let win, tray, options, lastFrame, poll, assetServer, characters, companions, displays, diagnostics, diagnosticRead;
38
+ let win, tray, options, lastFrame, poll, assetServer, characters, companions, displays, diagnostics, diagnosticRead, disposeAlwaysOnTop;
38
39
  let lifecycle = { locks: 0, unlocks: 0, suspends: 0, resumes: 0 };
39
40
  const configureDiagnostics = () => {
40
41
  if (options?.diagnostics !== true) {
@@ -216,7 +217,7 @@ app.whenReady().then(async () => {
216
217
  return characters.import(new Uint8Array(value));
217
218
  });
218
219
  win = new BrowserWindow({ ...screen.getPrimaryDisplay().workArea, transparent: true, frame: false, resizable: false, skipTaskbar: true, hasShadow: false, show: false, alwaysOnTop: true, backgroundColor: '#00000000', webPreferences: { additionalArguments: displayTest ? ['--dsh-pet-display-test'] : [], preload: join(__dirname, 'preload.cjs'), sandbox: true, contextIsolation: true, nodeIntegration: false } });
219
- win.setAlwaysOnTop(true, 'floating');
220
+ disposeAlwaysOnTop = installAlwaysOnTop(win, { isSuspended: () => suspended });
220
221
  win.on('show', visibility); win.on('hide', visibility);
221
222
  win.webContents.on('render-process-gone', () => app.exit(1));
222
223
  win.setVisibleOnAllWorkspaces(true, { visibleOnFullScreen: true });
@@ -280,5 +281,5 @@ app.whenReady().then(async () => {
280
281
  if (process.connected) process.send(failure, () => app.exit(1)); else app.exit(1);
281
282
  });
282
283
 
283
- app.on('before-quit', () => { if (userClosed) process.send?.({ type: 'closed' }); clearInterval(poll); keyboardActivity.configure(false); if (diagnosticRead) { clearTimeout(diagnosticRead.timer); diagnosticRead.resolve(null); diagnosticRead = undefined; } diagnostics?.release(); void diagnostics?.close(); assetServer?.close(); tray?.destroy(); });
284
+ app.on('before-quit', () => { if (userClosed) process.send?.({ type: 'closed' }); disposeAlwaysOnTop?.(); clearInterval(poll); keyboardActivity.configure(false); if (diagnosticRead) { clearTimeout(diagnosticRead.timer); diagnosticRead.resolve(null); diagnosticRead = undefined; } diagnostics?.release(); void diagnostics?.close(); assetServer?.close(); tray?.destroy(); });
284
285
  app.on('window-all-closed', () => { userClosed = true; app.quit(); });
package/dist/bridge.js CHANGED
@@ -204,8 +204,10 @@ var ElectronBridge = class extends EventEmitter {
204
204
  this.send({ type: "snapshot", snapshot: desktopSnapshot(snapshot, key !== this.resultKey) });
205
205
  this.resultKey = key;
206
206
  }
207
- notify(notice) {
208
- this.send({ type: "notice", notice });
207
+ notify(notice, runtime) {
208
+ if (!this.child?.connected || this.closing) return false;
209
+ if (runtime && (!this.nativeVisible || this.suspended || runtime.generation !== this.generation || runtime.visibilityRevision !== this.visibilityRevision || !runtime.visible)) return false;
210
+ return this.send({ type: "notice", notice, ...runtime ? { generation: runtime.generation, visibilityRevision: runtime.visibilityRevision } : {} });
209
211
  }
210
212
  notificationState(snapshot) {
211
213
  this.lastNotificationState = structuredClone(snapshot);
@@ -215,9 +217,7 @@ var ElectronBridge = class extends EventEmitter {
215
217
  this.send({ type: "notification-snooze-result", interactionId, ok, ...error ? { error: error.slice(0, 600) } : {} });
216
218
  }
217
219
  presentRole(notice, runtime) {
218
- if (!this.child?.connected || this.closing || !this.nativeVisible || this.suspended || runtime.generation !== this.generation || runtime.visibilityRevision !== this.visibilityRevision || !runtime.visible) return false;
219
- this.send({ type: "notice", notice, generation: runtime.generation, visibilityRevision: runtime.visibilityRevision });
220
- return true;
220
+ return this.notify(notice, runtime);
221
221
  }
222
222
  chatResult(receipt) {
223
223
  this.send(receipt);
@@ -249,9 +249,15 @@ var ElectronBridge = class extends EventEmitter {
249
249
  }
250
250
  send(message) {
251
251
  const child = this.child;
252
- if (child?.connected && !this.closing) child.send(message, (error) => {
253
- if (error && this.child === child && !this.closing) this.emit("failure", error);
254
- });
252
+ if (!child?.connected || this.closing) return false;
253
+ try {
254
+ child.send(message, (error) => {
255
+ if (error && this.child === child && !this.closing) this.emit("failure", error);
256
+ });
257
+ return true;
258
+ } catch {
259
+ return false;
260
+ }
255
261
  }
256
262
  async dispose() {
257
263
  this.closing = true;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/bridge.ts", "../src/desktop-lifecycle.ts", "../src/electron-runtime.ts"],
4
- "sourcesContent": ["import { spawn, type ChildProcess } from 'node:child_process';\nimport { fileURLToPath } from 'node:url';\nimport { EventEmitter } from 'node:events';\nimport type { ChatReceipt } from '../web/chat-contract.js';\nimport type { PetSnapshot, PetNotice } from './model.ts';\nimport type { NotificationRuntime, NotificationSnapshot, TaskNotice } from './notification-contract.ts';\nimport { NativeStartError, type StartLifetime, type NativeLifecycle } from './desktop-lifecycle.ts';\nimport { electronExecutable } from './electron-runtime.ts';\nexport { NativeStartError, type StartLifetime, type NativeLifecycle } from './desktop-lifecycle.ts';\n\nimport type { CompanionshipMode } from '../web/companionship.js';\nimport type { TextScale } from '../web/text-scale.js';\n\nexport interface DesktopOptions { size: number; npcHome?: number; npcRange?: number; textScale?: TextScale; roam: boolean; diagnostics?: boolean; companionship?: CompanionshipMode; notifications: boolean; bubbleDurationMs: number; electronPath?: string; locale?: string; systemNotifications?: boolean; reminders?: boolean; reminderDelayMs?: number; }\nexport interface PetBridge {\n start(options: DesktopOptions, lifetime?: StartLifetime): Promise<void>;\n update(snapshot: PetSnapshot): void;\n chatResult?(receipt: ChatReceipt): void;\n notify(notice: PetNotice | TaskNotice): void;\n notificationState?(snapshot: NotificationSnapshot): void;\n snoozeResult?(interactionId: string, ok: boolean, error?: string): void;\n presentRole?(notice: TaskNotice, runtime: NotificationRuntime): boolean;\n onAction(listener: (action: unknown) => void): void;\n removeAction(listener: (action: unknown) => void): void;\n dispose(): Promise<void>;\n configure?(options: DesktopOptions): void;\n control?(command: 'show' | 'hide' | 'characters'): void;\n focusHarness?(): void;\n onLifecycle?(listener: (state: NativeLifecycle) => void): void;\n removeLifecycle?(listener: (state: NativeLifecycle) => void): void;\n}\n\n/** Owns a separate Electron window; no changes or private IPC in the Harness desktop shell are needed. */\nexport class ElectronBridge extends EventEmitter implements PetBridge {\n private child?: ChildProcess;\n private latest?: PetSnapshot;\n private latestOptions?: DesktopOptions;\n private resultKey?: string;\n private closing = false;\n private preparing?: AbortController;\n private preparation?: Promise<string>;\n\n private generation = 0;\n private visibilityRevision = 0;\n private nativeVisible = false;\n private suspended = false;\n private screenLocked = false;\n private systemAsleep = false;\n private lastNotificationState?: NotificationSnapshot;\n\n async start(options: DesktopOptions, lifetime?: StartLifetime): Promise<void> {\n if (this.child || this.preparing) throw new NativeStartError('Desktop pet is already running or starting', false);\n if (lifetime?.signal.aborted) throw new Error('\u684C\u5BA0\u542F\u52A8\u5DF2\u53D6\u6D88');\n this.latestOptions = { ...options };\n this.closing = false;\n this.generation = lifetime?.generation ?? this.generation + 1;\n this.visibilityRevision = 0; this.nativeVisible = false;\n if (process.platform === 'linux' && !process.env.DISPLAY && !process.env.WAYLAND_DISPLAY) throw new NativeStartError('\u684C\u5BA0\u9700\u8981\u684C\u9762\u663E\u793A\u73AF\u5883\u3002', false);\n let executable: string;\n if (options.electronPath !== undefined) executable = options.electronPath;\n else {\n const preparing = new AbortController(); this.preparing = preparing;\n const abort = () => preparing.abort();\n lifetime?.signal.addEventListener('abort', abort, { once: true });\n if (lifetime?.signal.aborted) abort();\n try {\n this.preparation = electronExecutable(preparing.signal);\n executable = await this.preparation;\n if (preparing.signal.aborted || this.closing) throw new Error('\u684C\u5BA0\u542F\u52A8\u5DF2\u53D6\u6D88');\n } catch (error) { throw error instanceof NativeStartError ? error : new NativeStartError(String(error).slice(0, 600), false); }\n finally { lifetime?.signal.removeEventListener('abort', abort); this.preparing = undefined; this.preparation = undefined; }\n }\n const env: NodeJS.ProcessEnv = { ...process.env, DSH_PET_GENERATION: String(this.generation), DSH_PET_VISIBLE: lifetime?.visible === false ? '0' : '1', DSH_PET_SCREEN_LOCKED: this.screenLocked ? '1' : '0', DSH_PET_SYSTEM_ASLEEP: this.systemAsleep ? '1' : '0' };\n delete (env as NodeJS.ProcessEnv).ELECTRON_RUN_AS_NODE;\n const args = [fileURLToPath(new URL('../desktop/main.cjs', import.meta.url))];\n if (env.DSH_PET_TEST_NO_SANDBOX === '1') args.unshift('--no-sandbox');\n const child = spawn(executable, args, { env, stdio: ['ignore', 'pipe', 'pipe', 'ipc'] });\n const generation = this.generation; this.child = child;\n let diagnostic = '', userClosed = false;\n child.stderr?.on('data', data => { diagnostic = (diagnostic + data.toString()).slice(-4000); });\n child.on('message', message => {\n if (this.child !== child || this.closing || lifetime?.signal.aborted || !isRecord(message)) return;\n if (message.type === 'closed') userClosed = true;\n if (message.type === 'action') this.emit('action', message.action);\n if (message.type === 'tray-state') this.emit('tray-state', message.state);\n if (message.type === 'tray-icon') this.emit('tray-icon', message);\n if (message.type === 'visibility' && message.generation === generation && typeof message.visible === 'boolean' && Number.isSafeInteger(message.visibilityRevision) && (message.visibilityRevision as number) > this.visibilityRevision) {\n this.visibilityRevision = message.visibilityRevision as number;\n this.nativeVisible = message.visible; this.suspended = message.suspended === true;\n if (typeof message.screenLocked === 'boolean') this.screenLocked = message.screenLocked;\n if (typeof message.systemAsleep === 'boolean') this.systemAsleep = message.systemAsleep;\n this.emit('lifecycle', { running: true, visible: this.nativeVisible, generation, visibilityRevision: this.visibilityRevision, suspended: this.suspended, ...(typeof message.desiredVisible === 'boolean' ? { desiredVisible: message.desiredVisible } : {}) });\n }\n });\n child.once('exit', (code, signal) => {\n if (this.child !== child) return;\n this.child = undefined; this.nativeVisible = false;\n const unexpected = !this.closing && !userClosed && !lifetime?.signal.aborted;\n const error = unexpected ? `\u684C\u5BA0\u8FDB\u7A0B\u5DF2\u9000\u51FA (${signal ?? code}): ${diagnostic}`.slice(0, 600) : undefined;\n this.emit('lifecycle', { running: false, visible: false, generation, visibilityRevision: ++this.visibilityRevision, suspended: false, unexpected, ...(error ? { error } : {}) });\n if (error) this.emit('failure', new Error(error));\n });\n child.on('error', error => { if (this.child === child && !this.closing && !lifetime?.signal.aborted) this.emit('failure', error); });\n await new Promise<void>((resolve, reject) => {\n let done = false;\n const finish = (error?: Error) => {\n if (done) return; done = true;\n clearTimeout(timer); child.off('message', ready); child.off('error', failed); child.off('exit', exited); lifetime?.signal.removeEventListener('abort', aborted);\n if (error) { child.kill(); reject(error); } else resolve();\n };\n const ready = (message: unknown) => {\n if (isRecord(message) && message.type === 'startup-error' && this.child === child && typeof message.error === 'string') {\n finish(new NativeStartError(message.error.slice(0, 600), message.recoverable === true)); return;\n }\n if (isRecord(message) && message.type === 'ready' && this.child === child && !lifetime?.signal.aborted) {\n this.resultKey = undefined;\n this.send({ type: 'init', options: { ...this.latestOptions, locale: this.latestOptions?.locale ?? null }, baseline: true, snapshot: this.latest && desktopSnapshot(this.latest, true) });\n if (this.lastNotificationState) this.notificationState(this.lastNotificationState);\n finish();\n }\n };\n const failed = (error: NodeJS.ErrnoException) => finish(new NativeStartError(error.message.slice(0, 600), error.code === 'EAGAIN' || error.code === 'ENOMEM'));\n const exited = (code: number | null, signal: string | null) => finish(new NativeStartError(`\u684C\u5BA0\u542F\u52A8\u5931\u8D25 (${signal ?? code}): ${diagnostic}`.slice(0, 600), true));\n const aborted = () => finish(new Error('\u684C\u5BA0\u542F\u52A8\u5DF2\u53D6\u6D88'));\n const timer = setTimeout(() => finish(new NativeStartError(`\u684C\u5BA0\u672A\u80FD\u5728 20 \u79D2\u5185\u542F\u52A8: ${diagnostic}`.slice(0, 600), true)), 20000);\n child.on('message', ready); child.once('error', failed); child.once('exit', exited);\n lifetime?.signal.addEventListener('abort', aborted, { once: true });\n if (lifetime?.signal.aborted) aborted();\n });\n }\n\n update(snapshot: PetSnapshot): void {\n this.latest = snapshot;\n const key = snapshot.results.map(result => `${result.id}:${result.read}`).join('|');\n this.send({ type: 'snapshot', snapshot: desktopSnapshot(snapshot, key !== this.resultKey) });\n this.resultKey = key;\n }\n notify(notice: PetNotice | TaskNotice): void { this.send({ type: 'notice', notice }); }\n notificationState(snapshot: NotificationSnapshot): void { this.lastNotificationState = structuredClone(snapshot); this.send({ type: 'notification-state', snapshot }); }\n snoozeResult(interactionId: string, ok: boolean, error?: string): void { this.send({ type: 'notification-snooze-result', interactionId, ok, ...(error ? { error: error.slice(0, 600) } : {}) }); }\n presentRole(notice: TaskNotice, runtime: NotificationRuntime): boolean {\n if (!this.child?.connected || this.closing || !this.nativeVisible || this.suspended || runtime.generation !== this.generation || runtime.visibilityRevision !== this.visibilityRevision || !runtime.visible) return false;\n this.send({ type: 'notice', notice, generation: runtime.generation, visibilityRevision: runtime.visibilityRevision }); return true;\n }\n chatResult(receipt: ChatReceipt): void { this.send(receipt); }\n onAction(listener: (action: unknown) => void): void { this.on('action', listener); }\n removeAction(listener: (action: unknown) => void): void { this.off('action', listener); }\n // JSON IPC omits undefined. An explicit null lets a cleared Harness\n // preference restore the renderer's automatic language instead of retaining\n // its previous locale during a merged configuration update.\n configure(options: DesktopOptions): void { this.latestOptions = { ...options }; this.send({ type: 'configure', options: { ...options, locale: options.locale ?? null } }); }\n control(command: 'show' | 'hide' | 'characters'): void { this.send({ type: 'control', command }); }\n focusHarness(): void { this.send({ type: 'control', command: 'focus-harness' }); }\n onLifecycle(listener: (state: NativeLifecycle) => void): void { this.on('lifecycle', listener); }\n removeLifecycle(listener: (state: NativeLifecycle) => void): void { this.off('lifecycle', listener); }\n private send(message: object): void {\n const child = this.child;\n if (child?.connected && !this.closing) child.send(message, error => { if (error && this.child === child && !this.closing) this.emit('failure', error); });\n }\n\n async dispose(): Promise<void> {\n this.closing = true;\n this.preparing?.abort();\n await this.preparation?.catch(() => undefined);\n const child = this.child;\n if (!child) return;\n if (child.pid === undefined || child.exitCode !== null || child.signalCode !== null) { if (this.child === child) this.child = undefined; return; }\n await new Promise<void>((resolve, reject) => {\n let deadline: ReturnType<typeof setTimeout>;\n const timer = setTimeout(() => { child.kill('SIGKILL'); deadline = setTimeout(() => { if (child.exitCode !== null || child.signalCode !== null) resolve(); else reject(new Error('\u684C\u5BA0\u8FDB\u7A0B\u672A\u786E\u8BA4\u9000\u51FA')); }, 1000); }, 3000);\n child.once('exit', () => { clearTimeout(timer); clearTimeout(deadline); resolve(); });\n if (child.connected) child.send({ type: 'quit' }, error => { if (error) child.kill(); }); else child.kill();\n });\n if (this.child === child) this.child = undefined;\n }\n}\n\nexport function isRecord(value: unknown): value is Record<string, unknown> { return typeof value === 'object' && value !== null && !Array.isArray(value); }\n\n/** Stream animation updates carry metadata; full result text crosses IPC only when it changes. */\nfunction desktopSnapshot(snapshot: PetSnapshot, includeResults: boolean) {\n const { results, ...state } = snapshot;\n return { ...state, text: state.mood === 'happy' ? '' : state.text,\n sessions: state.sessions.map(session => ({ ...session, text: session.mood === 'happy' ? '' : session.text, reply: '' })),\n ...(includeResults ? { results } : {}),\n };\n}\n", "/** Shared Host/native lifetime contract. Only explicitly recoverable failures retry. */\nexport interface StartLifetime { signal: AbortSignal; generation: number; visible?: boolean; }\nexport interface NativeLifecycle {\n running: boolean; visible: boolean; error?: string;\n generation?: number; visibilityRevision?: number; suspended?: boolean;\n desiredVisible?: boolean; unexpected?: boolean;\n}\nexport class NativeStartError extends Error {\n constructor(message: string, readonly recoverable: boolean) { super(message); this.name = 'NativeStartError'; }\n}\n", "import { spawn } from 'node:child_process';\nimport { access, readFile } from 'node:fs/promises';\nimport { createRequire } from 'node:module';\nimport { dirname, join } from 'node:path';\nimport { NativeStartError } from './desktop-lifecycle.ts';\n\n// Electron 44's index.js may spawnSync its installer. Resolve files without\n// executing that entrypoint, then prepare missing binaries off the Host loop.\nexport async function electronExecutable(signal: AbortSignal): Promise<string> {\n const directory = dirname(createRequire(import.meta.url).resolve('electron'));\n async function installed(): Promise<string | undefined> {\n let relative: string;\n try { relative = await readFile(join(directory, 'path.txt'), 'utf8'); }\n catch (error) { if ((error as NodeJS.ErrnoException).code !== 'ENOENT') throw error; relative = ''; }\n if (process.env.ELECTRON_OVERRIDE_DIST_PATH) return join(process.env.ELECTRON_OVERRIDE_DIST_PATH, relative || 'electron');\n if (!relative) return;\n const executable = join(directory, 'dist', relative);\n try { await access(executable); return executable; }\n catch (error) { if ((error as NodeJS.ErrnoException).code !== 'ENOENT') throw error; }\n }\n if (signal.aborted) throw new Error('\u684C\u5BA0\u542F\u52A8\u5DF2\u53D6\u6D88');\n const existing = await installed();\n if (existing) return existing;\n await new Promise<void>((resolve, reject) => {\n if (signal.aborted) { reject(new Error('\u684C\u5BA0\u542F\u52A8\u5DF2\u53D6\u6D88')); return; }\n const child = spawn(process.execPath, [join(directory, 'install.js')], {\n env: { ...process.env, ELECTRON_RUN_AS_NODE: '1' }, stdio: 'ignore', windowsHide: true,\n });\n let failure: Error | undefined, killTimer: ReturnType<typeof setTimeout> | undefined;\n const stop = (error: Error) => {\n if (failure) return;\n failure = error; child.kill();\n killTimer = setTimeout(() => child.kill('SIGKILL'), 1000);\n };\n const aborted = () => stop(new Error('\u684C\u5BA0\u542F\u52A8\u5DF2\u53D6\u6D88'));\n const timer = setTimeout(() => stop(new NativeStartError('Electron \u8FD0\u884C\u65F6\u51C6\u5907\u8D85\u65F6\uFF0C\u8BF7\u68C0\u67E5\u7F51\u7EDC\u6216\u6309\u4F7F\u7528\u6307\u5357\u9884\u5148\u5B89\u88C5\u8FD0\u884C\u65F6\u3002', false)), 240_000);\n signal.addEventListener('abort', aborted, { once: true });\n const finish = (error?: Error) => {\n clearTimeout(timer); clearTimeout(killTimer); signal.removeEventListener('abort', aborted);\n if (failure || error) reject(failure ?? error); else resolve();\n };\n child.once('error', error => finish(new NativeStartError(error.message.slice(0, 600), false)));\n child.once('exit', code => finish(code === 0 ? undefined : new NativeStartError(`Electron \u8FD0\u884C\u65F6\u51C6\u5907\u5931\u8D25 (${code})\uFF0C\u8BF7\u68C0\u67E5\u7F51\u7EDC\u6216\u6309\u4F7F\u7528\u6307\u5357\u9884\u5148\u5B89\u88C5\u8FD0\u884C\u65F6\u3002`, false)));\n if (signal.aborted) aborted();\n });\n if (signal.aborted) throw new Error('\u684C\u5BA0\u542F\u52A8\u5DF2\u53D6\u6D88');\n const executable = await installed();\n if (!executable) throw new NativeStartError('Electron \u5B89\u88C5\u672A\u751F\u6210\u53EF\u7528\u8FD0\u884C\u65F6\uFF0C\u8BF7\u6309\u4F7F\u7528\u6307\u5357\u91CD\u65B0\u51C6\u5907\u3002', false);\n return executable;\n}\n"],
5
- "mappings": ";AAAA,SAAS,SAAAA,cAAgC;AACzC,SAAS,qBAAqB;AAC9B,SAAS,oBAAoB;;;ACKtB,IAAM,mBAAN,cAA+B,MAAM;AAAA,EAC1C,YAAY,SAA0B,aAAsB;AAAE,UAAM,OAAO;AAArC;AAAwC,SAAK,OAAO;AAAA,EAAoB;AAChH;;;ACTA,SAAS,aAAa;AACtB,SAAS,QAAQ,gBAAgB;AACjC,SAAS,qBAAq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KAAK,UAAU,MAAO,MAAK,QAAQ;AAAA,EACzC;AACF;AAEO,SAAS,SAAS,OAAkD;AAAE,SAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAAG;AAG1J,SAAS,gBAAgB,UAAuB,gBAAyB;AACvE,QAAM,EAAE,SAAS,GAAG,MAAM,IAAI;AAC9B,SAAO;AAAA,IAAE,GAAG;AAAA,IAAO,MAAM,MAAM,SAAS,UAAU,KAAK,MAAM;AAAA,IAC3D,UAAU,MAAM,SAAS,IAAI,cAAY,EAAE,GAAG,SAAS,MAAM,QAAQ,SAAS,UAAU,KAAK,QAAQ,MAAM,OAAO,GAAG,EAAE;AAAA,IACvH,GAAI,iBAAiB,EAAE,QAAQ,IAAI,CAAC;AAAA,EACtC;AACF;",
4
+ "sourcesContent": ["import { spawn, type ChildProcess } from 'node:child_process';\nimport { fileURLToPath } from 'node:url';\nimport { EventEmitter } from 'node:events';\nimport type { ChatReceipt } from '../web/chat-contract.js';\nimport type { PetSnapshot, PetNotice } from './model.ts';\nimport type { NotificationRuntime, NotificationSnapshot, TaskNotice } from './notification-contract.ts';\nimport { NativeStartError, type StartLifetime, type NativeLifecycle } from './desktop-lifecycle.ts';\nimport { electronExecutable } from './electron-runtime.ts';\nexport { NativeStartError, type StartLifetime, type NativeLifecycle } from './desktop-lifecycle.ts';\n\nimport type { CompanionshipMode } from '../web/companionship.js';\nimport type { TextScale } from '../web/text-scale.js';\n\nexport interface DesktopOptions { size: number; npcHome?: number; npcRange?: number; textScale?: TextScale; roam: boolean; diagnostics?: boolean; companionship?: CompanionshipMode; notifications: boolean; bubbleDurationMs: number; electronPath?: string; locale?: string; systemNotifications?: boolean; reminders?: boolean; reminderDelayMs?: number; }\nexport interface PetBridge {\n start(options: DesktopOptions, lifetime?: StartLifetime): Promise<void>;\n update(snapshot: PetSnapshot): void;\n chatResult?(receipt: ChatReceipt): void;\n notify(notice: PetNotice | TaskNotice, runtime?: NotificationRuntime): boolean;\n notificationState?(snapshot: NotificationSnapshot): void;\n snoozeResult?(interactionId: string, ok: boolean, error?: string): void;\n presentRole?(notice: TaskNotice, runtime: NotificationRuntime): boolean;\n onAction(listener: (action: unknown) => void): void;\n removeAction(listener: (action: unknown) => void): void;\n dispose(): Promise<void>;\n configure?(options: DesktopOptions): void;\n control?(command: 'show' | 'hide' | 'characters'): void;\n focusHarness?(): void;\n onLifecycle?(listener: (state: NativeLifecycle) => void): void;\n removeLifecycle?(listener: (state: NativeLifecycle) => void): void;\n}\n\n/** Owns a separate Electron window; no changes or private IPC in the Harness desktop shell are needed. */\nexport class ElectronBridge extends EventEmitter implements PetBridge {\n private child?: ChildProcess;\n private latest?: PetSnapshot;\n private latestOptions?: DesktopOptions;\n private resultKey?: string;\n private closing = false;\n private preparing?: AbortController;\n private preparation?: Promise<string>;\n\n private generation = 0;\n private visibilityRevision = 0;\n private nativeVisible = false;\n private suspended = false;\n private screenLocked = false;\n private systemAsleep = false;\n private lastNotificationState?: NotificationSnapshot;\n\n async start(options: DesktopOptions, lifetime?: StartLifetime): Promise<void> {\n if (this.child || this.preparing) throw new NativeStartError('Desktop pet is already running or starting', false);\n if (lifetime?.signal.aborted) throw new Error('\u684C\u5BA0\u542F\u52A8\u5DF2\u53D6\u6D88');\n this.latestOptions = { ...options };\n this.closing = false;\n this.generation = lifetime?.generation ?? this.generation + 1;\n this.visibilityRevision = 0; this.nativeVisible = false;\n if (process.platform === 'linux' && !process.env.DISPLAY && !process.env.WAYLAND_DISPLAY) throw new NativeStartError('\u684C\u5BA0\u9700\u8981\u684C\u9762\u663E\u793A\u73AF\u5883\u3002', false);\n let executable: string;\n if (options.electronPath !== undefined) executable = options.electronPath;\n else {\n const preparing = new AbortController(); this.preparing = preparing;\n const abort = () => preparing.abort();\n lifetime?.signal.addEventListener('abort', abort, { once: true });\n if (lifetime?.signal.aborted) abort();\n try {\n this.preparation = electronExecutable(preparing.signal);\n executable = await this.preparation;\n if (preparing.signal.aborted || this.closing) throw new Error('\u684C\u5BA0\u542F\u52A8\u5DF2\u53D6\u6D88');\n } catch (error) { throw error instanceof NativeStartError ? error : new NativeStartError(String(error).slice(0, 600), false); }\n finally { lifetime?.signal.removeEventListener('abort', abort); this.preparing = undefined; this.preparation = undefined; }\n }\n const env: NodeJS.ProcessEnv = { ...process.env, DSH_PET_GENERATION: String(this.generation), DSH_PET_VISIBLE: lifetime?.visible === false ? '0' : '1', DSH_PET_SCREEN_LOCKED: this.screenLocked ? '1' : '0', DSH_PET_SYSTEM_ASLEEP: this.systemAsleep ? '1' : '0' };\n delete (env as NodeJS.ProcessEnv).ELECTRON_RUN_AS_NODE;\n const args = [fileURLToPath(new URL('../desktop/main.cjs', import.meta.url))];\n if (env.DSH_PET_TEST_NO_SANDBOX === '1') args.unshift('--no-sandbox');\n const child = spawn(executable, args, { env, stdio: ['ignore', 'pipe', 'pipe', 'ipc'] });\n const generation = this.generation; this.child = child;\n let diagnostic = '', userClosed = false;\n child.stderr?.on('data', data => { diagnostic = (diagnostic + data.toString()).slice(-4000); });\n child.on('message', message => {\n if (this.child !== child || this.closing || lifetime?.signal.aborted || !isRecord(message)) return;\n if (message.type === 'closed') userClosed = true;\n if (message.type === 'action') this.emit('action', message.action);\n if (message.type === 'tray-state') this.emit('tray-state', message.state);\n if (message.type === 'tray-icon') this.emit('tray-icon', message);\n if (message.type === 'visibility' && message.generation === generation && typeof message.visible === 'boolean' && Number.isSafeInteger(message.visibilityRevision) && (message.visibilityRevision as number) > this.visibilityRevision) {\n this.visibilityRevision = message.visibilityRevision as number;\n this.nativeVisible = message.visible; this.suspended = message.suspended === true;\n if (typeof message.screenLocked === 'boolean') this.screenLocked = message.screenLocked;\n if (typeof message.systemAsleep === 'boolean') this.systemAsleep = message.systemAsleep;\n this.emit('lifecycle', { running: true, visible: this.nativeVisible, generation, visibilityRevision: this.visibilityRevision, suspended: this.suspended, ...(typeof message.desiredVisible === 'boolean' ? { desiredVisible: message.desiredVisible } : {}) });\n }\n });\n child.once('exit', (code, signal) => {\n if (this.child !== child) return;\n this.child = undefined; this.nativeVisible = false;\n const unexpected = !this.closing && !userClosed && !lifetime?.signal.aborted;\n const error = unexpected ? `\u684C\u5BA0\u8FDB\u7A0B\u5DF2\u9000\u51FA (${signal ?? code}): ${diagnostic}`.slice(0, 600) : undefined;\n this.emit('lifecycle', { running: false, visible: false, generation, visibilityRevision: ++this.visibilityRevision, suspended: false, unexpected, ...(error ? { error } : {}) });\n if (error) this.emit('failure', new Error(error));\n });\n child.on('error', error => { if (this.child === child && !this.closing && !lifetime?.signal.aborted) this.emit('failure', error); });\n await new Promise<void>((resolve, reject) => {\n let done = false;\n const finish = (error?: Error) => {\n if (done) return; done = true;\n clearTimeout(timer); child.off('message', ready); child.off('error', failed); child.off('exit', exited); lifetime?.signal.removeEventListener('abort', aborted);\n if (error) { child.kill(); reject(error); } else resolve();\n };\n const ready = (message: unknown) => {\n if (isRecord(message) && message.type === 'startup-error' && this.child === child && typeof message.error === 'string') {\n finish(new NativeStartError(message.error.slice(0, 600), message.recoverable === true)); return;\n }\n if (isRecord(message) && message.type === 'ready' && this.child === child && !lifetime?.signal.aborted) {\n this.resultKey = undefined;\n this.send({ type: 'init', options: { ...this.latestOptions, locale: this.latestOptions?.locale ?? null }, baseline: true, snapshot: this.latest && desktopSnapshot(this.latest, true) });\n if (this.lastNotificationState) this.notificationState(this.lastNotificationState);\n finish();\n }\n };\n const failed = (error: NodeJS.ErrnoException) => finish(new NativeStartError(error.message.slice(0, 600), error.code === 'EAGAIN' || error.code === 'ENOMEM'));\n const exited = (code: number | null, signal: string | null) => finish(new NativeStartError(`\u684C\u5BA0\u542F\u52A8\u5931\u8D25 (${signal ?? code}): ${diagnostic}`.slice(0, 600), true));\n const aborted = () => finish(new Error('\u684C\u5BA0\u542F\u52A8\u5DF2\u53D6\u6D88'));\n const timer = setTimeout(() => finish(new NativeStartError(`\u684C\u5BA0\u672A\u80FD\u5728 20 \u79D2\u5185\u542F\u52A8: ${diagnostic}`.slice(0, 600), true)), 20000);\n child.on('message', ready); child.once('error', failed); child.once('exit', exited);\n lifetime?.signal.addEventListener('abort', aborted, { once: true });\n if (lifetime?.signal.aborted) aborted();\n });\n }\n\n update(snapshot: PetSnapshot): void {\n this.latest = snapshot;\n const key = snapshot.results.map(result => `${result.id}:${result.read}`).join('|');\n this.send({ type: 'snapshot', snapshot: desktopSnapshot(snapshot, key !== this.resultKey) });\n this.resultKey = key;\n }\n notify(notice: PetNotice | TaskNotice, runtime?: NotificationRuntime): boolean {\n if (!this.child?.connected || this.closing) return false;\n if (runtime && (!this.nativeVisible || this.suspended || runtime.generation !== this.generation || runtime.visibilityRevision !== this.visibilityRevision || !runtime.visible)) return false;\n return this.send({ type: 'notice', notice, ...(runtime ? { generation: runtime.generation, visibilityRevision: runtime.visibilityRevision } : {}) });\n }\n notificationState(snapshot: NotificationSnapshot): void { this.lastNotificationState = structuredClone(snapshot); this.send({ type: 'notification-state', snapshot }); }\n snoozeResult(interactionId: string, ok: boolean, error?: string): void { this.send({ type: 'notification-snooze-result', interactionId, ok, ...(error ? { error: error.slice(0, 600) } : {}) }); }\n presentRole(notice: TaskNotice, runtime: NotificationRuntime): boolean { return this.notify(notice, runtime); }\n chatResult(receipt: ChatReceipt): void { this.send(receipt); }\n onAction(listener: (action: unknown) => void): void { this.on('action', listener); }\n removeAction(listener: (action: unknown) => void): void { this.off('action', listener); }\n // JSON IPC omits undefined. An explicit null lets a cleared Harness\n // preference restore the renderer's automatic language instead of retaining\n // its previous locale during a merged configuration update.\n configure(options: DesktopOptions): void { this.latestOptions = { ...options }; this.send({ type: 'configure', options: { ...options, locale: options.locale ?? null } }); }\n control(command: 'show' | 'hide' | 'characters'): void { this.send({ type: 'control', command }); }\n focusHarness(): void { this.send({ type: 'control', command: 'focus-harness' }); }\n onLifecycle(listener: (state: NativeLifecycle) => void): void { this.on('lifecycle', listener); }\n removeLifecycle(listener: (state: NativeLifecycle) => void): void { this.off('lifecycle', listener); }\n private send(message: object): boolean {\n const child = this.child;\n if (!child?.connected || this.closing) return false;\n try {\n // A false Node return can mean backpressure after enqueueing. Reporting\n // rejection here would let callers send the same accepted notice again.\n child.send(message, error => { if (error && this.child === child && !this.closing) this.emit('failure', error); });\n return true;\n } catch { return false; }\n }\n\n async dispose(): Promise<void> {\n this.closing = true;\n this.preparing?.abort();\n await this.preparation?.catch(() => undefined);\n const child = this.child;\n if (!child) return;\n if (child.pid === undefined || child.exitCode !== null || child.signalCode !== null) { if (this.child === child) this.child = undefined; return; }\n await new Promise<void>((resolve, reject) => {\n let deadline: ReturnType<typeof setTimeout>;\n const timer = setTimeout(() => { child.kill('SIGKILL'); deadline = setTimeout(() => { if (child.exitCode !== null || child.signalCode !== null) resolve(); else reject(new Error('\u684C\u5BA0\u8FDB\u7A0B\u672A\u786E\u8BA4\u9000\u51FA')); }, 1000); }, 3000);\n child.once('exit', () => { clearTimeout(timer); clearTimeout(deadline); resolve(); });\n if (child.connected) child.send({ type: 'quit' }, error => { if (error) child.kill(); }); else child.kill();\n });\n if (this.child === child) this.child = undefined;\n }\n}\n\nexport function isRecord(value: unknown): value is Record<string, unknown> { return typeof value === 'object' && value !== null && !Array.isArray(value); }\n\n/** Stream animation updates carry metadata; full result text crosses IPC only when it changes. */\nfunction desktopSnapshot(snapshot: PetSnapshot, includeResults: boolean) {\n const { results, ...state } = snapshot;\n return { ...state, text: state.mood === 'happy' ? '' : state.text,\n sessions: state.sessions.map(session => ({ ...session, text: session.mood === 'happy' ? '' : session.text, reply: '' })),\n ...(includeResults ? { results } : {}),\n };\n}\n", "/** Shared Host/native lifetime contract. Only explicitly recoverable failures retry. */\nexport interface StartLifetime { signal: AbortSignal; generation: number; visible?: boolean; }\nexport interface NativeLifecycle {\n running: boolean; visible: boolean; error?: string;\n generation?: number; visibilityRevision?: number; suspended?: boolean;\n desiredVisible?: boolean; unexpected?: boolean;\n}\nexport class NativeStartError extends Error {\n constructor(message: string, readonly recoverable: boolean) { super(message); this.name = 'NativeStartError'; }\n}\n", "import { spawn } from 'node:child_process';\nimport { access, readFile } from 'node:fs/promises';\nimport { createRequire } from 'node:module';\nimport { dirname, join } from 'node:path';\nimport { NativeStartError } from './desktop-lifecycle.ts';\n\n// Electron 44's index.js may spawnSync its installer. Resolve files without\n// executing that entrypoint, then prepare missing binaries off the Host loop.\nexport async function electronExecutable(signal: AbortSignal): Promise<string> {\n const directory = dirname(createRequire(import.meta.url).resolve('electron'));\n async function installed(): Promise<string | undefined> {\n let relative: string;\n try { relative = await readFile(join(directory, 'path.txt'), 'utf8'); }\n catch (error) { if ((error as NodeJS.ErrnoException).code !== 'ENOENT') throw error; relative = ''; }\n if (process.env.ELECTRON_OVERRIDE_DIST_PATH) return join(process.env.ELECTRON_OVERRIDE_DIST_PATH, relative || 'electron');\n if (!relative) return;\n const executable = join(directory, 'dist', relative);\n try { await access(executable); return executable; }\n catch (error) { if ((error as NodeJS.ErrnoException).code !== 'ENOENT') throw error; }\n }\n if (signal.aborted) throw new Error('\u684C\u5BA0\u542F\u52A8\u5DF2\u53D6\u6D88');\n const existing = await installed();\n if (existing) return existing;\n await new Promise<void>((resolve, reject) => {\n if (signal.aborted) { reject(new Error('\u684C\u5BA0\u542F\u52A8\u5DF2\u53D6\u6D88')); return; }\n const child = spawn(process.execPath, [join(directory, 'install.js')], {\n env: { ...process.env, ELECTRON_RUN_AS_NODE: '1' }, stdio: 'ignore', windowsHide: true,\n });\n let failure: Error | undefined, killTimer: ReturnType<typeof setTimeout> | undefined;\n const stop = (error: Error) => {\n if (failure) return;\n failure = error; child.kill();\n killTimer = setTimeout(() => child.kill('SIGKILL'), 1000);\n };\n const aborted = () => stop(new Error('\u684C\u5BA0\u542F\u52A8\u5DF2\u53D6\u6D88'));\n const timer = setTimeout(() => stop(new NativeStartError('Electron \u8FD0\u884C\u65F6\u51C6\u5907\u8D85\u65F6\uFF0C\u8BF7\u68C0\u67E5\u7F51\u7EDC\u6216\u6309\u4F7F\u7528\u6307\u5357\u9884\u5148\u5B89\u88C5\u8FD0\u884C\u65F6\u3002', false)), 240_000);\n signal.addEventListener('abort', aborted, { once: true });\n const finish = (error?: Error) => {\n clearTimeout(timer); clearTimeout(killTimer); signal.removeEventListener('abort', aborted);\n if (failure || error) reject(failure ?? error); else resolve();\n };\n child.once('error', error => finish(new NativeStartError(error.message.slice(0, 600), false)));\n child.once('exit', code => finish(code === 0 ? undefined : new NativeStartError(`Electron \u8FD0\u884C\u65F6\u51C6\u5907\u5931\u8D25 (${code})\uFF0C\u8BF7\u68C0\u67E5\u7F51\u7EDC\u6216\u6309\u4F7F\u7528\u6307\u5357\u9884\u5148\u5B89\u88C5\u8FD0\u884C\u65F6\u3002`, false)));\n if (signal.aborted) aborted();\n });\n if (signal.aborted) throw new Error('\u684C\u5BA0\u542F\u52A8\u5DF2\u53D6\u6D88');\n const executable = await installed();\n if (!executable) throw new NativeStartError('Electron \u5B89\u88C5\u672A\u751F\u6210\u53EF\u7528\u8FD0\u884C\u65F6\uFF0C\u8BF7\u6309\u4F7F\u7528\u6307\u5357\u91CD\u65B0\u51C6\u5907\u3002', false);\n return executable;\n}\n"],
5
+ "mappings": ";AAAA,SAAS,SAAAA,cAAgC;AACzC,SAAS,qBAAqB;AAC9B,SAAS,oBAAoB;;;ACKtB,IAAM,mBAAN,cAA+B,MAAM;AAAA,EAC1C,YAAY,SAA0B,aAAsB;AAAE,UAAM,OAAO;AAArC;AAAwC,SAAK,OAAO;AAAA,EAAoB;AAChH;;;ACTA,SAAS,aAAa;AACtB,SAAS,QAAQ,gBAAgB;AACjC,SAAS,qBAAqB;AAC9B,SAAS,SAAS,YAAY;AAK9B,eAAsB,mBAAmB,QAAsC;AAC7E,QAAM,YAAY,QAAQ,cAAc,YAAY,GAAG,EAAE,QAAQ,UAAU,CAAC;AAC5E,iBAAe,YAAyC;AACtD,QAAI;AACJ,QAAI;AAAE,iBAAW,MAAM,SAAS,KAAK,WAAW,UAAU,GAAG,MAAM;AAAA,IAAG,SAC/D,OAAO;AAAE,UAAK,MA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,KAAK;AAAG;AAG1J,SAAS,gBAAgB,UAAuB,gBAAyB;AACvE,QAAM,EAAE,SAAS,GAAG,MAAM,IAAI;AAC9B,SAAO;AAAA,IAAE,GAAG;AAAA,IAAO,MAAM,MAAM,SAAS,UAAU,KAAK,MAAM;AAAA,IAC3D,UAAU,MAAM,SAAS,IAAI,cAAY,EAAE,GAAG,SAAS,MAAM,QAAQ,SAAS,UAAU,KAAK,QAAQ,MAAM,OAAO,GAAG,EAAE;AAAA,IACvH,GAAI,iBAAiB,EAAE,QAAQ,IAAI,CAAC;AAAA,EACtC;AACF;",
6
6
  "names": ["spawn", "executable", "spawn"]
7
7
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "schema": 1,
3
- "commit": "ddf6e54e590aa3963fa0e67f98ef41ce1f02f19c",
3
+ "commit": "9d9878f889774c1e7f2f7f95eb0580cf5b4eb648",
4
4
  "dirty": false,
5
- "productDigest": "00251d71dc180e03ce10bd7cdc88054003826def31b8b8a711e87d97a2685468"
5
+ "productDigest": "2f5df902390332f13e2fd9a37c3293a20544dc1d782fbbaf1e9faff8bc106826"
6
6
  }
package/dist/index.js CHANGED
@@ -867,8 +867,10 @@ var ElectronBridge = class extends EventEmitter {
867
867
  this.send({ type: "snapshot", snapshot: desktopSnapshot(snapshot, key !== this.resultKey) });
868
868
  this.resultKey = key;
869
869
  }
870
- notify(notice) {
871
- this.send({ type: "notice", notice });
870
+ notify(notice, runtime) {
871
+ if (!this.child?.connected || this.closing) return false;
872
+ if (runtime && (!this.nativeVisible || this.suspended || runtime.generation !== this.generation || runtime.visibilityRevision !== this.visibilityRevision || !runtime.visible)) return false;
873
+ return this.send({ type: "notice", notice, ...runtime ? { generation: runtime.generation, visibilityRevision: runtime.visibilityRevision } : {} });
872
874
  }
873
875
  notificationState(snapshot) {
874
876
  this.lastNotificationState = structuredClone(snapshot);
@@ -878,9 +880,7 @@ var ElectronBridge = class extends EventEmitter {
878
880
  this.send({ type: "notification-snooze-result", interactionId: interactionId2, ok, ...error ? { error: error.slice(0, 600) } : {} });
879
881
  }
880
882
  presentRole(notice, runtime) {
881
- if (!this.child?.connected || this.closing || !this.nativeVisible || this.suspended || runtime.generation !== this.generation || runtime.visibilityRevision !== this.visibilityRevision || !runtime.visible) return false;
882
- this.send({ type: "notice", notice, generation: runtime.generation, visibilityRevision: runtime.visibilityRevision });
883
- return true;
883
+ return this.notify(notice, runtime);
884
884
  }
885
885
  chatResult(receipt) {
886
886
  this.send(receipt);
@@ -912,9 +912,15 @@ var ElectronBridge = class extends EventEmitter {
912
912
  }
913
913
  send(message) {
914
914
  const child = this.child;
915
- if (child?.connected && !this.closing) child.send(message, (error) => {
916
- if (error && this.child === child && !this.closing) this.emit("failure", error);
917
- });
915
+ if (!child?.connected || this.closing) return false;
916
+ try {
917
+ child.send(message, (error) => {
918
+ if (error && this.child === child && !this.closing) this.emit("failure", error);
919
+ });
920
+ return true;
921
+ } catch {
922
+ return false;
923
+ }
918
924
  }
919
925
  async dispose() {
920
926
  this.closing = true;
@@ -1343,6 +1349,24 @@ var PetControls = class {
1343
1349
  configure() {
1344
1350
  this.bridge.configure?.(this.options());
1345
1351
  }
1352
+ /**
1353
+ * Relay a host-authored hint to the pet as a toast. Delivery is best-effort:
1354
+ * it needs a running, visible, awake pet with notices enabled. The result is
1355
+ * whether the Host handed the message to the native IPC channel after its own
1356
+ * generation/visibility check; the native window re-checks and may still drop
1357
+ * it, so true never means the user saw it. Task notices, session replies and
1358
+ * delivery claims stay owned by the broker; a hint can never fabricate them.
1359
+ * Session ids are navigation identity: they are validated but never rewritten.
1360
+ */
1361
+ hint(value) {
1362
+ if (this.disposed || !this.options().notifications) return false;
1363
+ if (this.state.phase !== "running" || !this.state.visible || this.state.suspended) return false;
1364
+ const title2 = hintText(value.title, 256), body2 = hintText(value.body, 2048);
1365
+ if (!title2) return false;
1366
+ const sessionId = hintSessionId(value.sessionId);
1367
+ if (sessionId === false) return false;
1368
+ return this.bridge.notify({ title: title2, body: body2, sessionId: sessionId ?? "", kind: "message" }, this.status());
1369
+ }
1346
1370
  command(command) {
1347
1371
  if (command === "hide") this.set({ ...this.state, desiredVisible: false });
1348
1372
  else if (command === "start" || command === "show" || command === "characters") this.set({ ...this.state, desiredVisible: true });
@@ -1498,6 +1522,14 @@ var PetControls = class {
1498
1522
  return pending;
1499
1523
  }
1500
1524
  };
1525
+ function hintText(value, limit) {
1526
+ return String(value ?? "").replace(/\s+/g, " ").trim().slice(0, limit);
1527
+ }
1528
+ function hintSessionId(value) {
1529
+ if (value === void 0 || value === null) return void 0;
1530
+ if (typeof value !== "string" || value.length > 2048 || !value.trim()) return false;
1531
+ return value;
1532
+ }
1501
1533
 
1502
1534
  // src/index.ts
1503
1535
  import { z as wire } from "zod";