(
ctx: MemoryScopeContext,
virtualPath: string,
fileText: string,
actor: MemoryActor
)
| 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, |
nothing calls this directly
no test coverage detected