Files
memind/scripts/check-conversation-package-manifest.mjs
T

59 lines
2.1 KiB
JavaScript

#!/usr/bin/env node
import fs from 'node:fs/promises';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { verifyConversationPackageManifest } from '../mindspace-conversation-package-verify.mjs';
import { createLocalMindSpaceStorageAdapter } from '../mindspace-storage-adapter.mjs';
const repoRoot = path.join(path.dirname(fileURLToPath(import.meta.url)), '..');
function usage() {
return [
'Usage: node scripts/check-conversation-package-manifest.mjs --manifest <manifest.json> [--storage-root <dir>]',
'',
'Validates that a conversation package manifest has required metadata and every artifact has',
'a readable canonicalUrl or a storageKey under manifest.storagePrefix.',
].join('\n');
}
function parseArgs(argv) {
let manifestPath = null;
let storageRoot = null;
for (let i = 2; i < argv.length; i += 1) {
if (argv[i] === '--manifest' && argv[i + 1]) {
manifestPath = path.resolve(argv[i + 1]);
i += 1;
} else if (argv[i] === '--storage-root' && argv[i + 1]) {
storageRoot = path.resolve(argv[i + 1]);
i += 1;
} else if (argv[i] === '--help' || argv[i] === '-h') {
console.log(usage());
process.exit(0);
}
}
if (!manifestPath) {
console.error(usage());
process.exit(2);
}
return { manifestPath, storageRoot };
}
const { manifestPath, storageRoot } = parseArgs(process.argv);
const manifest = JSON.parse(await fs.readFile(manifestPath, 'utf8'));
const storageAdapter = storageRoot ? createLocalMindSpaceStorageAdapter(storageRoot) : null;
const result = await verifyConversationPackageManifest(manifest, {
statObject: storageAdapter ? (key) => storageAdapter.statObject(key) : null,
});
if (result.ok) {
console.log(`OK: conversation package manifest ${path.relative(repoRoot, manifestPath) || manifestPath}`);
process.exit(0);
}
console.error(`Found ${result.issues.length} conversation package manifest issue(s):`);
for (const item of result.issues) {
const suffix = item.artifactId ? ` [artifact ${item.artifactId}]` : '';
console.error(`- ${item.code}${suffix}: ${item.message}`);
}
process.exit(1);