@nimiplatform/app-tools 0.13.1 → 0.16.0-rc.9

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 (100) hide show
  1. package/README.md +65 -8
  2. package/bin/nimi-app.mjs +26 -10
  3. package/lib/app-access-declaration.mjs +3 -0
  4. package/lib/app-dependency-combinations.mjs +70 -20
  5. package/lib/app-doctor-update.mjs +95 -36
  6. package/lib/app-host-support.mjs +6 -0
  7. package/lib/app-icons.mjs +181 -0
  8. package/lib/app-identifiers.mjs +27 -0
  9. package/lib/app-info.mjs +21 -33
  10. package/lib/app-lifecycle-guidance.mjs +2 -1
  11. package/lib/app-pack.mjs +14 -36
  12. package/lib/app-project-lifecycle.mjs +141 -243
  13. package/lib/app-scaffold-capabilities.mjs +13 -109
  14. package/lib/app-scaffold-profiles.mjs +108 -117
  15. package/lib/app-scaffold.mjs +70 -165
  16. package/lib/app-toolchain-updates.mjs +45 -0
  17. package/lib/canonical-capability-ids.generated.mjs +2 -0
  18. package/lib/development-environment.d.mts +10 -0
  19. package/lib/development-environment.mjs +39 -0
  20. package/lib/hosted-web-release.mjs +98 -0
  21. package/lib/index.mjs +40 -1
  22. package/lib/mobile-development.mjs +19 -0
  23. package/lib/realm-environments.generated.mjs +5 -0
  24. package/lib/web-coordination.mjs +59 -0
  25. package/lib/web-development.d.mts +23 -0
  26. package/lib/web-development.mjs +118 -0
  27. package/lib/web-scaffold.mjs +125 -0
  28. package/package.json +39 -27
  29. package/scripts/dev-shell.mjs +4 -1
  30. package/scripts/sync-scaffold-versions.mjs +0 -2
  31. package/skills/nimi-app-lifecycle/SKILL.md +13 -5
  32. package/skills/nimi-app-lifecycle/references/acceptance.md +6 -2
  33. package/skills/nimi-app-lifecycle/references/adapt.md +7 -3
  34. package/skills/nimi-app-lifecycle/references/audit.md +3 -2
  35. package/skills/nimi-app-lifecycle/references/create.md +8 -2
  36. package/skills/nimi-app-lifecycle/references/release.md +2 -0
  37. package/skills/nimi-app-lifecycle/references/upgrade-platform.md +15 -1
  38. package/templates/app-source/src/ai-studio-core/ai-studio-core.css +87 -52
  39. package/templates/app-source/src/ai-studio-core/history-policy.ts +45 -11
  40. package/templates/app-source/src/ai-studio-core/history.ts +22 -11
  41. package/templates/app-source/src/ai-studio-core/host-context.tsx +9 -4
  42. package/templates/app-source/src/ai-studio-core/index.ts +2 -0
  43. package/templates/app-source/src/ai-studio-core/job-recovery-panel.tsx +15 -5
  44. package/templates/app-source/src/ai-studio-core/job-recovery.ts +2 -2
  45. package/templates/app-source/src/ai-studio-core/messages/en.json +79 -19
  46. package/templates/app-source/src/ai-studio-core/messages/zh.json +79 -19
  47. package/templates/app-source/src/ai-studio-core/module-registration.ts +1 -0
  48. package/templates/app-source/src/ai-studio-core/non-success-presentation.ts +40 -5
  49. package/templates/app-source/src/ai-studio-core/parameter-fields.tsx +12 -6
  50. package/templates/app-source/src/ai-studio-core/parameters.ts +4 -0
  51. package/templates/app-source/src/ai-studio-core/prompt-drafts.ts +42 -0
  52. package/templates/app-source/src/ai-studio-core/runtime-types.ts +9 -2
  53. package/templates/app-source/src/ai-studio-core/runtime.ts +8 -4
  54. package/templates/app-source/src/ai-studio-core/section-ai-testing-composer.tsx +98 -90
  55. package/templates/app-source/src/ai-studio-core/section-ai-testing-exchange-result.tsx +1 -1
  56. package/templates/app-source/src/ai-studio-core/section-ai-testing-history.tsx +205 -48
  57. package/templates/app-source/src/ai-studio-core/section-ai-testing-input.ts +1 -0
  58. package/templates/app-source/src/ai-studio-core/section-ai-testing-output.tsx +36 -14
  59. package/templates/app-source/src/ai-studio-core/section-ai-testing-result.tsx +102 -77
  60. package/templates/app-source/src/ai-studio-core/section-ai-testing-run.ts +62 -16
  61. package/templates/app-source/src/ai-studio-core/section-ai-testing-session-result.tsx +2 -0
  62. package/templates/app-source/src/ai-studio-core/section-ai-testing-studio-result.tsx +12 -21
  63. package/templates/app-source/src/ai-studio-core/section-ai-testing-transcription-result.tsx +26 -9
  64. package/templates/app-source/src/ai-studio-core/section-ai-testing-vision-result.tsx +3 -3
  65. package/templates/app-source/src/ai-studio-core/section-ai-testing.tsx +182 -81
  66. package/templates/app-source/src/ai-studio-core/workspace.tsx +49 -22
  67. package/templates/app-source/src/product-modules/agent-center/index.tsx +2 -3
  68. package/templates/app-source/src/product-modules/agent-conversation/index.tsx +2 -3
  69. package/templates/app-source/src/studio-modules/studio-create/messages/en.json +17 -3
  70. package/templates/app-source/src/studio-modules/studio-create/messages/zh.json +17 -3
  71. package/templates/app-source/src/studio-modules/studio-create/parameter-panel.tsx +33 -1
  72. package/templates/app-source/src/studio-modules/studio-create/parameters.ts +3 -1
  73. package/templates/app-source/src/studio-modules/studio-create/runtime.ts +47 -4
  74. package/templates/app-source/src/studio-modules/studio-media/messages/en.json +59 -8
  75. package/templates/app-source/src/studio-modules/studio-media/messages/zh.json +59 -8
  76. package/templates/app-source/src/studio-modules/studio-media/music-parameters.tsx +2 -1
  77. package/templates/app-source/src/studio-modules/studio-media/parameter-panel.tsx +271 -83
  78. package/templates/app-source/src/studio-modules/studio-media/parameters.ts +120 -2
  79. package/templates/app-source/src/studio-modules/studio-media/registration.ts +1 -0
  80. package/templates/app-source/src/studio-modules/studio-media/runtime.ts +24 -14
  81. package/templates/app-source/src/studio-modules/studio-voice/descriptors.ts +1 -1
  82. package/templates/app-source/src/studio-modules/studio-voice/messages/en.json +3 -2
  83. package/templates/app-source/src/studio-modules/studio-voice/messages/zh.json +3 -2
  84. package/templates/app-source/src/studio-modules/studio-voice/parameter-panel.tsx +46 -23
  85. package/templates/app-source/src/studio-modules/studio-voice/registration.ts +2 -1
  86. package/templates/app-source/src/studio-modules/studio-voice/runtime.ts +2 -2
  87. package/templates/app-source/src/workbench-core/workbench-core.tsx +27 -3
  88. package/templates/default-starter/AGENTS.md +8 -5
  89. package/templates/default-starter/NIMI_APP.md +7 -0
  90. package/templates/default-starter/README.md +3 -1
  91. package/templates/default-starter/src/shell/App.tsx +12 -20
  92. package/templates/default-starter/src/shell/auth/local-app-client.ts +6 -15
  93. package/templates/default-starter/src/shell/auth/runtime-platform.ts +7 -107
  94. package/templates/default-starter/src/shell/workbench-target-adapter.ts +9 -126
  95. package/templates/default-starter.manifest.json +4 -16
  96. package/templates/hosted-web-release.yml +88 -0
  97. package/templates/default-starter/src-tauri/Cargo.toml +0 -17
  98. package/templates/default-starter/src-tauri/build.rs +0 -32
  99. package/templates/default-starter/src-tauri/capabilities/default.json +0 -7
  100. package/templates/default-starter/src-tauri/tauri.conf.json +0 -26
