@jini-ai/desktop-host 0.7.3-next.2 → 0.7.3-next.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.
- package/README.md +217 -1
- package/dist/electron/electron-shell.js +5 -7
- package/dist/electron/handoff/index.d.ts +54 -0
- package/dist/electron/handoff/index.js +32 -0
- package/dist/electron/memory-sampler.d.ts +28 -0
- package/dist/electron/memory-sampler.js +41 -0
- package/dist/electron/partitions/cache-maintenance.d.ts +280 -0
- package/dist/electron/partitions/cache-maintenance.js +239 -0
- package/dist/electron/partitions/claim-sources.d.ts +54 -0
- package/dist/electron/partitions/claim-sources.js +36 -0
- package/dist/electron/partitions/holder-registry.d.ts +116 -0
- package/dist/electron/partitions/holder-registry.js +130 -0
- package/dist/electron/partitions/index.d.ts +10 -0
- package/dist/electron/partitions/index.js +10 -0
- package/dist/electron/partitions/maintenance-marker.d.ts +61 -0
- package/dist/electron/partitions/maintenance-marker.js +85 -0
- package/dist/electron/partitions/partition-inventory.d.ts +23 -0
- package/dist/electron/partitions/partition-inventory.js +19 -0
- package/dist/electron/partitions/partition-pass.d.ts +114 -0
- package/dist/electron/partitions/partition-pass.js +414 -0
- package/dist/electron/partitions/partition-root.d.ts +42 -0
- package/dist/electron/partitions/partition-root.js +52 -0
- package/dist/electron/partitions/profile-interlock.d.ts +141 -0
- package/dist/electron/partitions/profile-interlock.js +273 -0
- package/dist/electron/partitions/retirement-ledger.d.ts +116 -0
- package/dist/electron/partitions/retirement-ledger.js +149 -0
- package/dist/electron/preferences/index.d.ts +5 -0
- package/dist/electron/preferences/index.js +5 -0
- package/dist/electron/preferences/ipc.d.ts +35 -0
- package/dist/electron/preferences/ipc.js +21 -0
- package/dist/electron/preferences/menu.d.ts +103 -0
- package/dist/electron/preferences/menu.js +67 -0
- package/dist/electron/preferences/preference-file.d.ts +63 -0
- package/dist/electron/preferences/preference-file.js +51 -0
- package/dist/electron/preferences/values.d.ts +25 -0
- package/dist/electron/preferences/values.js +18 -0
- package/dist/electron/preload/index.d.ts +3 -0
- package/dist/electron/preload/index.js +2 -0
- package/dist/electron/preload/ipc-subscribe.d.ts +34 -0
- package/dist/electron/preload/ipc-subscribe.js +18 -0
- package/dist/electron/selftest/index.d.ts +3 -0
- package/dist/electron/selftest/index.js +3 -0
- package/dist/electron/selftest/selftest-tracker.d.ts +82 -0
- package/dist/electron/selftest/selftest-tracker.js +67 -0
- package/dist/electron/session-bootstrap/exchange.d.ts +50 -0
- package/dist/electron/session-bootstrap/exchange.js +41 -0
- package/dist/electron/session-bootstrap/header-arming.d.ts +18 -0
- package/dist/electron/session-bootstrap/header-arming.js +13 -0
- package/dist/electron/session-bootstrap/index.d.ts +11 -0
- package/dist/electron/session-bootstrap/index.js +10 -0
- package/dist/electron/session-bootstrap/partition.d.ts +17 -0
- package/dist/electron/session-bootstrap/partition.js +24 -0
- package/dist/electron/session-bootstrap/probe.d.ts +40 -0
- package/dist/electron/session-bootstrap/probe.js +29 -0
- package/dist/electron/session-bootstrap/types.d.ts +62 -0
- package/dist/electron/session-bootstrap/types.js +7 -0
- package/dist/electron/updates/desktop-updater.d.ts +90 -0
- package/dist/electron/updates/desktop-updater.js +124 -0
- package/dist/electron/updates/index.d.ts +4 -0
- package/dist/electron/updates/index.js +4 -0
- package/dist/electron/updates/instance-presence-strict.d.ts +27 -0
- package/dist/electron/updates/instance-presence-strict.js +46 -0
- package/dist/electron/updates/native-notices.d.ts +89 -0
- package/dist/electron/updates/native-notices.js +41 -0
- package/dist/electron/updates/update-check-now.d.ts +117 -0
- package/dist/electron/updates/update-check-now.js +88 -0
- package/dist/electron/usability/find-in-page-ipc.d.ts +3 -6
- package/dist/electron/usability/window-bounds-store.js +14 -12
- package/dist/electron/usability/zoom-menu.d.ts +1 -1
- package/dist/electron/webview/index.d.ts +2 -0
- package/dist/electron/webview/index.js +2 -0
- package/dist/electron/webview/webview-types.d.ts +66 -0
- package/dist/electron/webview/webview-types.js +12 -0
- package/dist/electron/windows/app-window.d.ts +83 -0
- package/dist/electron/windows/app-window.js +62 -0
- package/dist/electron/windows/dock-icon.d.ts +34 -0
- package/dist/electron/windows/dock-icon.js +32 -0
- package/dist/electron/windows/index.d.ts +3 -0
- package/dist/electron/windows/index.js +3 -0
- package/dist/logging.js +3 -1
- package/dist/node-toolchain/boot-setup.d.ts +63 -0
- package/dist/node-toolchain/boot-setup.js +59 -0
- package/dist/node-toolchain/index.d.ts +2 -0
- package/dist/node-toolchain/index.js +1 -0
- package/dist/shell/auto-update-controller.d.ts +34 -0
- package/dist/shell/auto-update-controller.js +27 -0
- package/dist/shell/copied-site-databases.d.ts +71 -0
- package/dist/shell/copied-site-databases.js +60 -0
- package/dist/shell/find-in-page-verify.d.ts +33 -0
- package/dist/shell/find-in-page-verify.js +30 -0
- package/dist/shell/find-menu.d.ts +33 -0
- package/dist/shell/find-menu.js +36 -0
- package/dist/shell/guest-navigation.d.ts +47 -0
- package/dist/shell/guest-navigation.js +58 -0
- package/dist/shell/instance-presence.d.ts +20 -0
- package/dist/shell/instance-presence.js +26 -0
- package/dist/shell/js-backslide-guard.d.ts +42 -0
- package/dist/shell/js-backslide-guard.js +44 -0
- package/dist/shell/node-toolchain.d.ts +34 -0
- package/dist/shell/node-toolchain.js +50 -0
- package/dist/shell/pty-helpers.d.ts +25 -0
- package/dist/shell/pty-helpers.js +50 -0
- package/dist/shell/site-presence.d.ts +32 -0
- package/dist/shell/site-presence.js +42 -0
- package/dist/shell/speech/mac-on-device-transcriber.d.ts +24 -0
- package/dist/shell/speech/mac-on-device-transcriber.js +81 -0
- package/dist/shell/speech/speech-ipc.d.ts +52 -0
- package/dist/shell/speech/speech-ipc.js +40 -0
- package/dist/shell/spellcheck-menu.d.ts +84 -0
- package/dist/shell/spellcheck-menu.js +63 -0
- package/dist/shell/supervised-site-url.d.ts +20 -0
- package/dist/shell/supervised-site-url.js +22 -0
- package/dist/speech/macos/mac-on-device-transcriber.d.ts +2 -1
- package/dist/speech/speech-bridge.d.ts +1 -8
- package/dist/speech/transcription-port.d.ts +1 -9
- package/dist/tauri/tauri-shell.js +8 -10
- package/package.json +153 -6
package/README.md
CHANGED
|
@@ -119,7 +119,8 @@ before calling through. The ports are small: `SingleInstanceLockPort` is just `c
|
|
|
119
119
|
| `./tauri` | The full Tauri assembly + per-port factories + fakes. `createTauriRenderService` throws `NotImplementedError`. | none — the Tauri API is injected, not imported |
|
|
120
120
|
| `./shutdown` | Pending teardown tracking, quit/drain decisions and signal routing. | none |
|
|
121
121
|
| `./electron/navigation-policy` | Window/renderer origin boundaries and guest admission. | none |
|
|
122
|
-
| `./electron/updates` | Updater policy/controller and file-backed multi-instance presence. | none |
|
|
122
|
+
| `./electron/updates` | Updater policy/controller, the manual "Check for updates" (`createUpdateCheckNow`) and file-backed multi-instance presence. | none |
|
|
123
|
+
| `./electron/preferences` | JSON preference reads/writes through an injected durable-file port, bounded/choice values, save-before-apply native checkbox and radio items with in-place refresh, and a trusted preference IPC pair. | none |
|
|
123
124
|
| `./node-toolchain` | Node/npm/npx shims and caller-named environment variables. | none |
|
|
124
125
|
| `./electron/usability` | Find, zoom, spelling menus and remembered bounds through host ports. | none |
|
|
125
126
|
| `./speech` | Transcription contracts, mono PCM/WAV encoding, validated IPC and preload bridge. | none |
|
|
@@ -189,8 +190,223 @@ The default Node timer adapter is also exported as `createNodeUpdateTimers()`. D
|
|
|
189
190
|
|
|
190
191
|
`UpdaterLike` and `NavigableContents` are unions with the existing object registration types, exported as `LegacyUpdaterLike` and `LegacyNavigableContents`. The legacy controller `now` callback and dependency-object timers/timing/messages also remain accepted during migration. Native `on` implementations have two parameters (or a rest tuple); the old object registration has one. Custom one-parameter native updater facades should use `createElectronUpdaterAdapter`. Popup-only contents receive a callable handler that also supports the old `{ handler }` destructuring ABI. Hosts can remove their registration wrappers when ready.
|
|
191
192
|
|
|
193
|
+
## Wiring
|
|
194
|
+
|
|
195
|
+
Window navigation, guest admission and remembered bounds have one implementation each, under
|
|
196
|
+
`./electron/navigation-policy` and `./electron/usability`; there are no `./shell/*` wrappers for them,
|
|
197
|
+
except `./shell/find-menu`, which only adapts Electron's positional window shape to `./electron/usability`'s Find menu.
|
|
198
|
+
`./shell/guest-navigation` builds on the same navigation-policy API.
|
|
199
|
+
|
|
200
|
+
- **Needs injected:** `openExternal`, the app origin or renderer file URL, an `isSupervisedGuestUrl` /
|
|
201
|
+
`isAllowedSource` predicate, the guest `preloadPath`, and for bounds a `BoundsStorePort`
|
|
202
|
+
(`read`/`write` keyed by path), the bounds file name and a `joinPath`.
|
|
203
|
+
- **Provides:** popup/navigation/redirect boundaries, the sender check `isShellPageUrl`
|
|
204
|
+
(attach-mode origin as the second argument), guest preference hardening that throws the
|
|
205
|
+
missing-preload diagnostic, and bounds read/validate/write with the on-screen check.
|
|
206
|
+
- **Never imports:** `electron`, `node:fs` or host paths; the host owns storage and file location.
|
|
207
|
+
|
|
208
|
+
```ts
|
|
209
|
+
import { installAppWindowNavigationPolicy, applyGuestWebPreferences } from '@jini-ai/desktop-host/electron/navigation-policy';
|
|
210
|
+
import { readWindowBounds, resolveWindowBounds, windowBoundsFilePath } from '@jini-ai/desktop-host/electron/usability';
|
|
211
|
+
|
|
212
|
+
installAppWindowNavigationPolicy({ contents: win.webContents, appOrigin, openExternal: ({ url }) => shell.openExternal(url) });
|
|
213
|
+
contents.on('will-attach-webview', (_e, webPreferences) => applyGuestWebPreferences({ webPreferences, preloadPath }));
|
|
214
|
+
const key = windowBoundsFilePath({ userDataDir, fileName: 'window-bounds.json', joinPath: ({ directory, filename }) => path.join(directory, filename) });
|
|
215
|
+
const bounds = resolveWindowBounds({ stored: readWindowBounds({ store: jsonStore, key }), displays: screen.getAllDisplays(), fallback });
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
### Wiring: manual update check and desktop preferences
|
|
219
|
+
|
|
220
|
+
- **Needs injected:** for `createUpdateCheckNow` (`./electron/updates`), the host's eligibility
|
|
221
|
+
(`isPackaged`, `skipReason`), the automatic-updates read, the controller's `readyVersion` and
|
|
222
|
+
`showReadyPrompt`, a lazy `loadUpdater`, `notify`/`log`, an `UpdateCheckCopy` (every notice's
|
|
223
|
+
words), a redacting `describeErrorForLog` and a `describeErrorMessage` (the failed check's text for
|
|
224
|
+
`copy.notice`; caught errors reach both raw); `registerUpdateCheckIpc` takes the host's channel.
|
|
225
|
+
For `./electron/preferences`, a `PreferenceFilePort` (`read`/`withLock`/`writeAtomic`), the file
|
|
226
|
+
path, keys, bounds, choices, channels, error codes, menu labels and an `onProblem` warning hook.
|
|
227
|
+
- **Provides:** one in-flight manual check (repeat clicks join it; look-only when automatic updates
|
|
228
|
+
are off), `isNetworkUpdateError`; key-level preference read/write that never overwrites unreadable
|
|
229
|
+
bytes, `persistedCheckbox`/`persistedRadioGroup` that restore the last saved state on a failed save,
|
|
230
|
+
`refreshRadioGroup`/`refreshCheckboxesByLabel`, and `registerPreferenceIpc` (sender check first).
|
|
231
|
+
- **Never imports:** `electron`, `node:fs`, host copy, host paths or channel names; menu composition
|
|
232
|
+
(which items sit in which menu) stays with the host.
|
|
233
|
+
|
|
234
|
+
```ts
|
|
235
|
+
import { createUpdateCheckNow, registerUpdateCheckIpc } from '@jini-ai/desktop-host/electron/updates';
|
|
236
|
+
import { persistedCheckbox, readPreferenceValue, writePreferenceValue } from '@jini-ai/desktop-host/electron/preferences';
|
|
237
|
+
|
|
238
|
+
const file = { read: readJsonFile, withLock: withFileLock, writeAtomic: writeJsonFileAtomic };
|
|
239
|
+
const auto = () => readPreferenceValue({ file, filePath, key: 'automaticUpdates', parse: ({ value }) => value !== false, fallback: true });
|
|
240
|
+
const item = persistedCheckbox({ label: copy.automaticUpdates, checked: auto(), onError,
|
|
241
|
+
save: ({ checked }) => writePreferenceValue({ file, filePath, key: 'automaticUpdates', value: checked }) });
|
|
242
|
+
const check = createUpdateCheckNow({ ...eligibility, automaticUpdates: auto, copy: hostUpdateCopy, describeErrorForLog, describeErrorMessage, notify, log });
|
|
243
|
+
registerUpdateCheckIpc({ ipcMain, channel: HOST_CHECK_FOR_UPDATES_CHANNEL, checkNow: check.checkNow });
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
### Wiring: desktop updater lifecycle and native update boxes
|
|
247
|
+
|
|
248
|
+
- **Needs injected:** for `createDesktopUpdater` (`./electron/updates`), `DesktopUpdaterPorts`:
|
|
249
|
+
the automatic-updates read/save, the host's `skipReason`, a lazy `loadNativeUpdater`, `quitIdle`,
|
|
250
|
+
a `createController` factory (normally `./shell/auto-update-controller` bound to the host's
|
|
251
|
+
controller inputs, read at start), the "Update ready" prompt and a `DesktopUpdaterReporter`
|
|
252
|
+
(`skipped`/`startFailed`; the host owns the log wording). For the native boxes, a
|
|
253
|
+
`NativeDialogPort` (Electron's `dialog`), a `WindowListPort` (`BrowserWindow`), an
|
|
254
|
+
`UpdateReadyPromptCopy`, an `OthersOpenCopy` and the notice's acknowledge label.
|
|
255
|
+
- **Provides:** one start in flight (repeat starts and a manual check join it), OFF that persists
|
|
256
|
+
first and then disables native downloads/installs, `finalQuitHeldForUpdate` (held exactly when the
|
|
257
|
+
controller installs; never when the preference is off), `loadUpdaterForCheck` for
|
|
258
|
+
`createUpdateCheckNow`, and boxes parented to the focused window (Restart is button 0).
|
|
259
|
+
- **Never imports:** `electron`, a console, product copy, env names or the shell controller itself.
|
|
260
|
+
Architecture: [extraction-plan](../../ADS-memory/reports/jini-port/extraction-plan.md).
|
|
261
|
+
|
|
262
|
+
```ts
|
|
263
|
+
import { createDesktopUpdater, promptUpdateReady } from '@jini-ai/desktop-host/electron/updates';
|
|
264
|
+
import { createAutoUpdateController } from '@jini-ai/desktop-host/shell/auto-update-controller';
|
|
265
|
+
|
|
266
|
+
const updater = createDesktopUpdater({ ports: { automaticUpdates, saveAutomaticUpdates, skipReason, quitIdle,
|
|
267
|
+
loadNativeUpdater: async () => autoUpdater,
|
|
268
|
+
createController: ({ updater, promptUpdateReady }) => createAutoUpdateController({ ...controllerInputs(), updater, promptUpdateReady }),
|
|
269
|
+
promptUpdateReady: ({ version }) => promptUpdateReady({ dialog, windows: BrowserWindow, automaticUpdates, version, copy: readyCopy }),
|
|
270
|
+
reporter: { skipped: ({ reason }) => log(`updates off: ${reason}`), startFailed: ({ error }) => logError(error) } } });
|
|
271
|
+
updater.startInBackground();
|
|
272
|
+
app.on('before-quit', event => { if (updater.finalQuitHeldForUpdate()) event.preventDefault(); });
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
### Wiring: preload channel subscriber and `<webview>` types
|
|
276
|
+
|
|
277
|
+
- **Needs injected:** for `createPreloadSubscriber` (`./electron/preload`), a `PreloadIpcListenerPort`
|
|
278
|
+
(`on`/`removeListener`, args-object shaped) that passes `handler` through to Electron unchanged.
|
|
279
|
+
- **Provides:** a `PreloadSubscribe` that forwards only the payload (never the raw IPC event and its
|
|
280
|
+
`sender`) and returns a cleanup removing exactly that listener. `./electron/webview` provides
|
|
281
|
+
DOM-free structural types (`WebviewDidFailLoadDetail`, `WebviewFoundInPageDetail`, `WebviewTagMethods`, ...).
|
|
282
|
+
- **Stays with the host:** the channel allowlist (only fixed contract channels are ever subscribed),
|
|
283
|
+
`contextBridge` globals, and the `declare global` / JSX `webview` registration that combines these
|
|
284
|
+
types with `Event`/`HTMLElement`.
|
|
285
|
+
- **Never imports:** `electron`, React, or DOM lib types.
|
|
286
|
+
|
|
287
|
+
```ts
|
|
288
|
+
import { createPreloadSubscriber } from '@jini-ai/desktop-host/electron/preload';
|
|
289
|
+
|
|
290
|
+
const subscribe = createPreloadSubscriber({ ipcRenderer: {
|
|
291
|
+
on: ({ channel, handler }) => ipcRenderer.on(channel, handler),
|
|
292
|
+
removeListener: ({ channel, handler }) => ipcRenderer.removeListener(channel, handler),
|
|
293
|
+
} });
|
|
294
|
+
contextBridge.exposeInMainWorld('hostBridge', { onZoomCommand: ({ listener }) => subscribe({ channel: ZOOM_COMMAND_CHANNEL, listener }) });
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
Architecture: [extraction-plan.md](../../ADS-memory/reports/jini-port/extraction-plan.md).
|
|
298
|
+
|
|
299
|
+
### Wiring: boot-time toolchain setup and site-discovery lanes
|
|
300
|
+
|
|
301
|
+
- **Needs injected:** for `prepareNodeToolchainEnvBestEffort` (`./node-toolchain`), the host's bound
|
|
302
|
+
`writeNodeToolchain` (returns `null` for a transient launch, may throw), its bound
|
|
303
|
+
`buildNodeToolchainEnv` (which carries the host's own env-variable names) and a `report` sink for
|
|
304
|
+
`NodeToolchainSetupEvent`s. For `createSiteDiscoveryLanes`, the host's `discover({ scanRoots, signal })`.
|
|
305
|
+
- **Provides:** the toolchain env or `undefined`, never a throw; and `SiteDiscoveryLanes` whose rescan
|
|
306
|
+
and picker-validation lanes cancel only their own previous scan, with `abortAll` for before-quit.
|
|
307
|
+
A discoverer that throws synchronously rejects its scan instead of throwing into the boot path.
|
|
308
|
+
- **Stays with the host:** boot-mode choice, user-data and toolchain paths, env-variable names, and the
|
|
309
|
+
warning copy for each setup event.
|
|
310
|
+
- **Never imports:** `electron`, `node:fs`, or a console/logging formatter.
|
|
311
|
+
|
|
312
|
+
```ts
|
|
313
|
+
import { createSiteDiscoveryLanes, prepareNodeToolchainEnvBestEffort } from '@jini-ai/desktop-host/node-toolchain';
|
|
314
|
+
|
|
315
|
+
const toolchainEnv = prepareNodeToolchainEnvBestEffort({ userDataDir, electronPath: process.execPath, npmRoot,
|
|
316
|
+
writeNodeToolchain, buildNodeToolchainEnv, report: (event) => warn({ message: hostWarningFor({ event }) }) });
|
|
317
|
+
const discovery = createSiteDiscoveryLanes({ discover: ({ scanRoots, signal }) => discoverSites({ scanRoots, signal }) });
|
|
318
|
+
app.on('before-quit', () => discovery.abortAll());
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
Architecture: [extraction-plan.md](../../ADS-memory/reports/jini-port/extraction-plan.md).
|
|
322
|
+
|
|
323
|
+
### Wiring: native shell bindings (Find menu, node toolchain, speech)
|
|
324
|
+
|
|
325
|
+
These `./shell/*` entries hold no policy of their own; each binds an existing entry to Electron's
|
|
326
|
+
positional shapes or to Node's real `fs`/`execFile`, and every product value is injected.
|
|
327
|
+
|
|
328
|
+
- **`./shell/find-menu`** (`nativeFindMenu`, `sendNativeFindToggle`) over `./electron/usability`'s
|
|
329
|
+
`findMenu`. **Needs injected:** the deployed toggle `channel` and the `{ menu, item }` labels.
|
|
330
|
+
- **`./shell/node-toolchain`** (`bindNodeToolchain`) over `./node-toolchain`. **Needs injected:** the
|
|
331
|
+
shim banner `generatedComment` and the two env names (`toolchainEnvName`, `npmRootEnvName`) that the
|
|
332
|
+
host's stdio launch resolver reads. Returns `{ writeNodeToolchain, buildNodeToolchainEnv,
|
|
333
|
+
buildNodeToolchainShims }`, the shape `prepareNodeToolchainEnvBestEffort` takes. Writes under
|
|
334
|
+
`<userDataDir>/node-toolchain/{bin,npm-cache,npm-prefix}`.
|
|
335
|
+
- **`./shell/speech/speech-ipc`** (`registerNativeSpeechIpc`, `buildDefaultTranscriptionPort`) and
|
|
336
|
+
**`./shell/speech/mac-on-device-transcriber`** (`createNativeMacTranscriptionPort`) over `./speech`
|
|
337
|
+
and `./speech/macos`. **Needs injected:** a `NativeSpeechHost` — the IPC `channelNamespace` (must
|
|
338
|
+
match the host's preload bridge), all IPC/transcription/helper error wording, and
|
|
339
|
+
`mac: { binaryPath, messages, tempFilePrefix }`. The host computes `binaryPath` itself so its helper
|
|
340
|
+
cache never moves with this package's install location.
|
|
341
|
+
- **Stays with the host:** every channel name, env name, banner, label, message and path.
|
|
342
|
+
- **Never imports:** `electron` (structural ports only).
|
|
343
|
+
|
|
344
|
+
```ts
|
|
345
|
+
import { nativeFindMenu } from '@jini-ai/desktop-host/shell/find-menu';
|
|
346
|
+
import { bindNodeToolchain } from '@jini-ai/desktop-host/shell/node-toolchain';
|
|
347
|
+
import { registerNativeSpeechIpc } from '@jini-ai/desktop-host/shell/speech/speech-ipc';
|
|
348
|
+
|
|
349
|
+
const find = nativeFindMenu({ channel: FIND_TOGGLE_CHANNEL, labels: { menu: 'Find', item: 'Find in Page…' } });
|
|
350
|
+
const { writeNodeToolchain, buildNodeToolchainEnv } = bindNodeToolchain({ generatedComment, toolchainEnvName, npmRootEnvName });
|
|
351
|
+
registerNativeSpeechIpc({ ipcMain, isTrustedSender, host: speechHost });
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
### Wiring: Electron session bootstrap
|
|
355
|
+
|
|
356
|
+
- **Needs injected:** a `SessionNet` (Electron `net`), the partition's `Session` (`CookieJarSession` for
|
|
357
|
+
the cookie lookup, `HeaderArmingSession` for header arming), and every host value: URLs (already
|
|
358
|
+
guarded, e.g. loopback-only, before the call), the session cookie name, the partition prefix and
|
|
359
|
+
key, the header name/value, the outcome `label`, and a `describeError({ error })` that turns a raw
|
|
360
|
+
transport error into the outcome's `reason` text.
|
|
361
|
+
- **Provides:** `exchangeSessionJson` / `exchangeSessionRequest` (a request bound to the session's own
|
|
362
|
+
cookie jar via `useSessionCookies`, drained, resolving `SessionOutcome` only on `end` and never
|
|
363
|
+
rejecting for an HTTP or transport failure), `probeSession` (cookie-by-name cheap negative, then the
|
|
364
|
+
server's answer), `hasSessionCookie`, `persistentPartitionName`, and `armExactUrlHeader`.
|
|
365
|
+
- **Stays with the host:** endpoint paths, cookie/partition/header names, the URL guard and its refusal
|
|
366
|
+
copy, credential validation, and the probe-then-redeem policy.
|
|
367
|
+
- **Never imports:** `electron`, other `@jini-ai/*` implementations, or a logger.
|
|
368
|
+
|
|
369
|
+
```ts
|
|
370
|
+
import { exchangeSessionJson, probeSession, persistentPartitionName } from '@jini-ai/desktop-host/electron/session-bootstrap';
|
|
371
|
+
|
|
372
|
+
const partition = persistentPartitionName({ prefix: 'site-', key: path.resolve(siteDir) });
|
|
373
|
+
const jar = session.fromPartition(partition);
|
|
374
|
+
const origin = assertLoopback({ url: adminUrl });
|
|
375
|
+
const valid = await probeSession({ net, session: jar, url: new URL(ME_PATH, origin).href, cookieName: SESSION_COOKIE });
|
|
376
|
+
if (!valid) await exchangeSessionJson({ net, session: jar, url: new URL(REDEEM_PATH, origin).href, body: JSON.stringify({ token }), label: 'redeem', describeError: ({ error }) => error.message });
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
Architecture: [extraction-plan.md](../../ADS-memory/reports/jini-port/extraction-plan.md).
|
|
380
|
+
|
|
192
381
|
File logging uses core `Logger`; `error` in the optional bag is normalized into the JSON metadata alongside `meta`, consistently across all three levels.
|
|
193
382
|
|
|
383
|
+
### Wiring: standalone app window and dock icon
|
|
384
|
+
|
|
385
|
+
- **Needs injected:** for `createAppWindow` — the `url`, window `title`, `preloadPath` and an optional
|
|
386
|
+
`partition`, plus `AppWindowPorts` (`createBrowserWindow`, `installNavigationPolicy`) and an optional
|
|
387
|
+
self-test `trackWindow`; for `applyDockIcon` — `app.dock` (`DockIconPort`, `undefined` off macOS),
|
|
388
|
+
the icon path and a `reportFailure({ error })` reporter that receives the raw caught value.
|
|
389
|
+
- **Provides:** `appWindowOptions` (sandboxed, isolated, preload-bearing options; per-site partition
|
|
390
|
+
only when given) and `createAppWindow` (create, track, pin the title, install the boundary on the
|
|
391
|
+
URL's parsed origin, then load — that order is tested), and best-effort `applyDockIcon`.
|
|
392
|
+
- **Stays with the host:** the default title, icon asset, failure log copy and which navigation policy
|
|
393
|
+
to install (normally `installAppWindowNavigationPolicy` from `./electron/navigation-policy`).
|
|
394
|
+
- **Never imports:** `electron`, other `@jini-ai/*` implementations, `console` or a logger.
|
|
395
|
+
|
|
396
|
+
```ts
|
|
397
|
+
import { createAppWindow, applyDockIcon } from '@jini-ai/desktop-host/electron/windows';
|
|
398
|
+
import { installAppWindowNavigationPolicy } from '@jini-ai/desktop-host/electron/navigation-policy';
|
|
399
|
+
|
|
400
|
+
const win = createAppWindow({ url, title: siteName ?? APP_TITLE, preloadPath: PRELOAD, ports: {
|
|
401
|
+
createBrowserWindow: (options) => new BrowserWindow(options),
|
|
402
|
+
installNavigationPolicy: ({ contents, appOrigin }) =>
|
|
403
|
+
installAppWindowNavigationPolicy({ contents, appOrigin, openExternal: ({ url }) => void shell.openExternal(url) }),
|
|
404
|
+
} }, { partition, selftest, trackWindow: tracker?.add });
|
|
405
|
+
applyDockIcon({ dock: app.dock, iconPath: ICON, reportFailure: ({ error }) => log.warn({ message: 'dock icon not set' }, { error }) });
|
|
406
|
+
```
|
|
407
|
+
|
|
408
|
+
Architecture: [extraction-plan.md](../../ADS-memory/reports/jini-port/extraction-plan.md).
|
|
409
|
+
|
|
194
410
|
## Native speech runtime asset
|
|
195
411
|
|
|
196
412
|
`@jini-ai/desktop-host/speech/macos/speech-helper.swift` exports the Swift source used by the macOS speech adapter. The build copies it into `dist/speech/macos`; desktop hosts bundle or compile that source on macOS alongside the adapter. It is a required runtime asset, not a TypeScript entry.
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { orFallback } from '@jini-ai/core/errors/idioms';
|
|
1
2
|
import { stat } from 'node:fs/promises';
|
|
2
3
|
import { ShellError } from '../shell.js';
|
|
3
4
|
export function createElectronShellPort(surfaces) {
|
|
@@ -14,13 +15,10 @@ export function createElectronShellPort(surfaces) {
|
|
|
14
15
|
// calling `node:fs/promises` directly rather than adding a new structural Electron surface
|
|
15
16
|
// for a capability Electron's own main process didn't need mediating in the first place.
|
|
16
17
|
async dirExists({ path }) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
catch {
|
|
22
|
-
return false;
|
|
23
|
-
}
|
|
18
|
+
return orFallback({ work: async () => {
|
|
19
|
+
const info = await stat(path);
|
|
20
|
+
return info.isDirectory();
|
|
21
|
+
}, fallback: false, step: 'Check Electron directory' });
|
|
24
22
|
},
|
|
25
23
|
async recentDirs() {
|
|
26
24
|
return surfaces.app.getRecentDocuments();
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Main's half of a guest page's hand-off to a screen of the host's own app window: the page
|
|
3
|
+
* asks over an invoke channel, main checks the sender the way the host's other guest-facing
|
|
4
|
+
* channels do, brings the app window forward, and pushes the bounded request to its renderer.
|
|
5
|
+
* Channels, the payload parser and the refusal wording are the host's; this owns only the order.
|
|
6
|
+
*/
|
|
7
|
+
/** The slice of an app `BrowserWindow` the hand-off touches. */
|
|
8
|
+
export interface HandoffWindow<Payload> {
|
|
9
|
+
isMinimized(): boolean;
|
|
10
|
+
restore(): void;
|
|
11
|
+
show(): void;
|
|
12
|
+
focus(): void;
|
|
13
|
+
webContents: {
|
|
14
|
+
send(channel: string, payload: Payload): void;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/** `request` is invoked by the guest page; `open` is pushed to the app window's renderer. */
|
|
18
|
+
export interface HandoffChannels {
|
|
19
|
+
request: string;
|
|
20
|
+
open: string;
|
|
21
|
+
}
|
|
22
|
+
/** `opened: false` when no app window is open to show the requested screen. */
|
|
23
|
+
export interface HandoffResult {
|
|
24
|
+
opened: boolean;
|
|
25
|
+
}
|
|
26
|
+
/** The slice of Electron's `ipcMain` the hand-off registers on. */
|
|
27
|
+
export interface HandoffIpcMain {
|
|
28
|
+
handle(channel: string, handler: (event: {
|
|
29
|
+
senderFrame?: {
|
|
30
|
+
url?: unknown;
|
|
31
|
+
} | null;
|
|
32
|
+
} | undefined, raw: unknown) => HandoffResult): void;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Register once, app-wide, before any window can call it.
|
|
36
|
+
* @param required.isTrustedSender whether the calling frame's URL is a page this shell serves.
|
|
37
|
+
* @param required.windows the open app windows, read at call time; the first one is shown.
|
|
38
|
+
* @param required.parse turns the untrusted invoke argument into the bounded payload main forwards.
|
|
39
|
+
* @param required.senderRefused the error message an untrusted sender receives.
|
|
40
|
+
* @complexity O(w) in open app windows per request, plus `parse`.
|
|
41
|
+
*/
|
|
42
|
+
export declare function registerHandoffForwarding<Payload>({ ipcMain, isTrustedSender, windows, channels, parse, senderRefused }: {
|
|
43
|
+
ipcMain: HandoffIpcMain;
|
|
44
|
+
isTrustedSender: (required: {
|
|
45
|
+
senderUrl: string;
|
|
46
|
+
}) => boolean;
|
|
47
|
+
windows: () => readonly HandoffWindow<Payload>[];
|
|
48
|
+
channels: HandoffChannels;
|
|
49
|
+
parse: (required: {
|
|
50
|
+
raw: unknown;
|
|
51
|
+
}) => Payload;
|
|
52
|
+
senderRefused: string;
|
|
53
|
+
}, _optional?: Record<string, never>): void;
|
|
54
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Main's half of a guest page's hand-off to a screen of the host's own app window: the page
|
|
3
|
+
* asks over an invoke channel, main checks the sender the way the host's other guest-facing
|
|
4
|
+
* channels do, brings the app window forward, and pushes the bounded request to its renderer.
|
|
5
|
+
* Channels, the payload parser and the refusal wording are the host's; this owns only the order.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Register once, app-wide, before any window can call it.
|
|
9
|
+
* @param required.isTrustedSender whether the calling frame's URL is a page this shell serves.
|
|
10
|
+
* @param required.windows the open app windows, read at call time; the first one is shown.
|
|
11
|
+
* @param required.parse turns the untrusted invoke argument into the bounded payload main forwards.
|
|
12
|
+
* @param required.senderRefused the error message an untrusted sender receives.
|
|
13
|
+
* @complexity O(w) in open app windows per request, plus `parse`.
|
|
14
|
+
*/
|
|
15
|
+
export function registerHandoffForwarding({ ipcMain, isTrustedSender, windows, channels, parse, senderRefused }, _optional = {}) {
|
|
16
|
+
ipcMain.handle(channels.request, (event, raw) => {
|
|
17
|
+
const url = event?.senderFrame?.url;
|
|
18
|
+
if (typeof url !== "string" || !isTrustedSender({ senderUrl: url }))
|
|
19
|
+
throw new Error(senderRefused);
|
|
20
|
+
const window = windows()[0];
|
|
21
|
+
if (!window)
|
|
22
|
+
return { opened: false };
|
|
23
|
+
// An admin in its own window (or a minimized app) would otherwise change a screen nobody sees.
|
|
24
|
+
if (window.isMinimized())
|
|
25
|
+
window.restore();
|
|
26
|
+
window.show();
|
|
27
|
+
window.focus();
|
|
28
|
+
window.webContents.send(channels.open, parse({ raw }));
|
|
29
|
+
return { opened: true };
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/** Desktop OS adapter for the reviewed batched footprint read; no per-process probes. */
|
|
2
|
+
import type { ProcessPrivateMemory, ProcessUsage } from '@jini-ai/core/contracts/site/platform-process';
|
|
3
|
+
import { type ElectronProcessMemory } from './electron-process-memory.js';
|
|
4
|
+
import type { MemoryMetric, ResourceProcess } from "@jini-ai/core/contracts/site/contracts-resources";
|
|
5
|
+
/** Inject one bulk native read; null/missing/invalid readings keep that process's RSS. */
|
|
6
|
+
export type PrivateMemorySampler = (input: {
|
|
7
|
+
pids: readonly number[];
|
|
8
|
+
}, options?: object) => Promise<ProcessPrivateMemory>;
|
|
9
|
+
/** Usage preserves CPU/parent identity while carrying the selected memory source. */
|
|
10
|
+
export type MemoryUsage = ProcessUsage & {
|
|
11
|
+
memoryMetric: MemoryMetric;
|
|
12
|
+
rawRssBytes: number;
|
|
13
|
+
};
|
|
14
|
+
/** Native failure is per-memory-source: preserve the inventory and CPU counters for RSS fallback.
|
|
15
|
+
* @returns New usage rows with explicit source; never mutates the OS rows. O(p+e+r) time/space.
|
|
16
|
+
* @example await readDesktopMemory({ usages, platform: 'darwin', electronMetrics: [], samplePrivateMemory })
|
|
17
|
+
*/
|
|
18
|
+
export declare function readDesktopMemory({ usages, platform, electronMetrics, samplePrivateMemory }: {
|
|
19
|
+
usages: readonly ProcessUsage[];
|
|
20
|
+
platform: NodeJS.Platform;
|
|
21
|
+
electronMetrics: readonly ElectronProcessMemory[];
|
|
22
|
+
samplePrivateMemory: PrivateMemorySampler | undefined;
|
|
23
|
+
}, _options?: {}): Promise<MemoryUsage[]>;
|
|
24
|
+
/** A subtotal must expose fallback even if only one child failed; empty groups default to RSS. O(p) time/O(1) space. */
|
|
25
|
+
export declare function groupMemoryMetric({ processes }: {
|
|
26
|
+
processes: readonly ResourceProcess[];
|
|
27
|
+
}, _options?: {}): MemoryMetric;
|
|
28
|
+
//# sourceMappingURL=memory-sampler.d.ts.map
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { orFallback } from '@jini-ai/core/errors/idioms';
|
|
2
|
+
import { applyElectronMemoryReadings } from './electron-process-memory.js';
|
|
3
|
+
/** Electron privateBytes is committed memory on Windows. Other hosts keep OS RSS until a native reading succeeds.
|
|
4
|
+
* Invalid Electron readings never replace a usable RSS value. O(p+e) for p usages/e Electron metrics. */
|
|
5
|
+
function fallbackMemory({ usages, platform, electronMetrics }, _options = {}) {
|
|
6
|
+
const valid = platform === 'win32' ? electronMetrics.filter(row => validBytes(row.memory.privateBytes)) : [];
|
|
7
|
+
const committed = new Set(valid.map(row => row.pid));
|
|
8
|
+
return applyElectronMemoryReadings({ processes: usages.map(row => ({ ...row, rawRssBytes: row.rssBytes })), electronMetrics: valid }).map(row => ({ ...row,
|
|
9
|
+
memoryMetric: committed.has(row.pid) ? 'committed' : 'rss' }));
|
|
10
|
+
}
|
|
11
|
+
function validBytes(bytes) {
|
|
12
|
+
return typeof bytes === 'number' && Number.isSafeInteger(bytes) && bytes >= 0;
|
|
13
|
+
}
|
|
14
|
+
/** Native failure is per-memory-source: preserve the inventory and CPU counters for RSS fallback.
|
|
15
|
+
* @returns New usage rows with explicit source; never mutates the OS rows. O(p+e+r) time/space.
|
|
16
|
+
* @example await readDesktopMemory({ usages, platform: 'darwin', electronMetrics: [], samplePrivateMemory })
|
|
17
|
+
*/
|
|
18
|
+
export async function readDesktopMemory({ usages, platform, electronMetrics, samplePrivateMemory }, _options = {}) {
|
|
19
|
+
const fallback = fallbackMemory({ usages, platform, electronMetrics });
|
|
20
|
+
if (!samplePrivateMemory || !usages.length)
|
|
21
|
+
return fallback;
|
|
22
|
+
return orFallback({ work: async () => {
|
|
23
|
+
const native = await samplePrivateMemory({ pids: usages.map(row => row.pid) });
|
|
24
|
+
if (native.metric === 'unavailable')
|
|
25
|
+
return fallback;
|
|
26
|
+
const metric = native.metric;
|
|
27
|
+
const byPid = new Map(native.readings.map(row => [row.pid, row.bytes]));
|
|
28
|
+
return fallback.map(row => {
|
|
29
|
+
const bytes = byPid.get(row.pid);
|
|
30
|
+
return validBytes(bytes) ? { ...row, rssBytes: bytes, memoryMetric: metric } : row;
|
|
31
|
+
});
|
|
32
|
+
}, fallback, step: 'Read desktop private memory' });
|
|
33
|
+
}
|
|
34
|
+
/** A subtotal must expose fallback even if only one child failed; empty groups default to RSS. O(p) time/O(1) space. */
|
|
35
|
+
export function groupMemoryMetric({ processes }, _options = {}) {
|
|
36
|
+
const sources = new Set(processes.map(row => row.memoryMetric ?? 'rss'));
|
|
37
|
+
if (sources.size < 2)
|
|
38
|
+
return sources.values().next().value ?? 'rss';
|
|
39
|
+
return sources.has('rss') ? 'mixed-rss' : 'mixed';
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=memory-sampler.js.map
|