mirror of
https://github.com/K-Dense-AI/scientific-agent-skills.git
synced 2026-12-05 18:43:55 +08:00
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.
112 lines
3.7 KiB
Python
112 lines
3.7 KiB
Python
import httpx
|
|
import pytest
|
|
|
|
from fetch_window import fetch_window
|
|
|
|
|
|
def _make_client(handler):
|
|
transport = httpx.MockTransport(handler)
|
|
return httpx.Client(transport=transport, base_url="http://localhost:3030")
|
|
|
|
|
|
def _ocr_event(ts: str, app: str, title: str, text: str) -> dict:
|
|
return {
|
|
"type": "OCR",
|
|
"content": {"timestamp": ts, "app_name": app, "window_name": title, "text": text},
|
|
}
|
|
|
|
|
|
def test_fetch_calls_search_endpoint_with_time_window_params():
|
|
calls = []
|
|
|
|
def handler(request: httpx.Request) -> httpx.Response:
|
|
calls.append(request)
|
|
return httpx.Response(200, json={"data": [], "pagination": {"limit": 50, "offset": 0, "total": 0}})
|
|
|
|
client = _make_client(handler)
|
|
fetch_window(client, start_time="2026-04-17T00:00:00Z", end_time="2026-04-17T04:00:00Z")
|
|
|
|
assert calls, "expected at least one HTTP call"
|
|
assert calls[0].url.path == "/search"
|
|
params = dict(calls[0].url.params)
|
|
assert params["start_time"] == "2026-04-17T00:00:00Z"
|
|
assert params["end_time"] == "2026-04-17T04:00:00Z"
|
|
|
|
|
|
def test_fetch_normalizes_ocr_events_into_unified_schema():
|
|
def handler(request: httpx.Request) -> httpx.Response:
|
|
return httpx.Response(200, json={
|
|
"data": [_ocr_event("2026-04-17T10:00:00Z", "VSCode", "paper.tex", "hello")],
|
|
"pagination": {"limit": 50, "offset": 0, "total": 1},
|
|
})
|
|
|
|
events = fetch_window(_make_client(handler), "2026-04-17T00:00:00Z", "2026-04-17T23:59:59Z")
|
|
|
|
assert len(events) == 1
|
|
e = events[0]
|
|
assert e["app"] == "VSCode"
|
|
assert e["window_title"] == "paper.tex"
|
|
assert e["text"] == "hello"
|
|
assert e["content_type"] == "ocr"
|
|
assert e["ts"] == "2026-04-17T10:00:00Z"
|
|
|
|
|
|
def test_fetch_paginates_until_all_results_collected():
|
|
pages = [
|
|
{"data": [_ocr_event("2026-04-17T10:00:00Z", "App", "t1", "a")] * 2,
|
|
"pagination": {"limit": 2, "offset": 0, "total": 3}},
|
|
{"data": [_ocr_event("2026-04-17T10:05:00Z", "App", "t2", "b")],
|
|
"pagination": {"limit": 2, "offset": 2, "total": 3}},
|
|
]
|
|
call_count = {"n": 0}
|
|
|
|
def handler(request: httpx.Request) -> httpx.Response:
|
|
page = pages[call_count["n"]]
|
|
call_count["n"] += 1
|
|
return httpx.Response(200, json=page)
|
|
|
|
events = fetch_window(_make_client(handler), "2026-04-17T00:00:00Z", "2026-04-17T23:59:59Z", page_size=2)
|
|
|
|
assert call_count["n"] == 2
|
|
assert len(events) == 3
|
|
|
|
|
|
def test_fetch_returns_empty_list_when_no_results():
|
|
def handler(request):
|
|
return httpx.Response(200, json={"data": [], "pagination": {"limit": 50, "offset": 0, "total": 0}})
|
|
|
|
events = fetch_window(_make_client(handler), "2026-04-17T00:00:00Z", "2026-04-17T23:59:59Z")
|
|
assert events == []
|
|
|
|
|
|
def test_fetch_sends_bearer_token_when_provided():
|
|
seen = []
|
|
|
|
def handler(request):
|
|
seen.append(request)
|
|
return httpx.Response(200, json={"data": [], "pagination": {"limit": 50, "offset": 0, "total": 0}})
|
|
|
|
fetch_window(_make_client(handler), "a", "b", token="secret-123")
|
|
|
|
assert seen[0].headers.get("authorization") == "Bearer secret-123"
|
|
|
|
|
|
def test_fetch_omits_auth_header_when_no_token():
|
|
seen = []
|
|
|
|
def handler(request):
|
|
seen.append(request)
|
|
return httpx.Response(200, json={"data": [], "pagination": {"limit": 50, "offset": 0, "total": 0}})
|
|
|
|
fetch_window(_make_client(handler), "a", "b")
|
|
|
|
assert "authorization" not in {k.lower() for k in seen[0].headers.keys()}
|
|
|
|
|
|
def test_fetch_raises_on_http_error():
|
|
def handler(request):
|
|
return httpx.Response(500, text="server down")
|
|
|
|
with pytest.raises(httpx.HTTPStatusError):
|
|
fetch_window(_make_client(handler), "2026-04-17T00:00:00Z", "2026-04-17T23:59:59Z")
|