@nimiplatform/app-tools 0.2.0 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -68,6 +68,10 @@ pnpm dev
68
68
 
69
69
  `dev` uses the Desktop supervisor. Direct Electron, Tauri or renderer launch cannot claim protected Nimi access. Process running and Nimi Access ready remain separate states.
70
70
 
71
+ The default `windows-x86_64` build profile runs `build:electron:production`. It rebuilds the renderer and Electron main/preload, then creates a fresh, non-installer `dist-electron-package/<app>-shell-win32-x64/` directory with `asar` disabled and an App-specific `<app>-shell.exe`. The production main bundle has a compile-time production marker and rejects every `--nimi-dev-renderer-url` argument; packaged renderer assets stay relative under `dist/`. The protected native binding is resolved from Kit's optional dependency and is never declared directly by the App.
72
+
73
+ Tauri remains an explicit alternative through `pnpm run build:tauri:production`; selecting it requires an explicit Tauri build profile rather than changing the default Electron carrier.
74
+
71
75
  ## Canonical release boundary
72
76
 
73
77
  The production chain is singular. Its publisher GitHub Release stage is
@@ -88,7 +92,7 @@ public App repository
88
92
 
89
93
  The registry references publisher Release assets and never mirrors bytes. GitHub Release is not catalog admission; catalog admission is not installed; installed is not running; running is not Nimi Access ready.
90
94
 
91
- Repository administration must enable a protected `v*` tag ruleset and GitHub immutable releases before production. The managed tag workflow fetches the repository's canonical default branch and rejects a tag commit outside that history before production preflight, build, attestation, or Release. A fine-grained `GITHUB_REPOSITORY_ADMIN_TOKEN` secret with repository Administration read permission lets the workflow verify protected-tag and immutable-release settings; it cannot enable or change them. Manual workflow dispatch runs only the non-production build/package path. On Windows, the tag-only production build imports the publisher PFX from `WINDOWS_CERTIFICATE_BASE64`/`WINDOWS_CERTIFICATE_PASSWORD`, signs the exact declared Host, and removes the temporary certificate; production pack only re-verifies Authenticode and never signs. A successful tag workflow creates the immutable publisher GitHub Release and no registry, installed, running, or Nimi Access truth. Registry submission, the shared installed carrier, and installed launch remain unavailable.
95
+ Repository administration must enable a protected `v*` tag ruleset and GitHub immutable releases before production. The managed tag workflow fetches the repository's canonical default branch and rejects a tag commit outside that history before production preflight, build, attestation, or Release. A fine-grained `GITHUB_REPOSITORY_ADMIN_TOKEN` secret with repository Administration read permission lets the workflow verify protected-tag and immutable-release settings; it cannot enable or change them. Manual workflow dispatch runs only the non-production build/package path. On Windows, the tag-only production build invokes the App-declared production build with no certificate-secret mapping or app-tools-owned signing step. Optional native signing remains publisher-owned and must already be reflected in the final exact Runtime entry before production pack observes and records its native-trust posture; a present invalid or unresolved signature still fails closed. A successful tag workflow creates the immutable publisher GitHub Release and no registry, installed, running, or Nimi Access truth. Registry submission, the shared installed carrier, and installed launch remain unavailable.
92
96
 
93
97
  ## Acceptance status
94
98
 
package/lib/app-pack.mjs CHANGED
@@ -1,5 +1,9 @@
1
1
  // @nimi-authority: rule.nimi.platform.app-ecosystem.p-scaf-009b
2
+ // @nimi-authority: rule.nimi.platform.app-ecosystem.p-napp-014a
2
3
  // @nimi-authority: rule.nimi.platform.app-ecosystem.p-napp-018a
4
+ // @nimi-authority: rule.nimi.platform.app-ecosystem.p-napp-024a
5
+ // @nimi-authority: rule.nimi.platform.app-ecosystem.p-napp-024b
6
+ // @nimi-authority: rule.nimi.platform.app-ecosystem.p-napp-034a
3
7
 
4
8
  import { createHash } from 'node:crypto';
