Skip to content

fix(brain): scope query tools by distro - #658

Merged
vladimirrott merged 4 commits into
lacs-project:mainfrom
dannyward630:fix/657-distro-query-tools
Oct 26, 2026
Merged

vladimirrott merged 4 commits into
lacs-project:mainfrom
dannyward630:fix/657-distro-query-tools

Conversation

@dannyward630

@dannyward630 dannyward630 commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The planner previously exposed query tools without applying the distro policy used by propose_plan, while the shared prompt listed those tools and directed Ubuntu users to Fedora's layered-package query.

  • Filter daemon-backed query tools with the same available_on rule as the action catalogue.
  • Keep query_current_user available on every host because the planner resolves it locally.
  • Render the prompt's available-query list from the filtered tool definitions.
  • Make Example B distro-aware: Fedora checks layered packages; Ubuntu and Debian propose AptInstall and let APT report when a package is already installed.

Related Issue

Closes #657

Validation

  • Tests added or updated (extended existing tests; the suite test count is unchanged)
  • Documentation updated if behavior changed (the rendered system prompt now gives distro-specific guidance)
  • Security impact considered (no privileged action path changed)
  • Trust boundary preserved (the planner remains unprivileged; the daemon remains the only privileged executor)
  • CI passes — all PR checks pass at 04edff0; the manual E2E container smoke is skipped for pull request events.
  • cargo fmt --all -- --check — passed.
  • git diff --check — passed.
  • scripts/check_no_secrets.sh on the changed files — passed.
  • CARGO_TARGET_DIR=/private/tmp/sysknife-657-distro-query-tools/target CARGO_PROFILE_TEST_DEBUG=0 CARGO_INCREMENTAL=0 rustup run 1.96.0 cargo test --locked -p sysknife-brain --lib — attempted, but dependency compilation stopped when the filesystem ran out of space while compiling regex-automata and aws-lc-sys. The generated target directory was removed afterward.
  • The requested before-and-after E2E story run, including the no-daemon CLI path, is still outstanding. This macOS checkout has no provisioned Linux VM or running SysKnife daemon for tests/e2e/run-stories.sh.

Notes for Reviewers

The planner regression test compares every query_* name in the rendered Ubuntu and Fedora prompts with the planner's actual tool definitions. It also asserts that query_packages is absent on Ubuntu and present on Fedora, and that query_current_user remains available on both.

AI assistance

Codex (GPT-6) assisted with issue analysis, implementation, regression-test updates, and review.

@vladimirrott vladimirrott left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Danny, I ran the E2E stories you couldn't run from macOS, and the Ubuntu prompt holds up. Rendering {AVAILABLE_QUERY_TOOLS} from query_tools_for_distro was the right call: the list the model reads and the tools it gets offered now come from one place, and your planner test pins that per distro.

What I ran

