') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); chore(main): extract settings-runtime-effects + session-stream from main.ts (arch R5) by jackwener · Pull Request #1248 · apache/maka · GitHub
Skip to content

chore(main): extract settings-runtime-effects + session-stream from main.ts (arch R5) - #1248

Merged
jackwener merged 4 commits into
mainfrom
chore/arch-round-5
Jul 19, 2026
Merged

chore(main): extract settings-runtime-effects + session-stream from main.ts (arch R5)#1248
jackwener merged 4 commits into
mainfrom
chore/arch-round-5

Conversation

@jackwener

Copy link
Copy Markdown
Member

Round 5 of notes/frontend-architecture-map-2026-07-19.md: main.ts 1656 → 1372 (−284), both clusters extracted in full (no escape hatch needed).

  • settings-runtime-effects.ts (127 L): createSettingsRuntimeEffects(deps) → normalizeSettingsPatch / applySettingsRuntimeEffects (network/bot/gateway/permission-mode/keep-awake feat(plans): 保持系统唤醒 — real powerSaveBlocker capability for scheduled tasks #1207 effects byte-identical) / handleExternalSettingsChange.
  • session-stream.ts (409 L): createAiSdkBackendFactory (the whole backends.register('ai-sdk') closure incl. modelSupportsVision, contract text verbatim) + createSessionStreamer.
  • Semantics preserved with care: the register call SITE stays at its original position (registry-construction order); module-let mutations (runtime, lookupPricing) injected as accessors so both snapshot-read and live-read closures keep exact behavior; 9 streamEvents call sites untouched in main.ts.
  • Contracts: modules added to the main-process source aggregator; attachment-frontend (vision pin), ipc-surface, web-search-telemetry-scrub switched to combined-source with every assertion kept; wiring-contract (registerIpc anchor) untouched; one console allowlist path updated.
  • Proof: auditor boots all 11 fixtures clean; CDP turn-narrative renders the full chat hot path; settings-general renders 65 controls.

Gates (merged tree): desktop 2744 · ui 196 · typecheck · check-dead-css · knip ×2 = 0. Implemented by an opus worktree agent; R6 boundary shifted −284 in the map.

Pure move of main.ts's settings runtime-effects cluster into
settings-runtime-effects.ts, exporting createSettingsRuntimeEffects(deps)
→ { normalizeSettingsPatch, applySettingsRuntimeEffects,
handleExternalSettingsChange } (syncDefaultPermissionModeToSessions stays
internal). Follows the R4 tool-assembly / tool-artifact-persistence DI
precedent: settingsStore / botRegistry / openGateway / keepSystemAwake /
runtime / safeSendToRenderer / emitSessionsChanged are injected, bodies
byte-identical. keep-awake runtime-effect (#1207) rides
applySettingsRuntimeEffects unchanged.
Contract mechanics: add settings-runtime-effects.ts to the
main-process-contract-source-helpers aggregator; allowlist the moved
[config-watcher] console.error at its new path in check-console.mjs. No
source-pin test targeted these functions in main.ts directly.
Pure move of main.ts's session-stream cluster into session-stream.ts:
- createAiSdkBackendFactory(deps): BackendFactory — the whole
backends.register('ai-sdk', …) closure plus the internal modelSupportsVision.
Two seams resolved after the registration point are injected as accessors:
getRuntime (SessionManager built later) and getLookupPricing (mutable pricing
lookup, read live per recordLlmCall / snapshotted once for the lookupPricing
field — matching the original module-let closure semantics exactly).
- createSessionStreamer(deps): StreamEvents — streamEvents + its two
event-classifier helpers and the StreamEventsOptions/Result types.
main.ts keeps the module-scoped seams it owns (backends.register call site,
sessionActivities, lookupPricing let, runtime, the fake/e2e backend registers)
and every streamEvents call site.
Contract re-pins (maintainer-authorized): add session-stream.ts to the
main-process-contract-source-helpers aggregator; switch three direct-main.ts
readers to the combined source keeping every assertion —
attachment-frontend-contract (modelSupportsVision + supportsVision vision pin),
ipc-surface-contract (memoryPromptSnapshot + buildBackendSystemPrompt),
web-search-telemetry-scrub-contract (argsSummary scrub). registerIpc /
main-process-wiring-contract untouched.
main.ts 1656 → 1372 (−284 across both R5 clusters).
@jackwener
jackwener merged commit a939447 into mainJul 19, 2026
2 of 3 checks passed
Astro-Han added a commit that referenced this pull request Jul 19, 2026
…it (#1250)
R5 (#1248) moved the isComputerUseRealModelE2e tool/economy branches from
main.ts into session-stream.ts and repinned three main-process contract
tests to the combined source, but missed scripts/cu-real-model-launcher.test.mjs,
which still read main.ts alone. Its `Desktop isolation gate does not enable
FakeBackend` case then failed the `? computerUseTools` and
`? { economy: false, groups: [] }` matches, turning main CI red.
Scan main.ts + session-stream.ts together (same follow-the-split shape as
the R5 contract repins) so the isolation-gate pins follow the extracted
module. Test-only; no production code changes.
Sign up for freeto 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.

1 participant

@jackwener