@yahyahammad/venastine 0.3.8 → 0.3.9

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 (128) hide show
  1. package/.env.example +19 -19
  2. package/CONFIG_ARCHITECTURE.md +2030 -2002
  3. package/LICENSE +201 -201
  4. package/README.md +1034 -1034
  5. package/agents/builtin/compactor.md +75 -75
  6. package/agents/builtin/explore.md +77 -77
  7. package/agents/builtin/pipeline-reviewer.md +100 -100
  8. package/agents/builtin/plan.md +106 -106
  9. package/agents/builtin/review.md +74 -74
  10. package/agents/manager.py +261 -261
  11. package/agents/subagent_tool.py +472 -472
  12. package/agents/tui_commands.py +238 -146
  13. package/bin/venastine.mjs +528 -528
  14. package/bin/venastine.py +71 -71
  15. package/cli_commands.py +838 -835
  16. package/config.yaml +13 -0
  17. package/config_edit.py +1301 -1301
  18. package/config_schema.py +971 -966
  19. package/config_update.py +749 -749
  20. package/core/agent_activity.py +256 -256
  21. package/core/ansi.py +452 -452
  22. package/core/approval.py +137 -137
  23. package/core/call_view.py +364 -364
  24. package/core/cancel.py +121 -121
  25. package/core/chatgpt_auth.py +747 -747
  26. package/core/claims_view.py +107 -107
  27. package/core/client.py +2715 -2715
  28. package/core/commands.py +460 -454
  29. package/core/compaction.py +1735 -1735
  30. package/core/config_loader.py +1982 -1982
  31. package/core/connect.py +686 -686
  32. package/core/events.py +123 -123
  33. package/core/file_mentions.py +280 -280
  34. package/core/interaction.py +411 -411
  35. package/core/loop.py +2566 -2566
  36. package/core/memory.py +482 -482
  37. package/core/pipeline_models.py +190 -190
  38. package/core/provider_errors.py +234 -234
  39. package/core/reasoning/authorization.py +130 -130
  40. package/core/reasoning/base.py +219 -219
  41. package/core/reasoning/confidence_scoring.py +484 -484
  42. package/core/reasoning/events.py +149 -149
  43. package/core/reasoning/orchestrator.py +1561 -1561
  44. package/core/reasoning/output_writer.py +345 -345
  45. package/core/reasoning/payload_validation.py +524 -524
  46. package/core/reasoning/pipeline_storage.py +427 -427
  47. package/core/reasoning/scholar.py +458 -458
  48. package/core/reasoning/source_corpus.py +433 -433
  49. package/core/reasoning/source_scoring.py +855 -855
  50. package/core/replay.py +315 -315
  51. package/core/shell_sessions.py +1553 -1553
  52. package/credentials.py +307 -307
  53. package/database.py +333 -333
  54. package/docs/PRIVACY.md +78 -78
  55. package/docs/SECURITY.md +108 -108
  56. package/docs/THIRD_PARTY_NOTICES.md +148 -148
  57. package/env_secrets.py +118 -118
  58. package/json_store.py +343 -343
  59. package/logging_setup.py +295 -295
  60. package/main.py +3433 -3433
  61. package/mcp_client/client.py +733 -733
  62. package/mcp_client/config.py +484 -484
  63. package/mcp_client/registration.py +343 -343
  64. package/memories/manager.py +147 -147
  65. package/memories/tui_commands.py +319 -239
  66. package/package.json +303 -303
  67. package/project_init/config_files.py +282 -282
  68. package/project_init/generator.py +728 -728
  69. package/project_init/manifest.py +418 -418
  70. package/project_init/tui_commands.py +147 -147
  71. package/prompts/critic_pass.md +24 -24
  72. package/prompts/revalidate.md +25 -25
  73. package/prompts/revise.md +17 -17
  74. package/prompts/source_grounding.md +66 -66
  75. package/prompts/system_prompts.py +316 -316
  76. package/providers.json.example +94 -94
  77. package/pyproject.toml +149 -149
  78. package/requirements.txt +295 -295
  79. package/safety/policy_enforcement.py +1082 -1082
  80. package/security/askpass.py +419 -419
  81. package/security/capability.py +207 -207
  82. package/security/confine.py +484 -484
  83. package/security/hosted.py +182 -182
  84. package/security/permissions.py +237 -237
  85. package/security/protected_paths.py +501 -501
  86. package/security/sandbox.py +4108 -4108
  87. package/skills/builtin/math/formal-specification.md +67 -67
  88. package/skills/builtin/math/numerical-methods.md +66 -66
  89. package/skills/builtin/research/experiment-design.md +62 -62
  90. package/skills/builtin/research/reproducibility.md +55 -55
  91. package/skills/builtin/research/source-evaluation.md +70 -70
  92. package/skills/builtin/research/statistical-inference.md +63 -63
  93. package/skills/builtin/research/technical-writing.md +59 -59
  94. package/skills/builtin/software/code-review.md +61 -61
  95. package/skills/builtin/software/debugging.md +61 -61
  96. package/skills/builtin/software/test-design.md +67 -67
  97. package/skills/tui_commands.py +110 -110
  98. package/storage.py +1338 -1338
  99. package/tools/base.py +465 -465
  100. package/tools/builtin/_math_common.py +667 -667
  101. package/tools/builtin/_net_common.py +267 -267
  102. package/tools/builtin/arxiv.py +681 -681
  103. package/tools/builtin/fetch_url.py +371 -371
  104. package/tools/builtin/file_ops.py +720 -720
  105. package/tools/builtin/geometry.py +184 -184
  106. package/tools/builtin/load_skill.py +76 -76
  107. package/tools/builtin/pin.py +227 -227
  108. package/tools/builtin/probability_stats.py +224 -224
  109. package/tools/builtin/project_docs.py +464 -464
  110. package/tools/builtin/remember.py +175 -175
  111. package/tools/builtin/shell.py +980 -980
  112. package/tools/builtin/todo.py +149 -149
  113. package/tools/builtin/web_search.py +328 -328
  114. package/tools/context.py +159 -159
  115. package/tools/isolation.py +387 -387
  116. package/tools/registry.py +1242 -1242
  117. package/tui/app.py +8318 -8307
  118. package/tui/app.tcss +747 -739
  119. package/tui/commands.py +26 -26
  120. package/tui/diffs.py +286 -286
  121. package/tui/history.py +128 -128
  122. package/tui/hosted_driver.py +102 -102
  123. package/tui/markdown.py +1329 -1329
  124. package/tui/meters.py +364 -364
  125. package/tui/ravens.py +146 -146
  126. package/tui/screens.py +1255 -1197
  127. package/tui/themes.py +599 -599
  128. package/tui/widgets.py +3813 -3796
