alethic-kernel 0.4.0__tar.gz → 0.5.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.
Files changed (70) hide show
  1. {alethic_kernel-0.4.0 → alethic_kernel-0.5.0}/CHANGELOG.md +29 -0
  2. {alethic_kernel-0.4.0 → alethic_kernel-0.5.0}/CONTRIBUTING.md +11 -0
  3. {alethic_kernel-0.4.0/alethic_kernel.egg-info → alethic_kernel-0.5.0}/PKG-INFO +51 -2
  4. {alethic_kernel-0.4.0 → alethic_kernel-0.5.0}/README.md +50 -1
  5. {alethic_kernel-0.4.0 → alethic_kernel-0.5.0}/SECURITY.md +3 -4
  6. {alethic_kernel-0.4.0 → alethic_kernel-0.5.0/alethic_kernel.egg-info}/PKG-INFO +51 -2
  7. {alethic_kernel-0.4.0 → alethic_kernel-0.5.0}/alethic_kernel.egg-info/SOURCES.txt +8 -1
  8. alethic_kernel-0.5.0/alethic_kernel.egg-info/entry_points.txt +2 -0
  9. {alethic_kernel-0.4.0 → alethic_kernel-0.5.0}/pyproject.toml +4 -1
  10. {alethic_kernel-0.4.0 → alethic_kernel-0.5.0}/src/__init__.py +4 -0
  11. alethic_kernel-0.5.0/src/cli.py +122 -0
  12. {alethic_kernel-0.4.0 → alethic_kernel-0.5.0}/src/kernel.py +23 -6
  13. alethic_kernel-0.5.0/src/policy.py +240 -0
  14. {alethic_kernel-0.4.0 → alethic_kernel-0.5.0}/src/sqlite_store.py +16 -0
  15. {alethic_kernel-0.4.0 → alethic_kernel-0.5.0}/src/store.py +9 -0
  16. alethic_kernel-0.5.0/src/wrap.py +339 -0
  17. {alethic_kernel-0.4.0 → alethic_kernel-0.5.0}/tests/test_package_api.py +1 -1
  18. alethic_kernel-0.5.0/tests/test_policy.py +117 -0
  19. alethic_kernel-0.5.0/tests/test_store_trace.py +32 -0
  20. alethic_kernel-0.5.0/tests/test_wrap.py +254 -0
  21. {alethic_kernel-0.4.0 → alethic_kernel-0.5.0}/CODE_OF_CONDUCT.md +0 -0
  22. {alethic_kernel-0.4.0 → alethic_kernel-0.5.0}/LICENSE +0 -0
  23. {alethic_kernel-0.4.0 → alethic_kernel-0.5.0}/MANIFEST.in +0 -0
  24. {alethic_kernel-0.4.0 → alethic_kernel-0.5.0}/alethic_kernel.egg-info/dependency_links.txt +0 -0
  25. {alethic_kernel-0.4.0 → alethic_kernel-0.5.0}/alethic_kernel.egg-info/requires.txt +0 -0
  26. {alethic_kernel-0.4.0 → alethic_kernel-0.5.0}/alethic_kernel.egg-info/top_level.txt +0 -0
  27. {alethic_kernel-0.4.0 → alethic_kernel-0.5.0}/docs/api-reference.md +0 -0
  28. {alethic_kernel-0.4.0 → alethic_kernel-0.5.0}/docs/architecture.md +0 -0
  29. {alethic_kernel-0.4.0 → alethic_kernel-0.5.0}/docs/architecture.png +0 -0
  30. {alethic_kernel-0.4.0 → alethic_kernel-0.5.0}/docs/workers.md +0 -0
  31. {alethic_kernel-0.4.0 → alethic_kernel-0.5.0}/setup.cfg +0 -0
  32. {alethic_kernel-0.4.0 → alethic_kernel-0.5.0}/src/adaptive_worker.py +0 -0
  33. {alethic_kernel-0.4.0 → alethic_kernel-0.5.0}/src/context.py +0 -0
  34. {alethic_kernel-0.4.0 → alethic_kernel-0.5.0}/src/decision.py +0 -0
  35. {alethic_kernel-0.4.0 → alethic_kernel-0.5.0}/src/migrations.py +0 -0
  36. {alethic_kernel-0.4.0 → alethic_kernel-0.5.0}/src/orchestrator.py +0 -0
  37. {alethic_kernel-0.4.0 → alethic_kernel-0.5.0}/src/permissions.py +0 -0
  38. {alethic_kernel-0.4.0 → alethic_kernel-0.5.0}/src/py.typed +0 -0
  39. {alethic_kernel-0.4.0 → alethic_kernel-0.5.0}/src/schema.py +0 -0
  40. {alethic_kernel-0.4.0 → alethic_kernel-0.5.0}/src/session.py +0 -0
  41. {alethic_kernel-0.4.0 → alethic_kernel-0.5.0}/src/sim_worker.py +0 -0
  42. {alethic_kernel-0.4.0 → alethic_kernel-0.5.0}/src/store_protocol.py +0 -0
  43. {alethic_kernel-0.4.0 → alethic_kernel-0.5.0}/src/testing.py +0 -0
  44. {alethic_kernel-0.4.0 → alethic_kernel-0.5.0}/src/validators.py +0 -0
  45. {alethic_kernel-0.4.0 → alethic_kernel-0.5.0}/src/worker.py +0 -0
  46. {alethic_kernel-0.4.0 → alethic_kernel-0.5.0}/tests/__init__.py +0 -0
  47. {alethic_kernel-0.4.0 → alethic_kernel-0.5.0}/tests/conftest.py +0 -0
  48. {alethic_kernel-0.4.0 → alethic_kernel-0.5.0}/tests/helpers.py +0 -0
  49. {alethic_kernel-0.4.0 → alethic_kernel-0.5.0}/tests/test_action_decision.py +0 -0
  50. {alethic_kernel-0.4.0 → alethic_kernel-0.5.0}/tests/test_action_validator_chain.py +0 -0
  51. {alethic_kernel-0.4.0 → alethic_kernel-0.5.0}/tests/test_adaptive_worker.py +0 -0
  52. {alethic_kernel-0.4.0 → alethic_kernel-0.5.0}/tests/test_atomicity.py +0 -0
  53. {alethic_kernel-0.4.0 → alethic_kernel-0.5.0}/tests/test_belief_validator_chain.py +0 -0
  54. {alethic_kernel-0.4.0 → alethic_kernel-0.5.0}/tests/test_concurrency.py +0 -0
  55. {alethic_kernel-0.4.0 → alethic_kernel-0.5.0}/tests/test_conformance_suite_is_importable.py +0 -0
  56. {alethic_kernel-0.4.0 → alethic_kernel-0.5.0}/tests/test_context.py +0 -0
  57. {alethic_kernel-0.4.0 → alethic_kernel-0.5.0}/tests/test_docs_examples.py +0 -0
  58. {alethic_kernel-0.4.0 → alethic_kernel-0.5.0}/tests/test_kernel.py +0 -0
  59. {alethic_kernel-0.4.0 → alethic_kernel-0.5.0}/tests/test_migrations.py +0 -0
  60. {alethic_kernel-0.4.0 → alethic_kernel-0.5.0}/tests/test_orchestrator.py +0 -0
  61. {alethic_kernel-0.4.0 → alethic_kernel-0.5.0}/tests/test_permissions.py +0 -0
  62. {alethic_kernel-0.4.0 → alethic_kernel-0.5.0}/tests/test_readme_assets.py +0 -0
  63. {alethic_kernel-0.4.0 → alethic_kernel-0.5.0}/tests/test_schema.py +0 -0
  64. {alethic_kernel-0.4.0 → alethic_kernel-0.5.0}/tests/test_session.py +0 -0
  65. {alethic_kernel-0.4.0 → alethic_kernel-0.5.0}/tests/test_sim_worker.py +0 -0
  66. {alethic_kernel-0.4.0 → alethic_kernel-0.5.0}/tests/test_sqlite_store.py +0 -0
  67. {alethic_kernel-0.4.0 → alethic_kernel-0.5.0}/tests/test_store.py +0 -0
  68. {alethic_kernel-0.4.0 → alethic_kernel-0.5.0}/tests/test_store_equivalence.py +0 -0
  69. {alethic_kernel-0.4.0 → alethic_kernel-0.5.0}/tests/test_validator_isolation.py +0 -0
  70. {alethic_kernel-0.4.0 → alethic_kernel-0.5.0}/tests/test_validators.py +0 -0