I ran the same 122 dry-run stories (the curated 26 plus every # Distro: ubuntu story from 55 to 153) on an Ubuntu 24.04 host, first against main at edfb6f24, then against your branch merged onto that commit (04edff03 + edfb6f24). Provider was Groq openai/gpt-oss-120b, since my OpenAI key was revoked. Each side used its own freshly built binary.

passed failed
main 115/122 11, 12, 15, 16, 21, 38, 41
#658 114/122 11, 12, 15, 16, 21, 38, 41, 47

The seven shared failures also fail on main, so they belong to this model. The Ubuntu install stories (57, 85, 95) pass on both.

Story 47 is the one difference. I reran it five more times per side: main passed 6/6 and your branch 1/6. On your branch the model answers "show me all my installed flatpak apps" with UbuntuListFlatpaks instead of ListInstalledFlatpaks. Both build the same flatpak list --user --app argv at Low risk (crates/sysknife-daemon/src/actions/flatpak.rs:110 and :216), and story 130 already accepts either name on Ubuntu for that reason. Story 47 has no distro scope and only accepts the Fedora name. The host sees no difference, and I'll scope story 47 myself.

Mutation results

I broke seven things in the prompt and query-tool code and re-ran your tests. Six went red: offering every tool regardless of distro, leaving the preamble unfiltered, giving Debian the Fedora Example B, dropping query_current_user, a wrong entry in query_tool_action_name, and giving the generic prompt the Debian Example B.

One survived. If I delete the " (params: " block in push_preamble, no test fails, so the model could lose the parameter names and nothing would notice. One assertion closes it:

assert!(ubuntu.contains("`query_logs` (params: `unit`)"));

Before you mark it ready

  • CLAUDE.md still says "on Ubuntu → check dpkg status before proposing AptInstall". Your Debian Example B now tells the model no apt-backed query tool exists and to go straight to AptInstall, so please update that line in this PR.
  • Optional: query_tool_to_action could take its action name from query_tool_action_name, so one table holds the mapping and the parity test has nothing left to guard. I'd merge without it.

Add the assertion and the CLAUDE.md line, mark it ready, and I'll review it the same day. Thank you for taking #657 on so fast, and for doing it without the E2E stories on your machine.

@dannyward630
dannyward630 marked this pull request as ready for review October 26, 2026 02:17
@dannyward630

Copy link
Copy Markdown
Contributor Author

Addressed the requested follow-ups in a7e39e1:

  • Added the Ubuntu prompt assertion for the query_logs (params: unit) block.
  • Updated CLAUDE.md to propose AptInstall directly on Ubuntu without a package query.

cargo fmt --all -- --check and git diff --check pass. I attempted the focused Rust test, but this Windows host cannot compile the unchanged Unix-only UnixDatagram import in crates/sysknife-brain/src/journal.rs; the test needs Linux CI. CI for the updated commit is running now.

@vladimirrott vladimirrott left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Danny, both follow-ups landed the way I asked, and the CLAUDE.md line now reads like the Debian Example B it describes: no package query on Ubuntu, propose AptInstall, let APT say whether it is already there. Approving at a7e39e1.

The new assertion closes the survivor from my last review. I ran it through the merge gate in a container, with a mutation that skips the (params: …) block in push_preamble. The last two lines come from the receipt the gate wrote:

running 'system_prompt_contains_example_c_and_distro_aware_package_example_b' unmutated
rust suite: evidence of 1 executed unit(s), passing unmutated
applying the mutation and re-running
receipt recorded for #658 at a7e39e12 (observed: clean pass, mutated fail)
mutation: s/if !properties.is_empty() {/if false {/
observed_failure: test prompt::tests::system_prompt_contains_example_c_and_distro_aware_package_example_b ... FAILED

The Windows compile failure you hit is the Unix-only import in journal.rs; nothing for you to fix there, and CI is green at this head. The branch is behind main by e99a536, the story 47 scoping I promised in the last review, and git merge-tree reports no conflict.

Thank you for turning both items around the same evening.

@vladimirrott
vladimirrott merged commit 8532cf9 into lacs-project:main Oct 26, 2026
13 checks passed
@vladimirrott

Copy link
Copy Markdown
Member

Merged as 8532cf9. The query_logs params assertion you added kills the mutant that survived my first round, and the CLAUDE.md line now says what the Debian example does. Thank you for turning both around overnight. #657 is closed.

vladimirrott added a commit that referenced this pull request Oct 27, 2026
Minor release. #627 keys request_hash with an HMAC under the audit key
(chain_version 4; previews stored by an older release fail closed after
upgrading) and #639 changes the history request a newer CLI sends, so a
caller relying on the old behaviour notices: the middle digit moves.

Also: the planner sees only its host's distribution (#626, #656, #658,
#684), checkpoint and the MCP audit tools share the audit-store resolver
(#636), every workflow job has a time limit (#662), a weekly cargo audit
(#640), release hardening (#635, #637, #660), and every published figure
is rendered from its source (#685).


Claude-Session: https://claude.ai/code/session_01UpyrhbDTW1gBwzGAC44GYU

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The planner offers Fedora-only query tools on Ubuntu, and Example B tells it to call one

2 participants