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))
| 263 | // ExecuteWithStream runs the subcommand. The streaming callback is unused — |
| 264 | // context operations are short — but the signature satisfies the contract. |
| 265 | func (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 { |
no test coverage detected