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

Method install

packages/agent-core/src/plugin/manager.ts:62–140  ·  view source on GitHub ↗
(source: string)

Source from the content-addressed store, hash-verified

60 }
61
62 async install(source: string): Promise<PluginRecord> {
63 const resolved = resolveInstallSource(source);
64
65 let normalizedRoot: string;
66 let originalSource: string;
67 let sourceType: PluginSource;
68 let parsed: ParsedManifestResult;
69 let id: string;
70 let github: PluginGithubMetadata | undefined;
71
72 if (resolved.kind === 'local-path') {
73 const sourceRoot = await normalizeInstallRoot(resolved.path);
74 originalSource = resolved.path;
75 sourceType = 'local-path';
76 parsed = await parseManifest(sourceRoot);
77 if (parsed.manifest === undefined) {
78 const msg = parsed.diagnostics.find((d) => d.severity === 'error')?.message ?? 'no manifest';
79 throw new Error(`Cannot install plugin at ${sourceRoot}: ${msg}`);
80 }
81 id = normalizePluginId(parsed.manifest.name);
82 normalizedRoot = await copyPluginToManagedRoot(this.kimiHomeDir, id, sourceRoot);
83 parsed = await parseManifest(normalizedRoot);
84 } else {
85 let zipUrl: string;
86 if (resolved.kind === 'github') {
87 const githubResolution = await resolveGithubSource(resolved);
88 zipUrl = githubResolution.tarballUrl;
89 originalSource = source.trim();
90 sourceType = 'github';
91 github = {
92 owner: resolved.owner,
93 repo: resolved.repo,
94 ref: githubResolution.ref,
95 };
96 } else {
97 zipUrl = resolved.path;
98 originalSource = resolved.path;
99 sourceType = 'zip-url';
100 }
101 const buffer = await downloadZip(zipUrl);
102 const tmpDir = await mkdtemp(path.join(tmpdir(), 'kimi-plugin-zip-'));
103 try {
104 const detectedRoot = await extractZip(buffer, tmpDir);
105 parsed = await parseManifest(detectedRoot);
106 if (parsed.manifest === undefined) {
107 const msg = parsed.diagnostics.find((d) => d.severity === 'error')?.message ?? 'no manifest';
108 throw new Error(`Cannot install plugin from ${originalSource}: ${msg}`);
109 }
110 id = normalizePluginId(parsed.manifest.name);
111 normalizedRoot = await copyPluginToManagedRoot(this.kimiHomeDir, id, detectedRoot);
112 parsed = await parseManifest(normalizedRoot);
113 } finally {
114 await rm(tmpDir, { recursive: true, force: true });
115 }
116 }
117
118 if (parsed.manifest === undefined) {
119 const msg = parsed.diagnostics.find((d) => d.severity === 'error')?.message ?? 'no manifest';

Callers

nothing calls this directly

Calls 13

persistMethod · 0.95
resolveInstallSourceFunction · 0.90
parseManifestFunction · 0.90
normalizePluginIdFunction · 0.90
resolveGithubSourceFunction · 0.90
downloadZipFunction · 0.90
extractZipFunction · 0.90
normalizeInstallRootFunction · 0.85
copyPluginToManagedRootFunction · 0.85
mkdtempFunction · 0.85
recordFromFunction · 0.85
getMethod · 0.65

Tested by

no test coverage detected