chp-core 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.
@@ -0,0 +1,12 @@
1
+ node_modules/
2
+ dist/
3
+ *.egg-info/
4
+ __pycache__/
5
+ .pytest_cache/
6
+ .chp/
7
+ .DS_Store
8
+ *.tgz
9
+ .env
10
+ .env.*
11
+ *.pyc
12
+ .python-version
@@ -0,0 +1,212 @@
1
+ Metadata-Version: 2.4
2
+ Name: chp-core
3
+ Version: 0.1.0
4
+ Summary: Capability Host Protocol — local execution evidence for agents, tools, and systems
5
+ Author: Auxo
6
+ License: Apache-2.0
7
+ Keywords: agents,capability-host-protocol,chp,evidence,governance,observability,replay
8
+ Classifier: Development Status :: 3 - Alpha
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: License :: OSI Approved :: Apache Software License
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.10
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Programming Language :: Python :: 3.13
16
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
17
+ Classifier: Topic :: System :: Logging
18
+ Classifier: Topic :: System :: Monitoring
19
+ Requires-Python: >=3.10
20
+ Provides-Extra: dev
21
+ Requires-Dist: jsonschema>=4.23; extra == 'dev'
22
+ Requires-Dist: pytest>=8.0; extra == 'dev'
23
+ Description-Content-Type: text/markdown
24
+
25
+ # chp-core
26
+
27
+ Reference local host for CHP v0.1.
28
+
29
+ This package is intentionally small:
30
+
31
+ - register capabilities
32
+ - discover declarations
33
+ - invoke through a governed envelope
34
+ - preserve or generate correlation IDs
35
+ - emit append-only SQLite evidence
36
+ - replay evidence by correlation ID
37
+ - optionally serve discovery, invocation, and replay over local HTTP
38
+
39
+ ## Install
40
+
41
+ ```bash
42
+ pip install chp-core
43
+ ```
44
+
45
+ From this repository:
46
+
47
+ ```bash
48
+ python -m pip install -e packages/python
49
+ ```
50
+
51
+ ## Quick Example
52
+
53
+ ```python
54
+ from chp_core import LocalCapabilityHost, capability
55
+
56
+ host = LocalCapabilityHost("example-host")
57
+
58
+ @capability(
59
+ id="math.add",
60
+ version="1.0.0",
61
+ description="Add two numbers.",
62
+ )
63
+ def add(a: int, b: int):
64
+ return {"sum": a + b}
65
+
66
+ host.register(add)
67
+
68
+ result = host.invoke(
69
+ "math.add",
70
+ {"a": 2, "b": 3},
71
+ correlation_id="demo-correlation",
72
+ )
73
+
74
+ events = host.replay("demo-correlation")
75
+ ```
76
+
77
+ Async handlers are supported. Use `await host.ainvoke(...)` when already inside
78
+ an event loop.
79
+
80
+ By default, invocation payloads are not copied into evidence. Handlers can emit
81
+ explicit redacted evidence through `ctx.emit(...)`.
82
+
83
+ Payloads emitted through `ctx.emit(...)` are redacted by default for common
84
+ sensitive keys such as `token`, `secret`, `password`, `authorization`, and
85
+ `api_key`.
86
+
87
+ ## Adapters
88
+
89
+ Group related capabilities into an adapter class using `BaseAdapter` and the
90
+ `@capability` decorator. All decorated methods are auto-discovered:
91
+
92
+ ```python
93
+ from chp_core import BaseAdapter, capability, LocalCapabilityHost, register_adapter
94
+
95
+ class MathAdapter(BaseAdapter):
96
+ adapter_id = "math"
97
+ adapter_name = "Math Capabilities"
98
+
99
+ @capability(id="math.add", version="1.0.0", description="Add two numbers.")
100
+ async def add(self, ctx, payload):
101
+ return {"sum": payload["a"] + payload["b"]}
102
+
103
+ @capability(id="math.mul", version="1.0.0", description="Multiply two numbers.")
104
+ async def multiply(self, ctx, payload):
105
+ return {"product": payload["a"] * payload["b"]}
106
+
107
+ host = LocalCapabilityHost()
108
+ register_adapter(host, MathAdapter())
109
+ ```
110
+
111
+ For standalone functions, use `SimpleAdapter`:
112
+
113
+ ```python
114
+ from chp_core import SimpleAdapter, capability, register_adapter
115
+
116
+ @capability(id="greet.hello", version="1.0.0", description="Greet someone.")
117
+ def hello(name: str):
118
+ return {"message": f"Hello, {name}!"}
119
+
120
+ register_adapter(host, SimpleAdapter("greet", [hello]))
121
+ ```
122
+
123
+ ### Shipping an adapter package
124
+
125
+ Publish your adapter as a standalone package (e.g. `chp-linear`) and declare
126
+ it under the `chp.adapters` entry-point group so hosts can discover it
127
+ automatically:
128
+
129
+ ```toml
130
+ # your_adapter/pyproject.toml
131
+ [project.entry-points."chp.adapters"]
132
+ linear = "chp_linear:LinearAdapter"
133
+ ```
134
+
135
+ Once installed, any host can load all registered adapters:
136
+
137
+ ```python
138
+ from chp_core import auto_register_adapters
139
+
140
+ host = LocalCapabilityHost()
141
+ auto_register_adapters(host) # loads every installed chp.adapters entry point
142
+ ```
143
+
144
+ Or discover them manually:
145
+
146
+ ```python
147
+ from chp_core import discover_adapters
148
+
149
+ for name, adapter_cls in discover_adapters().items():
150
+ print(name, adapter_cls)
151
+ ```
152
+
153
+ `chp-core` ships a built-in `chp-git` adapter that exposes Git version-control
154
+ governance capabilities. It is registered automatically when the package is
155
+ installed.
156
+
157
+ ## HTTP Endpoint
158
+
159
+ The HTTP helper is transport glue around the same `LocalCapabilityHost`:
160
+
161
+ ```python
162
+ from chp_core import create_http_server
163
+
164
+ server = create_http_server(host, port=8765)
165
+ server.serve_forever()
166
+ ```
167
+
168
+ Routes:
169
+
170
+ - `GET /host`
171
+ - `GET /capabilities`
172
+ - `POST /invoke`
173
+ - `POST /replay`
174
+ - `GET /replay/{correlation_id}`
175
+
176
+ See `examples/capability-host-endpoint-demo/`.
177
+
178
+ The package also installs a small CLI:
179
+
180
+ ```bash
181
+ chp demo endpoint
182
+ chp serve-demo --port 8765
183
+ chp host
184
+ chp invoke demo.search_information --payload '{"query":"CHP vs MCP"}' --correlation-id corr_demo
185
+ chp replay corr_demo
186
+ ```
187
+
188
+ ## Development Evidence Controls
189
+
190
+ Use `chp work` to record local engineering work as CHP evidence:
191
+
192
+ ```bash
193
+ chp work run \
194
+ --intent "Verify the Python test suite." \
195
+ --correlation-id chp-dev-001 \
196
+ --test-run unit \
197
+ -- python -m unittest discover -s packages/python/tests
198
+
199
+ chp work summary chp-dev-001
200
+ chp work replay chp-dev-001
201
+ chp work explain chp-dev-001
202
+ chp work validate-demo endpoint --correlation-id chp-demo-validation
203
+ chp work check-alignment --correlation-id chp-alignment
204
+ chp work check-messaging --correlation-id chp-messaging
205
+ ```
206
+
207
+ ## Tests
208
+
209
+ ```bash
210
+ cd packages/python
211
+ python -m unittest discover -s tests
212
+ ```
@@ -0,0 +1,188 @@
1
+ # chp-core
2
+
3
+ Reference local host for CHP v0.1.
4
+
5
+ This package is intentionally small:
6
+
7
+ - register capabilities
8
+ - discover declarations
9
+ - invoke through a governed envelope
10
+ - preserve or generate correlation IDs
11
+ - emit append-only SQLite evidence
12
+ - replay evidence by correlation ID
13
+ - optionally serve discovery, invocation, and replay over local HTTP
14
+
15
+ ## Install
16
+
17
+ ```bash
18
+ pip install chp-core
19
+ ```
20
+
21
+ From this repository:
22
+
23
+ ```bash
24
+ python -m pip install -e packages/python
25
+ ```
26
+
27
+ ## Quick Example
28
+
29
+ ```python
30
+ from chp_core import LocalCapabilityHost, capability
31
+
32
+ host = LocalCapabilityHost("example-host")
33
+
34
+ @capability(
35
+ id="math.add",
36
+ version="1.0.0",
37
+ description="Add two numbers.",
38
+ )
39
+ def add(a: int, b: int):
40
+ return {"sum": a + b}
41
+
42
+ host.register(add)
43
+
44
+ result = host.invoke(
45
+ "math.add",
46
+ {"a": 2, "b": 3},
47
+ correlation_id="demo-correlation",
48
+ )
49
+
50
+ events = host.replay("demo-correlation")
51
+ ```
52
+
53
+ Async handlers are supported. Use `await host.ainvoke(...)` when already inside
54
+ an event loop.
55
+
56
+ By default, invocation payloads are not copied into evidence. Handlers can emit
57
+ explicit redacted evidence through `ctx.emit(...)`.
58
+
59
+ Payloads emitted through `ctx.emit(...)` are redacted by default for common
60
+ sensitive keys such as `token`, `secret`, `password`, `authorization`, and
61
+ `api_key`.
62
+
63
+ ## Adapters
64
+
65
+ Group related capabilities into an adapter class using `BaseAdapter` and the
66
+ `@capability` decorator. All decorated methods are auto-discovered:
67
+
68
+ ```python
69
+ from chp_core import BaseAdapter, capability, LocalCapabilityHost, register_adapter
70
+
71
+ class MathAdapter(BaseAdapter):
72
+ adapter_id = "math"
73
+ adapter_name = "Math Capabilities"
74
+
75
+ @capability(id="math.add", version="1.0.0", description="Add two numbers.")
76
+ async def add(self, ctx, payload):
77
+ return {"sum": payload["a"] + payload["b"]}
78
+
79
+ @capability(id="math.mul", version="1.0.0", description="Multiply two numbers.")
80
+ async def multiply(self, ctx, payload):
81
+ return {"product": payload["a"] * payload["b"]}
82
+
83
+ host = LocalCapabilityHost()
84
+ register_adapter(host, MathAdapter())
85
+ ```
86
+
87
+ For standalone functions, use `SimpleAdapter`:
88
+
89
+ ```python
90
+ from chp_core import SimpleAdapter, capability, register_adapter
91
+
92
+ @capability(id="greet.hello", version="1.0.0", description="Greet someone.")
93
+ def hello(name: str):
94
+ return {"message": f"Hello, {name}!"}
95
+
96
+ register_adapter(host, SimpleAdapter("greet", [hello]))
97
+ ```
98
+
99
+ ### Shipping an adapter package
100
+
101
+ Publish your adapter as a standalone package (e.g. `chp-linear`) and declare
102
+ it under the `chp.adapters` entry-point group so hosts can discover it
103
+ automatically:
104
+
105
+ ```toml
106
+ # your_adapter/pyproject.toml
107
+ [project.entry-points."chp.adapters"]
108
+ linear = "chp_linear:LinearAdapter"
109
+ ```
110
+
111
+ Once installed, any host can load all registered adapters:
112
+
113
+ ```python
114
+ from chp_core import auto_register_adapters
115
+
116
+ host = LocalCapabilityHost()
117
+ auto_register_adapters(host) # loads every installed chp.adapters entry point
118
+ ```
119
+
120
+ Or discover them manually:
121
+
122
+ ```python
123
+ from chp_core import discover_adapters
124
+
125
+ for name, adapter_cls in discover_adapters().items():
126
+ print(name, adapter_cls)
127
+ ```
128
+
129
+ `chp-core` ships a built-in `chp-git` adapter that exposes Git version-control
130
+ governance capabilities. It is registered automatically when the package is
131
+ installed.
132
+
133
+ ## HTTP Endpoint
134
+
135
+ The HTTP helper is transport glue around the same `LocalCapabilityHost`:
136
+
137
+ ```python
138
+ from chp_core import create_http_server
139
+
140
+ server = create_http_server(host, port=8765)
141
+ server.serve_forever()
142
+ ```
143
+
144
+ Routes:
145
+
146
+ - `GET /host`
147
+ - `GET /capabilities`
148
+ - `POST /invoke`
149
+ - `POST /replay`
150
+ - `GET /replay/{correlation_id}`
151
+
152
+ See `examples/capability-host-endpoint-demo/`.
153
+
154
+ The package also installs a small CLI:
155
+
156
+ ```bash
157
+ chp demo endpoint
158
+ chp serve-demo --port 8765
159
+ chp host
160
+ chp invoke demo.search_information --payload '{"query":"CHP vs MCP"}' --correlation-id corr_demo
161
+ chp replay corr_demo
162
+ ```
163
+
164
+ ## Development Evidence Controls
165
+
166
+ Use `chp work` to record local engineering work as CHP evidence:
167
+
168
+ ```bash
169
+ chp work run \
170
+ --intent "Verify the Python test suite." \
171
+ --correlation-id chp-dev-001 \
172
+ --test-run unit \
173
+ -- python -m unittest discover -s packages/python/tests
174
+
175
+ chp work summary chp-dev-001
176
+ chp work replay chp-dev-001
177
+ chp work explain chp-dev-001
178
+ chp work validate-demo endpoint --correlation-id chp-demo-validation
179
+ chp work check-alignment --correlation-id chp-alignment
180
+ chp work check-messaging --correlation-id chp-messaging
181
+ ```
182
+
183
+ ## Tests
184
+
185
+ ```bash
186
+ cd packages/python
187
+ python -m unittest discover -s tests
188
+ ```
@@ -0,0 +1,98 @@
1
+ """CHP v0.1 reference local host."""
2
+
3
+ from .adapters import (
4
+ CHP_ADAPTER_GROUP,
5
+ BaseAdapter,
6
+ CapabilityAdapter,
7
+ HostedCapability,
8
+ SimpleAdapter,
9
+ auto_register_adapters,
10
+ discover_adapters,
11
+ register_adapter,
12
+ register_capability_once,
13
+ register_hosted_capabilities,
14
+ )
15
+ from .capabilities import (
16
+ register_builtin_capabilities,
17
+ register_evaluate_counterfactual,
18
+ register_explain_execution,
19
+ register_trace_execution,
20
+ )
21
+ from .host import CapabilityExecutionContext, LocalCapabilityHost
22
+ from .http import CapabilityHostHTTPServer, create_http_server, serve_http
23
+ from .store import SQLiteEvidenceStore
24
+ from .decorators import capability
25
+ from .codex import (
26
+ CODEX_CAPABILITY_IDS,
27
+ record_codex_action,
28
+ register_codex_observation_capabilities,
29
+ )
30
+ from .otel import evidence_to_otel_span, replay_to_otel_spans
31
+ from .redaction import DEFAULT_SENSITIVE_KEYS, redact_payload
32
+ from .types import (
33
+ AssuranceMetadata,
34
+ CapabilityCategory,
35
+ CapabilityDescriptor,
36
+ CapabilityIdempotency,
37
+ CapabilityStatus,
38
+ CorrelationContext,
39
+ DenialReason,
40
+ ExecutionEvidence,
41
+ ExecutionOutcome,
42
+ HostDescriptor,
43
+ HostRequirements,
44
+ InvariantDescriptor,
45
+ InvocationEnvelope,
46
+ InvocationResult,
47
+ PolicyDescriptor,
48
+ ReplayQuery,
49
+ ReplayResult,
50
+ )
51
+
52
+ __all__ = [
53
+ "AssuranceMetadata",
54
+ "BaseAdapter",
55
+ "CHP_ADAPTER_GROUP",
56
+ "CODEX_CAPABILITY_IDS",
57
+ "CapabilityAdapter",
58
+ "CapabilityCategory",
59
+ "CapabilityIdempotency",
60
+ "CapabilityStatus",
61
+ "CapabilityDescriptor",
62
+ "CapabilityHostHTTPServer",
63
+ "CapabilityExecutionContext",
64
+ "capability",
65
+ "CorrelationContext",
66
+ "DEFAULT_SENSITIVE_KEYS",
67
+ "DenialReason",
68
+ "ExecutionEvidence",
69
+ "ExecutionOutcome",
70
+ "HostedCapability",
71
+ "HostDescriptor",
72
+ "HostRequirements",
73
+ "InvariantDescriptor",
74
+ "InvocationEnvelope",
75
+ "InvocationResult",
76
+ "LocalCapabilityHost",
77
+ "PolicyDescriptor",
78
+ "ReplayQuery",
79
+ "ReplayResult",
80
+ "SQLiteEvidenceStore",
81
+ "create_http_server",
82
+ "evidence_to_otel_span",
83
+ "redact_payload",
84
+ "SimpleAdapter",
85
+ "auto_register_adapters",
86
+ "discover_adapters",
87
+ "register_adapter",
88
+ "register_builtin_capabilities",
89
+ "register_capability_once",
90
+ "record_codex_action",
91
+ "register_codex_observation_capabilities",
92
+ "register_evaluate_counterfactual",
93
+ "register_explain_execution",
94
+ "register_hosted_capabilities",
95
+ "register_trace_execution",
96
+ "replay_to_otel_spans",
97
+ "serve_http",
98
+ ]