MCPcopy Index your code
hub / github.com/coder/mux / create

Method create

src/node/services/memoryService.ts:700–734  ·  view source on GitHub ↗
(
    ctx: MemoryScopeContext,
    virtualPath: string,
    fileText: string,
    actor: MemoryActor
  )

Source from the content-addressed store, hash-verified

698 }
699
700 async create(
701 ctx: MemoryScopeContext,
702 virtualPath: string,
703 fileText: string,
704 actor: MemoryActor
705 ): Promise<MemoryCommandResult> {
706 return this.runCommand(async () => {
707 const parsed = parseMemoryPath(virtualPath);
708 const scope = this.requireFilePath(parsed, virtualPath);
709 assertWithinFileSizeCap(fileText);
710 // create is a write: materialize the scope root on first use.
711 const store = await this.resolveStore(ctx, scope, parsed.relPath, { createRoot: true });
712 return this.locks.withLock(store.physicalRoot, async () => {
713 const existing = await store.kind(parsed.relPath);
714 if (existing !== null) {
715 throw new MemoryCommandError(
716 `A ${existing === "dir" ? "directory" : "file"} already exists at ${virtualPath}. To overwrite a file, delete it first, then create it.`
717 );
718 }
719 const files = await store.listFiles();
720 if (files.length >= MEMORY_MAX_FILES_PER_SCOPE) {
721 throw new MemoryCommandError(
722 `The ${scope} memory scope is full (${MEMORY_MAX_FILES_PER_SCOPE} files); delete unused files first`
723 );
724 }
725 await store.writeFile(parsed.relPath, fileText);
726 await this.recordUsage(ctx, scope, parsed.relPath, { write: true });
727 this.emitChange(ctx, scope, parsed.relPath, actor);
728 return {
729 success: true as const,
730 output: `Created ${toVirtualPath(scope, parsed.relPath)}`,
731 };
732 });
733 });
734 }
735
736 async strReplace(
737 ctx: MemoryScopeContext,

Callers

nothing calls this directly

Calls 12

runCommandMethod · 0.95
requireFilePathMethod · 0.95
resolveStoreMethod · 0.95
recordUsageMethod · 0.95
emitChangeMethod · 0.95
parseMemoryPathFunction · 0.85
assertWithinFileSizeCapFunction · 0.85
toVirtualPathFunction · 0.85
withLockMethod · 0.80
kindMethod · 0.65
listFilesMethod · 0.65
writeFileMethod · 0.65

Tested by

no test coverage detected