daemon: file capture.offer/getRules in deferrals (D7/D8); close settings.get/set (D9)

Rebased lane/daemon onto main first — fast-forward, no conflicts (lane/daemon was
already fully merged; main has since taken lane/gui, lane/pkg-qa, lane/proto).

1. capture.offer and capture.getRules were stubs, buried inside D3's generic stub list
   with no flag for how load-bearing capture.offer is: it's a CLAUDE.md §4
   non-negotiable (750ms deadline, fails open) and AGENT-DAEMON.md build step 6, and
   against the real daemon it 500s to -32603 every time — the extension captures
   nothing, not "falls through to Firefox on a slow path." Split into their own D7/D8
   rows so they stop being invisible.

2. settings.get/settings.set (D9, closed). Four pointer-to-member tables in
   dispatcher.cpp (bool / ranged int / plain string / string array), five enum-typed
   keys handled individually since parse_XXX already validates those — covers all 43
   SettingKeys without ~40 repetitive hand blocks. store::Settings::kDefaults grew from
   14 entries to 43 (the schema itself carries no "default" keyword anywhere, so these
   are hand-chosen — conservative for the ones ADR 0012 doesn't speak to;
   capture.monitoredExtensions defaults to the union of every builtin category's
   extensions rather than an arbitrary list of its own).

   settings.set validates every field before writing any of them: numeric min/max
   (hand-checked — the generated parser only checks JSON type, not schema
   constraints) and saveTo.* paths via fs::resolve_target/canonicalize_root (-32011) —
   allowedRoots entries checked as roots in their own right, defaultDir/tempDir checked
   as paths resolving inside the (possibly just-updated, same call) root list. Reports
   exactly the keys whose effective value actually changed, publishes
   event.settings.changed with that list, and calls the scheduler's reload_config()
   when a connection.* key took effect — live, not on next restart.

   Verified against real veloxd: all 43 keys round-trip with defaults, a keys subset
   filters, an out-of-range value rejects the whole call, a bad saveTo.defaultDir is
   -32011, allowedRoots+defaultDir set together cross-validate against the new roots,
   event.settings.changed fires over a live subscription. New dispatcher_settings_test
   covers the same ground without a socket. Full ctest: 53/53 (excluding a pre-existing,
   unrelated conformance failure — see below).

