brain-framework 21.3.0__tar.gz → 21.4.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-21.3.0/README.md → brain_framework-21.4.0/PKG-INFO +75 -4
- brain_framework-21.3.0/PKG-INFO → brain_framework-21.4.0/README.md +41 -34
- {brain_framework-21.3.0 → brain_framework-21.4.0}/pyproject.toml +11 -2
- {brain_framework-21.3.0 → brain_framework-21.4.0}/pyproject.toml.orig +11 -2
- {brain_framework-21.3.0 → brain_framework-21.4.0}/src/bf/__init__.py +1 -1
- {brain_framework-21.3.0 → brain_framework-21.4.0}/src/bf/cli.py +21 -3
- {brain_framework-21.3.0 → brain_framework-21.4.0}/src/bf/collect.py +52 -9
- {brain_framework-21.3.0 → brain_framework-21.4.0}/src/bf/health.py +50 -11
- {brain_framework-21.3.0 → brain_framework-21.4.0}/src/bf/history.py +5 -0
- {brain_framework-21.3.0 → brain_framework-21.4.0}/src/bf/index.py +164 -14
- {brain_framework-21.3.0 → brain_framework-21.4.0}/src/bf/mcp.py +2 -1
- {brain_framework-21.3.0 → brain_framework-21.4.0}/src/bf/models.py +114 -17
- {brain_framework-21.3.0 → brain_framework-21.4.0}/src/bf/records.py +8 -4
- {brain_framework-21.3.0 → brain_framework-21.4.0}/src/bf/replies.py +262 -1
- {brain_framework-21.3.0 → brain_framework-21.4.0}/src/bf/retrieve.py +30 -10
- {brain_framework-21.3.0 → brain_framework-21.4.0}/src/bf/schemas.py +5 -7
- {brain_framework-21.3.0 → brain_framework-21.4.0}/src/bf/skills/README.md +1 -1
- {brain_framework-21.3.0 → brain_framework-21.4.0}/src/bf/skills/bf-maintain/references/integrations.md +3 -2
- {brain_framework-21.3.0 → brain_framework-21.4.0}/src/bf/skills/bf-maintain/references/operations.md +5 -3
- {brain_framework-21.3.0 → brain_framework-21.4.0}/src/bf/skills/bf-use/SKILL.md +4 -3
- {brain_framework-21.3.0 → brain_framework-21.4.0}/src/bf/skills/bf-use/references/evidence.md +2 -0
- {brain_framework-21.3.0 → brain_framework-21.4.0}/src/bf/skills/bf-use/references/retrieval.md +2 -2
- brain_framework-21.4.0/src/bf/starter/AGENTS.md +23 -0
- {brain_framework-21.3.0 → brain_framework-21.4.0}/src/bf/starter/evals/retrieval.yaml +1 -0
- {brain_framework-21.3.0 → brain_framework-21.4.0}/src/bf/watch.py +31 -4
- brain_framework-21.3.0/src/bf/starter/AGENTS.md +0 -19
- {brain_framework-21.3.0 → brain_framework-21.4.0}/LICENSE +0 -0
- {brain_framework-21.3.0 → brain_framework-21.4.0}/THIRD_PARTY_NOTICES.md +0 -0
- {brain_framework-21.3.0 → brain_framework-21.4.0}/src/bf/__main__.py +0 -0
- {brain_framework-21.3.0 → brain_framework-21.4.0}/src/bf/assistants.py +0 -0
- {brain_framework-21.3.0 → brain_framework-21.4.0}/src/bf/channels.py +0 -0
- {brain_framework-21.3.0 → brain_framework-21.4.0}/src/bf/config.py +0 -0
- {brain_framework-21.3.0 → brain_framework-21.4.0}/src/bf/evaluate.py +0 -0
- {brain_framework-21.3.0 → brain_framework-21.4.0}/src/bf/graph.py +0 -0
- {brain_framework-21.3.0 → brain_framework-21.4.0}/src/bf/install.py +0 -0
- {brain_framework-21.3.0 → brain_framework-21.4.0}/src/bf/links.py +0 -0
- {brain_framework-21.3.0 → brain_framework-21.4.0}/src/bf/markdown.py +0 -0
- {brain_framework-21.3.0 → brain_framework-21.4.0}/src/bf/messages.py +0 -0
- {brain_framework-21.3.0 → brain_framework-21.4.0}/src/bf/ontology.py +0 -0
- {brain_framework-21.3.0 → brain_framework-21.4.0}/src/bf/pages.py +0 -0
- {brain_framework-21.3.0 → brain_framework-21.4.0}/src/bf/py.typed +0 -0
- {brain_framework-21.3.0 → brain_framework-21.4.0}/src/bf/runtime.py +0 -0
- {brain_framework-21.3.0 → brain_framework-21.4.0}/src/bf/skills/bf-action/SKILL.md +0 -0
- {brain_framework-21.3.0 → brain_framework-21.4.0}/src/bf/skills/bf-action/references/actions.md +0 -0
- {brain_framework-21.3.0 → brain_framework-21.4.0}/src/bf/skills/bf-action/references/context.md +0 -0
- {brain_framework-21.3.0 → brain_framework-21.4.0}/src/bf/skills/bf-action/references/handoff.md +0 -0
- {brain_framework-21.3.0 → brain_framework-21.4.0}/src/bf/skills/bf-action/scripts/check-handoff.py +0 -0
- {brain_framework-21.3.0 → brain_framework-21.4.0}/src/bf/skills/bf-action/scripts/new-action.py +0 -0
- {brain_framework-21.3.0 → brain_framework-21.4.0}/src/bf/skills/bf-action/templates/action.md +0 -0
- {brain_framework-21.3.0 → brain_framework-21.4.0}/src/bf/skills/bf-maintain/SKILL.md +0 -0
- {brain_framework-21.3.0 → brain_framework-21.4.0}/src/bf/skills/bf-maintain/references/conflicts.md +0 -0
- {brain_framework-21.3.0 → brain_framework-21.4.0}/src/bf/skills/bf-setup/SKILL.md +0 -0
- {brain_framework-21.3.0 → brain_framework-21.4.0}/src/bf/skills/bf-setup/references/discovery.md +0 -0
- {brain_framework-21.3.0 → brain_framework-21.4.0}/src/bf/skills/bf-setup/references/import.md +0 -0
- {brain_framework-21.3.0 → brain_framework-21.4.0}/src/bf/skills/bf-setup/references/scan.md +0 -0
- {brain_framework-21.3.0 → brain_framework-21.4.0}/src/bf/skills/bf-setup/scripts/inventory.py +0 -0
- {brain_framework-21.3.0 → brain_framework-21.4.0}/src/bf/skills/bf-use/references/consolidate.md +0 -0
- {brain_framework-21.3.0 → brain_framework-21.4.0}/src/bf/skills/bf-use/references/decisions.md +0 -0
- {brain_framework-21.3.0 → brain_framework-21.4.0}/src/bf/skills/bf-use/references/learn.md +0 -0
- {brain_framework-21.3.0 → brain_framework-21.4.0}/src/bf/skills/bf-use/references/links.md +0 -0
- {brain_framework-21.3.0 → brain_framework-21.4.0}/src/bf/skills/bf-use/references/review.md +0 -0
- {brain_framework-21.3.0 → brain_framework-21.4.0}/src/bf/skills/bf-use/references/share.md +0 -0
- {brain_framework-21.3.0 → brain_framework-21.4.0}/src/bf/skills/bf-use/scripts/evidence.py +0 -0
- {brain_framework-21.3.0 → brain_framework-21.4.0}/src/bf/skills/bf-use/scripts/guarded-write.py +0 -0
- {brain_framework-21.3.0 → brain_framework-21.4.0}/src/bf/skills/bf-use/templates/concept.md +0 -0
- {brain_framework-21.3.0 → brain_framework-21.4.0}/src/bf/skills/bf-use/templates/project.md +0 -0
- {brain_framework-21.3.0 → brain_framework-21.4.0}/src/bf/starter/concepts/index.md +0 -0
- {brain_framework-21.3.0 → brain_framework-21.4.0}/src/bf/starter/concepts/welcome.md +0 -0
- {brain_framework-21.3.0 → brain_framework-21.4.0}/src/bf/starter/gitignore +0 -0
- {brain_framework-21.3.0 → brain_framework-21.4.0}/src/bf/storage.py +0 -0
- {brain_framework-21.3.0 → brain_framework-21.4.0}/src/bf/update.py +0 -0
- {brain_framework-21.3.0 → brain_framework-21.4.0}/src/bf/usage.py +0 -0
- {brain_framework-21.3.0 → brain_framework-21.4.0}/src/bf/validate.py +0 -0
- {brain_framework-21.3.0 → brain_framework-21.4.0}/src/bf/watch_settings.py +0 -0
|
@@ -1,3 +1,37 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: brain-framework
|
|
3
|
+
Version: 21.4.0
|
|
4
|
+
Summary: Brain Framework is a local-first brain for you and your AI agents. It gathers evidence from your tools into plain files you own, connects it through an ontology you declare, lets any agent harness search it offline and can wake that harness when a gate you review finds an event.
|
|
5
|
+
Keywords: ai,ai-agents,agent-memory,agent-skills,agents-md,context-engineering,knowledge-graph,knowledge-management,local-first,mcp,model-context-protocol,ontology,personal-knowledge-management,python,second-brain
|
|
6
|
+
Author: Médéric Hurier
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
License-File: THIRD_PARTY_NOTICES.md
|
|
10
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
11
|
+
Classifier: Environment :: Console
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Operating System :: MacOS
|
|
14
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
17
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
18
|
+
Classifier: Topic :: Text Processing :: Indexing
|
|
19
|
+
Classifier: Typing :: Typed
|
|
20
|
+
Requires-Dist: markdown-it-py>=4.2.0,<5
|
|
21
|
+
Requires-Dist: pydantic>=2.13.5,<3
|
|
22
|
+
Requires-Dist: pyyaml>=6.0.3,<7
|
|
23
|
+
Requires-Dist: rich>=15.0.0,<16
|
|
24
|
+
Requires-Dist: typer>=0.27.2,<1
|
|
25
|
+
Requires-Dist: mcp>=2.1.1,<3 ; extra == 'mcp'
|
|
26
|
+
Requires-Python: >=3.14
|
|
27
|
+
Project-URL: Changelog, https://fmind.github.io/brain-framework/changelog/
|
|
28
|
+
Project-URL: Documentation, https://fmind.github.io/brain-framework/
|
|
29
|
+
Project-URL: Issues, https://github.com/fmind/brain-framework/issues
|
|
30
|
+
Project-URL: Repository, https://github.com/fmind/brain-framework
|
|
31
|
+
Project-URL: Security, https://github.com/fmind/brain-framework/security/policy
|
|
32
|
+
Provides-Extra: mcp
|
|
33
|
+
Description-Content-Type: text/markdown
|
|
34
|
+
|
|
1
35
|
<p align="center">
|
|
2
36
|
<img
|
|
3
37
|
src="https://raw.githubusercontent.com/fmind/brain-framework/main/docs/assets/brain-framework.svg"
|
|
@@ -11,11 +45,15 @@
|
|
|
11
45
|
|
|
12
46
|
**🧠 Brain Framework: from information to informed actions.**
|
|
13
47
|
|
|
14
|
-
|
|
48
|
+
Brain Framework is a local-first brain for you and your AI agents. It gathers evidence from your tools into plain files you own, connects it through an ontology you declare, lets any agent harness search it offline and can wake that harness when a gate you review finds an event.
|
|
49
|
+
|
|
50
|
+
- **Files you own, open to any agent.** A brain is a folder of Markdown and JSON. Agents reach it through the `bf` CLI, [MCP](https://fmind.github.io/brain-framework/docs/mcp/), [Agent Skills](https://agentskills.io/specification) and `AGENTS.md`.
|
|
51
|
+
- **Connections you declare.** Fields and links are explicit, and each claim keeps its source record. When that record changes, `newer_evidence` flags the conclusion. Nothing is inferred.
|
|
52
|
+
- **You decide when your agent runs.** [Gate programs](https://github.com/fmind/brain-framework#let-your-agent-come-to-you) you review can decide when your harness starts, and the harness's own permissions decide what it may do.
|
|
15
53
|
|
|
16
54
|
[](https://github.com/fmind/brain-framework/actions/workflows/ci.yml) [](https://pypi.org/project/brain-framework/) [](https://pypi.org/project/brain-framework/) [](https://github.com/fmind/brain-framework/blob/main/LICENSE)
|
|
17
55
|
|
|
18
|
-
[Try it](https://github.com/fmind/brain-framework#try-it) · [How it works](https://github.com/fmind/brain-framework#how-it-works) · [Agents](https://github.com/fmind/brain-framework#open-your-agent-in-your-brain) · [Your tools](https://github.com/fmind/brain-framework#bring-your-tools) · [Good to know](https://github.com/fmind/brain-framework#good-to-know) · [Documentation](https://fmind.github.io/brain-framework/)
|
|
56
|
+
[Try it](https://github.com/fmind/brain-framework#try-it) · [How it works](https://github.com/fmind/brain-framework#how-it-works) · [Agents](https://github.com/fmind/brain-framework#open-your-agent-in-your-brain) · [Your tools](https://github.com/fmind/brain-framework#bring-your-tools) · [Proactive agents](https://github.com/fmind/brain-framework#let-your-agent-come-to-you) · [Good to know](https://github.com/fmind/brain-framework#good-to-know) · [Documentation](https://fmind.github.io/brain-framework/)
|
|
19
57
|
|
|
20
58
|
<a href="https://raw.githubusercontent.com/fmind/brain-framework/main/docs/assets/brain-loop.svg">
|
|
21
59
|
<img
|
|
@@ -228,12 +266,45 @@ After reviewing your sensors, run `bf watch` to keep them refreshed and see fail
|
|
|
228
266
|
|
|
229
267
|
The dashboard shows the [offline watch demo](https://github.com/fmind/brain-framework/tree/main/examples/watch), which needs no provider account.
|
|
230
268
|
|
|
269
|
+
## Let your agent come to you
|
|
270
|
+
|
|
271
|
+
An [assistant](https://fmind.github.io/brain-framework/docs/prompts/) can watch what your sensors collect and speak first:
|
|
272
|
+
|
|
273
|
+
```yaml
|
|
274
|
+
assistants:
|
|
275
|
+
triage:
|
|
276
|
+
prompt: prompts/triage.md
|
|
277
|
+
# Claude Code may run only bf read and bf search, plus what its settings allow: swap in your harness.
|
|
278
|
+
command:
|
|
279
|
+
[
|
|
280
|
+
claude,
|
|
281
|
+
--print,
|
|
282
|
+
--output-format,
|
|
283
|
+
json,
|
|
284
|
+
--json-schema,
|
|
285
|
+
"{{schema}}",
|
|
286
|
+
--tools,
|
|
287
|
+
"Read,Grep,Glob,Bash",
|
|
288
|
+
--allowedTools,
|
|
289
|
+
"Bash(bf read *),Bash(bf search *)",
|
|
290
|
+
--permission-mode,
|
|
291
|
+
dontAsk,
|
|
292
|
+
]
|
|
293
|
+
reply: { path: /structured_output } # {say, wake}
|
|
294
|
+
post: desktop # a channel you declare
|
|
295
|
+
wake: { min: 600, max: 86400 }
|
|
296
|
+
schedules:
|
|
297
|
+
mail: { every: 600, gate: { command: [python3, routines/records-gate.py, mail] } }
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
While `bf watch` runs, a [gate](https://github.com/fmind/brain-framework/blob/main/examples/routines/records-gate.py) you review checks the collected records every 10 minutes. Each check starts your harness only when the gate finds events. The harness speaks or stays silent and may ask for one follow-up wake. BF posts its answer to your channel and records each run. Mail text reaches your harness, so [limit its tools](https://fmind.github.io/brain-framework/docs/prompts/#keep-prompts-safe), or let a read-only assistant [propose and another act](https://fmind.github.io/brain-framework/docs/prompts/#propose-then-act).
|
|
301
|
+
|
|
231
302
|
## Good to know
|
|
232
303
|
|
|
233
304
|
1. **Your data stays on your computer.** A brain is a folder on your disk. BF has no account, server or telemetry, and search and read work offline. Sensors collect while your machine is on.
|
|
234
305
|
1. **Your agent does the reasoning.** BF never runs a model: it collects, validates, searches and connects, and its [assistants](https://fmind.github.io/brain-framework/docs/prompts/) launch your agent harness. What your agent reads reaches that harness's provider; see [privacy and security](https://fmind.github.io/brain-framework/docs/privacy/) for a fully local setup.
|
|
235
306
|
1. **Git gives history and sharing.** Notes and programs are plain files: commit them for history, rollback and review. By default, collected records stay out of Git. A team brain is a private repository with one clone per teammate, and a personal brain can include it in its searches. See [team setup](https://fmind.github.io/brain-framework/docs/team/).
|
|
236
|
-
1. **It takes some setup.** Each source needs its access, such as `gh auth login` or `gcloud` authentication, then a sensor you review. Sensors, routines and the ontology are files you can read, edit or ask your agent to adapt.
|
|
307
|
+
1. **It takes some setup.** Each source needs its access, such as `gh auth login` or `gcloud` authentication, then a sensor you review. Sensors, routines and the ontology are files you can read, edit or ask your agent to adapt. A major release lists its manual upgrade steps; see [versioning and stability](https://fmind.github.io/brain-framework/docs/upgrades/#versioning-and-stability).
|
|
237
308
|
1. **It finds what was said and linked, not what was meant.** Search matches words and explicit identities, without embeddings, and incomplete results say so. Collect again when you need newer evidence. See [what BF does not do](https://fmind.github.io/brain-framework/docs/concepts/#what-bf-does-not-do).
|
|
238
309
|
|
|
239
|
-
[Browse the commands](https://fmind.github.io/brain-framework/docs/commands/) · [Report an issue](https://github.com/fmind/brain-framework/issues) · [Contribute](https://github.com/fmind/brain-framework/blob/main/CONTRIBUTING.md) · [MIT licensed](https://github.com/fmind/brain-framework/blob/main/LICENSE) · [Third-party notices](https://github.com/fmind/brain-framework/blob/main/THIRD_PARTY_NOTICES.md)
|
|
310
|
+
[Browse the commands](https://fmind.github.io/brain-framework/docs/commands/) · [Report an issue](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) · [MIT licensed](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,33 +1,3 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: brain-framework
|
|
3
|
-
Version: 21.3.0
|
|
4
|
-
Summary: 🧠 Brain Framework: from information to informed actions.
|
|
5
|
-
Keywords: ai,ai-agents,agent-memory,context-engineering,knowledge-management,local-first,mcp,model-context-protocol,python,second-brain
|
|
6
|
-
Author: Médéric Hurier
|
|
7
|
-
License-Expression: MIT
|
|
8
|
-
License-File: LICENSE
|
|
9
|
-
License-File: THIRD_PARTY_NOTICES.md
|
|
10
|
-
Classifier: Development Status :: 5 - Production/Stable
|
|
11
|
-
Classifier: Environment :: Console
|
|
12
|
-
Classifier: Operating System :: MacOS
|
|
13
|
-
Classifier: Operating System :: POSIX :: Linux
|
|
14
|
-
Classifier: Programming Language :: Python :: 3
|
|
15
|
-
Classifier: Programming Language :: Python :: 3.14
|
|
16
|
-
Classifier: Typing :: Typed
|
|
17
|
-
Requires-Dist: markdown-it-py>=4.2.0,<5
|
|
18
|
-
Requires-Dist: pydantic>=2.13.5,<3
|
|
19
|
-
Requires-Dist: pyyaml>=6.0.3,<7
|
|
20
|
-
Requires-Dist: rich>=15.0.0,<16
|
|
21
|
-
Requires-Dist: typer>=0.27.2,<1
|
|
22
|
-
Requires-Dist: mcp>=2.1.1,<3 ; extra == 'mcp'
|
|
23
|
-
Requires-Python: >=3.14
|
|
24
|
-
Project-URL: Changelog, https://fmind.github.io/brain-framework/changelog/
|
|
25
|
-
Project-URL: Documentation, https://fmind.github.io/brain-framework/
|
|
26
|
-
Project-URL: Issues, https://github.com/fmind/brain-framework/issues
|
|
27
|
-
Project-URL: Repository, https://github.com/fmind/brain-framework
|
|
28
|
-
Provides-Extra: mcp
|
|
29
|
-
Description-Content-Type: text/markdown
|
|
30
|
-
|
|
31
1
|
<p align="center">
|
|
32
2
|
<img
|
|
33
3
|
src="https://raw.githubusercontent.com/fmind/brain-framework/main/docs/assets/brain-framework.svg"
|
|
@@ -41,11 +11,15 @@ Description-Content-Type: text/markdown
|
|
|
41
11
|
|
|
42
12
|
**🧠 Brain Framework: from information to informed actions.**
|
|
43
13
|
|
|
44
|
-
|
|
14
|
+
Brain Framework is a local-first brain for you and your AI agents. It gathers evidence from your tools into plain files you own, connects it through an ontology you declare, lets any agent harness search it offline and can wake that harness when a gate you review finds an event.
|
|
15
|
+
|
|
16
|
+
- **Files you own, open to any agent.** A brain is a folder of Markdown and JSON. Agents reach it through the `bf` CLI, [MCP](https://fmind.github.io/brain-framework/docs/mcp/), [Agent Skills](https://agentskills.io/specification) and `AGENTS.md`.
|
|
17
|
+
- **Connections you declare.** Fields and links are explicit, and each claim keeps its source record. When that record changes, `newer_evidence` flags the conclusion. Nothing is inferred.
|
|
18
|
+
- **You decide when your agent runs.** [Gate programs](https://github.com/fmind/brain-framework#let-your-agent-come-to-you) you review can decide when your harness starts, and the harness's own permissions decide what it may do.
|
|
45
19
|
|
|
46
20
|
[](https://github.com/fmind/brain-framework/actions/workflows/ci.yml) [](https://pypi.org/project/brain-framework/) [](https://pypi.org/project/brain-framework/) [](https://github.com/fmind/brain-framework/blob/main/LICENSE)
|
|
47
21
|
|
|
48
|
-
[Try it](https://github.com/fmind/brain-framework#try-it) · [How it works](https://github.com/fmind/brain-framework#how-it-works) · [Agents](https://github.com/fmind/brain-framework#open-your-agent-in-your-brain) · [Your tools](https://github.com/fmind/brain-framework#bring-your-tools) · [Good to know](https://github.com/fmind/brain-framework#good-to-know) · [Documentation](https://fmind.github.io/brain-framework/)
|
|
22
|
+
[Try it](https://github.com/fmind/brain-framework#try-it) · [How it works](https://github.com/fmind/brain-framework#how-it-works) · [Agents](https://github.com/fmind/brain-framework#open-your-agent-in-your-brain) · [Your tools](https://github.com/fmind/brain-framework#bring-your-tools) · [Proactive agents](https://github.com/fmind/brain-framework#let-your-agent-come-to-you) · [Good to know](https://github.com/fmind/brain-framework#good-to-know) · [Documentation](https://fmind.github.io/brain-framework/)
|
|
49
23
|
|
|
50
24
|
<a href="https://raw.githubusercontent.com/fmind/brain-framework/main/docs/assets/brain-loop.svg">
|
|
51
25
|
<img
|
|
@@ -258,12 +232,45 @@ After reviewing your sensors, run `bf watch` to keep them refreshed and see fail
|
|
|
258
232
|
|
|
259
233
|
The dashboard shows the [offline watch demo](https://github.com/fmind/brain-framework/tree/main/examples/watch), which needs no provider account.
|
|
260
234
|
|
|
235
|
+
## Let your agent come to you
|
|
236
|
+
|
|
237
|
+
An [assistant](https://fmind.github.io/brain-framework/docs/prompts/) can watch what your sensors collect and speak first:
|
|
238
|
+
|
|
239
|
+
```yaml
|
|
240
|
+
assistants:
|
|
241
|
+
triage:
|
|
242
|
+
prompt: prompts/triage.md
|
|
243
|
+
# Claude Code may run only bf read and bf search, plus what its settings allow: swap in your harness.
|
|
244
|
+
command:
|
|
245
|
+
[
|
|
246
|
+
claude,
|
|
247
|
+
--print,
|
|
248
|
+
--output-format,
|
|
249
|
+
json,
|
|
250
|
+
--json-schema,
|
|
251
|
+
"{{schema}}",
|
|
252
|
+
--tools,
|
|
253
|
+
"Read,Grep,Glob,Bash",
|
|
254
|
+
--allowedTools,
|
|
255
|
+
"Bash(bf read *),Bash(bf search *)",
|
|
256
|
+
--permission-mode,
|
|
257
|
+
dontAsk,
|
|
258
|
+
]
|
|
259
|
+
reply: { path: /structured_output } # {say, wake}
|
|
260
|
+
post: desktop # a channel you declare
|
|
261
|
+
wake: { min: 600, max: 86400 }
|
|
262
|
+
schedules:
|
|
263
|
+
mail: { every: 600, gate: { command: [python3, routines/records-gate.py, mail] } }
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
While `bf watch` runs, a [gate](https://github.com/fmind/brain-framework/blob/main/examples/routines/records-gate.py) you review checks the collected records every 10 minutes. Each check starts your harness only when the gate finds events. The harness speaks or stays silent and may ask for one follow-up wake. BF posts its answer to your channel and records each run. Mail text reaches your harness, so [limit its tools](https://fmind.github.io/brain-framework/docs/prompts/#keep-prompts-safe), or let a read-only assistant [propose and another act](https://fmind.github.io/brain-framework/docs/prompts/#propose-then-act).
|
|
267
|
+
|
|
261
268
|
## Good to know
|
|
262
269
|
|
|
263
270
|
1. **Your data stays on your computer.** A brain is a folder on your disk. BF has no account, server or telemetry, and search and read work offline. Sensors collect while your machine is on.
|
|
264
271
|
1. **Your agent does the reasoning.** BF never runs a model: it collects, validates, searches and connects, and its [assistants](https://fmind.github.io/brain-framework/docs/prompts/) launch your agent harness. What your agent reads reaches that harness's provider; see [privacy and security](https://fmind.github.io/brain-framework/docs/privacy/) for a fully local setup.
|
|
265
272
|
1. **Git gives history and sharing.** Notes and programs are plain files: commit them for history, rollback and review. By default, collected records stay out of Git. A team brain is a private repository with one clone per teammate, and a personal brain can include it in its searches. See [team setup](https://fmind.github.io/brain-framework/docs/team/).
|
|
266
|
-
1. **It takes some setup.** Each source needs its access, such as `gh auth login` or `gcloud` authentication, then a sensor you review. Sensors, routines and the ontology are files you can read, edit or ask your agent to adapt.
|
|
273
|
+
1. **It takes some setup.** Each source needs its access, such as `gh auth login` or `gcloud` authentication, then a sensor you review. Sensors, routines and the ontology are files you can read, edit or ask your agent to adapt. A major release lists its manual upgrade steps; see [versioning and stability](https://fmind.github.io/brain-framework/docs/upgrades/#versioning-and-stability).
|
|
267
274
|
1. **It finds what was said and linked, not what was meant.** Search matches words and explicit identities, without embeddings, and incomplete results say so. Collect again when you need newer evidence. See [what BF does not do](https://fmind.github.io/brain-framework/docs/concepts/#what-bf-does-not-do).
|
|
268
275
|
|
|
269
|
-
[Browse the commands](https://fmind.github.io/brain-framework/docs/commands/) · [Report an issue](https://github.com/fmind/brain-framework/issues) · [Contribute](https://github.com/fmind/brain-framework/blob/main/CONTRIBUTING.md) · [MIT licensed](https://github.com/fmind/brain-framework/blob/main/LICENSE) · [Third-party notices](https://github.com/fmind/brain-framework/blob/main/THIRD_PARTY_NOTICES.md)
|
|
276
|
+
[Browse the commands](https://fmind.github.io/brain-framework/docs/commands/) · [Report an issue](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) · [MIT licensed](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,7 +1,7 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "brain-framework"
|
|
3
|
-
version = "21.
|
|
4
|
-
description = "
|
|
3
|
+
version = "21.4.0"
|
|
4
|
+
description = "Brain Framework is a local-first brain for you and your AI agents. It gathers evidence from your tools into plain files you own, connects it through an ontology you declare, lets any agent harness search it offline and can wake that harness when a gate you review finds an event."
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
requires-python = ">=3.14"
|
|
7
7
|
license = "MIT"
|
|
@@ -13,21 +13,29 @@ keywords = [
|
|
|
13
13
|
"ai",
|
|
14
14
|
"ai-agents",
|
|
15
15
|
"agent-memory",
|
|
16
|
+
"agent-skills",
|
|
17
|
+
"agents-md",
|
|
16
18
|
"context-engineering",
|
|
19
|
+
"knowledge-graph",
|
|
17
20
|
"knowledge-management",
|
|
18
21
|
"local-first",
|
|
19
22
|
"mcp",
|
|
20
23
|
"model-context-protocol",
|
|
24
|
+
"ontology",
|
|
25
|
+
"personal-knowledge-management",
|
|
21
26
|
"python",
|
|
22
27
|
"second-brain",
|
|
23
28
|
]
|
|
24
29
|
classifiers = [
|
|
25
30
|
"Development Status :: 5 - Production/Stable",
|
|
26
31
|
"Environment :: Console",
|
|
32
|
+
"Intended Audience :: Developers",
|
|
27
33
|
"Operating System :: MacOS",
|
|
28
34
|
"Operating System :: POSIX :: Linux",
|
|
29
35
|
"Programming Language :: Python :: 3",
|
|
30
36
|
"Programming Language :: Python :: 3.14",
|
|
37
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
38
|
+
"Topic :: Text Processing :: Indexing",
|
|
31
39
|
"Typing :: Typed",
|
|
32
40
|
]
|
|
33
41
|
dependencies = [
|
|
@@ -49,6 +57,7 @@ Changelog = "https://fmind.github.io/brain-framework/changelog/"
|
|
|
49
57
|
Documentation = "https://fmind.github.io/brain-framework/"
|
|
50
58
|
Issues = "https://github.com/fmind/brain-framework/issues"
|
|
51
59
|
Repository = "https://github.com/fmind/brain-framework"
|
|
60
|
+
Security = "https://github.com/fmind/brain-framework/security/policy"
|
|
52
61
|
|
|
53
62
|
[project.scripts]
|
|
54
63
|
bf = "bf:main"
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# https://packaging.python.org/en/latest/specifications/pyproject-toml/
|
|
2
2
|
[project]
|
|
3
3
|
name = "brain-framework"
|
|
4
|
-
version = "21.
|
|
5
|
-
description = "
|
|
4
|
+
version = "21.4.0"
|
|
5
|
+
description = "Brain Framework is a local-first brain for you and your AI agents. It gathers evidence from your tools into plain files you own, connects it through an ontology you declare, lets any agent harness search it offline and can wake that harness when a gate you review finds an event."
|
|
6
6
|
readme = "README.md"
|
|
7
7
|
requires-python = ">=3.14"
|
|
8
8
|
license = "MIT"
|
|
@@ -12,21 +12,29 @@ keywords = [
|
|
|
12
12
|
"ai",
|
|
13
13
|
"ai-agents",
|
|
14
14
|
"agent-memory",
|
|
15
|
+
"agent-skills",
|
|
16
|
+
"agents-md",
|
|
15
17
|
"context-engineering",
|
|
18
|
+
"knowledge-graph",
|
|
16
19
|
"knowledge-management",
|
|
17
20
|
"local-first",
|
|
18
21
|
"mcp",
|
|
19
22
|
"model-context-protocol",
|
|
23
|
+
"ontology",
|
|
24
|
+
"personal-knowledge-management",
|
|
20
25
|
"python",
|
|
21
26
|
"second-brain",
|
|
22
27
|
]
|
|
23
28
|
classifiers = [
|
|
24
29
|
"Development Status :: 5 - Production/Stable",
|
|
25
30
|
"Environment :: Console",
|
|
31
|
+
"Intended Audience :: Developers",
|
|
26
32
|
"Operating System :: MacOS",
|
|
27
33
|
"Operating System :: POSIX :: Linux",
|
|
28
34
|
"Programming Language :: Python :: 3",
|
|
29
35
|
"Programming Language :: Python :: 3.14",
|
|
36
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
37
|
+
"Topic :: Text Processing :: Indexing",
|
|
30
38
|
"Typing :: Typed",
|
|
31
39
|
]
|
|
32
40
|
dependencies = [
|
|
@@ -46,6 +54,7 @@ Changelog = "https://fmind.github.io/brain-framework/changelog/"
|
|
|
46
54
|
Documentation = "https://fmind.github.io/brain-framework/"
|
|
47
55
|
Issues = "https://github.com/fmind/brain-framework/issues"
|
|
48
56
|
Repository = "https://github.com/fmind/brain-framework"
|
|
57
|
+
Security = "https://github.com/fmind/brain-framework/security/policy"
|
|
49
58
|
|
|
50
59
|
[project.scripts]
|
|
51
60
|
bf = "bf:main"
|
|
@@ -276,6 +276,9 @@ def _vacant(directory: Path) -> None:
|
|
|
276
276
|
raise Error("initialization requires a new, empty or freshly cloned directory")
|
|
277
277
|
|
|
278
278
|
|
|
279
|
+
# This release's published schemas, for editor modelines: the strict schema on main may already belong to the next
|
|
280
|
+
# major, which can reject keys this release accepts. Editors fetch them; BF itself stays offline.
|
|
281
|
+
SCHEMAS = f"https://raw.githubusercontent.com/fmind/brain-framework/v{__version__}/docs/"
|
|
279
282
|
# The standard vocabulary (docs/docs/schema.md#standard-vocabulary): sensors that print these attributes plug into a
|
|
280
283
|
# new brain without mappings, and notes link with the relations at the end.
|
|
281
284
|
_PEOPLE = {
|
|
@@ -327,6 +330,20 @@ STANDARD_FIELDS = {
|
|
|
327
330
|
relation=True,
|
|
328
331
|
path="/attributes/project_refs",
|
|
329
332
|
),
|
|
333
|
+
"part-of": SchemaField(
|
|
334
|
+
description="Containing thread, folder, list, epic, project or other parent item.",
|
|
335
|
+
type="identity",
|
|
336
|
+
cardinality="many",
|
|
337
|
+
relation=True,
|
|
338
|
+
path="/attributes/parent_refs",
|
|
339
|
+
),
|
|
340
|
+
"label": SchemaField(
|
|
341
|
+
description="Label the provider attaches to the item.",
|
|
342
|
+
type="identity",
|
|
343
|
+
cardinality="many",
|
|
344
|
+
relation=True,
|
|
345
|
+
path="/attributes/label_refs",
|
|
346
|
+
),
|
|
330
347
|
"kind": SchemaField(
|
|
331
348
|
description="Provider-declared kind of item within a source that mixes several kinds.",
|
|
332
349
|
type="string",
|
|
@@ -379,7 +396,7 @@ def initialize(
|
|
|
379
396
|
store.write(
|
|
380
397
|
"bf.yaml",
|
|
381
398
|
(
|
|
382
|
-
"# https://fmind.github.io/brain-framework/\n"
|
|
399
|
+
f"# https://fmind.github.io/brain-framework/\n# yaml-language-server: $schema={SCHEMAS}bf.schema.json\n"
|
|
383
400
|
+ yaml.safe_dump(config.model_dump(by_alias=True, exclude_defaults=True), sort_keys=False, width=1000)
|
|
384
401
|
).encode(),
|
|
385
402
|
)
|
|
@@ -387,7 +404,7 @@ def initialize(
|
|
|
387
404
|
text = (files("bf") / "starter" / source).read_text(encoding="utf-8")
|
|
388
405
|
if target.endswith(".yaml"):
|
|
389
406
|
# The checks read the welcome note by the brain's own address, in the current format.
|
|
390
|
-
text = Template(text).substitute(name=name, version=FORMAT)
|
|
407
|
+
text = Template(text).substitute(name=name, version=FORMAT, schemas=SCHEMAS)
|
|
391
408
|
store.write(target, text.encode())
|
|
392
409
|
for directory in FOLDERS + (OPTIONAL if full else ()):
|
|
393
410
|
store.write(directory + "/.gitkeep", b"")
|
|
@@ -948,7 +965,8 @@ def report(
|
|
|
948
965
|
bool,
|
|
949
966
|
typer.Option(
|
|
950
967
|
help="Exit 1 on problems, an unavailable cache, brain or reference, scheduled programs that failed, are "
|
|
951
|
-
"overdue, never succeeded or fell silent,
|
|
968
|
+
"overdue, due but never succeeded or fell silent, sources degraded three runs in a row, unresolved "
|
|
969
|
+
"assistant work, or a failing channel."
|
|
952
970
|
),
|
|
953
971
|
] = False,
|
|
954
972
|
watch: Annotated[
|
|
@@ -61,6 +61,8 @@ CATCH_UP = timedelta(days=30)
|
|
|
61
61
|
BACKOFF = timedelta(minutes=1)
|
|
62
62
|
# A snapshot may remove half of its catalog, or up to this many records, without --allow-removal.
|
|
63
63
|
SHRINK_FLOOR = 10
|
|
64
|
+
# The largest count a sensor may report missing or tried: replies keep it an exact JSON integer.
|
|
65
|
+
MAX_COUNT = 2**53 - 1
|
|
64
66
|
# Reprojected records committed per transaction; a reply lists at most LIMIT records that failed.
|
|
65
67
|
REPROJECT = 1000
|
|
66
68
|
LIMIT = 200
|
|
@@ -440,6 +442,30 @@ def _coverage(
|
|
|
440
442
|
return {"start": interval[0], "end": interval[1]}, contiguous and (sensor.mode == "snapshot" or end >= observed)
|
|
441
443
|
|
|
442
444
|
|
|
445
|
+
def _envelope(printed: object) -> tuple[object, dict[str, int]]:
|
|
446
|
+
"""The records a sensor printed and what it reported missing: a JSON array alone, or the object
|
|
447
|
+
`{"records": [...], "incomplete": {"missed": N, "of": M}}` with integers 1 <= N <= M and no other keys.
|
|
448
|
+
|
|
449
|
+
Errors name the field, never a value or an unknown key, which the provider's output controls.
|
|
450
|
+
"""
|
|
451
|
+
if not isinstance(printed, dict):
|
|
452
|
+
return printed, {}
|
|
453
|
+
if printed.keys() != {"records", "incomplete"}:
|
|
454
|
+
raise Error("collector must print one JSON array of records, or an object holding only records and incomplete")
|
|
455
|
+
incomplete = printed["incomplete"]
|
|
456
|
+
if not isinstance(incomplete, dict) or incomplete.keys() != {"missed", "of"}:
|
|
457
|
+
raise Error("incomplete must be an object holding only missed and of")
|
|
458
|
+
for key in ("of", "missed"):
|
|
459
|
+
# A bool is an int to Python, and 1.0 is no count.
|
|
460
|
+
if type(incomplete[key]) is not int or not 1 <= incomplete[key] <= MAX_COUNT:
|
|
461
|
+
raise Error(f"incomplete.{key} must be an integer from 1 to {MAX_COUNT}")
|
|
462
|
+
if incomplete["missed"] > incomplete["of"]:
|
|
463
|
+
raise Error("incomplete.missed must not exceed incomplete.of")
|
|
464
|
+
if not isinstance(printed["records"], list):
|
|
465
|
+
raise Error("records must be one JSON array of records")
|
|
466
|
+
return printed["records"], {"missed": incomplete["missed"], "of": incomplete["of"]}
|
|
467
|
+
|
|
468
|
+
|
|
443
469
|
def _project(position: int, record: Record, sensor: Sensor, config: Config, observed: str) -> Record:
|
|
444
470
|
"""Map one printed record and stamp when it was observed; an error names its zero-based position, never a value."""
|
|
445
471
|
try:
|
|
@@ -483,8 +509,10 @@ def collect(
|
|
|
483
509
|
|
|
484
510
|
A snapshot that would empty its catalog, or remove more than half of it and more than SHRINK_FLOOR
|
|
485
511
|
records, fails unless `allow_removal` accepts it for this run. Records of the source's forgotten list, and with
|
|
486
|
-
`expire_after` records older than its cutoff, are removed and never stored again. A
|
|
487
|
-
|
|
512
|
+
`expire_after` records older than its cutoff, are removed and never stored again. A run whose sensor reports
|
|
513
|
+
`incomplete` removes no other record, whatever its mode or `allow_removal`: a lost feed or account must not
|
|
514
|
+
erase evidence. A `fixture` replaces the sensor's output in a preview that runs nothing, even for a disabled
|
|
515
|
+
sensor: a contract test of saved output.
|
|
488
516
|
"""
|
|
489
517
|
start, end = _window(start, end)
|
|
490
518
|
config = load(store)
|
|
@@ -512,7 +540,7 @@ def collect(
|
|
|
512
540
|
# A fixture runs nothing, so its placeholders never need this machine's line files or HOME.
|
|
513
541
|
argv = [] if fixture is not None else arguments(store, sensor, start, end)
|
|
514
542
|
raw = runner(argv, sensor, store, name, b"")
|
|
515
|
-
printed = decode(raw)
|
|
543
|
+
printed, incomplete = _envelope(decode(raw))
|
|
516
544
|
text_limit = sensor.max_text_bytes or (4 << 20)
|
|
517
545
|
truncated_count = 0
|
|
518
546
|
if isinstance(printed, list):
|
|
@@ -567,13 +595,16 @@ def collect(
|
|
|
567
595
|
"requested_end": end,
|
|
568
596
|
"reconcile": reconcile,
|
|
569
597
|
"output_bytes": len(raw),
|
|
598
|
+
**({"incomplete": incomplete} if incomplete else {}),
|
|
570
599
|
}
|
|
571
|
-
snapshot
|
|
600
|
+
# An incomplete snapshot updates what it printed, like a window: absent records may sit in the lost part.
|
|
601
|
+
snapshot = sensor.mode == "snapshot" and not incomplete
|
|
602
|
+
expire_stored = not incomplete
|
|
572
603
|
if dry_run:
|
|
573
604
|
# What a real run would change, from the records as they are: an interrupted commit that the run
|
|
574
605
|
# would first recover fails the preview instead, as reads do.
|
|
575
606
|
with records.reading(store):
|
|
576
|
-
kept = records.retention(store, name, incoming, cutoff=cutoff)
|
|
607
|
+
kept = records.retention(store, name, incoming, cutoff=cutoff, expire_stored=expire_stored)
|
|
577
608
|
counts, _ = records.plan(store, name, kept.kept, snapshot=snapshot)
|
|
578
609
|
if snapshot:
|
|
579
610
|
# The plan also removes these files; a real run counts them as forgotten or expired.
|
|
@@ -592,7 +623,7 @@ def collect(
|
|
|
592
623
|
# An interrupted commit may have removed files already: count the catalog it restores.
|
|
593
624
|
records.recover(store)
|
|
594
625
|
# Read under the lock, so a concurrent bf forget is either seen or waits for this run.
|
|
595
|
-
kept = records.retention(store, name, incoming, cutoff=cutoff)
|
|
626
|
+
kept = records.retention(store, name, incoming, cutoff=cutoff, expire_stored=expire_stored)
|
|
596
627
|
# Forgotten and expired records leave on purpose: only other removals need --allow-removal.
|
|
597
628
|
if snapshot and not allow_removal and (refusal := _shrink(store, name, kept)):
|
|
598
629
|
raise Error(refusal)
|
|
@@ -600,7 +631,9 @@ def collect(
|
|
|
600
631
|
result.update(records=len(kept.kept), **_retention(kept))
|
|
601
632
|
committed = True
|
|
602
633
|
result["elapsed_seconds"] = round(time.monotonic() - measured, 6)
|
|
603
|
-
|
|
634
|
+
previous = state(store).get(name, {})
|
|
635
|
+
coverage, latest = _coverage(previous, start, end, observed, sensor)
|
|
636
|
+
streak = cast(int, previous.get("incomplete_runs", 0))
|
|
604
637
|
remember(
|
|
605
638
|
store,
|
|
606
639
|
name,
|
|
@@ -615,8 +648,17 @@ def collect(
|
|
|
615
648
|
**{
|
|
616
649
|
"forgotten": 0,
|
|
617
650
|
"expired": 0,
|
|
618
|
-
**{key: value for key, value in result.items() if key
|
|
651
|
+
**{key: value for key, value in result.items() if key not in {"sensor", "incomplete"}},
|
|
619
652
|
},
|
|
653
|
+
# A complete run resets an incomplete streak; history without one gains no keys, so an earlier
|
|
654
|
+
# 21.x release still loads it.
|
|
655
|
+
**(
|
|
656
|
+
{**incomplete, "incomplete_runs": streak + 1}
|
|
657
|
+
if incomplete
|
|
658
|
+
else {"missed": 0, "of": 0, "incomplete_runs": 0}
|
|
659
|
+
if streak
|
|
660
|
+
else {}
|
|
661
|
+
),
|
|
620
662
|
)
|
|
621
663
|
except (Error, OSError, UnicodeError) as error:
|
|
622
664
|
message = (
|
|
@@ -632,8 +674,9 @@ def collect(
|
|
|
632
674
|
)
|
|
633
675
|
_failed(store, name, SENSORS, started, message, error, dry_run=dry_run)
|
|
634
676
|
counts = ", ".join(f"{result.get(key, 0)} {key}" for key in ("added", "updated", "unchanged", "removed"))
|
|
677
|
+
missing = f"; missed {incomplete['missed']} of {incomplete['of']}" if incomplete else ""
|
|
635
678
|
with suppress(Error, OSError):
|
|
636
|
-
append_log(store, name, f"{_now()} collected {result['records']} records: {counts}")
|
|
679
|
+
append_log(store, name, f"{_now()} collected {result['records']} records: {counts}{missing}")
|
|
637
680
|
return result
|
|
638
681
|
|
|
639
682
|
|
|
@@ -33,10 +33,9 @@ _COUNTERS = (
|
|
|
33
33
|
"output_bytes",
|
|
34
34
|
)
|
|
35
35
|
_RETAINED = frozenset({"forgotten", "expired"})
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
_LATE = frozenset({"overdue", "never"})
|
|
36
|
+
# Committed runs in a row reporting missing items before a scheduled source needs attention: one lost feed can be a
|
|
37
|
+
# passing provider error, three are a lasting gap.
|
|
38
|
+
DEGRADED = 3
|
|
40
39
|
|
|
41
40
|
|
|
42
41
|
def _freshness(program: Program | None, success: str, now: datetime) -> str:
|
|
@@ -66,6 +65,22 @@ def _silent(sensor: Sensor | None, success: str, changed: str, now: datetime) ->
|
|
|
66
65
|
return now - datetime.fromisoformat(changed) > timedelta(seconds=sensor.silent_after)
|
|
67
66
|
|
|
68
67
|
|
|
68
|
+
def degradation(entry: Mapping[str, object]) -> dict[str, object] | None:
|
|
69
|
+
"""What a sensor's last committed run reported missing, and how many committed runs in a row did; None after a
|
|
70
|
+
complete run. Labels and reasons stay in the sensor's log."""
|
|
71
|
+
# Run history is validated already: each count is a non-negative integer.
|
|
72
|
+
runs, missed, of = (int(cast("int", entry.get(key, 0))) for key in ("incomplete_runs", "missed", "of"))
|
|
73
|
+
if runs < 1 or not 1 <= missed <= of:
|
|
74
|
+
return None
|
|
75
|
+
return {"runs": runs, "missed": missed, "of": of}
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def lasting(health: Mapping[str, object]) -> bool:
|
|
79
|
+
"""Whether a source's runs reported missing items DEGRADED times in a row: one alert, not one per lost feed."""
|
|
80
|
+
degraded = health.get("degraded")
|
|
81
|
+
return isinstance(degraded, Mapping) and int(cast("int", degraded["runs"])) >= DEGRADED
|
|
82
|
+
|
|
83
|
+
|
|
69
84
|
def source_health(
|
|
70
85
|
store: Store, names: Iterable[str] = (), *, now: datetime | None = None, config: Config | None = None
|
|
71
86
|
) -> dict[str, dict[str, object]]:
|
|
@@ -119,6 +134,9 @@ def source_health(
|
|
|
119
134
|
item["failed"] = True
|
|
120
135
|
if _silent(settings, success, changed.get(name, ""), now):
|
|
121
136
|
item["silent"] = True
|
|
137
|
+
# The records may lack what the missed parts hold, whatever the sensor's state now.
|
|
138
|
+
if degraded := degradation(entry):
|
|
139
|
+
item["degraded"] = degraded
|
|
122
140
|
result[name] = item
|
|
123
141
|
return result
|
|
124
142
|
|
|
@@ -309,14 +327,33 @@ def assistant_health(
|
|
|
309
327
|
return result
|
|
310
328
|
|
|
311
329
|
|
|
330
|
+
def is_late(settings: Program | Assistant, health: Mapping[str, object], now: datetime) -> bool:
|
|
331
|
+
"""Whether a scheduled program is `overdue`, or has `never` succeeded and is due now by the dispatcher's rule.
|
|
332
|
+
|
|
333
|
+
A scheduled sensor or routine without a success is due at once. An assistant is late once one of its `never`
|
|
334
|
+
schedules falls due: a weekday `at` schedule declared on Sunday waits for Monday's slot. No grace period applies,
|
|
335
|
+
so a schedule that does not run shows from its slot.
|
|
336
|
+
"""
|
|
337
|
+
if health["freshness"] != "never" or not isinstance(settings, Assistant):
|
|
338
|
+
return health["freshness"] in {"overdue", "never"}
|
|
339
|
+
schedules = health.get("schedules")
|
|
340
|
+
return isinstance(schedules, Mapping) and any(
|
|
341
|
+
isinstance(item := schedules.get(name), Mapping)
|
|
342
|
+
and item.get("freshness") == "never"
|
|
343
|
+
and spec.next_due(now) <= now
|
|
344
|
+
for name, spec in settings.schedules.items()
|
|
345
|
+
)
|
|
346
|
+
|
|
347
|
+
|
|
312
348
|
def _attention(
|
|
313
349
|
config: Config,
|
|
314
350
|
sources: dict[str, dict[str, object]],
|
|
315
351
|
routines: dict[str, dict[str, object]],
|
|
316
352
|
assistants: dict[str, dict[str, object]],
|
|
353
|
+
now: datetime,
|
|
317
354
|
) -> list[dict[str, object]]:
|
|
318
|
-
"""Scheduled programs this machine runs that failed,
|
|
319
|
-
assistants with failed work however it was asked."""
|
|
355
|
+
"""Scheduled programs this machine runs that failed, are late or, for a source, fell silent or reported missing
|
|
356
|
+
items DEGRADED runs in a row, and assistants with failed work however it was asked."""
|
|
320
357
|
result: list[dict[str, object]] = []
|
|
321
358
|
for kind, healths, programs in (
|
|
322
359
|
("sensor", {name: health for name, health in sources.items() if name not in config.assistants}, config.sensors),
|
|
@@ -325,7 +362,7 @@ def _attention(
|
|
|
325
362
|
):
|
|
326
363
|
for name, health in healths.items():
|
|
327
364
|
settings, failed = programs.get(name), health.get("failed")
|
|
328
|
-
silent = health.get("silent")
|
|
365
|
+
silent, degraded = health.get("silent"), lasting(health)
|
|
329
366
|
if (
|
|
330
367
|
settings
|
|
331
368
|
and settings.enabled
|
|
@@ -335,7 +372,7 @@ def _attention(
|
|
|
335
372
|
if isinstance(settings, Assistant)
|
|
336
373
|
else settings.refresh
|
|
337
374
|
)
|
|
338
|
-
and (failed or silent or health
|
|
375
|
+
and (failed or silent or degraded or is_late(settings, health, now))
|
|
339
376
|
):
|
|
340
377
|
result.append(
|
|
341
378
|
{
|
|
@@ -343,6 +380,7 @@ def _attention(
|
|
|
343
380
|
"freshness": health["freshness"],
|
|
344
381
|
**({"failed": True} if failed else {}),
|
|
345
382
|
**({"silent": True} if silent else {}),
|
|
383
|
+
**({"degraded": True} if degraded else {}),
|
|
346
384
|
}
|
|
347
385
|
)
|
|
348
386
|
return result
|
|
@@ -351,8 +389,8 @@ def _attention(
|
|
|
351
389
|
def attention(
|
|
352
390
|
store: Store, now: datetime | None = None, counts: Mapping[str, Mapping[str, object]] | None = None
|
|
353
391
|
) -> list[dict[str, object]]:
|
|
354
|
-
"""Scheduled sensors, routines and assistants this machine runs that failed, are late
|
|
355
|
-
assistants with failed work.
|
|
392
|
+
"""Scheduled sensors, routines and assistants this machine runs that failed, are late, fell silent or keep
|
|
393
|
+
reporting missing items, and assistants with failed work.
|
|
356
394
|
|
|
357
395
|
`counts` are the indexed counts per source, as `index.sources` gives them, from a caller holding the cache open:
|
|
358
396
|
opening it again would wait behind a publish that waits for that caller.
|
|
@@ -371,6 +409,7 @@ def attention(
|
|
|
371
409
|
source_health(store, counts, now=now, config=config),
|
|
372
410
|
routine_health(store, now=now, config=config),
|
|
373
411
|
assistant_health(store, now=now, config=config),
|
|
412
|
+
now,
|
|
374
413
|
)
|
|
375
414
|
|
|
376
415
|
|
|
@@ -475,7 +514,7 @@ def report(stores: list[Store], now: datetime | None = None) -> dict[str, object
|
|
|
475
514
|
)
|
|
476
515
|
# The reasons a brain is unhealthy, beside its problems: the home page's late or failed programs, then
|
|
477
516
|
# unresolved assistant work and failing channels.
|
|
478
|
-
alerts = _attention(config, coverage, routines, assistants)
|
|
517
|
+
alerts = _attention(config, coverage, routines, assistants, now)
|
|
479
518
|
named = {entry.get("assistant") for entry in alerts}
|
|
480
519
|
alerts += [
|
|
481
520
|
{"assistant": name, "freshness": str(assistants.get(name, {}).get("freshness", "unknown")), "failed": True}
|