From d337d7605e9ba995cc20b3b8973a1f34e953e844 Mon Sep 17 00:00:00 2001 From: Ari Sosnovsky Date: Mon, 9 Nov 2026 16:06:03 -0500 Subject: [PATCH] workflows --- .agents/workflows/ABOUTME.md | 18 ++++++ .agents/workflows/journal-triage.toml | 42 +++++++++++++ .agents/workflows/journal-triage/collect.sh | 26 +++++++++ .agents/workflows/journal-triage/triage.md | 65 +++++++++++++++++++++ flake.lock | 8 +-- hosts/fwbook/packages.nix | 5 +- 6 files changed, 157 insertions(+), 7 deletions(-) create mode 100644 .agents/workflows/ABOUTME.md create mode 100644 .agents/workflows/journal-triage.toml create mode 100755 .agents/workflows/journal-triage/collect.sh create mode 100644 .agents/workflows/journal-triage/triage.md diff --git a/.agents/workflows/ABOUTME.md b/.agents/workflows/ABOUTME.md new file mode 100644 index 0000000..c90132c --- /dev/null +++ b/.agents/workflows/ABOUTME.md @@ -0,0 +1,18 @@ +# .agents/workflows + +nbot-wf workflow 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 `~/journal-reports/-.md`. + +- `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//` 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: `nbot-wf run .agents/workflows/journal-triage.toml`, or ask the agent to run it. diff --git a/.agents/workflows/journal-triage.toml b/.agents/workflows/journal-triage.toml new file mode 100644 index 0000000..444ef7b --- /dev/null +++ b/.agents/workflows/journal-triage.toml @@ -0,0 +1,42 @@ +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", min_length = 1, default = "24 hours ago" } +priority = { type = "enum", values = ["err", "warning", "notice"], default = "warning" } +host = { type = "string", min_length = 1, default = "fwbook" } +repo = { type = "string", min_length = 1, default = "/home/ari/nixos-setup" } + +[[step.collect]] +kind = "shell" +cwd = "{{ inputs.repo }}" +run = ["sh .agents/workflows/journal-triage/collect.sh {{ inputs.since }} {{ inputs.priority }}"] + +[step.collect.outputs] +raw_log = { type = "string" } +digest = { type = "string" } +lines = { type = "int" } +unique = { type = "int" } + +[[step.triage]] +kind = "agent" +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", min_length = 1 } +issues = { type = "list", items = { title = { type = "string" }, urgency = { type = "enum", values = ["critical", "high", "medium", "low", "noise"] }, fix = { type = "string" }, files = { type = "list" } } } + +[[step.report]] +kind = "shell" +needs = ["triage"] +run = [ + "mkdir -p \"$HOME/journal-reports\"", + "S={{ steps.triage.outputs.summary }}; H={{ inputs.host }}; f=\"$HOME/journal-reports/$H-$(date +%Y-%m-%d-%H%M).md\"; printf '%s\\n' \"$S\" > \"$f\"; echo \"report=$f\" >> \"$NBOT_WF_OUTPUTS\"; echo \"Report written to $f\"", +] + +[step.report.outputs] +report = { type = "string" } diff --git a/.agents/workflows/journal-triage/collect.sh b/.agents/workflows/journal-triage/collect.sh new file mode 100755 index 0000000..fc300ca --- /dev/null +++ b/.agents/workflows/journal-triage/collect.sh @@ -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_WF_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_WF_OUTPUTS" diff --git a/.agents/workflows/journal-triage/triage.md b/.agents/workflows/journal-triage/triage.md new file mode 100644 index 0000000..f091d7d --- /dev/null +++ b/.agents/workflows/journal-triage/triage.md @@ -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/.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). diff --git a/flake.lock b/flake.lock index d167cf6..f98cf56 100644 --- a/flake.lock +++ b/flake.lock @@ -2204,11 +2204,11 @@ ] }, "locked": { - "lastModified": 1794248263, - "narHash": "sha256-HFSSuT6ui+aTf7LrlrJUt6Jw5wyRObc5aF5/iDOKhHM=", + "lastModified": 1794253216, + "narHash": "sha256-nS/kSCqzFFMqi6JcVwWE6dKfOUYAkA6XJ9s5ufH2840=", "ref": "refs/heads/main", - "rev": "40b1496b6ffb0d3d1979b4af95ac9b812f93af14", - "revCount": 1009, + "rev": "4fdd29281814a399ba14540235f46be5b0db2820", + "revCount": 1032, "type": "git", "url": "ssh://git@github.com/asosnovsky/nbot.git" }, diff --git a/hosts/fwbook/packages.nix b/hosts/fwbook/packages.nix index 920fb5d..8591e4d 100644 --- a/hosts/fwbook/packages.nix +++ b/hosts/fwbook/packages.nix @@ -1,4 +1,4 @@ -{ pkgs, unstablePkgs, hermes-agent, nixarchy, skygUtils, config, ... }: +{ pkgs, unstablePkgs, hermes-agent, nixarchy, skygUtils, config, nbot, ... }: let # Omarchy (nixarchy) shell, hand-wired — no nixarchy modules. The shell is # launched from configs/fwbook/hypr/conf/autostart.lua (omarchy-launch-shell). @@ -55,8 +55,6 @@ in environment.systemPackages = [ omarchy ] ++ omarchyRuntime - # Theme application: omarchy-theme-set-gnome writes gsettings, and every - # theme names a Yaru icon variant. ++ (with pkgs; [ glib gsettings-desktop-schemas @@ -174,6 +172,7 @@ in delta-editor herdr hermes-agent.packages.${pkgs.stdenv.hostPlatform.system}.default + nbot.packages.${pkgs.stdenv.hostPlatform.system}.nbot-wf skygqts hermenix