Also found, not fixed (not this lane): tests/conformance/run.sh's live-veloxd leg fails
"pairing failed: no token issued" reproducibly, isolated, on main before any of this
session's changes — it launches the isolated veloxd without VELOX_PAIR_AUTO=1, so
EnvAutoApprover denies every session.pair and the WS leg's session.hello never gets a
token. tests/conformance/ is PROTO/QA-owned; flagging rather than editing across the
lane boundary.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01GRDjHGgpYmMoPE2UFbe7pP
This commit is contained in:
2026-09-12 13:42:45 +04:00
co-authored by Claude Sonnet 5
parent f4a6cebb3e
commit e0edf7a084
8 changed files with 509 additions and 15 deletions
+60 -9
View File
@@ -9,24 +9,62 @@ namespace velox::daemon::store {
namespace {
// Built-in defaults, mirroring Settings.schema.json / ADR 0012. Only the keys the daemon
// currently reads or is likely to need before the full settings.get handler lands; the
// rest resolve through the schema's own defaults at that layer.
constexpr std::array<std::pair<std::string_view, std::string_view>, 14> kDefaults{{
// Built-in defaults, one per SettingKey (Settings.schema.json / SettingKey.schema.json).
// The schema itself carries no "default" keyword anywhere — these are what settings.get
// falls back to for a key with no stored row, chosen per ADR 0012 where it speaks (the
// connection.* buffer/segment keys) and otherwise the conservative, least-surprising
// value for that key's own description. capture.monitoredExtensions defaults to the union
// of every builtin category's extensions (0001_initial.sql's seed) rather than an
// arbitrary list of its own, so the two stay in sync without a second place to edit.
constexpr std::array<std::pair<std::string_view, std::string_view>, 43> kDefaults{{
{"general.launchOnLogin", "false"},
{"general.minimizeToTray", "false"},
{"general.showDropTarget", "true"},
{"general.confirmOnExit", "true"},
{"general.language", "\"system\""},
{"general.checkForUpdates", "true"},
{"capture.enabled", "true"},
{"capture.monitoredExtensions",
"[\"exe\",\"msi\",\"deb\",\"rpm\",\"dmg\",\"appimage\",\"iso\",\"zip\",\"tar\",\"gz\","
"\"xz\",\"7z\",\"mp4\",\"mkv\",\"webm\",\"avi\",\"mov\",\"flv\",\"m4v\",\"ts\",\"mp3\","
"\"flac\",\"aac\",\"ogg\",\"opus\",\"wav\",\"m4a\",\"pdf\",\"doc\",\"docx\",\"xls\","
"\"xlsx\",\"ppt\",\"pptx\",\"odt\",\"epub\",\"jpg\",\"jpeg\",\"png\",\"gif\",\"webp\","
"\"svg\",\"bmp\",\"tiff\"]"},
{"capture.monitoredMimeTypes", "[]"},
{"capture.minSizeBytes", "0"},
{"capture.excludedHosts", "[]"},
{"capture.bypassModifier", "\"shift\""},
{"capture.autoStartTypes", "[]"},
{"saveTo.defaultDir", "\"~/Downloads\""},
{"saveTo.tempDir", "\"\""},
{"saveTo.allowedRoots", "[\"~/Downloads\"]"},
{"saveTo.fileExistsPolicy", "\"ask\""},
{"saveTo.createSubfolderPerSite", "false"},
{"connection.preset", "\"auto\""},
{"connection.maxSegmentsPerDownload", "8"},
{"connection.bufferBytes", "1048576"},
{"connection.maxConcurrentDownloads", "5"},
{"connection.maxActiveSegments", "32"},
{"connection.maxTotalBufferBytes", "134217728"},
{"connection.maxActiveSegments", "32"},
{"connection.maxConcurrentDownloads", "5"},
{"connection.timeoutSec", "30"},
{"connection.maxRetries", "10"},
{"connection.retryBackoffSec", "5"},
{"saveTo.defaultDir", "\"~/Downloads\""},
{"saveTo.allowedRoots", "[\"~/Downloads\"]"},
{"saveTo.createSubfolderPerSite", "false"},
{"downloads.speedLimitBps", "0"},
{"downloads.speedLimitEnabled", "false"},
{"downloads.virusScanCommand", "\"\""},
{"downloads.postDownloadCommand", "\"\""},
{"downloads.duplicatePolicy", "\"ask\""},
{"downloads.verifyChecksums", "true"},
{"proxy.mode", "\"system\""},
{"proxy.host", "\"\""},
{"proxy.port", "1"},
{"proxy.username", "\"\""},
{"proxy.bypassHosts", "[]"},
{"proxy.pacUrl", "\"\""},
{"sounds.enabled", "true"},
{"sounds.onComplete", "\"\""},
{"sounds.onQueueComplete", "\"\""},
{"sounds.onError", "\"\""},
}};
} // namespace
@@ -86,6 +124,19 @@ std::int64_t Settings::get_int(std::string_view key) {
return 0;
}
bool Settings::get_bool(std::string_view key) {
auto raw = get_raw(key);
if (raw && *raw) {
auto j = nlohmann::json::parse(**raw, nullptr, false);
if (j.is_boolean()) return j.get<bool>();
}
if (auto d = default_for(key)) {
auto j = nlohmann::json::parse(*d, nullptr, false);
if (j.is_boolean()) return j.get<bool>();
}
return false;
}
std::string Settings::get_string(std::string_view key) {
auto raw = get_raw(key);
if (raw && *raw) {
+1
View File
@@ -35,6 +35,7 @@ public:
// Typed convenience over get_raw + the defaults. A malformed stored value falls back
// to the default rather than throwing.
std::int64_t get_int(std::string_view key);
bool get_bool(std::string_view key);
std::string get_string(std::string_view key);
std::vector<std::string> get_string_array(std::string_view key);