@@ -5,6 +5,35 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [Unreleased]
9
+
10
+ ## [0.5.0] - 2026-11-28
11
+
12
+ ### Added
13
+
14
+ - Added `list_trace(slot, trace_id)` to `MemoryStore` and `SqliteStore`: one
15
+ trace's records in a slot, in append order. On SQLite it is served by the
16
+ trace index. It is optional for other stores; the kernel uses it when a
17
+ store has it and persistent records were not asked for.
18
+
19
+ - Added the `alethic` command. `alethic wrap -- <server command>` runs any MCP
20
+ server with each `tools/call` decided by the kernel against a TOML policy
21
+ and recorded; refused calls are answered by the wrapper and never reach the
22
+ server, and tools no call could pass for are removed from `tools/list`.
23
+ `alethic log` shows recorded decisions and `alethic init` writes a starter
24
+ policy.
25
+ - Added `Policy`, `PolicyError` and `PolicyValidator`, exported from `alethic`:
26
+ a declarative allow/deny/review policy usable as an action validator.
27
+
28
+ ### Changed
29
+
30
+ - `commit_belief_from_proposal`, `validate_plan` and `decide_action` now read
31
+ only the slots their gates use. Each previously loaded every record in all
32
+ seven slots, so decisions on a long-lived store slowed with every record
33
+ written. With a store that has `list_trace` they load only the current
34
+ trace's records, so the cost of a decision no longer depends on the size
35
+ of the store. `current_view()` returns what it did before.
36
+
8
37
  ## [0.4.0] - 2026-09-20
