whenthen 0.0.2__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.
- whenthen-0.0.2/.gitignore +120 -0
- whenthen-0.0.2/LICENSE +21 -0
- whenthen-0.0.2/PKG-INFO +158 -0
- whenthen-0.0.2/README.md +136 -0
- whenthen-0.0.2/docs/adr/0001-home-language-seams-and-v1.md +133 -0
- whenthen-0.0.2/docs/research/01-os-scheduler-backends.md +126 -0
- whenthen-0.0.2/docs/research/02-libraries-and-language.md +216 -0
- whenthen-0.0.2/docs/research/03-agent-scheduling-practice.md +129 -0
- whenthen-0.0.2/docs/research/04-scheduler-patterns-and-conditions.md +149 -0
- whenthen-0.0.2/docs/research/05-claude-code-native-scheduling.md +144 -0
- whenthen-0.0.2/docs/research/README.md +140 -0
- whenthen-0.0.2/pyproject.toml +179 -0
- whenthen-0.0.2/tests/conftest.py +50 -0
- whenthen-0.0.2/tests/test_core.py +424 -0
- whenthen-0.0.2/tests/test_tools.py +388 -0
- whenthen-0.0.2/tests/test_triggers.py +190 -0
- whenthen-0.0.2/whenthen/__init__.py +60 -0
- whenthen-0.0.2/whenthen/__main__.py +79 -0
- whenthen-0.0.2/whenthen/_bundled.py +174 -0
- whenthen-0.0.2/whenthen/clocks.py +255 -0
- whenthen-0.0.2/whenthen/core.py +999 -0
- whenthen-0.0.2/whenthen/data/agents/whenthen-keeper.md +74 -0
- whenthen-0.0.2/whenthen/data/skills/whenthen/SKILL.md +133 -0
- whenthen-0.0.2/whenthen/data/skills/whenthen/references/agent-tasks.md +18 -0
- whenthen-0.0.2/whenthen/data/skills/whenthen/references/research.md +14 -0
- whenthen-0.0.2/whenthen/errors.py +9 -0
- whenthen-0.0.2/whenthen/store.py +181 -0
- whenthen-0.0.2/whenthen/tools.py +789 -0
- whenthen-0.0.2/whenthen/triggers.py +832 -0
- whenthen-0.0.2/whenthen/vocabulary.py +150 -0
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
.claude/handoffs/
|
|
2
|
+
.claude/scratch/
|
|
3
|
+
|
|
4
|
+
# Byte-compiled / optimized / DLL files
|
|
5
|
+
__pycache__/
|
|
6
|
+
*.py[cod]
|
|
7
|
+
*$py.class
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
.DS_Store
|
|
11
|
+
# C extensions
|
|
12
|
+
*.so
|
|
13
|
+
|
|
14
|
+
# TLS certificates
|
|
15
|
+
## Ignore all PEM files anywhere
|
|
16
|
+
*.pem
|
|
17
|
+
## Also ignore any certs directory
|
|
18
|
+
certs/
|
|
19
|
+
|
|
20
|
+
# Distribution / packaging
|
|
21
|
+
.Python
|
|
22
|
+
build/
|
|
23
|
+
develop-eggs/
|
|
24
|
+
dist/
|
|
25
|
+
downloads/
|
|
26
|
+
eggs/
|
|
27
|
+
.eggs/
|
|
28
|
+
lib/
|
|
29
|
+
lib64/
|
|
30
|
+
parts/
|
|
31
|
+
sdist/
|
|
32
|
+
var/
|
|
33
|
+
wheels/
|
|
34
|
+
node_modules/
|
|
35
|
+
*.egg-info/
|
|
36
|
+
.installed.cfg
|
|
37
|
+
*.egg
|
|
38
|
+
MANIFEST
|
|
39
|
+
_build
|
|
40
|
+
|
|
41
|
+
# PyInstaller
|
|
42
|
+
# Usually these files are written by a python script from a template
|
|
43
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
44
|
+
*.manifest
|
|
45
|
+
*.spec
|
|
46
|
+
|
|
47
|
+
# Installer logs
|
|
48
|
+
pip-log.txt
|
|
49
|
+
pip-delete-this-directory.txt
|
|
50
|
+
|
|
51
|
+
# Unit test / coverage reports
|
|
52
|
+
htmlcov/
|
|
53
|
+
.tox/
|
|
54
|
+
.coverage
|
|
55
|
+
.coverage.*
|
|
56
|
+
.cache
|
|
57
|
+
nosetests.xml
|
|
58
|
+
coverage.xml
|
|
59
|
+
*.cover
|
|
60
|
+
.hypothesis/
|
|
61
|
+
.pytest_cache/
|
|
62
|
+
|
|
63
|
+
# Translations
|
|
64
|
+
*.mo
|
|
65
|
+
*.pot
|
|
66
|
+
|
|
67
|
+
# Django stuff:
|
|
68
|
+
*.log
|
|
69
|
+
local_settings.py
|
|
70
|
+
db.sqlite3
|
|
71
|
+
|
|
72
|
+
# Flask stuff:
|
|
73
|
+
instance/
|
|
74
|
+
.webassets-cache
|
|
75
|
+
|
|
76
|
+
# Scrapy stuff:
|
|
77
|
+
.scrapy
|
|
78
|
+
|
|
79
|
+
# Sphinx documentation
|
|
80
|
+
docs/_build/
|
|
81
|
+
|
|
82
|
+
# PyBuilder
|
|
83
|
+
target/
|
|
84
|
+
|
|
85
|
+
# Jupyter Notebook
|
|
86
|
+
.ipynb_checkpoints
|
|
87
|
+
|
|
88
|
+
# pyenv
|
|
89
|
+
.python-version
|
|
90
|
+
|
|
91
|
+
# celery beat schedule file
|
|
92
|
+
celerybeat-schedule
|
|
93
|
+
|
|
94
|
+
# SageMath parsed files
|
|
95
|
+
*.sage.py
|
|
96
|
+
|
|
97
|
+
# Environments
|
|
98
|
+
.env
|
|
99
|
+
.venv
|
|
100
|
+
env/
|
|
101
|
+
venv/
|
|
102
|
+
ENV/
|
|
103
|
+
env.bak/
|
|
104
|
+
venv.bak/
|
|
105
|
+
|
|
106
|
+
# Spyder project settings
|
|
107
|
+
.spyderproject
|
|
108
|
+
.spyproject
|
|
109
|
+
|
|
110
|
+
# Rope project settings
|
|
111
|
+
.ropeproject
|
|
112
|
+
|
|
113
|
+
# mkdocs documentation
|
|
114
|
+
/site
|
|
115
|
+
|
|
116
|
+
# mypy
|
|
117
|
+
.mypy_cache/
|
|
118
|
+
|
|
119
|
+
# PyCharm
|
|
120
|
+
.idea
|
whenthen-0.0.2/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Thor Whalen
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
whenthen-0.0.2/PKG-INFO
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: whenthen
|
|
3
|
+
Version: 0.0.2
|
|
4
|
+
Summary: When a condition holds, then run a task: one light interface for one-off and recurring commands over the OS scheduler, made to be driven by AI agents.
|
|
5
|
+
Project-URL: Homepage, https://github.com/thorwhalen/whenthen
|
|
6
|
+
Project-URL: Repository, https://github.com/thorwhalen/whenthen
|
|
7
|
+
Project-URL: Documentation, https://thorwhalen.github.io/whenthen
|
|
8
|
+
Author: Thor Whalen
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: agents,automation,cron,scheduling,triggers
|
|
12
|
+
Requires-Python: >=3.10
|
|
13
|
+
Requires-Dist: cw<0.2,>=0.1
|
|
14
|
+
Provides-Extra: dev
|
|
15
|
+
Requires-Dist: pytest-cov>=4.0; extra == 'dev'
|
|
16
|
+
Requires-Dist: pytest>=7.0; extra == 'dev'
|
|
17
|
+
Requires-Dist: ruff>=0.1.0; extra == 'dev'
|
|
18
|
+
Provides-Extra: docs
|
|
19
|
+
Requires-Dist: sphinx-rtd-theme>=1.0; extra == 'docs'
|
|
20
|
+
Requires-Dist: sphinx>=6.0; extra == 'docs'
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
|
|
23
|
+
# whenthen
|
|
24
|
+
|
|
25
|
+
When a condition holds, then run a task: a light scheduler for commands, made to be driven by AI agents.
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
pip install whenthen
|
|
29
|
+
whenthen add backup --command "rsync -a /home/me/notes /backup/notes" --times 03:00 --dry-run
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
```text
|
|
33
|
+
backup: runs `/usr/bin/rsync -a /home/me/notes /backup/notes` at 03:00 every day (Europe/Paris); next Thu 3 Dec 2026 03:00 CET (in 15h 52m), then Fri 4 Dec 2026 03:00 CET, Sat 5 Dec 2026 03:00 CET.
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Drop `--dry-run` and the job is stored, and one line is added to your crontab. That line, the clock, runs `whenthen tick` every minute; the tick works out what is due and runs it. Jobs are small JSON records, not cron lines, so things cron cannot do work anyway:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
whenthen add check-build --command "curl -fsS https://example.com/build" --in 10h # once
|
|
40
|
+
whenthen add poll --command "curl -fsS https://example.com/health" --every 90m # any interval
|
|
41
|
+
whenthen add report --script "weekly-report" --times 09:00 --weekdays mon # a stored script
|
|
42
|
+
whenthen status # is everything running?
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
A laptop that was asleep runs what it missed, once, when it wakes.
|
|
46
|
+
|
|
47
|
+
## Made for agents
|
|
48
|
+
|
|
49
|
+
A person rarely types these commands. An agent reads "update my feeds every weekday at six", emits typed flags, and whenthen checks them and answers with the sentence above, which the agent reads back. The command never parses English, and never stores a cron expression: models get schedules wrong often enough ([research](docs/research/README.md)) that a deterministic check and a plain read-back sit between the sentence and the schedule.
|
|
50
|
+
|
|
51
|
+
Two things ship for Claude Code and are linked into `~/.claude` by one command:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
whenthen install-skills
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
- the **`whenthen` skill**: English to flags, which tool to use when it is not this one, the dry-run and read-back procedure, what needs a person's yes;
|
|
58
|
+
- the **`whenthen-keeper` agent**: sets up several jobs, writes the script when a task is more than one command, audits the schedule, finds out why a job did not run, and returns a short JSON report.
|
|
59
|
+
|
|
60
|
+
Every command prints JSON.
|
|
61
|
+
|
|
62
|
+
## What to run
|
|
63
|
+
|
|
64
|
+
| Form | Flag | Notes |
|
|
65
|
+
|---|---|---|
|
|
66
|
+
| one program with arguments | `--command "prog arg"` | no shell syntax; the program's full path is resolved and stored when you add the job |
|
|
67
|
+
| a stored script | `--script "name arg"` | store it first: `whenthen script-put name --from file` |
|
|
68
|
+
| a Python function | `--call pkg.module:function --param k=v` | runs under the interpreter that added the job |
|
|
69
|
+
| a named recurring request | `--intent key --param k=v` | from the vocabulary, below |
|
|
70
|
+
|
|
71
|
+
Secrets do not go in any of these (they would be stored in the job). Name a file of `NAME=value` lines with `--env-file`; it is read when the job runs.
|
|
72
|
+
|
|
73
|
+
A job runs the script it was added with and no other: the script's hash is stored with the job, and a script changed afterwards is not run until the job is added again with `--replace`. A run started by whenthen cannot add or change jobs, scripts, the vocabulary or the clock.
|
|
74
|
+
|
|
75
|
+
## When to run it
|
|
76
|
+
|
|
77
|
+
| Flag | Meaning |
|
|
78
|
+
|---|---|
|
|
79
|
+
| `--in 10h` | once, a duration from now (`90s`, `20m`, `1h30m`, `2d`, `1w`) |
|
|
80
|
+
| `--at 2026-12-03T07:00` or `--at 15:00` | once, at that time (a bare time means the next time it is that time) |
|
|
81
|
+
| `--every 90m` | repeatedly, at any interval of a minute or more |
|
|
82
|
+
| `--times 07:00,19:00` with `--weekdays mon-fri`, `--days 1,15`, `--months jun-aug` | on a calendar rule |
|
|
83
|
+
| `--cron "0 6 * * 1-6"` | a five-field cron expression, converted to the calendar form |
|
|
84
|
+
| `--tz Europe/Paris` | the zone for wall-clock times (default: the machine's, stored by name when the job is added) |
|
|
85
|
+
| `--on-event build-finished` | no time: the job runs when another program says so (below) |
|
|
86
|
+
|
|
87
|
+
A rule whenthen cannot honour exactly is refused with the reason, not approximated. On the days clocks change, a daily job runs once and an hourly one runs every hour.
|
|
88
|
+
|
|
89
|
+
A job added with `--on-event` waits for a program that already knows the moment: a build script, a git hook, a shortcut on a phone. That program calls `whenthen fire <job> --occurrence <id>`, with an id unique to the event; the same id never runs twice.
|
|
90
|
+
|
|
91
|
+
Policy: `--timeout 30m` stops a long run and everything it started; `--grace 1h` skips an occurrence that would start later than that (default: run it once, however late); `--overlap allow` lets a run start while the previous one is going (default: skip and record it).
|
|
92
|
+
|
|
93
|
+
## Looking after jobs
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
whenthen ls # every job: when, next, last run
|
|
97
|
+
whenthen show <name> # the full record and its latest runs
|
|
98
|
+
whenthen run <name> # run it now, exactly as the clock would
|
|
99
|
+
whenthen runs <name> # history
|
|
100
|
+
whenthen log <name> # the end of the latest run's log
|
|
101
|
+
whenthen pause <name> # resume <name>, rm <name>
|
|
102
|
+
whenthen clock # the crontab line: status | install | remove
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
`whenthen status` reports the things that go wrong silently: a clock that stopped ticking, a job that keeps failing, a job that is overdue, an occurrence skipped as too late or whose run never started, a job record that cannot be read.
|
|
106
|
+
|
|
107
|
+
A job record and the JSON these commands print hold the machine's name, absolute paths and the stored request. Quote the `echo` line in a bug report, not the raw output.
|
|
108
|
+
|
|
109
|
+
## The vocabulary
|
|
110
|
+
|
|
111
|
+
Name a request once, use it by name afterwards:
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
whenthen intent-add backup-notes \
|
|
115
|
+
--command "{python} -m mynotes backup {target?}" \
|
|
116
|
+
--phrase "back up my notes" "save my notes"
|
|
117
|
+
whenthen add nightly-backup --intent backup-notes --times 02:00
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
`{name}` is a required parameter, an argument that is exactly `{name?}` an optional one, `{python}` the interpreter running whenthen. A package can contribute its own entry as a JSON document: `whenthen intent-add --from entry.json`.
|
|
121
|
+
|
|
122
|
+
## From Python
|
|
123
|
+
|
|
124
|
+
```python
|
|
125
|
+
import whenthen
|
|
126
|
+
|
|
127
|
+
result = whenthen.add("poll", command="curl -fsS https://example.com/health", every="90m", dry_run=True)
|
|
128
|
+
print(result["echo"])
|
|
129
|
+
whenthen.status()
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
The verbs are plain functions (`whenthen.tools.verbs`, each importable from `whenthen`); the command line is generated from them. Everything whenthen raises on purpose is a `whenthen.WhenthenError`.
|
|
133
|
+
|
|
134
|
+
## How it is built, and where it grows
|
|
135
|
+
|
|
136
|
+
A job is `(trigger, task, policy)`. One function, `fire(job, occurrence)`, runs a task: it refuses an occurrence it has already seen, applies the overlap rule and the time limit, and writes a run record. The tick asks each job's trigger one question, "is an occurrence due, and under which key?", and knows nothing about times. The places made to be extended:
|
|
137
|
+
|
|
138
|
+
| Seam | Default | Could be |
|
|
139
|
+
|---|---|---|
|
|
140
|
+
| `triggers.KINDS`: a kind of trigger and its answer to the tick | `at`, `every`, `calendar`, `event` | a condition polled each minute, recurrence rules |
|
|
141
|
+
| `clock=` (an object, or a name in `clocks.CLOCKS`) | `cron`: one line in the crontab | a launchd agent, a systemd user timer |
|
|
142
|
+
| `fire <job> --occurrence <key>`, from any program | the tick | a webhook, a file watcher, a phone reporting a named place |
|
|
143
|
+
| `root=` | the data directory: `~/.local/share/whenthen/` (or `$WHENTHEN_DATA_DIR`) | another directory |
|
|
144
|
+
| `spawn=` on `tick` | a detached process on this machine | a Python program that embeds the tick |
|
|
145
|
+
|
|
146
|
+
Conditions that whenthen itself watches (a state, a place) are the next phase: each is one more entry in `KINDS`.
|
|
147
|
+
|
|
148
|
+
The reasoning is in [the decision record](docs/adr/0001-home-language-seams-and-v1.md); the evidence in [the research](docs/research/README.md).
|
|
149
|
+
|
|
150
|
+
## Limits
|
|
151
|
+
|
|
152
|
+
- Times are honoured to the minute, and only while the machine is awake.
|
|
153
|
+
- Jobs run on the machine where they were added.
|
|
154
|
+
- Two data roots on one machine each get their own crontab line.
|
|
155
|
+
- The guards (a run cannot reschedule; a job is bound to its script) protect against accidents and careless agents. They are not a security boundary: anything running as the same user can edit the records.
|
|
156
|
+
- The clock is cron: macOS and Linux. On macOS, cron may need Full Disk Access to reach protected folders.
|
|
157
|
+
- Nothing reports a failure unasked: ask `whenthen status`.
|
|
158
|
+
- Requires Python 3.10 or later. One dependency: [`cw`](https://pypi.org/project/cw/), which generates the command line.
|
whenthen-0.0.2/README.md
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
# whenthen
|
|
2
|
+
|
|
3
|
+
When a condition holds, then run a task: a light scheduler for commands, made to be driven by AI agents.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
pip install whenthen
|
|
7
|
+
whenthen add backup --command "rsync -a /home/me/notes /backup/notes" --times 03:00 --dry-run
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
```text
|
|
11
|
+
backup: runs `/usr/bin/rsync -a /home/me/notes /backup/notes` at 03:00 every day (Europe/Paris); next Thu 3 Dec 2026 03:00 CET (in 15h 52m), then Fri 4 Dec 2026 03:00 CET, Sat 5 Dec 2026 03:00 CET.
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Drop `--dry-run` and the job is stored, and one line is added to your crontab. That line, the clock, runs `whenthen tick` every minute; the tick works out what is due and runs it. Jobs are small JSON records, not cron lines, so things cron cannot do work anyway:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
whenthen add check-build --command "curl -fsS https://example.com/build" --in 10h # once
|
|
18
|
+
whenthen add poll --command "curl -fsS https://example.com/health" --every 90m # any interval
|
|
19
|
+
whenthen add report --script "weekly-report" --times 09:00 --weekdays mon # a stored script
|
|
20
|
+
whenthen status # is everything running?
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
A laptop that was asleep runs what it missed, once, when it wakes.
|
|
24
|
+
|
|
25
|
+
## Made for agents
|
|
26
|
+
|
|
27
|
+
A person rarely types these commands. An agent reads "update my feeds every weekday at six", emits typed flags, and whenthen checks them and answers with the sentence above, which the agent reads back. The command never parses English, and never stores a cron expression: models get schedules wrong often enough ([research](docs/research/README.md)) that a deterministic check and a plain read-back sit between the sentence and the schedule.
|
|
28
|
+
|
|
29
|
+
Two things ship for Claude Code and are linked into `~/.claude` by one command:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
whenthen install-skills
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
- the **`whenthen` skill**: English to flags, which tool to use when it is not this one, the dry-run and read-back procedure, what needs a person's yes;
|
|
36
|
+
- the **`whenthen-keeper` agent**: sets up several jobs, writes the script when a task is more than one command, audits the schedule, finds out why a job did not run, and returns a short JSON report.
|
|
37
|
+
|
|
38
|
+
Every command prints JSON.
|
|
39
|
+
|
|
40
|
+
## What to run
|
|
41
|
+
|
|
42
|
+
| Form | Flag | Notes |
|
|
43
|
+
|---|---|---|
|
|
44
|
+
| one program with arguments | `--command "prog arg"` | no shell syntax; the program's full path is resolved and stored when you add the job |
|
|
45
|
+
| a stored script | `--script "name arg"` | store it first: `whenthen script-put name --from file` |
|
|
46
|
+
| a Python function | `--call pkg.module:function --param k=v` | runs under the interpreter that added the job |
|
|
47
|
+
| a named recurring request | `--intent key --param k=v` | from the vocabulary, below |
|
|
48
|
+
|
|
49
|
+
Secrets do not go in any of these (they would be stored in the job). Name a file of `NAME=value` lines with `--env-file`; it is read when the job runs.
|
|
50
|
+
|
|
51
|
+
A job runs the script it was added with and no other: the script's hash is stored with the job, and a script changed afterwards is not run until the job is added again with `--replace`. A run started by whenthen cannot add or change jobs, scripts, the vocabulary or the clock.
|
|
52
|
+
|
|
53
|
+
## When to run it
|
|
54
|
+
|
|
55
|
+
| Flag | Meaning |
|
|
56
|
+
|---|---|
|
|
57
|
+
| `--in 10h` | once, a duration from now (`90s`, `20m`, `1h30m`, `2d`, `1w`) |
|
|
58
|
+
| `--at 2026-12-03T07:00` or `--at 15:00` | once, at that time (a bare time means the next time it is that time) |
|
|
59
|
+
| `--every 90m` | repeatedly, at any interval of a minute or more |
|
|
60
|
+
| `--times 07:00,19:00` with `--weekdays mon-fri`, `--days 1,15`, `--months jun-aug` | on a calendar rule |
|
|
61
|
+
| `--cron "0 6 * * 1-6"` | a five-field cron expression, converted to the calendar form |
|
|
62
|
+
| `--tz Europe/Paris` | the zone for wall-clock times (default: the machine's, stored by name when the job is added) |
|
|
63
|
+
| `--on-event build-finished` | no time: the job runs when another program says so (below) |
|
|
64
|
+
|
|
65
|
+
A rule whenthen cannot honour exactly is refused with the reason, not approximated. On the days clocks change, a daily job runs once and an hourly one runs every hour.
|
|
66
|
+
|
|
67
|
+
A job added with `--on-event` waits for a program that already knows the moment: a build script, a git hook, a shortcut on a phone. That program calls `whenthen fire <job> --occurrence <id>`, with an id unique to the event; the same id never runs twice.
|
|
68
|
+
|
|
69
|
+
Policy: `--timeout 30m` stops a long run and everything it started; `--grace 1h` skips an occurrence that would start later than that (default: run it once, however late); `--overlap allow` lets a run start while the previous one is going (default: skip and record it).
|
|
70
|
+
|
|
71
|
+
## Looking after jobs
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
whenthen ls # every job: when, next, last run
|
|
75
|
+
whenthen show <name> # the full record and its latest runs
|
|
76
|
+
whenthen run <name> # run it now, exactly as the clock would
|
|
77
|
+
whenthen runs <name> # history
|
|
78
|
+
whenthen log <name> # the end of the latest run's log
|
|
79
|
+
whenthen pause <name> # resume <name>, rm <name>
|
|
80
|
+
whenthen clock # the crontab line: status | install | remove
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
`whenthen status` reports the things that go wrong silently: a clock that stopped ticking, a job that keeps failing, a job that is overdue, an occurrence skipped as too late or whose run never started, a job record that cannot be read.
|
|
84
|
+
|
|
85
|
+
A job record and the JSON these commands print hold the machine's name, absolute paths and the stored request. Quote the `echo` line in a bug report, not the raw output.
|
|
86
|
+
|
|
87
|
+
## The vocabulary
|
|
88
|
+
|
|
89
|
+
Name a request once, use it by name afterwards:
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
whenthen intent-add backup-notes \
|
|
93
|
+
--command "{python} -m mynotes backup {target?}" \
|
|
94
|
+
--phrase "back up my notes" "save my notes"
|
|
95
|
+
whenthen add nightly-backup --intent backup-notes --times 02:00
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
`{name}` is a required parameter, an argument that is exactly `{name?}` an optional one, `{python}` the interpreter running whenthen. A package can contribute its own entry as a JSON document: `whenthen intent-add --from entry.json`.
|
|
99
|
+
|
|
100
|
+
## From Python
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
import whenthen
|
|
104
|
+
|
|
105
|
+
result = whenthen.add("poll", command="curl -fsS https://example.com/health", every="90m", dry_run=True)
|
|
106
|
+
print(result["echo"])
|
|
107
|
+
whenthen.status()
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
The verbs are plain functions (`whenthen.tools.verbs`, each importable from `whenthen`); the command line is generated from them. Everything whenthen raises on purpose is a `whenthen.WhenthenError`.
|
|
111
|
+
|
|
112
|
+
## How it is built, and where it grows
|
|
113
|
+
|
|
114
|
+
A job is `(trigger, task, policy)`. One function, `fire(job, occurrence)`, runs a task: it refuses an occurrence it has already seen, applies the overlap rule and the time limit, and writes a run record. The tick asks each job's trigger one question, "is an occurrence due, and under which key?", and knows nothing about times. The places made to be extended:
|
|
115
|
+
|
|
116
|
+
| Seam | Default | Could be |
|
|
117
|
+
|---|---|---|
|
|
118
|
+
| `triggers.KINDS`: a kind of trigger and its answer to the tick | `at`, `every`, `calendar`, `event` | a condition polled each minute, recurrence rules |
|
|
119
|
+
| `clock=` (an object, or a name in `clocks.CLOCKS`) | `cron`: one line in the crontab | a launchd agent, a systemd user timer |
|
|
120
|
+
| `fire <job> --occurrence <key>`, from any program | the tick | a webhook, a file watcher, a phone reporting a named place |
|
|
121
|
+
| `root=` | the data directory: `~/.local/share/whenthen/` (or `$WHENTHEN_DATA_DIR`) | another directory |
|
|
122
|
+
| `spawn=` on `tick` | a detached process on this machine | a Python program that embeds the tick |
|
|
123
|
+
|
|
124
|
+
Conditions that whenthen itself watches (a state, a place) are the next phase: each is one more entry in `KINDS`.
|
|
125
|
+
|
|
126
|
+
The reasoning is in [the decision record](docs/adr/0001-home-language-seams-and-v1.md); the evidence in [the research](docs/research/README.md).
|
|
127
|
+
|
|
128
|
+
## Limits
|
|
129
|
+
|
|
130
|
+
- Times are honoured to the minute, and only while the machine is awake.
|
|
131
|
+
- Jobs run on the machine where they were added.
|
|
132
|
+
- Two data roots on one machine each get their own crontab line.
|
|
133
|
+
- The guards (a run cannot reschedule; a job is bound to its script) protect against accidents and careless agents. They are not a security boundary: anything running as the same user can edit the records.
|
|
134
|
+
- The clock is cron: macOS and Linux. On macOS, cron may need Full Disk Access to reach protected folders.
|
|
135
|
+
- Nothing reports a failure unasked: ask `whenthen status`.
|
|
136
|
+
- Requires Python 3.10 or later. One dependency: [`cw`](https://pypi.org/project/cw/), which generates the command line.
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
# ADR 0001: home, language, seams, and what version 1 contains
|
|
2
|
+
|
|
3
|
+
- Status: accepted, 2026-12-02
|
|
4
|
+
- Evidence: the five research reports and their synthesis in `docs/research/` (start with `docs/research/README.md`)
|
|
5
|
+
|
|
6
|
+
## Context
|
|
7
|
+
|
|
8
|
+
The need: one light interface through which an AI agent can schedule a command, once ("in 10 hours") or on a recurring rule, turn a person's English into that command and that rule, and keep a vocabulary of recurring requests; later, run a task when a condition other than time holds (a place, an event, a state). It must be usable only through agents, be thin over the schedulers that already exist, and start with cron.
|
|
9
|
+
|
|
10
|
+
What was found before building (details in the synthesis):
|
|
11
|
+
|
|
12
|
+
- No operating-system scheduler offers the same guarantees as another. cron has no one-off, no catch-up after sleep, no overlap control, no "every 90 minutes" and no record of the last run; `at` is switched off on macOS; launchd and systemd timers each add a different subset.
|
|
13
|
+
- Every mature scheduler separates the same things: when (trigger), what (task), how (policy: lateness, overlap, time limit), the stored records, and whatever runs a due job.
|
|
14
|
+
- On the one benchmark found (self-published, not peer-reviewed, older models) language models turned English into a correct cron expression about four times in five, and far less often on the hard cases. Indicative only, but enough that a model must not be the last thing between a sentence and a schedule.
|
|
15
|
+
- A coding agent's own scheduling tools end with its session or run in a vendor's cloud without the local files. Neither replaces a scheduler on the machine.
|
|
16
|
+
- In-process scheduling libraries need a resident process, which is the thing to avoid.
|
|
17
|
+
|
|
18
|
+
## Decisions
|
|
19
|
+
|
|
20
|
+
### 1. Home: a new package, `whenthen`
|
|
21
|
+
|
|
22
|
+
No existing package had scheduling as its subject; the same small "install an OS job for my own command" helper had been written several times inside unrelated packages. A scheduler does not belong inside a messaging, retrieval or session-watching package, and each of those should be able to use it without importing the others. So: a package of its own, named for the model it implements (when a condition holds, then run a task), which still reads correctly once conditions other than time arrive.
|
|
23
|
+
|
|
24
|
+
### 2. Language: Python only, standard library plus `cw`
|
|
25
|
+
|
|
26
|
+
The work is reading a few small files, comparing times and starting a process once a minute. There is no hot path. The standard library covers all of it (`zoneinfo`, `subprocess`, `fcntl`, `json`). The one dependency is `cw`, a zero-dependency adapter that generates the command line from function signatures, so there is no hand-written parser to keep in step with the functions.
|
|
27
|
+
|
|
28
|
+
Not Rust. What would change this: a requirement to run on machines with no Python, or a measured need for a tick that costs under about 20 ms. The answer then is a small Rust program that reads the same JSON records, not a port: the records are the contract.
|
|
29
|
+
|
|
30
|
+
No scheduling library is a dependency. Cron-expression maths is about 100 lines here, and only as an input convenience. `cronsim` and `cron-descriptor` are named in an issue as optional extras for richer cron syntax.
|
|
31
|
+
|
|
32
|
+
### 3. The model
|
|
33
|
+
|
|
34
|
+
- A **job** is `(trigger, task, policy)`, one JSON file.
|
|
35
|
+
- A **trigger** is a tagged record: `{"kind": "at", ...}`, `{"kind": "every", ...}`, `{"kind": "calendar", ...}`, `{"kind": "event", ...}`. The kind answers one question for the tick, `due(trigger, state, since, now)`: is an occurrence due, under which key, and what should be remembered. The tick knows nothing about instants. The three time kinds answer from a next and a previous fire time; the `event` kind always answers no, because its occurrences arrive from outside.
|
|
36
|
+
- An **occurrence** is one firing, identified by a key. For time triggers the key is the scheduled instant in UTC (`20261203T060000Z`); for an event it is whatever identifies the event, any non-empty text.
|
|
37
|
+
- **`fire(job, occurrence)`** is the single entry point that runs a task. It refuses a key it has already seen, skips when the previous run is still going (unless the job allows overlap), builds a small fixed environment, enforces the time limit on the task and on everything the task started, and writes a run record and a log. Every policy lives here, behind one function.
|
|
38
|
+
- A trigger that does not recur by itself (a one-off, an event) is never used up by a busy job: the tick leaves a one-off due until the job is free, and an event that finds the job busy is answered `busy`, unrecorded, so its sender can send it again.
|
|
39
|
+
|
|
40
|
+
### 4. The clock is one cron line and a stateless tick, not one cron line per job
|
|
41
|
+
|
|
42
|
+
Rejected: rendering each job as its own crontab line. That inherits every one of cron's gaps and makes cron the place where the truth about jobs is kept.
|
|
43
|
+
|
|
44
|
+
Chosen: a single crontab line runs `whenthen tick` each minute. The tick reads the job records, computes what has come due since each job was last handled, and starts `fire` for it. Consequences:
|
|
45
|
+
|
|
46
|
+
- "in 10 hours", "every 90 minutes" and "the 1st and 15th" all work on the weakest scheduler there is;
|
|
47
|
+
- a machine that slept runs what it missed, once, when it wakes, and the run record says how late it was;
|
|
48
|
+
- a later, stronger clock (a launchd agent, a systemd user timer) changes one line, not every job (`clocks.tick_spec` gives the command in parts for those);
|
|
49
|
+
- polling a condition every minute, which the next phase needs, is the same loop.
|
|
50
|
+
|
|
51
|
+
The costs, accepted: a process start every minute (tens of milliseconds); times honoured to the minute, not the second; nothing runs while the machine sleeps.
|
|
52
|
+
|
|
53
|
+
The tick claims an occurrence, then starts its run in another process. Two things keep an occurrence from being lost in that gap: a run that could not be started gives the claim back, and a claim that never got a run record is started again on a later tick, three times at most, then reported by `status`. Running twice is prevented where it matters, in `fire`, by the run record of the key.
|
|
54
|
+
|
|
55
|
+
### 5. Code does not parse English
|
|
56
|
+
|
|
57
|
+
The agent reads the person's sentence and emits typed flags (`--in 10h`, `--times 07:00 --weekdays mon-fri`). The command validates them, refuses what it cannot honour exactly, and returns a plain-English reading with the next three fire times, which the agent repeats to the person. A cron expression is accepted as input and immediately converted to the structured form; it is never the stored form.
|
|
58
|
+
|
|
59
|
+
Input that two tools read differently is refused rather than guessed: a weekday is a name, never a number; a date-time has one accepted shape on every Python version; an interval is a whole number of seconds. A calendar rule stores the IANA name of the zone it was added in, so the process cron starts later reads the clock as the person did.
|
|
60
|
+
|
|
61
|
+
### 6. A task is a command
|
|
62
|
+
|
|
63
|
+
One program and its arguments, no shell. The program's path is resolved and stored when the job is added, with the `PATH` it will need, because cron supplies almost none. Anything with several steps is a script stored under the data root; a Python function is reached through `whenthen call package.module:function`, and is imported once when the job is added, in the folder and environment the run will have. A run by an agent (`claude -p …`) is a command like any other for now.
|
|
64
|
+
|
|
65
|
+
### 7. The vocabulary is data
|
|
66
|
+
|
|
67
|
+
A recurring request ("update correspondences") is a small JSON record: a key, the phrases people use, a command template with named parameters. Records live in the user's data root. Another package contributes one by handing a JSON document to `whenthen intent-add --from`; neither package imports the other. whenthen ships no entry that names a third-party command.
|
|
68
|
+
|
|
69
|
+
### 8. Guard rails in version 1
|
|
70
|
+
|
|
71
|
+
- A run started by whenthen cannot change what will run: it may not add, replace, pause, resume or remove jobs, store scripts, change the vocabulary, or install or remove the clock.
|
|
72
|
+
- A job that runs a stored script is bound to that script's content (its SHA-256 is stored with the job). A changed script is not run: the run is recorded as an error until the job is added again on purpose. Replacing a stored script is itself explicit (`--replace`) and names the jobs it affects.
|
|
73
|
+
- A job records who asked and in which words (`source`, `quote`).
|
|
74
|
+
- Secrets are never in a job record: a job names a file of `NAME=value` lines, read when it runs.
|
|
75
|
+
- Removing a job keeps its definition aside.
|
|
76
|
+
- The skill, not the code, carries the rule that only the person's own words schedule anything, and the review of commands that change things beyond their own data or that run an agent.
|
|
77
|
+
|
|
78
|
+
These are guards against accident and against an agent that follows its instructions loosely. They are not a security boundary: any process running as the same user can write the records directly.
|
|
79
|
+
|
|
80
|
+
### 9. The agent surface
|
|
81
|
+
|
|
82
|
+
A skill (`whenthen`) for any session, and a subagent (`whenthen-keeper`) that does multi-job set-up, script writing, audits and diagnosis in a fresh context and returns a short JSON report. Both ship inside the package (`whenthen/data/`) and are linked into a Claude Code home by `whenthen install-skills`. No hook: nothing in a scheduling request needs to run on every tool call.
|
|
83
|
+
|
|
84
|
+
### 10. Surfaces
|
|
85
|
+
|
|
86
|
+
The functions are the interface; a surface is generated from them. `tools.verbs` is what any surface may expose; `tools.machine_verbs` (install or remove the clock, the tick, calling an importable function, linking the skill) is plumbing for the machine whenthen runs on and belongs on the command line only. Would another surface need the core to change?
|
|
87
|
+
|
|
88
|
+
- A command line: built, generated by `cw` from both lists.
|
|
89
|
+
- An MCP server or an HTTP service: no change to the core. Generate it from `tools.verbs`; the content arguments (`text=` on `script_put` and `intent_add`) exist so that such a surface never needs a file path or standard input. It must not expose `machine_verbs`.
|
|
90
|
+
- A page in a browser: it reads the JSON records or calls an HTTP surface; nothing here would run in the browser, since the whole point is a process on the machine.
|
|
91
|
+
|
|
92
|
+
### 11. What was reused, and what was not
|
|
93
|
+
|
|
94
|
+
- `cw` for the command line (a dependency).
|
|
95
|
+
- The linking of bundled skills and agents into Claude Code homes is the `skill` package's `install_bundled`, copied into `whenthen/_bundled.py` with its origin noted, because depending on `skill` would bring a large dependency tree into a package whose promise is to be light.
|
|
96
|
+
- The crontab handling follows the same in-house installer the research describes (one marked line, every other line untouched, split on newlines only, bytes that are not UTF-8 kept as they are).
|
|
97
|
+
- The JSON-files store is forty lines of standard library here rather than `dol`: the records are the contract, and nothing else from a storage library is needed.
|
|
98
|
+
|
|
99
|
+
## Seams
|
|
100
|
+
|
|
101
|
+
| Seam | Where | Default (works with nothing else installed) | A replacement that already exists |
|
|
102
|
+
|---|---|---|---|
|
|
103
|
+
| Trigger kinds | `triggers.KINDS`: kind → `Kind(due, recurring, next_after, previous, cursor, skip_to)`; only `due` is required | `at`, `every`, `calendar`, `event` | a predicate polled by the tick (its own key, its own remembered state, no instants); RFC 5545 recurrence rules; `cronsim` for full cron syntax |
|
|
104
|
+
| The clock: what wakes the tick | `clock=` on `add`, `status`, `clock`: an object with `install()`, `remove()`, `status()`, or a name in `clocks.CLOCKS`; one function chooses the default | `cron`: one marked line per data root in the user's crontab | a launchd agent or a systemd user timer running the same tick (`clocks.tick_spec`) |
|
|
105
|
+
| Occurrences from outside | `fire(job, occurrence=<any text>)`, the same function the tick ends in | the tick | a webhook receiver, a file watcher, a phone reporting a named place |
|
|
106
|
+
| Where records live | `root=` on every function | the data directory `~/.local/share/whenthen/` (or `$WHENTHEN_DATA_DIR`) | another directory. Not another kind of store: locks, logs and scripts are files, and the run that the tick starts is told the directory by an environment variable |
|
|
107
|
+
| How a due occurrence is started | `spawn=` on `tick`, for a Python program that embeds the tick (and for tests); the tick cron runs always uses the default | a detached `whenthen fire` process on this machine | a caller's own process supervisor |
|
|
108
|
+
|
|
109
|
+
NOT seams (decided, and deliberately closed for now): the run-record and job-record formats; the policy fields; the command-line adapter; the task kind (only `command`; a second kind is an issue, not a hidden switch); English parsing (there is none, by decision 5); which clock is installed is not recorded (the default is asked; a second clock needs that recorded first, and the place is marked in `tools._clock_for`).
|
|
110
|
+
|
|
111
|
+
One-command test of the whole path with every seam on a test double: `pytest tests/test_tools.py::test_smoke_add_tick_run_status`.
|
|
112
|
+
|
|
113
|
+
## Version 1 against later
|
|
114
|
+
|
|
115
|
+
| In version 1 | Later (each filed as an issue) |
|
|
116
|
+
|---|---|
|
|
117
|
+
| one-off jobs (`--in`, `--at`), intervals (`--every`), calendar rules (`--times` with weekdays, days of the month, months), cron expressions as input | "every other Friday", "last day of the month", "first Monday"; several triggers on one job; end conditions |
|
|
118
|
+
| the cron clock | launchd and systemd clocks; rendering a job natively to an OS scheduler where exact timing or wake-from-sleep matters |
|
|
119
|
+
| catch-up after sleep, a grace period, overlap skip or allow, a time limit that reaches the whole process group, pause and resume | retries with back-off, jitter, "replace the running one", a policy for exit codes that mean "do not retry" |
|
|
120
|
+
| run records, logs, `status` reporting failing jobs, overdue jobs and a stopped clock | telling the person without being asked: a push, an entry in an attention list, a dead-man ping |
|
|
121
|
+
| commands, stored scripts, Python functions | a first-class agent task with its own limits and result contract |
|
|
122
|
+
| the vocabulary, contributed as JSON; a job bound to its script's hash | packages shipping their entries; typed parameters |
|
|
123
|
+
| jobs that wait for an event sent by an outside program (`--on-event`, then `fire <job> --occurrence <key>`) | conditions whenthen itself watches: predicates polled by the tick; a receiver for events (a payload, a place as a named-place event from a phone, never coordinates in the store) |
|
|
124
|
+
| this machine (the record stores the machine it was added on; nothing reads it yet) | honouring that field when a data root is shared; fan-out to other machines |
|
|
125
|
+
| owner's-words rule and risk review in the skill | a risk floor enforced in code |
|
|
126
|
+
|
|
127
|
+
## Consequences
|
|
128
|
+
|
|
129
|
+
- An agent can be handed "do this every weekday at six" and return a checked job and one line to read back, without knowing cron.
|
|
130
|
+
- The registry is readable JSON, so any other tool (a dashboard, a second implementation) can read it without importing whenthen.
|
|
131
|
+
- Adding a condition that is not a time is an addition (an entry in `KINDS`, or a caller of `fire`), not a change to the tick, jobs, policy or records. A test adds a polled kind in ten lines to keep that true.
|
|
132
|
+
- Retries are not an addition yet: an occurrence key runs at most once, and "not before" has no place in the remembered state. The retry issue says what has to move.
|
|
133
|
+
- Because the tick is the only thing cron runs, a broken interpreter path stops every job at once; `whenthen status` reports a clock that has stopped ticking, and nothing reports it unasked until the "telling the person" issue is done. Until then the readers of `status` are the agents: the skill makes every scheduling request start with `whenthen status` and repeat any problem it lists.
|