@nimiplatform/app-tools 0.1.3 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. package/LICENSE +198 -6
  2. package/README.md +83 -27
  3. package/bin/nimi-app.mjs +328 -45
  4. package/lib/app-access-declaration.mjs +49 -0
  5. package/lib/app-doctor-update.mjs +411 -149
  6. package/lib/app-pack.mjs +402 -0
  7. package/lib/app-project-lifecycle.mjs +1141 -0
  8. package/lib/app-scaffold-capabilities.mjs +769 -0
  9. package/lib/app-scaffold-default-source.mjs +21 -0
  10. package/lib/app-scaffold-profiles.mjs +1093 -0
  11. package/lib/app-scaffold.mjs +1266 -813
  12. package/lib/index.mjs +195 -42
  13. package/lib/simulator-conformance-ast.mjs +498 -0
  14. package/lib/simulator-conformance-css.mjs +116 -0
  15. package/lib/simulator-conformance-graph.mjs +757 -0
  16. package/lib/simulator-conformance.d.mts +14 -0
  17. package/lib/simulator-conformance.mjs +203 -0
  18. package/lib/simulator-css-profile.d.mts +27 -0
  19. package/lib/simulator-css-profile.mjs +531 -0
  20. package/lib/simulator-kit-export-resolution.mjs +70 -0
  21. package/lib/simulator-manifest.mjs +334 -0
  22. package/lib/windows-powershell.mjs +7 -0
  23. package/package.json +66 -3
  24. package/scripts/dev-shell.mjs +465 -0
  25. package/scripts/sync-app-source.mjs +300 -0
  26. package/scripts/sync-scaffold-versions.mjs +91 -0
  27. package/templates/app-source/LICENSE +21 -0
  28. package/templates/app-source/src/ai-studio-core/ai-config.ts +100 -0
  29. package/templates/app-source/src/ai-studio-core/ai-studio-core.css +338 -0
  30. package/templates/app-source/src/ai-studio-core/contexts.tsx +61 -0
  31. package/templates/app-source/src/ai-studio-core/history-policy.ts +447 -0
  32. package/templates/app-source/src/ai-studio-core/history.ts +824 -0
  33. package/templates/app-source/src/ai-studio-core/host-context.tsx +79 -0
  34. package/templates/app-source/src/ai-studio-core/index.ts +214 -0
  35. package/templates/app-source/src/ai-studio-core/messages/en.json +310 -0
  36. package/templates/app-source/src/ai-studio-core/messages/index.ts +47 -0
  37. package/templates/app-source/src/ai-studio-core/messages/zh.json +310 -0
  38. package/templates/app-source/src/ai-studio-core/module-registration.ts +109 -0
  39. package/templates/app-source/src/ai-studio-core/non-success-presentation.ts +65 -0
  40. package/templates/app-source/src/ai-studio-core/parameter-fields.tsx +247 -0
  41. package/templates/app-source/src/ai-studio-core/parameters.ts +110 -0
  42. package/templates/app-source/src/ai-studio-core/prompt-drafts.ts +69 -0
  43. package/templates/app-source/src/ai-studio-core/run-target.ts +123 -0
  44. package/templates/app-source/src/ai-studio-core/runtime-dispatcher.ts +35 -0
  45. package/templates/app-source/src/ai-studio-core/runtime-types.ts +86 -0
  46. package/templates/app-source/src/ai-studio-core/runtime.ts +306 -0
  47. package/templates/app-source/src/ai-studio-core/section-ai-testing-admission.ts +38 -0
  48. package/templates/app-source/src/ai-studio-core/section-ai-testing-ai-config.tsx +30 -0
  49. package/templates/app-source/src/ai-studio-core/section-ai-testing-artifact-preview.ts +40 -0
  50. package/templates/app-source/src/ai-studio-core/section-ai-testing-composer.tsx +257 -0
  51. package/templates/app-source/src/ai-studio-core/section-ai-testing-history.tsx +676 -0
  52. package/templates/app-source/src/ai-studio-core/section-ai-testing-input.ts +19 -0
  53. package/templates/app-source/src/ai-studio-core/section-ai-testing-output.tsx +291 -0
  54. package/templates/app-source/src/ai-studio-core/section-ai-testing-result.tsx +413 -0
  55. package/templates/app-source/src/ai-studio-core/section-ai-testing-run.ts +174 -0
  56. package/templates/app-source/src/ai-studio-core/section-ai-testing-studio-result.tsx +449 -0
  57. package/templates/app-source/src/ai-studio-core/section-ai-testing-surface.tsx +45 -0
  58. package/templates/app-source/src/ai-studio-core/section-ai-testing.tsx +494 -0
  59. package/templates/app-source/src/ai-studio-core/studio-directives.ts +33 -0
  60. package/templates/app-source/src/ai-studio-core/workspace.tsx +381 -0
  61. package/templates/app-source/src/product-modules/agent-center/index.tsx +27 -0
  62. package/templates/app-source/src/product-modules/agent-conversation/index.tsx +19 -0
  63. package/templates/app-source/src/product-modules/agent-realtime/index.tsx +29 -0
  64. package/templates/app-source/src/product-modules/kit-recipes/gallery.tsx +142 -0
  65. package/templates/app-source/src/product-modules/kit-recipes/index.tsx +19 -0
  66. package/templates/app-source/src/product-modules/kit-recipes/kit-component-gallery-data-recipes.tsx +336 -0
  67. package/templates/app-source/src/product-modules/kit-recipes/kit-component-gallery-demos.tsx +165 -0
  68. package/templates/app-source/src/product-modules/kit-recipes/kit-component-gallery-recipes.tsx +682 -0
  69. package/templates/app-source/src/product-modules/kit-recipes/kit-component-gallery-surface.tsx +341 -0
  70. package/templates/app-source/src/studio-modules/studio-create/descriptors.ts +26 -0
  71. package/templates/app-source/src/studio-modules/studio-create/index.ts +14 -0
  72. package/templates/app-source/src/studio-modules/studio-create/messages/en.json +67 -0
  73. package/templates/app-source/src/studio-modules/studio-create/messages/index.ts +5 -0
  74. package/templates/app-source/src/studio-modules/studio-create/messages/zh.json +67 -0
  75. package/templates/app-source/src/studio-modules/studio-create/parameter-panel.tsx +153 -0
  76. package/templates/app-source/src/studio-modules/studio-create/parameters.ts +70 -0
  77. package/templates/app-source/src/studio-modules/studio-create/registration.ts +46 -0
  78. package/templates/app-source/src/studio-modules/studio-create/runtime.ts +339 -0
  79. package/templates/app-source/src/studio-modules/studio-media/descriptors.ts +22 -0
  80. package/templates/app-source/src/studio-modules/studio-media/index.ts +12 -0
  81. package/templates/app-source/src/studio-modules/studio-media/messages/en.json +82 -0
  82. package/templates/app-source/src/studio-modules/studio-media/messages/index.ts +5 -0
  83. package/templates/app-source/src/studio-modules/studio-media/messages/zh.json +82 -0
  84. package/templates/app-source/src/studio-modules/studio-media/parameter-panel.tsx +283 -0
  85. package/templates/app-source/src/studio-modules/studio-media/parameters.ts +94 -0
  86. package/templates/app-source/src/studio-modules/studio-media/registration.ts +44 -0
  87. package/templates/app-source/src/studio-modules/studio-media/runtime.ts +113 -0
  88. package/templates/app-source/src/studio-modules/studio-voice/descriptors.ts +28 -0
  89. package/templates/app-source/src/studio-modules/studio-voice/index.ts +16 -0
  90. package/templates/app-source/src/studio-modules/studio-voice/messages/en.json +99 -0
  91. package/templates/app-source/src/studio-modules/studio-voice/messages/index.ts +5 -0
  92. package/templates/app-source/src/studio-modules/studio-voice/messages/zh.json +99 -0
  93. package/templates/app-source/src/studio-modules/studio-voice/parameter-panel.tsx +284 -0
  94. package/templates/app-source/src/studio-modules/studio-voice/parameters.ts +116 -0
  95. package/templates/app-source/src/studio-modules/studio-voice/registration.ts +59 -0
  96. package/templates/app-source/src/studio-modules/studio-voice/runtime.ts +347 -0
  97. package/templates/app-source/src/workbench-core/empty-state.tsx +31 -0
  98. package/templates/app-source/src/workbench-core/index.ts +17 -0
  99. package/templates/app-source/src/workbench-core/runtime-gate.tsx +131 -0
  100. package/templates/app-source/src/workbench-core/workbench-core.css +255 -0
  101. package/templates/app-source/src/workbench-core/workbench-core.tsx +140 -0
  102. package/templates/app-source.manifest.json +333 -0
  103. package/templates/default-starter/AGENTS.md +33 -0
  104. package/templates/default-starter/LICENSE +21 -0
  105. package/templates/default-starter/README.md +41 -0
  106. package/templates/default-starter/SECURITY.md +5 -0
  107. package/templates/default-starter/index.html +12 -0
  108. package/templates/default-starter/scripts/validate.mjs +26 -0
  109. package/templates/default-starter/src/shell/App.tsx +27 -0
  110. package/templates/default-starter/src/shell/auth/app-identity.ts +3 -0
  111. package/templates/default-starter/src/shell/auth/local-app-client.ts +18 -0
  112. package/templates/default-starter/src/shell/auth/runtime-platform.ts +110 -0
  113. package/templates/default-starter/src/shell/authenticated-shell.tsx +20 -0
  114. package/templates/default-starter/src/shell/workbench-target-adapter.ts +40 -0
  115. package/templates/default-starter/src/styles.css +26 -0
  116. package/templates/default-starter/src-tauri/Cargo.toml +17 -0
  117. package/templates/default-starter/src-tauri/build.rs +5 -0
  118. package/templates/default-starter/src-tauri/capabilities/default.json +7 -0
  119. package/templates/default-starter/src-tauri/tauri.conf.json +26 -0
  120. package/templates/default-starter/tsconfig.json +18 -0
  121. package/templates/default-starter.manifest.json +99 -0
