MCPcopy Create free account
hub / github.com/diillson/chatcli / ExecuteWithStream

Method ExecuteWithStream

cli/plugins/builtin_context.go:265–375  ·  view source on GitHub ↗

ExecuteWithStream runs the subcommand. The streaming callback is unused — context operations are short — but the signature satisfies the contract.

(_ context.Context, args []string, _ func(string))

Source from the content-addressed store, hash-verified

263// ExecuteWithStream runs the subcommand. The streaming callback is unused —
264// context operations are short — but the signature satisfies the contract.
265func (p *BuiltinContextPlugin) ExecuteWithStream(_ context.Context, args []string, _ func(string)) (string, error) {
266 adapter := currentContextAdapter()
267 if adapter == nil {
268 return "", fmt.Errorf("@context: context management not available in this session")
269 }
270 cmd, raw, err := parseContextInvocation(args)
271 if err != nil {
272 return "", fmt.Errorf("@context: %w", err)
273 }
274
275 switch cmd {
276 case "create":
277 name := strings.TrimSpace(jsonString(raw, "name"))
278 if name == "" {
279 return "", fmt.Errorf("@context create: \"name\" is required")
280 }
281 paths := contextStringSlice(raw, "paths", "path", "source", "corpus")
282 if len(paths) == 0 {
283 return "", fmt.Errorf("@context create: at least one source path is required (a corpus.jsonl, directory or file)")
284 }
285 mode := strings.TrimSpace(jsonString(raw, "mode"))
286 if mode == "" {
287 mode = "knowledge"
288 }
289 out, cerr := adapter.Create(name, mode, paths, jsonString(raw, "description", "desc"), jsonBool(raw, "force"))
290 return wrapContextErr("create", out, cerr)
291 case "update":
292 name := strings.TrimSpace(jsonString(raw, "name"))
293 if name == "" {
294 return "", fmt.Errorf("@context update: \"name\" is required")
295 }
296 out, uerr := adapter.Update(name,
297 contextStringSlice(raw, "paths", "path", "source"),
298 jsonString(raw, "mode"),
299 jsonString(raw, "description", "desc"),
300 contextStringSlice(raw, "tags", "tag"))
301 return wrapContextErr("update", out, uerr)
302 case "show":
303 name := strings.TrimSpace(jsonString(raw, "name"))
304 if name == "" {
305 return "", fmt.Errorf("@context show: \"name\" is required")
306 }
307 out, serr := adapter.Show(name)
308 return wrapContextErr("show", out, serr)
309 case "inspect":
310 name := strings.TrimSpace(jsonString(raw, "name"))
311 if name == "" {
312 return "", fmt.Errorf("@context inspect: \"name\" is required")
313 }
314 out, ierr := adapter.Inspect(name, jsonInt(raw, "chunk"))
315 return wrapContextErr("inspect", out, ierr)
316 case "merge":
317 name := strings.TrimSpace(jsonString(raw, "name"))
318 if name == "" {
319 return "", fmt.Errorf("@context merge: \"name\" is required")
320 }
321 sources := contextStringSlice(raw, "sources", "source", "contexts", "from")
322 if len(sources) < 2 {

Callers 1

ExecuteMethod · 0.95

Calls 15

currentContextAdapterFunction · 0.85
parseContextInvocationFunction · 0.85
jsonStringFunction · 0.85
contextStringSliceFunction · 0.85
jsonBoolFunction · 0.85
wrapContextErrFunction · 0.85
jsonIntFunction · 0.85
contextRagTopKFunction · 0.85
ErrorfMethod · 0.80
CreateMethod · 0.65
UpdateMethod · 0.65
ShowMethod · 0.65

Tested by

no test coverage detected