okf-cli 0.5.3__tar.gz → 0.5.5__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.
Files changed (48) hide show
  1. {okf_cli-0.5.3 → okf_cli-0.5.5}/.github/workflows/test.yml +2 -0
  2. okf_cli-0.5.5/.last-update.json +1 -0
  3. {okf_cli-0.5.3 → okf_cli-0.5.5}/AGENTS.md +2 -2
  4. {okf_cli-0.5.3 → okf_cli-0.5.5}/PKG-INFO +10 -6
  5. {okf_cli-0.5.3 → okf_cli-0.5.5}/README.md +9 -5
  6. {okf_cli-0.5.3 → okf_cli-0.5.5}/openwiki/architecture.md +16 -12
  7. {okf_cli-0.5.3 → okf_cli-0.5.5}/openwiki/testing.md +6 -4
  8. {okf_cli-0.5.3 → okf_cli-0.5.5}/openwiki/workflows.md +5 -4
  9. {okf_cli-0.5.3 → okf_cli-0.5.5}/pyproject.toml +1 -1
  10. {okf_cli-0.5.3 → okf_cli-0.5.5}/src/okf/api.py +54 -14
  11. {okf_cli-0.5.3 → okf_cli-0.5.5}/src/okf/commands/bundle.py +2 -2
  12. okf_cli-0.5.5/src/okf/commands/list.py +39 -0
  13. {okf_cli-0.5.3 → okf_cli-0.5.5}/src/okf/commands/validate.py +4 -3
  14. {okf_cli-0.5.3 → okf_cli-0.5.5}/tests/test_api.py +116 -0
  15. {okf_cli-0.5.3 → okf_cli-0.5.5}/tests/test_cli.py +52 -0
  16. {okf_cli-0.5.3 → okf_cli-0.5.5}/uv.lock +1 -1
  17. okf_cli-0.5.3/.last-update.json +0 -4
  18. okf_cli-0.5.3/src/okf/commands/list.py +0 -24
  19. {okf_cli-0.5.3 → okf_cli-0.5.5}/.gitignore +0 -0
  20. {okf_cli-0.5.3 → okf_cli-0.5.5}/LICENSE +0 -0
  21. {okf_cli-0.5.3 → okf_cli-0.5.5}/OKF_SPEC.md +0 -0
  22. {okf_cli-0.5.3 → okf_cli-0.5.5}/example/.okfignore +0 -0
  23. {okf_cli-0.5.3 → okf_cli-0.5.5}/example/README.md +0 -0
  24. {okf_cli-0.5.3 → okf_cli-0.5.5}/example/blank-line/no-blank.md +0 -0
  25. {okf_cli-0.5.3 → okf_cli-0.5.5}/example/blank-line/with-blank.md +0 -0
  26. {okf_cli-0.5.3 → okf_cli-0.5.5}/example/datasets/sales.md +0 -0
  27. {okf_cli-0.5.3 → okf_cli-0.5.5}/example/domain.md +0 -0
  28. {okf_cli-0.5.3 → okf_cli-0.5.5}/example/loose/deep/no-heading.md +0 -0
  29. {okf_cli-0.5.3 → okf_cli-0.5.5}/example/loose/no-desc.md +0 -0
  30. {okf_cli-0.5.3 → okf_cli-0.5.5}/example/loose/no-title.md +0 -0
  31. {okf_cli-0.5.3 → okf_cli-0.5.5}/example/playbooks/incident-response.md +0 -0
  32. {okf_cli-0.5.3 → okf_cli-0.5.5}/example/playbooks/oncall-guide.md +0 -0
  33. {okf_cli-0.5.3 → okf_cli-0.5.5}/example/smoke-ignore.md +0 -0
  34. {okf_cli-0.5.3 → okf_cli-0.5.5}/example/tables/customers.md +0 -0
  35. {okf_cli-0.5.3 → okf_cli-0.5.5}/example/tables/orders.md +0 -0
  36. {okf_cli-0.5.3 → okf_cli-0.5.5}/example/tables/partitions/2026/q1/jan/january.md +0 -0
  37. {okf_cli-0.5.3 → okf_cli-0.5.5}/example/tables/partitions/daily.md +0 -0
  38. {okf_cli-0.5.3 → okf_cli-0.5.5}/openwiki/domain-model.md +0 -0
  39. {okf_cli-0.5.3 → okf_cli-0.5.5}/openwiki/operations.md +0 -0
  40. {okf_cli-0.5.3 → okf_cli-0.5.5}/openwiki/quickstart.md +0 -0
  41. {okf_cli-0.5.3 → okf_cli-0.5.5}/skills/okf-cli/SKILL.md +0 -0
  42. {okf_cli-0.5.3 → okf_cli-0.5.5}/skills/writing-knowledge-base/SKILL.md +0 -0
  43. {okf_cli-0.5.3 → okf_cli-0.5.5}/src/okf/__init__.py +0 -0
  44. {okf_cli-0.5.3 → okf_cli-0.5.5}/src/okf/cli.py +0 -0
  45. {okf_cli-0.5.3 → okf_cli-0.5.5}/src/okf/commands/__init__.py +0 -0
  46. {okf_cli-0.5.3 → okf_cli-0.5.5}/src/okf/commands/read.py +0 -0
  47. {okf_cli-0.5.3 → okf_cli-0.5.5}/src/okf/core.py +0 -0
  48. {okf_cli-0.5.3 → okf_cli-0.5.5}/tests/test_core.py +0 -0