package/bin/nimi-app.mjs CHANGED
@@ -1,112 +1,395 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  import process from 'node:process';
4
- import { createApp, doctorAppScaffold, updateAppScaffold } from '../lib/index.mjs';
4
+ import {
5
+ APP_SCAFFOLD_FEATURE_IDS,
6
+ buildApp,
7
+ checkApp,
8
+ createApp,
9
+ initAppScaffold,
10
+ packApp,
11
+ resolveAppCreateInput,
12
+ resolveAppCreatePlan,
13
+ runDevShell,
14
+ syncApp,
15
+ testApp,
16
+ } from '../lib/index.mjs';
17
+ import { APP_SCAFFOLD_MODULE_REGISTRY } from '../lib/app-scaffold-capabilities.mjs';
18
+ import { createInterface } from 'node:readline/promises';
5
19
 
6
20
  function parseArgs(argv) {
7
21
  const [command = '', ...rest] = argv;
8
- let dir = '';
9
- let profile = '';
10
- let appId = '';
11
- let title = '';
12
- let packageName = '';
13
- let author = '';
14
- let json = false;
22
+ const values = {
23
+ dir: '', profile: '', appId: '', version: '', title: '', packageName: '', author: '',
24
+ features: undefined, shell: '', cdpPort: undefined, noCdp: false, conformance: '', target: '', aggregate: false, production: false, json: false,
25
+ };
26
+ const seen = new Set();
27
+ const readValue = (index, flag, key, preserve = false) => {
28
+ if (seen.has(key)) throw new Error(`Duplicate option: ${flag}`);
29
+ const next = rest[index + 1];
30
+ if (next === undefined || String(next).startsWith('--')) {
31
+ throw new Error(`${flag} requires a value`);
32
+ }
33
+ const value = preserve ? String(next) : String(next).trim();
34
+ if (!value) throw new Error(`${flag} requires a non-empty value`);
35
+ seen.add(key);
36
+ values[key] = value;
37
+ return index + 1;
38
+ };
15
39
  for (let index = 0; index < rest.length; index += 1) {
40
+ if (rest[index] === '--') {
41
+ continue;
42
+ }
16
43
  if (rest[index] === '--dir') {
17
- dir = String(rest[index + 1] || '').trim();
18
- index += 1;
44
+ index = readValue(index, '--dir', 'dir');
19
45
  continue;
20
46
  }
21
47
  if (rest[index] === '--profile') {
22
- profile = String(rest[index + 1] || '').trim();
23
- index += 1;
48
+ index = readValue(index, '--profile', 'profile');
24
49
  continue;
25
50
  }
26
51
  if (rest[index] === '--app-id') {
27
- appId = String(rest[index + 1] || '').trim();
28
- index += 1;
52
+ index = readValue(index, '--app-id', 'appId', true);
53
+ continue;
54
+ }
55
+ if (rest[index] === '--version') {
56
+ index = readValue(index, '--version', 'version');
29
57
  continue;
30
58
  }
31
59
  if (rest[index] === '--title') {
32
- title = String(rest[index + 1] || '').trim();
33
- index += 1;
60
+ index = readValue(index, '--title', 'title', true);
34
61
  continue;
35
62
  }
36
63
  if (rest[index] === '--package-name') {
37
- packageName = String(rest[index + 1] || '').trim();
38
- index += 1;
64
+ index = readValue(index, '--package-name', 'packageName', true);
39
65
  continue;
40
66
  }
41
67
  if (rest[index] === '--author') {
42
- author = String(rest[index + 1] || '').trim();
43
- index += 1;
68
+ index = readValue(index, '--author', 'author', true);
69
+ continue;
70
+ }
71
+ if (rest[index] === '--features') {
72
+ index = readValue(index, '--features', 'features');
73
+ continue;
74
+ }
75
+ if (rest[index] === '--shell') {
76
+ index = readValue(index, '--shell', 'shell');
77
+ continue;
78
+ }
79
+ if (rest[index] === '--cdp-port') {
80
+ index = readValue(index, '--cdp-port', 'cdpPort');
81
+ continue;
82
+ }
83
+ if (rest[index] === '--no-cdp') {
84
+ if (seen.has('noCdp')) throw new Error('Duplicate option: --no-cdp');
85
+ seen.add('noCdp');
86
+ values.noCdp = true;
87
+ continue;
88
+ }
89
+ if (rest[index] === '--conformance') {
90
+ index = readValue(index, '--conformance', 'conformance');
91
+ continue;
92
+ }
93
+ if (rest[index] === '--target') {
94
+ index = readValue(index, '--target', 'target');
95
+ continue;
96
+ }
97
+ if (rest[index] === '--aggregate') {
98
+ if (seen.has('aggregate')) throw new Error('Duplicate option: --aggregate');
99
+ seen.add('aggregate');
100
+ values.aggregate = true;
101
+ continue;
102
+ }
103
+ if (rest[index] === '--production') {
104
+ if (seen.has('production')) throw new Error('Duplicate option: --production');
105
+ seen.add('production');
106
+ values.production = true;
44
107
  continue;
45
108
  }
46
109
  if (rest[index] === '--json') {
47
- json = true;
110
+ if (seen.has('json')) throw new Error('Duplicate option: --json');
111
+ seen.add('json');
112
+ values.json = true;
48
113
  continue;
49
114
  }
50
115
  throw new Error(`Unknown option: ${rest[index]}`);
51
116
  }
52
- return {
117
+ return Object.freeze({
53
118
  command: String(command || '').trim(),
54
- dir,
55
- profile,
56
- appId,
57
- title,
58
- packageName,
59
- author,
60
- json,
61
- };
119
+ ...values,
120
+ providedOptions: Object.freeze([...seen]),
121
+ });
122
+ }
123
+
124
+ function assertCommandOptions(command, providedOptions) {
125
+ const allowed = {
126
+ create: new Set(['dir', 'profile', 'appId', 'version', 'title', 'packageName', 'author', 'features', 'json']),
127
+ init: new Set(['dir', 'json']),
128
+ sync: new Set(['dir', 'json']),
129
+ check: new Set(['dir', 'json', 'conformance', 'production']),
130
+ dev: new Set(['dir', 'shell', 'cdpPort', 'noCdp']),
131
+ test: new Set(['dir', 'json']),
132
+ build: new Set(['dir', 'target', 'production', 'json']),
133
+ pack: new Set(['dir', 'target', 'aggregate', 'production', 'json']),
134
+ }[command];
135
+ if (!allowed) return;
136
+ const invalid = providedOptions.find((key) => !allowed.has(key));
137
+ if (invalid) throw new Error(`Option --${invalid.replace(/[A-Z]/g, (value) => `-${value.toLowerCase()}`)} is not available for nimi-app ${command}`);
62
138
  }
