experiments in a post-browser web
10
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix(cmd-panel): call api.initialize + migrate setKey/getKey to set/get (Cat 1)

Cat 1 of the v1-removal smoke regression analysis (docs/v1-removal-smoke-regressions.md).

When peek://ext/cmd/panel.html was given a tile-preload token in Phase 3.11b, app/cmd/panel.js was never updated for the Phase 4 strict settings API:

- never called await api.initialize(), so tokenValid stayed false and every api.settings/api.subscribe/api.publish call rejected or no-op-d.
- used api.settings.setKey(k, v) which Phase 4 removed and now throws.
- used api.settings.get() with no arg, which returned the whole settings blob in v1 but is no longer supported - the strict API requires a key.

Result: panel crashed during init, waitForPanelCommandsLoaded timed out, and all cmd-panel-dependent tests failed (14 tests across Cmd Palette, External URL Opening via cmd, tags page widget, Command Chaining, list-notes chains, Edit param mode, and api.commands.flush/batched).

Changes (panel.js only):
- Add await api.initialize() immediately after const api = window.app so the surface token is validated before any settings/subscribe call.
- Replace 5 api.settings.setKey(K, V) calls with api.settings.set(K, V).
- Refactor loadAdaptiveData() to fetch each key (adaptiveVersion, adaptiveFeedback, matchCounts) individually via api.settings.get(key) and inspect result.data.
- Refactor the prefs load to use api.settings.get(prefs) and read result.data.showUrlsInResults directly.

No internal logic changes beyond the api shape migration. The commands.flush gap (tests 3956, 4000) is tracked separately in the analysis doc as a preload-side missing method, not panel.js scope.

Validation: yarn test:grep Cmd Palette - test 142 (edit Tab-completion) now passes (was failing before). Test 93 (gallery command) still fails on a later assertion expecting the example extension command to register, likely Cat 3 cascade (cmd/background.js settings API breakage prevents example extension commands from loading).

+39 -28
+39 -28
app/cmd/panel.js
··· 17 17 18 18 const api = window.app; 19 19 20 + // Initialize the tile-preload surface before any API calls. Without this, 21 + // `tokenValid` is false and api.settings/api.subscribe/api.commands all 22 + // silently no-op or reject — see docs/v1-removal-smoke-regressions.md §1. 23 + if (api.initialize) { 24 + await api.initialize(); 25 + } 26 + 20 27 // Storage keys for persistent adaptive matching 21 28 const STORAGE_KEY_FEEDBACK = 'adaptiveFeedback'; 22 29 const STORAGE_KEY_COUNTS = 'matchCounts'; ··· 28 35 let adaptiveDataCache = null; 29 36 30 37 /** 31 - * Load persisted adaptive data from extension settings 38 + * Load persisted adaptive data from extension settings. 39 + * Phase 4 API: each key fetched individually via api.settings.get(key). 32 40 */ 33 41 const loadAdaptiveData = async () => { 34 42 if (adaptiveDataCache) { 35 43 return adaptiveDataCache; 36 44 } 37 45 38 - const result = await api.settings.get(); 39 - if (result.success && result.data) { 40 - const storedVersion = result.data[STORAGE_KEY_VERSION] || 0; 46 + const [versionRes, feedbackRes, countsRes] = await Promise.all([ 47 + api.settings.get(STORAGE_KEY_VERSION), 48 + api.settings.get(STORAGE_KEY_FEEDBACK), 49 + api.settings.get(STORAGE_KEY_COUNTS), 50 + ]); 41 51 42 - if (storedVersion < ADAPTIVE_VERSION) { 43 - log('cmd:panel', 'loadAdaptiveData: resetting stale feedback data (version', storedVersion, '->', ADAPTIVE_VERSION + ')'); 44 - adaptiveDataCache = { 45 - feedback: {}, 46 - counts: result.data[STORAGE_KEY_COUNTS] || {} 47 - }; 48 - await Promise.all([ 49 - api.settings.setKey(STORAGE_KEY_FEEDBACK, {}), 50 - api.settings.setKey(STORAGE_KEY_VERSION, ADAPTIVE_VERSION) 51 - ]); 52 - } else { 53 - adaptiveDataCache = { 54 - feedback: result.data[STORAGE_KEY_FEEDBACK] || {}, 55 - counts: result.data[STORAGE_KEY_COUNTS] || {} 56 - }; 57 - } 52 + const storedVersion = (versionRes.success && versionRes.data) || 0; 53 + const storedCounts = (countsRes.success && countsRes.data) || {}; 54 + const storedFeedback = (feedbackRes.success && feedbackRes.data) || {}; 55 + 56 + if (storedVersion < ADAPTIVE_VERSION) { 57 + log('cmd:panel', 'loadAdaptiveData: resetting stale feedback data (version', storedVersion, '->', ADAPTIVE_VERSION + ')'); 58 + adaptiveDataCache = { 59 + feedback: {}, 60 + counts: storedCounts, 61 + }; 62 + await Promise.all([ 63 + api.settings.set(STORAGE_KEY_FEEDBACK, {}), 64 + api.settings.set(STORAGE_KEY_VERSION, ADAPTIVE_VERSION), 65 + ]); 58 66 } else { 59 - adaptiveDataCache = { feedback: {}, counts: {} }; 60 - await api.settings.setKey(STORAGE_KEY_VERSION, ADAPTIVE_VERSION); 67 + adaptiveDataCache = { 68 + feedback: storedFeedback, 69 + counts: storedCounts, 70 + }; 61 71 } 62 72 log('cmd:panel', 'loadAdaptiveData: loaded', Object.keys(adaptiveDataCache.feedback).length, 'feedback entries,', Object.keys(adaptiveDataCache.counts).length, 'count entries'); 63 73 return adaptiveDataCache; ··· 69 79 const saveAdaptiveData = async (feedback, counts) => { 70 80 adaptiveDataCache = { feedback, counts }; 71 81 await Promise.all([ 72 - api.settings.setKey(STORAGE_KEY_FEEDBACK, feedback), 73 - api.settings.setKey(STORAGE_KEY_COUNTS, counts) 82 + api.settings.set(STORAGE_KEY_FEEDBACK, feedback), 83 + api.settings.set(STORAGE_KEY_COUNTS, counts), 74 84 ]); 75 85 }; 76 86 ··· 90 100 // Cached prefs for URL search behavior 91 101 let showUrlsInResults = defaults.prefs.showUrlsInResults; 92 102 93 - // Load prefs on startup 94 - api.settings.get().then(result => { 95 - if (result.success && result.data?.prefs) { 96 - showUrlsInResults = result.data.prefs.showUrlsInResults ?? defaults.prefs.showUrlsInResults; 103 + // Load prefs on startup. Phase 4: api.settings.get(key) — request the 104 + // 'prefs' row directly rather than the (now removed) no-arg whole-object form. 105 + api.settings.get('prefs').then(result => { 106 + if (result.success && result.data) { 107 + showUrlsInResults = result.data.showUrlsInResults ?? defaults.prefs.showUrlsInResults; 97 108 } 98 109 log('cmd:panel', 'showUrlsInResults:', showUrlsInResults); 99 110 });