AskTim 0.1.0__tar.gz → 0.1.1__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.
- {asktim-0.1.0/src/AskTim.egg-info → asktim-0.1.1}/PKG-INFO +14 -4
- {asktim-0.1.0 → asktim-0.1.1}/README.md +13 -3
- {asktim-0.1.0 → asktim-0.1.1}/pyproject.toml +5 -2
- {asktim-0.1.0 → asktim-0.1.1/src/AskTim.egg-info}/PKG-INFO +14 -4
- {asktim-0.1.0 → asktim-0.1.1}/src/AskTim.egg-info/SOURCES.txt +4 -0
- {asktim-0.1.0 → asktim-0.1.1}/src/AskTim.egg-info/top_level.txt +1 -0
- asktim-0.1.1/src/AskTim.py +7 -0
- {asktim-0.1.0 → asktim-0.1.1}/src/asktim/__init__.py +1 -1
- asktim-0.1.1/src/asktim/_version.py +2 -0
- {asktim-0.1.0 → asktim-0.1.1}/src/asktim/agent.py +3 -2
- {asktim-0.1.0 → asktim-0.1.1}/src/asktim/context.py +1 -1
- {asktim-0.1.0 → asktim-0.1.1}/src/asktim/notebook.py +2 -2
- {asktim-0.1.0 → asktim-0.1.1}/src/asktim/privacy.py +63 -4
- {asktim-0.1.0 → asktim-0.1.1}/src/asktim/prompts.py +10 -4
- {asktim-0.1.0 → asktim-0.1.1}/src/asktim/runner.py +7 -2
- {asktim-0.1.0 → asktim-0.1.1}/src/asktim/safety.py +297 -0
- asktim-0.1.1/src/asktim/snakefile.py +324 -0
- {asktim-0.1.0 → asktim-0.1.1}/tests/test_cli_and_agent.py +24 -0
- {asktim-0.1.0 → asktim-0.1.1}/tests/test_notebook.py +14 -0
- {asktim-0.1.0 → asktim-0.1.1}/tests/test_privacy.py +17 -0
- asktim-0.1.1/tests/test_snakemake.py +265 -0
- {asktim-0.1.0 → asktim-0.1.1}/LICENSE +0 -0
- {asktim-0.1.0 → asktim-0.1.1}/MANIFEST.in +0 -0
- {asktim-0.1.0 → asktim-0.1.1}/bin/AskTim! +0 -0
- {asktim-0.1.0 → asktim-0.1.1}/examples/AskTim-demo.ipynb +0 -0
- {asktim-0.1.0 → asktim-0.1.1}/setup.cfg +0 -0
- {asktim-0.1.0 → asktim-0.1.1}/src/AskTim.egg-info/dependency_links.txt +0 -0
- {asktim-0.1.0 → asktim-0.1.1}/src/AskTim.egg-info/entry_points.txt +0 -0
- {asktim-0.1.0 → asktim-0.1.1}/src/AskTim.egg-info/requires.txt +0 -0
- {asktim-0.1.0 → asktim-0.1.1}/src/asktim/__main__.py +0 -0
- {asktim-0.1.0 → asktim-0.1.1}/src/asktim/api.py +0 -0
- {asktim-0.1.0 → asktim-0.1.1}/src/asktim/chat.py +0 -0
- {asktim-0.1.0 → asktim-0.1.1}/src/asktim/cli.py +0 -0
- {asktim-0.1.0 → asktim-0.1.1}/src/asktim/config.py +0 -0
- {asktim-0.1.0 → asktim-0.1.1}/src/asktim/fileinfo.py +0 -0
- {asktim-0.1.0 → asktim-0.1.1}/src/asktim/history.py +0 -0
- {asktim-0.1.0 → asktim-0.1.1}/src/asktim/inventory.py +0 -0
- {asktim-0.1.0 → asktim-0.1.1}/src/asktim/logbook.py +0 -0
- {asktim-0.1.0 → asktim-0.1.1}/src/asktim/net.py +0 -0
- {asktim-0.1.0 → asktim-0.1.1}/src/asktim/offline.py +0 -0
- {asktim-0.1.0 → asktim-0.1.1}/src/asktim/paths.py +0 -0
- {asktim-0.1.0 → asktim-0.1.1}/src/asktim/providers/__init__.py +0 -0
- {asktim-0.1.0 → asktim-0.1.1}/src/asktim/providers/anthropic.py +0 -0
- {asktim-0.1.0 → asktim-0.1.1}/src/asktim/providers/gemini.py +0 -0
- {asktim-0.1.0 → asktim-0.1.1}/src/asktim/providers/openai.py +0 -0
- {asktim-0.1.0 → asktim-0.1.1}/src/asktim/records.py +0 -0
- {asktim-0.1.0 → asktim-0.1.1}/src/asktim/render.py +0 -0
- {asktim-0.1.0 → asktim-0.1.1}/src/asktim/shell_setup.py +0 -0
- {asktim-0.1.0 → asktim-0.1.1}/src/asktim/ui.py +0 -0
- {asktim-0.1.0 → asktim-0.1.1}/src/asktim/viewers.py +0 -0
- {asktim-0.1.0 → asktim-0.1.1}/tests/conftest.py +0 -0
- {asktim-0.1.0 → asktim-0.1.1}/tests/kernel_harness.py +0 -0
- {asktim-0.1.0 → asktim-0.1.1}/tests/markdown_fuzz/check.mjs +0 -0
- {asktim-0.1.0 → asktim-0.1.1}/tests/mock_ai.py +0 -0
- {asktim-0.1.0 → asktim-0.1.1}/tests/test_display_safety.py +0 -0
- {asktim-0.1.0 → asktim-0.1.1}/tests/test_history_and_files.py +0 -0
- {asktim-0.1.0 → asktim-0.1.1}/tests/test_providers.py +0 -0
- {asktim-0.1.0 → asktim-0.1.1}/tests/test_safety.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: AskTim
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.1
|
|
4
4
|
Summary: AskTim! - an AI helper for bioinformatics students that keeps their data out of the AI, at the command line and in Jupyter and Colab notebooks.
|
|
5
5
|
Author: Tim Hearn
|
|
6
6
|
Project-URL: Homepage, https://github.com/comparativechrono/AskTim
|
|
@@ -47,8 +47,8 @@ Dynamic: license-file
|
|
|
47
47
|
<p align="center"><strong>An AI helper for learning bioinformatics that keeps your data out of the AI.</strong></p>
|
|
48
48
|
|
|
49
49
|
<p align="center">
|
|
50
|
-
<a href="https://pypi.org/project/AskTim/"><img src="https://img.shields.io/pypi/v/AskTim" alt="PyPI"></a>
|
|
51
|
-
<a href="https://pypi.org/project/AskTim/"><img src="https://img.shields.io/pypi/pyversions/AskTim" alt="Python versions"></a>
|
|
50
|
+
<a href="https://pypi.org/project/AskTim/"><img src="https://img.shields.io/pypi/v/AskTim?label=PyPI" alt="PyPI"></a>
|
|
51
|
+
<a href="https://pypi.org/project/AskTim/"><img src="https://img.shields.io/pypi/pyversions/AskTim?label=Python" alt="Python versions"></a>
|
|
52
52
|
<a href="https://github.com/comparativechrono/AskTim/actions/workflows/tests.yml"><img src="https://github.com/comparativechrono/AskTim/actions/workflows/tests.yml/badge.svg" alt="Tests"></a>
|
|
53
53
|
</p>
|
|
54
54
|
|
|
@@ -168,6 +168,13 @@ the model):
|
|
|
168
168
|
- `run.json`: the same, for programs;
|
|
169
169
|
- `rerun.sh`: the commands that worked, as a script you can read and run again without any AI.
|
|
170
170
|
|
|
171
|
+
**Workflows.** If Snakemake is installed, the agent can write a workflow (a `Snakefile` in its run
|
|
172
|
+
folder) and run it with `snakemake`, after a dry run. Before each run, AskTim! reads the Snakefile
|
|
173
|
+
and checks every rule as it checks the agent's own commands: its shell command (with `{input}` and
|
|
174
|
+
`{output}` filled in), the files it writes, and its Python code and scripts. Options and rules
|
|
175
|
+
that would install software (`--use-conda`, containers, wrappers) are refused, and sending the
|
|
176
|
+
jobs to a cluster (`--executor slurm`) needs your yes.
|
|
177
|
+
|
|
171
178
|
The agent can also open a file for you. An HTML report (FastQC, MultiQC), an image or a PDF opens
|
|
172
179
|
in its usual program. A BAM or VCF file can open in IGV, an alignment in Jalview or AliView, and a
|
|
173
180
|
tree in FigTree, if those programs are installed. You are asked every time.
|
|
@@ -299,6 +306,9 @@ change, so check them before recommending one to a class. When this was written
|
|
|
299
306
|
programs (the agent opens files for you with `open_file` instead).
|
|
300
307
|
- **Limits:** by default 25 steps and 600 seconds per command (a command is stopped together with
|
|
301
308
|
everything it started), and output is trimmed before it is filtered.
|
|
309
|
+
- **Snakemake workflows are read before they run.** Each rule's command, output files, Python code
|
|
310
|
+
and scripts get the same checks as the agent's commands, and so do Snakemake's options and
|
|
311
|
+
profiles. In the sandbox, programs keep their caches in the private temporary folder.
|
|
302
312
|
- **Code is checked too.** Python and R the agent writes or runs is checked for installs, network
|
|
303
313
|
use, deletions and writes outside its folder. Risky code still needs your yes in `--auto`.
|
|
304
314
|
- **A record of every run** (`RUN.md`, `run.json`, `rerun.sh`), and a draft statement on your use of
|
|
@@ -434,7 +444,7 @@ include it.
|
|
|
434
444
|
|
|
435
445
|
### Making a release
|
|
436
446
|
|
|
437
|
-
1. Put the new version in `src/asktim/
|
|
447
|
+
1. Put the new version in `src/asktim/_version.py` (`__version__ = "0.2.0"`) and push it.
|
|
438
448
|
2. On GitHub, draft a new release with the tag `v0.2.0` (the same version, with a `v`) and publish it.
|
|
439
449
|
|
|
440
450
|
The release workflow then runs the tests, builds the package, checks that the tag matches the
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
<p align="center"><strong>An AI helper for learning bioinformatics that keeps your data out of the AI.</strong></p>
|
|
8
8
|
|
|
9
9
|
<p align="center">
|
|
10
|
-
<a href="https://pypi.org/project/AskTim/"><img src="https://img.shields.io/pypi/v/AskTim" alt="PyPI"></a>
|
|
11
|
-
<a href="https://pypi.org/project/AskTim/"><img src="https://img.shields.io/pypi/pyversions/AskTim" alt="Python versions"></a>
|
|
10
|
+
<a href="https://pypi.org/project/AskTim/"><img src="https://img.shields.io/pypi/v/AskTim?label=PyPI" alt="PyPI"></a>
|
|
11
|
+
<a href="https://pypi.org/project/AskTim/"><img src="https://img.shields.io/pypi/pyversions/AskTim?label=Python" alt="Python versions"></a>
|
|
12
12
|
<a href="https://github.com/comparativechrono/AskTim/actions/workflows/tests.yml"><img src="https://github.com/comparativechrono/AskTim/actions/workflows/tests.yml/badge.svg" alt="Tests"></a>
|
|
13
13
|
</p>
|
|
14
14
|
|
|
@@ -128,6 +128,13 @@ the model):
|
|
|
128
128
|
- `run.json`: the same, for programs;
|
|
129
129
|
- `rerun.sh`: the commands that worked, as a script you can read and run again without any AI.
|
|
130
130
|
|
|
131
|
+
**Workflows.** If Snakemake is installed, the agent can write a workflow (a `Snakefile` in its run
|
|
132
|
+
folder) and run it with `snakemake`, after a dry run. Before each run, AskTim! reads the Snakefile
|
|
133
|
+
and checks every rule as it checks the agent's own commands: its shell command (with `{input}` and
|
|
134
|
+
`{output}` filled in), the files it writes, and its Python code and scripts. Options and rules
|
|
135
|
+
that would install software (`--use-conda`, containers, wrappers) are refused, and sending the
|
|
136
|
+
jobs to a cluster (`--executor slurm`) needs your yes.
|
|
137
|
+
|
|
131
138
|
The agent can also open a file for you. An HTML report (FastQC, MultiQC), an image or a PDF opens
|
|
132
139
|
in its usual program. A BAM or VCF file can open in IGV, an alignment in Jalview or AliView, and a
|
|
133
140
|
tree in FigTree, if those programs are installed. You are asked every time.
|
|
@@ -259,6 +266,9 @@ change, so check them before recommending one to a class. When this was written
|
|
|
259
266
|
programs (the agent opens files for you with `open_file` instead).
|
|
260
267
|
- **Limits:** by default 25 steps and 600 seconds per command (a command is stopped together with
|
|
261
268
|
everything it started), and output is trimmed before it is filtered.
|
|
269
|
+
- **Snakemake workflows are read before they run.** Each rule's command, output files, Python code
|
|
270
|
+
and scripts get the same checks as the agent's commands, and so do Snakemake's options and
|
|
271
|
+
profiles. In the sandbox, programs keep their caches in the private temporary folder.
|
|
262
272
|
- **Code is checked too.** Python and R the agent writes or runs is checked for installs, network
|
|
263
273
|
use, deletions and writes outside its folder. Risky code still needs your yes in `--auto`.
|
|
264
274
|
- **A record of every run** (`RUN.md`, `run.json`, `rerun.sh`), and a draft statement on your use of
|
|
@@ -394,7 +404,7 @@ include it.
|
|
|
394
404
|
|
|
395
405
|
### Making a release
|
|
396
406
|
|
|
397
|
-
1. Put the new version in `src/asktim/
|
|
407
|
+
1. Put the new version in `src/asktim/_version.py` (`__version__ = "0.2.0"`) and push it.
|
|
398
408
|
2. On GitHub, draft a new release with the tag `v0.2.0` (the same version, with a `v`) and publish it.
|
|
399
409
|
|
|
400
410
|
The release workflow then runs the tests, builds the package, checks that the tag matches the
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "AskTim"
|
|
7
|
-
# the version is __version__ in src/asktim/
|
|
7
|
+
# the version is __version__ in src/asktim/_version.py (a release's tag must match it: v0.1.1)
|
|
8
8
|
dynamic = ["version"]
|
|
9
9
|
description = "AskTim! - an AI helper for bioinformatics students that keeps their data out of the AI, at the command line and in Jupyter and Colab notebooks."
|
|
10
10
|
readme = "README.md"
|
|
@@ -52,9 +52,12 @@ Issues = "https://github.com/comparativechrono/AskTim/issues"
|
|
|
52
52
|
# The command students type, `AskTim! "my question"`, is a small script file rather than an entry
|
|
53
53
|
# point: older versions of pip (23.0 and before) fail on an entry point whose name holds "!".
|
|
54
54
|
script-files = ["bin/AskTim!"]
|
|
55
|
+
# `import AskTim` works as well as `import asktim` (students type the name they installed)
|
|
56
|
+
py-modules = ["AskTim"]
|
|
55
57
|
|
|
56
58
|
[tool.setuptools.dynamic]
|
|
57
|
-
|
|
59
|
+
# (its own file: on macOS and Windows, which ignore case in file names, a lookup of "asktim" can find AskTim.py)
|
|
60
|
+
version = { attr = "asktim._version.__version__" }
|
|
58
61
|
|
|
59
62
|
[tool.setuptools.packages.find]
|
|
60
63
|
where = ["src"]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: AskTim
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.1
|
|
4
4
|
Summary: AskTim! - an AI helper for bioinformatics students that keeps their data out of the AI, at the command line and in Jupyter and Colab notebooks.
|
|
5
5
|
Author: Tim Hearn
|
|
6
6
|
Project-URL: Homepage, https://github.com/comparativechrono/AskTim
|
|
@@ -47,8 +47,8 @@ Dynamic: license-file
|
|
|
47
47
|
<p align="center"><strong>An AI helper for learning bioinformatics that keeps your data out of the AI.</strong></p>
|
|
48
48
|
|
|
49
49
|
<p align="center">
|
|
50
|
-
<a href="https://pypi.org/project/AskTim/"><img src="https://img.shields.io/pypi/v/AskTim" alt="PyPI"></a>
|
|
51
|
-
<a href="https://pypi.org/project/AskTim/"><img src="https://img.shields.io/pypi/pyversions/AskTim" alt="Python versions"></a>
|
|
50
|
+
<a href="https://pypi.org/project/AskTim/"><img src="https://img.shields.io/pypi/v/AskTim?label=PyPI" alt="PyPI"></a>
|
|
51
|
+
<a href="https://pypi.org/project/AskTim/"><img src="https://img.shields.io/pypi/pyversions/AskTim?label=Python" alt="Python versions"></a>
|
|
52
52
|
<a href="https://github.com/comparativechrono/AskTim/actions/workflows/tests.yml"><img src="https://github.com/comparativechrono/AskTim/actions/workflows/tests.yml/badge.svg" alt="Tests"></a>
|
|
53
53
|
</p>
|
|
54
54
|
|
|
@@ -168,6 +168,13 @@ the model):
|
|
|
168
168
|
- `run.json`: the same, for programs;
|
|
169
169
|
- `rerun.sh`: the commands that worked, as a script you can read and run again without any AI.
|
|
170
170
|
|
|
171
|
+
**Workflows.** If Snakemake is installed, the agent can write a workflow (a `Snakefile` in its run
|
|
172
|
+
folder) and run it with `snakemake`, after a dry run. Before each run, AskTim! reads the Snakefile
|
|
173
|
+
and checks every rule as it checks the agent's own commands: its shell command (with `{input}` and
|
|
174
|
+
`{output}` filled in), the files it writes, and its Python code and scripts. Options and rules
|
|
175
|
+
that would install software (`--use-conda`, containers, wrappers) are refused, and sending the
|
|
176
|
+
jobs to a cluster (`--executor slurm`) needs your yes.
|
|
177
|
+
|
|
171
178
|
The agent can also open a file for you. An HTML report (FastQC, MultiQC), an image or a PDF opens
|
|
172
179
|
in its usual program. A BAM or VCF file can open in IGV, an alignment in Jalview or AliView, and a
|
|
173
180
|
tree in FigTree, if those programs are installed. You are asked every time.
|
|
@@ -299,6 +306,9 @@ change, so check them before recommending one to a class. When this was written
|
|
|
299
306
|
programs (the agent opens files for you with `open_file` instead).
|
|
300
307
|
- **Limits:** by default 25 steps and 600 seconds per command (a command is stopped together with
|
|
301
308
|
everything it started), and output is trimmed before it is filtered.
|
|
309
|
+
- **Snakemake workflows are read before they run.** Each rule's command, output files, Python code
|
|
310
|
+
and scripts get the same checks as the agent's commands, and so do Snakemake's options and
|
|
311
|
+
profiles. In the sandbox, programs keep their caches in the private temporary folder.
|
|
302
312
|
- **Code is checked too.** Python and R the agent writes or runs is checked for installs, network
|
|
303
313
|
use, deletions and writes outside its folder. Risky code still needs your yes in `--auto`.
|
|
304
314
|
- **A record of every run** (`RUN.md`, `run.json`, `rerun.sh`), and a draft statement on your use of
|
|
@@ -434,7 +444,7 @@ include it.
|
|
|
434
444
|
|
|
435
445
|
### Making a release
|
|
436
446
|
|
|
437
|
-
1. Put the new version in `src/asktim/
|
|
447
|
+
1. Put the new version in `src/asktim/_version.py` (`__version__ = "0.2.0"`) and push it.
|
|
438
448
|
2. On GitHub, draft a new release with the tag `v0.2.0` (the same version, with a `v`) and publish it.
|
|
439
449
|
|
|
440
450
|
The release workflow then runs the tests, builds the package, checks that the tag matches the
|
|
@@ -4,6 +4,7 @@ README.md
|
|
|
4
4
|
pyproject.toml
|
|
5
5
|
bin/AskTim!
|
|
6
6
|
examples/AskTim-demo.ipynb
|
|
7
|
+
src/AskTim.py
|
|
7
8
|
src/AskTim.egg-info/PKG-INFO
|
|
8
9
|
src/AskTim.egg-info/SOURCES.txt
|
|
9
10
|
src/AskTim.egg-info/dependency_links.txt
|
|
@@ -12,6 +13,7 @@ src/AskTim.egg-info/requires.txt
|
|
|
12
13
|
src/AskTim.egg-info/top_level.txt
|
|
13
14
|
src/asktim/__init__.py
|
|
14
15
|
src/asktim/__main__.py
|
|
16
|
+
src/asktim/_version.py
|
|
15
17
|
src/asktim/agent.py
|
|
16
18
|
src/asktim/api.py
|
|
17
19
|
src/asktim/chat.py
|
|
@@ -33,6 +35,7 @@ src/asktim/render.py
|
|
|
33
35
|
src/asktim/runner.py
|
|
34
36
|
src/asktim/safety.py
|
|
35
37
|
src/asktim/shell_setup.py
|
|
38
|
+
src/asktim/snakefile.py
|
|
36
39
|
src/asktim/ui.py
|
|
37
40
|
src/asktim/viewers.py
|
|
38
41
|
src/asktim/providers/__init__.py
|
|
@@ -49,4 +52,5 @@ tests/test_notebook.py
|
|
|
49
52
|
tests/test_privacy.py
|
|
50
53
|
tests/test_providers.py
|
|
51
54
|
tests/test_safety.py
|
|
55
|
+
tests/test_snakemake.py
|
|
52
56
|
tests/markdown_fuzz/check.mjs
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"""`import AskTim` is the same as `import asktim` (the package on PyPI is called AskTim).
|
|
2
|
+
|
|
3
|
+
In a notebook, either one makes the AskTim! command work in cells: AskTim! "your question".
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from asktim import * # noqa: F401,F403
|
|
7
|
+
from asktim import __version__, agent, ask, load_ipython_extension, unload_ipython_extension # noqa: F401
|
|
@@ -17,7 +17,7 @@ that are installed, your recent commands (with secrets removed) and descriptions
|
|
|
17
17
|
(format, size, columns) - not the data in them. `AskTim! privacy` says exactly what is sent.
|
|
18
18
|
"""
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
from ._version import __version__
|
|
21
21
|
|
|
22
22
|
__all__ = ["ask", "agent", "load_ipython_extension", "unload_ipython_extension", "__version__"]
|
|
23
23
|
|
|
@@ -139,7 +139,8 @@ class Agent(object):
|
|
|
139
139
|
inv = inventory.gather()
|
|
140
140
|
inv_lines = inventory.describe(inv, notebook_packages=self.nb.packages() if self.nb is not None else None)
|
|
141
141
|
system = prompts.agent_system(inv_lines, self.cfg, self.mode, self._rel(self.work_dir) or ".", self._rel(self.student_dir) or ".",
|
|
142
|
-
notebook=self.nb is not None, sandbox_note=(self.sandbox_note + ".") if self.sandbox else "", script_name=self.script_name
|
|
142
|
+
notebook=self.nb is not None, sandbox_note=(self.sandbox_note + ".") if self.sandbox else "", script_name=self.script_name,
|
|
143
|
+
allow_network=self.allow_network, max_steps=self.max_steps, timeout=self.timeout)
|
|
143
144
|
tools = prompts.tool_specs(notebook=self.nb is not None)
|
|
144
145
|
self.conv = Conversation()
|
|
145
146
|
self.conv.user(self._first_message())
|
|
@@ -362,7 +363,7 @@ class Agent(object):
|
|
|
362
363
|
step.update({"exit": res.exit_code, "seconds": round(res.duration, 2), "timed_out": res.timed_out, "lines": res.lines})
|
|
363
364
|
raw = res.text()
|
|
364
365
|
step["output_tail"] = privacy.mask_identity(res.last_lines(30))
|
|
365
|
-
fr = privacy.filter_output(raw, kind=verdict.output_kind, strict=self.strict)
|
|
366
|
+
fr = privacy.filter_output(raw, kind=verdict.output_kind, strict=self.strict, places=[self.work_dir] + safety.named_dirs(cmd, self.work_dir))
|
|
366
367
|
self.withheld += fr.withheld
|
|
367
368
|
step["withheld"] = fr.withheld
|
|
368
369
|
body = privacy.shorten(fr.text, self.out_chars)
|
|
@@ -93,7 +93,7 @@ def terminal(cfg, files=(), stdin_text=None, send_history=None, history_n=None,
|
|
|
93
93
|
desc = fileinfo.describe(f, strict=strict)
|
|
94
94
|
g.add("A file the student asked about: " + _clean(g, desc, strict), "a description of %s (its structure, not its contents)" % os.path.basename(f))
|
|
95
95
|
if stdin_text:
|
|
96
|
-
fr = privacy.filter_output(stdin_text, strict=strict)
|
|
96
|
+
fr = privacy.filter_output(stdin_text, strict=strict, places=[cwd])
|
|
97
97
|
g.withheld += fr.withheld
|
|
98
98
|
body = privacy.shorten(fr.text, 6000)
|
|
99
99
|
g.add("Output the student piped into AskTim! (lines that look like data are withheld):\n```text\n%s\n```" % body,
|
|
@@ -343,7 +343,7 @@ def notebook_context(cfg, attached=None):
|
|
|
343
343
|
g.withheld += fr.withheld
|
|
344
344
|
g.add("The last error, in this cell:\n```python\n%s\n```\nIt raised:\n```text\n%s\n```" % (clean(privacy.filter_code(err["cell"], strict=strict)[0])[-3000:], privacy.shorten(fr.text, 3000)), "the last error")
|
|
345
345
|
if attached:
|
|
346
|
-
fr = privacy.filter_output(attached, kind="default", strict=strict)
|
|
346
|
+
fr = privacy.filter_output(attached, kind="default", strict=strict, places=[os.getcwd()])
|
|
347
347
|
g.withheld += fr.withheld
|
|
348
348
|
g.add("Text or code the student attached to the question (lines that look like data are withheld):\n```text\n%s\n```" % privacy.shorten(clean(fr.text), 6000), "the text under your question (%s)" % fr.summary())
|
|
349
349
|
return g
|
|
@@ -635,7 +635,7 @@ class NotebookTools(object):
|
|
|
635
635
|
step["exit"] = 0 if err is None else 1
|
|
636
636
|
step["seconds"] = round(dt, 2)
|
|
637
637
|
printed = "".join(buf)
|
|
638
|
-
fr = privacy.filter_output(printed, strict=self.cfg.strict)
|
|
638
|
+
fr = privacy.filter_output(printed, strict=self.cfg.strict, places=[os.getcwd(), agent.work_dir])
|
|
639
639
|
agent.withheld += fr.withheld
|
|
640
640
|
step["withheld"] = fr.withheld
|
|
641
641
|
step["lines"] = fr.total
|
|
@@ -287,6 +287,9 @@ _CODE = re.compile(r"^\s*(?:[A-Za-z_][\w.]*(?:\[[^\]]*\])?\s*(?:[-+*/]?=|<-)\s*\
|
|
|
287
287
|
_SAM_HEADER = re.compile(r"^@(HD|SQ|RG|PG|CO)\t")
|
|
288
288
|
_VCF_META_KEEP = re.compile(r"^##(fileformat|INFO=<ID=|FORMAT=<ID=|FILTER=<ID=|ALT=<ID=|source=)")
|
|
289
289
|
_PATHLIKE = re.compile(r"^[\w.\-~/]*(/|\.[A-Za-z0-9]{1,8}(\.gz|\.bz2|\.xz|\.zst)?)$")
|
|
290
|
+
# a path without an extension (/usr/bin/bwa, results/sample1): its parts are names, mostly with lower-case
|
|
291
|
+
# letters - unlike a quality string, which may hold slashes too (/AAA/EEEE)
|
|
292
|
+
_SLASH_PATH = re.compile(r"^(?:~|\.{1,2})?/?[\w.\-+@]+(?:/[\w.\-+@]+)*/?$")
|
|
290
293
|
|
|
291
294
|
|
|
292
295
|
def _tokens(line):
|
|
@@ -359,7 +362,14 @@ def _codecall(s):
|
|
|
359
362
|
|
|
360
363
|
|
|
361
364
|
def _pathish(s):
|
|
362
|
-
|
|
365
|
+
if len(s) > 200:
|
|
366
|
+
return False
|
|
367
|
+
if _PATHLIKE.match(s):
|
|
368
|
+
return True
|
|
369
|
+
if "/" in s and _SLASH_PATH.match(s):
|
|
370
|
+
parts = [x for x in s.split("/") if x and x not in ("~", ".", "..")]
|
|
371
|
+
return bool(parts) and sum(1 for x in parts if re.search(r"[a-z]", x)) >= max(1, 0.6 * len(parts))
|
|
372
|
+
return False
|
|
363
373
|
|
|
364
374
|
|
|
365
375
|
def _keep_special(s, strict):
|
|
@@ -367,6 +377,8 @@ def _keep_special(s, strict):
|
|
|
367
377
|
log lines, code. In strict mode only counts, checksums and log/error lines."""
|
|
368
378
|
if _FLAGSTAT.match(s) or _SUM.match(s):
|
|
369
379
|
return True
|
|
380
|
+
if _TIMESTAMP.match(s) or _PROGRESS.match(s) or _VERSION_LINE.match(s) or _HEAD_TAIL.match(s):
|
|
381
|
+
return True
|
|
370
382
|
if _WC.match(s) and not all(_is_num(t) for t in _tokens(s)):
|
|
371
383
|
label = _tokens(s)[-1]
|
|
372
384
|
return label == "total" or _pathish(label)
|
|
@@ -417,12 +429,28 @@ def _keylike(key):
|
|
|
417
429
|
_OPTION = re.compile(r"^--?[A-Za-z][\w\-]*=?")
|
|
418
430
|
|
|
419
431
|
|
|
432
|
+
_SHELL_OPS = re.compile(r"\s(?:\|\|?|&&|;|>>?|<|2>>?|2>&1|&>)\s")
|
|
433
|
+
|
|
434
|
+
|
|
420
435
|
def _commandlike(s):
|
|
421
|
-
"""A command line (echoed by set -x, or written in a log): a program name and options
|
|
436
|
+
"""A command line (echoed by set -x, or written in a log): a program name and options, or a program
|
|
437
|
+
whose output is piped or redirected (Snakemake's echo of a rule's shell command)."""
|
|
422
438
|
toks = _tokens(s.lstrip("+$> "))
|
|
423
439
|
if len(toks) < 2 or not re.match(r"^[A-Za-z_][\w.\-]*$", toks[0]):
|
|
424
440
|
return False
|
|
425
|
-
return any(_OPTION.match(t) for t in toks[1:]) or toks[0] in ("cd", "mkdir", "cp", "mv", "rm", "cat", "for", "while", "if", "then", "do", "done", "fi")
|
|
441
|
+
return (any(_OPTION.match(t) for t in toks[1:]) or toks[0] in ("cd", "mkdir", "cp", "mv", "rm", "cat", "for", "while", "if", "then", "do", "done", "fi")
|
|
442
|
+
or bool(_SHELL_OPS.search(" %s " % s.strip())))
|
|
443
|
+
|
|
444
|
+
|
|
445
|
+
# lines that are not data although they hold numbers: a date and time on its own (Snakemake writes one
|
|
446
|
+
# before each job), progress ("3 of 7 steps (43%) done"), a version ("Python version: 3.13.1 (main, ...)")
|
|
447
|
+
_TIMESTAMP = re.compile(
|
|
448
|
+
r"^\[?\s*(?:(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun)\w*,?\s+)?(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\w*\s+\d{1,2},?"
|
|
449
|
+
r"\s+(?:\d{4}\s+)?\d{1,2}:\d{2}(?::\d{2})?(?:\s+\d{4})?\s*\]?$"
|
|
450
|
+
r"|^\[?\d{4}-\d{2}-\d{2}[ T]\d{2}:\d{2}(?::\d{2}(?:[.,]\d+)?)?(?:Z|[+-]\d{2}:?\d{2})?\]?$")
|
|
451
|
+
_PROGRESS = re.compile(r"^\s*\d+\s+of\s+\d+\s+(?:steps?|jobs?|tasks?|files?|samples?|chunks?)\b.*\bdone\b", re.I)
|
|
452
|
+
_VERSION_LINE = re.compile(r"^\s*[\w .()/-]{0,40}\bversion\b[\w .()/-]{0,20}:\s*\S.{0,150}$", re.I)
|
|
453
|
+
_HEAD_TAIL = re.compile(r"^==> .{1,300} <==$") # head and tail name each file they show
|
|
426
454
|
|
|
427
455
|
|
|
428
456
|
def _gaps(line):
|
|
@@ -666,6 +694,13 @@ def _classify(lines, strict):
|
|
|
666
694
|
s = lines[i].strip()
|
|
667
695
|
if labels[i] is None and s and not (_textlike(s) or _keep_special(s, True)):
|
|
668
696
|
labels[i] = "values"
|
|
697
|
+
# Snakemake's table of jobs per rule ("Job stats:", "Job counts:" before version 7): rule names and counts
|
|
698
|
+
for i, L in enumerate(lines):
|
|
699
|
+
if L.strip() in ("Job stats:", "Job counts:"):
|
|
700
|
+
j = i + 1
|
|
701
|
+
while j < n and lines[j].strip() and j - i <= 300 and re.fullmatch(r"[\w\s\-.]+", lines[j]):
|
|
702
|
+
labels[j] = None
|
|
703
|
+
j += 1
|
|
669
704
|
return labels
|
|
670
705
|
|
|
671
706
|
|
|
@@ -710,12 +745,34 @@ class FilterResult(object):
|
|
|
710
745
|
return "%d of %d lines withheld (%s)" % (self.withheld, self.total, what)
|
|
711
746
|
|
|
712
747
|
|
|
713
|
-
def
|
|
748
|
+
def _existing_names(lines, labels, places):
|
|
749
|
+
"""Lines that name a file or folder that exists (ls, find and which print names, not data): kept."""
|
|
750
|
+
places = [p for p in places if p]
|
|
751
|
+
for i, ln in enumerate(lines):
|
|
752
|
+
if labels[i] not in ("lists of values", "values", "quality strings or encoded data"):
|
|
753
|
+
continue
|
|
754
|
+
name = ln.strip().rstrip("/*@=|")
|
|
755
|
+
if not name or len(name) > 300 or "\t" in name:
|
|
756
|
+
continue
|
|
757
|
+
try:
|
|
758
|
+
if os.path.isabs(name) or name.startswith("~"):
|
|
759
|
+
found = os.path.lexists(os.path.expanduser(name))
|
|
760
|
+
else:
|
|
761
|
+
found = any(os.path.lexists(os.path.join(p, name)) for p in places)
|
|
762
|
+
except (OSError, ValueError):
|
|
763
|
+
found = False
|
|
764
|
+
if found:
|
|
765
|
+
labels[i] = None
|
|
766
|
+
|
|
767
|
+
|
|
768
|
+
def filter_output(text, kind="default", strict=False, places=()):
|
|
714
769
|
"""Filter the output of a command or of code before the AI sees it.
|
|
715
770
|
|
|
716
771
|
kind: "default" - classify every line; "help" (help or version text), "code" (a script
|
|
717
772
|
being read) and "summary" (counts, checksums, listings, flagstat ...) are only cleaned of
|
|
718
773
|
secrets and personal details - except in strict mode, where every line is classified.
|
|
774
|
+
places: the folders the command ran in and looked at; a line that names a file or folder
|
|
775
|
+
there is a file name, not data (not in strict mode, which withholds file names).
|
|
719
776
|
"""
|
|
720
777
|
text = ANSI.sub("", text or "")
|
|
721
778
|
# progress bars: keep what a terminal finally shows on each line
|
|
@@ -730,6 +787,8 @@ def filter_output(text, kind="default", strict=False):
|
|
|
730
787
|
labels = [None if (_textlike(ln.strip()) or not ln.strip() or _keep_special(ln.strip(), True) or ln.lstrip().startswith("-")) else "values" for ln in lines]
|
|
731
788
|
else:
|
|
732
789
|
labels = _classify(lines, strict)
|
|
790
|
+
if places and not strict:
|
|
791
|
+
_existing_names(lines, labels, places)
|
|
733
792
|
vcf_meta = 0
|
|
734
793
|
for i, ln in enumerate(lines):
|
|
735
794
|
if labels[i] is None and ln.startswith("##"):
|
|
@@ -68,6 +68,10 @@ AGENT_RULES = [
|
|
|
68
68
|
"Use only programs and packages that are installed (listed below). Nothing can be installed: package managers (pip, conda, apt, "
|
|
69
69
|
"brew, install.packages, BiocManager ...) and sudo are blocked. If the task needs something that is not installed, use an "
|
|
70
70
|
"installed alternative if there is one, or stop and say what the student would need.",
|
|
71
|
+
"Workflows: if the student asks for a pipeline or workflow and Snakemake is installed, you may write a Snakefile in your folder "
|
|
72
|
+
"and run it with `snakemake --cores N`, after a dry run (`snakemake -n --cores N`). Its rules must use the installed programs: "
|
|
73
|
+
"no --use-conda, containers, wrappers or cluster executors (they install or download software, or run jobs out of AskTim!'s "
|
|
74
|
+
"reach). AskTim! checks every rule's command and output files just as it checks your own commands.",
|
|
71
75
|
"{network}",
|
|
72
76
|
"{folder}",
|
|
73
77
|
"You cannot see data. AskTim! withholds it: in the output you receive, lines that look like data (sequences, reads, alignments, "
|
|
@@ -134,8 +138,10 @@ def chat_system(inventory_lines, cfg, notebook=False):
|
|
|
134
138
|
return "\n".join(lines)
|
|
135
139
|
|
|
136
140
|
|
|
137
|
-
def agent_system(inventory_lines, cfg, mode, run_dir_rel, student_dir_rel, notebook=False, sandbox_note="", script_name="analysis.sh"
|
|
138
|
-
|
|
141
|
+
def agent_system(inventory_lines, cfg, mode, run_dir_rel, student_dir_rel, notebook=False, sandbox_note="", script_name="analysis.sh",
|
|
142
|
+
allow_network=None, max_steps=None, timeout=None):
|
|
143
|
+
# what this run allows (--web, --steps, --timeout), not only what the settings say
|
|
144
|
+
allow = bool(cfg.get("agent.allow_network")) if allow_network is None else bool(allow_network)
|
|
139
145
|
network = (
|
|
140
146
|
"The student has allowed you to use the internet to download public data and references (curl, wget, git clone, SRA tools). "
|
|
141
147
|
"Never upload or send anything: posting data, scp, git push and the like are blocked."
|
|
@@ -151,8 +157,8 @@ def agent_system(inventory_lines, cfg, mode, run_dir_rel, student_dir_rel, noteb
|
|
|
151
157
|
"input files where they are (use paths such as ../../data/reads.fq or absolute paths); to index an input, link it into your "
|
|
152
158
|
"folder first (ln -s ../../data/ref.fa .) and index the link.{sandbox}"
|
|
153
159
|
).format(run=run_dir_rel, student=student_dir_rel, sandbox=(" " + sandbox_note) if sandbox_note else "")
|
|
154
|
-
max_steps = int(cfg.get("agent.max_steps") or 25)
|
|
155
|
-
timeout = int(cfg.get("agent.command_timeout") or 600)
|
|
160
|
+
max_steps = int(max_steps or cfg.get("agent.max_steps") or 25)
|
|
161
|
+
timeout = int(timeout or cfg.get("agent.command_timeout") or 600)
|
|
156
162
|
rules = [r.format(network=network, folder=folder, timeout=timeout, max_steps=max_steps) for r in AGENT_RULES]
|
|
157
163
|
lines = [AGENT_ROLE, "", "How you work:"] + ["- " + r for r in rules]
|
|
158
164
|
if notebook:
|
|
@@ -67,8 +67,8 @@ def clean_env(extra=None, tmpdir=None):
|
|
|
67
67
|
for k, v in os.environ.items():
|
|
68
68
|
if SECRET_ENV.search(k) and k not in KEEP_ENV:
|
|
69
69
|
continue
|
|
70
|
-
if k
|
|
71
|
-
continue
|
|
70
|
+
if k in ("SSH_AUTH_SOCK", "SNAKEMAKE_PROFILE"):
|
|
71
|
+
continue # (a default Snakemake profile could send the agent's jobs to a cluster unseen)
|
|
72
72
|
env[k] = v
|
|
73
73
|
env.update({
|
|
74
74
|
"PAGER": "cat", "MANPAGER": "cat", "GIT_PAGER": "cat", "SYSTEMD_PAGER": "", "LESS": "-FRX",
|
|
@@ -78,6 +78,11 @@ def clean_env(extra=None, tmpdir=None):
|
|
|
78
78
|
})
|
|
79
79
|
if tmpdir:
|
|
80
80
|
env["TMPDIR"] = tmpdir
|
|
81
|
+
# In the sandbox the home folder is read-only, so programs that keep a cache there
|
|
82
|
+
# (Snakemake's source cache, matplotlib's and fontconfig's font caches, R) keep it in
|
|
83
|
+
# the private temporary folder instead. (Their settings in ~/.config can still be read.)
|
|
84
|
+
env["XDG_CACHE_HOME"] = os.path.join(tmpdir, ".cache")
|
|
85
|
+
env["XDG_STATE_HOME"] = os.path.join(tmpdir, ".local-state")
|
|
81
86
|
if extra:
|
|
82
87
|
env.update(extra)
|
|
83
88
|
return env
|