@nimiplatform/app-tools 0.6.3 → 0.11.4

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 (115) hide show
  1. package/README.md +153 -12
  2. package/bin/nimi-app.mjs +16 -14
  3. package/lib/app-access-declaration.mjs +1 -0
  4. package/lib/app-dependency-combinations.mjs +49 -0
  5. package/lib/app-doctor-update.mjs +84 -23
  6. package/lib/app-info.mjs +33 -3
  7. package/lib/app-lifecycle-guidance.mjs +4 -2
  8. package/lib/app-pack.mjs +5 -2
  9. package/lib/app-project-lifecycle.mjs +284 -53
  10. package/lib/app-safety-profile.mjs +204 -0
  11. package/lib/app-scaffold-capabilities.mjs +11 -3
  12. package/lib/app-scaffold-profiles.mjs +136 -27
  13. package/lib/app-scaffold.mjs +55 -7
  14. package/lib/canonical-capability-ids.generated.mjs +25 -0
  15. package/lib/index.mjs +0 -4
  16. package/package.json +27 -31
  17. package/scripts/dev-shell.mjs +80 -18
  18. package/skills/nimi-app-lifecycle/SKILL.md +7 -3
  19. package/skills/nimi-app-lifecycle/references/acceptance.md +7 -1
  20. package/skills/nimi-app-lifecycle/references/adapt.md +46 -1
  21. package/skills/nimi-app-lifecycle/references/audit.md +55 -0
  22. package/skills/nimi-app-lifecycle/references/platform-gaps.md +15 -0
  23. package/skills/nimi-app-lifecycle/references/release.md +2 -2
  24. package/skills/nimi-app-lifecycle/references/safety-declaration.md +37 -0
  25. package/skills/nimi-app-lifecycle/references/upgrade-platform.md +16 -2
  26. package/templates/app-source/src/ai-studio-core/ai-config.ts +17 -3
  27. package/templates/app-source/src/ai-studio-core/ai-studio-core.css +40 -3
  28. package/templates/app-source/src/ai-studio-core/audio-separation-request.ts +24 -0
  29. package/templates/app-source/src/ai-studio-core/contexts.tsx +4 -0
  30. package/templates/app-source/src/ai-studio-core/history-policy.ts +395 -41
  31. package/templates/app-source/src/ai-studio-core/history.ts +262 -10
  32. package/templates/app-source/src/ai-studio-core/host-context.tsx +15 -2
  33. package/templates/app-source/src/ai-studio-core/index.ts +15 -4
  34. package/templates/app-source/src/ai-studio-core/job-recovery-panel.tsx +105 -0
  35. package/templates/app-source/src/ai-studio-core/job-recovery.ts +224 -0
  36. package/templates/app-source/src/ai-studio-core/managed-result-references.ts +79 -0
  37. package/templates/app-source/src/ai-studio-core/messages/en.json +185 -10
  38. package/templates/app-source/src/ai-studio-core/messages/zh.json +185 -10
  39. package/templates/app-source/src/ai-studio-core/module-registration.ts +9 -1
  40. package/templates/app-source/src/ai-studio-core/non-success-presentation.ts +81 -2
  41. package/templates/app-source/src/ai-studio-core/parameters.ts +34 -1
  42. package/templates/app-source/src/ai-studio-core/runtime-types.ts +124 -8
  43. package/templates/app-source/src/ai-studio-core/runtime.ts +218 -20
  44. package/templates/app-source/src/ai-studio-core/section-ai-testing-annotation-result.tsx +123 -0
  45. package/templates/app-source/src/ai-studio-core/section-ai-testing-artifact-preview.ts +3 -0
  46. package/templates/app-source/src/ai-studio-core/section-ai-testing-audio-separation-result.tsx +26 -0
  47. package/templates/app-source/src/ai-studio-core/section-ai-testing-composer.tsx +14 -7
  48. package/templates/app-source/src/ai-studio-core/section-ai-testing-decision-result.tsx +76 -0
  49. package/templates/app-source/src/ai-studio-core/section-ai-testing-exchange-result.tsx +71 -0
  50. package/templates/app-source/src/ai-studio-core/section-ai-testing-history.tsx +20 -4
  51. package/templates/app-source/src/ai-studio-core/section-ai-testing-input.ts +29 -0
  52. package/templates/app-source/src/ai-studio-core/section-ai-testing-music-result.tsx +45 -0
  53. package/templates/app-source/src/ai-studio-core/section-ai-testing-output.tsx +132 -10
  54. package/templates/app-source/src/ai-studio-core/section-ai-testing-result.tsx +122 -38
  55. package/templates/app-source/src/ai-studio-core/section-ai-testing-run.ts +4 -3
  56. package/templates/app-source/src/ai-studio-core/section-ai-testing-session-result.tsx +66 -0
  57. package/templates/app-source/src/ai-studio-core/section-ai-testing-studio-result.tsx +100 -22
  58. package/templates/app-source/src/ai-studio-core/section-ai-testing-surface.tsx +6 -0
  59. package/templates/app-source/src/ai-studio-core/section-ai-testing-transcript-result.tsx +45 -0
  60. package/templates/app-source/src/ai-studio-core/section-ai-testing-transcription-result.tsx +106 -0
  61. package/templates/app-source/src/ai-studio-core/section-ai-testing-vision-result.tsx +23 -4
  62. package/templates/app-source/src/ai-studio-core/section-ai-testing-voice-asset-actions.tsx +40 -0
  63. package/templates/app-source/src/ai-studio-core/section-ai-testing-voice-conversion-result.tsx +20 -0
  64. package/templates/app-source/src/ai-studio-core/section-ai-testing.tsx +219 -35
  65. package/templates/app-source/src/ai-studio-core/text-annotation-document.ts +50 -0
  66. package/templates/app-source/src/ai-studio-core/text-media-replay.ts +51 -0
  67. package/templates/app-source/src/ai-studio-core/voice-assets.ts +17 -0
  68. package/templates/app-source/src/ai-studio-core/workspace.tsx +48 -6
  69. package/templates/app-source/src/studio-modules/studio-create/descriptors.ts +1 -1
  70. package/templates/app-source/src/studio-modules/studio-create/messages/en.json +13 -1
  71. package/templates/app-source/src/studio-modules/studio-create/messages/zh.json +13 -1
  72. package/templates/app-source/src/studio-modules/studio-create/parameter-panel.tsx +11 -2
  73. package/templates/app-source/src/studio-modules/studio-create/parameters.ts +2 -2
  74. package/templates/app-source/src/studio-modules/studio-create/registration.ts +2 -2
  75. package/templates/app-source/src/studio-modules/studio-create/runtime.ts +121 -3
  76. package/templates/app-source/src/studio-modules/studio-media/audio-separate-parameters.tsx +72 -0
  77. package/templates/app-source/src/studio-modules/studio-media/audio-separate-runtime.ts +90 -0
  78. package/templates/app-source/src/studio-modules/studio-media/descriptors.ts +16 -1
  79. package/templates/app-source/src/studio-modules/studio-media/index.ts +2 -0
  80. package/templates/app-source/src/studio-modules/studio-media/messages/en.json +225 -7
  81. package/templates/app-source/src/studio-modules/studio-media/messages/zh.json +225 -7
  82. package/templates/app-source/src/studio-modules/studio-media/music-parameters.tsx +85 -0
  83. package/templates/app-source/src/studio-modules/studio-media/music-transcription-parameters.tsx +85 -0
  84. package/templates/app-source/src/studio-modules/studio-media/music-transcription-runtime.ts +64 -0
  85. package/templates/app-source/src/studio-modules/studio-media/parameter-panel.tsx +9 -26
  86. package/templates/app-source/src/studio-modules/studio-media/parameters.ts +170 -6
  87. package/templates/app-source/src/studio-modules/studio-media/registration.ts +29 -1
  88. package/templates/app-source/src/studio-modules/studio-media/runtime.ts +90 -6
  89. package/templates/app-source/src/studio-modules/studio-media/vision-parameters.tsx +1 -0
  90. package/templates/app-source/src/studio-modules/studio-media/vision-runtime.ts +23 -5
  91. package/templates/app-source/src/studio-modules/studio-media/voice-convert-parameters.tsx +132 -0
  92. package/templates/app-source/src/studio-modules/studio-media/voice-convert-runtime.ts +120 -0
  93. package/templates/app-source/src/studio-modules/studio-voice/audio-url.ts +25 -0
  94. package/templates/app-source/src/studio-modules/studio-voice/messages/en.json +4 -4
  95. package/templates/app-source/src/studio-modules/studio-voice/messages/zh.json +4 -4
  96. package/templates/app-source/src/studio-modules/studio-voice/parameters.ts +36 -10
  97. package/templates/app-source/src/studio-modules/studio-voice/runtime.ts +66 -30
  98. package/templates/app-source/src/workbench-core/index.ts +2 -0
  99. package/templates/app-source/src/workbench-core/runtime-gate.tsx +102 -6
  100. package/templates/app-source/src/workbench-core/workbench-core.css +42 -0
  101. package/templates/app-source/src/workbench-core/workbench-core.tsx +69 -18
  102. package/templates/app-source.manifest.json +100 -0
  103. package/templates/default-starter/AGENTS.md +4 -2
  104. package/templates/default-starter/README.md +2 -1
  105. package/templates/default-starter/src/shell/workbench-target-adapter.ts +102 -12
  106. package/templates/default-starter.manifest.json +0 -4
  107. package/lib/simulator-conformance-ast.mjs +0 -498
  108. package/lib/simulator-conformance-css.mjs +0 -116
  109. package/lib/simulator-conformance-graph.mjs +0 -757
  110. package/lib/simulator-conformance.d.mts +0 -14
  111. package/lib/simulator-conformance.mjs +0 -203
  112. package/lib/simulator-css-profile.d.mts +0 -27
  113. package/lib/simulator-css-profile.mjs +0 -531
  114. package/lib/simulator-kit-export-resolution.mjs +0 -70
  115. package/lib/simulator-manifest.mjs +0 -334
