@nimiplatform/app-tools 0.1.2 → 0.2.0
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/LICENSE +198 -6
- package/README.md +83 -27
- package/bin/nimi-app.mjs +328 -45
- package/lib/app-access-declaration.mjs +49 -0
- package/lib/app-doctor-update.mjs +411 -149
- package/lib/app-pack.mjs +401 -0
- package/lib/app-project-lifecycle.mjs +1141 -0
- package/lib/app-scaffold-capabilities.mjs +769 -0
- package/lib/app-scaffold-default-source.mjs +21 -0
- package/lib/app-scaffold-profiles.mjs +1093 -0
- package/lib/app-scaffold.mjs +1266 -813
- package/lib/index.mjs +194 -42
- package/lib/simulator-conformance-ast.mjs +498 -0
- package/lib/simulator-conformance-css.mjs +116 -0
- package/lib/simulator-conformance-graph.mjs +757 -0
- package/lib/simulator-conformance.d.mts +14 -0
- package/lib/simulator-conformance.mjs +203 -0
- package/lib/simulator-css-profile.d.mts +27 -0
- package/lib/simulator-css-profile.mjs +531 -0
- package/lib/simulator-kit-export-resolution.mjs +70 -0
- package/lib/simulator-manifest.mjs +334 -0
- package/package.json +66 -3
- package/scripts/dev-shell.mjs +465 -0
- package/scripts/sync-app-source.mjs +300 -0
- package/scripts/sync-scaffold-versions.mjs +91 -0
- package/templates/app-source/LICENSE +21 -0
- package/templates/app-source/src/ai-studio-core/ai-config.ts +100 -0
- package/templates/app-source/src/ai-studio-core/ai-studio-core.css +338 -0
- package/templates/app-source/src/ai-studio-core/contexts.tsx +61 -0
- package/templates/app-source/src/ai-studio-core/history-policy.ts +447 -0
- package/templates/app-source/src/ai-studio-core/history.ts +824 -0
- package/templates/app-source/src/ai-studio-core/host-context.tsx +79 -0
- package/templates/app-source/src/ai-studio-core/index.ts +214 -0
- package/templates/app-source/src/ai-studio-core/messages/en.json +310 -0
- package/templates/app-source/src/ai-studio-core/messages/index.ts +47 -0
- package/templates/app-source/src/ai-studio-core/messages/zh.json +310 -0
- package/templates/app-source/src/ai-studio-core/module-registration.ts +109 -0
- package/templates/app-source/src/ai-studio-core/non-success-presentation.ts +65 -0
- package/templates/app-source/src/ai-studio-core/parameter-fields.tsx +247 -0
- package/templates/app-source/src/ai-studio-core/parameters.ts +110 -0
- package/templates/app-source/src/ai-studio-core/prompt-drafts.ts +69 -0
- package/templates/app-source/src/ai-studio-core/run-target.ts +123 -0
- package/templates/app-source/src/ai-studio-core/runtime-dispatcher.ts +35 -0
- package/templates/app-source/src/ai-studio-core/runtime-types.ts +86 -0
- package/templates/app-source/src/ai-studio-core/runtime.ts +306 -0
- package/templates/app-source/src/ai-studio-core/section-ai-testing-admission.ts +38 -0
- package/templates/app-source/src/ai-studio-core/section-ai-testing-ai-config.tsx +30 -0
- package/templates/app-source/src/ai-studio-core/section-ai-testing-artifact-preview.ts +40 -0
- package/templates/app-source/src/ai-studio-core/section-ai-testing-composer.tsx +257 -0
- package/templates/app-source/src/ai-studio-core/section-ai-testing-history.tsx +676 -0
- package/templates/app-source/src/ai-studio-core/section-ai-testing-input.ts +19 -0
- package/templates/app-source/src/ai-studio-core/section-ai-testing-output.tsx +291 -0
- package/templates/app-source/src/ai-studio-core/section-ai-testing-result.tsx +413 -0
- package/templates/app-source/src/ai-studio-core/section-ai-testing-run.ts +174 -0
- package/templates/app-source/src/ai-studio-core/section-ai-testing-studio-result.tsx +449 -0
- package/templates/app-source/src/ai-studio-core/section-ai-testing-surface.tsx +45 -0
- package/templates/app-source/src/ai-studio-core/section-ai-testing.tsx +494 -0
- package/templates/app-source/src/ai-studio-core/studio-directives.ts +33 -0
- package/templates/app-source/src/ai-studio-core/workspace.tsx +381 -0
- package/templates/app-source/src/product-modules/agent-center/index.tsx +27 -0
- package/templates/app-source/src/product-modules/agent-conversation/index.tsx +19 -0
- package/templates/app-source/src/product-modules/agent-realtime/index.tsx +29 -0
- package/templates/app-source/src/product-modules/kit-recipes/gallery.tsx +142 -0
- package/templates/app-source/src/product-modules/kit-recipes/index.tsx +19 -0
- package/templates/app-source/src/product-modules/kit-recipes/kit-component-gallery-data-recipes.tsx +336 -0
- package/templates/app-source/src/product-modules/kit-recipes/kit-component-gallery-demos.tsx +165 -0
- package/templates/app-source/src/product-modules/kit-recipes/kit-component-gallery-recipes.tsx +682 -0
- package/templates/app-source/src/product-modules/kit-recipes/kit-component-gallery-surface.tsx +341 -0
- package/templates/app-source/src/studio-modules/studio-create/descriptors.ts +26 -0
- package/templates/app-source/src/studio-modules/studio-create/index.ts +14 -0
- package/templates/app-source/src/studio-modules/studio-create/messages/en.json +67 -0
- package/templates/app-source/src/studio-modules/studio-create/messages/index.ts +5 -0
- package/templates/app-source/src/studio-modules/studio-create/messages/zh.json +67 -0
- package/templates/app-source/src/studio-modules/studio-create/parameter-panel.tsx +153 -0
- package/templates/app-source/src/studio-modules/studio-create/parameters.ts +70 -0
- package/templates/app-source/src/studio-modules/studio-create/registration.ts +46 -0
- package/templates/app-source/src/studio-modules/studio-create/runtime.ts +339 -0
- package/templates/app-source/src/studio-modules/studio-media/descriptors.ts +22 -0
- package/templates/app-source/src/studio-modules/studio-media/index.ts +12 -0
- package/templates/app-source/src/studio-modules/studio-media/messages/en.json +82 -0
- package/templates/app-source/src/studio-modules/studio-media/messages/index.ts +5 -0
- package/templates/app-source/src/studio-modules/studio-media/messages/zh.json +82 -0
- package/templates/app-source/src/studio-modules/studio-media/parameter-panel.tsx +283 -0
- package/templates/app-source/src/studio-modules/studio-media/parameters.ts +94 -0
- package/templates/app-source/src/studio-modules/studio-media/registration.ts +44 -0
- package/templates/app-source/src/studio-modules/studio-media/runtime.ts +113 -0
- package/templates/app-source/src/studio-modules/studio-voice/descriptors.ts +28 -0
- package/templates/app-source/src/studio-modules/studio-voice/index.ts +16 -0
- package/templates/app-source/src/studio-modules/studio-voice/messages/en.json +99 -0
- package/templates/app-source/src/studio-modules/studio-voice/messages/index.ts +5 -0
- package/templates/app-source/src/studio-modules/studio-voice/messages/zh.json +99 -0
- package/templates/app-source/src/studio-modules/studio-voice/parameter-panel.tsx +284 -0
- package/templates/app-source/src/studio-modules/studio-voice/parameters.ts +116 -0
- package/templates/app-source/src/studio-modules/studio-voice/registration.ts +59 -0
- package/templates/app-source/src/studio-modules/studio-voice/runtime.ts +347 -0
- package/templates/app-source/src/workbench-core/empty-state.tsx +31 -0
- package/templates/app-source/src/workbench-core/index.ts +17 -0
- package/templates/app-source/src/workbench-core/runtime-gate.tsx +131 -0
- package/templates/app-source/src/workbench-core/workbench-core.css +255 -0
- package/templates/app-source/src/workbench-core/workbench-core.tsx +140 -0
- package/templates/app-source.manifest.json +333 -0
- package/templates/default-starter/AGENTS.md +33 -0
- package/templates/default-starter/LICENSE +21 -0
- package/templates/default-starter/README.md +41 -0
- package/templates/default-starter/SECURITY.md +5 -0
- package/templates/default-starter/index.html +12 -0
- package/templates/default-starter/scripts/validate.mjs +26 -0
- package/templates/default-starter/src/shell/App.tsx +27 -0
- package/templates/default-starter/src/shell/auth/app-identity.ts +3 -0
- package/templates/default-starter/src/shell/auth/local-app-client.ts +18 -0
- package/templates/default-starter/src/shell/auth/runtime-platform.ts +110 -0
- package/templates/default-starter/src/shell/authenticated-shell.tsx +20 -0
- package/templates/default-starter/src/shell/workbench-target-adapter.ts +40 -0
- package/templates/default-starter/src/styles.css +26 -0
- package/templates/default-starter/src-tauri/Cargo.toml +17 -0
- package/templates/default-starter/src-tauri/build.rs +5 -0
- package/templates/default-starter/src-tauri/capabilities/default.json +7 -0
- package/templates/default-starter/src-tauri/tauri.conf.json +26 -0
- package/templates/default-starter/tsconfig.json +18 -0
- package/templates/default-starter.manifest.json +99 -0
|
@@ -1,14 +1,37 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, readdirSync, readFileSync, statSync, writeFileSync } from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
+
import { parse as parseYaml } from 'yaml';
|
|
3
4
|
import {
|
|
4
|
-
|
|
5
|
+
buildAppScaffoldSnapshotFromIntent,
|
|
5
6
|
hashScaffoldContent,
|
|
7
|
+
SCAFFOLD_INTENT_PATH,
|
|
8
|
+
SCAFFOLD_LOCK_VERSION,
|
|
6
9
|
SCAFFOLD_LOCK_PATH,
|
|
7
10
|
SCAFFOLD_VERSION,
|
|
8
11
|
SUPPORTED_APP_SCAFFOLD_PROFILES,
|
|
9
12
|
} from './app-scaffold.mjs';
|
|
10
|
-
|
|
11
|
-
|
|
13
|
+
import { assertManifestAppAccessDeclaration } from './app-access-declaration.mjs';
|
|
14
|
+
import { validateSimulatorAppSourceWithCanonicalKitExports } from './simulator-conformance.mjs';
|
|
15
|
+
|
|
16
|
+
const SCAN_EXCLUDED_DIRS = new Set([
|
|
17
|
+
'.git',
|
|
18
|
+
'.turbo',
|
|
19
|
+
'.vite',
|
|
20
|
+
'build',
|
|
21
|
+
'coverage',
|
|
22
|
+
'dist',
|
|
23
|
+
'dist-electron',
|
|
24
|
+
'docs',
|
|
25
|
+
'node_modules',
|
|
26
|
+
'target',
|
|
27
|
+
'.tmp',
|
|
28
|
+
]);
|
|
29
|
+
const SCAN_EXCLUDED_FILES = new Set([
|
|
30
|
+
'Cargo.lock',
|
|
31
|
+
'package-lock.json',
|
|
32
|
+
'pnpm-lock.yaml',
|
|
33
|
+
'yarn.lock',
|
|
34
|
+
]);
|
|
12
35
|
const TEXT_EXTENSIONS = new Set([
|
|
13
36
|
'',
|
|
14
37
|
'.cjs',
|
|
@@ -56,36 +79,69 @@ const PROVIDER_MODEL_HARDCODING_MODEL_FAMILIES = Object.freeze([
|
|
|
56
79
|
String.raw`perplexity(?:-[a-z0-9][a-z0-9._-]*)*`,
|
|
57
80
|
String.raw`ollama(?:-[a-z0-9][a-z0-9._-]*)*`,
|
|
58
81
|
]);
|
|
82
|
+
const LOCAL_DEVELOPMENT_BYPASS_LABELS = new Set([
|
|
83
|
+
'generic platform auth helper in scaffold',
|
|
84
|
+
'Realm login bypass endpoint',
|
|
85
|
+
'Realm refresh bypass endpoint',
|
|
86
|
+
'Realm permission grant REST bypass endpoint',
|
|
87
|
+
'Realm raw request bypass',
|
|
88
|
+
'Realm API path literal bypass',
|
|
89
|
+
'Realm API url literal bypass',
|
|
90
|
+
'Realm API fetch bypass',
|
|
91
|
+
'OpenAI-compatible Runtime REST endpoint assumption',
|
|
92
|
+
'app-owned session store',
|
|
93
|
+
'app-owned refresh token provider',
|
|
94
|
+
'app-owned protected Runtime gRPC client',
|
|
95
|
+
'app-owned Runtime endpoint custody',
|
|
96
|
+
'renderer or app storage of protected material',
|
|
97
|
+
'environment custody of protected material',
|
|
98
|
+
'renderer launch binding custody',
|
|
99
|
+
'installed-app developer registration bypass',
|
|
100
|
+
'Desktop private import',
|
|
101
|
+
'Runtime private import',
|
|
102
|
+
'generated private Runtime client',
|
|
103
|
+
]);
|
|
59
104
|
|
|
60
105
|
function resolveTargetDir(cwd, options = {}) {
|
|
61
106
|
return path.resolve(cwd, String(options.dir || '').trim() || '.');
|
|
62
107
|
}
|
|
63
108
|
|
|
64
|
-
function readJsonFile(filePath) {
|
|
109
|
+
function readJsonFile(filePath, label = 'JSON file') {
|
|
65
110
|
try {
|
|
66
111
|
return JSON.parse(readFileSync(filePath, 'utf8'));
|
|
67
112
|
} catch (error) {
|
|
68
113
|
const message = error instanceof Error ? error.message : String(error);
|
|
69
|
-
throw new Error(`Invalid
|
|
114
|
+
throw new Error(`Invalid ${label}: ${filePath}: ${message}`);
|
|
70
115
|
}
|
|
71
116
|
}
|
|
72
117
|
|
|
73
118
|
function readLock(targetDir) {
|
|
74
119
|
const lockPath = path.join(targetDir, SCAFFOLD_LOCK_PATH);
|
|
75
120
|
if (!existsSync(lockPath)) {
|
|
76
|
-
throw new Error(`Missing scaffold lock: ${SCAFFOLD_LOCK_PATH}
|
|
121
|
+
throw new Error(`Missing initialized scaffold lock: ${SCAFFOLD_LOCK_PATH}. Run pnpm install, then pnpm run init.`);
|
|
122
|
+
}
|
|
123
|
+
return readJsonFile(lockPath, 'scaffold lock');
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function readIntent(targetDir) {
|
|
127
|
+
const intentPath = path.join(targetDir, SCAFFOLD_INTENT_PATH);
|
|
128
|
+
if (!existsSync(intentPath)) {
|
|
129
|
+
throw new Error(`Missing scaffold init intent: ${SCAFFOLD_INTENT_PATH}`);
|
|
77
130
|
}
|
|
78
|
-
return readJsonFile(
|
|
131
|
+
return readJsonFile(intentPath, 'scaffold init intent');
|
|
79
132
|
}
|
|
80
133
|
|
|
81
134
|
function assertSupportedLock(lock) {
|
|
135
|
+
if (lock?.lockVersion !== SCAFFOLD_LOCK_VERSION) {
|
|
136
|
+
throw new Error(`Unsupported scaffold lock version: ${String(lock?.lockVersion || 'missing')}`);
|
|
137
|
+
}
|
|
82
138
|
if (lock?.scaffoldVersion !== SCAFFOLD_VERSION) {
|
|
83
139
|
throw new Error(`Unsupported scaffold version: ${String(lock?.scaffoldVersion || 'missing')}`);
|
|
84
140
|
}
|
|
85
141
|
if (!SUPPORTED_APP_SCAFFOLD_PROFILES.includes(lock?.profile)) {
|
|
86
142
|
throw new Error(`Unsupported scaffold profile: ${String(lock?.profile || 'missing')}`);
|
|
87
143
|
}
|
|
88
|
-
if (!lock.appId || !lock.appTitle) {
|
|
144
|
+
if (!lock.appId || !lock.appTitle || !lock.version) {
|
|
89
145
|
throw new Error('Scaffold lock missing app identity');
|
|
90
146
|
}
|
|
91
147
|
}
|
|
@@ -114,16 +170,38 @@ function assertSameJson(actual, expected, label) {
|
|
|
114
170
|
}
|
|
115
171
|
}
|
|
116
172
|
|
|
117
|
-
function expectedSnapshotFromLock(lock, versions) {
|
|
173
|
+
function expectedSnapshotFromLock(lock, versions, intent, targetDir, options = {}) {
|
|
118
174
|
assertSupportedLock(lock);
|
|
119
|
-
|
|
120
|
-
|
|
175
|
+
if (!intent) {
|
|
176
|
+
throw new Error(`Missing scaffold init intent: ${SCAFFOLD_INTENT_PATH}`);
|
|
177
|
+
}
|
|
178
|
+
for (const [intentField, lockField, label] of [
|
|
179
|
+
['profile', 'profile', 'profile'],
|
|
180
|
+
['appId', 'appId', 'App ID'],
|
|
181
|
+
['appTitle', 'appTitle', 'display name'],
|
|
182
|
+
['packageName', 'packageName', 'package name'],
|
|
183
|
+
['packageAuthor', 'packageAuthor', 'package author'],
|
|
184
|
+
['cargoPackageName', 'cargoPackageName', 'Cargo package name'],
|
|
185
|
+
['tauriIdentifier', 'tauriIdentifier', 'Tauri identifier'],
|
|
186
|
+
['accentPack', 'accentPack', 'accent pack'],
|
|
187
|
+
]) {
|
|
188
|
+
const expected = lockField.includes('.')
|
|
189
|
+
? lockField.split('.').reduce((value, key) => value?.[key], lock)
|
|
190
|
+
: lock[lockField];
|
|
191
|
+
if (stableStringify(intent[intentField]) !== stableStringify(expected)) {
|
|
192
|
+
throw new Error(`Scaffold ${label} is immutable; create a fresh scaffold to change it`);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
const snapshot = buildAppScaffoldSnapshotFromIntent({
|
|
196
|
+
intent,
|
|
121
197
|
versions,
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
packageName: lock.packageName,
|
|
125
|
-
author: lock.packageAuthor || '',
|
|
198
|
+
targetDir,
|
|
199
|
+
allowDerivedAppAccessDrift: options.allowDerivedAppAccessDrift === true,
|
|
126
200
|
});
|
|
201
|
+
if (stableStringify(intent.directFeatures) !== stableStringify(lock.directFeatures)) {
|
|
202
|
+
throw new Error('Scaffold feature selection is immutable; create a fresh scaffold for a different feature closure');
|
|
203
|
+
}
|
|
204
|
+
return snapshot;
|
|
127
205
|
}
|
|
128
206
|
|
|
129
207
|
function readContentForHash(filePath) {
|
|
@@ -131,18 +209,45 @@ function readContentForHash(filePath) {
|
|
|
131
209
|
}
|
|
132
210
|
|
|
133
211
|
function ensureLockMatchesCurrentGenerator(lock, snapshot) {
|
|
212
|
+
assertSameJson(lock.scaffoldVersion, snapshot.lock.scaffoldVersion, 'Scaffold version');
|
|
134
213
|
assertSameJson(lock.appIdentity, snapshot.lock.appIdentity, 'App identity');
|
|
214
|
+
assertSameJson(lock.version, snapshot.lock.version, 'App version');
|
|
135
215
|
assertSameJson(lock.packageName, snapshot.lock.packageName, 'Package name');
|
|
136
216
|
assertSameJson(lock.packageAuthor, snapshot.lock.packageAuthor, 'Package author');
|
|
137
217
|
assertSameJson(lock.cargoPackageName, snapshot.lock.cargoPackageName, 'Cargo package name');
|
|
138
218
|
assertSameJson(lock.tauriIdentifier, snapshot.lock.tauriIdentifier, 'Tauri identifier');
|
|
219
|
+
assertSameJson(lock.accentPack, snapshot.lock.accentPack, 'Accent pack');
|
|
220
|
+
assertSameJson(lock.features, snapshot.lock.features, 'Scaffold features');
|
|
221
|
+
assertSameJson(lock.directFeatures, snapshot.lock.directFeatures, 'Direct scaffold features');
|
|
222
|
+
assertSameJson(lock.resolvedModules, snapshot.lock.resolvedModules, 'Resolved scaffold modules');
|
|
223
|
+
assertSameJson(lock.resolvedViews, snapshot.lock.resolvedViews, 'Resolved scaffold views');
|
|
224
|
+
assertSameJson(lock.resolvedNavigation, snapshot.lock.resolvedNavigation, 'Resolved scaffold navigation');
|
|
225
|
+
assertSameJson(lock.resolvedStyles, snapshot.lock.resolvedStyles, 'Resolved scaffold styles');
|
|
226
|
+
assertSameJson(lock.resolvedAssets, snapshot.lock.resolvedAssets, 'Resolved scaffold assets');
|
|
227
|
+
assertSameJson(lock.hostAdapterContracts, snapshot.lock.hostAdapterContracts, 'Scaffold host adapter contracts');
|
|
228
|
+
assertSameJson(lock.appAccessItems, snapshot.lock.appAccessItems, 'App access items');
|
|
229
|
+
assertSameJson(lock.capabilityContractRefs, snapshot.lock.capabilityContractRefs, 'Capability contract refs');
|
|
230
|
+
assertSameJson(lock.requiredStandardizedFeatureRefs, snapshot.lock.requiredStandardizedFeatureRefs, 'Required standardized feature refs');
|
|
139
231
|
assertSameJson(lock.managedFileTaxonomy, snapshot.lock.managedFileTaxonomy, 'Managed file taxonomy');
|
|
140
232
|
assertSameJson(lock.dependencyMatrix, snapshot.lock.dependencyMatrix, 'Dependency matrix');
|
|
141
233
|
assertSameJson(lock.managedFileHashes, snapshot.lock.managedFileHashes, 'Managed file hashes');
|
|
142
|
-
assertSameJson(
|
|
234
|
+
assertSameJson(
|
|
235
|
+
projectHashClasses(lock.appOwnedInitialHashes),
|
|
236
|
+
projectHashClasses(snapshot.lock.appOwnedInitialHashes),
|
|
237
|
+
'App-owned taxonomy',
|
|
238
|
+
);
|
|
143
239
|
assertSameJson(lock.semantics, snapshot.lock.semantics, 'Scaffold semantics');
|
|
144
240
|
}
|
|
145
241
|
|
|
242
|
+
function projectHashClasses(entries) {
|
|
243
|
+
return Object.fromEntries(
|
|
244
|
+
Object.entries(entries || {}).map(([relativePath, entry]) => [
|
|
245
|
+
relativePath,
|
|
246
|
+
{ class: entry?.class || '' },
|
|
247
|
+
]),
|
|
248
|
+
);
|
|
249
|
+
}
|
|
250
|
+
|
|
146
251
|
function collectTextFiles(rootDir) {
|
|
147
252
|
const results = [];
|
|
148
253
|
const walk = (currentDir) => {
|
|
@@ -158,6 +263,20 @@ function collectTextFiles(rootDir) {
|
|
|
158
263
|
if (!entry.isFile()) {
|
|
159
264
|
continue;
|
|
160
265
|
}
|
|
266
|
+
const relativePath = path.relative(rootDir, fullPath).split(path.sep).join('/');
|
|
267
|
+
if (SCAN_EXCLUDED_FILES.has(entry.name)) {
|
|
268
|
+
continue;
|
|
269
|
+
}
|
|
270
|
+
if (
|
|
271
|
+
relativePath.startsWith('.nimi/config/')
|
|
272
|
+
|| relativePath.startsWith('.nimi/contracts/')
|
|
273
|
+
|| relativePath.startsWith('.nimi/methodology/')
|
|
274
|
+
|| relativePath.startsWith('.nimi/spec/')
|
|
275
|
+
|| relativePath.startsWith('.nimi/local/')
|
|
276
|
+
|| relativePath.startsWith('.nimi/cache/')
|
|
277
|
+
) {
|
|
278
|
+
continue;
|
|
279
|
+
}
|
|
161
280
|
const stat = statSync(fullPath);
|
|
162
281
|
if (stat.size > 1024 * 1024) {
|
|
163
282
|
continue;
|
|
@@ -191,44 +310,76 @@ function buildProviderModelHardcodingPattern() {
|
|
|
191
310
|
|
|
192
311
|
function buildForbiddenPatterns() {
|
|
193
312
|
const runtimeBridgeName = ['runtime', 'bridge', 'plugin'].join('_');
|
|
194
|
-
const retiredFlag = ['--', 'template'].join('');
|
|
195
313
|
const modelTestImport = ['kit', 'features', 'model-test'].join('/');
|
|
196
|
-
const retiredProfiles = ['basic', ['vercel', 'ai'].join('-')];
|
|
197
|
-
const retiredBuilders = [
|
|
198
|
-
['build', 'Basic', 'App', 'Template'].join(''),
|
|
199
|
-
['build', 'VercelAI', 'App', 'Template'].join(''),
|
|
200
|
-
].join('|');
|
|
201
314
|
return [
|
|
202
315
|
['generic platform auth helper in scaffold', /createPlatformClient\s*\(/],
|
|
203
316
|
['first-party helper in third-party scaffold', /createLocalFirstPartyRuntimePlatformClient/],
|
|
204
317
|
['Realm login bypass endpoint', /\/api\/auth\/login/],
|
|
205
318
|
['Realm refresh bypass endpoint', /\/api\/auth\/refresh/],
|
|
319
|
+
['Realm permission grant REST bypass endpoint', /\/api\/human\/me\/permission-grants/],
|
|
320
|
+
['Realm raw request bypass', /\b(?:raw|unsafeRaw)\.request(?:<[\s\S]*?>)?\s*\(/],
|
|
321
|
+
['Realm API path literal bypass', /\bpath\s*:\s*['"`]\/api\//],
|
|
322
|
+
['Realm API url literal bypass', /\burl\s*:\s*['"`]\/api\//],
|
|
323
|
+
['Realm API fetch bypass', /\bfetch\s*\(\s*['"`]\/api\//],
|
|
324
|
+
['direct Realm permission grant module access', /\.permissionGrants\./],
|
|
325
|
+
['direct Realm permission grant method', /\b(?:listMyAppPermissionGrants|getMyAppPermissionGrant(?:Status|Projection)?|requestMyAppPermissionGrant|revokeMyAppPermissionGrant)\s*\(/],
|
|
326
|
+
['OpenAI-compatible Runtime REST endpoint assumption', /\/v1\/(?:chat\/completions|responses|embeddings|audio|images|models)\b/],
|
|
206
327
|
['app-owned session store', /sessionStore/],
|
|
207
328
|
['app-owned refresh token provider', /refreshTokenProvider/],
|
|
329
|
+
['app-owned protected Runtime gRPC client', /@grpc\/grpc-js|\bgrpc\.credentials\.createInsecure\s*\(/],
|
|
330
|
+
['app-owned Runtime endpoint custody', /\b(?:NIMI_RUNTIME_ENDPOINT|runtimeEndpoint)\b/],
|
|
331
|
+
['renderer or app storage of protected material', /\b(?:localStorage|sessionStorage)\.setItem\s*\([^\n]{0,160}(?:access[_-]?token|refresh[_-]?token|launch[_-]?ticket|protected[_-]?session|credential)/i],
|
|
332
|
+
['environment custody of protected material', /\bNIMI_[A-Z0-9_]*(?:TOKEN|TICKET|SESSION|CREDENTIAL)(?:_ID|_SECRET)?\b/],
|
|
208
333
|
['raw bearer token custody wording', /raw JWT/i],
|
|
209
334
|
['model-test import', new RegExp(modelTestImport.replace('/', '\\/'))],
|
|
210
335
|
['stale Runtime shell API', new RegExp(runtimeBridgeName)],
|
|
211
|
-
['retired template flag', new RegExp(retiredFlag.replace('-', '\\-'))],
|
|
212
|
-
['retired template builder', new RegExp(retiredBuilders)],
|
|
213
|
-
['retired kit package name', /@nimiplatform\/nimi-kit/],
|
|
214
|
-
['retired developer tools package name', /@nimiplatform\/dev-tools/],
|
|
215
|
-
['retired profile switch branch', new RegExp(`case\\s+['"](?:${retiredProfiles.join('|')})['"]`)],
|
|
216
|
-
['retired submitted profile', new RegExp(`(?:profile|template):\\s*(?:${retiredProfiles.join('|')})\\b`)],
|
|
217
|
-
['retired vercel profile remnant', new RegExp(retiredProfiles[1])],
|
|
218
336
|
['provider/model hardcoding', buildProviderModelHardcodingPattern()],
|
|
219
|
-
['
|
|
220
|
-
['
|
|
221
|
-
['installed-app
|
|
337
|
+
['external principal installed-app posture', /\bACCOUNT_CALLER_MODE_EXTERNAL_PRINCIPAL\b/],
|
|
338
|
+
['renderer launch binding custody', /\b(?:launchNonce|releaseDescriptorRef|launchBinding)\b/],
|
|
339
|
+
['installed-app developer registration bypass', /(?:developerRegistration\s*:\s*true[\s\S]{0,160}third-party-nimi-app|third-party-nimi-app[\s\S]{0,160}developerRegistration\s*:\s*true)/],
|
|
340
|
+
['Desktop private import', /\bfrom\s+['"`][^'"`]*apps\/desktop\//],
|
|
341
|
+
['Runtime private import', /\bfrom\s+['"`][^'"`]*runtime\/internal\//],
|
|
342
|
+
['generated private Runtime client', /\bfrom\s+['"`][^'"`]*(?:@nimiplatform\/runtime\/generated\/private-client|runtime\/generated\/private|generated\/private-client)/],
|
|
343
|
+
['forbidden installed-app shell capability', /\b(?:auth\.session(?:Load|Save|Clear)|local-agent\.runtimeTrustedCaller|platform-projection\.get|tauri-only\.commands)\b/],
|
|
222
344
|
];
|
|
223
345
|
}
|
|
224
346
|
|
|
225
|
-
function scanForbiddenPatterns(targetDir) {
|
|
347
|
+
function scanForbiddenPatterns(targetDir, profile, selectedLabels = null) {
|
|
226
348
|
const findings = [];
|
|
227
349
|
const patterns = buildForbiddenPatterns();
|
|
350
|
+
const testFileAllowedLabels = new Set([
|
|
351
|
+
'renderer launch binding custody',
|
|
352
|
+
'installed-app developer registration bypass',
|
|
353
|
+
'forbidden installed-app shell capability',
|
|
354
|
+
'Desktop private import',
|
|
355
|
+
'Runtime private import',
|
|
356
|
+
'generated private Runtime client',
|
|
357
|
+
'external principal installed-app posture',
|
|
358
|
+
'app-owned protected Runtime gRPC client',
|
|
359
|
+
'app-owned Runtime endpoint custody',
|
|
360
|
+
'renderer or app storage of protected material',
|
|
361
|
+
'environment custody of protected material',
|
|
362
|
+
]);
|
|
228
363
|
for (const filePath of collectTextFiles(targetDir)) {
|
|
229
364
|
const relativePath = path.relative(targetDir, filePath).split(path.sep).join('/');
|
|
230
365
|
const text = readFileSync(filePath, 'utf8');
|
|
366
|
+
const isTestFile = relativePath.startsWith('test/') || /(?:^|\/)\w[^/]*\.(?:test|spec)\.[cm]?[jt]sx?$/i.test(relativePath);
|
|
231
367
|
for (const [label, pattern] of patterns) {
|
|
368
|
+
if (selectedLabels && !selectedLabels.has(label)) {
|
|
369
|
+
continue;
|
|
370
|
+
}
|
|
371
|
+
if (selectedLabels && isTestFile) {
|
|
372
|
+
continue;
|
|
373
|
+
}
|
|
374
|
+
// Test files reference provider/model names to assert behavior (including
|
|
375
|
+
// negative assertions that forbid hardcoding); only product/glue source is
|
|
376
|
+
// product truth, so the hardcoding pattern is scoped out of tests.
|
|
377
|
+
if (label === 'provider/model hardcoding' && isTestFile) {
|
|
378
|
+
continue;
|
|
379
|
+
}
|
|
380
|
+
if (isTestFile && testFileAllowedLabels.has(label)) {
|
|
381
|
+
continue;
|
|
382
|
+
}
|
|
232
383
|
if (pattern.test(text)) {
|
|
233
384
|
findings.push(`${relativePath}: ${label}`);
|
|
234
385
|
}
|
|
@@ -237,14 +388,12 @@ function scanForbiddenPatterns(targetDir) {
|
|
|
237
388
|
return findings;
|
|
238
389
|
}
|
|
239
390
|
|
|
240
|
-
function readYamlScalar(text, key) {
|
|
241
|
-
const match = text.match(new RegExp(`^${key}:\\s*(.+?)\\s*$`, 'm'));
|
|
242
|
-
return match ? match[1].trim() : '';
|
|
243
|
-
}
|
|
244
|
-
|
|
245
391
|
function assertRequiredSupportFiles(targetDir, snapshot) {
|
|
246
392
|
const missing = [];
|
|
247
393
|
for (const file of snapshot.files) {
|
|
394
|
+
if (!snapshot.lock.managedFileHashes[file.path]) {
|
|
395
|
+
continue;
|
|
396
|
+
}
|
|
248
397
|
if (!existsSync(path.join(targetDir, file.path))) {
|
|
249
398
|
missing.push(file.path);
|
|
250
399
|
}
|
|
@@ -255,112 +404,113 @@ function assertRequiredSupportFiles(targetDir, snapshot) {
|
|
|
255
404
|
|
|
256
405
|
const tauriConfig = JSON.parse(readFileSync(path.join(targetDir, 'src-tauri/tauri.conf.json'), 'utf8'));
|
|
257
406
|
const icons = tauriConfig?.bundle?.icon;
|
|
258
|
-
if (!Array.isArray(icons) || icons.join(',') !== 'icons/icon.png') {
|
|
259
|
-
throw new Error('Tauri icon support drift: bundle.icon must be ["icons/icon.png"]');
|
|
407
|
+
if (!Array.isArray(icons) || icons.join(',') !== 'icons/icon.png,icons/icon.ico') {
|
|
408
|
+
throw new Error('Tauri icon support drift: bundle.icon must be ["icons/icon.png","icons/icon.ico"]');
|
|
260
409
|
}
|
|
261
410
|
const icon = readFileSync(path.join(targetDir, 'src-tauri/icons/icon.png'));
|
|
262
411
|
const pngSignature = [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a];
|
|
263
412
|
if (icon.length !== 68 || pngSignature.some((value, index) => icon[index] !== value)) {
|
|
264
413
|
throw new Error('Tauri icon support drift: src-tauri/icons/icon.png is not the scaffold PNG');
|
|
265
414
|
}
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
throw new Error('Submitted manifest contains admission or grant wording');
|
|
415
|
+
const ico = readFileSync(path.join(targetDir, 'src-tauri/icons/icon.ico'));
|
|
416
|
+
const icoHeader = [0x00, 0x00, 0x01, 0x00, 0x01, 0x00];
|
|
417
|
+
if (
|
|
418
|
+
ico.length !== 90
|
|
419
|
+
|| icoHeader.some((value, index) => ico[index] !== value)
|
|
420
|
+
|| pngSignature.some((value, index) => ico[index + 22] !== value)
|
|
421
|
+
) {
|
|
422
|
+
throw new Error('Tauri icon support drift: src-tauri/icons/icon.ico is not the scaffold ICO');
|
|
275
423
|
}
|
|
424
|
+
}
|
|
276
425
|
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
426
|
+
function assertProjectConfiguration(targetDir, parsedManifest = null) {
|
|
427
|
+
const manifestPath = path.join(targetDir, 'nimi.app.yaml');
|
|
428
|
+
const manifest = readFileSync(manifestPath, 'utf8');
|
|
429
|
+
assertManifestAppAccessDeclaration(manifest, manifestPath);
|
|
430
|
+
let document = parsedManifest;
|
|
431
|
+
if (!document) {
|
|
432
|
+
try {
|
|
433
|
+
document = parseYaml(manifest);
|
|
434
|
+
} catch (error) {
|
|
435
|
+
throw new Error(`Submitted manifest YAML cannot be parsed: ${error instanceof Error ? error.message : String(error)}`);
|
|
285
436
|
}
|
|
286
437
|
}
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
438
|
+
const rendererOrigin = assertElectronLocalDevelopmentManifest(document);
|
|
439
|
+
assertOfficialDevelopmentEntrypoints(targetDir, rendererOrigin);
|
|
440
|
+
}
|
|
290
441
|
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
'
|
|
295
|
-
'build_command:',
|
|
296
|
-
'output_path:',
|
|
297
|
-
'lockfile_path:',
|
|
298
|
-
'lockfile_policy:',
|
|
299
|
-
'ci_install_command:',
|
|
300
|
-
'profile_role: developer-workflow-input',
|
|
301
|
-
]) {
|
|
302
|
-
if (!buildProfile.includes(marker)) {
|
|
303
|
-
throw new Error(`Build profile marker missing: ${marker}`);
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
if (/checksum-pinned|ordinary-user install|direct npm install|direct npx|direct clone/i.test(buildProfile)) {
|
|
307
|
-
throw new Error('Build profile contains stale install or admission wording');
|
|
308
|
-
}
|
|
309
|
-
const ciWorkflow = readFileSync(path.join(targetDir, '.github/workflows/ci.yml'), 'utf8');
|
|
310
|
-
const lockfilePath = readYamlScalar(buildProfile, 'lockfile_path');
|
|
311
|
-
const lockfilePolicy = readYamlScalar(buildProfile, 'lockfile_policy');
|
|
312
|
-
const ciInstallCommand = readYamlScalar(buildProfile, 'ci_install_command');
|
|
313
|
-
if (lockfilePath !== 'pnpm-lock.yaml') {
|
|
314
|
-
throw new Error(`Build profile lockfile path must be pnpm-lock.yaml: ${lockfilePath}`);
|
|
315
|
-
}
|
|
316
|
-
if (lockfilePolicy !== 'author-install-generates-lockfile') {
|
|
317
|
-
throw new Error(`Build profile lockfile policy mismatch: ${lockfilePolicy}`);
|
|
318
|
-
}
|
|
319
|
-
if (!ciWorkflow.includes(`- run: ${ciInstallCommand}`)) {
|
|
320
|
-
throw new Error('CI install command does not match build profile');
|
|
321
|
-
}
|
|
322
|
-
const lockfileExists = existsSync(path.join(targetDir, lockfilePath));
|
|
323
|
-
if (!lockfileExists && /--frozen-lockfile/.test(ciWorkflow)) {
|
|
324
|
-
throw new Error(`CI uses frozen lockfile install but lockfile is missing: ${lockfilePath}`);
|
|
325
|
-
}
|
|
326
|
-
if (!lockfileExists && /^\s*cache:\s*pnpm\s*$/m.test(ciWorkflow)) {
|
|
327
|
-
throw new Error(`CI enables pnpm cache before lockfile exists: ${lockfilePath}`);
|
|
442
|
+
function assertElectronLocalDevelopmentManifest(document) {
|
|
443
|
+
const rendererOrigin = document?.local_development?.electron?.renderer_origin;
|
|
444
|
+
if (typeof rendererOrigin !== 'string' || rendererOrigin.trim() !== rendererOrigin) {
|
|
445
|
+
throw new Error('nimi.app.yaml must declare local_development.electron.renderer_origin');
|
|
328
446
|
}
|
|
447
|
+
let parsed;
|
|
448
|
+
try {
|
|
449
|
+
parsed = new URL(rendererOrigin);
|
|
450
|
+
} catch {
|
|
451
|
+
throw new Error('nimi.app.yaml local_development.electron.renderer_origin must be a canonical loopback origin');
|
|
452
|
+
}
|
|
453
|
+
if (
|
|
454
|
+
parsed.protocol !== 'http:'
|
|
455
|
+
|| parsed.hostname !== '127.0.0.1'
|
|
456
|
+
|| !parsed.port
|
|
457
|
+
|| parsed.username
|
|
458
|
+
|| parsed.password
|
|
459
|
+
|| parsed.pathname !== '/'
|
|
460
|
+
|| parsed.search
|
|
461
|
+
|| parsed.hash
|
|
462
|
+
|| rendererOrigin !== parsed.origin
|
|
463
|
+
) {
|
|
464
|
+
throw new Error('nimi.app.yaml local_development.electron.renderer_origin must be a canonical 127.0.0.1 origin');
|
|
465
|
+
}
|
|
466
|
+
return parsed.origin;
|
|
467
|
+
}
|
|
329
468
|
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
'
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
469
|
+
function assertOfficialDevelopmentEntrypoints(targetDir, rendererOrigin) {
|
|
470
|
+
const packageJson = readJsonFile(path.join(targetDir, 'package.json'), 'package.json');
|
|
471
|
+
const scripts = packageJson?.scripts;
|
|
472
|
+
if (!scripts || typeof scripts !== 'object' || Array.isArray(scripts)) {
|
|
473
|
+
throw new Error('package.json scripts are required');
|
|
474
|
+
}
|
|
475
|
+
const rendererPort = new URL(rendererOrigin).port;
|
|
476
|
+
const required = {
|
|
477
|
+
dev: 'nimi-app dev --shell electron',
|
|
478
|
+
'dev:shell': 'nimi-app dev',
|
|
479
|
+
'dev:renderer': `vite --host 127.0.0.1 --port ${rendererPort} --strictPort`,
|
|
480
|
+
};
|
|
481
|
+
for (const [name, command] of Object.entries(required)) {
|
|
482
|
+
if (scripts[name] !== command) {
|
|
483
|
+
throw new Error(`package.json ${name} must use the official local-development launcher: ${command}`);
|
|
340
484
|
}
|
|
341
485
|
}
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
'
|
|
346
|
-
|
|
347
|
-
'
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
486
|
+
if (
|
|
487
|
+
typeof scripts['build:electron'] !== 'string'
|
|
488
|
+
|| scripts['build:electron'].trim() !== scripts['build:electron']
|
|
489
|
+
|| scripts['build:electron'].length === 0
|
|
490
|
+
) {
|
|
491
|
+
throw new Error('package.json build:electron must build the Desktop-supervised Electron host');
|
|
492
|
+
}
|
|
493
|
+
for (const [name, value] of Object.entries(scripts)) {
|
|
494
|
+
const command = typeof value === 'string' ? value.trim() : '';
|
|
495
|
+
if (/--shell\s+tauri(?:\s|$)/i.test(command)) {
|
|
496
|
+
throw new Error(`package.json ${name} selects the retired Tauri local-development carrier`);
|
|
497
|
+
}
|
|
498
|
+
if (/(?:^|\s)(?:(?:pnpm\s+(?:exec\s+)?)|(?:npx\s+))?tauri\s+dev(?:\s|$)/i.test(command)) {
|
|
499
|
+
throw new Error(`package.json ${name} bypasses the Desktop-owned Electron development supervisor`);
|
|
500
|
+
}
|
|
501
|
+
if (/^(?:(?:pnpm\s+(?:exec\s+)?)|(?:npx\s+))?electron(?:\.cmd)?(?:\s|$)/i.test(command)) {
|
|
502
|
+
throw new Error(`package.json ${name} bypasses the Desktop-owned Electron development supervisor`);
|
|
351
503
|
}
|
|
352
504
|
}
|
|
505
|
+
}
|
|
353
506
|
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
'
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
if (!agents.includes(marker)) {
|
|
362
|
-
throw new Error(`AGENTS.md boundary text missing: ${marker}`);
|
|
363
|
-
}
|
|
507
|
+
function assertNimicodingProjectionCurrent(targetDir, runners) {
|
|
508
|
+
if (!runners?.runNimicodingSync) {
|
|
509
|
+
throw new Error('Missing nimicoding sync runner');
|
|
510
|
+
}
|
|
511
|
+
const result = runners.runNimicodingSync(targetDir, 'check');
|
|
512
|
+
if (result && result.ok === false) {
|
|
513
|
+
throw new Error('nimicoding package-owned projection check failed');
|
|
364
514
|
}
|
|
365
515
|
}
|
|
366
516
|
|
|
@@ -382,14 +532,22 @@ function assertManagedFilesCurrent(targetDir, lock) {
|
|
|
382
532
|
}
|
|
383
533
|
}
|
|
384
534
|
|
|
385
|
-
function
|
|
535
|
+
function validateAppProjectState(targetDir, versions, runners = {}) {
|
|
536
|
+
if (!existsSync(path.join(targetDir, SCAFFOLD_LOCK_PATH))) {
|
|
537
|
+
if (existsSync(path.join(targetDir, SCAFFOLD_INTENT_PATH))) {
|
|
538
|
+
readLock(targetDir);
|
|
539
|
+
}
|
|
540
|
+
return validateExistingSubmittedApp(targetDir);
|
|
541
|
+
}
|
|
386
542
|
const lock = readLock(targetDir);
|
|
387
|
-
const
|
|
543
|
+
const intent = readIntent(targetDir);
|
|
544
|
+
const snapshot = expectedSnapshotFromLock(lock, versions, intent, targetDir);
|
|
388
545
|
ensureLockMatchesCurrentGenerator(lock, snapshot);
|
|
389
546
|
assertRequiredSupportFiles(targetDir, snapshot);
|
|
390
|
-
|
|
547
|
+
assertProjectConfiguration(targetDir);
|
|
391
548
|
assertManagedFilesCurrent(targetDir, lock);
|
|
392
|
-
|
|
549
|
+
assertNimicodingProjectionCurrent(targetDir, runners);
|
|
550
|
+
const forbiddenFindings = scanForbiddenPatterns(targetDir, lock.profile);
|
|
393
551
|
if (forbiddenFindings.length > 0) {
|
|
394
552
|
throw new Error(`Forbidden scaffold remnants detected: ${forbiddenFindings.join('; ')}`);
|
|
395
553
|
}
|
|
@@ -400,22 +558,104 @@ function validateDoctorState(targetDir, versions) {
|
|
|
400
558
|
};
|
|
401
559
|
}
|
|
402
560
|
|
|
403
|
-
|
|
561
|
+
function validateExistingSubmittedApp(targetDir) {
|
|
562
|
+
const manifestPath = path.join(targetDir, 'nimi.app.yaml');
|
|
563
|
+
if (!existsSync(manifestPath)) {
|
|
564
|
+
throw new Error('Existing submitted app requires nimi.app.yaml');
|
|
565
|
+
}
|
|
566
|
+
const manifest = readFileSync(manifestPath, 'utf8');
|
|
567
|
+
let parsed;
|
|
568
|
+
try {
|
|
569
|
+
parsed = parseYaml(manifest);
|
|
570
|
+
} catch (error) {
|
|
571
|
+
throw new Error(`Submitted manifest YAML cannot be parsed: ${error instanceof Error ? error.message : String(error)}`);
|
|
572
|
+
}
|
|
573
|
+
const appId = typeof parsed?.app_id === 'string' ? parsed.app_id.trim() : '';
|
|
574
|
+
const profile = typeof parsed?.profile === 'string' ? parsed.profile.trim() : '';
|
|
575
|
+
if (!appId || appId !== parsed?.app_id || !SUPPORTED_APP_SCAFFOLD_PROFILES.includes(profile)) {
|
|
576
|
+
throw new Error('Existing submitted app requires canonical app_id and supported profile');
|
|
577
|
+
}
|
|
578
|
+
if (parsed?.manifest_role !== 'submitted-input') {
|
|
579
|
+
throw new Error('Submitted manifest marker missing');
|
|
580
|
+
}
|
|
581
|
+
assertProjectConfiguration(targetDir, parsed);
|
|
582
|
+
const forbiddenFindings = scanForbiddenPatterns(targetDir, profile, LOCAL_DEVELOPMENT_BYPASS_LABELS);
|
|
583
|
+
if (forbiddenFindings.length > 0) {
|
|
584
|
+
throw new Error(`Forbidden local-development bypasses detected: ${forbiddenFindings.join('; ')}`);
|
|
585
|
+
}
|
|
586
|
+
return {
|
|
587
|
+
targetDir,
|
|
588
|
+
managed: false,
|
|
589
|
+
appId,
|
|
590
|
+
profile,
|
|
591
|
+
checkedFiles: collectTextFiles(targetDir).length,
|
|
592
|
+
};
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
export function initApp(cwd, options = {}, versions, runners = {}) {
|
|
596
|
+
const targetDir = resolveTargetDir(cwd, options);
|
|
597
|
+
const intent = readIntent(targetDir);
|
|
598
|
+
const snapshot = buildAppScaffoldSnapshotFromIntent({ intent, versions, targetDir });
|
|
599
|
+
if (!runners?.runNimicodingSync) {
|
|
600
|
+
throw new Error('Missing nimicoding sync runner');
|
|
601
|
+
}
|
|
602
|
+
const nimicoding = runners.runNimicodingSync(targetDir, 'apply');
|
|
603
|
+
for (const file of snapshot.initFiles) {
|
|
604
|
+
writeScaffoldFile(targetDir, file);
|
|
605
|
+
}
|
|
606
|
+
validateAppProjectState(targetDir, versions, runners);
|
|
607
|
+
const payload = {
|
|
608
|
+
ok: true,
|
|
609
|
+
command: 'init',
|
|
610
|
+
dir: targetDir,
|
|
611
|
+
scaffoldVersion: snapshot.lock.scaffoldVersion,
|
|
612
|
+
profile: snapshot.lock.profile,
|
|
613
|
+
appId: snapshot.lock.appId,
|
|
614
|
+
features: snapshot.lock.features,
|
|
615
|
+
initializedFiles: snapshot.initFiles.length,
|
|
616
|
+
nimicodingSync: nimicoding?.summary || null,
|
|
617
|
+
};
|
|
618
|
+
if (options.json) {
|
|
619
|
+
process.stdout.write(`${JSON.stringify(payload, null, 2)}\n`);
|
|
620
|
+
} else {
|
|
621
|
+
process.stdout.write(`[nimi-app] init completed for ${targetDir}\n`);
|
|
622
|
+
}
|
|
623
|
+
return payload;
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
export function validateAppProject(cwd, options = {}, versions, runners = {}) {
|
|
404
627
|
const targetDir = resolveTargetDir(cwd, options);
|
|
405
|
-
|
|
628
|
+
if (options.conformance) {
|
|
629
|
+
if (options.conformance !== 'simulator') {
|
|
630
|
+
throw new Error(`Unsupported conformance target: ${options.conformance}`);
|
|
631
|
+
}
|
|
632
|
+
if (options.json) {
|
|
633
|
+
throw new Error('--json is not supported for Simulator source validation');
|
|
634
|
+
}
|
|
635
|
+
return validateSimulatorAppSourceWithCanonicalKitExports(targetDir).then((result) => {
|
|
636
|
+
process.stdout.write(`[nimi-app] Simulator source validation passed for ${targetDir}\n`);
|
|
637
|
+
return result;
|
|
638
|
+
});
|
|
639
|
+
}
|
|
640
|
+
const result = validateAppProjectState(targetDir, versions, runners);
|
|
406
641
|
const payload = {
|
|
407
642
|
ok: true,
|
|
408
|
-
command: '
|
|
643
|
+
command: 'check',
|
|
409
644
|
dir: targetDir,
|
|
410
|
-
scaffoldVersion: result.lock
|
|
411
|
-
profile: result.lock.profile,
|
|
412
|
-
appId: result.lock.appId,
|
|
413
|
-
|
|
645
|
+
scaffoldVersion: result.lock?.scaffoldVersion ?? null,
|
|
646
|
+
profile: result.lock?.profile ?? result.profile,
|
|
647
|
+
appId: result.lock?.appId ?? result.appId,
|
|
648
|
+
features: result.lock?.features ?? [],
|
|
649
|
+
checkedManagedFiles: result.lock ? Object.keys(result.lock.managedFileHashes || {}).length : 0,
|
|
650
|
+
checkedExistingFiles: result.managed === false ? result.checkedFiles : 0,
|
|
414
651
|
};
|
|
652
|
+
if (options.silent) {
|
|
653
|
+
return payload;
|
|
654
|
+
}
|
|
415
655
|
if (options.json) {
|
|
416
656
|
process.stdout.write(`${JSON.stringify(payload, null, 2)}\n`);
|
|
417
657
|
} else {
|
|
418
|
-
process.stdout.write(`[nimi-app]
|
|
658
|
+
process.stdout.write(`[nimi-app] check passed for ${targetDir}\n`);
|
|
419
659
|
}
|
|
420
660
|
return payload;
|
|
421
661
|
}
|
|
@@ -423,10 +663,10 @@ export function doctorApp(cwd, options = {}, versions) {
|
|
|
423
663
|
function collectExpectedClasses(snapshot) {
|
|
424
664
|
const entries = new Map();
|
|
425
665
|
for (const [relativePath, entry] of Object.entries(snapshot.lock.managedFileHashes)) {
|
|
426
|
-
entries.set(relativePath, entry.class);
|
|
666
|
+
entries.set(relativePath, { class: entry.class, owner: 'managed' });
|
|
427
667
|
}
|
|
428
668
|
for (const [relativePath, entry] of Object.entries(snapshot.lock.appOwnedInitialHashes)) {
|
|
429
|
-
entries.set(relativePath, entry.class);
|
|
669
|
+
entries.set(relativePath, { class: entry.class, owner: 'app-owned' });
|
|
430
670
|
}
|
|
431
671
|
return entries;
|
|
432
672
|
}
|
|
@@ -434,14 +674,18 @@ function collectExpectedClasses(snapshot) {
|
|
|
434
674
|
function assertNoClassificationConflict(lock, snapshot) {
|
|
435
675
|
const currentClasses = collectExpectedClasses(snapshot);
|
|
436
676
|
for (const [relativePath, entry] of Object.entries(lock.managedFileHashes || {})) {
|
|
437
|
-
|
|
438
|
-
|
|
677
|
+
const current = currentClasses.get(relativePath);
|
|
678
|
+
if (current?.owner === 'managed' && current.class === entry.class) {
|
|
679
|
+
continue;
|
|
439
680
|
}
|
|
681
|
+
throw new Error(`Scaffold classification conflict: ${relativePath}`);
|
|
440
682
|
}
|
|
441
683
|
for (const [relativePath, entry] of Object.entries(lock.appOwnedInitialHashes || {})) {
|
|
442
|
-
|
|
443
|
-
|
|
684
|
+
const current = currentClasses.get(relativePath);
|
|
685
|
+
if (current?.owner === 'app-owned' && current.class === entry.class) {
|
|
686
|
+
continue;
|
|
444
687
|
}
|
|
688
|
+
throw new Error(`Scaffold classification conflict: ${relativePath}`);
|
|
445
689
|
}
|
|
446
690
|
}
|
|
447
691
|
|
|
@@ -451,11 +695,25 @@ function writeScaffoldFile(targetDir, file) {
|
|
|
451
695
|
writeFileSync(targetPath, file.content);
|
|
452
696
|
}
|
|
453
697
|
|
|
454
|
-
export function
|
|
698
|
+
export function syncManagedApp(cwd, options = {}, versions, runners = {}) {
|
|
455
699
|
const targetDir = resolveTargetDir(cwd, options);
|
|
456
700
|
const lock = readLock(targetDir);
|
|
457
|
-
const
|
|
701
|
+
const intent = readIntent(targetDir);
|
|
702
|
+
const packageJson = readJsonFile(path.join(targetDir, 'package.json'), 'package.json');
|
|
703
|
+
const versionedIntent = {
|
|
704
|
+
...intent,
|
|
705
|
+
version: packageJson.version,
|
|
706
|
+
appIdentity: {
|
|
707
|
+
...intent.appIdentity,
|
|
708
|
+
version: packageJson.version,
|
|
709
|
+
},
|
|
710
|
+
};
|
|
711
|
+
const snapshot = expectedSnapshotFromLock(lock, versions, versionedIntent, targetDir, { allowDerivedAppAccessDrift: true });
|
|
458
712
|
assertNoClassificationConflict(lock, snapshot);
|
|
713
|
+
if (!runners?.runNimicodingSync) {
|
|
714
|
+
throw new Error('Missing nimicoding sync runner');
|
|
715
|
+
}
|
|
716
|
+
runners.runNimicodingSync(targetDir, 'apply');
|
|
459
717
|
|
|
460
718
|
for (const file of snapshot.filesWithoutLock) {
|
|
461
719
|
const managedEntry = snapshot.lock.managedFileHashes[file.path];
|
|
@@ -469,20 +727,24 @@ export function updateApp(cwd, options = {}, versions) {
|
|
|
469
727
|
content: `${JSON.stringify(snapshot.lock, null, 2)}\n`,
|
|
470
728
|
});
|
|
471
729
|
|
|
472
|
-
|
|
730
|
+
validateAppProjectState(targetDir, versions, runners);
|
|
473
731
|
const payload = {
|
|
474
732
|
ok: true,
|
|
475
|
-
command: '
|
|
733
|
+
command: 'sync',
|
|
476
734
|
dir: targetDir,
|
|
477
735
|
scaffoldVersion: snapshot.lock.scaffoldVersion,
|
|
478
736
|
profile: snapshot.lock.profile,
|
|
479
737
|
appId: snapshot.lock.appId,
|
|
738
|
+
features: snapshot.lock.features,
|
|
480
739
|
refreshedManagedFiles: Object.keys(snapshot.lock.managedFileHashes).length,
|
|
481
740
|
};
|
|
741
|
+
if (options.silent) {
|
|
742
|
+
return payload;
|
|
743
|
+
}
|
|
482
744
|
if (options.json) {
|
|
483
745
|
process.stdout.write(`${JSON.stringify(payload, null, 2)}\n`);
|
|
484
746
|
} else {
|
|
485
|
-
process.stdout.write(`[nimi-app]
|
|
747
|
+
process.stdout.write(`[nimi-app] sync refreshed managed scaffold files at ${targetDir}\n`);
|
|
486
748
|
}
|
|
487
749
|
return payload;
|
|
488
750
|
}
|