MCPcopy
hub / github.com/EveryInc/compound-engineering-plugin / writePiBundle

Function writePiBundle

src/targets/pi.ts:59–135  ·  view source on GitHub ↗
(outputRoot: string, bundle: PiBundle)

Source from the content-addressed store, hash-verified

57}
58
59export async function writePiBundle(outputRoot: string, bundle: PiBundle): Promise<void> {
60 const pluginName = bundle.pluginName ? sanitizeCodexPathComponent(bundle.pluginName) : undefined
61 const paths = resolvePiPaths(outputRoot, pluginName)
62 const manifest = pluginName
63 ? await readInstallManifestWithLegacyFallback(paths, pluginName)
64 : null
65 const currentPrompts = bundle.prompts.map((prompt) => `${sanitizePathName(prompt.name)}.md`)
66 const currentSkills = [
67 ...bundle.skillDirs.map((skill) => sanitizePathName(skill.name)),
68 ...bundle.generatedSkills.map((skill) => sanitizePathName(skill.name)),
69 ]
70 const currentAgents = bundle.agents.map((agent) => `${sanitizePathName(agent.name)}.md`)
71 const currentExtensions = bundle.extensions.map((extension) => extension.name)
72
73 await ensureDir(paths.skillsDir)
74 await ensureDir(paths.promptsDir)
75 await ensureDir(paths.extensionsDir)
76 await ensureDir(paths.agentsDir)
77
78 await cleanupStaleAgents(paths.skillsDir, null)
79 await cleanupRemovedPrompts(paths.promptsDir, manifest, currentPrompts)
80 await cleanupRemovedSkills(paths.skillsDir, manifest, currentSkills)
81 await cleanupRemovedAgents(paths.agentsDir, manifest, currentAgents)
82 await cleanupRemovedExtensions(paths.extensionsDir, manifest, currentExtensions)
83
84 for (const prompt of bundle.prompts) {
85 await writeText(path.join(paths.promptsDir, `${sanitizePathName(prompt.name)}.md`), prompt.content + "\n")
86 }
87
88 for (const skill of bundle.skillDirs) {
89 const skillName = sanitizePathName(skill.name)
90 const targetDir = path.join(paths.skillsDir, skillName)
91 await cleanupCurrentManagedSkillDir(targetDir, manifest, skillName)
92 await copySkillDir(skill.sourceDir, targetDir, transformContentForPi)
93 }
94
95 for (const skill of bundle.generatedSkills) {
96 const skillName = sanitizePathName(skill.name)
97 const targetDir = path.join(paths.skillsDir, skillName)
98 await cleanupCurrentManagedSkillDir(targetDir, manifest, skillName)
99 await writeText(path.join(targetDir, "SKILL.md"), skill.content + "\n")
100 }
101
102 for (const agent of bundle.agents) {
103 const agentFileName = `${sanitizePathName(agent.name)}.md`
104 const targetPath = path.join(paths.agentsDir, agentFileName)
105 await cleanupCurrentManagedAgentFile(targetPath, manifest, agentFileName)
106 await writeText(targetPath, agent.content + "\n")
107 }
108
109 for (const extension of bundle.extensions) {
110 await writeText(path.join(paths.extensionsDir, extension.name), extension.content + "\n")
111 }
112
113 if (bundle.mcporterConfig) {
114 const backupPath = await backupFile(paths.mcporterConfigPath)
115 if (backupPath) {
116 console.log(`Backed up existing MCPorter config to ${backupPath}`)

Callers 1

pi-writer.test.tsFile · 0.90

Calls 15

sanitizePathNameFunction · 0.90
ensureDirFunction · 0.90
cleanupStaleAgentsFunction · 0.90
writeTextFunction · 0.90
copySkillDirFunction · 0.90
backupFileFunction · 0.90
writeJsonFunction · 0.90
resolvePiPathsFunction · 0.85
cleanupRemovedExtensionsFunction · 0.85
ensurePiAgentsBlockFunction · 0.85

Tested by

no test coverage detected