kingmadoc 0.2.0__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.
- kingmadoc-0.2.0/.featuredoc.yml +84 -0
- kingmadoc-0.2.0/.github/ISSUE_TEMPLATE/bug_report.md +33 -0
- kingmadoc-0.2.0/.github/ISSUE_TEMPLATE/feature_request.md +24 -0
- kingmadoc-0.2.0/.github/workflows/ci.yml +75 -0
- kingmadoc-0.2.0/.github/workflows/release.yml +86 -0
- kingmadoc-0.2.0/.gitignore +30 -0
- kingmadoc-0.2.0/CHANGELOG.md +214 -0
- kingmadoc-0.2.0/CLAUDE.md +53 -0
- kingmadoc-0.2.0/CONTRIBUTING.md +114 -0
- kingmadoc-0.2.0/LICENSE +21 -0
- kingmadoc-0.2.0/PKG-INFO +253 -0
- kingmadoc-0.2.0/README.md +199 -0
- kingmadoc-0.2.0/docs/conventions.md +381 -0
- kingmadoc-0.2.0/docs/index.md +73 -0
- kingmadoc-0.2.0/docs/releasing.md +29 -0
- kingmadoc-0.2.0/docs/roadmap.md +293 -0
- kingmadoc-0.2.0/docs/test-plan.md +186 -0
- kingmadoc-0.2.0/evals/README.md +46 -0
- kingmadoc-0.2.0/evals/fixtures/shop/manage.py +8 -0
- kingmadoc-0.2.0/evals/fixtures/shop/requirements.txt +1 -0
- kingmadoc-0.2.0/evals/fixtures/shop/shop/__init__.py +0 -0
- kingmadoc-0.2.0/evals/fixtures/shop/shop/models.py +27 -0
- kingmadoc-0.2.0/evals/fixtures/shop/shop/services.py +36 -0
- kingmadoc-0.2.0/evals/fixtures/shop/shop/settings.py +4 -0
- kingmadoc-0.2.0/evals/fixtures/shop/shop/urls.py +8 -0
- kingmadoc-0.2.0/evals/fixtures/shop/shop/views.py +31 -0
- kingmadoc-0.2.0/evals/fixtures/shop-discount/shop/discounts.py +12 -0
- kingmadoc-0.2.0/evals/fixtures/shop-discount/shop/services.py +37 -0
- kingmadoc-0.2.0/evals/results/2026-09-27T111837Z.json +229 -0
- kingmadoc-0.2.0/evals/results/2026-09-27T112600Z.json +219 -0
- kingmadoc-0.2.0/evals/scenarios/explain-branch.yml +17 -0
- kingmadoc-0.2.0/evals/scenarios/explain-feature.yml +20 -0
- kingmadoc-0.2.0/evals/scenarios/plan-feature.yml +21 -0
- kingmadoc-0.2.0/examples/verify-mode-plan.md +306 -0
- kingmadoc-0.2.0/pyproject.toml +132 -0
- kingmadoc-0.2.0/scripts/build_skill_variants.py +184 -0
- kingmadoc-0.2.0/scripts/run_evals.py +355 -0
- kingmadoc-0.2.0/skill/SKILL.md +200 -0
- kingmadoc-0.2.0/skill/codex.md +427 -0
- kingmadoc-0.2.0/skill/copilot.md +427 -0
- kingmadoc-0.2.0/skill/cursor.md +428 -0
- kingmadoc-0.2.0/skill/explaining-code/SKILL.md +214 -0
- kingmadoc-0.2.0/skill/explaining-code/reference/arc42.md +202 -0
- kingmadoc-0.2.0/skill/explaining-code/reference/c4-model.md +341 -0
- kingmadoc-0.2.0/skill/explaining-code/reference/c4.md +133 -0
- kingmadoc-0.2.0/skill/explaining-code/reference/models.md +314 -0
- kingmadoc-0.2.0/skill/explaining-code/reference/split.md +138 -0
- kingmadoc-0.2.0/skill/reference/diagram-rules.md +41 -0
- kingmadoc-0.2.0/skill/reference/formats.md +195 -0
- kingmadoc-0.2.0/src/kingmadoc/__init__.py +11 -0
- kingmadoc-0.2.0/src/kingmadoc/about.py +49 -0
- kingmadoc-0.2.0/src/kingmadoc/adr.py +147 -0
- kingmadoc-0.2.0/src/kingmadoc/cli.py +631 -0
- kingmadoc-0.2.0/src/kingmadoc/config.py +531 -0
- kingmadoc-0.2.0/src/kingmadoc/d2_binary.py +164 -0
- kingmadoc-0.2.0/src/kingmadoc/diagrams/__init__.py +36 -0
- kingmadoc-0.2.0/src/kingmadoc/diagrams/base.py +481 -0
- kingmadoc-0.2.0/src/kingmadoc/diagrams/d2.py +250 -0
- kingmadoc-0.2.0/src/kingmadoc/diagrams/mermaid.py +285 -0
- kingmadoc-0.2.0/src/kingmadoc/diagrams/plantuml.py +226 -0
- kingmadoc-0.2.0/src/kingmadoc/documents.py +134 -0
- kingmadoc-0.2.0/src/kingmadoc/exceptions.py +45 -0
- kingmadoc-0.2.0/src/kingmadoc/explain.py +278 -0
- kingmadoc-0.2.0/src/kingmadoc/facts/__init__.py +6 -0
- kingmadoc-0.2.0/src/kingmadoc/facts/branch.py +82 -0
- kingmadoc-0.2.0/src/kingmadoc/facts/collect.py +218 -0
- kingmadoc-0.2.0/src/kingmadoc/facts/data_model.py +264 -0
- kingmadoc-0.2.0/src/kingmadoc/facts/js_modules.py +171 -0
- kingmadoc-0.2.0/src/kingmadoc/facts/projects.py +34 -0
- kingmadoc-0.2.0/src/kingmadoc/facts/routes.py +252 -0
- kingmadoc-0.2.0/src/kingmadoc/facts/services.py +49 -0
- kingmadoc-0.2.0/src/kingmadoc/git.py +46 -0
- kingmadoc-0.2.0/src/kingmadoc/naming.py +47 -0
- kingmadoc-0.2.0/src/kingmadoc/plan/__init__.py +1 -0
- kingmadoc-0.2.0/src/kingmadoc/plan/analyzer.py +659 -0
- kingmadoc-0.2.0/src/kingmadoc/plan/dependencies.py +131 -0
- kingmadoc-0.2.0/src/kingmadoc/plan/generator.py +481 -0
- kingmadoc-0.2.0/src/kingmadoc/plan/models.py +197 -0
- kingmadoc-0.2.0/src/kingmadoc/plandoc.py +182 -0
- kingmadoc-0.2.0/src/kingmadoc/render.py +184 -0
- kingmadoc-0.2.0/src/kingmadoc/skills.py +227 -0
- kingmadoc-0.2.0/src/kingmadoc/templates/adr.md.j2 +26 -0
- kingmadoc-0.2.0/src/kingmadoc/templates/domain_design.md.j2 +18 -0
- kingmadoc-0.2.0/src/kingmadoc/templates/functional_design.md.j2 +86 -0
- kingmadoc-0.2.0/src/kingmadoc/templates/plan_default.md.j2 +113 -0
- kingmadoc-0.2.0/src/kingmadoc/templates/security_design.md.j2 +18 -0
- kingmadoc-0.2.0/src/kingmadoc/templates/technical_design.md.j2 +104 -0
- kingmadoc-0.2.0/src/kingmadoc/templating.py +90 -0
- kingmadoc-0.2.0/src/kingmadoc/verify/__init__.py +1 -0
- kingmadoc-0.2.0/src/kingmadoc/verify/changes.py +81 -0
- kingmadoc-0.2.0/src/kingmadoc/verify/commands.py +143 -0
- kingmadoc-0.2.0/src/kingmadoc/verify/deviations.py +115 -0
- kingmadoc-0.2.0/src/kingmadoc/verify/locate.py +60 -0
- kingmadoc-0.2.0/src/kingmadoc/verify/report.py +124 -0
- kingmadoc-0.2.0/src/kingmadoc/vscode.py +73 -0
- kingmadoc-0.2.0/tests/fixtures/backends/d2/class.d2 +40 -0
- kingmadoc-0.2.0/tests/fixtures/backends/d2/component.d2 +12 -0
- kingmadoc-0.2.0/tests/fixtures/backends/d2/container.d2 +18 -0
- kingmadoc-0.2.0/tests/fixtures/backends/d2/context.d2 +20 -0
- kingmadoc-0.2.0/tests/fixtures/backends/d2/sequence.d2 +11 -0
- kingmadoc-0.2.0/tests/fixtures/backends/mermaid/class.mmd +22 -0
- kingmadoc-0.2.0/tests/fixtures/backends/mermaid/component.mmd +11 -0
- kingmadoc-0.2.0/tests/fixtures/backends/mermaid/container.mmd +15 -0
- kingmadoc-0.2.0/tests/fixtures/backends/mermaid/context.mmd +13 -0
- kingmadoc-0.2.0/tests/fixtures/backends/mermaid/sequence.mmd +10 -0
- kingmadoc-0.2.0/tests/fixtures/backends/plantuml/class.puml +21 -0
- kingmadoc-0.2.0/tests/fixtures/backends/plantuml/component.puml +13 -0
- kingmadoc-0.2.0/tests/fixtures/backends/plantuml/container.puml +17 -0
- kingmadoc-0.2.0/tests/fixtures/backends/plantuml/context.puml +15 -0
- kingmadoc-0.2.0/tests/fixtures/backends/plantuml/sequence.puml +11 -0
- kingmadoc-0.2.0/tests/fixtures/mermaid/component.mmd +13 -0
- kingmadoc-0.2.0/tests/fixtures/mermaid/container.mmd +16 -0
- kingmadoc-0.2.0/tests/fixtures/mermaid/context.mmd +15 -0
- kingmadoc-0.2.0/tests/test_adr.py +132 -0
- kingmadoc-0.2.0/tests/test_adr_numbering.py +44 -0
- kingmadoc-0.2.0/tests/test_analyzer.py +164 -0
- kingmadoc-0.2.0/tests/test_cli.py +27 -0
- kingmadoc-0.2.0/tests/test_cli_encoding.py +33 -0
- kingmadoc-0.2.0/tests/test_cli_init.py +42 -0
- kingmadoc-0.2.0/tests/test_cli_plan_custom_template.py +60 -0
- kingmadoc-0.2.0/tests/test_cli_sigint.py +48 -0
- kingmadoc-0.2.0/tests/test_cli_verify_config.py +35 -0
- kingmadoc-0.2.0/tests/test_config.py +41 -0
- kingmadoc-0.2.0/tests/test_config_poetry.py +48 -0
- kingmadoc-0.2.0/tests/test_config_shape.py +98 -0
- kingmadoc-0.2.0/tests/test_d2_download.py +134 -0
- kingmadoc-0.2.0/tests/test_dependencies.py +101 -0
- kingmadoc-0.2.0/tests/test_dependency_graph_model.py +112 -0
- kingmadoc-0.2.0/tests/test_design_models.py +59 -0
- kingmadoc-0.2.0/tests/test_diagram_backends.py +210 -0
- kingmadoc-0.2.0/tests/test_diagrams_mermaid.py +131 -0
- kingmadoc-0.2.0/tests/test_documents.py +122 -0
- kingmadoc-0.2.0/tests/test_duplicate_names.py +58 -0
- kingmadoc-0.2.0/tests/test_evals.py +270 -0
- kingmadoc-0.2.0/tests/test_explain.py +135 -0
- kingmadoc-0.2.0/tests/test_explain_config.py +48 -0
- kingmadoc-0.2.0/tests/test_explain_status.py +159 -0
- kingmadoc-0.2.0/tests/test_extra_designs_coverage.py +35 -0
- kingmadoc-0.2.0/tests/test_facts.py +182 -0
- kingmadoc-0.2.0/tests/test_facts_code.py +185 -0
- kingmadoc-0.2.0/tests/test_facts_data_model.py +189 -0
- kingmadoc-0.2.0/tests/test_functional_design.py +120 -0
- kingmadoc-0.2.0/tests/test_generator.py +91 -0
- kingmadoc-0.2.0/tests/test_grep_performance.py +30 -0
- kingmadoc-0.2.0/tests/test_manifests.py +100 -0
- kingmadoc-0.2.0/tests/test_max_lines_per_file.py +59 -0
- kingmadoc-0.2.0/tests/test_output_dir.py +77 -0
- kingmadoc-0.2.0/tests/test_plan_e2e.py +83 -0
- kingmadoc-0.2.0/tests/test_plandoc.py +177 -0
- kingmadoc-0.2.0/tests/test_properties.py +130 -0
- kingmadoc-0.2.0/tests/test_render.py +360 -0
- kingmadoc-0.2.0/tests/test_security_domain_designs.py +94 -0
- kingmadoc-0.2.0/tests/test_skill.py +209 -0
- kingmadoc-0.2.0/tests/test_skill_explaining_code.py +238 -0
- kingmadoc-0.2.0/tests/test_skill_models.py +289 -0
- kingmadoc-0.2.0/tests/test_skills_install.py +217 -0
- kingmadoc-0.2.0/tests/test_source_dirs.py +59 -0
- kingmadoc-0.2.0/tests/test_summary_slug_diagram_defaults.py +64 -0
- kingmadoc-0.2.0/tests/test_technical_design.py +132 -0
- kingmadoc-0.2.0/tests/test_templating_security.py +64 -0
- kingmadoc-0.2.0/tests/test_verify.py +256 -0
- kingmadoc-0.2.0/tests/test_verify_locate.py +71 -0
- kingmadoc-0.2.0/tests/test_version.py +83 -0
- kingmadoc-0.2.0/tests/test_vscode_preview.py +105 -0
- kingmadoc-0.2.0/uv.lock +992 -0
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# KingmaDoc configuration. All keys are optional; shown values are the defaults.
|
|
2
|
+
|
|
3
|
+
# Where generated feature docs are written (relative to the project root).
|
|
4
|
+
output_dir: docs/features
|
|
5
|
+
|
|
6
|
+
# Plan template: a bundled name, or an explicit path such as ./my_plan.md.j2
|
|
7
|
+
# (relative to the project root). Templates always run sandboxed.
|
|
8
|
+
template: plan_default.md.j2
|
|
9
|
+
|
|
10
|
+
# Number of clarifying questions asked in `plan` mode (0-5).
|
|
11
|
+
max_questions: 5
|
|
12
|
+
|
|
13
|
+
project:
|
|
14
|
+
# Defaults to the project directory name.
|
|
15
|
+
name: null
|
|
16
|
+
description: ""
|
|
17
|
+
|
|
18
|
+
analyzer:
|
|
19
|
+
max_files: 5000 # maximum
|
|
20
|
+
tree_depth: 3
|
|
21
|
+
# Lines read per source file when scanning imports (imports sit at the top).
|
|
22
|
+
max_lines_per_file: 2000
|
|
23
|
+
exclude_dirs:
|
|
24
|
+
- ".git"
|
|
25
|
+
- ".hg"
|
|
26
|
+
- ".svn"
|
|
27
|
+
- ".venv"
|
|
28
|
+
- "venv"
|
|
29
|
+
- "env"
|
|
30
|
+
- "node_modules"
|
|
31
|
+
- "__pycache__"
|
|
32
|
+
- ".mypy_cache"
|
|
33
|
+
- ".pytest_cache"
|
|
34
|
+
- ".ruff_cache"
|
|
35
|
+
- ".tox"
|
|
36
|
+
- "dist"
|
|
37
|
+
- "build"
|
|
38
|
+
- "*.egg-info"
|
|
39
|
+
- "evals" # fixture projects for the skill evaluations
|
|
40
|
+
|
|
41
|
+
# Diagrams included in the plan doc.
|
|
42
|
+
diagrams:
|
|
43
|
+
- c4_context
|
|
44
|
+
- c4_container
|
|
45
|
+
|
|
46
|
+
# Diagram language: mermaid, plantuml (C4-PlantUML) or d2.
|
|
47
|
+
diagram_format: mermaid
|
|
48
|
+
|
|
49
|
+
# Optional extra documents written by `plan` next to the plan doc. `template` is a
|
|
50
|
+
# bundled name or an explicit path (e.g. ./my_design.md.j2); templates run sandboxed.
|
|
51
|
+
# `models` selects the design models (sections) of a document; default: all of them.
|
|
52
|
+
extra_designs:
|
|
53
|
+
functional_design:
|
|
54
|
+
# <slug>-functional-design.md: user flows, edge cases, business rules,
|
|
55
|
+
# permissions and roles.
|
|
56
|
+
enabled: false
|
|
57
|
+
template: functional_design.md.j2
|
|
58
|
+
models: []
|
|
59
|
+
technical_design:
|
|
60
|
+
# <slug>-technical-design.md: database schema, API contracts, error handling,
|
|
61
|
+
# performance and security considerations.
|
|
62
|
+
enabled: false
|
|
63
|
+
template: technical_design.md.j2
|
|
64
|
+
models: [dependency_graph]
|
|
65
|
+
domain_design:
|
|
66
|
+
# <slug>-domain-design.md: domain model and event storming.
|
|
67
|
+
enabled: false
|
|
68
|
+
template: domain_design.md.j2
|
|
69
|
+
models: [domain_model, event_storming]
|
|
70
|
+
security_design:
|
|
71
|
+
# <slug>-security-design.md: threat model (STRIDE) and who may do what.
|
|
72
|
+
enabled: false
|
|
73
|
+
template: security_design.md.j2
|
|
74
|
+
models: [threat_model, permissions]
|
|
75
|
+
|
|
76
|
+
# Architecture Decision Records: `kingmadoc adr "<title>"` writes docs/adr/<NNNN>-<slug>.md.
|
|
77
|
+
adr:
|
|
78
|
+
enabled: false
|
|
79
|
+
template: adr.md.j2
|
|
80
|
+
|
|
81
|
+
# Explainers written by the explaining-code agent skill ("explain this project").
|
|
82
|
+
# format: arc42 (the 12 arc42 sections, default) or c4 (compact zoom-in).
|
|
83
|
+
explain:
|
|
84
|
+
format: arc42
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Bug report
|
|
3
|
+
about: Something in KingmaDoc does not work as documented
|
|
4
|
+
title: ""
|
|
5
|
+
labels: bug
|
|
6
|
+
assignees: ""
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## What happened
|
|
10
|
+
|
|
11
|
+
<!-- A clear description of the bug. Include the full error message, if any. -->
|
|
12
|
+
|
|
13
|
+
## Steps to reproduce
|
|
14
|
+
|
|
15
|
+
1. <!-- e.g. `kingmadoc plan "Add login." --no-input` in a project with ... -->
|
|
16
|
+
2.
|
|
17
|
+
3.
|
|
18
|
+
|
|
19
|
+
## Expected behavior
|
|
20
|
+
|
|
21
|
+
<!-- What you expected to happen instead. -->
|
|
22
|
+
|
|
23
|
+
## Environment
|
|
24
|
+
|
|
25
|
+
- KingmaDoc version (`kingmadoc --version`, or "skill"):
|
|
26
|
+
- How you use it: CLI / Claude Code skill / Cursor / Codex / GitHub Copilot
|
|
27
|
+
- Python version (CLI only):
|
|
28
|
+
- Operating system:
|
|
29
|
+
- `diagram_format` and other non-default settings in `.featuredoc.yml`:
|
|
30
|
+
|
|
31
|
+
## Additional context
|
|
32
|
+
|
|
33
|
+
<!-- Generated docs (or the relevant part), screenshots, logs. Remove anything private. -->
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Feature request
|
|
3
|
+
about: Suggest an idea or improvement for KingmaDoc
|
|
4
|
+
title: ""
|
|
5
|
+
labels: enhancement
|
|
6
|
+
assignees: ""
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Problem
|
|
10
|
+
|
|
11
|
+
<!-- What are you trying to do, and what makes it hard today?
|
|
12
|
+
e.g. "After the agent finishes, I can't tell whether ... matches the plan." -->
|
|
13
|
+
|
|
14
|
+
## Proposed solution
|
|
15
|
+
|
|
16
|
+
<!-- What should KingmaDoc do? Which part: plan, verify, adr, diagrams, the skill, config? -->
|
|
17
|
+
|
|
18
|
+
## Alternatives considered
|
|
19
|
+
|
|
20
|
+
<!-- Other tools or workarounds you tried. -->
|
|
21
|
+
|
|
22
|
+
## Additional context
|
|
23
|
+
|
|
24
|
+
<!-- Example documents, diagrams, links. -->
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
|
|
8
|
+
permissions:
|
|
9
|
+
contents: read
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
lint:
|
|
13
|
+
name: lint (ruff, mypy, conventions)
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
17
|
+
with:
|
|
18
|
+
fetch-depth: 0 # the version comes from the git tags (hatch-vcs)
|
|
19
|
+
- uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
|
|
20
|
+
with:
|
|
21
|
+
python-version: "3.11"
|
|
22
|
+
cache: pip
|
|
23
|
+
cache-dependency-path: pyproject.toml
|
|
24
|
+
- name: Install
|
|
25
|
+
run: python -m pip install -e ".[dev]"
|
|
26
|
+
- name: Ruff
|
|
27
|
+
run: ruff check .
|
|
28
|
+
- name: mypy --strict
|
|
29
|
+
run: mypy
|
|
30
|
+
- name: Architecture contracts (import-linter)
|
|
31
|
+
run: lint-imports
|
|
32
|
+
- name: Skill variants up to date
|
|
33
|
+
run: python scripts/build_skill_variants.py --check
|
|
34
|
+
- name: Convention checker
|
|
35
|
+
run: python .claude/skills/checking-conventions/scripts/check_conventions.py
|
|
36
|
+
- name: Lock file up to date, no known vulnerabilities (pip-audit)
|
|
37
|
+
run: |
|
|
38
|
+
python -m pip install uv pip-audit
|
|
39
|
+
uv lock --check
|
|
40
|
+
uv export --frozen --all-extras --no-emit-project --format requirements-txt -o "$RUNNER_TEMP/requirements.txt"
|
|
41
|
+
pip-audit --strict -r "$RUNNER_TEMP/requirements.txt"
|
|
42
|
+
|
|
43
|
+
test:
|
|
44
|
+
name: pytest (${{ matrix.os }}, Python ${{ matrix.python-version }})
|
|
45
|
+
runs-on: ${{ matrix.os }}
|
|
46
|
+
strategy:
|
|
47
|
+
fail-fast: false
|
|
48
|
+
matrix:
|
|
49
|
+
os: [ubuntu-latest, macos-latest, windows-latest]
|
|
50
|
+
python-version: ["3.11", "3.12", "3.13"]
|
|
51
|
+
steps:
|
|
52
|
+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
53
|
+
with:
|
|
54
|
+
fetch-depth: 0 # the version comes from the git tags (hatch-vcs)
|
|
55
|
+
- uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
|
|
56
|
+
with:
|
|
57
|
+
python-version: ${{ matrix.python-version }}
|
|
58
|
+
cache: pip
|
|
59
|
+
cache-dependency-path: pyproject.toml
|
|
60
|
+
- name: Install
|
|
61
|
+
run: python -m pip install -e ".[dev]"
|
|
62
|
+
- name: Test
|
|
63
|
+
if: ${{ !(matrix.os == 'ubuntu-latest' && matrix.python-version == '3.11') }}
|
|
64
|
+
run: python -m pytest
|
|
65
|
+
- name: Test with branch coverage (minimum in pyproject.toml)
|
|
66
|
+
if: ${{ matrix.os == 'ubuntu-latest' && matrix.python-version == '3.11' }}
|
|
67
|
+
run: python -m pytest --cov --cov-report=term
|
|
68
|
+
- name: CLI smoke test
|
|
69
|
+
shell: bash
|
|
70
|
+
run: |
|
|
71
|
+
kingmadoc --help
|
|
72
|
+
cd "$RUNNER_TEMP"
|
|
73
|
+
kingmadoc init
|
|
74
|
+
kingmadoc plan "Test feature." --no-input
|
|
75
|
+
test -f docs/features/test-feature-plan.md
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
name: Release
|
|
2
|
+
|
|
3
|
+
# Push a tag like v0.2.0: build, publish to PyPI (trusted publishing, no API token) and
|
|
4
|
+
# create the GitHub release with the built files. One-time setup: see RELEASING.md.
|
|
5
|
+
on:
|
|
6
|
+
push:
|
|
7
|
+
tags: ["v*"]
|
|
8
|
+
|
|
9
|
+
permissions:
|
|
10
|
+
contents: read
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
build:
|
|
14
|
+
name: Build and test the distribution
|
|
15
|
+
runs-on: ubuntu-latest
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
18
|
+
with:
|
|
19
|
+
fetch-depth: 0 # the version comes from the tag (hatch-vcs)
|
|
20
|
+
- uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
|
|
21
|
+
with:
|
|
22
|
+
python-version: "3.11"
|
|
23
|
+
- name: Build
|
|
24
|
+
run: |
|
|
25
|
+
python -m pip install build twine
|
|
26
|
+
python -m build
|
|
27
|
+
twine check --strict dist/*
|
|
28
|
+
- name: The version is the tag
|
|
29
|
+
run: |
|
|
30
|
+
version="${GITHUB_REF_NAME#v}"
|
|
31
|
+
ls dist/kingmadoc-"$version".tar.gz dist/kingmadoc-"$version"-py3-none-any.whl
|
|
32
|
+
- name: The wheel works on its own (skills and templates included)
|
|
33
|
+
run: |
|
|
34
|
+
python -m venv "$RUNNER_TEMP/venv"
|
|
35
|
+
"$RUNNER_TEMP/venv/bin/pip" install dist/*.whl
|
|
36
|
+
cd "$RUNNER_TEMP"
|
|
37
|
+
"$RUNNER_TEMP/venv/bin/kingmadoc" --version
|
|
38
|
+
"$RUNNER_TEMP/venv/bin/kingmadoc" plan "Release check." --no-input --stdout > /dev/null
|
|
39
|
+
"$RUNNER_TEMP/venv/bin/kingmadoc" skills install
|
|
40
|
+
test -f .claude/skills/explaining-code/SKILL.md
|
|
41
|
+
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
|
42
|
+
with:
|
|
43
|
+
name: dist
|
|
44
|
+
path: dist/
|
|
45
|
+
if-no-files-found: error
|
|
46
|
+
|
|
47
|
+
pypi:
|
|
48
|
+
name: Publish to PyPI
|
|
49
|
+
needs: build
|
|
50
|
+
runs-on: ubuntu-latest
|
|
51
|
+
environment:
|
|
52
|
+
name: pypi
|
|
53
|
+
url: https://pypi.org/p/kingmadoc
|
|
54
|
+
permissions:
|
|
55
|
+
id-token: write # trusted publishing
|
|
56
|
+
steps:
|
|
57
|
+
- uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
|
|
58
|
+
with:
|
|
59
|
+
name: dist
|
|
60
|
+
path: dist/
|
|
61
|
+
- uses: pypa/gh-action-pypi-publish@dc37677b2e1c63e2034f94d8a5b11f265b73ba33 # v1.14.2
|
|
62
|
+
|
|
63
|
+
github-release:
|
|
64
|
+
name: GitHub release
|
|
65
|
+
needs: pypi
|
|
66
|
+
runs-on: ubuntu-latest
|
|
67
|
+
permissions:
|
|
68
|
+
contents: write
|
|
69
|
+
steps:
|
|
70
|
+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
71
|
+
- uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
|
|
72
|
+
with:
|
|
73
|
+
name: dist
|
|
74
|
+
path: dist/
|
|
75
|
+
- name: Create the release with the changelog section
|
|
76
|
+
env:
|
|
77
|
+
GH_TOKEN: ${{ github.token }}
|
|
78
|
+
run: |
|
|
79
|
+
version="${GITHUB_REF_NAME#v}"
|
|
80
|
+
awk -v v="$version" '
|
|
81
|
+
$0 ~ "^## \\[" v "\\]" { found = 1; next }
|
|
82
|
+
found && /^## \[/ { exit }
|
|
83
|
+
found { print }
|
|
84
|
+
' CHANGELOG.md > "$RUNNER_TEMP/notes.md"
|
|
85
|
+
gh release create "$GITHUB_REF_NAME" dist/* --title "KingmaDoc $version" \
|
|
86
|
+
--notes-file "$RUNNER_TEMP/notes.md" --verify-tag
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Byte-compiled / cache
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
.mypy_cache/
|
|
5
|
+
.pytest_cache/
|
|
6
|
+
.ruff_cache/
|
|
7
|
+
|
|
8
|
+
# Packaging
|
|
9
|
+
build/
|
|
10
|
+
dist/
|
|
11
|
+
*.egg-info/
|
|
12
|
+
.eggs/
|
|
13
|
+
|
|
14
|
+
# Environments
|
|
15
|
+
.venv/
|
|
16
|
+
venv/
|
|
17
|
+
env/
|
|
18
|
+
.env
|
|
19
|
+
|
|
20
|
+
# Test / coverage
|
|
21
|
+
.coverage
|
|
22
|
+
.coverage.*
|
|
23
|
+
htmlcov/
|
|
24
|
+
.tox/
|
|
25
|
+
.nox/
|
|
26
|
+
|
|
27
|
+
# Editors / OS
|
|
28
|
+
.idea/
|
|
29
|
+
.vscode/
|
|
30
|
+
.DS_Store
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
## [0.2.0] - 2026-09-27
|
|
11
|
+
|
|
12
|
+
Explain existing code with pictures, machine-readable plans, and a `verify` that
|
|
13
|
+
compares the code with its plan. Upgrading from 0.1.1:
|
|
14
|
+
|
|
15
|
+
- Update with `pipx reinstall kingmadoc` (or, once on PyPI, `pipx upgrade kingmadoc`),
|
|
16
|
+
then run `kingmadoc skills install` again; it updates the skills without `--force`.
|
|
17
|
+
- Plans now start with YAML frontmatter and have a "Requirements" section. Plans from
|
|
18
|
+
0.1.x have neither: `kingmadoc check` says so, and `verify` reports them as
|
|
19
|
+
"Not verified". Regenerate the plan, or add the frontmatter by hand
|
|
20
|
+
(`skill/reference/formats.md`).
|
|
21
|
+
- `kingmadoc verify` now compares the code with the plan and changes the plan's status
|
|
22
|
+
(`implemented` / `partial`); it runs project commands only with `--run-checks`.
|
|
23
|
+
- `.vscode/settings.json` is only written with `skills install --vscode`.
|
|
24
|
+
- Python API: `skills.install_skills` returns an `InstallResult`; `verify.stub` is
|
|
25
|
+
replaced by `verify.locate` (`find_plan`) and `verify.report` (`render_verify`).
|
|
26
|
+
|
|
27
|
+
### Added
|
|
28
|
+
|
|
29
|
+
**Explain existing code** (agent skill `explaining-code` 5.4, roadmap WP12)
|
|
30
|
+
|
|
31
|
+
- Explains a feature, a branch (what it changed), a project or a part of one with
|
|
32
|
+
pictures: an arc42 document by default, or the compact C4 format
|
|
33
|
+
(`explain.format: c4`); one document, or functional and technical apart
|
|
34
|
+
(`explain.documents: split`). No audit or risk list; at most three questions.
|
|
35
|
+
- Real C4 diagrams in Simon Brown's notation, plus the models the code calls for, picked
|
|
36
|
+
from a decision table: UML sequence, state machine, class and domain model, package,
|
|
37
|
+
activity with swimlanes, use case, ER, data flow with trust boundaries, event flow and
|
|
38
|
+
DDD context map. Tests check that every example follows its notation and compiles.
|
|
39
|
+
- One folder per subject, `docs/explain/<NNNN>-<name>/`, with an ID that is never
|
|
40
|
+
reused: `kingmadoc explain new "<name>"` picks or reuses it and keeps the index
|
|
41
|
+
`docs/explain/README.md` up to date.
|
|
42
|
+
- `kingmadoc explain facts [--base REF] [--json]`: what can be read from the code
|
|
43
|
+
without guessing, for the agent to draw from: the stack, project references (.NET),
|
|
44
|
+
Python and JavaScript/TypeScript module dependencies, routes with their access rules
|
|
45
|
+
(ASP.NET, Next.js, Django, FastAPI, Flask, Express), .NET services, the data model
|
|
46
|
+
(EF Core, Prisma, Django, SQLAlchemy, TypeORM) and, with `--base`, a branch's commits
|
|
47
|
+
and changed files.
|
|
48
|
+
- `kingmadoc explain status [--check]`: which explainers the code changed under since
|
|
49
|
+
the commit they are based on.
|
|
50
|
+
|
|
51
|
+
**Pictures**
|
|
52
|
+
|
|
53
|
+
- `kingmadoc render <doc>`: turns the D2 diagrams in a Markdown document into SVG images
|
|
54
|
+
next to it; the document shows only the pictures, the sources go to `img/*.d2`. The
|
|
55
|
+
images follow the viewer's dark mode (`--light` for light only). D2 is downloaded on
|
|
56
|
+
first use (pinned, SHA-256-verified; `KINGMADOC_D2_DOWNLOAD=0` to opt out).
|
|
57
|
+
|
|
58
|
+
**Plans and verification** (roadmap WP1, WP2)
|
|
59
|
+
|
|
60
|
+
- Plans start with YAML frontmatter (`kingmadoc: 1`, `feature`, `status`,
|
|
61
|
+
`requirements`, `files_expected`) and have a "Requirements" section with `REQ-n` IDs
|
|
62
|
+
from the acceptance criteria. `kingmadoc check <slug>` validates a plan;
|
|
63
|
+
`kingmadoc approve <slug>` sets `status: approved`, the gate before code.
|
|
64
|
+
- `kingmadoc verify <slug>` compares the code with its plan: the files changed since
|
|
65
|
+
the plan (git, including uncommitted work), expected files never touched, changes
|
|
66
|
+
outside the plan, `REQ-n` no test or commit mentions, containers added or gone, and
|
|
67
|
+
code written before approval. Build, test and lint (from `verify:` in the config, or
|
|
68
|
+
detected) run only with `--run-checks`. The plan's status becomes `implemented` or
|
|
69
|
+
`partial`.
|
|
70
|
+
- Design documents: design models per document (`extra_designs.<document>.models`),
|
|
71
|
+
`domain_design` (domain model, event storming) and `security_design` (STRIDE threat
|
|
72
|
+
model, permissions matrix); `technical_design` gets a module dependency graph, and
|
|
73
|
+
`kingmadoc analyze` reports `module_dependencies`.
|
|
74
|
+
|
|
75
|
+
**Installing and updating**
|
|
76
|
+
|
|
77
|
+
- `kingmadoc skills install [--agent claude|cursor|codex|copilot]` installs both
|
|
78
|
+
skills into the project and updates them later without `--force` (only local edits
|
|
79
|
+
need it); `--vscode` makes VS Code open explainers as a rendered preview.
|
|
80
|
+
- `kingmadoc --version` shows the installed git commit (`0.2.0 (git 1a2b3c4)`).
|
|
81
|
+
|
|
82
|
+
**Development**
|
|
83
|
+
|
|
84
|
+
- Skill evaluations (roadmap WP5): scenarios in `evals/`, run with
|
|
85
|
+
`python scripts/run_evals.py --compare --record`.
|
|
86
|
+
|
|
87
|
+
### Changed
|
|
88
|
+
|
|
89
|
+
- The version comes from the git tag (`hatch-vcs`): every commit after a release has a
|
|
90
|
+
higher development version, so updates of a git install are visible.
|
|
91
|
+
- Release workflow: a `v*` tag builds, tests and publishes to PyPI (trusted
|
|
92
|
+
publishing) and creates the GitHub release (`docs/releasing.md`).
|
|
93
|
+
- The `kingmadoc` skill (1.1) is split into `SKILL.md` and `reference/`
|
|
94
|
+
(formats, diagram rules); the Cursor, Codex and Copilot files still hold everything.
|
|
95
|
+
- Quality: branch coverage with a 90 % minimum, property-based tests (Hypothesis),
|
|
96
|
+
`import-linter` contracts for the architecture rules, `uv.lock`, `pip-audit` and
|
|
97
|
+
Ruff's security rules in CI.
|
|
98
|
+
- API: `skills.install_skills` returns an `InstallResult`; `verify.stub` is replaced by
|
|
99
|
+
`verify.locate` and `verify.report`.
|
|
100
|
+
|
|
101
|
+
### Fixed
|
|
102
|
+
|
|
103
|
+
- Analyzer: imports in test directories no longer add frameworks to the detected stack.
|
|
104
|
+
- Analyzer: build output of Next.js (`.next/`), Nuxt and SvelteKit is no longer
|
|
105
|
+
analyzed as source.
|
|
106
|
+
|
|
107
|
+
## [0.1.1] - 2026-09-26
|
|
108
|
+
|
|
109
|
+
First public release, including all fixes from the pre-release review. Upgrading from
|
|
110
|
+
the unpublished 0.1.0: move `extra_designs.adr` to a
|
|
111
|
+
top-level `adr:` block, and use `kingmadoc analyze --json` instead of `plan --json`.
|
|
112
|
+
|
|
113
|
+
### Security
|
|
114
|
+
|
|
115
|
+
- Templates: `kingmadoc` no longer loads templates from the analyzed project's root,
|
|
116
|
+
so running it in an untrusted repository cannot execute code from that repository.
|
|
117
|
+
All templates render in Jinja's sandbox, and a project template is used only when
|
|
118
|
+
`template:` names an explicit path (`ConfigError` if it is missing or not a file).
|
|
119
|
+
- Config: `output_dir` must resolve inside the project root (symlinks resolved first);
|
|
120
|
+
a repository's config can no longer make `plan` write outside the project.
|
|
121
|
+
- Analyzer: import scanning no longer takes quadratic time on long runs of blank lines;
|
|
122
|
+
a crafted file could stall `plan` for minutes (50k blank lines: 75 s → 0.04 s).
|
|
123
|
+
|
|
124
|
+
### Fixed
|
|
125
|
+
|
|
126
|
+
- CLI: `plan --stdout` no longer crashes with `UnicodeEncodeError` when stdout is not
|
|
127
|
+
UTF-8 (piped output on Windows); stdout is written as UTF-8.
|
|
128
|
+
- CLI: `verify` no longer crashes with an unhandled `ValueError` when `output_dir` is an
|
|
129
|
+
absolute path outside the project; it reports a config error instead.
|
|
130
|
+
- Documents: writing several documents is now truly all-or-nothing; a failure part-way
|
|
131
|
+
restores replaced files and removes new ones.
|
|
132
|
+
- Analyzer: a manifest with a wrongly typed table or list (e.g. `dependencies = 5`) no
|
|
133
|
+
longer crashes the analysis.
|
|
134
|
+
- Analyzer: manifests saved with a UTF-8 byte-order mark are parsed instead of skipped.
|
|
135
|
+
- Analyzer: Compose images with a registry port (`registry.local:5000/postgres:16`)
|
|
136
|
+
are recognized by their image name.
|
|
137
|
+
- Summaries: the first sentence is no longer cut at `e.g.`, `i.e.`, `etc.`, `vs.`,
|
|
138
|
+
`cf.` or `approx.`, and only ends before a capital letter.
|
|
139
|
+
- Slugs: accented letters are transliterated (`café` → `cafe`); descriptions without
|
|
140
|
+
Latin letters get a short hash instead of all sharing the slug `feature`.
|
|
141
|
+
- Diagrams: test directories (`__tests__`, `spec`, `src/tests`, ...) are no longer
|
|
142
|
+
inferred as C4 containers, and loose `src/*.py` files no longer add a `src` container
|
|
143
|
+
next to `src/<pkg>`.
|
|
144
|
+
- Diagrams: elements with the same name no longer produce wrong arrows
|
|
145
|
+
(`Rel(user, user)`); duplicate names are rejected, and generated names are unique.
|
|
146
|
+
- ADRs: date-named files such as `docs/adr/2024-q3-review.md` no longer set the next
|
|
147
|
+
ADR number.
|
|
148
|
+
|
|
149
|
+
### Changed
|
|
150
|
+
|
|
151
|
+
- Config: `adr` is a top-level block, `adr: {enabled, template}`; `extra_designs.adr`
|
|
152
|
+
is rejected as an unknown key.
|
|
153
|
+
- Config: each extra design (`extra_designs.<name>.template`) and `adr.template` can
|
|
154
|
+
select its own template.
|
|
155
|
+
- CLI: `plan` always requires a description; its `--json` option moved to
|
|
156
|
+
`kingmadoc analyze --json`.
|
|
157
|
+
- Diagrams: `render_context(relationships=None)` is replaced by the keyword
|
|
158
|
+
`default_relationships: bool = True`; explicit relationships are drawn in addition to
|
|
159
|
+
the default arrows.
|
|
160
|
+
- API: `write_document` takes `(path, content)`, like `write_documents`.
|
|
161
|
+
- Packaging: bundled templates live in `src/kingmadoc/templates/`; the sdist no longer
|
|
162
|
+
contains the repository's Claude Code dev tooling (`.claude/`).
|
|
163
|
+
- Development: Ruff and `mypy --strict` are enforced in CI (new `lint` job), and
|
|
164
|
+
GitHub Actions are pinned to commit SHAs.
|
|
165
|
+
|
|
166
|
+
### Added
|
|
167
|
+
|
|
168
|
+
- CLI: `kingmadoc analyze [--json]` prints the codebase analysis.
|
|
169
|
+
- Config: `analyzer.max_lines_per_file` (default 2000) limits how many lines per source
|
|
170
|
+
file are read when detecting frameworks; manifests are always read in full.
|
|
171
|
+
- Analyzer: Cargo `[workspace.dependencies]` and `[target.*.dependencies]`, PEP 735
|
|
172
|
+
`[dependency-groups]`, Poetry `[tool.poetry.group.*.dependencies]` and npm
|
|
173
|
+
`optionalDependencies` are read.
|
|
174
|
+
- Generator: importing it fails if `EXTRA_DESIGNS` and the `extra_designs` config
|
|
175
|
+
fields disagree, instead of failing during `plan`.
|
|
176
|
+
- Tests for `init`, custom templates, Ctrl-C during questions, atomic writes, the skill
|
|
177
|
+
variant `--check`, Poetry dependencies and `verify --config`.
|
|
178
|
+
|
|
179
|
+
## [0.1.0] - 2026-09-26
|
|
180
|
+
|
|
181
|
+
Internal milestone; never published. Its contents first shipped in 0.1.1.
|
|
182
|
+
|
|
183
|
+
### Added
|
|
184
|
+
|
|
185
|
+
- `kingmadoc plan "<description>"`: analyzes the codebase, asks up to five clarifying
|
|
186
|
+
questions and writes `docs/features/<slug>-plan.md` with a one-sentence summary,
|
|
187
|
+
scope (in / out), assumptions, risks, C4 Context and C4 Container diagrams, open
|
|
188
|
+
questions and a codebase appendix. Options: `--no-input`, `--stdout`, `--output`,
|
|
189
|
+
`--force`, `--config`, `--root`.
|
|
190
|
+
- `kingmadoc plan --json`: the codebase analysis as JSON (file count, language
|
|
191
|
+
breakdown, top-level directories, entry points, config files, test directories and
|
|
192
|
+
detected stack). The analysis reads `pyproject.toml`, `requirements.txt`,
|
|
193
|
+
`package.json`, `go.mod`, `Cargo.toml` and Docker Compose files, and stops at 5000 files.
|
|
194
|
+
- `kingmadoc verify <slug>`: work-in-progress stub that writes a placeholder
|
|
195
|
+
`<slug>-verify.md` next to the plan (exit code 1 if the plan does not exist).
|
|
196
|
+
- `kingmadoc adr "<title>"`: numbered Architecture Decision Records in
|
|
197
|
+
`docs/adr/<NNNN>-<slug>.md`, enabled with `extra_designs.adr.enabled`.
|
|
198
|
+
- `kingmadoc init`: writes `.featuredoc.yml` with every default and a comment per key.
|
|
199
|
+
- Optional extra documents next to the plan: `<slug>-functional-design.md` (user flows,
|
|
200
|
+
edge cases, business rules, permissions) and `<slug>-technical-design.md` (database
|
|
201
|
+
schema, API contracts, error handling, performance, security).
|
|
202
|
+
- Diagram backends: Mermaid (default), PlantUML (C4-PlantUML) and D2, selected with
|
|
203
|
+
`diagram_format`, each with C4 Context/Container/Component, sequence and class diagrams.
|
|
204
|
+
- Markdown-only agent skill `skill/SKILL.md` for Claude Code, with generated variants
|
|
205
|
+
for Cursor (`skill/cursor.md`), Codex (`skill/codex.md`) and GitHub Copilot
|
|
206
|
+
(`skill/copilot.md`). The skill performs plan and full verify without Python.
|
|
207
|
+
- Documentation: README, CONTRIBUTING, conventions (`docs/conventions.md`) and an
|
|
208
|
+
example plan doc (`examples/verify-mode-plan.md`).
|
|
209
|
+
- CI on Python 3.11–3.13 on Linux, macOS and Windows.
|
|
210
|
+
|
|
211
|
+
[Unreleased]: https://github.com/ATkingma/KingmaDoc/compare/v0.2.0...HEAD
|
|
212
|
+
[0.2.0]: https://github.com/ATkingma/KingmaDoc/compare/v0.1.1...v0.2.0
|
|
213
|
+
[0.1.1]: https://github.com/ATkingma/KingmaDoc/compare/v0.1.0...v0.1.1
|
|
214
|
+
[0.1.0]: https://github.com/ATkingma/KingmaDoc/releases/tag/v0.1.0
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# CLAUDE.md
|
|
2
|
+
|
|
3
|
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
+
|
|
5
|
+
## Project
|
|
6
|
+
|
|
7
|
+
KingmaDoc is a Python CLI (Click, Jinja2, PyYAML) that generates feature docs for AI coding agents, to prevent "code blindness": `plan` writes a Feature Design Doc before implementation (C4/sequence/class diagrams in Mermaid, PlantUML or D2); `verify` writes a Feature Verification Doc afterwards (deviations from the plan, and build/test/lint results with `--run-checks`). `plan` generates C4 Context + Container.
|
|
8
|
+
|
|
9
|
+
## Commands
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
uv venv -p 3.11 .venv && uv pip install -p .venv -e '.[dev]' # setup
|
|
13
|
+
.venv/bin/pytest -q # all tests
|
|
14
|
+
.venv/bin/pytest tests/test_config.py::test_unknown_key_raises # single test
|
|
15
|
+
.venv/bin/kingmadoc plan "Add a feature." --no-input --stdout # smoke test
|
|
16
|
+
python3 .claude/skills/checking-conventions/scripts/check_conventions.py # convention check (also runs ruff + mypy when in .venv)
|
|
17
|
+
.venv/bin/ruff check . && .venv/bin/mypy # lint + mypy --strict
|
|
18
|
+
.venv/bin/lint-imports && .venv/bin/pytest --cov # architecture contracts; branch coverage (min 90 %)
|
|
19
|
+
.venv/bin/python scripts/run_evals.py --compare --record # skill evals (runs real agents; evals/README.md)
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
The version comes from git tags (`hatch-vcs`; never set it by hand, `kingmadoc.__version__` reads the installed metadata); releases: `docs/releasing.md`. After changing dependencies in `pyproject.toml`, run `uv lock` (CI checks `uv.lock` and runs `pip-audit`). Ruff includes the `S` (bandit) rules; justify a `# noqa: S…` in a comment. A new top-level module must be added to the E1 contract in `[tool.importlinter]` (a test checks it).
|
|
23
|
+
|
|
24
|
+
A Stop hook (`.claude/settings.json`) runs the convention checker after every turn with uncommitted changes and feeds violations back. Fix them; for manual rules use the `checking-conventions` skill (repo dev tool, not the product skill).
|
|
25
|
+
|
|
26
|
+
Regenerate `examples/verify-mode-plan.md` after changing the template or generator (it's output of running `plan` on this repo with `-o examples/verify-mode-plan.md --force`; keep its answers).
|
|
27
|
+
|
|
28
|
+
## Architecture
|
|
29
|
+
|
|
30
|
+
Flow for `plan "<description>"` (`cli.py`): `config.load_config` → `plan.analyzer.analyze` → `plan.generator.build_questions` (prompts on stderr so `--stdout` stays clean; `--no-input`/closed stdin leaves them unanswered → "Open questions") → `plan.generator.build_plan_context` (pure; CLI passes `now`) → `render_plan` (every `PlanContext` field is a template variable) → `documents.write_documents` (all-or-nothing) to `<output_dir>/<slug>-plan.md`, plus one file per enabled `extra_designs.<name>` (`<slug>-functional-design.md`, `<slug>-technical-design.md`) via `render_extra_design`, each with its own `template:` and `models:` (design-model sections rendered by `plan/models.py`; names per document in `config.DOCUMENT_MODELS`, checked against the registry at import time). To add an extra doc type: a field on `config.ExtraDesignsConfig` (its default sets the bundled template), an `ExtraDesign(name, suffix)` in `generator.EXTRA_DESIGNS` (checked against the config fields at import time), a template, and a format block in `skill/reference/formats.md` → prints one path per line.
|
|
31
|
+
|
|
32
|
+
- `config.py`: frozen dataclasses with defaults; `parse_config` rejects unknown keys and wrong types. `default_config_yaml()` produces the `init` output and must stay equal to the dataclass defaults (enforced by a test).
|
|
33
|
+
- `plan/analyzer.py`: pathlib walk with fnmatch excludes ("glob", hard cap `MAX_FILES_LIMIT` = 5000), manifest parsing (`pyproject.toml`, `requirements.txt`, `package.json`, `go.mod`, `Cargo.toml`, compose files → `DEPENDENCY_TECH`), regex import scanning ("grep"). Returns an immutable `CodebaseReport` (`kingmadoc analyze` prints it via `format_report`, `--json` via `report_to_dict`); `source_dirs` drives container inference (descends into `src/` layouts, skips tests/docs/examples).
|
|
34
|
+
- `skill/SKILL.md`: the product skill (Markdown-only KingmaDoc for users without Python; not the repo's `checking-conventions` dev skill): the workflow, under 250 lines. Its document formats live in `skill/reference/formats.md` and must keep the same headings as `src/kingmadoc/templates/plan_default.md.j2`, the extra-design templates and `verify/report.py` — `tests/test_skill.py` fails otherwise, so change both together; the Mermaid rules in `skill/reference/diagram-rules.md`. SKILL.md keeps a `## Output format` / `## Diagram rules` stub that links each reference. `skill/cursor.md`, `codex.md`, `copilot.md` are single files generated by `scripts/build_skill_variants.py`, which inlines each reference in place of its stub — never edit them; rerun the script after changing SKILL.md or a reference (`tests/test_skill.py` fails on stale variants). `kingmadoc skills install` copies SKILL.md plus `reference/`.
|
|
35
|
+
- `adr.py` (`kingmadoc adr "<title>"`, gated by the top-level `adr.enabled`; `adr.template` selects the template): `adr_path` → `next_number` (max existing + 1, never reused) + `adr_filename` → `render_adr` (`templates/adr.md.j2`, bundled) → `docs/adr/<NNNN>-<slug>.md`. Not a mode; shares `naming.slugify` and `templating.load_template` with plan.
|
|
36
|
+
- `render.py` (`kingmadoc render <doc>`): renders each ```` ```d2 ```` block to `img/<doc>-<n>.svg` (D2 via `d2_binary.ensure_d2`), moves its source to `img/<doc>-<n>.d2`, and leaves only `<!-- kingmadoc:diagram img/<doc>-<n>.d2 -->` + the image in the document (the comment is invisible in previews; re-rendering reads the `.d2` files, so edit those). Converts the older `<details>` format. Renders everything to a temp dir first, so a failing diagram changes nothing.
|
|
37
|
+
- `d2_binary.py`: `ensure_d2` finds D2 (`KINGMADOC_D2`, PATH, cache) or downloads the pinned release once into the user cache; the SHA-256 per platform is pinned in `D2_ASSETS` (update version + all hashes together, cross-checked with the release's SHA256SUMS). `skills.py` + `kingmadoc skills install`: the skills in `skill/` ship as package data (hatch force-include) and are copied into the agent's skills dir; a `.kingmadoc-skill.json` manifest per skill folder records the installed hashes, so a reinstall updates unchanged files and only blocks local edits (`PREVIOUS_RELEASES` is the frozen hash list for installs from before the manifest).
|
|
38
|
+
- `skill/explaining-code/`: second product skill; explains existing code (feature, branch, project, part) with D2 pictures, one folder per subject `docs/explain/<NNNN>-<slug>/README.md` (`explain.py` + `kingmadoc explain new`: next ID, never reused, same subject reuses its folder; regenerates the index `docs/explain/README.md`, also after `render` of such a file; `explain status` → `freshness`: `git diff --relative --name-only <Based on commit>` over the paths the explainer names in code spans (else the whole project), excluding `docs/explain`; `render` names a README's images `figure-<n>`). `SKILL.md` = workflow and D2 examples; the formats are `reference/arc42.md` (default) and `reference/c4.md`, chosen by `explain.format`; `reference/split.md` for `explain.documents: split` (cover + `functional.md` + `technical.md`); `reference/c4-model.md` (Simon Brown's C4: abstractions, 7 diagrams, notation, D2 style block, checklist) and `reference/models.md` (decision table + rules + one example per other model). `tests/test_skill_explaining_code.py` checks its format and compiles every D2 example with the real `d2` when available (`D2_BIN`); `tests/test_skill_models.py` checks every example obeys its model's rules. D2 pitfalls: quote labels with `[`/`:`; `source-arrowhead` only works on `<->`.
|
|
39
|
+
- `facts/` (`kingmadoc explain facts`): pure parsers `projects.project_references` (.csproj) and `data_model.data_model` (EF Core via `DbSet<T>`, Prisma, Django, SQLAlchemy, TypeORM; regex, test files skipped) → frozen `Entity`/`Field`/`Relation`; `routes.routes` (ASP.NET controllers + minimal APIs, Next.js app/pages, Django urls + decorators, FastAPI, Flask, Express; `access` = what the code states), `services.services` (.NET DI), `js_modules.js_dependencies` (relative + tsconfig `paths` imports, `plan.dependencies.collapse` above 25 modules); `branch.branch_changes` (git I/O via `git.run_git`, merge base → working tree); `collect.collect_facts` reads files from the `CodebaseReport` and renders Markdown/JSON.
|
|
40
|
+
- `plandoc.py` (not a mode; pure): the plan frontmatter (B2) and `REQ-n` requirements (B1): `check_plan` (every problem as a message), `parse_plan` → `PlanMeta`, `set_status` (frontmatter + header table). `kingmadoc check <slug>` / `approve <slug>` in `cli.py` use `verify.locate.find_plan`. The template renders the frontmatter from `PlanContext.slug/requirements/files_expected` (`generator.requirements_from_answers`: acceptance answer split on `;`/newlines; `files_from_answers`: existing paths only).
|
|
41
|
+
- `verify/` (`kingmadoc verify <slug> [--run-checks]`): `locate.find_plan` (bad slug / missing plan → `VerificationError`) → `changes.detect_changes` (git; base = parent of the commit that added the plan, else last commit before **Generated** + 59 s; working tree incl. untracked; the plan's folder ignored) → `deviations.find_deviations` (pure: draft plan with code = process, `files_expected` untouched / changes outside, `REQ-n` not mentioned in tests or commit messages, containers vs `planned_containers` from the plan text; the CLI passes `infer_containers` names since verify may not import plan) → `commands.detect_commands` (config `verify:` > Makefile > npm > cargo > go > dotnet > pytest/ruff) and `run_check` (no shell; only with `--run-checks`, never enabled by the repo's config) → `report.render_verify` + `verify_status`; the plan's status becomes `implemented`/`partial` unless draft or not verified (written together, `write_documents`). Modes may not import each other (E5, auto-checked), so shared I/O lives in `documents.py`.
|
|
42
|
+
- `diagrams/`: backend pattern, selected by `diagram_format` (`mermaid` default, `plantuml`, `d2`) via `diagrams.get_backend`. `base.py` has the `DiagramBackend` Protocol (`render_context/container/component/sequence/class`) and the shared pure model: `build_*` validate input, assign unique aliases and resolve relationships into frozen `Diagram`/`Node`/`Edge`. Backend modules (`mermaid.py`, `plantuml.py`, `d2.py`) only format that model and return a fenced block (templates must not add fences). Escaping differs per backend and is verified against the real tools: Mermaid `"`→`#quot;` (C4 titles drop `#`/`;`), PlantUML `"`→`<U+0022>`, D2 escapes `\`, `"`, `$`. Adding a backend: a module, an entry in `diagrams.BACKENDS` and `config.DIAGRAM_FORMATS`, snapshots via `KINGMADOC_UPDATE_SNAPSHOTS=1 pytest tests/test_diagram_backends.py`. Extra-doc templates pick their ER/flowchart placeholder by `diagram_format`. No knowledge of analysis: `generator.build_plan_context` maps analysis → C4 elements.
|
|
43
|
+
- Templates live in `src/kingmadoc/templates/` (shipped as package data). Security: `templating.load_template` loads bundled templates only from that package dir and never searches the analyzed project's root; a project template is used only when a `template:` setting gives an explicit path (`ConfigError` if missing or not a file). Every template renders in Jinja's `SandboxedEnvironment` (repos may be untrusted; see `tests/test_templating_security.py`). Jinja uses `StrictUndefined`, so every template variable must be passed.
|
|
44
|
+
|
|
45
|
+
## Conventions
|
|
46
|
+
|
|
47
|
+
All docs are indexed in `docs/index.md` (English only; add new `.md` files there). Rules: the **Rule summary** table at the top of `docs/conventions.md` (ID, status, auto/manual); open a rule's section only when needed. Key rules:
|
|
48
|
+
|
|
49
|
+
- Classes only for frozen dataclasses (data) and `typing.Protocol` extension points (behavior); everything else plain functions. Composition, not inheritance.
|
|
50
|
+
- Keep I/O in the shell (`cli.py`, file walking/writing); diagram builders, config parsing and detection stay pure.
|
|
51
|
+
- Type hints and docstrings on all public functions; `pathlib.Path` for all paths.
|
|
52
|
+
- No global state; config is passed explicitly, never imported as a module-level object.
|
|
53
|
+
- Raise subclasses of `kingmadoc.exceptions.KingmaDocError`; the CLI converts them to `click.ClickException`.
|