From e41ffa6a1454ad4bc8b31092987bd07e84234a0a Mon Sep 17 00:00:00 2001
From: m3tam3re
Date: Sat, 31 Oct 2026 14:36:41 +0100
Subject: [PATCH] fix(windows): add windowless agent-libw for scheduled sync
agent-lib.exe is a console program, so Windows opens a terminal window on
every scheduled run. Ship agent-libw.exe, the same program built with
-H=windowsgui, in the Windows zip for use in the task action. Start the
PowerShell toast without a window, since agent-libw has no console to
inherit.
Co-Authored-By: Claude Opus 5.5
---
.gitignore | 1 +
.goreleaser.yaml | 14 ++++++++++++++
README.md | 1 +
docs/fleet-handoff.md | 11 ++++++++++-
internal/notify/toast_windows.go | 6 ++++++
5 files changed, 32 insertions(+), 1 deletion(-)
diff --git a/.gitignore b/.gitignore
index 3bd1c20..4488b71 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,6 +6,7 @@
# Go build artifacts
agent-lib
agent-lib.exe
+agent-libw.exe
dist/
*.test
*.out
diff --git a/.goreleaser.yaml b/.goreleaser.yaml
index bd5b61d..fd3d577 100644
--- a/.goreleaser.yaml
+++ b/.goreleaser.yaml
@@ -40,6 +40,18 @@ builds:
ldflags:
- -s -w -X github.com/m3tam3re/agent-lib/internal/version.Version={{.Version}}
binary: agent-lib
+ # GUI-Subsystem-Variante fuer die Aufgabenplanung: oeffnet kein
+ # Konsolenfenster, dafuer auch keine Ausgabe auf stdout/stderr.
+ - id: agent-libw
+ env:
+ - CGO_ENABLED=0
+ goos:
+ - windows
+ goarch:
+ - amd64
+ ldflags:
+ - -s -w -H=windowsgui -X github.com/m3tam3re/agent-lib/internal/version.Version={{.Version}}
+ binary: agent-libw
checksum:
name_template: "checksums.txt"
@@ -53,6 +65,8 @@ archives:
# Explizit stabil, damit Fleet-Download-URLs vorhersehbar bleiben:
# .../releases/download//agent-lib__.
name_template: "{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}"
+ # Das Windows-Zip enthaelt zusaetzlich agent-libw.exe.
+ allow_different_binary_count: true
changelog:
sort: asc
diff --git a/README.md b/README.md
index bcb1b9f..675e729 100644
--- a/README.md
+++ b/README.md
@@ -300,6 +300,7 @@ flag that drives the non-zero exit code — suitable for headless drift checks.
| `status` exits 1 | Local modifications block repository updates (or occupy names the repo needs). See `status` output for the item list. |
| Sync fails with clone/fetch error | Work repository unreachable, or token expired. Previous local state remains intact; fix config/network and re-run. |
| No toast on Windows | Toasts need an interactive user session — the scheduled task must run as the logged-in user, not SYSTEM. |
+| Terminal window flashes on scheduled sync (Windows) | The task runs the console program `agent-lib.exe`. Point it at `agent-libw.exe sync` from the same zip: same commands, no window, no output. |
## Development
diff --git a/docs/fleet-handoff.md b/docs/fleet-handoff.md
index 646844e..5b1eea8 100644
--- a/docs/fleet-handoff.md
+++ b/docs/fleet-handoff.md
@@ -27,7 +27,8 @@ the external areas).
- Source of truth: GitHub releases of `m3tam3re/agent-lib`.
- Artifacts: `agent-lib_{windows_amd64,linux_amd64,linux_arm64,darwin_amd64,darwin_arm64}`
- plus `checksums.txt` (tar.gz archives; windows is a zip).
+ plus `checksums.txt` (tar.gz archives; windows is a zip containing
+ `agent-lib.exe` and the windowless `agent-libw.exe`).
- Fleet pins an exact release tag (installer-pin pattern already used for
other tools). **No self-update exists in the binary** — binary updates are
exclusively fleet rollouts. Content updates are pulled by the binary itself.
@@ -68,6 +69,12 @@ Local state (manifest, cached bare repo, sync log) lives per-user:
against the user's profile.
2. Windows toast notifications require an interactive user session. A task
running as SYSTEM produces no visible toasts.
+- On Windows, the task action must run `agent-libw.exe sync`, not
+ `agent-lib.exe sync`. `agent-lib.exe` is a console program, so Windows opens
+ a terminal window for it on every run. `agent-libw.exe` is the same program
+ without a console. It prints nothing, so check the task's last run result
+ (`0` = success, `1` = failed), and run `agent-lib.exe sync` by hand to see
+ the error.
- Suggested cadence: every 1–4 hours plus/except at logon. Sync is idempotent
and cheap when unchanged.
- Optional companion: a drift check running `agent-lib status --json`
@@ -132,6 +139,8 @@ Local state (manifest, cached bare repo, sync log) lives per-user:
admins; token present.
- [ ] Scheduled task runs as the logged-in user; toast appears when a
modified item is skipped (manual visual check on a Windows client).
+- [ ] Windows task action uses `agent-libw.exe`; no terminal window appears
+ when the task runs.
- [ ] `agent-lib status` exits 0 on a clean machine, non-zero after editing a
deployed file (self-test).
- [ ] Drift monitoring consumes `status --json` → `problematic_drift`.
diff --git a/internal/notify/toast_windows.go b/internal/notify/toast_windows.go
index fcad560..13db58e 100644
--- a/internal/notify/toast_windows.go
+++ b/internal/notify/toast_windows.go
@@ -6,8 +6,12 @@ import (
"fmt"
"os/exec"
"strings"
+ "syscall"
)
+// createNoWindow is the Win32 CREATE_NO_WINDOW process creation flag.
+const createNoWindow = 0x08000000
+
// PowerShellToast raises a Windows toast notification by invoking
// PowerShell with an AppId-tagged script — the same mechanism go-toast
// uses, without the dependency.
@@ -36,6 +40,8 @@ func (p PowerShellToast) Send(title, body string) error {
}
script := fmt.Sprintf(toastScript, escape(appID), escape(title), escape(body))
cmd := exec.Command("powershell", "-NoProfile", "-NonInteractive", "-Command", script)
+ // agent-libw has no console to inherit, so PowerShell would open its own.
+ cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true, CreationFlags: createNoWindow}
if out, err := cmd.CombinedOutput(); err != nil {
return fmt.Errorf("toast failed: %v: %s", err, strings.TrimSpace(string(out)))
}