@nimiplatform/app-tools 0.14.0 → 0.16.0-rc.12
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 +112 -24
- package/bin/nimi-app.mjs +35 -15
- package/lib/app-access-declaration.mjs +3 -0
- package/lib/app-dependency-combinations.mjs +70 -24
- package/lib/app-doctor-update.mjs +97 -39
- package/lib/app-host-support.mjs +6 -0
- package/lib/app-identifiers.mjs +27 -0
- package/lib/app-info.mjs +292 -1
- package/lib/app-lifecycle-guidance.mjs +1 -1
- package/lib/app-pack.mjs +65 -39
- package/lib/app-project-lifecycle.mjs +149 -244
- package/lib/app-scaffold-capabilities.mjs +13 -109
- package/lib/app-scaffold-profiles.mjs +81 -115
- package/lib/app-scaffold.mjs +74 -166
- package/lib/app-toolchain-updates.mjs +45 -0
- package/lib/canonical-capability-ids.generated.mjs +2 -0
- package/lib/development-environment.d.mts +10 -0
- package/lib/development-environment.mjs +39 -0
- package/lib/hosted-web-release.mjs +98 -0
- package/lib/index.mjs +43 -3
- package/lib/mobile-development.mjs +19 -0
- package/lib/realm-environments.generated.mjs +5 -0
- package/lib/storefront-media.mjs +154 -0
- package/lib/web-coordination.mjs +59 -0
- package/lib/web-development.d.mts +23 -0
- package/lib/web-development.mjs +118 -0
- package/lib/web-scaffold.mjs +125 -0
- package/package.json +33 -21
- package/scripts/dev-shell.mjs +4 -1
- package/scripts/sync-scaffold-versions.mjs +0 -2
- package/skills/nimi-app-lifecycle/SKILL.md +3 -1
- package/skills/nimi-app-lifecycle/references/acceptance.md +6 -2
- package/skills/nimi-app-lifecycle/references/adapt.md +5 -3
- package/skills/nimi-app-lifecycle/references/audit.md +3 -2
- package/skills/nimi-app-lifecycle/references/create.md +6 -2
- package/skills/nimi-app-lifecycle/references/release.md +10 -0
- package/skills/nimi-app-lifecycle/references/upgrade-platform.md +12 -7
- package/templates/app-source/src/ai-studio-core/ai-studio-core.css +87 -52
- package/templates/app-source/src/ai-studio-core/history-policy.ts +45 -11
- package/templates/app-source/src/ai-studio-core/history.ts +22 -11
- package/templates/app-source/src/ai-studio-core/host-context.tsx +9 -4
- package/templates/app-source/src/ai-studio-core/index.ts +2 -0
- package/templates/app-source/src/ai-studio-core/job-recovery-panel.tsx +15 -5
- package/templates/app-source/src/ai-studio-core/job-recovery.ts +2 -2
- package/templates/app-source/src/ai-studio-core/messages/en.json +73 -19
- package/templates/app-source/src/ai-studio-core/messages/zh.json +73 -19
- package/templates/app-source/src/ai-studio-core/module-registration.ts +1 -0
- package/templates/app-source/src/ai-studio-core/non-success-presentation.ts +30 -5
- package/templates/app-source/src/ai-studio-core/parameter-fields.tsx +12 -6
- package/templates/app-source/src/ai-studio-core/parameters.ts +4 -0
- package/templates/app-source/src/ai-studio-core/prompt-drafts.ts +42 -0
- package/templates/app-source/src/ai-studio-core/runtime-types.ts +9 -2
- package/templates/app-source/src/ai-studio-core/runtime.ts +8 -4
- package/templates/app-source/src/ai-studio-core/section-ai-testing-composer.tsx +98 -90
- package/templates/app-source/src/ai-studio-core/section-ai-testing-exchange-result.tsx +1 -1
- package/templates/app-source/src/ai-studio-core/section-ai-testing-history.tsx +205 -48
- package/templates/app-source/src/ai-studio-core/section-ai-testing-input.ts +1 -0
- package/templates/app-source/src/ai-studio-core/section-ai-testing-output.tsx +36 -14
- package/templates/app-source/src/ai-studio-core/section-ai-testing-result.tsx +96 -75
- package/templates/app-source/src/ai-studio-core/section-ai-testing-run.ts +59 -16
- package/templates/app-source/src/ai-studio-core/section-ai-testing-session-result.tsx +2 -0
- package/templates/app-source/src/ai-studio-core/section-ai-testing-studio-result.tsx +12 -21
- package/templates/app-source/src/ai-studio-core/section-ai-testing-transcription-result.tsx +2 -2
- package/templates/app-source/src/ai-studio-core/section-ai-testing-vision-result.tsx +3 -3
- package/templates/app-source/src/ai-studio-core/section-ai-testing.tsx +158 -76
- package/templates/app-source/src/ai-studio-core/workspace.tsx +49 -22
- package/templates/app-source/src/product-modules/agent-center/index.tsx +2 -3
- package/templates/app-source/src/product-modules/agent-conversation/index.tsx +2 -3
- package/templates/app-source/src/studio-modules/studio-create/messages/en.json +12 -3
- package/templates/app-source/src/studio-modules/studio-create/messages/zh.json +12 -3
- package/templates/app-source/src/studio-modules/studio-create/parameter-panel.tsx +11 -2
- package/templates/app-source/src/studio-modules/studio-create/parameters.ts +2 -1
- package/templates/app-source/src/studio-modules/studio-create/runtime.ts +47 -5
- package/templates/app-source/src/studio-modules/studio-media/messages/en.json +59 -8
- package/templates/app-source/src/studio-modules/studio-media/messages/zh.json +68 -8
- package/templates/app-source/src/studio-modules/studio-media/music-parameters.tsx +2 -1
- package/templates/app-source/src/studio-modules/studio-media/parameter-panel.tsx +271 -83
- package/templates/app-source/src/studio-modules/studio-media/parameters.ts +120 -2
- package/templates/app-source/src/studio-modules/studio-media/registration.ts +1 -0
- package/templates/app-source/src/studio-modules/studio-media/runtime.ts +24 -14
- package/templates/app-source/src/studio-modules/studio-voice/descriptors.ts +1 -1
- package/templates/app-source/src/studio-modules/studio-voice/messages/en.json +3 -2
- package/templates/app-source/src/studio-modules/studio-voice/messages/zh.json +3 -2
- package/templates/app-source/src/studio-modules/studio-voice/parameter-panel.tsx +46 -23
- package/templates/app-source/src/studio-modules/studio-voice/registration.ts +2 -1
- package/templates/app-source/src/studio-modules/studio-voice/runtime.ts +2 -2
- package/templates/app-source/src/workbench-core/workbench-core.tsx +27 -3
- package/templates/default-starter/AGENTS.md +3 -3
- package/templates/default-starter/README.md +1 -1
- package/templates/default-starter/src/shell/App.tsx +6 -18
- package/templates/default-starter/src/shell/auth/local-app-client.ts +6 -15
- package/templates/default-starter/src/shell/auth/runtime-platform.ts +7 -107
- package/templates/default-starter/src/shell/workbench-target-adapter.ts +9 -126
- package/templates/default-starter.manifest.json +0 -16
- package/templates/hosted-web-release.yml +98 -0
- package/templates/default-starter/src-tauri/Cargo.toml +0 -17
- package/templates/default-starter/src-tauri/build.rs +0 -32
- package/templates/default-starter/src-tauri/capabilities/default.json +0 -7
- package/templates/default-starter/src-tauri/tauri.conf.json +0 -26
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
import { isAppId } from './app-identifiers.mjs';
|
|
2
|
+
import { readWebDevelopment } from './web-development.mjs';
|
|
3
|
+
import { readMobileDevelopment } from './mobile-development.mjs';
|
|
1
4
|
import { APP_AUTHOR_DECLARATION_FIELDS, hashScaffoldManagedContent } from './app-scaffold.mjs';
|
|
2
|
-
import { readAppIntroduction } from './app-info.mjs';
|
|
5
|
+
import { readAppIntroduction, readAppStorefront } from './app-info.mjs';
|
|
3
6
|
import { existsSync, readdirSync, readFileSync, realpathSync, statSync } from 'node:fs';
|
|
4
7
|
import path from 'node:path';
|
|
8
|
+
import { minVersion } from 'semver';
|
|
5
9
|
import { parse as parseYaml, stringify as stringifyYaml } from 'yaml';
|
|
6
10
|
import {
|
|
7
11
|
buildAppScaffoldSnapshotFromIntent,
|
|
@@ -16,8 +20,8 @@ import {
|
|
|
16
20
|
} from './app-scaffold.mjs';
|
|
17
21
|
import { assertManifestAppAccessDeclaration } from './app-access-declaration.mjs';
|
|
18
22
|
import { assertLifecycleGuidanceCurrent, LIFECYCLE_SKILL_PATH, lifecycleOwnerSteps, planLifecycleGuidance } from './app-lifecycle-guidance.mjs';
|
|
19
|
-
import { applyProjectFiles, describeChanges, plannedFile } from './app-project-files.mjs';
|
|
20
|
-
import { resolveDependencyCombination } from './app-dependency-combinations.mjs';
|
|
23
|
+
import { applyProjectFiles, assertProjectOutputPath, describeChanges, plannedFile } from './app-project-files.mjs';
|
|
24
|
+
import { appToolsDeclaration, matchesRecordedHostDependencies, resolveDependencyCombination } from './app-dependency-combinations.mjs';
|
|
21
25
|
|
|
22
26
|
const SCAN_EXCLUDED_DIRS = new Set([
|
|
23
27
|
'.git',
|
|
@@ -207,9 +211,39 @@ function expectedSnapshotFromLock(lock, versions, intent, targetDir, options = {
|
|
|
207
211
|
if (stableStringify(intent.directFeatures) !== stableStringify(lock.directFeatures)) {
|
|
208
212
|
throw new Error('Scaffold feature selection is immutable; create a fresh scaffold for a different feature closure');
|
|
209
213
|
}
|
|
214
|
+
if (versions.source === 'existing') retainMatchingHostFiles(targetDir, lock, snapshot, versions);
|
|
210
215
|
return snapshot;
|
|
211
216
|
}
|
|
212
217
|
|
|
218
|
+
// A maintained SDK/Kit pair can predate APIs imported by today's generated
|
|
219
|
+
// renderer and Host. Its checked-in wiring also binds the App-owned feature
|
|
220
|
+
// modules. Carry it forward only with the original paths, class and digest.
|
|
221
|
+
function retainMatchingHostFiles(targetDir, lock, snapshot, versions) {
|
|
222
|
+
const matrix = lock.dependencyMatrix;
|
|
223
|
+
const migration = 'Migrate the App-owned feature modules and matching Host with the selected SDK/Kit before sync.';
|
|
224
|
+
if (!matchesRecordedHostDependencies(matrix.npm, versions)) {
|
|
225
|
+
throw new Error(migration);
|
|
226
|
+
}
|
|
227
|
+
assertSameJson(lock.hostAdapterContracts, snapshot.lock.hostAdapterContracts, 'Scaffold host adapter contracts');
|
|
228
|
+
snapshot.retainedHostFiles = [];
|
|
229
|
+
snapshot.filesWithoutLock = snapshot.filesWithoutLock.map(file => {
|
|
230
|
+
const expected = snapshot.lock.managedFileHashes[file.path];
|
|
231
|
+
if (!expected || !/^(?:src\/|src-electron\/|vite\.config\.ts$)/u.test(file.path)) return file;
|
|
232
|
+
const recorded = lock.managedFileHashes?.[file.path];
|
|
233
|
+
if (!recorded || recorded.class !== expected.class) throw new Error(`${file.path}: ${migration}`);
|
|
234
|
+
const absolute = path.join(targetDir, file.path);
|
|
235
|
+
assertProjectOutputPath(targetDir, absolute);
|
|
236
|
+
const content = existsSync(absolute) ? readFileSync(absolute) : null;
|
|
237
|
+
if (!content || hashScaffoldManagedContent(file.path, content) !== recorded.sha256) {
|
|
238
|
+
throw new Error(`Managed scaffold drift detected: ${file.path}. Restore its locked source before sync.`);
|
|
239
|
+
}
|
|
240
|
+
if (recorded.sha256 === expected.sha256) return file;
|
|
241
|
+
snapshot.lock.managedFileHashes[file.path] = { ...expected, sha256: recorded.sha256 };
|
|
242
|
+
snapshot.retainedHostFiles.push(file.path);
|
|
243
|
+
return { ...file, content };
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
|
|
213
247
|
function readContentForHash(filePath) {
|
|
214
248
|
return readFileSync(filePath);
|
|
215
249
|
}
|
|
@@ -443,26 +477,6 @@ function assertRequiredSupportFiles(targetDir, snapshot) {
|
|
|
443
477
|
if (missing.length > 0) {
|
|
444
478
|
throw new Error(`Missing required scaffold support files: ${missing.join(', ')}`);
|
|
445
479
|
}
|
|
446
|
-
|
|
447
|
-
const tauriConfig = JSON.parse(readFileSync(path.join(targetDir, 'src-tauri/tauri.conf.json'), 'utf8'));
|
|
448
|
-
const icons = tauriConfig?.bundle?.icon;
|
|
449
|
-
if (!Array.isArray(icons) || icons.join(',') !== 'icons/icon.png,icons/icon.ico') {
|
|
450
|
-
throw new Error('Tauri icon support drift: bundle.icon must be ["icons/icon.png","icons/icon.ico"]');
|
|
451
|
-
}
|
|
452
|
-
const icon = readFileSync(path.join(targetDir, 'src-tauri/icons/icon.png'));
|
|
453
|
-
const pngSignature = [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a];
|
|
454
|
-
if (icon.length !== 68 || pngSignature.some((value, index) => icon[index] !== value)) {
|
|
455
|
-
throw new Error('Tauri icon support drift: src-tauri/icons/icon.png is not the scaffold PNG');
|
|
456
|
-
}
|
|
457
|
-
const ico = readFileSync(path.join(targetDir, 'src-tauri/icons/icon.ico'));
|
|
458
|
-
const icoHeader = [0x00, 0x00, 0x01, 0x00, 0x01, 0x00];
|
|
459
|
-
if (
|
|
460
|
-
ico.length !== 90
|
|
461
|
-
|| icoHeader.some((value, index) => ico[index] !== value)
|
|
462
|
-
|| pngSignature.some((value, index) => ico[index + 22] !== value)
|
|
463
|
-
) {
|
|
464
|
-
throw new Error('Tauri icon support drift: src-tauri/icons/icon.ico is not the scaffold ICO');
|
|
465
|
-
}
|
|
466
480
|
}
|
|
467
481
|
|
|
468
482
|
function usesAppOwnedRenderer(targetDir, plannedSources) {
|
|
@@ -485,10 +499,9 @@ function assertProjectConfiguration(targetDir, parsedManifest = null, managed =
|
|
|
485
499
|
throw new Error(`Submitted manifest YAML cannot be parsed: ${error instanceof Error ? error.message : String(error)}`);
|
|
486
500
|
}
|
|
487
501
|
}
|
|
488
|
-
const rendererOrigin = assertElectronLocalDevelopmentManifest(document);
|
|
489
502
|
readAppIntroduction(targetDir, document);
|
|
490
|
-
|
|
491
|
-
|
|
503
|
+
readAppStorefront(targetDir, document);
|
|
504
|
+
assertCarrierDevelopmentInputs(targetDir, document, readJsonFile(path.join(targetDir, 'package.json')), managed);
|
|
492
505
|
}
|
|
493
506
|
|
|
494
507
|
function assertElectronLocalDevelopmentManifest(document) {
|
|
@@ -591,12 +604,28 @@ function assertNimicodingProjectionCurrent(targetDir, runners) {
|
|
|
591
604
|
}
|
|
592
605
|
}
|
|
593
606
|
|
|
607
|
+
function assertCarrierDevelopmentInputs(targetDir, manifest, packageJson, managed, plannedSources) {
|
|
608
|
+
if (manifest.local_development && Object.hasOwn(manifest.local_development, 'mobile')) readMobileDevelopment(manifest, packageJson);
|
|
609
|
+
if (manifest.platform === 'web' || (manifest.local_development && Object.hasOwn(manifest.local_development, 'web'))) {
|
|
610
|
+
const declaration = manifest.local_development.web;
|
|
611
|
+
const script = /^pnpm run ([A-Za-z0-9][A-Za-z0-9:_.-]*)$/u.exec(declaration?.command || '')?.[1];
|
|
612
|
+
if (!script || !packageJson.scripts?.[script] || /\bnimi-app\s+dev\b/u.test(packageJson.scripts[script])) throw new Error('Web dev requires a non-recursive App-owned renderer script.');
|
|
613
|
+
if (manifest.platform === 'web' || declaration.origin || declaration.redirect_uri || declaration.client_id) readWebDevelopment(manifest);
|
|
614
|
+
if (declaration.local) readWebDevelopment(manifest, { realm: 'local' });
|
|
615
|
+
}
|
|
616
|
+
if (manifest.platform !== 'web') {
|
|
617
|
+
if (manifest.platform !== undefined && manifest.platform !== 'desktop') throw new Error('Unsupported App platform.');
|
|
618
|
+
const rendererOrigin = assertElectronLocalDevelopmentManifest(manifest);
|
|
619
|
+
assertDeclaredHostSourceDirectory(targetDir, manifest);
|
|
620
|
+
assertOfficialDevelopmentEntrypoints(targetDir, rendererOrigin, packageJson, managed || !usesAppOwnedRenderer(targetDir, plannedSources));
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
|
|
594
624
|
export function validateAppProjectInputs(targetDir, manifest, packageJson, managed = false, plannedSources) {
|
|
595
625
|
assertManifestAppAccessDeclaration(stringifyYaml(manifest), 'nimi.app.yaml');
|
|
596
626
|
readAppIntroduction(targetDir, manifest);
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
assertOfficialDevelopmentEntrypoints(targetDir, rendererOrigin, packageJson, managed || !usesAppOwnedRenderer(targetDir, plannedSources));
|
|
627
|
+
readAppStorefront(targetDir, manifest);
|
|
628
|
+
assertCarrierDevelopmentInputs(targetDir, manifest, packageJson, managed, plannedSources);
|
|
600
629
|
const findings = scanForbiddenPatterns(targetDir, manifest.profile, managed ? null : LOCAL_DEVELOPMENT_BYPASS_LABELS, plannedSources);
|
|
601
630
|
if (findings.length) throw new Error(`Forbidden App source patterns: ${findings.join('; ')}`);
|
|
602
631
|
}
|
|
@@ -669,7 +698,7 @@ function validateExistingSubmittedApp(targetDir) {
|
|
|
669
698
|
}
|
|
670
699
|
const appId = typeof parsed?.app_id === 'string' ? parsed.app_id.trim() : '';
|
|
671
700
|
const profile = typeof parsed?.profile === 'string' ? parsed.profile.trim() : '';
|
|
672
|
-
if (!appId || appId !== parsed?.app_id || !SUPPORTED_APP_SCAFFOLD_PROFILES.includes(profile)) {
|
|
701
|
+
if (!isAppId(appId) || appId !== parsed?.app_id || !SUPPORTED_APP_SCAFFOLD_PROFILES.includes(profile)) {
|
|
673
702
|
throw new Error('Existing submitted app requires canonical app_id and supported profile');
|
|
674
703
|
}
|
|
675
704
|
if (parsed?.manifest_role !== 'submitted-input') {
|
|
@@ -689,7 +718,7 @@ function validateExistingSubmittedApp(targetDir) {
|
|
|
689
718
|
};
|
|
690
719
|
}
|
|
691
720
|
|
|
692
|
-
export function initApp(cwd, options = {}, versions, runners = {}) {
|
|
721
|
+
export function initApp(cwd, options = {}, versions, runners = {}, workflows = []) {
|
|
693
722
|
const targetDir = resolveTargetDir(cwd, options);
|
|
694
723
|
const intent = readIntent(targetDir);
|
|
695
724
|
const currentManifest = readCurrentAppManifest(targetDir);
|
|
@@ -697,23 +726,44 @@ export function initApp(cwd, options = {}, versions, runners = {}) {
|
|
|
697
726
|
// Create still uses the tool default. An explicit listed selection before
|
|
698
727
|
// first init refreshes derived glue through this owner, just as sync does.
|
|
699
728
|
// Check the original generated files before projecting the selected pair.
|
|
700
|
-
const
|
|
701
|
-
const
|
|
702
|
-
const
|
|
729
|
+
const pkg = readJsonFile(path.join(targetDir, 'package.json'));
|
|
730
|
+
const creatorSpec = intent?.dependencyMatrix?.npm?.['@nimiplatform/app-tools'];
|
|
731
|
+
const compatiblePatch = typeof creatorSpec === 'string' && creatorSpec !== versions.appToolsVersion
|
|
732
|
+
&& appToolsDeclaration(creatorSpec, versions.appToolsVersion) === creatorSpec;
|
|
733
|
+
const creatorVersions = compatiblePatch
|
|
734
|
+
? { ...versions, ...resolveDependencyCombination({ dependencies: intent.dependencyMatrix.npm }, versions) }
|
|
735
|
+
: versions;
|
|
736
|
+
const original = buildAppScaffoldSnapshotFromIntent({ intent, versions: creatorVersions, targetDir, refreshInitialDependencies: compatiblePatch });
|
|
737
|
+
const combination = resolveDependencyCombination(pkg, versions);
|
|
738
|
+
const appToolsVersion = appToolsDeclaration(pkg.devDependencies?.['@nimiplatform/app-tools'], versions.appToolsVersion);
|
|
739
|
+
const effective = { ...versions, ...combination, appToolsVersion };
|
|
703
740
|
const snapshot = buildAppScaffoldSnapshotFromIntent({ intent, versions: effective, targetDir, refreshDerived: true });
|
|
741
|
+
if (combination.source === 'existing'
|
|
742
|
+
&& !matchesRecordedHostDependencies(intent.dependencyMatrix.npm, combination)) {
|
|
743
|
+
throw new Error('The selected SDK/Kit requires a different Host. Initialize with the creator combination or migrate the Host and App-owned feature modules together.');
|
|
744
|
+
}
|
|
704
745
|
validateAppProjectInputs(targetDir, currentManifest, readJsonFile(path.join(targetDir, 'package.json')), true);
|
|
705
746
|
const initializedPaths = new Set(snapshot.initFiles.map((file) => file.path));
|
|
706
|
-
|
|
747
|
+
const initialFiles = Object.entries(original.lock.managedFileHashes).filter(([relativePath]) =>
|
|
748
|
+
!initializedPaths.has(relativePath) && !(compatiblePatch && relativePath === SCAFFOLD_INTENT_PATH));
|
|
749
|
+
try {
|
|
750
|
+
assertManagedFilesCurrent(targetDir, { managedFileHashes: Object.fromEntries(initialFiles) });
|
|
751
|
+
} catch (cause) {
|
|
752
|
+
if (!compatiblePatch) throw cause;
|
|
753
|
+
throw new Error(`${cause.message}. Review the listed files. For an untouched scaffold from a different generator, run nimi-app init with its exact creator ${minVersion(creatorSpec).version} (published package or original tarball), then sync with the selected tool.`, { cause });
|
|
754
|
+
}
|
|
707
755
|
const managedFiles = snapshot.filesWithoutLock.filter((file) => snapshot.lock.managedFileHashes[file.path]);
|
|
708
756
|
const planned = [...managedFiles.map((file) => {
|
|
709
757
|
let content = file.content;
|
|
710
758
|
if (file.path === 'nimi.app.yaml' && currentManifest) {
|
|
711
759
|
const next = parseYaml(content);
|
|
712
760
|
for (const field of APP_AUTHOR_DECLARATION_FIELDS) if (Object.hasOwn(currentManifest, field)) next[field] = currentManifest[field];
|
|
761
|
+
if (currentManifest.local_development?.web) next.local_development = { ...next.local_development, web: currentManifest.local_development.web };
|
|
762
|
+
if (currentManifest.local_development?.mobile) next.local_development = { ...next.local_development, mobile: currentManifest.local_development.mobile };
|
|
713
763
|
content = stringifyYaml(next, { lineWidth: 0 });
|
|
714
764
|
}
|
|
715
765
|
return plannedFile(targetDir, file.path, content);
|
|
716
|
-
}), ...planLifecycleGuidance(targetDir), ...snapshot.initFiles.map((file) => plannedFile(targetDir, file.path, file.content))];
|
|
766
|
+
}), ...workflows, ...planLifecycleGuidance(targetDir), ...snapshot.initFiles.map((file) => plannedFile(targetDir, file.path, file.content))];
|
|
717
767
|
const preview = {
|
|
718
768
|
ok: true, command: 'init', dir: targetDir, dryRun: options.dryRun === true,
|
|
719
769
|
skillPath: LIFECYCLE_SKILL_PATH, changes: describeChanges(targetDir, planned), ownerSteps: lifecycleOwnerSteps(versions),
|
|
@@ -794,7 +844,13 @@ function collectExpectedClasses(snapshot) {
|
|
|
794
844
|
// A lock written by an earlier scaffold version can still list a file that the
|
|
795
845
|
// current generator creates once for the App to own. Only the declared paths
|
|
796
846
|
// may change owner, and only from managed glue to App-owned product code.
|
|
847
|
+
const RETIRED_TAURI_GLUE = new Set([
|
|
848
|
+
'src-tauri/Cargo.toml', 'src-tauri/build.rs', 'src-tauri/capabilities/default.json',
|
|
849
|
+
'src-tauri/tauri.conf.json', 'src-tauri/src/main.rs', 'src-tauri/icons/icon.png', 'src-tauri/icons/icon.ico',
|
|
850
|
+
]);
|
|
851
|
+
|
|
797
852
|
function isAppOwnedHandover(relativePath, lockedEntry, current) {
|
|
853
|
+
if (!current && RETIRED_TAURI_GLUE.has(relativePath)) return lockedEntry?.class === 'scaffold-managed glue';
|
|
798
854
|
return SCAFFOLD_APP_OWNED_HANDOVER_PATHS.includes(relativePath)
|
|
799
855
|
&& lockedEntry?.class === 'scaffold-managed glue'
|
|
800
856
|
&& current?.owner === 'app-owned'
|
|
@@ -835,14 +891,14 @@ function assertNoClassificationConflict(lock, snapshot, targetDir) {
|
|
|
835
891
|
handovers.push(describeAppOwnedHandover(targetDir, relativePath, entry));
|
|
836
892
|
continue;
|
|
837
893
|
}
|
|
838
|
-
throw new Error(`Scaffold classification conflict: ${relativePath}
|
|
894
|
+
throw new Error(`Scaffold classification conflict: ${relativePath}. Review its ownership and restore the matching scaffold lock before sync.`);
|
|
839
895
|
}
|
|
840
896
|
for (const [relativePath, entry] of Object.entries(lock.appOwnedInitialHashes || {})) {
|
|
841
897
|
const current = currentClasses.get(relativePath);
|
|
842
898
|
if (current?.owner === 'app-owned' && current.class === entry.class) {
|
|
843
899
|
continue;
|
|
844
900
|
}
|
|
845
|
-
throw new Error(`Scaffold classification conflict: ${relativePath}
|
|
901
|
+
throw new Error(`Scaffold classification conflict: ${relativePath}. Review its ownership and restore the matching scaffold lock before sync.`);
|
|
846
902
|
}
|
|
847
903
|
return handovers;
|
|
848
904
|
}
|
|
@@ -882,10 +938,12 @@ export function planManagedAppSync(cwd, options = {}, versions) {
|
|
|
882
938
|
if (file.path === 'nimi.app.yaml' && currentManifest) {
|
|
883
939
|
const next = parseYaml(content);
|
|
884
940
|
for (const field of APP_AUTHOR_DECLARATION_FIELDS) if (Object.hasOwn(currentManifest, field)) next[field] = currentManifest[field];
|
|
941
|
+
if (currentManifest.local_development?.web) next.local_development = { ...next.local_development, web: currentManifest.local_development.web };
|
|
942
|
+
if (currentManifest.local_development?.mobile) next.local_development = { ...next.local_development, mobile: currentManifest.local_development.mobile };
|
|
885
943
|
content = stringifyYaml(next, { lineWidth: 0 });
|
|
886
944
|
}
|
|
887
945
|
return plannedFile(targetDir, file.path, content);
|
|
888
946
|
});
|
|
889
947
|
planned.push(...planLifecycleGuidance(targetDir), plannedFile(targetDir, SCAFFOLD_LOCK_PATH, `${JSON.stringify(snapshot.lock, null, 2)}\n`));
|
|
890
|
-
return { targetDir, snapshot, planned, handovers };
|
|
948
|
+
return { targetDir, snapshot, planned, handovers, previousDependencies: lock.dependencyMatrix.npm };
|
|
891
949
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// @nimi-authority: rule.nimi.platform.app-ecosystem.p-scaf-002a
|
|
2
|
+
export function assertDesktopHostSupport(profileRef) {
|
|
3
|
+
if (profileRef === 'tauri-pnpm-vite') {
|
|
4
|
+
throw new Error('tauri-pnpm-vite is unsupported in this release. Use the original Tauri toolchain or explicitly migrate the App to Electron.');
|
|
5
|
+
}
|
|
6
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
|
|
3
|
+
const segment = '[a-z0-9](?:[a-z0-9-]*[a-z0-9])?';
|
|
4
|
+
const productId = new RegExp('^' + segment + '(?:\\.' + segment + ')+$');
|
|
5
|
+
const clientId = /^[a-z][a-z0-9]*(?:[._-][a-z0-9]+)+$/u;
|
|
6
|
+
const publicSlug = new RegExp('^' + segment + '$');
|
|
7
|
+
|
|
8
|
+
export function isAppId(value) {
|
|
9
|
+
return typeof value === 'string' && value.length >= 3 && value.length <= 120 && productId.test(value);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function isClientId(value) {
|
|
13
|
+
return typeof value === 'string' && value.length >= 3 && value.length <= 120 && clientId.test(value);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function hostedWebIdentity(appId, slug, registeredClient) {
|
|
17
|
+
if (!isAppId(appId)) throw new Error('Invalid hosted Web product ID.');
|
|
18
|
+
if (typeof slug !== 'string' || slug.length > 63 || !publicSlug.test(slug))
|
|
19
|
+
throw new Error('Invalid hosted Web slug.');
|
|
20
|
+
const preferred = appId + '.web';
|
|
21
|
+
const id =
|
|
22
|
+
registeredClient ??
|
|
23
|
+
(isClientId(preferred) ? preferred : 'web.' + createHash('sha256').update(appId).digest('hex'));
|
|
24
|
+
if (!isClientId(id)) throw new Error('Invalid hosted Web client ID.');
|
|
25
|
+
const origin = 'https://' + slug + '.nimi.xyz';
|
|
26
|
+
return { appId, slug, clientId: id, origin, redirectUri: origin + '/' };
|
|
27
|
+
}
|
package/lib/app-info.mjs
CHANGED
|
@@ -9,13 +9,24 @@ import { parse as parseYaml } from 'yaml';
|
|
|
9
9
|
import { normalizeAppAccessItems } from './app-access-declaration.mjs';
|
|
10
10
|
import { CANONICAL_CAPABILITY_IDS } from './canonical-capability-ids.generated.mjs';
|
|
11
11
|
import { SAFETY_PROFILE_FIELD, normalizeSafetyProfile } from './app-safety-profile.mjs';
|
|
12
|
+
import {
|
|
13
|
+
STOREFRONT_CATEGORIES,
|
|
14
|
+
STOREFRONT_COVER_BOUNDS,
|
|
15
|
+
STOREFRONT_GALLERY_BOUNDS,
|
|
16
|
+
STOREFRONT_GALLERY_ID_PATTERN,
|
|
17
|
+
STOREFRONT_IMAGE_MAX_BYTES,
|
|
18
|
+
STOREFRONT_LOCALE_PATTERN,
|
|
19
|
+
STOREFRONT_SHA256_PATTERN,
|
|
20
|
+
inspectStaticStorefrontImage,
|
|
21
|
+
storefrontMediaExtension,
|
|
22
|
+
} from './storefront-media.mjs';
|
|
12
23
|
|
|
13
24
|
export const APP_INFO_MAX_BYTES = 1024 * 1024;
|
|
14
25
|
export const APP_INTRODUCTION_FILE = 'NIMI_APP.md';
|
|
15
26
|
export const APP_INFO_FIELDS = Object.freeze([
|
|
16
27
|
'format', 'app_id', 'version', 'target_id', 'display_name', 'summary', 'icon', 'readme_markdown', 'release_notes_markdown',
|
|
17
28
|
'license', 'app_access', 'capability_contract_refs', 'required_standardized_feature_refs', 'storage_policy', 'author',
|
|
18
|
-
'homepage_url', 'support_url', SAFETY_PROFILE_FIELD,
|
|
29
|
+
'homepage_url', 'support_url', SAFETY_PROFILE_FIELD, 'storefront',
|
|
19
30
|
]);
|
|
20
31
|
// Declaration fields that App Tools projects from nimi.app.yaml into the
|
|
21
32
|
// archive declaration and that Registry compares against the candidate.
|
|
@@ -102,10 +113,288 @@ export function validateAppInfo(info) {
|
|
|
102
113
|
https(info.homepage_url, 'homepage_url');
|
|
103
114
|
https(info.support_url, 'support_url');
|
|
104
115
|
safetyProfile(info[SAFETY_PROFILE_FIELD], 'App info');
|
|
116
|
+
if (info.storefront !== undefined) validateAppInfoStorefront(info.storefront);
|
|
105
117
|
if (Buffer.byteLength(JSON.stringify(info)) > APP_INFO_MAX_BYTES) throw new Error('App info exceeds 1 MiB');
|
|
106
118
|
return info;
|
|
107
119
|
}
|
|
108
120
|
|
|
121
|
+
function validLocale(value, label) {
|
|
122
|
+
if (typeof value !== 'string' || value.length > 16 || !STOREFRONT_LOCALE_PATTERN.test(value)) {
|
|
123
|
+
throw new Error(`${label} must be a valid locale tag (e.g. en, zh)`);
|
|
124
|
+
}
|
|
125
|
+
return value;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function validateImageRef(ref, bounds, label) {
|
|
129
|
+
if (!ref || typeof ref !== 'object' || Array.isArray(ref)) throw new Error(`${label} must be an image reference object`);
|
|
130
|
+
for (const key of Object.keys(ref)) {
|
|
131
|
+
if (!['media_type', 'width', 'height', 'size', 'sha256'].includes(key)) throw new Error(`${label} contains unsupported field: ${key}`);
|
|
132
|
+
}
|
|
133
|
+
if (!['image/webp', 'image/png'].includes(ref.media_type)) throw new Error(`${label} media_type must be image/webp or image/png`);
|
|
134
|
+
if (!Number.isInteger(ref.width) || !Number.isInteger(ref.height)
|
|
135
|
+
|| ref.width < bounds.minW || ref.width > bounds.maxW || ref.height < bounds.minH || ref.height > bounds.maxH) {
|
|
136
|
+
throw new Error(`${label} dimensions are outside allowed bounds`);
|
|
137
|
+
}
|
|
138
|
+
if (!Number.isInteger(ref.size) || ref.size <= 0 || ref.size > STOREFRONT_IMAGE_MAX_BYTES || !STOREFRONT_SHA256_PATTERN.test(ref.sha256)) {
|
|
139
|
+
throw new Error(`${label} size or sha256 is invalid`);
|
|
140
|
+
}
|
|
141
|
+
return ref;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export function validateAppInfoStorefront(storefront) {
|
|
145
|
+
if (!storefront || typeof storefront !== 'object' || Array.isArray(storefront)) throw new Error('App info storefront must be an object');
|
|
146
|
+
for (const key of Object.keys(storefront)) {
|
|
147
|
+
if (!['category', 'default_locale', 'locales', 'media'].includes(key)) throw new Error(`App info storefront contains unsupported field: ${key}`);
|
|
148
|
+
}
|
|
149
|
+
if (!STOREFRONT_CATEGORIES.includes(storefront.category)) throw new Error(`App info storefront category is unsupported: ${storefront.category}`);
|
|
150
|
+
const defaultLocale = validLocale(storefront.default_locale, 'storefront.default_locale');
|
|
151
|
+
if (storefront.locales !== undefined) {
|
|
152
|
+
if (!storefront.locales || typeof storefront.locales !== 'object' || Array.isArray(storefront.locales)) throw new Error('App info storefront.locales must be an object');
|
|
153
|
+
const entries = Object.entries(storefront.locales);
|
|
154
|
+
if (entries.length > 16) throw new Error('App info storefront.locales exceeds 16 locales');
|
|
155
|
+
for (const [locale, entry] of entries) {
|
|
156
|
+
validLocale(locale, 'storefront.locales key');
|
|
157
|
+
if (!entry || typeof entry !== 'object' || Array.isArray(entry)) throw new Error(`storefront.locales.${locale} must be an object`);
|
|
158
|
+
for (const key of Object.keys(entry)) {
|
|
159
|
+
if (!['display_name', 'summary', 'tags', 'highlights', 'introduction_markdown'].includes(key)) {
|
|
160
|
+
throw new Error(`storefront.locales.${locale} contains unsupported field: ${key}`);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
if (locale === defaultLocale) {
|
|
164
|
+
if (entry.display_name !== undefined || entry.summary !== undefined || entry.introduction_markdown !== undefined) {
|
|
165
|
+
throw new Error(`storefront.locales.${locale} must not duplicate top-level display_name, summary or NIMI_APP.md`);
|
|
166
|
+
}
|
|
167
|
+
} else {
|
|
168
|
+
if (entry.display_name !== undefined) text(entry.display_name, `storefront.locales.${locale}.display_name`, 120);
|
|
169
|
+
if (entry.summary !== undefined) text(entry.summary, `storefront.locales.${locale}.summary`, 280);
|
|
170
|
+
if (entry.introduction_markdown !== undefined) text(entry.introduction_markdown, `storefront.locales.${locale}.introduction_markdown`, 96 * 1024, true);
|
|
171
|
+
}
|
|
172
|
+
if (entry.tags !== undefined) {
|
|
173
|
+
if (!Array.isArray(entry.tags) || entry.tags.length > 5 || new Set(entry.tags).size !== entry.tags.length) {
|
|
174
|
+
throw new Error(`storefront.locales.${locale}.tags must contain at most 5 unique tags`);
|
|
175
|
+
}
|
|
176
|
+
for (const tag of entry.tags) text(tag, `storefront.locales.${locale}.tags`, 32);
|
|
177
|
+
}
|
|
178
|
+
if (entry.highlights !== undefined) {
|
|
179
|
+
if (!Array.isArray(entry.highlights) || entry.highlights.length > 4) {
|
|
180
|
+
throw new Error(`storefront.locales.${locale}.highlights must contain at most 4 items`);
|
|
181
|
+
}
|
|
182
|
+
for (const item of entry.highlights) {
|
|
183
|
+
if (!item || typeof item !== 'object' || Array.isArray(item)) throw new Error(`storefront.locales.${locale}.highlights item must be an object`);
|
|
184
|
+
for (const key of Object.keys(item)) {
|
|
185
|
+
if (!['title', 'description'].includes(key)) throw new Error(`storefront highlight contains unsupported field: ${key}`);
|
|
186
|
+
}
|
|
187
|
+
text(item.title, `storefront.locales.${locale}.highlights.title`, 60);
|
|
188
|
+
text(item.description, `storefront.locales.${locale}.highlights.description`, 200);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
if (storefront.media !== undefined) {
|
|
194
|
+
const media = storefront.media;
|
|
195
|
+
if (!media || typeof media !== 'object' || Array.isArray(media)) throw new Error('App info storefront.media must be an object');
|
|
196
|
+
for (const key of Object.keys(media)) {
|
|
197
|
+
if (!['cover', 'gallery'].includes(key)) throw new Error(`App info storefront.media contains unsupported field: ${key}`);
|
|
198
|
+
}
|
|
199
|
+
if (media.cover === undefined && (!Array.isArray(media.gallery) || media.gallery.length === 0)) {
|
|
200
|
+
throw new Error('App info storefront.media must declare cover or gallery');
|
|
201
|
+
}
|
|
202
|
+
if (media.cover !== undefined) {
|
|
203
|
+
if (!media.cover || typeof media.cover !== 'object' || Array.isArray(media.cover)) throw new Error('storefront.media.cover must be an object');
|
|
204
|
+
for (const key of Object.keys(media.cover)) {
|
|
205
|
+
if (!['default', 'locales'].includes(key)) throw new Error(`storefront.media.cover contains unsupported field: ${key}`);
|
|
206
|
+
}
|
|
207
|
+
validateImageRef(media.cover.default, STOREFRONT_COVER_BOUNDS, 'storefront.media.cover.default');
|
|
208
|
+
if (media.cover.locales !== undefined) {
|
|
209
|
+
if (!media.cover.locales || typeof media.cover.locales !== 'object' || Array.isArray(media.cover.locales)) {
|
|
210
|
+
throw new Error('storefront.media.cover.locales must be an object');
|
|
211
|
+
}
|
|
212
|
+
const entries = Object.entries(media.cover.locales);
|
|
213
|
+
if (entries.length > 15) throw new Error('storefront.media.cover.locales exceeds 15 locales');
|
|
214
|
+
for (const [locale, ref] of entries) {
|
|
215
|
+
validLocale(locale, 'storefront.media.cover.locales key');
|
|
216
|
+
if (locale === defaultLocale) throw new Error('storefront.media.cover.locales must not duplicate default_locale');
|
|
217
|
+
validateImageRef(ref, STOREFRONT_COVER_BOUNDS, `storefront.media.cover.locales.${locale}`);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
if (media.gallery !== undefined) {
|
|
222
|
+
if (!Array.isArray(media.gallery) || media.gallery.length > 6) throw new Error('storefront.media.gallery must contain at most 6 items');
|
|
223
|
+
const seenIds = new Set();
|
|
224
|
+
for (const item of media.gallery) {
|
|
225
|
+
if (!item || typeof item !== 'object' || Array.isArray(item)) throw new Error('storefront.media.gallery item must be an object');
|
|
226
|
+
for (const key of Object.keys(item)) {
|
|
227
|
+
if (!['id', 'kind', 'default', 'locales', 'caption'].includes(key)) throw new Error(`storefront gallery item contains unsupported field: ${key}`);
|
|
228
|
+
}
|
|
229
|
+
if (typeof item.id !== 'string' || !STOREFRONT_GALLERY_ID_PATTERN.test(item.id) || seenIds.has(item.id)) {
|
|
230
|
+
throw new Error(`storefront gallery id is invalid or duplicated: ${item.id}`);
|
|
231
|
+
}
|
|
232
|
+
seenIds.add(item.id);
|
|
233
|
+
if (item.kind !== 'image') throw new Error(`storefront gallery item ${item.id} kind must be image`);
|
|
234
|
+
validateImageRef(item.default, STOREFRONT_GALLERY_BOUNDS, `storefront.media.gallery.${item.id}.default`);
|
|
235
|
+
if (item.locales !== undefined) {
|
|
236
|
+
if (!item.locales || typeof item.locales !== 'object' || Array.isArray(item.locales)) {
|
|
237
|
+
throw new Error(`storefront.media.gallery.${item.id}.locales must be an object`);
|
|
238
|
+
}
|
|
239
|
+
const entries = Object.entries(item.locales);
|
|
240
|
+
if (entries.length > 15) throw new Error(`storefront.media.gallery.${item.id}.locales exceeds 15 locales`);
|
|
241
|
+
for (const [locale, ref] of entries) {
|
|
242
|
+
validLocale(locale, `storefront.media.gallery.${item.id}.locales key`);
|
|
243
|
+
if (locale === defaultLocale) throw new Error(`storefront.media.gallery.${item.id}.locales must not duplicate default_locale`);
|
|
244
|
+
validateImageRef(ref, STOREFRONT_GALLERY_BOUNDS, `storefront.media.gallery.${item.id}.locales.${locale}`);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
if (item.caption !== undefined) {
|
|
248
|
+
if (!item.caption || typeof item.caption !== 'object' || Array.isArray(item.caption)) {
|
|
249
|
+
throw new Error(`storefront.media.gallery.${item.id}.caption must be an object`);
|
|
250
|
+
}
|
|
251
|
+
const entries = Object.entries(item.caption);
|
|
252
|
+
if (entries.length > 16) throw new Error(`storefront.media.gallery.${item.id}.caption exceeds 16 locales`);
|
|
253
|
+
for (const [locale, captionText] of entries) {
|
|
254
|
+
validLocale(locale, `storefront.media.gallery.${item.id}.caption key`);
|
|
255
|
+
text(captionText, `storefront.media.gallery.${item.id}.caption.${locale}`, 200);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
return storefront;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
export function readAppStorefront(root, manifest) {
|
|
265
|
+
const raw = manifest?.metadata?.storefront;
|
|
266
|
+
if (raw === undefined) return { storefront: undefined, mediaEntries: new Map() };
|
|
267
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) throw new Error('metadata.storefront must be an object');
|
|
268
|
+
for (const key of Object.keys(raw)) {
|
|
269
|
+
if (!['category', 'default_locale', 'locales', 'media'].includes(key)) {
|
|
270
|
+
throw new Error(`metadata.storefront contains unsupported field: ${key}`);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
const category = raw.category;
|
|
274
|
+
const defaultLocale = validLocale(raw.default_locale, 'metadata.storefront.default_locale');
|
|
275
|
+
const storefront = { category, default_locale: defaultLocale };
|
|
276
|
+
const readUtf8 = (relative, label, max) => new TextDecoder('utf-8', { fatal: true, ignoreBOM: true }).decode(resource(root, relative, label, max));
|
|
277
|
+
|
|
278
|
+
if (raw.locales !== undefined) {
|
|
279
|
+
if (!raw.locales || typeof raw.locales !== 'object' || Array.isArray(raw.locales)) throw new Error('metadata.storefront.locales must be an object');
|
|
280
|
+
const localesOut = {};
|
|
281
|
+
for (const locale of Object.keys(raw.locales).sort()) {
|
|
282
|
+
validLocale(locale, 'metadata.storefront.locales key');
|
|
283
|
+
const entry = raw.locales[locale];
|
|
284
|
+
if (!entry || typeof entry !== 'object' || Array.isArray(entry)) throw new Error(`metadata.storefront.locales.${locale} must be an object`);
|
|
285
|
+
for (const key of Object.keys(entry)) {
|
|
286
|
+
if (!['display_name', 'summary', 'tags', 'highlights', 'introduction'].includes(key)) {
|
|
287
|
+
throw new Error(`metadata.storefront.locales.${locale} contains unsupported field: ${key}`);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
const next = {};
|
|
291
|
+
if (locale === defaultLocale) {
|
|
292
|
+
if (entry.display_name !== undefined || entry.summary !== undefined || entry.introduction !== undefined) {
|
|
293
|
+
throw new Error(`metadata.storefront.locales.${locale} must not specify display_name, summary or introduction (use top-level metadata and NIMI_APP.md)`);
|
|
294
|
+
}
|
|
295
|
+
} else {
|
|
296
|
+
if (entry.display_name !== undefined) next.display_name = entry.display_name;
|
|
297
|
+
if (entry.summary !== undefined) next.summary = entry.summary;
|
|
298
|
+
if (entry.introduction !== undefined) {
|
|
299
|
+
next.introduction_markdown = readUtf8(entry.introduction, `storefront.locales.${locale}.introduction`, 96 * 1024);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
if (entry.tags !== undefined) next.tags = entry.tags;
|
|
303
|
+
if (entry.highlights !== undefined) {
|
|
304
|
+
if (!Array.isArray(entry.highlights)) throw new Error(`metadata.storefront.locales.${locale}.highlights must be a list`);
|
|
305
|
+
next.highlights = entry.highlights.map((item) => {
|
|
306
|
+
if (!item || typeof item !== 'object' || Array.isArray(item)) throw new Error(`metadata.storefront.locales.${locale}.highlights item must be an object`);
|
|
307
|
+
for (const key of Object.keys(item)) {
|
|
308
|
+
if (!['title', 'description'].includes(key)) throw new Error(`metadata.storefront highlight contains unsupported field: ${key}`);
|
|
309
|
+
}
|
|
310
|
+
return { title: item.title, description: item.description };
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
localesOut[locale] = next;
|
|
314
|
+
}
|
|
315
|
+
if (Object.keys(localesOut).length > 0) storefront.locales = localesOut;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
const mediaEntries = new Map();
|
|
319
|
+
const readImage = (relative, bounds, label) => {
|
|
320
|
+
const bytes = resource(root, relative, label, STOREFRONT_IMAGE_MAX_BYTES);
|
|
321
|
+
const ref = inspectStaticStorefrontImage(bytes, bounds, label);
|
|
322
|
+
const archiveName = `${ref.sha256}.${storefrontMediaExtension(ref.media_type)}`;
|
|
323
|
+
if (!mediaEntries.has(archiveName)) mediaEntries.set(archiveName, bytes);
|
|
324
|
+
return ref;
|
|
325
|
+
};
|
|
326
|
+
|
|
327
|
+
if (raw.media !== undefined) {
|
|
328
|
+
const rawMedia = raw.media;
|
|
329
|
+
if (!rawMedia || typeof rawMedia !== 'object' || Array.isArray(rawMedia)) throw new Error('metadata.storefront.media must be an object');
|
|
330
|
+
for (const key of Object.keys(rawMedia)) {
|
|
331
|
+
if (!['cover', 'gallery'].includes(key)) throw new Error(`metadata.storefront.media contains unsupported field: ${key}`);
|
|
332
|
+
}
|
|
333
|
+
const mediaOut = {};
|
|
334
|
+
if (rawMedia.cover !== undefined) {
|
|
335
|
+
const rawCover = rawMedia.cover;
|
|
336
|
+
if (!rawCover || typeof rawCover !== 'object' || Array.isArray(rawCover)) throw new Error('metadata.storefront.media.cover must be an object');
|
|
337
|
+
for (const key of Object.keys(rawCover)) {
|
|
338
|
+
if (!['path', 'locales'].includes(key)) throw new Error(`metadata.storefront.media.cover contains unsupported field: ${key}`);
|
|
339
|
+
}
|
|
340
|
+
const coverOut = { default: readImage(rawCover.path, STOREFRONT_COVER_BOUNDS, 'storefront.media.cover.path') };
|
|
341
|
+
if (rawCover.locales !== undefined) {
|
|
342
|
+
if (!rawCover.locales || typeof rawCover.locales !== 'object' || Array.isArray(rawCover.locales)) {
|
|
343
|
+
throw new Error('metadata.storefront.media.cover.locales must be an object');
|
|
344
|
+
}
|
|
345
|
+
const coverLocales = {};
|
|
346
|
+
for (const locale of Object.keys(rawCover.locales).sort()) {
|
|
347
|
+
validLocale(locale, 'metadata.storefront.media.cover.locales key');
|
|
348
|
+
if (locale === defaultLocale) throw new Error('metadata.storefront.media.cover.locales must not duplicate default_locale');
|
|
349
|
+
coverLocales[locale] = readImage(rawCover.locales[locale], STOREFRONT_COVER_BOUNDS, `storefront.media.cover.locales.${locale}`);
|
|
350
|
+
}
|
|
351
|
+
if (Object.keys(coverLocales).length > 0) coverOut.locales = coverLocales;
|
|
352
|
+
}
|
|
353
|
+
mediaOut.cover = coverOut;
|
|
354
|
+
}
|
|
355
|
+
if (rawMedia.gallery !== undefined) {
|
|
356
|
+
if (!Array.isArray(rawMedia.gallery)) throw new Error('metadata.storefront.media.gallery must be a list');
|
|
357
|
+
mediaOut.gallery = rawMedia.gallery.map((item) => {
|
|
358
|
+
if (!item || typeof item !== 'object' || Array.isArray(item)) throw new Error('metadata.storefront.media.gallery item must be an object');
|
|
359
|
+
for (const key of Object.keys(item)) {
|
|
360
|
+
if (!['id', 'kind', 'path', 'locales', 'caption'].includes(key)) throw new Error(`metadata.storefront gallery item contains unsupported field: ${key}`);
|
|
361
|
+
}
|
|
362
|
+
if (item.kind !== 'image') throw new Error(`metadata.storefront gallery item ${item.id} kind must be image`);
|
|
363
|
+
const galleryItem = {
|
|
364
|
+
id: item.id,
|
|
365
|
+
kind: 'image',
|
|
366
|
+
default: readImage(item.path, STOREFRONT_GALLERY_BOUNDS, `storefront.media.gallery.${item.id}.path`),
|
|
367
|
+
};
|
|
368
|
+
if (item.locales !== undefined) {
|
|
369
|
+
if (!item.locales || typeof item.locales !== 'object' || Array.isArray(item.locales)) {
|
|
370
|
+
throw new Error(`metadata.storefront.media.gallery.${item.id}.locales must be an object`);
|
|
371
|
+
}
|
|
372
|
+
const itemLocales = {};
|
|
373
|
+
for (const locale of Object.keys(item.locales).sort()) {
|
|
374
|
+
validLocale(locale, `metadata.storefront.media.gallery.${item.id}.locales key`);
|
|
375
|
+
if (locale === defaultLocale) throw new Error(`metadata.storefront.media.gallery.${item.id}.locales must not duplicate default_locale`);
|
|
376
|
+
itemLocales[locale] = readImage(item.locales[locale], STOREFRONT_GALLERY_BOUNDS, `storefront.media.gallery.${item.id}.locales.${locale}`);
|
|
377
|
+
}
|
|
378
|
+
if (Object.keys(itemLocales).length > 0) galleryItem.locales = itemLocales;
|
|
379
|
+
}
|
|
380
|
+
if (item.caption !== undefined) {
|
|
381
|
+
if (!item.caption || typeof item.caption !== 'object' || Array.isArray(item.caption)) {
|
|
382
|
+
throw new Error(`metadata.storefront.media.gallery.${item.id}.caption must be an object`);
|
|
383
|
+
}
|
|
384
|
+
const captions = {};
|
|
385
|
+
for (const locale of Object.keys(item.caption).sort()) captions[locale] = item.caption[locale];
|
|
386
|
+
if (Object.keys(captions).length > 0) galleryItem.caption = captions;
|
|
387
|
+
}
|
|
388
|
+
return galleryItem;
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
storefront.media = mediaOut;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
validateAppInfoStorefront(storefront);
|
|
395
|
+
return { storefront, mediaEntries };
|
|
396
|
+
}
|
|
397
|
+
|
|
109
398
|
function resource(root, relative, label, maxBytes) {
|
|
110
399
|
if (typeof relative !== 'string' || path.isAbsolute(relative) || relative.includes('\\')
|
|
111
400
|
|| relative.split('/').some((part) => !part || part === '.' || part === '..')) throw new Error(`metadata.${label} must name an App-relative resource`);
|
|
@@ -141,6 +430,7 @@ export function readAppInfo(root, targetId) {
|
|
|
141
430
|
const metadata = manifest.metadata;
|
|
142
431
|
if (!metadata || typeof metadata !== 'object') throw new Error('nimi.app.yaml metadata is required for distribution (summary, icon)');
|
|
143
432
|
const readText = (relative, label, max) => new TextDecoder('utf-8', { fatal: true, ignoreBOM: true }).decode(resource(root, relative, label, max));
|
|
433
|
+
const { storefront } = readAppStorefront(root, manifest);
|
|
144
434
|
const info = validateAppInfo({
|
|
145
435
|
format: 'nimi.app-info/v1', app_id: manifest.app_id, version: manifest.version, target_id: targetId,
|
|
146
436
|
display_name: manifest.display_name, summary: metadata.summary,
|
|
@@ -154,6 +444,7 @@ export function readAppInfo(root, targetId) {
|
|
|
154
444
|
storage_policy: storage(manifest.storage_policy),
|
|
155
445
|
author: metadata.author || '', homepage_url: https(metadata.homepage_url, 'homepage_url'), support_url: https(metadata.support_url, 'support_url'),
|
|
156
446
|
...(manifest[SAFETY_PROFILE_FIELD] === undefined ? {} : { [SAFETY_PROFILE_FIELD]: normalizeSafetyProfile(manifest[SAFETY_PROFILE_FIELD]) }),
|
|
447
|
+
...(storefront === undefined ? {} : { storefront }),
|
|
157
448
|
});
|
|
158
449
|
const submissionPath = path.join(root, '.nimi/admission/submission.yaml');
|
|
159
450
|
if (existsSync(submissionPath)) {
|
|
@@ -12,7 +12,7 @@ const AGENTS_BLOCK = `${START}
|
|
|
12
12
|
## Nimi App development
|
|
13
13
|
|
|
14
14
|
- For auditing adaptation feasibility or cost, creating, adapting, upgrading or releasing this App, read [the lifecycle skill](.agents/skills/nimi-app-lifecycle/SKILL.md) and only the relevant scenario. Audit-only requests do not begin implementation; prior reports remain evidence-dependent.
|
|
15
|
-
- For first integration or foundation wiring changes, use the selected app-tools package's generated reference and reuse its
|
|
15
|
+
- For first integration or foundation wiring changes, use the selected app-tools package's generated reference for the same carrier and reuse its renderer, session, App Access, AIConfig and AI call wiring; Host/preload apply only to native Desktop, while Web uses official scoped login and its admitted HTTPS source. Follow the adaptation guide's baseline checks and reuse passing results for ordinary business edits.
|
|
16
16
|
- Keep App-owned product behavior, Host code, business accounts and non-AI services with this repository. Use the SDK/Kit Local App carrier for Nimi AI, configuration, storage and session access.
|
|
17
17
|
- Development may consume complete local npm tarballs through the supported explicit overrides and version matrix; public-release preflight uses registry resolutions. Do not substitute source-workspace or directory links.
|
|
18
18
|
- App Tools owns its lifecycle skill, this block, managed workflow and declared engineering fields; preserve other instructions, product source and licenses. Existing adoption does not create fresh scaffold intent or lock.
|