Repository navigation
guard, config: honour the local-logs enabled switch - #408
Conversation
The Settings panel's "enabled" toggle under local logs stored security.localLogs.enabled in policy.json, and the client read it back correctly, but nothing else looked at it. WriteLocalLog appended every decision to solongate-audit.jsonl regardless, and LocalLogsSetting parsed the flag and then returned Enabled: true from every branch. So turning local logs off did nothing, and the live view, which takes its on/off marker from LocalLogsSetting, kept saying they were on. The flag now means the same thing everywhere, and the same thing the client already meant by it: with no localLogs block, or a block with no path (which is how the client stands for the default folder), logging is on; with a path, "enabled" decides. - guardcore: WriteLocalLog returns before touching the disk when the block switches logging off. Both writers go through it: the guard's decision record and the PostToolUse audit hook. - config: LocalLogsSetting returns the configured flag instead of a hardcoded true, so the live view's "local" marker and the panels built on it show the real state. The path is still resolved while off, so turning it back on lands where it did before. - health: the local logs check reports "off" as a warning, the way the rate limit and DLP checks report theirs, rather than "on" with the age of whatever an earlier run left in the file. - tui: clearing the path said "local logs off", but a cleared path drops the block and logging carries on in the default folder. The message now says that; the enabled row is the way to turn it off. Tests cover the guard writing nothing to either folder when off, the off rule itself, LocalLogsSetting reporting the configured flag with an absolute, relative or empty path, the doctor check, and the issue's repro: SetLocalLogs with Enabled false, then LocalLogsSetting. Fixes solongate#181. Fixes solongate#127. Signed-off-by: NopeCharon <115794254+NopeCharon@users.noreply.github.com>
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 35 |
| Duplication | 2 |
AI Reviewer: first review requested successfully. AI can make mistakes. Always validate suggestions.
TIP This summary will be updated as you push new changes.
There was a problem hiding this comment.
Pull Request Overview
A backward-compatibility regression should be fixed before merging: configurations that specify only a local-log path may now suppress audit writes because an omitted enabled flag is interpreted as false. No coverage or additional quality findings were reported.
Test suggestions
- Audit logging is skipped when local logs are disabled, including avoidance of fallback writes.
- The localLogsOff decision covers missing blocks, enabled paths, disabled absolute and relative paths, and blank paths.
- LocalLogsSetting preserves enabled=false and enabled=true for configured absolute paths.
- A disabled relative path remains disabled and unusable.
- An empty path reports enabled default-folder behavior regardless of the stored flag.
- Health reports local logs as off even when an older audit file exists.
- SetLocalLogs changes are reflected by config.LocalLogsSetting.
- Clearing the settings path reports fallback to the default folder.
TIP Add review instructions in .codacy/instructions/review.md, or an AGENTS.md, so the reviewer knows your conventions.
TIP How was this review? Give us feedback
| if sec == nil || sec.LocalLogs == nil { | ||
| return false | ||
| } | ||
| return !sec.LocalLogs.Enabled && strings.TrimSpace(sec.LocalLogs.Path) != "" |
There was a problem hiding this comment.
🔴 HIGH RISK
Path-only local-log configurations now stop producing audit entries because an omitted enabled field is treated the same as an explicit false. Preserve the default enabled behavior when the field is absent while still honoring an explicit disabled value, and add a regression test for path-only configuration.
TIP React 👍 if this review is right, or reply with what's wrong and how it could be better to help improve the reviewer.
Fixes #181.
Fixes #127.
The Settings panel has an "enabled" toggle under local logs. It saves
security.localLogs.enabledto the policy file, andSettings.GetLocalLogsreads it back correctly, but nothing else ever read it:guardcore.WriteLocalLogappended every entry tosolongate-audit.jsonlwhatever the flag said.config.LocalLogsSettingparsed the flag and then returnedEnabled: truefrom every branch. The live view takes itslocal ✓ / offmarker from it, so the marker stayed on after the user turned logging off.So turning local logs off did nothing anywhere.
What "off" means
The flag now means the same thing everywhere, and what the client already meant by it. With no
localLogsblock, or a block with an empty path, logging is on: the client stands for the default folder that way (SetLocalLogsdrops the block when the path is cleared, andGetLocalLogsreports that as enabled). With a path,enableddecides. Turning logging off from the default folder therefore works too, because the TUI writes the default folder's path along withenabled: false.Change
packages/guard/guardcore/audit.go:WriteLocalLogreturns before touching the disk whenlocalLogsOff(sec)is true. Both writers of the local audit log go through it: the guard's decision record and the PostToolUseaudithook.packages/core/config/locallogs.go:LocalLogsSettingreturns the configured flag instead of a hardcodedtrue. The path is still resolved while logging is off, so turning it back on writes to the same place as before.packages/core/health/health.go: the local logs check (solongate doctor, and the TUI's diagnostics) reportsoffas a warning, the way the rate limit and DLP checks report theirs, instead of "on" with the age of whatever an earlier run left in the file.packages/tui/panels/settings_keys.go: clearing the path showed "path cleared (local logs off)". A cleared path drops the block, though, and logging carries on in the default folder. The message now says "path cleared (logging to the default folder)". The enabled row is how you turn logging off.The token-usage files the
tokenshook writes next to the audit log aren't covered by this setting, before or after this change. They feed the token counts, not the audit trail.Decision path
This touches
packages/guard, but only the code that writes the audit log after a decision. It doesn't change any allow/deny decision, adds no dependency, and adds no I/O: when logging is off it skips the existingMkdirAlland append. Anyone who switched local logs off in the TUI will now actually get no local audit entries, which is what the switch says.Tests
guardcore:TestWriteLocalLogWritesNothingWhenDisabledchecks that neither the custom folder nor the default folder gets a file.TestLocalLogsOffcovers the rule: no block, enabled, disabled with an absolute or relative path, and disabled with a blank path (which still means the default folder, so logging stays on).config:LocalLogsSettingreports the configured flag with an absolute path (still resolving the file), with a relative path, and as the default with an empty path.health:TestLocalLogCheckReportsOffWhenDisabledreportsoffeven when an older log file sits in the folder.client:TestSetLocalLogsDisabledIsWhatConfigReportsis the issue's repro:SetLocalLogswithEnabled: false, thenconfig.LocalLogsSetting(), then back on.tui/panels: the clear-path test checks the new message.The new tests fail on
main. I rango vet ./...andgo test -count=1 -race ./...inpackages/core,packages/guardandpackages/tuion linux/arm64. For an end-to-end check I built the guard binary and fed it a Claude CodeBashpayload, both as the PreToolUse guard and as theaudithook, under a scratchHOMEwithlocalLogsset to a custom folder:main,enabled: false: 1 line written to the custom folder.enabled: false: nothing written to the custom folder or the default one.enabled: true: 1 line written to the custom folder, as before.I didn't try it in a live agent session.