rigcode 0.1.0__py3-none-any.whl
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.
- rigcode/__init__.py +4 -0
- rigcode/__main__.py +4 -0
- rigcode/agent/__init__.py +0 -0
- rigcode/agent/loop.py +627 -0
- rigcode/agent/mentions.py +70 -0
- rigcode/agent/prompts.py +195 -0
- rigcode/agent/runtime.py +535 -0
- rigcode/agent/session.py +165 -0
- rigcode/agent/state.py +161 -0
- rigcode/cli.py +283 -0
- rigcode/config.py +284 -0
- rigcode/doctor.py +158 -0
- rigcode/extensions.py +275 -0
- rigcode/hooks.py +142 -0
- rigcode/llm/__init__.py +0 -0
- rigcode/llm/client.py +259 -0
- rigcode/llm/probe.py +229 -0
- rigcode/llm/stream.py +240 -0
- rigcode/llm/textmode.py +161 -0
- rigcode/llm/types.py +92 -0
- rigcode/llm/wire.py +76 -0
- rigcode/mcp.py +329 -0
- rigcode/permissions.py +221 -0
- rigcode/prompts/agents/coder.md +13 -0
- rigcode/prompts/agents/debugger.md +14 -0
- rigcode/prompts/agents/explore.md +22 -0
- rigcode/prompts/agents/plan.md +21 -0
- rigcode/prompts/agents/researcher.md +14 -0
- rigcode/prompts/agents/reviewer.md +18 -0
- rigcode/prompts/agents/verifier.md +15 -0
- rigcode/prompts/commit.md +5 -0
- rigcode/prompts/compact.md +24 -0
- rigcode/prompts/init.md +10 -0
- rigcode/prompts/system.md +27 -0
- rigcode/tools/__init__.py +0 -0
- rigcode/tools/base.py +245 -0
- rigcode/tools/bashsafety.py +262 -0
- rigcode/tools/editmatch.py +367 -0
- rigcode/tools/files.py +534 -0
- rigcode/tools/interact.py +69 -0
- rigcode/tools/search.py +309 -0
- rigcode/tools/shell.py +424 -0
- rigcode/tools/skill.py +37 -0
- rigcode/tools/task.py +54 -0
- rigcode/tools/todo.py +62 -0
- rigcode/tools/web.py +346 -0
- rigcode/ui/__init__.py +0 -0
- rigcode/ui/base.py +69 -0
- rigcode/ui/commands.py +581 -0
- rigcode/ui/plain.py +321 -0
- rigcode/ui/render.py +207 -0
- rigcode/ui/terminal.py +1154 -0
- rigcode/utils/__init__.py +0 -0
- rigcode/utils/files.py +176 -0
- rigcode/utils/frontmatter.py +38 -0
- rigcode/utils/globmatch.py +91 -0
- rigcode/utils/jsonrepair.py +110 -0
- rigcode/utils/paths.py +83 -0
- rigcode/utils/text.py +105 -0
- rigcode-0.1.0.dist-info/METADATA +203 -0
- rigcode-0.1.0.dist-info/RECORD +64 -0
- rigcode-0.1.0.dist-info/WHEEL +4 -0
- rigcode-0.1.0.dist-info/entry_points.txt +2 -0
- rigcode-0.1.0.dist-info/licenses/LICENSE +21 -0
rigcode/config.py
ADDED
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
"""Layered settings: defaults < ~/.rigcode/settings.json < .rigcode/settings.json
|
|
2
|
+
< .rigcode/settings.local.json < environment < CLI flags.
|
|
3
|
+
|
|
4
|
+
Permission rule lists and hook lists are unioned across layers; everything else
|
|
5
|
+
deep-merges with later layers winning.
|
|
6
|
+
"""
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import copy
|
|
10
|
+
import json
|
|
11
|
+
import os
|
|
12
|
+
from dataclasses import dataclass, field
|
|
13
|
+
from pathlib import Path
|
|
14
|
+
from typing import Any
|
|
15
|
+
|
|
16
|
+
from rigcode.utils.paths import rigcode_home
|
|
17
|
+
|
|
18
|
+
DEFAULTS: dict[str, Any] = {
|
|
19
|
+
"provider": {
|
|
20
|
+
# auto = find a local server (llama.cpp, Ollama, LM Studio, vLLM) on its default port.
|
|
21
|
+
"base_url": "auto",
|
|
22
|
+
"api_key": "none",
|
|
23
|
+
# auto = the server's only model, or the one it has loaded.
|
|
24
|
+
"model": "auto",
|
|
25
|
+
# None = auto-detect from the server, falling back to 131072.
|
|
26
|
+
"context_window": None,
|
|
27
|
+
# Cap on generated tokens per request (thinking + answer). None = server default.
|
|
28
|
+
"max_output_tokens": 32768,
|
|
29
|
+
"temperature": None,
|
|
30
|
+
"top_p": None,
|
|
31
|
+
# low | medium | high | max | none (thinking off) | null (don't send; server default)
|
|
32
|
+
"reasoning_effort": "low",
|
|
33
|
+
# auto | native | text (text = tool calls written as <tool_call> JSON in the reply)
|
|
34
|
+
"tool_mode": "auto",
|
|
35
|
+
# all | turn | none: which past reasoning_content to send back to the server.
|
|
36
|
+
"keep_reasoning": "all",
|
|
37
|
+
# Optional hard cap on thinking tokens per request (llama.cpp reasoning_budget_tokens).
|
|
38
|
+
"reasoning_budget_tokens": None,
|
|
39
|
+
"extra_body": {},
|
|
40
|
+
"extra_headers": {},
|
|
41
|
+
# Seconds without any data before giving up. Large: a queued request gets no bytes until a slot frees.
|
|
42
|
+
"request_timeout": 3600,
|
|
43
|
+
"connect_timeout": 15,
|
|
44
|
+
"max_retries": 3,
|
|
45
|
+
# Pre-process the static prompt prefix in the background at startup (llama.cpp).
|
|
46
|
+
"warmup": True,
|
|
47
|
+
# llama.cpp-only knobs; ignored for other servers.
|
|
48
|
+
"llama_cpp": {
|
|
49
|
+
"cache_prompt": True,
|
|
50
|
+
"return_progress": True,
|
|
51
|
+
# Pin agents to fixed slots. Leave this off unless the server runs with --no-cache-idle-slots:
|
|
52
|
+
# by default llama.cpp moves idle slots to its RAM cache, and only unpinned requests get
|
|
53
|
+
# their saved state back (a request pinned to a cleared slot re-reads its whole prompt).
|
|
54
|
+
"slot_pinning": False,
|
|
55
|
+
# With pinning: None = main agent on the highest slot, subagents on the slots below it.
|
|
56
|
+
"main_slot": None,
|
|
57
|
+
"subagent_slots": None,
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
"profile": None,
|
|
61
|
+
"profiles": {},
|
|
62
|
+
"permissions": {
|
|
63
|
+
# default | acceptEdits | plan | bypass
|
|
64
|
+
"mode": "default",
|
|
65
|
+
"allow": [],
|
|
66
|
+
"deny": [],
|
|
67
|
+
"ask": [],
|
|
68
|
+
"additional_directories": [],
|
|
69
|
+
},
|
|
70
|
+
"hooks": {},
|
|
71
|
+
"mcp_servers": {},
|
|
72
|
+
"context": {
|
|
73
|
+
"auto_compact": True,
|
|
74
|
+
# Summarize the conversation when the prompt reaches this many tokens or this fraction of
|
|
75
|
+
# the context window, whichever comes first. With slow prompt processing a huge context is
|
|
76
|
+
# expensive to rebuild if the server cache is ever lost, so the token cap is deliberately low.
|
|
77
|
+
"compact_at_tokens": 100000,
|
|
78
|
+
"compact_at": 0.85,
|
|
79
|
+
# Recent user messages kept verbatim after compaction (char budget).
|
|
80
|
+
"keep_recent_chars": 6000,
|
|
81
|
+
"repo_map": True,
|
|
82
|
+
"repo_map_max_lines": 80,
|
|
83
|
+
"max_tool_output_chars": 12000,
|
|
84
|
+
"read_max_chars": 30000,
|
|
85
|
+
"max_memory_chars": 20000,
|
|
86
|
+
},
|
|
87
|
+
"tools": {
|
|
88
|
+
"glob_max_results": 100,
|
|
89
|
+
"background_shells": True,
|
|
90
|
+
"web": True,
|
|
91
|
+
},
|
|
92
|
+
"agents": {
|
|
93
|
+
# How a subagent starts. fork: from a copy of the main conversation (its brief arrives as the
|
|
94
|
+
# Task result), which reuses the server's cache of that conversation. fresh: from just the
|
|
95
|
+
# system prompt and its brief. auto: fork while the main conversation is under fork_max_tokens
|
|
96
|
+
# (default: the compaction threshold or half the context window, whichever is smaller).
|
|
97
|
+
"context": "auto",
|
|
98
|
+
"fork_max_tokens": None,
|
|
99
|
+
# Parallel subagents only apply to fresh ones (parallel forks would each re-read the conversation).
|
|
100
|
+
"max_concurrency": 1,
|
|
101
|
+
"max_turns": 40,
|
|
102
|
+
},
|
|
103
|
+
"ui": {
|
|
104
|
+
# collapsed | full | hidden
|
|
105
|
+
"thinking": "collapsed",
|
|
106
|
+
# bell | none
|
|
107
|
+
"notify": "bell",
|
|
108
|
+
"markdown": True,
|
|
109
|
+
"tool_output_lines": 6,
|
|
110
|
+
},
|
|
111
|
+
# auto | bash | powershell | cmd | sh | <path to shell executable>
|
|
112
|
+
"shell": "auto",
|
|
113
|
+
"memory_files": ["AGENTS.md", "CLAUDE.md", "RIGCODE.md"],
|
|
114
|
+
"compat": {"claude_project_dirs": True, "claude_user_dirs": False},
|
|
115
|
+
"web": {
|
|
116
|
+
# auto | duckduckgo | searxng | brave | tavily
|
|
117
|
+
"search_provider": "auto",
|
|
118
|
+
"searxng_url": None,
|
|
119
|
+
"brave_api_key": None,
|
|
120
|
+
"tavily_api_key": None,
|
|
121
|
+
"user_agent": "Mozilla/5.0 (compatible; rigcode)",
|
|
122
|
+
},
|
|
123
|
+
"max_steps_per_turn": 150,
|
|
124
|
+
"require_read_before_edit": True,
|
|
125
|
+
"debug": False,
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
_UNION_LIST_KEYS = {("permissions", "allow"), ("permissions", "deny"), ("permissions", "ask"),
|
|
129
|
+
("permissions", "additional_directories")}
|
|
130
|
+
|
|
131
|
+
ENV_OVERRIDES = {
|
|
132
|
+
"RIGCODE_BASE_URL": ("provider", "base_url", str),
|
|
133
|
+
"RIGCODE_MODEL": ("provider", "model", str),
|
|
134
|
+
"RIGCODE_API_KEY": ("provider", "api_key", str),
|
|
135
|
+
"RIGCODE_EFFORT": ("provider", "reasoning_effort", str),
|
|
136
|
+
"RIGCODE_CONTEXT_WINDOW": ("provider", "context_window", int),
|
|
137
|
+
"RIGCODE_TOOL_MODE": ("provider", "tool_mode", str),
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
@dataclass
|
|
142
|
+
class ConfigSource:
|
|
143
|
+
scope: str
|
|
144
|
+
path: Path
|
|
145
|
+
loaded: bool = False
|
|
146
|
+
error: str | None = None
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def _merge(base: dict, overlay: dict, path: tuple = ()) -> dict:
|
|
150
|
+
for key, val in overlay.items():
|
|
151
|
+
kp = path + (key,)
|
|
152
|
+
if kp in _UNION_LIST_KEYS and isinstance(val, list):
|
|
153
|
+
existing = base.get(key) or []
|
|
154
|
+
base[key] = existing + [v for v in val if v not in existing]
|
|
155
|
+
elif path == ("hooks",) and isinstance(val, list):
|
|
156
|
+
base[key] = (base.get(key) or []) + val
|
|
157
|
+
elif isinstance(val, dict) and isinstance(base.get(key), dict):
|
|
158
|
+
_merge(base[key], val, kp)
|
|
159
|
+
else:
|
|
160
|
+
base[key] = copy.deepcopy(val)
|
|
161
|
+
return base
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
def _read_json(path: Path) -> tuple[dict | None, str | None]:
|
|
165
|
+
if not path.exists():
|
|
166
|
+
return None, None
|
|
167
|
+
try:
|
|
168
|
+
text = path.read_text(encoding="utf-8-sig")
|
|
169
|
+
data = json.loads(text) if text.strip() else {}
|
|
170
|
+
if not isinstance(data, dict):
|
|
171
|
+
return None, "top-level JSON value must be an object"
|
|
172
|
+
return data, None
|
|
173
|
+
except (OSError, json.JSONDecodeError) as e:
|
|
174
|
+
return None, str(e)
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
def settings_paths(project_root: Path) -> dict[str, Path]:
|
|
178
|
+
return {
|
|
179
|
+
"user": rigcode_home() / "settings.json",
|
|
180
|
+
"project": project_root / ".rigcode" / "settings.json",
|
|
181
|
+
"local": project_root / ".rigcode" / "settings.local.json",
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
@dataclass
|
|
186
|
+
class Settings:
|
|
187
|
+
data: dict
|
|
188
|
+
project_root: Path
|
|
189
|
+
sources: list[ConfigSource] = field(default_factory=list)
|
|
190
|
+
|
|
191
|
+
def get(self, dotted: str, default: Any = None) -> Any:
|
|
192
|
+
cur: Any = self.data
|
|
193
|
+
for part in dotted.split("."):
|
|
194
|
+
if not isinstance(cur, dict) or part not in cur:
|
|
195
|
+
return default
|
|
196
|
+
cur = cur[part]
|
|
197
|
+
return cur
|
|
198
|
+
|
|
199
|
+
def set(self, dotted: str, value: Any) -> None:
|
|
200
|
+
"""In-memory override for this process only."""
|
|
201
|
+
parts = dotted.split(".")
|
|
202
|
+
cur = self.data
|
|
203
|
+
for part in parts[:-1]:
|
|
204
|
+
cur = cur.setdefault(part, {})
|
|
205
|
+
cur[parts[-1]] = value
|
|
206
|
+
|
|
207
|
+
@property
|
|
208
|
+
def provider(self) -> dict:
|
|
209
|
+
return self.data["provider"]
|
|
210
|
+
|
|
211
|
+
def apply_profile(self, name: str) -> bool:
|
|
212
|
+
prof = (self.data.get("profiles") or {}).get(name)
|
|
213
|
+
if not isinstance(prof, dict):
|
|
214
|
+
return False
|
|
215
|
+
_merge(self.data["provider"], prof)
|
|
216
|
+
self.data["profile"] = name
|
|
217
|
+
return True
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
def load_settings(project_root: Path, cli: dict | None = None) -> Settings:
|
|
221
|
+
data = copy.deepcopy(DEFAULTS)
|
|
222
|
+
sources: list[ConfigSource] = []
|
|
223
|
+
for scope, path in settings_paths(project_root).items():
|
|
224
|
+
src = ConfigSource(scope, path)
|
|
225
|
+
layer, err = _read_json(path)
|
|
226
|
+
if layer is not None:
|
|
227
|
+
_merge(data, layer)
|
|
228
|
+
src.loaded = True
|
|
229
|
+
src.error = err
|
|
230
|
+
sources.append(src)
|
|
231
|
+
|
|
232
|
+
# Claude-Code-compatible project MCP file.
|
|
233
|
+
mcp_path = project_root / ".mcp.json"
|
|
234
|
+
layer, err = _read_json(mcp_path)
|
|
235
|
+
if layer is not None:
|
|
236
|
+
servers = layer.get("mcpServers") or layer.get("mcp_servers") or {}
|
|
237
|
+
if isinstance(servers, dict):
|
|
238
|
+
for name, spec in servers.items():
|
|
239
|
+
data["mcp_servers"].setdefault(name, spec)
|
|
240
|
+
sources.append(ConfigSource("mcp", mcp_path, True, None))
|
|
241
|
+
elif err:
|
|
242
|
+
sources.append(ConfigSource("mcp", mcp_path, False, err))
|
|
243
|
+
|
|
244
|
+
for env, (section, key, typ) in ENV_OVERRIDES.items():
|
|
245
|
+
val = os.environ.get(env)
|
|
246
|
+
if val:
|
|
247
|
+
try:
|
|
248
|
+
data[section][key] = typ(val)
|
|
249
|
+
except ValueError:
|
|
250
|
+
pass
|
|
251
|
+
|
|
252
|
+
settings = Settings(data=data, project_root=project_root, sources=sources)
|
|
253
|
+
profile = (cli or {}).pop("profile", None) or data.get("profile")
|
|
254
|
+
if profile:
|
|
255
|
+
settings.apply_profile(profile)
|
|
256
|
+
for dotted, value in (cli or {}).items():
|
|
257
|
+
if value is not None:
|
|
258
|
+
settings.set(dotted, value)
|
|
259
|
+
return settings
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
def update_settings_file(path: Path, mutate) -> dict:
|
|
263
|
+
"""Read-modify-write a settings JSON file (creating it if needed)."""
|
|
264
|
+
data, _err = _read_json(path)
|
|
265
|
+
data = data or {}
|
|
266
|
+
mutate(data)
|
|
267
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
268
|
+
tmp = path.with_suffix(path.suffix + ".tmp")
|
|
269
|
+
tmp.write_text(json.dumps(data, indent=2) + "\n", encoding="utf-8")
|
|
270
|
+
os.replace(tmp, path)
|
|
271
|
+
return data
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
def add_permission_rule(project_root: Path, rule: str, kind: str = "allow", scope: str = "local") -> Path:
|
|
275
|
+
path = settings_paths(project_root)[scope]
|
|
276
|
+
|
|
277
|
+
def mutate(d: dict) -> None:
|
|
278
|
+
perms = d.setdefault("permissions", {})
|
|
279
|
+
lst = perms.setdefault(kind, [])
|
|
280
|
+
if rule not in lst:
|
|
281
|
+
lst.append(rule)
|
|
282
|
+
|
|
283
|
+
update_settings_file(path, mutate)
|
|
284
|
+
return path
|
rigcode/doctor.py
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"""`rigcode doctor` / `/doctor`: diagnose the model server connection and the local setup."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import asyncio
|
|
5
|
+
import ipaddress
|
|
6
|
+
import platform
|
|
7
|
+
import shutil
|
|
8
|
+
import socket
|
|
9
|
+
import sys
|
|
10
|
+
import time
|
|
11
|
+
from collections.abc import Callable
|
|
12
|
+
from urllib.parse import urlparse
|
|
13
|
+
|
|
14
|
+
from rigcode import __version__
|
|
15
|
+
from rigcode.agent.runtime import MIN_LOCAL_CONTEXT
|
|
16
|
+
from rigcode.llm.client import LLMClient
|
|
17
|
+
from rigcode.llm.probe import AUTO, discover
|
|
18
|
+
from rigcode.llm.types import Delta, LLMError
|
|
19
|
+
from rigcode.tools.shell import resolve_shell
|
|
20
|
+
from rigcode.utils.text import fmt_duration
|
|
21
|
+
|
|
22
|
+
Out = Callable[..., None] # out(text, style="")
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def _local_subnet_hint(host: str) -> str:
|
|
26
|
+
"""Best guess at this machine's /24 on the server's network, for the firewall command."""
|
|
27
|
+
try:
|
|
28
|
+
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s:
|
|
29
|
+
s.connect((host, 9))
|
|
30
|
+
mine = s.getsockname()[0]
|
|
31
|
+
net = ipaddress.ip_network(f"{mine}/24", strict=False)
|
|
32
|
+
return str(net)
|
|
33
|
+
except OSError:
|
|
34
|
+
return "<your-subnet>/24"
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
async def _tcp_check(host: str, port: int, timeout: float = 5.0) -> str | None:
|
|
38
|
+
try:
|
|
39
|
+
_r, w = await asyncio.wait_for(asyncio.open_connection(host, port), timeout)
|
|
40
|
+
w.close()
|
|
41
|
+
try:
|
|
42
|
+
await w.wait_closed()
|
|
43
|
+
except OSError:
|
|
44
|
+
pass
|
|
45
|
+
return None
|
|
46
|
+
except asyncio.TimeoutError:
|
|
47
|
+
return "timed out"
|
|
48
|
+
except OSError as e:
|
|
49
|
+
return str(e)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
async def run_doctor(settings, project_root, out: Out, chat_test: bool = True) -> bool:
|
|
53
|
+
ok = True
|
|
54
|
+
out(f"rigcode doctor · rigcode {__version__} · Python {sys.version.split()[0]} · {platform.platform()}", "bold")
|
|
55
|
+
|
|
56
|
+
out("\nConfiguration", "bold")
|
|
57
|
+
for src in settings.sources:
|
|
58
|
+
if src.error:
|
|
59
|
+
ok = False
|
|
60
|
+
out(f" ✗ {src.scope}: {src.path} - {src.error}", "class:error")
|
|
61
|
+
else:
|
|
62
|
+
out(f" {'✓' if src.loaded else '·'} {src.scope}: {src.path}{'' if src.loaded else ' (not present)'}",
|
|
63
|
+
"" if src.loaded else "class:dim")
|
|
64
|
+
|
|
65
|
+
out("\nLocal tools", "bold")
|
|
66
|
+
try:
|
|
67
|
+
shell = resolve_shell(settings.get("shell", "auto"))
|
|
68
|
+
out(f" ✓ shell: {shell.name} ({shell.exe})")
|
|
69
|
+
except RuntimeError as e:
|
|
70
|
+
ok = False
|
|
71
|
+
out(f" ✗ shell: {e}", "class:error")
|
|
72
|
+
git = shutil.which("git")
|
|
73
|
+
out(f" {'✓' if git else '✗'} git: {git or 'not found (git features disabled)'}", "" if git else "class:warn")
|
|
74
|
+
rg = shutil.which("rg")
|
|
75
|
+
out(f" {'✓' if rg else '·'} ripgrep: {rg or 'not found - Grep uses a slower built-in search'}",
|
|
76
|
+
"" if rg else "class:dim")
|
|
77
|
+
|
|
78
|
+
provider = dict(settings.provider)
|
|
79
|
+
base = str(provider.get("base_url") or "")
|
|
80
|
+
auto = base in AUTO
|
|
81
|
+
out(f"\nModel server: {'auto-detect (provider.base_url is not set)' if auto else base}", "bold")
|
|
82
|
+
if not auto:
|
|
83
|
+
u = urlparse(base)
|
|
84
|
+
host = u.hostname or ""
|
|
85
|
+
port = u.port or (443 if u.scheme == "https" else 80)
|
|
86
|
+
err = await _tcp_check(host, port)
|
|
87
|
+
if err:
|
|
88
|
+
ok = False
|
|
89
|
+
out(f" ✗ TCP {host}:{port}: {err}", "class:error")
|
|
90
|
+
if "timed out" in err or "10060" in err:
|
|
91
|
+
out(" The host did not answer on that port. If the server is running, a firewall is probably "
|
|
92
|
+
"blocking it. On the server machine (Ubuntu ufw):", "class:dim")
|
|
93
|
+
out(f" sudo ufw allow from {_local_subnet_hint(host)} to any port {port} proto tcp", "")
|
|
94
|
+
else:
|
|
95
|
+
out(" Connection refused: check that the server is running and listening on 0.0.0.0 "
|
|
96
|
+
f"(llama-server --host 0.0.0.0 --port {port}).", "class:dim")
|
|
97
|
+
return ok
|
|
98
|
+
out(f" ✓ TCP {host}:{port} reachable")
|
|
99
|
+
info, found = await discover(provider)
|
|
100
|
+
if not info.reachable:
|
|
101
|
+
ok = False
|
|
102
|
+
out(f" ✗ {info.error}", "class:error")
|
|
103
|
+
return ok
|
|
104
|
+
if found:
|
|
105
|
+
out(f" ✓ {found}")
|
|
106
|
+
out(f" ✓ server: {info.describe()}")
|
|
107
|
+
if info.models:
|
|
108
|
+
model = provider.get("model")
|
|
109
|
+
listed = model in info.models
|
|
110
|
+
out(f" {'✓' if listed else '·'} models: {', '.join(info.models[:6])}"
|
|
111
|
+
+ ("" if listed or info.kind == "llama.cpp" else f" (configured '{model}' is not listed)"),
|
|
112
|
+
"" if listed else "class:dim")
|
|
113
|
+
if info.context_window:
|
|
114
|
+
small = info.context_window < MIN_LOCAL_CONTEXT
|
|
115
|
+
out(f" {'✗' if small else '✓'} context window per request: {info.context_window:,} tokens"
|
|
116
|
+
+ (" - too small: long prompts get cut off" if small else ""), "class:warn" if small else "")
|
|
117
|
+
elif info.kind == "ollama":
|
|
118
|
+
out(" · context window: decided when Ollama loads the model (OLLAMA_CONTEXT_LENGTH). "
|
|
119
|
+
"rigcode needs at least 16k; 32k or more is better.", "class:dim")
|
|
120
|
+
if info.kind == "llama.cpp":
|
|
121
|
+
pinned = (settings.get("provider.llama_cpp.slot_pinning", False))
|
|
122
|
+
out(f" ✓ slots: {info.total_slots or '?'} ("
|
|
123
|
+
+ ("pinned: main agent on the highest slot" if pinned else
|
|
124
|
+
"unpinned: the server restores each agent's cached prompt from its RAM cache") + ")", "class:dim")
|
|
125
|
+
if info.effort_levels:
|
|
126
|
+
out(f" ✓ template effort levels: {', '.join(info.effort_levels)}"
|
|
127
|
+
+ (" (medium is sent as high)" if "medium" not in info.effort_levels else ""), "class:dim")
|
|
128
|
+
|
|
129
|
+
if chat_test:
|
|
130
|
+
out("\nChat test (tiny request, thinking off)", "bold")
|
|
131
|
+
client = LLMClient(provider, info)
|
|
132
|
+
first: list[float] = []
|
|
133
|
+
started = time.monotonic()
|
|
134
|
+
|
|
135
|
+
def on_delta(d: Delta) -> None:
|
|
136
|
+
if d.kind == "first_token" and not first:
|
|
137
|
+
first.append(time.monotonic() - started)
|
|
138
|
+
|
|
139
|
+
try:
|
|
140
|
+
turn = await client.complete([{"role": "user", "content": "Reply with exactly: OK"}], effort="none",
|
|
141
|
+
max_tokens=24, on_delta=on_delta)
|
|
142
|
+
text = (turn.content or turn.reasoning).strip().replace("\n", " ")[:60]
|
|
143
|
+
ttft = f"first token after {fmt_duration(first[0])}" if first else "no streamed tokens"
|
|
144
|
+
speed = f", {turn.usage.gen_tps:.1f} tok/s" if turn.usage.gen_tps else ""
|
|
145
|
+
out(f" ✓ replied {text!r} - {ttft}{speed}, total {fmt_duration(turn.elapsed)}")
|
|
146
|
+
if turn.tool_calls:
|
|
147
|
+
out(" · (the reply contained a tool call)", "class:dim")
|
|
148
|
+
except LLMError as e:
|
|
149
|
+
ok = False
|
|
150
|
+
out(f" ✗ request failed: {e}", "class:error")
|
|
151
|
+
finally:
|
|
152
|
+
await client.aclose()
|
|
153
|
+
|
|
154
|
+
servers = settings.get("mcp_servers", {}) or {}
|
|
155
|
+
if servers:
|
|
156
|
+
out(f"\nMCP: {len(servers)} server(s) configured: {', '.join(servers)} (status: /mcp inside rigcode)", "class:dim")
|
|
157
|
+
out("\n" + ("All checks passed." if ok else "Some checks failed - see above."), "class:ok" if ok else "class:error")
|
|
158
|
+
return ok
|