@nimiplatform/app-tools 0.14.0 → 0.16.0-rc.9

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 (96) hide show
  1. package/README.md +48 -5
  2. package/bin/nimi-app.mjs +26 -10
  3. package/lib/app-access-declaration.mjs +3 -0
  4. package/lib/app-dependency-combinations.mjs +70 -24
  5. package/lib/app-doctor-update.mjs +92 -36
  6. package/lib/app-host-support.mjs +6 -0
  7. package/lib/app-identifiers.mjs +27 -0
  8. package/lib/app-lifecycle-guidance.mjs +1 -1
  9. package/lib/app-pack.mjs +14 -36
  10. package/lib/app-project-lifecycle.mjs +141 -243
  11. package/lib/app-scaffold-capabilities.mjs +13 -109
  12. package/lib/app-scaffold-profiles.mjs +81 -115
  13. package/lib/app-scaffold.mjs +68 -164
  14. package/lib/app-toolchain-updates.mjs +45 -0
  15. package/lib/canonical-capability-ids.generated.mjs +2 -0
  16. package/lib/development-environment.d.mts +10 -0
  17. package/lib/development-environment.mjs +39 -0
  18. package/lib/hosted-web-release.mjs +98 -0
  19. package/lib/index.mjs +40 -1
  20. package/lib/mobile-development.mjs +19 -0
  21. package/lib/realm-environments.generated.mjs +5 -0
  22. package/lib/web-coordination.mjs +59 -0
  23. package/lib/web-development.d.mts +23 -0
  24. package/lib/web-development.mjs +118 -0
  25. package/lib/web-scaffold.mjs +125 -0
  26. package/package.json +32 -21
  27. package/scripts/dev-shell.mjs +4 -1
  28. package/scripts/sync-scaffold-versions.mjs +0 -2
  29. package/skills/nimi-app-lifecycle/SKILL.md +3 -1
  30. package/skills/nimi-app-lifecycle/references/acceptance.md +6 -2
  31. package/skills/nimi-app-lifecycle/references/adapt.md +5 -3
  32. package/skills/nimi-app-lifecycle/references/audit.md +3 -2
  33. package/skills/nimi-app-lifecycle/references/create.md +6 -2
  34. package/skills/nimi-app-lifecycle/references/upgrade-platform.md +12 -7
  35. package/templates/app-source/src/ai-studio-core/ai-studio-core.css +87 -52
  36. package/templates/app-source/src/ai-studio-core/history-policy.ts +45 -11
  37. package/templates/app-source/src/ai-studio-core/history.ts +22 -11
  38. package/templates/app-source/src/ai-studio-core/host-context.tsx +9 -4
  39. package/templates/app-source/src/ai-studio-core/index.ts +2 -0
  40. package/templates/app-source/src/ai-studio-core/job-recovery-panel.tsx +15 -5
  41. package/templates/app-source/src/ai-studio-core/job-recovery.ts +2 -2
  42. package/templates/app-source/src/ai-studio-core/messages/en.json +73 -19
  43. package/templates/app-source/src/ai-studio-core/messages/zh.json +73 -19
  44. package/templates/app-source/src/ai-studio-core/module-registration.ts +1 -0
  45. package/templates/app-source/src/ai-studio-core/non-success-presentation.ts +30 -5
  46. package/templates/app-source/src/ai-studio-core/parameter-fields.tsx +12 -6
  47. package/templates/app-source/src/ai-studio-core/parameters.ts +4 -0
  48. package/templates/app-source/src/ai-studio-core/prompt-drafts.ts +42 -0
  49. package/templates/app-source/src/ai-studio-core/runtime-types.ts +9 -2
  50. package/templates/app-source/src/ai-studio-core/runtime.ts +8 -4
  51. package/templates/app-source/src/ai-studio-core/section-ai-testing-composer.tsx +98 -90
  52. package/templates/app-source/src/ai-studio-core/section-ai-testing-exchange-result.tsx +1 -1
  53. package/templates/app-source/src/ai-studio-core/section-ai-testing-history.tsx +205 -48
  54. package/templates/app-source/src/ai-studio-core/section-ai-testing-input.ts +1 -0
  55. package/templates/app-source/src/ai-studio-core/section-ai-testing-output.tsx +36 -14
  56. package/templates/app-source/src/ai-studio-core/section-ai-testing-result.tsx +96 -75
  57. package/templates/app-source/src/ai-studio-core/section-ai-testing-run.ts +59 -16
  58. package/templates/app-source/src/ai-studio-core/section-ai-testing-session-result.tsx +2 -0
  59. package/templates/app-source/src/ai-studio-core/section-ai-testing-studio-result.tsx +12 -21
  60. package/templates/app-source/src/ai-studio-core/section-ai-testing-transcription-result.tsx +2 -2
  61. package/templates/app-source/src/ai-studio-core/section-ai-testing-vision-result.tsx +3 -3
  62. package/templates/app-source/src/ai-studio-core/section-ai-testing.tsx +158 -76
  63. package/templates/app-source/src/ai-studio-core/workspace.tsx +49 -22
  64. package/templates/app-source/src/product-modules/agent-center/index.tsx +2 -3
  65. package/templates/app-source/src/product-modules/agent-conversation/index.tsx +2 -3
  66. package/templates/app-source/src/studio-modules/studio-create/messages/en.json +12 -3
  67. package/templates/app-source/src/studio-modules/studio-create/messages/zh.json +12 -3
  68. package/templates/app-source/src/studio-modules/studio-create/parameter-panel.tsx +11 -2
  69. package/templates/app-source/src/studio-modules/studio-create/parameters.ts +2 -1
  70. package/templates/app-source/src/studio-modules/studio-create/runtime.ts +47 -5
  71. package/templates/app-source/src/studio-modules/studio-media/messages/en.json +59 -8
  72. package/templates/app-source/src/studio-modules/studio-media/messages/zh.json +59 -8
  73. package/templates/app-source/src/studio-modules/studio-media/music-parameters.tsx +2 -1
  74. package/templates/app-source/src/studio-modules/studio-media/parameter-panel.tsx +271 -83
  75. package/templates/app-source/src/studio-modules/studio-media/parameters.ts +120 -2
  76. package/templates/app-source/src/studio-modules/studio-media/registration.ts +1 -0
  77. package/templates/app-source/src/studio-modules/studio-media/runtime.ts +24 -14
  78. package/templates/app-source/src/studio-modules/studio-voice/descriptors.ts +1 -1
  79. package/templates/app-source/src/studio-modules/studio-voice/messages/en.json +3 -2
  80. package/templates/app-source/src/studio-modules/studio-voice/messages/zh.json +3 -2
  81. package/templates/app-source/src/studio-modules/studio-voice/parameter-panel.tsx +46 -23
  82. package/templates/app-source/src/studio-modules/studio-voice/registration.ts +2 -1
  83. package/templates/app-source/src/studio-modules/studio-voice/runtime.ts +2 -2
  84. package/templates/app-source/src/workbench-core/workbench-core.tsx +27 -3
  85. package/templates/default-starter/AGENTS.md +3 -3
  86. package/templates/default-starter/README.md +1 -1
  87. package/templates/default-starter/src/shell/App.tsx +6 -18
  88. package/templates/default-starter/src/shell/auth/local-app-client.ts +6 -15
  89. package/templates/default-starter/src/shell/auth/runtime-platform.ts +7 -107
  90. package/templates/default-starter/src/shell/workbench-target-adapter.ts +9 -126
  91. package/templates/default-starter.manifest.json +0 -16
  92. package/templates/hosted-web-release.yml +88 -0
  93. package/templates/default-starter/src-tauri/Cargo.toml +0 -17
  94. package/templates/default-starter/src-tauri/build.rs +0 -32
  95. package/templates/default-starter/src-tauri/capabilities/default.json +0 -7
  96. package/templates/default-starter/src-tauri/tauri.conf.json +0 -26