63
139
 
64
140
  function printUsage() {
141
+ const modules = Object.values(APP_SCAFFOLD_MODULE_REGISTRY)
142
+ .sort((left, right) => left.order - right.order || left.id.localeCompare(right.id));
143
+ const admitted = modules.filter((module) => module.kind === 'feature' && module.lifecycle === 'admitted');
144
+ const candidates = modules.filter((module) => module.kind === 'feature' && module.lifecycle === 'candidate');
145
+ const internal = modules.filter((module) => module.kind === 'internal');
146
+ const featureList = (entries) => entries.length > 0
147
+ ? entries.map((entry) => `${entry.id} (${entry.label})`).join(', ')
148
+ : '(none)';
149
+ const internalList = internal.length > 0
150
+ ? internal.map((entry) => entry.id).join(', ')
151
+ : '(none)';
65
152
  process.stdout.write(
66
153
  [
154
+ 'Nimi App developer tools',
155
+ '',
67
156
  'Usage:',
68
- ' nimi-app create [--dir path] [--profile standalone|workspace-app] [--app-id id] [--title title] [--package-name name] [--author author]',
69
- ' nimi-app doctor [--dir path] [--json]',
70
- ' nimi-app update [--dir path] [--json]',
157
+ ' nimi-app create [--dir path] [--profile standalone] [--features admitted-ids|all] [--app-id dotted.id] [--version semver] [--title title] [--package-name name] [--author person-or-team] [--json]',
158
+ ' nimi-app init [--dir path] [--json]',
159
+ ' nimi-app sync [--dir path] [--json]',
160
+ ' nimi-app check [--dir path] [--conformance simulator | --production] [--json]',
161
+ ' nimi-app dev [--dir path] [--shell electron] [--cdp-port 1024..65535 | --no-cdp]',
162
+ ' nimi-app test [--dir path] [--json]',
163
+ ' nimi-app build [--dir path] [--target target-id] [--production] [--json]',
164
+ ' nimi-app pack [--dir path] (--target target-id [--production] | --aggregate) [--json]',
165
+ '',
166
+ 'Current module registry:',
167
+ ` Admitted features: ${featureList(admitted)}`,
168
+ ` Candidate features (not public-selectable): ${featureList(candidates)}`,
169
+ ` Internal modules (dependency-only): ${internalList}`,
170
+ admitted.length > 0
171
+ ? ` --features all expands in order to: ${admitted.map((entry) => entry.id).join(', ')}`
172
+ : ' --features all is unavailable because no features are currently admitted.',
173
+ ' Candidate and internal IDs fail closed when passed to the public CLI.',
174
+ '',
175
+ 'Composition:',
176
+ ' Base = identity-neutral Lab-derived workbench-core + empty module registry + target adapter.',
177
+ ' Coarse inventory = studio-create (Create), studio-media (Media), studio-voice (Voice), kit-recipes (UI Recipes).',
178
+ ' AI features resolve the internal ai-studio-core once; it cannot be selected directly.',
179
+ ' Generated Apps exclude Lab-only Settings/account, App Access diagnostics, Realm/Agent probes, World Tour, and native/diagnostic surfaces.',
180
+ '',
181
+ 'Third-party topology:',
182
+ ' standalone: any empty target directory using public registry package versions only.',
183
+ ' Nimi workspace paths, local tarballs, downgrades, and private validation topology are never public create modes.',
184
+ '',
185
+ 'Ownership:',
186
+ ' App-owned: workbench-core and selected module product code under src/capabilities/**.',
187
+ ' Scaffold-managed: carrier, identity, manifest/native wiring, and generated composition glue.',
188
+ ' sync refreshes only scaffold-managed files; check is non-mutating.',
189
+ ' Simulator conformance remains an explicit check mode for existing Simulator Apps; this scaffold does not generate one.',
190
+ '',
191
+ 'Required order:',
192
+ ' create -> dependency install -> init -> sync -> check -> dev/test/build -> pack',
193
+ ' Run init and later commands only after dependency installation.',
194
+ '',
195
+ 'Development CDP:',
196
+ ' Electron CDP defaults to an automatically selected loopback port.',
197
+ ' --cdp-port overrides it; --no-cdp disables it.',
198
+ ' NIMI_APP_DEV_CDP_PORT in the project .env provides a stable port below the CLI override.',
199
+ '',
200
+ 'Acceptance status:',
201
+ ' Generated build and Desktop-supervised launch remain NOT-VERIFIED until those real journeys run.',
202
+ ' CLI/help or focused tests do not constitute implementation or release acceptance.',
71
203
  '',
72
204
  ].join('\n'),
73
205
  );
74
206
  }
