@nimiplatform/app-tools 0.2.8 → 0.3.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.
Files changed (43) hide show
  1. package/README.md +113 -5
  2. package/bin/nimi-app.mjs +4 -0
  3. package/lib/app-doctor-update.mjs +7 -1
  4. package/lib/app-pack.mjs +33 -11
  5. package/lib/app-project-lifecycle.mjs +1 -0
  6. package/lib/app-scaffold-profiles.mjs +29 -14
  7. package/lib/app-scaffold.mjs +53 -7
  8. package/lib/macos-native.mjs +96 -0
  9. package/lib/payload-links.mjs +41 -0
  10. package/package.json +7 -7
  11. package/templates/app-source/src/ai-studio-core/ai-studio-core.css +31 -0
  12. package/templates/app-source/src/ai-studio-core/history-policy.ts +23 -1
  13. package/templates/app-source/src/ai-studio-core/history.ts +7 -1
  14. package/templates/app-source/src/ai-studio-core/messages/en.json +1 -0
  15. package/templates/app-source/src/ai-studio-core/messages/zh.json +1 -0
  16. package/templates/app-source/src/ai-studio-core/module-registration.ts +2 -2
  17. package/templates/app-source/src/ai-studio-core/non-success-presentation.ts +6 -2
  18. package/templates/app-source/src/ai-studio-core/run-target.ts +1 -1
  19. package/templates/app-source/src/ai-studio-core/runtime-types.ts +4 -0
  20. package/templates/app-source/src/ai-studio-core/runtime.ts +13 -4
  21. package/templates/app-source/src/ai-studio-core/section-ai-testing-admission.ts +3 -3
  22. package/templates/app-source/src/ai-studio-core/section-ai-testing-composer.tsx +41 -13
  23. package/templates/app-source/src/ai-studio-core/section-ai-testing-history.tsx +1 -1
  24. package/templates/app-source/src/ai-studio-core/section-ai-testing-input.ts +1 -0
  25. package/templates/app-source/src/ai-studio-core/section-ai-testing-output.tsx +26 -1
  26. package/templates/app-source/src/ai-studio-core/section-ai-testing-result.tsx +14 -4
  27. package/templates/app-source/src/ai-studio-core/section-ai-testing-run.ts +3 -1
  28. package/templates/app-source/src/ai-studio-core/section-ai-testing-studio-result.tsx +12 -3
  29. package/templates/app-source/src/ai-studio-core/section-ai-testing-vision-input.tsx +56 -0
  30. package/templates/app-source/src/ai-studio-core/section-ai-testing-vision-result.tsx +22 -0
  31. package/templates/app-source/src/ai-studio-core/section-ai-testing.tsx +54 -29
  32. package/templates/app-source/src/product-modules/agent-realtime/index.tsx +2 -2
  33. package/templates/app-source/src/studio-modules/studio-create/runtime.ts +1 -0
  34. package/templates/app-source/src/studio-modules/studio-media/descriptors.ts +6 -1
  35. package/templates/app-source/src/studio-modules/studio-media/messages/en.json +19 -0
  36. package/templates/app-source/src/studio-modules/studio-media/messages/zh.json +19 -0
  37. package/templates/app-source/src/studio-modules/studio-media/registration.ts +10 -1
  38. package/templates/app-source/src/studio-modules/studio-media/runtime.ts +2 -0
  39. package/templates/app-source/src/studio-modules/studio-media/vision-parameters.tsx +18 -0
  40. package/templates/app-source/src/studio-modules/studio-media/vision-runtime.ts +58 -0
  41. package/templates/app-source/src/workbench-core/workbench-core.css +5 -0
  42. package/templates/app-source.manifest.json +16 -0
  43. package/templates/default-starter/README.md +25 -1
package/README.md CHANGED
@@ -34,7 +34,7 @@ node app-tools/bin/nimi-app.mjs --help
34
34
 
35
35
  ## Create
36
36
 
37
- Interactive use validates every field, shows the resolved plan and asks for confirmation. The optional `author` names one person or team. Non-interactive use supplies the same inputs directly:
37
+ Interactive use validates every field, shows the resolved plan and asks for confirmation. The optional `author` names one person or team; include `--author` when creating a Windows release project because the standard packager uses it for executable metadata. Non-interactive use supplies the same inputs directly:
38
38
 
39
39
  ```bash
40
40
  node app-tools/bin/nimi-app.mjs create \
@@ -79,13 +79,31 @@ The list shows the current project's registrations and creation times. Copy the
79
79
 
80
80
  The default `windows-x86_64` build profile runs `build:electron:production`. It rebuilds the renderer and Electron main/preload, then creates a fresh, non-installer `dist-electron-package/<app>-shell-win32-x64/` directory with `asar` disabled and an App-specific `<app>-shell.exe`. The production main bundle has a compile-time production marker and rejects every `--nimi-dev-renderer-url` argument; packaged renderer assets stay relative under `dist/`. The protected native binding is resolved from Kit's optional dependency and is never declared directly by the App.
81
81
 
82
+ App Tools 0.3 also prepares the `macos-aarch64` target on an Apple Silicon Mac.
83
+ The same owner command produces `dist-electron-package/<app>-shell-darwin-arm64/`
84
+ with a native `.app` bundle and a direct `Contents/MacOS` entry. The publisher's
85
+ build applies an ad-hoc integrity seal without a Developer ID identity or Apple
86
+ notarization; production pack observes that absence and rejects invalid seals.
87
+ Relative framework links are preserved inside the immutable payload. The App
88
+ continues to consume the macOS native binding through Kit's optional dependency.
89
+ Nimi installation never signs or repairs the publisher's code.
90
+
91
+ Existing `.nimi/config/build-profile.yaml` target choices are App-owned and are
92
+ preserved by sync. To add macOS, declare `macos-aarch64` with `os: macos`,
93
+ `arch: arm64`, the same production build command, the Darwin output directory
94
+ above as `payload_path`, and
95
+ `payload/<app>-shell.app/Contents/MacOS/<app>-shell` as `runtime_entry`.
96
+ The managed workflow resolves that declared target to `macos-15`; Windows keeps
97
+ its existing runner and profile. These authoring/build capabilities do not by
98
+ themselves establish Registry admission or a completed Desktop lifecycle.
99
+
82
100
  Tauri remains an explicit alternative through `pnpm run build:tauri:production`; selecting it requires an explicit Tauri build profile rather than changing the default Electron carrier.
83
101
 
84
102
  ## Canonical release boundary
85
103
 
86
- The production chain is singular. Its publisher GitHub Release stage is
87
- available for explicitly configured pilot repositories; later registry and
88
- installed lifecycle stages remain unavailable:
104
+ The Registry publication chain uses the stages below. Publisher GitHub Release
105
+ is available for configured pilot repositories; protected Registry admission and
106
+ verified installation, update, launch and uninstall are available on Windows x86_64:
89
107
 
90
108
  ```text