@@ -14,4 +14,6 @@ jobs:
14
14
  with:
15
15
  python-version: ${{ matrix.python-version }}
16
16
  - run: uv sync
17
+ - run: uvx ruff check .
18
+ - run: uvx ruff format --check .
17
19
  - run: uv run pytest -q
@@ -0,0 +1 @@
1
+ {"head": "661f7ac9042711e133fd4c8fe4e806e1f2d81b13", "timestamp": "2026-07-26T08:13:49Z"}
@@ -44,7 +44,7 @@ okf-cli
44
44
  │ ├── core.py # shared parsing/formatting/conformance
45
45
  │ └── commands/
46
46
  │ ├── bundle.py # thin wrapper → api.bundle()
47
- │ ├── list.py # thin wrapper → api.list_concepts()
47
+ │ ├── list.py # thin wrapper → api.list_entries()
48
48
  │ ├── read.py # thin wrapper → api.show_concept()
49
49
  │ └── validate.py # thin wrapper → api.validate()
50
50
  └── tests/
@@ -72,7 +72,7 @@ uv run okf validate bundled
72
72
 
73
73
  ### Modify conformance behavior
74
74
 
75
- Update `check_conformance()` in `src/okf/core.py`, then ensure `validate`, `list`, and `show` all behave consistently.
75
+ Update `check_conformance()` in `src/okf/core.py`, then ensure `validate`, `list`, and `read` all behave consistently.
76
76
 
77
77
  ## Style guidelines
78
78
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: okf-cli
3
- Version: 0.5.3
3
+ Version: 0.5.5
4
4
  Summary: Open Knowledge Format tooling
5
5
  License: MIT License
6
6
 
@@ -34,7 +34,7 @@ Description-Content-Type: text/markdown
34
34
 
35
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.
36
36
 
37
- Also validates bundles, lists concept IDs, reads concepts by ID, and reports version.
37
+ Also validates bundles, lists concepts, reads concepts by ID, and reports version.
38
38
 
39
39
  ## Install
40
40
 
@@ -77,18 +77,22 @@ okf bundle example bundled --default-type reference --force --strict
77
77
 
78
78
  **Link checking**: scans body links to local `.md` targets. Missing or out-of-bundle links warn by default, fail with `--strict`.
79
79
 
80
- ### `okf list` — list concept IDs in a bundle
80
+ ### `okf list` — list concepts in a bundle
81
81
 
82
82
  ```
83
83
  okf list <directory>
84
84
  ```
85
85
 
86
- Prints concept IDs (path without `.md`). Requires valid OKF bundle.
86
+ Prints a table of concepts with ID, type, title, and description. Requires valid OKF bundle.
87
87
 
88
88
  ```bash
89
89
  okf list example_knowledge_base/
90
- # datasets/sales
91
- # tables/orders
90
+ # ┏━━━━━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━┓
91
+ # ┃ ID ┃ Type ┃ Title ┃ Description ┃
92
+ # ┡━━━━━━━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━┩
93
+ # │ datasets/sales │ datasets │ Sales │ Sales data. │
94
+ # │ tables/orders │ tables │ Orders │ One row. │
95
+ # └────────────────┴──────────┴────────┴─────────────┘
92
96
  ```
