converting loops

This commit is contained in:
ari committed 2026-11-17 14:22:28 -05:00
1 parent 956158729e
commit a1ebcfb6aa
5 files changed
+15 -15

No files matched your search

+18
View File
@@ -0,0 +1,18 @@
# .agents/looprails
Looprail files for this repo.
## journal-triage
`journal-triage.toml` reads the journald log of this machine, has Claude Opus triage it
against this repo, and writes a report ranked by urgency to `.tmp/journal-reports/<host>-<date>.md` (gitignored).
- `journal-triage/collect.sh`: pulls warnings (and worse), failed units and a digest of
unique messages into the run folder.
- `journal-triage/triage.md`: the brief for Opus. It reads `GUIDELINES.md`, traces each issue to
`hosts/<host>/` or `modules/`, and suggests fixes as repo changes. It only reads and suggests:
no edits, no builds, no sudo.
- Inputs: `since` (default `24 hours ago`), `priority` (`err`, `warning`, `notice`),
`host` (default `fwbook`), `repo` (default `/home/ari/nixos-setup`).
Run: `looprail run .agents/looprails/journal-triage.toml`, or ask the agent to run it.
+45
View File
@@ -0,0 +1,45 @@
name = "journal-triage"
description = "Collect journald warnings, triage them with Claude Opus against this repo, and write an urgency-ranked report with fixes as repo changes."
[inputs.static]
since = { type = "string", description = "How far back to read the journal.", min_length = 1, default = "24 hours ago" }
priority = { type = "enum", description = "Lowest log priority to include.", values = ["err", "warning", "notice"], default = "warning" }
host = { type = "string", description = "Name of the host folder under hosts/ to trace issues to.", min_length = 1, default = "fwbook" }
repo = { type = "string", description = "Path of the NixOS config repo.", min_length = 1, default = "/home/ari/nixos-setup" }
[[step.collect]]
kind = "shell"
description = "Collects journal warnings and failed units into a digest."
cwd = "{{ inputs.repo }}"
run = ["sh .agents/looprails/journal-triage/collect.sh {{ inputs.since }} {{ inputs.priority }}"]
[step.collect.outputs]
raw_log = { type = "string", description = "Path of the full raw journal log." }
digest = { type = "string", description = "Path of the deduplicated digest." }
lines = { type = "int", description = "Number of raw log lines." }
unique = { type = "int", description = "Number of distinct messages." }
[[step.triage]]
kind = "agent"
description = "Has Opus triage the log against the repo and suggest fixes."
needs = ["collect"]
agent = { command = ["claude-agent-acp"], model = "opus" }
cwd = "{{ inputs.repo }}"
brief = "journal-triage/triage.md"
failover = "agent"
[step.triage.outputs]
summary = { type = "string", description = "Markdown report ranked by urgency.", min_length = 1 }
issues = { type = "list", description = "The issues found, with urgency, fix and files.", items = { title = { type = "string" }, urgency = { type = "enum", values = ["critical", "high", "medium", "low", "noise"] }, fix = { type = "string" }, files = { type = "list" } } }
[[step.report]]
kind = "shell"
description = "Writes the report to .tmp/journal-reports."
needs = ["triage"]
run = [
"R={{ inputs.repo }}; mkdir -p \"$R/.tmp/journal-reports\"",
"S={{ steps.triage.outputs.summary }}; H={{ inputs.host }}; R={{ inputs.repo }}; f=\"$R/.tmp/journal-reports/$H-$(date +%Y-%m-%d-%H%M).md\"; printf '%s\\n' \"$S\" > \"$f\"; echo \"report=$f\" >> \"$NBOT_LR_OUTPUTS\"; echo \"Report written to $f\"",
]
[step.report.outputs]
report = { type = "string", description = "Path of the written report." }
+26
View File
@@ -0,0 +1,26 @@
#!/bin/sh
# Collect journald warnings+ and failed units into the run folder, plus a deduplicated digest.
set -eu
since="$1"; priority="$2"
dir="$NBOT_LR_RUN_DIR"
raw="$dir/journal-raw.log"; digest="$dir/journal-digest.txt"
journalctl -p "$priority" --since "$since" --no-pager -q -o short-iso > "$raw" || true
{
echo "=== Failed systemd units ==="
systemctl --failed --no-legend --plain || true
systemctl --user --failed --no-legend --plain 2>/dev/null || true
echo
echo "=== Boots in window ==="
journalctl --list-boots --no-pager -q | tail -5 || true
echo
echo "=== Unique messages (count, source: message; numbers/hex normalized), most frequent first ==="
cut -d' ' -f3- "$raw" \
| sed -E 's/\[[0-9]+\]//; s/0x[0-9a-fA-F]+/0xN/g; s/[0-9]+/N/g' \
| sort | uniq -c | sort -rn | head -400
} > "$digest"
lines=$(wc -l < "$raw")
uniq=$(grep -c '^ *[0-9]' "$digest" || true)
printf 'raw_log=%s\ndigest=%s\nlines=%s\nunique=%s\n' "$raw" "$digest" "$lines" "$uniq" >> "$NBOT_LR_OUTPUTS"
@@ -0,0 +1,65 @@
You are triaging the systemd journal of the NixOS host `{{ inputs.host }}`, and tracing each issue
back to the NixOS config repo that builds it: {{ inputs.repo }} (your working folder).
Window: since {{ inputs.since }}, priority {{ inputs.priority }} and worse.
{{ steps.collect.outputs.lines }} log lines, {{ steps.collect.outputs.unique }} distinct messages.
- Digest (failed units, boots, deduplicated messages with counts): {{ steps.collect.outputs.digest }}
- Full raw log (timestamps, for context): {{ steps.collect.outputs.raw_log }}
## Rules: read and suggest only
- Change nothing. Do not edit, create or delete files, in the repo or anywhere else.
- Do not run builds or switches: no `nixos-rebuild`, `nh`, `skyg`, `nix build`, `nix flake check`,
`nixos-anywhere`, docker/podman builds. No sudo. No git commands that change state.
- You may run read-only commands: `systemctl status`, `journalctl -u`, `ls`, `cat`, `grep`, `rg`,
`git log`, `git diff`, `nix-instantiate --parse`.
- Never read anything in `secrets/`.
## Steps
1. Read `GUIDELINES.md` in the repo. Your suggested changes must follow it.
2. Read the digest, then grep the raw log for detail where needed.
3. Group related messages into issues. Ignore harmless boot-time noise unless it points to
something real; list it briefly under "noise" so the reader knows it was seen.
4. For each real issue, find where it comes from in the repo: start with `hosts/{{ inputs.host }}/`,
then `modules/`, `configs/`, `pkgs/` and `flake.nix`. Check whether another host
(`hosts/*/`) already solves the same problem, and reuse that pattern.
Note when the cause is outside the repo (a hand-written file in `~/.config`, state on disk).
## How to write fixes
- Give each fix as a short suggested Nix change with its repo path, e.g.
`hosts/{{ inputs.host }}/systemd.nix` plus a small snippet.
- Follow the repo's layout: put config in the matching host sub-file (`hardware.nix`, `systemd.nix`,
`packages.nix`, `networking.nix`, `services.nix` or `services/<name>.nix`, `home/default.nix`).
Custom options live under `skyg.*`; check `modules/lib.nix` before naming one.
- Never suggest `imports = [...]` in host files.
- Never suggest editing `flake.lock`, anything in `hosts/*/hardware-configuration/` or
`*.hardware-configuration.nix`, or `secrets/`. If the cause lives there, say so and suggest an
override in the right host sub-file instead (e.g. `fileSystems."/boot".options` in `hardware.nix`
with `lib.mkForce`).
- When a fix is imperative (a one-off command), say it needs to be run by hand, and prefer a
declarative option when one exists.
- Remind the reader that they rebuild themselves; do not tell them a change has been applied.
## Urgency
- critical: data loss, security, hardware failing, system unbootable or core service down
- high: a service failing or crash-looping, repeated errors with user-visible effect
- medium: degraded behaviour, misconfiguration, something that will bite later
- low: cosmetic or rare warnings worth a look
- noise: benign, safe to ignore
## Output
`summary` is a Markdown report:
- a one-paragraph overview
- sections by urgency, critical first; each issue with evidence (unit, sample message, count,
first/last seen), likely cause, the repo files involved, and fixes as suggested repo changes
- a short "Repo recommendations" section: patterns across hosts or modules worth changing
(duplication, hand-made units that should be declarative, a fix that would help other hosts too)
Keep it concise, with plain words.
`issues` is the same issues as a list; `files` holds the repo paths involved (empty if none).