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

Function executeMemoryCommand

src/node/services/tools/memory.ts:126–209  ·  view source on GitHub ↗
(
  memoryService: MemoryService,
  ctx: MemoryScopeContext,
  input: MemoryCommandInput,
  checkWriteAccess: (virtualPath: string) => MemoryToolResult | null
)

Source from the content-addressed store, hash-verified

124 * short-circuits the dispatch.
125 */
126export async function executeMemoryCommand(
127 memoryService: MemoryService,
128 ctx: MemoryScopeContext,
129 input: MemoryCommandInput,
130 checkWriteAccess: (virtualPath: string) => MemoryToolResult | null
131): Promise<MemoryToolResult> {
132 try {
133 switch (input.command) {
134 case "view": {
135 if (input.path == null) {
136 return { success: false, error: "view requires 'path'" };
137 }
138 return await memoryService.view(ctx, input.path, {
139 offset: input.offset ?? undefined,
140 limit: input.limit ?? undefined,
141 });
142 }
143 case "create": {
144 if (input.path == null || input.file_text == null) {
145 return { success: false, error: "create requires 'path' and 'file_text'" };
146 }
147 return (
148 checkWriteAccess(input.path) ??
149 (await memoryService.create(ctx, input.path, input.file_text, "agent"))
150 );
151 }
152 case "str_replace": {
153 if (input.path == null || input.old_str == null) {
154 return { success: false, error: "str_replace requires 'path' and 'old_str'" };
155 }
156 return (
157 checkWriteAccess(input.path) ??
158 (await memoryService.strReplace(
159 ctx,
160 input.path,
161 input.old_str,
162 input.new_str ?? "",
163 "agent"
164 ))
165 );
166 }
167 case "insert": {
168 if (input.path == null || input.insert_line == null || input.insert_text == null) {
169 return {
170 success: false,
171 error: "insert requires 'path', 'insert_line' and 'insert_text'",
172 };
173 }
174 return (
175 checkWriteAccess(input.path) ??
176 (await memoryService.insert(
177 ctx,
178 input.path,
179 input.insert_line,
180 input.insert_text,
181 "agent"
182 ))
183 );

Callers 2

createMemoryToolFunction · 0.85

Calls 8

getErrorMessageFunction · 0.90
checkWriteAccessFunction · 0.85
viewMethod · 0.80
strReplaceMethod · 0.80
insertMethod · 0.80
deletePathMethod · 0.80
createMethod · 0.65
renameMethod · 0.65

Tested by

no test coverage detected