rb-textcheck 0.3.6__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.
- rb_textcheck-0.3.6/.gitignore +20 -0
- rb_textcheck-0.3.6/LICENSE +21 -0
- rb_textcheck-0.3.6/PKG-INFO +138 -0
- rb_textcheck-0.3.6/README.md +115 -0
- rb_textcheck-0.3.6/pyproject.toml +172 -0
- rb_textcheck-0.3.6/src/rb_textcheck/__init__.py +36 -0
- rb_textcheck-0.3.6/src/rb_textcheck/_distribution.py +24 -0
- rb_textcheck-0.3.6/src/rb_textcheck/cli.py +73 -0
- rb_textcheck-0.3.6/src/rb_textcheck/commands/__init__.py +1 -0
- rb_textcheck-0.3.6/src/rb_textcheck/commands/auth.py +66 -0
- rb_textcheck-0.3.6/src/rb_textcheck/commands/check.py +37 -0
- rb_textcheck-0.3.6/src/rb_textcheck/commands/config.py +87 -0
- rb_textcheck-0.3.6/src/rb_textcheck/commands/describe.py +34 -0
- rb_textcheck-0.3.6/src/rb_textcheck/commands/doctor.py +43 -0
- rb_textcheck-0.3.6/src/rb_textcheck/commands/fix.py +45 -0
- rb_textcheck-0.3.6/src/rb_textcheck/commands/init.py +48 -0
- rb_textcheck-0.3.6/src/rb_textcheck/commands/profile.py +35 -0
- rb_textcheck-0.3.6/src/rb_textcheck/commands/project.py +55 -0
- rb_textcheck-0.3.6/src/rb_textcheck/commands/rules.py +18 -0
- rb_textcheck-0.3.6/src/rb_textcheck/commands/skill.py +138 -0
- rb_textcheck-0.3.6/src/rb_textcheck/commands/status.py +35 -0
- rb_textcheck-0.3.6/src/rb_textcheck/core/__init__.py +1 -0
- rb_textcheck-0.3.6/src/rb_textcheck/core/checks.py +757 -0
- rb_textcheck-0.3.6/src/rb_textcheck/core/data_files.py +20 -0
- rb_textcheck-0.3.6/src/rb_textcheck/core/deps.py +165 -0
- rb_textcheck-0.3.6/src/rb_textcheck/core/errors.py +239 -0
- rb_textcheck-0.3.6/src/rb_textcheck/core/fix.py +234 -0
- rb_textcheck-0.3.6/src/rb_textcheck/core/humanizer_lint.py +335 -0
- rb_textcheck-0.3.6/src/rb_textcheck/core/models.py +25 -0
- rb_textcheck-0.3.6/src/rb_textcheck/core/normalize.py +52 -0
- rb_textcheck-0.3.6/src/rb_textcheck/core/opencli.py +286 -0
- rb_textcheck-0.3.6/src/rb_textcheck/core/profile.py +376 -0
- rb_textcheck-0.3.6/src/rb_textcheck/core/services.py +149 -0
- rb_textcheck-0.3.6/src/rb_textcheck/core/skills.py +64 -0
- rb_textcheck-0.3.6/src/rb_textcheck/core/text_blocks.py +104 -0
- rb_textcheck-0.3.6/src/rb_textcheck/core/version.py +89 -0
- rb_textcheck-0.3.6/src/rb_textcheck/data/LICENSE-humanizer-ru.txt +26 -0
- rb_textcheck-0.3.6/src/rb_textcheck/data/SKILL.md +63 -0
- rb_textcheck-0.3.6/src/rb_textcheck/data/__init__.py +1 -0
- rb_textcheck-0.3.6/src/rb_textcheck/data/quality-profile.schema.json +405 -0
- rb_textcheck-0.3.6/src/rb_textcheck/output/__init__.py +281 -0
- rb_textcheck-0.3.6/src/rb_textcheck/output/human.py +73 -0
- rb_textcheck-0.3.6/src/rb_textcheck/output/json.py +11 -0
- rb_textcheck-0.3.6/tests/__init__.py +1 -0
- rb_textcheck-0.3.6/tests/conftest.py +39 -0
- rb_textcheck-0.3.6/tests/contracts/data/article-without-h2.html +2 -0
- rb_textcheck-0.3.6/tests/contracts/data/clean-article.html +4 -0
- rb_textcheck-0.3.6/tests/contracts/data/profile-requires-h2.quality.yml +3 -0
- rb_textcheck-0.3.6/tests/contracts/fixtures.yaml +18 -0
- rb_textcheck-0.3.6/tests/contracts/schema.json +89 -0
- rb_textcheck-0.3.6/tests/contracts/tools-catalog/textcheck.yaml +20 -0
- rb_textcheck-0.3.6/tests/contracts/windmill/textcheck.yaml +63 -0
- rb_textcheck-0.3.6/tests/data/contracts/windmill-serp.yaml +106 -0
- rb_textcheck-0.3.6/tests/data/opencli.schema.json +350 -0
- rb_textcheck-0.3.6/tests/help_allowlist.txt +3 -0
- rb_textcheck-0.3.6/tests/snapshots/describe.json +1140 -0
- rb_textcheck-0.3.6/tests/snapshots/help/auth-status.txt +26 -0
- rb_textcheck-0.3.6/tests/snapshots/help/auth.txt +13 -0
- rb_textcheck-0.3.6/tests/snapshots/help/check.txt +25 -0
- rb_textcheck-0.3.6/tests/snapshots/help/config-get.txt +16 -0
- rb_textcheck-0.3.6/tests/snapshots/help/config-list.txt +13 -0
- rb_textcheck-0.3.6/tests/snapshots/help/config-set.txt +17 -0
- rb_textcheck-0.3.6/tests/snapshots/help/config.txt +14 -0
- rb_textcheck-0.3.6/tests/snapshots/help/describe.txt +18 -0
- rb_textcheck-0.3.6/tests/snapshots/help/doctor.txt +17 -0
- rb_textcheck-0.3.6/tests/snapshots/help/fix.txt +31 -0
- rb_textcheck-0.3.6/tests/snapshots/help/init.txt +16 -0
- rb_textcheck-0.3.6/tests/snapshots/help/profile-validate.txt +22 -0
- rb_textcheck-0.3.6/tests/snapshots/help/profile.txt +12 -0
- rb_textcheck-0.3.6/tests/snapshots/help/rules.txt +12 -0
- rb_textcheck-0.3.6/tests/snapshots/help/skill-install.txt +18 -0
- rb_textcheck-0.3.6/tests/snapshots/help/skill-list.txt +13 -0
- rb_textcheck-0.3.6/tests/snapshots/help/skill.txt +13 -0
- rb_textcheck-0.3.6/tests/snapshots/help/status.txt +14 -0
- rb_textcheck-0.3.6/tests/test_check_cli.py +137 -0
- rb_textcheck-0.3.6/tests/test_cli.py +307 -0
- rb_textcheck-0.3.6/tests/test_contract_runner.py +257 -0
- rb_textcheck-0.3.6/tests/test_contracts.py +389 -0
- rb_textcheck-0.3.6/tests/test_deps.py +150 -0
- rb_textcheck-0.3.6/tests/test_describe.py +181 -0
- rb_textcheck-0.3.6/tests/test_detach.py +161 -0
- rb_textcheck-0.3.6/tests/test_fix.py +179 -0
- rb_textcheck-0.3.6/tests/test_help.py +495 -0
- rb_textcheck-0.3.6/tests/test_normalize.py +44 -0
- rb_textcheck-0.3.6/tests/test_profile.py +145 -0
- rb_textcheck-0.3.6/tests/test_project.py +155 -0
- rb_textcheck-0.3.6/tests/test_scripts.py +54 -0
- rb_textcheck-0.3.6/tests/test_services.py +50 -0
- rb_textcheck-0.3.6/tests/test_skills.py +181 -0
- rb_textcheck-0.3.6/tests/test_vectors.py +106 -0
- rb_textcheck-0.3.6/vectors/README.md +60 -0
- rb_textcheck-0.3.6/vectors/cases/article.yaml +164 -0
- rb_textcheck-0.3.6/vectors/cases/corruption.yaml +74 -0
- rb_textcheck-0.3.6/vectors/cases/forbid.yaml +313 -0
- rb_textcheck-0.3.6/vectors/cases/format.yaml +75 -0
- rb_textcheck-0.3.6/vectors/cases/headings.yaml +181 -0
- rb_textcheck-0.3.6/vectors/cases/humanizer.yaml +445 -0
- rb_textcheck-0.3.6/vectors/cases/language.yaml +48 -0
- rb_textcheck-0.3.6/vectors/cases/leftovers.yaml +40 -0
- rb_textcheck-0.3.6/vectors/cases/length.yaml +106 -0
- rb_textcheck-0.3.6/vectors/cases/markup.yaml +203 -0
- rb_textcheck-0.3.6/vectors/cases/tags.yaml +78 -0
- rb_textcheck-0.3.6/vectors/cases/truncation.yaml +60 -0
- rb_textcheck-0.3.6/vectors/fix/cases.yaml +338 -0
- rb_textcheck-0.3.6/vectors/profiles/article-required.quality.yml +12 -0
- rb_textcheck-0.3.6/vectors/profiles/content-import-article.quality.yml +149 -0
- rb_textcheck-0.3.6/vectors/profiles/content-logistics.quality.yml +161 -0
- rb_textcheck-0.3.6/vectors/profiles/content-marking.quality.yml +98 -0
- rb_textcheck-0.3.6/vectors/profiles/content-write.quality.yml +50 -0
- rb_textcheck-0.3.6/vectors/profiles/fix-child.quality.yml +6 -0
- rb_textcheck-0.3.6/vectors/profiles/fix-typography.quality.yml +10 -0
- rb_textcheck-0.3.6/vectors/profiles/seo-meta.quality.yml +72 -0
- rb_textcheck-0.3.6/vectors/profiles/vat-22.quality.yml +7 -0
- rb_textcheck-0.3.6/vectors/profiles-invalid/bad-regex.quality.yml +4 -0
- rb_textcheck-0.3.6/vectors/profiles-invalid/broken-yaml.quality.yml +2 -0
- rb_textcheck-0.3.6/vectors/profiles-invalid/expect.yaml +26 -0
- rb_textcheck-0.3.6/vectors/profiles-invalid/extends-cycle-a.quality.yml +2 -0
- rb_textcheck-0.3.6/vectors/profiles-invalid/extends-cycle-b.quality.yml +2 -0
- rb_textcheck-0.3.6/vectors/profiles-invalid/extends-kind-mismatch.quality.yml +3 -0
- rb_textcheck-0.3.6/vectors/profiles-invalid/extends-missing.quality.yml +2 -0
- rb_textcheck-0.3.6/vectors/profiles-invalid/extends-self.quality.yml +2 -0
- rb_textcheck-0.3.6/vectors/profiles-invalid/fix-bad-group.quality.yml +6 -0
- rb_textcheck-0.3.6/vectors/profiles-invalid/fix-bad-regex.quality.yml +6 -0
- rb_textcheck-0.3.6/vectors/profiles-invalid/fix-bad-where.quality.yml +6 -0
- rb_textcheck-0.3.6/vectors/profiles-invalid/fix-empty-from.quality.yml +5 -0
- rb_textcheck-0.3.6/vectors/profiles-invalid/fix-unknown-rule.quality.yml +6 -0
- rb_textcheck-0.3.6/vectors/profiles-invalid/fix-without-to.quality.yml +4 -0
- rb_textcheck-0.3.6/vectors/profiles-invalid/forbid-not-a-list.quality.yml +4 -0
- rb_textcheck-0.3.6/vectors/profiles-invalid/forbid-unknown-key.quality.yml +5 -0
- rb_textcheck-0.3.6/vectors/profiles-invalid/forbid-without-name.quality.yml +3 -0
- rb_textcheck-0.3.6/vectors/profiles-invalid/forbid-without-regex-and-judge.quality.yml +3 -0
- rb_textcheck-0.3.6/vectors/profiles-invalid/headings-required-bad-regex.quality.yml +5 -0
- rb_textcheck-0.3.6/vectors/profiles-invalid/kind-unknown.quality.yml +2 -0
- rb_textcheck-0.3.6/vectors/profiles-invalid/meta-article-section.quality.yml +4 -0
- rb_textcheck-0.3.6/vectors/profiles-invalid/meta-length-shape.quality.yml +4 -0
- rb_textcheck-0.3.6/vectors/profiles-invalid/not-a-mapping.quality.yml +3 -0
- rb_textcheck-0.3.6/vectors/profiles-invalid/unknown-inner-key.quality.yml +3 -0
- rb_textcheck-0.3.6/vectors/profiles-invalid/unknown-section.quality.yml +3 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
__pycache__/
|
|
2
|
+
*.py[cod]
|
|
3
|
+
.venv/
|
|
4
|
+
.pytest_cache/
|
|
5
|
+
.ruff_cache/
|
|
6
|
+
dist/
|
|
7
|
+
*.egg-info/
|
|
8
|
+
.python-version
|
|
9
|
+
.coverage
|
|
10
|
+
htmlcov/
|
|
11
|
+
# mutmut's working copy and results (uv run --group mutation mutmut run)
|
|
12
|
+
mutants/
|
|
13
|
+
# Local env files hold keys: keys never go into the repo (the gate's secret scan)
|
|
14
|
+
.env
|
|
15
|
+
.env.*
|
|
16
|
+
# The root lines Antagor adds
|
|
17
|
+
.DS_Store
|
|
18
|
+
Thumbs.db
|
|
19
|
+
.pdm-build/
|
|
20
|
+
.cache/
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Roman Bolandau
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: rb-textcheck
|
|
3
|
+
Version: 0.3.6
|
|
4
|
+
Summary: Deterministic text quality checks by a quality profile, with no network and no LLM.
|
|
5
|
+
Project-URL: Repository, https://github.com/bolandeu/rb-textcheck
|
|
6
|
+
Author: Roman Bolandau
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Requires-Python: >=3.14
|
|
10
|
+
Requires-Dist: beautifulsoup4>=4.12
|
|
11
|
+
Requires-Dist: html5lib>=1.1
|
|
12
|
+
Requires-Dist: jsonschema>=4.23
|
|
13
|
+
Requires-Dist: packaging>=24.0
|
|
14
|
+
Requires-Dist: platformdirs>=4.2
|
|
15
|
+
Requires-Dist: pydantic>=2.6
|
|
16
|
+
Requires-Dist: pymorphy3-dicts-ru>=2.4
|
|
17
|
+
Requires-Dist: pymorphy3>=2.0
|
|
18
|
+
Requires-Dist: pyyaml>=6.0
|
|
19
|
+
Requires-Dist: rich>=13.7
|
|
20
|
+
Requires-Dist: tomli-w>=1.0
|
|
21
|
+
Requires-Dist: typer<0.29,>=0.27
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
|
|
24
|
+
# textcheck
|
|
25
|
+
|
|
26
|
+
Deterministic text quality checks by a quality profile (no network, no LLM)
|
|
27
|
+
|
|
28
|
+
Перенос детерминированного слоя проверок antagor (`utils/quality_checks.py`,
|
|
29
|
+
`humanizer_lint.py`, `quality_profile.py`, `text_blocks.py`, коммит `9a5e4d8`)
|
|
30
|
+
в отдельный инструмент: без сети, без LLM.
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
textcheck check article.html --profile content-logistics.quality.yml --json
|
|
34
|
+
cat article.md | textcheck check - --format md --json
|
|
35
|
+
textcheck fix article.html --profile typography.quality.yml > fixed.html
|
|
36
|
+
textcheck fix article.html --profile typography.quality.yml --check --json
|
|
37
|
+
textcheck profile validate content-logistics.quality.yml
|
|
38
|
+
textcheck rules --json
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
`check --json` → `{ok, issues[{rule, message, excerpt, gate, unit, address, action}],
|
|
42
|
+
humanizer{score, verdict} | null, gate_failed}`. Коды выхода: `0` — гейт пройден
|
|
43
|
+
(находки с `gate: false` — к сведению), `1` — есть находки с `gate: true`
|
|
44
|
+
(отчёт выдаётся целиком, плюс `error.code = QUALITY_GATE_FAILED`), `2` —
|
|
45
|
+
аргументы или профиль (`INVALID_ARGUMENTS`, `INVALID_PROFILE`).
|
|
46
|
+
|
|
47
|
+
`fix` — механические автозамены из секции профиля `fixes` (`{name, from, to,
|
|
48
|
+
regex, where, fixes_rule}`), по порядку, только в тексте (теги, атрибуты, код,
|
|
49
|
+
адреса ссылок и голые URL не трогаются). По умолчанию — исправленный текст в
|
|
50
|
+
stdout; `--json` → `{ok, text, applied[{name, count, addresses}], unchanged}`;
|
|
51
|
+
`--check` — плюс отчёт `check` по результату и его код выхода.
|
|
52
|
+
|
|
53
|
+
Библиотечно:
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
import rb_textcheck
|
|
57
|
+
|
|
58
|
+
result = rb_textcheck.check(text, "content-logistics.quality.yml", "html") # профиль: путь | dict | None
|
|
59
|
+
result.gate_failed, result.as_dict()
|
|
60
|
+
fixed = rb_textcheck.fix(text, "typography.quality.yml", "html") # .text, .applied, .unchanged
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Профиль `quality.yml` — формат antagor `prompts/*.quality.yml`: `kind: article`
|
|
64
|
+
(по умолчанию; секции `length`, `headings` (+ `required`), `tags`, `cliches`,
|
|
65
|
+
`forbid`, `fixes`, `humanizer`, `language`, `grounding`, `judge_model`,
|
|
66
|
+
`generation` — последние три textcheck не применяет) или `kind: meta` (профиль
|
|
67
|
+
seo-meta, только валидация). `extends: <имя|путь>` — наследование. Неизвестный
|
|
68
|
+
ключ на любом уровне — ошибка. JSON Schema —
|
|
69
|
+
`src/rb_textcheck/data/quality-profile.schema.json`.
|
|
70
|
+
|
|
71
|
+
Поведение закреплено корпусом `vectors/` (формат — `vectors/README.md`).
|
|
72
|
+
|
|
73
|
+
`core/humanizer_lint.py` — копия `lint.py` скилла humanizer-ru, автор Serge Shima,
|
|
74
|
+
MIT: `src/rb_textcheck/data/LICENSE-humanizer-ru.txt`.
|
|
75
|
+
|
|
76
|
+
## Development
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
uv sync
|
|
80
|
+
uv run textcheck --help
|
|
81
|
+
uv run pytest --snapshot-update # after changing a command's help; review tests/snapshots/help/
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
The gate is `gate check`, run on this machine before a commit.
|
|
85
|
+
is the git tag; a release goes through Antagor (`antagor publish`), which writes `CHANGELOG.md`.
|
|
86
|
+
|
|
87
|
+
## Install
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
From the git tag instead:
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
uv tool install "rb-textcheck @ git+https://github.com/bolandeu/rb-textcheck.git@vX.Y.Z"
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
An AI agent bootstraps the CLI the same way on a fresh machine — see `src/rb_textcheck/data/SKILL.md`.
|
|
99
|
+
|
|
100
|
+
**Update** an installed copy to the latest commit:
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
uv tool upgrade rb-textcheck
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
After install, the command `textcheck` is available globally, on
|
|
107
|
+
macOS, Linux and Windows alike (see `architecture.md` in the cli-generator
|
|
108
|
+
plugin for why: no shelling out, no hardcoded POSIX paths).
|
|
109
|
+
|
|
110
|
+
To pick up later architecture changes from the `cli-generator` template
|
|
111
|
+
itself, run `copier update` in this repo (requires this repo and the
|
|
112
|
+
template to both be git repos; see the `cli-generator` plugin's README).
|
|
113
|
+
|
|
114
|
+
## Architecture
|
|
115
|
+
|
|
116
|
+
This project follows a fixed CLI architecture:
|
|
117
|
+
|
|
118
|
+
- `src/rb_textcheck/commands/` — argument parsing only, no business logic.
|
|
119
|
+
- `src/rb_textcheck/core/` — services, models, errors: the real logic.
|
|
120
|
+
- `src/rb_textcheck/providers/` — external APIs/integrations.
|
|
121
|
+
- `src/rb_textcheck/credentials/` — secrets via the OS keychain (`keyring`)
|
|
122
|
+
and environment variables. Secrets never live in `.rb_textcheck/config.toml`.
|
|
123
|
+
- `src/rb_textcheck/output/` — human (`rich`) and `--json` rendering.
|
|
124
|
+
|
|
125
|
+
Run `textcheck doctor` to check environment/config/auth readiness, and
|
|
126
|
+
`textcheck --help` for the full command surface. Every command supports
|
|
127
|
+
`--json` for machine/agent consumption; errors are structured (`error.code`,
|
|
128
|
+
fixed exit codes, `error.action` telling you what to do next) and go to
|
|
129
|
+
stderr in human mode, so stdout is always safe to pipe.
|
|
130
|
+
|
|
131
|
+
A project can require a minimum CLI version in its `.rb_textcheck/config.toml`
|
|
132
|
+
(`[cli] min_version = "..."`); an older install refuses with exit 6 and
|
|
133
|
+
`uv tool upgrade rb-textcheck` fixes it.
|
|
134
|
+
|
|
135
|
+
See `src/rb_textcheck/data/SKILL.md` for the agent-facing usage guide
|
|
136
|
+
bundled with this package — install it into an AI tool with
|
|
137
|
+
`textcheck skill install`, or get it as plain text with
|
|
138
|
+
`textcheck --ai` (works even without file access).
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# textcheck
|
|
2
|
+
|
|
3
|
+
Deterministic text quality checks by a quality profile (no network, no LLM)
|
|
4
|
+
|
|
5
|
+
Перенос детерминированного слоя проверок antagor (`utils/quality_checks.py`,
|
|
6
|
+
`humanizer_lint.py`, `quality_profile.py`, `text_blocks.py`, коммит `9a5e4d8`)
|
|
7
|
+
в отдельный инструмент: без сети, без LLM.
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
textcheck check article.html --profile content-logistics.quality.yml --json
|
|
11
|
+
cat article.md | textcheck check - --format md --json
|
|
12
|
+
textcheck fix article.html --profile typography.quality.yml > fixed.html
|
|
13
|
+
textcheck fix article.html --profile typography.quality.yml --check --json
|
|
14
|
+
textcheck profile validate content-logistics.quality.yml
|
|
15
|
+
textcheck rules --json
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
`check --json` → `{ok, issues[{rule, message, excerpt, gate, unit, address, action}],
|
|
19
|
+
humanizer{score, verdict} | null, gate_failed}`. Коды выхода: `0` — гейт пройден
|
|
20
|
+
(находки с `gate: false` — к сведению), `1` — есть находки с `gate: true`
|
|
21
|
+
(отчёт выдаётся целиком, плюс `error.code = QUALITY_GATE_FAILED`), `2` —
|
|
22
|
+
аргументы или профиль (`INVALID_ARGUMENTS`, `INVALID_PROFILE`).
|
|
23
|
+
|
|
24
|
+
`fix` — механические автозамены из секции профиля `fixes` (`{name, from, to,
|
|
25
|
+
regex, where, fixes_rule}`), по порядку, только в тексте (теги, атрибуты, код,
|
|
26
|
+
адреса ссылок и голые URL не трогаются). По умолчанию — исправленный текст в
|
|
27
|
+
stdout; `--json` → `{ok, text, applied[{name, count, addresses}], unchanged}`;
|
|
28
|
+
`--check` — плюс отчёт `check` по результату и его код выхода.
|
|
29
|
+
|
|
30
|
+
Библиотечно:
|
|
31
|
+
|
|
32
|
+
```python
|
|
33
|
+
import rb_textcheck
|
|
34
|
+
|
|
35
|
+
result = rb_textcheck.check(text, "content-logistics.quality.yml", "html") # профиль: путь | dict | None
|
|
36
|
+
result.gate_failed, result.as_dict()
|
|
37
|
+
fixed = rb_textcheck.fix(text, "typography.quality.yml", "html") # .text, .applied, .unchanged
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Профиль `quality.yml` — формат antagor `prompts/*.quality.yml`: `kind: article`
|
|
41
|
+
(по умолчанию; секции `length`, `headings` (+ `required`), `tags`, `cliches`,
|
|
42
|
+
`forbid`, `fixes`, `humanizer`, `language`, `grounding`, `judge_model`,
|
|
43
|
+
`generation` — последние три textcheck не применяет) или `kind: meta` (профиль
|
|
44
|
+
seo-meta, только валидация). `extends: <имя|путь>` — наследование. Неизвестный
|
|
45
|
+
ключ на любом уровне — ошибка. JSON Schema —
|
|
46
|
+
`src/rb_textcheck/data/quality-profile.schema.json`.
|
|
47
|
+
|
|
48
|
+
Поведение закреплено корпусом `vectors/` (формат — `vectors/README.md`).
|
|
49
|
+
|
|
50
|
+
`core/humanizer_lint.py` — копия `lint.py` скилла humanizer-ru, автор Serge Shima,
|
|
51
|
+
MIT: `src/rb_textcheck/data/LICENSE-humanizer-ru.txt`.
|
|
52
|
+
|
|
53
|
+
## Development
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
uv sync
|
|
57
|
+
uv run textcheck --help
|
|
58
|
+
uv run pytest --snapshot-update # after changing a command's help; review tests/snapshots/help/
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
The gate is `gate check`, run on this machine before a commit.
|
|
62
|
+
is the git tag; a release goes through Antagor (`antagor publish`), which writes `CHANGELOG.md`.
|
|
63
|
+
|
|
64
|
+
## Install
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
From the git tag instead:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
uv tool install "rb-textcheck @ git+https://github.com/bolandeu/rb-textcheck.git@vX.Y.Z"
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
An AI agent bootstraps the CLI the same way on a fresh machine — see `src/rb_textcheck/data/SKILL.md`.
|
|
76
|
+
|
|
77
|
+
**Update** an installed copy to the latest commit:
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
uv tool upgrade rb-textcheck
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
After install, the command `textcheck` is available globally, on
|
|
84
|
+
macOS, Linux and Windows alike (see `architecture.md` in the cli-generator
|
|
85
|
+
plugin for why: no shelling out, no hardcoded POSIX paths).
|
|
86
|
+
|
|
87
|
+
To pick up later architecture changes from the `cli-generator` template
|
|
88
|
+
itself, run `copier update` in this repo (requires this repo and the
|
|
89
|
+
template to both be git repos; see the `cli-generator` plugin's README).
|
|
90
|
+
|
|
91
|
+
## Architecture
|
|
92
|
+
|
|
93
|
+
This project follows a fixed CLI architecture:
|
|
94
|
+
|
|
95
|
+
- `src/rb_textcheck/commands/` — argument parsing only, no business logic.
|
|
96
|
+
- `src/rb_textcheck/core/` — services, models, errors: the real logic.
|
|
97
|
+
- `src/rb_textcheck/providers/` — external APIs/integrations.
|
|
98
|
+
- `src/rb_textcheck/credentials/` — secrets via the OS keychain (`keyring`)
|
|
99
|
+
and environment variables. Secrets never live in `.rb_textcheck/config.toml`.
|
|
100
|
+
- `src/rb_textcheck/output/` — human (`rich`) and `--json` rendering.
|
|
101
|
+
|
|
102
|
+
Run `textcheck doctor` to check environment/config/auth readiness, and
|
|
103
|
+
`textcheck --help` for the full command surface. Every command supports
|
|
104
|
+
`--json` for machine/agent consumption; errors are structured (`error.code`,
|
|
105
|
+
fixed exit codes, `error.action` telling you what to do next) and go to
|
|
106
|
+
stderr in human mode, so stdout is always safe to pipe.
|
|
107
|
+
|
|
108
|
+
A project can require a minimum CLI version in its `.rb_textcheck/config.toml`
|
|
109
|
+
(`[cli] min_version = "..."`); an older install refuses with exit 6 and
|
|
110
|
+
`uv tool upgrade rb-textcheck` fixes it.
|
|
111
|
+
|
|
112
|
+
See `src/rb_textcheck/data/SKILL.md` for the agent-facing usage guide
|
|
113
|
+
bundled with this package — install it into an AI tool with
|
|
114
|
+
`textcheck skill install`, or get it as plain text with
|
|
115
|
+
`textcheck --ai` (works even without file access).
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "rb-textcheck"
|
|
3
|
+
# Version comes from the git tag vX.Y.Z (uv-dynamic-versioning) — never add `version =`.
|
|
4
|
+
dynamic = ["version"]
|
|
5
|
+
description = "Deterministic text quality checks by a quality profile, with no network and no LLM."
|
|
6
|
+
readme = "README.md"
|
|
7
|
+
license = "MIT"
|
|
8
|
+
license-files = ["LICENSE"]
|
|
9
|
+
authors = [{ name = "Roman Bolandau" }]
|
|
10
|
+
requires-python = ">=3.14"
|
|
11
|
+
dependencies = [
|
|
12
|
+
"typer>=0.27,<0.29",
|
|
13
|
+
"rich>=13.7",
|
|
14
|
+
"pydantic>=2.6",
|
|
15
|
+
"tomli-w>=1.0",
|
|
16
|
+
"platformdirs>=4.2",
|
|
17
|
+
"packaging>=24.0",
|
|
18
|
+
"beautifulsoup4>=4.12",
|
|
19
|
+
"html5lib>=1.1",
|
|
20
|
+
"pymorphy3>=2.0",
|
|
21
|
+
"pymorphy3-dicts-ru>=2.4",
|
|
22
|
+
"pyyaml>=6.0",
|
|
23
|
+
"jsonschema>=4.23",
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
[project.scripts]
|
|
27
|
+
textcheck = "rb_textcheck.cli:main"
|
|
28
|
+
|
|
29
|
+
[project.urls]
|
|
30
|
+
Repository = "https://github.com/bolandeu/rb-textcheck"
|
|
31
|
+
|
|
32
|
+
[build-system]
|
|
33
|
+
requires = ["hatchling", "uv-dynamic-versioning"]
|
|
34
|
+
build-backend = "hatchling.build"
|
|
35
|
+
|
|
36
|
+
[tool.hatch.version]
|
|
37
|
+
source = "uv-dynamic-versioning"
|
|
38
|
+
|
|
39
|
+
[tool.uv-dynamic-versioning]
|
|
40
|
+
vcs = "git"
|
|
41
|
+
style = "pep440"
|
|
42
|
+
fallback-version = "0.0.0"
|
|
43
|
+
|
|
44
|
+
[tool.uv]
|
|
45
|
+
# Rebuild the editable install when a commit or tag moves, so `--version` follows the tag.
|
|
46
|
+
cache-keys = [{ file = "pyproject.toml" }, { git = { commit = true, tags = true } }]
|
|
47
|
+
|
|
48
|
+
[tool.hatch.build.targets.sdist]
|
|
49
|
+
# What a release must not carry: the agent's own files, the forge configs and the dev tooling. The wheel is
|
|
50
|
+
# narrow already (`packages = ["src/<pkg>"]`); this is about the sdist, which is otherwise a copy of the repo.
|
|
51
|
+
exclude = [
|
|
52
|
+
"/.agents",
|
|
53
|
+
"/.claude",
|
|
54
|
+
"/.claude-plugin",
|
|
55
|
+
"/.gitea",
|
|
56
|
+
"/.github",
|
|
57
|
+
"/docs",
|
|
58
|
+
"/scripts",
|
|
59
|
+
"/uv.lock",
|
|
60
|
+
"/AGENTS.md",
|
|
61
|
+
"/CLAUDE.md",
|
|
62
|
+
"/CODING_STANDARDS.md",
|
|
63
|
+
"/CONTEXT.md",
|
|
64
|
+
"/.copier-answers.yml",
|
|
65
|
+
"^\\.gitignore$",
|
|
66
|
+
"/.gitleaks.toml",
|
|
67
|
+
]
|
|
68
|
+
|
|
69
|
+
[tool.hatch.build.targets.wheel]
|
|
70
|
+
packages = ["src/rb_textcheck"]
|
|
71
|
+
|
|
72
|
+
[tool.hatch.build.targets.wheel.force-include]
|
|
73
|
+
# The installed CLI reads [[tool.rb.external]] from here (core/deps.py).
|
|
74
|
+
"pyproject.toml" = "rb_textcheck/_pyproject.toml"
|
|
75
|
+
|
|
76
|
+
[dependency-groups]
|
|
77
|
+
# Mutation testing, run now and then and before big releases — not in the gate:
|
|
78
|
+
# `uv run --group mutation mutmut run`, then `mutmut results` / `mutmut browse`.
|
|
79
|
+
# Needs fork(): macOS/Linux (WSL on Windows). Settings: [tool.mutmut] below.
|
|
80
|
+
mutation = ["mutmut>=3.3"]
|
|
81
|
+
dev = [
|
|
82
|
+
"jsonschema>=4.23",
|
|
83
|
+
"pytest>=8.0",
|
|
84
|
+
"pyyaml>=6.0", # .copier-answers.yml, the CI workflow, tests/contracts/*.yaml
|
|
85
|
+
"pytest-cov>=5.0",
|
|
86
|
+
"ruff>=0.6",
|
|
87
|
+
"syrupy>=4.8",
|
|
88
|
+
"ty>=0.0.80",
|
|
89
|
+
]
|
|
90
|
+
|
|
91
|
+
# External (non-Python) dependencies — every CLI this tool runs (require_cli,
|
|
92
|
+
# shutil.which, subprocess with a literal program, npx). The gate checks this
|
|
93
|
+
# list against the code both ways; doctor and require_cli read it at runtime;
|
|
94
|
+
# the tools catalog reads it (the Standard, Technology).
|
|
95
|
+
# [[tool.rb.external]]
|
|
96
|
+
# name = "ffmpeg"
|
|
97
|
+
# required = true # false: the tool works without it (doctor stays healthy)
|
|
98
|
+
# min_version = "6.0" # optional
|
|
99
|
+
# check = "ffmpeg -version" # prints the version; default "<name> --version"
|
|
100
|
+
# why = "transcodes the downloaded videos"
|
|
101
|
+
# detect = false # run via an injected runner / absolute path the gate can't see
|
|
102
|
+
# dist = "rb-serp" # for one of our CLIs: its distribution (default rb-<name>)
|
|
103
|
+
# url = "https://github.com/bolandeu/serp" # its repo: DEPENDENCY_TOO_OLD then prints a pinned install
|
|
104
|
+
|
|
105
|
+
# Where sysadmin's tool-updater installs this tool after its first tag. The
|
|
106
|
+
# installation is sysadmin's; this section only says where. homeserver: users
|
|
107
|
+
# to install for (empty = build and publish only); mac: install on the Mac.
|
|
108
|
+
# extras (optional): the extras to install with, e.g. extras = ["browser"].
|
|
109
|
+
[tool.rb.install]
|
|
110
|
+
homeserver = ["rbtools"]
|
|
111
|
+
mac = true
|
|
112
|
+
|
|
113
|
+
[tool.cli-generator]
|
|
114
|
+
# Where scripts/check_command_docstrings.py (called by the project's checks)
|
|
115
|
+
# looks for commands: a glob or a list of globs, relative to the repo root.
|
|
116
|
+
commands = ["src/rb_textcheck/commands/*.py"]
|
|
117
|
+
# gate check (the gate): extras to install before ruff/ty/pytest.
|
|
118
|
+
# gate_extras = ["browser"]
|
|
119
|
+
|
|
120
|
+
[tool.pytest.ini_options]
|
|
121
|
+
# Only tests/: mutmut leaves a copy of the tree in mutants/.
|
|
122
|
+
testpaths = ["tests"]
|
|
123
|
+
addopts = "--cov --cov-report=term-missing:skip-covered"
|
|
124
|
+
# tests/test_help.py keeps help snapshots at tests/snapshots/help/<command>.txt
|
|
125
|
+
# (the Standard, Commands), not in syrupy's own `__snapshots__/<test file>/` layout, so
|
|
126
|
+
# syrupy warns it "can not relate" each file to its test. It can — by name.
|
|
127
|
+
filterwarnings = ["ignore:(?s).*Can not relate snapshot:UserWarning"]
|
|
128
|
+
|
|
129
|
+
[tool.mutmut]
|
|
130
|
+
source_paths = ["src/rb_textcheck"]
|
|
131
|
+
also_copy = ["scripts/", "pyproject.toml"] # tests read them (test_scripts.py, the distribution checks)
|
|
132
|
+
pytest_add_cli_args = ["--no-cov"] # fail_under would kill every mutant
|
|
133
|
+
# only_mutate = ["*/core/normalize.py"] # one module at a time on a big tool
|
|
134
|
+
|
|
135
|
+
[tool.coverage.run]
|
|
136
|
+
source = ["src"]
|
|
137
|
+
# sysmon (default on 3.14) keeps a record per recompiled code object; Typer recompiles annotations on every invoke, so memory grows.
|
|
138
|
+
core = "ctrace"
|
|
139
|
+
|
|
140
|
+
[tool.coverage.report]
|
|
141
|
+
# The template ships at ~94%; keep the bar where it is instead of letting
|
|
142
|
+
# new commands land untested. Raise it, never lower it.
|
|
143
|
+
fail_under = 90
|
|
144
|
+
show_missing = true
|
|
145
|
+
|
|
146
|
+
[tool.ty.terminal]
|
|
147
|
+
# Only errors fail the gate; recent ty (>= 0.0.84) otherwise exits 1 on warnings too.
|
|
148
|
+
# Legacy code that can't be fixed yet: downgrade specific rules instead of
|
|
149
|
+
# ignoring them, e.g. [tool.ty.rules] possibly-unbound-attribute = "warn".
|
|
150
|
+
error-on-warning = false
|
|
151
|
+
|
|
152
|
+
[tool.ruff]
|
|
153
|
+
line-length = 120
|
|
154
|
+
|
|
155
|
+
[tool.ruff.lint]
|
|
156
|
+
select = ["E4", "E7", "E9", "F", "I", "UP", "B", "SIM", "RUF", "S", "T20", "TID251"]
|
|
157
|
+
# Russian messages, comments and docstrings: Cyrillic letters are not confusables here.
|
|
158
|
+
ignore = ["RUF001", "RUF002", "RUF003"]
|
|
159
|
+
|
|
160
|
+
[tool.ruff.lint.per-file-ignores]
|
|
161
|
+
"tests/*" = ["S101", "T201", "TID251"] # assert is the point of a test; print in code strings; httpx for mocks
|
|
162
|
+
"scripts/*" = ["S603", "S607", "T201"] # subprocess with fixed argv lists (git, uv), no shell; scripts print to the console
|
|
163
|
+
"src/*/providers/*" = ["TID251"] # external APIs live here
|
|
164
|
+
# Third-party copy (humanizer-ru lint.py, MIT): kept verbatim so diffs against upstream stay readable.
|
|
165
|
+
"src/rb_textcheck/core/humanizer_lint.py" = ["UP031", "B905", "RUF007", "T201"]
|
|
166
|
+
|
|
167
|
+
[tool.ruff.lint.flake8-tidy-imports.banned-api]
|
|
168
|
+
"httpx".msg = "Call external APIs through providers/ (subclass providers.HttpProvider)."
|
|
169
|
+
|
|
170
|
+
[tool.ruff.lint.flake8-bugbear]
|
|
171
|
+
# Typer's `param: T = typer.Option(...)` style is a call in a default on purpose.
|
|
172
|
+
extend-immutable-calls = ["typer.Option", "typer.Argument"]
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"""rb_textcheck - детерминированные проверки текста по профилю качества.
|
|
2
|
+
|
|
3
|
+
Библиотечно: ``rb_textcheck.check(text, profile, format)`` -> Result
|
|
4
|
+
(``.issues``, ``.humanizer``, ``.gate_failed``, ``.as_dict()``);
|
|
5
|
+
``rb_textcheck.fix(text, profile, format)`` -> FixResult (``.text``, ``.applied``, ``.unchanged``).
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from typing import Any
|
|
11
|
+
|
|
12
|
+
__all__ = ["FixResult", "ProfileError", "QualityProfile", "Result", "check", "fix", "load_profile", "rules"]
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def rules() -> list[dict[str, Any]]:
|
|
16
|
+
"""Правила проверки: id, description, formats - в порядке выдачи."""
|
|
17
|
+
from .core.checks import RULES
|
|
18
|
+
|
|
19
|
+
return [dict(rule) for rule in RULES]
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def __getattr__(name: str) -> Any:
|
|
23
|
+
# Ленивый импорт: CLI (--version, --help) не платит за bs4/html5lib
|
|
24
|
+
if name in ("check", "Result"):
|
|
25
|
+
from .core import checks
|
|
26
|
+
|
|
27
|
+
return getattr(checks, name)
|
|
28
|
+
if name in ("fix", "FixResult"):
|
|
29
|
+
from .core import fix
|
|
30
|
+
|
|
31
|
+
return getattr(fix, name)
|
|
32
|
+
if name in ("load_profile", "ProfileError", "QualityProfile"):
|
|
33
|
+
from .core import profile
|
|
34
|
+
|
|
35
|
+
return getattr(profile, name)
|
|
36
|
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"""The distribution name and the tool namespace copier writes from its answers, because an editable install cannot map
|
|
2
|
+
this import package to its distribution at runtime.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
# Rendered by copier from the `dist_name` answer: the [project] name in
|
|
6
|
+
# pyproject.toml (`rb-<slug>`, the Standard, Technology), which may differ from this
|
|
7
|
+
# import package's name. importlib.metadata finds this package's version,
|
|
8
|
+
# summary and console script by it; an editable install (`uv sync`) can't be
|
|
9
|
+
# mapped from package to distribution at runtime, so it is written down here.
|
|
10
|
+
# tests/test_cli.py fails if it drifts from pyproject.toml.
|
|
11
|
+
DIST_NAME = "rb-textcheck"
|
|
12
|
+
# The previous distribution name during a rename: an install made
|
|
13
|
+
# under it (not yet reinstalled) still finds its own version. Drop it once
|
|
14
|
+
# every machine has the new name.
|
|
15
|
+
DIST_NAME_LEGACY: str | None = None
|
|
16
|
+
# The command name (`cli_name`) as an identifier: the namespace of this tool's
|
|
17
|
+
# shared-database names (core/db.py) — table prefix `<TOOL>_`, env var
|
|
18
|
+
# `<TOOL>_DATABASE_URL`, Alembic table `alembic_version_<TOOL>`. Written down,
|
|
19
|
+
# not derived at runtime: a bare source run falls back to the package name,
|
|
20
|
+
# and a table name must never depend on how the tool was started.
|
|
21
|
+
TOOL = "textcheck"
|
|
22
|
+
# The cli-generator release this project was generated or last updated from
|
|
23
|
+
# (copier's `_commit`), for `describe --json`; None for a project not made by copier.
|
|
24
|
+
TEMPLATE_VERSION: str | None = "v1.27.3"
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"""The root Typer app: global options, the command groups and the optional commands a generated package has, wired
|
|
2
|
+
together, and the console-script entry point.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
import typer
|
|
8
|
+
|
|
9
|
+
from . import output
|
|
10
|
+
from .commands import auth, check, doctor, fix, profile, rules
|
|
11
|
+
from .core.version import DEV_VERSION, cli_name, installed_version, optional_module, package_summary
|
|
12
|
+
|
|
13
|
+
_PACKAGE_NAME = __name__.split(".")[0]
|
|
14
|
+
# Optional parts (copier questions, dropped by _exclude): each one ships a module that registers its
|
|
15
|
+
# commands and global options. Probed at runtime, so this file needs no template logic.
|
|
16
|
+
PARTS = ("project", "skill", "describe", "db")
|
|
17
|
+
|
|
18
|
+
# A bare `<cli>` is the discovery entry point for humans and agents alike:
|
|
19
|
+
# name + version + description, then every command with the first line of
|
|
20
|
+
# its docstring. No `no_args_is_help` (that exits 2) — main_options() below
|
|
21
|
+
# prints this and exits 0. Shell completion stays enabled.
|
|
22
|
+
app = typer.Typer(
|
|
23
|
+
cls=output.RootGroup, # a usage error under --json is the error envelope
|
|
24
|
+
help=f"{cli_name()} {installed_version() or DEV_VERSION} — {package_summary() or 'project-aware automation CLI'}",
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
app.add_typer(auth.app, name="auth") # `auth status` in every CLI; login/logout only with credentials
|
|
28
|
+
app.add_typer(profile.app, name="profile")
|
|
29
|
+
|
|
30
|
+
app.command(name="doctor")(doctor.doctor)
|
|
31
|
+
app.command(name="check")(check.check)
|
|
32
|
+
app.command(name="fix")(fix.fix)
|
|
33
|
+
app.command(name="rules")(rules.rules)
|
|
34
|
+
for part in PARTS:
|
|
35
|
+
if module := optional_module(f"{_PACKAGE_NAME}.commands.{part}"):
|
|
36
|
+
module.register(app)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _version_callback(value: bool) -> None:
|
|
40
|
+
if not value:
|
|
41
|
+
return
|
|
42
|
+
typer.echo(installed_version() or DEV_VERSION)
|
|
43
|
+
raise typer.Exit()
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
@app.callback(invoke_without_command=True)
|
|
47
|
+
def main_options(
|
|
48
|
+
ctx: typer.Context,
|
|
49
|
+
json_output: bool = typer.Option(False, "--json", help="Emit machine-readable JSON output."),
|
|
50
|
+
quiet: bool = typer.Option(False, "--quiet", help="Suppress non-essential output."),
|
|
51
|
+
verbose: bool = typer.Option(False, "--verbose", help="Emit extra diagnostic output."),
|
|
52
|
+
non_interactive: bool = typer.Option(False, "--non-interactive", help="Never prompt; fail instead."),
|
|
53
|
+
dry_run: bool = typer.Option(False, "--dry-run", help="Show what would happen without making changes."),
|
|
54
|
+
version: bool = typer.Option(
|
|
55
|
+
False, "--version", callback=_version_callback, is_eager=True, help="Show the version and exit."
|
|
56
|
+
),
|
|
57
|
+
) -> None:
|
|
58
|
+
ctx.ensure_object(dict) # a part's global option (--project) may have put its value here already
|
|
59
|
+
ctx.obj["json"] = json_output
|
|
60
|
+
ctx.obj["quiet"] = quiet
|
|
61
|
+
ctx.obj["verbose"] = verbose
|
|
62
|
+
ctx.obj["non_interactive"] = non_interactive
|
|
63
|
+
ctx.obj["dry_run"] = dry_run
|
|
64
|
+
output.configure_logging(verbose)
|
|
65
|
+
output.help_if_no_command(ctx)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def main() -> None:
|
|
69
|
+
app()
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
if __name__ == "__main__":
|
|
73
|
+
main()
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""The commands of the CLI, one module per command or command group."""
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"""The `auth` command group: `status` reports the health of the credentials of every provider, or an empty report when
|
|
2
|
+
the package has none.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
import importlib
|
|
8
|
+
from datetime import UTC, datetime
|
|
9
|
+
|
|
10
|
+
import typer
|
|
11
|
+
|
|
12
|
+
from .. import output
|
|
13
|
+
from ..core.errors import InvalidArguments
|
|
14
|
+
from ..core.version import DEV_VERSION, cli_name, installed_version, module_exists, optional_module
|
|
15
|
+
|
|
16
|
+
# `auth status` exists in every CLI (the Standard, Health); a CLI
|
|
17
|
+
# generated without credentials (no credentials/ package, no commands/login.py)
|
|
18
|
+
# reports an empty `credentials` list and exits 0. Detected at runtime so this
|
|
19
|
+
# file needs no template logic — same approach as doctor.py.
|
|
20
|
+
_PACKAGE_NAME = __name__.split(".")[0]
|
|
21
|
+
_HAS_CREDENTIALS = module_exists(f"{_PACKAGE_NAME}.credentials.manager")
|
|
22
|
+
|
|
23
|
+
app = output.group("Credentials: report their health (and store them, if this CLI has any).")
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@app.command("status")
|
|
27
|
+
@output.guard
|
|
28
|
+
def auth_status(
|
|
29
|
+
ctx: typer.Context,
|
|
30
|
+
check: bool = typer.Option(
|
|
31
|
+
False, "--check", help="Also make one cheap read-only call per provider (10 s timeout) to prove each works."
|
|
32
|
+
),
|
|
33
|
+
provider: str | None = typer.Option(
|
|
34
|
+
None, "--provider", help="Report only this provider, or one target as <kind>:<target> (default: all)."
|
|
35
|
+
),
|
|
36
|
+
json_output: bool = output.JsonOption,
|
|
37
|
+
quiet: bool = output.QuietOption,
|
|
38
|
+
) -> None:
|
|
39
|
+
"""Report every provider's credential: where it comes from and whether it works. Never prints values.
|
|
40
|
+
|
|
41
|
+
Without --check only presence is reported (status `unchecked` or `missing`).
|
|
42
|
+
Exits 0 when every required provider is ok/unchecked (an optional one may be
|
|
43
|
+
missing), 3 when any required provider has a problem or any credential is
|
|
44
|
+
invalid/expired, 2 on a usage error. A per-target provider (one credential per
|
|
45
|
+
site/host/account) gets one entry per stored target, named `<kind>:<target>`. The --json shape is a cross-tool contract:
|
|
46
|
+
`tool`, `version`, `checked_at`, `credentials[]` with `provider`, `required`,
|
|
47
|
+
`fields`, `source`, `source_ref`, `status`, `expires_at`, `quota`, `message`.
|
|
48
|
+
|
|
49
|
+
Example: {cli} auth status --check --json
|
|
50
|
+
"""
|
|
51
|
+
tool, version = cli_name(), installed_version() or DEV_VERSION
|
|
52
|
+
if not _HAS_CREDENTIALS:
|
|
53
|
+
if provider is not None:
|
|
54
|
+
raise InvalidArguments(f"Unknown provider '{provider}' ({tool} stores no credentials).")
|
|
55
|
+
checked_at = datetime.now(UTC).replace(microsecond=0).isoformat().replace("+00:00", "Z")
|
|
56
|
+
payload = {"tool": tool, "version": version, "checked_at": checked_at, "credentials": []}
|
|
57
|
+
output.emit_report(ctx, payload, lambda _: output.human.echo(f"{tool} stores no credentials."), None)
|
|
58
|
+
return
|
|
59
|
+
health = importlib.import_module(f"{_PACKAGE_NAME}.credentials.health")
|
|
60
|
+
payload, problem = health.status(tool, version, check=check, only=provider)
|
|
61
|
+
output.emit_report(ctx, payload, health.render, problem)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
if _login := optional_module(f"{_PACKAGE_NAME}.commands.login"):
|
|
65
|
+
app.command("login")(_login.login)
|
|
66
|
+
app.command("logout")(_login.logout)
|