93
97
 
94
98
  ### `okf read` — read a concept by ID
@@ -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, reads concepts by ID, and reports version.
5
+ Also validates bundles, lists concepts, reads concepts by ID, and reports version.
6
6
 
7
7
  ## Install
8
8
 
@@ -45,18 +45,22 @@ okf bundle example bundled --default-type reference --force --strict
45
45
 
46
46
  **Link checking**: scans body links to local `.md` targets. Missing or out-of-bundle links warn by default, fail with `--strict`.
47
47
 
48
- ### `okf list` — list concept IDs in a bundle
48
+ ### `okf list` — list concepts in a bundle
49
49
 
50
50
  ```
51
51
  okf list <directory>
52
52
  ```
53
53
 
54
- Prints concept IDs (path without `.md`). Requires valid OKF bundle.
54
+ Prints a table of concepts with ID, type, title, and description. Requires valid OKF bundle.
55
55
 
56
56
  ```bash
57
57
  okf list example_knowledge_base/
58
- # datasets/sales
59
- # tables/orders
58
+ # ┏━━━━━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━┓
59
+ # ┃ ID ┃ Type ┃ Title ┃ Description ┃
60
+ # ┡━━━━━━━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━┩
61
+ # │ datasets/sales │ datasets │ Sales │ Sales data. │
62
+ # │ tables/orders │ tables │ Orders │ One row. │
63
+ # └────────────────┴──────────┴────────┴─────────────┘
60
64
  ```
61
65
 
62
66
  ### `okf read` — read a concept by ID
@@ -17,14 +17,15 @@ Why this split: the API layer is the canonical home for all logic. Commands hand
17
17
 
18
18
  Public functions and return types:
19
19
 
20
- | Function | Returns | Key behavior |
21
- | ---------------------------------------------- | ---------------- | ----------------------------------------------------------------------------- |
22
- | `bundle(input_dir, output_dir, ...)` | `BundleResult` | Full bundle pipeline with link checking, `.okfignore`, `AGENTS.md` generation |
23
- | `convert_file(input_file, output_file, type_)` | `BundleResult` | Convert single markdown file to OKF concept (timestamp from mtime) |
24
- | `convert_content(content, output_file, type_)` | `BundleResult` | Convert raw markdown string to OKF concept (no timestamp) |
25
- | `list_concepts(bundle_dir)` | `list[str]` | Conformance-gated concept ID listing |
26
- | `show_concept(bundle_dir, concept_id)` | `ConceptContent` | Conformance-gated concept read with path traversal guard |
27
- | `validate(bundle_dir)` | `ValidateResult` | Conformance check with `.ok` property |
20
+ | Function | Returns | Key behavior |
21
+ | ------------------------------------------------------------------------ | ---------------- | ------------------------------------------------------------------------------------------------------------------------------ |
22
+ | `bundle(input_dir, output_dir, *, default_type, force, strict, dry_run)` | `BundleResult` | Full bundle pipeline with link checking, `.okfignore`, `AGENTS.md` generation; `dry_run` validates and reports without writing |
23
+ | `convert_file(input_file, output_file, type_)` | `BundleResult` | Convert single markdown file to OKF concept (timestamp from mtime) |
24
+ | `convert_content(content, output_file, type_)` | `BundleResult` | Convert raw markdown string to OKF concept (no timestamp) |
25
+ | `list_concepts(bundle_dir)` | `list[str]` | Conformance-gated concept ID listing |
26
+ | `list_entries(bundle_dir)` | `list[dict]` | Conformance-gated concept metadata (id, type, title, description) |
27
+ | `show_concept(bundle_dir, concept_id)` | `ConceptContent` | Conformance-gated concept read with path traversal guard |
28
+ | `validate(bundle_dir)` | `ValidateResult` | Conformance check with `.ok` property |
28
29
 
29
30
  Internal helpers (not public API): `_iter_links`, `_resolve_md_target`, `_load_okfignore`, `_generate_indexes`, `_write_concept`.
30
31
 
@@ -48,7 +49,8 @@ Each file imports from `okf.api` and calls the corresponding function, translati
48
49
  1. Read source directory + optional `.okfignore` (`_load_okfignore`).
