Files
openmotion/scripts/check.ts
open-design-crew[bot] 6d38d942f2 feat(desktop): cloud-first thin shell, local atoms, signed config, and Sentry observability (#1001)
* feat(desktop): cloud-first thin shell, local atoms, signed config, and complete Sentry observability

* feat(desktop): add in-app update banner, release notes preview, and mandatory update gate

* fix(ci): resolve backend typecheck, dock short-host floor, ci-scope, and source privacy scan

* fix(desktop): address all P1 and P2 security/robustness review findings on PR #1001

* fix(local-atoms): accept TOML array-of-tables headers in merged structure check

---------

Co-authored-by: heggria <bshengtao@gmail.com>
2026-11-24 19:13:55 -08:00

110 lines
6.4 KiB
TypeScript

import { isMain } from '../shared/entry.ts';
import { readFile, readdir } from 'node:fs/promises';
import { fileURLToPath } from 'node:url';
import { stripTypeScriptTypes } from 'node:module';
import path from 'node:path';
import assert from 'node:assert/strict';
import { releaseProfile } from '../shared/mcp-registry.ts';
import { checkDesign } from './design-check.ts';
import { checkI18n } from './check-i18n.ts';
import { checkLayout } from './check-layout.ts';
import { checkRouting } from './check-routing.ts';
import { getWorkflow, markdownAnchors, workflowLinkAnchors, workflowRegistry, phase1WorkflowNames } from '../shared/workflow.ts';
const root = fileURLToPath(new URL('../', import.meta.url));
// Hosts parse SKILL.md frontmatter as YAML, so a plain value containing ": " or " #"
// is a parse error there even though a line-based regex accepts it.
export function assertSkillFrontmatterYaml(frontmatter: string, skill: string) {
for (const line of frontmatter.split('\n')) {
if (!line.trim() || /^\s/.test(line)) continue;
const field = line.match(/^([A-Za-z_][\w-]*):(?: (.*))?$/);
assert.ok(field, `${skill} frontmatter line is not a YAML key: ${line}`);
const value = (field[2] ?? '').trim();
if (!value || /^[>|][+-]?$/.test(value) || /^'[^']*'$|^"(?:[^"\\]|\\.)*"$/.test(value)) continue;
assert.ok(!/^[-?:,[\]{}#&*!|>'"%@`]/.test(value) && !/: | #|:$/.test(value),
`${skill} frontmatter ${field[1]} is not a valid plain YAML value; use a folded block (>-) or quotes`);
}
}
async function stripTypeScriptRecursive(folder: string): Promise<void> {
let entries;
try {
entries = await readdir(folder, { withFileTypes: true });
} catch (error) {
if ((error as NodeJS.ErrnoException).code === 'ENOENT') return;
throw error;
}
for (const entry of entries) {
if (entry.name === 'node_modules' || entry.name === 'dist' || entry.name === 'build') continue;
const full = path.join(folder, entry.name);
if (entry.isDirectory()) {
await stripTypeScriptRecursive(full);
} else if (entry.isFile() && entry.name.endsWith('.ts') && !entry.name.endsWith('.d.ts')) {
stripTypeScriptTypes(await readFile(full, 'utf8'), { mode: 'strip' });
}
}
}
export async function check() {
const manifest = JSON.parse(await readFile(path.join(root, '.codex-plugin/plugin.json'), 'utf8'));
const marketplace = JSON.parse(await readFile(path.join(root, 'marketplace.example.json'), 'utf8'));
assert.equal(manifest.name, marketplace.plugins[0].name);
assert.deepEqual(manifest.skills, ['./skills/', './.codex-plugin/onboarding/']);
const pkg = JSON.parse(await readFile(path.join(root, 'package.json'), 'utf8'));
const lock = JSON.parse(await readFile(path.join(root, 'package-lock.json'), 'utf8'));
assert.equal(pkg.version, manifest.version);
assert.equal(lock.packages[''].version, manifest.version);
assert.equal(pkg.dependencies.hyperframes, '0.9.7');
assert.equal(lock.packages['node_modules/hyperframes'].version, pkg.dependencies.hyperframes);
assert.equal(manifest.mcpServers, './.mcp.json');
const mcp = JSON.parse(await readFile(path.join(root, '.mcp.json'), 'utf8'));
assert.equal(mcp.mcpServers.openmotion.type, 'http');
assert.match(mcp.mcpServers.openmotion.url, /^https?:\/\/[^/]+\/mcp$/);
assert.ok(!JSON.stringify(mcp).includes('${'), 'MCP launch paths cannot depend on placeholder expansion');
assert.equal(marketplace.plugins[0].source.path, './');
for (const folder of ['src', 'web', 'shared', 'scripts', 'tests', 'gateway', 'tracking']) {
await stripTypeScriptRecursive(path.join(root, folder));
}
for (const file of ['server.ts', 'design-projects.ts', 'review-comments.ts', 'hyperframes.ts', 'template-library.ts', 'template-catalog.ts', 'prism-templates.ts', 'drizzle.config.ts']) {
stripTypeScriptTypes(await readFile(path.join(root, file), 'utf8'), { mode: 'strip' });
}
for (const folder of ['skills', 'library/skills']) for (const entry of await readdir(path.join(root, folder), { withFileTypes: true })) {
if (!entry.isDirectory() || entry.name.startsWith('.')) continue;
const document = await readFile(path.join(root, folder, entry.name, 'SKILL.md'), 'utf8');
const frontmatter = document.match(/^---\n([\s\S]*?)\n---(?:\n|$)/)?.[1];
assert.ok(frontmatter, `Missing skill frontmatter: ${entry.name}`);
assert.match(frontmatter, /^name: [a-z0-9-]+$/m);
assert.match(frontmatter, /^description: .+$/m);
assertSkillFrontmatterYaml(frontmatter, entry.name);
assert.equal(document.match(/^name: (.+)$/m)?.[1], entry.name);
}
// Agents choose routes from these texts, so a stale "placeholder" note hides a ready Skill.
const readySkills = Object.values(workflowRegistry).filter(definition => definition.status === 'ready')
.map(definition => Object.values(definition.sections)[0]?.match(/^skills\/([^/]+)\//)?.[1]).filter(Boolean) as string[];
for (const [workflow, definition] of Object.entries(workflowRegistry)) {
if (releaseProfile === 'phase1' && !phase1WorkflowNames.includes(workflow)) continue;
for (const section of Object.keys(definition.sections)) {
const document = await getWorkflow(section, workflow);
assert.ok(document.content.trim(), `Empty workflow section: ${workflow}/${section}`);
for (const skill of readySkills) assert.doesNotMatch(document.content, new RegExp(`${skill} (?:remains|is still|is) (?:an? )?placeholder`, 'i'),
`${document.documentId} calls ready Skill ${skill} a placeholder`);
for (const reference of document.references) {
const linked = await getWorkflow(reference.section, reference.workflow);
assert.equal(linked.documentId, reference.documentId, `Unreachable workflow link from ${document.documentId}`);
}
for (const link of workflowLinkAnchors(document.content, document.documentId)) {
const linked = link.documentId === document.documentId ? document : await getWorkflow(link.section, link.workflow);
assert.ok(markdownAnchors(linked.content).has(link.anchor), `Missing heading anchor in ${document.documentId}: ${link.href}`);
}
}
}
assert.match(await readFile(path.join(root, 'templates/index.html'), 'utf8'), /data-composition-id/);
await checkI18n();
await checkRouting();
await checkDesign();
await checkLayout();
console.log('Plugin manifest, marketplace, skill, i18n, routing, layout and TypeScript syntax checks passed.');
}
if (isMain(import.meta.url)) await check();