aegisone 1.0.57 → 1.0.59

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/README.md +4 -2
  2. package/package.json +3 -2
  3. package/scripts/predist.mjs +1 -1
  4. package/src/doctor.js +1 -1
  5. package/vendor/cli/README.md +2 -2
  6. package/vendor/cli/package.json +1 -1
  7. package/vendor/cli/src/app.js +1 -1
  8. package/vendor/cli/src/commands.js +2 -2
  9. package/vendor/cli/src/config.js +1 -1
  10. package/vendor/cli/src/panels.js +1 -1
  11. package/vendor/cli/vendor/client/model-autosync.js +3 -0
  12. package/vendor/cli/vendor/client/model-sync.js +3 -0
  13. package/vendor/cli/vendor/client/prefs.js +1 -1
  14. package/vendor/cli/vendor/client/skills.js +3 -0
  15. package/vendor/cli/vendor/client/speech.js +3 -0
  16. package/vendor/cli/vendor/desktop/lib/local/engine.js +1 -1
  17. package/vendor/cli/vendor/desktop/lib/local/integrity.js +1 -1
  18. package/vendor/cli/vendor/desktop/lib/local/sandbox-appcontainer.js +6 -6
  19. package/vendor/cli/vendor/desktop/lib/local/sandbox-bwrap.js +7 -7
  20. package/vendor/cli/vendor/desktop/lib/local/sandbox.js +17 -11
  21. package/vendor/cli/vendor/desktop/main.js +406 -2
  22. package/vendor/cli/vendor/one/src/iface/pty.js +3 -0
  23. package/vendor/cli/vendor/one/src/protocol.js +3 -0
  24. package/vendor/desktop/lib/local/cli-face.js +1 -1
  25. package/vendor/desktop/lib/local/engine.js +1 -1
  26. package/vendor/desktop/lib/local/integrity.js +1 -1
  27. package/vendor/desktop/lib/local/pty-host.js +3 -0
  28. package/vendor/desktop/lib/local/sandbox-appcontainer.js +6 -6
  29. package/vendor/desktop/lib/local/sandbox-bwrap.js +7 -7
  30. package/vendor/desktop/lib/local/sandbox.js +17 -11
  31. package/vendor/desktop/lib/skills-host.js +3 -0
  32. package/vendor/desktop/lib/speech-host.js +3 -0
  33. package/vendor/desktop/lib/speech-resolve.js +3 -0
  34. package/vendor/desktop/main.js +406 -2
  35. package/vendor/desktop/package.json +4 -3
  36. package/vendor/desktop/preload.js +1 -1
  37. package/vendor/desktop/renderer/app.js +3 -3
  38. package/vendor/desktop/renderer/avatar/avatar.css +29 -1
  39. package/vendor/desktop/renderer/avatar/pane.js +1 -1
  40. package/vendor/desktop/renderer/dictation.js +3 -0
  41. package/vendor/desktop/renderer/index.html +200 -2
  42. package/vendor/desktop/renderer/pty-panel.js +3 -0
  43. package/vendor/desktop/renderer/settings-skills.js +3 -0
  44. package/vendor/desktop/renderer/style.css +230 -0
  45. package/vendor/desktop/renderer/vendor/NOTICE.md +10 -2
  46. package/vendor/desktop/renderer/vendor/xterm.css +285 -0
  47. package/vendor/desktop/renderer/vendor/xterm.js +1 -0
  48. package/vendor/desktop/vendor/faces/cli/README.md +2 -2
  49. package/vendor/desktop/vendor/faces/cli/package.json +1 -1
  50. package/vendor/desktop/vendor/faces/cli/src/app.js +1 -1
  51. package/vendor/desktop/vendor/faces/cli/src/commands.js +2 -2
  52. package/vendor/desktop/vendor/faces/cli/src/config.js +1 -1
  53. package/vendor/desktop/vendor/faces/cli/src/panels.js +1 -1
  54. package/vendor/desktop/vendor/faces/cli/vendor/client/model-autosync.js +3 -0
  55. package/vendor/desktop/vendor/faces/cli/vendor/client/model-sync.js +3 -0
  56. package/vendor/desktop/vendor/faces/cli/vendor/client/prefs.js +1 -1
  57. package/vendor/desktop/vendor/faces/cli/vendor/client/skills.js +3 -0
  58. package/vendor/desktop/vendor/faces/cli/vendor/client/speech.js +3 -0
  59. package/vendor/desktop/vendor/faces/cli/vendor/desktop/lib/local/engine.js +1 -1
  60. package/vendor/desktop/vendor/faces/cli/vendor/desktop/lib/local/integrity.js +1 -1
  61. package/vendor/desktop/vendor/faces/cli/vendor/desktop/lib/local/sandbox-appcontainer.js +1 -1
  62. package/vendor/desktop/vendor/faces/cli/vendor/desktop/lib/local/sandbox-bwrap.js +1 -1
  63. package/vendor/desktop/vendor/faces/cli/vendor/desktop/lib/local/sandbox.js +1 -1
  64. package/vendor/desktop/vendor/faces/cli/vendor/desktop/main.js +3 -3
  65. package/vendor/desktop/vendor/faces/cli/vendor/one/src/iface/pty.js +3 -0
  66. package/vendor/desktop/vendor/faces/cli/vendor/one/src/protocol.js +3 -0
  67. package/vendor/desktop/vendor/model-autosync.js +3 -0
  68. package/vendor/desktop/vendor/model-sync.js +3 -0
  69. package/vendor/desktop/vendor/prefs.js +1 -1
  70. package/vendor/desktop/vendor/protocol.js +3 -0
  71. package/vendor/desktop/vendor/pty.js +3 -0
  72. package/vendor/desktop/vendor/skills.js +3 -0
  73. package/vendor/desktop/vendor/speech.js +3 -0
@@ -214,6 +214,35 @@ const creditsLib = (() => {
214
214
  return require('./vendor/credits.js');
215
215
  }
216
216
  })();
