cli-svckit 0.1.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. cli_svckit-0.1.2/.githooks/pre-commit +3 -0
  2. cli_svckit-0.1.2/.githooks/pre-push +9 -0
  3. cli_svckit-0.1.2/.github/CODEOWNERS +1 -0
  4. cli_svckit-0.1.2/.github/dependabot.yml +10 -0
  5. cli_svckit-0.1.2/.github/workflows/ci.yml +82 -0
  6. cli_svckit-0.1.2/.github/workflows/release.yml +47 -0
  7. cli_svckit-0.1.2/.gitignore +12 -0
  8. cli_svckit-0.1.2/.public-check-allow +4 -0
  9. cli_svckit-0.1.2/AGENTS.md +24 -0
  10. cli_svckit-0.1.2/CHANGELOG.md +37 -0
  11. cli_svckit-0.1.2/CONTRIBUTING.md +44 -0
  12. cli_svckit-0.1.2/LICENSE +21 -0
  13. cli_svckit-0.1.2/PKG-INFO +151 -0
  14. cli_svckit-0.1.2/README.md +125 -0
  15. cli_svckit-0.1.2/SECURITY.md +7 -0
  16. cli_svckit-0.1.2/docs/compatibility.md +71 -0
  17. cli_svckit-0.1.2/docs/contract.md +216 -0
  18. cli_svckit-0.1.2/docs/coordination.md +90 -0
  19. cli_svckit-0.1.2/docs/design.md +86 -0
  20. cli_svckit-0.1.2/examples/README.md +31 -0
  21. cli_svckit-0.1.2/examples/toy_participant.py +137 -0
  22. cli_svckit-0.1.2/pyproject.toml +57 -0
  23. cli_svckit-0.1.2/scripts/check-public.sh +78 -0
  24. cli_svckit-0.1.2/scripts/compat_check.py +167 -0
  25. cli_svckit-0.1.2/scripts/install-hooks.sh +10 -0
  26. cli_svckit-0.1.2/src/cli_svckit/__init__.py +75 -0
  27. cli_svckit-0.1.2/src/cli_svckit/contract/__init__.py +47 -0
  28. cli_svckit-0.1.2/src/cli_svckit/contract/argparse_cli.py +37 -0
  29. cli_svckit-0.1.2/src/cli_svckit/contract/client.py +290 -0
  30. cli_svckit-0.1.2/src/cli_svckit/contract/discovery.py +76 -0
  31. cli_svckit-0.1.2/src/cli_svckit/contract/envelope.py +338 -0
  32. cli_svckit-0.1.2/src/cli_svckit/contract/schemas/complete.json +126 -0
  33. cli_svckit-0.1.2/src/cli_svckit/contract/schemas/describe.json +137 -0
  34. cli_svckit-0.1.2/src/cli_svckit/contract/schemas/doctor.json +87 -0
  35. cli_svckit-0.1.2/src/cli_svckit/contract/schemas/envelope.json +133 -0
  36. cli_svckit-0.1.2/src/cli_svckit/contract/schemas/health.json +75 -0
  37. cli_svckit-0.1.2/src/cli_svckit/contract/schemas/install.json +102 -0
  38. cli_svckit-0.1.2/src/cli_svckit/contract/schemas/lease.json +114 -0
  39. cli_svckit-0.1.2/src/cli_svckit/contract/schemas/prepare.json +89 -0
  40. cli_svckit-0.1.2/src/cli_svckit/contract/server.py +165 -0
  41. cli_svckit-0.1.2/src/cli_svckit/contract/typer_cli.py +36 -0
  42. cli_svckit-0.1.2/src/cli_svckit/coord/__init__.py +1 -0
  43. cli_svckit-0.1.2/src/cli_svckit/coord/controller.py +353 -0
  44. cli_svckit-0.1.2/src/cli_svckit/coord/lease.py +439 -0
  45. cli_svckit-0.1.2/src/cli_svckit/coord/participant.py +227 -0
  46. cli_svckit-0.1.2/src/cli_svckit/coord/watch.py +387 -0
  47. cli_svckit-0.1.2/src/cli_svckit/doctor.py +125 -0
  48. cli_svckit-0.1.2/src/cli_svckit/health.py +149 -0
  49. cli_svckit-0.1.2/src/cli_svckit/procs.py +139 -0
  50. cli_svckit-0.1.2/src/cli_svckit/py.typed +0 -0
  51. cli_svckit-0.1.2/src/cli_svckit/rcfile.py +336 -0
  52. cli_svckit-0.1.2/src/cli_svckit/receipts.py +59 -0
  53. cli_svckit-0.1.2/src/cli_svckit/testing.py +448 -0
  54. cli_svckit-0.1.2/tests/compat/contract-1.0/README.md +13 -0
  55. cli_svckit-0.1.2/tests/compat/contract-1.0/complete.json +126 -0
  56. cli_svckit-0.1.2/tests/compat/contract-1.0/describe.json +137 -0
  57. cli_svckit-0.1.2/tests/compat/contract-1.0/doctor.json +87 -0
  58. cli_svckit-0.1.2/tests/compat/contract-1.0/envelope.json +133 -0
  59. cli_svckit-0.1.2/tests/compat/contract-1.0/health.json +75 -0
  60. cli_svckit-0.1.2/tests/compat/contract-1.0/install.json +102 -0
  61. cli_svckit-0.1.2/tests/compat/contract-1.0/lease.json +114 -0
  62. cli_svckit-0.1.2/tests/compat/contract-1.0/prepare.json +89 -0
  63. cli_svckit-0.1.2/tests/compat/lease-v1/README.md +17 -0
  64. cli_svckit-0.1.2/tests/compat/lease-v1/cleared.json +36 -0
  65. cli_svckit-0.1.2/tests/compat/lease-v1/complete.json +48 -0
  66. cli_svckit-0.1.2/tests/compat/lease-v1/expired.json +33 -0
  67. cli_svckit-0.1.2/tests/compat/lease-v1/prepare.json +33 -0
  68. cli_svckit-0.1.2/tests/compat/lease-v1/running.json +39 -0
  69. cli_svckit-0.1.2/tests/test_cli_adapters.py +55 -0
  70. cli_svckit-0.1.2/tests/test_client.py +218 -0
  71. cli_svckit-0.1.2/tests/test_compat_check.py +126 -0
  72. cli_svckit-0.1.2/tests/test_compat_lease.py +215 -0
  73. cli_svckit-0.1.2/tests/test_compat_schemas.py +376 -0
  74. cli_svckit-0.1.2/tests/test_conformance.py +167 -0
  75. cli_svckit-0.1.2/tests/test_controller.py +304 -0
  76. cli_svckit-0.1.2/tests/test_crossversion.py +200 -0
  77. cli_svckit-0.1.2/tests/test_discovery.py +69 -0
  78. cli_svckit-0.1.2/tests/test_doctor.py +65 -0
  79. cli_svckit-0.1.2/tests/test_e2e_coordination.py +211 -0
  80. cli_svckit-0.1.2/tests/test_envelope.py +189 -0
  81. cli_svckit-0.1.2/tests/test_health.py +130 -0
  82. cli_svckit-0.1.2/tests/test_lease.py +262 -0
  83. cli_svckit-0.1.2/tests/test_participant.py +247 -0
  84. cli_svckit-0.1.2/tests/test_procs.py +80 -0
  85. cli_svckit-0.1.2/tests/test_rcfile.py +241 -0
  86. cli_svckit-0.1.2/tests/test_receipts.py +29 -0
  87. cli_svckit-0.1.2/tests/test_schemas.py +139 -0
  88. cli_svckit-0.1.2/tests/test_server.py +164 -0
  89. cli_svckit-0.1.2/tests/test_smoke.py +52 -0
  90. cli_svckit-0.1.2/tests/test_watch.py +182 -0
  91. cli_svckit-0.1.2/uv.lock +715 -0
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env bash
2
+ # Blocks commits that add secrets or machine/system details (see scripts/check-public.sh).
3
+ exec "$(git rev-parse --show-toplevel)/scripts/check-public.sh" --staged
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env bash
2
+ # Re-checks every commit being pushed (catches commits made with --no-verify).
3
+ set -euo pipefail
4
+ z=0000000000000000000000000000000000000000
5
+ while read -r _lref lsha _rref rsha; do
6
+ [[ "$lsha" == "$z" ]] && continue # branch delete
7
+ if [[ "$rsha" == "$z" ]]; then range="$lsha --not --remotes"; else range="$rsha..$lsha"; fi
8
+ "$(git rev-parse --show-toplevel)/scripts/check-public.sh" --range "$range"
9
+ done
@@ -0,0 +1 @@
1
+ * @ejlevin1
@@ -0,0 +1,10 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: github-actions
4
+ directory: /
5
+ schedule:
6
+ interval: weekly
7
+ - package-ecosystem: uv
8
+ directory: /
9
+ schedule:
10
+ interval: weekly
@@ -0,0 +1,82 @@
1
+ name: ci
2
+ on:
3
+ push:
4
+ branches: [main]
5
+ tags: ["v*"]
6
+ pull_request:
7
+ workflow_dispatch:
8
+
9
+ permissions:
10
+ contents: read
11
+
12
+ concurrency:
13
+ group: ci-${{ github.ref }}
14
+ cancel-in-progress: true
15
+
16
+ jobs:
17
+ test:
18
+ strategy:
19
+ fail-fast: false
20
+ matrix:
21
+ os: [ubuntu-latest, macos-latest]
22
+ python: ["3.11", "3.12", "3.13", "3.14"]
23
+ runs-on: ${{ matrix.os }}
24
+ steps:
25
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
26
+ with:
27
+ persist-credentials: false
28
+ - uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0
29
+ - run: uv run --locked --all-extras -p ${{ matrix.python }} pytest -q
30
+ - run: uv run --locked --all-extras -p ${{ matrix.python }} ruff check
31
+
32
+ public-check:
33
+ runs-on: ubuntu-latest
34
+ env:
35
+ GITLEAKS_VERSION: "8.30.1"
36
+ steps:
37
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
38
+ with:
39
+ fetch-depth: 0
40
+ persist-credentials: false
41
+ - name: install gitleaks (checksum verified)
42
+ run: |
43
+ set -euo pipefail
44
+ v="$GITLEAKS_VERSION"; base="https://github.com/gitleaks/gitleaks/releases/download/v${v}"
45
+ cd "$RUNNER_TEMP"
46
+ curl -sSfLO "${base}/gitleaks_${v}_linux_x64.tar.gz"
47
+ curl -sSfLO "${base}/gitleaks_${v}_checksums.txt"
48
+ sha256sum -c --ignore-missing "gitleaks_${v}_checksums.txt"
49
+ tar -xzf "gitleaks_${v}_linux_x64.tar.gz" gitleaks
50
+ sudo install -m 0755 gitleaks /usr/local/bin/gitleaks
51
+ - run: scripts/check-public.sh --all
52
+ - run: scripts/check-public.sh --history
53
+
54
+ compat:
55
+ strategy:
56
+ fail-fast: false
57
+ matrix:
58
+ os: [ubuntu-latest, macos-latest]
59
+ runs-on: ${{ matrix.os }}
60
+ steps:
61
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
62
+ with:
63
+ fetch-depth: 0
64
+ persist-credentials: false
65
+ - uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0
66
+ - name: public API vs previous release (Griffe)
67
+ run: uv run --locked --all-extras -p 3.13 python scripts/compat_check.py
68
+ - name: schema, lease and cross-version tests against the previous release
69
+ run: |
70
+ set -euo pipefail
71
+ prev=$(uv run --locked --all-extras -p 3.13 python -c "
72
+ import sys; sys.path.insert(0, 'scripts')
73
+ import compat_check
74
+ from pathlib import Path
75
+ print(compat_check.previous_tag(Path('.')) or '')")
76
+ if [ -n "$prev" ]; then
77
+ git worktree add "$RUNNER_TEMP/prev" "$prev"
78
+ export SVCKIT_PREV_SRC="$RUNNER_TEMP/prev"
79
+ else
80
+ echo "no previous release tag: cross-version tests will skip"
81
+ fi
82
+ uv run --locked --all-extras -p 3.13 pytest -q tests/test_crossversion.py tests/test_compat_schemas.py tests/test_compat_lease.py
@@ -0,0 +1,47 @@
1
+ name: release
2
+
3
+ # Publishes to PyPI with Trusted Publishing (OIDC): no API tokens are stored.
4
+ # Trigger: push a tag vX.Y.Z whose version equals pyproject.toml, or run manually for an existing tag.
5
+ on:
6
+ push:
7
+ tags: ["v*"]
8
+ workflow_dispatch:
9
+ inputs:
10
+ tag:
11
+ description: "Existing tag to publish (vX.Y.Z)"
12
+ required: true
13
+
14
+ permissions:
15
+ contents: read
16
+
17
+ jobs:
18
+ build:
19
+ runs-on: ubuntu-latest
20
+ steps:
21
+ - uses: actions/checkout@v4
22
+ with:
23
+ ref: ${{ github.event.inputs.tag || github.ref }}
24
+ - uses: astral-sh/setup-uv@v6
25
+ - name: Check tag matches the package version
26
+ run: |
27
+ tag="${{ github.event.inputs.tag || github.ref_name }}"
28
+ ver="$(python3 -c "import tomllib;print(tomllib.load(open(\"pyproject.toml\",\"rb\"))[\"project\"][\"version\"])")"
29
+ test "$tag" = "v$ver" || { echo "tag $tag does not match version $ver"; exit 1; }
30
+ - run: uv build
31
+ - uses: actions/upload-artifact@v4
32
+ with:
33
+ name: dist
34
+ path: dist/
35
+
36
+ publish:
37
+ needs: build
38
+ runs-on: ubuntu-latest
39
+ environment: pypi
40
+ permissions:
41
+ id-token: write
42
+ steps:
43
+ - uses: actions/download-artifact@v4
44
+ with:
45
+ name: dist
46
+ path: dist/
47
+ - uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,12 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ .venv/
4
+ build/
5
+ dist/
6
+ *.egg-info/
7
+ .pytest_cache/
8
+ .ruff_cache/
9
+ .coverage
10
+ htmlcov/
11
+ .DS_Store
12
+ *.bak*
@@ -0,0 +1,4 @@
1
+ # Narrow regexes for lines that legitimately match a system-info pattern (matched against the whole line).
2
+ # Keep each one specific and explain it.
3
+ # git@github.com ssh clone URL of this repo, not a personal email
4
+ git@github\.com:ejlevin1/cli-svckit\.git
@@ -0,0 +1,24 @@
1
+ # Agent rules for this repo
2
+
3
+ This repository is **public**. Treat every byte you commit as published.
4
+
5
+ ## Hard rules
6
+ 1. No secrets, tokens, keys or credentials, ever. Not in code, tests, fixtures, docs or commit messages.
7
+ 2. No system or personal information: no real names, home-directory paths (`/Users/<name>/`,
8
+ `/home/<name>/`), host names, private IPs, internal domains, ports of real deployments, or email
9
+ addresses other than `@example.com` / GitHub noreply. Use `~`, `<home>`, `example.com`,
10
+ `alice` / `bob` and `203.0.113.x` (TEST-NET) in examples.
11
+ 3. Never paste captured command output from a real machine into the repo; write synthetic examples.
12
+ 4. Run `scripts/check-public.sh --staged` before every commit (the pre-commit hook does this once
13
+ `scripts/install-hooks.sh` has been run). Never commit with `--no-verify`.
14
+ 5. Core package (`src/cli_svckit/`) uses the standard library only. Typer/Rich/psutil are optional
15
+ extras and must be imported lazily.
16
+ 6. Everything site-specific is passed in by the consuming tool: the library has no defaults that name a
17
+ real product, path or host.
18
+ 7. Tests must not touch the real service manager, real shell rc files or real lease directories: use
19
+ temp dirs and fakes.
20
+
21
+ ## Commands
22
+ - Tests: `uv run pytest -q`
23
+ - Lint: `uv run ruff check`
24
+ - Public check: `scripts/check-public.sh --all` (tree) / `--history` (all commits)
@@ -0,0 +1,37 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented here. The format follows
4
+ [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the project uses semantic versioning.
5
+
6
+ ## [0.1.2] - 2026-12-01
7
+
8
+ ### Added
9
+
10
+ - Release workflow: tags `vX.Y.Z` publish to PyPI with Trusted Publishing (OIDC, no stored tokens); the tag must match the package version.
11
+
12
+ ## [0.1.1]
13
+
14
+ ### Added
15
+ - Compatibility checks: a Griffe check of the public Python API against the previous release, schema and
16
+ lease-format compatibility tests (hypothesis-jsonschema against the frozen 1.0 schemas) and a cross-version run in CI.
17
+ - Documented compatibility policy (`docs/compatibility.md`).
18
+
19
+ ### Fixed
20
+ - Contract doc examples now use the operation kinds the library and its consumers use.
21
+
22
+ ## [0.1.0]
23
+
24
+ ### Added
25
+ - Contract envelope (`cli_svckit.contract.envelope`): versioned JSON request/response types, error codes, exit codes,
26
+ secret redaction, operation records, glob matching and bundled JSON schemas for every method.
27
+ - Contract client (`Participant`, `CallResult`, `negotiate`): runs a participant's `svc <method> --json` command with a
28
+ timeout and a fail-open or fail-closed policy, and negotiates the contract version.
29
+ - Contract server (`dispatch`, `run`): lets a tool answer contract calls from a simple provider object.
30
+ - Participant discovery (`participants_from_registry`): builds participants from a registry table.
31
+ - Lease directory (`LeaseDir`, `Lease`): a durable on-disk record of each restart or update operation, with phases,
32
+ expiry of stale leases and tombstones for finished operations.
33
+ - Participant side (`Interest`, `active_ops`, `Quiescer`): daemons learn which operations affect them, quiesce once on
34
+ prepare, resume once on completion, and catch up after a restart.
35
+ - Lease watcher (`LeaseWatcher`): notices lease directory changes using kqueue, inotify or polling.
36
+ - Controller (`Operation`): coordinates participants through prepare, running and complete phases.
37
+ - Health and doctor helpers (`HealthResult`, `run_checks`) plus a Typer/argparse CLI wiring for the contract.
@@ -0,0 +1,44 @@
1
+ # Contributing
2
+
3
+ ## Setup
4
+ ```sh
5
+ brew install gitleaks uv # or your platform's equivalent
6
+ uv sync
7
+ scripts/install-hooks.sh # sets core.hooksPath=.githooks for this clone
8
+ ```
9
+
10
+ ## Public-repo guard
11
+ Every commit and push runs `scripts/check-public.sh`:
12
+
13
+ - **gitleaks** for secrets;
14
+ - **generic system-info patterns** (home paths, private and CGNAT IPs, email addresses other than
15
+ example.com / GitHub noreply, Cloudflare Access domains);
16
+ - **your personal patterns**, read from `~/.config/public-check/patterns` (or `$PUBLIC_CHECK_PATTERNS`).
17
+ Put your own names, domains and host names there, one extended regex per line. That file is never
18
+ committed: a committed deny-list would itself be the leak.
19
+
20
+ The pre-push hook re-checks every pushed commit, so a commit made with `--no-verify` is still caught.
21
+ CI runs the same checks over the tree and the full history.
22
+
23
+ A false positive goes in `.public-check-allow` as a narrow regex with a comment explaining it.
24
+
25
+ ## Commits
26
+ - Conventional commit messages (`feat:`, `fix:`, `docs:`, `test:`, `chore:`).
27
+ - Author with your GitHub noreply address
28
+ (`git config user.email <id>+<login>@users.noreply.github.com`).
29
+
30
+ ## Compatibility
31
+ The [compatibility policy](docs/compatibility.md) protects the contract schemas, the lease format and the Python
32
+ API against the previous release. Before opening a pull request, run:
33
+
34
+ ```sh
35
+ git fetch --tags
36
+ uv run --locked python scripts/compat_check.py
37
+ uv run --locked --all-extras -q pytest -q tests/test_compat_schemas.py tests/test_compat_lease.py
38
+ ```
39
+
40
+ The cross-version test needs `SVCKIT_PREV_SRC` (see the policy page).
41
+
42
+ An allowed breaking change to the Python API (while 0.x) bumps the MINOR version and adds a `### Breaking` heading
43
+ listing it to the top `CHANGELOG.md` section. Contract and lease breakages need a new contract major or `"v": 2`
44
+ instead; see the policy page.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ejlevin1
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,151 @@
1
+ Metadata-Version: 2.5
2
+ Name: cli-svckit
3
+ Version: 0.1.2
4
+ Summary: Toolkit for CLIs that ship local services: lifecycle, CLI install, a JSON contract and restart/update coordination.
5
+ Project-URL: Homepage, https://github.com/ejlevin1/cli-svckit
6
+ Project-URL: Issues, https://github.com/ejlevin1/cli-svckit/issues
7
+ Author: ejlevin1
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Keywords: cli,coordination,launchd,services,systemd,typer
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Operating System :: MacOS
14
+ Classifier: Operating System :: POSIX :: Linux
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3 :: Only
17
+ Classifier: Topic :: System :: Systems Administration
18
+ Classifier: Typing :: Typed
19
+ Requires-Python: >=3.11
20
+ Provides-Extra: rich
21
+ Requires-Dist: rich>=13; extra == 'rich'
22
+ Provides-Extra: typer
23
+ Requires-Dist: rich>=13; extra == 'typer'
24
+ Requires-Dist: typer>=0.12; extra == 'typer'
25
+ Description-Content-Type: text/markdown
26
+
27
+ # cli-svckit
28
+
29
+ A small toolkit for command-line tools that ship local background services, so that one controller can
30
+ manage a whole set of them the same way.
31
+
32
+ > **Status: 0.1.0 (phase 0).** The contract and the coordination layer work today. Install from the git tag:
33
+ >
34
+ > ```sh
35
+ > pip install "cli-svckit @ git+https://github.com/ejlevin1/cli-svckit@v0.1.0"
36
+ > ```
37
+
38
+ Compatibility guarantees for the contract, lease format and Python API: [docs/compatibility.md](docs/compatibility.md).
39
+
40
+ ## What works now
41
+
42
+ - **The JSON contract** (`cli_svckit.contract`): every participating tool answers
43
+ `<tool> svc describe|health|doctor|install|uninstall|prepare|complete --json` with one versioned envelope
44
+ (`Request`, `Response`, `Error`, exit codes, JSON Schemas). `server.run` serves a provider object;
45
+ `client.Participant` calls a tool and `discovery` finds participants. Spec: [docs/contract.md](docs/contract.md).
46
+ - **Lease coordination** (`cli_svckit.coord`): before a disruptive operation the controller writes a durable lease
47
+ file; leases expire, so a controller that dies never freezes anyone. `LeaseDir`, `Lease`.
48
+ - **Watcher** (`coord.watch.LeaseWatcher`): kqueue, inotify or polling, with a callback after every change.
49
+ - **Controller** (`coord.controller.Operation`): a context manager that writes the lease, calls `prepare` until
50
+ every relevant participant is ready (or a cap is hit), runs your action, then calls `complete`.
51
+ - **Participant helpers** (`coord.participant`): `Interest` and `Quiescer` turn watcher events into one
52
+ `on_prepare` and one `on_complete` per operation, and survive daemon restarts.
53
+ - **Health and doctor** (`cli_svckit.health`, `cli_svckit.doctor`): health results, HTTP/port/pid probes, a doctor
54
+ runner with exit codes.
55
+ - **rc-file install** (`cli_svckit.rcfile`, `cli_svckit.receipts`): one marked line in a shell rc file or a
56
+ symlink on `PATH`; removal backs up first and refuses if the line was edited.
57
+ - **Testing helpers** (`cli_svckit.testing`): `FakeParticipant`, `temp_lease_dir`, `assert_conforms`.
58
+
59
+ ## Not yet
60
+
61
+ - launchd and systemd service backends (a declarative service spec rendered to the host's service manager).
62
+ - Rich renderers for health and doctor tables.
63
+ - A PyPI release (install from the git tag for now).
64
+
65
+ ## A participant in about 20 lines
66
+
67
+ A daemon that pauses its work while an `update` of its service is in progress. The `svc` entry point answers the
68
+ controller's `prepare` and `complete` calls; the lease watcher covers the case where nobody calls it.
69
+
70
+ ```python
71
+ import sys
72
+ from cli_svckit.contract.server import run
73
+ from cli_svckit.coord.lease import LeaseDir
74
+ from cli_svckit.coord.participant import Interest, Quiescer
75
+ from cli_svckit.coord.watch import LeaseWatcher
76
+
77
+ class Provider:
78
+ def describe(self, params):
79
+ return {"tool": {"name": "example-tool", "version": "1.0"},
80
+ "coordination": {"kinds": ["update"], "services": ["com.example.*"], "watches_lease": True}}
81
+ def prepare(self, params):
82
+ return {"state": "ready", "op_id": params["op"]["id"], "quiesced": True, "in_flight": []}
83
+ def complete(self, params):
84
+ return {"state": "resumed", "actions": []}
85
+
86
+ def daemon(lease_path):
87
+ leases = LeaseDir(lease_path)
88
+ leases.ensure()
89
+ q = Quiescer(leases, Interest(["update"], ["com.example.*"]),
90
+ on_prepare=lambda lease: print("pausing for", lease.op.id),
91
+ on_complete=lambda lease: print("resuming:", lease.outcome))
92
+ q.catch_up()
93
+ LeaseWatcher(leases.path, q.refresh).start()
94
+
95
+ if __name__ == "__main__":
96
+ sys.exit(run(Provider(), sys.argv[2:])) # example-tool svc <method> --json
97
+ ```
98
+
99
+ A longer, runnable version is `examples/toy_participant.py`.
100
+
101
+ ## A controller in about 15 lines
102
+
103
+ ```python
104
+ import os
105
+ from cli_svckit.contract.client import Participant
106
+ from cli_svckit.coord.controller import Operation
107
+ from cli_svckit.coord.lease import LeaseDir
108
+
109
+ leases = LeaseDir(os.path.expanduser("~/.local/state/example-tool/leases"))
110
+ workers = [Participant("example-tool", ["example-tool"])]
111
+
112
+ op = Operation("update", ["com.example.worker"], lease_dir=leases, participants=workers,
113
+ reason="upgrade to 1.4.0", by={"tool": "example-tool", "user": "alice"},
114
+ max_wait_s=300, on_cap="proceed")
115
+ with op: # writes the lease, calls prepare until ready, sets phase running
116
+ restart_service("com.example.worker") # your code
117
+ op.facts["new_version"] = "1.4.0" # stored on the lease and passed to complete
118
+ # leaving the block calls complete on each participant and moves the lease to done/
119
+ ```
120
+
121
+ `restart_service` stands for your own code. If it raises, the operation ends with outcome `failed`. If participants
122
+ are not ready at the cap and `on_cap="abort"`, `OperationAborted` is raised and the lease ends as `aborted`.
123
+
124
+ ## Further reading
125
+
126
+ - [docs/design.md](docs/design.md): why hooks plus a lease directory, and the semantics.
127
+ - [docs/coordination.md](docs/coordination.md): the full prepare, run, complete sequence and the lease file.
128
+ - [docs/contract.md](docs/contract.md): the wire contract.
129
+
130
+ ## Design rules
131
+
132
+ - Generic: every name, label, path, host and port comes from the consuming tool. Nothing site-specific
133
+ lives here.
134
+ - Small: launchd and systemd remain the supervisors. The library renders specs and talks to them; it is
135
+ not a process manager.
136
+ - Python 3.11+, zero runtime dependencies in the core.
137
+
138
+ ## Development
139
+
140
+ ```sh
141
+ uv sync
142
+ scripts/install-hooks.sh # once per clone: secret + system-info checks on commit and push
143
+ uv run pytest -q
144
+ uv run ruff check
145
+ ```
146
+
147
+ See [CONTRIBUTING.md](CONTRIBUTING.md) and [SECURITY.md](SECURITY.md).
148
+
149
+ ## License
150
+
151
+ [MIT](LICENSE)
@@ -0,0 +1,125 @@
1
+ # cli-svckit
2
+
3
+ A small toolkit for command-line tools that ship local background services, so that one controller can
4
+ manage a whole set of them the same way.
5
+
6
+ > **Status: 0.1.0 (phase 0).** The contract and the coordination layer work today. Install from the git tag:
7
+ >
8
+ > ```sh
9
+ > pip install "cli-svckit @ git+https://github.com/ejlevin1/cli-svckit@v0.1.0"
10
+ > ```
11
+
12
+ Compatibility guarantees for the contract, lease format and Python API: [docs/compatibility.md](docs/compatibility.md).
13
+
14
+ ## What works now
15
+
16
+ - **The JSON contract** (`cli_svckit.contract`): every participating tool answers
17
+ `<tool> svc describe|health|doctor|install|uninstall|prepare|complete --json` with one versioned envelope
18
+ (`Request`, `Response`, `Error`, exit codes, JSON Schemas). `server.run` serves a provider object;
19
+ `client.Participant` calls a tool and `discovery` finds participants. Spec: [docs/contract.md](docs/contract.md).
20
+ - **Lease coordination** (`cli_svckit.coord`): before a disruptive operation the controller writes a durable lease
21
+ file; leases expire, so a controller that dies never freezes anyone. `LeaseDir`, `Lease`.
22
+ - **Watcher** (`coord.watch.LeaseWatcher`): kqueue, inotify or polling, with a callback after every change.
23
+ - **Controller** (`coord.controller.Operation`): a context manager that writes the lease, calls `prepare` until
24
+ every relevant participant is ready (or a cap is hit), runs your action, then calls `complete`.
25
+ - **Participant helpers** (`coord.participant`): `Interest` and `Quiescer` turn watcher events into one
26
+ `on_prepare` and one `on_complete` per operation, and survive daemon restarts.
27
+ - **Health and doctor** (`cli_svckit.health`, `cli_svckit.doctor`): health results, HTTP/port/pid probes, a doctor
28
+ runner with exit codes.
29
+ - **rc-file install** (`cli_svckit.rcfile`, `cli_svckit.receipts`): one marked line in a shell rc file or a
30
+ symlink on `PATH`; removal backs up first and refuses if the line was edited.
31
+ - **Testing helpers** (`cli_svckit.testing`): `FakeParticipant`, `temp_lease_dir`, `assert_conforms`.
32
+
33
+ ## Not yet
34
+
35
+ - launchd and systemd service backends (a declarative service spec rendered to the host's service manager).
36
+ - Rich renderers for health and doctor tables.
37
+ - A PyPI release (install from the git tag for now).
38
+
39
+ ## A participant in about 20 lines
40
+
41
+ A daemon that pauses its work while an `update` of its service is in progress. The `svc` entry point answers the
42
+ controller's `prepare` and `complete` calls; the lease watcher covers the case where nobody calls it.
43
+
44
+ ```python
45
+ import sys
46
+ from cli_svckit.contract.server import run
47
+ from cli_svckit.coord.lease import LeaseDir
48
+ from cli_svckit.coord.participant import Interest, Quiescer
49
+ from cli_svckit.coord.watch import LeaseWatcher
50
+
51
+ class Provider:
52
+ def describe(self, params):
53
+ return {"tool": {"name": "example-tool", "version": "1.0"},
54
+ "coordination": {"kinds": ["update"], "services": ["com.example.*"], "watches_lease": True}}
55
+ def prepare(self, params):
56
+ return {"state": "ready", "op_id": params["op"]["id"], "quiesced": True, "in_flight": []}
57
+ def complete(self, params):
58
+ return {"state": "resumed", "actions": []}
59
+
60
+ def daemon(lease_path):
61
+ leases = LeaseDir(lease_path)
62
+ leases.ensure()
63
+ q = Quiescer(leases, Interest(["update"], ["com.example.*"]),
64
+ on_prepare=lambda lease: print("pausing for", lease.op.id),
65
+ on_complete=lambda lease: print("resuming:", lease.outcome))
66
+ q.catch_up()
67
+ LeaseWatcher(leases.path, q.refresh).start()
68
+
69
+ if __name__ == "__main__":
70
+ sys.exit(run(Provider(), sys.argv[2:])) # example-tool svc <method> --json
71
+ ```
72
+
73
+ A longer, runnable version is `examples/toy_participant.py`.
74
+
75
+ ## A controller in about 15 lines
76
+
77
+ ```python
78
+ import os
79
+ from cli_svckit.contract.client import Participant
80
+ from cli_svckit.coord.controller import Operation
81
+ from cli_svckit.coord.lease import LeaseDir
82
+
83
+ leases = LeaseDir(os.path.expanduser("~/.local/state/example-tool/leases"))
84
+ workers = [Participant("example-tool", ["example-tool"])]
85
+
86
+ op = Operation("update", ["com.example.worker"], lease_dir=leases, participants=workers,
87
+ reason="upgrade to 1.4.0", by={"tool": "example-tool", "user": "alice"},
88
+ max_wait_s=300, on_cap="proceed")
89
+ with op: # writes the lease, calls prepare until ready, sets phase running
90
+ restart_service("com.example.worker") # your code
91
+ op.facts["new_version"] = "1.4.0" # stored on the lease and passed to complete
92
+ # leaving the block calls complete on each participant and moves the lease to done/
93
+ ```
94
+
95
+ `restart_service` stands for your own code. If it raises, the operation ends with outcome `failed`. If participants
96
+ are not ready at the cap and `on_cap="abort"`, `OperationAborted` is raised and the lease ends as `aborted`.
97
+
98
+ ## Further reading
99
+
100
+ - [docs/design.md](docs/design.md): why hooks plus a lease directory, and the semantics.
101
+ - [docs/coordination.md](docs/coordination.md): the full prepare, run, complete sequence and the lease file.
102
+ - [docs/contract.md](docs/contract.md): the wire contract.
103
+
104
+ ## Design rules
105
+
106
+ - Generic: every name, label, path, host and port comes from the consuming tool. Nothing site-specific
107
+ lives here.
108
+ - Small: launchd and systemd remain the supervisors. The library renders specs and talks to them; it is
109
+ not a process manager.
110
+ - Python 3.11+, zero runtime dependencies in the core.
111
+
112
+ ## Development
113
+
114
+ ```sh
115
+ uv sync
116
+ scripts/install-hooks.sh # once per clone: secret + system-info checks on commit and push
117
+ uv run pytest -q
118
+ uv run ruff check
119
+ ```
120
+
121
+ See [CONTRIBUTING.md](CONTRIBUTING.md) and [SECURITY.md](SECURITY.md).
122
+
123
+ ## License
124
+
125
+ [MIT](LICENSE)
@@ -0,0 +1,7 @@
1
+ # Security policy
2
+
3
+ Please report vulnerabilities privately through GitHub:
4
+ **Security → Report a vulnerability** on this repository (private vulnerability reporting).
5
+ Do not open a public issue for security problems.
6
+
7
+ Only the latest release is supported while the project is pre-1.0.
@@ -0,0 +1,71 @@
1
+ # Compatibility policy
2
+
3
+ cli-svckit has three public surfaces that other tools depend on: the JSON contract, the lease file format and the
4
+ Python API. This page says what may change in a release and which CI checks enforce it. The checks compare the
5
+ current tree against the **previous release**: the highest `vX.Y.Z` tag that is an ancestor of HEAD and is not the
6
+ version in `pyproject.toml` (so a build of a release tag compares against the release before it).
7
+
8
+ ## The policy
9
+
10
+ **P1. Contract 1.x is never breaking.** A schema change that rejects any instance valid under the frozen 1.0
11
+ schema, or that adds a required field, fails CI. A breaking contract change needs a contract major (2.0) and
12
+ frozen 2.0 copies of the schemas.
13
+
14
+ **P2. Lease format v1 stays readable.** Current code must read every stored v1 sample with the same meaning.
15
+ A breaking change needs `"v": 2`. Readers ignore lease files whose `v` is greater than they understand.
16
+
17
+ **P3. Python API.** While the version is 0.x, a breakage found by Griffe fails CI unless both hold:
18
+
19
+ 1. the MINOR version is bumped compared with the previous tag, and
20
+ 2. the top section of `CHANGELOG.md` has a `### Breaking` heading that lists the breakage.
21
+
22
+ From 1.0 on, a breakage needs a major bump. Deprecations keep the old name for at least one minor release and
23
+ emit a `DeprecationWarning`.
24
+
25
+ **P4. Cross-version.** The previous release's example participant must pass the current `assert_conforms` and
26
+ complete a coordinated operation with the current controller. The current example participant must do the same
27
+ with the previous release's controller.
28
+
29
+ ## What each check does
30
+
31
+ | Policy | Check | What it does |
32
+ | --- | --- | --- |
33
+ | P1 | `tests/test_compat_schemas.py` | Generates instances with hypothesis-jsonschema from the frozen 1.0 schemas in `tests/compat/contract-1.0/` and validates each against the current schemas. Also validates the stored sample documents. |
34
+ | P2 | `tests/test_compat_lease.py` | Reads each stored v1 lease in `tests/compat/lease-v1/` with the current code and checks the meaning (phase, outcome, expiry). |
35
+ | P3 | `scripts/compat_check.py` | Uses Griffe to compare the public API (`cli_svckit.__all__`) with the previous tag, then applies the version-bump and CHANGELOG rule. |
36
+ | P4 | `tests/test_crossversion.py` | Runs the previous release's example participant against the current controller, and the reverse. Skipped unless `SVCKIT_PREV_SRC` is set. |
37
+
38
+ ## Running the checks locally
39
+
40
+ API check (needs tags: `git fetch --tags`):
41
+
42
+ ```sh
43
+ uv run --locked python scripts/compat_check.py # against the previous release
44
+ uv run --locked python scripts/compat_check.py --against v0.1.0
45
+ ```
46
+
47
+ Exit code 0 means fine, or nothing to compare; 1 means a disallowed breakage.
48
+
49
+ Schema and lease tests:
50
+
51
+ ```sh
52
+ uv run --locked --all-extras -q pytest -q tests/test_compat_schemas.py tests/test_compat_lease.py
53
+ ```
54
+
55
+ Hypothesis runs `max_examples=200`. Set `HYPOTHESIS_PROFILE=ci` to derandomize, as CI does.
56
+
57
+ Cross-version test: check out the previous release into a separate directory and point `SVCKIT_PREV_SRC` at it.
58
+
59
+ ```sh
60
+ git worktree add /tmp/svckit-prev v0.1.0
61
+ SVCKIT_PREV_SRC=/tmp/svckit-prev uv run --locked --all-extras -q pytest -q tests/test_crossversion.py
62
+ git worktree remove /tmp/svckit-prev
63
+ ```
64
+
65
+ ## Making an allowed breaking change
66
+
67
+ - **Contract:** add the new major, freeze copies of its schemas next to the 1.0 ones, and keep the 1.0 checks
68
+ running for as long as 1.x is supported.
69
+ - **Lease:** write `"v": 2`; keep reading v1.
70
+ - **Python API (0.x):** bump the minor in `pyproject.toml` and `src/cli_svckit/__init__.py`, run `uv lock`, and add
71
+ a `### Breaking` heading to the top `CHANGELOG.md` section that names each breakage. Prefer deprecating first.