Skip to content

Commit 1f0d5a3

Browse files
committed
refactor: tidy examples/ + document use-case extraction heuristic
- Reorganize examples/ for clarity: - examples/raw/papers/ -> examples/data/papers/ - examples/demo_wiki/ -> examples/data/wiki/ - All e2e scripts moved under examples/e2e/ - Remove examples/__init__.py (no longer an importable package) - examples/wiki_schema.md -> docs/wiki_schema.md - Decouple integration test from examples/ packaging: tests/integration/test_e2e_scenario.py loads run_scenario via importlib by file path. - Drop dead sys.path injections in moved scripts (engine is installed via the uv workspace). - Sweep cross-references: README, examples/README, docs/USAGE, docs/wiki_schema, scripts/run_gemini_comparison, root pyproject ruff per-file-ignores, .gitignore. - SPEC \u00a79.1: add use-case extraction heuristic (when a feature warrants its own projects/<name>/ vs. examples/, scripts/, utils, or the engine CLI). All baselines preserved: - engine: 464 passed, 12 skipped - utils: 2 passed - wiki-agent: 46 passed - check_layering: OK
1 parent 6b6babd commit 1f0d5a3

24 files changed

Lines changed: 156 additions & 76 deletions

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ checkpoints/
7979
# ─────────────────────────────────────────────────────────────
8080
examples/adapters/
8181
examples/wiki/
82+
examples/e2e/adapters/
83+
examples/e2e/wiki/
84+
examples/e2e/demo_wiki/
8285

8386
# ─────────────────────────────────────────────────────────────
8487
# Script output artifacts

CHANGELOG.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,33 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Changed
11+
12+
- **Tidied `examples/` directory** for a clearer separation between
13+
runnable demos and sample data:
14+
- `examples/raw/papers/``examples/data/papers/` (sample paper corpus).
15+
- `examples/demo_wiki/``examples/data/wiki/` (pre-built wiki snapshot).
16+
- All e2e demo scripts (`run_e2e.py`, `run_wiki_e2e.py`,
17+
`demo_e2e_scenario.py`, `research_pipeline.py`, `validate_adapter.py`)
18+
moved under `examples/e2e/`.
19+
- Removed `examples/__init__.py` so `examples/` is no longer treated
20+
as an importable Python package; the integration test
21+
`tests/integration/test_e2e_scenario.py` now loads
22+
`demo_e2e_scenario` by file path via `importlib`.
23+
- `examples/wiki_schema.md` moved to `docs/wiki_schema.md`.
24+
- All cross-references (root `README.md`, `examples/README.md`,
25+
`docs/USAGE.md`, `docs/wiki_schema.md`,
26+
`scripts/run_gemini_comparison.py`, root `pyproject.toml` ruff
27+
`per-file-ignores`, and `.gitignore`) updated accordingly.
28+
29+
### Added
30+
31+
- **SPEC §9.1 — Use-case extraction heuristic.** Documents when a
32+
feature warrants its own `projects/<name>/` (≥ 2 of: external runtime
33+
dependencies, domain-specific schema, long-running surface,
34+
standalone publishability) vs. living in `examples/`, `scripts/`,
35+
`projects/utils/`, or the engine's own CLI.
36+
1037
## [1.0.0rc1] — 2026-04-26
1138

