okf-cli 0.5.0__tar.gz → 0.5.3__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.5.0 → okf_cli-0.5.3}/AGENTS.md +1 -1
- {okf_cli-0.5.0 → okf_cli-0.5.3}/PKG-INFO +7 -7
- {okf_cli-0.5.0 → okf_cli-0.5.3}/README.md +6 -6
- okf_cli-0.5.3/example/blank-line/no-blank.md +4 -0
- {okf_cli-0.5.0 → okf_cli-0.5.3}/openwiki/quickstart.md +9 -3
- {okf_cli-0.5.0 → okf_cli-0.5.3}/openwiki/workflows.md +1 -1
- {okf_cli-0.5.0 → okf_cli-0.5.3}/pyproject.toml +2 -6
- okf_cli-0.5.3/skills/okf-cli/SKILL.md +196 -0
- {okf_cli-0.5.0 → okf_cli-0.5.3}/src/okf/api.py +19 -14
- {okf_cli-0.5.0 → okf_cli-0.5.3}/src/okf/commands/bundle.py +13 -1
- {okf_cli-0.5.0 → okf_cli-0.5.3}/src/okf/commands/read.py +4 -1
- {okf_cli-0.5.0 → okf_cli-0.5.3}/tests/test_api.py +78 -0
- {okf_cli-0.5.0 → okf_cli-0.5.3}/tests/test_cli.py +58 -0
- {okf_cli-0.5.0 → okf_cli-0.5.3}/uv.lock +1 -1
- okf_cli-0.5.0/example/blank-line/no-blank.md +0 -3
- okf_cli-0.5.0/skills/okf-cli-manual/SKILL.md +0 -110
- {okf_cli-0.5.0 → okf_cli-0.5.3}/.github/workflows/test.yml +0 -0
- {okf_cli-0.5.0 → okf_cli-0.5.3}/.gitignore +0 -0
- {okf_cli-0.5.0 → okf_cli-0.5.3}/.last-update.json +0 -0
- {okf_cli-0.5.0 → okf_cli-0.5.3}/LICENSE +0 -0
- {okf_cli-0.5.0 → okf_cli-0.5.3}/OKF_SPEC.md +0 -0
- {okf_cli-0.5.0 → okf_cli-0.5.3}/example/.okfignore +0 -0
- {okf_cli-0.5.0 → okf_cli-0.5.3}/example/README.md +0 -0
- {okf_cli-0.5.0 → okf_cli-0.5.3}/example/blank-line/with-blank.md +0 -0
- {okf_cli-0.5.0 → okf_cli-0.5.3}/example/datasets/sales.md +0 -0
- {okf_cli-0.5.0 → okf_cli-0.5.3}/example/domain.md +0 -0
- {okf_cli-0.5.0 → okf_cli-0.5.3}/example/loose/deep/no-heading.md +0 -0
- {okf_cli-0.5.0 → okf_cli-0.5.3}/example/loose/no-desc.md +0 -0
- {okf_cli-0.5.0 → okf_cli-0.5.3}/example/loose/no-title.md +0 -0
- {okf_cli-0.5.0 → okf_cli-0.5.3}/example/playbooks/incident-response.md +0 -0
- {okf_cli-0.5.0 → okf_cli-0.5.3}/example/playbooks/oncall-guide.md +0 -0
- {okf_cli-0.5.0 → okf_cli-0.5.3}/example/smoke-ignore.md +0 -0
- {okf_cli-0.5.0 → okf_cli-0.5.3}/example/tables/customers.md +0 -0
- {okf_cli-0.5.0 → okf_cli-0.5.3}/example/tables/orders.md +0 -0
- {okf_cli-0.5.0 → okf_cli-0.5.3}/example/tables/partitions/2026/q1/jan/january.md +0 -0
- {okf_cli-0.5.0 → okf_cli-0.5.3}/example/tables/partitions/daily.md +0 -0
- {okf_cli-0.5.0 → okf_cli-0.5.3}/openwiki/architecture.md +0 -0
- {okf_cli-0.5.0 → okf_cli-0.5.3}/openwiki/domain-model.md +0 -0
- {okf_cli-0.5.0 → okf_cli-0.5.3}/openwiki/operations.md +0 -0
- {okf_cli-0.5.0 → okf_cli-0.5.3}/openwiki/testing.md +0 -0
- {okf_cli-0.5.0 → okf_cli-0.5.3}/skills/writing-knowledge-base/SKILL.md +0 -0
- {okf_cli-0.5.0 → okf_cli-0.5.3}/src/okf/__init__.py +0 -0
- {okf_cli-0.5.0 → okf_cli-0.5.3}/src/okf/cli.py +0 -0
- {okf_cli-0.5.0 → okf_cli-0.5.3}/src/okf/commands/__init__.py +0 -0
- {okf_cli-0.5.0 → okf_cli-0.5.3}/src/okf/commands/list.py +0 -0
- {okf_cli-0.5.0 → okf_cli-0.5.3}/src/okf/commands/validate.py +0 -0
- {okf_cli-0.5.0 → okf_cli-0.5.3}/src/okf/core.py +0 -0
- {okf_cli-0.5.0 → okf_cli-0.5.3}/tests/test_core.py +0 -0
|
@@ -45,7 +45,7 @@ okf-cli
|
|
|
45
45
|
│ └── commands/
|
|
46
46
|
│ ├── bundle.py # thin wrapper → api.bundle()
|
|
47
47
|
│ ├── list.py # thin wrapper → api.list_concepts()
|
|
48
|
-
│ ├──
|
|
48
|
+
│ ├── read.py # thin wrapper → api.show_concept()
|
|
49
49
|
│ └── validate.py # thin wrapper → api.validate()
|
|
50
50
|
└── tests/
|
|
51
51
|
├── test_api.py # API unit/integration tests
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: okf-cli
|
|
3
|
-
Version: 0.5.
|
|
3
|
+
Version: 0.5.3
|
|
4
4
|
Summary: Open Knowledge Format tooling
|
|
5
5
|
License: MIT License
|
|
6
6
|
|
|
@@ -60,12 +60,12 @@ Global options: `--version`, `--help`.
|
|
|
60
60
|
okf bundle <input-dir> [output-dir] [--default-type <name>] [--force] [--strict]
|
|
61
61
|
```
|
|
62
62
|
|
|
63
|
-
| Argument | Description
|
|
64
|
-
| ---------------- |
|
|
65
|
-
| `input-dir` | Directory of plain `.md` files
|
|
66
|
-
| `output-dir` | Target directory (default: `<input-dir>_knowledge_base`)
|
|
67
|
-
| `--default-type` | Type for root-level files (default: input directory name)
|
|
68
|
-
| `--force`, `-f` | Overwrite output directory if it exists
|
|
63
|
+
| Argument | Description |
|
|
64
|
+
| ---------------- | ------------------------------------------------------------------------------------------------ |
|
|
65
|
+
| `input-dir` | Directory of plain `.md` files |
|
|
66
|
+
| `output-dir` | Target directory (default: `<input-dir>_knowledge_base`) |
|
|
67
|
+
| `--default-type` | Type for root-level files (default: input directory name) |
|
|
68
|
+
| `--force`, `-f` | Overwrite output directory if it exists |
|
|
69
69
|
| `--strict` | Enforce strict OKF spec output: fail on broken local `.md` links and skip `AGENTS.md` generation |
|
|
70
70
|
|
|
71
71
|
```bash
|
|
@@ -28,12 +28,12 @@ Global options: `--version`, `--help`.
|
|
|
28
28
|
okf bundle <input-dir> [output-dir] [--default-type <name>] [--force] [--strict]
|
|
29
29
|
```
|
|
30
30
|
|
|
31
|
-
| Argument | Description
|
|
32
|
-
| ---------------- |
|
|
33
|
-
| `input-dir` | Directory of plain `.md` files
|
|
34
|
-
| `output-dir` | Target directory (default: `<input-dir>_knowledge_base`)
|
|
35
|
-
| `--default-type` | Type for root-level files (default: input directory name)
|
|
36
|
-
| `--force`, `-f` | Overwrite output directory if it exists
|
|
31
|
+
| Argument | Description |
|
|
32
|
+
| ---------------- | ------------------------------------------------------------------------------------------------ |
|
|
33
|
+
| `input-dir` | Directory of plain `.md` files |
|
|
34
|
+
| `output-dir` | Target directory (default: `<input-dir>_knowledge_base`) |
|
|
35
|
+
| `--default-type` | Type for root-level files (default: input directory name) |
|
|
36
|
+
| `--force`, `-f` | Overwrite output directory if it exists |
|
|
37
37
|
| `--strict` | Enforce strict OKF spec output: fail on broken local `.md` links and skip `AGENTS.md` generation |
|
|
38
38
|
|
|
39
39
|
```bash
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
- CLI entrypoint: `src/okf/cli.py`
|
|
6
6
|
- Programmatic Python API: `src/okf/api.py`
|
|
7
7
|
- Shared parsing/conformance logic: `src/okf/core.py`
|
|
8
|
-
- Commands (thin wrappers): `src/okf/commands/bundle.py`, `src/okf/commands/validate.py`, `src/okf/commands/list.py`, `src/okf/commands/
|
|
8
|
+
- Commands (thin wrappers): `src/okf/commands/bundle.py`, `src/okf/commands/validate.py`, `src/okf/commands/list.py`, `src/okf/commands/read.py`
|
|
9
9
|
|
|
10
10
|
## Start in 5 minutes
|
|
11
11
|
|
|
@@ -19,14 +19,19 @@ uv run okf validate example_knowledge_base
|
|
|
19
19
|
uv run okf list example_knowledge_base
|
|
20
20
|
uv run okf read example_knowledge_base tables/customers
|
|
21
21
|
uv run okf bundle example --default-type reference --force --strict
|
|
22
|
+
uv run okf bundle example --default-type reference --dry-run
|
|
22
23
|
```
|
|
23
24
|
|
|
24
25
|
### Python API
|
|
25
26
|
|
|
26
27
|
```python
|
|
27
28
|
from okf.api import (
|
|
28
|
-
bundle,
|
|
29
|
-
|
|
29
|
+
bundle,
|
|
30
|
+
convert_file,
|
|
31
|
+
convert_content,
|
|
32
|
+
list_concepts,
|
|
33
|
+
show_concept,
|
|
34
|
+
validate,
|
|
30
35
|
)
|
|
31
36
|
|
|
32
37
|
# Full directory bundle
|
|
@@ -51,6 +56,7 @@ Why this sequence:
|
|
|
51
56
|
1. `validate` checks OKF conformance gate used by readers.
|
|
52
57
|
1. `list`/`show` operate only on conformant bundles.
|
|
53
58
|
1. `--strict` catches broken local `.md` references at bundle time and skips `AGENTS.md` generation.
|
|
59
|
+
1. `--dry-run` validates the source and reports warnings/errors without writing any files.
|
|
54
60
|
|
|
55
61
|
## OpenWiki map
|
|
56
62
|
|
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "okf-cli"
|
|
3
|
-
version = "0.5.
|
|
3
|
+
version = "0.5.3"
|
|
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 = [
|
|
9
|
-
"typer>=0.15",
|
|
10
|
-
"pyyaml>=6",
|
|
11
|
-
"rich>=15.0.0",
|
|
12
|
-
]
|
|
8
|
+
dependencies = ["typer>=0.15", "pyyaml>=6", "rich>=15.0.0"]
|
|
13
9
|
|
|
14
10
|
[project.scripts]
|
|
15
11
|
okf = "okf.cli:app"
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: okf-cli
|
|
3
|
+
description: >
|
|
4
|
+
User manual and reference for the okf CLI tool (Open Knowledge Format).
|
|
5
|
+
Use for questions about bundling plain markdown into OKF knowledge bases,
|
|
6
|
+
validating OKF bundles, listing concepts, reading concepts, CLI options,
|
|
7
|
+
and end-user workflows. Not for okf-cli source development.
|
|
8
|
+
license: MIT
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
# okf CLI User Manual
|
|
12
|
+
|
|
13
|
+
`okf` converts plain markdown directories into **Open Knowledge Format (OKF)** bundles — structured knowledge bases with YAML frontmatter, auto-generated indexes, and cross-link support.
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
Requires Python 3.11+ and `uv`:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
uv tool install okf-cli
|
|
21
|
+
okf --version
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Upgrade:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
uv tool upgrade okf-cli
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## CLI overview
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
okf [OPTIONS] COMMAND [ARGS]...
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Global options:
|
|
37
|
+
|
|
38
|
+
| Option | Description |
|
|
39
|
+
| ---------------------- | ---------------------------------------- |
|
|
40
|
+
| `--version` | Show version and exit |
|
|
41
|
+
| `--install-completion` | Install completion for the current shell |
|
|
42
|
+
| `--show-completion` | Print completion script to copy |
|
|
43
|
+
| `--help` | Show help |
|
|
44
|
+
|
|
45
|
+
## Commands
|
|
46
|
+
|
|
47
|
+
### `okf bundle`
|
|
48
|
+
|
|
49
|
+
Convert a directory of plain markdown into an OKF bundle.
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
okf bundle <input-dir> [output-dir] [OPTIONS]
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Arguments:
|
|
56
|
+
|
|
57
|
+
| Argument | Description |
|
|
58
|
+
| ------------ | -------------------------------------------------------- |
|
|
59
|
+
| `input-dir` | Source directory of plain markdown files |
|
|
60
|
+
| `output-dir` | Target directory (default: `<input-dir>_knowledge_base`) |
|
|
61
|
+
|
|
62
|
+
Options:
|
|
63
|
+
|
|
64
|
+
| Option | Description |
|
|
65
|
+
| ----------------------- | ----------------------------------------------------------------- |
|
|
66
|
+
| `--default-type <type>` | Concept type for root-level files (default: input directory name) |
|
|
67
|
+
| `--force`, `-f` | Overwrite output directory if it exists |
|
|
68
|
+
| `--strict` | Fail on broken local `.md` links and skip `AGENTS.md` generation |
|
|
69
|
+
|
|
70
|
+
Examples:
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
okf bundle my-docs --default-type reference
|
|
74
|
+
okf bundle my-docs out --default-type reference --force
|
|
75
|
+
okf bundle my-docs --default-type reference --strict
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Behavior:
|
|
79
|
+
|
|
80
|
+
- Skips `index.md`, `log.md`, `README.md` during input scanning.
|
|
81
|
+
- Reads `.okfignore` in the input root for exact bundle-relative paths to skip.
|
|
82
|
+
- Generates `index.md` in every directory containing concepts or subdirectories.
|
|
83
|
+
- Generates `AGENTS.md` at bundle root with navigation guidance (skipped with `--strict`).
|
|
84
|
+
- Warns about broken local `.md` links; `--strict` turns warnings into fatal errors.
|
|
85
|
+
|
|
86
|
+
### `okf validate`
|
|
87
|
+
|
|
88
|
+
Check whether a directory conforms to the OKF specification.
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
okf validate <directory>
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Reports errors and warnings per file. Exits non-zero on conformance failures.
|
|
95
|
+
|
|
96
|
+
### `okf list`
|
|
97
|
+
|
|
98
|
+
List all concept IDs in a conformant OKF bundle.
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
okf list <directory>
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Concept IDs are bundle-relative paths without the `.md` suffix, e.g. `tables/orders`.
|
|
105
|
+
|
|
106
|
+
### `okf read`
|
|
107
|
+
|
|
108
|
+
Print a concept's full contents by concept ID.
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
okf read <directory> <concept-id>
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Example:
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
okf read my-docs_knowledge_base tables/orders
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## Plain markdown input format
|
|
121
|
+
|
|
122
|
+
Best-quality input uses strict shape:
|
|
123
|
+
|
|
124
|
+
```markdown
|
|
125
|
+
# Clear Concept Title
|
|
126
|
+
|
|
127
|
+
> One-sentence summary of this concept.
|
|
128
|
+
|
|
129
|
+
Body content with useful context, structure, examples, or schema.
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Lenient fallback exists for imperfect files, but metadata quality may be lower.
|
|
133
|
+
|
|
134
|
+
Rules:
|
|
135
|
+
|
|
136
|
+
- First line: `# Title`
|
|
137
|
+
- Next block: `>` description (concise, factual)
|
|
138
|
+
- Directory name becomes the concept `type`: `tables/orders.md` → type `tables`
|
|
139
|
+
- Root-level files use `--default-type`, or the input directory name if omitted
|
|
140
|
+
- Do not add frontmatter to source files — `okf bundle` generates it
|
|
141
|
+
- Avoid creating `index.md`, `log.md`, or `README.md` as source concepts (reserved)
|
|
142
|
+
|
|
143
|
+
## Typical workflow
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
# 1. Bundle
|
|
147
|
+
okf bundle my-notes --default-type reference --force
|
|
148
|
+
|
|
149
|
+
# 2. Validate
|
|
150
|
+
okf validate my-notes_knowledge_base
|
|
151
|
+
|
|
152
|
+
# 3. Explore
|
|
153
|
+
okf list my-notes_knowledge_base
|
|
154
|
+
okf read my-notes_knowledge_base some/concept
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
## `.okfignore`
|
|
158
|
+
|
|
159
|
+
Place in the input root to exclude markdown files. Syntax:
|
|
160
|
+
|
|
161
|
+
```text
|
|
162
|
+
# comments and blank lines allowed
|
|
163
|
+
private-notes.md
|
|
164
|
+
drafts/old-post.md
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
Entries are exact bundle-relative paths. No glob or negation support.
|
|
168
|
+
|
|
169
|
+
## Reserved filenames
|
|
170
|
+
|
|
171
|
+
These files are never treated as concepts:
|
|
172
|
+
|
|
173
|
+
- `index.md` — generated directory listings
|
|
174
|
+
- `log.md` — changelog / activity log
|
|
175
|
+
- `agents.md` — agent navigation guidance (generated)
|
|
176
|
+
- `README.md` — skipped only during bundling input
|
|
177
|
+
|
|
178
|
+
## Strict mode
|
|
179
|
+
|
|
180
|
+
Use `--strict` when you want:
|
|
181
|
+
|
|
182
|
+
- Broken local `.md` links to fail the bundle
|
|
183
|
+
- No `AGENTS.md` generated
|
|
184
|
+
|
|
185
|
+
Example:
|
|
186
|
+
|
|
187
|
+
```bash
|
|
188
|
+
okf bundle my-docs --default-type reference --strict
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
## Tips
|
|
192
|
+
|
|
193
|
+
- Always run `okf validate` before consuming a bundle with `list` or `read`; those commands refuse non-conformant bundles.
|
|
194
|
+
- Use `--force` when regenerating bundles; output directories are not overwritten by default.
|
|
195
|
+
- Root-level markdown files get their `type` from the input directory name unless `--default-type` is set.
|
|
196
|
+
- Subdirectory markdown files get their `type` from the subdirectory name.
|
|
@@ -265,6 +265,7 @@ def bundle(
|
|
|
265
265
|
default_type: str | None = None,
|
|
266
266
|
force: bool = False,
|
|
267
267
|
strict: bool = False,
|
|
268
|
+
dry_run: bool = False,
|
|
268
269
|
) -> BundleResult:
|
|
269
270
|
"""Convert plain markdown into an OKF-conformant knowledge bundle.
|
|
270
271
|
|
|
@@ -275,6 +276,8 @@ def bundle(
|
|
|
275
276
|
force: Overwrite output directory if it exists.
|
|
276
277
|
strict: Enforce strict OKF spec output: fail on broken local .md
|
|
277
278
|
links and skip AGENTS.md generation.
|
|
279
|
+
dry_run: Validate and report what would be written without creating
|
|
280
|
+
or modifying any files or directories.
|
|
278
281
|
|
|
279
282
|
Returns:
|
|
280
283
|
BundleResult with counts, warnings, and errors.
|
|
@@ -294,12 +297,14 @@ def bundle(
|
|
|
294
297
|
raise ValueError("Input and output directories must be different")
|
|
295
298
|
|
|
296
299
|
if dst.exists():
|
|
297
|
-
if not force:
|
|
300
|
+
if not dry_run and not force:
|
|
298
301
|
raise FileExistsError(
|
|
299
302
|
f"Output directory '{dst}' exists. Use --force to overwrite."
|
|
300
303
|
)
|
|
301
|
-
|
|
302
|
-
|
|
304
|
+
if force:
|
|
305
|
+
if not dry_run:
|
|
306
|
+
shutil.rmtree(dst)
|
|
307
|
+
warnings.append(f"Removed existing '{dst}'")
|
|
303
308
|
|
|
304
309
|
try:
|
|
305
310
|
ignored = _load_okfignore(src)
|
|
@@ -372,7 +377,6 @@ def bundle(
|
|
|
372
377
|
for f in md_files:
|
|
373
378
|
rel = f.relative_to(src)
|
|
374
379
|
out_file = dst / rel
|
|
375
|
-
out_file.parent.mkdir(parents=True, exist_ok=True)
|
|
376
380
|
|
|
377
381
|
if rel.parent == Path("."):
|
|
378
382
|
type_name = default_type or src.name
|
|
@@ -383,19 +387,22 @@ def bundle(
|
|
|
383
387
|
title, description, body = parse_md(text)
|
|
384
388
|
ts = datetime.fromtimestamp(f.stat().st_mtime, tz=UTC).isoformat()
|
|
385
389
|
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
390
|
+
if not dry_run:
|
|
391
|
+
out_file.parent.mkdir(parents=True, exist_ok=True)
|
|
392
|
+
try:
|
|
393
|
+
_write_concept(title, description, body, out_file, type_name, ts)
|
|
394
|
+
except ValueError as e:
|
|
395
|
+
errors.append(f"{rel}: {e}")
|
|
396
|
+
return BundleResult(len(processed), dst, warnings, errors)
|
|
391
397
|
processed.append(
|
|
392
398
|
(rel, {"title": title, "description": description, "type": type_name})
|
|
393
399
|
)
|
|
394
400
|
|
|
395
|
-
|
|
401
|
+
if not dry_run:
|
|
402
|
+
_generate_indexes(processed, dst)
|
|
396
403
|
|
|
397
404
|
# Write AGENTS.md (skipped in strict mode)
|
|
398
|
-
if not strict:
|
|
405
|
+
if not dry_run and not strict:
|
|
399
406
|
(dst / "AGENTS.md").write_text(
|
|
400
407
|
f"# Knowledge Base: {dst.name}\n\n"
|
|
401
408
|
f"You are in an OKF (Open Knowledge Format) knowledge base called "
|
|
@@ -494,9 +501,7 @@ def show_concept(bundle_dir: str | Path, concept_id: str) -> ConceptContent:
|
|
|
494
501
|
raise ValueError(f"'{concept_id}' is a reserved filename, not a concept")
|
|
495
502
|
|
|
496
503
|
if not concept_path.is_file():
|
|
497
|
-
raise FileNotFoundError(
|
|
498
|
-
f"Concept '{concept_id}' not found"
|
|
499
|
-
)
|
|
504
|
+
raise FileNotFoundError(f"Concept '{concept_id}' not found")
|
|
500
505
|
|
|
501
506
|
raw = concept_path.read_text(encoding="utf-8")
|
|
502
507
|
fm = parse_frontmatter(raw)
|
|
@@ -29,6 +29,11 @@ def bundle(
|
|
|
29
29
|
"and skip AGENTS.md generation"
|
|
30
30
|
),
|
|
31
31
|
),
|
|
32
|
+
dry_run: bool = typer.Option(
|
|
33
|
+
False,
|
|
34
|
+
"--dry-run",
|
|
35
|
+
help="Validate and show warnings without writing any files",
|
|
36
|
+
),
|
|
32
37
|
) -> None:
|
|
33
38
|
"""Convert plain markdown into an OKF-conformant knowledge bundle."""
|
|
34
39
|
try:
|
|
@@ -38,6 +43,7 @@ def bundle(
|
|
|
38
43
|
default_type=default_type,
|
|
39
44
|
force=force,
|
|
40
45
|
strict=strict,
|
|
46
|
+
dry_run=dry_run,
|
|
41
47
|
)
|
|
42
48
|
except FileNotFoundError as e:
|
|
43
49
|
err_console.print(f"Error: {e}", style="red")
|
|
@@ -58,7 +64,13 @@ def bundle(
|
|
|
58
64
|
raise typer.Exit(code=1)
|
|
59
65
|
|
|
60
66
|
n = result.files_written
|
|
67
|
+
if dry_run:
|
|
68
|
+
verb = "Would convert"
|
|
69
|
+
prefix = "Dry run."
|
|
70
|
+
else:
|
|
71
|
+
verb = "Converted"
|
|
72
|
+
prefix = "Done."
|
|
61
73
|
console.print(
|
|
62
|
-
f"
|
|
74
|
+
f"{prefix} {verb} {n} file{'s' if n != 1 else ''} → {result.output_dir}",
|
|
63
75
|
style="green",
|
|
64
76
|
)
|
|
@@ -26,4 +26,7 @@ def cmd_read(
|
|
|
26
26
|
err_console.print(f"Error: {e}", style="red")
|
|
27
27
|
raise typer.Exit(code=1)
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
raw = result.raw
|
|
30
|
+
if not raw.endswith("\n"):
|
|
31
|
+
raw += "\n"
|
|
32
|
+
console.print(raw, end="", markup=False, highlight=False)
|
|
@@ -458,6 +458,84 @@ class TestBundle:
|
|
|
458
458
|
assert "[bad](bad.md)" in index
|
|
459
459
|
assert "[](" not in index
|
|
460
460
|
|
|
461
|
+
def test_dry_run_no_writes(self, tmp_path: Path):
|
|
462
|
+
src = tmp_path / "src"
|
|
463
|
+
dst = tmp_path / "out"
|
|
464
|
+
src.mkdir()
|
|
465
|
+
_write(
|
|
466
|
+
src,
|
|
467
|
+
{
|
|
468
|
+
"tables/orders.md": "# Orders\n\n> One row.\n\nBody.",
|
|
469
|
+
"tables/customers.md": "# Customers\n\n> All.\n\nBody.",
|
|
470
|
+
},
|
|
471
|
+
)
|
|
472
|
+
|
|
473
|
+
result = bundle(src, dst, dry_run=True)
|
|
474
|
+
|
|
475
|
+
assert result.files_written == 2
|
|
476
|
+
assert result.errors == []
|
|
477
|
+
assert not dst.exists()
|
|
478
|
+
|
|
479
|
+
def test_dry_run_reports_warnings(self, tmp_path: Path):
|
|
480
|
+
src = tmp_path / "src"
|
|
481
|
+
dst = tmp_path / "out"
|
|
482
|
+
src.mkdir()
|
|
483
|
+
_write(
|
|
484
|
+
src,
|
|
485
|
+
{"tables/orders.md": "# Orders\n\n> One row.\n\nSee [C](customers.md)."},
|
|
486
|
+
)
|
|
487
|
+
|
|
488
|
+
result = bundle(src, dst, dry_run=True)
|
|
489
|
+
|
|
490
|
+
assert result.files_written == 1
|
|
491
|
+
assert any("not found in bundle" in w for w in result.warnings)
|
|
492
|
+
assert not dst.exists()
|
|
493
|
+
|
|
494
|
+
def test_dry_run_force_does_not_delete_existing(self, tmp_path: Path):
|
|
495
|
+
src = tmp_path / "src"
|
|
496
|
+
dst = tmp_path / "out"
|
|
497
|
+
src.mkdir()
|
|
498
|
+
dst.mkdir()
|
|
499
|
+
(dst / "old.txt").write_text("preserve me")
|
|
500
|
+
_write(src, {"tables/a.md": "# A\n\n> Desc.\n"})
|
|
501
|
+
|
|
502
|
+
result = bundle(src, dst, force=True, dry_run=True)
|
|
503
|
+
|
|
504
|
+
assert result.files_written == 1
|
|
505
|
+
assert any("Removed existing" in w for w in result.warnings)
|
|
506
|
+
assert (dst / "old.txt").exists()
|
|
507
|
+
assert (dst / "old.txt").read_text() == "preserve me"
|
|
508
|
+
|
|
509
|
+
def test_dry_run_no_force_when_output_exists(self, tmp_path: Path):
|
|
510
|
+
src = tmp_path / "src"
|
|
511
|
+
dst = tmp_path / "out"
|
|
512
|
+
src.mkdir()
|
|
513
|
+
dst.mkdir()
|
|
514
|
+
(dst / "old.txt").write_text("preserve me")
|
|
515
|
+
_write(src, {"tables/a.md": "# A\n\n> Desc.\n"})
|
|
516
|
+
|
|
517
|
+
result = bundle(src, dst, dry_run=True)
|
|
518
|
+
|
|
519
|
+
assert result.files_written == 1
|
|
520
|
+
assert result.errors == []
|
|
521
|
+
assert not any("Removed existing" in w for w in result.warnings)
|
|
522
|
+
assert (dst / "old.txt").exists()
|
|
523
|
+
|
|
524
|
+
def test_dry_run_strict_still_fails(self, tmp_path: Path):
|
|
525
|
+
src = tmp_path / "src"
|
|
526
|
+
dst = tmp_path / "out"
|
|
527
|
+
src.mkdir()
|
|
528
|
+
_write(
|
|
529
|
+
src,
|
|
530
|
+
{"tables/orders.md": "# Orders\n\n> One row.\n\nSee [C](customers.md)."},
|
|
531
|
+
)
|
|
532
|
+
|
|
533
|
+
result = bundle(src, dst, strict=True, dry_run=True)
|
|
534
|
+
|
|
535
|
+
assert result.files_written == 0
|
|
536
|
+
assert any("strict link check failed" in e.lower() for e in result.errors)
|
|
537
|
+
assert not dst.exists()
|
|
538
|
+
|
|
461
539
|
|
|
462
540
|
# ---------------------------------------------------------------------------
|
|
463
541
|
# list_concepts()
|
|
@@ -87,6 +87,64 @@ def test_bundle_strict_shows_error(tmp_path: Path):
|
|
|
87
87
|
assert not (dst / "AGENTS.md").exists()
|
|
88
88
|
|
|
89
89
|
|
|
90
|
+
def test_bundle_dry_run_no_writes(tmp_path: Path):
|
|
91
|
+
src = tmp_path / "src"
|
|
92
|
+
dst = tmp_path / "out"
|
|
93
|
+
src.mkdir()
|
|
94
|
+
_write(src, {"tables/a.md": "# A\n\n> Desc.\n"})
|
|
95
|
+
|
|
96
|
+
result = runner.invoke(app, ["bundle", str(src), str(dst), "--dry-run"])
|
|
97
|
+
assert result.exit_code == 0
|
|
98
|
+
assert "Dry run" in result.output
|
|
99
|
+
assert "Would convert" in result.output
|
|
100
|
+
assert not dst.exists()
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def test_bundle_dry_run_existing_output_no_force(tmp_path: Path):
|
|
104
|
+
src = tmp_path / "src"
|
|
105
|
+
dst = tmp_path / "out"
|
|
106
|
+
src.mkdir()
|
|
107
|
+
dst.mkdir()
|
|
108
|
+
_write(src, {"tables/a.md": "# A\n\n> Desc.\n"})
|
|
109
|
+
|
|
110
|
+
result = runner.invoke(app, ["bundle", str(src), str(dst), "--dry-run"])
|
|
111
|
+
assert result.exit_code == 0
|
|
112
|
+
assert "Dry run" in result.output
|
|
113
|
+
assert "--force" not in result.output
|
|
114
|
+
assert dst.exists()
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def test_bundle_dry_run_shows_warnings(tmp_path: Path):
|
|
118
|
+
src = tmp_path / "src"
|
|
119
|
+
dst = tmp_path / "out"
|
|
120
|
+
src.mkdir()
|
|
121
|
+
_write(
|
|
122
|
+
src,
|
|
123
|
+
{"tables/orders.md": "# Orders\n\n> One row.\n\nSee [C](customers.md)."},
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
result = runner.invoke(app, ["bundle", str(src), str(dst), "--dry-run"])
|
|
127
|
+
assert result.exit_code == 0
|
|
128
|
+
normalized = " ".join(result.output.split())
|
|
129
|
+
assert "not found in bundle" in normalized
|
|
130
|
+
assert not dst.exists()
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def test_bundle_dry_run_strict_exits_on_error(tmp_path: Path):
|
|
134
|
+
src = tmp_path / "src"
|
|
135
|
+
dst = tmp_path / "out"
|
|
136
|
+
src.mkdir()
|
|
137
|
+
_write(
|
|
138
|
+
src,
|
|
139
|
+
{"tables/orders.md": "# Orders\n\n> One row.\n\nSee [C](customers.md)."},
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
result = runner.invoke(app, ["bundle", str(src), str(dst), "--dry-run", "--strict"])
|
|
143
|
+
assert result.exit_code == 1
|
|
144
|
+
assert "strict link check failed" in result.output
|
|
145
|
+
assert not dst.exists()
|
|
146
|
+
|
|
147
|
+
|
|
90
148
|
# ---------------------------------------------------------------------------
|
|
91
149
|
# validate — exit codes & error messages
|
|
92
150
|
# ---------------------------------------------------------------------------
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: okf-cli-manual
|
|
3
|
-
description: Install and use okf-cli to convert plain markdown into OKF-conformant knowledge bundles, list concept IDs, inspect concepts, and validate bundles. Use when the user asks to "bundle markdown", "create OKF bundle", "validate OKF", "list concepts", or work with okf-cli.
|
|
4
|
-
license: MIT
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
# okf-cli Manual
|
|
8
|
-
|
|
9
|
-
Install and use okf-cli for working with Open Knowledge Format (OKF)
|
|
10
|
-
|
|
11
|
-
## Install
|
|
12
|
-
|
|
13
|
-
```bash
|
|
14
|
-
uv tool install okf-cli
|
|
15
|
-
okf --version
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
Upgrade:
|
|
19
|
-
|
|
20
|
-
```bash
|
|
21
|
-
uv tool upgrade okf-cli
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
## Commands
|
|
25
|
-
|
|
26
|
-
### `okf bundle` — convert plain markdown to OKF bundle
|
|
27
|
-
|
|
28
|
-
```
|
|
29
|
-
okf bundle <input-dir> [output-dir] [--default-type <type>] [--force] [--strict-links]
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
| Argument | Description |
|
|
33
|
-
| ---------------- | ---------------------------------------------------------------------------- |
|
|
34
|
-
| `input-dir` | Directory of plain `.md` files |
|
|
35
|
-
| `output-dir` | Target directory (default: `bundled`) |
|
|
36
|
-
| `--default-type` | Type for root-level files — skip root files if omitted |
|
|
37
|
-
| `--force`, `-f` | Overwrite output directory if it exists |
|
|
38
|
-
| `--strict-links` | Fail if local markdown links point outside bundle or to missing `.md` target |
|
|
39
|
-
|
|
40
|
-
```bash
|
|
41
|
-
okf bundle my-docs bundled --default-type reference
|
|
42
|
-
okf bundle my-docs bundled --default-type reference --force
|
|
43
|
-
okf bundle my-docs bundled --default-type reference --strict-links
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
`.okfignore` — place in `input-dir` root, one bundle-relative path per line:
|
|
47
|
-
|
|
48
|
-
```
|
|
49
|
-
# skip these files
|
|
50
|
-
smoke-ignore.md
|
|
51
|
-
tables/orders.md
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
### `okf list` — list concept IDs in a bundle
|
|
55
|
-
|
|
56
|
-
```
|
|
57
|
-
okf list <directory>
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
Prints concept IDs (path with `.md` stripped). Reserved files (`index.md`, `log.md`) excluded.
|
|
61
|
-
|
|
62
|
-
```bash
|
|
63
|
-
okf list bundled/
|
|
64
|
-
# datasets/sales
|
|
65
|
-
# tables/orders
|
|
66
|
-
# tables/customers
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
### `okf show` — print a concept by ID
|
|
70
|
-
|
|
71
|
-
```
|
|
72
|
-
okf show <directory> <concept-id>
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
```bash
|
|
76
|
-
okf show bundled/ tables/orders
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
### `okf validate` — check OKF conformance
|
|
80
|
-
|
|
81
|
-
```
|
|
82
|
-
okf validate <directory>
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
Validates per OKF §9: frontmatter present, `type` non-empty, reserved filenames follow structure.
|
|
86
|
-
|
|
87
|
-
```bash
|
|
88
|
-
okf validate bundled/
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
## Input format for `bundle`
|
|
92
|
-
|
|
93
|
-
Each `.md` file should follow this structure:
|
|
94
|
-
|
|
95
|
-
```markdown
|
|
96
|
-
# Clear Concept Title
|
|
97
|
-
|
|
98
|
-
> One-sentence summary of this concept.
|
|
99
|
-
|
|
100
|
-
Body content with useful context, structure, examples, or schema.
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
Rules:
|
|
104
|
-
|
|
105
|
-
- First line: `# Title`
|
|
106
|
-
- Second block: `>` description (concise, factual)
|
|
107
|
-
- Directory name becomes the concept `type`: `tables/orders.md` → type `tables`
|
|
108
|
-
- Root-level files require `--default-type`
|
|
109
|
-
- Do not add frontmatter to source files — `okf bundle` generates it
|
|
110
|
-
- Avoid creating `index.md`, `log.md`, or `README.md` as source concepts (reserved by spec)
|
|
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
|
|
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
|