49
50
  1. Walk `*.md`, skipping reserved names and ignored paths.
50
51
  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` makes these fatal.
52
+ 1. Scan markdown body links via `_iter_links` / `_resolve_md_target` — warns on missing or out-of-bundle targets; `--strict` makes these fatal (even during `--dry-run`).
53
+ 1. If `dry_run=True`, skip all writes: no concept files, no `index.md` files, and no `AGENTS.md`. The result still reports planned `files_written` and any warnings/errors.
52
54
  1. Build YAML frontmatter via `build_frontmatter`.
53
55
  1. Write transformed files and generate `index.md` per directory.
54
56
  1. Write `AGENTS.md` at output root with navigation guidance for the knowledge base (skipped when `--strict` is used).
@@ -59,9 +61,11 @@ Each file imports from `okf.api` and calls the corresponding function, translati
59
61
  1. Call `check_conformance` once.
60
62
  1. Return `ValidateResult` with file count, errors, and warnings.
61
63
 
62
- ### `okf list` and `okf read` (via `api.list_concepts()` / `api.show_concept()`)
64
+ ### `okf list` and `okf read` (via `api.list_entries()` / `api.show_concept()`)
63
65
 
64
- Both functions first run `check_conformance`. If directory is non-conformant, they raise `ValueError`.
66
+ `okf list` renders the metadata returned by `api.list_entries()` as a Rich table (ID, type, title, description). `okf read` looks up a single concept by ID via `api.show_concept()`.
67
+
68
+ Both reading paths first run `check_conformance`. If directory is non-conformant, they raise `ValueError`.
65
69
 
66
70
  Reason: reading APIs should not return misleading data from broken bundles.
67
71
 
@@ -79,7 +83,7 @@ Source: `src/okf/core.py` (constants), `src/okf/api.py` (enforcement).
79
83
 
80
84
  Major behavior shifts:
81
85
 
82
- - project started bundling-focused, then added `validate`/`list`/`show` workflow;
86
+ - project started bundling-focused, then added `validate`/`list`/`read` workflow;
83
87
  - frontmatter parsing/conformance matured to real YAML parsing and shared conformance gating;
84
88
  - markdown parsing in bundling became lenient to tolerate imperfect source docs;
85
89
  - `.okfignore` added to allow selective exclusions without moving/deleting source files;
@@ -5,9 +5,10 @@
5
5
  - API unit/integration tests: `tests/test_api.py`
6
6
  - `TestBundle` — bundling via `api.bundle()`, link checking, `.okfignore`, lenient parsing, `AGENTS.md` generation
7
7
  - `TestListConcepts` — listing via `api.list_concepts()`, reserved file handling
8
+ - `TestListEntries` — listing metadata via `api.list_entries()` (ID, type, title, description)
8
9
  - `TestShowConcept` — reading via `api.show_concept()`, path traversal guard
9
10
  - `TestValidate` — conformance checks via `api.validate()`, all §9 rule variants
10
- - `TestWorkflow` — cross-command pipeline (bundle → validate/list/show)
11
+ - `TestWorkflow` — cross-command pipeline (bundle → validate/list/read)
11
12
  - `TestConvertFile` — single-file conversion via `api.convert_file()`, mtime timestamp
12
13
  - `TestConvertContent` — raw markdown conversion via `api.convert_content()`, no timestamp
13
14
  - Core unit tests: `tests/test_core.py`
@@ -16,7 +17,7 @@
16
17
  - conformance engine (`check_conformance`)
17
18
  - CLI integration tests: `tests/test_cli.py`
18
19
  - exit codes and error message formatting for all commands
19
- - Typer-specific behavior (argument parsing, `--force`, `--strict`)
20
+ - Typer-specific behavior (argument parsing, `--force`, `--strict`, `--dry-run`)
20
21
 
21
22
  ## Run tests
22
23
 
@@ -70,8 +71,9 @@ uv run pytest -q
70
71
  - Lenient parsing fallback when strict markdown format is missing.
71
72
  - Reserved filename differences between bundling and spec conformance.
72
73
  - Root `index.md` special allowance for `okf_version` only.
73
- - `list`/`show` hard failure on non-conformant bundles.
74
- - `show` path traversal guard.
74
+ - `list`/`read` hard failure on non-conformant bundles.
75
+ - `read` path traversal guard.
75
76
  - Link checking: `_resolve_md_target` path resolution, `--strict` fatal mode, missing/out-of-bundle targets.
77
+ - `--dry-run`: no files written, warnings still reported, `--force` does not delete existing output.
76
78
 
77
79
  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] [--dry-run]
23
23
  # output-dir defaults to <input-dir>_knowledge_base
24
24
  # --default-type defaults to input directory name
25
25
  ```
