Skip to content

The open-source full-stack studio for Opus 5.5 motion video. Reverse engineering for any video. Code video with HTML: recreate, edit and render. BYOA + BYOK · Motion.md · Images, Video, Music & Voice.

chore(release): synchronize integrated preparation helpers

罗高4475b0ea620a
diff --git a/.github/workflows/motion-candidate.yml b/.github/workflows/motion-candidate.yml
index 55bf487b..082bfaa4 100644
--- a/.github/workflows/motion-candidate.yml
+++ b/.github/workflows/motion-candidate.yml
@@ -69,7 +69,7 @@ jobs:
npm run typecheck:studio
npm run build:studio
npm run build:tracking
- node --experimental-strip-types --test tests/tracking.test.ts tests/install.test.ts tests/npm-installer.test.ts tests/npm-package.test.ts tests/test-package.test.ts tests/source-install.test.ts tests/bootstrap.test.ts tests/mcp-registry.test.ts tests/mcp-runtime.test.ts tests/mcp-upgrade.test.ts tests/preview.test.ts tests/phase1.test.ts tests/preview-handoff.test.ts tests/adapters.test.ts tests/package.test.ts tests/recreate-measure.test.ts tests/workflow.test.ts tests/catalog.test.ts tests/prism-templates.test.ts tests/extension-boundary.test.ts tests/connections.test.ts tests/install-guide.test.ts
+ node --experimental-strip-types --test tests/tracking.test.ts tests/install.test.ts tests/npm-installer.test.ts tests/native-runtime.test.ts tests/npm-package.test.ts tests/test-package.test.ts tests/source-install.test.ts tests/bootstrap.test.ts tests/mcp-registry.test.ts tests/mcp-runtime.test.ts tests/mcp-upgrade.test.ts tests/preview.test.ts tests/phase1.test.ts tests/preview-handoff.test.ts tests/adapters.test.ts tests/package.test.ts tests/recreate-measure.test.ts tests/workflow.test.ts tests/catalog.test.ts tests/prism-templates.test.ts tests/extension-boundary.test.ts tests/connections.test.ts tests/install-guide.test.ts
npm run test:studio -- --maxWorkers=2
npm run package:phase1
archive="$PWD/dist/motion-$(node -p "require('./package.json').version")-phase1.zip"
diff --git a/docs/install.md b/docs/install.md
index d47e6175..56543e97 100644
--- a/docs/install.md
+++ b/docs/install.md
@@ -9,7 +9,7 @@ If you are reading this file in the source repository and see `{{...}}`, it is a
1. Collect OS/CPU, Node.js/npm versions and the current Agent identity together, using the host's supplied context where available. Node.js 22.18+ with npm and the Agent must already be installed. Supported native targets: {{TARGETS}}. Do not claim support for another target from package-download success.
2. Select the current host explicitly: `codex` (Codex), `claude` (Claude Code), `deepseek` (DeepSeek Harness) or `workbuddy` (WorkBuddy). An explicit user selection takes precedence. Do not infer the current host from which CLIs happen to be installed. Ask only when the current host or required profile cannot be established. Configure only that host; preserve projects, credentials and unrelated MCP/Skills settings.
3. For a test candidate, use a separate host profile, application home, project data and Skills directory. Keep those paths and reuse them for prepare and future reconnects. The [platform installation recipes]({{DETAILS_URL}}) describe the actual supported options. Do not run a test candidate into the user's daily profile by default.
-4. Choose exactly one setup command below, applying the test isolation paths first when required. Run prepare only after successful setup, with the same application home, and wait for completion before native operations. Follow the selected host's discovery/reload mechanism. Compatible phase-one updates can keep existing connections; reconnect closed or incompatible transports. Confirm the application version, template environment, eleven public Tools and five Skills through that host, including an actual `motion_get_project` call. Registration alone does not prove loading.
+4. Choose exactly one setup command below, applying the test isolation paths first when required. Setup starts checked video-component downloads in the background. Do not wait for prepare to connect MCP, create/edit projects or open ordinary preview. Studio shows preparation status and retry; media import, automated capture and export require their respective components. Follow the selected host's discovery/reload mechanism. Compatible phase-one updates can keep existing connections; reconnect closed or incompatible transports. Confirm the application version, template environment, eleven public Tools and five Skills through that host, including an actual `motion_get_project` call. Registration alone does not prove loading.
5. Report the result and any failed step. Introduce the available capabilities and wait for the user's next request. Installation does not authorize generating a video or calling a paid model.
## Choose the selected host's setup command
@@ -23,7 +23,7 @@ The commands below show normal installations. For test candidates, apply the sep
| DeepSeek Harness | `npx --yes --package "{{PACKAGE_SPEC}}" openmotion setup --host deepseek --profile PROFILE` | Replace `PROFILE` with the actual selected profile from the host context; do not guess `web` or `desktop`. The standard macOS Desktop CLI is detected even when `dsh` is absent from PATH; use `--dsh` for another executable location. |
| WorkBuddy | `npx --yes --package "{{PACKAGE_SPEC}}" openmotion setup --host workbuddy` | Preserve the selected `WORKBUDDY_CONFIG_DIR` and Skills root. |
-Then prepare the same installation:
+Optional: explicitly wait for all video components or retry preparation for the same installation:
```sh
npx --yes --package "{{PACKAGE_SPEC}}" openmotion prepare
@@ -33,7 +33,7 @@ Repeat an explicit `--home` from setup on prepare. Setup installs the selected h
## Runtime and environment
-Setup copies the checked application into a managed writable directory and installs its locked production npm dependencies. The application and user projects do not run from the temporary npx cache. Prepare or first native use prepares the platform's independent native archives concurrently: browser/FFmpeg/ffprobe separately on macOS, browser/combined media on Windows. It waits for all components and reports a failure if any component fails; successful checked components remain reusable. This is not an offline package.
+Setup copies the checked application into a managed writable directory and installs its locked production npm dependencies. The application and user projects do not run from the temporary npx cache. Setup starts a detached preparation worker for the platform's independent native archives concurrently: browser/FFmpeg/ffprobe separately on macOS, browser/combined media on Windows. The local backend and Studio start without waiting. Studio displays per-component download/verification/extraction/checking status and retries failed components. Installers, MCP and Studio join shared cache locks rather than downloading again. An explicit prepare waits for all components and reports failure; successful checked components remain reusable. No export starts automatically after preparation. This is not an offline package.
There is no persisted switch-environment command in this version. Test versions embed DEV defaults and use an environment-specific installation; stable versions embed prod. DEV access still requires the service network/authentication. A public npm package does not grant access or bundle private catalog contents. When changing environment, use a separate home/data/profile; merely setting an environment variable while running setup does not configure a later desktop Agent. Do not silently fall back from one environment to another.
diff --git a/docs/motion-release-activation.md b/docs/motion-release-activation.md
index 17197461..cc16c0b3 100644
--- a/docs/motion-release-activation.md
+++ b/docs/motion-release-activation.md
@@ -6,7 +6,7 @@ This branch retains the legacy HTML Anything application. The Motion application
The three manual workflows, their runtime helpers, installation/acceptance templates and deterministic tests were initially copied without modification from reviewed PR [#214](https://github.com/nexu-io/html-anything/pull/214), source commit `de45dadea282214762c7b3123cea7e6b1044f26f`. The test-channel follow-up copies the same 18 shared control files byte-for-byte from Motion commit `94d15d656eb085f98067867502418bb99c7de0e9` and updates this control set to require DEV candidates and defer npm test promotion until native checks pass. No application business logic or private Git history is imported; shared runtime helpers and tests are included as control dependencies. The extra `Motion release controls` CI job runs only syntax checks and simulated-service tests with read-only permissions; the legacy CI commands and permissions are preserved. Its runner is pinned to Ubuntu 24.04 because the locked Playwright cannot install browsers on the Ubuntu 26.04 image now selected by ubuntu-latest.
-The branch-selection/automatic-numbering follow-up copies the same shared control set from Motion commit `a664ffeb823216fe03db2f576dbceac2cf5bb3fd`. Empty versions derive from that candidate's frozen Motion source, never from the legacy main package version. Source manifests are not bumped by a build. Both matching PRs must be integrated before accepting feature/motion-produced candidates for publication.
+The branch-selection/automatic-numbering follow-up copies the same shared control set from Motion commit `3d9d093231069108ada13c4e6c82e09ca91a5663`. This includes the already integrated #231 shared asset helper and install-guide updates; the candidate gate also runs its native-preparation regression. Empty versions derive from that candidate's frozen Motion source, never from the legacy main package version. Source manifests are not bumped by a build. Both matching PRs must be integrated before accepting feature/motion-produced candidates for publication.
GitHub requires a manual workflow to exist on the default branch before its Run workflow entry is available. Candidate builds now allow `feature/motion` or `main`; publication and recovery still require execution from `main`. They fetch the Motion application from a reviewed commit integrated into `feature/motion`. See [GitHub manual workflows](https://docs.github.com/en/actions/how-tos/manage-workflow-runs/manually-run-a-workflow).
diff --git a/scripts/runtime-assets.mjs b/scripts/runtime-assets.mjs
index 35462e57..ebf48378 100644
--- a/scripts/runtime-assets.mjs
+++ b/scripts/runtime-assets.mjs
@@ -1,7 +1,7 @@
import assert from 'node:assert/strict';
import { createHash, randomUUID } from 'node:crypto';
import { createReadStream, createWriteStream, constants } from 'node:fs';
-import { access, copyFile, mkdir, open, readFile, realpath, rename, rm, writeFile } from 'node:fs/promises';
+import { access, copyFile, link, mkdir, open, readFile, realpath, rename, rm, writeFile } from 'node:fs/promises';
import { spawn } from 'node:child_process';
import { fileURLToPath } from 'node:url';
import path from 'node:path';
@@ -13,7 +13,7 @@ export async function sha256(filename) {
for await (const chunk of createReadStream(filename)) hash.update(chunk);
return hash.digest('hex');
}
-export async function download(asset, filename) {
+export async function download(asset, filename, progress = async () => {}) {
const url = new URL(asset.url);
assert(url.protocol === 'https:' && /^[a-f0-9]{64}$/.test(asset.sha256), 'Require HTTPS and a pinned SHA256');
try { if (await sha256(filename) === asset.sha256) return; } catch (error) { if (error.code !== 'ENOENT') throw error; }
@@ -32,7 +32,18 @@ export async function download(asset, filename) {
current = new URL(location, current);
}
assert(response.ok && response.body, `Download ${url.hostname}${url.pathname}: HTTP ${response.status}`);
- await pipeline(Readable.fromWeb(response.body), createWriteStream(temporary));
+ let receivedBytes = 0;
+ const encoding = response.headers.get('content-encoding');
+ const totalBytes = !encoding || encoding === 'identity' ? Number(response.headers.get('content-length')) || undefined : undefined;
+ async function* measured(source) {
+ for await (const chunk of source) {
+ receivedBytes += chunk.length;
+ await progress({ stage: 'downloading', receivedBytes, totalBytes });
+ yield chunk;
+ }
+ }
+ await pipeline(Readable.fromWeb(response.body), measured, createWriteStream(temporary));
+ await progress({ stage: 'verifying' });
assert.equal(await sha256(temporary), asset.sha256, `SHA256 mismatch: ${url.pathname}`);
await rename(temporary, filename);
} finally { await rm(temporary, { force: true }); }
@@ -77,10 +88,43 @@ export async function withLock(filename, work) {
finally { await handle.close(); await rm(filename, { force: true }); }
}
-export async function obtainAsset(asset, filename, allowLocal = false) {
+export function processAlive(pid) {
+ if (!Number.isSafeInteger(pid) || pid <= 0) return false;
+ try { process.kill(pid, 0); return true; } catch (error) { return error.code !== 'ESRCH'; }
+}
+
+// Native caches are shared by installers and running apps; contenders join the owner.
+export async function withCacheLock(filename, work) {
+ await mkdir(path.dirname(filename), { recursive: true });
+ const token = randomUUID(), candidate = filename + '.' + token;
+ await writeFile(candidate, JSON.stringify({ pid: process.pid, token }), { mode: 0o600 });
+ const deadline = Date.now() + 15 * 60_000;
+ try {
+ for (;;) {
+ try { await link(candidate, filename); break; }
+ catch (error) { if (error.code !== 'EEXIST') throw error; }
+ const owner = await readJSON(filename);
+ const pid = typeof owner === 'number' ? owner : owner?.pid;
+ if (pid && !processAlive(pid)) {
+ await withCacheLock(filename + '.reclaim', async () => {
+ if (JSON.stringify(await readJSON(filename)) === JSON.stringify(owner)) await rm(filename, { force: true });
+ });
+ }
+ if (Date.now() > deadline) throw new Error('Timed out waiting for native preparation; no live download lock was removed.');
+ await new Promise(resolve => setTimeout(resolve, 100));
+ }
+ try { return await work(); }
+ finally { if ((await readJSON(filename))?.token === token) await rm(filename, { force: true }); }
+ } finally { await rm(candidate, { force: true }); }
+}
+
+export async function obtainAsset(asset, filename, allowLocal = false, progress) {
+ return withCacheLock(filename + '.lock', () => obtainLockedAsset(asset, filename, allowLocal, progress));
+}
+async function obtainLockedAsset(asset, filename, allowLocal, progress) {
assert(/^[a-f0-9]{64}$/.test(asset.sha256), 'Require a pinned SHA256');
const url = new URL(asset.url);
- if (url.protocol !== 'file:') return download(asset, filename);
+ if (url.protocol !== 'file:') return download(asset, filename, progress);
assert(allowLocal, 'Local assets require an explicitly supplied local manifest');
if (await sha256(filename).catch(error => { if (error.code !== 'ENOENT') throw error; }) === asset.sha256) return;
await mkdir(path.dirname(filename), { recursive: true });
diff --git a/tests/release-workflows.test.mjs b/tests/release-workflows.test.mjs
index 3aea70d3..6097dfc0 100644
--- a/tests/release-workflows.test.mjs
+++ b/tests/release-workflows.test.mjs
@@ -267,6 +267,7 @@ test('daily build and publication are separate manual entries without an indepen
assert(build.includes('name: ' + candidateJobName) && build.includes('ref: ${{ steps.source.outputs.source_sha }}'));
assert(build.includes("github.ref == 'refs/heads/main' || github.ref == 'refs/heads/feature/motion'"));
assert(build.includes('--template-env=dev') && !build.includes('--template-env=prod'));
+ assert(build.includes('tests/native-runtime.test.ts'), 'Candidate checks include the integrated native-preparation regression');
assert(build.includes('HYPERFRAMES_BROWSER_PATH: /usr/bin/google-chrome') && build.includes('\"$HYPERFRAMES_BROWSER_PATH\" --version'));
assert(!/apt-get install[^\n]*\bchromium\b/.test(build), 'Candidate builds must not install Ubuntu desktop snaps');
assert.match(build, /version:\n(?:[^\n]*\n)*? required: false\n default: ''/);