Files
scientific-agent-skills/scientific-skills/autoskill/scripts/doctor.py
T
Renato Umeton 412d3f22ae add: autoskill — synthesize new skills from observed local screen activity
A meta-skill that observes a researcher's own screen activity via a local
screenpipe daemon, clusters repeated workflow patterns, compares each
cluster against this repo's existing 135 skills using local embeddings,
and drafts either a thin composition recipe (a SKILL.md that chains
existing skills) or a full new SKILL.md when no combination fits.

Key design properties

- On-demand, no daemon of its own; invoked by the user with a time window.
- Local-first. Detection, clustering, redaction, and embeddings all run
  on-device. Screenpipe's native app/window filters run at capture time;
  a defense-in-depth regex pass scrubs emails, JWTs, SSH private-key
  blocks, known-env-var secret assignments, Slack / HuggingFace / OpenAI
  / GitHub / AWS / Google / Stripe tokens, US SSNs, and US phone numbers
  before any cluster summary reaches the LLM.
- LLM backend user-selectable, default local via LM Studio
  (Gemma-4-31B-it recommended). Opt-in Anthropic or BYOK Foundry
  backends sit behind the same interface.
- sentence-transformers/all-MiniLM-L6-v2 indexes every SKILL.md
  frontmatter description locally. For each cluster, top-k matches go to
  the LLM, which emits reuse / compose / novel and a SKILL.md body where
  appropriate.
- Staged output lives under ~/.autoskill/proposed/<ts>/ (default,
  outside the repo tree). A promote CLI moves approved ones into
  scientific-skills/<name>/.
- Unified CLI: autoskill run | doctor | promote. doctor preflights
  screenpipe reachability + auth, the configured LLM backend, the
  config, and the skills directory.

What's shipped

- 8 pipeline scripts (fetch_window, redact, cluster, match_skills,
  synthesize, promote, backends, run) plus the autoskill.py dispatcher.
- 83 pytest tests: unit, integration, and end-to-end with
  httpx.MockTransport fakes for screenpipe and LM Studio.
- Verified live end-to-end on macOS: source-built screenpipe daemon
  (17k+ real OCR events captured) + real all-MiniLM-L6-v2 embedding the
  full 135-skill index + real Gemma-4-31B-it at 128K context returning a
  parseable JSON verdict, producing a report.md with sensible top-k
  matches.
- SKILL.md frontmatter matches the convention used by literature-review,
  hypothesis-generation, and other sibling skills.
- skill-scanner scan scientific-skills/autoskill --use-behavioral run
  per the repo's CONTRIBUTING requirement; findings profile (15 total,
  5 critical, 8 medium, 2 low) is in line with already-merged script-
  shipping peers (literature-review: 14/3/8/2, citation-management:
  17/5/10/1). Remaining findings are intentional-behavior flags
  covering env-var-based auth to the user-configured LLM and screenpipe
  endpoints; these are documented explicitly in SKILL.md.

Tracked by issue #140.
2026-04-17 16:06:17 -04:00

109 lines
3.4 KiB
Python

import argparse
import os
import sys
from pathlib import Path
import httpx
_VALID_BACKENDS = {"local", "claude", "foundry"}
def default_screenpipe_probe(config):
sp = config.get("screenpipe", {})
url = sp.get("url", "http://localhost:3030")
token = sp.get("token") or os.environ.get("SCREENPIPE_TOKEN")
headers = {"Authorization": f"Bearer {token}"} if token else {}
try:
r = httpx.get(f"{url}/health", headers=headers, timeout=5.0)
if r.status_code == 200:
return ("ok", url)
return ("error", f"{url} returned HTTP {r.status_code}")
except httpx.HTTPError as e:
return ("error", f"{url}: {e}")
def default_llm_probe(config):
kind = config.get("backend")
if kind == "local":
endpoint = config.get("local", {}).get("endpoint", "http://localhost:1234/v1")
try:
r = httpx.get(f"{endpoint}/models", timeout=5.0)
if r.status_code == 200:
return ("ok", endpoint)
return ("error", f"{endpoint} returned HTTP {r.status_code}")
except httpx.HTTPError as e:
return ("error", f"{endpoint}: {e}")
if kind == "claude":
if not os.environ.get("ANTHROPIC_API_KEY"):
return ("error", "ANTHROPIC_API_KEY not set")
return ("ok", "ANTHROPIC_API_KEY present (not probed)")
if kind == "foundry":
if not os.environ.get("FOUNDRY_API_KEY"):
return ("error", "FOUNDRY_API_KEY not set")
return ("ok", "FOUNDRY_API_KEY present (not probed)")
return ("error", f"unknown backend: {kind!r}")
def check(config, *, skills_dir, screenpipe_probe, llm_probe):
result = {}
kind = config.get("backend")
if kind in _VALID_BACKENDS:
result["config"] = ("ok", f"backend={kind}")
else:
result["config"] = ("error", f"unknown backend: {kind!r}")
skills_dir = Path(skills_dir)
if skills_dir.is_dir():
result["skills_dir"] = ("ok", str(skills_dir))
else:
result["skills_dir"] = ("error", f"not a directory: {skills_dir}")
result["screenpipe"] = screenpipe_probe(config)
result["llm"] = llm_probe(config)
return result
def _format_report(result: dict) -> str:
lines = ["autoskill doctor", "================"]
for key in ("config", "skills_dir", "screenpipe", "llm"):
status, detail = result[key]
lines.append(f" {key:12s}: {status:5s} {detail}")
return "\n".join(lines)
def main(argv=None):
import yaml
parser = argparse.ArgumentParser(
prog="autoskill-doctor",
description="Check that screenpipe, LM Studio, config, and skills dir are ready.",
)
parser.add_argument("--config", required=True,
help="path to autoskill config.yaml")
parser.add_argument("--skills-dir", required=True,
help="path to scientific-skills/")
args = parser.parse_args(argv)
config = yaml.safe_load(Path(args.config).read_text())
result = check(
config,
skills_dir=args.skills_dir,
screenpipe_probe=default_screenpipe_probe,
llm_probe=default_llm_probe,
)
report = _format_report(result)
print(report)
any_error = any(status == "error" for status, _ in result.values())
if any_error:
print("\ndoctor: one or more checks failed", file=sys.stderr)
return 1
print("\ndoctor: all checks passed")
return 0
if __name__ == "__main__":
raise SystemExit(main())