@@ -0,0 +1,98 @@
1
+ import { readdir, readFile, writeFile } from 'node:fs/promises';
2
+ import path from 'node:path';
3
+ import { writeNimiAppArchive } from './app-pack.mjs';
4
+ import { hostedWebIdentity } from './app-identifiers.mjs';
5
+ import { resolveDevelopmentRealm } from './development-environment.mjs';
6
+
7
+ const versionPattern =
8
+ /^(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/u;
9
+
10
+ // @nimi-authority: rule.nimi.platform.app-ecosystem.hosted-web-publication
11
+ export function hostedWebViteConfig(manifest, env) {
12
+ const identity = hostedWebIdentity(manifest.app_id, manifest.public_slug, env.NIMI_WEB_CLIENT_ID);
13
+ const official = resolveDevelopmentRealm('official');
14
+ const version = env.NIMI_WEB_VERSION ?? manifest.version;
15
+ if (typeof version !== 'string' || version.length > 120 || !versionPattern.test(version))
16
+ throw new Error('Invalid Web release version.');
17
+ const config = {
18
+ appId: identity.appId,
19
+ clientId: identity.clientId,
20
+ realmEnvironmentId: official.environmentId,
21
+ officialWebBaseUrl: official.webOrigin,
22
+ realmBaseUrl: identity.origin,
23
+ redirectUri: identity.redirectUri,
24
+ };
25
+ for (const [key, expected] of Object.entries({
26
+ NIMI_WEB_ORIGIN: identity.origin,
27
+ NIMI_WEB_CLIENT_ID: config.clientId,
28
+ NIMI_WEB_REDIRECT_URI: config.redirectUri,
29
+ NIMI_WEB_REALM_ENVIRONMENT_ID: config.realmEnvironmentId,
30
+ NIMI_WEB_OFFICIAL_WEB_URL: config.officialWebBaseUrl,
31
+ })) {
32
+ if (env[key] !== undefined && env[key] !== expected)
33
+ throw new Error(key + ' conflicts with hosted Web identity.');
34
+ }
35
+ const info = {
36
+ format: 'nimi.web-bundle/v1',
37
+ app_id: identity.appId,
38
+ slug: identity.slug,
39
+ version,
40
+ client_id: config.clientId,
41
+ origin: identity.origin,
42
+ redirect_uri: config.redirectUri,
43
+ official_web_url: config.officialWebBaseUrl,
44
+ realm_environment_id: config.realmEnvironmentId,
45
+ entry: 'index.html',
46
+ app_access: manifest.app_access,
47
+ capability_contract_refs: manifest.capability_contract_refs ?? [],
48
+ };
49
+ return {
50
+ base: '/',
51
+ define: { __NIMI_APP_WEB_CONFIG__: JSON.stringify(config) },
52
+ build: { assetsDir: '_releases/' + version + '/assets' },
53
+ plugins: [
54
+ {
55
+ name: 'nimi-hosted-web-release',
56
+ async writeBundle(options) {
57
+ if (env.NIMI_WEB_ARCHIVE) {
58
+ if (!options.dir) throw new Error('Hosted Web packaging requires one static output directory.');
59
+ await packHostedWeb(options.dir, env.NIMI_WEB_ARCHIVE);
60
+ }
61
+ },
62
+ generateBundle() {
63
+ this.emitFile({
64
+ type: 'asset',
65
+ fileName: 'nimi-web-bundle.json',
66
+ source: JSON.stringify(info, null, 2) + '\n',
67
+ });
68
+ },
69
+ },
70
+ ],
71
+ };
72
+ }
73
+
74
+ export async function packHostedWeb(directory, outputFile) {
75
+ const root = path.resolve(directory);
76
+ if (path.resolve(outputFile).startsWith(root + path.sep))
77
+ throw new Error('Write the archive outside the static directory.');
78
+ const entries = [];
79
+ async function collect(relative) {
80
+ for (const item of await readdir(path.join(root, relative), { withFileTypes: true })) {
81
+ const name = relative ? relative + '/' + item.name : item.name;
82
+ if (/^(?:_headers|_redirects|_routes\.json|_worker\.js|wrangler\.[^/]+|functions)(?:\/|$)/iu.test(name))
83
+ continue;
84
+ if (/^(?:\.git|\.env(?:\..*)?)(?:\/|$)/u.test(name))
85
+ throw new Error('Private working files cannot be hosted: ' + name);
86
+ if (item.isDirectory()) await collect(name);
87
+ else if (item.isFile()) entries.push({ name, bytes: await readFile(path.join(root, name)) });
88
+ else throw new Error('Unsupported file in hosted Web bundle: ' + name);
89
+ }
90
+ }
91
+ await collect('');
92
+ if (
93
+ !entries.some((e) => e.name === 'index.html') ||
94
+ !entries.some((e) => e.name === 'nimi-web-bundle.json')
95
+ )
96
+ throw new Error('Missing hosted Web entry or release manifest.');
97
+ await writeFile(outputFile, writeNimiAppArchive(entries), { flag: 'wx' });
98
+ }
package/lib/index.mjs CHANGED
@@ -19,7 +19,12 @@ import {
19
19
  validateAppInitialization,
20
20
  } from './app-project-lifecycle.mjs';
21
21
  import { aggregateAppTargetCandidates, packAppTarget } from './app-pack.mjs';
22
- export { runDevShell } from '../scripts/dev-shell.mjs';
22
+ import { runDevShell } from '../scripts/dev-shell.mjs';
23
+ export { runDevShell };
24
+ import { parse as parseYaml } from 'yaml';
25
+ import { readWebDevelopment } from './web-development.mjs';
26
+ import { readMobileDevelopment } from './mobile-development.mjs';
27
+ import { resolveDevelopmentRealm, developmentRealmEnvironment } from './development-environment.mjs';
23
28
  export { APP_SCAFFOLD_FEATURE_IDS } from './app-scaffold-capabilities.mjs';
24
29
 
25
30
  const APP_TOOLS_PACKAGE_MANIFEST = JSON.parse(
@@ -106,6 +111,8 @@ function runAppCommand(targetDir, command, options = {}) {
106
111
  shell: true,
107
112
  encoding: 'utf8',
108
113
  stdio: options.capture ? 'pipe' : 'inherit',
114
+ env: options.env ?? process.env,
115
+ windowsHide: true,
109
116
  });
110
117
  return {
111
118
  status: result.status ?? 1,
@@ -125,6 +132,7 @@ export function createApp(cwd, options = {}) {
125
132
  options: {
126
133
  dir: options.dir,
127
134
  profile: options.profile,
135
+ platform: options.platform,
128
136
  appId: options.appId,
129
137
  name: options.name,
130
138
  title: options.title,
@@ -212,7 +220,38 @@ export function buildApp(cwd, options = {}) {
212
220
  }
213
221
 
214
222
  export function packApp(cwd, options = {}) {
223
+ const manifest = parseYaml(readFileSync(path.join(path.resolve(cwd, options.dir || '.'), 'nimi.app.yaml'), 'utf8'));
224
+ if (manifest.platform === 'web') throw new Error('Web pack is not implemented; use the App-owned website build and deployment process.');
215
225
  return options.aggregate
216
226
  ? aggregateAppTargetCandidates(cwd, options)
217
227
  : packAppTarget(cwd, options);
218
228
  }
229
+
230
+ // @nimi-authority: rule.nimi.platform.app-ecosystem.scaffold-web-carrier
231
+ // @nimi-authority: rule.nimi.platform.app-ecosystem.mobile-development-entry
232
+ export async function runAppDevelopment(cwd, options = {}) {
233
+ const root = path.resolve(cwd, options.dir || '.');
234
+ if (!existsSync(path.join(root, 'nimi.app.yaml'))) throw new Error('nimi.app.yaml is required for App development.');
235
+ const manifest = parseYaml(readFileSync(path.join(root, 'nimi.app.yaml'), 'utf8'));
236
+ const platform = options.platform || manifest.platform || 'desktop';
237
+ if (!['desktop', 'web', 'mobile'].includes(platform)) throw new Error(`Unsupported App development platform: ${platform}`);
238
+ if (platform === 'desktop') return runDevShell(cwd, options);
239
+ if (options.shell || options.cdpPort !== undefined || options.noCdp || options.resume || options.newRegistration || options.listRegistrations) {
240
+ throw new Error('Desktop shell, registration and CDP launch options do not apply to remote Web or Mobile dev.');
241
+ }
242
+ const pkg = JSON.parse(readFileSync(path.join(root, 'package.json'), 'utf8'));
243
+ const selectedRealm = resolveDevelopmentRealm(options.realm || undefined);
244
+ const environment = { ...process.env, ...developmentRealmEnvironment(selectedRealm) };
245
+ if (platform === 'mobile') {
246
+ const mobile = readMobileDevelopment(manifest, pkg);
247
+ process.stdout.write('[nimi-app] Running the App-owned mobile command; native source admission and verified OS callback remain required.\n');
248
+ const result = runAppCommand(root, mobile.command, { env: environment });
249
+ if (result.status !== 0) throw new Error(`Mobile development command exited with ${result.status}: ${result.stderr}`);
250
+ return;
251
+ }
252
+ const web = readWebDevelopment(manifest, { realm: selectedRealm.name, env: environment });
253
+ if (!pkg.scripts?.[web.script] || /\bnimi-app\s+dev\b/u.test(pkg.scripts[web.script])) throw new Error('Web dev requires a real, non-recursive App-owned renderer script.');
254
+ process.stdout.write(`[nimi-app] Web source: ${web.site.origin}; official sign-in and first Home source confirmation are required.\n`);
255
+ const result = runAppCommand(root, web.command, { env: environment });
256
+ if (result.status !== 0) throw new Error(`Web development command exited with ${result.status}: ${result.stderr}`);
257
+ }
@@ -0,0 +1,19 @@
1
+ import { isAppId } from './app-identifiers.mjs';
2
+ // @nimi-authority: rule.nimi.platform.app-ecosystem.mobile-development-entry
3
+ export function readMobileDevelopment(manifest, pkg) {
4
+ const mobile = manifest?.local_development?.mobile;
5
+ if (!mobile || typeof mobile !== 'object' || Array.isArray(mobile)
6
+ || Object.keys(mobile).some(key => key !== 'command')) {
7
+ throw new Error('Declare an App-owned local_development.mobile.command in nimi.app.yaml.');
8
+ }
9
+ if (typeof manifest.app_id !== 'string' || !isAppId(manifest.app_id)) {
10
+ throw new Error('Mobile development requires a canonical App id.');
11
+ }
12
+ const match = typeof mobile.command === 'string' && /^pnpm run ([A-Za-z0-9][A-Za-z0-9:_.-]*)$/u.exec(mobile.command);
13
+ if (!match) throw new Error('Mobile command must name an App-owned pnpm script.');
14
+ const command = pkg?.scripts?.[match[1]];
15
+ if (typeof command !== 'string' || !command.trim() || /\bnimi-app\s+dev\b/u.test(command)) {
16
+ throw new Error('Mobile dev requires a real, non-recursive App-owned native script.');
17
+ }
18
+ return { command: mobile.command, script: match[1] };
19
+ }
@@ -0,0 +1,5 @@
1
+ // Generated by scripts/generate-development-realms.mjs.
2
+ export const REALM_PROFILES = Object.freeze({
3
+ official: Object.freeze({"apiOrigin":"https://realm.nimi.ai","realtimeOrigin":"https://realm.nimi.ai","webOrigin":"https://nimi.ai","environmentId":"production"}),
4
+ local: Object.freeze({"apiOrigin":"http://127.0.0.1:3002","realtimeOrigin":"http://127.0.0.1:3003","webOrigin":"http://localhost:3000","environmentId":"dev"}),
5
+ });
@@ -0,0 +1,59 @@
1
+ // @nimi-authority: rule.nimi.platform.app-ecosystem.scaffold-web-carrier
2
+ export function isWebCoordinationPath(method, pathname) {
3
+ if (method === 'GET') {
4
+ return pathname === '/api/runtime-access/context'
5
+ || /^\/api\/runtime-access\/connections\/[A-Za-z0-9_-]+$/u.test(pathname)
6
+ || /^\/api\/auth\/runtime-clients\/[A-Za-z0-9_.-]+$/u.test(pathname);
7
+ }
8
+ return method === 'POST' && (pathname === '/api/runtime-access/token'
9
+ || pathname === '/api/runtime-access/context/end'
10
+ || pathname === '/api/runtime-access/connections');
11
+ }
12
+
13
+ function httpsOrigin(value) {
14
+ try {
15
+ const url = new URL(value);
16
+ return url.protocol === 'https:' && url.origin === value ? url.origin : undefined;
17
+ } catch {
18
+ return undefined;
19
+ }
20
+ }
21
+
22
+ function reject(message, status) {
23
+ return new Response(message, { status, headers: { 'Cache-Control': 'no-store' } });
24
+ }
25
+
26
+ export async function handleNimiWebCoordination({ request, env }) {
27
+ const source = new URL(request.url);
28
+ if (!isWebCoordinationPath(request.method, source.pathname)) return reject('Not found', 404);
29
+
30
+ const site = httpsOrigin(env.NIMI_WEB_ORIGIN);
31
+ const realm = httpsOrigin(env.NIMI_REALM_URL);
32
+ if (!site || !realm || site === realm) return reject('Coordination is not configured', 503);
33
+ const origin = request.headers.get('origin');
34
+ if (source.origin !== site || (origin !== null && origin !== site)) return reject('Origin is not allowed', 403);
35
+
36
+ const headers = new Headers();
37
+ for (const name of ['accept', 'authorization', 'content-type', 'origin']) {
38
+ const value = request.headers.get(name);
39
+ if (value !== null) headers.set(name, value);
40
+ }
41
+ const target = new URL(source.pathname + source.search, realm);
42
+ let upstream;
43
+ try {
44
+ upstream = await fetch(target, { method: request.method, headers, body: request.body, redirect: 'manual' });
45
+ } catch {
46
+ return reject('Realm coordination is unavailable', 502);
47
+ }
48
+ if (upstream.status >= 300 && upstream.status < 400) {
49
+ await upstream.body?.cancel();
50
+ return reject('Unexpected coordination redirect', 502);
51
+ }
52
+
53
+ const responseHeaders = new Headers({ 'Cache-Control': 'no-store' });
54
+ for (const name of ['content-type', 'retry-after']) {
55
+ const value = upstream.headers.get(name);
56
+ if (value !== null) responseHeaders.set(name, value);
57
+ }
58
+ return new Response(upstream.body, { status: upstream.status, headers: responseHeaders });
59
+ }
@@ -0,0 +1,23 @@
1
+ import type { IncomingMessage, ServerResponse } from 'node:http';
2
+ import type { UserConfig } from 'vite';
3
+
4
+ export interface NimiWebClientConfig {
5
+ readonly appId: string;
6
+ readonly clientId: string;
7
+ readonly realmEnvironmentId: string;
8
+ readonly officialWebBaseUrl: string;
9
+ readonly realmBaseUrl: string;
10
+ readonly redirectUri: string;
11
+ }
12
+ export function readWebDevelopment(manifest: unknown, options?: { realm?: 'official' | 'local'; env?: Record<string, string | undefined> }): Readonly<{
13
+ site: URL; realm: URL; official: URL; command: string; script: string;
14
+ config: Readonly<NimiWebClientConfig>;
15
+ }>;
16
+ export function isWebCoordinationPath(method: string, url: string): boolean;
17
+ export function webOriginGuard(site: URL): (request: IncomingMessage, response: ServerResponse, next: () => void) => void;
18
+ export function nimiWebViteConfig(options: {
19
+ root: string;
20
+ env?: Record<string, string | undefined>;
21
+ serve?: boolean;
22
+ release?: boolean;
23
+ }): UserConfig;
@@ -0,0 +1,118 @@
1
+ // @nimi-authority: rule.nimi.platform.app-ecosystem.scaffold-web-carrier
2
+ import { isAppId, isClientId } from './app-identifiers.mjs';
3
+ import { hostedWebViteConfig } from './hosted-web-release.mjs';
4
+ import { readFileSync } from 'node:fs';
5
+ import path from 'node:path';
6
+ import { parse as parseYaml } from 'yaml';
7
+ import { isWebCoordinationPath as isCoordinationPath } from './web-coordination.mjs';
8
+ import { resolveDevelopmentRealm } from './development-environment.mjs';
9
+
10
+ function exactOrigin(value, label, requireHttps = false) {
11
+ let url;
12
+ try { url = new URL(value); } catch { throw new Error(`${label} must be an exact origin.`); }
13
+ if (url.origin !== value || url.username || url.password
14
+ || (url.protocol !== 'https:' && !(url.protocol === 'http:' && !requireHttps && ['localhost', '127.0.0.1', '[::1]'].includes(url.hostname)))) {
15
+ throw new Error(`${label} requires HTTPS (HTTP is allowed only for loopback coordination).`);
16
+ }
17
+ return url;
18
+ }
19
+
20
+ function readWebSource(appId, web, release = false) {
21
+ const site = exactOrigin(web.origin, 'Web origin', true);
22
+ const official = exactOrigin(web.official_web_url, 'Official Web URL', release);
23
+ if (release && [site, official].some(url => /^(?:localhost|.+\.localhost|127\.\d+\.\d+\.\d+|\[::1\])$/u.test(url.hostname))) {
24
+ throw new Error('Web release requires deployed HTTPS origins.');
25
+ }
26
+ if (site.hostname === official.hostname) throw new Error('Use different hostnames for the App and official sign-in; ports do not isolate cookies.');
27
+ const callback = new URL(web.redirect_uri);
28
+ if (callback.origin !== site.origin || callback.username || callback.password || callback.search || callback.hash || callback.href !== web.redirect_uri) {
29
+ throw new Error('Web callback must be an exact URL on the configured HTTPS App origin.');
30
+ }
31
+ if (!isAppId(appId)) throw new Error('Invalid Web app_id.');
32
+ if (!isClientId(web.client_id)) throw new Error('Invalid Web client_id.');
33
+ if (typeof web.realm_environment_id !== 'string' || !/^[A-Za-z0-9][A-Za-z0-9_.-]{0,127}$/u.test(web.realm_environment_id)) throw new Error('Invalid Web realm_environment_id.');
34
+ return { site, official, config: Object.freeze({
35
+ appId, clientId: web.client_id, realmEnvironmentId: web.realm_environment_id,
36
+ officialWebBaseUrl: official.origin, realmBaseUrl: site.origin, redirectUri: callback.href,
37
+ }) };
38
+ }
39
+
40
+ export function readWebDevelopment(manifest, options = {}) {
41
+ const declaration = manifest?.local_development?.web;
42
+ if (!declaration || typeof declaration !== 'object' || Array.isArray(declaration)) throw new Error('Declare local_development.web in nimi.app.yaml.');
43
+ const selected = resolveDevelopmentRealm(options.realm, options.env);
44
+ const sourceInput = selected.name === 'official' ? declaration : declaration.local;
45
+ if (!sourceInput || typeof sourceInput !== 'object' || Array.isArray(sourceInput)) throw new Error('Declare local_development.web.local for local Realm development.');
46
+ const web = { realm_url: selected.apiOrigin, official_web_url: selected.webOrigin, realm_environment_id: selected.environmentId, ...sourceInput, command: declaration.command };
47
+ if (!web.origin || !web.redirect_uri || !web.client_id) throw new Error(`Configure the exact registered ${selected.name} Web origin, redirect_uri and client_id in nimi.app.yaml; a scaffold is not source admission.`);
48
+ if (selected.name === 'official' && (web.realm_url !== selected.apiOrigin || web.official_web_url !== selected.webOrigin || web.realm_environment_id !== selected.environmentId)) {
49
+ throw new Error('Official Web development must use official Realm configuration; select --realm local for local inputs.');
50
+ }
51
+ const source = readWebSource(manifest.app_id, web);
52
+ const realm = exactOrigin(web.realm_url, 'Realm URL');
53
+ const match = typeof web.command === 'string' && /^pnpm run ([A-Za-z0-9][A-Za-z0-9:_.-]*)$/u.exec(web.command);
54
+ if (!match) throw new Error('Web command must name an App-owned pnpm script.');
55
+ return Object.freeze({ ...source, realm, command: web.command, script: match[1] });
56
+ }
57
+
58
+ export function isWebCoordinationPath(method, url) {
59
+ return isCoordinationPath(method, url.split('?')[0]);
60
+ }
61
+
62
+ export function webOriginGuard(site) {
63
+ return (request, response, next) => {
64
+ const h1 = request.headers.host;
65
+ const host = request.headers[':authority'] ?? h1;
66
+ if (typeof host !== 'string' || host.toLowerCase() !== site.host
67
+ || (h1 !== undefined && (typeof h1 !== 'string' || h1.toLowerCase() !== site.host))) {
68
+ response.writeHead(421, { 'Content-Type': 'text/plain', 'Cache-Control': 'no-store' });
69
+ response.end('Use the configured App origin.'); return;
70
+ }
71
+ if (request.url?.startsWith('/api/') && !isWebCoordinationPath(request.method, request.url)) {
72
+ response.writeHead(404); response.end(); return;
73
+ }
74
+ next();
75
+ };
76
+ }
77
+
78
+ /** Vite configuration for a declared source. Release hosting owns the same
79
+ * bounded coordination routes independently of the development server. */
80
+ export function nimiWebViteConfig({ root, env = process.env, serve = true, release = false }) {
81
+ const manifest = parseYaml(readFileSync(path.join(root, 'nimi.app.yaml'), 'utf8'));
82
+ if (release) {
83
+ if (serve) throw new Error('Web release configuration requires a build.');
84
+ if (Object.hasOwn(manifest, 'public_slug')) return hostedWebViteConfig(manifest, env);
85
+ const required = key => {
86
+ const value = env[key];
87
+ if (typeof value !== 'string' || !value || value !== value.trim()) throw new Error(`Set ${key} for the Web release.`);
88
+ return value;
89
+ };
90
+ const { config } = readWebSource(manifest.app_id, {
91
+ origin: required('NIMI_WEB_ORIGIN'),
92
+ redirect_uri: required('NIMI_WEB_REDIRECT_URI'),
93
+ client_id: required('NIMI_WEB_CLIENT_ID'),
94
+ realm_environment_id: required('NIMI_WEB_REALM_ENVIRONMENT_ID'),
95
+ official_web_url: required('NIMI_WEB_OFFICIAL_WEB_URL'),
96
+ }, true);
97
+ return { define: { __NIMI_APP_WEB_CONFIG__: JSON.stringify(config) } };
98
+ }
99
+ const { site, realm, config } = readWebDevelopment(manifest, { env });
100
+ const define = { __NIMI_APP_WEB_CONFIG__: JSON.stringify(config) };
101
+ if (!serve) return { define };
102
+ if (!env.NIMI_WEB_TLS_KEY || !env.NIMI_WEB_TLS_CERT) throw new Error('Set NIMI_WEB_TLS_KEY and NIMI_WEB_TLS_CERT to browser-trusted certificate files.');
103
+ return {
104
+ define,
105
+ server: {
106
+ host: env.NIMI_WEB_BIND_HOST || '127.0.0.1', port: Number(site.port || 443), strictPort: true,
107
+ https: { key: readFileSync(path.resolve(root, env.NIMI_WEB_TLS_KEY)), cert: readFileSync(path.resolve(root, env.NIMI_WEB_TLS_CERT)) },
108
+ proxy: { '^/api/(runtime-access/|auth/runtime-clients/)': {
109
+ target: realm.origin, changeOrigin: true,
110
+ configure(proxy) {
111
+ proxy.on('proxyReq', request => request.removeHeader('cookie'));
112
+ proxy.on('proxyRes', response => { delete response.headers['set-cookie']; });
113
+ },
114
+ } },
115
+ },
116
+ plugins: [{ name: 'nimi-web-origin', enforce: 'pre', configureServer(server) { server.middlewares.use(webOriginGuard(site)); } }],
117
+ };
118
+ }
@@ -0,0 +1,125 @@
1
+ // @nimi-authority: rule.nimi.platform.app-ecosystem.scaffold-web-carrier
2
+ import { REALM_PROFILES } from './realm-environments.generated.mjs';
3
+ export const WEB_BASE_TEMPLATE_PATHS = new Set([
4
+ '.gitattributes', 'index.html', 'SECURITY.md',
5
+ 'src/shell/auth/app-identity.ts', 'src/shell/authenticated-shell.tsx', 'src/styles.css', 'tsconfig.json',
6
+ ]);
7
+
8
+ const managed = (path, content) => ({ path, content, mutationClass: 'scaffold-managed glue' });
9
+
10
+ export function webDevelopmentInput(identity) {
11
+ const realm = REALM_PROFILES.official;
12
+ // A port hash and a guessed client id are not a registered browser source.
13
+ return { origin: '', redirect_uri: '', client_id: '',
14
+ realm_environment_id: realm.environmentId, realm_url: realm.apiOrigin, official_web_url: realm.webOrigin,
15
+ command: 'pnpm run dev:web-renderer' };
16
+ }
17
+
18
+ export function webBuildProfile() {
19
+ return { build_profile_ref: 'web-pnpm', test_command: 'pnpm run test:app', build_command: 'pnpm run build',
20
+ output_path: 'dist', lockfile_path: 'pnpm-lock.yaml', lockfile_policy: 'author-install-generates-lockfile',
21
+ ci_install_command: 'pnpm install --frozen-lockfile', targets: { web: { build_command: 'pnpm run build', payload_path: 'dist', runtime_entry: 'payload/index.html' } },
22
+ profile_role: 'developer-workflow-input' };
23
+ }
24
+
25
+ export function webPackage(pkg) {
26
+ const { main: _main, ...result } = pkg;
27
+ for (const name of ['@electron/packager', 'electron', 'pngjs']) delete result.devDependencies[name];
28
+ result.pnpm = { onlyBuiltDependencies: ['esbuild'] };
29
+ result.scripts = { dev: 'nimi-app dev --platform web', 'dev:web-renderer': 'vite',
30
+ init: 'nimi-app init', sync: 'nimi-app sync', check: 'nimi-app check', test: 'nimi-app test',
31
+ 'test:app': 'tsc --noEmit', 'app:build': 'nimi-app build', typecheck: 'tsc --noEmit', build: 'tsc --noEmit && vite build',
32
+ 'build:release': 'tsc --noEmit && vite build --mode web-release' };
33
+ return result;
34
+ }
35
+
36
+ export function webDependencyMatrix(matrix) {
37
+ for (const name of ['@electron/packager', 'electron', 'pngjs']) delete matrix.npm[name];
38
+ return matrix;
39
+ }
40
+
41
+ export function buildWebStarterFiles(identity, { productArea, navigation }) {
42
+ return [
43
+ { path: 'NIMI_APP.md', mutationClass: 'app-owned product code', content: '# '+identity.appTitle+'\n\nUse this website to work with the AI capabilities supplied by your primary Nimi Runtime. Sign in on the official Nimi page, keep Nimi Home running on the PC, and confirm this source once in Home. Configure the capabilities needed by the selected App features. Results use the App storage scope; other sources do not automatically share files. Cloud inference follows the Runtime configuration and may incur provider charges.\n' },
44
+ managed('src/main.tsx', WEB_MAIN),
45
+ managed('src/shell/App.tsx', WEB_APP),
46
+ managed('src/shell/auth/local-app-client.ts', WEB_CLIENT),
47
+ managed('src/shell/auth/runtime-platform.ts', WEB_RUNTIME),
48
+ managed('src/shell/web-download.ts', WEB_DOWNLOAD),
49
+ managed('vite.config.ts', WEB_VITE),
50
+ managed('src/shell/routes/product-area.tsx', productArea),
51
+ { ...managed('src/shell/routes/app-navigation.tsx', navigation), mutationClass: 'app-owned product code' },
52
+ { path: 'README.md', mutationClass: 'app-owned product code', content: `# ${identity.appTitle}\n\nBrowser App using the shared Nimi SDK and Kit.\n\nInstall dependencies, run init, then check and dev. Configure the exact HTTPS source and callback in nimi.app.yaml. Set NIMI_WEB_TLS_KEY and NIMI_WEB_TLS_CERT in .env.local to certificate files trusted by your browser. Have this source admitted through the Registry owner and confirm it once in PC Home. These steps do not publish the website.\n\nAI and files travel directly to the user's primary Runtime. The dev server forwards only scoped identity and connection coordination. Production hosting must separately provide those bounded routes. No Relay or native Host is installed in the browser.\n\nThe initial test command typechecks the project; add business tests as the App evolves and run real supported tasks. Build does not certify Runtime use. Web pack and automated publishing are unavailable.\n` },
53
+ { path: 'AGENTS.md', mutationClass: 'app-owned product code', content: '# Web App instructions\n\nUse the shared public SDK and Kit. Keep business state with the App and AI execution with Runtime. This project uses official Runtime-client login and an admitted Web source, never native Host proof or a direct provider fallback. Preserve App-owned product code during sync. Use the declared development, test and build commands. New source admission and first Home confirmation belong to their owners; normal reconnection reuses them. Do not publish or bypass trust prompts as part of development.\n' },
54
+ ];
55
+ }
56
+
57
+ const WEB_VITE = `import { defineConfig, loadEnv, mergeConfig } from 'vite';
58
+ import react from '@vitejs/plugin-react';
59
+ import tailwindcss from '@tailwindcss/vite';
60
+ import { nimiWebViteConfig } from '@nimiplatform/app-tools/web';
61
+ export default defineConfig(({ command, mode }) => mergeConfig({ base: './', plugins: [react(), tailwindcss()],
62
+ server: { watch: { ignored: ['**/.nimi/local/**', '**/.tmp/**'] } },
63
+ resolve: { dedupe: ['react', 'react-dom', 'react/jsx-runtime'] },
64
+ }, nimiWebViteConfig({ root: import.meta.dirname, env: { ...loadEnv(mode, import.meta.dirname, ''), ...process.env }, serve: command === 'serve', release: mode === 'web-release' })));
65
+ `;
66
+
67
+ const WEB_CLIENT = `import type { NimiAppScope } from '@nimiplatform/kit/core/app-session';
68
+ let scope: NimiAppScope | null = null;
69
+ export function setNimiRemoteAppClient(value: NimiAppScope | null) { scope = value; }
70
+ export function getNimiLocalAppClient(): NimiAppScope['client'] {
71
+ if (!scope || scope.signal.aborted) throw new Error('Connect to your primary Runtime before starting work.');
72
+ return scope.client;
73
+ }
74
+ `;
75
+
76
+ const WEB_RUNTIME = `import { getNimiLocalAppClient } from './local-app-client.js';
77
+ export { appId, appTitle, scaffoldProfile } from './app-identity.js';
78
+ export async function getRuntimePlatformProjection() {
79
+ try { getNimiLocalAppClient(); return { status: 'ready' as const, mode: 'remote-app' as const }; }
80
+ catch (error) { return { status: 'unavailable' as const, mode: 'remote-app' as const, message: error instanceof Error ? error.message : String(error) }; }
81
+ }
82
+ `;
83
+
84
+ const WEB_APP = `import { NimiToaster } from '@nimiplatform/kit/ui';
85
+ import { AppNavigationProvider } from './routes/app-navigation.js';
86
+ import { AuthenticatedShell } from './authenticated-shell.js';
87
+ export function App() { return <AppNavigationProvider><AuthenticatedShell /><NimiToaster /></AppNavigationProvider>; }
88
+ `;
89
+
90
+ const WEB_MAIN = `import React from 'react';
91
+ import { createRoot } from 'react-dom/client';
92
+ import { NimiThemeProvider, TooltipProvider } from '@nimiplatform/kit/ui';
93
+ import { createWebNimiAppSession, type NimiRemoteAppConfig } from '@nimiplatform/kit/auth/app/web';
94
+ import { NimiAppSessionProvider, NimiAccountControl, NimiAppAccessGate } from '@nimiplatform/kit/auth/app';
95
+ import { setNimiRemoteAppClient } from './shell/auth/local-app-client.js';
96
+ import { appTitle } from './shell/auth/app-identity.js';
97
+ import { App } from './shell/App.js';
98
+ import './styles.css';
99
+ declare const __NIMI_APP_WEB_CONFIG__: NimiRemoteAppConfig;
100
+ const session = createWebNimiAppSession(__NIMI_APP_WEB_CONFIG__);
101
+ const off = session.subscribe(() => { const state = session.getSnapshot(); setNimiRemoteAppClient(state.runtime.status === 'connected' ? state.runtime.scope : null); });
102
+ const root = document.getElementById('root')!;
103
+ root.classList.add('nimi-workbench-host', 'nimi-ui-module--lab'); document.body.classList.add('nimi-ui-module--lab');
104
+ const reactRoot = createRoot(root);
105
+ reactRoot.render(<React.StrictMode><NimiThemeProvider accentPack="nimi-accent"><TooltipProvider><NimiAppSessionProvider session={session}>
106
+ <div className="flex h-full min-h-0 flex-col"><header className="flex items-center gap-3 border-b p-3"><strong>{appTitle}</strong><NimiAccountControl hideSignedOut language="en" /></header>
107
+ <NimiAppAccessGate title={appTitle} language="en">{() => <main className="min-h-0 flex-1"><App /></main>}</NimiAppAccessGate></div>
108
+ </NimiAppSessionProvider></TooltipProvider></NimiThemeProvider></React.StrictMode>);
109
+ void session.start();
110
+ if (import.meta.hot) import.meta.hot.dispose(() => { session.dispose(); off(); setNimiRemoteAppClient(null); reactRoot.unmount(); });
111
+ `;
112
+
113
+ const WEB_DOWNLOAD = `import { readNimiAppAssetBlob, openNimiAppAssetMediaUrl } from '@nimiplatform/kit/core/app-asset-media';
114
+ import { getNimiLocalAppClient } from './auth/local-app-client.js';
115
+ export function requestDownload(filename: string, blob: Blob) {
116
+ const url = URL.createObjectURL(blob), anchor = document.createElement('a');
117
+ anchor.href = url; anchor.download = filename; anchor.hidden = true;
118
+ try { document.body.append(anchor); anchor.click(); } finally { anchor.remove(); setTimeout(() => URL.revokeObjectURL(url), 0); }
119
+ return { destination: 'browser-download' as const, filename, byteSize: blob.size };
120
+ }
121
+ export const openAssetMediaUrl = (relativePath: string, signal?: AbortSignal) => openNimiAppAssetMediaUrl(getNimiLocalAppClient().storage.assets, relativePath, signal);
122
+ export async function downloadAsset(relativePath: string) {
123
+ return requestDownload(relativePath.split('/').at(-1)!, await readNimiAppAssetBlob(getNimiLocalAppClient().storage.assets, relativePath));
124
+ }
125
+ `;
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@nimiplatform/app-tools",
3
- "version": "0.14.0",
3
+ "version": "0.16.0-rc.9",
4
4
  "description": "Public app-authoring CLI for Nimi App projects.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
7
7
  "engines": {
8
- "node": ">=24.22.1 <25.0.0"
8
+ "node": ">=24.22.3 <25.0.0"
9
9
  },
10
10
  "private": false,
11
11
  "repository": {
@@ -18,37 +18,48 @@
18
18
  "provenance": true
19
19
  },
20
20
  "nimiScaffoldVersions": {
21
- "sdkVersion": "^0.22.2",
22
- "appToolsVersion": "^0.14.0",
21
+ "sdkVersion": "^0.24.0-rc.10",
22
+ "appToolsVersion": "^0.16.0-rc.9",
23
23
  "nimicodingVersion": "0.7.0",
24
- "aiSdkVersion": "^7.0.150",
25
- "kitVersion": "^0.22.1",
24
+ "aiSdkVersion": "^7.0.171",
25
+ "kitVersion": "^0.24.0-rc.16",
26
26
  "reactVersion": "^19.3.1",
27
27
  "reactDomVersion": "^19.3.1",
28
- "i18nextVersion": "^26.5.6",
29
- "lucideReactVersion": "^1.61.0",
28
+ "i18nextVersion": "^26.7.2",
29
+ "lucideReactVersion": "^1.70.0",
30
30
  "tsxVersion": "^4.23.15",
31
31
  "typescriptVersion": "^6.0.3",
32
32
  "nodeTypesVersion": "^24.19.2",
33
33
  "reactTypesVersion": "^19.3.0",
34
34
  "reactDomTypesVersion": "^19.3.0",
35
- "viteVersion": "^8.3.5",
36
- "viteReactPluginVersion": "^6.1.2",
37
- "tailwindcssVersion": "^4.3.3",
38
- "tailwindcssViteVersion": "^4.3.3",
39
- "tauriCliVersion": "^2.11.4",
35
+ "viteVersion": "^8.3.8",
36
+ "viteReactPluginVersion": "^6.2.1",
37
+ "tailwindcssVersion": "^4.3.5",
38
+ "tailwindcssViteVersion": "^4.3.5",
40
39
  "yamlVersion": "^2.9.1",
41
40
  "pngjsVersion": "^7.0.0",
42
- "nimiShellTauriVersion": "0.11.1",
43
41
  "electronPackagerVersion": "^20.3.0",
44
- "electronVersion": "^45.0.0",
42
+ "electronVersion": "^45.4.1",
45
43
  "esbuildVersion": "^0.28.2",
46
44
  "packageManager": "pnpm@10.34.7"
47
45
  },
48
46
  "bin": {
49
47
  "nimi-app": "./bin/nimi-app.mjs"
50
48
  },
51
- "exports": {},
49
+ "exports": {
50
+ "./development": {
51
+ "types": "./lib/development-environment.d.mts",
52
+ "import": "./lib/development-environment.mjs",
53
+ "default": "./lib/development-environment.mjs"
54
+ },
55
+ "./web/release": "./lib/hosted-web-release.mjs",
56
+ "./web/coordination": "./lib/web-coordination.mjs",
57
+ "./web": {
58
+ "types": "./lib/web-development.d.mts",
59
+ "import": "./lib/web-development.mjs",
60
+ "default": "./lib/web-development.mjs"
61
+ }
62
+ },
52
63
  "scripts": {
53
64
  "build": "node scripts/sync-scaffold-versions.mjs --apply && node scripts/sync-app-source.mjs --apply",
54
65
  "sync:versions": "node scripts/sync-scaffold-versions.mjs --apply",
@@ -57,7 +68,7 @@
57
68
  "prepublishOnly": "pnpm run build",
58
69
  "test": "node ../scripts/with-workspace-surfaces.mjs -- pnpm run test:prepared",
59
70
  "test:large-archive": "node --test test/app-pack-large.test.mjs",
60
- "test:prepared": "node scripts/sync-scaffold-versions.mjs --check && node --test test/dev-shell.test.mjs && node --test test/app-icons.test.mjs test/app-dependency-combinations.test.mjs test/app-safety-profile.test.mjs test/app-project-lifecycle.test.mjs test/app-pack.test.mjs test/app-pack-large.test.mjs test/app-scaffold.test.mjs"
71
+ "test:prepared": "node scripts/sync-scaffold-versions.mjs --check && node --test test/dev-shell.test.mjs && node --test test/app-icons.test.mjs test/app-dependency-combinations.test.mjs test/app-safety-profile.test.mjs test/app-project-lifecycle.test.mjs test/app-pack.test.mjs test/app-pack-large.test.mjs test/app-scaffold.test.mjs test/web-carrier.test.mjs test/hosted-web-release.test.mjs test/mobile-development.test.mjs"
61
72
  },
62
73
  "files": [
63
74
  "bin",
@@ -69,12 +80,12 @@
69
80
  ],
70
81
  "dependencies": {
71
82
  "pngjs": "7.0.0",
72
- "semver": "^7.8.5",
83
+ "semver": "^7.8.6",
73
84
  "typescript": "6.0.3",
74
85
  "yaml": "2.9.1"
75
86
  },
76
87
  "peerDependencies": {
77
- "vite": "^8.0.0"
88
+ "vite": "~8.1.7 || ~8.2.5 || ^8.3.7"
78
89
  },
79
90
  "peerDependenciesMeta": {
80
91
  "vite": {
@@ -83,7 +94,7 @@
83
94
  },
84
95
  "devDependencies": {
85
96
  "@types/node": "24.19.2",
86
- "vite": "8.3.5",
87
- "i18next": "26.5.6"
97
+ "vite": "8.3.8",
98
+ "i18next": "26.7.2"
88
99
  }
89
100
  }