1239
First production-readiness release candidate. Public API surface and

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ from llm_patch.core.interfaces import (
592592
The `examples/` directory contains a complete tutorial that chains an [LLM Wiki Agent](https://github.com/SamurAIGPT/llm-wiki-agent) with llm-patch to build domain-specialized LoRA adapters from ML research papers:
593593

594594
```
595-
raw/papers/*.md ──► LLM Wiki Agent ──► wiki/ ──► WikiKnowledgeSource ──► adapters/
595+
examples/data/papers/*.md ──► LLM Wiki Agent ──► wiki/ ──► WikiKnowledgeSource ──► adapters/
596596
```
597597

598598
### Quick Demo (No GPU Required)

SPEC.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,36 @@ the same exemption.
198198

199199
## 9. Adding a New Use-Case Project
200200

201+
### 9.1 Extraction Heuristic — when does something deserve its own project?
202+
203+
Not every demo, script, or feature warrants a `projects/<name>/`
204+
directory. Promote a piece of work into its own use-case project when
205+
**at least two** of the following are true:
206+
207+
1. **External runtime dependencies.** It pulls in third-party packages
208+
(e.g. `anthropic`, `obsidian-tools`, a vector DB client) that the
209+
engine itself must not depend on.
210+
2. **Domain-specific schema or vocabulary.** It defines its own
211+
data model, frontmatter contract, prompt templates, or wire format
212+
that is meaningless to the engine and to other use-cases.
213+
3. **Long-running surface or service.** It exposes a CLI, daemon,
214+
server, or scheduled job intended to be operated as a deployable
215+
unit, with its own lifecycle, configuration, and logging concerns.
216+
4. **Standalone publishability.** It is something an end user would
217+
reasonably `pip install <name>` on its own, with its own README,
218+
versioning, and changelog.
219+
220+
If only **one** criterion applies, prefer one of these lighter homes:
221+
222+
- **One-off scripts** that exercise the engine end-to-end belong in
223+
`examples/` (tutorial demos) or `scripts/` (operator/automation
224+
one-shots).
225+
- **Reusable stdlib-only helpers** belong in `projects/utils/`.
226+
- **Engine-facing CLI commands** belong in the engine itself
227+
(`llm_patch.cli`), not in a separate project.
228+
229+
### 9.2 Procedure
230+
201231
1. Run `python tools/scaffold_project.py <name>` to materialize the
202232
standardized skeleton (`src/llm_patch_<name>/`, `tests/`,
203233
`pyproject.toml`, `README.md`, `CHANGELOG.md`). The scaffold

docs/USAGE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ python run_e2e.py --clean --aggregate
119119

120120
This will:
121121

122-
1. Copy sample ML papers from `raw/papers/` into a simulated `wiki/` directory
122+
1. Copy sample ML papers from `examples/data/papers/` into a simulated `wiki/` directory
123123
2. Add wiki-style frontmatter and create entity stub pages
124124
3. Run the full pipeline with mock generator and repository
125125
4. Report all generated adapter manifests
@@ -379,7 +379,7 @@ wiki = WikiPipeline(agent, config)
379379
wiki.init()
380380

381381
# Ingest a raw source
382-
result = wiki.ingest(Path("./raw/papers/attention-paper.md"))
382+
result = wiki.ingest(Path("./examples/data/papers/attention-paper.md"))
383383

384384
# Query the wiki
385385
answer = wiki.query("How does self-attention work?")
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Wiki Schema (CLAUDE.md-style)
22

33
This file defines the structure, conventions, and rules for the LLM Wiki.
4-
Load it with `WikiSchema.from_file("wiki_schema.md")`.
4+
Load it with `WikiSchema.from_file("docs/wiki_schema.md")`.
55

66
## Directory Layout
77

@@ -26,7 +26,7 @@ type: concept|entity|summary|synthesis|journal
2626
tags: [tag1, tag2]
2727
created: YYYY-MM-DD
2828
updated: YYYY-MM-DD
29-
sources: [raw/papers/example.md]
29+
sources: [examples/data/papers/example.md]
3030
confidence: high|medium|low|uncertain
3131
---
3232
```

examples/README.md

Lines changed: 45 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,63 +7,71 @@ adapter weights that can be applied to a base language model.
77
## Architecture
88

99
```
10-
raw/papers/*.md ──► LLM Wiki Agent ──► wiki/ (structured markdown)
11-
(ingest) │
12-
13-
llm-patch library
14-
┌──────────────┐
15-
│ WikiSource │ (IKnowledgeSource)
16-
│ watches │
17-
│ wiki/ │
18-
└──────┬───────┘
19-
20-
┌──────────────┐
21-
│ Weight │ (IWeightGenerator)
22-
│ Generator │
23-
└──────┬───────┘
24-
25-
┌──────────────┐
26-
│ Adapter │ (IAdapterRepository)
27-
│ Repository │
28-
└──────┬───────┘
29-
30-
adapters/{id}/
10+
data/papers/*.md ──► LLM Wiki Agent ──► wiki/ (structured markdown)
11+
(ingest) │
12+
13+
llm-patch library
14+
┌──────────────┐
15+
│ WikiSource │ (IKnowledgeSource)
16+
│ watches │
17+
│ wiki/ │
18+
└──────┬───────┘
19+
20+
┌──────────────┐
21+
│ Weight │ (IWeightGenerator)
22+
│ Generator │
23+
└──────┬───────┘
24+
25+
┌──────────────┐
26+
│ Adapter │ (IAdapterRepository)
27+
│ Repository │
28+
└──────┬───────┘
29+
30+
adapters/{id}/
3131
```
3232

33-
## Files
33+
## Layout
3434

35-
| File | Purpose |
36-
|------|---------|
37-
| `research_pipeline.py` | Core demo — batch or watch mode pipeline |
38-
| `run_e2e.py` | Full end-to-end: simulate wiki → generate → validate |
39-
| `validate_adapter.py` | Load adapter + base model, compare inference |
40-
| `raw/papers/*.md` | 3 sample ML paper summaries |
35+
```
36+
examples/
37+
├── data/ # Read-only sample corpora used by the demos
38+
│ ├── papers/ # 3 sample ML paper summaries (raw input)
39+
│ └── wiki/ # Pre-built wiki snapshot (sources/ + entities/)
40+
├── e2e/ # End-to-end demo scripts
41+
│ ├── run_e2e.py # Full pipeline: simulate wiki → generate → validate
42+
│ ├── run_wiki_e2e.py # Wiki-agent variant (mock or Anthropic)
43+
│ ├── demo_e2e_scenario.py # Scripted 5-step scenario for documentation/tests
44+
│ ├── research_pipeline.py # Core batch/watch pipeline implementation
45+
│ └── validate_adapter.py # GPU-only adapter validation script
46+
└── quickstart/ # Smallest possible getting-started example
47+
```
4148

4249
## Quick Start
4350

4451
### 1. Run the end-to-end demo (no GPU needed)
4552

4653
```bash
47-
cd examples
48-
python run_e2e.py --clean
54+
python examples/e2e/run_e2e.py --clean
4955
```
5056

5157
This will:
52-
1. Copy raw papers from `raw/papers/` into a simulated `wiki/` directory
58+
1. Copy raw papers from `examples/data/papers/` into a simulated `wiki/` directory
5359
2. Add wiki-style frontmatter and create entity stub pages
5460
3. Run the WikiKnowledgeSource → MockWeightGenerator → MockAdapterRepository pipeline
5561
4. Report all generated adapter manifests
5662

5763
### 2. Batch mode — process an existing wiki
5864

5965
```bash
60-
python research_pipeline.py batch --wiki-dir wiki/ --output-dir adapters/
66+
python examples/e2e/research_pipeline.py batch \
67+
--wiki-dir examples/data/wiki/ --output-dir adapters/
6168
```
6269

6370
### 3. Batch mode with wikilink aggregation
6471

6572
```bash
66-
python research_pipeline.py batch --wiki-dir wiki/ --aggregate
73+
python examples/e2e/research_pipeline.py batch \
74+
--wiki-dir examples/data/wiki/ --aggregate
6775
```
6876

6977
When `--aggregate` is enabled, each source page follows its `[[wikilinks]]`
@@ -73,7 +81,7 @@ enriched document before weight generation.
7381
### 4. Watch mode — live monitoring
7482

7583
```bash
76-
python research_pipeline.py watch --wiki-dir wiki/
84+
python examples/e2e/research_pipeline.py watch --wiki-dir wiki/
7785
```
7886

7987
Add or modify wiki pages while the watcher is running. Each change triggers
@@ -82,8 +90,9 @@ automatic adapter generation. Press Ctrl-C to stop.
8290
### 5. Validate adapters (GPU required)
8391

8492
```bash
85-
python validate_adapter.py --adapter-dir adapters/sources/attention-paper \
86-
--base-model google/gemma-2-2b-it
93+
python examples/e2e/validate_adapter.py \
94+
--adapter-dir adapters/sources/attention-paper \
95+
--base-model google/gemma-2-2b-it
8796
```
8897

8998
This loads the base model, applies the LoRA adapter, and runs a side-by-side

examples/__init__.py

Whitespace-only changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)