From f793c04c1e6a5275b9a7a20a91b68cf16020cfc0 Mon Sep 17 00:00:00 2001 From: Hirogen Date: Thu, 19 Nov 2026 21:27:47 +0100 Subject: [PATCH] Load agent steering from the repo root and add format and resx checks - Root CLAUDE.md with project facts; Claude Code never loaded .github/CLAUDE.md. Generic agent rules move to .github/agent-guidelines.md. - docs/CODING_STANDARDS.md for review-time rules (no XML docs on internal/private members), tracked via a .gitignore exception. - CI: dotnet format whitespace check on the C# files a PR changes, and tools/Test-ResxKeyParity.ps1 for en/de/zh-CN key parity. - Resources.de.resx: add the three missing ColumnizerMask column keys. - src/.editorconfig: ReSharper final-newline setting now matches insert_final_newline = false. - devcontainer sets core.hooksPath to .githooks. --- .devcontainer/devcontainer.json | 2 +- .github/CLAUDE.md | 415 +--------------------- .github/agent-guidelines.md | 142 ++++++++ .github/workflows/test_dotnet.yml | 12 + .gitignore | 1 + CLAUDE.md | 81 +++++ docs/CODING_STANDARDS.md | 26 ++ src/.editorconfig | 2 +- src/LogExpert.Resources/Resources.de.resx | 9 + tools/Test-ResxKeyParity.ps1 | 77 ++++ 10 files changed, 351 insertions(+), 416 deletions(-) create mode 100644 .github/agent-guidelines.md create mode 100644 CLAUDE.md create mode 100644 docs/CODING_STANDARDS.md create mode 100644 tools/Test-ResxKeyParity.ps1 diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 275a90052..897c3c3ed 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -20,7 +20,7 @@ // } // Use 'postCreateCommand' to run commands after the container is created. - // "postCreateCommand": "dotnet restore", + "postCreateCommand": "git config core.hooksPath .githooks", // Configure tool-specific properties. // Configure tool-specific properties. diff --git a/.github/CLAUDE.md b/.github/CLAUDE.md index 018a6afa9..e2a2b6193 100644 --- a/.github/CLAUDE.md +++ b/.github/CLAUDE.md @@ -1,414 +1 @@ -# CLAUDE.md - -This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. - -# Karpathy Guidelines - -Behavioral guidelines to reduce common LLM coding mistakes. - -**Tradeoff:** These guidelines bias toward caution over speed. For trivial tasks, use judgment. - -## 0. Fast Path for Trivial Tasks - -**For obvious, low-risk, reversible, text only ( no source code ), single-file changes, execute directly with minimal ceremony.** - -- Do not create a plan, spawn or delegate to agents, run quorum review, inspect unrelated files, perform broad searches, or run Git archaeology. -- Read only the target and, when genuinely necessary, one directly relevant instruction or nearby example. -- Do not ask questions when the request and local convention determine the result; make the obvious reversible assumption. -- Use the minimum tool calls: inspect, edit, and verify once. Keep progress narration to one short update at most. -- If the preferred editing tool fails once because of an environment or tooling problem, use a safe direct fallback. Do not repeatedly debug the tool unless no safe fallback exists. -- Verification should be proportional to the change. For a simple text edit, rereading the changed content is sufficient. - -This fast path overrides the planning, clarification, delegation, and quorum-review requirements below for trivial tasks. Higher-priority system, developer, safety, and explicitly invoked skill instructions still apply. - -## 1. Clarify Before Executing - -**Resolve ambiguity up front — before spawning agents or starting any autonomous work.** - -Do this in order, then stop and ask before proceeding: - -1. **Understand the request.** Read what was asked closely and state your assumptions explicitly. -2. **Inspect the codebase.** Check the relevant code, conventions, and existing patterns. Note anything that's unclear or that could be interpreted in more than one way. -3. **Ask.** Raise every consequential question now, batched together — don't pick an interpretation silently, and don't defer the question into the work itself. - -Throughout: - -- If multiple interpretations exist, present them — don't choose one silently. -- If a simpler approach exists, say so. Push back when warranted. -- Don't invent APIs. Confirm a function, flag, or endpoint exists — and check its signature — before calling it. If you can't verify it, say so rather than guessing. - -Only once these questions are resolved do you move to execution (§4). - -## 2. Simplicity First - -**Minimum code that solves the problem. Nothing speculative.** - -- No features beyond what was asked. -- No abstractions for single-use code. -- No "flexibility" or "configurability" that wasn't requested. -- No error handling for impossible scenarios. -- If you write 200 lines and it could be 50, rewrite it. - -**Minimal comments**: - -- avoid adding code comments unless necessary (i.e. only if the code itself is not self explanatory). When necessary, code comments must be as brief as possible to ensure readability and avoid overbloating. - -Ask yourself: "Would a senior engineer say this is overcomplicated?" If yes, simplify. - -## 3. Surgical Changes - -**Touch only what you must. Clean up only your own mess.** - -When editing existing code: - -- Don't "improve" adjacent code, comments, or formatting. -- Don't refactor things that aren't broken. -- Match existing style, even if you'd do it differently. -- If you spot problems outside your task — dead code, bugs — mention them; don't fix or delete them unless asked. - -When your changes create orphans: - -- Remove imports/variables/functions that YOUR changes made unused. -- Don't remove pre-existing dead code unless asked. - -The test: every changed line should trace directly to the user's request. - -## 4. Goal-Driven Execution - -**Define success criteria. Loop until verified.** - -Begin only once §1's questions are resolved. Then turn the task into a verifiable goal with an observable check. A passing test is the strongest check; a clean typecheck, running it and inspecting output, or diffing against expected output also count. - -- "Add validation" → "Write tests for invalid inputs, then make them pass" -- "Fix the bug" → "Write a test that reproduces it, then make it pass" -- "Refactor X" → "Ensure tests pass before and after" -- "Update the config" → "Apply it, start the service, and confirm the setting takes effect" - -For multi-step tasks, state a brief plan: - -``` -1. [Step] → verify: [check] -2. [Step] → verify: [check] -3. [Step] → verify: [check] -``` - -When no obvious check exists (docs, exploration, some one-off scripts), ask how to verify success before starting. Don't report success you haven't actually observed. - -Strong, agreed-upon criteria — settled in §1 — let you loop independently. Weak criteria ("make it work") force constant clarification, which is why §1 comes first. - -## 5. Delegate Grunt Work Down a Tier - -**Spend the capable model on judgment; push mechanical, low-context work to a cheaper model.** - -Act as an orchestrator. Fan out grunt work — reading files, gathering context, simple searches, minor mechanical edits, other simple tool calls — to cheaper agents, then review their findings and any code changes yourself before acting on them. Keep the important and dangerous work — architecture, ambiguous decisions, risky or hard-to-reverse edits, final review — on the more capable model. - -When delegation is available, use a less capable, cheaper model for genuinely simple, mechanical, low-risk work. Keep tasks requiring substantial context or judgment on the primary, more capable model. - -Match the model to the task: pick the cheapest tier that can do the job well, and skip an intermediate tier when the work is simple enough for a lower one. - -Guidelines: - -- Only delegate work that is genuinely low-context and low-risk. If doing it well requires the capable model's judgment, keep it. -- Give each agent a self-contained task with clear success criteria (per §4) so you can verify its output without redoing the work. -- Never merge a delegated finding or edit unblocked — review it first. The cheaper model did the legwork; you own the decision. - -## 6. Quorum Review for Big Changes - -**For bigger changes, three agents check the work and two of three must agree before it counts as a success.** - -This applies to any change that is large, or that spans multiple files. For trivial, single-file edits, skip it and use §4's normal verification. - -- Spawn **three independent agents** to review the completed change, each judging against the success criteria settled in §1/§4. -- **Vary each agent's prompt slightly so they are not identical.** Give them the same context and criteria, but frame each reviewer differently — a distinct persona or emphasis (e.g. one as a correctness-focused engineer, one probing edge cases, one checking that it actually satisfies the request). Don't hand all three the same "You are a systems engineer…" opening. -- The change is a success only when **at least two of the three agree** it is correct and complete. -- If the vote fails (two or more say it's wrong or incomplete), treat it as not done: address their objections, then re-run the quorum. -- Keep their judgments independent so the vote is meaningful, and read their reasoning yourself before accepting the verdict. - -## 7. Reporting Results - -- Keep straightforward findings and small fixes in chat. -- If a review has four or more substantive findings, or the detailed response would exceed roughly 25 lines, write the full results to a clearly named Markdown file in the repository. -- In chat, provide only a short summary and a link to that report. -- Do not create a report file for a simple bug, small change, or brief explanation. - -## Project Overview - -LogExpert is a Windows log file viewer and analyzer built with C# and Windows Forms. It's a GUI replacement for the Unix `tail` command with extensive features including tail mode, filtering, bookmarks, highlighting, and a plugin-based architecture for parsing custom log formats. - -**Key Technologies:** -- .NET 10.0 (Windows target framework) -- Windows Forms for UI -- Nuke Build System with MSBuild -- NUnit for testing -- Plugin-based architecture - -## Environment - -This is a Windows .NET/WinForms repo. Python is often unavailable — prefer PowerShell, `tshark`, and built-in tooling. Check whether `gh` CLI (and any other external tool) is actually installed before building a plan around it. The active GitHub account is `brunerpat`. - -### Line Endings - -The working tree is CRLF on Windows (only `usedComponents.json` is pinned to LF via [.gitattributes](.gitattributes); there is no global normalization). Never use `sed`-based or other text-tool renames that strip line endings — they produce a whole-file diff of pure line-ending churn. After any bulk rename, verify no references were left unrenamed (a missed reference will break the build). - -## Testing - -Follow TDD for all bug fixes: write a failing test that reproduces the issue first, then fix, then verify the **full suite** passes — not just the new test in isolation (timing/filesystem tests can pass alone but fail alongside the suite). - -## Documentation - -Docs must be code-grounded and reconciled against the actual source and live config, then reader-tested before delivery. Don't document from assumption. - -## Refactoring - -For "behavior-preserving" refactors, explicitly confirm equivalence and flag any unintended logic changes before applying. - -## Build Commands - -### Using Nuke Build (Recommended) - -```powershell -# Build the solution -./build.ps1 - -# Clean and build -./build.ps1 --target Clean Compile - -# Run tests -./build.ps1 --target Test - -# Full release build with packages -./build.ps1 --target Clean Pack CreateSetup --configuration Release -``` - -#### How the Nuke build works - -- `build.ps1` bootstraps and runs the Nuke build defined in [build/Build.cs](build/Build.cs). Targets and their dependencies are declared there in C#. -- **Default target is `Test`** (which depends on `Compile`), so a bare `./build.ps1` restores, compiles, and runs the tests. -- Select targets with `--target ` (space-separated for multiple). Common targets: `Clean`, `Restore`, `Compile`, `Test`, `Pack`, `CreateSetup`, `Publish`. -- List all available targets: `./build.ps1 --help` -- Preview the execution plan without running it: `./build.ps1 --plan` -- Pick build configuration with `--configuration Debug|Release` (defaults to `Debug` locally, `Release` on CI). - -### Using .NET CLI Directly - -```bash -# From src/ directory -dotnet restore -dotnet build --no-restore -dotnet test --no-build --verbosity normal - -# Run specific test project -dotnet test src/LogExpert.Tests/LogExpert.Tests.csproj -``` - -### Important Build Notes - -- **Windows-only**: This project requires Windows and .NET 10.0.100 SDK (specified in [global.json](global.json)) -- **Cannot build on Linux/macOS**: Uses Windows Desktop SDK and Windows Forms -- Nuke build automatically downloads the correct .NET SDK version if needed -- Output directory: `bin/(Debug|Release)/` - -## Architecture - -### High-Level Structure - -The codebase follows a modular architecture with clear separation of concerns: - -``` -LogExpert/ -├── LogExpert/ # Main application entry point and UI orchestration -├── LogExpert.Core/ # Core business logic, log reading, filtering -├── LogExpert.UI/ # Windows Forms UI components and dialogs -├── LogExpert.Resources/ # Localization resources -├── LogExpert.Configuration/# Configuration management -├── ColumnizerLib/ # Plugin interface definitions -├── PluginRegistry/ # Plugin discovery and security -└── Columnizers/ # Built-in columnizer plugins (CSV, JSON, Regex, etc.) -``` - -### Key Architectural Components - -#### 1. Single Instance Mode with IPC -- Application uses a Mutex to ensure single instance per session -- Named pipes (`LogExpertInstanceMutex{sessionId}`) for inter-process communication -- Secondary instances send file paths to primary instance via JSON over named pipes -- See [Program.cs](src/LogExpert/Program.cs) for implementation - -#### 2. Plugin System -- **Columnizers** (`ILogLineColumnizer`): Parse log lines into columns -- **File System Plugins** (`IFileSystemPlugin`): Support non-local file sources (e.g., SFTP) -- **Context Menu Plugins** (`IContextMenuEntry`): Add custom menu items -- **Keyword Actions** (`IKeywordAction`): React to keywords in logs -- Plugin discovery happens at startup via `PluginRegistry` -- Plugins are loaded from `plugins/` and `pluginsx86/` directories -- Security: Plugin hashes are verified against generated hashes (Release builds only) -- See [PLUGIN_DEVELOPMENT_GUIDE.md](src/docs/PLUGIN_DEVELOPMENT_GUIDE.md) for details - -#### 3. Log File Reading -- Abstract base class: `PositionAwareStreamReaderBase` -- Implementations: `PositionAwareStreamReaderSystem`, `PositionAwareStreamReaderLegacy` -- Uses buffered streams for efficient reading of large files -- Supports encoding detection (UTF-8, UTF-16, UTF-32 with BOM) -- Position tracking for tail mode and seeking -- See [src/LogExpert.Core/Classes/Log/](src/LogExpert.Core/Classes/Log/) for implementations - -#### 4. Configuration Management -- Centralized via `ConfigManager.Instance` -- Initialized with application startup path and screen information -- Supports import/export of settings -- Persists user preferences, columnizer history, highlight masks, etc. -- Configuration stored in application startup directory (portable mode) - -#### 5. Windows Forms UI Architecture -- MDI interface with tab support via `AbstractLogTabWindow` -- Main window created in [LogTabWindow.cs](src/LogExpert.UI/Dialogs/LogTabWindow/) -- Custom controls: `BufferedDataGridView`, `LogTabControl`, `DateTimeDragControl` -- High DPI considerations: Avoid `AutoScaleMode` and `AutoScaleDimensions` on individual controls -- Dark mode support via `Application.SetColorMode()` - -### Critical Files and Their Purposes - -- [Program.cs](src/LogExpert/Program.cs) - Application entry point, IPC setup, single instance handling -- [AbstractLogTabWindow.cs](src/LogExpert.UI/Extensions/LogWindow/AbstractLogTabWindow.cs) - Main window factory and orchestration -- [ILogLineColumnizer.cs](src/ColumnizerLib/ILogLineColumnizer.cs) - Core plugin interface for columnizers -- [ColumnizerPicker.cs](src/LogExpert.Core/Classes/Columnizer/ColumnizerPicker.cs) - Automatic columnizer detection -- [PluginRegistry.cs](src/PluginRegistry/) - Plugin discovery and security verification -- [ConfigManager.cs](src/LogExpert.Configuration/) - Configuration persistence and management -- [LogBuffer.cs](src/LogExpert.Core/Classes/Log/LogBuffer.cs) - In-memory log line caching - -## Development Workflow - -### Adding a New Columnizer Plugin - -1. Create new project in `src/` following naming pattern `*Columnizer` -2. Add project reference to `ColumnizerLib` -3. Implement `ILogLineColumnizer` interface -4. Add project to `src/LogExpert.sln` -5. Create corresponding test project in `Tests/` folder -6. Plugin will be auto-discovered at runtime from output directory - -### Modifying Core Log Reading Logic - -- Core reading classes are in [src/LogExpert.Core/Classes/Log/](src/LogExpert.Core/Classes/Log/) -- Inherit from `PositionAwareStreamReaderBase` for custom stream readers -- Key methods to implement: `ReadLine()`, `Position` property, `Seek()` -- Always maintain position tracking for tail mode support - -### Working with Windows Forms UI - -- UI components in `LogExpert.UI` project -- Follow existing High DPI patterns (no AutoScale on controls) -- Test with both light and dark mode (see `SetColorMode()` in Program.cs; the `ColorMode` preference is Light/Dark/System) -- Use localization resources from `LogExpert.Resources` project -- Windows Forms designer files: `*.designer.cs` - -### Test Setup & Conventions - -- Unit tests use NUnit framework with Moq for mocking -- Test projects follow naming pattern `*.Tests` -- Test data stored in `TestData/` directories within test projects -- Run all tests: `./build.ps1 --target Test` -- Run specific test: `dotnet test src/LogExpert.Tests/LogExpert.Tests.csproj` - -## Important Patterns and Conventions - -### Code Style -- Nullable reference types enabled (`enable`) -- `.editorconfig` is the source of truth for formatting and analyzer severities — match it rather than imposing your own style; don't fight or override its rules -- ImplicitUsings enabled -- Assembly signing enabled (Key.snk) - -### Configuration Files -- **Directory.Build.props** - Common MSBuild properties for all projects -- **Directory.Packages.props** - Centralized NuGet package version management -- **global.json** - .NET SDK version pinning (10.0.100) -- **.editorconfig** - Code style and analysis rules - -### Project Organization -- Solution folders: "Columnizers", "Tests", "docs", "setup" -- Test projects nested under "Tests" solution folder -- Columnizer projects nested under "Columnizers" solution folder -- Documentation in `src/docs/` included in solution - -### Git Workflow -- Default branch: `Development` (use for PRs) -- Commit format: **Do not** add a `Co-Authored-By` trailer (or any other agent/AI attribution) to commit messages -- GitHub Actions run on push to Development branch -- AppVeyor is the second CI for builds and artifact creation. It is currently disabled and needs to be re-added alongside GitHub Actions - -## Plugin Security System - -- SHA256 hashes of the built-in plugins are generated during **every** build by - [PluginHashGenerator.targets](src/PluginRegistry/PluginHashGenerator.targets), which runs before - `LogExpert.PluginRegistry` compiles and writes `obj//BuiltInPluginHashes.g.cs` -- Build-order-only `ProjectReference` entries in `LogExpert.PluginRegistry.csproj` guarantee the - plugins are built first -- The table is **not** committed and there is no CI step for it — nothing to regenerate by hand, - nothing to verify, nothing to commit back -- At runtime, `PluginRegistry` verifies plugin hashes before loading; verification is skipped in - Debug builds (`PluginHashCalculator.BypassHashVerification`) -- Users can trust new plugins via UI dialog -- See [PLUGIN_HASH_MANAGEMENT.md](src/docs/PLUGIN_HASH_MANAGEMENT.md) - -## Common Gotchas - -1. **Cross-platform builds fail**: This is Windows-only. Don't attempt Linux/macOS builds. -2. **SDK version mismatch**: Must use .NET 10.0.100 SDK (specified in global.json) -3. **Plugin not loading**: Check output directory - plugins must be in `plugins/` or `pluginsx86/` -4. **High DPI issues**: Never use AutoScaleMode on individual controls, only on forms -5. **IPC failures**: Named pipes require proper Windows permissions and session isolation -6. **Encoding detection**: BOM-less files default to encoding from EncodingOptions -7. **Plugin hashes**: Only verified in Release builds; Debug builds skip verification - -## Dont Do that - -Hard rules — never do these: - -- **Don't add a `Co-Authored-By` trailer** (or any other agent/AI attribution) to commit messages. -- **Don't attempt Linux/macOS builds.** This is Windows-only (Windows Desktop SDK + Windows Forms). -- **Don't use `AutoScaleMode` or `AutoScaleDimensions` on individual controls** — only on forms (High DPI). -- **Don't override or fight `.editorconfig` rules** — it is the source of truth for formatting and analyzer severities. - -## Key Dependencies - -- **NLog**: Logging framework -- **Newtonsoft.Json**: JSON serialization (legacy, but widely used) -- **CsvHelper**: CSV parsing in CsvColumnizer -- **SSH.NET**: SFTP support in SftpFileSystem plugins -- **DockPanelSuite**: Docking panel UI controls -- **Moq/NUnit**: Testing frameworks - -## References - -- Main README: [README.md](README.md) -- Plugin Development: [PLUGIN_DEVELOPMENT_GUIDE.md](src/docs/PLUGIN_DEVELOPMENT_GUIDE.md) -- Plugin Hash System: [PLUGIN_HASH_MANAGEMENT.md](src/docs/PLUGIN_HASH_MANAGEMENT.md) -- GitHub Wiki: https://github.com/LogExperts/LogExpert/wiki -- Discord: https://discord.gg/SjxkuckRe9 - -## Agent skills - -### Issue tracker - -Issues are tracked in `LogExperts/LogExpert` GitHub Issues, read-only for skills via the `gh` CLI — analysis only; only humans post. See `docs/agents/issue-tracker.md`. - -### Triage labels - -Canonical triage roles map to repo labels (`needs-info` → `question`; the rest use default names), used to read/filter issues — skills don't apply labels. See `docs/agents/triage-labels.md`. - -### Domain docs - -Single-context: one `CONTEXT.md` + `docs/adr/` at the repo root. See `docs/agents/domain.md`. - -# Update Rules File -To update this file, ensure that all sections are kept current with the latest architectural decisions, build processes, and development workflows. Follow these guidelines: -- Review and update build commands if there are changes in the build system. -- Reflect any architectural changes in the "Architecture" section. -- Keep development workflow steps accurate for new contributors. -- Regularly verify links to other documentation files. -- Maintain clarity and conciseness for ease of understanding by new developers. -- Use consistent formatting throughout the document. -- Add new sections as needed for significant changes in the project structure or processes. -- Ensure all technical terms are explained or linked to relevant documentation. -- Periodically review for outdated information and remove or update as necessary. -- If told to not do something, ensure this is also added to the "Dont Do that" section. \ No newline at end of file +Moved: project instructions are in the root [CLAUDE.md](../CLAUDE.md); agent behaviour rules are in [agent-guidelines.md](agent-guidelines.md). diff --git a/.github/agent-guidelines.md b/.github/agent-guidelines.md new file mode 100644 index 000000000..7934024cf --- /dev/null +++ b/.github/agent-guidelines.md @@ -0,0 +1,142 @@ +# Agent Guidelines + +Behavioural rules for AI agents working in this repo: how to plan, clarify, delegate and verify. Project facts (build, tests, gotchas) live in the root `CLAUDE.md`. + +## Karpathy Guidelines + +Behavioral guidelines to reduce common LLM coding mistakes. + +**Tradeoff:** These guidelines bias toward caution over speed. For trivial tasks, use judgment. + +### 0. Fast Path for Trivial Tasks + +**For obvious, low-risk, reversible, text only ( no source code ), single-file changes, execute directly with minimal ceremony.** + +- Do not create a plan, spawn or delegate to agents, run quorum review, inspect unrelated files, perform broad searches, or run Git archaeology. +- Read only the target and, when genuinely necessary, one directly relevant instruction or nearby example. +- Do not ask questions when the request and local convention determine the result; make the obvious reversible assumption. +- Use the minimum tool calls: inspect, edit, and verify once. Keep progress narration to one short update at most. +- If the preferred editing tool fails once because of an environment or tooling problem, use a safe direct fallback. Do not repeatedly debug the tool unless no safe fallback exists. +- Verification should be proportional to the change. For a simple text edit, rereading the changed content is sufficient. + +This fast path overrides the planning, clarification, delegation, and quorum-review requirements below for trivial tasks. Higher-priority system, developer, safety, and explicitly invoked skill instructions still apply. + +### 1. Clarify Before Executing + +**Resolve ambiguity up front — before spawning agents or starting any autonomous work.** + +Do this in order, then stop and ask before proceeding: + +1. **Understand the request.** Read what was asked closely and state your assumptions explicitly. +2. **Inspect the codebase.** Check the relevant code, conventions, and existing patterns. Note anything that's unclear or that could be interpreted in more than one way. +3. **Ask.** Raise every consequential question now, batched together — don't pick an interpretation silently, and don't defer the question into the work itself. + +Throughout: + +- If multiple interpretations exist, present them — don't choose one silently. +- If a simpler approach exists, say so. Push back when warranted. +- Don't invent APIs. Confirm a function, flag, or endpoint exists — and check its signature — before calling it. If you can't verify it, say so rather than guessing. + +Only once these questions are resolved do you move to execution (§4). + +### 2. Simplicity First + +**Minimum code that solves the problem. Nothing speculative.** + +- No features beyond what was asked. +- No abstractions for single-use code. +- No "flexibility" or "configurability" that wasn't requested. +- No error handling for impossible scenarios. +- If you write 200 lines and it could be 50, rewrite it. + +**Minimal comments**: + +- avoid adding code comments unless necessary (i.e. only if the code itself is not self explanatory). When necessary, code comments must be as brief as possible to ensure readability and avoid overbloating. + +Ask yourself: "Would a senior engineer say this is overcomplicated?" If yes, simplify. + +### 3. Surgical Changes + +**Touch only what you must. Clean up only your own mess.** + +When editing existing code: + +- Don't "improve" adjacent code, comments, or formatting. +- Don't refactor things that aren't broken. +- Match existing style, even if you'd do it differently. +- If you spot problems outside your task — dead code, bugs — mention them; don't fix or delete them unless asked. + +When your changes create orphans: + +- Remove imports/variables/functions that YOUR changes made unused. +- Don't remove pre-existing dead code unless asked. + +The test: every changed line should trace directly to the user's request. + +### 4. Goal-Driven Execution + +**Define success criteria. Loop until verified.** + +Begin only once §1's questions are resolved. Then turn the task into a verifiable goal with an observable check. A passing test is the strongest check; a clean typecheck, running it and inspecting output, or diffing against expected output also count. + +- "Add validation" → "Write tests for invalid inputs, then make them pass" +- "Fix the bug" → "Write a test that reproduces it, then make it pass" +- "Refactor X" → "Ensure tests pass before and after" +- "Update the config" → "Apply it, start the service, and confirm the setting takes effect" + +For multi-step tasks, state a brief plan: + +``` +1. [Step] → verify: [check] +2. [Step] → verify: [check] +3. [Step] → verify: [check] +``` + +When no obvious check exists (docs, exploration, some one-off scripts), ask how to verify success before starting. Don't report success you haven't actually observed. + +Strong, agreed-upon criteria — settled in §1 — let you loop independently. Weak criteria ("make it work") force constant clarification, which is why §1 comes first. + +### 5. Delegate Grunt Work Down a Tier + +**Spend the capable model on judgment; push mechanical, low-context work to a cheaper model.** + +Act as an orchestrator. Fan out grunt work — reading files, gathering context, simple searches, minor mechanical edits, other simple tool calls — to cheaper agents, then review their findings and any code changes yourself before acting on them. Keep the important and dangerous work — architecture, ambiguous decisions, risky or hard-to-reverse edits, final review — on the more capable model. + +When delegation is available, use a less capable, cheaper model for genuinely simple, mechanical, low-risk work. Keep tasks requiring substantial context or judgment on the primary, more capable model. + +Match the model to the task: pick the cheapest tier that can do the job well, and skip an intermediate tier when the work is simple enough for a lower one. + +Guidelines: + +- Only delegate work that is genuinely low-context and low-risk. If doing it well requires the capable model's judgment, keep it. +- Give each agent a self-contained task with clear success criteria (per §4) so you can verify its output without redoing the work. +- Never merge a delegated finding or edit unblocked — review it first. The cheaper model did the legwork; you own the decision. + +### 6. Quorum Review for Big Changes + +**For bigger changes, three agents check the work and two of three must agree before it counts as a success.** + +This applies to any change that is large, or that spans multiple files. For trivial, single-file edits, skip it and use §4's normal verification. + +- Spawn **three independent agents** to review the completed change, each judging against the success criteria settled in §1/§4. +- **Vary each agent's prompt slightly so they are not identical.** Give them the same context and criteria, but frame each reviewer differently — a distinct persona or emphasis (e.g. one as a correctness-focused engineer, one probing edge cases, one checking that it actually satisfies the request). Don't hand all three the same "You are a systems engineer…" opening. +- The change is a success only when **at least two of the three agree** it is correct and complete. +- If the vote fails (two or more say it's wrong or incomplete), treat it as not done: address their objections, then re-run the quorum. +- Keep their judgments independent so the vote is meaningful, and read their reasoning yourself before accepting the verdict. + +### 7. Reporting Results + +- Keep straightforward findings and small fixes in chat. +- If a review has four or more substantive findings, or the detailed response would exceed roughly 25 lines, write the full results to a clearly named Markdown file in the repository. +- In chat, provide only a short summary and a link to that report. +- Do not create a report file for a simple bug, small change, or brief explanation. + +## Other Working Rules + +### Documentation + +Docs must be code-grounded and reconciled against the actual source and live config, then reader-tested before delivery. Don't document from assumption. + +### Refactoring + +For "behavior-preserving" refactors, explicitly confirm equivalence and flag any unintended logic changes before applying. diff --git a/.github/workflows/test_dotnet.yml b/.github/workflows/test_dotnet.yml index e3379416d..c5617e03d 100644 --- a/.github/workflows/test_dotnet.yml +++ b/.github/workflows/test_dotnet.yml @@ -16,10 +16,22 @@ jobs: steps: - uses: actions/checkout@v4 + with: + fetch-depth: 2 # PR merge commit plus its parents, for the format check + - name: Check resx key parity + run: pwsh -NoProfile -File tools/Test-ResxKeyParity.ps1 - name: Setup .NET uses: actions/setup-dotnet@v4 with: dotnet-version: 10.0.x + - name: Check whitespace formatting of changed C# files + if: github.event_name == 'pull_request' + shell: pwsh + run: | + # Scoped to the PR's changed files: the existing code base has ~480 pre-existing whitespace violations. + $files = @(git diff --name-only --diff-filter=ACMR HEAD^1 HEAD -- 'src/*.cs') + if ($files.Count -eq 0) { Write-Host 'No changed C# files.'; exit 0 } + dotnet format whitespace src/LogExpert.sln --verify-no-changes --include $files - name: Restore dependencies run: dotnet restore working-directory: src diff --git a/.gitignore b/.gitignore index 24e47bf81..f14740a2a 100644 --- a/.gitignore +++ b/.gitignore @@ -621,6 +621,7 @@ temp.txt # roots docs folder should be empty /docs/* +!/docs/CODING_STANDARDS.md # test project logs should be ignored, this is for rolling logfile tests /src/tools/LogRotator/logs/* diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 000000000..e8245f396 --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1,81 @@ +# CLAUDE.md + +LogExpert: Windows log viewer/tail tool in C# / Windows Forms (.NET 10, `net10.0-windows`), Nuke build, NUnit + Moq tests, plugin-based columnizers. Main solution: `src/LogExpert.sln`. Entry point: `src/LogExpert/Program.cs`. + +Before planning, delegating or reviewing a multi-file change, read [.github/agent-guidelines.md](.github/agent-guidelines.md) (clarify-first, simplicity, delegation, quorum-of-3 review). +For repo layout, CI pipelines and the full architecture overview, see [.github/copilot-instructions.md](.github/copilot-instructions.md). + +## Environment + +- Windows only. Python: `py -I`. Python is often unavailable; prefer PowerShell and built-in tooling. +- Check that `gh` (and any other external tool) is installed before planning around it. Active GitHub account: `brunerpat`. +- Line endings: the working tree is CRLF (only `usedComponents.json` is pinned to LF in `.gitattributes`). Never use `sed` or other text tools that strip CRs; they produce whole-file churn. After a bulk rename, check no reference was missed. + +## Build and test + +```powershell +./build.ps1 # default target Test (restore, compile, test) +./build.ps1 --target Clean Compile +./build.ps1 --target Test +./build.ps1 --target Clean Pack CreateSetup --configuration Release +./build.ps1 --help # list targets; --plan previews +``` + +Targets live in `build/Build.cs`. Directly, from `src/`: `dotnet restore`, `dotnet build --no-restore`, `dotnet test --no-build --verbosity normal`, or one project: `dotnet test src/LogExpert.Tests/LogExpert.Tests.csproj`. Output goes to `bin/(Debug|Release)/`. SDK pinned in `global.json`. + +Local checks that CI also runs: + +- `pwsh -File tools/Test-ResxKeyParity.ps1`: resource keys must match across `Resources.resx`, `Resources.de.resx`, `Resources.zh-CN.resx` and `Resources.Designer.cs`. Add every new string to all three resx files. +- `dotnet format whitespace src/LogExpert.sln --verify-no-changes --include `: CI checks only the files a PR changes, because the existing code has many old violations. + +Testing: TDD for bug fixes (failing test first). Then run the **full suite**, not only the new test; timing and filesystem tests can pass alone and fail together. + +### Known flaky UI tests (on `Development` as of 2026-09-26, @ d9845e24) + +Don't chase these as regressions; check whether they're fixed before relying on this. + +- `MarkerWindowTests.InactiveWindow_KeepsItsOwnSearchWhenAnotherWindowSearches` **hangs** the test host (0 % CPU, a LogExpert window left open) in about 1/3 to 1/2 of runs when another LogTabWindow test runs before it in the same process. It passes alone. +- `SelectionPainterTests.PaintedBlock_HasNoInternalEdge_AndErasesOldEdgesAfterSelectionChanges` **fails** deterministically (pixel colour assertion). +- Run UI tests with `--blame-hang --blame-hang-timeout 90s --blame-hang-dump-type none` so a hang names the test. For a clean full run, add `--filter "FullyQualifiedName!~InactiveWindow_KeepsItsOwnSearch"` and treat the painter failure as known. + +## Code style and review + +- `src/.editorconfig` is the source of truth for formatting and analyzer severities. Match it; don't override it. +- Nullable reference types and ImplicitUsings are on; assemblies are signed (`Key.snk`). Package versions are in `src/Directory.Packages.props`. +- When reviewing code, apply [docs/CODING_STANDARDS.md](docs/CODING_STANDARDS.md). +- Before reviewing a PR, check for `docs/improve/review-pr-.md`. If it exists, build on it instead of starting over. Save each finished review there. + +## Architecture pointers + +- `src/LogExpert.Core/Classes/Log/`: log reading (`PositionAwareStreamReaderBase` and its implementations, `LogBuffer`). Keep position tracking intact for tail mode. +- `src/LogExpert.UI/`: WinForms UI. Main window: `src/LogExpert.UI/Dialogs/LogTabWindow/`. Strings come from `src/LogExpert.Resources`. +- `src/ColumnizerLib/ILogLineColumnizer.cs`: plugin interface. New columnizer: a `*Columnizer` project referencing `ColumnizerLib`, added to `src/LogExpert.sln`, with a test project. +- `src/LogExpert/Program.cs`: single-instance mutex plus named-pipe IPC (`LogExpertInstanceMutex{sessionId}`). +- Plugin hashes: `src/PluginRegistry/PluginHashGenerator.targets` writes `obj//BuiltInPluginHashes.g.cs` on every build. Build-order-only `ProjectReference`s in `src/PluginRegistry/LogExpert.PluginRegistry.csproj` make sure plugins build first. The table is not committed: nothing to regenerate, verify or commit. Verification is skipped in Debug (`PluginHashCalculator.BypassHashVerification`). See `src/docs/PLUGIN_HASH_MANAGEMENT.md`. + +## Common gotchas + +1. Linux/macOS builds fail (Windows Desktop SDK). +2. The SDK version must match `global.json`. +3. Plugin not loading: plugins must be in `plugins/` or `pluginsx86/` next to the exe. +4. High DPI: `AutoScaleMode` belongs on forms only, never on individual controls. +5. IPC failures: named pipes need the right Windows permissions and session isolation. +6. BOM-less files fall back to the encoding from `EncodingOptions`. +7. Plugin hashes are only verified in Release builds. +8. Test dark mode as well as light mode (`ColorMode` preference: Light/Dark/System; see `SetColorMode()` in `Program.cs`). + +## Dont Do that + +Hard rules. Never do these: + +- **Don't add a `Co-Authored-By` trailer** (or any other agent/AI attribution) to commit messages. The `.githooks/commit-msg` hook strips them; enable it with `git config core.hooksPath .githooks`. +- **Don't attempt Linux/macOS builds.** +- **Don't use `AutoScaleMode` or `AutoScaleDimensions` on individual controls**, only on forms. +- **Don't override or fight `src/.editorconfig` rules.** + +## Git and CI + +- Default branch `Development`; PRs target it. GitHub Actions run on push and PR to `Development`. AppVeyor is disabled for now. +- Issues are read-only for agents: see `docs/agents/issue-tracker.md`, `docs/agents/triage-labels.md`, and `docs/agents/domain.md` (single `CONTEXT.md` + `docs/adr/`). + +When told not to do something, add it to "Dont Do that". diff --git a/docs/CODING_STANDARDS.md b/docs/CODING_STANDARDS.md new file mode 100644 index 000000000..ff19a2654 --- /dev/null +++ b/docs/CODING_STANDARDS.md @@ -0,0 +1,26 @@ +# Coding Standards + +Rules for judging a change at review time. Formatting and analyzer severities are enforced by `src/.editorconfig`, so they are not repeated here. + +## Comments + +- **No XML doc comments (`///`) on internal or private members, or on test classes and test methods.** `CS1591` is turned off in `src/.editorconfig` on purpose. +- Add code comments only when the code can't explain itself, and keep them as short as possible. + +## Scope of a change + +- Every changed line should trace back to the request. Don't "improve" adjacent code, comments or formatting, and don't refactor what isn't broken. +- Match the existing style of the file, even if you would do it differently. +- Remove imports, variables and functions that the change itself made unused. Leave pre-existing dead code alone and mention it instead. + +## Design + +- Minimum code that solves the problem: no speculative features, configurability, or abstractions for single-use code. +- No error handling for impossible scenarios. +- "Behaviour-preserving" refactors must actually preserve behaviour. Flag any logic change explicitly. + +## Repo-specific + +- High DPI: `AutoScaleMode` / `AutoScaleDimensions` go on forms only, never on individual controls. +- User-visible strings go in the resx files under `src/LogExpert.Resources` (and the plugin `Resources.resx` files), with the same keys in `de` and `zh-CN`. CI runs `tools/Test-ResxKeyParity.ps1`. +- Bug fixes come with a test that reproduces the bug. diff --git a/src/.editorconfig b/src/.editorconfig index af6a16f31..47527c3c2 100644 --- a/src/.editorconfig +++ b/src/.editorconfig @@ -325,7 +325,7 @@ resharper_braces_for_foreach = required resharper_braces_for_ifelse = required resharper_braces_for_while = required resharper_csharp_align_multiline_parameter = true -resharper_csharp_insert_final_newline = true +resharper_csharp_insert_final_newline = false resharper_csharp_max_line_length = 500 resharper_csharp_use_indent_from_vs = false resharper_csharp_wrap_lines = false diff --git a/src/LogExpert.Resources/Resources.de.resx b/src/LogExpert.Resources/Resources.de.resx index 67ef82bf3..6b2824bc5 100644 --- a/src/LogExpert.Resources/Resources.de.resx +++ b/src/LogExpert.Resources/Resources.de.resx @@ -799,6 +799,15 @@ Damit die anderen Fenster beim Auswählen einer Zeile (Mausklick oder Pfeiltaste Applikationsstartupverzeichnis + + Typ + + + Glob verwendet die Platzhalter * und ?. Regex verwendet die .NET-Syntax für reguläre Ausdrücke. + + + Columnizer '{0}' ist nicht installiert – dieser Eintrag wird übersprungen. + Dateinamenmaske (Regex) diff --git a/tools/Test-ResxKeyParity.ps1 b/tools/Test-ResxKeyParity.ps1 new file mode 100644 index 000000000..eec2f6cb1 --- /dev/null +++ b/tools/Test-ResxKeyParity.ps1 @@ -0,0 +1,77 @@ +<# +.SYNOPSIS + Fails when resource keys differ between a neutral Resources.resx, its culture + files (de, zh-CN, ...) and the generated Resources.Designer.cs accessors. + +.DESCRIPTION + For every Resources.resx under src/ that has at least one Resources..resx + sibling: + - each culture file must contain exactly the neutral file's string keys + (non-string entries such as images are only required in the neutral file); + - Resources.Designer.cs, if present, must expose exactly the neutral file's keys. + Exit code 0 when everything matches, 1 otherwise. + +.EXAMPLE + pwsh -File tools/Test-ResxKeyParity.ps1 +#> +[CmdletBinding()] +param( + [string] $Root = (Join-Path $PSScriptRoot '..' 'src') +) + +$ErrorActionPreference = 'Stop' + +function Get-ResxEntries([string] $Path) { + [xml] $xml = Get-Content -LiteralPath $Path -Raw -Encoding UTF8 + foreach ($data in $xml.root.data) { + [pscustomobject]@{ + Name = $data.name + IsString = [string]::IsNullOrEmpty($data.type) -and [string]::IsNullOrEmpty($data.mimetype) + } + } +} + +function Compare-KeySet([string] $Label, [string[]] $Expected, [string[]] $Actual) { + $missing = $Expected | Where-Object { $_ -notin $Actual } | Sort-Object + $extra = $Actual | Where-Object { $_ -notin $Expected } | Sort-Object + if (-not $missing -and -not $extra) { return $true } + + Write-Host "FAIL $Label" -ForegroundColor Red + foreach ($k in $missing) { Write-Host " missing: $k" } + foreach ($k in $extra) { Write-Host " extra: $k" } + return $false +} + +$ok = $true +$neutralFiles = Get-ChildItem -LiteralPath $Root -Recurse -Filter 'Resources.resx' | + Where-Object { $_.FullName -notmatch '[\\/](bin|obj)[\\/]' } + +foreach ($neutral in $neutralFiles) { + $dir = $neutral.DirectoryName + $cultureFiles = Get-ChildItem -LiteralPath $dir -Filter 'Resources.*.resx' + if (-not $cultureFiles) { continue } + + $relDir = [IO.Path]::GetRelativePath((Resolve-Path $Root), $dir) + $entries = @(Get-ResxEntries $neutral.FullName) + $allKeys = @($entries.Name) + $stringKeys = @($entries | Where-Object IsString | ForEach-Object Name) + + foreach ($culture in $cultureFiles) { + $cultureKeys = @(Get-ResxEntries $culture.FullName | Where-Object IsString | ForEach-Object Name) + $ok = (Compare-KeySet "$relDir/$($culture.Name) vs Resources.resx" $stringKeys $cultureKeys) -and $ok + } + + $designer = Join-Path $dir 'Resources.Designer.cs' + if (Test-Path -LiteralPath $designer) { + $accessors = @(Select-String -LiteralPath $designer -Pattern '^\s*(?:public|internal)\s+static\s+[\w.:]+\s+(\w+)\s*\{' | + ForEach-Object { $_.Matches[0].Groups[1].Value } | + Where-Object { $_ -notin 'ResourceManager', 'Culture' }) + $ok = (Compare-KeySet "$relDir/Resources.Designer.cs vs Resources.resx" $allKeys $accessors) -and $ok + } +} + +if ($ok) { + Write-Host "Resx key parity OK ($($neutralFiles.Count) neutral files checked)." + exit 0 +} +exit 1