Skip to content

guard, config: honour the local-logs enabled switch - #408

Merged
codeyevsky merged 2 commits into
solongate:mainfrom
NopeCharon:fix/local-logs-enabled
Nov 23, 2026
Merged

codeyevsky merged 2 commits into
solongate:mainfrom
NopeCharon:fix/local-logs-enabled

Conversation

@NopeCharon

Copy link
Copy Markdown
Contributor

Fixes #181.
Fixes #127.

The Settings panel has an "enabled" toggle under local logs. It saves security.localLogs.enabled to the policy file, and Settings.GetLocalLogs reads it back correctly, but nothing else ever read it:

  • guardcore.WriteLocalLog appended every entry to solongate-audit.jsonl whatever the flag said.
  • config.LocalLogsSetting parsed the flag and then returned Enabled: true from every branch. The live view takes its local ✓ / off marker 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 localLogs block, or a block with an empty path, logging is on: the client stands for the default folder that way (SetLocalLogs drops the block when the path is cleared, and GetLocalLogs reports that as enabled). With a path, enabled decides. Turning logging off from the default folder therefore works too, because the TUI writes the default folder's path along with enabled: false.

Change

  • packages/guard/guardcore/audit.go: WriteLocalLog returns before touching the disk when localLogsOff(sec) is true. Both writers of the local audit log go through it: the guard's decision record and the PostToolUse audit hook.
  • packages/core/config/locallogs.go: LocalLogsSetting returns the configured flag instead of a hardcoded true. 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) reports off as 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 tokens hook 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 existing MkdirAll and 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: TestWriteLocalLogWritesNothingWhenDisabled checks that neither the custom folder nor the default folder gets a file. TestLocalLogsOff covers 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: LocalLogsSetting reports the configured flag with an absolute path (still resolving the file), with a relative path, and as the default with an empty path.
  • health: TestLocalLogCheckReportsOffWhenDisabled reports off even when an older log file sits in the folder.
  • client: TestSetLocalLogsDisabledIsWhatConfigReports is the issue's repro: SetLocalLogs with Enabled: false, then config.LocalLogsSetting(), then back on.
  • tui/panels: the clear-path test checks the new message.

The new tests fail on main. I ran go vet ./... and go test -count=1 -race ./... in packages/core, packages/guard and packages/tui on linux/arm64. For an end-to-end check I built the guard binary and fed it a Claude Code Bash payload, both as the PreToolUse guard and as the audit hook, under a scratch HOME with localLogs set to a custom folder:

  • main, enabled: false: 1 line written to the custom folder.
  • This branch, enabled: false: nothing written to the custom folder or the default one.
  • This branch, enabled: true: 1 line written to the custom folder, as before.

I didn't try it in a live agent session.

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>
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 35 complexity · 2 duplication

Metric Results
Complexity 35
Duplication 2

View in Codacy

AI Reviewer: first review requested successfully. AI can make mistakes. Always validate suggestions.

Run reviewer

TIP This summary will be updated as you push new changes.

@codacy-production codacy-production Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

⚠️ Resolve issues before merging

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) != ""

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 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.

@codeyevsky
codeyevsky merged commit 48a119c into solongate:main Nov 23, 2026
37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants