@nimiplatform/app-tools 0.16.0-rc.10 → 0.16.0-rc.13

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.
@@ -1,6 +1,6 @@
1
1
  import { isAppId } from './app-identifiers.mjs';
2
2
  import { WEB_BASE_TEMPLATE_PATHS, webDevelopmentInput, webBuildProfile, webPackage, webDependencyMatrix } from './web-scaffold.mjs';
3
- import { resolveWebAppScaffoldFeatures } from './app-scaffold-capabilities.mjs';
3
+ import { resolveDesktopAppScaffoldFeatures, resolveWebAppScaffoldFeatures } from './app-scaffold-capabilities.mjs';
4
4
  import path from 'node:path';
5
5
  import { createHash } from 'node:crypto';
6
6
  import YAML from 'yaml';
@@ -29,7 +29,7 @@ export { SUPPORTED_APP_SCAFFOLD_PROFILES };
29
29
  const DEFAULT_APP_ID = 'my.nimi-app';
30
30
  const DEFAULT_APP_TITLE = 'My Nimi App';
31
31
  const DEFAULT_APP_VERSION = '0.1.0';
32
- const SEMVER_PATTERN = /^(?:0|[1-9][0-9]*)\.(?:0|[1-9][0-9]*)\.(?:0|[1-9][0-9]*)(?:-[0-9A-Za-z]+(?:[.-][0-9A-Za-z]+)*)?(?:\+[0-9A-Za-z]+(?:[.-][0-9A-Za-z]+)*)?$/u;
32
+ const SEMVER_PATTERN = /^(?:0|[1-9][0-9]*)\.(?:0|[1-9][0-9]*)\.(?:0|[1-9][0-9]*)(?:-(?:0|[1-9][0-9]*|[0-9]*[A-Za-z-][0-9A-Za-z-]*)(?:\.(?:0|[1-9][0-9]*|[0-9]*[A-Za-z-][0-9A-Za-z-]*))*)?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/u;
33
33
  export const SCAFFOLD_INTENT_VERSION = 4;
34
34
  export const SCAFFOLD_LOCK_VERSION = 4;
35
35
  export const SCAFFOLD_VERSION = '2026-10-13.standard-app-navigation-v1';
