heddle-mcp 0.1.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.
- heddle_mcp-0.1.0/.github/workflows/ci.yml +46 -0
- heddle_mcp-0.1.0/.github/workflows/release.yml +53 -0
- heddle_mcp-0.1.0/.gitignore +8 -0
- heddle_mcp-0.1.0/CLAUDE.md +75 -0
- heddle_mcp-0.1.0/ISSUES.md +23 -0
- heddle_mcp-0.1.0/LICENSE +202 -0
- heddle_mcp-0.1.0/PKG-INFO +178 -0
- heddle_mcp-0.1.0/README.md +150 -0
- heddle_mcp-0.1.0/RELEASING.md +44 -0
- heddle_mcp-0.1.0/ROADMAP.md +90 -0
- heddle_mcp-0.1.0/bench/benchmark.py +107 -0
- heddle_mcp-0.1.0/docs/demo.md +55 -0
- heddle_mcp-0.1.0/docs/launch.md +85 -0
- heddle_mcp-0.1.0/examples/sales/conftest.py +4 -0
- heddle_mcp-0.1.0/examples/sales/contracts/Customer.yaml +10 -0
- heddle_mcp-0.1.0/examples/sales/contracts/Product.yaml +10 -0
- heddle_mcp-0.1.0/examples/sales/contracts/Region.yaml +8 -0
- heddle_mcp-0.1.0/examples/sales/contracts/Sale.yaml +12 -0
- heddle_mcp-0.1.0/examples/sales/contracts/average_sale.yaml +16 -0
- heddle_mcp-0.1.0/examples/sales/contracts/customers_by_segment.yaml +12 -0
- heddle_mcp-0.1.0/examples/sales/contracts/included_sales.yaml +15 -0
- heddle_mcp-0.1.0/examples/sales/contracts/revenue_by_category.yaml +12 -0
- heddle_mcp-0.1.0/examples/sales/contracts/revenue_by_customer.yaml +12 -0
- heddle_mcp-0.1.0/examples/sales/contracts/revenue_by_product.yaml +12 -0
- heddle_mcp-0.1.0/examples/sales/contracts/revenue_by_region.yaml +13 -0
- heddle_mcp-0.1.0/examples/sales/contracts/revenue_by_segment.yaml +13 -0
- heddle_mcp-0.1.0/examples/sales/contracts/revenue_share_by_region.yaml +16 -0
- heddle_mcp-0.1.0/examples/sales/contracts/sale_count_by_region.yaml +12 -0
- heddle_mcp-0.1.0/examples/sales/contracts/sales_in_region.yaml +12 -0
- heddle_mcp-0.1.0/examples/sales/contracts/sales_over.yaml +12 -0
- heddle_mcp-0.1.0/examples/sales/contracts/segment_revenue_share.yaml +16 -0
- heddle_mcp-0.1.0/examples/sales/contracts/top_customers.yaml +14 -0
- heddle_mcp-0.1.0/examples/sales/contracts/top_products.yaml +14 -0
- heddle_mcp-0.1.0/examples/sales/contracts/total_revenue.yaml +12 -0
- heddle_mcp-0.1.0/examples/sales/src/__init__.py +0 -0
- heddle_mcp-0.1.0/examples/sales/src/customers.py +29 -0
- heddle_mcp-0.1.0/examples/sales/src/filters.py +15 -0
- heddle_mcp-0.1.0/examples/sales/src/metrics.py +49 -0
- heddle_mcp-0.1.0/examples/sales/src/products.py +28 -0
- heddle_mcp-0.1.0/examples/sales/src/types.py +28 -0
- heddle_mcp-0.1.0/examples/sales/tests/__init__.py +0 -0
- heddle_mcp-0.1.0/examples/sales/tests/test_customers.py +36 -0
- heddle_mcp-0.1.0/examples/sales/tests/test_filters.py +39 -0
- heddle_mcp-0.1.0/examples/sales/tests/test_metrics.py +71 -0
- heddle_mcp-0.1.0/examples/sales/tests/test_products.py +37 -0
- heddle_mcp-0.1.0/examples/sales/tests/test_types.py +20 -0
- heddle_mcp-0.1.0/pyproject.toml +52 -0
- heddle_mcp-0.1.0/src/heddle/__init__.py +8 -0
- heddle_mcp-0.1.0/src/heddle/api.py +190 -0
- heddle_mcp-0.1.0/src/heddle/cli.py +92 -0
- heddle_mcp-0.1.0/src/heddle/config.py +115 -0
- heddle_mcp-0.1.0/src/heddle/contract.py +115 -0
- heddle_mcp-0.1.0/src/heddle/errors.py +26 -0
- heddle_mcp-0.1.0/src/heddle/implhash.py +63 -0
- heddle_mcp-0.1.0/src/heddle/indexer.py +91 -0
- heddle_mcp-0.1.0/src/heddle/project.py +144 -0
- heddle_mcp-0.1.0/src/heddle/py.typed +0 -0
- heddle_mcp-0.1.0/src/heddle/server.py +83 -0
- heddle_mcp-0.1.0/src/heddle/store.py +179 -0
- heddle_mcp-0.1.0/src/heddle/tokens.py +36 -0
- heddle_mcp-0.1.0/src/heddle/verify.py +142 -0
- heddle_mcp-0.1.0/tests/__init__.py +0 -0
- heddle_mcp-0.1.0/tests/conftest.py +83 -0
- heddle_mcp-0.1.0/tests/test_cli.py +56 -0
- heddle_mcp-0.1.0/tests/test_concurrency.py +63 -0
- heddle_mcp-0.1.0/tests/test_contract_hash.py +120 -0
- heddle_mcp-0.1.0/tests/test_implhash.py +88 -0
- heddle_mcp-0.1.0/tests/test_interpreter.py +128 -0
- heddle_mcp-0.1.0/tests/test_mcp_e2e.py +87 -0
- heddle_mcp-0.1.0/tests/test_namespacing.py +212 -0
- heddle_mcp-0.1.0/tests/test_pycache.py +96 -0
- heddle_mcp-0.1.0/tests/test_store_and_api.py +142 -0
- heddle_mcp-0.1.0/tests/test_verify.py +109 -0
- heddle_mcp-0.1.0/uv.lock +1395 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
pull_request:
|
|
6
|
+
|
|
7
|
+
# cancel superseded runs on the same ref (e.g. rapid pushes)
|
|
8
|
+
concurrency:
|
|
9
|
+
group: ${{ github.workflow }}-${{ github.ref }}
|
|
10
|
+
cancel-in-progress: true
|
|
11
|
+
|
|
12
|
+
permissions:
|
|
13
|
+
contents: read
|
|
14
|
+
|
|
15
|
+
jobs:
|
|
16
|
+
test:
|
|
17
|
+
name: test (py${{ matrix.python-version }})
|
|
18
|
+
runs-on: ubuntu-latest
|
|
19
|
+
strategy:
|
|
20
|
+
fail-fast: false
|
|
21
|
+
matrix:
|
|
22
|
+
python-version: ["3.10", "3.11", "3.12", "3.13"]
|
|
23
|
+
steps:
|
|
24
|
+
- uses: actions/checkout@v4
|
|
25
|
+
- uses: astral-sh/setup-uv@v6
|
|
26
|
+
with:
|
|
27
|
+
enable-cache: true
|
|
28
|
+
- name: Sync deps
|
|
29
|
+
run: uv sync --frozen --python ${{ matrix.python-version }}
|
|
30
|
+
- name: Run tests
|
|
31
|
+
# hash-stability suites are load-bearing; e2e spawns the real stdio server
|
|
32
|
+
run: uv run --python ${{ matrix.python-version }} pytest -q
|
|
33
|
+
|
|
34
|
+
benchmark:
|
|
35
|
+
name: benchmark (>5x DoD guard)
|
|
36
|
+
runs-on: ubuntu-latest
|
|
37
|
+
steps:
|
|
38
|
+
- uses: actions/checkout@v4
|
|
39
|
+
- uses: astral-sh/setup-uv@v6
|
|
40
|
+
with:
|
|
41
|
+
enable-cache: true
|
|
42
|
+
- name: Sync deps
|
|
43
|
+
run: uv sync --frozen
|
|
44
|
+
- name: Token-reduction benchmark
|
|
45
|
+
# exits nonzero below the 5x definition-of-done line
|
|
46
|
+
run: uv run python bench/benchmark.py
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
name: Release
|
|
2
|
+
|
|
3
|
+
# Publish to PyPI via Trusted Publishing (OIDC) when a version tag is pushed.
|
|
4
|
+
# No API token is stored: the publish job mints a short-lived OIDC token that
|
|
5
|
+
# PyPI trusts because this repo + workflow + environment are registered there.
|
|
6
|
+
#
|
|
7
|
+
# The published version comes from src/heddle/__init__.py (hatchling reads it
|
|
8
|
+
# as the dynamic version); the tag is only the trigger, so keep the tag and
|
|
9
|
+
# __version__ in sync, e.g. __version__ = "0.1.0" published by tag v0.1.0.
|
|
10
|
+
|
|
11
|
+
on:
|
|
12
|
+
push:
|
|
13
|
+
tags:
|
|
14
|
+
- "v*"
|
|
15
|
+
|
|
16
|
+
permissions:
|
|
17
|
+
contents: read
|
|
18
|
+
|
|
19
|
+
jobs:
|
|
20
|
+
build:
|
|
21
|
+
name: Build distribution
|
|
22
|
+
runs-on: ubuntu-latest
|
|
23
|
+
steps:
|
|
24
|
+
- uses: actions/checkout@v4
|
|
25
|
+
- uses: astral-sh/setup-uv@v6
|
|
26
|
+
with:
|
|
27
|
+
enable-cache: true
|
|
28
|
+
- name: Build sdist and wheel
|
|
29
|
+
run: uv build
|
|
30
|
+
- name: Store the distribution
|
|
31
|
+
uses: actions/upload-artifact@v4
|
|
32
|
+
with:
|
|
33
|
+
name: dist
|
|
34
|
+
path: dist/
|
|
35
|
+
|
|
36
|
+
publish:
|
|
37
|
+
name: Publish to PyPI
|
|
38
|
+
needs: build
|
|
39
|
+
runs-on: ubuntu-latest
|
|
40
|
+
# `name` must match the environment in the PyPI pending-publisher form.
|
|
41
|
+
environment:
|
|
42
|
+
name: pypi
|
|
43
|
+
url: https://pypi.org/p/heddle-mcp
|
|
44
|
+
permissions:
|
|
45
|
+
id-token: write # required for Trusted Publishing; no stored secret
|
|
46
|
+
steps:
|
|
47
|
+
- name: Download the distribution
|
|
48
|
+
uses: actions/download-artifact@v4
|
|
49
|
+
with:
|
|
50
|
+
name: dist
|
|
51
|
+
path: dist/
|
|
52
|
+
- name: Publish to PyPI
|
|
53
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# Working rules for heddle
|
|
2
|
+
|
|
3
|
+
Heddle is a hash-keyed verification cache + content-addressed contract store,
|
|
4
|
+
exposed over MCP. Contracts are warp (durable), code is weft (regenerable). These
|
|
5
|
+
rules override default behavior — follow them.
|
|
6
|
+
|
|
7
|
+
## Git is the user's
|
|
8
|
+
|
|
9
|
+
**Commit and push only when the user explicitly asks** — never on your own, and
|
|
10
|
+
write **no `Co-Authored-By` trailer** when you do. The user owns the PR/merge flow
|
|
11
|
+
and brings local back to a clean, synced `main` before each new piece of work.
|
|
12
|
+
|
|
13
|
+
**A fresh branch per change.** The first action on any new feature/change is
|
|
14
|
+
`git switch -c <scoped-name>` off `main` — never commit to `main`, and never reuse
|
|
15
|
+
a previous feature branch for new work. One piece = one branch = one PR.
|
|
16
|
+
|
|
17
|
+
**Never git worktrees** — too much machinery for this project; the user dislikes
|
|
18
|
+
them. Don't reach for worktree isolation.
|
|
19
|
+
|
|
20
|
+
## Scope discipline
|
|
21
|
+
|
|
22
|
+
Anything not on the current milestone is an entry in [ISSUES.md](ISSUES.md) — file
|
|
23
|
+
it there, don't write the code. The named failure mode is "scope creep toward
|
|
24
|
+
Loom." Keep the surface minimal: **5 MCP tools, 5 CLI commands.** The README
|
|
25
|
+
documents "the entire surface"; if a change would add to it, stop and confirm.
|
|
26
|
+
|
|
27
|
+
## Definition of done: >5x token reduction
|
|
28
|
+
|
|
29
|
+
`bench/benchmark.py` is the DoD guard — it exits nonzero below 5x (currently
|
|
30
|
+
5.5x). Run it for anything that could touch the context packets or hashing.
|
|
31
|
+
**Never regress it.**
|
|
32
|
+
|
|
33
|
+
## Hash stability is load-bearing
|
|
34
|
+
|
|
35
|
+
`tests/test_contract_hash.py` and `tests/test_implhash.py` are the spec. Cosmetic
|
|
36
|
+
input changes — whitespace, key order, comments, docstrings, file relocation —
|
|
37
|
+
must never change a hash; meaning changes (signature, invariant/example order)
|
|
38
|
+
must. If you touch `contract.py` or `implhash.py`, these tests are the contract.
|
|
39
|
+
Run `uv run pytest` (full suite) before declaring anything done.
|
|
40
|
+
|
|
41
|
+
## The store is derived
|
|
42
|
+
|
|
43
|
+
`.heddle/store.db` is rebuildable from `contracts/` via `heddle index` — never
|
|
44
|
+
hand-edit it. `contracts/*.yaml` is the source of truth.
|
|
45
|
+
|
|
46
|
+
## Errors are structured
|
|
47
|
+
|
|
48
|
+
Nothing leaks a stack trace over MCP. `_respond` in
|
|
49
|
+
[server.py](src/heddle/server.py) wraps every tool; raise `HeddleError(code,
|
|
50
|
+
message)` for anything an agent should see. Keep it that way.
|
|
51
|
+
|
|
52
|
+
## The verify interpreter
|
|
53
|
+
|
|
54
|
+
`verify` shells pytest out to a resolved interpreter (see
|
|
55
|
+
[config.py](src/heddle/config.py)), in precedence order:
|
|
56
|
+
|
|
57
|
+
1. `heddle serve --python PATH`
|
|
58
|
+
2. `.heddle/config.json` → `{"python": "..."}`
|
|
59
|
+
3. auto-detected project venv (`<root>/.venv/bin/python`, …)
|
|
60
|
+
4. `sys.executable`
|
|
61
|
+
|
|
62
|
+
So heddle can verify a target project against *its own* venv without being
|
|
63
|
+
installed into it. `heddle status` reports the resolved interpreter.
|
|
64
|
+
|
|
65
|
+
## How to run
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
uv run pytest # full suite — hash stability is load-bearing
|
|
69
|
+
uv run python bench/benchmark.py # the DoD number
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
CI (`.github/workflows/ci.yml`) runs both on every push and PR, so the DoD and
|
|
73
|
+
hash-stability rules are enforced, not just documented. Keep it green.
|
|
74
|
+
|
|
75
|
+
Python >=3.10. Deps: mcp, pyyaml, tiktoken, pytest.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Filed issues (v0.1 non-goals and follow-ups)
|
|
2
|
+
|
|
3
|
+
Per the v0.1 spec: if a task isn't on a milestone, it's an issue. These move to
|
|
4
|
+
the GitHub tracker once the repo has a remote.
|
|
5
|
+
|
|
6
|
+
## Deferred by design (spec non-goals)
|
|
7
|
+
|
|
8
|
+
1. **Multi-language support** — v0.1 is Python-only (AST hashing and pytest runner are Python-specific). Each language needs a normalised-AST hasher and a test-runner adapter.
|
|
9
|
+
2. **Content-addressed implementation store** — implementations remain plain files on disk; only their hashes live in the store.
|
|
10
|
+
3. **Hosted / team-shared store** — single-process, single sqlite file for now. A shared verification cache across a team is the obvious v0.2 candidate.
|
|
11
|
+
4. **Semantic diff rendering** — `put_contract` reports *that* a contract changed and who is invalidated, not a pretty diff of *what* changed.
|
|
12
|
+
5. **Tessl spec-format compatibility** — import/export adapter for Tessl-style spec files. Format is frozen for v0.1 as specced.
|
|
13
|
+
6. **New syntax of any kind** — contracts stay plain YAML.
|
|
14
|
+
|
|
15
|
+
## Known limitations / follow-ups
|
|
16
|
+
|
|
17
|
+
7. **PyPI release** — `pip install heddle-mcp` in the README assumes publication; cut 0.1.0 to PyPI (the bare `heddle` name is held by a third-party placeholder, so the distribution name is `heddle-mcp`).
|
|
18
|
+
8. **README gif** — record the Claude Code → heddle demo loop.
|
|
19
|
+
9. **Pre-existing stale bytecode** — the verification runner passes `-B` / `PYTHONDONTWRITEBYTECODE` so its own runs never cache bytecode, but a stale user-written `__pycache__` (same size, same mtime second) could still be loaded. Consider a `--no-pycache-trust` mode that clears `__pycache__` in the dep closure before running.
|
|
20
|
+
10. **Name finalization** — "heddle" is a working name; rename is a find-and-replace.
|
|
21
|
+
11. **Demo gif** — record the Claude Code → heddle loop; storyboard + exact command sequence in [docs/demo.md](docs/demo.md).
|
|
22
|
+
12. **Contract names are global** — no namespacing/packages; collisions across folders are unhandled (one `contracts/` dir per project for now).
|
|
23
|
+
|
heddle_mcp-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: heddle-mcp
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Content-addressed contracts with a hash-keyed verification cache for spec-driven agent loops, over MCP.
|
|
5
|
+
Project-URL: Homepage, https://github.com/davet47/heddle
|
|
6
|
+
Project-URL: Repository, https://github.com/davet47/heddle
|
|
7
|
+
Project-URL: Issues, https://github.com/davet47/heddle/issues
|
|
8
|
+
Author: Dave T
|
|
9
|
+
License: Apache-2.0
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: agents,caching,contracts,mcp,spec-driven
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
22
|
+
Requires-Python: >=3.10
|
|
23
|
+
Requires-Dist: mcp>=1.0
|
|
24
|
+
Requires-Dist: pytest>=8.0
|
|
25
|
+
Requires-Dist: pyyaml>=6.0
|
|
26
|
+
Requires-Dist: tiktoken>=0.7
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
|
|
29
|
+
# heddle
|
|
30
|
+
|
|
31
|
+
[](https://github.com/davet47/heddle/actions/workflows/ci.yml)
|
|
32
|
+
|
|
33
|
+
**Heddle treats software units as content-addressed contracts rather than files.** An MCP server that makes agent regeneration loops cheap.
|
|
34
|
+
|
|
35
|
+
Because contracts are content-addressed and dependency-aware, agents reuse verification, compute blast radius precisely, and regenerate code from a few hundred tokens of context instead of re-reading whole files. Build systems ask which files changed. Heddle asks which software obligations changed.
|
|
36
|
+
|
|
37
|
+
The heddle is the part of a loom that holds the warp threads, the fixed, durable strands, while the shuttle weaves disposable weft through them. **Contracts are warp. Code is weft.**
|
|
38
|
+
|
|
39
|
+
## The problem
|
|
40
|
+
|
|
41
|
+
Agents repeatedly pay to rediscover software structure. Spec-driven development tools made specs the durable artifact and code regenerable, but they run on plain files, so every regeneration loop re-derives what the project already knows:
|
|
42
|
+
|
|
43
|
+
1. **Context acquisition is expensive.** Regenerating one unit means re-reading whole spec and source files: thousands of tokens to learn what a few hundred convey.
|
|
44
|
+
2. **Verification is uncached.** Every regeneration re-runs (and re-reads the output of) the full relevant test surface, even for units whose contracts haven't changed.
|
|
45
|
+
3. **Blast radius is by convention, not mechanism.** When a spec changes, nothing tells the agent precisely which dependents are invalidated.
|
|
46
|
+
|
|
47
|
+
## The model
|
|
48
|
+
|
|
49
|
+
Heddle treats each software unit as a content-addressed contract with explicit dependencies, not a file. A contract is a small YAML spec (signature, invariants, examples, dependency names); the implementation behind it is regenerable weft. Because every contract is hashed and its dependencies are named, the structure an agent keeps re-deriving from files becomes something heddle computes once and serves.
|
|
50
|
+
|
|
51
|
+
## Outcomes
|
|
52
|
+
|
|
53
|
+
The model buys three things, all mechanical:
|
|
54
|
+
|
|
55
|
+
- **Verification caching.** A green test result is keyed on the contract, implementation, and dependency hashes, and served from cache until one of them changes. pytest runs only on a real miss.
|
|
56
|
+
- **Mechanical blast radius.** A contract change reports the exact set of invalidated dependents, transitively and by hash, not by convention.
|
|
57
|
+
- **Tiny context packets.** An agent regenerating a unit gets the contract, its dependencies' signatures, and its callers as one packet of a few hundred tokens, instead of the whole file closure.
|
|
58
|
+
|
|
59
|
+
### The number
|
|
60
|
+
|
|
61
|
+
Same three regeneration tasks on a 20-contract sample project, once with raw file reads, once through heddle (tiktoken cl100k, reproduce with `uv run python bench/benchmark.py`):
|
|
62
|
+
|
|
63
|
+
| task | raw files | heddle | reduction |
|
|
64
|
+
|---------------------|----------:|-------:|----------:|
|
|
65
|
+
| revenue_by_region | 1,925 | 371 | 5.2x |
|
|
66
|
+
| top_customers | 2,137 | 334 | 6.4x |
|
|
67
|
+
| revenue_by_category | 1,942 | 392 | 5.0x |
|
|
68
|
+
| **total** | **6,004** | **1,097** | **5.5x** |
|
|
69
|
+
|
|
70
|
+
Raw mode counts what a file-based agent reads per task: the unit's spec file, every transitive dep's spec file, every source module in the dep closure, the unit's test file, and the output of running the suite. It is deliberately generous to the baseline: it assumes the agent already knows the exact dependency closure, which is precisely the thing heddle computes for you.
|
|
71
|
+
|
|
72
|
+
## Quickstart
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
pip install heddle-mcp
|
|
76
|
+
# or from source: pip install "git+https://github.com/davet47/heddle"
|
|
77
|
+
|
|
78
|
+
cd your-project
|
|
79
|
+
heddle init # creates .heddle/ and contracts/
|
|
80
|
+
heddle index # builds the store from contracts/
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Point Claude Code at it:
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
claude mcp add heddle -- heddle serve
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
(Stdio transport; the server resolves the project by walking up from its working directory to the nearest `.heddle/`.)
|
|
90
|
+
|
|
91
|
+
## Contracts
|
|
92
|
+
|
|
93
|
+
One YAML file per unit in `contracts/`. Minimal, hand-writable, hashable:
|
|
94
|
+
|
|
95
|
+
```yaml
|
|
96
|
+
name: revenue_by_region
|
|
97
|
+
signature: "(sales: list[Sale]) -> dict[Region, float]"
|
|
98
|
+
deps: [Sale, Region] # other contract names
|
|
99
|
+
invariants:
|
|
100
|
+
- excludes sales where completed is false
|
|
101
|
+
- excludes sales with null amount
|
|
102
|
+
examples:
|
|
103
|
+
- in: "[Sale(region='QLD', amount=10, completed=True)]"
|
|
104
|
+
out: "{'QLD': 10.0}"
|
|
105
|
+
tests: [tests/test_revenue.py::test_revenue_by_region] # pytest node IDs
|
|
106
|
+
impl: src/revenue.py::revenue_by_region # current woven weft
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Subdirectories are namespaces: `contracts/billing/invoice.yaml` is the contract
|
|
110
|
+
`billing/invoice`, so the same short name can live in different folders. A
|
|
111
|
+
contract's `name` must match its path under `contracts/`.
|
|
112
|
+
|
|
113
|
+
### When to write a contract
|
|
114
|
+
|
|
115
|
+
A contract belongs on a stable seam: an interface other units depend on and that you expect to outlive its current implementation. The implementation behind it is disposable weft, regenerated freely. Dropping a contract where it does not earn that place is correct use, not a failure. The failure mode is the opposite, over-pinning interiors you would happily rewrite, which turns the durable layer into busywork.
|
|
116
|
+
|
|
117
|
+
Contracts are reviewed artifacts. Authoring one is cheap and getting cheaper, so the real cost is reviewing it, not writing it. A wrong contract is worse than no contract, because the durable artifact now lies: agents will regenerate code to satisfy a spec that is itself incorrect. Review a contract the way you review an interface, not the way you skim generated code.
|
|
118
|
+
|
|
119
|
+
### Hashing semantics
|
|
120
|
+
|
|
121
|
+
- **Contract hash**: sha256 over a canonical form: keys sorted, whitespace normalised, comments stripped, invariant and example order preserved, dep order ignored. `impl` and `tests` are excluded, so **relocating files never invalidates.** Invariants are free text and live inside this hash, so rewording one without changing its meaning still moves the contract hash and re-verifies every dependent. Behaviour-equivalent prose edits are not free yet (see [Roadmap](https://github.com/davet47/heddle/blob/main/ROADMAP.md)).
|
|
122
|
+
- **Impl hash**: sha256 over the normalised AST of the implementation, so reformatting and comment edits never bust the cache. Docstrings are stripped too.
|
|
123
|
+
- **Verification key**: `(contract hash, impl hash, transitive dep contract hashes)`. Heddle caches verification results, not correctness: a cached green result is served iff the full key matches, and an edit to any contract in the closure forces a re-run. Failures are never served from cache. Two caveats are worth knowing. A cached pass assumes deterministic tests, so a green result that depended on wall-clock time, network, or randomness can outlive the condition that made it pass. And test source is not yet part of the key, so editing a test body without touching the contract or impl does not by itself force a re-run (see [Roadmap](ROADMAP.md)).
|
|
124
|
+
|
|
125
|
+
## MCP tools (the entire surface)
|
|
126
|
+
|
|
127
|
+
| tool | does |
|
|
128
|
+
|---|---|
|
|
129
|
+
| `get_contract` | the ~300-token context packet: contract + hash + one-line dep signatures + caller list |
|
|
130
|
+
| `put_contract` | validate, write `contracts/<name>.yaml`, return new hash + every invalidated dependent |
|
|
131
|
+
| `get_dependents` | blast-radius query, direct or transitive, names + hashes |
|
|
132
|
+
| `verify` | per-unit `cached-pass` / `pass` / `fail`; runs pytest only on cache misses; failures come back as a ≤40-token assertion summary, never a traceback |
|
|
133
|
+
| `status` | dirty contracts, stale verifications, cache hit-rate, resolved verify interpreter, cumulative token counters |
|
|
134
|
+
|
|
135
|
+
Every tool returns structured errors — `{"error": {"code": "unknown_dep", "message": "'Regoin' not found — nearest: 'Region'"}}` — never a stack trace.
|
|
136
|
+
|
|
137
|
+
### The verify interpreter
|
|
138
|
+
|
|
139
|
+
`verify` runs your tests with the project's own python, resolved in order:
|
|
140
|
+
`heddle serve --python PATH` → `.heddle/config.json` (`{"python": "..."}`) → an
|
|
141
|
+
auto-detected `<project>/.venv` → the interpreter running heddle. So a
|
|
142
|
+
globally-installed heddle can verify a project against its own virtualenv without
|
|
143
|
+
being installed into it; `heddle status` shows which interpreter it resolved.
|
|
144
|
+
|
|
145
|
+
`.heddle/config.json` also takes `verify_timeout` (seconds per pytest run,
|
|
146
|
+
default 300) for suites that need longer than the default, and `pycache_trust`
|
|
147
|
+
(default `true`); set `pycache_trust: false` — or pass `--no-pycache-trust` — to
|
|
148
|
+
clear the project's `__pycache__` before each verify run, so a stale `.pyc` can
|
|
149
|
+
never shadow the current source.
|
|
150
|
+
|
|
151
|
+
## CLI
|
|
152
|
+
|
|
153
|
+
`heddle init` · `heddle index` · `heddle serve` · `heddle status` · `heddle verify`. The sqlite store under `.heddle/` is derived state: delete it any time and `heddle index` rebuilds it from `contracts/`.
|
|
154
|
+
|
|
155
|
+
`heddle verify <name>…` runs the same cached verification as the MCP tool from the command line and exits nonzero if any unit fails — drop it in CI or a pre-commit hook.
|
|
156
|
+
|
|
157
|
+
## Try the sample project
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
cd examples/sales
|
|
161
|
+
heddle init && heddle index && heddle serve # then point your agent at it
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
20 contracts, 25 tests, three dependency layers deep.
|
|
165
|
+
|
|
166
|
+
## Development
|
|
167
|
+
|
|
168
|
+
```bash
|
|
169
|
+
uv sync
|
|
170
|
+
uv run pytest # full suite; hash stability is the load-bearing suite
|
|
171
|
+
uv run python bench/benchmark.py
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
Python-only and single-process by design for v0.1. Everything not in this README is an [issue](ISSUES.md).
|
|
175
|
+
|
|
176
|
+
## License
|
|
177
|
+
|
|
178
|
+
Apache 2.0
|