@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/core/workspace_trust.py
CHANGED
|
@@ -173,7 +173,7 @@ def _load_trust_store() -> dict:
|
|
|
173
173
|
if not os.path.exists(path):
|
|
174
174
|
return {}
|
|
175
175
|
try:
|
|
176
|
-
with open(path,
|
|
176
|
+
with open(path, encoding="utf-8-sig") as f:
|
|
177
177
|
data = json.load(f)
|
|
178
178
|
except (OSError, ValueError):
|
|
179
179
|
return {}
|
package/credentials.py
CHANGED
|
@@ -1,180 +1,308 @@
|
|
|
1
|
-
import json
|
|
2
|
-
import os
|
|
3
|
-
|
|
4
|
-
#
|
|
5
|
-
#
|
|
6
|
-
#
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
#
|
|
10
|
-
#
|
|
11
|
-
#
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
1
|
+
import json
|
|
2
|
+
import os
|
|
3
|
+
|
|
4
|
+
# A root module importing a root module: no new edge, and json_store.py's
|
|
5
|
+
# docstring names `credentials` among the things already imported from
|
|
6
|
+
# everywhere for that reason.
|
|
7
|
+
from json_store import write_json_atomic
|
|
8
|
+
|
|
9
|
+
# #24. Resolved at IMPORT time, exactly like its four siblings --
|
|
10
|
+
# config.DB_PATH / OUTPUT_DIR / WORKSPACE_DIR and logging_setup's log
|
|
11
|
+
# file are all `os.environ.get(NAME, default)` evaluated once -- so a
|
|
12
|
+
# test can still redirect it by monkeypatching the attribute, and a
|
|
13
|
+
# user can point it anywhere with AGENT_PROVIDERS_FILE before launch.
|
|
14
|
+
# The default stays CWD-relative on purpose: for a repo-local tool,
|
|
15
|
+
# per-checkout state is what you want, and repo-relative would share
|
|
16
|
+
# one key file across every clone on the machine.
|
|
17
|
+
LLM_PROVIDERS_FILE = os.environ.get("AGENT_PROVIDERS_FILE", "providers.json")
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def no_providers_message() -> str:
|
|
21
|
+
"""The error for "the file itself is not there" (#24).
|
|
22
|
+
|
|
23
|
+
ONE wording, used by both raisers -- api_initialization (the one
|
|
24
|
+
every user actually meets) and load_credentials below -- so the two
|
|
25
|
+
cannot drift apart the way their old messages already had.
|
|
26
|
+
|
|
27
|
+
Batch 35: the LOCATION clause is conditional now, because the path is
|
|
28
|
+
no longer always cwd-relative. AGENT_PROVIDERS_FILE has always accepted
|
|
29
|
+
an absolute path, and the npm launcher sets one when the working
|
|
30
|
+
directory has no providers.json of its own. Naming os.getcwd()
|
|
31
|
+
unconditionally then reported a directory the code never looked in and
|
|
32
|
+
sent the user to create the file in the wrong place -- the exact class
|
|
33
|
+
of defect #24 was filed about, reintroduced by a path it did not
|
|
34
|
+
anticipate. An absolute path is already the whole answer and needs no
|
|
35
|
+
second location.
|
|
36
|
+
"""
|
|
37
|
+
if os.path.isabs(LLM_PROVIDERS_FILE):
|
|
38
|
+
found = f"No providers configured: {LLM_PROVIDERS_FILE} was not found."
|
|
39
|
+
else:
|
|
40
|
+
found = (
|
|
41
|
+
f"No providers configured: {LLM_PROVIDERS_FILE} was not found in "
|
|
42
|
+
f"{os.getcwd()!r}."
|
|
43
|
+
)
|
|
44
|
+
return (
|
|
45
|
+
f"{found} Copy providers.json.example to "
|
|
46
|
+
f"{LLM_PROVIDERS_FILE} and add your API key."
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def unknown_provider_message(provider_name: str, providers: dict) -> str:
|
|
51
|
+
"""The error for "the file is there, this provider is not in it" (#24).
|
|
52
|
+
|
|
53
|
+
Names the configured set exactly like /model's refusal does, so the
|
|
54
|
+
typo is answered where it was made rather than two layers later.
|
|
55
|
+
"""
|
|
56
|
+
configured = ", ".join(sorted(providers)) or "none"
|
|
57
|
+
return (
|
|
58
|
+
f"Unknown provider: {provider_name}. Configured: {configured} "
|
|
59
|
+
f"(file: {LLM_PROVIDERS_FILE})."
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
# ROADMAP_v3 §79 (HD5). Providers connected for THIS PROCESS ONLY, never
|
|
64
|
+
# written anywhere. A shared hosted demo runs every visitor in one container
|
|
65
|
+
# as one Unix user, so a key in a file is a key one bug away from the next
|
|
66
|
+
# visitor; a key in this dict lives as long as the session's process does.
|
|
67
|
+
# Entries here win over the file's, and the file is never told about them.
|
|
68
|
+
_SESSION_PROVIDERS: dict = {}
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def set_session_provider(provider_name: str, entry: dict) -> None:
|
|
72
|
+
"""Connect a provider for this process without writing it to disk (HD5).
|
|
73
|
+
|
|
74
|
+
A COPY is stored, so the caller's dict cannot change it afterwards.
|
|
75
|
+
"""
|
|
76
|
+
_SESSION_PROVIDERS[provider_name] = dict(entry)
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def clear_session_providers() -> None:
|
|
80
|
+
_SESSION_PROVIDERS.clear()
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def _load_file_data() -> dict:
|
|
84
|
+
if not os.path.exists(LLM_PROVIDERS_FILE):
|
|
85
|
+
return {}
|
|
86
|
+
with open(LLM_PROVIDERS_FILE, encoding="utf-8") as file:
|
|
87
|
+
return json.load(file)
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def load_provider_data() -> dict:
|
|
91
|
+
"""Every configured provider: the file's entries, with any connected for
|
|
92
|
+
this session only laid over them (HD5).
|
|
93
|
+
|
|
94
|
+
Callers get fresh dicts each time, so mutating the answer changes
|
|
95
|
+
neither the file nor the session's entries. `save_credentials` reads the
|
|
96
|
+
FILE alone, which is what keeps a session-only key from being written
|
|
97
|
+
back by the next save of some other provider.
|
|
98
|
+
"""
|
|
99
|
+
data = _load_file_data()
|
|
100
|
+
for name, entry in _SESSION_PROVIDERS.items():
|
|
101
|
+
data[name] = dict(entry)
|
|
102
|
+
return data
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
# 0600 -- owner read/write, nobody else. This file holds every LLM
|
|
106
|
+
# provider's API key in cleartext, and a bare open(path, "w") left its
|
|
107
|
+
# protection to the process umask: 0644 under the common default, i.e.
|
|
108
|
+
# readable by every other account on the machine (#19).
|
|
109
|
+
#
|
|
110
|
+
# The blast radius of a credential file is not the file; it is the paid
|
|
111
|
+
# API account behind it. Every comparable tool treats one as 0600
|
|
112
|
+
# (~/.aws/credentials, ~/.docker/config.json, ~/.ssh/id_*), and OpenSSH
|
|
113
|
+
# goes further and REFUSES a group-readable private key.
|
|
114
|
+
_SECRET_FILE_MODE = 0o600
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def _write_secret_json(path: str, data: dict) -> None:
|
|
118
|
+
"""Write JSON to a file created 0600, never world-readable even briefly,
|
|
119
|
+
and never half-written.
|
|
120
|
+
|
|
121
|
+
0600 AT CREATION, NOT open() followed by os.chmod. A post-write chmod
|
|
122
|
+
leaves a window in which the key is on disk with the umask's
|
|
123
|
+
permissions -- short, but it is exactly the window an attacker with
|
|
124
|
+
local read access is waiting for, and closing it costs one line.
|
|
125
|
+
`write_json_atomic` applies the mode to the TEMP file, which is the
|
|
126
|
+
same property: `os.replace` carries it across, and the key is never on
|
|
127
|
+
disk under the umask's permissions at any point.
|
|
128
|
+
|
|
129
|
+
WINDOWS: POSIX mode bits do not apply, and the mode argument only
|
|
130
|
+
controls the read-only flag there. This is a no-op on Windows rather
|
|
131
|
+
than a wrong-op; the file's protection comes from the ACL on the user
|
|
132
|
+
profile directory instead. The tests skip accordingly, and the CI
|
|
133
|
+
container is where the assertion actually runs.
|
|
134
|
+
|
|
135
|
+
ATOMIC SINCE BATCH 108, and this was the older half of the same defect.
|
|
136
|
+
It wrote `O_TRUNC` straight over the live file, so a crash, a full disk
|
|
137
|
+
or a kill between the truncate and the flush destroyed every stored
|
|
138
|
+
provider key at once -- and unlike the secrets store, this file ships
|
|
139
|
+
in use for every user who has ever saved a credential. `json_store.py`
|
|
140
|
+
was extracted to delete exactly this pattern and says so; the two files
|
|
141
|
+
holding credentials were the last two stores in the project still
|
|
142
|
+
carrying a private copy of it.
|
|
143
|
+
"""
|
|
144
|
+
write_json_atomic(path, data, mode=_SECRET_FILE_MODE, indent=2)
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def _write_provider_data(provider_data: dict) -> None:
|
|
148
|
+
_write_secret_json(LLM_PROVIDERS_FILE, provider_data)
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def save_credentials(
|
|
152
|
+
provider_name: str,
|
|
153
|
+
api_key: str,
|
|
154
|
+
api_url: str = "",
|
|
155
|
+
is_v1_compatible: bool = True,
|
|
156
|
+
supports_stream_usage: bool = False,
|
|
157
|
+
) -> None:
|
|
158
|
+
# The FILE, never the merged view: a session-only entry (HD5) read here
|
|
159
|
+
# would be written to disk by this save.
|
|
160
|
+
provider_data = _load_file_data()
|
|
161
|
+
|
|
162
|
+
if provider_name in provider_data:
|
|
163
|
+
provider_data[provider_name]["API_KEY"] = api_key
|
|
164
|
+
if api_url:
|
|
165
|
+
provider_data[provider_name]["API_URL"] = api_url
|
|
166
|
+
provider_data[provider_name]["is_v1_compatible"] = is_v1_compatible
|
|
167
|
+
provider_data[provider_name]["supports_stream_usage"] = supports_stream_usage
|
|
168
|
+
else:
|
|
169
|
+
provider_data[provider_name] = {
|
|
170
|
+
"API_KEY": api_key,
|
|
171
|
+
"API_URL": api_url,
|
|
172
|
+
"is_v1_compatible": is_v1_compatible,
|
|
173
|
+
"supports_stream_usage": supports_stream_usage,
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
_write_provider_data(provider_data)
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
def forget_key(provider_name: str) -> "str | None":
|
|
180
|
+
"""Remove `provider_name`'s key; say where it was (ROADMAP_v3 §83, CG13).
|
|
181
|
+
|
|
182
|
+
`/disconnect`'s one writer. A session-only entry (HD5) is dropped whole,
|
|
183
|
+
since it exists only to carry the key, and the file is not touched --
|
|
184
|
+
a shared deployment never writes it. Otherwise the file entry's
|
|
185
|
+
`API_KEY` is blanked and EVERY OTHER FIELD STAYS: the URL, the two
|
|
186
|
+
flags, `echoes_reasoning`, `accepts_images` -- exactly what
|
|
187
|
+
`save_credentials` keeps when a key is replaced, so a later `/connect`
|
|
188
|
+
comes back to the same entry. Returns "session", "file", or None when
|
|
189
|
+
there was no key to forget.
|
|
190
|
+
"""
|
|
191
|
+
if _SESSION_PROVIDERS.pop(provider_name, None) is not None:
|
|
192
|
+
return "session"
|
|
193
|
+
provider_data = _load_file_data()
|
|
194
|
+
entry = provider_data.get(provider_name)
|
|
195
|
+
if not entry or not entry.get("API_KEY"):
|
|
196
|
+
return None
|
|
197
|
+
entry["API_KEY"] = ""
|
|
198
|
+
_write_provider_data(provider_data)
|
|
199
|
+
return "file"
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
def load_credentials(provider_name: str) -> tuple[str, str]:
|
|
203
|
+
provider_data = load_provider_data()
|
|
204
|
+
# #24. The two failure modes say different things now -- "the file is
|
|
205
|
+
# not there" is a setup problem with a one-line remedy; "the provider
|
|
206
|
+
# is not in it" is a typo. Same builders api_initialization uses.
|
|
207
|
+
if not provider_data and not os.path.exists(LLM_PROVIDERS_FILE):
|
|
208
|
+
raise ValueError(no_providers_message())
|
|
209
|
+
if provider_name not in provider_data:
|
|
210
|
+
raise ValueError(unknown_provider_message(provider_name, provider_data))
|
|
211
|
+
|
|
212
|
+
entry = provider_data[provider_name]
|
|
213
|
+
return entry["API_KEY"], entry.get("API_URL", "")
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
def missing_key_message(provider_name: str) -> str:
|
|
217
|
+
"""The one wording for "configured, but with an empty API_KEY".
|
|
218
|
+
|
|
219
|
+
Extracted in batch 44 for the reason no_providers_message() was: /model
|
|
220
|
+
carried its own copy, naming providers.json literally where this file
|
|
221
|
+
names LLM_PROVIDERS_FILE, so the same fact read differently at launch
|
|
222
|
+
and at a switch -- while tui/app.py's comment beside the launch render
|
|
223
|
+
already claimed they were "the same fact at both moments". WARN-only at
|
|
224
|
+
both call sites: a local OpenAI-compatible endpoint legitimately takes
|
|
225
|
+
no key, and refusing would block a real configuration.
|
|
226
|
+
"""
|
|
227
|
+
return (f"{provider_name} has no API_KEY in {LLM_PROVIDERS_FILE} "
|
|
228
|
+
f"— calls will fail unless it is a local endpoint that "
|
|
229
|
+
f"needs none.")
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
def empty_key_refusal(provider_name: str) -> str:
|
|
233
|
+
"""What a SEND says when a provider that cannot go keyless has no key.
|
|
234
|
+
|
|
235
|
+
missing_key_message is the launch and /model WARNING, and its "unless it
|
|
236
|
+
is a local endpoint" is true there. This is the refusal at the moment a
|
|
237
|
+
client would be built, for a provider with no local-endpoint case at all
|
|
238
|
+
(batch 234: ANTHROPIC). anthropic 0.116.0 refused an empty key itself
|
|
239
|
+
with a TypeError naming the problem; 2.x builds `Authorization: Bearer `,
|
|
240
|
+
httpx2 refuses that header before anything is sent, and the SDK reports
|
|
241
|
+
it as "Connection error." -- which core/provider_errors.py rightly
|
|
242
|
+
treats as transient, so it was retried as a network blip.
|
|
243
|
+
"""
|
|
244
|
+
return (f"{provider_name} has no API_KEY in {LLM_PROVIDERS_FILE}, and its "
|
|
245
|
+
f"SDK cannot send a request without one. Add the key there, or "
|
|
246
|
+
f"with /connect {provider_name.lower()} in the TUI.")
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
def missing_credential_message(provider_name: str,
|
|
250
|
+
entry: dict) -> "str | None":
|
|
251
|
+
"""What to say when `provider_name` has nothing to authenticate with, or
|
|
252
|
+
None when it has something. The ONE test, for launch and for every
|
|
253
|
+
command that switches a provider.
|
|
254
|
+
|
|
255
|
+
A key for every provider but one. The ChatGPT plan's entry holds no key
|
|
256
|
+
BY DESIGN (ROADMAP_v3 §83, CG20) and its credential is the sign-in in
|
|
257
|
+
`chatgpt_auth.json`, so testing the key said "calls will fail" -- in
|
|
258
|
+
red, at launch and after each `/model CHATGPT` -- about a plan that was
|
|
259
|
+
signed in and answering (batch 189, the owner's live check). Three call
|
|
260
|
+
sites each tested the key on their own, which is why one fix here rather
|
|
261
|
+
than three there.
|
|
262
|
+
|
|
263
|
+
On a hosted deployment the plan has no credential at all (CG1): the
|
|
264
|
+
answer there is why, never "/connect chatgpt signs in", which that
|
|
265
|
+
deployment refuses (batch 195). Signed in or not -- a token file
|
|
266
|
+
carried onto one still cannot reach the plan (core/client.py).
|
|
267
|
+
"""
|
|
268
|
+
if provider_name == "CHATGPT":
|
|
269
|
+
# Imported here: core.chatgpt_auth imports this module.
|
|
270
|
+
from core import chatgpt_auth
|
|
271
|
+
from security import hosted
|
|
272
|
+
|
|
273
|
+
if hosted.is_hosted():
|
|
274
|
+
return chatgpt_auth.LOCAL_ONLY
|
|
275
|
+
if chatgpt_auth.status().signed_in:
|
|
276
|
+
return None
|
|
277
|
+
return ("The ChatGPT plan is not signed in, so CHATGPT cannot answer. "
|
|
278
|
+
"/connect chatgpt signs in.")
|
|
279
|
+
if entry.get("API_KEY"):
|
|
280
|
+
return None
|
|
281
|
+
return missing_key_message(provider_name)
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
def provider_startup_issues(provider_name: str) -> list:
|
|
285
|
+
"""What launch should say about the provider setup, before either
|
|
286
|
+
shell starts (#138).
|
|
287
|
+
|
|
288
|
+
The same three checks /model performs on a switch -- file present,
|
|
289
|
+
provider configured, a credential present (a key, or for the ChatGPT
|
|
290
|
+
plan its sign-in: `missing_credential_message`) -- applied at the moment the user
|
|
291
|
+
chose the provider, instead of at the first model call, which is a
|
|
292
|
+
dead end away from the mistake that caused it. WARN-ONLY, never a
|
|
293
|
+
refusal: an OpenAI-compatible endpoint running locally legitimately
|
|
294
|
+
takes no key (the reason /model warns there too), and refusing would
|
|
295
|
+
block a real configuration.
|
|
296
|
+
|
|
297
|
+
Empty list means healthy and says NOTHING -- silence is the healthy
|
|
298
|
+
case's whole UX. Plain sentences, no prefix: rendering is the
|
|
299
|
+
shell's (CLI prints, TUI write_error), so one wording reaches both.
|
|
300
|
+
"""
|
|
301
|
+
providers = load_provider_data()
|
|
302
|
+
if not providers and not os.path.exists(LLM_PROVIDERS_FILE):
|
|
303
|
+
return [no_providers_message()]
|
|
304
|
+
if provider_name not in providers:
|
|
305
|
+
return [unknown_provider_message(provider_name, providers)]
|
|
306
|
+
message = missing_credential_message(provider_name,
|
|
307
|
+
providers[provider_name])
|
|
308
|
+
return [message] if message else []
|
package/database.py
CHANGED
|
@@ -9,7 +9,7 @@ table schema.
|
|
|
9
9
|
|
|
10
10
|
import logging
|
|
11
11
|
|
|
12
|
-
from sqlmodel import
|
|
12
|
+
from sqlmodel import SQLModel, create_engine
|
|
13
13
|
|
|
14
14
|
import config
|
|
15
15
|
|
|
@@ -23,6 +23,87 @@ engine = create_engine(
|
|
|
23
23
|
connect_args={"check_same_thread": False},
|
|
24
24
|
)
|
|
25
25
|
|
|
26
|
+
# ---------------------------------------------------------------------------
|
|
27
|
+
# ---- Concurrent writers (ROADMAP_v2 §47 slice 8) --------------------------
|
|
28
|
+
# ---------------------------------------------------------------------------
|
|
29
|
+
#
|
|
30
|
+
# `check_same_thread: False` has always been here, because the TUI drains the
|
|
31
|
+
# loop on a worker thread while the UI thread reads. What was never true
|
|
32
|
+
# until NA9 is that two writers could be in flight at once: one agent ran at
|
|
33
|
+
# a time, so the pool handed out one connection that mattered and SQLite's
|
|
34
|
+
# single-writer rule cost nothing.
|
|
35
|
+
#
|
|
36
|
+
# MEASURED, at the real engine against a real database, because this is the
|
|
37
|
+
# one hazard in the slice it would have been easiest to assume. Each shape is
|
|
38
|
+
# N threads creating a subagent thread and writing 200 messages to it, which
|
|
39
|
+
# is a child run's shape:
|
|
40
|
+
#
|
|
41
|
+
# writers journal=delete journal=WAL
|
|
42
|
+
# 3 0 errors, 2.94s 0 errors, 1.31s
|
|
43
|
+
# 8 1 "database is 0 errors, 3.21s
|
|
44
|
+
# locked", 6.78s
|
|
45
|
+
# 16 -- 1 "database is locked", 6.00s
|
|
46
|
+
#
|
|
47
|
+
# So at SUBAGENT_MAX_PARALLEL = 3 the shipped configuration does NOT lock,
|
|
48
|
+
# and WAL is enabled anyway for the two things the table shows: it removes
|
|
49
|
+
# the failure at 8, which is where a raised ceiling lands, and it is a little
|
|
50
|
+
# over twice as fast at 3, which is the configuration everyone runs. A
|
|
51
|
+
# concurrency ceiling that is a tunable constant invites being tuned, and the
|
|
52
|
+
# failure it walks into is a lost message rather than a slow one.
|
|
53
|
+
#
|
|
54
|
+
# THE BUSY TIMEOUT WAS ALREADY 5000ms and this does not change it. Measured
|
|
55
|
+
# too, via `PRAGMA busy_timeout`: SQLAlchemy's pysqlite dialect passes
|
|
56
|
+
# `timeout=5.0` to sqlite3.connect by default. It is restated here rather
|
|
57
|
+
# than left implicit because it is load-bearing for the numbers above, and a
|
|
58
|
+
# default nobody wrote down is a number that can change under us.
|
|
59
|
+
#
|
|
60
|
+
# ON CONNECT rather than once at import: `journal_mode` is persistent in the
|
|
61
|
+
# file but the pool opens connections over the life of the process and a
|
|
62
|
+
# fresh database file arrives with none of this, so the reliable place to
|
|
63
|
+
# state it is every connection. Contained and logged for the reason
|
|
64
|
+
# everything at this layer is: WAL needs shared memory, which some network
|
|
65
|
+
# filesystems do not provide, and a harness that refuses to start because it
|
|
66
|
+
# could not make its journal faster would be a self-inflicted outage.
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def _apply_sqlite_pragmas(dbapi_connection, _record) -> None:
|
|
70
|
+
"""WAL and an explicit busy timeout, per connection. See above."""
|
|
71
|
+
try:
|
|
72
|
+
cursor = dbapi_connection.cursor()
|
|
73
|
+
try:
|
|
74
|
+
cursor.execute("PRAGMA journal_mode=WAL")
|
|
75
|
+
cursor.execute("PRAGMA busy_timeout=5000")
|
|
76
|
+
finally:
|
|
77
|
+
cursor.close()
|
|
78
|
+
except Exception: # noqa: BLE001 -- a slower journal is not an outage
|
|
79
|
+
logger.warning(
|
|
80
|
+
"Could not set journal_mode=WAL on this database; continuing on "
|
|
81
|
+
"whatever journal it has. Concurrent subagent writes may "
|
|
82
|
+
"contend. This is expected on filesystems without shared "
|
|
83
|
+
"memory support.", exc_info=True)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
# Imported here rather than at the top so the listener registration reads as
|
|
87
|
+
# one unit with the reasoning above it.
|
|
88
|
+
from sqlalchemy import event as _sqlalchemy_event # noqa: E402
|
|
89
|
+
from sqlalchemy.engine import Engine as _SqlAlchemyEngine # noqa: E402
|
|
90
|
+
|
|
91
|
+
# ONLY ON A REAL ENGINE, and the condition is named rather than caught.
|
|
92
|
+
#
|
|
93
|
+
# The suite's root conftest stubs `sqlmodel` into sys.modules before
|
|
94
|
+
# collection, so `create_engine` above returns a plain namespace there and
|
|
95
|
+
# `listens_for` raises InvalidRequestError on it -- at import, which is a
|
|
96
|
+
# collection error for every test that touches storage. An `except` around
|
|
97
|
+
# the registration would fix that and would also swallow a genuine
|
|
98
|
+
# misregistration in production, silently, leaving the journal on `delete`
|
|
99
|
+
# with nothing said. An isinstance check cannot: a real engine always
|
|
100
|
+
# passes it, so a production failure still raises.
|
|
101
|
+
#
|
|
102
|
+
# Same seam `ensure_columns` already uses one function down, for the same
|
|
103
|
+
# stated reason -- a boundary that only works in production is not a seam.
|
|
104
|
+
if isinstance(engine, _SqlAlchemyEngine):
|
|
105
|
+
_sqlalchemy_event.listens_for(engine, "connect")(_apply_sqlite_pragmas)
|
|
106
|
+
|
|
26
107
|
|
|
27
108
|
def create_db_and_tables() -> None:
|
|
28
109
|
"""Creates any table that doesn't exist yet. Safe to call every startup.
|