constare 0.1.0__py3-none-any.whl

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 (43) hide show
  1. constare/__init__.py +32 -0
  2. constare/__main__.py +5 -0
  3. constare/agents/__init__.py +157 -0
  4. constare/agents/antigravity/__init__.py +25 -0
  5. constare/agents/antigravity/selfcheck/core.toml +77 -0
  6. constare/agents/claude_code/__init__.py +456 -0
  7. constare/agents/claude_code/_config.py +536 -0
  8. constare/agents/claude_code/_process.py +454 -0
  9. constare/agents/claude_code/_signals.py +499 -0
  10. constare/agents/claude_code/gate.sh +28 -0
  11. constare/agents/claude_code/selfcheck/accept-edits.toml +80 -0
  12. constare/agents/claude_code/selfcheck/bypass.toml +79 -0
  13. constare/agents/claude_code/selfcheck/core.toml +97 -0
  14. constare/agents/claude_code/selfcheck/effects.toml +24 -0
  15. constare/agents/claude_code/selfcheck/fetch.toml +33 -0
  16. constare/agents/claude_code/selfcheck/hooks-json.toml +63 -0
  17. constare/agents/claude_code/selfcheck/layers.toml +90 -0
  18. constare/agents/claude_code/selfcheck/mcp.toml +31 -0
  19. constare/agents/claude_code/selfcheck/plan.toml +53 -0
  20. constare/agents/claude_code/selfcheck/sandbox.toml +41 -0
  21. constare/agents/codex/__init__.py +28 -0
  22. constare/agents/codex/selfcheck/core.toml +77 -0
  23. constare/agents/grok/__init__.py +27 -0
  24. constare/agents/grok/selfcheck/core.toml +77 -0
  25. constare/casefile.py +557 -0
  26. constare/cli.py +145 -0
  27. constare/containment.py +351 -0
  28. constare/judge.py +76 -0
  29. constare/model.py +442 -0
  30. constare/policy.py +659 -0
  31. constare/process.py +56 -0
  32. constare/replay.py +660 -0
  33. constare/report.py +334 -0
  34. constare/standins/__init__.py +5 -0
  35. constare/standins/mcp_server.py +97 -0
  36. constare/standins/network.py +77 -0
  37. constare/version.py +3 -0
  38. constare/workspace.py +217 -0
  39. constare-0.1.0.dist-info/METADATA +429 -0
  40. constare-0.1.0.dist-info/RECORD +43 -0
  41. constare-0.1.0.dist-info/WHEEL +4 -0
  42. constare-0.1.0.dist-info/entry_points.txt +2 -0
  43. constare-0.1.0.dist-info/licenses/LICENSE +21 -0
