rh-cli 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.
- rh/__init__.py +12 -0
- rh/add.py +105 -0
- rh/cli.py +799 -0
- rh/config.py +308 -0
- rh/paths.py +96 -0
- rh/resume.py +186 -0
- rh/search.py +123 -0
- rh/skills/research-helper/SKILL.md +497 -0
- rh/tasks.py +221 -0
- rh/ui.py +128 -0
- rh/workflow.py +268 -0
- rh_cli-0.1.0.dist-info/METADATA +217 -0
- rh_cli-0.1.0.dist-info/RECORD +17 -0
- rh_cli-0.1.0.dist-info/WHEEL +5 -0
- rh_cli-0.1.0.dist-info/entry_points.txt +2 -0
- rh_cli-0.1.0.dist-info/licenses/LICENSE +21 -0
- rh_cli-0.1.0.dist-info/top_level.txt +1 -0
rh/__init__.py
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"""research-helper CLI — makes SKILL.md easy for AI agents to adopt.
|
|
2
|
+
|
|
3
|
+
Storage: everything lives under `.rh/` in a project root (or $RH_HOME /
|
|
4
|
+
$XDG_CONFIG_HOME/rh as a global default). ENV.md remains the single config
|
|
5
|
+
source; .rh/env.json is the machine-readable mirror of the SKILL.md config
|
|
6
|
+
block, .rh/tasks.json is the machine-readable task board, and the SKILL.md
|
|
7
|
+
artifacts (PROBLEM.md, PLAN.md, ...) are kept at the root or inside .rh/ when
|
|
8
|
+
the user asked for a clean workspace.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
__version__ = "0.1.0"
|
|
12
|
+
__all__ = ["__version__"]
|
rh/add.py
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"""`rh add` — append under a heading/DOI, creating it if missing.
|
|
2
|
+
|
|
3
|
+
Targets:
|
|
4
|
+
note -> .rh/notes/<slug>.md (heading-created files)
|
|
5
|
+
literature -> LITERATURE.md (SKILL.md §3: citation + DOI + take/reject)
|
|
6
|
+
layout -> OUTPUT_LAYOUT.md (SKILL.md §3: output skeleton + paper patterns)
|
|
7
|
+
gaps -> GAPS.md
|
|
8
|
+
problem -> PROBLEM.md
|
|
9
|
+
plan -> PLAN.md
|
|
10
|
+
status -> STATUS.md
|
|
11
|
+
manuscript -> MANUSCRIPT.md
|
|
12
|
+
log -> .rh/logs/YYYY-MM-DD-HHMM-<role>-<slug>.md
|
|
13
|
+
task -> .rh/tasks.json via TaskStore
|
|
14
|
+
"""
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
import re
|
|
18
|
+
import unicodedata
|
|
19
|
+
from datetime import datetime
|
|
20
|
+
from pathlib import Path
|
|
21
|
+
|
|
22
|
+
from . import paths
|
|
23
|
+
|
|
24
|
+
ADD_TARGETS = {
|
|
25
|
+
"note": "notes",
|
|
26
|
+
"literature": "LITERATURE.md",
|
|
27
|
+
"layout": "OUTPUT_LAYOUT.md",
|
|
28
|
+
"gaps": "GAPS.md",
|
|
29
|
+
"problem": "PROBLEM.md",
|
|
30
|
+
"plan": "PLAN.md",
|
|
31
|
+
"status": "STATUS.md",
|
|
32
|
+
"manuscript": "MANUSCRIPT.md",
|
|
33
|
+
"log": "log",
|
|
34
|
+
"task": "task",
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def slugify(text: str) -> str:
|
|
39
|
+
text = unicodedata.normalize("NFKD", text).lower().strip()
|
|
40
|
+
text = re.sub(r"[^a-z0-9]+", "-", text).strip("-")
|
|
41
|
+
return text or "untitled"
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def _heading_re(heading: str) -> re.Pattern:
|
|
45
|
+
# match `## <heading>` exactly (case-insensitive)
|
|
46
|
+
return re.compile(rf"^##\s+{re.escape(heading)}\s*$", re.MULTILINE | re.IGNORECASE)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def _doi_re(doi: str) -> re.Pattern:
|
|
50
|
+
clean = doi.strip().removeprefix("https://doi.org/")
|
|
51
|
+
return re.compile(rf"doi[:\s]*{re.escape(clean)}", re.IGNORECASE)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def append_under(artifact: Path, heading: str, body: str, *, use_doi: bool = False) -> str:
|
|
55
|
+
"""Append `body` under `heading` (or create it). Returns 'created'|'appended'."""
|
|
56
|
+
artifact.parent.mkdir(parents=True, exist_ok=True)
|
|
57
|
+
text = artifact.read_text(encoding="utf-8") if artifact.exists() else ""
|
|
58
|
+
pattern = _doi_re(heading) if use_doi else _heading_re(heading)
|
|
59
|
+
m = pattern.search(text)
|
|
60
|
+
block = body.strip("\n") + "\n"
|
|
61
|
+
if m:
|
|
62
|
+
# append at end of that section: before next ## heading or EOF
|
|
63
|
+
nxt = re.search(r"\n## ", text[m.end():])
|
|
64
|
+
if nxt:
|
|
65
|
+
insert_at = m.end() + nxt.start()
|
|
66
|
+
text = text[:insert_at].rstrip() + "\n\n" + block + text[insert_at:].lstrip("\n")
|
|
67
|
+
else:
|
|
68
|
+
text = text.rstrip() + "\n\n" + block
|
|
69
|
+
result = "appended"
|
|
70
|
+
else:
|
|
71
|
+
title = heading if use_doi else f"## {heading}"
|
|
72
|
+
if use_doi:
|
|
73
|
+
title = f"## {heading}\n\nDOI: {heading}"
|
|
74
|
+
text = (text.rstrip() + "\n\n" if text.strip() else "") + title + "\n\n" + block
|
|
75
|
+
result = "created"
|
|
76
|
+
artifact.write_text(text, encoding="utf-8")
|
|
77
|
+
return result
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def add_note(root: Path, heading_or_file: str, body: str, *, file: str | None = None) -> tuple[Path, str]:
|
|
81
|
+
"""Note: file defaults to kebab of heading; heading is the ## section."""
|
|
82
|
+
name = file or f"{slugify(heading_or_file)}.md"
|
|
83
|
+
target = paths.notes_dir(root) / name
|
|
84
|
+
result = append_under(target, heading_or_file, body)
|
|
85
|
+
return target, result
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def add_log(root: Path, role: str, title: str, body: str) -> Path:
|
|
89
|
+
ts = datetime.now().strftime("%Y-%m-%d-%H%M")
|
|
90
|
+
target = paths.logs_dir(root) / f"{ts}-{slugify(role)}-{slugify(title)}.md"
|
|
91
|
+
target.parent.mkdir(parents=True, exist_ok=True)
|
|
92
|
+
text = f"# {title}\n- phase / step: \n- what was tried: \n- outcome: \n- evidence: \n- decision taken + why: \n- what a future agent must not redo: \n\n{body.strip()}\n"
|
|
93
|
+
target.write_text(text, encoding="utf-8")
|
|
94
|
+
return target
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def add_text(root: Path, target_kind: str, heading_or_doi: str, body: str) -> tuple[Path, str]:
|
|
98
|
+
if target_kind not in ADD_TARGETS or target_kind in ("note", "log", "task"):
|
|
99
|
+
raise ValueError(f"unknown add target {target_kind!r}; choices: {sorted(ADD_TARGETS)}")
|
|
100
|
+
artifact = paths.artifact_path(root, ADD_TARGETS[target_kind])
|
|
101
|
+
use_doi = target_kind == "literature" and re.search(
|
|
102
|
+
r"\b10\.\d{4,9}/", heading_or_doi, re.IGNORECASE
|
|
103
|
+
) is not None
|
|
104
|
+
result = append_under(artifact, heading_or_doi, body, use_doi=use_doi)
|
|
105
|
+
return artifact, result
|