@yahyahammad/venastine 0.2.0 → 0.3.8
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 -14
- package/CONFIG_ARCHITECTURE.md +2002 -0
- package/NOTICE +1 -1
- package/README.md +233 -94
- package/agents/builtin/build.md +73 -0
- package/agents/builtin/general.md +80 -0
- package/agents/builtin/plan.md +23 -5
- package/agents/builtin/test.md +65 -0
- package/agents/builtin/writer.md +67 -0
- package/agents/manager.py +261 -195
- package/agents/subagent_tool.py +277 -43
- package/agents/tui_commands.py +7 -12
- package/bin/venastine.mjs +528 -382
- package/bin/venastine.py +71 -0
- package/cli_commands.py +835 -0
- package/config.py +95 -1198
- package/config.yaml +1090 -0
- package/config_edit.py +1301 -0
- package/config_schema.py +966 -0
- package/config_update.py +749 -0
- package/core/agent_activity.py +158 -20
- package/core/ansi.py +452 -0
- package/core/approval.py +27 -5
- package/core/call_view.py +364 -0
- package/core/cancel.py +121 -0
- package/core/chatgpt_auth.py +747 -0
- package/core/claims_view.py +107 -0
- package/core/client.py +1238 -82
- package/core/commands.py +454 -0
- package/core/compaction.py +830 -66
- package/core/config_loader.py +516 -97
- package/core/connect.py +686 -0
- package/core/events.py +68 -6
- package/core/file_mentions.py +280 -0
- package/core/interaction.py +87 -4
- package/core/line_pattern.py +128 -0
- package/core/loop.py +1516 -440
- package/core/memory.py +120 -8
- package/core/pipeline_models.py +23 -9
- package/core/provider_errors.py +234 -0
- package/core/reasoning/confidence_scoring.py +70 -54
- package/core/reasoning/json_retry.py +19 -1
- package/core/reasoning/orchestrator.py +232 -53
- package/core/reasoning/output_writer.py +90 -31
- package/core/reasoning/payload_validation.py +133 -7
- package/core/reasoning/pipeline_storage.py +427 -361
- package/core/reasoning/review.py +659 -615
- package/core/reasoning/scholar.py +38 -14
- package/core/reasoning/source_corpus.py +110 -4
- package/core/replay.py +158 -26
- package/core/session.py +36 -12
- package/core/session_view.py +259 -0
- package/core/session_wake.py +259 -0
- package/core/shell_sessions.py +1553 -0
- package/core/workspace_trust.py +1 -1
- package/credentials.py +308 -180
- package/database.py +82 -1
- package/{PRIVACY.md → docs/PRIVACY.md} +19 -7
- package/docs/SECURITY.md +108 -0
- package/docs/THIRD_PARTY_NOTICES.md +148 -0
- package/env_secrets.py +118 -77
- package/json_store.py +236 -16
- package/logging_setup.py +121 -11
- package/main.py +1671 -199
- package/mcp_client/client.py +257 -23
- package/mcp_client/config.py +484 -379
- package/mcp_client/registration.py +163 -2
- package/memories/manager.py +15 -0
- package/memories/tui_commands.py +7 -12
- package/package.json +234 -4
- package/project_init/config_files.py +4 -0
- package/project_init/generator.py +201 -37
- package/project_init/manifest.py +418 -406
- package/project_init/tui_commands.py +7 -4
- package/prompts/revalidate.md +1 -1
- package/prompts/revise.md +17 -15
- package/prompts/system_prompts.py +64 -10
- package/providers.json.example +94 -92
- package/pyproject.toml +51 -2
- package/requirements.txt +252 -29
- package/safety/policy_enforcement.py +353 -17
- package/security/askpass.py +419 -0
- package/security/capability.py +37 -7
- package/security/confine.py +484 -0
- package/security/hosted.py +182 -0
- package/security/permissions.py +54 -7
- package/security/posture.py +124 -12
- package/security/protected_paths.py +198 -6
- package/security/sandbox.py +3262 -139
- package/security/secrets.py +855 -0
- package/skills/tui_commands.py +3 -4
- package/storage.py +368 -35
- package/tools/base.py +465 -305
- package/tools/builtin/_math_common.py +306 -16
- package/tools/builtin/_net_common.py +267 -61
- package/tools/builtin/arxiv.py +681 -223
- package/tools/builtin/ask_user.py +231 -213
- package/tools/builtin/discrete_math.py +35 -4
- package/tools/builtin/fetch_url.py +239 -21
- package/tools/builtin/file_ops.py +341 -33
- package/tools/builtin/geometry.py +184 -148
- package/tools/builtin/get_time.py +2 -2
- package/tools/builtin/linear_algebra.py +66 -23
- package/tools/builtin/load_skill.py +10 -0
- package/tools/builtin/logic.py +171 -12
- package/tools/builtin/pin.py +46 -12
- package/tools/builtin/probability_stats.py +224 -228
- package/tools/builtin/project_docs.py +80 -21
- package/tools/builtin/remember.py +21 -4
- package/tools/builtin/shell.py +586 -67
- package/tools/builtin/shell_sessions.py +613 -0
- package/tools/builtin/symbolic_math.py +80 -10
- package/tools/builtin/todo.py +5 -3
- package/tools/builtin/web_search.py +329 -151
- package/tools/context.py +23 -0
- package/tools/isolation.py +387 -314
- package/tools/registry.py +347 -30
- package/tui/app.py +4645 -438
- package/tui/app.tcss +185 -2
- package/tui/commands.py +10 -154
- package/tui/diffs.py +286 -265
- package/tui/hosted_driver.py +102 -0
- package/tui/markdown.py +60 -10
- package/tui/meters.py +103 -7
- package/tui/screens.py +346 -92
- package/tui/themes.py +59 -19
- package/tui/widgets.py +1575 -111
- package/SECURITY.md +0 -88
- package/THIRD_PARTY_NOTICES.md +0 -100
package/security/permissions.py
CHANGED
|
@@ -25,14 +25,33 @@ and inverting it would create a cycle the moment tools/context.py grows
|
|
|
25
25
|
an import of its own.
|
|
26
26
|
"""
|
|
27
27
|
|
|
28
|
-
from
|
|
28
|
+
from collections.abc import Iterable
|
|
29
|
+
from typing import TYPE_CHECKING, Optional
|
|
29
30
|
|
|
30
31
|
import config
|
|
32
|
+
from security import hosted
|
|
31
33
|
|
|
32
34
|
if TYPE_CHECKING: # pragma: no cover - typing only, never imported at runtime
|
|
33
35
|
from tools.context import ToolContext
|
|
34
36
|
|
|
35
37
|
|
|
38
|
+
# The tools whose approval is decided by `shell_approval_mode` and nothing
|
|
39
|
+
# else, so they have a `tool_permissions` field and no `tool_approvals` one.
|
|
40
|
+
# `shell` since §28 (G3): a field there was the ratchet, and every answer it
|
|
41
|
+
# could give is one the mode already names. The two background-session start
|
|
42
|
+
# tools since ROADMAP_v3 §49 (SS16), because they run a command through the
|
|
43
|
+
# same gate -- a second switch over it would be G3's ratchet again.
|
|
44
|
+
#
|
|
45
|
+
# A set named here rather than `name == "shell"` inline, so the exemption
|
|
46
|
+
# has one spelling that tests can hold against the registry: an import-time
|
|
47
|
+
# check in tools/registry.py requires every name here to be registered with
|
|
48
|
+
# shell's own approval check, so the exemption cannot outlive the gate it is
|
|
49
|
+
# an exemption FOR.
|
|
50
|
+
APPROVAL_BY_SHELL_MODE = frozenset({"shell", "shell_background",
|
|
51
|
+
"shell_monitor",
|
|
52
|
+
"shell_interactive"})
|
|
53
|
+
|
|
54
|
+
|
|
36
55
|
def _default_for_unknown_tool(tool_name: str) -> bool:
|
|
37
56
|
"""Explicit, named default for tools with no declared field, rather
|
|
38
57
|
than letting getattr's fallback decide by omission.
|
|
@@ -115,6 +134,14 @@ def is_tool_allowed(
|
|
|
115
134
|
permissions = config.ToolPermissions()
|
|
116
135
|
if not getattr(permissions, tool_name, _default_for_unknown_tool(tool_name)):
|
|
117
136
|
return False
|
|
137
|
+
# ROADMAP_v3 §79 (HD4). A shared hosted deployment refuses the tools
|
|
138
|
+
# that reach the container itself, whatever config.yaml says: every
|
|
139
|
+
# visitor shares that container and one Unix user. Second to the global
|
|
140
|
+
# check and before any context, for the same reason that check is
|
|
141
|
+
# first -- no agent or skill may re-enable what this layer refuses.
|
|
142
|
+
# HD11 adds the math tools, unless the bridge verified their confinement.
|
|
143
|
+
if tool_name in hosted.refused_tools():
|
|
144
|
+
return False
|
|
118
145
|
if context is not None and context.allowed_tools is not None:
|
|
119
146
|
return tool_name in context.allowed_tools
|
|
120
147
|
return True
|
|
@@ -153,12 +180,18 @@ def requires_approval(
|
|
|
153
180
|
if context is not None
|
|
154
181
|
else False
|
|
155
182
|
)
|
|
156
|
-
|
|
183
|
+
# bool(), because the signature says so and an override is only typed
|
|
184
|
+
# where a definition is PARSED (§67 A28): a ToolContext built in code
|
|
185
|
+
# with {"web_search": "false"} returned the string 'false' (batch 220,
|
|
186
|
+
# #250). Truthiness is unchanged -- that string still TIGHTENS, which is
|
|
187
|
+
# the ratchet above working, not a leak -- only the type is.
|
|
188
|
+
return bool(tool_level or context_level)
|
|
157
189
|
|
|
158
190
|
|
|
159
191
|
def assert_permissions_declared(tool_names: Iterable[str]) -> None:
|
|
160
|
-
"""D24: every statically registered tool must have a
|
|
161
|
-
|
|
192
|
+
"""D24: every statically registered tool must have a declared permission
|
|
193
|
+
field, and -- with one deliberate exception -- a declared approval
|
|
194
|
+
field. Raises rather than warning, because the failure
|
|
162
195
|
this guards against is invisible at runtime.
|
|
163
196
|
|
|
164
197
|
The precedent is `fetch_url`: registered, documented as working, and
|
|
@@ -170,6 +203,13 @@ def assert_permissions_declared(tool_names: Iterable[str]) -> None:
|
|
|
170
203
|
_default_for_unknown_tool) is exactly what makes it important that
|
|
171
204
|
omission is never accidental for built-in ones.
|
|
172
205
|
|
|
206
|
+
The exception is APPROVAL_BY_SHELL_MODE in approvals: those tools'
|
|
207
|
+
approval is governed solely by `shell_approval_mode`, and a second
|
|
208
|
+
switch there could only force `always` -- exactly what the mode already
|
|
209
|
+
says. A test pins the set as the SOLE exemption, and tools/registry.py
|
|
210
|
+
requires each name in it to carry shell's own approval check, so a
|
|
211
|
+
future omission cannot ride in on it.
|
|
212
|
+
|
|
173
213
|
Dynamically-named `mcp__*` tools are exempt by design; they can never
|
|
174
214
|
have a declared field. Call this after static registration only.
|
|
175
215
|
"""
|
|
@@ -179,12 +219,19 @@ def assert_permissions_declared(tool_names: Iterable[str]) -> None:
|
|
|
179
219
|
name
|
|
180
220
|
for name in tool_names
|
|
181
221
|
if not name.startswith("mcp__")
|
|
182
|
-
and not (hasattr(permissions, name)
|
|
222
|
+
and not (hasattr(permissions, name)
|
|
223
|
+
and (name in APPROVAL_BY_SHELL_MODE
|
|
224
|
+
or hasattr(approvals, name)))
|
|
183
225
|
]
|
|
184
226
|
if missing:
|
|
185
227
|
raise RuntimeError(
|
|
186
228
|
"Tools are registered with no declared permission/approval "
|
|
187
229
|
f"field, so they would be silently denied forever: {sorted(missing)}. "
|
|
188
|
-
"Add a bool field for each to
|
|
189
|
-
"
|
|
230
|
+
"Add a bool field for each to ToolPermissionsModel and -- "
|
|
231
|
+
f"except {sorted(APPROVAL_BY_SHELL_MODE)}, whose approval lives "
|
|
232
|
+
"solely in shell_approval_mode -- to ToolApprovalsModel in "
|
|
233
|
+
"config_schema.py, and a key for each to tool_permissions "
|
|
234
|
+
"(and, with the same exception, tool_approvals) in config.yaml "
|
|
235
|
+
"(ROADMAP_v2 §15, D24). The field names live in Python so this "
|
|
236
|
+
"check stays a build-time one; the values live in the YAML."
|
|
190
237
|
)
|
package/security/posture.py
CHANGED
|
@@ -28,9 +28,11 @@ WHAT THE GUARANTEE IS, AND IS NOT
|
|
|
28
28
|
Stated precisely, because a half-understood control is worse than none
|
|
29
29
|
(UN4). The posture CANNOT be changed by:
|
|
30
30
|
|
|
31
|
-
* any tool call -- nothing writes `config.
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
* any tool call -- nothing writes `config.yaml`, where the values
|
|
32
|
+
live, or `config.py`, which reads them, without an approval prompt:
|
|
33
|
+
both are outside the workspace and `_file_approval_check`
|
|
34
|
+
hard-returns True there. `write` and `edit` are globally denied on
|
|
35
|
+
top of that;
|
|
34
36
|
* `settings.json` at either tier -- the keys are rejected BY NAME, the
|
|
35
37
|
way G7 rejects `shell_approval_mode`, because a project's settings
|
|
36
38
|
beat the user's and arrive with a directory you cloned;
|
|
@@ -50,10 +52,29 @@ ORDERING IS SELF-ENFORCING (UN2)
|
|
|
50
52
|
--------------------------------
|
|
51
53
|
`current()` marks the posture bound. `apply_cli()` raises if folding in
|
|
52
54
|
the command line would now CHANGE it. So a wrong call order in `main.py`
|
|
53
|
-
|
|
54
|
-
matters because the failure mode of getting it wrong is a run that
|
|
55
|
+
would be a LOUD startup failure rather than a silently stale posture --
|
|
56
|
+
which matters because the failure mode of getting it wrong is a run that
|
|
55
57
|
believes it is safer than it is, and that is invisible.
|
|
56
58
|
|
|
59
|
+
AND THAT GUARD IS DORMANT ON EVERY SHIPPED LAUNCH (batch 142).
|
|
60
|
+
`main.py` calls `apply_cli()` with NO ARGUMENTS -- it is the only
|
|
61
|
+
production call -- so `supplied` is always empty, `candidate` always
|
|
62
|
+
equals `_posture`, and `candidate != _posture` is never true. Measured:
|
|
63
|
+
`current()` then `apply_cli()` does not raise, while the control
|
|
64
|
+
`apply_cli(shell_approval_mode="never")` does. There is no live harm and
|
|
65
|
+
that is the same fact as the finding -- with nothing folded in, a
|
|
66
|
+
premature reader reads the right value anyway -- but a reader creeping
|
|
67
|
+
above that line today produces nothing at all.
|
|
68
|
+
|
|
69
|
+
WHAT ENFORCES UN2 TODAY is
|
|
70
|
+
`test_posture.py::test_no_module_reads_the_posture_at_import`, a source
|
|
71
|
+
scan, which is what AGENTS.md names as the pin. The scan covers IMPORT
|
|
72
|
+
time only, not a reader placed inside `main()` above the `apply_cli()`
|
|
73
|
+
call. The guard below becomes live the day the first posture flag
|
|
74
|
+
exists (`--unsafe` is written about in this module and in
|
|
75
|
+
`test_posture.py` as though it did), and `TestApplyCliOrdering` keeps it
|
|
76
|
+
working for that day -- which is why it is kept rather than removed.
|
|
77
|
+
|
|
57
78
|
The predicate is "a change after a read", not "a read", and the
|
|
58
79
|
difference is not a softening. The guard exists to catch *something acted
|
|
59
80
|
on the config-only value*; if the command line produces the posture that
|
|
@@ -68,7 +89,10 @@ Never calling `apply_cli()` at all -- a library import, a bare test --
|
|
|
68
89
|
leaves the config-derived default, which is the safe posture.
|
|
69
90
|
|
|
70
91
|
This module imports `config` and the stdlib and nothing else, per
|
|
71
|
-
ARCHITECTURE's rule for `security/`.
|
|
92
|
+
ARCHITECTURE's rule for `security/`. Note that `config` is now a shim over
|
|
93
|
+
`config.yaml` and so pulls in `ruamel.yaml` and `pydantic` transitively --
|
|
94
|
+
the rule this sentence states is about what `security/` may NAME, and that
|
|
95
|
+
is unchanged: `config` and the stdlib.
|
|
72
96
|
"""
|
|
73
97
|
|
|
74
98
|
from __future__ import annotations
|
|
@@ -76,8 +100,9 @@ from __future__ import annotations
|
|
|
76
100
|
import contextlib
|
|
77
101
|
import dataclasses
|
|
78
102
|
import os
|
|
103
|
+
from collections.abc import Iterator
|
|
79
104
|
from dataclasses import dataclass
|
|
80
|
-
from typing import Any
|
|
105
|
+
from typing import Any
|
|
81
106
|
|
|
82
107
|
import config
|
|
83
108
|
|
|
@@ -95,7 +120,7 @@ class Posture:
|
|
|
95
120
|
legal statement anywhere in the process.
|
|
96
121
|
"""
|
|
97
122
|
|
|
98
|
-
# "always" / "tiered" / "never" -- validated at bind time, so a typo
|
|
123
|
+
# "always" / "tiered" / "contained" / "never" -- validated at bind time, so a typo
|
|
99
124
|
# is a startup failure and never a policy that quietly means
|
|
100
125
|
# something else (the argument capability.validate_mode makes).
|
|
101
126
|
shell_approval_mode: str
|
|
@@ -104,6 +129,19 @@ class Posture:
|
|
|
104
129
|
# records that it is not defended against because it cannot be.
|
|
105
130
|
allow_insecure_fallback: bool
|
|
106
131
|
auto_approve_fallback: bool
|
|
132
|
+
# ROADMAP_v3 §49 slice 3 (SS35). Whether a command may run in WSL at
|
|
133
|
+
# all. Frozen here rather than read live for the reason the whole
|
|
134
|
+
# module exists, and the reason it belongs here rather than beside
|
|
135
|
+
# `wsl_distro` in plain config: a distro NAME decides where a command
|
|
136
|
+
# lands, and this decides whether it may leave the container.
|
|
137
|
+
allow_wsl_backend: bool
|
|
138
|
+
# ROADMAP_v3 §49 slice 4 (SS46). Whether a command may run on the
|
|
139
|
+
# configured remote host at all. Here rather than beside `ssh_host` in
|
|
140
|
+
# plain config for `allow_wsl_backend`'s reason, with one more: the
|
|
141
|
+
# other SSH keys say WHERE a command would land, and this one says
|
|
142
|
+
# whether this machine may run agent commands on a machine it cannot
|
|
143
|
+
# inspect.
|
|
144
|
+
allow_ssh_backend: bool
|
|
107
145
|
# Master switch for pattern-based redaction of what leaves a tool.
|
|
108
146
|
redact_tool_outputs: bool
|
|
109
147
|
# VENASTINE_REDACT_OFF, the per-run weakening of the line above.
|
|
@@ -152,7 +190,24 @@ class Posture:
|
|
|
152
190
|
"SHELL_APPROVAL_MODE is 'never' -- no shell command is "
|
|
153
191
|
"ever asked about, including one that reads outside the "
|
|
154
192
|
"workspace on the host"))
|
|
155
|
-
|
|
193
|
+
elif self.shell_approval_mode == "contained":
|
|
194
|
+
# §48 (CE4). Not a network or host-read weakening -- both still
|
|
195
|
+
# ask -- but anything the container confines runs unasked,
|
|
196
|
+
# including code the agent wrote itself, and in a workspace that
|
|
197
|
+
# holds a `.venastine/` that code can read it.
|
|
198
|
+
reasons.append((
|
|
199
|
+
"shell: contained",
|
|
200
|
+
"SHELL_APPROVAL_MODE is 'contained' -- a command that runs "
|
|
201
|
+
"in the container without network runs without asking, "
|
|
202
|
+
"including code the agent wrote itself; host reads and "
|
|
203
|
+
"network commands still ask"))
|
|
204
|
+
# §48 (CE6). Under "always" the pair is NOT "no ask": the mode check
|
|
205
|
+
# returns before the fallback opt-in is ever read, so every command
|
|
206
|
+
# asks, the host fallback included. Measured, and the badge said
|
|
207
|
+
# otherwise -- so under "always" the pair reports as the fallback
|
|
208
|
+
# alone, which is what it actually is.
|
|
209
|
+
if (self.allow_insecure_fallback and self.auto_approve_fallback
|
|
210
|
+
and self.shell_approval_mode != "always"):
|
|
156
211
|
reasons.append((
|
|
157
212
|
"host shell, no ask",
|
|
158
213
|
"ALLOW_INSECURE_SANDBOX_FALLBACK and "
|
|
@@ -162,9 +217,58 @@ class Posture:
|
|
|
162
217
|
elif self.allow_insecure_fallback:
|
|
163
218
|
reasons.append((
|
|
164
219
|
"host shell fallback",
|
|
165
|
-
"ALLOW_INSECURE_SANDBOX_FALLBACK is on -- if
|
|
166
|
-
"
|
|
167
|
-
"network isolation"))
|
|
220
|
+
"ALLOW_INSECURE_SANDBOX_FALLBACK is on -- if no container "
|
|
221
|
+
"runtime (Docker or Podman) can run the sandbox, commands "
|
|
222
|
+
"run on the host with no filesystem or network isolation"))
|
|
223
|
+
# ROADMAP_v3 §49 slice 3 (SS41). Reported when it is ENABLED rather
|
|
224
|
+
# than when it is used: the badge describes what this process may
|
|
225
|
+
# do, and a user reading it after a WSL command has already run has
|
|
226
|
+
# read it too late. It is its own pair rather than folded into the
|
|
227
|
+
# fallback's, because the two are different weakenings -- the
|
|
228
|
+
# fallback is the host when there is no container, and this is a
|
|
229
|
+
# Linux userland the agent can ask for while one is running.
|
|
230
|
+
if self.allow_wsl_backend:
|
|
231
|
+
# ROADMAP_v3 §49 slice 5b (SS65). The last clause used to read
|
|
232
|
+
# "Only a read-only command inside the workspace runs there
|
|
233
|
+
# without asking" unconditionally, and that is FALSE when the
|
|
234
|
+
# fallback opt-in is on -- measured against the real gate, where
|
|
235
|
+
# `rm -rf /home` on WSL answers asks=False, because WSL is
|
|
236
|
+
# UNCONTAINED and the opt-in sits above the capability rule.
|
|
237
|
+
# A badge that overstates what asks is worse than no badge, and
|
|
238
|
+
# this is §48 (CE6)'s correction applied to a second pair.
|
|
239
|
+
if (self.auto_approve_fallback
|
|
240
|
+
and self.shell_approval_mode not in ("always", "never")):
|
|
241
|
+
asking = ("AUTO_APPROVE_SANDBOX_FALLBACK is on as well, so "
|
|
242
|
+
"NOTHING there asks first -- that opt-in answers "
|
|
243
|
+
"for the whole backend, not only for the host "
|
|
244
|
+
"fallback it is named after. Running as root is "
|
|
245
|
+
"the one exception and always asks")
|
|
246
|
+
else:
|
|
247
|
+
asking = ("Only a read-only command inside the workspace "
|
|
248
|
+
"runs there without asking, and a command that "
|
|
249
|
+
"runs as root always asks")
|
|
250
|
+
reasons.append((
|
|
251
|
+
"wsl backend",
|
|
252
|
+
"ALLOW_WSL_BACKEND is on -- the agent can ask for a command "
|
|
253
|
+
"to run in WSL, which is not a sandbox: it reaches this "
|
|
254
|
+
"harness's own config and authority files, has no memory or "
|
|
255
|
+
"process limits, and can start Windows programs with your "
|
|
256
|
+
"full authority. " + asking))
|
|
257
|
+
# SS55. A THIRD pair, not a widening of the WSL one, because the
|
|
258
|
+
# three weakenings are different: the fallback is the host when
|
|
259
|
+
# there is no container, WSL is a Linux userland beside a running
|
|
260
|
+
# one, and this is a machine that is not this machine at all. A
|
|
261
|
+
# user who reads "uncontained" has to be able to tell which.
|
|
262
|
+
if self.allow_ssh_backend:
|
|
263
|
+
reasons.append((
|
|
264
|
+
"ssh backend",
|
|
265
|
+
"ALLOW_SSH_BACKEND is on -- the agent can ask for a command "
|
|
266
|
+
"to run on the configured remote host, which this harness "
|
|
267
|
+
"cannot inspect: no isolation, no memory or process limits, "
|
|
268
|
+
"and credentials it did not issue. Nothing runs there "
|
|
269
|
+
"without asking you first -- running as root included "
|
|
270
|
+
"(slice 5b) -- and `write` still saves locally while the "
|
|
271
|
+
"shell runs remotely"))
|
|
168
272
|
if not self.redact_tool_outputs:
|
|
169
273
|
reasons.append((
|
|
170
274
|
"no redaction",
|
|
@@ -197,6 +301,8 @@ def _from_config() -> Posture:
|
|
|
197
301
|
shell_approval_mode=config.SHELL_APPROVAL_MODE,
|
|
198
302
|
allow_insecure_fallback=bool(config.ALLOW_INSECURE_SANDBOX_FALLBACK),
|
|
199
303
|
auto_approve_fallback=bool(config.AUTO_APPROVE_SANDBOX_FALLBACK),
|
|
304
|
+
allow_wsl_backend=bool(config.ALLOW_WSL_BACKEND),
|
|
305
|
+
allow_ssh_backend=bool(config.ALLOW_SSH_BACKEND),
|
|
200
306
|
redact_tool_outputs=bool(config.REDACT_TOOL_OUTPUTS),
|
|
201
307
|
redact_off_env=_redact_off_from_env(),
|
|
202
308
|
)
|
|
@@ -261,6 +367,12 @@ def apply_cli(**overrides: Any) -> Posture:
|
|
|
261
367
|
# the read alone would also make `main()` un-callable twice in one
|
|
262
368
|
# interpreter, which the suite does constantly -- and a guard that
|
|
263
369
|
# forces the tests to work around it stops being read as a guard.
|
|
370
|
+
#
|
|
371
|
+
# DORMANT UNTIL THE FIRST POSTURE FLAG EXISTS (batch 142). No shipped
|
|
372
|
+
# launch passes an override, so `supplied` is {} and this cannot
|
|
373
|
+
# fire. The predicate is NOT the thing to revisit -- raising on the
|
|
374
|
+
# read alone was tried and was wrong twice, and the paragraph above
|
|
375
|
+
# is why. See the module docstring for what enforces UN2 meanwhile.
|
|
264
376
|
if _read and candidate != _posture:
|
|
265
377
|
raise RuntimeError(
|
|
266
378
|
"security.posture.apply_cli() would CHANGE the posture after it "
|
|
@@ -66,6 +66,7 @@ from __future__ import annotations
|
|
|
66
66
|
import logging
|
|
67
67
|
import os
|
|
68
68
|
import re
|
|
69
|
+
import stat
|
|
69
70
|
|
|
70
71
|
import config
|
|
71
72
|
import credentials
|
|
@@ -196,7 +197,29 @@ def check_workspace(workspace_dir: str) -> str | None:
|
|
|
196
197
|
The message is written for the person who has to fix it, and names
|
|
197
198
|
both what overlaps and what to do instead: a workspace refusal is
|
|
198
199
|
always a configuration error, never something the model did.
|
|
200
|
+
|
|
201
|
+
AN EMPTY NAME IS REFUSED BEFORE IT IS RESOLVED (TECHNICAL_DEBT 93,
|
|
202
|
+
batch 160), because `os.path.realpath("")` is the LAUNCH DIRECTORY.
|
|
203
|
+
`config_schema._overlay_env` honours a variable that is set at all --
|
|
204
|
+
`if override is not None`, deliberately generic over its table -- so
|
|
205
|
+
`AGENT_WORKSPACE=` made the launch directory the auto-approved
|
|
206
|
+
workspace, and `WORKSPACE_DIR_EXPLICIT`, which reads the variable's
|
|
207
|
+
presence and never its value, made it the project as well. Measured
|
|
208
|
+
in batch 146: `_file_approval_check('write', ...)` answered no-prompt
|
|
209
|
+
for a file in the launch directory. Here rather than in the merge, so
|
|
210
|
+
the merge stays generic and the one place a bad workspace is refused
|
|
211
|
+
stays the one place; `main()` calls this before anything reads the
|
|
212
|
+
workspace or the project.
|
|
199
213
|
"""
|
|
214
|
+
if not workspace_dir or not workspace_dir.strip():
|
|
215
|
+
return (
|
|
216
|
+
"The workspace is an empty path -- AGENT_WORKSPACE is set to an "
|
|
217
|
+
"empty value, or workspace_dir in config.yaml is blank -- and an "
|
|
218
|
+
"empty path resolves to the directory this was launched from, "
|
|
219
|
+
"which would make it the auto-approved workspace and the "
|
|
220
|
+
"project. Unset AGENT_WORKSPACE, or name a directory; the "
|
|
221
|
+
"default is ./workspace."
|
|
222
|
+
)
|
|
200
223
|
workspace_real = os.path.realpath(workspace_dir)
|
|
201
224
|
|
|
202
225
|
for protected, label in critical_paths():
|
|
@@ -219,6 +242,68 @@ def check_workspace(workspace_dir: str) -> str | None:
|
|
|
219
242
|
return None
|
|
220
243
|
|
|
221
244
|
|
|
245
|
+
def check_project(project_path: str) -> str | None:
|
|
246
|
+
"""Why *project_path* may not be the PROJECT, or None (debt item 26).
|
|
247
|
+
|
|
248
|
+
The project is what `config_loader.get_project_path()` resolves, and
|
|
249
|
+
everything downstream follows it: D17 workspace trust, the
|
|
250
|
+
`.venastine/` config tier, `/init`'s destination and `UserMemory`'s
|
|
251
|
+
project scope (WS7, D25/M12). It may not be the harness's own install
|
|
252
|
+
tree.
|
|
253
|
+
|
|
254
|
+
THE DISPARITY THIS CLOSES, and it is why this is a guard rather than a
|
|
255
|
+
convention. Naming that directory was ALREADY refused --
|
|
256
|
+
`check_workspace` above returns a reason for `AGENT_WORKSPACE=<harness
|
|
257
|
+
root>`, and for every non-exempt subfolder of it. But `main()` falls
|
|
258
|
+
back to `os.getcwd()` when nothing names a workspace as the project, so
|
|
259
|
+
launching from a clone reached the same state by saying nothing:
|
|
260
|
+
measured in batch 96 from an owner report and reproduced in batch 107,
|
|
261
|
+
the trust prompt listed the harness's own `AGENTS.md`. The rule was
|
|
262
|
+
enforced when you said it and skipped when you did not.
|
|
263
|
+
|
|
264
|
+
THE MESSAGE NAMES THREE WAYS OUT since batch 111, and used to name two
|
|
265
|
+
and a trap. It said `workspace_dir` in `config.yaml` "is not enough on
|
|
266
|
+
its own" -- true, and no help at all to the person reading it, who had
|
|
267
|
+
just written the directory they meant into the file this refusal is
|
|
268
|
+
about. `workspace_is_project` is the third way (TECHNICAL_DEBT 28), and
|
|
269
|
+
the sentence is now about what to do rather than about what does not
|
|
270
|
+
work.
|
|
271
|
+
|
|
272
|
+
EQUALITY, NOT CONTAINMENT, which is the one place this deliberately
|
|
273
|
+
differs from `check_workspace`. That one is a WRITE boundary and
|
|
274
|
+
refuses anything inside the tree except `workspace/` and `output/`;
|
|
275
|
+
this one answers "is the project the harness", and `<harness>/workspace`
|
|
276
|
+
is a perfectly good project. It is the shipped layout, and it is the
|
|
277
|
+
answer for someone working on the harness itself.
|
|
278
|
+
|
|
279
|
+
A REASON STRING rather than an exception, for `check_workspace`'s
|
|
280
|
+
reason: the caller prints it and exits. REALPATH'D HERE rather than at
|
|
281
|
+
the caller, because `main()`'s implicit branch hands over a bare
|
|
282
|
+
`os.getcwd()` -- and because the realpath is what makes this a question
|
|
283
|
+
about a directory instead of about a spelling. `_relation` compares
|
|
284
|
+
strings, so `<root>/workspace/..` and a Windows path differing only in
|
|
285
|
+
case both read as `disjoint` to it; `os.path.realpath` resolves the
|
|
286
|
+
first on every platform and canonicalises the second on Windows
|
|
287
|
+
(measured, batch 107).
|
|
288
|
+
"""
|
|
289
|
+
root = harness_root()
|
|
290
|
+
if _relation(os.path.realpath(project_path), root) != "equal":
|
|
291
|
+
return None
|
|
292
|
+
return (
|
|
293
|
+
f"The project would be the harness's own install tree ({root}), "
|
|
294
|
+
f"because nothing named a workspace as the project and this was "
|
|
295
|
+
f"launched from there. Workspace trust, .venastine/, /init's "
|
|
296
|
+
f"destination and project-scoped memories all follow the project, "
|
|
297
|
+
f"so the harness would be asked to trust its own AGENTS.md and "
|
|
298
|
+
f"/init would scaffold documentation into its own source. Three "
|
|
299
|
+
f"ways out, any one of them enough: launch from the directory you "
|
|
300
|
+
f"want to work in; set AGENT_WORKSPACE to it; or, if you have "
|
|
301
|
+
f"already written it as workspace_dir in config.yaml, set "
|
|
302
|
+
f"workspace_is_project: true beside it. To work on the harness "
|
|
303
|
+
f"itself, AGENT_WORKSPACE=./workspace."
|
|
304
|
+
)
|
|
305
|
+
|
|
306
|
+
|
|
222
307
|
def readonly_mounts(workspace_real: str) -> list[str]:
|
|
223
308
|
"""Docker `-v` arguments binding every protected path NESTED inside
|
|
224
309
|
*workspace_real* read-only, in the order docker expects them.
|
|
@@ -280,13 +365,24 @@ def readonly_mounts(workspace_real: str) -> list[str]:
|
|
|
280
365
|
# project_docs.py unions this set into its own wider denylist rather than
|
|
281
366
|
# re-spelling the segment.
|
|
282
367
|
#
|
|
368
|
+
# AND ONE COMPARISON, since batch 146 -- `folded_segments` below, because
|
|
369
|
+
# the fact is not the spelling on its own but the spelling together with
|
|
370
|
+
# how a filesystem will match it. Two of the three consumers had their own
|
|
371
|
+
# comparison and only one of them folded case, which is not a thing either
|
|
372
|
+
# file said; it was a thing you could only find by writing `.VENASTINE/`.
|
|
373
|
+
#
|
|
283
374
|
# KNOWN LIMITS, in the house style. The file tools DENY; the shell only
|
|
284
375
|
# ever ASKS, because a token check that learned shell syntax would be a
|
|
285
376
|
# parser whose bugs auto-approve (G2), and an approval prompt leaves the
|
|
286
377
|
# whole command text in front of a human instead. The auto-approved INERT
|
|
287
378
|
# tier executes argv with no shell (§46 EP5), so its tokens ARE its
|
|
288
|
-
# arguments and a token check is sound there; every tier
|
|
289
|
-
# expand a glob or a variable into the segment is asked about
|
|
379
|
+
# arguments and a token check is sound there; under `tiered` every tier
|
|
380
|
+
# that could expand a glob or a variable into the segment is asked about
|
|
381
|
+
# anyway. That sentence was FALSE until §48 (CE1): a contained command was
|
|
382
|
+
# auto-approved, and `cat .ven*/settings.json; true` read the file unasked.
|
|
383
|
+
# Under `contained` and `never` it is still not true -- such a spelling,
|
|
384
|
+
# or code that opens the file, runs unasked; the ro mount stops a write,
|
|
385
|
+
# and the read is recorded in SECURITY.md as documented risk.
|
|
290
386
|
# MCP servers exposing their own file tools are a separate surface this
|
|
291
387
|
# list does not reach, and the user-tier `~/.config/venastine` stays
|
|
292
388
|
# where it always was -- outside a default workspace it is prompt-gated
|
|
@@ -294,16 +390,112 @@ def readonly_mounts(workspace_real: str) -> list[str]:
|
|
|
294
390
|
PROTECTED_SEGMENTS = frozenset({".venastine"})
|
|
295
391
|
|
|
296
392
|
|
|
393
|
+
def hardlinked_segment(resolved_path: str, roots) -> str | None:
|
|
394
|
+
"""The protected segment a HARD LINK at *resolved_path* is a second
|
|
395
|
+
name for, or None (TECHNICAL_DEBT 90, batch 160).
|
|
396
|
+
|
|
397
|
+
`protected_segment` reads a resolved PATH, and a hardlink is not a link
|
|
398
|
+
to anything: `realpath` returns the name it was given and `islink` is
|
|
399
|
+
False, so a second name for `.venastine/settings.json` sitting in the
|
|
400
|
+
workspace read as an ordinary file. A `read` through one served the
|
|
401
|
+
protected file -- measured in batch 146, along with the write half that
|
|
402
|
+
`write_text_atomic` already closed by replacing the name.
|
|
403
|
+
|
|
404
|
+
SAME FILE, NOT SAME NAME: a file with more than one name is compared by
|
|
405
|
+
`(st_dev, st_ino)` against every file under the `.venastine/` of each of
|
|
406
|
+
*roots* -- the project and the workspace, which are the directories that
|
|
407
|
+
tree is read from. Both fields are real on Windows as well as POSIX
|
|
408
|
+
(measured: an NTFS hardlink pair reports `st_nlink == 2` and one file
|
|
409
|
+
id). The two rejected alternatives are why it is this one: enumerating a
|
|
410
|
+
file's other names is per-platform, and refusing every `st_nlink > 1`
|
|
411
|
+
denies ordinary files to protect against a layout the write path
|
|
412
|
+
already handled. A file with one name pays one `stat`.
|
|
413
|
+
|
|
414
|
+
A `.venastine/` elsewhere on the disk is not looked for, so a hardlink
|
|
415
|
+
into some other project's tree is not caught; the deny exists for the
|
|
416
|
+
one this harness reads.
|
|
417
|
+
"""
|
|
418
|
+
try:
|
|
419
|
+
target = os.stat(resolved_path)
|
|
420
|
+
except OSError:
|
|
421
|
+
return None
|
|
422
|
+
if not stat.S_ISREG(target.st_mode) or target.st_nlink < 2:
|
|
423
|
+
return None
|
|
424
|
+
identity = (target.st_dev, target.st_ino)
|
|
425
|
+
for root in roots:
|
|
426
|
+
try:
|
|
427
|
+
entries = os.listdir(root)
|
|
428
|
+
except OSError:
|
|
429
|
+
continue
|
|
430
|
+
for entry in entries:
|
|
431
|
+
if entry.casefold() not in PROTECTED_SEGMENTS_FOLDED:
|
|
432
|
+
continue
|
|
433
|
+
for dirpath, _dirnames, filenames in os.walk(
|
|
434
|
+
os.path.join(root, entry)):
|
|
435
|
+
for name in filenames:
|
|
436
|
+
try:
|
|
437
|
+
other = os.stat(os.path.join(dirpath, name))
|
|
438
|
+
except OSError:
|
|
439
|
+
continue
|
|
440
|
+
if (other.st_dev, other.st_ino) == identity:
|
|
441
|
+
return entry
|
|
442
|
+
return None
|
|
443
|
+
|
|
444
|
+
|
|
445
|
+
def folded_segments(names) -> frozenset:
|
|
446
|
+
"""`names` prepared for the comparison a filesystem will actually make.
|
|
447
|
+
|
|
448
|
+
THE ONE SPELLING OF THE FOLD (batch 146). Both consumers that compare a
|
|
449
|
+
path's segments against a denylist call this -- `protected_segment`
|
|
450
|
+
below and `project_docs._is_readable_doc` -- because the alternative is
|
|
451
|
+
what was there before: two comparisons, one of them case-sensitive, and
|
|
452
|
+
nothing in either file able to say they disagreed.
|
|
453
|
+
|
|
454
|
+
`casefold` rather than `lower`, which is the comparison Python offers
|
|
455
|
+
for "are these the same name to a human"; for ASCII segment names they
|
|
456
|
+
are identical and the difference costs nothing.
|
|
457
|
+
"""
|
|
458
|
+
return frozenset(name.casefold() for name in names)
|
|
459
|
+
|
|
460
|
+
|
|
461
|
+
#: PUBLIC, because `shell.py`'s raw-token branch compares against it too
|
|
462
|
+
#: and a second `folded_segments(PROTECTED_SEGMENTS)` at that module's top
|
|
463
|
+
#: would be one derived value computed twice.
|
|
464
|
+
PROTECTED_SEGMENTS_FOLDED = folded_segments(PROTECTED_SEGMENTS)
|
|
465
|
+
|
|
466
|
+
|
|
297
467
|
def protected_segment(resolved_path: str) -> str | None:
|
|
298
468
|
"""The protected segment *resolved_path* carries, or None.
|
|
299
469
|
|
|
300
470
|
Callers pass a realpath'd path (file_ops' ``resolve_path``, the
|
|
301
471
|
sandbox's ``_within``), so `..` travel and symlinks are already
|
|
302
|
-
collapsed: a link pointing at `.venastine/settings.json` arrives
|
|
303
|
-
|
|
304
|
-
|
|
472
|
+
collapsed: a link pointing at `.venastine/settings.json` arrives here
|
|
473
|
+
as the real thing. Split on both separators because a raw shell token
|
|
474
|
+
may carry either.
|
|
475
|
+
|
|
476
|
+
CASE-FOLDED ON EVERY PLATFORM, and the word "realpath" above is exactly
|
|
477
|
+
why it has to be (batch 146). This used to say that on Windows a
|
|
478
|
+
case-spelled path "arrives here as the real thing" too, and that is
|
|
479
|
+
true only where the path ALREADY EXISTS for realpath to canonicalise --
|
|
480
|
+
which is not the state a `write` is in. With no `.venastine/` yet,
|
|
481
|
+
`.VENASTINE/mcp.json` resolved to itself, carried no known segment, was
|
|
482
|
+
auto-approved, and created the protected directory under the spelling
|
|
483
|
+
the guard did not know. After that realpath canonicalised every later
|
|
484
|
+
path to the ON-DISK name, so BOTH spellings were admitted in that
|
|
485
|
+
project from then on, and the file `config_loader` opens at startup was
|
|
486
|
+
one of them. Measured, including the control: a project whose directory
|
|
487
|
+
was created lowercase refuses both.
|
|
488
|
+
|
|
489
|
+
Folding unconditionally rather than per platform is the fail-closed
|
|
490
|
+
direction and costs what it costs: on a case-SENSITIVE filesystem a
|
|
491
|
+
directory genuinely named `.VENASTINE` is now denied to the file tools
|
|
492
|
+
with no prompt and no override, because for them this list is the hard
|
|
493
|
+
deny rather than a reason to ask. The shell consumer only ever ASKS, so
|
|
494
|
+
there the same fold costs one prompt.
|
|
305
495
|
"""
|
|
306
496
|
for part in re.split(r"[\\/]", resolved_path):
|
|
307
|
-
if part in
|
|
497
|
+
if part.casefold() in PROTECTED_SEGMENTS_FOLDED:
|
|
498
|
+
# The spelling from the PATH, not from the list, so the refusal
|
|
499
|
+
# names what the caller actually wrote.
|
|
308
500
|
return part
|
|
309
501
|
return None
|