@yahyahammad/venastine 0.3.8 → 0.3.10
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.
- package/.env.example +19 -19
- package/CONFIG_ARCHITECTURE.md +2139 -2002
- package/LICENSE +201 -201
- package/README.md +1043 -1034
- package/agents/builtin/compactor.md +75 -75
- package/agents/builtin/explore.md +77 -77
- package/agents/builtin/pipeline-reviewer.md +100 -100
- package/agents/builtin/plan.md +106 -106
- package/agents/builtin/review.md +74 -74
- package/agents/manager.py +261 -261
- package/agents/subagent_tool.py +472 -472
- package/agents/tui_commands.py +238 -146
- package/bin/venastine.mjs +584 -528
- package/bin/venastine.py +73 -71
- package/cli_commands.py +848 -835
- package/config.yaml +64 -0
- package/config_edit.py +1301 -1301
- package/config_schema.py +987 -966
- package/config_update.py +749 -749
- package/core/agent_activity.py +256 -256
- package/core/ansi.py +452 -452
- package/core/approval.py +137 -137
- package/core/call_view.py +364 -364
- package/core/cancel.py +121 -121
- package/core/chatgpt_auth.py +747 -747
- package/core/claims_view.py +107 -107
- package/core/client.py +2756 -2715
- package/core/commands.py +464 -454
- package/core/compaction.py +1735 -1735
- package/core/config_loader.py +1982 -1982
- package/core/connect.py +686 -686
- package/core/events.py +123 -123
- package/core/file_mentions.py +280 -280
- package/core/interaction.py +411 -411
- package/core/loop.py +2566 -2566
- package/core/memory.py +482 -482
- package/core/pipeline_models.py +190 -190
- package/core/provider_errors.py +274 -234
- package/core/reasoning/authorization.py +130 -130
- package/core/reasoning/base.py +219 -219
- package/core/reasoning/confidence_scoring.py +484 -484
- package/core/reasoning/events.py +149 -149
- package/core/reasoning/orchestrator.py +1561 -1561
- package/core/reasoning/output_writer.py +345 -345
- package/core/reasoning/payload_validation.py +524 -524
- package/core/reasoning/pipeline_storage.py +427 -427
- package/core/reasoning/scholar.py +467 -458
- package/core/reasoning/source_corpus.py +433 -433
- package/core/reasoning/source_scoring.py +855 -855
- package/core/replay.py +315 -315
- package/core/shell_sessions.py +1553 -1553
- package/credentials.py +307 -307
- package/database.py +333 -333
- package/docs/PRIVACY.md +78 -78
- package/docs/SECURITY.md +114 -108
- package/docs/THIRD_PARTY_NOTICES.md +148 -148
- package/env_secrets.py +118 -118
- package/json_store.py +343 -343
- package/logging_setup.py +295 -295
- package/main.py +3433 -3433
- package/mcp_client/client.py +780 -733
- package/mcp_client/config.py +484 -484
- package/mcp_client/registration.py +343 -343
- package/memories/manager.py +147 -147
- package/memories/tui_commands.py +319 -239
- package/package.json +303 -303
- package/project_init/config_files.py +282 -282
- package/project_init/generator.py +728 -728
- package/project_init/manifest.py +418 -418
- package/project_init/tui_commands.py +147 -147
- package/prompts/critic_pass.md +24 -24
- package/prompts/revalidate.md +25 -25
- package/prompts/revise.md +17 -17
- package/prompts/source_grounding.md +66 -66
- package/prompts/system_prompts.py +316 -316
- package/providers.json.example +94 -94
- package/pyproject.toml +149 -149
- package/requirements.txt +314 -295
- package/safety/policy_enforcement.py +1082 -1082
- package/security/askpass.py +419 -419
- package/security/capability.py +207 -207
- package/security/confine.py +484 -484
- package/security/hosted.py +182 -182
- package/security/permissions.py +237 -237
- package/security/protected_paths.py +501 -501
- package/security/sandbox.py +4108 -4108
- package/skills/builtin/math/formal-specification.md +67 -67
- package/skills/builtin/math/numerical-methods.md +66 -66
- package/skills/builtin/research/experiment-design.md +62 -62
- package/skills/builtin/research/reproducibility.md +55 -55
- package/skills/builtin/research/source-evaluation.md +70 -70
- package/skills/builtin/research/statistical-inference.md +63 -63
- package/skills/builtin/research/technical-writing.md +59 -59
- package/skills/builtin/software/code-review.md +61 -61
- package/skills/builtin/software/debugging.md +61 -61
- package/skills/builtin/software/test-design.md +67 -67
- package/skills/tui_commands.py +110 -110
- package/storage.py +1338 -1338
- package/tools/base.py +465 -465
- package/tools/builtin/_math_common.py +667 -667
- package/tools/builtin/_net_common.py +1145 -267
- package/tools/builtin/_page_text.py +490 -0
- package/tools/builtin/_pdf_text.py +113 -0
- package/tools/builtin/arxiv.py +685 -681
- package/tools/builtin/fetch_url.py +639 -371
- package/tools/builtin/file_ops.py +720 -720
- package/tools/builtin/geometry.py +184 -184
- package/tools/builtin/load_skill.py +76 -76
- package/tools/builtin/pin.py +227 -227
- package/tools/builtin/probability_stats.py +224 -224
- package/tools/builtin/project_docs.py +464 -464
- package/tools/builtin/remember.py +175 -175
- package/tools/builtin/shell.py +980 -980
- package/tools/builtin/todo.py +149 -149
- package/tools/builtin/web_search.py +402 -328
- package/tools/context.py +159 -159
- package/tools/isolation.py +387 -387
- package/tools/registry.py +1252 -1242
- package/tui/app.py +8372 -8307
- package/tui/app.tcss +754 -739
- package/tui/commands.py +26 -26
- package/tui/diffs.py +286 -286
- package/tui/history.py +128 -128
- package/tui/hosted_driver.py +102 -102
- package/tui/markdown.py +1329 -1329
- package/tui/meters.py +364 -364
- package/tui/ravens.py +146 -146
- package/tui/screens.py +1255 -1197
- package/tui/themes.py +599 -599
- package/tui/widgets.py +3861 -3796
package/security/capability.py
CHANGED
|
@@ -1,207 +1,207 @@
|
|
|
1
|
-
"""
|
|
2
|
-
security/capability.py
|
|
3
|
-
|
|
4
|
-
ROADMAP_v2 §28. The generic half of the shell approval gate: what a call
|
|
5
|
-
is able to do (`CommandProfile`), what the harness can confine it to
|
|
6
|
-
(`CONTAINED` / `UNCONTAINED` / `UNAVAILABLE`), and the one rule that turns
|
|
7
|
-
those two into "does a human have to say yes".
|
|
8
|
-
|
|
9
|
-
Nothing here knows what a shell command is. That is deliberate (G2):
|
|
10
|
-
`write`, `edit` and MCP tools have the same shape of question -- this call
|
|
11
|
-
can reach these things, and the harness can confine it this far -- and the
|
|
12
|
-
audit found the same defect (#67/#133) twice already by letting each site
|
|
13
|
-
answer it separately. The SHELL-specific part, deciding which capabilities
|
|
14
|
-
a particular command string has, lives in security/sandbox.py.
|
|
15
|
-
|
|
16
|
-
Note the direction of the dependency: sandbox.py imports this module, not
|
|
17
|
-
the other way round. A second producer of profiles must not have to import
|
|
18
|
-
the shell sandbox to describe a file write.
|
|
19
|
-
"""
|
|
20
|
-
|
|
21
|
-
from __future__ import annotations
|
|
22
|
-
|
|
23
|
-
from dataclasses import dataclass
|
|
24
|
-
|
|
25
|
-
# ---------------------------------------------------------------------------
|
|
26
|
-
# ---- Containment ----------------------------------------------------------
|
|
27
|
-
# ---------------------------------------------------------------------------
|
|
28
|
-
|
|
29
|
-
# How far the harness can confine a call it is about to make. Three values,
|
|
30
|
-
# not a boolean, because "cannot run this at all" is a real third answer and
|
|
31
|
-
# it changes what the gate should do: asking about a call that is going to
|
|
32
|
-
# fail regardless burns a turn and teaches the model to retry.
|
|
33
|
-
CONTAINED = "contained" # confined to the workspace (a Docker or Podman container)
|
|
34
|
-
UNCONTAINED = "uncontained" # runs with the user's own authority (host)
|
|
35
|
-
UNAVAILABLE = "unavailable" # no backend can run it
|
|
36
|
-
|
|
37
|
-
# ---------------------------------------------------------------------------
|
|
38
|
-
# ---- Approval modes -------------------------------------------------------
|
|
39
|
-
# ---------------------------------------------------------------------------
|
|
40
|
-
|
|
41
|
-
ALWAYS = "always"
|
|
42
|
-
TIERED = "tiered"
|
|
43
|
-
# §48 (CE2). The pre-§48 `tiered` rule, kept under its own name: anything
|
|
44
|
-
# the container confines and that gets no network runs unasked.
|
|
45
|
-
#
|
|
46
|
-
# NOT called CONTAINED, and the reason is a hazard rather than a style
|
|
47
|
-
# point: `CONTAINED = "contained"` above is a CONTAINMENT value, and the
|
|
48
|
-
# two vocabularies share a spelling. A mode compared against the
|
|
49
|
-
# containment constant would read as correct and match, so the Python
|
|
50
|
-
# names must differ even though the strings cannot.
|
|
51
|
-
CONTAINED_MODE = "contained"
|
|
52
|
-
NEVER = "never"
|
|
53
|
-
|
|
54
|
-
# Strictest first. The order is what validate_mode's message lists, so a
|
|
55
|
-
# reader of the error sees the modes the way config.yaml describes them.
|
|
56
|
-
APPROVAL_MODES = (ALWAYS, TIERED, CONTAINED_MODE, NEVER)
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
def validate_mode(value: str, setting_name: str) -> str:
|
|
60
|
-
"""Return *value*, or raise if it is not an approval mode.
|
|
61
|
-
|
|
62
|
-
Called at IMPORT time by whoever owns the setting, which is D24's
|
|
63
|
-
posture applied to a value rather than a field: a typo in a security
|
|
64
|
-
setting must not be resolved by falling back to a default. The two
|
|
65
|
-
directions a typo can fail are not symmetric -- silently reading
|
|
66
|
-
`"teired"` as anything other than an error either asks about
|
|
67
|
-
everything (annoying, visible) or asks about nothing (catastrophic,
|
|
68
|
-
invisible), and there is no way to pick a default that is safe under
|
|
69
|
-
both readings. So there is no default.
|
|
70
|
-
"""
|
|
71
|
-
if value not in APPROVAL_MODES:
|
|
72
|
-
raise ValueError(
|
|
73
|
-
f"{setting_name} must be one of {', '.join(APPROVAL_MODES)}, "
|
|
74
|
-
f"got {value!r}")
|
|
75
|
-
return value
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
# ---------------------------------------------------------------------------
|
|
79
|
-
# ---- Capability profile ---------------------------------------------------
|
|
80
|
-
# ---------------------------------------------------------------------------
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
@dataclass(frozen=True)
|
|
84
|
-
class CommandProfile:
|
|
85
|
-
"""What one call is able to do, as a capability SET rather than a
|
|
86
|
-
trust level (G1).
|
|
87
|
-
|
|
88
|
-
A linear tier ordering was the obvious design and it is wrong here,
|
|
89
|
-
because it orders harms that are not comparable: `rm -rf /workspace`
|
|
90
|
-
(writes, no network) and `curl https://x` (no writes, network) are
|
|
91
|
-
different harms, not more and less of one thing. Ranking them forces
|
|
92
|
-
an answer to a question nobody asked, and a new dimension later
|
|
93
|
-
renumbers every tier. A set lets policy read exactly the dimension it
|
|
94
|
-
cares about and lets a dimension arrive without touching the others.
|
|
95
|
-
|
|
96
|
-
`tier` survives as a LABEL -- it names the profile for the approval
|
|
97
|
-
prompt and the record, and nothing branches on it. If you find
|
|
98
|
-
yourself writing `if profile.tier == ...` in policy, the field you
|
|
99
|
-
actually wanted is missing.
|
|
100
|
-
|
|
101
|
-
Every field is an UPPER BOUND. `writes` means "not known to be
|
|
102
|
-
read-only", not "will write" -- knowing which would mean parsing the
|
|
103
|
-
command, and refusing to parse is the property that makes the
|
|
104
|
-
classifier sound (G2).
|
|
105
|
-
"""
|
|
106
|
-
|
|
107
|
-
tier: str
|
|
108
|
-
# Whether the classifier could characterise this call AT ALL.
|
|
109
|
-
#
|
|
110
|
-
# A separate dimension from the capabilities, and the one the `tier`
|
|
111
|
-
# label was standing in for: "read-only, nothing leaves the workspace"
|
|
112
|
-
# and "we could not tell" are different claims, and only the first is
|
|
113
|
-
# a reason to skip a human. Without this field the containment
|
|
114
|
-
# argument silently covers the second -- an unmeasurable call inside a
|
|
115
|
-
# network-less container satisfies every capability test by returning
|
|
116
|
-
# False to all of them, which is the vacuity class this audit keeps
|
|
117
|
-
# finding: a check that passes because its input was empty.
|
|
118
|
-
#
|
|
119
|
-
# It is also what batch 9 needs. A model-based classifier's "I am not
|
|
120
|
-
# sure" has to land somewhere that cannot be argued away by
|
|
121
|
-
# containment, and this is that place.
|
|
122
|
-
measured: bool
|
|
123
|
-
# Some argument resolves outside the workspace. Only meaningful where
|
|
124
|
-
# the workspace is the boundary -- under CONTAINED the container's
|
|
125
|
-
# filesystem is not the host's, so this says nothing useful there.
|
|
126
|
-
escapes_workspace: bool
|
|
127
|
-
# Not known to be read-only.
|
|
128
|
-
writes: bool
|
|
129
|
-
# Not known to be free of code execution: the call may run code its own
|
|
130
|
-
# tokens do not show -- an interpreter's `-c`, a script on disk, a
|
|
131
|
-
# Makefile, a test runner's conftest.py (§48, CE7). An UPPER BOUND like
|
|
132
|
-
# every field here, and its own dimension although every shell profile
|
|
133
|
-
# today sets it alike with `writes`: changing a file and running a
|
|
134
|
-
# program are different harms, and a future write/edit profile changes
|
|
135
|
-
# a file without running anything. Required, with no default, so a
|
|
136
|
-
# producer cannot leave it unsaid.
|
|
137
|
-
runs_code: bool
|
|
138
|
-
# The sandbox will GRANT this call network access. One fact for both
|
|
139
|
-
# consumers, deliberately: the executor uses it to decide whether to
|
|
140
|
-
# pass `--network`, and the gate uses it to decide whether to ask.
|
|
141
|
-
# Splitting it into a permissive routing answer and a pessimistic
|
|
142
|
-
# approval answer is exactly the shape of #67/#133 -- sharing the
|
|
143
|
-
# mechanism is not sharing the policy -- inside the module written to
|
|
144
|
-
# close that.
|
|
145
|
-
network: bool
|
|
146
|
-
# Why the classifier said what it said. Shown in the approval prompt,
|
|
147
|
-
# so it is written for the person answering it, not for a log.
|
|
148
|
-
reason: str
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
# ---------------------------------------------------------------------------
|
|
152
|
-
# ---- The rule -------------------------------------------------------------
|
|
153
|
-
# ---------------------------------------------------------------------------
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
def auto_approved(profile: CommandProfile, containment: str) -> bool:
|
|
157
|
-
"""Whether *profile* is covered by *containment* without asking anyone.
|
|
158
|
-
|
|
159
|
-
One branch per containment, rather than one predicate ANDed across
|
|
160
|
-
all of them, because the dimensions that matter genuinely differ:
|
|
161
|
-
|
|
162
|
-
CONTAINED the container bounds the filesystem, so
|
|
163
|
-
`escapes_workspace` says nothing -- `cat /etc/passwd`
|
|
164
|
-
in a container reads the container's. What the
|
|
165
|
-
container does NOT bound is egress, and that is the
|
|
166
|
-
half the pre-§28 gate never looked at (#157 hole 2).
|
|
167
|
-
Nor does it make running code harmless (§48, CE1,
|
|
168
|
-
amending G4, which approved anything contained without
|
|
169
|
-
network): the classifier cannot see what a `-c`, a
|
|
170
|
-
script or a Makefile will do, a protected segment read
|
|
171
|
-
through one carries no token to catch, and code is
|
|
172
|
-
where a way out of the container starts. So
|
|
173
|
-
`runs_code` asks here too.
|
|
174
|
-
|
|
175
|
-
UNCONTAINED nothing is bounded, so everything must be clear: no
|
|
176
|
-
argument leaving the workspace (#157 hole 1), nothing
|
|
177
|
-
that might write, no network.
|
|
178
|
-
|
|
179
|
-
UNAVAILABLE the call cannot run, so it is not covered either.
|
|
180
|
-
Note this is NOT "do not ask": False here means ASK,
|
|
181
|
-
like every other False. A caller that would rather stay
|
|
182
|
-
silent about a call which is going to fail regardless
|
|
183
|
-
has to say so itself -- shell does, and the two
|
|
184
|
-
polarities meeting is worth the one explicit branch
|
|
185
|
-
rather than a second meaning smuggled into this return.
|
|
186
|
-
|
|
187
|
-
`measured` gates all three. A call the classifier could not
|
|
188
|
-
characterise must not be auto-approved by a containment argument,
|
|
189
|
-
because every capability test passes vacuously on a profile that
|
|
190
|
-
knows nothing.
|
|
191
|
-
|
|
192
|
-
This function reads no config and knows about no tool. A caller with
|
|
193
|
-
an explicit documented override applies it before calling here, where
|
|
194
|
-
it is visible, rather than passing a flag in to be honoured out of
|
|
195
|
-
sight. There are two today, both in shell's `_shell_approval_check`:
|
|
196
|
-
`AUTO_APPROVE_SANDBOX_FALLBACK`, and the `contained` approval mode
|
|
197
|
-
(§48, CE2), which is this rule's CONTAINED branch as it read before
|
|
198
|
-
`runs_code` joined it.
|
|
199
|
-
"""
|
|
200
|
-
if not profile.measured:
|
|
201
|
-
return False
|
|
202
|
-
if containment == CONTAINED:
|
|
203
|
-
return not (profile.network or profile.runs_code)
|
|
204
|
-
if containment == UNCONTAINED:
|
|
205
|
-
return not (profile.escapes_workspace or profile.writes
|
|
206
|
-
or profile.runs_code or profile.network)
|
|
207
|
-
return False
|
|
1
|
+
"""
|
|
2
|
+
security/capability.py
|
|
3
|
+
|
|
4
|
+
ROADMAP_v2 §28. The generic half of the shell approval gate: what a call
|
|
5
|
+
is able to do (`CommandProfile`), what the harness can confine it to
|
|
6
|
+
(`CONTAINED` / `UNCONTAINED` / `UNAVAILABLE`), and the one rule that turns
|
|
7
|
+
those two into "does a human have to say yes".
|
|
8
|
+
|
|
9
|
+
Nothing here knows what a shell command is. That is deliberate (G2):
|
|
10
|
+
`write`, `edit` and MCP tools have the same shape of question -- this call
|
|
11
|
+
can reach these things, and the harness can confine it this far -- and the
|
|
12
|
+
audit found the same defect (#67/#133) twice already by letting each site
|
|
13
|
+
answer it separately. The SHELL-specific part, deciding which capabilities
|
|
14
|
+
a particular command string has, lives in security/sandbox.py.
|
|
15
|
+
|
|
16
|
+
Note the direction of the dependency: sandbox.py imports this module, not
|
|
17
|
+
the other way round. A second producer of profiles must not have to import
|
|
18
|
+
the shell sandbox to describe a file write.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
from __future__ import annotations
|
|
22
|
+
|
|
23
|
+
from dataclasses import dataclass
|
|
24
|
+
|
|
25
|
+
# ---------------------------------------------------------------------------
|
|
26
|
+
# ---- Containment ----------------------------------------------------------
|
|
27
|
+
# ---------------------------------------------------------------------------
|
|
28
|
+
|
|
29
|
+
# How far the harness can confine a call it is about to make. Three values,
|
|
30
|
+
# not a boolean, because "cannot run this at all" is a real third answer and
|
|
31
|
+
# it changes what the gate should do: asking about a call that is going to
|
|
32
|
+
# fail regardless burns a turn and teaches the model to retry.
|
|
33
|
+
CONTAINED = "contained" # confined to the workspace (a Docker or Podman container)
|
|
34
|
+
UNCONTAINED = "uncontained" # runs with the user's own authority (host)
|
|
35
|
+
UNAVAILABLE = "unavailable" # no backend can run it
|
|
36
|
+
|
|
37
|
+
# ---------------------------------------------------------------------------
|
|
38
|
+
# ---- Approval modes -------------------------------------------------------
|
|
39
|
+
# ---------------------------------------------------------------------------
|
|
40
|
+
|
|
41
|
+
ALWAYS = "always"
|
|
42
|
+
TIERED = "tiered"
|
|
43
|
+
# §48 (CE2). The pre-§48 `tiered` rule, kept under its own name: anything
|
|
44
|
+
# the container confines and that gets no network runs unasked.
|
|
45
|
+
#
|
|
46
|
+
# NOT called CONTAINED, and the reason is a hazard rather than a style
|
|
47
|
+
# point: `CONTAINED = "contained"` above is a CONTAINMENT value, and the
|
|
48
|
+
# two vocabularies share a spelling. A mode compared against the
|
|
49
|
+
# containment constant would read as correct and match, so the Python
|
|
50
|
+
# names must differ even though the strings cannot.
|
|
51
|
+
CONTAINED_MODE = "contained"
|
|
52
|
+
NEVER = "never"
|
|
53
|
+
|
|
54
|
+
# Strictest first. The order is what validate_mode's message lists, so a
|
|
55
|
+
# reader of the error sees the modes the way config.yaml describes them.
|
|
56
|
+
APPROVAL_MODES = (ALWAYS, TIERED, CONTAINED_MODE, NEVER)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def validate_mode(value: str, setting_name: str) -> str:
|
|
60
|
+
"""Return *value*, or raise if it is not an approval mode.
|
|
61
|
+
|
|
62
|
+
Called at IMPORT time by whoever owns the setting, which is D24's
|
|
63
|
+
posture applied to a value rather than a field: a typo in a security
|
|
64
|
+
setting must not be resolved by falling back to a default. The two
|
|
65
|
+
directions a typo can fail are not symmetric -- silently reading
|
|
66
|
+
`"teired"` as anything other than an error either asks about
|
|
67
|
+
everything (annoying, visible) or asks about nothing (catastrophic,
|
|
68
|
+
invisible), and there is no way to pick a default that is safe under
|
|
69
|
+
both readings. So there is no default.
|
|
70
|
+
"""
|
|
71
|
+
if value not in APPROVAL_MODES:
|
|
72
|
+
raise ValueError(
|
|
73
|
+
f"{setting_name} must be one of {', '.join(APPROVAL_MODES)}, "
|
|
74
|
+
f"got {value!r}")
|
|
75
|
+
return value
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
# ---------------------------------------------------------------------------
|
|
79
|
+
# ---- Capability profile ---------------------------------------------------
|
|
80
|
+
# ---------------------------------------------------------------------------
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
@dataclass(frozen=True)
|
|
84
|
+
class CommandProfile:
|
|
85
|
+
"""What one call is able to do, as a capability SET rather than a
|
|
86
|
+
trust level (G1).
|
|
87
|
+
|
|
88
|
+
A linear tier ordering was the obvious design and it is wrong here,
|
|
89
|
+
because it orders harms that are not comparable: `rm -rf /workspace`
|
|
90
|
+
(writes, no network) and `curl https://x` (no writes, network) are
|
|
91
|
+
different harms, not more and less of one thing. Ranking them forces
|
|
92
|
+
an answer to a question nobody asked, and a new dimension later
|
|
93
|
+
renumbers every tier. A set lets policy read exactly the dimension it
|
|
94
|
+
cares about and lets a dimension arrive without touching the others.
|
|
95
|
+
|
|
96
|
+
`tier` survives as a LABEL -- it names the profile for the approval
|
|
97
|
+
prompt and the record, and nothing branches on it. If you find
|
|
98
|
+
yourself writing `if profile.tier == ...` in policy, the field you
|
|
99
|
+
actually wanted is missing.
|
|
100
|
+
|
|
101
|
+
Every field is an UPPER BOUND. `writes` means "not known to be
|
|
102
|
+
read-only", not "will write" -- knowing which would mean parsing the
|
|
103
|
+
command, and refusing to parse is the property that makes the
|
|
104
|
+
classifier sound (G2).
|
|
105
|
+
"""
|
|
106
|
+
|
|
107
|
+
tier: str
|
|
108
|
+
# Whether the classifier could characterise this call AT ALL.
|
|
109
|
+
#
|
|
110
|
+
# A separate dimension from the capabilities, and the one the `tier`
|
|
111
|
+
# label was standing in for: "read-only, nothing leaves the workspace"
|
|
112
|
+
# and "we could not tell" are different claims, and only the first is
|
|
113
|
+
# a reason to skip a human. Without this field the containment
|
|
114
|
+
# argument silently covers the second -- an unmeasurable call inside a
|
|
115
|
+
# network-less container satisfies every capability test by returning
|
|
116
|
+
# False to all of them, which is the vacuity class this audit keeps
|
|
117
|
+
# finding: a check that passes because its input was empty.
|
|
118
|
+
#
|
|
119
|
+
# It is also what batch 9 needs. A model-based classifier's "I am not
|
|
120
|
+
# sure" has to land somewhere that cannot be argued away by
|
|
121
|
+
# containment, and this is that place.
|
|
122
|
+
measured: bool
|
|
123
|
+
# Some argument resolves outside the workspace. Only meaningful where
|
|
124
|
+
# the workspace is the boundary -- under CONTAINED the container's
|
|
125
|
+
# filesystem is not the host's, so this says nothing useful there.
|
|
126
|
+
escapes_workspace: bool
|
|
127
|
+
# Not known to be read-only.
|
|
128
|
+
writes: bool
|
|
129
|
+
# Not known to be free of code execution: the call may run code its own
|
|
130
|
+
# tokens do not show -- an interpreter's `-c`, a script on disk, a
|
|
131
|
+
# Makefile, a test runner's conftest.py (§48, CE7). An UPPER BOUND like
|
|
132
|
+
# every field here, and its own dimension although every shell profile
|
|
133
|
+
# today sets it alike with `writes`: changing a file and running a
|
|
134
|
+
# program are different harms, and a future write/edit profile changes
|
|
135
|
+
# a file without running anything. Required, with no default, so a
|
|
136
|
+
# producer cannot leave it unsaid.
|
|
137
|
+
runs_code: bool
|
|
138
|
+
# The sandbox will GRANT this call network access. One fact for both
|
|
139
|
+
# consumers, deliberately: the executor uses it to decide whether to
|
|
140
|
+
# pass `--network`, and the gate uses it to decide whether to ask.
|
|
141
|
+
# Splitting it into a permissive routing answer and a pessimistic
|
|
142
|
+
# approval answer is exactly the shape of #67/#133 -- sharing the
|
|
143
|
+
# mechanism is not sharing the policy -- inside the module written to
|
|
144
|
+
# close that.
|
|
145
|
+
network: bool
|
|
146
|
+
# Why the classifier said what it said. Shown in the approval prompt,
|
|
147
|
+
# so it is written for the person answering it, not for a log.
|
|
148
|
+
reason: str
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
# ---------------------------------------------------------------------------
|
|
152
|
+
# ---- The rule -------------------------------------------------------------
|
|
153
|
+
# ---------------------------------------------------------------------------
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def auto_approved(profile: CommandProfile, containment: str) -> bool:
|
|
157
|
+
"""Whether *profile* is covered by *containment* without asking anyone.
|
|
158
|
+
|
|
159
|
+
One branch per containment, rather than one predicate ANDed across
|
|
160
|
+
all of them, because the dimensions that matter genuinely differ:
|
|
161
|
+
|
|
162
|
+
CONTAINED the container bounds the filesystem, so
|
|
163
|
+
`escapes_workspace` says nothing -- `cat /etc/passwd`
|
|
164
|
+
in a container reads the container's. What the
|
|
165
|
+
container does NOT bound is egress, and that is the
|
|
166
|
+
half the pre-§28 gate never looked at (#157 hole 2).
|
|
167
|
+
Nor does it make running code harmless (§48, CE1,
|
|
168
|
+
amending G4, which approved anything contained without
|
|
169
|
+
network): the classifier cannot see what a `-c`, a
|
|
170
|
+
script or a Makefile will do, a protected segment read
|
|
171
|
+
through one carries no token to catch, and code is
|
|
172
|
+
where a way out of the container starts. So
|
|
173
|
+
`runs_code` asks here too.
|
|
174
|
+
|
|
175
|
+
UNCONTAINED nothing is bounded, so everything must be clear: no
|
|
176
|
+
argument leaving the workspace (#157 hole 1), nothing
|
|
177
|
+
that might write, no network.
|
|
178
|
+
|
|
179
|
+
UNAVAILABLE the call cannot run, so it is not covered either.
|
|
180
|
+
Note this is NOT "do not ask": False here means ASK,
|
|
181
|
+
like every other False. A caller that would rather stay
|
|
182
|
+
silent about a call which is going to fail regardless
|
|
183
|
+
has to say so itself -- shell does, and the two
|
|
184
|
+
polarities meeting is worth the one explicit branch
|
|
185
|
+
rather than a second meaning smuggled into this return.
|
|
186
|
+
|
|
187
|
+
`measured` gates all three. A call the classifier could not
|
|
188
|
+
characterise must not be auto-approved by a containment argument,
|
|
189
|
+
because every capability test passes vacuously on a profile that
|
|
190
|
+
knows nothing.
|
|
191
|
+
|
|
192
|
+
This function reads no config and knows about no tool. A caller with
|
|
193
|
+
an explicit documented override applies it before calling here, where
|
|
194
|
+
it is visible, rather than passing a flag in to be honoured out of
|
|
195
|
+
sight. There are two today, both in shell's `_shell_approval_check`:
|
|
196
|
+
`AUTO_APPROVE_SANDBOX_FALLBACK`, and the `contained` approval mode
|
|
197
|
+
(§48, CE2), which is this rule's CONTAINED branch as it read before
|
|
198
|
+
`runs_code` joined it.
|
|
199
|
+
"""
|
|
200
|
+
if not profile.measured:
|
|
201
|
+
return False
|
|
202
|
+
if containment == CONTAINED:
|
|
203
|
+
return not (profile.network or profile.runs_code)
|
|
204
|
+
if containment == UNCONTAINED:
|
|
205
|
+
return not (profile.escapes_workspace or profile.writes
|
|
206
|
+
or profile.runs_code or profile.network)
|
|
207
|
+
return False
|