harnessweaver-cli 0.7.1__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.
- harnessweaver_cli-0.7.1/.gitignore +40 -0
- harnessweaver_cli-0.7.1/CHANGELOG.md +82 -0
- harnessweaver_cli-0.7.1/LICENSE +202 -0
- harnessweaver_cli-0.7.1/PKG-INFO +83 -0
- harnessweaver_cli-0.7.1/README.md +60 -0
- harnessweaver_cli-0.7.1/pyproject.toml +35 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/__init__.py +7 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/_load.py +119 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/_yaml.py +49 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/add.py +238 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/dev.py +141 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/doctor.py +185 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/evals.py +276 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/gateway.py +301 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/main.py +62 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/plugins.py +105 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/policy.py +143 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/py.typed +0 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/replay.py +75 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/scaffold.py +158 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/sidecar.py +48 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/spec.py +160 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/templates/_dev/compose.yaml +183 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/templates/_dev/otel-collector.yaml +25 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/templates/_plugin/README.md +26 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/templates/_plugin/pyproject.toml +26 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/templates/_plugin/src/__ns___harness/__init__.py +20 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/templates/_plugin/src/__ns___harness/guards.py +48 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/templates/_plugin/src/__ns___harness/py.typed +0 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/templates/_plugin/tests/test_guards.py +26 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/templates/agent/README.md +18 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/templates/agent/app/__init__.py +1 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/templates/agent/app/agent.py +12 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/templates/agent/app/main.py +19 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/templates/agent/app/tools.py +28 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/templates/agent/evals/redteam.yaml +17 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/templates/agent/harness.offline.yaml +16 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/templates/agent/harness.yaml +38 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/templates/agent/pyproject.toml +13 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/templates/agent/tests/test_agent.py +54 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/templates/agent/tools/lookup_order.tool.yaml +15 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/templates/agent/tools/refund_payment.tool.yaml +17 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/templates/chat/README.md +15 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/templates/chat/app/__init__.py +1 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/templates/chat/app/chat.py +32 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/templates/chat/app/main.py +33 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/templates/chat/evals/golden.yaml +10 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/templates/chat/harness.offline.yaml +12 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/templates/chat/harness.yaml +39 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/templates/chat/pyproject.toml +13 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/templates/chat/tests/test_chat.py +63 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/templates/extraction/README.md +16 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/templates/extraction/app/__init__.py +1 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/templates/extraction/app/main.py +21 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/templates/extraction/app/models.py +20 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/templates/extraction/evals/golden.yaml +12 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/templates/extraction/harness.offline.yaml +18 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/templates/extraction/harness.yaml +33 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/templates/extraction/prompts/extract@1.md +7 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/templates/extraction/pyproject.toml +13 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/templates/extraction/tests/test_extract.py +56 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/templates/rag/README.md +17 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/templates/rag/app/__init__.py +1 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/templates/rag/app/flow.py +29 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/templates/rag/app/main.py +19 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/templates/rag/data/kb.yaml +13 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/templates/rag/evals/golden.yaml +14 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/templates/rag/harness.offline.yaml +13 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/templates/rag/harness.yaml +50 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/templates/rag/prompts/answer@1.md +9 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/templates/rag/pyproject.toml +13 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/templates/rag/tests/test_answer.py +50 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/templates/workflow/README.md +16 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/templates/workflow/app/__init__.py +1 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/templates/workflow/app/main.py +20 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/templates/workflow/app/steps.py +49 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/templates/workflow/evals/golden.yaml +9 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/templates/workflow/harness.offline.yaml +12 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/templates/workflow/harness.yaml +39 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/templates/workflow/prompts/classify@1.md +4 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/templates/workflow/prompts/reply@1.md +5 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/templates/workflow/prompts/summarize@1.md +3 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/templates/workflow/pyproject.toml +13 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/templates/workflow/tests/test_pipeline.py +32 -0
- harnessweaver_cli-0.7.1/src/harnessweaver_cli/tools.py +72 -0
- harnessweaver_cli-0.7.1/tests/conftest.py +23 -0
- harnessweaver_cli-0.7.1/tests/test_add_and_tools.py +150 -0
- harnessweaver_cli-0.7.1/tests/test_cli.py +50 -0
- harnessweaver_cli-0.7.1/tests/test_dev.py +116 -0
- harnessweaver_cli-0.7.1/tests/test_doctor.py +96 -0
- harnessweaver_cli-0.7.1/tests/test_evals.py +111 -0
- harnessweaver_cli-0.7.1/tests/test_gateway.py +161 -0
- harnessweaver_cli-0.7.1/tests/test_init.py +139 -0
- harnessweaver_cli-0.7.1/tests/test_plugins.py +92 -0
- harnessweaver_cli-0.7.1/tests/test_policy_and_replay.py +176 -0
- harnessweaver_cli-0.7.1/tests/test_spec.py +242 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*.egg-info/
|
|
5
|
+
.venv/
|
|
6
|
+
build/
|
|
7
|
+
dist/
|
|
8
|
+
.pytest_cache/
|
|
9
|
+
.ruff_cache/
|
|
10
|
+
.pyright/
|
|
11
|
+
.hypothesis/
|
|
12
|
+
.coverage
|
|
13
|
+
.coverage.*
|
|
14
|
+
htmlcov/
|
|
15
|
+
|
|
16
|
+
# TypeScript
|
|
17
|
+
node_modules/
|
|
18
|
+
typescript/**/dist/
|
|
19
|
+
*.tsbuildinfo
|
|
20
|
+
|
|
21
|
+
# Docs site
|
|
22
|
+
site/
|
|
23
|
+
|
|
24
|
+
# HarnessWeaver local run state (baselines under .harness/baselines are committed per example)
|
|
25
|
+
.harness/state.db
|
|
26
|
+
.harness/dev/
|
|
27
|
+
*.db-journal
|
|
28
|
+
|
|
29
|
+
# Editors and OS
|
|
30
|
+
.DS_Store
|
|
31
|
+
.idea/
|
|
32
|
+
.vscode/
|
|
33
|
+
|
|
34
|
+
# Claude Code local files
|
|
35
|
+
.claude/
|
|
36
|
+
|
|
37
|
+
# Secrets
|
|
38
|
+
.env
|
|
39
|
+
.env.*
|
|
40
|
+
!.env.example
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# Changelog: harnessweaver-cli
|
|
2
|
+
|
|
3
|
+
All notable changes to the `harnessweaver` command and its project templates. The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this package uses [Semantic Versioning](https://semver.org/) on its own (RULES V1). Versions before 0.7.1 were never published; their Git tags (`harnessweaver-cli@<version>`) mark the commit where each one landed.
|
|
4
|
+
|
|
5
|
+
## [Unreleased]
|
|
6
|
+
|
|
7
|
+
## 0.7.1 - 2026-11-01
|
|
8
|
+
|
|
9
|
+
The first version published to PyPI.
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- The package ships the Apache-2.0 `LICENSE` in its wheel and sdist.
|
|
14
|
+
|
|
15
|
+
## 0.7.0 - 2026-11-01
|
|
16
|
+
|
|
17
|
+
### Added
|
|
18
|
+
|
|
19
|
+
- `harnessweaver sidecar --max-body-bytes`: the largest request body harnessd reads, 10 MiB by default.
|
|
20
|
+
|
|
21
|
+
## 0.6.2 - 2026-11-01
|
|
22
|
+
|
|
23
|
+
### Security
|
|
24
|
+
|
|
25
|
+
- `spec diff git:<ref>:<path>` read profiles from the working tree, so a pull request that weakened only a profile showed no difference. A `git:` side is now loaded from that ref's own tree, the ref can't be read as a git option, and the diff lists profile layers added and removed.
|
|
26
|
+
|
|
27
|
+
## 0.6.1 - 2026-10-25
|
|
28
|
+
|
|
29
|
+
### Fixed
|
|
30
|
+
|
|
31
|
+
- The `chat` template's terminal app ends the chat at the end of input (Ctrl-D, or piped input running out) instead of raising `EOFError`.
|
|
32
|
+
|
|
33
|
+
## 0.6.0 - 2026-10-20
|
|
34
|
+
|
|
35
|
+
### Added
|
|
36
|
+
|
|
37
|
+
- `harnessweaver gateway litellm` writes a LiteLLM Proxy config from the spec (gateway models, aliases, retries, a timeout from the longest deadline, message logging off, the `otel` callback, and a tool-permission guardrail that allows only tools whose manifests need no run), and `harnessweaver gateway mcp` writes the neutral `tool-allow-list` for an MCP gateway: each allowed tool's server, digest and scopes, and every withheld tool with its reason (ADR-0039).
|
|
38
|
+
- `harnessweaver dev [--up]` writes a local Compose stack into `.harness/dev/` (LiteLLM, an OpenTelemetry collector, Langfuse and harnessd, digest-pinned and on 127.0.0.1 only) with local secrets generated once into `.env`, and starts it.
|
|
39
|
+
|
|
40
|
+
## 0.5.0 - 2026-10-20
|
|
41
|
+
|
|
42
|
+
### Added
|
|
43
|
+
|
|
44
|
+
- `harnessweaver sidecar [SPEC]` runs harnessd.
|
|
45
|
+
|
|
46
|
+
## 0.4.0 - 2026-10-20
|
|
47
|
+
|
|
48
|
+
### Added
|
|
49
|
+
|
|
50
|
+
- `harnessweaver add guard` adds a guard in shadow mode (`mode: log_only`, R8), and `harnessweaver add tool` writes a tool manifest from a function's signature and Google-style docstring and adds its directory to `tools.manifests`. Both edit `harness.yaml` with its comments kept (ruamel.yaml, ADR-0016), and a guard whose edit doesn't load is taken back out.
|
|
51
|
+
- `harnessweaver tools pin` writes each manifest's `definition_digest` (S2); `--tool` pins one.
|
|
52
|
+
- `harnessweaver plugin new <namespace>` scaffolds a standalone plugin package (entry point, `hw.Plugin`, a sample `<namespace>.banned_words` guard, and tests whose `pytest` run includes the conformance suite), and `harnessweaver plugin list` shows installed plugins with their versions, contract ranges and compatibility.
|
|
53
|
+
- Project templates `rag`, `agent` (a Pydantic AI agent with governed tools and a red-team eval set), `workflow` and `chat`, each passing its own tests offline (T6).
|
|
54
|
+
|
|
55
|
+
### Changed
|
|
56
|
+
|
|
57
|
+
- `harnessweaver init` refuses template names starting with `_`, which are scaffolds for other commands.
|
|
58
|
+
|
|
59
|
+
## 0.3.0 - 2026-10-20
|
|
60
|
+
|
|
61
|
+
### Added
|
|
62
|
+
|
|
63
|
+
- `harnessweaver eval run` (baselines in `.harness/baselines/<task>.<suite>.json`, `--update-baseline`, the shadow-guard report; exit 1 on a missed threshold or a regression, 2 when the suites can't run) and `harnessweaver eval report` (online samples).
|
|
64
|
+
- `harnessweaver policy test` checks a table of calls against `Harness.authorize` (`policy_tests.yaml`; exit 1 on a mismatch, 2 when the tests can't run).
|
|
65
|
+
- `harnessweaver replay <run_id>` runs a recorded run again against the current code and spec (exit 1 when the status or output changed).
|
|
66
|
+
|
|
67
|
+
### Changed
|
|
68
|
+
|
|
69
|
+
- The extraction template's offline overlay answers every golden case, so `harnessweaver eval run -e offline` passes on it, and it tests its golden set.
|
|
70
|
+
|
|
71
|
+
## 0.2.0 - 2026-10-19
|
|
72
|
+
|
|
73
|
+
### Added
|
|
74
|
+
|
|
75
|
+
- `harnessweaver doctor` warns about tool manifests without a pinned digest (printing the digest to pin) and fails ones that changed since they were pinned.
|
|
76
|
+
|
|
77
|
+
## 0.1.0 - 2026-10-18
|
|
78
|
+
|
|
79
|
+
### Added
|
|
80
|
+
|
|
81
|
+
- The `harnessweaver` command with `init` (built-in and plugin templates), `spec validate`, `spec explain`, `spec diff` (either side can be `git:<ref>:<path>`), `doctor` (level and next steps, reachable hooks, duplicate retry owners, unpinned profiles, shadow guards, content capture), `hooks`, `test` (offline, test mode on) and `contracts export`.
|
|
82
|
+
- The `extraction` project template, whose output passes its own tests (T6).
|
|
@@ -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 2026 Muthu Kumaran R
|
|
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,83 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: harnessweaver-cli
|
|
3
|
+
Version: 0.7.1
|
|
4
|
+
Summary: Developer tooling for HarnessWeaver: the harnessweaver command.
|
|
5
|
+
Author-email: Muthu Kumaran R <rsmk7new@gmail.com>
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Keywords: agents,ai,governance,guardrails,harness,llm,observability
|
|
9
|
+
Classifier: Development Status :: 2 - Pre-Alpha
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
15
|
+
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
|
|
16
|
+
Classifier: Typing :: Typed
|
|
17
|
+
Requires-Python: >=3.12
|
|
18
|
+
Requires-Dist: harnessweaver>=0.1.0
|
|
19
|
+
Requires-Dist: rich>=15
|
|
20
|
+
Requires-Dist: ruamel-yaml>=0.18
|
|
21
|
+
Requires-Dist: typer>=0.27
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
|
|
24
|
+
# harnessweaver-cli
|
|
25
|
+
|
|
26
|
+
Developer tooling for [HarnessWeaver](../../README.md). Installs the `harnessweaver` command. The full reference, with every option and exit code, is [docs/cli.md](../../docs/cli.md).
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
uv add --dev harnessweaver-cli
|
|
30
|
+
harnessweaver --help
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Start a project
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
harnessweaver init invoice-bot # the extraction template; -t picks another
|
|
37
|
+
cd invoice-bot
|
|
38
|
+
harnessweaver spec validate --env offline # load it the way the app will
|
|
39
|
+
harnessweaver test # its tests, offline
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
`init` copies a template and puts the project name in it; there is no template
|
|
43
|
+
language. A plugin's templates are named `<namespace>.<template>`
|
|
44
|
+
(`harnessweaver init -t acme.rag`). Every template's output passes its own tests
|
|
45
|
+
(RULES T6).
|
|
46
|
+
|
|
47
|
+
| Template | What you get |
|
|
48
|
+
| --- | --- |
|
|
49
|
+
| `extraction` (default) | Typed extraction with schema validation, one repair, PII and secrets guards, a golden set |
|
|
50
|
+
| `rag` | A session flow that routes the question, retrieves ACL-checked passages and answers with citations the output guard checks |
|
|
51
|
+
| `agent` | A Pydantic AI agent with two governed tools, one of them approval-gated, a policy rule and a red-team eval set |
|
|
52
|
+
| `workflow` | A three-stage step graph: a parallel stage, then a reply in an evaluator-optimizer loop |
|
|
53
|
+
| `chat` | A chat turn with memory, a topic guard and a streamed answer moderated chunk by chunk |
|
|
54
|
+
|
|
55
|
+
## Commands
|
|
56
|
+
|
|
57
|
+
| Command | What it does |
|
|
58
|
+
| --- | --- |
|
|
59
|
+
| `init [DIR] [-t TEMPLATE] [--name NAME] [--force]` | Start a project: `harness.yaml`, an offline overlay, code, a prompt, evals and tests. Never overwrites without `--force` |
|
|
60
|
+
| `spec validate [SPEC] [-e ENV] [--format text\|json]` | Load the spec with every check the app runs: layers, locks, bounds, plugins, tasks, reachable hooks (R4). Prints the adoption level |
|
|
61
|
+
| `spec explain [SPEC] [--path PREFIX]` | Every effective value, the layer it came from, and its locks and bounds |
|
|
62
|
+
| `spec diff BEFORE AFTER [--exit-code]` | Compare two effective specs as Markdown, for PR comments. Either side can be `git:<ref>:<path>`, read with the profiles committed at that ref |
|
|
63
|
+
| `doctor [SPEC] [--strict]` | Adoption level and what the next level needs, hooks each task's runner reaches, duplicate retry owners (R5), unpinned profiles, shadow guards (R8), content capture (R9), plugin installation problems. Exits 1 on a failure, or on a warning with `--strict` |
|
|
64
|
+
| `hooks [SPEC] [--task TASK]` | The middleware on every hook point in the order it runs, with band, fail mode and timeout |
|
|
65
|
+
| `test [-e ENV] [PYTEST ARGS...]` | Run the app's tests with `HARNESSWEAVER_TEST_MODE=1` and the `offline` overlay |
|
|
66
|
+
| `contracts export [DIR] [--check]` | Write the JSON Schema of every contract, or report drift |
|
|
67
|
+
| `eval run [SPEC] [--suite NAME] [--task TASK] [--update-baseline]` | Run the spec's eval suites, compare with `.harness/baselines`, print the shadow-guard report. Exits 1 on a missed threshold or a regression, 2 when the suites can't run |
|
|
68
|
+
| `eval report [SPEC] [--task TASK]` | The production runs online evals sampled and graded |
|
|
69
|
+
| `policy test [SPEC] [--cases FILE]` | Check a table of tool calls (`policy_tests.yaml`) against the governor's verdicts, as a dry run |
|
|
70
|
+
| `replay RUN_ID [SPEC]` | Run a recorded run again against the current code and spec, and show what changed |
|
|
71
|
+
| `add guard USE [SPEC] [--stage S] [--id ID] [--action A] [--set KEY=VALUE]` | Add a guard in shadow mode (`mode: log_only`, R8). Comments in `harness.yaml` are kept; an edit that doesn't load is taken back |
|
|
72
|
+
| `add tool MODULE:FUNCTION [SPEC] [--dir tools] [--risk R] [--side-effect S]` | Write a tool manifest from the function's signature and docstring, and add its directory to `tools.manifests` |
|
|
73
|
+
| `tools pin [SPEC] [--tool NAME]` | Write each manifest's `definition_digest`, so a tool that changes unreviewed is blocked (S2) |
|
|
74
|
+
| `plugin new NAMESPACE [DIR]` | Scaffold a standalone plugin package with a sample guard and tests that run the conformance suite |
|
|
75
|
+
| `plugin list [--format text\|json]` | Installed plugins: namespace, distribution, version, contract range, compatibility |
|
|
76
|
+
| `sidecar [SPEC] [-e ENV] [--host H] [--port P] [--token-env VAR]` | Serve the spec to other languages: runs `harnessd` (needs `harnessweaver-sidecar` and a token, S6) |
|
|
77
|
+
| `gateway litellm [SPEC] [-o FILE]` | A LiteLLM Proxy config from the spec: gateway models and aliases, retries, a timeout, no message logging, and a tool-permission guardrail from the manifests |
|
|
78
|
+
| `gateway mcp [SPEC] [-o FILE]` | A neutral tool allow-list for an MCP gateway: each allowed tool's server, digest and scopes, and the withheld tools with the reason |
|
|
79
|
+
| `dev [SPEC] [-e ENV] [--up]` | Write `.harness/dev/`: LiteLLM, an OTel collector, Langfuse and harnessd in a Compose file, wired to the spec, with local secrets in `.env`. `--up` starts it |
|
|
80
|
+
|
|
81
|
+
Every command that takes `SPEC` defaults to `harness.yaml`, takes
|
|
82
|
+
`--profile-dir` to find `org://` profiles, and makes the spec's directory
|
|
83
|
+
importable, as it is when the app runs from there.
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# harnessweaver-cli
|
|
2
|
+
|
|
3
|
+
Developer tooling for [HarnessWeaver](../../README.md). Installs the `harnessweaver` command. The full reference, with every option and exit code, is [docs/cli.md](../../docs/cli.md).
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
uv add --dev harnessweaver-cli
|
|
7
|
+
harnessweaver --help
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
## Start a project
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
harnessweaver init invoice-bot # the extraction template; -t picks another
|
|
14
|
+
cd invoice-bot
|
|
15
|
+
harnessweaver spec validate --env offline # load it the way the app will
|
|
16
|
+
harnessweaver test # its tests, offline
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
`init` copies a template and puts the project name in it; there is no template
|
|
20
|
+
language. A plugin's templates are named `<namespace>.<template>`
|
|
21
|
+
(`harnessweaver init -t acme.rag`). Every template's output passes its own tests
|
|
22
|
+
(RULES T6).
|
|
23
|
+
|
|
24
|
+
| Template | What you get |
|
|
25
|
+
| --- | --- |
|
|
26
|
+
| `extraction` (default) | Typed extraction with schema validation, one repair, PII and secrets guards, a golden set |
|
|
27
|
+
| `rag` | A session flow that routes the question, retrieves ACL-checked passages and answers with citations the output guard checks |
|
|
28
|
+
| `agent` | A Pydantic AI agent with two governed tools, one of them approval-gated, a policy rule and a red-team eval set |
|
|
29
|
+
| `workflow` | A three-stage step graph: a parallel stage, then a reply in an evaluator-optimizer loop |
|
|
30
|
+
| `chat` | A chat turn with memory, a topic guard and a streamed answer moderated chunk by chunk |
|
|
31
|
+
|
|
32
|
+
## Commands
|
|
33
|
+
|
|
34
|
+
| Command | What it does |
|
|
35
|
+
| --- | --- |
|
|
36
|
+
| `init [DIR] [-t TEMPLATE] [--name NAME] [--force]` | Start a project: `harness.yaml`, an offline overlay, code, a prompt, evals and tests. Never overwrites without `--force` |
|
|
37
|
+
| `spec validate [SPEC] [-e ENV] [--format text\|json]` | Load the spec with every check the app runs: layers, locks, bounds, plugins, tasks, reachable hooks (R4). Prints the adoption level |
|
|
38
|
+
| `spec explain [SPEC] [--path PREFIX]` | Every effective value, the layer it came from, and its locks and bounds |
|
|
39
|
+
| `spec diff BEFORE AFTER [--exit-code]` | Compare two effective specs as Markdown, for PR comments. Either side can be `git:<ref>:<path>`, read with the profiles committed at that ref |
|
|
40
|
+
| `doctor [SPEC] [--strict]` | Adoption level and what the next level needs, hooks each task's runner reaches, duplicate retry owners (R5), unpinned profiles, shadow guards (R8), content capture (R9), plugin installation problems. Exits 1 on a failure, or on a warning with `--strict` |
|
|
41
|
+
| `hooks [SPEC] [--task TASK]` | The middleware on every hook point in the order it runs, with band, fail mode and timeout |
|
|
42
|
+
| `test [-e ENV] [PYTEST ARGS...]` | Run the app's tests with `HARNESSWEAVER_TEST_MODE=1` and the `offline` overlay |
|
|
43
|
+
| `contracts export [DIR] [--check]` | Write the JSON Schema of every contract, or report drift |
|
|
44
|
+
| `eval run [SPEC] [--suite NAME] [--task TASK] [--update-baseline]` | Run the spec's eval suites, compare with `.harness/baselines`, print the shadow-guard report. Exits 1 on a missed threshold or a regression, 2 when the suites can't run |
|
|
45
|
+
| `eval report [SPEC] [--task TASK]` | The production runs online evals sampled and graded |
|
|
46
|
+
| `policy test [SPEC] [--cases FILE]` | Check a table of tool calls (`policy_tests.yaml`) against the governor's verdicts, as a dry run |
|
|
47
|
+
| `replay RUN_ID [SPEC]` | Run a recorded run again against the current code and spec, and show what changed |
|
|
48
|
+
| `add guard USE [SPEC] [--stage S] [--id ID] [--action A] [--set KEY=VALUE]` | Add a guard in shadow mode (`mode: log_only`, R8). Comments in `harness.yaml` are kept; an edit that doesn't load is taken back |
|
|
49
|
+
| `add tool MODULE:FUNCTION [SPEC] [--dir tools] [--risk R] [--side-effect S]` | Write a tool manifest from the function's signature and docstring, and add its directory to `tools.manifests` |
|
|
50
|
+
| `tools pin [SPEC] [--tool NAME]` | Write each manifest's `definition_digest`, so a tool that changes unreviewed is blocked (S2) |
|
|
51
|
+
| `plugin new NAMESPACE [DIR]` | Scaffold a standalone plugin package with a sample guard and tests that run the conformance suite |
|
|
52
|
+
| `plugin list [--format text\|json]` | Installed plugins: namespace, distribution, version, contract range, compatibility |
|
|
53
|
+
| `sidecar [SPEC] [-e ENV] [--host H] [--port P] [--token-env VAR]` | Serve the spec to other languages: runs `harnessd` (needs `harnessweaver-sidecar` and a token, S6) |
|
|
54
|
+
| `gateway litellm [SPEC] [-o FILE]` | A LiteLLM Proxy config from the spec: gateway models and aliases, retries, a timeout, no message logging, and a tool-permission guardrail from the manifests |
|
|
55
|
+
| `gateway mcp [SPEC] [-o FILE]` | A neutral tool allow-list for an MCP gateway: each allowed tool's server, digest and scopes, and the withheld tools with the reason |
|
|
56
|
+
| `dev [SPEC] [-e ENV] [--up]` | Write `.harness/dev/`: LiteLLM, an OTel collector, Langfuse and harnessd in a Compose file, wired to the spec, with local secrets in `.env`. `--up` starts it |
|
|
57
|
+
|
|
58
|
+
Every command that takes `SPEC` defaults to `harness.yaml`, takes
|
|
59
|
+
`--profile-dir` to find `org://` profiles, and makes the spec's directory
|
|
60
|
+
importable, as it is when the app runs from there.
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.32"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "harnessweaver-cli"
|
|
7
|
+
version = "0.7.1"
|
|
8
|
+
description = "Developer tooling for HarnessWeaver: the harnessweaver command."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "Apache-2.0"
|
|
11
|
+
authors = [{ name = "Muthu Kumaran R", email = "rsmk7new@gmail.com" }]
|
|
12
|
+
requires-python = ">=3.12"
|
|
13
|
+
keywords = ["ai", "llm", "harness", "guardrails", "agents", "governance", "observability"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 2 - Pre-Alpha",
|
|
16
|
+
"Intended Audience :: Developers",
|
|
17
|
+
"Programming Language :: Python :: 3",
|
|
18
|
+
"Programming Language :: Python :: 3.12",
|
|
19
|
+
"Programming Language :: Python :: 3.13",
|
|
20
|
+
"Programming Language :: Python :: 3.14",
|
|
21
|
+
"Topic :: Software Development :: Libraries :: Application Frameworks",
|
|
22
|
+
"Typing :: Typed",
|
|
23
|
+
]
|
|
24
|
+
dependencies = [
|
|
25
|
+
"harnessweaver>=0.1.0",
|
|
26
|
+
"typer>=0.27",
|
|
27
|
+
"rich>=15",
|
|
28
|
+
"ruamel-yaml>=0.18",
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
[project.scripts]
|
|
32
|
+
harnessweaver = "harnessweaver_cli.main:app"
|
|
33
|
+
|
|
34
|
+
[tool.hatch.build.targets.wheel]
|
|
35
|
+
packages = ["src/harnessweaver_cli"]
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"""Finding and loading specs for the CLI, including ``git:<ref>:<path>`` sources."""
|
|
2
|
+
|
|
3
|
+
import io
|
|
4
|
+
import subprocess
|
|
5
|
+
import sys
|
|
6
|
+
import tarfile
|
|
7
|
+
import tempfile
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
import typer
|
|
11
|
+
|
|
12
|
+
from harnessweaver import Harness
|
|
13
|
+
from harnessweaver.core.errors import HarnessError, SpecError
|
|
14
|
+
from harnessweaver.core.ports import StateStore
|
|
15
|
+
from harnessweaver.spec import EffectiveSpec, load_spec
|
|
16
|
+
|
|
17
|
+
__all__ = ["fail", "load_effective", "load_harness", "spec_path"]
|
|
18
|
+
|
|
19
|
+
DEFAULT_SPEC = Path("harness.yaml")
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def fail(error: HarnessError | str, code: int = 1) -> typer.Exit:
|
|
23
|
+
"""Print an error the way every command does and return the exit to raise.
|
|
24
|
+
|
|
25
|
+
Commands that report checks (``eval run``, ``policy test``, ``replay``) exit 1
|
|
26
|
+
when a check fails and 2 when they can't run, so CI can tell the two apart.
|
|
27
|
+
"""
|
|
28
|
+
message = error.message if isinstance(error, HarnessError) else error
|
|
29
|
+
typer.echo(f"error: {message}", err=True)
|
|
30
|
+
return typer.Exit(code=code)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def spec_path(path: Path | None, code: int = 1) -> Path:
|
|
34
|
+
"""The spec to load. Its directory becomes importable, as when the app runs from
|
|
35
|
+
there, so ``tasks.*.input`` and handler paths resolve."""
|
|
36
|
+
found = path or DEFAULT_SPEC
|
|
37
|
+
if not found.is_file():
|
|
38
|
+
raise fail(f"no spec at {found}; pass the path to harness.yaml", code)
|
|
39
|
+
directory = str(found.resolve().parent)
|
|
40
|
+
if directory not in sys.path:
|
|
41
|
+
sys.path.insert(0, directory)
|
|
42
|
+
return found
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def load_harness(
|
|
46
|
+
path: Path | None,
|
|
47
|
+
env: str | None,
|
|
48
|
+
profile_dirs: list[Path],
|
|
49
|
+
*,
|
|
50
|
+
state: StateStore | None = None,
|
|
51
|
+
code: int = 1,
|
|
52
|
+
) -> Harness:
|
|
53
|
+
"""Load and build the harness, the same way an app does (every check runs).
|
|
54
|
+
``state`` replaces the spec's state store (evals keep their runs in memory)."""
|
|
55
|
+
try:
|
|
56
|
+
effective = load_spec(spec_path(path, code), env=env, profile_dirs=profile_dirs)
|
|
57
|
+
return Harness.from_spec(effective, state=state)
|
|
58
|
+
except HarnessError as exc:
|
|
59
|
+
raise fail(exc, code) from None
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def _git(*args: str) -> bytes | None:
|
|
63
|
+
"""Run git and return its output, or ``None`` if it fails or isn't installed."""
|
|
64
|
+
try:
|
|
65
|
+
done = subprocess.run(["git", *args], capture_output=True, check=False)
|
|
66
|
+
except OSError:
|
|
67
|
+
return None
|
|
68
|
+
return done.stdout if done.returncode == 0 else None
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def _load_from_git(ref: str, raw_path: str, env: str | None, dirs: list[Path]) -> EffectiveSpec:
|
|
72
|
+
"""Load a spec as it stands at ``ref``, with the profiles that were committed with it.
|
|
73
|
+
|
|
74
|
+
The whole tree at the ref is extracted, so ``.harness/profiles`` and file references come
|
|
75
|
+
from the ref and not the working tree: otherwise a pull request that weakens only a
|
|
76
|
+
profile would show no difference. A ``--profile-dir`` inside the repository is read from
|
|
77
|
+
the ref too. One outside it, like ``HARNESSWEAVER_PROFILE_PATH``, isn't in git, so both
|
|
78
|
+
sides of a diff see the same files.
|
|
79
|
+
|
|
80
|
+
Raises:
|
|
81
|
+
SpecError: If the ref or the path can't be read.
|
|
82
|
+
"""
|
|
83
|
+
missing = SpecError(f"can't read {raw_path} at {ref} from git")
|
|
84
|
+
# --end-of-options keeps a ref from being read as an option of git's.
|
|
85
|
+
commit = _git("rev-parse", "--verify", "--quiet", "--end-of-options", f"{ref}^{{commit}}")
|
|
86
|
+
top = _git("rev-parse", "--show-toplevel")
|
|
87
|
+
if commit is None or top is None:
|
|
88
|
+
raise missing
|
|
89
|
+
root = Path(top.decode().strip()).resolve()
|
|
90
|
+
archive = _git("-C", str(root), "archive", "--format=tar", commit.decode().strip())
|
|
91
|
+
if archive is None:
|
|
92
|
+
raise missing
|
|
93
|
+
|
|
94
|
+
def inside(tree: Path, path: Path) -> Path | None:
|
|
95
|
+
"""Where ``path`` is in the extracted tree, if it's in the repository at all."""
|
|
96
|
+
resolved = path.resolve()
|
|
97
|
+
return tree / resolved.relative_to(root) if resolved.is_relative_to(root) else None
|
|
98
|
+
|
|
99
|
+
with tempfile.TemporaryDirectory(prefix="harnessweaver-git-") as temporary:
|
|
100
|
+
tree = Path(temporary).resolve()
|
|
101
|
+
with tarfile.open(fileobj=io.BytesIO(archive)) as tar:
|
|
102
|
+
tar.extractall(tree, filter="data") # the data filter refuses paths out of the tree
|
|
103
|
+
path = inside(tree, Path(raw_path))
|
|
104
|
+
if path is None or not path.is_file():
|
|
105
|
+
raise missing
|
|
106
|
+
return load_spec(path, env=env, profile_dirs=[inside(tree, d) or d for d in dirs])
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def load_effective(source: str, env: str | None, profile_dirs: list[Path]) -> EffectiveSpec:
|
|
110
|
+
"""Load a spec from a file, or from git as ``git:<ref>:<path>`` (for ``spec diff`` in CI)."""
|
|
111
|
+
try:
|
|
112
|
+
if not source.startswith("git:"):
|
|
113
|
+
return load_spec(spec_path(Path(source)), env=env, profile_dirs=profile_dirs)
|
|
114
|
+
ref, _, raw_path = source.removeprefix("git:").partition(":")
|
|
115
|
+
if not ref or not raw_path:
|
|
116
|
+
raise SpecError(f"{source!r} must look like git:<ref>:<path>")
|
|
117
|
+
return _load_from_git(ref, raw_path, env, profile_dirs)
|
|
118
|
+
except HarnessError as exc:
|
|
119
|
+
raise fail(exc) from None
|