rigops 0.13.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.
- rigops/__init__.py +3 -0
- rigops/__main__.py +7 -0
- rigops/authprobe.py +106 -0
- rigops/backlog.py +107 -0
- rigops/cause.py +151 -0
- rigops/cli/__init__.py +66 -0
- rigops/cli/authprobe.py +47 -0
- rigops/cli/backlog.py +93 -0
- rigops/cli/config.py +61 -0
- rigops/cli/doctor.py +666 -0
- rigops/cli/eit.py +225 -0
- rigops/cli/eval.py +370 -0
- rigops/cli/hook.py +7 -0
- rigops/cli/janitor.py +88 -0
- rigops/cli/jobs.py +122 -0
- rigops/cli/ledger.py +350 -0
- rigops/cli/mine.py +7 -0
- rigops/cli/reap.py +110 -0
- rigops/cli/tax.py +238 -0
- rigops/cli/version.py +12 -0
- rigops/config.py +83 -0
- rigops/config_spec.py +336 -0
- rigops/core/__init__.py +224 -0
- rigops/corpus.py +44 -0
- rigops/cost.py +37 -0
- rigops/detector.py +91 -0
- rigops/doctor/__init__.py +81 -0
- rigops/doctor/check_agents.py +85 -0
- rigops/doctor/check_budget.py +110 -0
- rigops/doctor/check_jobs.py +30 -0
- rigops/doctor/check_levers.py +328 -0
- rigops/doctor/check_mcp.py +104 -0
- rigops/doctor/check_memory.py +92 -0
- rigops/doctor/check_pointers.py +358 -0
- rigops/doctor/ids.py +32 -0
- rigops/doctor/pointer_grammar.py +147 -0
- rigops/errors.py +5 -0
- rigops/eval/__init__.py +35 -0
- rigops/eval/cases.py +188 -0
- rigops/eval/checks.py +117 -0
- rigops/eval/client.py +190 -0
- rigops/eval/diff.py +108 -0
- rigops/eval/score.py +90 -0
- rigops/fmt.py +62 -0
- rigops/frontmatter.py +36 -0
- rigops/guard_state.py +69 -0
- rigops/hook.py +245 -0
- rigops/janitor.py +384 -0
- rigops/jobs.py +203 -0
- rigops/judge.py +364 -0
- rigops/launchd.py +194 -0
- rigops/ledger_row.py +88 -0
- rigops/levers.py +397 -0
- rigops/mine.py +195 -0
- rigops/mine_group.py +111 -0
- rigops/mine_redact.py +192 -0
- rigops/modelmix.py +36 -0
- rigops/notify.py +114 -0
- rigops/procgroup.py +37 -0
- rigops/reap.py +917 -0
- rigops/reap_guards.py +70 -0
- rigops/reap_owned.py +44 -0
- rigops/reap_procs.py +382 -0
- rigops/reap_report.py +78 -0
- rigops/reap_selftest.py +94 -0
- rigops/rebuilds.py +163 -0
- rigops/redaction-patterns.public.txt +40 -0
- rigops/registry.py +137 -0
- rigops/sources/__init__.py +19 -0
- rigops/sources/ccusage.py +44 -0
- rigops/sources/command.py +50 -0
- rigops/starts.py +247 -0
- rigops/state.py +159 -0
- rigops/templates/cron/crontab.example +21 -0
- rigops/templates/launchd/doctor.plist.in +44 -0
- rigops/templates/launchd/janitor.plist.in +50 -0
- rigops/templates/launchd/ledger.plist.in +48 -0
- rigops/templates/launchd/reap.plist.in +48 -0
- rigops/transcripts.py +369 -0
- rigops/watermarks.py +116 -0
- rigops-0.13.0.dist-info/METADATA +300 -0
- rigops-0.13.0.dist-info/RECORD +86 -0
- rigops-0.13.0.dist-info/WHEEL +5 -0
- rigops-0.13.0.dist-info/entry_points.txt +2 -0
- rigops-0.13.0.dist-info/licenses/LICENSE +21 -0
- rigops-0.13.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
"""Every pointer in the instruction surface must resolve to something real.
|
|
2
|
+
|
|
3
|
+
Prose cannot be type-checked, so it rots: a retired MCP, a deleted agent, a
|
|
4
|
+
disabled plugin recommended as live, a model id two generations old. This check
|
|
5
|
+
extracts the pointers and asserts each one against the filesystem, settings.json,
|
|
6
|
+
installed_plugins.json and launchctl.
|
|
7
|
+
|
|
8
|
+
A memory note is part of that surface: it is recalled into a session and acted
|
|
9
|
+
on, and notes pointing at deleted scripts and plans have had to be found by hand.
|
|
10
|
+
It is also a dated record, so it is scanned narrowly. Only the path rule applies,
|
|
11
|
+
and only to paths under ``doctor.pointers.memory_roots``: another host's
|
|
12
|
+
filesystem is a fact about that host, and a label, model id, plugin, agent,
|
|
13
|
+
skill or server named in a note is mostly history (a skill it names is often a
|
|
14
|
+
project's own, which the rig-wide skill roots do not see). A note that
|
|
15
|
+
records a path as retired names it without its root, so a root-anchored path in
|
|
16
|
+
a note is always a claim that it exists.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
from __future__ import annotations
|
|
20
|
+
|
|
21
|
+
import glob
|
|
22
|
+
import json
|
|
23
|
+
from pathlib import Path
|
|
24
|
+
|
|
25
|
+
from rigops import core
|
|
26
|
+
|
|
27
|
+
from .pointer_grammar import (
|
|
28
|
+
AGENT_RE,
|
|
29
|
+
BUILTIN_AGENTS,
|
|
30
|
+
DEFAULT_AGENT_ROOTS,
|
|
31
|
+
DEFAULT_IGNORE_PREFIXES,
|
|
32
|
+
DEFAULT_IGNORE_SEGMENTS,
|
|
33
|
+
DEFAULT_MEMORY_ROOTS,
|
|
34
|
+
DEFAULT_MODELS,
|
|
35
|
+
DEFAULT_SKILL_ROOTS,
|
|
36
|
+
DEFAULT_SOURCES,
|
|
37
|
+
DIST_TAGS,
|
|
38
|
+
MCP_RE,
|
|
39
|
+
MEMORY_NOTE_RE,
|
|
40
|
+
MODEL_RE,
|
|
41
|
+
NOT_PLUGIN_NAMES,
|
|
42
|
+
PATH_RE,
|
|
43
|
+
PLUGIN_ID_RE,
|
|
44
|
+
PLUGIN_WORD_RE,
|
|
45
|
+
SETTINGS_PATH_KEYS,
|
|
46
|
+
SKILL_RE,
|
|
47
|
+
TRANSCRIPT_RE,
|
|
48
|
+
launchd_re,
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
AREA = "docs"
|
|
52
|
+
CHECK = "pointers"
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
_UNSET = object()
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def _cfg(cfg, key, default):
|
|
59
|
+
"""An explicitly empty list in config is a deliberate override, not a miss."""
|
|
60
|
+
value = core.cfg_get(cfg, f"doctor.pointers.{key}", _UNSET)
|
|
61
|
+
return default if value is _UNSET or value is None else value
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def _sources(cfg):
|
|
65
|
+
return source_files(_cfg(cfg, "sources", DEFAULT_SOURCES))
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def source_files(patterns):
|
|
69
|
+
"""Return the files the patterns name, plus a finding per pattern that is gone.
|
|
70
|
+
|
|
71
|
+
A missing entry is only reported when the operator wrote it. The defaults
|
|
72
|
+
name files that exist on this rig and not on every rig, so a fresh install
|
|
73
|
+
would otherwise open with findings about a vault it does not have.
|
|
74
|
+
"""
|
|
75
|
+
out, missing = [], []
|
|
76
|
+
for pattern in patterns:
|
|
77
|
+
expanded = str(core.expand(pattern))
|
|
78
|
+
if any(ch in expanded for ch in "*?["):
|
|
79
|
+
out.extend(Path(hit) for hit in sorted(glob.glob(expanded, recursive=True)))
|
|
80
|
+
elif Path(expanded).is_file():
|
|
81
|
+
out.append(Path(expanded))
|
|
82
|
+
elif pattern not in DEFAULT_SOURCES:
|
|
83
|
+
missing.append(_finding(
|
|
84
|
+
"source", pattern, "doctor.pointers.sources",
|
|
85
|
+
"point the source at a file that exists or drop the entry",
|
|
86
|
+
))
|
|
87
|
+
return [p for p in out if p.is_file()], missing
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def _json(path, default):
|
|
91
|
+
try:
|
|
92
|
+
return json.loads(core.read_text(path))
|
|
93
|
+
except (OSError, ValueError):
|
|
94
|
+
return default
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def _roots(cfg, key, default):
|
|
98
|
+
"""Return the roots that exist, plus a finding per configured root that is gone.
|
|
99
|
+
|
|
100
|
+
Same rule as the source list: a root an operator named is a claim about this
|
|
101
|
+
rig, while a default root is simply absent on a rig with no such layout.
|
|
102
|
+
"""
|
|
103
|
+
dirs, missing = [], []
|
|
104
|
+
for pattern in _cfg(cfg, key, default):
|
|
105
|
+
base = core.expand(pattern)
|
|
106
|
+
if base.is_dir():
|
|
107
|
+
dirs.append(base)
|
|
108
|
+
elif pattern not in default:
|
|
109
|
+
missing.append(_finding(
|
|
110
|
+
"root", str(base), f"doctor.pointers.{key}",
|
|
111
|
+
"point the root at a directory that exists or drop the entry",
|
|
112
|
+
))
|
|
113
|
+
return dirs, missing
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def _root_findings(cfg):
|
|
117
|
+
out = []
|
|
118
|
+
for key, default in (
|
|
119
|
+
("skill_roots", DEFAULT_SKILL_ROOTS), ("agent_roots", DEFAULT_AGENT_ROOTS),
|
|
120
|
+
):
|
|
121
|
+
out.extend(_roots(cfg, key, default)[1])
|
|
122
|
+
return out
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def _mcp_names(cfg):
|
|
126
|
+
"""Every server name a session could resolve, from all four registries."""
|
|
127
|
+
names = set(_json("~/.claude/settings.json", {}).get("mcpServers", {}) or {})
|
|
128
|
+
user = _json("~/.claude.json", {})
|
|
129
|
+
names |= set(user.get("mcpServers", {}) or {})
|
|
130
|
+
# A server wired for one project is still a real server the docs may name.
|
|
131
|
+
for project in (user.get("projects", {}) or {}).values():
|
|
132
|
+
names |= set((project or {}).get("mcpServers", {}) or {})
|
|
133
|
+
for manifest in (core.CLAUDE_DIR / "plugins").rglob(".mcp.json"):
|
|
134
|
+
names |= set(_json(manifest, {}).get("mcpServers", {}) or {})
|
|
135
|
+
names |= set(_json(core.CLAUDE_DIR / ".mcp.json", {}).get("mcpServers", {}) or {})
|
|
136
|
+
names |= set(_cfg(cfg, "known_mcp", []))
|
|
137
|
+
return {name.lower() for name in names}
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def _known(cfg):
|
|
141
|
+
settings = _json("~/.claude/settings.json", {})
|
|
142
|
+
installed = _json("~/.claude/plugins/installed_plugins.json", {}).get("plugins", {})
|
|
143
|
+
agents = set(BUILTIN_AGENTS)
|
|
144
|
+
for base in _roots(cfg, "agent_roots", DEFAULT_AGENT_ROOTS)[0]:
|
|
145
|
+
agents |= {p.stem.lower() for p in base.rglob("*.md") if p.parent.name == "agents"}
|
|
146
|
+
agents |= {a.lower() for a in _cfg(cfg, "known_agents", [])}
|
|
147
|
+
skills = set()
|
|
148
|
+
for base in _roots(cfg, "skill_roots", DEFAULT_SKILL_ROOTS)[0]:
|
|
149
|
+
skills |= {p.parent.name.lower() for p in base.rglob("SKILL.md")}
|
|
150
|
+
skills |= {s.lower() for s in _cfg(cfg, "known_skills", [])}
|
|
151
|
+
labels = set()
|
|
152
|
+
for line in core.run(["launchctl", "list"]).splitlines()[1:]:
|
|
153
|
+
parts = line.split("\t")
|
|
154
|
+
if len(parts) >= 3:
|
|
155
|
+
labels.add(parts[-1].strip())
|
|
156
|
+
return {
|
|
157
|
+
"plugins": settings.get("enabledPlugins", {}) or {},
|
|
158
|
+
"installed": installed,
|
|
159
|
+
"namespaces": {key.split("@")[0].lower() for key in installed},
|
|
160
|
+
"agents": agents,
|
|
161
|
+
"skills": skills,
|
|
162
|
+
"mcp": _mcp_names(cfg),
|
|
163
|
+
"labels": labels,
|
|
164
|
+
"label_re": launchd_re(core.cfg_get(cfg, "doctor.label_prefix", None)),
|
|
165
|
+
"models": set(_cfg(cfg, "known_models", DEFAULT_MODELS)),
|
|
166
|
+
"ignore": [
|
|
167
|
+
str(core.expand(p))
|
|
168
|
+
for p in _cfg(cfg, "ignore_prefixes", DEFAULT_IGNORE_PREFIXES)
|
|
169
|
+
],
|
|
170
|
+
"placeholders": _cfg(cfg, "ignore_segments", DEFAULT_IGNORE_SEGMENTS),
|
|
171
|
+
"memory_roots": [
|
|
172
|
+
str(core.expand(p)) for p in _cfg(cfg, "memory_roots", DEFAULT_MEMORY_ROOTS)
|
|
173
|
+
],
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
def _clean_path(raw):
|
|
178
|
+
return raw.rstrip(".,;:!?)]}\"'`*")
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
def _within(resolved, prefixes):
|
|
182
|
+
return any(resolved == pre or resolved.startswith(pre + "/") for pre in prefixes)
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
def _path_ok(raw, known, truncated=False):
|
|
186
|
+
path = _clean_path(raw)
|
|
187
|
+
if any(token in path for token in ("$", "{", "}", "...", "<", ">")):
|
|
188
|
+
return True
|
|
189
|
+
if any(seg in path for seg in known["placeholders"]):
|
|
190
|
+
return True
|
|
191
|
+
resolved = str(core.expand(path))
|
|
192
|
+
if _within(resolved, known["ignore"]):
|
|
193
|
+
return True
|
|
194
|
+
if TRANSCRIPT_RE.search(resolved):
|
|
195
|
+
return True
|
|
196
|
+
if any(ch in path for ch in "*?["):
|
|
197
|
+
head = resolved.split("*")[0].split("[")[0].split("?")[0]
|
|
198
|
+
anchor = core.expand(head if head.endswith("/") else head.rsplit("/", 1)[0])
|
|
199
|
+
if not anchor.is_dir():
|
|
200
|
+
return False
|
|
201
|
+
if "**" in resolved:
|
|
202
|
+
# A recursive glob in prose describes a shape, not a file, and one
|
|
203
|
+
# that matches nothing walks the entire subtree: `~/projects/**/x.md`
|
|
204
|
+
# costs forty seconds. This runs in a pre-commit hook, so the check
|
|
205
|
+
# stops at the anchor.
|
|
206
|
+
return True
|
|
207
|
+
pattern = resolved[len(str(anchor)) + 1:]
|
|
208
|
+
try:
|
|
209
|
+
return any(True for _ in anchor.glob(pattern))
|
|
210
|
+
except (OSError, ValueError, IndexError):
|
|
211
|
+
return True
|
|
212
|
+
target = core.expand(path)
|
|
213
|
+
if target.exists():
|
|
214
|
+
return True
|
|
215
|
+
if not truncated:
|
|
216
|
+
return False
|
|
217
|
+
# The match ended at a space, so the real path may continue past it: treat a
|
|
218
|
+
# prefix of a real entry ("~/Library/Application" for "Application Support")
|
|
219
|
+
# as sound. Gated on the truncation, or every missing path would escape
|
|
220
|
+
# whenever some sibling happened to be named after it.
|
|
221
|
+
parent = target.parent
|
|
222
|
+
try:
|
|
223
|
+
return parent.is_dir() and any(
|
|
224
|
+
child.name.startswith(target.name + " ") for child in parent.iterdir()
|
|
225
|
+
)
|
|
226
|
+
except OSError:
|
|
227
|
+
return True
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
def finding_key(kind, value, where):
|
|
231
|
+
# The key names the file but not the line: the same broken pointer is one
|
|
232
|
+
# defect however far an unrelated edit above it pushes the line down, and an
|
|
233
|
+
# id that moved on every reflow would put a fresh row in the backlog each run.
|
|
234
|
+
return f"{kind}:{value}:{where.rsplit(':', 1)[0]}"
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
def _finding(kind, value, where, fix, area=AREA):
|
|
238
|
+
return core.Finding(
|
|
239
|
+
check=CHECK, area=area, key=finding_key(kind, value, where),
|
|
240
|
+
symptom=f"{kind} pointer `{value}` does not resolve",
|
|
241
|
+
evidence=where, fix=fix,
|
|
242
|
+
)
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
def _unregistered(name, known, kind):
|
|
246
|
+
"""True when the name is one this rig should have and does not.
|
|
247
|
+
|
|
248
|
+
A `namespace:name` pointer whose namespace is not an installed plugin is left
|
|
249
|
+
alone: some namespaces are supplied by the runtime and have no directory to
|
|
250
|
+
walk, and calling those broken would be the check inventing a defect.
|
|
251
|
+
"""
|
|
252
|
+
namespace, _, bare = name.rpartition(":")
|
|
253
|
+
if namespace and namespace.lower() not in known["namespaces"]:
|
|
254
|
+
return False
|
|
255
|
+
return bare.lower() not in known[kind]
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
def _scan_text(path, text, known, numbered=True, memory=False):
|
|
259
|
+
out = []
|
|
260
|
+
label = core.short(path)
|
|
261
|
+
for lineno, line in enumerate(text.splitlines(), 1):
|
|
262
|
+
where = f"{label}:{lineno}" if numbered else label
|
|
263
|
+
for match in PATH_RE.finditer(line):
|
|
264
|
+
raw = match.group(0)
|
|
265
|
+
if memory and not _within(str(core.expand(_clean_path(raw))), known["memory_roots"]):
|
|
266
|
+
continue
|
|
267
|
+
if not _path_ok(raw, known, truncated=line[match.end():match.end() + 1] == " "):
|
|
268
|
+
out.append(_finding("path", _clean_path(raw), where,
|
|
269
|
+
"repoint at the live path or delete the claim"))
|
|
270
|
+
if memory:
|
|
271
|
+
continue
|
|
272
|
+
for regex in AGENT_RE:
|
|
273
|
+
for name in regex.findall(line):
|
|
274
|
+
if _unregistered(name, known, "agents"):
|
|
275
|
+
out.append(_finding("agent", name, where,
|
|
276
|
+
"name an agent that exists or drop the dispatch"))
|
|
277
|
+
for regex in SKILL_RE:
|
|
278
|
+
for name in regex.findall(line):
|
|
279
|
+
if _unregistered(name, known, "skills"):
|
|
280
|
+
out.append(_finding("skill", name, where,
|
|
281
|
+
"name a skill that exists or drop the pointer",
|
|
282
|
+
area="skills"))
|
|
283
|
+
for name, market in PLUGIN_ID_RE.findall(line):
|
|
284
|
+
full = f"{name}@{market}"
|
|
285
|
+
if market in DIST_TAGS or name in NOT_PLUGIN_NAMES:
|
|
286
|
+
continue
|
|
287
|
+
if full not in known["plugins"] and full not in known["installed"]:
|
|
288
|
+
out.append(_finding("plugin", full, where,
|
|
289
|
+
"install it, or stop naming a plugin this rig lacks"))
|
|
290
|
+
elif not known["plugins"].get(full, False):
|
|
291
|
+
out.append(_finding("plugin", full, where,
|
|
292
|
+
"enable it in settings.json or stop recommending it"))
|
|
293
|
+
for name in PLUGIN_WORD_RE.findall(line):
|
|
294
|
+
matches = [k for k in known["plugins"] if k.split("@")[0] == name]
|
|
295
|
+
if matches and not any(known["plugins"][k] for k in matches):
|
|
296
|
+
out.append(_finding("plugin", name, where,
|
|
297
|
+
"enable it in settings.json or stop recommending it"))
|
|
298
|
+
for regex in MCP_RE:
|
|
299
|
+
for name in regex.findall(line):
|
|
300
|
+
if name.lower() not in known["mcp"]:
|
|
301
|
+
out.append(_finding("mcp", name, where,
|
|
302
|
+
"wire the server or delete the reference",
|
|
303
|
+
area="repos"))
|
|
304
|
+
# No labels at all means no launchctl, not a rig with nothing loaded, so
|
|
305
|
+
# the rule stands down rather than reporting every label in the docs.
|
|
306
|
+
for label_name in known["label_re"].findall(line) if known["labels"] else []:
|
|
307
|
+
stripped = label_name[:-6] if label_name.endswith(".plist") else label_name
|
|
308
|
+
if stripped.startswith("com.apple.") or ".example." in stripped:
|
|
309
|
+
continue
|
|
310
|
+
if stripped not in known["labels"]:
|
|
311
|
+
out.append(_finding("launchd", stripped, where,
|
|
312
|
+
"load the job or drop the row", area="launchd"))
|
|
313
|
+
for model in MODEL_RE.findall(line):
|
|
314
|
+
if model not in known["models"]:
|
|
315
|
+
out.append(_finding("model", model, where,
|
|
316
|
+
"update to a current model id", area="metrics"))
|
|
317
|
+
return out
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
def _settings_text(path):
|
|
321
|
+
"""Return only the executable slice of settings.json as scannable text.
|
|
322
|
+
|
|
323
|
+
The result is assembled rather than read, so findings against it carry the
|
|
324
|
+
file but no line number: a line of synthesised text is not evidence.
|
|
325
|
+
"""
|
|
326
|
+
data = _json(path, {})
|
|
327
|
+
parts = [json.dumps(data.get(key, {}), indent=1) for key in SETTINGS_PATH_KEYS]
|
|
328
|
+
# A read grant to a directory that no longer exists is dead configuration,
|
|
329
|
+
# and it is the pointer class this check was written for.
|
|
330
|
+
grants = (data.get("permissions", {}) or {}).get("additionalDirectories", [])
|
|
331
|
+
parts.append(json.dumps(grants, indent=1))
|
|
332
|
+
# Skill overrides name skills, so they are rendered into the prose grammar
|
|
333
|
+
# the one scanner already reads rather than given a second code path.
|
|
334
|
+
parts.extend(f"`{name}` skill" for name in data.get("skillOverrides", {}) or {})
|
|
335
|
+
return "\n".join(parts)
|
|
336
|
+
|
|
337
|
+
|
|
338
|
+
def run(cfg):
|
|
339
|
+
known = _known(cfg)
|
|
340
|
+
paths, findings = _sources(cfg)
|
|
341
|
+
findings.extend(_root_findings(cfg))
|
|
342
|
+
for path in paths:
|
|
343
|
+
is_settings = path.name == "settings.json"
|
|
344
|
+
try:
|
|
345
|
+
text = _settings_text(path) if is_settings else core.read_text(path)
|
|
346
|
+
except OSError:
|
|
347
|
+
continue
|
|
348
|
+
findings.extend(_scan_text(
|
|
349
|
+
path, text, known, numbered=not is_settings,
|
|
350
|
+
memory=bool(MEMORY_NOTE_RE.search(str(path))),
|
|
351
|
+
))
|
|
352
|
+
seen, unique = set(), []
|
|
353
|
+
for finding in findings:
|
|
354
|
+
if finding.id in seen:
|
|
355
|
+
continue
|
|
356
|
+
seen.add(finding.id)
|
|
357
|
+
unique.append(finding)
|
|
358
|
+
return unique
|
rigops/doctor/ids.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"""The finding ids and statuses that decide doctor's exit code.
|
|
2
|
+
|
|
3
|
+
An id is a hash of ``(check, key)``, so the contract is the pair. A ``*`` ends a
|
|
4
|
+
key whose tail names the defect (a path, a server) and a ``*`` check matches the
|
|
5
|
+
driver itself. Renaming an entry breaks every backlog line deduplicated on it.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
EXIT_1_FINDINGS = frozenset({
|
|
11
|
+
("agents", "read_only_edit:*"),
|
|
12
|
+
("budget", "always_on"),
|
|
13
|
+
("jobs", "program:*"),
|
|
14
|
+
("mcp", "stdio:*"),
|
|
15
|
+
("pointers", "agent:*"),
|
|
16
|
+
("pointers", "launchd:*"),
|
|
17
|
+
("pointers", "mcp:*"),
|
|
18
|
+
("pointers", "model:*"),
|
|
19
|
+
("pointers", "path:*"),
|
|
20
|
+
("pointers", "plugin:*"),
|
|
21
|
+
("pointers", "root:*"),
|
|
22
|
+
("pointers", "skill:*"),
|
|
23
|
+
("pointers", "source:*"),
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
EXIT_2_FINDINGS = frozenset({
|
|
27
|
+
("*", "crashed"),
|
|
28
|
+
("*", "import"),
|
|
29
|
+
("budget", "unreadable"),
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
EXIT_1_STATUSES = ("failing", "hung", "fail")
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"""What a pointer looks like in prose, and which ones this rig should know.
|
|
2
|
+
|
|
3
|
+
Separated from the check itself so the grammar can be read (and corrected) on
|
|
4
|
+
its own: every default list, every extraction pattern and every exclusion lives
|
|
5
|
+
here, while ``check_pointers`` holds the resolution rules that use them.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import re
|
|
11
|
+
|
|
12
|
+
from rigops import core
|
|
13
|
+
|
|
14
|
+
DEFAULT_SOURCES = [
|
|
15
|
+
"~/.claude/CLAUDE.md",
|
|
16
|
+
"~/.claude/rules/**/*.md",
|
|
17
|
+
"~/.claude/references/**/*.md",
|
|
18
|
+
"~/.claude/skills/**/SKILL.md",
|
|
19
|
+
"~/.claude/agents/*.md",
|
|
20
|
+
"~/.claude/settings.json",
|
|
21
|
+
"~/docs/CLAUDE.md",
|
|
22
|
+
"~/docs/AGENTS.md",
|
|
23
|
+
"~/docs/AGENT-CHEATSHEET.md",
|
|
24
|
+
"~/docs/playbooks/*.md",
|
|
25
|
+
"~/projects/personal/*/CLAUDE.md",
|
|
26
|
+
"~/.claude/projects/*/memory/*.md",
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
DEFAULT_IGNORE_PREFIXES = [
|
|
30
|
+
"/tmp", "/private/tmp", "/var/folders", "~/Downloads",
|
|
31
|
+
"~/.claude/plugins/cache", "~/.claude/plugins/marketplaces",
|
|
32
|
+
"~/.claude/sessions", "~/.claude/backups", "~/.claude/shell-snapshots",
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
# Session transcripts and their sidecar directories are runtime state named after
|
|
36
|
+
# session ids, which come and go. Ignoring the projects directory wholesale to
|
|
37
|
+
# skip them took the fact store beside them out of the check too, and a memory
|
|
38
|
+
# note that points at something deleted is exactly what this check is for.
|
|
39
|
+
TRANSCRIPT_RE = re.compile(
|
|
40
|
+
r"/\.claude/projects/[^/]+/"
|
|
41
|
+
r"[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}(?:\.jsonl|/|$)"
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
# A memory note gets the path rule alone, under these roots; check_pointers says why.
|
|
45
|
+
MEMORY_NOTE_RE = re.compile(r"/\.claude/projects/[^/]+/memory/")
|
|
46
|
+
DEFAULT_MEMORY_ROOTS = ["~/.claude", "~/bin", "~/.local/bin"]
|
|
47
|
+
|
|
48
|
+
# Segments that mark a documentation placeholder rather than a real location.
|
|
49
|
+
DEFAULT_IGNORE_SEGMENTS = [
|
|
50
|
+
"skill-name", "my-project", "path/to", "example", "foo", "bar", "repo-name", "YYYY",
|
|
51
|
+
]
|
|
52
|
+
|
|
53
|
+
# Skills and agents ship in several layouts (user directory, project directory,
|
|
54
|
+
# cached plugin, marketplace checkout), so the roots are walked rather than
|
|
55
|
+
# matched shape by shape: a layout this check has not seen would otherwise turn
|
|
56
|
+
# every sound pointer to that skill into a finding.
|
|
57
|
+
DEFAULT_SKILL_ROOTS = ["~/.claude/skills", "~/.claude/plugins", "~/docs/.claude/skills"]
|
|
58
|
+
DEFAULT_AGENT_ROOTS = ["~/.claude/agents", "~/.claude/plugins"]
|
|
59
|
+
|
|
60
|
+
DEFAULT_MODELS = [
|
|
61
|
+
"claude-opus-5", "claude-sonnet-5", "claude-haiku-4-5-20251001",
|
|
62
|
+
"claude-fable-5", "claude-fable-5-1",
|
|
63
|
+
]
|
|
64
|
+
|
|
65
|
+
# settings.json is the source of truth for plugin and permission state, so only
|
|
66
|
+
# its executable pointers are checked; a disabled plugin listed there is a fact,
|
|
67
|
+
# not a stale recommendation. The allow, deny and ask rules stay out for the same
|
|
68
|
+
# reason: a rule naming a file that does not exist is the rule working.
|
|
69
|
+
SETTINGS_PATH_KEYS = ("hooks", "statusLine", "env", "mcpServers", "modelSettings")
|
|
70
|
+
|
|
71
|
+
BUILTIN_AGENTS = {
|
|
72
|
+
"general-purpose", "explore", "plan", "claude",
|
|
73
|
+
"statusline-setup", "output-style-setup",
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
# Absolute paths live outside the home directory too, and the tools this rig
|
|
77
|
+
# names most often (the package manager prefix, the system binaries) all do. The
|
|
78
|
+
# lookbehind keeps the match from starting inside a longer token, so a relative
|
|
79
|
+
# path such as `.config/bin/run.sh` is not read as `/bin/run.sh`.
|
|
80
|
+
PATH_ROOTS = "opt|usr|etc|srv|var|tmp|private|bin|sbin|Applications|Library|Volumes"
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def _home_root() -> str:
|
|
84
|
+
"""The directory homes are made in, as a regex branch.
|
|
85
|
+
|
|
86
|
+
Read off this rig rather than written down: the name differs by platform,
|
|
87
|
+
and a home directly under the filesystem root has no such directory, in
|
|
88
|
+
which case the branch is dropped instead of matching everything.
|
|
89
|
+
"""
|
|
90
|
+
parent = str(core.HOME.parent)
|
|
91
|
+
return "" if parent == "/" else f"|{re.escape(parent)}/[A-Za-z0-9._-]+"
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
PATH_RE = re.compile(
|
|
95
|
+
rf"(?<![\w./~-])(?:~{_home_root()}|/(?:{PATH_ROOTS}))/[^\s`'\"()\[\],;:|<>]*"
|
|
96
|
+
)
|
|
97
|
+
# Only the "<name> agent" order is trusted: "agent <name>" also matches ordinary
|
|
98
|
+
# prose such as "the agent auto-invokes", which is not a pointer at all.
|
|
99
|
+
AGENT_RE = [
|
|
100
|
+
re.compile(r"[`*]{1,2}([a-z][a-z0-9:_-]{2,})[`*]{1,2}\s+(?:sub)?agent\b"),
|
|
101
|
+
re.compile(r"subagent_type[\"']?\s*[:=]\s*[\"'`]([a-z][a-z0-9:_-]{2,})"),
|
|
102
|
+
]
|
|
103
|
+
SKILL_RE = [
|
|
104
|
+
re.compile(r"\bskills?\s+[`*]{1,2}([a-z][a-z0-9:_-]{2,})[`*]{1,2}"),
|
|
105
|
+
re.compile(r"[`*]{1,2}([a-z][a-z0-9:_-]{2,})[`*]{1,2}\s+skill\b"),
|
|
106
|
+
re.compile(r"Skill\(\s*[\"']([a-z][a-z0-9:_-]+)"),
|
|
107
|
+
]
|
|
108
|
+
# A marketplace name starts with a letter, which a version specifier such as
|
|
109
|
+
# `node@20` or `pnpm@9.1.0` does not, and the boundaries exclude a token that is
|
|
110
|
+
# part of a longer one: an email address, a scoped package, an ssh remote with a
|
|
111
|
+
# path (`git@host:org/repo.git`).
|
|
112
|
+
PLUGIN_ID_RE = re.compile(
|
|
113
|
+
r"(?<![\w.@/+-])([a-z][a-z0-9-]*)@([a-z][a-z0-9-]*[a-z0-9])(?![\w./:@-])"
|
|
114
|
+
)
|
|
115
|
+
# A dist tag pins a dependency; no marketplace is called this.
|
|
116
|
+
DIST_TAGS = {
|
|
117
|
+
"latest", "next", "beta", "alpha", "canary", "rc", "stable",
|
|
118
|
+
"dev", "nightly", "edge", "lts", "main",
|
|
119
|
+
}
|
|
120
|
+
# An ssh remote with no path left (`ssh -T git@host`) is shaped exactly like a
|
|
121
|
+
# plugin id, and these are the account names it is written with.
|
|
122
|
+
NOT_PLUGIN_NAMES = {"git", "root", "admin", "ubuntu", "deploy", "ec2-user"}
|
|
123
|
+
PLUGIN_WORD_RE = re.compile(r"[`*]{1,2}([a-z0-9][a-z0-9-]{2,})[`*]{1,2}\s+plugin\b")
|
|
124
|
+
MCP_RE = [
|
|
125
|
+
re.compile(r"[`*]{1,2}([A-Za-z0-9][A-Za-z0-9_-]{2,})[`*]{1,2}\s+MCP\b"),
|
|
126
|
+
re.compile(r"\bMCP\s+server\s+[`*]{1,2}([A-Za-z0-9][A-Za-z0-9_-]{2,})[`*]{1,2}"),
|
|
127
|
+
]
|
|
128
|
+
|
|
129
|
+
_LABEL_SEGMENT = r"[A-Za-z0-9_-]+"
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
# Two segments is a label: `local.rigops-doctor` is the shape this fleet's own
|
|
133
|
+
# default prefix produces, and requiring a third missed all of them. The
|
|
134
|
+
# lookbehind keeps a filename such as `settings.local.json` out of the match.
|
|
135
|
+
# An operator prefix is commoner in prose (`user.` is also a code variable), so
|
|
136
|
+
# it counts only before a hyphenated name, and only when it ends in a dot.
|
|
137
|
+
def launchd_re(prefixes) -> re.Pattern:
|
|
138
|
+
own = {p for p in prefixes or () if isinstance(p, str) and len(p) > 1 and p.endswith(".")}
|
|
139
|
+
own -= {"com.", "local."}
|
|
140
|
+
shapes = [rf"(?:com|local)\.{_LABEL_SEGMENT}(?:\.{_LABEL_SEGMENT})*"]
|
|
141
|
+
if own:
|
|
142
|
+
head = "|".join(re.escape(p) for p in sorted(own))
|
|
143
|
+
shapes.append(rf"(?:{head})[A-Za-z0-9_]+(?:-[A-Za-z0-9_]+)+(?:\.{_LABEL_SEGMENT})*")
|
|
144
|
+
return re.compile(rf"(?<![\w.-])({'|'.join(shapes)})\b")
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
MODEL_RE = re.compile(r"\bclaude-(?:opus|sonnet|haiku|fable|instant|[0-9])[a-z0-9.-]*\b")
|
rigops/errors.py
ADDED
rigops/eval/__init__.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"""Versioned eval cases run against an OpenAI-compatible endpoint, scored per
|
|
2
|
+
group, recorded as one append-only row per run, and compared run to run.
|
|
3
|
+
|
|
4
|
+
``client`` is the only module that touches the network and ``cases`` the only
|
|
5
|
+
one that reads files; ``checks``, ``score`` and ``diff`` do no I/O at all, so a
|
|
6
|
+
regression verdict can be table-tested without a model.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
from .cases import Case, CaseError, Suite, digest, load_suite, parse_case, read_text_file
|
|
12
|
+
from .checks import evaluate, extract_json, printable
|
|
13
|
+
from .client import complete
|
|
14
|
+
from .diff import compare, resolve
|
|
15
|
+
from .score import build_row, row_problem, stats, summarize
|
|
16
|
+
|
|
17
|
+
__all__ = [
|
|
18
|
+
"printable",
|
|
19
|
+
"read_text_file",
|
|
20
|
+
"row_problem",
|
|
21
|
+
"Case",
|
|
22
|
+
"CaseError",
|
|
23
|
+
"Suite",
|
|
24
|
+
"digest",
|
|
25
|
+
"load_suite",
|
|
26
|
+
"parse_case",
|
|
27
|
+
"evaluate",
|
|
28
|
+
"extract_json",
|
|
29
|
+
"complete",
|
|
30
|
+
"compare",
|
|
31
|
+
"resolve",
|
|
32
|
+
"build_row",
|
|
33
|
+
"stats",
|
|
34
|
+
"summarize",
|
|
35
|
+
]
|