MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / parseManifest

Function parseManifest

packages/agent-core/src/plugin/manifest.ts:42–135  ·  view source on GitHub ↗
(pluginRoot: string)

Source from the content-addressed store, hash-verified

40}
41
42export async function parseManifest(pluginRoot: string): Promise<ParsedManifestResult> {
43 const rootJsonPath = path.join(pluginRoot, KIMI_PLUGIN_ROOT_PATH);
44 const dirJsonPath = path.join(pluginRoot, KIMI_PLUGIN_DIR_PATH);
45 const rootJsonExists = await isFile(rootJsonPath);
46 const dirJsonExists = await isFile(dirJsonPath);
47
48 if (!rootJsonExists && !dirJsonExists) {
49 return {
50 diagnostics: [
51 {
52 severity: 'error',
53 message: `No manifest at ${KIMI_PLUGIN_ROOT_PATH} or ${KIMI_PLUGIN_DIR_PATH}`,
54 },
55 ],
56 };
57 }
58
59 const manifestPath = rootJsonExists ? rootJsonPath : dirJsonPath;
60 const manifestKind: PluginManifestKind = rootJsonExists ? 'kimi-plugin-root' : 'kimi-plugin-dir';
61 const shadowedManifestPath = rootJsonExists && dirJsonExists ? dirJsonPath : undefined;
62
63 let raw: unknown;
64 try {
65 raw = JSON.parse(await readFile(manifestPath, 'utf8'));
66 } catch (error) {
67 return {
68 manifestKind,
69 manifestPath,
70 shadowedManifestPath,
71 diagnostics: [
72 {
73 severity: 'error',
74 message: `Failed to parse ${path.relative(pluginRoot, manifestPath)}: ${(error as Error).message}`,
75 },
76 ],
77 };
78 }
79
80 if (!isObject(raw)) {
81 return {
82 manifestKind,
83 manifestPath,
84 shadowedManifestPath,
85 diagnostics: [{ severity: 'error', message: 'manifest must be a JSON object' }],
86 };
87 }
88
89 const diagnostics: PluginDiagnostic[] = [];
90
91 const name = typeof raw['name'] === 'string' ? raw['name'].trim() : '';
92 if (name.length === 0) {
93 diagnostics.push({ severity: 'error', message: '"name" is required' });
94 return { manifestKind, manifestPath, shadowedManifestPath, diagnostics };
95 }
96 if (!PLUGIN_NAME_REGEX.test(name)) {
97 diagnostics.push({
98 severity: 'error',
99 message: `"name" must match ${PLUGIN_NAME_REGEX} (got "${name}")`,

Callers 3

manifest.test.tsFile · 0.90
installMethod · 0.90
materializeMethod · 0.90

Calls 14

resolveSkillsFieldFunction · 0.85
readAuthorFunction · 0.85
readSessionStartFunction · 0.85
readMcpServersFunction · 0.85
readHooksFunction · 0.85
readCommandsFunction · 0.85
readInterfaceFunction · 0.85
isFileFunction · 0.70
isObjectFunction · 0.70
stringFieldFunction · 0.70
stringArrayFieldFunction · 0.70

Tested by

no test coverage detected