91
109
  public App repository
@@ -101,7 +119,97 @@ public App repository
101
119
 
102
120
  The registry references publisher Release assets and never mirrors bytes. GitHub Release is not catalog admission; catalog admission is not installed; installed is not running; running is not Nimi Access ready.
103
121
 
104
- Repository administration must enable a protected `v*` tag ruleset and GitHub immutable releases before production. The managed tag workflow fetches the repository's canonical default branch and rejects a tag commit outside that history before production preflight, build, attestation, or Release. A fine-grained `NIMI_REPOSITORY_ADMIN_TOKEN` secret with repository Administration read permission lets the workflow verify protected-tag and immutable-release settings; it cannot enable or change them. Manual workflow dispatch runs only the non-production build/package path. On Windows, the tag-only production build invokes the App-declared production build with no certificate-secret mapping or app-tools-owned signing step. Optional native signing remains publisher-owned and must already be reflected in the final exact Runtime entry before production pack observes and records its native-trust posture; a present invalid or unresolved signature still fails closed. A successful tag workflow creates the immutable publisher GitHub Release and no registry, installed, running, or Nimi Access truth. Registry submission, the shared installed carrier, and installed launch remain unavailable.
122
+ Repository administration must enable a protected `v*` tag ruleset and GitHub immutable releases before production. The managed tag workflow fetches the repository's canonical default branch and rejects a tag commit outside that history before production preflight, build, attestation, or Release. A fine-grained `NIMI_REPOSITORY_ADMIN_TOKEN` secret with repository Administration read permission lets the workflow verify protected-tag and immutable-release settings; it cannot enable or change them. Manual workflow dispatch runs only the non-production build/package path. On Windows, the tag-only production build invokes the App-declared production build with no certificate-secret mapping or app-tools-owned signing step. Optional native signing remains publisher-owned and must already be reflected in the final exact Runtime entry before production pack observes and records its native-trust posture; a present invalid or unresolved signature still fails closed. A successful tag workflow creates the immutable publisher GitHub Release and no registry, installed, running, or Nimi Access truth. Protected Registry submission and approved Windows x86_64 installation, update, launch/focus/stop, current-session Nimi Access and uninstall are available through their Platform, Runtime and Desktop owners. Other-platform installed lifecycle and ordinary repair remain unavailable. Explicit immutable local-package import remains a separate product path whose entry is not yet implemented.
123
+
124
+ Registry projects must be open source with an explicit license and reviewable release source. Consistently observed unsigned packages are eligible; invalid signatures cannot be downgraded to unsigned. These Registry admission requirements do not apply to user-imported packages or Developer Mode projects. Registry approval is not a guarantee that third-party code is harmless.
125
+
126
+ ## Publishing on GitHub
127
+
128
+ Local development does not need a GitHub token. Publishing an App Release does.
129
+ `nimi-app check --production` checks local inputs; the tag workflow checks the
130
+ GitHub repository settings. Complete the one-time setup below before pushing a
131
+ release tag.
132
+
133
+ ### 1. Configure the publisher repository
134
+
135
+ Use a public repository owned by the publisher. You need administrator access
136
+ for this setup.
137
+
138
+ - In **Settings → General → Releases**, enable **Release immutability**.
139
+ - In **Settings → Rules → Rulesets**, create a **tag** ruleset, set enforcement
140
+ to **Active**, and include tags matching `v*`. Enable **Restrict updates**
141
+ and **Restrict deletions**. Tag creation must remain available to the publisher.
142
+
143
+ These settings protect published versions. The workflow only checks them; it
144
+ does not change repository settings.
145
+
146
+ ### 2. Create the read-only settings token
147
+
148
+ Open [GitHub's fine-grained token page](https://github.com/settings/personal-access-tokens/new).
149
+
150
+ 1. Name the token so you can recognize its purpose, and choose an expiration date.
151
+ 2. Set **Resource owner** to the user or organization that owns the App repository.
152
+ 3. Under **Repository access**, choose **Only select repositories** and select
153
+ this App repository.
154
+ 4. Under **Repository permissions**, set **Administration** to **Read-only**.
155
+ GitHub includes read-only Metadata automatically. No Contents write,
156
+ Actions write, Secrets write, or organization-wide access is needed.
157
+ 5. Generate the token. If the organization requires approval, complete that
158
+ approval before publishing.
159
+
160
+ This token reads tag-protection and release-immutability settings. The workflow
161
+ uses GitHub's separate built-in token to publish artifacts and its OIDC
162
+ permission to create build attestations.
163
+
164
+ ### 3. Save it as an Actions secret
165
+
166
+ In the App repository, open **Settings → Secrets and variables → Actions →
167
+ New repository secret**.
168
+
169
+ - **Name:** `NIMI_REPOSITORY_ADMIN_TOKEN`
170
+ - **Secret:** the fine-grained token value from step 2
171
+
172
+ Save it and confirm the exact name appears in the repository's Actions secrets.
173
+ Use a **secret**, not an Actions variable. An organization secret is also
174
+ supported when its repository-access list includes this App. Keep the value
175
+ out of source files, `.env`, and release notes.
176
+
177
+ ### 4. Check, build, and publish a version
178
+
179
+ Run the existing local path from the App repository:
180
+
181
+ ```bash
182
+ pnpm run sync
183
+ pnpm exec nimi-app check --production
184
+ pnpm exec nimi-app test
185
+ pnpm exec nimi-app build --target windows-x86_64 --production
186
+ pnpm exec nimi-app pack --target windows-x86_64 --production
187
+ ```
188
+
189
+ Commit the release changes and get that exact commit onto the repository's
190
+ canonical default branch. Keep `package.json` and `nimi.app.yaml` versions
191
+ equal. Use that version for the annotated tag; `0.1.0` below is an example:
192
+
193
+ ```bash
194
+ git tag -a v0.1.0 -m "Release 0.1.0"
195
+ git push origin v0.1.0
196
+ ```
197
+
198
+ Open **Actions → nimi-app-release**. A successful run produces the immutable
199
+ GitHub Release containing the `.nimiapp` package and aggregate candidate JSON.
200
+ Manual workflow dispatch checks the development path and does not publish.
201
+
202
+ If setup fails, the failed step points to the required setting. Add or replace
203
+ the secret, fix its repository selection/permissions, or enable the named
204
+ setting, then use **Re-run failed jobs** on the same run. A tag outside the
205
+ default branch requires merging its exact commit first. A code change requires
206
+ a new version and tag. Newly published release proofs can take a short time to
207
+ appear; the workflow waits for this specific delay and still requires successful
208
+ verification.
209
+
210
+ GitHub Release publication is followed by the separate
211
+ [Registry submission and human admission flow](https://github.com/nimiplatform/nimi-app-registry#ownership-boundary).
212
+ App Tools does not create an approval or install the App as a side effect.
105
213
 
106
214
  ## Acceptance status
107
215
 
package/bin/nimi-app.mjs CHANGED
@@ -366,6 +366,10 @@ try {
366
366
  production,
367
367
  json,
368
368
  });
369
+ if (production && !json) {
370
+ process.stdout.write('[nimi-app] Local checks do not verify GitHub repository settings or secrets. Before tagging, configure NIMI_REPOSITORY_ADMIN_TOKEN and release protection:\n');
371
+ process.stdout.write('https://github.com/nimiplatform/nimi/blob/main/app-tools/README.md#publishing-on-github\n');
372
+ }
369
373
  break;
370
374
  case 'test':
371
375
  testApp(process.cwd(), { dir, json });
@@ -388,7 +388,13 @@ function scanForbiddenPatterns(targetDir, profile, selectedLabels = null) {
388
388
  if (label === 'environment custody of protected material' && isManagedReleaseWorkflow) {
389
389
  continue;
390
390
  }
391
- if (pattern.test(text)) {
391
+ // Publishing documentation names the GitHub-only repository secret.
392
+ // App/runtime source still cannot read it, and other protected Nimi
393
+ // environment material remains forbidden in documentation as well.
394
+ const scanText = label === 'environment custody of protected material' && relativePath.endsWith('.md')
395
+ ? text.replace(/\bNIMI_REPOSITORY_ADMIN_TOKEN\b/gu, '')
396
+ : text;
397
+ if (pattern.test(scanText)) {
392
398
  findings.push(`${relativePath}: ${label}`);
393
399
  }
394
400
  }
package/lib/app-pack.mjs CHANGED
@@ -12,11 +12,14 @@ import {
12
12
  mkdirSync,
13
13
  readFileSync,
14
14
  readdirSync,
15
+ readlinkSync,
15
16
  writeFileSync,
16
17
  } from 'node:fs';
17
18
  import path from 'node:path';
18
19
  import { parse as parseYaml } from 'yaml';
19
20
  import { observeWindowsExecutableFacts } from './windows-powershell.mjs';
21
+ import { SYMBOLIC_LINK_MODE, validatePayloadLinks } from './payload-links.mjs';
22
+ import { observeMacOSExecutableFacts } from './macos-native.mjs';
20
23
 
21
24
  const PACKAGE_FORMAT = 'nimi.app-package/v1';
22
25
  const TARGET_METADATA_FORMAT = 'nimi.app-target-candidate/v1';
@@ -28,6 +31,7 @@ const OUTPUT_DIR = 'dist/nimi-app';
28
31
  const SEMVER_PATTERN = /^(?:0|[1-9][0-9]*)\.(?:0|[1-9][0-9]*)\.(?:0|[1-9][0-9]*)(?:-[0-9A-Za-z]+(?:[.-][0-9A-Za-z]+)*)?(?:\+[0-9A-Za-z]+(?:[.-][0-9A-Za-z]+)*)?$/u;
29
32
  const TARGETS = Object.freeze({
30
33
  'windows-x86_64': Object.freeze({ os: 'windows', arch: 'x86_64' }),
34
+ 'macos-aarch64': Object.freeze({ os: 'macos', arch: 'arm64' }),
31
35
  });
32
36
 
33
37
  function compareText(left, right) {
@@ -103,7 +107,7 @@ function readCargoPackageVersion(source) {
103
107
  throw new Error('src-tauri/Cargo.toml [package] version is missing');
104
108
  }
105
109
 
106
- function collectPayload(payloadPath) {
110
+ function collectPayload(payloadPath, os) {
107
111
  const stat = lstatSync(payloadPath);
108
112
  if (stat.isSymbolicLink()) throw new Error('Pack payload must not contain symbolic links');
109
113
  if (stat.isFile()) {
@@ -116,8 +120,10 @@ function collectPayload(payloadPath) {
116
120
  const relative = prefix ? `${prefix}/${entry.name}` : entry.name;
117
121
  const absolute = path.join(current, entry.name);
118
122
  const entryStat = lstatSync(absolute);
119
- if (entryStat.isSymbolicLink()) throw new Error(`Pack payload must not contain symbolic links: ${relative}`);
120
- if (entryStat.isDirectory()) {
123
+ if (entryStat.isSymbolicLink()) {
124
+ if (os !== 'macos') throw new Error(`Pack payload must not contain symbolic links: ${relative}`);
125
+ entries.push({ relative, bytes: Buffer.from(readlinkSync(absolute)), mode: SYMBOLIC_LINK_MODE });
126
+ } else if (entryStat.isDirectory()) {
121
127
  walk(absolute, relative);
122
128
  } else if (entryStat.isFile()) {
123
129
  entries.push({ relative, bytes: readFileSync(absolute), mode: entryStat.mode & 0o111 ? 0o755 : 0o644 });
@@ -157,7 +163,7 @@ export function writeNimiAppArchive(entries) {
157
163
  const normalized = entries.map((entry) => ({
158
164
  name: zipEntryName(entry.name),
159
165
  bytes: Buffer.isBuffer(entry.bytes) ? entry.bytes : Buffer.from(entry.bytes),
160
- mode: entry.mode === 0o755 ? 0o755 : 0o644,
166
+ mode: entry.mode === SYMBOLIC_LINK_MODE ? SYMBOLIC_LINK_MODE : entry.mode === 0o755 ? 0o755 : 0o644,
161
167
  })).sort((left, right) => compareText(left.name, right.name));
162
168
  if (normalized.length === 0) throw new Error('nimiapp archive requires at least one file');
163
169
  if (new Set(normalized.map((entry) => entry.name)).size !== normalized.length) throw new Error('nimiapp archive entries must be unique');
@@ -199,7 +205,7 @@ export function writeNimiAppArchive(entries) {
199
205
  central.writeUInt16LE(0, 32);
200
206
  central.writeUInt16LE(0, 34);
201
207
  central.writeUInt16LE(0, 36);
202
- central.writeUInt32LE(((0o100000 | entry.mode) << 16) >>> 0, 38);
208
+ central.writeUInt32LE(((entry.mode === SYMBOLIC_LINK_MODE ? entry.mode : 0o100000 | entry.mode) << 16) >>> 0, 38);
203
209
  central.writeUInt32LE(offset, 42);
204
210
  centralParts.push(central, name);
205
211
  offset += local.length + name.length + entry.bytes.length;
@@ -236,9 +242,10 @@ export function readNimiAppArchive(bytes) {
236
242
  const extraLength = archive.readUInt16LE(cursor + 30);
237
243
  const commentLength = archive.readUInt16LE(cursor + 32);
238
244
  const localOffset = archive.readUInt32LE(cursor + 42);
239
- const mode = (archive.readUInt32LE(cursor + 38) >>> 16) & 0o777;
245
+ const unixMode = archive.readUInt32LE(cursor + 38) >>> 16;
246
+ const mode = (unixMode & 0o170000) === 0o120000 ? unixMode : unixMode & 0o777;
240
247
  if (method !== 0 || extraLength !== 0 || commentLength !== 0) throw new Error('Unsupported nimiapp ZIP entry encoding');
241
- if (mode !== 0o644 && mode !== 0o755) throw new Error('Unsupported nimiapp ZIP entry mode');
248
+ if (mode !== 0o644 && mode !== 0o755 && mode !== SYMBOLIC_LINK_MODE) throw new Error('Unsupported nimiapp ZIP entry mode');
242
249
  const name = zipEntryName(archive.subarray(cursor + 46, cursor + 46 + nameLength).toString('utf8'));
243
250
  if (entries.has(name) || archive.readUInt32LE(localOffset) !== 0x04034b50) throw new Error('Invalid or duplicate nimiapp ZIP entry');
244
251
  const localNameLength = archive.readUInt16LE(localOffset + 26);
@@ -358,10 +365,15 @@ function resolveTargetFacts(input, production, archivedRuntimeEntryBytes) {
358
365
  executionProfile: null,
359
366
  };
360
367
  }
368
+ if (input.target.os === 'macos') {
369
+ const facts = observeMacOSExecutableFacts(input.runtimeHostPath);
370
+ if (!archivedRuntimeEntryBytes.equals(readFileSync(input.runtimeHostPath))) throw new Error('Production Runtime entry changed during macOS native observation');
371
+ return facts;
372
+ }
361
373
  return observeProductionWindowsFacts(input, archivedRuntimeEntryBytes);
362
374
  }
363
375
 
364
- function validateNativeExecutionFacts(nativeTrust, executionProfile, label) {
376
+ function validateNativeExecutionFacts(nativeTrust, executionProfile, label, os) {
365
377
  if (!nativeTrust || typeof nativeTrust !== 'object' || Array.isArray(nativeTrust)) {
366
378
  throw new Error(`${label} native_trust must be an object`);
367
379
  }
@@ -371,6 +383,13 @@ function validateNativeExecutionFacts(nativeTrust, executionProfile, label) {
371
383
  }
372
384
  return;
373
385
  }
386
+ if (os === 'macos') {
387
+ if (!executionProfile || Object.keys(executionProfile).join(',') !== 'launch_mode' || executionProfile.launch_mode !== 'current-user') throw new Error(`${label} macOS execution_profile must use current-user launch`);
388
+ if (Object.keys(nativeTrust).sort().join(',') !== 'certificate_subject,macos_developer_id,macos_notarization,posture') throw new Error(`${label} macOS native_trust is inconsistent`);
389
+ if (nativeTrust.posture === 'production-unsigned' && nativeTrust.macos_developer_id === 'absent' && nativeTrust.macos_notarization === 'absent' && nativeTrust.certificate_subject === null) return;
390
+ if (nativeTrust.posture === 'observed-valid-native-signature' && nativeTrust.macos_developer_id === 'valid' && ['absent', 'notarized'].includes(nativeTrust.macos_notarization) && typeof nativeTrust.certificate_subject === 'string' && nativeTrust.certificate_subject.trim() === nativeTrust.certificate_subject && nativeTrust.certificate_subject) return;
391
+ throw new Error(`${label} macOS native_trust posture is inconsistent`);
392
+ }
374
393
  if (
375
394
  !executionProfile
376
395
  || typeof executionProfile !== 'object'
@@ -423,10 +442,12 @@ export function packAppTarget(cwd, options = {}) {
423
442
  const targetId = String(options.target || '').trim();
424
443
  if (!targetId) throw new Error('nimi-app pack requires --target');
425
444
  const input = readPackInputs(targetDir, targetId);
426
- const payloadEntries = collectPayload(input.payloadPath).map((entry) => {
445
+ const payloadEntries = collectPayload(input.payloadPath, input.target.os).map((entry) => {
427
446
  const name = `payload/${entry.relative.replaceAll('\\', '/')}`;
447
+ if (name === input.runtimeEntry && entry.mode === SYMBOLIC_LINK_MODE) throw new Error('Runtime entry must be a direct regular file');
428
448
  return { name, bytes: entry.bytes, mode: name === input.runtimeEntry ? 0o755 : entry.mode };
429
449
  });
450
+ validatePayloadLinks(new Map(payloadEntries.map((entry) => [entry.name, entry])), input.target.os);
430
451
  const runtimeEntry = payloadEntries.find((entry) => entry.name === input.runtimeEntry);
431
452
  if (!runtimeEntry) throw new Error(`runtime_entry is missing from target payload: ${input.runtimeEntry}`);
432
453
  const { nativeTrust, executionProfile } = resolveTargetFacts(input, options.production === true, runtimeEntry.bytes);
@@ -498,12 +519,13 @@ export function aggregateAppTargetCandidates(cwd, options = {}) {
498
519
  }
499
520
  const runtimeEntry = canonicalRelative(target.runtime_entry, `${metadataLabel}.runtime_entry`);
500
521
  if (!runtimeEntry.startsWith('payload/')) throw new Error(`Target runtime_entry must resolve inside payload: ${runtimeEntry}`);
501
- validateNativeExecutionFacts(target.native_trust, target.execution_profile, metadataLabel);
522
+ validateNativeExecutionFacts(target.native_trust, target.execution_profile, metadataLabel, target.os);
502
523
  const artifactPath = path.join(outputDir, assetName);
503
524
  if (!existsSync(artifactPath)) throw new Error(`Target artifact is missing: ${target.asset_name}`);
504
525
  const bytes = readFileSync(artifactPath);
505
526
  if (bytes.length !== target.size || createHash('sha256').update(bytes).digest('hex') !== target.sha256) throw new Error(`Target artifact changed after pack: ${target.asset_name}`);
506
527
  const entries = readNimiAppArchive(bytes);
528
+ validatePayloadLinks(entries, target.os);
507
529
  const manifest = readPackageManifestFromArchive(entries, metadataLabel);
508
530
  if (manifest.format !== PACKAGE_FORMAT) throw new Error(`Target archive manifest format is invalid: ${target.asset_name}`);
509
531
  for (const field of ['app_id', 'version', 'target_id', 'os', 'arch', 'runtime_entry', 'native_trust', 'execution_profile']) {
@@ -511,7 +533,7 @@ export function aggregateAppTargetCandidates(cwd, options = {}) {
511
533
  throw new Error(`Target metadata does not match archive manifest ${field}: ${target.asset_name}`);
512
534
  }
513
535
  }
514
- validateNativeExecutionFacts(manifest.native_trust, manifest.execution_profile, `${target.asset_name} archive manifest`);
536
+ validateNativeExecutionFacts(manifest.native_trust, manifest.execution_profile, `${target.asset_name} archive manifest`, target.os);
515
537
  const runtimeEntryArchive = entries.get(runtimeEntry);
516
538
  if (!runtimeEntryArchive || runtimeEntryArchive.mode !== 0o755) {
517
539
  throw new Error(`Target archive runtime_entry is missing or non-executable: ${runtimeEntry}`);
@@ -46,6 +46,7 @@ const SUBMISSION_PATH = '.nimi/admission/submission.yaml';
46
46
  const SEMVER_PATTERN = /^(?:0|[1-9][0-9]*)\.(?:0|[1-9][0-9]*)\.(?:0|[1-9][0-9]*)(?:-[0-9A-Za-z]+(?:[.-][0-9A-Za-z]+)*)?(?:\+[0-9A-Za-z]+(?:[.-][0-9A-Za-z]+)*)?$/u;
47
47
  const CURRENT_APP_TARGETS = Object.freeze({
48
48
  'windows-x86_64': Object.freeze({ os: 'windows', arch: 'x86_64' }),
49
+ 'macos-aarch64': Object.freeze({ os: 'macos', arch: 'arm64' }),
49
50
  });
50
51
 
51
52
  function resolveTargetDir(cwd, options = {}) {
@@ -135,19 +135,22 @@ function renderDefaultElectronProductionPackager(identity) {
135
135
  '',
136
136
  `const APP_EXECUTABLE_NAME = ${JSON.stringify(identity.cargoPackageName)};`,
137
137
  `const APP_PRODUCT_NAME = ${JSON.stringify(identity.appTitle)};`,
138
- `const APP_VERSION = ${JSON.stringify(identity.version)};`,
139
138
  resolveWindowsResourceVersion.toString(),
140
- 'const WINDOWS_RESOURCE_VERSION = resolveWindowsResourceVersion(APP_VERSION);',
141
- "const NATIVE_BINDING_PACKAGE = '@nimiplatform/kit-protected-local-win32-x64';",
139
+ "const MACOS_BUILD = process.platform === 'darwin' && process.arch === 'arm64';",
140
+ "const NATIVE_PLATFORM = MACOS_BUILD ? 'darwin' : 'win32';",
141
+ "const NATIVE_ARCH = MACOS_BUILD ? 'arm64' : 'x64';",
142
+ "const NATIVE_BINDING_PACKAGE = MACOS_BUILD ? '@nimiplatform/kit-protected-local-darwin-arm64' : '@nimiplatform/kit-protected-local-win32-x64';",
142
143
  "const appRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');",
143
144
  "const outputRoot = path.join(appRoot, 'dist-electron-package');",
144
145
  "const requireFromApp = createRequire(path.join(appRoot, 'package.json'));",
145
146
  '',
146
- "if (process.platform !== 'win32' || process.arch !== 'x64') {",
147
- " throw new Error('The windows-x86_64 Electron production profile requires a win32-x64 build host.');",
147
+ "if (!MACOS_BUILD && (process.platform !== 'win32' || process.arch !== 'x64')) {",
148
+ " throw new Error('Electron production packaging requires a windows-x86_64 or macos-aarch64 build host.');",
148
149
  '}',
149
150
  '',
150
151
  "const appPackage = JSON.parse(await readFile(path.join(appRoot, 'package.json'), 'utf8'));",
152
+ 'const APP_VERSION = appPackage.version;',
153
+ 'const RESOURCE_VERSION = MACOS_BUILD ? APP_VERSION : resolveWindowsResourceVersion(APP_VERSION);',
151
154
  "for (const sectionName of ['dependencies', 'devDependencies', 'optionalDependencies', 'peerDependencies']) {",
152
155
  ' if (Object.hasOwn(appPackage[sectionName] || {}, NATIVE_BINDING_PACKAGE)) {',
153
156
  " throw new Error('The protected native binding must arrive through the Kit optional dependency.');",
@@ -158,7 +161,7 @@ function renderDefaultElectronProductionPackager(identity) {
158
161
  "const kitRoot = await findPackageRoot(kitEntry, '@nimiplatform/kit');",
159
162
  "const kitPackage = JSON.parse(await readFile(path.join(kitRoot, 'package.json'), 'utf8'));",
160
163
  'if (!Object.hasOwn(kitPackage.optionalDependencies || {}, NATIVE_BINDING_PACKAGE)) {',
161
- " throw new Error('Kit does not declare the windows-x64 protected native binding as optional.');",
164
+ " throw new Error('Kit does not declare the current-platform protected native binding as optional.');",
162
165
  '}',
163
166
  "const requireFromKit = createRequire(path.join(kitRoot, 'package.json'));",
164
167
  'const nativeEntry = requireFromKit.resolve(NATIVE_BINDING_PACKAGE);',
@@ -209,12 +212,13 @@ function renderDefaultElectronProductionPackager(identity) {
209
212
  '',
210
213
  ' const packagePaths = await packager({',
211
214
  ' dir: productionSourceRoot,',
212
- " platform: 'win32',",
213
- " arch: 'x64',",
215
+ ' platform: NATIVE_PLATFORM,',
216
+ ' arch: NATIVE_ARCH,',
217
+ ` appBundleId: ${JSON.stringify(identity.tauriIdentifier)},`,
214
218
  ' name: APP_EXECUTABLE_NAME,',
215
219
  ' executableName: APP_EXECUTABLE_NAME,',
216
- ' appVersion: WINDOWS_RESOURCE_VERSION,',
217
- ' buildVersion: WINDOWS_RESOURCE_VERSION,',
220
+ ' appVersion: RESOURCE_VERSION,',
221
+ ' buildVersion: RESOURCE_VERSION,',
218
222
  ' electronVersion: electronPackage.version,',
219
223
  ' out: outputRoot,',
220
224
  ' tmpdir: packagerTempRoot,',
@@ -223,6 +227,13 @@ function renderDefaultElectronProductionPackager(identity) {
223
227
  ' prune: false,',
224
228
  ' quiet: true,',
225
229
  ' derefSymlinks: true,',
230
+ ' // Publisher-side ad-hoc sealing supplies no Developer ID or notarization.',
231
+ ' // Runtime preserves these bytes; Nimi never signs installed third-party code.',
232
+ ' ...(MACOS_BUILD ? { osxSign: {',
233
+ " identity: '-', identityValidation: false, preAutoEntitlements: false,",
234
+ ' preEmbedProvisioningProfile: false, strictVerify: true,',
235
+ " optionsForFile: () => ({ entitlements: [], hardenedRuntime: false, timestamp: 'none' }),",
236
+ ' } } : {}),',
226
237
  ' afterInitialize: [async ({ buildPath }) => {',
227
238
  " const packagedManifestPath = path.join(buildPath, 'package.json');",
228
239
  " const packagedManifest = JSON.parse(await readFile(packagedManifestPath, 'utf8'));",
@@ -238,11 +249,13 @@ function renderDefaultElectronProductionPackager(identity) {
238
249
  ' },',
239
250
  ' });',
240
251
  " if (!Array.isArray(packagePaths) || packagePaths.length !== 1) throw new Error('Electron packager returned an ambiguous production package.');",
241
- ' const expectedPackageRoot = path.join(outputRoot, `${APP_EXECUTABLE_NAME}-win32-x64`);',
252
+ ' const expectedPackageRoot = path.join(outputRoot, `${APP_EXECUTABLE_NAME}-${NATIVE_PLATFORM}-${NATIVE_ARCH}`);',
242
253
  ' if (path.resolve(packagePaths[0]).toLowerCase() !== path.resolve(expectedPackageRoot).toLowerCase()) {',
243
254
  " throw new Error('Electron packager returned an unexpected production package path.');",
244
255
  ' }',
245
- ' await realpath(path.join(expectedPackageRoot, `${APP_EXECUTABLE_NAME}.exe`));',
256
+ ' await realpath(MACOS_BUILD',
257
+ " ? path.join(expectedPackageRoot, `${APP_EXECUTABLE_NAME}.app`, 'Contents', 'MacOS', APP_EXECUTABLE_NAME)",
258
+ ' : path.join(expectedPackageRoot, `${APP_EXECUTABLE_NAME}.exe`));',
246
259
  ' packageCompleted = true;',
247
260
  ' process.stdout.write(`[nimi-app] Electron production package: ${expectedPackageRoot}\\n`);',
248
261
  '} finally {',
@@ -253,9 +266,10 @@ function renderDefaultElectronProductionPackager(identity) {
253
266
  '',
254
267
  'async function installProductionDependencies(projectRoot) {',
255
268
  " const command = 'pnpm install --prod --frozen-lockfile --ignore-scripts --node-linker=hoisted';",
256
- " const commandShell = process.env.ComSpec || 'cmd.exe';",
269
+ " const commandShell = MACOS_BUILD ? 'pnpm' : process.env.ComSpec || 'cmd.exe';",
270
+ " const commandArguments = MACOS_BUILD ? ['install', '--prod', '--frozen-lockfile', '--ignore-scripts', '--node-linker=hoisted'] : ['/d', '/s', '/c', command];",
257
271
  ' await new Promise((resolve, reject) => {',
258
- " const child = spawn(commandShell, ['/d', '/s', '/c', command], {",
272
+ ' const child = spawn(commandShell, commandArguments, {',
259
273
  ' cwd: projectRoot,',
260
274
  " stdio: 'inherit',",
261
275
  ' windowsHide: true,',
@@ -1000,6 +1014,7 @@ function renderGeneratedAIStudioHostAdapter(resolution) {
1000
1014
  ' appId,',
1001
1015
  " surfaceId: 'ai-capabilities',",
1002
1016
  " abortReason: 'studio-user-canceled',",
1017
+ ' translate,',
1003
1018
  ' handlers: generatedStudioRuntimeHandlers,',
1004
1019
  ' resolveCapability: (capabilityId) => generatedAIStudioComposition.getCapability(capabilityId).descriptor,',
1005
1020
  ' inspectRuntime: inspectTargetRuntime,',
@@ -79,7 +79,6 @@ const APP_RELEASE_WORKFLOW = [
79
79
  ' - run: pnpm exec nimi-app sync',
80
80
  ' - run: test -z "$(git status --porcelain)"',
81
81
  ' - run: pnpm exec nimi-app check --json > .nimi-targets.json',
82
- ' - run: pnpm exec nimi-app test',
83
82
  ' - name: Require tag/version lockstep',
84
83
  " if: github.event_name == 'push' && github.ref_type == 'tag'",
85
84
  ' run: node -e "const p=require(\'./package.json\'); if (process.env.GITHUB_REF_NAME !== (\'v\' + p.version)) throw new Error(\'tag_version_mismatch\')"',
@@ -107,8 +106,23 @@ const APP_RELEASE_WORKFLOW = [
107
106
  ' GH_TOKEN: ${{ secrets.NIMI_REPOSITORY_ADMIN_TOKEN }}',
108
107
  ' shell: bash',
109
108
  ' run: |',
110
- ' test -n "$GH_TOKEN"',
111
- ' test "$(gh api "repos/$GITHUB_REPOSITORY/immutable-releases" --jq .enabled)" = true',
109
+ " if test -z \"$GH_TOKEN\"; then",
110
+ " echo \"::error title=Missing release setup::Add the repository Actions secret NIMI_REPOSITORY_ADMIN_TOKEN before publishing.\"",
111
+ " echo \"Create a fine-grained personal access token at https://github.com/settings/personal-access-tokens/new\"",
112
+ " echo \"Select the repository owner and only $GITHUB_REPOSITORY. Grant repository Administration: Read-only.\"",
113
+ " echo \"Save its value as NIMI_REPOSITORY_ADMIN_TOKEN at https://github.com/$GITHUB_REPOSITORY/settings/secrets/actions\"",
114
+ " echo \"Guide: https://github.com/nimiplatform/nimi/blob/main/app-tools/README.md#publishing-on-github\"",
115
+ " echo \"Then open this Actions run and choose Re-run failed jobs. Keep the existing tag.\"",
116
+ " exit 1",
117
+ " fi",
118
+ " if ! immutable=$(gh api \"repos/$GITHUB_REPOSITORY/immutable-releases\" --jq .enabled); then",
119
+ " echo \"::error title=Release settings inaccessible::Check token expiration, repository selection, Administration: Read-only, and any required organization approval.\"",
120
+ " exit 1",
121
+ " fi",
122
+ " if test \"$immutable\" != true; then",
123
+ " echo \"::error title=Immutable releases required::Enable release immutability in repository Settings > General > Releases, then re-run failed jobs.\"",
124
+ " exit 1",
125
+ " fi",
112
126
  ' protected=false',
113
127
  ' while read -r ruleset_id; do',
114
128
  ' ruleset=$(gh api "repos/$GITHUB_REPOSITORY/rulesets/$ruleset_id")',
@@ -122,12 +136,16 @@ const APP_RELEASE_WORKFLOW = [
122
136
  ' break',
123
137
  ' fi',
124
138
  ' done < <(gh api "repos/$GITHUB_REPOSITORY/rulesets" --jq \'.[] | select(.target == "tag" and .enforcement == "active") | .id\')',
125
- ' test "$protected" = true',
139
+ " if test \"$protected\" != true; then",
140
+ " echo \"::error title=Version tag protection required::Create an active tag ruleset for v* with Restrict updates and Restrict deletions in repository Settings > Rules > Rulesets.\"",
141
+ " echo \"After saving the ruleset, re-run failed jobs. Do not move or replace the existing tag.\"",
142
+ " exit 1",
143
+ " fi",
126
144
  ' - name: Resolve declared target matrix',
127
145
  ' id: matrix',
128
146
  ' shell: bash',
129
147
  ' run: |',
130
- " matrix=$(jq -c '{include: [.targets[] | {target: ., runner: (if . == \"windows-x86_64\" then \"windows-latest\" else error(\"unsupported target\") end)}]}' .nimi-targets.json)",
148
+ " matrix=$(jq -c '{include: [.targets[] | {target: ., runner: (if . == \"windows-x86_64\" then \"windows-latest\" elif . == \"macos-aarch64\" then \"macos-15\" else error(\"unsupported target\") end)}]}' .nimi-targets.json)",
131
149
  ' test "$(jq \'.include | length\' <<<"$matrix")" -gt 0',
132
150
  ' echo "matrix=$matrix" >> "$GITHUB_OUTPUT"',
133
151
  ' build-target:',
@@ -148,6 +166,8 @@ const APP_RELEASE_WORKFLOW = [
148
166
  ' package-manager-cache: false',
149
167
  ' - run: corepack enable',
150
168
  ' - run: pnpm install --frozen-lockfile',
169
+ ' - name: Test declared target',
170
+ ' run: pnpm exec nimi-app test',
151
171
  ' - name: Build development target',
152
172
  " if: github.event_name != 'push' || github.ref_type != 'tag'",
153
173
  ' env:',
@@ -248,6 +268,25 @@ const APP_RELEASE_WORKFLOW = [
248
268
  ' run: |',
249
269
  ' set -euo pipefail',
250
270
  ' shopt -s nullglob',
271
+ " verify_release() {",
272
+ " local verification_log",
273
+ " verification_log=$(mktemp)",
274
+ " for attempt in 1 2 3 4 5 6; do",
275
+ " if gh release verify \"$GITHUB_REF_NAME\" --repo \"$GITHUB_REPOSITORY\" >\"$verification_log\" 2>&1; then",
276
+ " cat \"$verification_log\"",
277
+ " rm \"$verification_log\"",
278
+ " return 0",
279
+ " fi",
280
+ " cat \"$verification_log\"",
281
+ " if ! grep -q \"no attestations for tag\" \"$verification_log\" || test \"$attempt\" = 6; then",
282
+ " rm \"$verification_log\"",
283
+ " echo \"::error title=Release verification failed::Inspect the error above. A published immutable Release must not be replaced; re-run failed jobs after its proof is available.\"",
284
+ " return 1",
285
+ " fi",
286
+ " echo \"Waiting for GitHub to make the new immutable Release attestation available (attempt $attempt/6).\"",
287
+ " sleep 10",
288
+ " done",
289
+ " }",
251
290
  ' assets=(release-assets/*.nimiapp release-assets/*.candidate.json)',
252
291
  ' test "${#assets[@]}" -gt 0',
253
292
  " expected=$(printf '%s\\n' \"${assets[@]##*/}\" | jq -R -s -c 'split(\"\\n\")[:-1] | sort')",
@@ -258,7 +297,7 @@ const APP_RELEASE_WORKFLOW = [
258
297
  ' test "$unexpected" -eq 0',
259
298
  ' if test "$(jq -r .draft <<<"$release_json")" = false; then',
260
299
  ' test "$existing" = "$expected"',
261
- ' gh release verify "$GITHUB_REF_NAME" --repo "$GITHUB_REPOSITORY"',
300
+ ' verify_release',
262
301
  ' for asset in "${assets[@]}"; do gh release verify-asset "$GITHUB_REF_NAME" "$asset" --repo "$GITHUB_REPOSITORY"; done',
263
302
  ' exit 0',
264
303
  ' fi',
@@ -280,7 +319,7 @@ const APP_RELEASE_WORKFLOW = [
280
319
  ' fi',
281
320
  ' done',
282
321
  ' gh release edit "$GITHUB_REF_NAME" --repo "$GITHUB_REPOSITORY" --draft=false',
283
- ' gh release verify "$GITHUB_REF_NAME" --repo "$GITHUB_REPOSITORY"',
322
+ ' verify_release',
284
323
  ' for asset in "${assets[@]}"; do gh release verify-asset "$GITHUB_REF_NAME" "$asset" --repo "$GITHUB_REPOSITORY"; done',
285
324
  '',
286
325
  ].join('\n');
@@ -988,6 +1027,13 @@ export function renderAppBuildProfile(options = {}) {
988
1027
  payload_path: `dist-electron-package/${identity.cargoPackageName}-win32-x64`,
989
1028
  runtime_entry: `payload/${identity.cargoPackageName}.exe`,
990
1029
  },
1030
+ 'macos-aarch64': {
1031
+ os: 'macos',
1032
+ arch: 'arm64',
1033
+ build_command: 'pnpm run build:electron:production',
1034
+ payload_path: `dist-electron-package/${identity.cargoPackageName}-darwin-arm64`,
1035
+ runtime_entry: `payload/${identity.cargoPackageName}.app/Contents/MacOS/${identity.cargoPackageName}`,
1036
+ },
991
1037
  } : undefined);
992
1038
  return YAML.stringify({
993
1039
  build_profile_ref: 'electron-packager-pnpm-vite',