@@ -172,7 +172,7 @@ const APP_RELEASE_WORKFLOW = [
172
172
  ' id: matrix',
173
173
  ' shell: bash',
174
174
  ' run: |',
175
- " matrix=$(jq -c '{include: [.targets[] | {target: ., runner: (if . == \"windows-x86_64\" then \"windows-latest\" elif . == \"macos-aarch64\" then \"macos-15\" else error(\"unsupported target\") end)}]}' .nimi-targets.json)",
175
+ " matrix=$(jq -c '{include: [.targets[] | {target: ., runner: (if . == \"desktop-universal\" then \"ubuntu-latest\" elif . == \"windows-x86_64\" then \"windows-latest\" elif . == \"macos-aarch64\" then \"macos-15\" else error(\"unsupported target\") end)}]}' .nimi-targets.json)",
176
176
  ' test "$(jq \'.include | length\' <<<"$matrix")" -gt 0',
177
177
  ' echo "matrix=$matrix" >> "$GITHUB_OUTPUT"',
178
178
  ' build-target:',
@@ -278,6 +278,7 @@ const APP_RELEASE_WORKFLOW = [
278
278
  ' dist/nimi-app/*.target.json',
279
279
  ' dist/nimi-app/*.app-info.json',
280
280
  ' dist/nimi-app/*.candidate.json',
281
+ ' dist/nimi-app/*-storefront-media.zip',
281
282
  ' if-no-files-found: error',
282
283
  ' release:',
283
284
  " if: github.event_name == 'push' && github.ref_type == 'tag'",
@@ -316,7 +317,7 @@ const APP_RELEASE_WORKFLOW = [
316
317
  " sleep 10",
317
318
  " done",
318
319
  " }",
319
- ' assets=(release-assets/*.nimiapp release-assets/*.app-info.json release-assets/*.candidate.json)',
320
+ ' assets=(release-assets/*.nimiapp release-assets/*.app-info.json release-assets/*.candidate.json release-assets/*-storefront-media.zip)',
320
321
  ' test "${#assets[@]}" -gt 0',
321
322
  " expected=$(printf '%s\\n' \"${assets[@]##*/}\" | jq -R -s -c 'split(\"\\n\")[:-1] | sort')",
322
323
  ' if release_id=$(gh release view "$GITHUB_REF_NAME" --repo "$GITHUB_REPOSITORY" --json databaseId --jq .databaseId 2>/dev/null); then',
@@ -520,6 +521,23 @@ function deriveScaffoldDevPort(appId) {
520
521
  return 1430 + hash;
521
522
  }
522
523
 
524
+ export const SUPPORTED_DESKTOP_CARRIERS = Object.freeze(['managed-web', 'native']);
525
+
526
+ function resolveDesktopCarrier(platform, carrier) {
527
+ const normalized = String(carrier || '').trim();
528
+ if (platform === 'web') {
529
+ if (normalized) {
530
+ throw new Error('--carrier is available only for desktop Apps');
531
+ }
532
+ return undefined;
533
+ }
534
+ const selected = normalized || 'managed-web';
535
+ if (!SUPPORTED_DESKTOP_CARRIERS.includes(selected)) {
536
+ throw new Error(`Unsupported desktop App carrier: ${selected} (expected managed-web or native)`);
537
+ }
538
+ return selected;
539
+ }
540
+
523
541
  function buildAppIdentity(
524
542
  profile,
525
543
  appId,
@@ -531,14 +549,19 @@ function buildAppIdentity(
531
549
  features = undefined,
532
550
  featureResolver = resolveAppScaffoldFeatures,
533
551
  platform = 'desktop',
552
+ carrier = undefined,
534
553
  ) {
535
554
  const resolvedPackageName = packageName || packageSafeName(appId);
536
555
  if (!['desktop', 'web'].includes(platform)) throw new Error(`Unsupported App platform: ${platform}`);
537
- const capabilityResolution = platform === 'web' ? resolveWebAppScaffoldFeatures(features, featureResolver) : featureResolver(features);
556
+ const desktopCarrier = resolveDesktopCarrier(platform, carrier);
557
+ const capabilityResolution = platform === 'web'
558
+ ? resolveWebAppScaffoldFeatures(features, featureResolver)
559
+ : resolveDesktopAppScaffoldFeatures(features, desktopCarrier, featureResolver);
538
560
  const identity = {
539
561
  appId,
540
562
  appTitle,
541
563
  platform,
564
+ ...(desktopCarrier ? { carrier: desktopCarrier } : {}),
542
565
  version: normalizeAppVersion(version),
543
566
  profile,
544
567
  packageName: resolvedPackageName,
@@ -572,6 +595,8 @@ function resolveAppScaffoldCreateInputWithResolver(
572
595
  featureResolver,
573
596
  ) {
574
597
  const profile = resolveProfile(options);
598
+ const platform = options.platform || 'desktop';
599
+ const carrier = resolveDesktopCarrier(platform, options.carrier);
575
600
  const appId = resolveAppId(options);
576
601
  const appTitle = normalizeDisplayName(options.title || options.name || DEFAULT_APP_TITLE);
577
602
  const version = normalizeAppVersion(options.version);
@@ -588,10 +613,12 @@ function resolveAppScaffoldCreateInputWithResolver(
588
613
  options.accentPack,
589
614
  options.features,
590
615
  featureResolver,
591
- options.platform || 'desktop',
616
+ platform,
617
+ carrier,
592
618
  );
593
619
  return Object.freeze({
594
620
  ...(identity.platform === 'web' ? { platform: 'web' } : {}),
621
+ ...(identity.carrier ? { carrier: identity.carrier } : {}),
595
622
  profile,
596
623
  appId,
597
624
  appTitle,
@@ -671,7 +698,31 @@ function buildPackageJson(profile, versions, identity) {
671
698
  if (identity.author) {
672
699
  packageJson.author = identity.author;
673
700
  }
674
- return identity.platform === 'web' ? webPackage(packageJson) : packageJson;
701
+ if (identity.platform === 'web') return webPackage(packageJson);
702
+ if (identity.carrier === 'managed-web') {
703
+ const { main: _main, ...managedPkg } = packageJson;
704
+ for (const name of ['@electron/packager', 'electron', 'esbuild', 'pngjs']) {
705
+ delete managedPkg.devDependencies[name];
706
+ }
707
+ managedPkg.pnpm = { onlyBuiltDependencies: ['esbuild', 'protobufjs'] };
708
+ managedPkg.scripts = {
709
+ dev: 'nimi-app dev --shell electron',
710
+ 'dev:renderer': `vite --host 127.0.0.1 --port ${identity.devPort} --strictPort`,
711
+ 'dev:shell': 'nimi-app dev',
712
+ init: 'nimi-app init',
713
+ sync: 'nimi-app sync',
714
+ check: 'nimi-app check',
715
+ test: 'nimi-app test',
716
+ 'test:app': 'node --test test/*.test.mjs',
717
+ 'app:build': 'nimi-app build',
718
+ pack: 'nimi-app pack',
719
+ typecheck: 'tsc --noEmit',
720
+ build: 'tsc --noEmit && vite build',
721
+ validate: 'node scripts/validate.mjs',
722
+ };
723
+ return managedPkg;
724
+ }
725
+ return packageJson;
675
726
  }
676
727
 
677
728
  function buildRuntimeDependencies(profile, versions, capabilityResolution) {
@@ -812,6 +863,13 @@ function buildNimiAppManifest(identity) {
812
863
  capability_contract_refs: identity.capabilityResolution.capabilityContractRefs,
813
864
  required_standardized_feature_refs: identity.capabilityResolution.requiredStandardizedFeatureRefs,
814
865
  storage_policy: { kind: 'nimi-mediated-default' },
866
+ ...(identity.platform !== 'web' && identity.carrier === 'managed-web' ? {
867
+ desktop: {
868
+ window: {
869
+ title_bar_style: 'hidden',
870
+ },
871
+ },
872
+ } : {}),
815
873
  metadata: {
816
874
  summary: '',
817
875
  icon: 'assets/app-icon.png',
@@ -857,7 +915,187 @@ function applyProfileSeam(relativePath, content, profile, identity) {
857
915
  return buildNimiAppManifest(identity);
858
916
  }
859
917
  if (relativePath === 'README.md') {
860
- return content.replace(/Profile: `standalone`/, `Profile: \`${profile}\``);
918
+ return content
919
+ .replace(/Profile: `standalone`/, `Profile: \`${profile}\``)
920
+ .replace(/<!-- carrier: (native|managed-web) -->\r?\n([\s\S]*?)<!-- end carrier -->\r?\n/gu,
921
+ (_, carrier, section) => carrier === identity.carrier ? section : '');
922
+ }
923
+ if (identity.carrier === 'managed-web' && relativePath === 'src/capabilities/agent-center/index.tsx') {
924
+ return [
925
+ "import type { ComponentProps } from 'react';",
926
+ "import { AppAgentCenterEntry } from '@nimiplatform/kit/features/agent-center';",
927
+ '',
928
+ '// @nimi-authority: rule.nimi.platform.app-ecosystem.p-scaf-019c',
929
+ '// @nimi-authority: rule.nimi.platform.app-ecosystem.p-agid-014a',
930
+ "export function AgentCenterCapability(props: { readonly client: ComponentProps<typeof AppAgentCenterEntry>['client'] }) {",
931
+ ' return (',
932
+ ' <AppAgentCenterEntry',
933
+ ' client={props.client}',
934
+ ' hostMechanics={null}',
935
+ " language={globalThis.document?.documentElement.lang || 'en'}",
936
+ ' />',
937
+ ' );',
938
+ '}',
939
+ '',
940
+ ].join('\n');
941
+ }
942
+ if (identity.carrier === 'managed-web' && relativePath === 'src/capabilities/agent-conversation/index.tsx') {
943
+ return [
944
+ "import { useEffect, useMemo, useRef, useState } from 'react';",
945
+ "import { ArrowLeft, ChevronRight, MessagesSquare } from 'lucide-react';",
946
+ "import { Avatar, Button, InlineAlert, LoadingSkeleton, Surface } from '@nimiplatform/kit/ui';",
947
+ 'import {',
948
+ ' APP_CONVERSATION_ENTRY_COPY,',
949
+ ' CanonicalComposer,',
950
+ ' CanonicalTranscriptView,',
951
+ ' createAppConversationEntrySession,',
952
+ ' createBrowserAppConversationHostPort,',
953
+ ' type AppConversationEntryClient,',
954
+ ' type AppConversationEntrySession,',
955
+ ' type AppConversationEntryState,',
956
+ "} from '@nimiplatform/kit/features/chat';",
957
+ '',
958
+ '// @nimi-authority: rule.nimi.platform.app-ecosystem.p-scaf-019c',
959
+ '// @nimi-authority: rule.nimi.runtime.agent-participation.r093',
960
+ '// Managed-web carrier keeps text conversation and omits microphone recording.',
961
+ 'export function AgentConversationCapability(props: { readonly client: AppConversationEntryClient }) {',
962
+ " const language = globalThis.document?.documentElement.lang || 'en';",
963
+ " const copy = useMemo(() => (language.trim().toLowerCase().startsWith('zh') ? APP_CONVERSATION_ENTRY_COPY.zh : APP_CONVERSATION_ENTRY_COPY.en), [language]);",
964
+ ' const hostPort = useMemo(() => createBrowserAppConversationHostPort(), []);',
965
+ ' const sessionRef = useRef<AppConversationEntrySession | null>(null);',
966
+ ' const [state, setState] = useState<AppConversationEntryState | null>(null);',
967
+ " const [composerText, setComposerText] = useState('');",
968
+ '',
969
+ ' useEffect(() => {',
970
+ ' const session = createAppConversationEntrySession({ client: props.client, hostPort });',
971
+ ' sessionRef.current = session;',
972
+ ' const unobserve = session.observe(setState);',
973
+ ' void session.loadReferences();',
974
+ ' return () => {',
975
+ ' unobserve();',
976
+ ' if (sessionRef.current === session) sessionRef.current = null;',
977
+ ' void session.dispose();',
978
+ ' };',
979
+ ' }, [props.client, hostPort]);',
980
+ '',
981
+ ' useEffect(() => {',
982
+ " setComposerText('');",
983
+ ' }, [state?.conversationAnchorId]);',
984
+ '',
985
+ ' const composerAdapter = useMemo(() => ({',
986
+ ' submit: async ({ text }: { text: string; attachments: readonly never[] }) => {',
987
+ ' const session = sessionRef.current;',
988
+ ' if (!session || !text.trim()) return;',
989
+ ' const requestId = `send_${globalThis.crypto?.randomUUID?.() ?? Date.now()}`;',
990
+ " await session.send({ requestId, parts: [{ kind: 'text', text }] });",
991
+ ' if (sessionRef.current !== session) return;',
992
+ " setComposerText((current) => (current === text ? '' : current));",
993
+ ' },',
994
+ ' }), []);',
995
+ '',
996
+ " if (!state || state.status === 'idle' || state.status === 'loading-references' || state.status === 'opening' || state.status === 'failed' || state.status === 'stale') {",
997
+ " const opening = state?.status === 'opening';",
998
+ ' return (',
999
+ ' <Surface tone="panel" className="space-y-3 p-4" data-nimi-app-conversation-entry="true">',
1000
+ ' <h1 className="m-0 text-2xl font-semibold tracking-tight">{copy.title}</h1>',
1001
+ " {!state || state.status === 'idle' || state.status === 'loading-references' || opening ? (",
1002
+ ' <LoadingSkeleton lines={2} label={opening ? copy.opening : copy.loadingReferences} />',
1003
+ ' ) : null}',
1004
+ ' {state?.error ? <InlineAlert tone="warning">{state.error}</InlineAlert> : null}',
1005
+ " {state && (state.status === 'failed' || state.status === 'stale') ? (",
1006
+ ' <Button size="sm" tone="secondary" onClick={() => { void sessionRef.current?.loadReferences(); }}>',
1007
+ ' {state.selectedReference ? copy.reload : copy.retry}',
1008
+ ' </Button>',
1009
+ ' ) : null}',
1010
+ ' </Surface>',
1011
+ ' );',
1012
+ ' }',
1013
+ '',
1014
+ " if (state.status === 'select-reference') {",
1015
+ ' return (',
1016
+ ' <Surface tone="panel" className="space-y-4 p-4" data-nimi-app-conversation-entry="true">',
1017
+ ' <header className="flex items-start gap-3">',
1018
+ ' <span className="grid size-10 shrink-0 place-items-center rounded-xl bg-[var(--nimi-surface-active)] text-[var(--nimi-action-primary-bg)]">',
1019
+ ' <MessagesSquare className="size-5" aria-hidden="true" />',
1020
+ ' </span>',
1021
+ ' <div className="min-w-0">',
1022
+ ' <h1 className="m-0 text-2xl font-semibold tracking-tight">{copy.title}</h1>',
1023
+ ' <p className="m-0 mt-1 text-sm text-[var(--nimi-text-secondary)]">{copy.description}</p>',
1024
+ ' </div>',
1025
+ ' </header>',
1026
+ ' {state.references.length === 0 ? (',
1027
+ ' <InlineAlert tone="warning">{copy.empty}</InlineAlert>',
1028
+ ' ) : (',
1029
+ ' <div className="grid grid-cols-[repeat(auto-fill,minmax(min(100%,13rem),1fr))] gap-2" data-nimi-app-conversation-selector="true">',
1030
+ ' {state.references.map((reference) => (',
1031
+ ' <Button',
1032
+ ' key={reference.agentHandle}',
1033
+ ' tone="secondary"',
1034
+ ' aria-label={`${reference.displayName} · ${copy.select}`}',
1035
+ ' className="min-h-14 min-w-0 justify-start px-3 text-left [&>span]:w-full [&>span]:justify-start"',
1036
+ ' onClick={() => { void sessionRef.current?.selectReference(reference.agentHandle); }}',
1037
+ ' >',
1038
+ ' <Avatar size="md" src={reference.avatarUrl || undefined} alt="" fallback={reference.displayName.slice(0, 1)} />',
1039
+ ' <span className="min-w-0 flex-1 truncate">{reference.displayName}</span>',
1040
+ ' <ChevronRight className="size-4 shrink-0 opacity-60" aria-hidden="true" />',
1041
+ ' </Button>',
1042
+ ' ))}',
1043
+ ' </div>',
1044
+ ' )}',
1045
+ ' </Surface>',
1046
+ ' );',
1047
+ ' }',
1048
+ '',
1049
+ " if (state.status !== 'ready' || !state.selectedReference || !state.conversationAnchorId) {",
1050
+ ' return null;',
1051
+ ' }',
1052
+ '',
1053
+ ' const reference = state.selectedReference;',
1054
+ ' return (',
1055
+ ' <div className="h-full min-h-[28rem]" data-nimi-app-conversation-entry="true">',
1056
+ ' <Surface tone="panel" className="flex h-full min-h-[inherit] min-w-0 flex-col overflow-hidden">',
1057
+ ' <header className="flex shrink-0 items-center justify-between gap-3 border-b border-[var(--nimi-border-subtle)] px-4 py-3">',
1058
+ ' <div className="flex min-w-0 items-center gap-3">',
1059
+ ' <Button size="sm" tone="ghost" onClick={() => { void sessionRef.current?.clearSelection(); }}>',
1060
+ ' <ArrowLeft className="size-4" aria-hidden="true" />{copy.back}',
1061
+ ' </Button>',
1062
+ ' <Avatar size="md" src={reference.avatarUrl || undefined} alt="" fallback={reference.displayName.slice(0, 1)} />',
1063
+ ' <h1 className="m-0 min-w-0 text-base font-semibold break-words">{reference.displayName}</h1>',
1064
+ ' </div>',
1065
+ ' </header>',
1066
+ ' {state.actionError ? <div className="px-4 py-2"><InlineAlert tone="warning">{state.actionError}</InlineAlert></div> : null}',
1067
+ ' <CanonicalTranscriptView',
1068
+ ' messages={state.messages}',
1069
+ ' copy={copy.chatCopy}',
1070
+ ' activeConversationId={state.conversationAnchorId}',
1071
+ ' agentAvatarUrl={reference.avatarUrl}',
1072
+ ' agentName={reference.displayName}',
1073
+ ' pendingFirstBeat={state.activeTurnId !== null}',
1074
+ ' emptyEyebrow={copy.transcriptEmptyEyebrow}',
1075
+ ' emptyTitle={copy.transcriptEmptyTitle}',
1076
+ ' emptyDescription={copy.transcriptEmptyDescription}',
1077
+ ' pendingStopLabel={copy.stopTurn}',
1078
+ ' onStopGenerating={() => { void sessionRef.current?.interrupt().catch(() => {}); }}',
1079
+ ' widthClassName="w-full max-w-[52rem]"',
1080
+ ' contentPaddingBottomClassName="pb-4"',
1081
+ ' />',
1082
+ ' <div className="shrink-0 border-t border-[var(--nimi-border-subtle)]">',
1083
+ ' <CanonicalComposer',
1084
+ ' adapter={composerAdapter}',
1085
+ ' text={composerText}',
1086
+ ' onTextChange={setComposerText}',
1087
+ ' placeholder={copy.composerPlaceholder}',
1088
+ ' sendLabel={copy.send}',
1089
+ ' widthClassName="w-full max-w-[52rem]"',
1090
+ ' layout="stacked"',
1091
+ ' />',
1092
+ ' </div>',
1093
+ ' </Surface>',
1094
+ ' </div>',
1095
+ ' );',
1096
+ '}',
1097
+ '',
1098
+ ].join('\n');
861
1099
  }
862
1100
  return content;
863
1101
  }
@@ -950,6 +1188,28 @@ export function renderAppIdentityInput(identity) {
950
1188
  export function renderAppBuildProfile(options = {}) {
951
1189
  const identity = options.identity || null;
952
1190
  if (identity?.platform === 'web') return YAML.stringify(webBuildProfile(), { lineWidth: 0 });
1191
+ if (identity?.carrier === 'managed-web') {
1192
+ const targets = options.targets || {
1193
+ 'desktop-universal': {
1194
+ os: 'any',
1195
+ arch: 'any',
1196
+ build_command: 'pnpm run build',
1197
+ payload_path: 'dist/renderer',
1198
+ runtime_entry: 'payload/index.html',
1199
+ },
1200
+ };
1201
+ return YAML.stringify({
1202
+ build_profile_ref: 'managed-web-pnpm-vite',
1203
+ test_command: options.testCommand || 'pnpm run test:app',
1204
+ build_command: options.buildCommand || 'pnpm run build',
1205
+ output_path: 'dist/renderer',
1206
+ lockfile_path: 'pnpm-lock.yaml',
1207
+ lockfile_policy: LOCKFILE_POLICY,
1208
+ ci_install_command: 'pnpm install --frozen-lockfile',
1209
+ targets,
1210
+ profile_role: 'developer-workflow-input',
1211
+ }, { lineWidth: 0 });
1212
+ }
953
1213
  const targets = options.targets || (identity ? {
954
1214
  'windows-x86_64': {
955
1215
  os: 'windows',
@@ -1140,6 +1400,7 @@ function buildScaffoldIntent(identity, versions, targetDir = '') {
1140
1400
  initOrder: ['nimi-app create', 'pnpm install', 'pnpm exec nimi-app init'],
1141
1401
  profile: identity.profile,
1142
1402
  ...(identity.platform === 'web' ? { platform: 'web' } : {}),
1403
+ ...(identity.carrier === 'managed-web' ? { carrier: 'managed-web' } : {}),
1143
1404
  appId: identity.appId,
1144
1405
  appTitle: identity.appTitle,
1145
1406
  version: identity.version,
@@ -1161,7 +1422,7 @@ function buildScaffoldIntent(identity, versions, targetDir = '') {
1161
1422
  requiredStandardizedFeatureRefs: identity.capabilityResolution.requiredStandardizedFeatureRefs,
1162
1423
  devPort: identity.devPort,
1163
1424
  appIdentity: buildIdentityMapping(identity, targetDir),
1164
- dependencyMatrix: buildDependencyMatrix(identity.profile, versions, identity.capabilityResolution, identity.platform),
1425
+ dependencyMatrix: buildDependencyMatrix(identity.profile, versions, identity.capabilityResolution, identity.platform, identity.carrier),
1165
1426
  semantics: {
1166
1427
  role: 'app-scaffold-init-input',
1167
1428
  authority: 'app-tools-orchestration-input-not-platform-admission',
@@ -1257,7 +1518,7 @@ export function hashScaffoldContent(content) {
1257
1518
  return createHash('sha256').update(content).digest('hex');
1258
1519
  }
1259
1520
 
1260
- function buildDependencyMatrix(profile, versions, capabilityResolution, platform = 'desktop') {
1521
+ function buildDependencyMatrix(profile, versions, capabilityResolution, platform = 'desktop', carrier = 'native') {
1261
1522
  const matrix = {
1262
1523
  npm: {
1263
1524
  '@nimiplatform/app-tools': versions.appToolsVersion,
@@ -1279,7 +1540,13 @@ function buildDependencyMatrix(profile, versions, capabilityResolution, platform
1279
1540
  pnpm: versions.packageManager.replace(/^pnpm@/u, ''),
1280
1541
  },
1281
1542
  };
1282
- return platform === 'web' ? webDependencyMatrix(matrix) : matrix;
1543
+ if (platform === 'web') return webDependencyMatrix(matrix);
1544
+ if (carrier === 'managed-web') {
1545
+ for (const name of ['@electron/packager', 'electron', 'esbuild', 'pngjs']) {
1546
+ delete matrix.npm[name];
1547
+ }
1548
+ }
1549
+ return matrix;
1283
1550
  }
1284
1551
 
1285
1552
  function buildScaffoldLock(identity, versions, files, targetDir = '') {
@@ -1313,6 +1580,7 @@ function buildScaffoldLock(identity, versions, files, targetDir = '') {
1313
1580
  scaffoldVersion: SCAFFOLD_VERSION,
1314
1581
  profile: identity.profile,
1315
1582
  ...(identity.platform === 'web' ? { platform: 'web' } : {}),
1583
+ ...(identity.carrier === 'managed-web' ? { carrier: 'managed-web' } : {}),
1316
1584
  appId: identity.appId,
1317
1585
  appTitle: identity.appTitle,
1318
1586
  version: identity.version,
@@ -1340,7 +1608,7 @@ function buildScaffoldLock(identity, versions, files, targetDir = '') {
1340
1608
  },
1341
1609
  managedFileHashes,
1342
1610
  appOwnedInitialHashes,
1343
- dependencyMatrix: buildDependencyMatrix(identity.profile, versions, identity.capabilityResolution, identity.platform),
1611
+ dependencyMatrix: buildDependencyMatrix(identity.profile, versions, identity.capabilityResolution, identity.platform, identity.carrier),
1344
1612
  semantics: {
1345
1613
  initRole: 'developer-scaffold-initialization-after-install',
1346
1614
  nimicodingProjectionOwner: '@nimiplatform/nimi-coding',
@@ -1355,7 +1623,7 @@ function buildScaffoldLock(identity, versions, files, targetDir = '') {
1355
1623
  }
1356
1624
 
1357
1625
  function buildAppScaffoldSnapshotWithResolver(
1358
- { profile, platform = 'desktop', versions, appId, appTitle, version = DEFAULT_APP_VERSION, packageName, author, accentPack, features, targetDir = '' },
1626
+ { profile, platform = 'desktop', carrier = undefined, versions, appId, appTitle, version = DEFAULT_APP_VERSION, packageName, author, accentPack, features, targetDir = '' },
1359
1627
  featureResolver,
1360
1628
  ) {
1361
1629
  const identity = buildAppIdentity(
@@ -1369,6 +1637,7 @@ function buildAppScaffoldSnapshotWithResolver(
1369
1637
  features,
1370
1638
  featureResolver,
1371
1639
  platform,
1640
+ carrier,
1372
1641
  );
1373
1642
  const createFiles = [
1374
1643
  ...buildScaffoldFiles(identity, versions),
@@ -1399,6 +1668,7 @@ function buildAppScaffoldSnapshotWithResolver(
1399
1668
  version: identity.version,
1400
1669
  profile: identity.profile,
1401
1670
  ...(identity.platform === 'web' ? { platform: 'web' } : {}),
1671
+ ...(identity.carrier ? { carrier: identity.carrier } : {}),
1402
1672
  packageName: identity.packageName,
1403
1673
  packageAuthor: identity.author || null,
1404
1674
  cargoPackageName: identity.cargoPackageName,
@@ -1432,9 +1702,12 @@ export function buildAppScaffoldSnapshotFromIntent({ intent, versions, targetDir
1432
1702
  throw new Error(`Unsupported scaffold profile: ${String(intent?.profile || 'missing')}`);
1433
1703
  }
1434
1704
  const canonicalTargetDir = targetDir || intent?.appIdentity?.targetDir || '';
1705
+ const platform = intent.platform || 'desktop';
1706
+ const carrier = platform === 'web' ? undefined : (intent.carrier || 'native');
1435
1707
  const snapshot = buildAppScaffoldSnapshotWithResolver({
1436
1708
  profile: intent.profile,
1437
- platform: intent.platform || 'desktop',
1709
+ platform,
1710
+ carrier,
1438
1711
  versions,
1439
1712
  appId: intent.appId,
1440
1713
  appTitle: intent.appTitle,
@@ -1447,7 +1720,7 @@ export function buildAppScaffoldSnapshotFromIntent({ intent, versions, targetDir
1447
1720
  }, resolveAppScaffoldIntentFeatures);
1448
1721
  const expectedIntent = JSON.parse(snapshot.filesByPath.get(SCAFFOLD_INTENT_PATH).content);
1449
1722
  // @nimi-authority: rule.nimi.platform.app-ecosystem.p-scaf-018c
1450
- const immutableInputs = new Set(['intentVersion', 'scaffoldVersion', 'initRequired', 'initCommand', 'initOrder', 'profile', 'platform', 'appId', 'appTitle', 'version', 'packageName', 'packageAuthor', 'cargoPackageName', 'tauriIdentifier', 'accentPack', 'directFeatures', 'devPort', 'semantics']);
1723
+ const immutableInputs = new Set(['intentVersion', 'scaffoldVersion', 'initRequired', 'initCommand', 'initOrder', 'profile', 'platform', 'carrier', 'appId', 'appTitle', 'version', 'packageName', 'packageAuthor', 'cargoPackageName', 'tauriIdentifier', 'accentPack', 'directFeatures', 'devPort', 'semantics']);
1451
1724
  if (canonicalJson(Object.keys(intent).sort()) !== canonicalJson(Object.keys(expectedIntent).sort())) {
1452
1725
  throw new Error('Scaffold intent fields do not match the current canonical resolved intent');
1453
1726
  }
@@ -1481,6 +1754,7 @@ function buildAppScaffoldCreatePlanWithResolver(
1481
1754
  const snapshot = buildAppScaffoldSnapshotWithResolver({
1482
1755
  profile: resolvedInput.profile,
1483
1756
  platform: resolvedInput.platform || 'desktop',
1757
+ carrier: resolvedInput.carrier,
1484
1758
  versions,
1485
1759
  appId: resolvedInput.appId,
1486
1760
  appTitle: resolvedInput.appTitle,
@@ -1497,6 +1771,7 @@ function buildAppScaffoldCreatePlanWithResolver(
1497
1771
  preview: Object.freeze({
1498
1772
  targetDir: resolvedInput.targetDir,
1499
1773
  profile: resolvedInput.profile,
1774
+ ...(resolvedInput.carrier ? { carrier: resolvedInput.carrier } : {}),
1500
1775
  identity: snapshot.lock.appIdentity,
1501
1776
  directFeatures: snapshot.lock.directFeatures,
1502
1777
  resolvedModules: snapshot.lock.resolvedModules,
@@ -1557,7 +1832,7 @@ export function createAppScaffoldCandidate(input) {
1557
1832
  return createAppScaffold({ ...input, plan });
1558
1833
  }
1559
1834
 
1560
- export const APP_AUTHOR_DECLARATION_FIELDS = Object.freeze(['metadata', 'app_access', 'capability_contract_refs', 'required_standardized_feature_refs', 'storage_policy', 'safety_profile', 'public_slug']);
1835
+ export const APP_AUTHOR_DECLARATION_FIELDS = Object.freeze(['desktop', 'metadata', 'app_access', 'capability_contract_refs', 'required_standardized_feature_refs', 'storage_policy', 'safety_profile', 'public_slug']);
1561
1836
 
1562
1837
  // Source configuration is editable; existing scaffold checks still cover identity and carrier fields.
1563
1838
  export function hashScaffoldManagedContent(relativePath, content) {
@@ -0,0 +1,106 @@
1
+ import { parseDocument as parseYamlDocument, isMap, isScalar } from 'yaml';
2
+
3
+ // @nimi-authority: rule.nimi.platform.app-ecosystem.p-napp-014a
4
+
5
+ export const DESKTOP_WINDOW_DEFAULTS = Object.freeze({
6
+ width: 1280,
7
+ height: 840,
8
+ min_width: 480,
9
+ min_height: 420,
10
+ title_bar_style: 'native',
11
+ });
12
+
13
+ const DESKTOP_WINDOW_BOUNDS = Object.freeze({
14
+ width: Object.freeze([400, 2560]),
15
+ height: Object.freeze([360, 1600]),
16
+ min_width: Object.freeze([320, 1280]),
17
+ min_height: Object.freeze([320, 960]),
18
+ });
19
+
20
+ const ALLOWED_DESKTOP_KEYS = new Set(['window']);
21
+ const ALLOWED_WINDOW_KEYS = new Set(['width', 'height', 'min_width', 'min_height', 'title_bar_style']);
22
+ const ALLOWED_TITLE_BAR_STYLES = new Set(['native', 'hidden']);
23
+
24
+ function isPlainObject(value) {
25
+ return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
26
+ }
27
+
28
+ function assertDesktopWindowYamlIntegerNodes(yamlText, label) {
29
+ const doc = parseYamlDocument(yamlText, { keepSourceTokens: true });
30
+ if (!isMap(doc.contents)) return;
31
+ const desktopNode = doc.contents.get('desktop', true);
32
+ if (!isMap(desktopNode)) return;
33
+ const windowNode = desktopNode.get('window', true);
34
+ if (!isMap(windowNode)) return;
35
+ for (const pair of windowNode.items) {
36
+ const key = isScalar(pair.key) ? String(pair.key.value) : '';
37
+ if (!['width', 'height', 'min_width', 'min_height'].includes(key)) continue;
38
+ if (!isScalar(pair.value) || typeof pair.value.value !== 'number') {
39
+ throw new Error(`${label}.window.${key} must be a base-10 YAML integer`);
40
+ }
41
+ const rawSource = typeof pair.value.srcToken?.source === 'string'
42
+ ? pair.value.srcToken.source.trim()
43
+ : String(pair.value.value);
44
+ if (!/^[0-9]+$/u.test(rawSource)) {
45
+ throw new Error(`${label}.window.${key} must be a base-10 YAML integer`);
46
+ }
47
+ }
48
+ }
49
+
50
+ /**
51
+ * Validates optional `desktop` declaration (`desktop.window`) with closed keys
52
+ * and exact geometry bounds matching Runtime (`managed_web.go`) and Desktop
53
+ * (`managed-web-snapshot.ts`). Returns `undefined` when omitted, or a clean
54
+ * normalized object preserving only declared keys.
55
+ */
56
+ export function validateManifestDesktop(desktop, label = 'nimi.app.yaml desktop', yamlText = null) {
57
+ if (desktop === undefined) return undefined;
58
+ if (typeof yamlText === 'string') {
59
+ assertDesktopWindowYamlIntegerNodes(yamlText, label);
60
+ }
61
+ if (!isPlainObject(desktop)) {
62
+ throw new Error(`${label} must be a mapping`);
63
+ }
64
+ for (const key of Object.keys(desktop)) {
65
+ if (!ALLOWED_DESKTOP_KEYS.has(key)) {
66
+ throw new Error(`${label} contains unsupported field: ${key}`);
67
+ }
68
+ }
69
+ if (desktop.window === undefined) {
70
+ return {};
71
+ }
72
+ const rawWindow = desktop.window;
73
+ if (!isPlainObject(rawWindow)) {
74
+ throw new Error(`${label}.window must be a mapping`);
75
+ }
76
+ const normalizedWindow = {};
77
+ for (const key of Object.keys(rawWindow)) {
78
+ if (!ALLOWED_WINDOW_KEYS.has(key)) {
79
+ throw new Error(`${label}.window contains unsupported field: ${key}`);
80
+ }
81
+ const value = rawWindow[key];
82
+ if (key === 'title_bar_style') {
83
+ if (typeof value !== 'string' || !ALLOWED_TITLE_BAR_STYLES.has(value)) {
84
+ throw new Error(`${label}.window.title_bar_style must be "native" or "hidden"`);
85
+ }
86
+ normalizedWindow.title_bar_style = value;
87
+ continue;
88
+ }
89
+ const [min, max] = DESKTOP_WINDOW_BOUNDS[key];
90
+ if (typeof value !== 'number' || !Number.isSafeInteger(value) || value < min || value > max) {
91
+ throw new Error(`${label}.window.${key} must be an integer between ${min} and ${max}`);
92
+ }
93
+ normalizedWindow[key] = value;
94
+ }
95
+ const effectiveWidth = normalizedWindow.width ?? DESKTOP_WINDOW_DEFAULTS.width;
96
+ const effectiveHeight = normalizedWindow.height ?? DESKTOP_WINDOW_DEFAULTS.height;
97
+ const effectiveMinWidth = normalizedWindow.min_width ?? DESKTOP_WINDOW_DEFAULTS.min_width;
98
+ const effectiveMinHeight = normalizedWindow.min_height ?? DESKTOP_WINDOW_DEFAULTS.min_height;
99
+ if (effectiveMinWidth > effectiveWidth) {
100
+ throw new Error(`${label}.window.min_width (${effectiveMinWidth}) must not exceed width (${effectiveWidth})`);
101
+ }
102
+ if (effectiveMinHeight > effectiveHeight) {
103
+ throw new Error(`${label}.window.min_height (${effectiveMinHeight}) must not exceed height (${effectiveHeight})`);
104
+ }
105
+ return { window: normalizedWindow };
106
+ }
package/lib/index.mjs CHANGED
@@ -133,6 +133,7 @@ export function createApp(cwd, options = {}) {
133
133
  dir: options.dir,
134
134
  profile: options.profile,
135
135
  platform: options.platform,
136
+ carrier: options.carrier,
136
137
  appId: options.appId,
137
138
  name: options.name,
138
139
  title: options.title,