217
+ // Dictation (Settings → Dictation, and the composer's mic). `lib/speech-host.js`
218
+ // holds the three things that need a process (PATH probe, temp file, execFile);
219
+ // the decision itself is `client/speech.js`, shared with the terminal so the two
220
+ // faces cannot disagree about whether a microphone is on. Same two-layout
221
+ // resolution as every other shared module in this file.
222
+ const speechHost = require('./lib/speech-host.js');
223
+ // The skill registry (Settings → Skills). `client/skills.js` is the ONE scanner —
224
+ // `/skills` in the terminal reads the same module, so "what can this machine do"
225
+ // has one answer. `lib/skills-host.js` adds only the home/cwd pinning that a
226
+ // renderer must not be able to supply for itself.
227
+ const skillsHost = require('./lib/skills-host.js');
228
+
229
+ /**
230
+ * Read the shared `speech` preference, or `{}` when nobody has chosen.
231
+ *
232
+ * An absent value means OFF — `client/speech.js` `resolve()` requires an
233
+ * explicit `enabled: true`, so a fresh install never opens a microphone because
234
+ * it was upgraded. Never throws: a corrupt prefs file must not take the window
235
+ * down at boot, it must simply read as "dictation is off".
236
+ */
237
+ function readSpeechSettings(store) {
238
+ try {
239
+ if (!store || typeof store.getSharedPref !== 'function') return {};
240
+ const value = store.getSharedPref('speech');
241
+ return value && typeof value === 'object' && !Array.isArray(value) ? value : {};
242
+ } catch {
243
+ return {};
244
+ }
245
+ }
217
246
  // The LOCAL memory index (~/plan/agent-safety-plan.md §5). Rebuildable from the
218
247
  // cloud, never authoritative, and strictly best-effort: every call here is
219
248
  // wrapped because a dead index must not fail a save the cloud already accepted.
@@ -323,6 +352,13 @@ const DESKTOP_CLASSES = Object.freeze(['aegis', 'byok', 'local']);
323
352
  */
324
353
  const CHAT_DELTA_CHANNEL = `${IPC_PREFIX}chatDelta`;
325
354
 
355
+ /**
356
+ * ON9 — main -> renderer push channel for the embedded terminal panel's
357
+ * data/exit frames, tagged by session id the same way CHAT_DELTA_CHANNEL is
358
+ * (see createPtyIpc below and preload.js aegis.pty.onEvent).
359
+ */
360
+ const PTY_EVENT_CHANNEL = `${IPC_PREFIX}ptyEvent`;
361
+
326
362
  /** Main -> renderer pushes for native menu accelerators (Cmd/Ctrl+N,
327
363
  * Cmd/Ctrl+K) that have no Electron role to bind to — the renderer owns
328
364
  * "new chat" and "open search" behaviour, so the menu just asks for it. */
@@ -1754,6 +1790,50 @@ function createDevModeDispatch(settings) {
1754
1790
  };
1755
1791
  }
1756
1792
 
