@nimiplatform/app-tools 0.6.3 → 0.7.5

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 (35) hide show
  1. package/README.md +100 -10
  2. package/bin/nimi-app.mjs +6 -12
  3. package/lib/app-dependency-combinations.mjs +62 -0
  4. package/lib/app-doctor-update.mjs +18 -16
  5. package/lib/app-info.mjs +25 -2
  6. package/lib/app-lifecycle-guidance.mjs +4 -2
  7. package/lib/app-pack.mjs +5 -2
  8. package/lib/app-project-lifecycle.mjs +208 -50
  9. package/lib/app-safety-profile.mjs +204 -0
  10. package/lib/app-scaffold-capabilities.mjs +8 -0
  11. package/lib/app-scaffold-profiles.mjs +42 -3
  12. package/lib/app-scaffold.mjs +2 -1
  13. package/lib/canonical-capability-ids.generated.mjs +21 -0
  14. package/lib/index.mjs +0 -4
  15. package/package.json +7 -12
  16. package/scripts/dev-shell.mjs +20 -2
  17. package/skills/nimi-app-lifecycle/SKILL.md +7 -3
  18. package/skills/nimi-app-lifecycle/references/acceptance.md +6 -0
  19. package/skills/nimi-app-lifecycle/references/adapt.md +46 -1
  20. package/skills/nimi-app-lifecycle/references/audit.md +55 -0
  21. package/skills/nimi-app-lifecycle/references/platform-gaps.md +15 -0
  22. package/skills/nimi-app-lifecycle/references/release.md +1 -1
  23. package/skills/nimi-app-lifecycle/references/safety-declaration.md +37 -0
  24. package/skills/nimi-app-lifecycle/references/upgrade-platform.md +2 -2
  25. package/templates/app-source/src/studio-modules/studio-voice/parameters.ts +8 -10
  26. package/templates/default-starter/AGENTS.md +4 -2
  27. package/lib/simulator-conformance-ast.mjs +0 -498
  28. package/lib/simulator-conformance-css.mjs +0 -116
  29. package/lib/simulator-conformance-graph.mjs +0 -757
  30. package/lib/simulator-conformance.d.mts +0 -14
  31. package/lib/simulator-conformance.mjs +0 -203
  32. package/lib/simulator-css-profile.d.mts +0 -27
  33. package/lib/simulator-css-profile.mjs +0 -531
  34. package/lib/simulator-kit-export-resolution.mjs +0 -70
  35. package/lib/simulator-manifest.mjs +0 -334
@@ -1,12 +1,17 @@
1
1
  import { readAppInfo } from './app-info.mjs';
2
2
  // @nimi-authority: rule.nimi.platform.app-ecosystem.p-scaf-018c
3
3
  // @nimi-authority: rule.nimi.platform.app-ecosystem.p-napp-009b
4
+ // @nimi-authority: rule.nimi.platform.app-ecosystem.p-napp-043a
4
5
 
