@yahyahammad/venastine 0.2.0 → 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.
- package/.env.example +9 -4
- package/CONFIG_ARCHITECTURE.md +2030 -0
- package/LICENSE +201 -201
- package/NOTICE +1 -1
- package/README.md +1034 -895
- package/agents/builtin/build.md +73 -0
- package/agents/builtin/compactor.md +75 -75
- package/agents/builtin/explore.md +77 -77
- package/agents/builtin/general.md +80 -0
- package/agents/builtin/pipeline-reviewer.md +100 -100
- package/agents/builtin/plan.md +106 -88
- package/agents/builtin/review.md +74 -74
- package/agents/builtin/test.md +65 -0
- package/agents/builtin/writer.md +67 -0
- package/agents/manager.py +68 -2
- package/agents/subagent_tool.py +472 -238
- package/agents/tui_commands.py +238 -151
- package/bin/venastine.mjs +150 -4
- package/bin/venastine.py +71 -0
- package/cli_commands.py +838 -0
- package/config.py +95 -1198
- package/config.yaml +1103 -0
- package/config_edit.py +1301 -0
- package/config_schema.py +971 -0
- package/config_update.py +749 -0
- package/core/agent_activity.py +256 -118
- package/core/ansi.py +452 -0
- package/core/approval.py +137 -115
- 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 +2715 -1559
- package/core/commands.py +460 -0
- package/core/compaction.py +1735 -971
- package/core/config_loader.py +1982 -1563
- package/core/connect.py +686 -0
- package/core/events.py +123 -61
- package/core/file_mentions.py +280 -0
- package/core/interaction.py +411 -328
- package/core/line_pattern.py +128 -0
- package/core/loop.py +2566 -1490
- package/core/memory.py +482 -370
- package/core/pipeline_models.py +190 -176
- package/core/provider_errors.py +234 -0
- package/core/reasoning/authorization.py +130 -130
- package/core/reasoning/base.py +219 -219
- package/core/reasoning/confidence_scoring.py +484 -468
- package/core/reasoning/events.py +149 -149
- package/core/reasoning/json_retry.py +19 -1
- package/core/reasoning/orchestrator.py +1561 -1382
- package/core/reasoning/output_writer.py +345 -286
- package/core/reasoning/payload_validation.py +524 -398
- package/core/reasoning/pipeline_storage.py +88 -22
- package/core/reasoning/review.py +659 -615
- package/core/reasoning/scholar.py +458 -434
- package/core/reasoning/source_corpus.py +433 -327
- package/core/reasoning/source_scoring.py +855 -855
- package/core/replay.py +315 -183
- 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 +148 -20
- package/database.py +333 -252
- package/{PRIVACY.md → docs/PRIVACY.md} +78 -66
- package/docs/SECURITY.md +108 -0
- package/docs/THIRD_PARTY_NOTICES.md +148 -0
- package/env_secrets.py +50 -9
- package/json_store.py +343 -123
- package/logging_setup.py +295 -185
- package/main.py +3433 -1961
- package/mcp_client/client.py +733 -499
- package/mcp_client/config.py +126 -21
- package/mcp_client/registration.py +343 -182
- package/memories/manager.py +147 -132
- package/memories/tui_commands.py +319 -244
- package/package.json +303 -73
- package/project_init/config_files.py +282 -278
- package/project_init/generator.py +728 -564
- package/project_init/manifest.py +18 -6
- package/project_init/tui_commands.py +147 -144
- package/prompts/critic_pass.md +24 -24
- package/prompts/revalidate.md +25 -25
- package/prompts/revise.md +2 -0
- package/prompts/source_grounding.md +66 -66
- package/prompts/system_prompts.py +316 -262
- package/providers.json.example +4 -2
- package/pyproject.toml +149 -100
- package/requirements.txt +295 -72
- package/safety/policy_enforcement.py +1082 -746
- package/security/askpass.py +419 -0
- package/security/capability.py +207 -177
- package/security/confine.py +484 -0
- package/security/hosted.py +182 -0
- package/security/permissions.py +237 -190
- package/security/posture.py +124 -12
- package/security/protected_paths.py +501 -309
- package/security/sandbox.py +4108 -985
- package/security/secrets.py +855 -0
- 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 -111
- package/storage.py +1338 -1005
- package/tools/base.py +161 -1
- package/tools/builtin/_math_common.py +667 -377
- package/tools/builtin/_net_common.py +225 -19
- package/tools/builtin/arxiv.py +497 -39
- package/tools/builtin/ask_user.py +231 -213
- package/tools/builtin/discrete_math.py +35 -4
- package/tools/builtin/fetch_url.py +371 -153
- package/tools/builtin/file_ops.py +720 -412
- package/tools/builtin/geometry.py +48 -12
- package/tools/builtin/get_time.py +2 -2
- package/tools/builtin/linear_algebra.py +66 -23
- package/tools/builtin/load_skill.py +76 -66
- package/tools/builtin/logic.py +171 -12
- package/tools/builtin/pin.py +227 -193
- package/tools/builtin/probability_stats.py +12 -16
- package/tools/builtin/project_docs.py +464 -405
- package/tools/builtin/remember.py +175 -158
- package/tools/builtin/shell.py +980 -461
- package/tools/builtin/shell_sessions.py +613 -0
- package/tools/builtin/symbolic_math.py +80 -10
- package/tools/builtin/todo.py +149 -147
- package/tools/builtin/web_search.py +191 -13
- package/tools/context.py +159 -136
- package/tools/isolation.py +107 -34
- package/tools/registry.py +1242 -925
- package/tui/app.py +8318 -4100
- package/tui/app.tcss +747 -556
- package/tui/commands.py +26 -170
- package/tui/diffs.py +34 -13
- package/tui/history.py +128 -128
- package/tui/hosted_driver.py +102 -0
- package/tui/markdown.py +1329 -1279
- package/tui/meters.py +364 -268
- package/tui/ravens.py +146 -146
- package/tui/screens.py +1255 -943
- package/tui/themes.py +599 -559
- package/tui/widgets.py +3813 -2332
- package/SECURITY.md +0 -88
- package/THIRD_PARTY_NOTICES.md +0 -100
package/agents/tui_commands.py
CHANGED
|
@@ -1,151 +1,238 @@
|
|
|
1
|
-
"""
|
|
2
|
-
agents/tui_commands.py
|
|
3
|
-
|
|
4
|
-
ROADMAP_v2 §18, D6 user-initiated half: /agent, /goal and /grill-me
|
|
5
|
-
register into §16's slash registry. The shell hosts the commands; this
|
|
6
|
-
section owns them -- the same mechanism-vs-policy split tools/registry.py
|
|
7
|
-
uses for tools. TUI-only for now (CLI stays unchanged per the §18 scope
|
|
8
|
-
decision); the model-initiated half lives in subagent_tool.py and works
|
|
9
|
-
in every shell.
|
|
10
|
-
|
|
11
|
-
Handlers receive the app object from tui.commands.dispatch(); this module
|
|
12
|
-
deliberately does NOT import tui.app, so app.py can import it without a
|
|
13
|
-
cycle.
|
|
14
|
-
"""
|
|
15
|
-
|
|
16
|
-
from
|
|
17
|
-
from
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
agent
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
app.
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
switch
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
if
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
1
|
+
"""
|
|
2
|
+
agents/tui_commands.py
|
|
3
|
+
|
|
4
|
+
ROADMAP_v2 §18, D6 user-initiated half: /agent, /goal and /grill-me
|
|
5
|
+
register into §16's slash registry. The shell hosts the commands; this
|
|
6
|
+
section owns them -- the same mechanism-vs-policy split tools/registry.py
|
|
7
|
+
uses for tools. TUI-only for now (CLI stays unchanged per the §18 scope
|
|
8
|
+
decision); the model-initiated half lives in subagent_tool.py and works
|
|
9
|
+
in every shell.
|
|
10
|
+
|
|
11
|
+
Handlers receive the app object from tui.commands.dispatch(); this module
|
|
12
|
+
deliberately does NOT import tui.app, so app.py can import it without a
|
|
13
|
+
cycle.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from agents.manager import GRILL_ME_TASK, manager
|
|
17
|
+
from tui.commands import bind
|
|
18
|
+
from tui.commands import registry as commands
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def _cmd_agent(app, args: str) -> None:
|
|
22
|
+
"""Session-scoped active agent: subsequent turns run under the
|
|
23
|
+
agent's body, model/provider/max_steps overrides, and ToolContext,
|
|
24
|
+
until /agent default or another switch."""
|
|
25
|
+
if not args:
|
|
26
|
+
current = app.active_agent.name if app.active_agent else "default"
|
|
27
|
+
stops, _ = cycle_stops()
|
|
28
|
+
cycle = (" shift+tab in the prompt steps through "
|
|
29
|
+
f"{' → '.join(_stop_name(stop) for stop in stops)}."
|
|
30
|
+
if len(stops) > 1 else "")
|
|
31
|
+
app._transcript.write_system(
|
|
32
|
+
f"Active agent: {current}. "
|
|
33
|
+
f"Available: {', '.join(manager.names()) or 'none'}. "
|
|
34
|
+
f"/agent <name> to switch, /agent default to clear.{cycle}"
|
|
35
|
+
)
|
|
36
|
+
return
|
|
37
|
+
if args == "default":
|
|
38
|
+
_switch_to(app, None)
|
|
39
|
+
return
|
|
40
|
+
agent = manager.get(args)
|
|
41
|
+
if agent is None:
|
|
42
|
+
app._transcript.write_error(
|
|
43
|
+
f"Unknown agent {args!r}. "
|
|
44
|
+
f"Available: {', '.join(manager.names()) or 'none'}."
|
|
45
|
+
)
|
|
46
|
+
return
|
|
47
|
+
_switch_to(app, agent)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def _switch_to(app, agent) -> None:
|
|
51
|
+
"""Make `agent` the active one, or clear it with None.
|
|
52
|
+
|
|
53
|
+
ONE path for /agent and for shift+tab (ROADMAP_v3 §59), so the two
|
|
54
|
+
cannot differ in what a switch says, re-checks or repaints. A turn
|
|
55
|
+
already running keeps the agent it started with: `agent_turn` reads
|
|
56
|
+
`app.active_agent` once, when the turn begins.
|
|
57
|
+
"""
|
|
58
|
+
app.active_agent = agent
|
|
59
|
+
if agent is None:
|
|
60
|
+
app._transcript.write_system("Active agent cleared — default harness.")
|
|
61
|
+
else:
|
|
62
|
+
app._transcript.write_system(
|
|
63
|
+
f"Active agent: {agent.name} — {agent.description}")
|
|
64
|
+
_note_skills_under_new_context(app)
|
|
65
|
+
_refresh_agent_panel(app)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
# ---------------------------------------------------------------------------
|
|
69
|
+
# ---- shift+tab: the agent cycle (ROADMAP_v3 §59, UI2 / UI3) ----------------
|
|
70
|
+
# ---------------------------------------------------------------------------
|
|
71
|
+
|
|
72
|
+
DEFAULT_STOP = "default"
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def _stop_name(stop) -> str:
|
|
76
|
+
return DEFAULT_STOP if stop is None else stop.name
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def cycle_stops() -> tuple[list, list]:
|
|
80
|
+
"""The stops shift+tab walks, and the configured names it had to skip.
|
|
81
|
+
|
|
82
|
+
The first stop is ALWAYS None, the plain harness (UI6), and the rest
|
|
83
|
+
are `config.AGENT_CYCLE` in its own order. A "default" entry and a
|
|
84
|
+
repeated name add nothing. A name no tier provides is skipped, because
|
|
85
|
+
the user and project tiers are only known at runtime; the caller says
|
|
86
|
+
so. Read at call time, so a test or a /config edit is seen at once.
|
|
87
|
+
"""
|
|
88
|
+
import config
|
|
89
|
+
|
|
90
|
+
stops, missing, seen = [None], [], {DEFAULT_STOP}
|
|
91
|
+
for name in config.AGENT_CYCLE:
|
|
92
|
+
if name in seen:
|
|
93
|
+
continue
|
|
94
|
+
seen.add(name)
|
|
95
|
+
agent = manager.get(name)
|
|
96
|
+
if agent is None:
|
|
97
|
+
missing.append(name)
|
|
98
|
+
else:
|
|
99
|
+
stops.append(agent)
|
|
100
|
+
return stops, missing
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def can_cycle() -> bool:
|
|
104
|
+
"""Whether shift+tab means "next agent" right now: at least one agent
|
|
105
|
+
beside the default. When it does not, the prompt declines the key and
|
|
106
|
+
Textual's reverse focus gets it, as before §59."""
|
|
107
|
+
stops, _ = cycle_stops()
|
|
108
|
+
return len(stops) > 1
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def cycle_agent(app) -> None:
|
|
112
|
+
"""shift+tab in the prompt: switch to the next stop.
|
|
113
|
+
|
|
114
|
+
From an agent the roster does not list (one picked with /agent), the
|
|
115
|
+
next stop is the first one, the default. A cycle has one start, and
|
|
116
|
+
that is the stop a user can always find again.
|
|
117
|
+
"""
|
|
118
|
+
stops, missing = cycle_stops()
|
|
119
|
+
_note_missing(app, missing)
|
|
120
|
+
if len(stops) < 2:
|
|
121
|
+
return
|
|
122
|
+
names = [_stop_name(stop) for stop in stops]
|
|
123
|
+
current = _stop_name(app.active_agent)
|
|
124
|
+
following = (names.index(current) + 1) % len(stops) \
|
|
125
|
+
if current in names else 0
|
|
126
|
+
_switch_to(app, stops[following])
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def _note_missing(app, missing: list) -> None:
|
|
130
|
+
"""Name each skipped roster entry once per session, not once per press.
|
|
131
|
+
Kept on the app, so a new session starts with a clean slate."""
|
|
132
|
+
noted = getattr(app, "_agent_cycle_noted", None)
|
|
133
|
+
if noted is None:
|
|
134
|
+
noted = set()
|
|
135
|
+
app._agent_cycle_noted = noted
|
|
136
|
+
for name in missing:
|
|
137
|
+
if name in noted:
|
|
138
|
+
continue
|
|
139
|
+
noted.add(name)
|
|
140
|
+
app._transcript.write_system(
|
|
141
|
+
f"agent_cycle in config.yaml names {name!r}, which no agent tier "
|
|
142
|
+
"provides here, so shift+tab skips it.")
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def _refresh_agent_panel(app) -> None:
|
|
146
|
+
"""Batch 59: the panel's root row IS the active agent, so a
|
|
147
|
+
switch has to repaint it.
|
|
148
|
+
|
|
149
|
+
getattr rather than a direct call because this module is driven
|
|
150
|
+
against stub apps in tests/test_agents.py that carry a transcript
|
|
151
|
+
and nothing else -- and /agent must not start depending on a
|
|
152
|
+
sidebar widget to do its actual job."""
|
|
153
|
+
refresh = getattr(app, "refresh_agent_panel", None)
|
|
154
|
+
if refresh is not None:
|
|
155
|
+
refresh()
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
def _note_skills_under_new_context(app) -> None:
|
|
159
|
+
"""K2's activation note is computed against the context active at
|
|
160
|
+
activation time; an /agent switch changes the context for every
|
|
161
|
+
subsequent turn, so re-check active skills and say what is now
|
|
162
|
+
denied (review §19-20 f21). Advisory only -- enforcement still
|
|
163
|
+
happens per call via is_tool_allowed."""
|
|
164
|
+
from skills.manager import manager as skill_manager
|
|
165
|
+
|
|
166
|
+
context = (manager.active_context(app.active_agent)
|
|
167
|
+
if app.active_agent is not None else None)
|
|
168
|
+
label = app.active_agent.name if app.active_agent is not None else "default"
|
|
169
|
+
for name in app.active_skills:
|
|
170
|
+
skill = skill_manager.get(name)
|
|
171
|
+
if skill is None:
|
|
172
|
+
continue
|
|
173
|
+
missing = skill_manager.missing_tools(skill, context)
|
|
174
|
+
if missing:
|
|
175
|
+
app._transcript.write_system(
|
|
176
|
+
f"Note: {name} expects {', '.join(missing)}, which are "
|
|
177
|
+
f"not available under agent {label}.")
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
def _cmd_goal(app, args: str) -> None:
|
|
181
|
+
"""Persistent per-thread objective (extra_data). Injected into every
|
|
182
|
+
turn's system prompt in ANY shell; the banner mirrors it here.
|
|
183
|
+
|
|
184
|
+
#113: the read and clear paths go through `app._memory`, NOT
|
|
185
|
+
`app.memory` -- same rule refresh_goal_banner's comment states.
|
|
186
|
+
Constructing a ConversationMemory persists a thread row, so answering
|
|
187
|
+
"there is no goal" (or clearing one on a session that has none) must
|
|
188
|
+
not be what creates the thread. Only SETTING a goal touches
|
|
189
|
+
app.memory: the user is putting state on a thread, so a thread is
|
|
190
|
+
warranted."""
|
|
191
|
+
if args == "clear":
|
|
192
|
+
if app._memory is None:
|
|
193
|
+
app._transcript.write_system("No goal set.")
|
|
194
|
+
else:
|
|
195
|
+
app.memory.set_extra("goal", None)
|
|
196
|
+
app._transcript.write_system("Goal cleared.")
|
|
197
|
+
elif args:
|
|
198
|
+
app.memory.set_extra("goal", args)
|
|
199
|
+
app._transcript.write_system(f"Goal set: {args}")
|
|
200
|
+
else:
|
|
201
|
+
goal = app._memory.extra.get("goal") if app._memory else None
|
|
202
|
+
if goal:
|
|
203
|
+
app._transcript.write_system(f"Current goal: {goal}")
|
|
204
|
+
else:
|
|
205
|
+
app._transcript.write_system(
|
|
206
|
+
"No goal set. /goal <text> to set one, /goal clear to remove.")
|
|
207
|
+
app.refresh_goal_banner()
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
def _cmd_grill(app, args: str) -> None:
|
|
211
|
+
"""One turn in the CURRENT thread under the grill-me agent's system
|
|
212
|
+
prompt -- it reads the live history directly (no digest loss)."""
|
|
213
|
+
if app._busy:
|
|
214
|
+
app._transcript.write_error(
|
|
215
|
+
"Still working — wait for this turn to finish.")
|
|
216
|
+
return
|
|
217
|
+
agent = manager.get("grill-me")
|
|
218
|
+
if agent is None:
|
|
219
|
+
app._transcript.write_error("grill-me agent not found.")
|
|
220
|
+
return
|
|
221
|
+
app._transcript.write_user("/grill-me")
|
|
222
|
+
# run_one_shot owns the WHOLE assembly (#170): the channel, the
|
|
223
|
+
# catalog facts and the run must come from one answer, so nothing is
|
|
224
|
+
# decided here. (Review f19's "no context, deliberately" answered a
|
|
225
|
+
# question §25 R15 replaced -- what matters now is not which policy
|
|
226
|
+
# governs but whether anything can answer, and only the run knows.)
|
|
227
|
+
app.run_one_shot(agent, GRILL_ME_TASK)
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
def register_agent_commands() -> None:
|
|
231
|
+
"""Idempotent — registering by name overwrites, matching §16's
|
|
232
|
+
register_builtin_commands()."""
|
|
233
|
+
for command in (
|
|
234
|
+
bind("agent", _cmd_agent),
|
|
235
|
+
bind("goal", _cmd_goal),
|
|
236
|
+
bind("grill-me", _cmd_grill),
|
|
237
|
+
):
|
|
238
|
+
commands.register(command)
|
package/bin/venastine.mjs
CHANGED
|
@@ -40,6 +40,8 @@ const HERE = path.dirname(fileURLToPath(import.meta.url));
|
|
|
40
40
|
const ROOT = path.dirname(HERE);
|
|
41
41
|
const REQUIREMENTS = path.join(ROOT, 'requirements.txt');
|
|
42
42
|
const MAIN = path.join(ROOT, 'main.py');
|
|
43
|
+
const CONFIG_FILE = path.join(ROOT, 'config.yaml');
|
|
44
|
+
const CONFIG_UPDATE = path.join(ROOT, 'config_update.py');
|
|
43
45
|
|
|
44
46
|
/**
|
|
45
47
|
* ~/.config/venastine ON EVERY PLATFORM, Windows included.
|
|
@@ -52,6 +54,16 @@ const MAIN = path.join(ROOT, 'main.py');
|
|
|
52
54
|
*/
|
|
53
55
|
const CONFIG_HOME = path.join(os.homedir(), '.config', 'venastine');
|
|
54
56
|
|
|
57
|
+
/**
|
|
58
|
+
* Where config_update.py keeps the pristine copy and the user's mirror.
|
|
59
|
+
*
|
|
60
|
+
* Spelled in two languages, so a docs-consistency test holds this against
|
|
61
|
+
* `config_update.STATE_DIRNAME`. Node owns only the two cheap halves -- the
|
|
62
|
+
* post-session copy below, and the doctor lines -- because everything else
|
|
63
|
+
* needs a YAML parser and this file has ZERO dependencies by design.
|
|
64
|
+
*/
|
|
65
|
+
const CONFIG_STATE = path.join(CONFIG_HOME, 'config-state');
|
|
66
|
+
|
|
55
67
|
const MIN_PYTHON = [3, 11];
|
|
56
68
|
|
|
57
69
|
/** Python floor, in the terms the project already states it in (#144). */
|
|
@@ -172,18 +184,36 @@ function isReady(rt) {
|
|
|
172
184
|
return fs.existsSync(rt.stamp) && fs.existsSync(rt.python);
|
|
173
185
|
}
|
|
174
186
|
|
|
175
|
-
|
|
187
|
+
// Non-comment lines in requirements.txt. NOT a count of pins, which is what
|
|
188
|
+
// it was called until batch 140: some lines are ranges (a floor and a
|
|
189
|
+
// ceiling, like `rich`'s), so the screen that said "N pinned packages" was
|
|
190
|
+
// promising something the file does not say. The exact set is in the file
|
|
191
|
+
// the screen names, which is what makes the count enough. (This comment
|
|
192
|
+
// said "2 of the 18" until batch 208, by when it was 4 of 20: a count in
|
|
193
|
+
// prose beside the code that computes it is the copy that drifts.)
|
|
194
|
+
function countRequirements() {
|
|
176
195
|
return fs.readFileSync(REQUIREMENTS, 'utf8')
|
|
177
196
|
.split(/\r?\n/)
|
|
178
197
|
.filter((line) => line.trim() && !line.trim().startsWith('#'))
|
|
179
198
|
.length;
|
|
180
199
|
}
|
|
181
200
|
|
|
201
|
+
// ROADMAP_v3 §88 (A83). The harness runs under this process with the console
|
|
202
|
+
// inherited, and it is the terminal's one reader from then on, so this
|
|
203
|
+
// process stops reading in so many words: rl.close() only ASKS libuv to stop,
|
|
204
|
+
// and on Windows its console reader is a thread whose read in flight cannot
|
|
205
|
+
// be cancelled. pause() is the same request made of the stream itself, and
|
|
206
|
+
// unref() lets nothing about stdin keep this process alive. Measured in a
|
|
207
|
+
// console of its own, five keys typed at the child after the consent all
|
|
208
|
+
// reached it, before this and after it, three runs each: the old shape
|
|
209
|
+
// lost nothing there, and this one loses nothing either.
|
|
182
210
|
function ask(question) {
|
|
183
211
|
return new Promise((resolve) => {
|
|
184
212
|
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
185
213
|
rl.question(question, (answer) => {
|
|
186
214
|
rl.close();
|
|
215
|
+
process.stdin.pause();
|
|
216
|
+
if (typeof process.stdin.unref === 'function') process.stdin.unref();
|
|
187
217
|
resolve(/^y(es)?$/i.test(answer.trim()));
|
|
188
218
|
});
|
|
189
219
|
});
|
|
@@ -193,8 +223,14 @@ function ask(question) {
|
|
|
193
223
|
* Build the Python environment, only ever with the user's say-so.
|
|
194
224
|
*
|
|
195
225
|
* The consent prompt is not ceremony. This is the one action the launcher
|
|
196
|
-
* takes on its own initiative -- it runs a network install of
|
|
197
|
-
*
|
|
226
|
+
* takes on its own initiative -- it runs a network install of everything in
|
|
227
|
+
* requirements.txt -- and the project's own rule for that case is D17/D31:
|
|
228
|
+
*
|
|
229
|
+
* NO COUNT IN THIS SENTENCE, deliberately (batch 140). It said "17
|
|
230
|
+
* pinned distributions" and the file had 22 installable lines when that was
|
|
231
|
+
* measured, 18 now that batch 136 moved the test packages out. The screen
|
|
232
|
+
* below prints the live number; prose that restates a computed value is a
|
|
233
|
+
* second copy of it, and this is the copy that drifted.
|
|
198
234
|
* show what will run and confirm it. That is also why the bootstrap is here
|
|
199
235
|
* and not in an npm `postinstall` hook, where it would run unannounced and be
|
|
200
236
|
* skipped entirely under `--ignore-scripts`.
|
|
@@ -210,7 +246,7 @@ async function ensureRuntime(python, rt, { assumeYes }) {
|
|
|
210
246
|
'Venastine needs a Python environment (first run).\n' +
|
|
211
247
|
` python : ${python.version} (${python.executable})\n` +
|
|
212
248
|
` venv : ${rt.dir}\n` +
|
|
213
|
-
` install : ${
|
|
249
|
+
` install : ${countRequirements()} packages from requirements.txt\n`;
|
|
214
250
|
|
|
215
251
|
if (!assumeYes) {
|
|
216
252
|
if (!process.stdin.isTTY) {
|
|
@@ -255,6 +291,77 @@ function run(cmd, args) {
|
|
|
255
291
|
if (r.status !== 0) throw new Error(`${path.basename(cmd)} ${args[0]} exited ${r.status}`);
|
|
256
292
|
}
|
|
257
293
|
|
|
294
|
+
/**
|
|
295
|
+
* Put the user's own settings back into config.yaml after npm replaced it.
|
|
296
|
+
*
|
|
297
|
+
* npm replaces a package directory WHOLESALE on update -- measured with
|
|
298
|
+
* `npm pack` and two installs into a scratch prefix: an edited
|
|
299
|
+
* `max_tokens: 31337` came back as the shipped `16000`. `config.yaml` ships
|
|
300
|
+
* inside the package (CONFIG_ARCHITECTURE.md locks it to one location for a
|
|
301
|
+
* security reason that this problem does not touch), so without this the
|
|
302
|
+
* update silently discards every value the user set.
|
|
303
|
+
*
|
|
304
|
+
* `config_update.py` owns every decision; this call owns none of them. It
|
|
305
|
+
* runs on every launch and does nothing on almost all of them -- the module
|
|
306
|
+
* imports no first-party code until it has decided there is a merge to do,
|
|
307
|
+
* because `import config_schema` alone costs 294ms of pydantic and ruamel.
|
|
308
|
+
*
|
|
309
|
+
* THE STATUS IS DELIBERATELY UNCHECKED. A configuration-history feature must
|
|
310
|
+
* not be able to stop the harness from starting; the module says so itself by
|
|
311
|
+
* always exiting 0, and this is the other half of that promise.
|
|
312
|
+
*
|
|
313
|
+
* `firstRun` is the one fact Python cannot work out for itself: it is read
|
|
314
|
+
* from the venv stamp BEFORE ensureRuntime() builds it. Without it, an
|
|
315
|
+
* install that was already in use when this feature arrived would have its
|
|
316
|
+
* edited config.yaml recorded as the pristine baseline, and those edits would
|
|
317
|
+
* be lost at the next update instead of preserved by it.
|
|
318
|
+
*/
|
|
319
|
+
function syncConfig(rt, firstRun) {
|
|
320
|
+
try {
|
|
321
|
+
spawnSync(rt.python, [CONFIG_UPDATE, ...(firstRun ? ['--first-run'] : [])], {
|
|
322
|
+
stdio: 'inherit',
|
|
323
|
+
cwd: ROOT,
|
|
324
|
+
windowsHide: true,
|
|
325
|
+
});
|
|
326
|
+
} catch {
|
|
327
|
+
// See above: never fatal.
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Mirror config.yaml AFTER the session, so a /config write survives an update.
|
|
333
|
+
*
|
|
334
|
+
* This is the common upgrade order and the whole feature misses its own case
|
|
335
|
+
* without it: change a setting, exit, `npm update` days later, launch. By
|
|
336
|
+
* then npm has replaced the file, so the only copy of that change is the one
|
|
337
|
+
* taken here. The next launch's mirror is too late.
|
|
338
|
+
*
|
|
339
|
+
* THIS USED TO BE FOUR LINES OF fs.copyFileSync HERE, and they were the one
|
|
340
|
+
* writer not subject to the module's rule 1 ("the mirror is refreshed only
|
|
341
|
+
* when the version still matches"). They copied whenever a `version` file
|
|
342
|
+
* existed -- so a merge that FAILED, which deliberately leaves the version
|
|
343
|
+
* and the mirror untouched so the next launch can retry, was followed at
|
|
344
|
+
* session end by the newly shipped config.yaml being copied over the mirror.
|
|
345
|
+
* The user's settings were then gone from every copy, permanently, and the
|
|
346
|
+
* retry found nothing to restore. The state directory is also global while
|
|
347
|
+
* this file's ROOT is not, so a checkout run overwrote an npm install's
|
|
348
|
+
* mirror with the checkout's own config.yaml.
|
|
349
|
+
*
|
|
350
|
+
* So the decision lives in Python, where it is tested, and this spawns it.
|
|
351
|
+
* An interpreter start at session EXIT costs nothing anybody is waiting for.
|
|
352
|
+
*/
|
|
353
|
+
function mirrorConfig(rt) {
|
|
354
|
+
try {
|
|
355
|
+
spawnSync(rt.python, [CONFIG_UPDATE, '--mirror'], {
|
|
356
|
+
stdio: 'inherit',
|
|
357
|
+
cwd: ROOT,
|
|
358
|
+
windowsHide: true,
|
|
359
|
+
});
|
|
360
|
+
} catch {
|
|
361
|
+
// Never fatal, for syncConfig's reason.
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
258
365
|
/** Walks up from cwd the way dotenv's find_dotenv(usecwd=True) now does. */
|
|
259
366
|
function findEnvFile() {
|
|
260
367
|
let dir = process.cwd();
|
|
@@ -306,6 +413,32 @@ function childEnv() {
|
|
|
306
413
|
return env;
|
|
307
414
|
}
|
|
308
415
|
|
|
416
|
+
/**
|
|
417
|
+
* One line about the config merge, WITHOUT starting Python.
|
|
418
|
+
*
|
|
419
|
+
* --venastine-doctor returns before ensureRuntime(), so there may be no
|
|
420
|
+
* interpreter to ask. Everything here is a plain text file for that reason.
|
|
421
|
+
*/
|
|
422
|
+
function configStateSummary() {
|
|
423
|
+
try {
|
|
424
|
+
// installs.json maps an install directory to its state subdirectory.
|
|
425
|
+
// READ, never recomputed: config_update.py owns that naming, and two
|
|
426
|
+
// languages agreeing about a hash by inspection would fail silently --
|
|
427
|
+
// the mirror would be written where the merge does not look.
|
|
428
|
+
const installs = JSON.parse(
|
|
429
|
+
fs.readFileSync(path.join(CONFIG_STATE, 'installs.json'), 'utf8'));
|
|
430
|
+
const dir = path.join(CONFIG_STATE, installs[fs.realpathSync(ROOT)]);
|
|
431
|
+
const version = fs.readFileSync(path.join(dir, 'version'), 'utf8').trim();
|
|
432
|
+
const record = path.join(dir, 'last-update.txt');
|
|
433
|
+
const last = fs.existsSync(record)
|
|
434
|
+
? `, last merged ${fs.statSync(record).mtime.toISOString().slice(0, 10)}`
|
|
435
|
+
: '';
|
|
436
|
+
return `${dir} (tracking ${version}${last})`;
|
|
437
|
+
} catch {
|
|
438
|
+
return `${CONFIG_STATE} (not tracked yet; the next launch starts it)`;
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
|
|
309
442
|
function doctor(python, rt) {
|
|
310
443
|
const cwd = process.cwd();
|
|
311
444
|
const env = childEnv();
|
|
@@ -325,6 +458,8 @@ function doctor(python, rt) {
|
|
|
325
458
|
` log file : ${env.AGENT_LOG_FILE || path.join(cwd, 'logs', 'app.log')}`,
|
|
326
459
|
` output dir : ${env.AGENT_OUTPUT_DIR || path.join(cwd, 'output')}`,
|
|
327
460
|
` workspace : ${env.AGENT_WORKSPACE || path.join(cwd, 'workspace')}`,
|
|
461
|
+
` config.yaml : ${CONFIG_FILE}`,
|
|
462
|
+
` config state : ${configStateSummary()}`,
|
|
328
463
|
];
|
|
329
464
|
process.stdout.write(lines.join('\n') + '\n');
|
|
330
465
|
}
|
|
@@ -348,7 +483,15 @@ async function main() {
|
|
|
348
483
|
const python = findPython();
|
|
349
484
|
const rt = runtimePaths();
|
|
350
485
|
|
|
486
|
+
// BEFORE ensureRuntime, which is what makes it an answer: "has this install
|
|
487
|
+
// ever been launched?" is the only way to know whether the config.yaml in
|
|
488
|
+
// front of us is pristine or already edited. See syncConfig().
|
|
489
|
+
const firstRun = !isReady(rt);
|
|
490
|
+
|
|
351
491
|
if (wantReinstall) {
|
|
492
|
+
// The venv only. The config state in CONFIG_STATE is the user's own
|
|
493
|
+
// settings history and has nothing to do with a broken environment --
|
|
494
|
+
// removing it here would throw away the edits an update is about to need.
|
|
352
495
|
fs.rmSync(rt.dir, { recursive: true, force: true });
|
|
353
496
|
process.stdout.write(`Removed ${rt.dir}\n`);
|
|
354
497
|
}
|
|
@@ -359,6 +502,7 @@ async function main() {
|
|
|
359
502
|
}
|
|
360
503
|
|
|
361
504
|
await ensureRuntime(python, rt, { assumeYes });
|
|
505
|
+
syncConfig(rt, firstRun);
|
|
362
506
|
|
|
363
507
|
// Let the child own the terminal's interrupt. Without this, Ctrl+C kills
|
|
364
508
|
// the launcher first and the harness loses its chance to shut down.
|
|
@@ -374,6 +518,8 @@ async function main() {
|
|
|
374
518
|
windowsHide: false,
|
|
375
519
|
});
|
|
376
520
|
|
|
521
|
+
mirrorConfig(rt);
|
|
522
|
+
|
|
377
523
|
if (child.error) fail(`Could not start the harness: ${child.error.message}`);
|
|
378
524
|
if (child.signal) process.exit(128 + (os.constants.signals[child.signal] || 0));
|
|
379
525
|
process.exit(child.status ?? 1);
|