@@ -1,12 +1,18 @@
1
1
  import { readAppInfo } from './app-info.mjs';
2
+ import { CANONICAL_CAPABILITY_IDS } from './canonical-capability-ids.generated.mjs';
2
3
  // @nimi-authority: rule.nimi.platform.app-ecosystem.p-scaf-018c
3
4
  // @nimi-authority: rule.nimi.platform.app-ecosystem.p-napp-009b
5
+ // @nimi-authority: rule.nimi.platform.app-ecosystem.p-napp-043a
4
6
 
5
- import { existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from 'node:fs';
7
+ import { existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, realpathSync, writeFileSync } from 'node:fs';
8
+ import { createRequire } from 'node:module';
6
9
  import path from 'node:path';
10
+ import { satisfies } from 'semver';
7
11
  import { parse as parseYaml, parseDocument as parseYamlDocument, stringify as stringifyYaml } from 'yaml';
8
12
 
9
13
  import { assertManifestAppAccessDeclaration } from './app-access-declaration.mjs';
14
+ import { defaultDependencyCombination, resolveDependencyCombination } from './app-dependency-combinations.mjs';
15
+ import { SAFETY_PROFILE_FIELD, normalizeSafetyProfile } from './app-safety-profile.mjs';
10
16
  import { planManagedAppSync, validateAppProject, validateAppProjectInputs, validateManagedAppFiles } from './app-doctor-update.mjs';
11
17
  import { LIFECYCLE_SKILL_PATH, hasLifecycleGuidanceOwner, lifecycleOwnerSteps, planLifecycleGuidance } from './app-lifecycle-guidance.mjs';
12
18
  import { applyProjectFiles, describeChanges, plannedFile } from './app-project-files.mjs';
@@ -38,6 +44,7 @@ const SYNCHRONIZED_NIMI_PACKAGES = new Set([
38
44
  '@nimiplatform/kit',
39
45
  '@nimiplatform/app-tools',
40
46
  '@nimiplatform/nimi-coding',
47
+ '@nimiplatform/sdk-adapter-vercel-ai',
41
48
  ...KIT_OWNED_NATIVE_CARRIERS,
42
49
  ]);
43
50
  const BUILD_PROFILE_PATH = '.nimi/config/build-profile.yaml';
@@ -132,7 +139,18 @@ function readSubmittedManifest(targetDir, sources) {
132
139
  if (!SEMVER_PATTERN.test(version) || version !== document.version) {
133
140
  throw new Error('Existing submitted app version must be an exact semantic version');
134
141
  }
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 });
142
+ let safetyProfile;
143
+ if (document.capability_contract_refs !== undefined) {
144
+ canonicalInputList(document.capability_contract_refs, 'nimi.app.yaml capability_contract_refs');
145
+ }
146
+ if (document[SAFETY_PROFILE_FIELD] !== undefined) {
147
+ try {
148
+ safetyProfile = normalizeSafetyProfile(document[SAFETY_PROFILE_FIELD]);
149
+ } catch (error) {
150
+ throw new Error(`nimi.app.yaml ${error instanceof Error ? error.message : String(error)}`, { cause: error });
151
+ }
152
+ }
153
+ 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
154
  }
137
155
 
138
156
  function assertNoRetiredScaffoldState(targetDir) {
@@ -147,15 +165,41 @@ function assertNoRetiredScaffoldState(targetDir) {
147
165
  }
148
166
  }
149
167
 
150
- function expectedNimiDependencies(versions) {
168
+ // The SDK/Kit pair comes from the App's resolved combination; the tool
169
+ // dependencies come from the selected tool version. Both are one judgment
170
+ // shared by manifest, lock, Cargo and workflow checks.
171
+ function expectedNimiDependencies(versions, combination) {
151
172
  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 }),
173
+ Object.freeze({ name: '@nimiplatform/sdk', section: 'dependencies', version: combination.sdkVersion }),
174
+ Object.freeze({ name: '@nimiplatform/kit', section: 'dependencies', version: combination.kitVersion }),
154
175
  Object.freeze({ name: '@nimiplatform/app-tools', section: 'devDependencies', version: versions.appToolsVersion }),