5
9
  import {
@@ -11,13 +15,15 @@ import {
11
15
  writeFileSync,
12
16
  } from 'node:fs';
13
17
  import path from 'node:path';
14
- import { spawnSync } from 'node:child_process';
15
18
  import { parse as parseYaml } from 'yaml';
19
+ import { observeWindowsExecutableFacts } from './windows-powershell.mjs';
16
20
 
17
21
  const PACKAGE_FORMAT = 'nimi.app-package/v1';
18
22
  const TARGET_METADATA_FORMAT = 'nimi.app-target-candidate/v1';
19
23
  const AGGREGATE_FORMAT = 'nimi.app-release-candidate/v1';
20
24
  const BUILD_PROFILE_PATH = '.nimi/config/build-profile.yaml';
25
+ const ELECTRON_BUILD_PROFILE_REF = 'electron-packager-pnpm-vite';
26
+ const TAURI_BUILD_PROFILE_REF = 'tauri-pnpm-vite';
21
27
  const OUTPUT_DIR = 'dist/nimi-app';
22
28
  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;
23
29
  const TARGETS = Object.freeze({
@@ -38,6 +44,10 @@ function canonicalJson(value) {
38
44
  return `${JSON.stringify(sortedValue(value), null, 2)}\n`;
39
45
  }
40
46
 
47
+ function sameCanonicalValue(left, right) {
48
+ return JSON.stringify(sortedValue(left)) === JSON.stringify(sortedValue(right));
49
+ }
50
+
41
51
  function canonicalRelative(value, field) {
42
52
  if (typeof value !== 'string' || !value || value !== value.trim() || value.includes('\\')) {
43
53
  throw new Error(`${field} must be a canonical relative path`);
@@ -261,20 +271,30 @@ function readPackInputs(targetDir, targetId) {
261
271
  }
262
272
  const manifestPath = path.join(targetDir, 'nimi.app.yaml');
263
273
  const manifest = readYaml(manifestPath, 'nimi.app.yaml');
264
- const cargoPath = path.join(targetDir, 'src-tauri', 'Cargo.toml');
265
- if (!existsSync(cargoPath)) throw new Error('src-tauri/Cargo.toml is missing');
266
- const tauriConfig = readJson(path.join(targetDir, 'src-tauri', 'tauri.conf.json'), 'src-tauri/tauri.conf.json');
267
274
  const buildProfile = readYaml(path.join(targetDir, BUILD_PROFILE_PATH), BUILD_PROFILE_PATH);
275
+ const buildProfileRef = buildProfile.build_profile_ref;
276
+ if (buildProfileRef !== ELECTRON_BUILD_PROFILE_REF && buildProfileRef !== TAURI_BUILD_PROFILE_REF) {
277
+ throw new Error(`${BUILD_PROFILE_PATH} build_profile_ref is unsupported: ${String(buildProfileRef)}`);
278
+ }
279
+ const requiresTauri = buildProfileRef === TAURI_BUILD_PROFILE_REF;
268
280
  const appId = String(manifest.app_id || '');
269
281
  const version = String(packageJson.version || '');
270
282
  if (!/^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)+$/u.test(appId)) throw new Error('nimi.app.yaml app_id must be canonical and dotted');
271
- if (
272
- !SEMVER_PATTERN.test(version)
273
- || manifest.version !== version
274
- || readCargoPackageVersion(readFileSync(cargoPath, 'utf8')) !== version
275
- || tauriConfig.version !== version
276
- ) {
277
- throw new Error('package.json, nimi.app.yaml, Cargo.toml, and tauri.conf.json versions must be exact and lockstep before pack');
283
+ if (!SEMVER_PATTERN.test(version) || manifest.version !== version) {
284
+ throw new Error('package.json and nimi.app.yaml versions must be exact and lockstep before pack');
285
+ }
286
+ if (requiresTauri) {
287
+ const cargoPath = path.join(targetDir, 'src-tauri', 'Cargo.toml');
288
+ const tauriPath = path.join(targetDir, 'src-tauri', 'tauri.conf.json');
289
+ if (!existsSync(cargoPath)) throw new Error('src-tauri/Cargo.toml is missing');
290
+ if (!existsSync(tauriPath)) throw new Error('src-tauri/tauri.conf.json is missing');
291
+ const tauriConfig = readJson(tauriPath, 'src-tauri/tauri.conf.json');
292
+ if (
293
+ readCargoPackageVersion(readFileSync(cargoPath, 'utf8')) !== version
294
+ || tauriConfig.version !== version
295
+ ) {
296
+ throw new Error('package.json, nimi.app.yaml, Cargo.toml, and tauri.conf.json versions must be exact and lockstep before pack');
297
+ }
278
298
  }
279
299
  const configured = buildProfile.targets?.[targetId];
280
300
  if (!configured || typeof configured !== 'object' || Array.isArray(configured)) throw new Error(`Build profile does not declare target: ${targetId}`);
@@ -291,37 +311,111 @@ function readPackInputs(targetDir, targetId) {
291
311
  return { target, targetId, targetDir, packageJson, licensePath, manifestPath, appId, version, payloadPath: payload.resolved, runtimeEntry, runtimeHostPath };
292
312
  }
293
313
 
294
- function requireCommand(result, label) {
295
- if (result.status !== 0) {
296
- const detail = [result.error?.message, result.stdout, result.stderr].filter(Boolean).join('\n').trim();
297
- throw new Error(`${label} failed${detail ? `: ${detail}` : ''}`);
314
+ export function classifyWindowsNativeTrustObservation(observation) {
315
+ const {
316
+ status,
317
+ signature_type: signatureType,
318
+ certificate_subject: certificateSubject,
319
+ } = observation || {};
320
+ if (status === 'NotSigned' && signatureType === 'None' && certificateSubject === null) {
321
+ return Object.freeze({
322
+ posture: 'production-unsigned',
323
+ windows_authenticode: 'unsigned',
324
+ certificate_subject: null,
325
+ });
326
+ }
327
+ if (
328
+ status === 'Valid'
329
+ && signatureType === 'Authenticode'
330
+ && typeof certificateSubject === 'string'
331
+ && certificateSubject.length > 0
332
+ && certificateSubject === certificateSubject.trim()
333
+ ) {
334
+ return Object.freeze({
335
+ posture: 'observed-valid-native-signature',
336
+ windows_authenticode: 'valid',
337
+ certificate_subject: certificateSubject,
338
+ });
298
339
  }
299
- return [result.stdout, result.stderr].filter(Boolean).join('\n');
340
+ throw new Error(`Windows Authenticode verification failed: status=${String(status)}, type=${String(signatureType)}, signer=${certificateSubject === null ? 'absent' : 'present'}`);
300
341
  }
301
342
 
302
- function verifyWindowsNativeTrust(input) {
343
+ function observeProductionWindowsFacts(input, archivedRuntimeEntryBytes) {
303
344
  if (process.platform !== 'win32' || process.arch !== 'x64') throw new Error('Production Windows pack must run on windows-x86_64');
304
- const result = spawnSync('powershell.exe', [
305
- '-NoProfile',
306
- '-NonInteractive',
307
- '-Command',
308
- "$signature = Get-AuthenticodeSignature -LiteralPath $env:NIMI_APP_SIGN_TARGET; if ($signature.Status -ne 'Valid' -or -not $signature.SignerCertificate) { Write-Error ('Authenticode status: ' + $signature.Status); exit 1 }; $signature.SignerCertificate.Subject",
309
- ], {
310
- encoding: 'utf8',
311
- env: { ...process.env, NIMI_APP_SIGN_TARGET: input.runtimeHostPath },
312
- });
313
- const subject = requireCommand(result, 'Windows Authenticode verification').trim();
314
- if (!subject) throw new Error('Windows Authenticode verification returned no signer subject');
315
- return {
316
- posture: 'observed-valid-native-signature',
317
- windows_authenticode: 'valid',
318
- certificate_subject: subject,
319
- };
345
+ const observed = observeWindowsExecutableFacts(input.runtimeHostPath);
346
+ const currentRuntimeEntryBytes = readFileSync(input.runtimeHostPath);
347
+ if (!archivedRuntimeEntryBytes.equals(currentRuntimeEntryBytes)) {
348
+ throw new Error('Production Runtime entry changed while native and execution facts were observed');
349
+ }
350
+ const nativeTrust = classifyWindowsNativeTrustObservation(observed.authenticode);
351
+ return { nativeTrust, executionProfile: observed.execution_profile };
352
+ }
353
+
354
+ function resolveTargetFacts(input, production, archivedRuntimeEntryBytes) {
355
+ if (!production) {
356
+ return {
357
+ nativeTrust: { posture: 'development-unsigned' },
358
+ executionProfile: null,
359
+ };
360
+ }
361
+ return observeProductionWindowsFacts(input, archivedRuntimeEntryBytes);
362
+ }
363
+
364
+ function validateNativeExecutionFacts(nativeTrust, executionProfile, label) {
365
+ if (!nativeTrust || typeof nativeTrust !== 'object' || Array.isArray(nativeTrust)) {
366
+ throw new Error(`${label} native_trust must be an object`);
367
+ }
368
+ if (nativeTrust.posture === 'development-unsigned') {
369
+ if (executionProfile !== null || Object.keys(nativeTrust).length !== 1) {
370
+ throw new Error(`${label} development native/execution posture is inconsistent`);
371
+ }
372
+ return;
373
+ }
374
+ if (
375
+ !executionProfile
376
+ || typeof executionProfile !== 'object'
377
+ || Array.isArray(executionProfile)
378
+ || executionProfile.requested_execution_level !== 'asInvoker'
379
+ || executionProfile.ui_access !== false
380
+ || Object.keys(executionProfile).sort().join(',') !== 'requested_execution_level,ui_access'
381
+ ) {
382
+ throw new Error(`${label} ordinary Windows execution_profile must be exactly asInvoker with ui_access=false`);
383
+ }
384
+ if (nativeTrust.posture === 'production-unsigned') {
385
+ if (
386
+ nativeTrust.windows_authenticode !== 'unsigned'
387
+ || nativeTrust.certificate_subject !== null
388
+ || Object.keys(nativeTrust).sort().join(',') !== 'certificate_subject,posture,windows_authenticode'
389
+ ) {
390
+ throw new Error(`${label} production unsigned native_trust is inconsistent`);
391
+ }
392
+ return;
393
+ }
394
+ if (nativeTrust.posture === 'observed-valid-native-signature') {
395
+ if (
396
+ nativeTrust.windows_authenticode !== 'valid'
397
+ || typeof nativeTrust.certificate_subject !== 'string'
398
+ || !nativeTrust.certificate_subject
399
+ || nativeTrust.certificate_subject !== nativeTrust.certificate_subject.trim()
400
+ || Object.keys(nativeTrust).sort().join(',') !== 'certificate_subject,posture,windows_authenticode'
401
+ ) {
402
+ throw new Error(`${label} signed native_trust is inconsistent`);
403
+ }
404
+ return;
405
+ }
406
+ throw new Error(`${label} native_trust posture is unsupported`);
320
407
  }
321
408
 
322
- function resolveNativeTrust(input, production) {
323
- if (!production) return { posture: 'development-unsigned' };
324
- return verifyWindowsNativeTrust(input);
409
+ function readPackageManifestFromArchive(entries, label) {
410
+ const entry = entries.get('manifest.json');
411
+ if (!entry) throw new Error(`${label} archive manifest.json is missing`);
412
+ try {
413
+ const manifest = JSON.parse(entry.bytes.toString('utf8'));
414
+ if (!manifest || typeof manifest !== 'object' || Array.isArray(manifest)) throw new Error('root must be an object');
415
+ return manifest;
416
+ } catch (error) {
417
+ throw new Error(`${label} archive manifest.json is invalid: ${error instanceof Error ? error.message : String(error)}`);
418
+ }
325
419
  }
326
420
 
327
421
  export function packAppTarget(cwd, options = {}) {
@@ -333,8 +427,9 @@ export function packAppTarget(cwd, options = {}) {
333
427
  const name = `payload/${entry.relative.replaceAll('\\', '/')}`;
334
428
  return { name, bytes: entry.bytes, mode: name === input.runtimeEntry ? 0o755 : entry.mode };
335
429
  });
336
- if (!payloadEntries.some((entry) => entry.name === input.runtimeEntry)) throw new Error(`runtime_entry is missing from target payload: ${input.runtimeEntry}`);
337
- const nativeTrust = resolveNativeTrust(input, options.production === true);
430
+ const runtimeEntry = payloadEntries.find((entry) => entry.name === input.runtimeEntry);
431
+ if (!runtimeEntry) throw new Error(`runtime_entry is missing from target payload: ${input.runtimeEntry}`);
432
+ const { nativeTrust, executionProfile } = resolveTargetFacts(input, options.production === true, runtimeEntry.bytes);
338
433
  const packageManifest = {
339
434
  format: PACKAGE_FORMAT,
340
435
  app_id: input.appId,
@@ -344,6 +439,7 @@ export function packAppTarget(cwd, options = {}) {
344
439
  arch: input.target.arch,
345
440
  runtime_entry: input.runtimeEntry,
346
441
  native_trust: nativeTrust,
442
+ execution_profile: executionProfile,
347
443
  };
348
444
  const archive = writeNimiAppArchive([
349
445
  { name: 'LICENSE', bytes: readFileSync(input.licensePath), mode: 0o644 },
@@ -370,6 +466,7 @@ export function packAppTarget(cwd, options = {}) {
370
466
  sha256,
371
467
  runtime_entry: input.runtimeEntry,
372
468
  native_trust: packageManifest.native_trust,
469
+ execution_profile: packageManifest.execution_profile,
373
470
  };
374
471
  writeFileSync(metadataPath, canonicalJson(metadata));
375
472
  return { ok: true, command: 'pack', dir: targetDir, artifactPath, metadataPath, ...metadata };
@@ -386,13 +483,39 @@ export function aggregateAppTargetCandidates(cwd, options = {}) {
386
483
  const version = targets[0].version;
387
484
  const seen = new Set();
388
485
  for (const target of targets) {
486
+ const metadataLabel = `${target.target_id || 'unknown'} target metadata`;
389
487
  if (target.format !== TARGET_METADATA_FORMAT || target.app_id !== appId || target.version !== version) throw new Error('Target metadata cannot be aggregated across App releases');
390
488
  if (seen.has(target.target_id)) throw new Error(`Duplicate target metadata: ${target.target_id}`);
391
489
  seen.add(target.target_id);
392
- const artifactPath = path.join(outputDir, target.asset_name);
490
+ const expectedTarget = TARGETS[target.target_id];
491
+ if (!expectedTarget || target.os !== expectedTarget.os || target.arch !== expectedTarget.arch) {
492
+ throw new Error(`Target metadata identity is invalid: ${target.target_id}`);
493
+ }
494
+ const assetName = canonicalRelative(target.asset_name, `${metadataLabel}.asset_name`);
495
+ if (assetName !== path.basename(assetName)) throw new Error(`Target asset_name must be a direct file name: ${assetName}`);
496
+ if (!Number.isSafeInteger(target.size) || target.size <= 0 || !/^[a-f0-9]{64}$/u.test(target.sha256)) {
497
+ throw new Error(`Target artifact size or SHA-256 is invalid: ${assetName}`);
498
+ }
499
+ const runtimeEntry = canonicalRelative(target.runtime_entry, `${metadataLabel}.runtime_entry`);
500
+ if (!runtimeEntry.startsWith('payload/')) throw new Error(`Target runtime_entry must resolve inside payload: ${runtimeEntry}`);
501
+ validateNativeExecutionFacts(target.native_trust, target.execution_profile, metadataLabel);
502
+ const artifactPath = path.join(outputDir, assetName);
393
503
  if (!existsSync(artifactPath)) throw new Error(`Target artifact is missing: ${target.asset_name}`);
394
504
  const bytes = readFileSync(artifactPath);
395
505
  if (bytes.length !== target.size || createHash('sha256').update(bytes).digest('hex') !== target.sha256) throw new Error(`Target artifact changed after pack: ${target.asset_name}`);
506
+ const entries = readNimiAppArchive(bytes);
507
+ const manifest = readPackageManifestFromArchive(entries, metadataLabel);
508
+ if (manifest.format !== PACKAGE_FORMAT) throw new Error(`Target archive manifest format is invalid: ${target.asset_name}`);
509
+ for (const field of ['app_id', 'version', 'target_id', 'os', 'arch', 'runtime_entry', 'native_trust', 'execution_profile']) {
510
+ if (!sameCanonicalValue(target[field], manifest[field])) {
511
+ throw new Error(`Target metadata does not match archive manifest ${field}: ${target.asset_name}`);
512
+ }
513
+ }
514
+ validateNativeExecutionFacts(manifest.native_trust, manifest.execution_profile, `${target.asset_name} archive manifest`);
515
+ const runtimeEntryArchive = entries.get(runtimeEntry);
516
+ if (!runtimeEntryArchive || runtimeEntryArchive.mode !== 0o755) {
517
+ throw new Error(`Target archive runtime_entry is missing or non-executable: ${runtimeEntry}`);
518
+ }
396
519
  }
397
520
  const candidate = { format: AGGREGATE_FORMAT, app_id: appId, version, targets: targets.sort((left, right) => compareText(left.target_id, right.target_id)) };
398
521
  const candidatePath = path.join(outputDir, `${appId}-${version}.candidate.json`);
@@ -37,6 +37,9 @@ const SYNCHRONIZED_NIMI_PACKAGES = new Set([
37
37
  ...KIT_OWNED_NATIVE_CARRIERS,
38
38
  ]);
39
39
  const BUILD_PROFILE_PATH = '.nimi/config/build-profile.yaml';
40
+ const ELECTRON_BUILD_PROFILE_REF = 'electron-packager-pnpm-vite';
41
+ const TAURI_BUILD_PROFILE_REF = 'tauri-pnpm-vite';
42
+ const SUPPORTED_BUILD_PROFILE_REFS = new Set([ELECTRON_BUILD_PROFILE_REF, TAURI_BUILD_PROFILE_REF]);
40
43
  const MANAGED_WORKFLOW_PATH = '.github/workflows/nimi-app-release.yml';
41
44
  const APP_IDENTITY_PATH = '.nimi/config/app-identity.yaml';
42
45
  const SUBMISSION_PATH = '.nimi/admission/submission.yaml';
@@ -605,23 +608,45 @@ function assertNoStandaloneParentSources(targetDir) {
605
608
  }
606
609
  }
607
610
 
608
- function readProjectLifecycleFiles(targetDir) {
611
+ function cargoPackageNameFromNpmPackageName(packageName) {
612
+ const normalized = String(packageName || '')
613
+ .trim()
614
+ .toLowerCase()
615
+ .replace(/^@/u, '')
616
+ .replace(/\//gu, '-')
617
+ .replace(/[^a-z0-9-]+/gu, '-')
618
+ .replace(/^-+|-+$/gu, '');
619
+ if (!normalized) throw new Error('package.json name must produce a canonical cargo_package_name');
620
+ return `${normalized}-shell`;
621
+ }
622
+
623
+ function tauriIdentifierFromAppId(appId) {
624
+ return `ai.nimi.apps.${appId}`;
625
+ }
626
+
627
+ function readProjectLifecycleFiles(targetDir, buildProfileRef) {
609
628
  const packagePath = path.join(targetDir, 'package.json');
610
- const cargoPath = path.join(targetDir, 'src-tauri', 'Cargo.toml');
611
- const tauriPath = path.join(targetDir, 'src-tauri', 'tauri.conf.json');
612
- for (const requiredPath of [packagePath, cargoPath, tauriPath]) {
613
- if (!existsSync(requiredPath)) throw new Error(`Required App lifecycle file is missing: ${path.relative(targetDir, requiredPath)}`);
614
- }
615
- return {
629
+ if (!existsSync(packagePath)) throw new Error('Required App lifecycle file is missing: package.json');
630
+ const files = {
616
631
  packagePath,
617
632
  packageSource: readFileSync(packagePath, 'utf8'),
618
633
  packageJson: readJsonFile(packagePath, 'package.json'),
619
- cargoPath,
620
- cargoSource: readFileSync(cargoPath, 'utf8'),
621
- tauriPath,
622
- tauriSource: readFileSync(tauriPath, 'utf8'),
623
- tauriConfig: readJsonFile(tauriPath, 'src-tauri/tauri.conf.json'),
634
+ cargoPath: null,
635
+ cargoSource: null,
636
+ tauriPath: null,
637
+ tauriSource: null,
638
+ tauriConfig: null,
624
639
  };
640
+ if (buildProfileRef !== TAURI_BUILD_PROFILE_REF) return files;
641
+ files.cargoPath = path.join(targetDir, 'src-tauri', 'Cargo.toml');
642
+ files.tauriPath = path.join(targetDir, 'src-tauri', 'tauri.conf.json');
643
+ for (const requiredPath of [files.cargoPath, files.tauriPath]) {
644
+ if (!existsSync(requiredPath)) throw new Error(`Required App lifecycle file is missing: ${path.relative(targetDir, requiredPath)}`);
645
+ }
646
+ files.cargoSource = readFileSync(files.cargoPath, 'utf8');
647
+ files.tauriSource = readFileSync(files.tauriPath, 'utf8');
648
+ files.tauriConfig = readJsonFile(files.tauriPath, 'src-tauri/tauri.conf.json');
649
+ return files;
625
650
  }
626
651
 
627
652
  function readCargoPackageVersion(source) {
@@ -654,16 +679,18 @@ function readCargoPackageName(source) {
654
679
  throw new Error('src-tauri/Cargo.toml [package] name is missing');
655
680
  }
656
681
 
657
- function assertVersionLockstep(files, descriptor) {
682
+ function assertVersionLockstep(files, descriptor, buildProfileRef) {
658
683
  const version = files.packageJson.version;
659
684
  if (typeof version !== 'string' || !SEMVER_PATTERN.test(version)) {
660
685
  throw new Error('package.json version must be an exact semantic version');
661
686
  }
662
- const observed = [
663
- ['nimi.app.yaml', descriptor.version],
664
- ['src-tauri/Cargo.toml', readCargoPackageVersion(files.cargoSource)],
665
- ['src-tauri/tauri.conf.json', files.tauriConfig.version],
666
- ];
687
+ const observed = [['nimi.app.yaml', descriptor.version]];
688
+ if (buildProfileRef === TAURI_BUILD_PROFILE_REF) {
689
+ observed.push(
690
+ ['src-tauri/Cargo.toml', readCargoPackageVersion(files.cargoSource)],
691
+ ['src-tauri/tauri.conf.json', files.tauriConfig.version],
692
+ );
693
+ }
667
694
  for (const [name, candidate] of observed) {
668
695
  if (candidate !== null && candidate !== undefined && candidate !== version) {
669
696
  throw new Error(`${name} version must match package.json version ${version}`);
@@ -672,7 +699,7 @@ function assertVersionLockstep(files, descriptor) {
672
699
  return version;
673
700
  }
674
701
 
675
- function assertCanonicalAuthoringInputs(targetDir, descriptor, files, version) {
702
+ function assertCanonicalAuthoringInputs(targetDir, descriptor, files, version, nativeIdentity) {
676
703
  const identityPath = path.join(targetDir, APP_IDENTITY_PATH);
677
704
  const submissionPath = path.join(targetDir, SUBMISSION_PATH);
678
705
  if (!existsSync(identityPath)) throw new Error(`Required App lifecycle file is missing: ${APP_IDENTITY_PATH}`);
@@ -687,8 +714,8 @@ function assertCanonicalAuthoringInputs(targetDir, descriptor, files, version) {
687
714
  display_name: descriptor.displayName,
688
715
  version,
689
716
  npm_package_name: canonicalInputText(files.packageJson.name, 'package.json name'),
690
- cargo_package_name: readCargoPackageName(files.cargoSource),
691
- tauri_identifier: files.tauriConfig.identifier,
717
+ cargo_package_name: nativeIdentity.cargoPackageName,
718
+ tauri_identifier: nativeIdentity.tauriIdentifier,
692
719
  package_author: packageAuthor,
693
720
  identity_role: 'scaffold-generated-authoring-input',
694
721
  };
@@ -802,6 +829,12 @@ function readBuildProfile(targetDir) {
802
829
  if (profile.profile_role !== 'developer-workflow-input') {
803
830
  throw new Error(`${BUILD_PROFILE_PATH} profile_role must be developer-workflow-input`);
804
831
  }
832
+ const buildProfileRef = typeof profile.build_profile_ref === 'string'
833
+ ? profile.build_profile_ref
834
+ : '';
835
+ if (!SUPPORTED_BUILD_PROFILE_REFS.has(buildProfileRef)) {
836
+ throw new Error(`${BUILD_PROFILE_PATH} build_profile_ref is unsupported: ${String(profile.build_profile_ref)}`);
837
+ }
805
838
  const targets = profile.targets === undefined ? {} : profile.targets;
806
839
  if (!targets || typeof targets !== 'object' || Array.isArray(targets)) {
807
840
  throw new Error(`${BUILD_PROFILE_PATH} targets must be an object`);
@@ -819,6 +852,7 @@ function readBuildProfile(targetDir) {
819
852
  }
820
853
  }
821
854
  return {
855
+ buildProfileRef,
822
856
  testCommand: canonicalOwnerCommand(profile.test_command, `${BUILD_PROFILE_PATH} test_command`),
823
857
  buildCommand: canonicalOwnerCommand(profile.build_command, `${BUILD_PROFILE_PATH} build_command`),
824
858
  targets,
@@ -848,7 +882,7 @@ function selectBuildOwner(profile, requestedTarget) {
848
882
  return { target, command, payloadPath, runtimeEntry };
849
883
  }
850
884
 
851
- function resolveProductionSignTarget(targetDir, selected) {
885
+ function assertProductionRuntimeEntry(targetDir, selected) {
852
886
  const projectRoot = path.resolve(targetDir);
853
887
  const payloadPath = path.resolve(projectRoot, ...selected.payloadPath.split('/'));
854
888
  const projectPrefix = `${projectRoot}${path.sep}`;
@@ -856,25 +890,26 @@ function resolveProductionSignTarget(targetDir, selected) {
856
890
  throw new Error(`Production payload is missing or noncanonical: ${selected.payloadPath}`);
857
891
  }
858
892
  const payloadStat = lstatSync(payloadPath);
859
- let signTarget = payloadPath;
893
+ let runtimeTarget = payloadPath;
860
894
  if (payloadStat.isDirectory()) {
861
895
  const runtimeRelative = selected.runtimeEntry.slice('payload/'.length);
862
- signTarget = path.resolve(payloadPath, ...runtimeRelative.split('/'));
896
+ runtimeTarget = path.resolve(payloadPath, ...runtimeRelative.split('/'));
897
+ } else if (payloadStat.isFile() && selected.runtimeEntry !== `payload/${path.basename(payloadPath)}`) {
898
+ throw new Error(`Production Runtime entry does not select the direct payload file: ${selected.runtimeEntry}`);
863
899
  } else if (!payloadStat.isFile() || payloadStat.isSymbolicLink()) {
864
900
  throw new Error(`Production payload is not a direct file or directory: ${selected.payloadPath}`);
865
901
  }
866
902
  const payloadPrefix = `${payloadPath}${path.sep}`;
867
903
  if (
868
- !existsSync(signTarget)
869
- || (!payloadStat.isFile() && !signTarget.startsWith(payloadPrefix))
904
+ !existsSync(runtimeTarget)
905
+ || (!payloadStat.isFile() && !runtimeTarget.startsWith(payloadPrefix))
870
906
  ) {
871
907
  throw new Error(`Production Runtime entry is missing or noncanonical: ${selected.runtimeEntry}`);
872
908
  }
873
- const signTargetStat = lstatSync(signTarget);
874
- if (!signTargetStat.isFile() || signTargetStat.isSymbolicLink()) {
909
+ const runtimeTargetStat = lstatSync(runtimeTarget);
910
+ if (!runtimeTargetStat.isFile() || runtimeTargetStat.isSymbolicLink()) {
875
911
  throw new Error(`Production Runtime entry must be a direct regular file: ${selected.runtimeEntry}`);
876
912
  }
877
- return path.relative(projectRoot, signTarget).split(path.sep).join('/');
878
913
  }
879
914
 
880
915
  function runOwnerCommand(targetDir, kind, command, options, runners) {
@@ -889,13 +924,24 @@ function runOwnerCommand(targetDir, kind, command, options, runners) {
889
924
 
890
925
  function assertProjectLifecycleCurrent(targetDir, versions, options = {}) {
891
926
  const descriptor = readSubmittedManifest(targetDir);
892
- const files = readProjectLifecycleFiles(targetDir);
927
+ const buildProfile = readBuildProfile(targetDir);
928
+ const files = readProjectLifecycleFiles(targetDir, buildProfile.buildProfileRef);
893
929
  assertPackageManifestCurrent(files.packageJson, versions);
894
- const version = assertVersionLockstep(files, descriptor);
895
- assertCargoManifestCurrent(files.cargoSource, versions.nimiShellTauriVersion);
896
- assertTauriConfigCurrent(files.tauriConfig, descriptor.appId);
930
+ const version = assertVersionLockstep(files, descriptor, buildProfile.buildProfileRef);
931
+ let nativeIdentity = {
932
+ cargoPackageName: cargoPackageNameFromNpmPackageName(files.packageJson.name),
933
+ tauriIdentifier: tauriIdentifierFromAppId(descriptor.appId),
934
+ };
935
+ if (buildProfile.buildProfileRef === TAURI_BUILD_PROFILE_REF) {
936
+ assertCargoManifestCurrent(files.cargoSource, versions.nimiShellTauriVersion);
937
+ assertTauriConfigCurrent(files.tauriConfig, descriptor.appId);
938
+ nativeIdentity = {
939
+ cargoPackageName: readCargoPackageName(files.cargoSource),
940
+ tauriIdentifier: files.tauriConfig.identifier,
941
+ };
942
+ }
897
943
  assertNoStandaloneParentSources(targetDir);
898
- const authoring = assertCanonicalAuthoringInputs(targetDir, descriptor, files, version);
944
+ const authoring = assertCanonicalAuthoringInputs(targetDir, descriptor, files, version, nativeIdentity);
899
945
  if (existsSync(path.join(targetDir, SCAFFOLD_LOCK_PATH))) {
900
946
  const lock = readJsonFile(path.join(targetDir, SCAFFOLD_LOCK_PATH), 'scaffold lock');
901
947
  for (const [field, expected] of [
@@ -907,38 +953,50 @@ function assertProjectLifecycleCurrent(targetDir, versions, options = {}) {
907
953
  }
908
954
  }
909
955
  }
910
- const buildProfile = readBuildProfile(targetDir);
911
956
  assertManagedWorkflowCurrent(targetDir);
912
957
  assertPnpmWorkspaceCurrent(targetDir);
913
958
  if (options.requireInstalledLock === true) {
914
959
  assertPnpmLockCurrent(targetDir, files.packageJson);
915
- assertCargoLockCurrent(targetDir, versions.nimiShellTauriVersion);
960
+ if (buildProfile.buildProfileRef === TAURI_BUILD_PROFILE_REF) {
961
+ assertCargoLockCurrent(targetDir, versions.nimiShellTauriVersion);
962
+ }
916
963
  }
917
964
  return { descriptor, files, version, buildProfile, authoring };
918
965
  }
919
966
 
920
967
  function buildExistingSubmittedAppSyncPlan(targetDir, versions) {
921
968
  const descriptor = readSubmittedManifest(targetDir);
922
- const files = readProjectLifecycleFiles(targetDir);
969
+ const buildProfile = readBuildProfile(targetDir);
970
+ const files = readProjectLifecycleFiles(targetDir, buildProfile.buildProfileRef);
923
971
  const version = files.packageJson.version;
924
972
  if (typeof version !== 'string' || !SEMVER_PATTERN.test(version)) {
925
973
  throw new Error('package.json version must be an exact semantic version before sync');
926
974
  }
975
+ const requiresTauri = buildProfile.buildProfileRef === TAURI_BUILD_PROFILE_REF;
927
976
  const identity = {
928
977
  appId: descriptor.appId,
929
978
  appTitle: descriptor.displayName,
930
979
  version,
931
980
  profile: descriptor.profile,
932
981
  packageName: files.packageJson.name,
933
- cargoPackageName: readCargoPackageName(files.cargoSource),
934
- tauriIdentifier: `ai.nimi.apps.${descriptor.appId}`,
982
+ cargoPackageName: requiresTauri
983
+ ? readCargoPackageName(files.cargoSource)
984
+ : cargoPackageNameFromNpmPackageName(files.packageJson.name),
985
+ tauriIdentifier: requiresTauri
986
+ ? files.tauriConfig.identifier
987
+ : tauriIdentifierFromAppId(descriptor.appId),
935
988
  author: typeof files.packageJson.author === 'string' ? files.packageJson.author : '',
936
989
  };
937
990
  const planned = [
938
991
  { path: files.packagePath, content: normalizePackageManifest(files.packageJson, descriptor, versions), previous: files.packageSource },
939
- { path: files.cargoPath, content: normalizeCargoManifest(files.cargoSource, versions.nimiShellTauriVersion), previous: files.cargoSource },
940
- { path: files.tauriPath, content: normalizeTauriConfig(files.tauriConfig, descriptor.appId), previous: files.tauriSource },
941
992
  ];
993
+ if (requiresTauri) {
994
+ planned.push(
995
+ { path: files.cargoPath, content: normalizeCargoManifest(files.cargoSource, versions.nimiShellTauriVersion), previous: files.cargoSource },
996
+ { path: files.tauriPath, content: normalizeTauriConfig(files.tauriConfig, descriptor.appId), previous: files.tauriSource },
997
+ );
998
+ identity.tauriIdentifier = tauriIdentifierFromAppId(descriptor.appId);
999
+ }
942
1000
  planned.push(...normalizeStandaloneSourceFiles(targetDir));
943
1001
  const identityPath = path.join(targetDir, APP_IDENTITY_PATH);
944
1002
  planned.push({
@@ -983,14 +1041,14 @@ function buildExistingSubmittedAppSyncPlan(targetDir, versions) {
983
1041
  planned.push({ path: submissionPath, content: submissionContent, previous: currentSubmissionSource });
984
1042
  const buildProfilePath = path.join(targetDir, BUILD_PROFILE_PATH);
985
1043
  const currentBuildProfile = existsSync(buildProfilePath) ? readFileSync(buildProfilePath, 'utf8') : '';
986
- const buildProfile = currentBuildProfile
1044
+ const buildProfileInput = currentBuildProfile
987
1045
  ? parseYamlFile(currentBuildProfile, buildProfilePath)
988
1046
  : {};
989
1047
  const scripts = files.packageJson.scripts || {};
990
- const testCommand = buildProfile.test_command
1048
+ const testCommand = buildProfileInput.test_command
991
1049
  || (typeof scripts['test:app'] === 'string' ? 'pnpm run test:app' : null)
992
1050
  || (typeof scripts.test === 'string' && !/\bnimi-app\s+test\b/u.test(scripts.test) ? 'pnpm run test' : null);
993
- const buildCommand = buildProfile.build_command
1051
+ const buildCommand = buildProfileInput.build_command
994
1052
  || (typeof scripts['build:shell'] === 'string' ? 'pnpm run build:shell' : null)
995
1053
  || (typeof scripts.build === 'string' && !/\bnimi-app\s+build\b/u.test(scripts.build) ? 'pnpm run build' : null);
996
1054
  if (!testCommand || !buildCommand) {
@@ -998,7 +1056,7 @@ function buildExistingSubmittedAppSyncPlan(targetDir, versions) {
998
1056
  }
999
1057
  const normalizedBuildProfile = currentBuildProfile
1000
1058
  ? stringifyYaml({
1001
- ...buildProfile,
1059
+ ...buildProfileInput,
1002
1060
  test_command: testCommand,
1003
1061
  build_command: buildCommand,
1004
1062
  profile_role: 'developer-workflow-input',
@@ -1017,7 +1075,18 @@ function buildExistingSubmittedAppSyncPlan(targetDir, versions) {
1017
1075
  });
1018
1076
  const workspace = normalizePnpmWorkspace(targetDir);
1019
1077
  if (workspace) planned.push(workspace);
1020
- return { descriptor, planned };
1078
+ return { descriptor, planned, buildProfileRef: buildProfile.buildProfileRef };
1079
+ }
1080
+
1081
+ function lifecycleNextSteps(buildProfileRef, versions) {
1082
+ return [
1083
+ 'pnpm install',
1084
+ ...(buildProfileRef === TAURI_BUILD_PROFILE_REF
1085
+ ? [`cargo update -p nimi-shell-tauri --precise ${versions.nimiShellTauriVersion}`]
1086
+ : []),
1087
+ 'nimi-app sync',
1088
+ 'nimi-app check',
1089
+ ];
1021
1090
  }
1022
1091
 
1023
1092
  function runNimicodingSync(targetDir, mode, runners) {
@@ -1060,7 +1129,7 @@ export function syncAppProject(cwd, options = {}, versions, runners = {}) {
1060
1129
  ...refreshed,
1061
1130
  managed: true,
1062
1131
  synchronizedFiles,
1063
- nextSteps: ['pnpm install', `cargo update -p nimi-shell-tauri --precise ${versions.nimiShellTauriVersion}`, 'nimi-app sync', 'nimi-app check'],
1132
+ nextSteps: lifecycleNextSteps(plan.buildProfileRef, versions),
1064
1133
  }, options, `sync completed for ${targetDir}`);
1065
1134
  }
1066
1135
  const plan = managed ? null : buildExistingSubmittedAppSyncPlan(targetDir, versions);
@@ -1076,7 +1145,7 @@ export function syncAppProject(cwd, options = {}, versions, runners = {}) {
1076
1145
  appId: plan?.descriptor.appId || readSubmittedManifest(targetDir).appId,
1077
1146
  synchronizedFiles,
1078
1147
  nimicodingSync: nimicoding?.summary || null,
1079
- nextSteps: ['pnpm install', `cargo update -p nimi-shell-tauri --precise ${versions.nimiShellTauriVersion}`, 'nimi-app sync', 'nimi-app check'],
1148
+ nextSteps: lifecycleNextSteps(plan.buildProfileRef, versions),
1080
1149
  }, options, `sync completed for ${targetDir}`);
1081
1150
  }
1082
1151
 
@@ -1125,10 +1194,7 @@ export function buildAppProject(cwd, options = {}, runners = {}) {
1125
1194
  const selected = selectBuildOwner(profile, options.target);
1126
1195
  const result = runOwnerCommand(targetDir, 'build', selected.command, options, runners);
1127
1196
  if (options.production === true) {
1128
- if (selected.target !== 'windows-x86_64' || typeof runners?.signWindowsTarget !== 'function') {
1129
- throw new Error(`Production signing is unavailable for target: ${selected.target}`);
1130
- }
1131
- runners.signWindowsTarget(targetDir, resolveProductionSignTarget(targetDir, selected));
1197
+ assertProductionRuntimeEntry(targetDir, selected);
1132
1198
  }
1133
1199
  return emitResult({
1134
1200
  ok: true,