75
207
 
208
+ const CANCEL_TOKEN = ':cancel';
209
+
210
+ function defaultPackageName(appId) {
211
+ return String(appId || 'my-nimi-app').replaceAll('.', '-');
212
+ }
213
+
214
+ async function collectCreateInput(cwd, initial) {
215
+ const prompt = createInterface({ input: process.stdin, output: process.stdout });
216
+ const raw = { ...initial };
217
+ const ask = async ({ key, label, fallback = '', optional = false }) => {
218
+ for (;;) {
219
+ const suffix = fallback ? ` [${fallback}]` : optional ? ' (optional)' : '';
220
+ const answer = await prompt.question(`${label}${suffix} (or ${CANCEL_TOKEN}): `);
221
+ if (answer.trim().toLowerCase() === CANCEL_TOKEN) throw new Error('Create cancelled by user');
222
+ const value = answer === '' ? fallback : answer;
223
+ const candidate = { ...raw, [key]: value };
224
+ try {
225
+ resolveAppCreateInput(cwd, candidate);
226
+ raw[key] = value;
227
+ return;
228
+ } catch (error) {
229
+ const message = error instanceof Error ? error.message : String(error);
230
+ process.stdout.write(`Validation error: ${message}\n`);
231
+ }
232
+ }
233
+ };
234
+ try {
235
+ if (!raw.appId) await ask({ key: 'appId', label: 'App ID', fallback: 'my.nimi-app' });
236
+ if (!raw.version) await ask({ key: 'version', label: 'Initial version', fallback: '0.1.0' });
237
+ if (!raw.title) await ask({ key: 'title', label: 'Display Name', fallback: 'My Nimi App' });
238
+ if (!raw.packageName) await ask({ key: 'packageName', label: 'Package name', fallback: defaultPackageName(raw.appId) });
239
+ if (!initial.providedOptions.includes('author')) await ask({ key: 'author', label: 'Author (person or team)', optional: true });
240
+ if (raw.features === undefined) {
241
+ process.stdout.write(`Available features: ${APP_SCAFFOLD_FEATURE_IDS.join(', ') || '(none)'}\n`);
242
+ await ask({ key: 'features', label: 'Features (comma-separated, blank for base only)', optional: true });
243
+ }
244
+ return raw;
245
+ } finally {
246
+ prompt.close();
247
+ }
248
+ }
249
+
250
+ function printCreatePreview(preview, json = false) {
251
+ if (!json) process.stdout.write('[nimi-app] resolved create preview:\n');
252
+ process.stdout.write(`${JSON.stringify(preview, null, 2)}\n`);
253
+ }
254
+
255
+ async function confirmCreate(preview) {
256
+ const prompt = createInterface({ input: process.stdin, output: process.stdout });
257
+ try {
258
+ printCreatePreview(preview);
259
+ for (;;) {
260
+ const answer = (await prompt.question('Create this App? [y/N]: ')).trim().toLowerCase();
261
+ if (answer === CANCEL_TOKEN || answer === 'n' || answer === 'no' || answer === '') {
262
+ throw new Error('Create cancelled by user');
263
+ }
264
+ if (answer === 'y' || answer === 'yes') return;
265
+ process.stdout.write('Please answer yes or no.\n');
266
+ }
267
+ } finally {
268
+ prompt.close();
269
+ }
270
+ }
271
+
272
+ let parsedArgs = null;
76
273
  try {
77
- const { command, dir, profile, appId, title, packageName, author, json } = parseArgs(process.argv.slice(2));
274
+ parsedArgs = parseArgs(process.argv.slice(2));
275
+ const {
276
+ command,
277
+ dir,
278
+ profile,
279
+ appId,
280
+ version,
281
+ title,
282
+ packageName,
283
+ author,
284
+ features: parsedFeatures,
285
+ shell,
286
+ cdpPort,
287
+ noCdp,
288
+ conformance,
289
+ target,
290
+ aggregate,
291
+ production,
292
+ json,
293
+ providedOptions,
294
+ } = parsedArgs;
78
295
  if (!command || command === '--help' || command === '-h') {
79
296
  printUsage();
80
297
  process.exit(0);
81
298
  }
299
+ assertCommandOptions(command, providedOptions);
300
+ if (command !== 'dev' && (cdpPort !== undefined || noCdp)) {
301
+ throw new Error('--cdp-port and --no-cdp are available only for nimi-app dev');
302
+ }
303
+ if (command === 'dev' && cdpPort !== undefined && noCdp) {
304
+ throw new Error('--cdp-port and --no-cdp cannot be combined');
305
+ }
82
306
  switch (command) {
83
307
  case 'create':
84
- createApp(process.cwd(), {
308
+ {
309
+ const interactive = Boolean(process.stdin.isTTY && process.stdout.isTTY);
310
+ const rawInput = {
311
+ dir,
312
+ profile,
313
+ appId,
314
+ version,
315
+ title,
316
+ packageName,
317
+ author,
318
+ features: parsedFeatures,
319
+ providedOptions,
320
+ };
321
+ const collected = interactive
322
+ ? await collectCreateInput(process.cwd(), rawInput)
323
+ : rawInput;
324
+ const plan = resolveAppCreatePlan(process.cwd(), collected);
325
+ if (interactive) {
326
+ await confirmCreate(plan.preview);
327
+ } else if (!json) {
328
+ printCreatePreview(plan.preview);
329
+ }
330
+ const result = createApp(process.cwd(), {
331
+ ...collected,
332
+ plan,
333
+ silent: json,
334
+ });
335
+ if (json) process.stdout.write(`${JSON.stringify(result, null, 2)}\n`);
336
+ }
337
+ break;
338
+ case 'init':
339
+ initAppScaffold(process.cwd(), {
85
340
  dir,
86
- profile,
87
- appId,
88
- title,
89
- packageName,
90
- author,
341
+ json,
91
342
  });
92
343
  break;
93
- case 'doctor':
94
- doctorAppScaffold(process.cwd(), {
344
+ case 'sync':
345
+ syncApp(process.cwd(), {
95
346
  dir,
96
347
  json,
97
348
  });
98
349
  break;
99
- case 'update':
100
- updateAppScaffold(process.cwd(), {
350
+ case 'check':
351
+ await checkApp(process.cwd(), {
101
352
  dir,
353
+ conformance,
354
+ production,
102
355
  json,
103
356
  });
104
357
  break;
358
+ case 'test':
359
+ testApp(process.cwd(), { dir, json });
360
+ break;
361
+ case 'build':
362
+ buildApp(process.cwd(), { dir, target, production, json });
363
+ break;
364
+ case 'pack':
365
+ if (aggregate && (target || production)) throw new Error('--aggregate cannot be combined with --target or --production');
366
+ {
367
+ const result = packApp(process.cwd(), { dir, target, aggregate, production });
368
+ if (json) process.stdout.write(`${JSON.stringify(result, null, 2)}\n`);
369
+ else process.stdout.write(`[nimi-app] pack ${aggregate ? 'aggregate' : target} completed\n`);
370
+ }
371
+ break;
372
+ case 'dev':
373
+ await runDevShell(process.cwd(), {
374
+ dir,
375
+ shell: shell || 'electron',
376
+ cdpPort,
377
+ noCdp,
378
+ });
379
+ break;
105
380
  default:
106
381
  throw new Error(`Unknown command: ${command}`);
107
382
  }
108
383
  } catch (error) {
109
384
  const message = error instanceof Error ? error.message : String(error || 'unknown error');
110
- process.stderr.write(`[nimi-app] failed: ${message}\n`);
385
+ if (parsedArgs?.json) {
386
+ process.stdout.write(`${JSON.stringify({
387
+ ok: false,
388
+ command: parsedArgs.command || null,
389
+ error: { message },
390
+ }, null, 2)}\n`);
391
+ } else {
392
+ process.stderr.write(`[nimi-app] failed: ${message}\n`);
393
+ }
111
394
  process.exit(1);
112
395
  }
@@ -0,0 +1,49 @@
1
+ import { parse as parseYaml } from 'yaml';
2
+
3
+ export const APP_ACCESS_DOMAINS = Object.freeze([
4
+ 'realm.data',
5
+ 'runtime.consume',
6
+ 'agent.local',
7
+ 'agent.configure',
8
+ ]);
9
+
10
+ const SUPPORTED_APP_ACCESS_DOMAINS = new Set(APP_ACCESS_DOMAINS);
11
+ const MAX_ITEM_BYTES = 128;
12
+
13
+ export function normalizeAppAccessItems(input) {
14
+ const source = input === undefined ? [] : input;
15
+ if (!Array.isArray(source)) throw new Error('App access declaration must be an array');
16
+ const seen = new Set();
17
+ return source.map((item, index) => {
18
+ if (typeof item !== 'string' || item.length === 0 || item !== item.trim() || Buffer.byteLength(item, 'utf8') > MAX_ITEM_BYTES) {
19
+ throw new Error(`Invalid App access declaration item ${index}`);
20
+ }
21
+ if (seen.has(item)) throw new Error(`Duplicate App access declaration item: ${item}`);
22
+ seen.add(item);
23
+ return item;
24
+ });
25
+ }
26
+
27
+ export function resolveAppAccessDeclaration(input) {
28
+ const rawItems = normalizeAppAccessItems(input);
29
+ return {
30
+ rawItems,
31
+ activatedDomains: rawItems.filter((item) => SUPPORTED_APP_ACCESS_DOMAINS.has(item)),
32
+ };
33
+ }
34
+
35
+ export function assertManifestAppAccessDeclaration(manifest, manifestPath) {
36
+ let parsed;
37
+ try {
38
+ parsed = parseYaml(manifest);
39
+ } catch (error) {
40
+ throw new Error(`Submitted manifest YAML cannot be parsed: ${error instanceof Error ? error.message : String(error)}`);
41
+ }
42
+ if (!Object.hasOwn(parsed || {}, 'app_access')) {
43
+ throw new Error('Submitted manifest app_access declaration is required');
44
+ }
45
+ normalizeAppAccessItems(parsed.app_access);
46
+ if (!manifestPath.endsWith('nimi.app.yaml')) {
47
+ throw new Error('Submitted App access declaration was not read from nimi.app.yaml');
48
+ }
49
+ }