9
38
 
10
39
  ### Added
@@ -2,6 +2,17 @@
2
2
 
3
3
  Thank you for your interest in contributing to Alethic! We welcome contributions, feedback, and ideas from the community.
4
4
 
5
+ ## Start here
6
+
7
+ Browse [focused starter issues](https://github.com/emiluzelac/alethic/labels/good%20first%20issue)
8
+ or propose a small change to the [public issue tracker](https://github.com/emiluzelac/alethic/issues).
9
+ Good first contributions include a runnable custom validator example and a
10
+ short tutorial showing how governed records survive a restart with the SQLite
11
+ store. Use synthetic inputs and include the expected decision or output.
12
+
13
+ Use [the private reporting form](https://github.com/emiluzelac/alethic/security/advisories/new)
14
+ for suspected vulnerabilities. See the [security policy](SECURITY.md) for scope.
15
+
5
16
  ## Code of Conduct
6
17
 
7
18
  Be respectful, inclusive, and professional. We're building trust in AI systems together.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: alethic-kernel
3
- Version: 0.4.0
3
+ Version: 0.5.0
4
4
  Summary: Alethic: a governed cognitive substrate for AI systems
5
5
  Author: Emil Uzelac
6
6
  License-Expression: MIT
@@ -30,7 +30,7 @@ Dynamic: license-file
30
30
 
31
31
  # Alethic
32
32
 
33
- **A governed cognitive substrate for AI systems.**
33
+ **Govern evidence, state, and actions for AI systems.**
34
34
 
35
35
  [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.18691808.svg)](https://doi.org/10.5281/zenodo.18691808)
36
36
 
@@ -41,6 +41,14 @@ external effects. It maintains typed state, links beliefs to evidence, applies
41
41
  declarative constraints, and records why each proposal was committed or
42
42
  invalidated. The kernel contains no model, prompt, tool, task, or domain logic.
43
43
 
44
+ ## Alethic Kernel and Guard
45
+
46
+ Use the kernel as a standalone Python library to evaluate proposals inside a
47
+ trusted application. [Alethic Guard](https://github.com/emiluzelac/alethic-guard)
48
+ uses the kernel for mediated approvals and adds host-side isolation and recovery
49
+ for enrolled workloads on supported Ubuntu/KVM hosts. [Explore both projects and
50
+ try the live kernel demo](https://alethic.dev/).
51
+
44
52
  ## Install
45
53
 
46
54
  The Python distribution is named `alethic-kernel`; its single import namespace
@@ -50,6 +58,47 @@ is `alethic`.
50
58
  pip install alethic-kernel
51
59
  ```
52
60
 
61
+ ## Govern an agent's tools in one line
62
+
63
+ `alethic wrap` goes in front of any MCP server command. Every tool call the
64
+ agent makes becomes a proposal, the kernel decides it against your policy, and
65
+ the decision is recorded. A refused call never reaches the server.
66
+
67
+ ```json
68
+ { "command": "alethic", "args": ["wrap", "--", "npx", "some-mcp-server"] }
69
+ ```
70
+
71
+ With no policy, every call is allowed and recorded, so you get an audit log
72
+ before you write a rule. `alethic init` writes a starter `alethic.toml`:
73
+
74
+ ```toml
75
+ default = "allow" # "deny" makes this an allow-list
76
+
77
+ [[rule]]
78
+ tool = "delete_*" # glob on the tool name
79
+ action = "deny"
80
+
81
+ [[rule]]
82
+ tool = "write_file"
83
+ args.path = { under = "~/projects/demo" } # symlinks and ".." are resolved first
84
+ action = "allow"
85
+
86
+ [[rule]]
87
+ tool = "write_file"
88
+ action = "review" # refused, and marked for a person to decide
89
+ ```
90
+
91
+ The policy is the first found of `--policy`, `$ALETHIC_POLICY`,
92
+ `~/.alethic/policy.toml`, then `./alethic.toml`; a file in the project folder
93
+ never overrides your own. The first matching rule decides. Tools that no call could pass for are removed
94
+ from the list the model sees. `alethic log` shows what was allowed and refused.
95
+ Session logs are SQLite files under `~/.alethic/sessions`, readable only by
96
+ you; set `record_arguments = false` to store a digest in place of each call's
97
+ arguments.
98
+
99
+ The wrapper governs calls that go through it. It does not sandbox the server
100
+ or stop an agent that has another route to the same effect.
101
+
53
102
  ## Use
54
103
 
55
104
  ```python
@@ -1,6 +1,6 @@
1
1
  # Alethic
2
2
 
3
- **A governed cognitive substrate for AI systems.**
3
+ **Govern evidence, state, and actions for AI systems.**
4
4
 
5
5
  [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.18691808.svg)](https://doi.org/10.5281/zenodo.18691808)
6
6
 
@@ -11,6 +11,14 @@ external effects. It maintains typed state, links beliefs to evidence, applies
11
11
  declarative constraints, and records why each proposal was committed or
12
12
  invalidated. The kernel contains no model, prompt, tool, task, or domain logic.
13
13
 
14
+ ## Alethic Kernel and Guard
15
+
16
+ Use the kernel as a standalone Python library to evaluate proposals inside a
17
+ trusted application. [Alethic Guard](https://github.com/emiluzelac/alethic-guard)
18
+ uses the kernel for mediated approvals and adds host-side isolation and recovery
19
+ for enrolled workloads on supported Ubuntu/KVM hosts. [Explore both projects and
20
+ try the live kernel demo](https://alethic.dev/).
21
+
14
22
  ## Install
15
23
 
16
24
  The Python distribution is named `alethic-kernel`; its single import namespace
@@ -20,6 +28,47 @@ is `alethic`.
20
28
  pip install alethic-kernel
21
29
  ```
22
30
 
31
+ ## Govern an agent's tools in one line
32
+
33
+ `alethic wrap` goes in front of any MCP server command. Every tool call the
34
+ agent makes becomes a proposal, the kernel decides it against your policy, and
35
+ the decision is recorded. A refused call never reaches the server.
36
+
37
+ ```json
38
+ { "command": "alethic", "args": ["wrap", "--", "npx", "some-mcp-server"] }
39
+ ```
40
+
41
+ With no policy, every call is allowed and recorded, so you get an audit log
42
+ before you write a rule. `alethic init` writes a starter `alethic.toml`:
43
+
44
+ ```toml
45
+ default = "allow" # "deny" makes this an allow-list
46
+
47
+ [[rule]]
48
+ tool = "delete_*" # glob on the tool name
49
+ action = "deny"
50
+
51
+ [[rule]]
52
+ tool = "write_file"
53
+ args.path = { under = "~/projects/demo" } # symlinks and ".." are resolved first
54
+ action = "allow"
55
+
56
+ [[rule]]
57
+ tool = "write_file"
58
+ action = "review" # refused, and marked for a person to decide
59
+ ```
60
+
61
+ The policy is the first found of `--policy`, `$ALETHIC_POLICY`,
62
+ `~/.alethic/policy.toml`, then `./alethic.toml`; a file in the project folder
63
+ never overrides your own. The first matching rule decides. Tools that no call could pass for are removed
64
+ from the list the model sees. `alethic log` shows what was allowed and refused.
65
+ Session logs are SQLite files under `~/.alethic/sessions`, readable only by
66
+ you; set `record_arguments = false` to store a digest in place of each call's
67
+ arguments.
68
+
69
+ The wrapper governs calls that go through it. It does not sandbox the server
70
+ or stop an agent that has another route to the same effect.
71
+
23
72
  ## Use
24
73
 
25
74
  ```python
@@ -2,9 +2,8 @@
2
2
 
3
3
  ## Reporting a Vulnerability
4
4
 
5
- Please report security vulnerabilities through GitHub's private vulnerability
6
- reporting: go to the **Security** tab of this repository and choose **Report a
7
- vulnerability**.
5
+ Report a suspected vulnerability through [GitHub's private vulnerability
6
+ reporting form](https://github.com/emiluzelac/alethic/security/advisories/new).
8
7
 
9
8
  Please do not open a public issue for a security vulnerability.
10
9
 
@@ -18,7 +17,7 @@ Alethic is pre-1.0. Only the latest release receives security fixes.
18
17
 
19
18
  | Version | Supported |
20
19
  | ------- | --------- |
21
- | 0.3.x | ✅ |
20
+ | 0.5.0 | ✅ |
22
21
 
23
22
  ## Scope and Known Limitations
24
23
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: alethic-kernel
3
- Version: 0.4.0
3
+ Version: 0.5.0
4
4
  Summary: Alethic: a governed cognitive substrate for AI systems
5
5
  Author: Emil Uzelac
6
6
  License-Expression: MIT
@@ -30,7 +30,7 @@ Dynamic: license-file
30
30
 
31
31
  # Alethic
32
32
 
33
- **A governed cognitive substrate for AI systems.**
33
+ **Govern evidence, state, and actions for AI systems.**
34
34
 
35
35
  [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.18691808.svg)](https://doi.org/10.5281/zenodo.18691808)
36
36
 
@@ -41,6 +41,14 @@ external effects. It maintains typed state, links beliefs to evidence, applies
41
41
  declarative constraints, and records why each proposal was committed or
42
42
  invalidated. The kernel contains no model, prompt, tool, task, or domain logic.
43
43
 
44
+ ## Alethic Kernel and Guard
45
+
46
+ Use the kernel as a standalone Python library to evaluate proposals inside a
47
+ trusted application. [Alethic Guard](https://github.com/emiluzelac/alethic-guard)
48
+ uses the kernel for mediated approvals and adds host-side isolation and recovery
49
+ for enrolled workloads on supported Ubuntu/KVM hosts. [Explore both projects and
50
+ try the live kernel demo](https://alethic.dev/).
51
+
44
52
  ## Install
45
53
 
46
54
  The Python distribution is named `alethic-kernel`; its single import namespace
@@ -50,6 +58,47 @@ is `alethic`.
50
58
  pip install alethic-kernel
51
59
  ```
52
60
 
61
+ ## Govern an agent's tools in one line
62
+
63
+ `alethic wrap` goes in front of any MCP server command. Every tool call the
64
+ agent makes becomes a proposal, the kernel decides it against your policy, and
65
+ the decision is recorded. A refused call never reaches the server.
66
+
67
+ ```json
68
+ { "command": "alethic", "args": ["wrap", "--", "npx", "some-mcp-server"] }
69
+ ```
70
+
71
+ With no policy, every call is allowed and recorded, so you get an audit log
72
+ before you write a rule. `alethic init` writes a starter `alethic.toml`:
73
+
74
+ ```toml
75
+ default = "allow" # "deny" makes this an allow-list
76
+
77
+ [[rule]]
78
+ tool = "delete_*" # glob on the tool name
79
+ action = "deny"
80
+
81
+ [[rule]]
82
+ tool = "write_file"
83
+ args.path = { under = "~/projects/demo" } # symlinks and ".." are resolved first
84
+ action = "allow"
85
+
86
+ [[rule]]
87
+ tool = "write_file"
88
+ action = "review" # refused, and marked for a person to decide
89
+ ```
90
+
91
+ The policy is the first found of `--policy`, `$ALETHIC_POLICY`,
92
+ `~/.alethic/policy.toml`, then `./alethic.toml`; a file in the project folder
93
+ never overrides your own. The first matching rule decides. Tools that no call could pass for are removed
94
+ from the list the model sees. `alethic log` shows what was allowed and refused.
95
+ Session logs are SQLite files under `~/.alethic/sessions`, readable only by
96
+ you; set `record_arguments = false` to store a digest in place of each call's
97
+ arguments.
98
+
99
+ The wrapper governs calls that go through it. It does not sandbox the server
100
+ or stop an agent that has another route to the same effect.
101
+
53
102
  ## Use
54
103
 
55
104
  ```python
@@ -9,6 +9,7 @@ pyproject.toml
9
9
  alethic_kernel.egg-info/PKG-INFO
10
10
  alethic_kernel.egg-info/SOURCES.txt
11
11
  alethic_kernel.egg-info/dependency_links.txt
12
+ alethic_kernel.egg-info/entry_points.txt
12
13
  alethic_kernel.egg-info/requires.txt
13
14
  alethic_kernel.egg-info/top_level.txt
14
15
  docs/api-reference.md
@@ -17,12 +18,14 @@ docs/architecture.png
17
18
  docs/workers.md
18
19
  src/__init__.py
19
20
  src/adaptive_worker.py
21
+ src/cli.py
20
22
  src/context.py
21
23
  src/decision.py
22
24
  src/kernel.py
23
25
  src/migrations.py
24
26
  src/orchestrator.py
25
27
  src/permissions.py
28
+ src/policy.py
26
29
  src/py.typed
27
30
  src/schema.py
28
31
  src/session.py
@@ -33,6 +36,7 @@ src/store_protocol.py
33
36
  src/testing.py
34
37
  src/validators.py
35
38
  src/worker.py
39
+ src/wrap.py
36
40
  tests/__init__.py
37
41
  tests/conftest.py
38
42
  tests/helpers.py
@@ -50,6 +54,7 @@ tests/test_migrations.py
50
54
  tests/test_orchestrator.py
51
55
  tests/test_package_api.py
52
56
  tests/test_permissions.py
57
+ tests/test_policy.py
53
58
  tests/test_readme_assets.py
54
59
  tests/test_schema.py
55
60
  tests/test_session.py
@@ -57,5 +62,7 @@ tests/test_sim_worker.py
57
62
  tests/test_sqlite_store.py
58
63
  tests/test_store.py
59
64
  tests/test_store_equivalence.py
65
+ tests/test_store_trace.py
60
66
  tests/test_validator_isolation.py
61
- tests/test_validators.py
67
+ tests/test_validators.py
68
+ tests/test_wrap.py
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ alethic = alethic.cli:main
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "alethic-kernel"
7
- version = "0.4.0"
7
+ version = "0.5.0"
8
8
  description = "Alethic: a governed cognitive substrate for AI systems"
9
9
  requires-python = ">=3.11"
10
10
  license = "MIT"
@@ -31,6 +31,9 @@ Repository = "https://github.com/emiluzelac/alethic.git"
31
31
  "Bug Tracker" = "https://github.com/emiluzelac/alethic/issues"
32
32
  "Research Paper" = "https://doi.org/10.5281/zenodo.18691808"
33
33
 
34
+ [project.scripts]
35
+ alethic = "alethic.cli:main"
36
+
34
37
  [project.optional-dependencies]
35
38
  dev = ["pytest>=8.0", "pytest-cov", "mypy"]
36
39
 
@@ -22,6 +22,7 @@ from .orchestrator import Orchestrator, OrchestratorResult
22
22
  from .session import Session
23
23
  from .sim_worker import SimulatorWorker, SimRule, evaluate_rule
24
24
  from .adaptive_worker import AdaptiveWorker
25
+ from .policy import Policy, PolicyError, PolicyValidator
25
26
 
26
27
  try:
27
28
  __version__ = _version("alethic-kernel")
@@ -40,6 +41,9 @@ __all__ = [
40
41
  "Orchestrator",
41
42
  "OrchestratorResult",
42
43
  "PERMISSIONS",
44
+ "Policy",
45
+ "PolicyError",
46
+ "PolicyValidator",
43
47
  "Provenance",
44
48
  "Record",
45
49
  "RecordIdConflict",
@@ -0,0 +1,122 @@
1
+ """The ``alethic`` command."""
2
+ from __future__ import annotations
3
+
4
+ import argparse
5
+ import json
6
+ import sys
7
+ import time
8
+ from pathlib import Path
9
+ from typing import List, Optional, Sequence
10
+
11
+ from . import __version__
12
+ from .policy import PolicyError
13
+ from .wrap import home, read_log, run
14
+
15
+ STARTER_POLICY = '''\
16
+ # Alethic tool-call policy. The first matching rule decides; see `alethic wrap --help`.
17
+ default = "allow" # "deny" makes this an allow-list
18
+ record_arguments = true # false stores only a SHA-256 of each call's arguments
19
+
20
+ # [[rule]]
21
+ # tool = "delete_*"
22
+ # action = "deny"
23
+ # reason = "Deleting is not allowed here"
24
+
25
+ # [[rule]]
26
+ # tool = "write_file"
27
+ # args.path = { under = "~/projects/demo" }
28
+ # action = "allow"
29
+
30
+ # [[rule]]
31
+ # tool = "write_file"
32
+ # action = "review"
33
+ '''
34
+
35
+
36
+ def _wrap(args: argparse.Namespace) -> int:
37
+ command: List[str] = args.command[1:] if args.command[:1] == ["--"] else args.command
38
+ if not command:
39
+ print("alethic: give the server command after --, e.g. alethic wrap -- npx some-mcp-server",
40
+ file=sys.stderr)
41
+ return 2
42
+ try:
43
+ return run(command, args.policy, args.log_dir)
44
+ except (PolicyError, OSError) as exc:
45
+ print(f"alethic: {exc}", file=sys.stderr)
46
+ return 2
47
+
48
+
49
+ def _log(args: argparse.Namespace) -> int:
50
+ directory = Path(args.log_dir).expanduser() if args.log_dir else home() / "sessions"
51
+ logs = sorted(directory.glob("*.db"))
52
+ if args.session:
53
+ logs = [p for p in logs if args.session in p.name]
54
+ elif not args.all:
55
+ logs = logs[-1:]
56
+ if not logs:
57
+ print(f"alethic: no session logs in {directory}", file=sys.stderr)
58
+ return 1
59
+ for path in logs:
60
+ rows = read_log(path)
61
+ if args.json:
62
+ for row in rows:
63
+ print(json.dumps({"session": path.stem, **row}, ensure_ascii=False))
64
+ continue
65
+ print(f"{path.stem} ({len(rows)} tool calls)")
66
+ for row in rows:
67
+ when = time.strftime("%H:%M:%S", time.localtime(row["ts_ms"] / 1000))
68
+ shown = json.dumps(row["arguments"], ensure_ascii=False) if row["arguments"] is not None else ""
69
+ if len(shown) > 70:
70
+ shown = shown[:67] + "..."
71
+ tail = f" [{row['reason']}]" if row["reason"] else ""
72
+ print(f" {when} {row['outcome'].upper():<6} {row['tool']} {shown}{tail}")
73
+ return 0
74
+
75
+
76
+ def _init(args: argparse.Namespace) -> int:
77
+ path = Path(args.path)
78
+ try:
79
+ with open(path, "x", encoding="utf-8") as handle:
80
+ handle.write(STARTER_POLICY)
81
+ except FileExistsError:
82
+ print(f"alethic: {path} already exists", file=sys.stderr)
83
+ return 1
84
+ print(f"Wrote {path}")
85
+ return 0
86
+
87
+
88
+ def main(argv: Optional[Sequence[str]] = None) -> int:
89
+ parser = argparse.ArgumentParser(prog="alethic", description="Govern what AI agents are allowed to do.")
90
+ parser.add_argument("--version", action="version", version=f"alethic {__version__}")
91
+ commands = parser.add_subparsers(dest="name", required=True)
92
+
93
+ wrap = commands.add_parser(
94
+ "wrap", help="run an MCP server with every tool call decided and recorded",
95
+ description="Put this in front of an MCP server command. Tool calls are checked against "
96
+ "the first policy found: --policy, $ALETHIC_POLICY, ~/.alethic/policy.toml, then "
97
+ "./alethic.toml. A project file never overrides your own policy. Calls are "
98
+ "recorded. With no policy, every call is allowed and recorded.",
99
+ )
100
+ wrap.add_argument("--policy", help="policy file (TOML)")
101
+ wrap.add_argument("--log-dir", help="where session logs go (default ~/.alethic/sessions)")
102
+ wrap.add_argument("command", nargs=argparse.REMAINDER, help="-- server command and its arguments")
103
+ wrap.set_defaults(handler=_wrap)
104
+
105
+ log = commands.add_parser("log", help="show recorded tool-call decisions")
106
+ log.add_argument("--log-dir", help="where session logs are (default ~/.alethic/sessions)")
107
+ log.add_argument("--session", help="show sessions whose name contains this text")
108
+ log.add_argument("--all", action="store_true", help="show every session, not only the latest")
109
+ log.add_argument("--json", action="store_true", help="one JSON object per tool call")
110
+ log.set_defaults(handler=_log)
111
+
112
+ init = commands.add_parser("init", help="write a starter policy file")
113
+ init.add_argument("path", nargs="?", default="alethic.toml")
114
+ init.set_defaults(handler=_init)
115
+
116
+ args = parser.parse_args(argv)
117
+ handler = args.handler
118
+ return int(handler(args))
119
+
120
+
121
+ if __name__ == "__main__":
122
+ sys.exit(main())
@@ -23,6 +23,9 @@ def _rid(slot: str, n: int, trace_id: str) -> str:
23
23
  return f"{slot}:{trace_id}:{n}"
24
24
 
25
25
 
26
+ _ALL_SLOTS: Tuple[Slot, ...] = ("percepts", "beliefs", "constraints", "plans",
27
+ "evidence", "predictions", "actions")
28
+
26
29
  # A backstop against spinning forever if a store reports every id as taken.
27
30
  # Reached only by a store that is misbehaving, never by a busy trace.
28
31
  _MAX_ID_PROBES = 10_000
@@ -299,11 +302,25 @@ class Kernel:
299
302
 
300
303
  def current_view(self, trace_id: str,
301
304
  include_persistent: bool = False) -> Dict[str, Dict[str, Any]]:
302
- slots: List[Slot] = ["percepts", "beliefs", "constraints", "plans",
303
- "evidence", "predictions", "actions"]
305
+ return self._view(trace_id, _ALL_SLOTS, include_persistent)
306
+
307
+ def _view(self, trace_id: str, slots: Sequence[Slot],
308
+ include_persistent: bool = False) -> Dict[str, Dict[str, Any]]:
309
+ """``current_view`` restricted to the slots a gate actually reads.
310
+
311
+ Reading a slot loads every record in it, for every trace. A decision
312
+ that asked for all seven would reread the whole audit trail each time,
313
+ including the actions and evidence slots that every decision appends
314
+ to, so a long-lived store would get slower with each call it records.
315
+ """
304
316
  view: Dict[str, Dict[str, Any]] = {s: {} for s in slots}
317
+ # A store may offer list_trace(slot, trace_id): the same records as
318
+ # list_slot filtered to one trace, without loading the others.
319
+ # Persistent records belong to other traces, so they need the slot.
320
+ by_trace = None if include_persistent else getattr(self.store, "list_trace", None)
305
321
  for slot in slots:
306
- for r in self.store.list_slot(slot):
322
+ records = by_trace(slot, trace_id) if by_trace else self.store.list_slot(slot)
323
+ for r in records:
307
324
  if r.status != "ACTIVE":
308
325
  continue
309
326
  # include record if it matches the trace_id, or if it's
@@ -335,7 +352,7 @@ class Kernel:
335
352
  if not prop or prop.status != "ACTIVE" or prop.slot != "beliefs" or prop.mode != "PROPOSE":
336
353
  return False, "INVALID_PROPOSAL"
337
354
 
338
- view = self.current_view(trace_id)
355
+ view = self._view(trace_id, ("percepts",))
339
356
  context = ValidationContext(store=self.store, trace_id=trace_id,
340
357
  now_ms=int(time.time() * 1000))
341
358
  validator_results: List[Dict[str, Any]] = []
@@ -478,7 +495,7 @@ class Kernel:
478
495
  if not prop or prop.status != "ACTIVE" or prop.slot != "plans" or prop.mode != "PROPOSE":
479
496
  return False, "INVALID_PLAN_PROPOSAL"
480
497
 
481
- view = self.current_view(trace_id)
498
+ view = self._view(trace_id, ("beliefs", "constraints"))
482
499
  committed_beliefs = view["beliefs"]
483
500
  constraints = view["constraints"]
484
501
 
@@ -553,7 +570,7 @@ class Kernel:
553
570
  code="INVALID_ACTION_PROPOSAL",
554
571
  reasons=(f"Not an active action proposal: {proposal_id}",),
555
572
  )
556
- view = self.current_view(trace_id)
573
+ view = self._view(trace_id, ("beliefs", "constraints", "predictions"))
557
574
 
558
575
  # optional prediction gate
559
576
  if require_prediction: