bigbrain-memory 1.1.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- bigbrain/__init__.py +3 -0
- bigbrain/cli.py +250 -0
- bigbrain/core.py +752 -0
- bigbrain/install.py +271 -0
- bigbrain/llm.py +93 -0
- bigbrain/mcp_server.py +159 -0
- bigbrain/schemas.py +191 -0
- bigbrain/source.py +389 -0
- bigbrain_memory-1.1.1.dist-info/METADATA +420 -0
- bigbrain_memory-1.1.1.dist-info/RECORD +14 -0
- bigbrain_memory-1.1.1.dist-info/WHEEL +5 -0
- bigbrain_memory-1.1.1.dist-info/entry_points.txt +2 -0
- bigbrain_memory-1.1.1.dist-info/licenses/LICENSE +21 -0
- bigbrain_memory-1.1.1.dist-info/top_level.txt +1 -0
bigbrain/__init__.py
ADDED
bigbrain/cli.py
ADDED
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
"""BigBrain command-line interface.
|
|
2
|
+
|
|
3
|
+
bigbrain init Scaffold .bigbrain/ in the current directory
|
|
4
|
+
bigbrain install Scaffold + wire into whatever AI tooling is present
|
|
5
|
+
bigbrain index Print INDEX.md
|
|
6
|
+
bigbrain read <file_id> Print a memory file
|
|
7
|
+
bigbrain log ... Append a transaction log entry
|
|
8
|
+
bigbrain compile Reconcile log.md into memory/*.md and rebuild INDEX.md
|
|
9
|
+
bigbrain status Print engine state as JSON
|
|
10
|
+
bigbrain serve-mcp Run the MCP stdio server (for hosts with native tool-calling)
|
|
11
|
+
"""
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
import argparse
|
|
15
|
+
import json
|
|
16
|
+
import sys
|
|
17
|
+
from pathlib import Path
|
|
18
|
+
|
|
19
|
+
from . import core
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def _cmd_init(args: argparse.Namespace) -> int:
|
|
23
|
+
p = core.init_engine(Path(args.path))
|
|
24
|
+
print(f"[BigBrain] Initialized at {p.big_brain_dir}")
|
|
25
|
+
return 0
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _cmd_install(args: argparse.Namespace) -> int:
|
|
29
|
+
from . import install as install_mod
|
|
30
|
+
|
|
31
|
+
report = install_mod.install(Path(args.path), force=args.force)
|
|
32
|
+
for line in report.lines:
|
|
33
|
+
print(line)
|
|
34
|
+
return 0
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def _cmd_index(args: argparse.Namespace) -> int:
|
|
38
|
+
print(core.read_index(Path(args.path)), end="")
|
|
39
|
+
return 0
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def _cmd_read(args: argparse.Namespace) -> int:
|
|
43
|
+
try:
|
|
44
|
+
print(core.read_memory(Path(args.path), args.file_id), end="")
|
|
45
|
+
except FileNotFoundError as e:
|
|
46
|
+
print(f"[BigBrain] Error: {e}", file=sys.stderr)
|
|
47
|
+
return 1
|
|
48
|
+
return 0
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def _cmd_log(args: argparse.Namespace) -> int:
|
|
52
|
+
try:
|
|
53
|
+
core.append_log(Path(args.path), args.type, args.target, args.summary, args.details)
|
|
54
|
+
except ValueError as e:
|
|
55
|
+
print(f"[BigBrain] Error: {e}", file=sys.stderr)
|
|
56
|
+
return 1
|
|
57
|
+
print(f"[BigBrain] Logged {args.type.upper()} targeting '{args.target}'")
|
|
58
|
+
return 0
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def _cmd_compile(args: argparse.Namespace) -> int:
|
|
62
|
+
try:
|
|
63
|
+
result = core.compile_memory(
|
|
64
|
+
Path(args.path), reason=args.reason, use_llm=args.llm, llm_timeout=args.llm_timeout
|
|
65
|
+
)
|
|
66
|
+
except core.LockError as e:
|
|
67
|
+
print(f"[BigBrain] Error: {e}", file=sys.stderr)
|
|
68
|
+
return 1
|
|
69
|
+
print(
|
|
70
|
+
f"[BigBrain] Compiled ({result['reason']}, mode={result['mode']}): "
|
|
71
|
+
f"{result['entries_processed']} entries -> {len(result['files_updated'])} file(s) updated."
|
|
72
|
+
)
|
|
73
|
+
for w in result.get("warnings", []):
|
|
74
|
+
print(f" ! {w}")
|
|
75
|
+
for f in result["files_updated"]:
|
|
76
|
+
print(f" - {f}")
|
|
77
|
+
return 0
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def _cmd_grep(args: argparse.Namespace) -> int:
|
|
81
|
+
hits = core.grep(Path(args.path), args.term, include_log=args.include_log)
|
|
82
|
+
if not hits:
|
|
83
|
+
print("[BigBrain] No matches.")
|
|
84
|
+
return 0
|
|
85
|
+
for h in hits:
|
|
86
|
+
print(f"{h['file_id']} ({h['path']}:{h['line']}): {h['text']}")
|
|
87
|
+
return 0
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def _cmd_search(args: argparse.Namespace) -> int:
|
|
91
|
+
hits = core.search(Path(args.path), args.query, top_n=args.top)
|
|
92
|
+
if not hits:
|
|
93
|
+
print("[BigBrain] No relevant memory files found.")
|
|
94
|
+
return 0
|
|
95
|
+
for h in hits:
|
|
96
|
+
print(f"{h['file_id']} (score={h['score']}, {h['path']}): {h['snippet']}")
|
|
97
|
+
return 0
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def _cmd_doctor(args: argparse.Namespace) -> int:
|
|
101
|
+
result = core.doctor(Path(args.path), fix=args.fix)
|
|
102
|
+
if result["fixed"]:
|
|
103
|
+
print("[BigBrain] Fixed:")
|
|
104
|
+
for f in result["fixed"]:
|
|
105
|
+
print(f" - {f}")
|
|
106
|
+
if result["issues"]:
|
|
107
|
+
print("[BigBrain] Issues:")
|
|
108
|
+
for i in result["issues"]:
|
|
109
|
+
print(f" ! {i}")
|
|
110
|
+
if not result["issues"] and not result["fixed"]:
|
|
111
|
+
print("[BigBrain] No issues found.")
|
|
112
|
+
return 1 if result["issues"] else 0
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def _cmd_status(args: argparse.Namespace) -> int:
|
|
116
|
+
print(json.dumps(core.status(Path(args.path)), indent=2))
|
|
117
|
+
return 0
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def _cmd_rebuild_index(args: argparse.Namespace) -> int:
|
|
121
|
+
core.rebuild_index(Path(args.path))
|
|
122
|
+
return 0
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def _cmd_serve_mcp(args: argparse.Namespace) -> int:
|
|
126
|
+
from . import mcp_server
|
|
127
|
+
|
|
128
|
+
mcp_server.serve(Path(args.path))
|
|
129
|
+
return 0
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def _cmd_source(args: argparse.Namespace) -> int:
|
|
133
|
+
from . import source
|
|
134
|
+
try:
|
|
135
|
+
root = Path(args.path)
|
|
136
|
+
def progress(message):
|
|
137
|
+
print(f"[BigBrain] {message}", file=sys.stderr, flush=True)
|
|
138
|
+
if args.command == "source-refresh":
|
|
139
|
+
result = source.refresh(root, rebuild=args.rebuild, progress=progress)
|
|
140
|
+
elif args.command == "source-status":
|
|
141
|
+
result = source.status(root, progress=progress)
|
|
142
|
+
elif args.command == "source-search":
|
|
143
|
+
result = source.search(root, args.query, top_n=args.top, progress=progress)
|
|
144
|
+
elif args.command == "source-files":
|
|
145
|
+
result = source.list_files(root, args.prefix, args.limit, args.offset, progress=progress)
|
|
146
|
+
else:
|
|
147
|
+
result = source.read(root, args.file, args.start_line, args.max_lines, progress=progress)
|
|
148
|
+
print(json.dumps(result, indent=2))
|
|
149
|
+
report = result.get("status", result)
|
|
150
|
+
return 0 if report["complete"] else 1
|
|
151
|
+
except KeyboardInterrupt:
|
|
152
|
+
print("[BigBrain] Source indexing interrupted. Uncommitted source-cache updates are rolled back; memory is unchanged.",
|
|
153
|
+
file=sys.stderr, flush=True)
|
|
154
|
+
return 130
|
|
155
|
+
except (source.SourceError, core.LockError, OSError) as exc:
|
|
156
|
+
print(f"[BigBrain] Error: {exc}", file=sys.stderr)
|
|
157
|
+
return 1
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
161
|
+
parser = argparse.ArgumentParser(prog="bigbrain", description="Deterministic filesystem-first memory engine.")
|
|
162
|
+
parser.add_argument("--path", default=".", help="Project root (default: current directory)")
|
|
163
|
+
sub = parser.add_subparsers(dest="command", required=True)
|
|
164
|
+
|
|
165
|
+
sub.add_parser("init", help="Scaffold .bigbrain/ in the current directory").set_defaults(func=_cmd_init)
|
|
166
|
+
|
|
167
|
+
p_install = sub.add_parser("install", help="Scaffold + wire BigBrain into whatever AI tooling is present")
|
|
168
|
+
p_install.add_argument("--force", action="store_true", help="Re-write wiring blocks even if already present")
|
|
169
|
+
p_install.set_defaults(func=_cmd_install)
|
|
170
|
+
|
|
171
|
+
sub.add_parser("index", help="Print INDEX.md").set_defaults(func=_cmd_index)
|
|
172
|
+
|
|
173
|
+
p_read = sub.add_parser("read", help="Print a memory file by file_id")
|
|
174
|
+
p_read.add_argument("file_id")
|
|
175
|
+
p_read.set_defaults(func=_cmd_read)
|
|
176
|
+
|
|
177
|
+
p_log = sub.add_parser("log", help="Append a transaction log entry")
|
|
178
|
+
p_log.add_argument("--type", required=True, choices=core.LOG_TYPES)
|
|
179
|
+
p_log.add_argument("--target", required=True, help="Target memory file_id")
|
|
180
|
+
p_log.add_argument("--summary", required=True)
|
|
181
|
+
p_log.add_argument("--details", required=True)
|
|
182
|
+
p_log.set_defaults(func=_cmd_log)
|
|
183
|
+
|
|
184
|
+
p_compile = sub.add_parser("compile", help="Reconcile log.md into memory/*.md and rebuild INDEX.md")
|
|
185
|
+
p_compile.add_argument("--reason", default="manual", help="Why compilation was triggered")
|
|
186
|
+
p_compile.add_argument(
|
|
187
|
+
"--llm",
|
|
188
|
+
action="store_true",
|
|
189
|
+
help="Use a configured LLM CLI to dedupe/resolve contradictions per file "
|
|
190
|
+
"(see .bigbrain/config.yml); falls back to deterministic merge per-file on failure",
|
|
191
|
+
)
|
|
192
|
+
p_compile.add_argument("--llm-timeout", type=int, default=120, help="Seconds before an --llm call is abandoned")
|
|
193
|
+
p_compile.set_defaults(func=_cmd_compile)
|
|
194
|
+
|
|
195
|
+
p_grep = sub.add_parser("grep", help="Exact-substring search across memory files (fallback when file_id is unknown)")
|
|
196
|
+
p_grep.add_argument("term")
|
|
197
|
+
p_grep.add_argument("--include-log", action="store_true", help="Also search log.md and log.archive.md")
|
|
198
|
+
p_grep.set_defaults(func=_cmd_grep)
|
|
199
|
+
|
|
200
|
+
p_search = sub.add_parser(
|
|
201
|
+
"search", help="Ranked fuzzy/word-overlap search across memory files (use when exact wording is unknown)"
|
|
202
|
+
)
|
|
203
|
+
p_search.add_argument("query")
|
|
204
|
+
p_search.add_argument("--top", type=int, default=8, help="Max results to return")
|
|
205
|
+
p_search.set_defaults(func=_cmd_search)
|
|
206
|
+
|
|
207
|
+
sub.add_parser("status", help="Print engine state as JSON").set_defaults(func=_cmd_status)
|
|
208
|
+
sub.add_parser("rebuild-index", help="Rebuild INDEX.md from memory/*.md").set_defaults(func=_cmd_rebuild_index)
|
|
209
|
+
|
|
210
|
+
p_doctor = sub.add_parser("doctor", help="Validate .bigbrain/ and optionally repair common issues")
|
|
211
|
+
p_doctor.add_argument("--fix", action="store_true", help="Apply auto-fixes instead of just reporting")
|
|
212
|
+
p_doctor.set_defaults(func=_cmd_doctor)
|
|
213
|
+
|
|
214
|
+
sub.add_parser("serve-mcp", help="Run the MCP stdio server").set_defaults(func=_cmd_serve_mcp)
|
|
215
|
+
|
|
216
|
+
p = sub.add_parser("source-refresh", help="Incrementally reconcile the Git working tree source index")
|
|
217
|
+
p.add_argument("--rebuild", action="store_true", help="Discard and rebuild the derived source cache")
|
|
218
|
+
p.set_defaults(func=_cmd_source)
|
|
219
|
+
p = sub.add_parser("source-files", help="Browse a bounded inventory of eligible source files")
|
|
220
|
+
p.add_argument("--prefix", default="")
|
|
221
|
+
p.add_argument("--limit", type=int, default=100)
|
|
222
|
+
p.add_argument("--offset", type=int, default=0)
|
|
223
|
+
p.set_defaults(func=_cmd_source)
|
|
224
|
+
sub.add_parser("source-status", help="Refresh and report source coverage and freshness").set_defaults(func=_cmd_source)
|
|
225
|
+
p = sub.add_parser("source-search", help="Search current source and documentation (JSON results)")
|
|
226
|
+
p.add_argument("query")
|
|
227
|
+
p.add_argument("--top", type=int, default=8)
|
|
228
|
+
p.set_defaults(func=_cmd_source)
|
|
229
|
+
p = sub.add_parser("source-read", help="Read a bounded source snapshot with hash and line numbers")
|
|
230
|
+
p.add_argument("file")
|
|
231
|
+
p.add_argument("--start-line", type=int, default=1)
|
|
232
|
+
p.add_argument("--max-lines", type=int, default=80)
|
|
233
|
+
p.set_defaults(func=_cmd_source)
|
|
234
|
+
|
|
235
|
+
# Accept both `--path ROOT command` and `command --path ROOT`, including
|
|
236
|
+
# the invocation generated by older installers.
|
|
237
|
+
for command_parser in sub.choices.values():
|
|
238
|
+
command_parser.add_argument("--path", default=argparse.SUPPRESS, help="Project root")
|
|
239
|
+
|
|
240
|
+
return parser
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
def main(argv=None) -> int:
|
|
244
|
+
parser = build_parser()
|
|
245
|
+
args = parser.parse_args(argv)
|
|
246
|
+
return args.func(args)
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
if __name__ == "__main__":
|
|
250
|
+
sys.exit(main())
|