155
176
  Object.freeze({ name: '@nimiplatform/nimi-coding', section: 'devDependencies', version: versions.nimicodingVersion }),
156
177
  ]);
157
178
  }
158
179
 
180
+ // Managed (scaffold-locked) projects derive glue, matrix and package fields
181
+ // from `versions`; `managedProjectVersions` has already pinned those to the
182
+ // project's own supported combination, so the default of the effective
183
+ // versions is that combination. Existing submitted Apps resolve theirs directly.
184
+ function selectDependencyCombination(packageJson, versions, managed) {
185
+ return managed ? defaultDependencyCombination(versions) : resolveDependencyCombination(packageJson, versions);
186
+ }
187
+
188
+ // Validate the App's explicit SDK/Kit selection before deriving or writing
189
+ // managed glue. A previous Host contract must be upgraded by the App first;
190
+ // selecting a newer tool never silently changes business dependencies.
191
+ function managedProjectVersions(targetDir, versions) {
192
+ const packagePath = path.join(targetDir, 'package.json');
193
+ if (!existsSync(packagePath)) return versions;
194
+ const combination = resolveDependencyCombination(readJsonFile(packagePath, 'package.json'), versions);
195
+ return Object.freeze({ ...versions, sdkVersion: combination.sdkVersion, kitVersion: combination.kitVersion, nimiShellTauriVersion: combination.nimiShellTauriVersion });
196
+ }
197
+
198
+ function describeCombination(combination, toolVersions) {
199
+ const isDefault = combination.sdkVersion === toolVersions.sdkVersion && combination.kitVersion === toolVersions.kitVersion;
200
+ return { sdk: combination.sdkVersion, kit: combination.kitVersion, source: isDefault ? 'default' : 'existing' };
201
+ }
202
+
159
203
  function dependencySection(packageJson, sectionName) {
160
204
  const section = packageJson[sectionName];
161
205
  if (section === undefined) return null;
@@ -172,6 +216,15 @@ function isLocalDependencySpec(value) {
172
216
  || /\.(?:tar\.gz|tgz)(?:[?#].*)?$/iu.test(normalized);
173
217
  }
174
218
 
219
+ function localPackageArchive(value) {
220
+ return typeof value === 'string' ? value.match(/^(file:[^\r\n]+?\.(?:tgz|tar\.gz))(?:\(.*\))?$/u)?.[1] || '' : '';
221
+ }
222
+
223
+ function archivePath(targetDir, value) {
224
+ const archive = localPackageArchive(value);
225
+ return archive ? path.resolve(targetDir, archive.slice('file:'.length)) : '';
226
+ }
227
+
175
228
  function synchronizedNimiPackageName(key) {
176
229
  const normalized = String(key || '').replace(/^\/+/, '');
177
230
  for (const packageName of SYNCHRONIZED_NIMI_PACKAGES) {
@@ -202,7 +255,7 @@ function assertPublicNimiDependencySpecs(packageJson) {
202
255
  }
203
256
  }
204
257
 
205
- function assertPackageManifestCurrent(packageJson, versions) {
258
+ function assertPackageManifestCurrent(packageJson, versions, combination) {
206
259
  if (packageJson.private !== true || Object.hasOwn(packageJson, 'publishConfig')) {
207
260
  throw new Error('Nimi App package.json must be private and must not declare npm publishConfig');
208
261
  }
@@ -210,7 +263,7 @@ function assertPackageManifestCurrent(packageJson, versions) {
210
263
  throw new Error(`package.json packageManager must be ${versions.packageManager}`);
211
264
  }
212
265
  assertPublicNimiDependencySpecs(packageJson);
213
- for (const expected of expectedNimiDependencies(versions)) {
266
+ for (const expected of expectedNimiDependencies(versions, combination)) {
214
267
  const section = dependencySection(packageJson, expected.section);
215
268
  if (section?.[expected.name] !== expected.version) {
216
269
  throw new Error(`package.json ${expected.section}.${expected.name} must be ${expected.version}`);
@@ -249,9 +302,10 @@ function assertPackageManifestCurrent(packageJson, versions) {
249
302
  if (scripts.publish !== undefined) {
250
303
  throw new Error('package.json scripts.publish is unavailable until publisher GitHub and registry orchestration is implemented');
251
304
  }
305
+ return combination;
252
306
  }
253
307
 
254
- function normalizePackageManifest(packageJson, descriptor, versions, buildProfileRef, packageSource) {
308
+ function normalizePackageManifest(packageJson, descriptor, versions, buildProfileRef, packageSource, combination) {
255
309
  if (!packageJson || typeof packageJson !== 'object' || Array.isArray(packageJson)) {
256
310
  throw new Error('package.json must contain an object');
257
311
  }
@@ -259,7 +313,7 @@ function normalizePackageManifest(packageJson, descriptor, versions, buildProfil
259
313
  normalized.private = true;
260
314
  delete normalized.publishConfig;
261
315
  for (const sectionName of NPM_DEPENDENCY_SECTIONS) dependencySection(normalized, sectionName);
262
- for (const expected of expectedNimiDependencies(versions)) {
316
+ for (const expected of expectedNimiDependencies(versions, combination)) {
263
317
  for (const sectionName of NPM_DEPENDENCY_SECTIONS) {
264
318
  const section = dependencySection(normalized, sectionName);
265
319
  if (section) delete section[expected.name];
@@ -301,7 +355,7 @@ function normalizePackageManifest(packageJson, descriptor, versions, buildProfil
301
355
  .replace(/\bpnpm\s+run\s+doctor\s*&&\s*/gu, '')
302
356
  .replace(/\bnimi-app\s+doctor\s*&&\s*/gu, '');
303
357
  }
304
- assertPackageManifestCurrent(normalized, versions);
358
+ assertPackageManifestCurrent(normalized, versions, combination);
305
359
  // Project formatters may use different whitespace or key order. Only managed
306
360
  // value changes require rewriting this App-owned manifest.
307
361
  if (stableInputJson(normalized) === stableInputJson(packageJson)) return packageSource;
@@ -344,6 +398,11 @@ function canonicalInputList(value, label, allowEmpty = true) {
344
398
  if (!Array.isArray(value) || (!allowEmpty && value.length === 0)) throw new Error(`${label} must be ${allowEmpty ? 'an array' : 'a non-empty array'}`);
345
399
  const entries = value.map((item, index) => canonicalInputText(item, `${label}[${index}]`));
346
400
  if (new Set(entries).size !== entries.length) throw new Error(`${label} must not contain duplicates`);
401
+ if (label.endsWith('capability_contract_refs')) {
402
+ for (const entry of entries) {
403
+ if (!CANONICAL_CAPABILITY_IDS.includes(entry)) throw new Error(`${label} contains unknown CapabilityContract: ${entry}`);
404
+ }
405
+ }
347
406
  return entries;
348
407
  }
349
408
 
@@ -406,7 +465,7 @@ function normalizePnpmWorkspace(targetDir) {
406
465
  }
407
466
  let removed = false;
408
467
  for (const key of Object.keys(overrides || {})) {
409
- if (synchronizedNimiPackageName(key)) {
468
+ if (synchronizedNimiPackageName(key) && !localPackageArchive(overrides[key])) {
410
469
  document.deleteIn(['overrides', key]);
411
470
  removed = true;
412
471
  }
@@ -420,9 +479,10 @@ function normalizePnpmWorkspace(targetDir) {
420
479
  };
421
480
  }
422
481
 
423
- function assertPnpmWorkspaceCurrent(targetDir, sources) {
482
+ function assertPnpmWorkspaceCurrent(targetDir, sources, production = false) {
424
483
  const workspacePath = path.join(targetDir, 'pnpm-workspace.yaml');
425
- if (!hasProjectFile(targetDir, 'pnpm-workspace.yaml', sources)) return;
484
+ const localPackages = new Map();
485
+ if (!hasProjectFile(targetDir, 'pnpm-workspace.yaml', sources)) return localPackages;
426
486
  const source = readProjectText(targetDir, 'pnpm-workspace.yaml', sources);
427
487
  const workspace = parseYamlFile(source, workspacePath);
428
488
  const overrides = workspace?.overrides;
@@ -430,16 +490,24 @@ function assertPnpmWorkspaceCurrent(targetDir, sources) {
430
490
  throw new Error('pnpm-workspace.yaml overrides must be an object');
431
491
  }
432
492
  for (const key of Object.keys(overrides || {})) {
433
- if (synchronizedNimiPackageName(key)) {
493
+ const packageName = synchronizedNimiPackageName(key);
494
+ if (packageName && localPackageArchive(overrides[key])) {
495
+ 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.');
496
+ if (key !== packageName) throw new Error(`Local Nimi tarball overrides must name the exact package: ${key}`);
497
+ const target = archivePath(targetDir, overrides[key]);
498
+ if (!existsSync(target) || !lstatSync(target).isFile()) throw installRequiredError(`Local Nimi package archive is missing: ${overrides[key]}`);
499
+ localPackages.set(packageName, overrides[key]);
500
+ } else if (packageName) {
434
501
  throw installRequiredError(`pnpm-workspace.yaml retains a Nimi dependency override: ${key}`);
435
502
  }
436
503
  }
504
+ return localPackages;
437
505
  }
438
506
 
439
- function findLocalNimiResolution(value, currentPackage = '', pathParts = []) {
507
+ function findLocalNimiResolution(value, currentPackage = '', pathParts = [], allowedArchive = () => false) {
440
508
  if (Array.isArray(value)) {
441
509
  for (let index = 0; index < value.length; index += 1) {
442
- const finding = findLocalNimiResolution(value[index], currentPackage, [...pathParts, String(index)]);
510
+ const finding = findLocalNimiResolution(value[index], currentPackage, [...pathParts, String(index)], allowedArchive);
443
511
  if (finding) return finding;
444
512
  }
445
513
  return null;
@@ -452,25 +520,63 @@ function findLocalNimiResolution(value, currentPackage = '', pathParts = []) {
452
520
  packageName
453
521
  && normalizedKey.startsWith(`${packageName}@`)
454
522
  && isLocalDependencySpec(normalizedKey.slice(packageName.length + 1))
523
+ && !allowedArchive(packageName, normalizedKey.slice(packageName.length + 1), [...pathParts, key])
455
524
  ) {
456
525
  return [...pathParts, key].join('.');
457
526
  }
458
- if (packageName && typeof child === 'string' && isLocalDependencySpec(child)) {
527
+ if (packageName && typeof child === 'string' && isLocalDependencySpec(child) && !allowedArchive(packageName, child, [...pathParts, key])) {
459
528
  return [...pathParts, key].join('.');
460
529
  }
461
- const finding = findLocalNimiResolution(child, packageName, [...pathParts, key]);
530
+ const finding = findLocalNimiResolution(child, packageName, [...pathParts, key], allowedArchive);
462
531
  if (finding) return finding;
463
532
  }
464
533
  return null;
465
534
  }
466
535
 
467
- function assertPnpmLockCurrent(targetDir, packageJson) {
536
+ function readInstalledPnpmLock(targetDir) {
537
+ const modulesPath = path.join(targetDir, 'node_modules', '.modules.yaml');
538
+ if (!existsSync(modulesPath)) throw installRequiredError('pnpm installation metadata is missing');
539
+ const modules = parseYamlFile(readFileSync(modulesPath, 'utf8'), modulesPath);
540
+ if (typeof modules?.virtualStoreDir !== 'string' || !modules.virtualStoreDir.trim()) {
541
+ throw installRequiredError('pnpm installation has no virtual store');
542
+ }
543
+ const installedLockPath = path.join(path.resolve(targetDir, 'node_modules', modules.virtualStoreDir), 'lock.yaml');
544
+ if (!existsSync(installedLockPath)) throw installRequiredError('pnpm installed dependency lock is missing');
545
+ return parseYamlFile(readFileSync(installedLockPath, 'utf8'), installedLockPath);
546
+ }
547
+
548
+ function selectedLocalPackageRecord(lock, name, selected, targetDir) {
549
+ const matches = Object.entries(lock?.packages || {}).filter(([key, entry]) =>
550
+ key.startsWith(name + '@') && archivePath(targetDir, entry?.resolution?.tarball) === archivePath(targetDir, selected));
551
+ if (matches.length !== 1 || typeof matches[0][1]?.version !== 'string'
552
+ || typeof matches[0][1]?.resolution?.integrity !== 'string' || !matches[0][1].resolution.integrity) {
553
+ throw installRequiredError(`Local Nimi package installation is stale or has no complete locked tarball resolution: ${name}`);
554
+ }
555
+ return matches[0][1];
556
+ }
557
+
558
+ function assertPnpmLockCurrent(targetDir, packageJson, localPackages, versions, combination) {
468
559
  const lockPath = path.join(targetDir, 'pnpm-lock.yaml');
469
560
  if (!existsSync(lockPath)) {
470
561
  throw installRequiredError('pnpm-lock.yaml is missing');
471
562
  }
472
563
  const lock = parseYamlFile(readFileSync(lockPath, 'utf8'), lockPath);
473
- const finding = findLocalNimiResolution(lock);
564
+ const allowedArchive = (name, value, location = []) => {
565
+ // pnpm rebases importer specifiers to the member directory; resolved
566
+ // versions and package/snapshot keys stay relative to the workspace root.
567
+ let base = targetDir;
568
+ if (location.length === 5 && location[0] === 'importers'
569
+ && NPM_DEPENDENCY_SECTIONS.includes(location[2]) && location[4] === 'specifier') {
570
+ base = path.resolve(targetDir, location[1]);
571
+ const relative = path.relative(targetDir, base);
572
+ if (path.isAbsolute(location[1]) || relative === '..' || relative.startsWith(`..${path.sep}`)) {
573
+ throw installRequiredError(`pnpm-lock.yaml importer is outside the App workspace: ${location[1]}`);
574
+ }
575
+ }
576
+ return localPackageArchive(value) && localPackages.has(name)
577
+ && archivePath(base, value) === archivePath(targetDir, localPackages.get(name));
578
+ };
579
+ const finding = findLocalNimiResolution(lock, '', [], allowedArchive);
474
580
  if (finding) {
475
581
  throw installRequiredError(`pnpm-lock.yaml retains a local Nimi resolution at ${finding}`);
476
582
  }
@@ -478,14 +584,51 @@ function assertPnpmLockCurrent(targetDir, packageJson) {
478
584
  if (!importer || typeof importer !== 'object' || Array.isArray(importer)) {
479
585
  throw installRequiredError('pnpm-lock.yaml root importer is missing');
480
586
  }
587
+ const installedLock = localPackages.size > 0 ? readInstalledPnpmLock(targetDir) : null;
588
+ for (const [name, selected] of localPackages) {
589
+ if (lock.overrides?.[name] !== selected) throw installRequiredError(`pnpm-lock.yaml local package override does not match pnpm-workspace.yaml: ${name}`);
590
+ let manifestPath = path.join(targetDir, 'node_modules', ...name.split('/'), 'package.json');
591
+ if (KIT_OWNED_NATIVE_CARRIERS.includes(name)) {
592
+ try {
593
+ const kitManifest = realpathSync(path.join(targetDir, 'node_modules', '@nimiplatform', 'kit', 'package.json'));
594
+ manifestPath = createRequire(kitManifest).resolve(name + '/package.json');
595
+ } catch {
596
+ throw installRequiredError(`Local Nimi native package is not installed for Kit: ${name}`);
597
+ }
598
+ }
599
+ if (!existsSync(manifestPath)) throw installRequiredError(`Local Nimi package is not installed: ${name}`);
600
+ const installed = readJsonFile(manifestPath, name);
601
+ const declared = NPM_DEPENDENCY_SECTIONS.map((section) => dependencySection(packageJson, section)?.[name]).filter((value) => value !== undefined);
602
+ const expected = expectedNimiDependencies(versions, combination).find((entry) => entry.name === name)?.version
603
+ || (KIT_OWNED_NATIVE_CARRIERS.includes(name) ? combination.kitVersion : declared[0]);
604
+ if (!expected || declared.some((specifier) => specifier !== expected)) {
605
+ throw installRequiredError(`Local Nimi package has no consistent declared version: ${name}`);
606
+ }
607
+ if (installed.name !== name || !satisfies(installed.version, expected, { includePrerelease: true })) {
608
+ throw installRequiredError(`Installed local Nimi package must be ${name}@${expected}`);
609
+ }
610
+ if (archivePath(targetDir, installedLock?.overrides?.[name]) !== archivePath(targetDir, selected)) {
611
+ throw installRequiredError(`Local Nimi package installation is stale: ${name}`);
612
+ }
613
+ const locked = selectedLocalPackageRecord(lock, name, selected, targetDir);
614
+ const installedResolution = selectedLocalPackageRecord(installedLock, name, selected, targetDir);
615
+ if (installed.version !== locked.version || installedResolution.version !== locked.version
616
+ || installedResolution.resolution.integrity !== locked.resolution.integrity) {
617
+ throw installRequiredError(`Local Nimi package installation is stale: ${name}`);
618
+ }
619
+ }
481
620
  for (const sectionName of NPM_DEPENDENCY_SECTIONS) {
482
621
  const packageSection = dependencySection(packageJson, sectionName) || {};
483
622
  const lockSection = importer[sectionName] || {};
484
623
  for (const [name, specifier] of Object.entries(packageSection)) {
485
624
  if (!name.startsWith('@nimiplatform/')) continue;
486
- if (lockSection?.[name]?.specifier !== specifier) {
625
+ if (lockSection?.[name]?.specifier !== (localPackages.get(name) || specifier)) {
487
626
  throw installRequiredError(`pnpm-lock.yaml ${sectionName}.${name} specifier does not match package.json`);
488
627
  }
628
+ if (localPackages.has(name)
629
+ && installedLock?.importers?.['.']?.[sectionName]?.[name]?.version !== lockSection[name]?.version) {
630
+ throw installRequiredError(`Local Nimi package installation is stale: ${name}`);
631
+ }
489
632
  }
490
633
  for (const name of Object.keys(lockSection || {})) {
491
634
  if (name.startsWith('@nimiplatform/') && !Object.hasOwn(packageSection, name)) {
@@ -493,6 +636,21 @@ function assertPnpmLockCurrent(targetDir, packageJson) {
493
636
  }
494
637
  }
495
638
  }
639
+ for (const [importerName, child] of Object.entries(lock.importers)) {
640
+ if (importerName === '.') continue;
641
+ for (const sectionName of NPM_DEPENDENCY_SECTIONS) {
642
+ for (const [name, dependency] of Object.entries(child?.[sectionName] || {})) {
643
+ if (!localPackages.has(name)) continue;
644
+ const location = ['importers', importerName, sectionName, name, 'specifier'];
645
+ const installed = installedLock?.importers?.[importerName]?.[sectionName]?.[name];
646
+ if (typeof dependency?.version !== 'string' || installed?.version !== dependency.version
647
+ || !allowedArchive(name, dependency?.specifier, location)
648
+ || !allowedArchive(name, installed?.specifier, location)) {
649
+ throw installRequiredError(`Local Nimi package installation is stale: importers.${importerName}.${sectionName}.${name}`);
650
+ }
651
+ }
652
+ }
653
+ }
496
654
  }
497
655
 
498
656
  function assertCargoLockCurrent(targetDir, version) {
@@ -760,7 +918,7 @@ function assertCanonicalAuthoringInputs(targetDir, descriptor, files, version, n
760
918
  'support_manifest',
761
919
  'review_inputs',
762
920
  'admission_truth',
763
- ], ['ai_profile_recommendation_ref']);
921
+ ], ['ai_profile_recommendation_ref', SAFETY_PROFILE_FIELD]);
764
922
  const expectedSubmissionIdentity = {
765
923
  app_id: descriptor.appId,
766
924
  display_name: descriptor.displayName,
@@ -783,6 +941,11 @@ function assertCanonicalAuthoringInputs(targetDir, descriptor, files, version, n
783
941
  }
784
942
  normalizeStorageInput(submission.storage_policy, `${SUBMISSION_PATH} storage_policy`);
785
943
  normalizeSupportInput(submission.support_manifest, `${SUBMISSION_PATH} support_manifest`);
944
+ // nimi.app.yaml is the only declaration author; the submission copy must be
945
+ // the tool projection of it, never an independently edited second source.
946
+ if (JSON.stringify(submission[SAFETY_PROFILE_FIELD]) !== JSON.stringify(descriptor.safetyProfile)) {
947
+ throw new Error(`${SUBMISSION_PATH} ${SAFETY_PROFILE_FIELD} must match the nimi.app.yaml declaration; run nimi-app sync to project it`);
948
+ }
786
949
  const reviewInputs = assertExactKeys(submission.review_inputs, `${SUBMISSION_PATH} review_inputs`, ['manifest', 'build_profile', 'scaffold_boundary']);
787
950
  const expectedReviewInputs = {
788
951
  manifest: 'nimi.app.yaml',
@@ -795,6 +958,43 @@ function assertCanonicalAuthoringInputs(targetDir, descriptor, files, version, n
795
958
  return { identity, submission };
796
959
  }
797
960
 
961
+ function isScopedComponentReleaseWorkflow(source, targetDir) {
962
+ // A separate, non-latest component tag with matching bounded asset names is
963
+ // not the App release. Unclassified releases still require owner review.
964
+ if (/candidate-uploads|\/api\/platform\/apps\/candidates|\.nimiapp\b|\bnimi-app\s+(?:build|pack)\b|\belectron-builder\b|\btauri\s+build\b/iu.test(source)
965
+ || /\bgh\s+release\s+(?:create|upload|edit|delete)\b/iu.test(source)) return false;
966
+ const packageJson = JSON.parse(readFileSync(path.join(targetDir, 'package.json'), 'utf8'));
967
+ const inspectedScripts = new Set();
968
+ const invokesAppBuild = command => {
969
+ if (/\bnimi-app\s+(?:build|pack)\b|\belectron-builder\b|\btauri\s+build\b/u.test(command)) return true;
970
+ for (const match of command.matchAll(/\b(?:npm|pnpm)\s+(?:run\s+)?([\w:-]+)/gu)) {
971
+ if (inspectedScripts.has(match[1])) continue;
972
+ inspectedScripts.add(match[1]);
973
+ const script = packageJson.scripts?.[match[1]];
974
+ if (script && invokesAppBuild(script)) return true;
975
+ }
976
+ return false;
977
+ };
978
+ if (invokesAppBuild(source)) return false;
979
+ let workflow;
980
+ try { workflow = parseYaml(source); } catch { return false; }
981
+ const releaseSteps = Object.values(workflow?.jobs ?? {}).flatMap(job => job?.steps ?? [])
982
+ .filter(step => /(?:softprops\/action-gh-release|ncipollo\/release-action|actions\/create-release)/iu.test(String(step?.uses ?? '')));
983
+ if (releaseSteps.length === 0) return false;
984
+ return releaseSteps.every(step => {
985
+ if (!/^softprops\/action-gh-release@/u.test(String(step.uses)) || step.with?.make_latest !== false) return false;
986
+ const tag = String(step.with?.tag_name ?? '');
987
+ const prefix = /^([a-zA-Z0-9][a-zA-Z0-9._-]*)-v(?=\$\{\{|\d)/u.exec(tag)?.[1];
988
+ if (!prefix || prefix === packageJson.name || prefix === packageJson.name?.replace(/^@[^/]+\//u, '')) return false;
989
+ const files = typeof step.with?.files === 'string' ? step.with.files.trim().split(/\r?\n/u) : [];
990
+ return files.length > 0 && files.every(file => (
991
+ (file.startsWith(`${prefix}-`) || file.startsWith(`${prefix}.`))
992
+ && !/[\\/]/u.test(file) && !file.includes('..')
993
+ && /\.(?:zip|tar\.gz|exe|dll|node|\*)$/u.test(file)
994
+ ));
995
+ });
996
+ }
997
+
798
998
  function assertManagedWorkflowCurrent(targetDir, sources) {
799
999
  const workflowPath = path.join(targetDir, MANAGED_WORKFLOW_PATH);
800
1000
  if (!hasProjectFile(targetDir, MANAGED_WORKFLOW_PATH, sources)) throw new Error(`Required App lifecycle file is missing: ${MANAGED_WORKFLOW_PATH}`);
@@ -806,11 +1006,11 @@ function assertManagedWorkflowCurrent(targetDir, sources) {
806
1006
  const candidatePath = path.join(workflowDir, name);
807
1007
  if (candidatePath === workflowPath || !/\.ya?ml$/iu.test(name)) continue;
808
1008
  const source = readFileSync(candidatePath, 'utf8');
809
- if (
1009
+ if (!isScopedComponentReleaseWorkflow(source, targetDir) && (
810
1010
  /\bgh\s+release\s+(?:create|upload|edit|delete)\b/iu.test(source)
811
1011
  || /(?:softprops\/action-gh-release|ncipollo\/release-action|actions\/create-release)/iu.test(source)
812
1012
  || /candidate-uploads|\/api\/platform\/apps\/candidates/iu.test(source)
813
- ) {
1013
+ )) {
814
1014
  throw new Error(`Parallel App production workflow is forbidden: .github/workflows/${name}`);
815
1015
  }
816
1016
  }
@@ -948,14 +1148,15 @@ function assertProjectLifecycleCurrent(targetDir, versions, options = {}) {
948
1148
  const descriptor = readSubmittedManifest(targetDir, sources);
949
1149
  const buildProfile = readBuildProfile(targetDir, sources);
950
1150
  const files = readProjectLifecycleFiles(targetDir, buildProfile.buildProfileRef, sources);
951
- assertPackageManifestCurrent(files.packageJson, versions);
1151
+ const combination = selectDependencyCombination(files.packageJson, versions, options.managed === true);
1152
+ assertPackageManifestCurrent(files.packageJson, versions, combination);
952
1153
  const version = assertVersionLockstep(files, descriptor, buildProfile.buildProfileRef);
953
1154
  let nativeIdentity = {
954
1155
  cargoPackageName: cargoPackageNameFromNpmPackageName(files.packageJson.name),
955
1156
  tauriIdentifier: tauriIdentifierFromAppId(descriptor.appId),
956
1157
  };
957
1158
  if (buildProfile.buildProfileRef === TAURI_BUILD_PROFILE_REF) {
958
- assertCargoManifestCurrent(files.cargoSource, versions.nimiShellTauriVersion);
1159
+ assertCargoManifestCurrent(files.cargoSource, combination.nimiShellTauriVersion);
959
1160
  assertTauriConfigCurrent(files.tauriConfig, descriptor.appId);
960
1161
  nativeIdentity = {
961
1162
  cargoPackageName: readCargoPackageName(files.cargoSource),
@@ -965,17 +1166,17 @@ function assertProjectLifecycleCurrent(targetDir, versions, options = {}) {
965
1166
  assertNoStandaloneParentSources(targetDir, sources);
966
1167
  const authoring = assertCanonicalAuthoringInputs(targetDir, descriptor, files, version, nativeIdentity, sources);
967
1168
  assertManagedWorkflowCurrent(targetDir, sources);
968
- assertPnpmWorkspaceCurrent(targetDir, sources);
1169
+ const localPackages = assertPnpmWorkspaceCurrent(targetDir, sources, options.production === true);
969
1170
  if (options.requireInstalledLock === true) {
970
- assertPnpmLockCurrent(targetDir, files.packageJson);
1171
+ assertPnpmLockCurrent(targetDir, files.packageJson, localPackages, versions, combination);
971
1172
  if (buildProfile.buildProfileRef === TAURI_BUILD_PROFILE_REF) {
972
- assertCargoLockCurrent(targetDir, versions.nimiShellTauriVersion);
1173
+ assertCargoLockCurrent(targetDir, combination.nimiShellTauriVersion);
973
1174
  }
974
1175
  }
975
- return { descriptor, files, version, buildProfile, authoring };
1176
+ return { descriptor, files, version, buildProfile, authoring, combination };
976
1177
  }
977
1178
 
978
- function buildExistingSubmittedAppSyncPlan(targetDir, versions, sources) {
1179
+ function buildExistingSubmittedAppSyncPlan(targetDir, versions, sources, managed = false) {
979
1180
  const descriptor = readSubmittedManifest(targetDir, sources);
980
1181
  const buildProfile = readBuildProfile(targetDir, sources);
981
1182
  const files = readProjectLifecycleFiles(targetDir, buildProfile.buildProfileRef, sources);
@@ -984,6 +1185,7 @@ function buildExistingSubmittedAppSyncPlan(targetDir, versions, sources) {
984
1185
  throw new Error('package.json version must be an exact semantic version before sync');
985
1186
  }
986
1187
  const requiresTauri = buildProfile.buildProfileRef === TAURI_BUILD_PROFILE_REF;
1188
+ const combination = selectDependencyCombination(files.packageJson, versions, managed);
987
1189
  const identity = {
988
1190
  appId: descriptor.appId,
989
1191
  appTitle: descriptor.displayName,
@@ -999,11 +1201,11 @@ function buildExistingSubmittedAppSyncPlan(targetDir, versions, sources) {
999
1201
  author: typeof files.packageJson.author === 'string' ? files.packageJson.author : '',
1000
1202
  };
1001
1203
  const planned = [
1002
- { path: files.packagePath, content: normalizePackageManifest(files.packageJson, descriptor, versions, buildProfile.buildProfileRef, files.packageSource), previous: files.packageSource },
1204
+ { path: files.packagePath, content: normalizePackageManifest(files.packageJson, descriptor, versions, buildProfile.buildProfileRef, files.packageSource, combination), previous: files.packageSource },
1003
1205
  ];
1004
1206
  if (requiresTauri) {
1005
1207
  planned.push(
1006
- { path: files.cargoPath, content: normalizeCargoManifest(files.cargoSource, versions.nimiShellTauriVersion), previous: files.cargoSource },
1208
+ { path: files.cargoPath, content: normalizeCargoManifest(files.cargoSource, combination.nimiShellTauriVersion), previous: files.cargoSource },
1007
1209
  { path: files.tauriPath, content: normalizeTauriConfig(files.tauriConfig, descriptor.appId), previous: files.tauriSource },
1008
1210
  );
1009
1211
  identity.tauriIdentifier = tauriIdentifierFromAppId(descriptor.appId);
@@ -1036,7 +1238,7 @@ function buildExistingSubmittedAppSyncPlan(targetDir, versions, sources) {
1036
1238
  'support_manifest',
1037
1239
  'review_inputs',
1038
1240
  'admission_truth',
1039
- ], ['ai_profile_recommendation_ref']);
1241
+ ], ['ai_profile_recommendation_ref', SAFETY_PROFILE_FIELD]);
1040
1242
  canonicalInputList(currentSubmission.capability_contract_refs, `${SUBMISSION_PATH} capability_contract_refs`);
1041
1243
  canonicalInputList(currentSubmission.required_standardized_feature_refs, `${SUBMISSION_PATH} required_standardized_feature_refs`);
1042
1244
  normalizeStorageInput(currentSubmission.storage_policy, `${SUBMISSION_PATH} storage_policy`);
@@ -1047,6 +1249,7 @@ function buildExistingSubmittedAppSyncPlan(targetDir, versions, sources) {
1047
1249
  requiredStandardizedFeatureRefs: descriptor.requiredStandardizedFeatureRefs ?? currentSubmission?.required_standardized_feature_refs ?? [],
1048
1250
  aiProfileRecommendationRef: currentSubmission?.ai_profile_recommendation_ref,
1049
1251
  storagePolicy: descriptor.storagePolicy ?? currentSubmission?.storage_policy ?? { kind: 'nimi-mediated-default' },
1252
+ safetyProfile: descriptor.safetyProfile,
1050
1253
  supportManifest,
1051
1254
  });
1052
1255
  planned.push({ path: submissionPath, content: submissionContent, previous: currentSubmissionSource });
@@ -1086,14 +1289,14 @@ function buildExistingSubmittedAppSyncPlan(targetDir, versions, sources) {
1086
1289
  });
1087
1290
  const workspace = normalizePnpmWorkspace(targetDir);
1088
1291
  if (workspace) planned.push(workspace);
1089
- return { descriptor, planned: planned.map((file) => plannedFile(targetDir, path.relative(targetDir, file.path), file.content)), buildProfileRef: buildProfile.buildProfileRef };
1292
+ return { descriptor, planned: planned.map((file) => plannedFile(targetDir, path.relative(targetDir, file.path), file.content)), buildProfileRef: buildProfile.buildProfileRef, combination };
1090
1293
  }
1091
1294
 
1092
- function lifecycleNextSteps(buildProfileRef, versions) {
1295
+ function lifecycleNextSteps(buildProfileRef, combination) {
1093
1296
  return [
1094
1297
  'pnpm install',
1095
1298
  ...(buildProfileRef === TAURI_BUILD_PROFILE_REF
1096
- ? [`cargo update -p nimi-shell-tauri --precise ${versions.nimiShellTauriVersion}`]
1299
+ ? [`cargo update -p nimi-shell-tauri --precise ${combination.nimiShellTauriVersion}`]
1097
1300
  : []),
1098
1301
  'nimi-app sync',
1099
1302
  'nimi-app check',
@@ -1121,28 +1324,50 @@ function planSources(targetDir, planned) {
1121
1324
 
1122
1325
  function validateProjectPlan(targetDir, versions, planned, managed) {
1123
1326
  const sources = planSources(targetDir, planned);
1124
- const current = assertProjectLifecycleCurrent(targetDir, versions, { sources });
1327
+ const current = assertProjectLifecycleCurrent(targetDir, versions, { sources, managed });
1125
1328
  for (const target of Object.keys(current.buildProfile.targets)) selectBuildOwner(current.buildProfile, target);
1126
1329
  validateAppProjectInputs(targetDir, parseYaml(readProjectText(targetDir, 'nimi.app.yaml', sources)), current.files.packageJson, managed, sources);
1127
1330
  return current;
1128
1331
  }
1129
1332
 
1130
1333
  export function validateAppInitialization(targetDir, versions) {
1131
- const current = assertProjectLifecycleCurrent(targetDir, versions);
1334
+ const effective = managedProjectVersions(targetDir, versions);
1335
+ const current = assertProjectLifecycleCurrent(targetDir, effective, { managed: true });
1132
1336
  for (const target of Object.keys(current.buildProfile.targets)) selectBuildOwner(current.buildProfile, target);
1133
1337
  }
1134
1338
 
1135
- function executeProjectPlan(targetDir, options, versions, runners, plan, scaffold) {
1339
+ function ownershipHandoverMessage(handover) {
1340
+ if (handover.file === 'missing') {
1341
+ return `${handover.path} now belongs to the App and is missing; add the App's own ${handover.path} before packaging.`;
1342
+ }
1343
+ const kept = `${handover.path} now belongs to the App; sync keeps it unchanged and will not rewrite it.`;
1344
+ return handover.earlierScaffoldContent
1345
+ ? `${kept} It still holds the text the earlier scaffold wrote: replace it with the App's own license and copyright holder.`
1346
+ : kept;
1347
+ }
1348
+
1349
+ function emitOwnershipHandovers(handovers, options) {
1350
+ if (options.json) return;
1351
+ for (const handover of handovers) process.stdout.write(`[nimi-app] ${ownershipHandoverMessage(handover)}\n`);
1352
+ }
1353
+
1354
+ function executeProjectPlan(targetDir, options, versions, runners, plan, scaffold, toolVersions = versions) {
1136
1355
  if (scaffold) validateManagedAppFiles(targetDir, scaffold.snapshot.lock, planSources(targetDir, plan.planned));
1137
1356
  validateProjectPlan(targetDir, versions, plan.planned, Boolean(scaffold));
1357
+ const handovers = scaffold?.handovers ?? [];
1138
1358
  const preview = {
1139
1359
  ok: true, command: options.adopt ? 'init' : 'sync', dir: targetDir,
1140
1360
  managed: Boolean(scaffold), appId: plan.descriptor.appId,
1141
1361
  dryRun: options.dryRun === true, skillPath: LIFECYCLE_SKILL_PATH,
1142
1362
  changes: describeChanges(targetDir, plan.planned), ownerSteps: lifecycleOwnerSteps(versions),
1143
- nextSteps: lifecycleNextSteps(plan.buildProfileRef, versions),
1363
+ nextSteps: lifecycleNextSteps(plan.buildProfileRef, plan.combination),
1364
+ dependencyCombination: describeCombination(plan.combination, toolVersions),
1365
+ ...(scaffold ? { ownershipHandover: handovers } : {}),
1144
1366
  };
1145
- if (options.dryRun) return emitResult(preview, options, `${preview.command} preview: ${preview.changes.map((file) => `${file.action} ${file.path}`).join(', ') || 'no app-tools changes'}`);
1367
+ if (options.dryRun) {
1368
+ emitOwnershipHandovers(handovers, options);
1369
+ return emitResult(preview, options, `${preview.command} preview: ${preview.changes.map((file) => `${file.action} ${file.path}`).join(', ') || 'no app-tools changes'}`);
1370
+ }
1146
1371
  const nimicoding = runNimicodingSync(targetDir, 'apply', runners);
1147
1372
  const lockPath = path.join(targetDir, SCAFFOLD_LOCK_PATH);
1148
1373
  const lockFile = plan.planned.find((file) => file.path === lockPath);
@@ -1150,12 +1375,13 @@ function executeProjectPlan(targetDir, options, versions, runners, plan, scaffol
1150
1375
  ...plan.planned.filter((file) => file !== lockFile),
1151
1376
  ...planLifecycleGuidance(targetDir),
1152
1377
  ]);
1153
- assertProjectLifecycleCurrent(targetDir, versions);
1378
+ assertProjectLifecycleCurrent(targetDir, versions, { managed: Boolean(scaffold) });
1154
1379
  if (scaffold) {
1155
1380
  validateManagedAppFiles(targetDir, scaffold.snapshot.lock);
1156
1381
  synchronizedFiles.push(...applyProjectFiles(targetDir, [lockFile]));
1157
1382
  }
1158
1383
  validateAppProject(targetDir, { silent: true }, versions, runners);
1384
+ emitOwnershipHandovers(handovers, options);
1159
1385
  return emitResult({ ...preview, synchronizedFiles, nimicodingSync: nimicoding?.summary || null }, options, `${preview.command} completed for ${targetDir}`);
1160
1386
  }
1161
1387
 
@@ -1164,12 +1390,13 @@ export function syncAppProject(cwd, options = {}, versions, runners = {}) {
1164
1390
  const targetDir = resolveTargetDir(cwd, options);
1165
1391
  assertNoRetiredScaffoldState(targetDir);
1166
1392
  const guidance = planLifecycleGuidance(targetDir);
1167
- const scaffold = existsSync(path.join(targetDir, SCAFFOLD_LOCK_PATH))
1168
- ? planManagedAppSync(targetDir, {}, versions) : null;
1393
+ const managed = existsSync(path.join(targetDir, SCAFFOLD_LOCK_PATH));
1394
+ const effective = managed ? managedProjectVersions(targetDir, versions) : versions;
1395
+ const scaffold = managed ? planManagedAppSync(targetDir, {}, effective) : null;
1169
1396
  const base = scaffold?.planned || [];
1170
- const plan = buildExistingSubmittedAppSyncPlan(targetDir, versions, planSources(targetDir, base));
1397
+ const plan = buildExistingSubmittedAppSyncPlan(targetDir, effective, planSources(targetDir, base), managed);
1171
1398
  plan.planned = [...base, ...plan.planned, ...guidance];
1172
- return executeProjectPlan(targetDir, options, versions, runners, plan, scaffold);
1399
+ return executeProjectPlan(targetDir, options, effective, runners, plan, scaffold, versions);
1173
1400
  }
1174
1401
 
1175
1402
  function adoptionSources(targetDir, options) {
@@ -1230,19 +1457,21 @@ export function adoptAppProject(cwd, options = {}, versions, runners = {}) {
1230
1457
 
1231
1458
  export function checkAppProject(cwd, options = {}, versions, runners = {}) {
1232
1459
  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
1460
  assertNoRetiredScaffoldState(targetDir);
1237
1461
  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);
1462
+ const effective = managed ? managedProjectVersions(targetDir, versions) : versions;
1463
+ const existingState = managed ? null : assertProjectLifecycleCurrent(targetDir, effective, { requireInstalledLock: true, production: options.production === true, managed });
1464
+ const validation = validateAppProject(cwd, { dir: targetDir, silent: true }, effective, runners);
1240
1465
  let nimicoding = null;
1241
1466
  if (!managed) nimicoding = runNimicodingSync(targetDir, 'check', runners);
1242
- const { descriptor, buildProfile } = existingState || assertProjectLifecycleCurrent(targetDir, versions, { requireInstalledLock: true });
1467
+ const { descriptor, buildProfile, combination } = existingState || assertProjectLifecycleCurrent(targetDir, effective, { requireInstalledLock: true, production: options.production === true, managed });
1243
1468
  if (options.production === true) {
1244
1469
  for (const target of Object.keys(buildProfile.targets)) readAppInfo(targetDir, target);
1245
1470
  }
1471
+ const safetyProfile = descriptor.safetyProfile ? 'declared' : 'undeclared';
1472
+ if (options.production === true && !options.json && safetyProfile === 'undeclared') {
1473
+ 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');
1474
+ }
1246
1475
  return emitResult({
1247
1476
  ok: true,
1248
1477
  command: 'check',
@@ -1251,6 +1480,8 @@ export function checkAppProject(cwd, options = {}, versions, runners = {}) {
1251
1480
  managed,
1252
1481
  appId: descriptor.appId,
1253
1482
  profile: descriptor.profile,
1483
+ safetyProfile,
1484
+ dependencyCombination: describeCombination(combination, versions),
1254
1485
  targets: Object.keys(buildProfile.targets).sort(),
1255
1486
  checkedManagedFiles: validation.checkedManagedFiles,
1256
1487
  checkedExistingFiles: validation.checkedExistingFiles,