priorwork 0.2.2__tar.gz → 0.2.4__tar.gz
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.
- {priorwork-0.2.2 → priorwork-0.2.4}/PKG-INFO +3 -1
- {priorwork-0.2.2 → priorwork-0.2.4}/priorwork/__init__.py +1 -1
- priorwork-0.2.4/priorwork/ai.py +76 -0
- {priorwork-0.2.2 → priorwork-0.2.4}/priorwork/api.py +11 -3
- {priorwork-0.2.2 → priorwork-0.2.4}/priorwork/assets/en/AGENTS.md +1 -1
- {priorwork-0.2.2 → priorwork-0.2.4}/priorwork/assets/en/skills/priorwork-extract/SKILL.md +2 -0
- {priorwork-0.2.2 → priorwork-0.2.4}/priorwork/assets/env.example +18 -2
- {priorwork-0.2.2 → priorwork-0.2.4}/priorwork/assets/ja/AGENTS.md +1 -1
- {priorwork-0.2.2 → priorwork-0.2.4}/priorwork/assets/ja/skills/priorwork-extract/SKILL.md +2 -0
- {priorwork-0.2.2 → priorwork-0.2.4}/priorwork/check.py +12 -2
- {priorwork-0.2.2 → priorwork-0.2.4}/priorwork/cli.py +40 -8
- {priorwork-0.2.2 → priorwork-0.2.4}/priorwork/docs/reference.ja.md +15 -5
- {priorwork-0.2.2 → priorwork-0.2.4}/priorwork/docs/reference.md +46 -7
- {priorwork-0.2.2 → priorwork-0.2.4}/priorwork/doctor.py +40 -4
- {priorwork-0.2.2 → priorwork-0.2.4}/priorwork/fulltext.py +123 -24
- {priorwork-0.2.2 → priorwork-0.2.4}/priorwork/lang_ja.py +94 -5
- priorwork-0.2.4/priorwork/machine.py +148 -0
- {priorwork-0.2.2 → priorwork-0.2.4}/priorwork/octavo.py +2 -1
- {priorwork-0.2.2 → priorwork-0.2.4}/priorwork/requests.py +8 -0
- priorwork-0.2.4/priorwork/scan.py +93 -0
- {priorwork-0.2.2 → priorwork-0.2.4}/priorwork/settings.py +79 -21
- {priorwork-0.2.2 → priorwork-0.2.4}/priorwork/survey.py +1 -1
- {priorwork-0.2.2 → priorwork-0.2.4}/priorwork/zotero.py +123 -10
- {priorwork-0.2.2 → priorwork-0.2.4}/priorwork.egg-info/PKG-INFO +3 -1
- {priorwork-0.2.2 → priorwork-0.2.4}/priorwork.egg-info/SOURCES.txt +5 -0
- {priorwork-0.2.2 → priorwork-0.2.4}/priorwork.egg-info/requires.txt +3 -0
- {priorwork-0.2.2 → priorwork-0.2.4}/pyproject.toml +3 -1
- {priorwork-0.2.2 → priorwork-0.2.4}/tests/test_cli_json.py +6 -4
- {priorwork-0.2.2 → priorwork-0.2.4}/tests/test_doctor.py +21 -1
- priorwork-0.2.4/tests/test_machine.py +97 -0
- priorwork-0.2.4/tests/test_ocr.py +315 -0
- {priorwork-0.2.2 → priorwork-0.2.4}/tests/test_octavo.py +7 -0
- priorwork-0.2.4/tests/test_settings.py +88 -0
- {priorwork-0.2.2 → priorwork-0.2.4}/tests/test_worktree.py +16 -0
- priorwork-0.2.2/tests/test_settings.py +0 -47
- {priorwork-0.2.2 → priorwork-0.2.4}/LICENSE +0 -0
- {priorwork-0.2.2 → priorwork-0.2.4}/README.md +0 -0
- {priorwork-0.2.2 → priorwork-0.2.4}/priorwork/__main__.py +0 -0
- {priorwork-0.2.2 → priorwork-0.2.4}/priorwork/assets/en/skills/priorwork/SKILL.md +0 -0
- {priorwork-0.2.2 → priorwork-0.2.4}/priorwork/assets/en/skills/priorwork-audit/SKILL.md +0 -0
- {priorwork-0.2.2 → priorwork-0.2.4}/priorwork/assets/en/skills/priorwork-check/SKILL.md +0 -0
- {priorwork-0.2.2 → priorwork-0.2.4}/priorwork/assets/en/skills/priorwork-derive/SKILL.md +0 -0
- {priorwork-0.2.2 → priorwork-0.2.4}/priorwork/assets/en/skills/priorwork-manuscript/SKILL.md +0 -0
- {priorwork-0.2.2 → priorwork-0.2.4}/priorwork/assets/en/skills/priorwork-new/SKILL.md +0 -0
- {priorwork-0.2.2 → priorwork-0.2.4}/priorwork/assets/en/skills/priorwork-screen/SKILL.md +0 -0
- {priorwork-0.2.2 → priorwork-0.2.4}/priorwork/assets/en/skills/priorwork-snowball/SKILL.md +0 -0
- {priorwork-0.2.2 → priorwork-0.2.4}/priorwork/assets/en/templates/literature_review.md +0 -0
- {priorwork-0.2.2 → priorwork-0.2.4}/priorwork/assets/en/templates/manuscript.md +0 -0
- {priorwork-0.2.2 → priorwork-0.2.4}/priorwork/assets/en/templates/medical_review.md +0 -0
- {priorwork-0.2.2 → priorwork-0.2.4}/priorwork/assets/ja/skills/priorwork/SKILL.md +0 -0
- {priorwork-0.2.2 → priorwork-0.2.4}/priorwork/assets/ja/skills/priorwork-audit/SKILL.md +0 -0
- {priorwork-0.2.2 → priorwork-0.2.4}/priorwork/assets/ja/skills/priorwork-check/SKILL.md +0 -0
- {priorwork-0.2.2 → priorwork-0.2.4}/priorwork/assets/ja/skills/priorwork-derive/SKILL.md +0 -0
- {priorwork-0.2.2 → priorwork-0.2.4}/priorwork/assets/ja/skills/priorwork-manuscript/SKILL.md +0 -0
- {priorwork-0.2.2 → priorwork-0.2.4}/priorwork/assets/ja/skills/priorwork-new/SKILL.md +0 -0
- {priorwork-0.2.2 → priorwork-0.2.4}/priorwork/assets/ja/skills/priorwork-screen/SKILL.md +0 -0
- {priorwork-0.2.2 → priorwork-0.2.4}/priorwork/assets/ja/skills/priorwork-snowball/SKILL.md +0 -0
- {priorwork-0.2.2 → priorwork-0.2.4}/priorwork/assets/ja/templates/literature_review.md +0 -0
- {priorwork-0.2.2 → priorwork-0.2.4}/priorwork/assets/ja/templates/manuscript.md +0 -0
- {priorwork-0.2.2 → priorwork-0.2.4}/priorwork/assets/ja/templates/medical_review.md +0 -0
- {priorwork-0.2.2 → priorwork-0.2.4}/priorwork/derived.py +0 -0
- {priorwork-0.2.2 → priorwork-0.2.4}/priorwork/docsref.py +0 -0
- {priorwork-0.2.2 → priorwork-0.2.4}/priorwork/export.py +0 -0
- {priorwork-0.2.2 → priorwork-0.2.4}/priorwork/i18n.py +0 -0
- {priorwork-0.2.2 → priorwork-0.2.4}/priorwork/manuscript.py +0 -0
- {priorwork-0.2.2 → priorwork-0.2.4}/priorwork/scaffold.py +0 -0
- {priorwork-0.2.2 → priorwork-0.2.4}/priorwork/snowball.py +0 -0
- {priorwork-0.2.2 → priorwork-0.2.4}/priorwork/ssci.py +0 -0
- {priorwork-0.2.2 → priorwork-0.2.4}/priorwork/workspace.py +0 -0
- {priorwork-0.2.2 → priorwork-0.2.4}/priorwork/worktree.py +0 -0
- {priorwork-0.2.2 → priorwork-0.2.4}/priorwork.egg-info/dependency_links.txt +0 -0
- {priorwork-0.2.2 → priorwork-0.2.4}/priorwork.egg-info/entry_points.txt +0 -0
- {priorwork-0.2.2 → priorwork-0.2.4}/priorwork.egg-info/top_level.txt +0 -0
- {priorwork-0.2.2 → priorwork-0.2.4}/setup.cfg +0 -0
- {priorwork-0.2.2 → priorwork-0.2.4}/tests/test_api.py +0 -0
- {priorwork-0.2.2 → priorwork-0.2.4}/tests/test_check_cards.py +0 -0
- {priorwork-0.2.2 → priorwork-0.2.4}/tests/test_check_citations.py +0 -0
- {priorwork-0.2.2 → priorwork-0.2.4}/tests/test_check_depth.py +0 -0
- {priorwork-0.2.2 → priorwork-0.2.4}/tests/test_check_fulltext_cli.py +0 -0
- {priorwork-0.2.2 → priorwork-0.2.4}/tests/test_docs_commands.py +0 -0
- {priorwork-0.2.2 → priorwork-0.2.4}/tests/test_english.py +0 -0
- {priorwork-0.2.2 → priorwork-0.2.4}/tests/test_export.py +0 -0
- {priorwork-0.2.2 → priorwork-0.2.4}/tests/test_extension.py +0 -0
- {priorwork-0.2.2 → priorwork-0.2.4}/tests/test_fulltext_reading.py +0 -0
- {priorwork-0.2.2 → priorwork-0.2.4}/tests/test_i18n.py +0 -0
- {priorwork-0.2.2 → priorwork-0.2.4}/tests/test_journal_search.py +0 -0
- {priorwork-0.2.2 → priorwork-0.2.4}/tests/test_manuscript.py +0 -0
- {priorwork-0.2.2 → priorwork-0.2.4}/tests/test_manuscript_read.py +0 -0
- {priorwork-0.2.2 → priorwork-0.2.4}/tests/test_medical.py +0 -0
- {priorwork-0.2.2 → priorwork-0.2.4}/tests/test_requests_6.py +0 -0
- {priorwork-0.2.2 → priorwork-0.2.4}/tests/test_scaffold.py +0 -0
- {priorwork-0.2.2 → priorwork-0.2.4}/tests/test_search_zotero.py +0 -0
- {priorwork-0.2.2 → priorwork-0.2.4}/tests/test_site.py +0 -0
- {priorwork-0.2.2 → priorwork-0.2.4}/tests/test_ssci.py +0 -0
- {priorwork-0.2.2 → priorwork-0.2.4}/tests/test_survey.py +0 -0
- {priorwork-0.2.2 → priorwork-0.2.4}/tests/test_survey_fugu.py +0 -0
- {priorwork-0.2.2 → priorwork-0.2.4}/tests/test_survey_notes.py +0 -0
- {priorwork-0.2.2 → priorwork-0.2.4}/tests/test_survey_pay.py +0 -0
- {priorwork-0.2.2 → priorwork-0.2.4}/tests/test_zotero_sync.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: priorwork
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.4
|
|
4
4
|
Summary: Build literature reviews for the social sciences and clinical research in conversation with an AI agent (Semantic Scholar + OpenAlex + PubMed)
|
|
5
5
|
Author: yoshida-kd
|
|
6
6
|
License-Expression: MIT
|
|
@@ -26,6 +26,8 @@ Provides-Extra: dev
|
|
|
26
26
|
Requires-Dist: pytest>=8; extra == "dev"
|
|
27
27
|
Provides-Extra: docling
|
|
28
28
|
Requires-Dist: docling>=2.40; extra == "docling"
|
|
29
|
+
Provides-Extra: ocr
|
|
30
|
+
Requires-Dist: refolio>=0.1.6; extra == "ocr"
|
|
29
31
|
Dynamic: license-file
|
|
30
32
|
|
|
31
33
|
# Priorwork
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"""手元の AI(視覚モデル)のつなぎ先。画像だけの PDF を読むのは Refolio(scan.py)で、ここは設定と確認だけ。
|
|
2
|
+
|
|
3
|
+
Octavo の `octavo ai` と同じ口: OpenAI 互換の `<url>/chat/completions`(Ollama・LM Studio・llama.cpp の server・vLLM)。
|
|
4
|
+
|
|
5
|
+
- 設定は、環境変数 > ワークスペースの `.env` > このマシンの `~/.config/refolio/env`(Octavo・Refolio と共有。
|
|
6
|
+
そこでは AI_URL・AI_MODEL・AI_TIMEOUT・AI_ALLOW)。Priorwork の名前は PRIORWORK_AI_URL・PRIORWORK_AI_MODEL・
|
|
7
|
+
PRIORWORK_AI_TIMEOUT(既定 600 秒)・PRIORWORK_AI_ALLOW(localhost のほかに手元とみなすホスト。カンマ区切り)。
|
|
8
|
+
- **鍵は読まない。** Priorwork は LLM の API キーを使わない。鍵の要らない、手元のサーバーのためのもの。
|
|
9
|
+
"""
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
import os
|
|
13
|
+
from dataclasses import dataclass
|
|
14
|
+
from typing import Any, Dict, Optional
|
|
15
|
+
|
|
16
|
+
import requests
|
|
17
|
+
|
|
18
|
+
from . import __version__
|
|
19
|
+
from .i18n import t
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class AIError(Exception):
|
|
23
|
+
pass
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@dataclass
|
|
27
|
+
class Endpoint:
|
|
28
|
+
url: str
|
|
29
|
+
model: str
|
|
30
|
+
timeout: int
|
|
31
|
+
allow: str = ""
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def endpoint() -> Optional[Endpoint]:
|
|
35
|
+
"""設定されたつなぎ先。PRIORWORK_AI_URL が無ければ None(使わない)。モデルが無ければ AIError。"""
|
|
36
|
+
url = (os.environ.get("PRIORWORK_AI_URL") or "").strip()
|
|
37
|
+
if not url:
|
|
38
|
+
return None
|
|
39
|
+
if not url.startswith(("http://", "https://")):
|
|
40
|
+
raise AIError(t("PRIORWORK_AI_URL must be an http:// or https:// address (for example "
|
|
41
|
+
"http://localhost:11434/v1 for Ollama)"))
|
|
42
|
+
model = (os.environ.get("PRIORWORK_AI_MODEL") or "").strip()
|
|
43
|
+
if not model:
|
|
44
|
+
raise AIError(t("PRIORWORK_AI_URL is set but PRIORWORK_AI_MODEL is not: set the vision model to use "
|
|
45
|
+
"(for example qwen2.5vl:7b)"))
|
|
46
|
+
try:
|
|
47
|
+
timeout = int(os.environ.get("PRIORWORK_AI_TIMEOUT") or 600)
|
|
48
|
+
except ValueError:
|
|
49
|
+
timeout = 600
|
|
50
|
+
allow = ",".join(h.strip() for h in (os.environ.get("PRIORWORK_AI_ALLOW") or "").split(",") if h.strip())
|
|
51
|
+
return Endpoint(url.rstrip("/"), model, max(timeout, 1), allow)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def _request(ep: Endpoint, method: str, path: str) -> Dict[str, Any]:
|
|
55
|
+
try:
|
|
56
|
+
r = requests.request(method, ep.url + path, timeout=min(ep.timeout, 30),
|
|
57
|
+
headers={"User-Agent": f"priorwork/{__version__}"})
|
|
58
|
+
except requests.RequestException as e:
|
|
59
|
+
raise AIError(t("could not reach the AI at {url} ({reason}); is the server running?",
|
|
60
|
+
url=ep.url, reason=e)) from e
|
|
61
|
+
if not r.ok:
|
|
62
|
+
raise AIError(t("the AI at {url} answered {code}: {detail}", url=ep.url, code=r.status_code,
|
|
63
|
+
detail=(r.text or "")[:300].strip() or r.reason))
|
|
64
|
+
try:
|
|
65
|
+
return r.json()
|
|
66
|
+
except ValueError as e:
|
|
67
|
+
raise AIError(t("the AI at {url} did not answer in JSON", url=ep.url)) from e
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def check(ep: Endpoint) -> str:
|
|
71
|
+
"""つなぎ先が答えるか(GET <url>/models)。答えなければ AIError。"""
|
|
72
|
+
got = _request(ep, "GET", "/models")
|
|
73
|
+
models = [str(m.get("id")) for m in got.get("data", []) if isinstance(m, dict)]
|
|
74
|
+
if models and ep.model not in models:
|
|
75
|
+
raise AIError(t("the server at {url} does not list the model {model}", url=ep.url, model=ep.model))
|
|
76
|
+
return t("{model} at {url}", model=ep.model, url=ep.url)
|
|
@@ -27,15 +27,23 @@ from urllib.parse import quote, urlencode
|
|
|
27
27
|
|
|
28
28
|
import requests
|
|
29
29
|
|
|
30
|
-
from . import ssci
|
|
30
|
+
from . import machine, ssci
|
|
31
31
|
from .i18n import t
|
|
32
32
|
from .ssci import classify_paper
|
|
33
33
|
from .workspace import ROOT
|
|
34
34
|
|
|
35
35
|
|
|
36
36
|
def _load_dotenv():
|
|
37
|
-
"""Load <workspace>/.env regardless of the current working directory
|
|
38
|
-
|
|
37
|
+
"""Load <workspace>/.env regardless of the current working directory, then this machine's shared settings
|
|
38
|
+
file (~/.config/refolio/env) for what is still unset. machine.SOURCES records where each value came from."""
|
|
39
|
+
before = {k for k, v in os.environ.items() if v}
|
|
40
|
+
_load_workspace_env(ROOT / ".env")
|
|
41
|
+
machine.SOURCES.update({k: "env" for k in before})
|
|
42
|
+
machine.SOURCES.update({k: "workspace" for k, v in os.environ.items() if v and k not in before})
|
|
43
|
+
machine.SOURCES.update(machine.fill_environ(before))
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def _load_workspace_env(path: Path):
|
|
39
47
|
if not path.exists():
|
|
40
48
|
return
|
|
41
49
|
try:
|
|
@@ -135,7 +135,7 @@ The workspace is kept in a private GitHub repository. You may operate Git withou
|
|
|
135
135
|
|
|
136
136
|
## Zotero
|
|
137
137
|
|
|
138
|
-
Write to Zotero only with `./priorwork zotero <survey> --add`, and only when the user has allowed it in the settings (`ZOTERO_WRITE=1` in `.env`). Otherwise the user adds to Zotero by hand. Never call the Zotero API yourself or change Zotero's data files. The setting that allows writing (`.env`) is the user's to change.
|
|
138
|
+
Write to Zotero only with `./priorwork zotero <survey> --add`, and only when the user has allowed it in the settings (`ZOTERO_WRITE=1` in `.env`). (`./priorwork fulltext` also attaches the text it recognised from a scanned PDF to that paper, when allowed; `--undo` takes that back too.) Otherwise the user adds to Zotero by hand. Never call the Zotero API yourself or change Zotero's data files. The setting that allows writing (`.env`) is the user's to change.
|
|
139
139
|
|
|
140
140
|
- **Every included paper is meant to be in Zotero, without exception.** Zotero is where the user manages the references for their own papers, so do not drop a paper from the list to add to Zotero because you could get its full text yourself (open access, for example).
|
|
141
141
|
- **The list to add to Zotero is always `./priorwork`'s output, as it is** (`./priorwork zotero <survey> --dois`, or `--add --dry-run`). Do not reselect or trim it. Give the number not in Zotero yet in your report (`./priorwork check` gives a WARN too).
|
|
@@ -39,6 +39,8 @@ In a survey made from a manuscript (`priorwork-manuscript`), the papers the draf
|
|
|
39
39
|
|
|
40
40
|
If the source is "Zotero's index text (no page breaks)", do not give page numbers; write "(page not checked)".
|
|
41
41
|
|
|
42
|
+
A scanned PDF (page images only) is read by OCR with Refolio (`refolio text`: NDLOCR-Lite, or a local vision model set in this machine's settings) when it is installed; the output says so. OCR can misread letters and numbers: give a number only where the text around it reads cleanly, and otherwise say in the card's notes that it comes from OCR text. If it cannot be read, `fulltext` fails and says how to set it up: do not install Refolio or its OCR yourself (`refolio setup --ocr` downloads about 0.5 GB) or start an AI server; list those papers in your final report and tell the user that installing Refolio (`pip install "priorwork[ocr]"`, then `refolio setup --ocr`), or setting a local vision model, would let you read them.
|
|
43
|
+
|
|
42
44
|
**Read it by parts** rather than opening the whole file. The references are kept apart already.
|
|
43
45
|
|
|
44
46
|
```bash
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Keys are best set once for the whole machine, in ~/.config/refolio/env (the same KEY=value lines;
|
|
2
|
+
# shared by every workspace, Octavo and Refolio; mode 600). The settings page and `priorwork settings`
|
|
3
|
+
# write there. A workspace's .env is only for what this one workspace needs differently: a value here
|
|
4
|
+
# wins over the machine's. To make one: cp .env.example .env
|
|
2
5
|
# .env.example is committed to Git (no secrets here). .env is in .gitignore — never commit it.
|
|
3
6
|
|
|
4
7
|
# Semantic Scholar API key (optional, recommended)
|
|
@@ -21,7 +24,9 @@ ZOTERO_API_KEY=
|
|
|
21
24
|
ZOTERO_USER_ID=
|
|
22
25
|
# Let priorwork add the included papers to the survey's Zotero collection (`priorwork zotero SURVEY --add`).
|
|
23
26
|
# Off unless set to 1; the key then also needs "Allow write access". It never edits or deletes your items
|
|
24
|
-
# (`--undo` takes back only what priorwork added).
|
|
27
|
+
# (`--undo` takes back only what priorwork added). With it, the text that `fulltext` recognises (OCR)
|
|
28
|
+
# from a scanned PDF is also attached to the paper's item as <PDF name>_ocr.md (on WebDAV, the share
|
|
29
|
+
# must then be writable).
|
|
25
30
|
# ZOTERO_WRITE=1
|
|
26
31
|
|
|
27
32
|
# WebDAV file sync (e.g. Nextcloud). URL of the folder that contains Zotero's <key>.zip files,
|
|
@@ -46,3 +51,14 @@ ZOTERO_WEBDAV_PASSWORD=
|
|
|
46
51
|
# How to read PDFs: auto (Docling if installed, else pypdf), docling or pypdf.
|
|
47
52
|
# Docling keeps tables and headings; install it with: pip install "priorwork[docling]"
|
|
48
53
|
# PRIORWORK_PDF_ENGINE=
|
|
54
|
+
|
|
55
|
+
# Scanned PDFs are read by Refolio (pip install "priorwork[ocr]", then refolio setup --ocr).
|
|
56
|
+
# A local vision model reads the pages its OCR cannot: any OpenAI-compatible server on this machine
|
|
57
|
+
# (Ollama, LM Studio, llama.cpp's server, vLLM; the one Octavo uses). No API key is used.
|
|
58
|
+
# In ~/.config/refolio/env these are AI_URL, AI_MODEL, AI_TIMEOUT and AI_ALLOW; here:
|
|
59
|
+
# PRIORWORK_AI_URL=http://localhost:11434/v1
|
|
60
|
+
# PRIORWORK_AI_MODEL=qwen2.5vl:7b
|
|
61
|
+
# Seconds to wait for one page (default 600)
|
|
62
|
+
# PRIORWORK_AI_TIMEOUT=
|
|
63
|
+
# Hosts besides localhost that count as this machine's (comma-separated)
|
|
64
|
+
# PRIORWORK_AI_ALLOW=
|
|
@@ -135,7 +135,7 @@
|
|
|
135
135
|
|
|
136
136
|
## Zotero
|
|
137
137
|
|
|
138
|
-
Zotero に書き込むのは、ユーザーが設定で許したとき(`.env` の `ZOTERO_WRITE=1`)に `./priorwork zotero <survey> --add`
|
|
138
|
+
Zotero に書き込むのは、ユーザーが設定で許したとき(`.env` の `ZOTERO_WRITE=1`)に `./priorwork zotero <survey> --add` を使うときだけ(許されていれば、`./priorwork fulltext` もスキャンした PDF から文字認識した本文をその論文に添付する。これも `--undo` で戻る)。それ以外は、Zotero への追加はユーザーが手作業で行う。Zotero の API を直接呼んだり、Zotero のデータのファイルを書き換えたりしない。書き込みを許す設定(`.env`)は、ユーザーが自分で変える。
|
|
139
139
|
|
|
140
140
|
- **採用論文は、例外なくすべて Zotero に入れる前提**で扱う。Zotero はユーザーが論文を書くときの参考文献の管理の基盤なので、本文をオープンアクセスなどで自分で取得できた論文も、Zotero に入れる一覧から外さない。
|
|
141
141
|
- Zotero に入れる一覧は、**必ず `./priorwork` の出力をそのまま使う**(`./priorwork zotero <survey> --dois`、または `--add --dry-run`)。自分で選び直したり、絞ったりしない。報告では未登録の本数を伝える(`./priorwork check` も WARN で出す)。
|
|
@@ -39,6 +39,8 @@ description: >-
|
|
|
39
39
|
|
|
40
40
|
取得元が「Zotero の索引テキスト(ページ区切りなし)」の場合、ページ番号は書かず「(ページ未確認)」とする。
|
|
41
41
|
|
|
42
|
+
スキャンした PDF(ページの画像だけ)は、Refolio が入っていれば、それで文字認識(OCR)して読む(`refolio text`。NDLOCR-Lite か、このマシンの設定にある手元の視覚モデル)。そのことは出力に出る。文字認識は文字や数字を読み違えることがある。数字は前後の文が正しく読めている所でだけ書き、そうでなければカードのメモに文字認識の本文から取ったと書く。読めなければ `fulltext` は失敗して入れ方を示す。自分では Refolio もその文字認識も入れず(`refolio setup --ocr` は約 0.5 GB を取ってくる)、AI のサーバーも起動しない。その論文を最後の報告に挙げ、Refolio を入れるか(`pip install "priorwork[ocr]"` の後に `refolio setup --ocr`)、手元の視覚モデルを設定すれば本文で読めるとユーザーに伝える。
|
|
43
|
+
|
|
42
44
|
**ファイル全体を開かず、部分ごとに読む。** 参照文献はすでに別に分けてある。
|
|
43
45
|
|
|
44
46
|
```bash
|
|
@@ -635,7 +635,12 @@ def _check_one_octavo(survey: Survey, md: str, info: dict) -> List[Finding]:
|
|
|
635
635
|
theirs = info["zotero_collections"]
|
|
636
636
|
ours = survey.zotero_collection.get("name", "")
|
|
637
637
|
shown = ", ".join(f'"{c}"' for c in theirs)
|
|
638
|
-
|
|
638
|
+
# Octavo の zotero_linked(サーベイごとのコレクション): .bib には入らないが、`octavo bib tidy` が引用された論文を
|
|
639
|
+
# 主のコレクションに足す
|
|
640
|
+
linked = bool(ours) and any(within_collection(ours, c) for c in info.get("zotero_linked") or [])
|
|
641
|
+
if linked:
|
|
642
|
+
pass
|
|
643
|
+
elif theirs and ours and not any(within_collection(ours, c) for c in theirs):
|
|
639
644
|
findings.append((WARN, t("The Zotero collection of the survey (\"{ours}\") is not among those the Octavo "
|
|
640
645
|
"project {project} pulls its .bib from ({theirs}), nor under them, so its papers will "
|
|
641
646
|
"not reach the .bib. Add it in Octavo (Choose the Zotero Collection), or link the "
|
|
@@ -661,7 +666,12 @@ def _check_one_octavo(survey: Survey, md: str, info: dict) -> List[Finding]:
|
|
|
661
666
|
except RuntimeError:
|
|
662
667
|
cited = set()
|
|
663
668
|
in_text = [e for e in absent if e["key"] in cited]
|
|
664
|
-
if in_text:
|
|
669
|
+
if in_text and linked:
|
|
670
|
+
findings.append((WARN, t("The text written for the Octavo project {project} cites {n|# paper|# papers} not in "
|
|
671
|
+
"its .bib: {numbers}. The survey's collection is linked there, so in Octavo run "
|
|
672
|
+
"`octavo bib tidy --apply` (it adds cited papers to the main collection), then "
|
|
673
|
+
"`octavo bib pull`", project=project, n=len(in_text), numbers=_numbers(in_text))))
|
|
674
|
+
elif in_text:
|
|
665
675
|
findings.append((WARN, t("The text written for the Octavo project {project} cites {n|# paper|# papers} not in "
|
|
666
676
|
"its .bib: {numbers}. Add {n|it|them} to its Zotero collection, then `octavo bib pull`",
|
|
667
677
|
project=project, n=len(in_text), numbers=_numbers(in_text))))
|
|
@@ -14,7 +14,7 @@ from datetime import date
|
|
|
14
14
|
from pathlib import Path
|
|
15
15
|
from typing import Any, Dict, List, Optional, Tuple
|
|
16
16
|
|
|
17
|
-
from . import __version__, derived, i18n, scaffold, settings, ssci
|
|
17
|
+
from . import __version__, derived, i18n, machine, scaffold, settings, ssci
|
|
18
18
|
import requests
|
|
19
19
|
|
|
20
20
|
from .api import RETRY_STATUSES, ApiError, LiteratureClient, in_journals, not_research, parse_identifier
|
|
@@ -57,7 +57,7 @@ USAGE_LINES = [
|
|
|
57
57
|
" sync [--force|--diff] update AGENTS.md, the skills and ./priorwork to the engine's version",
|
|
58
58
|
" doctor [--online] diagnose the setup (API keys, SSCI list, engine version, …)",
|
|
59
59
|
" upgrade [--to X.Y.Z] update the engine to the latest (or given) version, then sync",
|
|
60
|
-
" settings show or change the API keys, Zotero and the SSCI list",
|
|
60
|
+
" settings show or change the API keys, Zotero, the local AI and the SSCI list",
|
|
61
61
|
"",
|
|
62
62
|
"Surveys",
|
|
63
63
|
" status [SURVEY] list the surveys / progress and next steps",
|
|
@@ -286,15 +286,28 @@ def cmd_settings(args, client):
|
|
|
286
286
|
changed = settings.update(ROOT, values)
|
|
287
287
|
if not args.json:
|
|
288
288
|
print(t("Updated: {names}", names=", ".join(changed)) if changed else t("no changes"))
|
|
289
|
+
if args.move_to_machine:
|
|
290
|
+
got = settings.move_to_machine(ROOT)
|
|
291
|
+
if not args.json:
|
|
292
|
+
print(t("Moved to {path}: {names}", path=machine.path(), names=", ".join(got["moved"]))
|
|
293
|
+
if got["moved"] else t("no changes"))
|
|
294
|
+
if got["conflicts"]:
|
|
295
|
+
print("[Notice] " + t("Not moved, because {path} has another value (remove one of them on the settings "
|
|
296
|
+
"page): {names}", path=machine.path(), names=", ".join(got["conflicts"])),
|
|
297
|
+
file=sys.stderr)
|
|
289
298
|
if args.json:
|
|
290
299
|
return dump_json(settings.status(ROOT))
|
|
291
|
-
if not (args.stdin or args.import_ssci or args.import_scie):
|
|
300
|
+
if not (args.stdin or args.import_ssci or args.import_scie or args.move_to_machine):
|
|
292
301
|
st = settings.status(ROOT)
|
|
293
|
-
print(st["
|
|
302
|
+
print(t("This machine: {path}", path=st["machine"]) + ("" if st["machine_exists"] else " " + t("(not created yet)")))
|
|
303
|
+
print(t("This workspace: {path}", path=st["env"]) + ("" if st["exists"] else " " + t("(not created yet)")))
|
|
304
|
+
where = {"workspace": ".env", "machine": t("this machine")}
|
|
294
305
|
for item in st["items"]:
|
|
295
306
|
shown = t("set") if item["set"] else t("not set")
|
|
296
307
|
if item["value"]:
|
|
297
308
|
shown += f" ({item['value']})"
|
|
309
|
+
if item["source"]:
|
|
310
|
+
shown += f" [{where[item['source']]}]"
|
|
298
311
|
print(f" {item['key']}: {shown}")
|
|
299
312
|
print(t("SSCI journal list") + ": " + (f"{st['ssci']['file']} ({st['ssci']['journals']})" if st["ssci"]["file"]
|
|
300
313
|
else t("not set")))
|
|
@@ -478,7 +491,9 @@ def cmd_status(args, client):
|
|
|
478
491
|
for p in s.octavo_projects:
|
|
479
492
|
print(t("Octavo project: {root} | .bib: {bib} | Zotero collections: {collections}", root=p["root"],
|
|
480
493
|
bib=(Path(p["bib"]).name if p["bib"] else "-") + ("" if p["bib_exists"] else " " + t("(not there yet)")),
|
|
481
|
-
collections=", ".join(p["zotero_collections"]) or t("(not set)"))
|
|
494
|
+
collections=", ".join(p["zotero_collections"]) or t("(not set)"))
|
|
495
|
+
+ (" | " + t("linked: {collections}", collections=", ".join(p["zotero_linked"]))
|
|
496
|
+
if p.get("zotero_linked") else ""))
|
|
482
497
|
roots = {p["root"] for p in s.octavo_projects}
|
|
483
498
|
if roots:
|
|
484
499
|
others = [o for o in Survey.list_all() if o.name != s.name and roots & {p["root"] for p in o.octavo_projects}]
|
|
@@ -1274,6 +1289,12 @@ def cmd_fulltext(args, client):
|
|
|
1274
1289
|
entry["fulltext_failed"] = {"at": now_iso(), "reason": str(e).splitlines()[0]}
|
|
1275
1290
|
s.save()
|
|
1276
1291
|
raise
|
|
1292
|
+
zocr = info.pop("zotero_ocr", None)
|
|
1293
|
+
if zocr: # Zotero に足した OCR の本文の添付は、ほかの書き込みと同じく記録して --undo で戻せるようにする
|
|
1294
|
+
s.set_zotero_written([*s.zotero_written, {"number": entry["number"], "key": zocr["key"], "action": "ocr",
|
|
1295
|
+
"collection": "", "version": zocr["version"], "at": now_iso(),
|
|
1296
|
+
"filename": zocr["filename"]}])
|
|
1297
|
+
info["zotero_attachment"] = zocr["key"]
|
|
1277
1298
|
entry["fulltext"] = info
|
|
1278
1299
|
entry.pop("fulltext_failed", None)
|
|
1279
1300
|
s.save()
|
|
@@ -1302,7 +1323,13 @@ def cmd_fulltext(args, client):
|
|
|
1302
1323
|
if info.get("references_chars"):
|
|
1303
1324
|
print(t("* The references ({chars} characters) are kept apart: `--references` shows them",
|
|
1304
1325
|
chars=f"{info['references_chars']:,}"))
|
|
1305
|
-
if info.get("
|
|
1326
|
+
if info.get("ocr"):
|
|
1327
|
+
print(t("* The PDF is scanned page images, so this is text recognised by OCR: letters and numbers can be wrong. "
|
|
1328
|
+
"Check numbers against the page in the PDF"))
|
|
1329
|
+
if info.get("zotero_attachment"):
|
|
1330
|
+
print(t("* Added the recognised text to the paper in Zotero (an _ocr.md attachment); next time it is read "
|
|
1331
|
+
"from there"))
|
|
1332
|
+
elif info.get("extractor") == "docling":
|
|
1306
1333
|
print(t("* Read with Docling: headings and tables are kept as Markdown"))
|
|
1307
1334
|
else:
|
|
1308
1335
|
print(t("* Extracted text can garble columns, tables and formulas. Check numbers against the page in the PDF too."))
|
|
@@ -1407,10 +1434,12 @@ def print_written(written: List[Dict[str, Any]], coll: Dict[str, str], add: bool
|
|
|
1407
1434
|
else:
|
|
1408
1435
|
print(t("Would undo (nothing written yet):") if dry_run else t("Undid what Priorwork wrote to Zotero:"))
|
|
1409
1436
|
labels = {"create": t("new item from the bibliographic data"), "collect": t("item already in the library"),
|
|
1437
|
+
"ocr": t("the recognised text (_ocr.md) attached to the item"),
|
|
1410
1438
|
"trash": t("to the Zotero trash"), "keep": t("kept (changed in Zotero since)"),
|
|
1411
1439
|
"uncollect": t("out of the collection"), "gone": t("no longer in Zotero")}
|
|
1412
1440
|
if not add and dry_run: # 作ったアイテムに手が入ったかは、書くときに確かめる
|
|
1413
|
-
labels.update(create=t("to the Zotero trash, unless changed in Zotero since"), collect=labels["uncollect"]
|
|
1441
|
+
labels.update(create=t("to the Zotero trash, unless changed in Zotero since"), collect=labels["uncollect"],
|
|
1442
|
+
ocr=t("the recognised text (_ocr.md) to the Zotero trash, unless changed since"))
|
|
1414
1443
|
for w in written:
|
|
1415
1444
|
if not dry_run and not w.get("done"):
|
|
1416
1445
|
what = t("failed: {error}", error=w.get("error", ""))
|
|
@@ -1798,7 +1827,10 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
1798
1827
|
p.add_argument("--online", action="store_true", help=t("also check the connections to Semantic Scholar, OpenAlex and Zotero"))
|
|
1799
1828
|
|
|
1800
1829
|
p = sub.add_parser("settings", parents=[common, as_json],
|
|
1801
|
-
help=t("show or change the settings
|
|
1830
|
+
help=t("show or change the settings (API keys, Zotero, local AI) and the SSCI list"))
|
|
1831
|
+
p.add_argument("--move-to-machine", action="store_true",
|
|
1832
|
+
help=t("move the keys in the workspace's .env to this machine's settings (~/.config/refolio/env), "
|
|
1833
|
+
"shared by every workspace, Octavo and Refolio"))
|
|
1802
1834
|
p.add_argument("--stdin", action="store_true",
|
|
1803
1835
|
help=t("read the values to write as a JSON object from stdin (an empty string removes one)"))
|
|
1804
1836
|
p.add_argument("--import-ssci", metavar="CSV", help=t("import the SSCI list downloaded from the Master Journal List"))
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
- カードには要旨か本文に書かれていることだけを書き、確認レベルを更新する。
|
|
29
29
|
- 利用者に論文を示すときは「著者 (年)」で、番号では示さない。
|
|
30
30
|
- 終わったと言う前に `./priorwork check` を実行する。
|
|
31
|
-
- Zotero への書き込みは `./priorwork zotero --add`
|
|
31
|
+
- Zotero への書き込みは `./priorwork zotero --add`(と `fulltext` が添付する文字認識の本文)だけで、許されているとき(`ZOTERO_WRITE=1`)だけだ。
|
|
32
32
|
- Git では、サーベイ名のブランチで作業し、コミット・push して PR を作る。マージはしない。
|
|
33
33
|
- Priorwork 自体のファイル(`.venv` の中)、`AGENTS.md`、スキルは開かず、直さない。そのワークスペースだけの指示は `AGENTS.local.md` にある。
|
|
34
34
|
|
|
@@ -43,7 +43,7 @@ my-surveys/
|
|
|
43
43
|
├── .agent/skills/ # 工程ごとのスキル(.claude/skills からも見える)
|
|
44
44
|
├── priorwork # ./priorwork(エージェントが実行するもの)
|
|
45
45
|
├── requirements.txt # エンジンの版(priorwork==X.Y.Z)
|
|
46
|
-
├── .env #
|
|
46
|
+
├── .env # このワークスペースだけの設定。~/.config/refolio/env より優先(Git に載せない)
|
|
47
47
|
└── .priorwork/
|
|
48
48
|
├── config.json # ワークスペースの言語
|
|
49
49
|
├── surveys/ # サーベイごとの状態(Git に載せる)
|
|
@@ -266,6 +266,8 @@ my-surveys/
|
|
|
266
266
|
- **ファイル全体でなく、部分ごとに読む**(論文 1 本でおよそ 2 万トークン)。参照文献の節は別に分ける(`<ファイル>.refs.txt`)。その後ろの付録は残す。`--outline`・`--pages`・`--grep` は保存した本文を読み、取り直さない。これより前に保存した本文も、こうして読むときに分ける。
|
|
267
267
|
- **ほかのサーベイの本文を使う。** ワークスペースのほかのサーベイに同じ論文の本文(欠けておらず WP 版でないもの)があれば、`fulltext` はそれを使う。`--refresh` で取り直す。
|
|
268
268
|
- **PDF の読み取り。** Docling を入れると(`pip install "priorwork[docling]"`。PyTorch ごと入るので 1〜2 GB)、手元のレイアウトのモデルが PDF を Markdown にする: 表は表のまま、見出しに印が付き、ページのヘッダー・フッターは除かれる。CPU で 1 ページ 2〜3 秒ほどかかり、API キーは要らない。ページの区切りは pypdf と同じく `=== page N ===`。`PRIORWORK_PDF_ENGINE=pypdf|docling` で固定できる(既定は `auto`)。Docling で読めない PDF は pypdf で読む。どちらを使うかは `doctor` に出る。
|
|
269
|
+
- **スキャンした PDF(ページの画像だけ)は、Refolio で文字認識(OCR)して読む。** Refolio はファミリーの PDF の道具(`pip install "priorwork[ocr]"` で `refolio>=0.1.6` が入る)。`fulltext` は `refolio text --json` を動かし、ページごとに、文字層があればそれを、無ければ NDLOCR-Lite(手元の文字認識。日本語や古い印刷物に強い。`refolio setup --ocr` で入れる。約 0.5 GB)で、それも無ければ手元の視覚モデルで読む。Refolio が無ければ、入れ方を示す。情報には `"ocr": "refolio"` と出て、出力は文字や数字の読み違いがありうると知らせる。数字は PDF のページで確かめる。`ZOTERO_WRITE=1` で論文が Zotero にあれば、その本文を `<PDF の名前>_ocr.md` としてアイテムに添付し(タグ `priorwork:ocr`。メモには何で読んだかを書く)、サーベイの Zotero への書き込みとして記録する(`zotero --undo` でごみ箱へ)。次からは、どのマシンでも、`fulltext` がその添付を読み(`"ocr": "zotero"`)、文字認識し直さない。WebDAV のときは共有が書き込めることが要る。書き込めなければ何も足さず、本文は手元のキャッシュにだけ残る。
|
|
270
|
+
- **手元の視覚モデル。** このマシンの設定(下)の `AI_URL`(OpenAI 互換のサーバー。Ollama・LM Studio・llama.cpp の server・vLLM など。例: `http://localhost:11434/v1`)と `AI_MODEL`(視覚モデル)。Octavo・Refolio と同じもの。Priorwork はこれを Refolio に渡す(`--ai-url`・`--ai-model`、`AI_ALLOW` からは `--ai-allow`。localhost のほかに手元とみなすホスト)。Refolio はそうした手元のホストにしかページを送らない。API キーは送らず、読まない。`AI_TIMEOUT` は 1 ページを待つ秒数(既定 600)。`doctor` はスキャンした PDF を何で読むかを示し、接続の確認ではサーバーにモデルの一覧を問い合わせる(`GET <url>/models`)。
|
|
269
271
|
|
|
270
272
|
---
|
|
271
273
|
|
|
@@ -361,8 +363,8 @@ my-surveys/
|
|
|
361
363
|
./priorwork zotero SURVEY --undo
|
|
362
364
|
```
|
|
363
365
|
|
|
364
|
-
-
|
|
365
|
-
- 既定では読むだけだ。`--add` には `ZOTERO_WRITE=1` と書き込める鍵が要る。ライブラリにある項目(同じ DOI
|
|
366
|
+
- 設定([10.1](#101-このマシンの設定とワークスペースの設定)): `ZOTERO_API_KEY`、`ZOTERO_USER_ID`、`ZOTERO_DATA_DIR`(ローカルの Zotero)、`ZOTERO_WEBDAV_URL` / `_USER` / `_PASSWORD`(WebDAV のファイル同期)は Octavo と共有。`ZOTERO_WRITE` はワークスペースの `.env` に。
|
|
367
|
+
- 既定では読むだけだ。`--add` には `ZOTERO_WRITE=1` と書き込める鍵が要る。ライブラリにある項目(同じ DOI か題)はコレクションに加え、無ければ新しく作る。項目を変えたり消したりせず、ほかのコレクションに触れず、コレクションも作らない。ほかに書くのは、スキャンした PDF の文字認識の本文を `fulltext` が添付することだけ(5 節)。`--undo` は Priorwork が書いたものだけを戻す。標準の進め方ではカードの前の停止で一覧を示し、利用者が同意してから入れる。全自動では止まらずに入れ、手動では毎回尋ねる。
|
|
366
368
|
- 結び付けると、「Zotero にある」はそのコレクション(とその下)にあることで、本文もまずその PDF から取る。
|
|
367
369
|
- ライブラリは zotero.org から読み、`.priorwork/cache/zotero/` に置く(変わった分だけ読む。`--refresh` で全部)。そこで PDF の無い論文は、`fulltext` がその論文の添付だけを Zotero に聞き直す。同じ論文がライブラリに2件あれば PDF のある方を使い、両方のキーをお知らせに出す。Zotero の「重複アイテム」で統合するようユーザーに頼む。
|
|
368
370
|
|
|
@@ -401,6 +403,7 @@ my-surveys/
|
|
|
401
403
|
```bash
|
|
402
404
|
./priorwork settings # 設定(キーの値は出さない)
|
|
403
405
|
./priorwork settings --stdin # 標準入力の KEY=VALUE の行で設定する
|
|
406
|
+
./priorwork settings --move-to-machine # .env のキーを、このマシンの設定に移す
|
|
404
407
|
./priorwork settings --import-ssci SSCI.csv # Clarivate の Master Journal List の SSCI リスト
|
|
405
408
|
./priorwork doctor --online
|
|
406
409
|
./priorwork sync # AGENTS.md とスキルをエンジンの版に(--diff、--force)
|
|
@@ -413,10 +416,17 @@ my-surveys/
|
|
|
413
416
|
| `OPENALEX_API_KEY`、`OPENALEX_MAILTO` | 任意 |
|
|
414
417
|
| `NCBI_API_KEY` | 任意。PubMed はこれがあれば毎秒 10 件、なければ 3 件まで |
|
|
415
418
|
| `ZOTERO_*` | [8](#8-zotero) |
|
|
419
|
+
| `AI_URL`、`AI_MODEL`、`AI_TIMEOUT`、`AI_ALLOW` | スキャンした PDF を読む手元の視覚モデル([5.2](#52-本文)) |
|
|
416
420
|
|
|
417
421
|
SSCI の表示: ✅ リストで確認、🟡 約 100 誌の組み込みのリストから推定(要確認)、🔍 不明、⚪ リストに無い。📕 本・❌ ワーキングペーパーとプレプリント・❓ 掲載先不明は、既定で検索結果から除く。
|
|
418
422
|
|
|
419
|
-
### 10.1
|
|
423
|
+
### 10.1 このマシンの設定と、ワークスペースの設定
|
|
424
|
+
|
|
425
|
+
- **このマシンの設定ファイル** `~/.config/refolio/env`(どの OS でも。Linux で `XDG_CONFIG_HOME` があれば `$XDG_CONFIG_HOME/refolio/env`。`REFOLIO_CONFIG` で別の場所を指せる)は、Priorwork・Octavo・Refolio が共有する。API キー・Zotero・手元の AI・雑誌リストの場所を、どのワークスペースにも一度で設定する。`.env` と同じ形(`KEY=value`。`#` がコメントになるのは行頭だけ)。本人だけが読めるようにする(権限 600)。ほかの人も読めれば Priorwork が警告し、作るときは 600 で作る。Priorwork が読む AI の鍵は、ここにも無い。
|
|
426
|
+
- **ワークスペースの `.env`** はそれより優先され、そのワークスペースだけで変えたいものと、`ZOTERO_WRITE`(サーベイごとに決めるもの)を置く。プロセスの環境変数は、その両方より優先される。そこでの手元の AI の名前は `PRIORWORK_AI_URL`・`PRIORWORK_AI_MODEL`・`PRIORWORK_AI_TIMEOUT`・`PRIORWORK_AI_ALLOW`。接頭辞の無い `AI_URL` の環境変数は読まない。
|
|
427
|
+
- `settings`(と設定ページ)は、いま効いている側に書く: `.env` にそのキーの値があれば `.env` に、無ければこのマシンの設定に。`settings --move-to-machine` は `.env` のキーをこのマシンの設定に移す(そこに別の値があるキーは移さず、名前を示す)。`doctor` は、ファイルと、そこから使っているキーと、`.env` が上書きしているキーを示す。
|
|
428
|
+
|
|
429
|
+
### 10.2 再試行・キャッシュ・表示の言語
|
|
420
430
|
|
|
421
431
|
- 再試行: HTTP 429・5xx・通信エラーは 5・10・20・40・60 秒待って、最大 5 回(`PRIORWORK_MAX_RETRIES`)。
|
|
422
432
|
- キャッシュ: API の応答を `~/.cache/priorwork/` に 7 日保存する(`PRIORWORK_CACHE_TTL_DAYS`。`PRIORWORK_NO_CACHE=1` か `--no-cache` で使わない)。
|
|
@@ -32,8 +32,8 @@ survey**; this page is what each command does.
|
|
|
32
32
|
- Cards hold only what the abstract or the full text says, with the evidence level updated.
|
|
33
33
|
- Name papers as "Author (year)" when talking to the user, not by number.
|
|
34
34
|
- Run `./priorwork check` before calling anything finished.
|
|
35
|
-
- Write to Zotero only through `./priorwork zotero --add
|
|
36
|
-
(`ZOTERO_WRITE=1`).
|
|
35
|
+
- Write to Zotero only through `./priorwork zotero --add` (and the OCR text that `fulltext` attaches),
|
|
36
|
+
and only when it is allowed (`ZOTERO_WRITE=1`).
|
|
37
37
|
- In Git, work on a branch named after the survey, commit and push, open a pull request; never merge.
|
|
38
38
|
- Never open or edit Priorwork's own files (inside `.venv`), `AGENTS.md` or the skills; instructions
|
|
39
39
|
for one workspace go in `AGENTS.local.md`.
|
|
@@ -49,7 +49,7 @@ my-surveys/
|
|
|
49
49
|
├── .agent/skills/ # the skills for each step (also seen through .claude/skills)
|
|
50
50
|
├── priorwork # ./priorwork (what the agent runs)
|
|
51
51
|
├── requirements.txt # the engine's version (priorwork==X.Y.Z)
|
|
52
|
-
├── .env #
|
|
52
|
+
├── .env # this workspace's own settings, over ~/.config/refolio/env (not in Git)
|
|
53
53
|
└── .priorwork/
|
|
54
54
|
├── config.json # the workspace's language
|
|
55
55
|
├── surveys/ # the state of each survey (in Git)
|
|
@@ -328,6 +328,24 @@ pages). Only the extracted text is kept, in `.priorwork/cache/fulltext/`. A fail
|
|
|
328
328
|
page headers and footers go. It takes about 2–3 seconds a page on a CPU, and no API key. Page breaks
|
|
329
329
|
are kept as `=== page N ===`, as with pypdf. `PRIORWORK_PDF_ENGINE=pypdf|docling` fixes the choice
|
|
330
330
|
(default `auto`); if Docling fails on a PDF, pypdf reads it. `doctor` shows which one is used.
|
|
331
|
+
- **Scanned PDFs (page images only) are read by OCR, with Refolio.** Refolio is the family's PDF
|
|
332
|
+
tool (`pip install "priorwork[ocr]"` installs it as `refolio>=0.1.6`). `fulltext` runs
|
|
333
|
+
`refolio text --json`, which reads each page from its text layer, else with NDLOCR-Lite (local OCR,
|
|
334
|
+
strong on Japanese and old prints; installed with `refolio setup --ocr`, about 0.5 GB), else with a
|
|
335
|
+
local vision model. Without Refolio, `fulltext` says how to install it. The info says
|
|
336
|
+
`"ocr": "refolio"` and the output warns that letters and numbers can be misread: check numbers
|
|
337
|
+
against the PDF page. With `ZOTERO_WRITE=1` and the paper in Zotero, the text is attached to the
|
|
338
|
+
item as `<PDF name>_ocr.md` (tag `priorwork:ocr`; its note names what read it), logged with the
|
|
339
|
+
survey's Zotero writes (`zotero --undo` trashes it). Next time, on any machine, `fulltext` reads
|
|
340
|
+
that attachment (`"ocr": "zotero"`) instead of recognising the pages again. With WebDAV, the share
|
|
341
|
+
must be writable for this; if it is not, nothing is added and the text stays in the local cache.
|
|
342
|
+
- **The local vision model.** `AI_URL` (an OpenAI-compatible server such as Ollama, LM Studio,
|
|
343
|
+
llama.cpp's server or vLLM, e.g. `http://localhost:11434/v1`) and `AI_MODEL` (a vision model) in
|
|
344
|
+
this machine's settings (below), the same ones Octavo and Refolio use. Priorwork passes them to
|
|
345
|
+
Refolio (`--ai-url`, `--ai-model`, and `--ai-allow` from `AI_ALLOW`: hosts besides localhost that
|
|
346
|
+
count as this machine's); Refolio sends a page only to such a local host. No API key is sent or
|
|
347
|
+
read. `AI_TIMEOUT` is the seconds to wait for one page (default 600). `doctor` says how scanned
|
|
348
|
+
PDFs are read, and with the online checks asks the server for its models (`GET <url>/models`).
|
|
331
349
|
|
|
332
350
|
---
|
|
333
351
|
|
|
@@ -432,11 +450,13 @@ checked in the full text, and the length leaves out citations in parentheses unl
|
|
|
432
450
|
./priorwork zotero SURVEY --undo
|
|
433
451
|
```
|
|
434
452
|
|
|
435
|
-
- Settings
|
|
436
|
-
`ZOTERO_WEBDAV_URL` / `_USER` / `_PASSWORD` (file sync through
|
|
453
|
+
- Settings ([10.1](#101-this-machines-settings-and-the-workspaces)): `ZOTERO_API_KEY`, `ZOTERO_USER_ID`,
|
|
454
|
+
`ZOTERO_DATA_DIR` (a local Zotero), `ZOTERO_WEBDAV_URL` / `_USER` / `_PASSWORD` (file sync through
|
|
455
|
+
WebDAV), shared with Octavo; `ZOTERO_WRITE` in the workspace's `.env`.
|
|
437
456
|
- Reading only by default. `--add` needs `ZOTERO_WRITE=1` and a key with write access: an item
|
|
438
457
|
already in the library (same DOI or title) is added to the collection, otherwise a new item is
|
|
439
|
-
made; it never changes or deletes items, never touches other collections, never makes one.
|
|
458
|
+
made; it never changes or deletes items, never touches other collections, never makes one. The only
|
|
459
|
+
other write is the OCR text of a scanned PDF, attached by `fulltext` (section 5).
|
|
440
460
|
`--undo` takes back only what Priorwork wrote. In the standard mode show the list at the stop
|
|
441
461
|
before the cards and add once the user agrees; in auto add without stopping; in manual ask.
|
|
442
462
|
- Once linked, "in Zotero" means in that collection (and those under it); full texts come from
|
|
@@ -493,6 +513,7 @@ checked in the full text, and the length leaves out citations in parentheses unl
|
|
|
493
513
|
```bash
|
|
494
514
|
./priorwork settings # the settings (key values are never shown)
|
|
495
515
|
./priorwork settings --stdin # set them from KEY=VALUE lines on stdin
|
|
516
|
+
./priorwork settings --move-to-machine # move the keys in .env to this machine's settings
|
|
496
517
|
./priorwork settings --import-ssci SSCI.csv # the SSCI list from Clarivate's Master Journal List
|
|
497
518
|
./priorwork doctor --online
|
|
498
519
|
./priorwork sync # AGENTS.md and the skills to the engine's version (--diff, --force)
|
|
@@ -505,12 +526,30 @@ checked in the full text, and the length leaves out citations in parentheses unl
|
|
|
505
526
|
| `OPENALEX_API_KEY`, `OPENALEX_MAILTO` | optional |
|
|
506
527
|
| `NCBI_API_KEY` | optional; PubMed allows 10 requests a second with it, 3 without |
|
|
507
528
|
| `ZOTERO_*` | [8](#8-zotero) |
|
|
529
|
+
| `AI_URL`, `AI_MODEL`, `AI_TIMEOUT`, `AI_ALLOW` | the local vision model for scanned PDFs ([5.2](#52-full-texts)) |
|
|
508
530
|
|
|
509
531
|
The SSCI status: ✅ checked against the list, 🟡 guessed from a built-in list of about 100 journals
|
|
510
532
|
(verify), 🔍 unknown, ⚪ not in the list; 📕 books, ❌ working papers and preprints, ❓ unknown venues
|
|
511
533
|
are left out of searches by default.
|
|
512
534
|
|
|
513
|
-
### 10.1
|
|
535
|
+
### 10.1 This machine's settings, and the workspace's
|
|
536
|
+
|
|
537
|
+
- **This machine's settings file**, `~/.config/refolio/env` (on every OS; on Linux
|
|
538
|
+
`$XDG_CONFIG_HOME/refolio/env` when that is set; `REFOLIO_CONFIG` points elsewhere), is shared by
|
|
539
|
+
Priorwork, Octavo and Refolio: API keys, Zotero, the local AI and the journal lists' paths, set once
|
|
540
|
+
for every workspace. It is a `.env`-style file (`KEY=value`; `#` starts a comment only at the start
|
|
541
|
+
of a line). Keep it private (mode 600): Priorwork warns if others can read it, and makes it so
|
|
542
|
+
when it creates it. It never holds an AI key that Priorwork reads.
|
|
543
|
+
- **The workspace's `.env`** wins over it, for what one workspace needs differently, and holds
|
|
544
|
+
`ZOTERO_WRITE` (a per-survey decision). The process environment wins over both. The local AI's
|
|
545
|
+
names there are `PRIORWORK_AI_URL`, `PRIORWORK_AI_MODEL`, `PRIORWORK_AI_TIMEOUT` and
|
|
546
|
+
`PRIORWORK_AI_ALLOW`; a bare `AI_URL` in the environment is not read.
|
|
547
|
+
- `settings` (and the settings page) writes a key where its value is in effect: in `.env` if `.env`
|
|
548
|
+
has a value for it, else in this machine's file. `settings --move-to-machine` moves `.env`'s keys
|
|
549
|
+
to this machine's file (a key whose value differs there is left, and named). `doctor` shows the
|
|
550
|
+
file, the keys used from it, and those that `.env` overrides.
|
|
551
|
+
|
|
552
|
+
### 10.2 Retries, cache and language
|
|
514
553
|
|
|
515
554
|
- Retries: HTTP 429, 5xx and network errors wait 5, 10, 20, 40 and 60 s, up to 5 times (`PRIORWORK_MAX_RETRIES`).
|
|
516
555
|
- Cache: API responses stay in `~/.cache/priorwork/` for 7 days (`PRIORWORK_CACHE_TTL_DAYS`; `PRIORWORK_NO_CACHE=1` or `--no-cache` turns it off).
|
|
@@ -113,8 +113,21 @@ def run_checks(root: Path, client: Optional[Any] = None) -> List[Check]:
|
|
|
113
113
|
out.extend(git_checks(root))
|
|
114
114
|
|
|
115
115
|
# 設定
|
|
116
|
-
|
|
117
|
-
|
|
116
|
+
from . import machine
|
|
117
|
+
shared = machine.path()
|
|
118
|
+
from_shared = sorted(k for k, v in machine.SOURCES.items() if v == "machine")
|
|
119
|
+
if shared.is_file():
|
|
120
|
+
out.append((WARN if machine.loose(shared) else OK, t("Settings of this machine"),
|
|
121
|
+
t("{path}: {keys}", path=shared, keys=", ".join(from_shared) or t("nothing used from it"))
|
|
122
|
+
+ (" | " + t("others can read it: chmod 600 {path}", path=shared) if machine.loose(shared) else "")))
|
|
123
|
+
elif not (root / ".env").is_file():
|
|
124
|
+
out.append((WARN, t("Settings of this machine"), t(
|
|
125
|
+
"Neither {path} nor .env exists. Set your API keys in the settings (VS Code: Priorwork's Settings; "
|
|
126
|
+
"command line: `priorwork settings`); they are saved for the whole machine", path=shared)))
|
|
127
|
+
in_ws = sorted(k for k, v in machine.SOURCES.items() if v == "workspace" and machine.file_key(k) in machine.KEYS)
|
|
128
|
+
if in_ws:
|
|
129
|
+
out.append((OK, ".env", t("These come from the workspace's .env and win over the machine's settings: {keys}",
|
|
130
|
+
keys=", ".join(in_ws))))
|
|
118
131
|
if os.environ.get("SEMANTIC_SCHOLAR_API_KEY") or os.environ.get("S2_API_KEY"):
|
|
119
132
|
out.append((OK, "Semantic Scholar", t("An API key is set")))
|
|
120
133
|
else:
|
|
@@ -146,7 +159,7 @@ def run_checks(root: Path, client: Optional[Any] = None) -> List[Check]:
|
|
|
146
159
|
"(ZOTERO_WRITE=1)") if zotero.write else "")) if zotero
|
|
147
160
|
else (OK, "Zotero", t("Not set (optional; with it, priorwork can see what is in Zotero and fetch full texts)")))
|
|
148
161
|
|
|
149
|
-
from . import fulltext
|
|
162
|
+
from . import fulltext, scan
|
|
150
163
|
reader = t("PDF reader")
|
|
151
164
|
try:
|
|
152
165
|
engine = fulltext.pdf_engine()
|
|
@@ -154,7 +167,23 @@ def run_checks(root: Path, client: Optional[Any] = None) -> List[Check]:
|
|
|
154
167
|
out.append((WARN, reader, str(e)))
|
|
155
168
|
else:
|
|
156
169
|
out.append((OK, reader, t("Docling (tables and headings are kept)") if engine == "docling" else
|
|
157
|
-
t("pypdf (optional: `pip install \"priorwork[docling]\"` reads tables and headings
|
|
170
|
+
t("pypdf (optional: `pip install \"priorwork[docling]\"` reads tables and headings "
|
|
171
|
+
"with a local model)")))
|
|
172
|
+
from . import ai
|
|
173
|
+
try:
|
|
174
|
+
ep, ai_error = ai.endpoint(), ""
|
|
175
|
+
except ai.AIError as e:
|
|
176
|
+
ep, ai_error = None, str(e)
|
|
177
|
+
scans = t("Scanned PDFs")
|
|
178
|
+
if not scan.command():
|
|
179
|
+
out.append((OK, scans, t("Cannot be read (optional: `{install}` reads them with Refolio on this machine)",
|
|
180
|
+
install=scan.INSTALL)))
|
|
181
|
+
else:
|
|
182
|
+
out.append((WARN if ai_error else OK, scans, ai_error or (
|
|
183
|
+
t("Read with Refolio (NDLOCR-Lite if `refolio setup --ocr` was run, then the AI model {model} at {url})",
|
|
184
|
+
model=ep.model, url=ep.url) if ep else
|
|
185
|
+
t("Read with Refolio (NDLOCR-Lite, after `refolio setup --ocr`; `refolio doctor` tells whether it is "
|
|
186
|
+
"installed)"))))
|
|
158
187
|
if shutil.which("pandoc"):
|
|
159
188
|
out.append((OK, "pandoc", t("Found (`priorwork export --format docx` works)")))
|
|
160
189
|
else:
|
|
@@ -184,4 +213,11 @@ def _online_checks(client: Any, zotero: Optional[ZoteroClient]) -> List[Check]:
|
|
|
184
213
|
out.append((OK, t("Zotero writing"), t("The API key can write to the library")))
|
|
185
214
|
except ZoteroError as e:
|
|
186
215
|
out.append((NG, t("Zotero writing"), str(e)))
|
|
216
|
+
from . import ai
|
|
217
|
+
try:
|
|
218
|
+
ep = ai.endpoint()
|
|
219
|
+
if ep is not None:
|
|
220
|
+
out.append((OK, t("AI connection"), ai.check(ep)))
|
|
221
|
+
except ai.AIError as e: # 手元のサーバーが動いていないなど。Refolio は NDLOCR-Lite があればそれで読む
|
|
222
|
+
out.append((WARN, t("AI connection"), str(e)))
|
|
187
223
|
return out
|