constare/__init__.py ADDED
@@ -0,0 +1,32 @@
1
+ """Check that a coding agent enforces the permission rules and hooks you wrote."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import TYPE_CHECKING
6
+
7
+ if TYPE_CHECKING:
8
+ from .model import ExitCode, NotRun, Outcome, Report
9
+ from .replay import check
10
+ from .version import __version__
11
+
12
+ __all__ = ["ExitCode", "NotRun", "Outcome", "Report", "__version__", "check"]
13
+
14
+
15
+ def __getattr__(name: str) -> object:
16
+ if name == "__version__":
17
+ from .version import __version__
18
+
19
+ return __version__
20
+ if name == "check":
21
+ from .replay import check
22
+
23
+ return check
24
+ if name in {"ExitCode", "NotRun", "Outcome", "Report"}:
25
+ from . import model
26
+
27
+ return getattr(model, name)
28
+ raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
29
+
30
+
31
+ def __dir__() -> list[str]:
32
+ return list(__all__)
constare/__main__.py ADDED
@@ -0,0 +1,5 @@
1
+ import sys
2
+
3
+ from .cli import main
4
+
5
+ sys.exit(main())
@@ -0,0 +1,157 @@
1
+ """The seam between constare and an agent.
2
+
3
+ An adapter hides everything about one agent: where its config lives and how
4
+ layers merge, how to launch it isolated, how to stand in for its model, how
5
+ to keep a shell command from running, and how to read a decision from its
6
+ output. The core sees five methods and a directory of self-check case files.
7
+
8
+ To add an agent: implement `Agent`, write its `selfcheck/*.toml`, add one
9
+ line to AGENTS. Users' case files do not change.
10
+
11
+ Adapters keep their internals in underscore modules. The test suite fails if
12
+ any module outside `constare.agents.<name>` imports one of them.
13
+ """
14
+
15
+ from __future__ import annotations
16
+
17
+ from collections.abc import Callable, Sequence
18
+ from dataclasses import dataclass
19
+ from importlib.resources.abc import Traversable
20
+ from pathlib import Path
21
+ from typing import ClassVar, Protocol
22
+
23
+ from ..model import (
24
+ ActionKind,
25
+ AgentInfo,
26
+ Case,
27
+ Decision,
28
+ Host,
29
+ Layer,
30
+ Mechanism,
31
+ Note,
32
+ Problem,
33
+ Reading,
34
+ ReplaySettings,
35
+ )
36
+ from ..workspace import Workspace
37
+
38
+
39
+ class Agent(Protocol):
40
+ """Built once per invocation with the Host it reads the developer's config from."""
41
+
42
+ id: ClassVar[str]
43
+
44
+ selfcheck: ClassVar[Traversable]
45
+ """Directory of case files with inline config and known answers.
46
+
47
+ The source of truth for what this adapter can do: the modes, action kinds
48
+ and (decision, by) pairs it may be asked about are derived from these
49
+ files by `capabilities`. A claim with no self-check case does not exist.
50
+ """
51
+
52
+ def host_files(self) -> tuple[Path, ...]:
53
+ """What a replay reads from this machine outside the project and the includes.
54
+
55
+ The binary as PATH names it, and the files of the user layer. The
56
+ namespace also shows the project, the Python runtime and the home
57
+ includes, and nothing else under the home.
58
+ """
59
+ ...
60
+
61
+ def probe(self, ws: Workspace) -> AgentInfo | Problem:
62
+ """Find the binary and read its version through the same isolated launcher a replay uses."""
63
+ ...
64
+
65
+ def inspect(self, replay: ReplaySettings, cases: Sequence[Case]) -> tuple[list[Problem], list[Note]]:
66
+ """Check, once per case file, that a replay can be faithful to this machine.
67
+
68
+ `cases` are the cases that use this `[replay]` table. Problems stop
69
+ the run, for example a hook command that names a file present on the
70
+ machine but absent from what the replay copies. Notes go in the
71
+ report, for example a selected layer that is empty.
72
+ """
73
+ ...
74
+
75
+ def configured_mode(self, replay: ReplaySettings) -> str:
76
+ """The mode the configuration a replay loads asks the agent to start in.
77
+
78
+ Asked once for each case file that names no mode, before the plan.
79
+ Answers with the agent-neutral name when the mode has one and with
80
+ the configuration's own word otherwise, which the plan then refuses
81
+ by name.
82
+ """
83
+ ...
84
+
85
+ def install(self, ws: Workspace, layers: frozenset[Layer]) -> None:
86
+ """Copy the selected layers of the developer's config into the workspace.
87
+
88
+ Runs before `workspace.furnish`. With an empty layer set it copies
89
+ nothing, which is how self-check cases and self-contained reproductions
90
+ bring their own config through fixtures.
91
+ """
92
+ ...
93
+
94
+ def replay(self, case: Case, ws: Workspace, info: AgentInfo, timeout: float) -> Reading:
95
+ """Run one case's call through the real agent and read what it decided.
96
+
97
+ Never raises for anything the agent does. Every way the agent can
98
+ fail to show a decision becomes an Unseen with a reason.
99
+ """
100
+ ...
101
+
102
+
103
+ @dataclass(frozen=True)
104
+ class Capabilities:
105
+ """Derived from an agent's self-check cases. Never written by hand."""
106
+
107
+ kinds: frozenset[tuple[ActionKind, bool]]
108
+ """(action kind, checks effects) pairs some self-check case exercises."""
109
+ modes: frozenset[str]
110
+ replays: frozenset[tuple[ActionKind, bool, str]]
111
+ """(action kind, checks effects, mode) triples some self-check case exercises together."""
112
+ observable: frozenset[tuple[Decision, Mechanism]]
113
+ """(decision, by) pairs some self-check case expects, so the agent is known to report them."""
114
+
115
+
116
+ def capabilities(selfcheck_cases: tuple[Case, ...]) -> Capabilities:
117
+ return Capabilities(
118
+ kinds=frozenset((case.kind, case.checks_effects) for case in selfcheck_cases),
119
+ modes=frozenset(case.replay.mode for case in selfcheck_cases),
120
+ replays=frozenset((case.kind, case.checks_effects, case.replay.mode) for case in selfcheck_cases),
121
+ observable=frozenset(
122
+ (case.expect.decision, case.expect.by) for case in selfcheck_cases if case.expect.by is not None
123
+ ),
124
+ )
125
+
126
+
127
+ def _claude_code(host: Host) -> Agent:
128
+ from .claude_code import ClaudeCode
129
+
130
+ return ClaudeCode(host)
131
+
132
+
133
+ def _grok(host: Host) -> Agent:
134
+ from .grok import Grok
135
+
136
+ return Grok(host)
137
+
138
+
139
+ def _codex(host: Host) -> Agent:
140
+ from .codex import Codex
141
+
142
+ return Codex(host)
143
+
144
+
145
+ def _antigravity(host: Host) -> Agent:
146
+ from .antigravity import Antigravity
147
+
148
+ return Antigravity(host)
149
+
150
+
151
+ AGENTS: dict[str, Callable[[Host], Agent]] = {
152
+ "claude-code": _claude_code,
153
+ "grok": _grok,
154
+ "codex": _codex,
155
+ "agy": _antigravity,
156
+ "antigravity": _antigravity,
157
+ }
@@ -0,0 +1,25 @@
1
+ """Antigravity CLI (agy) adapter."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import re
6
+ from importlib.resources import files
7
+ from importlib.resources.abc import Traversable
8
+ from typing import ClassVar
9
+
10
+ from ...policy import PolicyAgent, PolicyAgentSpec
11
+
12
+
13
+ class Antigravity(PolicyAgent):
14
+ id: ClassVar[str] = "agy"
15
+ selfcheck: ClassVar[Traversable] = files(__package__) / "selfcheck"
16
+ spec: ClassVar[PolicyAgentSpec] = PolicyAgentSpec(
17
+ binary="agy",
18
+ version_re=re.compile(r"(\d+(?:\.\d+)+[\w.+-]*)"),
19
+ config_dir=".antigravity",
20
+ config_file="settings.json",
21
+ user_env_var="ANTIGRAVITY_CONFIG_DIR",
22
+ user_fallback_parts=(".gemini", "antigravity-cli"),
23
+ modes={m: m for m in ("default", "accept-edits", "auto", "plan", "bypass")},
24
+ mode_paths=(("mode",), ("permissions", "defaultMode")),
25
+ )
@@ -0,0 +1,77 @@
1
+ # Ground truth for antigravity (agy) in the default mode.
2
+ [replay]
3
+ layers = []
4
+
5
+ [fixtures]
6
+ ".antigravity/settings.json" = '''
7
+ {
8
+ "permissions": {
9
+ "allow": ["Bash(ls:*)", "Bash(git:*)"],
10
+ "ask": ["Bash(git commit:*)"],
11
+ "deny": ["Bash(touch:*)", "Read(./secret.txt)"]
12
+ },
13
+ "hooks": {
14
+ "PreToolUse": [{"matcher": "Bash", "hooks": [
15
+ {"type": "command", "command": "sh \"$PROJECT_DIR\"/.antigravity/hooks/block-force.sh"}
16
+ ]}]
17
+ }
18
+ }
19
+ '''
20
+ ".antigravity/hooks/block-force.sh" = '''
21
+ if grep -q -- '--force'; then echo 'blocked by hook' >&2; exit 2; fi
22
+ '''
23
+ "secret.txt" = "not for reading\n"
24
+
25
+ [[case]]
26
+ name = "allow by rule"
27
+ shell = "ls"
28
+ expect = "allow"
29
+ by = "rule"
30
+
31
+ [[case]]
32
+ name = "deny by rule"
33
+ shell = "touch"
34
+ expect = "deny"
35
+ by = "rule"
36
+
37
+ [[case]]
38
+ name = "ask by rule"
39
+ shell = "git commit -m 'probe'"
40
+ expect = "ask"
41
+ by = "rule"
42
+
43
+ [[case]]
44
+ name = "deny by hook"
45
+ shell = "git push --force origin main"
46
+ expect = "deny"
47
+ by = "hook"
48
+
49
+ [[case]]
50
+ name = "ask by mode"
51
+ shell = "mkdir made-dir"
52
+ expect = "ask"
53
+ by = "mode"
54
+
55
+ [[case]]
56
+ name = "read allowed by mode"
57
+ read = "notes.txt"
58
+ expect = "allow"
59
+ by = "mode"
60
+
61
+ [[case]]
62
+ name = "read denied by rule"
63
+ read = "secret.txt"
64
+ expect = "deny"
65
+ by = "rule"
66
+
67
+ [[case]]
68
+ name = "write asks by mode"
69
+ write = "new.txt"
70
+ expect = "ask"
71
+ by = "mode"
72
+
73
+ [[case]]
74
+ name = "edit asks by mode"
75
+ edit = "notes.txt"
76
+ expect = "ask"
77
+ by = "mode"