brain-framework 29.0.0__tar.gz → 29.0.1__tar.gz

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.
Files changed (33) hide show
  1. {brain_framework-29.0.0 → brain_framework-29.0.1}/PKG-INFO +1 -1
  2. {brain_framework-29.0.0 → brain_framework-29.0.1}/pyproject.toml +1 -1
  3. {brain_framework-29.0.0 → brain_framework-29.0.1}/pyproject.toml.orig +1 -1
  4. {brain_framework-29.0.0 → brain_framework-29.0.1}/src/bf/__init__.py +1 -1
  5. {brain_framework-29.0.0 → brain_framework-29.0.1}/src/bf/cli.py +12 -33
  6. {brain_framework-29.0.0 → brain_framework-29.0.1}/src/bf/config.py +21 -29
  7. {brain_framework-29.0.0 → brain_framework-29.0.1}/src/bf/engine.py +123 -130
  8. {brain_framework-29.0.0 → brain_framework-29.0.1}/src/bf/guides/authoring.md +1 -1
  9. {brain_framework-29.0.0 → brain_framework-29.0.1}/src/bf/guides/operations.md +2 -2
  10. {brain_framework-29.0.0 → brain_framework-29.0.1}/src/bf/jobs.py +182 -154
  11. {brain_framework-29.0.0 → brain_framework-29.0.1}/src/bf/markdown.py +39 -40
  12. {brain_framework-29.0.0 → brain_framework-29.0.1}/src/bf/mcp.py +41 -23
  13. {brain_framework-29.0.0 → brain_framework-29.0.1}/src/bf/models.py +6 -2
  14. {brain_framework-29.0.0 → brain_framework-29.0.1}/src/bf/query.py +243 -186
  15. {brain_framework-29.0.0 → brain_framework-29.0.1}/src/bf/records.py +75 -107
  16. {brain_framework-29.0.0 → brain_framework-29.0.1}/src/bf/schemas.py +20 -39
  17. {brain_framework-29.0.0 → brain_framework-29.0.1}/src/bf/skills/bf/SKILL.md +1 -1
  18. {brain_framework-29.0.0 → brain_framework-29.0.1}/src/bf/storage.py +63 -43
  19. {brain_framework-29.0.0 → brain_framework-29.0.1}/src/bf/watch.py +58 -83
  20. {brain_framework-29.0.0 → brain_framework-29.0.1}/LICENSE +0 -0
  21. {brain_framework-29.0.0 → brain_framework-29.0.1}/README.md +0 -0
  22. {brain_framework-29.0.0 → brain_framework-29.0.1}/THIRD_PARTY_NOTICES.md +0 -0
  23. {brain_framework-29.0.0 → brain_framework-29.0.1}/src/bf/__main__.py +0 -0
  24. {brain_framework-29.0.0 → brain_framework-29.0.1}/src/bf/guides/getting-started.md +0 -0
  25. {brain_framework-29.0.0 → brain_framework-29.0.1}/src/bf/guides/index.md +0 -0
  26. {brain_framework-29.0.0 → brain_framework-29.0.1}/src/bf/guides/reference.md +0 -0
  27. {brain_framework-29.0.0 → brain_framework-29.0.1}/src/bf/guides/retrieval.md +0 -0
  28. {brain_framework-29.0.0 → brain_framework-29.0.1}/src/bf/py.typed +0 -0
  29. {brain_framework-29.0.0 → brain_framework-29.0.1}/src/bf/starter/AGENTS.md +0 -0
  30. {brain_framework-29.0.0 → brain_framework-29.0.1}/src/bf/starter/concepts/welcome.md +0 -0
  31. {brain_framework-29.0.0 → brain_framework-29.0.1}/src/bf/starter/docs/index.md +0 -0
  32. {brain_framework-29.0.0 → brain_framework-29.0.1}/src/bf/starter/evals/smoke.yaml +0 -0
  33. {brain_framework-29.0.0 → brain_framework-29.0.1}/src/bf/starter/gitignore +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: brain-framework
3
- Version: 29.0.0
3
+ Version: 29.0.1
4
4
  Summary: Brain Framework is a local-first brain for you and your AI agents. It compiles OKF Markdown notes into JSON records, validates notes, records, and evals against JSON Schemas, orchestrates jobs and services, and queries offline with rg and jq.
5
5
  Keywords: ai,ai-agents,agent-memory,agent-skills,agents-md,context-engineering,json,json-schema,knowledge-graph,knowledge-management,local-first,mcp,model-context-protocol,personal-knowledge-management,python,second-brain
6
6
  Author: Médéric Hurier
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "brain-framework"
3
- version = "29.0.0"
3
+ version = "29.0.1"
4
4
  description = "Brain Framework is a local-first brain for you and your AI agents. It compiles OKF Markdown notes into JSON records, validates notes, records, and evals against JSON Schemas, orchestrates jobs and services, and queries offline with rg and jq."
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.14"
@@ -1,7 +1,7 @@
1
1
  # https://packaging.python.org/en/latest/specifications/pyproject-toml/
2
2
  [project]
3
3
  name = "brain-framework"
4
- version = "29.0.0"
4
+ version = "29.0.1"
5
5
  description = "Brain Framework is a local-first brain for you and your AI agents. It compiles OKF Markdown notes into JSON records, validates notes, records, and evals against JSON Schemas, orchestrates jobs and services, and queries offline with rg and jq."
6
6
  readme = "README.md"
7
7
  requires-python = ">=3.14"
@@ -3,7 +3,7 @@
3
3
  import os
4
4
  import sys
5
5
 
6
- __version__ = "29.0.0"
6
+ __version__ = "29.0.1"
7
7
 
8
8
 
9
9
  def main() -> None:
@@ -38,43 +38,35 @@ def _build_parser() -> _Parser:
38
38
  p_init.add_argument("path", type=Path, metavar="PATH", help="New or empty directory for the brain.")
39
39
  p_init.add_argument("--name", default="", help="Explicit brain name (defaults to directory slug).")
40
40
  _sub(sub, "build", "Compile OKF Markdown notes into memories/{concepts,projects,actions}/*.json.")
41
-
42
41
  p_ingest = _sub(sub, "ingest", "Validate and save JSON records into memories/<source>/<sha256>.json.")
43
42
  p_ingest.add_argument("source", metavar="SOURCE", help="Lowercase source name for memories/<source>/.")
44
43
  p_ingest.add_argument("--input", default="-", metavar="FILE", help="Input JSON/JSONL file path, or '-' for stdin.")
45
44
  p_ingest.add_argument("--mode", choices=("upsert", "snapshot"), default="upsert", help="Merge or snapshot mode.")
46
- p_ingest.add_argument("--allow-removal", action="store_true", help="Allow snapshot to drop >50%% of >=10 records.")
45
+ rm_help = "Allow snapshot to drop >50%% of >=10 records or empty a source."
46
+ p_ingest.add_argument("--allow-removal", action="store_true", help=rm_help)
47
47
  p_ingest.add_argument("--dry-run", action="store_true", help="Validate and report counts without writing files.")
48
-
49
48
  p_read = _sub(sub, "read", "Read an OKF note, note#anchor section, source:id record, JSON memory, or bf:// URI.")
50
49
  p_read.add_argument("target", metavar="TARGET", help="Note path, source:id, JSON memory path, or bf:// URI.")
51
-
52
50
  p_query = _sub(sub, "query", "Query pure JSON memories via rg or jq.")
53
51
  p_query.add_argument("pattern", nargs="?", default=None, metavar="QUERY", help="Lexical pattern for rg.")
54
52
  p_query.add_argument("--jq", default=None, metavar="FILTER", help="jq filter expression over JSON memories.")
55
53
  p_query.add_argument("-s", "--scope", default="", metavar="SCOPE", help="Optional folder or source name.")
56
54
  lim_help = "Max items returned (default 20; 1..500 rg, 1..5000 jq)."
57
55
  p_query.add_argument("-n", "--limit", type=int, default=20, metavar="N", help=lim_help)
58
-
59
56
  _sub(sub, "validate", "Validate bf.yaml, schemas/, OKF notes, JSON memories, evals, and links.")
60
57
  _sub(sub, "review", "List stale notes, newer linked evidence, draft actions, and open tasks.")
61
-
62
58
  p_eval = _sub(sub, "eval", "Run deterministic evaluations in evals/.")
63
59
  p_eval.add_argument("target", nargs="?", default="", metavar="SUITE", help="Optional eval file path or stem.")
64
-
65
60
  p_run = _sub(sub, "run", "Execute jobs declared in bf.yaml (use -- EXTRA_ARGS... for one job or --hook).")
66
61
  p_run.add_argument("jobs", nargs="*", metavar="JOB", help="Specific job names to execute.")
67
62
  sel = p_run.add_mutually_exclusive_group()
68
63
  sel.add_argument("--due", action="store_true", help="Rebuild dirty notes and run due scheduled/event jobs.")
69
64
  sel.add_argument("--hook", choices=("pre-commit", "pre-push"), default="", help="Run jobs matching Git hook.")
70
65
  p_run.add_argument("--dry-run", action="store_true", help="Validate job selection without executing commands.")
71
-
72
66
  p_status = _sub(sub, "status", "Inspect folder counts, attention, unit states, and event sequence.")
73
67
  p_status.add_argument("--check", action="store_true", help="Exit 1 if required binaries fail or a unit failed.")
74
-
75
68
  p_watch = _sub(sub, "watch", "Supervise constant services, file changes, events, and scheduled jobs.")
76
69
  p_watch.add_argument("--json", dest="json_stream", action="store_true", help="Emit compact JSON lines.")
77
-
78
70
  _sub(sub, "mcp", "Run the read-only Model Context Protocol server over stdio.")
79
71
  return parser
80
72
 
@@ -134,37 +126,29 @@ def run(argv: Sequence[str] | None = None) -> int:
134
126
  head_argv, extra = _split_run_passthrough(items)
135
127
  args = parser.parse_args(head_argv)
136
128
  brain_arg = _resolve_brain_arg(args)
137
- if args.command == "init":
138
- from bf import engine
139
-
140
- _emit(engine.init_brain(args.path, name=args.name))
141
- return 0
142
129
  if args.command == "mcp":
143
130
  from bf import mcp
144
131
 
145
132
  mcp.serve(brain_arg)
146
133
  return 0
147
- from bf import config
134
+ from bf import config, engine, jobs, query, records
148
135
 
136
+ if args.command == "init":
137
+ _emit(engine.init_brain(args.path, name=args.name))
138
+ return 0
149
139
  store, c = config.select(brain_arg), args.command
150
140
  if c == "watch":
151
141
  from bf import watch
152
142
 
153
143
  return 0 if watch.serve(store, json_stream=args.json_stream)["ok"] else 1
154
144
  if c in {"build", "validate", "review"}:
155
- from bf import engine
156
-
157
145
  res = {"build": engine.build, "validate": engine.validate, "review": engine.review}[c](store)
158
146
  elif c == "ingest":
159
- from bf import records
160
-
161
147
  if args.input == "-" and sys.stdin.isatty():
162
148
  raise InputError("stdin is a terminal; pipe JSON records or pass --input FILE")
163
149
  kw_in: dict[str, Any] = {"mode": args.mode, "allow_removal": args.allow_removal, "dry_run": args.dry_run}
164
150
  res = records.ingest(store, args.source, _read_input(args.input), **kw_in)
165
151
  elif c in {"read", "query", "eval"}:
166
- from bf import query
167
-
168
152
  if c == "read":
169
153
  res = query.read_target(store, args.target)
170
154
  elif c == "eval":
@@ -172,19 +156,14 @@ def run(argv: Sequence[str] | None = None) -> int:
172
156
  elif (args.jq is not None) == (args.pattern is not None):
173
157
  raise InputError("pass either positional QUERY (rg) or --jq FILTER")
174
158
  else:
175
- qkw: dict[str, Any] = {"scope": args.scope, "limit": args.limit}
176
159
  fn = query.query_jq if args.jq is not None else query.search_rg
177
- res = fn(store, args.jq if args.jq is not None else args.pattern, **qkw)
160
+ res = fn(store, args.jq if args.jq is not None else args.pattern, scope=args.scope, limit=args.limit)
161
+ elif c == "run":
162
+ b = _read_input("-") if (args.hook == "pre-push" and not args.dry_run and not sys.stdin.isatty()) else b""
163
+ ro: jobs.RunOpts = {"extra_args": extra, "stdin_bytes": b, "dry_run": args.dry_run}
164
+ res = jobs.run_jobs(store, args.jobs, due_only=args.due, hook=args.hook, **ro)
178
165
  else:
179
- from bf import jobs
180
-
181
- if c == "run":
182
- is_push = args.hook == "pre-push" and not args.dry_run and not sys.stdin.isatty()
183
- kw_run: dict[str, Any] = {"due_only": args.due, "hook": args.hook, "extra_args": extra}
184
- kw_run["stdin_bytes"] = _read_input("-") if is_push else b""
185
- res = jobs.run_jobs(store, args.jobs, **kw_run, dry_run=args.dry_run)
186
- else:
187
- res = jobs.status_summary(store, check=args.check)
166
+ res = jobs.status_summary(store, check=args.check)
188
167
  _emit(res)
189
168
  return 0 if (c in {"ingest", "read", "query"} or (c == "status" and not args.check) or res["ok"]) else 1
190
169
  except KeyboardInterrupt:
@@ -10,7 +10,7 @@ from dataclasses import dataclass, field
10
10
  from datetime import UTC, datetime
11
11
  from functools import cache
12
12
  from pathlib import Path
13
- from typing import Any, Literal, cast
13
+ from typing import Literal, cast
14
14
  from urllib.parse import unquote
15
15
  from zoneinfo import ZoneInfo, ZoneInfoNotFoundError
16
16
 
@@ -29,7 +29,10 @@ LIBYAML = (
29
29
  "uv tool install --reinstall --python 3.14 brain-framework"
30
30
  )
31
31
  _FLOAT_RE = r"^(?:[-+]?(?:\.[0-9]+|[0-9]+(?:\.[0-9]*)?)(?:[eE][-+]?[0-9]+)?|[-+]?\.(?:inf|Inf|INF)|\.(?:nan|NaN|NAN))$"
32
- _NULL_BOOL = (("null", r"^(?:~|null|Null|NULL|)$", ["~", "n", "N", ""]), ("bool", r"^(?i:true|false)$", list("tTfF")))
32
+ _NULL_BOOL = (
33
+ ("null", r"^(?:~|null|Null|NULL|)$", ["~", "n", "N", ""]),
34
+ ("bool", r"^(?:true|True|TRUE|false|False|FALSE)$", list("tTfF")),
35
+ )
33
36
  _INT_SPEC = ("int", r"^(?:[-+]?[0-9]+|0o[0-7]+|0x[0-9a-fA-F]+)$", list("-+0123456789"))
34
37
  _CORE = (*_NULL_BOOL, _INT_SPEC, ("float", _FLOAT_RE, list("-+.0123456789")))
35
38
  _ENV_KEY_RE = re.compile(r"^[A-Z_][A-Z0-9_]*$")
@@ -285,31 +288,24 @@ def _parse_job(name: str, raw: dict[str, object], base_env: dict[str, str]) -> J
285
288
  if inp:
286
289
  relative(inp)
287
290
  raw_ing = raw.get("ingest")
288
- mode: Literal["upsert", "snapshot"] = "upsert"
289
291
  if isinstance(raw_ing, dict):
290
292
  ingest = str(raw_ing["source"])
291
- if raw_ing.get("mode") == "snapshot":
292
- mode = "snapshot"
293
+ mode: Literal["upsert", "snapshot"] = "snapshot" if raw_ing.get("mode") == "snapshot" else "upsert"
293
294
  allow_removal = bool(raw_ing.get("allow_removal", False))
294
295
  else:
295
- ingest, allow_removal = str(raw_ing or ""), False
296
+ ingest, mode, allow_removal = str(raw_ing or ""), "upsert", False
296
297
  if ingest in models.RESERVED_SOURCES:
297
298
  raise Error(f"bf.yaml jobs.{name}.ingest: source {ingest!r} is reserved")
298
- raw_act = raw.get("action")
299
- action_keep = int(cast("int", raw_act["keep"])) if isinstance(raw_act, dict) else 0
299
+ action_keep = int(cast("int", raw_act["keep"])) if isinstance(raw_act := raw.get("action"), dict) else 0
300
300
  sched, every, cron = _parse_schedule(raw.get("schedule"), f"bf.yaml jobs.{name}.schedule")
301
301
  hooks = (str(raw["hook"]),) if isinstance(raw.get("hook"), str) else _str_tuple(raw.get("hook"))
302
302
  lb = models.parse_duration(raw.get("lookback", 86400), f"bf.yaml jobs.{name}.lookback")
303
303
  ov = models.parse_duration(raw.get("overlap", 0), f"bf.yaml jobs.{name}.overlap", allow_zero=True)
304
304
  to = models.parse_duration(raw.get("timeout", 300), f"bf.yaml jobs.{name}.timeout", maximum=86_400)
305
- io_kw: dict[str, Any] = {"input": inp, "ingest": ingest, "mode": mode, "allow_removal": allow_removal}
306
- evs = _parse_events(raw.get("events"))
307
- trig_kw: dict[str, Any] = {"schedule": sched, "every": every, "cron": cron, "events": evs, "hooks": hooks}
308
- lim_kw: dict[str, Any] = {"lookback": lb, "overlap": ov, "timeout": to}
309
305
  en, req, env = _unit_meta(raw, "job", name, base_env)
310
- return JobSpec(
311
- name=name, run=run, **io_kw, action_keep=action_keep, **trig_kw, **lim_kw, enabled=en, requires=req, env=env
312
- )
306
+ ev = _parse_events(raw.get("events"))
307
+ a = (name, run, inp, ingest, mode, allow_removal, action_keep, sched, every, cron, ev, hooks, lb, ov, to, en, req)
308
+ return JobSpec(*a, env)
313
309
 
314
310
 
315
311
  def _parse_service(name: str, raw: dict[str, object], base_env: dict[str, str]) -> ServiceSpec:
@@ -329,18 +325,14 @@ def load(store: Store) -> Config:
329
325
  models.check_version(raw, "bf.yaml")
330
326
  if problems := validate_instance(_brain_validator(), raw, "bf.yaml"):
331
327
  raise Error("; ".join(problems))
332
- rb = raw.get("brains")
333
- brains = {
334
- str(a): models.clean(str(t), f"bf.yaml brains.{a}") for a, t in (rb.items() if isinstance(rb, dict) else ())
335
- }
328
+ rb = raw.get("brains") if isinstance(raw.get("brains"), dict) else {}
329
+ brains = {str(a): models.clean(str(t), f"bf.yaml brains.{a}") for a, t in cast("dict[str, object]", rb).items()}
336
330
  tz = _check_tz(str(raw.get("timezone") or "UTC"), "bf.yaml timezone")
337
331
  base_env = _parse_env_map(raw.get("env"), "bf.yaml env")
338
-
339
- def sec(k: str) -> dict[str, dict[str, object]]:
340
- return cast("dict[str, dict[str, object]]", raw[k]) if isinstance(raw.get(k), dict) else {}
341
-
342
- jobs = {str(k): _parse_job(str(k), v, base_env) for k, v in sec("jobs").items()}
343
- services = {str(k): _parse_service(str(k), v, base_env) for k, v in sec("services").items()}
332
+ raw_jobs = cast("dict[str, dict[str, object]]", raw["jobs"]) if isinstance(raw.get("jobs"), dict) else {}
333
+ raw_svcs = cast("dict[str, dict[str, object]]", raw["services"]) if isinstance(raw.get("services"), dict) else {}
334
+ jobs = {str(k): _parse_job(str(k), v, base_env) for k, v in raw_jobs.items()}
335
+ services = {str(k): _parse_service(str(k), v, base_env) for k, v in raw_svcs.items()}
344
336
  all_names = (*jobs, *services)
345
337
  if "events" in all_names:
346
338
  raise Error("bf.yaml: unit name 'events' is reserved")
@@ -349,7 +341,7 @@ def load(store: Store) -> Config:
349
341
  raise Error(f"bf.yaml: unit name {dup!r} is declared in multiple sections")
350
342
  w_spec = _parse_watch(cast("dict[str, object]", rw) if isinstance(rw := raw.get("watch"), dict) else {})
351
343
  if len(_LOADED) >= 64:
352
- _LOADED.clear()
344
+ _LOADED.pop(next(iter(_LOADED)))
353
345
  _LOADED[key] = cfg = Config(str(raw["name"]), brains, tz, base_env, jobs, services, w_spec)
354
346
  return cfg
355
347
 
@@ -389,10 +381,10 @@ def select(value: str = "") -> Store:
389
381
  return _open_brain(env_brain)
390
382
  except Error:
391
383
  if models.NAME_RE.fullmatch(env_brain) and (nearest := inside_brain()) is not None:
384
+ near_name = ""
392
385
  with suppress(Error):
393
- if env_brain == load(nearest).name:
394
- return nearest
395
- if env_brain == nearest.root.name:
386
+ near_name = load(nearest).name
387
+ if env_brain in {near_name, nearest.root.name}:
396
388
  return nearest
397
389
  raise
398
390
  if nearest := inside_brain():