@@ -1,182 +1,182 @@
1
- """
2
- security/hosted.py
3
-
4
- ROADMAP_v3 §79 (HD4, HD6, HD13). What a hosted deployment changes inside the
5
- harness, and nothing else: the mode it runs in, the tools a shared deployment
6
- refuses whatever `config.yaml` says, the sign-ins its bridge completes, and
7
- the hardening calls a hosted process makes about itself.
8
-
9
- THE MODE COMES FROM THE REAL ENVIRONMENT, ONCE, AT IMPORT. The web bridge
10
- (`deploy/hosted/`) starts every session's process with `VENASTINE_HOSTED`
11
- set, and nothing else does. A `.env` cannot supply it (A70: `VENASTINE_*`
12
- names are never taken from that file, and the file is never loaded into the
13
- environment at all). It is bound at import for `security/posture.py`'s
14
- reason: a value read at call time follows a mutation, and this one decides
15
- what a visitor may do.
16
-
17
- AN ENVIRONMENT VARIABLE CAN ONLY TAKE CAPABILITY AWAY HERE, which is why
18
- having one does not contradict `posture.py`'s "there is none, by design".
19
- Unset is a local install. `single-user` is a local install that says it is
20
- hosted. `shared` removes things. And anything the parser does not recognise
21
- is `shared`: a typo must land on the restrictive side, because the bridge
22
- that sets this is the only thing standing between a visitor and the
23
- container.
24
- """
25
-
26
- import ctypes
27
- import os
28
- import signal
29
- import sys
30
-
31
- OFF = ""
32
- SHARED = "shared"
33
- SINGLE_USER = "single-user"
34
-
35
- # HD4. The tools that reach the container itself -- its files and its
36
- # processes. A shared deployment runs every visitor in one container as one
37
- # Unix user, so any of these would let one visitor read another's session.
38
- # They ship disabled anyway; this is the second layer, for the deployment
39
- # whose config.yaml says otherwise.
40
- SHARED_REFUSED_TOOLS = frozenset({
41
- "read", "write", "edit",
42
- # Batch 174: an image file, read under `read`'s rules (§81, IM1).
43
- "view_image",
44
- "shell", "shell_background", "shell_monitor", "shell_interactive",
45
- "shell_input", "shell_sessions", "shell_output", "shell_kill",
46
- })
47
-
48
-
49
- # HD11. The tools whose child evaluates what the model sent: SymPy's parser
50
- # ends in `eval`. A shared deployment runs them only inside the walls
51
- # security/confine.py puts up, and only once the bridge's self-test has
52
- # shown those walls standing on this host -- `VENASTINE_CONFINEMENT` is set
53
- # to `verified` by the bridge after a clean pass, and by nothing else.
54
- # Unset, they are refused like the tools above. (These are exactly the
55
- # registry's BUDGET_COMPUTE tools; a test pins that.)
56
- CONFINED_TOOLS = frozenset({
57
- "symbolic_math", "linear_algebra", "probability_stats",
58
- "discrete_math", "logic", "geometry",
59
- })
60
- CONFINEMENT_VERIFIED = "verified"
61
-
62
-
63
- def _mode_from_env() -> str:
64
- raw = os.environ.get("VENASTINE_HOSTED", "").strip().lower()
65
- if not raw:
66
- return OFF
67
- if raw == SINGLE_USER:
68
- return SINGLE_USER
69
- return SHARED
70
-
71
-
72
- MODE = _mode_from_env()
73
- # Bound at import for MODE's reason. Only a value the bridge set counts.
74
- CONFINEMENT = os.environ.get("VENASTINE_CONFINEMENT", "").strip()
75
-
76
- # HD13. The sign-ins the BRIDGE completes for this session -- ModelScope's,
77
- # on modelscope.ai and on modelscope.cn (batch 176), whose apps each need a
78
- # client secret that only the bridge holds. The names are
79
- # deploy/hosted/sign_in.py's SITES, which this layer does not import;
80
- # test_hosted_mode.py holds the two together. Bound at import for MODE's
81
- # reason, and honoured only in a hosted session: the bridge sets it when it
82
- # can finish the sign-in, and a local install has no bridge to finish it,
83
- # however this variable reads.
84
- BRIDGE_SIGN_IN_NAMES = frozenset({"modelscope", "modelscope-cn"})
85
-
86
-
87
- def _bridge_sign_ins_from_env() -> frozenset:
88
- if MODE == OFF:
89
- return frozenset()
90
- raw = os.environ.get("VENASTINE_BRIDGE_SIGN_IN", "")
91
- return frozenset(name.strip().lower() for name in raw.split(",")) \
92
- & BRIDGE_SIGN_IN_NAMES
93
-
94
-
95
- BRIDGE_SIGN_INS = _bridge_sign_ins_from_env()
96
-
97
-
98
- def mode() -> str:
99
- return MODE
100
-
101
-
102
- def refused_tools() -> frozenset:
103
- """What this deployment refuses whatever config.yaml says: nothing
104
- unless it is shared; then the container tools always, and the math
105
- tools unless their confinement was verified on this host (HD4, HD11)."""
106
- if MODE != SHARED:
107
- return frozenset()
108
- if CONFINEMENT == CONFINEMENT_VERIFIED:
109
- return SHARED_REFUSED_TOOLS
110
- return SHARED_REFUSED_TOOLS | CONFINED_TOOLS
111
-
112
-
113
- def is_hosted() -> bool:
114
- return MODE != OFF
115
-
116
-
117
- def is_shared() -> bool:
118
- return MODE == SHARED
119
-
120
-
121
- def bridge_signs_in(name: str) -> bool:
122
- """Whether this session's bridge completes `name`'s sign-in (HD13)."""
123
- return name in BRIDGE_SIGN_INS
124
-
125
-
126
- def make_undumpable() -> bool:
127
- """Mark this process non-dumpable, so other processes of the same user
128
- cannot read its memory or environment (HD6). True when it took effect.
129
-
130
- `prctl(PR_SET_DUMPABLE, 0)`: the kernel then hands `/proc/<pid>/mem`,
131
- `/proc/<pid>/environ` and the rest to root and refuses a debugger
132
- attach without CAP_SYS_PTRACE. Measured under WSL before it was relied
133
- on: a sibling process read an ordinary process's environ, secret
134
- included, and was refused the same read once the target had made this
135
- call. It is per PROCESS and an exec resets it, which is why the session
136
- makes it itself, first thing, rather than the bridge making it for the
137
- child.
138
-
139
- Linux only, and never raises: off Linux there is no shared container to
140
- protect, and a hosted session that cannot harden itself still runs --
141
- the bridge's own isolation is the first line, and this is the second.
142
- """
143
- if not sys.platform.startswith("linux"):
144
- return False
145
- try:
146
- libc = ctypes.CDLL(None, use_errno=True)
147
- return libc.prctl(4, 0, 0, 0, 0) == 0 # PR_SET_DUMPABLE == 4
148
- except (OSError, AttributeError):
149
- return False
150
-
151
-
152
- def die_with_parent() -> bool:
153
- """Ask the kernel for SIGTERM when the bridge that started this session
154
- goes away (HD8). True when it took effect.
155
-
156
- The bridge starts every session in a NEW process group, so that stopping
157
- one reaches what it started; the cost is that a signal to the bridge
158
- reaches no session. Measured 2026-10-20 under WSL: a SIGTERM to the
159
- bridge left the open session running, orphaned, with its directory, and
160
- nothing would ever have stopped it -- it holds a visitor's key in memory
161
- and counts against the container's. `prctl(PR_SET_PDEATHSIG)` closes
162
- that, in the session, because like PR_SET_DUMPABLE it does not survive
163
- the exec that starts one.
164
-
165
- The signal comes when the THREAD that forked this process exits; the
166
- bridge spawns from its event loop's thread, which lives as long as the
167
- server does. If the bridge died before this call, the signal is already
168
- missed, so a changed parent pid ends the session here instead.
169
-
170
- Linux only, and never raises, for make_undumpable's reasons.
171
- """
172
- if not sys.platform.startswith("linux"):
173
- return False
174
- parent = os.getppid()
175
- try:
176
- libc = ctypes.CDLL(None, use_errno=True)
177
- ok = libc.prctl(1, int(signal.SIGTERM), 0, 0, 0) == 0 # PR_SET_PDEATHSIG == 1
178
- except (OSError, AttributeError):
179
- return False
180
- if ok and os.getppid() != parent:
181
- os.kill(os.getpid(), signal.SIGTERM)
182
- return ok
1
+ """
2
+ security/hosted.py
3
+
4
+ ROADMAP_v3 §79 (HD4, HD6, HD13). What a hosted deployment changes inside the
5
+ harness, and nothing else: the mode it runs in, the tools a shared deployment
6
+ refuses whatever `config.yaml` says, the sign-ins its bridge completes, and
7
+ the hardening calls a hosted process makes about itself.
8
+
9
+ THE MODE COMES FROM THE REAL ENVIRONMENT, ONCE, AT IMPORT. The web bridge
10
+ (`deploy/hosted/`) starts every session's process with `VENASTINE_HOSTED`
11
+ set, and nothing else does. A `.env` cannot supply it (A70: `VENASTINE_*`
12
+ names are never taken from that file, and the file is never loaded into the
13
+ environment at all). It is bound at import for `security/posture.py`'s
14
+ reason: a value read at call time follows a mutation, and this one decides
15
+ what a visitor may do.
16
+
17
+ AN ENVIRONMENT VARIABLE CAN ONLY TAKE CAPABILITY AWAY HERE, which is why
18
+ having one does not contradict `posture.py`'s "there is none, by design".
19
+ Unset is a local install. `single-user` is a local install that says it is
20
+ hosted. `shared` removes things. And anything the parser does not recognise
21
+ is `shared`: a typo must land on the restrictive side, because the bridge
22
+ that sets this is the only thing standing between a visitor and the
23
+ container.
24
+ """
25
+
26
+ import ctypes
27
+ import os
28
+ import signal
29
+ import sys
30
+
31
+ OFF = ""
32
+ SHARED = "shared"
33
+ SINGLE_USER = "single-user"
34
+
35
+ # HD4. The tools that reach the container itself -- its files and its
36
+ # processes. A shared deployment runs every visitor in one container as one
37
+ # Unix user, so any of these would let one visitor read another's session.
38
+ # They ship disabled anyway; this is the second layer, for the deployment
39
+ # whose config.yaml says otherwise.
40
+ SHARED_REFUSED_TOOLS = frozenset({
41
+ "read", "write", "edit",
42
+ # Batch 174: an image file, read under `read`'s rules (§81, IM1).
43
+ "view_image",
44
+ "shell", "shell_background", "shell_monitor", "shell_interactive",
45
+ "shell_input", "shell_sessions", "shell_output", "shell_kill",
46
+ })
47
+
48
+
49
+ # HD11. The tools whose child evaluates what the model sent: SymPy's parser
50
+ # ends in `eval`. A shared deployment runs them only inside the walls
51
+ # security/confine.py puts up, and only once the bridge's self-test has
52
+ # shown those walls standing on this host -- `VENASTINE_CONFINEMENT` is set
53
+ # to `verified` by the bridge after a clean pass, and by nothing else.
54
+ # Unset, they are refused like the tools above. (These are exactly the
55
+ # registry's BUDGET_COMPUTE tools; a test pins that.)
56
+ CONFINED_TOOLS = frozenset({
57
+ "symbolic_math", "linear_algebra", "probability_stats",
58
+ "discrete_math", "logic", "geometry",
59
+ })
60
+ CONFINEMENT_VERIFIED = "verified"
61
+
62
+
63
+ def _mode_from_env() -> str:
64
+ raw = os.environ.get("VENASTINE_HOSTED", "").strip().lower()
65
+ if not raw:
66
+ return OFF
67
+ if raw == SINGLE_USER:
68
+ return SINGLE_USER
69
+ return SHARED
70
+
71
+
72
+ MODE = _mode_from_env()
73
+ # Bound at import for MODE's reason. Only a value the bridge set counts.
74
+ CONFINEMENT = os.environ.get("VENASTINE_CONFINEMENT", "").strip()
75
+
76
+ # HD13. The sign-ins the BRIDGE completes for this session -- ModelScope's,
77
+ # on modelscope.ai and on modelscope.cn (batch 176), whose apps each need a
78
+ # client secret that only the bridge holds. The names are
79
+ # deploy/hosted/sign_in.py's SITES, which this layer does not import;
80
+ # test_hosted_mode.py holds the two together. Bound at import for MODE's
81
+ # reason, and honoured only in a hosted session: the bridge sets it when it
82
+ # can finish the sign-in, and a local install has no bridge to finish it,
83
+ # however this variable reads.
84
+ BRIDGE_SIGN_IN_NAMES = frozenset({"modelscope", "modelscope-cn"})
85
+
86
+
87
+ def _bridge_sign_ins_from_env() -> frozenset:
88
+ if MODE == OFF:
89
+ return frozenset()
90
+ raw = os.environ.get("VENASTINE_BRIDGE_SIGN_IN", "")
91
+ return frozenset(name.strip().lower() for name in raw.split(",")) \
92
+ & BRIDGE_SIGN_IN_NAMES
93
+
94
+
95
+ BRIDGE_SIGN_INS = _bridge_sign_ins_from_env()
96
+
97
+
98
+ def mode() -> str:
99
+ return MODE
100
+
101
+
102
+ def refused_tools() -> frozenset:
103
+ """What this deployment refuses whatever config.yaml says: nothing
104
+ unless it is shared; then the container tools always, and the math
105
+ tools unless their confinement was verified on this host (HD4, HD11)."""
106
+ if MODE != SHARED:
107
+ return frozenset()
108
+ if CONFINEMENT == CONFINEMENT_VERIFIED:
109
+ return SHARED_REFUSED_TOOLS
110
+ return SHARED_REFUSED_TOOLS | CONFINED_TOOLS
111
+
112
+
113
+ def is_hosted() -> bool:
114
+ return MODE != OFF
115
+
116
+
117
+ def is_shared() -> bool:
118
+ return MODE == SHARED
119
+
120
+
121
+ def bridge_signs_in(name: str) -> bool:
122
+ """Whether this session's bridge completes `name`'s sign-in (HD13)."""
123
+ return name in BRIDGE_SIGN_INS
124
+
125
+
126
+ def make_undumpable() -> bool:
127
+ """Mark this process non-dumpable, so other processes of the same user
128
+ cannot read its memory or environment (HD6). True when it took effect.
129
+
130
+ `prctl(PR_SET_DUMPABLE, 0)`: the kernel then hands `/proc/<pid>/mem`,
131
+ `/proc/<pid>/environ` and the rest to root and refuses a debugger
132
+ attach without CAP_SYS_PTRACE. Measured under WSL before it was relied
133
+ on: a sibling process read an ordinary process's environ, secret
134
+ included, and was refused the same read once the target had made this
135
+ call. It is per PROCESS and an exec resets it, which is why the session
136
+ makes it itself, first thing, rather than the bridge making it for the
137
+ child.
138
+
139
+ Linux only, and never raises: off Linux there is no shared container to
140
+ protect, and a hosted session that cannot harden itself still runs --
141
+ the bridge's own isolation is the first line, and this is the second.
142
+ """
143
+ if not sys.platform.startswith("linux"):
144
+ return False
145
+ try:
146
+ libc = ctypes.CDLL(None, use_errno=True)
147
+ return libc.prctl(4, 0, 0, 0, 0) == 0 # PR_SET_DUMPABLE == 4
148
+ except (OSError, AttributeError):
149
+ return False
150
+
151
+
152
+ def die_with_parent() -> bool:
153
+ """Ask the kernel for SIGTERM when the bridge that started this session
154
+ goes away (HD8). True when it took effect.
155
+
156
+ The bridge starts every session in a NEW process group, so that stopping
157
+ one reaches what it started; the cost is that a signal to the bridge
158
+ reaches no session. Measured 2026-10-20 under WSL: a SIGTERM to the
159
+ bridge left the open session running, orphaned, with its directory, and
160
+ nothing would ever have stopped it -- it holds a visitor's key in memory
161
+ and counts against the container's. `prctl(PR_SET_PDEATHSIG)` closes
162
+ that, in the session, because like PR_SET_DUMPABLE it does not survive
163
+ the exec that starts one.
164
+
165
+ The signal comes when the THREAD that forked this process exits; the
166
+ bridge spawns from its event loop's thread, which lives as long as the
167
+ server does. If the bridge died before this call, the signal is already
168
+ missed, so a changed parent pid ends the session here instead.
169
+
170
+ Linux only, and never raises, for make_undumpable's reasons.
171
+ """
172
+ if not sys.platform.startswith("linux"):
173
+ return False
174
+ parent = os.getppid()
175
+ try:
176
+ libc = ctypes.CDLL(None, use_errno=True)
177
+ ok = libc.prctl(1, int(signal.SIGTERM), 0, 0, 0) == 0 # PR_SET_PDEATHSIG == 1
178
+ except (OSError, AttributeError):
179
+ return False
180
+ if ok and os.getppid() != parent:
181
+ os.kill(os.getpid(), signal.SIGTERM)
182
+ return ok