1793
+ /**
1794
+ * Model auto-sync: `aegis:getModelAutoSync` / `aegis:setModelAutoSync`.
1795
+ *
1796
+ * The switch for `client/model-autosync.js`. Same shape as
1797
+ * createConfirmModeDispatch and the same refusal rule: an explicit boolean is
1798
+ * required to change anything, so a malformed payload cannot turn a background
1799
+ * writer of `models.json` ON by accident. Off is the default and remains off
1800
+ * unless someone says so.
1801
+ *
1802
+ * `setModelAutoSync` writes the SHARED preference (`client/prefs.js`
1803
+ * `modelAutoSync`), not a host-local one, because both hosts run the same
1804
+ * scheduler: a machine whose window syncs but whose terminal does not would be
1805
+ * the drift that key exists to prevent.
1806
+ *
1807
+ * `getModelAutoSync` also reports what the scheduler last DID — an on/off
1808
+ * switch with no outcome beside it makes a preference that silently does
1809
+ * nothing indistinguishable from one that works.
1810
+ */
1811
+ function createModelAutoSyncDispatch(settings, engine) {
1812
+ if (!settings) throw new Error('createModelAutoSyncDispatch requires a settings store');
1813
+ return {
1814
+ getModelAutoSync: () => {
1815
+ const status = engine && typeof engine.modelAutoSyncStatus === 'function'
1816
+ ? engine.modelAutoSyncStatus()
1817
+ : { enabled: false };
1818
+ return { enabled: Boolean(status && status.enabled), status };
1819
+ },
1820
+ setModelAutoSync: (payload) => {
1821
+ const enabled = payload && payload.enabled;
1822
+ if (typeof enabled !== 'boolean') {
1823
+ const status = engine && typeof engine.modelAutoSyncStatus === 'function'
1824
+ ? engine.modelAutoSyncStatus()
1825
+ : { enabled: false };
1826
+ return { enabled: Boolean(status && status.enabled), status };
1827
+ }
1828
+ settings.setSharedPref('modelAutoSync', enabled);
1829
+ const status = engine && typeof engine.modelAutoSyncStatus === 'function'
1830
+ ? engine.modelAutoSyncStatus()
1831
+ : { enabled };
1832
+ return { enabled, status };
1833
+ },
1834
+ };
1835
+ }
1836
+
1757
1837
  /**
1758
1838
  * Plan mode: `aegis:getPermissionMode` / `aegis:setPermissionMode`. Same shape
1759
1839
  * as createConfirmModeDispatch, registered through the same generic
@@ -1976,6 +2056,66 @@ function createCliFaceDispatch(deps) {
1976
2056
  };
1977
2057
  }
1978
2058
 
2059
+ /**
2060
+ * ON9 — register the embedded terminal panel's five `aegis:pty*` handlers.
2061
+ *
2062
+ * Not routed through the generic `{name: handler}` wrapper the rest of this
2063
+ * file's settings-surface dispatches use (`registerConfirmModeIpc`): that
2064
+ * wrapper drops `event`, and `ptyExec` needs `event.sender` to push streamed
2065
+ * data/exit frames the same way `chatCompletion`'s streaming branch does
2066
+ * (see `registerIpc`'s special case above). The decision logic — what counts
2067
+ * as a capable pty backend, when to refuse rather than downgrade — lives
2068
+ * entirely in `lib/local/pty-host.js`; this function is the effects: probe
2069
+ * `node-pty`, build the host once, wire five channels to it.
2070
+ */
2071
+ function createPtyIpc(ipcMain, deps) {
2072
+ const d = deps || {};
2073
+ const hostMod = d.ptyHostModule || require('./lib/local/pty-host.js');
2074
+ const nodePty = d.nodePty !== undefined ? d.nodePty : hostMod.probeNodePty();
2075
+ const host = hostMod.createPtyHost({
2076
+ nativePty: Boolean(nodePty),
2077
+ appInfo: d.appInfo,
2078
+ spawnPty: nodePty
2079
+ ? (argv, opts) =>
2080
+ nodePty.spawn(argv[0], argv.slice(1), {
2081
+ name: 'xterm-color',
2082
+ cols: opts.cols || 80,
2083
+ rows: opts.rows || 24,
2084
+ cwd: opts.cwd || process.cwd(),
2085
+ // Merged, never replaced: `command.env` from cli-face.js's
2086
+ // innerCommand() carries only the ONE switch it adds
2087
+ // (ELECTRON_RUN_AS_NODE) on the bundled branch, not a full
2088
+ // environment — `opts.env || process.env` would have handed the
2089
+ // spawned process that single variable and nothing else (no
2090
+ // PATH, no HOME), the same bug Object.assign already avoids in
2091
+ // the external-terminal path above (openCliFace's spawnChild).
2092
+ env: Object.assign({}, process.env, opts.env || {}),
2093
+ })
2094
+ : undefined,
2095
+ });
2096
+
2097
+ ipcMain.handle(`${IPC_PREFIX}ptyHello`, (_event, payload) => host.hello((payload && payload.id) || 0));
2098
+ ipcMain.handle(`${IPC_PREFIX}ptyExec`, (event, payload) => {
2099
+ const p = payload || {};
2100
+ const sender = event && event.sender;
2101
+ const emit = (frame) => {
2102
+ if (sender && !sender.isDestroyed()) sender.send(PTY_EVENT_CHANNEL, frame);
2103
+ };
2104
+ return host.exec(p.id, p.params, emit);
2105
+ });
2106
+ ipcMain.handle(`${IPC_PREFIX}ptyWrite`, (_event, payload) => {
2107
+ const p = payload || {};
2108
+ return host.write(p.id, p.data);
2109
+ });
2110
+ ipcMain.handle(`${IPC_PREFIX}ptyResize`, (_event, payload) => {
2111
+ const p = payload || {};
2112
+ return host.resize(p.id, p.cols, p.rows);
2113
+ });
2114
+ ipcMain.handle(`${IPC_PREFIX}ptyCancel`, (_event, payload) => host.cancel((payload || {}).id));
2115
+
2116
+ return host;
2117
+ }
2118
+
1979
2119
  function createSandboxPolicyDispatch(settings, sandbox, opts) {
1980
2120
  if (!settings) throw new Error('createSandboxPolicyDispatch requires a settings store');
1981
2121
  const mod = sandbox || {};
@@ -2408,7 +2548,33 @@ function createEngine(aegis, { app, safeStorage, dir: dirOverride, sessionsDir:
2408
2548
  // never as `off`. `strict` is the user's own choice and lives beside the
2409
2549
  // policy; absent means degrade-loudly, because refusing every command on an
2410
2550
  // AppArmor-restricted host would brick the product rather than protect it.
2411
- sandbox: { policy: settings.getSandboxPolicy(), strict: false, appDir: __dirname },
2551
+ //
2552
+ // A GETTER, not a captured value — the same seam the terminal face passes
2553
+ // (`cli/src/engine.js`), for the same reason, and this host had the bug that
2554
+ // comment warns about. `resolveSandbox()` in engine.js reads `policy` once
2555
+ // per turn; capturing the store's value HERE meant it read whatever existed
2556
+ // at first-window creation and never again. The visible symptom was the
2557
+ // Settings › sandbox network switch: flipping "allow network from sandboxed
2558
+ // commands" wrote to disk, repainted the caption, and left the running
2559
+ // engine enforcing the OLD axis until the app was relaunched. On Linux that
2560
+ // looked like a stale sandbox; on macOS it read as "the network approval is
2561
+ // broken", because `sandbox-seatbelt.js` is the file that turns that axis
2562
+ // into `(deny network*)` and it was being handed a policy the user had
2563
+ // already changed. Windows had the identical staleness behind an
2564
+ // unimplemented mechanism, so the toggle could never have any effect there
2565
+ // either.
2566
+ //
2567
+ // Guarded because a staged settings store may predate the accessor — the
2568
+ // same shape `cli/src/engine.js` uses. A missing accessor answers null,
2569
+ // which `resolveSandbox()` reads as "no policy was requested", i.e. the
2570
+ // pre-existing unconfined turn, never as a permissive default.
2571
+ sandbox: {
2572
+ policy: () => (typeof settings.getSandboxPolicy === 'function'
2573
+ ? settings.getSandboxPolicy()
2574
+ : null),
2575
+ strict: false,
2576
+ appDir: __dirname,
2577
+ },
2412
2578
  // Stored /permissions rules (~/plan/agent-safety-plan.md §2). The rules live
2413
2579
  // in the SHARED data dir (~/.aegiscode/permissions.json), which is the same
2414
2580
  // file the terminal face writes via `/permissions allow|deny|ask`, so a rule
@@ -2831,6 +2997,26 @@ function createModelDispatch(engine, { env = process.env, settings } = {}) {
2831
2997
  'userModels.canDiscover': (payload) =>
2832
2998
  Boolean(engine.canDiscoverModels(payload && payload.provider)),
2833
2999
  'userModels.discoverable': () => engine.discoverableProviders(),
3000
+ // The reconciliation between what the vendors ISSUE and what AEGIS
3001
+ // promotes. The plan is read-only and carries no ids of its own: it is the
3002
+ // diff between `listModels('byok')`'s three layers and each vendor's own
3003
+ // list, so a Settings row can say "4 ids this vendor issues are not offered
3004
+ // here" instead of making the user diff two panels by eye.
3005
+ //
3006
+ // Apply is a SEPARATE message, and the renderer sends the plan it was shown:
3007
+ // the write is never inferred from the read, so opening Settings cannot add
3008
+ // rows to `models.json` as a side effect.
3009
+ 'userModels.syncPlan': (payload) => engine.modelSyncPlan(payload && payload.only),
3010
+ 'userModels.syncApply': (payload) =>
3011
+ engine.modelSyncApply(payload && payload.plan, payload && payload.only),
3012
+ // The auto-sync switch and what it last did. `syncStatus` is read-only and
3013
+ // cheap (it re-reads the preference and reports the throttle state); the
3014
+ // run message exists so Settings' "Sync now" does not have to wait for the
3015
+ // background clock — it is the same `runIfDue`, so pressing it while the
3016
+ // cadence is fresh correctly answers "throttled" instead of double-asking
3017
+ // every vendor.
3018
+ 'userModels.syncStatus': () => engine.modelAutoSyncStatus(),
3019
+ 'userModels.syncNow': (payload) => engine.modelAutoSyncRun(payload && payload.only),
2834
3020
  // Persisting memory ("sync finished turns to cloud memory automatically").
2835
3021
  // Reserved namespace, so it is invisible to the provider CRUD above — but
2836
3022
  // unlike a provider it IS reachable deliberately, through these two. The
@@ -3252,7 +3438,18 @@ function createSyncDispatch(sessions, dir, aegis, settingsDir, modelDispatch) {
3252
3438
  if (!modelDispatch || typeof modelDispatch.chat !== 'function') return null;
3253
3439
  try {
3254
3440
  const data = await modelDispatch.chat({
3255
- class: (payload && payload.class) || 'model',
3441
+ // 'aegis', not a made-up sentinel: the engine's dispatch() only
3442
+ // knows 'aegis' | 'byok' | 'local' | 'pro' and THROWS on anything
3443
+ // else (lib/local/engine.js `dispatch`). `payload.class` is empty
3444
+ // whenever the renderer's class <select> has not finished loading
3445
+ // yet — it starts with zero <option>s and is populated by an async
3446
+ // IPC round trip (app.js `loadClasses`) — which is exactly the
3447
+ // first turn of a fresh session, i.e. exactly when naming fires.
3448
+ // That throw was caught here and swallowed, so the naming round
3449
+ // silently failed and every title fell through to the crude local
3450
+ // derivation, permanently. 'aegis' matches the same empty-select
3451
+ // fallback app.js itself uses elsewhere (see `classId` there).
3452
+ class: (payload && payload.class) || 'aegis',
3256
3453
  model: payload && payload.model,
3257
3454
  prompt: text,
3258
3455
  system: opts.system,
@@ -5955,6 +6152,11 @@ function bootstrap() {
5955
6152
  // logging backgroundLaneLogs() gates below, aegis:get/setAccountUsername
5956
6153
  // persist the sign-in slug the panel checks to decide whether to show itself.
5957
6154
  registerConfirmModeIpc(ipcMain, createDevModeDispatch(settings));
6155
+ // Model auto-sync (Settings › Models): aegis:getModelAutoSync /
6156
+ // setModelAutoSync. The switch the background clock below obeys — registered
6157
+ // here, beside the other shared preferences, because that is where the
6158
+ // settings store lands.
6159
+ registerConfirmModeIpc(ipcMain, createModelAutoSyncDispatch(settings, engine));
5958
6160
 
5959
6161
  // Vault backend preference (Settings/the authorship panel → Google Drive /
5960
6162
  // AE / No sync): aegis:getVaultBackend / aegis:setVaultBackend. Registered
@@ -6003,6 +6205,22 @@ function bootstrap() {
6003
6205
  })
6004
6206
  );
6005
6207
 
6208
+ // ON9 — the same chip's OTHER outcome: the terminal face drawn INSIDE this
6209
+ // window instead of a second OS process, when `node-pty` (an
6210
+ // optionalDependency, same discipline as `electron` itself) resolves.
6211
+ // `createPtyIpc` probes it once at bootstrap; `aegis:ptyHello`'s caps tell
6212
+ // the renderer whether to open the embedded panel or fall back to the
6213
+ // `openCliFace` path above — that choice is the renderer's, not main's.
6214
+ createPtyIpc(ipcMain, {
6215
+ appInfo: {
6216
+ packaged: app.isPackaged,
6217
+ resourcesPath: process.resourcesPath,
6218
+ appDir: __dirname,
6219
+ execPath: process.execPath,
6220
+ nodePath: process.execPath,
6221
+ },
6222
+ });
6223
+
6006
6224
  // Funnel instrumentation (Phase 2 of docs/upgrade-conversion-plan.md):
6007
6225
  // aegis:telemetryEvent / aegis:telemetryReport, backed by
6008
6226
  // lib/local/telemetry.js.
@@ -6307,6 +6525,7 @@ function bootstrap() {
6307
6525
  // hold the process open, but an explicit quit should still cancel them
6308
6526
  // rather than let one land during teardown.
6309
6527
  if (updateManager && typeof updateManager.stop === 'function') updateManager.stop();
6528
+ stopModelAutoSync();
6310
6529
  });
6311
6530
 
6312
6531
  // Unload any local model this app warmed (engine.js `unloadLocalModels` ->
@@ -6359,6 +6578,53 @@ function bootstrap() {
6359
6578
  isPackaged: app.isPackaged,
6360
6579
  onStatus: broadcastUpdateStatus,
6361
6580
  });
6581
+
6582
+ // ── the model auto-sync clock ───────────────────────────────────────────
6583
+ //
6584
+ // `client/model-autosync.js` deliberately owns no timer: it decides WHEN a
6585
+ // sync is due, and the host supplies the clock. This is that clock.
6586
+ //
6587
+ // Design points that are deliberate, not incidental:
6588
+ //
6589
+ // · NOTHING runs until the preference is on. `runIfDue()` re-reads the
6590
+ // shared store on every call and answers `{ ran:false, reason:'off' }`
6591
+ // when nobody chose — so an upgrading machine makes zero vendor calls.
6592
+ // · The first attempt is delayed, not immediate: a launch should open a
6593
+ // window before it asks six vendors anything.
6594
+ // · The timer is unref'd, exactly like the update manager's, so a pending
6595
+ // tick can never be the reason the app refuses to quit.
6596
+ // · A sync that runs is broadcast to the window so a Settings panel can
6597
+ // show "2 models added" without polling.
6598
+ let modelAutoSyncTimer = null;
6599
+ function startModelAutoSync() {
6600
+ if (modelAutoSyncTimer) return;
6601
+ const tick = () => {
6602
+ Promise.resolve(engine.modelAutoSyncRun())
6603
+ .then((report) => {
6604
+ if (!report || !report.ran) return;
6605
+ if (report.added > 0 && typeof engine.refreshByokModels === 'function') {
6606
+ // The plan's writes land in `models.json`; the next turn reads that
6607
+ // file anyway, but the OPEN window's picker was built at load, so
6608
+ // it is told rather than left stale until a restart.
6609
+ try { engine.refreshByokModels(); } catch { /* the file is the truth */ }
6610
+ }
6611
+ for (const win of openWindows) {
6612
+ if (!win.isDestroyed()) win.webContents.send(`${IPC_PREFIX}modelSyncReport`, report);
6613
+ }
6614
+ })
6615
+ .catch(() => { /* the scheduler never rejects; this is belt and braces */ });
6616
+ };
6617
+ // Ten minutes after launch: long enough that a cold start is unaffected,
6618
+ // short enough that a long session still syncs the same day.
6619
+ const first = setTimeout(tick, 10 * 60 * 1000);
6620
+ if (typeof first.unref === 'function') first.unref();
6621
+ modelAutoSyncTimer = setInterval(tick, 6 * 60 * 60 * 1000);
6622
+ if (typeof modelAutoSyncTimer.unref === 'function') modelAutoSyncTimer.unref();
6623
+ }
6624
+ function stopModelAutoSync() {
6625
+ if (modelAutoSyncTimer) clearInterval(modelAutoSyncTimer);
6626
+ modelAutoSyncTimer = null;
6627
+ }
6362
6628
  registerUpdateIpc(ipcMain, updateManager);
6363
6629
  ipcMain.handle(`${IPC_PREFIX}accountStatus`, () => accountKey.status());
6364
6630
  // The renderer's report of whether Back/Forward would move (see app.js
@@ -6390,6 +6656,71 @@ function bootstrap() {
6390
6656
  // intentions and must never be one button that guesses.
6391
6657
  ipcMain.handle(`${IPC_PREFIX}driveBackupConversation`, (_event, payload) =>
6392
6658
  googleConnect.backupConversation({ sessionId: payload && payload.sessionId }));
6659
+ // ── Dictation (speech to text) ────────────────────────────────────────────
6660
+ // Four channels, all thin: the decision is client/speech.js and the work is
6661
+ // lib/speech-host.js. Nothing here holds a policy, and nothing here stores a
6662
+ // transcript or a recording.
6663
+ //
6664
+ // `speechStatus` is what the Settings card and the composer's mic button read.
6665
+ // It never throws: a machine with no whisper.cpp gets `{ enabled: false,
6666
+ // reason, install }`, which is the copy the card prints.
6667
+ ipcMain.handle(`${IPC_PREFIX}speechStatus`, () => {
6668
+ try {
6669
+ return speechHost.status({ settings: readSpeechSettings(settings) });
6670
+ } catch (e) {
6671
+ return { enabled: false, engine: 'none', reason: (e && e.message) || 'dictation status failed' };
6672
+ }
6673
+ });
6674
+ // `speechSet` writes the shared preference. The payload is picked apart field
6675
+ // by field rather than stored wholesale, so a renderer cannot drop extra keys
6676
+ // into the shared store — `client/prefs.js` refuses secrets, but shape is this
6677
+ // handler's job.
6678
+ ipcMain.handle(`${IPC_PREFIX}speechSet`, (_event, payload) => {
6679
+ try {
6680
+ const p = payload && typeof payload === 'object' ? payload : {};
6681
+ const current = readSpeechSettings(settings);
6682
+ const next = { ...current };
6683
+ if (typeof p.enabled === 'boolean') next.enabled = p.enabled;
6684
+ if (typeof p.engine === 'string') next.engine = p.engine === 'local' ? 'local' : 'none';
6685
+ if (typeof p.model === 'string') next.model = p.model.trim();
6686
+ if (typeof p.language === 'string') next.language = p.language.trim() || 'auto';
6687
+ if (p.maxSeconds != null && Number.isFinite(Number(p.maxSeconds))) {
6688
+ next.maxSeconds = Math.min(600, Math.max(5, Math.round(Number(p.maxSeconds))));
6689
+ }
6690
+ // Turning it on with no engine installed is refused here rather than in
6691
+ // the renderer: the card can be bypassed, and the invariant "enabled
6692
+ // implies a machine that can actually transcribe" is the one worth
6693
+ // holding. The user sees the same install hint either way.
6694
+ if (next.enabled === true) {
6695
+ const st = speechHost.status({ settings: { ...next, enabled: true } });
6696
+ if (!st.enabled) return { ok: false, ...st, settings: st.settings };
6697
+ }
6698
+ settings.setSharedPref('speech', next);
6699
+ return { ok: true, ...speechHost.status({ settings: next }) };
6700
+ } catch (e) {
6701
+ return { ok: false, error: (e && e.message) || 'could not save dictation settings' };
6702
+ }
6703
+ });
6704
+ // `speechTranscribe` takes the recorded bytes as a Buffer over the bridge and
6705
+ // answers `{ ok, text }` or `{ ok: false, reason }`. The temp file it needs is
6706
+ // created and removed inside lib/speech-host.js; the audio never leaves this
6707
+ // machine, which is asserted by client/speech.js's plan having no URL in it.
6708
+ ipcMain.handle(`${IPC_PREFIX}speechTranscribe`, (_event, payload) => {
6709
+ const p = payload && typeof payload === 'object' ? payload : {};
6710
+ return speechHost
6711
+ .transcribe(p.audio, { settings: readSpeechSettings(settings), ext: p.ext })
6712
+ .catch((e) => ({ ok: false, reason: (e && e.message) || 'transcription failed' }));
6713
+ });
6714
+ // ── Skills (Settings → Skills) ────────────────────────────────────────────
6715
+ // The window's list/create/remove. Same shared registry `/skills` reads, so a
6716
+ // skill made in the card appears in the terminal on the next scan and vice
6717
+ // versa. `home`/`cwd` are decided in lib/skills-host.js, never by the caller:
6718
+ // an IPC payload naming its own home would be an arbitrary-file-write.
6719
+ ipcMain.handle(`${IPC_PREFIX}skillsList`, () => skillsHost.list());
6720
+ ipcMain.handle(`${IPC_PREFIX}skillsRead`, (_event, payload) => skillsHost.read(payload || {}));
6721
+ ipcMain.handle(`${IPC_PREFIX}skillsCreate`, (_event, payload) => skillsHost.create(payload || {}));
6722
+ ipcMain.handle(`${IPC_PREFIX}skillsRemove`, (_event, payload) => skillsHost.remove(payload || {}));
6723
+ ipcMain.handle(`${IPC_PREFIX}skillsImport`, (_event, payload) => skillsHost.importFromUrl(payload || {}));
6393
6724
  registerExportIpc(
6394
6725
  ipcMain,
6395
6726
  sessionStore,
@@ -6565,6 +6896,75 @@ function bootstrap() {
6565
6896
  }
6566
6897
 
6567
6898
  app.whenReady().then(async () => {
6899
+ // ── Microphone permission (Settings → Dictation) ──────────────────────
6900
+ //
6901
+ // Electron grants NO web permission by default, so `getUserMedia({ audio:
6902
+ // true })` in the renderer rejects with NotAllowedError before any system
6903
+ // prompt is ever shown. That is the reason dictation was unreachable even
6904
+ // for someone with whisper.cpp installed: the feature worked and could not
6905
+ // be started.
6906
+ //
6907
+ // The handler below is deliberately narrow, and it is a SECURITY boundary,
6908
+ // not a convenience:
6909
+ //
6910
+ // · Only `media` is ever granted, and only to this app's own file://
6911
+ // renderer. Camera (`media` without the audio detail) is not reachable
6912
+ // from this product and is denied.
6913
+ // · Only the MAIN window gets it. The quick launcher is a separate
6914
+ // frameless window with no composer; a dictation grant there would be a
6915
+ // microphone nobody asked for.
6916
+ // · The DECISION about whether dictation may run at all stays in
6917
+ // `client/speech.js` — this handler says "the OS may prompt", it never
6918
+ // turns the feature on. Both gates must pass.
6919
+ //
6920
+ // `setPermissionCheckHandler` is registered alongside because a packaged
6921
+ // Electron build otherwise reports `navigator.permissions.query({name:
6922
+ // 'microphone'})` as denied even after the request handler granted it, and
6923
+ // the renderer's feature detection reads that answer.
6924
+ const isOwnRenderer = (url) => {
6925
+ if (typeof url !== 'string' || !url) return false;
6926
+ try {
6927
+ const parsed = new URL(url);
6928
+ if (parsed.protocol === 'file:') return true;
6929
+ // Dev runs load over http://localhost (electron . with a dev server).
6930
+ return /^(localhost|127\.0\.0\.1)$/.test(parsed.hostname);
6931
+ } catch {
6932
+ return false;
6933
+ }
6934
+ };
6935
+ const isMainWindowUrl = (webContents) => {
6936
+ if (!webContents || typeof webContents.getURL !== 'function') return false;
6937
+ const url = webContents.getURL();
6938
+ if (!isOwnRenderer(url)) return false;
6939
+ // The quick launcher loads quick.html; nothing in it records audio.
6940
+ return !/quick\.html(?:[?#]|$)/.test(url);
6941
+ };
6942
+ try {
6943
+ // `session` comes from the electron handle resolved above, not a top-level
6944
+ // require — this file must stay importable in plain Node so its pure
6945
+ // exports can be unit-tested without an Electron binary.
6946
+ const session = electron.session;
6947
+ session.defaultSession.setPermissionRequestHandler((webContents, permission, callback, details) => {
6948
+ if (permission !== 'media') return callback(false);
6949
+ if (!isMainWindowUrl(webContents)) return callback(false);
6950
+ // `details.mediaTypes` names what was asked for: ['audio'] for dictation.
6951
+ const types = (details && details.mediaTypes) || [];
6952
+ if (Array.isArray(types) && types.length && !types.includes('audio')) return callback(false);
6953
+ // Video is never requested by this product.
6954
+ if (Array.isArray(types) && types.includes('video')) return callback(false);
6955
+ return callback(true);
6956
+ });
6957
+ session.defaultSession.setPermissionCheckHandler((webContents, permission, requestingOrigin) => {
6958
+ if (permission !== 'media') return false;
6959
+ if (!isMainWindowUrl(webContents)) return false;
6960
+ return isOwnRenderer(requestingOrigin);
6961
+ });
6962
+ } catch (e) {
6963
+ // Never fatal: without a grant dictation reports "permission was denied"
6964
+ // in the card, which is a true sentence, and every other feature works.
6965
+ console.warn(`aegis: could not install the microphone permission handler: ${e && e.message}`);
6966
+ }
6967
+
6568
6968
  // Hydrate the client from the persisted key BEFORE the renderer issues any
6569
6969
  // status/model call, so class/model dropdowns populate immediately when a
6570
6970
  // key was saved in-app (safeStorage is usable only after app ready).
@@ -6696,6 +7096,7 @@ function bootstrap() {
6696
7096
  // its global shortcut only — never by starting the app.
6697
7097
  const win = createWindow();
6698
7098
  updateManager.start();
7099
+ startModelAutoSync();
6699
7100
  // Cold-launch deep link (Linux/Windows argv, or a pre-ready macOS
6700
7101
  // 'open-url'): the window didn't exist when it was parsed above, so
6701
7102
  // deliver it now that one does.
@@ -6763,6 +7164,8 @@ module.exports = {
6763
7164
  TOPUP_POLL_MS,
6764
7165
  TOPUP_POLL_TRIES,
6765
7166
  CHAT_DELTA_CHANNEL,
7167
+ PTY_EVENT_CHANNEL,
7168
+ createPtyIpc,
6766
7169
  MENU_NEW_CHAT_CHANNEL,
6767
7170
  MENU_SEARCH_CHANNEL,
6768
7171
  MENU_SEARCH_MEMORY_CHANNEL,
@@ -6813,6 +7216,7 @@ module.exports = {
6813
7216
  registerQuickLauncherIpc,
6814
7217
  createConfirmModeDispatch,
6815
7218
  createDevModeDispatch,
7219
+ createModelAutoSyncDispatch,
6816
7220
  createVaultBackendDispatch,
6817
7221
  createPermRulesDispatch,
6818
7222
  createSandboxPolicyDispatch,
@@ -0,0 +1,3 @@
1
+ // SPDX-License-Identifier: AGPL-3.0-or-later
2
+ // Copyright (C) 2026 Niklas Borneklint — AEGIS Code (aegiscode) / Aegiscloud.
3
+ "use strict";const path=require("node:path"),KIND=Object.freeze({PTY:"pty",PIPE:"pipe"}),CAP="pty",CODE=Object.freeze({UNSUPPORTED:"unsupported",NO_SPAWN:"no_spawn",BAD_DESC:"bad_desc"});function plan(n){const e=n||{};return"wasm"===e.target?{ok:!1,code:CODE.UNSUPPORTED,msg:"this target has no child processes: a WASM core cannot run exec"}:e.nativePty?{ok:!0,kind:KIND.PTY,cap:CAP,reason:"a PTY backend is available, so the child gets a real terminal"}:{ok:!0,kind:KIND.PIPE,cap:null,reason:"no PTY backend: stdio works, but resize, signals and line discipline do not"}}function caps(n){return n&&n.ok&&n.cap?[n.cap]:[]}function spawn(n,e,a){const s=a||{};if(!n||!n.ok)return{ok:!1,code:n&&n.code||CODE.UNSUPPORTED,msg:n&&n.msg||"no usable process plan"};const o=e||{},t=Array.isArray(o.argv)?o.argv.map(String):[];if(!t.length)return{ok:!1,code:CODE.BAD_DESC,msg:"exec needs a non-empty argv"};const c={cwd:o.cwd,env:o.env,cols:o.cols,rows:o.rows};return n.kind===KIND.PTY?"function"!=typeof s.spawnPty?{ok:!1,code:CODE.NO_SPAWN,msg:"pty was negotiated but no PTY spawner was injected"}:{ok:!0,kind:KIND.PTY,handle:s.spawnPty(t,c)}:"function"!=typeof s.spawnChild?{ok:!1,code:CODE.NO_SPAWN,msg:"no child-process spawner was injected"}:{ok:!0,kind:KIND.PIPE,handle:s.spawnChild(t,c)}}function sameCommand(n,e){return path.basename(String(n||""))===path.basename(String(e||""))}module.exports={KIND:KIND,CAP:CAP,CODE:CODE,plan:plan,caps:caps,spawn:spawn,sameCommand:sameCommand};
@@ -0,0 +1,3 @@
1
+ // SPDX-License-Identifier: AGPL-3.0-or-later
2
+ // Copyright (C) 2026 Niklas Borneklint — AEGIS Code (aegiscode) / Aegiscloud.
3
+ "use strict";const PROTO=1,METHODS=Object.freeze(["hello","exec","event","cancel"]),CAPS=Object.freeze({EXEC:"exec",EVENT:"event",CANCEL:"cancel",PTY:"pty"}),CODE=Object.freeze({BAD_JSON:"bad_json",BAD_FRAME:"bad_frame",UNKNOWN_METHOD:"unknown_method",PROTO_MISMATCH:"proto_mismatch",HELLO_REQUIRED:"hello_required",CAPABILITY_MISSING:"capability_missing",UNSUPPORTED:"unsupported"});function request(e,o,t){return{id:e,m:String(o),p:t&&"object"==typeof t?t:{}}}function ok(e,o){return{id:e,ok:!0,r:o&&"object"==typeof o?o:{}}}function err(e,o,t){return{id:e,ok:!1,e:{code:String(o||CODE.UNSUPPORTED),msg:String(t||"")}}}function isObject(e){return Boolean(e)&&"object"==typeof e&&!Array.isArray(e)}function validate(e){return isObject(e)?void 0===e.id||null===e.id?{ok:!1,code:CODE.BAD_FRAME,msg:"frame has no id"}:void 0!==e.ok?!0===e.ok?void 0!==e.e?{ok:!1,code:CODE.BAD_FRAME,msg:"reply carries both r and e"}:{ok:!0}:!1===e.ok?isObject(e.e)&&e.e.code?{ok:!0}:{ok:!1,code:CODE.BAD_FRAME,msg:"a failed reply must name a code"}:{ok:!1,code:CODE.BAD_FRAME,msg:"ok must be true or false"}:"string"==typeof e.m&&METHODS.includes(e.m)?void 0===e.p||isObject(e.p)?{ok:!0}:{ok:!1,code:CODE.BAD_FRAME,msg:"params must be an object"}:{ok:!1,code:CODE.UNKNOWN_METHOD,msg:`unknown method: ${String(e.m)}`}:{ok:!1,code:CODE.BAD_FRAME,msg:"frame must be an object"}}function negotiate(e,o){const t=o||{},r=validate(e);if(!r.ok)return{ok:!1,code:r.code,msg:r.msg};if("hello"!==e.m)return{ok:!1,code:CODE.HELLO_REQUIRED,msg:`the first frame must be hello, got ${String(e.m)}`};const n=e.p||{};if(1!==n.proto)return{ok:!1,code:CODE.PROTO_MISMATCH,msg:`peer speaks protocol ${String(n.proto)}, this build speaks 1`};const i=Array.isArray(n.caps)?n.caps.map(String):[],s=(Array.isArray(t.requireCaps)?t.requireCaps.map(String):[]).filter((e=>!i.includes(e)));return s.length?{ok:!1,code:CODE.CAPABILITY_MISSING,msg:`peer does not offer: ${s.join(", ")}`}:{ok:!0,proto:1,caps:i}}function hello(e){return request(void 0===e?0:e,"hello",{proto:1,caps:[CAPS.EXEC,CAPS.EVENT,CAPS.CANCEL]})}function encode(e){return`${JSON.stringify(e)}\n`}function decodeLine(e){const o=String(null==e?"":e).trim();if(!o)return{ok:!1,id:null,code:CODE.BAD_JSON,msg:"empty line"};let t;try{t=JSON.parse(o)}catch(e){return{ok:!1,id:null,code:CODE.BAD_JSON,msg:`not JSON: ${e.message}`}}const r=validate(t);return r.ok?{ok:!0,frame:t}:{ok:!1,id:isObject(t)&&void 0!==t.id?t.id:null,code:r.code,msg:r.msg}}function splitLines(e){const o=String(null==e?"":e).split("\n"),t=o.pop();return{lines:o.filter((e=>""!==e.trim())),rest:void 0===t?"":t}}module.exports={PROTO:1,METHODS:METHODS,CAPS:CAPS,CODE:CODE,request:request,ok:ok,err:err,hello:hello,validate:validate,negotiate:negotiate,encode:encode,decodeLine:decodeLine,splitLines:splitLines};
@@ -1,3 +1,3 @@
1
1
  // SPDX-License-Identifier: AGPL-3.0-or-later
2
2
  // Copyright (C) 2026 Niklas Borneklint — AEGIS Code (aegiscode) / Aegiscloud.
3
- "use strict";const path=require("node:path"),CLI_BIN="aegiscode",EMULATORS=Object.freeze({linux:[{cmd:"x-terminal-emulator",style:"-e"},{cmd:"gnome-terminal",style:"-e"},{cmd:"konsole",style:"-e"},{cmd:"xfce4-terminal",style:"-e"},{cmd:"mate-terminal",style:"-e"},{cmd:"lxterminal",style:"-e"},{cmd:"kitty",style:"--"},{cmd:"alacritty",style:"--"},{cmd:"xterm",style:"-e"}],darwin:[{cmd:"osascript",style:"termapp"}],win32:[{cmd:"wt.exe",style:"exec"},{cmd:"cmd.exe",style:"exec"}]}),VENDOR_FACE=Object.freeze(["vendor","faces","cli","bin",`${CLI_BIN}.js`]);function cliEntry({packaged:e,resourcesPath:t,appDir:r,entryExists:n}={}){if(e)return t?path.join(t,"faces","cli","bin",`${CLI_BIN}.js`):null;if(!r)return null;const c=path.join(r,...VENDOR_FACE);let a=!1;try{a=Boolean(n&&n(c))}catch{a=!1}return a?c:path.join(r,"..","cli","bin",`${CLI_BIN}.js`)}function isBundledEntry(e){return/[\\/]faces[\\/]cli[\\/]bin[\\/]/.test(String(e||""))}function cliArgv(e,t){const r=Array.isArray(t)?t.map(String):[];return e?[e,...r]:r}function pickEmulator({platform:e,exists:t,candidates:r}={}){const n=r||EMULATORS[e]||[];if(!n.length)return{ok:!1,reason:`no terminal emulator known for ${e||"this host"}`};for(const e of n){let r=!1;try{r=Boolean(t&&t(e.cmd))}catch{r=!1}if(r)return{ok:!0,emulator:e}}return{ok:!1,reason:`no terminal emulator found (tried ${n.map((e=>e.cmd)).join(", ")}) — run the command in the plan by hand`}}function emulatorArgv(e,t){const r=t&&t.exec||"",n=t&&t.args||[];if(!e||!r)return[];switch(e.style){case"-e":return["-e",r,...n];case"--":return["--",r,...n];case"exec":return"cmd.exe"===e.cmd?["/c","start",'""',r,...n]:[r,...n];default:return[r,...n]}}function macScript(e){return`tell application "Terminal"\n activate\n do script "${[e&&e.exec||"",...e&&e.args||[]].map((e=>shellQuote(e))).join(" ").replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"\nend tell`}function shellQuote(e){const t=String(null==e?"":e);return t?`'${t.replace(/'/g,"'\\''")}'`:"''"}function plan(e){const t=e||{},r=cliEntry(t);if(!r)return{ok:!1,reason:"could not locate the aegiscode entry point for this build",command:CLI_BIN};const n=Boolean(t.packaged)||isBundledEntry(r),c={exec:n?t.execPath:t.nodePath||"node",args:cliArgv(r,t.args)},a=n?{ELECTRON_RUN_AS_NODE:"1"}:void 0,l=[c.exec,...c.args].map((e=>shellQuote(e))).join(" "),o=pickEmulator({platform:t.platform,exists:t.exists,candidates:t.candidates});return o.ok?"termapp"===o.emulator.style?{ok:!0,exec:o.emulator.cmd,args:["-e",macScript(c)],env:a,command:l}:{ok:!0,exec:o.emulator.cmd,args:emulatorArgv(o.emulator,c),env:a,command:l}:{ok:!1,reason:o.reason,command:l}}module.exports={CLI_BIN:CLI_BIN,EMULATORS:EMULATORS,VENDOR_FACE:VENDOR_FACE,cliEntry:cliEntry,isBundledEntry:isBundledEntry,cliArgv:cliArgv,pickEmulator:pickEmulator,emulatorArgv:emulatorArgv,macScript:macScript,shellQuote:shellQuote,plan:plan};
3
+ "use strict";const path=require("node:path"),CLI_BIN="aegiscode",EMULATORS=Object.freeze({linux:[{cmd:"x-terminal-emulator",style:"-e"},{cmd:"gnome-terminal",style:"-e"},{cmd:"konsole",style:"-e"},{cmd:"xfce4-terminal",style:"-e"},{cmd:"mate-terminal",style:"-e"},{cmd:"lxterminal",style:"-e"},{cmd:"kitty",style:"--"},{cmd:"alacritty",style:"--"},{cmd:"xterm",style:"-e"}],darwin:[{cmd:"osascript",style:"termapp"}],win32:[{cmd:"wt.exe",style:"exec"},{cmd:"cmd.exe",style:"exec"}]}),VENDOR_FACE=Object.freeze(["vendor","faces","cli","bin",`${CLI_BIN}.js`]);function cliEntry({packaged:e,resourcesPath:t,appDir:n,entryExists:r}={}){if(e)return t?path.join(t,"faces","cli","bin",`${CLI_BIN}.js`):null;if(!n)return null;const a=path.join(n,...VENDOR_FACE);let c=!1;try{c=Boolean(r&&r(a))}catch{c=!1}return c?a:path.join(n,"..","cli","bin",`${CLI_BIN}.js`)}function isBundledEntry(e){return/[\\/]faces[\\/]cli[\\/]bin[\\/]/.test(String(e||""))}function cliArgv(e,t){const n=Array.isArray(t)?t.map(String):[];return e?[e,...n]:n}function pickEmulator({platform:e,exists:t,candidates:n}={}){const r=n||EMULATORS[e]||[];if(!r.length)return{ok:!1,reason:`no terminal emulator known for ${e||"this host"}`};for(const e of r){let n=!1;try{n=Boolean(t&&t(e.cmd))}catch{n=!1}if(n)return{ok:!0,emulator:e}}return{ok:!1,reason:`no terminal emulator found (tried ${r.map((e=>e.cmd)).join(", ")}) — run the command in the plan by hand`}}function emulatorArgv(e,t){const n=t&&t.exec||"",r=t&&t.args||[];if(!e||!n)return[];switch(e.style){case"-e":return["-e",n,...r];case"--":return["--",n,...r];case"exec":return"cmd.exe"===e.cmd?["/c","start",'""',n,...r]:[n,...r];default:return[n,...r]}}function macScript(e){return`tell application "Terminal"\n activate\n do script "${[e&&e.exec||"",...e&&e.args||[]].map((e=>shellQuote(e))).join(" ").replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"\nend tell`}function shellQuote(e){const t=String(null==e?"":e);return t?`'${t.replace(/'/g,"'\\''")}'`:"''"}function innerCommand(e){const t=e||{},n=cliEntry(t);if(!n)return{ok:!1,reason:"could not locate the aegiscode entry point for this build",command:CLI_BIN};const r=Boolean(t.packaged)||isBundledEntry(n),a=r?t.execPath:t.nodePath||"node",c=cliArgv(n,t.args),o=r?{ELECTRON_RUN_AS_NODE:"1"}:void 0,l=[a,...c].map((e=>shellQuote(e))).join(" ");return{ok:!0,exec:a,args:c,env:o,command:l}}function plan(e){const t=e||{},n=innerCommand(t);if(!n.ok)return n;const r=pickEmulator({platform:t.platform,exists:t.exists,candidates:t.candidates});return r.ok?"termapp"===r.emulator.style?{ok:!0,exec:r.emulator.cmd,args:["-e",macScript(n)],env:n.env,command:n.command}:{ok:!0,exec:r.emulator.cmd,args:emulatorArgv(r.emulator,n),env:n.env,command:n.command}:{ok:!1,reason:r.reason,command:n.command}}module.exports={CLI_BIN:CLI_BIN,EMULATORS:EMULATORS,VENDOR_FACE:VENDOR_FACE,cliEntry:cliEntry,isBundledEntry:isBundledEntry,cliArgv:cliArgv,pickEmulator:pickEmulator,emulatorArgv:emulatorArgv,macScript:macScript,shellQuote:shellQuote,innerCommand:innerCommand,plan:plan};