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

Method ExecuteWithStream

cli/plugins/builtin_memory.go:216–289  ·  view source on GitHub ↗

ExecuteWithStream mirrors Execute — this plugin produces no incremental output, so the stream callback is ignored.

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

Source from the content-addressed store, hash-verified

214// ExecuteWithStream mirrors Execute — this plugin produces no incremental
215// output, so the stream callback is ignored.
216func (p *BuiltinMemoryPlugin) ExecuteWithStream(_ context.Context, args []string, _ func(string)) (string, error) {
217 adapter := currentMemoryAdapter()
218 if adapter == nil {
219 return "", errors.New("@memory: memory is not enabled in this session")
220 }
221 if len(args) == 0 {
222 return "", errors.New(`@memory: empty args. Example: <tool_call name="@memory" args='{"cmd":"remember","args":{"content":"User prefers Go"}}' />`)
223 }
224
225 cmd, inner, err := parseMemoryInvocation(args)
226 if err != nil {
227 return "", fmt.Errorf("@memory: %w", err)
228 }
229
230 switch cmd {
231 case "remember":
232 var in struct {
233 Content string `json:"content"`
234 Category string `json:"category"`
235 }
236 _ = json.Unmarshal([]byte(inner), &in)
237 if strings.TrimSpace(in.Content) == "" {
238 return "", errors.New(`@memory remember: "content" is required`)
239 }
240 return adapter.Remember(in.Content, in.Category)
241 case "profile":
242 fields, err := parseProfileFields(inner)
243 if err != nil {
244 return "", fmt.Errorf("@memory profile: %w", err)
245 }
246 if len(fields) == 0 {
247 return "", errors.New(`@memory profile: provide "fields" with at least one key/value`)
248 }
249 return adapter.UpdateProfile(fields)
250 case "forget":
251 var in struct {
252 Match string `json:"match"`
253 }
254 _ = json.Unmarshal([]byte(inner), &in)
255 if strings.TrimSpace(in.Match) == "" {
256 return "", errors.New(`@memory forget: "match" is required`)
257 }
258 return adapter.Forget(in.Match)
259 case "recall":
260 var in struct {
261 Query string `json:"query"`
262 }
263 _ = json.Unmarshal([]byte(inner), &in)
264 return adapter.Recall(in.Query)
265 case "map":
266 ga, ok := adapter.(GraphAccessor)
267 if !ok {
268 return "", errors.New("@memory map: knowledge graph not available")
269 }
270 return ga.GraphMap()
271 case "neighbors":
272 ga, ok := adapter.(GraphAccessor)
273 if !ok {

Callers 1

ExecuteMethod · 0.95

Calls 10

currentMemoryAdapterFunction · 0.85
parseMemoryInvocationFunction · 0.85
parseProfileFieldsFunction · 0.85
ErrorfMethod · 0.80
RememberMethod · 0.65
UpdateProfileMethod · 0.65
ForgetMethod · 0.65
RecallMethod · 0.65
GraphMapMethod · 0.65
GraphNeighborsMethod · 0.65

Tested by

no test coverage detected