okf-cli 0.4.7__tar.gz → 0.4.9__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.
- {okf_cli-0.4.7 → okf_cli-0.4.9}/.gitignore +1 -0
- okf_cli-0.4.9/.last-update.json +4 -0
- {okf_cli-0.4.7 → okf_cli-0.4.9}/PKG-INFO +29 -18
- {okf_cli-0.4.7 → okf_cli-0.4.9}/README.md +27 -17
- okf_cli-0.4.9/example/blank-line/no-blank.md +3 -0
- okf_cli-0.4.9/example/blank-line/with-blank.md +5 -0
- {okf_cli-0.4.7 → okf_cli-0.4.9}/openwiki/architecture.md +3 -3
- {okf_cli-0.4.7 → okf_cli-0.4.9}/openwiki/domain-model.md +6 -6
- {okf_cli-0.4.7 → okf_cli-0.4.9}/openwiki/operations.md +2 -2
- {okf_cli-0.4.7 → okf_cli-0.4.9}/openwiki/quickstart.md +2 -2
- {okf_cli-0.4.7 → okf_cli-0.4.9}/openwiki/testing.md +4 -2
- {okf_cli-0.4.7 → okf_cli-0.4.9}/openwiki/workflows.md +4 -4
- {okf_cli-0.4.7 → okf_cli-0.4.9}/pyproject.toml +6 -2
- {okf_cli-0.4.7 → okf_cli-0.4.9}/src/okf/api.py +30 -29
- {okf_cli-0.4.7 → okf_cli-0.4.9}/src/okf/cli.py +2 -1
- {okf_cli-0.4.7 → okf_cli-0.4.9}/src/okf/commands/bundle.py +17 -12
- {okf_cli-0.4.7 → okf_cli-0.4.9}/src/okf/commands/list.py +4 -3
- okf_cli-0.4.9/src/okf/commands/show.py +29 -0
- {okf_cli-0.4.7 → okf_cli-0.4.9}/src/okf/commands/validate.py +6 -4
- {okf_cli-0.4.7 → okf_cli-0.4.9}/src/okf/core.py +4 -0
- {okf_cli-0.4.7 → okf_cli-0.4.9}/tests/test_api.py +5 -4
- {okf_cli-0.4.7 → okf_cli-0.4.9}/tests/test_cli.py +3 -2
- {okf_cli-0.4.7 → okf_cli-0.4.9}/uv.lock +3 -1
- okf_cli-0.4.7/.last-update.json +0 -1
- okf_cli-0.4.7/src/okf/commands/show.py +0 -21
- {okf_cli-0.4.7 → okf_cli-0.4.9}/.github/workflows/test.yml +0 -0
- {okf_cli-0.4.7 → okf_cli-0.4.9}/AGENTS.md +0 -0
- {okf_cli-0.4.7 → okf_cli-0.4.9}/LICENSE +0 -0
- {okf_cli-0.4.7 → okf_cli-0.4.9}/OKF_SPEC.md +0 -0
- {okf_cli-0.4.7 → okf_cli-0.4.9}/example/.okfignore +0 -0
- {okf_cli-0.4.7 → okf_cli-0.4.9}/example/README.md +0 -0
- {okf_cli-0.4.7 → okf_cli-0.4.9}/example/datasets/sales.md +0 -0
- {okf_cli-0.4.7 → okf_cli-0.4.9}/example/domain.md +0 -0
- {okf_cli-0.4.7 → okf_cli-0.4.9}/example/loose/deep/no-heading.md +0 -0
- {okf_cli-0.4.7 → okf_cli-0.4.9}/example/loose/no-desc.md +0 -0
- {okf_cli-0.4.7 → okf_cli-0.4.9}/example/loose/no-title.md +0 -0
- {okf_cli-0.4.7 → okf_cli-0.4.9}/example/playbooks/incident-response.md +0 -0
- {okf_cli-0.4.7 → okf_cli-0.4.9}/example/playbooks/oncall-guide.md +0 -0
- {okf_cli-0.4.7 → okf_cli-0.4.9}/example/smoke-ignore.md +0 -0
- {okf_cli-0.4.7 → okf_cli-0.4.9}/example/tables/customers.md +0 -0
- {okf_cli-0.4.7 → okf_cli-0.4.9}/example/tables/orders.md +0 -0
- {okf_cli-0.4.7 → okf_cli-0.4.9}/example/tables/partitions/2026/q1/jan/january.md +0 -0
- {okf_cli-0.4.7 → okf_cli-0.4.9}/example/tables/partitions/daily.md +0 -0
- {okf_cli-0.4.7 → okf_cli-0.4.9}/skills/okf-cli-manual/SKILL.md +0 -0
- {okf_cli-0.4.7 → okf_cli-0.4.9}/skills/writing-knowledge-base/SKILL.md +0 -0
- {okf_cli-0.4.7 → okf_cli-0.4.9}/src/okf/__init__.py +0 -0
- {okf_cli-0.4.7 → okf_cli-0.4.9}/src/okf/commands/__init__.py +0 -0
- {okf_cli-0.4.7 → okf_cli-0.4.9}/tests/test_core.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: okf-cli
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.9
|
|
4
4
|
Summary: Open Knowledge Format tooling
|
|
5
5
|
License: MIT License
|
|
6
6
|
|
|
@@ -26,6 +26,7 @@ License: MIT License
|
|
|
26
26
|
License-File: LICENSE
|
|
27
27
|
Requires-Python: >=3.11
|
|
28
28
|
Requires-Dist: pyyaml>=6
|
|
29
|
+
Requires-Dist: rich>=15.0.0
|
|
29
30
|
Requires-Dist: typer>=0.15
|
|
30
31
|
Description-Content-Type: text/markdown
|
|
31
32
|
|
|
@@ -33,7 +34,7 @@ Description-Content-Type: text/markdown
|
|
|
33
34
|
|
|
34
35
|
Converts plain markdown into [OKF](https://github.com/GoogleCloudPlatform/knowledge-catalog/blob/main/okf/SPEC.md)-conformant knowledge bundles. Domain experts write the content, `okf bundle` generates frontmatter, type, timestamps, and index files.
|
|
35
36
|
|
|
36
|
-
Also validates bundles, lists concept IDs,
|
|
37
|
+
Also validates bundles, lists concept IDs, reads concepts by ID, and reports version.
|
|
37
38
|
|
|
38
39
|
## Install
|
|
39
40
|
|
|
@@ -46,32 +47,35 @@ uv tool install okf-cli
|
|
|
46
47
|
```bash
|
|
47
48
|
uv sync
|
|
48
49
|
uv run okf --help
|
|
50
|
+
uv run okf --version
|
|
49
51
|
```
|
|
50
52
|
|
|
53
|
+
Global options: `--version`, `--help`.
|
|
54
|
+
|
|
51
55
|
## Commands
|
|
52
56
|
|
|
53
57
|
### `okf bundle` — convert plain markdown to OKF bundle
|
|
54
58
|
|
|
55
59
|
```
|
|
56
|
-
okf bundle <input-dir> [output-dir] [--default-type <name>] [--force] [--strict
|
|
60
|
+
okf bundle <input-dir> [output-dir] [--default-type <name>] [--force] [--strict]
|
|
57
61
|
```
|
|
58
62
|
|
|
59
63
|
| Argument | Description |
|
|
60
64
|
| ---------------- | ---------------------------------------------------------------------------- |
|
|
61
65
|
| `input-dir` | Directory of plain `.md` files |
|
|
62
|
-
| `output-dir` | Target directory (default: `
|
|
63
|
-
| `--default-type` | Type for root-level files (
|
|
66
|
+
| `output-dir` | Target directory (default: `<input-dir>_knowledge_base`) |
|
|
67
|
+
| `--default-type` | Type for root-level files (default: input directory name) |
|
|
64
68
|
| `--force`, `-f` | Overwrite output directory if it exists |
|
|
65
|
-
| `--strict
|
|
69
|
+
| `--strict` | Enforce strict OKF spec output: fail on broken local `.md` links and skip `AGENTS.md` generation |
|
|
66
70
|
|
|
67
71
|
```bash
|
|
68
|
-
okf bundle example --default-type reference
|
|
69
|
-
okf bundle example --default-type reference --force --strict
|
|
72
|
+
okf bundle example --default-type reference # → example_knowledge_base/
|
|
73
|
+
okf bundle example bundled --default-type reference --force --strict
|
|
70
74
|
```
|
|
71
75
|
|
|
72
76
|
**`.okfignore`**: put in `input-dir` root; one bundle-relative `.md` path per line. Exact match only (no glob).
|
|
73
77
|
|
|
74
|
-
**Link checking**: scans body links to local `.md` targets. Missing or out-of-bundle links warn by default, fail with `--strict
|
|
78
|
+
**Link checking**: scans body links to local `.md` targets. Missing or out-of-bundle links warn by default, fail with `--strict`.
|
|
75
79
|
|
|
76
80
|
### `okf list` — list concept IDs in a bundle
|
|
77
81
|
|
|
@@ -82,7 +86,7 @@ okf list <directory>
|
|
|
82
86
|
Prints concept IDs (path without `.md`). Requires valid OKF bundle.
|
|
83
87
|
|
|
84
88
|
```bash
|
|
85
|
-
okf list
|
|
89
|
+
okf list example_knowledge_base/
|
|
86
90
|
# datasets/sales
|
|
87
91
|
# tables/orders
|
|
88
92
|
```
|
|
@@ -104,7 +108,7 @@ okf validate <directory>
|
|
|
104
108
|
Checks OKF v0.1 §9 conformance: frontmatter required, `type` required, reserved filenames follow spec structure, UTF-8 required.
|
|
105
109
|
|
|
106
110
|
```bash
|
|
107
|
-
okf validate
|
|
111
|
+
okf validate example_knowledge_base/
|
|
108
112
|
# 16 files: 16 ok
|
|
109
113
|
```
|
|
110
114
|
|
|
@@ -129,7 +133,7 @@ Files without strict format are bundled best-effort: title omitted if absent, de
|
|
|
129
133
|
| `index.md`, `log.md`, `README.md` skipped in `bundle` | Repo artifacts; not OKF concepts. `list`/`show`/`validate` only reserve `index.md` and `log.md`. |
|
|
130
134
|
| `.okfignore` entries skipped | Skip selected files without moving them. |
|
|
131
135
|
|
|
132
|
-
Root files
|
|
136
|
+
Root files use `--default-type`, defaulting to the input directory name. See [`example/`](example/) for sample structure.
|
|
133
137
|
|
|
134
138
|
## Output
|
|
135
139
|
|
|
@@ -157,13 +161,20 @@ Generated bundles conform to [OKF v0.1](OKF_SPEC.md) (§9): frontmatter required
|
|
|
157
161
|
```
|
|
158
162
|
okf-cli
|
|
159
163
|
├── .github/workflows/test.yml # CI
|
|
164
|
+
├── AGENTS.md # Contributor context for AI agents
|
|
160
165
|
├── OKF_SPEC.md # OKF specification
|
|
166
|
+
├── README.md # This file
|
|
167
|
+
├── openwiki/ # Contributor docs (architecture, workflows, etc.)
|
|
161
168
|
├── pyproject.toml # uv-managed Python project
|
|
169
|
+
├── skills/ # Optional skill definitions
|
|
170
|
+
├── uv.lock # uv lockfile
|
|
162
171
|
├── src/okf/
|
|
163
|
-
│ ├── cli.py
|
|
164
|
-
│ ├── api.py
|
|
165
|
-
│ ├── core.py
|
|
166
|
-
│ └── commands/
|
|
167
|
-
├── tests/
|
|
168
|
-
└── example/
|
|
172
|
+
│ ├── cli.py # Typer entrypoint
|
|
173
|
+
│ ├── api.py # Programmatic Python API
|
|
174
|
+
│ ├── core.py # Shared parsing/formatting
|
|
175
|
+
│ └── commands/ # bundle, list, show, validate
|
|
176
|
+
├── tests/ # pytest suite
|
|
177
|
+
└── example/ # Sample input markdown
|
|
169
178
|
```
|
|
179
|
+
|
|
180
|
+
For contributor guidance, see [`AGENTS.md`](AGENTS.md) and [`openwiki/quickstart.md`](openwiki/quickstart.md).
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Converts plain markdown into [OKF](https://github.com/GoogleCloudPlatform/knowledge-catalog/blob/main/okf/SPEC.md)-conformant knowledge bundles. Domain experts write the content, `okf bundle` generates frontmatter, type, timestamps, and index files.
|
|
4
4
|
|
|
5
|
-
Also validates bundles, lists concept IDs,
|
|
5
|
+
Also validates bundles, lists concept IDs, reads concepts by ID, and reports version.
|
|
6
6
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
@@ -15,32 +15,35 @@ uv tool install okf-cli
|
|
|
15
15
|
```bash
|
|
16
16
|
uv sync
|
|
17
17
|
uv run okf --help
|
|
18
|
+
uv run okf --version
|
|
18
19
|
```
|
|
19
20
|
|
|
21
|
+
Global options: `--version`, `--help`.
|
|
22
|
+
|
|
20
23
|
## Commands
|
|
21
24
|
|
|
22
25
|
### `okf bundle` — convert plain markdown to OKF bundle
|
|
23
26
|
|
|
24
27
|
```
|
|
25
|
-
okf bundle <input-dir> [output-dir] [--default-type <name>] [--force] [--strict
|
|
28
|
+
okf bundle <input-dir> [output-dir] [--default-type <name>] [--force] [--strict]
|
|
26
29
|
```
|
|
27
30
|
|
|
28
31
|
| Argument | Description |
|
|
29
32
|
| ---------------- | ---------------------------------------------------------------------------- |
|
|
30
33
|
| `input-dir` | Directory of plain `.md` files |
|
|
31
|
-
| `output-dir` | Target directory (default: `
|
|
32
|
-
| `--default-type` | Type for root-level files (
|
|
34
|
+
| `output-dir` | Target directory (default: `<input-dir>_knowledge_base`) |
|
|
35
|
+
| `--default-type` | Type for root-level files (default: input directory name) |
|
|
33
36
|
| `--force`, `-f` | Overwrite output directory if it exists |
|
|
34
|
-
| `--strict
|
|
37
|
+
| `--strict` | Enforce strict OKF spec output: fail on broken local `.md` links and skip `AGENTS.md` generation |
|
|
35
38
|
|
|
36
39
|
```bash
|
|
37
|
-
okf bundle example --default-type reference
|
|
38
|
-
okf bundle example --default-type reference --force --strict
|
|
40
|
+
okf bundle example --default-type reference # → example_knowledge_base/
|
|
41
|
+
okf bundle example bundled --default-type reference --force --strict
|
|
39
42
|
```
|
|
40
43
|
|
|
41
44
|
**`.okfignore`**: put in `input-dir` root; one bundle-relative `.md` path per line. Exact match only (no glob).
|
|
42
45
|
|
|
43
|
-
**Link checking**: scans body links to local `.md` targets. Missing or out-of-bundle links warn by default, fail with `--strict
|
|
46
|
+
**Link checking**: scans body links to local `.md` targets. Missing or out-of-bundle links warn by default, fail with `--strict`.
|
|
44
47
|
|
|
45
48
|
### `okf list` — list concept IDs in a bundle
|
|
46
49
|
|
|
@@ -51,7 +54,7 @@ okf list <directory>
|
|
|
51
54
|
Prints concept IDs (path without `.md`). Requires valid OKF bundle.
|
|
52
55
|
|
|
53
56
|
```bash
|
|
54
|
-
okf list
|
|
57
|
+
okf list example_knowledge_base/
|
|
55
58
|
# datasets/sales
|
|
56
59
|
# tables/orders
|
|
57
60
|
```
|
|
@@ -73,7 +76,7 @@ okf validate <directory>
|
|
|
73
76
|
Checks OKF v0.1 §9 conformance: frontmatter required, `type` required, reserved filenames follow spec structure, UTF-8 required.
|
|
74
77
|
|
|
75
78
|
```bash
|
|
76
|
-
okf validate
|
|
79
|
+
okf validate example_knowledge_base/
|
|
77
80
|
# 16 files: 16 ok
|
|
78
81
|
```
|
|
79
82
|
|
|
@@ -98,7 +101,7 @@ Files without strict format are bundled best-effort: title omitted if absent, de
|
|
|
98
101
|
| `index.md`, `log.md`, `README.md` skipped in `bundle` | Repo artifacts; not OKF concepts. `list`/`show`/`validate` only reserve `index.md` and `log.md`. |
|
|
99
102
|
| `.okfignore` entries skipped | Skip selected files without moving them. |
|
|
100
103
|
|
|
101
|
-
Root files
|
|
104
|
+
Root files use `--default-type`, defaulting to the input directory name. See [`example/`](example/) for sample structure.
|
|
102
105
|
|
|
103
106
|
## Output
|
|
104
107
|
|
|
@@ -126,13 +129,20 @@ Generated bundles conform to [OKF v0.1](OKF_SPEC.md) (§9): frontmatter required
|
|
|
126
129
|
```
|
|
127
130
|
okf-cli
|
|
128
131
|
├── .github/workflows/test.yml # CI
|
|
132
|
+
├── AGENTS.md # Contributor context for AI agents
|
|
129
133
|
├── OKF_SPEC.md # OKF specification
|
|
134
|
+
├── README.md # This file
|
|
135
|
+
├── openwiki/ # Contributor docs (architecture, workflows, etc.)
|
|
130
136
|
├── pyproject.toml # uv-managed Python project
|
|
137
|
+
├── skills/ # Optional skill definitions
|
|
138
|
+
├── uv.lock # uv lockfile
|
|
131
139
|
├── src/okf/
|
|
132
|
-
│ ├── cli.py
|
|
133
|
-
│ ├── api.py
|
|
134
|
-
│ ├── core.py
|
|
135
|
-
│ └── commands/
|
|
136
|
-
├── tests/
|
|
137
|
-
└── example/
|
|
140
|
+
│ ├── cli.py # Typer entrypoint
|
|
141
|
+
│ ├── api.py # Programmatic Python API
|
|
142
|
+
│ ├── core.py # Shared parsing/formatting
|
|
143
|
+
│ └── commands/ # bundle, list, show, validate
|
|
144
|
+
├── tests/ # pytest suite
|
|
145
|
+
└── example/ # Sample input markdown
|
|
138
146
|
```
|
|
147
|
+
|
|
148
|
+
For contributor guidance, see [`AGENTS.md`](AGENTS.md) and [`openwiki/quickstart.md`](openwiki/quickstart.md).
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
- **Core layer** (`src/okf/core.py`) — shared parsing, formatting, conformance helpers.
|
|
10
10
|
- **Command wrappers** (`src/okf/commands/`) — thin IO/error bridges from CLI args to API calls.
|
|
11
11
|
|
|
12
|
-
Why this split: the API layer is the canonical home for all logic. Commands handle only Typer argument parsing, error display, and exit codes. `core.py`
|
|
12
|
+
Why this split: the API layer is the canonical home for all logic. Commands handle only Typer argument parsing, error display, and exit codes. `core.py` holds pure parsing / formatting / conformance logic, but also instantiates shared rich `Console` singletons at import for output (used by `cli.py` and `commands/*`).
|
|
13
13
|
|
|
14
14
|
## Key modules
|
|
15
15
|
|
|
@@ -48,10 +48,10 @@ Each file imports from `okf.api` and calls the corresponding function, translati
|
|
|
48
48
|
1. Read source directory + optional `.okfignore` (`_load_okfignore`).
|
|
49
49
|
1. Walk `*.md`, skipping reserved names and ignored paths.
|
|
50
50
|
1. Parse each markdown file via `parse_md` (strict first, lenient fallback).
|
|
51
|
-
1. Scan markdown body links via `_iter_links` / `_resolve_md_target` — warns on missing or out-of-bundle targets; `--strict
|
|
51
|
+
1. Scan markdown body links via `_iter_links` / `_resolve_md_target` — warns on missing or out-of-bundle targets; `--strict` makes these fatal.
|
|
52
52
|
1. Build YAML frontmatter via `build_frontmatter`.
|
|
53
53
|
1. Write transformed files and generate `index.md` per directory.
|
|
54
|
-
1. Write `AGENTS.md` at output root with navigation guidance for the knowledge base.
|
|
54
|
+
1. Write `AGENTS.md` at output root with navigation guidance for the knowledge base (skipped when `--strict` is used).
|
|
55
55
|
|
|
56
56
|
### `okf validate` (via `api.validate()`)
|
|
57
57
|
|
|
@@ -76,10 +76,10 @@ Source: `src/okf/core.py`.
|
|
|
76
76
|
- `_resolve_md_target(current_rel, raw_target)` resolves to a bundle-relative POSIX path.
|
|
77
77
|
- Ignored: external URLs (`https:`, `mailto:`), fragment-only links (`#section`), directory links, non-`.md` targets.
|
|
78
78
|
- Default mode: warnings for missing targets or targets resolving outside bundle.
|
|
79
|
-
- `--strict
|
|
79
|
+
- `--strict`: turns warnings into fatal exit and skips `AGENTS.md` generation.
|
|
80
80
|
- Generated `index.md` files count as valid link targets.
|
|
81
81
|
|
|
82
|
-
Source: `src/okf/
|
|
82
|
+
Source: `src/okf/api.py` (`_iter_links`, `_resolve_md_target`).
|
|
83
83
|
|
|
84
84
|
## `.okfignore` model (bundle-only)
|
|
85
85
|
|
|
@@ -89,7 +89,7 @@ Source: `src/okf/commands/bundle.py`.
|
|
|
89
89
|
- no glob/negation semantics
|
|
90
90
|
- non-UTF-8 `.okfignore` fails bundling
|
|
91
91
|
|
|
92
|
-
Source: `_load_okfignore` in `src/okf/
|
|
92
|
+
Source: `_load_okfignore` in `src/okf/api.py`; example file: `example/.okfignore`.
|
|
93
93
|
|
|
94
94
|
## Bundle output artifacts
|
|
95
95
|
|
|
@@ -97,9 +97,9 @@ Each bundle run produces:
|
|
|
97
97
|
|
|
98
98
|
- concept `.md` files with YAML frontmatter
|
|
99
99
|
- `index.md` per directory listing contents and subdirs
|
|
100
|
-
- `AGENTS.md` at output root: navigation guide for AI agents and humans (references `index.md`, explains frontmatter and cross-links)
|
|
100
|
+
- `AGENTS.md` at output root: navigation guide for AI agents and humans (references `index.md`, explains frontmatter and cross-links); omitted in `--strict` mode
|
|
101
101
|
|
|
102
|
-
Source: `src/okf/
|
|
102
|
+
Source: `src/okf/api.py` (`_write_concept`, `_generate_indexes`, `bundle`).
|
|
103
103
|
|
|
104
104
|
## Conformance rules enforced
|
|
105
105
|
|
|
@@ -114,4 +114,4 @@ Source: `src/okf/commands/bundle.py`.
|
|
|
114
114
|
- `log.md` must not have frontmatter;
|
|
115
115
|
1. markdown files must be UTF-8.
|
|
116
116
|
|
|
117
|
-
Source: `src/okf/core.py`; behavior validated by `tests/
|
|
117
|
+
Source: `src/okf/core.py`; behavior validated by `tests/test_api.py` (`TestValidate`) and `tests/test_cli.py`.
|
|
@@ -14,8 +14,8 @@ Packaging and runtime metadata: `pyproject.toml`.
|
|
|
14
14
|
Key points:
|
|
15
15
|
|
|
16
16
|
- CLI script entrypoint: `okf = "okf.cli:app"`
|
|
17
|
-
- Python API: `from okf.api import bundle, list_concepts, show_concept, validate`
|
|
18
|
-
- Runtime deps: `typer`, `pyyaml`
|
|
17
|
+
- Python API: `from okf.api import bundle, convert_file, convert_content, list_concepts, show_concept, validate`
|
|
18
|
+
- Runtime deps: `typer`, `pyyaml`, `rich`
|
|
19
19
|
- Dev deps include `pytest`, `ruff`
|
|
20
20
|
|
|
21
21
|
## Day-to-day commands
|
|
@@ -18,7 +18,7 @@ uv run okf bundle example --default-type reference --force
|
|
|
18
18
|
uv run okf validate example_knowledge_base
|
|
19
19
|
uv run okf list example_knowledge_base
|
|
20
20
|
uv run okf show example_knowledge_base tables/customers
|
|
21
|
-
uv run okf bundle example --default-type reference --force --strict
|
|
21
|
+
uv run okf bundle example --default-type reference --force --strict
|
|
22
22
|
```
|
|
23
23
|
|
|
24
24
|
### Python API
|
|
@@ -50,7 +50,7 @@ Why this sequence:
|
|
|
50
50
|
1. `bundle` transforms raw markdown into OKF structure.
|
|
51
51
|
1. `validate` checks OKF conformance gate used by readers.
|
|
52
52
|
1. `list`/`show` operate only on conformant bundles.
|
|
53
|
-
1. `--strict
|
|
53
|
+
1. `--strict` catches broken local `.md` references at bundle time and skips `AGENTS.md` generation.
|
|
54
54
|
|
|
55
55
|
## OpenWiki map
|
|
56
56
|
|
|
@@ -8,13 +8,15 @@
|
|
|
8
8
|
- `TestShowConcept` — reading via `api.show_concept()`, path traversal guard
|
|
9
9
|
- `TestValidate` — conformance checks via `api.validate()`, all §9 rule variants
|
|
10
10
|
- `TestWorkflow` — cross-command pipeline (bundle → validate/list/show)
|
|
11
|
+
- `TestConvertFile` — single-file conversion via `api.convert_file()`, mtime timestamp
|
|
12
|
+
- `TestConvertContent` — raw markdown conversion via `api.convert_content()`, no timestamp
|
|
11
13
|
- Core unit tests: `tests/test_core.py`
|
|
12
14
|
- parsing helpers (`parse_md`, `parse_frontmatter`)
|
|
13
15
|
- frontmatter generation (`build_frontmatter`)
|
|
14
16
|
- conformance engine (`check_conformance`)
|
|
15
17
|
- CLI integration tests: `tests/test_cli.py`
|
|
16
18
|
- exit codes and error message formatting for all commands
|
|
17
|
-
- Typer-specific behavior (argument parsing, `--force`, `--strict
|
|
19
|
+
- Typer-specific behavior (argument parsing, `--force`, `--strict`)
|
|
18
20
|
|
|
19
21
|
## Run tests
|
|
20
22
|
|
|
@@ -70,6 +72,6 @@ uv run pytest -q
|
|
|
70
72
|
- Root `index.md` special allowance for `okf_version` only.
|
|
71
73
|
- `list`/`show` hard failure on non-conformant bundles.
|
|
72
74
|
- `show` path traversal guard.
|
|
73
|
-
- Link checking: `_resolve_md_target` path resolution, `--strict
|
|
75
|
+
- Link checking: `_resolve_md_target` path resolution, `--strict` fatal mode, missing/out-of-bundle targets.
|
|
74
76
|
|
|
75
77
|
Primary evidence: `tests/test_api.py`, `tests/test_core.py`, `tests/test_cli.py`.
|
|
@@ -19,7 +19,7 @@ Lenient fallback exists for imperfect files, but strict shape gives better metad
|
|
|
19
19
|
### 2) Bundle to OKF
|
|
20
20
|
|
|
21
21
|
```bash
|
|
22
|
-
uv run okf bundle <input-dir> [output-dir] [--default-type <type>] [--force] [--strict
|
|
22
|
+
uv run okf bundle <input-dir> [output-dir] [--default-type <type>] [--force] [--strict]
|
|
23
23
|
# output-dir defaults to <input-dir>_knowledge_base
|
|
24
24
|
# --default-type defaults to input directory name
|
|
25
25
|
```
|
|
@@ -29,10 +29,10 @@ Important behavior:
|
|
|
29
29
|
- Root-level markdown uses input directory name as type if `--default-type` not specified.
|
|
30
30
|
- Reserved filenames skipped during bundling (`index.md`, `log.md`, `README.md`).
|
|
31
31
|
- `.okfignore` in input root can skip exact bundle-relative paths.
|
|
32
|
-
- `--strict
|
|
33
|
-
- `AGENTS.md` is generated at output root with navigation guidance.
|
|
32
|
+
- `--strict` enforces strict OKF spec output: fails on broken local `.md` links and skips `AGENTS.md` generation.
|
|
33
|
+
- `AGENTS.md` is generated at output root with navigation guidance (unless `--strict` is used).
|
|
34
34
|
|
|
35
|
-
Source: `src/okf/
|
|
35
|
+
Source: `src/okf/api.py`.
|
|
36
36
|
|
|
37
37
|
### 3) Validate output
|
|
38
38
|
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "okf-cli"
|
|
3
|
-
version = "0.4.
|
|
3
|
+
version = "0.4.9"
|
|
4
4
|
description = "Open Knowledge Format tooling"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
license = { file = "LICENSE" }
|
|
7
7
|
requires-python = ">=3.11"
|
|
8
|
-
dependencies = [
|
|
8
|
+
dependencies = [
|
|
9
|
+
"typer>=0.15",
|
|
10
|
+
"pyyaml>=6",
|
|
11
|
+
"rich>=15.0.0",
|
|
12
|
+
]
|
|
9
13
|
|
|
10
14
|
[project.scripts]
|
|
11
15
|
okf = "okf.cli:app"
|
|
@@ -264,7 +264,7 @@ def bundle(
|
|
|
264
264
|
*,
|
|
265
265
|
default_type: str | None = None,
|
|
266
266
|
force: bool = False,
|
|
267
|
-
|
|
267
|
+
strict: bool = False,
|
|
268
268
|
) -> BundleResult:
|
|
269
269
|
"""Convert plain markdown into an OKF-conformant knowledge bundle.
|
|
270
270
|
|
|
@@ -273,8 +273,8 @@ def bundle(
|
|
|
273
273
|
output_dir: Target directory. Defaults to ``<input-dir>_knowledge_base``.
|
|
274
274
|
default_type: Concept type for root-level files.
|
|
275
275
|
force: Overwrite output directory if it exists.
|
|
276
|
-
|
|
277
|
-
|
|
276
|
+
strict: Enforce strict OKF spec output: fail on broken local .md
|
|
277
|
+
links and skip AGENTS.md generation.
|
|
278
278
|
|
|
279
279
|
Returns:
|
|
280
280
|
BundleResult with counts, warnings, and errors.
|
|
@@ -362,7 +362,7 @@ def bundle(
|
|
|
362
362
|
|
|
363
363
|
warnings.extend(link_issues)
|
|
364
364
|
|
|
365
|
-
if
|
|
365
|
+
if strict and link_issues:
|
|
366
366
|
errors.append("strict link check failed")
|
|
367
367
|
return BundleResult(0, dst, warnings, errors)
|
|
368
368
|
|
|
@@ -394,30 +394,31 @@ def bundle(
|
|
|
394
394
|
|
|
395
395
|
_generate_indexes(processed, dst)
|
|
396
396
|
|
|
397
|
-
# Write AGENTS.md
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
397
|
+
# Write AGENTS.md (skipped in strict mode)
|
|
398
|
+
if not strict:
|
|
399
|
+
(dst / "AGENTS.md").write_text(
|
|
400
|
+
f"# Knowledge Base: {dst.name}\n\n"
|
|
401
|
+
f"You are in an OKF (Open Knowledge Format) knowledge base called "
|
|
402
|
+
f"**{dst.name}**. OKF is a structured markdown format where each "
|
|
403
|
+
f"`.md` file is a concept with YAML frontmatter (`type`, `title`, "
|
|
404
|
+
f"`description`) and cross-links between related concepts.\n\n"
|
|
405
|
+
"## Instructions\n\n"
|
|
406
|
+
"- **Answer from this knowledge base only.** Use the concepts and "
|
|
407
|
+
"links here as your source of truth.\n"
|
|
408
|
+
"- **If the answer is not in the knowledge base, say so directly.** "
|
|
409
|
+
"Do not fabricate, guess, or pull from external knowledge.\n\n"
|
|
410
|
+
"## Getting Started\n\n"
|
|
411
|
+
"Read [index.md](index.md) first — it lists all concepts "
|
|
412
|
+
"and subdirectories.\n\n"
|
|
413
|
+
"## Navigation\n\n"
|
|
414
|
+
"- Follow markdown links between concepts.\n"
|
|
415
|
+
"- Each `.md` file has YAML frontmatter with `type`, `title`, "
|
|
416
|
+
"`description`.\n"
|
|
417
|
+
"- Subdirectories group related concepts by topic.\n"
|
|
418
|
+
"- Cross-links (e.g. `[Customers](/tables/customers.md)`) "
|
|
419
|
+
"express relationships.\n",
|
|
420
|
+
encoding="utf-8",
|
|
421
|
+
)
|
|
421
422
|
|
|
422
423
|
return BundleResult(
|
|
423
424
|
files_written=len(processed),
|
|
@@ -494,7 +495,7 @@ def show_concept(bundle_dir: str | Path, concept_id: str) -> ConceptContent:
|
|
|
494
495
|
|
|
495
496
|
if not concept_path.is_file():
|
|
496
497
|
raise FileNotFoundError(
|
|
497
|
-
f"Concept '{concept_id}' not found
|
|
498
|
+
f"Concept '{concept_id}' not found"
|
|
498
499
|
)
|
|
499
500
|
|
|
500
501
|
raw = concept_path.read_text(encoding="utf-8")
|
|
@@ -8,6 +8,7 @@ from okf.commands.bundle import bundle
|
|
|
8
8
|
from okf.commands.list import cmd_list
|
|
9
9
|
from okf.commands.show import cmd_show
|
|
10
10
|
from okf.commands.validate import validate
|
|
11
|
+
from okf.core import console
|
|
11
12
|
|
|
12
13
|
app = typer.Typer(
|
|
13
14
|
name="okf",
|
|
@@ -18,7 +19,7 @@ app = typer.Typer(
|
|
|
18
19
|
|
|
19
20
|
def _version_callback(value: bool) -> None:
|
|
20
21
|
if value:
|
|
21
|
-
|
|
22
|
+
console.print(f"okf {_version('okf-cli')}")
|
|
22
23
|
raise typer.Exit()
|
|
23
24
|
|
|
24
25
|
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
"""okf bundle command."""
|
|
2
2
|
|
|
3
|
-
from pathlib import Path
|
|
4
|
-
|
|
5
3
|
import typer
|
|
6
4
|
|
|
7
5
|
from okf import api
|
|
6
|
+
from okf.core import console, err_console
|
|
8
7
|
|
|
9
8
|
|
|
10
9
|
def bundle(
|
|
@@ -22,10 +21,13 @@ def bundle(
|
|
|
22
21
|
force: bool = typer.Option(
|
|
23
22
|
False, "--force", "-f", help="Overwrite output directory if it exists"
|
|
24
23
|
),
|
|
25
|
-
|
|
24
|
+
strict: bool = typer.Option(
|
|
26
25
|
False,
|
|
27
|
-
"--strict
|
|
28
|
-
help=
|
|
26
|
+
"--strict",
|
|
27
|
+
help=(
|
|
28
|
+
"Enforce strict OKF spec output: fail on broken local .md links "
|
|
29
|
+
"and skip AGENTS.md generation"
|
|
30
|
+
),
|
|
29
31
|
),
|
|
30
32
|
) -> None:
|
|
31
33
|
"""Convert plain markdown into an OKF-conformant knowledge bundle."""
|
|
@@ -35,25 +37,28 @@ def bundle(
|
|
|
35
37
|
output_dir,
|
|
36
38
|
default_type=default_type,
|
|
37
39
|
force=force,
|
|
38
|
-
|
|
40
|
+
strict=strict,
|
|
39
41
|
)
|
|
40
42
|
except FileNotFoundError as e:
|
|
41
|
-
|
|
43
|
+
err_console.print(f"Error: {e}", style="red")
|
|
42
44
|
raise typer.Exit(code=1)
|
|
43
45
|
except FileExistsError as e:
|
|
44
|
-
|
|
46
|
+
err_console.print(f"Error: {e}", style="red")
|
|
45
47
|
raise typer.Exit(code=1)
|
|
46
48
|
except ValueError as e:
|
|
47
|
-
|
|
49
|
+
err_console.print(f"Error: {e}", style="red")
|
|
48
50
|
raise typer.Exit(code=1)
|
|
49
51
|
|
|
50
52
|
for w in result.warnings:
|
|
51
|
-
|
|
53
|
+
err_console.print(f"Warning: {w}", style="yellow")
|
|
52
54
|
for e in result.errors:
|
|
53
|
-
|
|
55
|
+
err_console.print(f"Error: {e}", style="red")
|
|
54
56
|
|
|
55
57
|
if result.errors:
|
|
56
58
|
raise typer.Exit(code=1)
|
|
57
59
|
|
|
58
60
|
n = result.files_written
|
|
59
|
-
|
|
61
|
+
console.print(
|
|
62
|
+
f"Done. Converted {n} file{'s' if n != 1 else ''} → {result.output_dir}",
|
|
63
|
+
style="green",
|
|
64
|
+
)
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import typer
|
|
4
4
|
|
|
5
5
|
from okf import api
|
|
6
|
+
from okf.core import console, err_console
|
|
6
7
|
|
|
7
8
|
|
|
8
9
|
def cmd_list(
|
|
@@ -12,12 +13,12 @@ def cmd_list(
|
|
|
12
13
|
try:
|
|
13
14
|
cids = api.list_concepts(directory)
|
|
14
15
|
except (ValueError, NotADirectoryError) as e:
|
|
15
|
-
|
|
16
|
+
err_console.print(f"Error: {e}", style="red")
|
|
16
17
|
raise typer.Exit(code=1)
|
|
17
18
|
|
|
18
19
|
if not cids:
|
|
19
|
-
|
|
20
|
+
err_console.print("No concepts found", style="yellow")
|
|
20
21
|
raise typer.Exit(code=1)
|
|
21
22
|
|
|
22
23
|
for cid in cids:
|
|
23
|
-
|
|
24
|
+
console.print(cid, style="cyan")
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"""okf show command."""
|
|
2
|
+
|
|
3
|
+
import typer
|
|
4
|
+
|
|
5
|
+
from okf import api
|
|
6
|
+
from okf.core import console, err_console
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def cmd_show(
|
|
10
|
+
directory: str = typer.Argument(..., help="Directory of the OKF bundle"),
|
|
11
|
+
concept_id: str = typer.Argument(
|
|
12
|
+
..., help="Concept ID to read (e.g. tables/orders)"
|
|
13
|
+
),
|
|
14
|
+
) -> None:
|
|
15
|
+
"""Print a concept's full contents by its concept ID."""
|
|
16
|
+
try:
|
|
17
|
+
result = api.show_concept(directory, concept_id)
|
|
18
|
+
except FileNotFoundError as e:
|
|
19
|
+
err_console.print(f"Error: {e}", style="red")
|
|
20
|
+
err_console.print(
|
|
21
|
+
f"Run `okf list {directory}` to see available concept IDs.",
|
|
22
|
+
style="yellow",
|
|
23
|
+
)
|
|
24
|
+
raise typer.Exit(code=1)
|
|
25
|
+
except (ValueError, NotADirectoryError) as e:
|
|
26
|
+
err_console.print(f"Error: {e}", style="red")
|
|
27
|
+
raise typer.Exit(code=1)
|
|
28
|
+
|
|
29
|
+
console.print(result.raw, end="", markup=False, highlight=False)
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import typer
|
|
4
4
|
|
|
5
5
|
from okf import api
|
|
6
|
+
from okf.core import console, err_console
|
|
6
7
|
|
|
7
8
|
|
|
8
9
|
def validate(
|
|
@@ -12,13 +13,13 @@ def validate(
|
|
|
12
13
|
try:
|
|
13
14
|
result = api.validate(directory)
|
|
14
15
|
except NotADirectoryError as e:
|
|
15
|
-
|
|
16
|
+
err_console.print(f"Error: {e}", style="red")
|
|
16
17
|
raise typer.Exit(code=1)
|
|
17
18
|
|
|
18
19
|
for w in result.warnings:
|
|
19
|
-
|
|
20
|
+
err_console.print(f"Warning: {w}", style="yellow")
|
|
20
21
|
for e in result.errors:
|
|
21
|
-
|
|
22
|
+
err_console.print(f"Error: {e}", style="red")
|
|
22
23
|
|
|
23
24
|
ok = result.total_files - len(result.errors)
|
|
24
25
|
parts = [f"{result.total_files} files: {ok} ok"]
|
|
@@ -26,7 +27,8 @@ def validate(
|
|
|
26
27
|
parts.append(f"{len(result.errors)} errors")
|
|
27
28
|
if result.warnings:
|
|
28
29
|
parts.append(f"{len(result.warnings)} warnings")
|
|
29
|
-
|
|
30
|
+
summary_color = "green" if not result.errors else "red"
|
|
31
|
+
console.print("\n" + ", ".join(parts), style=summary_color)
|
|
30
32
|
|
|
31
33
|
if result.errors:
|
|
32
34
|
raise typer.Exit(code=1)
|
|
@@ -5,6 +5,10 @@ from pathlib import Path
|
|
|
5
5
|
from typing import Any
|
|
6
6
|
|
|
7
7
|
import yaml
|
|
8
|
+
from rich.console import Console
|
|
9
|
+
|
|
10
|
+
console = Console()
|
|
11
|
+
err_console = Console(stderr=True)
|
|
8
12
|
|
|
9
13
|
RESERVED = frozenset({"index.md", "log.md", "readme.md"})
|
|
10
14
|
SPEC_RESERVED = frozenset({"index.md", "log.md", "agents.md"})
|
|
@@ -334,7 +334,7 @@ class TestBundle:
|
|
|
334
334
|
|
|
335
335
|
assert any("points outside bundle" in w for w in result.warnings)
|
|
336
336
|
|
|
337
|
-
def
|
|
337
|
+
def test_strict_fails(self, tmp_path: Path):
|
|
338
338
|
src = tmp_path / "src"
|
|
339
339
|
dst = tmp_path / "out"
|
|
340
340
|
src.mkdir()
|
|
@@ -343,12 +343,12 @@ class TestBundle:
|
|
|
343
343
|
{"tables/orders.md": "# Orders\n\n> One row.\n\nSee [C](customers.md)."},
|
|
344
344
|
)
|
|
345
345
|
|
|
346
|
-
result = bundle(src, dst,
|
|
346
|
+
result = bundle(src, dst, strict=True)
|
|
347
347
|
|
|
348
348
|
assert result.files_written == 0
|
|
349
349
|
assert any("strict link check failed" in e.lower() for e in result.errors)
|
|
350
350
|
|
|
351
|
-
def
|
|
351
|
+
def test_strict_passes(self, tmp_path: Path):
|
|
352
352
|
src = tmp_path / "src"
|
|
353
353
|
dst = tmp_path / "out"
|
|
354
354
|
src.mkdir()
|
|
@@ -362,10 +362,11 @@ class TestBundle:
|
|
|
362
362
|
},
|
|
363
363
|
)
|
|
364
364
|
|
|
365
|
-
result = bundle(src, dst,
|
|
365
|
+
result = bundle(src, dst, strict=True)
|
|
366
366
|
|
|
367
367
|
assert result.files_written == 2
|
|
368
368
|
assert result.errors == []
|
|
369
|
+
assert not (dst / "AGENTS.md").exists()
|
|
369
370
|
|
|
370
371
|
def test_agents_md(self, tmp_path: Path):
|
|
371
372
|
src = tmp_path / "src"
|
|
@@ -70,7 +70,7 @@ def test_bundle_force_shows_removed(tmp_path: Path):
|
|
|
70
70
|
assert "Removed existing" in result.output
|
|
71
71
|
|
|
72
72
|
|
|
73
|
-
def
|
|
73
|
+
def test_bundle_strict_shows_error(tmp_path: Path):
|
|
74
74
|
src = tmp_path / "src"
|
|
75
75
|
dst = tmp_path / "out"
|
|
76
76
|
src.mkdir()
|
|
@@ -81,9 +81,10 @@ def test_bundle_strict_links_shows_error(tmp_path: Path):
|
|
|
81
81
|
},
|
|
82
82
|
)
|
|
83
83
|
|
|
84
|
-
result = runner.invoke(app, ["bundle", str(src), str(dst), "--strict
|
|
84
|
+
result = runner.invoke(app, ["bundle", str(src), str(dst), "--strict"])
|
|
85
85
|
assert result.exit_code == 1
|
|
86
86
|
assert "strict link check failed" in result.output
|
|
87
|
+
assert not (dst / "AGENTS.md").exists()
|
|
87
88
|
|
|
88
89
|
|
|
89
90
|
# ---------------------------------------------------------------------------
|
|
@@ -52,10 +52,11 @@ wheels = [
|
|
|
52
52
|
|
|
53
53
|
[[package]]
|
|
54
54
|
name = "okf-cli"
|
|
55
|
-
version = "0.4.
|
|
55
|
+
version = "0.4.8"
|
|
56
56
|
source = { editable = "." }
|
|
57
57
|
dependencies = [
|
|
58
58
|
{ name = "pyyaml" },
|
|
59
|
+
{ name = "rich" },
|
|
59
60
|
{ name = "typer" },
|
|
60
61
|
]
|
|
61
62
|
|
|
@@ -68,6 +69,7 @@ dev = [
|
|
|
68
69
|
[package.metadata]
|
|
69
70
|
requires-dist = [
|
|
70
71
|
{ name = "pyyaml", specifier = ">=6" },
|
|
72
|
+
{ name = "rich", specifier = ">=15.0.0" },
|
|
71
73
|
{ name = "typer", specifier = ">=0.15" },
|
|
72
74
|
]
|
|
73
75
|
|
okf_cli-0.4.7/.last-update.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"head": "b0a76b5d97d2d46ab19d4fc4149be3efb4dc0228", "timestamp": "2025-07-15T19:10:00Z"}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"""okf show command."""
|
|
2
|
-
|
|
3
|
-
import typer
|
|
4
|
-
|
|
5
|
-
from okf import api
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
def cmd_show(
|
|
9
|
-
directory: str = typer.Argument(..., help="Directory of the OKF bundle"),
|
|
10
|
-
concept_id: str = typer.Argument(
|
|
11
|
-
..., help="Concept ID to read (e.g. tables/orders)"
|
|
12
|
-
),
|
|
13
|
-
) -> None:
|
|
14
|
-
"""Print a concept's full contents by its concept ID."""
|
|
15
|
-
try:
|
|
16
|
-
result = api.show_concept(directory, concept_id)
|
|
17
|
-
except (ValueError, FileNotFoundError, NotADirectoryError) as e:
|
|
18
|
-
typer.echo(f"Error: {e}", err=True)
|
|
19
|
-
raise typer.Exit(code=1)
|
|
20
|
-
|
|
21
|
-
typer.echo(result.raw, nl=False)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|