5
- import { existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from 'node:fs';
6
+ import { existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, realpathSync, writeFileSync } from 'node:fs';
7
+ import { createRequire } from 'node:module';
6
8
  import path from 'node:path';
9
+ import { satisfies } from 'semver';
7
10
  import { parse as parseYaml, parseDocument as parseYamlDocument, stringify as stringifyYaml } from 'yaml';
8
11
 
9
12
  import { assertManifestAppAccessDeclaration } from './app-access-declaration.mjs';
13
+ import { defaultDependencyCombination, resolveDependencyCombination } from './app-dependency-combinations.mjs';
14
+ import { SAFETY_PROFILE_FIELD, normalizeSafetyProfile } from './app-safety-profile.mjs';
10
15
  import { planManagedAppSync, validateAppProject, validateAppProjectInputs, validateManagedAppFiles } from './app-doctor-update.mjs';
11
16
  import { LIFECYCLE_SKILL_PATH, hasLifecycleGuidanceOwner, lifecycleOwnerSteps, planLifecycleGuidance } from './app-lifecycle-guidance.mjs';
12
17
  import { applyProjectFiles, describeChanges, plannedFile } from './app-project-files.mjs';
@@ -132,7 +137,15 @@ function readSubmittedManifest(targetDir, sources) {
132
137
  if (!SEMVER_PATTERN.test(version) || version !== document.version) {
133
138
  throw new Error('Existing submitted app version must be an exact semantic version');
134
139
  }
135
- return Object.freeze({ appId, displayName, profile, version, rendererOrigin: parsedOrigin.origin, capabilityContractRefs: document.capability_contract_refs, requiredStandardizedFeatureRefs: document.required_standardized_feature_refs, storagePolicy: document.storage_policy });
140
+ let safetyProfile;
141
+ if (document[SAFETY_PROFILE_FIELD] !== undefined) {
142
+ try {
143
+ safetyProfile = normalizeSafetyProfile(document[SAFETY_PROFILE_FIELD]);
144
+ } catch (error) {
145
+ throw new Error(`nimi.app.yaml ${error instanceof Error ? error.message : String(error)}`, { cause: error });
146
+ }
147
+ }
148
+ return Object.freeze({ appId, displayName, profile, version, rendererOrigin: parsedOrigin.origin, capabilityContractRefs: document.capability_contract_refs, requiredStandardizedFeatureRefs: document.required_standardized_feature_refs, storagePolicy: document.storage_policy, safetyProfile });
136
149
  }
137
150
 
138
151
  function assertNoRetiredScaffoldState(targetDir) {
@@ -147,15 +160,42 @@ function assertNoRetiredScaffoldState(targetDir) {
147
160
  }
148
161
  }
149
162
 
150
- function expectedNimiDependencies(versions) {
163
+ // The SDK/Kit pair comes from the App's resolved combination; the tool
164
+ // dependencies come from the selected tool version. Both are one judgment
165
+ // shared by manifest, lock, Cargo and workflow checks.
166
+ function expectedNimiDependencies(versions, combination) {
151
167
  return Object.freeze([
152
- Object.freeze({ name: '@nimiplatform/sdk', section: 'dependencies', version: versions.sdkVersion }),
153
- Object.freeze({ name: '@nimiplatform/kit', section: 'dependencies', version: versions.kitVersion }),
168
+ Object.freeze({ name: '@nimiplatform/sdk', section: 'dependencies', version: combination.sdkVersion }),
169
+ Object.freeze({ name: '@nimiplatform/kit', section: 'dependencies', version: combination.kitVersion }),
154
170
  Object.freeze({ name: '@nimiplatform/app-tools', section: 'devDependencies', version: versions.appToolsVersion }),
155
171
  Object.freeze({ name: '@nimiplatform/nimi-coding', section: 'devDependencies', version: versions.nimicodingVersion }),
156
172
  ]);
157
173
  }
158
174
 
175
+ // Managed (scaffold-locked) projects derive glue, matrix and package fields
176
+ // from `versions`; `managedProjectVersions` has already pinned those to the
177
+ // project's own supported combination, so the default of the effective
178
+ // versions is that combination. Existing submitted Apps resolve theirs directly.
179
+ function selectDependencyCombination(packageJson, versions, managed) {
180
+ return managed ? defaultDependencyCombination(versions) : resolveDependencyCombination(packageJson, versions);
181
+ }
182
+
183
+ // An existing managed project keeps its current supported SDK/Kit combination:
184
+ // the generator recomputes derived projections for that combination, while the
185
+ // app-tools and nimi-coding tool dependencies still follow the selected tool.
186
+ // Only a fresh create starts from the tool default. An unlisted pairing fails.
187
+ function managedProjectVersions(targetDir, versions) {
188
+ const packagePath = path.join(targetDir, 'package.json');
189
+ if (!existsSync(packagePath)) return versions;
190
+ const combination = resolveDependencyCombination(readJsonFile(packagePath, 'package.json'), versions);
191
+ return Object.freeze({ ...versions, sdkVersion: combination.sdkVersion, kitVersion: combination.kitVersion, nimiShellTauriVersion: combination.nimiShellTauriVersion });
192
+ }
193
+
194
+ function describeCombination(combination, toolVersions) {
195
+ const isDefault = combination.sdkVersion === toolVersions.sdkVersion && combination.kitVersion === toolVersions.kitVersion;
196
+ return { sdk: combination.sdkVersion, kit: combination.kitVersion, source: isDefault ? 'default' : 'existing' };
197
+ }
198
+
159
199
  function dependencySection(packageJson, sectionName) {
160
200
  const section = packageJson[sectionName];
161
201
  if (section === undefined) return null;
@@ -172,6 +212,15 @@ function isLocalDependencySpec(value) {
172
212
  || /\.(?:tar\.gz|tgz)(?:[?#].*)?$/iu.test(normalized);
173
213
  }
174
214
 
215
+ function localPackageArchive(value) {
216
+ return typeof value === 'string' ? value.match(/^(file:[^\r\n]+?\.(?:tgz|tar\.gz))(?:\(.*\))?$/u)?.[1] || '' : '';
217
+ }
218
+
219
+ function archivePath(targetDir, value) {
220
+ const archive = localPackageArchive(value);
221
+ return archive ? path.resolve(targetDir, archive.slice('file:'.length)) : '';
222
+ }
223
+
175
224
  function synchronizedNimiPackageName(key) {
176
225
  const normalized = String(key || '').replace(/^\/+/, '');
177
226
  for (const packageName of SYNCHRONIZED_NIMI_PACKAGES) {
@@ -202,7 +251,7 @@ function assertPublicNimiDependencySpecs(packageJson) {
202
251
  }
203
252
  }
204
253
 
205
- function assertPackageManifestCurrent(packageJson, versions) {
254
+ function assertPackageManifestCurrent(packageJson, versions, combination) {
206
255
  if (packageJson.private !== true || Object.hasOwn(packageJson, 'publishConfig')) {
207
256
  throw new Error('Nimi App package.json must be private and must not declare npm publishConfig');
208
257
  }
@@ -210,7 +259,7 @@ function assertPackageManifestCurrent(packageJson, versions) {
210
259
  throw new Error(`package.json packageManager must be ${versions.packageManager}`);
211
260
  }
212
261
  assertPublicNimiDependencySpecs(packageJson);
213
- for (const expected of expectedNimiDependencies(versions)) {
262
+ for (const expected of expectedNimiDependencies(versions, combination)) {
214
263
  const section = dependencySection(packageJson, expected.section);
215
264
  if (section?.[expected.name] !== expected.version) {
216
265
  throw new Error(`package.json ${expected.section}.${expected.name} must be ${expected.version}`);
@@ -249,9 +298,10 @@ function assertPackageManifestCurrent(packageJson, versions) {
249
298
  if (scripts.publish !== undefined) {
250
299
  throw new Error('package.json scripts.publish is unavailable until publisher GitHub and registry orchestration is implemented');
251
300
  }
301
+ return combination;
252
302
  }
253
303
 
254
- function normalizePackageManifest(packageJson, descriptor, versions, buildProfileRef, packageSource) {
304
+ function normalizePackageManifest(packageJson, descriptor, versions, buildProfileRef, packageSource, combination) {
255
305
  if (!packageJson || typeof packageJson !== 'object' || Array.isArray(packageJson)) {
256
306
  throw new Error('package.json must contain an object');
257
307
  }
@@ -259,7 +309,7 @@ function normalizePackageManifest(packageJson, descriptor, versions, buildProfil
259
309
  normalized.private = true;
260
310
  delete normalized.publishConfig;
261
311
  for (const sectionName of NPM_DEPENDENCY_SECTIONS) dependencySection(normalized, sectionName);
262
- for (const expected of expectedNimiDependencies(versions)) {
312
+ for (const expected of expectedNimiDependencies(versions, combination)) {
263
313
  for (const sectionName of NPM_DEPENDENCY_SECTIONS) {
264
314
  const section = dependencySection(normalized, sectionName);
265
315
  if (section) delete section[expected.name];
@@ -301,7 +351,7 @@ function normalizePackageManifest(packageJson, descriptor, versions, buildProfil
301
351
  .replace(/\bpnpm\s+run\s+doctor\s*&&\s*/gu, '')
302
352
  .replace(/\bnimi-app\s+doctor\s*&&\s*/gu, '');
303
353
  }
304
- assertPackageManifestCurrent(normalized, versions);
354
+ assertPackageManifestCurrent(normalized, versions, combination);
305
355
  // Project formatters may use different whitespace or key order. Only managed
306
356
  // value changes require rewriting this App-owned manifest.
307
357
  if (stableInputJson(normalized) === stableInputJson(packageJson)) return packageSource;
@@ -406,7 +456,7 @@ function normalizePnpmWorkspace(targetDir) {
406
456
  }
407
457
  let removed = false;
408
458
  for (const key of Object.keys(overrides || {})) {
409
- if (synchronizedNimiPackageName(key)) {
459
+ if (synchronizedNimiPackageName(key) && !localPackageArchive(overrides[key])) {
410
460
  document.deleteIn(['overrides', key]);
411
461
  removed = true;
412
462
  }
@@ -420,9 +470,10 @@ function normalizePnpmWorkspace(targetDir) {
420
470
  };
421
471
  }
422
472
 
423
- function assertPnpmWorkspaceCurrent(targetDir, sources) {
473
+ function assertPnpmWorkspaceCurrent(targetDir, sources, production = false) {
424
474
  const workspacePath = path.join(targetDir, 'pnpm-workspace.yaml');
425
- if (!hasProjectFile(targetDir, 'pnpm-workspace.yaml', sources)) return;
475
+ const localPackages = new Map();
476
+ if (!hasProjectFile(targetDir, 'pnpm-workspace.yaml', sources)) return localPackages;
426
477
  const source = readProjectText(targetDir, 'pnpm-workspace.yaml', sources);
427
478
  const workspace = parseYamlFile(source, workspacePath);
428
479
  const overrides = workspace?.overrides;
@@ -430,16 +481,24 @@ function assertPnpmWorkspaceCurrent(targetDir, sources) {
430
481
  throw new Error('pnpm-workspace.yaml overrides must be an object');
431
482
  }
432
483
  for (const key of Object.keys(overrides || {})) {
433
- if (synchronizedNimiPackageName(key)) {
484
+ const packageName = synchronizedNimiPackageName(key);
485
+ if (packageName && localPackageArchive(overrides[key])) {
486
+ if (production) throw new Error('Production release preflight requires registry dependencies. Remove local Nimi tarball overrides only when preparing a public release; use check without --production for local development.');
487
+ if (key !== packageName) throw new Error(`Local Nimi tarball overrides must name the exact package: ${key}`);
488
+ const target = archivePath(targetDir, overrides[key]);
489
+ if (!existsSync(target) || !lstatSync(target).isFile()) throw installRequiredError(`Local Nimi package archive is missing: ${overrides[key]}`);
490
+ localPackages.set(packageName, overrides[key]);
491
+ } else if (packageName) {
434
492
  throw installRequiredError(`pnpm-workspace.yaml retains a Nimi dependency override: ${key}`);
435
493
  }
436
494
  }
495
+ return localPackages;
437
496
  }
438
497
 
439
- function findLocalNimiResolution(value, currentPackage = '', pathParts = []) {
498
+ function findLocalNimiResolution(value, currentPackage = '', pathParts = [], allowedArchive = () => false) {
440
499
  if (Array.isArray(value)) {
441
500
  for (let index = 0; index < value.length; index += 1) {
442
- const finding = findLocalNimiResolution(value[index], currentPackage, [...pathParts, String(index)]);
501
+ const finding = findLocalNimiResolution(value[index], currentPackage, [...pathParts, String(index)], allowedArchive);
443
502
  if (finding) return finding;
444
503
  }
445
504
  return null;
@@ -452,25 +511,63 @@ function findLocalNimiResolution(value, currentPackage = '', pathParts = []) {
452
511
  packageName
453
512
  && normalizedKey.startsWith(`${packageName}@`)
454
513
  && isLocalDependencySpec(normalizedKey.slice(packageName.length + 1))
514
+ && !allowedArchive(packageName, normalizedKey.slice(packageName.length + 1), [...pathParts, key])
455
515
  ) {
456
516
  return [...pathParts, key].join('.');
457
517
  }
458
- if (packageName && typeof child === 'string' && isLocalDependencySpec(child)) {
518
+ if (packageName && typeof child === 'string' && isLocalDependencySpec(child) && !allowedArchive(packageName, child, [...pathParts, key])) {
459
519
  return [...pathParts, key].join('.');
460
520
  }
461
- const finding = findLocalNimiResolution(child, packageName, [...pathParts, key]);
521
+ const finding = findLocalNimiResolution(child, packageName, [...pathParts, key], allowedArchive);
462
522
  if (finding) return finding;
463
523
  }
464
524
  return null;
465
525
  }
466
526
 
467
- function assertPnpmLockCurrent(targetDir, packageJson) {
527
+ function readInstalledPnpmLock(targetDir) {
528
+ const modulesPath = path.join(targetDir, 'node_modules', '.modules.yaml');
529
+ if (!existsSync(modulesPath)) throw installRequiredError('pnpm installation metadata is missing');
530
+ const modules = parseYamlFile(readFileSync(modulesPath, 'utf8'), modulesPath);
531
+ if (typeof modules?.virtualStoreDir !== 'string' || !modules.virtualStoreDir.trim()) {
532
+ throw installRequiredError('pnpm installation has no virtual store');
533
+ }
534
+ const installedLockPath = path.join(path.resolve(targetDir, 'node_modules', modules.virtualStoreDir), 'lock.yaml');
535
+ if (!existsSync(installedLockPath)) throw installRequiredError('pnpm installed dependency lock is missing');
536
+ return parseYamlFile(readFileSync(installedLockPath, 'utf8'), installedLockPath);
537
+ }
538
+
539
+ function selectedLocalPackageRecord(lock, name, selected, targetDir) {
540
+ const matches = Object.entries(lock?.packages || {}).filter(([key, entry]) =>
541
+ key.startsWith(name + '@') && archivePath(targetDir, entry?.resolution?.tarball) === archivePath(targetDir, selected));
542
+ if (matches.length !== 1 || typeof matches[0][1]?.version !== 'string'
543
+ || typeof matches[0][1]?.resolution?.integrity !== 'string' || !matches[0][1].resolution.integrity) {
544
+ throw installRequiredError(`Local Nimi package installation is stale or has no complete locked tarball resolution: ${name}`);
545
+ }
546
+ return matches[0][1];
547
+ }
548
+
549
+ function assertPnpmLockCurrent(targetDir, packageJson, localPackages, versions, combination) {
468
550
  const lockPath = path.join(targetDir, 'pnpm-lock.yaml');
469
551
  if (!existsSync(lockPath)) {
470
552
  throw installRequiredError('pnpm-lock.yaml is missing');
471
553
  }
472
554
  const lock = parseYamlFile(readFileSync(lockPath, 'utf8'), lockPath);
473
- const finding = findLocalNimiResolution(lock);
555
+ const allowedArchive = (name, value, location = []) => {
556
+ // pnpm rebases importer specifiers to the member directory; resolved
557
+ // versions and package/snapshot keys stay relative to the workspace root.
558
+ let base = targetDir;
559
+ if (location.length === 5 && location[0] === 'importers'
560
+ && NPM_DEPENDENCY_SECTIONS.includes(location[2]) && location[4] === 'specifier') {
561
+ base = path.resolve(targetDir, location[1]);
562
+ const relative = path.relative(targetDir, base);
563
+ if (path.isAbsolute(location[1]) || relative === '..' || relative.startsWith(`..${path.sep}`)) {
564
+ throw installRequiredError(`pnpm-lock.yaml importer is outside the App workspace: ${location[1]}`);
565
+ }
566
+ }
567
+ return localPackageArchive(value) && localPackages.has(name)
568
+ && archivePath(base, value) === archivePath(targetDir, localPackages.get(name));
569
+ };
570
+ const finding = findLocalNimiResolution(lock, '', [], allowedArchive);
474
571
  if (finding) {
475
572
  throw installRequiredError(`pnpm-lock.yaml retains a local Nimi resolution at ${finding}`);
476
573
  }
@@ -478,14 +575,46 @@ function assertPnpmLockCurrent(targetDir, packageJson) {
478
575
  if (!importer || typeof importer !== 'object' || Array.isArray(importer)) {
479
576
  throw installRequiredError('pnpm-lock.yaml root importer is missing');
480
577
  }
578
+ const installedLock = localPackages.size > 0 ? readInstalledPnpmLock(targetDir) : null;
579
+ for (const [name, selected] of localPackages) {
580
+ if (lock.overrides?.[name] !== selected) throw installRequiredError(`pnpm-lock.yaml local package override does not match pnpm-workspace.yaml: ${name}`);
581
+ let manifestPath = path.join(targetDir, 'node_modules', ...name.split('/'), 'package.json');
582
+ if (KIT_OWNED_NATIVE_CARRIERS.includes(name)) {
583
+ try {
584
+ const kitManifest = realpathSync(path.join(targetDir, 'node_modules', '@nimiplatform', 'kit', 'package.json'));
585
+ manifestPath = createRequire(kitManifest).resolve(name + '/package.json');
586
+ } catch {
587
+ throw installRequiredError(`Local Nimi native package is not installed for Kit: ${name}`);
588
+ }
589
+ }
590
+ if (!existsSync(manifestPath)) throw installRequiredError(`Local Nimi package is not installed: ${name}`);
591
+ const installed = readJsonFile(manifestPath, name);
592
+ const expected = expectedNimiDependencies(versions, combination).find((entry) => entry.name === name)?.version || combination.kitVersion;
593
+ if (installed.name !== name || !satisfies(installed.version, expected, { includePrerelease: true })) {
594
+ throw installRequiredError(`Installed local Nimi package must be ${name}@${expected}`);
595
+ }
596
+ if (archivePath(targetDir, installedLock?.overrides?.[name]) !== archivePath(targetDir, selected)) {
597
+ throw installRequiredError(`Local Nimi package installation is stale: ${name}`);
598
+ }
599
+ const locked = selectedLocalPackageRecord(lock, name, selected, targetDir);
600
+ const installedResolution = selectedLocalPackageRecord(installedLock, name, selected, targetDir);
601
+ if (installed.version !== locked.version || installedResolution.version !== locked.version
602
+ || installedResolution.resolution.integrity !== locked.resolution.integrity) {
603
+ throw installRequiredError(`Local Nimi package installation is stale: ${name}`);
604
+ }
605
+ }
481
606
  for (const sectionName of NPM_DEPENDENCY_SECTIONS) {
482
607
  const packageSection = dependencySection(packageJson, sectionName) || {};
483
608
  const lockSection = importer[sectionName] || {};
484
609
  for (const [name, specifier] of Object.entries(packageSection)) {
485
610
  if (!name.startsWith('@nimiplatform/')) continue;
486
- if (lockSection?.[name]?.specifier !== specifier) {
611
+ if (lockSection?.[name]?.specifier !== (localPackages.get(name) || specifier)) {
487
612
  throw installRequiredError(`pnpm-lock.yaml ${sectionName}.${name} specifier does not match package.json`);
488
613
  }
614
+ if (localPackages.has(name)
615
+ && installedLock?.importers?.['.']?.[sectionName]?.[name]?.version !== lockSection[name]?.version) {
616
+ throw installRequiredError(`Local Nimi package installation is stale: ${name}`);
617
+ }
489
618
  }
490
619
  for (const name of Object.keys(lockSection || {})) {
491
620
  if (name.startsWith('@nimiplatform/') && !Object.hasOwn(packageSection, name)) {
@@ -493,6 +622,21 @@ function assertPnpmLockCurrent(targetDir, packageJson) {
493
622
  }
494
623
  }
495
624
  }
625
+ for (const [importerName, child] of Object.entries(lock.importers)) {
626
+ if (importerName === '.') continue;
627
+ for (const sectionName of NPM_DEPENDENCY_SECTIONS) {
628
+ for (const [name, dependency] of Object.entries(child?.[sectionName] || {})) {
629
+ if (!localPackages.has(name)) continue;
630
+ const location = ['importers', importerName, sectionName, name, 'specifier'];
631
+ const installed = installedLock?.importers?.[importerName]?.[sectionName]?.[name];
632
+ if (typeof dependency?.version !== 'string' || installed?.version !== dependency.version
633
+ || !allowedArchive(name, dependency?.specifier, location)
634
+ || !allowedArchive(name, installed?.specifier, location)) {
635
+ throw installRequiredError(`Local Nimi package installation is stale: importers.${importerName}.${sectionName}.${name}`);
636
+ }
637
+ }
638
+ }
639
+ }
496
640
  }
497
641
 
498
642
  function assertCargoLockCurrent(targetDir, version) {
@@ -760,7 +904,7 @@ function assertCanonicalAuthoringInputs(targetDir, descriptor, files, version, n
760
904
  'support_manifest',
761
905
  'review_inputs',
762
906
  'admission_truth',
763
- ], ['ai_profile_recommendation_ref']);
907
+ ], ['ai_profile_recommendation_ref', SAFETY_PROFILE_FIELD]);
764
908
  const expectedSubmissionIdentity = {
765
909
  app_id: descriptor.appId,
766
910
  display_name: descriptor.displayName,
@@ -783,6 +927,11 @@ function assertCanonicalAuthoringInputs(targetDir, descriptor, files, version, n
783
927
  }
784
928
  normalizeStorageInput(submission.storage_policy, `${SUBMISSION_PATH} storage_policy`);
785
929
  normalizeSupportInput(submission.support_manifest, `${SUBMISSION_PATH} support_manifest`);
930
+ // nimi.app.yaml is the only declaration author; the submission copy must be
931
+ // the tool projection of it, never an independently edited second source.
932
+ if (JSON.stringify(submission[SAFETY_PROFILE_FIELD]) !== JSON.stringify(descriptor.safetyProfile)) {
933
+ throw new Error(`${SUBMISSION_PATH} ${SAFETY_PROFILE_FIELD} must match the nimi.app.yaml declaration; run nimi-app sync to project it`);
934
+ }
786
935
  const reviewInputs = assertExactKeys(submission.review_inputs, `${SUBMISSION_PATH} review_inputs`, ['manifest', 'build_profile', 'scaffold_boundary']);
787
936
  const expectedReviewInputs = {
788
937
  manifest: 'nimi.app.yaml',
@@ -948,14 +1097,15 @@ function assertProjectLifecycleCurrent(targetDir, versions, options = {}) {
948
1097
  const descriptor = readSubmittedManifest(targetDir, sources);
949
1098
  const buildProfile = readBuildProfile(targetDir, sources);
950
1099
  const files = readProjectLifecycleFiles(targetDir, buildProfile.buildProfileRef, sources);
951
- assertPackageManifestCurrent(files.packageJson, versions);
1100
+ const combination = selectDependencyCombination(files.packageJson, versions, options.managed === true);
1101
+ assertPackageManifestCurrent(files.packageJson, versions, combination);
952
1102
  const version = assertVersionLockstep(files, descriptor, buildProfile.buildProfileRef);
953
1103
  let nativeIdentity = {
954
1104
  cargoPackageName: cargoPackageNameFromNpmPackageName(files.packageJson.name),
955
1105
  tauriIdentifier: tauriIdentifierFromAppId(descriptor.appId),
956
1106
  };
957
1107
  if (buildProfile.buildProfileRef === TAURI_BUILD_PROFILE_REF) {
958
- assertCargoManifestCurrent(files.cargoSource, versions.nimiShellTauriVersion);
1108
+ assertCargoManifestCurrent(files.cargoSource, combination.nimiShellTauriVersion);
959
1109
  assertTauriConfigCurrent(files.tauriConfig, descriptor.appId);
960
1110
  nativeIdentity = {
961
1111
  cargoPackageName: readCargoPackageName(files.cargoSource),
@@ -965,17 +1115,17 @@ function assertProjectLifecycleCurrent(targetDir, versions, options = {}) {
965
1115
  assertNoStandaloneParentSources(targetDir, sources);
966
1116
  const authoring = assertCanonicalAuthoringInputs(targetDir, descriptor, files, version, nativeIdentity, sources);
967
1117
  assertManagedWorkflowCurrent(targetDir, sources);
968
- assertPnpmWorkspaceCurrent(targetDir, sources);
1118
+ const localPackages = assertPnpmWorkspaceCurrent(targetDir, sources, options.production === true);
969
1119
  if (options.requireInstalledLock === true) {
970
- assertPnpmLockCurrent(targetDir, files.packageJson);
1120
+ assertPnpmLockCurrent(targetDir, files.packageJson, localPackages, versions, combination);
971
1121
  if (buildProfile.buildProfileRef === TAURI_BUILD_PROFILE_REF) {
972
- assertCargoLockCurrent(targetDir, versions.nimiShellTauriVersion);
1122
+ assertCargoLockCurrent(targetDir, combination.nimiShellTauriVersion);
973
1123
  }
974
1124
  }
975
- return { descriptor, files, version, buildProfile, authoring };
1125
+ return { descriptor, files, version, buildProfile, authoring, combination };
976
1126
  }
977
1127
 
978
- function buildExistingSubmittedAppSyncPlan(targetDir, versions, sources) {
1128
+ function buildExistingSubmittedAppSyncPlan(targetDir, versions, sources, managed = false) {
979
1129
  const descriptor = readSubmittedManifest(targetDir, sources);
980
1130
  const buildProfile = readBuildProfile(targetDir, sources);
981
1131
  const files = readProjectLifecycleFiles(targetDir, buildProfile.buildProfileRef, sources);
@@ -984,6 +1134,7 @@ function buildExistingSubmittedAppSyncPlan(targetDir, versions, sources) {
984
1134
  throw new Error('package.json version must be an exact semantic version before sync');
985
1135
  }
986
1136
  const requiresTauri = buildProfile.buildProfileRef === TAURI_BUILD_PROFILE_REF;
1137
+ const combination = selectDependencyCombination(files.packageJson, versions, managed);
987
1138
  const identity = {
988
1139
  appId: descriptor.appId,
989
1140
  appTitle: descriptor.displayName,
@@ -999,11 +1150,11 @@ function buildExistingSubmittedAppSyncPlan(targetDir, versions, sources) {
999
1150
  author: typeof files.packageJson.author === 'string' ? files.packageJson.author : '',
1000
1151
  };
1001
1152
  const planned = [
1002
- { path: files.packagePath, content: normalizePackageManifest(files.packageJson, descriptor, versions, buildProfile.buildProfileRef, files.packageSource), previous: files.packageSource },
1153
+ { path: files.packagePath, content: normalizePackageManifest(files.packageJson, descriptor, versions, buildProfile.buildProfileRef, files.packageSource, combination), previous: files.packageSource },
1003
1154
  ];
1004
1155
  if (requiresTauri) {
1005
1156
  planned.push(
1006
- { path: files.cargoPath, content: normalizeCargoManifest(files.cargoSource, versions.nimiShellTauriVersion), previous: files.cargoSource },
1157
+ { path: files.cargoPath, content: normalizeCargoManifest(files.cargoSource, combination.nimiShellTauriVersion), previous: files.cargoSource },
1007
1158
  { path: files.tauriPath, content: normalizeTauriConfig(files.tauriConfig, descriptor.appId), previous: files.tauriSource },
1008
1159
  );
1009
1160
  identity.tauriIdentifier = tauriIdentifierFromAppId(descriptor.appId);
@@ -1036,7 +1187,7 @@ function buildExistingSubmittedAppSyncPlan(targetDir, versions, sources) {
1036
1187
  'support_manifest',
1037
1188
  'review_inputs',
1038
1189
  'admission_truth',
1039
- ], ['ai_profile_recommendation_ref']);
1190
+ ], ['ai_profile_recommendation_ref', SAFETY_PROFILE_FIELD]);
1040
1191
  canonicalInputList(currentSubmission.capability_contract_refs, `${SUBMISSION_PATH} capability_contract_refs`);
1041
1192
  canonicalInputList(currentSubmission.required_standardized_feature_refs, `${SUBMISSION_PATH} required_standardized_feature_refs`);
1042
1193
  normalizeStorageInput(currentSubmission.storage_policy, `${SUBMISSION_PATH} storage_policy`);
@@ -1047,6 +1198,7 @@ function buildExistingSubmittedAppSyncPlan(targetDir, versions, sources) {
1047
1198
  requiredStandardizedFeatureRefs: descriptor.requiredStandardizedFeatureRefs ?? currentSubmission?.required_standardized_feature_refs ?? [],
1048
1199
  aiProfileRecommendationRef: currentSubmission?.ai_profile_recommendation_ref,
1049
1200
  storagePolicy: descriptor.storagePolicy ?? currentSubmission?.storage_policy ?? { kind: 'nimi-mediated-default' },
1201
+ safetyProfile: descriptor.safetyProfile,
1050
1202
  supportManifest,
1051
1203
  });
1052
1204
  planned.push({ path: submissionPath, content: submissionContent, previous: currentSubmissionSource });
@@ -1086,14 +1238,14 @@ function buildExistingSubmittedAppSyncPlan(targetDir, versions, sources) {
1086
1238
  });
1087
1239
  const workspace = normalizePnpmWorkspace(targetDir);
1088
1240
  if (workspace) planned.push(workspace);
1089
- return { descriptor, planned: planned.map((file) => plannedFile(targetDir, path.relative(targetDir, file.path), file.content)), buildProfileRef: buildProfile.buildProfileRef };
1241
+ return { descriptor, planned: planned.map((file) => plannedFile(targetDir, path.relative(targetDir, file.path), file.content)), buildProfileRef: buildProfile.buildProfileRef, combination };
1090
1242
  }
1091
1243
 
1092
- function lifecycleNextSteps(buildProfileRef, versions) {
1244
+ function lifecycleNextSteps(buildProfileRef, combination) {
1093
1245
  return [
1094
1246
  'pnpm install',
1095
1247
  ...(buildProfileRef === TAURI_BUILD_PROFILE_REF
1096
- ? [`cargo update -p nimi-shell-tauri --precise ${versions.nimiShellTauriVersion}`]
1248
+ ? [`cargo update -p nimi-shell-tauri --precise ${combination.nimiShellTauriVersion}`]
1097
1249
  : []),
1098
1250
  'nimi-app sync',
1099
1251
  'nimi-app check',
@@ -1121,18 +1273,18 @@ function planSources(targetDir, planned) {
1121
1273
 
1122
1274
  function validateProjectPlan(targetDir, versions, planned, managed) {
1123
1275
  const sources = planSources(targetDir, planned);
1124
- const current = assertProjectLifecycleCurrent(targetDir, versions, { sources });
1276
+ const current = assertProjectLifecycleCurrent(targetDir, versions, { sources, managed });
1125
1277
  for (const target of Object.keys(current.buildProfile.targets)) selectBuildOwner(current.buildProfile, target);
1126
1278
  validateAppProjectInputs(targetDir, parseYaml(readProjectText(targetDir, 'nimi.app.yaml', sources)), current.files.packageJson, managed, sources);
1127
1279
  return current;
1128
1280
  }
1129
1281
 
1130
1282
  export function validateAppInitialization(targetDir, versions) {
1131
- const current = assertProjectLifecycleCurrent(targetDir, versions);
1283
+ const current = assertProjectLifecycleCurrent(targetDir, versions, { managed: true });
1132
1284
  for (const target of Object.keys(current.buildProfile.targets)) selectBuildOwner(current.buildProfile, target);
1133
1285
  }
1134
1286
 
1135
- function executeProjectPlan(targetDir, options, versions, runners, plan, scaffold) {
1287
+ function executeProjectPlan(targetDir, options, versions, runners, plan, scaffold, toolVersions = versions) {
1136
1288
  if (scaffold) validateManagedAppFiles(targetDir, scaffold.snapshot.lock, planSources(targetDir, plan.planned));
1137
1289
  validateProjectPlan(targetDir, versions, plan.planned, Boolean(scaffold));
1138
1290
  const preview = {
@@ -1140,7 +1292,8 @@ function executeProjectPlan(targetDir, options, versions, runners, plan, scaffol
1140
1292
  managed: Boolean(scaffold), appId: plan.descriptor.appId,
1141
1293
  dryRun: options.dryRun === true, skillPath: LIFECYCLE_SKILL_PATH,
1142
1294
  changes: describeChanges(targetDir, plan.planned), ownerSteps: lifecycleOwnerSteps(versions),
1143
- nextSteps: lifecycleNextSteps(plan.buildProfileRef, versions),
1295
+ nextSteps: lifecycleNextSteps(plan.buildProfileRef, plan.combination),
1296
+ dependencyCombination: describeCombination(plan.combination, toolVersions),
1144
1297
  };
1145
1298
  if (options.dryRun) return emitResult(preview, options, `${preview.command} preview: ${preview.changes.map((file) => `${file.action} ${file.path}`).join(', ') || 'no app-tools changes'}`);
1146
1299
  const nimicoding = runNimicodingSync(targetDir, 'apply', runners);
@@ -1150,7 +1303,7 @@ function executeProjectPlan(targetDir, options, versions, runners, plan, scaffol
1150
1303
  ...plan.planned.filter((file) => file !== lockFile),
1151
1304
  ...planLifecycleGuidance(targetDir),
1152
1305
  ]);
1153
- assertProjectLifecycleCurrent(targetDir, versions);
1306
+ assertProjectLifecycleCurrent(targetDir, versions, { managed: Boolean(scaffold) });
1154
1307
  if (scaffold) {
1155
1308
  validateManagedAppFiles(targetDir, scaffold.snapshot.lock);
1156
1309
  synchronizedFiles.push(...applyProjectFiles(targetDir, [lockFile]));
@@ -1164,12 +1317,13 @@ export function syncAppProject(cwd, options = {}, versions, runners = {}) {
1164
1317
  const targetDir = resolveTargetDir(cwd, options);
1165
1318
  assertNoRetiredScaffoldState(targetDir);
1166
1319
  const guidance = planLifecycleGuidance(targetDir);
1167
- const scaffold = existsSync(path.join(targetDir, SCAFFOLD_LOCK_PATH))
1168
- ? planManagedAppSync(targetDir, {}, versions) : null;
1320
+ const managed = existsSync(path.join(targetDir, SCAFFOLD_LOCK_PATH));
1321
+ const effective = managed ? managedProjectVersions(targetDir, versions) : versions;
1322
+ const scaffold = managed ? planManagedAppSync(targetDir, {}, effective) : null;
1169
1323
  const base = scaffold?.planned || [];
1170
- const plan = buildExistingSubmittedAppSyncPlan(targetDir, versions, planSources(targetDir, base));
1324
+ const plan = buildExistingSubmittedAppSyncPlan(targetDir, effective, planSources(targetDir, base), managed);
1171
1325
  plan.planned = [...base, ...plan.planned, ...guidance];
1172
- return executeProjectPlan(targetDir, options, versions, runners, plan, scaffold);
1326
+ return executeProjectPlan(targetDir, options, effective, runners, plan, scaffold, versions);
1173
1327
  }
1174
1328
 
1175
1329
  function adoptionSources(targetDir, options) {
@@ -1230,19 +1384,21 @@ export function adoptAppProject(cwd, options = {}, versions, runners = {}) {
1230
1384
 
1231
1385
  export function checkAppProject(cwd, options = {}, versions, runners = {}) {
1232
1386
  const targetDir = resolveTargetDir(cwd, options);
1233
- if (options.conformance) {
1234
- return validateAppProject(cwd, { dir: targetDir, conformance: options.conformance, json: options.json }, versions, runners);
1235
- }
1236
1387
  assertNoRetiredScaffoldState(targetDir);
1237
1388
  const managed = existsSync(path.join(targetDir, SCAFFOLD_LOCK_PATH));
1238
- const existingState = managed ? null : assertProjectLifecycleCurrent(targetDir, versions, { requireInstalledLock: true });
1239
- const validation = validateAppProject(cwd, { dir: targetDir, silent: true }, versions, runners);
1389
+ const effective = managed ? managedProjectVersions(targetDir, versions) : versions;
1390
+ const existingState = managed ? null : assertProjectLifecycleCurrent(targetDir, effective, { requireInstalledLock: true, production: options.production === true, managed });
1391
+ const validation = validateAppProject(cwd, { dir: targetDir, silent: true }, effective, runners);
1240
1392
  let nimicoding = null;
1241
1393
  if (!managed) nimicoding = runNimicodingSync(targetDir, 'check', runners);
1242
- const { descriptor, buildProfile } = existingState || assertProjectLifecycleCurrent(targetDir, versions, { requireInstalledLock: true });
1394
+ const { descriptor, buildProfile, combination } = existingState || assertProjectLifecycleCurrent(targetDir, effective, { requireInstalledLock: true, production: options.production === true, managed });
1243
1395
  if (options.production === true) {
1244
1396
  for (const target of Object.keys(buildProfile.targets)) readAppInfo(targetDir, target);
1245
1397
  }
1398
+ const safetyProfile = descriptor.safetyProfile ? 'declared' : 'undeclared';
1399
+ if (options.production === true && !options.json && safetyProfile === 'undeclared') {
1400
+ process.stdout.write('[nimi-app] safety_profile is not declared in nimi.app.yaml; local builds and private packages remain usable, while new public Registry admission requires the declaration.\n');
1401
+ }
1246
1402
  return emitResult({
1247
1403
  ok: true,
1248
1404
  command: 'check',
@@ -1251,6 +1407,8 @@ export function checkAppProject(cwd, options = {}, versions, runners = {}) {
1251
1407
  managed,
1252
1408
  appId: descriptor.appId,
1253
1409
  profile: descriptor.profile,
1410
+ safetyProfile,
1411
+ dependencyCombination: describeCombination(combination, versions),
1254
1412
  targets: Object.keys(buildProfile.targets).sort(),
1255
1413
  checkedManagedFiles: validation.checkedManagedFiles,
1256
1414
  checkedExistingFiles: validation.checkedExistingFiles,