mirror of
https://github.com/nexu-io/openmotion.git
synced 2026-12-01 23:51:42 +08:00
* feat(cloud): add Streamable HTTP MCP install guide, stateless onboarding API, and OpenMotion OAuth consent UI * fix(release): point legacy npm install-guide contract check at archived template * fix(cloud,onboarding,oauth): address PR #984 review feedback - Add DSH-compatible dshCardPresentation payload matching detailsSchema (id, title, description, video previewUrl, posterUrl, duration) and update docs/install.md + Zod schema regression coverage - Refactor OAuth 2.1 consent HTML to consume /design-system/ui.css, data-motion-ui, semantic --motion-* tokens, and shared .ui-* controls with zero local palette overrides or color literals - Extract shared inline-onboarding document renderer into shared/inline-onboarding-renderer.ts preserving the native_required external-media guard across CLI and cloud paths - Cache encoded onboarding preview media once per resourceVersion and replace entry-count HTML caching with a 16 MiB byte-bounded LRU cache - Restore local/DSH onboarding default (docs/templates/legacy-npm-install.md) in scripts/install-onboarding.mjs and repair moved relative links - Align canonical repository docs (AGENTS.md, CLAUDE.md, READMEs, release/adapter/skill docs) and fix .codex-plugin/onboarding anchor * test(onboarding,dsh): keep controls and DSH card tests independent of Studio build output * docs(onboarding): repoint legacy local/npm references and anchors to archived guide --------- Co-authored-by: 罗高 <luogao@users.noreply.github.com>
63 lines
4.9 KiB
JavaScript
63 lines
4.9 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import { mkdir, readFile } from 'node:fs/promises';
|
|
import path from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
import { runFile, sha256, writeAtomic, writeJSON } from './runtime-assets.mjs';
|
|
import { installationInstructions } from './install-onboarding.mjs';
|
|
import { checkReleaseVersion, releaseTemplateEnvironment } from './release-version.mjs';
|
|
|
|
export function validateGuideSpec(name, version) {
|
|
assert.match(name || '', /^(?:@[a-z0-9][a-z0-9._-]*\/)?[a-z0-9][a-z0-9._-]*$/, 'Require an npm package name');
|
|
assert(name.length <= 214, 'npm package name is too long');
|
|
checkReleaseVersion(version);
|
|
return version.includes('-test.') ? 'test' : 'stable';
|
|
}
|
|
|
|
export function validateGuideIdentity(pkg, manifest) {
|
|
validateGuideSpec(pkg.name, pkg.version);
|
|
assert.equal(pkg.private, false, 'Only public release candidates may have a public installation guide');
|
|
assert.equal(pkg.version, manifest.version, 'Package and embedded manifest versions differ');
|
|
assert.equal(manifest.schemaVersion, 1, 'Unsupported release manifest');
|
|
assert.equal(manifest.templateEnvironment, releaseTemplateEnvironment(pkg.version), 'Template defaults must match the release channel');
|
|
assert.equal(pkg.bin?.openmotion, 'scripts/npm-installer.mjs', 'Missing OpenMotion entry point');
|
|
assert.match(manifest.commit || '', /^[a-f0-9]{40}$/, 'Require the built source SHA');
|
|
for (const hash of [manifest.application?.sha256, manifest.locks?.npm, manifest.locks?.native]) assert.match(hash || '', /^[a-f0-9]{64}$/, 'Require release checksums');
|
|
const targets = Object.values(manifest.runtime?.targets || {});
|
|
assert(targets.length > 0 && targets.every(t => t.platform && t.arch && (t.platform === 'darwin' || t.minimumOS)), 'Require native target declarations (minimum system version required outside macOS)');
|
|
return pkg.version.includes('-test.') ? 'test' : 'stable';
|
|
}
|
|
|
|
export async function generateInstallGuide(tgz, output, candidate = false) {
|
|
const readEntry = async entry => JSON.parse(await runFile('tar', ['-xOf', path.resolve(tgz), entry]));
|
|
const pkg = await readEntry('package/package.json'), manifest = await readEntry('package/payload/release-npm.json');
|
|
const channel = validateGuideIdentity(pkg, manifest);
|
|
const digest = await sha256(tgz), packageSpec = `${pkg.name}@${pkg.version}`;
|
|
await installationInstructions(fileURLToPath(new URL('../', import.meta.url)), 'docs/templates/legacy-npm-install.md');
|
|
const values = { VERSION: pkg.version, PACKAGE_SPEC: packageSpec, CHANNEL: channel, COMMIT: manifest.commit,
|
|
TEMPLATE_ENVIRONMENT: manifest.templateEnvironment, TGZ_SHA256: digest,
|
|
TARGETS: Object.values(manifest.runtime.targets).map(t => `${t.platform}/${t.arch}${t.minimumOS ? ` (${t.minimumOS}+)` : ''}`).join(', '),
|
|
DETAILS_URL: `https://github.com/nexu-io/openmotion/blob/${manifest.commit}/docs/npm-installation.md` };
|
|
const guide = await readFile(new URL('../docs/templates/legacy-npm-install.md', import.meta.url), 'utf8');
|
|
// Source checkout commands never belong to a published npm installation.
|
|
const template = guide.replace(/<!-- source-only:start -->[\s\S]*?<!-- source-only:end -->\s*/g, '')
|
|
.replace(/^# Install OpenMotion$/m, '# Install OpenMotion {{VERSION}}')
|
|
.replace('skills@1.9.0 add nexu-io/openmotion ', `skills@1.9.0 add https://github.com/nexu-io/openmotion/tree/${manifest.commit} `);
|
|
assert(!template.includes('<!-- source-only:'), 'Installation guide has unmatched source-only markers');
|
|
// The repository warning is unnecessary after all release placeholders are resolved.
|
|
const text = (candidate ? '> Build preview only: this candidate is not an approved registry installation entry.\n\n' : '') + template.replace(/^If you are reading this file.*\n\n/m, '').replace(/\{\{([A-Z0-9_]+)\}\}/g, (_, key) => {
|
|
assert(Object.hasOwn(values, key), 'Unknown installation placeholder: ' + key); return values[key];
|
|
});
|
|
assert(!text.includes('{{'), 'Installation guide has unresolved placeholders');
|
|
await mkdir(output, { recursive: true });
|
|
await writeAtomic(path.join(output, 'install.md'), text);
|
|
const record = { schemaVersion: 1, candidate, packageName: pkg.name, version: pkg.version, packageSpec, channel,
|
|
templateEnvironment: manifest.templateEnvironment, commit: manifest.commit, tgzSHA256: digest,
|
|
applicationSHA256: manifest.application.sha256, locks: manifest.locks, guideSHA256: await sha256(path.join(output, 'install.md')) };
|
|
await writeJSON(path.join(output, 'install-record.json'), record);
|
|
return record;
|
|
}
|
|
if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
|
assert([4, 5].includes(process.argv.length) && (process.argv[4] === undefined || process.argv[4] === '--candidate'), 'Usage: install-guide.mjs <complete-npm.tgz> <output-directory> [--candidate]');
|
|
console.log(JSON.stringify(await generateInstallGuide(process.argv[2], path.resolve(process.argv[3]), process.argv[4] === '--candidate')));
|
|
}
|