Skip to content

Commit e0acade

Browse files
committed
Merge remote-tracking branch 'upstream/main' into pr/add-mutation-coordinator
# Conflicts: # openkb/cli.py # openkb/indexer.py
2 parents cf53d5f + dce4972 commit e0acade

103 files changed

Lines changed: 3265 additions & 1731 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/ci.yml‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: ["main"]
6+
pull_request:
7+
8+
# Least-privilege token: this workflow only reads the repo. Arbitrary
9+
# dependency build code runs during install, so never expose a writable
10+
# token to it (see the supply-chain notes in pyproject.toml).
11+
permissions:
12+
contents: read
13+
14+
# Cancel superseded runs on the same ref (rapid PR pushes) instead of
15+
# letting them pile up and post stale statuses.
16+
concurrency:
17+
group: ci-${{ github.ref }}
18+
cancel-in-progress: true
19+
20+
jobs:
21+
check:
22+
runs-on: ubuntu-latest
23+
steps:
24+
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
25+
with:
26+
persist-credentials: false
27+
28+
- uses: astral-sh/setup-uv@fac544c07dec837d0ccb6301d7b5580bf5edae39 # v8.2.0
29+
with:
30+
version: "0.10.2"
31+
enable-cache: true
32+
33+
# `uv sync --locked` installs the exact uv.lock resolution (direct AND
34+
# transitive deps) and fails if the lock is stale — a bare `pip install`
35+
# would ignore the lockfile and let transitive versions float, defeating
36+
# the repo's exact-pin supply-chain policy. Run `uv lock` and commit the
37+
# lockfile whenever pyproject dependencies change.
38+
- name: Install (locked)
39+
run: uv sync --locked --extra dev --python 3.12
40+
41+
# --no-sync: don't let `uv run` re-sync without the dev extra and
42+
# uninstall the tools it is about to run.
43+
- name: Ruff lint
44+
run: uv run --no-sync ruff check .
45+
46+
- name: Ruff format check
47+
run: uv run --no-sync ruff format --check .
48+
49+
- name: Mypy
50+
run: uv run --no-sync mypy openkb
51+
52+
- name: Pytest
53+
run: uv run --no-sync pytest

‎.github/workflows/publish.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
id-token: write # OIDC trusted publishing to PyPI
3030
contents: write # Create GitHub Release
3131
steps:
32-
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.2.2
32+
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
3333
with:
3434
fetch-depth: 0 # hatch-vcs needs full history + tags
3535

‎.gitignore‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,11 @@ wiki/
1616
output/
1717

1818
# Local only
19-
docs/
19+
docs/internal/
2020
.claude/
21+
22+
# Heavy test-input documents for the examples (the old blanket `docs/` rule
23+
# used to catch this dir at any depth; the anchored `docs/internal/` above
24+
# does not). The PDFs already tracked on main stay tracked — this only stops
25+
# new drops from being swept into commits.
26+
examples/docs/

‎AGENTS.md‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# AGENTS.md — OpenKB map for coding agents
2+
3+
OpenKB compiles raw documents into an interlinked wiki knowledge base using
4+
LLMs (vectorless retrieval via PageIndex). This repo is developed **agent-first**:
5+
humans steer, agents execute. Optimize changes for agent legibility.
6+
7+
## Read next
8+
- `docs/golden-principles.md` — mechanical rules to follow (enforced where possible).
9+
- `docs/internal/superpowers/{specs,plans}/` — design history & plans *(maintainer-local, not in git)*.
10+
- `README.md` — user-facing overview and commands.
11+
12+
## Dev commands
13+
- Install: `pip install -e ".[dev]"` (or `uv sync --extra dev` — plain `uv sync` skips the dev tools)
14+
- Run CLI: `openkb <command>` (entry point: `openkb.cli:cli`)
15+
- Test: `pytest`
16+
- Lint/format/types: `ruff check .` · `ruff format .` · `mypy openkb`
17+
18+
## Module map (openkb/)
19+
- `cli.py` — Click CLI entry point & command wiring *(large; see tech-debt)*.
20+
- `config.py` — config loading/validation (LiteLLM passthrough, env).
21+
- `converter.py` — document → markdown conversion (markitdown).
22+
- `url_ingest.py` — fetch & ingest URLs (trafilatura).
23+
- `images.py` — figure/image extraction & handling.
24+
- `indexer.py` — PageIndex tree indexing for long docs.
25+
- `mutation.py` — crash-safe, serial KB mutations.
26+
- `locks.py` — atomic writes / file locking (`atomic_write_text`, portalocker).
27+
- `state.py` — run/session state tracking.
28+
- `frontmatter.py` — YAML frontmatter round-trip (OKF).
29+
- `schema.py` — page/content schema constants & helpers.
30+
- `lint.py` — structural wiki lint (broken links, orphans, index sync).
31+
- `tree_renderer.py`, `visualize.py`, `watcher.py` — rendering / graph / file watch.
32+
- `agent/compiler.py` — LLM wiki compiler *(large; see tech-debt)*.
33+
- `agent/linter.py` — semantic (LLM) wiki lint (contradictions, gaps, staleness).
34+
- `agent/chat.py`, `agent/chat_session.py` — chat over the wiki *(chat.py large)*.
35+
- `agent/query.py` — one-off query generator.
36+
- `agent/tools.py` — shared wiki read/write tool functions used by query/linter (and by chat indirectly via `query.build_chat_agent`).
37+
- `agent/skills.py`, `agent/skill_runner.py`, `skill/` — Skill Factory.
38+
- `deck/`, `templates/`, `prompts/` — deck output, templates, prompt assets.
39+
40+
## Hard invariants
41+
- Deps are pinned **exactly** (supply-chain caution). Vet before bumping.
42+
- Wiki writes go through `locks.py` / `mutation.py` (never ad-hoc).
43+
- Modules stay < 800 lines (`tests/test_file_size.py`); grandfathered files are in tech-debt.
44+
- Keep this file a short map — put depth in `docs/`.

