File size: 1,559 Bytes
ce45eb0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
"""CLI command handlers."""
from __future__ import annotations

from ..manager import ContextManager
from ..ingest.files import ingest_file


def _mgr(args) -> ContextManager:
    return ContextManager.create("cli", path=args.db)


def dispatch(args) -> int:
    ctx = _mgr(args)
    if args.cmd == "init":
        print(f"initialized store at {args.db}"); return 0
    if args.cmd == "remember":
        it = ctx.remember(args.content, expert=args.expert, scope=args.scope,
                          importance=args.importance)
        print(f"remembered {it.id} [{it.expert}]"); return 0
    if args.cmd == "ingest":
        items = ingest_file(args.path, scope=args.scope)
        for it in items:
            ctx.store.add(it)
        print(f"ingested {len(items)} chunks from {args.path}"); return 0
    if args.cmd in ("recall", "pack"):
        pack = ctx.build_pack(args.query, scope=args.scope,
                              top_experts=args.top_experts, max_tokens=args.max_tokens)
        print(pack.to_prompt()); return 0
    if args.cmd == "inspect":
        print(ctx.inspect(args.query, scope=args.scope,
                          top_experts=args.top_experts, max_tokens=args.max_tokens)); return 0
    if args.cmd == "serve":
        if args.transport == "rest":
            from ..serve.rest.app import serve as serve_rest
            serve_rest(host=args.host, port=args.port, manager=ctx); return 0
        from ..serve.mcp.server import serve
        serve(transport=args.transport, host=args.host, port=args.port); return 0
    return 1