@@ -1,4 +1,6 @@
1
+ import { buildWebStarterFiles } from './web-scaffold.mjs';
1
2
  import path from 'node:path';
3
+ import { readFileSync } from 'node:fs';
2
4
 
3
5
  export const SUPPORTED_APP_SCAFFOLD_PROFILES = ['standalone'];
4
6
 
@@ -41,6 +43,7 @@ export function resolveWindowsResourceVersion(appVersion) {
41
43
  }
42
44
 
43
45
  export function buildDefaultStarterFiles(identity) {
46
+ if (identity.platform === 'web') return [...buildWebStarterFiles(identity, { productArea: renderDefaultProductArea(identity), navigation: renderDefaultAppNavigation() }), ...buildGeneratedModuleCompositionFiles(identity)];
44
47
  return [
45
48
  {
46
49
  path: 'src/main.tsx',
@@ -58,11 +61,6 @@ export function buildDefaultStarterFiles(identity) {
58
61
  mutationClass: 'app-owned product code',
59
62
  },
60
63
  ...buildGeneratedModuleCompositionFiles(identity),
61
- {
62
- path: 'src-tauri/src/main.rs',
63
- content: renderDefaultTauriMain(),
64
- mutationClass: 'scaffold-managed glue',
65
- },
66
64
  {
67
65
  path: 'src-electron/main.ts',
68
66
  content: renderDefaultElectronMain(identity),
@@ -78,6 +76,11 @@ export function buildDefaultStarterFiles(identity) {
78
76
  content: DEFAULT_ELECTRON_PRELOAD_BUNDLER,
79
77
  mutationClass: 'scaffold-managed glue',
80
78
  },
79
+ {
80
+ path: 'scripts/app-icons.mjs',
81
+ content: readFileSync(new URL('./app-icons.mjs', import.meta.url), 'utf8'),
82
+ mutationClass: 'scaffold-managed glue',
83
+ },
81
84
  {
82
85
  path: 'scripts/clean-electron-production.mjs',
83
86
  content: DEFAULT_ELECTRON_PRODUCTION_CLEANER,
@@ -109,10 +112,11 @@ const DEFAULT_VITE_CONFIG = [
109
112
  'export default defineConfig({',
110
113
  " base: './',",
111
114
  " cacheDir: '.vite',",
115
+ " optimizeDeps: { entries: ['index.html'] },",
112
116
  ' // The bootstrap creates the root once; only components participate in Fast Refresh.',
113
117
  " plugins: [react({ exclude: [/\\/node_modules\\//, /\\/src\\/main\\.tsx$/] }), tailwindcss()],",
114
118
  ' server: {',
115
- " watch: { ignored: ['**/.nimi/local/**', '**/dist/**', '**/dist-electron/**', '**/dist-electron-package/**'] },",
119
+ " watch: { ignored: ['**/.nimi/local/**', '**/dist/**', '**/dist-electron/**', '**/dist-electron-package/**', '**/dist-web/**', '**/dist-mobile/**', '**/android/**/build/**', '**/android/app/src/main/assets/public/**'] },",
116
120
  ' },',
117
121
  ' resolve: {',
118
122
  " dedupe: ['react', 'react-dom', 'react/jsx-runtime', 'react/jsx-dev-runtime'],",
@@ -131,10 +135,12 @@ const DEFAULT_ELECTRON_PRELOAD = [
131
135
 
132
136
  const DEFAULT_ELECTRON_PRELOAD_BUNDLER = [
133
137
  "import { build } from 'esbuild';",
138
+ "import { prepareElectronIcons } from './app-icons.mjs';",
134
139
  "import path from 'node:path';",
135
140
  "import { fileURLToPath } from 'node:url';",
136
141
  '',
137
142
  "const appRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');",
143
+ 'prepareElectronIcons(appRoot);',
138
144
  '',
139
145
  'await build({',
140
146
  " entryPoints: [path.join(appRoot, 'src-electron/preload.cts')],",
@@ -167,6 +173,7 @@ function renderDefaultElectronProductionPackager(identity) {
167
173
  "import path from 'node:path';",
168
174
  "import { fileURLToPath } from 'node:url';",
169
175
  "import { packager } from '@electron/packager';",
176
+ "import { prepareElectronIcons } from './app-icons.mjs';",
170
177
  "import { build } from 'esbuild';",
171
178
  "import { parse as parseYaml, stringify as stringifyYaml } from 'yaml';",
172
179
  '',
@@ -216,6 +223,7 @@ function renderDefaultElectronProductionPackager(identity) {
216
223
  'let packageCompleted = false;',
217
224
  '',
218
225
  'try {',
226
+ ' const icons = prepareElectronIcons(appRoot, { required: true });',
219
227
  ' await build({',
220
228
  " entryPoints: [path.join(appRoot, 'src-electron/main.ts')],",
221
229
  " outfile: path.join(appRoot, 'dist-electron/main.js'),",
@@ -247,6 +255,9 @@ function renderDefaultElectronProductionPackager(identity) {
247
255
  " await cp(path.join(appRoot, 'dist'), path.join(productionSourceRoot, 'dist'), { recursive: true, force: false });",
248
256
  " await copyFile(path.join(appRoot, 'dist-electron', 'main.js'), path.join(productionSourceRoot, 'dist-electron', 'main.js'));",
249
257
  " await copyFile(path.join(appRoot, 'dist-electron', 'preload.cjs'), path.join(productionSourceRoot, 'dist-electron', 'preload.cjs'));",
258
+ " await copyFile(icons.png, path.join(productionSourceRoot, 'dist-electron', 'app-icon.png'));",
259
+ " await copyFile(icons.macPng, path.join(productionSourceRoot, 'dist-electron', 'app-icon-macos.png'));",
260
+ " await copyFile(icons.ico, path.join(productionSourceRoot, 'dist-electron', 'app-icon.ico'));",
250
261
  ' await installProductionDependencies(productionSourceRoot);',
251
262
  '',
252
263
  " const productionManifestPath = path.join(productionSourceRoot, 'package.json');",
@@ -267,6 +278,7 @@ function renderDefaultElectronProductionPackager(identity) {
267
278
  '',
268
279
  ' const packagePaths = await packager({',
269
280
  ' dir: productionSourceRoot,',
281
+ ' icon: MACOS_BUILD ? icons.icns : icons.ico,',
270
282
  ' platform: NATIVE_PLATFORM,',
271
283
  ' arch: NATIVE_ARCH,',
272
284
  ` appBundleId: ${JSON.stringify(identity.tauriIdentifier)},`,
@@ -300,6 +312,8 @@ function renderDefaultElectronProductionPackager(identity) {
300
312
  " await writeFile(packagedManifestPath, `${JSON.stringify(packagedManifest, null, 2)}\\n`);",
301
313
  ' }],',
302
314
  ' win32metadata: {',
315
+ ' // Match the starter license holder when the App omits its optional author.',
316
+ ' ...(appPackage.author ? {} : { CompanyName: APP_PRODUCT_NAME }),',
303
317
  ' ProductName: APP_PRODUCT_NAME,',
304
318
  ' FileDescription: APP_PRODUCT_NAME,',
305
319
  ' InternalName: APP_EXECUTABLE_NAME,',
@@ -389,9 +403,11 @@ function renderDefaultMain(identity) {
389
403
  ' DEFAULT_DEV_RENDERER_ENTRY_IMPORT_RETRY_DELAYS_MS,',
390
404
  ' createRendererEntryModuleLoader,',
391
405
  "} from '@nimiplatform/kit/shell/renderer/bootstrap';",
406
+ "import { getTargetAppSession, endTargetAppSession } from './shell/workbench-target-adapter.js';",
392
407
  "import './styles.css';",
393
408
  '',
394
409
  'installNimiShellRuntimeBridge();',
410
+ 'const session = getTargetAppSession();',
395
411
  '',
396
412
  'const entryModuleLoader = createRendererEntryModuleLoader({',
397
413
  ' retryDelaysMs: DEFAULT_DEV_RENDERER_ENTRY_IMPORT_RETRY_DELAYS_MS,',
@@ -406,7 +422,8 @@ function renderDefaultMain(identity) {
406
422
  '/* Admitted workbench styles use this module scope, including body-portaled controls. */',
407
423
  "document.body.classList.add('nimi-ui-module--lab');",
408
424
  "rendererRoot.classList.add('nimi-workbench-host', 'nimi-ui-module--lab');",
409
- 'createRoot(rendererRoot).render(',
425
+ 'const reactRoot = createRoot(rendererRoot);',
426
+ 'reactRoot.render(',
410
427
  ' <React.StrictMode>',
411
428
  ` <NimiThemeProvider accentPack="${identity.accentPack}">`,
412
429
  ' <TooltipProvider>',
@@ -417,6 +434,8 @@ function renderDefaultMain(identity) {
417
434
  ' </NimiThemeProvider>',
418
435
  ' </React.StrictMode>,',
419
436
  ');',
437
+ 'void session.start();',
438
+ 'if (import.meta.hot) import.meta.hot.dispose(() => { endTargetAppSession(session); reactRoot.unmount(); });',
420
439
  '',
421
440
  ].join('\n');
422
441
  }
@@ -491,7 +510,9 @@ export function createAppNavigation() {
491
510
  }
492
511
  type NavigationOwner = {
493
512
  navigation: ReturnType<typeof createAppNavigation>;
513
+ locale: 'en' | 'zh';
494
514
  ready: boolean; setReady: (value: boolean) => void;
515
+ sidebarAvailable: boolean;
495
516
  sidebarVisible: boolean; setSidebarVisible: (value: boolean) => void;
496
517
  };
497
518
  const Context = createContext<NavigationOwner | null>(null);
@@ -501,6 +522,7 @@ export function useAppNavigation(): NavigationOwner {
501
522
  return owner;
502
523
  }
503
524
  export function AppNavigationProvider({ children }: { children: ReactNode }) {
525
+ const locale = navigator.language.toLowerCase().startsWith('zh') ? 'zh' : 'en';
504
526
  const [navigation] = useState(createAppNavigation);
505
527
  const [ready, updateReady] = useState(false);
506
528
  const [sidebarVisible, setSidebarVisible] = useState(true);
@@ -516,7 +538,7 @@ export function AppNavigationProvider({ children }: { children: ReactNode }) {
516
538
  if (!value) navigation.reset({ id: generatedInitialViewId ?? 'welcome' });
517
539
  updateReady(value);
518
540
  }, [navigation]);
519
- return <Context.Provider value={{ navigation, ready, sidebarVisible, setSidebarVisible, setReady }}><NimiNavigationProvider controller={navigation}>{children}</NimiNavigationProvider></Context.Provider>;
541
+ return <Context.Provider value={{ navigation, locale, ready, sidebarAvailable: hasGeneratedViews, sidebarVisible, setSidebarVisible, setReady }}><NimiNavigationProvider controller={navigation}>{children}</NimiNavigationProvider></Context.Provider>;
520
542
  }
521
543
  `;
522
544
  }
@@ -532,7 +554,7 @@ function buildGeneratedModuleCompositionFiles(identity) {
532
554
  ];
533
555
  if (hasAIStudioResolution(resolution)) {
534
556
  files.push(generatedFile('i18n.ts', renderGeneratedAIStudioI18n()));
535
- files.push(generatedFile('host-adapters.tsx', renderGeneratedAIStudioHostAdapter(resolution)));
557
+ files.push(generatedFile('host-adapters.tsx', renderGeneratedAIStudioHostAdapter(resolution, identity.platform)));
536
558
  }
537
559
  return files;
538
560
  }
@@ -838,7 +860,7 @@ function renderGeneratedAIStudioI18n() {
838
860
  ].join('\n');
839
861
  }
840
862
 
841
- function renderGeneratedAIStudioHostAdapter(resolution) {
863
+ function renderGeneratedAIStudioHostAdapter(resolution, platform = 'desktop') {
842
864
  const core = resolvedAIStudioCore(resolution);
843
865
  const coreImportPath = generatedModuleImportPath(core);
844
866
  const workspaceExport = core.productEntry.componentExport;
@@ -848,30 +870,26 @@ function renderGeneratedAIStudioHostAdapter(resolution) {
848
870
  "import type { NimiAIConfigSnapshot } from '@nimiplatform/sdk/ai';",
849
871
  "import { createNimiClientId } from '@nimiplatform/sdk/types';",
850
872
  "import { ModelConfigAIConfigSurface } from '@nimiplatform/kit/features/model-config';",
851
- "import { openDesktopIntent } from '@nimiplatform/kit/shell/renderer/bridge';",
873
+ platform === 'web' ? "import { requestDownload, downloadAsset, openAssetMediaUrl } from '../../shell/web-download.js';" : "import { openDesktopIntent, openNimiLocalAppAssetMediaUrl } from '@nimiplatform/kit/shell/renderer/bridge';",
852
874
  "import { StatusBadge } from '@nimiplatform/kit/ui';",
853
875
  'import {',
854
876
  ' AIStudioHostProvider,',
855
877
  ` ${workspaceExport},`,
856
878
  ' DEFAULT_AI_STUDIO_HISTORY_PANEL_PREFERENCES,',
857
- ' appendStudioRunHistoryRecord,',
858
879
  ' cleanupStudioHistoryArtifacts,',
859
880
  ' clearStudioHistoryWithPolicy,',
860
881
  ' createStudioNonSuccess,',
861
882
  ' createStudioRunTargetSummary,',
862
- ' createEmptyStudioPromptDraftStore,',
883
+ ' createStudioPromptDraftRepository,',
863
884
  ' loadStudioAIConfig,',
864
885
  ' parseAIStudioHistoryPanelPreferences,',
865
- ' parseStudioRunHistory,',
866
- ' parseStudioPromptDraftStore,',
886
+ ' parseStudioRunHistoryRecord,',
887
+ ' studioHistoryFromRecords,',
867
888
  ' projectStudioManagedHistory,',
868
- ' readStudioPromptDraft,',
869
889
  ' requireStudioAIConfigOwner,',
870
890
  ' removeStudioHistoryWithPolicy,',
871
891
  ' runStudioCapability,',
872
892
  ' subscribeStudioAIConfigRefresh,',
873
- ' studioHistoryArtifactPaths,',
874
- ' updateStudioPromptDraftStore,',
875
893
  ' useAIStudioWorkspaceController,',
876
894
  ' type AIStudioHistoryMutationOutcome,',
877
895
  ' type AIStudioHistoryPanelPreferences,',
@@ -879,11 +897,11 @@ function renderGeneratedAIStudioHostAdapter(resolution) {
879
897
  ' type AIStudioHistoryRepository,',
880
898
  ' type AIStudioHostPort,',
881
899
  ' type AIStudioWorkspaceController,',
882
- ' type StudioPromptDraftStore,',
883
900
  ' type StudioRunHistory,',
884
901
  ' type StudioRunHistoryRecord,',
885
902
  ' type StudioRuntimeInspection,',
886
903
  `} from '${coreImportPath}';`,
904
+ "import { createNimiAppRecordStore } from '@nimiplatform/kit/core/app-record-storage';",
887
905
  "import { appId, appTitle } from '../../shell/auth/app-identity.js';",
888
906
  "import { getNimiLocalAppClient } from '../../shell/auth/local-app-client.js';",
889
907
  "import { getRuntimePlatformProjection } from '../../shell/auth/runtime-platform.js';",
@@ -894,10 +912,12 @@ function renderGeneratedAIStudioHostAdapter(resolution) {
894
912
  "import { generatedStudioRuntimeHandlers } from './runtime-registry.js';",
895
913
  "import { generatedLocale, translateGeneratedMessage } from './i18n.js';",
896
914
  '',
897
- "const HISTORY_PATH = 'ai-studio/run-history.v1.json';",
898
- "const PROMPT_DRAFT_STORAGE_KEY = 'nimi.ai-studio.prompt-drafts.v1';",
899
915
  'const translate: AIStudioHostPort[\'translate\'] = translateGeneratedMessage;',
900
916
  '',
917
+ 'function createGeneratedServices(client: ReturnType<typeof getNimiLocalAppClient>) {',
918
+ platform === 'web'
919
+ ? 'const storageScope = appId; // Only non-sensitive panel preferences use browser storage.'
920
+ : "const storageScope = '';",
901
921
  'async function inspectTargetRuntime(): Promise<StudioRuntimeInspection> {',
902
922
  ' const projection = await getRuntimePlatformProjection();',
903
923
  " if (projection.status === 'ready') {",
@@ -923,20 +943,9 @@ function renderGeneratedAIStudioHostAdapter(resolution) {
923
943
  " || normalized.endsWith('_LOCAL_ASSET_NOT_FOUND');",
924
944
  '}',
925
945
  '',
946
+ "const historyRecords = createNimiAppRecordStore(client.storage.assets, 'ai-studio/history', parseStudioRunHistoryRecord);",
926
947
  'async function loadRunHistory(): Promise<StudioRunHistory> {',
927
- ' try {',
928
- ' const document = await getNimiLocalAppClient().storage.readJson(HISTORY_PATH);',
929
- ' return parseStudioRunHistory(document.value);',
930
- ' } catch (error) {',
931
- ' if (isStorageEntryNotFound(error)) return {};',
932
- ' throw error;',
933
- ' }',
934
- '}',
935
- '',
936
- 'async function writeRunHistory(history: StudioRunHistory): Promise<StudioRunHistory> {',
937
- ' const normalized = parseStudioRunHistory(JSON.parse(JSON.stringify(history)) as unknown);',
938
- ' await getNimiLocalAppClient().storage.writeJson(HISTORY_PATH, normalized as never);',
939
- ' return normalized;',
948
+ ' return studioHistoryFromRecords((await historyRecords.list()).sort((a, b) => b.createdAt.localeCompare(a.createdAt)));',
940
949
  '}',
941
950
  '',
942
951
  'let historyMutationTail: Promise<unknown> = Promise.resolve();',
@@ -948,7 +957,7 @@ function renderGeneratedAIStudioHostAdapter(resolution) {
948
957
  '',
949
958
  'const cleanupArtifacts: AIStudioHistoryRepository[\'cleanupArtifacts\'] = (relativePaths) => cleanupStudioHistoryArtifacts({',
950
959
  ' relativePaths,',
951
- ' removeArtifact: (relativePath) => getNimiLocalAppClient().storage.assets.remove(relativePath),',
960
+ ' removeArtifact: (relativePath) => client.storage.assets.remove(relativePath),',
952
961
  ' isNotFound: isStorageEntryNotFound,',
953
962
  '});',
954
963
  '',
@@ -958,7 +967,7 @@ function renderGeneratedAIStudioHostAdapter(resolution) {
958
967
  ' resolveCapabilityLabel: (capabilityId) => generatedAIStudioRegistrations.find((entry) => (',
959
968
  ' entry.descriptor.id === capabilityId',
960
969
  ' ))?.descriptor.label ?? capabilityId,',
961
- ' statArtifact: (artifact) => getNimiLocalAppClient().storage.assets.stat(artifact.relativePath),',
970
+ ' statArtifact: (artifact) => client.storage.assets.stat(artifact.relativePath),',
962
971
  ' });',
963
972
  '}',
964
973
  '',
@@ -966,34 +975,23 @@ function renderGeneratedAIStudioHostAdapter(resolution) {
966
975
  ' return verifyHistoryProjection(await loadRunHistory());',
967
976
  '}',
968
977
  '',
969
- 'async function appendRecord(record: StudioRunHistoryRecord): Promise<AIStudioHistoryProjection> {',
978
+ 'async function appendRecord(record: StudioRunHistoryRecord) {',
970
979
  ' return mutateHistory(async () => {',
971
- ' const current = await loadRunHistory();',
972
- ' const next = appendStudioRunHistoryRecord(current, record);',
973
- ' return verifyHistoryProjection(await writeRunHistory(next));',
980
+ ' const saved = await historyRecords.read(record.id);',
981
+ ' if (!saved) await historyRecords.write(record, null);',
982
+ ' try { return await verifyHistoryProjection(await loadRunHistory()); }',
983
+ " catch (error) { return { record: saved ?? record, refreshError: error instanceof Error ? error.message : String(error || 'History refresh failed.') }; }",
974
984
  ' });',
975
985
  '}',
976
986
  '',
977
987
  'async function persistHistory({ result, record }: { readonly result: Parameters<AIStudioHistoryRepository[\'persist\']>[0][\'result\']; readonly record: StudioRunHistoryRecord }) {',
978
988
  ' try {',
979
- ' return { ok: true as const, projection: await appendRecord(record) };',
989
+ ' const saved = await appendRecord(record);',
990
+ " return 'refreshError' in saved ? { ok: true as const, ...saved } : { ok: true as const, projection: saved, record };",
980
991
  ' } catch (error) {',
981
- ' const paths = studioHistoryArtifactPaths(record);',
982
- ' if (result.ok && result.output.kind === \'artifacts\' && (result.output.musicGeneration || result.output.musicTranscription || result.output.voiceConversion)) {',
983
- ' // Music recovery already owns these assets; history is an additional index.',
984
- ' return { ok: false as const, message: error instanceof Error ? error.message : String(error), retryRecord: true, remainingCleanupPaths: [] };',
985
- ' }',
986
- ' const cleanup = await cleanupArtifacts(paths);',
987
992
  " const message = error instanceof Error ? error.message : String(error || 'History persistence failed.');",
988
- ' return {',
989
- ' ok: false as const,',
990
- ' message,',
991
- ' retryRecord: paths.length === 0,',
992
- ' remainingCleanupPaths: cleanup.remainingCleanupPaths,',
993
- ' ...(paths.length > 0 ? {',
994
- " displayFailure: { reason: 'runtime-call-failed' as const, message: `Runtime completed, but managed artifact history persistence failed: ${message}` },",
995
- ' } : {}),',
996
- ' };',
993
+ ' // A lost publish response must not delete assets of a committed record.',
994
+ ' return { ok: false as const, message, retryRecord: true, remainingCleanupPaths: [] };',
997
995
  ' }',
998
996
  '}',
999
997
  '',
@@ -1004,9 +1002,12 @@ function renderGeneratedAIStudioHostAdapter(resolution) {
1004
1002
  ' history: current,',
1005
1003
  ' recordId,',
1006
1004
  ' deleteAssets,',
1007
- ' removeArtifact: (relativePath) => getNimiLocalAppClient().storage.assets.remove(relativePath),',
1005
+ ' removeArtifact: (relativePath) => client.storage.assets.remove(relativePath),',
1008
1006
  ' isNotFound: isStorageEntryNotFound,',
1009
- ' commit: async (next) => { await writeRunHistory(next); },',
1007
+ ' commit: async (next) => {',
1008
+ ' const retained = new Set(Object.values(next).flat().map(record => record.id));',
1009
+ ' for (const record of Object.values(current).flat()) if (!retained.has(record.id)) await historyRecords.remove(record.id);',
1010
+ ' },',
1010
1011
  ' project: verifyHistoryProjection,',
1011
1012
  ' });',
1012
1013
  ' });',
@@ -1019,9 +1020,12 @@ function renderGeneratedAIStudioHostAdapter(resolution) {
1019
1020
  ' history: current,',
1020
1021
  ' capabilityId,',
1021
1022
  ' deleteAssets,',
1022
- ' removeArtifact: (relativePath) => getNimiLocalAppClient().storage.assets.remove(relativePath),',
1023
+ ' removeArtifact: (relativePath) => client.storage.assets.remove(relativePath),',
1023
1024
  ' isNotFound: isStorageEntryNotFound,',
1024
- ' commit: async (next) => { await writeRunHistory(next); },',
1025
+ ' commit: async (next) => {',
1026
+ ' const retained = new Set(Object.values(next).flat().map(record => record.id));',
1027
+ ' for (const record of Object.values(current).flat()) if (!retained.has(record.id)) await historyRecords.remove(record.id);',
1028
+ ' },',
1025
1029
  ' project: verifyHistoryProjection,',
1026
1030
  ' });',
1027
1031
  ' });',
@@ -1030,13 +1034,13 @@ function renderGeneratedAIStudioHostAdapter(resolution) {
1030
1034
  "const HISTORY_PANEL_STORAGE_KEY = 'nimi.ai-studio.history-panel.v1';",
1031
1035
  'function loadPanelPreferences(): AIStudioHistoryPanelPreferences {',
1032
1036
  ' try {',
1033
- ' const raw = globalThis.localStorage?.getItem(HISTORY_PANEL_STORAGE_KEY);',
1037
+ ' const raw = globalThis.localStorage?.getItem(HISTORY_PANEL_STORAGE_KEY + storageScope);',
1034
1038
  ' if (!raw) return DEFAULT_AI_STUDIO_HISTORY_PANEL_PREFERENCES;',
1035
1039
  ' return parseAIStudioHistoryPanelPreferences(JSON.parse(raw));',
1036
1040
  ' } catch { return DEFAULT_AI_STUDIO_HISTORY_PANEL_PREFERENCES; }',
1037
1041
  '}',
1038
1042
  'function savePanelPreferences(preferences: AIStudioHistoryPanelPreferences): void {',
1039
- ' try { globalThis.localStorage?.setItem(HISTORY_PANEL_STORAGE_KEY, JSON.stringify(preferences)); } catch { /* UI state remains session-local. */ }',
1043
+ ' try { globalThis.localStorage?.setItem(HISTORY_PANEL_STORAGE_KEY + storageScope, JSON.stringify(preferences)); } catch { /* UI state remains session-local. */ }',
1040
1044
  '}',
1041
1045
  '',
1042
1046
  'const historyRepository: AIStudioHistoryRepository = Object.freeze({',
@@ -1051,37 +1055,25 @@ function renderGeneratedAIStudioHostAdapter(resolution) {
1051
1055
  ' savePanelPreferences,',
1052
1056
  '});',
1053
1057
  '',
1054
- 'let promptDraftStore = readPromptDraftStore();',
1055
- '',
1056
- 'function readPromptDraftStore(): StudioPromptDraftStore {',
1057
- ' try {',
1058
- ' const raw = globalThis.localStorage?.getItem(PROMPT_DRAFT_STORAGE_KEY);',
1059
- ' if (!raw) return createEmptyStudioPromptDraftStore();',
1060
- ' return parseStudioPromptDraftStore(JSON.parse(raw));',
1061
- ' } catch {',
1062
- ' return createEmptyStudioPromptDraftStore();',
1063
- ' }',
1064
- '}',
1065
- '',
1066
- 'async function savePromptDraft(key: Parameters<AIStudioHostPort[\'app\'][\'commands\'][\'savePromptDraft\']>[0], prompt: string, enabled: boolean) {',
1067
- ' const next = updateStudioPromptDraftStore(promptDraftStore, key, prompt, enabled);',
1068
- ' if (next === promptDraftStore) return promptDraftStore;',
1069
- ' promptDraftStore = next;',
1070
- ' try { globalThis.localStorage?.setItem(PROMPT_DRAFT_STORAGE_KEY, JSON.stringify(promptDraftStore)); } catch { /* UI state remains session-local. */ }',
1071
- ' return promptDraftStore;',
1072
- '}',
1058
+ 'const promptDrafts = createStudioPromptDraftRepository(client.storage);',
1073
1059
  '',
1060
+ ...(platform === 'web' ? [
1061
+ "const exportText: AIStudioHostPort['app']['commands']['exportText'] = async ({ filename, body }) => {",
1062
+ " try { return { ok: true, value: requestDownload(filename, new Blob([body], { type: 'text/plain' })) }; } catch (error) { return { ok: false, error }; }",
1063
+ '};', '',
1064
+ ] : [
1074
1065
  "const exportText: AIStudioHostPort['app']['commands']['exportText'] = async ({ filename, body }) => {",
1075
1066
  ' try {',
1076
- ' const assets = getNimiLocalAppClient().storage.assets;',
1067
+ ' const assets = client.storage.assets;',
1077
1068
  " const saved = await assets.write({ relativePath: `exports/${crypto.randomUUID()}/${filename}`,",
1078
1069
  " body: new Blob([body], { type: 'text/plain' }), mediaType: 'text/plain', overwrite: false });",
1079
1070
  ' let revealed = false;',
1080
1071
  ' try { await assets.reveal(saved.relativePath); revealed = true; } catch { /* The file remains saved. */ }',
1081
- ' return { ok: true, value: { filename, artifactPath: saved.relativePath, byteSize: saved.sizeBytes, revealed } };',
1072
+ " return { ok: true, value: { destination: 'runtime-asset', filename, artifactPath: saved.relativePath, byteSize: saved.sizeBytes, revealed } };",
1082
1073
  ' } catch (error) { return { ok: false, error }; }',
1083
1074
  '};',
1084
1075
  '',
1076
+ ]),
1085
1077
  'const RUN_STATUS_LABEL_KEYS: Readonly<Record<string, string>> = Object.freeze({',
1086
1078
  " ready: 'StudioShell.runStatusReady',",
1087
1079
  " unavailable: 'StudioShell.runStatusUnavailable',",
@@ -1101,7 +1093,8 @@ function renderGeneratedAIStudioHostAdapter(resolution) {
1101
1093
  ' clock: { now: () => Date.now() },',
1102
1094
  ' app: {',
1103
1095
  ' projection: {',
1104
- ' promptDraft: (key, enabled) => ({ prompt: readStudioPromptDraft(promptDraftStore, key, enabled) }),',
1096
+ ' promptDraft: promptDrafts.load,',
1097
+ ` assetExportAction: () => '${platform === 'web' ? 'download' : 'reveal'}',`,
1105
1098
  ' projectRunTarget: createStudioRunTargetSummary,',
1106
1099
  ' runStatusLabel,',
1107
1100
  ' },',
@@ -1109,7 +1102,7 @@ function renderGeneratedAIStudioHostAdapter(resolution) {
1109
1102
  ' subscribeAIConfigRefresh: (listener) => subscribeStudioAIConfigRefresh(listener, window, document),',
1110
1103
  ' },',
1111
1104
  ' commands: {',
1112
- ' savePromptDraft,',
1105
+ ' savePromptDraft: promptDrafts.save,',
1113
1106
  ' async copyText(text) {',
1114
1107
  ' try {',
1115
1108
  ' await navigator.clipboard.writeText(text);',
@@ -1119,6 +1112,8 @@ function renderGeneratedAIStudioHostAdapter(resolution) {
1119
1112
  ' }',
1120
1113
  ' },',
1121
1114
  ' exportText,',
1115
+ platform === 'web' ? ' exportAsset: async relativePath => { await downloadAsset(relativePath); },' : ' exportAsset: async (relativePath) => { await client.storage.assets.reveal(relativePath); },',
1116
+ platform === 'web' ? ' openAssetMediaUrl,' : ' openAssetMediaUrl: openNimiLocalAppAssetMediaUrl,',
1122
1117
  ' },',
1123
1118
  ' },',
1124
1119
  ' sdk: {',
@@ -1130,34 +1125,36 @@ function renderGeneratedAIStudioHostAdapter(resolution) {
1130
1125
  ' handlers: generatedStudioRuntimeHandlers,',
1131
1126
  ' resolveCapability: (capabilityId) => generatedAIStudioComposition.getCapability(capabilityId).descriptor,',
1132
1127
  ' inspectRuntime: inspectTargetRuntime,',
1133
- ' getClient: getNimiLocalAppClient,',
1128
+ ' getClient: () => client,',
1134
1129
  " createScenarioId: (capability) => `studio:${capability.id}`,",
1135
1130
  ' nonSuccess: (capability, reason, message, diagnostics) => (',
1136
1131
  ' createStudioNonSuccess(capability, reason, message, translate, diagnostics)',
1137
1132
  ' ),',
1138
1133
  ' }),',
1139
- ' deleteLocalAppVoiceAsset: (voiceAssetId) => getNimiLocalAppClient().ai.voiceAssets.delete(voiceAssetId),',
1134
+ ' deleteLocalAppVoiceAsset: (voiceAssetId) => client.ai.voiceAssets.delete(voiceAssetId),',
1140
1135
  ' async listLocalAppVoiceAssets() {',
1141
- " const result = await getNimiLocalAppClient().ai.voiceAssets.list({ pageSize: 100, pageToken: '' });",
1136
+ " const result = await client.ai.voiceAssets.list({ pageSize: 100, pageToken: '' });",
1142
1137
  ' return result.assets.map((asset) => ({',
1143
1138
  ' voiceAssetId: asset.voiceAssetId,',
1144
1139
  ' creationSource: asset.creationSource,',
1145
1140
  ' status: asset.status,',
1146
1141
  ' }));',
1147
1142
  ' },',
1148
- ' uploadLocalAppArtifact: (input) => getNimiLocalAppClient().ai.artifacts.upload(input),',
1149
- ' assets: getNimiLocalAppClient().storage.assets,',
1150
- ' storage: getNimiLocalAppClient().storage,',
1143
+ ' uploadLocalAppArtifact: (input) => client.ai.artifacts.upload(input),',
1144
+ ' assets: client.storage.assets,',
1145
+ ' storage: client.storage,',
1151
1146
  ' aiConfig: {',
1152
- ' getSnapshot: () => getNimiLocalAppClient().aiConfig.get(),',
1147
+ ' getSnapshot: () => client.aiConfig.get(),',
1153
1148
  ' get: () => loadStudioAIConfig({',
1154
- ' get: async () => (await getNimiLocalAppClient().aiConfig.get()).config,',
1149
+ ' get: async () => (await client.aiConfig.get()).config,',
1155
1150
  ' }, appId),',
1156
1151
  ' },',
1157
- ' revealLocalAppAsset: (relativePath) => getNimiLocalAppClient().storage.assets.reveal(relativePath),',
1158
1152
  ' },',
1159
1153
  '};',
1160
1154
  '',
1155
+ 'return { hostValue, historyRepository, inspectTargetRuntime };',
1156
+ '}',
1157
+ '',
1161
1158
  'const generatedCapabilityContracts = Object.freeze([',
1162
1159
  ' ...new Set(generatedAIStudioRegistrations.flatMap((registration) => (',
1163
1160
  ' registration.descriptor.capabilityContract ? [registration.descriptor.capabilityContract] : []',
@@ -1174,6 +1171,7 @@ function renderGeneratedAIStudioHostAdapter(resolution) {
1174
1171
  ' // Absent when the App-owned ai-studio-core predates commit reporting.',
1175
1172
  ' readonly onCommitted?: () => void;',
1176
1173
  '}) {',
1174
+ ' const [client] = useState(getNimiLocalAppClient);',
1177
1175
  ' const [snapshot, setSnapshot] = useState<NimiAIConfigSnapshot | null>(null);',
1178
1176
  ' const [loading, setLoading] = useState(true);',
1179
1177
  ' const [loadError, setLoadError] = useState<string | null>(null);',
@@ -1181,7 +1179,7 @@ function renderGeneratedAIStudioHostAdapter(resolution) {
1181
1179
  ' setLoading(true);',
1182
1180
  ' setLoadError(null);',
1183
1181
  ' try {',
1184
- ' const next = await getNimiLocalAppClient().aiConfig.get();',
1182
+ ' const next = await client.aiConfig.get();',
1185
1183
  ' if (next.config) requireStudioAIConfigOwner(next.config, appId);',
1186
1184
  ' setSnapshot(next);',
1187
1185
  ' } catch (error) {',
@@ -1207,12 +1205,12 @@ function renderGeneratedAIStudioHostAdapter(resolution) {
1207
1205
  ' capabilities={snapshot?.config ? snapshot.config.capabilities as never : snapshot ? null : undefined}',
1208
1206
  ' revision={snapshot?.revision}',
1209
1207
  ' effectiveSelections={snapshot?.effectiveSelections}',
1210
- ' listOptions={(query) => getNimiLocalAppClient().aiConfig.listOptions(query)}',
1208
+ ' listOptions={(query) => client.aiConfig.listOptions(query)}',
1211
1209
  ' loading={loading && !snapshot}',
1212
1210
  ' loadError={loadError}',
1213
1211
  ' onRetry={() => { void refresh(); }}',
1214
1212
  ' onOverwrite={async (input) => {',
1215
- ' const result = await getNimiLocalAppClient().aiConfig.overwrite(input);',
1213
+ ' const result = await client.aiConfig.overwrite(input);',
1216
1214
  ' setSnapshot({ config: result.config, revision: result.revision, effectiveSelections: [] });',
1217
1215
  ' // A commit re-reads every mounted consumer, this panel included,',
1218
1216
  ' // even when the drawer closed before the write finished.',
@@ -1222,12 +1220,14 @@ function renderGeneratedAIStudioHostAdapter(resolution) {
1222
1220
  ' }',
1223
1221
  ' return result;',
1224
1222
  ' }}',
1223
+ ...(platform === 'web' ? [] : [
1225
1224
  ' onOpenOwnerConfiguration={() => {',
1226
1225
  ' void openDesktopIntent({',
1227
1226
  " requestId: createNimiClientId('desktop-open'),",
1228
1227
  " intent: { kind: 'open-apps', appId, section: 'ai-models' },",
1229
1228
  ' });',
1230
1229
  ' }}',
1230
+ ]),
1231
1231
  ' copy={{',
1232
1232
  " title: translate('StudioModelConfig.drawerTitle'),",
1233
1233
  " description: translate('StudioModelConfig.drawerDescription', { appTitle }),",
@@ -1257,6 +1257,7 @@ function renderGeneratedAIStudioHostAdapter(resolution) {
1257
1257
  ' readonly onSelectCapability: (capabilityId: string, runId?: string) => void;',
1258
1258
  ' readonly children: ReactNode;',
1259
1259
  '}) {',
1260
+ ' const [{ hostValue, historyRepository, inspectTargetRuntime }] = useState(() => createGeneratedServices(getNimiLocalAppClient()));',
1260
1261
  ' const snapshot = useNimiNavigationSnapshot<{ id: string; runId?: string }>();',
1261
1262
  ' const [runtime, setRuntime] = useState<StudioRuntimeInspection | null>(null);',
1262
1263
  ' useEffect(() => {',
@@ -1313,28 +1314,10 @@ function renderGeneratedAIStudioHostAdapter(resolution) {
1313
1314
  ].join('\n');
1314
1315
  }
1315
1316
 
1316
- function renderDefaultTauriMain() {
1317
- return [
1318
- 'fn main() {',
1319
- ' tauri::Builder::default()',
1320
- ' .setup(|app| {',
1321
- ' use tauri::Manager;',
1322
- ' app.manage(',
1323
- ' nimi_shell_tauri::capabilities::runtime::RuntimeBridgeLocalAppHost::platform_default(),',
1324
- ' );',
1325
- ' Ok(())',
1326
- ' })',
1327
- ' .invoke_handler(nimi_shell_tauri::nimi_shell_tauri_local_app_standard_shell_handler![])',
1328
- ' .run(tauri::generate_context!())',
1329
- ' .expect("failed to run Nimi App shell");',
1330
- '}',
1331
- '',
1332
- ].join('\n');
1333
- }
1334
-
1335
1317
  function renderDefaultElectronMain(identity) {
1336
1318
  return [
1337
1319
  "import path from 'node:path';",
1320
+ "import { existsSync } from 'node:fs';",
1338
1321
  "import { fileURLToPath, pathToFileURL } from 'node:url';",
1339
1322
  "import { app, BrowserWindow, ipcMain, Menu, protocol, session, webContents } from 'electron';",
1340
1323
  "import { configureNimiElectronAppHostProfile } from '@nimiplatform/kit/shell/electron/host-profile';",
@@ -1367,6 +1350,9 @@ function renderDefaultElectronMain(identity) {
1367
1350
  ' && __NIMI_ELECTRON_PRODUCTION__;',
1368
1351
  "const currentDir = path.dirname(fileURLToPath(import.meta.url));",
1369
1352
  "const appRoot = path.resolve(currentDir, '..');",
1353
+ "const appIconPath = path.join(currentDir, process.platform === 'win32' ? 'app-icon.ico' : process.platform === 'darwin' ? 'app-icon-macos.png' : 'app-icon.png');",
1354
+ "if (IS_PRODUCTION_BUNDLE && !existsSync(appIconPath)) throw new Error('Packaged App icon is missing.');",
1355
+ 'const windowIcon = existsSync(appIconPath) ? appIconPath : undefined;',
1370
1356
  "const preloadPath = path.join(currentDir, 'preload.cjs');",
1371
1357
  "const productionRendererUrl = pathToFileURL(path.join(appRoot, 'dist', 'index.html')).toString();",
1372
1358
  'const developmentRendererUrl = readDevelopmentRendererUrl();',
@@ -1376,15 +1362,19 @@ function renderDefaultElectronMain(identity) {
1376
1362
  'let quitting = false;',
1377
1363
  '',
1378
1364
  `app.setName(${JSON.stringify(identity.appTitle)});`,
1379
- 'app.setAppUserModelId(NATIVE_BUNDLE_IDENTIFIER);',
1365
+ "if (process.platform === 'win32') {",
1366
+ ' app.setAppUserModelId(IS_PRODUCTION_BUNDLE ? NATIVE_BUNDLE_IDENTIFIER : `ai.nimi.dev.apps.${APP_ID}`);',
1367
+ '}',
1380
1368
  'const chromeHost = createNimiElectronAppChromeHost({',
1381
1369
  ` metadata: { name: ${JSON.stringify(identity.appTitle)}, version: ${JSON.stringify(identity.version)} },`,
1382
1370
  ' allowedRendererUrls, app,',
1371
+ " appCommands: [{ id: 'app.nimi-account', menu: 'file', labels: { en: 'Nimi account', zh: 'Nimi 账号' } }],",
1383
1372
  ' menu: { buildFromTemplate: template => Menu.buildFromTemplate(template as Electron.MenuItemConstructorOptions[]), setApplicationMenu: menu => Menu.setApplicationMenu(menu as Electron.Menu | null) },',
1384
1373
  '});',
1385
1374
  'registerNimiElectronAppAssetProtocolScheme(protocol);',
1386
1375
  '',
1387
1376
  'void app.whenReady().then(async () => {',
1377
+ " if (process.platform === 'darwin' && !IS_PRODUCTION_BUNDLE && windowIcon) app.dock?.setIcon(windowIcon);",
1388
1378
  ' registerNimiElectronAppBridge({',
1389
1379
  ' chromeHost,',
1390
1380
  ' appId: APP_ID,',
@@ -1426,6 +1416,7 @@ function renderDefaultElectronMain(identity) {
1426
1416
  ' minWidth: 360,',
1427
1417
  ' minHeight: 560,',
1428
1418
  ` title: ${JSON.stringify(identity.appTitle)},`,
1419
+ ' icon: windowIcon,',
1429
1420
  ' autoHideMenuBar: true,',
1430
1421
  ' webPreferences: {',
1431
1422
  ' preload: preloadPath,',