brain-framework 30.0.0__tar.gz → 31.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-30.0.0 → brain_framework-31.0.0}/PKG-INFO +9 -9
- {brain_framework-30.0.0 → brain_framework-31.0.0}/README.md +8 -8
- {brain_framework-30.0.0 → brain_framework-31.0.0}/pyproject.toml +1 -1
- {brain_framework-30.0.0 → brain_framework-31.0.0}/pyproject.toml.orig +1 -1
- {brain_framework-30.0.0 → brain_framework-31.0.0}/src/bf/__init__.py +1 -1
- {brain_framework-30.0.0 → brain_framework-31.0.0}/src/bf/cli.py +218 -115
- {brain_framework-30.0.0 → brain_framework-31.0.0}/src/bf/config.py +36 -35
- brain_framework-31.0.0/src/bf/engine.py +693 -0
- {brain_framework-30.0.0 → brain_framework-31.0.0}/src/bf/guides/authoring.md +10 -10
- {brain_framework-30.0.0 → brain_framework-31.0.0}/src/bf/guides/getting-started.md +2 -2
- {brain_framework-30.0.0 → brain_framework-31.0.0}/src/bf/guides/index.md +5 -5
- brain_framework-31.0.0/src/bf/guides/operations.md +86 -0
- brain_framework-31.0.0/src/bf/guides/reference.md +62 -0
- brain_framework-31.0.0/src/bf/guides/retrieval.md +55 -0
- brain_framework-31.0.0/src/bf/index.py +384 -0
- {brain_framework-30.0.0 → brain_framework-31.0.0}/src/bf/loops.py +116 -71
- {brain_framework-30.0.0 → brain_framework-31.0.0}/src/bf/markdown.py +52 -28
- {brain_framework-30.0.0 → brain_framework-31.0.0}/src/bf/mcp.py +29 -20
- {brain_framework-30.0.0 → brain_framework-31.0.0}/src/bf/models.py +8 -6
- {brain_framework-30.0.0 → brain_framework-31.0.0}/src/bf/query.py +126 -56
- {brain_framework-30.0.0 → brain_framework-31.0.0}/src/bf/records.py +0 -2
- brain_framework-31.0.0/src/bf/schemas.py +363 -0
- {brain_framework-30.0.0 → brain_framework-31.0.0}/src/bf/skills/bf/SKILL.md +12 -12
- {brain_framework-30.0.0 → brain_framework-31.0.0}/src/bf/starter/AGENTS.md +2 -2
- {brain_framework-30.0.0 → brain_framework-31.0.0}/src/bf/starter/concepts/welcome.md +1 -1
- {brain_framework-30.0.0 → brain_framework-31.0.0}/src/bf/starter/evals/smoke.yaml +1 -1
- {brain_framework-30.0.0 → brain_framework-31.0.0}/src/bf/starter/gitignore +3 -2
- {brain_framework-30.0.0 → brain_framework-31.0.0}/src/bf/storage.py +128 -34
- {brain_framework-30.0.0 → brain_framework-31.0.0}/src/bf/watch.py +58 -25
- brain_framework-30.0.0/src/bf/engine.py +0 -642
- brain_framework-30.0.0/src/bf/guides/operations.md +0 -78
- brain_framework-30.0.0/src/bf/guides/reference.md +0 -63
- brain_framework-30.0.0/src/bf/guides/retrieval.md +0 -53
- brain_framework-30.0.0/src/bf/schemas.py +0 -324
- {brain_framework-30.0.0 → brain_framework-31.0.0}/LICENSE +0 -0
- {brain_framework-30.0.0 → brain_framework-31.0.0}/THIRD_PARTY_NOTICES.md +0 -0
- {brain_framework-30.0.0 → brain_framework-31.0.0}/src/bf/__main__.py +0 -0
- {brain_framework-30.0.0 → brain_framework-31.0.0}/src/bf/proc.py +1 -1
- {brain_framework-30.0.0 → brain_framework-31.0.0}/src/bf/py.typed +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: brain-framework
|
|
3
|
-
Version:
|
|
3
|
+
Version: 31.0.0
|
|
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 unified loops, 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
|
|
@@ -42,9 +42,9 @@ Description-Content-Type: text/markdown
|
|
|
42
42
|
|
|
43
43
|
Brain Framework (`bf`) turns a flat folder of human-authored Markdown notes and collected JSON records into a schema-validated, pure-JSON knowledge store (`memories/**/*.json`) that humans and AI agents query offline with `rg` and `jq` (`bf query`, `bf read`, or `bf mcp`).
|
|
44
44
|
|
|
45
|
-
- **Three formats, one job each.** **YAML for config** (`bf.yaml` `version:
|
|
46
|
-
- **Agents always query JSON — with minimal tokens.** `bf build` compiles Markdown notes, headings, keyed `attr_list` metadata (`
|
|
47
|
-
- **Unified strange-loop orchestration (`loops:`).** Around
|
|
45
|
+
- **Three formats, one job each.** **YAML for config** (`bf.yaml` `version: 16`, `evals/*.yaml` `version: 1`, note frontmatter), **JSON for records** (`memories/**/*.json`, validated by package-owned core schemas and optional user `schemas/*.json` by convention, plus plain JSON lines in `logs/*.log`), and **Markdown for humans** (`projects/`, `concepts/`, and `actions/` parsed with [Python-Markdown](https://python-markdown.github.io/) `attr_list` metadata, plus plain Markdown inputs under `prompts/`).
|
|
46
|
+
- **Agents always query JSON — with minimal tokens.** `bf build` compiles Markdown notes, headings, keyed `attr_list` metadata (`anchors`), links, and open tasks into `memories/{concepts,projects,actions}/*.json` and updates per-source `.bf/cache/index/` shards without scanning sensor corpora. `bf read` (`--outline`, `--lines`, `--fields`, `--max-bytes`), `bf query` (`rg` + `--jq`, `--format jsonl|tsv`), `bf review`, and `bf status` keep outputs bounded and fast.
|
|
47
|
+
- **Unified strange-loop orchestration (`loops:`).** Around 6,000 lines of Python with lazy imports, delegating retrieval to `rg` and `jq`, cross-references to relative Markdown paths, `source:id`, and `bf://` URLs, and every sensor, routine, git hook, continuous listener (`on: daemon`), and autonomous thinking bot to one `loops:` primitive in `bf.yaml` — with bounded concurrent execution under `bf watch` and zero custom databases, built-in LLMs, or provider SDKs.
|
|
48
48
|
|
|
49
49
|
[](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)
|
|
50
50
|
|
|
@@ -58,7 +58,7 @@ bf init ~/brain
|
|
|
58
58
|
cd ~/brain
|
|
59
59
|
bf check
|
|
60
60
|
bf review
|
|
61
|
-
bf query --jq '{ref, title,
|
|
61
|
+
bf query --jq '{ref, title, anchors}'
|
|
62
62
|
```
|
|
63
63
|
|
|
64
64
|
Explore the [four-tool walkthrough](https://github.com/fmind/brain-framework/blob/main/examples/context-hub/README.md) (Workspace, Jira, GitHub, and Google Cloud fixtures) or read [Getting started](https://fmind.github.io/brain-framework/getting-started/).
|
|
@@ -74,14 +74,14 @@ Explore the [four-tool walkthrough](https://github.com/fmind/brain-framework/blo
|
|
|
74
74
|
</a>
|
|
75
75
|
|
|
76
76
|
- **Notes, `attr_list`, & unified links ([Authoring](https://fmind.github.io/brain-framework/authoring/)):** Separate volatile TODOs (`projects/`), durable knowledge (`concepts/`), and dated workspaces (`actions/*/ACTION.md`), scaffold with `bf new`, attach metadata on headings (`## MCP {#mcp creator=Anthropic}`) and blocks (`{: #summary confidence=high}`), and cross-reference notes, records (`source:id`), or sibling brains (`bf://`).
|
|
77
|
-
- **Unified `loops:`, schemas, & concurrent `bf watch` ([Operations](https://fmind.github.io/brain-framework/operations/)):** Ship user-owned JSON Schemas in `schemas/`, copy stdlib sensors from [examples/sensors](https://github.com/fmind/brain-framework/tree/main/examples/sensors), and orchestrate multi-schedule, event-triggered, git-hook, `emit:
|
|
77
|
+
- **Unified `loops:`, schemas, & concurrent `bf watch` ([Operations](https://fmind.github.io/brain-framework/operations/)):** Ship user-owned JSON Schemas in `schemas/`, copy stdlib sensors from [examples/sensors](https://github.com/fmind/brain-framework/tree/main/examples/sensors), and orchestrate multi-schedule, event-triggered, git-hook, `emit: <kind>`, and `on: daemon` loops under `bf.yaml` (`loops:`, `watch.concurrency`) with a live Rich TUI.
|
|
78
78
|
- **Standard JSON retrieval & MCP ([Retrieval](https://fmind.github.io/brain-framework/retrieval/)):** Resolve `bf://` URLs, `#anchor` sections, `--outline`, or `--lines` with `bf read`, search and filter `memories/**/*.json` via `bf query` (`rg`, `jq`, or `rg` + `--jq`), verify in one shot with `bf check`, or expose strictly read-only tools via `bf mcp`.
|
|
79
|
-
- **Integrity, freshness, & schemas ([Reference](https://fmind.github.io/brain-framework/reference/)):** `bf
|
|
79
|
+
- **Integrity, freshness, & schemas ([Reference](https://fmind.github.io/brain-framework/reference/)):** `bf check` compiles notes, validates every schema, compiled-note sync, link, `#anchor`, and cross-brain `bf://` reference with digest caching, and runs deterministic evals (`--validate` or `--eval [TARGET]`); `bf review` surfaces `newer_evidence`, overdue `stale_after` notes, and open `draft` actions; `bf schema` prints bundled Draft 2020-12 JSON Schemas.
|
|
80
80
|
|
|
81
81
|
## Good to know
|
|
82
82
|
|
|
83
83
|
1. **Local-first and private.** Zero global config (`--brain` -> `BF_BRAIN` -> enclosing `bf.yaml` -> `DEFAULT_BRAIN_PATH`), `O_NOFOLLOW` path confinement, and private `0700` `.bf/` and `logs/` ([Operations](https://fmind.github.io/brain-framework/operations/)).
|
|
84
84
|
2. **Harnesses reason; BF verifies.** Coding agents load the single `/bf` [Agent Skill](https://agentskills.io/specification) from `.agents/skills/bf`, track work via `bf new action <slug>`, emit loop events via `bf emit`, and run `bf check` ([Example brain](https://github.com/fmind/brain-framework/blob/main/examples/brain/README.md)).
|
|
85
|
-
3. **Git-native collaboration.** Track notes, `bf.yaml`, `evals/`, and `schemas/` in Git while ignoring compiled note JSON files, `logs/`, `actions/`, and `.bf/`.
|
|
85
|
+
3. **Git-native collaboration.** Track notes, `actions/*/ACTION.md`, `bf.yaml`, `evals/`, and `schemas/` in Git while ignoring compiled note JSON files, `logs/`, `actions/*/{inputs,outputs}/`, and `.bf/`.
|
|
86
86
|
|
|
87
|
-
[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) · [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)
|
|
87
|
+
[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)
|
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
|
|
9
9
|
Brain Framework (`bf`) turns a flat folder of human-authored Markdown notes and collected JSON records into a schema-validated, pure-JSON knowledge store (`memories/**/*.json`) that humans and AI agents query offline with `rg` and `jq` (`bf query`, `bf read`, or `bf mcp`).
|
|
10
10
|
|
|
11
|
-
- **Three formats, one job each.** **YAML for config** (`bf.yaml` `version:
|
|
12
|
-
- **Agents always query JSON — with minimal tokens.** `bf build` compiles Markdown notes, headings, keyed `attr_list` metadata (`
|
|
13
|
-
- **Unified strange-loop orchestration (`loops:`).** Around
|
|
11
|
+
- **Three formats, one job each.** **YAML for config** (`bf.yaml` `version: 16`, `evals/*.yaml` `version: 1`, note frontmatter), **JSON for records** (`memories/**/*.json`, validated by package-owned core schemas and optional user `schemas/*.json` by convention, plus plain JSON lines in `logs/*.log`), and **Markdown for humans** (`projects/`, `concepts/`, and `actions/` parsed with [Python-Markdown](https://python-markdown.github.io/) `attr_list` metadata, plus plain Markdown inputs under `prompts/`).
|
|
12
|
+
- **Agents always query JSON — with minimal tokens.** `bf build` compiles Markdown notes, headings, keyed `attr_list` metadata (`anchors`), links, and open tasks into `memories/{concepts,projects,actions}/*.json` and updates per-source `.bf/cache/index/` shards without scanning sensor corpora. `bf read` (`--outline`, `--lines`, `--fields`, `--max-bytes`), `bf query` (`rg` + `--jq`, `--format jsonl|tsv`), `bf review`, and `bf status` keep outputs bounded and fast.
|
|
13
|
+
- **Unified strange-loop orchestration (`loops:`).** Around 6,000 lines of Python with lazy imports, delegating retrieval to `rg` and `jq`, cross-references to relative Markdown paths, `source:id`, and `bf://` URLs, and every sensor, routine, git hook, continuous listener (`on: daemon`), and autonomous thinking bot to one `loops:` primitive in `bf.yaml` — with bounded concurrent execution under `bf watch` and zero custom databases, built-in LLMs, or provider SDKs.
|
|
14
14
|
|
|
15
15
|
[](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)
|
|
16
16
|
|
|
@@ -24,7 +24,7 @@ bf init ~/brain
|
|
|
24
24
|
cd ~/brain
|
|
25
25
|
bf check
|
|
26
26
|
bf review
|
|
27
|
-
bf query --jq '{ref, title,
|
|
27
|
+
bf query --jq '{ref, title, anchors}'
|
|
28
28
|
```
|
|
29
29
|
|
|
30
30
|
Explore the [four-tool walkthrough](https://github.com/fmind/brain-framework/blob/main/examples/context-hub/README.md) (Workspace, Jira, GitHub, and Google Cloud fixtures) or read [Getting started](https://fmind.github.io/brain-framework/getting-started/).
|
|
@@ -40,14 +40,14 @@ Explore the [four-tool walkthrough](https://github.com/fmind/brain-framework/blo
|
|
|
40
40
|
</a>
|
|
41
41
|
|
|
42
42
|
- **Notes, `attr_list`, & unified links ([Authoring](https://fmind.github.io/brain-framework/authoring/)):** Separate volatile TODOs (`projects/`), durable knowledge (`concepts/`), and dated workspaces (`actions/*/ACTION.md`), scaffold with `bf new`, attach metadata on headings (`## MCP {#mcp creator=Anthropic}`) and blocks (`{: #summary confidence=high}`), and cross-reference notes, records (`source:id`), or sibling brains (`bf://`).
|
|
43
|
-
- **Unified `loops:`, schemas, & concurrent `bf watch` ([Operations](https://fmind.github.io/brain-framework/operations/)):** Ship user-owned JSON Schemas in `schemas/`, copy stdlib sensors from [examples/sensors](https://github.com/fmind/brain-framework/tree/main/examples/sensors), and orchestrate multi-schedule, event-triggered, git-hook, `emit:
|
|
43
|
+
- **Unified `loops:`, schemas, & concurrent `bf watch` ([Operations](https://fmind.github.io/brain-framework/operations/)):** Ship user-owned JSON Schemas in `schemas/`, copy stdlib sensors from [examples/sensors](https://github.com/fmind/brain-framework/tree/main/examples/sensors), and orchestrate multi-schedule, event-triggered, git-hook, `emit: <kind>`, and `on: daemon` loops under `bf.yaml` (`loops:`, `watch.concurrency`) with a live Rich TUI.
|
|
44
44
|
- **Standard JSON retrieval & MCP ([Retrieval](https://fmind.github.io/brain-framework/retrieval/)):** Resolve `bf://` URLs, `#anchor` sections, `--outline`, or `--lines` with `bf read`, search and filter `memories/**/*.json` via `bf query` (`rg`, `jq`, or `rg` + `--jq`), verify in one shot with `bf check`, or expose strictly read-only tools via `bf mcp`.
|
|
45
|
-
- **Integrity, freshness, & schemas ([Reference](https://fmind.github.io/brain-framework/reference/)):** `bf
|
|
45
|
+
- **Integrity, freshness, & schemas ([Reference](https://fmind.github.io/brain-framework/reference/)):** `bf check` compiles notes, validates every schema, compiled-note sync, link, `#anchor`, and cross-brain `bf://` reference with digest caching, and runs deterministic evals (`--validate` or `--eval [TARGET]`); `bf review` surfaces `newer_evidence`, overdue `stale_after` notes, and open `draft` actions; `bf schema` prints bundled Draft 2020-12 JSON Schemas.
|
|
46
46
|
|
|
47
47
|
## Good to know
|
|
48
48
|
|
|
49
49
|
1. **Local-first and private.** Zero global config (`--brain` -> `BF_BRAIN` -> enclosing `bf.yaml` -> `DEFAULT_BRAIN_PATH`), `O_NOFOLLOW` path confinement, and private `0700` `.bf/` and `logs/` ([Operations](https://fmind.github.io/brain-framework/operations/)).
|
|
50
50
|
2. **Harnesses reason; BF verifies.** Coding agents load the single `/bf` [Agent Skill](https://agentskills.io/specification) from `.agents/skills/bf`, track work via `bf new action <slug>`, emit loop events via `bf emit`, and run `bf check` ([Example brain](https://github.com/fmind/brain-framework/blob/main/examples/brain/README.md)).
|
|
51
|
-
3. **Git-native collaboration.** Track notes, `bf.yaml`, `evals/`, and `schemas/` in Git while ignoring compiled note JSON files, `logs/`, `actions/`, and `.bf/`.
|
|
51
|
+
3. **Git-native collaboration.** Track notes, `actions/*/ACTION.md`, `bf.yaml`, `evals/`, and `schemas/` in Git while ignoring compiled note JSON files, `logs/`, `actions/*/{inputs,outputs}/`, and `.bf/`.
|
|
52
52
|
|
|
53
|
-
[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) · [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)
|
|
53
|
+
[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 = "31.0.0"
|
|
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 unified loops, 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 = "
|
|
4
|
+
version = "31.0.0"
|
|
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 unified loops, and queries offline with rg and jq."
|
|
6
6
|
readme = "README.md"
|
|
7
7
|
requires-python = ">=3.14"
|
|
@@ -48,16 +48,18 @@ def _build_parser() -> _Parser:
|
|
|
48
48
|
sp = cmd("init", "Initialize a new brain directory.", with_brain=False)
|
|
49
49
|
sp.add_argument("path", type=Path, help="Target directory (new or empty).")
|
|
50
50
|
sp.add_argument("--name", default=None, help="Brain identifier (lowercase letters, digits, hyphens).")
|
|
51
|
+
sp.add_argument("--description", default="", help="Short brain description written to bf.yaml.")
|
|
52
|
+
|
|
51
53
|
sp = cmd("build", "Compile OKF Markdown notes into memories/**/*.json.")
|
|
52
54
|
sp.add_argument("--force", action="store_true", help="Recompile every note, ignoring incremental cache.")
|
|
55
|
+
|
|
53
56
|
sp = cmd("ingest", "Validate and save JSON records into memories/<source>/.")
|
|
54
57
|
sp.add_argument("source", help="Sensor source name (lowercase letters, digits, hyphens).")
|
|
55
58
|
sp.add_argument("--input", default="-", metavar="FILE", help="Input JSON/JSONL file path or '-' for stdin.")
|
|
56
59
|
sp.add_argument("--mode", choices=("upsert", "snapshot"), default="upsert", help="Write mode (default: upsert).")
|
|
57
|
-
sp.add_argument(
|
|
58
|
-
"--allow-removal", action="store_true", help="Allow snapshot to empty or drop >50%% of 10+ records."
|
|
59
|
-
)
|
|
60
|
+
sp.add_argument("--allow-removal", action="store_true", help="Allow snapshot to empty/drop >50%% of 10+ records.")
|
|
60
61
|
sp.add_argument("--dry-run", action="store_true", help="Validate and preview counts without writing files.")
|
|
62
|
+
|
|
61
63
|
sp = cmd("read", "Read an OKF note, #anchor section, source:id record, or bf:// URI.")
|
|
62
64
|
sp.add_argument("target", help="Note path, note#anchor, source:id, memory path, alias, or bf:// URI.")
|
|
63
65
|
grp = sp.add_mutually_exclusive_group()
|
|
@@ -67,55 +69,65 @@ def _build_parser() -> _Parser:
|
|
|
67
69
|
grp.add_argument("--full", action="store_true", help="Return full compiled JSON record.")
|
|
68
70
|
sp.add_argument("--fields", default=None, metavar="F,...", help="Comma-separated top-level fields to return.")
|
|
69
71
|
sp.add_argument("--max-bytes", type=int, default=None, metavar="N", help="Maximum UTF-8 JSON response size.")
|
|
72
|
+
|
|
70
73
|
sp = cmd("query", "Search and filter memories/**/*.json via rg and jq.")
|
|
71
74
|
sp.add_argument("pattern", nargs="?", default=None, help="ripgrep regex pattern (optional with --jq or filters).")
|
|
72
75
|
sp.add_argument("--jq", default=None, metavar="EXPR", help="Isolated jq filter expression.")
|
|
73
76
|
sp.add_argument("--kind", choices=("note", "memory"), default="", help="Filter by record kind.")
|
|
74
77
|
sp.add_argument("-s", "--scope", default="", metavar="PATH", help="Restrict to a note, source, or memories/ path.")
|
|
75
|
-
sp.add_argument("--source", default="", metavar="NAME", help="Restrict to one source directory.")
|
|
76
78
|
sp.add_argument("--fields", default=None, metavar="F,...", help="Comma-separated item fields to project.")
|
|
77
79
|
sp.add_argument("-n", "--limit", type=int, default=20, metavar="N", help="Max results (1..5000, default: 20).")
|
|
78
80
|
sp.add_argument("--format", choices=("json", "jsonl", "tsv"), default="json", help="Output format (default: json).")
|
|
79
|
-
|
|
80
|
-
sp.add_argument("--limit", type=int, default=50, metavar="N", help="Max problems returned (default: 50).")
|
|
81
|
-
sp.add_argument("--all", dest="all_problems", action="store_true", help="Return all problems without truncation.")
|
|
82
|
-
sp.add_argument("--strict", action="store_true", help="Fail on snapshot/forgotten link warnings.")
|
|
83
|
-
sp.add_argument("--force", action="store_true", help="Bypass cached validation digests.")
|
|
81
|
+
|
|
84
82
|
sp = cmd("review", "Review stale notes, newer linked evidence, draft actions, and open tasks.")
|
|
85
|
-
sp.add_argument("--limit", type=int, default=20, metavar="N", help="Max stale/action items (default: 20).")
|
|
83
|
+
sp.add_argument("-n", "--limit", type=int, default=20, metavar="N", help="Max stale/action items (default: 20).")
|
|
86
84
|
sp.add_argument("--all", dest="all_items", action="store_true", help="Return all stale notes and open actions.")
|
|
87
85
|
sp.add_argument("--fields", default=None, metavar="F,...", help="Comma-separated item fields to project.")
|
|
88
86
|
sp.add_argument("--format", choices=("json", "jsonl", "tsv"), default="json", help="Output format (default: json).")
|
|
89
|
-
|
|
90
|
-
sp
|
|
91
|
-
sp
|
|
92
|
-
|
|
87
|
+
|
|
88
|
+
sp = cmd("check", "Run incremental build, schema/link validation, and deterministic evals.")
|
|
89
|
+
sp.add_argument("target", nargs="?", default=None, help="Optional eval filename or stem.")
|
|
90
|
+
cgrp = sp.add_mutually_exclusive_group()
|
|
91
|
+
cgrp.add_argument("--validate", dest="validate_only", action="store_true", help="Validate only (read-only).")
|
|
92
|
+
cgrp.add_argument("--eval", dest="eval_only", action="store_true", help="Run eval suites only.")
|
|
93
|
+
sp.add_argument("-n", "--limit", type=int, default=None, metavar="N", help="Max validation problems (default: 50).")
|
|
94
|
+
sp.add_argument("--all", dest="all_problems", action="store_true", help="Return all problems without truncation.")
|
|
95
|
+
sp.add_argument("--strict", action="store_true", help="Fail validation on warnings (snapshot, forgotten, skill).")
|
|
93
96
|
sp.add_argument("--force", action="store_true", help="Recompile every note and bypass validation cache.")
|
|
97
|
+
|
|
94
98
|
sp = cmd("new", "Scaffold a new OKF Markdown note and compile it.")
|
|
95
99
|
sp.add_argument("kind", choices=("concept", "project", "action"), help="Note category.")
|
|
96
100
|
sp.add_argument("slug", help="Lowercase hyphenated filename slug.")
|
|
97
101
|
sp.add_argument("--title", default="", help="Note H1 title (defaults to title-cased slug).")
|
|
98
102
|
sp.add_argument("--type", dest="note_type", default="", help="Frontmatter type (default: guide/project/action).")
|
|
99
103
|
sp.add_argument("--status", default="", help="Frontmatter status (default: draft for action, else stable).")
|
|
104
|
+
|
|
100
105
|
sp = cmd("schema", "Print bundled Draft 2020-12 JSON Schemas.", with_brain=False)
|
|
101
106
|
sp.add_argument("name", nargs="?", default=None, help="Schema name: bf, record, concepts, or evals.")
|
|
107
|
+
|
|
102
108
|
sp = cmd("run", "Execute named, due, or Git-hook loops from bf.yaml (use '-- ARGS...' to pass arguments).")
|
|
103
|
-
sp.add_argument("loops", nargs="*", help="Cycle loop names to run sequentially.")
|
|
109
|
+
sp.add_argument("loops", nargs="*", help="Cycle loop names to run sequentially (or reset with --reset).")
|
|
104
110
|
rgrp = sp.add_mutually_exclusive_group()
|
|
105
111
|
rgrp.add_argument("--due", action="store_true", help="Rebuild notes and run scheduled/event-triggered loops.")
|
|
106
112
|
rgrp.add_argument("--hook", choices=("pre-commit", "pre-push"), default="", help="Run loops for a Git hook.")
|
|
113
|
+
rgrp.add_argument("--reset", action="store_true", help="Reset .bf/<loop>.json state for named loops to idle.")
|
|
107
114
|
sp.add_argument("--dry-run", action="store_true", help="Validate triggers and preview loops without executing.")
|
|
115
|
+
|
|
108
116
|
sp = cmd("emit", "Append a custom event to .bf/events.jsonl and logs/events.log.")
|
|
109
117
|
sp.add_argument("kind", help="Event kind identifier (e.g. task.ready).")
|
|
110
118
|
sp.add_argument("--source", default="bf", help="Event source name (default: bf).")
|
|
111
119
|
sp.add_argument("--data", default="", metavar="JSON", help="Optional JSON object payload.")
|
|
112
120
|
sp.add_argument("--dedupe", action="store_true", help="Deduplicate on kind, source, and data.id.")
|
|
121
|
+
|
|
113
122
|
sp = cmd("status", "Inspect brain counts, failing loop attention, and orphaned states.")
|
|
114
123
|
sp.add_argument("--all", dest="all_units", action="store_true", help="Include full per-loop status map.")
|
|
115
124
|
sp.add_argument("--fields", default=None, metavar="F,...", help="Comma-separated top-level fields to return.")
|
|
116
125
|
sp.add_argument("--check", action="store_true", help="Verify requires: commands and exit 1 on any problem.")
|
|
126
|
+
sp.add_argument("--prune", action="store_true", help="Remove orphaned .bf/ state files and stale cache shards.")
|
|
127
|
+
|
|
117
128
|
sp = cmd("watch", "Supervise daemon loops, file rebuilds, and concurrent cycle loops.")
|
|
118
129
|
sp.add_argument("--json", dest="json_stream", action="store_true", help="Stream watch.tick JSON lines (no TUI).")
|
|
130
|
+
|
|
119
131
|
cmd("mcp", "Run the read-only stdio MCP server.")
|
|
120
132
|
return p
|
|
121
133
|
|
|
@@ -124,10 +136,10 @@ def _split_run(items: list[str]) -> tuple[list[str], list[str]]:
|
|
|
124
136
|
if "--" in items:
|
|
125
137
|
sep, idx = items.index("--"), 0
|
|
126
138
|
while idx < sep:
|
|
127
|
-
if (
|
|
128
|
-
idx += 2 if
|
|
139
|
+
if (tok := items[idx]) == "--brain" or tok.startswith("-"):
|
|
140
|
+
idx += 2 if tok == "--brain" else 1
|
|
129
141
|
continue
|
|
130
|
-
return (items[:sep], items[sep + 1 :]) if
|
|
142
|
+
return (items[:sep], items[sep + 1 :]) if tok == "run" else (items, [])
|
|
131
143
|
return items, []
|
|
132
144
|
|
|
133
145
|
|
|
@@ -138,8 +150,8 @@ def _read_in(spec: str) -> bytes:
|
|
|
138
150
|
else:
|
|
139
151
|
with expand(Path(spec)).open("rb") as fh:
|
|
140
152
|
data = fh.read(MAX_BATCH + 1)
|
|
141
|
-
except OSError as
|
|
142
|
-
raise Error(f"cannot read input file{f' ({
|
|
153
|
+
except OSError as err:
|
|
154
|
+
raise Error(f"cannot read input file{f' ({err.strerror})' if err.strerror else ''}") from err
|
|
143
155
|
if len(data) > MAX_BATCH:
|
|
144
156
|
raise Error(f"input exceeds {MAX_BATCH} bytes; split the batch")
|
|
145
157
|
return data
|
|
@@ -158,11 +170,9 @@ def _emit_fmt(res: dict[str, Any], fmt: str, fields: str | None, *, review: bool
|
|
|
158
170
|
tag = review and (not raw_c or "section" in raw_c)
|
|
159
171
|
rows = (
|
|
160
172
|
[
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
for r in res[k]
|
|
165
|
-
)
|
|
173
|
+
{"section": sec, **row} if tag else row
|
|
174
|
+
for sec, key in (("stale", "stale"), ("action_open", "actions_open"))
|
|
175
|
+
for row in res[key]
|
|
166
176
|
]
|
|
167
177
|
if review
|
|
168
178
|
else res["items"]
|
|
@@ -173,13 +183,13 @@ def _emit_fmt(res: dict[str, Any], fmt: str, fields: str | None, *, review: bool
|
|
|
173
183
|
elif rows:
|
|
174
184
|
cols = raw_c or list(dict.fromkeys(k for r in rows if isinstance(r, dict) for k in r))
|
|
175
185
|
|
|
176
|
-
def cell(
|
|
177
|
-
|
|
178
|
-
json.dumps(
|
|
179
|
-
|
|
180
|
-
|
|
186
|
+
def cell(val: object) -> str:
|
|
187
|
+
raw = (
|
|
188
|
+
json.dumps(val, ensure_ascii=False, separators=(",", ":")) if isinstance(val, (dict, list)) else val
|
|
189
|
+
)
|
|
190
|
+
return printable(
|
|
191
|
+
("" if raw is None else str(raw)).replace("\t", " ").replace("\r", " ").replace("\n", " ")
|
|
181
192
|
)
|
|
182
|
-
return printable(s.replace("\t", " ").replace("\r", " ").replace("\n", " "))
|
|
183
193
|
|
|
184
194
|
lines = ["\t".join(cell(r.get(k)) for k in cols) if isinstance(r, dict) else cell(r) for r in rows]
|
|
185
195
|
sys.stdout.buffer.write(("\n".join(lines) + "\n").encode())
|
|
@@ -187,101 +197,194 @@ def _emit_fmt(res: dict[str, Any], fmt: str, fields: str | None, *, review: bool
|
|
|
187
197
|
return None
|
|
188
198
|
|
|
189
199
|
|
|
190
|
-
def
|
|
191
|
-
|
|
200
|
+
def _resolve_brain_arg(args: argparse.Namespace) -> str:
|
|
201
|
+
cmd = args.command
|
|
202
|
+
root_vals = getattr(args, "root_brain", None) or []
|
|
203
|
+
sub_vals = getattr(args, "brain", None) or []
|
|
204
|
+
if cmd in {"init", "schema"} and root_vals:
|
|
205
|
+
raise InputError(f"bf {cmd} does not accept --brain")
|
|
206
|
+
vals = [*root_vals, *sub_vals]
|
|
207
|
+
if any(not v.strip() for v in vals):
|
|
208
|
+
raise InputError("--brain must be nonempty")
|
|
209
|
+
if len(set(vals)) > 1:
|
|
210
|
+
raise InputError("conflicting --brain values")
|
|
211
|
+
return vals[0] if vals else ""
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
def _dispatch(args: argparse.Namespace, extra: list[str]) -> int:
|
|
215
|
+
cmd = args.command
|
|
216
|
+
brain_arg = _resolve_brain_arg(args)
|
|
217
|
+
if cmd == "mcp":
|
|
218
|
+
from bf import mcp
|
|
219
|
+
|
|
220
|
+
mcp.serve(brain_arg)
|
|
221
|
+
return 0
|
|
222
|
+
if cmd == "schema":
|
|
223
|
+
from bf import schemas
|
|
224
|
+
|
|
225
|
+
_emit(schemas.get_schema(args.name) if args.name is not None else schemas.export_schemas())
|
|
226
|
+
return 0
|
|
227
|
+
if cmd == "init":
|
|
228
|
+
from bf import engine
|
|
229
|
+
|
|
230
|
+
if args.name is not None and not args.name.strip():
|
|
231
|
+
raise InputError("--name must be nonempty")
|
|
232
|
+
_emit(engine.init_brain(args.path, name=args.name or "", description=args.description))
|
|
233
|
+
return 0
|
|
234
|
+
|
|
235
|
+
from bf import config
|
|
236
|
+
|
|
237
|
+
store = config.select(brain_arg)
|
|
238
|
+
if cmd == "watch":
|
|
239
|
+
from bf import watch
|
|
240
|
+
|
|
241
|
+
return 0 if watch.serve(store, json_stream=args.json_stream)["ok"] else 1
|
|
242
|
+
if cmd == "status":
|
|
243
|
+
from bf import engine, loops
|
|
244
|
+
|
|
245
|
+
wanted = engine.parse_fields(args.fields)
|
|
246
|
+
res = loops.status_summary(store, check=args.check, all_units=args.all_units, prune=args.prune)
|
|
247
|
+
ok = bool(res.get("ok", True))
|
|
248
|
+
if wanted is not None:
|
|
249
|
+
res = {k: res[k] for k in wanted if k in res}
|
|
250
|
+
_emit(res)
|
|
251
|
+
return 0 if (not args.check or ok) else 1
|
|
252
|
+
if cmd == "emit":
|
|
253
|
+
from bf import models, records
|
|
254
|
+
|
|
255
|
+
brain_name = config.load(store).name
|
|
256
|
+
if not models.EVENT_KIND_RE.fullmatch(args.kind):
|
|
257
|
+
raise InputError("event kind must match ^[a-z][a-z0-9._-]{0,127}$")
|
|
258
|
+
if not models.NAME_RE.fullmatch(args.source):
|
|
259
|
+
raise InputError("event source must use lowercase letters, digits, and hyphens")
|
|
260
|
+
try:
|
|
261
|
+
raw_data = models.decode(args.data, "--data") if args.data else {}
|
|
262
|
+
except Error as err:
|
|
263
|
+
raise InputError(str(err)) from err
|
|
264
|
+
if not isinstance(raw_data, dict):
|
|
265
|
+
raise InputError("--data must be a JSON object")
|
|
266
|
+
ev = records.append_event(store, args.kind, args.source, raw_data, dedupe=args.dedupe)
|
|
267
|
+
_emit({"ok": True, "brain": brain_name, "event": ev})
|
|
268
|
+
return 0
|
|
269
|
+
if cmd == "check":
|
|
270
|
+
from bf import query
|
|
271
|
+
|
|
272
|
+
if args.target is not None and not args.target.strip():
|
|
273
|
+
raise InputError("eval target must be nonempty")
|
|
274
|
+
if args.eval_only and (args.limit is not None or args.all_problems or args.strict or args.force):
|
|
275
|
+
raise InputError("--limit, --all, --strict, and --force cannot be combined with --eval")
|
|
276
|
+
v_on, e_on = not args.eval_only, not args.validate_only
|
|
277
|
+
res = query.check_brain(
|
|
278
|
+
store,
|
|
279
|
+
target=args.target or "",
|
|
280
|
+
build_notes=v_on and e_on,
|
|
281
|
+
run_validate=v_on,
|
|
282
|
+
run_eval=e_on,
|
|
283
|
+
limit=50 if args.limit is None else args.limit,
|
|
284
|
+
all_problems=args.all_problems,
|
|
285
|
+
strict=args.strict,
|
|
286
|
+
force=args.force,
|
|
287
|
+
)
|
|
288
|
+
_emit(res)
|
|
289
|
+
return 0 if res["ok"] else 1
|
|
290
|
+
if cmd == "run":
|
|
291
|
+
from bf import loops
|
|
292
|
+
|
|
293
|
+
if args.reset:
|
|
294
|
+
if args.dry_run or extra:
|
|
295
|
+
raise InputError("--reset cannot be combined with --dry-run or passthrough -- arguments")
|
|
296
|
+
_emit(loops.reset_loops(store, args.loops))
|
|
297
|
+
return 0
|
|
298
|
+
stdin_b = _read_in("-") if (args.hook == "pre-push" and not args.dry_run and not sys.stdin.isatty()) else b""
|
|
299
|
+
res = loops.run_loops(
|
|
300
|
+
store,
|
|
301
|
+
args.loops,
|
|
302
|
+
due_only=args.due,
|
|
303
|
+
hook=args.hook,
|
|
304
|
+
extra_args=extra,
|
|
305
|
+
stdin_bytes=stdin_b,
|
|
306
|
+
dry_run=args.dry_run,
|
|
307
|
+
)
|
|
308
|
+
_emit(res)
|
|
309
|
+
return 0 if res["ok"] else 1
|
|
310
|
+
if cmd == "ingest":
|
|
311
|
+
from bf import records
|
|
312
|
+
|
|
313
|
+
if args.input == "-" and sys.stdin.isatty():
|
|
314
|
+
raise InputError("stdin is a terminal; pipe JSON records or pass --input FILE")
|
|
315
|
+
_emit(
|
|
316
|
+
records.ingest(
|
|
317
|
+
store,
|
|
318
|
+
args.source,
|
|
319
|
+
_read_in(args.input),
|
|
320
|
+
mode=args.mode,
|
|
321
|
+
allow_removal=args.allow_removal,
|
|
322
|
+
dry_run=args.dry_run,
|
|
323
|
+
)
|
|
324
|
+
)
|
|
325
|
+
return 0
|
|
326
|
+
if cmd == "read":
|
|
327
|
+
from bf import query
|
|
328
|
+
|
|
329
|
+
_emit(
|
|
330
|
+
query.read_target(
|
|
331
|
+
store,
|
|
332
|
+
args.target,
|
|
333
|
+
outline=args.outline,
|
|
334
|
+
lines=args.lines,
|
|
335
|
+
fields=args.fields,
|
|
336
|
+
max_bytes=args.max_bytes,
|
|
337
|
+
raw=args.raw,
|
|
338
|
+
full=args.full,
|
|
339
|
+
)
|
|
340
|
+
)
|
|
341
|
+
return 0
|
|
342
|
+
if cmd == "query":
|
|
343
|
+
from bf import query
|
|
344
|
+
|
|
345
|
+
res = query.query(
|
|
346
|
+
store, args.pattern, jq_expr=args.jq, scope=args.scope, kind=args.kind, fields=args.fields, limit=args.limit
|
|
347
|
+
)
|
|
348
|
+
_emit_fmt(res, args.format, args.fields, review=False)
|
|
349
|
+
return 0
|
|
350
|
+
if cmd == "build":
|
|
351
|
+
from bf import engine
|
|
352
|
+
|
|
353
|
+
res = engine.build(store, force=args.force)
|
|
354
|
+
_emit(res)
|
|
355
|
+
return 0 if res["ok"] else 1
|
|
356
|
+
if cmd == "new":
|
|
357
|
+
from bf import engine
|
|
358
|
+
|
|
359
|
+
res = engine.new_note(
|
|
360
|
+
store, None, args.kind, args.slug, title=args.title, status=args.status, note_type=args.note_type
|
|
361
|
+
)
|
|
362
|
+
_emit(res)
|
|
363
|
+
return 0 if res["ok"] else 1
|
|
364
|
+
from bf import engine
|
|
365
|
+
|
|
366
|
+
res = engine.review(store, limit=args.limit, all_items=args.all_items, fields=args.fields)
|
|
367
|
+
_emit_fmt(res, args.format, args.fields, review=True)
|
|
368
|
+
if args.format != "json" and not res["ok"] and res.get("problems"):
|
|
369
|
+
sys.stderr.write(f"bf: {printable('; '.join(str(p) for p in res['problems']))}\n")
|
|
370
|
+
return 0 if res["ok"] else 1
|
|
192
371
|
|
|
193
372
|
|
|
194
373
|
def run(argv: Sequence[str] | None = None) -> int:
|
|
195
374
|
"""Execute one CLI invocation and return its POSIX exit code (`0`, `1`, `2`, `130`)."""
|
|
196
375
|
try:
|
|
197
376
|
head, extra = _split_run(list(sys.argv[1:] if argv is None else argv))
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
if c in {"init", "schema"} and rv:
|
|
201
|
-
raise InputError(f"bf {c} does not accept --brain")
|
|
202
|
-
vals = [*rv, *sv]
|
|
203
|
-
if any(not v.strip() for v in vals) or len(set(vals)) > 1:
|
|
204
|
-
raise InputError(
|
|
205
|
-
"--brain must be nonempty" if any(not v.strip() for v in vals) else "conflicting --brain values"
|
|
206
|
-
)
|
|
207
|
-
b_arg = vals[0] if vals else ""
|
|
208
|
-
if c == "mcp":
|
|
209
|
-
_mod("mcp").serve(b_arg)
|
|
210
|
-
return 0
|
|
211
|
-
if c == "schema":
|
|
212
|
-
_emit(_mod("schemas").get_schema(a.name) if a.name is not None else _mod("schemas").export_schemas())
|
|
213
|
-
return 0
|
|
214
|
-
if c == "init":
|
|
215
|
-
if a.name is not None and not a.name.strip():
|
|
216
|
-
raise InputError("--name must be nonempty")
|
|
217
|
-
_emit(_mod("engine").init_brain(a.path, name=a.name or ""))
|
|
218
|
-
return 0
|
|
219
|
-
st = _mod("config").select(b_arg)
|
|
220
|
-
if c == "watch":
|
|
221
|
-
return 0 if _mod("watch").serve(st, json_stream=a.json_stream)["ok"] else 1
|
|
222
|
-
if c == "status":
|
|
223
|
-
res = _mod("loops").status_summary(st, check=a.check, all_units=a.all_units)
|
|
224
|
-
ok = bool(res.get("ok", True))
|
|
225
|
-
if (wanted := _mod("engine").parse_fields(a.fields)) is not None:
|
|
226
|
-
res = {k: res[k] for k in wanted if k in res}
|
|
227
|
-
_emit(res)
|
|
228
|
-
return 0 if (not a.check or ok) else 1
|
|
229
|
-
if c == "emit":
|
|
230
|
-
brain_name, mod_m = _mod("config").load(st).name, _mod("models")
|
|
231
|
-
if not mod_m.EVENT_KIND_RE.fullmatch(a.kind):
|
|
232
|
-
raise InputError("event kind must match ^[a-z][a-z0-9._-]{0,127}$")
|
|
233
|
-
if not mod_m.NAME_RE.fullmatch(a.source):
|
|
234
|
-
raise InputError("event source must use lowercase letters, digits, and hyphens")
|
|
235
|
-
try:
|
|
236
|
-
raw_d = mod_m.decode(a.data, "--data") if a.data else {}
|
|
237
|
-
except Error as err:
|
|
238
|
-
raise InputError(str(err)) from err
|
|
239
|
-
if not isinstance(raw_d, dict):
|
|
240
|
-
raise InputError("--data must be a JSON object")
|
|
241
|
-
ev = _mod("records").append_event(st, a.kind, a.source, raw_d, dedupe=a.dedupe)
|
|
242
|
-
_emit({"ok": True, "brain": brain_name, "event": ev})
|
|
243
|
-
return 0
|
|
244
|
-
if c == "ingest" and a.input == "-" and sys.stdin.isatty():
|
|
245
|
-
raise InputError("stdin is a terminal; pipe JSON records or pass --input FILE")
|
|
246
|
-
b = _read_in("-") if (c == "run" and a.hook == "pre-push" and not a.dry_run and not sys.stdin.isatty()) else b""
|
|
247
|
-
pick = lambda *ks: {k: getattr(a, k) for k in ks} # noqa: E731
|
|
248
|
-
ops = {
|
|
249
|
-
"ingest": lambda: _mod("records").ingest(
|
|
250
|
-
st, a.source, _read_in(a.input), **pick("mode", "allow_removal", "dry_run")
|
|
251
|
-
),
|
|
252
|
-
"run": lambda: _mod("loops").run_loops(
|
|
253
|
-
st, a.loops, due_only=a.due, extra_args=extra, stdin_bytes=b, **pick("hook", "dry_run")
|
|
254
|
-
),
|
|
255
|
-
"read": lambda: _mod("query").read_target(
|
|
256
|
-
st, a.target, **pick("outline", "lines", "fields", "max_bytes", "raw", "full")
|
|
257
|
-
),
|
|
258
|
-
"query": lambda: _mod("query").query(
|
|
259
|
-
st, a.pattern, jq_expr=a.jq, **pick("scope", "kind", "source", "fields", "limit")
|
|
260
|
-
),
|
|
261
|
-
"eval": lambda: _mod("query").evaluate(st, a.target),
|
|
262
|
-
"build": lambda: _mod("engine").build(st, force=a.force),
|
|
263
|
-
"check": lambda: _mod("engine").check_brain(st, strict=a.strict, force=a.force),
|
|
264
|
-
"new": lambda: _mod("engine").new_note(st, None, a.kind, a.slug, **pick("title", "status", "note_type")),
|
|
265
|
-
"review": lambda: _mod("engine").review(st, **pick("limit", "all_items", "fields")),
|
|
266
|
-
"validate": lambda: _mod("engine").validate(st, **pick("limit", "all_problems", "strict", "force")),
|
|
267
|
-
}
|
|
268
|
-
res = ops[c]()
|
|
269
|
-
if c in {"query", "review"}:
|
|
270
|
-
_emit_fmt(res, a.format, a.fields, review=c == "review")
|
|
271
|
-
if c == "review" and a.format != "json" and not res["ok"] and res.get("problems"):
|
|
272
|
-
sys.stderr.write(f"bf: {printable('; '.join(str(p) for p in res['problems']))}\n")
|
|
273
|
-
return 0 if (c == "query" or res["ok"]) else 1
|
|
274
|
-
_emit(res)
|
|
275
|
-
return 0 if (c in {"ingest", "read"} or res["ok"]) else 1
|
|
377
|
+
args = _build_parser().parse_args(head)
|
|
378
|
+
return _dispatch(args, extra)
|
|
276
379
|
except KeyboardInterrupt:
|
|
277
380
|
return 130
|
|
278
381
|
except BrokenPipeError:
|
|
279
382
|
return 0
|
|
280
|
-
except InputError as
|
|
281
|
-
sys.stderr.write(f"bf: invalid input: {printable(str(
|
|
383
|
+
except InputError as err:
|
|
384
|
+
sys.stderr.write(f"bf: invalid input: {printable(str(err))}\n")
|
|
282
385
|
return 2
|
|
283
|
-
except (Error, OSError, UnicodeError) as
|
|
284
|
-
sys.stderr.write(f"bf: {printable(failure(
|
|
386
|
+
except (Error, OSError, UnicodeError) as err:
|
|
387
|
+
sys.stderr.write(f"bf: {printable(failure(err))}\n")
|
|
285
388
|
return 1
|
|
286
389
|
|
|
287
390
|
|