MCPcopy Create free account
hub / github.com/altic-dev/Pilot / writeFile

Function writeFile

src/lib/docker.ts:285–305  ·  view source on GitHub ↗
(sessionId: string, filePath: string, content: string)

Source from the content-addressed store, hash-verified

283 * Write a file to the container
284 */
285export async function writeFile(sessionId: string, filePath: string, content: string): Promise<void> {
286 const container = containerCache.get(sessionId);
287 if (!container) {
288 throw new Error(`No container found for session: ${sessionId}`);
289 }
290
291 try {
292 const pack = tar.pack();
293 const fileName = filePath.split('/').pop() || 'file';
294 const dirPath = filePath.substring(0, filePath.lastIndexOf('/')) || '/workspace';
295
296 pack.entry({ name: fileName }, content);
297 pack.finalize();
298
299 await container.putArchive(pack, { path: dirPath });
300 logger.info('File written to container', { sessionId, filePath });
301 } catch (error) {
302 logger.error('Failed to write file to container', { sessionId, filePath, error });
303 throw new Error(`Failed to write file: ${error}`);
304 }
305}
306
307/**
308 * Destroy container and clean up resources

Callers 5

copyPickerScriptMethod · 0.90
injectNextJsMethod · 0.90
injectHtmlTemplateMethod · 0.90
trackModificationsMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected