Skip to content

Commit cdc254f

Browse files
authored
Upgrade asta-documents version (#15)
1 parent 2dfb44c commit cdc254f

File tree

4 files changed

+78
-52
lines changed

4 files changed

+78
-52
lines changed

skills/find-literature/SKILL.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,21 @@ Verify installation with `asta literature --help`
2929

3030
Run in background for comprehensive searches (30-60s):
3131
```bash
32-
# Saves to .asta/literature/find/YYYY-MM-DD-HH-MM-SS-{query-slug}.json by default
33-
Bash(command="asta literature find 'query' --timeout 300", run_in_background=true)
32+
# Save to a temporary file with explicit -o parameter (required)
33+
Bash(command="asta literature find 'query' -o /tmp/literature-search-result.json --timeout 300", run_in_background=true)
3434
```
35-
The command saves results to `.asta/literature/find/` (in current working directory) by default with an auto-generated filename.
36-
The filename is printed to the console when the search is finished. Use the TaskOutput tool to capture the filename for later processing
3735

38-
After the file has been created, index it using the [asta-documents](../asta-documents/SKILL.md) skill.
36+
After the search completes, move the file to `.asta/documents/literature/find/` and index it:
3937

4038
```bash
41-
Bash(command="asta documents add file://<filename> --name=... --summary=...")
39+
# Create directory if it doesn't exist
40+
mkdir -p .asta/documents/literature/find
41+
42+
# Move the result file to the documents directory
43+
mv /tmp/literature-search-result.json .asta/documents/literature/find/
44+
45+
# Index the file using asta-documents
46+
Bash(command="asta documents add file://.asta/documents/literature/find/literature-search-result.json --name='Literature Search: <query>' --summary='Search results for: <query>'")
4247
```
4348

4449
Browse results with jq:

src/asta/literature/find.py

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
"""Find papers command"""
22

33
import json
4-
import re
5-
from datetime import datetime
64
from pathlib import Path
75

86
import click
@@ -13,6 +11,13 @@
1311

1412
@click.command()
1513
@click.argument("query")
14+
@click.option(
15+
"-o",
16+
"--output",
17+
type=click.Path(),
18+
required=True,
19+
help="Output file path for the results (required)",
20+
)
1621
@click.option(
1722
"--timeout",
1823
type=int,
@@ -25,24 +30,24 @@
2530
default="infer",
2631
help="Search strategy: infer (auto-detect), fast (quick results), or diligent (comprehensive)",
2732
)
28-
def find(query: str, timeout: int, mode: str):
33+
def find(query: str, output: str, timeout: int, mode: str):
2934
"""Find papers matching QUERY using Asta Paper Finder.
3035
31-
Saves results to .asta/literature/find/ with an auto-generated filename.
36+
Requires an output file path to save results.
3237
3338
Examples:
3439
35-
# Save to default location
36-
asta literature find "machine learning in healthcare"
40+
# Save to specific file
41+
asta literature find "machine learning in healthcare" -o results.json
3742
3843
# With custom timeout
39-
asta literature find "transformers" --timeout 60
44+
asta literature find "transformers" -o results.json --timeout 60
4045
4146
# Use fast mode for quick results
42-
asta literature find "deep learning" --mode fast
47+
asta literature find "deep learning" -o results.json --mode fast
4348
4449
# Use diligent mode for comprehensive search
45-
asta literature find "neural networks" --mode diligent
50+
asta literature find "neural networks" -o results.json --mode diligent
4651
"""
4752
try:
4853
client = AstaPaperFinder()
@@ -58,15 +63,9 @@ def find(query: str, timeout: int, mode: str):
5863
# Convert to dict for output
5964
output_data = literature_result.model_dump(mode="json", exclude_none=False)
6065

61-
# Generate default path: .asta/literature/find/YYYY-MM-DD-HH-MM-SS-query-slug.json
62-
default_dir = Path.cwd() / ".asta" / "literature" / "find"
63-
default_dir.mkdir(parents=True, exist_ok=True)
64-
65-
timestamp = datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
66-
# Create a slug from the query (lowercase, alphanumeric and hyphens only, max 50 chars)
67-
query_slug = re.sub(r"[^a-z0-9]+", "-", query.lower()).strip("-")[:50]
68-
filename = f"{timestamp}-{query_slug}.json"
69-
output_path = default_dir / filename
66+
# Use the specified output path
67+
output_path = Path(output)
68+
output_path.parent.mkdir(parents=True, exist_ok=True)
7069

7170
# Save to file
7271
with open(output_path, "w") as f:

src/asta/utils/passthrough.conf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
passthrough {
1212
documents {
1313
tool_name = "asta-documents"
14-
install_type = "git"
15-
install_source = "git+ssh://git@github.com/allenai/asta-resource-repo.git"
16-
minimum_version = "0.2.0"
14+
install_type = "pypi"
15+
install_source = "asta-resource-repository"
16+
minimum_version = "0.3.0"
1717
command_name = "documents"
1818
friendly_name = "asta-documents"
1919
docstring = "Manage a local library of documents known to Asta"

tests/test_cli.py

Lines changed: 47 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -60,33 +60,30 @@ def test_find_success_file_output(self, runner, tmp_path):
6060
}
6161

6262
with patch("asta.literature.find.AstaPaperFinder") as MockFinder:
63-
with patch("asta.literature.find.Path.cwd", return_value=tmp_path):
64-
mock_instance = MagicMock()
65-
mock_instance.find_papers.return_value = mock_result
66-
MockFinder.return_value = mock_instance
63+
mock_instance = MagicMock()
64+
mock_instance.find_papers.return_value = mock_result
65+
MockFinder.return_value = mock_instance
6766

68-
result = runner.invoke(cli, ["literature", "find", "test query"])
67+
output_file = tmp_path / "results.json"
68+
result = runner.invoke(
69+
cli, ["literature", "find", "test query", "-o", str(output_file)]
70+
)
6971

7072
assert result.exit_code == 0
7173

72-
# Verify file was created in default location
73-
output_dir = tmp_path / ".asta" / "literature" / "find"
74-
assert output_dir.exists()
75-
76-
# Find the created file (should match pattern: YYYY-MM-DD-HH-MM-SS-test-query.json)
77-
json_files = list(output_dir.glob("*-test-query.json"))
78-
assert len(json_files) == 1
74+
# Verify file was created at specified location
75+
assert output_file.exists()
7976

8077
# Verify file contents
81-
with open(json_files[0]) as f:
78+
with open(output_file) as f:
8279
data = json.load(f)
8380

8481
assert data["query"] == "test query"
8582
assert len(data["results"]) == 2
8683
assert data["results"][0]["corpusId"] == 123
8784
assert data["results"][1]["corpusId"] == 456
8885

89-
def test_find_timeout_error(self, runner):
86+
def test_find_timeout_error(self, runner, tmp_path):
9087
"""Test find command with timeout error."""
9188
with patch("asta.literature.find.AstaPaperFinder") as MockFinder:
9289
mock_instance = MagicMock()
@@ -95,22 +92,28 @@ def test_find_timeout_error(self, runner):
9592
)
9693
MockFinder.return_value = mock_instance
9794

98-
result = runner.invoke(cli, ["literature", "find", "test query"])
95+
output_file = tmp_path / "results.json"
96+
result = runner.invoke(
97+
cli, ["literature", "find", "test query", "-o", str(output_file)]
98+
)
9999

100100
assert result.exit_code == 2
101101

102-
def test_find_general_error(self, runner):
102+
def test_find_general_error(self, runner, tmp_path):
103103
"""Test find command with general error."""
104104
with patch("asta.literature.find.AstaPaperFinder") as MockFinder:
105105
mock_instance = MagicMock()
106106
mock_instance.find_papers.side_effect = Exception("API error")
107107
MockFinder.return_value = mock_instance
108108

109-
result = runner.invoke(cli, ["literature", "find", "test query"])
109+
output_file = tmp_path / "results.json"
110+
result = runner.invoke(
111+
cli, ["literature", "find", "test query", "-o", str(output_file)]
112+
)
110113

111114
assert result.exit_code == 1
112115

113-
def test_find_custom_timeout(self, runner):
116+
def test_find_custom_timeout(self, runner, tmp_path):
114117
"""Test find command with custom timeout."""
115118
mock_result = {
116119
"query": "test query",
@@ -134,16 +137,26 @@ def test_find_custom_timeout(self, runner):
134137
mock_instance.find_papers.return_value = mock_result
135138
MockFinder.return_value = mock_instance
136139

140+
output_file = tmp_path / "results.json"
137141
result = runner.invoke(
138-
cli, ["literature", "find", "test query", "--timeout", "60"]
142+
cli,
143+
[
144+
"literature",
145+
"find",
146+
"test query",
147+
"-o",
148+
str(output_file),
149+
"--timeout",
150+
"60",
151+
],
139152
)
140153

141154
assert result.exit_code == 0
142155
mock_instance.find_papers.assert_called_once_with(
143156
"test query", timeout=60, save_to_file=None, operation_mode="infer"
144157
)
145158

146-
def test_find_with_mode_option(self, runner):
159+
def test_find_with_mode_option(self, runner, tmp_path):
147160
"""Test find command with different operation modes."""
148161
mock_result = {
149162
"query": "test query",
@@ -166,9 +179,19 @@ def test_find_with_mode_option(self, runner):
166179
mock_instance.find_papers.return_value = mock_result
167180
MockFinder.return_value = mock_instance
168181

182+
output_file = tmp_path / "results.json"
169183
# Test fast mode
170184
result = runner.invoke(
171-
cli, ["literature", "find", "test query", "--mode", "fast"]
185+
cli,
186+
[
187+
"literature",
188+
"find",
189+
"test query",
190+
"-o",
191+
str(output_file),
192+
"--mode",
193+
"fast",
194+
],
172195
)
173196

174197
assert result.exit_code == 0
@@ -413,11 +436,10 @@ def test_documents_config(self):
413436

414437
# Should have required fields
415438
assert config["tool_name"] == "asta-documents"
416-
assert "install_type" in config
417-
assert config["install_type"] in ("pypi", "git", "local")
418-
assert "minimum_version" in config
439+
assert config["install_type"] == "pypi"
440+
assert config["install_source"] == "asta-resource-repository"
441+
assert config["minimum_version"] == "0.3.0"
419442
assert validate_semver(config["minimum_version"])
420-
assert "install_source" in config
421443
assert config["command_name"] == "documents"
422444

423445
def test_documents_help_requires_installation(self, runner):

0 commit comments

Comments
 (0)