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

Class PluginManager

packages/agent-core/src/plugin/manager.ts:37–315  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

35}
36
37export class PluginManager {
38 private readonly kimiHomeDir: string;
39 private records = new Map<string, PluginRecord>();
40
41 constructor(options: PluginManagerOptions) {
42 this.kimiHomeDir = options.kimiHomeDir;
43 }
44
45 async load(): Promise<void> {
46 const file = await readInstalled(this.kimiHomeDir);
47 const next = new Map<string, PluginRecord>();
48 for (const entry of file.plugins) {
49 next.set(entry.id, await this.materialize(entry));
50 }
51 this.records = next;
52 }
53
54 list(): readonly PluginRecord[] {
55 return [...this.records.values()].toSorted((a, b) => a.id.localeCompare(b.id));
56 }
57
58 get(id: string): PluginRecord | undefined {
59 return this.records.get(normalizePluginId(id));
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,

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected