brain-framework 32.0.0__tar.gz → 33.0.0__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.
- {brain_framework-32.0.0 → brain_framework-33.0.0}/PKG-INFO +6 -6
- {brain_framework-32.0.0 → brain_framework-33.0.0}/README.md +5 -5
- {brain_framework-32.0.0 → brain_framework-33.0.0}/pyproject.toml +19 -2
- {brain_framework-32.0.0 → brain_framework-33.0.0}/pyproject.toml.orig +14 -2
- {brain_framework-32.0.0 → brain_framework-33.0.0}/src/bf/__init__.py +7 -1
- {brain_framework-32.0.0 → brain_framework-33.0.0}/src/bf/cli.py +50 -29
- {brain_framework-32.0.0 → brain_framework-33.0.0}/src/bf/config.py +20 -16
- {brain_framework-32.0.0 → brain_framework-33.0.0}/src/bf/engine.py +26 -60
- {brain_framework-32.0.0 → brain_framework-33.0.0}/src/bf/guides/authoring.md +10 -9
- {brain_framework-32.0.0 → brain_framework-33.0.0}/src/bf/guides/getting-started.md +4 -3
- {brain_framework-32.0.0 → brain_framework-33.0.0}/src/bf/guides/index.md +2 -2
- {brain_framework-32.0.0 → brain_framework-33.0.0}/src/bf/guides/operations.md +9 -9
- {brain_framework-32.0.0 → brain_framework-33.0.0}/src/bf/guides/reference.md +9 -9
- {brain_framework-32.0.0 → brain_framework-33.0.0}/src/bf/guides/retrieval.md +5 -5
- {brain_framework-32.0.0 → brain_framework-33.0.0}/src/bf/loops.py +31 -45
- {brain_framework-32.0.0 → brain_framework-33.0.0}/src/bf/markdown.py +58 -31
- {brain_framework-32.0.0 → brain_framework-33.0.0}/src/bf/models.py +3 -1
- {brain_framework-32.0.0 → brain_framework-33.0.0}/src/bf/proc.py +31 -1
- {brain_framework-32.0.0 → brain_framework-33.0.0}/src/bf/query.py +38 -9
- {brain_framework-32.0.0 → brain_framework-33.0.0}/src/bf/records.py +19 -8
- {brain_framework-32.0.0 → brain_framework-33.0.0}/src/bf/schemas.py +35 -22
- {brain_framework-32.0.0 → brain_framework-33.0.0}/src/bf/skills/bf/SKILL.md +5 -5
- {brain_framework-32.0.0 → brain_framework-33.0.0}/src/bf/starter/AGENTS.md +3 -3
- {brain_framework-32.0.0 → brain_framework-33.0.0}/src/bf/starter/concepts/welcome.md +2 -1
- {brain_framework-32.0.0 → brain_framework-33.0.0}/src/bf/starter/gitignore +2 -2
- {brain_framework-32.0.0 → brain_framework-33.0.0}/src/bf/status.py +90 -21
- {brain_framework-32.0.0 → brain_framework-33.0.0}/src/bf/watch.py +14 -5
- {brain_framework-32.0.0 → brain_framework-33.0.0}/LICENSE +0 -0
- {brain_framework-32.0.0 → brain_framework-33.0.0}/THIRD_PARTY_NOTICES.md +0 -0
- {brain_framework-32.0.0 → brain_framework-33.0.0}/src/bf/__main__.py +0 -0
- {brain_framework-32.0.0 → brain_framework-33.0.0}/src/bf/py.typed +0 -0
- {brain_framework-32.0.0 → brain_framework-33.0.0}/src/bf/starter/evals/smoke.py +0 -0
- {brain_framework-32.0.0 → brain_framework-33.0.0}/src/bf/storage.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: brain-framework
|
|
3
|
-
Version:
|
|
3
|
+
Version: 33.0.0
|
|
4
4
|
Summary: Brain Framework is a local-first brain for you and your AI agents. It compiles OKF Markdown notes into JSONL records, enforces required per-source JSON Schemas, orchestrates convention loops, and queries offline with rg, jq, and DuckDB.
|
|
5
5
|
Keywords: ai,ai-agents,agent-memory,agent-skills,agents-md,context-engineering,json,json-schema,knowledge-graph,knowledge-management,local-first,personal-knowledge-management,python,second-brain
|
|
6
6
|
Author: Médéric Hurier
|
|
@@ -33,14 +33,14 @@ Description-Content-Type: text/markdown
|
|
|
33
33
|
<p align="center">
|
|
34
34
|
<img
|
|
35
35
|
src="https://raw.githubusercontent.com/fmind/brain-framework/main/docs/assets/brain-framework.svg"
|
|
36
|
-
alt="Brain Framework
|
|
36
|
+
alt="Brain Framework: Plain-file knowledge and offline retrieval for humans and AI agents"
|
|
37
37
|
width="100%"
|
|
38
38
|
/>
|
|
39
39
|
</p>
|
|
40
40
|
|
|
41
|
-
Brain Framework (`bf`) turns a 3x3 folder of human-authored Markdown notes, shell/Python loops, and JSONL records (`memories/<source>.jsonl`, `usages/<source>.jsonl`, `logs/<loop>.jsonl`) into a schema-validated, UNIX-native knowledge brain with zero database or external indexer
|
|
41
|
+
Brain Framework (`bf`) turns a 3x3 folder of human-authored Markdown notes, shell/Python loops, and JSONL records (`memories/<source>.jsonl`, `usages/<source>.jsonl`, `logs/<loop>.jsonl`) into a schema-validated, UNIX-native knowledge brain with zero database or external indexer, ready for humans and AI coding harnesses to query offline with `rg`, `jq`, and DuckDB.
|
|
42
42
|
|
|
43
|
-
- **Three formats, one job each.** **YAML for config** (`bf.yaml` `version:
|
|
43
|
+
- **Three formats, one job each.** **YAML for config** (`bf.yaml` `version: 18` + note frontmatter), **Markdown for humans** (`concepts/`, `projects/`, `actions/` with flat `<slug>.md` and universal `<slug>/index.md` bundles), and **JSONL for records** (`memories/`, `usages/`, and private `logs/`, validated by bundled `bf`/`record` schemas plus `schemas/<source>.json` and `schemas/usages.json`).
|
|
44
44
|
- **Strict read/write boundary & UNIX composability.** `bf status`, `bf review`, `bf read`, `bf query`, `bf check`, and `bf schema` are strictly read-only and never mutate disk; flat JSONL files stay directly inspectable with `rg`, `jq`, and DuckDB.
|
|
45
45
|
- **Convention-first `loops:` with zero built-in LLMs.** Under 6,500 lines of Python with just 5 minimal runtime dependencies (`croniter`, `jsonschema`, `markdown`, `pyyaml`, `watchfiles`), unifying deterministic collectors (`sensors/`), routines (`routines/`), coding-harness agents (`agents/`), and daemons (`when: daemon`) via `BF_*` env + `stdin` JSON, `stdout` JSONL data/events, `stderr` structured JSONL logs, and `logs/events.jsonl`.
|
|
46
46
|
|
|
@@ -48,7 +48,7 @@ Brain Framework (`bf`) turns a 3x3 folder of human-authored Markdown notes, shel
|
|
|
48
48
|
|
|
49
49
|
## Try it
|
|
50
50
|
|
|
51
|
-
Requires Linux or macOS, [uv](https://docs.astral.sh/uv/getting-started/installation/), [ripgrep](https://github.com/BurntSushi/ripgrep) (`rg`), and [jq](https://jqlang.org/)
|
|
51
|
+
Requires Linux or macOS, [uv](https://docs.astral.sh/uv/getting-started/installation/), [ripgrep](https://github.com/BurntSushi/ripgrep) (`rg`), and [jq](https://jqlang.org/), with no model or cloud account needed:
|
|
52
52
|
|
|
53
53
|
```bash
|
|
54
54
|
uv tool install --python 3.14 brain-framework
|
|
@@ -81,6 +81,6 @@ Explore the [four-tool walkthrough](https://github.com/fmind/brain-framework/blo
|
|
|
81
81
|
|
|
82
82
|
1. **Local-first and private.** Zero global config (`--brain` -> enclosing `bf.yaml` -> `BF_BRAIN` -> `$BRAIN_LOCATION` -> `~/brain`), `O_NOFOLLOW` path confinement, disposable `0700` `.bf/` (locks + loop cursors), and private `0700` `logs/` ([Operations](https://fmind.github.io/brain-framework/operations/)).
|
|
83
83
|
2. **Harnesses reason; BF verifies.** Coding agents orient with `bf status` and `bf review`, author Markdown notes directly, emit events via `bf emit`, and verify with `bf build && bf check` plus Python/pytest suites in `evals/` ([Example brain](https://github.com/fmind/brain-framework/blob/main/examples/brain/README.md)).
|
|
84
|
-
3. **Git-native collaboration.** Track notes, `bf.yaml`, `schemas/`, `sensors/`, `routines/`, `agents/`, `clients/`, `prompts/`, and `evals/` in Git while ignoring `memories/` (keeping `*.forgotten`), `
|
|
84
|
+
3. **Git-native collaboration.** Track notes, `bf.yaml`, `schemas/`, `sensors/`, `routines/`, `agents/`, `clients/`, `prompts/`, and `evals/` in Git while ignoring `memories/` and `usages/` (keeping `*.forgotten`), `logs/`, and `.bf/`.
|
|
85
85
|
|
|
86
86
|
[Documentation](https://fmind.github.io/brain-framework/) · [Reference](https://fmind.github.io/brain-framework/reference/) · [Issues](https://github.com/fmind/brain-framework/issues) · [Contribute](https://github.com/fmind/brain-framework/blob/main/CONTRIBUTING.md) · [Governance](https://github.com/fmind/brain-framework/blob/main/GOVERNANCE.md) · [Security](https://github.com/fmind/brain-framework/blob/main/SECURITY.md) · [MIT License](https://github.com/fmind/brain-framework/blob/main/LICENSE) · [Third-party notices](https://github.com/fmind/brain-framework/blob/main/THIRD_PARTY_NOTICES.md)
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
<p align="center">
|
|
2
2
|
<img
|
|
3
3
|
src="https://raw.githubusercontent.com/fmind/brain-framework/main/docs/assets/brain-framework.svg"
|
|
4
|
-
alt="Brain Framework
|
|
4
|
+
alt="Brain Framework: Plain-file knowledge and offline retrieval for humans and AI agents"
|
|
5
5
|
width="100%"
|
|
6
6
|
/>
|
|
7
7
|
</p>
|
|
8
8
|
|
|
9
|
-
Brain Framework (`bf`) turns a 3x3 folder of human-authored Markdown notes, shell/Python loops, and JSONL records (`memories/<source>.jsonl`, `usages/<source>.jsonl`, `logs/<loop>.jsonl`) into a schema-validated, UNIX-native knowledge brain with zero database or external indexer
|
|
9
|
+
Brain Framework (`bf`) turns a 3x3 folder of human-authored Markdown notes, shell/Python loops, and JSONL records (`memories/<source>.jsonl`, `usages/<source>.jsonl`, `logs/<loop>.jsonl`) into a schema-validated, UNIX-native knowledge brain with zero database or external indexer, ready for humans and AI coding harnesses to query offline with `rg`, `jq`, and DuckDB.
|
|
10
10
|
|
|
11
|
-
- **Three formats, one job each.** **YAML for config** (`bf.yaml` `version:
|
|
11
|
+
- **Three formats, one job each.** **YAML for config** (`bf.yaml` `version: 18` + note frontmatter), **Markdown for humans** (`concepts/`, `projects/`, `actions/` with flat `<slug>.md` and universal `<slug>/index.md` bundles), and **JSONL for records** (`memories/`, `usages/`, and private `logs/`, validated by bundled `bf`/`record` schemas plus `schemas/<source>.json` and `schemas/usages.json`).
|
|
12
12
|
- **Strict read/write boundary & UNIX composability.** `bf status`, `bf review`, `bf read`, `bf query`, `bf check`, and `bf schema` are strictly read-only and never mutate disk; flat JSONL files stay directly inspectable with `rg`, `jq`, and DuckDB.
|
|
13
13
|
- **Convention-first `loops:` with zero built-in LLMs.** Under 6,500 lines of Python with just 5 minimal runtime dependencies (`croniter`, `jsonschema`, `markdown`, `pyyaml`, `watchfiles`), unifying deterministic collectors (`sensors/`), routines (`routines/`), coding-harness agents (`agents/`), and daemons (`when: daemon`) via `BF_*` env + `stdin` JSON, `stdout` JSONL data/events, `stderr` structured JSONL logs, and `logs/events.jsonl`.
|
|
14
14
|
|
|
@@ -16,7 +16,7 @@ Brain Framework (`bf`) turns a 3x3 folder of human-authored Markdown notes, shel
|
|
|
16
16
|
|
|
17
17
|
## Try it
|
|
18
18
|
|
|
19
|
-
Requires Linux or macOS, [uv](https://docs.astral.sh/uv/getting-started/installation/), [ripgrep](https://github.com/BurntSushi/ripgrep) (`rg`), and [jq](https://jqlang.org/)
|
|
19
|
+
Requires Linux or macOS, [uv](https://docs.astral.sh/uv/getting-started/installation/), [ripgrep](https://github.com/BurntSushi/ripgrep) (`rg`), and [jq](https://jqlang.org/), with no model or cloud account needed:
|
|
20
20
|
|
|
21
21
|
```bash
|
|
22
22
|
uv tool install --python 3.14 brain-framework
|
|
@@ -49,6 +49,6 @@ Explore the [four-tool walkthrough](https://github.com/fmind/brain-framework/blo
|
|
|
49
49
|
|
|
50
50
|
1. **Local-first and private.** Zero global config (`--brain` -> enclosing `bf.yaml` -> `BF_BRAIN` -> `$BRAIN_LOCATION` -> `~/brain`), `O_NOFOLLOW` path confinement, disposable `0700` `.bf/` (locks + loop cursors), and private `0700` `logs/` ([Operations](https://fmind.github.io/brain-framework/operations/)).
|
|
51
51
|
2. **Harnesses reason; BF verifies.** Coding agents orient with `bf status` and `bf review`, author Markdown notes directly, emit events via `bf emit`, and verify with `bf build && bf check` plus Python/pytest suites in `evals/` ([Example brain](https://github.com/fmind/brain-framework/blob/main/examples/brain/README.md)).
|
|
52
|
-
3. **Git-native collaboration.** Track notes, `bf.yaml`, `schemas/`, `sensors/`, `routines/`, `agents/`, `clients/`, `prompts/`, and `evals/` in Git while ignoring `memories/` (keeping `*.forgotten`), `
|
|
52
|
+
3. **Git-native collaboration.** Track notes, `bf.yaml`, `schemas/`, `sensors/`, `routines/`, `agents/`, `clients/`, `prompts/`, and `evals/` in Git while ignoring `memories/` and `usages/` (keeping `*.forgotten`), `logs/`, and `.bf/`.
|
|
53
53
|
|
|
54
54
|
[Documentation](https://fmind.github.io/brain-framework/) · [Reference](https://fmind.github.io/brain-framework/reference/) · [Issues](https://github.com/fmind/brain-framework/issues) · [Contribute](https://github.com/fmind/brain-framework/blob/main/CONTRIBUTING.md) · [Governance](https://github.com/fmind/brain-framework/blob/main/GOVERNANCE.md) · [Security](https://github.com/fmind/brain-framework/blob/main/SECURITY.md) · [MIT License](https://github.com/fmind/brain-framework/blob/main/LICENSE) · [Third-party notices](https://github.com/fmind/brain-framework/blob/main/THIRD_PARTY_NOTICES.md)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "brain-framework"
|
|
3
|
-
version = "
|
|
3
|
+
version = "33.0.0"
|
|
4
4
|
description = "Brain Framework is a local-first brain for you and your AI agents. It compiles OKF Markdown notes into JSONL records, enforces required per-source JSON Schemas, orchestrates convention loops, and queries offline with rg, jq, and DuckDB."
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
requires-python = ">=3.14"
|
|
@@ -146,16 +146,30 @@ ignore = [
|
|
|
146
146
|
"T201",
|
|
147
147
|
]
|
|
148
148
|
|
|
149
|
+
[tool.deptry]
|
|
150
|
+
extend_exclude = [
|
|
151
|
+
"examples",
|
|
152
|
+
"scripts",
|
|
153
|
+
]
|
|
154
|
+
known_first_party = ["bf"]
|
|
155
|
+
|
|
149
156
|
[tool.ty.rules]
|
|
150
157
|
blanket-ignore-comment = "error"
|
|
158
|
+
unused-ignore-comment = "error"
|
|
159
|
+
unused-type-ignore-comment = "error"
|
|
151
160
|
|
|
152
161
|
[tool.pytest]
|
|
153
|
-
addopts = [
|
|
162
|
+
addopts = [
|
|
163
|
+
"-ra",
|
|
164
|
+
"--allow-hosts=127.0.0.1,::1",
|
|
165
|
+
"--allow-unix-socket",
|
|
166
|
+
]
|
|
154
167
|
faulthandler_timeout = "300"
|
|
155
168
|
faulthandler_exit_on_timeout = true
|
|
156
169
|
filterwarnings = ["error"]
|
|
157
170
|
strict = true
|
|
158
171
|
testpaths = ["tests"]
|
|
172
|
+
timeout = "60"
|
|
159
173
|
|
|
160
174
|
[tool.coverage.run]
|
|
161
175
|
branch = true
|
|
@@ -172,8 +186,11 @@ skip_empty = true
|
|
|
172
186
|
|
|
173
187
|
[dependency-groups]
|
|
174
188
|
dev = [
|
|
189
|
+
"deptry>=0.25.1",
|
|
175
190
|
"packaging>=26.3",
|
|
176
191
|
"pytest-cov>=7.1.0",
|
|
192
|
+
"pytest-socket>=0.8.1",
|
|
193
|
+
"pytest-timeout>=2.4.0",
|
|
177
194
|
"pytest-watcher>=0.6.3",
|
|
178
195
|
"pytest-xdist>=3.8.0",
|
|
179
196
|
"pytest>=9.1.1",
|
|
@@ -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 = "
|
|
4
|
+
version = "33.0.0"
|
|
5
5
|
description = "Brain Framework is a local-first brain for you and your AI agents. It compiles OKF Markdown notes into JSONL records, enforces required per-source JSON Schemas, orchestrates convention loops, and queries offline with rg, jq, and DuckDB."
|
|
6
6
|
readme = "README.md"
|
|
7
7
|
requires-python = ">=3.14"
|
|
@@ -63,9 +63,12 @@ module-name = "bf"
|
|
|
63
63
|
|
|
64
64
|
[dependency-groups]
|
|
65
65
|
dev = [
|
|
66
|
+
"deptry>=0.25.1",
|
|
66
67
|
# Imported directly by scripts/notices.py to parse requirements and normalize names.
|
|
67
68
|
"packaging>=26.3",
|
|
68
69
|
"pytest-cov>=7.1.0",
|
|
70
|
+
"pytest-socket>=0.8.1",
|
|
71
|
+
"pytest-timeout>=2.4.0",
|
|
69
72
|
"pytest-watcher>=0.6.3",
|
|
70
73
|
"pytest-xdist>=3.8.0",
|
|
71
74
|
"pytest>=9.1.1",
|
|
@@ -153,11 +156,19 @@ ignore = [
|
|
|
153
156
|
"T201", # Test diagnostics may use print.
|
|
154
157
|
]
|
|
155
158
|
|
|
159
|
+
[tool.deptry]
|
|
160
|
+
# deptry does not infer uv_build's src/ layout on `.`; examples/ and scripts/ are repo-only like tests/.
|
|
161
|
+
extend_exclude = ["examples", "scripts"]
|
|
162
|
+
known_first_party = ["bf"]
|
|
163
|
+
|
|
156
164
|
[tool.ty.rules]
|
|
157
165
|
blanket-ignore-comment = "error" # Require `ty: ignore[<rule>]`; Ruff PGH003 checks only `type: ignore`.
|
|
166
|
+
unused-ignore-comment = "error"
|
|
167
|
+
unused-type-ignore-comment = "error"
|
|
158
168
|
|
|
159
169
|
[tool.pytest]
|
|
160
|
-
|
|
170
|
+
# Offline by default: tests reach only loopback and Unix sockets.
|
|
171
|
+
addopts = ["-ra", "--allow-hosts=127.0.0.1,::1", "--allow-unix-socket"]
|
|
161
172
|
# A test still running after 300 seconds dumps every thread's traceback and ends the run, long before CI's 30-minute job
|
|
162
173
|
# timeout. Subprocess waits in tests stay within 120 seconds. The timeout is a string option.
|
|
163
174
|
faulthandler_timeout = "300"
|
|
@@ -165,6 +176,7 @@ faulthandler_exit_on_timeout = true
|
|
|
165
176
|
filterwarnings = ["error"]
|
|
166
177
|
strict = true
|
|
167
178
|
testpaths = ["tests"]
|
|
179
|
+
timeout = "60"
|
|
168
180
|
|
|
169
181
|
[tool.coverage.run]
|
|
170
182
|
branch = true
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import os
|
|
4
4
|
import sys
|
|
5
5
|
|
|
6
|
-
__version__ = "
|
|
6
|
+
__version__ = "33.0.0"
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
def main() -> None:
|
|
@@ -15,6 +15,12 @@ def main() -> None:
|
|
|
15
15
|
sys.stdout.buffer.write(f"{__version__}\n".encode())
|
|
16
16
|
sys.stdout.flush()
|
|
17
17
|
except BrokenPipeError:
|
|
18
|
+
try:
|
|
19
|
+
devnull = os.open(os.devnull, os.O_WRONLY)
|
|
20
|
+
os.dup2(devnull, 1)
|
|
21
|
+
os.close(devnull)
|
|
22
|
+
except OSError:
|
|
23
|
+
pass
|
|
18
24
|
return
|
|
19
25
|
except OSError:
|
|
20
26
|
pass
|
|
@@ -19,6 +19,11 @@ class _Parser(argparse.ArgumentParser):
|
|
|
19
19
|
def error(self, message: str) -> NoReturn:
|
|
20
20
|
raise InputError(message)
|
|
21
21
|
|
|
22
|
+
def _print_message(self, message: str, file: Any = None) -> None:
|
|
23
|
+
super()._print_message(message, file)
|
|
24
|
+
if message and (target := file or sys.stderr) is not None:
|
|
25
|
+
target.flush()
|
|
26
|
+
|
|
22
27
|
|
|
23
28
|
def _add_brain_opt(parser: argparse.ArgumentParser, dest: str = "brain") -> None:
|
|
24
29
|
parser.add_argument(
|
|
@@ -100,7 +105,9 @@ def _build_parser() -> _Parser:
|
|
|
100
105
|
rv_lim = sp.add_mutually_exclusive_group()
|
|
101
106
|
rv_lim.add_argument("-n", "--limit", type=int, default=None, metavar="N", help="Max stale items (default: 20).")
|
|
102
107
|
rv_lim.add_argument("--all", dest="all_items", action="store_true", help="Return all stale notes.")
|
|
103
|
-
sp.add_argument(
|
|
108
|
+
sp.add_argument(
|
|
109
|
+
"--format", choices=("json", "jsonl", "text"), default="json", help="Output format (default: json)."
|
|
110
|
+
)
|
|
104
111
|
|
|
105
112
|
sp = cmd("check", "Validate bf.yaml, schemas, notes, JSONL records, loops, and links (read-only).")
|
|
106
113
|
ck_lim = sp.add_mutually_exclusive_group()
|
|
@@ -108,9 +115,15 @@ def _build_parser() -> _Parser:
|
|
|
108
115
|
ck_lim.add_argument(
|
|
109
116
|
"--all", dest="all_problems", action="store_true", help="Return all problems without truncation."
|
|
110
117
|
)
|
|
118
|
+
sp.add_argument(
|
|
119
|
+
"--notes",
|
|
120
|
+
action="store_true",
|
|
121
|
+
help="Validate config, schemas, loops, notes, and note links without validating sensor/usage JSONL.",
|
|
122
|
+
)
|
|
111
123
|
sp.add_argument(
|
|
112
124
|
"--strict", action="store_true", help="Fail validation on warnings (snapshot or forgotten targets)."
|
|
113
125
|
)
|
|
126
|
+
sp.add_argument("--format", choices=("json", "text"), default="json", help="Output format (default: json).")
|
|
114
127
|
|
|
115
128
|
sp = cmd("schema", "Print bundled Draft 2020-12 JSON Schemas.", with_brain=False)
|
|
116
129
|
sp.add_argument("name", nargs="?", default=None, help="Schema name: bf or record.")
|
|
@@ -182,20 +195,27 @@ def _read_in(spec: str) -> bytes:
|
|
|
182
195
|
return data
|
|
183
196
|
|
|
184
197
|
|
|
198
|
+
def _use_color() -> bool:
|
|
199
|
+
return sys.stdout.isatty() and os.environ.get("TERM", "") != "dumb" and not os.environ.get("NO_COLOR", "")
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
def _write_text(text: str) -> None:
|
|
203
|
+
sys.stdout.buffer.write(text.encode("utf-8"))
|
|
204
|
+
sys.stdout.flush()
|
|
205
|
+
|
|
206
|
+
|
|
185
207
|
def _emit(payload: object) -> None:
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
sys.stdout.flush()
|
|
208
|
+
sys.stdout.buffer.write(terminal(payload))
|
|
209
|
+
sys.stdout.flush()
|
|
189
210
|
|
|
190
211
|
|
|
191
212
|
def _emit_fmt(res: dict[str, Any], fmt: str, *, review: bool = False) -> None:
|
|
192
213
|
if fmt == "json":
|
|
193
214
|
return _emit(res)
|
|
194
215
|
rows = res["stale"] if review else res["items"]
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
sys.stdout.flush()
|
|
216
|
+
for row in rows:
|
|
217
|
+
sys.stdout.buffer.write(terminal(row))
|
|
218
|
+
sys.stdout.flush()
|
|
199
219
|
if res.get("truncated"):
|
|
200
220
|
flag = "--all" if review else "-n/--limit"
|
|
201
221
|
sys.stderr.write(f"bf: warning: truncated to {len(rows)} items; pass {flag} for more\n")
|
|
@@ -244,12 +264,7 @@ def _dispatch(args: argparse.Namespace, extra: list[str]) -> int:
|
|
|
244
264
|
|
|
245
265
|
res = status.status_summary(store, all_units=args.all_units or args.format == "text")
|
|
246
266
|
if args.format == "text":
|
|
247
|
-
|
|
248
|
-
sys.stdout.isatty() and os.environ.get("TERM", "") != "dumb" and not os.environ.get("NO_COLOR", "")
|
|
249
|
-
)
|
|
250
|
-
with suppress(BrokenPipeError):
|
|
251
|
-
sys.stdout.buffer.write(status.format_status_text(res, color=use_color).encode("utf-8"))
|
|
252
|
-
sys.stdout.flush()
|
|
267
|
+
_write_text(status.format_status_text(res, color=_use_color()))
|
|
253
268
|
else:
|
|
254
269
|
_emit(res)
|
|
255
270
|
return 0 if (not args.check or res.get("ok", True)) else 1
|
|
@@ -264,31 +279,32 @@ def _dispatch(args: argparse.Namespace, extra: list[str]) -> int:
|
|
|
264
279
|
if args.data == "-":
|
|
265
280
|
if sys.stdin.isatty():
|
|
266
281
|
raise InputError("stdin is a terminal; pipe JSON object or pass --data JSON")
|
|
267
|
-
raw_in = _read_in("-")
|
|
268
|
-
try:
|
|
269
|
-
raw_data = models.decode(raw_in, "--data") if raw_in.strip() else {}
|
|
270
|
-
except Error as err:
|
|
271
|
-
raise InputError(str(err)) from err
|
|
282
|
+
raw_in: bytes | str = _read_in("-")
|
|
272
283
|
else:
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
284
|
+
raw_in = args.data or ""
|
|
285
|
+
try:
|
|
286
|
+
raw_data = models.decode(raw_in, "--data") if raw_in.strip() else {}
|
|
287
|
+
except Error as err:
|
|
288
|
+
raise InputError(str(err)) from err
|
|
277
289
|
if not isinstance(raw_data, dict):
|
|
278
290
|
raise InputError("--data must be a JSON object")
|
|
279
291
|
ev = records.append_event(store, args.kind, args.source, raw_data, dedupe=args.dedupe)
|
|
280
292
|
_emit({"ok": True, "brain": brain_name, "event": ev})
|
|
281
293
|
return 0
|
|
282
294
|
if cmd == "check":
|
|
283
|
-
from bf import engine
|
|
295
|
+
from bf import engine, status
|
|
284
296
|
|
|
285
297
|
res = engine.validate(
|
|
286
298
|
store,
|
|
287
299
|
limit=50 if args.limit is None else args.limit,
|
|
288
300
|
all_problems=args.all_problems,
|
|
289
301
|
strict=args.strict,
|
|
302
|
+
notes_only=args.notes,
|
|
290
303
|
)
|
|
291
|
-
|
|
304
|
+
if args.format == "text":
|
|
305
|
+
_write_text(status.format_check_text(res, color=_use_color(), notes_only=args.notes))
|
|
306
|
+
else:
|
|
307
|
+
_emit(res)
|
|
292
308
|
return 0 if res["ok"] else 1
|
|
293
309
|
if cmd == "run":
|
|
294
310
|
from bf import loops
|
|
@@ -335,6 +351,8 @@ def _dispatch(args: argparse.Namespace, extra: list[str]) -> int:
|
|
|
335
351
|
|
|
336
352
|
res = query.query(store, args.pattern, jq_expr=args.jq, scope=args.scope, kind=args.kind, limit=args.limit)
|
|
337
353
|
_emit_fmt(res, args.format, review=False)
|
|
354
|
+
if unbuilt := res.get("unbuilt_notes"):
|
|
355
|
+
sys.stderr.write(f"bf: hint: unbuilt notes in {', '.join(unbuilt)}; run bf build\n")
|
|
338
356
|
return 0
|
|
339
357
|
if cmd == "build":
|
|
340
358
|
from bf import engine
|
|
@@ -343,12 +361,15 @@ def _dispatch(args: argparse.Namespace, extra: list[str]) -> int:
|
|
|
343
361
|
_emit(res)
|
|
344
362
|
return 0 if res["ok"] else 1
|
|
345
363
|
|
|
346
|
-
from bf import engine
|
|
364
|
+
from bf import engine, status
|
|
347
365
|
|
|
348
366
|
res = engine.review(store, limit=20 if args.limit is None else args.limit, all_items=args.all_items)
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
367
|
+
if args.format == "text":
|
|
368
|
+
_write_text(status.format_review_text(res, color=_use_color()))
|
|
369
|
+
else:
|
|
370
|
+
_emit_fmt(res, args.format, review=True)
|
|
371
|
+
if args.format != "json" and not res["ok"] and res.get("problems"):
|
|
372
|
+
sys.stderr.write(f"bf: {printable('; '.join(str(p) for p in res['problems']))}\n")
|
|
352
373
|
return 0 if res["ok"] else 1
|
|
353
374
|
|
|
354
375
|
|
|
@@ -188,10 +188,6 @@ def _check_tz(tz: str, label: str) -> str:
|
|
|
188
188
|
return tz
|
|
189
189
|
|
|
190
190
|
|
|
191
|
-
def _str_tuple(raw: object) -> tuple[str, ...]:
|
|
192
|
-
return tuple(str(item) for item in raw) if isinstance(raw, list) else ()
|
|
193
|
-
|
|
194
|
-
|
|
195
191
|
def _check_env(key: str, val: str, label: str, key_err: str) -> str:
|
|
196
192
|
if not _ENV_KEY_RE.fullmatch(key):
|
|
197
193
|
raise Error(key_err)
|
|
@@ -341,14 +337,6 @@ def _parse_trigger_window(item: Mapping[str, object], label: str) -> tuple[int |
|
|
|
341
337
|
return backfill, overlap
|
|
342
338
|
|
|
343
339
|
|
|
344
|
-
def _parse_event_value(raw: object) -> EventMatch:
|
|
345
|
-
if isinstance(raw, str):
|
|
346
|
-
return EventMatch(kind=raw)
|
|
347
|
-
if isinstance(raw, dict):
|
|
348
|
-
return EventMatch(str(raw.get("kind", "")), str(raw.get("source", "")), str(raw.get("filter", "")))
|
|
349
|
-
return EventMatch()
|
|
350
|
-
|
|
351
|
-
|
|
352
340
|
def _parse_when(raw_when: object, label: str) -> tuple[bool, tuple[ScheduleSpec, ...], tuple[EventMatch, ...]]:
|
|
353
341
|
if raw_when is None:
|
|
354
342
|
return False, (), ()
|
|
@@ -377,7 +365,12 @@ def _parse_when(raw_when: object, label: str) -> tuple[bool, tuple[ScheduleSpec,
|
|
|
377
365
|
bf_w, ov_w = _parse_trigger_window(item, label)
|
|
378
366
|
add_sched(ScheduleSpec(f"cron:{expr}", cron=expr, backfill=bf_w, overlap=ov_w))
|
|
379
367
|
elif "event" in item:
|
|
380
|
-
|
|
368
|
+
ev = item["event"]
|
|
369
|
+
events.append(
|
|
370
|
+
EventMatch(kind=ev)
|
|
371
|
+
if isinstance(ev, str)
|
|
372
|
+
else EventMatch(str(ev.get("kind", "")), str(ev.get("source", "")), str(ev.get("filter", "")))
|
|
373
|
+
)
|
|
381
374
|
elif type(item) is int or (isinstance(item, str) and bool(models.DURATION_RE.fullmatch(item.strip()))):
|
|
382
375
|
secs = models.parse_duration(item, label)
|
|
383
376
|
add_sched(ScheduleSpec(f"every:{str(item).strip()}", every=secs))
|
|
@@ -406,7 +399,9 @@ def _parse_loop(
|
|
|
406
399
|
raw_ingest = raw.get("ingest")
|
|
407
400
|
explicit_ingest = raw_ingest is not None
|
|
408
401
|
target: Literal["memories", "usages"] = "memories"
|
|
409
|
-
if
|
|
402
|
+
if raw_ingest is False:
|
|
403
|
+
ingest, mode = "", "upsert"
|
|
404
|
+
elif isinstance(raw_ingest, str):
|
|
410
405
|
ingest, mode = name, cast("Literal['upsert', 'snapshot']", raw_ingest)
|
|
411
406
|
elif isinstance(raw_ingest, dict):
|
|
412
407
|
ingest = str(raw_ingest.get("source") or name)
|
|
@@ -417,14 +412,23 @@ def _parse_loop(
|
|
|
417
412
|
if ingest and ingest in reserved:
|
|
418
413
|
raise Error(f"{label}.ingest: source {ingest!r} is reserved")
|
|
419
414
|
|
|
415
|
+
raw_run = raw.get("run")
|
|
416
|
+
run = tuple(str(item) for item in raw_run) if isinstance(raw_run, list) else ()
|
|
417
|
+
for idx, arg in enumerate(run):
|
|
418
|
+
for match in models.PLACEHOLDER_RE.finditer(arg):
|
|
419
|
+
if idx == 0:
|
|
420
|
+
raise Error(f"{label}.run[0]: placeholders are not allowed in executable name; use a relative path")
|
|
421
|
+
if match[0] != f"{{{{{match[1]}}}}}" or match[1] not in models.PLACEHOLDERS:
|
|
422
|
+
allowed = ", ".join(f"{{{{{k}}}}}" for k in sorted(models.PLACEHOLDERS))
|
|
423
|
+
raise Error(f"{label}.run: unknown placeholder {match[0]}; allowed: {allowed}")
|
|
420
424
|
def_win = dw if isinstance(dw := defaults.get("window"), dict) else {}
|
|
421
425
|
own_win = rw if isinstance(rw := raw.get("window"), dict) else {}
|
|
422
426
|
win = {**def_win, **own_win}
|
|
423
|
-
explicit_timeout = "timeout" in raw
|
|
427
|
+
explicit_timeout = "timeout" in raw
|
|
424
428
|
timeout_val = raw["timeout"] if "timeout" in raw else defaults.get("timeout", 300)
|
|
425
429
|
return LoopSpec(
|
|
426
430
|
name=name,
|
|
427
|
-
run=
|
|
431
|
+
run=run,
|
|
428
432
|
description=models.clean_text(str(raw.get("description") or ""), f"{label}.description"),
|
|
429
433
|
daemon=daemon,
|
|
430
434
|
ingest=ingest,
|
|
@@ -4,7 +4,6 @@ from __future__ import annotations
|
|
|
4
4
|
|
|
5
5
|
import json
|
|
6
6
|
import re
|
|
7
|
-
import subprocess
|
|
8
7
|
from contextlib import suppress
|
|
9
8
|
from datetime import UTC, date, datetime, timedelta
|
|
10
9
|
from importlib import resources
|
|
@@ -17,6 +16,7 @@ from bf.models import DEFAULT_NOTES, FORMAT, MAX_TOTAL_FILES, Error, InputError,
|
|
|
17
16
|
from bf.storage import Store, expand, private_dir, writer
|
|
18
17
|
|
|
19
18
|
_WARN_FORGOTTEN = "snapshot_or_forgotten"
|
|
19
|
+
_TERMINAL_STATUSES = frozenset(("deprecated", "done", "archived", "cancelled"))
|
|
20
20
|
|
|
21
21
|
|
|
22
22
|
def _starter_bf_yaml(name: str, description: str) -> bytes:
|
|
@@ -170,39 +170,19 @@ def build(store: Store, *, now: datetime | None = None) -> dict[str, Any]:
|
|
|
170
170
|
}
|
|
171
171
|
|
|
172
172
|
|
|
173
|
-
def _load_source_refs(store: Store, source: str
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
cache[source] = refs
|
|
182
|
-
return cache[source]
|
|
173
|
+
def _load_source_refs(store: Store, source: str) -> set[str]:
|
|
174
|
+
refs: set[str] = set()
|
|
175
|
+
for target in models.RECORD_DIRS:
|
|
176
|
+
with suppress(FileNotFoundError, Error, OSError):
|
|
177
|
+
for _, obj in records.iter_jsonl(store, records.record_file(source, target)):
|
|
178
|
+
if isinstance(r := obj.get("ref"), str) and r:
|
|
179
|
+
refs.add(r)
|
|
180
|
+
return refs
|
|
183
181
|
|
|
184
182
|
|
|
185
|
-
def
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
wrapped = f"{proc.JQ_PRELUDE}\ntry ([\n{flt}\n] | length > 0) catch false"
|
|
189
|
-
cp = subprocess.run( # noqa: S603
|
|
190
|
-
[jq_bin, "-n", "-L", "/dev/null", "--", wrapped],
|
|
191
|
-
capture_output=True,
|
|
192
|
-
cwd="/",
|
|
193
|
-
env=proc.safe_env(jq_bin),
|
|
194
|
-
timeout=5,
|
|
195
|
-
check=False,
|
|
196
|
-
)
|
|
197
|
-
except (Error, subprocess.TimeoutExpired) as err:
|
|
198
|
-
return f"{label}: {err}"
|
|
199
|
-
if cp.returncode != 0:
|
|
200
|
-
err_t = cp.stderr.decode("utf-8", "replace").strip()
|
|
201
|
-
return f"{label}: invalid jq event filter ({err_t.splitlines()[-1] if err_t else 'jq exited nonzero'})"
|
|
202
|
-
return ""
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
def validate(store: Store, *, limit: int = 50, all_problems: bool = False, strict: bool = False) -> dict[str, Any]:
|
|
183
|
+
def validate(
|
|
184
|
+
store: Store, *, limit: int = 50, all_problems: bool = False, strict: bool = False, notes_only: bool = False
|
|
185
|
+
) -> dict[str, Any]:
|
|
206
186
|
"""Strictly read-only config, schemas, JSONL records (`memories/` & `usages/`), notes, loops, and link checks."""
|
|
207
187
|
from bf import loops as lp_m
|
|
208
188
|
|
|
@@ -287,14 +267,11 @@ def validate(store: Store, *, limit: int = 50, all_problems: bool = False, stric
|
|
|
287
267
|
add(errors, "memory", f"{rec_path}: invalid or reserved source {src!r}")
|
|
288
268
|
continue
|
|
289
269
|
try:
|
|
290
|
-
raw_fg = store.read(rec_path, models.MAX_NOTE).decode("utf-8").splitlines()
|
|
291
270
|
forgotten_map.setdefault(src, set()).update(
|
|
292
|
-
f"{src}:{
|
|
293
|
-
)
|
|
294
|
-
except (Error, UnicodeDecodeError) as err:
|
|
295
|
-
add(
|
|
296
|
-
errors, "memory", str(err) if isinstance(err, Error) else f"{rec_path}: file is not valid UTF-8"
|
|
271
|
+
f"{src}:{fid}" for fid in records.forgotten_ids(store, src, bucket)
|
|
297
272
|
)
|
|
273
|
+
except Error as err:
|
|
274
|
+
add(errors, "memory", str(err))
|
|
298
275
|
continue
|
|
299
276
|
if not leaf.endswith(".jsonl"):
|
|
300
277
|
add(errors, "memory", f"{rec_path}: {bucket}/ holds flat <source>.jsonl files")
|
|
@@ -317,6 +294,8 @@ def validate(store: Store, *, limit: int = 50, all_problems: bool = False, stric
|
|
|
317
294
|
except Error as err:
|
|
318
295
|
add(errors, "note", str(err))
|
|
319
296
|
continue
|
|
297
|
+
if notes_only:
|
|
298
|
+
continue
|
|
320
299
|
|
|
321
300
|
if bucket == "usages":
|
|
322
301
|
if "usages" not in validators:
|
|
@@ -383,7 +362,7 @@ def validate(store: Store, *, limit: int = 50, all_problems: bool = False, stric
|
|
|
383
362
|
elif ing_tgt == "memories" and ing_src not in validators:
|
|
384
363
|
add(errors, "schema", f"loops.{lp_name}: missing required schemas/{ing_src}.json")
|
|
385
364
|
for ev_rule in loop.events:
|
|
386
|
-
if ev_rule.filter and (jq_err :=
|
|
365
|
+
if ev_rule.filter and (jq_err := proc.check_jq_filter(ev_rule.filter, f"loops.{lp_name}")):
|
|
387
366
|
add(errors, "loop", jq_err)
|
|
388
367
|
|
|
389
368
|
anchors: dict[tuple[str, str], set[str]] = {}
|
|
@@ -454,8 +433,7 @@ def validate(store: Store, *, limit: int = 50, all_problems: bool = False, stric
|
|
|
454
433
|
s_src = parsed_r[0]
|
|
455
434
|
s_key = (sib_name, s_src)
|
|
456
435
|
if s_key not in sib_refs:
|
|
457
|
-
|
|
458
|
-
sib_refs[s_key] = _load_source_refs(sib, s_src, tmp)
|
|
436
|
+
sib_refs[s_key] = _load_source_refs(sib, s_src)
|
|
459
437
|
if rest not in sib_refs[s_key]:
|
|
460
438
|
add(errors, "link", f"{origin}: broken cross-brain link bf://{sib_name}/{rest}")
|
|
461
439
|
elif not sib.exists(rest):
|
|
@@ -470,8 +448,9 @@ def validate(store: Store, *, limit: int = 50, all_problems: bool = False, stric
|
|
|
470
448
|
add(errors, "link", f"{origin}: invalid record link {to}")
|
|
471
449
|
else:
|
|
472
450
|
src = parsed_r[0]
|
|
473
|
-
|
|
474
|
-
|
|
451
|
+
if src not in source_refs:
|
|
452
|
+
source_refs[src] = _load_source_refs(store, src)
|
|
453
|
+
if to not in source_refs[src]:
|
|
475
454
|
if src in snap_srcs or to in forgotten_map.get(src, ()):
|
|
476
455
|
add(
|
|
477
456
|
warnings,
|
|
@@ -515,19 +494,6 @@ def _ts_key(raw: str) -> str:
|
|
|
515
494
|
return raw
|
|
516
495
|
|
|
517
496
|
|
|
518
|
-
def _note_updated(rec: dict[str, Any]) -> str:
|
|
519
|
-
if upd := str(rec.get("updated") or ""):
|
|
520
|
-
return upd
|
|
521
|
-
if isinstance(srcs := rec.get("sources"), list):
|
|
522
|
-
rets = [
|
|
523
|
-
str(r)
|
|
524
|
-
for s in srcs
|
|
525
|
-
if isinstance(s, dict) and isinstance(r := s.get("retrieved"), str) and len(r) >= 10 and r[:4].isdigit()
|
|
526
|
-
]
|
|
527
|
-
return max(rets, default="")
|
|
528
|
-
return ""
|
|
529
|
-
|
|
530
|
-
|
|
531
497
|
def review(store: Store, *, now: datetime | None = None, limit: int = 20, all_items: bool = False) -> dict[str, Any]:
|
|
532
498
|
"""Read-only staleness (`newer_evidence`, `due`, `future_updated`) and open task summary over JSONL."""
|
|
533
499
|
if not all_items and limit < 1:
|
|
@@ -558,7 +524,7 @@ def review(store: Store, *, now: datetime | None = None, limit: int = 20, all_it
|
|
|
558
524
|
continue
|
|
559
525
|
ref_val = str(obj["ref"])
|
|
560
526
|
note_entries.append(obj)
|
|
561
|
-
if upd :=
|
|
527
|
+
if upd := str(obj.get("updated") or obj.get("created") or ""):
|
|
562
528
|
note_time[ref_val] = _ts_key(upd)
|
|
563
529
|
for lk in obj.get("links") or ():
|
|
564
530
|
if isinstance(lk, dict) and isinstance(lk.get("to"), str):
|
|
@@ -588,7 +554,7 @@ def review(store: Store, *, now: datetime | None = None, limit: int = 20, all_it
|
|
|
588
554
|
ref_val = str(obj.get("ref") or (f"{src}:{rec_id}" if rec_id else ""))
|
|
589
555
|
if not ref_val:
|
|
590
556
|
continue
|
|
591
|
-
if ts := str(obj.get("updated") or obj.get("
|
|
557
|
+
if ts := str(obj.get("updated") or obj.get("created") or ""):
|
|
592
558
|
rec_time[ref_val] = max(rec_time.get(ref_val, ""), _ts_key(ts))
|
|
593
559
|
if isinstance(lks := obj.get("links"), list):
|
|
594
560
|
for lk in lks:
|
|
@@ -602,13 +568,13 @@ def review(store: Store, *, now: datetime | None = None, limit: int = 20, all_it
|
|
|
602
568
|
today_iso = today.isoformat()
|
|
603
569
|
for entry in sorted(note_entries, key=lambda x: str(x["ref"])):
|
|
604
570
|
ref, status = str(entry["ref"]), str(entry.get("status") or "stable")
|
|
605
|
-
if status
|
|
571
|
+
if status in _TERMINAL_STATUSES:
|
|
606
572
|
continue
|
|
607
573
|
tasks_open += sum(1 for t in (entry.get("tasks") or ()) if isinstance(t, dict) and not t.get("done"))
|
|
608
574
|
reasons: list[str] = []
|
|
609
575
|
newer: list[str] = []
|
|
610
576
|
due = False
|
|
611
|
-
upd =
|
|
577
|
+
upd = str(entry.get("updated") or entry.get("created") or "")
|
|
612
578
|
if upd and ((len(upd) == 10 and upd > today_iso) or (len(upd) > 10 and _ts_key(upd) > _ts_key(now_iso))):
|
|
613
579
|
reasons.append("future_updated")
|
|
614
580
|
sa = entry.get("stale_after")
|