From 3eebb0f59041aad629a586a3c305f2a11f6e8262 Mon Sep 17 00:00:00 2001 From: Markus Graf Date: Thu, 26 Mar 2026 21:52:44 +0100 Subject: [PATCH] docs(07-02): complete print-config and LoadResult wiring plan - SUMMARY.md for plan 02: PrintConfig + CLI wiring - STATE.md: updated progress (100%), metrics, decisions, session - ROADMAP.md: Phase 7 marked Complete (2/2 summaries) - REQUIREMENTS.md: CFG-06 marked complete --- .planning/REQUIREMENTS.md | 4 +- .planning/ROADMAP.md | 8 +- .planning/STATE.md | 12 +-- .../07-02-SUMMARY.md | 95 +++++++++++++++++++ 4 files changed, 107 insertions(+), 12 deletions(-) create mode 100644 .planning/phases/07-custom-rules-and-print-config/07-02-SUMMARY.md diff --git a/.planning/REQUIREMENTS.md b/.planning/REQUIREMENTS.md index 977be57..2dc8739 100644 --- a/.planning/REQUIREMENTS.md +++ b/.planning/REQUIREMENTS.md @@ -14,7 +14,7 @@ Requirements for custom sound mappings milestone. Each maps to roadmap phases. - [x] **CFG-03**: User can specify an explicit config path via `--config` flag (error if file missing) - [x] **CFG-04**: User can override individual values without replicating the entire default config (partial override) - [x] **CFG-05**: Unknown keys in config file produce a clear error with the typo'd key name -- [ ] **CFG-06**: User can run `netsynth --print-config` to see the effective config as commented TOML +- [x] **CFG-06**: User can run `netsynth --print-config` to see the effective config as commented TOML ### Waveforms @@ -61,7 +61,7 @@ Which phases cover which requirements. Updated during roadmap creation. | CFG-03 | Phase 6 | Complete | | CFG-04 | Phase 6 | Complete | | CFG-05 | Phase 6 | Complete | -| CFG-06 | Phase 7 | Pending | +| CFG-06 | Phase 7 | Complete | | WAVE-01 | Phase 5 | Complete | | WAVE-02 | Phase 5 | Complete | | RULE-01 | Phase 7 | Complete | diff --git a/.planning/ROADMAP.md b/.planning/ROADMAP.md index 47e6846..5f0bf67 100644 --- a/.planning/ROADMAP.md +++ b/.planning/ROADMAP.md @@ -25,7 +25,7 @@ Full details: `.planning/milestones/v1.0-ROADMAP.md` - [x] **Phase 5: Waveform Types and Bank Decoupling** - Internal refactors establishing waveform enum and injectable bank signature (completed 2026-03-26) - [x] **Phase 6: Config Package and Sound Overrides** - TOML loading, auto-discovery, partial merge, and frequency/waveform overrides wired end-to-end (completed 2026-03-26) -- [ ] **Phase 7: Custom Rules and Print-Config** - User-defined classification rules and --print-config UX +- [x] **Phase 7: Custom Rules and Print-Config** - User-defined classification rules and --print-config UX (completed 2026-03-26) ## Phase Details @@ -68,11 +68,11 @@ Plans: 2. User-defined rules fire before built-in protocol rules — a custom rule for port 443 overrides the default HTTPS classification for packets on that port 3. A user-defined class name gets its own synthesis layer automatically — no silence or missing audio for traffic matched by a custom rule 4. User runs `netsynth --print-config` and sees the full effective config (defaults merged with their overrides) as commented TOML, without starting a capture -**Plans:** 1/2 plans executed +**Plans:** 2/2 plans complete Plans: - [x] 07-01-PLAN.md — Config extension: RawRule, LoadResult, rule validation, auto-freq assignment (TDD) -- [ ] 07-02-PLAN.md — CLI wiring: --print-config flag, user rule prepend, PrintConfig output +- [x] 07-02-PLAN.md — CLI wiring: --print-config flag, user rule prepend, PrintConfig output ## Progress @@ -84,4 +84,4 @@ Plans: | 4. Power User Features | v1.0 | 2/2 | Complete | 2026-03-26 | | 5. Waveform Types and Bank Decoupling | v1.1 | 2/2 | Complete | 2026-03-26 | | 6. Config Package and Sound Overrides | v1.1 | 2/2 | Complete | 2026-03-26 | -| 7. Custom Rules and Print-Config | v1.1 | 1/2 | In Progress| | +| 7. Custom Rules and Print-Config | v1.1 | 2/2 | Complete | 2026-03-26 | diff --git a/.planning/STATE.md b/.planning/STATE.md index d85ee21..9affd9b 100644 --- a/.planning/STATE.md +++ b/.planning/STATE.md @@ -3,14 +3,14 @@ gsd_state_version: 1.0 milestone: v1.1 milestone_name: Custom Sound Mappings status: executing -stopped_at: Completed 07-01-PLAN.md -last_updated: "2026-03-26T20:45:59.826Z" +stopped_at: Completed 07-02-PLAN.md +last_updated: "2026-03-26T20:52:30.478Z" last_activity: 2026-03-26 progress: total_phases: 3 - completed_phases: 2 + completed_phases: 3 total_plans: 6 - completed_plans: 5 + completed_plans: 6 percent: 0 --- @@ -81,6 +81,6 @@ None. ## Session Continuity -Last session: 2026-03-26T20:45:59.819Z -Stopped at: Completed 07-01-PLAN.md +Last session: 2026-03-26T20:52:30.470Z +Stopped at: Completed 07-02-PLAN.md Resume file: None diff --git a/.planning/phases/07-custom-rules-and-print-config/07-02-SUMMARY.md b/.planning/phases/07-custom-rules-and-print-config/07-02-SUMMARY.md new file mode 100644 index 0000000..f5c71ad --- /dev/null +++ b/.planning/phases/07-custom-rules-and-print-config/07-02-SUMMARY.md @@ -0,0 +1,95 @@ +--- +phase: 07-custom-rules-and-print-config +plan: "02" +subsystem: config, cmd/netsynth +tags: [config, cli, print-config, rules, wiring, CFG-06, RULE-02] +dependency_graph: + requires: [LoadResult, UserRules, AutoClasses, PrintConfig] + provides: [--print-config flag, runPrintConfig, user-rule-prepend, PrintConfig-output] + affects: [cmd/netsynth/main.go, config/config.go] +tech_stack: + added: ["sort", "time", "strings.Builder"] + patterns: [LoadResult-propagation, user-rule-prepend, annotated-TOML-output] +key_files: + created: [] + modified: + - cmd/netsynth/main.go + - cmd/netsynth/main_test.go + - config/config.go + - config/config_test.go +decisions: + - "--print-config check placed after --list-interfaces but before interface-required validation so it works without -i" + - "AutoClasses map added to LoadResult to track which classes were auto-assigned by FNV-32a" + - "PrintConfig returns a string (not writes to io.Writer) for testability; caller prints to stdout" + - "waveformString returns custom for WaveformCustom (zero value used by hand-tuned built-in classes)" + - "classAnnotation: built-in classes compared on both BaseHz and WaveformType for override detection" +metrics: + duration: 8min + completed: "2026-03-26T20:55:00Z" + tasks_completed: 2 + files_modified: 4 +--- + +# Phase 7 Plan 02: CLI Wiring and PrintConfig Output Summary + +Wire the LoadResult into main.go (user rules prepend, --print-config flag), implement the PrintConfig output function in the config package, and add comprehensive tests for both. Completes RULE-02 and CFG-06 — the final plan for Phase 7 and the v1.1 milestone. + +## What Was Built + +**cmd/netsynth/main.go:** +- Added `printConfig bool` var and `--print-config` flag registration +- `runPrintConfig()`: calls `config.Load(configPath)` then `config.PrintConfig(result)`, prints to stdout, exits clean +- --print-config check fires before interface-required validation (no -i needed) +- `runLiveMode` and `runPcapMode` now accept `config.LoadResult` instead of bare `map[TrafficClass]FreqConfig` +- User rules prepend in both modes: `append(result.UserRules, classify.DefaultRules...)` (RULE-02) +- Removed unused `synth` import + +**config/config.go:** +- `LoadResult` gains `AutoClasses map[classify.TrafficClass]bool` field +- `addAutoFreqEntries` updated to accept and populate `autoClasses` map +- `Load()` initializes `AutoClasses` map and returns it in `LoadResult` +- `PrintConfig(result LoadResult) string`: generates commented TOML output with: + - Header: `# NetSynth effective configuration`, `# Config source: `, `# Generated: ` + - `[[rules]]` section for each user rule (port omitted when DstPort==0) + - `[sounds.*]` section for all classes in deterministic order (14 built-ins in AllClasses() order, then user-defined sorted alphabetically) + - Per-class annotation: `(default)`, `(override)`, or `(auto-assigned)` +- `waveformString()`: converts WaveformType to TOML string +- `classAnnotation()`: determines annotation based on AutoClasses membership and comparison with defaults + +## Tasks Completed + +| Task | Name | Commit | Files | +|------|------|--------|-------| +| 1 | Wire LoadResult into main.go and add --print-config flag | d43914f | cmd/netsynth/main.go, cmd/netsynth/main_test.go | +| 2 | Implement PrintConfig output function with comment annotations | b52e36b | config/config.go, config/config_test.go | + +## Deviations from Plan + +None - plan executed exactly as written. + +## Test Coverage + +New tests added (8 PrintConfig tests in config_test.go, 3 print-config tests in main_test.go): + +**config/config_test.go:** +- `TestPrintConfigContainsAllClasses` - all 14 class names in output +- `TestPrintConfigSourcePath` - `# Config source: ` in header +- `TestPrintConfigNoSourcePath` - `# Config source: none` when no config +- `TestPrintConfigContainsRules` - `[[rules]]` section with port/protocol/class +- `TestPrintConfigRuleNoPort` - port line omitted when DstPort==0 +- `TestPrintConfigDefaultAnnotation` - `(default)` for unmodified built-in class +- `TestPrintConfigOverrideAnnotation` - `(override)` for modified built-in class +- `TestPrintConfigAutoAssignedAnnotation` - `(auto-assigned)` for FNV-hash assigned class + +**cmd/netsynth/main_test.go:** +- `TestPrintConfigFlagRegistered` - flag exists on command +- `TestPrintConfigNoInterface` - --print-config works without -i +- `TestPrintConfigWithConfigFile` - --print-config with --config succeeds + +Full suite: `go test ./... -count=1` all 7 packages pass. + +## Known Stubs + +None. All functionality is fully implemented and wired. + +## Self-Check: PASSED