# Cron script job hardening note

Case: GitHub Trending daily report.

## What worked
- Moving the job to `no_agent: true` made the script the source of truth.
- Updating a script-only cron job still required a valid `schedule` field.
- Running the script directly in the shell exposed the real bug faster than repeated cron retries.
- UTF-8 locale settings reduced risk of mangled report text.

## What failed first
- The original cron job used an agent prompt and failed with a model auth/runtime issue unrelated to the reporting logic.
- Re-running the same cron action without changing the execution mode repeated the same failure.
- The first script iteration had a Python argument-count bug; local shell execution caught it immediately.
- The HTML parser still needs better extraction of `owner/repo` links and names.

## Verification pattern
1. Run the script by hand.
2. Fix parser/runtime bugs.
3. Update the cron job to `no_agent: true` and point it at the script.
4. Trigger `cronjob run` once.
5. Inspect the generated `~/.hermes/cron/output/<job_id>/` file if the run fails.

## Output file format

Every run of a `no_agent` script job produces a `.md` file at:
`~/.hermes/cron/output/<job_id>/<YYYY-MM-DD_HH-MM-SS>.md`

Format:
```
# Cron Job: <job name>

**Job ID:** <id>
**Run Time:** <timestamp>
**Mode:** no_agent (script)

---

<full script stdout>
```

The metadata header is Hermes-generated; everything after the `---` separator is the script's raw stdout.

## Using outputs for web pages

After reading the most recent output file, you can parse the structured data and build a served HTML page:
1. `read_file` on the latest `.md` in `~/.hermes/cron/output/<job_id>/`
2. Extract relevant fields (repo names, stars, descriptions, etc.)
3. Write a self-contained HTML landing page with `write_file`
4. Serve it via `python3 -m http.server <port> --bind 0.0.0.0` in background mode (use `notify_on_complete=false` — servers don't exit)

## Common output issues
- Scripts that use `mktemp -d` destroy intermediate files — only the stdout is preserved in the output directory.