‎CLAUDE.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@AGENTS.md

‎docs/.gitignore‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Default-closed: docs/ content stays out of git unless explicitly
2+
# allowlisted below. This repo publishes code, not design/spec docs — the
3+
# allowlist restores the safety net the old blanket `docs/` ignore provided,
4+
# so a doc accidentally written outside docs/internal/ can't be swept into a
5+
# commit by `git add -A`. To publish a new doc, add a `!its-name.md` line.
6+
*
7+
!.gitignore
8+
!golden-principles.md

‎docs/golden-principles.md‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Golden Principles
2+
3+
Opinionated, mechanical rules that keep this agent-generated codebase legible
4+
and consistent for future agent runs. Enforced by CI where possible; the rest
5+
are honored by convention and checked in review. When a rule proves valuable,
6+
promote it into a lint (see `tests/test_file_size.py` for the pattern).
7+
8+
## Boundaries
9+
- **Validate data shapes at boundaries.** Parse/validate inputs (frontmatter via
10+
`openkb/frontmatter.py`, config via `openkb/config.py`) at the edge. Never build
11+
on guessed shapes.
12+
13+
## Reuse
14+
- **Prefer shared utilities over hand-rolled helpers** so invariants stay
15+
centralized. Check `openkb/` for an existing helper before writing a new one.
16+
17+
## I/O and state
18+
- **All wiki file writes go through `openkb/locks.py` / `openkb/mutation.py`**
19+
(atomic, crash-safe). No ad-hoc writes to the wiki tree.
20+
- **Log through `openkb/log.py`**, not bare `print`, for anything diagnostic.
21+
22+
## Size and shape
23+
<a id="file-size"></a>
24+
- **Keep modules focused and under 800 lines** (enforced by
25+
`tests/test_file_size.py`). Split large modules into focused units by
26+
responsibility. Existing over-limit files are grandfathered (with reasons)
27+
in the test's `_GRANDFATHERED` set and additionally tracked in
28+
`docs/internal/tech-debt.md` *(maintainer-local, not in git)*.
29+
30+
## Docs
31+
- **`AGENTS.md` is a map, not a manual.** Keep it short; deep/local docs live
32+
under `docs/` (public) and `docs/internal/` (maintainer-local, not in git).

‎openkb/__init__.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""OpenKB package."""
2-
from importlib.metadata import PackageNotFoundError, version as _version
2+
3+
from importlib.metadata import PackageNotFoundError
4+
from importlib.metadata import version as _version
35

46
try:
57
__version__ = _version("openkb")

‎openkb/__main__.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Allow running OpenKB as ``python -m openkb``."""
2+
23
from openkb.cli import cli
34

45
cli()

‎openkb/agent/_markdown.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
from rich.syntax import Syntax
1616
from rich.text import Text
1717

18-
1918
INLINE_CODE_STYLE = "blue"
2019
BLOCKQUOTE_BAR = "\u258e"
2120

0 commit comments

Comments
 (0)