@@ -30,7 +30,8 @@ Important behavior:
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
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).
33
+ - `--dry-run` validates the source and reports warnings/errors without writing files or directories; existing output is left untouched even if `--force` is passed.
34
+ - `AGENTS.md` is generated at output root with navigation guidance (unless `--strict` or `--dry-run` is used).
34
35
 
35
36
  Source: `src/okf/api.py`.
36
37
 
@@ -51,7 +52,7 @@ uv run okf list <output-dir>
51
52
  uv run okf read <output-dir> <concept-id>
52
53
  ```
53
54
 
54
- `list` returns concept IDs; `read` prints full concept markdown.
55
+ `list` prints a table of concepts (ID, type, title, description); `read` prints full concept markdown.
55
56
 
56
57
  ## Contributor workflow
57
58
 
@@ -61,7 +62,7 @@ Start files:
61
62
 
62
63
  - `src/okf/core.py`
63
64
  - `tests/test_core.py`
64
- - `tests/test_api.py` (validate/list/show tests)
65
+ - `tests/test_api.py` (validate/list/read tests)
65
66
 
66
67
  Why: `check_conformance` and parsing helpers are shared dependencies across the API layer.
67
68
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "okf-cli"
3
- version = "0.5.3"
3
+ version = "0.5.5"
4
4
  description = "Open Knowledge Format tooling"
5
5
  readme = "README.md"
6
6
  license = { file = "LICENSE" }
@@ -296,6 +296,13 @@ def bundle(
296
296
  if src.resolve() == dst.resolve():
297
297
  raise ValueError("Input and output directories must be different")
298
298
 
299
+ try:
300
+ dst.resolve().relative_to(src.resolve())
301
+ except ValueError:
302
+ pass
303
+ else:
304
+ raise ValueError("Output directory must not be inside input directory")
305
+
299
306
  if dst.exists():
300
307
  if not dry_run and not force:
301
308
  raise FileExistsError(
@@ -435,6 +442,27 @@ def bundle(
435
442
  )
436
443
 
437
444
 
445
+ def _iter_concept_files(dir_path: Path):
446
+ """Yield (concept_id, file_path) for every concept in a bundle.
447
+
448
+ Validates the directory and conformance before iterating. Skips
449
+ spec-reserved filenames such as ``index.md`` and ``log.md``.
450
+ """
451
+ if not dir_path.is_dir():
452
+ raise NotADirectoryError(f"'{dir_path}' is not a directory")
453
+
454
+ errors, _warnings = check_conformance(dir_path)
455
+ if errors:
456
+ raise ValueError("not an OKF-conformant bundle:\n" + "\n".join(errors))
457
+
458
+ for f in sorted(dir_path.rglob("*.md")):
459
+ if f.name.lower() in SPEC_RESERVED:
460
+ continue
461
+ rel = f.relative_to(dir_path)
462
+ cid = str(rel.parent / rel.stem) if rel.parent != Path(".") else rel.stem
463
+ yield cid, f
464
+
465
+
438
466
  def list_concepts(bundle_dir: str | Path) -> list[str]:
439
467
  """List all concept IDs in an OKF-conformant bundle.
440
468
 
@@ -447,24 +475,36 @@ def list_concepts(bundle_dir: str | Path) -> list[str]:
447
475
  Raises:
448
476
  ValueError: If the directory is not a valid OKF bundle.
449
477
  """
450
- dir_path = Path(bundle_dir)
478
+ return [cid for cid, _f in _iter_concept_files(Path(bundle_dir))]
451
479
 
452
- if not dir_path.is_dir():
453
- raise NotADirectoryError(f"'{dir_path}' is not a directory")
454
480
 
455
- errors, _warnings = check_conformance(dir_path)
456
- if errors:
457
- raise ValueError("not an OKF-conformant bundle:\n" + "\n".join(errors))
481
+ def list_entries(bundle_dir: str | Path) -> list[dict[str, str]]:
482
+ """List all concepts with their frontmatter metadata.
458
483
 
459
- cids: list[str] = []
460
- for f in sorted(dir_path.rglob("*.md")):
461
- if f.name.lower() in SPEC_RESERVED:
462
- continue
463
- rel = f.relative_to(dir_path)
464
- cid = str(rel.parent / rel.stem) if rel.parent != Path(".") else rel.stem
465
- cids.append(cid)
484
+ Args:
485
+ bundle_dir: Path to an OKF bundle directory.
466
486
 
467
- return cids
487
+ Returns:
488
+ Sorted list of dicts with keys ``id``, ``type``, ``title``,
489
+ ``description``. ``title`` and ``description`` are empty strings
490
+ when absent from frontmatter.
491
+
492
+ Raises:
493
+ ValueError: If the directory is not a valid OKF bundle.
494
+ """
495
+ entries: list[dict[str, str]] = []
496
+ for cid, f in _iter_concept_files(Path(bundle_dir)):
497
+ fm = parse_frontmatter(f.read_text(encoding="utf-8")) or {}
498
+ entries.append(
499
+ {
500
+ "id": cid,
501
+ "type": str(fm.get("type", "")),
502
+ "title": str(fm.get("title", "")),
503
+ "description": str(fm.get("description", "")),
504
+ }
505
+ )
506
+
507
+ return entries
468
508
 
469
509
 
470
510
  def show_concept(bundle_dir: str | Path, concept_id: str) -> ConceptContent:
@@ -57,8 +57,8 @@ def bundle(
57
57
 
58
58
  for w in result.warnings:
59
59
  err_console.print(f"Warning: {w}", style="yellow")
60
- for e in result.errors:
61
- err_console.print(f"Error: {e}", style="red")
60
+ for error in result.errors:
61
+ err_console.print(f"Error: {error}", style="red")
62
62
 
63
63
  if result.errors:
64
64
  raise typer.Exit(code=1)
@@ -0,0 +1,39 @@
1
+ """okf list command."""
2
+
3
+ from pathlib import Path
4
+
5
+ import typer
6
+ from rich.table import Table
7
+
8
+ from okf import api
9
+ from okf.core import console, err_console
10
+
11
+
12
+ def cmd_list(
13
+ directory: str = typer.Argument(..., help="Directory of the OKF bundle"),
14
+ ) -> None:
15
+ """List concepts in a table with ID, type, title, and description."""
16
+ try:
17
+ entries = api.list_entries(directory)
18
+ except (ValueError, NotADirectoryError) as e:
19
+ err_console.print(f"Error: {e}", style="red")
20
+ raise typer.Exit(code=1)
21
+
22
+ if not entries:
23
+ err_console.print("No concepts found", style="yellow")
24
+ raise typer.Exit(code=1)
25
+
26
+ table = Table(
27
+ "ID",
28
+ "Type",
29
+ "Title",
30
+ "Description",
31
+ caption="Use the ID column with: okf read <bundle> <id>",
32
+ )
33
+ table.columns[0].no_wrap = True
34
+
35
+ for entry in entries:
36
+ title = entry["title"] if entry["title"] else Path(entry["id"]).stem
37
+ table.add_row(entry["id"], entry["type"], title, entry["description"])
38
+
39
+ console.print(table)
@@ -18,10 +18,11 @@ def validate(
18
18
 
19
19
  for w in result.warnings:
20
20
  err_console.print(f"Warning: {w}", style="yellow")
21
- for e in result.errors:
22
- err_console.print(f"Error: {e}", style="red")
21
+ for error in result.errors:
22
+ err_console.print(f"Error: {error}", style="red")
23
23
 
24
- ok = result.total_files - len(result.errors)
24
+ bad_files = len({error.split(":", 1)[0] for error in result.errors})
25
+ ok = result.total_files - bad_files
25
26
  parts = [f"{result.total_files} files: {ok} ok"]
26
27
  if result.errors:
27
28
  parts.append(f"{len(result.errors)} errors")
@@ -13,6 +13,7 @@ from okf.api import (
13
13
  convert_content,
14
14
  convert_file,
15
15
  list_concepts,
16
+ list_entries,
16
17
  show_concept,
17
18
  validate,
18
19
  )
@@ -225,6 +226,12 @@ class TestBundle:
225
226
  with pytest.raises(ValueError, match="different"):
226
227
  bundle(src, src)
227
228
 
229
+ def test_output_inside_input(self, tmp_path: Path):
230
+ src = tmp_path / "src"
231
+ src.mkdir()
232
+ with pytest.raises(ValueError, match="inside input"):
233
+ bundle(src, src / "out")
234
+
228
235
  def test_empty_dir(self, tmp_path: Path):
229
236
  src = tmp_path / "src"
230
237
  src.mkdir()
@@ -639,6 +646,115 @@ class TestListConcepts:
639
646
  list_concepts(tmp_path / "nope")
640
647
 
641
648
 
649
+ # ---------------------------------------------------------------------------
650
+ # list_entries()
651
+ # ---------------------------------------------------------------------------
652
+
653
+
654
+ class TestListEntries:
655
+ def test_lists_with_metadata(self, tmp_path: Path):
656
+ src = tmp_path / "src"
657
+ dst = tmp_path / "out"
658
+ src.mkdir()
659
+ _write(
660
+ src,
661
+ {
662
+ "tables/orders.md": "# Orders\n\n> Customer orders.\n\nBody.",
663
+ "datasets/sales.md": "# Sales\n\n> Sales dataset.\n\nBody.",
664
+ },
665
+ )
666
+ bundle(src, dst)
667
+
668
+ entries = list_entries(dst)
669
+
670
+ assert isinstance(entries, list)
671
+ assert all(isinstance(e, dict) for e in entries)
672
+ keys = ("id", "type", "title", "description")
673
+ assert all(k in e for e in entries for k in keys)
674
+ assert {"tables/orders", "datasets/sales"} == {e["id"] for e in entries}
675
+
676
+ def test_entries_have_types(self, tmp_path: Path):
677
+ src = tmp_path / "src"
678
+ dst = tmp_path / "out"
679
+ src.mkdir()
680
+ _write(
681
+ src,
682
+ {
683
+ "tables/a.md": "# A\n\n> Desc.\n\nBody.",
684
+ "playbooks/b.md": "# B\n\n> Playbook.\n\nBody.",
685
+ },
686
+ )
687
+ bundle(src, dst)
688
+
689
+ entries = list_entries(dst)
690
+ by_id = {e["id"]: e for e in entries}
691
+
692
+ assert by_id["tables/a"]["type"] == "tables"
693
+ assert by_id["playbooks/b"]["type"] == "playbooks"
694
+
695
+ def test_missing_title_shows_empty(self, tmp_path: Path):
696
+ src = tmp_path / "src"
697
+ dst = tmp_path / "out"
698
+ src.mkdir()
699
+ _write(src, {"tables/bad.md": "No heading.\n> Desc.\n"})
700
+ bundle(src, dst)
701
+
702
+ entries = list_entries(dst)
703
+ assert entries[0]["title"] == ""
704
+
705
+ def test_missing_description_shows_empty(self, tmp_path: Path):
706
+ # Construct a bundle manually so description is truly absent.
707
+ d = tmp_path / "bundle"
708
+ d.mkdir()
709
+ (d / "tables").mkdir()
710
+ (d / "tables" / "minimal.md").write_text(
711
+ "---\ntype: tables\ntitle: Minimal\n---\n\nJust body."
712
+ )
713
+
714
+ entries = list_entries(d)
715
+ assert entries[0]["description"] == ""
716
+
717
+ def test_excludes_reserved(self, tmp_path: Path):
718
+ src = tmp_path / "src"
719
+ dst = tmp_path / "out"
720
+ src.mkdir()
721
+ _write(src, {"tables/a.md": "# A\n\n> Desc.\n"})
722
+ bundle(src, dst)
723
+
724
+ entries = list_entries(dst)
725
+ ids = {e["id"] for e in entries}
726
+ assert "index" not in ids
727
+
728
+ def test_sorted_order(self, tmp_path: Path):
729
+ src = tmp_path / "src"
730
+ dst = tmp_path / "out"
731
+ src.mkdir()
732
+ _write(
733
+ src,
734
+ {
735
+ "tables/orders.md": "# Orders\n\n> One row.\n",
736
+ "playbooks/incident.md": "# Incident\n\n> Playbook.\n",
737
+ },
738
+ )
739
+ bundle(src, dst)
740
+
741
+ entries = list_entries(dst)
742
+ ids = [e["id"] for e in entries]
743
+ assert ids == sorted(ids)
744
+
745
+ def test_not_conformant(self, tmp_path: Path):
746
+ d = tmp_path / "raw"
747
+ d.mkdir()
748
+ _write(d, {"plain.md": "# Title\n\n> Desc.\n\nBody."})
749
+
750
+ with pytest.raises(ValueError, match="not an OKF-conformant"):
751
+ list_entries(d)
752
+
753
+ def test_not_a_dir(self, tmp_path: Path):
754
+ with pytest.raises(NotADirectoryError):
755
+ list_entries(tmp_path / "nope")
756
+
757
+
642
758
  # ---------------------------------------------------------------------------
643
759
  # show_concept()
644
760
  # ---------------------------------------------------------------------------
@@ -210,6 +210,58 @@ def test_list_empty_shows_message(tmp_path: Path):
210
210
  assert "No concepts found" in result.output
211
211
 
212
212
 
213
+ def test_list_shows_table(tmp_path: Path):
214
+ d = tmp_path / "bundle"
215
+ d.mkdir()
216
+ _write(
217
+ d,
218
+ {
219
+ "tables/orders.md": (
220
+ "---\n"
221
+ "type: tables\n"
222
+ "title: Orders\n"
223
+ "description: Customer orders.\n"
224
+ "---\n\n"
225
+ "Body."
226
+ ),
227
+ "datasets/sales.md": (
228
+ "---\n"
229
+ "type: datasets\n"
230
+ "title: Sales\n"
231
+ "description: Sales data.\n"
232
+ "---\n\n"
233
+ "Body."
234
+ ),
235
+ },
236
+ )
237
+
238
+ result = runner.invoke(app, ["list", str(d)])
239
+ assert result.exit_code == 0
240
+ assert "Type" in result.output
241
+ assert "Title" in result.output
242
+ assert "Description" in result.output
243
+ assert "ID" in result.output
244
+ assert "Orders" in result.output
245
+ assert "Customer orders." in result.output
246
+ assert "tables/orders" in result.output
247
+ assert "okf read" in result.output
248
+
249
+
250
+ def test_list_falls_back_to_stem_for_missing_title(tmp_path: Path):
251
+ d = tmp_path / "bundle"
252
+ d.mkdir()
253
+ _write(
254
+ d,
255
+ {
256
+ "tables/bad.md": ("---\ntype: tables\n---\n\nBody."),
257
+ },
258
+ )
259
+
260
+ result = runner.invoke(app, ["list", str(d)])
261
+ assert result.exit_code == 0
262
+ assert "bad" in result.output
263
+
264
+
213
265
  # ---------------------------------------------------------------------------
214
266
  # read — exit codes & error messages
215
267
  # ---------------------------------------------------------------------------
@@ -52,7 +52,7 @@ wheels = [
52
52
 
53
53
  [[package]]
54
54
  name = "okf-cli"
55
- version = "0.5.3"
55
+ version = "0.5.5"
56
56
  source = { editable = "." }
57
57
  dependencies = [
58
58
  { name = "pyyaml" },
@@ -1,4 +0,0 @@
1
- {
2
- "head": "55fc995650cb6e812fed6efd436bf36763a75065",
3
- "timestamp": "2026-07-19T22:00:00Z"
4
- }
@@ -1,24 +0,0 @@
1
- """okf list command."""
2
-
3
- import typer
4
-
5
- from okf import api
6
- from okf.core import console, err_console
7
-
8
-
9
- def cmd_list(
10
- directory: str = typer.Argument(..., help="Directory of the OKF bundle"),
11
- ) -> None:
12
- """List all concept IDs in an OKF bundle."""
13
- try:
14
- cids = api.list_concepts(directory)
15
- except (ValueError, NotADirectoryError) as e:
16
- err_console.print(f"Error: {e}", style="red")
17
- raise typer.Exit(code=1)
18
-
19
- if not cids:
20
- err_console.print("No concepts found", style="yellow")
21
- raise typer.Exit(code=1)
22
-
23
- for cid in cids:
24
- console.print(cid, style="cyan")
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